summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcvs2svn <cvs2svn@FreeBSD.org>2003-05-31 11:28:29 +0000
committercvs2svn <cvs2svn@FreeBSD.org>2003-05-31 11:28:29 +0000
commit4b38df05470b4d78dd0a2a026ab8f90299ec8382 (patch)
treef1e2900ee8435e83ab443db9f7a879b677f37cdd
parentacb9e0f3f677031b651a96575f7f5942a621da54 (diff)
downloadsrc-test2-4b38df05470b4d78dd0a2a026ab8f90299ec8382.tar.gz
src-test2-4b38df05470b4d78dd0a2a026ab8f90299ec8382.zip
Notes
-rw-r--r--bin/csh/config_p.h161
-rw-r--r--bin/uuidgen/Makefile6
-rw-r--r--bin/uuidgen/uuidgen.179
-rw-r--r--bin/uuidgen/uuidgen.c113
-rw-r--r--contrib/telnet/arpa/telnet.h347
-rw-r--r--contrib/telnet/libtelnet/auth-proto.h111
-rw-r--r--contrib/telnet/libtelnet/auth.c623
-rw-r--r--contrib/telnet/libtelnet/auth.h80
-rw-r--r--contrib/telnet/libtelnet/enc-proto.h126
-rw-r--r--contrib/telnet/libtelnet/enc_des.c662
-rw-r--r--contrib/telnet/libtelnet/encrypt.c953
-rw-r--r--contrib/telnet/libtelnet/encrypt.h106
-rw-r--r--contrib/telnet/libtelnet/genget.c107
-rw-r--r--contrib/telnet/libtelnet/getent.c76
-rw-r--r--contrib/telnet/libtelnet/kerberos.c506
-rw-r--r--contrib/telnet/libtelnet/kerberos5.c825
-rw-r--r--contrib/telnet/libtelnet/key-proto.h65
-rw-r--r--contrib/telnet/libtelnet/krb4encpwd.c428
-rw-r--r--contrib/telnet/libtelnet/misc-proto.h80
-rw-r--r--contrib/telnet/libtelnet/misc.c109
-rw-r--r--contrib/telnet/libtelnet/misc.h42
-rw-r--r--contrib/telnet/libtelnet/pk.c265
-rw-r--r--contrib/telnet/libtelnet/pk.h59
-rw-r--r--contrib/telnet/libtelnet/read_password.c151
-rw-r--r--contrib/telnet/libtelnet/rsaencpwd.c475
-rw-r--r--contrib/telnet/libtelnet/sra.c602
-rw-r--r--contrib/telnet/telnet/authenc.c111
-rw-r--r--contrib/telnet/telnet/commands.c3014
-rw-r--r--contrib/telnet/telnet/defines.h56
-rw-r--r--contrib/telnet/telnet/externs.h491
-rw-r--r--contrib/telnet/telnet/fdset.h49
-rw-r--r--contrib/telnet/telnet/general.h45
-rw-r--r--contrib/telnet/telnet/main.c373
-rw-r--r--contrib/telnet/telnet/network.c182
-rw-r--r--contrib/telnet/telnet/ring.c322
-rw-r--r--contrib/telnet/telnet/ring.h107
-rw-r--r--contrib/telnet/telnet/sys_bsd.c1145
-rw-r--r--contrib/telnet/telnet/telnet.11424
-rw-r--r--contrib/telnet/telnet/telnet.c2378
-rw-r--r--contrib/telnet/telnet/terminal.c242
-rw-r--r--contrib/telnet/telnet/types.h52
-rw-r--r--contrib/telnet/telnet/utilities.c912
-rw-r--r--contrib/telnet/telnetd/authenc.c90
-rw-r--r--contrib/telnet/telnetd/defs.h258
-rw-r--r--contrib/telnet/telnetd/ext.h218
-rw-r--r--contrib/telnet/telnetd/global.c52
-rw-r--r--contrib/telnet/telnetd/pathnames.h56
-rw-r--r--contrib/telnet/telnetd/slc.c484
-rw-r--r--contrib/telnet/telnetd/state.c1631
-rw-r--r--contrib/telnet/telnetd/sys_term.c1339
-rw-r--r--contrib/telnet/telnetd/telnetd.8587
-rw-r--r--contrib/telnet/telnetd/telnetd.c1226
-rw-r--r--contrib/telnet/telnetd/telnetd.h49
-rw-r--r--contrib/telnet/telnetd/termstat.c632
-rw-r--r--contrib/telnet/telnetd/utility.c1081
-rw-r--r--etc/rc.d/atm2104
-rw-r--r--etc/rc.d/atm368
-rw-r--r--etc/rc.d/lockd46
-rw-r--r--etc/rc.d/netoptions36
-rw-r--r--etc/rc.d/ppp48
-rw-r--r--etc/rc.d/resolv165
-rw-r--r--etc/rc.d/routing140
-rw-r--r--etc/rc.d/statd46
-rw-r--r--etc/rc.d/tmp165
-rw-r--r--etc/rc.d/var165
-rw-r--r--etc/rc.initdiskless223
-rw-r--r--gnu/usr.bin/gdb/doc/inc-hist.diff31
-rw-r--r--include/_ctype.h228
-rw-r--r--lib/libc/gen/fts-compat.c1154
-rw-r--r--lib/libc/gen/fts-compat.h137
-rw-r--r--lib/libc/gen/sem.c357
-rw-r--r--lib/libc/gen/sem_destroy.384
-rw-r--r--lib/libc/gen/sem_getvalue.376
-rw-r--r--lib/libc/gen/sem_init.3102
-rw-r--r--lib/libc/gen/sem_open.3227
-rw-r--r--lib/libc/gen/sem_post.371
-rw-r--r--lib/libc/gen/sem_wait.389
-rw-r--r--lib/libc/locale/euc.5242
-rw-r--r--lib/libc/locale/utf2.594
-rw-r--r--lib/libc/posix1e/mac_is_present.381
-rw-r--r--lib/libc/sys/shm_open.2193
-rw-r--r--lib/libc/sys/sigwait.286
-rw-r--r--lib/libkse/Makefile37
-rw-r--r--lib/libkse/arch/i386/i386/thr_enter_uts.S101
-rw-r--r--lib/libkse/arch/i386/i386/thr_getcontext.S157
-rw-r--r--lib/libkse/arch/i386/include/atomic_ops.h51
-rw-r--r--lib/libkse/arch/i386/include/pthread_md.h54
-rw-r--r--lib/libkse/support/Makefile.inc10
-rw-r--r--lib/libkse/support/thr_support.c55
-rw-r--r--lib/libkse/sys/Makefile.inc7
-rw-r--r--lib/libkse/sys/lock.c300
-rw-r--r--lib/libkse/sys/lock.h92
-rw-r--r--lib/libkse/sys/thr_error.c58
-rw-r--r--lib/libkse/test/Makefile115
-rw-r--r--lib/libkse/test/README28
-rw-r--r--lib/libkse/test/guard_b.c150
-rw-r--r--lib/libkse/test/guard_b.exp3
-rw-r--r--lib/libkse/test/guard_s.pl69
-rw-r--r--lib/libkse/test/hello_b.c13
-rw-r--r--lib/libkse/test/hello_d.c38
-rw-r--r--lib/libkse/test/hello_d.exp1
-rw-r--r--lib/libkse/test/hello_s.c47
-rw-r--r--lib/libkse/test/join_leak_d.c108
-rw-r--r--lib/libkse/test/join_leak_d.exp2
-rw-r--r--lib/libkse/test/mutex_d.c1554
-rw-r--r--lib/libkse/test/mutex_d.exp290
-rw-r--r--lib/libkse/test/propagate_s.pl74
-rw-r--r--lib/libkse/test/sem_d.c133
-rw-r--r--lib/libkse/test/sem_d.exp22
-rw-r--r--lib/libkse/test/sigsuspend_d.c288
-rw-r--r--lib/libkse/test/sigsuspend_d.exp8
-rw-r--r--lib/libkse/test/sigwait_d.c304
-rw-r--r--lib/libkse/test/sigwait_d.exp10
-rw-r--r--lib/libkse/test/verify474
-rw-r--r--lib/libkse/thread/Makefile.inc105
-rw-r--r--lib/libkse/thread/thr_aio_suspend.c51
-rw-r--r--lib/libkse/thread/thr_attr_destroy.c62
-rw-r--r--lib/libkse/thread/thr_attr_get_np.c53
-rw-r--r--lib/libkse/thread/thr_attr_getdetachstate.c59
-rw-r--r--lib/libkse/thread/thr_attr_getguardsize.c52
-rw-r--r--lib/libkse/thread/thr_attr_getinheritsched.c51
-rw-r--r--lib/libkse/thread/thr_attr_getschedparam.c51
-rw-r--r--lib/libkse/thread/thr_attr_getschedpolicy.c51
-rw-r--r--lib/libkse/thread/thr_attr_getscope.c54
-rw-r--r--lib/libkse/thread/thr_attr_getstack.c59
-rw-r--r--lib/libkse/thread/thr_attr_getstackaddr.c54
-rw-r--r--lib/libkse/thread/thr_attr_getstacksize.c54
-rw-r--r--lib/libkse/thread/thr_attr_init.c62
-rw-r--r--lib/libkse/thread/thr_attr_setcreatesuspend_np.c52
-rw-r--r--lib/libkse/thread/thr_attr_setdetachstate.c61
-rw-r--r--lib/libkse/thread/thr_attr_setguardsize.c61
-rw-r--r--lib/libkse/thread/thr_attr_setinheritsched.c51
-rw-r--r--lib/libkse/thread/thr_attr_setschedparam.c57
-rw-r--r--lib/libkse/thread/thr_attr_setschedpolicy.c53
-rw-r--r--lib/libkse/thread/thr_attr_setscope.c55
-rw-r--r--lib/libkse/thread/thr_attr_setstack.c58
-rw-r--r--lib/libkse/thread/thr_attr_setstackaddr.c54
-rw-r--r--lib/libkse/thread/thr_attr_setstacksize.c54
-rw-r--r--lib/libkse/thread/thr_autoinit.c64
-rw-r--r--lib/libkse/thread/thr_cancel.c288
-rw-r--r--lib/libkse/thread/thr_clean.c72
-rw-r--r--lib/libkse/thread/thr_close.c55
-rw-r--r--lib/libkse/thread/thr_concurrency.c139
-rw-r--r--lib/libkse/thread/thr_cond.c799
-rw-r--r--lib/libkse/thread/thr_condattr_destroy.c53
-rw-r--r--lib/libkse/thread/thr_condattr_init.c58
-rw-r--r--lib/libkse/thread/thr_creat.c49
-rw-r--r--lib/libkse/thread/thr_create.c347
-rw-r--r--lib/libkse/thread/thr_detach.c115
-rw-r--r--lib/libkse/thread/thr_equal.c44
-rw-r--r--lib/libkse/thread/thr_exit.c129
-rw-r--r--lib/libkse/thread/thr_fcntl.c71
-rw-r--r--lib/libkse/thread/thr_find_thread.c100
-rw-r--r--lib/libkse/thread/thr_fork.c59
-rw-r--r--lib/libkse/thread/thr_fsync.c51
-rw-r--r--lib/libkse/thread/thr_getprio.c56
-rw-r--r--lib/libkse/thread/thr_getschedparam.c73
-rw-r--r--lib/libkse/thread/thr_info.c205
-rw-r--r--lib/libkse/thread/thr_init.c530
-rw-r--r--lib/libkse/thread/thr_join.c160
-rw-r--r--lib/libkse/thread/thr_kern.c2214
-rw-r--r--lib/libkse/thread/thr_kill.c66
-rw-r--r--lib/libkse/thread/thr_main_np.c47
-rw-r--r--lib/libkse/thread/thr_mattr_init.c58
-rw-r--r--lib/libkse/thread/thr_mattr_kind_np.c97
-rw-r--r--lib/libkse/thread/thr_msync.c33
-rw-r--r--lib/libkse/thread/thr_multi_np.c50
-rw-r--r--lib/libkse/thread/thr_mutex.c1637
-rw-r--r--lib/libkse/thread/thr_mutex_prioceiling.c111
-rw-r--r--lib/libkse/thread/thr_mutex_protocol.c70
-rw-r--r--lib/libkse/thread/thr_mutexattr_destroy.c53
-rw-r--r--lib/libkse/thread/thr_nanosleep.c129
-rw-r--r--lib/libkse/thread/thr_once.c55
-rw-r--r--lib/libkse/thread/thr_open.c67
-rw-r--r--lib/libkse/thread/thr_pause.c49
-rw-r--r--lib/libkse/thread/thr_poll.c57
-rw-r--r--lib/libkse/thread/thr_printf.c120
-rw-r--r--lib/libkse/thread/thr_priority_queue.c273
-rw-r--r--lib/libkse/thread/thr_private.h1232
-rw-r--r--lib/libkse/thread/thr_pselect.c57
-rw-r--r--lib/libkse/thread/thr_read.c56
-rw-r--r--lib/libkse/thread/thr_readv.c56
-rw-r--r--lib/libkse/thread/thr_resume_np.c99
-rw-r--r--lib/libkse/thread/thr_rtld.c137
-rw-r--r--lib/libkse/thread/thr_rwlock.c350
-rw-r--r--lib/libkse/thread/thr_rwlockattr.c98
-rw-r--r--lib/libkse/thread/thr_select.c60
-rw-r--r--lib/libkse/thread/thr_self.c47
-rw-r--r--lib/libkse/thread/thr_sem.c258
-rw-r--r--lib/libkse/thread/thr_seterrno.c59
-rw-r--r--lib/libkse/thread/thr_setprio.c52
-rw-r--r--lib/libkse/thread/thr_setschedparam.c136
-rw-r--r--lib/libkse/thread/thr_sig.c906
-rw-r--r--lib/libkse/thread/thr_sigaction.c106
-rw-r--r--lib/libkse/thread/thr_sigmask.c103
-rw-r--r--lib/libkse/thread/thr_sigpending.c66
-rw-r--r--lib/libkse/thread/thr_sigprocmask.c51
-rw-r--r--lib/libkse/thread/thr_sigsuspend.c88
-rw-r--r--lib/libkse/thread/thr_sigwait.c175
-rw-r--r--lib/libkse/thread/thr_single_np.c49
-rw-r--r--lib/libkse/thread/thr_sleep.c49
-rw-r--r--lib/libkse/thread/thr_spec.c224
-rw-r--r--lib/libkse/thread/thr_spinlock.c152
-rw-r--r--lib/libkse/thread/thr_stack.c237
-rw-r--r--lib/libkse/thread/thr_suspend_np.c109
-rw-r--r--lib/libkse/thread/thr_switch_np.c53
-rw-r--r--lib/libkse/thread/thr_system.c49
-rw-r--r--lib/libkse/thread/thr_tcdrain.c49
-rw-r--r--lib/libkse/thread/thr_vfork.c12
-rw-r--r--lib/libkse/thread/thr_wait.c48
-rw-r--r--lib/libkse/thread/thr_wait4.c54
-rw-r--r--lib/libkse/thread/thr_waitpid.c50
-rw-r--r--lib/libkse/thread/thr_write.c56
-rw-r--r--lib/libkse/thread/thr_writev.c58
-rw-r--r--lib/libkse/thread/thr_yield.c65
-rw-r--r--lib/ncurses/form/Makefile97
-rw-r--r--lib/ncurses/menu/Makefile82
-rw-r--r--lib/ncurses/ncurses/Makefile562
-rw-r--r--lib/ncurses/ncurses/ncurses_cfg.h155
-rw-r--r--lib/ncurses/ncurses/pathnames.h38
-rw-r--r--lib/ncurses/ncurses/termcap.c267
-rw-r--r--lib/ncurses/panel/Makefile46
-rw-r--r--release/amd64/boot_crunch.conf29
-rwxr-xr-xrelease/amd64/dokern.sh51
-rw-r--r--release/amd64/fixit_crunch.conf25
-rw-r--r--release/amd64/mkisoimages.sh56
-rw-r--r--release/doc/en_US.ISO8859-1/hardware/article.sgml3676
-rw-r--r--release/doc/en_US.ISO8859-1/relnotes/article.sgml1088
-rw-r--r--sbin/setkey/Makefile62
-rw-r--r--sbin/setkey/parse.y933
-rw-r--r--sbin/setkey/sample.cf219
-rw-r--r--sbin/setkey/scriptdump.pl56
-rw-r--r--sbin/setkey/setkey.8625
-rw-r--r--sbin/setkey/setkey.c648
-rw-r--r--sbin/setkey/test-pfkey.c531
-rw-r--r--sbin/setkey/test-policy.c161
-rw-r--r--sbin/setkey/token.l322
-rw-r--r--sbin/setkey/vchar.h36
-rw-r--r--share/man/man3/pthread_attr.3238
-rw-r--r--share/man/man3/pthread_attr_get_np.3116
-rw-r--r--share/man/man3/pthread_attr_setcreatesuspend_np.372
-rw-r--r--share/man/man3/pthread_cancel.381
-rw-r--r--share/man/man3/pthread_cleanup_pop.366
-rw-r--r--share/man/man3/pthread_cleanup_push.368
-rw-r--r--share/man/man3/pthread_cond_broadcast.372
-rw-r--r--share/man/man3/pthread_cond_destroy.376
-rw-r--r--share/man/man3/pthread_cond_init.382
-rw-r--r--share/man/man3/pthread_cond_signal.372
-rw-r--r--share/man/man3/pthread_cond_timedwait.391
-rw-r--r--share/man/man3/pthread_cond_wait.385
-rw-r--r--share/man/man3/pthread_condattr.388
-rw-r--r--share/man/man3/pthread_create.3125
-rw-r--r--share/man/man3/pthread_detach.391
-rw-r--r--share/man/man3/pthread_equal.369
-rw-r--r--share/man/man3/pthread_exit.3105
-rw-r--r--share/man/man3/pthread_getconcurrency.3115
-rw-r--r--share/man/man3/pthread_getspecific.385
-rw-r--r--share/man/man3/pthread_join.3106
-rw-r--r--share/man/man3/pthread_key_create.3109
-rw-r--r--share/man/man3/pthread_key_delete.3100
-rw-r--r--share/man/man3/pthread_kill.377
-rw-r--r--share/man/man3/pthread_main_np.360
-rw-r--r--share/man/man3/pthread_multi_np.366
-rw-r--r--share/man/man3/pthread_mutex_destroy.374
-rw-r--r--share/man/man3/pthread_mutex_init.379
-rw-r--r--share/man/man3/pthread_mutex_lock.376
-rw-r--r--share/man/man3/pthread_mutex_trylock.377
-rw-r--r--share/man/man3/pthread_mutex_unlock.376
-rw-r--r--share/man/man3/pthread_mutexattr.3187
-rw-r--r--share/man/man3/pthread_mutexattr_getkind_np.381
-rw-r--r--share/man/man3/pthread_once.3106
-rw-r--r--share/man/man3/pthread_resume_all_np.351
-rw-r--r--share/man/man3/pthread_resume_np.372
-rw-r--r--share/man/man3/pthread_rwlock_destroy.382
-rw-r--r--share/man/man3/pthread_rwlock_init.3101
-rw-r--r--share/man/man3/pthread_rwlock_rdlock.3124
-rw-r--r--share/man/man3/pthread_rwlock_unlock.381
-rw-r--r--share/man/man3/pthread_rwlock_wrlock.3105
-rw-r--r--share/man/man3/pthread_rwlockattr_destroy.371
-rw-r--r--share/man/man3/pthread_rwlockattr_getpshared.383
-rw-r--r--share/man/man3/pthread_rwlockattr_init.370
-rw-r--r--share/man/man3/pthread_rwlockattr_setpshared.392
-rw-r--r--share/man/man3/pthread_schedparam.393
-rw-r--r--share/man/man3/pthread_self.362
-rw-r--r--share/man/man3/pthread_set_name_np.355
-rw-r--r--share/man/man3/pthread_setspecific.398
-rw-r--r--share/man/man3/pthread_sigmask.398
-rw-r--r--share/man/man3/pthread_suspend_all_np.353
-rw-r--r--share/man/man3/pthread_suspend_np.370
-rw-r--r--share/man/man3/pthread_switch_add_np.387
-rw-r--r--share/man/man3/pthread_testcancel.3210
-rw-r--r--share/man/man4/cy.4247
-rw-r--r--share/man/man4/en.460
-rw-r--r--share/man/man4/mac_stub.498
-rw-r--r--share/man/man4/snd_csa.463
-rw-r--r--share/man/man4/snd_gusc.478
-rw-r--r--share/man/man4/snd_maestro3.476
-rw-r--r--share/man/man4/snd_sbc.479
-rw-r--r--share/man/man4/spkr.4236
-rw-r--r--share/man/man4/tx.4108
-rw-r--r--share/man/man9/VOP_VPTOFH.961
-rw-r--r--share/zoneinfo/backward16
-rw-r--r--sys/amd64/amd64/amd64_mem.c620
-rw-r--r--sys/amd64/amd64/apic_vector.S680
-rw-r--r--sys/amd64/amd64/bios.c680
-rw-r--r--sys/amd64/amd64/fpu.c724
-rw-r--r--sys/amd64/amd64/mp_machdep.c2839
-rw-r--r--sys/amd64/amd64/mpboot.S282
-rw-r--r--sys/amd64/amd64/mptable.c2839
-rw-r--r--sys/amd64/amd64/prof_machdep.c359
-rw-r--r--sys/amd64/ia32/ia32_sigtramp.S87
-rw-r--r--sys/amd64/include/apicreg.h444
-rw-r--r--sys/amd64/include/fpu.h113
-rw-r--r--sys/amd64/include/mptable.h2839
-rw-r--r--sys/amd64/include/pc/bios.h280
-rw-r--r--sys/amd64/isa/atpic_vector.S253
-rw-r--r--sys/amd64/isa/nmi.c714
-rw-r--r--sys/boot/i386/boot2/boot1.S361
-rw-r--r--sys/boot/i386/boot2/sio.S80
-rw-r--r--sys/boot/i386/btx/btx/btx.S1173
-rw-r--r--sys/boot/i386/btx/btxldr/btxldr.S396
-rw-r--r--sys/boot/i386/gptboot/Makefile111
-rw-r--r--sys/boot/i386/gptboot/gptboot.c633
-rw-r--r--sys/boot/i386/pxeldr/pxeldr.S282
-rw-r--r--sys/boot/ia64/common/bootinfo.c348
-rw-r--r--sys/boot/ia64/common/copy.c68
-rw-r--r--sys/boot/ia64/common/devicename.c240
-rw-r--r--sys/boot/ia64/common/exec.c223
-rw-r--r--sys/boot/ia64/efi/Makefile123
-rw-r--r--sys/boot/ia64/efi/conf.c95
-rw-r--r--sys/boot/ia64/efi/ldscript.ia6480
-rw-r--r--sys/boot/ia64/efi/main.c571
-rw-r--r--sys/boot/ia64/efi/start.S305
-rw-r--r--sys/boot/ia64/efi/version16
-rw-r--r--sys/boot/ia64/libski/pal_stub.S65
-rw-r--r--sys/boot/ia64/ski/Makefile84
-rw-r--r--sys/boot/ia64/ski/acpi_stub.c193
-rw-r--r--sys/boot/ia64/ski/bootinfo.c315
-rw-r--r--sys/boot/ia64/ski/conf.c86
-rw-r--r--sys/boot/ia64/ski/copy.c58
-rw-r--r--sys/boot/ia64/ski/delay.c34
-rw-r--r--sys/boot/ia64/ski/devicename.c237
-rw-r--r--sys/boot/ia64/ski/efi_stub.c267
-rw-r--r--sys/boot/ia64/ski/elf_freebsd.c205
-rw-r--r--sys/boot/ia64/ski/exit.c42
-rw-r--r--sys/boot/ia64/ski/ldscript.ia64135
-rw-r--r--sys/boot/ia64/ski/libski.h96
-rw-r--r--sys/boot/ia64/ski/main.c134
-rw-r--r--sys/boot/ia64/ski/pal_stub.S65
-rw-r--r--sys/boot/ia64/ski/sal_stub.c117
-rw-r--r--sys/boot/ia64/ski/skiconsole.c96
-rw-r--r--sys/boot/ia64/ski/skifs.c192
-rw-r--r--sys/boot/ia64/ski/skiload.cmd16
-rw-r--r--sys/boot/ia64/ski/ssc.c52
-rw-r--r--sys/boot/ia64/ski/time.c175
-rw-r--r--sys/boot/ia64/ski/version8
-rw-r--r--sys/boot/pc98/btx/btx/btx.S1306
-rw-r--r--sys/boot/pc98/btx/btxldr/btxldr.S471
-rw-r--r--sys/boot/powerpc/ofw/Makefile115
-rw-r--r--sys/boot/powerpc/ofw/conf.c109
-rw-r--r--sys/boot/powerpc/ofw/help.ofw1
-rw-r--r--sys/boot/powerpc/ofw/metadata.c316
-rw-r--r--sys/boot/powerpc/ofw/start.c104
-rw-r--r--sys/boot/powerpc/ofw/version6
-rw-r--r--sys/boot/sparc64/boot1/_start.s8
-rw-r--r--sys/compat/freebsd32/Makefile16
-rw-r--r--sys/compat/freebsd32/freebsd32.h103
-rw-r--r--sys/compat/freebsd32/freebsd32_misc.c1436
-rw-r--r--sys/compat/freebsd32/freebsd32_proto.h302
-rw-r--r--sys/compat/freebsd32/freebsd32_syscall.h298
-rw-r--r--sys/compat/freebsd32/freebsd32_syscalls.c447
-rw-r--r--sys/compat/freebsd32/freebsd32_sysent.c465
-rw-r--r--sys/compat/freebsd32/freebsd32_util.h89
-rw-r--r--sys/compat/freebsd32/syscalls.conf12
-rw-r--r--sys/compat/freebsd32/syscalls.master613
-rw-r--r--sys/compat/ia32/ia32_genassym.c24
-rw-r--r--sys/compat/ia32/ia32_signal.h164
-rw-r--r--sys/compat/ia32/ia32_sigtramp.S87
-rw-r--r--sys/compat/ia32/ia32_sysvec.c282
-rw-r--r--sys/compat/ia32/ia32_util.h89
-rw-r--r--sys/compat/netbsd/dvcfg.h65
-rw-r--r--sys/compat/netbsd/physio_proc.h57
-rw-r--r--sys/contrib/dev/acpica/acdos16.h152
-rw-r--r--sys/contrib/dev/acpica/actbl71.h238
-rw-r--r--sys/contrib/dev/acpica/exdyadic.c939
-rw-r--r--sys/contrib/dev/acpica/exmonad.c1083
-rw-r--r--sys/contrib/dev/acpica/psfind.c485
-rw-r--r--sys/dev/agp/agp.c811
-rw-r--r--sys/dev/agp/agp_ali.c268
-rw-r--r--sys/dev/agp/agp_amd.c421
-rw-r--r--sys/dev/agp/agp_i810.c705
-rw-r--r--sys/dev/agp/agp_if.m134
-rw-r--r--sys/dev/agp/agp_intel.c401
-rw-r--r--sys/dev/agp/agp_sis.c262
-rw-r--r--sys/dev/agp/agp_via.c259
-rw-r--r--sys/dev/agp/agppriv.h105
-rw-r--r--sys/dev/agp/agpreg.h205
-rw-r--r--sys/dev/agp/agpvar.h126
-rw-r--r--sys/dev/atkbdc/atkbd.c1408
-rw-r--r--sys/dev/atkbdc/atkbd_atkbdc.c178
-rw-r--r--sys/dev/atkbdc/atkbd_isa.c178
-rw-r--r--sys/dev/atkbdc/atkbdc.c1041
-rw-r--r--sys/dev/atkbdc/atkbdc_isa.c369
-rw-r--r--sys/dev/atkbdc/atkbdc_subr.c369
-rw-r--r--sys/dev/atkbdc/atkbdcreg.h263
-rw-r--r--sys/dev/atkbdc/atkbdreg.h47
-rw-r--r--sys/dev/atkbdc/psm.c2960
-rw-r--r--sys/dev/bktr/ioctl_bt848.h298
-rw-r--r--sys/dev/bktr/ioctl_meteor.h187
-rw-r--r--sys/dev/cy/cy.c2960
-rw-r--r--sys/dev/cy/cy_isa.c2960
-rw-r--r--sys/dev/cy/cy_pci.c206
-rw-r--r--sys/dev/cy/cyreg.h75
-rw-r--r--sys/dev/dc/dcphy.c462
-rw-r--r--sys/dev/dc/if_dc.c3790
-rw-r--r--sys/dev/dc/if_dcreg.h1183
-rw-r--r--sys/dev/dc/pnphy.c282
-rw-r--r--sys/dev/de/dc21040reg.h583
-rw-r--r--sys/dev/de/if_de.c5262
-rw-r--r--sys/dev/de/if_devar.h924
-rw-r--r--sys/dev/en/if_en_pci.c481
-rw-r--r--sys/dev/fb/splash_bmp.c642
-rw-r--r--sys/dev/fb/splash_pcx.c262
-rw-r--r--sys/dev/fdc/fdc.c2793
-rw-r--r--sys/dev/fdc/fdcreg.h71
-rw-r--r--sys/dev/fe/mb86960.h340
-rw-r--r--sys/dev/ic/cd1400.h203
-rw-r--r--sys/dev/mc146818/mc146818reg.h187
-rw-r--r--sys/dev/mse/mse.c915
-rw-r--r--sys/dev/pcf/pcf.c632
-rw-r--r--sys/dev/ppc/ppc.c2166
-rw-r--r--sys/dev/ppc/ppcreg.h272
-rw-r--r--sys/dev/sf/if_sf.c1543
-rw-r--r--sys/dev/sf/if_sfreg.h1060
-rw-r--r--sys/dev/sk/if_sk.c2246
-rw-r--r--sys/dev/sk/if_skreg.h1223
-rw-r--r--sys/dev/sk/xmaciireg.h403
-rw-r--r--sys/dev/speaker/speaker.h29
-rw-r--r--sys/dev/speaker/spkr.c683
-rw-r--r--sys/dev/ti/if_ti.c3626
-rw-r--r--sys/dev/ti/if_tireg.h1067
-rw-r--r--sys/dev/ti/ti_fw.h4593
-rw-r--r--sys/dev/ti/ti_fw2.h5232
-rw-r--r--sys/dev/vr/if_vr.c1805
-rw-r--r--sys/dev/vr/if_vrreg.h594
-rw-r--r--sys/fs/cd9660/TODO43
-rw-r--r--sys/fs/cd9660/TODO.hibler16
-rw-r--r--sys/fs/cd9660/cd9660_bmap.c106
-rw-r--r--sys/fs/cd9660/cd9660_lookup.c452
-rw-r--r--sys/fs/cd9660/cd9660_mount.h55
-rw-r--r--sys/fs/cd9660/cd9660_node.c444
-rw-r--r--sys/fs/cd9660/cd9660_node.h125
-rw-r--r--sys/fs/cd9660/cd9660_rrip.c717
-rw-r--r--sys/fs/cd9660/cd9660_rrip.h141
-rw-r--r--sys/fs/cd9660/cd9660_util.c188
-rw-r--r--sys/fs/cd9660/cd9660_vfsops.c898
-rw-r--r--sys/fs/cd9660/cd9660_vnops.c834
-rw-r--r--sys/fs/cd9660/iso.h357
-rw-r--r--sys/fs/cd9660/iso_rrip.h86
-rw-r--r--sys/fs/coda/README62
-rw-r--r--sys/fs/coda/TODO17
-rw-r--r--sys/fs/coda/cnode.h210
-rw-r--r--sys/fs/coda/coda.h761
-rw-r--r--sys/fs/coda/coda_fbsd.c219
-rw-r--r--sys/fs/coda/coda_io.h59
-rw-r--r--sys/fs/coda/coda_kernel.h66
-rw-r--r--sys/fs/coda/coda_namecache.c763
-rw-r--r--sys/fs/coda/coda_namecache.h194
-rw-r--r--sys/fs/coda/coda_opstats.h127
-rw-r--r--sys/fs/coda/coda_pioctl.h70
-rw-r--r--sys/fs/coda/coda_psdev.c685
-rw-r--r--sys/fs/coda/coda_psdev.h39
-rw-r--r--sys/fs/coda/coda_subr.c571
-rw-r--r--sys/fs/coda/coda_subr.h45
-rw-r--r--sys/fs/coda/coda_venus.c665
-rw-r--r--sys/fs/coda/coda_venus.h133
-rw-r--r--sys/fs/coda/coda_vfsops.c570
-rw-r--r--sys/fs/coda/coda_vfsops.h64
-rw-r--r--sys/fs/coda/coda_vnops.c2007
-rw-r--r--sys/fs/coda/coda_vnops.h87
-rw-r--r--sys/geom/geom_ccd.c1268
-rw-r--r--sys/gnu/fs/ext2fs/COPYRIGHT.INFO35
-rw-r--r--sys/gnu/fs/ext2fs/ext2_alloc.c539
-rw-r--r--sys/gnu/fs/ext2fs/ext2_balloc.c314
-rw-r--r--sys/gnu/fs/ext2fs/ext2_bmap.c334
-rw-r--r--sys/gnu/fs/ext2fs/ext2_extern.h116
-rw-r--r--sys/gnu/fs/ext2fs/ext2_fs.h549
-rw-r--r--sys/gnu/fs/ext2fs/ext2_fs_sb.h81
-rw-r--r--sys/gnu/fs/ext2fs/ext2_inode.c552
-rw-r--r--sys/gnu/fs/ext2fs/ext2_inode_cnv.c131
-rw-r--r--sys/gnu/fs/ext2fs/ext2_linux_balloc.c610
-rw-r--r--sys/gnu/fs/ext2fs/ext2_linux_ialloc.c514
-rw-r--r--sys/gnu/fs/ext2fs/ext2_lookup.c1108
-rw-r--r--sys/gnu/fs/ext2fs/ext2_mount.h74
-rw-r--r--sys/gnu/fs/ext2fs/ext2_readwrite.c312
-rw-r--r--sys/gnu/fs/ext2fs/ext2_subr.c127
-rw-r--r--sys/gnu/fs/ext2fs/ext2_vfsops.c1230
-rw-r--r--sys/gnu/fs/ext2fs/ext2_vnops.c1962
-rw-r--r--sys/gnu/fs/ext2fs/fs.h180
-rw-r--r--sys/gnu/fs/ext2fs/i386-bitops.h162
-rw-r--r--sys/gnu/fs/ext2fs/inode.h177
-rw-r--r--sys/gnu/fs/ext2fs/sparc64-bitops.h248
-rw-r--r--sys/i386/i386/apic_vector.s680
-rw-r--r--sys/i386/i386/mptable.c2839
-rw-r--r--sys/i386/include/apicreg.h444
-rw-r--r--sys/i386/include/mptable.h2839
-rw-r--r--sys/i386/isa/atpic_vector.s253
-rw-r--r--sys/i386/isa/nmi.c714
-rw-r--r--sys/i386/pci/pci_pir.c822
-rw-r--r--sys/i4b/include/i4b_cause.h147
-rw-r--r--sys/i4b/include/i4b_debug.h301
-rw-r--r--sys/i4b/include/i4b_ioctl.h742
-rw-r--r--sys/i4b/include/i4b_rbch_ioctl.h53
-rw-r--r--sys/i4b/include/i4b_tel_ioctl.h93
-rw-r--r--sys/i4b/include/i4b_trace.h90
-rw-r--r--sys/ia64/ia32/ia32_signal.c384
-rw-r--r--sys/ia64/ia64/context.S804
-rw-r--r--sys/ia64/ia64/exception.S1396
-rw-r--r--sys/ia64/ia64/locore.S439
-rw-r--r--sys/ia64/ia64/pal.S223
-rw-r--r--sys/ia64/ia64/setjmp.S348
-rw-r--r--sys/ia64/ia64/support.S901
-rw-r--r--sys/ia64/ia64/syscall.S562
-rw-r--r--sys/isa/atrtc.c1216
-rw-r--r--sys/kern/kern_kse.c2055
-rw-r--r--sys/kern/ksched.c300
-rw-r--r--sys/kern/link_elf_obj.c1312
-rw-r--r--sys/kern/p1003_1b.c348
-rw-r--r--sys/kern/posix4_mib.c148
-rw-r--r--sys/kern/subr_acl_posix1e.c939
-rw-r--r--sys/kern/subr_clist.c696
-rw-r--r--sys/kern/subr_rtc.c319
-rw-r--r--sys/kern/subr_turnstile.c987
-rw-r--r--sys/kern/uipc_sockbuf.c1007
-rw-r--r--sys/kern/vfs_acl.c939
-rw-r--r--sys/kern/vfs_extattr.c4326
-rw-r--r--sys/modules/mac_stub/Makefile9
-rw-r--r--sys/modules/sound/sound/Makefile17
-rw-r--r--sys/netatalk/ddp_pcb.c594
-rw-r--r--sys/netinet/libalias/HISTORY145
-rw-r--r--sys/netinet/libalias/Makefile11
-rw-r--r--sys/netinet/libalias/alias.c1582
-rw-r--r--sys/netinet/libalias/alias.h182
-rw-r--r--sys/netinet/libalias/alias_cuseeme.c121
-rw-r--r--sys/netinet/libalias/alias_db.c2931
-rw-r--r--sys/netinet/libalias/alias_ftp.c583
-rw-r--r--sys/netinet/libalias/alias_irc.c357
-rw-r--r--sys/netinet/libalias/alias_local.h229
-rw-r--r--sys/netinet/libalias/alias_nbt.c704
-rw-r--r--sys/netinet/libalias/alias_pptp.c369
-rw-r--r--sys/netinet/libalias/alias_proxy.c837
-rw-r--r--sys/netinet/libalias/alias_smedia.c433
-rw-r--r--sys/netinet/libalias/alias_util.c169
-rw-r--r--sys/netinet/libalias/libalias.3981
-rw-r--r--sys/netinet/tcp_reass.c2997
-rw-r--r--sys/netinet/tcp_timewait.c1955
-rw-r--r--sys/pc98/cbus/30line.h147
-rw-r--r--sys/pc98/cbus/cbus.h184
-rw-r--r--sys/pc98/cbus/cbus_dma.c625
-rw-r--r--sys/pc98/cbus/clock.c1146
-rw-r--r--sys/pc98/cbus/fdc.c3345
-rw-r--r--sys/pc98/cbus/fdcreg.h92
-rw-r--r--sys/pc98/cbus/gdc.c1443
-rw-r--r--sys/pc98/cbus/olpt.c818
-rw-r--r--sys/pc98/cbus/pckbd.c965
-rw-r--r--sys/pc98/cbus/pcrtc.c1146
-rw-r--r--sys/pc98/cbus/pmc.c244
-rw-r--r--sys/pc98/cbus/ppc.c2222
-rw-r--r--sys/pc98/cbus/ppcreg.h280
-rw-r--r--sys/pc98/cbus/sc_machdep.h56
-rw-r--r--sys/pc98/cbus/scgdcrndr.c207
-rw-r--r--sys/pc98/cbus/scterm-sck.c1217
-rw-r--r--sys/pc98/cbus/scvtb.c399
-rw-r--r--sys/pc98/cbus/sio.c5114
-rw-r--r--sys/pc98/cbus/sio_cbus.c110
-rw-r--r--sys/pc98/cbus/syscons_cbus.c263
-rw-r--r--sys/pc98/pc98/busio.s1774
-rw-r--r--sys/pc98/pc98/busiosubr.c273
-rw-r--r--sys/pc98/pc98/machdep.c2850
-rw-r--r--sys/powerpc/aim/clock.c332
-rw-r--r--sys/powerpc/aim/copyinout.c320
-rw-r--r--sys/powerpc/aim/interrupt.c117
-rw-r--r--sys/powerpc/aim/locore.S207
-rw-r--r--sys/powerpc/aim/machdep.c761
-rw-r--r--sys/powerpc/aim/mmu_oea.c2512
-rw-r--r--sys/powerpc/aim/nexus.c405
-rw-r--r--sys/powerpc/aim/ofw_machdep.c184
-rw-r--r--sys/powerpc/aim/ofwmagic.S75
-rw-r--r--sys/powerpc/aim/swtch.S158
-rw-r--r--sys/powerpc/aim/trap.c659
-rw-r--r--sys/powerpc/aim/trap_subr.S948
-rw-r--r--sys/powerpc/aim/vm_machdep.c292
-rw-r--r--sys/powerpc/powerpc/mmu_oea.c2512
-rw-r--r--sys/powerpc/psim/uart_iobus.c109
-rw-r--r--sys/rpc/types.h108
-rw-r--r--sys/security/mac/mac_framework.c3975
-rw-r--r--sys/security/mac/mac_framework.h347
-rw-r--r--sys/security/mac/mac_internal.h3975
-rw-r--r--sys/security/mac/mac_net.c3975
-rw-r--r--sys/security/mac/mac_pipe.c3975
-rw-r--r--sys/security/mac/mac_policy.h463
-rw-r--r--sys/security/mac/mac_process.c3975
-rw-r--r--sys/security/mac/mac_syscalls.c3975
-rw-r--r--sys/security/mac/mac_system.c3975
-rw-r--r--sys/security/mac/mac_vfs.c3975
-rw-r--r--sys/security/mac_stub/mac_stub.c1118
-rw-r--r--sys/sparc64/include/ofw_nexus.h72
-rw-r--r--sys/sparc64/pci/ofw_pci_if.m93
-rw-r--r--sys/sys/_semaphore.h71
-rw-r--r--sys/sys/aac_ioctl.h179
-rw-r--r--sys/sys/bitstring.h150
-rw-r--r--sys/sys/bus_dma.h241
-rw-r--r--sys/sys/ioctl_bt848.h298
-rw-r--r--sys/sys/ioctl_meteor.h187
-rw-r--r--sys/sys/linedisc.h358
-rw-r--r--sys/sys/posix4.h116
-rw-r--r--sys/sys/semaphore.h64
-rw-r--r--sys/tools/miidevs2h.awk147
-rw-r--r--sys/tools/pccarddevs2h.awk178
-rw-r--r--sys/tools/usbdevs2h.awk236
-rw-r--r--tools/build/make_check/Makefile95
-rw-r--r--tools/build/make_check/regress.sysvmatch.out1
-rw-r--r--tools/build/make_check/regress.variables.out1
-rw-r--r--tools/regression/usr.bin/sed/hanoi.sed103
-rw-r--r--tools/regression/usr.bin/sed/math.sed163
-rw-r--r--tools/regression/usr.bin/sed/multitest.t552
-rw-r--r--tools/regression/usr.bin/sed/sed.test552
-rw-r--r--usr.bin/gprof/amd64.c15
-rw-r--r--usr.bin/gprof/amd64.h44
-rw-r--r--usr.bin/truss/amd64-fbsd32.c343
-rw-r--r--usr.bin/truss/amd64-linux32.c339
-rw-r--r--usr.sbin/mount_nwfs/Makefile16
-rw-r--r--usr.sbin/mount_nwfs/mount_nwfs.8230
-rw-r--r--usr.sbin/mount_nwfs/mount_nwfs.c365
-rw-r--r--usr.sbin/mount_portalfs/Makefile15
-rw-r--r--usr.sbin/mount_portalfs/activate.c214
-rw-r--r--usr.sbin/mount_portalfs/conf.c340
-rw-r--r--usr.sbin/mount_portalfs/mount_portalfs.8152
-rw-r--r--usr.sbin/mount_portalfs/mount_portalfs.c284
-rw-r--r--usr.sbin/mount_portalfs/pathnames.h44
-rw-r--r--usr.sbin/mount_portalfs/portal.conf7
-rw-r--r--usr.sbin/mount_portalfs/portald.h84
-rw-r--r--usr.sbin/mount_portalfs/pt_conf.c55
-rw-r--r--usr.sbin/mount_portalfs/pt_exec.c60
-rw-r--r--usr.sbin/mount_portalfs/pt_file.c109
-rw-r--r--usr.sbin/mount_portalfs/pt_tcp.c167
-rw-r--r--usr.sbin/mount_portalfs/pt_tcplisten.c206
-rw-r--r--usr.sbin/mount_smbfs/Makefile22
-rw-r--r--usr.sbin/nologin/Makefile7
-rw-r--r--usr.sbin/nologin/nologin.572
-rw-r--r--usr.sbin/nologin/nologin.861
-rw-r--r--usr.sbin/nologin/nologin.sh39
-rw-r--r--usr.sbin/sade/Makefile93
-rw-r--r--usr.sbin/sade/command.c184
-rw-r--r--usr.sbin/sade/config.c1093
-rw-r--r--usr.sbin/sade/devices.c578
-rw-r--r--usr.sbin/sade/disks.c985
-rw-r--r--usr.sbin/sade/dispatch.c448
-rw-r--r--usr.sbin/sade/dmenu.c316
-rw-r--r--usr.sbin/sade/globals.c73
-rw-r--r--usr.sbin/sade/help/partition.hlp169
-rw-r--r--usr.sbin/sade/help/slice.hlp65
-rw-r--r--usr.sbin/sade/install.c1262
-rw-r--r--usr.sbin/sade/keymap.c95
-rw-r--r--usr.sbin/sade/label.c1607
-rw-r--r--usr.sbin/sade/list.h60
-rw-r--r--usr.sbin/sade/main.c185
-rw-r--r--usr.sbin/sade/menus.c2422
-rw-r--r--usr.sbin/sade/misc.c529
-rw-r--r--usr.sbin/sade/msg.c356
-rw-r--r--usr.sbin/sade/rtermcap.c15
-rw-r--r--usr.sbin/sade/sade.81010
-rw-r--r--usr.sbin/sade/sade.h881
-rw-r--r--usr.sbin/sade/system.c537
-rw-r--r--usr.sbin/sade/termcap.c150
-rw-r--r--usr.sbin/sade/usb.c44
-rw-r--r--usr.sbin/sade/variable.c296
-rw-r--r--usr.sbin/sade/wizard.c200
678 files changed, 14 insertions, 316839 deletions
diff --git a/bin/csh/config_p.h b/bin/csh/config_p.h
deleted file mode 100644
index 9e91642bb5eb..000000000000
--- a/bin/csh/config_p.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/* config.h. Generated automatically by configure. */
-/*
- * config.h -- configure various defines for tcsh
- *
- * All source files should #include this FIRST.
- *
- * Edit this to match your system type.
- */
-
-/* $FreeBSD$ */
-
-#ifndef _h_config
-#define _h_config
-/****************** System dependant compilation flags ****************/
-/*
- * POSIX This system supports IEEE Std 1003.1-1988 (POSIX).
- */
-#define POSIX
-
-/*
- * POSIXJOBS This system supports the optional IEEE Std 1003.1-1988 (POSIX)
- * job control facilities.
- */
-#define POSIXJOBS
-
-/*
- * POSIXSIGS Use the POSIX signal facilities to emulate BSD signals.
- */
-/* #undef POSIXSIGS */
-
-/*
- * VFORK This machine has a vfork().
- * It used to be that for job control to work, this define
- * was mandatory. This is not the case any more.
- * If you think you still need it, but you don't have vfork,
- * define this anyway and then do #define vfork fork.
- * I do this anyway on a Sun because of yellow pages brain damage,
- * [should not be needed under 4.1]
- * and on the iris4d cause SGI's fork is sufficiently "virtual"
- * that vfork isn't necessary. (Besides, SGI's vfork is weird).
- * Note that some machines eg. rs6000 have a vfork, but not
- * with the berkeley semantics, so we cannot use it there either.
- */
-#define VFORK
-
-/*
- * BSDJOBS You have BSD-style job control (both process groups and
- * a tty that deals correctly
- */
-#define BSDJOBS
-
-/*
- * BSDSIGS You have 4.2-style signals, rather than USG style.
- * Note: POSIX systems should not define this unless they
- * have sigvec() and friends (ie: 4.3BSD-RENO, HP-UX).
- */
-#define BSDSIGS
-
-/*
- * BSDTIMES You have BSD-style process time stuff (like rusage)
- * This may or may not be true. For example, Apple Unix
- * (OREO) has BSDJOBS and BSDSIGS but not BSDTIMES.
- */
-#define BSDTIMES
-
-/*
- * BSDLIMIT You have BSD-style resource limit stuff (getrlimit/setrlimit)
- */
-#define BSDLIMIT
-
-/*
- * BSDNICE Your system uses setpriority() instead of nice, to
- * change a processes scheduling priority
- */
-#define BSDNICE
-
-/*
- * TERMIO You have struct termio instead of struct sgttyb.
- * This is usually the case for SYSV systems, where
- * BSD uses sgttyb. POSIX systems should define this
- * anyway, even though they use struct termios.
- */
-#define TERMIO
-
-/*
- * SYSVREL Your machine is SYSV based (HPUX, A/UX)
- * NOTE: don't do this if you are on a Pyramid -- tcsh is
- * built in a BSD universe.
- * Set SYSVREL to 1, 2, 3, or 4, depending the version of System V
- * you are running. Or set it to 0 if you are not SYSV based
- */
-#define SYSVREL 0
-
-/*
- * YPBUGS Work around Sun YP bugs that cause expansion of ~username
- * to send command output to /dev/null
- */
-/* #undef YPBUGS */
-
-/*
- * SIGVOID Define this if your signal handlers return void. On older
- * systems, signal returns int, but on newer ones, it returns void.
- */
-#define SIGVOID
-
-/*
- * HAVEDUP2 Define this if your system supports dup2().
- */
-#define HAVEDUP2
-
-/*
- * UTHOST Does the utmp file have a host field?
- */
-#define UTHOST
-
-/*
- * DIRENT Your system has <dirent.h> instead of <sys/dir.h>
- */
-#define DIRENT
-/****************** local defines *********************/
-/****************** configurable hacks ****************/
-
-#include <stdlib.h>
-
-/* have been moved to config_f.h */
-#include "config_f.h"
-
-#if defined(__FreeBSD__)
-#define NLS_BUGS
-/* we want to use the system malloc when we install as /bin/csh */
-#define SYSMALLOC
-#define BSD_STYLE_COLORLS
-#endif
-
-#if defined(__bsdi__)
-/*
- * _PATH_TCSHELL if you've change the installation location (vix)
- */
-# if _BSDI_VERSION >= 199701
-# define _PATH_TCSHELL "/bin/tcsh"
-/* # undef SYSMALLOC */
-# define SYSMALLOC
-# else
-# define _PATH_TCSHELL "/usr/contrib/bin/tcsh"
-# endif
-
-# undef NLS
-# undef NLS_CATALOGS
-
-#elif defined(__APPLE__)
-# define SYSMALLOC
-
-#else
-# define NLS_CATALOGS
-#endif
-
-#define KANJI
-#define DSPMBYTE
-
-#endif /* _h_config */
-/* config.h.in. Generated automatically from configure.in by autoheader. */
diff --git a/bin/uuidgen/Makefile b/bin/uuidgen/Makefile
deleted file mode 100644
index 81459e2339d6..000000000000
--- a/bin/uuidgen/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-# $FreeBSD$
-
-PROG= uuidgen
-WARNS?= 4
-
-.include <bsd.prog.mk>
diff --git a/bin/uuidgen/uuidgen.1 b/bin/uuidgen/uuidgen.1
deleted file mode 100644
index 5e974755e0c5..000000000000
--- a/bin/uuidgen/uuidgen.1
+++ /dev/null
@@ -1,79 +0,0 @@
-.\" 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.
-.\" 2. Redistributions in binary form must 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.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd May 23, 2002
-.Dt UUIDGEN 1
-.Os
-.Sh NAME
-.Nm uuidgen
-.Nd generate universally unique identifiers
-.Sh SYNOPSIS
-.Nm
-.Op Fl 1
-.Op Fl n Ar count
-.Op Fl o Ar filename
-.Sh DESCRIPTION
-The
-.Nm
-utility by default generates a single universally unique identifier (UUID),
-also known as a globally unique identifier (GUID).
-The UUID is written to stdout by default.
-The following options can be used to change the behaviour of
-.Nm :
-.Bl -tag -width indent
-.It Fl 1
-This option only has effect if multiple identifiers are to be generated and
-instructs
-.Nm
-to not generate them in batch, but one at a time.
-.It Fl n
-This option controls the number of identifiers generated.
-By default, multiple
-identifiers are generated in batch.
-.It Fl o
-Redirect output to
-.Ar filename
-instead of stdout.
-.El
-.Pp
-Batched generation yields a dense set of identifiers in such a way that there
-is no identifier that is larger than the smallest identifier in the set and
-smaller than the largest identifier in the set and that is not already in the
-set.
-.Pp
-When generating the identifiers one at a time, the identifiers will be close
-to each other, but operating system latency and processing time will be
-reflected in the distance between two successive identifiers.
-.Sh DIAGNOSTICS
-.Ex -std
-.Sh SEE ALSO
-.Xr uuidgen 2 ,
-.Xr uuid 3
-.Sh HISTORY
-The
-.Nm
-command first appeared in
-.Fx 5.0 .
diff --git a/bin/uuidgen/uuidgen.c b/bin/uuidgen/uuidgen.c
deleted file mode 100644
index d5dac4bcacfb..000000000000
--- a/bin/uuidgen/uuidgen.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.
- * 2. Redistributions in binary form must 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$");
-
-#include <err.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <uuid.h>
-
-static void
-usage(void)
-{
- (void)fprintf(stderr, "usage: uuidgen [-1] [-n count] [-o filename]\n");
- exit(1);
-}
-
-int
-main(int argc, char *argv[])
-{
- FILE *fp;
- uuid_t *store, *uuid;
- char *p;
- int ch, count, i, iterate;
-
- count = -1; /* no count yet */
- fp = stdout; /* default output file */
- iterate = 0; /* not one at a time */
- while ((ch = getopt(argc, argv, "1n:o:")) != -1)
- switch (ch) {
- case '1':
- iterate = 1;
- break;
- case 'n':
- if (count > 0)
- usage();
- count = strtol(optarg, &p, 10);
- if (*p != 0 || count < 1)
- usage();
- break;
- case 'o':
- if (fp != stdout)
- errx(1, "multiple output files not allowed");
- fp = fopen(optarg, "w");
- if (fp == NULL)
- err(1, "fopen");
- break;
- default:
- usage();
- }
- argv += optind;
- argc -= optind;
-
- if (argc)
- usage();
-
- if (count == -1)
- count = 1;
-
- store = (uuid_t*)malloc(sizeof(uuid_t) * count);
- if (store == NULL)
- err(1, "malloc()");
-
- if (!iterate) {
- /* Get them all in a single batch */
- if (uuidgen(store, count) != 0)
- err(1, "uuidgen()");
- } else {
- uuid = store;
- for (i = 0; i < count; i++) {
- if (uuidgen(uuid++, 1) != 0)
- err(1, "uuidgen()");
- }
- }
-
- uuid = store;
- while (count--) {
- uuid_to_string(uuid++, &p, NULL);
- fprintf(fp, "%s\n", p);
- free(p);
- }
-
- free(store);
- if (fp != stdout)
- fclose(fp);
- return (0);
-}
diff --git a/contrib/telnet/arpa/telnet.h b/contrib/telnet/arpa/telnet.h
deleted file mode 100644
index c937f03eacde..000000000000
--- a/contrib/telnet/arpa/telnet.h
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)telnet.h 8.2 (Berkeley) 12/15/93
- * $FreeBSD$
- */
-
-#ifndef _ARPA_TELNET_H_
-#define _ARPA_TELNET_H_
-
-/*
- * Definitions for the TELNET protocol.
- */
-#define IAC 255 /* interpret as command: */
-#define DONT 254 /* you are not to use option */
-#define DO 253 /* please, you use option */
-#define WONT 252 /* I won't use option */
-#define WILL 251 /* I will use option */
-#define SB 250 /* interpret as subnegotiation */
-#define GA 249 /* you may reverse the line */
-#define EL 248 /* erase the current line */
-#define EC 247 /* erase the current character */
-#define AYT 246 /* are you there */
-#define AO 245 /* abort output--but let prog finish */
-#define IP 244 /* interrupt process--permanently */
-#define BREAK 243 /* break */
-#define DM 242 /* data mark--for connect. cleaning */
-#define NOP 241 /* nop */
-#define SE 240 /* end sub negotiation */
-#define EOR 239 /* end of record (transparent mode) */
-#define ABORT 238 /* Abort process */
-#define SUSP 237 /* Suspend process */
-#define xEOF 236 /* End of file: EOF is already used... */
-
-#define SYNCH 242 /* for telfunc calls */
-
-#ifdef TELCMDS
-const char *telcmds[] = {
- "EOF", "SUSP", "ABORT", "EOR",
- "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
- "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC",
- 0
-};
-#else
-extern char *telcmds[];
-#endif
-
-#define TELCMD_FIRST xEOF
-#define TELCMD_LAST IAC
-#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \
- (unsigned int)(x) >= TELCMD_FIRST)
-#define TELCMD(x) telcmds[(x)-TELCMD_FIRST]
-
-/* telnet options */
-#define TELOPT_BINARY 0 /* 8-bit data path */
-#define TELOPT_ECHO 1 /* echo */
-#define TELOPT_RCP 2 /* prepare to reconnect */
-#define TELOPT_SGA 3 /* suppress go ahead */
-#define TELOPT_NAMS 4 /* approximate message size */
-#define TELOPT_STATUS 5 /* give status */
-#define TELOPT_TM 6 /* timing mark */
-#define TELOPT_RCTE 7 /* remote controlled transmission and echo */
-#define TELOPT_NAOL 8 /* negotiate about output line width */
-#define TELOPT_NAOP 9 /* negotiate about output page size */
-#define TELOPT_NAOCRD 10 /* negotiate about CR disposition */
-#define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */
-#define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */
-#define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */
-#define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */
-#define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */
-#define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */
-#define TELOPT_XASCII 17 /* extended ascic character set */
-#define TELOPT_LOGOUT 18 /* force logout */
-#define TELOPT_BM 19 /* byte macro */
-#define TELOPT_DET 20 /* data entry terminal */
-#define TELOPT_SUPDUP 21 /* supdup protocol */
-#define TELOPT_SUPDUPOUTPUT 22 /* supdup output */
-#define TELOPT_SNDLOC 23 /* send location */
-#define TELOPT_TTYPE 24 /* terminal type */
-#define TELOPT_EOR 25 /* end or record */
-#define TELOPT_TUID 26 /* TACACS user identification */
-#define TELOPT_OUTMRK 27 /* output marking */
-#define TELOPT_TTYLOC 28 /* terminal location number */
-#define TELOPT_3270REGIME 29 /* 3270 regime */
-#define TELOPT_X3PAD 30 /* X.3 PAD */
-#define TELOPT_NAWS 31 /* window size */
-#define TELOPT_TSPEED 32 /* terminal speed */
-#define TELOPT_LFLOW 33 /* remote flow control */
-#define TELOPT_LINEMODE 34 /* Linemode option */
-#define TELOPT_XDISPLOC 35 /* X Display Location */
-#define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */
-#define TELOPT_AUTHENTICATION 37/* Authenticate */
-#define TELOPT_ENCRYPT 38 /* Encryption option */
-#define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */
-#define TELOPT_TN3270E 40 /* RFC2355 - TN3270 Enhancements */
-#define TELOPT_CHARSET 42 /* RFC2066 - Charset */
-#define TELOPT_COMPORT 44 /* RFC2217 - Com Port Control */
-#define TELOPT_KERMIT 47 /* RFC2840 - Kermit */
-#define TELOPT_EXOPL 255 /* extended-options-list */
-
-
-#define NTELOPTS (1+TELOPT_KERMIT)
-#ifdef TELOPTS
-const char *telopts[NTELOPTS+1] = {
- "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
- "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
- "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
- "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
- "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
- "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD",
- "TACACS UID", "OUTPUT MARKING", "TTYLOC",
- "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
- "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION",
- "ENCRYPT", "NEW-ENVIRON", "TN3270E", "CHARSET", "COM-PORT",
- "KERMIT",
- 0
-};
-#define TELOPT_FIRST TELOPT_BINARY
-#define TELOPT_LAST TELOPT_KERMIT
-#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST)
-#define TELOPT(x) telopts[(x)-TELOPT_FIRST]
-#endif
-
-/* sub-option qualifiers */
-#define TELQUAL_IS 0 /* option is... */
-#define TELQUAL_SEND 1 /* send option */
-#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */
-#define TELQUAL_REPLY 2 /* AUTHENTICATION: client version of IS */
-#define TELQUAL_NAME 3 /* AUTHENTICATION: client version of IS */
-
-#define LFLOW_OFF 0 /* Disable remote flow control */
-#define LFLOW_ON 1 /* Enable remote flow control */
-#define LFLOW_RESTART_ANY 2 /* Restart output on any char */
-#define LFLOW_RESTART_XON 3 /* Restart output only on XON */
-
-/*
- * LINEMODE suboptions
- */
-
-#define LM_MODE 1
-#define LM_FORWARDMASK 2
-#define LM_SLC 3
-
-#define MODE_EDIT 0x01
-#define MODE_TRAPSIG 0x02
-#define MODE_ACK 0x04
-#define MODE_SOFT_TAB 0x08
-#define MODE_LIT_ECHO 0x10
-
-#define MODE_MASK 0x1f
-
-/* Not part of protocol, but needed to simplify things... */
-#define MODE_FLOW 0x0100
-#define MODE_ECHO 0x0200
-#define MODE_INBIN 0x0400
-#define MODE_OUTBIN 0x0800
-#define MODE_FORCE 0x1000
-
-#define SLC_SYNCH 1
-#define SLC_BRK 2
-#define SLC_IP 3
-#define SLC_AO 4
-#define SLC_AYT 5
-#define SLC_EOR 6
-#define SLC_ABORT 7
-#define SLC_EOF 8
-#define SLC_SUSP 9
-#define SLC_EC 10
-#define SLC_EL 11
-#define SLC_EW 12
-#define SLC_RP 13
-#define SLC_LNEXT 14
-#define SLC_XON 15
-#define SLC_XOFF 16
-#define SLC_FORW1 17
-#define SLC_FORW2 18
-#define SLC_MCL 19
-#define SLC_MCR 20
-#define SLC_MCWL 21
-#define SLC_MCWR 22
-#define SLC_MCBOL 23
-#define SLC_MCEOL 24
-#define SLC_INSRT 25
-#define SLC_OVER 26
-#define SLC_ECR 27
-#define SLC_EWR 28
-#define SLC_EBOL 29
-#define SLC_EEOL 30
-
-#define NSLC 30
-
-/*
- * For backwards compatibility, we define SLC_NAMES to be the
- * list of names if SLC_NAMES is not defined.
- */
-#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \
- "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \
- "LNEXT", "XON", "XOFF", "FORW1", "FORW2", \
- "MCL", "MCR", "MCWL", "MCWR", "MCBOL", \
- "MCEOL", "INSRT", "OVER", "ECR", "EWR", \
- "EBOL", "EEOL", \
- 0
-
-#ifdef SLC_NAMES
-const char *slc_names[] = {
- SLC_NAMELIST
-};
-#else
-extern char *slc_names[];
-#define SLC_NAMES SLC_NAMELIST
-#endif
-
-#define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC)
-#define SLC_NAME(x) slc_names[x]
-
-#define SLC_NOSUPPORT 0
-#define SLC_CANTCHANGE 1
-#define SLC_VARIABLE 2
-#define SLC_DEFAULT 3
-#define SLC_LEVELBITS 0x03
-
-#define SLC_FUNC 0
-#define SLC_FLAGS 1
-#define SLC_VALUE 2
-
-#define SLC_ACK 0x80
-#define SLC_FLUSHIN 0x40
-#define SLC_FLUSHOUT 0x20
-
-#define OLD_ENV_VAR 1
-#define OLD_ENV_VALUE 0
-#define NEW_ENV_VAR 0
-#define NEW_ENV_VALUE 1
-#define ENV_ESC 2
-#define ENV_USERVAR 3
-
-/*
- * AUTHENTICATION suboptions
- */
-
-/*
- * Who is authenticating who ...
- */
-#define AUTH_WHO_CLIENT 0 /* Client authenticating server */
-#define AUTH_WHO_SERVER 1 /* Server authenticating client */
-#define AUTH_WHO_MASK 1
-
-/*
- * amount of authentication done
- */
-#define AUTH_HOW_ONE_WAY 0
-#define AUTH_HOW_MUTUAL 2
-#define AUTH_HOW_MASK 2
-
-#define AUTHTYPE_NULL 0
-#define AUTHTYPE_KERBEROS_V4 1
-#define AUTHTYPE_KERBEROS_V5 2
-#define AUTHTYPE_SPX 3
-#define AUTHTYPE_MINK 4
-#define AUTHTYPE_SRA 6
-#define AUTHTYPE_CNT 7
-
-#define AUTHTYPE_TEST 99
-
-#ifdef AUTH_NAMES
-const char *authtype_names[] = {
- "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", NULL, "SRA",
- 0
-};
-#else
-extern char *authtype_names[];
-#endif
-
-#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT)
-#define AUTHTYPE_NAME(x) authtype_names[x]
-
-/*
- * ENCRYPTion suboptions
- */
-#define ENCRYPT_IS 0 /* I pick encryption type ... */
-#define ENCRYPT_SUPPORT 1 /* I support encryption types ... */
-#define ENCRYPT_REPLY 2 /* Initial setup response */
-#define ENCRYPT_START 3 /* Am starting to send encrypted */
-#define ENCRYPT_END 4 /* Am ending encrypted */
-#define ENCRYPT_REQSTART 5 /* Request you start encrypting */
-#define ENCRYPT_REQEND 6 /* Request you end encrypting */
-#define ENCRYPT_ENC_KEYID 7
-#define ENCRYPT_DEC_KEYID 8
-#define ENCRYPT_CNT 9
-
-#define ENCTYPE_ANY 0
-#define ENCTYPE_DES_CFB64 1
-#define ENCTYPE_DES_OFB64 2
-#define ENCTYPE_CNT 3
-
-#ifdef ENCRYPT_NAMES
-const char *encrypt_names[] = {
- "IS", "SUPPORT", "REPLY", "START", "END",
- "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID",
- 0
-};
-const char *enctype_names[] = {
- "ANY", "DES_CFB64", "DES_OFB64",
- 0
-};
-#else
-extern char *encrypt_names[];
-extern char *enctype_names[];
-#endif
-
-
-#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT)
-#define ENCRYPT_NAME(x) encrypt_names[x]
-
-#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT)
-#define ENCTYPE_NAME(x) enctype_names[x]
-
-#endif /* !_TELNET_H_ */
diff --git a/contrib/telnet/libtelnet/auth-proto.h b/contrib/telnet/libtelnet/auth-proto.h
deleted file mode 100644
index 6d3ba7f07493..000000000000
--- a/contrib/telnet/libtelnet/auth-proto.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)auth-proto.h 8.1 (Berkeley) 6/4/93
- * $FreeBSD$
- */
-
-/*
- * Copyright (C) 1990 by the Massachusetts Institute of Technology
- *
- * Export of this software from the United States of America is assumed
- * to require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifdef AUTHENTICATION
-
-Authenticator *findauthenticator(int, int);
-
-void auth_init(const char *, int);
-int auth_cmd(int, char **);
-void auth_request(void);
-void auth_send(unsigned char *, int);
-void auth_send_retry(void);
-void auth_is(unsigned char *, int);
-void auth_reply(unsigned char *, int);
-void auth_finished(Authenticator *, int);
-int auth_wait(char *);
-void auth_disable_name(char *);
-void auth_gen_printsub(unsigned char *, int, unsigned char *, int);
-void auth_name(unsigned char *, int);
-void auth_printsub(unsigned char *, int, unsigned char *, int);
-int auth_sendname(unsigned char *, int);
-void auth_encrypt_user(char *);
-int auth_disable(char *);
-int auth_enable(char *);
-int auth_togdebug(int);
-int auth_status(void);
-
-int getauthmask(char *, int *);
-
-#ifdef KRB4
-int kerberos4_init(Authenticator *, int);
-int kerberos4_send(Authenticator *);
-void kerberos4_is(Authenticator *, unsigned char *, int);
-void kerberos4_reply(Authenticator *, unsigned char *, int);
-int kerberos4_status(Authenticator *, char *, int);
-void kerberos4_printsub(unsigned char *, int, unsigned char *, int);
-#endif
-
-#ifdef KRB5
-int kerberos5_init(Authenticator *, int);
-int kerberos5_send_mutual(Authenticator *);
-int kerberos5_send_oneway(Authenticator *);
-void kerberos5_is(Authenticator *, unsigned char *, int);
-void kerberos5_reply(Authenticator *, unsigned char *, int);
-int kerberos5_status(Authenticator *, char *, int level);
-void kerberos5_printsub(unsigned char *, int, unsigned char *, int);
-#endif
-
-#ifdef SRA
-int sra_init(Authenticator *, int);
-int sra_send(Authenticator *);
-void sra_is(Authenticator *, unsigned char *, int);
-void sra_reply(Authenticator *, unsigned char *, int);
-int sra_status(Authenticator *, char *, int);
-void sra_printsub(unsigned char *, int, unsigned char *, int);
-#endif
-
-#endif
diff --git a/contrib/telnet/libtelnet/auth.c b/contrib/telnet/libtelnet/auth.c
deleted file mode 100644
index 46426559e088..000000000000
--- a/contrib/telnet/libtelnet/auth.c
+++ /dev/null
@@ -1,623 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)auth.c 8.3 (Berkeley) 5/30/95";
-#endif /* not lint */
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-
-/*
- * Copyright (C) 1990 by the Massachusetts Institute of Technology
- *
- * Export of this software from the United States of America is assumed
- * to require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-
-#ifdef AUTHENTICATION
-#define AUTH_NAMES
-#include <sys/types.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <arpa/telnet.h>
-
-#include "encrypt.h"
-#include "auth.h"
-#include "misc-proto.h"
-#include "auth-proto.h"
-
-#define typemask(x) ((x) > 0 ? 1 << ((x)-1) : 0)
-
-#ifdef KRB4_ENCPWD
-extern krb4encpwd_init();
-extern krb4encpwd_send();
-extern krb4encpwd_is();
-extern krb4encpwd_reply();
-extern krb4encpwd_status();
-extern krb4encpwd_printsub();
-#endif
-
-#ifdef RSA_ENCPWD
-extern rsaencpwd_init();
-extern rsaencpwd_send();
-extern rsaencpwd_is();
-extern rsaencpwd_reply();
-extern rsaencpwd_status();
-extern rsaencpwd_printsub();
-#endif
-
-int auth_debug_mode = 0;
-static const char *Name = "Noname";
-static int Server = 0;
-static Authenticator *authenticated = 0;
-static int authenticating = 0;
-static int validuser = 0;
-static unsigned char _auth_send_data[256];
-static unsigned char *auth_send_data;
-static int auth_send_cnt = 0;
-
-int auth_onoff(char *type, int on);
-void auth_encrypt_user(char *name);
-
-/*
- * Authentication types supported. Plese note that these are stored
- * in priority order, i.e. try the first one first.
- */
-Authenticator authenticators[] = {
-#ifdef KRB5
-# ifdef ENCRYPTION
- { AUTHTYPE_KERBEROS_V5, AUTH_WHO_CLIENT|AUTH_HOW_MUTUAL,
- kerberos5_init,
- kerberos5_send_mutual,
- kerberos5_is,
- kerberos5_reply,
- kerberos5_status,
- kerberos5_printsub },
-# endif /* ENCRYPTION */
- { AUTHTYPE_KERBEROS_V5, AUTH_WHO_CLIENT|AUTH_HOW_ONE_WAY,
- kerberos5_init,
- kerberos5_send_oneway,
- kerberos5_is,
- kerberos5_reply,
- kerberos5_status,
- kerberos5_printsub },
-#endif
-#ifdef KRB4
-# ifdef ENCRYPTION
- { AUTHTYPE_KERBEROS_V4, AUTH_WHO_CLIENT|AUTH_HOW_MUTUAL,
- kerberos4_init,
- kerberos4_send,
- kerberos4_is,
- kerberos4_reply,
- kerberos4_status,
- kerberos4_printsub },
-# endif /* ENCRYPTION */
- { AUTHTYPE_KERBEROS_V4, AUTH_WHO_CLIENT|AUTH_HOW_ONE_WAY,
- kerberos4_init,
- kerberos4_send,
- kerberos4_is,
- kerberos4_reply,
- kerberos4_status,
- kerberos4_printsub },
-#endif
-#ifdef KRB4_ENCPWD
- { AUTHTYPE_KRB4_ENCPWD, AUTH_WHO_CLIENT|AUTH_HOW_MUTUAL,
- krb4encpwd_init,
- krb4encpwd_send,
- krb4encpwd_is,
- krb4encpwd_reply,
- krb4encpwd_status,
- krb4encpwd_printsub },
-#endif
-#ifdef RSA_ENCPWD
- { AUTHTYPE_RSA_ENCPWD, AUTH_WHO_CLIENT|AUTH_HOW_ONE_WAY,
- rsaencpwd_init,
- rsaencpwd_send,
- rsaencpwd_is,
- rsaencpwd_reply,
- rsaencpwd_status,
- rsaencpwd_printsub },
-#endif
-#ifdef SRA
- { AUTHTYPE_SRA, AUTH_WHO_CLIENT|AUTH_HOW_ONE_WAY,
- sra_init,
- sra_send,
- sra_is,
- sra_reply,
- sra_status,
- sra_printsub },
-
-#endif
- { 0, 0, 0, 0, 0, 0, 0, 0 },
-};
-
-static Authenticator NoAuth = { 0, 0, 0, 0, 0, 0, 0, 0 };
-
-static int i_support = 0;
-static int i_wont_support = 0;
-
-Authenticator *
-findauthenticator(int type, int way)
-{
- Authenticator *ap = authenticators;
-
- while (ap->type && (ap->type != type || ap->way != way))
- ++ap;
- return(ap->type ? ap : 0);
-}
-
-void
-auth_init(const char *name, int server)
-{
- Authenticator *ap = authenticators;
-
- Server = server;
- Name = name;
-
- i_support = 0;
- authenticated = 0;
- authenticating = 0;
- while (ap->type) {
- if (!ap->init || (*ap->init)(ap, server)) {
- i_support |= typemask(ap->type);
- if (auth_debug_mode)
- printf(">>>%s: I support auth type %d %d\r\n",
- Name,
- ap->type, ap->way);
- }
- else if (auth_debug_mode)
- printf(">>>%s: Init failed: auth type %d %d\r\n",
- Name, ap->type, ap->way);
- ++ap;
- }
-}
-
-void
-auth_disable_name(char *name)
-{
- int x;
- for (x = 0; x < AUTHTYPE_CNT; ++x) {
- if (AUTHTYPE_NAME(x) && !strcasecmp(name, AUTHTYPE_NAME(x))) {
- i_wont_support |= typemask(x);
- break;
- }
- }
-}
-
-int
-getauthmask(char *type, int *maskp)
-{
- int x;
-
- if (AUTHTYPE_NAME(0) && !strcasecmp(type, AUTHTYPE_NAME(0))) {
- *maskp = -1;
- return(1);
- }
-
- for (x = 1; x < AUTHTYPE_CNT; ++x) {
- if (AUTHTYPE_NAME(x) && !strcasecmp(type, AUTHTYPE_NAME(x))) {
- *maskp = typemask(x);
- return(1);
- }
- }
- return(0);
-}
-
-int
-auth_enable(char *type)
-{
- return(auth_onoff(type, 1));
-}
-
-int
-auth_disable(char *type)
-{
- return(auth_onoff(type, 0));
-}
-
-int
-auth_onoff(char *type, int on)
-{
- int i, mask = -1;
- Authenticator *ap;
-
- if (!strcasecmp(type, "?") || !strcasecmp(type, "help")) {
- printf("auth %s 'type'\n", on ? "enable" : "disable");
- printf("Where 'type' is one of:\n");
- printf("\t%s\n", AUTHTYPE_NAME(0));
- mask = 0;
- for (ap = authenticators; ap->type; ap++) {
- if ((mask & (i = typemask(ap->type))) != 0)
- continue;
- mask |= i;
- printf("\t%s\n", AUTHTYPE_NAME(ap->type));
- }
- return(0);
- }
-
- if (!getauthmask(type, &mask)) {
- printf("%s: invalid authentication type\n", type);
- return(0);
- }
- if (on)
- i_wont_support &= ~mask;
- else
- i_wont_support |= mask;
- return(1);
-}
-
-int
-auth_togdebug(int on)
-{
- if (on < 0)
- auth_debug_mode ^= 1;
- else
- auth_debug_mode = on;
- printf("auth debugging %s\n", auth_debug_mode ? "enabled" : "disabled");
- return(1);
-}
-
-int
-auth_status(void)
-{
- Authenticator *ap;
- int i, mask;
-
- if (i_wont_support == -1)
- printf("Authentication disabled\n");
- else
- printf("Authentication enabled\n");
-
- mask = 0;
- for (ap = authenticators; ap->type; ap++) {
- if ((mask & (i = typemask(ap->type))) != 0)
- continue;
- mask |= i;
- printf("%s: %s\n", AUTHTYPE_NAME(ap->type),
- (i_wont_support & typemask(ap->type)) ?
- "disabled" : "enabled");
- }
- return(1);
-}
-
-/*
- * This routine is called by the server to start authentication
- * negotiation.
- */
-void
-auth_request(void)
-{
- static unsigned char str_request[64] = { IAC, SB,
- TELOPT_AUTHENTICATION,
- TELQUAL_SEND, };
- Authenticator *ap = authenticators;
- unsigned char *e = str_request + 4;
-
- if (!authenticating) {
- authenticating = 1;
- while (ap->type) {
- if (i_support & ~i_wont_support & typemask(ap->type)) {
- if (auth_debug_mode) {
- printf(">>>%s: Sending type %d %d\r\n",
- Name, ap->type, ap->way);
- }
- *e++ = ap->type;
- *e++ = ap->way;
- }
- ++ap;
- }
- *e++ = IAC;
- *e++ = SE;
- net_write(str_request, e - str_request);
- printsub('>', &str_request[2], e - str_request - 2);
- }
-}
-
-/*
- * This is called when an AUTH SEND is received.
- * It should never arrive on the server side (as only the server can
- * send an AUTH SEND).
- * You should probably respond to it if you can...
- *
- * If you want to respond to the types out of order (i.e. even
- * if he sends LOGIN KERBEROS and you support both, you respond
- * with KERBEROS instead of LOGIN (which is against what the
- * protocol says)) you will have to hack this code...
- */
-void
-auth_send(unsigned char *data, int cnt)
-{
- Authenticator *ap;
- static unsigned char str_none[] = { IAC, SB, TELOPT_AUTHENTICATION,
- TELQUAL_IS, AUTHTYPE_NULL, 0,
- IAC, SE };
- if (Server) {
- if (auth_debug_mode) {
- printf(">>>%s: auth_send called!\r\n", Name);
- }
- return;
- }
-
- if (auth_debug_mode) {
- printf(">>>%s: auth_send got:", Name);
- printd(data, cnt); printf("\r\n");
- }
-
- /*
- * Save the data, if it is new, so that we can continue looking
- * at it if the authorization we try doesn't work
- */
- if (data < _auth_send_data ||
- data > _auth_send_data + sizeof(_auth_send_data)) {
- auth_send_cnt = (size_t)cnt > sizeof(_auth_send_data)
- ? sizeof(_auth_send_data)
- : cnt;
- memmove((void *)_auth_send_data, (void *)data, auth_send_cnt);
- auth_send_data = _auth_send_data;
- } else {
- /*
- * This is probably a no-op, but we just make sure
- */
- auth_send_data = data;
- auth_send_cnt = cnt;
- }
- while ((auth_send_cnt -= 2) >= 0) {
- if (auth_debug_mode)
- printf(">>>%s: He supports %d\r\n",
- Name, *auth_send_data);
- if ((i_support & ~i_wont_support) & typemask(*auth_send_data)) {
- ap = findauthenticator(auth_send_data[0],
- auth_send_data[1]);
- if (ap && ap->send) {
- if (auth_debug_mode)
- printf(">>>%s: Trying %d %d\r\n",
- Name, auth_send_data[0],
- auth_send_data[1]);
- if ((*ap->send)(ap)) {
- /*
- * Okay, we found one we like
- * and did it.
- * we can go home now.
- */
- if (auth_debug_mode)
- printf(">>>%s: Using type %d\r\n",
- Name, *auth_send_data);
- auth_send_data += 2;
- return;
- }
- }
- /* else
- * just continue on and look for the
- * next one if we didn't do anything.
- */
- }
- auth_send_data += 2;
- }
- net_write(str_none, sizeof(str_none));
- printsub('>', &str_none[2], sizeof(str_none) - 2);
- if (auth_debug_mode)
- printf(">>>%s: Sent failure message\r\n", Name);
- auth_finished(0, AUTH_REJECT);
-}
-
-void
-auth_send_retry(void)
-{
- /*
- * if auth_send_cnt <= 0 then auth_send will end up rejecting
- * the authentication and informing the other side of this.
- */
- auth_send(auth_send_data, auth_send_cnt);
-}
-
-void
-auth_is(unsigned char *data, int cnt)
-{
- Authenticator *ap;
-
- if (cnt < 2)
- return;
-
- if (data[0] == AUTHTYPE_NULL) {
- auth_finished(0, AUTH_REJECT);
- return;
- }
-
- if ((ap = findauthenticator(data[0], data[1]))) {
- if (ap->is)
- (*ap->is)(ap, data+2, cnt-2);
- } else if (auth_debug_mode)
- printf(">>>%s: Invalid authentication in IS: %d\r\n",
- Name, *data);
-}
-
-void
-auth_reply(unsigned char *data, int cnt)
-{
- Authenticator *ap;
-
- if (cnt < 2)
- return;
-
- if ((ap = findauthenticator(data[0], data[1]))) {
- if (ap->reply)
- (*ap->reply)(ap, data+2, cnt-2);
- } else if (auth_debug_mode)
- printf(">>>%s: Invalid authentication in SEND: %d\r\n",
- Name, *data);
-}
-
-void
-auth_name(unsigned char *data, int cnt)
-{
- unsigned char savename[256];
-
- if (cnt < 1) {
- if (auth_debug_mode)
- printf(">>>%s: Empty name in NAME\r\n", Name);
- return;
- }
- if ((size_t)cnt > sizeof(savename) - 1) {
- if (auth_debug_mode)
- printf(">>>%s: Name in NAME (%d) exceeds %d length\r\n",
- Name, cnt, (u_int)sizeof(savename)-1);
- return;
- }
- memmove((void *)savename, (void *)data, cnt);
- savename[cnt] = '\0'; /* Null terminate */
- if (auth_debug_mode)
- printf(">>>%s: Got NAME [%s]\r\n", Name, savename);
- auth_encrypt_user(savename);
-}
-
-int
-auth_sendname(unsigned char *cp, int len)
-{
- static unsigned char str_request[256+6]
- = { IAC, SB, TELOPT_AUTHENTICATION, TELQUAL_NAME, };
- unsigned char *e = str_request + 4;
- unsigned char *ee = &str_request[sizeof(str_request)-2];
-
- while (--len >= 0) {
- if ((*e++ = *cp++) == IAC)
- *e++ = IAC;
- if (e >= ee)
- return(0);
- }
- *e++ = IAC;
- *e++ = SE;
- net_write(str_request, e - str_request);
- printsub('>', &str_request[2], e - &str_request[2]);
- return(1);
-}
-
-void
-auth_finished(Authenticator *ap, int result)
-{
- if (!(authenticated = ap))
- authenticated = &NoAuth;
- validuser = result;
-}
-
-/* ARGSUSED */
-static void
-auth_intr(int sig __unused)
-{
- auth_finished(0, AUTH_REJECT);
-}
-
-int
-auth_wait(char *name)
-{
- if (auth_debug_mode)
- printf(">>>%s: in auth_wait.\r\n", Name);
-
- if (Server && !authenticating)
- return(0);
-
- (void) signal(SIGALRM, auth_intr);
- alarm(30);
- while (!authenticated)
- if (telnet_spin())
- break;
- alarm(0);
- (void) signal(SIGALRM, SIG_DFL);
-
- /*
- * Now check to see if the user is valid or not
- */
- if (!authenticated || authenticated == &NoAuth)
- return(AUTH_REJECT);
-
- if (validuser == AUTH_VALID)
- validuser = AUTH_USER;
-
- if (authenticated->status)
- validuser = (*authenticated->status)(authenticated,
- name, validuser);
- return(validuser);
-}
-
-void
-auth_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
-{
- Authenticator *ap;
-
- if ((ap = findauthenticator(data[1], data[2])) && ap->printsub)
- (*ap->printsub)(data, cnt, buf, buflen);
- else
- auth_gen_printsub(data, cnt, buf, buflen);
-}
-
-void
-auth_gen_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
-{
- unsigned char *cp;
- unsigned char tbuf[16];
-
- cnt -= 3;
- data += 3;
- buf[buflen-1] = '\0';
- buf[buflen-2] = '*';
- buflen -= 2;
- for (; cnt > 0; cnt--, data++) {
- sprintf((char *)tbuf, " %d", *data);
- for (cp = tbuf; *cp && buflen > 0; --buflen)
- *buf++ = *cp++;
- if (buflen <= 0)
- return;
- }
- *buf = '\0';
-}
-#endif
diff --git a/contrib/telnet/libtelnet/auth.h b/contrib/telnet/libtelnet/auth.h
deleted file mode 100644
index a8ee04831d67..000000000000
--- a/contrib/telnet/libtelnet/auth.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)auth.h 8.1 (Berkeley) 6/4/93
- * $FreeBSD$
- */
-
-/*
- * Copyright (C) 1990 by the Massachusetts Institute of Technology
- *
- * Export of this software from the United States of America is assumed
- * to require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifndef __AUTH__
-#define __AUTH__
-
-#define AUTH_REJECT 0 /* Rejected */
-#define AUTH_UNKNOWN 1 /* We don't know who he is, but he's okay */
-#define AUTH_OTHER 2 /* We know him, but not his name */
-#define AUTH_USER 3 /* We know he name */
-#define AUTH_VALID 4 /* We know him, and he needs no password */
-
-typedef struct XauthP {
- int type;
- int way;
- int (*init)(struct XauthP *, int);
- int (*send)(struct XauthP *);
- void (*is)(struct XauthP *, unsigned char *, int);
- void (*reply)(struct XauthP *, unsigned char *, int);
- int (*status)(struct XauthP *, char *, int);
- void (*printsub)(unsigned char *, int, unsigned char *, int);
-} Authenticator;
-
-#include "auth-proto.h"
-
-extern int auth_debug_mode;
-#endif
diff --git a/contrib/telnet/libtelnet/enc-proto.h b/contrib/telnet/libtelnet/enc-proto.h
deleted file mode 100644
index 46663c7789e2..000000000000
--- a/contrib/telnet/libtelnet/enc-proto.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)enc-proto.h 8.1 (Berkeley) 6/4/93
- * $FreeBSD$
- */
-
-/*
- * Copyright (C) 1990 by the Massachusetts Institute of Technology
- *
- * Export of this software from the United States of America is assumed
- * to require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifdef ENCRYPTION
-void encrypt_init(const char *, int);
-Encryptions *findencryption(int);
-void encrypt_send_supprt(void);
-void encrypt_auto(int);
-void decrypt_auto(int);
-void encrypt_is(unsigned char *, int);
-void encrypt_reply(unsigned char *, int);
-void encrypt_start_input(int);
-void encrypt_session_key(Session_Key *, int);
-void encrypt_end_input(void);
-void encrypt_start_output(int);
-void encrypt_end_output(void);
-void encrypt_send_request_start(void);
-void encrypt_send_request_end(void);
-void encrypt_send_end(void);
-void encrypt_wait(void);
-void encrypt_send_support(void);
-void encrypt_send_keyid(int, const char *, int, int);
-void encrypt_start(unsigned char *, int);
-void encrypt_end(void);
-void encrypt_support(unsigned char *, int);
-void encrypt_request_start(unsigned char *, int);
-void encrypt_request_end(void);
-void encrypt_enc_keyid(unsigned char *, int);
-void encrypt_dec_keyid(unsigned char *, int);
-void encrypt_printsub(unsigned char *, int, unsigned char *, int);
-void encrypt_gen_printsub(unsigned char *, int, unsigned char *, int);
-void encrypt_display(void);
-
-void fb64_printsub(unsigned char *, int, unsigned char *, int, const char *);
-
-int EncryptEnable(char *, char *);
-int EncryptDisable(char *, char *);
-int EncryptStatus(void);
-int EncryptDebug(int);
-int EncryptVerbose(int);
-int EncryptAutoEnc(int);
-int EncryptAutoDec(int);
-
-void krbdes_encrypt(unsigned char *, int);
-int krbdes_decrypt(int);
-int krbdes_is(unsigned char *, int);
-int krbdes_reply(unsigned char *, int);
-void krbdes_init(int);
-int krbdes_start(int, int);
-void krbdes_session(Session_Key *, int);
-void krbdes_printsub(unsigned char *, int, unsigned char *, int);
-
-void cfb64_encrypt(unsigned char *, int);
-int cfb64_decrypt(int);
-void cfb64_init(int);
-int cfb64_start(int, int);
-int cfb64_is(unsigned char *, int);
-int cfb64_reply(unsigned char *, int);
-void cfb64_session(Session_Key *, int);
-int cfb64_keyid(int, unsigned char *, int *);
-void cfb64_printsub(unsigned char *, int, unsigned char *, int);
-
-void ofb64_encrypt(unsigned char *, int);
-int ofb64_decrypt(int);
-void ofb64_init(int);
-int ofb64_start(int, int);
-int ofb64_is(unsigned char *, int);
-int ofb64_reply(unsigned char *, int);
-void ofb64_session(Session_Key *, int);
-int ofb64_keyid(int, unsigned char *, int *);
-void ofb64_printsub(unsigned char *, int, unsigned char *, int);
-
-#endif /* ENCRYPTION */
diff --git a/contrib/telnet/libtelnet/enc_des.c b/contrib/telnet/libtelnet/enc_des.c
deleted file mode 100644
index 2f7fe6e74402..000000000000
--- a/contrib/telnet/libtelnet/enc_des.c
+++ /dev/null
@@ -1,662 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)enc_des.c 8.3 (Berkeley) 5/30/95";
-#endif /* not lint */
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#ifdef ENCRYPTION
-# ifdef AUTHENTICATION
-#include <arpa/telnet.h>
-#include <openssl/des.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "encrypt.h"
-#include "key-proto.h"
-#include "misc-proto.h"
-
-extern int encrypt_debug_mode;
-
-#define CFB 0
-#define OFB 1
-
-#define NO_SEND_IV 1
-#define NO_RECV_IV 2
-#define NO_KEYID 4
-#define IN_PROGRESS (NO_SEND_IV|NO_RECV_IV|NO_KEYID)
-#define SUCCESS 0
-#define FAILED -1
-
-
-struct fb {
- Block krbdes_key;
- Schedule krbdes_sched;
- Block temp_feed;
- unsigned char fb_feed[64];
- int need_start;
- int state[2];
- int keyid[2];
- struct stinfo {
- Block str_output;
- Block str_feed;
- Block str_iv;
- Block str_ikey;
- Schedule str_sched;
- int str_index;
- int str_flagshift;
- } streams[2];
-};
-
-static struct fb fb[2];
-
-struct keyidlist {
- const char *keyid;
- int keyidlen;
- char *key;
- int keylen;
- int flags;
-} keyidlist [] = {
- { "\0", 1, 0, 0, 0 }, /* default key of zero */
- { 0, 0, 0, 0, 0 }
-};
-
-#define KEYFLAG_MASK 03
-
-#define KEYFLAG_NOINIT 00
-#define KEYFLAG_INIT 01
-#define KEYFLAG_OK 02
-#define KEYFLAG_BAD 03
-
-#define KEYFLAG_SHIFT 2
-
-#define SHIFT_VAL(a,b) (KEYFLAG_SHIFT*((a)+((b)*2)))
-
-#define FB64_IV 1
-#define FB64_IV_OK 2
-#define FB64_IV_BAD 3
-
-
-void fb64_stream_iv(Block, struct stinfo *);
-void fb64_init(struct fb *);
-static int fb64_start(struct fb *, int, int);
-int fb64_is(unsigned char *, int, struct fb *);
-int fb64_reply(unsigned char *, int, struct fb *);
-static void fb64_session(Session_Key *, int, struct fb *);
-void fb64_stream_key(Block, struct stinfo *);
-int fb64_keyid(int, unsigned char *, int *, struct fb *);
-
-void
-cfb64_init(int server __unused)
-{
- fb64_init(&fb[CFB]);
- fb[CFB].fb_feed[4] = ENCTYPE_DES_CFB64;
- fb[CFB].streams[0].str_flagshift = SHIFT_VAL(0, CFB);
- fb[CFB].streams[1].str_flagshift = SHIFT_VAL(1, CFB);
-}
-
-void
-ofb64_init(int server __unused)
-{
- fb64_init(&fb[OFB]);
- fb[OFB].fb_feed[4] = ENCTYPE_DES_OFB64;
- fb[CFB].streams[0].str_flagshift = SHIFT_VAL(0, OFB);
- fb[CFB].streams[1].str_flagshift = SHIFT_VAL(1, OFB);
-}
-
-void
-fb64_init(struct fb *fbp)
-{
- memset((void *)fbp, 0, sizeof(*fbp));
- fbp->state[0] = fbp->state[1] = FAILED;
- fbp->fb_feed[0] = IAC;
- fbp->fb_feed[1] = SB;
- fbp->fb_feed[2] = TELOPT_ENCRYPT;
- fbp->fb_feed[3] = ENCRYPT_IS;
-}
-
-/*
- * Returns:
- * -1: some error. Negotiation is done, encryption not ready.
- * 0: Successful, initial negotiation all done.
- * 1: successful, negotiation not done yet.
- * 2: Not yet. Other things (like getting the key from
- * Kerberos) have to happen before we can continue.
- */
-int
-cfb64_start(int dir, int server)
-{
- return(fb64_start(&fb[CFB], dir, server));
-}
-
-int
-ofb64_start(int dir, int server)
-{
- return(fb64_start(&fb[OFB], dir, server));
-}
-
-static int
-fb64_start(struct fb *fbp, int dir, int server __unused)
-{
- size_t x;
- unsigned char *p;
- int state;
-
- switch (dir) {
- case DIR_DECRYPT:
- /*
- * This is simply a request to have the other side
- * start output (our input). He will negotiate an
- * IV so we need not look for it.
- */
- state = fbp->state[dir-1];
- if (state == FAILED)
- state = IN_PROGRESS;
- break;
-
- case DIR_ENCRYPT:
- state = fbp->state[dir-1];
- if (state == FAILED)
- state = IN_PROGRESS;
- else if ((state & NO_SEND_IV) == 0)
- break;
-
- if (!VALIDKEY(fbp->krbdes_key)) {
- fbp->need_start = 1;
- break;
- }
- state &= ~NO_SEND_IV;
- state |= NO_RECV_IV;
- if (encrypt_debug_mode)
- printf("Creating new feed\r\n");
- /*
- * Create a random feed and send it over.
- */
- des_random_key((Block *)fbp->temp_feed);
- des_ecb_encrypt((Block *)fbp->temp_feed, (Block *)fbp->temp_feed,
- fbp->krbdes_sched, 1);
- p = fbp->fb_feed + 3;
- *p++ = ENCRYPT_IS;
- p++;
- *p++ = FB64_IV;
- for (x = 0; x < sizeof(Block); ++x) {
- if ((*p++ = fbp->temp_feed[x]) == IAC)
- *p++ = IAC;
- }
- *p++ = IAC;
- *p++ = SE;
- printsub('>', &fbp->fb_feed[2], p - &fbp->fb_feed[2]);
- net_write(fbp->fb_feed, p - fbp->fb_feed);
- break;
- default:
- return(FAILED);
- }
- return(fbp->state[dir-1] = state);
-}
-
-/*
- * Returns:
- * -1: some error. Negotiation is done, encryption not ready.
- * 0: Successful, initial negotiation all done.
- * 1: successful, negotiation not done yet.
- */
-int
-cfb64_is(unsigned char *data, int cnt)
-{
- return(fb64_is(data, cnt, &fb[CFB]));
-}
-
-int
-ofb64_is(unsigned char *data, int cnt)
-{
- return(fb64_is(data, cnt, &fb[OFB]));
-}
-
-int
-fb64_is(unsigned char *data, int cnt, struct fb *fbp)
-{
- unsigned char *p;
- int state = fbp->state[DIR_DECRYPT-1];
-
- if (cnt-- < 1)
- goto failure;
-
- switch (*data++) {
- case FB64_IV:
- if (cnt != sizeof(Block)) {
- if (encrypt_debug_mode)
- printf("CFB64: initial vector failed on size\r\n");
- state = FAILED;
- goto failure;
- }
-
- if (encrypt_debug_mode)
- printf("CFB64: initial vector received\r\n");
-
- if (encrypt_debug_mode)
- printf("Initializing Decrypt stream\r\n");
-
- fb64_stream_iv((void *)data, &fbp->streams[DIR_DECRYPT-1]);
-
- p = fbp->fb_feed + 3;
- *p++ = ENCRYPT_REPLY;
- p++;
- *p++ = FB64_IV_OK;
- *p++ = IAC;
- *p++ = SE;
- printsub('>', &fbp->fb_feed[2], p - &fbp->fb_feed[2]);
- net_write(fbp->fb_feed, p - fbp->fb_feed);
-
- state = fbp->state[DIR_DECRYPT-1] = IN_PROGRESS;
- break;
-
- default:
- if (encrypt_debug_mode) {
- printf("Unknown option type: %d\r\n", *(data-1));
- printd(data, cnt);
- printf("\r\n");
- }
- /* FALL THROUGH */
- failure:
- /*
- * We failed. Send an FB64_IV_BAD option
- * to the other side so it will know that
- * things failed.
- */
- p = fbp->fb_feed + 3;
- *p++ = ENCRYPT_REPLY;
- p++;
- *p++ = FB64_IV_BAD;
- *p++ = IAC;
- *p++ = SE;
- printsub('>', &fbp->fb_feed[2], p - &fbp->fb_feed[2]);
- net_write(fbp->fb_feed, p - fbp->fb_feed);
-
- break;
- }
- return(fbp->state[DIR_DECRYPT-1] = state);
-}
-
-/*
- * Returns:
- * -1: some error. Negotiation is done, encryption not ready.
- * 0: Successful, initial negotiation all done.
- * 1: successful, negotiation not done yet.
- */
-int
-cfb64_reply(unsigned char *data, int cnt)
-{
- return(fb64_reply(data, cnt, &fb[CFB]));
-}
-
-int
-ofb64_reply(unsigned char *data, int cnt)
-{
- return(fb64_reply(data, cnt, &fb[OFB]));
-}
-
-int
-fb64_reply(unsigned char *data, int cnt, struct fb *fbp)
-{
- int state = fbp->state[DIR_ENCRYPT-1];
-
- if (cnt-- < 1)
- goto failure;
-
- switch (*data++) {
- case FB64_IV_OK:
- fb64_stream_iv(fbp->temp_feed, &fbp->streams[DIR_ENCRYPT-1]);
- if (state == FAILED)
- state = IN_PROGRESS;
- state &= ~NO_RECV_IV;
- encrypt_send_keyid(DIR_ENCRYPT, "\0", 1, 1);
- break;
-
- case FB64_IV_BAD:
- memset(fbp->temp_feed, 0, sizeof(Block));
- fb64_stream_iv(fbp->temp_feed, &fbp->streams[DIR_ENCRYPT-1]);
- state = FAILED;
- break;
-
- default:
- if (encrypt_debug_mode) {
- printf("Unknown option type: %d\r\n", data[-1]);
- printd(data, cnt);
- printf("\r\n");
- }
- /* FALL THROUGH */
- failure:
- state = FAILED;
- break;
- }
- return(fbp->state[DIR_ENCRYPT-1] = state);
-}
-
-void
-cfb64_session(Session_Key *key, int server)
-{
- fb64_session(key, server, &fb[CFB]);
-}
-
-void
-ofb64_session(Session_Key *key, int server)
-{
- fb64_session(key, server, &fb[OFB]);
-}
-
-static void
-fb64_session(Session_Key *key, int server, struct fb *fbp)
-{
- if (!key || key->type != SK_DES) {
- if (encrypt_debug_mode)
- printf("Can't set krbdes's session key (%d != %d)\r\n",
- key ? key->type : -1, SK_DES);
- return;
- }
- memmove((void *)fbp->krbdes_key, (void *)key->data, sizeof(Block));
-
- fb64_stream_key(fbp->krbdes_key, &fbp->streams[DIR_ENCRYPT-1]);
- fb64_stream_key(fbp->krbdes_key, &fbp->streams[DIR_DECRYPT-1]);
-
- des_key_sched((Block *)fbp->krbdes_key, fbp->krbdes_sched);
- /*
- * Now look to see if krbdes_start() was was waiting for
- * the key to show up. If so, go ahead an call it now
- * that we have the key.
- */
- if (fbp->need_start) {
- fbp->need_start = 0;
- fb64_start(fbp, DIR_ENCRYPT, server);
- }
-}
-
-/*
- * We only accept a keyid of 0. If we get a keyid of
- * 0, then mark the state as SUCCESS.
- */
-int
-cfb64_keyid(int dir, unsigned char *kp, int *lenp)
-{
- return(fb64_keyid(dir, kp, lenp, &fb[CFB]));
-}
-
-int
-ofb64_keyid(int dir, unsigned char *kp, int *lenp)
-{
- return(fb64_keyid(dir, kp, lenp, &fb[OFB]));
-}
-
-int
-fb64_keyid(int dir, unsigned char *kp, int *lenp, struct fb *fbp)
-{
- int state = fbp->state[dir-1];
-
- if (*lenp != 1 || (*kp != '\0')) {
- *lenp = 0;
- return(state);
- }
-
- if (state == FAILED)
- state = IN_PROGRESS;
-
- state &= ~NO_KEYID;
-
- return(fbp->state[dir-1] = state);
-}
-
-void
-fb64_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen, const char *type)
-{
- char lbuf[32];
- int i;
- char *cp;
-
- buf[buflen-1] = '\0'; /* make sure it's NULL terminated */
- buflen -= 1;
-
- switch(data[2]) {
- case FB64_IV:
- sprintf(lbuf, "%s_IV", type);
- cp = lbuf;
- goto common;
-
- case FB64_IV_OK:
- sprintf(lbuf, "%s_IV_OK", type);
- cp = lbuf;
- goto common;
-
- case FB64_IV_BAD:
- sprintf(lbuf, "%s_IV_BAD", type);
- cp = lbuf;
- goto common;
-
- default:
- sprintf(lbuf, " %d (unknown)", data[2]);
- cp = lbuf;
- common:
- for (; (buflen > 0) && (*buf = *cp++); buf++)
- buflen--;
- for (i = 3; i < cnt; i++) {
- sprintf(lbuf, " %d", data[i]);
- for (cp = lbuf; (buflen > 0) && (*buf = *cp++); buf++)
- buflen--;
- }
- break;
- }
-}
-
-void
-cfb64_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
-{
- fb64_printsub(data, cnt, buf, buflen, "CFB64");
-}
-
-void
-ofb64_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
-{
- fb64_printsub(data, cnt, buf, buflen, "OFB64");
-}
-
-void
-fb64_stream_iv(Block seed, struct stinfo *stp)
-{
-
- memmove((void *)stp->str_iv, (void *)seed, sizeof(Block));
- memmove((void *)stp->str_output, (void *)seed, sizeof(Block));
-
- des_key_sched((Block *)stp->str_ikey, stp->str_sched);
-
- stp->str_index = sizeof(Block);
-}
-
-void
-fb64_stream_key(Block key, struct stinfo *stp)
-{
- memmove((void *)stp->str_ikey, (void *)key, sizeof(Block));
- des_key_sched((Block *)key, stp->str_sched);
-
- memmove((void *)stp->str_output, (void *)stp->str_iv, sizeof(Block));
-
- stp->str_index = sizeof(Block);
-}
-
-/*
- * DES 64 bit Cipher Feedback
- *
- * key --->+-----+
- * +->| DES |--+
- * | +-----+ |
- * | v
- * INPUT --(--------->(+)+---> DATA
- * | |
- * +-------------+
- *
- *
- * Given:
- * iV: Initial vector, 64 bits (8 bytes) long.
- * Dn: the nth chunk of 64 bits (8 bytes) of data to encrypt (decrypt).
- * On: the nth chunk of 64 bits (8 bytes) of encrypted (decrypted) output.
- *
- * V0 = DES(iV, key)
- * On = Dn ^ Vn
- * V(n+1) = DES(On, key)
- */
-
-void
-cfb64_encrypt(unsigned char *s, int c)
-{
- struct stinfo *stp = &fb[CFB].streams[DIR_ENCRYPT-1];
- int idx;
-
- idx = stp->str_index;
- while (c-- > 0) {
- if (idx == sizeof(Block)) {
- Block b;
- des_ecb_encrypt((Block *)stp->str_output, (Block *)b, stp->str_sched, 1);
- memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
- idx = 0;
- }
-
- /* On encryption, we store (feed ^ data) which is cypher */
- *s = stp->str_output[idx] = (stp->str_feed[idx] ^ *s);
- s++;
- idx++;
- }
- stp->str_index = idx;
-}
-
-int
-cfb64_decrypt(int data)
-{
- struct stinfo *stp = &fb[CFB].streams[DIR_DECRYPT-1];
- int idx;
-
- if (data == -1) {
- /*
- * Back up one byte. It is assumed that we will
- * never back up more than one byte. If we do, this
- * may or may not work.
- */
- if (stp->str_index)
- --stp->str_index;
- return(0);
- }
-
- idx = stp->str_index++;
- if (idx == sizeof(Block)) {
- Block b;
- des_ecb_encrypt((Block *)stp->str_output, (Block *)b, stp->str_sched, 1);
- memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
- stp->str_index = 1; /* Next time will be 1 */
- idx = 0; /* But now use 0 */
- }
-
- /* On decryption we store (data) which is cypher. */
- stp->str_output[idx] = data;
- return(data ^ stp->str_feed[idx]);
-}
-
-/*
- * DES 64 bit Output Feedback
- *
- * key --->+-----+
- * +->| DES |--+
- * | +-----+ |
- * +-----------+
- * v
- * INPUT -------->(+) ----> DATA
- *
- * Given:
- * iV: Initial vector, 64 bits (8 bytes) long.
- * Dn: the nth chunk of 64 bits (8 bytes) of data to encrypt (decrypt).
- * On: the nth chunk of 64 bits (8 bytes) of encrypted (decrypted) output.
- *
- * V0 = DES(iV, key)
- * V(n+1) = DES(Vn, key)
- * On = Dn ^ Vn
- */
-void
-ofb64_encrypt(unsigned char *s, int c)
-{
- struct stinfo *stp = &fb[OFB].streams[DIR_ENCRYPT-1];
- int idx;
-
- idx = stp->str_index;
- while (c-- > 0) {
- if (idx == sizeof(Block)) {
- Block b;
- des_ecb_encrypt((Block *)stp->str_feed, (Block *)b, stp->str_sched, 1);
- memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
- idx = 0;
- }
- *s++ ^= stp->str_feed[idx];
- idx++;
- }
- stp->str_index = idx;
-}
-
-int
-ofb64_decrypt(int data)
-{
- struct stinfo *stp = &fb[OFB].streams[DIR_DECRYPT-1];
- int idx;
-
- if (data == -1) {
- /*
- * Back up one byte. It is assumed that we will
- * never back up more than one byte. If we do, this
- * may or may not work.
- */
- if (stp->str_index)
- --stp->str_index;
- return(0);
- }
-
- idx = stp->str_index++;
- if (idx == sizeof(Block)) {
- Block b;
- des_ecb_encrypt((Block *)stp->str_feed, (Block *)b, stp->str_sched, 1);
- memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
- stp->str_index = 1; /* Next time will be 1 */
- idx = 0; /* But now use 0 */
- }
-
- return(data ^ stp->str_feed[idx]);
-}
-# endif /* AUTHENTICATION */
-#endif /* ENCRYPTION */
diff --git a/contrib/telnet/libtelnet/encrypt.c b/contrib/telnet/libtelnet/encrypt.c
deleted file mode 100644
index 8bdf672ab3ba..000000000000
--- a/contrib/telnet/libtelnet/encrypt.c
+++ /dev/null
@@ -1,953 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-
-__FBSDID("$FreeBSD$");
-
-#ifndef lint
-#if 0
-static const char sccsid[] = "@(#)encrypt.c 8.2 (Berkeley) 5/30/95";
-#endif
-#endif /* not lint */
-
-/*
- * Copyright (C) 1990 by the Massachusetts Institute of Technology
- *
- * Export of this software from the United States of America is assumed
- * to require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifdef ENCRYPTION
-
-#include <sys/types.h>
-#define ENCRYPT_NAMES
-#include <arpa/telnet.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "encrypt.h"
-#include "misc.h"
-
-/*
- * These functions pointers point to the current routines
- * for encrypting and decrypting data.
- */
-void (*encrypt_output)(unsigned char *, int);
-int (*decrypt_input)(int);
-
-int EncryptType(char *type, char *mode);
-int EncryptStart(char *mode);
-int EncryptStop(char *mode);
-int EncryptStartInput(void);
-int EncryptStartOutput(void);
-int EncryptStopInput(void);
-int EncryptStopOutput(void);
-
-int encrypt_debug_mode = 0;
-static int decrypt_mode = 0;
-static int encrypt_mode = 0;
-static int encrypt_verbose = 0;
-static int autoencrypt = 0;
-static int autodecrypt = 0;
-static int havesessionkey = 0;
-static int Server = 0;
-static const char *Name = "Noname";
-
-#define typemask(x) ((x) > 0 ? 1 << ((x)-1) : 0)
-
-static u_long i_support_encrypt = 0
- | typemask(ENCTYPE_DES_CFB64) | typemask(ENCTYPE_DES_OFB64)
- |0;
-static u_long i_support_decrypt = 0
- | typemask(ENCTYPE_DES_CFB64) | typemask(ENCTYPE_DES_OFB64)
- |0;
-
-static u_long i_wont_support_encrypt = 0;
-static u_long i_wont_support_decrypt = 0;
-#define I_SUPPORT_ENCRYPT (i_support_encrypt & ~i_wont_support_encrypt)
-#define I_SUPPORT_DECRYPT (i_support_decrypt & ~i_wont_support_decrypt)
-
-static u_long remote_supports_encrypt = 0;
-static u_long remote_supports_decrypt = 0;
-
-static Encryptions encryptions[] = {
- { "DES_CFB64", ENCTYPE_DES_CFB64,
- cfb64_encrypt,
- cfb64_decrypt,
- cfb64_init,
- cfb64_start,
- cfb64_is,
- cfb64_reply,
- cfb64_session,
- cfb64_keyid,
- cfb64_printsub },
- { "DES_OFB64", ENCTYPE_DES_OFB64,
- ofb64_encrypt,
- ofb64_decrypt,
- ofb64_init,
- ofb64_start,
- ofb64_is,
- ofb64_reply,
- ofb64_session,
- ofb64_keyid,
- ofb64_printsub },
- { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
-};
-
-static unsigned char str_send[64] = { IAC, SB, TELOPT_ENCRYPT,
- ENCRYPT_SUPPORT };
-static unsigned char str_suplen = 0;
-static unsigned char str_start[72] = { IAC, SB, TELOPT_ENCRYPT };
-static unsigned char str_end[] = { IAC, SB, TELOPT_ENCRYPT, 0, IAC, SE };
-
-Encryptions *
-findencryption(int type)
-{
- Encryptions *ep = encryptions;
-
- if (!(I_SUPPORT_ENCRYPT & remote_supports_decrypt & (unsigned)typemask(type)))
- return(0);
- while (ep->type && ep->type != type)
- ++ep;
- return(ep->type ? ep : 0);
-}
-
-static Encryptions *
-finddecryption(int type)
-{
- Encryptions *ep = encryptions;
-
- if (!(I_SUPPORT_DECRYPT & remote_supports_encrypt & (unsigned)typemask(type)))
- return(0);
- while (ep->type && ep->type != type)
- ++ep;
- return(ep->type ? ep : 0);
-}
-
-#define MAXKEYLEN 64
-
-static struct key_info {
- unsigned char keyid[MAXKEYLEN];
- int keylen;
- int dir;
- int *modep;
- Encryptions *(*getcrypt)(int);
-} ki[2] = {
- { { 0 }, 0, DIR_ENCRYPT, &encrypt_mode, findencryption },
- { { 0 }, 0, DIR_DECRYPT, &decrypt_mode, finddecryption },
-};
-
-static void encrypt_keyid(struct key_info *kp, unsigned char *keyid, int len);
-
-void
-encrypt_init(const char *name, int server)
-{
- Encryptions *ep = encryptions;
-
- Name = name;
- Server = server;
- i_support_encrypt = i_support_decrypt = 0;
- remote_supports_encrypt = remote_supports_decrypt = 0;
- encrypt_mode = 0;
- decrypt_mode = 0;
- encrypt_output = 0;
- decrypt_input = 0;
-
- str_suplen = 4;
-
- while (ep->type) {
- if (encrypt_debug_mode)
- printf(">>>%s: I will support %s\r\n",
- Name, ENCTYPE_NAME(ep->type));
- i_support_encrypt |= typemask(ep->type);
- i_support_decrypt |= typemask(ep->type);
- if ((i_wont_support_decrypt & typemask(ep->type)) == 0)
- if ((str_send[str_suplen++] = ep->type) == IAC)
- str_send[str_suplen++] = IAC;
- if (ep->init)
- (*ep->init)(Server);
- ++ep;
- }
- str_send[str_suplen++] = IAC;
- str_send[str_suplen++] = SE;
-}
-
-static void
-encrypt_list_types(void)
-{
- Encryptions *ep = encryptions;
-
- printf("Valid encryption types:\n");
- while (ep->type) {
- printf("\t%s (%d)\r\n", ENCTYPE_NAME(ep->type), ep->type);
- ++ep;
- }
-}
-
-int
-EncryptEnable(char *type, char *mode)
-{
- if (isprefix(type, "help") || isprefix(type, "?")) {
- printf("Usage: encrypt enable <type> [input|output]\n");
- encrypt_list_types();
- return(0);
- }
- if (EncryptType(type, mode))
- return(EncryptStart(mode));
- return(0);
-}
-
-int
-EncryptDisable(char *type, char *mode)
-{
- Encryptions *ep;
- int ret = 0;
-
- if (isprefix(type, "help") || isprefix(type, "?")) {
- printf("Usage: encrypt disable <type> [input|output]\n");
- encrypt_list_types();
- } else if ((ep = (Encryptions *)genget(type, (char **)encryptions,
- sizeof(Encryptions))) == 0) {
- printf("%s: invalid encryption type\n", type);
- } else if (Ambiguous((char **)ep)) {
- printf("Ambiguous type '%s'\n", type);
- } else {
- if ((mode == 0) || (isprefix(mode, "input") ? 1 : 0)) {
- if (decrypt_mode == ep->type)
- EncryptStopInput();
- i_wont_support_decrypt |= typemask(ep->type);
- ret = 1;
- }
- if ((mode == 0) || (isprefix(mode, "output"))) {
- if (encrypt_mode == ep->type)
- EncryptStopOutput();
- i_wont_support_encrypt |= typemask(ep->type);
- ret = 1;
- }
- if (ret == 0)
- printf("%s: invalid encryption mode\n", mode);
- }
- return(ret);
-}
-
-int
-EncryptType(char *type, char *mode)
-{
- Encryptions *ep;
- int ret = 0;
-
- if (isprefix(type, "help") || isprefix(type, "?")) {
- printf("Usage: encrypt type <type> [input|output]\n");
- encrypt_list_types();
- } else if ((ep = (Encryptions *)genget(type, (char **)encryptions,
- sizeof(Encryptions))) == 0) {
- printf("%s: invalid encryption type\n", type);
- } else if (Ambiguous((char **)ep)) {
- printf("Ambiguous type '%s'\n", type);
- } else {
- if ((mode == 0) || isprefix(mode, "input")) {
- decrypt_mode = ep->type;
- i_wont_support_decrypt &= ~typemask(ep->type);
- ret = 1;
- }
- if ((mode == 0) || isprefix(mode, "output")) {
- encrypt_mode = ep->type;
- i_wont_support_encrypt &= ~typemask(ep->type);
- ret = 1;
- }
- if (ret == 0)
- printf("%s: invalid encryption mode\n", mode);
- }
- return(ret);
-}
-
-int
-EncryptStart(char *mode)
-{
- int ret = 0;
- if (mode) {
- if (isprefix(mode, "input"))
- return(EncryptStartInput());
- if (isprefix(mode, "output"))
- return(EncryptStartOutput());
- if (isprefix(mode, "help") || isprefix(mode, "?")) {
- printf("Usage: encrypt start [input|output]\n");
- return(0);
- }
- printf("%s: invalid encryption mode 'encrypt start ?' for help\n", mode);
- return(0);
- }
- ret += EncryptStartInput();
- ret += EncryptStartOutput();
- return(ret);
-}
-
-int
-EncryptStartInput(void)
-{
- if (decrypt_mode) {
- encrypt_send_request_start();
- return(1);
- }
- printf("No previous decryption mode, decryption not enabled\r\n");
- return(0);
-}
-
-int
-EncryptStartOutput(void)
-{
- if (encrypt_mode) {
- encrypt_start_output(encrypt_mode);
- return(1);
- }
- printf("No previous encryption mode, encryption not enabled\r\n");
- return(0);
-}
-
-int
-EncryptStop(char *mode)
-{
- int ret = 0;
- if (mode) {
- if (isprefix(mode, "input"))
- return(EncryptStopInput());
- if (isprefix(mode, "output"))
- return(EncryptStopOutput());
- if (isprefix(mode, "help") || isprefix(mode, "?")) {
- printf("Usage: encrypt stop [input|output]\n");
- return(0);
- }
- printf("%s: invalid encryption mode 'encrypt stop ?' for help\n", mode);
- return(0);
- }
- ret += EncryptStopInput();
- ret += EncryptStopOutput();
- return(ret);
-}
-
-int
-EncryptStopInput(void)
-{
- encrypt_send_request_end();
- return(1);
-}
-
-int
-EncryptStopOutput(void)
-{
- encrypt_send_end();
- return(1);
-}
-
-void
-encrypt_display(void)
-{
- if (encrypt_output)
- printf("Currently encrypting output with %s\r\n",
- ENCTYPE_NAME(encrypt_mode));
- if (decrypt_input)
- printf("Currently decrypting input with %s\r\n",
- ENCTYPE_NAME(decrypt_mode));
-}
-
-int
-EncryptStatus(void)
-{
- if (encrypt_output)
- printf("Currently encrypting output with %s\r\n",
- ENCTYPE_NAME(encrypt_mode));
- else if (encrypt_mode) {
- printf("Currently output is clear text.\r\n");
- printf("Last encryption mode was %s\r\n",
- ENCTYPE_NAME(encrypt_mode));
- }
- if (decrypt_input) {
- printf("Currently decrypting input with %s\r\n",
- ENCTYPE_NAME(decrypt_mode));
- } else if (decrypt_mode) {
- printf("Currently input is clear text.\r\n");
- printf("Last decryption mode was %s\r\n",
- ENCTYPE_NAME(decrypt_mode));
- }
- return 1;
-}
-
-void
-encrypt_send_support(void)
-{
- if (str_suplen) {
- /*
- * If the user has requested that decryption start
- * immediatly, then send a "REQUEST START" before
- * we negotiate the type.
- */
- if (!Server && autodecrypt)
- encrypt_send_request_start();
- net_write(str_send, str_suplen);
- printsub('>', &str_send[2], str_suplen - 2);
- str_suplen = 0;
- }
-}
-
-int
-EncryptDebug(int on)
-{
- if (on < 0)
- encrypt_debug_mode ^= 1;
- else
- encrypt_debug_mode = on;
- printf("Encryption debugging %s\r\n",
- encrypt_debug_mode ? "enabled" : "disabled");
- return(1);
-}
-
-int
-EncryptVerbose(int on)
-{
- if (on < 0)
- encrypt_verbose ^= 1;
- else
- encrypt_verbose = on;
- printf("Encryption %s verbose\r\n",
- encrypt_verbose ? "is" : "is not");
- return(1);
-}
-
-int
-EncryptAutoEnc(int on)
-{
- encrypt_auto(on);
- printf("Automatic encryption of output is %s\r\n",
- autoencrypt ? "enabled" : "disabled");
- return(1);
-}
-
-int
-EncryptAutoDec(int on)
-{
- decrypt_auto(on);
- printf("Automatic decryption of input is %s\r\n",
- autodecrypt ? "enabled" : "disabled");
- return(1);
-}
-
-/*
- * Called when ENCRYPT SUPPORT is received.
- */
-void
-encrypt_support(unsigned char *typelist, int cnt)
-{
- int type, use_type = 0;
- Encryptions *ep;
-
- /*
- * Forget anything the other side has previously told us.
- */
- remote_supports_decrypt = 0;
-
- while (cnt-- > 0) {
- type = *typelist++;
- if (encrypt_debug_mode)
- printf(">>>%s: He is supporting %s (%d)\r\n",
- Name,
- ENCTYPE_NAME(type), type);
- if ((type < ENCTYPE_CNT) &&
- (I_SUPPORT_ENCRYPT & typemask(type))) {
- remote_supports_decrypt |= typemask(type);
- if (use_type == 0)
- use_type = type;
- }
- }
- if (use_type) {
- ep = findencryption(use_type);
- if (!ep)
- return;
- type = ep->start ? (*ep->start)(DIR_ENCRYPT, Server) : 0;
- if (encrypt_debug_mode)
- printf(">>>%s: (*ep->start)() returned %d\r\n",
- Name, type);
- if (type < 0)
- return;
- encrypt_mode = use_type;
- if (type == 0)
- encrypt_start_output(use_type);
- }
-}
-
-void
-encrypt_is(unsigned char *data, int cnt)
-{
- Encryptions *ep;
- int type, ret;
-
- if (--cnt < 0)
- return;
- type = *data++;
- if (type < ENCTYPE_CNT)
- remote_supports_encrypt |= typemask(type);
- if (!(ep = finddecryption(type))) {
- if (encrypt_debug_mode)
- printf(">>>%s: Can't find type %s (%d) for initial negotiation\r\n",
- Name,
- ENCTYPE_NAME_OK(type)
- ? ENCTYPE_NAME(type) : "(unknown)",
- type);
- return;
- }
- if (!ep->is) {
- if (encrypt_debug_mode)
- printf(">>>%s: No initial negotiation needed for type %s (%d)\r\n",
- Name,
- ENCTYPE_NAME_OK(type)
- ? ENCTYPE_NAME(type) : "(unknown)",
- type);
- ret = 0;
- } else {
- ret = (*ep->is)(data, cnt);
- if (encrypt_debug_mode)
- printf("(*ep->is)(%p, %d) returned %s(%d)\n", data, cnt,
- (ret < 0) ? "FAIL " :
- (ret == 0) ? "SUCCESS " : "MORE_TO_DO ", ret);
- }
- if (ret < 0) {
- autodecrypt = 0;
- } else {
- decrypt_mode = type;
- if (ret == 0 && autodecrypt)
- encrypt_send_request_start();
- }
-}
-
-void
-encrypt_reply(unsigned char *data, int cnt)
-{
- Encryptions *ep;
- int ret, type;
-
- if (--cnt < 0)
- return;
- type = *data++;
- if (!(ep = findencryption(type))) {
- if (encrypt_debug_mode)
- printf(">>>%s: Can't find type %s (%d) for initial negotiation\r\n",
- Name,
- ENCTYPE_NAME_OK(type)
- ? ENCTYPE_NAME(type) : "(unknown)",
- type);
- return;
- }
- if (!ep->reply) {
- if (encrypt_debug_mode)
- printf(">>>%s: No initial negotiation needed for type %s (%d)\r\n",
- Name,
- ENCTYPE_NAME_OK(type)
- ? ENCTYPE_NAME(type) : "(unknown)",
- type);
- ret = 0;
- } else {
- ret = (*ep->reply)(data, cnt);
- if (encrypt_debug_mode)
- printf("(*ep->reply)(%p, %d) returned %s(%d)\n",
- data, cnt,
- (ret < 0) ? "FAIL " :
- (ret == 0) ? "SUCCESS " : "MORE_TO_DO ", ret);
- }
- if (encrypt_debug_mode)
- printf(">>>%s: encrypt_reply returned %d\n", Name, ret);
- if (ret < 0) {
- autoencrypt = 0;
- } else {
- encrypt_mode = type;
- if (ret == 0 && autoencrypt)
- encrypt_start_output(type);
- }
-}
-
-/*
- * Called when a ENCRYPT START command is received.
- */
-void
-encrypt_start(unsigned char *data __unused, int cnt __unused)
-{
- Encryptions *ep;
-
- if (!decrypt_mode) {
- /*
- * Something is wrong. We should not get a START
- * command without having already picked our
- * decryption scheme. Send a REQUEST-END to
- * attempt to clear the channel...
- */
- printf("%s: Warning, Cannot decrypt input stream!!!\r\n", Name);
- encrypt_send_request_end();
- return;
- }
-
- if ((ep = finddecryption(decrypt_mode))) {
- decrypt_input = ep->input;
- if (encrypt_verbose)
- printf("[ Input is now decrypted with type %s ]\r\n",
- ENCTYPE_NAME(decrypt_mode));
- if (encrypt_debug_mode)
- printf(">>>%s: Start to decrypt input with type %s\r\n",
- Name, ENCTYPE_NAME(decrypt_mode));
- } else {
- printf("%s: Warning, Cannot decrypt type %s (%d)!!!\r\n",
- Name,
- ENCTYPE_NAME_OK(decrypt_mode)
- ? ENCTYPE_NAME(decrypt_mode)
- : "(unknown)",
- decrypt_mode);
- encrypt_send_request_end();
- }
-}
-
-void
-encrypt_session_key( Session_Key *key, int server)
-{
- Encryptions *ep = encryptions;
-
- havesessionkey = 1;
-
- while (ep->type) {
- if (ep->session)
- (*ep->session)(key, server);
- ++ep;
- }
-}
-
-/*
- * Called when ENCRYPT END is received.
- */
-void
-encrypt_end(void)
-{
- decrypt_input = 0;
- if (encrypt_debug_mode)
- printf(">>>%s: Input is back to clear text\r\n", Name);
- if (encrypt_verbose)
- printf("[ Input is now clear text ]\r\n");
-}
-
-/*
- * Called when ENCRYPT REQUEST-END is received.
- */
-void
-encrypt_request_end(void)
-{
- encrypt_send_end();
-}
-
-/*
- * Called when ENCRYPT REQUEST-START is received. If we receive
- * this before a type is picked, then that indicates that the
- * other side wants us to start encrypting data as soon as we
- * can.
- */
-void
-encrypt_request_start(unsigned char *data __unused, int cnt __unused)
-{
- if (encrypt_mode == 0) {
- if (Server)
- autoencrypt = 1;
- return;
- }
- encrypt_start_output(encrypt_mode);
-}
-
-static unsigned char str_keyid[(MAXKEYLEN*2)+5] = { IAC, SB, TELOPT_ENCRYPT };
-
-void
-encrypt_enc_keyid(unsigned char *keyid, int len)
-{
- encrypt_keyid(&ki[1], keyid, len);
-}
-
-void
-encrypt_dec_keyid(unsigned char *keyid, int len)
-{
- encrypt_keyid(&ki[0], keyid, len);
-}
-
-void
-encrypt_keyid(struct key_info *kp, unsigned char *keyid, int len)
-{
- Encryptions *ep;
- int dir = kp->dir;
- int ret = 0;
-
- if (!(ep = (*kp->getcrypt)(*kp->modep))) {
- if (len == 0)
- return;
- kp->keylen = 0;
- } else if (len == 0) {
- /*
- * Empty option, indicates a failure.
- */
- if (kp->keylen == 0)
- return;
- kp->keylen = 0;
- if (ep->keyid)
- (void)(*ep->keyid)(dir, kp->keyid, &kp->keylen);
-
- } else if ((len != kp->keylen) ||
- (memcmp(keyid, kp->keyid, len) != 0)) {
- /*
- * Length or contents are different
- */
- kp->keylen = len;
- memmove(kp->keyid, keyid, len);
- if (ep->keyid)
- (void)(*ep->keyid)(dir, kp->keyid, &kp->keylen);
- } else {
- if (ep->keyid)
- ret = (*ep->keyid)(dir, kp->keyid, &kp->keylen);
- if ((ret == 0) && (dir == DIR_ENCRYPT) && autoencrypt)
- encrypt_start_output(*kp->modep);
- return;
- }
-
- encrypt_send_keyid(dir, kp->keyid, kp->keylen, 0);
-}
-
-void
-encrypt_send_keyid(int dir, const char *keyid, int keylen, int saveit)
-{
- unsigned char *strp;
-
- str_keyid[3] = (dir == DIR_ENCRYPT)
- ? ENCRYPT_ENC_KEYID : ENCRYPT_DEC_KEYID;
- if (saveit) {
- struct key_info *kp = &ki[(dir == DIR_ENCRYPT) ? 0 : 1];
- memmove(kp->keyid, keyid, keylen);
- kp->keylen = keylen;
- }
-
- for (strp = &str_keyid[4]; keylen > 0; --keylen) {
- if ((*strp++ = *keyid++) == IAC)
- *strp++ = IAC;
- }
- *strp++ = IAC;
- *strp++ = SE;
- net_write(str_keyid, strp - str_keyid);
- printsub('>', &str_keyid[2], strp - str_keyid - 2);
-}
-
-void
-encrypt_auto(int on)
-{
- if (on < 0)
- autoencrypt ^= 1;
- else
- autoencrypt = on ? 1 : 0;
-}
-
-void
-decrypt_auto(int on)
-{
- if (on < 0)
- autodecrypt ^= 1;
- else
- autodecrypt = on ? 1 : 0;
-}
-
-void
-encrypt_start_output(int type)
-{
- Encryptions *ep;
- unsigned char *p;
- int i;
-
- if (!(ep = findencryption(type))) {
- if (encrypt_debug_mode) {
- printf(">>>%s: Can't encrypt with type %s (%d)\r\n",
- Name,
- ENCTYPE_NAME_OK(type)
- ? ENCTYPE_NAME(type) : "(unknown)",
- type);
- }
- return;
- }
- if (ep->start) {
- i = (*ep->start)(DIR_ENCRYPT, Server);
- if (encrypt_debug_mode) {
- printf(">>>%s: Encrypt start: %s (%d) %s\r\n",
- Name,
- (i < 0) ? "failed" :
- "initial negotiation in progress",
- i, ENCTYPE_NAME(type));
- }
- if (i)
- return;
- }
- p = str_start + 3;
- *p++ = ENCRYPT_START;
- for (i = 0; i < ki[0].keylen; ++i) {
- if ((*p++ = ki[0].keyid[i]) == IAC)
- *p++ = IAC;
- }
- *p++ = IAC;
- *p++ = SE;
- net_write(str_start, p - str_start);
- net_encrypt();
- printsub('>', &str_start[2], p - &str_start[2]);
- /*
- * If we are already encrypting in some mode, then
- * encrypt the ring (which includes our request) in
- * the old mode, mark it all as "clear text" and then
- * switch to the new mode.
- */
- encrypt_output = ep->output;
- encrypt_mode = type;
- if (encrypt_debug_mode)
- printf(">>>%s: Started to encrypt output with type %s\r\n",
- Name, ENCTYPE_NAME(type));
- if (encrypt_verbose)
- printf("[ Output is now encrypted with type %s ]\r\n",
- ENCTYPE_NAME(type));
-}
-
-void
-encrypt_send_end(void)
-{
- if (!encrypt_output)
- return;
-
- str_end[3] = ENCRYPT_END;
- net_write(str_end, sizeof(str_end));
- net_encrypt();
- printsub('>', &str_end[2], sizeof(str_end) - 2);
- /*
- * Encrypt the output buffer now because it will not be done by
- * netflush...
- */
- encrypt_output = 0;
- if (encrypt_debug_mode)
- printf(">>>%s: Output is back to clear text\r\n", Name);
- if (encrypt_verbose)
- printf("[ Output is now clear text ]\r\n");
-}
-
-void
-encrypt_send_request_start(void)
-{
- unsigned char *p;
- int i;
-
- p = &str_start[3];
- *p++ = ENCRYPT_REQSTART;
- for (i = 0; i < ki[1].keylen; ++i) {
- if ((*p++ = ki[1].keyid[i]) == IAC)
- *p++ = IAC;
- }
- *p++ = IAC;
- *p++ = SE;
- net_write(str_start, p - str_start);
- printsub('>', &str_start[2], p - &str_start[2]);
- if (encrypt_debug_mode)
- printf(">>>%s: Request input to be encrypted\r\n", Name);
-}
-
-void
-encrypt_send_request_end(void)
-{
- str_end[3] = ENCRYPT_REQEND;
- net_write(str_end, sizeof(str_end));
- printsub('>', &str_end[2], sizeof(str_end) - 2);
-
- if (encrypt_debug_mode)
- printf(">>>%s: Request input to be clear text\r\n", Name);
-}
-
-void
-encrypt_wait(void)
-{
- if (encrypt_debug_mode)
- printf(">>>%s: in encrypt_wait\r\n", Name);
- if (!havesessionkey || !(I_SUPPORT_ENCRYPT & remote_supports_decrypt))
- return;
- while (autoencrypt && !encrypt_output)
- if (telnet_spin())
- return;
-}
-
-void
-encrypt_gen_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
-{
- char tbuf[16], *cp;
-
- cnt -= 2;
- data += 2;
- buf[buflen-1] = '\0';
- buf[buflen-2] = '*';
- buflen -= 2;;
- for (; cnt > 0; cnt--, data++) {
- sprintf(tbuf, " %d", *data);
- for (cp = tbuf; *cp && buflen > 0; --buflen)
- *buf++ = *cp++;
- if (buflen <= 0)
- return;
- }
- *buf = '\0';
-}
-
-void
-encrypt_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
-{
- Encryptions *ep;
- int type = data[1];
-
- for (ep = encryptions; ep->type && ep->type != type; ep++)
- ;
-
- if (ep->printsub)
- (*ep->printsub)(data, cnt, buf, buflen);
- else
- encrypt_gen_printsub(data, cnt, buf, buflen);
-}
-#endif /* ENCRYPTION */
diff --git a/contrib/telnet/libtelnet/encrypt.h b/contrib/telnet/libtelnet/encrypt.h
deleted file mode 100644
index eda8d57e0328..000000000000
--- a/contrib/telnet/libtelnet/encrypt.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)encrypt.h 8.1 (Berkeley) 6/4/93
- * $FreeBSD$
- */
-
-/*
- * Copyright (C) 1990 by the Massachusetts Institute of Technology
- *
- * Export of this software from the United States of America is assumed
- * to require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifdef ENCRYPTION
-# ifndef __ENCRYPTION__
-# define __ENCRYPTION__
-
-#define DIR_DECRYPT 1
-#define DIR_ENCRYPT 2
-
-#include <openssl/des.h>
-typedef unsigned char Block[8];
-typedef unsigned char *BlockT;
-#if 0
-typedef struct { Block __; } Schedule[16];
-#else
-#define Schedule des_key_schedule
-#endif
-
-#define VALIDKEY(key) ( key[0] | key[1] | key[2] | key[3] | \
- key[4] | key[5] | key[6] | key[7])
-
-#define SAMEKEY(k1, k2) (!bcmp((void *)k1, (void *)k2, sizeof(Block)))
-
-typedef struct {
- short type;
- int length;
- unsigned char *data;
-} Session_Key;
-
-typedef struct {
- const char *name;
- int type;
- void (*output)(unsigned char *, int);
- int (*input)(int);
- void (*init)(int);
- int (*start)(int, int);
- int (*is)(unsigned char *, int);
- int (*reply)(unsigned char *, int);
- void (*session)(Session_Key *, int);
- int (*keyid)(int, unsigned char *, int *);
- void (*printsub)(unsigned char *, int, unsigned char *, int);
-} Encryptions;
-
-#define SK_DES 1 /* Matched Kerberos v5 KEYTYPE_DES */
-
-#include "enc-proto.h"
-
-extern int encrypt_debug_mode;
-extern int (*decrypt_input)(int);
-extern void (*encrypt_output)(unsigned char *, int);
-# endif /* __ENCRYPTION__ */
-#endif /* ENCRYPTION */
diff --git a/contrib/telnet/libtelnet/genget.c b/contrib/telnet/libtelnet/genget.c
deleted file mode 100644
index e24bb4458455..000000000000
--- a/contrib/telnet/libtelnet/genget.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-
-__FBSDID("$FreeBSD$");
-
-#ifndef lint
-#if 0
-static const char sccsid[] = "@(#)genget.c 8.2 (Berkeley) 5/30/95";
-#endif
-#endif /* not lint */
-
-
-#include <ctype.h>
-
-#include "misc-proto.h"
-
-#define LOWER(x) (isupper(x) ? tolower(x) : (x))
-/*
- * The prefix function returns 0 if *s1 is not a prefix
- * of *s2. If *s1 exactly matches *s2, the negative of
- * the length is returned. If *s1 is a prefix of *s2,
- * the length of *s1 is returned.
- */
-int
-isprefix(char *s1, const char *s2)
-{
- char *os1;
- char c1, c2;
-
- if (*s1 == '\0')
- return(-1);
- os1 = s1;
- c1 = *s1;
- c2 = *s2;
- while (LOWER(c1) == LOWER(c2)) {
- if (c1 == '\0')
- break;
- c1 = *++s1;
- c2 = *++s2;
- }
- return(*s1 ? 0 : (*s2 ? (s1 - os1) : (os1 - s1)));
-}
-
-static char *ambiguous; /* special return value for command routines */
-
-char **
-genget(char *name, char **table, int stlen)
-{
- char **c, **found;
- int n;
-
- if (name == 0)
- return 0;
-
- found = 0;
- for (c = table; *c != 0; c = (char **)((char *)c + stlen)) {
- if ((n = isprefix(name, *c)) == 0)
- continue;
- if (n < 0) /* exact match */
- return(c);
- if (found)
- return(&ambiguous);
- found = c;
- }
- return(found);
-}
-
-/*
- * Function call version of Ambiguous()
- */
-int
-Ambiguous(char **s)
-{
- return(s == &ambiguous);
-}
diff --git a/contrib/telnet/libtelnet/getent.c b/contrib/telnet/libtelnet/getent.c
deleted file mode 100644
index d6e8d9c88475..000000000000
--- a/contrib/telnet/libtelnet/getent.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-
-__FBSDID("$FreeBSD$");
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)getent.c 8.2 (Berkeley) 12/15/93";
-#endif
-#endif /* not lint */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "misc-proto.h"
-
-static char *area;
-static char gettytab[] = "/etc/gettytab";
-
-/*ARGSUSED*/
-int
-getent(char *cp __unused, const char *name)
-{
- int retval;
- char *tempnam, *dba[2] = { gettytab, NULL };
-
- tempnam = strdup(name);
- retval = cgetent(&area, dba, tempnam) == 0 ? 1 : 0;
- free(tempnam);
- return(retval);
-}
-
-/*ARGSUSED*/
-char *
-Getstr(const char *id, char **cpp __unused)
-{
- int retval;
- char *answer, *tempid;
-
- tempid = strdup(id);
- retval = cgetstr(area, tempid, &answer);
- free(tempid);
- return((retval > 0) ? answer : NULL);
-}
diff --git a/contrib/telnet/libtelnet/kerberos.c b/contrib/telnet/libtelnet/kerberos.c
deleted file mode 100644
index 2380c27daa5e..000000000000
--- a/contrib/telnet/libtelnet/kerberos.c
+++ /dev/null
@@ -1,506 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-
-__FBSDID("$FreeBSD$");
-
-#ifndef lint
-static const char sccsid[] = "@(#)kerberos.c 8.3 (Berkeley) 5/30/95";
-#endif /* not lint */
-
-/*
- * Copyright (C) 1990 by the Massachusetts Institute of Technology
- *
- * Export of this software from the United States of America is assumed
- * to require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifdef KRB4
-#include <sys/types.h>
-#include <arpa/telnet.h>
-#include <openssl/des.h> /* BSD wont include this in krb.h, so we do it here */
-#include <krb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "encrypt.h"
-#include "auth.h"
-#include "misc.h"
-
-int kerberos4_cksum(unsigned char *, int);
-int kuserok(AUTH_DAT *, char *);
-
-extern int auth_debug_mode;
-
-static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
- AUTHTYPE_KERBEROS_V4, };
-
-#define KRB_AUTH 0 /* Authentication data follows */
-#define KRB_REJECT 1 /* Rejected (reason might follow) */
-#define KRB_ACCEPT 2 /* Accepted */
-#define KRB_CHALLENGE 3 /* Challenge for mutual auth. */
-#define KRB_RESPONSE 4 /* Response for mutual auth. */
-
-static KTEXT_ST auth;
-static char name[ANAME_SZ];
-static AUTH_DAT adat = { 0, "", "", "", 0, {}, 0, 0, 0, { 0, "", 0 } };
-#ifdef ENCRYPTION
-static Block session_key = { 0 };
-static des_key_schedule sched;
-static Block challenge = { 0 };
-#endif /* ENCRYPTION */
-
-static char krb_service_name[] = "rcmd";
-static char empty[] = "";
-
-static int
-Data(Authenticator *ap, int type, const unsigned char *d, int c)
-{
- unsigned char *p = str_data + 4;
- const unsigned char *cd = d;
-
- if (c == -1)
- c = strlen(cd);
-
- if (auth_debug_mode) {
- printf("%s:%d: [%d] (%d)",
- str_data[3] == TELQUAL_IS ? ">>>IS" : ">>>REPLY",
- str_data[3],
- type, c);
- printd(d, c);
- printf("\r\n");
- }
- *p++ = ap->type;
- *p++ = ap->way;
- *p++ = type;
- while (c-- > 0) {
- if ((*p++ = *cd++) == IAC)
- *p++ = IAC;
- }
- *p++ = IAC;
- *p++ = SE;
- if (str_data[3] == TELQUAL_IS)
- printsub('>', &str_data[2], p - (&str_data[2]));
- return(net_write(str_data, p - str_data));
-}
-
-int
-kerberos4_init(Authenticator *ap __unused, int server)
-{
- FILE *fp;
-
- if (server) {
- str_data[3] = TELQUAL_REPLY;
- if ((fp = fopen(KEYFILE, "r")) == NULL)
- return(0);
- fclose(fp);
- } else {
- str_data[3] = TELQUAL_IS;
- }
- return(1);
-}
-
-char dst_realm_buf[REALM_SZ], *dest_realm = NULL;
-int dst_realm_sz = REALM_SZ;
-
-int
-kerberos4_send(Authenticator *ap)
-{
- KTEXT_ST lauth;
- char instance[INST_SZ];
- char *realm;
- CREDENTIALS cred;
- int r;
-
- printf("[ Trying KERBEROS4 ... ]\n");
- if (!UserNameRequested) {
- if (auth_debug_mode) {
- printf("Kerberos V4: no user name supplied\r\n");
- }
- return(0);
- }
-
- memset(instance, 0, sizeof(instance));
-
- if ((realm = krb_get_phost(RemoteHostName)))
- strncpy(instance, realm, sizeof(instance));
-
- instance[sizeof(instance)-1] = '\0';
-
- realm = dest_realm ? dest_realm : krb_realmofhost(RemoteHostName);
-
- if (!realm) {
- printf("Kerberos V4: no realm for %s\r\n", RemoteHostName);
- return(0);
- }
- if ((r = krb_mk_req(&lauth, krb_service_name, instance, realm, 0L))) {
- printf("mk_req failed: %s\r\n", krb_err_txt[r]);
- return(0);
- }
- if ((r = krb_get_cred(krb_service_name, instance, realm, &cred))) {
- printf("get_cred failed: %s\r\n", krb_err_txt[r]);
- return(0);
- }
- if (!auth_sendname(UserNameRequested, strlen(UserNameRequested))) {
- if (auth_debug_mode)
- printf("Not enough room for user name\r\n");
- return(0);
- }
- if (auth_debug_mode)
- printf("Sent %d bytes of authentication data\r\n", lauth.length);
- if (!Data(ap, KRB_AUTH, (void *)lauth.dat, lauth.length)) {
- if (auth_debug_mode)
- printf("Not enough room for authentication data\r\n");
- return(0);
- }
-#ifdef ENCRYPTION
- /*
- * If we are doing mutual authentication, get set up to send
- * the challenge, and verify it when the response comes back.
- */
- if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) {
- register int i;
-
- des_key_sched(&cred.session, sched);
- des_random_key(&session_key);
- des_ecb_encrypt(&session_key, &session_key, sched, 0);
- des_ecb_encrypt(&session_key, &challenge, sched, 0);
- /*
- * Increment the challenge by 1, and encrypt it for
- * later comparison.
- */
- for (i = 7; i >= 0; --i) {
- register int x;
- x = (unsigned int)challenge[i] + 1;
- challenge[i] = x; /* ignore overflow */
- if (x < 256) /* if no overflow, all done */
- break;
- }
- des_ecb_encrypt(&challenge, &challenge, sched, 1);
- }
-#endif /* ENCRYPTION */
-
- if (auth_debug_mode) {
- printf("CK: %d:", kerberos4_cksum(lauth.dat, lauth.length));
- printd(lauth.dat, lauth.length);
- printf("\r\n");
- printf("Sent Kerberos V4 credentials to server\r\n");
- }
- return(1);
-}
-
-void
-kerberos4_is(Authenticator *ap, unsigned char *data, int cnt)
-{
-#ifdef ENCRYPTION
- Session_Key skey;
- Block datablock;
-#endif /* ENCRYPTION */
- char realm[REALM_SZ];
- char instance[INST_SZ];
- int r;
-
- if (cnt-- < 1)
- return;
- switch (*data++) {
- case KRB_AUTH:
- if (krb_get_lrealm(realm, 1) != KSUCCESS) {
- Data(ap, KRB_REJECT, "No local V4 Realm.", -1);
- auth_finished(ap, AUTH_REJECT);
- if (auth_debug_mode)
- printf("No local realm\r\n");
- return;
- }
- memmove((void *)auth.dat, (void *)data, auth.length = cnt);
- if (auth_debug_mode) {
- printf("Got %d bytes of authentication data\r\n", cnt);
- printf("CK: %d:", kerberos4_cksum(auth.dat, auth.length));
- printd(auth.dat, auth.length);
- printf("\r\n");
- }
- instance[0] = '*'; instance[1] = 0;
- if ((r = krb_rd_req(&auth, krb_service_name,
- instance, 0, &adat, empty))) {
- if (auth_debug_mode)
- printf("Kerberos failed him as %s\r\n", name);
- Data(ap, KRB_REJECT, krb_err_txt[r], -1);
- auth_finished(ap, AUTH_REJECT);
- return;
- }
-#ifdef ENCRYPTION
- memmove((void *)session_key, (void *)adat.session, sizeof(Block));
-#endif /* ENCRYPTION */
- krb_kntoln(&adat, name);
-
- if (UserNameRequested && !kuserok(&adat, UserNameRequested))
- Data(ap, KRB_ACCEPT, NULL, 0);
- else
- Data(ap, KRB_REJECT, "user is not authorized", -1);
- auth_finished(ap, AUTH_USER);
- break;
-
- case KRB_CHALLENGE:
-#ifndef ENCRYPTION
- Data(ap, KRB_RESPONSE, NULL, 0);
-#else /* ENCRYPTION */
- if (!VALIDKEY(session_key)) {
- /*
- * We don't have a valid session key, so just
- * send back a response with an empty session
- * key.
- */
- Data(ap, KRB_RESPONSE, NULL, 0);
- break;
- }
-
- des_key_sched(&session_key, sched);
- memmove((void *)datablock, (void *)data, sizeof(Block));
- /*
- * Take the received encrypted challenge, and encrypt
- * it again to get a unique session_key for the
- * ENCRYPT option.
- */
- des_ecb_encrypt(&datablock, &session_key, sched, 1);
- skey.type = SK_DES;
- skey.length = 8;
- skey.data = session_key;
- encrypt_session_key(&skey, 1);
- /*
- * Now decrypt the received encrypted challenge,
- * increment by one, re-encrypt it and send it back.
- */
- des_ecb_encrypt(&datablock, &challenge, sched, 0);
- for (r = 7; r >= 0; r--) {
- register int t;
- t = (unsigned int)challenge[r] + 1;
- challenge[r] = t; /* ignore overflow */
- if (t < 256) /* if no overflow, all done */
- break;
- }
- des_ecb_encrypt(&challenge, &challenge, sched, 1);
- Data(ap, KRB_RESPONSE, challenge, sizeof(challenge));
-#endif /* ENCRYPTION */
- break;
-
- default:
- if (auth_debug_mode)
- printf("Unknown Kerberos option %d\r\n", data[-1]);
- Data(ap, KRB_REJECT, NULL, 0);
- break;
- }
-}
-
-void
-kerberos4_reply(Authenticator *ap, unsigned char *data, int cnt)
-{
-#ifdef ENCRYPTION
- Session_Key skey;
-#endif /* ENCRYPTION */
-
- if (cnt-- < 1)
- return;
- switch (*data++) {
- case KRB_REJECT:
- if (cnt > 0) {
- printf("[ Kerberos V4 refuses authentication because %.*s ]\r\n",
- cnt, data);
- } else
- printf("[ Kerberos V4 refuses authentication ]\r\n");
- auth_send_retry();
- return;
- case KRB_ACCEPT:
- printf("[ Kerberos V4 accepts you ]\n");
- if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) {
- /*
- * Send over the encrypted challenge.
- */
-#ifndef ENCRYPTION
- Data(ap, KRB_CHALLENGE, NULL, 0);
-#else /* ENCRYPTION */
- Data(ap, KRB_CHALLENGE, session_key,
- sizeof(session_key));
- des_ecb_encrypt(&session_key, &session_key, sched, 1);
- skey.type = SK_DES;
- skey.length = 8;
- skey.data = session_key;
- encrypt_session_key(&skey, 0);
-#endif /* ENCRYPTION */
- return;
- }
- auth_finished(ap, AUTH_USER);
- return;
- case KRB_RESPONSE:
-#ifdef ENCRYPTION
- /*
- * Verify that the response to the challenge is correct.
- */
- if ((cnt != sizeof(Block)) ||
- (0 != memcmp((void *)data, (void *)challenge,
- sizeof(challenge))))
- {
-#endif /* ENCRYPTION */
- printf("[ Kerberos V4 challenge failed!!! ]\r\n");
- auth_send_retry();
- return;
-#ifdef ENCRYPTION
- }
- printf("[ Kerberos V4 challenge successful ]\r\n");
- auth_finished(ap, AUTH_USER);
-#endif /* ENCRYPTION */
- break;
- default:
- if (auth_debug_mode)
- printf("Unknown Kerberos option %d\r\n", data[-1]);
- return;
- }
-}
-
-int
-kerberos4_status(Authenticator *ap __unused, char *nam, int level)
-{
- if (level < AUTH_USER)
- return(level);
-
- if (UserNameRequested && !kuserok(&adat, UserNameRequested)) {
- strcpy(nam, UserNameRequested);
- return(AUTH_VALID);
- } else
- return(AUTH_USER);
-}
-
-#define BUMP(buf, len) while (*(buf)) {++(buf), --(len);}
-#define ADDC(buf, len, c) if ((len) > 0) {*(buf)++ = (c); --(len);}
-
-void
-kerberos4_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
-{
- char lbuf[32];
- register int i;
-
- buf[buflen-1] = '\0'; /* make sure its NULL terminated */
- buflen -= 1;
-
- switch(data[3]) {
- case KRB_REJECT: /* Rejected (reason might follow) */
- strncpy((char *)buf, " REJECT ", buflen);
- goto common;
-
- case KRB_ACCEPT: /* Accepted (name might follow) */
- strncpy((char *)buf, " ACCEPT ", buflen);
- common:
- BUMP(buf, buflen);
- if (cnt <= 4)
- break;
- ADDC(buf, buflen, '"');
- for (i = 4; i < cnt; i++)
- ADDC(buf, buflen, data[i]);
- ADDC(buf, buflen, '"');
- ADDC(buf, buflen, '\0');
- break;
-
- case KRB_AUTH: /* Authentication data follows */
- strncpy((char *)buf, " AUTH", buflen);
- goto common2;
-
- case KRB_CHALLENGE:
- strncpy((char *)buf, " CHALLENGE", buflen);
- goto common2;
-
- case KRB_RESPONSE:
- strncpy((char *)buf, " RESPONSE", buflen);
- goto common2;
-
- default:
- sprintf(lbuf, " %d (unknown)", data[3]);
- strncpy((char *)buf, lbuf, buflen);
- common2:
- BUMP(buf, buflen);
- for (i = 4; i < cnt; i++) {
- sprintf(lbuf, " %d", data[i]);
- strncpy((char *)buf, lbuf, buflen);
- BUMP(buf, buflen);
- }
- break;
- }
-}
-
-int
-kerberos4_cksum(unsigned char *d, int n)
-{
- int ck = 0;
-
- /*
- * A comment is probably needed here for those not
- * well versed in the "C" language. Yes, this is
- * supposed to be a "switch" with the body of the
- * "switch" being a "while" statement. The whole
- * purpose of the switch is to allow us to jump into
- * the middle of the while() loop, and then not have
- * to do any more switch()s.
- *
- * Some compilers will spit out a warning message
- * about the loop not being entered at the top.
- */
- switch (n&03)
- while (n > 0) {
- case 0:
- ck ^= (int)*d++ << 24;
- --n;
- case 3:
- ck ^= (int)*d++ << 16;
- --n;
- case 2:
- ck ^= (int)*d++ << 8;
- --n;
- case 1:
- ck ^= (int)*d++;
- --n;
- }
- return(ck);
-}
-#endif
diff --git a/contrib/telnet/libtelnet/kerberos5.c b/contrib/telnet/libtelnet/kerberos5.c
deleted file mode 100644
index ab7b2dce47b8..000000000000
--- a/contrib/telnet/libtelnet/kerberos5.c
+++ /dev/null
@@ -1,825 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Copyright (C) 1990 by the Massachusetts Institute of Technology
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <sys/cdefs.h>
-
-__FBSDID("$FreeBSD$");
-
-#ifdef KRB5
-
-#include <arpa/telnet.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <netdb.h>
-#include <ctype.h>
-#include <pwd.h>
-#define Authenticator k5_Authenticator
-#include <krb5.h>
-#undef Authenticator
-
-#include "encrypt.h"
-#include "auth.h"
-#include "misc.h"
-
-int forward_flags = 0; /* Flags get set in telnet/main.c on -f and -F */
-
-/* These values need to be the same as those defined in telnet/main.c. */
-/* Either define them in both places, or put in some common header file. */
-#define OPTS_FORWARD_CREDS 0x00000002
-#define OPTS_FORWARDABLE_CREDS 0x00000001
-
-void kerberos5_forward (Authenticator *);
-
-static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
- AUTHTYPE_KERBEROS_V5, };
-
-#define KRB_AUTH 0 /* Authentication data follows */
-#define KRB_REJECT 1 /* Rejected (reason might follow) */
-#define KRB_ACCEPT 2 /* Accepted */
-#define KRB_RESPONSE 3 /* Response for mutual auth. */
-
-#define KRB_FORWARD 4 /* Forwarded credentials follow */
-#define KRB_FORWARD_ACCEPT 5 /* Forwarded credentials accepted */
-#define KRB_FORWARD_REJECT 6 /* Forwarded credentials rejected */
-
-static krb5_data auth;
-static krb5_ticket *ticket;
-
-static krb5_context context;
-static krb5_auth_context auth_context;
-
-static int
-Data(Authenticator *ap, int type, const char *d, int c)
-{
- unsigned char *p = str_data + 4;
- const unsigned char *cd = d;
-
- if (c == -1)
- c = strlen(cd);
-
- if (auth_debug_mode) {
- printf("%s:%d: [%d] (%d)",
- str_data[3] == TELQUAL_IS ? ">>>IS" : ">>>REPLY",
- str_data[3],
- type, c);
- printd(d, c);
- printf("\r\n");
- }
- *p++ = ap->type;
- *p++ = ap->way;
- *p++ = type;
- while (c-- > 0) {
- if ((*p++ = *cd++) == IAC)
- *p++ = IAC;
- }
- *p++ = IAC;
- *p++ = SE;
- if (str_data[3] == TELQUAL_IS)
- printsub('>', &str_data[2], p - &str_data[2]);
- return(net_write(str_data, p - str_data));
-}
-
-int
-kerberos5_init(Authenticator *ap __unused, int server)
-{
- krb5_error_code ret;
-
- ret = krb5_init_context(&context);
- if (ret)
- return 0;
- if (server) {
- krb5_keytab kt;
- krb5_kt_cursor cursor;
-
- ret = krb5_kt_default(context, &kt);
- if (ret)
- return 0;
-
- ret = krb5_kt_start_seq_get (context, kt, &cursor);
- if (ret) {
- krb5_kt_close (context, kt);
- return 0;
- }
- krb5_kt_end_seq_get (context, kt, &cursor);
- krb5_kt_close (context, kt);
-
- str_data[3] = TELQUAL_REPLY;
- } else
- str_data[3] = TELQUAL_IS;
- return(1);
-}
-
-extern int net;
-
-static int
-kerberos5_send(const char *name, Authenticator *ap)
-{
- krb5_error_code ret;
- krb5_ccache ccache;
- int ap_opts;
- krb5_data cksum_data;
- char foo[2];
-
- if (!UserNameRequested) {
- if (auth_debug_mode) {
- printf("Kerberos V5: no user name supplied\r\n");
- }
- return(0);
- }
-
- ret = krb5_cc_default(context, &ccache);
- if (ret) {
- if (auth_debug_mode) {
- printf("Kerberos V5: could not get default ccache: %s\r\n",
- krb5_get_err_text (context, ret));
- }
- return 0;
- }
-
- if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL)
- ap_opts = AP_OPTS_MUTUAL_REQUIRED;
- else
- ap_opts = 0;
- ap_opts |= AP_OPTS_USE_SUBKEY;
-
- ret = krb5_auth_con_init (context, &auth_context);
- if (ret) {
- if (auth_debug_mode) {
- printf("Kerberos V5: krb5_auth_con_init failed (%s)\r\n",
- krb5_get_err_text(context, ret));
- }
- return(0);
- }
-
- ret = krb5_auth_con_setaddrs_from_fd (context,
- auth_context,
- &net);
- if (ret) {
- if (auth_debug_mode) {
- printf ("Kerberos V5:"
- " krb5_auth_con_setaddrs_from_fd failed (%s)\r\n",
- krb5_get_err_text(context, ret));
- }
- return(0);
- }
-
- krb5_auth_con_setkeytype (context, auth_context, KEYTYPE_DES);
-
- foo[0] = ap->type;
- foo[1] = ap->way;
-
- cksum_data.length = sizeof(foo);
- cksum_data.data = foo;
-
-
- {
- krb5_principal service;
- char sname[128];
-
-
- ret = krb5_sname_to_principal (context,
- RemoteHostName,
- NULL,
- KRB5_NT_SRV_HST,
- &service);
- if(ret) {
- if (auth_debug_mode) {
- printf ("Kerberos V5:"
- " krb5_sname_to_principal(%s) failed (%s)\r\n",
- RemoteHostName, krb5_get_err_text(context, ret));
- }
- return 0;
- }
- ret = krb5_unparse_name_fixed(context, service, sname, sizeof(sname));
- if(ret) {
- if (auth_debug_mode) {
- printf ("Kerberos V5:"
- " krb5_unparse_name_fixed failed (%s)\r\n",
- krb5_get_err_text(context, ret));
- }
- return 0;
- }
- printf("[ Trying %s (%s)... ]\r\n", name, sname);
- ret = krb5_mk_req_exact(context, &auth_context, ap_opts,
- service,
- &cksum_data, ccache, &auth);
- krb5_free_principal (context, service);
-
- }
- if (ret) {
- if (1 || auth_debug_mode) {
- printf("Kerberos V5: mk_req failed (%s)\r\n",
- krb5_get_err_text(context, ret));
- }
- return(0);
- }
-
- if (!auth_sendname((unsigned char *)UserNameRequested,
- strlen(UserNameRequested))) {
- if (auth_debug_mode)
- printf("Not enough room for user name\r\n");
- return(0);
- }
- if (!Data(ap, KRB_AUTH, auth.data, auth.length)) {
- if (auth_debug_mode)
- printf("Not enough room for authentication data\r\n");
- return(0);
- }
- if (auth_debug_mode) {
- printf("Sent Kerberos V5 credentials to server\r\n");
- }
- return(1);
-}
-
-int
-kerberos5_send_mutual(Authenticator *ap)
-{
- return kerberos5_send("mutual KERBEROS5", ap);
-}
-
-int
-kerberos5_send_oneway(Authenticator *ap)
-{
- return kerberos5_send("KERBEROS5", ap);
-}
-
-void
-kerberos5_is(Authenticator *ap, unsigned char *data, int cnt)
-{
- krb5_error_code ret;
- krb5_data outbuf;
- krb5_keyblock *key_block;
- char *name;
- krb5_principal server;
- int zero = 0;
-
- if (cnt-- < 1)
- return;
- switch (*data++) {
- case KRB_AUTH:
- auth.data = (char *)data;
- auth.length = cnt;
-
- auth_context = NULL;
-
- ret = krb5_auth_con_init (context, &auth_context);
- if (ret) {
- Data(ap, KRB_REJECT, "krb5_auth_con_init failed", -1);
- auth_finished(ap, AUTH_REJECT);
- if (auth_debug_mode)
- printf("Kerberos V5: krb5_auth_con_init failed (%s)\r\n",
- krb5_get_err_text(context, ret));
- return;
- }
-
- ret = krb5_auth_con_setaddrs_from_fd (context,
- auth_context,
- &zero);
- if (ret) {
- Data(ap, KRB_REJECT, "krb5_auth_con_setaddrs_from_fd failed", -1);
- auth_finished(ap, AUTH_REJECT);
- if (auth_debug_mode)
- printf("Kerberos V5: "
- "krb5_auth_con_setaddrs_from_fd failed (%s)\r\n",
- krb5_get_err_text(context, ret));
- return;
- }
-
- ret = krb5_sock_to_principal (context,
- 0,
- "host",
- KRB5_NT_SRV_HST,
- &server);
- if (ret) {
- Data(ap, KRB_REJECT, "krb5_sock_to_principal failed", -1);
- auth_finished(ap, AUTH_REJECT);
- if (auth_debug_mode)
- printf("Kerberos V5: "
- "krb5_sock_to_principal failed (%s)\r\n",
- krb5_get_err_text(context, ret));
- return;
- }
-
- ret = krb5_rd_req(context,
- &auth_context,
- &auth,
- server,
- NULL,
- NULL,
- &ticket);
-
- krb5_free_principal (context, server);
- if (ret) {
- char *errbuf;
-
- asprintf(&errbuf,
- "Read req failed: %s",
- krb5_get_err_text(context, ret));
- Data(ap, KRB_REJECT, errbuf, -1);
- if (auth_debug_mode)
- printf("%s\r\n", errbuf);
- free (errbuf);
- return;
- }
-
- {
- char foo[2];
-
- foo[0] = ap->type;
- foo[1] = ap->way;
-
- ret = krb5_verify_authenticator_checksum(context,
- auth_context,
- foo,
- sizeof(foo));
-
- if (ret) {
- char *errbuf;
- asprintf(&errbuf, "Bad checksum: %s",
- krb5_get_err_text(context, ret));
- Data(ap, KRB_REJECT, errbuf, -1);
- if (auth_debug_mode)
- printf ("%s\r\n", errbuf);
- free(errbuf);
- return;
- }
- }
- ret = krb5_auth_con_getremotesubkey (context,
- auth_context,
- &key_block);
-
- if (ret) {
- Data(ap, KRB_REJECT, "krb5_auth_con_getremotesubkey failed", -1);
- auth_finished(ap, AUTH_REJECT);
- if (auth_debug_mode)
- printf("Kerberos V5: "
- "krb5_auth_con_getremotesubkey failed (%s)\r\n",
- krb5_get_err_text(context, ret));
- return;
- }
-
- if (key_block == NULL) {
- ret = krb5_auth_con_getkey(context,
- auth_context,
- &key_block);
- }
- if (ret) {
- Data(ap, KRB_REJECT, "krb5_auth_con_getkey failed", -1);
- auth_finished(ap, AUTH_REJECT);
- if (auth_debug_mode)
- printf("Kerberos V5: "
- "krb5_auth_con_getkey failed (%s)\r\n",
- krb5_get_err_text(context, ret));
- return;
- }
- if (key_block == NULL) {
- Data(ap, KRB_REJECT, "no subkey received", -1);
- auth_finished(ap, AUTH_REJECT);
- if (auth_debug_mode)
- printf("Kerberos V5: "
- "krb5_auth_con_getremotesubkey returned NULL key\r\n");
- return;
- }
-
- if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) {
- ret = krb5_mk_rep(context, auth_context, &outbuf);
- if (ret) {
- Data(ap, KRB_REJECT,
- "krb5_mk_rep failed", -1);
- auth_finished(ap, AUTH_REJECT);
- if (auth_debug_mode)
- printf("Kerberos V5: "
- "krb5_mk_rep failed (%s)\r\n",
- krb5_get_err_text(context, ret));
- return;
- }
- Data(ap, KRB_RESPONSE, outbuf.data, outbuf.length);
- }
- if (krb5_unparse_name(context, ticket->client, &name))
- name = 0;
-
- if(UserNameRequested && krb5_kuserok(context,
- ticket->client,
- UserNameRequested)) {
- Data(ap, KRB_ACCEPT, name, name ? -1 : 0);
- if (auth_debug_mode) {
- printf("Kerberos5 identifies him as ``%s''\r\n",
- name ? name : "");
- }
-
- if(key_block->keytype == ETYPE_DES_CBC_MD5 ||
- key_block->keytype == ETYPE_DES_CBC_MD4 ||
- key_block->keytype == ETYPE_DES_CBC_CRC) {
- Session_Key skey;
-
- skey.type = SK_DES;
- skey.length = 8;
- skey.data = key_block->keyvalue.data;
- encrypt_session_key(&skey, 0);
- }
-
- } else {
- char *msg;
-
- asprintf (&msg, "user `%s' is not authorized to "
- "login as `%s'",
- name ? name : "<unknown>",
- UserNameRequested ? UserNameRequested : "<nobody>");
- if (msg == NULL)
- Data(ap, KRB_REJECT, NULL, 0);
- else {
- Data(ap, KRB_REJECT, (void *)msg, -1);
- free(msg);
- }
- auth_finished (ap, AUTH_REJECT);
- krb5_free_keyblock_contents(context, key_block);
- break;
- }
- auth_finished(ap, AUTH_USER);
- krb5_free_keyblock_contents(context, key_block);
-
- break;
- case KRB_FORWARD: {
- struct passwd *pwd;
- char ccname[1024]; /* XXX */
- krb5_data inbuf;
- krb5_ccache ccache;
- inbuf.data = (char *)data;
- inbuf.length = cnt;
-
- pwd = getpwnam (UserNameRequested);
- if (pwd == NULL)
- break;
-
- snprintf (ccname, sizeof(ccname),
- "FILE:/tmp/krb5cc_%u", pwd->pw_uid);
-
- ret = krb5_cc_resolve (context, ccname, &ccache);
- if (ret) {
- if (auth_debug_mode)
- printf ("Kerberos V5: could not get ccache: %s\r\n",
- krb5_get_err_text(context, ret));
- break;
- }
-
- ret = krb5_cc_initialize (context,
- ccache,
- ticket->client);
- if (ret) {
- if (auth_debug_mode)
- printf ("Kerberos V5: could not init ccache: %s\r\n",
- krb5_get_err_text(context, ret));
- break;
- }
-
-#if defined(DCE)
- esetenv("KRB5CCNAME", ccname, 1);
-#endif
- ret = krb5_rd_cred2 (context,
- auth_context,
- ccache,
- &inbuf);
- if(ret) {
- char *errbuf;
-
- asprintf (&errbuf,
- "Read forwarded creds failed: %s",
- krb5_get_err_text (context, ret));
- if(errbuf == NULL)
- Data(ap, KRB_FORWARD_REJECT, NULL, 0);
- else
- Data(ap, KRB_FORWARD_REJECT, errbuf, -1);
- if (auth_debug_mode)
- printf("Could not read forwarded credentials: %s\r\n",
- errbuf);
- free (errbuf);
- } else {
- Data(ap, KRB_FORWARD_ACCEPT, 0, 0);
-#if defined(DCE)
- dfsfwd = 1;
-#endif
- }
- chown (ccname + 5, pwd->pw_uid, -1);
- if (auth_debug_mode)
- printf("Forwarded credentials obtained\r\n");
- break;
- }
- default:
- if (auth_debug_mode)
- printf("Unknown Kerberos option %d\r\n", data[-1]);
- Data(ap, KRB_REJECT, 0, 0);
- break;
- }
-}
-
-void
-kerberos5_reply(Authenticator *ap, unsigned char *data, int cnt)
-{
- static int mutual_complete = 0;
-
- if (cnt-- < 1)
- return;
- switch (*data++) {
- case KRB_REJECT:
- if (cnt > 0) {
- printf("[ Kerberos V5 refuses authentication because %.*s ]\r\n",
- cnt, data);
- } else
- printf("[ Kerberos V5 refuses authentication ]\r\n");
- auth_send_retry();
- return;
- case KRB_ACCEPT: {
- krb5_error_code ret;
- Session_Key skey;
- krb5_keyblock *keyblock;
-
- if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL &&
- !mutual_complete) {
- printf("[ Kerberos V5 accepted you, but didn't provide mutual authentication! ]\r\n");
- auth_send_retry();
- return;
- }
- if (cnt)
- printf("[ Kerberos V5 accepts you as ``%.*s'' ]\r\n", cnt, data);
- else
- printf("[ Kerberos V5 accepts you ]\r\n");
-
- ret = krb5_auth_con_getlocalsubkey (context,
- auth_context,
- &keyblock);
- if (ret)
- ret = krb5_auth_con_getkey (context,
- auth_context,
- &keyblock);
- if(ret) {
- printf("[ krb5_auth_con_getkey: %s ]\r\n",
- krb5_get_err_text(context, ret));
- auth_send_retry();
- return;
- }
-
- skey.type = SK_DES;
- skey.length = 8;
- skey.data = keyblock->keyvalue.data;
- encrypt_session_key(&skey, 0);
- krb5_free_keyblock_contents (context, keyblock);
- auth_finished(ap, AUTH_USER);
- if (forward_flags & OPTS_FORWARD_CREDS)
- kerberos5_forward(ap);
- break;
- }
- case KRB_RESPONSE:
- if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) {
- /* the rest of the reply should contain a krb_ap_rep */
- krb5_ap_rep_enc_part *reply;
- krb5_data inbuf;
- krb5_error_code ret;
-
- inbuf.length = cnt;
- inbuf.data = (char *)data;
-
- ret = krb5_rd_rep(context, auth_context, &inbuf, &reply);
- if (ret) {
- printf("[ Mutual authentication failed: %s ]\r\n",
- krb5_get_err_text (context, ret));
- auth_send_retry();
- return;
- }
- krb5_free_ap_rep_enc_part(context, reply);
- mutual_complete = 1;
- }
- return;
- case KRB_FORWARD_ACCEPT:
- printf("[ Kerberos V5 accepted forwarded credentials ]\r\n");
- return;
- case KRB_FORWARD_REJECT:
- printf("[ Kerberos V5 refuses forwarded credentials because %.*s ]\r\n",
- cnt, data);
- return;
- default:
- if (auth_debug_mode)
- printf("Unknown Kerberos option %d\r\n", data[-1]);
- return;
- }
-}
-
-int
-kerberos5_status(Authenticator *ap __unused, char *name, int level)
-{
- if (level < AUTH_USER)
- return(level);
-
- if (UserNameRequested &&
- krb5_kuserok(context,
- ticket->client,
- UserNameRequested))
- {
- strcpy(name, UserNameRequested);
- return(AUTH_VALID);
- } else
- return(AUTH_USER);
-}
-
-#define BUMP(buf, len) while (*(buf)) {++(buf), --(len);}
-#define ADDC(buf, len, c) if ((len) > 0) {*(buf)++ = (c); --(len);}
-
-void
-kerberos5_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
-{
- int i;
-
- buf[buflen-1] = '\0'; /* make sure its NULL terminated */
- buflen -= 1;
-
- switch(data[3]) {
- case KRB_REJECT: /* Rejected (reason might follow) */
- strlcpy((char *)buf, " REJECT ", buflen);
- goto common;
-
- case KRB_ACCEPT: /* Accepted (name might follow) */
- strlcpy((char *)buf, " ACCEPT ", buflen);
- common:
- BUMP(buf, buflen);
- if (cnt <= 4)
- break;
- ADDC(buf, buflen, '"');
- for (i = 4; i < cnt; i++)
- ADDC(buf, buflen, data[i]);
- ADDC(buf, buflen, '"');
- ADDC(buf, buflen, '\0');
- break;
-
-
- case KRB_AUTH: /* Authentication data follows */
- strlcpy((char *)buf, " AUTH", buflen);
- goto common2;
-
- case KRB_RESPONSE:
- strlcpy((char *)buf, " RESPONSE", buflen);
- goto common2;
-
- case KRB_FORWARD: /* Forwarded credentials follow */
- strlcpy((char *)buf, " FORWARD", buflen);
- goto common2;
-
- case KRB_FORWARD_ACCEPT: /* Forwarded credentials accepted */
- strlcpy((char *)buf, " FORWARD_ACCEPT", buflen);
- goto common2;
-
- case KRB_FORWARD_REJECT: /* Forwarded credentials rejected */
- /* (reason might follow) */
- strlcpy((char *)buf, " FORWARD_REJECT", buflen);
- goto common2;
-
- default:
- snprintf(buf, buflen, " %d (unknown)", data[3]);
- common2:
- BUMP(buf, buflen);
- for (i = 4; i < cnt; i++) {
- snprintf(buf, buflen, " %d", data[i]);
- BUMP(buf, buflen);
- }
- break;
- }
-}
-
-void
-kerberos5_forward(Authenticator *ap)
-{
- krb5_error_code ret;
- krb5_ccache ccache;
- krb5_creds creds;
- krb5_kdc_flags flags;
- krb5_data out_data;
- krb5_principal principal;
-
- ret = krb5_cc_default (context, &ccache);
- if (ret) {
- if (auth_debug_mode)
- printf ("KerberosV5: could not get default ccache: %s\r\n",
- krb5_get_err_text (context, ret));
- return;
- }
-
- ret = krb5_cc_get_principal (context, ccache, &principal);
- if (ret) {
- if (auth_debug_mode)
- printf ("KerberosV5: could not get principal: %s\r\n",
- krb5_get_err_text (context, ret));
- return;
- }
-
- memset (&creds, 0, sizeof(creds));
-
- creds.client = principal;
-
- ret = krb5_build_principal (context,
- &creds.server,
- strlen(principal->realm),
- principal->realm,
- "krbtgt",
- principal->realm,
- NULL);
-
- if (ret) {
- if (auth_debug_mode)
- printf ("KerberosV5: could not get principal: %s\r\n",
- krb5_get_err_text (context, ret));
- return;
- }
-
- creds.times.endtime = 0;
-
- flags.i = 0;
- flags.b.forwarded = 1;
- if (forward_flags & OPTS_FORWARDABLE_CREDS)
- flags.b.forwardable = 1;
-
- ret = krb5_get_forwarded_creds (context,
- auth_context,
- ccache,
- flags.i,
- RemoteHostName,
- &creds,
- &out_data);
- if (ret) {
- if (auth_debug_mode)
- printf ("Kerberos V5: error getting forwarded creds: %s\r\n",
- krb5_get_err_text (context, ret));
- return;
- }
-
- if(!Data(ap, KRB_FORWARD, out_data.data, out_data.length)) {
- if (auth_debug_mode)
- printf("Not enough room for authentication data\r\n");
- } else {
- if (auth_debug_mode)
- printf("Forwarded local Kerberos V5 credentials to server\r\n");
- }
-}
-
-#if defined(DCE)
-/* if this was a K5 authentication try and join a PAG for the user. */
-void
-kerberos5_dfspag(void)
-{
- if (dfsk5ok) {
- dfspag = krb5_dfs_pag(context, dfsfwd, ticket->client,
- UserNameRequested);
- }
-}
-#endif
-
-#endif /* KRB5 */
diff --git a/contrib/telnet/libtelnet/key-proto.h b/contrib/telnet/libtelnet/key-proto.h
deleted file mode 100644
index 2f3f3466daa5..000000000000
--- a/contrib/telnet/libtelnet/key-proto.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)key-proto.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * Copyright (C) 1990 by the Massachusetts Institute of Technology
- *
- * Export of this software from the United States of America is assumed
- * to require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- *
- * $FreeBSD$
- */
-
-#ifndef __KEY_PROTO__
-#define __KEY_PROTO__
-
-int key_file_exists(void);
-void key_lookup(unsigned char *, Block);
-void key_stream_init(Block, Block, int);
-unsigned char key_stream(int, int);
-#endif
diff --git a/contrib/telnet/libtelnet/krb4encpwd.c b/contrib/telnet/libtelnet/krb4encpwd.c
deleted file mode 100644
index e0530f6e63c3..000000000000
--- a/contrib/telnet/libtelnet/krb4encpwd.c
+++ /dev/null
@@ -1,428 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-
-__FBSDID("$FreeBSD$");
-
-#ifndef lint
-static char sccsid[] = "@(#)krb4encpwd.c 8.3 (Berkeley) 5/30/95";
-#endif /* not lint */
-
-
-#ifdef KRB4_ENCPWD
-/*
- * COPYRIGHT (C) 1990 DIGITAL EQUIPMENT CORPORATION
- * ALL RIGHTS RESERVED
- *
- * "Digital Equipment Corporation authorizes the reproduction,
- * distribution and modification of this software subject to the following
- * restrictions:
- *
- * 1. Any partial or whole copy of this software, or any modification
- * thereof, must include this copyright notice in its entirety.
- *
- * 2. This software is supplied "as is" with no warranty of any kind,
- * expressed or implied, for any purpose, including any warranty of fitness
- * or merchantibility. DIGITAL assumes no responsibility for the use or
- * reliability of this software, nor promises to provide any form of
- * support for it on any basis.
- *
- * 3. Distribution of this software is authorized only if no profit or
- * remuneration of any kind is received in exchange for such distribution.
- *
- * 4. This software produces public key authentication certificates
- * bearing an expiration date established by DIGITAL and RSA Data
- * Security, Inc. It may cease to generate certificates after the expiration
- * date. Any modification of this software that changes or defeats
- * the expiration date or its effect is unauthorized.
- *
- * 5. Software that will renew or extend the expiration date of
- * authentication certificates produced by this software may be obtained
- * from RSA Data Security, Inc., 10 Twin Dolphin Drive, Redwood City, CA
- * 94065, (415)595-8782, or from DIGITAL"
- *
- */
-
-#include <sys/types.h>
-#include <openssl/des.h>
-#include <arpa/telnet.h>
-#include <krb.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "encrypt.h"
-#include "auth.h"
-#include "misc.h"
-
-int krb_mk_encpwd_req(KTEXT, char *, char *, char *, char *, char *, char *);
-int krb_rd_encpwd_req(KTEXT, char *, char *, u_long, AUTH_DAT *, char *, char *, char *, char *);
-
-extern auth_debug_mode;
-
-static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
- AUTHTYPE_KRB4_ENCPWD, };
-static unsigned char str_name[1024] = { IAC, SB, TELOPT_AUTHENTICATION,
- TELQUAL_NAME, };
-
-#define KRB4_ENCPWD_AUTH 0 /* Authentication data follows */
-#define KRB4_ENCPWD_REJECT 1 /* Rejected (reason might follow) */
-#define KRB4_ENCPWD_ACCEPT 2 /* Accepted */
-#define KRB4_ENCPWD_CHALLENGE 3 /* Challenge for mutual auth. */
-#define KRB4_ENCPWD_ACK 4 /* Acknowledge */
-
-#define KRB_SERVICE_NAME "rcmd"
-
-static KTEXT_ST auth;
-static char name[ANAME_SZ];
-static char user_passwd[ANAME_SZ];
-static AUTH_DAT adat = { 0 };
-#ifdef ENCRYPTION
-static Block session_key = { 0 };
-#endif /* ENCRYPTION */
-static char challenge[REALM_SZ];
-
- static int
-Data(ap, type, d, c)
- Authenticator *ap;
- int type;
- void *d;
- int c;
-{
- unsigned char *p = str_data + 4;
- unsigned char *cd = (unsigned char *)d;
-
- if (c == -1)
- c = strlen((char *)cd);
-
- if (0) {
- printf("%s:%d: [%d] (%d)",
- str_data[3] == TELQUAL_IS ? ">>>IS" : ">>>REPLY",
- str_data[3],
- type, c);
- printd(d, c);
- printf("\r\n");
- }
- *p++ = ap->type;
- *p++ = ap->way;
- *p++ = type;
- while (c-- > 0) {
- if ((*p++ = *cd++) == IAC)
- *p++ = IAC;
- }
- *p++ = IAC;
- *p++ = SE;
- if (str_data[3] == TELQUAL_IS)
- printsub('>', &str_data[2], p - (&str_data[2]));
- return(net_write(str_data, p - str_data));
-}
-
- int
-krb4encpwd_init(ap, server)
- Authenticator *ap;
- int server;
-{
- char hostname[80], *cp, *realm;
- C_Block skey;
-
- if (server) {
- str_data[3] = TELQUAL_REPLY;
- } else {
- str_data[3] = TELQUAL_IS;
- gethostname(hostname, sizeof(hostname));
- realm = krb_realmofhost(hostname);
- cp = strchr(hostname, '.');
- if (*cp != NULL) *cp = NULL;
- if (read_service_key(KRB_SERVICE_NAME, hostname, realm, 0,
- KEYFILE, (char *)skey)) {
- return(0);
- }
- }
- return(1);
-}
-
- int
-krb4encpwd_send(ap)
- Authenticator *ap;
-{
-
- printf("[ Trying KRB4ENCPWD ... ]\n");
- if (!UserNameRequested) {
- return(0);
- }
- if (!auth_sendname(UserNameRequested, strlen(UserNameRequested))) {
- return(0);
- }
-
- if (!Data(ap, KRB4_ENCPWD_ACK, (void *)NULL, 0)) {
- return(0);
- }
-
- return(1);
-}
-
- void
-krb4encpwd_is(ap, data, cnt)
- Authenticator *ap;
- unsigned char *data;
- int cnt;
-{
- Session_Key skey;
- Block datablock;
- char r_passwd[ANAME_SZ], r_user[ANAME_SZ];
- char lhostname[ANAME_SZ], *cp;
- int r;
- time_t now;
-
- if (cnt-- < 1)
- return;
- switch (*data++) {
- case KRB4_ENCPWD_AUTH:
- memmove((void *)auth.dat, (void *)data, auth.length = cnt);
-
- gethostname(lhostname, sizeof(lhostname));
- if ((cp = strchr(lhostname, '.')) != 0) *cp = '\0';
-
- if (r = krb_rd_encpwd_req(&auth, KRB_SERVICE_NAME, lhostname, 0, &adat, NULL, challenge, r_user, r_passwd)) {
- Data(ap, KRB4_ENCPWD_REJECT, (void *)"Auth failed", -1);
- auth_finished(ap, AUTH_REJECT);
- return;
- }
- auth_encrypt_userpwd(r_passwd);
- if (passwdok(UserNameRequested, UserPassword) == 0) {
- /*
- * illegal username and password
- */
- Data(ap, KRB4_ENCPWD_REJECT, (void *)"Illegal password", -1);
- auth_finished(ap, AUTH_REJECT);
- return;
- }
-
- memmove((void *)session_key, (void *)adat.session, sizeof(Block));
- Data(ap, KRB4_ENCPWD_ACCEPT, (void *)0, 0);
- auth_finished(ap, AUTH_USER);
- break;
-
- case KRB4_ENCPWD_CHALLENGE:
- /*
- * Take the received random challenge text and save
- * for future authentication.
- */
- memmove((void *)challenge, (void *)data, sizeof(Block));
- break;
-
-
- case KRB4_ENCPWD_ACK:
- /*
- * Receive ack, if mutual then send random challenge
- */
-
- /*
- * If we are doing mutual authentication, get set up to send
- * the challenge, and verify it when the response comes back.
- */
-
- if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) {
- register int i;
-
- time(&now);
- sprintf(challenge, "%x", now);
- Data(ap, KRB4_ENCPWD_CHALLENGE, (void *)challenge, strlen(challenge));
- }
- break;
-
- default:
- Data(ap, KRB4_ENCPWD_REJECT, 0, 0);
- break;
- }
-}
-
-
- void
-krb4encpwd_reply(ap, data, cnt)
- Authenticator *ap;
- unsigned char *data;
- int cnt;
-{
- Session_Key skey;
- KTEXT_ST krb_token;
- Block enckey;
- CREDENTIALS cred;
- int r;
- char randchal[REALM_SZ], instance[ANAME_SZ], *cp;
- char hostname[80], *realm;
-
- if (cnt-- < 1)
- return;
- switch (*data++) {
- case KRB4_ENCPWD_REJECT:
- if (cnt > 0) {
- printf("[ KRB4_ENCPWD refuses authentication because %.*s ]\r\n",
- cnt, data);
- } else
- printf("[ KRB4_ENCPWD refuses authentication ]\r\n");
- auth_send_retry();
- return;
- case KRB4_ENCPWD_ACCEPT:
- printf("[ KRB4_ENCPWD accepts you ]\n");
- auth_finished(ap, AUTH_USER);
- return;
- case KRB4_ENCPWD_CHALLENGE:
- /*
- * Verify that the response to the challenge is correct.
- */
-
- gethostname(hostname, sizeof(hostname));
- realm = krb_realmofhost(hostname);
- memmove((void *)challenge, (void *)data, cnt);
- memset(user_passwd, 0, sizeof(user_passwd));
- local_des_read_pw_string(user_passwd, sizeof(user_passwd)-1, "Password: ", 0);
- UserPassword = user_passwd;
- Challenge = challenge;
- strcpy(instance, RemoteHostName);
- if ((cp = strchr(instance, '.')) != 0) *cp = '\0';
-
- if (r = krb_mk_encpwd_req(&krb_token, KRB_SERVICE_NAME, instance, realm, Challenge, UserNameRequested, user_passwd)) {
- krb_token.length = 0;
- }
-
- if (!Data(ap, KRB4_ENCPWD_AUTH, (void *)krb_token.dat, krb_token.length)) {
- return;
- }
-
- break;
-
- default:
- return;
- }
-}
-
- int
-krb4encpwd_status(ap, name, level)
- Authenticator *ap;
- char *name;
- int level;
-{
-
- if (level < AUTH_USER)
- return(level);
-
- if (UserNameRequested && passwdok(UserNameRequested, UserPassword)) {
- strcpy(name, UserNameRequested);
- return(AUTH_VALID);
- } else {
- return(AUTH_USER);
- }
-}
-
-#define BUMP(buf, len) while (*(buf)) {++(buf), --(len);}
-#define ADDC(buf, len, c) if ((len) > 0) {*(buf)++ = (c); --(len);}
-
- void
-krb4encpwd_printsub(data, cnt, buf, buflen)
- unsigned char *data, *buf;
- int cnt, buflen;
-{
- char lbuf[32];
- register int i;
-
- buf[buflen-1] = '\0'; /* make sure its NULL terminated */
- buflen -= 1;
-
- switch(data[3]) {
- case KRB4_ENCPWD_REJECT: /* Rejected (reason might follow) */
- strncpy((char *)buf, " REJECT ", buflen);
- goto common;
-
- case KRB4_ENCPWD_ACCEPT: /* Accepted (name might follow) */
- strncpy((char *)buf, " ACCEPT ", buflen);
- common:
- BUMP(buf, buflen);
- if (cnt <= 4)
- break;
- ADDC(buf, buflen, '"');
- for (i = 4; i < cnt; i++)
- ADDC(buf, buflen, data[i]);
- ADDC(buf, buflen, '"');
- ADDC(buf, buflen, '\0');
- break;
-
- case KRB4_ENCPWD_AUTH: /* Authentication data follows */
- strncpy((char *)buf, " AUTH", buflen);
- goto common2;
-
- case KRB4_ENCPWD_CHALLENGE:
- strncpy((char *)buf, " CHALLENGE", buflen);
- goto common2;
-
- case KRB4_ENCPWD_ACK:
- strncpy((char *)buf, " ACK", buflen);
- goto common2;
-
- default:
- sprintf(lbuf, " %d (unknown)", data[3]);
- strncpy((char *)buf, lbuf, buflen);
- common2:
- BUMP(buf, buflen);
- for (i = 4; i < cnt; i++) {
- sprintf(lbuf, " %d", data[i]);
- strncpy((char *)buf, lbuf, buflen);
- BUMP(buf, buflen);
- }
- break;
- }
-}
-
-int passwdok(name, passwd)
-char *name, *passwd;
-{
- char *crypt();
- char *salt, *p;
- struct passwd *pwd;
- int passwdok_status = 0;
-
- if (pwd = getpwnam(name))
- salt = pwd->pw_passwd;
- else salt = "xx";
-
- p = crypt(passwd, salt);
-
- if (pwd && !strcmp(p, pwd->pw_passwd)) {
- passwdok_status = 1;
- } else passwdok_status = 0;
- return(passwdok_status);
-}
-
-#endif
diff --git a/contrib/telnet/libtelnet/misc-proto.h b/contrib/telnet/libtelnet/misc-proto.h
deleted file mode 100644
index aea753c3ff93..000000000000
--- a/contrib/telnet/libtelnet/misc-proto.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)misc-proto.h 8.1 (Berkeley) 6/4/93
- * $FreeBSD$
- */
-
-/*
- * Copyright (C) 1990 by the Massachusetts Institute of Technology
- *
- * Export of this software from the United States of America is assumed
- * to require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifndef __MISC_PROTO__
-#define __MISC_PROTO__
-
-void auth_encrypt_init(char *, char *, const char *, int);
-void auth_encrypt_connect(int);
-void printd(const unsigned char *, int);
-
-int isprefix(char *, const char *);
-char **genget(char *, char **, int);
-int Ambiguous(char **);
-
-int getent(char *, const char *);
-char *Getstr(const char *, char **);
-
-/*
- * These functions are imported from the application
- */
-int net_write(unsigned char *, int);
-void net_encrypt(void);
-int telnet_spin(void);
-char *telnet_getenv(char *);
-char *telnet_gets(const char *, char *, int, int);
-void printsub(char, unsigned char *, int);
-#endif
diff --git a/contrib/telnet/libtelnet/misc.c b/contrib/telnet/libtelnet/misc.c
deleted file mode 100644
index 97299ad53b77..000000000000
--- a/contrib/telnet/libtelnet/misc.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-
-__FBSDID("$FreeBSD$");
-
-#ifndef lint
-#if 0
-static const char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/4/93";
-#endif
-#endif /* not lint */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "misc.h"
-#ifdef AUTHENTICATION
-#include "auth.h"
-#endif
-#ifdef ENCRYPTION
-#include "encrypt.h"
-#endif /* ENCRYPTION */
-
-char *RemoteHostName;
-char *LocalHostName;
-char *UserNameRequested = 0;
-int ConnectedCount = 0;
-
-#ifndef AUTHENTICATION
-#define undef1 __unused
-#else
-#define undef1
-#endif
-
-void
-auth_encrypt_init(char *local, char *remote, const char *name undef1, int server undef1)
-{
- RemoteHostName = remote;
- LocalHostName = local;
-#ifdef AUTHENTICATION
- auth_init(name, server);
-#endif
-#ifdef ENCRYPTION
- encrypt_init(name, server);
-#endif /* ENCRYPTION */
- if (UserNameRequested) {
- free(UserNameRequested);
- UserNameRequested = 0;
- }
-}
-
-#ifdef ENCRYPTION
-void
-auth_encrypt_user(char *name)
-{
- if (UserNameRequested)
- free(UserNameRequested);
- UserNameRequested = name ? strdup(name) : 0;
-}
-
-/* ARGSUSED */
-void
-auth_encrypt_connect(int cnt __unused)
-{
-}
-#endif /* ENCRYPTION */
-
-void
-printd(const unsigned char *data, int cnt)
-{
- if (cnt > 16)
- cnt = 16;
- while (cnt-- > 0) {
- printf(" %02x", *data);
- ++data;
- }
-}
diff --git a/contrib/telnet/libtelnet/misc.h b/contrib/telnet/libtelnet/misc.h
deleted file mode 100644
index 41ffa7f67aa7..000000000000
--- a/contrib/telnet/libtelnet/misc.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)misc.h 8.1 (Berkeley) 6/4/93
- */
-
-extern char *UserNameRequested;
-extern char *LocalHostName;
-extern char *RemoteHostName;
-extern int ConnectedCount;
-extern int ReservedPort;
-
-#include "misc-proto.h"
diff --git a/contrib/telnet/libtelnet/pk.c b/contrib/telnet/libtelnet/pk.c
deleted file mode 100644
index 044e9b9e8ffa..000000000000
--- a/contrib/telnet/libtelnet/pk.c
+++ /dev/null
@@ -1,265 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * Dave Safford. 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$");
-
-/* public key routines */
-/* functions:
- genkeys(char *public, char *secret)
- common_key(char *secret, char *public, desData *deskey)
- pk_encode(char *in, *out, DesData *deskey);
- pk_decode(char *in, *out, DesData *deskey);
- where
- char public[HEXKEYBYTES + 1];
- char secret[HEXKEYBYTES + 1];
- */
-
-#include <sys/time.h>
-#include <openssl/des.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "mp.h"
-#include "pk.h"
-
-static void adjust(char keyout[HEXKEYBYTES+1], char *keyin);
-
-/*
- * Choose top 128 bits of the common key to use as our idea key.
- */
-static void
-extractideakey(MINT *ck, IdeaData *ideakey)
-{
- MINT *a;
- MINT *z;
- short r;
- int i;
- short base = (1 << 8);
- char *k;
-
- z = itom(0);
- a = itom(0);
- madd(ck, z, a);
- for (i = 0; i < ((KEYSIZE - 128) / 8); i++) {
- sdiv(a, base, a, &r);
- }
- k = (char *)ideakey;
- for (i = 0; i < 16; i++) {
- sdiv(a, base, a, &r);
- *k++ = r;
- }
- mfree(z);
- mfree(a);
-}
-
-/*
- * Choose middle 64 bits of the common key to use as our des key, possibly
- * overwriting the lower order bits by setting parity.
- */
-static void
-extractdeskey(MINT *ck, DesData *deskey)
-{
- MINT *a;
- MINT *z;
- short r;
- int i;
- short base = (1 << 8);
- char *k;
-
- z = itom(0);
- a = itom(0);
- madd(ck, z, a);
- for (i = 0; i < ((KEYSIZE - 64) / 2) / 8; i++) {
- sdiv(a, base, a, &r);
- }
- k = (char *)deskey;
- for (i = 0; i < 8; i++) {
- sdiv(a, base, a, &r);
- *k++ = r;
- }
- mfree(z);
- mfree(a);
-}
-
-/*
- * get common key from my secret key and his public key
- */
-void
-common_key(char *xsecret, char *xpublic, IdeaData *ideakey, DesData *deskey)
-{
- MINT *public;
- MINT *secret;
- MINT *common;
- MINT *modulus = xtom(HEXMODULUS);
-
- public = xtom(xpublic);
- secret = xtom(xsecret);
- common = itom(0);
- pow(public, secret, modulus, common);
- extractdeskey(common, deskey);
- extractideakey(common, ideakey);
- des_set_odd_parity(deskey);
- mfree(common);
- mfree(secret);
- mfree(public);
- mfree(modulus);
-}
-
-/*
- * Generate a seed
- */
-static void
-getseed(char *seed, int seedsize)
-{
- int i;
-
- srandomdev();
- for (i = 0; i < seedsize; i++) {
- seed[i] = random() & 0xff;
- }
-}
-
-/*
- * Generate a random public/secret key pair
- */
-void
-genkeys(char *public, char *secret)
-{
- size_t i;
-
-# define BASEBITS (8*sizeof(short) - 1)
-# define BASE (1 << BASEBITS)
-
- MINT *pk = itom(0);
- MINT *sk = itom(0);
- MINT *tmp;
- MINT *base = itom(BASE);
- MINT *root = itom(PROOT);
- MINT *modulus = xtom(HEXMODULUS);
- short r;
- unsigned short seed[KEYSIZE/BASEBITS + 1];
- char *xkey;
-
- getseed((char *)seed, sizeof(seed));
- for (i = 0; i < KEYSIZE/BASEBITS + 1; i++) {
- r = seed[i] % BASE;
- tmp = itom(r);
- mult(sk, base, sk);
- madd(sk, tmp, sk);
- mfree(tmp);
- }
- tmp = itom(0);
- mdiv(sk, modulus, tmp, sk);
- mfree(tmp);
- pow(root, sk, modulus, pk);
- xkey = mtox(sk);
- adjust(secret, xkey);
- xkey = mtox(pk);
- adjust(public, xkey);
- mfree(sk);
- mfree(base);
- mfree(pk);
- mfree(root);
- mfree(modulus);
-}
-
-/*
- * Adjust the input key so that it is 0-filled on the left
- */
-static void
-adjust(char keyout[HEXKEYBYTES+1], char *keyin)
-{
- char *p;
- char *s;
-
- for (p = keyin; *p; p++)
- ;
- for (s = keyout + HEXKEYBYTES; p >= keyin; p--, s--) {
- *s = *p;
- }
- while (s >= keyout) {
- *s-- = '0';
- }
-}
-
-static char hextab[17] = "0123456789ABCDEF";
-
-/* given a DES key, cbc encrypt and translate input to terminated hex */
-void
-pk_encode(char *in, char *out, DesData *key)
-{
- char buf[256];
- DesData i;
- des_key_schedule k;
- int l,op,deslen;
-
- memset(&i,0,sizeof(i));
- memset(buf,0,sizeof(buf));
- deslen = ((strlen(in) + 7)/8)*8;
- des_key_sched(key, k);
- des_cbc_encrypt(in,buf,deslen, k,&i,DES_ENCRYPT);
- for (l=0,op=0;l<deslen;l++) {
- out[op++] = hextab[(buf[l] & 0xf0) >> 4];
- out[op++] = hextab[(buf[l] & 0x0f)];
- }
- out[op] = '\0';
-}
-
-/* given a DES key, translate input from hex and decrypt */
-void
-pk_decode(char *in, char *out, DesData *key)
-{
- char buf[256];
- DesData i;
- des_key_schedule k;
- int n1,n2,op;
- size_t l;
-
- memset(&i,0,sizeof(i));
- memset(buf,0,sizeof(buf));
- for (l=0,op=0;l<strlen(in)/2;l++,op+=2) {
- if (in[op] > '9')
- n1 = in[op] - 'A' + 10;
- else
- n1 = in[op] - '0';
- if (in[op+1] > '9')
- n2 = in[op+1] - 'A' + 10;
- else
- n2 = in[op+1] - '0';
- buf[l] = n1*16 +n2;
- }
- des_key_sched(key, k);
- des_cbc_encrypt(buf,out,strlen(in)/2, k,&i,DES_DECRYPT);
- out[strlen(in)/2] = '\0';
-}
diff --git a/contrib/telnet/libtelnet/pk.h b/contrib/telnet/libtelnet/pk.h
deleted file mode 100644
index 555d8ebdeb78..000000000000
--- a/contrib/telnet/libtelnet/pk.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * Dave Safford. 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.
- *
- * $FreeBSD$
- */
-
-/* header for the des routines that we will use */
-
-typedef unsigned char byte, DesData[ 8], IdeaData[16];
-#define DesKeys des_key_schedule
-
-#define DES_DECRYPT 0
-#define DES_ENCRYPT 1
-
-/* public key routines */
-/* functions:
- genkeys(char *public, char *secret)
- common_key(char *secret, char *public, desData *deskey)
- where
- char public[HEXKEYBYTES + 1];
- char secret[HEXKEYBYTES + 1];
- */
-
-#define HEXMODULUS "d4a0ba0250b6fd2ec626e7efd637df76c716e22d0944b88b"
-#define HEXKEYBYTES 48
-#define KEYSIZE 192
-#define KEYBYTES 24
-#define PROOT 3
-
-extern void genkeys(char *public, char *secret);
-extern void common_key(char *secret, char *public, IdeaData *common,
- DesData *deskey);
-extern void pk_encode(char *in, char *out, DesData *deskey);
-extern void pk_decode(char *in, char *out, DesData *deskey);
diff --git a/contrib/telnet/libtelnet/read_password.c b/contrib/telnet/libtelnet/read_password.c
deleted file mode 100644
index badf21417dcc..000000000000
--- a/contrib/telnet/libtelnet/read_password.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-
-__FBSDID("$FreeBSD$");
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)read_password.c 8.3 (Berkeley) 5/30/95";
-#endif
-#endif /* not lint */
-
-/*
- * $Source: /mit/kerberos/src/lib/des/RCS/read_password.c,v $
- * $Author: jon $
- *
- * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
- * of Technology.
- *
- * For copying and distribution information, please see the file
- * <mit-copyright.h>.
- *
- * This routine prints the supplied string to standard
- * output as a prompt, and reads a password string without
- * echoing.
- */
-
-#if defined(RSA_ENCPWD) || defined(KRB4_ENCPWD)
-
-#include <stdio.h>
-#include <strings.h>
-#include <sys/ioctl.h>
-#include <signal.h>
-#include <setjmp.h>
-
-static jmp_buf env;
-
-/*** Routines ****************************************************** */
-/*
- * This version just returns the string, doesn't map to key.
- *
- * Returns 0 on success, non-zero on failure.
- */
-
-int
-local_des_read_pw_string(s,max,prompt,verify)
- char *s;
- int max;
- char *prompt;
- int verify;
-{
- int ok = 0;
- char *ptr;
-
- jmp_buf old_env;
- struct sgttyb tty_state;
- char key_string[BUFSIZ];
-
- if (max > BUFSIZ) {
- return -1;
- }
-
- /* XXX assume jmp_buf is typedef'ed to an array */
- memmove((char *)env, (char *)old_env, sizeof(env));
- if (setjmp(env))
- goto lose;
-
- /* save terminal state*/
- if (ioctl(0,TIOCGETP,(char *)&tty_state) == -1)
- return -1;
-/*
- push_signals();
-*/
- /* Turn off echo */
- tty_state.sg_flags &= ~ECHO;
- if (ioctl(0,TIOCSETP,(char *)&tty_state) == -1)
- return -1;
- while (!ok) {
- (void) printf("%s", prompt);
- (void) fflush(stdout);
- while (!fgets(s, max, stdin));
-
- if ((ptr = strchr(s, '\n')))
- *ptr = '\0';
- if (verify) {
- printf("\nVerifying, please re-enter %s",prompt);
- (void) fflush(stdout);
- if (!fgets(key_string, sizeof(key_string), stdin)) {
- clearerr(stdin);
- continue;
- }
- if ((ptr = strchr(key_string, '\n')))
- *ptr = '\0';
- if (strcmp(s,key_string)) {
- printf("\n\07\07Mismatch - try again\n");
- (void) fflush(stdout);
- continue;
- }
- }
- ok = 1;
- }
-
-lose:
- if (!ok)
- memset(s, 0, max);
- printf("\n");
- /* turn echo back on */
- tty_state.sg_flags |= ECHO;
- if (ioctl(0,TIOCSETP,(char *)&tty_state))
- ok = 0;
-/*
- pop_signals();
-*/
- memmove((char *)old_env, (char *)env, sizeof(env));
- if (verify)
- memset(key_string, 0, sizeof (key_string));
- s[max-1] = 0; /* force termination */
- return !ok; /* return nonzero if not okay */
-}
-#endif /* defined(RSA_ENCPWD) || defined(KRB4_ENCPWD) */
diff --git a/contrib/telnet/libtelnet/rsaencpwd.c b/contrib/telnet/libtelnet/rsaencpwd.c
deleted file mode 100644
index fba0c6b61735..000000000000
--- a/contrib/telnet/libtelnet/rsaencpwd.c
+++ /dev/null
@@ -1,475 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-
-__FBSDID("$FreeBSD$");
-
-#ifndef lint
-static char sccsid[] = "@(#)rsaencpwd.c 8.3 (Berkeley) 5/30/95";
-#endif /* not lint */
-
-
-#ifdef RSA_ENCPWD
-/*
- * COPYRIGHT (C) 1990 DIGITAL EQUIPMENT CORPORATION
- * ALL RIGHTS RESERVED
- *
- * "Digital Equipment Corporation authorizes the reproduction,
- * distribution and modification of this software subject to the following
- * restrictions:
- *
- * 1. Any partial or whole copy of this software, or any modification
- * thereof, must include this copyright notice in its entirety.
- *
- * 2. This software is supplied "as is" with no warranty of any kind,
- * expressed or implied, for any purpose, including any warranty of fitness
- * or merchantibility. DIGITAL assumes no responsibility for the use or
- * reliability of this software, nor promises to provide any form of
- * support for it on any basis.
- *
- * 3. Distribution of this software is authorized only if no profit or
- * remuneration of any kind is received in exchange for such distribution.
- *
- * 4. This software produces public key authentication certificates
- * bearing an expiration date established by DIGITAL and RSA Data
- * Security, Inc. It may cease to generate certificates after the expiration
- * date. Any modification of this software that changes or defeats
- * the expiration date or its effect is unauthorized.
- *
- * 5. Software that will renew or extend the expiration date of
- * authentication certificates produced by this software may be obtained
- * from RSA Data Security, Inc., 10 Twin Dolphin Drive, Redwood City, CA
- * 94065, (415)595-8782, or from DIGITAL"
- *
- */
-
-#include <sys/types.h>
-#include <arpa/telnet.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "encrypt.h"
-#include "auth.h"
-#include "misc.h"
-#include "cdc.h"
-
-extern auth_debug_mode;
-
-static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
- AUTHTYPE_RSA_ENCPWD, };
-static unsigned char str_name[1024] = { IAC, SB, TELOPT_AUTHENTICATION,
- TELQUAL_NAME, };
-
-#define RSA_ENCPWD_AUTH 0 /* Authentication data follows */
-#define RSA_ENCPWD_REJECT 1 /* Rejected (reason might follow) */
-#define RSA_ENCPWD_ACCEPT 2 /* Accepted */
-#define RSA_ENCPWD_CHALLENGEKEY 3 /* Challenge and public key */
-
-#define NAME_SZ 40
-#define CHAL_SZ 20
-#define PWD_SZ 40
-
-static KTEXT_ST auth;
-static char name[NAME_SZ];
-static char user_passwd[PWD_SZ];
-static char key_file[2*NAME_SZ];
-static char lhostname[NAME_SZ];
-static char challenge[CHAL_SZ];
-static int challenge_len;
-
- static int
-Data(ap, type, d, c)
- Authenticator *ap;
- int type;
- void *d;
- int c;
-{
- unsigned char *p = str_data + 4;
- unsigned char *cd = (unsigned char *)d;
-
- if (c == -1)
- c = strlen((char *)cd);
-
- if (0) {
- printf("%s:%d: [%d] (%d)",
- str_data[3] == TELQUAL_IS ? ">>>IS" : ">>>REPLY",
- str_data[3],
- type, c);
- printd(d, c);
- printf("\r\n");
- }
- *p++ = ap->type;
- *p++ = ap->way;
- if (type != NULL) *p++ = type;
- while (c-- > 0) {
- if ((*p++ = *cd++) == IAC)
- *p++ = IAC;
- }
- *p++ = IAC;
- *p++ = SE;
- if (str_data[3] == TELQUAL_IS)
- printsub('>', &str_data[2], p - (&str_data[2]));
- return(net_write(str_data, p - str_data));
-}
-
- int
-rsaencpwd_init(ap, server)
- Authenticator *ap;
- int server;
-{
- char *cp;
- FILE *fp;
-
- if (server) {
- str_data[3] = TELQUAL_REPLY;
- memset(key_file, 0, sizeof(key_file));
- gethostname(lhostname, sizeof(lhostname));
- if ((cp = strchr(lhostname, '.')) != 0) *cp = '\0';
- strcpy(key_file, "/etc/.");
- strcat(key_file, lhostname);
- strcat(key_file, "_privkey");
- if ((fp=fopen(key_file, "r"))==NULL) return(0);
- fclose(fp);
- } else {
- str_data[3] = TELQUAL_IS;
- }
- return(1);
-}
-
- int
-rsaencpwd_send(ap)
- Authenticator *ap;
-{
-
- printf("[ Trying RSAENCPWD ... ]\n");
- if (!UserNameRequested) {
- return(0);
- }
- if (!auth_sendname(UserNameRequested, strlen(UserNameRequested))) {
- return(0);
- }
- if (!Data(ap, NULL, (void *)NULL, 0)) {
- return(0);
- }
-
-
- return(1);
-}
-
- void
-rsaencpwd_is(ap, data, cnt)
- Authenticator *ap;
- unsigned char *data;
- int cnt;
-{
- Session_Key skey;
- Block datablock;
- char r_passwd[PWD_SZ], r_user[NAME_SZ];
- char *cp, key[160];
- char chalkey[160], *ptr;
- FILE *fp;
- int r, i, j, chalkey_len, len;
- time_t now;
-
- cnt--;
- switch (*data++) {
- case RSA_ENCPWD_AUTH:
- memmove((void *)auth.dat, (void *)data, auth.length = cnt);
-
- if ((fp=fopen(key_file, "r"))==NULL) {
- Data(ap, RSA_ENCPWD_REJECT, (void *)"Auth failed", -1);
- auth_finished(ap, AUTH_REJECT);
- return;
- }
- /*
- * get privkey
- */
- fscanf(fp, "%x;", &len);
- for (i=0;i<len;i++) {
- j = getc(fp); key[i]=j;
- }
- fclose(fp);
-
- r = accept_rsa_encpwd(&auth, key, challenge,
- challenge_len, r_passwd);
- if (r < 0) {
- Data(ap, RSA_ENCPWD_REJECT, (void *)"Auth failed", -1);
- auth_finished(ap, AUTH_REJECT);
- return;
- }
- auth_encrypt_userpwd(r_passwd);
- if (rsaencpwd_passwdok(UserNameRequested, UserPassword) == 0) {
- /*
- * illegal username and password
- */
- Data(ap, RSA_ENCPWD_REJECT, (void *)"Illegal password", -1);
- auth_finished(ap, AUTH_REJECT);
- return;
- }
-
- Data(ap, RSA_ENCPWD_ACCEPT, (void *)0, 0);
- auth_finished(ap, AUTH_USER);
- break;
-
-
- case IAC:
-
- /*
- * If we are doing mutual authentication, get set up to send
- * the challenge, and verify it when the response comes back.
- */
- if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_ONE_WAY) {
- register int i;
-
-
- time(&now);
- if ((now % 2) == 0) {
- sprintf(challenge, "%x", now);
- challenge_len = strlen(challenge);
- } else {
- strcpy(challenge, "randchal");
- challenge_len = 8;
- }
-
- if ((fp=fopen(key_file, "r"))==NULL) {
- Data(ap, RSA_ENCPWD_REJECT, (void *)"Auth failed", -1);
- auth_finished(ap, AUTH_REJECT);
- return;
- }
- /*
- * skip privkey
- */
- fscanf(fp, "%x;", &len);
- for (i=0;i<len;i++) {
- j = getc(fp);
- }
- /*
- * get pubkey
- */
- fscanf(fp, "%x;", &len);
- for (i=0;i<len;i++) {
- j = getc(fp); key[i]=j;
- }
- fclose(fp);
- chalkey[0] = 0x30;
- ptr = (char *) &chalkey[1];
- chalkey_len = 1+NumEncodeLengthOctets(i)+i+1+NumEncodeLengthOctets(challenge_len)+challenge_len;
- EncodeLength(ptr, chalkey_len);
- ptr +=NumEncodeLengthOctets(chalkey_len);
- *ptr++ = 0x04; /* OCTET STRING */
- *ptr++ = challenge_len;
- memmove(ptr, challenge, challenge_len);
- ptr += challenge_len;
- *ptr++ = 0x04; /* OCTET STRING */
- EncodeLength(ptr, i);
- ptr += NumEncodeLengthOctets(i);
- memmove(ptr, key, i);
- chalkey_len = 1+NumEncodeLengthOctets(chalkey_len)+chalkey_len;
- Data(ap, RSA_ENCPWD_CHALLENGEKEY, (void *)chalkey, chalkey_len);
- }
- break;
-
- default:
- Data(ap, RSA_ENCPWD_REJECT, 0, 0);
- break;
- }
-}
-
-
- void
-rsaencpwd_reply(ap, data, cnt)
- Authenticator *ap;
- unsigned char *data;
- int cnt;
-{
- Session_Key skey;
- KTEXT_ST token;
- Block enckey;
- int r, pubkey_len;
- char randchal[CHAL_SZ], *cp;
- char chalkey[160], pubkey[128], *ptr;
-
- if (cnt-- < 1)
- return;
- switch (*data++) {
- case RSA_ENCPWD_REJECT:
- if (cnt > 0) {
- printf("[ RSA_ENCPWD refuses authentication because %.*s ]\r\n",
- cnt, data);
- } else
- printf("[ RSA_ENCPWD refuses authentication ]\r\n");
- auth_send_retry();
- return;
- case RSA_ENCPWD_ACCEPT:
- printf("[ RSA_ENCPWD accepts you ]\n");
- auth_finished(ap, AUTH_USER);
- return;
- case RSA_ENCPWD_CHALLENGEKEY:
- /*
- * Verify that the response to the challenge is correct.
- */
-
- memmove((void *)chalkey, (void *)data, cnt);
- ptr = (char *) &chalkey[0];
- ptr += DecodeHeaderLength(chalkey);
- if (*ptr != 0x04) {
- return;
- }
- *ptr++;
- challenge_len = DecodeValueLength(ptr);
- ptr += NumEncodeLengthOctets(challenge_len);
- memmove(challenge, ptr, challenge_len);
- ptr += challenge_len;
- if (*ptr != 0x04) {
- return;
- }
- *ptr++;
- pubkey_len = DecodeValueLength(ptr);
- ptr += NumEncodeLengthOctets(pubkey_len);
- memmove(pubkey, ptr, pubkey_len);
- memset(user_passwd, 0, sizeof(user_passwd));
- local_des_read_pw_string(user_passwd, sizeof(user_passwd)-1, "Password: ", 0);
- UserPassword = user_passwd;
- Challenge = challenge;
- r = init_rsa_encpwd(&token, user_passwd, challenge, challenge_len, pubkey);
- if (r < 0) {
- token.length = 1;
- }
-
- if (!Data(ap, RSA_ENCPWD_AUTH, (void *)token.dat, token.length)) {
- return;
- }
-
- break;
-
- default:
- return;
- }
-}
-
- int
-rsaencpwd_status(ap, name, level)
- Authenticator *ap;
- char *name;
- int level;
-{
-
- if (level < AUTH_USER)
- return(level);
-
- if (UserNameRequested && rsaencpwd_passwdok(UserNameRequested, UserPassword)) {
- strcpy(name, UserNameRequested);
- return(AUTH_VALID);
- } else {
- return(AUTH_USER);
- }
-}
-
-#define BUMP(buf, len) while (*(buf)) {++(buf), --(len);}
-#define ADDC(buf, len, c) if ((len) > 0) {*(buf)++ = (c); --(len);}
-
- void
-rsaencpwd_printsub(data, cnt, buf, buflen)
- unsigned char *data, *buf;
- int cnt, buflen;
-{
- char lbuf[32];
- register int i;
-
- buf[buflen-1] = '\0'; /* make sure its NULL terminated */
- buflen -= 1;
-
- switch(data[3]) {
- case RSA_ENCPWD_REJECT: /* Rejected (reason might follow) */
- strncpy((char *)buf, " REJECT ", buflen);
- goto common;
-
- case RSA_ENCPWD_ACCEPT: /* Accepted (name might follow) */
- strncpy((char *)buf, " ACCEPT ", buflen);
- common:
- BUMP(buf, buflen);
- if (cnt <= 4)
- break;
- ADDC(buf, buflen, '"');
- for (i = 4; i < cnt; i++)
- ADDC(buf, buflen, data[i]);
- ADDC(buf, buflen, '"');
- ADDC(buf, buflen, '\0');
- break;
-
- case RSA_ENCPWD_AUTH: /* Authentication data follows */
- strncpy((char *)buf, " AUTH", buflen);
- goto common2;
-
- case RSA_ENCPWD_CHALLENGEKEY:
- strncpy((char *)buf, " CHALLENGEKEY", buflen);
- goto common2;
-
- default:
- sprintf(lbuf, " %d (unknown)", data[3]);
- strncpy((char *)buf, lbuf, buflen);
- common2:
- BUMP(buf, buflen);
- for (i = 4; i < cnt; i++) {
- sprintf(lbuf, " %d", data[i]);
- strncpy((char *)buf, lbuf, buflen);
- BUMP(buf, buflen);
- }
- break;
- }
-}
-
-int rsaencpwd_passwdok(name, passwd)
-char *name, *passwd;
-{
- char *crypt();
- char *salt, *p;
- struct passwd *pwd;
- int passwdok_status = 0;
-
- if (pwd = getpwnam(name))
- salt = pwd->pw_passwd;
- else salt = "xx";
-
- p = crypt(passwd, salt);
-
- if (pwd && !strcmp(p, pwd->pw_passwd)) {
- passwdok_status = 1;
- } else passwdok_status = 0;
- return(passwdok_status);
-}
-
-#endif
diff --git a/contrib/telnet/libtelnet/sra.c b/contrib/telnet/libtelnet/sra.c
deleted file mode 100644
index 194048532b4e..000000000000
--- a/contrib/telnet/libtelnet/sra.c
+++ /dev/null
@@ -1,602 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * Dave Safford. 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$");
-
-#ifdef SRA
-#ifdef ENCRYPTION
-#include <sys/types.h>
-#include <arpa/telnet.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <ttyent.h>
-
-#ifndef NOPAM
-#include <security/pam_appl.h>
-#else
-#include <unistd.h>
-#endif
-
-#include "auth.h"
-#include "misc.h"
-#include "encrypt.h"
-#include "pk.h"
-
-char pka[HEXKEYBYTES+1], ska[HEXKEYBYTES+1], pkb[HEXKEYBYTES+1];
-char *user, *pass, *xuser, *xpass;
-DesData ck;
-IdeaData ik;
-
-extern int auth_debug_mode;
-extern char line[];
-
-static int sra_valid = 0;
-static int passwd_sent = 0;
-
-static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
- AUTHTYPE_SRA, };
-
-#define SRA_KEY 0
-#define SRA_USER 1
-#define SRA_CONTINUE 2
-#define SRA_PASS 3
-#define SRA_ACCEPT 4
-#define SRA_REJECT 5
-
-static int check_user(char *, char *);
-
-/* support routine to send out authentication message */
-static int
-Data(Authenticator *ap, int type, void *d, int c)
-{
- unsigned char *p = str_data + 4;
- unsigned char *cd = (unsigned char *)d;
-
- if (c == -1)
- c = strlen((char *)cd);
-
- if (auth_debug_mode) {
- printf("%s:%d: [%d] (%d)",
- str_data[3] == TELQUAL_IS ? ">>>IS" : ">>>REPLY",
- str_data[3],
- type, c);
- printd(d, c);
- printf("\r\n");
- }
- *p++ = ap->type;
- *p++ = ap->way;
- *p++ = type;
- while (c-- > 0) {
- if ((*p++ = *cd++) == IAC)
- *p++ = IAC;
- }
- *p++ = IAC;
- *p++ = SE;
- if (str_data[3] == TELQUAL_IS)
- printsub('>', &str_data[2], p - (&str_data[2]));
- return(net_write(str_data, p - str_data));
-}
-
-int
-sra_init(Authenticator *ap __unused, int server)
-{
- if (server)
- str_data[3] = TELQUAL_REPLY;
- else
- str_data[3] = TELQUAL_IS;
-
- user = (char *)malloc(256);
- xuser = (char *)malloc(513);
- pass = (char *)malloc(256);
- xpass = (char *)malloc(513);
-
- if (user == NULL || xuser == NULL || pass == NULL || xpass ==
- NULL)
- return 0; /* malloc failed */
-
- passwd_sent = 0;
-
- genkeys(pka,ska);
- return(1);
-}
-
-/* client received a go-ahead for sra */
-int
-sra_send(Authenticator *ap)
-{
- /* send PKA */
-
- if (auth_debug_mode)
- printf("Sent PKA to server.\r\n" );
- printf("Trying SRA secure login:\r\n");
- if (!Data(ap, SRA_KEY, (void *)pka, HEXKEYBYTES)) {
- if (auth_debug_mode)
- printf("Not enough room for authentication data\r\n");
- return(0);
- }
-
- return(1);
-}
-
-/* server received an IS -- could be SRA KEY, USER, or PASS */
-void
-sra_is(Authenticator *ap, unsigned char *data, int cnt)
-{
- int valid;
- Session_Key skey;
-
- if (cnt-- < 1)
- goto bad;
- switch (*data++) {
-
- case SRA_KEY:
- if (cnt < HEXKEYBYTES) {
- Data(ap, SRA_REJECT, (void *)0, 0);
- auth_finished(ap, AUTH_USER);
- if (auth_debug_mode) {
- printf("SRA user rejected for bad PKB\r\n");
- }
- return;
- }
- if (auth_debug_mode)
- printf("Sent pka\r\n");
- if (!Data(ap, SRA_KEY, (void *)pka, HEXKEYBYTES)) {
- if (auth_debug_mode)
- printf("Not enough room\r\n");
- return;
- }
- memcpy(pkb,data,HEXKEYBYTES);
- pkb[HEXKEYBYTES] = '\0';
- common_key(ska,pkb,&ik,&ck);
- return;
-
- case SRA_USER:
- /* decode KAB(u) */
- if (cnt > 512) /* Attempted buffer overflow */
- break;
- memcpy(xuser,data,cnt);
- xuser[cnt] = '\0';
- pk_decode(xuser,user,&ck);
- auth_encrypt_user(user);
- Data(ap, SRA_CONTINUE, (void *)0, 0);
-
- return;
-
- case SRA_PASS:
- if (cnt > 512) /* Attempted buffer overflow */
- break;
- /* decode KAB(P) */
- memcpy(xpass,data,cnt);
- xpass[cnt] = '\0';
- pk_decode(xpass,pass,&ck);
-
- /* check user's password */
- valid = check_user(user,pass);
-
- if(valid) {
- Data(ap, SRA_ACCEPT, (void *)0, 0);
- skey.data = ck;
- skey.type = SK_DES;
- skey.length = 8;
- encrypt_session_key(&skey, 1);
-
- sra_valid = 1;
- auth_finished(ap, AUTH_VALID);
- if (auth_debug_mode) {
- printf("SRA user accepted\r\n");
- }
- }
- else {
- Data(ap, SRA_CONTINUE, (void *)0, 0);
-/*
- Data(ap, SRA_REJECT, (void *)0, 0);
- sra_valid = 0;
- auth_finished(ap, AUTH_REJECT);
-*/
- if (auth_debug_mode) {
- printf("SRA user failed\r\n");
- }
- }
- return;
-
- default:
- if (auth_debug_mode)
- printf("Unknown SRA option %d\r\n", data[-1]);
- }
-bad:
- Data(ap, SRA_REJECT, 0, 0);
- sra_valid = 0;
- auth_finished(ap, AUTH_REJECT);
-}
-
-/* client received REPLY -- could be SRA KEY, CONTINUE, ACCEPT, or REJECT */
-void
-sra_reply(Authenticator *ap, unsigned char *data, int cnt)
-{
- char uprompt[256],tuser[256];
- Session_Key skey;
- size_t i;
-
- if (cnt-- < 1)
- return;
- switch (*data++) {
-
- case SRA_KEY:
- /* calculate common key */
- if (cnt < HEXKEYBYTES) {
- if (auth_debug_mode) {
- printf("SRA user rejected for bad PKB\r\n");
- }
- return;
- }
- memcpy(pkb,data,HEXKEYBYTES);
- pkb[HEXKEYBYTES] = '\0';
-
- common_key(ska,pkb,&ik,&ck);
-
- enc_user:
-
- /* encode user */
- memset(tuser,0,sizeof(tuser));
- sprintf(uprompt,"User (%s): ",UserNameRequested);
- telnet_gets(uprompt,tuser,255,1);
- if (tuser[0] == '\n' || tuser[0] == '\r' )
- strcpy(user,UserNameRequested);
- else {
- /* telnet_gets leaves the newline on */
- for(i=0;i<sizeof(tuser);i++) {
- if (tuser[i] == '\n') {
- tuser[i] = '\0';
- break;
- }
- }
- strcpy(user,tuser);
- }
- pk_encode(user,xuser,&ck);
-
- /* send it off */
- if (auth_debug_mode)
- printf("Sent KAB(U)\r\n");
- if (!Data(ap, SRA_USER, (void *)xuser, strlen(xuser))) {
- if (auth_debug_mode)
- printf("Not enough room\r\n");
- return;
- }
- break;
-
- case SRA_CONTINUE:
- if (passwd_sent) {
- passwd_sent = 0;
- printf("[ SRA login failed ]\r\n");
- goto enc_user;
- }
- /* encode password */
- memset(pass,0,sizeof(pass));
- telnet_gets("Password: ",pass,255,0);
- pk_encode(pass,xpass,&ck);
- /* send it off */
- if (auth_debug_mode)
- printf("Sent KAB(P)\r\n");
- if (!Data(ap, SRA_PASS, (void *)xpass, strlen(xpass))) {
- if (auth_debug_mode)
- printf("Not enough room\r\n");
- return;
- }
- passwd_sent = 1;
- break;
-
- case SRA_REJECT:
- printf("[ SRA refuses authentication ]\r\n");
- printf("Trying plaintext login:\r\n");
- auth_finished(0,AUTH_REJECT);
- return;
-
- case SRA_ACCEPT:
- printf("[ SRA accepts you ]\r\n");
- skey.data = ck;
- skey.type = SK_DES;
- skey.length = 8;
- encrypt_session_key(&skey, 0);
-
- auth_finished(ap, AUTH_VALID);
- return;
- default:
- if (auth_debug_mode)
- printf("Unknown SRA option %d\r\n", data[-1]);
- return;
- }
-}
-
-int
-sra_status(Authenticator *ap __unused, char *name, int level)
-{
- if (level < AUTH_USER)
- return(level);
- if (UserNameRequested && sra_valid) {
- strcpy(name, UserNameRequested);
- return(AUTH_VALID);
- } else
- return(AUTH_USER);
-}
-
-#define BUMP(buf, len) while (*(buf)) {++(buf), --(len);}
-#define ADDC(buf, len, c) if ((len) > 0) {*(buf)++ = (c); --(len);}
-
-void
-sra_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
-{
- char lbuf[32];
- int i;
-
- buf[buflen-1] = '\0'; /* make sure its NULL terminated */
- buflen -= 1;
-
- switch(data[3]) {
-
- case SRA_CONTINUE:
- strncpy((char *)buf, " CONTINUE ", buflen);
- goto common;
-
- case SRA_REJECT: /* Rejected (reason might follow) */
- strncpy((char *)buf, " REJECT ", buflen);
- goto common;
-
- case SRA_ACCEPT: /* Accepted (name might follow) */
- strncpy((char *)buf, " ACCEPT ", buflen);
-
- common:
- BUMP(buf, buflen);
- if (cnt <= 4)
- break;
- ADDC(buf, buflen, '"');
- for (i = 4; i < cnt; i++)
- ADDC(buf, buflen, data[i]);
- ADDC(buf, buflen, '"');
- ADDC(buf, buflen, '\0');
- break;
-
- case SRA_KEY: /* Authentication data follows */
- strncpy((char *)buf, " KEY ", buflen);
- goto common2;
-
- case SRA_USER:
- strncpy((char *)buf, " USER ", buflen);
- goto common2;
-
- case SRA_PASS:
- strncpy((char *)buf, " PASS ", buflen);
- goto common2;
-
- default:
- sprintf(lbuf, " %d (unknown)", data[3]);
- strncpy((char *)buf, lbuf, buflen);
- common2:
- BUMP(buf, buflen);
- for (i = 4; i < cnt; i++) {
- sprintf(lbuf, " %d", data[i]);
- strncpy((char *)buf, lbuf, buflen);
- BUMP(buf, buflen);
- }
- break;
- }
-}
-
-static int
-isroot(const char *usr)
-{
- struct passwd *pwd;
-
- if ((pwd=getpwnam(usr))==NULL)
- return 0;
- return (!pwd->pw_uid);
-}
-
-static int
-rootterm(char *ttyn)
-{
- struct ttyent *t;
-
- return ((t = getttynam(ttyn)) && t->ty_status & TTY_SECURE);
-}
-
-#ifdef NOPAM
-static int
-check_user(char *name, char *cred)
-{
- char *cp;
- char *xpasswd, *salt;
-
- if (isroot(name) && !rootterm(line))
- {
- crypt("AA","*"); /* Waste some time to simulate success */
- return(0);
- }
-
- if (pw = sgetpwnam(name)) {
- if (pw->pw_shell == NULL) {
- pw = (struct passwd *) NULL;
- return(0);
- }
-
- salt = pw->pw_passwd;
- xpasswd = crypt(cred, salt);
- /* The strcmp does not catch null passwords! */
- if (pw == NULL || *pw->pw_passwd == '\0' ||
- strcmp(xpasswd, pw->pw_passwd)) {
- pw = (struct passwd *) NULL;
- return(0);
- }
- return(1);
- }
- return(0);
-}
-#else
-
-/*
- * The following is stolen from ftpd, which stole it from the imap-uw
- * PAM module and login.c. It is needed because we can't really
- * "converse" with the user, having already gone to the trouble of
- * getting their username and password through an encrypted channel.
- */
-
-#define COPY_STRING(s) (s ? strdup(s):NULL)
-
-struct cred_t {
- const char *uname;
- const char *pass;
-};
-typedef struct cred_t cred_t;
-
-static int
-auth_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata)
-{
- int i;
- cred_t *cred = (cred_t *) appdata;
- struct pam_response *reply =
- malloc(sizeof(struct pam_response) * num_msg);
-
- if (reply == NULL)
- return PAM_BUF_ERR;
-
- for (i = 0; i < num_msg; i++) {
- switch (msg[i]->msg_style) {
- case PAM_PROMPT_ECHO_ON: /* assume want user name */
- reply[i].resp_retcode = PAM_SUCCESS;
- reply[i].resp = COPY_STRING(cred->uname);
- /* PAM frees resp. */
- break;
- case PAM_PROMPT_ECHO_OFF: /* assume want password */
- reply[i].resp_retcode = PAM_SUCCESS;
- reply[i].resp = COPY_STRING(cred->pass);
- /* PAM frees resp. */
- break;
- case PAM_TEXT_INFO:
- case PAM_ERROR_MSG:
- reply[i].resp_retcode = PAM_SUCCESS;
- reply[i].resp = NULL;
- break;
- default: /* unknown message style */
- free(reply);
- return PAM_CONV_ERR;
- }
- }
-
- *resp = reply;
- return PAM_SUCCESS;
-}
-
-/*
- * The PAM version as a side effect may put a new username in *name.
- */
-static int
-check_user(char *name, char *cred)
-{
- pam_handle_t *pamh = NULL;
- const void *item;
- int rval;
- int e;
- cred_t auth_cred = { name, cred };
- struct pam_conv conv = { &auth_conv, &auth_cred };
-
- e = pam_start("telnetd", name, &conv, &pamh);
- if (e != PAM_SUCCESS) {
- syslog(LOG_ERR, "pam_start: %s", pam_strerror(pamh, e));
- return 0;
- }
-
-#if 0 /* Where can we find this value? */
- e = pam_set_item(pamh, PAM_RHOST, remotehost);
- if (e != PAM_SUCCESS) {
- syslog(LOG_ERR, "pam_set_item(PAM_RHOST): %s",
- pam_strerror(pamh, e));
- return 0;
- }
-#endif
-
- e = pam_authenticate(pamh, 0);
- switch (e) {
- case PAM_SUCCESS:
- /*
- * With PAM we support the concept of a "template"
- * user. The user enters a login name which is
- * authenticated by PAM, usually via a remote service
- * such as RADIUS or TACACS+. If authentication
- * succeeds, a different but related "template" name
- * is used for setting the credentials, shell, and
- * home directory. The name the user enters need only
- * exist on the remote authentication server, but the
- * template name must be present in the local password
- * database.
- *
- * This is supported by two various mechanisms in the
- * individual modules. However, from the application's
- * point of view, the template user is always passed
- * back as a changed value of the PAM_USER item.
- */
- if ((e = pam_get_item(pamh, PAM_USER, &item)) ==
- PAM_SUCCESS) {
- strcpy(name, item);
- } else
- syslog(LOG_ERR, "Couldn't get PAM_USER: %s",
- pam_strerror(pamh, e));
- if (isroot(name) && !rootterm(line))
- rval = 0;
- else
- rval = 1;
- break;
-
- case PAM_AUTH_ERR:
- case PAM_USER_UNKNOWN:
- case PAM_MAXTRIES:
- rval = 0;
- break;
-
- default:
- syslog(LOG_ERR, "auth_pam: %s", pam_strerror(pamh, e));
- rval = 0;
- break;
- }
-
- if ((e = pam_end(pamh, e)) != PAM_SUCCESS) {
- syslog(LOG_ERR, "pam_end: %s", pam_strerror(pamh, e));
- rval = 0;
- }
- return rval;
-}
-
-#endif
-
-#endif /* ENCRYPTION */
-#endif /* SRA */
diff --git a/contrib/telnet/telnet/authenc.c b/contrib/telnet/telnet/authenc.c
deleted file mode 100644
index 85f389b2e55d..000000000000
--- a/contrib/telnet/telnet/authenc.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)authenc.c 8.1 (Berkeley) 6/6/93";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#ifdef AUTHENTICATION
-#ifdef ENCRYPTION
-#include <sys/types.h>
-#include <arpa/telnet.h>
-#include <pwd.h>
-#include <unistd.h>
-#include <libtelnet/encrypt.h>
-#include <libtelnet/misc.h>
-
-#include "general.h"
-#include "ring.h"
-#include "externs.h"
-#include "defines.h"
-#include "types.h"
-
-int
-net_write(unsigned char *str, int len)
-{
- if (NETROOM() > len) {
- ring_supply_data(&netoring, str, len);
- if (str[0] == IAC && str[1] == SE)
- printsub('>', &str[2], len-2);
- return(len);
- }
- return(0);
-}
-
-void
-net_encrypt(void)
-{
-#ifdef ENCRYPTION
- if (encrypt_output)
- ring_encrypt(&netoring, encrypt_output);
- else
- ring_clearto(&netoring);
-#endif /* ENCRYPTION */
-}
-
-int
-telnet_spin(void)
-{
- return(-1);
-}
-
-char *
-telnet_getenv(char *val)
-{
- return((char *)env_getvalue((unsigned char *)val));
-}
-
-char *
-telnet_gets(const char *prom, char *result, int length, int echo)
-{
- extern int globalmode;
- int om = globalmode;
- char *res;
-
- TerminalNewMode(-1);
- if (echo) {
- printf("%s", prom);
- res = fgets(result, length, stdin);
- } else if ((res = getpass(prom))) {
- strncpy(result, res, length);
- res = result;
- }
- TerminalNewMode(om);
- return(res);
-}
-#endif /* ENCRYPTION */
-#endif /* AUTHENTICATION */
diff --git a/contrib/telnet/telnet/commands.c b/contrib/telnet/telnet/commands.c
deleted file mode 100644
index 32aca9f751c4..000000000000
--- a/contrib/telnet/telnet/commands.c
+++ /dev/null
@@ -1,3014 +0,0 @@
-/*
- * Copyright (c) 1988, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/un.h>
-#include <sys/file.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-#include <ctype.h>
-#include <err.h>
-#include <errno.h>
-#include <netdb.h>
-#include <pwd.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <arpa/telnet.h>
-#include <arpa/inet.h>
-
-#include "general.h"
-
-#include "ring.h"
-
-#include "externs.h"
-#include "defines.h"
-#include "types.h"
-#include "misc.h"
-
-#ifdef AUTHENTICATION
-#include <libtelnet/auth.h>
-#endif
-#ifdef ENCRYPTION
-#include <libtelnet/encrypt.h>
-#endif
-
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip6.h>
-
-#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 256
-#endif
-
-typedef int (*intrtn_t)(int, char **);
-
-#ifdef AUTHENTICATION
-extern int auth_togdebug(int);
-#endif
-#ifdef ENCRYPTION
-extern int EncryptAutoEnc(int);
-extern int EncryptAutoDec(int);
-extern int EncryptDebug(int);
-extern int EncryptVerbose(int);
-#endif /* ENCRYPTION */
-#if defined(IPPROTO_IP) && defined(IP_TOS)
-int tos = -1;
-#endif /* defined(IPPROTO_IP) && defined(IP_TOS) */
-
-char *hostname;
-static char _hostname[MAXHOSTNAMELEN];
-
-static int help(int, char **);
-static int call(intrtn_t, ...);
-static void cmdrc(char *, char *);
-#ifdef INET6
-static int switch_af(struct addrinfo **);
-#endif
-static int togglehelp(void);
-static int send_tncmd(void (*)(int, int), const char *, char *);
-static int setmod(int);
-static int clearmode(int);
-static int modehelp(void);
-static int sourceroute(struct addrinfo *, char *, char **, int *, int *, int *);
-
-typedef struct {
- const char *name; /* command name */
- const char *help; /* help string (NULL for no help) */
- int (*handler)(int, char **); /* routine which executes command */
- int needconnect; /* Do we need to be connected to execute? */
-} Command;
-
-static char line[256];
-static char saveline[256];
-static int margc;
-static char *margv[20];
-
-#ifdef OPIE
-#include <sys/wait.h>
-#define PATH_OPIEKEY "/usr/bin/opiekey"
-static int
-opie_calc(int argc, char *argv[])
-{
- int status;
-
- if(argc != 3) {
- printf("%s sequence challenge\n", argv[0]);
- return (0);
- }
-
- switch(fork()) {
- case 0:
- execv(PATH_OPIEKEY, argv);
- exit (1);
- case -1:
- perror("fork");
- break;
- default:
- (void) wait(&status);
- if (WIFEXITED(status))
- return (WEXITSTATUS(status));
- }
- return (0);
-}
-#endif
-
-static void
-makeargv(void)
-{
- char *cp, *cp2, c;
- char **argp = margv;
-
- margc = 0;
- cp = line;
- if (*cp == '!') { /* Special case shell escape */
- strcpy(saveline, line); /* save for shell command */
- *argp++ = strdup("!"); /* No room in string to get this */
- margc++;
- cp++;
- }
- while ((c = *cp)) {
- int inquote = 0;
- while (isspace(c))
- c = *++cp;
- if (c == '\0')
- break;
- *argp++ = cp;
- margc += 1;
- for (cp2 = cp; c != '\0'; c = *++cp) {
- if (inquote) {
- if (c == inquote) {
- inquote = 0;
- continue;
- }
- } else {
- if (c == '\\') {
- if ((c = *++cp) == '\0')
- break;
- } else if (c == '"') {
- inquote = '"';
- continue;
- } else if (c == '\'') {
- inquote = '\'';
- continue;
- } else if (isspace(c))
- break;
- }
- *cp2++ = c;
- }
- *cp2 = '\0';
- if (c == '\0')
- break;
- cp++;
- }
- *argp++ = 0;
-}
-
-/*
- * Make a character string into a number.
- *
- * Todo: 1. Could take random integers (12, 0x12, 012, 0b1).
- */
-
-static int
-special(char *s)
-{
- char c;
- char b;
-
- switch (*s) {
- case '^':
- b = *++s;
- if (b == '?') {
- c = b | 0x40; /* DEL */
- } else {
- c = b & 0x1f;
- }
- break;
- default:
- c = *s;
- break;
- }
- return c;
-}
-
-/*
- * Construct a control character sequence
- * for a special character.
- */
-static const char *
-control(cc_t c)
-{
- static char buf[5];
- /*
- * The only way I could get the Sun 3.5 compiler
- * to shut up about
- * if ((unsigned int)c >= 0x80)
- * was to assign "c" to an unsigned int variable...
- * Arggg....
- */
- unsigned int uic = (unsigned int)c;
-
- if (uic == 0x7f)
- return ("^?");
- if (c == (cc_t)_POSIX_VDISABLE) {
- return "off";
- }
- if (uic >= 0x80) {
- buf[0] = '\\';
- buf[1] = ((c>>6)&07) + '0';
- buf[2] = ((c>>3)&07) + '0';
- buf[3] = (c&07) + '0';
- buf[4] = 0;
- } else if (uic >= 0x20) {
- buf[0] = c;
- buf[1] = 0;
- } else {
- buf[0] = '^';
- buf[1] = '@'+c;
- buf[2] = 0;
- }
- return (buf);
-}
-
-/*
- * The following are data structures and routines for
- * the "send" command.
- *
- */
-
-struct sendlist {
- const char *name; /* How user refers to it (case independent) */
- const char *help; /* Help information (0 ==> no help) */
- int needconnect; /* Need to be connected */
- int narg; /* Number of arguments */
- int (*handler)(char *, ...); /* Routine to perform (for special ops) */
- int nbyte; /* Number of bytes to send this command */
- int what; /* Character to be sent (<0 ==> special) */
-};
-
-
-static int
- send_esc(void),
- send_help(void),
- send_docmd(char *),
- send_dontcmd(char *),
- send_willcmd(char *),
- send_wontcmd(char *);
-
-static struct sendlist Sendlist[] = {
- { "ao", "Send Telnet Abort output", 1, 0, NULL, 2, AO },
- { "ayt", "Send Telnet 'Are You There'", 1, 0, NULL, 2, AYT },
- { "brk", "Send Telnet Break", 1, 0, NULL, 2, BREAK },
- { "break", NULL, 1, 0, NULL, 2, BREAK },
- { "ec", "Send Telnet Erase Character", 1, 0, NULL, 2, EC },
- { "el", "Send Telnet Erase Line", 1, 0, NULL, 2, EL },
- { "escape", "Send current escape character",1, 0, (int (*)(char *, ...))send_esc, 1, 0 },
- { "ga", "Send Telnet 'Go Ahead' sequence", 1, 0, NULL, 2, GA },
- { "ip", "Send Telnet Interrupt Process",1, 0, NULL, 2, IP },
- { "intp", NULL, 1, 0, NULL, 2, IP },
- { "interrupt", NULL, 1, 0, NULL, 2, IP },
- { "intr", NULL, 1, 0, NULL, 2, IP },
- { "nop", "Send Telnet 'No operation'", 1, 0, NULL, 2, NOP },
- { "eor", "Send Telnet 'End of Record'", 1, 0, NULL, 2, EOR },
- { "abort", "Send Telnet 'Abort Process'", 1, 0, NULL, 2, ABORT },
- { "susp", "Send Telnet 'Suspend Process'",1, 0, NULL, 2, SUSP },
- { "eof", "Send Telnet End of File Character", 1, 0, NULL, 2, xEOF },
- { "synch", "Perform Telnet 'Synch operation'", 1, 0, (int (*)(char *, ...))dosynch, 2, 0 },
- { "getstatus", "Send request for STATUS", 1, 0, (int (*)(char *, ...))get_status, 6, 0 },
- { "?", "Display send options", 0, 0, (int (*)(char *, ...))send_help, 0, 0 },
- { "help", NULL, 0, 0, (int (*)(char *, ...))send_help, 0, 0 },
- { "do", NULL, 0, 1, (int (*)(char *, ...))send_docmd, 3, 0 },
- { "dont", NULL, 0, 1, (int (*)(char *, ...))send_dontcmd, 3, 0 },
- { "will", NULL, 0, 1, (int (*)(char *, ...))send_willcmd, 3, 0 },
- { "wont", NULL, 0, 1, (int (*)(char *, ...))send_wontcmd, 3, 0 },
- { NULL, NULL, 0, 0, NULL, 0, 0 }
-};
-
-#define GETSEND(name) ((struct sendlist *) genget(name, (char **) Sendlist, \
- sizeof(struct sendlist)))
-
-static int
-sendcmd(int argc, char *argv[])
-{
- int count; /* how many bytes we are going to need to send */
- int i;
- struct sendlist *s; /* pointer to current command */
- int success = 0;
- int needconnect = 0;
-
- if (argc < 2) {
- printf("need at least one argument for 'send' command\n");
- printf("'send ?' for help\n");
- return 0;
- }
- /*
- * First, validate all the send arguments.
- * In addition, we see how much space we are going to need, and
- * whether or not we will be doing a "SYNCH" operation (which
- * flushes the network queue).
- */
- count = 0;
- for (i = 1; i < argc; i++) {
- s = GETSEND(argv[i]);
- if (s == 0) {
- printf("Unknown send argument '%s'\n'send ?' for help.\n",
- argv[i]);
- return 0;
- } else if (Ambiguous((void *)s)) {
- printf("Ambiguous send argument '%s'\n'send ?' for help.\n",
- argv[i]);
- return 0;
- }
- if (i + s->narg >= argc) {
- fprintf(stderr,
- "Need %d argument%s to 'send %s' command. 'send %s ?' for help.\n",
- s->narg, s->narg == 1 ? "" : "s", s->name, s->name);
- return 0;
- }
- count += s->nbyte;
- if ((void *)s->handler == (void *)send_help) {
- send_help();
- return 0;
- }
-
- i += s->narg;
- needconnect += s->needconnect;
- }
- if (!connected && needconnect) {
- printf("?Need to be connected first.\n");
- printf("'send ?' for help\n");
- return 0;
- }
- /* Now, do we have enough room? */
- if (NETROOM() < count) {
- printf("There is not enough room in the buffer TO the network\n");
- printf("to process your request. Nothing will be done.\n");
- printf("('send synch' will throw away most data in the network\n");
- printf("buffer, if this might help.)\n");
- return 0;
- }
- /* OK, they are all OK, now go through again and actually send */
- count = 0;
- for (i = 1; i < argc; i++) {
- if ((s = GETSEND(argv[i])) == 0) {
- fprintf(stderr, "Telnet 'send' error - argument disappeared!\n");
- quit();
- /*NOTREACHED*/
- }
- if (s->handler) {
- count++;
- success += (*s->handler)((s->narg > 0) ? argv[i+1] : 0,
- (s->narg > 1) ? argv[i+2] : 0);
- i += s->narg;
- } else {
- NET2ADD(IAC, s->what);
- printoption("SENT", IAC, s->what);
- }
- }
- return (count == success);
-}
-
-static int
-send_esc(void)
-{
- NETADD(escape);
- return 1;
-}
-
-static int
-send_docmd(char *name)
-{
- return(send_tncmd(send_do, "do", name));
-}
-
-static int
-send_dontcmd(name)
- char *name;
-{
- return(send_tncmd(send_dont, "dont", name));
-}
-
-static int
-send_willcmd(char *name)
-{
- return(send_tncmd(send_will, "will", name));
-}
-
-static int
-send_wontcmd(char *name)
-{
- return(send_tncmd(send_wont, "wont", name));
-}
-
-static int
-send_tncmd(void (*func)(int, int), const char *cmd, char *name)
-{
- char **cpp;
- extern char *telopts[];
- int val = 0;
-
- if (isprefix(name, "help") || isprefix(name, "?")) {
- int col, len;
-
- printf("usage: send %s <value|option>\n", cmd);
- printf("\"value\" must be from 0 to 255\n");
- printf("Valid options are:\n\t");
-
- col = 8;
- for (cpp = telopts; *cpp; cpp++) {
- len = strlen(*cpp) + 3;
- if (col + len > 65) {
- printf("\n\t");
- col = 8;
- }
- printf(" \"%s\"", *cpp);
- col += len;
- }
- printf("\n");
- return 0;
- }
- cpp = (char **)genget(name, telopts, sizeof(char *));
- if (Ambiguous(cpp)) {
- fprintf(stderr,"'%s': ambiguous argument ('send %s ?' for help).\n",
- name, cmd);
- return 0;
- }
- if (cpp) {
- val = cpp - telopts;
- } else {
- char *cp = name;
-
- while (*cp >= '0' && *cp <= '9') {
- val *= 10;
- val += *cp - '0';
- cp++;
- }
- if (*cp != 0) {
- fprintf(stderr, "'%s': unknown argument ('send %s ?' for help).\n",
- name, cmd);
- return 0;
- } else if (val < 0 || val > 255) {
- fprintf(stderr, "'%s': bad value ('send %s ?' for help).\n",
- name, cmd);
- return 0;
- }
- }
- if (!connected) {
- printf("?Need to be connected first.\n");
- return 0;
- }
- (*func)(val, 1);
- return 1;
-}
-
-static int
-send_help(void)
-{
- struct sendlist *s; /* pointer to current command */
- for (s = Sendlist; s->name; s++) {
- if (s->help)
- printf("%-15s %s\n", s->name, s->help);
- }
- return(0);
-}
-
-/*
- * The following are the routines and data structures referred
- * to by the arguments to the "toggle" command.
- */
-
-static int
-lclchars(void)
-{
- donelclchars = 1;
- return 1;
-}
-
-static int
-togdebug(void)
-{
-#ifndef NOT43
- if (net > 0 &&
- (SetSockOpt(net, SOL_SOCKET, SO_DEBUG, telnet_debug)) < 0) {
- perror("setsockopt (SO_DEBUG)");
- }
-#else /* NOT43 */
- if (telnet_debug) {
- if (net > 0 && SetSockOpt(net, SOL_SOCKET, SO_DEBUG, 1) < 0)
- perror("setsockopt (SO_DEBUG)");
- } else
- printf("Cannot turn off socket debugging\n");
-#endif /* NOT43 */
- return 1;
-}
-
-
-static int
-togcrlf(void)
-{
- if (crlf) {
- printf("Will send carriage returns as telnet <CR><LF>.\n");
- } else {
- printf("Will send carriage returns as telnet <CR><NUL>.\n");
- }
- return 1;
-}
-
-int binmode;
-
-static int
-togbinary(int val)
-{
- donebinarytoggle = 1;
-
- if (val >= 0) {
- binmode = val;
- } else {
- if (my_want_state_is_will(TELOPT_BINARY) &&
- my_want_state_is_do(TELOPT_BINARY)) {
- binmode = 1;
- } else if (my_want_state_is_wont(TELOPT_BINARY) &&
- my_want_state_is_dont(TELOPT_BINARY)) {
- binmode = 0;
- }
- val = binmode ? 0 : 1;
- }
-
- if (val == 1) {
- if (my_want_state_is_will(TELOPT_BINARY) &&
- my_want_state_is_do(TELOPT_BINARY)) {
- printf("Already operating in binary mode with remote host.\n");
- } else {
- printf("Negotiating binary mode with remote host.\n");
- tel_enter_binary(3);
- }
- } else {
- if (my_want_state_is_wont(TELOPT_BINARY) &&
- my_want_state_is_dont(TELOPT_BINARY)) {
- printf("Already in network ascii mode with remote host.\n");
- } else {
- printf("Negotiating network ascii mode with remote host.\n");
- tel_leave_binary(3);
- }
- }
- return 1;
-}
-
-static int
-togrbinary(int val)
-{
- donebinarytoggle = 1;
-
- if (val == -1)
- val = my_want_state_is_do(TELOPT_BINARY) ? 0 : 1;
-
- if (val == 1) {
- if (my_want_state_is_do(TELOPT_BINARY)) {
- printf("Already receiving in binary mode.\n");
- } else {
- printf("Negotiating binary mode on input.\n");
- tel_enter_binary(1);
- }
- } else {
- if (my_want_state_is_dont(TELOPT_BINARY)) {
- printf("Already receiving in network ascii mode.\n");
- } else {
- printf("Negotiating network ascii mode on input.\n");
- tel_leave_binary(1);
- }
- }
- return 1;
-}
-
-static int
-togxbinary(int val)
-{
- donebinarytoggle = 1;
-
- if (val == -1)
- val = my_want_state_is_will(TELOPT_BINARY) ? 0 : 1;
-
- if (val == 1) {
- if (my_want_state_is_will(TELOPT_BINARY)) {
- printf("Already transmitting in binary mode.\n");
- } else {
- printf("Negotiating binary mode on output.\n");
- tel_enter_binary(2);
- }
- } else {
- if (my_want_state_is_wont(TELOPT_BINARY)) {
- printf("Already transmitting in network ascii mode.\n");
- } else {
- printf("Negotiating network ascii mode on output.\n");
- tel_leave_binary(2);
- }
- }
- return 1;
-}
-
-struct togglelist {
- const char *name; /* name of toggle */
- const char *help; /* help message */
- int (*handler)(int); /* routine to do actual setting */
- int *variable;
- const char *actionexplanation;
-};
-
-static struct togglelist Togglelist[] = {
- { "autoflush",
- "flushing of output when sending interrupt characters",
- 0,
- &autoflush,
- "flush output when sending interrupt characters" },
- { "autosynch",
- "automatic sending of interrupt characters in urgent mode",
- 0,
- &autosynch,
- "send interrupt characters in urgent mode" },
-#ifdef AUTHENTICATION
- { "autologin",
- "automatic sending of login and/or authentication info",
- 0,
- &autologin,
- "send login name and/or authentication information" },
- { "authdebug",
- "Toggle authentication debugging",
- auth_togdebug,
- 0,
- "print authentication debugging information" },
-#endif
-#ifdef ENCRYPTION
- { "autoencrypt",
- "automatic encryption of data stream",
- EncryptAutoEnc,
- 0,
- "automatically encrypt output" },
- { "autodecrypt",
- "automatic decryption of data stream",
- EncryptAutoDec,
- 0,
- "automatically decrypt input" },
- { "verbose_encrypt",
- "Toggle verbose encryption output",
- EncryptVerbose,
- 0,
- "print verbose encryption output" },
- { "encdebug",
- "Toggle encryption debugging",
- EncryptDebug,
- 0,
- "print encryption debugging information" },
-#endif /* ENCRYPTION */
- { "skiprc",
- "don't read ~/.telnetrc file",
- 0,
- &skiprc,
- "skip reading of ~/.telnetrc file" },
- { "binary",
- "sending and receiving of binary data",
- togbinary,
- 0,
- 0 },
- { "inbinary",
- "receiving of binary data",
- togrbinary,
- 0,
- 0 },
- { "outbinary",
- "sending of binary data",
- togxbinary,
- 0,
- 0 },
- { "crlf",
- "sending carriage returns as telnet <CR><LF>",
- (int (*)(int))togcrlf,
- &crlf,
- 0 },
- { "crmod",
- "mapping of received carriage returns",
- 0,
- &crmod,
- "map carriage return on output" },
- { "localchars",
- "local recognition of certain control characters",
- (int (*)(int))lclchars,
- &localchars,
- "recognize certain control characters" },
- { " ", "", NULL, NULL, NULL }, /* empty line */
- { "debug",
- "debugging",
- (int (*)(int))togdebug,
- &telnet_debug,
- "turn on socket level debugging" },
- { "netdata",
- "printing of hexadecimal network data (debugging)",
- 0,
- &netdata,
- "print hexadecimal representation of network traffic" },
- { "prettydump",
- "output of \"netdata\" to user readable format (debugging)",
- 0,
- &prettydump,
- "print user readable output for \"netdata\"" },
- { "options",
- "viewing of options processing (debugging)",
- 0,
- &showoptions,
- "show option processing" },
- { "termdata",
- "(debugging) toggle printing of hexadecimal terminal data",
- 0,
- &termdata,
- "print hexadecimal representation of terminal traffic" },
- { "?",
- NULL,
- (int (*)(int))togglehelp,
- NULL,
- NULL },
- { NULL, NULL, NULL, NULL, NULL },
- { "help",
- NULL,
- (int (*)(int))togglehelp,
- NULL,
- NULL },
- { NULL, NULL, NULL, NULL, NULL }
-};
-
-static int
-togglehelp(void)
-{
- struct togglelist *c;
-
- for (c = Togglelist; c->name; c++) {
- if (c->help) {
- if (*c->help)
- printf("%-15s toggle %s\n", c->name, c->help);
- else
- printf("\n");
- }
- }
- printf("\n");
- printf("%-15s %s\n", "?", "display help information");
- return 0;
-}
-
-static void
-settogglehelp(int set)
-{
- struct togglelist *c;
-
- for (c = Togglelist; c->name; c++) {
- if (c->help) {
- if (*c->help)
- printf("%-15s %s %s\n", c->name, set ? "enable" : "disable",
- c->help);
- else
- printf("\n");
- }
- }
-}
-
-#define GETTOGGLE(name) (struct togglelist *) \
- genget(name, (char **) Togglelist, sizeof(struct togglelist))
-
-static int
-toggle(int argc, char *argv[])
-{
- int retval = 1;
- char *name;
- struct togglelist *c;
-
- if (argc < 2) {
- fprintf(stderr,
- "Need an argument to 'toggle' command. 'toggle ?' for help.\n");
- return 0;
- }
- argc--;
- argv++;
- while (argc--) {
- name = *argv++;
- c = GETTOGGLE(name);
- if (Ambiguous((void *)c)) {
- fprintf(stderr, "'%s': ambiguous argument ('toggle ?' for help).\n",
- name);
- return 0;
- } else if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('toggle ?' for help).\n",
- name);
- return 0;
- } else {
- if (c->variable) {
- *c->variable = !*c->variable; /* invert it */
- if (c->actionexplanation) {
- printf("%s %s.\n", *c->variable? "Will" : "Won't",
- c->actionexplanation);
- }
- }
- if (c->handler) {
- retval &= (*c->handler)(-1);
- }
- }
- }
- return retval;
-}
-
-/*
- * The following perform the "set" command.
- */
-
-#ifdef USE_TERMIO
-struct termio new_tc = { 0, 0, 0, 0, {}, 0, 0 };
-#endif
-
-struct setlist {
- const char *name; /* name */
- const char *help; /* help information */
- void (*handler)(char *);
- cc_t *charp; /* where it is located at */
-};
-
-static struct setlist Setlist[] = {
-#ifdef KLUDGELINEMODE
- { "echo", "character to toggle local echoing on/off", NULL, &echoc },
-#endif
- { "escape", "character to escape back to telnet command mode", NULL, &escape },
- { "rlogin", "rlogin escape character", 0, &rlogin },
- { "tracefile", "file to write trace information to", SetNetTrace, (cc_t *)NetTraceFile},
- { " ", "", NULL, NULL },
- { " ", "The following need 'localchars' to be toggled true", NULL, NULL },
- { "flushoutput", "character to cause an Abort Output", NULL, termFlushCharp },
- { "interrupt", "character to cause an Interrupt Process", NULL, termIntCharp },
- { "quit", "character to cause an Abort process", NULL, termQuitCharp },
- { "eof", "character to cause an EOF ", NULL, termEofCharp },
- { " ", "", NULL, NULL },
- { " ", "The following are for local editing in linemode", NULL, NULL },
- { "erase", "character to use to erase a character", NULL, termEraseCharp },
- { "kill", "character to use to erase a line", NULL, termKillCharp },
- { "lnext", "character to use for literal next", NULL, termLiteralNextCharp },
- { "susp", "character to cause a Suspend Process", NULL, termSuspCharp },
- { "reprint", "character to use for line reprint", NULL, termRprntCharp },
- { "worderase", "character to use to erase a word", NULL, termWerasCharp },
- { "start", "character to use for XON", NULL, termStartCharp },
- { "stop", "character to use for XOFF", NULL, termStopCharp },
- { "forw1", "alternate end of line character", NULL, termForw1Charp },
- { "forw2", "alternate end of line character", NULL, termForw2Charp },
- { "ayt", "alternate AYT character", NULL, termAytCharp },
- { NULL, NULL, NULL, NULL }
-};
-
-static struct setlist *
-getset(char *name)
-{
- return (struct setlist *)
- genget(name, (char **) Setlist, sizeof(struct setlist));
-}
-
-void
-set_escape_char(char *s)
-{
- if (rlogin != _POSIX_VDISABLE) {
- rlogin = (s && *s) ? special(s) : _POSIX_VDISABLE;
- printf("Telnet rlogin escape character is '%s'.\n",
- control(rlogin));
- } else {
- escape = (s && *s) ? special(s) : _POSIX_VDISABLE;
- printf("Telnet escape character is '%s'.\n", control(escape));
- }
-}
-
-static int
-setcmd(int argc, char *argv[])
-{
- int value;
- struct setlist *ct;
- struct togglelist *c;
-
- if (argc < 2 || argc > 3) {
- printf("Format is 'set Name Value'\n'set ?' for help.\n");
- return 0;
- }
- if ((argc == 2) && (isprefix(argv[1], "?") || isprefix(argv[1], "help"))) {
- for (ct = Setlist; ct->name; ct++)
- printf("%-15s %s\n", ct->name, ct->help);
- printf("\n");
- settogglehelp(1);
- printf("%-15s %s\n", "?", "display help information");
- return 0;
- }
-
- ct = getset(argv[1]);
- if (ct == 0) {
- c = GETTOGGLE(argv[1]);
- if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('set ?' for help).\n",
- argv[1]);
- return 0;
- } else if (Ambiguous((void *)c)) {
- fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\n",
- argv[1]);
- return 0;
- }
- if (c->variable) {
- if ((argc == 2) || (strcmp("on", argv[2]) == 0))
- *c->variable = 1;
- else if (strcmp("off", argv[2]) == 0)
- *c->variable = 0;
- else {
- printf("Format is 'set togglename [on|off]'\n'set ?' for help.\n");
- return 0;
- }
- if (c->actionexplanation) {
- printf("%s %s.\n", *c->variable? "Will" : "Won't",
- c->actionexplanation);
- }
- }
- if (c->handler)
- (*c->handler)(1);
- } else if (argc != 3) {
- printf("Format is 'set Name Value'\n'set ?' for help.\n");
- return 0;
- } else if (Ambiguous((void *)ct)) {
- fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\n",
- argv[1]);
- return 0;
- } else if (ct->handler) {
- (*ct->handler)(argv[2]);
- printf("%s set to \"%s\".\n", ct->name, (char *)ct->charp);
- } else {
- if (strcmp("off", argv[2])) {
- value = special(argv[2]);
- } else {
- value = _POSIX_VDISABLE;
- }
- *(ct->charp) = (cc_t)value;
- printf("%s character is '%s'.\n", ct->name, control(*(ct->charp)));
- }
- slc_check();
- return 1;
-}
-
-static int
-unsetcmd(int argc, char *argv[])
-{
- struct setlist *ct;
- struct togglelist *c;
- char *name;
-
- if (argc < 2) {
- fprintf(stderr,
- "Need an argument to 'unset' command. 'unset ?' for help.\n");
- return 0;
- }
- if (isprefix(argv[1], "?") || isprefix(argv[1], "help")) {
- for (ct = Setlist; ct->name; ct++)
- printf("%-15s %s\n", ct->name, ct->help);
- printf("\n");
- settogglehelp(0);
- printf("%-15s %s\n", "?", "display help information");
- return 0;
- }
-
- argc--;
- argv++;
- while (argc--) {
- name = *argv++;
- ct = getset(name);
- if (ct == 0) {
- c = GETTOGGLE(name);
- if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('unset ?' for help).\n",
- name);
- return 0;
- } else if (Ambiguous((void *)c)) {
- fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n",
- name);
- return 0;
- }
- if (c->variable) {
- *c->variable = 0;
- if (c->actionexplanation) {
- printf("%s %s.\n", *c->variable? "Will" : "Won't",
- c->actionexplanation);
- }
- }
- if (c->handler)
- (*c->handler)(0);
- } else if (Ambiguous((void *)ct)) {
- fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n",
- name);
- return 0;
- } else if (ct->handler) {
- (*ct->handler)(0);
- printf("%s reset to \"%s\".\n", ct->name, (char *)ct->charp);
- } else {
- *(ct->charp) = _POSIX_VDISABLE;
- printf("%s character is '%s'.\n", ct->name, control(*(ct->charp)));
- }
- }
- return 1;
-}
-
-/*
- * The following are the data structures and routines for the
- * 'mode' command.
- */
-#ifdef KLUDGELINEMODE
-extern int kludgelinemode;
-
-static int
-dokludgemode(void)
-{
- kludgelinemode = 1;
- send_wont(TELOPT_LINEMODE, 1);
- send_dont(TELOPT_SGA, 1);
- send_dont(TELOPT_ECHO, 1);
- return 1;
-}
-#endif
-
-static int
-dolinemode(void)
-{
-#ifdef KLUDGELINEMODE
- if (kludgelinemode)
- send_dont(TELOPT_SGA, 1);
-#endif
- send_will(TELOPT_LINEMODE, 1);
- send_dont(TELOPT_ECHO, 1);
- return 1;
-}
-
-static int
-docharmode(void)
-{
-#ifdef KLUDGELINEMODE
- if (kludgelinemode)
- send_do(TELOPT_SGA, 1);
- else
-#endif
- send_wont(TELOPT_LINEMODE, 1);
- send_do(TELOPT_ECHO, 1);
- return 1;
-}
-
-static int
-dolmmode(int bit, int on)
-{
- unsigned char c;
- extern int linemode;
-
- if (my_want_state_is_wont(TELOPT_LINEMODE)) {
- printf("?Need to have LINEMODE option enabled first.\n");
- printf("'mode ?' for help.\n");
- return 0;
- }
-
- if (on)
- c = (linemode | bit);
- else
- c = (linemode & ~bit);
- lm_mode(&c, 1, 1);
- return 1;
-}
-
-static int
-setmod(int bit)
-{
- return dolmmode(bit, 1);
-}
-
-static int
-clearmode(int bit)
-{
- return dolmmode(bit, 0);
-}
-
-struct modelist {
- const char *name; /* command name */
- const char *help; /* help string */
- int (*handler)(int);/* routine which executes command */
- int needconnect; /* Do we need to be connected to execute? */
- int arg1;
-};
-
-static struct modelist ModeList[] = {
- { "character", "Disable LINEMODE option", (int (*)(int))docharmode, 1, 0 },
-#ifdef KLUDGELINEMODE
- { "", "(or disable obsolete line-by-line mode)", NULL, 0, 0 },
-#endif
- { "line", "Enable LINEMODE option", (int (*)(int))dolinemode, 1, 0 },
-#ifdef KLUDGELINEMODE
- { "", "(or enable obsolete line-by-line mode)", NULL, 0, 0 },
-#endif
- { "", "", NULL, 0, 0 },
- { "", "These require the LINEMODE option to be enabled", NULL, 0, 0 },
- { "isig", "Enable signal trapping", setmod, 1, MODE_TRAPSIG },
- { "+isig", 0, setmod, 1, MODE_TRAPSIG },
- { "-isig", "Disable signal trapping", clearmode, 1, MODE_TRAPSIG },
- { "edit", "Enable character editing", setmod, 1, MODE_EDIT },
- { "+edit", 0, setmod, 1, MODE_EDIT },
- { "-edit", "Disable character editing", clearmode, 1, MODE_EDIT },
- { "softtabs", "Enable tab expansion", setmod, 1, MODE_SOFT_TAB },
- { "+softtabs", 0, setmod, 1, MODE_SOFT_TAB },
- { "-softtabs", "Disable character editing", clearmode, 1, MODE_SOFT_TAB },
- { "litecho", "Enable literal character echo", setmod, 1, MODE_LIT_ECHO },
- { "+litecho", 0, setmod, 1, MODE_LIT_ECHO },
- { "-litecho", "Disable literal character echo", clearmode, 1, MODE_LIT_ECHO },
- { "help", 0, (int (*)(int))modehelp, 0, 0 },
-#ifdef KLUDGELINEMODE
- { "kludgeline", 0, (int (*)(int))dokludgemode, 1, 0 },
-#endif
- { "", "", NULL, 0, 0 },
- { "?", "Print help information", (int (*)(int))modehelp, 0, 0 },
- { NULL, NULL, NULL, 0, 0 },
-};
-
-
-static int
-modehelp(void)
-{
- struct modelist *mt;
-
- printf("format is: 'mode Mode', where 'Mode' is one of:\n\n");
- for (mt = ModeList; mt->name; mt++) {
- if (mt->help) {
- if (*mt->help)
- printf("%-15s %s\n", mt->name, mt->help);
- else
- printf("\n");
- }
- }
- return 0;
-}
-
-#define GETMODECMD(name) (struct modelist *) \
- genget(name, (char **) ModeList, sizeof(struct modelist))
-
-static int
-modecmd(int argc, char *argv[])
-{
- struct modelist *mt;
-
- if (argc != 2) {
- printf("'mode' command requires an argument\n");
- printf("'mode ?' for help.\n");
- } else if ((mt = GETMODECMD(argv[1])) == 0) {
- fprintf(stderr, "Unknown mode '%s' ('mode ?' for help).\n", argv[1]);
- } else if (Ambiguous((void *)mt)) {
- fprintf(stderr, "Ambiguous mode '%s' ('mode ?' for help).\n", argv[1]);
- } else if (mt->needconnect && !connected) {
- printf("?Need to be connected first.\n");
- printf("'mode ?' for help.\n");
- } else if (mt->handler) {
- return (*mt->handler)(mt->arg1);
- }
- return 0;
-}
-
-/*
- * The following data structures and routines implement the
- * "display" command.
- */
-
-static int
-display(int argc, char *argv[])
-{
- struct togglelist *tl;
- struct setlist *sl;
-
-#define dotog(tl) if (tl->variable && tl->actionexplanation) { \
- if (*tl->variable) { \
- printf("will"); \
- } else { \
- printf("won't"); \
- } \
- printf(" %s.\n", tl->actionexplanation); \
- }
-
-#define doset(sl) if (sl->name && *sl->name != ' ') { \
- if (sl->handler == 0) \
- printf("%-15s [%s]\n", sl->name, control(*sl->charp)); \
- else \
- printf("%-15s \"%s\"\n", sl->name, (char *)sl->charp); \
- }
-
- if (argc == 1) {
- for (tl = Togglelist; tl->name; tl++) {
- dotog(tl);
- }
- printf("\n");
- for (sl = Setlist; sl->name; sl++) {
- doset(sl);
- }
- } else {
- int i;
-
- for (i = 1; i < argc; i++) {
- sl = getset(argv[i]);
- tl = GETTOGGLE(argv[i]);
- if (Ambiguous((void *)sl) || Ambiguous((void *)tl)) {
- printf("?Ambiguous argument '%s'.\n", argv[i]);
- return 0;
- } else if (!sl && !tl) {
- printf("?Unknown argument '%s'.\n", argv[i]);
- return 0;
- } else {
- if (tl) {
- dotog(tl);
- }
- if (sl) {
- doset(sl);
- }
- }
- }
- }
-/*@*/optionstatus();
-#ifdef ENCRYPTION
- EncryptStatus();
-#endif /* ENCRYPTION */
- return 1;
-#undef doset
-#undef dotog
-}
-
-/*
- * The following are the data structures, and many of the routines,
- * relating to command processing.
- */
-
-/*
- * Set the escape character.
- */
-static int
-setescape(int argc, char *argv[])
-{
- char *arg;
- char buf[50];
-
- printf(
- "Deprecated usage - please use 'set escape%s%s' in the future.\n",
- (argc > 2)? " ":"", (argc > 2)? argv[1]: "");
- if (argc > 2)
- arg = argv[1];
- else {
- printf("new escape character: ");
- (void) fgets(buf, sizeof(buf), stdin);
- arg = buf;
- }
- if (arg[0] != '\0')
- escape = arg[0];
- (void) fflush(stdout);
- return 1;
-}
-
-static int
-togcrmod(void)
-{
- crmod = !crmod;
- printf("Deprecated usage - please use 'toggle crmod' in the future.\n");
- printf("%s map carriage return on output.\n", crmod ? "Will" : "Won't");
- (void) fflush(stdout);
- return 1;
-}
-
-static int
-suspend(void)
-{
-#ifdef SIGTSTP
- setcommandmode();
- {
- long oldrows, oldcols, newrows, newcols, err_;
-
- err_ = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0;
- (void) kill(0, SIGTSTP);
- /*
- * If we didn't get the window size before the SUSPEND, but we
- * can get them now (?), then send the NAWS to make sure that
- * we are set up for the right window size.
- */
- if (TerminalWindowSize(&newrows, &newcols) && connected &&
- (err_ || ((oldrows != newrows) || (oldcols != newcols)))) {
- sendnaws();
- }
- }
- /* reget parameters in case they were changed */
- TerminalSaveState();
- setconnmode(0);
-#else
- printf("Suspend is not supported. Try the '!' command instead\n");
-#endif
- return 1;
-}
-
-static int
-shell(int argc, char *argv[] __unused)
-{
- long oldrows, oldcols, newrows, newcols, err_;
-
- setcommandmode();
-
- err_ = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0;
- switch(vfork()) {
- case -1:
- perror("Fork failed\n");
- break;
-
- case 0:
- {
- /*
- * Fire up the shell in the child.
- */
- const char *shellp, *shellname;
-
- shellp = getenv("SHELL");
- if (shellp == NULL)
- shellp = "/bin/sh";
- if ((shellname = strrchr(shellp, '/')) == 0)
- shellname = shellp;
- else
- shellname++;
- if (argc > 1)
- execl(shellp, shellname, "-c", &saveline[1], (char *)0);
- else
- execl(shellp, shellname, (char *)0);
- perror("Execl");
- _exit(1);
- }
- default:
- (void)wait((int *)0); /* Wait for the shell to complete */
-
- if (TerminalWindowSize(&newrows, &newcols) && connected &&
- (err_ || ((oldrows != newrows) || (oldcols != newcols)))) {
- sendnaws();
- }
- break;
- }
- return 1;
-}
-
-static int
-bye(int argc, char *argv[])
-{
- extern int resettermname;
-
- if (connected) {
- (void) shutdown(net, 2);
- printf("Connection closed.\n");
- (void) NetClose(net);
- connected = 0;
- resettermname = 1;
-#ifdef AUTHENTICATION
-#ifdef ENCRYPTION
- auth_encrypt_connect(connected);
-#endif
-#endif
- /* reset options */
- tninit();
- }
- if ((argc != 2) || (strcmp(argv[1], "fromquit") != 0)) {
- longjmp(toplevel, 1);
- /* NOTREACHED */
- }
- return 1; /* Keep lint, etc., happy */
-}
-
-void
-quit(void)
-{
- (void) call(bye, "bye", "fromquit", 0);
- Exit(0);
-}
-
-static int
-logout(void)
-{
- send_do(TELOPT_LOGOUT, 1);
- (void) netflush();
- return 1;
-}
-
-
-/*
- * The SLC command.
- */
-
-struct slclist {
- const char *name;
- const char *help;
- void (*handler)(int);
- int arg;
-};
-
-static void slc_help(void);
-
-struct slclist SlcList[] = {
- { "export", "Use local special character definitions",
- (void (*)(int))slc_mode_export, 0 },
- { "import", "Use remote special character definitions",
- slc_mode_import, 1 },
- { "check", "Verify remote special character definitions",
- slc_mode_import, 0 },
- { "help", NULL, (void (*)(int))slc_help, 0 },
- { "?", "Print help information", (void (*)(int))slc_help, 0 },
- { NULL, NULL, NULL, 0 },
-};
-
-static void
-slc_help(void)
-{
- struct slclist *c;
-
- for (c = SlcList; c->name; c++) {
- if (c->help) {
- if (*c->help)
- printf("%-15s %s\n", c->name, c->help);
- else
- printf("\n");
- }
- }
-}
-
-static struct slclist *
-getslc(char *name)
-{
- return (struct slclist *)
- genget(name, (char **) SlcList, sizeof(struct slclist));
-}
-
-static int
-slccmd(int argc, char *argv[])
-{
- struct slclist *c;
-
- if (argc != 2) {
- fprintf(stderr,
- "Need an argument to 'slc' command. 'slc ?' for help.\n");
- return 0;
- }
- c = getslc(argv[1]);
- if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('slc ?' for help).\n",
- argv[1]);
- return 0;
- }
- if (Ambiguous((void *)c)) {
- fprintf(stderr, "'%s': ambiguous argument ('slc ?' for help).\n",
- argv[1]);
- return 0;
- }
- (*c->handler)(c->arg);
- slcstate();
- return 1;
-}
-
-/*
- * The ENVIRON command.
- */
-
-struct envlist {
- const char *name;
- const char *help;
- void (*handler)(unsigned char *, unsigned char *);
- int narg;
-};
-
-extern struct env_lst *
- env_define(const unsigned char *, unsigned char *);
-extern void
- env_undefine(unsigned char *),
- env_export(const unsigned char *),
- env_unexport(const unsigned char *),
- env_send(unsigned char *),
-#if defined(OLD_ENVIRON) && defined(ENV_HACK)
- env_varval(unsigned char *),
-#endif
- env_list(void);
-static void
- env_help(void);
-
-struct envlist EnvList[] = {
- { "define", "Define an environment variable",
- (void (*)(unsigned char *, unsigned char *))env_define, 2 },
- { "undefine", "Undefine an environment variable",
- (void (*)(unsigned char *, unsigned char *))env_undefine, 1 },
- { "export", "Mark an environment variable for automatic export",
- (void (*)(unsigned char *, unsigned char *))env_export, 1 },
- { "unexport", "Don't mark an environment variable for automatic export",
- (void (*)(unsigned char *, unsigned char *))env_unexport, 1 },
- { "send", "Send an environment variable", (void (*)(unsigned char *, unsigned char *))env_send, 1 },
- { "list", "List the current environment variables",
- (void (*)(unsigned char *, unsigned char *))env_list, 0 },
-#if defined(OLD_ENVIRON) && defined(ENV_HACK)
- { "varval", "Reverse VAR and VALUE (auto, right, wrong, status)",
- (void (*)(unsigned char *, unsigned char *))env_varval, 1 },
-#endif
- { "help", NULL, (void (*)(unsigned char *, unsigned char *))env_help, 0 },
- { "?", "Print help information", (void (*)(unsigned char *, unsigned char *))env_help, 0 },
- { NULL, NULL, NULL, 0 },
-};
-
-static void
-env_help(void)
-{
- struct envlist *c;
-
- for (c = EnvList; c->name; c++) {
- if (c->help) {
- if (*c->help)
- printf("%-15s %s\n", c->name, c->help);
- else
- printf("\n");
- }
- }
-}
-
-static struct envlist *
-getenvcmd(char *name)
-{
- return (struct envlist *)
- genget(name, (char **) EnvList, sizeof(struct envlist));
-}
-
-static int
-env_cmd(int argc, char *argv[])
-{
- struct envlist *c;
-
- if (argc < 2) {
- fprintf(stderr,
- "Need an argument to 'environ' command. 'environ ?' for help.\n");
- return 0;
- }
- c = getenvcmd(argv[1]);
- if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('environ ?' for help).\n",
- argv[1]);
- return 0;
- }
- if (Ambiguous((void *)c)) {
- fprintf(stderr, "'%s': ambiguous argument ('environ ?' for help).\n",
- argv[1]);
- return 0;
- }
- if (c->narg + 2 != argc) {
- fprintf(stderr,
- "Need %s%d argument%s to 'environ %s' command. 'environ ?' for help.\n",
- c->narg < argc + 2 ? "only " : "",
- c->narg, c->narg == 1 ? "" : "s", c->name);
- return 0;
- }
- (*c->handler)(argv[2], argv[3]);
- return 1;
-}
-
-struct env_lst {
- struct env_lst *next; /* pointer to next structure */
- struct env_lst *prev; /* pointer to previous structure */
- unsigned char *var; /* pointer to variable name */
- unsigned char *value; /* pointer to variable value */
- int export; /* 1 -> export with default list of variables */
- int welldefined; /* A well defined variable */
-};
-
-struct env_lst envlisthead;
-
-static struct env_lst *
-env_find(const unsigned char *var)
-{
- struct env_lst *ep;
-
- for (ep = envlisthead.next; ep; ep = ep->next) {
- if (strcmp(ep->var, var) == 0)
- return(ep);
- }
- return(NULL);
-}
-
-void
-env_init(void)
-{
- extern char **environ;
- char **epp, *cp;
- struct env_lst *ep;
-
- for (epp = environ; *epp; epp++) {
- if ((cp = strchr(*epp, '='))) {
- *cp = '\0';
- ep = env_define((unsigned char *)*epp,
- (unsigned char *)cp+1);
- ep->export = 0;
- *cp = '=';
- }
- }
- /*
- * Special case for DISPLAY variable. If it is ":0.0" or
- * "unix:0.0", we have to get rid of "unix" and insert our
- * hostname.
- */
- if ((ep = env_find("DISPLAY"))
- && ((*ep->value == ':')
- || (strncmp((char *)ep->value, "unix:", 5) == 0))) {
- char hbuf[256+1];
- char *cp2 = strchr((char *)ep->value, ':');
-
- gethostname(hbuf, 256);
- hbuf[256] = '\0';
- cp = (char *)malloc(strlen(hbuf) + strlen(cp2) + 1);
- sprintf((char *)cp, "%s%s", hbuf, cp2);
- free(ep->value);
- ep->value = (unsigned char *)cp;
- }
- /*
- * If USER is not defined, but LOGNAME is, then add
- * USER with the value from LOGNAME. By default, we
- * don't export the USER variable.
- */
- if ((env_find("USER") == NULL) && (ep = env_find("LOGNAME"))) {
- env_define("USER", ep->value);
- env_unexport("USER");
- }
- env_export("DISPLAY");
- env_export("PRINTER");
-}
-
-struct env_lst *
-env_define(const unsigned char *var, unsigned char *value)
-{
- struct env_lst *ep;
-
- if ((ep = env_find(var))) {
- if (ep->var)
- free(ep->var);
- if (ep->value)
- free(ep->value);
- } else {
- ep = (struct env_lst *)malloc(sizeof(struct env_lst));
- ep->next = envlisthead.next;
- envlisthead.next = ep;
- ep->prev = &envlisthead;
- if (ep->next)
- ep->next->prev = ep;
- }
- ep->welldefined = opt_welldefined(var);
- ep->export = 1;
- ep->var = strdup(var);
- ep->value = strdup(value);
- return(ep);
-}
-
-void
-env_undefine(unsigned char *var)
-{
- struct env_lst *ep;
-
- if ((ep = env_find(var))) {
- ep->prev->next = ep->next;
- if (ep->next)
- ep->next->prev = ep->prev;
- if (ep->var)
- free(ep->var);
- if (ep->value)
- free(ep->value);
- free(ep);
- }
-}
-
-void
-env_export(const unsigned char *var)
-{
- struct env_lst *ep;
-
- if ((ep = env_find(var)))
- ep->export = 1;
-}
-
-void
-env_unexport(const unsigned char *var)
-{
- struct env_lst *ep;
-
- if ((ep = env_find(var)))
- ep->export = 0;
-}
-
-void
-env_send(unsigned char *var)
-{
- struct env_lst *ep;
-
- if (my_state_is_wont(TELOPT_NEW_ENVIRON)
-#ifdef OLD_ENVIRON
- && my_state_is_wont(TELOPT_OLD_ENVIRON)
-#endif
- ) {
- fprintf(stderr,
- "Cannot send '%s': Telnet ENVIRON option not enabled\n",
- var);
- return;
- }
- ep = env_find(var);
- if (ep == 0) {
- fprintf(stderr, "Cannot send '%s': variable not defined\n",
- var);
- return;
- }
- env_opt_start_info();
- env_opt_add(ep->var);
- env_opt_end(0);
-}
-
-void
-env_list(void)
-{
- struct env_lst *ep;
-
- for (ep = envlisthead.next; ep; ep = ep->next) {
- printf("%c %-20s %s\n", ep->export ? '*' : ' ',
- ep->var, ep->value);
- }
-}
-
-unsigned char *
-env_default(int init, int welldefined)
-{
- static struct env_lst *nep = NULL;
-
- if (init) {
- nep = &envlisthead;
- return(NULL);
- }
- if (nep) {
- while ((nep = nep->next)) {
- if (nep->export && (nep->welldefined == welldefined))
- return(nep->var);
- }
- }
- return(NULL);
-}
-
-unsigned char *
-env_getvalue(const unsigned char *var)
-{
- struct env_lst *ep;
-
- if ((ep = env_find(var)))
- return(ep->value);
- return(NULL);
-}
-
-#if defined(OLD_ENVIRON) && defined(ENV_HACK)
-void
-env_varval(unsigned char *what)
-{
- extern int old_env_var, old_env_value, env_auto;
- int len = strlen((char *)what);
-
- if (len == 0)
- goto unknown;
-
- if (strncasecmp((char *)what, "status", len) == 0) {
- if (env_auto)
- printf("%s%s", "VAR and VALUE are/will be ",
- "determined automatically\n");
- if (old_env_var == OLD_ENV_VAR)
- printf("VAR and VALUE set to correct definitions\n");
- else
- printf("VAR and VALUE definitions are reversed\n");
- } else if (strncasecmp((char *)what, "auto", len) == 0) {
- env_auto = 1;
- old_env_var = OLD_ENV_VALUE;
- old_env_value = OLD_ENV_VAR;
- } else if (strncasecmp((char *)what, "right", len) == 0) {
- env_auto = 0;
- old_env_var = OLD_ENV_VAR;
- old_env_value = OLD_ENV_VALUE;
- } else if (strncasecmp((char *)what, "wrong", len) == 0) {
- env_auto = 0;
- old_env_var = OLD_ENV_VALUE;
- old_env_value = OLD_ENV_VAR;
- } else {
-unknown:
- printf("Unknown \"varval\" command. (\"auto\", \"right\", \"wrong\", \"status\")\n");
- }
-}
-#endif
-
-#ifdef AUTHENTICATION
-/*
- * The AUTHENTICATE command.
- */
-
-struct authlist {
- const char *name;
- const char *help;
- int (*handler)(char *);
- int narg;
-};
-
-extern int
- auth_enable(char *),
- auth_disable(char *),
- auth_status(void);
-static int
- auth_help(void);
-
-struct authlist AuthList[] = {
- { "status", "Display current status of authentication information",
- (int (*)(char *))auth_status, 0 },
- { "disable", "Disable an authentication type ('auth disable ?' for more)",
- auth_disable, 1 },
- { "enable", "Enable an authentication type ('auth enable ?' for more)",
- auth_enable, 1 },
- { "help", NULL, (int (*)(char *))auth_help, 0 },
- { "?", "Print help information", (int (*)(char *))auth_help, 0 },
- { NULL, NULL, NULL, 0 },
-};
-
-static int
-auth_help(void)
-{
- struct authlist *c;
-
- for (c = AuthList; c->name; c++) {
- if (c->help) {
- if (*c->help)
- printf("%-15s %s\n", c->name, c->help);
- else
- printf("\n");
- }
- }
- return 0;
-}
-
-int
-auth_cmd(int argc, char *argv[])
-{
- struct authlist *c;
-
- if (argc < 2) {
- fprintf(stderr,
- "Need an argument to 'auth' command. 'auth ?' for help.\n");
- return 0;
- }
-
- c = (struct authlist *)
- genget(argv[1], (char **) AuthList, sizeof(struct authlist));
- if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('auth ?' for help).\n",
- argv[1]);
- return 0;
- }
- if (Ambiguous((void *)c)) {
- fprintf(stderr, "'%s': ambiguous argument ('auth ?' for help).\n",
- argv[1]);
- return 0;
- }
- if (c->narg + 2 != argc) {
- fprintf(stderr,
- "Need %s%d argument%s to 'auth %s' command. 'auth ?' for help.\n",
- c->narg < argc + 2 ? "only " : "",
- c->narg, c->narg == 1 ? "" : "s", c->name);
- return 0;
- }
- return((*c->handler)(argv[2]));
-}
-#endif
-
-#ifdef ENCRYPTION
-/*
- * The ENCRYPT command.
- */
-
-struct encryptlist {
- const char *name;
- const char *help;
- int (*handler)(char *, char *);
- int needconnect;
- int minarg;
- int maxarg;
-};
-
-extern int
- EncryptEnable(char *, char *),
- EncryptDisable(char *, char *),
- EncryptType(char *, char *),
- EncryptStart(char *),
- EncryptStartInput(void),
- EncryptStartOutput(void),
- EncryptStop(char *),
- EncryptStopInput(void),
- EncryptStopOutput(void),
- EncryptStatus(void);
-static int
- EncryptHelp(void);
-
-struct encryptlist EncryptList[] = {
- { "enable", "Enable encryption. ('encrypt enable ?' for more)",
- EncryptEnable, 1, 1, 2 },
- { "disable", "Disable encryption. ('encrypt enable ?' for more)",
- EncryptDisable, 0, 1, 2 },
- { "type", "Set encryption type. ('encrypt type ?' for more)",
- EncryptType, 0, 1, 1 },
- { "start", "Start encryption. ('encrypt start ?' for more)",
- (int (*)(char *, char *))EncryptStart, 1, 0, 1 },
- { "stop", "Stop encryption. ('encrypt stop ?' for more)",
- (int (*)(char *, char *))EncryptStop, 1, 0, 1 },
- { "input", "Start encrypting the input stream",
- (int (*)(char *, char *))EncryptStartInput, 1, 0, 0 },
- { "-input", "Stop encrypting the input stream",
- (int (*)(char *, char *))EncryptStopInput, 1, 0, 0 },
- { "output", "Start encrypting the output stream",
- (int (*)(char *, char *))EncryptStartOutput, 1, 0, 0 },
- { "-output", "Stop encrypting the output stream",
- (int (*)(char *, char *))EncryptStopOutput, 1, 0, 0 },
-
- { "status", "Display current status of authentication information",
- (int (*)(char *, char *))EncryptStatus, 0, 0, 0 },
- { "help", NULL, (int (*)(char *, char *))EncryptHelp, 0, 0, 0 },
- { "?", "Print help information", (int (*)(char *, char *))EncryptHelp, 0, 0, 0 },
- { NULL, NULL, NULL, 0, 0, 0 },
-};
-
-static int
-EncryptHelp(void)
-{
- struct encryptlist *c;
-
- for (c = EncryptList; c->name; c++) {
- if (c->help) {
- if (*c->help)
- printf("%-15s %s\n", c->name, c->help);
- else
- printf("\n");
- }
- }
- return 0;
-}
-
-static int
-encrypt_cmd(int argc, char *argv[])
-{
- struct encryptlist *c;
-
- if (argc < 2) {
- fprintf(stderr,
- "Need an argument to 'encrypt' command. 'encrypt ?' for help.\n");
- return 0;
- }
-
- c = (struct encryptlist *)
- genget(argv[1], (char **) EncryptList, sizeof(struct encryptlist));
- if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('encrypt ?' for help).\n",
- argv[1]);
- return 0;
- }
- if (Ambiguous((void *)c)) {
- fprintf(stderr, "'%s': ambiguous argument ('encrypt ?' for help).\n",
- argv[1]);
- return 0;
- }
- argc -= 2;
- if (argc < c->minarg || argc > c->maxarg) {
- if (c->minarg == c->maxarg) {
- fprintf(stderr, "Need %s%d argument%s ",
- c->minarg < argc ? "only " : "", c->minarg,
- c->minarg == 1 ? "" : "s");
- } else {
- fprintf(stderr, "Need %s%d-%d arguments ",
- c->maxarg < argc ? "only " : "", c->minarg, c->maxarg);
- }
- fprintf(stderr, "to 'encrypt %s' command. 'encrypt ?' for help.\n",
- c->name);
- return 0;
- }
- if (c->needconnect && !connected) {
- if (!(argc && (isprefix(argv[2], "help") || isprefix(argv[2], "?")))) {
- printf("?Need to be connected first.\n");
- return 0;
- }
- }
- return ((*c->handler)(argc > 0 ? argv[2] : 0,
- argc > 1 ? argv[3] : 0));
-}
-#endif /* ENCRYPTION */
-
-/*
- * Print status about the connection.
- */
-/*ARGSUSED*/
-static int
-status(int argc, char *argv[])
-{
- if (connected) {
- printf("Connected to %s.\n", hostname);
- if ((argc < 2) || strcmp(argv[1], "notmuch")) {
- int mode = getconnmode();
-
- if (my_want_state_is_will(TELOPT_LINEMODE)) {
- printf("Operating with LINEMODE option\n");
- printf("%s line editing\n", (mode&MODE_EDIT) ? "Local" : "No");
- printf("%s catching of signals\n",
- (mode&MODE_TRAPSIG) ? "Local" : "No");
- slcstate();
-#ifdef KLUDGELINEMODE
- } else if (kludgelinemode && my_want_state_is_dont(TELOPT_SGA)) {
- printf("Operating in obsolete linemode\n");
-#endif
- } else {
- printf("Operating in single character mode\n");
- if (localchars)
- printf("Catching signals locally\n");
- }
- printf("%s character echo\n", (mode&MODE_ECHO) ? "Local" : "Remote");
- if (my_want_state_is_will(TELOPT_LFLOW))
- printf("%s flow control\n", (mode&MODE_FLOW) ? "Local" : "No");
-#ifdef ENCRYPTION
- encrypt_display();
-#endif /* ENCRYPTION */
- }
- } else {
- printf("No connection.\n");
- }
- printf("Escape character is '%s'.\n", control(escape));
- (void) fflush(stdout);
- return 1;
-}
-
-#ifdef SIGINFO
-/*
- * Function that gets called when SIGINFO is received.
- */
-void
-ayt_status(void)
-{
- (void) call(status, "status", "notmuch", 0);
-}
-#endif
-
-static const char *
-sockaddr_ntop(struct sockaddr *sa)
-{
- void *addr;
- static char addrbuf[INET6_ADDRSTRLEN];
-
- switch (sa->sa_family) {
- case AF_INET:
- addr = &((struct sockaddr_in *)sa)->sin_addr;
- break;
- case AF_UNIX:
- addr = &((struct sockaddr_un *)sa)->sun_path;
- break;
-#ifdef INET6
- case AF_INET6:
- addr = &((struct sockaddr_in6 *)sa)->sin6_addr;
- break;
-#endif
- default:
- return NULL;
- }
- inet_ntop(sa->sa_family, addr, addrbuf, sizeof(addrbuf));
- return addrbuf;
-}
-
-#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
-static int
-setpolicy(int lnet, struct addrinfo *res, char *policy)
-{
- char *buf;
- int level;
- int optname;
-
- if (policy == NULL)
- return 0;
-
- buf = ipsec_set_policy(policy, strlen(policy));
- if (buf == NULL) {
- printf("%s\n", ipsec_strerror());
- return -1;
- }
- level = res->ai_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
- optname = res->ai_family == AF_INET ? IP_IPSEC_POLICY : IPV6_IPSEC_POLICY;
- if (setsockopt(lnet, level, optname, buf, ipsec_get_policylen(buf)) < 0){
- perror("setsockopt");
- return -1;
- }
-
- free(buf);
- return 0;
-}
-#endif
-
-#ifdef INET6
-/*
- * When an Address Family related error happend, check if retry with
- * another AF is possible or not.
- * Return 1, if retry with another af is OK. Else, return 0.
- */
-static int
-switch_af(struct addrinfo **aip)
-{
- int nextaf;
- struct addrinfo *ai;
-
- ai = *aip;
- nextaf = (ai->ai_family == AF_INET) ? AF_INET6 : AF_INET;
- do
- ai=ai->ai_next;
- while (ai != NULL && ai->ai_family != nextaf);
- *aip = ai;
- if (*aip != NULL) {
- return 1;
- }
- return 0;
-}
-#endif
-
-int
-tn(int argc, char *argv[])
-{
- char *srp = 0;
- int proto, opt;
- int srlen;
- int srcroute = 0, result;
- char *cmd, *hostp = 0, *portp = 0, *user = 0;
- char *src_addr = NULL;
- struct addrinfo hints, *res, *res0 = NULL, *src_res, *src_res0 = NULL;
- int error = 0, af_error = 0;
-
- if (connected) {
- printf("?Already connected to %s\n", hostname);
- setuid(getuid());
- return 0;
- }
- if (argc < 2) {
- (void) strcpy(line, "open ");
- printf("(to) ");
- (void) fgets(&line[strlen(line)], sizeof(line) - strlen(line), stdin);
- makeargv();
- argc = margc;
- argv = margv;
- }
- cmd = *argv;
- --argc; ++argv;
- while (argc) {
- if (strcmp(*argv, "help") == 0 || isprefix(*argv, "?"))
- goto usage;
- if (strcmp(*argv, "-l") == 0) {
- --argc; ++argv;
- if (argc == 0)
- goto usage;
- user = *argv++;
- --argc;
- continue;
- }
- if (strcmp(*argv, "-a") == 0) {
- --argc; ++argv;
- autologin = 1;
- continue;
- }
- if (strcmp(*argv, "-s") == 0) {
- --argc; ++argv;
- if (argc == 0)
- goto usage;
- src_addr = *argv++;
- --argc;
- continue;
- }
- if (hostp == 0) {
- hostp = *argv++;
- --argc;
- continue;
- }
- if (portp == 0) {
- portp = *argv++;
- --argc;
- continue;
- }
- usage:
- printf("usage: %s [-l user] [-a] [-s src_addr] host-name [port]\n", cmd);
- setuid(getuid());
- return 0;
- }
- if (hostp == 0)
- goto usage;
-
- if (src_addr != NULL) {
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = family;
- hints.ai_socktype = SOCK_STREAM;
- error = getaddrinfo(src_addr, 0, &hints, &src_res);
- if (error == EAI_NODATA) {
- hints.ai_flags = 0;
- error = getaddrinfo(src_addr, 0, &hints, &src_res);
- }
- if (error != 0) {
- fprintf(stderr, "%s: %s\n", src_addr, gai_strerror(error));
- if (error == EAI_SYSTEM)
- fprintf(stderr, "%s: %s\n", src_addr, strerror(errno));
- setuid(getuid());
- return 0;
- }
- src_res0 = src_res;
- }
- if (hostp[0] == '/') {
- struct sockaddr_un su;
-
- if (strlen(hostp) >= sizeof(su.sun_path)) {
- fprintf(stderr, "hostname too long for unix domain socket: %s",
- hostp);
- goto fail;
- }
- memset(&su, 0, sizeof su);
- su.sun_family = AF_UNIX;
- strncpy(su.sun_path, hostp, sizeof su.sun_path);
- printf("Trying %s...\n", hostp);
- net = socket(PF_UNIX, SOCK_STREAM, 0);
- if ( net < 0) {
- perror("socket");
- goto fail;
- }
- if (connect(net, (struct sockaddr *)&su, sizeof su) == -1) {
- perror(su.sun_path);
- (void) NetClose(net);
- goto fail;
- }
- goto af_unix;
- } else if (hostp[0] == '@' || hostp[0] == '!') {
- if (
-#ifdef INET6
- family == AF_INET6 ||
-#endif
- (hostname = strrchr(hostp, ':')) == NULL)
- hostname = strrchr(hostp, '@');
- if (hostname == NULL) {
- hostname = hostp;
- } else {
- hostname++;
- srcroute = 1;
- }
- } else
- hostname = hostp;
- if (!portp) {
- telnetport = 1;
- portp = strdup("telnet");
- } else if (*portp == '-') {
- portp++;
- telnetport = 1;
- } else
- telnetport = 0;
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_flags = AI_NUMERICHOST;
- hints.ai_family = family;
- hints.ai_socktype = SOCK_STREAM;
- error = getaddrinfo(hostname, portp, &hints, &res);
- if (error) {
- hints.ai_flags = AI_CANONNAME;
- error = getaddrinfo(hostname, portp, &hints, &res);
- }
- if (error != 0) {
- fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error));
- if (error == EAI_SYSTEM)
- fprintf(stderr, "%s: %s\n", hostname, strerror(errno));
- setuid(getuid());
- goto fail;
- }
- if (hints.ai_flags == AI_NUMERICHOST) {
- /* hostname has numeric */
- int gni_err = 1;
-
- if (doaddrlookup)
- gni_err = getnameinfo(res->ai_addr, res->ai_addr->sa_len,
- _hostname, sizeof(_hostname) - 1, NULL, 0,
- NI_NAMEREQD);
- if (gni_err != 0)
- (void) strncpy(_hostname, hostp, sizeof(_hostname) - 1);
- _hostname[sizeof(_hostname)-1] = '\0';
- hostname = _hostname;
- } else {
- /* hostname has FQDN */
- if (srcroute != 0)
- (void) strncpy(_hostname, hostname, sizeof(_hostname) - 1);
- else if (res->ai_canonname != NULL)
- strcpy(_hostname, res->ai_canonname);
- else
- (void) strncpy(_hostname, hostp, sizeof(_hostname) - 1);
- _hostname[sizeof(_hostname)-1] = '\0';
- hostname = _hostname;
- }
- res0 = res;
- #ifdef INET6
- af_again:
- #endif
- if (srcroute != 0) {
- static char hostbuf[BUFSIZ];
-
- if (af_error == 0) { /* save intermediate hostnames for retry */
- strncpy(hostbuf, hostp, BUFSIZ - 1);
- hostbuf[BUFSIZ - 1] = '\0';
- } else
- hostp = hostbuf;
- srp = 0;
- result = sourceroute(res, hostp, &srp, &srlen, &proto, &opt);
- if (result == 0) {
-#ifdef INET6
- if (family == AF_UNSPEC && af_error == 0 &&
- switch_af(&res) == 1) {
- af_error = 1;
- goto af_again;
- }
-#endif
- setuid(getuid());
- goto fail;
- } else if (result == -1) {
- printf("Bad source route option: %s\n", hostp);
- setuid(getuid());
- goto fail;
- }
- }
- do {
- printf("Trying %s...\n", sockaddr_ntop(res->ai_addr));
- net = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
- setuid(getuid());
- if (net < 0) {
-#ifdef INET6
- if (family == AF_UNSPEC && af_error == 0 &&
- switch_af(&res) == 1) {
- af_error = 1;
- goto af_again;
- }
-#endif
- perror("telnet: socket");
- goto fail;
- }
- if (srp && setsockopt(net, proto, opt, (char *)srp, srlen) < 0)
- perror("setsockopt (source route)");
-#if defined(IPPROTO_IP) && defined(IP_TOS)
- if (res->ai_family == PF_INET) {
-# if defined(HAS_GETTOS)
- struct tosent *tp;
- if (tos < 0 && (tp = gettosbyname("telnet", "tcp")))
- tos = tp->t_tos;
-# endif
- if (tos < 0)
- tos = IPTOS_LOWDELAY;
- if (tos
- && (setsockopt(net, IPPROTO_IP, IP_TOS,
- (char *)&tos, sizeof(int)) < 0)
- && (errno != ENOPROTOOPT))
- perror("telnet: setsockopt (IP_TOS) (ignored)");
- }
-#endif /* defined(IPPROTO_IP) && defined(IP_TOS) */
-
- if (telnet_debug && SetSockOpt(net, SOL_SOCKET, SO_DEBUG, 1) < 0) {
- perror("setsockopt (SO_DEBUG)");
- }
-
- if (src_addr != NULL) {
- for (src_res = src_res0; src_res != 0; src_res = src_res->ai_next)
- if (src_res->ai_family == res->ai_family)
- break;
- if (src_res == NULL)
- src_res = src_res0;
- if (bind(net, src_res->ai_addr, src_res->ai_addrlen) == -1) {
-#ifdef INET6
- if (family == AF_UNSPEC && af_error == 0 &&
- switch_af(&res) == 1) {
- af_error = 1;
- (void) NetClose(net);
- goto af_again;
- }
-#endif
- perror("bind");
- (void) NetClose(net);
- goto fail;
- }
- }
-#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
- if (setpolicy(net, res, ipsec_policy_in) < 0) {
- (void) NetClose(net);
- goto fail;
- }
- if (setpolicy(net, res, ipsec_policy_out) < 0) {
- (void) NetClose(net);
- goto fail;
- }
-#endif
-
- if (connect(net, res->ai_addr, res->ai_addrlen) < 0) {
- struct addrinfo *next;
-
- next = res->ai_next;
- /* If already an af failed, only try same af. */
- if (af_error != 0)
- while (next != NULL && next->ai_family != res->ai_family)
- next = next->ai_next;
- warn("connect to address %s", sockaddr_ntop(res->ai_addr));
- if (next != NULL) {
- res = next;
- (void) NetClose(net);
- continue;
- }
- warnx("Unable to connect to remote host");
- (void) NetClose(net);
- goto fail;
- }
- connected++;
-#ifdef AUTHENTICATION
-#ifdef ENCRYPTION
- auth_encrypt_connect(connected);
-#endif
-#endif
- } while (connected == 0);
- freeaddrinfo(res0);
- if (src_res0 != NULL)
- freeaddrinfo(src_res0);
- cmdrc(hostp, hostname);
- af_unix:
- if (autologin && user == NULL) {
- struct passwd *pw;
-
- user = getenv("USER");
- if (user == NULL ||
- ((pw = getpwnam(user)) && pw->pw_uid != getuid())) {
- if ((pw = getpwuid(getuid())))
- user = pw->pw_name;
- else
- user = NULL;
- }
- }
- if (user) {
- env_define("USER", user);
- env_export("USER");
- }
- (void) call(status, "status", "notmuch", 0);
- if (setjmp(peerdied) == 0)
- telnet(user);
- (void) NetClose(net);
- ExitString("Connection closed by foreign host.\n",1);
- /*NOTREACHED*/
- fail:
- if (res0 != NULL)
- freeaddrinfo(res0);
- if (src_res0 != NULL)
- freeaddrinfo(src_res0);
- return 0;
-}
-
-#define HELPINDENT (sizeof ("connect"))
-
-static char
- openhelp[] = "connect to a site",
- closehelp[] = "close current connection",
- logouthelp[] = "forcibly logout remote user and close the connection",
- quithelp[] = "exit telnet",
- statushelp[] = "print status information",
- helphelp[] = "print help information",
- sendhelp[] = "transmit special characters ('send ?' for more)",
- sethelp[] = "set operating parameters ('set ?' for more)",
- unsethelp[] = "unset operating parameters ('unset ?' for more)",
- togglestring[] ="toggle operating parameters ('toggle ?' for more)",
- slchelp[] = "change state of special charaters ('slc ?' for more)",
- displayhelp[] = "display operating parameters",
-#ifdef AUTHENTICATION
- authhelp[] = "turn on (off) authentication ('auth ?' for more)",
-#endif
-#ifdef ENCRYPTION
- encrypthelp[] = "turn on (off) encryption ('encrypt ?' for more)",
-#endif /* ENCRYPTION */
- zhelp[] = "suspend telnet",
-#ifdef OPIE
- opiehelp[] = "compute response to OPIE challenge",
-#endif
- shellhelp[] = "invoke a subshell",
- envhelp[] = "change environment variables ('environ ?' for more)",
- modestring[] = "try to enter line or character mode ('mode ?' for more)";
-
-static Command cmdtab[] = {
- { "close", closehelp, bye, 1 },
- { "logout", logouthelp, (int (*)(int, char **))logout, 1 },
- { "display", displayhelp, display, 0 },
- { "mode", modestring, modecmd, 0 },
- { "telnet", openhelp, tn, 0 },
- { "open", openhelp, tn, 0 },
- { "quit", quithelp, (int (*)(int, char **))quit, 0 },
- { "send", sendhelp, sendcmd, 0 },
- { "set", sethelp, setcmd, 0 },
- { "unset", unsethelp, unsetcmd, 0 },
- { "status", statushelp, status, 0 },
- { "toggle", togglestring, toggle, 0 },
- { "slc", slchelp, slccmd, 0 },
-#ifdef AUTHENTICATION
- { "auth", authhelp, auth_cmd, 0 },
-#endif
-#ifdef ENCRYPTION
- { "encrypt", encrypthelp, encrypt_cmd, 0 },
-#endif /* ENCRYPTION */
- { "z", zhelp, (int (*)(int, char **))suspend, 0 },
- { "!", shellhelp, shell, 1 },
- { "environ", envhelp, env_cmd, 0 },
- { "?", helphelp, help, 0 },
-#ifdef OPIE
- { "opie", opiehelp, opie_calc, 0 },
-#endif
- { NULL, NULL, NULL, 0 }
-};
-
-static char crmodhelp[] = "deprecated command -- use 'toggle crmod' instead";
-static char escapehelp[] = "deprecated command -- use 'set escape' instead";
-
-static Command cmdtab2[] = {
- { "help", 0, help, 0 },
- { "escape", escapehelp, setescape, 0 },
- { "crmod", crmodhelp, (int (*)(int, char **))togcrmod, 0 },
- { NULL, NULL, NULL, 0 }
-};
-
-
-/*
- * Call routine with argc, argv set from args (terminated by 0).
- */
-
-static int
-call(intrtn_t routine, ...)
-{
- va_list ap;
- char *args[100];
- int argno = 0;
-
- va_start(ap, routine);
- while ((args[argno++] = va_arg(ap, char *)) != 0);
- va_end(ap);
- return (*routine)(argno-1, args);
-}
-
-
-static Command *
-getcmd(char *name)
-{
- Command *cm;
-
- if ((cm = (Command *) genget(name, (char **) cmdtab, sizeof(Command))))
- return cm;
- return (Command *) genget(name, (char **) cmdtab2, sizeof(Command));
-}
-
-void
-command(int top, const char *tbuf, int cnt)
-{
- Command *c;
-
- setcommandmode();
- if (!top) {
- putchar('\n');
- } else {
- (void) signal(SIGINT, SIG_DFL);
- (void) signal(SIGQUIT, SIG_DFL);
- }
- for (;;) {
- if (rlogin == _POSIX_VDISABLE)
- printf("%s> ", prompt);
- if (tbuf) {
- char *cp;
- cp = line;
- while (cnt > 0 && (*cp++ = *tbuf++) != '\n')
- cnt--;
- tbuf = 0;
- if (cp == line || *--cp != '\n' || cp == line)
- goto getline;
- *cp = '\0';
- if (rlogin == _POSIX_VDISABLE)
- printf("%s\n", line);
- } else {
- getline:
- if (rlogin != _POSIX_VDISABLE)
- printf("%s> ", prompt);
- if (fgets(line, sizeof(line), stdin) == NULL) {
- if (feof(stdin) || ferror(stdin)) {
- (void) quit();
- /*NOTREACHED*/
- }
- break;
- }
- }
- if (line[0] == 0)
- break;
- makeargv();
- if (margv[0] == 0) {
- break;
- }
- c = getcmd(margv[0]);
- if (Ambiguous((void *)c)) {
- printf("?Ambiguous command\n");
- continue;
- }
- if (c == 0) {
- printf("?Invalid command\n");
- continue;
- }
- if (c->needconnect && !connected) {
- printf("?Need to be connected first.\n");
- continue;
- }
- if ((*c->handler)(margc, margv)) {
- break;
- }
- }
- if (!top) {
- if (!connected) {
- longjmp(toplevel, 1);
- /*NOTREACHED*/
- }
- setconnmode(0);
- }
-}
-
-/*
- * Help command.
- */
-static int
-help(int argc, char *argv[])
-{
- Command *c;
-
- if (argc == 1) {
- printf("Commands may be abbreviated. Commands are:\n\n");
- for (c = cmdtab; c->name; c++)
- if (c->help) {
- printf("%-*s\t%s\n", (int)HELPINDENT, c->name,
- c->help);
- }
- return 0;
- }
- else while (--argc > 0) {
- char *arg;
- arg = *++argv;
- c = getcmd(arg);
- if (Ambiguous((void *)c))
- printf("?Ambiguous help command %s\n", arg);
- else if (c == (Command *)0)
- printf("?Invalid help command %s\n", arg);
- else
- printf("%s\n", c->help);
- }
- return 0;
-}
-
-static char *rcname = 0;
-static char rcbuf[128];
-
-void
-cmdrc(char *m1, char *m2)
-{
- Command *c;
- FILE *rcfile;
- int gotmachine = 0;
- int l1 = strlen(m1);
- int l2 = strlen(m2);
- char m1save[MAXHOSTNAMELEN];
-
- if (skiprc)
- return;
-
- strlcpy(m1save, m1, sizeof(m1save));
- m1 = m1save;
-
- if (rcname == 0) {
- rcname = getenv("HOME");
- if (rcname && (strlen(rcname) + 10) < sizeof(rcbuf))
- strcpy(rcbuf, rcname);
- else
- rcbuf[0] = '\0';
- strcat(rcbuf, "/.telnetrc");
- rcname = rcbuf;
- }
-
- if ((rcfile = fopen(rcname, "r")) == 0) {
- return;
- }
-
- for (;;) {
- if (fgets(line, sizeof(line), rcfile) == NULL)
- break;
- if (line[0] == 0)
- break;
- if (line[0] == '#')
- continue;
- if (gotmachine) {
- if (!isspace(line[0]))
- gotmachine = 0;
- }
- if (gotmachine == 0) {
- if (isspace(line[0]))
- continue;
- if (strncasecmp(line, m1, l1) == 0)
- strncpy(line, &line[l1], sizeof(line) - l1);
- else if (strncasecmp(line, m2, l2) == 0)
- strncpy(line, &line[l2], sizeof(line) - l2);
- else if (strncasecmp(line, "DEFAULT", 7) == 0)
- strncpy(line, &line[7], sizeof(line) - 7);
- else
- continue;
- if (line[0] != ' ' && line[0] != '\t' && line[0] != '\n')
- continue;
- gotmachine = 1;
- }
- makeargv();
- if (margv[0] == 0)
- continue;
- c = getcmd(margv[0]);
- if (Ambiguous((void *)c)) {
- printf("?Ambiguous command: %s\n", margv[0]);
- continue;
- }
- if (c == 0) {
- printf("?Invalid command: %s\n", margv[0]);
- continue;
- }
- /*
- * This should never happen...
- */
- if (c->needconnect && !connected) {
- printf("?Need to be connected first for %s.\n", margv[0]);
- continue;
- }
- (*c->handler)(margc, margv);
- }
- fclose(rcfile);
-}
-
-/*
- * Source route is handed in as
- * [!]@hop1@hop2...[@|:]dst
- * If the leading ! is present, it is a
- * strict source route, otherwise it is
- * assmed to be a loose source route.
- *
- * We fill in the source route option as
- * hop1,hop2,hop3...dest
- * and return a pointer to hop1, which will
- * be the address to connect() to.
- *
- * Arguments:
- *
- * res: ponter to addrinfo structure which contains sockaddr to
- * the host to connect to.
- *
- * arg: pointer to route list to decipher
- *
- * cpp: If *cpp is not equal to NULL, this is a
- * pointer to a pointer to a character array
- * that should be filled in with the option.
- *
- * lenp: pointer to an integer that contains the
- * length of *cpp if *cpp != NULL.
- *
- * protop: pointer to an integer that should be filled in with
- * appropriate protocol for setsockopt, as socket
- * protocol family.
- *
- * optp: pointer to an integer that should be filled in with
- * appropriate option for setsockopt, as socket protocol
- * family.
- *
- * Return values:
- *
- * If the return value is 1, then all operations are
- * successful. If the
- * return value is -1, there was a syntax error in the
- * option, either unknown characters, or too many hosts.
- * If the return value is 0, one of the hostnames in the
- * path is unknown, and *cpp is set to point to the bad
- * hostname.
- *
- * *cpp: If *cpp was equal to NULL, it will be filled
- * in with a pointer to our static area that has
- * the option filled in. This will be 32bit aligned.
- *
- * *lenp: This will be filled in with how long the option
- * pointed to by *cpp is.
- *
- * *protop: This will be filled in with appropriate protocol for
- * setsockopt, as socket protocol family.
- *
- * *optp: This will be filled in with appropriate option for
- * setsockopt, as socket protocol family.
- */
-static int
-sourceroute(struct addrinfo *ai, char *arg, char **cpp, int *lenp, int *protop, int *optp)
-{
- static char buf[1024 + ALIGNBYTES]; /*XXX*/
- char *cp, *cp2, *lsrp, *ep;
- struct sockaddr_in *_sin;
-#ifdef INET6
- struct sockaddr_in6 *sin6;
- struct cmsghdr *cmsg;
-#endif
- struct addrinfo hints, *res;
- int error;
- char c;
-
- /*
- * Verify the arguments, and make sure we have
- * at least 7 bytes for the option.
- */
- if (cpp == NULL || lenp == NULL)
- return -1;
- if (*cpp != NULL) {
- switch (res->ai_family) {
- case AF_INET:
- if (*lenp < 7)
- return -1;
- break;
-#ifdef INET6
- case AF_INET6:
- if (*lenp < (int)CMSG_SPACE(sizeof(struct ip6_rthdr) +
- sizeof(struct in6_addr)))
- return -1;
- break;
-#endif
- }
- }
- /*
- * Decide whether we have a buffer passed to us,
- * or if we need to use our own static buffer.
- */
- if (*cpp) {
- lsrp = *cpp;
- ep = lsrp + *lenp;
- } else {
- *cpp = lsrp = (char *)ALIGN(buf);
- ep = lsrp + 1024;
- }
-
- cp = arg;
-
-#ifdef INET6
- if (ai->ai_family == AF_INET6) {
- cmsg = inet6_rthdr_init(*cpp, IPV6_RTHDR_TYPE_0);
- if (*cp != '@')
- return -1;
- *protop = IPPROTO_IPV6;
- *optp = IPV6_PKTOPTIONS;
- } else
-#endif
- {
- /*
- * Next, decide whether we have a loose source
- * route or a strict source route, and fill in
- * the begining of the option.
- */
- if (*cp == '!') {
- cp++;
- *lsrp++ = IPOPT_SSRR;
- } else
- *lsrp++ = IPOPT_LSRR;
-
- if (*cp != '@')
- return -1;
-
- lsrp++; /* skip over length, we'll fill it in later */
- *lsrp++ = 4;
- *protop = IPPROTO_IP;
- *optp = IP_OPTIONS;
- }
-
- cp++;
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = ai->ai_family;
- hints.ai_socktype = SOCK_STREAM;
- for (c = 0;;) {
- if (
-#ifdef INET6
- ai->ai_family != AF_INET6 &&
-#endif
- c == ':')
- cp2 = 0;
- else for (cp2 = cp; (c = *cp2); cp2++) {
- if (c == ',') {
- *cp2++ = '\0';
- if (*cp2 == '@')
- cp2++;
- } else if (c == '@') {
- *cp2++ = '\0';
- } else if (
-#ifdef INET6
- ai->ai_family != AF_INET6 &&
-#endif
- c == ':') {
- *cp2++ = '\0';
- } else
- continue;
- break;
- }
- if (!c)
- cp2 = 0;
-
- hints.ai_flags = AI_NUMERICHOST;
- error = getaddrinfo(cp, NULL, &hints, &res);
- if (error == EAI_NODATA) {
- hints.ai_flags = 0;
- error = getaddrinfo(cp, NULL, &hints, &res);
- }
- if (error != 0) {
- fprintf(stderr, "%s: %s\n", cp, gai_strerror(error));
- if (error == EAI_SYSTEM)
- fprintf(stderr, "%s: %s\n", cp,
- strerror(errno));
- *cpp = cp;
- return(0);
- }
-#ifdef INET6
- if (res->ai_family == AF_INET6) {
- sin6 = (struct sockaddr_in6 *)res->ai_addr;
- inet6_rthdr_add(cmsg, &sin6->sin6_addr,
- IPV6_RTHDR_LOOSE);
- } else
-#endif
- {
- _sin = (struct sockaddr_in *)res->ai_addr;
- memcpy(lsrp, (char *)&_sin->sin_addr, 4);
- lsrp += 4;
- }
- if (cp2)
- cp = cp2;
- else
- break;
- /*
- * Check to make sure there is space for next address
- */
-#ifdef INET6
- if (res->ai_family == AF_INET6) {
- if (((char *)CMSG_DATA(cmsg) +
- sizeof(struct ip6_rthdr) +
- ((inet6_rthdr_segments(cmsg) + 1) *
- sizeof(struct in6_addr))) > ep)
- return -1;
- } else
-#endif
- if (lsrp + 4 > ep)
- return -1;
- freeaddrinfo(res);
- }
-#ifdef INET6
- if (res->ai_family == AF_INET6) {
- inet6_rthdr_lasthop(cmsg, IPV6_RTHDR_LOOSE);
- *lenp = cmsg->cmsg_len;
- } else
-#endif
- {
- if ((*(*cpp+IPOPT_OLEN) = lsrp - *cpp) <= 7) {
- *cpp = 0;
- *lenp = 0;
- return -1;
- }
- *lsrp++ = IPOPT_NOP; /* 32 bit word align it */
- *lenp = lsrp - *cpp;
- }
- freeaddrinfo(res);
- return 1;
-}
diff --git a/contrib/telnet/telnet/defines.h b/contrib/telnet/telnet/defines.h
deleted file mode 100644
index 840666deacb6..000000000000
--- a/contrib/telnet/telnet/defines.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)defines.h 8.1 (Berkeley) 6/6/93
- * $FreeBSD$
- */
-
-#define settimer(x) clocks.x = clocks.system++
-
-#define NETADD(c) { *netoring.supply = c; ring_supplied(&netoring, 1); }
-#define NET2ADD(c1,c2) { NETADD(c1); NETADD(c2); }
-#define NETBYTES() (ring_full_count(&netoring))
-#define NETROOM() (ring_empty_count(&netoring))
-
-#define TTYADD(c) if (!(SYNCHing||flushout)) { \
- *ttyoring.supply = c; \
- ring_supplied(&ttyoring, 1); \
- }
-#define TTYBYTES() (ring_full_count(&ttyoring))
-#define TTYROOM() (ring_empty_count(&ttyoring))
-
-/* Various modes */
-#define MODE_LOCAL_CHARS(m) ((m)&(MODE_EDIT|MODE_TRAPSIG))
-#define MODE_LOCAL_ECHO(m) ((m)&MODE_ECHO)
-#define MODE_COMMAND_LINE(m) ((m)==-1)
-
-#define CONTROL(x) ((x)&0x1f) /* CTRL(x) is not portable */
diff --git a/contrib/telnet/telnet/externs.h b/contrib/telnet/telnet/externs.h
deleted file mode 100644
index e9be27e1634f..000000000000
--- a/contrib/telnet/telnet/externs.h
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- * Copyright (c) 1988, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)externs.h 8.3 (Berkeley) 5/30/95
- * $FreeBSD$
- */
-
-#ifndef BSD
-# define BSD 43
-#endif
-
-/*
- * ucb stdio.h defines BSD as something weird
- */
-#if defined(sun) && defined(__svr4__)
-#define BSD 43
-#endif
-
-#ifndef USE_TERMIO
-# if BSD > 43 || defined(SYSV_TERMIO)
-# define USE_TERMIO
-# endif
-#endif
-
-#include <stdio.h>
-#include <setjmp.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#ifdef USE_TERMIO
-# ifndef VINTR
-# include <sys/termios.h>
-# endif
-# define termio termios
-#endif
-#if defined(NO_CC_T) || !defined(USE_TERMIO)
-# if !defined(USE_TERMIO)
-typedef char cc_t;
-# else
-typedef unsigned char cc_t;
-# endif
-#endif
-
-#include <string.h>
-
-#if defined(IPSEC)
-#include <netinet6/ipsec.h>
-#if defined(IPSEC_POLICY_IPSEC)
-extern char *ipsec_policy_in;
-extern char *ipsec_policy_out;
-#endif
-#endif
-
-#ifndef _POSIX_VDISABLE
-# ifdef sun
-# include <sys/param.h> /* pick up VDISABLE definition, mayby */
-# endif
-# ifdef VDISABLE
-# define _POSIX_VDISABLE VDISABLE
-# else
-# define _POSIX_VDISABLE ((cc_t)'\377')
-# endif
-#endif
-
-#define SUBBUFSIZE 256
-
-#if !defined(P)
-# ifdef __STDC__
-# define P(x) x
-# else
-# define P(x) ()
-# endif
-#endif
-
-extern int
- autologin, /* Autologin enabled */
- skiprc, /* Don't process the ~/.telnetrc file */
- eight, /* use eight bit mode (binary in and/or out */
- family, /* address family of peer */
- flushout, /* flush output */
- connected, /* Are we connected to the other side? */
- globalmode, /* Mode tty should be in */
- telnetport, /* Are we connected to the telnet port? */
- localflow, /* Flow control handled locally */
- restartany, /* If flow control, restart output on any character */
- localchars, /* we recognize interrupt/quit */
- donelclchars, /* the user has set "localchars" */
- showoptions,
- net, /* Network file descriptor */
- tin, /* Terminal input file descriptor */
- tout, /* Terminal output file descriptor */
- crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
- autoflush, /* flush output when interrupting? */
- autosynch, /* send interrupt characters with SYNCH? */
- SYNCHing, /* Is the stream in telnet SYNCH mode? */
- donebinarytoggle, /* the user has put us in binary */
- dontlecho, /* do we suppress local echoing right now? */
- crmod,
- netdata, /* Print out network data flow */
- prettydump, /* Print "netdata" output in user readable format */
- termdata, /* Print out terminal data flow */
- telnet_debug, /* Debug level */
- doaddrlookup, /* do a reverse lookup? */
- clienteof; /* Client received EOF */
-
-extern cc_t escape; /* Escape to command mode */
-extern cc_t rlogin; /* Rlogin mode escape character */
-#ifdef KLUDGELINEMODE
-extern cc_t echoc; /* Toggle local echoing */
-#endif
-
-extern char
- *prompt; /* Prompt for command. */
-
-extern char
- doopt[],
- dont[],
- will[],
- wont[],
- options[], /* All the little options */
- *hostname; /* Who are we connected to? */
-#ifdef ENCRYPTION
-extern void (*encrypt_output)(unsigned char *, int);
-extern int (*decrypt_input)(int);
-#endif /* ENCRYPTION */
-
-/*
- * We keep track of each side of the option negotiation.
- */
-
-#define MY_STATE_WILL 0x01
-#define MY_WANT_STATE_WILL 0x02
-#define MY_STATE_DO 0x04
-#define MY_WANT_STATE_DO 0x08
-
-/*
- * Macros to check the current state of things
- */
-
-#define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
-#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
-#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
-#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
-
-#define my_state_is_dont(opt) (!my_state_is_do(opt))
-#define my_state_is_wont(opt) (!my_state_is_will(opt))
-#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
-#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
-
-#define set_my_state_do(opt) {options[opt] |= MY_STATE_DO;}
-#define set_my_state_will(opt) {options[opt] |= MY_STATE_WILL;}
-#define set_my_want_state_do(opt) {options[opt] |= MY_WANT_STATE_DO;}
-#define set_my_want_state_will(opt) {options[opt] |= MY_WANT_STATE_WILL;}
-
-#define set_my_state_dont(opt) {options[opt] &= ~MY_STATE_DO;}
-#define set_my_state_wont(opt) {options[opt] &= ~MY_STATE_WILL;}
-#define set_my_want_state_dont(opt) {options[opt] &= ~MY_WANT_STATE_DO;}
-#define set_my_want_state_wont(opt) {options[opt] &= ~MY_WANT_STATE_WILL;}
-
-/*
- * Make everything symetrical
- */
-
-#define HIS_STATE_WILL MY_STATE_DO
-#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
-#define HIS_STATE_DO MY_STATE_WILL
-#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
-
-#define his_state_is_do my_state_is_will
-#define his_state_is_will my_state_is_do
-#define his_want_state_is_do my_want_state_is_will
-#define his_want_state_is_will my_want_state_is_do
-
-#define his_state_is_dont my_state_is_wont
-#define his_state_is_wont my_state_is_dont
-#define his_want_state_is_dont my_want_state_is_wont
-#define his_want_state_is_wont my_want_state_is_dont
-
-#define set_his_state_do set_my_state_will
-#define set_his_state_will set_my_state_do
-#define set_his_want_state_do set_my_want_state_will
-#define set_his_want_state_will set_my_want_state_do
-
-#define set_his_state_dont set_my_state_wont
-#define set_his_state_wont set_my_state_dont
-#define set_his_want_state_dont set_my_want_state_wont
-#define set_his_want_state_wont set_my_want_state_dont
-
-#if defined(USE_TERMIO)
-#define SIG_FUNC_RET void
-#else
-#define SIG_FUNC_RET int
-#endif
-
-#ifdef SIGINFO
-extern SIG_FUNC_RET
- ayt_status(void);
-#endif
-
-extern FILE
- *NetTrace; /* Where debugging output goes */
-extern unsigned char
- NetTraceFile[]; /* Name of file where debugging output goes */
-extern void
- SetNetTrace(char *); /* Function to change where debugging goes */
-
-extern jmp_buf
- peerdied,
- toplevel; /* For error conditions. */
-
-extern void
- command(int, const char *, int),
- Dump(char, unsigned char *, int),
- env_init(void),
- Exit(int),
- ExitString(const char *, int),
- init_network(void),
- init_sys(void),
- init_telnet(void),
- init_terminal(void),
- intp(void),
- optionstatus(void),
- printoption(const char *, int, int),
- printsub(char, unsigned char *, int),
- quit(void),
- sendabort(void),
- sendbrk(void),
- sendeof(void),
- sendsusp(void),
- sendnaws(void),
- sendayt(void),
- setconnmode(int),
- setcommandmode(void),
- set_escape_char(char *s),
- setneturg(void),
- sys_telnet_init(void),
- telnet(char *),
- tel_enter_binary(int),
- tel_leave_binary(int),
- TerminalFlushOutput(void),
- TerminalNewMode(int),
- TerminalRestoreState(void),
- TerminalSaveState(void),
- TerminalDefaultChars(void),
- TerminalSpeeds(long *, long *),
- tninit(void),
- upcase(char *),
- willoption(int),
- wontoption(int);
-
-extern void
- send_do(int, int),
- send_dont(int, int),
- send_will(int, int),
- send_wont(int, int);
-
-extern void
- lm_will(unsigned char *, int),
- lm_wont(unsigned char *, int),
- lm_do(unsigned char *, int),
- lm_dont(unsigned char *, int),
- lm_mode(unsigned char *, int, int);
-
-extern void
- slc_init(void),
- slcstate(void),
- slc_mode_export(void),
- slc_mode_import(int),
- slc_import(int),
- slc_export(void),
- slc(unsigned char *, int),
- slc_check(void),
- slc_start_reply(void),
- slc_add_reply(unsigned char, unsigned char, cc_t),
- slc_end_reply(void);
-extern int
- getconnmode(void),
- opt_welldefined(const char *),
- NetClose(int),
- netflush(void),
- process_rings(int, int, int, int, int, int),
- rlogin_susp(void),
- SetSockOpt(int, int, int, int),
- slc_update(void),
- stilloob(void),
- telrcv(void),
- TerminalRead(char *, int),
- TerminalWrite(char *, int),
- TerminalAutoFlush(void),
- TerminalWindowSize(long *, long *),
- TerminalSpecialChars(int),
- tn(int, char **),
- ttyflush(int);
-
-extern void
- env_opt(unsigned char *, int),
- env_opt_start(void),
- env_opt_start_info(void),
- env_opt_add(unsigned char *),
- env_opt_end(int);
-
-extern unsigned char
- *env_default(int, int),
- *env_getvalue(const unsigned char *);
-
-extern int
- get_status(char *),
- dosynch(char *);
-
-extern cc_t
- *tcval(int);
-
-#ifndef USE_TERMIO
-
-extern struct tchars ntc;
-extern struct ltchars nltc;
-extern struct sgttyb nttyb;
-
-# define termEofChar ntc.t_eofc
-# define termEraseChar nttyb.sg_erase
-# define termFlushChar nltc.t_flushc
-# define termIntChar ntc.t_intrc
-# define termKillChar nttyb.sg_kill
-# define termLiteralNextChar nltc.t_lnextc
-# define termQuitChar ntc.t_quitc
-# define termSuspChar nltc.t_suspc
-# define termRprntChar nltc.t_rprntc
-# define termWerasChar nltc.t_werasc
-# define termStartChar ntc.t_startc
-# define termStopChar ntc.t_stopc
-# define termForw1Char ntc.t_brkc
-extern cc_t termForw2Char;
-extern cc_t termAytChar;
-
-# define termEofCharp (cc_t *)&ntc.t_eofc
-# define termEraseCharp (cc_t *)&nttyb.sg_erase
-# define termFlushCharp (cc_t *)&nltc.t_flushc
-# define termIntCharp (cc_t *)&ntc.t_intrc
-# define termKillCharp (cc_t *)&nttyb.sg_kill
-# define termLiteralNextCharp (cc_t *)&nltc.t_lnextc
-# define termQuitCharp (cc_t *)&ntc.t_quitc
-# define termSuspCharp (cc_t *)&nltc.t_suspc
-# define termRprntCharp (cc_t *)&nltc.t_rprntc
-# define termWerasCharp (cc_t *)&nltc.t_werasc
-# define termStartCharp (cc_t *)&ntc.t_startc
-# define termStopCharp (cc_t *)&ntc.t_stopc
-# define termForw1Charp (cc_t *)&ntc.t_brkc
-# define termForw2Charp (cc_t *)&termForw2Char
-# define termAytCharp (cc_t *)&termAytChar
-
-# else
-
-extern struct termio new_tc;
-
-# define termEofChar new_tc.c_cc[VEOF]
-# define termEraseChar new_tc.c_cc[VERASE]
-# define termIntChar new_tc.c_cc[VINTR]
-# define termKillChar new_tc.c_cc[VKILL]
-# define termQuitChar new_tc.c_cc[VQUIT]
-
-# ifndef VSUSP
-extern cc_t termSuspChar;
-# else
-# define termSuspChar new_tc.c_cc[VSUSP]
-# endif
-# if defined(VFLUSHO) && !defined(VDISCARD)
-# define VDISCARD VFLUSHO
-# endif
-# ifndef VDISCARD
-extern cc_t termFlushChar;
-# else
-# define termFlushChar new_tc.c_cc[VDISCARD]
-# endif
-# ifndef VWERASE
-extern cc_t termWerasChar;
-# else
-# define termWerasChar new_tc.c_cc[VWERASE]
-# endif
-# ifndef VREPRINT
-extern cc_t termRprntChar;
-# else
-# define termRprntChar new_tc.c_cc[VREPRINT]
-# endif
-# ifndef VLNEXT
-extern cc_t termLiteralNextChar;
-# else
-# define termLiteralNextChar new_tc.c_cc[VLNEXT]
-# endif
-# ifndef VSTART
-extern cc_t termStartChar;
-# else
-# define termStartChar new_tc.c_cc[VSTART]
-# endif
-# ifndef VSTOP
-extern cc_t termStopChar;
-# else
-# define termStopChar new_tc.c_cc[VSTOP]
-# endif
-# ifndef VEOL
-extern cc_t termForw1Char;
-# else
-# define termForw1Char new_tc.c_cc[VEOL]
-# endif
-# ifndef VEOL2
-extern cc_t termForw2Char;
-# else
-# define termForw2Char new_tc.c_cc[VEOL]
-# endif
-# ifndef VSTATUS
-extern cc_t termAytChar;
-#else
-# define termAytChar new_tc.c_cc[VSTATUS]
-#endif
-
-# if defined(__STDC__)
-# define termEofCharp &termEofChar
-# define termEraseCharp &termEraseChar
-# define termIntCharp &termIntChar
-# define termKillCharp &termKillChar
-# define termQuitCharp &termQuitChar
-# define termSuspCharp &termSuspChar
-# define termFlushCharp &termFlushChar
-# define termWerasCharp &termWerasChar
-# define termRprntCharp &termRprntChar
-# define termLiteralNextCharp &termLiteralNextChar
-# define termStartCharp &termStartChar
-# define termStopCharp &termStopChar
-# define termForw1Charp &termForw1Char
-# define termForw2Charp &termForw2Char
-# define termAytCharp &termAytChar
-# else
- /* Work around a compiler bug */
-# define termEofCharp 0
-# define termEraseCharp 0
-# define termIntCharp 0
-# define termKillCharp 0
-# define termQuitCharp 0
-# define termSuspCharp 0
-# define termFlushCharp 0
-# define termWerasCharp 0
-# define termRprntCharp 0
-# define termLiteralNextCharp 0
-# define termStartCharp 0
-# define termStopCharp 0
-# define termForw1Charp 0
-# define termForw2Charp 0
-# define termAytCharp 0
-# endif
-#endif
-
-
-/* Ring buffer structures which are shared */
-
-extern Ring
- netoring,
- netiring,
- ttyoring,
- ttyiring;
-
-extern void
- xmitAO(void),
- xmitEC(void),
- xmitEL(void);
diff --git a/contrib/telnet/telnet/fdset.h b/contrib/telnet/telnet/fdset.h
deleted file mode 100644
index 045bb7221419..000000000000
--- a/contrib/telnet/telnet/fdset.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)fdset.h 8.1 (Berkeley) 6/6/93
- */
-
-/*
- * The following is defined just in case someone should want to run
- * this telnet on a 4.2 system.
- *
- */
-
-#ifndef FD_SETSIZE
-
-#define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n)))
-#define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n)))
-#define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n)))
-#define FD_ZERO(p) ((p)->fds_bits[0] = 0)
-
-#endif
diff --git a/contrib/telnet/telnet/general.h b/contrib/telnet/telnet/general.h
deleted file mode 100644
index 4efa9519469e..000000000000
--- a/contrib/telnet/telnet/general.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)general.h 8.1 (Berkeley) 6/6/93
- */
-
-/*
- * Some general definitions.
- */
-
-
-#define numberof(x) (sizeof x/sizeof x[0])
-#define highestof(x) (numberof(x)-1)
-
-#define ClearElement(x) memset((char *)&x, 0, sizeof x)
-#define ClearArray(x) memset((char *)x, 0, sizeof x)
diff --git a/contrib/telnet/telnet/main.c b/contrib/telnet/telnet/main.c
deleted file mode 100644
index e3fe643ebc7f..000000000000
--- a/contrib/telnet/telnet/main.c
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * Copyright (c) 1988, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "ring.h"
-#include "externs.h"
-#include "defines.h"
-
-#ifdef AUTHENTICATION
-#include <libtelnet/auth.h>
-#endif
-#ifdef ENCRYPTION
-#include <libtelnet/encrypt.h>
-#endif
-
-/* These values need to be the same as defined in libtelnet/kerberos5.c */
-/* Either define them in both places, or put in some common header file. */
-#define OPTS_FORWARD_CREDS 0x00000002
-#define OPTS_FORWARDABLE_CREDS 0x00000001
-
-#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
-char *ipsec_policy_in = NULL;
-char *ipsec_policy_out = NULL;
-#endif
-
-int family = AF_UNSPEC;
-
-/*
- * Initialize variables.
- */
-void
-tninit(void)
-{
- init_terminal();
-
- init_network();
-
- init_telnet();
-
- init_sys();
-}
-
-static void
-usage(void)
-{
- fprintf(stderr, "usage: %s %s%s%s%s\n",
- prompt,
-#ifdef AUTHENTICATION
- "[-4] [-6] [-8] [-E] [-K] [-L] [-N] [-S tos] [-X atype] [-c] [-d]",
- "\n\t[-e char] [-k realm] [-l user] [-f/-F] [-n tracefile] ",
-#else
- "[-4] [-6] [-8] [-E] [-L] [-N] [-S tos] [-c] [-d]",
- "\n\t[-e char] [-l user] [-n tracefile] ",
-#endif
- "[-r] [-s src_addr] [-u] ",
-#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
- "[-P policy] "
-#endif
-#ifdef ENCRYPTION
- "[-y] [host-name [port]]"
-#else /* ENCRYPTION */
- "[host-name [port]]"
-#endif /* ENCRYPTION */
- );
- exit(1);
-}
-
-/*
- * main. Parse arguments, invoke the protocol or command parser.
- */
-
-int
-main(int argc, char *argv[])
-{
- int ch;
- char *user;
- char *src_addr = NULL;
-#ifdef FORWARD
- extern int forward_flags;
-#endif /* FORWARD */
-
- tninit(); /* Clear out things */
-
- TerminalSaveState();
-
- if ((prompt = strrchr(argv[0], '/')))
- ++prompt;
- else
- prompt = argv[0];
-
- user = NULL;
-
- rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
-#ifdef AUTHENTICATION
- autologin = 1;
-#else
- autologin = -1;
-#endif
-
-#ifdef ENCRYPTION
- encrypt_auto(1);
- decrypt_auto(1);
-#endif
-
-#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
-#define IPSECOPT "P:"
-#else
-#define IPSECOPT
-#endif
- while ((ch = getopt(argc, argv,
- "468EKLNS:X:acde:fFk:l:n:rs:t:uxy" IPSECOPT)) != -1)
-#undef IPSECOPT
- {
- switch(ch) {
- case '4':
- family = AF_INET;
- break;
-#ifdef INET6
- case '6':
- family = AF_INET6;
- break;
-#endif
- case '8':
- eight = 3; /* binary output and input */
- break;
- case 'E':
- rlogin = escape = _POSIX_VDISABLE;
- break;
- case 'K':
-#ifdef AUTHENTICATION
- autologin = 0;
-#endif
- break;
- case 'L':
- eight |= 2; /* binary output only */
- break;
- case 'N':
- doaddrlookup = 0;
- break;
- case 'S':
- {
-#ifdef HAS_GETTOS
- extern int tos;
-
- if ((tos = parsetos(optarg, "tcp")) < 0)
- fprintf(stderr, "%s%s%s%s\n",
- prompt, ": Bad TOS argument '",
- optarg,
- "; will try to use default TOS");
-#else
- fprintf(stderr,
- "%s: Warning: -S ignored, no parsetos() support.\n",
- prompt);
-#endif
- }
- break;
- case 'X':
-#ifdef AUTHENTICATION
- auth_disable_name(optarg);
-#endif
- break;
- case 'a':
-#ifdef AUTHENTICATION
- /* It's the default now, so ignore */
-#else
- autologin = 1;
-#endif
- break;
- case 'c':
- skiprc = 1;
- break;
- case 'd':
- telnet_debug = 1;
- break;
- case 'e':
- set_escape_char(optarg);
- break;
- case 'f':
-#ifdef AUTHENTICATION
-#if defined(KRB5) && defined(FORWARD)
- if (forward_flags & OPTS_FORWARD_CREDS) {
- fprintf(stderr,
- "%s: Only one of -f and -F allowed.\n",
- prompt);
- usage();
- }
- forward_flags |= OPTS_FORWARD_CREDS;
-#else
- fprintf(stderr,
- "%s: Warning: -f ignored, no Kerberos V5 support.\n",
- prompt);
-#endif
-#else
- fprintf(stderr,
- "%s: Warning: -f ignored, no Kerberos V5 support.\n",
- prompt);
-#endif
- break;
- case 'F':
-#ifdef AUTHENTICATION
-#if defined(KRB5) && defined(FORWARD)
- if (forward_flags & OPTS_FORWARD_CREDS) {
- fprintf(stderr,
- "%s: Only one of -f and -F allowed.\n",
- prompt);
- usage();
- }
- forward_flags |= OPTS_FORWARD_CREDS;
- forward_flags |= OPTS_FORWARDABLE_CREDS;
-#else
- fprintf(stderr,
- "%s: Warning: -F ignored, no Kerberos V5 support.\n",
- prompt);
-#endif
-#else
- fprintf(stderr,
- "%s: Warning: -F ignored, no Kerberos V5 support.\n",
- prompt);
-#endif
- break;
- case 'k':
-#ifdef AUTHENTICATION
-#if defined(KRB4)
- {
- extern char *dest_realm, dst_realm_buf[], dst_realm_sz;
- dest_realm = dst_realm_buf;
- (void)strncpy(dest_realm, optarg, dst_realm_sz);
- }
-#else
- fprintf(stderr,
- "%s: Warning: -k ignored, no Kerberos V4 support.\n",
- prompt);
-#endif
-#else
- fprintf(stderr,
- "%s: Warning: -k ignored, no Kerberos V4 support.\n",
- prompt);
-#endif
- break;
- case 'l':
-#ifdef AUTHENTICATION
- /* This is the default now, so ignore it */
-#else
- autologin = 1;
-#endif
- user = optarg;
- break;
- case 'n':
- SetNetTrace(optarg);
- break;
- case 'r':
- rlogin = '~';
- break;
- case 's':
- src_addr = optarg;
- break;
- case 'u':
- family = AF_UNIX;
- break;
- case 'x':
-#ifndef ENCRYPTION
- fprintf(stderr,
- "%s: Warning: -x ignored, no ENCRYPT support.\n",
- prompt);
-#endif /* ENCRYPTION */
- break;
- case 'y':
-#ifdef ENCRYPTION
- encrypt_auto(0);
- decrypt_auto(0);
-#else
- fprintf(stderr,
- "%s: Warning: -y ignored, no ENCRYPT support.\n",
- prompt);
-#endif /* ENCRYPTION */
- break;
-#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
- case 'P':
- if (!strncmp("in", optarg, 2))
- ipsec_policy_in = strdup(optarg);
- else if (!strncmp("out", optarg, 3))
- ipsec_policy_out = strdup(optarg);
- else
- usage();
- break;
-#endif
- case '?':
- default:
- usage();
- /* NOTREACHED */
- }
- }
- if (autologin == -1)
- autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
-
- argc -= optind;
- argv += optind;
-
- if (argc) {
- char *args[9], **argp = args;
-
- if (argc > 2)
- usage();
- *argp++ = prompt;
- if (user) {
- *argp++ = strdup("-l");
- *argp++ = user;
- }
- if (src_addr) {
- *argp++ = strdup("-s");
- *argp++ = src_addr;
- }
- *argp++ = argv[0]; /* host */
- if (argc > 1)
- *argp++ = argv[1]; /* port */
- *argp = 0;
-
- if (setjmp(toplevel) != 0)
- Exit(0);
- if (tn(argp - args, args) == 1)
- return (0);
- else
- return (1);
- }
- (void)setjmp(toplevel);
- for (;;) {
- command(1, 0, 0);
- }
- return 0;
-}
diff --git a/contrib/telnet/telnet/network.c b/contrib/telnet/telnet/network.c
deleted file mode 100644
index bb75d6309f90..000000000000
--- a/contrib/telnet/telnet/network.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)network.c 8.2 (Berkeley) 12/15/93";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-
-#include <errno.h>
-#include <stdlib.h>
-
-#include <arpa/telnet.h>
-#include <unistd.h>
-
-#include "ring.h"
-
-#include "defines.h"
-#include "externs.h"
-#include "fdset.h"
-
-Ring netoring, netiring;
-unsigned char netobuf[2*BUFSIZ], netibuf[BUFSIZ];
-
-/*
- * Initialize internal network data structures.
- */
-
-void
-init_network(void)
-{
- if (ring_init(&netoring, netobuf, sizeof netobuf) != 1) {
- exit(1);
- }
- if (ring_init(&netiring, netibuf, sizeof netibuf) != 1) {
- exit(1);
- }
- NetTrace = stdout;
-}
-
-
-/*
- * Check to see if any out-of-band data exists on a socket (for
- * Telnet "synch" processing).
- */
-
-int
-stilloob(void)
-{
- static struct timeval timeout = { 0, 0 };
- fd_set excepts;
- int value;
-
- do {
- FD_ZERO(&excepts);
- FD_SET(net, &excepts);
- value = select(net+1, (fd_set *)0, (fd_set *)0, &excepts, &timeout);
- } while ((value == -1) && (errno == EINTR));
-
- if (value < 0) {
- perror("select");
- (void) quit();
- /* NOTREACHED */
- }
- if (FD_ISSET(net, &excepts)) {
- return 1;
- } else {
- return 0;
- }
-}
-
-
-/*
- * setneturg()
- *
- * Sets "neturg" to the current location.
- */
-
-void
-setneturg(void)
-{
- ring_mark(&netoring);
-}
-
-
-/*
- * netflush
- * Send as much data as possible to the network,
- * handling requests for urgent data.
- *
- * The return value indicates whether we did any
- * useful work.
- */
-
-int
-netflush(void)
-{
- int n, n1;
-
-#ifdef ENCRYPTION
- if (encrypt_output)
- ring_encrypt(&netoring, encrypt_output);
-#endif /* ENCRYPTION */
- if ((n1 = n = ring_full_consecutive(&netoring)) > 0) {
- if (!ring_at_mark(&netoring)) {
- n = send(net, (char *)netoring.consume, n, 0); /* normal write */
- } else {
- /*
- * In 4.2 (and 4.3) systems, there is some question about
- * what byte in a sendOOB operation is the "OOB" data.
- * To make ourselves compatible, we only send ONE byte
- * out of band, the one WE THINK should be OOB (though
- * we really have more the TCP philosophy of urgent data
- * rather than the Unix philosophy of OOB data).
- */
- n = send(net, (char *)netoring.consume, 1, MSG_OOB);/* URGENT data */
- }
- }
- if (n < 0) {
- if (errno != ENOBUFS && errno != EWOULDBLOCK) {
- setcommandmode();
- perror(hostname);
- (void)NetClose(net);
- ring_clear_mark(&netoring);
- longjmp(peerdied, -1);
- /*NOTREACHED*/
- }
- n = 0;
- }
- if (netdata && n) {
- Dump('>', netoring.consume, n);
- }
- if (n) {
- ring_consumed(&netoring, n);
- /*
- * If we sent all, and more to send, then recurse to pick
- * up the other half.
- */
- if ((n1 == n) && ring_full_consecutive(&netoring)) {
- (void) netflush();
- }
- return 1;
- } else {
- return 0;
- }
-}
diff --git a/contrib/telnet/telnet/ring.c b/contrib/telnet/telnet/ring.c
deleted file mode 100644
index 6c2b7efc5a51..000000000000
--- a/contrib/telnet/telnet/ring.c
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)ring.c 8.2 (Berkeley) 5/30/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * This defines a structure for a ring buffer.
- *
- * The circular buffer has two parts:
- *(((
- * full: [consume, supply)
- * empty: [supply, consume)
- *]]]
- *
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifdef size_t
-#undef size_t
-#endif
-
-#include <sys/types.h>
-#ifndef FILIO_H
-#include <sys/ioctl.h>
-#endif
-#include <sys/socket.h>
-
-#include "ring.h"
-#include "general.h"
-
-/* Internal macros */
-
-#if !defined(MIN)
-#define MIN(a,b) (((a)<(b))? (a):(b))
-#endif /* !defined(MIN) */
-
-#define ring_subtract(d,a,b) (((a)-(b) >= 0)? \
- (a)-(b): (((a)-(b))+(d)->size))
-
-#define ring_increment(d,a,c) (((a)+(c) < (d)->top)? \
- (a)+(c) : (((a)+(c))-(d)->size))
-
-#define ring_decrement(d,a,c) (((a)-(c) >= (d)->bottom)? \
- (a)-(c) : (((a)-(c))-(d)->size))
-
-
-/*
- * The following is a clock, used to determine full, empty, etc.
- *
- * There is some trickiness here. Since the ring buffers are initialized
- * to ZERO on allocation, we need to make sure, when interpreting the
- * clock, that when the times are EQUAL, then the buffer is FULL.
- */
-static u_long ring_clock = 0;
-
-
-#define ring_empty(d) (((d)->consume == (d)->supply) && \
- ((d)->consumetime >= (d)->supplytime))
-#define ring_full(d) (((d)->supply == (d)->consume) && \
- ((d)->supplytime > (d)->consumetime))
-
-/* Buffer state transition routines */
-
-int
-ring_init(Ring *ring, unsigned char *buffer, int count)
-{
- memset((char *)ring, 0, sizeof *ring);
-
- ring->size = count;
-
- ring->supply = ring->consume = ring->bottom = buffer;
-
- ring->top = ring->bottom+ring->size;
-
-#ifdef ENCRYPTION
- ring->clearto = 0;
-#endif /* ENCRYPTION */
-
- return 1;
-}
-
-/* Mark routines */
-
-/*
- * Mark the most recently supplied byte.
- */
-
-void
-ring_mark(Ring *ring)
-{
- ring->mark = ring_decrement(ring, ring->supply, 1);
-}
-
-/*
- * Is the ring pointing to the mark?
- */
-
-int
-ring_at_mark(Ring *ring)
-{
- if (ring->mark == ring->consume) {
- return 1;
- } else {
- return 0;
- }
-}
-
-/*
- * Clear any mark set on the ring.
- */
-
-void
-ring_clear_mark(Ring *ring)
-{
- ring->mark = 0;
-}
-
-/*
- * Add characters from current segment to ring buffer.
- */
-void
-ring_supplied(Ring *ring, int count)
-{
- ring->supply = ring_increment(ring, ring->supply, count);
- ring->supplytime = ++ring_clock;
-}
-
-/*
- * We have just consumed "c" bytes.
- */
-void
-ring_consumed(Ring *ring, int count)
-{
- if (count == 0) /* don't update anything */
- return;
-
- if (ring->mark &&
- (ring_subtract(ring, ring->mark, ring->consume) < count)) {
- ring->mark = 0;
- }
-#ifdef ENCRYPTION
- if (ring->consume < ring->clearto &&
- ring->clearto <= ring->consume + count)
- ring->clearto = 0;
- else if (ring->consume + count > ring->top &&
- ring->bottom <= ring->clearto &&
- ring->bottom + ((ring->consume + count) - ring->top))
- ring->clearto = 0;
-#endif /* ENCRYPTION */
- ring->consume = ring_increment(ring, ring->consume, count);
- ring->consumetime = ++ring_clock;
- /*
- * Try to encourage "ring_empty_consecutive()" to be large.
- */
- if (ring_empty(ring)) {
- ring->consume = ring->supply = ring->bottom;
- }
-}
-
-
-
-/* Buffer state query routines */
-
-
-/* Number of bytes that may be supplied */
-int
-ring_empty_count(Ring *ring)
-{
- if (ring_empty(ring)) { /* if empty */
- return ring->size;
- } else {
- return ring_subtract(ring, ring->consume, ring->supply);
- }
-}
-
-/* number of CONSECUTIVE bytes that may be supplied */
-int
-ring_empty_consecutive(Ring *ring)
-{
- if ((ring->consume < ring->supply) || ring_empty(ring)) {
- /*
- * if consume is "below" supply, or empty, then
- * return distance to the top
- */
- return ring_subtract(ring, ring->top, ring->supply);
- } else {
- /*
- * else, return what we may.
- */
- return ring_subtract(ring, ring->consume, ring->supply);
- }
-}
-
-/* Return the number of bytes that are available for consuming
- * (but don't give more than enough to get to cross over set mark)
- */
-
-int
-ring_full_count(Ring *ring)
-{
- if ((ring->mark == 0) || (ring->mark == ring->consume)) {
- if (ring_full(ring)) {
- return ring->size; /* nothing consumed, but full */
- } else {
- return ring_subtract(ring, ring->supply, ring->consume);
- }
- } else {
- return ring_subtract(ring, ring->mark, ring->consume);
- }
-}
-
-/*
- * Return the number of CONSECUTIVE bytes available for consuming.
- * However, don't return more than enough to cross over set mark.
- */
-int
-ring_full_consecutive(Ring *ring)
-{
- if ((ring->mark == 0) || (ring->mark == ring->consume)) {
- if ((ring->supply < ring->consume) || ring_full(ring)) {
- return ring_subtract(ring, ring->top, ring->consume);
- } else {
- return ring_subtract(ring, ring->supply, ring->consume);
- }
- } else {
- if (ring->mark < ring->consume) {
- return ring_subtract(ring, ring->top, ring->consume);
- } else { /* Else, distance to mark */
- return ring_subtract(ring, ring->mark, ring->consume);
- }
- }
-}
-
-/*
- * Move data into the "supply" portion of of the ring buffer.
- */
-void
-ring_supply_data(Ring *ring, unsigned char *buffer, int count)
-{
- int i;
-
- while (count) {
- i = MIN(count, ring_empty_consecutive(ring));
- memcpy(ring->supply, buffer, i);
- ring_supplied(ring, i);
- count -= i;
- buffer += i;
- }
-}
-
-#ifdef ENCRYPTION
-void
-ring_encrypt(Ring *ring, void (*encryptor)(unsigned char *, int))
-{
- unsigned char *s, *c;
-
- if (ring_empty(ring) || ring->clearto == ring->supply)
- return;
-
- if (!(c = ring->clearto))
- c = ring->consume;
-
- s = ring->supply;
-
- if (s <= c) {
- (*encryptor)(c, ring->top - c);
- (*encryptor)(ring->bottom, s - ring->bottom);
- } else
- (*encryptor)(c, s - c);
-
- ring->clearto = ring->supply;
-}
-
- void
-ring_clearto(ring)
- Ring *ring;
-{
- if (!ring_empty(ring))
- ring->clearto = ring->supply;
- else
- ring->clearto = 0;
-}
-#endif /* ENCRYPTION */
diff --git a/contrib/telnet/telnet/ring.h b/contrib/telnet/telnet/ring.h
deleted file mode 100644
index 516b7a5d806a..000000000000
--- a/contrib/telnet/telnet/ring.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ring.h 8.1 (Berkeley) 6/6/93
- * $FreeBSD$
- */
-
-#if defined(P)
-# undef P
-#endif
-
-#if defined(__STDC__) || defined(LINT_ARGS)
-# define P(x) x
-#else
-# define P(x) ()
-#endif
-
-/*
- * This defines a structure for a ring buffer.
- *
- * The circular buffer has two parts:
- *(((
- * full: [consume, supply)
- * empty: [supply, consume)
- *]]]
- *
- */
-typedef struct {
- unsigned char *consume, /* where data comes out of */
- *supply, /* where data comes in to */
- *bottom, /* lowest address in buffer */
- *top, /* highest address+1 in buffer */
- *mark; /* marker (user defined) */
-#ifdef ENCRYPTION
- unsigned char *clearto; /* Data to this point is clear text */
- unsigned char *encryyptedto; /* Data is encrypted to here */
-#endif /* ENCRYPTION */
- int size; /* size in bytes of buffer */
- u_long consumetime, /* help us keep straight full, empty, etc. */
- supplytime;
-} Ring;
-
-/* Here are some functions and macros to deal with the ring buffer */
-
-/* Initialization routine */
-extern int
- ring_init(Ring *ring, unsigned char *buffer, int count);
-
-/* Data movement routines */
-extern void
- ring_supply_data(Ring *ring, unsigned char *buffer, int count);
-#ifdef notdef
-extern void
- ring_consume_data(Ring *ring, unsigned char *buffer, int count);
-#endif
-
-/* Buffer state transition routines */
-extern void
- ring_supplied(Ring *ring, int count),
- ring_consumed(Ring *ring, int count);
-
-/* Buffer state query routines */
-extern int
- ring_at_mark(Ring *),
- ring_empty_count(Ring *ring),
- ring_empty_consecutive(Ring *ring),
- ring_full_count(Ring *ring),
- ring_full_consecutive(Ring *ring);
-
-#ifdef ENCRYPTION
-extern void
- ring_encrypt(Ring *ring, void (*func)(unsigned char *, int)),
- ring_clearto(Ring *ring);
-#endif /* ENCRYPTION */
-
-extern void
- ring_clear_mark(Ring *),
- ring_mark(Ring *);
diff --git a/contrib/telnet/telnet/sys_bsd.c b/contrib/telnet/telnet/sys_bsd.c
deleted file mode 100644
index 45ef1e2aa3cd..000000000000
--- a/contrib/telnet/telnet/sys_bsd.c
+++ /dev/null
@@ -1,1145 +0,0 @@
-/*
- * Copyright (c) 1988, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)sys_bsd.c 8.4 (Berkeley) 5/30/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * The following routines try to encapsulate what is system dependent
- * (at least between 4.x and dos) which is used in telnet.c.
- */
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <arpa/telnet.h>
-
-#include "ring.h"
-#include "fdset.h"
-#include "defines.h"
-#include "externs.h"
-#include "types.h"
-
-int
- tout, /* Output file descriptor */
- tin, /* Input file descriptor */
- net;
-
-#ifndef USE_TERMIO
-struct tchars otc = { 0 }, ntc = { 0 };
-struct ltchars oltc = { 0 }, nltc = { 0 };
-struct sgttyb ottyb = { 0 }, nttyb = { 0 };
-int olmode = 0;
-# define cfgetispeed(ptr) (ptr)->sg_ispeed
-# define cfgetospeed(ptr) (ptr)->sg_ospeed
-# define old_tc ottyb
-
-#else /* USE_TERMIO */
-struct termio old_tc = { 0, 0, 0, 0, {}, 0, 0 };
-
-# ifndef TCSANOW
-# ifdef TCSETS
-# define TCSANOW TCSETS
-# define TCSADRAIN TCSETSW
-# define tcgetattr(f, t) ioctl(f, TCGETS, (char *)t)
-# else
-# ifdef TCSETA
-# define TCSANOW TCSETA
-# define TCSADRAIN TCSETAW
-# define tcgetattr(f, t) ioctl(f, TCGETA, (char *)t)
-# else
-# define TCSANOW TIOCSETA
-# define TCSADRAIN TIOCSETAW
-# define tcgetattr(f, t) ioctl(f, TIOCGETA, (char *)t)
-# endif
-# endif
-# define tcsetattr(f, a, t) ioctl(f, a, (char *)t)
-# define cfgetospeed(ptr) ((ptr)->c_cflag&CBAUD)
-# ifdef CIBAUD
-# define cfgetispeed(ptr) (((ptr)->c_cflag&CIBAUD) >> IBSHIFT)
-# else
-# define cfgetispeed(ptr) cfgetospeed(ptr)
-# endif
-# endif /* TCSANOW */
-# ifdef sysV88
-# define TIOCFLUSH TC_PX_DRAIN
-# endif
-#endif /* USE_TERMIO */
-
-static fd_set *ibitsp, *obitsp, *xbitsp;
-int fdsn;
-
-#ifdef SIGINT
-static SIG_FUNC_RET intr(int);
-#endif /* SIGINT */
-#ifdef SIGQUIT
-static SIG_FUNC_RET intr2(int);
-#endif /* SIGQUIT */
-#ifdef SIGTSTP
-static SIG_FUNC_RET susp(int);
-#endif /* SIGTSTP */
-#ifdef SIGINFO
-static SIG_FUNC_RET ayt(int);
-#endif
-
-void
-init_sys(void)
-{
- tout = fileno(stdout);
- tin = fileno(stdin);
- errno = 0;
-}
-
-int
-TerminalWrite(char *buf, int n)
-{
- return write(tout, buf, n);
-}
-
-int
-TerminalRead(char *buf, int n)
-{
- return read(tin, buf, n);
-}
-
-/*
- *
- */
-
-int
-TerminalAutoFlush(void)
-{
-#if defined(LNOFLSH)
- int flush;
-
- ioctl(0, TIOCLGET, (char *)&flush);
- return !(flush&LNOFLSH); /* if LNOFLSH, no autoflush */
-#else /* LNOFLSH */
- return 1;
-#endif /* LNOFLSH */
-}
-
-#ifdef KLUDGELINEMODE
-extern int kludgelinemode;
-#endif
-/*
- * TerminalSpecialChars()
- *
- * Look at an input character to see if it is a special character
- * and decide what to do.
- *
- * Output:
- *
- * 0 Don't add this character.
- * 1 Do add this character
- */
-
-int
-TerminalSpecialChars(int c)
-{
- if (c == termIntChar) {
- intp();
- return 0;
- } else if (c == termQuitChar) {
-#ifdef KLUDGELINEMODE
- if (kludgelinemode)
- sendbrk();
- else
-#endif
- sendabort();
- return 0;
- } else if (c == termEofChar) {
- if (my_want_state_is_will(TELOPT_LINEMODE)) {
- sendeof();
- return 0;
- }
- return 1;
- } else if (c == termSuspChar) {
- sendsusp();
- return(0);
- } else if (c == termFlushChar) {
- xmitAO(); /* Transmit Abort Output */
- return 0;
- } else if (!MODE_LOCAL_CHARS(globalmode)) {
- if (c == termKillChar) {
- xmitEL();
- return 0;
- } else if (c == termEraseChar) {
- xmitEC(); /* Transmit Erase Character */
- return 0;
- }
- }
- return 1;
-}
-
-
-/*
- * Flush output to the terminal
- */
-
-void
-TerminalFlushOutput(void)
-{
-#ifdef TIOCFLUSH
- (void) ioctl(fileno(stdout), TIOCFLUSH, (char *) 0);
-#else
- (void) ioctl(fileno(stdout), TCFLSH, (char *) 0);
-#endif
-}
-
-void
-TerminalSaveState(void)
-{
-#ifndef USE_TERMIO
- ioctl(0, TIOCGETP, (char *)&ottyb);
- ioctl(0, TIOCGETC, (char *)&otc);
- ioctl(0, TIOCGLTC, (char *)&oltc);
- ioctl(0, TIOCLGET, (char *)&olmode);
-
- ntc = otc;
- nltc = oltc;
- nttyb = ottyb;
-
-#else /* USE_TERMIO */
- tcgetattr(0, &old_tc);
-
- new_tc = old_tc;
-
-#ifndef VDISCARD
- termFlushChar = CONTROL('O');
-#endif
-#ifndef VWERASE
- termWerasChar = CONTROL('W');
-#endif
-#ifndef VREPRINT
- termRprntChar = CONTROL('R');
-#endif
-#ifndef VLNEXT
- termLiteralNextChar = CONTROL('V');
-#endif
-#ifndef VSTART
- termStartChar = CONTROL('Q');
-#endif
-#ifndef VSTOP
- termStopChar = CONTROL('S');
-#endif
-#ifndef VSTATUS
- termAytChar = CONTROL('T');
-#endif
-#endif /* USE_TERMIO */
-}
-
-cc_t *
-tcval(int func)
-{
- switch(func) {
- case SLC_IP: return(&termIntChar);
- case SLC_ABORT: return(&termQuitChar);
- case SLC_EOF: return(&termEofChar);
- case SLC_EC: return(&termEraseChar);
- case SLC_EL: return(&termKillChar);
- case SLC_XON: return(&termStartChar);
- case SLC_XOFF: return(&termStopChar);
- case SLC_FORW1: return(&termForw1Char);
-#ifdef USE_TERMIO
- case SLC_FORW2: return(&termForw2Char);
-# ifdef VDISCARD
- case SLC_AO: return(&termFlushChar);
-# endif
-# ifdef VSUSP
- case SLC_SUSP: return(&termSuspChar);
-# endif
-# ifdef VWERASE
- case SLC_EW: return(&termWerasChar);
-# endif
-# ifdef VREPRINT
- case SLC_RP: return(&termRprntChar);
-# endif
-# ifdef VLNEXT
- case SLC_LNEXT: return(&termLiteralNextChar);
-# endif
-# ifdef VSTATUS
- case SLC_AYT: return(&termAytChar);
-# endif
-#endif
-
- case SLC_SYNCH:
- case SLC_BRK:
- case SLC_EOR:
- default:
- return((cc_t *)0);
- }
-}
-
-void
-TerminalDefaultChars(void)
-{
-#ifndef USE_TERMIO
- ntc = otc;
- nltc = oltc;
- nttyb.sg_kill = ottyb.sg_kill;
- nttyb.sg_erase = ottyb.sg_erase;
-#else /* USE_TERMIO */
- memcpy(new_tc.c_cc, old_tc.c_cc, sizeof(old_tc.c_cc));
-# ifndef VDISCARD
- termFlushChar = CONTROL('O');
-# endif
-# ifndef VWERASE
- termWerasChar = CONTROL('W');
-# endif
-# ifndef VREPRINT
- termRprntChar = CONTROL('R');
-# endif
-# ifndef VLNEXT
- termLiteralNextChar = CONTROL('V');
-# endif
-# ifndef VSTART
- termStartChar = CONTROL('Q');
-# endif
-# ifndef VSTOP
- termStopChar = CONTROL('S');
-# endif
-# ifndef VSTATUS
- termAytChar = CONTROL('T');
-# endif
-#endif /* USE_TERMIO */
-}
-
-/*
- * TerminalNewMode - set up terminal to a specific mode.
- * MODE_ECHO: do local terminal echo
- * MODE_FLOW: do local flow control
- * MODE_TRAPSIG: do local mapping to TELNET IAC sequences
- * MODE_EDIT: do local line editing
- *
- * Command mode:
- * MODE_ECHO|MODE_EDIT|MODE_FLOW|MODE_TRAPSIG
- * local echo
- * local editing
- * local xon/xoff
- * local signal mapping
- *
- * Linemode:
- * local/no editing
- * Both Linemode and Single Character mode:
- * local/remote echo
- * local/no xon/xoff
- * local/no signal mapping
- */
-
-void
-TerminalNewMode(int f)
-{
- static int prevmode = 0;
-#ifndef USE_TERMIO
- struct tchars tc;
- struct ltchars ltc;
- struct sgttyb sb;
- int lmode;
-#else /* USE_TERMIO */
- struct termio tmp_tc;
-#endif /* USE_TERMIO */
- int onoff;
- int old;
- cc_t esc;
-
- globalmode = f&~MODE_FORCE;
- if (prevmode == f)
- return;
-
- /*
- * Write any outstanding data before switching modes
- * ttyflush() returns 0 only when there is no more data
- * left to write out, it returns -1 if it couldn't do
- * anything at all, otherwise it returns 1 + the number
- * of characters left to write.
-#ifndef USE_TERMIO
- * We would really like ask the kernel to wait for the output
- * to drain, like we can do with the TCSADRAIN, but we don't have
- * that option. The only ioctl that waits for the output to
- * drain, TIOCSETP, also flushes the input queue, which is NOT
- * what we want (TIOCSETP is like TCSADFLUSH).
-#endif
- */
- old = ttyflush(SYNCHing|flushout);
- if (old < 0 || old > 1) {
-#ifdef USE_TERMIO
- tcgetattr(tin, &tmp_tc);
-#endif /* USE_TERMIO */
- do {
- /*
- * Wait for data to drain, then flush again.
- */
-#ifdef USE_TERMIO
- tcsetattr(tin, TCSADRAIN, &tmp_tc);
-#endif /* USE_TERMIO */
- old = ttyflush(SYNCHing|flushout);
- } while (old < 0 || old > 1);
- }
-
- old = prevmode;
- prevmode = f&~MODE_FORCE;
-#ifndef USE_TERMIO
- sb = nttyb;
- tc = ntc;
- ltc = nltc;
- lmode = olmode;
-#else
- tmp_tc = new_tc;
-#endif
-
- if (f&MODE_ECHO) {
-#ifndef USE_TERMIO
- sb.sg_flags |= ECHO;
-#else
- tmp_tc.c_lflag |= ECHO;
- tmp_tc.c_oflag |= ONLCR;
- if (crlf)
- tmp_tc.c_iflag |= ICRNL;
-#endif
- } else {
-#ifndef USE_TERMIO
- sb.sg_flags &= ~ECHO;
-#else
- tmp_tc.c_lflag &= ~ECHO;
- tmp_tc.c_oflag &= ~ONLCR;
-#endif
- }
-
- if ((f&MODE_FLOW) == 0) {
-#ifndef USE_TERMIO
- tc.t_startc = _POSIX_VDISABLE;
- tc.t_stopc = _POSIX_VDISABLE;
-#else
- tmp_tc.c_iflag &= ~(IXOFF|IXON); /* Leave the IXANY bit alone */
- } else {
- if (restartany < 0) {
- tmp_tc.c_iflag |= IXOFF|IXON; /* Leave the IXANY bit alone */
- } else if (restartany > 0) {
- tmp_tc.c_iflag |= IXOFF|IXON|IXANY;
- } else {
- tmp_tc.c_iflag |= IXOFF|IXON;
- tmp_tc.c_iflag &= ~IXANY;
- }
-#endif
- }
-
- if ((f&MODE_TRAPSIG) == 0) {
-#ifndef USE_TERMIO
- tc.t_intrc = _POSIX_VDISABLE;
- tc.t_quitc = _POSIX_VDISABLE;
- tc.t_eofc = _POSIX_VDISABLE;
- ltc.t_suspc = _POSIX_VDISABLE;
- ltc.t_dsuspc = _POSIX_VDISABLE;
-#else
- tmp_tc.c_lflag &= ~ISIG;
-#endif
- localchars = 0;
- } else {
-#ifdef USE_TERMIO
- tmp_tc.c_lflag |= ISIG;
-#endif
- localchars = 1;
- }
-
- if (f&MODE_EDIT) {
-#ifndef USE_TERMIO
- sb.sg_flags &= ~CBREAK;
- sb.sg_flags |= CRMOD;
-#else
- tmp_tc.c_lflag |= ICANON;
-#endif
- } else {
-#ifndef USE_TERMIO
- sb.sg_flags |= CBREAK;
- if (f&MODE_ECHO)
- sb.sg_flags |= CRMOD;
- else
- sb.sg_flags &= ~CRMOD;
-#else
- tmp_tc.c_lflag &= ~ICANON;
- tmp_tc.c_iflag &= ~ICRNL;
- tmp_tc.c_cc[VMIN] = 1;
- tmp_tc.c_cc[VTIME] = 0;
-#endif
- }
-
- if ((f&(MODE_EDIT|MODE_TRAPSIG)) == 0) {
-#ifndef USE_TERMIO
- ltc.t_lnextc = _POSIX_VDISABLE;
-#else
-# ifdef VLNEXT
- tmp_tc.c_cc[VLNEXT] = (cc_t)(_POSIX_VDISABLE);
-# endif
-#endif
- }
-
- if (f&MODE_SOFT_TAB) {
-#ifndef USE_TERMIO
- sb.sg_flags |= XTABS;
-#else
-# ifdef OXTABS
- tmp_tc.c_oflag |= OXTABS;
-# endif
-# ifdef TABDLY
- tmp_tc.c_oflag &= ~TABDLY;
- tmp_tc.c_oflag |= TAB3;
-# endif
-#endif
- } else {
-#ifndef USE_TERMIO
- sb.sg_flags &= ~XTABS;
-#else
-# ifdef OXTABS
- tmp_tc.c_oflag &= ~OXTABS;
-# endif
-# ifdef TABDLY
- tmp_tc.c_oflag &= ~TABDLY;
-# endif
-#endif
- }
-
- if (f&MODE_LIT_ECHO) {
-#ifndef USE_TERMIO
- lmode &= ~LCTLECH;
-#else
-# ifdef ECHOCTL
- tmp_tc.c_lflag &= ~ECHOCTL;
-# endif
-#endif
- } else {
-#ifndef USE_TERMIO
- lmode |= LCTLECH;
-#else
-# ifdef ECHOCTL
- tmp_tc.c_lflag |= ECHOCTL;
-# endif
-#endif
- }
-
- if (f == -1) {
- onoff = 0;
- } else {
-#ifndef USE_TERMIO
- if (f & MODE_OUTBIN)
- lmode |= LLITOUT;
- else
- lmode &= ~LLITOUT;
-
- if (f & MODE_INBIN)
- lmode |= LPASS8;
- else
- lmode &= ~LPASS8;
-#else
- if (f & MODE_INBIN)
- tmp_tc.c_iflag &= ~ISTRIP;
- else
- tmp_tc.c_iflag |= ISTRIP;
- if (f & MODE_OUTBIN) {
- tmp_tc.c_cflag &= ~(CSIZE|PARENB);
- tmp_tc.c_cflag |= CS8;
- tmp_tc.c_oflag &= ~OPOST;
- } else {
- tmp_tc.c_cflag &= ~(CSIZE|PARENB);
- tmp_tc.c_cflag |= old_tc.c_cflag & (CSIZE|PARENB);
- tmp_tc.c_oflag |= OPOST;
- }
-#endif
- onoff = 1;
- }
-
- if (f != -1) {
-#ifdef SIGINT
- (void) signal(SIGINT, intr);
-#endif
-#ifdef SIGQUIT
- (void) signal(SIGQUIT, intr2);
-#endif
-#ifdef SIGTSTP
- (void) signal(SIGTSTP, susp);
-#endif /* SIGTSTP */
-#ifdef SIGINFO
- (void) signal(SIGINFO, ayt);
-#endif
-#if defined(USE_TERMIO) && defined(NOKERNINFO)
- tmp_tc.c_lflag |= NOKERNINFO;
-#endif
- /*
- * We don't want to process ^Y here. It's just another
- * character that we'll pass on to the back end. It has
- * to process it because it will be processed when the
- * user attempts to read it, not when we send it.
- */
-#ifndef USE_TERMIO
- ltc.t_dsuspc = _POSIX_VDISABLE;
-#else
-# ifdef VDSUSP
- tmp_tc.c_cc[VDSUSP] = (cc_t)(_POSIX_VDISABLE);
-# endif
-#endif
-#ifdef USE_TERMIO
- /*
- * If the VEOL character is already set, then use VEOL2,
- * otherwise use VEOL.
- */
- esc = (rlogin != _POSIX_VDISABLE) ? rlogin : escape;
- if ((tmp_tc.c_cc[VEOL] != esc)
-# ifdef VEOL2
- && (tmp_tc.c_cc[VEOL2] != esc)
-# endif
- ) {
- if (tmp_tc.c_cc[VEOL] == (cc_t)(_POSIX_VDISABLE))
- tmp_tc.c_cc[VEOL] = esc;
-# ifdef VEOL2
- else if (tmp_tc.c_cc[VEOL2] == (cc_t)(_POSIX_VDISABLE))
- tmp_tc.c_cc[VEOL2] = esc;
-# endif
- }
-#else
- if (tc.t_brkc == (cc_t)(_POSIX_VDISABLE))
- tc.t_brkc = esc;
-#endif
- } else {
-#ifdef SIGINFO
- (void) signal(SIGINFO, (void (*)(int))ayt_status);
-#endif
-#ifdef SIGINT
- (void) signal(SIGINT, SIG_DFL);
-#endif
-#ifdef SIGQUIT
- (void) signal(SIGQUIT, SIG_DFL);
-#endif
-#ifdef SIGTSTP
- (void) signal(SIGTSTP, SIG_DFL);
-# ifndef SOLARIS
- (void) sigsetmask(sigblock(0) & ~(1<<(SIGTSTP-1)));
-# else /* SOLARIS */
- (void) sigrelse(SIGTSTP);
-# endif /* SOLARIS */
-#endif /* SIGTSTP */
-#ifndef USE_TERMIO
- ltc = oltc;
- tc = otc;
- sb = ottyb;
- lmode = olmode;
-#else
- tmp_tc = old_tc;
-#endif
- }
-#ifndef USE_TERMIO
- ioctl(tin, TIOCLSET, (char *)&lmode);
- ioctl(tin, TIOCSLTC, (char *)&ltc);
- ioctl(tin, TIOCSETC, (char *)&tc);
- ioctl(tin, TIOCSETN, (char *)&sb);
-#else
- if (tcsetattr(tin, TCSADRAIN, &tmp_tc) < 0)
- tcsetattr(tin, TCSANOW, &tmp_tc);
-#endif
-
- ioctl(tin, FIONBIO, (char *)&onoff);
- ioctl(tout, FIONBIO, (char *)&onoff);
-
-}
-
-/*
- * Try to guess whether speeds are "encoded" (4.2BSD) or just numeric (4.4BSD).
- */
-#if B4800 != 4800
-#define DECODE_BAUD
-#endif
-
-#ifdef DECODE_BAUD
-#ifndef B7200
-#define B7200 B4800
-#endif
-
-#ifndef B14400
-#define B14400 B9600
-#endif
-
-#ifndef B19200
-# define B19200 B14400
-#endif
-
-#ifndef B28800
-#define B28800 B19200
-#endif
-
-#ifndef B38400
-# define B38400 B28800
-#endif
-
-#ifndef B57600
-#define B57600 B38400
-#endif
-
-#ifndef B76800
-#define B76800 B57600
-#endif
-
-#ifndef B115200
-#define B115200 B76800
-#endif
-
-#ifndef B230400
-#define B230400 B115200
-#endif
-
-
-/*
- * This code assumes that the values B0, B50, B75...
- * are in ascending order. They do not have to be
- * contiguous.
- */
-struct termspeeds {
- long speed;
- long value;
-} termspeeds[] = {
- { 0, B0 }, { 50, B50 }, { 75, B75 },
- { 110, B110 }, { 134, B134 }, { 150, B150 },
- { 200, B200 }, { 300, B300 }, { 600, B600 },
- { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 },
- { 4800, B4800 }, { 7200, B7200 }, { 9600, B9600 },
- { 14400, B14400 }, { 19200, B19200 }, { 28800, B28800 },
- { 38400, B38400 }, { 57600, B57600 }, { 115200, B115200 },
- { 230400, B230400 }, { -1, B230400 }
-};
-#endif /* DECODE_BAUD */
-
-void
-TerminalSpeeds(long *ispeed, long *ospeed)
-{
-#ifdef DECODE_BAUD
- struct termspeeds *tp;
-#endif /* DECODE_BAUD */
- long in, out;
-
- out = cfgetospeed(&old_tc);
- in = cfgetispeed(&old_tc);
- if (in == 0)
- in = out;
-
-#ifdef DECODE_BAUD
- tp = termspeeds;
- while ((tp->speed != -1) && (tp->value < in))
- tp++;
- *ispeed = tp->speed;
-
- tp = termspeeds;
- while ((tp->speed != -1) && (tp->value < out))
- tp++;
- *ospeed = tp->speed;
-#else /* DECODE_BAUD */
- *ispeed = in;
- *ospeed = out;
-#endif /* DECODE_BAUD */
-}
-
-int
-TerminalWindowSize(long *rows, long *cols)
-{
-#ifdef TIOCGWINSZ
- struct winsize ws;
-
- if (ioctl(fileno(stdin), TIOCGWINSZ, (char *)&ws) >= 0) {
- *rows = ws.ws_row;
- *cols = ws.ws_col;
- return 1;
- }
-#endif /* TIOCGWINSZ */
- return 0;
-}
-
-int
-NetClose(int fd)
-{
- return close(fd);
-}
-
-static void
-NetNonblockingIO(int fd, int onoff)
-{
- ioctl(fd, FIONBIO, (char *)&onoff);
-}
-
-
-/*
- * Various signal handling routines.
- */
-
-/* ARGSUSED */
-static SIG_FUNC_RET
-deadpeer(int sig __unused)
-{
- setcommandmode();
- longjmp(peerdied, -1);
-}
-
-/* ARGSUSED */
-SIG_FUNC_RET
-intr(int sig __unused)
-{
- if (localchars) {
- intp();
- return;
- }
- setcommandmode();
- longjmp(toplevel, -1);
-}
-
-/* ARGSUSED */
-SIG_FUNC_RET
-intr2(int sig __unused)
-{
- if (localchars) {
-#ifdef KLUDGELINEMODE
- if (kludgelinemode)
- sendbrk();
- else
-#endif
- sendabort();
- return;
- }
-}
-
-#ifdef SIGTSTP
-/* ARGSUSED */
-SIG_FUNC_RET
-susp(int sig __unused)
-{
- if ((rlogin != _POSIX_VDISABLE) && rlogin_susp())
- return;
- if (localchars)
- sendsusp();
-}
-#endif
-
-#ifdef SIGWINCH
-/* ARGSUSED */
-static SIG_FUNC_RET
-sendwin(int sig __unused)
-{
- if (connected) {
- sendnaws();
- }
-}
-#endif
-
-#ifdef SIGINFO
-/* ARGSUSED */
-SIG_FUNC_RET
-ayt(int sig __unused)
-{
- if (connected)
- sendayt();
- else
- ayt_status();
-}
-#endif
-
-
-void
-sys_telnet_init(void)
-{
- (void) signal(SIGINT, intr);
- (void) signal(SIGQUIT, intr2);
- (void) signal(SIGPIPE, deadpeer);
-#ifdef SIGWINCH
- (void) signal(SIGWINCH, sendwin);
-#endif
-#ifdef SIGTSTP
- (void) signal(SIGTSTP, susp);
-#endif
-#ifdef SIGINFO
- (void) signal(SIGINFO, ayt);
-#endif
-
- setconnmode(0);
-
- NetNonblockingIO(net, 1);
-
-#if defined(SO_OOBINLINE)
- if (SetSockOpt(net, SOL_SOCKET, SO_OOBINLINE, 1) == -1) {
- perror("SetSockOpt");
- }
-#endif /* defined(SO_OOBINLINE) */
-}
-
-/*
- * Process rings -
- *
- * This routine tries to fill up/empty our various rings.
- *
- * The parameter specifies whether this is a poll operation,
- * or a block-until-something-happens operation.
- *
- * The return value is 1 if something happened, 0 if not.
- */
-
-int
-process_rings(int netin, int netout, int netex, int ttyin, int ttyout, int poll)
-{
- int c;
- int returnValue = 0;
- static struct timeval TimeValue = { 0, 0 };
- int maxfd = -1;
- int tmp;
-
- if ((netout || netin || netex) && net > maxfd)
- maxfd = net;
-
- if (ttyout && tout > maxfd)
- maxfd = tout;
- if (ttyin && tin > maxfd)
- maxfd = tin;
- tmp = howmany(maxfd+1, NFDBITS) * sizeof(fd_mask);
- if (tmp > fdsn) {
- if (ibitsp)
- free(ibitsp);
- if (obitsp)
- free(obitsp);
- if (xbitsp)
- free(xbitsp);
-
- fdsn = tmp;
- if ((ibitsp = (fd_set *)malloc(fdsn)) == NULL)
- err(1, "malloc");
- if ((obitsp = (fd_set *)malloc(fdsn)) == NULL)
- err(1, "malloc");
- if ((xbitsp = (fd_set *)malloc(fdsn)) == NULL)
- err(1, "malloc");
- memset(ibitsp, 0, fdsn);
- memset(obitsp, 0, fdsn);
- memset(xbitsp, 0, fdsn);
- }
-
- if (netout)
- FD_SET(net, obitsp);
- if (ttyout)
- FD_SET(tout, obitsp);
- if (ttyin)
- FD_SET(tin, ibitsp);
- if (netin)
- FD_SET(net, ibitsp);
- if (netex)
- FD_SET(net, xbitsp);
- if ((c = select(maxfd + 1, ibitsp, obitsp, xbitsp,
- (poll == 0)? (struct timeval *)0 : &TimeValue)) < 0) {
- if (c == -1) {
- /*
- * we can get EINTR if we are in line mode,
- * and the user does an escape (TSTP), or
- * some other signal generator.
- */
- if (errno == EINTR) {
- return 0;
- }
- /* I don't like this, does it ever happen? */
- printf("sleep(5) from telnet, after select: %s\r\n", strerror(errno));
- sleep(5);
- }
- return 0;
- }
-
- /*
- * Any urgent data?
- */
- if (FD_ISSET(net, xbitsp)) {
- FD_CLR(net, xbitsp);
- SYNCHing = 1;
- (void) ttyflush(1); /* flush already enqueued data */
- }
-
- /*
- * Something to read from the network...
- */
- if (FD_ISSET(net, ibitsp)) {
- int canread;
-
- FD_CLR(net, ibitsp);
- canread = ring_empty_consecutive(&netiring);
-#if !defined(SO_OOBINLINE)
- /*
- * In 4.2 (and some early 4.3) systems, the
- * OOB indication and data handling in the kernel
- * is such that if two separate TCP Urgent requests
- * come in, one byte of TCP data will be overlaid.
- * This is fatal for Telnet, but we try to live
- * with it.
- *
- * In addition, in 4.2 (and...), a special protocol
- * is needed to pick up the TCP Urgent data in
- * the correct sequence.
- *
- * What we do is: if we think we are in urgent
- * mode, we look to see if we are "at the mark".
- * If we are, we do an OOB receive. If we run
- * this twice, we will do the OOB receive twice,
- * but the second will fail, since the second
- * time we were "at the mark", but there wasn't
- * any data there (the kernel doesn't reset
- * "at the mark" until we do a normal read).
- * Once we've read the OOB data, we go ahead
- * and do normal reads.
- *
- * There is also another problem, which is that
- * since the OOB byte we read doesn't put us
- * out of OOB state, and since that byte is most
- * likely the TELNET DM (data mark), we would
- * stay in the TELNET SYNCH (SYNCHing) state.
- * So, clocks to the rescue. If we've "just"
- * received a DM, then we test for the
- * presence of OOB data when the receive OOB
- * fails (and AFTER we did the normal mode read
- * to clear "at the mark").
- */
- if (SYNCHing) {
- int atmark;
- static int bogus_oob = 0, first = 1;
-
- ioctl(net, SIOCATMARK, (char *)&atmark);
- if (atmark) {
- c = recv(net, netiring.supply, canread, MSG_OOB);
- if ((c == -1) && (errno == EINVAL)) {
- c = recv(net, netiring.supply, canread, 0);
- if (clocks.didnetreceive < clocks.gotDM) {
- SYNCHing = stilloob(net);
- }
- } else if (first && c > 0) {
- /*
- * Bogosity check. Systems based on 4.2BSD
- * do not return an error if you do a second
- * recv(MSG_OOB). So, we do one. If it
- * succeeds and returns exactly the same
- * data, then assume that we are running
- * on a broken system and set the bogus_oob
- * flag. (If the data was different, then
- * we probably got some valid new data, so
- * increment the count...)
- */
- int i;
- i = recv(net, netiring.supply + c, canread - c, MSG_OOB);
- if (i == c &&
- memcmp(netiring.supply, netiring.supply + c, i) == 0) {
- bogus_oob = 1;
- first = 0;
- } else if (i < 0) {
- bogus_oob = 0;
- first = 0;
- } else
- c += i;
- }
- if (bogus_oob && c > 0) {
- int i;
- /*
- * Bogosity. We have to do the read
- * to clear the atmark to get out of
- * an infinate loop.
- */
- i = read(net, netiring.supply + c, canread - c);
- if (i > 0)
- c += i;
- }
- } else {
- c = recv(net, netiring.supply, canread, 0);
- }
- } else {
- c = recv(net, netiring.supply, canread, 0);
- }
- settimer(didnetreceive);
-#else /* !defined(SO_OOBINLINE) */
- c = recv(net, (char *)netiring.supply, canread, 0);
-#endif /* !defined(SO_OOBINLINE) */
- if (c < 0 && errno == EWOULDBLOCK) {
- c = 0;
- } else if (c <= 0) {
- return -1;
- }
- if (netdata) {
- Dump('<', netiring.supply, c);
- }
- if (c)
- ring_supplied(&netiring, c);
- returnValue = 1;
- }
-
- /*
- * Something to read from the tty...
- */
- if (FD_ISSET(tin, ibitsp)) {
- FD_CLR(tin, ibitsp);
- c = TerminalRead(ttyiring.supply, ring_empty_consecutive(&ttyiring));
- if (c < 0 && errno == EIO)
- c = 0;
- if (c < 0 && errno == EWOULDBLOCK) {
- c = 0;
- } else {
- /* EOF detection for line mode!!!! */
- if ((c == 0) && MODE_LOCAL_CHARS(globalmode) && isatty(tin)) {
- /* must be an EOF... */
- *ttyiring.supply = termEofChar;
- c = 1;
- }
- if (c <= 0) {
- return -1;
- }
- if (termdata) {
- Dump('<', ttyiring.supply, c);
- }
- ring_supplied(&ttyiring, c);
- }
- returnValue = 1; /* did something useful */
- }
-
- if (FD_ISSET(net, obitsp)) {
- FD_CLR(net, obitsp);
- returnValue |= netflush();
- }
- if (FD_ISSET(tout, obitsp)) {
- FD_CLR(tout, obitsp);
- returnValue |= (ttyflush(SYNCHing|flushout) > 0);
- }
-
- return returnValue;
-}
diff --git a/contrib/telnet/telnet/telnet.1 b/contrib/telnet/telnet/telnet.1
deleted file mode 100644
index 2bbc0b77ff33..000000000000
--- a/contrib/telnet/telnet/telnet.1
+++ /dev/null
@@ -1,1424 +0,0 @@
-.\" Copyright (c) 1983, 1990, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)telnet.1 8.6 (Berkeley) 6/1/94
-.\" $FreeBSD$
-.\"
-.Dd January 27, 2000
-.Dt TELNET 1
-.Os
-.Sh NAME
-.Nm telnet
-.Nd user interface to the
-.Tn TELNET
-protocol
-.Sh SYNOPSIS
-.Nm
-.Op Fl 468EFKLNacdfruxy
-.Op Fl S Ar tos
-.Op Fl X Ar authtype
-.Op Fl e Ar escapechar
-.Op Fl k Ar realm
-.Op Fl l Ar user
-.Op Fl n Ar tracefile
-.Op Fl s Ar src_addr
-.Oo
-.Ar host
-.Op Ar port
-.Oc
-.Sh DESCRIPTION
-The
-.Nm
-command
-is used to communicate with another host using the
-.Tn TELNET
-protocol.
-If
-.Nm
-is invoked without the
-.Ar host
-argument, it enters command mode,
-indicated by its prompt
-.Pq Dq Li telnet\&> .
-In this mode, it accepts and executes the commands listed below.
-If it is invoked with arguments, it performs an
-.Ic open
-command with those arguments.
-.Pp
-Options:
-.Bl -tag -width indent
-.It Fl 4
-Forces
-.Nm
-to use IPv4 addresses only.
-.It Fl 6
-Forces
-.Nm
-to use IPv6 addresses only.
-.It Fl 8
-Specifies an 8-bit data path. This causes an attempt to
-negotiate the
-.Dv TELNET BINARY
-option on both input and output.
-.It Fl E
-Stops any character from being recognized as an escape character.
-.It Fl F
-If Kerberos V5 authentication is being used, the
-.Fl F
-option allows the local credentials to be forwarded
-to the remote system, including any credentials that
-have already been forwarded into the local environment.
-.It Fl K
-Specifies no automatic login to the remote system.
-.It Fl L
-Specifies an 8-bit data path on output. This causes the
-.Dv BINARY
-option to be negotiated on output.
-.It Fl N
-Prevents IP address to name lookup when destination host is given
-as an IP address.
-.It Fl S Ar tos
-Sets the IP type-of-service (TOS) option for the telnet
-connection to the value
-.Ar tos ,
-which can be a numeric TOS value
-or, on systems that support it, a symbolic
-TOS name found in the
-.Pa /etc/iptos
-file.
-.It Fl X Ar atype
-Disables the
-.Ar atype
-type of authentication.
-.It Fl a
-Attempt automatic login.
-This is now the default, so this option is ignored.
-Currently, this sends the user name via the
-.Ev USER
-variable
-of the
-.Ev ENVIRON
-option if supported by the remote system.
-The name used is that of the current user as returned by
-.Xr getlogin 2
-if it agrees with the current user ID,
-otherwise it is the name associated with the user ID.
-.It Fl c
-Disables the reading of the user's
-.Pa \&.telnetrc
-file. (See the
-.Ic toggle skiprc
-command on this man page.)
-.It Fl d
-Sets the initial value of the
-.Ic debug
-toggle to
-.Dv TRUE .
-.It Fl e Ar escapechar
-Sets the initial
-.Nm
-escape character to
-.Ar escapechar .
-If
-.Ar escapechar
-is omitted, then
-there will be no escape character.
-.It Fl f
-If Kerberos V5 authentication is being used, the
-.Fl f
-option allows the local credentials to be forwarded to the remote system.
-.It Fl k Ar realm
-If Kerberos authentication is being used, the
-.Fl k
-option requests that
-.Nm
-obtain tickets for the remote host in
-realm
-.Ar realm
-instead of the remote host's realm, as determined by
-.Xr krb_realmofhost 3 .
-.It Fl l Ar user
-When connecting to the remote system, if the remote system
-understands the
-.Ev ENVIRON
-option, then
-.Ar user
-will be sent to the remote system as the value for the variable
-.Ev USER .
-This option implies the
-.Fl a
-option.
-This option may also be used with the
-.Ic open
-command.
-.It Fl n Ar tracefile
-Opens
-.Ar tracefile
-for recording trace information.
-See the
-.Ic set tracefile
-command below.
-.It Fl r
-Specifies a user interface similar to
-.Xr rlogin 1 .
-In this
-mode, the escape character is set to the tilde (~) character,
-unless modified by the
-.Fl e
-option.
-.It Fl s Ar src_addr
-Set the source IP address for the
-.Nm
-connection to
-.Ar src_addr ,
-which can be an IP address or a host name.
-.It Fl u
-Forces
-.Nm
-to use
-.Dv AF_UNIX
-addresses only (e.g.,
-.Ux
-domain sockets, accessed with a file path).
-.It Fl x
-Turns on encryption of the data stream if possible.
-This is now the default, so this option is ignored.
-.It Fl y
-Suppresses encryption of the data stream.
-.It Ar host
-Indicates the official name, an alias, or the Internet address
-of a remote host.
-If
-.Ar host
-starts with a
-.Ql / ,
-.Nm
-establishes a connection to the corresponding named socket.
-.It Ar port
-Indicates a port number (address of an application). If a number is
-not specified, the default
-.Nm
-port is used.
-.El
-.Pp
-When in rlogin mode, a line of the form ~. disconnects from the
-remote host; ~ is the
-.Nm
-escape character.
-Similarly, the line ~^Z suspends the
-.Nm
-session.
-The line ~^] escapes to the normal
-.Nm
-escape prompt.
-.Pp
-Once a connection has been opened,
-.Nm
-will attempt to enable the
-.Dv TELNET LINEMODE
-option.
-If this fails, then
-.Nm
-will revert to one of two input modes:
-either \*(Lqcharacter at a time\*(Rq
-or \*(Lqold line by line\*(Rq
-depending on what the remote system supports.
-.Pp
-When
-.Dv LINEMODE
-is enabled, character processing is done on the
-local system, under the control of the remote system. When input
-editing or character echoing is to be disabled, the remote system
-will relay that information. The remote system will also relay
-changes to any special characters that happen on the remote
-system, so that they can take effect on the local system.
-.Pp
-In \*(Lqcharacter at a time\*(Rq mode, most
-text typed is immediately sent to the remote host for processing.
-.Pp
-In \*(Lqold line by line\*(Rq mode, all text is echoed locally,
-and (normally) only completed lines are sent to the remote host.
-The \*(Lqlocal echo character\*(Rq (initially \*(Lq^E\*(Rq) may be used
-to turn off and on the local echo
-(this would mostly be used to enter passwords
-without the password being echoed).
-.Pp
-If the
-.Dv LINEMODE
-option is enabled, or if the
-.Ic localchars
-toggle is
-.Dv TRUE
-(the default for \*(Lqold line by line\*(Rq; see below),
-the user's
-.Ic quit ,
-.Ic intr ,
-and
-.Ic flush
-characters are trapped locally, and sent as
-.Tn TELNET
-protocol sequences to the remote side.
-If
-.Dv LINEMODE
-has ever been enabled, then the user's
-.Ic susp
-and
-.Ic eof
-are also sent as
-.Tn TELNET
-protocol sequences,
-and
-.Ic quit
-is sent as a
-.Dv TELNET ABORT
-instead of
-.Dv BREAK .
-There are options (see
-.Ic toggle
-.Ic autoflush
-and
-.Ic toggle
-.Ic autosynch
-below)
-which cause this action to flush subsequent output to the terminal
-(until the remote host acknowledges the
-.Tn TELNET
-sequence) and flush previous terminal input
-(in the case of
-.Ic quit
-and
-.Ic intr ) .
-.Pp
-While connected to a remote host,
-.Nm
-command mode may be entered by typing the
-.Nm
-\*(Lqescape character\*(Rq (initially \*(Lq^]\*(Rq).
-When in command mode, the normal terminal editing conventions are available.
-.Pp
-The following
-.Nm
-commands are available.
-Only enough of each command to uniquely identify it need be typed
-(this is also true for arguments to the
-.Ic mode ,
-.Ic set ,
-.Ic toggle ,
-.Ic unset ,
-.Ic slc ,
-.Ic environ ,
-and
-.Ic display
-commands).
-.Pp
-.Bl -tag -width "mode type"
-.It Ic auth Ar argument ...
-The auth command manipulates the information sent through the
-.Dv TELNET AUTHENTICATE
-option. Valid arguments for the
-.Ic auth
-command are:
-.Bl -tag -width "disable type"
-.It Ic disable Ar type
-Disables the specified type of authentication. To
-obtain a list of available types, use the
-.Ic auth disable ?\&
-command.
-.It Ic enable Ar type
-Enables the specified type of authentication. To
-obtain a list of available types, use the
-.Ic auth enable ?\&
-command.
-.It Ic status
-Lists the current status of the various types of
-authentication.
-.El
-.It Ic close
-Close a
-.Tn TELNET
-session and return to command mode.
-.It Ic display Ar argument ...
-Displays all, or some, of the
-.Ic set
-and
-.Ic toggle
-values (see below).
-.It Ic encrypt Ar argument ...
-The encrypt command manipulates the information sent through the
-.Dv TELNET ENCRYPT
-option.
-.Pp
-Valid arguments for the
-.Ic encrypt
-command are:
-.Bl -tag -width Ar
-.It Ic disable Ar type Xo
-.Op Cm input | output
-.Xc
-Disables the specified type of encryption. If you
-omit the input and output, both input and output
-are disabled. To obtain a list of available
-types, use the
-.Ic encrypt disable ?\&
-command.
-.It Ic enable Ar type Xo
-.Op Cm input | output
-.Xc
-Enables the specified type of encryption. If you
-omit input and output, both input and output are
-enabled. To obtain a list of available types, use the
-.Ic encrypt enable ?\&
-command.
-.It Ic input
-This is the same as the
-.Ic encrypt start input
-command.
-.It Ic -input
-This is the same as the
-.Ic encrypt stop input
-command.
-.It Ic output
-This is the same as the
-.Ic encrypt start output
-command.
-.It Ic -output
-This is the same as the
-.Ic encrypt stop output
-command.
-.It Ic start Op Cm input | output
-Attempts to start encryption. If you omit
-.Ic input
-and
-.Ic output ,
-both input and output are enabled. To
-obtain a list of available types, use the
-.Ic encrypt enable ?\&
-command.
-.It Ic status
-Lists the current status of encryption.
-.It Ic stop Op Cm input | output
-Stops encryption. If you omit input and output,
-encryption is on both input and output.
-.It Ic type Ar type
-Sets the default type of encryption to be used
-with later
-.Ic encrypt start
-or
-.Ic encrypt stop
-commands.
-.El
-.It Ic environ Ar arguments ...
-The
-.Ic environ
-command is used to manipulate the
-variables that may be sent through the
-.Dv TELNET ENVIRON
-option.
-The initial set of variables is taken from the users
-environment, with only the
-.Ev DISPLAY
-and
-.Ev PRINTER
-variables being exported by default.
-The
-.Ev USER
-variable is also exported if the
-.Fl a
-or
-.Fl l
-options are used.
-.Pp
-Valid arguments for the
-.Ic environ
-command are:
-.Bl -tag -width Fl
-.It Ic define Ar variable value
-Define the variable
-.Ar variable
-to have a value of
-.Ar value .
-Any variables defined by this command are automatically exported.
-The
-.Ar value
-may be enclosed in single or double quotes so
-that tabs and spaces may be included.
-.It Ic undefine Ar variable
-Remove
-.Ar variable
-from the list of environment variables.
-.It Ic export Ar variable
-Mark the variable
-.Ar variable
-to be exported to the remote side.
-.It Ic unexport Ar variable
-Mark the variable
-.Ar variable
-to not be exported unless
-explicitly asked for by the remote side.
-.It Ic list
-List the current set of environment variables.
-Those marked with a
-.Cm *
-will be sent automatically,
-other variables will only be sent if explicitly requested.
-.It Ic ?\&
-Prints out help information for the
-.Ic environ
-command.
-.El
-.It Ic logout
-Sends the
-.Dv TELNET LOGOUT
-option to the remote side.
-This command is similar to a
-.Ic close
-command; however, if the remote side does not support the
-.Dv LOGOUT
-option, nothing happens.
-If, however, the remote side does support the
-.Dv LOGOUT
-option, this command should cause the remote side to close the
-.Tn TELNET
-connection.
-If the remote side also supports the concept of
-suspending a user's session for later reattachment,
-the logout argument indicates that you
-should terminate the session immediately.
-.It Ic mode Ar type
-.Ar Type
-is one of several options, depending on the state of the
-.Tn TELNET
-session.
-The remote host is asked for permission to go into the requested mode.
-If the remote host is capable of entering that mode, the requested
-mode will be entered.
-.Bl -tag -width Ar
-.It Ic character
-Disable the
-.Dv TELNET LINEMODE
-option, or, if the remote side does not understand the
-.Dv LINEMODE
-option, then enter \*(Lqcharacter at a time\*(Rq mode.
-.It Ic line
-Enable the
-.Dv TELNET LINEMODE
-option, or, if the remote side does not understand the
-.Dv LINEMODE
-option, then attempt to enter \*(Lqold-line-by-line\*(Rq mode.
-.It Ic isig Pq Ic \-isig
-Attempt to enable (disable) the
-.Dv TRAPSIG
-mode of the
-.Dv LINEMODE
-option.
-This requires that the
-.Dv LINEMODE
-option be enabled.
-.It Ic edit Pq Ic \-edit
-Attempt to enable (disable) the
-.Dv EDIT
-mode of the
-.Dv LINEMODE
-option.
-This requires that the
-.Dv LINEMODE
-option be enabled.
-.It Ic softtabs Pq Ic \-softtabs
-Attempt to enable (disable) the
-.Dv SOFT_TAB
-mode of the
-.Dv LINEMODE
-option.
-This requires that the
-.Dv LINEMODE
-option be enabled.
-.It Ic litecho Pq Ic \-litecho
-Attempt to enable (disable) the
-.Dv LIT_ECHO
-mode of the
-.Dv LINEMODE
-option.
-This requires that the
-.Dv LINEMODE
-option be enabled.
-.It Ic ?\&
-Prints out help information for the
-.Ic mode
-command.
-.El
-.It Xo
-.Ic open Ar host
-.Op Fl l Ar user
-.Op Oo Fl Oc Ns Ar port
-.Xc
-Open a connection to the named host.
-If no port number
-is specified,
-.Nm
-will attempt to contact a
-.Tn TELNET
-server at the default port.
-The host specification may be either a host name (see
-.Xr hosts 5 ) ,
-an Internet address specified in the \*(Lqdot notation\*(Rq (see
-.Xr inet 3 ) ,
-or IPv6 host name or IPv6 coloned-hexadecimal addreess.
-The
-.Fl l
-option may be used to specify the user name
-to be passed to the remote system via the
-.Ev ENVIRON
-option.
-When connecting to a non-standard port,
-.Nm
-omits any automatic initiation of
-.Tn TELNET
-options. When the port number is preceded by a minus sign,
-the initial option negotiation is done.
-After establishing a connection, the file
-.Pa \&.telnetrc
-in the
-users home directory is opened. Lines beginning with a # are
-comment lines. Blank lines are ignored. Lines that begin
-without white space are the start of a machine entry. The
-first thing on the line is the name of the machine that is
-being connected to. The rest of the line, and successive
-lines that begin with white space are assumed to be
-.Nm
-commands and are processed as if they had been typed
-in manually to the
-.Nm
-command prompt.
-.It Ic quit
-Close any open
-.Tn TELNET
-session and exit
-.Nm .
-An end of file (in command mode) will also close a session and exit.
-.It Ic send Ar arguments
-Sends one or more special character sequences to the remote host.
-The following are the arguments which may be specified
-(more than one argument may be specified at a time):
-.Pp
-.Bl -tag -width escape
-.It Ic abort
-Sends the
-.Dv TELNET ABORT
-(Abort
-processes)
-sequence.
-.It Ic ao
-Sends the
-.Dv TELNET AO
-(Abort Output) sequence, which should cause the remote system to flush
-all output
-.Em from
-the remote system
-.Em to
-the user's terminal.
-.It Ic ayt
-Sends the
-.Dv TELNET AYT
-(Are You There)
-sequence, to which the remote system may or may not choose to respond.
-.It Ic brk
-Sends the
-.Dv TELNET BRK
-(Break) sequence, which may have significance to the remote
-system.
-.It Ic ec
-Sends the
-.Dv TELNET EC
-(Erase Character)
-sequence, which should cause the remote system to erase the last character
-entered.
-.It Ic el
-Sends the
-.Dv TELNET EL
-(Erase Line)
-sequence, which should cause the remote system to erase the line currently
-being entered.
-.It Ic eof
-Sends the
-.Dv TELNET EOF
-(End Of File)
-sequence.
-.It Ic eor
-Sends the
-.Dv TELNET EOR
-(End of Record)
-sequence.
-.It Ic escape
-Sends the current
-.Nm
-escape character (initially \*(Lq^\*(Rq).
-.It Ic ga
-Sends the
-.Dv TELNET GA
-(Go Ahead)
-sequence, which likely has no significance to the remote system.
-.It Ic getstatus
-If the remote side supports the
-.Dv TELNET STATUS
-command,
-.Ic getstatus
-will send the subnegotiation to request that the server send
-its current option status.
-.It Ic ip
-Sends the
-.Dv TELNET IP
-(Interrupt Process) sequence, which should cause the remote
-system to abort the currently running process.
-.It Ic nop
-Sends the
-.Dv TELNET NOP
-(No OPeration)
-sequence.
-.It Ic susp
-Sends the
-.Dv TELNET SUSP
-(SUSPend process)
-sequence.
-.It Ic synch
-Sends the
-.Dv TELNET SYNCH
-sequence.
-This sequence causes the remote system to discard all previously typed
-(but not yet read) input.
-This sequence is sent as
-.Tn TCP
-urgent
-data (and may not work if the remote system is a
-.Bx 4.2
-system -- if
-it doesn't work, a lower case \*(Lqr\*(Rq may be echoed on the terminal).
-.It Ic do Ar cmd
-.It Ic dont Ar cmd
-.It Ic will Ar cmd
-.It Ic wont Ar cmd
-Sends the
-.Dv TELNET DO
-.Ar cmd
-sequence.
-.Ar Cmd
-can be either a decimal number between 0 and 255,
-or a symbolic name for a specific
-.Dv TELNET
-command.
-.Ar Cmd
-can also be either
-.Ic help
-or
-.Ic ?\&
-to print out help information, including
-a list of known symbolic names.
-.It Ic ?\&
-Prints out help information for the
-.Ic send
-command.
-.El
-.It Ic set Ar argument value
-.It Ic unset Ar argument value
-The
-.Ic set
-command will set any one of a number of
-.Nm
-variables to a specific value or to
-.Dv TRUE .
-The special value
-.Ic off
-turns off the function associated with
-the variable, this is equivalent to using the
-.Ic unset
-command.
-The
-.Ic unset
-command will disable or set to
-.Dv FALSE
-any of the specified functions.
-The values of variables may be interrogated with the
-.Ic display
-command.
-The variables which may be set or unset, but not toggled, are
-listed here. In addition, any of the variables for the
-.Ic toggle
-command may be explicitly set or unset using
-the
-.Ic set
-and
-.Ic unset
-commands.
-.Bl -tag -width escape
-.It Ic ayt
-If
-.Tn TELNET
-is in localchars mode, or
-.Dv LINEMODE
-is enabled, and the status character is typed, a
-.Dv TELNET AYT
-sequence (see
-.Ic send ayt
-preceding) is sent to the
-remote host. The initial value for the \*(LqAre You There\*(Rq
-character is the terminal's status character.
-.It Ic echo
-This is the value (initially \*(Lq^E\*(Rq) which, when in
-\*(Lqline by line\*(Rq mode, toggles between doing local echoing
-of entered characters (for normal processing), and suppressing
-echoing of entered characters (for entering, say, a password).
-.It Ic eof
-If
-.Nm
-is operating in
-.Dv LINEMODE
-or \*(Lqold line by line\*(Rq mode, entering this character
-as the first character on a line will cause this character to be
-sent to the remote system.
-The initial value of the eof character is taken to be the terminal's
-.Ic eof
-character.
-.It Ic erase
-If
-.Nm
-is in
-.Ic localchars
-mode (see
-.Ic toggle
-.Ic localchars
-below),
-.Sy and
-if
-.Nm
-is operating in \*(Lqcharacter at a time\*(Rq mode, then when this
-character is typed, a
-.Dv TELNET EC
-sequence (see
-.Ic send
-.Ic ec
-above)
-is sent to the remote system.
-The initial value for the erase character is taken to be
-the terminal's
-.Ic erase
-character.
-.It Ic escape
-This is the
-.Nm
-escape character (initially \*(Lq^[\*(Rq) which causes entry
-into
-.Nm
-command mode (when connected to a remote system).
-.It Ic flushoutput
-If
-.Nm
-is in
-.Ic localchars
-mode (see
-.Ic toggle
-.Ic localchars
-below)
-and the
-.Ic flushoutput
-character is typed, a
-.Dv TELNET AO
-sequence (see
-.Ic send
-.Ic ao
-above)
-is sent to the remote host.
-The initial value for the flush character is taken to be
-the terminal's
-.Ic flush
-character.
-.It Ic forw1
-.It Ic forw2
-If
-.Nm
-is operating in
-.Dv LINEMODE ,
-these are the
-characters that, when typed, cause partial lines to be
-forwarded to the remote system. The initial value for
-the forwarding characters are taken from the terminal's
-eol and eol2 characters.
-.It Ic interrupt
-If
-.Nm
-is in
-.Ic localchars
-mode (see
-.Ic toggle
-.Ic localchars
-below)
-and the
-.Ic interrupt
-character is typed, a
-.Dv TELNET IP
-sequence (see
-.Ic send
-.Ic ip
-above)
-is sent to the remote host.
-The initial value for the interrupt character is taken to be
-the terminal's
-.Ic intr
-character.
-.It Ic kill
-If
-.Nm
-is in
-.Ic localchars
-mode (see
-.Ic toggle
-.Ic localchars
-below),
-.Ic and
-if
-.Nm
-is operating in \*(Lqcharacter at a time\*(Rq mode, then when this
-character is typed, a
-.Dv TELNET EL
-sequence (see
-.Ic send
-.Ic el
-above)
-is sent to the remote system.
-The initial value for the kill character is taken to be
-the terminal's
-.Ic kill
-character.
-.It Ic lnext
-If
-.Nm
-is operating in
-.Dv LINEMODE
-or \*(Lqold line by line\*(Rq mode, then this character is taken to
-be the terminal's
-.Ic lnext
-character.
-The initial value for the lnext character is taken to be
-the terminal's
-.Ic lnext
-character.
-.It Ic quit
-If
-.Nm
-is in
-.Ic localchars
-mode (see
-.Ic toggle
-.Ic localchars
-below)
-and the
-.Ic quit
-character is typed, a
-.Dv TELNET BRK
-sequence (see
-.Ic send
-.Ic brk
-above)
-is sent to the remote host.
-The initial value for the quit character is taken to be
-the terminal's
-.Ic quit
-character.
-.It Ic reprint
-If
-.Nm
-is operating in
-.Dv LINEMODE
-or \*(Lqold line by line\*(Rq mode, then this character is taken to
-be the terminal's
-.Ic reprint
-character.
-The initial value for the reprint character is taken to be
-the terminal's
-.Ic reprint
-character.
-.It Ic rlogin
-This is the rlogin escape character.
-If set, the normal
-.Nm
-escape character is ignored unless it is
-preceded by this character at the beginning of a line.
-This character, at the beginning of a line followed by
-a "." closes the connection; when followed by a ^Z it
-suspends the
-.Nm
-command. The initial state is to
-disable the
-.Nm rlogin
-escape character.
-.It Ic start
-If the
-.Dv TELNET TOGGLE-FLOW-CONTROL
-option has been enabled,
-then this character is taken to
-be the terminal's
-.Ic start
-character.
-The initial value for the start character is taken to be
-the terminal's
-.Ic start
-character.
-.It Ic stop
-If the
-.Dv TELNET TOGGLE-FLOW-CONTROL
-option has been enabled,
-then this character is taken to
-be the terminal's
-.Ic stop
-character.
-The initial value for the stop character is taken to be
-the terminal's
-.Ic stop
-character.
-.It Ic susp
-If
-.Nm
-is in
-.Ic localchars
-mode, or
-.Dv LINEMODE
-is enabled, and the
-.Ic suspend
-character is typed, a
-.Dv TELNET SUSP
-sequence (see
-.Ic send
-.Ic susp
-above)
-is sent to the remote host.
-The initial value for the suspend character is taken to be
-the terminal's
-.Ic suspend
-character.
-.It Ic tracefile
-This is the file to which the output, caused by
-.Ic netdata
-or
-.Ic option
-tracing being
-.Dv TRUE ,
-will be written. If it is set to
-.Dq Fl ,
-then tracing information will be written to standard output (the default).
-.It Ic worderase
-If
-.Nm
-is operating in
-.Dv LINEMODE
-or \*(Lqold line by line\*(Rq mode, then this character is taken to
-be the terminal's
-.Ic worderase
-character.
-The initial value for the worderase character is taken to be
-the terminal's
-.Ic worderase
-character.
-.It Ic ?\&
-Displays the legal
-.Ic set
-.Pq Ic unset
-commands.
-.El
-.It Ic opie Ar sequence challenge
-The
-.Ic opie
-command computes a response to the OPIE challenge.
-.It Ic slc Ar state
-The
-.Ic slc
-command (Set Local Characters) is used to set
-or change the state of the special
-characters when the
-.Dv TELNET LINEMODE
-option has
-been enabled. Special characters are characters that get
-mapped to
-.Tn TELNET
-commands sequences (like
-.Ic ip
-or
-.Ic quit )
-or line editing characters (like
-.Ic erase
-and
-.Ic kill ) .
-By default, the local special characters are exported.
-.Bl -tag -width Fl
-.It Ic check
-Verify the current settings for the current special characters.
-The remote side is requested to send all the current special
-character settings, and if there are any discrepancies with
-the local side, the local side will switch to the remote value.
-.It Ic export
-Switch to the local defaults for the special characters. The
-local default characters are those of the local terminal at
-the time when
-.Nm
-was started.
-.It Ic import
-Switch to the remote defaults for the special characters.
-The remote default characters are those of the remote system
-at the time when the
-.Tn TELNET
-connection was established.
-.It Ic ?\&
-Prints out help information for the
-.Ic slc
-command.
-.El
-.It Ic status
-Show the current status of
-.Nm .
-This includes the peer one is connected to, as well
-as the current mode.
-.It Ic toggle Ar arguments ...
-Toggle (between
-.Dv TRUE
-and
-.Dv FALSE )
-various flags that control how
-.Nm
-responds to events.
-These flags may be set explicitly to
-.Dv TRUE
-or
-.Dv FALSE
-using the
-.Ic set
-and
-.Ic unset
-commands listed above.
-More than one argument may be specified.
-The state of these flags may be interrogated with the
-.Ic display
-command.
-Valid arguments are:
-.Bl -tag -width Ar
-.It Ic authdebug
-Turns on debugging information for the authentication code.
-.It Ic autoflush
-If
-.Ic autoflush
-and
-.Ic localchars
-are both
-.Dv TRUE ,
-then when the
-.Ic ao ,
-or
-.Ic quit
-characters are recognized (and transformed into
-.Tn TELNET
-sequences; see
-.Ic set
-above for details),
-.Nm
-refuses to display any data on the user's terminal
-until the remote system acknowledges (via a
-.Dv TELNET TIMING MARK
-option)
-that it has processed those
-.Tn TELNET
-sequences.
-The initial value for this toggle is
-.Dv TRUE
-if the terminal user had not
-done an "stty noflsh", otherwise
-.Dv FALSE
-(see
-.Xr stty 1 ) .
-.It Ic autodecrypt
-When the
-.Dv TELNET ENCRYPT
-option is negotiated, by
-default the actual encryption (decryption) of the data
-stream does not start automatically. The autoencrypt
-(autodecrypt) command states that encryption of the
-output (input) stream should be enabled as soon as
-possible.
-.It Ic autologin
-If the remote side supports the
-.Dv TELNET AUTHENTICATION
-option
-.Nm
-attempts to use it to perform automatic authentication. If the
-.Dv AUTHENTICATION
-option is not supported, the user's login
-name are propagated through the
-.Dv TELNET ENVIRON
-option.
-This command is the same as specifying
-.Fl a
-option on the
-.Ic open
-command.
-.It Ic autosynch
-If
-.Ic autosynch
-and
-.Ic localchars
-are both
-.Dv TRUE ,
-then when either the
-.Ic intr
-or
-.Ic quit
-characters is typed (see
-.Ic set
-above for descriptions of the
-.Ic intr
-and
-.Ic quit
-characters), the resulting
-.Tn TELNET
-sequence sent is followed by the
-.Dv TELNET SYNCH
-sequence.
-This procedure
-.Ic should
-cause the remote system to begin throwing away all previously
-typed input until both of the
-.Tn TELNET
-sequences have been read and acted upon.
-The initial value of this toggle is
-.Dv FALSE .
-.It Ic binary
-Enable or disable the
-.Dv TELNET BINARY
-option on both input and output.
-.It Ic inbinary
-Enable or disable the
-.Dv TELNET BINARY
-option on input.
-.It Ic outbinary
-Enable or disable the
-.Dv TELNET BINARY
-option on output.
-.It Ic crlf
-If this is
-.Dv TRUE ,
-then carriage returns will be sent as
-.Li <CR><LF> .
-If this is
-.Dv FALSE ,
-then carriage returns will be send as
-.Li <CR><NUL> .
-The initial value for this toggle is
-.Dv FALSE .
-.It Ic crmod
-Toggle carriage return mode.
-When this mode is enabled, most carriage return characters received from
-the remote host will be mapped into a carriage return followed by
-a line feed.
-This mode does not affect those characters typed by the user, only
-those received from the remote host.
-This mode is not very useful unless the remote host
-only sends carriage return, but never line feed.
-The initial value for this toggle is
-.Dv FALSE .
-.It Ic debug
-Toggles socket level debugging (useful only to the
-.Ic super user ) .
-The initial value for this toggle is
-.Dv FALSE .
-.It Ic encdebug
-Turns on debugging information for the encryption code.
-.It Ic localchars
-If this is
-.Dv TRUE ,
-then the
-.Ic flush ,
-.Ic interrupt ,
-.Ic quit ,
-.Ic erase ,
-and
-.Ic kill
-characters (see
-.Ic set
-above) are recognized locally, and transformed into (hopefully) appropriate
-.Tn TELNET
-control sequences
-(respectively
-.Ic ao ,
-.Ic ip ,
-.Ic brk ,
-.Ic ec ,
-and
-.Ic el ;
-see
-.Ic send
-above).
-The initial value for this toggle is
-.Dv TRUE
-in \*(Lqold line by line\*(Rq mode,
-and
-.Dv FALSE
-in \*(Lqcharacter at a time\*(Rq mode.
-When the
-.Dv LINEMODE
-option is enabled, the value of
-.Ic localchars
-is ignored, and assumed to always be
-.Dv TRUE .
-If
-.Dv LINEMODE
-has ever been enabled, then
-.Ic quit
-is sent as
-.Ic abort ,
-and
-.Ic eof
-and
-.Ic suspend
-are sent as
-.Ic eof
-and
-.Ic susp
-(see
-.Ic send
-above).
-.It Ic netdata
-Toggles the display of all network data (in hexadecimal format).
-The initial value for this toggle is
-.Dv FALSE .
-.It Ic options
-Toggles the display of some internal
-.Nm
-protocol processing (having to do with
-.Tn TELNET
-options).
-The initial value for this toggle is
-.Dv FALSE .
-.It Ic prettydump
-When the
-.Ic netdata
-toggle is enabled, if
-.Ic prettydump
-is enabled the output from the
-.Ic netdata
-command will be formatted in a more user readable format.
-Spaces are put between each character in the output, and the
-beginning of any
-.Nm
-escape sequence is preceded by a '*' to aid in locating them.
-.It Ic skiprc
-When the skiprc toggle is
-.Dv TRUE ,
-.Nm
-skips the reading of the
-.Pa \&.telnetrc
-file in the users home
-directory when connections are opened. The initial
-value for this toggle is
-.Dv FALSE .
-.It Ic termdata
-Toggles the display of all terminal data (in hexadecimal format).
-The initial value for this toggle is
-.Dv FALSE .
-.It Ic verbose_encrypt
-When the
-.Ic verbose_encrypt
-toggle is
-.Dv TRUE ,
-.Nm
-prints out a message each time encryption is enabled or
-disabled. The initial value for this toggle is
-.Dv FALSE .
-.It Ic ?\&
-Displays the legal
-.Ic toggle
-commands.
-.El
-.It Ic z
-Suspend
-.Nm .
-This command only works when the user is using the
-.Xr csh 1 .
-.It Ic \&! Op Ar command
-Execute a single command in a subshell on the local
-system. If
-.Ar command
-is omitted, then an interactive
-subshell is invoked.
-.It Ic ?\& Op Ar command
-Get help. With no arguments,
-.Nm
-prints a help summary.
-If
-.Ar command
-is specified,
-.Nm
-will print the help information for just that command.
-.El
-.Sh ENVIRONMENT
-.Nm
-uses at least the
-.Ev HOME ,
-.Ev SHELL ,
-.Ev DISPLAY ,
-and
-.Ev TERM
-environment variables.
-Other environment variables may be propagated
-to the other side via the
-.Dv TELNET ENVIRON
-option.
-.Sh SEE ALSO
-.Xr rlogin 1 ,
-.Xr rsh 1 ,
-.Xr hosts 5 ,
-.Xr nologin 5 ,
-.Xr telnetd 8
-.Sh FILES
-.Bl -tag -width ~/.telnetrc -compact
-.It Pa ~/.telnetrc
-user customized telnet startup values
-.El
-.Sh HISTORY
-The
-.Nm
-command appeared in
-.Bx 4.2 .
-.Pp
-IPv6 support was added by WIDE/KAME project.
-.Sh NOTES
-On some remote systems, echo has to be turned off manually when in
-\*(Lqold line by line\*(Rq mode.
-.Pp
-In \*(Lqold line by line\*(Rq mode or
-.Dv LINEMODE
-the terminal's
-.Ic eof
-character is only recognized (and sent to the remote system)
-when it is the first character on a line.
diff --git a/contrib/telnet/telnet/telnet.c b/contrib/telnet/telnet/telnet.c
deleted file mode 100644
index 82ee4649b703..000000000000
--- a/contrib/telnet/telnet/telnet.c
+++ /dev/null
@@ -1,2378 +0,0 @@
-/*
- * Copyright (c) 1988, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)telnet.c 8.4 (Berkeley) 5/30/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-
-/* By the way, we need to include curses.h before telnet.h since,
- * among other things, telnet.h #defines 'DO', which is a variable
- * declared in curses.h.
- */
-
-#include <ctype.h>
-#include <curses.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <term.h>
-#include <unistd.h>
-#include <arpa/telnet.h>
-
-#include "ring.h"
-
-#include "defines.h"
-#include "externs.h"
-#include "types.h"
-#include "general.h"
-
-#ifdef AUTHENTICATION
-#include <libtelnet/auth.h>
-#endif
-#ifdef ENCRYPTION
-#include <libtelnet/encrypt.h>
-#endif
-#include <libtelnet/misc.h>
-
-#define strip(x) ((my_want_state_is_wont(TELOPT_BINARY)) ? ((x)&0x7f) : (x))
-
-static unsigned char subbuffer[SUBBUFSIZE],
- *subpointer, *subend; /* buffer for sub-options */
-#define SB_CLEAR() subpointer = subbuffer;
-#define SB_TERM() { subend = subpointer; SB_CLEAR(); }
-#define SB_ACCUM(c) if (subpointer < (subbuffer+sizeof subbuffer)) { \
- *subpointer++ = (c); \
- }
-
-#define SB_GET() ((*subpointer++)&0xff)
-#define SB_PEEK() ((*subpointer)&0xff)
-#define SB_EOF() (subpointer >= subend)
-#define SB_LEN() (subend - subpointer)
-
-char options[256]; /* The combined options */
-char do_dont_resp[256];
-char will_wont_resp[256];
-
-int
- eight = 0,
- autologin = 0, /* Autologin anyone? */
- skiprc = 0,
- connected,
- showoptions,
- ISend, /* trying to send network data in */
- telnet_debug = 0,
- crmod,
- netdata, /* Print out network data flow */
- crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
- telnetport,
- SYNCHing, /* we are in TELNET SYNCH mode */
- flushout, /* flush output */
- autoflush = 0, /* flush output when interrupting? */
- autosynch, /* send interrupt characters with SYNCH? */
- localflow, /* we handle flow control locally */
- restartany, /* if flow control enabled, restart on any character */
- localchars, /* we recognize interrupt/quit */
- donelclchars, /* the user has set "localchars" */
- donebinarytoggle, /* the user has put us in binary */
- dontlecho, /* do we suppress local echoing right now? */
- globalmode,
- doaddrlookup = 1, /* do a reverse address lookup? */
- clienteof = 0;
-
-char *prompt = 0;
-#ifdef ENCRYPTION
-char *line; /* hack around breakage in sra.c :-( !! */
-#endif
-
-cc_t escape;
-cc_t rlogin;
-#ifdef KLUDGELINEMODE
-cc_t echoc;
-#endif
-
-/*
- * Telnet receiver states for fsm
- */
-#define TS_DATA 0
-#define TS_IAC 1
-#define TS_WILL 2
-#define TS_WONT 3
-#define TS_DO 4
-#define TS_DONT 5
-#define TS_CR 6
-#define TS_SB 7 /* sub-option collection */
-#define TS_SE 8 /* looking for sub-option end */
-
-static int telrcv_state;
-#ifdef OLD_ENVIRON
-unsigned char telopt_environ = TELOPT_NEW_ENVIRON;
-#else
-# define telopt_environ TELOPT_NEW_ENVIRON
-#endif
-
-jmp_buf toplevel;
-jmp_buf peerdied;
-
-int flushline;
-int linemode;
-
-#ifdef KLUDGELINEMODE
-int kludgelinemode = 1;
-#endif
-
-static int is_unique(char *, char **, char **);
-
-/*
- * The following are some clocks used to decide how to interpret
- * the relationship between various variables.
- */
-
-Clocks clocks;
-
-/*
- * Initialize telnet environment.
- */
-
-void
-init_telnet(void)
-{
- env_init();
-
- SB_CLEAR();
- ClearArray(options);
-
- connected = ISend = localflow = donebinarytoggle = 0;
-#ifdef AUTHENTICATION
-#ifdef ENCRYPTION
- auth_encrypt_connect(connected);
-#endif
-#endif
- restartany = -1;
-
- SYNCHing = 0;
-
- /* Don't change NetTrace */
-
- escape = CONTROL(']');
- rlogin = _POSIX_VDISABLE;
-#ifdef KLUDGELINEMODE
- echoc = CONTROL('E');
-#endif
-
- flushline = 1;
- telrcv_state = TS_DATA;
-}
-
-
-/*
- * These routines are in charge of sending option negotiations
- * to the other side.
- *
- * The basic idea is that we send the negotiation if either side
- * is in disagreement as to what the current state should be.
- */
-
-void
-send_do(int c, int init)
-{
- if (init) {
- if (((do_dont_resp[c] == 0) && my_state_is_do(c)) ||
- my_want_state_is_do(c))
- return;
- set_my_want_state_do(c);
- do_dont_resp[c]++;
- }
- NET2ADD(IAC, DO);
- NETADD(c);
- printoption("SENT", DO, c);
-}
-
-void
-send_dont(int c, int init)
-{
- if (init) {
- if (((do_dont_resp[c] == 0) && my_state_is_dont(c)) ||
- my_want_state_is_dont(c))
- return;
- set_my_want_state_dont(c);
- do_dont_resp[c]++;
- }
- NET2ADD(IAC, DONT);
- NETADD(c);
- printoption("SENT", DONT, c);
-}
-
-void
-send_will(int c, int init)
-{
- if (init) {
- if (((will_wont_resp[c] == 0) && my_state_is_will(c)) ||
- my_want_state_is_will(c))
- return;
- set_my_want_state_will(c);
- will_wont_resp[c]++;
- }
- NET2ADD(IAC, WILL);
- NETADD(c);
- printoption("SENT", WILL, c);
-}
-
-void
-send_wont(int c, int init)
-{
- if (init) {
- if (((will_wont_resp[c] == 0) && my_state_is_wont(c)) ||
- my_want_state_is_wont(c))
- return;
- set_my_want_state_wont(c);
- will_wont_resp[c]++;
- }
- NET2ADD(IAC, WONT);
- NETADD(c);
- printoption("SENT", WONT, c);
-}
-
-void
-willoption(int option)
-{
- int new_state_ok = 0;
-
- if (do_dont_resp[option]) {
- --do_dont_resp[option];
- if (do_dont_resp[option] && my_state_is_do(option))
- --do_dont_resp[option];
- }
-
- if ((do_dont_resp[option] == 0) && my_want_state_is_dont(option)) {
-
- switch (option) {
-
- case TELOPT_ECHO:
- case TELOPT_BINARY:
- case TELOPT_SGA:
- settimer(modenegotiated);
- /* FALLTHROUGH */
- case TELOPT_STATUS:
-#ifdef AUTHENTICATION
- case TELOPT_AUTHENTICATION:
-#endif
-#ifdef ENCRYPTION
- case TELOPT_ENCRYPT:
-#endif /* ENCRYPTION */
- new_state_ok = 1;
- break;
-
- case TELOPT_TM:
- if (flushout)
- flushout = 0;
- /*
- * Special case for TM. If we get back a WILL,
- * pretend we got back a WONT.
- */
- set_my_want_state_dont(option);
- set_my_state_dont(option);
- return; /* Never reply to TM will's/wont's */
-
- case TELOPT_LINEMODE:
- default:
- break;
- }
-
- if (new_state_ok) {
- set_my_want_state_do(option);
- send_do(option, 0);
- setconnmode(0); /* possibly set new tty mode */
- } else {
- do_dont_resp[option]++;
- send_dont(option, 0);
- }
- }
- set_my_state_do(option);
-#ifdef ENCRYPTION
- if (option == TELOPT_ENCRYPT)
- encrypt_send_support();
-#endif /* ENCRYPTION */
-}
-
-void
-wontoption(int option)
-{
- if (do_dont_resp[option]) {
- --do_dont_resp[option];
- if (do_dont_resp[option] && my_state_is_dont(option))
- --do_dont_resp[option];
- }
-
- if ((do_dont_resp[option] == 0) && my_want_state_is_do(option)) {
-
- switch (option) {
-
-#ifdef KLUDGELINEMODE
- case TELOPT_SGA:
- if (!kludgelinemode)
- break;
- /* FALLTHROUGH */
-#endif
- case TELOPT_ECHO:
- settimer(modenegotiated);
- break;
-
- case TELOPT_TM:
- if (flushout)
- flushout = 0;
- set_my_want_state_dont(option);
- set_my_state_dont(option);
- return; /* Never reply to TM will's/wont's */
-
- default:
- break;
- }
- set_my_want_state_dont(option);
- if (my_state_is_do(option))
- send_dont(option, 0);
- setconnmode(0); /* Set new tty mode */
- } else if (option == TELOPT_TM) {
- /*
- * Special case for TM.
- */
- if (flushout)
- flushout = 0;
- set_my_want_state_dont(option);
- }
- set_my_state_dont(option);
-}
-
-static void
-dooption(int option)
-{
- int new_state_ok = 0;
-
- if (will_wont_resp[option]) {
- --will_wont_resp[option];
- if (will_wont_resp[option] && my_state_is_will(option))
- --will_wont_resp[option];
- }
-
- if (will_wont_resp[option] == 0) {
- if (my_want_state_is_wont(option)) {
-
- switch (option) {
-
- case TELOPT_TM:
- /*
- * Special case for TM. We send a WILL, but pretend
- * we sent WONT.
- */
- send_will(option, 0);
- set_my_want_state_wont(TELOPT_TM);
- set_my_state_wont(TELOPT_TM);
- return;
-
- case TELOPT_BINARY: /* binary mode */
- case TELOPT_NAWS: /* window size */
- case TELOPT_TSPEED: /* terminal speed */
- case TELOPT_LFLOW: /* local flow control */
- case TELOPT_TTYPE: /* terminal type option */
- case TELOPT_SGA: /* no big deal */
-#ifdef ENCRYPTION
- case TELOPT_ENCRYPT: /* encryption variable option */
-#endif /* ENCRYPTION */
- new_state_ok = 1;
- break;
-
- case TELOPT_NEW_ENVIRON: /* New environment variable option */
-#ifdef OLD_ENVIRON
- if (my_state_is_will(TELOPT_OLD_ENVIRON))
- send_wont(TELOPT_OLD_ENVIRON, 1); /* turn off the old */
- goto env_common;
- case TELOPT_OLD_ENVIRON: /* Old environment variable option */
- if (my_state_is_will(TELOPT_NEW_ENVIRON))
- break; /* Don't enable if new one is in use! */
- env_common:
- telopt_environ = option;
-#endif
- new_state_ok = 1;
- break;
-
-#ifdef AUTHENTICATION
- case TELOPT_AUTHENTICATION:
- if (autologin)
- new_state_ok = 1;
- break;
-#endif
-
- case TELOPT_XDISPLOC: /* X Display location */
- if (env_getvalue("DISPLAY"))
- new_state_ok = 1;
- break;
-
- case TELOPT_LINEMODE:
-#ifdef KLUDGELINEMODE
- kludgelinemode = 0;
- send_do(TELOPT_SGA, 1);
-#endif
- set_my_want_state_will(TELOPT_LINEMODE);
- send_will(option, 0);
- set_my_state_will(TELOPT_LINEMODE);
- slc_init();
- return;
-
- case TELOPT_ECHO: /* We're never going to echo... */
- default:
- break;
- }
-
- if (new_state_ok) {
- set_my_want_state_will(option);
- send_will(option, 0);
- setconnmode(0); /* Set new tty mode */
- } else {
- will_wont_resp[option]++;
- send_wont(option, 0);
- }
- } else {
- /*
- * Handle options that need more things done after the
- * other side has acknowledged the option.
- */
- switch (option) {
- case TELOPT_LINEMODE:
-#ifdef KLUDGELINEMODE
- kludgelinemode = 0;
- send_do(TELOPT_SGA, 1);
-#endif
- set_my_state_will(option);
- slc_init();
- send_do(TELOPT_SGA, 0);
- return;
- }
- }
- }
- set_my_state_will(option);
-}
-
-static void
-dontoption(int option)
-{
-
- if (will_wont_resp[option]) {
- --will_wont_resp[option];
- if (will_wont_resp[option] && my_state_is_wont(option))
- --will_wont_resp[option];
- }
-
- if ((will_wont_resp[option] == 0) && my_want_state_is_will(option)) {
- switch (option) {
- case TELOPT_LINEMODE:
- linemode = 0; /* put us back to the default state */
- break;
-#ifdef OLD_ENVIRON
- case TELOPT_NEW_ENVIRON:
- /*
- * The new environ option wasn't recognized, try
- * the old one.
- */
- send_will(TELOPT_OLD_ENVIRON, 1);
- telopt_environ = TELOPT_OLD_ENVIRON;
- break;
-#endif
- }
- /* we always accept a DONT */
- set_my_want_state_wont(option);
- if (my_state_is_will(option))
- send_wont(option, 0);
- setconnmode(0); /* Set new tty mode */
- }
- set_my_state_wont(option);
-}
-
-/*
- * Given a buffer returned by tgetent(), this routine will turn
- * the pipe separated list of names in the buffer into an array
- * of pointers to null terminated names. We toss out any bad,
- * duplicate, or verbose names (names with spaces).
- */
-
-static const char *name_unknown = "UNKNOWN";
-static const char *unknown[] = { NULL, NULL };
-
-static const char **
-mklist(char *buf, char *name)
-{
- int n;
- char c, *cp, **argvp, *cp2, **argv, **avt;
-
- if (name) {
- if (strlen(name) > 40) {
- name = 0;
- unknown[0] = name_unknown;
- } else {
- unknown[0] = name;
- upcase(name);
- }
- } else
- unknown[0] = name_unknown;
- /*
- * Count up the number of names.
- */
- for (n = 1, cp = buf; *cp && *cp != ':'; cp++) {
- if (*cp == '|')
- n++;
- }
- /*
- * Allocate an array to put the name pointers into
- */
- argv = (char **)malloc((n+3)*sizeof(char *));
- if (argv == 0)
- return(unknown);
-
- /*
- * Fill up the array of pointers to names.
- */
- *argv = 0;
- argvp = argv+1;
- n = 0;
- for (cp = cp2 = buf; (c = *cp); cp++) {
- if (c == '|' || c == ':') {
- *cp++ = '\0';
- /*
- * Skip entries that have spaces or are over 40
- * characters long. If this is our environment
- * name, then put it up front. Otherwise, as
- * long as this is not a duplicate name (case
- * insensitive) add it to the list.
- */
- if (n || (cp - cp2 > 41))
- ;
- else if (name && (strncasecmp(name, cp2, cp-cp2) == 0))
- *argv = cp2;
- else if (is_unique(cp2, argv+1, argvp))
- *argvp++ = cp2;
- if (c == ':')
- break;
- /*
- * Skip multiple delimiters. Reset cp2 to
- * the beginning of the next name. Reset n,
- * the flag for names with spaces.
- */
- while ((c = *cp) == '|')
- cp++;
- cp2 = cp;
- n = 0;
- }
- /*
- * Skip entries with spaces or non-ascii values.
- * Convert lower case letters to upper case.
- */
- if ((c == ' ') || !isascii(c))
- n = 1;
- else if (islower(c))
- *cp = toupper(c);
- }
-
- /*
- * Check for an old V6 2 character name. If the second
- * name points to the beginning of the buffer, and is
- * only 2 characters long, move it to the end of the array.
- */
- if ((argv[1] == buf) && (strlen(argv[1]) == 2)) {
- --argvp;
- for (avt = &argv[1]; avt < argvp; avt++)
- *avt = *(avt+1);
- *argvp++ = buf;
- }
-
- /*
- * Duplicate last name, for TTYPE option, and null
- * terminate the array. If we didn't find a match on
- * our terminal name, put that name at the beginning.
- */
- cp = *(argvp-1);
- *argvp++ = cp;
- *argvp = 0;
-
- if (*argv == 0) {
- if (name)
- *argv = name;
- else {
- --argvp;
- for (avt = argv; avt < argvp; avt++)
- *avt = *(avt+1);
- }
- }
- if (*argv)
- return((const char **)argv);
- else
- return(unknown);
-}
-
-static int
-is_unique(char *name, char **as, char **ae)
-{
- char **ap;
- int n;
-
- n = strlen(name) + 1;
- for (ap = as; ap < ae; ap++)
- if (strncasecmp(*ap, name, n) == 0)
- return(0);
- return (1);
-}
-
-#ifdef TERMCAP
-char termbuf[1024];
-
-/*ARGSUSED*/
-static int
-setupterm(char *tname, int fd, int *errp)
-{
- if (tgetent(termbuf, tname) == 1) {
- termbuf[1023] = '\0';
- if (errp)
- *errp = 1;
- return(0);
- }
- if (errp)
- *errp = 0;
- return(-1);
-}
-#else
-#define termbuf ttytype
-extern char ttytype[];
-#endif
-
-int resettermname = 1;
-
-static const char *
-gettermname(void)
-{
- char *tname;
- static const char **tnamep = 0;
- static const char **next;
- int err;
-
- if (resettermname) {
- resettermname = 0;
- if (tnamep && tnamep != unknown)
- free(tnamep);
- if ((tname = env_getvalue("TERM")) &&
- (setupterm(tname, 1, &err) == 0)) {
- tnamep = mklist(termbuf, tname);
- } else {
- if (tname && (strlen(tname) <= 40)) {
- unknown[0] = tname;
- upcase(tname);
- } else
- unknown[0] = name_unknown;
- tnamep = unknown;
- }
- next = tnamep;
- }
- if (*next == 0)
- next = tnamep;
- return(*next++);
-}
-/*
- * suboption()
- *
- * Look at the sub-option buffer, and try to be helpful to the other
- * side.
- *
- * Currently we recognize:
- *
- * Terminal type, send request.
- * Terminal speed (send request).
- * Local flow control (is request).
- * Linemode
- */
-
-static void
-suboption(void)
-{
- unsigned char subchar;
-
- printsub('<', subbuffer, SB_LEN()+2);
- switch (subchar = SB_GET()) {
- case TELOPT_TTYPE:
- if (my_want_state_is_wont(TELOPT_TTYPE))
- return;
- if (SB_EOF() || SB_GET() != TELQUAL_SEND) {
- return;
- } else {
- const char *name;
- unsigned char temp[50];
- int len;
-
- name = gettermname();
- len = strlen(name) + 4 + 2;
- if (len < NETROOM()) {
- sprintf(temp, "%c%c%c%c%s%c%c", IAC, SB, TELOPT_TTYPE,
- TELQUAL_IS, name, IAC, SE);
- ring_supply_data(&netoring, temp, len);
- printsub('>', &temp[2], len-2);
- } else {
- ExitString("No room in buffer for terminal type.\n", 1);
- /*NOTREACHED*/
- }
- }
- break;
- case TELOPT_TSPEED:
- if (my_want_state_is_wont(TELOPT_TSPEED))
- return;
- if (SB_EOF())
- return;
- if (SB_GET() == TELQUAL_SEND) {
- long ospeed, ispeed;
- unsigned char temp[50];
- int len;
-
- TerminalSpeeds(&ispeed, &ospeed);
-
- sprintf((char *)temp, "%c%c%c%c%ld,%ld%c%c", IAC, SB, TELOPT_TSPEED,
- TELQUAL_IS, ospeed, ispeed, IAC, SE);
- len = strlen((char *)temp+4) + 4; /* temp[3] is 0 ... */
-
- if (len < NETROOM()) {
- ring_supply_data(&netoring, temp, len);
- printsub('>', temp+2, len - 2);
- }
-/*@*/ else printf("lm_will: not enough room in buffer\n");
- }
- break;
- case TELOPT_LFLOW:
- if (my_want_state_is_wont(TELOPT_LFLOW))
- return;
- if (SB_EOF())
- return;
- switch(SB_GET()) {
- case LFLOW_RESTART_ANY:
- restartany = 1;
- break;
- case LFLOW_RESTART_XON:
- restartany = 0;
- break;
- case LFLOW_ON:
- localflow = 1;
- break;
- case LFLOW_OFF:
- localflow = 0;
- break;
- default:
- return;
- }
- setcommandmode();
- setconnmode(0);
- break;
-
- case TELOPT_LINEMODE:
- if (my_want_state_is_wont(TELOPT_LINEMODE))
- return;
- if (SB_EOF())
- return;
- switch (SB_GET()) {
- case WILL:
- lm_will(subpointer, SB_LEN());
- break;
- case WONT:
- lm_wont(subpointer, SB_LEN());
- break;
- case DO:
- lm_do(subpointer, SB_LEN());
- break;
- case DONT:
- lm_dont(subpointer, SB_LEN());
- break;
- case LM_SLC:
- slc(subpointer, SB_LEN());
- break;
- case LM_MODE:
- lm_mode(subpointer, SB_LEN(), 0);
- break;
- default:
- break;
- }
- break;
-
-#ifdef OLD_ENVIRON
- case TELOPT_OLD_ENVIRON:
-#endif
- case TELOPT_NEW_ENVIRON:
- if (SB_EOF())
- return;
- switch(SB_PEEK()) {
- case TELQUAL_IS:
- case TELQUAL_INFO:
- if (my_want_state_is_dont(subchar))
- return;
- break;
- case TELQUAL_SEND:
- if (my_want_state_is_wont(subchar)) {
- return;
- }
- break;
- default:
- return;
- }
- env_opt(subpointer, SB_LEN());
- break;
-
- case TELOPT_XDISPLOC:
- if (my_want_state_is_wont(TELOPT_XDISPLOC))
- return;
- if (SB_EOF())
- return;
- if (SB_GET() == TELQUAL_SEND) {
- unsigned char temp[50], *dp;
- int len;
-
- if ((dp = env_getvalue("DISPLAY")) == NULL ||
- strlen(dp) > sizeof(temp) - 7) {
- /*
- * Something happened, we no longer have a DISPLAY
- * variable. Or it is too long. So, turn off the option.
- */
- send_wont(TELOPT_XDISPLOC, 1);
- break;
- }
- snprintf(temp, sizeof(temp), "%c%c%c%c%s%c%c", IAC, SB,
- TELOPT_XDISPLOC, TELQUAL_IS, dp, IAC, SE);
- len = strlen((char *)temp+4) + 4; /* temp[3] is 0 ... */
-
- if (len < NETROOM()) {
- ring_supply_data(&netoring, temp, len);
- printsub('>', temp+2, len - 2);
- }
-/*@*/ else printf("lm_will: not enough room in buffer\n");
- }
- break;
-
-#ifdef AUTHENTICATION
- case TELOPT_AUTHENTICATION: {
- if (!autologin)
- break;
- if (SB_EOF())
- return;
- switch(SB_GET()) {
- case TELQUAL_IS:
- if (my_want_state_is_dont(TELOPT_AUTHENTICATION))
- return;
- auth_is(subpointer, SB_LEN());
- break;
- case TELQUAL_SEND:
- if (my_want_state_is_wont(TELOPT_AUTHENTICATION))
- return;
- auth_send(subpointer, SB_LEN());
- break;
- case TELQUAL_REPLY:
- if (my_want_state_is_wont(TELOPT_AUTHENTICATION))
- return;
- auth_reply(subpointer, SB_LEN());
- break;
- case TELQUAL_NAME:
- if (my_want_state_is_dont(TELOPT_AUTHENTICATION))
- return;
- auth_name(subpointer, SB_LEN());
- break;
- }
- }
- break;
-#endif
-#ifdef ENCRYPTION
- case TELOPT_ENCRYPT:
- if (SB_EOF())
- return;
- switch(SB_GET()) {
- case ENCRYPT_START:
- if (my_want_state_is_dont(TELOPT_ENCRYPT))
- return;
- encrypt_start(subpointer, SB_LEN());
- break;
- case ENCRYPT_END:
- if (my_want_state_is_dont(TELOPT_ENCRYPT))
- return;
- encrypt_end();
- break;
- case ENCRYPT_SUPPORT:
- if (my_want_state_is_wont(TELOPT_ENCRYPT))
- return;
- encrypt_support(subpointer, SB_LEN());
- break;
- case ENCRYPT_REQSTART:
- if (my_want_state_is_wont(TELOPT_ENCRYPT))
- return;
- encrypt_request_start(subpointer, SB_LEN());
- break;
- case ENCRYPT_REQEND:
- if (my_want_state_is_wont(TELOPT_ENCRYPT))
- return;
- /*
- * We can always send an REQEND so that we cannot
- * get stuck encrypting. We should only get this
- * if we have been able to get in the correct mode
- * anyhow.
- */
- encrypt_request_end();
- break;
- case ENCRYPT_IS:
- if (my_want_state_is_dont(TELOPT_ENCRYPT))
- return;
- encrypt_is(subpointer, SB_LEN());
- break;
- case ENCRYPT_REPLY:
- if (my_want_state_is_wont(TELOPT_ENCRYPT))
- return;
- encrypt_reply(subpointer, SB_LEN());
- break;
- case ENCRYPT_ENC_KEYID:
- if (my_want_state_is_dont(TELOPT_ENCRYPT))
- return;
- encrypt_enc_keyid(subpointer, SB_LEN());
- break;
- case ENCRYPT_DEC_KEYID:
- if (my_want_state_is_wont(TELOPT_ENCRYPT))
- return;
- encrypt_dec_keyid(subpointer, SB_LEN());
- break;
- default:
- break;
- }
- break;
-#endif /* ENCRYPTION */
- default:
- break;
- }
-}
-
-static unsigned char str_lm[] = { IAC, SB, TELOPT_LINEMODE, 0, 0, IAC, SE };
-
-void
-lm_will(unsigned char *cmd, int len)
-{
- if (len < 1) {
-/*@*/ printf("lm_will: no command!!!\n"); /* Should not happen... */
- return;
- }
- switch(cmd[0]) {
- case LM_FORWARDMASK: /* We shouldn't ever get this... */
- default:
- str_lm[3] = DONT;
- str_lm[4] = cmd[0];
- if (NETROOM() > (int)sizeof(str_lm)) {
- ring_supply_data(&netoring, str_lm, sizeof(str_lm));
- printsub('>', &str_lm[2], sizeof(str_lm)-2);
- }
-/*@*/ else printf("lm_will: not enough room in buffer\n");
- break;
- }
-}
-
-void
-lm_wont(unsigned char *cmd, int len)
-{
- if (len < 1) {
-/*@*/ printf("lm_wont: no command!!!\n"); /* Should not happen... */
- return;
- }
- switch(cmd[0]) {
- case LM_FORWARDMASK: /* We shouldn't ever get this... */
- default:
- /* We are always DONT, so don't respond */
- return;
- }
-}
-
-void
-lm_do(unsigned char *cmd, int len)
-{
- if (len < 1) {
-/*@*/ printf("lm_do: no command!!!\n"); /* Should not happen... */
- return;
- }
- switch(cmd[0]) {
- case LM_FORWARDMASK:
- default:
- str_lm[3] = WONT;
- str_lm[4] = cmd[0];
- if (NETROOM() > (int)sizeof(str_lm)) {
- ring_supply_data(&netoring, str_lm, sizeof(str_lm));
- printsub('>', &str_lm[2], sizeof(str_lm)-2);
- }
-/*@*/ else printf("lm_do: not enough room in buffer\n");
- break;
- }
-}
-
-void
-lm_dont(unsigned char *cmd, int len)
-{
- if (len < 1) {
-/*@*/ printf("lm_dont: no command!!!\n"); /* Should not happen... */
- return;
- }
- switch(cmd[0]) {
- case LM_FORWARDMASK:
- default:
- /* we are always WONT, so don't respond */
- break;
- }
-}
-
-static unsigned char str_lm_mode[] = {
- IAC, SB, TELOPT_LINEMODE, LM_MODE, 0, IAC, SE
-};
-
-void
-lm_mode(unsigned char *cmd, int len, int init)
-{
- if (len != 1)
- return;
- if ((linemode&MODE_MASK&~MODE_ACK) == *cmd)
- return;
- if (*cmd&MODE_ACK)
- return;
- linemode = *cmd&(MODE_MASK&~MODE_ACK);
- str_lm_mode[4] = linemode;
- if (!init)
- str_lm_mode[4] |= MODE_ACK;
- if (NETROOM() > (int)sizeof(str_lm_mode)) {
- ring_supply_data(&netoring, str_lm_mode, sizeof(str_lm_mode));
- printsub('>', &str_lm_mode[2], sizeof(str_lm_mode)-2);
- }
-/*@*/ else printf("lm_mode: not enough room in buffer\n");
- setconnmode(0); /* set changed mode */
-}
-
-
-
-/*
- * slc()
- * Handle special character suboption of LINEMODE.
- */
-
-struct spc {
- cc_t val;
- cc_t *valp;
- char flags; /* Current flags & level */
- char mylevel; /* Maximum level & flags */
-} spc_data[NSLC+1];
-
-#define SLC_IMPORT 0
-#define SLC_EXPORT 1
-#define SLC_RVALUE 2
-static int slc_mode = SLC_EXPORT;
-
-void
-slc_init(void)
-{
- struct spc *spcp;
-
- localchars = 1;
- for (spcp = spc_data; spcp < &spc_data[NSLC+1]; spcp++) {
- spcp->val = 0;
- spcp->valp = 0;
- spcp->flags = spcp->mylevel = SLC_NOSUPPORT;
- }
-
-#define initfunc(func, flags) { \
- spcp = &spc_data[func]; \
- if ((spcp->valp = tcval(func))) { \
- spcp->val = *spcp->valp; \
- spcp->mylevel = SLC_VARIABLE|flags; \
- } else { \
- spcp->val = 0; \
- spcp->mylevel = SLC_DEFAULT; \
- } \
- }
-
- initfunc(SLC_SYNCH, 0);
- /* No BRK */
- initfunc(SLC_AO, 0);
- initfunc(SLC_AYT, 0);
- /* No EOR */
- initfunc(SLC_ABORT, SLC_FLUSHIN|SLC_FLUSHOUT);
- initfunc(SLC_EOF, 0);
-#ifndef SYSV_TERMIO
- initfunc(SLC_SUSP, SLC_FLUSHIN);
-#endif
- initfunc(SLC_EC, 0);
- initfunc(SLC_EL, 0);
-#ifndef SYSV_TERMIO
- initfunc(SLC_EW, 0);
- initfunc(SLC_RP, 0);
- initfunc(SLC_LNEXT, 0);
-#endif
- initfunc(SLC_XON, 0);
- initfunc(SLC_XOFF, 0);
-#ifdef SYSV_TERMIO
- spc_data[SLC_XON].mylevel = SLC_CANTCHANGE;
- spc_data[SLC_XOFF].mylevel = SLC_CANTCHANGE;
-#endif
- initfunc(SLC_FORW1, 0);
-#ifdef USE_TERMIO
- initfunc(SLC_FORW2, 0);
- /* No FORW2 */
-#endif
-
- initfunc(SLC_IP, SLC_FLUSHIN|SLC_FLUSHOUT);
-#undef initfunc
-
- if (slc_mode == SLC_EXPORT)
- slc_export();
- else
- slc_import(1);
-
-}
-
-void
-slcstate(void)
-{
- printf("Special characters are %s values\n",
- slc_mode == SLC_IMPORT ? "remote default" :
- slc_mode == SLC_EXPORT ? "local" :
- "remote");
-}
-
-void
-slc_mode_export(void)
-{
- slc_mode = SLC_EXPORT;
- if (my_state_is_will(TELOPT_LINEMODE))
- slc_export();
-}
-
-void
-slc_mode_import(int def)
-{
- slc_mode = def ? SLC_IMPORT : SLC_RVALUE;
- if (my_state_is_will(TELOPT_LINEMODE))
- slc_import(def);
-}
-
-unsigned char slc_import_val[] = {
- IAC, SB, TELOPT_LINEMODE, LM_SLC, 0, SLC_VARIABLE, 0, IAC, SE
-};
-unsigned char slc_import_def[] = {
- IAC, SB, TELOPT_LINEMODE, LM_SLC, 0, SLC_DEFAULT, 0, IAC, SE
-};
-
-void
-slc_import(int def)
-{
- if (NETROOM() > (int)sizeof(slc_import_val)) {
- if (def) {
- ring_supply_data(&netoring, slc_import_def, sizeof(slc_import_def));
- printsub('>', &slc_import_def[2], sizeof(slc_import_def)-2);
- } else {
- ring_supply_data(&netoring, slc_import_val, sizeof(slc_import_val));
- printsub('>', &slc_import_val[2], sizeof(slc_import_val)-2);
- }
- }
-/*@*/ else printf("slc_import: not enough room\n");
-}
-
-void
-slc_export(void)
-{
- struct spc *spcp;
-
- TerminalDefaultChars();
-
- slc_start_reply();
- for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) {
- if (spcp->mylevel != SLC_NOSUPPORT) {
- if (spcp->val == (cc_t)(_POSIX_VDISABLE))
- spcp->flags = SLC_NOSUPPORT;
- else
- spcp->flags = spcp->mylevel;
- if (spcp->valp)
- spcp->val = *spcp->valp;
- slc_add_reply(spcp - spc_data, spcp->flags, spcp->val);
- }
- }
- slc_end_reply();
- (void)slc_update();
- setconnmode(1); /* Make sure the character values are set */
-}
-
-void
-slc(unsigned char *cp, int len)
-{
- struct spc *spcp;
- int func,level;
-
- slc_start_reply();
-
- for (; len >= 3; len -=3, cp +=3) {
-
- func = cp[SLC_FUNC];
-
- if (func == 0) {
- /*
- * Client side: always ignore 0 function.
- */
- continue;
- }
- if (func > NSLC) {
- if ((cp[SLC_FLAGS] & SLC_LEVELBITS) != SLC_NOSUPPORT)
- slc_add_reply(func, SLC_NOSUPPORT, 0);
- continue;
- }
-
- spcp = &spc_data[func];
-
- level = cp[SLC_FLAGS]&(SLC_LEVELBITS|SLC_ACK);
-
- if ((cp[SLC_VALUE] == (unsigned char)spcp->val) &&
- ((level&SLC_LEVELBITS) == (spcp->flags&SLC_LEVELBITS))) {
- continue;
- }
-
- if (level == (SLC_DEFAULT|SLC_ACK)) {
- /*
- * This is an error condition, the SLC_ACK
- * bit should never be set for the SLC_DEFAULT
- * level. Our best guess to recover is to
- * ignore the SLC_ACK bit.
- */
- cp[SLC_FLAGS] &= ~SLC_ACK;
- }
-
- if (level == ((spcp->flags&SLC_LEVELBITS)|SLC_ACK)) {
- spcp->val = (cc_t)cp[SLC_VALUE];
- spcp->flags = cp[SLC_FLAGS]; /* include SLC_ACK */
- continue;
- }
-
- level &= ~SLC_ACK;
-
- if (level <= (spcp->mylevel&SLC_LEVELBITS)) {
- spcp->flags = cp[SLC_FLAGS]|SLC_ACK;
- spcp->val = (cc_t)cp[SLC_VALUE];
- }
- if (level == SLC_DEFAULT) {
- if ((spcp->mylevel&SLC_LEVELBITS) != SLC_DEFAULT)
- spcp->flags = spcp->mylevel;
- else
- spcp->flags = SLC_NOSUPPORT;
- }
- slc_add_reply(func, spcp->flags, spcp->val);
- }
- slc_end_reply();
- if (slc_update())
- setconnmode(1); /* set the new character values */
-}
-
-void
-slc_check(void)
-{
- struct spc *spcp;
-
- slc_start_reply();
- for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) {
- if (spcp->valp && spcp->val != *spcp->valp) {
- spcp->val = *spcp->valp;
- if (spcp->val == (cc_t)(_POSIX_VDISABLE))
- spcp->flags = SLC_NOSUPPORT;
- else
- spcp->flags = spcp->mylevel;
- slc_add_reply(spcp - spc_data, spcp->flags, spcp->val);
- }
- }
- slc_end_reply();
- setconnmode(1);
-}
-
-unsigned char slc_reply[128];
-unsigned char *slc_replyp;
-
-void
-slc_start_reply(void)
-{
- slc_replyp = slc_reply;
- *slc_replyp++ = IAC;
- *slc_replyp++ = SB;
- *slc_replyp++ = TELOPT_LINEMODE;
- *slc_replyp++ = LM_SLC;
-}
-
-void
-slc_add_reply(unsigned char func, unsigned char flags, cc_t value)
-{
- if ((*slc_replyp++ = func) == IAC)
- *slc_replyp++ = IAC;
- if ((*slc_replyp++ = flags) == IAC)
- *slc_replyp++ = IAC;
- if ((*slc_replyp++ = (unsigned char)value) == IAC)
- *slc_replyp++ = IAC;
-}
-
-void
-slc_end_reply(void)
-{
- int len;
-
- *slc_replyp++ = IAC;
- *slc_replyp++ = SE;
- len = slc_replyp - slc_reply;
- if (len <= 6)
- return;
- if (NETROOM() > len) {
- ring_supply_data(&netoring, slc_reply, slc_replyp - slc_reply);
- printsub('>', &slc_reply[2], slc_replyp - slc_reply - 2);
- }
-/*@*/else printf("slc_end_reply: not enough room\n");
-}
-
-int
-slc_update(void)
-{
- struct spc *spcp;
- int need_update = 0;
-
- for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) {
- if (!(spcp->flags&SLC_ACK))
- continue;
- spcp->flags &= ~SLC_ACK;
- if (spcp->valp && (*spcp->valp != spcp->val)) {
- *spcp->valp = spcp->val;
- need_update = 1;
- }
- }
- return(need_update);
-}
-
-#ifdef OLD_ENVIRON
-# ifdef ENV_HACK
-/*
- * Earlier version of telnet/telnetd from the BSD code had
- * the definitions of VALUE and VAR reversed. To ensure
- * maximum interoperability, we assume that the server is
- * an older BSD server, until proven otherwise. The newer
- * BSD servers should be able to handle either definition,
- * so it is better to use the wrong values if we don't
- * know what type of server it is.
- */
-int env_auto = 1;
-int old_env_var = OLD_ENV_VAR;
-int old_env_value = OLD_ENV_VALUE;
-# else
-# define old_env_var OLD_ENV_VAR
-# define old_env_value OLD_ENV_VALUE
-# endif
-#endif
-
-void
-env_opt(unsigned char *buf, int len)
-{
- unsigned char *ep = 0, *epc = 0;
- int i;
-
- switch(buf[0]&0xff) {
- case TELQUAL_SEND:
- env_opt_start();
- if (len == 1) {
- env_opt_add(NULL);
- } else for (i = 1; i < len; i++) {
- switch (buf[i]&0xff) {
-#ifdef OLD_ENVIRON
- case OLD_ENV_VAR:
-# ifdef ENV_HACK
- if (telopt_environ == TELOPT_OLD_ENVIRON
- && env_auto) {
- /* Server has the same definitions */
- old_env_var = OLD_ENV_VAR;
- old_env_value = OLD_ENV_VALUE;
- }
- /* FALLTHROUGH */
-# endif
- case OLD_ENV_VALUE:
- /*
- * Although OLD_ENV_VALUE is not legal, we will
- * still recognize it, just in case it is an
- * old server that has VAR & VALUE mixed up...
- */
- /* FALLTHROUGH */
-#else
- case NEW_ENV_VAR:
-#endif
- case ENV_USERVAR:
- if (ep) {
- *epc = 0;
- env_opt_add(ep);
- }
- ep = epc = &buf[i+1];
- break;
- case ENV_ESC:
- i++;
- /*FALLTHROUGH*/
- default:
- if (epc)
- *epc++ = buf[i];
- break;
- }
- }
- if (ep) {
- *epc = 0;
- env_opt_add(ep);
- }
- env_opt_end(1);
- break;
-
- case TELQUAL_IS:
- case TELQUAL_INFO:
- /* Ignore for now. We shouldn't get it anyway. */
- break;
-
- default:
- break;
- }
-}
-
-#define OPT_REPLY_SIZE 256
-unsigned char *opt_reply;
-unsigned char *opt_replyp;
-unsigned char *opt_replyend;
-
-void
-env_opt_start(void)
-{
- if (opt_reply)
- opt_reply = (unsigned char *)realloc(opt_reply, OPT_REPLY_SIZE);
- else
- opt_reply = (unsigned char *)malloc(OPT_REPLY_SIZE);
- if (opt_reply == NULL) {
-/*@*/ printf("env_opt_start: malloc()/realloc() failed!!!\n");
- opt_reply = opt_replyp = opt_replyend = NULL;
- return;
- }
- opt_replyp = opt_reply;
- opt_replyend = opt_reply + OPT_REPLY_SIZE;
- *opt_replyp++ = IAC;
- *opt_replyp++ = SB;
- *opt_replyp++ = telopt_environ;
- *opt_replyp++ = TELQUAL_IS;
-}
-
-void
-env_opt_start_info(void)
-{
- env_opt_start();
- if (opt_replyp)
- opt_replyp[-1] = TELQUAL_INFO;
-}
-
-void
-env_opt_add(unsigned char *ep)
-{
- unsigned char *vp, c;
-
- if (opt_reply == NULL) /*XXX*/
- return; /*XXX*/
-
- if (ep == NULL || *ep == '\0') {
- /* Send user defined variables first. */
- env_default(1, 0);
- while ((ep = env_default(0, 0)))
- env_opt_add(ep);
-
- /* Now add the list of well know variables. */
- env_default(1, 1);
- while ((ep = env_default(0, 1)))
- env_opt_add(ep);
- return;
- }
- vp = env_getvalue(ep);
- if (opt_replyp + (vp ? strlen((char *)vp) : 0) +
- strlen((char *)ep) + 6 > opt_replyend)
- {
- int len;
- opt_replyend += OPT_REPLY_SIZE;
- len = opt_replyend - opt_reply;
- opt_reply = (unsigned char *)realloc(opt_reply, len);
- if (opt_reply == NULL) {
-/*@*/ printf("env_opt_add: realloc() failed!!!\n");
- opt_reply = opt_replyp = opt_replyend = NULL;
- return;
- }
- opt_replyp = opt_reply + len - (opt_replyend - opt_replyp);
- opt_replyend = opt_reply + len;
- }
- if (opt_welldefined(ep))
-#ifdef OLD_ENVIRON
- if (telopt_environ == TELOPT_OLD_ENVIRON)
- *opt_replyp++ = old_env_var;
- else
-#endif
- *opt_replyp++ = NEW_ENV_VAR;
- else
- *opt_replyp++ = ENV_USERVAR;
- for (;;) {
- while ((c = *ep++)) {
- switch(c&0xff) {
- case IAC:
- *opt_replyp++ = IAC;
- break;
- case NEW_ENV_VAR:
- case NEW_ENV_VALUE:
- case ENV_ESC:
- case ENV_USERVAR:
- *opt_replyp++ = ENV_ESC;
- break;
- }
- *opt_replyp++ = c;
- }
- if ((ep = vp)) {
-#ifdef OLD_ENVIRON
- if (telopt_environ == TELOPT_OLD_ENVIRON)
- *opt_replyp++ = old_env_value;
- else
-#endif
- *opt_replyp++ = NEW_ENV_VALUE;
- vp = NULL;
- } else
- break;
- }
-}
-
-int
-opt_welldefined(const char *ep)
-{
- if ((strcmp(ep, "USER") == 0) ||
- (strcmp(ep, "DISPLAY") == 0) ||
- (strcmp(ep, "PRINTER") == 0) ||
- (strcmp(ep, "SYSTEMTYPE") == 0) ||
- (strcmp(ep, "JOB") == 0) ||
- (strcmp(ep, "ACCT") == 0))
- return(1);
- return(0);
-}
-
-void
-env_opt_end(int emptyok)
-{
- int len;
-
- len = opt_replyp - opt_reply + 2;
- if (emptyok || len > 6) {
- *opt_replyp++ = IAC;
- *opt_replyp++ = SE;
- if (NETROOM() > len) {
- ring_supply_data(&netoring, opt_reply, len);
- printsub('>', &opt_reply[2], len - 2);
- }
-/*@*/ else printf("slc_end_reply: not enough room\n");
- }
- if (opt_reply) {
- free(opt_reply);
- opt_reply = opt_replyp = opt_replyend = NULL;
- }
-}
-
-
-
-int
-telrcv(void)
-{
- int c;
- int scc;
- unsigned char *sbp;
- int count;
- int returnValue = 0;
-
- scc = 0;
- count = 0;
- while (TTYROOM() > 2) {
- if (scc == 0) {
- if (count) {
- ring_consumed(&netiring, count);
- returnValue = 1;
- count = 0;
- }
- sbp = netiring.consume;
- scc = ring_full_consecutive(&netiring);
- if (scc == 0) {
- /* No more data coming in */
- break;
- }
- }
-
- c = *sbp++ & 0xff, scc--; count++;
-#ifdef ENCRYPTION
- if (decrypt_input)
- c = (*decrypt_input)(c);
-#endif /* ENCRYPTION */
-
- switch (telrcv_state) {
-
- case TS_CR:
- telrcv_state = TS_DATA;
- if (c == '\0') {
- break; /* Ignore \0 after CR */
- }
- else if ((c == '\n') && my_want_state_is_dont(TELOPT_ECHO) && !crmod) {
- TTYADD(c);
- break;
- }
- /* FALLTHROUGH */
-
- case TS_DATA:
- if (c == IAC) {
- telrcv_state = TS_IAC;
- break;
- }
- /*
- * The 'crmod' hack (see following) is needed
- * since we can't * set CRMOD on output only.
- * Machines like MULTICS like to send \r without
- * \n; since we must turn off CRMOD to get proper
- * input, the mapping is done here (sigh).
- */
- if ((c == '\r') && my_want_state_is_dont(TELOPT_BINARY)) {
- if (scc > 0) {
- c = *sbp&0xff;
-#ifdef ENCRYPTION
- if (decrypt_input)
- c = (*decrypt_input)(c);
-#endif /* ENCRYPTION */
- if (c == 0) {
- sbp++, scc--; count++;
- /* a "true" CR */
- TTYADD('\r');
- } else if (my_want_state_is_dont(TELOPT_ECHO) &&
- (c == '\n')) {
- sbp++, scc--; count++;
- TTYADD('\n');
- } else {
-#ifdef ENCRYPTION
- if (decrypt_input)
- (*decrypt_input)(-1);
-#endif /* ENCRYPTION */
-
- TTYADD('\r');
- if (crmod) {
- TTYADD('\n');
- }
- }
- } else {
- telrcv_state = TS_CR;
- TTYADD('\r');
- if (crmod) {
- TTYADD('\n');
- }
- }
- } else {
- TTYADD(c);
- }
- continue;
-
- case TS_IAC:
-process_iac:
- switch (c) {
-
- case WILL:
- telrcv_state = TS_WILL;
- continue;
-
- case WONT:
- telrcv_state = TS_WONT;
- continue;
-
- case DO:
- telrcv_state = TS_DO;
- continue;
-
- case DONT:
- telrcv_state = TS_DONT;
- continue;
-
- case DM:
- /*
- * We may have missed an urgent notification,
- * so make sure we flush whatever is in the
- * buffer currently.
- */
- printoption("RCVD", IAC, DM);
- SYNCHing = 1;
- (void) ttyflush(1);
- SYNCHing = stilloob();
- settimer(gotDM);
- break;
-
- case SB:
- SB_CLEAR();
- telrcv_state = TS_SB;
- continue;
-
- case IAC:
- TTYADD(IAC);
- break;
-
- case NOP:
- case GA:
- default:
- printoption("RCVD", IAC, c);
- break;
- }
- telrcv_state = TS_DATA;
- continue;
-
- case TS_WILL:
- printoption("RCVD", WILL, c);
- willoption(c);
- telrcv_state = TS_DATA;
- continue;
-
- case TS_WONT:
- printoption("RCVD", WONT, c);
- wontoption(c);
- telrcv_state = TS_DATA;
- continue;
-
- case TS_DO:
- printoption("RCVD", DO, c);
- dooption(c);
- if (c == TELOPT_NAWS) {
- sendnaws();
- } else if (c == TELOPT_LFLOW) {
- localflow = 1;
- setcommandmode();
- setconnmode(0);
- }
- telrcv_state = TS_DATA;
- continue;
-
- case TS_DONT:
- printoption("RCVD", DONT, c);
- dontoption(c);
- flushline = 1;
- setconnmode(0); /* set new tty mode (maybe) */
- telrcv_state = TS_DATA;
- continue;
-
- case TS_SB:
- if (c == IAC) {
- telrcv_state = TS_SE;
- } else {
- SB_ACCUM(c);
- }
- continue;
-
- case TS_SE:
- if (c != SE) {
- if (c != IAC) {
- /*
- * This is an error. We only expect to get
- * "IAC IAC" or "IAC SE". Several things may
- * have happend. An IAC was not doubled, the
- * IAC SE was left off, or another option got
- * inserted into the suboption are all possibilities.
- * If we assume that the IAC was not doubled,
- * and really the IAC SE was left off, we could
- * get into an infinate loop here. So, instead,
- * we terminate the suboption, and process the
- * partial suboption if we can.
- */
- SB_ACCUM(IAC);
- SB_ACCUM(c);
- subpointer -= 2;
- SB_TERM();
-
- printoption("In SUBOPTION processing, RCVD", IAC, c);
- suboption(); /* handle sub-option */
- telrcv_state = TS_IAC;
- goto process_iac;
- }
- SB_ACCUM(c);
- telrcv_state = TS_SB;
- } else {
- SB_ACCUM(IAC);
- SB_ACCUM(SE);
- subpointer -= 2;
- SB_TERM();
- suboption(); /* handle sub-option */
- telrcv_state = TS_DATA;
- }
- }
- }
- if (count)
- ring_consumed(&netiring, count);
- return returnValue||count;
-}
-
-static int bol = 1, local = 0;
-
-int
-rlogin_susp(void)
-{
- if (local) {
- local = 0;
- bol = 1;
- command(0, "z\n", 2);
- return(1);
- }
- return(0);
-}
-
-static int
-telsnd(void)
-{
- int tcc;
- int count;
- int returnValue = 0;
- unsigned char *tbp;
-
- tcc = 0;
- count = 0;
- while (NETROOM() > 2) {
- int sc;
- int c;
-
- if (tcc == 0) {
- if (count) {
- ring_consumed(&ttyiring, count);
- returnValue = 1;
- count = 0;
- }
- tbp = ttyiring.consume;
- tcc = ring_full_consecutive(&ttyiring);
- if (tcc == 0) {
- break;
- }
- }
- c = *tbp++ & 0xff, sc = strip(c), tcc--; count++;
- if (rlogin != _POSIX_VDISABLE) {
- if (bol) {
- bol = 0;
- if (sc == rlogin) {
- local = 1;
- continue;
- }
- } else if (local) {
- local = 0;
- if (sc == '.' || c == termEofChar) {
- bol = 1;
- command(0, "close\n", 6);
- continue;
- }
- if (sc == termSuspChar) {
- bol = 1;
- command(0, "z\n", 2);
- continue;
- }
- if (sc == escape) {
- command(0, tbp, tcc);
- bol = 1;
- count += tcc;
- tcc = 0;
- flushline = 1;
- break;
- }
- if (sc != rlogin) {
- ++tcc;
- --tbp;
- --count;
- c = sc = rlogin;
- }
- }
- if ((sc == '\n') || (sc == '\r'))
- bol = 1;
- } else if (escape != _POSIX_VDISABLE && sc == escape) {
- /*
- * Double escape is a pass through of a single escape character.
- */
- if (tcc && strip(*tbp) == escape) {
- tbp++;
- tcc--;
- count++;
- bol = 0;
- } else {
- command(0, (char *)tbp, tcc);
- bol = 1;
- count += tcc;
- tcc = 0;
- flushline = 1;
- break;
- }
- } else
- bol = 0;
-#ifdef KLUDGELINEMODE
- if (kludgelinemode && (globalmode&MODE_EDIT) && (sc == echoc)) {
- if (tcc > 0 && strip(*tbp) == echoc) {
- tcc--; tbp++; count++;
- } else {
- dontlecho = !dontlecho;
- settimer(echotoggle);
- setconnmode(0);
- flushline = 1;
- break;
- }
- }
-#endif
- if (MODE_LOCAL_CHARS(globalmode)) {
- if (TerminalSpecialChars(sc) == 0) {
- bol = 1;
- break;
- }
- }
- if (my_want_state_is_wont(TELOPT_BINARY)) {
- switch (c) {
- case '\n':
- /*
- * If we are in CRMOD mode (\r ==> \n)
- * on our local machine, then probably
- * a newline (unix) is CRLF (TELNET).
- */
- if (MODE_LOCAL_CHARS(globalmode)) {
- NETADD('\r');
- }
- NETADD('\n');
- bol = flushline = 1;
- break;
- case '\r':
- if (!crlf) {
- NET2ADD('\r', '\0');
- } else {
- NET2ADD('\r', '\n');
- }
- bol = flushline = 1;
- break;
- case IAC:
- NET2ADD(IAC, IAC);
- break;
- default:
- NETADD(c);
- break;
- }
- } else if (c == IAC) {
- NET2ADD(IAC, IAC);
- } else {
- NETADD(c);
- }
- }
- if (count)
- ring_consumed(&ttyiring, count);
- return returnValue||count; /* Non-zero if we did anything */
-}
-
-/*
- * Scheduler()
- *
- * Try to do something.
- *
- * If we do something useful, return 1; else return 0.
- *
- */
-
-static int
-Scheduler(int block)
-{
- /* One wants to be a bit careful about setting returnValue
- * to one, since a one implies we did some useful work,
- * and therefore probably won't be called to block next
- */
- int returnValue;
- int netin, netout, netex, ttyin, ttyout;
-
- /* Decide which rings should be processed */
-
- netout = ring_full_count(&netoring) &&
- (flushline ||
- (my_want_state_is_wont(TELOPT_LINEMODE)
-#ifdef KLUDGELINEMODE
- && (!kludgelinemode || my_want_state_is_do(TELOPT_SGA))
-#endif
- ) ||
- my_want_state_is_will(TELOPT_BINARY));
- ttyout = ring_full_count(&ttyoring);
-
- ttyin = ring_empty_count(&ttyiring) && (clienteof == 0);
-
- netin = !ISend && ring_empty_count(&netiring);
-
- netex = !SYNCHing;
-
- /* Call to system code to process rings */
-
- returnValue = process_rings(netin, netout, netex, ttyin, ttyout, !block);
-
- /* Now, look at the input rings, looking for work to do. */
-
- if (ring_full_count(&ttyiring)) {
- returnValue |= telsnd();
- }
-
- if (ring_full_count(&netiring)) {
- returnValue |= telrcv();
- }
- return returnValue;
-}
-
-#ifdef AUTHENTICATION
-#define __unusedhere
-#else
-#define __unusedhere __unused
-#endif
-/*
- * Select from tty and network...
- */
-void
-telnet(char *user __unusedhere)
-{
- sys_telnet_init();
-
-#ifdef AUTHENTICATION
-#ifdef ENCRYPTION
- {
- static char local_host[256] = { 0 };
-
- if (!local_host[0]) {
- gethostname(local_host, sizeof(local_host));
- local_host[sizeof(local_host)-1] = 0;
- }
- auth_encrypt_init(local_host, hostname, "TELNET", 0);
- auth_encrypt_user(user);
- }
-#endif
-#endif
- if (telnetport) {
-#ifdef AUTHENTICATION
- if (autologin)
- send_will(TELOPT_AUTHENTICATION, 1);
-#endif
-#ifdef ENCRYPTION
- send_do(TELOPT_ENCRYPT, 1);
- send_will(TELOPT_ENCRYPT, 1);
-#endif /* ENCRYPTION */
- send_do(TELOPT_SGA, 1);
- send_will(TELOPT_TTYPE, 1);
- send_will(TELOPT_NAWS, 1);
- send_will(TELOPT_TSPEED, 1);
- send_will(TELOPT_LFLOW, 1);
- send_will(TELOPT_LINEMODE, 1);
- send_will(TELOPT_NEW_ENVIRON, 1);
- send_do(TELOPT_STATUS, 1);
- if (env_getvalue("DISPLAY"))
- send_will(TELOPT_XDISPLOC, 1);
- if (eight)
- tel_enter_binary(eight);
- }
-
- for (;;) {
- int schedValue;
-
- while ((schedValue = Scheduler(0)) != 0) {
- if (schedValue == -1) {
- setcommandmode();
- return;
- }
- }
-
- if (Scheduler(1) == -1) {
- setcommandmode();
- return;
- }
- }
-}
-
-#if 0 /* XXX - this not being in is a bug */
-/*
- * nextitem()
- *
- * Return the address of the next "item" in the TELNET data
- * stream. This will be the address of the next character if
- * the current address is a user data character, or it will
- * be the address of the character following the TELNET command
- * if the current address is a TELNET IAC ("I Am a Command")
- * character.
- */
-
-static char *
-nextitem(char *current)
-{
- if ((*current&0xff) != IAC) {
- return current+1;
- }
- switch (*(current+1)&0xff) {
- case DO:
- case DONT:
- case WILL:
- case WONT:
- return current+3;
- case SB: /* loop forever looking for the SE */
- {
- char *look = current+2;
-
- for (;;) {
- if ((*look++&0xff) == IAC) {
- if ((*look++&0xff) == SE) {
- return look;
- }
- }
- }
- }
- default:
- return current+2;
- }
-}
-#endif /* 0 */
-
-/*
- * netclear()
- *
- * We are about to do a TELNET SYNCH operation. Clear
- * the path to the network.
- *
- * Things are a bit tricky since we may have sent the first
- * byte or so of a previous TELNET command into the network.
- * So, we have to scan the network buffer from the beginning
- * until we are up to where we want to be.
- *
- * A side effect of what we do, just to keep things
- * simple, is to clear the urgent data pointer. The principal
- * caller should be setting the urgent data pointer AFTER calling
- * us in any case.
- */
-
-static void
-netclear(void)
-{
- /* Deleted */
-}
-
-/*
- * These routines add various telnet commands to the data stream.
- */
-
-static void
-doflush(void)
-{
- NET2ADD(IAC, DO);
- NETADD(TELOPT_TM);
- flushline = 1;
- flushout = 1;
- (void) ttyflush(1); /* Flush/drop output */
- /* do printoption AFTER flush, otherwise the output gets tossed... */
- printoption("SENT", DO, TELOPT_TM);
-}
-
-void
-xmitAO(void)
-{
- NET2ADD(IAC, AO);
- printoption("SENT", IAC, AO);
- if (autoflush) {
- doflush();
- }
-}
-
-void
-xmitEL(void)
-{
- NET2ADD(IAC, EL);
- printoption("SENT", IAC, EL);
-}
-
-void
-xmitEC(void)
-{
- NET2ADD(IAC, EC);
- printoption("SENT", IAC, EC);
-}
-
-int
-dosynch(char *ch __unused)
-{
- netclear(); /* clear the path to the network */
- NETADD(IAC);
- setneturg();
- NETADD(DM);
- printoption("SENT", IAC, DM);
- return 1;
-}
-
-int want_status_response = 0;
-
-int
-get_status(char *ch __unused)
-{
- unsigned char tmp[16];
- unsigned char *cp;
-
- if (my_want_state_is_dont(TELOPT_STATUS)) {
- printf("Remote side does not support STATUS option\n");
- return 0;
- }
- cp = tmp;
-
- *cp++ = IAC;
- *cp++ = SB;
- *cp++ = TELOPT_STATUS;
- *cp++ = TELQUAL_SEND;
- *cp++ = IAC;
- *cp++ = SE;
- if (NETROOM() >= cp - tmp) {
- ring_supply_data(&netoring, tmp, cp-tmp);
- printsub('>', tmp+2, cp - tmp - 2);
- }
- ++want_status_response;
- return 1;
-}
-
-void
-intp(void)
-{
- NET2ADD(IAC, IP);
- printoption("SENT", IAC, IP);
- flushline = 1;
- if (autoflush) {
- doflush();
- }
- if (autosynch) {
- dosynch(NULL);
- }
-}
-
-void
-sendbrk(void)
-{
- NET2ADD(IAC, BREAK);
- printoption("SENT", IAC, BREAK);
- flushline = 1;
- if (autoflush) {
- doflush();
- }
- if (autosynch) {
- dosynch(NULL);
- }
-}
-
-void
-sendabort(void)
-{
- NET2ADD(IAC, ABORT);
- printoption("SENT", IAC, ABORT);
- flushline = 1;
- if (autoflush) {
- doflush();
- }
- if (autosynch) {
- dosynch(NULL);
- }
-}
-
-void
-sendsusp(void)
-{
- NET2ADD(IAC, SUSP);
- printoption("SENT", IAC, SUSP);
- flushline = 1;
- if (autoflush) {
- doflush();
- }
- if (autosynch) {
- dosynch(NULL);
- }
-}
-
-void
-sendeof(void)
-{
- NET2ADD(IAC, xEOF);
- printoption("SENT", IAC, xEOF);
-}
-
-void
-sendayt(void)
-{
- NET2ADD(IAC, AYT);
- printoption("SENT", IAC, AYT);
-}
-
-/*
- * Send a window size update to the remote system.
- */
-
-void
-sendnaws(void)
-{
- long rows, cols;
- unsigned char tmp[16];
- unsigned char *cp;
-
- if (my_state_is_wont(TELOPT_NAWS))
- return;
-
-#define PUTSHORT(cp, x) { if ((*cp++ = ((x)>>8)&0xff) == IAC) *cp++ = IAC; \
- if ((*cp++ = ((x))&0xff) == IAC) *cp++ = IAC; }
-
- if (TerminalWindowSize(&rows, &cols) == 0) { /* Failed */
- return;
- }
-
- cp = tmp;
-
- *cp++ = IAC;
- *cp++ = SB;
- *cp++ = TELOPT_NAWS;
- PUTSHORT(cp, cols);
- PUTSHORT(cp, rows);
- *cp++ = IAC;
- *cp++ = SE;
- if (NETROOM() >= cp - tmp) {
- ring_supply_data(&netoring, tmp, cp-tmp);
- printsub('>', tmp+2, cp - tmp - 2);
- }
-}
-
-void
-tel_enter_binary(int rw)
-{
- if (rw&1)
- send_do(TELOPT_BINARY, 1);
- if (rw&2)
- send_will(TELOPT_BINARY, 1);
-}
-
-void
-tel_leave_binary(int rw)
-{
- if (rw&1)
- send_dont(TELOPT_BINARY, 1);
- if (rw&2)
- send_wont(TELOPT_BINARY, 1);
-}
diff --git a/contrib/telnet/telnet/terminal.c b/contrib/telnet/telnet/terminal.c
deleted file mode 100644
index 3dda1c5bf886..000000000000
--- a/contrib/telnet/telnet/terminal.c
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Copyright (c) 1988, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)terminal.c 8.2 (Berkeley) 2/16/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <arpa/telnet.h>
-#include <sys/types.h>
-
-#include <stdlib.h>
-
-#include "ring.h"
-
-#include "externs.h"
-#include "types.h"
-
-#ifdef ENCRYPTION
-#include <libtelnet/encrypt.h>
-#endif
-
-Ring ttyoring, ttyiring;
-unsigned char ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ];
-
-int termdata; /* Debugging flag */
-
-#ifdef USE_TERMIO
-# ifndef VDISCARD
-cc_t termFlushChar;
-# endif
-# ifndef VLNEXT
-cc_t termLiteralNextChar;
-# endif
-# ifndef VSUSP
-cc_t termSuspChar;
-# endif
-# ifndef VWERASE
-cc_t termWerasChar;
-# endif
-# ifndef VREPRINT
-cc_t termRprntChar;
-# endif
-# ifndef VSTART
-cc_t termStartChar;
-# endif
-# ifndef VSTOP
-cc_t termStopChar;
-# endif
-# ifndef VEOL
-cc_t termForw1Char;
-# endif
-# ifndef VEOL2
-cc_t termForw2Char;
-# endif
-# ifndef VSTATUS
-cc_t termAytChar;
-# endif
-#else
-cc_t termForw2Char;
-cc_t termAytChar;
-#endif
-
-/*
- * initialize the terminal data structures.
- */
-
-void
-init_terminal(void)
-{
- if (ring_init(&ttyoring, ttyobuf, sizeof ttyobuf) != 1) {
- exit(1);
- }
- if (ring_init(&ttyiring, ttyibuf, sizeof ttyibuf) != 1) {
- exit(1);
- }
- autoflush = TerminalAutoFlush();
-}
-
-/*
- * Send as much data as possible to the terminal.
- *
- * Return value:
- * -1: No useful work done, data waiting to go out.
- * 0: No data was waiting, so nothing was done.
- * 1: All waiting data was written out.
- * n: All data - n was written out.
- */
-
-int
-ttyflush(int drop)
-{
- int n, n0, n1;
-
- n0 = ring_full_count(&ttyoring);
- if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) {
- if (drop) {
- TerminalFlushOutput();
- /* we leave 'n' alone! */
- } else {
- n = TerminalWrite(ttyoring.consume, n);
- }
- }
- if (n > 0) {
- if (termdata && n) {
- Dump('>', ttyoring.consume, n);
- }
- /*
- * If we wrote everything, and the full count is
- * larger than what we wrote, then write the
- * rest of the buffer.
- */
- if (n1 == n && n0 > n) {
- n1 = n0 - n;
- if (!drop)
- n1 = TerminalWrite(ttyoring.bottom, n1);
- if (n1 > 0)
- n += n1;
- }
- ring_consumed(&ttyoring, n);
- }
- if (n < 0)
- return -1;
- if (n == n0) {
- if (n0)
- return -1;
- return 0;
- }
- return n0 - n + 1;
-}
-
-
-/*
- * These routines decides on what the mode should be (based on the values
- * of various global variables).
- */
-
-
-int
-getconnmode(void)
-{
- extern int linemode;
- int mode = 0;
-#ifdef KLUDGELINEMODE
- extern int kludgelinemode;
-#endif
-
- if (my_want_state_is_dont(TELOPT_ECHO))
- mode |= MODE_ECHO;
-
- if (localflow)
- mode |= MODE_FLOW;
-
- if (my_want_state_is_will(TELOPT_BINARY))
- mode |= MODE_INBIN;
-
- if (his_want_state_is_will(TELOPT_BINARY))
- mode |= MODE_OUTBIN;
-
-#ifdef KLUDGELINEMODE
- if (kludgelinemode) {
- if (my_want_state_is_dont(TELOPT_SGA)) {
- mode |= (MODE_TRAPSIG|MODE_EDIT);
- if (dontlecho && (clocks.echotoggle > clocks.modenegotiated)) {
- mode &= ~MODE_ECHO;
- }
- }
- return(mode);
- }
-#endif
- if (my_want_state_is_will(TELOPT_LINEMODE))
- mode |= linemode;
- return(mode);
-}
-
-void
-setconnmode(int force)
-{
-#ifdef ENCRYPTION
- static int enc_passwd = 0;
-#endif /* ENCRYPTION */
- int newmode;
-
- newmode = getconnmode()|(force?MODE_FORCE:0);
-
- TerminalNewMode(newmode);
-
-#ifdef ENCRYPTION
- if ((newmode & (MODE_ECHO|MODE_EDIT)) == MODE_EDIT) {
- if (my_want_state_is_will(TELOPT_ENCRYPT)
- && (enc_passwd == 0) && !encrypt_output) {
- encrypt_request_start(0, 0);
- enc_passwd = 1;
- }
- } else {
- if (enc_passwd) {
- encrypt_request_end();
- enc_passwd = 0;
- }
- }
-#endif /* ENCRYPTION */
-
-}
-
-void
-setcommandmode(void)
-{
- TerminalNewMode(-1);
-}
diff --git a/contrib/telnet/telnet/types.h b/contrib/telnet/telnet/types.h
deleted file mode 100644
index 191d311fd154..000000000000
--- a/contrib/telnet/telnet/types.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)types.h 8.1 (Berkeley) 6/6/93
- */
-
-typedef struct {
- char *modedescriptions;
- char modetype;
-} Modelist;
-
-extern Modelist modelist[];
-
-typedef struct {
- int
- system, /* what the current time is */
- echotoggle, /* last time user entered echo character */
- modenegotiated, /* last time operating mode negotiated */
- didnetreceive, /* last time we read data from network */
- gotDM; /* when did we last see a data mark */
-} Clocks;
-
-extern Clocks clocks;
diff --git a/contrib/telnet/telnet/utilities.c b/contrib/telnet/telnet/utilities.c
deleted file mode 100644
index b0cfe37bbabd..000000000000
--- a/contrib/telnet/telnet/utilities.c
+++ /dev/null
@@ -1,912 +0,0 @@
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)utilities.c 8.3 (Berkeley) 5/30/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#define TELOPTS
-#define TELCMDS
-#define SLC_NAMES
-#include <arpa/telnet.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "general.h"
-
-#include "fdset.h"
-
-#include "ring.h"
-
-#include "defines.h"
-
-#include "externs.h"
-
-#ifdef AUTHENTICATION
-#include <libtelnet/auth.h>
-#endif
-#ifdef ENCRYPTION
-#include <libtelnet/encrypt.h>
-#endif
-
-FILE *NetTrace = 0; /* Not in bss, since needs to stay */
-int prettydump;
-
-/*
- * upcase()
- *
- * Upcase (in place) the argument.
- */
-
-void
-upcase(char *argument)
-{
- int c;
-
- while ((c = *argument) != 0) {
- if (islower(c)) {
- *argument = toupper(c);
- }
- argument++;
- }
-}
-
-/*
- * SetSockOpt()
- *
- * Compensate for differences in 4.2 and 4.3 systems.
- */
-
-int
-SetSockOpt(int fd, int level, int option, int yesno)
-{
- return setsockopt(fd, level, option,
- (char *)&yesno, sizeof yesno);
-}
-
-/*
- * The following are routines used to print out debugging information.
- */
-
-unsigned char NetTraceFile[256] = "(standard output)";
-
-void
-SetNetTrace(char *file)
-{
- if (NetTrace && NetTrace != stdout)
- fclose(NetTrace);
- if (file && (strcmp(file, "-") != 0)) {
- NetTrace = fopen(file, "w");
- if (NetTrace) {
- strcpy((char *)NetTraceFile, file);
- return;
- }
- fprintf(stderr, "Cannot open %s.\n", file);
- }
- NetTrace = stdout;
- strcpy((char *)NetTraceFile, "(standard output)");
-}
-
-void
-Dump(char direction, unsigned char *buffer, int length)
-{
-# define BYTES_PER_LINE 32
-# define min(x,y) ((x<y)? x:y)
- unsigned char *pThis;
- int offset;
-
- offset = 0;
-
- while (length) {
- /* print one line */
- fprintf(NetTrace, "%c 0x%x\t", direction, offset);
- pThis = buffer;
- if (prettydump) {
- buffer = buffer + min(length, BYTES_PER_LINE/2);
- while (pThis < buffer) {
- fprintf(NetTrace, "%c%.2x",
- (((*pThis)&0xff) == 0xff) ? '*' : ' ',
- (*pThis)&0xff);
- pThis++;
- }
- length -= BYTES_PER_LINE/2;
- offset += BYTES_PER_LINE/2;
- } else {
- buffer = buffer + min(length, BYTES_PER_LINE);
- while (pThis < buffer) {
- fprintf(NetTrace, "%.2x", (*pThis)&0xff);
- pThis++;
- }
- length -= BYTES_PER_LINE;
- offset += BYTES_PER_LINE;
- }
- if (NetTrace == stdout) {
- fprintf(NetTrace, "\r\n");
- } else {
- fprintf(NetTrace, "\n");
- }
- if (length < 0) {
- fflush(NetTrace);
- return;
- }
- /* find next unique line */
- }
- fflush(NetTrace);
-}
-
-
-void
-printoption(const char *direction, int cmd, int option)
-{
- if (!showoptions)
- return;
- if (cmd == IAC) {
- if (TELCMD_OK(option))
- fprintf(NetTrace, "%s IAC %s", direction, TELCMD(option));
- else
- fprintf(NetTrace, "%s IAC %d", direction, option);
- } else {
- const char *fmt;
- fmt = (cmd == WILL) ? "WILL" : (cmd == WONT) ? "WONT" :
- (cmd == DO) ? "DO" : (cmd == DONT) ? "DONT" : 0;
- if (fmt) {
- fprintf(NetTrace, "%s %s ", direction, fmt);
- if (TELOPT_OK(option))
- fprintf(NetTrace, "%s", TELOPT(option));
- else if (option == TELOPT_EXOPL)
- fprintf(NetTrace, "EXOPL");
- else
- fprintf(NetTrace, "%d", option);
- } else
- fprintf(NetTrace, "%s %d %d", direction, cmd, option);
- }
- if (NetTrace == stdout) {
- fprintf(NetTrace, "\r\n");
- fflush(NetTrace);
- } else {
- fprintf(NetTrace, "\n");
- }
- return;
-}
-
-void
-optionstatus(void)
-{
- int i;
- extern char will_wont_resp[], do_dont_resp[];
-
- for (i = 0; i < 256; i++) {
- if (do_dont_resp[i]) {
- if (TELOPT_OK(i))
- printf("resp DO_DONT %s: %d\n", TELOPT(i), do_dont_resp[i]);
- else if (TELCMD_OK(i))
- printf("resp DO_DONT %s: %d\n", TELCMD(i), do_dont_resp[i]);
- else
- printf("resp DO_DONT %d: %d\n", i,
- do_dont_resp[i]);
- if (my_want_state_is_do(i)) {
- if (TELOPT_OK(i))
- printf("want DO %s\n", TELOPT(i));
- else if (TELCMD_OK(i))
- printf("want DO %s\n", TELCMD(i));
- else
- printf("want DO %d\n", i);
- } else {
- if (TELOPT_OK(i))
- printf("want DONT %s\n", TELOPT(i));
- else if (TELCMD_OK(i))
- printf("want DONT %s\n", TELCMD(i));
- else
- printf("want DONT %d\n", i);
- }
- } else {
- if (my_state_is_do(i)) {
- if (TELOPT_OK(i))
- printf(" DO %s\n", TELOPT(i));
- else if (TELCMD_OK(i))
- printf(" DO %s\n", TELCMD(i));
- else
- printf(" DO %d\n", i);
- }
- }
- if (will_wont_resp[i]) {
- if (TELOPT_OK(i))
- printf("resp WILL_WONT %s: %d\n", TELOPT(i), will_wont_resp[i]);
- else if (TELCMD_OK(i))
- printf("resp WILL_WONT %s: %d\n", TELCMD(i), will_wont_resp[i]);
- else
- printf("resp WILL_WONT %d: %d\n",
- i, will_wont_resp[i]);
- if (my_want_state_is_will(i)) {
- if (TELOPT_OK(i))
- printf("want WILL %s\n", TELOPT(i));
- else if (TELCMD_OK(i))
- printf("want WILL %s\n", TELCMD(i));
- else
- printf("want WILL %d\n", i);
- } else {
- if (TELOPT_OK(i))
- printf("want WONT %s\n", TELOPT(i));
- else if (TELCMD_OK(i))
- printf("want WONT %s\n", TELCMD(i));
- else
- printf("want WONT %d\n", i);
- }
- } else {
- if (my_state_is_will(i)) {
- if (TELOPT_OK(i))
- printf(" WILL %s\n", TELOPT(i));
- else if (TELCMD_OK(i))
- printf(" WILL %s\n", TELCMD(i));
- else
- printf(" WILL %d\n", i);
- }
- }
- }
-
-}
-
-void
-printsub(char direction, unsigned char *pointer, int length)
-{
- int i;
-#ifdef AUTHENTICATION
- char buf[512];
-#endif
- extern int want_status_response;
-
- if (showoptions || direction == 0 ||
- (want_status_response && (pointer[0] == TELOPT_STATUS))) {
- if (direction) {
- fprintf(NetTrace, "%s IAC SB ",
- (direction == '<')? "RCVD":"SENT");
- if (length >= 3) {
- int j;
-
- i = pointer[length-2];
- j = pointer[length-1];
-
- if (i != IAC || j != SE) {
- fprintf(NetTrace, "(terminated by ");
- if (TELOPT_OK(i))
- fprintf(NetTrace, "%s ", TELOPT(i));
- else if (TELCMD_OK(i))
- fprintf(NetTrace, "%s ", TELCMD(i));
- else
- fprintf(NetTrace, "%d ", i);
- if (TELOPT_OK(j))
- fprintf(NetTrace, "%s", TELOPT(j));
- else if (TELCMD_OK(j))
- fprintf(NetTrace, "%s", TELCMD(j));
- else
- fprintf(NetTrace, "%d", j);
- fprintf(NetTrace, ", not IAC SE!) ");
- }
- }
- length -= 2;
- }
- if (length < 1) {
- fprintf(NetTrace, "(Empty suboption??\?)");
- if (NetTrace == stdout)
- fflush(NetTrace);
- return;
- }
- switch (pointer[0]) {
- case TELOPT_TTYPE:
- fprintf(NetTrace, "TERMINAL-TYPE ");
- switch (pointer[1]) {
- case TELQUAL_IS:
- fprintf(NetTrace, "IS \"%.*s\"", length-2, (char *)pointer+2);
- break;
- case TELQUAL_SEND:
- fprintf(NetTrace, "SEND");
- break;
- default:
- fprintf(NetTrace,
- "- unknown qualifier %d (0x%x).",
- pointer[1], pointer[1]);
- }
- break;
- case TELOPT_TSPEED:
- fprintf(NetTrace, "TERMINAL-SPEED");
- if (length < 2) {
- fprintf(NetTrace, " (empty suboption??\?)");
- break;
- }
- switch (pointer[1]) {
- case TELQUAL_IS:
- fprintf(NetTrace, " IS ");
- fprintf(NetTrace, "%.*s", length-2, (char *)pointer+2);
- break;
- default:
- if (pointer[1] == 1)
- fprintf(NetTrace, " SEND");
- else
- fprintf(NetTrace, " %d (unknown)", pointer[1]);
- for (i = 2; i < length; i++)
- fprintf(NetTrace, " ?%d?", pointer[i]);
- break;
- }
- break;
-
- case TELOPT_LFLOW:
- fprintf(NetTrace, "TOGGLE-FLOW-CONTROL");
- if (length < 2) {
- fprintf(NetTrace, " (empty suboption??\?)");
- break;
- }
- switch (pointer[1]) {
- case LFLOW_OFF:
- fprintf(NetTrace, " OFF"); break;
- case LFLOW_ON:
- fprintf(NetTrace, " ON"); break;
- case LFLOW_RESTART_ANY:
- fprintf(NetTrace, " RESTART-ANY"); break;
- case LFLOW_RESTART_XON:
- fprintf(NetTrace, " RESTART-XON"); break;
- default:
- fprintf(NetTrace, " %d (unknown)", pointer[1]);
- }
- for (i = 2; i < length; i++)
- fprintf(NetTrace, " ?%d?", pointer[i]);
- break;
-
- case TELOPT_NAWS:
- fprintf(NetTrace, "NAWS");
- if (length < 2) {
- fprintf(NetTrace, " (empty suboption??\?)");
- break;
- }
- if (length == 2) {
- fprintf(NetTrace, " ?%d?", pointer[1]);
- break;
- }
- fprintf(NetTrace, " %d %d (%d)",
- pointer[1], pointer[2],
- (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2])));
- if (length == 4) {
- fprintf(NetTrace, " ?%d?", pointer[3]);
- break;
- }
- fprintf(NetTrace, " %d %d (%d)",
- pointer[3], pointer[4],
- (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4])));
- for (i = 5; i < length; i++)
- fprintf(NetTrace, " ?%d?", pointer[i]);
- break;
-
-#ifdef AUTHENTICATION
- case TELOPT_AUTHENTICATION:
- fprintf(NetTrace, "AUTHENTICATION");
- if (length < 2) {
- fprintf(NetTrace, " (empty suboption??\?)");
- break;
- }
- switch (pointer[1]) {
- case TELQUAL_REPLY:
- case TELQUAL_IS:
- fprintf(NetTrace, " %s ", (pointer[1] == TELQUAL_IS) ?
- "IS" : "REPLY");
- if (AUTHTYPE_NAME_OK(pointer[2]))
- fprintf(NetTrace, "%s ", AUTHTYPE_NAME(pointer[2]));
- else
- fprintf(NetTrace, "%d ", pointer[2]);
- if (length < 3) {
- fprintf(NetTrace, "(partial suboption??\?)");
- break;
- }
- fprintf(NetTrace, "%s|%s",
- ((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?
- "CLIENT" : "SERVER",
- ((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?
- "MUTUAL" : "ONE-WAY");
-
- auth_printsub(&pointer[1], length - 1, buf, sizeof(buf));
- fprintf(NetTrace, "%s", buf);
- break;
-
- case TELQUAL_SEND:
- i = 2;
- fprintf(NetTrace, " SEND ");
- while (i < length) {
- if (AUTHTYPE_NAME_OK(pointer[i]))
- fprintf(NetTrace, "%s ", AUTHTYPE_NAME(pointer[i]));
- else
- fprintf(NetTrace, "%d ", pointer[i]);
- if (++i >= length) {
- fprintf(NetTrace, "(partial suboption??\?)");
- break;
- }
- fprintf(NetTrace, "%s|%s ",
- ((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?
- "CLIENT" : "SERVER",
- ((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?
- "MUTUAL" : "ONE-WAY");
- ++i;
- }
- break;
-
- case TELQUAL_NAME:
- i = 2;
- fprintf(NetTrace, " NAME \"");
- while (i < length)
- putc(pointer[i++], NetTrace);
- putc('"', NetTrace);
- break;
-
- default:
- for (i = 2; i < length; i++)
- fprintf(NetTrace, " ?%d?", pointer[i]);
- break;
- }
- break;
-#endif
-
-#ifdef ENCRYPTION
- case TELOPT_ENCRYPT:
- fprintf(NetTrace, "ENCRYPT");
- if (length < 2) {
- fprintf(NetTrace, " (empty suboption??\?)");
- break;
- }
- switch (pointer[1]) {
- case ENCRYPT_START:
- fprintf(NetTrace, " START");
- break;
-
- case ENCRYPT_END:
- fprintf(NetTrace, " END");
- break;
-
- case ENCRYPT_REQSTART:
- fprintf(NetTrace, " REQUEST-START");
- break;
-
- case ENCRYPT_REQEND:
- fprintf(NetTrace, " REQUEST-END");
- break;
-
- case ENCRYPT_IS:
- case ENCRYPT_REPLY:
- fprintf(NetTrace, " %s ", (pointer[1] == ENCRYPT_IS) ?
- "IS" : "REPLY");
- if (length < 3) {
- fprintf(NetTrace, " (partial suboption??\?)");
- break;
- }
- if (ENCTYPE_NAME_OK(pointer[2]))
- fprintf(NetTrace, "%s ", ENCTYPE_NAME(pointer[2]));
- else
- fprintf(NetTrace, " %d (unknown)", pointer[2]);
-
- encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf));
- fprintf(NetTrace, "%s", buf);
- break;
-
- case ENCRYPT_SUPPORT:
- i = 2;
- fprintf(NetTrace, " SUPPORT ");
- while (i < length) {
- if (ENCTYPE_NAME_OK(pointer[i]))
- fprintf(NetTrace, "%s ", ENCTYPE_NAME(pointer[i]));
- else
- fprintf(NetTrace, "%d ", pointer[i]);
- i++;
- }
- break;
-
- case ENCRYPT_ENC_KEYID:
- fprintf(NetTrace, " ENC_KEYID ");
- goto encommon;
-
- case ENCRYPT_DEC_KEYID:
- fprintf(NetTrace, " DEC_KEYID ");
- goto encommon;
-
- default:
- fprintf(NetTrace, " %d (unknown)", pointer[1]);
- encommon:
- for (i = 2; i < length; i++)
- fprintf(NetTrace, " %d", pointer[i]);
- break;
- }
- break;
-#endif /* ENCRYPTION */
-
- case TELOPT_LINEMODE:
- fprintf(NetTrace, "LINEMODE ");
- if (length < 2) {
- fprintf(NetTrace, " (empty suboption??\?)");
- break;
- }
- switch (pointer[1]) {
- case WILL:
- fprintf(NetTrace, "WILL ");
- goto common;
- case WONT:
- fprintf(NetTrace, "WONT ");
- goto common;
- case DO:
- fprintf(NetTrace, "DO ");
- goto common;
- case DONT:
- fprintf(NetTrace, "DONT ");
- common:
- if (length < 3) {
- fprintf(NetTrace, "(no option??\?)");
- break;
- }
- switch (pointer[2]) {
- case LM_FORWARDMASK:
- fprintf(NetTrace, "Forward Mask");
- for (i = 3; i < length; i++)
- fprintf(NetTrace, " %x", pointer[i]);
- break;
- default:
- fprintf(NetTrace, "%d (unknown)", pointer[2]);
- for (i = 3; i < length; i++)
- fprintf(NetTrace, " %d", pointer[i]);
- break;
- }
- break;
-
- case LM_SLC:
- fprintf(NetTrace, "SLC");
- for (i = 2; i < length - 2; i += 3) {
- if (SLC_NAME_OK(pointer[i+SLC_FUNC]))
- fprintf(NetTrace, " %s", SLC_NAME(pointer[i+SLC_FUNC]));
- else
- fprintf(NetTrace, " %d", pointer[i+SLC_FUNC]);
- switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) {
- case SLC_NOSUPPORT:
- fprintf(NetTrace, " NOSUPPORT"); break;
- case SLC_CANTCHANGE:
- fprintf(NetTrace, " CANTCHANGE"); break;
- case SLC_VARIABLE:
- fprintf(NetTrace, " VARIABLE"); break;
- case SLC_DEFAULT:
- fprintf(NetTrace, " DEFAULT"); break;
- }
- fprintf(NetTrace, "%s%s%s",
- pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "",
- pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "",
- pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : "");
- if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN|
- SLC_FLUSHOUT| SLC_LEVELBITS))
- fprintf(NetTrace, "(0x%x)", pointer[i+SLC_FLAGS]);
- fprintf(NetTrace, " %d;", pointer[i+SLC_VALUE]);
- if ((pointer[i+SLC_VALUE] == IAC) &&
- (pointer[i+SLC_VALUE+1] == IAC))
- i++;
- }
- for (; i < length; i++)
- fprintf(NetTrace, " ?%d?", pointer[i]);
- break;
-
- case LM_MODE:
- fprintf(NetTrace, "MODE ");
- if (length < 3) {
- fprintf(NetTrace, "(no mode??\?)");
- break;
- }
- {
- char tbuf[64];
- sprintf(tbuf, "%s%s%s%s%s",
- pointer[2]&MODE_EDIT ? "|EDIT" : "",
- pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "",
- pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "",
- pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "",
- pointer[2]&MODE_ACK ? "|ACK" : "");
- fprintf(NetTrace, "%s", tbuf[1] ? &tbuf[1] : "0");
- }
- if (pointer[2]&~(MODE_MASK))
- fprintf(NetTrace, " (0x%x)", pointer[2]);
- for (i = 3; i < length; i++)
- fprintf(NetTrace, " ?0x%x?", pointer[i]);
- break;
- default:
- fprintf(NetTrace, "%d (unknown)", pointer[1]);
- for (i = 2; i < length; i++)
- fprintf(NetTrace, " %d", pointer[i]);
- }
- break;
-
- case TELOPT_STATUS: {
- const char *cp;
- int j, k;
-
- fprintf(NetTrace, "STATUS");
-
- switch (pointer[1]) {
- default:
- if (pointer[1] == TELQUAL_SEND)
- fprintf(NetTrace, " SEND");
- else
- fprintf(NetTrace, " %d (unknown)", pointer[1]);
- for (i = 2; i < length; i++)
- fprintf(NetTrace, " ?%d?", pointer[i]);
- break;
- case TELQUAL_IS:
- if (--want_status_response < 0)
- want_status_response = 0;
- if (NetTrace == stdout)
- fprintf(NetTrace, " IS\r\n");
- else
- fprintf(NetTrace, " IS\n");
-
- for (i = 2; i < length; i++) {
- switch(pointer[i]) {
- case DO: cp = "DO"; goto common2;
- case DONT: cp = "DONT"; goto common2;
- case WILL: cp = "WILL"; goto common2;
- case WONT: cp = "WONT"; goto common2;
- common2:
- i++;
- if (TELOPT_OK((int)pointer[i]))
- fprintf(NetTrace, " %s %s", cp, TELOPT(pointer[i]));
- else
- fprintf(NetTrace, " %s %d", cp, pointer[i]);
-
- if (NetTrace == stdout)
- fprintf(NetTrace, "\r\n");
- else
- fprintf(NetTrace, "\n");
- break;
-
- case SB:
- fprintf(NetTrace, " SB ");
- i++;
- j = k = i;
- while (j < length) {
- if (pointer[j] == SE) {
- if (j+1 == length)
- break;
- if (pointer[j+1] == SE)
- j++;
- else
- break;
- }
- pointer[k++] = pointer[j++];
- }
- printsub(0, &pointer[i], k - i);
- if (i < length) {
- fprintf(NetTrace, " SE");
- i = j;
- } else
- i = j - 1;
-
- if (NetTrace == stdout)
- fprintf(NetTrace, "\r\n");
- else
- fprintf(NetTrace, "\n");
-
- break;
-
- default:
- fprintf(NetTrace, " %d", pointer[i]);
- break;
- }
- }
- break;
- }
- break;
- }
-
- case TELOPT_XDISPLOC:
- fprintf(NetTrace, "X-DISPLAY-LOCATION ");
- switch (pointer[1]) {
- case TELQUAL_IS:
- fprintf(NetTrace, "IS \"%.*s\"", length-2, (char *)pointer+2);
- break;
- case TELQUAL_SEND:
- fprintf(NetTrace, "SEND");
- break;
- default:
- fprintf(NetTrace, "- unknown qualifier %d (0x%x).",
- pointer[1], pointer[1]);
- }
- break;
-
- case TELOPT_NEW_ENVIRON:
- fprintf(NetTrace, "NEW-ENVIRON ");
-#ifdef OLD_ENVIRON
- goto env_common1;
- case TELOPT_OLD_ENVIRON:
- fprintf(NetTrace, "OLD-ENVIRON");
- env_common1:
-#endif
- switch (pointer[1]) {
- case TELQUAL_IS:
- fprintf(NetTrace, "IS ");
- goto env_common;
- case TELQUAL_SEND:
- fprintf(NetTrace, "SEND ");
- goto env_common;
- case TELQUAL_INFO:
- fprintf(NetTrace, "INFO ");
- env_common:
- {
- int noquote = 2;
-#if defined(ENV_HACK) && defined(OLD_ENVIRON)
- extern int old_env_var, old_env_value;
-#endif
- for (i = 2; i < length; i++ ) {
- switch (pointer[i]) {
- case NEW_ENV_VALUE:
-#ifdef OLD_ENVIRON
- /* case NEW_ENV_OVAR: */
- if (pointer[0] == TELOPT_OLD_ENVIRON) {
-# ifdef ENV_HACK
- if (old_env_var == OLD_ENV_VALUE)
- fprintf(NetTrace, "\" (VALUE) " + noquote);
- else
-# endif
- fprintf(NetTrace, "\" VAR " + noquote);
- } else
-#endif /* OLD_ENVIRON */
- fprintf(NetTrace, "\" VALUE " + noquote);
- noquote = 2;
- break;
-
- case NEW_ENV_VAR:
-#ifdef OLD_ENVIRON
- /* case OLD_ENV_VALUE: */
- if (pointer[0] == TELOPT_OLD_ENVIRON) {
-# ifdef ENV_HACK
- if (old_env_value == OLD_ENV_VAR)
- fprintf(NetTrace, "\" (VAR) " + noquote);
- else
-# endif
- fprintf(NetTrace, "\" VALUE " + noquote);
- } else
-#endif /* OLD_ENVIRON */
- fprintf(NetTrace, "\" VAR " + noquote);
- noquote = 2;
- break;
-
- case ENV_ESC:
- fprintf(NetTrace, "\" ESC " + noquote);
- noquote = 2;
- break;
-
- case ENV_USERVAR:
- fprintf(NetTrace, "\" USERVAR " + noquote);
- noquote = 2;
- break;
-
- default:
- if (isprint(pointer[i]) && pointer[i] != '"') {
- if (noquote) {
- putc('"', NetTrace);
- noquote = 0;
- }
- putc(pointer[i], NetTrace);
- } else {
- fprintf(NetTrace, "\" %03o " + noquote,
- pointer[i]);
- noquote = 2;
- }
- break;
- }
- }
- if (!noquote)
- putc('"', NetTrace);
- break;
- }
- }
- break;
-
- default:
- if (TELOPT_OK(pointer[0]))
- fprintf(NetTrace, "%s (unknown)", TELOPT(pointer[0]));
- else
- fprintf(NetTrace, "%d (unknown)", pointer[0]);
- for (i = 1; i < length; i++)
- fprintf(NetTrace, " %d", pointer[i]);
- break;
- }
- if (direction) {
- if (NetTrace == stdout)
- fprintf(NetTrace, "\r\n");
- else
- fprintf(NetTrace, "\n");
- }
- if (NetTrace == stdout)
- fflush(NetTrace);
- }
-}
-
-/* EmptyTerminal - called to make sure that the terminal buffer is empty.
- * Note that we consider the buffer to run all the
- * way to the kernel (thus the select).
- */
-
-static void
-EmptyTerminal(void)
-{
- fd_set o;
-
- FD_ZERO(&o);
-
- if (TTYBYTES() == 0) {
- FD_SET(tout, &o);
- (void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0,
- (struct timeval *) 0); /* wait for TTLOWAT */
- } else {
- while (TTYBYTES()) {
- (void) ttyflush(0);
- FD_SET(tout, &o);
- (void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0,
- (struct timeval *) 0); /* wait for TTLOWAT */
- }
- }
-}
-
-static void
-SetForExit(void)
-{
- setconnmode(0);
- do {
- (void)telrcv(); /* Process any incoming data */
- EmptyTerminal();
- } while (ring_full_count(&netiring)); /* While there is any */
- setcommandmode();
- fflush(stdout);
- fflush(stderr);
- setconnmode(0);
- EmptyTerminal(); /* Flush the path to the tty */
- setcommandmode();
-}
-
-void
-Exit(int returnCode)
-{
- SetForExit();
- exit(returnCode);
-}
-
-void
-ExitString(const char *string, int returnCode)
-{
- SetForExit();
- fwrite(string, 1, strlen(string), stderr);
- exit(returnCode);
-}
diff --git a/contrib/telnet/telnetd/authenc.c b/contrib/telnet/telnetd/authenc.c
deleted file mode 100644
index 9377b522c972..000000000000
--- a/contrib/telnet/telnetd/authenc.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)authenc.c 8.2 (Berkeley) 5/30/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#ifdef AUTHENTICATION
-#ifdef ENCRYPTION
-/* Above "#ifdef"s actually "or"'ed together. XXX MarkM
- */
-#include "telnetd.h"
-#include <libtelnet/misc.h>
-
-int
-net_write(unsigned char *str, int len)
-{
- if (nfrontp + len < netobuf + BUFSIZ) {
- output_datalen(str, len);
- return(len);
- }
- return(0);
-}
-
-void
-net_encrypt(void)
-{
-#ifdef ENCRYPTION
- char *s = (nclearto > nbackp) ? nclearto : nbackp;
- if (s < nfrontp && encrypt_output) {
- (*encrypt_output)((unsigned char *)s, nfrontp - s);
- }
- nclearto = nfrontp;
-#endif /* ENCRYPTION */
-}
-
-int
-telnet_spin(void)
-{
- ttloop();
- return(0);
-}
-
-char *
-telnet_getenv(char *val)
-{
- return(getenv(val));
-}
-
-char *
-telnet_gets(const char *prompt __unused, char *result __unused, int length __unused, int echo __unused)
-{
- return(NULL);
-}
-#endif /* ENCRYPTION */
-#endif /* AUTHENTICATION */
diff --git a/contrib/telnet/telnetd/defs.h b/contrib/telnet/telnetd/defs.h
deleted file mode 100644
index d727f367c045..000000000000
--- a/contrib/telnet/telnetd/defs.h
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)defs.h 8.1 (Berkeley) 6/4/93
- * $FreeBSD$
- */
-
-/*
- * Telnet server defines
- */
-#include <sys/types.h>
-#include <sys/param.h>
-
-#ifndef BSD
-# define BSD 43
-#endif
-
-#if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
-#define TELOPTS
-#define TELCMDS
-#define SLC_NAMES
-#endif
-
-#if defined(SYSV_TERMIO) && !defined(USE_TERMIO)
-# define USE_TERMIO
-#endif
-
-#include <sys/socket.h>
-#include <sys/wait.h>
-#include <fcntl.h>
-#include <sys/file.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#ifndef FILIO_H
-#include <sys/ioctl.h>
-#else
-#include <sys/filio.h>
-#endif
-
-#include <netinet/in.h>
-
-#include <arpa/telnet.h>
-
-#include <stdio.h>
-#ifdef __STDC__
-#include <stdlib.h>
-#endif
-#include <signal.h>
-#include <errno.h>
-#include <netdb.h>
-#include <syslog.h>
-#ifndef LOG_DAEMON
-#define LOG_DAEMON 0
-#endif
-#ifndef LOG_ODELAY
-#define LOG_ODELAY 0
-#endif
-#include <ctype.h>
-#ifndef NO_STRING_H
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-
-#ifndef USE_TERMIO
-#include <sgtty.h>
-#else
-# ifdef SYSV_TERMIO
-# include <termio.h>
-# else
-# include <termios.h>
-# endif
-#endif
-#if !defined(USE_TERMIO) || defined(NO_CC_T)
-typedef unsigned char cc_t;
-#endif
-
-#ifdef __STDC__
-#include <unistd.h>
-#endif
-
-#ifndef _POSIX_VDISABLE
-# ifdef VDISABLE
-# define _POSIX_VDISABLE VDISABLE
-# else
-# define _POSIX_VDISABLE ((unsigned char)'\377')
-# endif
-#endif
-
-#if !defined(TIOCSCTTY) && defined(TCSETCTTY)
-# define TIOCSCTTY TCSETCTTY
-#endif
-
-#ifndef FD_SET
-#ifndef HAVE_fd_set
-typedef struct fd_set { int fds_bits[1]; } fd_set;
-#endif
-
-#define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n)))
-#define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n)))
-#define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n)))
-#define FD_ZERO(p) ((p)->fds_bits[0] = 0)
-#endif /* FD_SET */
-
-/*
- * I/O data buffers defines
- */
-#define NETSLOP 64
-
-#define NIACCUM(c) { *netip++ = c; \
- ncc++; \
- }
-
-/* clock manipulations */
-#define settimer(x) (clocks.x = ++clocks.system)
-#define sequenceIs(x,y) (clocks.x < clocks.y)
-
-/*
- * Linemode support states, in decreasing order of importance
- */
-#define REAL_LINEMODE 0x04
-#define KLUDGE_OK 0x03
-#define NO_AUTOKLUDGE 0x02
-#define KLUDGE_LINEMODE 0x01
-#define NO_LINEMODE 0x00
-
-/*
- * Structures of information for each special character function.
- */
-typedef struct {
- unsigned char flag; /* the flags for this function */
- cc_t val; /* the value of the special character */
-} slcent, *Slcent;
-
-typedef struct {
- slcent defset; /* the default settings */
- slcent current; /* the current settings */
- cc_t *sptr; /* a pointer to the char in */
- /* system data structures */
-} slcfun, *Slcfun;
-
-#ifdef DIAGNOSTICS
-/*
- * Diagnostics capabilities
- */
-#define TD_REPORT 0x01 /* Report operations to client */
-#define TD_EXERCISE 0x02 /* Exercise client's implementation */
-#define TD_NETDATA 0x04 /* Display received data stream */
-#define TD_PTYDATA 0x08 /* Display data passed to pty */
-#define TD_OPTIONS 0x10 /* Report just telnet options */
-#endif /* DIAGNOSTICS */
-
-/*
- * We keep track of each side of the option negotiation.
- */
-
-#define MY_STATE_WILL 0x01
-#define MY_WANT_STATE_WILL 0x02
-#define MY_STATE_DO 0x04
-#define MY_WANT_STATE_DO 0x08
-
-/*
- * Macros to check the current state of things
- */
-
-#define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
-#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
-#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
-#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
-
-#define my_state_is_dont(opt) (!my_state_is_do(opt))
-#define my_state_is_wont(opt) (!my_state_is_will(opt))
-#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
-#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
-
-#define set_my_state_do(opt) (options[opt] |= MY_STATE_DO)
-#define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL)
-#define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO)
-#define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL)
-
-#define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO)
-#define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL)
-#define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO)
-#define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL)
-
-/*
- * Tricky code here. What we want to know is if the MY_STATE_WILL
- * and MY_WANT_STATE_WILL bits have the same value. Since the two
- * bits are adjacent, a little arithmatic will show that by adding
- * in the lower bit, the upper bit will be set if the two bits were
- * different, and clear if they were the same.
- */
-#define my_will_wont_is_changing(opt) \
- ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
-
-#define my_do_dont_is_changing(opt) \
- ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
-
-/*
- * Make everything symetrical
- */
-
-#define HIS_STATE_WILL MY_STATE_DO
-#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
-#define HIS_STATE_DO MY_STATE_WILL
-#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
-
-#define his_state_is_do my_state_is_will
-#define his_state_is_will my_state_is_do
-#define his_want_state_is_do my_want_state_is_will
-#define his_want_state_is_will my_want_state_is_do
-
-#define his_state_is_dont my_state_is_wont
-#define his_state_is_wont my_state_is_dont
-#define his_want_state_is_dont my_want_state_is_wont
-#define his_want_state_is_wont my_want_state_is_dont
-
-#define set_his_state_do set_my_state_will
-#define set_his_state_will set_my_state_do
-#define set_his_want_state_do set_my_want_state_will
-#define set_his_want_state_will set_my_want_state_do
-
-#define set_his_state_dont set_my_state_wont
-#define set_his_state_wont set_my_state_dont
-#define set_his_want_state_dont set_my_want_state_wont
-#define set_his_want_state_wont set_my_want_state_dont
-
-#define his_will_wont_is_changing my_do_dont_is_changing
-#define his_do_dont_is_changing my_will_wont_is_changing
diff --git a/contrib/telnet/telnetd/ext.h b/contrib/telnet/telnetd/ext.h
deleted file mode 100644
index 448ba68b92fd..000000000000
--- a/contrib/telnet/telnetd/ext.h
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ext.h 8.2 (Berkeley) 12/15/93
- * $FreeBSD$
- */
-
-/*
- * Telnet server variable declarations
- */
-extern char options[256];
-extern char do_dont_resp[256];
-extern char will_wont_resp[256];
-extern int linemode; /* linemode on/off */
-#ifdef LINEMODE
-extern int uselinemode; /* what linemode to use (on/off) */
-extern int editmode; /* edit modes in use */
-extern int useeditmode; /* edit modes to use */
-extern int alwayslinemode; /* command line option */
-extern int lmodetype; /* Client support for linemode */
-#endif /* LINEMODE */
-extern int flowmode; /* current flow control state */
-extern int restartany; /* restart output on any character state */
-#ifdef DIAGNOSTICS
-extern int diagnostic; /* telnet diagnostic capabilities */
-#endif /* DIAGNOSTICS */
-#ifdef BFTPDAEMON
-extern int bftpd; /* behave as bftp daemon */
-#endif /* BFTPDAEMON */
-#ifdef AUTHENTICATION
-extern int auth_level;
-#endif
-
-extern slcfun slctab[NSLC + 1]; /* slc mapping table */
-
-char *terminaltype;
-
-/*
- * I/O data buffers, pointers, and counters.
- */
-extern char ptyobuf[BUFSIZ+NETSLOP], *pfrontp, *pbackp;
-
-extern char netibuf[BUFSIZ], *netip;
-
-extern char netobuf[BUFSIZ], *nfrontp, *nbackp;
-extern char *neturg; /* one past last bye of urgent data */
-
-extern int pcc, ncc;
-
-extern int pty, net;
-extern char line[16];
-extern int SYNCHing; /* we are in TELNET SYNCH mode */
-
-extern void
- _termstat(void),
- add_slc(char, char, cc_t),
- check_slc(void),
- change_slc(char, char, cc_t),
- cleanup(int),
- clientstat(int, int, int),
- copy_termbuf(char *, size_t),
- deferslc(void),
- defer_terminit(void),
- do_opt_slc(unsigned char *, int),
- doeof(void),
- dooption(int),
- dontoption(int),
- edithost(char *, char *),
- fatal(int, const char *),
- fatalperror(int, const char *),
- get_slc_defaults(void),
- init_env(void),
- init_termbuf(void),
- interrupt(void),
- localstat(void),
- flowstat(void),
- netclear(void),
- netflush(void),
-#ifdef DIAGNOSTICS
- printoption(const char *, int),
- printdata(const char *, char *, int),
- printsub(char, unsigned char *, int),
-#endif
- process_slc(unsigned char, unsigned char, cc_t),
- ptyflush(void),
- putchr(int),
- putf(char *, char *),
- recv_ayt(void),
- send_do(int, int),
- send_dont(int, int),
- send_slc(void),
- send_status(void),
- send_will(int, int),
- send_wont(int, int),
- sendbrk(void),
- sendsusp(void),
- set_termbuf(void),
- start_login(char *, int, char *),
- start_slc(int),
-#ifdef AUTHENTICATION
- start_slave(char *),
-#else
- start_slave(char *, int, char *),
-#endif
- suboption(void),
- telrcv(void),
- ttloop(void),
- tty_binaryin(int),
- tty_binaryout(int);
-
-extern int
- end_slc(unsigned char **),
- getnpty(void),
-#ifndef convex
- getpty(int *),
-#endif
- login_tty(int),
- spcset(int, cc_t *, cc_t **),
- stilloob(int),
- terminit(void),
- termstat(void),
- tty_flowmode(void),
- tty_restartany(void),
- tty_isbinaryin(void),
- tty_isbinaryout(void),
- tty_iscrnl(void),
- tty_isecho(void),
- tty_isediting(void),
- tty_islitecho(void),
- tty_isnewmap(void),
- tty_israw(void),
- tty_issofttab(void),
- tty_istrapsig(void),
- tty_linemode(void);
-
-extern void
- tty_rspeed(int),
- tty_setecho(int),
- tty_setedit(int),
- tty_setlinemode(int),
- tty_setlitecho(int),
- tty_setsig(int),
- tty_setsofttab(int),
- tty_tspeed(int),
- willoption(int),
- wontoption(int);
-
-int output_data(const char *, ...) __printflike(1, 2);
-void output_datalen(const char *, int);
-void startslave(char *, int, char *);
-
-#ifdef ENCRYPTION
-extern void (*encrypt_output)(unsigned char *, int);
-extern int (*decrypt_input)(int);
-extern char *nclearto;
-#endif /* ENCRYPTION */
-
-
-/*
- * The following are some clocks used to decide how to interpret
- * the relationship between various variables.
- */
-
-extern struct {
- int
- system, /* what the current time is */
- echotoggle, /* last time user entered echo character */
- modenegotiated, /* last time operating mode negotiated */
- didnetreceive, /* last time we read data from network */
- ttypesubopt, /* ttype subopt is received */
- tspeedsubopt, /* tspeed subopt is received */
- environsubopt, /* environ subopt is received */
- oenvironsubopt, /* old environ subopt is received */
- xdisplocsubopt, /* xdisploc subopt is received */
- baseline, /* time started to do timed action */
- gotDM; /* when did we last see a data mark */
-} clocks;
-
-#ifndef DEFAULT_IM
-# ifdef ultrix
-# define DEFAULT_IM "\r\n\r\nULTRIX (%h) (%t)\r\n\r\r\n\r"
-# else
-# ifdef __FreeBSD__
-# define DEFAULT_IM "\r\n\r\nFreeBSD (%h) (%t)\r\n\r\r\n\r"
-# else
-# define DEFAULT_IM "\r\n\r\n4.4 BSD UNIX (%h) (%t)\r\n\r\r\n\r"
-# endif
-# endif
-#endif
diff --git a/contrib/telnet/telnetd/global.c b/contrib/telnet/telnetd/global.c
deleted file mode 100644
index 2ed82d0b6aee..000000000000
--- a/contrib/telnet/telnetd/global.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)global.c 8.1 (Berkeley) 6/4/93";
-#endif /* not lint */
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * Allocate global variables. We do this
- * by including the header file that defines
- * them all as externs, but first we define
- * the keyword "extern" to be nothing, so that
- * we will actually allocate the space.
- */
-
-#include "defs.h"
-#define extern
-#include "ext.h"
diff --git a/contrib/telnet/telnetd/pathnames.h b/contrib/telnet/telnetd/pathnames.h
deleted file mode 100644
index ed8ee887a39e..000000000000
--- a/contrib/telnet/telnetd/pathnames.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pathnames.h 8.1 (Berkeley) 6/4/93
- * $FreeBSD$
- */
-
-#if BSD > 43
-
-# include <paths.h>
-
-# ifndef _PATH_LOGIN
-# define _PATH_LOGIN "/usr/bin/login"
-# endif
-
-#else
-
-# define _PATH_TTY "/dev/tty"
-# ifndef _PATH_LOGIN
-# define _PATH_LOGIN "/bin/login"
-# endif
-
-#endif
-
-#ifdef BFTPDAEMON
-#define BFTPPATH "/usr/ucb/bftp"
-#endif /* BFTPDAEMON */
diff --git a/contrib/telnet/telnetd/slc.c b/contrib/telnet/telnetd/slc.c
deleted file mode 100644
index ad034418d313..000000000000
--- a/contrib/telnet/telnetd/slc.c
+++ /dev/null
@@ -1,484 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)slc.c 8.2 (Berkeley) 5/30/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "telnetd.h"
-
-#ifdef LINEMODE
-/*
- * local variables
- */
-static unsigned char *def_slcbuf = (unsigned char *)0;
-static int def_slclen = 0;
-static int slcchange; /* change to slc is requested */
-static unsigned char *slcptr; /* pointer into slc buffer */
-static unsigned char slcbuf[NSLC*6]; /* buffer for slc negotiation */
-
-/*
- * send_slc
- *
- * Write out the current special characters to the client.
- */
-void
-send_slc(void)
-{
- int i;
-
- /*
- * Send out list of triplets of special characters
- * to client. We only send info on the characters
- * that are currently supported.
- */
- for (i = 1; i <= NSLC; i++) {
- if ((slctab[i].defset.flag & SLC_LEVELBITS) == SLC_NOSUPPORT)
- continue;
- add_slc((unsigned char)i, slctab[i].current.flag,
- slctab[i].current.val);
- }
-
-} /* end of send_slc */
-
-/*
- * default_slc
- *
- * Set pty special characters to all the defaults.
- */
-static void
-default_slc(void)
-{
- int i;
-
- for (i = 1; i <= NSLC; i++) {
- slctab[i].current.val = slctab[i].defset.val;
- if (slctab[i].current.val == (cc_t)(_POSIX_VDISABLE))
- slctab[i].current.flag = SLC_NOSUPPORT;
- else
- slctab[i].current.flag = slctab[i].defset.flag;
- if (slctab[i].sptr) {
- *(slctab[i].sptr) = slctab[i].defset.val;
- }
- }
- slcchange = 1;
-
-} /* end of default_slc */
-#endif /* LINEMODE */
-
-/*
- * get_slc_defaults
- *
- * Initialize the slc mapping table.
- */
-void
-get_slc_defaults(void)
-{
- int i;
-
- init_termbuf();
-
- for (i = 1; i <= NSLC; i++) {
- slctab[i].defset.flag =
- spcset(i, &slctab[i].defset.val, &slctab[i].sptr);
- slctab[i].current.flag = SLC_NOSUPPORT;
- slctab[i].current.val = 0;
- }
-
-} /* end of get_slc_defaults */
-
-#ifdef LINEMODE
-/*
- * add_slc
- *
- * Add an slc triplet to the slc buffer.
- */
-void
-add_slc(char func, char flag, cc_t val)
-{
-
- if ((*slcptr++ = (unsigned char)func) == 0xff)
- *slcptr++ = 0xff;
-
- if ((*slcptr++ = (unsigned char)flag) == 0xff)
- *slcptr++ = 0xff;
-
- if ((*slcptr++ = (unsigned char)val) == 0xff)
- *slcptr++ = 0xff;
-
-} /* end of add_slc */
-
-/*
- * start_slc
- *
- * Get ready to process incoming slc's and respond to them.
- *
- * The parameter getit is non-zero if it is necessary to grab a copy
- * of the terminal control structures.
- */
-void
-start_slc(int getit)
-{
-
- slcchange = 0;
- if (getit)
- init_termbuf();
- (void) sprintf((char *)slcbuf, "%c%c%c%c",
- IAC, SB, TELOPT_LINEMODE, LM_SLC);
- slcptr = slcbuf + 4;
-
-} /* end of start_slc */
-
-/*
- * end_slc
- *
- * Finish up the slc negotiation. If something to send, then send it.
- */
-int
-end_slc(unsigned char **bufp)
-{
- int len;
-
- /*
- * If a change has occured, store the new terminal control
- * structures back to the terminal driver.
- */
- if (slcchange) {
- set_termbuf();
- }
-
- /*
- * If the pty state has not yet been fully processed and there is a
- * deferred slc request from the client, then do not send any
- * sort of slc negotiation now. We will respond to the client's
- * request very soon.
- */
- if (def_slcbuf && (terminit() == 0)) {
- return(0);
- }
-
- if (slcptr > (slcbuf + 4)) {
- if (bufp) {
- *bufp = &slcbuf[4];
- return(slcptr - slcbuf - 4);
- } else {
- (void) sprintf((char *)slcptr, "%c%c", IAC, SE);
- slcptr += 2;
- len = slcptr - slcbuf;
- output_datalen(slcbuf, len);
- netflush(); /* force it out immediately */
- DIAG(TD_OPTIONS, printsub('>', slcbuf+2, len-2););
- }
- }
- return (0);
-
-} /* end of end_slc */
-
-/*
- * process_slc
- *
- * Figure out what to do about the client's slc
- */
-void
-process_slc(unsigned char func, unsigned char flag, cc_t val)
-{
- int hislevel, mylevel, ack;
-
- /*
- * Ensure that we know something about this function
- */
- if (func > NSLC) {
- add_slc(func, SLC_NOSUPPORT, 0);
- return;
- }
-
- /*
- * Process the special case requests of 0 SLC_DEFAULT 0
- * and 0 SLC_VARIABLE 0. Be a little forgiving here, don't
- * worry about whether the value is actually 0 or not.
- */
- if (func == 0) {
- if ((flag = flag & SLC_LEVELBITS) == SLC_DEFAULT) {
- default_slc();
- send_slc();
- } else if (flag == SLC_VARIABLE) {
- send_slc();
- }
- return;
- }
-
- /*
- * Appears to be a function that we know something about. So
- * get on with it and see what we know.
- */
-
- hislevel = flag & SLC_LEVELBITS;
- mylevel = slctab[func].current.flag & SLC_LEVELBITS;
- ack = flag & SLC_ACK;
- /*
- * ignore the command if:
- * the function value and level are the same as what we already have;
- * or the level is the same and the ack bit is set
- */
- if (hislevel == mylevel && (val == slctab[func].current.val || ack)) {
- return;
- } else if (ack) {
- /*
- * If we get here, we got an ack, but the levels don't match.
- * This shouldn't happen. If it does, it is probably because
- * we have sent two requests to set a variable without getting
- * a response between them, and this is the first response.
- * So, ignore it, and wait for the next response.
- */
- return;
- } else {
- change_slc(func, flag, val);
- }
-
-} /* end of process_slc */
-
-/*
- * change_slc
- *
- * Process a request to change one of our special characters.
- * Compare client's request with what we are capable of supporting.
- */
-void
-change_slc(char func, char flag, cc_t val)
-{
- int hislevel, mylevel;
-
- hislevel = flag & SLC_LEVELBITS;
- mylevel = slctab[(int)func].defset.flag & SLC_LEVELBITS;
- /*
- * If client is setting a function to NOSUPPORT
- * or DEFAULT, then we can easily and directly
- * accomodate the request.
- */
- if (hislevel == SLC_NOSUPPORT) {
- slctab[(int)func].current.flag = flag;
- slctab[(int)func].current.val = (cc_t)_POSIX_VDISABLE;
- flag |= SLC_ACK;
- add_slc(func, flag, val);
- return;
- }
- if (hislevel == SLC_DEFAULT) {
- /*
- * Special case here. If client tells us to use
- * the default on a function we don't support, then
- * return NOSUPPORT instead of what we may have as a
- * default level of DEFAULT.
- */
- if (mylevel == SLC_DEFAULT) {
- slctab[(int)func].current.flag = SLC_NOSUPPORT;
- } else {
- slctab[(int)func].current.flag = slctab[(int)func].defset.flag;
- }
- slctab[(int)func].current.val = slctab[(int)func].defset.val;
- add_slc(func, slctab[(int)func].current.flag,
- slctab[(int)func].current.val);
- return;
- }
-
- /*
- * Client wants us to change to a new value or he
- * is telling us that he can't change to our value.
- * Some of the slc's we support and can change,
- * some we do support but can't change,
- * and others we don't support at all.
- * If we can change it then we have a pointer to
- * the place to put the new value, so change it,
- * otherwise, continue the negotiation.
- */
- if (slctab[(int)func].sptr) {
- /*
- * We can change this one.
- */
- slctab[(int)func].current.val = val;
- *(slctab[(int)func].sptr) = val;
- slctab[(int)func].current.flag = flag;
- flag |= SLC_ACK;
- slcchange = 1;
- add_slc(func, flag, val);
- } else {
- /*
- * It is not possible for us to support this
- * request as he asks.
- *
- * If our level is DEFAULT, then just ack whatever was
- * sent.
- *
- * If he can't change and we can't change,
- * then degenerate to NOSUPPORT.
- *
- * Otherwise we send our level back to him, (CANTCHANGE
- * or NOSUPPORT) and if CANTCHANGE, send
- * our value as well.
- */
- if (mylevel == SLC_DEFAULT) {
- slctab[(int)func].current.flag = flag;
- slctab[(int)func].current.val = val;
- flag |= SLC_ACK;
- } else if (hislevel == SLC_CANTCHANGE &&
- mylevel == SLC_CANTCHANGE) {
- flag &= ~SLC_LEVELBITS;
- flag |= SLC_NOSUPPORT;
- slctab[(int)func].current.flag = flag;
- } else {
- flag &= ~SLC_LEVELBITS;
- flag |= mylevel;
- slctab[(int)func].current.flag = flag;
- if (mylevel == SLC_CANTCHANGE) {
- slctab[(int)func].current.val =
- slctab[(int)func].defset.val;
- val = slctab[(int)func].current.val;
- }
- }
- add_slc(func, flag, val);
- }
-
-} /* end of change_slc */
-
-#if defined(USE_TERMIO) && (VEOF == VMIN)
-cc_t oldeofc = '\004';
-#endif
-
-/*
- * check_slc
- *
- * Check the special characters in use and notify the client if any have
- * changed. Only those characters that are capable of being changed are
- * likely to have changed. If a local change occurs, kick the support level
- * and flags up to the defaults.
- */
-void
-check_slc(void)
-{
- int i;
-
- for (i = 1; i <= NSLC; i++) {
-#if defined(USE_TERMIO) && (VEOF == VMIN)
- /*
- * In a perfect world this would be a neat little
- * function. But in this world, we should not notify
- * client of changes to the VEOF char when
- * ICANON is off, because it is not representing
- * a special character.
- */
- if (i == SLC_EOF) {
- if (!tty_isediting())
- continue;
- else if (slctab[i].sptr)
- oldeofc = *(slctab[i].sptr);
- }
-#endif /* defined(USE_TERMIO) && defined(SYSV_TERMIO) */
- if (slctab[i].sptr &&
- (*(slctab[i].sptr) != slctab[i].current.val)) {
- slctab[i].current.val = *(slctab[i].sptr);
- if (*(slctab[i].sptr) == (cc_t)_POSIX_VDISABLE)
- slctab[i].current.flag = SLC_NOSUPPORT;
- else
- slctab[i].current.flag = slctab[i].defset.flag;
- add_slc((unsigned char)i, slctab[i].current.flag,
- slctab[i].current.val);
- }
- }
-} /* check_slc */
-
-/*
- * do_opt_slc
- *
- * Process an slc option buffer. Defer processing of incoming slc's
- * until after the terminal state has been processed. Save the first slc
- * request that comes along, but discard all others.
- *
- * ptr points to the beginning of the buffer, len is the length.
- */
-void
-do_opt_slc(unsigned char *ptr, int len)
-{
- unsigned char func, flag;
- cc_t val;
- unsigned char *end = ptr + len;
-
- if (terminit()) { /* go ahead */
- while (ptr < end) {
- func = *ptr++;
- if (ptr >= end) break;
- flag = *ptr++;
- if (ptr >= end) break;
- val = (cc_t)*ptr++;
-
- process_slc(func, flag, val);
-
- }
- } else {
- /*
- * save this slc buffer if it is the first, otherwise dump
- * it.
- */
- if (def_slcbuf == (unsigned char *)0) {
- def_slclen = len;
- def_slcbuf = (unsigned char *)malloc((unsigned)len);
- if (def_slcbuf == (unsigned char *)0)
- return; /* too bad */
- memmove(def_slcbuf, ptr, len);
- }
- }
-
-} /* end of do_opt_slc */
-
-/*
- * deferslc
- *
- * Do slc stuff that was deferred.
- */
-void
-deferslc(void)
-{
- if (def_slcbuf) {
- start_slc(1);
- do_opt_slc(def_slcbuf, def_slclen);
- (void) end_slc(0);
- free(def_slcbuf);
- def_slcbuf = (unsigned char *)0;
- def_slclen = 0;
- }
-
-} /* end of deferslc */
-
-#endif /* LINEMODE */
diff --git a/contrib/telnet/telnetd/state.c b/contrib/telnet/telnetd/state.c
deleted file mode 100644
index 9db4516096a0..000000000000
--- a/contrib/telnet/telnetd/state.c
+++ /dev/null
@@ -1,1631 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)state.c 8.5 (Berkeley) 5/30/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdarg.h>
-#include "telnetd.h"
-#ifdef AUTHENTICATION
-#include <libtelnet/auth.h>
-#endif
-#ifdef ENCRYPTION
-#include <libtelnet/encrypt.h>
-#endif
-
-unsigned char doopt[] = { IAC, DO, '%', 'c', 0 };
-unsigned char dont[] = { IAC, DONT, '%', 'c', 0 };
-unsigned char will[] = { IAC, WILL, '%', 'c', 0 };
-unsigned char wont[] = { IAC, WONT, '%', 'c', 0 };
-int not42 = 1;
-
-/*
- * Buffer for sub-options, and macros
- * for suboptions buffer manipulations
- */
-unsigned char subbuffer[512], *subpointer= subbuffer, *subend= subbuffer;
-
-#define SB_CLEAR() subpointer = subbuffer
-#define SB_TERM() { subend = subpointer; SB_CLEAR(); }
-#define SB_ACCUM(c) if (subpointer < (subbuffer+sizeof subbuffer)) { \
- *subpointer++ = (c); \
- }
-#define SB_GET() ((*subpointer++)&0xff)
-#define SB_EOF() (subpointer >= subend)
-#define SB_LEN() (subend - subpointer)
-
-#ifdef ENV_HACK
-unsigned char *subsave;
-#define SB_SAVE() subsave = subpointer;
-#define SB_RESTORE() subpointer = subsave;
-#endif
-
-
-/*
- * State for recv fsm
- */
-#define TS_DATA 0 /* base state */
-#define TS_IAC 1 /* look for double IAC's */
-#define TS_CR 2 /* CR-LF ->'s CR */
-#define TS_SB 3 /* throw away begin's... */
-#define TS_SE 4 /* ...end's (suboption negotiation) */
-#define TS_WILL 5 /* will option negotiation */
-#define TS_WONT 6 /* wont " */
-#define TS_DO 7 /* do " */
-#define TS_DONT 8 /* dont " */
-
-static void doclientstat(void);
-
-void
-telrcv(void)
-{
- int c;
- static int state = TS_DATA;
-
- while (ncc > 0) {
- if ((&ptyobuf[BUFSIZ] - pfrontp) < 2)
- break;
- c = *netip++ & 0377, ncc--;
-#ifdef ENCRYPTION
- if (decrypt_input)
- c = (*decrypt_input)(c);
-#endif /* ENCRYPTION */
- switch (state) {
-
- case TS_CR:
- state = TS_DATA;
- /* Strip off \n or \0 after a \r */
- if ((c == 0) || (c == '\n')) {
- break;
- }
- /* FALLTHROUGH */
-
- case TS_DATA:
- if (c == IAC) {
- state = TS_IAC;
- break;
- }
- /*
- * We now map \r\n ==> \r for pragmatic reasons.
- * Many client implementations send \r\n when
- * the user hits the CarriageReturn key.
- *
- * We USED to map \r\n ==> \n, since \r\n says
- * that we want to be in column 1 of the next
- * printable line, and \n is the standard
- * unix way of saying that (\r is only good
- * if CRMOD is set, which it normally is).
- */
- if ((c == '\r') && his_state_is_wont(TELOPT_BINARY)) {
- int nc = *netip;
-#ifdef ENCRYPTION
- if (decrypt_input)
- nc = (*decrypt_input)(nc & 0xff);
-#endif /* ENCRYPTION */
-#ifdef LINEMODE
- /*
- * If we are operating in linemode,
- * convert to local end-of-line.
- */
- if (linemode && (ncc > 0) && (('\n' == nc) ||
- ((0 == nc) && tty_iscrnl())) ) {
- netip++; ncc--;
- c = '\n';
- } else
-#endif
- {
-#ifdef ENCRYPTION
- if (decrypt_input)
- (void)(*decrypt_input)(-1);
-#endif /* ENCRYPTION */
- state = TS_CR;
- }
- }
- *pfrontp++ = c;
- break;
-
- case TS_IAC:
-gotiac: switch (c) {
-
- /*
- * Send the process on the pty side an
- * interrupt. Do this with a NULL or
- * interrupt char; depending on the tty mode.
- */
- case IP:
- DIAG(TD_OPTIONS,
- printoption("td: recv IAC", c));
- interrupt();
- break;
-
- case BREAK:
- DIAG(TD_OPTIONS,
- printoption("td: recv IAC", c));
- sendbrk();
- break;
-
- /*
- * Are You There?
- */
- case AYT:
- DIAG(TD_OPTIONS,
- printoption("td: recv IAC", c));
- recv_ayt();
- break;
-
- /*
- * Abort Output
- */
- case AO:
- {
- DIAG(TD_OPTIONS,
- printoption("td: recv IAC", c));
- ptyflush(); /* half-hearted */
- init_termbuf();
-
- if (slctab[SLC_AO].sptr &&
- *slctab[SLC_AO].sptr != (cc_t)(_POSIX_VDISABLE)) {
- *pfrontp++ =
- (unsigned char)*slctab[SLC_AO].sptr;
- }
-
- netclear(); /* clear buffer back */
- output_data("%c%c", IAC, DM);
- neturg = nfrontp-1; /* off by one XXX */
- DIAG(TD_OPTIONS,
- printoption("td: send IAC", DM));
- break;
- }
-
- /*
- * Erase Character and
- * Erase Line
- */
- case EC:
- case EL:
- {
- cc_t ch;
-
- DIAG(TD_OPTIONS,
- printoption("td: recv IAC", c));
- ptyflush(); /* half-hearted */
- init_termbuf();
- if (c == EC)
- ch = *slctab[SLC_EC].sptr;
- else
- ch = *slctab[SLC_EL].sptr;
- if (ch != (cc_t)(_POSIX_VDISABLE))
- *pfrontp++ = (unsigned char)ch;
- break;
- }
-
- /*
- * Check for urgent data...
- */
- case DM:
- DIAG(TD_OPTIONS,
- printoption("td: recv IAC", c));
- SYNCHing = stilloob(net);
- settimer(gotDM);
- break;
-
-
- /*
- * Begin option subnegotiation...
- */
- case SB:
- state = TS_SB;
- SB_CLEAR();
- continue;
-
- case WILL:
- state = TS_WILL;
- continue;
-
- case WONT:
- state = TS_WONT;
- continue;
-
- case DO:
- state = TS_DO;
- continue;
-
- case DONT:
- state = TS_DONT;
- continue;
- case EOR:
- if (his_state_is_will(TELOPT_EOR))
- doeof();
- break;
-
- /*
- * Handle RFC 10xx Telnet linemode option additions
- * to command stream (EOF, SUSP, ABORT).
- */
- case xEOF:
- doeof();
- break;
-
- case SUSP:
- sendsusp();
- break;
-
- case ABORT:
- sendbrk();
- break;
-
- case IAC:
- *pfrontp++ = c;
- break;
- }
- state = TS_DATA;
- break;
-
- case TS_SB:
- if (c == IAC) {
- state = TS_SE;
- } else {
- SB_ACCUM(c);
- }
- break;
-
- case TS_SE:
- if (c != SE) {
- if (c != IAC) {
- /*
- * bad form of suboption negotiation.
- * handle it in such a way as to avoid
- * damage to local state. Parse
- * suboption buffer found so far,
- * then treat remaining stream as
- * another command sequence.
- */
-
- /* for DIAGNOSTICS */
- SB_ACCUM(IAC);
- SB_ACCUM(c);
- subpointer -= 2;
-
- SB_TERM();
- suboption();
- state = TS_IAC;
- goto gotiac;
- }
- SB_ACCUM(c);
- state = TS_SB;
- } else {
- /* for DIAGNOSTICS */
- SB_ACCUM(IAC);
- SB_ACCUM(SE);
- subpointer -= 2;
-
- SB_TERM();
- suboption(); /* handle sub-option */
- state = TS_DATA;
- }
- break;
-
- case TS_WILL:
- willoption(c);
- state = TS_DATA;
- continue;
-
- case TS_WONT:
- wontoption(c);
- state = TS_DATA;
- continue;
-
- case TS_DO:
- dooption(c);
- state = TS_DATA;
- continue;
-
- case TS_DONT:
- dontoption(c);
- state = TS_DATA;
- continue;
-
- default:
- syslog(LOG_ERR, "panic state=%d", state);
- printf("telnetd: panic state=%d\n", state);
- exit(1);
- }
- }
-} /* end of telrcv */
-
-/*
- * The will/wont/do/dont state machines are based on Dave Borman's
- * Telnet option processing state machine.
- *
- * These correspond to the following states:
- * my_state = the last negotiated state
- * want_state = what I want the state to go to
- * want_resp = how many requests I have sent
- * All state defaults are negative, and resp defaults to 0.
- *
- * When initiating a request to change state to new_state:
- *
- * if ((want_resp == 0 && new_state == my_state) || want_state == new_state) {
- * do nothing;
- * } else {
- * want_state = new_state;
- * send new_state;
- * want_resp++;
- * }
- *
- * When receiving new_state:
- *
- * if (want_resp) {
- * want_resp--;
- * if (want_resp && (new_state == my_state))
- * want_resp--;
- * }
- * if ((want_resp == 0) && (new_state != want_state)) {
- * if (ok_to_switch_to new_state)
- * want_state = new_state;
- * else
- * want_resp++;
- * send want_state;
- * }
- * my_state = new_state;
- *
- * Note that new_state is implied in these functions by the function itself.
- * will and do imply positive new_state, wont and dont imply negative.
- *
- * Finally, there is one catch. If we send a negative response to a
- * positive request, my_state will be the positive while want_state will
- * remain negative. my_state will revert to negative when the negative
- * acknowlegment arrives from the peer. Thus, my_state generally tells
- * us not only the last negotiated state, but also tells us what the peer
- * wants to be doing as well. It is important to understand this difference
- * as we may wish to be processing data streams based on our desired state
- * (want_state) or based on what the peer thinks the state is (my_state).
- *
- * This all works fine because if the peer sends a positive request, the data
- * that we receive prior to negative acknowlegment will probably be affected
- * by the positive state, and we can process it as such (if we can; if we
- * can't then it really doesn't matter). If it is that important, then the
- * peer probably should be buffering until this option state negotiation
- * is complete.
- *
- */
-void
-send_do(int option, int init)
-{
- if (init) {
- if ((do_dont_resp[option] == 0 && his_state_is_will(option)) ||
- his_want_state_is_will(option))
- return;
- /*
- * Special case for TELOPT_TM: We send a DO, but pretend
- * that we sent a DONT, so that we can send more DOs if
- * we want to.
- */
- if (option == TELOPT_TM)
- set_his_want_state_wont(option);
- else
- set_his_want_state_will(option);
- do_dont_resp[option]++;
- }
- output_data((const char *)doopt, option);
-
- DIAG(TD_OPTIONS, printoption("td: send do", option));
-}
-
-void
-willoption(int option)
-{
- int changeok = 0;
- void (*func)(void) = 0;
-
- /*
- * process input from peer.
- */
-
- DIAG(TD_OPTIONS, printoption("td: recv will", option));
-
- if (do_dont_resp[option]) {
- do_dont_resp[option]--;
- if (do_dont_resp[option] && his_state_is_will(option))
- do_dont_resp[option]--;
- }
- if (do_dont_resp[option] == 0) {
- if (his_want_state_is_wont(option)) {
- switch (option) {
-
- case TELOPT_BINARY:
- init_termbuf();
- tty_binaryin(1);
- set_termbuf();
- changeok++;
- break;
-
- case TELOPT_ECHO:
- /*
- * See comments below for more info.
- */
- not42 = 0; /* looks like a 4.2 system */
- break;
-
- case TELOPT_TM:
-#if defined(LINEMODE) && defined(KLUDGELINEMODE)
- /*
- * This telnetd implementation does not really
- * support timing marks, it just uses them to
- * support the kludge linemode stuff. If we
- * receive a will or wont TM in response to our
- * do TM request that may have been sent to
- * determine kludge linemode support, process
- * it, otherwise TM should get a negative
- * response back.
- */
- /*
- * Handle the linemode kludge stuff.
- * If we are not currently supporting any
- * linemode at all, then we assume that this
- * is the client telling us to use kludge
- * linemode in response to our query. Set the
- * linemode type that is to be supported, note
- * that the client wishes to use linemode, and
- * eat the will TM as though it never arrived.
- */
- if (lmodetype < KLUDGE_LINEMODE) {
- lmodetype = KLUDGE_LINEMODE;
- clientstat(TELOPT_LINEMODE, WILL, 0);
- send_wont(TELOPT_SGA, 1);
- } else if (lmodetype == NO_AUTOKLUDGE) {
- lmodetype = KLUDGE_OK;
- }
-#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
- /*
- * We never respond to a WILL TM, and
- * we leave the state WONT.
- */
- return;
-
- case TELOPT_LFLOW:
- /*
- * If we are going to support flow control
- * option, then don't worry peer that we can't
- * change the flow control characters.
- */
- slctab[SLC_XON].defset.flag &= ~SLC_LEVELBITS;
- slctab[SLC_XON].defset.flag |= SLC_DEFAULT;
- slctab[SLC_XOFF].defset.flag &= ~SLC_LEVELBITS;
- slctab[SLC_XOFF].defset.flag |= SLC_DEFAULT;
- case TELOPT_TTYPE:
- case TELOPT_SGA:
- case TELOPT_NAWS:
- case TELOPT_TSPEED:
- case TELOPT_XDISPLOC:
- case TELOPT_NEW_ENVIRON:
- case TELOPT_OLD_ENVIRON:
- changeok++;
- break;
-
-#ifdef LINEMODE
- case TELOPT_LINEMODE:
-# ifdef KLUDGELINEMODE
- /*
- * Note client's desire to use linemode.
- */
- lmodetype = REAL_LINEMODE;
-# endif /* KLUDGELINEMODE */
- func = doclientstat;
- changeok++;
- break;
-#endif /* LINEMODE */
-
-#ifdef AUTHENTICATION
- case TELOPT_AUTHENTICATION:
- func = auth_request;
- changeok++;
- break;
-#endif
-
-#ifdef ENCRYPTION
- case TELOPT_ENCRYPT:
- func = encrypt_send_support;
- changeok++;
- break;
-#endif /* ENCRYPTION */
-
- default:
- break;
- }
- if (changeok) {
- set_his_want_state_will(option);
- send_do(option, 0);
- } else {
- do_dont_resp[option]++;
- send_dont(option, 0);
- }
- } else {
- /*
- * Option processing that should happen when
- * we receive conformation of a change in
- * state that we had requested.
- */
- switch (option) {
- case TELOPT_ECHO:
- not42 = 0; /* looks like a 4.2 system */
- /*
- * Egads, he responded "WILL ECHO". Turn
- * it off right now!
- */
- send_dont(option, 1);
- /*
- * "WILL ECHO". Kludge upon kludge!
- * A 4.2 client is now echoing user input at
- * the tty. This is probably undesireable and
- * it should be stopped. The client will
- * respond WONT TM to the DO TM that we send to
- * check for kludge linemode. When the WONT TM
- * arrives, linemode will be turned off and a
- * change propogated to the pty. This change
- * will cause us to process the new pty state
- * in localstat(), which will notice that
- * linemode is off and send a WILL ECHO
- * so that we are properly in character mode and
- * all is well.
- */
- break;
-#ifdef LINEMODE
- case TELOPT_LINEMODE:
-# ifdef KLUDGELINEMODE
- /*
- * Note client's desire to use linemode.
- */
- lmodetype = REAL_LINEMODE;
-# endif /* KLUDGELINEMODE */
- func = doclientstat;
- break;
-#endif /* LINEMODE */
-
-#ifdef AUTHENTICATION
- case TELOPT_AUTHENTICATION:
- func = auth_request;
- break;
-#endif
-
-#ifdef ENCRYPTION
- case TELOPT_ENCRYPT:
- func = encrypt_send_support;
- break;
-#endif /* ENCRYPTION */
- case TELOPT_LFLOW:
- func = flowstat;
- break;
- }
- }
- }
- set_his_state_will(option);
- if (func)
- (*func)();
-} /* end of willoption */
-
-void
-send_dont(int option, int init)
-{
- if (init) {
- if ((do_dont_resp[option] == 0 && his_state_is_wont(option)) ||
- his_want_state_is_wont(option))
- return;
- set_his_want_state_wont(option);
- do_dont_resp[option]++;
- }
- output_data((const char *)dont, option);
-
- DIAG(TD_OPTIONS, printoption("td: send dont", option));
-}
-
-void
-wontoption(int option)
-{
- /*
- * Process client input.
- */
-
- DIAG(TD_OPTIONS, printoption("td: recv wont", option));
-
- if (do_dont_resp[option]) {
- do_dont_resp[option]--;
- if (do_dont_resp[option] && his_state_is_wont(option))
- do_dont_resp[option]--;
- }
- if (do_dont_resp[option] == 0) {
- if (his_want_state_is_will(option)) {
- /* it is always ok to change to negative state */
- switch (option) {
- case TELOPT_ECHO:
- not42 = 1; /* doesn't seem to be a 4.2 system */
- break;
-
- case TELOPT_BINARY:
- init_termbuf();
- tty_binaryin(0);
- set_termbuf();
- break;
-
-#ifdef LINEMODE
- case TELOPT_LINEMODE:
-# ifdef KLUDGELINEMODE
- /*
- * If real linemode is supported, then client is
- * asking to turn linemode off.
- */
- if (lmodetype != REAL_LINEMODE)
- break;
- lmodetype = KLUDGE_LINEMODE;
-# endif /* KLUDGELINEMODE */
- clientstat(TELOPT_LINEMODE, WONT, 0);
- break;
-#endif /* LINEMODE */
-
- case TELOPT_TM:
- /*
- * If we get a WONT TM, and had sent a DO TM,
- * don't respond with a DONT TM, just leave it
- * as is. Short circut the state machine to
- * achive this.
- */
- set_his_want_state_wont(TELOPT_TM);
- return;
-
- case TELOPT_LFLOW:
- /*
- * If we are not going to support flow control
- * option, then let peer know that we can't
- * change the flow control characters.
- */
- slctab[SLC_XON].defset.flag &= ~SLC_LEVELBITS;
- slctab[SLC_XON].defset.flag |= SLC_CANTCHANGE;
- slctab[SLC_XOFF].defset.flag &= ~SLC_LEVELBITS;
- slctab[SLC_XOFF].defset.flag |= SLC_CANTCHANGE;
- break;
-
-#ifdef AUTHENTICATION
- case TELOPT_AUTHENTICATION:
- auth_finished(0, AUTH_REJECT);
- break;
-#endif
-
- /*
- * For options that we might spin waiting for
- * sub-negotiation, if the client turns off the
- * option rather than responding to the request,
- * we have to treat it here as if we got a response
- * to the sub-negotiation, (by updating the timers)
- * so that we'll break out of the loop.
- */
- case TELOPT_TTYPE:
- settimer(ttypesubopt);
- break;
-
- case TELOPT_TSPEED:
- settimer(tspeedsubopt);
- break;
-
- case TELOPT_XDISPLOC:
- settimer(xdisplocsubopt);
- break;
-
- case TELOPT_OLD_ENVIRON:
- settimer(oenvironsubopt);
- break;
-
- case TELOPT_NEW_ENVIRON:
- settimer(environsubopt);
- break;
-
- default:
- break;
- }
- set_his_want_state_wont(option);
- if (his_state_is_will(option))
- send_dont(option, 0);
- } else {
- switch (option) {
- case TELOPT_TM:
-#if defined(LINEMODE) && defined(KLUDGELINEMODE)
- if (lmodetype < NO_AUTOKLUDGE) {
- lmodetype = NO_LINEMODE;
- clientstat(TELOPT_LINEMODE, WONT, 0);
- send_will(TELOPT_SGA, 1);
- send_will(TELOPT_ECHO, 1);
- }
-#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
- break;
-
-#ifdef AUTHENTICATION
- case TELOPT_AUTHENTICATION:
- auth_finished(0, AUTH_REJECT);
- break;
-#endif
- default:
- break;
- }
- }
- }
- set_his_state_wont(option);
-
-} /* end of wontoption */
-
-void
-send_will(int option, int init)
-{
- if (init) {
- if ((will_wont_resp[option] == 0 && my_state_is_will(option))||
- my_want_state_is_will(option))
- return;
- set_my_want_state_will(option);
- will_wont_resp[option]++;
- }
- output_data((const char *)will, option);
-
- DIAG(TD_OPTIONS, printoption("td: send will", option));
-}
-
-#if !defined(LINEMODE) || !defined(KLUDGELINEMODE)
-/*
- * When we get a DONT SGA, we will try once to turn it
- * back on. If the other side responds DONT SGA, we
- * leave it at that. This is so that when we talk to
- * clients that understand KLUDGELINEMODE but not LINEMODE,
- * we'll keep them in char-at-a-time mode.
- */
-int turn_on_sga = 0;
-#endif
-
-void
-dooption(int option)
-{
- int changeok = 0;
-
- /*
- * Process client input.
- */
-
- DIAG(TD_OPTIONS, printoption("td: recv do", option));
-
- if (will_wont_resp[option]) {
- will_wont_resp[option]--;
- if (will_wont_resp[option] && my_state_is_will(option))
- will_wont_resp[option]--;
- }
- if ((will_wont_resp[option] == 0) && (my_want_state_is_wont(option))) {
- switch (option) {
- case TELOPT_ECHO:
-#ifdef LINEMODE
-# ifdef KLUDGELINEMODE
- if (lmodetype == NO_LINEMODE)
-# else
- if (his_state_is_wont(TELOPT_LINEMODE))
-# endif
-#endif
- {
- init_termbuf();
- tty_setecho(1);
- set_termbuf();
- }
- changeok++;
- break;
-
- case TELOPT_BINARY:
- init_termbuf();
- tty_binaryout(1);
- set_termbuf();
- changeok++;
- break;
-
- case TELOPT_SGA:
-#if defined(LINEMODE) && defined(KLUDGELINEMODE)
- /*
- * If kludge linemode is in use, then we must
- * process an incoming do SGA for linemode
- * purposes.
- */
- if (lmodetype == KLUDGE_LINEMODE) {
- /*
- * Receipt of "do SGA" in kludge
- * linemode is the peer asking us to
- * turn off linemode. Make note of
- * the request.
- */
- clientstat(TELOPT_LINEMODE, WONT, 0);
- /*
- * If linemode did not get turned off
- * then don't tell peer that we did.
- * Breaking here forces a wont SGA to
- * be returned.
- */
- if (linemode)
- break;
- }
-#else
- turn_on_sga = 0;
-#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
- changeok++;
- break;
-
- case TELOPT_STATUS:
- changeok++;
- break;
-
- case TELOPT_TM:
- /*
- * Special case for TM. We send a WILL, but
- * pretend we sent a WONT.
- */
- send_will(option, 0);
- set_my_want_state_wont(option);
- set_my_state_wont(option);
- return;
-
- case TELOPT_LOGOUT:
- /*
- * When we get a LOGOUT option, respond
- * with a WILL LOGOUT, make sure that
- * it gets written out to the network,
- * and then just go away...
- */
- set_my_want_state_will(TELOPT_LOGOUT);
- send_will(TELOPT_LOGOUT, 0);
- set_my_state_will(TELOPT_LOGOUT);
- (void)netflush();
- cleanup(0);
- /* NOT REACHED */
- break;
-
-#ifdef ENCRYPTION
- case TELOPT_ENCRYPT:
- changeok++;
- break;
-#endif /* ENCRYPTION */
- case TELOPT_LINEMODE:
- case TELOPT_TTYPE:
- case TELOPT_NAWS:
- case TELOPT_TSPEED:
- case TELOPT_LFLOW:
- case TELOPT_XDISPLOC:
-#ifdef TELOPT_ENVIRON
- case TELOPT_NEW_ENVIRON:
-#endif
- case TELOPT_OLD_ENVIRON:
- default:
- break;
- }
- if (changeok) {
- set_my_want_state_will(option);
- send_will(option, 0);
- } else {
- will_wont_resp[option]++;
- send_wont(option, 0);
- }
- }
- set_my_state_will(option);
-
-} /* end of dooption */
-
-void
-send_wont(int option, int init)
-{
- if (init) {
- if ((will_wont_resp[option] == 0 && my_state_is_wont(option)) ||
- my_want_state_is_wont(option))
- return;
- set_my_want_state_wont(option);
- will_wont_resp[option]++;
- }
- output_data((const char *)wont, option);
-
- DIAG(TD_OPTIONS, printoption("td: send wont", option));
-}
-
-void
-dontoption(int option)
-{
- /*
- * Process client input.
- */
-
-
- DIAG(TD_OPTIONS, printoption("td: recv dont", option));
-
- if (will_wont_resp[option]) {
- will_wont_resp[option]--;
- if (will_wont_resp[option] && my_state_is_wont(option))
- will_wont_resp[option]--;
- }
- if ((will_wont_resp[option] == 0) && (my_want_state_is_will(option))) {
- switch (option) {
- case TELOPT_BINARY:
- init_termbuf();
- tty_binaryout(0);
- set_termbuf();
- break;
-
- case TELOPT_ECHO: /* we should stop echoing */
-#ifdef LINEMODE
-# ifdef KLUDGELINEMODE
- if ((lmodetype != REAL_LINEMODE) &&
- (lmodetype != KLUDGE_LINEMODE))
-# else
- if (his_state_is_wont(TELOPT_LINEMODE))
-# endif
-#endif
- {
- init_termbuf();
- tty_setecho(0);
- set_termbuf();
- }
- break;
-
- case TELOPT_SGA:
-#if defined(LINEMODE) && defined(KLUDGELINEMODE)
- /*
- * If kludge linemode is in use, then we
- * must process an incoming do SGA for
- * linemode purposes.
- */
- if ((lmodetype == KLUDGE_LINEMODE) ||
- (lmodetype == KLUDGE_OK)) {
- /*
- * The client is asking us to turn
- * linemode on.
- */
- lmodetype = KLUDGE_LINEMODE;
- clientstat(TELOPT_LINEMODE, WILL, 0);
- /*
- * If we did not turn line mode on,
- * then what do we say? Will SGA?
- * This violates design of telnet.
- * Gross. Very Gross.
- */
- }
- break;
-#else
- set_my_want_state_wont(option);
- if (my_state_is_will(option))
- send_wont(option, 0);
- set_my_state_wont(option);
- if (turn_on_sga ^= 1)
- send_will(option, 1);
- return;
-#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
-
- default:
- break;
- }
-
- set_my_want_state_wont(option);
- if (my_state_is_will(option))
- send_wont(option, 0);
- }
- set_my_state_wont(option);
-
-} /* end of dontoption */
-
-#ifdef ENV_HACK
-int env_ovar = -1;
-int env_ovalue = -1;
-#else /* ENV_HACK */
-# define env_ovar OLD_ENV_VAR
-# define env_ovalue OLD_ENV_VALUE
-#endif /* ENV_HACK */
-
-/*
- * suboption()
- *
- * Look at the sub-option buffer, and try to be helpful to the other
- * side.
- *
- * Currently we recognize:
- *
- * Terminal type is
- * Linemode
- * Window size
- * Terminal speed
- */
-void
-suboption(void)
-{
- int subchar;
-
- DIAG(TD_OPTIONS, {netflush(); printsub('<', subpointer, SB_LEN()+2);});
-
- subchar = SB_GET();
- switch (subchar) {
- case TELOPT_TSPEED: {
- int xspeed, rspeed;
-
- if (his_state_is_wont(TELOPT_TSPEED)) /* Ignore if option disabled */
- break;
-
- settimer(tspeedsubopt);
-
- if (SB_EOF() || SB_GET() != TELQUAL_IS)
- return;
-
- xspeed = atoi((char *)subpointer);
-
- while (SB_GET() != ',' && !SB_EOF());
- if (SB_EOF())
- return;
-
- rspeed = atoi((char *)subpointer);
- clientstat(TELOPT_TSPEED, xspeed, rspeed);
-
- break;
-
- } /* end of case TELOPT_TSPEED */
-
- case TELOPT_TTYPE: { /* Yaaaay! */
- static char terminalname[41];
-
- if (his_state_is_wont(TELOPT_TTYPE)) /* Ignore if option disabled */
- break;
- settimer(ttypesubopt);
-
- if (SB_EOF() || SB_GET() != TELQUAL_IS) {
- return; /* ??? XXX but, this is the most robust */
- }
-
- terminaltype = terminalname;
-
- while ((terminaltype < (terminalname + sizeof terminalname-1)) &&
- !SB_EOF()) {
- int c;
-
- c = SB_GET();
- if (isupper(c)) {
- c = tolower(c);
- }
- *terminaltype++ = c; /* accumulate name */
- }
- *terminaltype = 0;
- terminaltype = terminalname;
- break;
- } /* end of case TELOPT_TTYPE */
-
- case TELOPT_NAWS: {
- int xwinsize, ywinsize;
-
- if (his_state_is_wont(TELOPT_NAWS)) /* Ignore if option disabled */
- break;
-
- if (SB_EOF())
- return;
- xwinsize = SB_GET() << 8;
- if (SB_EOF())
- return;
- xwinsize |= SB_GET();
- if (SB_EOF())
- return;
- ywinsize = SB_GET() << 8;
- if (SB_EOF())
- return;
- ywinsize |= SB_GET();
- clientstat(TELOPT_NAWS, xwinsize, ywinsize);
-
- break;
-
- } /* end of case TELOPT_NAWS */
-
-#ifdef LINEMODE
- case TELOPT_LINEMODE: {
- int request;
-
- if (his_state_is_wont(TELOPT_LINEMODE)) /* Ignore if option disabled */
- break;
- /*
- * Process linemode suboptions.
- */
- if (SB_EOF())
- break; /* garbage was sent */
- request = SB_GET(); /* get will/wont */
-
- if (SB_EOF())
- break; /* another garbage check */
-
- if (request == LM_SLC) { /* SLC is not preceeded by WILL or WONT */
- /*
- * Process suboption buffer of slc's
- */
- start_slc(1);
- do_opt_slc(subpointer, subend - subpointer);
- (void) end_slc(0);
- break;
- } else if (request == LM_MODE) {
- if (SB_EOF())
- return;
- useeditmode = SB_GET(); /* get mode flag */
- clientstat(LM_MODE, 0, 0);
- break;
- }
-
- if (SB_EOF())
- break;
- switch (SB_GET()) { /* what suboption? */
- case LM_FORWARDMASK:
- /*
- * According to spec, only server can send request for
- * forwardmask, and client can only return a positive response.
- * So don't worry about it.
- */
-
- default:
- break;
- }
- break;
- } /* end of case TELOPT_LINEMODE */
-#endif
- case TELOPT_STATUS: {
- int mode;
-
- if (SB_EOF())
- break;
- mode = SB_GET();
- switch (mode) {
- case TELQUAL_SEND:
- if (my_state_is_will(TELOPT_STATUS))
- send_status();
- break;
-
- case TELQUAL_IS:
- break;
-
- default:
- break;
- }
- break;
- } /* end of case TELOPT_STATUS */
-
- case TELOPT_XDISPLOC: {
- if (SB_EOF() || SB_GET() != TELQUAL_IS)
- return;
- settimer(xdisplocsubopt);
- subpointer[SB_LEN()] = '\0';
- (void)setenv("DISPLAY", (char *)subpointer, 1);
- break;
- } /* end of case TELOPT_XDISPLOC */
-
-#ifdef TELOPT_NEW_ENVIRON
- case TELOPT_NEW_ENVIRON:
-#endif
- case TELOPT_OLD_ENVIRON: {
- int c;
- char *cp, *varp, *valp;
-
- if (SB_EOF())
- return;
- c = SB_GET();
- if (c == TELQUAL_IS) {
- if (subchar == TELOPT_OLD_ENVIRON)
- settimer(oenvironsubopt);
- else
- settimer(environsubopt);
- } else if (c != TELQUAL_INFO) {
- return;
- }
-
-#ifdef TELOPT_NEW_ENVIRON
- if (subchar == TELOPT_NEW_ENVIRON) {
- while (!SB_EOF()) {
- c = SB_GET();
- if ((c == NEW_ENV_VAR) || (c == ENV_USERVAR))
- break;
- }
- } else
-#endif
- {
-#ifdef ENV_HACK
- /*
- * We only want to do this if we haven't already decided
- * whether or not the other side has its VALUE and VAR
- * reversed.
- */
- if (env_ovar < 0) {
- int last = -1; /* invalid value */
- int empty = 0;
- int got_var = 0, got_value = 0, got_uservar = 0;
-
- /*
- * The other side might have its VALUE and VAR values
- * reversed. To be interoperable, we need to determine
- * which way it is. If the first recognized character
- * is a VAR or VALUE, then that will tell us what
- * type of client it is. If the fist recognized
- * character is a USERVAR, then we continue scanning
- * the suboption looking for two consecutive
- * VAR or VALUE fields. We should not get two
- * consecutive VALUE fields, so finding two
- * consecutive VALUE or VAR fields will tell us
- * what the client is.
- */
- SB_SAVE();
- while (!SB_EOF()) {
- c = SB_GET();
- switch(c) {
- case OLD_ENV_VAR:
- if (last < 0 || last == OLD_ENV_VAR
- || (empty && (last == OLD_ENV_VALUE)))
- goto env_ovar_ok;
- got_var++;
- last = OLD_ENV_VAR;
- break;
- case OLD_ENV_VALUE:
- if (last < 0 || last == OLD_ENV_VALUE
- || (empty && (last == OLD_ENV_VAR)))
- goto env_ovar_wrong;
- got_value++;
- last = OLD_ENV_VALUE;
- break;
- case ENV_USERVAR:
- /* count strings of USERVAR as one */
- if (last != ENV_USERVAR)
- got_uservar++;
- if (empty) {
- if (last == OLD_ENV_VALUE)
- goto env_ovar_ok;
- if (last == OLD_ENV_VAR)
- goto env_ovar_wrong;
- }
- last = ENV_USERVAR;
- break;
- case ENV_ESC:
- if (!SB_EOF())
- c = SB_GET();
- /* FALLTHROUGH */
- default:
- empty = 0;
- continue;
- }
- empty = 1;
- }
- if (empty) {
- if (last == OLD_ENV_VALUE)
- goto env_ovar_ok;
- if (last == OLD_ENV_VAR)
- goto env_ovar_wrong;
- }
- /*
- * Ok, the first thing was a USERVAR, and there
- * are not two consecutive VAR or VALUE commands,
- * and none of the VAR or VALUE commands are empty.
- * If the client has sent us a well-formed option,
- * then the number of VALUEs received should always
- * be less than or equal to the number of VARs and
- * USERVARs received.
- *
- * If we got exactly as many VALUEs as VARs and
- * USERVARs, the client has the same definitions.
- *
- * If we got exactly as many VARs as VALUEs and
- * USERVARS, the client has reversed definitions.
- */
- if (got_uservar + got_var == got_value) {
- env_ovar_ok:
- env_ovar = OLD_ENV_VAR;
- env_ovalue = OLD_ENV_VALUE;
- } else if (got_uservar + got_value == got_var) {
- env_ovar_wrong:
- env_ovar = OLD_ENV_VALUE;
- env_ovalue = OLD_ENV_VAR;
- DIAG(TD_OPTIONS,
- output_data("ENVIRON VALUE and VAR are reversed!\r\n"));
-
- }
- }
- SB_RESTORE();
-#endif
-
- while (!SB_EOF()) {
- c = SB_GET();
- if ((c == env_ovar) || (c == ENV_USERVAR))
- break;
- }
- }
-
- if (SB_EOF())
- return;
-
- cp = varp = (char *)subpointer;
- valp = 0;
-
- while (!SB_EOF()) {
- c = SB_GET();
- if (subchar == TELOPT_OLD_ENVIRON) {
- if (c == env_ovar)
- c = NEW_ENV_VAR;
- else if (c == env_ovalue)
- c = NEW_ENV_VALUE;
- }
- switch (c) {
-
- case NEW_ENV_VALUE:
- *cp = '\0';
- cp = valp = (char *)subpointer;
- break;
-
- case NEW_ENV_VAR:
- case ENV_USERVAR:
- *cp = '\0';
- if (valp)
- (void)setenv(varp, valp, 1);
- else
- unsetenv(varp);
- cp = varp = (char *)subpointer;
- valp = 0;
- break;
-
- case ENV_ESC:
- if (SB_EOF())
- break;
- c = SB_GET();
- /* FALLTHROUGH */
- default:
- *cp++ = c;
- break;
- }
- }
- *cp = '\0';
- if (valp)
- (void)setenv(varp, valp, 1);
- else
- unsetenv(varp);
- break;
- } /* end of case TELOPT_NEW_ENVIRON */
-#ifdef AUTHENTICATION
- case TELOPT_AUTHENTICATION:
- if (SB_EOF())
- break;
- switch(SB_GET()) {
- case TELQUAL_SEND:
- case TELQUAL_REPLY:
- /*
- * These are sent by us and cannot be sent by
- * the client.
- */
- break;
- case TELQUAL_IS:
- auth_is(subpointer, SB_LEN());
- break;
- case TELQUAL_NAME:
- auth_name(subpointer, SB_LEN());
- break;
- }
- break;
-#endif
-#ifdef ENCRYPTION
- case TELOPT_ENCRYPT:
- if (SB_EOF())
- break;
- switch(SB_GET()) {
- case ENCRYPT_SUPPORT:
- encrypt_support(subpointer, SB_LEN());
- break;
- case ENCRYPT_IS:
- encrypt_is(subpointer, SB_LEN());
- break;
- case ENCRYPT_REPLY:
- encrypt_reply(subpointer, SB_LEN());
- break;
- case ENCRYPT_START:
- encrypt_start(subpointer, SB_LEN());
- break;
- case ENCRYPT_END:
- encrypt_end();
- break;
- case ENCRYPT_REQSTART:
- encrypt_request_start(subpointer, SB_LEN());
- break;
- case ENCRYPT_REQEND:
- /*
- * We can always send an REQEND so that we cannot
- * get stuck encrypting. We should only get this
- * if we have been able to get in the correct mode
- * anyhow.
- */
- encrypt_request_end();
- break;
- case ENCRYPT_ENC_KEYID:
- encrypt_enc_keyid(subpointer, SB_LEN());
- break;
- case ENCRYPT_DEC_KEYID:
- encrypt_dec_keyid(subpointer, SB_LEN());
- break;
- default:
- break;
- }
- break;
-#endif /* ENCRYPTION */
-
- default:
- break;
- } /* end of switch */
-
-} /* end of suboption */
-
-static void
-doclientstat(void)
-{
- clientstat(TELOPT_LINEMODE, WILL, 0);
-}
-
-#define ADD(c) *ncp++ = c
-#define ADD_DATA(c) { *ncp++ = c; if (c == SE || c == IAC) *ncp++ = c; }
-void
-send_status(void)
-{
- unsigned char statusbuf[256];
- unsigned char *ncp;
- unsigned char i;
-
- ncp = statusbuf;
-
- netflush(); /* get rid of anything waiting to go out */
-
- ADD(IAC);
- ADD(SB);
- ADD(TELOPT_STATUS);
- ADD(TELQUAL_IS);
-
- /*
- * We check the want_state rather than the current state,
- * because if we received a DO/WILL for an option that we
- * don't support, and the other side didn't send a DONT/WONT
- * in response to our WONT/DONT, then the "state" will be
- * WILL/DO, and the "want_state" will be WONT/DONT. We
- * need to go by the latter.
- */
- for (i = 0; i < (unsigned char)NTELOPTS; i++) {
- if (my_want_state_is_will(i)) {
- ADD(WILL);
- ADD_DATA(i);
- if (i == IAC)
- ADD(IAC);
- }
- if (his_want_state_is_will(i)) {
- ADD(DO);
- ADD_DATA(i);
- if (i == IAC)
- ADD(IAC);
- }
- }
-
- if (his_want_state_is_will(TELOPT_LFLOW)) {
- ADD(SB);
- ADD(TELOPT_LFLOW);
- if (flowmode) {
- ADD(LFLOW_ON);
- } else {
- ADD(LFLOW_OFF);
- }
- ADD(SE);
-
- if (restartany >= 0) {
- ADD(SB);
- ADD(TELOPT_LFLOW);
- if (restartany) {
- ADD(LFLOW_RESTART_ANY);
- } else {
- ADD(LFLOW_RESTART_XON);
- }
- ADD(SE);
- }
- }
-
-#ifdef LINEMODE
- if (his_want_state_is_will(TELOPT_LINEMODE)) {
- unsigned char *cp, *cpe;
- int len;
-
- ADD(SB);
- ADD(TELOPT_LINEMODE);
- ADD(LM_MODE);
- ADD_DATA(editmode);
- ADD(SE);
-
- ADD(SB);
- ADD(TELOPT_LINEMODE);
- ADD(LM_SLC);
- start_slc(0);
- send_slc();
- len = end_slc(&cp);
- for (cpe = cp + len; cp < cpe; cp++)
- ADD_DATA(*cp);
- ADD(SE);
- }
-#endif /* LINEMODE */
-
- ADD(IAC);
- ADD(SE);
-
- output_datalen(statusbuf, ncp - statusbuf);
- netflush(); /* Send it on its way */
-
- DIAG(TD_OPTIONS,
- {printsub('>', statusbuf, ncp - statusbuf); netflush();});
-}
-
-/*
- * This function appends data to nfrontp and advances nfrontp.
- * Returns the number of characters written altogether (the
- * buffer may have been flushed in the process).
- */
-
-int
-output_data(const char *format, ...)
-{
- va_list args;
- int len;
- char *buf;
-
- va_start(args, format);
- if ((len = vasprintf(&buf, format, args)) == -1)
- return -1;
- output_datalen(buf, len);
- va_end(args);
- free(buf);
- return (len);
-}
-
-void
-output_datalen(const char *buf, int len)
-{
- int remaining, copied;
-
- remaining = BUFSIZ - (nfrontp - netobuf);
- while (len > 0) {
- /* Free up enough space if the room is too low*/
- if ((len > BUFSIZ ? BUFSIZ : len) > remaining) {
- netflush();
- remaining = BUFSIZ - (nfrontp - netobuf);
- }
-
- /* Copy out as much as will fit */
- copied = remaining > len ? len : remaining;
- memmove(nfrontp, buf, copied);
- nfrontp += copied;
- len -= copied;
- remaining -= copied;
- buf += copied;
- }
- return;
-}
diff --git a/contrib/telnet/telnetd/sys_term.c b/contrib/telnet/telnetd/sys_term.c
deleted file mode 100644
index 151c5b45215d..000000000000
--- a/contrib/telnet/telnetd/sys_term.c
+++ /dev/null
@@ -1,1339 +0,0 @@
- /*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)sys_term.c 8.4+1 (Berkeley) 5/30/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/tty.h>
-#include <libutil.h>
-#include <stdlib.h>
-#include <utmp.h>
-
-#include "telnetd.h"
-#include "pathnames.h"
-
-#ifdef AUTHENTICATION
-#include <libtelnet/auth.h>
-#endif
-
-int cleanopen(char *);
-void scrub_env(void);
-
-struct utmp wtmp;
-
-#ifdef _PATH_WTMP
-char wtmpf[] = _PATH_WTMP;
-#else
-char wtmpf[] = "/var/log/wtmp";
-#endif
-#ifdef _PATH_UTMP
-char utmpf[] = _PATH_UTMP;
-#else
-char utmpf[] = "/var/run/utmp";
-#endif
-
-char *envinit[3];
-extern char **environ;
-
-#define SCPYN(a, b) (void) strncpy(a, b, sizeof(a))
-#define SCMPN(a, b) strncmp(a, b, sizeof(a))
-
-#ifdef t_erase
-#undef t_erase
-#undef t_kill
-#undef t_intrc
-#undef t_quitc
-#undef t_startc
-#undef t_stopc
-#undef t_eofc
-#undef t_brkc
-#undef t_suspc
-#undef t_dsuspc
-#undef t_rprntc
-#undef t_flushc
-#undef t_werasc
-#undef t_lnextc
-#endif
-
-#ifndef USE_TERMIO
-struct termbuf {
- struct sgttyb sg;
- struct tchars tc;
- struct ltchars ltc;
- int state;
- int lflags;
-} termbuf, termbuf2;
-# define cfsetospeed(tp, val) (tp)->sg.sg_ospeed = (val)
-# define cfsetispeed(tp, val) (tp)->sg.sg_ispeed = (val)
-# define cfgetospeed(tp) (tp)->sg.sg_ospeed
-# define cfgetispeed(tp) (tp)->sg.sg_ispeed
-#else /* USE_TERMIO */
-# ifndef TCSANOW
-# ifdef TCSETS
-# define TCSANOW TCSETS
-# define TCSADRAIN TCSETSW
-# define tcgetattr(f, t) ioctl(f, TCGETS, (char *)t)
-# else
-# ifdef TCSETA
-# define TCSANOW TCSETA
-# define TCSADRAIN TCSETAW
-# define tcgetattr(f, t) ioctl(f, TCGETA, (char *)t)
-# else
-# define TCSANOW TIOCSETA
-# define TCSADRAIN TIOCSETAW
-# define tcgetattr(f, t) ioctl(f, TIOCGETA, (char *)t)
-# endif
-# endif
-# define tcsetattr(f, a, t) ioctl(f, a, t)
-# define cfsetospeed(tp, val) (tp)->c_cflag &= ~CBAUD; \
- (tp)->c_cflag |= (val)
-# define cfgetospeed(tp) ((tp)->c_cflag & CBAUD)
-# ifdef CIBAUD
-# define cfsetispeed(tp, val) (tp)->c_cflag &= ~CIBAUD; \
- (tp)->c_cflag |= ((val)<<IBSHIFT)
-# define cfgetispeed(tp) (((tp)->c_cflag & CIBAUD)>>IBSHIFT)
-# else
-# define cfsetispeed(tp, val) (tp)->c_cflag &= ~CBAUD; \
- (tp)->c_cflag |= (val)
-# define cfgetispeed(tp) ((tp)->c_cflag & CBAUD)
-# endif
-# endif /* TCSANOW */
-struct termios termbuf, termbuf2; /* pty control structure */
-#endif /* USE_TERMIO */
-
-#include <sys/types.h>
-#include <libutil.h>
-
-int cleanopen(char *);
-void scrub_env(void);
-static char **addarg(char **, const char *);
-
-/*
- * init_termbuf()
- * copy_termbuf(cp)
- * set_termbuf()
- *
- * These three routines are used to get and set the "termbuf" structure
- * to and from the kernel. init_termbuf() gets the current settings.
- * copy_termbuf() hands in a new "termbuf" to write to the kernel, and
- * set_termbuf() writes the structure into the kernel.
- */
-
-void
-init_termbuf(void)
-{
-#ifndef USE_TERMIO
- (void) ioctl(pty, TIOCGETP, (char *)&termbuf.sg);
- (void) ioctl(pty, TIOCGETC, (char *)&termbuf.tc);
- (void) ioctl(pty, TIOCGLTC, (char *)&termbuf.ltc);
-# ifdef TIOCGSTATE
- (void) ioctl(pty, TIOCGSTATE, (char *)&termbuf.state);
-# endif
-#else
- (void) tcgetattr(pty, &termbuf);
-#endif
- termbuf2 = termbuf;
-}
-
-#if defined(LINEMODE) && defined(TIOCPKT_IOCTL)
-void
-copy_termbuf(char *cp, size_t len)
-{
- if (len > sizeof(termbuf))
- len = sizeof(termbuf);
- memmove((char *)&termbuf, cp, len);
- termbuf2 = termbuf;
-}
-#endif /* defined(LINEMODE) && defined(TIOCPKT_IOCTL) */
-
-void
-set_termbuf(void)
-{
- /*
- * Only make the necessary changes.
- */
-#ifndef USE_TERMIO
- if (memcmp((char *)&termbuf.sg, (char *)&termbuf2.sg,
- sizeof(termbuf.sg)))
- (void) ioctl(pty, TIOCSETN, (char *)&termbuf.sg);
- if (memcmp((char *)&termbuf.tc, (char *)&termbuf2.tc,
- sizeof(termbuf.tc)))
- (void) ioctl(pty, TIOCSETC, (char *)&termbuf.tc);
- if (memcmp((char *)&termbuf.ltc, (char *)&termbuf2.ltc,
- sizeof(termbuf.ltc)))
- (void) ioctl(pty, TIOCSLTC, (char *)&termbuf.ltc);
- if (termbuf.lflags != termbuf2.lflags)
- (void) ioctl(pty, TIOCLSET, (char *)&termbuf.lflags);
-#else /* USE_TERMIO */
- if (memcmp((char *)&termbuf, (char *)&termbuf2, sizeof(termbuf)))
- (void) tcsetattr(pty, TCSANOW, &termbuf);
-#endif /* USE_TERMIO */
-}
-
-
-/*
- * spcset(func, valp, valpp)
- *
- * This function takes various special characters (func), and
- * sets *valp to the current value of that character, and
- * *valpp to point to where in the "termbuf" structure that
- * value is kept.
- *
- * It returns the SLC_ level of support for this function.
- */
-
-#ifndef USE_TERMIO
-int
-spcset(int func, cc_t *valp, cc_t **valpp)
-{
- switch(func) {
- case SLC_EOF:
- *valp = termbuf.tc.t_eofc;
- *valpp = (cc_t *)&termbuf.tc.t_eofc;
- return(SLC_VARIABLE);
- case SLC_EC:
- *valp = termbuf.sg.sg_erase;
- *valpp = (cc_t *)&termbuf.sg.sg_erase;
- return(SLC_VARIABLE);
- case SLC_EL:
- *valp = termbuf.sg.sg_kill;
- *valpp = (cc_t *)&termbuf.sg.sg_kill;
- return(SLC_VARIABLE);
- case SLC_IP:
- *valp = termbuf.tc.t_intrc;
- *valpp = (cc_t *)&termbuf.tc.t_intrc;
- return(SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT);
- case SLC_ABORT:
- *valp = termbuf.tc.t_quitc;
- *valpp = (cc_t *)&termbuf.tc.t_quitc;
- return(SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT);
- case SLC_XON:
- *valp = termbuf.tc.t_startc;
- *valpp = (cc_t *)&termbuf.tc.t_startc;
- return(SLC_VARIABLE);
- case SLC_XOFF:
- *valp = termbuf.tc.t_stopc;
- *valpp = (cc_t *)&termbuf.tc.t_stopc;
- return(SLC_VARIABLE);
- case SLC_AO:
- *valp = termbuf.ltc.t_flushc;
- *valpp = (cc_t *)&termbuf.ltc.t_flushc;
- return(SLC_VARIABLE);
- case SLC_SUSP:
- *valp = termbuf.ltc.t_suspc;
- *valpp = (cc_t *)&termbuf.ltc.t_suspc;
- return(SLC_VARIABLE);
- case SLC_EW:
- *valp = termbuf.ltc.t_werasc;
- *valpp = (cc_t *)&termbuf.ltc.t_werasc;
- return(SLC_VARIABLE);
- case SLC_RP:
- *valp = termbuf.ltc.t_rprntc;
- *valpp = (cc_t *)&termbuf.ltc.t_rprntc;
- return(SLC_VARIABLE);
- case SLC_LNEXT:
- *valp = termbuf.ltc.t_lnextc;
- *valpp = (cc_t *)&termbuf.ltc.t_lnextc;
- return(SLC_VARIABLE);
- case SLC_FORW1:
- *valp = termbuf.tc.t_brkc;
- *valpp = (cc_t *)&termbuf.ltc.t_lnextc;
- return(SLC_VARIABLE);
- case SLC_BRK:
- case SLC_SYNCH:
- case SLC_AYT:
- case SLC_EOR:
- *valp = (cc_t)0;
- *valpp = (cc_t *)0;
- return(SLC_DEFAULT);
- default:
- *valp = (cc_t)0;
- *valpp = (cc_t *)0;
- return(SLC_NOSUPPORT);
- }
-}
-
-#else /* USE_TERMIO */
-
-
-#define setval(a, b) *valp = termbuf.c_cc[a]; \
- *valpp = &termbuf.c_cc[a]; \
- return(b);
-#define defval(a) *valp = ((cc_t)a); *valpp = (cc_t *)0; return(SLC_DEFAULT);
-
-int
-spcset(int func, cc_t *valp, cc_t **valpp)
-{
- switch(func) {
- case SLC_EOF:
- setval(VEOF, SLC_VARIABLE);
- case SLC_EC:
- setval(VERASE, SLC_VARIABLE);
- case SLC_EL:
- setval(VKILL, SLC_VARIABLE);
- case SLC_IP:
- setval(VINTR, SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT);
- case SLC_ABORT:
- setval(VQUIT, SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT);
- case SLC_XON:
-#ifdef VSTART
- setval(VSTART, SLC_VARIABLE);
-#else
- defval(0x13);
-#endif
- case SLC_XOFF:
-#ifdef VSTOP
- setval(VSTOP, SLC_VARIABLE);
-#else
- defval(0x11);
-#endif
- case SLC_EW:
-#ifdef VWERASE
- setval(VWERASE, SLC_VARIABLE);
-#else
- defval(0);
-#endif
- case SLC_RP:
-#ifdef VREPRINT
- setval(VREPRINT, SLC_VARIABLE);
-#else
- defval(0);
-#endif
- case SLC_LNEXT:
-#ifdef VLNEXT
- setval(VLNEXT, SLC_VARIABLE);
-#else
- defval(0);
-#endif
- case SLC_AO:
-#if !defined(VDISCARD) && defined(VFLUSHO)
-# define VDISCARD VFLUSHO
-#endif
-#ifdef VDISCARD
- setval(VDISCARD, SLC_VARIABLE|SLC_FLUSHOUT);
-#else
- defval(0);
-#endif
- case SLC_SUSP:
-#ifdef VSUSP
- setval(VSUSP, SLC_VARIABLE|SLC_FLUSHIN);
-#else
- defval(0);
-#endif
-#ifdef VEOL
- case SLC_FORW1:
- setval(VEOL, SLC_VARIABLE);
-#endif
-#ifdef VEOL2
- case SLC_FORW2:
- setval(VEOL2, SLC_VARIABLE);
-#endif
- case SLC_AYT:
-#ifdef VSTATUS
- setval(VSTATUS, SLC_VARIABLE);
-#else
- defval(0);
-#endif
-
- case SLC_BRK:
- case SLC_SYNCH:
- case SLC_EOR:
- defval(0);
-
- default:
- *valp = 0;
- *valpp = 0;
- return(SLC_NOSUPPORT);
- }
-}
-#endif /* USE_TERMIO */
-
-/*
- * getpty()
- *
- * Allocate a pty. As a side effect, the external character
- * array "line" contains the name of the slave side.
- *
- * Returns the file descriptor of the opened pty.
- */
-char alpha[] = "0123456789abcdefghijklmnopqrstuv";
-char line[16];
-
-int
-getpty(int *ptynum __unused)
-{
- int p;
- const char *cp;
- char *p1, *p2;
- int i;
-
- (void) strcpy(line, _PATH_DEV);
- (void) strcat(line, "ptyXX");
- p1 = &line[8];
- p2 = &line[9];
-
- for (cp = "pqrsPQRS"; *cp; cp++) {
- struct stat stb;
-
- *p1 = *cp;
- *p2 = '0';
- /*
- * This stat() check is just to keep us from
- * looping through all 256 combinations if there
- * aren't that many ptys available.
- */
- if (stat(line, &stb) < 0)
- break;
- for (i = 0; i < 32; i++) {
- *p2 = alpha[i];
- p = open(line, 2);
- if (p > 0) {
- line[5] = 't';
- chown(line, 0, 0);
- chmod(line, 0600);
- return(p);
- }
- }
- }
- return(-1);
-}
-
-#ifdef LINEMODE
-/*
- * tty_flowmode() Find out if flow control is enabled or disabled.
- * tty_linemode() Find out if linemode (external processing) is enabled.
- * tty_setlinemod(on) Turn on/off linemode.
- * tty_isecho() Find out if echoing is turned on.
- * tty_setecho(on) Enable/disable character echoing.
- * tty_israw() Find out if terminal is in RAW mode.
- * tty_binaryin(on) Turn on/off BINARY on input.
- * tty_binaryout(on) Turn on/off BINARY on output.
- * tty_isediting() Find out if line editing is enabled.
- * tty_istrapsig() Find out if signal trapping is enabled.
- * tty_setedit(on) Turn on/off line editing.
- * tty_setsig(on) Turn on/off signal trapping.
- * tty_issofttab() Find out if tab expansion is enabled.
- * tty_setsofttab(on) Turn on/off soft tab expansion.
- * tty_islitecho() Find out if typed control chars are echoed literally
- * tty_setlitecho() Turn on/off literal echo of control chars
- * tty_tspeed(val) Set transmit speed to val.
- * tty_rspeed(val) Set receive speed to val.
- */
-
-
-int
-tty_linemode(void)
-{
-#ifndef USE_TERMIO
- return(termbuf.state & TS_EXTPROC);
-#else
- return(termbuf.c_lflag & EXTPROC);
-#endif
-}
-
-void
-tty_setlinemode(int on)
-{
-#ifdef TIOCEXT
- set_termbuf();
- (void) ioctl(pty, TIOCEXT, (char *)&on);
- init_termbuf();
-#else /* !TIOCEXT */
-# ifdef EXTPROC
- if (on)
- termbuf.c_lflag |= EXTPROC;
- else
- termbuf.c_lflag &= ~EXTPROC;
-# endif
-#endif /* TIOCEXT */
-}
-#endif /* LINEMODE */
-
-int
-tty_isecho(void)
-{
-#ifndef USE_TERMIO
- return (termbuf.sg.sg_flags & ECHO);
-#else
- return (termbuf.c_lflag & ECHO);
-#endif
-}
-
-int
-tty_flowmode(void)
-{
-#ifndef USE_TERMIO
- return(((termbuf.tc.t_startc) > 0 && (termbuf.tc.t_stopc) > 0) ? 1 : 0);
-#else
- return((termbuf.c_iflag & IXON) ? 1 : 0);
-#endif
-}
-
-int
-tty_restartany(void)
-{
-#ifndef USE_TERMIO
-# ifdef DECCTQ
- return((termbuf.lflags & DECCTQ) ? 0 : 1);
-# else
- return(-1);
-# endif
-#else
- return((termbuf.c_iflag & IXANY) ? 1 : 0);
-#endif
-}
-
-void
-tty_setecho(int on)
-{
-#ifndef USE_TERMIO
- if (on)
- termbuf.sg.sg_flags |= ECHO|CRMOD;
- else
- termbuf.sg.sg_flags &= ~(ECHO|CRMOD);
-#else
- if (on)
- termbuf.c_lflag |= ECHO;
- else
- termbuf.c_lflag &= ~ECHO;
-#endif
-}
-
-int
-tty_israw(void)
-{
-#ifndef USE_TERMIO
- return(termbuf.sg.sg_flags & RAW);
-#else
- return(!(termbuf.c_lflag & ICANON));
-#endif
-}
-
-#ifdef AUTHENTICATION
-#if defined(NO_LOGIN_F) && defined(LOGIN_R)
-int
-tty_setraw(int on)
-{
-# ifndef USE_TERMIO
- if (on)
- termbuf.sg.sg_flags |= RAW;
- else
- termbuf.sg.sg_flags &= ~RAW;
-# else
- if (on)
- termbuf.c_lflag &= ~ICANON;
- else
- termbuf.c_lflag |= ICANON;
-# endif
-}
-#endif
-#endif /* AUTHENTICATION */
-
-void
-tty_binaryin(int on)
-{
-#ifndef USE_TERMIO
- if (on)
- termbuf.lflags |= LPASS8;
- else
- termbuf.lflags &= ~LPASS8;
-#else
- if (on) {
- termbuf.c_iflag &= ~ISTRIP;
- } else {
- termbuf.c_iflag |= ISTRIP;
- }
-#endif
-}
-
-void
-tty_binaryout(int on)
-{
-#ifndef USE_TERMIO
- if (on)
- termbuf.lflags |= LLITOUT;
- else
- termbuf.lflags &= ~LLITOUT;
-#else
- if (on) {
- termbuf.c_cflag &= ~(CSIZE|PARENB);
- termbuf.c_cflag |= CS8;
- termbuf.c_oflag &= ~OPOST;
- } else {
- termbuf.c_cflag &= ~CSIZE;
- termbuf.c_cflag |= CS7|PARENB;
- termbuf.c_oflag |= OPOST;
- }
-#endif
-}
-
-int
-tty_isbinaryin(void)
-{
-#ifndef USE_TERMIO
- return(termbuf.lflags & LPASS8);
-#else
- return(!(termbuf.c_iflag & ISTRIP));
-#endif
-}
-
-int
-tty_isbinaryout(void)
-{
-#ifndef USE_TERMIO
- return(termbuf.lflags & LLITOUT);
-#else
- return(!(termbuf.c_oflag&OPOST));
-#endif
-}
-
-#ifdef LINEMODE
-int
-tty_isediting(void)
-{
-#ifndef USE_TERMIO
- return(!(termbuf.sg.sg_flags & (CBREAK|RAW)));
-#else
- return(termbuf.c_lflag & ICANON);
-#endif
-}
-
-int
-tty_istrapsig(void)
-{
-#ifndef USE_TERMIO
- return(!(termbuf.sg.sg_flags&RAW));
-#else
- return(termbuf.c_lflag & ISIG);
-#endif
-}
-
-void
-tty_setedit(int on)
-{
-#ifndef USE_TERMIO
- if (on)
- termbuf.sg.sg_flags &= ~CBREAK;
- else
- termbuf.sg.sg_flags |= CBREAK;
-#else
- if (on)
- termbuf.c_lflag |= ICANON;
- else
- termbuf.c_lflag &= ~ICANON;
-#endif
-}
-
-void
-tty_setsig(int on)
-{
-#ifndef USE_TERMIO
- if (on)
- ;
-#else
- if (on)
- termbuf.c_lflag |= ISIG;
- else
- termbuf.c_lflag &= ~ISIG;
-#endif
-}
-#endif /* LINEMODE */
-
-int
-tty_issofttab(void)
-{
-#ifndef USE_TERMIO
- return (termbuf.sg.sg_flags & XTABS);
-#else
-# ifdef OXTABS
- return (termbuf.c_oflag & OXTABS);
-# endif
-# ifdef TABDLY
- return ((termbuf.c_oflag & TABDLY) == TAB3);
-# endif
-#endif
-}
-
-void
-tty_setsofttab(int on)
-{
-#ifndef USE_TERMIO
- if (on)
- termbuf.sg.sg_flags |= XTABS;
- else
- termbuf.sg.sg_flags &= ~XTABS;
-#else
- if (on) {
-# ifdef OXTABS
- termbuf.c_oflag |= OXTABS;
-# endif
-# ifdef TABDLY
- termbuf.c_oflag &= ~TABDLY;
- termbuf.c_oflag |= TAB3;
-# endif
- } else {
-# ifdef OXTABS
- termbuf.c_oflag &= ~OXTABS;
-# endif
-# ifdef TABDLY
- termbuf.c_oflag &= ~TABDLY;
- termbuf.c_oflag |= TAB0;
-# endif
- }
-#endif
-}
-
-int
-tty_islitecho(void)
-{
-#ifndef USE_TERMIO
- return (!(termbuf.lflags & LCTLECH));
-#else
-# ifdef ECHOCTL
- return (!(termbuf.c_lflag & ECHOCTL));
-# endif
-# ifdef TCTLECH
- return (!(termbuf.c_lflag & TCTLECH));
-# endif
-# if !defined(ECHOCTL) && !defined(TCTLECH)
- return (0); /* assumes ctl chars are echoed '^x' */
-# endif
-#endif
-}
-
-void
-tty_setlitecho(int on)
-{
-#ifndef USE_TERMIO
- if (on)
- termbuf.lflags &= ~LCTLECH;
- else
- termbuf.lflags |= LCTLECH;
-#else
-# ifdef ECHOCTL
- if (on)
- termbuf.c_lflag &= ~ECHOCTL;
- else
- termbuf.c_lflag |= ECHOCTL;
-# endif
-# ifdef TCTLECH
- if (on)
- termbuf.c_lflag &= ~TCTLECH;
- else
- termbuf.c_lflag |= TCTLECH;
-# endif
-#endif
-}
-
-int
-tty_iscrnl(void)
-{
-#ifndef USE_TERMIO
- return (termbuf.sg.sg_flags & CRMOD);
-#else
- return (termbuf.c_iflag & ICRNL);
-#endif
-}
-
-/*
- * Try to guess whether speeds are "encoded" (4.2BSD) or just numeric (4.4BSD).
- */
-#if B4800 != 4800
-#define DECODE_BAUD
-#endif
-
-#ifdef DECODE_BAUD
-
-/*
- * A table of available terminal speeds
- */
-struct termspeeds {
- int speed;
- int value;
-} termspeeds[] = {
- { 0, B0 }, { 50, B50 }, { 75, B75 },
- { 110, B110 }, { 134, B134 }, { 150, B150 },
- { 200, B200 }, { 300, B300 }, { 600, B600 },
- { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 },
- { 4800, B4800 },
-#ifdef B7200
- { 7200, B7200 },
-#endif
- { 9600, B9600 },
-#ifdef B14400
- { 14400, B14400 },
-#endif
-#ifdef B19200
- { 19200, B19200 },
-#endif
-#ifdef B28800
- { 28800, B28800 },
-#endif
-#ifdef B38400
- { 38400, B38400 },
-#endif
-#ifdef B57600
- { 57600, B57600 },
-#endif
-#ifdef B115200
- { 115200, B115200 },
-#endif
-#ifdef B230400
- { 230400, B230400 },
-#endif
- { -1, 0 }
-};
-#endif /* DECODE_BAUD */
-
-void
-tty_tspeed(int val)
-{
-#ifdef DECODE_BAUD
- struct termspeeds *tp;
-
- for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++)
- ;
- if (tp->speed == -1) /* back up to last valid value */
- --tp;
- cfsetospeed(&termbuf, tp->value);
-#else /* DECODE_BAUD */
- cfsetospeed(&termbuf, val);
-#endif /* DECODE_BAUD */
-}
-
-void
-tty_rspeed(int val)
-{
-#ifdef DECODE_BAUD
- struct termspeeds *tp;
-
- for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++)
- ;
- if (tp->speed == -1) /* back up to last valid value */
- --tp;
- cfsetispeed(&termbuf, tp->value);
-#else /* DECODE_BAUD */
- cfsetispeed(&termbuf, val);
-#endif /* DECODE_BAUD */
-}
-
-/*
- * getptyslave()
- *
- * Open the slave side of the pty, and do any initialization
- * that is necessary.
- */
-static void
-getptyslave(void)
-{
- int t = -1;
- char erase;
-
-# ifdef LINEMODE
- int waslm;
-# endif
-# ifdef TIOCGWINSZ
- struct winsize ws;
- extern int def_row, def_col;
-# endif
- extern int def_tspeed, def_rspeed;
- /*
- * Opening the slave side may cause initilization of the
- * kernel tty structure. We need remember the state of
- * if linemode was turned on
- * terminal window size
- * terminal speed
- * erase character
- * so that we can re-set them if we need to.
- */
-# ifdef LINEMODE
- waslm = tty_linemode();
-# endif
- erase = termbuf.c_cc[VERASE];
-
- /*
- * Make sure that we don't have a controlling tty, and
- * that we are the session (process group) leader.
- */
-# ifdef TIOCNOTTY
- t = open(_PATH_TTY, O_RDWR);
- if (t >= 0) {
- (void) ioctl(t, TIOCNOTTY, (char *)0);
- (void) close(t);
- }
-# endif
-
- t = cleanopen(line);
- if (t < 0)
- fatalperror(net, line);
-
-
- /*
- * set up the tty modes as we like them to be.
- */
- init_termbuf();
-# ifdef TIOCGWINSZ
- if (def_row || def_col) {
- memset((char *)&ws, 0, sizeof(ws));
- ws.ws_col = def_col;
- ws.ws_row = def_row;
- (void)ioctl(t, TIOCSWINSZ, (char *)&ws);
- }
-# endif
-
- /*
- * Settings for sgtty based systems
- */
-# ifndef USE_TERMIO
- termbuf.sg.sg_flags |= CRMOD|ANYP|ECHO|XTABS;
-# endif /* USE_TERMIO */
-
- /*
- * Settings for all other termios/termio based
- * systems, other than 4.4BSD. In 4.4BSD the
- * kernel does the initial terminal setup.
- */
- tty_rspeed((def_rspeed > 0) ? def_rspeed : 9600);
- tty_tspeed((def_tspeed > 0) ? def_tspeed : 9600);
- if (erase)
- termbuf.c_cc[VERASE] = erase;
-# ifdef LINEMODE
- if (waslm)
- tty_setlinemode(1);
-# endif /* LINEMODE */
-
- /*
- * Set the tty modes, and make this our controlling tty.
- */
- set_termbuf();
- if (login_tty(t) == -1)
- fatalperror(net, "login_tty");
- if (net > 2)
- (void) close(net);
-#ifdef AUTHENTICATION
-#if defined(NO_LOGIN_F) && defined(LOGIN_R)
- /*
- * Leave the pty open so that we can write out the rlogin
- * protocol for /bin/login, if the authentication works.
- */
-#else
- if (pty > 2) {
- (void) close(pty);
- pty = -1;
- }
-#endif
-#endif /* AUTHENTICATION */
-}
-
-#ifndef O_NOCTTY
-#define O_NOCTTY 0
-#endif
-/*
- * Open the specified slave side of the pty,
- * making sure that we have a clean tty.
- */
-int
-cleanopen(char *li)
-{
- int t;
-
- /*
- * Make sure that other people can't open the
- * slave side of the connection.
- */
- (void) chown(li, 0, 0);
- (void) chmod(li, 0600);
-
- (void) revoke(li);
-
- t = open(line, O_RDWR|O_NOCTTY);
-
- if (t < 0)
- return(-1);
-
- return(t);
-}
-
-/*
- * startslave(host)
- *
- * Given a hostname, do whatever
- * is necessary to startup the login process on the slave side of the pty.
- */
-
-/* ARGSUSED */
-void
-startslave(char *host, int autologin, char *autoname)
-{
- int i;
-
-#ifdef AUTHENTICATION
- if (!autoname || !autoname[0])
- autologin = 0;
-
- if (autologin < auth_level) {
- fatal(net, "Authorization failed");
- exit(1);
- }
-#endif
-
-
- if ((i = fork()) < 0)
- fatalperror(net, "fork");
- if (i) {
- } else {
- getptyslave();
- start_login(host, autologin, autoname);
- /*NOTREACHED*/
- }
-}
-
-void
-init_env(void)
-{
- char **envp;
-
- envp = envinit;
- if ((*envp = getenv("TZ")))
- *envp++ -= 3;
- *envp = 0;
- environ = envinit;
-}
-
-
-/*
- * start_login(host)
- *
- * Assuming that we are now running as a child processes, this
- * function will turn us into the login process.
- */
-
-#ifndef AUTHENTICATION
-#define undef1 __unused
-#else
-#define undef1
-#endif
-
-void
-start_login(char *host undef1, int autologin undef1, char *name undef1)
-{
- char **argv;
-
- scrub_env();
-
- /*
- * -h : pass on name of host.
- * WARNING: -h is accepted by login if and only if
- * getuid() == 0.
- * -p : don't clobber the environment (so terminal type stays set).
- *
- * -f : force this login, he has already been authenticated
- */
- argv = addarg(0, "login");
-
-#if !defined(NO_LOGIN_H)
-#ifdef AUTHENTICATION
-# if defined(NO_LOGIN_F) && defined(LOGIN_R)
- /*
- * Don't add the "-h host" option if we are going
- * to be adding the "-r host" option down below...
- */
- if ((auth_level < 0) || (autologin != AUTH_VALID))
-# endif
- {
- argv = addarg(argv, "-h");
- argv = addarg(argv, host);
- }
-#endif /* AUTHENTICATION */
-#endif
-#if !defined(NO_LOGIN_P)
- argv = addarg(argv, "-p");
-#endif
-#ifdef LINEMODE
- /*
- * Set the environment variable "LINEMODE" to either
- * "real" or "kludge" if we are operating in either
- * real or kludge linemode.
- */
- if (lmodetype == REAL_LINEMODE)
- setenv("LINEMODE", "real", 1);
-# ifdef KLUDGELINEMODE
- else if (lmodetype == KLUDGE_LINEMODE || lmodetype == KLUDGE_OK)
- setenv("LINEMODE", "kludge", 1);
-# endif
-#endif
-#ifdef BFTPDAEMON
- /*
- * Are we working as the bftp daemon? If so, then ask login
- * to start bftp instead of shell.
- */
- if (bftpd) {
- argv = addarg(argv, "-e");
- argv = addarg(argv, BFTPPATH);
- } else
-#endif
-#ifdef AUTHENTICATION
- if (auth_level >= 0 && autologin == AUTH_VALID) {
-# if !defined(NO_LOGIN_F)
- argv = addarg(argv, "-f");
- argv = addarg(argv, "--");
- argv = addarg(argv, name);
-# else
-# if defined(LOGIN_R)
- /*
- * We don't have support for "login -f", but we
- * can fool /bin/login into thinking that we are
- * rlogind, and allow us to log in without a
- * password. The rlogin protocol expects
- * local-user\0remote-user\0term/speed\0
- */
-
- if (pty > 2) {
- char *cp;
- char speed[128];
- int isecho, israw, xpty, len;
- extern int def_rspeed;
-# ifndef LOGIN_HOST
- /*
- * Tell login that we are coming from "localhost".
- * If we passed in the real host name, then the
- * user would have to allow .rhost access from
- * every machine that they want authenticated
- * access to work from, which sort of defeats
- * the purpose of an authenticated login...
- * So, we tell login that the session is coming
- * from "localhost", and the user will only have
- * to have "localhost" in their .rhost file.
- */
-# define LOGIN_HOST "localhost"
-# endif
- argv = addarg(argv, "-r");
- argv = addarg(argv, LOGIN_HOST);
-
- xpty = pty;
- pty = 0;
- init_termbuf();
- isecho = tty_isecho();
- israw = tty_israw();
- if (isecho || !israw) {
- tty_setecho(0); /* Turn off echo */
- tty_setraw(1); /* Turn on raw */
- set_termbuf();
- }
- len = strlen(name)+1;
- write(xpty, name, len);
- write(xpty, name, len);
- snprintf(speed, sizeof(speed),
- "%s/%d", (cp = getenv("TERM")) ? cp : "",
- (def_rspeed > 0) ? def_rspeed : 9600);
- len = strlen(speed)+1;
- write(xpty, speed, len);
-
- if (isecho || !israw) {
- init_termbuf();
- tty_setecho(isecho);
- tty_setraw(israw);
- set_termbuf();
- if (!israw) {
- /*
- * Write a newline to ensure
- * that login will be able to
- * read the line...
- */
- write(xpty, "\n", 1);
- }
- }
- pty = xpty;
- }
-# else
- argv = addarg(argv, "--");
- argv = addarg(argv, name);
-# endif
-# endif
- } else
-#endif
- if (getenv("USER")) {
- argv = addarg(argv, "--");
- argv = addarg(argv, getenv("USER"));
-#if defined(LOGIN_ARGS) && defined(NO_LOGIN_P)
- {
- char **cpp;
- for (cpp = environ; *cpp; cpp++)
- argv = addarg(argv, *cpp);
- }
-#endif
- /*
- * Assume that login will set the USER variable
- * correctly. For SysV systems, this means that
- * USER will no longer be set, just LOGNAME by
- * login. (The problem is that if the auto-login
- * fails, and the user then specifies a different
- * account name, he can get logged in with both
- * LOGNAME and USER in his environment, but the
- * USER value will be wrong.
- */
- unsetenv("USER");
- }
-#ifdef AUTHENTICATION
-#if defined(NO_LOGIN_F) && defined(LOGIN_R)
- if (pty > 2)
- close(pty);
-#endif
-#endif /* AUTHENTICATION */
- closelog();
-
- if (altlogin == NULL) {
- altlogin = _PATH_LOGIN;
- }
- execv(altlogin, argv);
-
- syslog(LOG_ERR, "%s: %m", altlogin);
- fatalperror(net, altlogin);
- /*NOTREACHED*/
-}
-
-static char **
-addarg(char **argv, const char *val)
-{
- char **cpp;
-
- if (argv == NULL) {
- /*
- * 10 entries, a leading length, and a null
- */
- argv = (char **)malloc(sizeof(*argv) * 12);
- if (argv == NULL)
- return(NULL);
- *argv++ = (char *)10;
- *argv = (char *)0;
- }
- for (cpp = argv; *cpp; cpp++)
- ;
- if (cpp == &argv[(long)argv[-1]]) {
- --argv;
- *argv = (char *)((long)(*argv) + 10);
- argv = (char **)realloc(argv, sizeof(*argv)*((long)(*argv) + 2));
- if (argv == NULL)
- return(NULL);
- argv++;
- cpp = &argv[(long)argv[-1] - 10];
- }
- *cpp++ = strdup(val);
- *cpp = 0;
- return(argv);
-}
-
-/*
- * scrub_env()
- *
- * We only accept the environment variables listed below.
- */
-void
-scrub_env(void)
-{
- static const char *rej[] = {
- "TERMCAP=/",
- NULL
- };
-
- static const char *acc[] = {
- "XAUTH=", "XAUTHORITY=", "DISPLAY=",
- "TERM=",
- "EDITOR=",
- "PAGER=",
- "LOGNAME=",
- "POSIXLY_CORRECT=",
- "PRINTER=",
- NULL
- };
-
- char **cpp, **cpp2;
- const char **p;
-
- for (cpp2 = cpp = environ; *cpp; cpp++) {
- int reject_it = 0;
-
- for(p = rej; *p; p++)
- if(strncmp(*cpp, *p, strlen(*p)) == 0) {
- reject_it = 1;
- break;
- }
- if (reject_it)
- continue;
-
- for(p = acc; *p; p++)
- if(strncmp(*cpp, *p, strlen(*p)) == 0)
- break;
- if(*p != NULL)
- *cpp2++ = *cpp;
- }
- *cpp2 = NULL;
-}
-
-/*
- * cleanup()
- *
- * This is the routine to call when we are all through, to
- * clean up anything that needs to be cleaned up.
- */
-/* ARGSUSED */
-void
-cleanup(int sig __unused)
-{
- char *p;
- sigset_t mask;
-
- p = line + sizeof(_PATH_DEV) - 1;
- /*
- * Block all signals before clearing the utmp entry. We don't want to
- * be called again after calling logout() and then not add the wtmp
- * entry because of not finding the corresponding entry in utmp.
- */
- sigfillset(&mask);
- sigprocmask(SIG_SETMASK, &mask, NULL);
- if (logout(p))
- logwtmp(p, "", "");
- (void)chmod(line, 0666);
- (void)chown(line, 0, 0);
- *p = 'p';
- (void)chmod(line, 0666);
- (void)chown(line, 0, 0);
- (void) shutdown(net, 2);
- _exit(1);
-}
diff --git a/contrib/telnet/telnetd/telnetd.8 b/contrib/telnet/telnetd/telnetd.8
deleted file mode 100644
index b11fbac76059..000000000000
--- a/contrib/telnet/telnetd/telnetd.8
+++ /dev/null
@@ -1,587 +0,0 @@
-.\" Copyright (c) 1983, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)telnetd.8 8.4 (Berkeley) 6/1/94
-.\" $FreeBSD$
-.\"
-.Dd January 27, 2000
-.Dt TELNETD 8
-.Os
-.Sh NAME
-.Nm telnetd
-.Nd DARPA
-.Tn TELNET
-protocol server
-.Sh SYNOPSIS
-.Nm /usr/libexec/telnetd
-.Op Fl BUhlkn
-.Op Fl D Ar debugmode
-.Op Fl S Ar tos
-.Op Fl X Ar authtype
-.Op Fl a Ar authmode
-.Op Fl edebug
-.Op Fl p Ar loginprog
-.Op Fl u Ar len
-.Op Fl debug Op Ar port
-.Sh DESCRIPTION
-The
-.Nm
-command is a server which supports the
-.Tn DARPA
-standard
-.Tn TELNET
-virtual terminal protocol.
-.Nm Telnetd
-is normally invoked by the internet server (see
-.Xr inetd 8 )
-for requests to connect to the
-.Tn TELNET
-port as indicated by the
-.Pa /etc/services
-file (see
-.Xr services 5 ) .
-The
-.Fl debug
-option may be used to start up
-.Nm
-manually, instead of through
-.Xr inetd 8 .
-If started up this way,
-.Ar port
-may be specified to run
-.Nm
-on an alternate
-.Tn TCP
-port number.
-.Pp
-The
-.Nm
-command accepts the following options:
-.Bl -tag -width indent
-.It Fl a Ar authmode
-This option may be used for specifying what mode should
-be used for authentication.
-Note that this option is only useful if
-.Nm
-has been compiled with support for the
-.Dv AUTHENTICATION
-option.
-There are several valid values for
-.Ar authmode :
-.Bl -tag -width debug
-.It Cm debug
-Turn on authentication debugging code.
-.It Cm user
-Only allow connections when the remote user
-can provide valid authentication information
-to identify the remote user,
-and is allowed access to the specified account
-without providing a password.
-.It Cm valid
-Only allow connections when the remote user
-can provide valid authentication information
-to identify the remote user.
-The
-.Xr login 1
-command will provide any additional user verification
-needed if the remote user is not allowed automatic
-access to the specified account.
-.It Cm other
-Only allow connections that supply some authentication information.
-This option is currently not supported
-by any of the existing authentication mechanisms,
-and is thus the same as specifying
-.Fl a
-.Cm valid .
-.It Cm none
-This is the default state.
-Authentication information is not required.
-If no or insufficient authentication information
-is provided, then the
-.Xr login 1
-program will provide the necessary user
-verification.
-.It Cm off
-Disable the authentication code.
-All user verification will happen through the
-.Xr login 1
-program.
-.El
-.It Fl B
-Specify bftp server mode. In this mode,
-.Nm
-causes login to start a
-.Xr bftp 1
-session rather than the user's
-normal shell. In bftp daemon mode normal
-logins are not supported, and it must be used
-on a port other than the normal
-.Tn TELNET
-port.
-.It Fl D Ar debugmode
-This option may be used for debugging purposes.
-This allows
-.Nm
-to print out debugging information
-to the connection, allowing the user to see what
-.Nm
-is doing.
-There are several possible values for
-.Ar debugmode :
-.Bl -tag -width exercise
-.It Cm options
-Print information about the negotiation of
-.Tn TELNET
-options.
-.It Cm report
-Print the
-.Cm options
-information, plus some additional information
-about what processing is going on.
-.It Cm netdata
-Display the data stream received by
-.Nm .
-.It Cm ptydata
-Display data written to the pty.
-.It Cm exercise
-Has not been implemented yet.
-.El
-.It Fl debug
-Enable debugging on each socket created by
-.Nm
-(see
-.Dv SO_DEBUG
-in
-.Xr socket 2 ) .
-.It Fl edebug
-If
-.Nm
-has been compiled with support for data encryption, then the
-.Fl edebug
-option may be used to enable encryption debugging code.
-.It Fl h
-Disable the printing of host-specific information before
-login has been completed.
-.It Fl k
-This option is only useful if
-.Nm
-has been compiled with both linemode and kludge linemode
-support. If the
-.Fl k
-option is specified, then if the remote client does not
-support the
-.Dv LINEMODE
-option, then
-.Nm
-will operate in character at a time mode.
-It will still support kludge linemode, but will only
-go into kludge linemode if the remote client requests
-it.
-(This is done by the client sending
-.Dv DONT SUPPRESS-GO-AHEAD
-and
-.Dv DONT ECHO . )
-The
-.Fl k
-option is most useful when there are remote clients
-that do not support kludge linemode, but pass the heuristic
-(if they respond with
-.Dv WILL TIMING-MARK
-in response to a
-.Dv DO TIMING-MARK )
-for kludge linemode support.
-.It Fl l
-Specify line mode. Try to force clients to use line-
-at-a-time mode.
-If the
-.Dv LINEMODE
-option is not supported, it will go
-into kludge linemode.
-.It Fl n
-Disable
-.Dv TCP
-keep-alives. Normally
-.Nm
-enables the
-.Tn TCP
-keep-alive mechanism to probe connections that
-have been idle for some period of time to determine
-if the client is still there, so that idle connections
-from machines that have crashed or can no longer
-be reached may be cleaned up.
-.It Fl p Ar loginprog
-Specify an alternate
-.Xr login 1
-command to run to complete the login. The alternate command must
-understand the same command arguments as the standard login.
-.It Fl S Ar tos
-.It Fl u Ar len
-This option is used to specify the size of the field
-in the
-.Dv utmp
-structure that holds the remote host name.
-If the resolved host name is longer than
-.Ar len ,
-the dotted decimal value will be used instead.
-This allows hosts with very long host names that
-overflow this field to still be uniquely identified.
-Specifying
-.Fl u0
-indicates that only dotted decimal addresses
-should be put into the
-.Pa utmp
-file.
-.It Fl U
-This option causes
-.Nm
-to refuse connections from addresses that
-cannot be mapped back into a symbolic name
-via the
-.Xr gethostbyaddr 3
-routine.
-.It Fl X Ar authtype
-This option is only valid if
-.Nm
-has been built with support for the authentication option.
-It disables the use of
-.Ar authtype
-authentication, and
-can be used to temporarily disable
-a specific authentication type without having to recompile
-.Nm .
-.El
-.Pp
-.Nm Telnetd
-operates by allocating a pseudo-terminal device (see
-.Xr pty 4 )
-for a client, then creating a login process which has
-the slave side of the pseudo-terminal as
-.Dv stdin ,
-.Dv stdout
-and
-.Dv stderr .
-.Nm Telnetd
-manipulates the master side of the pseudo-terminal,
-implementing the
-.Tn TELNET
-protocol and passing characters
-between the remote client and the login process.
-.Pp
-When a
-.Tn TELNET
-session is started up,
-.Nm
-sends
-.Tn TELNET
-options to the client side indicating
-a willingness to do the
-following
-.Tn TELNET
-options, which are described in more detail below:
-.Bd -literal -offset indent
-DO AUTHENTICATION
-WILL ENCRYPT
-DO TERMINAL TYPE
-DO TSPEED
-DO XDISPLOC
-DO NEW-ENVIRON
-DO ENVIRON
-WILL SUPPRESS GO AHEAD
-DO ECHO
-DO LINEMODE
-DO NAWS
-WILL STATUS
-DO LFLOW
-DO TIMING-MARK
-.Ed
-.Pp
-The pseudo-terminal allocated to the client is configured
-to operate in
-.Dq cooked
-mode, and with
-.Dv XTABS and
-.Dv CRMOD
-enabled (see
-.Xr tty 4 ) .
-.Pp
-.Nm Telnetd
-has support for enabling locally the following
-.Tn TELNET
-options:
-.Bl -tag -width "DO AUTHENTICATION"
-.It "WILL ECHO"
-When the
-.Dv LINEMODE
-option is enabled, a
-.Dv WILL ECHO
-or
-.Dv WONT ECHO
-will be sent to the client to indicate the
-current state of terminal echoing.
-When terminal echo is not desired, a
-.Dv WILL ECHO
-is sent to indicate that
-.Nm
-will take care of echoing any data that needs to be
-echoed to the terminal, and then nothing is echoed.
-When terminal echo is desired, a
-.Dv WONT ECHO
-is sent to indicate that
-.Nm
-will not be doing any terminal echoing, so the
-client should do any terminal echoing that is needed.
-.It "WILL BINARY"
-Indicate that the client is willing to send a
-8 bits of data, rather than the normal 7 bits
-of the Network Virtual Terminal.
-.It "WILL SGA"
-Indicate that it will not be sending
-.Dv IAC GA ,
-go ahead, commands.
-.It "WILL STATUS"
-Indicate a willingness to send the client, upon
-request, of the current status of all
-.Tn TELNET
-options.
-.It "WILL TIMING-MARK"
-Whenever a
-.Dv DO TIMING-MARK
-command is received, it is always responded
-to with a
-.Dv WILL TIMING-MARK .
-.It "WILL LOGOUT"
-When a
-.Dv DO LOGOUT
-is received, a
-.Dv WILL LOGOUT
-is sent in response, and the
-.Tn TELNET
-session is shut down.
-.It "WILL ENCRYPT"
-Only sent if
-.Nm
-is compiled with support for data encryption, and
-indicates a willingness to decrypt
-the data stream.
-.El
-.Pp
-.Nm Telnetd
-has support for enabling remotely the following
-.Tn TELNET
-options:
-.Bl -tag -width "DO AUTHENTICATION"
-.It "DO BINARY"
-Sent to indicate that
-.Nm
-is willing to receive an 8 bit data stream.
-.It "DO LFLOW"
-Requests that the client handle flow control
-characters remotely.
-.It "DO ECHO"
-This is not really supported, but is sent to identify a
-.Bx 4.2
-.Xr telnet 1
-client, which will improperly respond with
-.Dv WILL ECHO .
-If a
-.Dv WILL ECHO
-is received, a
-.Dv DONT ECHO
-will be sent in response.
-.It "DO TERMINAL-TYPE"
-Indicate a desire to be able to request the
-name of the type of terminal that is attached
-to the client side of the connection.
-.It "DO SGA"
-Indicate that it does not need to receive
-.Dv IAC GA ,
-the go ahead command.
-.It "DO NAWS"
-Requests that the client inform the server when
-the window (display) size changes.
-.It "DO TERMINAL-SPEED"
-Indicate a desire to be able to request information
-about the speed of the serial line to which
-the client is attached.
-.It "DO XDISPLOC"
-Indicate a desire to be able to request the name
-of the X Window System display that is associated with
-the telnet client.
-.It "DO NEW-ENVIRON"
-Indicate a desire to be able to request environment
-variable information, as described in RFC 1572.
-.It "DO ENVIRON"
-Indicate a desire to be able to request environment
-variable information, as described in RFC 1408.
-.It "DO LINEMODE"
-Only sent if
-.Nm
-is compiled with support for linemode, and
-requests that the client do line by line processing.
-.It "DO TIMING-MARK"
-Only sent if
-.Nm
-is compiled with support for both linemode and
-kludge linemode, and the client responded with
-.Dv WONT LINEMODE .
-If the client responds with
-.Dv WILL TM ,
-the it is assumed that the client supports
-kludge linemode.
-Note that the
-.Op Fl k
-option can be used to disable this.
-.It "DO AUTHENTICATION"
-Only sent if
-.Nm
-is compiled with support for authentication, and
-indicates a willingness to receive authentication
-information for automatic login.
-.It "DO ENCRYPT"
-Only sent if
-.Nm
-is compiled with support for data encryption, and
-indicates a willingness to decrypt
-the data stream.
-.El
-.Sh NOTES
-By default
-.Nm
-will read the
-.Em \&he ,
-.Em \&hn ,
-and
-.Em \&im
-capabilities from
-.Pa /etc/gettytab
-and use that information (if present) to determine
-what to display before the login: prompt. You can
-also use a System V style
-.Pa /etc/issue
-file by using the
-.Em \&if
-capability, which will override
-.Em \&im .
-The information specified in either
-.Em \&im
-or
-.Em \&if
-will be displayed to both console and remote logins.
-.\" .Sh ENVIRONMENT
-.Sh FILES
-.Bl -tag -width /usr/ucb/bftp -compact
-.It Pa /etc/services
-.It Pa /etc/gettytab
-.It Pa /etc/iptos
-(if supported)
-.It Pa /usr/ucb/bftp
-(if supported)
-.El
-.Sh "SEE ALSO"
-.Xr bftp 1 ,
-.Xr login 1 ,
-.Xr gettytab 5 ,
-.Xr telnet 1
-(if supported)
-.Sh STANDARDS
-.Bl -tag -compact -width RFC-1572
-.It Cm RFC-854
-.Tn TELNET
-PROTOCOL SPECIFICATION
-.It Cm RFC-855
-TELNET OPTION SPECIFICATIONS
-.It Cm RFC-856
-TELNET BINARY TRANSMISSION
-.It Cm RFC-857
-TELNET ECHO OPTION
-.It Cm RFC-858
-TELNET SUPPRESS GO AHEAD OPTION
-.It Cm RFC-859
-TELNET STATUS OPTION
-.It Cm RFC-860
-TELNET TIMING MARK OPTION
-.It Cm RFC-861
-TELNET EXTENDED OPTIONS - LIST OPTION
-.It Cm RFC-885
-TELNET END OF RECORD OPTION
-.It Cm RFC-1073
-Telnet Window Size Option
-.It Cm RFC-1079
-Telnet Terminal Speed Option
-.It Cm RFC-1091
-Telnet Terminal-Type Option
-.It Cm RFC-1096
-Telnet X Display Location Option
-.It Cm RFC-1123
-Requirements for Internet Hosts -- Application and Support
-.It Cm RFC-1184
-Telnet Linemode Option
-.It Cm RFC-1372
-Telnet Remote Flow Control Option
-.It Cm RFC-1416
-Telnet Authentication Option
-.It Cm RFC-1411
-Telnet Authentication: Kerberos Version 4
-.It Cm RFC-1412
-Telnet Authentication: SPX
-.It Cm RFC-1571
-Telnet Environment Option Interoperability Issues
-.It Cm RFC-1572
-Telnet Environment Option
-.El
-.Sh BUGS
-Some
-.Tn TELNET
-commands are only partially implemented.
-.Pp
-Because of bugs in the original
-.Bx 4.2
-.Xr telnet 1 ,
-.Nm
-performs some dubious protocol exchanges to try to discover if the remote
-client is, in fact, a
-.Bx 4.2
-.Xr telnet 1 .
-.Pp
-Binary mode
-has no common interpretation except between similar operating systems
-(Unix in this case).
-.Pp
-The terminal type name received from the remote client is converted to
-lower case.
-.Pp
-.Nm Telnetd
-never sends
-.Tn TELNET
-.Dv IAC GA
-(go ahead) commands.
-.Sh HISTORY
-IPv6 support was added by WIDE/KAME project.
diff --git a/contrib/telnet/telnetd/telnetd.c b/contrib/telnet/telnetd/telnetd.c
deleted file mode 100644
index bdb76d7a786d..000000000000
--- a/contrib/telnet/telnetd/telnetd.c
+++ /dev/null
@@ -1,1226 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "telnetd.h"
-#include "pathnames.h"
-
-#include <sys/mman.h>
-#include <err.h>
-#include <libutil.h>
-#include <paths.h>
-#include <termcap.h>
-#include <utmp.h>
-
-#include <arpa/inet.h>
-
-#ifdef AUTHENTICATION
-#include <libtelnet/auth.h>
-int auth_level = 0;
-#endif
-#ifdef ENCRYPTION
-#include <libtelnet/encrypt.h>
-#endif
-#include <libtelnet/misc.h>
-
-char remote_hostname[MAXHOSTNAMELEN];
-size_t utmp_len = sizeof(remote_hostname) - 1;
-int registerd_host_only = 0;
-
-
-/*
- * I/O data buffers,
- * pointers, and counters.
- */
-char ptyibuf[BUFSIZ], *ptyip = ptyibuf;
-char ptyibuf2[BUFSIZ];
-
-int readstream(int, char *, int);
-void doit(struct sockaddr *);
-int terminaltypeok(char *);
-
-int hostinfo = 1; /* do we print login banner? */
-
-static int debug = 0;
-int keepalive = 1;
-const char *altlogin;
-
-void doit(struct sockaddr *);
-int terminaltypeok(char *);
-void startslave(char *, int, char *);
-extern void usage(void);
-static void _gettermname(void);
-
-/*
- * The string to pass to getopt(). We do it this way so
- * that only the actual options that we support will be
- * passed off to getopt().
- */
-char valid_opts[] = {
- 'd', ':', 'h', 'k', 'n', 'p', ':', 'S', ':', 'u', ':', 'U',
- '4', '6',
-#ifdef AUTHENTICATION
- 'a', ':', 'X', ':',
-#endif
-#ifdef BFTPDAEMON
- 'B',
-#endif
-#ifdef DIAGNOSTICS
- 'D', ':',
-#endif
-#ifdef ENCRYPTION
- 'e', ':',
-#endif
-#ifdef LINEMODE
- 'l',
-#endif
- '\0'
-};
-
-int family = AF_INET;
-
-#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 256
-#endif /* MAXHOSTNAMELEN */
-
-char *hostname;
-char host_name[MAXHOSTNAMELEN];
-
-extern void telnet(int, int, char *);
-
-int level;
-char user_name[256];
-
-int
-main(int argc, char *argv[])
-{
- struct sockaddr_storage from;
- int on = 1, fromlen;
- int ch;
-#if defined(IPPROTO_IP) && defined(IP_TOS)
- int tos = -1;
-#endif
-
- pfrontp = pbackp = ptyobuf;
- netip = netibuf;
- nfrontp = nbackp = netobuf;
-#ifdef ENCRYPTION
- nclearto = 0;
-#endif /* ENCRYPTION */
-
- /*
- * This initialization causes linemode to default to a configuration
- * that works on all telnet clients, including the FreeBSD client.
- * This is not quite the same as the telnet client issuing a "mode
- * character" command, but has most of the same benefits, and is
- * preferable since some clients (like usofts) don't have the
- * mode character command anyway and linemode breaks things.
- * The most notable symptom of fix is that csh "set filec" operations
- * like <ESC> (filename completion) and ^D (choices) keys now work
- * in telnet sessions and can be used more than once on the same line.
- * CR/LF handling is also corrected in some termio modes. This
- * change resolves problem reports bin/771 and bin/1037.
- */
-
- linemode=1; /*Default to mode that works on bulk of clients*/
-
- while ((ch = getopt(argc, argv, valid_opts)) != -1) {
- switch(ch) {
-
-#ifdef AUTHENTICATION
- case 'a':
- /*
- * Check for required authentication level
- */
- if (strcmp(optarg, "debug") == 0) {
- extern int auth_debug_mode;
- auth_debug_mode = 1;
- } else if (strcasecmp(optarg, "none") == 0) {
- auth_level = 0;
- } else if (strcasecmp(optarg, "other") == 0) {
- auth_level = AUTH_OTHER;
- } else if (strcasecmp(optarg, "user") == 0) {
- auth_level = AUTH_USER;
- } else if (strcasecmp(optarg, "valid") == 0) {
- auth_level = AUTH_VALID;
- } else if (strcasecmp(optarg, "off") == 0) {
- /*
- * This hack turns off authentication
- */
- auth_level = -1;
- } else {
- warnx("unknown authorization level for -a");
- }
- break;
-#endif /* AUTHENTICATION */
-
-#ifdef BFTPDAEMON
- case 'B':
- bftpd++;
- break;
-#endif /* BFTPDAEMON */
-
- case 'd':
- if (strcmp(optarg, "ebug") == 0) {
- debug++;
- break;
- }
- usage();
- /* NOTREACHED */
- break;
-
-#ifdef DIAGNOSTICS
- case 'D':
- /*
- * Check for desired diagnostics capabilities.
- */
- if (!strcmp(optarg, "report")) {
- diagnostic |= TD_REPORT|TD_OPTIONS;
- } else if (!strcmp(optarg, "exercise")) {
- diagnostic |= TD_EXERCISE;
- } else if (!strcmp(optarg, "netdata")) {
- diagnostic |= TD_NETDATA;
- } else if (!strcmp(optarg, "ptydata")) {
- diagnostic |= TD_PTYDATA;
- } else if (!strcmp(optarg, "options")) {
- diagnostic |= TD_OPTIONS;
- } else {
- usage();
- /* NOT REACHED */
- }
- break;
-#endif /* DIAGNOSTICS */
-
-#ifdef ENCRYPTION
- case 'e':
- if (strcmp(optarg, "debug") == 0) {
- extern int encrypt_debug_mode;
- encrypt_debug_mode = 1;
- break;
- }
- usage();
- /* NOTREACHED */
- break;
-#endif /* ENCRYPTION */
-
- case 'h':
- hostinfo = 0;
- break;
-
-#ifdef LINEMODE
- case 'l':
- alwayslinemode = 1;
- break;
-#endif /* LINEMODE */
-
- case 'k':
-#if defined(LINEMODE) && defined(KLUDGELINEMODE)
- lmodetype = NO_AUTOKLUDGE;
-#else
- /* ignore -k option if built without kludge linemode */
-#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
- break;
-
- case 'n':
- keepalive = 0;
- break;
-
- case 'p':
- altlogin = optarg;
- break;
-
- case 'S':
-#ifdef HAS_GETTOS
- if ((tos = parsetos(optarg, "tcp")) < 0)
- warnx("%s%s%s",
- "bad TOS argument '", optarg,
- "'; will try to use default TOS");
-#else
- warnx("TOS option unavailable; -S flag not supported");
-#endif
- break;
-
- case 'u':
- utmp_len = (size_t)atoi(optarg);
- if (utmp_len >= sizeof(remote_hostname))
- utmp_len = sizeof(remote_hostname) - 1;
- break;
-
- case 'U':
- registerd_host_only = 1;
- break;
-
-#ifdef AUTHENTICATION
- case 'X':
- /*
- * Check for invalid authentication types
- */
- auth_disable_name(optarg);
- break;
-#endif /* AUTHENTICATION */
-
- case '4':
- family = AF_INET;
- break;
-
-#ifdef INET6
- case '6':
- family = AF_INET6;
- break;
-#endif
-
- default:
- warnx("%c: unknown option", ch);
- /* FALLTHROUGH */
- case '?':
- usage();
- /* NOTREACHED */
- }
- }
-
- argc -= optind;
- argv += optind;
-
- if (debug) {
- int s, ns, foo, error;
- const char *service = "telnet";
- struct addrinfo hints, *res;
-
- if (argc > 1) {
- usage();
- /* NOT REACHED */
- } else if (argc == 1)
- service = *argv;
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_flags = AI_PASSIVE;
- hints.ai_family = family;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = 0;
- error = getaddrinfo(NULL, service, &hints, &res);
-
- if (error) {
- errx(1, "tcp/%s: %s\n", service, gai_strerror(error));
- if (error == EAI_SYSTEM)
- errx(1, "tcp/%s: %s\n", service, strerror(errno));
- usage();
- }
-
- s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
- if (s < 0)
- err(1, "socket");
- (void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
- (char *)&on, sizeof(on));
- if (bind(s, res->ai_addr, res->ai_addrlen) < 0)
- err(1, "bind");
- if (listen(s, 1) < 0)
- err(1, "listen");
- foo = res->ai_addrlen;
- ns = accept(s, res->ai_addr, &foo);
- if (ns < 0)
- err(1, "accept");
- (void) dup2(ns, 0);
- (void) close(ns);
- (void) close(s);
-#ifdef convex
- } else if (argc == 1) {
- ; /* VOID*/ /* Just ignore the host/port name */
-#endif
- } else if (argc > 0) {
- usage();
- /* NOT REACHED */
- }
-
- openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
- fromlen = sizeof (from);
- if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) {
- warn("getpeername");
- _exit(1);
- }
- if (keepalive &&
- setsockopt(0, SOL_SOCKET, SO_KEEPALIVE,
- (char *)&on, sizeof (on)) < 0) {
- syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
- }
-
-#if defined(IPPROTO_IP) && defined(IP_TOS)
- if (from.ss_family == AF_INET) {
-# if defined(HAS_GETTOS)
- struct tosent *tp;
- if (tos < 0 && (tp = gettosbyname("telnet", "tcp")))
- tos = tp->t_tos;
-# endif
- if (tos < 0)
- tos = 020; /* Low Delay bit */
- if (tos
- && (setsockopt(0, IPPROTO_IP, IP_TOS,
- (char *)&tos, sizeof(tos)) < 0)
- && (errno != ENOPROTOOPT) )
- syslog(LOG_WARNING, "setsockopt (IP_TOS): %m");
- }
-#endif /* defined(IPPROTO_IP) && defined(IP_TOS) */
- net = 0;
- doit((struct sockaddr *)&from);
- /* NOTREACHED */
- return(0);
-} /* end of main */
-
- void
-usage()
-{
- fprintf(stderr, "usage: telnetd");
-#ifdef AUTHENTICATION
- fprintf(stderr, " [-a (debug|other|user|valid|off|none)]\n\t");
-#endif
-#ifdef BFTPDAEMON
- fprintf(stderr, " [-B]");
-#endif
- fprintf(stderr, " [-debug]");
-#ifdef DIAGNOSTICS
- fprintf(stderr, " [-D (options|report|exercise|netdata|ptydata)]\n\t");
-#endif
-#ifdef AUTHENTICATION
- fprintf(stderr, " [-edebug]");
-#endif
- fprintf(stderr, " [-h]");
-#if defined(LINEMODE) && defined(KLUDGELINEMODE)
- fprintf(stderr, " [-k]");
-#endif
-#ifdef LINEMODE
- fprintf(stderr, " [-l]");
-#endif
- fprintf(stderr, " [-n]");
- fprintf(stderr, "\n\t");
-#ifdef HAS_GETTOS
- fprintf(stderr, " [-S tos]");
-#endif
-#ifdef AUTHENTICATION
- fprintf(stderr, " [-X auth-type]");
-#endif
- fprintf(stderr, " [-u utmp_hostname_length] [-U]");
- fprintf(stderr, " [port]\n");
- exit(1);
-}
-
-/*
- * getterminaltype
- *
- * Ask the other end to send along its terminal type and speed.
- * Output is the variable terminaltype filled in.
- */
-static unsigned char ttytype_sbbuf[] = {
- IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE
-};
-
-
-#ifndef AUTHENTICATION
-#define undef2 __unused
-#else
-#define undef2
-#endif
-
-static int
-getterminaltype(char *name undef2)
-{
- int retval = -1;
-
- settimer(baseline);
-#ifdef AUTHENTICATION
- /*
- * Handle the Authentication option before we do anything else.
- */
- send_do(TELOPT_AUTHENTICATION, 1);
- while (his_will_wont_is_changing(TELOPT_AUTHENTICATION))
- ttloop();
- if (his_state_is_will(TELOPT_AUTHENTICATION)) {
- retval = auth_wait(name);
- }
-#endif
-
-#ifdef ENCRYPTION
- send_will(TELOPT_ENCRYPT, 1);
-#endif /* ENCRYPTION */
- send_do(TELOPT_TTYPE, 1);
- send_do(TELOPT_TSPEED, 1);
- send_do(TELOPT_XDISPLOC, 1);
- send_do(TELOPT_NEW_ENVIRON, 1);
- send_do(TELOPT_OLD_ENVIRON, 1);
- while (
-#ifdef ENCRYPTION
- his_do_dont_is_changing(TELOPT_ENCRYPT) ||
-#endif /* ENCRYPTION */
- his_will_wont_is_changing(TELOPT_TTYPE) ||
- his_will_wont_is_changing(TELOPT_TSPEED) ||
- his_will_wont_is_changing(TELOPT_XDISPLOC) ||
- his_will_wont_is_changing(TELOPT_NEW_ENVIRON) ||
- his_will_wont_is_changing(TELOPT_OLD_ENVIRON)) {
- ttloop();
- }
-#ifdef ENCRYPTION
- /*
- * Wait for the negotiation of what type of encryption we can
- * send with. If autoencrypt is not set, this will just return.
- */
- if (his_state_is_will(TELOPT_ENCRYPT)) {
- encrypt_wait();
- }
-#endif /* ENCRYPTION */
- if (his_state_is_will(TELOPT_TSPEED)) {
- static unsigned char sb[] =
- { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE };
-
- output_datalen(sb, sizeof sb);
- DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
- }
- if (his_state_is_will(TELOPT_XDISPLOC)) {
- static unsigned char sb[] =
- { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE };
-
- output_datalen(sb, sizeof sb);
- DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
- }
- if (his_state_is_will(TELOPT_NEW_ENVIRON)) {
- static unsigned char sb[] =
- { IAC, SB, TELOPT_NEW_ENVIRON, TELQUAL_SEND, IAC, SE };
-
- output_datalen(sb, sizeof sb);
- DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
- }
- else if (his_state_is_will(TELOPT_OLD_ENVIRON)) {
- static unsigned char sb[] =
- { IAC, SB, TELOPT_OLD_ENVIRON, TELQUAL_SEND, IAC, SE };
-
- output_datalen(sb, sizeof sb);
- DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
- }
- if (his_state_is_will(TELOPT_TTYPE)) {
-
- output_datalen(ttytype_sbbuf, sizeof ttytype_sbbuf);
- DIAG(TD_OPTIONS, printsub('>', ttytype_sbbuf + 2,
- sizeof ttytype_sbbuf - 2););
- }
- if (his_state_is_will(TELOPT_TSPEED)) {
- while (sequenceIs(tspeedsubopt, baseline))
- ttloop();
- }
- if (his_state_is_will(TELOPT_XDISPLOC)) {
- while (sequenceIs(xdisplocsubopt, baseline))
- ttloop();
- }
- if (his_state_is_will(TELOPT_NEW_ENVIRON)) {
- while (sequenceIs(environsubopt, baseline))
- ttloop();
- }
- if (his_state_is_will(TELOPT_OLD_ENVIRON)) {
- while (sequenceIs(oenvironsubopt, baseline))
- ttloop();
- }
- if (his_state_is_will(TELOPT_TTYPE)) {
- char first[256], last[256];
-
- while (sequenceIs(ttypesubopt, baseline))
- ttloop();
-
- /*
- * If the other side has already disabled the option, then
- * we have to just go with what we (might) have already gotten.
- */
- if (his_state_is_will(TELOPT_TTYPE) && !terminaltypeok(terminaltype)) {
- (void) strncpy(first, terminaltype, sizeof(first)-1);
- first[sizeof(first)-1] = '\0';
- for(;;) {
- /*
- * Save the unknown name, and request the next name.
- */
- (void) strncpy(last, terminaltype, sizeof(last)-1);
- last[sizeof(last)-1] = '\0';
- _gettermname();
- if (terminaltypeok(terminaltype))
- break;
- if ((strncmp(last, terminaltype, sizeof(last)) == 0) ||
- his_state_is_wont(TELOPT_TTYPE)) {
- /*
- * We've hit the end. If this is the same as
- * the first name, just go with it.
- */
- if (strncmp(first, terminaltype, sizeof(first)) == 0)
- break;
- /*
- * Get the terminal name one more time, so that
- * RFC1091 compliant telnets will cycle back to
- * the start of the list.
- */
- _gettermname();
- if (strncmp(first, terminaltype, sizeof(first)) != 0) {
- (void) strncpy(terminaltype, first, sizeof(terminaltype)-1);
- terminaltype[sizeof(terminaltype)-1] = '\0';
- }
- break;
- }
- }
- }
- }
- return(retval);
-} /* end of getterminaltype */
-
-static void
-_gettermname(void)
-{
- /*
- * If the client turned off the option,
- * we can't send another request, so we
- * just return.
- */
- if (his_state_is_wont(TELOPT_TTYPE))
- return;
- settimer(baseline);
- output_datalen(ttytype_sbbuf, sizeof ttytype_sbbuf);
- DIAG(TD_OPTIONS, printsub('>', ttytype_sbbuf + 2,
- sizeof ttytype_sbbuf - 2););
- while (sequenceIs(ttypesubopt, baseline))
- ttloop();
-}
-
-int
-terminaltypeok(char *s)
-{
- char buf[1024];
-
- if (terminaltype == NULL)
- return(1);
-
- /*
- * tgetent() will return 1 if the type is known, and
- * 0 if it is not known. If it returns -1, it couldn't
- * open the database. But if we can't open the database,
- * it won't help to say we failed, because we won't be
- * able to verify anything else. So, we treat -1 like 1.
- */
- if (tgetent(buf, s) == 0)
- return(0);
- return(1);
-}
-
-/*
- * Get a pty, scan input lines.
- */
-void
-doit(struct sockaddr *who)
-{
- int err_; /* XXX */
- int ptynum;
-
- /*
- * Find an available pty to use.
- */
-#ifndef convex
- pty = getpty(&ptynum);
- if (pty < 0)
- fatal(net, "All network ports in use");
-#else
- for (;;) {
- char *lp;
-
- if ((lp = getpty()) == NULL)
- fatal(net, "Out of ptys");
-
- if ((pty = open(lp, 2)) >= 0) {
- strlcpy(line,lp,sizeof(line));
- line[5] = 't';
- break;
- }
- }
-#endif
-
- /* get name of connected client */
- if (realhostname_sa(remote_hostname, sizeof(remote_hostname) - 1,
- who, who->sa_len) == HOSTNAME_INVALIDADDR && registerd_host_only)
- fatal(net, "Couldn't resolve your address into a host name.\r\n\
- Please contact your net administrator");
- remote_hostname[sizeof(remote_hostname) - 1] = '\0';
-
- trimdomain(remote_hostname, UT_HOSTSIZE);
- if (!isdigit(remote_hostname[0]) && strlen(remote_hostname) > utmp_len)
- err_ = getnameinfo(who, who->sa_len, remote_hostname,
- sizeof(remote_hostname), NULL, 0,
- NI_NUMERICHOST|NI_WITHSCOPEID);
- /* XXX: do 'err_' check */
-
- (void) gethostname(host_name, sizeof(host_name) - 1);
- host_name[sizeof(host_name) - 1] = '\0';
- hostname = host_name;
-
-#ifdef AUTHENTICATION
-#ifdef ENCRYPTION
-/* The above #ifdefs should actually be "or"'ed, not "and"'ed.
- * This is a byproduct of needing "#ifdef" and not "#if defined()"
- * for unifdef. XXX MarkM
- */
- auth_encrypt_init(hostname, remote_hostname, "TELNETD", 1);
-#endif
-#endif
-
- init_env();
- /*
- * get terminal type.
- */
- *user_name = 0;
- level = getterminaltype(user_name);
- setenv("TERM", terminaltype ? terminaltype : "network", 1);
-
- telnet(net, pty, remote_hostname); /* begin server process */
-
- /*NOTREACHED*/
-} /* end of doit */
-
-/*
- * Main loop. Select from pty and network, and
- * hand data to telnet receiver finite state machine.
- */
-void
-telnet(int f, int p, char *host)
-{
- int on = 1;
-#define TABBUFSIZ 512
- char defent[TABBUFSIZ];
- char defstrs[TABBUFSIZ];
-#undef TABBUFSIZ
- char *HE;
- char *HN;
- char *IM;
- int nfd;
-
- /*
- * Initialize the slc mapping table.
- */
- get_slc_defaults();
-
- /*
- * Do some tests where it is desireable to wait for a response.
- * Rather than doing them slowly, one at a time, do them all
- * at once.
- */
- if (my_state_is_wont(TELOPT_SGA))
- send_will(TELOPT_SGA, 1);
- /*
- * Is the client side a 4.2 (NOT 4.3) system? We need to know this
- * because 4.2 clients are unable to deal with TCP urgent data.
- *
- * To find out, we send out a "DO ECHO". If the remote system
- * answers "WILL ECHO" it is probably a 4.2 client, and we note
- * that fact ("WILL ECHO" ==> that the client will echo what
- * WE, the server, sends it; it does NOT mean that the client will
- * echo the terminal input).
- */
- send_do(TELOPT_ECHO, 1);
-
-#ifdef LINEMODE
- if (his_state_is_wont(TELOPT_LINEMODE)) {
- /* Query the peer for linemode support by trying to negotiate
- * the linemode option.
- */
- linemode = 0;
- editmode = 0;
- send_do(TELOPT_LINEMODE, 1); /* send do linemode */
- }
-#endif /* LINEMODE */
-
- /*
- * Send along a couple of other options that we wish to negotiate.
- */
- send_do(TELOPT_NAWS, 1);
- send_will(TELOPT_STATUS, 1);
- flowmode = 1; /* default flow control state */
- restartany = -1; /* uninitialized... */
- send_do(TELOPT_LFLOW, 1);
-
- /*
- * Spin, waiting for a response from the DO ECHO. However,
- * some REALLY DUMB telnets out there might not respond
- * to the DO ECHO. So, we spin looking for NAWS, (most dumb
- * telnets so far seem to respond with WONT for a DO that
- * they don't understand...) because by the time we get the
- * response, it will already have processed the DO ECHO.
- * Kludge upon kludge.
- */
- while (his_will_wont_is_changing(TELOPT_NAWS))
- ttloop();
-
- /*
- * But...
- * The client might have sent a WILL NAWS as part of its
- * startup code; if so, we'll be here before we get the
- * response to the DO ECHO. We'll make the assumption
- * that any implementation that understands about NAWS
- * is a modern enough implementation that it will respond
- * to our DO ECHO request; hence we'll do another spin
- * waiting for the ECHO option to settle down, which is
- * what we wanted to do in the first place...
- */
- if (his_want_state_is_will(TELOPT_ECHO) &&
- his_state_is_will(TELOPT_NAWS)) {
- while (his_will_wont_is_changing(TELOPT_ECHO))
- ttloop();
- }
- /*
- * On the off chance that the telnet client is broken and does not
- * respond to the DO ECHO we sent, (after all, we did send the
- * DO NAWS negotiation after the DO ECHO, and we won't get here
- * until a response to the DO NAWS comes back) simulate the
- * receipt of a will echo. This will also send a WONT ECHO
- * to the client, since we assume that the client failed to
- * respond because it believes that it is already in DO ECHO
- * mode, which we do not want.
- */
- if (his_want_state_is_will(TELOPT_ECHO)) {
- DIAG(TD_OPTIONS, output_data("td: simulating recv\r\n"));
- willoption(TELOPT_ECHO);
- }
-
- /*
- * Finally, to clean things up, we turn on our echo. This
- * will break stupid 4.2 telnets out of local terminal echo.
- */
-
- if (my_state_is_wont(TELOPT_ECHO))
- send_will(TELOPT_ECHO, 1);
-
- /*
- * Turn on packet mode
- */
- (void) ioctl(p, TIOCPKT, (char *)&on);
-
-#if defined(LINEMODE) && defined(KLUDGELINEMODE)
- /*
- * Continuing line mode support. If client does not support
- * real linemode, attempt to negotiate kludge linemode by sending
- * the do timing mark sequence.
- */
- if (lmodetype < REAL_LINEMODE)
- send_do(TELOPT_TM, 1);
-#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
-
- /*
- * Call telrcv() once to pick up anything received during
- * terminal type negotiation, 4.2/4.3 determination, and
- * linemode negotiation.
- */
- telrcv();
-
- (void) ioctl(f, FIONBIO, (char *)&on);
- (void) ioctl(p, FIONBIO, (char *)&on);
-
-#if defined(SO_OOBINLINE)
- (void) setsockopt(net, SOL_SOCKET, SO_OOBINLINE,
- (char *)&on, sizeof on);
-#endif /* defined(SO_OOBINLINE) */
-
-#ifdef SIGTSTP
- (void) signal(SIGTSTP, SIG_IGN);
-#endif
-#ifdef SIGTTOU
- /*
- * Ignoring SIGTTOU keeps the kernel from blocking us
- * in ttioct() in /sys/tty.c.
- */
- (void) signal(SIGTTOU, SIG_IGN);
-#endif
-
- (void) signal(SIGCHLD, cleanup);
-
-#ifdef TIOCNOTTY
- {
- int t;
- t = open(_PATH_TTY, O_RDWR);
- if (t >= 0) {
- (void) ioctl(t, TIOCNOTTY, (char *)0);
- (void) close(t);
- }
- }
-#endif
-
- /*
- * Show banner that getty never gave.
- *
- * We put the banner in the pty input buffer. This way, it
- * gets carriage return null processing, etc., just like all
- * other pty --> client data.
- */
-
- if (getent(defent, "default") == 1) {
- char *cp=defstrs;
-
- HE = Getstr("he", &cp);
- HN = Getstr("hn", &cp);
- IM = Getstr("im", &cp);
- if (HN && *HN)
- (void) strlcpy(host_name, HN, sizeof(host_name));
- if (IM == 0)
- IM = strdup("");
- } else {
- IM = strdup(DEFAULT_IM);
- HE = 0;
- }
- edithost(HE, host_name);
- if (hostinfo && *IM)
- putf(IM, ptyibuf2);
-
- if (pcc)
- (void) strncat(ptyibuf2, ptyip, pcc+1);
- ptyip = ptyibuf2;
- pcc = strlen(ptyip);
-#ifdef LINEMODE
- /*
- * Last check to make sure all our states are correct.
- */
- init_termbuf();
- localstat();
-#endif /* LINEMODE */
-
- DIAG(TD_REPORT, output_data("td: Entering processing loop\r\n"));
-
- /*
- * Startup the login process on the slave side of the terminal
- * now. We delay this until here to insure option negotiation
- * is complete.
- */
- startslave(host, level, user_name);
-
- nfd = ((f > p) ? f : p) + 1;
- for (;;) {
- fd_set ibits, obits, xbits;
- int c;
-
- if (ncc < 0 && pcc < 0)
- break;
-
- FD_ZERO(&ibits);
- FD_ZERO(&obits);
- FD_ZERO(&xbits);
- /*
- * Never look for input if there's still
- * stuff in the corresponding output buffer
- */
- if (nfrontp - nbackp || pcc > 0) {
- FD_SET(f, &obits);
- } else {
- FD_SET(p, &ibits);
- }
- if (pfrontp - pbackp || ncc > 0) {
- FD_SET(p, &obits);
- } else {
- FD_SET(f, &ibits);
- }
- if (!SYNCHing) {
- FD_SET(f, &xbits);
- }
- if ((c = select(nfd, &ibits, &obits, &xbits,
- (struct timeval *)0)) < 1) {
- if (c == -1) {
- if (errno == EINTR) {
- continue;
- }
- }
- sleep(5);
- continue;
- }
-
- /*
- * Any urgent data?
- */
- if (FD_ISSET(net, &xbits)) {
- SYNCHing = 1;
- }
-
- /*
- * Something to read from the network...
- */
- if (FD_ISSET(net, &ibits)) {
-#if !defined(SO_OOBINLINE)
- /*
- * In 4.2 (and 4.3 beta) systems, the
- * OOB indication and data handling in the kernel
- * is such that if two separate TCP Urgent requests
- * come in, one byte of TCP data will be overlaid.
- * This is fatal for Telnet, but we try to live
- * with it.
- *
- * In addition, in 4.2 (and...), a special protocol
- * is needed to pick up the TCP Urgent data in
- * the correct sequence.
- *
- * What we do is: if we think we are in urgent
- * mode, we look to see if we are "at the mark".
- * If we are, we do an OOB receive. If we run
- * this twice, we will do the OOB receive twice,
- * but the second will fail, since the second
- * time we were "at the mark", but there wasn't
- * any data there (the kernel doesn't reset
- * "at the mark" until we do a normal read).
- * Once we've read the OOB data, we go ahead
- * and do normal reads.
- *
- * There is also another problem, which is that
- * since the OOB byte we read doesn't put us
- * out of OOB state, and since that byte is most
- * likely the TELNET DM (data mark), we would
- * stay in the TELNET SYNCH (SYNCHing) state.
- * So, clocks to the rescue. If we've "just"
- * received a DM, then we test for the
- * presence of OOB data when the receive OOB
- * fails (and AFTER we did the normal mode read
- * to clear "at the mark").
- */
- if (SYNCHing) {
- int atmark;
-
- (void) ioctl(net, SIOCATMARK, (char *)&atmark);
- if (atmark) {
- ncc = recv(net, netibuf, sizeof (netibuf), MSG_OOB);
- if ((ncc == -1) && (errno == EINVAL)) {
- ncc = read(net, netibuf, sizeof (netibuf));
- if (sequenceIs(didnetreceive, gotDM)) {
- SYNCHing = stilloob(net);
- }
- }
- } else {
- ncc = read(net, netibuf, sizeof (netibuf));
- }
- } else {
- ncc = read(net, netibuf, sizeof (netibuf));
- }
- settimer(didnetreceive);
-#else /* !defined(SO_OOBINLINE)) */
- ncc = read(net, netibuf, sizeof (netibuf));
-#endif /* !defined(SO_OOBINLINE)) */
- if (ncc < 0 && errno == EWOULDBLOCK)
- ncc = 0;
- else {
- if (ncc <= 0) {
- break;
- }
- netip = netibuf;
- }
- DIAG((TD_REPORT | TD_NETDATA),
- output_data("td: netread %d chars\r\n", ncc));
- DIAG(TD_NETDATA, printdata("nd", netip, ncc));
- }
-
- /*
- * Something to read from the pty...
- */
- if (FD_ISSET(p, &ibits)) {
- pcc = read(p, ptyibuf, BUFSIZ);
- /*
- * On some systems, if we try to read something
- * off the master side before the slave side is
- * opened, we get EIO.
- */
- if (pcc < 0 && (errno == EWOULDBLOCK ||
-#ifdef EAGAIN
- errno == EAGAIN ||
-#endif
- errno == EIO)) {
- pcc = 0;
- } else {
- if (pcc <= 0)
- break;
-#ifdef LINEMODE
- /*
- * If ioctl from pty, pass it through net
- */
- if (ptyibuf[0] & TIOCPKT_IOCTL) {
- copy_termbuf(ptyibuf+1, pcc-1);
- localstat();
- pcc = 1;
- }
-#endif /* LINEMODE */
- if (ptyibuf[0] & TIOCPKT_FLUSHWRITE) {
- netclear(); /* clear buffer back */
-#ifndef NO_URGENT
- /*
- * There are client telnets on some
- * operating systems get screwed up
- * royally if we send them urgent
- * mode data.
- */
- output_data("%c%c", IAC, DM);
- neturg = nfrontp-1; /* off by one XXX */
- DIAG(TD_OPTIONS,
- printoption("td: send IAC", DM));
-
-#endif
- }
- if (his_state_is_will(TELOPT_LFLOW) &&
- (ptyibuf[0] &
- (TIOCPKT_NOSTOP|TIOCPKT_DOSTOP))) {
- int newflow =
- ptyibuf[0] & TIOCPKT_DOSTOP ? 1 : 0;
- if (newflow != flowmode) {
- flowmode = newflow;
- output_data("%c%c%c%c%c%c",
- IAC, SB, TELOPT_LFLOW,
- flowmode ? LFLOW_ON
- : LFLOW_OFF,
- IAC, SE);
- DIAG(TD_OPTIONS, printsub('>',
- (unsigned char *)nfrontp-4,
- 4););
- }
- }
- pcc--;
- ptyip = ptyibuf+1;
- }
- }
-
- while (pcc > 0) {
- if ((&netobuf[BUFSIZ] - nfrontp) < 2)
- break;
- c = *ptyip++ & 0377, pcc--;
- if (c == IAC)
- output_data("%c", c);
- output_data("%c", c);
- if ((c == '\r') && (my_state_is_wont(TELOPT_BINARY))) {
- if (pcc > 0 && ((*ptyip & 0377) == '\n')) {
- output_data("%c", *ptyip++ & 0377);
- pcc--;
- } else
- output_data("%c", '\0');
- }
- }
-
- if (FD_ISSET(f, &obits) && (nfrontp - nbackp) > 0)
- netflush();
- if (ncc > 0)
- telrcv();
- if (FD_ISSET(p, &obits) && (pfrontp - pbackp) > 0)
- ptyflush();
- }
- cleanup(0);
-} /* end of telnet */
-
-#ifndef TCSIG
-# ifdef TIOCSIG
-# define TCSIG TIOCSIG
-# endif
-#endif
-
-/*
- * Send interrupt to process on other side of pty.
- * If it is in raw mode, just write NULL;
- * otherwise, write intr char.
- */
-void
-interrupt(void)
-{
- ptyflush(); /* half-hearted */
-
-#ifdef TCSIG
- (void) ioctl(pty, TCSIG, (char *)SIGINT);
-#else /* TCSIG */
- init_termbuf();
- *pfrontp++ = slctab[SLC_IP].sptr ?
- (unsigned char)*slctab[SLC_IP].sptr : '\177';
-#endif /* TCSIG */
-}
-
-/*
- * Send quit to process on other side of pty.
- * If it is in raw mode, just write NULL;
- * otherwise, write quit char.
- */
-void
-sendbrk(void)
-{
- ptyflush(); /* half-hearted */
-#ifdef TCSIG
- (void) ioctl(pty, TCSIG, (char *)SIGQUIT);
-#else /* TCSIG */
- init_termbuf();
- *pfrontp++ = slctab[SLC_ABORT].sptr ?
- (unsigned char)*slctab[SLC_ABORT].sptr : '\034';
-#endif /* TCSIG */
-}
-
-void
-sendsusp(void)
-{
-#ifdef SIGTSTP
- ptyflush(); /* half-hearted */
-# ifdef TCSIG
- (void) ioctl(pty, TCSIG, (char *)SIGTSTP);
-# else /* TCSIG */
- *pfrontp++ = slctab[SLC_SUSP].sptr ?
- (unsigned char)*slctab[SLC_SUSP].sptr : '\032';
-# endif /* TCSIG */
-#endif /* SIGTSTP */
-}
-
-/*
- * When we get an AYT, if ^T is enabled, use that. Otherwise,
- * just send back "[Yes]".
- */
-void
-recv_ayt(void)
-{
-#if defined(SIGINFO) && defined(TCSIG)
- if (slctab[SLC_AYT].sptr && *slctab[SLC_AYT].sptr != _POSIX_VDISABLE) {
- (void) ioctl(pty, TCSIG, (char *)SIGINFO);
- return;
- }
-#endif
- output_data("\r\n[Yes]\r\n");
-}
-
-void
-doeof(void)
-{
- init_termbuf();
-
-#if defined(LINEMODE) && defined(USE_TERMIO) && (VEOF == VMIN)
- if (!tty_isediting()) {
- extern char oldeofc;
- *pfrontp++ = oldeofc;
- return;
- }
-#endif
- *pfrontp++ = slctab[SLC_EOF].sptr ?
- (unsigned char)*slctab[SLC_EOF].sptr : '\004';
-}
diff --git a/contrib/telnet/telnetd/telnetd.h b/contrib/telnet/telnetd/telnetd.h
deleted file mode 100644
index 5bfc572f518d..000000000000
--- a/contrib/telnet/telnetd/telnetd.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)telnetd.h 8.1 (Berkeley) 6/4/93
- * $FreeBSD$
- */
-
-
-#include "defs.h"
-#include "ext.h"
-
-#ifdef DIAGNOSTICS
-#define DIAG(a,b) if (diagnostic & (a)) b
-#else
-#define DIAG(a,b)
-#endif
-
-/* other external variables */
-extern char **environ;
-extern const char *altlogin;
diff --git a/contrib/telnet/telnetd/termstat.c b/contrib/telnet/telnetd/termstat.c
deleted file mode 100644
index 36f599722308..000000000000
--- a/contrib/telnet/telnetd/termstat.c
+++ /dev/null
@@ -1,632 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)termstat.c 8.2 (Berkeley) 5/30/95";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "telnetd.h"
-
-#ifdef ENCRYPTION
-#include <libtelnet/encrypt.h>
-#endif
-
-/*
- * local variables
- */
-int def_tspeed = -1, def_rspeed = -1;
-#ifdef TIOCSWINSZ
-int def_row = 0, def_col = 0;
-#endif
-#ifdef LINEMODE
-static int _terminit = 0;
-#endif /* LINEMODE */
-
-#ifdef LINEMODE
-/*
- * localstat
- *
- * This function handles all management of linemode.
- *
- * Linemode allows the client to do the local editing of data
- * and send only complete lines to the server. Linemode state is
- * based on the state of the pty driver. If the pty is set for
- * external processing, then we can use linemode. Further, if we
- * can use real linemode, then we can look at the edit control bits
- * in the pty to determine what editing the client should do.
- *
- * Linemode support uses the following state flags to keep track of
- * current and desired linemode state.
- * alwayslinemode : true if -l was specified on the telnetd
- * command line. It means to have linemode on as much as
- * possible.
- *
- * lmodetype: signifies whether the client can
- * handle real linemode, or if use of kludgeomatic linemode
- * is preferred. It will be set to one of the following:
- * REAL_LINEMODE : use linemode option
- * NO_KLUDGE : don't initiate kludge linemode.
- * KLUDGE_LINEMODE : use kludge linemode
- * NO_LINEMODE : client is ignorant of linemode
- *
- * linemode, uselinemode : linemode is true if linemode
- * is currently on, uselinemode is the state that we wish
- * to be in. If another function wishes to turn linemode
- * on or off, it sets or clears uselinemode.
- *
- * editmode, useeditmode : like linemode/uselinemode, but
- * these contain the edit mode states (edit and trapsig).
- *
- * The state variables correspond to some of the state information
- * in the pty.
- * linemode:
- * In real linemode, this corresponds to whether the pty
- * expects external processing of incoming data.
- * In kludge linemode, this more closely corresponds to the
- * whether normal processing is on or not. (ICANON in
- * system V, or COOKED mode in BSD.)
- * If the -l option was specified (alwayslinemode), then
- * an attempt is made to force external processing on at
- * all times.
- *
- * The following heuristics are applied to determine linemode
- * handling within the server.
- * 1) Early on in starting up the server, an attempt is made
- * to negotiate the linemode option. If this succeeds
- * then lmodetype is set to REAL_LINEMODE and all linemode
- * processing occurs in the context of the linemode option.
- * 2) If the attempt to negotiate the linemode option failed,
- * and the "-k" (don't initiate kludge linemode) isn't set,
- * then we try to use kludge linemode. We test for this
- * capability by sending "do Timing Mark". If a positive
- * response comes back, then we assume that the client
- * understands kludge linemode (ech!) and the
- * lmodetype flag is set to KLUDGE_LINEMODE.
- * 3) Otherwise, linemode is not supported at all and
- * lmodetype remains set to NO_LINEMODE (which happens
- * to be 0 for convenience).
- * 4) At any time a command arrives that implies a higher
- * state of linemode support in the client, we move to that
- * linemode support.
- *
- * A short explanation of kludge linemode is in order here.
- * 1) The heuristic to determine support for kludge linemode
- * is to send a do timing mark. We assume that a client
- * that supports timing marks also supports kludge linemode.
- * A risky proposition at best.
- * 2) Further negotiation of linemode is done by changing the
- * the server's state regarding SGA. If server will SGA,
- * then linemode is off, if server won't SGA, then linemode
- * is on.
- */
-void
-localstat(void)
-{
- int need_will_echo = 0;
-
- /*
- * Check for changes to flow control if client supports it.
- */
- flowstat();
-
- /*
- * Check linemode on/off state
- */
- uselinemode = tty_linemode();
-
- /*
- * If alwayslinemode is on, and pty is changing to turn it off, then
- * force linemode back on.
- */
- if (alwayslinemode && linemode && !uselinemode) {
- uselinemode = 1;
- tty_setlinemode(uselinemode);
- }
-
- if (uselinemode) {
- /*
- * Check for state of BINARY options.
- *
- * We only need to do the binary dance if we are actually going
- * to use linemode. As this confuses some telnet clients
- * that don't support linemode, and doesn't gain us
- * anything, we don't do it unless we're doing linemode.
- * -Crh (henrich@msu.edu)
- */
-
- if (tty_isbinaryin()) {
- if (his_want_state_is_wont(TELOPT_BINARY))
- send_do(TELOPT_BINARY, 1);
- } else {
- if (his_want_state_is_will(TELOPT_BINARY))
- send_dont(TELOPT_BINARY, 1);
- }
-
- if (tty_isbinaryout()) {
- if (my_want_state_is_wont(TELOPT_BINARY))
- send_will(TELOPT_BINARY, 1);
- } else {
- if (my_want_state_is_will(TELOPT_BINARY))
- send_wont(TELOPT_BINARY, 1);
- }
- }
-
-#ifdef ENCRYPTION
- /*
- * If the terminal is not echoing, but editing is enabled,
- * something like password input is going to happen, so
- * if we the other side is not currently sending encrypted
- * data, ask the other side to start encrypting.
- */
- if (his_state_is_will(TELOPT_ENCRYPT)) {
- static int enc_passwd = 0;
- if (uselinemode && !tty_isecho() && tty_isediting()
- && (enc_passwd == 0) && !decrypt_input) {
- encrypt_send_request_start();
- enc_passwd = 1;
- } else if (enc_passwd) {
- encrypt_send_request_end();
- enc_passwd = 0;
- }
- }
-#endif /* ENCRYPTION */
-
- /*
- * Do echo mode handling as soon as we know what the
- * linemode is going to be.
- * If the pty has echo turned off, then tell the client that
- * the server will echo. If echo is on, then the server
- * will echo if in character mode, but in linemode the
- * client should do local echoing. The state machine will
- * not send anything if it is unnecessary, so don't worry
- * about that here.
- *
- * If we need to send the WILL ECHO (because echo is off),
- * then delay that until after we have changed the MODE.
- * This way, when the user is turning off both editing
- * and echo, the client will get editing turned off first.
- * This keeps the client from going into encryption mode
- * and then right back out if it is doing auto-encryption
- * when passwords are being typed.
- */
- if (uselinemode) {
- if (tty_isecho())
- send_wont(TELOPT_ECHO, 1);
- else
- need_will_echo = 1;
-#ifdef KLUDGELINEMODE
- if (lmodetype == KLUDGE_OK)
- lmodetype = KLUDGE_LINEMODE;
-#endif
- }
-
- /*
- * If linemode is being turned off, send appropriate
- * command and then we're all done.
- */
- if (!uselinemode && linemode) {
-# ifdef KLUDGELINEMODE
- if (lmodetype == REAL_LINEMODE) {
-# endif /* KLUDGELINEMODE */
- send_dont(TELOPT_LINEMODE, 1);
-# ifdef KLUDGELINEMODE
- } else if (lmodetype == KLUDGE_LINEMODE)
- send_will(TELOPT_SGA, 1);
-# endif /* KLUDGELINEMODE */
- send_will(TELOPT_ECHO, 1);
- linemode = uselinemode;
- goto done;
- }
-
-# ifdef KLUDGELINEMODE
- /*
- * If using real linemode check edit modes for possible later use.
- * If we are in kludge linemode, do the SGA negotiation.
- */
- if (lmodetype == REAL_LINEMODE) {
-# endif /* KLUDGELINEMODE */
- useeditmode = 0;
- if (tty_isediting())
- useeditmode |= MODE_EDIT;
- if (tty_istrapsig())
- useeditmode |= MODE_TRAPSIG;
- if (tty_issofttab())
- useeditmode |= MODE_SOFT_TAB;
- if (tty_islitecho())
- useeditmode |= MODE_LIT_ECHO;
-# ifdef KLUDGELINEMODE
- } else if (lmodetype == KLUDGE_LINEMODE) {
- if (tty_isediting() && uselinemode)
- send_wont(TELOPT_SGA, 1);
- else
- send_will(TELOPT_SGA, 1);
- }
-# endif /* KLUDGELINEMODE */
-
- /*
- * Negotiate linemode on if pty state has changed to turn it on.
- * Send appropriate command and send along edit mode, then all done.
- */
- if (uselinemode && !linemode) {
-# ifdef KLUDGELINEMODE
- if (lmodetype == KLUDGE_LINEMODE) {
- send_wont(TELOPT_SGA, 1);
- } else if (lmodetype == REAL_LINEMODE) {
-# endif /* KLUDGELINEMODE */
- send_do(TELOPT_LINEMODE, 1);
- /* send along edit modes */
- output_data("%c%c%c%c%c%c%c", IAC, SB,
- TELOPT_LINEMODE, LM_MODE, useeditmode,
- IAC, SE);
- editmode = useeditmode;
-# ifdef KLUDGELINEMODE
- }
-# endif /* KLUDGELINEMODE */
- linemode = uselinemode;
- goto done;
- }
-
-# ifdef KLUDGELINEMODE
- /*
- * None of what follows is of any value if not using
- * real linemode.
- */
- if (lmodetype < REAL_LINEMODE)
- goto done;
-# endif /* KLUDGELINEMODE */
-
- if (linemode && his_state_is_will(TELOPT_LINEMODE)) {
- /*
- * If edit mode changed, send edit mode.
- */
- if (useeditmode != editmode) {
- /*
- * Send along appropriate edit mode mask.
- */
- output_data("%c%c%c%c%c%c%c", IAC, SB,
- TELOPT_LINEMODE, LM_MODE, useeditmode,
- IAC, SE);
- editmode = useeditmode;
- }
-
-
- /*
- * Check for changes to special characters in use.
- */
- start_slc(0);
- check_slc();
- (void) end_slc(0);
- }
-
-done:
- if (need_will_echo)
- send_will(TELOPT_ECHO, 1);
- /*
- * Some things should be deferred until after the pty state has
- * been set by the local process. Do those things that have been
- * deferred now. This only happens once.
- */
- if (_terminit == 0) {
- _terminit = 1;
- defer_terminit();
- }
-
- netflush();
- set_termbuf();
- return;
-
-} /* end of localstat */
-#endif /* LINEMODE */
-
-/*
- * flowstat
- *
- * Check for changes to flow control
- */
-void
-flowstat(void)
-{
- if (his_state_is_will(TELOPT_LFLOW)) {
- if (tty_flowmode() != flowmode) {
- flowmode = tty_flowmode();
- output_data("%c%c%c%c%c%c",
- IAC, SB, TELOPT_LFLOW,
- flowmode ? LFLOW_ON : LFLOW_OFF,
- IAC, SE);
- }
- if (tty_restartany() != restartany) {
- restartany = tty_restartany();
- output_data("%c%c%c%c%c%c",
- IAC, SB, TELOPT_LFLOW,
- restartany ? LFLOW_RESTART_ANY
- : LFLOW_RESTART_XON,
- IAC, SE);
- }
- }
-}
-
-/*
- * clientstat
- *
- * Process linemode related requests from the client.
- * Client can request a change to only one of linemode, editmode or slc's
- * at a time, and if using kludge linemode, then only linemode may be
- * affected.
- */
-void
-clientstat(int code, int parm1, int parm2)
-{
-
- /*
- * Get a copy of terminal characteristics.
- */
- init_termbuf();
-
- /*
- * Process request from client. code tells what it is.
- */
- switch (code) {
-#ifdef LINEMODE
- case TELOPT_LINEMODE:
- /*
- * Don't do anything unless client is asking us to change
- * modes.
- */
- uselinemode = (parm1 == WILL);
- if (uselinemode != linemode) {
-# ifdef KLUDGELINEMODE
- /*
- * If using kludge linemode, make sure that
- * we can do what the client asks.
- * We can not turn off linemode if alwayslinemode
- * and the ICANON bit is set.
- */
- if (lmodetype == KLUDGE_LINEMODE) {
- if (alwayslinemode && tty_isediting()) {
- uselinemode = 1;
- }
- }
-
- /*
- * Quit now if we can't do it.
- */
- if (uselinemode == linemode)
- return;
-
- /*
- * If using real linemode and linemode is being
- * turned on, send along the edit mode mask.
- */
- if (lmodetype == REAL_LINEMODE && uselinemode)
-# else /* KLUDGELINEMODE */
- if (uselinemode)
-# endif /* KLUDGELINEMODE */
- {
- useeditmode = 0;
- if (tty_isediting())
- useeditmode |= MODE_EDIT;
- if (tty_istrapsig)
- useeditmode |= MODE_TRAPSIG;
- if (tty_issofttab())
- useeditmode |= MODE_SOFT_TAB;
- if (tty_islitecho())
- useeditmode |= MODE_LIT_ECHO;
- output_data("%c%c%c%c%c%c%c", IAC,
- SB, TELOPT_LINEMODE, LM_MODE,
- useeditmode, IAC, SE);
- editmode = useeditmode;
- }
-
-
- tty_setlinemode(uselinemode);
-
- linemode = uselinemode;
-
- if (!linemode)
- send_will(TELOPT_ECHO, 1);
- }
- break;
-
- case LM_MODE:
- {
- int ack, changed;
-
- /*
- * Client has sent along a mode mask. If it agrees with
- * what we are currently doing, ignore it; if not, it could
- * be viewed as a request to change. Note that the server
- * will change to the modes in an ack if it is different from
- * what we currently have, but we will not ack the ack.
- */
- useeditmode &= MODE_MASK;
- ack = (useeditmode & MODE_ACK);
- useeditmode &= ~MODE_ACK;
-
- if ((changed = (useeditmode ^ editmode))) {
- /*
- * This check is for a timing problem. If the
- * state of the tty has changed (due to the user
- * application) we need to process that info
- * before we write in the state contained in the
- * ack!!! This gets out the new MODE request,
- * and when the ack to that command comes back
- * we'll set it and be in the right mode.
- */
- if (ack)
- localstat();
- if (changed & MODE_EDIT)
- tty_setedit(useeditmode & MODE_EDIT);
-
- if (changed & MODE_TRAPSIG)
- tty_setsig(useeditmode & MODE_TRAPSIG);
-
- if (changed & MODE_SOFT_TAB)
- tty_setsofttab(useeditmode & MODE_SOFT_TAB);
-
- if (changed & MODE_LIT_ECHO)
- tty_setlitecho(useeditmode & MODE_LIT_ECHO);
-
- set_termbuf();
-
- if (!ack) {
- output_data("%c%c%c%c%c%c%c", IAC,
- SB, TELOPT_LINEMODE, LM_MODE,
- useeditmode|MODE_ACK,
- IAC, SE);
- }
-
- editmode = useeditmode;
- }
-
- break;
-
- } /* end of case LM_MODE */
-#endif /* LINEMODE */
-
- case TELOPT_NAWS:
-#ifdef TIOCSWINSZ
- {
- struct winsize ws;
-
- def_col = parm1;
- def_row = parm2;
-#ifdef LINEMODE
- /*
- * Defer changing window size until after terminal is
- * initialized.
- */
- if (terminit() == 0)
- return;
-#endif /* LINEMODE */
-
- /*
- * Change window size as requested by client.
- */
-
- ws.ws_col = parm1;
- ws.ws_row = parm2;
- (void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
- }
-#endif /* TIOCSWINSZ */
-
- break;
-
- case TELOPT_TSPEED:
- {
- def_tspeed = parm1;
- def_rspeed = parm2;
-#ifdef LINEMODE
- /*
- * Defer changing the terminal speed.
- */
- if (terminit() == 0)
- return;
-#endif /* LINEMODE */
- /*
- * Change terminal speed as requested by client.
- * We set the receive speed first, so that if we can't
- * store separate receive and transmit speeds, the transmit
- * speed will take precedence.
- */
- tty_rspeed(parm2);
- tty_tspeed(parm1);
- set_termbuf();
-
- break;
-
- } /* end of case TELOPT_TSPEED */
-
- default:
- /* What? */
- break;
- } /* end of switch */
-
- netflush();
-
-} /* end of clientstat */
-
-#ifdef LINEMODE
-/*
- * defer_terminit
- *
- * Some things should not be done until after the login process has started
- * and all the pty modes are set to what they are supposed to be. This
- * function is called when the pty state has been processed for the first time.
- * It calls other functions that do things that were deferred in each module.
- */
-void
-defer_terminit(void)
-{
-
- /*
- * local stuff that got deferred.
- */
- if (def_tspeed != -1) {
- clientstat(TELOPT_TSPEED, def_tspeed, def_rspeed);
- def_tspeed = def_rspeed = 0;
- }
-
-#ifdef TIOCSWINSZ
- if (def_col || def_row) {
- struct winsize ws;
-
- memset((char *)&ws, 0, sizeof(ws));
- ws.ws_col = def_col;
- ws.ws_row = def_row;
- (void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
- }
-#endif
-
- /*
- * The only other module that currently defers anything.
- */
- deferslc();
-
-} /* end of defer_terminit */
-
-/*
- * terminit
- *
- * Returns true if the pty state has been processed yet.
- */
-int
-terminit(void)
-{
- return(_terminit);
-
-} /* end of terminit */
-#endif /* LINEMODE */
diff --git a/contrib/telnet/telnetd/utility.c b/contrib/telnet/telnetd/utility.c
deleted file mode 100644
index 54e23270be18..000000000000
--- a/contrib/telnet/telnetd/utility.c
+++ /dev/null
@@ -1,1081 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static const char sccsid[] = "@(#)utility.c 8.4 (Berkeley) 5/30/95";
-#endif /* not lint */
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#ifdef __FreeBSD__
-#include <locale.h>
-#include <sys/utsname.h>
-#endif
-#include <string.h>
-#define PRINTOPTIONS
-#include "telnetd.h"
-
-#ifdef AUTHENTICATION
-#include <libtelnet/auth.h>
-#endif
-#ifdef ENCRYPTION
-#include <libtelnet/encrypt.h>
-#endif
-
-/*
- * utility functions performing io related tasks
- */
-
-/*
- * ttloop
- *
- * A small subroutine to flush the network output buffer, get some data
- * from the network, and pass it through the telnet state machine. We
- * also flush the pty input buffer (by dropping its data) if it becomes
- * too full.
- */
-
- void
-ttloop()
-{
-
- DIAG(TD_REPORT, output_data("td: ttloop\r\n"));
- if (nfrontp - nbackp > 0) {
- netflush();
- }
- ncc = read(net, netibuf, sizeof netibuf);
- if (ncc < 0) {
- syslog(LOG_INFO, "ttloop: read: %m");
- exit(1);
- } else if (ncc == 0) {
- syslog(LOG_INFO, "ttloop: peer died: %m");
- exit(1);
- }
- DIAG(TD_REPORT, output_data("td: ttloop read %d chars\r\n", ncc));
- netip = netibuf;
- telrcv(); /* state machine */
- if (ncc > 0) {
- pfrontp = pbackp = ptyobuf;
- telrcv();
- }
-} /* end of ttloop */
-
-/*
- * Check a descriptor to see if out of band data exists on it.
- */
-int
-stilloob(int s)
-{
- static struct timeval timeout = { 0, 0 };
- fd_set excepts;
- int value;
-
- do {
- FD_ZERO(&excepts);
- FD_SET(s, &excepts);
- memset((char *)&timeout, 0, sizeof timeout);
- value = select(s+1, (fd_set *)0, (fd_set *)0, &excepts, &timeout);
- } while ((value == -1) && (errno == EINTR));
-
- if (value < 0) {
- fatalperror(pty, "select");
- }
- if (FD_ISSET(s, &excepts)) {
- return 1;
- } else {
- return 0;
- }
-}
-
-void
-ptyflush(void)
-{
- int n;
-
- if ((n = pfrontp - pbackp) > 0) {
- DIAG(TD_REPORT | TD_PTYDATA,
- output_data("td: ptyflush %d chars\r\n", n));
- DIAG(TD_PTYDATA, printdata("pd", pbackp, n));
- n = write(pty, pbackp, n);
- }
- if (n < 0) {
- if (errno == EWOULDBLOCK || errno == EINTR)
- return;
- cleanup(0);
- }
- pbackp += n;
- if (pbackp == pfrontp)
- pbackp = pfrontp = ptyobuf;
-}
-
-/*
- * nextitem()
- *
- * Return the address of the next "item" in the TELNET data
- * stream. This will be the address of the next character if
- * the current address is a user data character, or it will
- * be the address of the character following the TELNET command
- * if the current address is a TELNET IAC ("I Am a Command")
- * character.
- */
-static char *
-nextitem(char *current)
-{
- if ((*current&0xff) != IAC) {
- return current+1;
- }
- switch (*(current+1)&0xff) {
- case DO:
- case DONT:
- case WILL:
- case WONT:
- return current+3;
- case SB: /* loop forever looking for the SE */
- {
- char *look = current+2;
-
- for (;;) {
- if ((*look++&0xff) == IAC) {
- if ((*look++&0xff) == SE) {
- return look;
- }
- }
- }
- }
- default:
- return current+2;
- }
-} /* end of nextitem */
-
-/*
- * netclear()
- *
- * We are about to do a TELNET SYNCH operation. Clear
- * the path to the network.
- *
- * Things are a bit tricky since we may have sent the first
- * byte or so of a previous TELNET command into the network.
- * So, we have to scan the network buffer from the beginning
- * until we are up to where we want to be.
- *
- * A side effect of what we do, just to keep things
- * simple, is to clear the urgent data pointer. The principal
- * caller should be setting the urgent data pointer AFTER calling
- * us in any case.
- */
-void
-netclear(void)
-{
- char *thisitem, *next;
- char *good;
-#define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \
- ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))
-
-#ifdef ENCRYPTION
- thisitem = nclearto > netobuf ? nclearto : netobuf;
-#else /* ENCRYPTION */
- thisitem = netobuf;
-#endif /* ENCRYPTION */
-
- while ((next = nextitem(thisitem)) <= nbackp) {
- thisitem = next;
- }
-
- /* Now, thisitem is first before/at boundary. */
-
-#ifdef ENCRYPTION
- good = nclearto > netobuf ? nclearto : netobuf;
-#else /* ENCRYPTION */
- good = netobuf; /* where the good bytes go */
-#endif /* ENCRYPTION */
-
- while (nfrontp > thisitem) {
- if (wewant(thisitem)) {
- int length;
-
- next = thisitem;
- do {
- next = nextitem(next);
- } while (wewant(next) && (nfrontp > next));
- length = next-thisitem;
- memmove(good, thisitem, length);
- good += length;
- thisitem = next;
- } else {
- thisitem = nextitem(thisitem);
- }
- }
-
- nbackp = netobuf;
- nfrontp = good; /* next byte to be sent */
- neturg = 0;
-} /* end of netclear */
-
-/*
- * netflush
- * Send as much data as possible to the network,
- * handling requests for urgent data.
- */
-void
-netflush(void)
-{
- int n;
- extern int not42;
-
- while ((n = nfrontp - nbackp) > 0) {
-#if 0
- /* XXX This causes output_data() to recurse and die */
- DIAG(TD_REPORT, {
- n += output_data("td: netflush %d chars\r\n", n);
- });
-#endif
-#ifdef ENCRYPTION
- if (encrypt_output) {
- char *s = nclearto ? nclearto : nbackp;
- if (nfrontp - s > 0) {
- (*encrypt_output)((unsigned char *)s, nfrontp-s);
- nclearto = nfrontp;
- }
- }
-#endif /* ENCRYPTION */
- /*
- * if no urgent data, or if the other side appears to be an
- * old 4.2 client (and thus unable to survive TCP urgent data),
- * write the entire buffer in non-OOB mode.
- */
- if ((neturg == 0) || (not42 == 0)) {
- n = write(net, nbackp, n); /* normal write */
- } else {
- n = neturg - nbackp;
- /*
- * In 4.2 (and 4.3) systems, there is some question about
- * what byte in a sendOOB operation is the "OOB" data.
- * To make ourselves compatible, we only send ONE byte
- * out of band, the one WE THINK should be OOB (though
- * we really have more the TCP philosophy of urgent data
- * rather than the Unix philosophy of OOB data).
- */
- if (n > 1) {
- n = send(net, nbackp, n-1, 0); /* send URGENT all by itself */
- } else {
- n = send(net, nbackp, n, MSG_OOB); /* URGENT data */
- }
- }
- if (n == -1) {
- if (errno == EWOULDBLOCK || errno == EINTR)
- continue;
- cleanup(0);
- /* NOTREACHED */
- }
- nbackp += n;
-#ifdef ENCRYPTION
- if (nbackp > nclearto)
- nclearto = 0;
-#endif /* ENCRYPTION */
- if (nbackp >= neturg) {
- neturg = 0;
- }
- if (nbackp == nfrontp) {
- nbackp = nfrontp = netobuf;
-#ifdef ENCRYPTION
- nclearto = 0;
-#endif /* ENCRYPTION */
- }
- }
- return;
-} /* end of netflush */
-
-
-/*
- * miscellaneous functions doing a variety of little jobs follow ...
- */
-
-
-void
-fatal(int f, const char *msg)
-{
- char buf[BUFSIZ];
-
- (void) snprintf(buf, sizeof(buf), "telnetd: %s.\r\n", msg);
-#ifdef ENCRYPTION
- if (encrypt_output) {
- /*
- * Better turn off encryption first....
- * Hope it flushes...
- */
- encrypt_send_end();
- netflush();
- }
-#endif /* ENCRYPTION */
- (void) write(f, buf, (int)strlen(buf));
- sleep(1); /*XXX*/
- exit(1);
-}
-
-void
-fatalperror(int f, const char *msg)
-{
- char buf[BUFSIZ];
-
- (void) snprintf(buf, sizeof(buf), "%s: %s", msg, strerror(errno));
- fatal(f, buf);
-}
-
-char editedhost[32];
-
-void
-edithost(char *pat, char *host)
-{
- char *res = editedhost;
-
- if (!pat)
- pat = strdup("");
- while (*pat) {
- switch (*pat) {
-
- case '#':
- if (*host)
- host++;
- break;
-
- case '@':
- if (*host)
- *res++ = *host++;
- break;
-
- default:
- *res++ = *pat;
- break;
- }
- if (res == &editedhost[sizeof editedhost - 1]) {
- *res = '\0';
- return;
- }
- pat++;
- }
- if (*host)
- (void) strncpy(res, host,
- sizeof editedhost - (res - editedhost) -1);
- else
- *res = '\0';
- editedhost[sizeof editedhost - 1] = '\0';
-}
-
-static char *putlocation;
-
-static void
-putstr(const char *s)
-{
-
- while (*s)
- putchr(*s++);
-}
-
-void
-putchr(int cc)
-{
- *putlocation++ = cc;
-}
-
-#ifdef __FreeBSD__
-static char fmtstr[] = { "%+" };
-#else
-static char fmtstr[] = { "%l:%M%P on %A, %d %B %Y" };
-#endif
-
-void
-putf(char *cp, char *where)
-{
- char *slash;
- time_t t;
- char db[100];
-#ifdef __FreeBSD__
- static struct utsname kerninfo;
-
- if (!*kerninfo.sysname)
- uname(&kerninfo);
-#endif
-
- putlocation = where;
-
- while (*cp) {
- if (*cp =='\n') {
- putstr("\r\n");
- cp++;
- continue;
- } else if (*cp != '%') {
- putchr(*cp++);
- continue;
- }
- switch (*++cp) {
-
- case 't':
-#ifdef STREAMSPTY
- /* names are like /dev/pts/2 -- we want pts/2 */
- slash = strchr(line+1, '/');
-#else
- slash = strrchr(line, '/');
-#endif
- if (slash == (char *) 0)
- putstr(line);
- else
- putstr(&slash[1]);
- break;
-
- case 'h':
- putstr(editedhost);
- break;
-
- case 'd':
-#ifdef __FreeBSD__
- setlocale(LC_TIME, "");
-#endif
- (void)time(&t);
- (void)strftime(db, sizeof(db), fmtstr, localtime(&t));
- putstr(db);
- break;
-
-#ifdef __FreeBSD__
- case 's':
- putstr(kerninfo.sysname);
- break;
-
- case 'm':
- putstr(kerninfo.machine);
- break;
-
- case 'r':
- putstr(kerninfo.release);
- break;
-
- case 'v':
- putstr(kerninfo.version);
- break;
-#endif
-
- case '%':
- putchr('%');
- break;
- }
- cp++;
- }
-}
-
-#ifdef DIAGNOSTICS
-/*
- * Print telnet options and commands in plain text, if possible.
- */
-void
-printoption(const char *fmt, int option)
-{
- if (TELOPT_OK(option))
- output_data("%s %s\r\n", fmt, TELOPT(option));
- else if (TELCMD_OK(option))
- output_data("%s %s\r\n", fmt, TELCMD(option));
- else
- output_data("%s %d\r\n", fmt, option);
- return;
-}
-
-void
-printsub(char direction, unsigned char *pointer, int length)
-{
- int i = 0;
-
- if (!(diagnostic & TD_OPTIONS))
- return;
-
- if (direction) {
- output_data("td: %s suboption ",
- direction == '<' ? "recv" : "send");
- if (length >= 3) {
- int j;
-
- i = pointer[length-2];
- j = pointer[length-1];
-
- if (i != IAC || j != SE) {
- output_data("(terminated by ");
- if (TELOPT_OK(i))
- output_data("%s ", TELOPT(i));
- else if (TELCMD_OK(i))
- output_data("%s ", TELCMD(i));
- else
- output_data("%d ", i);
- if (TELOPT_OK(j))
- output_data("%s", TELOPT(j));
- else if (TELCMD_OK(j))
- output_data("%s", TELCMD(j));
- else
- output_data("%d", j);
- output_data(", not IAC SE!) ");
- }
- }
- length -= 2;
- }
- if (length < 1) {
- output_data("(Empty suboption??\?)");
- return;
- }
- switch (pointer[0]) {
- case TELOPT_TTYPE:
- output_data("TERMINAL-TYPE ");
- switch (pointer[1]) {
- case TELQUAL_IS:
- output_data("IS \"%.*s\"", length-2, (char *)pointer+2);
- break;
- case TELQUAL_SEND:
- output_data("SEND");
- break;
- default:
- output_data(
- "- unknown qualifier %d (0x%x).",
- pointer[1], pointer[1]);
- }
- break;
- case TELOPT_TSPEED:
- output_data("TERMINAL-SPEED");
- if (length < 2) {
- output_data(" (empty suboption??\?)");
- break;
- }
- switch (pointer[1]) {
- case TELQUAL_IS:
- output_data(" IS %.*s", length-2, (char *)pointer+2);
- break;
- default:
- if (pointer[1] == 1)
- output_data(" SEND");
- else
- output_data(" %d (unknown)", pointer[1]);
- for (i = 2; i < length; i++) {
- output_data(" ?%d?", pointer[i]);
- }
- break;
- }
- break;
-
- case TELOPT_LFLOW:
- output_data("TOGGLE-FLOW-CONTROL");
- if (length < 2) {
- output_data(" (empty suboption??\?)");
- break;
- }
- switch (pointer[1]) {
- case LFLOW_OFF:
- output_data(" OFF"); break;
- case LFLOW_ON:
- output_data(" ON"); break;
- case LFLOW_RESTART_ANY:
- output_data(" RESTART-ANY"); break;
- case LFLOW_RESTART_XON:
- output_data(" RESTART-XON"); break;
- default:
- output_data(" %d (unknown)", pointer[1]);
- }
- for (i = 2; i < length; i++) {
- output_data(" ?%d?", pointer[i]);
- }
- break;
-
- case TELOPT_NAWS:
- output_data("NAWS");
- if (length < 2) {
- output_data(" (empty suboption??\?)");
- break;
- }
- if (length == 2) {
- output_data(" ?%d?", pointer[1]);
- break;
- }
- output_data(" %d %d (%d)",
- pointer[1], pointer[2],
- (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2])));
- if (length == 4) {
- output_data(" ?%d?", pointer[3]);
- break;
- }
- output_data(" %d %d (%d)",
- pointer[3], pointer[4],
- (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4])));
- for (i = 5; i < length; i++) {
- output_data(" ?%d?", pointer[i]);
- }
- break;
-
- case TELOPT_LINEMODE:
- output_data("LINEMODE ");
- if (length < 2) {
- output_data(" (empty suboption??\?)");
- break;
- }
- switch (pointer[1]) {
- case WILL:
- output_data("WILL ");
- goto common;
- case WONT:
- output_data("WONT ");
- goto common;
- case DO:
- output_data("DO ");
- goto common;
- case DONT:
- output_data("DONT ");
- common:
- if (length < 3) {
- output_data("(no option??\?)");
- break;
- }
- switch (pointer[2]) {
- case LM_FORWARDMASK:
- output_data("Forward Mask");
- for (i = 3; i < length; i++) {
- output_data(" %x", pointer[i]);
- }
- break;
- default:
- output_data("%d (unknown)", pointer[2]);
- for (i = 3; i < length; i++) {
- output_data(" %d", pointer[i]);
- }
- break;
- }
- break;
-
- case LM_SLC:
- output_data("SLC");
- for (i = 2; i < length - 2; i += 3) {
- if (SLC_NAME_OK(pointer[i+SLC_FUNC]))
- output_data(" %s", SLC_NAME(pointer[i+SLC_FUNC]));
- else
- output_data(" %d", pointer[i+SLC_FUNC]);
- switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) {
- case SLC_NOSUPPORT:
- output_data(" NOSUPPORT"); break;
- case SLC_CANTCHANGE:
- output_data(" CANTCHANGE"); break;
- case SLC_VARIABLE:
- output_data(" VARIABLE"); break;
- case SLC_DEFAULT:
- output_data(" DEFAULT"); break;
- }
- output_data("%s%s%s",
- pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "",
- pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "",
- pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : "");
- if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN|
- SLC_FLUSHOUT| SLC_LEVELBITS)) {
- output_data("(0x%x)", pointer[i+SLC_FLAGS]);
- }
- output_data(" %d;", pointer[i+SLC_VALUE]);
- if ((pointer[i+SLC_VALUE] == IAC) &&
- (pointer[i+SLC_VALUE+1] == IAC))
- i++;
- }
- for (; i < length; i++) {
- output_data(" ?%d?", pointer[i]);
- }
- break;
-
- case LM_MODE:
- output_data("MODE ");
- if (length < 3) {
- output_data("(no mode??\?)");
- break;
- }
- {
- char tbuf[32];
- sprintf(tbuf, "%s%s%s%s%s",
- pointer[2]&MODE_EDIT ? "|EDIT" : "",
- pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "",
- pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "",
- pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "",
- pointer[2]&MODE_ACK ? "|ACK" : "");
- output_data("%s", tbuf[1] ? &tbuf[1] : "0");
- }
- if (pointer[2]&~(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)) {
- output_data(" (0x%x)", pointer[2]);
- }
- for (i = 3; i < length; i++) {
- output_data(" ?0x%x?", pointer[i]);
- }
- break;
- default:
- output_data("%d (unknown)", pointer[1]);
- for (i = 2; i < length; i++) {
- output_data(" %d", pointer[i]);
- }
- }
- break;
-
- case TELOPT_STATUS: {
- const char *cp;
- int j, k;
-
- output_data("STATUS");
-
- switch (pointer[1]) {
- default:
- if (pointer[1] == TELQUAL_SEND)
- output_data(" SEND");
- else
- output_data(" %d (unknown)", pointer[1]);
- for (i = 2; i < length; i++) {
- output_data(" ?%d?", pointer[i]);
- }
- break;
- case TELQUAL_IS:
- output_data(" IS\r\n");
-
- for (i = 2; i < length; i++) {
- switch(pointer[i]) {
- case DO: cp = "DO"; goto common2;
- case DONT: cp = "DONT"; goto common2;
- case WILL: cp = "WILL"; goto common2;
- case WONT: cp = "WONT"; goto common2;
- common2:
- i++;
- if (TELOPT_OK(pointer[i]))
- output_data(" %s %s", cp, TELOPT(pointer[i]));
- else
- output_data(" %s %d", cp, pointer[i]);
-
- output_data("\r\n");
- break;
-
- case SB:
- output_data(" SB ");
- i++;
- j = k = i;
- while (j < length) {
- if (pointer[j] == SE) {
- if (j+1 == length)
- break;
- if (pointer[j+1] == SE)
- j++;
- else
- break;
- }
- pointer[k++] = pointer[j++];
- }
- printsub(0, &pointer[i], k - i);
- if (i < length) {
- output_data(" SE");
- i = j;
- } else
- i = j - 1;
-
- output_data("\r\n");
-
- break;
-
- default:
- output_data(" %d", pointer[i]);
- break;
- }
- }
- break;
- }
- break;
- }
-
- case TELOPT_XDISPLOC:
- output_data("X-DISPLAY-LOCATION ");
- switch (pointer[1]) {
- case TELQUAL_IS:
- output_data("IS \"%.*s\"", length-2, (char *)pointer+2);
- break;
- case TELQUAL_SEND:
- output_data("SEND");
- break;
- default:
- output_data("- unknown qualifier %d (0x%x).",
- pointer[1], pointer[1]);
- }
- break;
-
- case TELOPT_NEW_ENVIRON:
- output_data("NEW-ENVIRON ");
- goto env_common1;
- case TELOPT_OLD_ENVIRON:
- output_data("OLD-ENVIRON");
- env_common1:
- switch (pointer[1]) {
- case TELQUAL_IS:
- output_data("IS ");
- goto env_common;
- case TELQUAL_SEND:
- output_data("SEND ");
- goto env_common;
- case TELQUAL_INFO:
- output_data("INFO ");
- env_common:
- {
- int noquote = 2;
- for (i = 2; i < length; i++ ) {
- switch (pointer[i]) {
- case NEW_ENV_VAR:
- output_data("\" VAR " + noquote);
- noquote = 2;
- break;
-
- case NEW_ENV_VALUE:
- output_data("\" VALUE " + noquote);
- noquote = 2;
- break;
-
- case ENV_ESC:
- output_data("\" ESC " + noquote);
- noquote = 2;
- break;
-
- case ENV_USERVAR:
- output_data("\" USERVAR " + noquote);
- noquote = 2;
- break;
-
- default:
- if (isprint(pointer[i]) && pointer[i] != '"') {
- if (noquote) {
- output_data("\"");
- noquote = 0;
- }
- output_data("%c", pointer[i]);
- } else {
- output_data("\" %03o " + noquote,
- pointer[i]);
- noquote = 2;
- }
- break;
- }
- }
- if (!noquote)
- output_data("\"");
- break;
- }
- }
- break;
-
-#ifdef AUTHENTICATION
- case TELOPT_AUTHENTICATION:
- output_data("AUTHENTICATION");
-
- if (length < 2) {
- output_data(" (empty suboption??\?)");
- break;
- }
- switch (pointer[1]) {
- case TELQUAL_REPLY:
- case TELQUAL_IS:
- output_data(" %s ", (pointer[1] == TELQUAL_IS) ?
- "IS" : "REPLY");
- if (AUTHTYPE_NAME_OK(pointer[2]))
- output_data("%s ", AUTHTYPE_NAME(pointer[2]));
- else
- output_data("%d ", pointer[2]);
- if (length < 3) {
- output_data("(partial suboption??\?)");
- break;
- }
- output_data("%s|%s",
- ((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?
- "CLIENT" : "SERVER",
- ((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?
- "MUTUAL" : "ONE-WAY");
-
- {
- char buf[512];
- auth_printsub(&pointer[1], length - 1, buf, sizeof(buf));
- output_data("%s", buf);
- }
- break;
-
- case TELQUAL_SEND:
- i = 2;
- output_data(" SEND ");
- while (i < length) {
- if (AUTHTYPE_NAME_OK(pointer[i]))
- output_data("%s ", AUTHTYPE_NAME(pointer[i]));
- else
- output_data("%d ", pointer[i]);
- if (++i >= length) {
- output_data("(partial suboption??\?)");
- break;
- }
- output_data("%s|%s ",
- ((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?
- "CLIENT" : "SERVER",
- ((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?
- "MUTUAL" : "ONE-WAY");
- ++i;
- }
- break;
-
- case TELQUAL_NAME:
- output_data(" NAME \"%.*s\"", length - 2, pointer + 2);
- break;
-
- default:
- for (i = 2; i < length; i++) {
- output_data(" ?%d?", pointer[i]);
- }
- break;
- }
- break;
-#endif
-
-#ifdef ENCRYPTION
- case TELOPT_ENCRYPT:
- output_data("ENCRYPT");
- if (length < 2) {
- output_data(" (empty suboption??\?)");
- break;
- }
- switch (pointer[1]) {
- case ENCRYPT_START:
- output_data(" START");
- break;
-
- case ENCRYPT_END:
- output_data(" END");
- break;
-
- case ENCRYPT_REQSTART:
- output_data(" REQUEST-START");
- break;
-
- case ENCRYPT_REQEND:
- output_data(" REQUEST-END");
- break;
-
- case ENCRYPT_IS:
- case ENCRYPT_REPLY:
- output_data(" %s ", (pointer[1] == ENCRYPT_IS) ?
- "IS" : "REPLY");
- if (length < 3) {
- output_data(" (partial suboption??\?)");
- break;
- }
- if (ENCTYPE_NAME_OK(pointer[2]))
- output_data("%s ", ENCTYPE_NAME(pointer[2]));
- else
- output_data(" %d (unknown)", pointer[2]);
-
- {
- char buf[512];
- encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf));
- output_data("%s", buf);
- }
- break;
-
- case ENCRYPT_SUPPORT:
- i = 2;
- output_data(" SUPPORT ");
- while (i < length) {
- if (ENCTYPE_NAME_OK(pointer[i]))
- output_data("%s ", ENCTYPE_NAME(pointer[i]));
- else
- output_data("%d ", pointer[i]);
- i++;
- }
- break;
-
- case ENCRYPT_ENC_KEYID:
- output_data(" ENC_KEYID");
- goto encommon;
-
- case ENCRYPT_DEC_KEYID:
- output_data(" DEC_KEYID");
- goto encommon;
-
- default:
- output_data(" %d (unknown)", pointer[1]);
- encommon:
- for (i = 2; i < length; i++) {
- output_data(" %d", pointer[i]);
- }
- break;
- }
- break;
-#endif /* ENCRYPTION */
-
- default:
- if (TELOPT_OK(pointer[0]))
- output_data("%s (unknown)", TELOPT(pointer[0]));
- else
- output_data("%d (unknown)", pointer[i]);
- for (i = 1; i < length; i++) {
- output_data(" %d", pointer[i]);
- }
- break;
- }
- output_data("\r\n");
-}
-
-/*
- * Dump a data buffer in hex and ascii to the output data stream.
- */
-void
-printdata(const char *tag, char *ptr, int cnt)
-{
- int i;
- char xbuf[30];
-
- while (cnt) {
- /* flush net output buffer if no room for new data) */
- if ((&netobuf[BUFSIZ] - nfrontp) < 80) {
- netflush();
- }
-
- /* add a line of output */
- output_data("%s: ", tag);
- for (i = 0; i < 20 && cnt; i++) {
- output_data("%02x", *ptr);
- if (isprint(*ptr)) {
- xbuf[i] = *ptr;
- } else {
- xbuf[i] = '.';
- }
- if (i % 2) {
- output_data(" ");
- }
- cnt--;
- ptr++;
- }
- xbuf[i] = '\0';
- output_data(" %s\r\n", xbuf );
- }
-}
-#endif /* DIAGNOSTICS */
diff --git a/etc/rc.d/atm2 b/etc/rc.d/atm2
deleted file mode 100644
index 12acdcd4c4c8..000000000000
--- a/etc/rc.d/atm2
+++ /dev/null
@@ -1,104 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2000 The FreeBSD Project
-# 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$
-#
-
-# PROVIDE: atm2
-# REQUIRE: atm1 netif
-# BEFORE: network2
-# KEYWORD: FreeBSD
-
-#
-# Additional ATM interface configuration
-#
-
-. /etc/rc.subr
-
-atm2_start()
-{
- # Configure network interfaces
- for phy in ${atm_phy}; do
- eval netif_args=\$atm_netif_${phy}
- set -- ${netif_args}
- netname=$1
- netcnt=$2
- netindx=0
- while [ ${netindx} -lt ${netcnt} ]; do
- net="${netname}${netindx}"
- netindx=$((${netindx} + 1))
- echo -n " ${net}"
-
- # Configure atmarp server
- eval atmarp_args=\$atm_arpserver_${net}
- if [ -n "${atmarp_args}" ]; then
- atm set arpserver ${net} ${atmarp_args} ||
- continue
- fi
- eval scsparp_args=\$atm_scsparp_${net}
-
- case ${scsparp_args} in
- [Yy][Ee][Ss])
- case ${atmarp_args} in
- local)
- ;;
- *)
- echo ' local arpserver required for SCSP'
- continue
- ;;
- esac
-
- atm_atmarpd="${atm_atmarpd} ${net}"
- atm_scspd=1
- ;;
- esac
- done
- done
- echo '.'
-
- # Define any permanent ARP entries.
- if [ -n "${atm_arps}" ]; then
- for i in ${atm_arps}; do
- eval arp_args=\$atm_arp_${i}
- atm add arp ${arp_args}
- done
- fi
-
- # XXX - required by atm3.sh. I don't like having one script depend
- # on variables in another script (especially in a dynamic
- # ordered system like this), but it's necessary for the moment.
- #
- export atm_atmarpd
- export atm_scspd
-}
-
-load_rc_config "XXX"
-
-case ${atm_enable} in
-[Yy][Ee][Ss])
- atm2_start
- ;;
-esac
diff --git a/etc/rc.d/atm3 b/etc/rc.d/atm3
deleted file mode 100644
index 6cbb206fb526..000000000000
--- a/etc/rc.d/atm3
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2000 The FreeBSD Project
-# 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$
-#
-
-# Start ATM daemons
-# XXX - This script uses global variables set by scripts atm1 and atm2.
-# Ideally this shouldn't be the case.
-#
-
-# PROVIDE: atm3
-# REQUIRE: atm2
-# BEFORE: DAEMON
-# KEYWORD: FreeBSD
-
-. /etc/rc.subr
-
-atm3_start()
-{
- echo -n 'Starting ATM daemons:'
-
- # Start SCSP daemon (if needed)
- case ${atm_scspd} in
- 1)
- echo -n ' scspd'
- scspd
- ;;
- esac
-
- # Start ATMARP daemon (if needed)
- if [ -n "${atm_atmarpd}" ]; then
- echo -n ' atmarpd'
- atmarpd ${atm_atmarpd}
- fi
- echo '.'
-}
-
-load_rc_config "XXX"
-
-case ${atm_enable} in
-[Yy][Ee][Ss])
- atm3_start
- ;;
-esac
diff --git a/etc/rc.d/lockd b/etc/rc.d/lockd
deleted file mode 100644
index c250f94b9df7..000000000000
--- a/etc/rc.d/lockd
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/bin/sh
-#
-# $NetBSD: nfslocking,v 1.6 2002/03/24 15:52:41 lukem Exp $
-# $FreeBSD$
-#
-
-# PROVIDE: nfslocking
-# REQUIRE: nfsserver nfsclient nfsd
-# BEFORE: DAEMON
-# KEYWORD: FreeBSD NetBSD
-
-. /etc/rc.subr
-
-arg=$1
-
-case ${OSTYPE} in
-FreeBSD)
- RCVAR_SERVER="nfs_server_enable"
- RCVAR_CLIENT="nfs_client_enable"
- RCVAR_STATD="rpc_statd_enable"
- RCVAR_LOCKD="rpc_lockd_enable"
- ;;
-NetBSD)
- RCVAR_SERVER="nfs_server"
- RCVAR_CLIENT="nfs_client"
- RCVAR_STATD="statd"
- RCVAR_LOCKD="lockd"
- ;;
-esac
-
-start_precmd='checkyesno ${RCVAR_SERVER} || checkyesno ${RCVAR_CLIENT} ||
- [ -n "$rc_force" ]'
-stop_precmd=$start_precmd
-status_precmd=$start_precmd
-
-name="statd"
-rcvar=${RCVAR_STATD}
-command="/usr/sbin/rpc.${name}"
-load_rc_config $name
-run_rc_command "$arg"
-
-name="lockd"
-rcvar=${RCVAR_LOCKD}
-command="/usr/sbin/rpc.${name}"
-load_rc_config $name
-run_rc_command "$arg"
diff --git a/etc/rc.d/netoptions b/etc/rc.d/netoptions
deleted file mode 100644
index f18632f2eb6c..000000000000
--- a/etc/rc.d/netoptions
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-#
-# $FreeBSD$
-#
-
-# PROVIDE: network3
-# REQUIRE: localdaemons
-# BEFORE: securelevel
-# KEYWORD: FreeBSD
-
-. /etc/rc.subr
-
-load_rc_config 'XXX'
-
-echo -n 'Additional TCP options:'
-case ${log_in_vain} in
-[Nn][Oo] | '')
- log_in_vain=0
- ;;
-[Yy][Ee][Ss])
- log_in_vain=1
- ;;
-[0-9]*)
- ;;
-*)
- echo " invalid log_in_vain setting: ${log_in_vain}"
- log_in_vain=0
- ;;
-esac
-
-[ "${log_in_vain}" -ne 0 ] && (
- echo -n " log_in_vain=${log_in_vain}"
- sysctl net.inet.tcp.log_in_vain="${log_in_vain}" >/dev/null
- sysctl net.inet.udp.log_in_vain="${log_in_vain}" >/dev/null
-)
-echo '.'
diff --git a/etc/rc.d/ppp b/etc/rc.d/ppp
deleted file mode 100644
index fa5c7c82698e..000000000000
--- a/etc/rc.d/ppp
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/sh
-#
-# $FreeBSD$
-#
-
-# PROVIDE: ppp-user
-# REQUIRE: netif isdnd
-# KEYWORD: FreeBSD
-
-. /etc/rc.subr
-
-name="ppp"
-rcvar="ppp_enable"
-start_cmd="ppp_start"
-stop_cmd=":"
-
-ppp_start()
-{
- # Establish ppp mode.
- #
- if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \
- -a "${ppp_mode}" != "dedicated" \
- -a "${ppp_mode}" != "background" ]; then
- ppp_mode="auto"
- fi
-
- ppp_command="/usr/sbin/ppp -quiet -${ppp_mode}"
-
- # Switch on NAT mode?
- #
- case ${ppp_nat} in
- [Yy][Ee][Ss])
- ppp_command="${ppp_command} -nat"
- ;;
- esac
-
- ppp_command="${ppp_command} ${ppp_profile}"
-
- echo "Starting ppp as \"${ppp_user}\""
- su -m ${ppp_user} -c "exec ${ppp_command}"
-
- # Re-Sync ipfilter so it picks up any new network interfaces
- #
- /etc/rc.d/ipfilter resync
-}
-
-load_rc_config $name
-run_rc_command "$1"
diff --git a/etc/rc.d/resolv b/etc/rc.d/resolv
deleted file mode 100644
index 748a10bc7888..000000000000
--- a/etc/rc.d/resolv
+++ /dev/null
@@ -1,165 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 1999 Matt Dillon
-# 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$
-#
-
-# PROVIDE: diskless
-# REQUIRE: initdiskless rcconf mountcritlocal
-# BEFORE: addswap random
-# KEYWORD: FreeBSD
-
-dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
-[ ${dlv:=0} -eq 0 ] && exit 0
-
-name="diskless2"
-
-# Provide a function for normalizing the mounting of memory
-# filesystems. This should allow the rest of the code here to remain
-# as close as possible between 5-current and 4-stable.
-# $1 = size
-# $2 = mount point
-# $3 = (optional) bytes-per-inode
-mount_md() {
- if [ -n "$3" ]; then
- bpi="-i $3"
- fi
- /sbin/mdmfs $bpi -s $1 -M md $2
-}
-
-# If there is a global system configuration file, suck it in.
-#
-if [ -r /etc/rc.subr ]; then
- . /etc/rc.subr
- load_rc_config $name
-elif [ -r /etc/defaults/rc.conf ]; then
- . /etc/defaults/rc.conf
- source_rc_confs
-elif [ -r /etc/rc.conf ]; then
- . /etc/rc.conf
-fi
-
-# If we do not have a writable /var, create a memory
-# filesystem for /var. We don't have /usr yet so
-# use mkdir instead of touch to test. We want mount
-# to record its mounts so we have to make sure /var/db
-# exists before doing the mount -a.
-#
-if (/bin/mkdir /var/.diskless 2> /dev/null); then
- rmdir /var/.diskless
-else
- echo "+++ mount_md of /var"
- mount_md ${varsize:=32m} /var
-fi
-
-if [ ! -d /var/db ]; then
- mkdir /var/db
-fi
-
-# Now we need the rest of our mounts, particularly /usr
-#
-mount -a # chown and chgrp are in /usr
-
-# Populate /var
-#
-echo "+++ populate /var using /etc/mtree/BSD.var.dist"
-/usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var > /dev/null
-case ${sendmail_enable} in
-[Nn][Oo][Nn][Ee])
- ;;
-*)
- /usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p / > /dev/null
- ;;
-esac
-
-echo "+++ create log files based on the contents of /etc/newsyslog.conf"
-LOGFILES=`/usr/bin/awk '$1 != "#" { printf "%s ", $1 } ' /etc/newsyslog.conf`
-if [ -n "$LOGFILES" ]; then
- /usr/bin/touch $LOGFILES
-fi
-
-echo "+++ create lastlog"
-/usr/bin/touch /var/log/lastlog
-
-# Make sure our aliases database is uptodate, the aliases may have
-# been overriden in /conf.
-#
-/usr/bin/newaliases
-
-# XXX make sure to create one dir for each printer as requested by lpd
-#
-# If we do not have a writable /tmp, create a memory
-# filesystem for /tmp. If /tmp is a symlink (e.g. to /var/tmp,
-# then it should already be writable).
-#
-if (/bin/mkdir /tmp/.diskless 2> /dev/null); then
- rmdir /tmp/.diskless
-else
- if [ -h /tmp ]; then
- echo "*** /tmp is a symlink to a non-writable area!"
- echo "dropping into shell, ^D to continue anyway."
- /bin/sh
- else
- mount_md ${tmpsize:=20480} /tmp
- chmod 01777 /tmp
- fi
-fi
-
-if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
- # we have DEVFS, no worries...
- true
-elif (/bin/mkdir /dev/.diskless 2> /dev/null); then
- # if /dev is writable assume it has already been populated
- # via rc.diskless1
- #
- rmdir /dev/.diskless
-else
- (cd /; find -x dev | cpio -o -H newc) > /tmp/dev.tmp
- mount_md 4096 /dev 512
- (cd /; cpio -i -H newc -d < /tmp/dev.tmp)
- rm -f /tmp/dev.tmp
-fi
-
-# generate our hostname
-#
-if [ -z "`hostname -s`" ]; then
- hostname=`/bin/kenv dhcp.host-name`
- hostname $hostname
- echo "Hostname is $hostname"
-fi
-
-# if the info is available via dhcp/kenv
-# build the resolv.conf
-#
-if [ ! -e /etc/resolv.conf ]; then
- echo domain `/bin/kenv dhcp.domain-name` > /etc/resolv.conf
-
- set `/bin/kenv dhcp.domain-name-servers`
- for ns in `IFS=','; echo $*`; do
- echo nameserver $ns >> /etc/resolv.conf;
- done
-fi
-
diff --git a/etc/rc.d/routing b/etc/rc.d/routing
deleted file mode 100644
index 6478ab21e075..000000000000
--- a/etc/rc.d/routing
+++ /dev/null
@@ -1,140 +0,0 @@
-#!/bin/sh
-#
-# Configure routing and miscellaneous network tunables
-#
-# $FreeBSD$
-#
-
-# PROVIDE: network2
-# REQUIRE: netif ppp-user
-# KEYWORD: FreeBSD
-
-. /etc/rc.subr
-
-name="network2"
-start_cmd="network2_start"
-stop_cmd=":"
-
-network2_start()
-{
- case ${defaultrouter} in
- [Nn][Oo] | '')
- ;;
- *)
- static_routes="default ${static_routes}"
- route_default="default ${defaultrouter}"
- ;;
- esac
-
- # Setup static routes. This should be done before router discovery.
- #
- if [ -n "${static_routes}" ]; then
- for i in ${static_routes}; do
- eval route_args=\$route_${i}
- route add ${route_args}
- done
- fi
-
- echo -n 'Additional routing options:'
- case ${tcp_extensions} in
- [Yy][Ee][Ss] | '')
- ;;
- *)
- echo -n ' tcp extensions=NO'
- sysctl net.inet.tcp.rfc1323=0 >/dev/null
- ;;
- esac
-
- case ${icmp_bmcastecho} in
- [Yy][Ee][Ss])
- echo -n ' broadcast ping responses=YES'
- sysctl net.inet.icmp.bmcastecho=1 >/dev/null
- ;;
- esac
-
- case ${icmp_drop_redirect} in
- [Yy][Ee][Ss])
- echo -n ' ignore ICMP redirect=YES'
- sysctl net.inet.icmp.drop_redirect=1 >/dev/null
- ;;
- esac
-
- case ${icmp_log_redirect} in
- [Yy][Ee][Ss])
- echo -n ' log ICMP redirect=YES'
- sysctl net.inet.icmp.log_redirect=1 >/dev/null
- ;;
- esac
-
- case ${gateway_enable} in
- [Yy][Ee][Ss])
- echo -n ' IP gateway=YES'
- sysctl net.inet.ip.forwarding=1 >/dev/null
- ;;
- esac
-
- case ${forward_sourceroute} in
- [Yy][Ee][Ss])
- echo -n ' do source routing=YES'
- sysctl net.inet.ip.sourceroute=1 >/dev/null
- ;;
- esac
-
- case ${accept_sourceroute} in
- [Yy][Ee][Ss])
- echo -n ' accept source routing=YES'
- sysctl net.inet.ip.accept_sourceroute=1 >/dev/null
- ;;
- esac
-
- case ${tcp_keepalive} in
- [Nn][Oo])
- echo -n ' TCP keepalive=NO'
- sysctl net.inet.tcp.always_keepalive=0 >/dev/null
- ;;
- esac
-
- case ${tcp_drop_synfin} in
- [Yy][Ee][Ss])
- echo -n ' drop SYN+FIN packets=YES'
- sysctl net.inet.tcp.drop_synfin=1 >/dev/null
- ;;
- esac
-
- case ${ipxgateway_enable} in
- [Yy][Ee][Ss])
- echo -n ' IPX gateway=YES'
- sysctl net.ipx.ipx.ipxforwarding=1 >/dev/null
- ;;
- esac
-
- case ${arpproxy_all} in
- [Yy][Ee][Ss])
- echo -n ' ARP proxyall=YES'
- sysctl net.link.ether.inet.proxyall=1 >/dev/null
- ;;
- esac
-
- case ${ip_portrange_first} in
- [Nn][Oo] | '')
- ;;
- *)
- echo -n " ip_portrange_first=$ip_portrange_first"
- sysctl net.inet.ip.portrange.first=$ip_portrange_first >/dev/null
- ;;
- esac
-
- case ${ip_portrange_last} in
- [Nn][Oo] | '')
- ;;
- *)
- echo -n " ip_portrange_last=$ip_portrange_last"
- sysctl net.inet.ip.portrange.last=$ip_portrange_last >/dev/null
- ;;
- esac
-
- echo '.'
-}
-
-load_rc_config $name
-run_rc_command "$1"
diff --git a/etc/rc.d/statd b/etc/rc.d/statd
deleted file mode 100644
index c250f94b9df7..000000000000
--- a/etc/rc.d/statd
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/bin/sh
-#
-# $NetBSD: nfslocking,v 1.6 2002/03/24 15:52:41 lukem Exp $
-# $FreeBSD$
-#
-
-# PROVIDE: nfslocking
-# REQUIRE: nfsserver nfsclient nfsd
-# BEFORE: DAEMON
-# KEYWORD: FreeBSD NetBSD
-
-. /etc/rc.subr
-
-arg=$1
-
-case ${OSTYPE} in
-FreeBSD)
- RCVAR_SERVER="nfs_server_enable"
- RCVAR_CLIENT="nfs_client_enable"
- RCVAR_STATD="rpc_statd_enable"
- RCVAR_LOCKD="rpc_lockd_enable"
- ;;
-NetBSD)
- RCVAR_SERVER="nfs_server"
- RCVAR_CLIENT="nfs_client"
- RCVAR_STATD="statd"
- RCVAR_LOCKD="lockd"
- ;;
-esac
-
-start_precmd='checkyesno ${RCVAR_SERVER} || checkyesno ${RCVAR_CLIENT} ||
- [ -n "$rc_force" ]'
-stop_precmd=$start_precmd
-status_precmd=$start_precmd
-
-name="statd"
-rcvar=${RCVAR_STATD}
-command="/usr/sbin/rpc.${name}"
-load_rc_config $name
-run_rc_command "$arg"
-
-name="lockd"
-rcvar=${RCVAR_LOCKD}
-command="/usr/sbin/rpc.${name}"
-load_rc_config $name
-run_rc_command "$arg"
diff --git a/etc/rc.d/tmp b/etc/rc.d/tmp
deleted file mode 100644
index 748a10bc7888..000000000000
--- a/etc/rc.d/tmp
+++ /dev/null
@@ -1,165 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 1999 Matt Dillon
-# 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$
-#
-
-# PROVIDE: diskless
-# REQUIRE: initdiskless rcconf mountcritlocal
-# BEFORE: addswap random
-# KEYWORD: FreeBSD
-
-dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
-[ ${dlv:=0} -eq 0 ] && exit 0
-
-name="diskless2"
-
-# Provide a function for normalizing the mounting of memory
-# filesystems. This should allow the rest of the code here to remain
-# as close as possible between 5-current and 4-stable.
-# $1 = size
-# $2 = mount point
-# $3 = (optional) bytes-per-inode
-mount_md() {
- if [ -n "$3" ]; then
- bpi="-i $3"
- fi
- /sbin/mdmfs $bpi -s $1 -M md $2
-}
-
-# If there is a global system configuration file, suck it in.
-#
-if [ -r /etc/rc.subr ]; then
- . /etc/rc.subr
- load_rc_config $name
-elif [ -r /etc/defaults/rc.conf ]; then
- . /etc/defaults/rc.conf
- source_rc_confs
-elif [ -r /etc/rc.conf ]; then
- . /etc/rc.conf
-fi
-
-# If we do not have a writable /var, create a memory
-# filesystem for /var. We don't have /usr yet so
-# use mkdir instead of touch to test. We want mount
-# to record its mounts so we have to make sure /var/db
-# exists before doing the mount -a.
-#
-if (/bin/mkdir /var/.diskless 2> /dev/null); then
- rmdir /var/.diskless
-else
- echo "+++ mount_md of /var"
- mount_md ${varsize:=32m} /var
-fi
-
-if [ ! -d /var/db ]; then
- mkdir /var/db
-fi
-
-# Now we need the rest of our mounts, particularly /usr
-#
-mount -a # chown and chgrp are in /usr
-
-# Populate /var
-#
-echo "+++ populate /var using /etc/mtree/BSD.var.dist"
-/usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var > /dev/null
-case ${sendmail_enable} in
-[Nn][Oo][Nn][Ee])
- ;;
-*)
- /usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p / > /dev/null
- ;;
-esac
-
-echo "+++ create log files based on the contents of /etc/newsyslog.conf"
-LOGFILES=`/usr/bin/awk '$1 != "#" { printf "%s ", $1 } ' /etc/newsyslog.conf`
-if [ -n "$LOGFILES" ]; then
- /usr/bin/touch $LOGFILES
-fi
-
-echo "+++ create lastlog"
-/usr/bin/touch /var/log/lastlog
-
-# Make sure our aliases database is uptodate, the aliases may have
-# been overriden in /conf.
-#
-/usr/bin/newaliases
-
-# XXX make sure to create one dir for each printer as requested by lpd
-#
-# If we do not have a writable /tmp, create a memory
-# filesystem for /tmp. If /tmp is a symlink (e.g. to /var/tmp,
-# then it should already be writable).
-#
-if (/bin/mkdir /tmp/.diskless 2> /dev/null); then
- rmdir /tmp/.diskless
-else
- if [ -h /tmp ]; then
- echo "*** /tmp is a symlink to a non-writable area!"
- echo "dropping into shell, ^D to continue anyway."
- /bin/sh
- else
- mount_md ${tmpsize:=20480} /tmp
- chmod 01777 /tmp
- fi
-fi
-
-if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
- # we have DEVFS, no worries...
- true
-elif (/bin/mkdir /dev/.diskless 2> /dev/null); then
- # if /dev is writable assume it has already been populated
- # via rc.diskless1
- #
- rmdir /dev/.diskless
-else
- (cd /; find -x dev | cpio -o -H newc) > /tmp/dev.tmp
- mount_md 4096 /dev 512
- (cd /; cpio -i -H newc -d < /tmp/dev.tmp)
- rm -f /tmp/dev.tmp
-fi
-
-# generate our hostname
-#
-if [ -z "`hostname -s`" ]; then
- hostname=`/bin/kenv dhcp.host-name`
- hostname $hostname
- echo "Hostname is $hostname"
-fi
-
-# if the info is available via dhcp/kenv
-# build the resolv.conf
-#
-if [ ! -e /etc/resolv.conf ]; then
- echo domain `/bin/kenv dhcp.domain-name` > /etc/resolv.conf
-
- set `/bin/kenv dhcp.domain-name-servers`
- for ns in `IFS=','; echo $*`; do
- echo nameserver $ns >> /etc/resolv.conf;
- done
-fi
-
diff --git a/etc/rc.d/var b/etc/rc.d/var
deleted file mode 100644
index 748a10bc7888..000000000000
--- a/etc/rc.d/var
+++ /dev/null
@@ -1,165 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 1999 Matt Dillon
-# 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$
-#
-
-# PROVIDE: diskless
-# REQUIRE: initdiskless rcconf mountcritlocal
-# BEFORE: addswap random
-# KEYWORD: FreeBSD
-
-dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
-[ ${dlv:=0} -eq 0 ] && exit 0
-
-name="diskless2"
-
-# Provide a function for normalizing the mounting of memory
-# filesystems. This should allow the rest of the code here to remain
-# as close as possible between 5-current and 4-stable.
-# $1 = size
-# $2 = mount point
-# $3 = (optional) bytes-per-inode
-mount_md() {
- if [ -n "$3" ]; then
- bpi="-i $3"
- fi
- /sbin/mdmfs $bpi -s $1 -M md $2
-}
-
-# If there is a global system configuration file, suck it in.
-#
-if [ -r /etc/rc.subr ]; then
- . /etc/rc.subr
- load_rc_config $name
-elif [ -r /etc/defaults/rc.conf ]; then
- . /etc/defaults/rc.conf
- source_rc_confs
-elif [ -r /etc/rc.conf ]; then
- . /etc/rc.conf
-fi
-
-# If we do not have a writable /var, create a memory
-# filesystem for /var. We don't have /usr yet so
-# use mkdir instead of touch to test. We want mount
-# to record its mounts so we have to make sure /var/db
-# exists before doing the mount -a.
-#
-if (/bin/mkdir /var/.diskless 2> /dev/null); then
- rmdir /var/.diskless
-else
- echo "+++ mount_md of /var"
- mount_md ${varsize:=32m} /var
-fi
-
-if [ ! -d /var/db ]; then
- mkdir /var/db
-fi
-
-# Now we need the rest of our mounts, particularly /usr
-#
-mount -a # chown and chgrp are in /usr
-
-# Populate /var
-#
-echo "+++ populate /var using /etc/mtree/BSD.var.dist"
-/usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var > /dev/null
-case ${sendmail_enable} in
-[Nn][Oo][Nn][Ee])
- ;;
-*)
- /usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p / > /dev/null
- ;;
-esac
-
-echo "+++ create log files based on the contents of /etc/newsyslog.conf"
-LOGFILES=`/usr/bin/awk '$1 != "#" { printf "%s ", $1 } ' /etc/newsyslog.conf`
-if [ -n "$LOGFILES" ]; then
- /usr/bin/touch $LOGFILES
-fi
-
-echo "+++ create lastlog"
-/usr/bin/touch /var/log/lastlog
-
-# Make sure our aliases database is uptodate, the aliases may have
-# been overriden in /conf.
-#
-/usr/bin/newaliases
-
-# XXX make sure to create one dir for each printer as requested by lpd
-#
-# If we do not have a writable /tmp, create a memory
-# filesystem for /tmp. If /tmp is a symlink (e.g. to /var/tmp,
-# then it should already be writable).
-#
-if (/bin/mkdir /tmp/.diskless 2> /dev/null); then
- rmdir /tmp/.diskless
-else
- if [ -h /tmp ]; then
- echo "*** /tmp is a symlink to a non-writable area!"
- echo "dropping into shell, ^D to continue anyway."
- /bin/sh
- else
- mount_md ${tmpsize:=20480} /tmp
- chmod 01777 /tmp
- fi
-fi
-
-if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
- # we have DEVFS, no worries...
- true
-elif (/bin/mkdir /dev/.diskless 2> /dev/null); then
- # if /dev is writable assume it has already been populated
- # via rc.diskless1
- #
- rmdir /dev/.diskless
-else
- (cd /; find -x dev | cpio -o -H newc) > /tmp/dev.tmp
- mount_md 4096 /dev 512
- (cd /; cpio -i -H newc -d < /tmp/dev.tmp)
- rm -f /tmp/dev.tmp
-fi
-
-# generate our hostname
-#
-if [ -z "`hostname -s`" ]; then
- hostname=`/bin/kenv dhcp.host-name`
- hostname $hostname
- echo "Hostname is $hostname"
-fi
-
-# if the info is available via dhcp/kenv
-# build the resolv.conf
-#
-if [ ! -e /etc/resolv.conf ]; then
- echo domain `/bin/kenv dhcp.domain-name` > /etc/resolv.conf
-
- set `/bin/kenv dhcp.domain-name-servers`
- for ns in `IFS=','; echo $*`; do
- echo nameserver $ns >> /etc/resolv.conf;
- done
-fi
-
diff --git a/etc/rc.initdiskless b/etc/rc.initdiskless
deleted file mode 100644
index fcd947cf04f0..000000000000
--- a/etc/rc.initdiskless
+++ /dev/null
@@ -1,223 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 1999 Matt Dillion
-# 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$
-#
-# PROVIDE: initdiskless
-# KEYWORD: FreeBSD
-
-
-# On entry to this script the entire system consists of a read-only root
-# mounted via NFS. We use the contents of /conf to create and populate
-# memory filesystems. The kernel has run BOOTP and configured an interface
-# (otherwise it would not have been able to mount the NFS root!)
-#
-# The following directories are scanned. Each sucessive directory overrides
-# (is merged into) the previous one.
-#
-# /conf/base universal base
-# /conf/default modified by a secondary universal base
-# /conf/${ipba} modified based on the assigned broadcast IP
-# /conf/${ip} modified based on the machine's assigned IP
-#
-# Each of these directories may contain any number of subdirectories which
-# represent directories in / on the diskless machine. The existance of
-# these subdirectories causes this script to create a MEMORY FILESYSTEM for
-# /<sub_directory_name>. For example, if /conf/base/etc exists then a
-# memory filesystem will be created for /etc.
-#
-# If a subdirectory contains the file 'diskless_remount' the contents of
-# the file is used to remount the subdirectory prior to it being copied to
-# the memory filesystem. For example, if /conf/base/etc/diskless_remount
-# contains the string 'my.server.com:/etc' then my.server.com:/etc will be
-# mounted in place of the subdirectory. This allows you to avoid making
-# duplicates of system directories in /conf.
-#
-# If a subdirectory contains the file 'md_size', the contents of the
-# file is used to determine the size of the memory filesystem, in 512
-# byte sectors. The default is 8192 (4MB). You only have to specify an
-# md_size if the default doesn't work for you (i.e. if it is too big or
-# too small). Note that in -current the default is 4096 (2MB). For
-# example, /conf/base/etc/md_size might contain '16384'.
-#
-# If /conf/<special_dir>/SUBDIR.cpio.gz exists, the file is cpio'd into
-# the specified /SUBDIR (and a memory filesystem is created for /SUBDIR
-# if necessary).
-#
-# If /conf/<special_dir>/SUBDIR.remove exists, the file contains a list
-# of paths which are rm -rf'd relative to /SUBDIR.
-#
-# You will almost universally want to create a /conf/base/etc containing
-# a diskless_remount and possibly an md_size file. You will then almost
-# universally want to override rc.conf, rc.local, and fstab by creating
-# /conf/default/etc/{rc.conf,rc.local,fstab}. Your fstab should be sure
-# to mount a /usr... typically an NFS readonly /usr.
-#
-# NOTE! rc.diskless2 will create /var, /tmp, and /dev. Those filesystems
-# should not be specified in /conf. At least not yet.
-
-dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
-[ ${dlv:=0} -eq 0 ] && exit 0
-
-# chkerr:
-#
-# Routine to check for error
-#
-# checks error code and drops into shell on failure.
-# if shell exits, terminates script as well as /etc/rc.
-#
-chkerr() {
- case $1 in
- 0)
- ;;
- *)
- echo "$2 failed: dropping into /bin/sh"
- /bin/sh
- # RESUME
- ;;
- esac
-}
-
-# Create a generic memory disk
-#
-mount_md() {
- /sbin/mdmfs -i 4096 -s $1 -M md $2
-}
-
-# Create the memory filesystem if it has not already been created
-#
-create_md() {
- if [ "x`eval echo \\$md_created_$1`" = "x" ]; then
- if [ "x`eval echo \\$md_size_$1`" = "x" ]; then
- md_size=4096
- else
- md_size=`eval echo \\$md_size_$1`
- fi
- mount_md $md_size /$1
- /bin/chmod 755 /$1
- eval md_created_$1=created
- fi
-}
-
-# DEBUGGING
-#
-# set -v
-
-# Figure out our interface and IP.
-#
-bootp_ifc=""
-bootp_ipa=""
-bootp_ipbca=""
-iflist=`ifconfig -l`
-for i in ${iflist} ; do
- set `ifconfig ${i}`
- while [ $# -ge 1 ] ; do
- if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
- bootp_ifc=${i} ; bootp_ipa=${2} ; shift
- fi
- if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
- bootp_ipbca=$2; shift
- fi
- shift
- done
- if [ "${bootp_ifc}" != "" ] ; then
- break
- fi
-done
-echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
-
-# Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca},
-# and /conf/${bootp_ipa}. For each subdirectory found within these
-# directories:
-#
-# - calculate memory filesystem sizes. If the subdirectory (prior to
-# NFS remounting) contains the file 'md_size', the contents specified
-# in 512 byte sectors will be used to size the memory filesystem. Otherwise
-# 8192 sectors (4MB) is used.
-#
-# - handle NFS remounts. If the subdirectory contains the file
-# diskless_remount, the contents of the file is NFS mounted over
-# the directory. For example /conf/base/etc/diskless_remount
-# might contain 'myserver:/etc'. NFS remounts allow you to avoid
-# having to dup your system directories in /conf. Your server must
-# be sure to export those filesystems -alldirs, however.
-#
-for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
- for j in /conf/$i/* ; do
- # memory filesystem size specification
- #
- subdir=${j##*/}
- if [ -d $j -a -f $j/md_size ]; then
- eval md_size_$subdir=`cat $j/md_size`
- fi
-
- # NFS remount
- #
- if [ -d $j -a -f $j/diskless_remount ]; then
- nfspt=`/bin/cat $j/diskless_remount`
- mount_nfs $nfspt $j
- chkerr $? "mount_nfs $nfspt $j"
- fi
- done
-done
-
-# - Create all required MFS filesystems and populate them from
-# our templates. Support both a direct template and a dir.cpio.gz
-# archive. Support dir.remove files containing a list of relative
-# paths to remove.
-#
-# TODO:
-# + find a way to assign a 'group' identifier to a machine
-# so we can use group-specific configurations;
-
-for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
- for j in /conf/$i/* ; do
- subdir=${j##*/}
- if [ -d $j ]; then
- create_md $subdir
- cp -Rp $j/* /$subdir
- fi
- done
- for j in /conf/$i/*.cpio.gz ; do
- subdir=${j%*.cpio.gz}
- subdir=${subdir##*/}
- if [ -f $j ]; then
- create_md $subdir
- echo "Loading /$subdir from cpio archive $j"
- (cd / ; /stand/gzip -d < $j | /stand/cpio --extract -d )
- fi
- done
- for j in /conf/$i/*.remove ; do
- subdir=${j%*.remove}
- subdir=${subdir##*/}
- if [ -f $j ]; then
- # doubly sure it is a memory disk before rm -rf'ing
- create_md $subdir
- (cd /$subdir; rm -rf `/bin/cat $j`)
- fi
- done
-done
-
diff --git a/gnu/usr.bin/gdb/doc/inc-hist.diff b/gnu/usr.bin/gdb/doc/inc-hist.diff
deleted file mode 100644
index 923f97322641..000000000000
--- a/gnu/usr.bin/gdb/doc/inc-hist.diff
+++ /dev/null
@@ -1,31 +0,0 @@
-$FreeBSD$
-
---- inc-hist.texinfo.orig Wed Apr 11 08:20:01 2001
-+++ inc-hist.texinfo Wed Apr 11 08:21:57 2001
-@@ -26,9 +26,9 @@
- @node Using History Interactively
- @chapter Using History Interactively
-
--@ifclear BashFeatures
--@defcodeindex bt
--@end ifclear
-+@c @ifclear BashFeatures
-+@c @defcodeindex bt
-+@c @end ifclear
-
- @ifset BashFeatures
- This chapter describes how to use the @sc{gnu} History Library
-@@ -39,9 +39,10 @@
- @end ifset
- @ifclear BashFeatures
- This chapter describes how to use the @sc{gnu} History Library interactively,
--from a user's standpoint. It should be considered a user's guide. For
--information on using the @sc{gnu} History Library in your own programs,
--@pxref{Programming with GNU History}.
-+from a user's standpoint.
-+@c It should be considered a user's guide. For
-+@c information on using the @sc{gnu} History Library in your own programs,
-+@c @pxref{Programming with GNU History}.
- @end ifclear
-
- @ifset BashFeatures
diff --git a/include/_ctype.h b/include/_ctype.h
deleted file mode 100644
index 7d6fa79d3269..000000000000
--- a/include/_ctype.h
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * This code is derived from software contributed to Berkeley by
- * Paul Borman at Krystal Technologies.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ctype.h 8.4 (Berkeley) 1/21/94
- * $FreeBSD$
- */
-
-#ifndef _CTYPE_H_
-#define _CTYPE_H_
-
-#include <sys/cdefs.h>
-#include <sys/_types.h>
-
-#define _CTYPE_A 0x00000100L /* Alpha */
-#define _CTYPE_C 0x00000200L /* Control */
-#define _CTYPE_D 0x00000400L /* Digit */
-#define _CTYPE_G 0x00000800L /* Graph */
-#define _CTYPE_L 0x00001000L /* Lower */
-#define _CTYPE_P 0x00002000L /* Punct */
-#define _CTYPE_S 0x00004000L /* Space */
-#define _CTYPE_U 0x00008000L /* Upper */
-#define _CTYPE_X 0x00010000L /* X digit */
-#define _CTYPE_B 0x00020000L /* Blank */
-#define _CTYPE_R 0x00040000L /* Print */
-#define _CTYPE_I 0x00080000L /* Ideogram */
-#define _CTYPE_T 0x00100000L /* Special */
-#define _CTYPE_Q 0x00200000L /* Phonogram */
-#define _CTYPE_SW0 0x20000000L /* 0 width character */
-#define _CTYPE_SW1 0x40000000L /* 1 width character */
-#define _CTYPE_SW2 0x80000000L /* 2 width character */
-#define _CTYPE_SW3 0xc0000000L /* 3 width character */
-
-__BEGIN_DECLS
-int isalnum(int);
-int isalpha(int);
-int iscntrl(int);
-int isdigit(int);
-int isgraph(int);
-int islower(int);
-int isprint(int);
-int ispunct(int);
-int isspace(int);
-int isupper(int);
-int isxdigit(int);
-int tolower(int);
-int toupper(int);
-
-#if __XSI_VISIBLE
-int _tolower(int);
-int _toupper(int);
-int isascii(int);
-int toascii(int);
-#endif
-
-#if __BSD_VISIBLE
-int digittoint(int);
-int isblank(int);
-int ishexnumber(int);
-int isideogram(int);
-int isnumber(int);
-int isphonogram(int);
-int isrune(int);
-int isspecial(int);
-#endif
-__END_DECLS
-
-#define isalnum(c) __istype((c), _CTYPE_A|_CTYPE_D)
-#define isalpha(c) __istype((c), _CTYPE_A)
-#define iscntrl(c) __istype((c), _CTYPE_C)
-#define isdigit(c) __isctype((c), _CTYPE_D) /* ANSI -- locale independent */
-#define isgraph(c) __istype((c), _CTYPE_G)
-#define islower(c) __istype((c), _CTYPE_L)
-#define isprint(c) __istype((c), _CTYPE_R)
-#define ispunct(c) __istype((c), _CTYPE_P)
-#define isspace(c) __istype((c), _CTYPE_S)
-#define isupper(c) __istype((c), _CTYPE_U)
-#define isxdigit(c) __isctype((c), _CTYPE_X) /* ANSI -- locale independent */
-#define tolower(c) __tolower(c)
-#define toupper(c) __toupper(c)
-
-#if __XSI_VISIBLE
-/*
- * POSIX.1-2001 specifies _tolower() and _toupper() to be macros equivalent to
- * tolower() and toupper() respectively, minus extra checking to ensure that
- * the argument is a lower or uppercase letter respectively. We've chosen to
- * implement these macros with the same error checking as tolower() and
- * toupper() since this doesn't violate the specification itself, only its
- * intent. We purposely leave _tolower() and _toupper() undocumented to
- * discourage their use.
- *
- * XXX isascii() and toascii() should similarly be undocumented.
- */
-#define _tolower(c) __tolower(c)
-#define _toupper(c) __toupper(c)
-#define isascii(c) (((c) & ~0x7F) == 0)
-#define toascii(c) ((c) & 0x7F)
-#endif
-
-#if __BSD_VISIBLE
-#define digittoint(c) __maskrune((c), 0xFF)
-#define isblank(c) __istype((c), _CTYPE_B)
-#define ishexnumber(c) __istype((c), _CTYPE_X)
-#define isideogram(c) __istype((c), _CTYPE_I)
-#define isnumber(c) __istype((c), _CTYPE_D)
-#define isphonogram(c) __istype((c), _CTYPE_Q)
-#define isrune(c) __istype((c), 0xFFFFFF00L)
-#define isspecial(c) __istype((c), _CTYPE_T)
-#endif
-
-/* See comments in <sys/_types.h> about __ct_rune_t. */
-__BEGIN_DECLS
-unsigned long ___runetype(__ct_rune_t);
-__ct_rune_t ___tolower(__ct_rune_t);
-__ct_rune_t ___toupper(__ct_rune_t);
-__END_DECLS
-
-/*
- * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
- * to generate code for extern versions of all our inline functions.
- */
-#ifdef _EXTERNALIZE_CTYPE_INLINES_
-#define _USE_CTYPE_INLINE_
-#define static
-#define __inline
-#endif
-
-/*
- * <runetype.h> brings namespace pollution (struct member names). This prevents
- * us from using the inline optimizations in the more strict __POSIX_VISIBLE and
- * __XSI_VISIBLE namespaces. To fix this properly would require that we rename
- * member names of long-standing structs, or something equally evil.
- */
-#if !__BSD_VISIBLE && !defined(_USE_CTYPE_INLINE_) && \
- !defined(_DONT_USE_CTYPE_INLINE_)
-#define _DONT_USE_CTYPE_INLINE_
-#endif
-
-/*
- * Use inline functions if we are allowed to and the compiler supports them.
- */
-#if !defined(_DONT_USE_CTYPE_INLINE_) && \
- (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
-
-#include <runetype.h>
-
-static __inline int
-__maskrune(__ct_rune_t _c, unsigned long _f)
-{
- return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
- _CurrentRuneLocale->runetype[_c]) & _f;
-}
-
-static __inline int
-__istype(__ct_rune_t _c, unsigned long _f)
-{
- return (!!__maskrune(_c, _f));
-}
-
-static __inline int
-__isctype(__ct_rune_t _c, unsigned long _f)
-{
- return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
- !!(_DefaultRuneLocale.runetype[_c] & _f);
-}
-
-static __inline __ct_rune_t
-__toupper(__ct_rune_t _c)
-{
- return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
- _CurrentRuneLocale->mapupper[_c];
-}
-
-static __inline __ct_rune_t
-__tolower(__ct_rune_t _c)
-{
- return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
- _CurrentRuneLocale->maplower[_c];
-}
-
-#else /* not using inlines */
-
-__BEGIN_DECLS
-int __maskrune(__ct_rune_t, unsigned long);
-int __istype(__ct_rune_t, unsigned long);
-int __isctype(__ct_rune_t, unsigned long);
-__ct_rune_t __toupper(__ct_rune_t);
-__ct_rune_t __tolower(__ct_rune_t);
-__END_DECLS
-#endif /* using inlines */
-
-#endif /* !_CTYPE_H_ */
diff --git a/lib/libc/gen/fts-compat.c b/lib/libc/gen/fts-compat.c
deleted file mode 100644
index d69ef7ae1b03..000000000000
--- a/lib/libc/gen/fts-compat.c
+++ /dev/null
@@ -1,1154 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <fts.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "un-namespace.h"
-
-static FTSENT *fts_alloc(FTS *, char *, int);
-static FTSENT *fts_build(FTS *, int);
-static void fts_lfree(FTSENT *);
-static void fts_load(FTS *, FTSENT *);
-static size_t fts_maxarglen(char * const *);
-static void fts_padjust(FTS *, FTSENT *);
-static int fts_palloc(FTS *, size_t);
-static FTSENT *fts_sort(FTS *, FTSENT *, int);
-static u_short fts_stat(FTS *, FTSENT *, int);
-static int fts_safe_changedir(FTS *, FTSENT *, int, char *);
-
-#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
-
-#define CLR(opt) (sp->fts_options &= ~(opt))
-#define ISSET(opt) (sp->fts_options & (opt))
-#define SET(opt) (sp->fts_options |= (opt))
-
-#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd))
-
-/* fts_build flags */
-#define BCHILD 1 /* fts_children */
-#define BNAMES 2 /* fts_children, names only */
-#define BREAD 3 /* fts_read */
-
-FTS *
-fts_open(argv, options, compar)
- char * const *argv;
- int options;
- int (*compar)(const FTSENT * const *, const FTSENT * const *);
-{
- FTS *sp;
- FTSENT *p, *root;
- int nitems;
- FTSENT *parent, *tmp;
- int len;
-
- /* Options check. */
- if (options & ~FTS_OPTIONMASK) {
- errno = EINVAL;
- return (NULL);
- }
-
- /* Allocate/initialize the stream */
- if ((sp = malloc(sizeof(FTS))) == NULL)
- return (NULL);
- memset(sp, 0, sizeof(FTS));
- sp->fts_compar = compar;
- sp->fts_options = options;
-
- /* Shush, GCC. */
- tmp = NULL;
-
- /* Logical walks turn on NOCHDIR; symbolic links are too hard. */
- if (ISSET(FTS_LOGICAL))
- SET(FTS_NOCHDIR);
-
- /*
- * Start out with 1K of path space, and enough, in any case,
- * to hold the user's paths.
- */
- if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN)))
- goto mem1;
-
- /* Allocate/initialize root's parent. */
- if ((parent = fts_alloc(sp, "", 0)) == NULL)
- goto mem2;
- parent->fts_level = FTS_ROOTPARENTLEVEL;
-
- /* Allocate/initialize root(s). */
- for (root = NULL, nitems = 0; *argv != NULL; ++argv, ++nitems) {
- /* Don't allow zero-length paths. */
- if ((len = strlen(*argv)) == 0) {
- errno = ENOENT;
- goto mem3;
- }
-
- p = fts_alloc(sp, *argv, len);
- p->fts_level = FTS_ROOTLEVEL;
- p->fts_parent = parent;
- p->fts_accpath = p->fts_name;
- p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW));
-
- /* Command-line "." and ".." are real directories. */
- if (p->fts_info == FTS_DOT)
- p->fts_info = FTS_D;
-
- /*
- * If comparison routine supplied, traverse in sorted
- * order; otherwise traverse in the order specified.
- */
- if (compar) {
- p->fts_link = root;
- root = p;
- } else {
- p->fts_link = NULL;
- if (root == NULL)
- tmp = root = p;
- else {
- tmp->fts_link = p;
- tmp = p;
- }
- }
- }
- if (compar && nitems > 1)
- root = fts_sort(sp, root, nitems);
-
- /*
- * Allocate a dummy pointer and make fts_read think that we've just
- * finished the node before the root(s); set p->fts_info to FTS_INIT
- * so that everything about the "current" node is ignored.
- */
- if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL)
- goto mem3;
- sp->fts_cur->fts_link = root;
- sp->fts_cur->fts_info = FTS_INIT;
-
- /*
- * If using chdir(2), grab a file descriptor pointing to dot to ensure
- * that we can get back here; this could be avoided for some paths,
- * but almost certainly not worth the effort. Slashes, symbolic links,
- * and ".." are all fairly nasty problems. Note, if we can't get the
- * descriptor we run anyway, just more slowly.
- */
- if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = _open(".", O_RDONLY, 0)) < 0)
- SET(FTS_NOCHDIR);
-
- return (sp);
-
-mem3: fts_lfree(root);
- free(parent);
-mem2: free(sp->fts_path);
-mem1: free(sp);
- return (NULL);
-}
-
-static void
-fts_load(sp, p)
- FTS *sp;
- FTSENT *p;
-{
- int len;
- char *cp;
-
- /*
- * Load the stream structure for the next traversal. Since we don't
- * actually enter the directory until after the preorder visit, set
- * the fts_accpath field specially so the chdir gets done to the right
- * place and the user can access the first node. From fts_open it's
- * known that the path will fit.
- */
- len = p->fts_pathlen = p->fts_namelen;
- memmove(sp->fts_path, p->fts_name, len + 1);
- if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) {
- len = strlen(++cp);
- memmove(p->fts_name, cp, len + 1);
- p->fts_namelen = len;
- }
- p->fts_accpath = p->fts_path = sp->fts_path;
- sp->fts_dev = p->fts_dev;
-}
-
-int
-fts_close(sp)
- FTS *sp;
-{
- FTSENT *freep, *p;
- int saved_errno;
-
- /*
- * This still works if we haven't read anything -- the dummy structure
- * points to the root list, so we step through to the end of the root
- * list which has a valid parent pointer.
- */
- if (sp->fts_cur) {
- for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
- freep = p;
- p = p->fts_link != NULL ? p->fts_link : p->fts_parent;
- free(freep);
- }
- free(p);
- }
-
- /* Free up child linked list, sort array, path buffer. */
- if (sp->fts_child)
- fts_lfree(sp->fts_child);
- if (sp->fts_array)
- free(sp->fts_array);
- free(sp->fts_path);
-
- /* Return to original directory, save errno if necessary. */
- if (!ISSET(FTS_NOCHDIR)) {
- saved_errno = fchdir(sp->fts_rfd) ? errno : 0;
- (void)_close(sp->fts_rfd);
-
- /* Set errno and return. */
- if (saved_errno != 0) {
- /* Free up the stream pointer. */
- free(sp);
- errno = saved_errno;
- return (-1);
- }
- }
-
- /* Free up the stream pointer. */
- free(sp);
- return (0);
-}
-
-/*
- * Special case of "/" at the end of the path so that slashes aren't
- * appended which would cause paths to be written as "....//foo".
- */
-#define NAPPEND(p) \
- (p->fts_path[p->fts_pathlen - 1] == '/' \
- ? p->fts_pathlen - 1 : p->fts_pathlen)
-
-FTSENT *
-fts_read(sp)
- FTS *sp;
-{
- FTSENT *p, *tmp;
- int instr;
- char *t;
- int saved_errno;
-
- /* If finished or unrecoverable error, return NULL. */
- if (sp->fts_cur == NULL || ISSET(FTS_STOP))
- return (NULL);
-
- /* Set current node pointer. */
- p = sp->fts_cur;
-
- /* Save and zero out user instructions. */
- instr = p->fts_instr;
- p->fts_instr = FTS_NOINSTR;
-
- /* Any type of file may be re-visited; re-stat and re-turn. */
- if (instr == FTS_AGAIN) {
- p->fts_info = fts_stat(sp, p, 0);
- return (p);
- }
-
- /*
- * Following a symlink -- SLNONE test allows application to see
- * SLNONE and recover. If indirecting through a symlink, have
- * keep a pointer to current location. If unable to get that
- * pointer, follow fails.
- */
- if (instr == FTS_FOLLOW &&
- (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
- p->fts_info = fts_stat(sp, p, 1);
- if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
- if ((p->fts_symfd = _open(".", O_RDONLY, 0)) < 0) {
- p->fts_errno = errno;
- p->fts_info = FTS_ERR;
- } else
- p->fts_flags |= FTS_SYMFOLLOW;
- }
- return (p);
- }
-
- /* Directory in pre-order. */
- if (p->fts_info == FTS_D) {
- /* If skipped or crossed mount point, do post-order visit. */
- if (instr == FTS_SKIP ||
- (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
- if (p->fts_flags & FTS_SYMFOLLOW)
- (void)_close(p->fts_symfd);
- if (sp->fts_child) {
- fts_lfree(sp->fts_child);
- sp->fts_child = NULL;
- }
- p->fts_info = FTS_DP;
- return (p);
- }
-
- /* Rebuild if only read the names and now traversing. */
- if (sp->fts_child != NULL && ISSET(FTS_NAMEONLY)) {
- CLR(FTS_NAMEONLY);
- fts_lfree(sp->fts_child);
- sp->fts_child = NULL;
- }
-
- /*
- * Cd to the subdirectory.
- *
- * If have already read and now fail to chdir, whack the list
- * to make the names come out right, and set the parent errno
- * so the application will eventually get an error condition.
- * Set the FTS_DONTCHDIR flag so that when we logically change
- * directories back to the parent we don't do a chdir.
- *
- * If haven't read do so. If the read fails, fts_build sets
- * FTS_STOP or the fts_info field of the node.
- */
- if (sp->fts_child != NULL) {
- if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) {
- p->fts_errno = errno;
- p->fts_flags |= FTS_DONTCHDIR;
- for (p = sp->fts_child; p != NULL;
- p = p->fts_link)
- p->fts_accpath =
- p->fts_parent->fts_accpath;
- }
- } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
- if (ISSET(FTS_STOP))
- return (NULL);
- return (p);
- }
- p = sp->fts_child;
- sp->fts_child = NULL;
- goto name;
- }
-
- /* Move to the next node on this level. */
-next: tmp = p;
- if ((p = p->fts_link) != NULL) {
- free(tmp);
-
- /*
- * If reached the top, return to the original directory (or
- * the root of the tree), and load the paths for the next root.
- */
- if (p->fts_level == FTS_ROOTLEVEL) {
- if (FCHDIR(sp, sp->fts_rfd)) {
- SET(FTS_STOP);
- return (NULL);
- }
- fts_load(sp, p);
- return (sp->fts_cur = p);
- }
-
- /*
- * User may have called fts_set on the node. If skipped,
- * ignore. If followed, get a file descriptor so we can
- * get back if necessary.
- */
- if (p->fts_instr == FTS_SKIP)
- goto next;
- if (p->fts_instr == FTS_FOLLOW) {
- p->fts_info = fts_stat(sp, p, 1);
- if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
- if ((p->fts_symfd =
- _open(".", O_RDONLY, 0)) < 0) {
- p->fts_errno = errno;
- p->fts_info = FTS_ERR;
- } else
- p->fts_flags |= FTS_SYMFOLLOW;
- }
- p->fts_instr = FTS_NOINSTR;
- }
-
-name: t = sp->fts_path + NAPPEND(p->fts_parent);
- *t++ = '/';
- memmove(t, p->fts_name, p->fts_namelen + 1);
- return (sp->fts_cur = p);
- }
-
- /* Move up to the parent node. */
- p = tmp->fts_parent;
- free(tmp);
-
- if (p->fts_level == FTS_ROOTPARENTLEVEL) {
- /*
- * Done; free everything up and set errno to 0 so the user
- * can distinguish between error and EOF.
- */
- free(p);
- errno = 0;
- return (sp->fts_cur = NULL);
- }
-
- /* NUL terminate the pathname. */
- sp->fts_path[p->fts_pathlen] = '\0';
-
- /*
- * Return to the parent directory. If at a root node or came through
- * a symlink, go back through the file descriptor. Otherwise, cd up
- * one directory.
- */
- if (p->fts_level == FTS_ROOTLEVEL) {
- if (FCHDIR(sp, sp->fts_rfd)) {
- SET(FTS_STOP);
- return (NULL);
- }
- } else if (p->fts_flags & FTS_SYMFOLLOW) {
- if (FCHDIR(sp, p->fts_symfd)) {
- saved_errno = errno;
- (void)_close(p->fts_symfd);
- errno = saved_errno;
- SET(FTS_STOP);
- return (NULL);
- }
- (void)_close(p->fts_symfd);
- } else if (!(p->fts_flags & FTS_DONTCHDIR) &&
- fts_safe_changedir(sp, p->fts_parent, -1, "..")) {
- SET(FTS_STOP);
- return (NULL);
- }
- p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP;
- return (sp->fts_cur = p);
-}
-
-/*
- * Fts_set takes the stream as an argument although it's not used in this
- * implementation; it would be necessary if anyone wanted to add global
- * semantics to fts using fts_set. An error return is allowed for similar
- * reasons.
- */
-/* ARGSUSED */
-int
-fts_set(sp, p, instr)
- FTS *sp;
- FTSENT *p;
- int instr;
-{
- if (instr != 0 && instr != FTS_AGAIN && instr != FTS_FOLLOW &&
- instr != FTS_NOINSTR && instr != FTS_SKIP) {
- errno = EINVAL;
- return (1);
- }
- p->fts_instr = instr;
- return (0);
-}
-
-FTSENT *
-fts_children(sp, instr)
- FTS *sp;
- int instr;
-{
- FTSENT *p;
- int fd;
-
- if (instr != 0 && instr != FTS_NAMEONLY) {
- errno = EINVAL;
- return (NULL);
- }
-
- /* Set current node pointer. */
- p = sp->fts_cur;
-
- /*
- * Errno set to 0 so user can distinguish empty directory from
- * an error.
- */
- errno = 0;
-
- /* Fatal errors stop here. */
- if (ISSET(FTS_STOP))
- return (NULL);
-
- /* Return logical hierarchy of user's arguments. */
- if (p->fts_info == FTS_INIT)
- return (p->fts_link);
-
- /*
- * If not a directory being visited in pre-order, stop here. Could
- * allow FTS_DNR, assuming the user has fixed the problem, but the
- * same effect is available with FTS_AGAIN.
- */
- if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */)
- return (NULL);
-
- /* Free up any previous child list. */
- if (sp->fts_child != NULL)
- fts_lfree(sp->fts_child);
-
- if (instr == FTS_NAMEONLY) {
- SET(FTS_NAMEONLY);
- instr = BNAMES;
- } else
- instr = BCHILD;
-
- /*
- * If using chdir on a relative path and called BEFORE fts_read does
- * its chdir to the root of a traversal, we can lose -- we need to
- * chdir into the subdirectory, and we don't know where the current
- * directory is, so we can't get back so that the upcoming chdir by
- * fts_read will work.
- */
- if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' ||
- ISSET(FTS_NOCHDIR))
- return (sp->fts_child = fts_build(sp, instr));
-
- if ((fd = _open(".", O_RDONLY, 0)) < 0)
- return (NULL);
- sp->fts_child = fts_build(sp, instr);
- if (fchdir(fd))
- return (NULL);
- (void)_close(fd);
- return (sp->fts_child);
-}
-
-#ifndef fts_get_clientptr
-#error "fts_get_clientptr not defined"
-#endif
-
-void *
-(fts_get_clientptr)(FTS *sp)
-{
-
- return (fts_get_clientptr(sp));
-}
-
-#ifndef fts_get_stream
-#error "fts_get_stream not defined"
-#endif
-
-FTS *
-(fts_get_stream)(FTSENT *p)
-{
- return (fts_get_stream(p));
-}
-
-void
-fts_set_clientptr(FTS *sp, void *clientptr)
-{
-
- sp->fts_clientptr = clientptr;
-}
-
-/*
- * This is the tricky part -- do not casually change *anything* in here. The
- * idea is to build the linked list of entries that are used by fts_children
- * and fts_read. There are lots of special cases.
- *
- * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is
- * set and it's a physical walk (so that symbolic links can't be directories),
- * we can do things quickly. First, if it's a 4.4BSD file system, the type
- * of the file is in the directory entry. Otherwise, we assume that the number
- * of subdirectories in a node is equal to the number of links to the parent.
- * The former skips all stat calls. The latter skips stat calls in any leaf
- * directories and for any files after the subdirectories in the directory have
- * been found, cutting the stat calls by about 2/3.
- */
-static FTSENT *
-fts_build(sp, type)
- FTS *sp;
- int type;
-{
- struct dirent *dp;
- FTSENT *p, *head;
- int nitems;
- FTSENT *cur, *tail;
- DIR *dirp;
- void *oldaddr;
- int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno,
- nostat, doadjust;
- char *cp;
-
- /* Set current node pointer. */
- cur = sp->fts_cur;
-
- /*
- * Open the directory for reading. If this fails, we're done.
- * If being called from fts_read, set the fts_info field.
- */
-#ifdef FTS_WHITEOUT
- if (ISSET(FTS_WHITEOUT))
- oflag = DTF_NODUP|DTF_REWIND;
- else
- oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND;
-#else
-#define __opendir2(path, flag) opendir(path)
-#endif
- if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) {
- if (type == BREAD) {
- cur->fts_info = FTS_DNR;
- cur->fts_errno = errno;
- }
- return (NULL);
- }
-
- /*
- * Nlinks is the number of possible entries of type directory in the
- * directory if we're cheating on stat calls, 0 if we're not doing
- * any stat calls at all, -1 if we're doing stats on everything.
- */
- if (type == BNAMES) {
- nlinks = 0;
- /* Be quiet about nostat, GCC. */
- nostat = 0;
- } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) {
- nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2);
- nostat = 1;
- } else {
- nlinks = -1;
- nostat = 0;
- }
-
-#ifdef notdef
- (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink);
- (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n",
- ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT));
-#endif
- /*
- * If we're going to need to stat anything or we want to descend
- * and stay in the directory, chdir. If this fails we keep going,
- * but set a flag so we don't chdir after the post-order visit.
- * We won't be able to stat anything, but we can still return the
- * names themselves. Note, that since fts_read won't be able to
- * chdir into the directory, it will have to return different path
- * names than before, i.e. "a/b" instead of "b". Since the node
- * has already been visited in pre-order, have to wait until the
- * post-order visit to return the error. There is a special case
- * here, if there was nothing to stat then it's not an error to
- * not be able to stat. This is all fairly nasty. If a program
- * needed sorted entries or stat information, they had better be
- * checking FTS_NS on the returned nodes.
- */
- cderrno = 0;
- if (nlinks || type == BREAD) {
- if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {
- if (nlinks && type == BREAD)
- cur->fts_errno = errno;
- cur->fts_flags |= FTS_DONTCHDIR;
- descend = 0;
- cderrno = errno;
- (void)closedir(dirp);
- dirp = NULL;
- } else
- descend = 1;
- } else
- descend = 0;
-
- /*
- * Figure out the max file name length that can be stored in the
- * current path -- the inner loop allocates more path as necessary.
- * We really wouldn't have to do the maxlen calculations here, we
- * could do them in fts_read before returning the path, but it's a
- * lot easier here since the length is part of the dirent structure.
- *
- * If not changing directories set a pointer so that can just append
- * each new name into the path.
- */
- len = NAPPEND(cur);
- if (ISSET(FTS_NOCHDIR)) {
- cp = sp->fts_path + len;
- *cp++ = '/';
- } else {
- /* GCC, you're too verbose. */
- cp = NULL;
- }
- len++;
- maxlen = sp->fts_pathlen - len;
-
- level = cur->fts_level + 1;
-
- /* Read the directory, attaching each entry to the `link' pointer. */
- doadjust = 0;
- for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) {
- if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
- continue;
-
- if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL)
- goto mem1;
- if (dp->d_namlen >= maxlen) { /* include space for NUL */
- oldaddr = sp->fts_path;
- if (fts_palloc(sp, dp->d_namlen + len + 1)) {
- /*
- * No more memory for path or structures. Save
- * errno, free up the current structure and the
- * structures already allocated.
- */
-mem1: saved_errno = errno;
- if (p)
- free(p);
- fts_lfree(head);
- (void)closedir(dirp);
- cur->fts_info = FTS_ERR;
- SET(FTS_STOP);
- errno = saved_errno;
- return (NULL);
- }
- /* Did realloc() change the pointer? */
- if (oldaddr != sp->fts_path) {
- doadjust = 1;
- if (ISSET(FTS_NOCHDIR))
- cp = sp->fts_path + len;
- }
- maxlen = sp->fts_pathlen - len;
- }
-
- if (len + dp->d_namlen >= USHRT_MAX) {
- /*
- * In an FTSENT, fts_pathlen is a u_short so it is
- * possible to wraparound here. If we do, free up
- * the current structure and the structures already
- * allocated, then error out with ENAMETOOLONG.
- */
- free(p);
- fts_lfree(head);
- (void)closedir(dirp);
- cur->fts_info = FTS_ERR;
- SET(FTS_STOP);
- errno = ENAMETOOLONG;
- return (NULL);
- }
- p->fts_level = level;
- p->fts_parent = sp->fts_cur;
- p->fts_pathlen = len + dp->d_namlen;
-
-#ifdef FTS_WHITEOUT
- if (dp->d_type == DT_WHT)
- p->fts_flags |= FTS_ISW;
-#endif
-
- if (cderrno) {
- if (nlinks) {
- p->fts_info = FTS_NS;
- p->fts_errno = cderrno;
- } else
- p->fts_info = FTS_NSOK;
- p->fts_accpath = cur->fts_accpath;
- } else if (nlinks == 0
-#ifdef DT_DIR
- || (nostat &&
- dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)
-#endif
- ) {
- p->fts_accpath =
- ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;
- p->fts_info = FTS_NSOK;
- } else {
- /* Build a file name for fts_stat to stat. */
- if (ISSET(FTS_NOCHDIR)) {
- p->fts_accpath = p->fts_path;
- memmove(cp, p->fts_name, p->fts_namelen + 1);
- } else
- p->fts_accpath = p->fts_name;
- /* Stat it. */
- p->fts_info = fts_stat(sp, p, 0);
-
- /* Decrement link count if applicable. */
- if (nlinks > 0 && (p->fts_info == FTS_D ||
- p->fts_info == FTS_DC || p->fts_info == FTS_DOT))
- --nlinks;
- }
-
- /* We walk in directory order so "ls -f" doesn't get upset. */
- p->fts_link = NULL;
- if (head == NULL)
- head = tail = p;
- else {
- tail->fts_link = p;
- tail = p;
- }
- ++nitems;
- }
- if (dirp)
- (void)closedir(dirp);
-
- /*
- * If realloc() changed the address of the path, adjust the
- * addresses for the rest of the tree and the dir list.
- */
- if (doadjust)
- fts_padjust(sp, head);
-
- /*
- * If not changing directories, reset the path back to original
- * state.
- */
- if (ISSET(FTS_NOCHDIR)) {
- if (len == sp->fts_pathlen || nitems == 0)
- --cp;
- *cp = '\0';
- }
-
- /*
- * If descended after called from fts_children or after called from
- * fts_read and nothing found, get back. At the root level we use
- * the saved fd; if one of fts_open()'s arguments is a relative path
- * to an empty directory, we wind up here with no other way back. If
- * can't get back, we're done.
- */
- if (descend && (type == BCHILD || !nitems) &&
- (cur->fts_level == FTS_ROOTLEVEL ?
- FCHDIR(sp, sp->fts_rfd) :
- fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) {
- cur->fts_info = FTS_ERR;
- SET(FTS_STOP);
- return (NULL);
- }
-
- /* If didn't find anything, return NULL. */
- if (!nitems) {
- if (type == BREAD)
- cur->fts_info = FTS_DP;
- return (NULL);
- }
-
- /* Sort the entries. */
- if (sp->fts_compar && nitems > 1)
- head = fts_sort(sp, head, nitems);
- return (head);
-}
-
-static u_short
-fts_stat(sp, p, follow)
- FTS *sp;
- FTSENT *p;
- int follow;
-{
- FTSENT *t;
- dev_t dev;
- ino_t ino;
- struct stat *sbp, sb;
- int saved_errno;
-
- /* If user needs stat info, stat buffer already allocated. */
- sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;
-
-#ifdef FTS_WHITEOUT
- /* check for whiteout */
- if (p->fts_flags & FTS_ISW) {
- if (sbp != &sb) {
- memset(sbp, '\0', sizeof (*sbp));
- sbp->st_mode = S_IFWHT;
- }
- return (FTS_W);
- }
-#endif
-
- /*
- * If doing a logical walk, or application requested FTS_FOLLOW, do
- * a stat(2). If that fails, check for a non-existent symlink. If
- * fail, set the errno from the stat call.
- */
- if (ISSET(FTS_LOGICAL) || follow) {
- if (stat(p->fts_accpath, sbp)) {
- saved_errno = errno;
- if (!lstat(p->fts_accpath, sbp)) {
- errno = 0;
- return (FTS_SLNONE);
- }
- p->fts_errno = saved_errno;
- goto err;
- }
- } else if (lstat(p->fts_accpath, sbp)) {
- p->fts_errno = errno;
-err: memset(sbp, 0, sizeof(struct stat));
- return (FTS_NS);
- }
-
- if (S_ISDIR(sbp->st_mode)) {
- /*
- * Set the device/inode. Used to find cycles and check for
- * crossing mount points. Also remember the link count, used
- * in fts_build to limit the number of stat calls. It is
- * understood that these fields are only referenced if fts_info
- * is set to FTS_D.
- */
- dev = p->fts_dev = sbp->st_dev;
- ino = p->fts_ino = sbp->st_ino;
- p->fts_nlink = sbp->st_nlink;
-
- if (ISDOT(p->fts_name))
- return (FTS_DOT);
-
- /*
- * Cycle detection is done by brute force when the directory
- * is first encountered. If the tree gets deep enough or the
- * number of symbolic links to directories is high enough,
- * something faster might be worthwhile.
- */
- for (t = p->fts_parent;
- t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent)
- if (ino == t->fts_ino && dev == t->fts_dev) {
- p->fts_cycle = t;
- return (FTS_DC);
- }
- return (FTS_D);
- }
- if (S_ISLNK(sbp->st_mode))
- return (FTS_SL);
- if (S_ISREG(sbp->st_mode))
- return (FTS_F);
- return (FTS_DEFAULT);
-}
-
-/*
- * The comparison function takes pointers to pointers to FTSENT structures.
- * Qsort wants a comparison function that takes pointers to void.
- * (Both with appropriate levels of const-poisoning, of course!)
- * Use a trampoline function to deal with the difference.
- */
-static int
-fts_compar(const void *a, const void *b)
-{
- FTS *parent;
-
- parent = (*(const FTSENT * const *)a)->fts_fts;
- return (*parent->fts_compar)(a, b);
-}
-
-static FTSENT *
-fts_sort(sp, head, nitems)
- FTS *sp;
- FTSENT *head;
- int nitems;
-{
- FTSENT **ap, *p;
-
- /*
- * Construct an array of pointers to the structures and call qsort(3).
- * Reassemble the array in the order returned by qsort. If unable to
- * sort for memory reasons, return the directory entries in their
- * current order. Allocate enough space for the current needs plus
- * 40 so don't realloc one entry at a time.
- */
- if (nitems > sp->fts_nitems) {
- sp->fts_nitems = nitems + 40;
- if ((sp->fts_array = reallocf(sp->fts_array,
- sp->fts_nitems * sizeof(FTSENT *))) == NULL) {
- sp->fts_nitems = 0;
- return (head);
- }
- }
- for (ap = sp->fts_array, p = head; p; p = p->fts_link)
- *ap++ = p;
- qsort(sp->fts_array, nitems, sizeof(FTSENT *), fts_compar);
- for (head = *(ap = sp->fts_array); --nitems; ++ap)
- ap[0]->fts_link = ap[1];
- ap[0]->fts_link = NULL;
- return (head);
-}
-
-static FTSENT *
-fts_alloc(sp, name, namelen)
- FTS *sp;
- char *name;
- int namelen;
-{
- FTSENT *p;
- size_t len;
-
- struct ftsent_withstat {
- FTSENT ent;
- struct stat statbuf;
- };
-
- /*
- * The file name is a variable length array and no stat structure is
- * necessary if the user has set the nostat bit. Allocate the FTSENT
- * structure, the file name and the stat structure in one chunk, but
- * be careful that the stat structure is reasonably aligned.
- */
- if (ISSET(FTS_NOSTAT))
- len = sizeof(FTSENT) + namelen + 1;
- else
- len = sizeof(struct ftsent_withstat) + namelen + 1;
-
- if ((p = malloc(len)) == NULL)
- return (NULL);
-
- if (ISSET(FTS_NOSTAT)) {
- p->fts_name = (char *)(p + 1);
- p->fts_statp = NULL;
- } else {
- p->fts_name = (char *)((struct ftsent_withstat *)p + 1);
- p->fts_statp = &((struct ftsent_withstat *)p)->statbuf;
- }
-
- /* Copy the name and guarantee NUL termination. */
- memcpy(p->fts_name, name, namelen);
- p->fts_name[namelen] = '\0';
- p->fts_namelen = namelen;
- p->fts_path = sp->fts_path;
- p->fts_errno = 0;
- p->fts_flags = 0;
- p->fts_instr = FTS_NOINSTR;
- p->fts_number = 0;
- p->fts_pointer = NULL;
- p->fts_fts = sp;
- return (p);
-}
-
-static void
-fts_lfree(head)
- FTSENT *head;
-{
- FTSENT *p;
-
- /* Free a linked list of structures. */
- while ((p = head)) {
- head = head->fts_link;
- free(p);
- }
-}
-
-/*
- * Allow essentially unlimited paths; find, rm, ls should all work on any tree.
- * Most systems will allow creation of paths much longer than MAXPATHLEN, even
- * though the kernel won't resolve them. Add the size (not just what's needed)
- * plus 256 bytes so don't realloc the path 2 bytes at a time.
- */
-static int
-fts_palloc(sp, more)
- FTS *sp;
- size_t more;
-{
-
- sp->fts_pathlen += more + 256;
- /*
- * Check for possible wraparound. In an FTS, fts_pathlen is
- * a signed int but in an FTSENT it is an unsigned short.
- * We limit fts_pathlen to USHRT_MAX to be safe in both cases.
- */
- if (sp->fts_pathlen < 0 || sp->fts_pathlen >= USHRT_MAX) {
- if (sp->fts_path)
- free(sp->fts_path);
- sp->fts_path = NULL;
- errno = ENAMETOOLONG;
- return (1);
- }
- sp->fts_path = reallocf(sp->fts_path, sp->fts_pathlen);
- return (sp->fts_path == NULL);
-}
-
-/*
- * When the path is realloc'd, have to fix all of the pointers in structures
- * already returned.
- */
-static void
-fts_padjust(sp, head)
- FTS *sp;
- FTSENT *head;
-{
- FTSENT *p;
- char *addr = sp->fts_path;
-
-#define ADJUST(p) do { \
- if ((p)->fts_accpath != (p)->fts_name) { \
- (p)->fts_accpath = \
- (char *)addr + ((p)->fts_accpath - (p)->fts_path); \
- } \
- (p)->fts_path = addr; \
-} while (0)
- /* Adjust the current set of children. */
- for (p = sp->fts_child; p; p = p->fts_link)
- ADJUST(p);
-
- /* Adjust the rest of the tree, including the current level. */
- for (p = head; p->fts_level >= FTS_ROOTLEVEL;) {
- ADJUST(p);
- p = p->fts_link ? p->fts_link : p->fts_parent;
- }
-}
-
-static size_t
-fts_maxarglen(argv)
- char * const *argv;
-{
- size_t len, max;
-
- for (max = 0; *argv; ++argv)
- if ((len = strlen(*argv)) > max)
- max = len;
- return (max + 1);
-}
-
-/*
- * Change to dir specified by fd or p->fts_accpath without getting
- * tricked by someone changing the world out from underneath us.
- * Assumes p->fts_dev and p->fts_ino are filled in.
- */
-static int
-fts_safe_changedir(sp, p, fd, path)
- FTS *sp;
- FTSENT *p;
- int fd;
- char *path;
-{
- int ret, oerrno, newfd;
- struct stat sb;
-
- newfd = fd;
- if (ISSET(FTS_NOCHDIR))
- return (0);
- if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0)
- return (-1);
- if (_fstat(newfd, &sb)) {
- ret = -1;
- goto bail;
- }
- if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) {
- errno = ENOENT; /* disinformation */
- ret = -1;
- goto bail;
- }
- ret = fchdir(newfd);
-bail:
- oerrno = errno;
- if (fd < 0)
- (void)_close(newfd);
- errno = oerrno;
- return (ret);
-}
diff --git a/lib/libc/gen/fts-compat.h b/lib/libc/gen/fts-compat.h
deleted file mode 100644
index 09c4600a1072..000000000000
--- a/lib/libc/gen/fts-compat.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)fts.h 8.3 (Berkeley) 8/14/94
- * $FreeBSD$
- */
-
-#ifndef _FTS_H_
-#define _FTS_H_
-
-typedef struct {
- struct _ftsent *fts_cur; /* current node */
- struct _ftsent *fts_child; /* linked list of children */
- struct _ftsent **fts_array; /* sort array */
- dev_t fts_dev; /* starting device # */
- char *fts_path; /* path for this descent */
- int fts_rfd; /* fd for root */
- int fts_pathlen; /* sizeof(path) */
- int fts_nitems; /* elements in the sort array */
- int (*fts_compar) /* compare function */
- (const struct _ftsent * const *, const struct _ftsent * const *);
-
-#define FTS_COMFOLLOW 0x001 /* follow command line symlinks */
-#define FTS_LOGICAL 0x002 /* logical walk */
-#define FTS_NOCHDIR 0x004 /* don't change directories */
-#define FTS_NOSTAT 0x008 /* don't get stat info */
-#define FTS_PHYSICAL 0x010 /* physical walk */
-#define FTS_SEEDOT 0x020 /* return dot and dot-dot */
-#define FTS_XDEV 0x040 /* don't cross devices */
-#define FTS_WHITEOUT 0x080 /* return whiteout information */
-#define FTS_OPTIONMASK 0x0ff /* valid user option mask */
-
-#define FTS_NAMEONLY 0x100 /* (private) child names only */
-#define FTS_STOP 0x200 /* (private) unrecoverable error */
- int fts_options; /* fts_open options, global flags */
- void *fts_clientptr; /* thunk for sort function */
-} FTS;
-
-typedef struct _ftsent {
- struct _ftsent *fts_cycle; /* cycle node */
- struct _ftsent *fts_parent; /* parent directory */
- struct _ftsent *fts_link; /* next file in directory */
- long fts_number; /* local numeric value */
- void *fts_pointer; /* local address value */
- char *fts_accpath; /* access path */
- char *fts_path; /* root path */
- int fts_errno; /* errno for this node */
- int fts_symfd; /* fd for symlink */
- u_short fts_pathlen; /* strlen(fts_path) */
- u_short fts_namelen; /* strlen(fts_name) */
-
- ino_t fts_ino; /* inode */
- dev_t fts_dev; /* device */
- nlink_t fts_nlink; /* link count */
-
-#define FTS_ROOTPARENTLEVEL -1
-#define FTS_ROOTLEVEL 0
- short fts_level; /* depth (-1 to N) */
-
-#define FTS_D 1 /* preorder directory */
-#define FTS_DC 2 /* directory that causes cycles */
-#define FTS_DEFAULT 3 /* none of the above */
-#define FTS_DNR 4 /* unreadable directory */
-#define FTS_DOT 5 /* dot or dot-dot */
-#define FTS_DP 6 /* postorder directory */
-#define FTS_ERR 7 /* error; errno is set */
-#define FTS_F 8 /* regular file */
-#define FTS_INIT 9 /* initialized only */
-#define FTS_NS 10 /* stat(2) failed */
-#define FTS_NSOK 11 /* no stat(2) requested */
-#define FTS_SL 12 /* symbolic link */
-#define FTS_SLNONE 13 /* symbolic link without target */
-#define FTS_W 14 /* whiteout object */
- u_short fts_info; /* user flags for FTSENT structure */
-
-#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */
-#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */
-#define FTS_ISW 0x04 /* this is a whiteout object */
- u_short fts_flags; /* private flags for FTSENT structure */
-
-#define FTS_AGAIN 1 /* read node again */
-#define FTS_FOLLOW 2 /* follow symbolic link */
-#define FTS_NOINSTR 3 /* no instructions */
-#define FTS_SKIP 4 /* discard node */
- u_short fts_instr; /* fts_set() instructions */
-
- struct stat *fts_statp; /* stat(2) information */
- char *fts_name; /* file name */
- FTS *fts_fts; /* back pointer to main FTS */
-} FTSENT;
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-FTSENT *fts_children(FTS *, int);
-int fts_close(FTS *);
-void *fts_get_clientptr(FTS *);
-#define fts_get_clientptr(fts) ((fts)->fts_clientptr)
-FTS *fts_get_stream(FTSENT *);
-#define fts_get_stream(ftsent) ((ftsent)->fts_fts)
-FTS *fts_open(char * const *, int,
- int (*)(const FTSENT * const *, const FTSENT * const *));
-FTSENT *fts_read(FTS *);
-int fts_set(FTS *, FTSENT *, int);
-void fts_set_clientptr(FTS *, void *);
-__END_DECLS
-
-#endif /* !_FTS_H_ */
diff --git a/lib/libc/gen/sem.c b/lib/libc/gen/sem.c
deleted file mode 100644
index e37eccd1e00f..000000000000
--- a/lib/libc/gen/sem.c
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- * Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include "namespace.h"
-#include <stdlib.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <semaphore.h>
-#include <stdarg.h>
-#include <pthread.h>
-#include <sys/queue.h>
-#include <_semaphore.h>
-#include "un-namespace.h"
-
-#define _SEM_CHECK_VALIDITY(sem) \
- if ((*(sem))->magic != SEM_MAGIC) { \
- errno = EINVAL; \
- retval = -1; \
- goto RETURN; \
- }
-
-static sem_t sem_alloc(unsigned int value, semid_t semid, int system_sem);
-static void sem_free(sem_t sem);
-
-static LIST_HEAD(, sem) named_sems = LIST_HEAD_INITIALIZER(&named_sems);
-static pthread_mutex_t named_sems_mtx = PTHREAD_MUTEX_INITIALIZER;
-
-static void
-sem_free(sem_t sem)
-{
-
- _pthread_mutex_destroy(&sem->lock);
- _pthread_cond_destroy(&sem->gtzero);
- sem->magic = 0;
- free(sem);
-}
-
-static sem_t
-sem_alloc(unsigned int value, semid_t semid, int system_sem)
-{
- sem_t sem;
-
- if (value > SEM_VALUE_MAX) {
- errno = EINVAL;
- return (NULL);
- }
-
- sem = (sem_t)malloc(sizeof(struct sem));
- if (sem == NULL) {
- errno = ENOSPC;
- return (NULL);
- }
-
- /*
- * Initialize the semaphore.
- */
- if (_pthread_mutex_init(&sem->lock, NULL) != 0) {
- free(sem);
- errno = ENOSPC;
- return (NULL);
- }
-
- if (_pthread_cond_init(&sem->gtzero, NULL) != 0) {
- _pthread_mutex_destroy(&sem->lock);
- free(sem);
- errno = ENOSPC;
- return (NULL);
- }
-
- sem->count = (u_int32_t)value;
- sem->nwaiters = 0;
- sem->magic = SEM_MAGIC;
- sem->semid = semid;
- sem->syssem = system_sem;
- return (sem);
-}
-
-int
-sem_init(sem_t *sem, int pshared, unsigned int value)
-{
- int retval, got_system_sem;
- semid_t semid;
-
- got_system_sem = 0;
- semid = SEM_USER;
- /*
- * Range check the arguments.
- */
- if (pshared != 0) {
- retval = ksem_init(&semid, value);
- if (retval == -1)
- goto RETURN;
- got_system_sem = 1;
- }
-
- (*sem) = sem_alloc(value, semid, got_system_sem);
- if ((*sem) == NULL)
- retval = -1;
- else
- retval = 0;
- RETURN:
- if (retval != 0 && got_system_sem)
- ksem_destroy(semid);
- return retval;
-}
-
-int
-sem_destroy(sem_t *sem)
-{
- int retval;
-
- _SEM_CHECK_VALIDITY(sem);
-
- _pthread_mutex_lock(&(*sem)->lock);
- /*
- * If this is a system semaphore let the kernel track it otherwise
- * make sure there are no waiters.
- */
- if ((*sem)->syssem != 0) {
- retval = ksem_destroy((*sem)->semid);
- if (retval == -1) {
- _pthread_mutex_unlock(&(*sem)->lock);
- goto RETURN;
- }
- } else if ((*sem)->nwaiters > 0) {
- _pthread_mutex_unlock(&(*sem)->lock);
- errno = EBUSY;
- retval = -1;
- goto RETURN;
- }
- _pthread_mutex_unlock(&(*sem)->lock);
-
- sem_free(*sem);
-
- retval = 0;
- RETURN:
- return retval;
-}
-
-sem_t *
-sem_open(const char *name, int oflag, ...)
-{
- sem_t *sem;
- sem_t s;
- semid_t semid;
- mode_t mode;
- unsigned int value;
-
- mode = 0;
- value = 0;
-
- if ((oflag & O_CREAT) != 0) {
- va_list ap;
-
- va_start(ap, oflag);
- mode = va_arg(ap, int);
- value = va_arg(ap, unsigned int);
- va_end(ap);
- }
- /*
- * we can be lazy and let the kernel handle the "oflag",
- * we'll just merge duplicate IDs into our list.
- */
- if (ksem_open(&semid, name, oflag, mode, value) == -1)
- return (SEM_FAILED);
- /*
- * search for a duplicate ID, we must return the same sem_t *
- * if we locate one.
- */
- _pthread_mutex_lock(&named_sems_mtx);
- LIST_FOREACH(s, &named_sems, entry) {
- if (s->semid == semid) {
- _pthread_mutex_unlock(&named_sems_mtx);
- return (s->backpointer);
- }
- }
- sem = (sem_t *)malloc(sizeof(*sem));
- if (sem == NULL)
- goto err;
- *sem = sem_alloc(value, semid, 1);
- if ((*sem) == NULL)
- goto err;
- LIST_INSERT_HEAD(&named_sems, *sem, entry);
- (*sem)->backpointer = sem;
- _pthread_mutex_unlock(&named_sems_mtx);
- return (sem);
-err:
- _pthread_mutex_unlock(&named_sems_mtx);
- ksem_close(semid);
- if (sem != NULL) {
- if (*sem != NULL)
- sem_free(*sem);
- else
- errno = ENOSPC;
- free(sem);
- } else {
- errno = ENOSPC;
- }
- return (SEM_FAILED);
-}
-
-int
-sem_close(sem_t *sem)
-{
-
- if ((*sem)->syssem == 0) {
- errno = EINVAL;
- return (-1);
- }
- _pthread_mutex_lock(&named_sems_mtx);
- if (ksem_close((*sem)->semid) == -1) {
- _pthread_mutex_unlock(&named_sems_mtx);
- return (-1);
- }
- LIST_REMOVE((*sem), entry);
- _pthread_mutex_unlock(&named_sems_mtx);
- sem_free(*sem);
- free(sem);
- return (0);
-}
-
-int
-sem_unlink(const char *name)
-{
-
- return (ksem_unlink(name));
-}
-
-int
-sem_wait(sem_t *sem)
-{
- int retval;
-
- _SEM_CHECK_VALIDITY(sem);
-
- if ((*sem)->syssem != 0) {
- retval = ksem_wait((*sem)->semid);
- goto RETURN;
- }
-
- _pthread_mutex_lock(&(*sem)->lock);
-
- while ((*sem)->count == 0) {
- (*sem)->nwaiters++;
- _pthread_cond_wait(&(*sem)->gtzero, &(*sem)->lock);
- (*sem)->nwaiters--;
- }
- (*sem)->count--;
-
- _pthread_mutex_unlock(&(*sem)->lock);
-
- retval = 0;
- RETURN:
- return retval;
-}
-
-int
-sem_trywait(sem_t *sem)
-{
- int retval;
-
- _SEM_CHECK_VALIDITY(sem);
-
- if ((*sem)->syssem != 0) {
- retval = ksem_trywait((*sem)->semid);
- goto RETURN;
- }
-
- _pthread_mutex_lock(&(*sem)->lock);
-
- if ((*sem)->count > 0) {
- (*sem)->count--;
- retval = 0;
- } else {
- errno = EAGAIN;
- retval = -1;
- }
-
- _pthread_mutex_unlock(&(*sem)->lock);
-
- RETURN:
- return retval;
-}
-
-int
-sem_post(sem_t *sem)
-{
- int retval;
-
- _SEM_CHECK_VALIDITY(sem);
-
- if ((*sem)->syssem != 0) {
- retval = ksem_post((*sem)->semid);
- goto RETURN;
- }
-
- _pthread_mutex_lock(&(*sem)->lock);
-
- (*sem)->count++;
- if ((*sem)->nwaiters > 0)
- _pthread_cond_signal(&(*sem)->gtzero);
-
- _pthread_mutex_unlock(&(*sem)->lock);
-
- retval = 0;
- RETURN:
- return retval;
-}
-
-int
-sem_getvalue(sem_t * __restrict sem, int * __restrict sval)
-{
- int retval;
-
- _SEM_CHECK_VALIDITY(sem);
-
- if ((*sem)->syssem != 0) {
- retval = ksem_getvalue((*sem)->semid, sval);
- goto RETURN;
- }
-
- _pthread_mutex_lock(&(*sem)->lock);
- *sval = (int)(*sem)->count;
- _pthread_mutex_unlock(&(*sem)->lock);
-
- retval = 0;
- RETURN:
- return retval;
-}
diff --git a/lib/libc/gen/sem_destroy.3 b/lib/libc/gen/sem_destroy.3
deleted file mode 100644
index 9b88b02fbfb6..000000000000
--- a/lib/libc/gen/sem_destroy.3
+++ /dev/null
@@ -1,84 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd February 15, 2000
-.Dt SEM_DESTROY 3
-.Os
-.Sh NAME
-.Nm sem_destroy
-.Nd destroy an unnamed semaphore
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In semaphore.h
-.Ft int
-.Fn sem_destroy "sem_t *sem"
-.Sh DESCRIPTION
-The
-.Fn sem_destroy
-function destroys the unnamed semaphore pointed to by
-.Fa sem .
-After a successful call to
-.Fn sem_destroy ,
-.Fa sem
-is unusable until re-initialized by another call to
-.Fn sem_init .
-.Sh RETURN VALUES
-.Rv -std sem_destroy
-.Sh ERRORS
-The
-.Fn sem_destroy
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-.Fa sem
-points to an invalid semaphore.
-.It Bq Er EBUSY
-There are currently threads blocked on the semaphore that
-.Fa sem
-points to.
-.El
-.Sh SEE ALSO
-.Xr sem_init 3 ,
-.Xr sem 4
-.Sh STANDARDS
-The
-.Fn sem_destroy
-function conforms to
-.St -p1003.1-96 .
-.Pp
-POSIX does not define the behavior of
-.Fn sem_destroy
-if called while there are threads blocked on
-.Fa sem ,
-but this implementation is guaranteed to return -1 and set
-.Va errno
-to
-.Er EBUSY
-if there are threads blocked on
-.Fa sem .
diff --git a/lib/libc/gen/sem_getvalue.3 b/lib/libc/gen/sem_getvalue.3
deleted file mode 100644
index 694ced41162f..000000000000
--- a/lib/libc/gen/sem_getvalue.3
+++ /dev/null
@@ -1,76 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd February 15, 2000
-.Dt SEM_GETVALUE 3
-.Os
-.Sh NAME
-.Nm sem_getvalue
-.Nd get the value of a semaphore
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In semaphore.h
-.Ft int
-.Fn sem_getvalue "sem_t * restrict sem" "int * restrict sval"
-.Sh DESCRIPTION
-The
-.Fn sem_getvalue
-function sets the variable pointed to by
-.Fa sval
-to the current value of the semaphore pointed to by
-.Fa sem ,
-as of the time that the call to
-.Fn sem_getvalue
-is actually run.
-.Sh RETURN VALUES
-.Rv -std sem_getvalue
-.Sh ERRORS
-The
-.Fn sem_getvalue
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-.Fa sem
-points to an invalid semaphore.
-.El
-.Sh SEE ALSO
-.Xr sem_post 3 ,
-.Xr sem_trywait 3 ,
-.Xr sem_wait 3 ,
-.Xr sem 4
-.Sh STANDARDS
-The
-.Fn sem_getvalue
-function conforms to
-.St -p1003.1-96 .
-.Pp
-The value of the semaphore is never negative, even if there are threads blocked
-on the semaphore. POSIX is somewhat ambiguous in its wording with regard to
-what the value of the semaphore should be if there are blocked waiting threads,
-but this behavior is conformant, given the wording of the specification.
diff --git a/lib/libc/gen/sem_init.3 b/lib/libc/gen/sem_init.3
deleted file mode 100644
index 46394b48a995..000000000000
--- a/lib/libc/gen/sem_init.3
+++ /dev/null
@@ -1,102 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd February 15, 2000
-.Dt SEM_INIT 3
-.Os
-.Sh NAME
-.Nm sem_init
-.Nd initialize an unnamed semaphore
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In semaphore.h
-.Ft int
-.Fn sem_init "sem_t *sem" "int pshared" "unsigned int value"
-.Sh DESCRIPTION
-The
-.Fn sem_init
-function initializes the unnamed semaphore pointed to by
-.Fa sem
-to have the value
-.Fa value .
-A non-zero value for
-.Fa pshared
-specifies a shared semaphore that can be used by multiple processes, which this
-implementation is not capable of.
-.Pp
-Following a successful call to
-.Fn sem_init ,
-.Fa sem
-can be used as an argument in subsequent calls to
-.Xr sem_wait 3 ,
-.Xr sem_trywait 3 ,
-.Xr sem_post 3 ,
-and
-.Xr sem_destroy 3 .
-The
-.Fa sem
-argument is no longer valid after a successful call to
-.Xr sem_destroy 3 .
-.Sh RETURN VALUES
-.Rv -std sem_init
-.Sh ERRORS
-The
-.Fn sem_init
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-.Fa value
-exceeds SEM_VALUE_MAX.
-.It Bq Er ENOSPC
-Memory allocation error.
-.It Bq Er EPERM
-Unable to initialize a shared semaphore.
-.El
-.Sh SEE ALSO
-.Xr sem_destroy 3 ,
-.Xr sem_post 3 ,
-.Xr sem_trywait 3 ,
-.Xr sem_wait 3 ,
-.Xr sem 4
-.Sh STANDARDS
-The
-.Fn sem_init
-function conforms to
-.St -p1003.1-96 .
-.Pp
-This implementation does not support shared semaphores, and reports this fact
-by setting
-.Va errno
-to
-.Er EPERM .
-This is perhaps a stretch of the intention of POSIX, but is
-compliant, with the caveat that
-.Fn sem_init
-always reports a permissions error when an attempt to create a shared semaphore
-is made.
diff --git a/lib/libc/gen/sem_open.3 b/lib/libc/gen/sem_open.3
deleted file mode 100644
index 6beee26d511b..000000000000
--- a/lib/libc/gen/sem_open.3
+++ /dev/null
@@ -1,227 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd January 15, 2003
-.Dt SEM_OPEN 3
-.Os
-.Sh NAME
-.Nm sem_open ,
-.Nm sem_close ,
-.Nm sem_unlink
-.Nd named semaphore operations
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In semaphore.h
-.Ft sem_t *
-.Fn sem_open "const char *name" "int oflag" "..."
-.Ft int
-.Fn sem_close "sem_t *sem"
-.Ft int
-.Fn sem_unlink "const char *name"
-.Sh DESCRIPTION
-The
-.Fn sem_open
-function creates or opens the named semaphore specified by
-.Fa name .
-The returned semaphore may be used in subsequent calls to
-.Fn sem_getvalue ,
-.Fn sem_wait ,
-.Fn sem_trywait ,
-.Fn sem_post
-and
-.Fn sem_close .
-.Pp
-The following bits may be set in the
-.Fa oflag
-argument:
-.Bl -tag -width ".Dv O_CREAT"
-.It Dv O_CREAT
-Create the semaphore if it does not already exist.
-.Pp
-The third argument to the call to
-.Fn sem_open
-must be of type
-.Vt mode_t
-and specifies the mode for the semaphore.
-Only the
-.Dv S_IWUSR ,
-.Dv S_IWGRP ,
-and
-.Dv S_IWOTH
-bits are examined;
-it is not possible to grant only
-.Dq read
-permission on a semaphore.
-The mode is modified according to the process's file creation
-mask; see
-.Xr umask 2 .
-.Pp
-The fourth argument must be an
-.Vt "unsigned int"
-and specifies the initial value for the semaphore,
-and must be no greater than
-.Dv SEM_VALUE_MAX .
-.It Dv O_EXCL
-Create the semaphore if it does not exist.
-If the semaphore already exists,
-.Fn sem_open
-will fail.
-This flag is ignored unless
-.Dv O_CREAT
-is also specified.
-.El
-.Pp
-The
-.Fn sem_close
-function closes a named semaphore that was opened by a call to
-.Fn sem_open .
-.Pp
-The
-.Fn sem_unlink
-function removes the semaphore named
-.Fa name .
-Resources allocated to the semaphore are only deallocated when all
-processes that have the semaphore open close it.
-.Sh RETURN VALUES
-If successful,
-the
-.Fn sem_open
-function returns the address of the opened semaphore.
-If the same
-.Fa name
-argument is given to multiple calls to
-.Fn sem_open
-by the same process without an intervening call to
-.Fn sem_close ,
-the same address is returned each time.
-If the semaphore cannot be opened,
-.Fn sem_open
-returns
-.Dv SEM_FAILED
-and the global variable
-.Va errno
-is set to indicate the error.
-.Pp
-.Rv -std sem_close sem_unlink
-.Sh ERRORS
-The
-.Fn sem_open
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EACCES
-The semaphore exists and the permissions specified by
-.Fa oflag
-at the time it was created deny access to the this process.
-.It Bq Er EACCES
-The semaphore does not exist, but permission to create it is denied.
-.It Bq Er EEXIST
-.Dv O_CREAT
-and
-.Dv O_EXCL
-are set but the semaphore already exists.
-.It Bq Er EINTR
-The call was interrupted by a signal.
-.It Bq Er EINVAL
-The
-.Fn sem_open
-operation is not supported for the given
-.Fa name .
-.It Bq Er EINVAL
-The
-.Fa value
-argument is greater than
-.Dv SEM_VALUE_MAX .
-.\"FreeBSD never returns EMFILE
-.\".It Bq Er EMFILE
-.\"Too many semaphores are in use by this process.
-.It Bq Er ENAMETOOLONG
-The
-.Fa name
-argument is too long.
-.It Bq Er ENFILE
-The system limit on semaphores has been reached.
-.It Bq Er ENOENT
-.Dv O_CREAT
-is set but the named semaphore does not exist.
-.It Bq Er ENOSPC
-There is not enough space to create the semaphore.
-.El
-.Pp
-The
-.Fn sem_close
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The
-.Fa sem
-argument is not a valid semaphore.
-.El
-.Pp
-The
-.Fn sem_unlink
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EACCES
-Permission is denied to unlink the semaphore.
-.It Bq Er ENAMETOOLONG
-The specified
-.Fa name
-is too long.
-.It Bq Er ENOENT
-The named semaphore does not exist.
-.El
-.Sh SEE ALSO
-.Xr close 2 ,
-.Xr open 2 ,
-.Xr umask 2 ,
-.Xr unlink 2 ,
-.Xr sem_getvalue 3 ,
-.Xr sem_post 3 ,
-.Xr sem_trywait 3 ,
-.Xr sem_wait 3 ,
-.Xr sem 4
-.Sh STANDARDS
-The
-.Fn sem_open ,
-.Fn sem_close ,
-and
-.Fn sem_unlink
-functions conform to
-.St -p1003.1-96 .
-.Sh HISTORY
-Support for named semaphores first appeared in
-.Fx 5.0 .
-.Sh BUGS
-This implementation places strict requirements on the value of
-.Fa name :
-it must begin with a slash
-.Pq Ql / ,
-contain no other slash characters,
-and be less than 14 characters in length
-not including the terminating null character.
diff --git a/lib/libc/gen/sem_post.3 b/lib/libc/gen/sem_post.3
deleted file mode 100644
index 33348657322f..000000000000
--- a/lib/libc/gen/sem_post.3
+++ /dev/null
@@ -1,71 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd February 15, 2000
-.Dt SEM_POST 3
-.Os
-.Sh NAME
-.Nm sem_post
-.Nd increment (unlock) a semaphore
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In semaphore.h
-.Ft int
-.Fn sem_post "sem_t *sem"
-.Sh DESCRIPTION
-The
-.Fn sem_post
-function increments (unlocks) the semaphore pointed to by
-.Fa sem .
-If there are threads blocked on the semaphore when
-.Fn sem_post
-is called, then the highest priority thread that has been blocked the longest on
-the semaphore will be allowed to return from
-.Fn sem_wait .
-.Pp
-.Fn sem_post
-is signal-reentrant and may be called within signal handlers.
-.Sh RETURN VALUES
-.Rv -std sem_post
-.Sh ERRORS
-.Fn sem_post
-will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-.Fa sem
-points to an invalid semaphore.
-.El
-.Sh SEE ALSO
-.Xr sem_trywait 3 ,
-.Xr sem_wait 3 ,
-.Xr sem 4
-.Sh STANDARDS
-.Fn sem_post
-conforms to
-.St -p1003.1-96 .
diff --git a/lib/libc/gen/sem_wait.3 b/lib/libc/gen/sem_wait.3
deleted file mode 100644
index 735061ebc86c..000000000000
--- a/lib/libc/gen/sem_wait.3
+++ /dev/null
@@ -1,89 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd February 15, 2000
-.Dt SEM_WAIT 3
-.Os
-.Sh NAME
-.Nm sem_wait ,
-.Nm sem_trywait
-.Nd decrement (lock) a semaphore
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In semaphore.h
-.Ft int
-.Fn sem_wait "sem_t *sem"
-.Ft int
-.Fn sem_trywait "sem_t *sem"
-.Sh DESCRIPTION
-The
-.Fn sem_wait
-function decrements (locks) the semaphore pointed to by
-.Fa sem ,
-but blocks if the value of
-.Fa sem
-is zero, until the value is non-zero and the value can be decremented.
-.Pp
-The
-.Fn sem_trywait
-function decrements (locks) the semaphore pointed to by
-.Fa sem
-only if the value is non-zero. Otherwise, the semaphore is not decremented and
-an error is returned.
-.Sh RETURN VALUES
-.Rv -std
-.Sh ERRORS
-The
-.Fn sem_wait
-and
-.Fn sem_trywait
-functions will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-.Fa sem
-points to an invalid semaphore.
-.El
-.Pp
-Additionally,
-.Fn sem_trywait
-will fail if:
-.Bl -tag -width Er
-.It Bq Er EAGAIN
-The semaphore value was zero, and thus could not be decremented.
-.El
-.Sh SEE ALSO
-.Xr sem_post 3 ,
-.Xr sem 4
-.Sh STANDARDS
-The
-.Fn sem_wait
-and
-.Fn sem_trywait
-functions conform to
-.St -p1003.1-96 .
diff --git a/lib/libc/locale/euc.5 b/lib/libc/locale/euc.5
deleted file mode 100644
index 548d9caece8a..000000000000
--- a/lib/libc/locale/euc.5
+++ /dev/null
@@ -1,242 +0,0 @@
-.\" Copyright (c) 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Paul Borman at Krystal Technologies.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)euc.4 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
-.Dd June 4, 1993
-.Dt EUC 4
-.Os
-.Sh NAME
-.Nm euc
-.Nd EUC encoding of runes
-.Sh SYNOPSIS
-.Nm ENCODING
-.Qq EUC
-.Pp
-.Nm VARIABLE
-.Ar len1
-.Ar mask1
-.Ar len2
-.Ar mask2
-.Ar len3
-.Ar mask3
-.Ar len4
-.Ar mask4
-.Ar mask
-.Sh DESCRIPTION
-The
-.Nm EUC
-encoding is provided for compatibility with
-.Ux
-based systems.
-See
-.Xr mklocale 1
-for a complete description of the
-.Ev LC_CTYPE
-source file format.
-.Pp
-.Nm EUC
-implements a system of 4 multibyte codesets.
-A multibyte character in the first codeset consists of
-.Ar len1
-bytes starting with a byte in the range of 0x00 to 0x7f.
-To allow use of ASCII,
-.Ar len1
-is always 1.
-A multibyte character in the second codeset consists of
-.Ar len2
-bytes starting with a byte in the range of 0x80-0xff excluding 0x8e and 0x8f.
-A multibyte character in the third codeset consists of
-.Ar len3
-bytes starting with the byte 0x8e.
-A multibyte character in the fourth codeset consists of
-.Ar len4
-bytes starting with the byte 0x8f.
-.Pp
-The
-.Ev rune_t
-encoding of
-.Nm EUC
-multibyte characters is dependent on the
-.Ar len
-and
-.Ar mask
-arguments.
-First, the bytes are moved into a
-.Ev rune_t
-as follows:
-.Bd -literal
-byte0 << ((\fIlen\fPN-1) * 8) | byte1 << ((\fIlen\fPN-2) * 8) | ... | byte\fIlen\fPN-1
-.Ed
-.Pp
-The result is then ANDed with
-.Ar ~mask
-and ORed with
-.Ar maskN .
-Codesets 2 and 3 are special in that the leading byte (0x8e or 0x8f) is
-first removed and the
-.Ar lenN
-argument is reduced by 1.
-.Pp
-For example, the Japanese locale has the following
-.Ev VARIABLE
-line:
-.Bd -literal
-VARIABLE 1 0x0000 2 0x8080 2 0x0080 3 0x8000 0x8080
-.Ed
-.Pp
-Codeset 1 consists of the values 0x0000 - 0x007f.
-.Pp
-Codeset 2 consists of the values who have the bits 0x8080 set.
-.Pp
-Codeset 3 consists of the values 0x0080 - 0x00ff.
-.Pp
-Codeset 4 consists of the values 0x8000 - 0xff7f excluding the values
-which have the 0x0080 bit set.
-.Pp
-Notice that the global
-.Ar mask
-is set to 0x8080, this implies that from those 2 bits the codeset can
-be determined.
-.Sh "EXAMPLE - Japanese Locale"
-This is a complete example of an
-.Ev LC_CTYPE
-source file for the Japanese locale
-.Bd -literal
-/*
- * Japanese LOCALE_CTYPE definitions using EUC of JIS character sets
- */
-
-ENCODING "EUC"
-
-/* JIS JIS JIS */
-/* X201 X208 X201 */
-/* 00-7f 84-fe */
-
-VARIABLE 1 0x0000 2 0x8080 2 0x0080 3 0x8000 0x8080
-
-/*
- * Code Set 1
- */
-ALPHA 'A' - 'Z' 'a' - 'z'
-CONTROL 0x00 - 0x1f 0x7f
-DIGIT '0' - '9'
-GRAPH 0x21 - 0x7e
-LOWER 'a' - 'z'
-PUNCT 0x21 - 0x2f 0x3a - 0x40 0x5b - 0x60 0x7b - 0x7e
-SPACE 0x09 - 0x0d 0x20
-UPPER 'A' - 'Z'
-XDIGIT 'a' - 'f' 'A' - 'F'
-BLANK ' ' '\t'
-PRINT 0x20 - 0x7e
-
-MAPLOWER < 'A' - 'Z' : 'a' > < 'a' - 'z' : 'a' >
-MAPUPPER < 'A' - 'Z' : 'A' > < 'a' - 'z' : 'A' >
-TODIGIT < '0' - '9' : 0 >
-TODIGIT < 'A' - 'F' : 10 > < 'a' - 'f' : 10 >
-
-/*
- * Code Set 2
- */
-
-SPACE 0xa1a1
-PHONOGRAM 0xa1bc
-SPECIAL 0xa1a2 - 0xa1fe
-PUNCT 0xa1a2 - 0xa1f8 /* A few too many in here... */
-
-SPECIAL 0xa2a1 - 0xa2ae 0xa2ba - 0xa2c1 0xa2ca - 0xa2d0 0xa2dc - 0xa2ea
-SPECIAL 0xa2f2 - 0xa2f9 0xa2fe
-
-DIGIT 0xa3b0 - 0xa3b9
-UPPER 0xa3c1 - 0xa3da /* Romaji */
-LOWER 0xa3e1 - 0xa3fa /* Romaji */
-MAPLOWER < 0xa3c1 - 0xa3da : 0xa3e1 > /* English */
-MAPLOWER < 0xa3e1 - 0xa3fa : 0xa3e1 > /* English */
-MAPUPPER < 0xa3c1 - 0xa3da : 0xa3c1 >
-MAPUPPER < 0xa3e1 - 0xa3fa : 0xa3c1 >
-
-XDIGIT 0xa3c1 - 0xa3c6 0xa3e1 - 0xa3e6
-
-TODIGIT < 0xa3b0 - 0xa3b9 : 0 >
-TODIGIT < 0xa3c1 - 0xa3c6 : 10 > < 0xa3e1 - 0xa3e6 : 10 >
-
-PHONOGRAM 0xa4a1 - 0xa4f3
-PHONOGRAM 0xa5a1 - 0xa5f6
-
-UPPER 0xa6a1 - 0xa6b8 /* Greek */
-LOWER 0xa6c1 - 0xa6d8 /* Greek */
-MAPLOWER < 0xa6a1 - 0xa6b8 : 0xa6c1 > < 0xa6c1 - 0xa6d8 : 0xa6c1 >
-MAPUPPER < 0xa6a1 - 0xa6b8 : 0xa6a1 > < 0xa6c1 - 0xa6d8 : 0xa6a1 >
-
-UPPER 0xa7a1 - 0xa7c1 /* Cyrillic */
-LOWER 0xa7d1 - 0xa7f1 /* Cyrillic */
-MAPLOWER < 0xa7a1 - 0xa7c1 : 0xa7d1 > < 0xa7d1 - 0xa7f1 : 0xa7d1 >
-MAPUPPER < 0xa7a1 - 0xa7c1 : 0xa7a1 > < 0xa7d1 - 0xa7f1 : 0xa7a1 >
-
-SPECIAL 0xa8a1 - 0xa8c0
-
-IDEOGRAM 0xb0a1 - 0xb0fe 0xb1a1 - 0xb1fe 0xb2a1 - 0xb2fe
-IDEOGRAM 0xb3a1 - 0xb3fe 0xb4a1 - 0xb4fe 0xb5a1 - 0xb5fe
-IDEOGRAM 0xb6a1 - 0xb6fe 0xb7a1 - 0xb7fe 0xb8a1 - 0xb8fe
-IDEOGRAM 0xb9a1 - 0xb9fe 0xbaa1 - 0xbafe 0xbba1 - 0xbbfe
-IDEOGRAM 0xbca1 - 0xbcfe 0xbda1 - 0xbdfe 0xbea1 - 0xbefe
-IDEOGRAM 0xbfa1 - 0xbffe 0xc0a1 - 0xc0fe 0xc1a1 - 0xc1fe
-IDEOGRAM 0xc2a1 - 0xc2fe 0xc3a1 - 0xc3fe 0xc4a1 - 0xc4fe
-IDEOGRAM 0xc5a1 - 0xc5fe 0xc6a1 - 0xc6fe 0xc7a1 - 0xc7fe
-IDEOGRAM 0xc8a1 - 0xc8fe 0xc9a1 - 0xc9fe 0xcaa1 - 0xcafe
-IDEOGRAM 0xcba1 - 0xcbfe 0xcca1 - 0xccfe 0xcda1 - 0xcdfe
-IDEOGRAM 0xcea1 - 0xcefe 0xcfa1 - 0xcfd3 0xd0a1 - 0xd0fe
-IDEOGRAM 0xd1a1 - 0xd1fe 0xd2a1 - 0xd2fe 0xd3a1 - 0xd3fe
-IDEOGRAM 0xd4a1 - 0xd4fe 0xd5a1 - 0xd5fe 0xd6a1 - 0xd6fe
-IDEOGRAM 0xd7a1 - 0xd7fe 0xd8a1 - 0xd8fe 0xd9a1 - 0xd9fe
-IDEOGRAM 0xdaa1 - 0xdafe 0xdba1 - 0xdbfe 0xdca1 - 0xdcfe
-IDEOGRAM 0xdda1 - 0xddfe 0xdea1 - 0xdefe 0xdfa1 - 0xdffe
-IDEOGRAM 0xe0a1 - 0xe0fe 0xe1a1 - 0xe1fe 0xe2a1 - 0xe2fe
-IDEOGRAM 0xe3a1 - 0xe3fe 0xe4a1 - 0xe4fe 0xe5a1 - 0xe5fe
-IDEOGRAM 0xe6a1 - 0xe6fe 0xe7a1 - 0xe7fe 0xe8a1 - 0xe8fe
-IDEOGRAM 0xe9a1 - 0xe9fe 0xeaa1 - 0xeafe 0xeba1 - 0xebfe
-IDEOGRAM 0xeca1 - 0xecfe 0xeda1 - 0xedfe 0xeea1 - 0xeefe
-IDEOGRAM 0xefa1 - 0xeffe 0xf0a1 - 0xf0fe 0xf1a1 - 0xf1fe
-IDEOGRAM 0xf2a1 - 0xf2fe 0xf3a1 - 0xf3fe 0xf4a1 - 0xf4a4
-/*
- * This is for Code Set 3, half-width kana
- */
-SPECIAL 0xa1 - 0xdf
-PHONOGRAM 0xa1 - 0xdf
-CONTROL 0x84 - 0x97 0x9b - 0x9f 0xe0 - 0xfe
-.Ed
-.Sh "SEE ALSO"
-.Xr mklocale 1 ,
-.Xr setlocale 3
diff --git a/lib/libc/locale/utf2.5 b/lib/libc/locale/utf2.5
deleted file mode 100644
index f41c0f922dd9..000000000000
--- a/lib/libc/locale/utf2.5
+++ /dev/null
@@ -1,94 +0,0 @@
-.\" Copyright (c) 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Paul Borman at Krystal Technologies.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)utf2.4 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
-.Dd October 11, 2002
-.Dt UTF2 4
-.Os
-.Sh NAME
-.Nm utf2
-.Nd "Universal character set Transformation Format encoding of runes
-.Sh SYNOPSIS
-.Nm ENCODING
-.Qq UTF2
-.Sh DESCRIPTION
-.Bf Em
-The UTF2 encoding has been deprecated in favour of UTF-8.
-.Ef
-New applications should not use UTF2.
-.Pp
-The
-.Nm UTF2
-encoding is based on a proposed X-Open multibyte
-\s-1FSS-UCS-TF\s+1 (File System Safe Universal Character Set Transformation Format) encoding as used in
-.Sy "Plan 9 from Bell Labs" .
-Although it is capable of representing more than 16 bits,
-the current implementation is limited to 16 bits as defined by the
-Unicode Standard.
-.Pp
-.Nm UTF2
-representation is backwards compatible with ASCII, so 0x00-0x7f refer to the
-ASCII character set. The multibyte encoding of runes between 0x0080 and 0xffff
-consist entirely of bytes whose high order bit is set. The actual
-encoding is represented by the following table:
-.Bd -literal
-[0x0000 - 0x007f] [00000000.0bbbbbbb] -> 0bbbbbbb
-[0x0080 - 0x07ff] [00000bbb.bbbbbbbb] -> 110bbbbb, 10bbbbbb
-[0x0800 - 0xffff] [bbbbbbbb.bbbbbbbb] -> 1110bbbb, 10bbbbbb, 10bbbbbb
-.Ed
-.Pp
-If more than a single representation of a value exists (for example,
-0x00; 0xC0 0x80; 0xE0 0x80 0x80) the shortest representation is always
-used (but the longer ones will be correctly decoded).
-.Pp
-The final three encodings provided by X-Open:
-.Bd -literal
-[00000000.000bbbbb.bbbbbbbb.bbbbbbbb] ->
- 11110bbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
-
-[000000bb.bbbbbbbb.bbbbbbbb.bbbbbbbb] ->
- 111110bb, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
-
-[0bbbbbbb.bbbbbbbb.bbbbbbbb.bbbbbbbb] ->
- 1111110b, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
-.Ed
-.Pp
-which provides for the entire proposed ISO-10646 31 bit standard are currently
-not implemented.
-.Sh "SEE ALSO"
-.Xr mklocale 1 ,
-.Xr setlocale 3 ,
-.Xr utf8 5
diff --git a/lib/libc/posix1e/mac_is_present.3 b/lib/libc/posix1e/mac_is_present.3
deleted file mode 100644
index 4f9e0fe3ef58..000000000000
--- a/lib/libc/posix1e/mac_is_present.3
+++ /dev/null
@@ -1,81 +0,0 @@
-.\" Copyright (c) 2002 Networks Associates Technology, Inc.
-.\" All rights reserved.
-.\"
-.\" This software was developed for the FreeBSD Project by Chris
-.\" Costello at Safeport Network Services and NAI Labs, the Security
-.\" Research Division of Network Associates, Inc. under DARPA/SPAWAR
-.\" contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
-.\" research program.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that 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 AUTHORS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (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$
-.\"
-.Dd January 9, 2002
-.Dt MAC_IS_PRESENT_NP 3
-.Os
-.Sh NAME
-.Nm mac_is_present_np
-.Nd report whether the running system has MAC support
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/mac.h
-.Ft int
-.Fn mac_is_present "const char *policyname"
-.Sh DESCRIPTION
-The
-.Fn mac_is_present_np
-function determines whether the currently-running kernel supports MAC for
-a given policy or not.
-If
-.Fa policyname
-is
-.No non- Ns Dv NULL ,
-the presence of the named policy
-(e.g.\&
-.Dq Li biba ,
-.Dq Li mls ,
-.Dq Li te )
-is checked, otherwise the presence of any MAC policies at all is checked.
-.Sh RETURN VALUES
-If the system supports the given MAC policy, the value 1 is returned.
-If the specified MAC policy is not supported, the value 0 is returned.
-If an error occurs, the value \-1 is returned.
-.Sh ERRORS
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value of
-.Fa policyname
-is not valid.
-.It Bq Er ENOMEM
-Insufficient memory was available to allocate internal storage.
-.El
-.Sh SEE ALSO
-.Xr mac 3 ,
-.Xr mac_free 3 ,
-.Xr mac_get 3 ,
-.Xr mac_prepare 3 ,
-.Xr mac_set 3 ,
-.Xr mac_text 3 ,
-.Xr mac 4 ,
-.Xr mac 9
diff --git a/lib/libc/sys/shm_open.2 b/lib/libc/sys/shm_open.2
deleted file mode 100644
index 061913311a3f..000000000000
--- a/lib/libc/sys/shm_open.2
+++ /dev/null
@@ -1,193 +0,0 @@
-.\"
-.\" Copyright 2000 Massachusetts Institute of Technology
-.\"
-.\" Permission to use, copy, modify, and distribute this software and
-.\" its documentation for any purpose and without fee is hereby
-.\" granted, provided that both the above copyright notice and this
-.\" permission notice appear in all copies, that both the above
-.\" copyright notice and this permission notice appear in all
-.\" supporting documentation, and that the name of M.I.T. not be used
-.\" in advertising or publicity pertaining to distribution of the
-.\" software without specific, written prior permission. M.I.T. makes
-.\" no representations about the suitability of this software for any
-.\" purpose. It is provided "as is" without express or implied
-.\" warranty.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
-.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
-.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
-.\" SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
-.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
-.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd March 24, 2000
-.Dt SHM_OPEN 3
-.Os
-.Sh NAME
-.Nm shm_open
-.Nd open or create a shared memory object
-.Nm shm_unlink
-.Nd remove a shared memory object
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In sys/mman.h
-.Ft int
-.Fn shm_open "const char *path" "int flags" "mode_t mode"
-.Ft int
-.Fn shm_unlink "const char *path"
-.Sh DESCRIPTION
-The
-.Fn shm_open
-function opens (or optionally creates) a
-.Tn POSIX
-shared memory object named
-.Fa path .
-The
-.Fn shm_unlink
-function removes a shared memory object named
-.Fa path .
-.Pp
-In the
-.Fx
-implementation,
-.Tn POSIX
-shared memory objects are implemented as ordinary files.
-The
-.Fn shm_open
-and
-.Fn shm_unlink
-act as wrappers around the
-.Xr open 2
-and
-.Xr unlink 2
-routines, and
-.Fa path ,
-.Fa flags ,
-and
-.Fa mode
-arguments are as specified for those functions.
-The
-.Fa flags
-argument is checked to ensure that the access mode specified is not
-.Dv O_WRONLY
-(which is not defined for shared memory objects).
-.Pp
-In addition, the
-.Fx
-implementation causes
-.Fn mmap
-of a descriptor returned by
-.Fn shm_open
-to behave as if the
-.Dv MAP_NOSYNC
-flag had been specified to
-.Xr mmap 2 .
-(It does so by setting a special file flag using
-.Xr fcntl 2 . )
-.Pp
-The
-.Fn shm_unlink
-function makes no effort to ensure that
-.Fa path
-refers to a shared memory object.
-.Sh COMPATIBILITY
-The
-.Fa path
-argument does not necessarily represent a pathname (although it does in this
-and most other implementations).
-Two processes opening the same
-.Fa path
-are guaranteed to access the same shared memory object if and only if
-.Fa path
-begins with a slash
-.Pq Ql \&/
-character.
-.Pp
-Only the
-.Dv O_RDONLY ,
-.Dv O_RDWR ,
-.Dv O_CREAT ,
-.Dv O_EXCL ,
-and
-.Dv O_TRUNC
-flags may be used in portable programs.
-.Pp
-The result of using
-.Xr open 2 ,
-.Xr read 2 ,
-or
-.Xr write 2
-on a shared memory object, or on the descriptor returned by
-.Fn shm_open ,
-is undefined.
-It is also undefined whether the shared memory object itself, or its
-contents, persist across reboots.
-.Sh RETURN VALUES
-If successful,
-.Fn shm_open
-returns a non-negative integer;
-.Fn shm_unlink
-returns zero.
-Both functions return -1 on failure, and set
-.Va errno
-to indicate the error.
-.Sh ERRORS
-The
-.Fn shm_open
-and
-.Fn shm_unlink
-functions can fail with any error defined for
-.Fn open
-and
-.Fn unlink ,
-respectively. In addition, the following errors are defined for
-.Fn shm_open :
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The object named by
-.Fa path
-is not a shared memory object
-(i.e., it is not a regular file).
-.It Bq Er EINVAL
-The
-.Fa flags
-argument to
-.Fn shm_open
-specifies an access mode of
-.Dv O_WRONLY .
-.El
-.Sh SEE ALSO
-.Xr mmap 2 ,
-.Xr munmap 2 ,
-.Xr open 2 ,
-.Xr unlink 2
-.Sh STANDARDS
-The
-.Fn shm_open
-and
-.Fn shm_unlink
-functions are believed to conform to
-.St -p1003.1b-93 .
-.Sh HISTORY
-The
-.Fn shm_open
-and
-.Fn shm_unlink
-functions first appeared in
-.Fx 4.3 .
-.Sh AUTHORS
-.An Garrett A. Wollman Aq wollman@FreeBSD.org
-(C library support and this manual page)
-.Pp
-.An Matthew Dillon Aq dillon@FreeBSD.org
-.Pq Dv MAP_NOSYNC
diff --git a/lib/libc/sys/sigwait.2 b/lib/libc/sys/sigwait.2
deleted file mode 100644
index 3ff8a5299876..000000000000
--- a/lib/libc/sys/sigwait.2
+++ /dev/null
@@ -1,86 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd April 27, 2000
-.Dt SIGWAIT 3
-.Os
-.Sh NAME
-.Nm sigwait
-.Nd select a set of signals
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In signal.h
-.Ft int
-.Fn sigwait "const sigset_t * restrict set" "int * restrict sig"
-.Sh DESCRIPTION
-The
-.Fn sigwait
-function selects a set of signals, specified by
-.Fa set .
-If none of the selected signals are pending,
-.Fn sigwait
-waits until one or more of the selected signals has been generated.
-Then
-.Fn sigwait
-atomically clears one of the selected signals from the set of pending signals
-for the process and sets the location pointed to by
-.Fa sig
-to the signal number that was cleared.
-.Pp
-The signals specified by
-.Fa set
-should be blocked at the time of the call to
-.Fn sigwait .
-.Sh RETURN VALUES
-If successful,
-.Fn sigwait
-returns 0 and sets the location pointed to by
-.Fa sig
-to the cleared signal number.
-Otherwise, an error number is returned.
-.Sh ERRORS
-The
-.Fn sigwait
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-.Fa set
-specifies one or more invalid signal numbers.
-.El
-.Sh SEE ALSO
-.Xr sigaction 2 ,
-.Xr sigpending 2 ,
-.Xr sigsuspend 2 ,
-.Xr pause 3 ,
-.Xr pthread_sigmask 3
-.Sh STANDARDS
-The
-.Fn sigwait
-function conforms to
-.St -p1003.1-96
diff --git a/lib/libkse/Makefile b/lib/libkse/Makefile
deleted file mode 100644
index c25ccf4f6d2a..000000000000
--- a/lib/libkse/Makefile
+++ /dev/null
@@ -1,37 +0,0 @@
-# $FreeBSD$
-#
-# All library objects contain FreeBSD revision strings by default; they may be
-# excluded as a space-saving measure. To produce a library that does
-# not contain these strings, add -DSTRIP_FBSDID (see <sys/cdefs.h>) to CFLAGS
-# below. Note, there are no IDs for syscall stubs whose sources are generated.
-# To included legacy CSRG sccsid strings, add -DLIBC_SCCS and -DSYSLIBC_SCCS
-# (for system call stubs) to CFLAGS below. -DSYSLIBC_SCCS affects just the
-# system call stubs.
-LIB=kse
-SHLIB_MAJOR= 1
-CFLAGS+=-DPTHREAD_KERNEL
-CFLAGS+=-I${.CURDIR}/../libc/include -I${.CURDIR}/thread \
- -I${.CURDIR}/../../include
-CFLAGS+=-I${.CURDIR}/arch/${MACHINE_ARCH}/include
-CFLAGS+=-I${.CURDIR}/sys
-CFLAGS+=-I${.CURDIR}/../../libexec/rtld-elf
-CFLAGS+=-fno-builtin
-
-# Uncomment this if you want libpthread to contain debug information for
-# thread locking.
-CFLAGS+=-D_LOCK_DEBUG
-#CFLAGS+= -g
-
-LDADD+= -Wl,--version-script=${.CURDIR}/pthread.map
-
-# enable extra internal consistancy checks
-CFLAGS+=-D_PTHREADS_INVARIANTS -Wall
-
-AINC= -I${.CURDIR}/../libc/${MACHINE_ARCH} -I${.CURDIR}/thread
-PRECIOUSLIB= yes
-
-.include "${.CURDIR}/thread/Makefile.inc"
-.include "${.CURDIR}/sys/Makefile.inc"
-.include "${.CURDIR}/support/Makefile.inc"
-
-.include <bsd.lib.mk>
diff --git a/lib/libkse/arch/i386/i386/thr_enter_uts.S b/lib/libkse/arch/i386/i386/thr_enter_uts.S
deleted file mode 100644
index a617b72eccc6..000000000000
--- a/lib/libkse/arch/i386/i386/thr_enter_uts.S
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (c) 2002 Jonathan Mini <mini@freebsd.org>.
- * Copyright (c) 2001 Daniel Eischen <deischen@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. Neither the name of the author 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 DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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 <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * Where do we define these?
- */
-#define MC_SIZE 640 /* sizeof mcontext_t */
-#define UC_MC_OFFSET 16 /* offset to mcontext from ucontext */
-#define MC_LEN_OFFSET 80 /* offset to mc_len from mcontext */
-#define MC_FP_CW_OFFSET 96 /* offset to FP control word */
-#define MC_FPFMT_OFFSET 84 /* offset to mc_fpformat from mcontext */
-#define MC_FPFMT_NODEV 0x10000
-#define MC_OWNEDFP_OFFSET 88 /* offset to mc_ownedfp from mcontext */
-#define MC_OWNEDFP_NONE 0x20000
-#define KM_STACK_SP_OFFSET 36 /* offset to km_stack.ss_sp */
-#define KM_STACK_SIZE_OFFSET 40 /* offset to km_stack.ss_sp */
-#define KM_FUNC_OFFSET 32 /* offset to km_func */
-
-/*
- * int _thread_enter_uts(kse_thr_mailbox *tm, kse_mailbox *km);
- *
- * Returns 0 on success, -1 otherwise.
- */
-ENTRY(_thread_enter_uts)
- movl 4(%esp), %eax /* get address of context */
- cmpl $0, %eax /* check for null pointer */
- jne 1f
- movl $-1, %eax
- jmp 2f
-1: pushl %edx /* save value of edx */
- movl %eax, %edx /* get address of context */
- addl $UC_MC_OFFSET, %edx /* add offset to mcontext */
- /*movl %gs, 4(%edx)*/ /* we don't touch %gs */
- movl %fs, 8(%edx)
- movl %es, 12(%edx)
- movl %ds, 16(%edx)
- movl %edi, 20(%edx)
- movl %esi, 24(%edx)
- movl %ebp, 28(%edx)
- movl %ebx, 36(%edx)
- movl $0, 48(%edx) /* store successful return in eax */
- popl %eax /* get saved value of edx */
- movl %eax, 40(%edx) /* save edx */
- movl %ecx, 44(%edx)
- movl (%esp), %eax /* get return address */
- movl %eax, 60(%edx) /* save return address */
- movl %ss, 76(%edx)
- /*
- * Don't save floating point registers here.
- *
- * This is an explicit call to get the current context, so
- * the caller is done with the floating point registers.
- * Contexts formed by involuntary switches, such as signal delivery,
- * have floating point registers saved by the kernel.
- */
- fnstcw MC_FP_CW_OFFSET(%edx)
- movl $MC_OWNEDFP_NONE, MC_OWNEDFP_OFFSET(%edx) /* no FP */
- movl $MC_FPFMT_NODEV, MC_FPFMT_OFFSET(%edx) /* no FP */
- pushfl /* get eflags */
- popl %eax
- movl %eax, 68(%edx) /* store eflags */
- movl %esp, %eax /* setcontext pushes the return */
- addl $4, %eax /* address onto the top of the */
- movl %eax, 72(%edx) /* stack; account for this */
- movl $MC_SIZE, MC_LEN_OFFSET(%edx) /* context is now valid */
- movl 8(%esp), %edx /* get address of mailbox */
- movl KM_STACK_SP_OFFSET(%edx), %eax /* get bottom of stack */
- addl KM_STACK_SIZE_OFFSET(%edx), %eax /* add length */
- movl %eax, %esp /* switch to the uts's stack */
- pushl %edx /* push the address of the mailbox */
- pushl KM_FUNC_OFFSET(%edx) /* .. the uts can return to itself */
- pushl KM_FUNC_OFFSET(%edx) /* push the address of the uts func */
-2: ret
-
diff --git a/lib/libkse/arch/i386/i386/thr_getcontext.S b/lib/libkse/arch/i386/i386/thr_getcontext.S
deleted file mode 100644
index 82066efcde62..000000000000
--- a/lib/libkse/arch/i386/i386/thr_getcontext.S
+++ /dev/null
@@ -1,157 +0,0 @@
-/*-
- * Copyright (c) 2001 Daniel Eischen <deischen@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. Neither the name of the author 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 DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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 <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * Where do we define these?
- */
-#define UC_MC_OFFSET 16 /* offset to mcontext from ucontext */
-#define MC_LEN_OFFSET 80 /* offset to mc_len from mcontext */
-#define MC_LEN 640 /* mc_len <machine/ucontext.h> */
-#define MC_FPFMT_OFFSET 84
-#define MC_FPFMT_NODEV 0x10000
-#define MC_FPFMT_387 0x10001
-#define MC_FPFMT_XMM 0x10002
-#define MC_OWNEDFP_OFFSET 88
-#define MC_OWNEDFP_NONE 0x20000
-#define MC_OWNEDFP_FPU 0x20001
-#define MC_OWNEDFP_PCB 0x20002
-#define MC_FPREGS_OFFSET 96 /* offset to FP regs from mcontext */
-#define MC_FP_CW_OFFSET 96 /* offset to FP control word */
-
-/*
- * int thr_setcontext(ucontext_t *ucp)
- *
- * Restores the context in ucp.
- *
- * Returns 0 if there are no errors; -1 otherwise
- */
- .weak CNAME(_thr_setcontext)
- .set CNAME(_thr_setcontext),CNAME(__thr_setcontext)
-ENTRY(__thr_setcontext)
- movl 4(%esp), %eax /* get address of context and sigset */
- cmpl $0, %eax /* check for null pointer */
- jne 1f
- movl $-1, %eax
- jmp 7f
-1: addl $UC_MC_OFFSET, %eax /* add offset to mcontext */
- cmpl $MC_LEN, MC_LEN_OFFSET(%eax) /* is context valid? */
- je 2f
- movl $-1, %eax /* bzzzt, invalid context */
- jmp 7f
-/*2: movl 4(%edx), %gs*/ /* we don't touch %gs */
-2: movl 8(%edx), %fs
- movl 12(%edx), %es
- movl 16(%edx), %ds
- movl 76(%edx), %ss
- movl 20(%edx), %edi
- movl 24(%edx), %esi
- movl 28(%edx), %ebp
- movl %esp, %ecx /* save current stack in ecx */
- movl 72(%edx), %esp /* switch to context defined stack */
- movl 60(%edx), %eax /* put return address at top of stack */
- pushl %eax
- movl 44(%edx), %eax /* get ecx from context, */
- pushl %eax /* push on top of stack */
- movl 48(%edx), %eax /* get eax from context, */
- pushl %eax /* push on top of stack */
- /*
- * if (mc_fpowned == MC_OWNEDFP_FPU || mc_fpowned == MC_OWNEDFP_PCB) {
- * if (mc_fpformat == MC_FPFMT_387)
- * restore 387 FP register format
- * else if (mc_fpformat == MC_FPFMT_XMM)
- * restore XMM/SSE FP register format
- * }
- */
- cmpl $MC_OWNEDFP_FPU, MC_OWNEDFP_OFFSET(%edx)
- je 3f
- cmpl $MC_OWNEDFP_PCB, MC_OWNEDFP_OFFSET(%edx)
- jne 5f
-3: cmpl $MC_FPFMT_387, MC_FPFMT_OFFSET(%edx)
- jne 5f
- frstor MC_FPREGS_OFFSET(%edx) /* restore 387 FP regs */
- jmp 5f
-4: cmpl $MC_FPFMT_XMM, MC_FPFMT_OFFSET(%edx)
- jne 5f
- fxrstor MC_FPREGS_OFFSET(%edx) /* restore XMM FP regs */
- jmp 6f
-5: fninit
- fldcw MC_FP_CW_OFFSET(%edx)
-6: pushl 68(%edx) /* restore flags register */
- popf
- movl 36(%edx), %ebx /* restore ebx and edx */
- movl 40(%edx), %edx
- popl %eax /* restore eax and ecx last */
- popl %ecx
-7: ret
-
-/*
- * int thr_getcontext(ucontext_t *ucp);
- *
- * Returns 0 if there are no errors; -1 otherwise
- */
- .weak CNAME(_thr_getcontext)
- .set CNAME(_thr_getcontext),CNAME(__thr_getcontext)
-ENTRY(__thr_getcontext)
- movl 4(%esp), %eax /* get address of context */
- cmpl $0, %eax /* check for null pointer */
- jne 1f
- movl $-1, %eax
- jmp 2f
- movl 4(%esp), %eax /* get address of context and sigset */
-1: pushl %edx /* save value of edx */
- movl 8(%esp), %edx /* get address of context */
- addl $UC_MC_OFFSET, %edx /* add offset to mcontext */
- /*movl %gs, 4(%edx)*/ /* we don't touch %gs */
- movl %fs, 8(%edx)
- movl %es, 12(%edx)
- movl %ds, 16(%edx)
- movl %ss, 76(%edx)
- movl %edi, 20(%edx)
- movl %esi, 24(%edx)
- movl %ebp, 28(%edx)
- movl %ebx, 36(%edx)
- movl $0, 48(%edx) /* store successful return in eax */
- popl %eax /* get saved value of edx */
- movl %eax, 40(%edx) /* save edx */
- movl %ecx, 44(%edx)
- movl (%esp), %eax /* get return address */
- movl %eax, 60(%edx) /* save return address */
- fnstcw MC_FP_CW_OFFSET(%edx)
- movl $MC_LEN, MC_LEN_OFFSET(%edx)
- movl $MC_FPFMT_NODEV, MC_FPFMT_OFFSET(%edx) /* no FP */
- movl $MC_OWNEDFP_NONE, MC_OWNEDFP_OFFSET(%edx) /* no FP */
- pushfl
- popl %eax /* get eflags */
- movl %eax, 68(%edx) /* store eflags */
- movl %esp, %eax /* setcontext pushes the return */
- addl $4, %eax /* address onto the top of the */
- movl %eax, 72(%edx) /* stack; account for this */
- movl 40(%edx), %edx /* restore edx -- is this needed? */
- xorl %eax, %eax /* return 0 */
-2: ret
diff --git a/lib/libkse/arch/i386/include/atomic_ops.h b/lib/libkse/arch/i386/include/atomic_ops.h
deleted file mode 100644
index 1825b8cfb658..000000000000
--- a/lib/libkse/arch/i386/include/atomic_ops.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*-
- * Copyright (c) 2001 Daniel Eischen <deischen@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. Neither the name of the author 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 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 _ATOMIC_OPS_H_
-#define _ATOMIC_OPS_H_
-
-/*
- * Atomic swap:
- * Atomic (tmp = *dst, *dst = val), then *res = tmp
- *
- * void atomic_swap_long(long *dst, long val, long *res);
- */
-static inline void
-atomic_swap_long(long *dst, long val, long *res)
-{
- __asm __volatile(
- "xchgl %2, %1; movl %2, %0"
- : "=m" (*res) : "m" (*dst), "r" (val) : "memory");
-}
-
-#define atomic_swap_int(d, v, r) \
- atomic_swap_long((long *)(d), (long)(v), (long *)(r))
-
-#define atomic_swap_ptr atomic_swap_int
-
-#endif
diff --git a/lib/libkse/arch/i386/include/pthread_md.h b/lib/libkse/arch/i386/include/pthread_md.h
deleted file mode 100644
index cb5a3443a345..000000000000
--- a/lib/libkse/arch/i386/include/pthread_md.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * Copyright (c) 2002 Daniel Eischen <deischen@freebsd.org>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-/*
- * Machine-dependent thread prototypes/definitions for the thread kernel.
- */
-#ifndef _PTHREAD_MD_H_
-#define _PTHREAD_MD_H_
-
-#include <setjmp.h>
-#include <ucontext.h>
-
-extern int _thr_setcontext(ucontext_t *);
-extern int _thr_getcontext(ucontext_t *);
-
-/*
- * These are needed to ensure an application doesn't attempt to jump
- * between stacks of different threads. They return the stack of
- * jmp_buf, sigjmp_buf, and ucontext respectively.
- */
-#define GET_STACK_JB(jb) ((unsigned long)((jb)[0]._jb[2]))
-#define GET_STACK_SJB(sjb) ((unsigned long)((sjb)[0]._sjb[2]))
-#define GET_STACK_UC(ucp) ((unsigned long)((ucp)->uc_mcontext.mc_esp))
-
-#define THR_GETCONTEXT(ucp) _thr_getcontext(ucp)
-#define THR_SETCONTEXT(ucp) _thr_setcontext(ucp)
-
-#define THR_ALIGNBYTES 15
-#define THR_ALIGN(td) (((unsigned)(td) + THR_ALIGNBYTES) & ~THR_ALIGNBYTES)
-#endif
diff --git a/lib/libkse/support/Makefile.inc b/lib/libkse/support/Makefile.inc
deleted file mode 100644
index 27f65245acd0..000000000000
--- a/lib/libkse/support/Makefile.inc
+++ /dev/null
@@ -1,10 +0,0 @@
-# $FreeBSD$
-
-.PATH: ${.CURDIR}/support
-
-SRCS += thr_support.c
-SOBJS+= thr_libc.So
-
-thr_libc.So: thr_support.So
- ${CC} -nostdlib -L/usr/lib -o ${.TARGET} -Wl,-x,-r ${.ALLSRC} -lc_pic
-
diff --git a/lib/libkse/support/thr_support.c b/lib/libkse/support/thr_support.c
deleted file mode 100644
index 7ffa5d77fc90..000000000000
--- a/lib/libkse/support/thr_support.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*-
- * Copyright 2003 Alexander Kabaev.
- * 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.
- *
- * $FreeBSD$
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/kse.h>
-#include <signal.h>
-#include <string.h>
-
-__strong_reference(clock_gettime, _thr_clock_gettime);
-__strong_reference(kse_exit, _thr_kse_exit);
-__strong_reference(kse_wakeup, _thr_kse_wakeup);
-__strong_reference(kse_create, _thr_kse_create);
-__strong_reference(kse_thr_interrupt, _thr_kse_thr_interrupt);
-__strong_reference(kse_release, _thr_kse_release);
-
-__strong_reference(sigaction, _thr_sigaction);
-__strong_reference(sigprocmask, _thr_sigprocmask);
-__strong_reference(sigemptyset, _thr_sigemptyset);
-__strong_reference(sigaddset, _thr_sigaddset);
-__strong_reference(sigfillset, _thr_sigfillset);
-__strong_reference(sigismember, _thr_sigismember);
-__strong_reference(sigdelset, _thr_sigdelset);
-
-__strong_reference(memset, _thr_memset);
-__strong_reference(memcpy, _thr_memcpy);
-__strong_reference(strcpy, _thr_strcpy);
-__strong_reference(strlen, _thr_strlen);
-__strong_reference(bzero, _thr_bzero);
-
diff --git a/lib/libkse/sys/Makefile.inc b/lib/libkse/sys/Makefile.inc
deleted file mode 100644
index ac659e82bf2f..000000000000
--- a/lib/libkse/sys/Makefile.inc
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-.PATH: ${.CURDIR}/sys ${.CURDIR}/arch/${MACHINE_ARCH}/${MACHINE_ARCH}
-
-SRCS+= thr_error.c _atomic_lock.S ksd.c thr_enter_uts.S thr_getcontext.S \
- thr_switch.S lock.c
-
diff --git a/lib/libkse/sys/lock.c b/lib/libkse/sys/lock.c
deleted file mode 100644
index c67da334362e..000000000000
--- a/lib/libkse/sys/lock.c
+++ /dev/null
@@ -1,300 +0,0 @@
-/*-
- * Copyright (c) 2001, 2003 Daniel Eischen <deischen@freebsd.org>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-
-#include <sys/types.h>
-#include <machine/atomic.h>
-#include <assert.h>
-#include <stdlib.h>
-
-#include "atomic_ops.h"
-#include "lock.h"
-
-#define LCK_ASSERT assert
-#define MAX_SPINS 500
-
-void
-_lock_destroy(struct lock *lck)
-{
-
- if ((lck != NULL) && (lck->l_head != NULL)) {
- free(lck->l_head);
- lck->l_head = NULL;
- lck->l_tail = NULL;
- }
-}
-
-int
-_lock_init(struct lock *lck, enum lock_type ltype,
- lock_handler_t *waitfunc, lock_handler_t *wakeupfunc)
-{
-
- if (lck == NULL)
- return (-1);
- else if ((lck->l_head = malloc(sizeof(struct lockreq))) == NULL)
- return (-1);
- else {
- lck->l_type = ltype;
- lck->l_wait = waitfunc;
- lck->l_wakeup = wakeupfunc;
- lck->l_head->lr_locked = 0;
- lck->l_head->lr_watcher = NULL;
- lck->l_head->lr_owner = NULL;
- lck->l_head->lr_active = 1;
- lck->l_tail = lck->l_head;
- }
- return (0);
-}
-
-int
-_lockuser_init(struct lockuser *lu, void *priv)
-{
-
- if (lu == NULL)
- return (-1);
- else if ((lu->lu_myreq == NULL) &&
- ((lu->lu_myreq = malloc(sizeof(struct lockreq))) == NULL))
- return (-1);
- else {
- lu->lu_myreq->lr_locked = 1;
- lu->lu_myreq->lr_watcher = NULL;
- lu->lu_myreq->lr_owner = lu;
- lu->lu_myreq->lr_active = 0;
- lu->lu_watchreq = NULL;
- lu->lu_priority = 0;
- lu->lu_private = priv;
- lu->lu_private2 = NULL;
- }
- return (0);
-}
-
-void
-_lockuser_destroy(struct lockuser *lu)
-{
-
- if ((lu != NULL) && (lu->lu_myreq != NULL))
- free(lu->lu_myreq);
-}
-
-/*
- * Acquire a lock waiting (spin or sleep) for it to become available.
- */
-void
-_lock_acquire(struct lock *lck, struct lockuser *lu, int prio)
-{
- int i;
- long lval;
-
- /**
- * XXX - We probably want to remove these checks to optimize
- * performance. It is also a bug if any one of the
- * checks fail, so it's probably better to just let it
- * SEGV and fix it.
- */
-#if 0
- if (lck == NULL || lu == NULL || lck->l_head == NULL)
- return;
-#endif
- if ((lck->l_type & LCK_PRIORITY) == 0)
- atomic_swap_ptr(&lck->l_head, lu->lu_myreq, &lu->lu_watchreq);
- else {
- LCK_ASSERT(lu->lu_myreq->lr_locked == 1);
- LCK_ASSERT(lu->lu_myreq->lr_watcher == NULL);
- LCK_ASSERT(lu->lu_myreq->lr_owner == lu);
- LCK_ASSERT(lu->lu_watchreq == NULL);
-
- lu->lu_priority = prio;
- /*
- * Atomically swap the head of the lock request with
- * this request.
- */
- atomic_swap_ptr(&lck->l_head, lu->lu_myreq, &lu->lu_watchreq);
- }
-
- if (lu->lu_watchreq->lr_locked != 0) {
- atomic_store_rel_ptr(&lu->lu_watchreq->lr_watcher, lu);
- if ((lck->l_wait == NULL) ||
- ((lck->l_type & LCK_ADAPTIVE) == 0)) {
- while (lu->lu_watchreq->lr_locked == 0)
- ; /* spin, then yield? */
- } else {
- /*
- * Spin for a bit before invoking the wait function.
- *
- * We should be a little smarter here. If we're
- * running on a single processor, then the lock
- * owner got preempted and spinning will accomplish
- * nothing but waste time. If we're running on
- * multiple processors, the owner could be running
- * on another CPU and we might acquire the lock if
- * we spin for a bit.
- *
- * The other thing to keep in mind is that threads
- * acquiring these locks are considered to be in
- * critical regions; they will not be preempted by
- * the _UTS_ until they release the lock. It is
- * therefore safe to assume that if a lock can't
- * be acquired, it is currently held by a thread
- * running in another KSE.
- */
- for (i = 0; i < MAX_SPINS; i++) {
- if (lu->lu_watchreq->lr_locked == 0)
- return;
- if (lu->lu_watchreq->lr_active == 0)
- break;
- }
- atomic_swap_long((long *)&lu->lu_watchreq->lr_locked,
- 2, &lval);
- if (lval == 0)
- lu->lu_watchreq->lr_locked = 0;
- else
- lck->l_wait(lck, lu);
-
- }
- }
- lu->lu_myreq->lr_active = 1;
-}
-
-/*
- * Release a lock.
- */
-void
-_lock_release(struct lock *lck, struct lockuser *lu)
-{
- struct lockuser *lu_tmp, *lu_h;
- struct lockreq *myreq;
- int prio_h;
- long lval;
-
- /**
- * XXX - We probably want to remove these checks to optimize
- * performance. It is also a bug if any one of the
- * checks fail, so it's probably better to just let it
- * SEGV and fix it.
- */
-#if 0
- if ((lck == NULL) || (lu == NULL))
- return;
-#endif
- if ((lck->l_type & LCK_PRIORITY) != 0) {
- prio_h = 0;
- lu_h = NULL;
-
- /* Update tail if our request is last. */
- if (lu->lu_watchreq->lr_owner == NULL) {
- atomic_store_rel_ptr(&lck->l_tail, lu->lu_myreq);
- atomic_store_rel_ptr(&lu->lu_myreq->lr_owner, NULL);
- } else {
- /* Remove ourselves from the list. */
- atomic_store_rel_ptr(&lu->lu_myreq->lr_owner,
- lu->lu_watchreq->lr_owner);
- atomic_store_rel_ptr(
- &lu->lu_watchreq->lr_owner->lu_myreq, lu->lu_myreq);
- }
- /*
- * The watch request now becomes our own because we've
- * traded away our previous request. Save our previous
- * request so that we can grant the lock.
- */
- myreq = lu->lu_myreq;
- lu->lu_myreq = lu->lu_watchreq;
- lu->lu_watchreq = NULL;
- lu->lu_myreq->lr_locked = 1;
- lu->lu_myreq->lr_owner = lu;
- lu->lu_myreq->lr_watcher = NULL;
- /*
- * Traverse the list of lock requests in reverse order
- * looking for the user with the highest priority.
- */
- for (lu_tmp = lck->l_tail->lr_watcher; lu_tmp != NULL;
- lu_tmp = lu_tmp->lu_myreq->lr_watcher) {
- if (lu_tmp->lu_priority > prio_h) {
- lu_h = lu_tmp;
- prio_h = lu_tmp->lu_priority;
- }
- }
- if (lu_h != NULL) {
- /* Give the lock to the highest priority user. */
- if (lck->l_wakeup != NULL) {
- atomic_swap_long(
- (long *)&lu_h->lu_watchreq->lr_locked,
- 0, &lval);
- if (lval == 2)
- /* Notify the sleeper */
- lck->l_wakeup(lck,
- lu_h->lu_myreq->lr_watcher);
- }
- else
- atomic_store_rel_long(
- &lu_h->lu_watchreq->lr_locked, 0);
- } else {
- if (lck->l_wakeup != NULL) {
- atomic_swap_long((long *)&myreq->lr_locked,
- 0, &lval);
- if (lval == 2)
- /* Notify the sleeper */
- lck->l_wakeup(lck, myreq->lr_watcher);
- }
- else
- /* Give the lock to the previous request. */
- atomic_store_rel_long(&myreq->lr_locked, 0);
- }
- } else {
- /*
- * The watch request now becomes our own because we've
- * traded away our previous request. Save our previous
- * request so that we can grant the lock.
- */
- myreq = lu->lu_myreq;
- lu->lu_myreq = lu->lu_watchreq;
- lu->lu_watchreq = NULL;
- lu->lu_myreq->lr_locked = 1;
- if (lck->l_wakeup) {
- atomic_swap_long((long *)&myreq->lr_locked, 0, &lval);
- if (lval == 2)
- /* Notify the sleeper */
- lck->l_wakeup(lck, myreq->lr_watcher);
- }
- else
- /* Give the lock to the previous request. */
- atomic_store_rel_long(&myreq->lr_locked, 0);
- }
- lu->lu_myreq->lr_active = 0;
-}
-
-void
-_lock_grant(struct lock *lck /* unused */, struct lockuser *lu)
-{
- atomic_store_rel_long(&lu->lu_watchreq->lr_locked, 3);
-}
-
-void
-_lockuser_setactive(struct lockuser *lu, int active)
-{
- lu->lu_myreq->lr_active = active;
-}
-
diff --git a/lib/libkse/sys/lock.h b/lib/libkse/sys/lock.h
deleted file mode 100644
index 9d4b994fd40b..000000000000
--- a/lib/libkse/sys/lock.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2001, 2003 Daniel Eischen <deischen@freebsd.org>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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 _LOCK_H_
-#define _LOCK_H_
-
-struct lockreq;
-struct lockuser;
-struct lock;
-
-enum lock_type {
- LCK_DEFAULT = 0x0000, /* default is FIFO spin locks */
- LCK_PRIORITY = 0x0001,
- LCK_ADAPTIVE = 0x0002 /* call user-supplied handlers */
-};
-
-typedef void lock_handler_t(struct lock *, struct lockuser *);
-
-struct lock {
- struct lockreq *l_head;
- struct lockreq *l_tail; /* only used for priority locks */
- enum lock_type l_type;
- lock_handler_t *l_wait; /* only used for adaptive locks */
- lock_handler_t *l_wakeup; /* only used for adaptive locks */
-};
-
-/* Try to make this >= CACHELINESIZE */
-struct lockreq {
- volatile long lr_locked; /* lock granted = 0, busy otherwise */
- struct lockuser *lr_watcher; /* only used for priority locks */
- struct lockuser *lr_owner; /* only used for priority locks */
- volatile int lr_active; /* non-zero if the lock is last lock for thread */
-};
-
-struct lockuser {
- struct lockreq *lu_myreq; /* request to give up/trade */
- struct lockreq *lu_watchreq; /* watch this request */
- int lu_priority; /* only used for priority locks */
- void *lu_private1; /* private{1,2} are initialized to */
- void *lu_private2; /* NULL and can be used by caller */
-#define lu_private lu_private1
-};
-
-#define _LCK_INITIALIZER(lck_req) { &lck_req, NULL, LCK_DEFAULT, \
- NULL, NULL }
-#define _LCK_REQUEST_INITIALIZER { 0, NULL, NULL, 0 }
-
-#define _LCK_BUSY(lu) ((lu)->lu_watchreq->lr_locked != 0)
-#define _LCK_ACTIVE(lu) ((lu)->lu_watchreq->lr_active != 0)
-#define _LCK_GRANTED(lu) ((lu)->lu_watchreq->lr_locked == 3)
-
-#define _LCK_SET_PRIVATE(lu, p) (lu)->lu_private = (void *)(p)
-#define _LCK_GET_PRIVATE(lu) (lu)->lu_private
-#define _LCK_SET_PRIVATE2(lu, p) (lu)->lu_private2 = (void *)(p)
-#define _LCK_GET_PRIVATE2(lu) (lu)->lu_private2
-
-void _lock_destroy(struct lock *);
-int _lock_init(struct lock *, enum lock_type,
- lock_handler_t *, lock_handler_t *);
-int _lockuser_init(struct lockuser *lu, void *priv);
-void _lockuser_destroy(struct lockuser *lu);
-void _lockuser_setactive(struct lockuser *lu, int active);
-void _lock_acquire(struct lock *, struct lockuser *, int);
-void _lock_release(struct lock *, struct lockuser *);
-void _lock_grant(struct lock *, struct lockuser *);
-
-#endif
diff --git a/lib/libkse/sys/thr_error.c b/lib/libkse/sys/thr_error.c
deleted file mode 100644
index 6f19f931fce9..000000000000
--- a/lib/libkse/sys/thr_error.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell
- * and Chris Provenzano.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-#include <pthread.h>
-#include "libc_private.h"
-#include "thr_private.h"
-
-extern int errno;
-
-int *
-__error(void)
-{
- struct pthread *curthread;
-
- if (__isthreaded == 0)
- return (&errno);
- else if (_kse_in_critical())
- return &(_get_curkse()->k_error);
- else {
- curthread = _get_curthread();
- if ((curthread == NULL) || (curthread == _thr_initial))
- return (&errno);
- else
- return (&curthread->error);
- }
-}
diff --git a/lib/libkse/test/Makefile b/lib/libkse/test/Makefile
deleted file mode 100644
index 31c74f75e552..000000000000
--- a/lib/libkse/test/Makefile
+++ /dev/null
@@ -1,115 +0,0 @@
-#
-# $FreeBSD$
-#
-# Automated test suite for libpthread (pthreads).
-#
-
-# File lists.
-
-# Tests written in C.
-CTESTS := hello_d.c hello_s.c join_leak_d.c mutex_d.c sem_d.c sigsuspend_d.c \
- sigwait_d.c
-
-# C programs that are used internally by the tests. The build system merely
-# compiles these.
-BTESTS := guard_b.c hello_b.c
-
-# Tests written in perl.
-PTESTS := guard_s.pl propagate_s.pl
-
-# Munge the file lists to their final executable names (strip the .c).
-CTESTS := $(CTESTS:R)
-BTESTS := $(BTESTS:R)
-
-CPPFLAGS := -D_LIBC_R_ -D_REENTRANT
-CFLAGS := -Wall -pipe -g3
-LDFLAGS_A := -static
-LDFLAGS_P := -pg
-LDFLAGS_S :=
-LIBS := -lkse
-
-# Flags passed to verify. "-v" or "-u" may be useful.
-VFLAGS :=
-
-all : default
-
-# Only use the following suffixes, in order to avoid any strange built-in rules.
-.SUFFIXES :
-.SUFFIXES : .c .o .d .pl
-
-# Clear out all paths, then set just one (default path) for the main build
-# directory.
-.PATH :
-.PATH : .
-
-# Build the C programs.
-.for bin in $(CTESTS) $(BTESTS)
-$(bin)_a : $(bin:S/$/&.c/)
- $(CC) $(CFLAGS) $(CPPFLAGS) -c $(bin:S/$/&.c/) -o $(@:S/$/&.o/)
- $(CC) -o $@ $(@:S/$/&.o/) $(LDFLAGS_A) $(LIBS)
- @$(SHELL) -ec "$(CC) -M $(CPPFLAGS) $(bin:S/$/&.c/) | sed \"s/\($(bin:T)\)\.o\([ :]*\)/$(bin:H:S!/!\\/!g)\/\1_a.o \2/g\" > $(@:R:S/$/&.d/)"
-
-$(bin)_p : $(bin:S/$/&.c/)
- $(CC) $(CFLAGS) $(CPPFLAGS) -c $(bin:S/$/&.c/) -o $(@:S/$/&.o/)
- $(CC) -o $@ $(@:S/$/&.o/) $(LDFLAGS_P) $(LIBS)
- @$(SHELL) -ec "$(CC) -M $(CPPFLAGS) $(bin:S/$/&.c/) | sed \"s/\($(bin:T)\)\.o\([ :]*\)/$(bin:H:S!/!\\/!g)\/\1_p.o \2/g\" > $(@:R:S/$/&.d/)"
-
-$(bin)_s : $(bin:S/$/&.c/)
- $(CC) $(CFLAGS) $(CPPFLAGS) -c $(bin:S/$/&.c/) -o $(@:S/$/&.o/)
- $(CC) -o $@ $(@:S/$/&.o/) $(LDFLAGS_S) $(LIBS)
- @$(SHELL) -ec "$(CC) -M $(CPPFLAGS) $(bin:S/$/&.c/) | sed \"s/\($(bin:T)\)\.o\([ :]*\)/$(bin:H:S!/!\\/!g)\/\1_s.o \2/g\" > $(@:R:S/$/&.d/)"
-.endfor
-
-# Dependency file inclusion.
-.for depfile in $(CTESTS:R:S/$/&_a.d/) $(BTESTS:R:S/$/&_a.d/) \
- $(CTESTS:R:S/$/&_p.d/) $(BTESTS:R:S/$/&_p.d/) \
- $(CTESTS:R:S/$/&_s.d/) $(BTESTS:R:S/$/&_s.d/)
-.if exists($(depfile))
-.include "$(depfile)"
-.endif
-.endfor
-
-default : check
-
-tests_a : $(CTESTS:S/$/&_a/) $(BTESTS:S/$/&_a/)
-tests_p : $(CTESTS:S/$/&_p/) $(BTESTS:S/$/&_p/)
-tests_s : $(CTESTS:S/$/&_s/) $(BTESTS:S/$/&_s/)
-
-tests : tests_a tests_p tests_s
-
-check_a : tests_a
-.for bin in $(CTESTS) $(BTESTS)
- @cp $(bin)_a $(bin)
-.endfor
- @echo "Test static library:"
- @./verify $(VFLAGS) $(CTESTS) $(PTESTS)
-
-check_p : tests_p
-.for bin in $(CTESTS) $(BTESTS)
- @cp $(bin)_p $(bin)
-.endfor
- @echo "Test profile library:"
- @./verify $(VFLAGS) $(CTESTS) $(PTESTS)
-
-check_s : tests_s
-.for bin in $(CTESTS) $(BTESTS)
- @cp $(bin)_s $(bin)
-.endfor
- @echo "Test shared library:"
- @./verify $(VFLAGS) $(CTESTS) $(PTESTS)
-
-check : check_a check_p check_s
-
-clean :
- rm -f *~
- rm -f *.core
- rm -f *.out
- rm -f *.perf
- rm -f *.diff
- rm -f *.gmon
- rm -f $(CTESTS) $(BTESTS)
- rm -f $(CTESTS:S/$/&_a/) $(BTESTS:S/$/&_a/)
- rm -f $(CTESTS:S/$/&_p/) $(BTESTS:S/$/&_p/)
- rm -f $(CTESTS:S/$/&_s/) $(BTESTS:S/$/&_s/)
- rm -f *.d
- rm -f *.o
diff --git a/lib/libkse/test/README b/lib/libkse/test/README
deleted file mode 100644
index 8f625a1438e7..000000000000
--- a/lib/libkse/test/README
+++ /dev/null
@@ -1,28 +0,0 @@
-$FreeBSD$
-
-This test suite is meant to test general functionality of pthreads, as well as
-provide a simple framework for regression tests. In general, this test suite
-can be used with any pthreads library, but in reality there are a number of
-libpthread-specific aspects to this test suite which would require some
-effort to get around if testing another pthreads library.
-
-This test suite assumes that libpthread is installed.
-
-There are two forms of test that the 'verify' script understands. The simpler
-form is the diff format, where the output of the test program is diff'ed with
-the correspondingly named .exp file. If there is diff output, the test fails.
-The sequence test format is somewhat more complex, and is documented in the
-command line usage output for verify. The advantage of this format is that it
-allows multiple tests to pass/fail within one program.
-
-There is no driving need for test naming consistency, but the existing tests
-generally follow these conventions:
-
-<name>_d.c <name>_d.exp : Diff mode C test and expected output file.
-<name>_s.c : Sequence mode C test.
-<name>_b*.c : Back end C program used by perl tests.
-<name>_d.pl <name>_d.pl.exp : Diff mode perl test and expected output file.
-<name>_s.pl : Sequence mode perl test.
-
-<name> is something descriptive, such as "pr14685" in the case of a PR-related
-regression test, or "mutex" in the case of a test of mutexes.
diff --git a/lib/libkse/test/guard_b.c b/lib/libkse/test/guard_b.c
deleted file mode 100644
index 42bf4edd3bbb..000000000000
--- a/lib/libkse/test/guard_b.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (C) 2001 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer
- * unmodified other than the allowable addition of one or more
- * copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- *
- * Test thread stack guard functionality.
- */
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <limits.h>
-#include <pthread.h>
-
-#define FRAME_SIZE 1024
-#define FRAME_OVERHEAD 40
-
-struct args
-{
- void *top; /* Top of thread's initial stack frame. */
- int cur; /* Recursion depth. */
- int max; /* Maximum recursion depth. */
-};
-
-void *
-recurse(void *args)
-{
- int top;
- struct args *parms = (struct args *)args;
- char filler[FRAME_SIZE - FRAME_OVERHEAD];
-
- /* Touch the memory in this stack frame. */
- top = 0xa5;
- memset(filler, 0xa5, sizeof(filler));
-
- if (parms->top == NULL) {
- /* Initial stack frame. */
- parms->top = (void*)&top;
- }
-
- /*
- * Make sure frame size is what we expect. Getting this right involves
- * hand tweaking, so just print a warning rather than aborting.
- */
- if (parms->top - (void *)&top != FRAME_SIZE * parms->cur) {
- fprintf(stderr, "Stack size (%d) != expected (%d), frame %d\n",
- parms->top - (void *)&top, FRAME_SIZE * parms->cur,
- parms->cur);
- }
-
- parms->cur++;
- if (parms->cur < parms->max)
- recurse(args);
-
- return NULL;
-}
-
-
-int
-main(int argc, char **argv)
-{
- size_t def_stacksize, def_guardsize;
- size_t stacksize, guardsize;
- pthread_t thread;
- pthread_attr_t attr;
- struct args args;
-
- if (argc != 3) {
- fprintf(stderr, "usage: guard_b <stacksize> <guardsize>\n");
- exit(1);
- }
- fprintf(stderr, "Test begin\n");
-
- stacksize = strtoul(argv[1], NULL, 10);
- guardsize = strtoul(argv[2], NULL, 10);
-
- assert(pthread_attr_init(&attr) == 0);
- /*
- * Exercise the attribute APIs more thoroughly than is strictly
- * necessary for the meat of this test program.
- */
- assert(pthread_attr_getstacksize(&attr, &def_stacksize) == 0);
- assert(pthread_attr_getguardsize(&attr, &def_guardsize) == 0);
- if (def_stacksize != stacksize) {
- assert(pthread_attr_setstacksize(&attr, stacksize) == 0);
- assert(pthread_attr_getstacksize(&attr, &def_stacksize) == 0);
- assert(def_stacksize == stacksize);
- }
- if (def_guardsize != guardsize) {
- assert(pthread_attr_setguardsize(&attr, guardsize) == 0);
- assert(pthread_attr_getguardsize(&attr, &def_guardsize) == 0);
- assert(def_guardsize >= guardsize);
- }
-
- /*
- * Create a thread that will come just short of overflowing the thread
- * stack. We need to leave a bit of breathing room in case the thread
- * is context switched, and we also have to take care not to call any
- * functions in the deepest stack frame.
- */
- args.top = NULL;
- args.cur = 0;
- args.max = (stacksize / FRAME_SIZE) - 1;
- fprintf(stderr, "No overflow:\n");
- assert(pthread_create(&thread, &attr, recurse, &args) == 0);
- assert(pthread_join(thread, NULL) == 0);
-
- /*
- * Create a thread that will barely of overflow the thread stack. This
- * should cause a segfault.
- */
- args.top = NULL;
- args.cur = 0;
- args.max = (stacksize / FRAME_SIZE) + 1;
- fprintf(stderr, "Overflow:\n");
- assert(pthread_create(&thread, &attr, recurse, &args) == 0);
- assert(pthread_join(thread, NULL) == 0);
-
- /* Not reached. */
- fprintf(stderr, "Unexpected success\n");
- abort();
-
- return 0;
-}
diff --git a/lib/libkse/test/guard_b.exp b/lib/libkse/test/guard_b.exp
deleted file mode 100644
index 8e5b9e426a21..000000000000
--- a/lib/libkse/test/guard_b.exp
+++ /dev/null
@@ -1,3 +0,0 @@
-Test begin
-No overflow:
-Overflow:
diff --git a/lib/libkse/test/guard_s.pl b/lib/libkse/test/guard_s.pl
deleted file mode 100644
index 7802ff3c38d6..000000000000
--- a/lib/libkse/test/guard_s.pl
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/perl -w
-#
-# Copyright (C) 2001 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer
-# unmodified other than the allowable addition of one or more
-# copyright notices.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-#
-# Test thread stack guard functionality. The C test program needs to be driven
-# by this script because it segfaults when the stack guard is hit.
-#
-
-print "1..30\n";
-
-$i = 0;
-# Iterates 10 times.
-for ($stacksize = 65536; $stacksize < 131072; $stacksize += 7168)
-{
- # Iterates 3 times (1024, 4096, 7168).
- for ($guardsize = 1024; $guardsize < 8192; $guardsize += 3072)
- {
- $i++;
-
- print "stacksize: $stacksize, guardsize: $guardsize\n";
-
- `./guard_b $stacksize $guardsize >guard_b.out 2>&1`;
-
- if (! -f "./guard_b.out")
- {
- print "not ok $i\n";
- }
- else
- {
- `diff guard_b.exp guard_b.out >guard_b.diff 2>&1`;
- if ($?)
- {
- # diff returns non-zero if there is a difference.
- print "not ok $i\n";
- }
- else
- {
- print "ok $i\n";
- }
- }
- }
-}
diff --git a/lib/libkse/test/hello_b.c b/lib/libkse/test/hello_b.c
deleted file mode 100644
index 2eefa7f48bfe..000000000000
--- a/lib/libkse/test/hello_b.c
+++ /dev/null
@@ -1,13 +0,0 @@
-/****************************************************************************
- *
- * Back end C programs can be anything compilable.
- *
- * $FreeBSD$
- *
- ****************************************************************************/
-
-int
-main()
-{
- return 0;
-}
diff --git a/lib/libkse/test/hello_d.c b/lib/libkse/test/hello_d.c
deleted file mode 100644
index 6d77526f16c7..000000000000
--- a/lib/libkse/test/hello_d.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/****************************************************************************
- *
- * Simple diff mode test.
- *
- * $FreeBSD$
- *
- ****************************************************************************/
-
-#include <stdio.h>
-#include <string.h>
-#include <pthread.h>
-
-void *
-entry(void * a_arg)
-{
- fprintf(stderr, "Hello world\n");
-
- return NULL;
-}
-
-int
-main()
-{
- pthread_t thread;
- int error;
-
- error = pthread_create(&thread, NULL, entry, NULL);
- if (error)
- fprintf(stderr, "Error in pthread_create(): %s\n",
- strerror(error));
-
- error = pthread_join(thread, NULL);
- if (error)
- fprintf(stderr, "Error in pthread_join(): %s\n",
- strerror(error));
-
- return 0;
-}
diff --git a/lib/libkse/test/hello_d.exp b/lib/libkse/test/hello_d.exp
deleted file mode 100644
index 802992c4220d..000000000000
--- a/lib/libkse/test/hello_d.exp
+++ /dev/null
@@ -1 +0,0 @@
-Hello world
diff --git a/lib/libkse/test/hello_s.c b/lib/libkse/test/hello_s.c
deleted file mode 100644
index 942bf2dae0ae..000000000000
--- a/lib/libkse/test/hello_s.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/****************************************************************************
- *
- * Simple sequence mode test.
- *
- * $FreeBSD$
- *
- ****************************************************************************/
-
-#include <stdio.h>
-#include <string.h>
-#include <pthread.h>
-
-void *
-entry(void * a_arg)
-{
- fprintf(stderr, "ok 1\n");
- fprintf(stderr, "ok \n");
- fprintf(stderr, "ok 3\n");
-
- return NULL;
-}
-
-int
-main()
-{
- pthread_t thread;
- int error;
-
- fprintf(stderr, "1..3\n");
-
- fprintf(stderr, "Some random text\n");
-
- error = pthread_create(&thread, NULL, entry, NULL);
- fprintf(stderr, "More unimportant text\n");
- if (error)
- fprintf(stderr,"Error in pthread_create(): %s\n",
- strerror(error));
-
- error = pthread_join(thread, NULL);
- if (error)
- fprintf(stderr, "Error in pthread_join(): %s\n",
- strerror(error));
-
- fprintf(stderr, "Hello world\n");
-
- return 0;
-}
diff --git a/lib/libkse/test/join_leak_d.c b/lib/libkse/test/join_leak_d.c
deleted file mode 100644
index 6532ca5bfc74..000000000000
--- a/lib/libkse/test/join_leak_d.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2001 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- *
- * Test for leaked joined threads.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <errno.h>
-#include <string.h>
-#include <pthread.h>
-
-#define NITERATIONS 16384
-#define MAXGROWTH 16384
-
-void *
-thread_entry(void *a_arg)
-{
- return NULL;
-}
-
-int
-main(void)
-{
- pthread_t thread;
- int i, error;
- char *brk, *nbrk;
- unsigned growth;
-
- fprintf(stderr, "Test begin\n");
-
- /* Get an initial brk value. */
- brk = sbrk(0);
-
- /* Create threads and join them, one at a time. */
- for (i = 0; i < NITERATIONS; i++) {
- if ((error = pthread_create(&thread, NULL, thread_entry, NULL))
- != 0) {
- fprintf(stderr, "Error in pthread_create(): %s\n",
- strerror(error));
- exit(1);
- }
- if ((error = pthread_join(thread, NULL)) != 0) {
- fprintf(stderr, "Error in pthread_join(): %s\n",
- strerror(error));
- exit(1);
- }
- }
-
- /* Get a final brk value. */
- nbrk = sbrk(0);
-
- /*
- * Check that the amount of heap space allocated is below an acceptable
- * threshold. We could just compare brk and nbrk, but the test could
- * conceivably break if the internals of the threads library changes.
- */
- if (nbrk > brk) {
- /* Heap grows up. */
- growth = nbrk - brk;
- } else if (nbrk <= brk) {
- /* Heap grows down, or no growth. */
- growth = brk - nbrk;
- }
-
- if (growth > MAXGROWTH) {
- fprintf(stderr, "Heap growth exceeded maximum (%u > %u)\n",
- growth, MAXGROWTH);
- }
-#if (0)
- else {
- fprintf(stderr, "Heap growth acceptable (%u <= %u)\n",
- growth, MAXGROWTH);
- }
-#endif
-
- fprintf(stderr, "Test end\n");
- return 0;
-}
diff --git a/lib/libkse/test/join_leak_d.exp b/lib/libkse/test/join_leak_d.exp
deleted file mode 100644
index 369a88dd2404..000000000000
--- a/lib/libkse/test/join_leak_d.exp
+++ /dev/null
@@ -1,2 +0,0 @@
-Test begin
-Test end
diff --git a/lib/libkse/test/mutex_d.c b/lib/libkse/test/mutex_d.c
deleted file mode 100644
index 45d28a5f8ef3..000000000000
--- a/lib/libkse/test/mutex_d.c
+++ /dev/null
@@ -1,1554 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel M. Eischen <eischen@vigrid.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel M. Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL M. EISCHEN AND CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED 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$
- */
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <sys/ioctl.h>
-#include <assert.h>
-#include <errno.h>
-#include "pthread.h"
-#include <sched.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include <sysexits.h>
-
-#if defined(_LIBC_R_)
-#include <pthread_np.h>
-#endif
-
-#ifndef NELEMENTS
-#define NELEMENTS(arr) (sizeof (arr) / sizeof (arr[0]))
-#endif
-
-#ifndef NUM_THREADS
-#define NUM_THREADS 10
-#endif
-
-#define MAX_THREAD_CMDS 10
-
-static void log_error(const char *, ...) __printflike(1, 2);
-static void log_trace (const char *, ...) __printflike(1, 2);
-static void log (const char *, ...) __printflike(1, 2);
-
-/*------------------------------------------------------------
- * Types
- *----------------------------------------------------------*/
-
-typedef enum {
- STAT_INITIAL, /* initial state */
- STAT_WAITCONDVAR, /* waiting for condition variable signal */
- STAT_WAITMUTEX /* waiting for mutex lock */
-} thread_status_t;
-
-typedef enum {
- FLAGS_REPORT_WAITCONDMUTEX = 0x01,
- FLAGS_REPORT_WAITCONDVAR = 0x02,
- FLAGS_REPORT_WAITMUTEX = 0x04,
- FLAGS_REPORT_BUSY_LOOP = 0x08,
- FLAGS_IS_BUSY = 0x10,
- FLAGS_WAS_BUSY = 0x20
-} thread_flags_t;
-
-typedef enum {
- CMD_NONE,
- CMD_TAKE_MUTEX,
- CMD_RELEASE_MUTEX,
- CMD_WAIT_FOR_SIGNAL,
- CMD_BUSY_LOOP,
- CMD_PROTECTED_OP,
- CMD_RELEASE_ALL
-} thread_cmd_id_t;
-
-typedef struct {
- thread_cmd_id_t cmd_id;
- pthread_mutex_t *mutex;
- pthread_cond_t *cond;
-} thread_cmd_t;
-
-typedef struct {
- pthread_cond_t cond_var;
- thread_status_t status;
- thread_cmd_t cmd;
- int flags;
- int priority;
- int ret;
- pthread_t tid;
- u_int8_t id;
-} thread_state_t;
-
-typedef enum {
- M_POSIX,
- M_SS2_DEFAULT,
- M_SS2_ERRORCHECK,
- M_SS2_NORMAL,
- M_SS2_RECURSIVE
-} mutex_kind_t;
-
-
-/*------------------------------------------------------------
- * Constants
- *----------------------------------------------------------*/
-
-const char *protocol_strs[] = {
- "PTHREAD_PRIO_NONE",
- "PTHREAD_PRIO_INHERIT",
- "PTHREAD_PRIO_PROTECT"
-};
-
-const int protocols[] = {
- PTHREAD_PRIO_NONE,
- PTHREAD_PRIO_INHERIT,
- PTHREAD_PRIO_PROTECT
-};
-
-const char *mutextype_strs[] = {
- "POSIX (type not specified)",
- "SS2 PTHREAD_MUTEX_DEFAULT",
- "SS2 PTHREAD_MUTEX_ERRORCHECK",
- "SS2 PTHREAD_MUTEX_NORMAL",
- "SS2 PTHREAD_MUTEX_RECURSIVE"
-};
-
-const int mutex_types[] = {
- 0, /* M_POSIX */
- PTHREAD_MUTEX_DEFAULT, /* M_SS2_DEFAULT */
- PTHREAD_MUTEX_ERRORCHECK, /* M_SS2_ERRORCHECK */
- PTHREAD_MUTEX_NORMAL, /* M_SS2_NORMAL */
- PTHREAD_MUTEX_RECURSIVE /* M_SS2_RECURSIVE */
-};
-
-
-/*------------------------------------------------------------
- * Objects
- *----------------------------------------------------------*/
-
-static int done = 0;
-static int trace_enabled = 0;
-static int use_global_condvar = 0;
-static thread_state_t states[NUM_THREADS];
-static int pipefd[2];
-
-static pthread_mutex_t waiter_mutex;
-static pthread_mutex_t cond_mutex;
-static pthread_cond_t cond_var;
-
-static FILE *logfile;
-static int error_count = 0, pass_count = 0, total = 0;
-
-
-/*------------------------------------------------------------
- * Prototypes
- *----------------------------------------------------------*/
-extern char *strtok_r(char *str, const char *sep, char **last);
-
-
-/*------------------------------------------------------------
- * Functions
- *----------------------------------------------------------*/
-
-#ifdef DEBUG
-static void
-kern_switch (pthread_t pthread_out, pthread_t pthread_in)
-{
- if (pthread_out != NULL)
- printf ("Swapping out thread 0x%x, ", (int) pthread_out);
- else
- printf ("Swapping out kernel thread, ");
-
- if (pthread_in != NULL)
- printf ("swapping in thread 0x%x\n", (int) pthread_in);
- else
- printf ("swapping in kernel thread.\n");
-}
-#endif
-
-
-static void
-log_error (const char *fmt, ...)
-{
- va_list ap;
-
- va_start (ap, fmt);
- fprintf (logfile, "FAIL: ");
- vfprintf (logfile, fmt, ap);
- error_count = error_count + 1;
- total = total + 1;
-}
-
-
-static void
-log_pass (void)
-{
- fprintf (logfile, "PASS\n");
- pass_count = pass_count + 1;
- total = total + 1;
-}
-
-
-static void
-log_trace (const char *fmt, ...)
-{
- va_list ap;
-
- if (trace_enabled) {
- va_start (ap, fmt);
- vfprintf (logfile, fmt, ap);
- }
-}
-
-
-static void
-log (const char *fmt, ...)
-{
- va_list ap;
-
- va_start (ap, fmt);
- vfprintf (logfile, fmt, ap);
-}
-
-
-static void
-check_result (int expected, int actual)
-{
- if (expected != actual)
- log_error ("expected %d, returned %d\n", expected, actual);
- else
- log_pass ();
-}
-
-
-/*
- * Check to see that the threads ran in the specified order.
- */
-static void
-check_run_order (char *order)
-{
- const char *sep = ":,";
- char *tok, *last, *idstr, *endptr;
- int expected_id, bytes, count = 0, errors = 0;
- u_int8_t id;
-
- assert ((tok = (char *) malloc (strlen(order) + 1)) != NULL);
- strcpy (tok, order); /* tok has to be larger than order */
- assert (ioctl (pipefd[0], FIONREAD, &bytes) == 0);
- log_trace ("%d bytes read from FIFO.\n", bytes);
-
- for (idstr = strtok_r (tok, sep, &last);
- (idstr != NULL) && (count < bytes);
- idstr = strtok_r (NULL, sep, &last)) {
-
- /* Get the expected id: */
- expected_id = (int) strtol (idstr, &endptr, 10);
- assert ((endptr != NULL) && (*endptr == '\0'));
-
- /* Read the actual id from the pipe: */
- assert (read (pipefd[0], &id, sizeof (id)) == sizeof (id));
- count = count + sizeof (id);
-
- if (id != expected_id) {
- log_trace ("Thread %d ran out of order.\n", id);
- errors = errors + 1;
- }
- else {
- log_trace ("Thread %d at priority %d reporting.\n",
- (int) id, states[id].priority);
- }
- }
-
- if (count < bytes) {
- /* Clear the pipe: */
- while (count < bytes) {
- read (pipefd[0], &id, sizeof (id));
- count = count + 1;
- errors = errors + 1;
- }
- }
- else if (bytes < count)
- errors = errors + count - bytes;
-
- if (errors == 0)
- log_pass ();
- else
- log_error ("%d threads ran out of order", errors);
-}
-
-
-static void *
-waiter (void *arg)
-{
- thread_state_t *statep = (thread_state_t *) arg;
- pthread_mutex_t *held_mutex[MAX_THREAD_CMDS];
- int held_mutex_owned[MAX_THREAD_CMDS];
- sigset_t mask;
- struct timeval tv1, tv2;
- thread_cmd_t cmd;
- int i, mutex_count = 0;
-
- statep->status = STAT_INITIAL;
-
- /* Block all signals except for interrupt.*/
- sigfillset (&mask);
- sigdelset (&mask, SIGINT);
- sigprocmask (SIG_BLOCK, &mask, NULL);
-
- while (done == 0) {
- /* Wait for signal from the main thread to continue. */
- statep->status = STAT_WAITMUTEX;
- log_trace ("Thread %d: locking cond_mutex.\n",
- (int) statep->id);
- pthread_mutex_lock (&cond_mutex);
-
- /* Do we report our status. */
- if (statep->flags & FLAGS_REPORT_WAITCONDMUTEX)
- write (pipefd[1], &statep->id, sizeof (statep->id));
- log_trace ("Thread %d: waiting for cond_var.\n",
- (int) statep->id);
-
- /* Wait for a command. */
- statep->status = STAT_WAITCONDVAR;
-
- /*
- * The threads are allowed commanded to wait either on
- * their own unique condition variable (so they may be
- * separately signaled) or on one global condition variable
- * (so they may be signaled together).
- */
- if (use_global_condvar != 0)
- pthread_cond_wait (&cond_var, &cond_mutex);
- else
- pthread_cond_wait (&statep->cond_var, &cond_mutex);
-
- /* Do we report our status? */
- if (statep->flags & FLAGS_REPORT_WAITCONDVAR) {
- write (pipefd[1], &statep->id, sizeof (statep->id));
- log_trace ("Thread %d: wrote to pipe.\n",
- (int) statep->id);
- }
- log_trace ("Thread %d: received cond_var signal.\n",
- (int) statep->id);
-
- /* Get a copy of the command before releasing the mutex. */
- cmd = statep->cmd;
-
- /* Clear the command after copying it. */
- statep->cmd.cmd_id = CMD_NONE;
-
- /* Unlock the condition variable mutex. */
- assert (pthread_mutex_unlock (&cond_mutex) == 0);
-
- /* Peform the command.*/
- switch (cmd.cmd_id) {
- case CMD_TAKE_MUTEX:
- statep->ret = pthread_mutex_lock (cmd.mutex);
- if (statep->ret == 0) {
- assert (mutex_count < sizeof (held_mutex));
- held_mutex[mutex_count] = cmd.mutex;
- held_mutex_owned[mutex_count] = 1;
- mutex_count++;
- }
- else {
- held_mutex_owned[mutex_count] = 0;
- log_trace ("Thread id %d unable to lock mutex, "
- "error = %d\n", (int) statep->id,
- statep->ret);
- }
- break;
-
- case CMD_RELEASE_MUTEX:
- assert ((mutex_count <= sizeof (held_mutex)) &&
- (mutex_count > 0));
- mutex_count--;
- if (held_mutex_owned[mutex_count] != 0)
- assert (pthread_mutex_unlock
- (held_mutex[mutex_count]) == 0);
- break;
-
- case CMD_WAIT_FOR_SIGNAL:
- assert (pthread_mutex_lock (cmd.mutex) == 0);
- assert (pthread_cond_wait (cmd.cond, cmd.mutex) == 0);
- assert (pthread_mutex_unlock (cmd.mutex) == 0);
- break;
-
- case CMD_BUSY_LOOP:
- log_trace ("Thread %d: Entering busy loop.\n",
- (int) statep->id);
- /* Spin for 15 seconds. */
- assert (gettimeofday (&tv2, NULL) == 0);
- tv1.tv_sec = tv2.tv_sec + 5;
- tv1.tv_usec = tv2.tv_usec;
- statep->flags |= FLAGS_IS_BUSY;
- while (timercmp (&tv2, &tv1,<)) {
- assert (gettimeofday (&tv2, NULL) == 0);
- }
- statep->flags &= ~FLAGS_IS_BUSY;
- statep->flags |= FLAGS_WAS_BUSY;
-
- /* Do we report our status? */
- if (statep->flags & FLAGS_REPORT_BUSY_LOOP)
- write (pipefd[1], &statep->id,
- sizeof (statep->id));
-
- log_trace ("Thread %d: Leaving busy loop.\n",
- (int) statep->id);
- break;
-
- case CMD_PROTECTED_OP:
- assert (pthread_mutex_lock (cmd.mutex) == 0);
- statep->flags |= FLAGS_WAS_BUSY;
- /* Do we report our status? */
- if (statep->flags & FLAGS_REPORT_BUSY_LOOP)
- write (pipefd[1], &statep->id,
- sizeof (statep->id));
-
- assert (pthread_mutex_unlock (cmd.mutex) == 0);
- break;
-
- case CMD_RELEASE_ALL:
- assert ((mutex_count <= sizeof (held_mutex)) &&
- (mutex_count > 0));
- for (i = mutex_count - 1; i >= 0; i--) {
- if (held_mutex_owned[i] != 0)
- assert (pthread_mutex_unlock
- (held_mutex[i]) == 0);
- }
- mutex_count = 0;
- break;
-
- case CMD_NONE:
- default:
- break;
- }
-
- /* Wait for the big giant waiter lock. */
- statep->status = STAT_WAITMUTEX;
- log_trace ("Thread %d: waiting for big giant lock.\n",
- (int) statep->id);
- pthread_mutex_lock (&waiter_mutex);
- if (statep->flags & FLAGS_REPORT_WAITMUTEX)
- write (pipefd[1], &statep->id, sizeof (statep->id));
- log_trace ("Thread %d: got big giant lock.\n",
- (int) statep->id);
- statep->status = STAT_INITIAL;
- pthread_mutex_unlock (&waiter_mutex);
- }
-
- log_trace ("Thread %d: Exiting thread 0x%x\n", (int) statep->id,
- (int) pthread_self());
- pthread_exit (arg);
- return (NULL);
-}
-
-
-static void *
-lock_twice (void *arg)
-{
- thread_state_t *statep = (thread_state_t *) arg;
- sigset_t mask;
-
- statep->status = STAT_INITIAL;
-
- /* Block all signals except for interrupt.*/
- sigfillset (&mask);
- sigdelset (&mask, SIGINT);
- sigprocmask (SIG_BLOCK, &mask, NULL);
-
- /* Wait for a signal to continue. */
- log_trace ("Thread %d: locking cond_mutex.\n", (int) statep->id);
- pthread_mutex_lock (&cond_mutex);
-
- log_trace ("Thread %d: waiting for cond_var.\n", (int) statep->id);
- statep->status = STAT_WAITCONDVAR;
- pthread_cond_wait (&cond_var, &cond_mutex);
-
- log_trace ("Thread %d: received cond_var signal.\n", (int) statep->id);
-
- /* Unlock the condition variable mutex. */
- assert (pthread_mutex_unlock (&cond_mutex) == 0);
-
- statep->status = STAT_WAITMUTEX;
- /* Lock the mutex once. */
- assert (pthread_mutex_lock (statep->cmd.mutex) == 0);
-
- /* Lock it again and capture the error. */
- statep->ret = pthread_mutex_lock (statep->cmd.mutex);
- statep->status = 0;
-
- assert (pthread_mutex_unlock (statep->cmd.mutex) == 0);
-
- /* Unlock it again if it is locked recursively. */
- if (statep->ret == 0)
- pthread_mutex_unlock (statep->cmd.mutex);
-
- log_trace ("Thread %d: Exiting thread 0x%x\n", (int) statep->id,
- (int) pthread_self());
- pthread_exit (arg);
- return (NULL);
-}
-
-
-static void
-sighandler (int signo)
-{
- log ("Signal handler caught signal %d, thread id 0x%x\n",
- signo, (int) pthread_self());
-
- if (signo == SIGINT)
- done = 1;
-}
-
-
-static void
-send_cmd (int id, thread_cmd_id_t cmd)
-{
- assert (pthread_mutex_lock (&cond_mutex) == 0);
- assert (states[id].status == STAT_WAITCONDVAR);
- states[id].cmd.cmd_id = cmd;
- states[id].cmd.mutex = NULL;
- states[id].cmd.cond = NULL;
- /* Clear the busy flags. */
- states[id].flags &= ~(FLAGS_WAS_BUSY | FLAGS_IS_BUSY);
- assert (pthread_cond_signal (&states[id].cond_var) == 0);
- assert (pthread_mutex_unlock (&cond_mutex) == 0);
-}
-
-
-static void
-send_mutex_cmd (int id, thread_cmd_id_t cmd, pthread_mutex_t *m)
-{
- assert (pthread_mutex_lock (&cond_mutex) == 0);
- assert (states[id].status == STAT_WAITCONDVAR);
- states[id].cmd.cmd_id = cmd;
- states[id].cmd.mutex = m;
- states[id].cmd.cond = NULL;
- /* Clear the busy flags. */
- states[id].flags &= ~(FLAGS_WAS_BUSY | FLAGS_IS_BUSY);
- assert (pthread_cond_signal (&states[id].cond_var) == 0);
- assert (pthread_mutex_unlock (&cond_mutex) == 0);
-}
-
-
-static void
-send_mutex_cv_cmd (int id, thread_cmd_id_t cmd, pthread_mutex_t *m,
- pthread_cond_t *cv)
-{
- assert (pthread_mutex_lock (&cond_mutex) == 0);
- assert (states[id].status == STAT_WAITCONDVAR);
- states[id].cmd.cmd_id = cmd;
- states[id].cmd.mutex = m;
- states[id].cmd.cond = cv;
- /* Clear the busy flags. */
- states[id].flags &= ~(FLAGS_WAS_BUSY | FLAGS_IS_BUSY);
- assert (pthread_cond_signal (&states[id].cond_var) == 0);
- assert (pthread_mutex_unlock (&cond_mutex) == 0);
-}
-
-
-static void
-mutex_init_test (void)
-{
- pthread_mutexattr_t mattr;
- pthread_mutex_t mutex;
- mutex_kind_t mkind;
- int mproto, ret;
-
- /*
- * Initialize a mutex attribute.
- *
- * pthread_mutexattr_init not tested for: ENOMEM
- */
- assert (pthread_mutexattr_init (&mattr) == 0);
-
- /*
- * Initialize a mutex.
- *
- * pthread_mutex_init not tested for: EAGAIN ENOMEM EPERM EBUSY
- */
- log ("Testing pthread_mutex_init\n");
- log ("--------------------------\n");
-
- for (mproto = 0; mproto < NELEMENTS(protocols); mproto++) {
- for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) {
- /* Initialize the mutex attribute. */
- assert (pthread_mutexattr_init (&mattr) == 0);
- assert (pthread_mutexattr_setprotocol (&mattr,
- protocols[mproto]) == 0);
-
- /*
- * Ensure that the first mutex type is a POSIX
- * compliant mutex.
- */
- if (mkind != M_POSIX) {
- assert (pthread_mutexattr_settype (&mattr,
- mutex_types[mkind]) == 0);
- }
-
- log (" Protocol %s, Type %s - ",
- protocol_strs[mproto], mutextype_strs[mkind]);
- ret = pthread_mutex_init (&mutex, &mattr);
- check_result (/* expected */ 0, ret);
- assert (pthread_mutex_destroy (&mutex) == 0);
-
- /*
- * Destroy a mutex attribute.
- *
- * XXX - There should probably be a magic number
- * associated with a mutex attribute so that
- * destroy can be reasonably sure the attribute
- * is valid.
- *
- * pthread_mutexattr_destroy not tested for: EINVAL
- */
- assert (pthread_mutexattr_destroy (&mattr) == 0);
- }
- }
-}
-
-
-static void
-mutex_destroy_test (void)
-{
- pthread_mutexattr_t mattr;
- pthread_mutex_t mutex;
- pthread_condattr_t cattr;
- pthread_cond_t cv;
- pthread_attr_t pattr;
- int mproto, ret;
- mutex_kind_t mkind;
- thread_state_t state;
-
- /*
- * Destroy a mutex.
- *
- * XXX - There should probably be a magic number associated
- * with a mutex so that destroy can be reasonably sure
- * the mutex is valid.
- *
- * pthread_mutex_destroy not tested for:
- */
- log ("Testing pthread_mutex_destroy\n");
- log ("-----------------------------\n");
-
- assert (pthread_attr_init (&pattr) == 0);
- assert (pthread_attr_setdetachstate (&pattr,
- PTHREAD_CREATE_DETACHED) == 0);
- state.flags = 0; /* No flags yet. */
-
- for (mproto = 0; mproto < NELEMENTS(protocols); mproto++) {
- for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) {
- /* Initialize the mutex attribute. */
- assert (pthread_mutexattr_init (&mattr) == 0);
- assert (pthread_mutexattr_setprotocol (&mattr,
- protocols[mproto]) == 0);
-
- /*
- * Ensure that the first mutex type is a POSIX
- * compliant mutex.
- */
- if (mkind != M_POSIX) {
- assert (pthread_mutexattr_settype (&mattr,
- mutex_types[mkind]) == 0);
- }
-
- /* Create the mutex. */
- assert (pthread_mutex_init (&mutex, &mattr) == 0);
-
- log (" Protocol %s, Type %s\n",
- protocol_strs[mproto], mutextype_strs[mkind]);
-
- log (" Destruction of unused mutex - ");
- assert (pthread_mutex_init (&mutex, &mattr) == 0);
- ret = pthread_mutex_destroy (&mutex);
- check_result (/* expected */ 0, ret);
-
- log (" Destruction of mutex locked by self - ");
- assert (pthread_mutex_init (&mutex, &mattr) == 0);
- assert (pthread_mutex_lock (&mutex) == 0);
- ret = pthread_mutex_destroy (&mutex);
- check_result (/* expected */ EBUSY, ret);
- assert (pthread_mutex_unlock (&mutex) == 0);
- assert (pthread_mutex_destroy (&mutex) == 0);
-
- log (" Destruction of mutex locked by another "
- "thread - ");
- assert (pthread_mutex_init (&mutex, &mattr) == 0);
- send_mutex_cmd (0, CMD_TAKE_MUTEX, &mutex);
- sleep (1);
- ret = pthread_mutex_destroy (&mutex);
- check_result (/* expected */ EBUSY, ret);
- send_cmd (0, CMD_RELEASE_ALL);
- sleep (1);
- assert (pthread_mutex_destroy (&mutex) == 0);
-
- log (" Destruction of mutex while being used in "
- "cond_wait - ");
- assert (pthread_mutex_init (&mutex, &mattr) == 0);
- assert (pthread_condattr_init (&cattr) == 0);
- assert (pthread_cond_init (&cv, &cattr) == 0);
- send_mutex_cv_cmd (0, CMD_WAIT_FOR_SIGNAL, &mutex, &cv);
- sleep (1);
- ret = pthread_mutex_destroy (&mutex);
- check_result (/* expected */ EBUSY, ret);
- pthread_cond_signal (&cv);
- sleep (1);
- assert (pthread_mutex_destroy (&mutex) == 0);
- }
- }
-}
-
-
-static void
-mutex_lock_test (void)
-{
- pthread_mutexattr_t mattr;
- pthread_mutex_t mutex;
- pthread_attr_t pattr;
- int mproto, ret;
- mutex_kind_t mkind;
- thread_state_t state;
-
- /*
- * Lock a mutex.
- *
- * pthread_lock not tested for:
- */
- log ("Testing pthread_mutex_lock\n");
- log ("--------------------------\n");
-
- assert (pthread_attr_init (&pattr) == 0);
- assert (pthread_attr_setdetachstate (&pattr,
- PTHREAD_CREATE_DETACHED) == 0);
- state.flags = 0; /* No flags yet. */
-
- for (mproto = 0; mproto < NELEMENTS(protocols); mproto++) {
- for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) {
- /* Initialize the mutex attribute. */
- assert (pthread_mutexattr_init (&mattr) == 0);
- assert (pthread_mutexattr_setprotocol (&mattr,
- protocols[mproto]) == 0);
-
- /*
- * Ensure that the first mutex type is a POSIX
- * compliant mutex.
- */
- if (mkind != M_POSIX) {
- assert (pthread_mutexattr_settype (&mattr,
- mutex_types[mkind]) == 0);
- }
-
- /* Create the mutex. */
- assert (pthread_mutex_init (&mutex, &mattr) == 0);
-
- log (" Protocol %s, Type %s\n",
- protocol_strs[mproto], mutextype_strs[mkind]);
-
- log (" Lock on unlocked mutex - ");
- ret = pthread_mutex_lock (&mutex);
- check_result (/* expected */ 0, ret);
- pthread_mutex_unlock (&mutex);
-
- log (" Lock on invalid mutex - ");
- ret = pthread_mutex_lock (NULL);
- check_result (/* expected */ EINVAL, ret);
-
- log (" Lock on mutex held by self - ");
- assert (pthread_create (&state.tid, &pattr, lock_twice,
- (void *) &state) == 0);
- /* Let the thread start. */
- sleep (1);
- state.cmd.mutex = &mutex;
- state.ret = 0xdeadbeef;
- assert (pthread_mutex_lock (&cond_mutex) == 0);
- assert (pthread_cond_signal (&cond_var) == 0);
- assert (pthread_mutex_unlock (&cond_mutex) == 0);
- /* Let the thread receive and process the command. */
- sleep (1);
-
- switch (mkind) {
- case M_POSIX:
- check_result (/* expected */ EDEADLK,
- state.ret);
- break;
- case M_SS2_DEFAULT:
- check_result (/* expected */ EDEADLK,
- state.ret);
- break;
- case M_SS2_ERRORCHECK:
- check_result (/* expected */ EDEADLK,
- state.ret);
- break;
- case M_SS2_NORMAL:
- check_result (/* expected */ 0xdeadbeef,
- state.ret);
- break;
- case M_SS2_RECURSIVE:
- check_result (/* expected */ 0, state.ret);
- break;
- }
- pthread_mutex_destroy (&mutex);
- pthread_mutexattr_destroy (&mattr);
- }
- }
-}
-
-
-static void
-mutex_unlock_test (void)
-{
- const int test_thread_id = 0; /* ID of test thread */
- pthread_mutexattr_t mattr;
- pthread_mutex_t mutex;
- int mproto, ret;
- mutex_kind_t mkind;
-
- /*
- * Unlock a mutex.
- *
- * pthread_unlock not tested for:
- */
- log ("Testing pthread_mutex_unlock\n");
- log ("----------------------------\n");
-
- for (mproto = 0; mproto < NELEMENTS(protocols); mproto++) {
- for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) {
- /* Initialize the mutex attribute. */
- assert (pthread_mutexattr_init (&mattr) == 0);
- assert (pthread_mutexattr_setprotocol (&mattr,
- protocols[mproto]) == 0);
-
- /*
- * Ensure that the first mutex type is a POSIX
- * compliant mutex.
- */
- if (mkind != M_POSIX) {
- assert (pthread_mutexattr_settype (&mattr,
- mutex_types[mkind]) == 0);
- }
-
- /* Create the mutex. */
- assert (pthread_mutex_init (&mutex, &mattr) == 0);
-
- log (" Protocol %s, Type %s\n",
- protocol_strs[mproto], mutextype_strs[mkind]);
-
- log (" Unlock on mutex held by self - ");
- assert (pthread_mutex_lock (&mutex) == 0);
- ret = pthread_mutex_unlock (&mutex);
- check_result (/* expected */ 0, ret);
-
- log (" Unlock on invalid mutex - ");
- ret = pthread_mutex_unlock (NULL);
- check_result (/* expected */ EINVAL, ret);
-
- log (" Unlock on mutex locked by another thread - ");
- send_mutex_cmd (test_thread_id, CMD_TAKE_MUTEX, &mutex);
- sleep (1);
- ret = pthread_mutex_unlock (&mutex);
- switch (mkind) {
- case M_POSIX:
- check_result (/* expected */ EPERM, ret);
- break;
- case M_SS2_DEFAULT:
- check_result (/* expected */ EPERM, ret);
- break;
- case M_SS2_ERRORCHECK:
- check_result (/* expected */ EPERM, ret);
- break;
- case M_SS2_NORMAL:
- check_result (/* expected */ EPERM, ret);
- break;
- case M_SS2_RECURSIVE:
- check_result (/* expected */ EPERM, ret);
- break;
- }
- if (ret == 0) {
- /*
- * If for some reason we were able to unlock
- * the mutex, relock it so that the test
- * thread has no problems releasing the mutex.
- */
- pthread_mutex_lock (&mutex);
- }
- send_cmd (test_thread_id, CMD_RELEASE_ALL);
- sleep (1);
-
- pthread_mutex_destroy (&mutex);
- pthread_mutexattr_destroy (&mattr);
- }
- }
-}
-
-
-static void
-queueing_order_test (void)
-{
- int i;
-
- log ("Testing queueing order\n");
- log ("----------------------\n");
- assert (pthread_mutex_lock (&waiter_mutex) == 0);
- /*
- * Tell the threads to report when they take the waiters mutex.
- */
- assert (pthread_mutex_lock (&cond_mutex) == 0);
- for (i = 0; i < NUM_THREADS; i++) {
- states[i].flags = FLAGS_REPORT_WAITMUTEX;
- assert (pthread_cond_signal (&states[i].cond_var) == 0);
- }
- assert (pthread_mutex_unlock (&cond_mutex) == 0);
-
- /* Signal the threads to continue. */
- sleep (1);
-
- /* Use the global condition variable next time. */
- use_global_condvar = 1;
-
- /* Release the waiting threads and allow them to run again. */
- assert (pthread_mutex_unlock (&waiter_mutex) == 0);
- sleep (1);
-
- log (" Queueing order on a mutex - ");
- check_run_order ("9,8,7,6,5,4,3,2,1,0");
- for (i = 0; i < NUM_THREADS; i = i + 1) {
- /* Tell the threads to report when they've been signaled. */
- states[i].flags = FLAGS_REPORT_WAITCONDVAR;
- }
-
- /*
- * Prevent the threads from continuing their loop after we
- * signal them.
- */
- assert (pthread_mutex_lock (&waiter_mutex) == 0);
-
-
- log (" Queueing order on a condition variable - ");
- /*
- * Signal one thread to run and see that the highest priority
- * thread executes.
- */
- assert (pthread_mutex_lock (&cond_mutex) == 0);
- assert (pthread_cond_signal (&cond_var) == 0);
- assert (pthread_mutex_unlock (&cond_mutex) == 0);
- sleep (1);
- if (states[NUM_THREADS - 1].status != STAT_WAITMUTEX)
- log_error ("highest priority thread does not run.\n");
-
- /* Signal the remaining threads. */
- assert (pthread_mutex_lock (&cond_mutex) == 0);
- assert (pthread_cond_broadcast (&cond_var) == 0);
- assert (pthread_mutex_unlock (&cond_mutex) == 0);
- sleep (1);
-
- check_run_order ("9,8,7,6,5,4,3,2,1,0");
- for (i = 0; i < NUM_THREADS; i = i + 1) {
- /* Tell the threads not to report anything. */
- states[i].flags = 0;
- }
-
- /* Use the thread unique condition variable next time. */
- use_global_condvar = 0;
-
- /* Allow the threads to continue their loop. */
- assert (pthread_mutex_unlock (&waiter_mutex) == 0);
- sleep (1);
-}
-
-
-static void
-mutex_prioceiling_test (void)
-{
- const int test_thread_id = 0; /* ID of test thread */
- pthread_mutexattr_t mattr;
- struct sched_param param;
- pthread_mutex_t m[3];
- mutex_kind_t mkind;
- int i, ret, policy, my_prio, old_ceiling;
-
- log ("Testing priority ceilings\n");
- log ("-------------------------\n");
- for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) {
-
- log (" Protype PTHREAD_PRIO_PROTECT, Type %s\n",
- mutextype_strs[mkind]);
-
- /*
- * Initialize and create a mutex.
- */
- assert (pthread_mutexattr_init (&mattr) == 0);
-
- /* Get this threads current priority. */
- assert (pthread_getschedparam (pthread_self(), &policy,
- &param) == 0);
- my_prio = param.sched_priority; /* save for later use */
- log_trace ("Current scheduling policy %d, priority %d\n",
- policy, my_prio);
-
- /*
- * Initialize and create 3 priority protection mutexes with
- * default (max priority) ceilings.
- */
- assert (pthread_mutexattr_setprotocol(&mattr,
- PTHREAD_PRIO_PROTECT) == 0);
-
- /*
- * Ensure that the first mutex type is a POSIX
- * compliant mutex.
- */
- if (mkind != M_POSIX) {
- assert (pthread_mutexattr_settype (&mattr,
- mutex_types[mkind]) == 0);
- }
-
- for (i = 0; i < 3; i++)
- assert (pthread_mutex_init (&m[i], &mattr) == 0);
-
- /*
- * Set the ceiling priorities for the 3 priority protection
- * mutexes to, 5 less than, equal to, and 5 greater than,
- * this threads current priority.
- */
- for (i = 0; i < 3; i++)
- assert (pthread_mutex_setprioceiling (&m[i],
- my_prio - 5 + 5*i, &old_ceiling) == 0);
-
- /*
- * Check that if we attempt to take a mutex whose priority
- * ceiling is lower than our priority, we get an error.
- */
- log (" Lock with ceiling priority < thread priority - ");
- ret = pthread_mutex_lock (&m[0]);
- check_result (/* expected */ EINVAL, ret);
- if (ret == 0)
- pthread_mutex_unlock (&m[0]);
-
- /*
- * Check that we can take a mutex whose priority ceiling
- * is equal to our priority.
- */
- log (" Lock with ceiling priority = thread priority - ");
- ret = pthread_mutex_lock (&m[1]);
- check_result (/* expected */ 0, ret);
- if (ret == 0)
- pthread_mutex_unlock (&m[1]);
-
- /*
- * Check that we can take a mutex whose priority ceiling
- * is higher than our priority.
- */
- log (" Lock with ceiling priority > thread priority - ");
- ret = pthread_mutex_lock (&m[2]);
- check_result (/* expected */ 0, ret);
- if (ret == 0)
- pthread_mutex_unlock (&m[2]);
-
- /*
- * Have the test thread go into a busy loop for 5 seconds
- * and see that it doesn't block this thread (since the
- * priority ceiling of mutex 0 and the priority of the test
- * thread are both less than the priority of this thread).
- */
- log (" Preemption with ceiling priority < thread "
- "priority - ");
- /* Have the test thread take mutex 0. */
- send_mutex_cmd (test_thread_id, CMD_TAKE_MUTEX, &m[0]);
- sleep (1);
-
- log_trace ("Sending busy command.\n");
- send_cmd (test_thread_id, CMD_BUSY_LOOP);
- log_trace ("Busy sent, yielding\n");
- pthread_yield ();
- log_trace ("Returned from yield.\n");
- if (states[test_thread_id].flags &
- (FLAGS_IS_BUSY | FLAGS_WAS_BUSY))
- log_error ("test thread inproperly preempted us.\n");
- else {
- /* Let the thread finish its busy loop. */
- sleep (6);
- if ((states[test_thread_id].flags & FLAGS_WAS_BUSY) == 0)
- log_error ("test thread never finished.\n");
- else
- log_pass ();
- }
- states[test_thread_id].flags &= ~FLAGS_WAS_BUSY;
-
- /* Have the test thread release mutex 0. */
- send_cmd (test_thread_id, CMD_RELEASE_ALL);
- sleep (1);
-
- /*
- * Have the test thread go into a busy loop for 5 seconds
- * and see that it preempts this thread (since the priority
- * ceiling of mutex 1 is the same as the priority of this
- * thread). The test thread should not run to completion
- * as its time quantum should expire before the 5 seconds
- * are up.
- */
- log (" Preemption with ceiling priority = thread "
- "priority - ");
-
- /* Have the test thread take mutex 1. */
- send_mutex_cmd (test_thread_id, CMD_TAKE_MUTEX, &m[1]);
- sleep (1);
-
- log_trace ("Sending busy\n");
- send_cmd (test_thread_id, CMD_BUSY_LOOP);
- log_trace ("Busy sent, yielding\n");
- pthread_yield ();
- log_trace ("Returned from yield.\n");
- if ((states[test_thread_id].flags & FLAGS_IS_BUSY) == 0)
- log_error ("test thread did not switch in on yield.\n");
- else if (states[test_thread_id].flags & FLAGS_WAS_BUSY)
- log_error ("test thread ran to completion.\n");
- else {
- /* Let the thread finish its busy loop. */
- sleep (6);
- if ((states[test_thread_id].flags & FLAGS_WAS_BUSY) == 0)
- log_error ("test thread never finished.\n");
- else
- log_pass ();
- }
- states[test_thread_id].flags &= ~FLAGS_WAS_BUSY;
-
- /* Have the test thread release mutex 1. */
- send_cmd (test_thread_id, CMD_RELEASE_ALL);
- sleep (1);
-
- /*
- * Set the scheduling policy of the test thread to SCHED_FIFO
- * and have it go into a busy loop for 5 seconds. This
- * thread is SCHED_RR, and since the priority ceiling of
- * mutex 1 is the same as the priority of this thread, the
- * test thread should run to completion once it is switched
- * in.
- */
- log (" SCHED_FIFO scheduling and ceiling priority = "
- "thread priority - ");
- param.sched_priority = states[test_thread_id].priority;
- assert (pthread_setschedparam (states[test_thread_id].tid,
- SCHED_FIFO, &param) == 0);
-
- /* Have the test thread take mutex 1. */
- send_mutex_cmd (test_thread_id, CMD_TAKE_MUTEX, &m[1]);
- sleep (1);
-
- log_trace ("Sending busy\n");
- send_cmd (test_thread_id, CMD_BUSY_LOOP);
- log_trace ("Busy sent, yielding\n");
- pthread_yield ();
- log_trace ("Returned from yield.\n");
- if ((states[test_thread_id].flags & FLAGS_WAS_BUSY) == 0) {
- log_error ("test thread did not run to completion.\n");
- /* Let the thread finish it's busy loop. */
- sleep (6);
- }
- else
- log_pass ();
- states[test_thread_id].flags &= ~FLAGS_WAS_BUSY;
-
- /* Restore the test thread scheduling parameters. */
- param.sched_priority = states[test_thread_id].priority;
- assert (pthread_setschedparam (states[test_thread_id].tid,
- SCHED_RR, &param) == 0);
-
- /* Have the test thread release mutex 1. */
- send_cmd (test_thread_id, CMD_RELEASE_ALL);
- sleep (1);
-
- /*
- * Have the test thread go into a busy loop for 5 seconds
- * and see that it preempts this thread (since the priority
- * ceiling of mutex 2 is the greater than the priority of
- * this thread). The test thread should run to completion
- * and block this thread because its active priority is
- * higher.
- */
- log (" SCHED_FIFO scheduling and ceiling priority > "
- "thread priority - ");
- /* Have the test thread take mutex 2. */
- send_mutex_cmd (test_thread_id, CMD_TAKE_MUTEX, &m[2]);
- sleep (1);
-
- log_trace ("Sending busy\n");
- send_cmd (test_thread_id, CMD_BUSY_LOOP);
- log_trace ("Busy sent, yielding\n");
- pthread_yield ();
- log_trace ("Returned from yield.\n");
- if ((states[test_thread_id].flags & FLAGS_IS_BUSY) != 0) {
- log_error ("test thread did not run to completion.\n");
- /* Let the thread finish it's busy loop. */
- sleep (6);
- }
- else if ((states[test_thread_id].flags & FLAGS_WAS_BUSY) == 0)
- log_error ("test thread never finished.\n");
- else
- log_pass ();
- states[test_thread_id].flags &= ~FLAGS_WAS_BUSY;
-
- /* Have the test thread release mutex 2. */
- send_cmd (test_thread_id, CMD_RELEASE_ALL);
- sleep (1);
-
- /* Destroy the mutexes. */
- for (i = 0; i < 3; i++)
- assert (pthread_mutex_destroy (&m[i]) == 0);
- }
-}
-
-
-static void
-mutex_prioinherit_test (void)
-{
- pthread_mutexattr_t mattr;
- struct sched_param param;
- pthread_mutex_t m[3];
- mutex_kind_t mkind;
- int i, policy, my_prio;
-
- /* Get this threads current priority. */
- assert (pthread_getschedparam (pthread_self(), &policy,
- &param) == 0);
- my_prio = param.sched_priority; /* save for later use */
- log_trace ("Current scheduling policy %d, priority %d\n",
- policy, my_prio);
-
- log ("Testing priority inheritence\n");
- log ("----------------------------\n");
- for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) {
-
- log (" Protype PTHREAD_PRIO_INHERIT, Type %s\n",
- mutextype_strs[mkind]);
-
- /*
- * Initialize and create a mutex.
- */
- assert (pthread_mutexattr_init (&mattr) == 0);
-
- /*
- * Initialize and create 3 priority inheritence mutexes with
- * default (max priority) ceilings.
- */
- assert (pthread_mutexattr_setprotocol(&mattr,
- PTHREAD_PRIO_INHERIT) == 0);
-
- /*
- * Ensure that the first mutex type is a POSIX
- * compliant mutex.
- */
- if (mkind != M_POSIX) {
- assert (pthread_mutexattr_settype (&mattr,
- mutex_types[mkind]) == 0);
- }
-
- for (i = 0; i < 3; i++)
- assert (pthread_mutex_init (&m[i], &mattr) == 0);
-
- /*
- * Test setup:
- * Thread 4 - take mutex 0, 1
- * Thread 2 - enter protected busy loop with mutex 0
- * Thread 3 - enter protected busy loop with mutex 1
- * Thread 4 - enter protected busy loop with mutex 2
- * Thread 5 - enter busy loop
- * Thread 6 - enter protected busy loop with mutex 0
- * Thread 4 - releases mutexes 1 and 0.
- *
- * Expected results:
- * Threads complete in order 4, 6, 5, 3, 2
- */
- log (" Simple inheritence test - ");
-
- /*
- * Command thread 4 to take mutexes 0 and 1.
- */
- send_mutex_cmd (4, CMD_TAKE_MUTEX, &m[0]);
- sleep (1); /* Allow command to be received. */
- send_mutex_cmd (4, CMD_TAKE_MUTEX, &m[1]);
- sleep (1);
-
- /*
- * Tell the threads to report themselves when they are
- * at the bottom of their loop (waiting on wait_mutex).
- */
- for (i = 0; i < NUM_THREADS; i++)
- states[i].flags |= FLAGS_REPORT_WAITMUTEX;
-
- /*
- * Command thread 2 to take mutex 0 and thread 3 to take
- * mutex 1, both via a protected operation command. Since
- * thread 4 owns mutexes 0 and 1, both threads 2 and 3
- * will block until the mutexes are released by thread 4.
- */
- log_trace ("Commanding protected operation to thread 2.\n");
- send_mutex_cmd (2, CMD_PROTECTED_OP, &m[0]);
- log_trace ("Commanding protected operation to thread 3.\n");
- send_mutex_cmd (3, CMD_PROTECTED_OP, &m[1]);
- sleep (1);
-
- /*
- * Command thread 4 to take mutex 2 via a protected operation
- * and thread 5 to enter a busy loop for 5 seconds. Since
- * thread 5 has higher priority than thread 4, thread 5 will
- * enter the busy loop before thread 4 is activated.
- */
- log_trace ("Commanding protected operation to thread 4.\n");
- send_mutex_cmd (4, CMD_PROTECTED_OP, &m[2]);
- log_trace ("Commanding busy loop to thread 5.\n");
- send_cmd (5, CMD_BUSY_LOOP);
- sleep (1);
- if ((states[5].flags & FLAGS_IS_BUSY) == 0)
- log_error ("thread 5 is not running.\n");
- log_trace ("Commanding protected operation thread 6.\n");
- send_mutex_cmd (6, CMD_PROTECTED_OP, &m[0]);
- sleep (1);
- if ((states[4].flags & FLAGS_WAS_BUSY) == 0)
- log_error ("thread 4 failed to inherit priority.\n");
- states[4].flags = 0;
- send_cmd (4, CMD_RELEASE_ALL);
- sleep (5);
- check_run_order ("4,6,5,3,2");
-
- /*
- * Clear the flags.
- */
- for (i = 0; i < NUM_THREADS; i++)
- states[i].flags = 0;
-
- /*
- * Test setup:
- * Thread 2 - enter busy loop (SCHED_FIFO)
- * Thread 4 - take mutex 0
- * Thread 4 - priority change to same priority as thread 2
- * Thread 4 - release mutex 0
- *
- * Expected results:
- * Since thread 4 owns a priority mutex, it should be
- * placed at the front of the run queue (for its new
- * priority slot) when its priority is lowered to the
- * same priority as thread 2. If thread 4 did not own
- * a priority mutex, then it would have been added to
- * the end of the run queue and thread 2 would have
- * executed until it blocked (because it's scheduling
- * policy is SCHED_FIFO).
- *
- */
- log (" Inheritence test with change of priority - ");
-
- /*
- * Change threads 2 and 4 scheduling policies to be
- * SCHED_FIFO.
- */
- param.sched_priority = states[2].priority;
- assert (pthread_setschedparam (states[2].tid, SCHED_FIFO,
- &param) == 0);
- param.sched_priority = states[4].priority;
- assert (pthread_setschedparam (states[4].tid, SCHED_FIFO,
- &param) == 0);
-
- /*
- * Command thread 4 to take mutex 0.
- */
- send_mutex_cmd (4, CMD_TAKE_MUTEX, &m[0]);
- sleep (1);
-
- /*
- * Command thread 2 to enter busy loop.
- */
- send_cmd (2, CMD_BUSY_LOOP);
- sleep (1); /* Allow command to be received. */
-
- /*
- * Command thread 4 to enter busy loop.
- */
- send_cmd (4, CMD_BUSY_LOOP);
- sleep (1); /* Allow command to be received. */
-
- /* Have threads 2 and 4 report themselves. */
- states[2].flags = FLAGS_REPORT_WAITMUTEX;
- states[4].flags = FLAGS_REPORT_WAITMUTEX;
-
- /* Change the priority of thread 4. */
- param.sched_priority = states[2].priority;
- assert (pthread_setschedparam (states[4].tid, SCHED_FIFO,
- &param) == 0);
- sleep (5);
- check_run_order ("4,2");
-
- /* Clear the flags */
- states[2].flags = 0;
- states[4].flags = 0;
-
- /* Reset the policies. */
- param.sched_priority = states[2].priority;
- assert (pthread_setschedparam (states[2].tid, SCHED_RR,
- &param) == 0);
- param.sched_priority = states[4].priority;
- assert (pthread_setschedparam (states[4].tid, SCHED_RR,
- &param) == 0);
-
- send_cmd (4, CMD_RELEASE_MUTEX);
- sleep (1);
-
- /* Destroy the mutexes. */
- for (i = 0; i < 3; i++)
- assert (pthread_mutex_destroy (&m[i]) == 0);
- }
-}
-
-
-int main (int argc, char *argv[])
-{
- pthread_mutexattr_t mattr;
- pthread_condattr_t cattr;
- pthread_attr_t pattr;
- int i, policy, main_prio;
- void * exit_status;
- sigset_t mask;
- struct sigaction act;
- struct sched_param param;
-
- logfile = stdout;
-
- assert (pthread_getschedparam (pthread_self (), &policy, &param) == 0);
- main_prio = param.sched_priority;
-
- /* Setupt our signal mask. */
- sigfillset (&mask);
- sigdelset (&mask, SIGINT);
- sigprocmask (SIG_SETMASK, &mask, NULL);
-
- /* Install a signal handler for SIGINT */
- sigemptyset (&act.sa_mask);
- sigaddset (&act.sa_mask, SIGINT);
- act.sa_handler = sighandler;
- act.sa_flags = SA_RESTART;
- sigaction (SIGINT, &act, NULL);
-
- /*
- * Initialize the thread attribute.
- */
- assert (pthread_attr_init (&pattr) == 0);
- assert (pthread_attr_setdetachstate (&pattr,
- PTHREAD_CREATE_JOINABLE) == 0);
-
- /*
- * Initialize and create the waiter and condvar mutexes.
- */
- assert (pthread_mutexattr_init (&mattr) == 0);
- assert (pthread_mutex_init (&waiter_mutex, &mattr) == 0);
- assert (pthread_mutex_init (&cond_mutex, &mattr) == 0);
-
- /*
- * Initialize and create a condition variable.
- */
- assert (pthread_condattr_init (&cattr) == 0);
- assert (pthread_cond_init (&cond_var, &cattr) == 0);
-
- /* Create a pipe to catch the results of thread wakeups. */
- assert (pipe (pipefd) == 0);
-
-#ifdef DEBUG
- assert (pthread_switch_add_np (kern_switch) == 0);
-#endif
-
- /*
- * Create the waiting threads.
- */
- for (i = 0; i < NUM_THREADS; i++) {
- assert (pthread_cond_init (&states[i].cond_var, &cattr) == 0);
- states[i].id = (u_int8_t) i; /* NUM_THREADS must be <= 256 */
- states[i].status = 0;
- states[i].cmd.cmd_id = CMD_NONE;
- states[i].flags = 0; /* No flags yet. */
- assert (pthread_create (&states[i].tid, &pattr, waiter,
- (void *) &states[i]) == 0);
- param.sched_priority = main_prio - 10 + i;
- states[i].priority = param.sched_priority;
- assert (pthread_setschedparam (states[i].tid, SCHED_OTHER,
- &param) == 0);
-#if defined(_LIBC_R_)
- {
- char buf[30];
-
- snprintf (buf, sizeof(buf), "waiter_%d", i);
- pthread_set_name_np (states[i].tid, buf);
- }
-#endif
- }
-
- /* Allow the threads to start. */
- sleep (1);
- log_trace ("Done creating threads.\n");
-
- log ("\n");
- mutex_init_test ();
- log ("\n");
- mutex_destroy_test ();
- log ("\n");
- mutex_lock_test ();
- log ("\n");
- mutex_unlock_test ();
- log ("\n");
- queueing_order_test ();
- log ("\n");
- mutex_prioinherit_test ();
- log ("\n");
- mutex_prioceiling_test ();
- log ("\n");
-
- log ("Total tests %d, passed %d, failed %d\n",
- total, pass_count, error_count);
-
- /* Set the done flag and signal the threads to exit. */
- log_trace ("Setting done flag.\n");
- done = 1;
-
- /*
- * Wait for the threads to finish.
- */
- log_trace ("Trying to join threads.\n");
- for (i = 0; i < NUM_THREADS; i++) {
- send_cmd (i, CMD_NONE);
- assert (pthread_join (states[i].tid, &exit_status) == 0);
- }
-
- /* Clean up after ourselves. */
- close (pipefd[0]);
- close (pipefd[1]);
-
- if (error_count != 0)
- exit (EX_OSERR); /* any better ideas??? */
- else
- exit (EX_OK);
-}
diff --git a/lib/libkse/test/mutex_d.exp b/lib/libkse/test/mutex_d.exp
deleted file mode 100644
index de8a4e42d8e2..000000000000
--- a/lib/libkse/test/mutex_d.exp
+++ /dev/null
@@ -1,290 +0,0 @@
-
-Testing pthread_mutex_init
---------------------------
- Protocol PTHREAD_PRIO_NONE, Type POSIX (type not specified) - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_DEFAULT - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_ERRORCHECK - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_NORMAL - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_RECURSIVE - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type POSIX (type not specified) - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_DEFAULT - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_ERRORCHECK - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_NORMAL - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_RECURSIVE - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type POSIX (type not specified) - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_DEFAULT - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_ERRORCHECK - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_NORMAL - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_RECURSIVE - PASS
-
-Testing pthread_mutex_destroy
------------------------------
- Protocol PTHREAD_PRIO_NONE, Type POSIX (type not specified)
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_DEFAULT
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_ERRORCHECK
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_NORMAL
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_RECURSIVE
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type POSIX (type not specified)
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_DEFAULT
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_NORMAL
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_RECURSIVE
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type POSIX (type not specified)
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_DEFAULT
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_NORMAL
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_RECURSIVE
- Destruction of unused mutex - PASS
- Destruction of mutex locked by self - PASS
- Destruction of mutex locked by another thread - PASS
- Destruction of mutex while being used in cond_wait - PASS
-
-Testing pthread_mutex_lock
---------------------------
- Protocol PTHREAD_PRIO_NONE, Type POSIX (type not specified)
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_DEFAULT
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_ERRORCHECK
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_NORMAL
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_RECURSIVE
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type POSIX (type not specified)
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_DEFAULT
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_NORMAL
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_RECURSIVE
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type POSIX (type not specified)
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_DEFAULT
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_NORMAL
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_RECURSIVE
- Lock on unlocked mutex - PASS
- Lock on invalid mutex - PASS
- Lock on mutex held by self - PASS
-
-Testing pthread_mutex_unlock
-----------------------------
- Protocol PTHREAD_PRIO_NONE, Type POSIX (type not specified)
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_DEFAULT
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_ERRORCHECK
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_NORMAL
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_RECURSIVE
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type POSIX (type not specified)
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_DEFAULT
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_NORMAL
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_RECURSIVE
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type POSIX (type not specified)
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_DEFAULT
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_NORMAL
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
- Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_RECURSIVE
- Unlock on mutex held by self - PASS
- Unlock on invalid mutex - PASS
- Unlock on mutex locked by another thread - PASS
-
-Testing queueing order
-----------------------
- Queueing order on a mutex - PASS
- Queueing order on a condition variable - PASS
-
-Testing priority inheritence
-----------------------------
- Protype PTHREAD_PRIO_INHERIT, Type POSIX (type not specified)
- Simple inheritence test - PASS
- Inheritence test with change of priority - PASS
- Protype PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_DEFAULT
- Simple inheritence test - PASS
- Inheritence test with change of priority - PASS
- Protype PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
- Simple inheritence test - PASS
- Inheritence test with change of priority - PASS
- Protype PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_NORMAL
- Simple inheritence test - PASS
- Inheritence test with change of priority - PASS
- Protype PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_RECURSIVE
- Simple inheritence test - PASS
- Inheritence test with change of priority - PASS
-
-Testing priority ceilings
--------------------------
- Protype PTHREAD_PRIO_PROTECT, Type POSIX (type not specified)
- Lock with ceiling priority < thread priority - PASS
- Lock with ceiling priority = thread priority - PASS
- Lock with ceiling priority > thread priority - PASS
- Preemption with ceiling priority < thread priority - PASS
- Preemption with ceiling priority = thread priority - PASS
- SCHED_FIFO scheduling and ceiling priority = thread priority - PASS
- SCHED_FIFO scheduling and ceiling priority > thread priority - PASS
- Protype PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_DEFAULT
- Lock with ceiling priority < thread priority - PASS
- Lock with ceiling priority = thread priority - PASS
- Lock with ceiling priority > thread priority - PASS
- Preemption with ceiling priority < thread priority - PASS
- Preemption with ceiling priority = thread priority - PASS
- SCHED_FIFO scheduling and ceiling priority = thread priority - PASS
- SCHED_FIFO scheduling and ceiling priority > thread priority - PASS
- Protype PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
- Lock with ceiling priority < thread priority - PASS
- Lock with ceiling priority = thread priority - PASS
- Lock with ceiling priority > thread priority - PASS
- Preemption with ceiling priority < thread priority - PASS
- Preemption with ceiling priority = thread priority - PASS
- SCHED_FIFO scheduling and ceiling priority = thread priority - PASS
- SCHED_FIFO scheduling and ceiling priority > thread priority - PASS
- Protype PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_NORMAL
- Lock with ceiling priority < thread priority - PASS
- Lock with ceiling priority = thread priority - PASS
- Lock with ceiling priority > thread priority - PASS
- Preemption with ceiling priority < thread priority - PASS
- Preemption with ceiling priority = thread priority - PASS
- SCHED_FIFO scheduling and ceiling priority = thread priority - PASS
- SCHED_FIFO scheduling and ceiling priority > thread priority - PASS
- Protype PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_RECURSIVE
- Lock with ceiling priority < thread priority - PASS
- Lock with ceiling priority = thread priority - PASS
- Lock with ceiling priority > thread priority - PASS
- Preemption with ceiling priority < thread priority - PASS
- Preemption with ceiling priority = thread priority - PASS
- SCHED_FIFO scheduling and ceiling priority = thread priority - PASS
- SCHED_FIFO scheduling and ceiling priority > thread priority - PASS
-
-Total tests 212, passed 212, failed 0
diff --git a/lib/libkse/test/propagate_s.pl b/lib/libkse/test/propagate_s.pl
deleted file mode 100644
index 6b8509043d98..000000000000
--- a/lib/libkse/test/propagate_s.pl
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/usr/bin/perl -w
-#
-# Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-# the first lines of this file unmodified other than the possible
-# addition of one or more copyright notices.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-###########################################################################
-#
-# Verify that no cancellation points are propagated inside of libpthread.
-#
-# $FreeBSD$
-#
-
-@CPOINTS = ("aio_suspend", "close", "creat", "fcntl", "fsync", "mq_receive",
- "mq_send", "msync", "nanosleep", "open", "pause",
- "pthread_cond_timedwait", "pthread_cond_wait", "pthread_join",
- "pthread_testcancel", "read", "sem_wait", "sigsuspend",
- "sigtimedwait", "sigwait", "sigwaitinfo", "sleep", "system",
- "tcdrain", "wait", "waitpid", "write");
-
-print "1..1\n";
-
-$cpoints = join '\|', @CPOINTS;
-$regexp = "\" U \\(" . $cpoints . "\\\)\$\"";
-
-`nm -a /usr/lib/libc.a |grep $regexp >propagate_s.out`;
-if (!open (NMOUT, "<./propagate_s.out"))
-{
- print "not ok 1\n";
-}
-else
-{
- $propagations = 0;
-
- while (<NMOUT>)
- {
- $propagations++;
- print "$_\n";
- }
- if ($propagations != 0)
- {
- print "$propagations propagation(s)\n";
- print "not ok 1\n";
- }
- else
- {
- print "ok 1\n";
- }
- close NMOUT;
- unlink "propagate_s.out";
-}
diff --git a/lib/libkse/test/sem_d.c b/lib/libkse/test/sem_d.c
deleted file mode 100644
index b834591852d9..000000000000
--- a/lib/libkse/test/sem_d.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/****************************************************************************
- *
- * Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************
- *
- * sem test.
- *
- * $FreeBSD$
- *
- ****************************************************************************/
-
-#include <assert.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <semaphore.h>
-#include <pthread.h>
-
-#define NTHREADS 10
-
-void *
-entry(void * a_arg)
-{
- sem_t * sem = (sem_t *) a_arg;
-
- sem_wait(sem);
- fprintf(stderr, "Got semaphore\n");
-
- return NULL;
-}
-
-int
-main()
-{
- sem_t sem_a, sem_b;
- pthread_t threads[NTHREADS];
- unsigned i;
- int val;
-
- fprintf(stderr, "Test begin\n");
-
-#ifdef _LIBC_R_
- assert(-1 == sem_init(&sem_b, 1, 0));
- assert(EPERM == errno);
-#endif
-
- assert(0 == sem_init(&sem_b, 0, 0));
- assert(0 == sem_getvalue(&sem_b, &val));
- assert(0 == val);
-
- assert(0 == sem_post(&sem_b));
- assert(0 == sem_getvalue(&sem_b, &val));
- assert(1 == val);
-
- assert(0 == sem_wait(&sem_b));
- assert(-1 == sem_trywait(&sem_b));
- assert(EAGAIN == errno);
- assert(0 == sem_post(&sem_b));
- assert(0 == sem_trywait(&sem_b));
- assert(0 == sem_post(&sem_b));
- assert(0 == sem_wait(&sem_b));
- assert(0 == sem_post(&sem_b));
-
-#ifdef _LIBC_R_
- assert(SEM_FAILED == sem_open("/foo", O_CREAT | O_EXCL, 0644, 0));
- assert(ENOSYS == errno);
-
- assert(-1 == sem_close(&sem_b));
- assert(ENOSYS == errno);
-
- assert(-1 == sem_unlink("/foo"));
- assert(ENOSYS == errno);
-#endif
-
- assert(0 == sem_destroy(&sem_b));
-
- assert(0 == sem_init(&sem_a, 0, 0));
-
- for (i = 0; i < NTHREADS; i++) {
- pthread_create(&threads[i], NULL, entry, (void *) &sem_a);
- }
-
- for (i = 0; i < NTHREADS; i++) {
- assert(0 == sem_post(&sem_a));
- }
-
- for (i = 0; i < NTHREADS; i++) {
- pthread_join(threads[i], NULL);
- }
-
- for (i = 0; i < NTHREADS; i++) {
- pthread_create(&threads[i], NULL, entry, (void *) &sem_a);
- }
-
- for (i = 0; i < NTHREADS; i++) {
- assert(0 == sem_post(&sem_a));
- }
-
- for (i = 0; i < NTHREADS; i++) {
- pthread_join(threads[i], NULL);
- }
-
- assert(0 == sem_destroy(&sem_a));
-
- fprintf(stderr, "Test end\n");
- return 0;
-}
diff --git a/lib/libkse/test/sem_d.exp b/lib/libkse/test/sem_d.exp
deleted file mode 100644
index b0de3da1f5e6..000000000000
--- a/lib/libkse/test/sem_d.exp
+++ /dev/null
@@ -1,22 +0,0 @@
-Test begin
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Got semaphore
-Test end
diff --git a/lib/libkse/test/sigsuspend_d.c b/lib/libkse/test/sigsuspend_d.c
deleted file mode 100644
index d2420ed84456..000000000000
--- a/lib/libkse/test/sigsuspend_d.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel M. Eischen <eischen@vigrid.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel M. Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL M. EISCHEN AND CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <errno.h>
-#include <pthread.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-
-#if defined(_LIBC_R_)
-#include <pthread_np.h>
-#endif
-
-static int sigcounts[NSIG + 1];
-static int sigfifo[NSIG + 1];
-static int fifo_depth = 0;
-static sigset_t suspender_mask;
-static pthread_t suspender_tid;
-
-
-static void *
-sigsuspender (void *arg)
-{
- int save_count, status, i;
- sigset_t run_mask;
-
- /* Run with all signals blocked. */
- sigfillset (&run_mask);
- sigprocmask (SIG_SETMASK, &run_mask, NULL);
-
- /* Allow these signals to wake us up during a sigsuspend. */
- sigfillset (&suspender_mask); /* Default action */
- sigdelset (&suspender_mask, SIGINT); /* terminate */
- sigdelset (&suspender_mask, SIGHUP); /* terminate */
- sigdelset (&suspender_mask, SIGQUIT); /* create core image */
- sigdelset (&suspender_mask, SIGURG); /* ignore */
- sigdelset (&suspender_mask, SIGIO); /* ignore */
- sigdelset (&suspender_mask, SIGUSR2); /* terminate */
-
- while (sigcounts[SIGINT] == 0) {
- save_count = sigcounts[SIGUSR2];
-
- status = sigsuspend (&suspender_mask);
- if ((status == 0) || (errno != EINTR)) {
- fprintf (stderr, "Unable to suspend for signals, "
- "errno %d, return value %d\n",
- errno, status);
- exit (1);
- }
- for (i = 0; i < fifo_depth; i++)
- fprintf (stderr, "Sigsuspend woke up by signal %d\n",
- sigfifo[i]);
- fifo_depth = 0;
- }
-
- pthread_exit (arg);
- return (NULL);
-}
-
-
-static void
-sighandler (int signo)
-{
- sigset_t set, suspend_set;
- pthread_t self;
-
- if ((signo >= 0) && (signo <= NSIG))
- sigcounts[signo]++;
-
- /*
- * If we are running on behalf of the suspender thread,
- * ensure that we have the correct mask set.
- */
- self = pthread_self ();
- if (self == suspender_tid) {
- sigfifo[fifo_depth] = signo;
- fifo_depth++;
- fprintf (stderr,
- " -> Suspender thread signal handler caught signal %d\n",
- signo);
-
- /* Get the current signal mask. */
- sigprocmask (SIG_SETMASK, NULL, &set);
-
- /* The handler should run with the current signal masked. */
- suspend_set = suspender_mask;
- sigaddset(&suspend_set, signo);
-
- if (memcmp(&set, &suspend_set, sizeof(set)))
- fprintf (stderr,
- " >>> FAIL: sigsuspender signal handler running "
- "with incorrect mask.\n");
- }
- else
- fprintf (stderr,
- " -> Main thread signal handler caught signal %d\n",
- signo);
-}
-
-
-static void
-send_thread_signal (pthread_t tid, int signo)
-{
- if (pthread_kill (tid, signo) != 0) {
- fprintf (stderr, "Unable to send thread signal, errno %d.\n",
- errno);
- exit (1);
- }
-}
-
-
-static void
-send_process_signal (int signo)
-{
- if (kill (getpid (), signo) != 0) {
- fprintf (stderr, "Unable to send process signal, errno %d.\n",
- errno);
- exit (1);
- }
-}
-
-
-int main (int argc, char *argv[])
-{
- pthread_attr_t pattr;
- void * exit_status;
- struct sigaction act;
- sigset_t oldset;
- sigset_t newset;
-
- /* Initialize our signal counts. */
- memset ((void *) sigcounts, 0, NSIG * sizeof (int));
-
- /* Ignore signal SIGIO. */
- sigemptyset (&act.sa_mask);
- sigaddset (&act.sa_mask, SIGIO);
- act.sa_handler = SIG_IGN;
- act.sa_flags = 0;
- sigaction (SIGIO, &act, NULL);
-
- /* Install a signal handler for SIGURG. */
- sigemptyset (&act.sa_mask);
- sigaddset (&act.sa_mask, SIGURG);
- act.sa_handler = sighandler;
- act.sa_flags = SA_RESTART;
- sigaction (SIGURG, &act, NULL);
-
- /* Install a signal handler for SIGXCPU */
- sigemptyset (&act.sa_mask);
- sigaddset (&act.sa_mask, SIGXCPU);
- sigaction (SIGXCPU, &act, NULL);
-
- /* Get our current signal mask. */
- sigprocmask (SIG_SETMASK, NULL, &oldset);
-
- /* Mask out SIGUSR1 and SIGUSR2. */
- newset = oldset;
- sigaddset (&newset, SIGUSR1);
- sigaddset (&newset, SIGUSR2);
- sigprocmask (SIG_SETMASK, &newset, NULL);
-
- /* Install a signal handler for SIGUSR1 */
- sigemptyset (&act.sa_mask);
- sigaddset (&act.sa_mask, SIGUSR1);
- sigaction (SIGUSR1, &act, NULL);
-
- /* Install a signal handler for SIGUSR2 */
- sigemptyset (&act.sa_mask);
- sigaddset (&act.sa_mask, SIGUSR2);
- sigaction (SIGUSR2, &act, NULL);
-
- /*
- * Initialize the thread attribute.
- */
- if ((pthread_attr_init (&pattr) != 0) ||
- (pthread_attr_setdetachstate (&pattr,
- PTHREAD_CREATE_JOINABLE) != 0)) {
- fprintf (stderr, "Unable to initialize thread attributes.\n");
- exit (1);
- }
-
- /*
- * Create the sigsuspender thread.
- */
- if (pthread_create (&suspender_tid, &pattr, sigsuspender, NULL) != 0) {
- fprintf (stderr, "Unable to create thread, errno %d.\n", errno);
- exit (1);
- }
-#if defined(_LIBC_R)
- pthread_set_name_np (suspender_tid, "sigsuspender");
-#endif
-
- /*
- * Verify that an ignored signal doesn't cause a wakeup.
- * We don't have a handler installed for SIGIO.
- */
- send_thread_signal (suspender_tid, SIGIO);
- sleep (1);
- send_process_signal (SIGIO);
- sleep (1);
- if (sigcounts[SIGIO] != 0)
- fprintf (stderr, "FAIL: sigsuspend wakes up for ignored signal "
- "SIGIO.\n");
-
- /*
- * Verify that a signal with a default action of ignore, for
- * which we have a signal handler installed, will release a
- * sigsuspend.
- */
- send_thread_signal (suspender_tid, SIGURG);
- sleep (1);
- send_process_signal (SIGURG);
- sleep (1);
- if (sigcounts[SIGURG] != 2)
- fprintf (stderr,
- "FAIL: sigsuspend doesn't wake up for SIGURG.\n");
-
- /*
- * Verify that a SIGUSR2 signal will release a sigsuspended
- * thread.
- */
- send_thread_signal (suspender_tid, SIGUSR2);
- sleep (1);
- send_process_signal (SIGUSR2);
- sleep (1);
- if (sigcounts[SIGUSR2] != 2)
- fprintf (stderr,
- "FAIL: sigsuspend doesn't wake up for SIGUSR2.\n");
-
- /*
- * Verify that a signal, blocked in both the main and
- * sigsuspender threads, does not cause the signal handler
- * to be called.
- */
- send_thread_signal (suspender_tid, SIGUSR1);
- sleep (1);
- send_process_signal (SIGUSR1);
- sleep (1);
- if (sigcounts[SIGUSR1] != 0)
- fprintf (stderr, "FAIL: signal hander called for SIGUSR1.\n");
-
- /*
- * Verify that we can still kill the process for a signal
- * not being waited on by sigwait.
- */
- send_process_signal (SIGPIPE);
- fprintf (stderr, "FAIL: SIGPIPE did not terminate process.\n");
-
- /*
- * Wait for the thread to finish.
- */
- pthread_join (suspender_tid, &exit_status);
-
- return (0);
-}
diff --git a/lib/libkse/test/sigsuspend_d.exp b/lib/libkse/test/sigsuspend_d.exp
deleted file mode 100644
index 901fa50dd2d1..000000000000
--- a/lib/libkse/test/sigsuspend_d.exp
+++ /dev/null
@@ -1,8 +0,0 @@
- -> Suspender thread signal handler caught signal 16
-Sigsuspend woke up by signal 16
- -> Suspender thread signal handler caught signal 16
-Sigsuspend woke up by signal 16
- -> Suspender thread signal handler caught signal 31
-Sigsuspend woke up by signal 31
- -> Suspender thread signal handler caught signal 31
-Sigsuspend woke up by signal 31
diff --git a/lib/libkse/test/sigwait_d.c b/lib/libkse/test/sigwait_d.c
deleted file mode 100644
index f3ccd6b98491..000000000000
--- a/lib/libkse/test/sigwait_d.c
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel M. Eischen <eischen@vigrid.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel M. Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL M. EISCHEN AND CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <errno.h>
-#include <pthread.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-
-#if defined(_LIBC_R_)
-#include <pthread_np.h>
-#endif
-
-static int sigcounts[NSIG + 1];
-static sigset_t wait_mask;
-static pthread_mutex_t waiter_mutex;
-
-
-static void *
-sigwaiter (void *arg)
-{
- int signo;
- sigset_t mask;
-
- /* Block SIGHUP */
- sigemptyset (&mask);
- sigaddset (&mask, SIGHUP);
- sigprocmask (SIG_BLOCK, &mask, NULL);
-
- while (sigcounts[SIGINT] == 0) {
- if (sigwait (&wait_mask, &signo) != 0) {
- fprintf (stderr,
- "Unable to wait for signal, errno %d\n",
- errno);
- exit (1);
- }
- sigcounts[signo]++;
- fprintf (stderr, "Sigwait caught signal %d\n", signo);
-
- /* Allow the main thread to prevent the sigwait. */
- pthread_mutex_lock (&waiter_mutex);
- pthread_mutex_unlock (&waiter_mutex);
- }
-
- pthread_exit (arg);
- return (NULL);
-}
-
-
-static void
-sighandler (int signo)
-{
- fprintf (stderr, " -> Signal handler caught signal %d\n", signo);
-
- if ((signo >= 0) && (signo <= NSIG))
- sigcounts[signo]++;
-}
-
-static void
-send_thread_signal (pthread_t tid, int signo)
-{
- if (pthread_kill (tid, signo) != 0) {
- fprintf (stderr, "Unable to send thread signal, errno %d.\n",
- errno);
- exit (1);
- }
-}
-
-static void
-send_process_signal (int signo)
-{
- if (kill (getpid (), signo) != 0) {
- fprintf (stderr, "Unable to send process signal, errno %d.\n",
- errno);
- exit (1);
- }
-}
-
-
-int main (int argc, char *argv[])
-{
- pthread_mutexattr_t mattr;
- pthread_attr_t pattr;
- pthread_t tid;
- void * exit_status;
- struct sigaction act;
-
- /* Initialize our signal counts. */
- memset ((void *) sigcounts, 0, NSIG * sizeof (int));
-
- /* Setup our wait mask. */
- sigemptyset (&wait_mask); /* Default action */
- sigaddset (&wait_mask, SIGHUP); /* terminate */
- sigaddset (&wait_mask, SIGINT); /* terminate */
- sigaddset (&wait_mask, SIGQUIT); /* create core image */
- sigaddset (&wait_mask, SIGURG); /* ignore */
- sigaddset (&wait_mask, SIGIO); /* ignore */
- sigaddset (&wait_mask, SIGUSR1); /* terminate */
-
- /* Ignore signals SIGHUP and SIGIO. */
- sigemptyset (&act.sa_mask);
- sigaddset (&act.sa_mask, SIGHUP);
- sigaddset (&act.sa_mask, SIGIO);
- act.sa_handler = SIG_IGN;
- act.sa_flags = 0;
- sigaction (SIGHUP, &act, NULL);
- sigaction (SIGIO, &act, NULL);
-
- /* Install a signal handler for SIGURG */
- sigemptyset (&act.sa_mask);
- sigaddset (&act.sa_mask, SIGURG);
- act.sa_handler = sighandler;
- act.sa_flags = SA_RESTART;
- sigaction (SIGURG, &act, NULL);
-
- /* Install a signal handler for SIGXCPU */
- sigemptyset (&act.sa_mask);
- sigaddset (&act.sa_mask, SIGXCPU);
- sigaction (SIGXCPU, &act, NULL);
-
- /*
- * Initialize the thread attribute.
- */
- if ((pthread_attr_init (&pattr) != 0) ||
- (pthread_attr_setdetachstate (&pattr,
- PTHREAD_CREATE_JOINABLE) != 0)) {
- fprintf (stderr, "Unable to initialize thread attributes.\n");
- exit (1);
- }
-
- /*
- * Initialize and create a mutex.
- */
- if ((pthread_mutexattr_init (&mattr) != 0) ||
- (pthread_mutex_init (&waiter_mutex, &mattr) != 0)) {
- fprintf (stderr, "Unable to create waiter mutex.\n");
- exit (1);
- }
-
- /*
- * Create the sigwaiter thread.
- */
- if (pthread_create (&tid, &pattr, sigwaiter, NULL) != 0) {
- fprintf (stderr, "Unable to create thread.\n");
- exit (1);
- }
-#if defined(_LIBC_R_)
- pthread_set_name_np (tid, "sigwaiter");
-#endif
-
- /*
- * Verify that an ignored signal doesn't cause a wakeup.
- * We don't have a handler installed for SIGIO.
- */
- send_thread_signal (tid, SIGIO);
- sleep (1);
- send_process_signal (SIGIO);
- sleep (1);
- if (sigcounts[SIGIO] != 0)
- fprintf (stderr,
- "FAIL: sigwait wakes up for ignored signal SIGIO.\n");
-
- /*
- * Verify that a signal with a default action of ignore, for
- * which we have a signal handler installed, will release a sigwait.
- */
- send_thread_signal (tid, SIGURG);
- sleep (1);
- send_process_signal (SIGURG);
- sleep (1);
- if (sigcounts[SIGURG] != 2)
- fprintf (stderr, "FAIL: sigwait doesn't wake up for SIGURG.\n");
-
- /*
- * Verify that a signal with a default action that terminates
- * the process will release a sigwait.
- */
- send_thread_signal (tid, SIGUSR1);
- sleep (1);
- send_process_signal (SIGUSR1);
- sleep (1);
- if (sigcounts[SIGUSR1] != 2)
- fprintf (stderr,
- "FAIL: sigwait doesn't wake up for SIGUSR1.\n");
-
- /*
- * Verify that if we install a signal handler for a previously
- * ignored signal, an occurrence of this signal will release
- * the (already waiting) sigwait.
- */
-
- /* Install a signal handler for SIGHUP. */
- sigemptyset (&act.sa_mask);
- sigaddset (&act.sa_mask, SIGHUP);
- act.sa_handler = sighandler;
- act.sa_flags = SA_RESTART;
- sigaction (SIGHUP, &act, NULL);
-
- /* Sending SIGHUP should release the sigwait. */
- send_process_signal (SIGHUP);
- sleep (1);
- send_thread_signal (tid, SIGHUP);
- sleep (1);
- if (sigcounts[SIGHUP] != 2)
- fprintf (stderr, "FAIL: sigwait doesn't wake up for SIGHUP.\n");
-
- /*
- * Verify that a pending signal in the waiters mask will
- * cause sigwait to return the pending signal. We do this
- * by taking the waiters mutex and signaling the waiter to
- * release him from the sigwait. The waiter will block
- * on taking the mutex, and we can then send the waiter a
- * signal which should be added to his pending signals.
- * The next time the waiter does a sigwait, he should
- * return with the pending signal.
- */
- sigcounts[SIGHUP] = 0;
- pthread_mutex_lock (&waiter_mutex);
- /* Release the waiter from sigwait. */
- send_process_signal (SIGHUP);
- sleep (1);
- if (sigcounts[SIGHUP] != 1)
- fprintf (stderr, "FAIL: sigwait doesn't wake up for SIGHUP.\n");
- /*
- * Add SIGHUP to the process pending signals. Since there is
- * a signal handler installed for SIGHUP and this signal is
- * blocked from the waiter thread and unblocked in the main
- * thread, the signal handler should be called once for SIGHUP.
- */
- send_process_signal (SIGHUP);
- /* Release the waiter thread and allow him to run. */
- pthread_mutex_unlock (&waiter_mutex);
- sleep (1);
- if (sigcounts[SIGHUP] != 2)
- fprintf (stderr,
- "FAIL: sigwait doesn't return for pending SIGHUP.\n");
-
- /*
- * Repeat the above test using pthread_kill and SIGUSR1.
- */
- sigcounts[SIGUSR1] = 0;
- pthread_mutex_lock (&waiter_mutex);
- /* Release the waiter from sigwait. */
- send_thread_signal (tid, SIGUSR1);
- sleep (1);
- if (sigcounts[SIGUSR1] != 1)
- fprintf (stderr,
- "FAIL: sigwait doesn't wake up for SIGUSR1.\n");
- /* Add SIGUSR1 to the waiters pending signals. */
- send_thread_signal (tid, SIGUSR1);
- /* Release the waiter thread and allow him to run. */
- pthread_mutex_unlock (&waiter_mutex);
- sleep (1);
- if (sigcounts[SIGUSR1] != 2)
- fprintf (stderr,
- "FAIL: sigwait doesn't return for pending SIGUSR1.\n");
-
- /*
- * Verify that we can still kill the process for a signal
- * not being waited on by sigwait.
- */
- send_process_signal (SIGPIPE);
- fprintf (stderr, "FAIL: SIGPIPE did not terminate process.\n");
-
- /*
- * Wait for the thread to finish.
- */
- pthread_join (tid, &exit_status);
-
- return (0);
-}
diff --git a/lib/libkse/test/sigwait_d.exp b/lib/libkse/test/sigwait_d.exp
deleted file mode 100644
index 2e9b2c492525..000000000000
--- a/lib/libkse/test/sigwait_d.exp
+++ /dev/null
@@ -1,10 +0,0 @@
-Sigwait caught signal 16
-Sigwait caught signal 16
-Sigwait caught signal 30
-Sigwait caught signal 30
-Sigwait caught signal 1
-Sigwait caught signal 1
-Sigwait caught signal 1
- -> Signal handler caught signal 1
-Sigwait caught signal 30
-Sigwait caught signal 30
diff --git a/lib/libkse/test/verify b/lib/libkse/test/verify
deleted file mode 100644
index 2863e5c3fa0c..000000000000
--- a/lib/libkse/test/verify
+++ /dev/null
@@ -1,474 +0,0 @@
-#!/usr/bin/perl -w
-#-*-mode:perl-*-
-#############################################################################
-#
-# Copyright (C) 1999-2001 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-# the first lines of this file unmodified other than the possible
-# addition of one or more copyright notices.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-#############################################################################
-#
-# Test harness.
-#
-# $FreeBSD$
-#
-#############################################################################
-
-# Shut off buffering.
-select(STDOUT);
-$| = 1;
-
-#
-# Parse command-line arguments.
-#
-use Getopt::Long;
-Getopt::Long::config("bundling"); # Allow -hv rather than forcing -h -v.
-
-# Set option defaults for optional arguments.
-$opt_help = 0;
-$opt_verbose = 0;
-$opt_quiet = 0;
-$opt_srcdir = ".";
-$opt_objdir = ".";
-$opt_ustats = 0;
-$opt_zero = 0;
-
-$opt_retval =
-&GetOptions("h|help" => \$opt_help,
- "v|verbose" => \$opt_verbose,
- "q|quiet" => \$opt_quiet,
- "s|srcdir=s" => \$opt_srcdir,
- "o|objdir=s" => \$opt_objdir,
- "u|ustats" => \$opt_ustats,
- "z|zero" => \$opt_zero
- );
-
-if ($opt_help)
-{
- &usage();
- exit(0);
-}
-
-if ($opt_retval == 0)
-{
- &usage();
- exit 1;
-}
-
-if ($opt_verbose && $opt_quiet)
-{
- print STDERR "-v and -q are incompatible\n";
- &usage();
- exit 1;
-}
-
-if ($#ARGV + 1 == 0)
-{
- print STDERR "No tests specified\n";
- &usage();
- exit 1;
-}
-
-if ($opt_verbose)
-{
- print STDERR "Option values: h:$opt_help, v:$opt_verbose, "
- . "s:\"$opt_srcdir\", o:\"$opt_objdir\" "
- . "q:$opt_quiet, u:$opt_ustats, z:$opt_zero\n";
- printf STDERR "Tests (%d total): @ARGV\n", $#ARGV + 1;
-}
-
-#
-# Create and print header.
-#
-@TSTATS =
-(
- "--------------------------------------------------------------------------\n",
- "Test c_user c_system c_total chng\n",
- " passed/FAILED h_user h_system h_total %% chng\n"
- );
-
-if (!$opt_quiet)
-{
- foreach $line (@TSTATS)
- {
- printf STDOUT "$line";
- }
-}
-
-#
-# Run sequence test(s).
-#
-$total_utime = 0.0; # Total user time.
-$total_stime = 0.0; # Total system time.
-$total_hutime = 0.0; # Total historical user time.
-$total_hstime = 0.0; # Total historical system time.
-$total_ntime = 0.0; # Total time for tests that have historical data.
-
-foreach $test (@ARGV)
-{
- # Strip out any whitespace in $test.
- $test =~ s/^\s*(.*)\s*$/$1/;
-
- $okay = 1;
-
- if (-e "$opt_srcdir/$test.exp")
- {
- # Diff mode.
-
- ($okay, $utime, $stime) = &run_test($test);
-
- if (-e "$opt_objdir/$test.out")
- {
- `diff $opt_srcdir/$test.exp $opt_objdir/$test.out > $opt_objdir/$test.diff 2>&1`;
- if ($?)
- {
- # diff returns non-zero if there is a difference.
- $okay = 0;
- }
- }
- else
- {
- $okay = 0;
- if ($opt_verbose)
- {
- print STDERR
- "Nonexistent output file \"$opt_objdir/$test.out\"\n";
- }
- }
-
- ($hutime, $hstime) = &print_stats($test, $okay, 0, 0, $utime, $stime);
- }
- else
- {
- # Sequence mode.
-
- ($okay, $utime, $stime) = &run_test($test);
-
- if (open (STEST_OUT, "<$opt_objdir/$test.out"))
- {
- $num_subtests = 0;
- $num_failed_subtests = 0;
-
- while (defined($line = <STEST_OUT>))
- {
- if ($line =~ /1\.\.(\d+)/)
- {
- $num_subtests = $1;
- last;
- }
- }
- if ($num_subtests == 0)
- {
- $okay = 0;
- if ($opt_verbose)
- {
- print STDERR "Malformed or missing 1..n line\n";
- }
- }
- else
- {
- for ($subtest = 1; $subtest <= $num_subtests; $subtest++)
- {
- while (defined($line = <STEST_OUT>))
- {
- if ($line =~ /^not\s+ok\s+(\d+)?/)
- {
- $not = 1;
- $test_num = $1;
- last;
- }
- elsif ($line =~ /^ok\s+(\d+)?/)
- {
- $not = 0;
- $test_num = $1;
- last;
- }
- }
- if (defined($line))
- {
- if (defined($test_num) && ($test_num != $subtest))
- {
- # There was no output printed for one or more tests.
- for (; $subtest < $test_num; $subtest++)
- {
- $num_failed_subtests++;
- }
- }
- if ($not)
- {
- $num_failed_subtests++;
- }
- }
- else
- {
- for (; $subtest <= $num_subtests; $subtest++)
- {
- $num_failed_subtests++;
- }
- }
- }
-
- if (0 < $num_failed_subtests)
- {
- $okay = 0;
- }
- }
- }
- else
- {
- if (!$opt_quiet)
- {
- print STDERR "Cannot open output file \"$opt_objdir/$test.out\"\n";
- }
- exit 1;
- }
-
- ($hutime, $hstime) = &print_stats($test, $okay,
- $num_failed_subtests, $num_subtests,
- $utime, $stime);
- }
-
- $total_hutime += $hutime;
- $total_hstime += $hstime;
-
- if ($okay)
- {
- $total_utime += $utime;
- $total_stime += $stime;
- }
- else
- {
- @FAILED_TESTS = (@FAILED_TESTS, $test);
- }
-
- # If there were historical data, add the run time to the total time to
- # compare against the historical run time.
- if (0 < ($hutime + $hstime))
- {
- $total_ntime += $utime + $stime;
- }
-}
-
-# Print summary stats.
-$tt_str = sprintf ("%d / %d passed (%5.2f%%%%)",
- ($#ARGV + 1) - ($#FAILED_TESTS + 1),
- $#ARGV + 1,
- (($#ARGV + 1) - ($#FAILED_TESTS + 1))
- / ($#ARGV + 1) * 100);
-
-$t_str = sprintf ("Totals %7.2f %7.2f %7.2f"
- . " %7.2f\n"
- . " %s %7.2f %7.2f %7.2f %7.2f%%%%\n",
- $total_utime, $total_stime, $total_utime + $total_stime,
- ($total_ntime - ($total_hutime + $total_hstime)),
- $tt_str . ' ' x (40 - length($tt_str)),
- $total_hutime, $total_hstime, $total_hutime + $total_hstime,
- ($total_hutime + $total_hstime == 0.0) ? 0.0 :
- (($total_ntime
- - ($total_hutime + $total_hstime))
- / ($total_hutime + $total_hstime) * 100));
-
-@TSTATS = ("--------------------------------------------------------------------------\n",
- $t_str,
- "--------------------------------------------------------------------------\n"
- );
-if (!$opt_quiet)
-{
- foreach $line (@TSTATS)
- {
- printf STDOUT "$line";
- }
-}
-
-if ($#FAILED_TESTS >= 0)
-{
- # One or more tests failed, so return an error.
- exit 1;
-}
-# End of main execution.
-
-sub run_test
-{
- my ($test) = @_;
- my ($okay) = 1;
- my ($tutime, $tstime);
- my ($utime, $stime, $cutime, $cstime);
- my (@TSTATS, @TPATH);
- my ($t_str);
- my ($srcdir, $objdir);
-
- # Get the path component of $test, if any.
- @TPATH = split(/\//, $test);
- pop(@TPATH);
- $srcdir = join('/', ($opt_srcdir, @TPATH));
- $objdir = join('/', ($opt_objdir, @TPATH));
-
- @TSTATS = ("--------------------------------------------------------------------------\n");
-
- $t_str = sprintf ("%s%s", $test, ' ' x (40 - length($test)));
- @TSTATS = (@TSTATS, $t_str);
- @STATS = (@STATS, @TSTATS);
- if (!$opt_quiet)
- {
- foreach $line (@TSTATS)
- {
- printf STDOUT "$line";
- }
- }
-
- ($utime, $stime, $cutime, $cstime) = times;
- `$opt_objdir/$test $srcdir $objdir > $opt_objdir/$test.out 2>&1`;
- ($utime, $stime, $tutime, $tstime) = times;
-
- # Subtract the before time from the after time.
- $tutime -= $cutime;
- $tstime -= $cstime;
-
- if ($opt_zero)
- {
- if ($?)
- {
- $okay = 0;
- if ($opt_verbose)
- {
- print STDERR
- "\"$opt_objdir/$test > $opt_objdir/$test.out 2>&1\" returned $?\n";
- }
- }
- }
-
- return ($okay, $tutime, $tstime);
-}
-
-sub print_stats
-{
- my ($test, $okay, $failed_subtests, $subtests, $utime, $stime) = @_;
- my ($hutime, $hstime);
-# my (TEST_PERF);
- my (@TSTATS);
- my ($t_str, $pass_str);
-
- $pass_str = $okay ? "passed" : "*** FAILED ***";
- if ((0 != $subtests) && (!$okay))
- {
- $pass_str = $pass_str . " ($failed_subtests/$subtests failed)";
- }
- $pass_str = $pass_str . ' ' x (39 - length($pass_str));
-
- if (-r "$test.perf")
- {
- if (!open (TEST_PERF, "<$opt_objdir/$test.perf"))
- {
- print STDERR "Unable to open \"$opt_objdir/$test.perf\"\n";
- exit 1;
- }
- $_ = <TEST_PERF>;
-
- ($hutime, $hstime) = split;
- close TEST_PERF;
-
- $t_str = sprintf (" %7.2f %7.2f %7.2f %7.2f\n"
- . " %s %7.2f %7.2f %7.2f %7.2f%%%%\n",
- $utime, $stime, $utime + $stime,
- ($utime + $stime) - ($hutime + $hstime),
- $pass_str,
- $hutime, $hstime, $hutime + $hstime,
- (($hutime + $hstime) == 0.0) ? 0.0 :
- ((($utime + $stime) - ($hutime + $hstime))
- / ($hutime + $hstime) * 100));
- }
- else
- {
- $hutime = 0.0;
- $hstime = 0.0;
-
- $t_str = sprintf (" %7.2f %7.2f %7.2f \n"
- . " %s\n",
- $utime, $stime, $utime + $stime,
- $pass_str);
- }
- @TSTATS = ($t_str);
- if (!$opt_quiet)
- {
- foreach $line (@TSTATS)
- {
- printf STDOUT "$line";
- }
- }
-
- if ($okay && $opt_ustats)
- {
- if (!open (TEST_PERF, ">$opt_objdir/$test.perf"))
- {
- if (!$opt_quiet)
- {
- print STDERR "Unable to update \"$opt_objdir/$test.perf\"\n";
- }
- }
- else
- {
- print TEST_PERF "$utime $stime\n";
- close TEST_PERF;
- }
- }
-
- return ($hutime, $hstime);
-}
-
-sub usage
-{
- print <<EOF;
-$0 usage:
- $0 [<options>] <test>+
-
- Option | Description
- --------------+-------------------------------------------------------------
- -h --help | Print usage and exit.
- -v --verbose | Verbose (incompatible with quiet).
- -q --quiet | Quiet (incompatible with verbose).
- -s --srcdir | Path to source tree (default is ".").
- -o --objdir | Path to object tree (default is ".").
- -u --ustats | Update historical statistics (stored in "<test>.perf".
- -z --zero | Consider non-zero exit code to be an error.
- --------------+-------------------------------------------------------------
-
- If <test>.exp exists, <test>'s output is diff'ed with <test>.exp. Any
- difference is considered failure.
-
- If <test>.exp does not exist, output to stdout of the following form is
- expected:
-
- 1..<n>
- {not }ok[ 1]
- {not }ok[ 2]
- ...
- {not }ok[ n]
-
- 1 <= <n> < 2^31
-
- Lines which do not match the patterns shown above are ignored.
-EOF
-}
diff --git a/lib/libkse/thread/Makefile.inc b/lib/libkse/thread/Makefile.inc
deleted file mode 100644
index cc4f3409758c..000000000000
--- a/lib/libkse/thread/Makefile.inc
+++ /dev/null
@@ -1,105 +0,0 @@
-# $FreeBSD$
-
-# thr sources
-.PATH: ${.CURDIR}/thread
-
-SRCS+= \
- thr_aio_suspend.c \
- thr_autoinit.c \
- thr_attr_destroy.c \
- thr_attr_init.c \
- thr_attr_get_np.c \
- thr_attr_getdetachstate.c \
- thr_attr_getguardsize.c \
- thr_attr_getinheritsched.c \
- thr_attr_getschedparam.c \
- thr_attr_getschedpolicy.c \
- thr_attr_getscope.c \
- thr_attr_getstack.c \
- thr_attr_getstackaddr.c \
- thr_attr_getstacksize.c \
- thr_attr_setcreatesuspend_np.c \
- thr_attr_setdetachstate.c \
- thr_attr_setguardsize.c \
- thr_attr_setinheritsched.c \
- thr_attr_setschedparam.c \
- thr_attr_setschedpolicy.c \
- thr_attr_setscope.c \
- thr_attr_setstack.c \
- thr_attr_setstackaddr.c \
- thr_attr_setstacksize.c \
- thr_cancel.c \
- thr_clean.c \
- thr_close.c \
- thr_concurrency.c \
- thr_cond.c \
- thr_condattr_destroy.c \
- thr_condattr_init.c \
- thr_creat.c \
- thr_create.c \
- thr_detach.c \
- thr_equal.c \
- thr_exit.c \
- thr_fcntl.c \
- thr_find_thread.c \
- thr_fork.c \
- thr_fsync.c \
- thr_getprio.c \
- thr_getschedparam.c \
- thr_info.c \
- thr_init.c \
- thr_join.c \
- thr_kern.c \
- thr_kill.c \
- thr_main_np.c \
- thr_mattr_init.c \
- thr_mattr_kind_np.c \
- thr_msync.c \
- thr_multi_np.c \
- thr_mutex.c \
- thr_mutex_prioceiling.c \
- thr_mutex_protocol.c \
- thr_mutexattr_destroy.c \
- thr_nanosleep.c \
- thr_once.c \
- thr_open.c \
- thr_pause.c \
- thr_poll.c \
- thr_printf.c \
- thr_priority_queue.c \
- thr_pselect.c \
- thr_read.c \
- thr_readv.c \
- thr_resume_np.c \
- thr_rtld.c \
- thr_rwlock.c \
- thr_rwlockattr.c \
- thr_select.c \
- thr_self.c \
- thr_sem.c \
- thr_seterrno.c \
- thr_setprio.c \
- thr_setschedparam.c \
- thr_sig.c \
- thr_sigaction.c \
- thr_sigmask.c \
- thr_sigpending.c \
- thr_sigprocmask.c \
- thr_sigsuspend.c \
- thr_sigwait.c \
- thr_single_np.c \
- thr_sleep.c \
- thr_spec.c \
- thr_spinlock.c \
- thr_stack.c \
- thr_suspend_np.c \
- thr_switch_np.c \
- thr_system.c \
- thr_tcdrain.c \
- thr_vfork.c \
- thr_wait.c \
- thr_wait4.c \
- thr_waitpid.c \
- thr_write.c \
- thr_writev.c \
- thr_yield.c
diff --git a/lib/libkse/thread/thr_aio_suspend.c b/lib/libkse/thread/thr_aio_suspend.c
deleted file mode 100644
index 94eed27ca02e..000000000000
--- a/lib/libkse/thread/thr_aio_suspend.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include <aio.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_aio_suspend, aio_suspend);
-
-int
-_aio_suspend(const struct aiocb * const iocbs[], int niocb, const struct
- timespec *timeout)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __sys_aio_suspend(iocbs, niocb, timeout);
- _thr_leave_cancellation_point(curthread);
-
- return (ret);
-}
-
diff --git a/lib/libkse/thread/thr_attr_destroy.c b/lib/libkse/thread/thr_attr_destroy.c
deleted file mode 100644
index e239a1dc5c41..000000000000
--- a/lib/libkse/thread/thr_attr_destroy.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <stdlib.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_destroy, pthread_attr_destroy);
-
-int
-_pthread_attr_destroy(pthread_attr_t *attr)
-{
- int ret;
-
- /* Check for invalid arguments: */
- if (attr == NULL || *attr == NULL)
- /* Invalid argument: */
- ret = EINVAL;
- else {
- /* Free the memory allocated to the attribute object: */
- free(*attr);
-
- /*
- * Leave the attribute pointer NULL now that the memory
- * has been freed:
- */
- *attr = NULL;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_get_np.c b/lib/libkse/thread/thr_attr_get_np.c
deleted file mode 100644
index 44318246770d..000000000000
--- a/lib/libkse/thread/thr_attr_get_np.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2002,2003 Alexey Zelkin <phantom@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-#include <errno.h>
-#include <string.h>
-#include <pthread.h>
-#include <pthread_np.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_get_np, pthread_attr_get_np);
-
-int
-_pthread_attr_get_np(pthread_t pid, pthread_attr_t *dst)
-{
- struct pthread *curthread;
- int ret;
-
- if (pid == NULL || dst == NULL || *dst == NULL)
- return (EINVAL);
-
- curthread = _get_curthread();
- if ((ret = _thr_ref_add(curthread, pid, /*include dead*/0)) != 0)
- return (ret);
-
- memcpy(*dst, &pid->attr, sizeof(struct pthread_attr));
- _thr_ref_delete(curthread, pid);
-
- return (0);
-}
diff --git a/lib/libkse/thread/thr_attr_getdetachstate.c b/lib/libkse/thread/thr_attr_getdetachstate.c
deleted file mode 100644
index d994548de061..000000000000
--- a/lib/libkse/thread/thr_attr_getdetachstate.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_getdetachstate, pthread_attr_getdetachstate);
-
-int
-_pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
-{
- int ret;
-
- /* Check for invalid arguments: */
- if (attr == NULL || *attr == NULL || detachstate == NULL)
- ret = EINVAL;
- else {
- /* Check if the detached flag is set: */
- if ((*attr)->flags & PTHREAD_DETACHED)
- /* Return detached: */
- *detachstate = PTHREAD_CREATE_DETACHED;
- else
- /* Return joinable: */
- *detachstate = PTHREAD_CREATE_JOINABLE;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_getguardsize.c b/lib/libkse/thread/thr_attr_getguardsize.c
deleted file mode 100644
index b32015ad0a15..000000000000
--- a/lib/libkse/thread/thr_attr_getguardsize.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2001 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer
- * unmodified other than the allowable addition of one or more
- * copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_getguardsize, pthread_attr_getguardsize);
-
-int
-_pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize)
-{
- int ret;
-
- /* Check for invalid arguments: */
- if (attr == NULL || *attr == NULL || guardsize == NULL)
- ret = EINVAL;
- else {
- /* Return the guard size: */
- *guardsize = (*attr)->guardsize_attr;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_getinheritsched.c b/lib/libkse/thread/thr_attr_getinheritsched.c
deleted file mode 100644
index 26ae9e483113..000000000000
--- a/lib/libkse/thread/thr_attr_getinheritsched.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_getinheritsched, pthread_attr_getinheritsched);
-
-int
-_pthread_attr_getinheritsched(const pthread_attr_t *attr, int *sched_inherit)
-{
- int ret = 0;
-
- if ((attr == NULL) || (*attr == NULL))
- ret = EINVAL;
- else
- *sched_inherit = (*attr)->sched_inherit;
-
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_getschedparam.c b/lib/libkse/thread/thr_attr_getschedparam.c
deleted file mode 100644
index 79911f4ad4ba..000000000000
--- a/lib/libkse/thread/thr_attr_getschedparam.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_getschedparam, pthread_attr_getschedparam);
-
-int
-_pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)
-{
- int ret = 0;
-
- if ((attr == NULL) || (*attr == NULL) || (param == NULL))
- ret = EINVAL;
- else
- param->sched_priority = (*attr)->prio;
-
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_getschedpolicy.c b/lib/libkse/thread/thr_attr_getschedpolicy.c
deleted file mode 100644
index 1234b7d06849..000000000000
--- a/lib/libkse/thread/thr_attr_getschedpolicy.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_getschedpolicy, pthread_attr_getschedpolicy);
-
-int
-_pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
-{
- int ret = 0;
-
- if ((attr == NULL) || (*attr == NULL) || (policy == NULL))
- ret = EINVAL;
- else
- *policy = (*attr)->sched_policy;
-
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_getscope.c b/lib/libkse/thread/thr_attr_getscope.c
deleted file mode 100644
index fefe6cf8ee43..000000000000
--- a/lib/libkse/thread/thr_attr_getscope.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_getscope, pthread_attr_getscope);
-
-int
-_pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope)
-{
- int ret = 0;
-
- if ((attr == NULL) || (*attr == NULL) || (contentionscope == NULL))
- /* Return an invalid argument: */
- ret = EINVAL;
-
- else
- *contentionscope = (*attr)->flags & PTHREAD_SCOPE_SYSTEM ?
- PTHREAD_SCOPE_SYSTEM : PTHREAD_SCOPE_PROCESS;
-
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_getstack.c b/lib/libkse/thread/thr_attr_getstack.c
deleted file mode 100644
index 8c0f87fbe07d..000000000000
--- a/lib/libkse/thread/thr_attr_getstack.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2003 Craig Rodrigues <rodrigc@attbi.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Craig Rodrigues.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY CRAIG RODRIGUES AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_getstack, pthread_attr_getstack);
-
-int
-_pthread_attr_getstack(const pthread_attr_t * __restrict attr,
- void ** __restrict stackaddr,
- size_t * __restrict stacksize)
-{
- int ret;
-
- /* Check for invalid arguments: */
- if (attr == NULL || *attr == NULL || stackaddr == NULL
- || stacksize == NULL )
- ret = EINVAL;
- else {
- /* Return the stack address and size */
- *stackaddr = (*attr)->stackaddr_attr;
- *stacksize = (*attr)->stacksize_attr;
- ret = 0;
- }
- return(ret);
-}
-
diff --git a/lib/libkse/thread/thr_attr_getstackaddr.c b/lib/libkse/thread/thr_attr_getstackaddr.c
deleted file mode 100644
index d0822489de32..000000000000
--- a/lib/libkse/thread/thr_attr_getstackaddr.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_getstackaddr, pthread_attr_getstackaddr);
-
-int
-_pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
-{
- int ret;
-
- /* Check for invalid arguments: */
- if (attr == NULL || *attr == NULL || stackaddr == NULL)
- ret = EINVAL;
- else {
- /* Return the stack address: */
- *stackaddr = (*attr)->stackaddr_attr;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_getstacksize.c b/lib/libkse/thread/thr_attr_getstacksize.c
deleted file mode 100644
index ec1a9beeeb7e..000000000000
--- a/lib/libkse/thread/thr_attr_getstacksize.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_getstacksize, pthread_attr_getstacksize);
-
-int
-_pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
-{
- int ret;
-
- /* Check for invalid arguments: */
- if (attr == NULL || *attr == NULL || stacksize == NULL)
- ret = EINVAL;
- else {
- /* Return the stack size: */
- *stacksize = (*attr)->stacksize_attr;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_init.c b/lib/libkse/thread/thr_attr_init.c
deleted file mode 100644
index d8b701e02040..000000000000
--- a/lib/libkse/thread/thr_attr_init.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_init, pthread_attr_init);
-
-int
-_pthread_attr_init(pthread_attr_t *attr)
-{
- int ret;
- pthread_attr_t pattr;
-
- /* Allocate memory for the attribute object: */
- if ((pattr = (pthread_attr_t) malloc(sizeof(struct pthread_attr))) == NULL)
- /* Insufficient memory: */
- ret = ENOMEM;
- else {
- /* Initialise the attribute object with the defaults: */
- memcpy(pattr, &_pthread_attr_default,
- sizeof(struct pthread_attr));
-
- /* Return a pointer to the attribute object: */
- *attr = pattr;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_setcreatesuspend_np.c b/lib/libkse/thread/thr_attr_setcreatesuspend_np.c
deleted file mode 100644
index 28f0546d4e39..000000000000
--- a/lib/libkse/thread/thr_attr_setcreatesuspend_np.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_setcreatesuspend_np, pthread_attr_setcreatesuspend_np);
-
-int
-_pthread_attr_setcreatesuspend_np(pthread_attr_t *attr)
-{
- int ret;
- if (attr == NULL || *attr == NULL) {
- errno = EINVAL;
- ret = -1;
- } else {
- (*attr)->suspend = THR_CREATE_SUSPENDED;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_setdetachstate.c b/lib/libkse/thread/thr_attr_setdetachstate.c
deleted file mode 100644
index 4d517f238225..000000000000
--- a/lib/libkse/thread/thr_attr_setdetachstate.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_setdetachstate, pthread_attr_setdetachstate);
-
-int
-_pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
-{
- int ret;
-
- /* Check for invalid arguments: */
- if (attr == NULL || *attr == NULL ||
- (detachstate != PTHREAD_CREATE_DETACHED &&
- detachstate != PTHREAD_CREATE_JOINABLE))
- ret = EINVAL;
- else {
- /* Check if detached state: */
- if (detachstate == PTHREAD_CREATE_DETACHED)
- /* Set the detached flag: */
- (*attr)->flags |= PTHREAD_DETACHED;
- else
- /* Reset the detached flag: */
- (*attr)->flags &= ~PTHREAD_DETACHED;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_setguardsize.c b/lib/libkse/thread/thr_attr_setguardsize.c
deleted file mode 100644
index 59ec908547a6..000000000000
--- a/lib/libkse/thread/thr_attr_setguardsize.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2001 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer
- * unmodified other than the allowable addition of one or more
- * copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include <sys/param.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_setguardsize, pthread_attr_setguardsize);
-
-int
-_pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
-{
- int ret;
-
- /* Check for invalid arguments. */
- if (attr == NULL || *attr == NULL)
- ret = EINVAL;
- else {
- /*
- * Round guardsize up to the nearest multiple of
- * _thr_page_size.
- */
- if (guardsize % _thr_page_size != 0)
- guardsize = ((guardsize / _thr_page_size) + 1) *
- _thr_page_size;
-
- /* Save the stack size. */
- (*attr)->guardsize_attr = guardsize;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_setinheritsched.c b/lib/libkse/thread/thr_attr_setinheritsched.c
deleted file mode 100644
index 25ff5e106fda..000000000000
--- a/lib/libkse/thread/thr_attr_setinheritsched.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_setinheritsched, pthread_attr_setinheritsched);
-
-int
-_pthread_attr_setinheritsched(pthread_attr_t *attr, int sched_inherit)
-{
- int ret = 0;
-
- if ((attr == NULL) || (*attr == NULL))
- ret = EINVAL;
- else
- (*attr)->sched_inherit = sched_inherit;
-
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_setschedparam.c b/lib/libkse/thread/thr_attr_setschedparam.c
deleted file mode 100644
index bbb4b1ec37d2..000000000000
--- a/lib/libkse/thread/thr_attr_setschedparam.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_setschedparam, pthread_attr_setschedparam);
-
-int
-_pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
-{
- int ret = 0;
-
- if ((attr == NULL) || (*attr == NULL))
- ret = EINVAL;
- else if (param == NULL) {
- ret = ENOTSUP;
- } else if ((param->sched_priority < THR_MIN_PRIORITY) ||
- (param->sched_priority > THR_MAX_PRIORITY)) {
- /* Return an unsupported value error. */
- ret = ENOTSUP;
- } else
- (*attr)->prio = param->sched_priority;
-
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_setschedpolicy.c b/lib/libkse/thread/thr_attr_setschedpolicy.c
deleted file mode 100644
index ddb092157826..000000000000
--- a/lib/libkse/thread/thr_attr_setschedpolicy.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_setschedpolicy, pthread_attr_setschedpolicy);
-
-int
-_pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
-{
- int ret = 0;
-
- if ((attr == NULL) || (*attr == NULL))
- ret = EINVAL;
- else if ((policy < SCHED_FIFO) || (policy > SCHED_RR)) {
- ret = ENOTSUP;
- } else
- (*attr)->sched_policy = policy;
-
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_setscope.c b/lib/libkse/thread/thr_attr_setscope.c
deleted file mode 100644
index 70dd69e5e6c0..000000000000
--- a/lib/libkse/thread/thr_attr_setscope.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_setscope, pthread_attr_setscope);
-
-int
-_pthread_attr_setscope(pthread_attr_t *attr, int contentionscope)
-{
- int ret = 0;
-
- if ((attr == NULL) || (*attr == NULL)) {
- /* Return an invalid argument: */
- ret = EINVAL;
- } else if ((contentionscope != PTHREAD_SCOPE_PROCESS) &&
- (contentionscope != PTHREAD_SCOPE_SYSTEM)) {
- ret = EINVAL;
- } else
- (*attr)->flags |= contentionscope;
-
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_attr_setstack.c b/lib/libkse/thread/thr_attr_setstack.c
deleted file mode 100644
index feeb7132fed1..000000000000
--- a/lib/libkse/thread/thr_attr_setstack.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2003 Craig Rodrigues <rodrigc@attbi.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Craig Rodrigues.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY CRAIG RODRIGUES AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_setstack, pthread_attr_setstack);
-
-int
-_pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr,
- size_t stacksize)
-{
- int ret;
-
- /* Check for invalid arguments: */
- if (attr == NULL || *attr == NULL || stackaddr == NULL
- || stacksize < PTHREAD_STACK_MIN )
- ret = EINVAL;
- else {
- /* Save the stack address and stack size */
- (*attr)->stackaddr_attr = stackaddr;
- (*attr)->stacksize_attr = stacksize;
- ret = 0;
- }
- return(ret);
-}
-
diff --git a/lib/libkse/thread/thr_attr_setstackaddr.c b/lib/libkse/thread/thr_attr_setstackaddr.c
deleted file mode 100644
index 87837f13388d..000000000000
--- a/lib/libkse/thread/thr_attr_setstackaddr.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_setstackaddr, pthread_attr_setstackaddr);
-
-int
-_pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
-{
- int ret;
-
- /* Check for invalid arguments: */
- if (attr == NULL || *attr == NULL || stackaddr == NULL)
- ret = EINVAL;
- else {
- /* Save the stack address: */
- (*attr)->stackaddr_attr = stackaddr;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_attr_setstacksize.c b/lib/libkse/thread/thr_attr_setstacksize.c
deleted file mode 100644
index e26ab7df948e..000000000000
--- a/lib/libkse/thread/thr_attr_setstacksize.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_attr_setstacksize, pthread_attr_setstacksize);
-
-int
-_pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
-{
- int ret;
-
- /* Check for invalid arguments: */
- if (attr == NULL || *attr == NULL || stacksize < PTHREAD_STACK_MIN)
- ret = EINVAL;
- else {
- /* Save the stack size: */
- (*attr)->stacksize_attr = stacksize;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_autoinit.c b/lib/libkse/thread/thr_autoinit.c
deleted file mode 100644
index 95b2a853ca58..000000000000
--- a/lib/libkse/thread/thr_autoinit.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2002 Alfred Perlstein <alfred@freebsd.org>.
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-
-/*
- * This module uses GCC extentions to initialize the
- * threads package at program start-up time.
- */
-
-#include <pthread.h>
-#include "thr_private.h"
-
-void _thread_init_hack(void) __attribute__ ((constructor));
-
-void
-_thread_init_hack(void)
-{
-
- _libpthread_init(NULL);
-}
-
-/*
- * For the shared version of the threads library, the above is sufficient.
- * But for the archive version of the library, we need a little bit more.
- * Namely, we must arrange for this particular module to be pulled in from
- * the archive library at link time. To accomplish that, we define and
- * initialize a variable, "_thread_autoinit_dummy_decl". This variable is
- * referenced (as an extern) from libc/stdlib/exit.c. This will always
- * create a need for this module, ensuring that it is present in the
- * executable.
- */
-extern int _thread_autoinit_dummy_decl;
-int _thread_autoinit_dummy_decl = 0;
diff --git a/lib/libkse/thread/thr_cancel.c b/lib/libkse/thread/thr_cancel.c
deleted file mode 100644
index 064e422cadf8..000000000000
--- a/lib/libkse/thread/thr_cancel.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * David Leonard <d@openbsd.org>, 1999. Public domain.
- * $FreeBSD$
- */
-#include <sys/errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_cancel, pthread_cancel);
-__weak_reference(_pthread_setcancelstate, pthread_setcancelstate);
-__weak_reference(_pthread_setcanceltype, pthread_setcanceltype);
-__weak_reference(_pthread_testcancel, pthread_testcancel);
-
-static int checkcancel(struct pthread *curthread);
-static void testcancel(struct pthread *curthread);
-static void finish_cancellation(void *arg);
-
-int
-_pthread_cancel(pthread_t pthread)
-{
- struct pthread *curthread = _get_curthread();
- struct pthread *joinee = NULL;
- int ret;
-
- if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0)) == 0) {
- /*
- * Take the scheduling lock while we change the cancel flags.
- */
- THR_SCHED_LOCK(curthread, pthread);
-
- if (((pthread->cancelflags & PTHREAD_CANCEL_DISABLE) != 0) ||
- (((pthread->cancelflags & THR_AT_CANCEL_POINT) == 0) &&
- ((pthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) == 0)))
- /* Just mark it for cancellation: */
- pthread->cancelflags |= THR_CANCELLING;
- else {
- /*
- * Check if we need to kick it back into the
- * run queue:
- */
- switch (pthread->state) {
- case PS_RUNNING:
- /* No need to resume: */
- pthread->cancelflags |= THR_CANCELLING;
- break;
-
- case PS_LOCKWAIT:
- /*
- * These can't be removed from the queue.
- * Just mark it as cancelling and tell it
- * to yield once it leaves the critical
- * region.
- */
- pthread->cancelflags |= THR_CANCELLING;
- pthread->critical_yield = 1;
- break;
-
- case PS_SLEEP_WAIT:
- case PS_SIGSUSPEND:
- case PS_SIGWAIT:
- /* Interrupt and resume: */
- pthread->interrupted = 1;
- pthread->cancelflags |= THR_CANCELLING;
- _thr_setrunnable_unlocked(pthread);
- break;
-
- case PS_JOIN:
- /* Disconnect the thread from the joinee: */
- joinee = pthread->join_status.thread;
- pthread->join_status.thread = NULL;
- pthread->cancelflags |= THR_CANCELLING;
- _thr_setrunnable_unlocked(pthread);
- if ((joinee != NULL) &&
- (curthread->kseg == joinee->kseg)) {
- /* Remove the joiner from the joinee. */
- joinee->joiner = NULL;
- joinee = NULL;
- }
- break;
-
- case PS_SUSPENDED:
- case PS_MUTEX_WAIT:
- case PS_COND_WAIT:
- /*
- * Threads in these states may be in queues.
- * In order to preserve queue integrity, the
- * cancelled thread must remove itself from the
- * queue. Mark the thread as interrupted and
- * needing cancellation, and set the state to
- * running. When the thread resumes, it will
- * remove itself from the queue and call the
- * cancellation completion routine.
- */
- pthread->interrupted = 1;
- pthread->cancelflags |= THR_CANCEL_NEEDED;
- _thr_setrunnable_unlocked(pthread);
- pthread->continuation = finish_cancellation;
- break;
-
- case PS_DEAD:
- case PS_DEADLOCK:
- case PS_STATE_MAX:
- /* Ignore - only here to silence -Wall: */
- break;
- }
- if ((pthread->blocked != 0) &&
- ((pthread->cancelflags & THR_AT_CANCEL_POINT) != 0))
- kse_thr_interrupt(&pthread->tmbx);
- }
-
- /*
- * Release the thread's scheduling lock and remove the
- * reference:
- */
- THR_SCHED_UNLOCK(curthread, pthread);
- _thr_ref_delete(curthread, pthread);
-
- if ((joinee != NULL) &&
- (_thr_ref_add(curthread, joinee, /* include dead */1) == 0)) {
- /* Remove the joiner from the joinee. */
- THR_SCHED_LOCK(curthread, joinee);
- joinee->joiner = NULL;
- THR_SCHED_UNLOCK(curthread, joinee);
- _thr_ref_delete(curthread, joinee);
- }
- }
- return (ret);
-}
-
-int
-_pthread_setcancelstate(int state, int *oldstate)
-{
- struct pthread *curthread = _get_curthread();
- int ostate;
- int ret;
- int need_exit = 0;
-
- /* Take the scheduling lock while fiddling with the thread's state: */
- THR_SCHED_LOCK(curthread, curthread);
-
- ostate = curthread->cancelflags & PTHREAD_CANCEL_DISABLE;
-
- switch (state) {
- case PTHREAD_CANCEL_ENABLE:
- if (oldstate != NULL)
- *oldstate = ostate;
- curthread->cancelflags &= ~PTHREAD_CANCEL_DISABLE;
- if ((curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0)
- need_exit = checkcancel(curthread);
- ret = 0;
- break;
- case PTHREAD_CANCEL_DISABLE:
- if (oldstate != NULL)
- *oldstate = ostate;
- curthread->cancelflags |= PTHREAD_CANCEL_DISABLE;
- ret = 0;
- break;
- default:
- ret = EINVAL;
- }
-
- THR_SCHED_UNLOCK(curthread, curthread);
- if (need_exit != 0) {
- _thr_exit_cleanup();
- pthread_exit(PTHREAD_CANCELED);
- PANIC("cancel");
- }
- return (ret);
-}
-
-int
-_pthread_setcanceltype(int type, int *oldtype)
-{
- struct pthread *curthread = _get_curthread();
- int otype;
- int ret;
- int need_exit = 0;
-
- /* Take the scheduling lock while fiddling with the state: */
- THR_SCHED_LOCK(curthread, curthread);
-
- otype = curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS;
- switch (type) {
- case PTHREAD_CANCEL_ASYNCHRONOUS:
- if (oldtype != NULL)
- *oldtype = otype;
- curthread->cancelflags |= PTHREAD_CANCEL_ASYNCHRONOUS;
- need_exit = checkcancel(curthread);
- ret = 0;
- break;
- case PTHREAD_CANCEL_DEFERRED:
- if (oldtype != NULL)
- *oldtype = otype;
- curthread->cancelflags &= ~PTHREAD_CANCEL_ASYNCHRONOUS;
- ret = 0;
- break;
- default:
- ret = EINVAL;
- }
-
- THR_SCHED_UNLOCK(curthread, curthread);
- if (need_exit != 0) {
- _thr_exit_cleanup();
- pthread_exit(PTHREAD_CANCELED);
- PANIC("cancel");
- }
- return (ret);
-}
-
-static int
-checkcancel(struct pthread *curthread)
-{
- if (((curthread->cancelflags & PTHREAD_CANCEL_DISABLE) == 0) &&
- ((curthread->cancelflags & THR_CANCELLING) != 0)) {
- /*
- * It is possible for this thread to be swapped out
- * while performing cancellation; do not allow it
- * to be cancelled again.
- */
- curthread->cancelflags &= ~THR_CANCELLING;
- return (1);
- }
- else
- return (0);
-}
-
-static void
-testcancel(struct pthread *curthread)
-{
- /* Take the scheduling lock while fiddling with the state: */
-
- if (checkcancel(curthread) != 0) {
- /* Unlock before exiting: */
- THR_SCHED_UNLOCK(curthread, curthread);
-
- _thr_exit_cleanup();
- pthread_exit(PTHREAD_CANCELED);
- PANIC("cancel");
- }
-}
-
-void
-_pthread_testcancel(void)
-{
- struct pthread *curthread = _get_curthread();
-
- THR_SCHED_LOCK(curthread, curthread);
- testcancel(curthread);
- THR_SCHED_UNLOCK(curthread, curthread);
-}
-
-void
-_thr_enter_cancellation_point(struct pthread *thread)
-{
- /* Look for a cancellation before we block: */
- THR_SCHED_LOCK(thread, thread);
- testcancel(thread);
- thread->cancelflags |= THR_AT_CANCEL_POINT;
- THR_SCHED_UNLOCK(thread, thread);
-}
-
-void
-_thr_leave_cancellation_point(struct pthread *thread)
-{
- THR_SCHED_LOCK(thread, thread);
- thread->cancelflags &= ~THR_AT_CANCEL_POINT;
- /* Look for a cancellation after we unblock: */
- testcancel(thread);
- THR_SCHED_UNLOCK(thread, thread);
-}
-
-static void
-finish_cancellation(void *arg)
-{
- struct pthread *curthread = _get_curthread();
-
- curthread->continuation = NULL;
- curthread->interrupted = 0;
-
- THR_SCHED_LOCK(curthread, curthread);
- if ((curthread->cancelflags & THR_CANCEL_NEEDED) != 0) {
- curthread->cancelflags &= ~THR_CANCEL_NEEDED;
- THR_SCHED_UNLOCK(curthread, curthread);
- _thr_exit_cleanup();
- pthread_exit(PTHREAD_CANCELED);
- }
- THR_SCHED_UNLOCK(curthread, curthread);
-}
diff --git a/lib/libkse/thread/thr_clean.c b/lib/libkse/thread/thr_clean.c
deleted file mode 100644
index a8cedb43962f..000000000000
--- a/lib/libkse/thread/thr_clean.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <signal.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_cleanup_push, pthread_cleanup_push);
-__weak_reference(_pthread_cleanup_pop, pthread_cleanup_pop);
-
-void
-_pthread_cleanup_push(void (*routine) (void *), void *routine_arg)
-{
- struct pthread *curthread = _get_curthread();
- struct pthread_cleanup *new;
-
- if ((new = (struct pthread_cleanup *)
- malloc(sizeof(struct pthread_cleanup))) != NULL) {
- new->routine = routine;
- new->routine_arg = routine_arg;
- new->next = curthread->cleanup;
-
- curthread->cleanup = new;
- }
-}
-
-void
-_pthread_cleanup_pop(int execute)
-{
- struct pthread *curthread = _get_curthread();
- struct pthread_cleanup *old;
-
- if ((old = curthread->cleanup) != NULL) {
- curthread->cleanup = old->next;
- if (execute) {
- old->routine(old->routine_arg);
- }
- free(old);
- }
-}
diff --git a/lib/libkse/thread/thr_close.c b/lib/libkse/thread/thr_close.c
deleted file mode 100644
index 269140b3e7f7..000000000000
--- a/lib/libkse/thread/thr_close.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__close, close);
-
-int
-__close(int fd)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __sys_close(fd);
- _thr_leave_cancellation_point(curthread);
-
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_concurrency.c b/lib/libkse/thread/thr_concurrency.c
deleted file mode 100644
index 485c9a1785ac..000000000000
--- a/lib/libkse/thread/thr_concurrency.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 2003 Daniel M. Eischen <deischen@freebsd.org>
- * Copyright (c) 2003 Sergey Osokin <osa@freebsd.org.ru>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
-
-#include "thr_private.h"
-
-/*#define DEBUG_CONCURRENCY */
-#ifdef DEBUG_CONCURRENCY
-#define DBG_MSG stdout_debug
-#else
-#define DBG_MSG(x...)
-#endif
-
-static int level = 0;
-
-__weak_reference(_pthread_getconcurrency, pthread_getconcurrency);
-__weak_reference(_pthread_setconcurrency, pthread_setconcurrency);
-
-int
-_pthread_getconcurrency(void)
-{
- return (level);
-}
-
-int
-_pthread_setconcurrency(int new_level)
-{
- int ret;
-
- if (new_level < 0)
- ret = EINVAL;
- else if (new_level == level)
- ret = 0;
- else if (new_level == 0) {
- level = 0;
- ret = 0;
- } else if ((_kse_isthreaded() == 0) && (_kse_setthreaded(1) != 0)) {
- DBG_MSG("Can't enable threading.\n");
- ret = EAGAIN;
- } else {
- ret = _thr_setconcurrency(new_level);
- if (ret == 0)
- level = new_level;
- }
- return (ret);
-}
-
-int
-_thr_setconcurrency(int new_level)
-{
- struct pthread *curthread;
- struct kse *newkse;
- kse_critical_t crit;
- int kse_count;
- int i;
- int ret;
-
- ret = 0;
- curthread = _get_curthread();
- /* Race condition, but so what. */
- kse_count = _kse_initial->k_kseg->kg_ksecount;
- for (i = kse_count; i < new_level; i++) {
- newkse = _kse_alloc(curthread);
- if (newkse == NULL) {
- DBG_MSG("Can't alloc new KSE.\n");
- ret = EAGAIN;
- break;
- }
- newkse->k_kseg = _kse_initial->k_kseg;
- newkse->k_schedq = _kse_initial->k_schedq;
- newkse->k_curthread = NULL;
- crit = _kse_critical_enter();
- KSE_SCHED_LOCK(curthread->kse, newkse->k_kseg);
- TAILQ_INSERT_TAIL(&newkse->k_kseg->kg_kseq,
- newkse, k_kgqe);
- newkse->k_kseg->kg_ksecount++;
- newkse->k_flags |= KF_STARTED;
- KSE_SCHED_UNLOCK(curthread->kse, newkse->k_kseg);
- if (kse_create(&newkse->k_mbx, 0) != 0) {
- KSE_SCHED_LOCK(curthread->kse, newkse->k_kseg);
- TAILQ_REMOVE(&newkse->k_kseg->kg_kseq,
- newkse, k_kgqe);
- newkse->k_kseg->kg_ksecount--;
- KSE_SCHED_UNLOCK(curthread->kse, newkse->k_kseg);
- _kse_critical_leave(crit);
- _kse_free(curthread, newkse);
- DBG_MSG("kse_create syscall failed.\n");
- ret = EAGAIN;
- break;
- } else {
- _kse_critical_leave(crit);
- }
- }
- return (ret);
-}
-
-int
-_thr_setmaxconcurrency(void)
-{
- int vcpu;
- int len;
- int ret;
-
- len = sizeof(vcpu);
- ret = sysctlbyname("kern.threads.virtual_cpu", &vcpu, &len, NULL, NULL);
- if (ret == 0 && vcpu > 0)
- ret = _thr_setconcurrency(vcpu);
- return (ret);
-}
-
diff --git a/lib/libkse/thread/thr_cond.c b/lib/libkse/thread/thr_cond.c
deleted file mode 100644
index 8bf49bc155cb..000000000000
--- a/lib/libkse/thread/thr_cond.c
+++ /dev/null
@@ -1,799 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-#define THR_IN_CONDQ(thr) (((thr)->sflags & THR_FLAGS_IN_SYNCQ) != 0)
-#define THR_IN_CONDQ(thr) (((thr)->sflags & THR_FLAGS_IN_SYNCQ) != 0)
-#define THR_CONDQ_SET(thr) (thr)->sflags |= THR_FLAGS_IN_SYNCQ
-#define THR_CONDQ_CLEAR(thr) (thr)->sflags &= ~THR_FLAGS_IN_SYNCQ
-
-/*
- * Prototypes
- */
-static inline struct pthread *cond_queue_deq(pthread_cond_t);
-static inline void cond_queue_remove(pthread_cond_t, pthread_t);
-static inline void cond_queue_enq(pthread_cond_t, pthread_t);
-
-/*
- * Double underscore versions are cancellation points. Single underscore
- * versions are not and are provided for libc internal usage (which
- * shouldn't introduce cancellation points).
- */
-__weak_reference(__pthread_cond_wait, pthread_cond_wait);
-__weak_reference(__pthread_cond_timedwait, pthread_cond_timedwait);
-
-__weak_reference(_pthread_cond_init, pthread_cond_init);
-__weak_reference(_pthread_cond_destroy, pthread_cond_destroy);
-__weak_reference(_pthread_cond_signal, pthread_cond_signal);
-__weak_reference(_pthread_cond_broadcast, pthread_cond_broadcast);
-
-
-int
-_pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *cond_attr)
-{
- enum pthread_cond_type type;
- pthread_cond_t pcond;
- int flags;
- int rval = 0;
-
- if (cond == NULL)
- rval = EINVAL;
- else {
- /*
- * Check if a pointer to a condition variable attribute
- * structure was passed by the caller:
- */
- if (cond_attr != NULL && *cond_attr != NULL) {
- /* Default to a fast condition variable: */
- type = (*cond_attr)->c_type;
- flags = (*cond_attr)->c_flags;
- } else {
- /* Default to a fast condition variable: */
- type = COND_TYPE_FAST;
- flags = 0;
- }
-
- /* Process according to condition variable type: */
- switch (type) {
- /* Fast condition variable: */
- case COND_TYPE_FAST:
- /* Nothing to do here. */
- break;
-
- /* Trap invalid condition variable types: */
- default:
- /* Return an invalid argument error: */
- rval = EINVAL;
- break;
- }
-
- /* Check for no errors: */
- if (rval == 0) {
- if ((pcond = (pthread_cond_t)
- malloc(sizeof(struct pthread_cond))) == NULL) {
- rval = ENOMEM;
- } else if (_lock_init(&pcond->c_lock, LCK_ADAPTIVE,
- _thr_lock_wait, _thr_lock_wakeup) != 0) {
- free(pcond);
- rval = ENOMEM;
- } else {
- /*
- * Initialise the condition variable
- * structure:
- */
- TAILQ_INIT(&pcond->c_queue);
- pcond->c_flags |= COND_FLAGS_INITED;
- pcond->c_type = type;
- pcond->c_mutex = NULL;
- pcond->c_seqno = 0;
- *cond = pcond;
- }
- }
- }
- /* Return the completion status: */
- return (rval);
-}
-
-int
-_pthread_cond_destroy(pthread_cond_t *cond)
-{
- struct pthread_cond *cv;
- struct pthread *curthread = _get_curthread();
- int rval = 0;
-
- if (cond == NULL || *cond == NULL)
- rval = EINVAL;
- else {
- /* Lock the condition variable structure: */
- THR_LOCK_ACQUIRE(curthread, &(*cond)->c_lock);
-
- /*
- * NULL the caller's pointer now that the condition
- * variable has been destroyed:
- */
- cv = *cond;
- *cond = NULL;
-
- /* Unlock the condition variable structure: */
- THR_LOCK_RELEASE(curthread, &cv->c_lock);
-
- /*
- * Free the memory allocated for the condition
- * variable structure:
- */
- free(cv);
-
- }
- /* Return the completion status: */
- return (rval);
-}
-
-int
-_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
-{
- struct pthread *curthread = _get_curthread();
- int rval = 0;
- int done = 0;
- int interrupted = 0;
- int unlock_mutex = 1;
- int seqno;
-
- if (cond == NULL)
- return (EINVAL);
-
- /*
- * If the condition variable is statically initialized,
- * perform the dynamic initialization:
- */
- if (*cond == NULL &&
- (rval = pthread_cond_init(cond, NULL)) != 0)
- return (rval);
-
- if (!_kse_isthreaded())
- _kse_setthreaded(1);
-
- /*
- * Enter a loop waiting for a condition signal or broadcast
- * to wake up this thread. A loop is needed in case the waiting
- * thread is interrupted by a signal to execute a signal handler.
- * It is not (currently) possible to remain in the waiting queue
- * while running a handler. Instead, the thread is interrupted
- * and backed out of the waiting queue prior to executing the
- * signal handler.
- */
- do {
- /* Lock the condition variable structure: */
- THR_LOCK_ACQUIRE(curthread, &(*cond)->c_lock);
-
- /*
- * If the condvar was statically allocated, properly
- * initialize the tail queue.
- */
- if (((*cond)->c_flags & COND_FLAGS_INITED) == 0) {
- TAILQ_INIT(&(*cond)->c_queue);
- (*cond)->c_flags |= COND_FLAGS_INITED;
- }
-
- /* Process according to condition variable type: */
- switch ((*cond)->c_type) {
- /* Fast condition variable: */
- case COND_TYPE_FAST:
- if ((mutex == NULL) || (((*cond)->c_mutex != NULL) &&
- ((*cond)->c_mutex != *mutex))) {
- /* Unlock the condition variable structure: */
- THR_LOCK_RELEASE(curthread, &(*cond)->c_lock);
-
- /* Return invalid argument error: */
- rval = EINVAL;
- } else {
- /* Reset the timeout and interrupted flags: */
- curthread->timeout = 0;
- curthread->interrupted = 0;
-
- /*
- * Queue the running thread for the condition
- * variable:
- */
- cond_queue_enq(*cond, curthread);
-
- /* Remember the mutex and sequence number: */
- (*cond)->c_mutex = *mutex;
- seqno = (*cond)->c_seqno;
-
- /* Wait forever: */
- curthread->wakeup_time.tv_sec = -1;
-
- /* Unlock the mutex: */
- if ((unlock_mutex != 0) &&
- ((rval = _mutex_cv_unlock(mutex)) != 0)) {
- /*
- * Cannot unlock the mutex, so remove
- * the running thread from the condition
- * variable queue:
- */
- cond_queue_remove(*cond, curthread);
-
- /* Check for no more waiters: */
- if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
- (*cond)->c_mutex = NULL;
-
- /* Unlock the condition variable structure: */
- THR_LOCK_RELEASE(curthread, &(*cond)->c_lock);
- }
- else {
- /*
- * Don't unlock the mutex the next
- * time through the loop (if the
- * thread has to be requeued after
- * handling a signal).
- */
- unlock_mutex = 0;
-
- /*
- * This thread is active and is in a
- * critical region (holding the cv
- * lock); we should be able to safely
- * set the state.
- */
- THR_SCHED_LOCK(curthread, curthread);
- THR_SET_STATE(curthread, PS_COND_WAIT);
-
- /* Remember the CV: */
- curthread->data.cond = *cond;
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Unlock the CV structure: */
- THR_LOCK_RELEASE(curthread,
- &(*cond)->c_lock);
-
- /* Schedule the next thread: */
- _thr_sched_switch(curthread);
-
- curthread->data.cond = NULL;
-
- /*
- * XXX - This really isn't a good check
- * since there can be more than one
- * thread waiting on the CV. Signals
- * sent to threads waiting on mutexes
- * or CVs should really be deferred
- * until the threads are no longer
- * waiting, but POSIX says that signals
- * should be sent "as soon as possible".
- */
- done = (seqno != (*cond)->c_seqno);
-
- if (THR_IN_SYNCQ(curthread)) {
- /*
- * Lock the condition variable
- * while removing the thread.
- */
- THR_LOCK_ACQUIRE(curthread,
- &(*cond)->c_lock);
-
- cond_queue_remove(*cond,
- curthread);
-
- /* Check for no more waiters: */
- if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
- (*cond)->c_mutex = NULL;
-
- THR_LOCK_RELEASE(curthread,
- &(*cond)->c_lock);
- }
-
- /*
- * Save the interrupted flag; locking
- * the mutex may destroy it.
- */
- interrupted = curthread->interrupted;
-
- /*
- * Note that even though this thread may
- * have been canceled, POSIX requires
- * that the mutex be reaquired prior to
- * cancellation.
- */
- if (done || interrupted) {
- rval = _mutex_cv_lock(mutex);
- unlock_mutex = 1;
- }
- }
- }
- break;
-
- /* Trap invalid condition variable types: */
- default:
- /* Unlock the condition variable structure: */
- THR_LOCK_RELEASE(curthread, &(*cond)->c_lock);
-
- /* Return an invalid argument error: */
- rval = EINVAL;
- break;
- }
-
- if ((interrupted != 0) && (curthread->continuation != NULL))
- curthread->continuation((void *) curthread);
- } while ((done == 0) && (rval == 0));
-
- /* Return the completion status: */
- return (rval);
-}
-
-__strong_reference(_pthread_cond_wait, _thr_cond_wait);
-
-int
-__pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = _pthread_cond_wait(cond, mutex);
- _thr_leave_cancellation_point(curthread);
- return (ret);
-}
-
-int
-_pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
- const struct timespec * abstime)
-{
- struct pthread *curthread = _get_curthread();
- int rval = 0;
- int done = 0;
- int interrupted = 0;
- int unlock_mutex = 1;
- int seqno;
-
- THR_ASSERT(curthread->locklevel == 0,
- "cv_timedwait: locklevel is not zero!");
-
- if (abstime == NULL || abstime->tv_sec < 0 || abstime->tv_nsec < 0 ||
- abstime->tv_nsec >= 1000000000)
- return (EINVAL);
- /*
- * If the condition variable is statically initialized, perform dynamic
- * initialization.
- */
- if (*cond == NULL && (rval = pthread_cond_init(cond, NULL)) != 0)
- return (rval);
-
- if (!_kse_isthreaded())
- _kse_setthreaded(1);
-
- /*
- * Enter a loop waiting for a condition signal or broadcast
- * to wake up this thread. A loop is needed in case the waiting
- * thread is interrupted by a signal to execute a signal handler.
- * It is not (currently) possible to remain in the waiting queue
- * while running a handler. Instead, the thread is interrupted
- * and backed out of the waiting queue prior to executing the
- * signal handler.
- */
- do {
- /* Lock the condition variable structure: */
- THR_LOCK_ACQUIRE(curthread, &(*cond)->c_lock);
-
- /*
- * If the condvar was statically allocated, properly
- * initialize the tail queue.
- */
- if (((*cond)->c_flags & COND_FLAGS_INITED) == 0) {
- TAILQ_INIT(&(*cond)->c_queue);
- (*cond)->c_flags |= COND_FLAGS_INITED;
- }
-
- /* Process according to condition variable type: */
- switch ((*cond)->c_type) {
- /* Fast condition variable: */
- case COND_TYPE_FAST:
- if ((mutex == NULL) || (((*cond)->c_mutex != NULL) &&
- ((*cond)->c_mutex != *mutex))) {
- /* Return invalid argument error: */
- rval = EINVAL;
-
- /* Unlock the condition variable structure: */
- THR_LOCK_RELEASE(curthread, &(*cond)->c_lock);
- } else {
- /* Set the wakeup time: */
- curthread->wakeup_time.tv_sec = abstime->tv_sec;
- curthread->wakeup_time.tv_nsec =
- abstime->tv_nsec;
-
- /* Reset the timeout and interrupted flags: */
- curthread->timeout = 0;
- curthread->interrupted = 0;
-
- /*
- * Queue the running thread for the condition
- * variable:
- */
- cond_queue_enq(*cond, curthread);
-
- /* Remember the mutex and sequence number: */
- (*cond)->c_mutex = *mutex;
- seqno = (*cond)->c_seqno;
-
- /* Unlock the mutex: */
- if ((unlock_mutex != 0) &&
- ((rval = _mutex_cv_unlock(mutex)) != 0)) {
- /*
- * Cannot unlock the mutex; remove the
- * running thread from the condition
- * variable queue:
- */
- cond_queue_remove(*cond, curthread);
-
- /* Check for no more waiters: */
- if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
- (*cond)->c_mutex = NULL;
-
- /* Unlock the condition variable structure: */
- THR_LOCK_RELEASE(curthread, &(*cond)->c_lock);
- } else {
- /*
- * Don't unlock the mutex the next
- * time through the loop (if the
- * thread has to be requeued after
- * handling a signal).
- */
- unlock_mutex = 0;
-
- /*
- * This thread is active and is in a
- * critical region (holding the cv
- * lock); we should be able to safely
- * set the state.
- */
- THR_SCHED_LOCK(curthread, curthread);
- THR_SET_STATE(curthread, PS_COND_WAIT);
-
- /* Remember the CV: */
- curthread->data.cond = *cond;
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Unlock the CV structure: */
- THR_LOCK_RELEASE(curthread,
- &(*cond)->c_lock);
-
- /* Schedule the next thread: */
- _thr_sched_switch(curthread);
-
- curthread->data.cond = NULL;
-
- /*
- * XXX - This really isn't a good check
- * since there can be more than one
- * thread waiting on the CV. Signals
- * sent to threads waiting on mutexes
- * or CVs should really be deferred
- * until the threads are no longer
- * waiting, but POSIX says that signals
- * should be sent "as soon as possible".
- */
- done = (seqno != (*cond)->c_seqno);
-
- if (THR_IN_CONDQ(curthread)) {
- /*
- * Lock the condition variable
- * while removing the thread.
- */
- THR_LOCK_ACQUIRE(curthread,
- &(*cond)->c_lock);
-
- cond_queue_remove(*cond,
- curthread);
-
- /* Check for no more waiters: */
- if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
- (*cond)->c_mutex = NULL;
-
- THR_LOCK_RELEASE(curthread,
- &(*cond)->c_lock);
- }
-
- /*
- * Save the interrupted flag; locking
- * the mutex may destroy it.
- */
- interrupted = curthread->interrupted;
- if (curthread->timeout != 0) {
- /* The wait timedout. */
- rval = ETIMEDOUT;
- (void)_mutex_cv_lock(mutex);
- } else if ((interrupted == 0) ||
- (done != 0))
- rval = _mutex_cv_lock(mutex);
- }
- }
- break;
-
- /* Trap invalid condition variable types: */
- default:
- /* Unlock the condition variable structure: */
- THR_LOCK_RELEASE(curthread, &(*cond)->c_lock);
-
- /* Return an invalid argument error: */
- rval = EINVAL;
- break;
- }
-
- if ((interrupted != 0) && (curthread->continuation != NULL))
- curthread->continuation((void *)curthread);
- } while ((done == 0) && (rval == 0));
-
- /* Return the completion status: */
- return (rval);
-}
-
-int
-__pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
- const struct timespec *abstime)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = _pthread_cond_timedwait(cond, mutex, abstime);
- _thr_leave_cancellation_point(curthread);
- return (ret);
-}
-
-
-int
-_pthread_cond_signal(pthread_cond_t * cond)
-{
- struct pthread *curthread = _get_curthread();
- struct pthread *pthread;
- int rval = 0;
-
- THR_ASSERT(curthread->locklevel == 0,
- "cv_timedwait: locklevel is not zero!");
- if (cond == NULL)
- rval = EINVAL;
- /*
- * If the condition variable is statically initialized, perform dynamic
- * initialization.
- */
- else if (*cond != NULL || (rval = pthread_cond_init(cond, NULL)) == 0) {
- /* Lock the condition variable structure: */
- THR_LOCK_ACQUIRE(curthread, &(*cond)->c_lock);
-
- /* Process according to condition variable type: */
- switch ((*cond)->c_type) {
- /* Fast condition variable: */
- case COND_TYPE_FAST:
- /* Increment the sequence number: */
- (*cond)->c_seqno++;
-
- /*
- * Wakeups have to be done with the CV lock held;
- * otherwise there is a race condition where the
- * thread can timeout, run on another KSE, and enter
- * another blocking state (including blocking on a CV).
- */
- if ((pthread = TAILQ_FIRST(&(*cond)->c_queue))
- != NULL) {
- THR_SCHED_LOCK(curthread, pthread);
- cond_queue_remove(*cond, pthread);
- _thr_setrunnable_unlocked(pthread);
- THR_SCHED_UNLOCK(curthread, pthread);
- }
- /* Check for no more waiters: */
- if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
- (*cond)->c_mutex = NULL;
- break;
-
- /* Trap invalid condition variable types: */
- default:
- /* Return an invalid argument error: */
- rval = EINVAL;
- break;
- }
-
- /* Unlock the condition variable structure: */
- THR_LOCK_RELEASE(curthread, &(*cond)->c_lock);
- }
-
- /* Return the completion status: */
- return (rval);
-}
-
-__strong_reference(_pthread_cond_signal, _thr_cond_signal);
-
-int
-_pthread_cond_broadcast(pthread_cond_t * cond)
-{
- struct pthread *curthread = _get_curthread();
- struct pthread *pthread;
- int rval = 0;
-
- THR_ASSERT(curthread->locklevel == 0,
- "cv_timedwait: locklevel is not zero!");
- if (cond == NULL)
- rval = EINVAL;
- /*
- * If the condition variable is statically initialized, perform dynamic
- * initialization.
- */
- else if (*cond != NULL || (rval = pthread_cond_init(cond, NULL)) == 0) {
- /* Lock the condition variable structure: */
- THR_LOCK_ACQUIRE(curthread, &(*cond)->c_lock);
-
- /* Process according to condition variable type: */
- switch ((*cond)->c_type) {
- /* Fast condition variable: */
- case COND_TYPE_FAST:
- /* Increment the sequence number: */
- (*cond)->c_seqno++;
-
- /*
- * Enter a loop to bring all threads off the
- * condition queue:
- */
- while ((pthread = TAILQ_FIRST(&(*cond)->c_queue))
- != NULL) {
- THR_SCHED_LOCK(curthread, pthread);
- cond_queue_remove(*cond, pthread);
- _thr_setrunnable_unlocked(pthread);
- THR_SCHED_UNLOCK(curthread, pthread);
- }
-
- /* There are no more waiting threads: */
- (*cond)->c_mutex = NULL;
- break;
-
- /* Trap invalid condition variable types: */
- default:
- /* Return an invalid argument error: */
- rval = EINVAL;
- break;
- }
-
- /* Unlock the condition variable structure: */
- THR_LOCK_RELEASE(curthread, &(*cond)->c_lock);
- }
-
- /* Return the completion status: */
- return (rval);
-}
-
-__strong_reference(_pthread_cond_broadcast, _thr_cond_broadcast);
-
-void
-_cond_wait_backout(struct pthread *curthread)
-{
- pthread_cond_t cond;
-
- cond = curthread->data.cond;
- if (cond != NULL) {
- /* Lock the condition variable structure: */
- THR_LOCK_ACQUIRE(curthread, &cond->c_lock);
-
- /* Process according to condition variable type: */
- switch (cond->c_type) {
- /* Fast condition variable: */
- case COND_TYPE_FAST:
- cond_queue_remove(cond, curthread);
-
- /* Check for no more waiters: */
- if (TAILQ_FIRST(&cond->c_queue) == NULL)
- cond->c_mutex = NULL;
- break;
-
- default:
- break;
- }
-
- /* Unlock the condition variable structure: */
- THR_LOCK_RELEASE(curthread, &cond->c_lock);
- }
-}
-
-/*
- * Dequeue a waiting thread from the head of a condition queue in
- * descending priority order.
- */
-static inline struct pthread *
-cond_queue_deq(pthread_cond_t cond)
-{
- struct pthread *pthread;
-
- while ((pthread = TAILQ_FIRST(&cond->c_queue)) != NULL) {
- TAILQ_REMOVE(&cond->c_queue, pthread, sqe);
- THR_CONDQ_SET(pthread);
- if ((pthread->timeout == 0) && (pthread->interrupted == 0))
- /*
- * Only exit the loop when we find a thread
- * that hasn't timed out or been canceled;
- * those threads are already running and don't
- * need their run state changed.
- */
- break;
- }
-
- return (pthread);
-}
-
-/*
- * Remove a waiting thread from a condition queue in descending priority
- * order.
- */
-static inline void
-cond_queue_remove(pthread_cond_t cond, struct pthread *pthread)
-{
- /*
- * Because pthread_cond_timedwait() can timeout as well
- * as be signaled by another thread, it is necessary to
- * guard against removing the thread from the queue if
- * it isn't in the queue.
- */
- if (THR_IN_CONDQ(pthread)) {
- TAILQ_REMOVE(&cond->c_queue, pthread, sqe);
- THR_CONDQ_CLEAR(pthread);
- }
-}
-
-/*
- * Enqueue a waiting thread to a condition queue in descending priority
- * order.
- */
-static inline void
-cond_queue_enq(pthread_cond_t cond, struct pthread *pthread)
-{
- struct pthread *tid = TAILQ_LAST(&cond->c_queue, cond_head);
-
- THR_ASSERT(!THR_IN_SYNCQ(pthread),
- "cond_queue_enq: thread already queued!");
-
- /*
- * For the common case of all threads having equal priority,
- * we perform a quick check against the priority of the thread
- * at the tail of the queue.
- */
- if ((tid == NULL) || (pthread->active_priority <= tid->active_priority))
- TAILQ_INSERT_TAIL(&cond->c_queue, pthread, sqe);
- else {
- tid = TAILQ_FIRST(&cond->c_queue);
- while (pthread->active_priority <= tid->active_priority)
- tid = TAILQ_NEXT(tid, sqe);
- TAILQ_INSERT_BEFORE(tid, pthread, sqe);
- }
- THR_CONDQ_SET(pthread);
- pthread->data.cond = cond;
-}
diff --git a/lib/libkse/thread/thr_condattr_destroy.c b/lib/libkse/thread/thr_condattr_destroy.c
deleted file mode 100644
index e0ade00883ee..000000000000
--- a/lib/libkse/thread/thr_condattr_destroy.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <stdlib.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_condattr_destroy, pthread_condattr_destroy);
-
-int
-_pthread_condattr_destroy(pthread_condattr_t *attr)
-{
- int ret;
- if (attr == NULL || *attr == NULL) {
- ret = EINVAL;
- } else {
- free(*attr);
- *attr = NULL;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_condattr_init.c b/lib/libkse/thread/thr_condattr_init.c
deleted file mode 100644
index 7cf4c9eac92b..000000000000
--- a/lib/libkse/thread/thr_condattr_init.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_condattr_init, pthread_condattr_init);
-
-int
-_pthread_condattr_init(pthread_condattr_t *attr)
-{
- int ret;
- pthread_condattr_t pattr;
-
- if ((pattr = (pthread_condattr_t)
- malloc(sizeof(struct pthread_cond_attr))) == NULL) {
- ret = ENOMEM;
- } else {
- memcpy(pattr, &_pthread_condattr_default,
- sizeof(struct pthread_cond_attr));
- *attr = pattr;
- ret = 0;
- }
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_creat.c b/lib/libkse/thread/thr_creat.c
deleted file mode 100644
index bba8ec361501..000000000000
--- a/lib/libkse/thread/thr_creat.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include <fcntl.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(___creat, creat);
-
-int
-___creat(const char *path, mode_t mode)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __creat(path, mode);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_create.c b/lib/libkse/thread/thr_create.c
deleted file mode 100644
index 6b57f0eb4fe3..000000000000
--- a/lib/libkse/thread/thr_create.c
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * Copyright (c) 2003 Daniel M. Eischen <deischen@gdeb.com>
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stddef.h>
-#include <sys/time.h>
-#include <machine/reg.h>
-#include <pthread.h>
-#include "thr_private.h"
-#include "libc_private.h"
-
-#define OFF(f) offsetof(struct pthread, f)
-int _thread_next_offset = OFF(tle.tqe_next);
-int _thread_uniqueid_offset = OFF(uniqueid);
-int _thread_state_offset = OFF(state);
-int _thread_name_offset = OFF(name);
-int _thread_ctx_offset = OFF(tmbx.tm_context);
-#undef OFF
-
-int _thread_PS_RUNNING_value = PS_RUNNING;
-int _thread_PS_DEAD_value = PS_DEAD;
-
-static void free_thread(struct pthread *curthread, struct pthread *thread);
-static int create_stack(struct pthread_attr *pattr);
-static void thread_start(struct pthread *curthread,
- void *(*start_routine) (void *), void *arg);
-
-__weak_reference(_pthread_create, pthread_create);
-
-/*
- * Some notes on new thread creation and first time initializion
- * to enable multi-threading.
- *
- * There are basically two things that need to be done.
- *
- * 1) The internal library variables must be initialized.
- * 2) Upcalls need to be enabled to allow multiple threads
- * to be run.
- *
- * The first may be done as a result of other pthread functions
- * being called. When _thr_initial is null, _libpthread_init is
- * called to initialize the internal variables; this also creates
- * or sets the initial thread. It'd be nice to automatically
- * have _libpthread_init called on program execution so we don't
- * have to have checks throughout the library.
- *
- * The second part is only triggered by the creation of the first
- * thread (other than the initial/main thread). If the thread
- * being created is a scope system thread, then a new KSE/KSEG
- * pair needs to be allocated. Also, if upcalls haven't been
- * enabled on the initial thread's KSE, they must be now that
- * there is more than one thread; this could be delayed until
- * the initial KSEG has more than one thread.
- */
-int
-_pthread_create(pthread_t * thread, const pthread_attr_t * attr,
- void *(*start_routine) (void *), void *arg)
-{
- struct kse *curkse;
- struct pthread *curthread, *new_thread;
- struct kse *kse = NULL;
- struct kse_group *kseg = NULL;
- void *p;
- kse_critical_t crit;
- int i;
- int ret = 0;
-
- if (_thr_initial == NULL)
- _libpthread_init(NULL);
-
- /*
- * Turn on threaded mode, if failed, it is unnecessary to
- * do further work.
- */
- if (_kse_isthreaded() == 0 && _kse_setthreaded(1)) {
- return (EAGAIN);
- }
- curthread = _get_curthread();
-
- /*
- * Allocate memory for the thread structure.
- * Some functions use malloc, so don't put it
- * in a critical region.
- */
- if ((new_thread = _thr_alloc(curthread)) == NULL) {
- /* Insufficient memory to create a thread: */
- ret = EAGAIN;
- } else {
- /* Initialize the thread structure: */
- p = new_thread->alloc_addr;
- memset(new_thread, 0, sizeof(struct pthread));
- new_thread->alloc_addr = p;
-
- /* Check if default thread attributes are required: */
- if (attr == NULL || *attr == NULL)
- /* Use the default thread attributes: */
- new_thread->attr = _pthread_attr_default;
- else
- new_thread->attr = *(*attr);
-
- if (create_stack(&new_thread->attr) != 0) {
- /* Insufficient memory to create a stack: */
- ret = EAGAIN;
- _thr_free(curthread, new_thread);
- }
- else if (((new_thread->attr.flags & PTHREAD_SCOPE_SYSTEM) != 0) &&
- (((kse = _kse_alloc(curthread)) == NULL)
- || ((kseg = _kseg_alloc(curthread)) == NULL))) {
- /* Insufficient memory to create a new KSE/KSEG: */
- ret = EAGAIN;
-#ifndef KMF_DONE
-#define KMF_DONE 0x04
-#endif
- if (kse != NULL) {
- kse->k_mbx.km_flags |= KMF_DONE;
- _kse_free(curthread, kse);
- }
- if ((new_thread->attr.flags & THR_STACK_USER) == 0) {
- crit = _kse_critical_enter();
- curkse = _get_curkse();
- KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
- /* Stack routines don't use malloc/free. */
- _thr_stack_free(&new_thread->attr);
- KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
- _kse_critical_leave(crit);
- }
- _thr_free(curthread, new_thread);
- }
- else {
- if (kseg != NULL) {
- /* Add the KSE to the KSEG's list of KSEs. */
- TAILQ_INSERT_HEAD(&kseg->kg_kseq, kse, k_kgqe);
- kseg->kg_ksecount = 1;
- kse->k_kseg = kseg;
- kse->k_schedq = &kseg->kg_schedq;
- }
- /*
- * Write a magic value to the thread structure
- * to help identify valid ones:
- */
- new_thread->magic = THR_MAGIC;
-
- new_thread->slice_usec = -1;
- new_thread->start_routine = start_routine;
- new_thread->arg = arg;
- new_thread->cancelflags = PTHREAD_CANCEL_ENABLE |
- PTHREAD_CANCEL_DEFERRED;
-
- /* Initialize the thread for signals: */
- new_thread->sigmask = curthread->sigmask;
-
- /* No thread is wanting to join to this one: */
- new_thread->joiner = NULL;
-
- /* Initialize the signal frame: */
- new_thread->curframe = NULL;
-
- /*
- * Initialize the machine context.
- * Enter a critical region to get consistent context.
- */
- crit = _kse_critical_enter();
- THR_GETCONTEXT(&new_thread->tmbx.tm_context);
- _kse_critical_leave(crit);
- new_thread->tmbx.tm_udata = new_thread;
- new_thread->tmbx.tm_context.uc_sigmask =
- new_thread->sigmask;
- new_thread->tmbx.tm_context.uc_stack.ss_size =
- new_thread->attr.stacksize_attr;
- new_thread->tmbx.tm_context.uc_stack.ss_sp =
- new_thread->attr.stackaddr_attr;
- makecontext(&new_thread->tmbx.tm_context,
- (void (*)(void))thread_start, 4, new_thread,
- start_routine, arg);
- /*
- * Check if this thread is to inherit the scheduling
- * attributes from its parent:
- */
- if ((new_thread->attr.flags & PTHREAD_INHERIT_SCHED) != 0) {
- /*
- * Copy the scheduling attributes.
- * Lock the scheduling lock to get consistent
- * scheduling parameters.
- */
- THR_SCHED_LOCK(curthread, curthread);
- new_thread->base_priority =
- curthread->base_priority &
- ~THR_SIGNAL_PRIORITY;
- new_thread->attr.prio =
- curthread->base_priority &
- ~THR_SIGNAL_PRIORITY;
- new_thread->attr.sched_policy =
- curthread->attr.sched_policy;
- THR_SCHED_UNLOCK(curthread, curthread);
- } else {
- /*
- * Use just the thread priority, leaving the
- * other scheduling attributes as their
- * default values:
- */
- new_thread->base_priority =
- new_thread->attr.prio;
- }
- new_thread->active_priority = new_thread->base_priority;
- new_thread->inherited_priority = 0;
-
- /* Initialize the mutex queue: */
- TAILQ_INIT(&new_thread->mutexq);
-
- /*
- * Initialize thread locking.
- * Lock initializing needs malloc, so don't
- * enter critical region before doing this!
- */
- if (_lock_init(&new_thread->lock, LCK_ADAPTIVE,
- _thr_lock_wait, _thr_lock_wakeup) != 0)
- PANIC("Cannot initialize thread lock");
- for (i = 0; i < MAX_THR_LOCKLEVEL; i++) {
- _lockuser_init(&new_thread->lockusers[i],
- (void *)new_thread);
- _LCK_SET_PRIVATE2(&new_thread->lockusers[i],
- (void *)new_thread);
- }
-
- /* Initialise hooks in the thread structure: */
- new_thread->specific = NULL;
- new_thread->cleanup = NULL;
- new_thread->flags = 0;
- new_thread->continuation = NULL;
-
- if (new_thread->attr.suspend == THR_CREATE_SUSPENDED) {
- new_thread->state = PS_SUSPENDED;
- new_thread->flags = THR_FLAGS_SUSPENDED;
- }
- else
- new_thread->state = PS_RUNNING;
-
- /*
- * System scope threads have their own kse and
- * kseg. Process scope threads are all hung
- * off the main process kseg.
- */
- if ((new_thread->attr.flags & PTHREAD_SCOPE_SYSTEM) == 0) {
- new_thread->kseg = _kse_initial->k_kseg;
- new_thread->kse = _kse_initial;
- }
- else {
- kse->k_curthread = NULL;
-#ifdef NOT_YET
- kse->k_kseg->kg_flags |= KGF_SINGLE_THREAD;
-#endif
- new_thread->kse = kse;
- new_thread->kseg = kse->k_kseg;
- kse->k_mbx.km_udata = kse;
- kse->k_mbx.km_curthread = NULL;
- }
-
- /*
- * Schedule the new thread starting a new KSEG/KSE
- * pair if necessary.
- */
- ret = _thr_schedule_add(curthread, new_thread);
- if (ret != 0)
- free_thread(curthread, new_thread);
-
- /* Return a pointer to the thread structure: */
- (*thread) = new_thread;
- }
- }
-
- /* Return the status: */
- return (ret);
-}
-
-static void
-free_thread(struct pthread *curthread, struct pthread *thread)
-{
- if ((thread->attr.flags & PTHREAD_SCOPE_SYSTEM) != 0) {
- /* Free the KSE and KSEG. */
- _kseg_free(thread->kseg);
- _kse_free(curthread, thread->kse);
- }
- _thr_free(curthread, thread);
-}
-
-static int
-create_stack(struct pthread_attr *pattr)
-{
- int ret;
-
- /* Check if a stack was specified in the thread attributes: */
- if ((pattr->stackaddr_attr) != NULL) {
- pattr->guardsize_attr = 0;
- pattr->flags |= THR_STACK_USER;
- ret = 0;
- }
- else
- ret = _thr_stack_alloc(pattr);
- return (ret);
-}
-
-
-static void
-thread_start(struct pthread *curthread, void *(*start_routine) (void *),
- void *arg)
-{
- /* Run the current thread's start routine with argument: */
- pthread_exit(start_routine(arg));
-
- /* This point should never be reached. */
- PANIC("Thread has resumed after exit");
-}
diff --git a/lib/libkse/thread/thr_detach.c b/lib/libkse/thread/thr_detach.c
deleted file mode 100644
index 0b63dac190b0..000000000000
--- a/lib/libkse/thread/thr_detach.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <sys/types.h>
-#include <machine/atomic.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_detach, pthread_detach);
-
-int
-_pthread_detach(pthread_t pthread)
-{
- struct pthread *curthread = _get_curthread();
- struct pthread *joiner;
- int rval = 0;
-
- /* Check for invalid calling parameters: */
- if (pthread == NULL || pthread->magic != THR_MAGIC)
- /* Return an invalid argument error: */
- rval = EINVAL;
-
- else if ((rval = _thr_ref_add(curthread, pthread,
- /*include dead*/1)) != 0) {
- /* Return an error: */
- }
-
- /* Check if the thread is already detached: */
- else if ((pthread->attr.flags & PTHREAD_DETACHED) != 0) {
- /* Return an error: */
- _thr_ref_delete(curthread, pthread);
- rval = EINVAL;
- } else {
- /* Lock the detached thread: */
- THR_SCHED_LOCK(curthread, pthread);
-
- /* Flag the thread as detached: */
- pthread->attr.flags |= PTHREAD_DETACHED;
-
- /* Retrieve any joining thread and remove it: */
- joiner = pthread->joiner;
- if ((joiner != NULL) && (joiner->kseg == pthread->kseg)) {
- /*
- * We already own the scheduler lock for the joiner.
- * Take advantage of that and make the joiner runnable.
- */
- if (joiner->join_status.thread == pthread) {
- /*
- * Set the return value for the woken thread:
- */
- joiner->join_status.error = ESRCH;
- joiner->join_status.ret = NULL;
- joiner->join_status.thread = NULL;
-
- _thr_setrunnable_unlocked(joiner);
- }
- joiner = NULL;
- }
- THR_SCHED_UNLOCK(curthread, pthread);
-
- /* See if there is a thread waiting in pthread_join(): */
- if ((joiner != NULL) &&
- (_thr_ref_add(curthread, joiner, 0) == 0)) {
- /* Lock the joiner before fiddling with it. */
- THR_SCHED_LOCK(curthread, joiner);
- if (joiner->join_status.thread == pthread) {
- /*
- * Set the return value for the woken thread:
- */
- joiner->join_status.error = ESRCH;
- joiner->join_status.ret = NULL;
- joiner->join_status.thread = NULL;
-
- _thr_setrunnable_unlocked(joiner);
- }
- THR_SCHED_UNLOCK(curthread, joiner);
- _thr_ref_delete(curthread, joiner);
- }
- _thr_ref_delete(curthread, pthread);
- }
-
- /* Return the completion status: */
- return (rval);
-}
diff --git a/lib/libkse/thread/thr_equal.c b/lib/libkse/thread/thr_equal.c
deleted file mode 100644
index f8882f5f073b..000000000000
--- a/lib/libkse/thread/thr_equal.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_equal, pthread_equal);
-
-int
-_pthread_equal(pthread_t t1, pthread_t t2)
-{
- /* Compare the two thread pointers: */
- return (t1 == t2);
-}
diff --git a/lib/libkse/thread/thr_exit.c b/lib/libkse/thread/thr_exit.c
deleted file mode 100644
index 6dbef072a50c..000000000000
--- a/lib/libkse/thread/thr_exit.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-void _pthread_exit(void *status);
-
-__weak_reference(_pthread_exit, pthread_exit);
-
-void
-_thr_exit(char *fname, int lineno, char *msg)
-{
-
- /* Write an error message to the standard error file descriptor: */
- _thread_printf(2,
- "Fatal error '%s' at line %d in file %s (errno = %d)\n",
- msg, lineno, fname, errno);
-
- abort();
-}
-
-/*
- * Only called when a thread is cancelled. It may be more useful
- * to call it from pthread_exit() if other ways of asynchronous or
- * abnormal thread termination can be found.
- */
-void
-_thr_exit_cleanup(void)
-{
- struct pthread *curthread = _get_curthread();
-
- /*
- * POSIX states that cancellation/termination of a thread should
- * not release any visible resources (such as mutexes) and that
- * it is the applications responsibility. Resources that are
- * internal to the threads library, including file and fd locks,
- * are not visible to the application and need to be released.
- */
- /* Unlock all private mutexes: */
- _mutex_unlock_private(curthread);
-
- /*
- * This still isn't quite correct because we don't account
- * for held spinlocks (see libc/stdlib/malloc.c).
- */
-}
-
-void
-_pthread_exit(void *status)
-{
- struct pthread *curthread = _get_curthread();
-
- /* Check if this thread is already in the process of exiting: */
- if ((curthread->flags & THR_FLAGS_EXITING) != 0) {
- char msg[128];
- snprintf(msg, sizeof(msg), "Thread %p has called "
- "pthread_exit() from a destructor. POSIX 1003.1 "
- "1996 s16.2.5.2 does not allow this!", curthread);
- PANIC(msg);
- }
-
- /*
- * Flag this thread as exiting. Threads should now be prevented
- * from joining to this thread.
- */
- THR_SCHED_LOCK(curthread, curthread);
- curthread->flags |= THR_FLAGS_EXITING;
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Save the return value: */
- curthread->ret = status;
- while (curthread->cleanup != NULL) {
- pthread_cleanup_pop(1);
- }
- if (curthread->attr.cleanup_attr != NULL) {
- curthread->attr.cleanup_attr(curthread->attr.arg_attr);
- }
- /* Check if there is thread specific data: */
- if (curthread->specific != NULL) {
- /* Run the thread-specific data destructors: */
- _thread_cleanupspecific();
- }
-
- /* This thread will never be re-scheduled. */
- THR_LOCK_SWITCH(curthread);
- THR_SET_STATE(curthread, PS_DEAD);
- _thr_sched_switch_unlocked(curthread);
- /* Never reach! */
-
- /* This point should not be reached. */
- PANIC("Dead thread has resumed");
-}
diff --git a/lib/libkse/thread/thr_fcntl.c b/lib/libkse/thread/thr_fcntl.c
deleted file mode 100644
index 0b4a9904776b..000000000000
--- a/lib/libkse/thread/thr_fcntl.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <stdarg.h>
-#include "namespace.h"
-#include <fcntl.h>
-#include "un-namespace.h"
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__fcntl, fcntl);
-
-int
-__fcntl(int fd, int cmd,...)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
- va_list ap;
-
- _thr_enter_cancellation_point(curthread);
-
- va_start(ap, cmd);
- switch (cmd) {
- case F_DUPFD:
- case F_SETFD:
- case F_SETFL:
- ret = __sys_fcntl(fd, cmd, va_arg(ap, int));
- break;
- case F_GETFD:
- case F_GETFL:
- ret = __sys_fcntl(fd, cmd);
- break;
- default:
- ret = __sys_fcntl(fd, cmd, va_arg(ap, void *));
- }
- va_end(ap);
-
- _thr_leave_cancellation_point(curthread);
-
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_find_thread.c b/lib/libkse/thread/thr_find_thread.c
deleted file mode 100644
index ef469d94d2ad..000000000000
--- a/lib/libkse/thread/thr_find_thread.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org>
- * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-/*
- * Find a thread in the linked list of active threads and add a reference
- * to it. Threads with positive reference counts will not be deallocated
- * until all references are released.
- */
-int
-_thr_ref_add(struct pthread *curthread, struct pthread *thread,
- int include_dead)
-{
- kse_critical_t crit;
- struct pthread *pthread;
- struct kse *curkse;
-
- if (thread == NULL)
- /* Invalid thread: */
- return (EINVAL);
-
- crit = _kse_critical_enter();
- curkse = _get_curkse();
- KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
- TAILQ_FOREACH(pthread, &_thread_list, tle) {
- if (pthread == thread) {
- if ((include_dead == 0) &&
- ((pthread->state == PS_DEAD) ||
- ((pthread->state == PS_DEADLOCK) ||
- ((pthread->flags & THR_FLAGS_EXITING) != 0))))
- pthread = NULL;
- else {
- thread->refcount++;
- if (curthread != NULL)
- curthread->critical_count++;
- }
- break;
- }
- }
- KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
- _kse_critical_leave(crit);
-
- /* Return zero if the thread exists: */
- return ((pthread != NULL) ? 0 : ESRCH);
-}
-
-void
-_thr_ref_delete(struct pthread *curthread, struct pthread *thread)
-{
- kse_critical_t crit;
- struct kse *curkse;
-
- if (thread != NULL) {
- crit = _kse_critical_enter();
- curkse = _get_curkse();
- KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
- thread->refcount--;
- if (curthread != NULL)
- curthread->critical_count--;
- if ((thread->refcount == 0) &&
- (thread->flags & THR_FLAGS_GC_SAFE) != 0)
- THR_GCLIST_ADD(thread);
- KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
- _kse_critical_leave(crit);
- }
-}
diff --git a/lib/libkse/thread/thr_fork.c b/lib/libkse/thread/thr_fork.c
deleted file mode 100644
index a2796214e748..000000000000
--- a/lib/libkse/thread/thr_fork.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_fork, fork);
-
-pid_t
-_fork(void)
-{
- struct pthread *curthread;
- pid_t ret;
-
- curthread = _get_curthread();
-
- /* Fork a new process: */
- if ((ret = __sys_fork()) == 0)
- /* Child process */
- _kse_single_thread(curthread);
-
- /* Return the process ID: */
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_fsync.c b/lib/libkse/thread/thr_fsync.c
deleted file mode 100644
index d5d3398371b9..000000000000
--- a/lib/libkse/thread/thr_fsync.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <unistd.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__fsync, fsync);
-
-int
-__fsync(int fd)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __sys_fsync(fd);
- _thr_leave_cancellation_point(curthread);
-
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_getprio.c b/lib/libkse/thread/thr_getprio.c
deleted file mode 100644
index fa95ef9540ae..000000000000
--- a/lib/libkse/thread/thr_getprio.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_getprio, pthread_getprio);
-
-int
-_pthread_getprio(pthread_t pthread)
-{
- int policy, ret;
- struct sched_param param;
-
- if ((ret = pthread_getschedparam(pthread, &policy, &param)) == 0)
- ret = param.sched_priority;
- else {
- /* Invalid thread: */
- errno = ret;
- ret = -1;
- }
-
- /* Return the thread priority or an error status: */
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_getschedparam.c b/lib/libkse/thread/thr_getschedparam.c
deleted file mode 100644
index d00e498c3057..000000000000
--- a/lib/libkse/thread/thr_getschedparam.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_getschedparam, pthread_getschedparam);
-
-int
-_pthread_getschedparam(pthread_t pthread, int *policy,
- struct sched_param *param)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- if ((param == NULL) || (policy == NULL))
- /* Return an invalid argument error: */
- ret = EINVAL;
- else if (pthread == curthread) {
- /*
- * Avoid searching the thread list when it is the current
- * thread.
- */
- THR_SCHED_LOCK(curthread, curthread);
- param->sched_priority =
- THR_BASE_PRIORITY(pthread->base_priority);
- *policy = pthread->attr.sched_policy;
- THR_SCHED_UNLOCK(curthread, curthread);
- ret = 0;
- }
- /* Find the thread in the list of active threads. */
- else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0))
- == 0) {
- THR_SCHED_LOCK(curthread, pthread);
- param->sched_priority =
- THR_BASE_PRIORITY(pthread->base_priority);
- *policy = pthread->attr.sched_policy;
- THR_SCHED_UNLOCK(curthread, pthread);
- _thr_ref_delete(curthread, pthread);
- }
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_info.c b/lib/libkse/thread/thr_info.c
deleted file mode 100644
index 3218b5b88eb6..000000000000
--- a/lib/libkse/thread/thr_info.c
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <errno.h>
-#include "thr_private.h"
-
-#ifndef NELEMENTS
-#define NELEMENTS(arr) (sizeof(arr) / sizeof(arr[0]))
-#endif
-
-static void dump_thread(int fd, pthread_t pthread, int long_version);
-
-__weak_reference(_pthread_set_name_np, pthread_set_name_np);
-
-struct s_thread_info {
- enum pthread_state state;
- char *name;
-};
-
-/* Static variables: */
-static const struct s_thread_info thread_info[] = {
- {PS_RUNNING , "Running"},
- {PS_LOCKWAIT , "Waiting on an internal lock"},
- {PS_MUTEX_WAIT , "Waiting on a mutex"},
- {PS_COND_WAIT , "Waiting on a condition variable"},
- {PS_SLEEP_WAIT , "Sleeping"},
- {PS_SIGSUSPEND , "Suspended, waiting for a signal"},
- {PS_SIGWAIT , "Waiting for a signal"},
- {PS_JOIN , "Waiting to join"},
- {PS_SUSPENDED , "Suspended"},
- {PS_DEAD , "Dead"},
- {PS_DEADLOCK , "Deadlocked"},
- {PS_STATE_MAX , "Not a real state!"}
-};
-
-void
-_thread_dump_info(void)
-{
- char s[512], tmpfile[128];
- pthread_t pthread;
- int fd, i;
-
- for (i = 0; i < 100000; i++) {
- snprintf(tmpfile, sizeof(tmpfile), "/tmp/uthread.dump.%u.%i",
- getpid(), i);
- /* Open the dump file for append and create it if necessary: */
- if ((fd = __sys_open(tmpfile, O_RDWR | O_CREAT | O_EXCL,
- 0666)) < 0) {
- /* Can't open the dump file. */
- if (errno == EEXIST)
- continue;
- /*
- * We only need to continue in case of
- * EEXIT error. Most other error
- * codes means that we will fail all
- * the times.
- */
- return;
- } else {
- break;
- }
- }
- if (i==100000) {
- /* all 100000 possibilities are in use :( */
- return;
- } else {
- /* Dump the active threads. */
- strcpy(s, "\n\n========\nACTIVE THREADS\n\n");
- __sys_write(fd, s, strlen(s));
-
- /* Enter a loop to report each thread in the global list: */
- TAILQ_FOREACH(pthread, &_thread_list, tle) {
- if (pthread->state != PS_DEAD)
- dump_thread(fd, pthread, /*long_verson*/ 1);
- }
-
- /*
- * Dump the ready threads.
- * XXX - We can't easily do this because the run queues
- * are per-KSEG.
- */
- strcpy(s, "\n\n========\nREADY THREADS - unimplemented\n\n");
- __sys_write(fd, s, strlen(s));
-
-
- /*
- * Dump the waiting threads.
- * XXX - We can't easily do this because the wait queues
- * are per-KSEG.
- */
- strcpy(s, "\n\n========\nWAITING THREADS - unimplemented\n\n");
- __sys_write(fd, s, strlen(s));
-
- /* Close the dump file. */
- __sys_close(fd);
- }
-}
-
-static void
-dump_thread(int fd, pthread_t pthread, int long_version)
-{
- struct pthread *curthread = _get_curthread();
- char s[512];
- int i;
-
- /* Find the state: */
- for (i = 0; i < NELEMENTS(thread_info) - 1; i++)
- if (thread_info[i].state == pthread->state)
- break;
-
- /* Output a record for the thread: */
- snprintf(s, sizeof(s),
- "--------------------\n"
- "Thread %p (%s) prio %3d, blocked %s, state %s [%s:%d]\n",
- pthread, (pthread->name == NULL) ? "" : pthread->name,
- pthread->active_priority, (pthread->blocked != 0) ? "yes" : "no",
- thread_info[i].name, pthread->fname, pthread->lineno);
- __sys_write(fd, s, strlen(s));
-
- if (long_version != 0) {
- /* Check if this is the running thread: */
- if (pthread == curthread) {
- /* Output a record for the running thread: */
- strcpy(s, "This is the running thread\n");
- __sys_write(fd, s, strlen(s));
- }
- /* Check if this is the initial thread: */
- if (pthread == _thr_initial) {
- /* Output a record for the initial thread: */
- strcpy(s, "This is the initial thread\n");
- __sys_write(fd, s, strlen(s));
- }
- /* Process according to thread state: */
- switch (pthread->state) {
- case PS_SIGWAIT:
- snprintf(s, sizeof(s), "sigmask (hi)");
- __sys_write(fd, s, strlen(s));
- for (i = _SIG_WORDS - 1; i >= 0; i--) {
- snprintf(s, sizeof(s), "%08x\n",
- pthread->sigmask.__bits[i]);
- __sys_write(fd, s, strlen(s));
- }
- snprintf(s, sizeof(s), "(lo)\n");
- __sys_write(fd, s, strlen(s));
- break;
- /*
- * Trap other states that are not explicitly
- * coded to dump information:
- */
- default:
- /* Nothing to do here. */
- break;
- }
- }
-}
-
-/* Set the thread name for debug: */
-void
-_pthread_set_name_np(pthread_t thread, char *name)
-{
- /* Check if the caller has specified a valid thread: */
- if (thread != NULL && thread->magic == THR_MAGIC) {
- if (thread->name != NULL) {
- /* Free space for previous name. */
- free(thread->name);
- }
- thread->name = strdup(name);
- }
-}
diff --git a/lib/libkse/thread/thr_init.c b/lib/libkse/thread/thr_init.c
deleted file mode 100644
index ceee0411aca9..000000000000
--- a/lib/libkse/thread/thr_init.c
+++ /dev/null
@@ -1,530 +0,0 @@
-/*
- * Copyright (c) 2003 Daniel M. Eischen <deischen@freebsd.org>
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-
-/* Allocate space for global thread variables here: */
-#define GLOBAL_PTHREAD_PRIVATE
-
-#include "namespace.h"
-#include <sys/param.h>
-#include <sys/types.h>
-#include <machine/reg.h>
-
-#include <sys/ioctl.h>
-#include <sys/mount.h>
-#include <sys/uio.h>
-#include <sys/socket.h>
-#include <sys/event.h>
-#include <sys/stat.h>
-#include <sys/sysctl.h>
-#include <sys/time.h>
-#include <sys/ttycom.h>
-#include <sys/wait.h>
-#include <sys/mman.h>
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <pthread.h>
-#include <pthread_np.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "un-namespace.h"
-
-#include "libc_private.h"
-#include "thr_private.h"
-#include "ksd.h"
-
-int __pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
-int __pthread_mutex_lock(pthread_mutex_t *);
-int __pthread_mutex_trylock(pthread_mutex_t *);
-void _thread_init_hack(void);
-
-static void init_private(void);
-static void init_main_thread(struct pthread *thread);
-
-/*
- * All weak references used within libc should be in this table.
- * This is so that static libraries will work.
- */
-static void *references[] = {
- &_accept,
- &_bind,
- &_close,
- &_connect,
- &_dup,
- &_dup2,
- &_execve,
- &_fcntl,
- &_flock,
- &_flockfile,
- &_fstat,
- &_fstatfs,
- &_fsync,
- &_funlockfile,
- &_getdirentries,
- &_getlogin,
- &_getpeername,
- &_getsockname,
- &_getsockopt,
- &_ioctl,
- &_kevent,
- &_listen,
- &_nanosleep,
- &_open,
- &_pthread_getspecific,
- &_pthread_key_create,
- &_pthread_key_delete,
- &_pthread_mutex_destroy,
- &_pthread_mutex_init,
- &_pthread_mutex_lock,
- &_pthread_mutex_trylock,
- &_pthread_mutex_unlock,
- &_pthread_mutexattr_init,
- &_pthread_mutexattr_destroy,
- &_pthread_mutexattr_settype,
- &_pthread_once,
- &_pthread_setspecific,
- &_read,
- &_readv,
- &_recvfrom,
- &_recvmsg,
- &_select,
- &_sendmsg,
- &_sendto,
- &_setsockopt,
- &_sigaction,
- &_sigprocmask,
- &_sigsuspend,
- &_socket,
- &_socketpair,
- &_thread_init_hack,
- &_wait4,
- &_write,
- &_writev
-};
-
-/*
- * These are needed when linking statically. All references within
- * libgcc (and in the future libc) to these routines are weak, but
- * if they are not (strongly) referenced by the application or other
- * libraries, then the actual functions will not be loaded.
- */
-static void *libgcc_references[] = {
- &_pthread_once,
- &_pthread_key_create,
- &_pthread_key_delete,
- &_pthread_getspecific,
- &_pthread_setspecific,
- &_pthread_mutex_init,
- &_pthread_mutex_destroy,
- &_pthread_mutex_lock,
- &_pthread_mutex_trylock,
- &_pthread_mutex_unlock
-};
-
-#define DUAL_ENTRY(entry) \
- (pthread_func_t)entry, (pthread_func_t)entry
-
-static pthread_func_t jmp_table[][2] = {
- {DUAL_ENTRY(_pthread_cond_broadcast)}, /* PJT_COND_BROADCAST */
- {DUAL_ENTRY(_pthread_cond_destroy)}, /* PJT_COND_DESTROY */
- {DUAL_ENTRY(_pthread_cond_init)}, /* PJT_COND_INIT */
- {DUAL_ENTRY(_pthread_cond_signal)}, /* PJT_COND_SIGNAL */
- {(pthread_func_t)__pthread_cond_wait,
- (pthread_func_t)_pthread_cond_wait}, /* PJT_COND_WAIT */
- {DUAL_ENTRY(_pthread_getspecific)}, /* PJT_GETSPECIFIC */
- {DUAL_ENTRY(_pthread_key_create)}, /* PJT_KEY_CREATE */
- {DUAL_ENTRY(_pthread_key_delete)}, /* PJT_KEY_DELETE*/
- {DUAL_ENTRY(_pthread_main_np)}, /* PJT_MAIN_NP */
- {DUAL_ENTRY(_pthread_mutex_destroy)}, /* PJT_MUTEX_DESTROY */
- {DUAL_ENTRY(_pthread_mutex_init)}, /* PJT_MUTEX_INIT */
- {(pthread_func_t)__pthread_mutex_lock,
- (pthread_func_t)_pthread_mutex_lock}, /* PJT_MUTEX_LOCK */
- {(pthread_func_t)__pthread_mutex_trylock,
- (pthread_func_t)_pthread_mutex_trylock},/* PJT_MUTEX_TRYLOCK */
- {DUAL_ENTRY(_pthread_mutex_unlock)}, /* PJT_MUTEX_UNLOCK */
- {DUAL_ENTRY(_pthread_mutexattr_destroy)}, /* PJT_MUTEXATTR_DESTROY */
- {DUAL_ENTRY(_pthread_mutexattr_init)}, /* PJT_MUTEXATTR_INIT */
- {DUAL_ENTRY(_pthread_mutexattr_settype)}, /* PJT_MUTEXATTR_SETTYPE */
- {DUAL_ENTRY(_pthread_once)}, /* PJT_ONCE */
- {DUAL_ENTRY(_pthread_rwlock_destroy)}, /* PJT_RWLOCK_DESTROY */
- {DUAL_ENTRY(_pthread_rwlock_init)}, /* PJT_RWLOCK_INIT */
- {DUAL_ENTRY(_pthread_rwlock_rdlock)}, /* PJT_RWLOCK_RDLOCK */
- {DUAL_ENTRY(_pthread_rwlock_tryrdlock)},/* PJT_RWLOCK_TRYRDLOCK */
- {DUAL_ENTRY(_pthread_rwlock_trywrlock)},/* PJT_RWLOCK_TRYWRLOCK */
- {DUAL_ENTRY(_pthread_rwlock_unlock)}, /* PJT_RWLOCK_UNLOCK */
- {DUAL_ENTRY(_pthread_rwlock_wrlock)}, /* PJT_RWLOCK_WRLOCK */
- {DUAL_ENTRY(_pthread_self)}, /* PJT_SELF */
- {DUAL_ENTRY(_pthread_setspecific)}, /* PJT_SETSPECIFIC */
- {DUAL_ENTRY(_pthread_sigmask)} /* PJT_SIGMASK */
-};
-
-static int init_once = 0;
-
-/*
- * Threaded process initialization.
- *
- * This is only called under two conditions:
- *
- * 1) Some thread routines have detected that the library hasn't yet
- * been initialized (_thr_initial == NULL && curthread == NULL), or
- *
- * 2) An explicit call to reinitialize after a fork (indicated
- * by curthread != NULL)
- */
-void
-_libpthread_init(struct pthread *curthread)
-{
- int fd;
-
- /* Check if this function has already been called: */
- if ((_thr_initial != NULL) && (curthread == NULL))
- /* Only initialize the threaded application once. */
- return;
-
- /*
- * Make gcc quiescent about {,libgcc_}references not being
- * referenced:
- */
- if ((references[0] == NULL) || (libgcc_references[0] == NULL))
- PANIC("Failed loading mandatory references in _thread_init");
-
- /*
- * Check the size of the jump table to make sure it is preset
- * with the correct number of entries.
- */
- if (sizeof(jmp_table) != (sizeof(pthread_func_t) * PJT_MAX * 2))
- PANIC("Thread jump table not properly initialized");
- memcpy(__thr_jtable, jmp_table, sizeof(jmp_table));
-
- /*
- * Check for the special case of this process running as
- * or in place of init as pid = 1:
- */
- if ((_thr_pid = getpid()) == 1) {
- /*
- * Setup a new session for this process which is
- * assumed to be running as root.
- */
- if (setsid() == -1)
- PANIC("Can't set session ID");
- if (revoke(_PATH_CONSOLE) != 0)
- PANIC("Can't revoke console");
- if ((fd = __sys_open(_PATH_CONSOLE, O_RDWR)) < 0)
- PANIC("Can't open console");
- if (setlogin("root") == -1)
- PANIC("Can't set login to root");
- if (__sys_ioctl(fd, TIOCSCTTY, (char *) NULL) == -1)
- PANIC("Can't set controlling terminal");
- }
-
- /* Initialize pthread private data. */
- init_private();
- _kse_init();
-
- /* Initialize the initial kse and kseg. */
- _kse_initial = _kse_alloc(NULL);
- if (_kse_initial == NULL)
- PANIC("Can't allocate initial kse.");
- _kse_initial->k_kseg = _kseg_alloc(NULL);
- if (_kse_initial->k_kseg == NULL)
- PANIC("Can't allocate initial kseg.");
- _kse_initial->k_schedq = &_kse_initial->k_kseg->kg_schedq;
-
- TAILQ_INSERT_TAIL(&_kse_initial->k_kseg->kg_kseq, _kse_initial, k_kgqe);
- _kse_initial->k_kseg->kg_ksecount = 1;
-
- /* Set the initial thread. */
- if (curthread == NULL) {
- /* Create and initialize the initial thread. */
- curthread = _thr_alloc(NULL);
- if (curthread == NULL)
- PANIC("Can't allocate initial thread");
- _thr_initial = curthread;
- init_main_thread(curthread);
- } else {
- /*
- * The initial thread is the current thread. It is
- * assumed that the current thread is already initialized
- * because it is left over from a fork().
- */
- _thr_initial = curthread;
- }
- _kse_initial->k_kseg->kg_threadcount = 0;
- _thr_initial->kse = _kse_initial;
- _thr_initial->kseg = _kse_initial->k_kseg;
- _thr_initial->active = 1;
-
- /*
- * Add the thread to the thread list and to the KSEG's thread
- * queue.
- */
- THR_LIST_ADD(_thr_initial);
- KSEG_THRQ_ADD(_kse_initial->k_kseg, _thr_initial);
-
- /* Setup the KSE/thread specific data for the current KSE/thread. */
- if (_ksd_setprivate(&_thr_initial->kse->k_ksd) != 0)
- PANIC("Can't set initial KSE specific data");
- _set_curkse(_thr_initial->kse);
- _thr_initial->kse->k_curthread = _thr_initial;
- _thr_initial->kse->k_flags |= KF_INITIALIZED;
- _kse_initial->k_curthread = _thr_initial;
-
- _thr_rtld_init();
-}
-
-/*
- * This function and pthread_create() do a lot of the same things.
- * It'd be nice to consolidate the common stuff in one place.
- */
-static void
-init_main_thread(struct pthread *thread)
-{
- void *p;
- int i;
-
- /* Zero the initial thread structure. */
- p = thread->alloc_addr;
- memset(thread, 0, sizeof(struct pthread));
- thread->alloc_addr = p;
-
- /* Setup the thread attributes. */
- thread->attr = _pthread_attr_default;
-
- /*
- * Set up the thread stack.
- *
- * Create a red zone below the main stack. All other stacks
- * are constrained to a maximum size by the parameters
- * passed to mmap(), but this stack is only limited by
- * resource limits, so this stack needs an explicitly mapped
- * red zone to protect the thread stack that is just beyond.
- */
- if (mmap((void *)_usrstack - THR_STACK_INITIAL -
- _thr_guard_default, _thr_guard_default, 0, MAP_ANON,
- -1, 0) == MAP_FAILED)
- PANIC("Cannot allocate red zone for initial thread");
-
- /*
- * Mark the stack as an application supplied stack so that it
- * isn't deallocated.
- *
- * XXX - I'm not sure it would hurt anything to deallocate
- * the main thread stack because deallocation doesn't
- * actually free() it; it just puts it in the free
- * stack queue for later reuse.
- */
- thread->attr.stackaddr_attr = (void *)_usrstack - THR_STACK_INITIAL;
- thread->attr.stacksize_attr = THR_STACK_INITIAL;
- thread->attr.guardsize_attr = _thr_guard_default;
- thread->attr.flags |= THR_STACK_USER;
-
- /*
- * Write a magic value to the thread structure
- * to help identify valid ones:
- */
- thread->magic = THR_MAGIC;
-
- thread->slice_usec = -1;
- thread->cancelflags = PTHREAD_CANCEL_ENABLE | PTHREAD_CANCEL_DEFERRED;
- thread->name = strdup("initial thread");
-
- /* Initialize the thread for signals: */
- sigemptyset(&thread->sigmask);
-
- /*
- * Set up the thread mailbox. The threads saved context
- * is also in the mailbox.
- */
- thread->tmbx.tm_udata = thread;
- thread->tmbx.tm_context.uc_sigmask = thread->sigmask;
- thread->tmbx.tm_context.uc_stack.ss_size = thread->attr.stacksize_attr;
- thread->tmbx.tm_context.uc_stack.ss_sp = thread->attr.stackaddr_attr;
-
- /* Default the priority of the initial thread: */
- thread->base_priority = THR_DEFAULT_PRIORITY;
- thread->active_priority = THR_DEFAULT_PRIORITY;
- thread->inherited_priority = 0;
-
- /* Initialize the mutex queue: */
- TAILQ_INIT(&thread->mutexq);
-
- /* Initialize thread locking. */
- if (_lock_init(&thread->lock, LCK_ADAPTIVE,
- _thr_lock_wait, _thr_lock_wakeup) != 0)
- PANIC("Cannot initialize initial thread lock");
- for (i = 0; i < MAX_THR_LOCKLEVEL; i++) {
- _lockuser_init(&thread->lockusers[i], (void *)thread);
- _LCK_SET_PRIVATE2(&thread->lockusers[i], (void *)thread);
- }
-
- /* Initialize hooks in the thread structure: */
- thread->specific = NULL;
- thread->cleanup = NULL;
- thread->flags = 0;
- thread->continuation = NULL;
-
- thread->state = PS_RUNNING;
- thread->uniqueid = 0;
-}
-
-static void
-init_private(void)
-{
- struct clockinfo clockinfo;
- struct sigaction act;
- size_t len;
- int mib[2];
- int i;
-
- /*
- * Avoid reinitializing some things if they don't need to be,
- * e.g. after a fork().
- */
- if (init_once == 0) {
- /* Find the stack top */
- mib[0] = CTL_KERN;
- mib[1] = KERN_USRSTACK;
- len = sizeof (_usrstack);
- if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1)
- PANIC("Cannot get kern.usrstack from sysctl");
-
- /*
- * Create a red zone below the main stack. All other
- * stacks are constrained to a maximum size by the
- * parameters passed to mmap(), but this stack is only
- * limited by resource limits, so this stack needs an
- * explicitly mapped red zone to protect the thread stack
- * that is just beyond.
- */
- if (mmap((void *)_usrstack - THR_STACK_INITIAL -
- _thr_guard_default, _thr_guard_default,
- 0, MAP_ANON, -1, 0) == MAP_FAILED)
- PANIC("Cannot allocate red zone for initial thread");
-
- /* Get the kernel clockrate: */
- mib[0] = CTL_KERN;
- mib[1] = KERN_CLOCKRATE;
- len = sizeof (struct clockinfo);
- if (sysctl(mib, 2, &clockinfo, &len, NULL, 0) == 0)
- _clock_res_usec = clockinfo.tick;
- else
- _clock_res_usec = CLOCK_RES_USEC;
-
- _thr_page_size = getpagesize();
- _thr_guard_default = _thr_page_size;
-
- init_once = 1; /* Don't do this again. */
- } else {
- /*
- * Destroy the locks before creating them. We don't
- * know what state they are in so it is better to just
- * recreate them.
- */
- _lock_destroy(&_thread_signal_lock);
- _lock_destroy(&_mutex_static_lock);
- _lock_destroy(&_rwlock_static_lock);
- _lock_destroy(&_keytable_lock);
- }
-
-
- /* Initialize everything else. */
- TAILQ_INIT(&_thread_list);
- TAILQ_INIT(&_thread_gc_list);
-
- /* Enter a loop to get the existing signal status: */
- for (i = 1; i < NSIG; i++) {
- /* Check for signals which cannot be trapped: */
- if (i == SIGKILL || i == SIGSTOP) {
- }
-
- /* Get the signal handler details: */
- else if (__sys_sigaction(i, NULL,
- &_thread_sigact[i - 1]) != 0) {
- /*
- * Abort this process if signal
- * initialisation fails:
- */
- PANIC("Cannot read signal handler info");
- }
-
- /* Initialize the SIG_DFL dummy handler count. */
- _thread_dfl_count[i] = 0;
- }
-
- /*
- * Install the signal handler for SIGINFO. It isn't
- * really needed, but it is nice to have for debugging
- * purposes.
- */
- if (__sys_sigaction(SIGINFO, &act, NULL) != 0) {
- /*
- * Abort this process if signal initialisation fails:
- */
- PANIC("Cannot initialize signal handler");
- }
- _thread_sigact[SIGINFO - 1].sa_flags = SA_SIGINFO | SA_RESTART;
-
- /*
- * Initialize the lock for temporary installation of signal
- * handlers (to support sigwait() semantics) and for the
- * process signal mask and pending signal sets.
- */
- if (_lock_init(&_thread_signal_lock, LCK_ADAPTIVE,
- _kse_lock_wait, _kse_lock_wakeup) != 0)
- PANIC("Cannot initialize _thread_signal_lock");
- if (_lock_init(&_mutex_static_lock, LCK_ADAPTIVE,
- _thr_lock_wait, _thr_lock_wakeup) != 0)
- PANIC("Cannot initialize mutex static init lock");
- if (_lock_init(&_rwlock_static_lock, LCK_ADAPTIVE,
- _thr_lock_wait, _thr_lock_wakeup) != 0)
- PANIC("Cannot initialize rwlock static init lock");
- if (_lock_init(&_keytable_lock, LCK_ADAPTIVE,
- _thr_lock_wait, _thr_lock_wakeup) != 0)
- PANIC("Cannot initialize thread specific keytable lock");
- _thr_spinlock_init();
-
- /* Clear pending signals and get the process signal mask. */
- sigemptyset(&_thr_proc_sigpending);
- __sys_sigprocmask(SIG_SETMASK, NULL, &_thr_proc_sigmask);
-
- /*
- * _thread_list_lock and _kse_count are initialized
- * by _kse_init()
- */
-}
diff --git a/lib/libkse/thread/thr_join.c b/lib/libkse/thread/thr_join.c
deleted file mode 100644
index d6add8889ef0..000000000000
--- a/lib/libkse/thread/thr_join.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_join, pthread_join);
-
-int
-_pthread_join(pthread_t pthread, void **thread_return)
-{
- struct pthread *curthread = _get_curthread();
- kse_critical_t crit;
- int ret = 0;
-
- _thr_enter_cancellation_point(curthread);
-
- /* Check if the caller has specified an invalid thread: */
- if (pthread == NULL || pthread->magic != THR_MAGIC) {
- /* Invalid thread: */
- _thr_leave_cancellation_point(curthread);
- return (EINVAL);
- }
-
- /* Check if the caller has specified itself: */
- if (pthread == curthread) {
- /* Avoid a deadlock condition: */
- _thr_leave_cancellation_point(curthread);
- return (EDEADLK);
- }
-
- /*
- * Find the thread in the list of active threads or in the
- * list of dead threads:
- */
- if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/1)) != 0) {
- /* Return an error: */
- _thr_leave_cancellation_point(curthread);
- return (ESRCH);
- }
-
- THR_SCHED_LOCK(curthread, pthread);
- /* Check if this thread has been detached: */
- if ((pthread->attr.flags & PTHREAD_DETACHED) != 0) {
- THR_SCHED_UNLOCK(curthread, pthread);
- /* Remove the reference and return an error: */
- _thr_ref_delete(curthread, pthread);
- ret = ESRCH;
- } else {
- /* Lock the target thread while checking its state. */
- if (pthread->state == PS_DEAD) {
- if (thread_return != NULL)
- /* Return the thread's return value: */
- *thread_return = pthread->ret;
-
- /* Detach the thread. */
- pthread->attr.flags |= PTHREAD_DETACHED;
-
- /* Unlock the thread. */
- THR_SCHED_UNLOCK(curthread, pthread);
-
- /*
- * Remove the thread from the list of active
- * threads and add it to the GC list.
- */
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &_thread_list_lock);
- THR_LIST_REMOVE(pthread);
- THR_GCLIST_ADD(pthread);
- KSE_LOCK_RELEASE(curthread->kse, &_thread_list_lock);
- _kse_critical_leave(crit);
-
- /* Remove the reference. */
- _thr_ref_delete(curthread, pthread);
- }
- else if (pthread->joiner != NULL) {
- /* Unlock the thread and remove the reference. */
- THR_SCHED_UNLOCK(curthread, pthread);
- _thr_ref_delete(curthread, pthread);
-
- /* Multiple joiners are not supported. */
- ret = ENOTSUP;
- }
- else {
- /* Set the running thread to be the joiner: */
- pthread->joiner = curthread;
-
- /* Keep track of which thread we're joining to: */
- curthread->join_status.thread = pthread;
-
- /* Unlock the thread and remove the reference. */
- THR_SCHED_UNLOCK(curthread, pthread);
- _thr_ref_delete(curthread, pthread);
-
- THR_SCHED_LOCK(curthread, curthread);
- while (curthread->join_status.thread == pthread) {
- THR_SET_STATE(curthread, PS_JOIN);
- THR_SCHED_UNLOCK(curthread, curthread);
- /* Schedule the next thread: */
- _thr_sched_switch(curthread);
- THR_SCHED_LOCK(curthread, curthread);
- }
- THR_SCHED_UNLOCK(curthread, curthread);
-
- if ((curthread->cancelflags & THR_CANCELLING) &&
- !(curthread->cancelflags & PTHREAD_CANCEL_DISABLE)) {
- if (_thr_ref_add(curthread, pthread, 1) == 0) {
- THR_SCHED_LOCK(curthread, pthread);
- pthread->joiner = NULL;
- THR_SCHED_UNLOCK(curthread, pthread);
- _thr_ref_delete(curthread, pthread);
- }
- pthread_exit(PTHREAD_CANCELED);
- }
-
- /*
- * The thread return value and error are set by the
- * thread we're joining to when it exits or detaches:
- */
- ret = curthread->join_status.error;
- if ((ret == 0) && (thread_return != NULL))
- *thread_return = curthread->join_status.ret;
- }
- }
- _thr_leave_cancellation_point(curthread);
-
- /* Return the completion status: */
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_kern.c b/lib/libkse/thread/thr_kern.c
deleted file mode 100644
index 8eb084d95f1a..000000000000
--- a/lib/libkse/thread/thr_kern.c
+++ /dev/null
@@ -1,2214 +0,0 @@
-/*
- * Copyright (C) 2003 Daniel M. Eischen <deischen@freebsd.org>
- * Copyright (C) 2002 Jonathon Mini <mini@freebsd.org>
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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/types.h>
-#include <sys/kse.h>
-#include <sys/signalvar.h>
-#include <sys/queue.h>
-#include <machine/atomic.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <ucontext.h>
-#include <unistd.h>
-
-#include "atomic_ops.h"
-#include "thr_private.h"
-#include "pthread_md.h"
-#include "libc_private.h"
-
-/*#define DEBUG_THREAD_KERN */
-#ifdef DEBUG_THREAD_KERN
-#define DBG_MSG stdout_debug
-#else
-#define DBG_MSG(x...)
-#endif
-
-/*
- * Define a high water mark for the maximum number of threads that
- * will be cached. Once this level is reached, any extra threads
- * will be free()'d.
- *
- * XXX - It doesn't make sense to worry about the maximum number of
- * KSEs that we can cache because the system will limit us to
- * something *much* less than the maximum number of threads
- * that we can have. Disregarding KSEs in their own group,
- * the maximum number of KSEs is the number of processors in
- * the system.
- */
-#define MAX_CACHED_THREADS 100
-#define KSE_STACKSIZE 16384
-
-#define KSE_SET_MBOX(kse, thrd) \
- (kse)->k_mbx.km_curthread = &(thrd)->tmbx
-
-#define KSE_SET_EXITED(kse) (kse)->k_flags |= KF_EXITED
-
-/*
- * Macros for manipulating the run queues. The priority queue
- * routines use the thread's pqe link and also handle the setting
- * and clearing of the thread's THR_FLAGS_IN_RUNQ flag.
- */
-#define KSE_RUNQ_INSERT_HEAD(kse, thrd) \
- _pq_insert_head(&(kse)->k_schedq->sq_runq, thrd)
-#define KSE_RUNQ_INSERT_TAIL(kse, thrd) \
- _pq_insert_tail(&(kse)->k_schedq->sq_runq, thrd)
-#define KSE_RUNQ_REMOVE(kse, thrd) \
- _pq_remove(&(kse)->k_schedq->sq_runq, thrd)
-#define KSE_RUNQ_FIRST(kse) _pq_first(&(kse)->k_schedq->sq_runq)
-
-#define KSE_RUNQ_THREADS(kse) ((kse)->k_schedq->sq_runq.pq_threads)
-
-#ifndef KMF_DONE
-#define KMF_DONE 0x04
-#endif
-
-/*
- * We've got to keep track of everything that is allocated, not only
- * to have a speedy free list, but also so they can be deallocated
- * after a fork().
- */
-static TAILQ_HEAD(, kse) active_kseq;
-static TAILQ_HEAD(, kse) free_kseq;
-static TAILQ_HEAD(, kse_group) free_kse_groupq;
-static TAILQ_HEAD(, kse_group) active_kse_groupq;
-static TAILQ_HEAD(, kse_group) gc_ksegq;
-static struct lock kse_lock; /* also used for kseg queue */
-static int free_kse_count = 0;
-static int free_kseg_count = 0;
-static TAILQ_HEAD(, pthread) free_threadq;
-static struct lock thread_lock;
-static int free_thread_count = 0;
-static int inited = 0;
-static int active_threads = 1;
-static int active_kse_count = 0;
-static int active_kseg_count = 0;
-static u_int64_t next_uniqueid = 1;
-
-
-#ifdef DEBUG_THREAD_KERN
-static void dump_queues(struct kse *curkse);
-#endif
-static void kse_check_completed(struct kse *kse);
-static void kse_check_waitq(struct kse *kse);
-static void kse_check_signals(struct kse *kse);
-static void kse_fini(struct kse *curkse);
-static void kse_reinit(struct kse *kse);
-static void kse_sched_multi(struct kse *curkse);
-#ifdef NOT_YET
-static void kse_sched_single(struct kse *curkse);
-#endif
-static void kse_switchout_thread(struct kse *kse, struct pthread *thread);
-static void kse_wait(struct kse *kse, struct pthread *td_wait);
-static void kse_free_unlocked(struct kse *kse);
-static void kseg_free_unlocked(struct kse_group *kseg);
-static void kseg_init(struct kse_group *kseg);
-static void kseg_reinit(struct kse_group *kseg);
-static void kse_waitq_insert(struct pthread *thread);
-static void kse_wakeup_multi(struct kse *curkse);
-static void kse_wakeup_one(struct pthread *thread);
-static void thr_cleanup(struct kse *kse, struct pthread *curthread);
-static void thr_link(struct pthread *thread);
-static void thr_resume_wrapper(int unused_1, siginfo_t *unused_2,
- ucontext_t *ucp);
-static void thr_resume_check(struct pthread *curthread, ucontext_t *ucp,
- struct pthread_sigframe *psf);
-static int thr_timedout(struct pthread *thread, struct timespec *curtime);
-static void thr_unlink(struct pthread *thread);
-
-/*
- * This is called after a fork().
- * No locks need to be taken here since we are guaranteed to be
- * single threaded.
- */
-void
-_kse_single_thread(struct pthread *curthread)
-{
- struct kse *kse;
- struct kse_group *kseg;
- struct pthread *thread;
- kse_critical_t crit;
- int i;
-
- /*
- * Disable upcalls and clear the threaded flag.
- * XXX - I don't think we need to disable upcalls after a fork().
- * but it doesn't hurt.
- */
- crit = _kse_critical_enter();
- __isthreaded = 0;
- active_threads = 1;
-
- /*
- * Enter a loop to remove and free all threads other than
- * the running thread from the active thread list:
- */
- while ((thread = TAILQ_FIRST(&_thread_list)) != NULL) {
- THR_GCLIST_REMOVE(thread);
- /*
- * Remove this thread from the list (the current
- * thread will be removed but re-added by libpthread
- * initialization.
- */
- TAILQ_REMOVE(&_thread_list, thread, tle);
- /* Make sure this isn't the running thread: */
- if (thread != curthread) {
- _thr_stack_free(&thread->attr);
- if (thread->specific != NULL)
- free(thread->specific);
- for (i = 0; i < MAX_THR_LOCKLEVEL; i++) {
- _lockuser_destroy(&thread->lockusers[i]);
- }
- _lock_destroy(&thread->lock);
- free(thread);
- }
- }
-
- TAILQ_INIT(&curthread->mutexq); /* initialize mutex queue */
- curthread->joiner = NULL; /* no joining threads yet */
- curthread->refcount = 0;
- sigemptyset(&curthread->sigpend); /* clear pending signals */
- if (curthread->specific != NULL) {
- free(curthread->specific);
- curthread->specific = NULL;
- curthread->specific_data_count = 0;
- }
-
- /* Free the free KSEs: */
- while ((kse = TAILQ_FIRST(&free_kseq)) != NULL) {
- TAILQ_REMOVE(&free_kseq, kse, k_qe);
- for (i = 0; i < MAX_KSE_LOCKLEVEL; i++) {
- _lockuser_destroy(&kse->k_lockusers[i]);
- }
- _lock_destroy(&kse->k_lock);
- _ksd_destroy(&kse->k_ksd);
- if (kse->k_stack.ss_sp != NULL)
- free(kse->k_stack.ss_sp);
- free(kse);
- }
- free_kse_count = 0;
-
- /* Free the active KSEs: */
- while ((kse = TAILQ_FIRST(&active_kseq)) != NULL) {
- TAILQ_REMOVE(&active_kseq, kse, k_qe);
- for (i = 0; i < MAX_KSE_LOCKLEVEL; i++) {
- _lockuser_destroy(&kse->k_lockusers[i]);
- }
- _lock_destroy(&kse->k_lock);
- if (kse->k_stack.ss_sp != NULL)
- free(kse->k_stack.ss_sp);
- free(kse);
- }
- active_kse_count = 0;
-
- /* Free the free KSEGs: */
- while ((kseg = TAILQ_FIRST(&free_kse_groupq)) != NULL) {
- TAILQ_REMOVE(&free_kse_groupq, kseg, kg_qe);
- _lock_destroy(&kseg->kg_lock);
- _pq_free(&kseg->kg_schedq.sq_runq);
- free(kseg);
- }
- free_kseg_count = 0;
-
- /* Free the active KSEGs: */
- while ((kseg = TAILQ_FIRST(&active_kse_groupq)) != NULL) {
- TAILQ_REMOVE(&active_kse_groupq, kseg, kg_qe);
- _lock_destroy(&kseg->kg_lock);
- _pq_free(&kseg->kg_schedq.sq_runq);
- free(kseg);
- }
- active_kseg_count = 0;
-
- /* Free the free threads. */
- while ((thread = TAILQ_FIRST(&free_threadq)) != NULL) {
- TAILQ_REMOVE(&free_threadq, thread, tle);
- if (thread->specific != NULL)
- free(thread->specific);
- for (i = 0; i < MAX_THR_LOCKLEVEL; i++) {
- _lockuser_destroy(&thread->lockusers[i]);
- }
- _lock_destroy(&thread->lock);
- free(thread);
- }
- free_thread_count = 0;
-
- /* Free the to-be-gc'd threads. */
- while ((thread = TAILQ_FIRST(&_thread_gc_list)) != NULL) {
- TAILQ_REMOVE(&_thread_gc_list, thread, gcle);
- for (i = 0; i < MAX_THR_LOCKLEVEL; i++) {
- _lockuser_destroy(&thread->lockusers[i]);
- }
- _lock_destroy(&thread->lock);
- free(thread);
- }
- TAILQ_INIT(&gc_ksegq);
- _gc_count = 0;
-
- if (inited != 0) {
- /*
- * Destroy these locks; they'll be recreated to assure they
- * are in the unlocked state.
- */
- _lock_destroy(&kse_lock);
- _lock_destroy(&thread_lock);
- _lock_destroy(&_thread_list_lock);
- inited = 0;
- }
-
- /*
- * After a fork(), the leftover thread goes back to being
- * scope process.
- */
- curthread->attr.flags &= ~PTHREAD_SCOPE_SYSTEM;
- curthread->attr.flags |= PTHREAD_SCOPE_PROCESS;
-
- /*
- * After a fork, we are still operating on the thread's original
- * stack. Don't clear the THR_FLAGS_USER from the thread's
- * attribute flags.
- */
-
- /* Initialize the threads library. */
- curthread->kse = NULL;
- curthread->kseg = NULL;
- _kse_initial = NULL;
- _libpthread_init(curthread);
-}
-
-/*
- * This is used to initialize housekeeping and to initialize the
- * KSD for the KSE.
- */
-void
-_kse_init(void)
-{
- if (inited == 0) {
- TAILQ_INIT(&active_kseq);
- TAILQ_INIT(&active_kse_groupq);
- TAILQ_INIT(&free_kseq);
- TAILQ_INIT(&free_kse_groupq);
- TAILQ_INIT(&free_threadq);
- TAILQ_INIT(&gc_ksegq);
- if (_lock_init(&kse_lock, LCK_ADAPTIVE,
- _kse_lock_wait, _kse_lock_wakeup) != 0)
- PANIC("Unable to initialize free KSE queue lock");
- if (_lock_init(&thread_lock, LCK_ADAPTIVE,
- _kse_lock_wait, _kse_lock_wakeup) != 0)
- PANIC("Unable to initialize free thread queue lock");
- if (_lock_init(&_thread_list_lock, LCK_ADAPTIVE,
- _kse_lock_wait, _kse_lock_wakeup) != 0)
- PANIC("Unable to initialize thread list lock");
- active_kse_count = 0;
- active_kseg_count = 0;
- _gc_count = 0;
- inited = 1;
- }
-}
-
-int
-_kse_isthreaded(void)
-{
- return (__isthreaded != 0);
-}
-
-/*
- * This is called when the first thread (other than the initial
- * thread) is created.
- */
-int
-_kse_setthreaded(int threaded)
-{
- if ((threaded != 0) && (__isthreaded == 0)) {
- /*
- * Locking functions in libc are required when there are
- * threads other than the initial thread.
- */
- __isthreaded = 1;
-
- /*
- * Tell the kernel to create a KSE for the initial thread
- * and enable upcalls in it.
- */
- _kse_initial->k_flags |= KF_STARTED;
- if (kse_create(&_kse_initial->k_mbx, 0) != 0) {
- _kse_initial->k_flags &= ~KF_STARTED;
- __isthreaded = 0;
- /* may abort() */
- DBG_MSG("kse_create failed\n");
- return (-1);
- }
- KSE_SET_MBOX(_kse_initial, _thr_initial);
- _thr_setmaxconcurrency();
- }
- return (0);
-}
-
-/*
- * Lock wait and wakeup handlers for KSE locks. These are only used by
- * KSEs, and should never be used by threads. KSE locks include the
- * KSE group lock (used for locking the scheduling queue) and the
- * kse_lock defined above.
- *
- * When a KSE lock attempt blocks, the entire KSE blocks allowing another
- * KSE to run. For the most part, it doesn't make much sense to try and
- * schedule another thread because you need to lock the scheduling queue
- * in order to do that. And since the KSE lock is used to lock the scheduling
- * queue, you would just end up blocking again.
- */
-void
-_kse_lock_wait(struct lock *lock, struct lockuser *lu)
-{
- struct kse *curkse = (struct kse *)_LCK_GET_PRIVATE(lu);
- struct timespec ts;
- int saved_flags;
-
- if (curkse->k_mbx.km_curthread != NULL)
- PANIC("kse_lock_wait does not disable upcall.\n");
- /*
- * Enter a loop to wait until we get the lock.
- */
- ts.tv_sec = 0;
- ts.tv_nsec = 1000000; /* 1 sec */
- while (!_LCK_GRANTED(lu)) {
- /*
- * Yield the kse and wait to be notified when the lock
- * is granted.
- */
- saved_flags = curkse->k_mbx.km_flags;
- curkse->k_mbx.km_flags |= KMF_NOUPCALL | KMF_NOCOMPLETED;
- kse_release(&ts);
- curkse->k_mbx.km_flags = saved_flags;
- }
-}
-
-void
-_kse_lock_wakeup(struct lock *lock, struct lockuser *lu)
-{
- struct kse *curkse;
- struct kse *kse;
- struct kse_mailbox *mbx;
-
- curkse = _get_curkse();
- kse = (struct kse *)_LCK_GET_PRIVATE(lu);
-
- if (kse == curkse)
- PANIC("KSE trying to wake itself up in lock");
- else {
- mbx = &kse->k_mbx;
- _lock_grant(lock, lu);
- /*
- * Notify the owning kse that it has the lock.
- * It is safe to pass invalid address to kse_wakeup
- * even if the mailbox is not in kernel at all,
- * and waking up a wrong kse is also harmless.
- */
- kse_wakeup(mbx);
- }
-}
-
-/*
- * Thread wait and wakeup handlers for thread locks. These are only used
- * by threads, never by KSEs. Thread locks include the per-thread lock
- * (defined in its structure), and condition variable and mutex locks.
- */
-void
-_thr_lock_wait(struct lock *lock, struct lockuser *lu)
-{
- struct pthread *curthread = (struct pthread *)lu->lu_private;
-
- do {
- THR_SCHED_LOCK(curthread, curthread);
- THR_SET_STATE(curthread, PS_LOCKWAIT);
- THR_SCHED_UNLOCK(curthread, curthread);
- _thr_sched_switch(curthread);
- } while (!_LCK_GRANTED(lu));
-}
-
-void
-_thr_lock_wakeup(struct lock *lock, struct lockuser *lu)
-{
- struct pthread *thread;
- struct pthread *curthread;
-
- curthread = _get_curthread();
- thread = (struct pthread *)_LCK_GET_PRIVATE(lu);
-
- THR_SCHED_LOCK(curthread, thread);
- _lock_grant(lock, lu);
- _thr_setrunnable_unlocked(thread);
- THR_SCHED_UNLOCK(curthread, thread);
-}
-
-kse_critical_t
-_kse_critical_enter(void)
-{
- kse_critical_t crit;
-
- crit = _ksd_readandclear_tmbx;
- return (crit);
-}
-
-void
-_kse_critical_leave(kse_critical_t crit)
-{
- struct pthread *curthread;
-
- _ksd_set_tmbx(crit);
- if ((crit != NULL) && ((curthread = _get_curthread()) != NULL))
- THR_YIELD_CHECK(curthread);
-}
-
-int
-_kse_in_critical(void)
-{
- return (_ksd_get_tmbx() == NULL);
-}
-
-void
-_thr_critical_enter(struct pthread *thread)
-{
- thread->critical_count++;
-}
-
-void
-_thr_critical_leave(struct pthread *thread)
-{
- thread->critical_count--;
- THR_YIELD_CHECK(thread);
-}
-
-void
-_thr_sched_switch(struct pthread *curthread)
-{
- struct kse *curkse;
-
- (void)_kse_critical_enter();
- curkse = _get_curkse();
- KSE_SCHED_LOCK(curkse, curkse->k_kseg);
- _thr_sched_switch_unlocked(curthread);
-}
-
-/*
- * XXX - We may need to take the scheduling lock before calling
- * this, or perhaps take the lock within here before
- * doing anything else.
- */
-void
-_thr_sched_switch_unlocked(struct pthread *curthread)
-{
- struct pthread *td;
- struct pthread_sigframe psf;
- struct kse *curkse;
- int ret;
- volatile int uts_once;
- volatile int resume_once = 0;
-
- /* We're in the scheduler, 5 by 5: */
- curkse = _get_curkse();
-
- curthread->need_switchout = 1; /* The thread yielded on its own. */
- curthread->critical_yield = 0; /* No need to yield anymore. */
- curthread->slice_usec = -1; /* Restart the time slice. */
-
- /* Thread can unlock the scheduler lock. */
- curthread->lock_switch = 1;
-
- /*
- * The signal frame is allocated off the stack because
- * a thread can be interrupted by other signals while
- * it is running down pending signals.
- */
- sigemptyset(&psf.psf_sigset);
- curthread->curframe = &psf;
-
- /*
- * Enter the scheduler if any one of the following is true:
- *
- * o The current thread is dead; it's stack needs to be
- * cleaned up and it can't be done while operating on
- * it.
- * o There are no runnable threads.
- * o The next thread to run won't unlock the scheduler
- * lock. A side note: the current thread may be run
- * instead of the next thread in the run queue, but
- * we don't bother checking for that.
- */
- if ((curthread->state == PS_DEAD) ||
- (((td = KSE_RUNQ_FIRST(curkse)) == NULL) &&
- (curthread->state != PS_RUNNING)) ||
- ((td != NULL) && (td->lock_switch == 0)))
- _thread_enter_uts(&curthread->tmbx, &curkse->k_mbx);
- else {
- uts_once = 0;
- THR_GETCONTEXT(&curthread->tmbx.tm_context);
- if (uts_once == 0) {
- uts_once = 1;
-
- /* Switchout the current thread. */
- kse_switchout_thread(curkse, curthread);
-
- /* Choose another thread to run. */
- td = KSE_RUNQ_FIRST(curkse);
- KSE_RUNQ_REMOVE(curkse, td);
- curkse->k_curthread = td;
-
- /*
- * Make sure the current thread's kse points to
- * this kse.
- */
- td->kse = curkse;
-
- /*
- * Reset accounting.
- */
- td->tmbx.tm_uticks = 0;
- td->tmbx.tm_sticks = 0;
-
- /*
- * Reset the time slice if this thread is running
- * for the first time or running again after using
- * its full time slice allocation.
- */
- if (td->slice_usec == -1)
- td->slice_usec = 0;
-
- /* Mark the thread active. */
- td->active = 1;
-
- /* Remove the frame reference. */
- td->curframe = NULL;
-
- /*
- * Continue the thread at its current frame:
- */
- ret = _thread_switch(&td->tmbx, NULL);
- /* This point should not be reached. */
- if (ret != 0)
- PANIC("Bad return from _thread_switch");
- PANIC("Thread has returned from _thread_switch");
- }
- }
-
- if (curthread->lock_switch != 0) {
- /*
- * Unlock the scheduling queue and leave the
- * critical region.
- */
- /* Don't trust this after a switch! */
- curkse = _get_curkse();
-
- curthread->lock_switch = 0;
- KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
- _kse_critical_leave(&curthread->tmbx);
- }
- /*
- * This thread is being resumed; check for cancellations.
- */
- if ((resume_once == 0) && (!THR_IN_CRITICAL(curthread))) {
- resume_once = 1;
- thr_resume_check(curthread, &curthread->tmbx.tm_context, &psf);
- }
-
- THR_ACTIVATE_LAST_LOCK(curthread);
-}
-
-/*
- * This is the scheduler for a KSE which runs a scope system thread.
- * The multi-thread KSE scheduler should also work for a single threaded
- * KSE, but we use a separate scheduler so that it can be fine-tuned
- * to be more efficient (and perhaps not need a separate stack for
- * the KSE, allowing it to use the thread's stack).
- *
- * XXX - This probably needs some work.
- */
-#ifdef NOT_YET
-static void
-kse_sched_single(struct kse *curkse)
-{
- struct pthread *curthread = curkse->k_curthread;
- struct pthread *td_wait;
- struct timespec ts;
- int level;
-
- if (curthread->active == 0) {
- if (curthread->state != PS_RUNNING) {
- /* Check to see if the thread has timed out. */
- KSE_GET_TOD(curkse, &ts);
- if (thr_timedout(curthread, &ts) != 0) {
- curthread->timeout = 1;
- curthread->state = PS_RUNNING;
- }
- }
- }
-
- /* This thread no longer needs to yield the CPU: */
- curthread->critical_yield = 0;
- curthread->need_switchout = 0;
-
- /*
- * Lock the scheduling queue.
- *
- * There is no scheduling queue for single threaded KSEs,
- * but we need a lock for protection regardless.
- */
- KSE_SCHED_LOCK(curkse, curkse->k_kseg);
-
- /*
- * This has to do the job of kse_switchout_thread(), only
- * for a single threaded KSE/KSEG.
- */
-
- switch (curthread->state) {
- case PS_DEAD:
- /* Unlock the scheduling queue and exit the KSE and thread. */
- thr_cleaup(curkse, curthread);
- KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
- break;
-
- case PS_COND_WAIT:
- case PS_SLEEP_WAIT:
- /* Only insert threads that can timeout: */
- if (curthread->wakeup_time.tv_sec != -1) {
- /* Insert into the waiting queue: */
- KSE_WAITQ_INSERT(curkse, curthread);
- }
- break;
-
- case PS_LOCKWAIT:
- level = curthread->locklevel - 1;
- if (!_LCK_GRANTED(&curthread->lockusers[level]))
- KSE_WAITQ_INSERT(curkse, curthread);
- else
- THR_SET_STATE(curthread, PS_RUNNING);
- break;
-
- case PS_JOIN:
- case PS_MUTEX_WAIT:
- case PS_RUNNING:
- case PS_SIGSUSPEND:
- case PS_SIGWAIT:
- case PS_SUSPENDED:
- case PS_DEADLOCK:
- default:
- /*
- * These states don't timeout and don't need
- * to be in the waiting queue.
- */
- break;
- }
- while (curthread->state != PS_RUNNING) {
- curthread->active = 0;
- td_wait = KSE_WAITQ_FIRST(curkse);
-
- kse_wait(curkse, td_wait);
-
- if (td_wait != NULL) {
- KSE_GET_TOD(curkse, &ts);
- if (thr_timedout(curthread, &ts)) {
- /* Indicate the thread timedout: */
- td_wait->timeout = 1;
-
- /* Make the thread runnable. */
- THR_SET_STATE(td_wait, PS_RUNNING);
- KSE_WAITQ_REMOVE(curkse, td_wait);
- }
- }
- KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
- kse_check_signals(curkse);
- KSE_SCHED_LOCK(curkse, curkse->k_kseg);
- }
-
- /* Remove the frame reference. */
- curthread->curframe = NULL;
-
- /* Unlock the scheduling queue. */
- KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
-
- /*
- * Continue the thread at its current frame:
- */
- DBG_MSG("Continuing bound thread %p\n", curthread);
- _thread_switch(&curthread->tmbx, &curkse->k_mbx.km_curthread);
- PANIC("Thread has returned from _thread_switch");
-}
-#endif
-
-#ifdef DEBUG_THREAD_KERN
-static void
-dump_queues(struct kse *curkse)
-{
- struct pthread *thread;
-
- DBG_MSG("Threads in waiting queue:\n");
- TAILQ_FOREACH(thread, &curkse->k_kseg->kg_schedq.sq_waitq, pqe) {
- DBG_MSG(" thread %p, state %d, blocked %d\n",
- thread, thread->state, thread->blocked);
- }
-}
-#endif
-
-/*
- * This is the scheduler for a KSE which runs multiple threads.
- */
-static void
-kse_sched_multi(struct kse *curkse)
-{
- struct pthread *curthread, *td_wait;
- struct pthread_sigframe *curframe;
- int ret;
-
- THR_ASSERT(curkse->k_mbx.km_curthread == NULL,
- "Mailbox not null in kse_sched_multi");
-
- /* Check for first time initialization: */
- if ((curkse->k_flags & KF_INITIALIZED) == 0) {
- /* Setup this KSEs specific data. */
- _ksd_setprivate(&curkse->k_ksd);
- _set_curkse(curkse);
-
- /* Set this before grabbing the context. */
- curkse->k_flags |= KF_INITIALIZED;
- }
-
- /* This may have returned from a kse_release(). */
- if (KSE_WAITING(curkse)) {
- DBG_MSG("Entered upcall when KSE is waiting.");
- KSE_CLEAR_WAIT(curkse);
- }
-
- /* Lock the scheduling lock. */
- curthread = curkse->k_curthread;
- if ((curthread == NULL) || (curthread->need_switchout == 0)) {
- /* This is an upcall; take the scheduler lock. */
- KSE_SCHED_LOCK(curkse, curkse->k_kseg);
- }
-
- if (KSE_IS_IDLE(curkse)) {
- KSE_CLEAR_IDLE(curkse);
- curkse->k_kseg->kg_idle_kses--;
- }
- /*
- * If the current thread was completed in another KSE, then
- * it will be in the run queue. Don't mark it as being blocked.
- */
- if ((curthread != NULL) &&
- ((curthread->flags & THR_FLAGS_IN_RUNQ) == 0) &&
- (curthread->need_switchout == 0)) {
- /*
- * Assume the current thread is blocked; when the
- * completed threads are checked and if the current
- * thread is among the completed, the blocked flag
- * will be cleared.
- */
- curthread->blocked = 1;
- }
-
- /* Check for any unblocked threads in the kernel. */
- kse_check_completed(curkse);
-
- /*
- * Check for threads that have timed-out.
- */
- kse_check_waitq(curkse);
-
- /*
- * Switchout the current thread, if necessary, as the last step
- * so that it is inserted into the run queue (if it's runnable)
- * _after_ any other threads that were added to it above.
- */
- if (curthread == NULL)
- ; /* Nothing to do here. */
- else if ((curthread->need_switchout == 0) &&
- (curthread->blocked == 0) && (THR_IN_CRITICAL(curthread))) {
- /*
- * Resume the thread and tell it to yield when
- * it leaves the critical region.
- */
- curthread->critical_yield = 1;
- curthread->active = 1;
- if ((curthread->flags & THR_FLAGS_IN_RUNQ) != 0)
- KSE_RUNQ_REMOVE(curkse, curthread);
- curkse->k_curthread = curthread;
- curthread->kse = curkse;
- DBG_MSG("Continuing thread %p in critical region\n",
- curthread);
- kse_wakeup_multi(curkse);
- KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
- ret = _thread_switch(&curthread->tmbx,
- &curkse->k_mbx.km_curthread);
- if (ret != 0)
- PANIC("Can't resume thread in critical region\n");
- }
- else if ((curthread->flags & THR_FLAGS_IN_RUNQ) == 0)
- kse_switchout_thread(curkse, curthread);
- curkse->k_curthread = NULL;
-
- kse_wakeup_multi(curkse);
-
- /* This has to be done without the scheduling lock held. */
- KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
- kse_check_signals(curkse);
- KSE_SCHED_LOCK(curkse, curkse->k_kseg);
-
-#ifdef DEBUG_THREAD_KERN
- dump_queues(curkse);
-#endif
-
- /* Check if there are no threads ready to run: */
- while (((curthread = KSE_RUNQ_FIRST(curkse)) == NULL) &&
- (curkse->k_kseg->kg_threadcount != 0)) {
- /*
- * Wait for a thread to become active or until there are
- * no more threads.
- */
- td_wait = KSE_WAITQ_FIRST(curkse);
- kse_wait(curkse, td_wait);
- kse_check_completed(curkse);
- kse_check_waitq(curkse);
- KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
- kse_check_signals(curkse);
- KSE_SCHED_LOCK(curkse, curkse->k_kseg);
- }
-
- /* Check for no more threads: */
- if (curkse->k_kseg->kg_threadcount == 0) {
- /*
- * Normally this shouldn't return, but it will if there
- * are other KSEs running that create new threads that
- * are assigned to this KSE[G]. For instance, if a scope
- * system thread were to create a scope process thread
- * and this kse[g] is the initial kse[g], then that newly
- * created thread would be assigned to us (the initial
- * kse[g]).
- */
- KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
- kse_fini(curkse);
- /* never returns */
- }
-
- THR_ASSERT(curthread != NULL,
- "Return from kse_wait/fini without thread.");
- THR_ASSERT(curthread->state != PS_DEAD,
- "Trying to resume dead thread!");
- KSE_RUNQ_REMOVE(curkse, curthread);
-
- /*
- * Make the selected thread the current thread.
- */
- curkse->k_curthread = curthread;
-
- /*
- * Make sure the current thread's kse points to this kse.
- */
- curthread->kse = curkse;
-
- /*
- * Reset accounting.
- */
- curthread->tmbx.tm_uticks = 0;
- curthread->tmbx.tm_sticks = 0;
-
- /*
- * Reset the time slice if this thread is running for the first
- * time or running again after using its full time slice allocation.
- */
- if (curthread->slice_usec == -1)
- curthread->slice_usec = 0;
-
- /* Mark the thread active. */
- curthread->active = 1;
-
- /* Remove the frame reference. */
- curframe = curthread->curframe;
- curthread->curframe = NULL;
-
- kse_wakeup_multi(curkse);
-
- /*
- * The thread's current signal frame will only be NULL if it
- * is being resumed after being blocked in the kernel. In
- * this case, and if the thread needs to run down pending
- * signals or needs a cancellation check, we need to add a
- * signal frame to the thread's context.
- */
-#ifdef NOT_YET
- if ((curframe == NULL) && ((curthread->have_signals != 0) ||
- (((curthread->cancelflags & THR_AT_CANCEL_POINT) == 0) &&
- ((curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0))))
- signalcontext(&curthread->tmbx.tm_context, 0,
- (__sighandler_t *)thr_resume_wrapper);
-#else
- if ((curframe == NULL) && (curthread->have_signals != 0))
- signalcontext(&curthread->tmbx.tm_context, 0,
- (__sighandler_t *)thr_resume_wrapper);
-#endif
- /*
- * Continue the thread at its current frame:
- */
- if (curthread->lock_switch != 0) {
- /*
- * This thread came from a scheduler switch; it will
- * unlock the scheduler lock and set the mailbox.
- */
- ret = _thread_switch(&curthread->tmbx, NULL);
- } else {
- /* This thread won't unlock the scheduler lock. */
- KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
- ret = _thread_switch(&curthread->tmbx,
- &curkse->k_mbx.km_curthread);
- }
- if (ret != 0)
- PANIC("Thread has returned from _thread_switch");
-
- /* This point should not be reached. */
- PANIC("Thread has returned from _thread_switch");
-}
-
-static void
-kse_check_signals(struct kse *curkse)
-{
- sigset_t sigset;
- int i;
-
- /* Deliver posted signals. */
- for (i = 0; i < _SIG_WORDS; i++) {
- atomic_swap_int(&curkse->k_mbx.km_sigscaught.__bits[i],
- 0, &sigset.__bits[i]);
- }
- if (SIGNOTEMPTY(sigset)) {
- /*
- * Dispatch each signal.
- *
- * XXX - There is no siginfo for any of these.
- * I think there should be, especially for
- * signals from other processes (si_pid, si_uid).
- */
- for (i = 1; i < NSIG; i++) {
- if (sigismember(&sigset, i) != 0) {
- DBG_MSG("Dispatching signal %d\n", i);
- _thr_sig_dispatch(curkse, i,
- NULL /* no siginfo */);
- }
- }
- sigemptyset(&sigset);
- __sys_sigprocmask(SIG_SETMASK, &sigset, NULL);
- }
-}
-
-static void
-thr_resume_wrapper(int unused_1, siginfo_t *unused_2, ucontext_t *ucp)
-{
- struct pthread *curthread = _get_curthread();
-
- thr_resume_check(curthread, ucp, NULL);
-}
-
-static void
-thr_resume_check(struct pthread *curthread, ucontext_t *ucp,
- struct pthread_sigframe *psf)
-{
- /* Check signals before cancellations. */
- while (curthread->have_signals != 0) {
- /* Clear the pending flag. */
- curthread->have_signals = 0;
-
- /*
- * It's perfectly valid, though not portable, for
- * signal handlers to munge their interrupted context
- * and expect to return to it. Ensure we use the
- * correct context when running down signals.
- */
- _thr_sig_rundown(curthread, ucp, psf);
- }
-
-#ifdef NOT_YET
- if (((curthread->cancelflags & THR_AT_CANCEL_POINT) == 0) &&
- ((curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0))
- pthread_testcancel();
-#endif
-}
-
-/*
- * Clean up a thread. This must be called with the thread's KSE
- * scheduling lock held. The thread must be a thread from the
- * KSE's group.
- */
-static void
-thr_cleanup(struct kse *curkse, struct pthread *thread)
-{
- struct pthread *joiner;
- int sys_scope;
-
- if ((joiner = thread->joiner) != NULL) {
- /* Joinee scheduler lock held; joiner won't leave. */
- if (joiner->kseg == curkse->k_kseg) {
- if (joiner->join_status.thread == thread) {
- joiner->join_status.thread = NULL;
- joiner->join_status.ret = thread->ret;
- _thr_setrunnable_unlocked(joiner);
- }
- } else {
- KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
- /* The joiner may have removed itself and exited. */
- if (_thr_ref_add(thread, joiner, 0) == 0) {
- KSE_SCHED_LOCK(curkse, joiner->kseg);
- if (joiner->join_status.thread == thread) {
- joiner->join_status.thread = NULL;
- joiner->join_status.ret = thread->ret;
- _thr_setrunnable_unlocked(joiner);
- }
- KSE_SCHED_UNLOCK(curkse, joiner->kseg);
- _thr_ref_delete(thread, joiner);
- }
- KSE_SCHED_LOCK(curkse, curkse->k_kseg);
- }
- thread->attr.flags |= PTHREAD_DETACHED;
- }
-
- if (!(sys_scope = (thread->attr.flags & PTHREAD_SCOPE_SYSTEM))) {
- /*
- * Remove the thread from the KSEG's list of threads.
- */
- KSEG_THRQ_REMOVE(thread->kseg, thread);
- /*
- * Migrate the thread to the main KSE so that this
- * KSE and KSEG can be cleaned when their last thread
- * exits.
- */
- thread->kseg = _kse_initial->k_kseg;
- thread->kse = _kse_initial;
- }
- thread->flags |= THR_FLAGS_GC_SAFE;
-
- /*
- * We can't hold the thread list lock while holding the
- * scheduler lock.
- */
- KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
- DBG_MSG("Adding thread %p to GC list\n", thread);
- KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
- THR_GCLIST_ADD(thread);
- /* Use thread_list_lock */
- active_threads--;
- if (active_threads == 0) {
- KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
- exit(0);
- }
- KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
- if (sys_scope) {
- /*
- * System scope thread is single thread group,
- * when thread is exited, its kse and ksegrp should
- * be recycled as well.
- */
- kse_exit();
- PANIC("kse_exit() failed for system scope thread");
- }
- KSE_SCHED_LOCK(curkse, curkse->k_kseg);
-}
-
-void
-_thr_gc(struct pthread *curthread)
-{
- struct pthread *td, *td_next;
- kse_critical_t crit;
- TAILQ_HEAD(, pthread) worklist;
-
- TAILQ_INIT(&worklist);
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &_thread_list_lock);
-
- /* Check the threads waiting for GC. */
- for (td = TAILQ_FIRST(&_thread_gc_list); td != NULL; td = td_next) {
- td_next = TAILQ_NEXT(td, gcle);
- if ((td->flags & THR_FLAGS_GC_SAFE) == 0)
- continue;
- else if (((td->attr.flags & PTHREAD_SCOPE_SYSTEM) != 0) &&
- ((td->kse->k_mbx.km_flags & KMF_DONE) == 0)) {
- /*
- * The thread and KSE are operating on the same
- * stack. Wait for the KSE to exit before freeing
- * the thread's stack as well as everything else.
- */
- continue;
- }
- /*
- * Remove the thread from the GC list. If the thread
- * isn't yet detached, it will get added back to the
- * GC list at a later time.
- */
- THR_GCLIST_REMOVE(td);
- DBG_MSG("Freeing thread %p stack\n", td);
- /*
- * We can free the thread stack since it's no longer
- * in use.
- */
- _thr_stack_free(&td->attr);
- if (((td->attr.flags & PTHREAD_DETACHED) != 0) &&
- (td->refcount == 0)) {
- /*
- * The thread has detached and is no longer
- * referenced. It is safe to remove all
- * remnants of the thread.
- */
- THR_LIST_REMOVE(td);
- TAILQ_INSERT_HEAD(&worklist, td, gcle);
- }
- }
- KSE_LOCK_RELEASE(curthread->kse, &_thread_list_lock);
- _kse_critical_leave(crit);
-
- while ((td = TAILQ_FIRST(&worklist)) != NULL) {
- TAILQ_REMOVE(&worklist, td, gcle);
-
- if ((td->attr.flags & PTHREAD_SCOPE_SYSTEM) != 0) {
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &kse_lock);
- kse_free_unlocked(td->kse);
- kseg_free_unlocked(td->kseg);
- KSE_LOCK_RELEASE(curthread->kse, &kse_lock);
- _kse_critical_leave(crit);
- }
- DBG_MSG("Freeing thread %p\n", td);
- _thr_free(curthread, td);
- }
- /* XXX free kse and ksegrp list should be looked as well */
-}
-
-
-/*
- * Only new threads that are running or suspended may be scheduled.
- */
-int
-_thr_schedule_add(struct pthread *curthread, struct pthread *newthread)
-{
- struct kse *curkse;
- kse_critical_t crit;
- int ret;
-
- /* Add the new thread. */
- thr_link(newthread);
-
- /*
- * If this is the first time creating a thread, make sure
- * the mailbox is set for the current thread.
- */
- if ((newthread->attr.flags & PTHREAD_SCOPE_SYSTEM) != 0) {
-#ifdef NOT_YET
- /* We use the thread's stack as the KSE's stack. */
- new_thread->kse->k_mbx.km_stack.ss_sp =
- new_thread->attr.stackaddr_attr;
- new_thread->kse->k_mbx.km_stack.ss_size =
- new_thread->attr.stacksize_attr;
-#endif
- /*
- * No need to lock the scheduling queue since the
- * KSE/KSEG pair have not yet been started.
- */
- KSEG_THRQ_ADD(newthread->kseg, newthread);
- if (newthread->state == PS_RUNNING)
- THR_RUNQ_INSERT_TAIL(newthread);
- newthread->kse->k_curthread = NULL;
- newthread->kse->k_mbx.km_flags = 0;
- newthread->kse->k_mbx.km_func = (kse_func_t *)kse_sched_multi;
- newthread->kse->k_mbx.km_quantum = 0;
-
- /*
- * This thread needs a new KSE and KSEG.
- */
- crit = _kse_critical_enter();
- curkse = _get_curkse();
- _ksd_setprivate(&newthread->kse->k_ksd);
- newthread->kse->k_flags |= KF_INITIALIZED|KF_STARTED;
- ret = kse_create(&newthread->kse->k_mbx, 1);
- if (ret != 0)
- ret = errno;
- _ksd_setprivate(&curkse->k_ksd);
- _kse_critical_leave(crit);
- }
- else {
- /*
- * Lock the KSE and add the new thread to its list of
- * assigned threads. If the new thread is runnable, also
- * add it to the KSE's run queue.
- */
- KSE_SCHED_LOCK(curthread->kse, newthread->kseg);
- KSEG_THRQ_ADD(newthread->kseg, newthread);
- if (newthread->state == PS_RUNNING)
- THR_RUNQ_INSERT_TAIL(newthread);
- if ((newthread->kse->k_flags & KF_STARTED) == 0) {
- /*
- * This KSE hasn't been started yet. Start it
- * outside of holding the lock.
- */
- newthread->kse->k_flags |= KF_STARTED;
- newthread->kse->k_mbx.km_func =
- (kse_func_t *)kse_sched_multi;
- newthread->kse->k_mbx.km_flags = 0;
- kse_create(&newthread->kse->k_mbx, 0);
- } else if ((newthread->state == PS_RUNNING) &&
- KSE_IS_IDLE(newthread->kse)) {
- /*
- * The thread is being scheduled on another KSEG.
- */
- kse_wakeup_one(newthread);
- }
- KSE_SCHED_UNLOCK(curthread->kse, newthread->kseg);
- ret = 0;
- }
- if (ret != 0)
- thr_unlink(newthread);
-
- return (ret);
-}
-
-void
-kse_waitq_insert(struct pthread *thread)
-{
- struct pthread *td;
-
- if (thread->wakeup_time.tv_sec == -1)
- TAILQ_INSERT_TAIL(&thread->kse->k_schedq->sq_waitq, thread,
- pqe);
- else {
- td = TAILQ_FIRST(&thread->kse->k_schedq->sq_waitq);
- while ((td != NULL) && (td->wakeup_time.tv_sec != -1) &&
- ((td->wakeup_time.tv_sec < thread->wakeup_time.tv_sec) ||
- ((td->wakeup_time.tv_sec == thread->wakeup_time.tv_sec) &&
- (td->wakeup_time.tv_nsec <= thread->wakeup_time.tv_nsec))))
- td = TAILQ_NEXT(td, pqe);
- if (td == NULL)
- TAILQ_INSERT_TAIL(&thread->kse->k_schedq->sq_waitq,
- thread, pqe);
- else
- TAILQ_INSERT_BEFORE(td, thread, pqe);
- }
- thread->flags |= THR_FLAGS_IN_WAITQ;
-}
-
-/*
- * This must be called with the scheduling lock held.
- */
-static void
-kse_check_completed(struct kse *kse)
-{
- struct pthread *thread;
- struct kse_thr_mailbox *completed;
-
- if ((completed = kse->k_mbx.km_completed) != NULL) {
- kse->k_mbx.km_completed = NULL;
- while (completed != NULL) {
- thread = completed->tm_udata;
- DBG_MSG("Found completed thread %p, name %s\n",
- thread,
- (thread->name == NULL) ? "none" : thread->name);
- thread->blocked = 0;
- if (thread != kse->k_curthread) {
- if ((thread->flags & THR_FLAGS_SUSPENDED) != 0)
- THR_SET_STATE(thread, PS_SUSPENDED);
- else
- KSE_RUNQ_INSERT_TAIL(kse, thread);
- if ((thread->kse != kse) &&
- (thread->kse->k_curthread == thread)) {
- thread->kse->k_curthread = NULL;
- thread->active = 0;
- }
- }
- completed = completed->tm_next;
- }
- }
-}
-
-/*
- * This must be called with the scheduling lock held.
- */
-static void
-kse_check_waitq(struct kse *kse)
-{
- struct pthread *pthread;
- struct timespec ts;
-
- KSE_GET_TOD(kse, &ts);
-
- /*
- * Wake up threads that have timedout. This has to be
- * done before adding the current thread to the run queue
- * so that a CPU intensive thread doesn't get preference
- * over waiting threads.
- */
- while (((pthread = KSE_WAITQ_FIRST(kse)) != NULL) &&
- thr_timedout(pthread, &ts)) {
- /* Remove the thread from the wait queue: */
- KSE_WAITQ_REMOVE(kse, pthread);
- DBG_MSG("Found timedout thread %p in waitq\n", pthread);
-
- /* Indicate the thread timedout: */
- pthread->timeout = 1;
-
- /* Add the thread to the priority queue: */
- if ((pthread->flags & THR_FLAGS_SUSPENDED) != 0)
- THR_SET_STATE(pthread, PS_SUSPENDED);
- else {
- THR_SET_STATE(pthread, PS_RUNNING);
- KSE_RUNQ_INSERT_TAIL(kse, pthread);
- }
- }
-}
-
-static int
-thr_timedout(struct pthread *thread, struct timespec *curtime)
-{
- if (thread->wakeup_time.tv_sec < 0)
- return (0);
- else if (thread->wakeup_time.tv_sec > curtime->tv_sec)
- return (0);
- else if ((thread->wakeup_time.tv_sec == curtime->tv_sec) &&
- (thread->wakeup_time.tv_nsec > curtime->tv_nsec))
- return (0);
- else
- return (1);
-}
-
-/*
- * This must be called with the scheduling lock held.
- *
- * Each thread has a time slice, a wakeup time (used when it wants
- * to wait for a specified amount of time), a run state, and an
- * active flag.
- *
- * When a thread gets run by the scheduler, the active flag is
- * set to non-zero (1). When a thread performs an explicit yield
- * or schedules a state change, it enters the scheduler and the
- * active flag is cleared. When the active flag is still seen
- * set in the scheduler, that means that the thread is blocked in
- * the kernel (because it is cleared before entering the scheduler
- * in all other instances).
- *
- * The wakeup time is only set for those states that can timeout.
- * It is set to (-1, -1) for all other instances.
- *
- * The thread's run state, aside from being useful when debugging,
- * is used to place the thread in an appropriate queue. There
- * are 2 basic queues:
- *
- * o run queue - queue ordered by priority for all threads
- * that are runnable
- * o waiting queue - queue sorted by wakeup time for all threads
- * that are not otherwise runnable (not blocked
- * in kernel, not waiting for locks)
- *
- * The thread's time slice is used for round-robin scheduling
- * (the default scheduling policy). While a SCHED_RR thread
- * is runnable it's time slice accumulates. When it reaches
- * the time slice interval, it gets reset and added to the end
- * of the queue of threads at its priority. When a thread no
- * longer becomes runnable (blocks in kernel, waits, etc), its
- * time slice is reset.
- *
- * The job of kse_switchout_thread() is to handle all of the above.
- */
-static void
-kse_switchout_thread(struct kse *kse, struct pthread *thread)
-{
- int level;
- int i;
-
- /*
- * Place the currently running thread into the
- * appropriate queue(s).
- */
- DBG_MSG("Switching out thread %p, state %d\n", thread, thread->state);
-
- THR_DEACTIVATE_LAST_LOCK(thread);
- if (thread->blocked != 0) {
- thread->active = 0;
- thread->need_switchout = 0;
- /* This thread must have blocked in the kernel. */
- /* thread->slice_usec = -1;*/ /* restart timeslice */
- /*
- * XXX - Check for pending signals for this thread to
- * see if we need to interrupt it in the kernel.
- */
- /* if (thread->check_pending != 0) */
- if ((thread->slice_usec != -1) &&
- (thread->attr.sched_policy != SCHED_FIFO))
- thread->slice_usec += (thread->tmbx.tm_uticks
- + thread->tmbx.tm_sticks) * _clock_res_usec;
- }
- else {
- switch (thread->state) {
- case PS_DEAD:
- /*
- * The scheduler is operating on a different
- * stack. It is safe to do garbage collecting
- * here.
- */
- thread->active = 0;
- thread->need_switchout = 0;
- thr_cleanup(kse, thread);
- return;
- break;
-
- case PS_RUNNING:
- if ((thread->flags & THR_FLAGS_SUSPENDED) != 0)
- THR_SET_STATE(thread, PS_SUSPENDED);
- break;
-
- case PS_COND_WAIT:
- case PS_SLEEP_WAIT:
- /* Insert into the waiting queue: */
- KSE_WAITQ_INSERT(kse, thread);
- break;
-
- case PS_LOCKWAIT:
- /*
- * This state doesn't timeout.
- */
- thread->wakeup_time.tv_sec = -1;
- thread->wakeup_time.tv_nsec = -1;
- level = thread->locklevel - 1;
- if (!_LCK_GRANTED(&thread->lockusers[level]))
- KSE_WAITQ_INSERT(kse, thread);
- else
- THR_SET_STATE(thread, PS_RUNNING);
- break;
-
- case PS_JOIN:
- case PS_MUTEX_WAIT:
- case PS_SIGSUSPEND:
- case PS_SIGWAIT:
- case PS_SUSPENDED:
- case PS_DEADLOCK:
- default:
- /*
- * These states don't timeout.
- */
- thread->wakeup_time.tv_sec = -1;
- thread->wakeup_time.tv_nsec = -1;
-
- /* Insert into the waiting queue: */
- KSE_WAITQ_INSERT(kse, thread);
- break;
- }
- if (thread->state != PS_RUNNING) {
- /* Restart the time slice: */
- thread->slice_usec = -1;
- } else {
- if (thread->need_switchout != 0)
- /*
- * The thread yielded on its own;
- * restart the timeslice.
- */
- thread->slice_usec = -1;
- else if ((thread->slice_usec != -1) &&
- (thread->attr.sched_policy != SCHED_FIFO)) {
- thread->slice_usec += (thread->tmbx.tm_uticks
- + thread->tmbx.tm_sticks) * _clock_res_usec;
- /* Check for time quantum exceeded: */
- if (thread->slice_usec > TIMESLICE_USEC)
- thread->slice_usec = -1;
- }
- if (thread->slice_usec == -1) {
- /*
- * The thread exceeded its time quantum or
- * it yielded the CPU; place it at the tail
- * of the queue for its priority.
- */
- KSE_RUNQ_INSERT_TAIL(kse, thread);
- } else {
- /*
- * The thread hasn't exceeded its interval
- * Place it at the head of the queue for its
- * priority.
- */
- KSE_RUNQ_INSERT_HEAD(kse, thread);
- }
- }
- }
- thread->active = 0;
- thread->need_switchout = 0;
- if (thread->check_pending != 0) {
- /* Install pending signals into the frame. */
- thread->check_pending = 0;
- for (i = 0; i < _SIG_MAXSIG; i++) {
- if (sigismember(&thread->sigpend, i) &&
- !sigismember(&thread->tmbx.tm_context.uc_sigmask, i))
- _thr_sig_add(thread, i, &thread->siginfo[i]);
- }
- }
-}
-
-/*
- * This function waits for the smallest timeout value of any waiting
- * thread, or until it receives a message from another KSE.
- *
- * This must be called with the scheduling lock held.
- */
-static void
-kse_wait(struct kse *kse, struct pthread *td_wait)
-{
- struct timespec ts, ts_sleep;
- int saved_flags;
-
- KSE_GET_TOD(kse, &ts);
-
- if ((td_wait == NULL) || (td_wait->wakeup_time.tv_sec < 0)) {
- /* Limit sleep to no more than 1 minute. */
- ts_sleep.tv_sec = 60;
- ts_sleep.tv_nsec = 0;
- } else {
- TIMESPEC_SUB(&ts_sleep, &td_wait->wakeup_time, &ts);
- if (ts_sleep.tv_sec > 60) {
- ts_sleep.tv_sec = 60;
- ts_sleep.tv_nsec = 0;
- }
- }
- /* Don't sleep for negative times. */
- if ((ts_sleep.tv_sec >= 0) && (ts_sleep.tv_nsec >= 0)) {
- KSE_SET_IDLE(kse);
- kse->k_kseg->kg_idle_kses++;
- KSE_SCHED_UNLOCK(kse, kse->k_kseg);
- saved_flags = kse->k_mbx.km_flags;
- kse->k_mbx.km_flags |= KMF_NOUPCALL;
- kse_release(&ts_sleep);
- kse->k_mbx.km_flags = saved_flags;
- KSE_SCHED_LOCK(kse, kse->k_kseg);
- if (KSE_IS_IDLE(kse)) {
- KSE_CLEAR_IDLE(kse);
- kse->k_kseg->kg_idle_kses--;
- }
- }
-}
-
-/*
- * Avoid calling this kse_exit() so as not to confuse it with the
- * system call of the same name.
- */
-static void
-kse_fini(struct kse *kse)
-{
- /* struct kse_group *free_kseg = NULL; */
- struct timespec ts;
-
- /*
- * Check to see if this is one of the main kses.
- */
- if (kse->k_kseg != _kse_initial->k_kseg) {
- PANIC("shouldn't get here");
- /* This is for supporting thread groups. */
-#ifdef NOT_YET
- /* Remove this KSE from the KSEG's list of KSEs. */
- KSE_SCHED_LOCK(kse, kse->k_kseg);
- TAILQ_REMOVE(&kse->k_kseg->kg_kseq, kse, k_kgqe);
- kse->k_kseg->kg_ksecount--;
- if (TAILQ_EMPTY(&kse->k_kseg->kg_kseq))
- free_kseg = kse->k_kseg;
- KSE_SCHED_UNLOCK(kse, kse->k_kseg);
-
- /*
- * Add this KSE to the list of free KSEs along with
- * the KSEG if is now orphaned.
- */
- KSE_LOCK_ACQUIRE(kse, &kse_lock);
- if (free_kseg != NULL)
- kseg_free_unlocked(free_kseg);
- kse_free_unlocked(kse);
- KSE_LOCK_RELEASE(kse, &kse_lock);
- kse_exit();
- /* Never returns. */
- PANIC("kse_exit()");
-#endif
- } else {
-#ifdef NOT_YET
- /*
- * In future, we might allow program to kill
- * kse in initial group.
- */
- if (kse != _kse_initial) {
- KSE_SCHED_LOCK(kse, kse->k_kseg);
- TAILQ_REMOVE(&kse->k_kseg->kg_kseq, kse, k_kgqe);
- kse->k_kseg->kg_ksecount--;
- KSE_SCHED_UNLOCK(kse, kse->k_kseg);
- KSE_LOCK_ACQUIRE(kse, &kse_lock);
- kse_free_unlocked(kse);
- KSE_LOCK_RELEASE(kse, &kse_lock);
- kse_exit();
- /* Never returns. */
- PANIC("kse_exit() failed for initial kseg");
- }
-#endif
- KSE_SCHED_LOCK(kse, kse->k_kseg);
- KSE_SET_IDLE(kse);
- kse->k_kseg->kg_idle_kses++;
- KSE_SCHED_UNLOCK(kse, kse->k_kseg);
- ts.tv_sec = 120;
- ts.tv_nsec = 0;
- kse->k_mbx.km_flags = 0;
- kse_release(&ts);
- /* Never reach */
- }
-}
-
-void
-_thr_set_timeout(const struct timespec *timeout)
-{
- struct pthread *curthread = _get_curthread();
- struct timespec ts;
-
- /* Reset the timeout flag for the running thread: */
- curthread->timeout = 0;
-
- /* Check if the thread is to wait forever: */
- if (timeout == NULL) {
- /*
- * Set the wakeup time to something that can be recognised as
- * different to an actual time of day:
- */
- curthread->wakeup_time.tv_sec = -1;
- curthread->wakeup_time.tv_nsec = -1;
- }
- /* Check if no waiting is required: */
- else if ((timeout->tv_sec == 0) && (timeout->tv_nsec == 0)) {
- /* Set the wake up time to 'immediately': */
- curthread->wakeup_time.tv_sec = 0;
- curthread->wakeup_time.tv_nsec = 0;
- } else {
- /* Calculate the time for the current thread to wakeup: */
- KSE_GET_TOD(curthread->kse, &ts);
- TIMESPEC_ADD(&curthread->wakeup_time, &ts, timeout);
- }
-}
-
-void
-_thr_panic_exit(char *file, int line, char *msg)
-{
- char buf[256];
-
- snprintf(buf, sizeof(buf), "(%s:%d) %s\n", file, line, msg);
- __sys_write(2, buf, strlen(buf));
- abort();
-}
-
-void
-_thr_setrunnable(struct pthread *curthread, struct pthread *thread)
-{
- kse_critical_t crit;
-
- crit = _kse_critical_enter();
- KSE_SCHED_LOCK(curthread->kse, thread->kseg);
- _thr_setrunnable_unlocked(thread);
- KSE_SCHED_UNLOCK(curthread->kse, thread->kseg);
- _kse_critical_leave(crit);
-}
-
-void
-_thr_setrunnable_unlocked(struct pthread *thread)
-{
- if ((thread->kseg->kg_flags & KGF_SINGLE_THREAD) != 0) {
- /* No silly queues for these threads. */
- if ((thread->flags & THR_FLAGS_SUSPENDED) != 0)
- THR_SET_STATE(thread, PS_SUSPENDED);
- else
- THR_SET_STATE(thread, PS_RUNNING);
- } else if (thread->state != PS_RUNNING) {
- if ((thread->flags & THR_FLAGS_IN_WAITQ) != 0)
- KSE_WAITQ_REMOVE(thread->kse, thread);
- if ((thread->flags & THR_FLAGS_SUSPENDED) != 0)
- THR_SET_STATE(thread, PS_SUSPENDED);
- else {
- THR_SET_STATE(thread, PS_RUNNING);
- if ((thread->blocked == 0) && (thread->active == 0) &&
- (thread->flags & THR_FLAGS_IN_RUNQ) == 0)
- THR_RUNQ_INSERT_TAIL(thread);
- }
- }
- /*
- * XXX - Threads are not yet assigned to specific KSEs; they are
- * assigned to the KSEG. So the fact that a thread's KSE is
- * waiting doesn't necessarily mean that it will be the KSE
- * that runs the thread after the lock is granted. But we
- * don't know if the other KSEs within the same KSEG are
- * also in a waiting state or not so we err on the side of
- * caution and wakeup the thread's last known KSE. We
- * ensure that the threads KSE doesn't change while it's
- * scheduling lock is held so it is safe to reference it
- * (the KSE). If the KSE wakes up and doesn't find any more
- * work it will again go back to waiting so no harm is done.
- */
- kse_wakeup_one(thread);
-}
-
-static void
-kse_wakeup_one(struct pthread *thread)
-{
- struct kse *ke;
-
- if (KSE_IS_IDLE(thread->kse)) {
- KSE_CLEAR_IDLE(thread->kse);
- thread->kseg->kg_idle_kses--;
- KSE_WAKEUP(thread->kse);
- } else {
- TAILQ_FOREACH(ke, &thread->kseg->kg_kseq, k_kgqe) {
- if (KSE_IS_IDLE(ke)) {
- KSE_CLEAR_IDLE(ke);
- ke->k_kseg->kg_idle_kses--;
- KSE_WAKEUP(ke);
- return;
- }
- }
- }
-}
-
-static void
-kse_wakeup_multi(struct kse *curkse)
-{
- struct kse *ke;
- int tmp;
-
- if ((tmp = KSE_RUNQ_THREADS(curkse)) && curkse->k_kseg->kg_idle_kses) {
- TAILQ_FOREACH(ke, &curkse->k_kseg->kg_kseq, k_kgqe) {
- if (KSE_IS_IDLE(ke)) {
- KSE_CLEAR_IDLE(ke);
- ke->k_kseg->kg_idle_kses--;
- KSE_WAKEUP(ke);
- if (--tmp == 0)
- break;
- }
- }
- }
-}
-
-struct pthread *
-_get_curthread(void)
-{
- return (_ksd_curthread);
-}
-
-/* This assumes the caller has disabled upcalls. */
-struct kse *
-_get_curkse(void)
-{
- return (_ksd_curkse);
-}
-
-void
-_set_curkse(struct kse *kse)
-{
- _ksd_setprivate(&kse->k_ksd);
-}
-
-/*
- * Allocate a new KSEG.
- *
- * We allow the current thread to be NULL in the case that this
- * is the first time a KSEG is being created (library initialization).
- * In this case, we don't need to (and can't) take any locks.
- */
-struct kse_group *
-_kseg_alloc(struct pthread *curthread)
-{
- struct kse_group *kseg = NULL;
- kse_critical_t crit;
-
- if ((curthread != NULL) && (free_kseg_count > 0)) {
- /* Use the kse lock for the kseg queue. */
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &kse_lock);
- if ((kseg = TAILQ_FIRST(&free_kse_groupq)) != NULL) {
- TAILQ_REMOVE(&free_kse_groupq, kseg, kg_qe);
- free_kseg_count--;
- active_kseg_count++;
- TAILQ_INSERT_TAIL(&active_kse_groupq, kseg, kg_qe);
- }
- KSE_LOCK_RELEASE(curthread->kse, &kse_lock);
- _kse_critical_leave(crit);
- if (kseg)
- kseg_reinit(kseg);
- }
-
- /*
- * If requested, attempt to allocate a new KSE group only if the
- * KSE allocation was successful and a KSE group wasn't found in
- * the free list.
- */
- if ((kseg == NULL) &&
- ((kseg = (struct kse_group *)malloc(sizeof(*kseg))) != NULL)) {
- if (_pq_alloc(&kseg->kg_schedq.sq_runq,
- THR_MIN_PRIORITY, THR_LAST_PRIORITY) != 0) {
- free(kseg);
- kseg = NULL;
- } else {
- kseg_init(kseg);
- /* Add the KSEG to the list of active KSEGs. */
- if (curthread != NULL) {
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &kse_lock);
- active_kseg_count++;
- TAILQ_INSERT_TAIL(&active_kse_groupq,
- kseg, kg_qe);
- KSE_LOCK_RELEASE(curthread->kse, &kse_lock);
- _kse_critical_leave(crit);
- } else {
- active_kseg_count++;
- TAILQ_INSERT_TAIL(&active_kse_groupq,
- kseg, kg_qe);
- }
- }
- }
- return (kseg);
-}
-
-/*
- * This must be called with the kse lock held and when there are
- * no more threads that reference it.
- */
-static void
-kseg_free_unlocked(struct kse_group *kseg)
-{
- TAILQ_REMOVE(&active_kse_groupq, kseg, kg_qe);
- TAILQ_INSERT_HEAD(&free_kse_groupq, kseg, kg_qe);
- free_kseg_count++;
- active_kseg_count--;
-}
-
-void
-_kseg_free(struct kse_group *kseg)
-{
- struct kse *curkse;
- kse_critical_t crit;
-
- crit = _kse_critical_enter();
- curkse = _get_curkse();
- KSE_LOCK_ACQUIRE(curkse, &kse_lock);
- kseg_free_unlocked(kseg);
- KSE_LOCK_RELEASE(curkse, &kse_lock);
- _kse_critical_leave(crit);
-}
-
-/*
- * Allocate a new KSE.
- *
- * We allow the current thread to be NULL in the case that this
- * is the first time a KSE is being created (library initialization).
- * In this case, we don't need to (and can't) take any locks.
- */
-struct kse *
-_kse_alloc(struct pthread *curthread)
-{
- struct kse *kse = NULL;
- kse_critical_t crit;
- int need_ksd = 0;
- int i;
-
- if ((curthread != NULL) && (free_kse_count > 0)) {
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &kse_lock);
- /* Search for a finished KSE. */
- kse = TAILQ_FIRST(&free_kseq);
- while ((kse != NULL) &&
- ((kse->k_mbx.km_flags & KMF_DONE) == 0)) {
- kse = TAILQ_NEXT(kse, k_qe);
- }
- if (kse != NULL) {
- DBG_MSG("found an unused kse.\n");
- TAILQ_REMOVE(&free_kseq, kse, k_qe);
- free_kse_count--;
- TAILQ_INSERT_TAIL(&active_kseq, kse, k_qe);
- active_kse_count++;
- }
- KSE_LOCK_RELEASE(curthread->kse, &kse_lock);
- _kse_critical_leave(crit);
- if (kse != NULL)
- kse_reinit(kse);
- }
- if ((kse == NULL) &&
- ((kse = (struct kse *)malloc(sizeof(*kse))) != NULL)) {
- bzero(kse, sizeof(*kse));
-
- /* Initialize the lockusers. */
- for (i = 0; i < MAX_KSE_LOCKLEVEL; i++) {
- _lockuser_init(&kse->k_lockusers[i], (void *)kse);
- _LCK_SET_PRIVATE2(&kse->k_lockusers[i], NULL);
- }
- /* _lock_init(kse->k_lock, ...) */
-
- /* We had to malloc a kse; mark it as needing a new ID.*/
- need_ksd = 1;
-
- /*
- * Create the KSE context.
- *
- * XXX - For now this is done here in the allocation.
- * In the future, we may want to have it done
- * outside the allocation so that scope system
- * threads (one thread per KSE) are not required
- * to have a stack for an unneeded kse upcall.
- */
- kse->k_mbx.km_func = (kse_func_t *)kse_sched_multi;
- kse->k_mbx.km_stack.ss_sp = (char *)malloc(KSE_STACKSIZE);
- kse->k_mbx.km_stack.ss_size = KSE_STACKSIZE;
- kse->k_mbx.km_udata = (void *)kse;
- kse->k_mbx.km_quantum = 20000;
- /*
- * We need to keep a copy of the stack in case it
- * doesn't get used; a KSE running a scope system
- * thread will use that thread's stack.
- */
- kse->k_stack.ss_sp = kse->k_mbx.km_stack.ss_sp;
- kse->k_stack.ss_size = kse->k_mbx.km_stack.ss_size;
- if (kse->k_mbx.km_stack.ss_sp == NULL) {
- for (i = 0; i < MAX_KSE_LOCKLEVEL; i++) {
- _lockuser_destroy(&kse->k_lockusers[i]);
- }
- /* _lock_destroy(&kse->k_lock); */
- free(kse);
- kse = NULL;
- }
- }
- if ((kse != NULL) && (need_ksd != 0)) {
- /* This KSE needs initialization. */
- if (curthread != NULL) {
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &kse_lock);
- }
- /* Initialize KSD inside of the lock. */
- if (_ksd_create(&kse->k_ksd, (void *)kse, sizeof(*kse)) != 0) {
- if (curthread != NULL) {
- KSE_LOCK_RELEASE(curthread->kse, &kse_lock);
- _kse_critical_leave(crit);
- }
- free(kse->k_mbx.km_stack.ss_sp);
- for (i = 0; i < MAX_KSE_LOCKLEVEL; i++) {
- _lockuser_destroy(&kse->k_lockusers[i]);
- }
- free(kse);
- return (NULL);
- }
- kse->k_flags = 0;
- TAILQ_INSERT_TAIL(&active_kseq, kse, k_qe);
- active_kse_count++;
- if (curthread != NULL) {
- KSE_LOCK_RELEASE(curthread->kse, &kse_lock);
- _kse_critical_leave(crit);
- }
- }
- return (kse);
-}
-
-static void
-kse_reinit(struct kse *kse)
-{
- /*
- * XXX - For now every kse has its stack.
- * In the future, we may want to have it done
- * outside the allocation so that scope system
- * threads (one thread per KSE) are not required
- * to have a stack for an unneeded kse upcall.
- */
- kse->k_mbx.km_flags = 0;
- kse->k_curthread = 0;
- kse->k_kseg = 0;
- kse->k_schedq = 0;
- kse->k_locklevel = 0;
- sigemptyset(&kse->k_sigmask);
- bzero(&kse->k_sigq, sizeof(kse->k_sigq));
- kse->k_check_sigq = 0;
- kse->k_flags = 0;
- kse->k_waiting = 0;
- kse->k_idle = 0;
- kse->k_error = 0;
- kse->k_cpu = 0;
- kse->k_done = 0;
-}
-
-void
-kse_free_unlocked(struct kse *kse)
-{
- TAILQ_REMOVE(&active_kseq, kse, k_qe);
- active_kse_count--;
- kse->k_kseg = NULL;
- kse->k_mbx.km_quantum = 20000;
- kse->k_flags = 0;
- TAILQ_INSERT_HEAD(&free_kseq, kse, k_qe);
- free_kse_count++;
-}
-
-void
-_kse_free(struct pthread *curthread, struct kse *kse)
-{
- kse_critical_t crit;
-
- if (curthread == NULL)
- kse_free_unlocked(kse);
- else {
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &kse_lock);
- kse_free_unlocked(kse);
- KSE_LOCK_RELEASE(curthread->kse, &kse_lock);
- _kse_critical_leave(crit);
- }
-}
-
-static void
-kseg_init(struct kse_group *kseg)
-{
- kseg_reinit(kseg);
- _lock_init(&kseg->kg_lock, LCK_ADAPTIVE, _kse_lock_wait,
- _kse_lock_wakeup);
-}
-
-static void
-kseg_reinit(struct kse_group *kseg)
-{
- TAILQ_INIT(&kseg->kg_kseq);
- TAILQ_INIT(&kseg->kg_threadq);
- TAILQ_INIT(&kseg->kg_schedq.sq_waitq);
- kseg->kg_threadcount = 0;
- kseg->kg_ksecount = 0;
- kseg->kg_idle_kses = 0;
- kseg->kg_flags = 0;
-}
-
-struct pthread *
-_thr_alloc(struct pthread *curthread)
-{
- kse_critical_t crit;
- void *p;
- struct pthread *thread = NULL;
-
- if (curthread != NULL) {
- if (GC_NEEDED())
- _thr_gc(curthread);
- if (free_thread_count > 0) {
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &thread_lock);
- if ((thread = TAILQ_FIRST(&free_threadq)) != NULL) {
- TAILQ_REMOVE(&free_threadq, thread, tle);
- free_thread_count--;
- }
- KSE_LOCK_RELEASE(curthread->kse, &thread_lock);
- _kse_critical_leave(crit);
- }
- }
- if (thread == NULL) {
- p = malloc(sizeof(struct pthread) + THR_ALIGNBYTES);
- if (p != NULL) {
- thread = (struct pthread *)THR_ALIGN(p);
- thread->alloc_addr = p;
- }
- }
- return (thread);
-}
-
-void
-_thr_free(struct pthread *curthread, struct pthread *thread)
-{
- kse_critical_t crit;
- int i;
-
- DBG_MSG("Freeing thread %p\n", thread);
- if ((curthread == NULL) || (free_thread_count >= MAX_CACHED_THREADS)) {
- for (i = 0; i < MAX_THR_LOCKLEVEL; i++) {
- _lockuser_destroy(&thread->lockusers[i]);
- }
- _lock_destroy(&thread->lock);
- free(thread->alloc_addr);
- }
- else {
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &thread_lock);
- TAILQ_INSERT_HEAD(&free_threadq, thread, tle);
- free_thread_count++;
- KSE_LOCK_RELEASE(curthread->kse, &thread_lock);
- _kse_critical_leave(crit);
- }
-}
-
-/*
- * Add an active thread:
- *
- * o Assign the thread a unique id (which GDB uses to track
- * threads.
- * o Add the thread to the list of all threads and increment
- * number of active threads.
- */
-static void
-thr_link(struct pthread *thread)
-{
- kse_critical_t crit;
- struct kse *curkse;
-
- crit = _kse_critical_enter();
- curkse = _get_curkse();
-
- KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
- /*
- * Initialize the unique id (which GDB uses to track
- * threads), add the thread to the list of all threads,
- * and
- */
- thread->uniqueid = next_uniqueid++;
- THR_LIST_ADD(thread);
- active_threads++;
- KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
-
- _kse_critical_leave(crit);
-}
-
-/*
- * Remove an active thread.
- */
-static void
-thr_unlink(struct pthread *thread)
-{
- kse_critical_t crit;
- struct kse *curkse;
-
- crit = _kse_critical_enter();
- curkse = _get_curkse();
-
- KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
- THR_LIST_REMOVE(thread);
- active_threads--;
- KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
-
- _kse_critical_leave(crit);
-}
diff --git a/lib/libkse/thread/thr_kill.c b/lib/libkse/thread/thr_kill.c
deleted file mode 100644
index 19f34bb4396b..000000000000
--- a/lib/libkse/thread/thr_kill.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <signal.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_kill, pthread_kill);
-
-int
-_pthread_kill(pthread_t pthread, int sig)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- /* Check for invalid signal numbers: */
- if (sig < 0 || sig >= NSIG)
- /* Invalid signal: */
- ret = EINVAL;
- /*
- * Ensure the thread is in the list of active threads, and the
- * signal is valid (signal 0 specifies error checking only) and
- * not being ignored:
- */
- else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0))
- == 0) {
- if ((sig > 0) &&
- (_thread_sigact[sig - 1].sa_handler != SIG_IGN))
- _thr_sig_send(pthread, sig);
- _thr_ref_delete(curthread, pthread);
- }
-
- /* Return the completion status: */
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_main_np.c b/lib/libkse/thread/thr_main_np.c
deleted file mode 100644
index 0dacd4804c62..000000000000
--- a/lib/libkse/thread/thr_main_np.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2001 Alfred Perlstein
- * Author: Alfred Perlstein <alfred@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <pthread.h>
-#include <pthread_np.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_main_np, pthread_main_np);
-
-/*
- * Provide the equivelant to Solaris thr_main() function
- */
-int
-_pthread_main_np()
-{
-
- if (!_thr_initial)
- return (-1);
- else
- return (pthread_equal(pthread_self(), _thr_initial) ? 1 : 0);
-}
diff --git a/lib/libkse/thread/thr_mattr_init.c b/lib/libkse/thread/thr_mattr_init.c
deleted file mode 100644
index d5a7a1898aa7..000000000000
--- a/lib/libkse/thread/thr_mattr_init.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 1996 Jeffrey Hsu <hsu@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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_mutexattr_init, pthread_mutexattr_init);
-
-int
-_pthread_mutexattr_init(pthread_mutexattr_t *attr)
-{
- int ret;
- pthread_mutexattr_t pattr;
-
- if ((pattr = (pthread_mutexattr_t)
- malloc(sizeof(struct pthread_mutex_attr))) == NULL) {
- ret = ENOMEM;
- } else {
- memcpy(pattr, &_pthread_mutexattr_default,
- sizeof(struct pthread_mutex_attr));
- *attr = pattr;
- ret = 0;
- }
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_mattr_kind_np.c b/lib/libkse/thread/thr_mattr_kind_np.c
deleted file mode 100644
index f3d30ff075b7..000000000000
--- a/lib/libkse/thread/thr_mattr_kind_np.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (c) 1996 Jeffrey Hsu <hsu@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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_mutexattr_setkind_np, pthread_mutexattr_setkind_np);
-__weak_reference(_pthread_mutexattr_getkind_np, pthread_mutexattr_getkind_np);
-__weak_reference(_pthread_mutexattr_gettype, pthread_mutexattr_gettype);
-__weak_reference(_pthread_mutexattr_settype, pthread_mutexattr_settype);
-
-int
-_pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind)
-{
- int ret;
- if (attr == NULL || *attr == NULL) {
- errno = EINVAL;
- ret = -1;
- } else {
- (*attr)->m_type = kind;
- ret = 0;
- }
- return(ret);
-}
-
-int
-_pthread_mutexattr_getkind_np(pthread_mutexattr_t attr)
-{
- int ret;
- if (attr == NULL) {
- errno = EINVAL;
- ret = -1;
- } else {
- ret = attr->m_type;
- }
- return(ret);
-}
-
-int
-_pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
-{
- int ret;
- if (attr == NULL || *attr == NULL || type >= MUTEX_TYPE_MAX) {
- errno = EINVAL;
- ret = -1;
- } else {
- (*attr)->m_type = type;
- ret = 0;
- }
- return(ret);
-}
-
-int
-_pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type)
-{
- int ret;
-
- if (attr == NULL || *attr == NULL || (*attr)->m_type >=
- MUTEX_TYPE_MAX) {
- ret = EINVAL;
- } else {
- *type = (*attr)->m_type;
- ret = 0;
- }
- return ret;
-}
diff --git a/lib/libkse/thread/thr_msync.c b/lib/libkse/thread/thr_msync.c
deleted file mode 100644
index 24b78ecbacdf..000000000000
--- a/lib/libkse/thread/thr_msync.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * David Leonard <d@openbsd.org>, 1999. Public Domain.
- *
- * $OpenBSD: uthread_msync.c,v 1.2 1999/06/09 07:16:17 d Exp $
- *
- * $FreeBSD$
- */
-
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__msync, msync);
-
-int
-__msync(void *addr, size_t len, int flags)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- /*
- * XXX This is quite pointless unless we know how to get the
- * file descriptor associated with the memory, and lock it for
- * write. The only real use of this wrapper is to guarantee
- * a cancellation point, as per the standard. sigh.
- */
- _thr_enter_cancellation_point(curthread);
- ret = __sys_msync(addr, len, flags);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_multi_np.c b/lib/libkse/thread/thr_multi_np.c
deleted file mode 100644
index bd42365621a6..000000000000
--- a/lib/libkse/thread/thr_multi_np.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <pthread.h>
-#include <pthread_np.h>
-
-__weak_reference(_pthread_multi_np, pthread_multi_np);
-
-int
-_pthread_multi_np()
-{
-
- /* Return to multi-threaded scheduling mode: */
- /*
- * XXX - Do we want to do this?
- * __is_threaded = 1;
- */
- pthread_resume_all_np();
- return (0);
-}
diff --git a/lib/libkse/thread/thr_mutex.c b/lib/libkse/thread/thr_mutex.c
deleted file mode 100644
index 2df59efee68d..000000000000
--- a/lib/libkse/thread/thr_mutex.c
+++ /dev/null
@@ -1,1637 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-#if defined(_PTHREADS_INVARIANTS)
-#define MUTEX_INIT_LINK(m) do { \
- (m)->m_qe.tqe_prev = NULL; \
- (m)->m_qe.tqe_next = NULL; \
-} while (0)
-#define MUTEX_ASSERT_IS_OWNED(m) do { \
- if ((m)->m_qe.tqe_prev == NULL) \
- PANIC("mutex is not on list"); \
-} while (0)
-#define MUTEX_ASSERT_NOT_OWNED(m) do { \
- if (((m)->m_qe.tqe_prev != NULL) || \
- ((m)->m_qe.tqe_next != NULL)) \
- PANIC("mutex is on list"); \
-} while (0)
-#define THR_ASSERT_NOT_IN_SYNCQ(thr) do { \
- THR_ASSERT(((thr)->sflags & THR_FLAGS_IN_SYNCQ) == 0, \
- "thread in syncq when it shouldn't be."); \
-} while (0);
-#else
-#define MUTEX_INIT_LINK(m)
-#define MUTEX_ASSERT_IS_OWNED(m)
-#define MUTEX_ASSERT_NOT_OWNED(m)
-#define THR_ASSERT_NOT_IN_SYNCQ(thr)
-#endif
-
-/*
- * Prototypes
- */
-static void mutex_handoff(struct pthread *, struct pthread_mutex *);
-static inline int mutex_self_trylock(struct pthread *, pthread_mutex_t);
-static inline int mutex_self_lock(struct pthread *, pthread_mutex_t);
-static int mutex_unlock_common(pthread_mutex_t *, int);
-static void mutex_priority_adjust(struct pthread *, pthread_mutex_t);
-static void mutex_rescan_owned (struct pthread *, struct pthread *,
- struct pthread_mutex *);
-static inline pthread_t mutex_queue_deq(pthread_mutex_t);
-static inline void mutex_queue_remove(pthread_mutex_t, pthread_t);
-static inline void mutex_queue_enq(pthread_mutex_t, pthread_t);
-
-
-static struct pthread_mutex_attr static_mutex_attr =
- PTHREAD_MUTEXATTR_STATIC_INITIALIZER;
-static pthread_mutexattr_t static_mattr = &static_mutex_attr;
-
-/* Single underscore versions provided for libc internal usage: */
-__weak_reference(__pthread_mutex_lock, pthread_mutex_lock);
-__weak_reference(__pthread_mutex_trylock, pthread_mutex_trylock);
-
-/* No difference between libc and application usage of these: */
-__weak_reference(_pthread_mutex_init, pthread_mutex_init);
-__weak_reference(_pthread_mutex_destroy, pthread_mutex_destroy);
-__weak_reference(_pthread_mutex_unlock, pthread_mutex_unlock);
-
-
-
-int
-_pthread_mutex_init(pthread_mutex_t *mutex,
- const pthread_mutexattr_t *mutex_attr)
-{
- struct pthread_mutex *pmutex;
- enum pthread_mutextype type;
- int protocol;
- int ceiling;
- int flags;
- int ret = 0;
-
- if (mutex == NULL)
- ret = EINVAL;
-
- /* Check if default mutex attributes: */
- else if (mutex_attr == NULL || *mutex_attr == NULL) {
- /* Default to a (error checking) POSIX mutex: */
- type = PTHREAD_MUTEX_ERRORCHECK;
- protocol = PTHREAD_PRIO_NONE;
- ceiling = THR_MAX_PRIORITY;
- flags = 0;
- }
-
- /* Check mutex type: */
- else if (((*mutex_attr)->m_type < PTHREAD_MUTEX_ERRORCHECK) ||
- ((*mutex_attr)->m_type >= MUTEX_TYPE_MAX))
- /* Return an invalid argument error: */
- ret = EINVAL;
-
- /* Check mutex protocol: */
- else if (((*mutex_attr)->m_protocol < PTHREAD_PRIO_NONE) ||
- ((*mutex_attr)->m_protocol > PTHREAD_MUTEX_RECURSIVE))
- /* Return an invalid argument error: */
- ret = EINVAL;
-
- else {
- /* Use the requested mutex type and protocol: */
- type = (*mutex_attr)->m_type;
- protocol = (*mutex_attr)->m_protocol;
- ceiling = (*mutex_attr)->m_ceiling;
- flags = (*mutex_attr)->m_flags;
- }
-
- /* Check no errors so far: */
- if (ret == 0) {
- if ((pmutex = (pthread_mutex_t)
- malloc(sizeof(struct pthread_mutex))) == NULL)
- ret = ENOMEM;
- else if (_lock_init(&pmutex->m_lock, LCK_ADAPTIVE,
- _thr_lock_wait, _thr_lock_wakeup) != 0) {
- free(pmutex);
- *mutex = NULL;
- ret = ENOMEM;
- } else {
- /* Set the mutex flags: */
- pmutex->m_flags = flags;
-
- /* Process according to mutex type: */
- switch (type) {
- /* case PTHREAD_MUTEX_DEFAULT: */
- case PTHREAD_MUTEX_ERRORCHECK:
- case PTHREAD_MUTEX_NORMAL:
- /* Nothing to do here. */
- break;
-
- /* Single UNIX Spec 2 recursive mutex: */
- case PTHREAD_MUTEX_RECURSIVE:
- /* Reset the mutex count: */
- pmutex->m_count = 0;
- break;
-
- /* Trap invalid mutex types: */
- default:
- /* Return an invalid argument error: */
- ret = EINVAL;
- break;
- }
- if (ret == 0) {
- /* Initialise the rest of the mutex: */
- TAILQ_INIT(&pmutex->m_queue);
- pmutex->m_flags |= MUTEX_FLAGS_INITED;
- pmutex->m_owner = NULL;
- pmutex->m_type = type;
- pmutex->m_protocol = protocol;
- pmutex->m_refcount = 0;
- if (protocol == PTHREAD_PRIO_PROTECT)
- pmutex->m_prio = ceiling;
- else
- pmutex->m_prio = -1;
- pmutex->m_saved_prio = 0;
- MUTEX_INIT_LINK(pmutex);
- *mutex = pmutex;
- } else {
- free(pmutex);
- *mutex = NULL;
- }
- }
- }
- /* Return the completion status: */
- return (ret);
-}
-
-int
-_pthread_mutex_destroy(pthread_mutex_t *mutex)
-{
- struct pthread *curthread = _get_curthread();
- pthread_mutex_t m;
- int ret = 0;
-
- if (mutex == NULL || *mutex == NULL)
- ret = EINVAL;
- else {
- /* Lock the mutex structure: */
- THR_LOCK_ACQUIRE(curthread, &(*mutex)->m_lock);
-
- /*
- * Check to see if this mutex is in use:
- */
- if (((*mutex)->m_owner != NULL) ||
- (TAILQ_FIRST(&(*mutex)->m_queue) != NULL) ||
- ((*mutex)->m_refcount != 0)) {
- ret = EBUSY;
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*mutex)->m_lock);
- } else {
- /*
- * Save a pointer to the mutex so it can be free'd
- * and set the caller's pointer to NULL:
- */
- m = *mutex;
- *mutex = NULL;
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &m->m_lock);
-
- /*
- * Free the memory allocated for the mutex
- * structure:
- */
- MUTEX_ASSERT_NOT_OWNED(m);
- free(m);
- }
- }
-
- /* Return the completion status: */
- return (ret);
-}
-
-static int
-init_static(struct pthread *thread, pthread_mutex_t *mutex)
-{
- int ret;
-
- THR_LOCK_ACQUIRE(thread, &_mutex_static_lock);
-
- if (*mutex == NULL)
- ret = pthread_mutex_init(mutex, NULL);
- else
- ret = 0;
-
- THR_LOCK_RELEASE(thread, &_mutex_static_lock);
-
- return (ret);
-}
-
-static int
-init_static_private(struct pthread *thread, pthread_mutex_t *mutex)
-{
- int ret;
-
- THR_LOCK_ACQUIRE(thread, &_mutex_static_lock);
-
- if (*mutex == NULL)
- ret = pthread_mutex_init(mutex, &static_mattr);
- else
- ret = 0;
-
- THR_LOCK_RELEASE(thread, &_mutex_static_lock);
-
- return (ret);
-}
-
-static int
-mutex_trylock_common(struct pthread *curthread, pthread_mutex_t *mutex)
-{
- int ret = 0;
-
- THR_ASSERT((mutex != NULL) && (*mutex != NULL),
- "Uninitialized mutex in pthread_mutex_trylock_basic");
-
- /* Lock the mutex structure: */
- THR_LOCK_ACQUIRE(curthread, &(*mutex)->m_lock);
-
- /*
- * If the mutex was statically allocated, properly
- * initialize the tail queue.
- */
- if (((*mutex)->m_flags & MUTEX_FLAGS_INITED) == 0) {
- TAILQ_INIT(&(*mutex)->m_queue);
- MUTEX_INIT_LINK(*mutex);
- (*mutex)->m_flags |= MUTEX_FLAGS_INITED;
- }
-
- /* Process according to mutex type: */
- switch ((*mutex)->m_protocol) {
- /* Default POSIX mutex: */
- case PTHREAD_PRIO_NONE:
- /* Check if this mutex is not locked: */
- if ((*mutex)->m_owner == NULL) {
- /* Lock the mutex for the running thread: */
- (*mutex)->m_owner = curthread;
-
- /* Add to the list of owned mutexes: */
- MUTEX_ASSERT_NOT_OWNED(*mutex);
- TAILQ_INSERT_TAIL(&curthread->mutexq,
- (*mutex), m_qe);
- } else if ((*mutex)->m_owner == curthread)
- ret = mutex_self_trylock(curthread, *mutex);
- else
- /* Return a busy error: */
- ret = EBUSY;
- break;
-
- /* POSIX priority inheritence mutex: */
- case PTHREAD_PRIO_INHERIT:
- /* Check if this mutex is not locked: */
- if ((*mutex)->m_owner == NULL) {
- /* Lock the mutex for the running thread: */
- (*mutex)->m_owner = curthread;
-
- THR_SCHED_LOCK(curthread, curthread);
- /* Track number of priority mutexes owned: */
- curthread->priority_mutex_count++;
-
- /*
- * The mutex takes on the attributes of the
- * running thread when there are no waiters.
- */
- (*mutex)->m_prio = curthread->active_priority;
- (*mutex)->m_saved_prio =
- curthread->inherited_priority;
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Add to the list of owned mutexes: */
- MUTEX_ASSERT_NOT_OWNED(*mutex);
- TAILQ_INSERT_TAIL(&curthread->mutexq,
- (*mutex), m_qe);
- } else if ((*mutex)->m_owner == curthread)
- ret = mutex_self_trylock(curthread, *mutex);
- else
- /* Return a busy error: */
- ret = EBUSY;
- break;
-
- /* POSIX priority protection mutex: */
- case PTHREAD_PRIO_PROTECT:
- /* Check for a priority ceiling violation: */
- if (curthread->active_priority > (*mutex)->m_prio)
- ret = EINVAL;
-
- /* Check if this mutex is not locked: */
- else if ((*mutex)->m_owner == NULL) {
- /* Lock the mutex for the running thread: */
- (*mutex)->m_owner = curthread;
-
- THR_SCHED_LOCK(curthread, curthread);
- /* Track number of priority mutexes owned: */
- curthread->priority_mutex_count++;
-
- /*
- * The running thread inherits the ceiling
- * priority of the mutex and executes at that
- * priority.
- */
- curthread->active_priority = (*mutex)->m_prio;
- (*mutex)->m_saved_prio =
- curthread->inherited_priority;
- curthread->inherited_priority =
- (*mutex)->m_prio;
- THR_SCHED_UNLOCK(curthread, curthread);
- /* Add to the list of owned mutexes: */
- MUTEX_ASSERT_NOT_OWNED(*mutex);
- TAILQ_INSERT_TAIL(&curthread->mutexq,
- (*mutex), m_qe);
- } else if ((*mutex)->m_owner == curthread)
- ret = mutex_self_trylock(curthread, *mutex);
- else
- /* Return a busy error: */
- ret = EBUSY;
- break;
-
- /* Trap invalid mutex types: */
- default:
- /* Return an invalid argument error: */
- ret = EINVAL;
- break;
- }
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*mutex)->m_lock);
-
- /* Return the completion status: */
- return (ret);
-}
-
-int
-__pthread_mutex_trylock(pthread_mutex_t *mutex)
-{
- struct pthread *curthread = _get_curthread();
- int ret = 0;
-
- if (mutex == NULL)
- ret = EINVAL;
-
- /*
- * If the mutex is statically initialized, perform the dynamic
- * initialization:
- */
- else if ((*mutex != NULL) ||
- ((ret = init_static(curthread, mutex)) == 0))
- ret = mutex_trylock_common(curthread, mutex);
-
- return (ret);
-}
-
-int
-_pthread_mutex_trylock(pthread_mutex_t *mutex)
-{
- struct pthread *curthread = _get_curthread();
- int ret = 0;
-
- if (mutex == NULL)
- ret = EINVAL;
-
- /*
- * If the mutex is statically initialized, perform the dynamic
- * initialization marking the mutex private (delete safe):
- */
- else if ((*mutex != NULL) ||
- ((ret = init_static_private(curthread, mutex)) == 0))
- ret = mutex_trylock_common(curthread, mutex);
-
- return (ret);
-}
-
-static int
-mutex_lock_common(struct pthread *curthread, pthread_mutex_t *m)
-{
- int ret = 0;
-
- THR_ASSERT((m != NULL) && (*m != NULL),
- "Uninitialized mutex in pthread_mutex_trylock_basic");
-
- /* Reset the interrupted flag: */
- curthread->interrupted = 0;
-
- /*
- * Enter a loop waiting to become the mutex owner. We need a
- * loop in case the waiting thread is interrupted by a signal
- * to execute a signal handler. It is not (currently) possible
- * to remain in the waiting queue while running a handler.
- * Instead, the thread is interrupted and backed out of the
- * waiting queue prior to executing the signal handler.
- */
- do {
- /* Lock the mutex structure: */
- THR_LOCK_ACQUIRE(curthread, &(*m)->m_lock);
-
- /*
- * If the mutex was statically allocated, properly
- * initialize the tail queue.
- */
- if (((*m)->m_flags & MUTEX_FLAGS_INITED) == 0) {
- TAILQ_INIT(&(*m)->m_queue);
- (*m)->m_flags |= MUTEX_FLAGS_INITED;
- MUTEX_INIT_LINK(*m);
- }
-
- /* Process according to mutex type: */
- switch ((*m)->m_protocol) {
- /* Default POSIX mutex: */
- case PTHREAD_PRIO_NONE:
- if ((*m)->m_owner == NULL) {
- /* Lock the mutex for this thread: */
- (*m)->m_owner = curthread;
-
- /* Add to the list of owned mutexes: */
- MUTEX_ASSERT_NOT_OWNED(*m);
- TAILQ_INSERT_TAIL(&curthread->mutexq,
- (*m), m_qe);
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
- } else if ((*m)->m_owner == curthread) {
- ret = mutex_self_lock(curthread, *m);
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
- } else {
- /*
- * Join the queue of threads waiting to lock
- * the mutex and save a pointer to the mutex.
- */
- mutex_queue_enq(*m, curthread);
- curthread->data.mutex = *m;
- /*
- * This thread is active and is in a critical
- * region (holding the mutex lock); we should
- * be able to safely set the state.
- */
- THR_SCHED_LOCK(curthread, curthread);
- THR_SET_STATE(curthread, PS_MUTEX_WAIT);
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
-
- /* Schedule the next thread: */
- _thr_sched_switch(curthread);
- }
- break;
-
- /* POSIX priority inheritence mutex: */
- case PTHREAD_PRIO_INHERIT:
- /* Check if this mutex is not locked: */
- if ((*m)->m_owner == NULL) {
- /* Lock the mutex for this thread: */
- (*m)->m_owner = curthread;
-
- THR_SCHED_LOCK(curthread, curthread);
- /* Track number of priority mutexes owned: */
- curthread->priority_mutex_count++;
-
- /*
- * The mutex takes on attributes of the
- * running thread when there are no waiters.
- * Make sure the thread's scheduling lock is
- * held while priorities are adjusted.
- */
- (*m)->m_prio = curthread->active_priority;
- (*m)->m_saved_prio =
- curthread->inherited_priority;
- curthread->inherited_priority = (*m)->m_prio;
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Add to the list of owned mutexes: */
- MUTEX_ASSERT_NOT_OWNED(*m);
- TAILQ_INSERT_TAIL(&curthread->mutexq,
- (*m), m_qe);
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
- } else if ((*m)->m_owner == curthread) {
- ret = mutex_self_lock(curthread, *m);
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
- } else {
- /*
- * Join the queue of threads waiting to lock
- * the mutex and save a pointer to the mutex.
- */
- mutex_queue_enq(*m, curthread);
- curthread->data.mutex = *m;
-
- /*
- * This thread is active and is in a critical
- * region (holding the mutex lock); we should
- * be able to safely set the state.
- */
- if (curthread->active_priority > (*m)->m_prio)
- /* Adjust priorities: */
- mutex_priority_adjust(curthread, *m);
-
- THR_SCHED_LOCK(curthread, curthread);
- THR_SET_STATE(curthread, PS_MUTEX_WAIT);
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
-
- /* Schedule the next thread: */
- _thr_sched_switch(curthread);
- }
- break;
-
- /* POSIX priority protection mutex: */
- case PTHREAD_PRIO_PROTECT:
- /* Check for a priority ceiling violation: */
- if (curthread->active_priority > (*m)->m_prio) {
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
- ret = EINVAL;
- }
- /* Check if this mutex is not locked: */
- else if ((*m)->m_owner == NULL) {
- /*
- * Lock the mutex for the running
- * thread:
- */
- (*m)->m_owner = curthread;
-
- THR_SCHED_LOCK(curthread, curthread);
- /* Track number of priority mutexes owned: */
- curthread->priority_mutex_count++;
-
- /*
- * The running thread inherits the ceiling
- * priority of the mutex and executes at that
- * priority. Make sure the thread's
- * scheduling lock is held while priorities
- * are adjusted.
- */
- curthread->active_priority = (*m)->m_prio;
- (*m)->m_saved_prio =
- curthread->inherited_priority;
- curthread->inherited_priority = (*m)->m_prio;
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Add to the list of owned mutexes: */
- MUTEX_ASSERT_NOT_OWNED(*m);
- TAILQ_INSERT_TAIL(&curthread->mutexq,
- (*m), m_qe);
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
- } else if ((*m)->m_owner == curthread) {
- ret = mutex_self_lock(curthread, *m);
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
- } else {
- /*
- * Join the queue of threads waiting to lock
- * the mutex and save a pointer to the mutex.
- */
- mutex_queue_enq(*m, curthread);
- curthread->data.mutex = *m;
-
- /* Clear any previous error: */
- curthread->error = 0;
-
- /*
- * This thread is active and is in a critical
- * region (holding the mutex lock); we should
- * be able to safely set the state.
- */
-
- THR_SCHED_LOCK(curthread, curthread);
- THR_SET_STATE(curthread, PS_MUTEX_WAIT);
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
-
- /* Schedule the next thread: */
- _thr_sched_switch(curthread);
- /*
- * The threads priority may have changed while
- * waiting for the mutex causing a ceiling
- * violation.
- */
- ret = curthread->error;
- curthread->error = 0;
- }
- break;
-
- /* Trap invalid mutex types: */
- default:
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
-
- /* Return an invalid argument error: */
- ret = EINVAL;
- break;
- }
-
- } while (((*m)->m_owner != curthread) && (ret == 0) &&
- (curthread->interrupted == 0));
-
- /*
- * Check to see if this thread was interrupted and
- * is still in the mutex queue of waiting threads:
- */
- if (curthread->interrupted != 0) {
- /* Remove this thread from the mutex queue. */
- THR_LOCK_ACQUIRE(curthread, &(*m)->m_lock);
- if (THR_IN_SYNCQ(curthread))
- mutex_queue_remove(*m, curthread);
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
-
- /* Check for asynchronous cancellation. */
- if (curthread->continuation != NULL)
- curthread->continuation((void *) curthread);
- }
-
- /* Return the completion status: */
- return (ret);
-}
-
-int
-__pthread_mutex_lock(pthread_mutex_t *m)
-{
- struct pthread *curthread;
- int ret = 0;
-
- if (_thr_initial == NULL)
- _libpthread_init(NULL);
-
- curthread = _get_curthread();
- if (m == NULL)
- ret = EINVAL;
-
- /*
- * If the mutex is statically initialized, perform the dynamic
- * initialization:
- */
- else if ((*m != NULL) || ((ret = init_static(curthread, m)) == 0))
- ret = mutex_lock_common(curthread, m);
-
- return (ret);
-}
-
-__strong_reference(__pthread_mutex_lock, _thr_mutex_lock);
-
-int
-_pthread_mutex_lock(pthread_mutex_t *m)
-{
- struct pthread *curthread;
- int ret = 0;
-
- if (_thr_initial == NULL)
- _libpthread_init(NULL);
- curthread = _get_curthread();
-
- if (m == NULL)
- ret = EINVAL;
-
- /*
- * If the mutex is statically initialized, perform the dynamic
- * initialization marking it private (delete safe):
- */
- else if ((*m != NULL) ||
- ((ret = init_static_private(curthread, m)) == 0))
- ret = mutex_lock_common(curthread, m);
-
- return (ret);
-}
-
-int
-_pthread_mutex_unlock(pthread_mutex_t *m)
-{
- return (mutex_unlock_common(m, /* add reference */ 0));
-}
-
-__strong_reference(_pthread_mutex_unlock, _thr_mutex_unlock);
-
-int
-_mutex_cv_unlock(pthread_mutex_t *m)
-{
- return (mutex_unlock_common(m, /* add reference */ 1));
-}
-
-int
-_mutex_cv_lock(pthread_mutex_t *m)
-{
- struct pthread *curthread;
- int ret;
-
- curthread = _get_curthread();
- if ((ret = _pthread_mutex_lock(m)) == 0) {
- THR_LOCK_ACQUIRE(curthread, &(*m)->m_lock);
- (*m)->m_refcount--;
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
- }
- return (ret);
-}
-
-static inline int
-mutex_self_trylock(struct pthread *curthread, pthread_mutex_t m)
-{
- int ret = 0;
-
- switch (m->m_type) {
- /* case PTHREAD_MUTEX_DEFAULT: */
- case PTHREAD_MUTEX_ERRORCHECK:
- case PTHREAD_MUTEX_NORMAL:
- /*
- * POSIX specifies that mutexes should return EDEADLK if a
- * recursive lock is detected.
- */
- if (m->m_owner == curthread)
- ret = EDEADLK;
- else
- ret = EBUSY;
- break;
-
- case PTHREAD_MUTEX_RECURSIVE:
- /* Increment the lock count: */
- m->m_count++;
- break;
-
- default:
- /* Trap invalid mutex types; */
- ret = EINVAL;
- }
-
- return (ret);
-}
-
-static inline int
-mutex_self_lock(struct pthread *curthread, pthread_mutex_t m)
-{
- int ret = 0;
-
- switch (m->m_type) {
- /* case PTHREAD_MUTEX_DEFAULT: */
- case PTHREAD_MUTEX_ERRORCHECK:
- /*
- * POSIX specifies that mutexes should return EDEADLK if a
- * recursive lock is detected.
- */
- ret = EDEADLK;
- break;
-
- case PTHREAD_MUTEX_NORMAL:
- /*
- * What SS2 define as a 'normal' mutex. Intentionally
- * deadlock on attempts to get a lock you already own.
- */
-
- THR_SCHED_LOCK(curthread, curthread);
- THR_SET_STATE(curthread, PS_DEADLOCK);
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &m->m_lock);
-
- /* Schedule the next thread: */
- _thr_sched_switch(curthread);
- break;
-
- case PTHREAD_MUTEX_RECURSIVE:
- /* Increment the lock count: */
- m->m_count++;
- break;
-
- default:
- /* Trap invalid mutex types; */
- ret = EINVAL;
- }
-
- return (ret);
-}
-
-static int
-mutex_unlock_common(pthread_mutex_t *m, int add_reference)
-{
- struct pthread *curthread = _get_curthread();
- int ret = 0;
-
- if (m == NULL || *m == NULL)
- ret = EINVAL;
- else {
- /* Lock the mutex structure: */
- THR_LOCK_ACQUIRE(curthread, &(*m)->m_lock);
-
- /* Process according to mutex type: */
- switch ((*m)->m_protocol) {
- /* Default POSIX mutex: */
- case PTHREAD_PRIO_NONE:
- /*
- * Check if the running thread is not the owner of the
- * mutex:
- */
- if ((*m)->m_owner != curthread)
- /*
- * Return an invalid argument error for no
- * owner and a permission error otherwise:
- */
- ret = (*m)->m_owner == NULL ? EINVAL : EPERM;
-
- else if (((*m)->m_type == PTHREAD_MUTEX_RECURSIVE) &&
- ((*m)->m_count > 0))
- /* Decrement the count: */
- (*m)->m_count--;
- else {
- /*
- * Clear the count in case this is a recursive
- * mutex.
- */
- (*m)->m_count = 0;
-
- /* Remove the mutex from the threads queue. */
- MUTEX_ASSERT_IS_OWNED(*m);
- TAILQ_REMOVE(&(*m)->m_owner->mutexq,
- (*m), m_qe);
- MUTEX_INIT_LINK(*m);
-
- /*
- * Hand off the mutex to the next waiting
- * thread:
- */
- mutex_handoff(curthread, *m);
- }
- break;
-
- /* POSIX priority inheritence mutex: */
- case PTHREAD_PRIO_INHERIT:
- /*
- * Check if the running thread is not the owner of the
- * mutex:
- */
- if ((*m)->m_owner != curthread)
- /*
- * Return an invalid argument error for no
- * owner and a permission error otherwise:
- */
- ret = (*m)->m_owner == NULL ? EINVAL : EPERM;
-
- else if (((*m)->m_type == PTHREAD_MUTEX_RECURSIVE) &&
- ((*m)->m_count > 0))
- /* Decrement the count: */
- (*m)->m_count--;
- else {
- /*
- * Clear the count in case this is recursive
- * mutex.
- */
- (*m)->m_count = 0;
-
- /*
- * Restore the threads inherited priority and
- * recompute the active priority (being careful
- * not to override changes in the threads base
- * priority subsequent to locking the mutex).
- */
- THR_SCHED_LOCK(curthread, curthread);
- curthread->inherited_priority =
- (*m)->m_saved_prio;
- curthread->active_priority =
- MAX(curthread->inherited_priority,
- curthread->base_priority);
-
- /*
- * This thread now owns one less priority mutex.
- */
- curthread->priority_mutex_count--;
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Remove the mutex from the threads queue. */
- MUTEX_ASSERT_IS_OWNED(*m);
- TAILQ_REMOVE(&(*m)->m_owner->mutexq,
- (*m), m_qe);
- MUTEX_INIT_LINK(*m);
-
- /*
- * Hand off the mutex to the next waiting
- * thread:
- */
- mutex_handoff(curthread, *m);
- }
- break;
-
- /* POSIX priority ceiling mutex: */
- case PTHREAD_PRIO_PROTECT:
- /*
- * Check if the running thread is not the owner of the
- * mutex:
- */
- if ((*m)->m_owner != curthread)
- /*
- * Return an invalid argument error for no
- * owner and a permission error otherwise:
- */
- ret = (*m)->m_owner == NULL ? EINVAL : EPERM;
-
- else if (((*m)->m_type == PTHREAD_MUTEX_RECURSIVE) &&
- ((*m)->m_count > 0))
- /* Decrement the count: */
- (*m)->m_count--;
- else {
- /*
- * Clear the count in case this is a recursive
- * mutex.
- */
- (*m)->m_count = 0;
-
- /*
- * Restore the threads inherited priority and
- * recompute the active priority (being careful
- * not to override changes in the threads base
- * priority subsequent to locking the mutex).
- */
- THR_SCHED_LOCK(curthread, curthread);
- curthread->inherited_priority =
- (*m)->m_saved_prio;
- curthread->active_priority =
- MAX(curthread->inherited_priority,
- curthread->base_priority);
-
- /*
- * This thread now owns one less priority mutex.
- */
- curthread->priority_mutex_count--;
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Remove the mutex from the threads queue. */
- MUTEX_ASSERT_IS_OWNED(*m);
- TAILQ_REMOVE(&(*m)->m_owner->mutexq,
- (*m), m_qe);
- MUTEX_INIT_LINK(*m);
-
- /*
- * Hand off the mutex to the next waiting
- * thread:
- */
- mutex_handoff(curthread, *m);
- }
- break;
-
- /* Trap invalid mutex types: */
- default:
- /* Return an invalid argument error: */
- ret = EINVAL;
- break;
- }
-
- if ((ret == 0) && (add_reference != 0))
- /* Increment the reference count: */
- (*m)->m_refcount++;
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
- }
-
- /* Return the completion status: */
- return (ret);
-}
-
-
-/*
- * This function is called when a change in base priority occurs for
- * a thread that is holding or waiting for a priority protection or
- * inheritence mutex. A change in a threads base priority can effect
- * changes to active priorities of other threads and to the ordering
- * of mutex locking by waiting threads.
- *
- * This must be called without the target thread's scheduling lock held.
- */
-void
-_mutex_notify_priochange(struct pthread *curthread, struct pthread *pthread,
- int propagate_prio)
-{
- struct pthread_mutex *m;
-
- /* Adjust the priorites of any owned priority mutexes: */
- if (pthread->priority_mutex_count > 0) {
- /*
- * Rescan the mutexes owned by this thread and correct
- * their priorities to account for this threads change
- * in priority. This has the side effect of changing
- * the threads active priority.
- *
- * Be sure to lock the first mutex in the list of owned
- * mutexes. This acts as a barrier against another
- * simultaneous call to change the threads priority
- * and from the owning thread releasing the mutex.
- */
- m = TAILQ_FIRST(&pthread->mutexq);
- if (m != NULL) {
- THR_LOCK_ACQUIRE(curthread, &m->m_lock);
- /*
- * Make sure the thread still owns the lock.
- */
- if (m == TAILQ_FIRST(&pthread->mutexq))
- mutex_rescan_owned(curthread, pthread,
- /* rescan all owned */ NULL);
- THR_LOCK_RELEASE(curthread, &m->m_lock);
- }
- }
-
- /*
- * If this thread is waiting on a priority inheritence mutex,
- * check for priority adjustments. A change in priority can
- * also cause a ceiling violation(*) for a thread waiting on
- * a priority protection mutex; we don't perform the check here
- * as it is done in pthread_mutex_unlock.
- *
- * (*) It should be noted that a priority change to a thread
- * _after_ taking and owning a priority ceiling mutex
- * does not affect ownership of that mutex; the ceiling
- * priority is only checked before mutex ownership occurs.
- */
- if (propagate_prio != 0) {
- /*
- * Lock the thread's scheduling queue. This is a bit
- * convoluted; the "in synchronization queue flag" can
- * only be cleared with both the thread's scheduling and
- * mutex locks held. The thread's pointer to the wanted
- * mutex is guaranteed to be valid during this time.
- */
- THR_SCHED_LOCK(curthread, pthread);
-
- if (((pthread->sflags & THR_FLAGS_IN_SYNCQ) == 0) ||
- ((m = pthread->data.mutex) == NULL))
- THR_SCHED_UNLOCK(curthread, pthread);
- else {
- /*
- * This thread is currently waiting on a mutex; unlock
- * the scheduling queue lock and lock the mutex. We
- * can't hold both at the same time because the locking
- * order could cause a deadlock.
- */
- THR_SCHED_UNLOCK(curthread, pthread);
- THR_LOCK_ACQUIRE(curthread, &m->m_lock);
-
- /*
- * Check to make sure this thread is still in the
- * same state (the lock above can yield the CPU to
- * another thread or the thread may be running on
- * another CPU).
- */
- if (((pthread->sflags & THR_FLAGS_IN_SYNCQ) != 0) &&
- (pthread->data.mutex == m)) {
- /*
- * Remove and reinsert this thread into
- * the list of waiting threads to preserve
- * decreasing priority order.
- */
- mutex_queue_remove(m, pthread);
- mutex_queue_enq(m, pthread);
-
- if (m->m_protocol == PTHREAD_PRIO_INHERIT)
- /* Adjust priorities: */
- mutex_priority_adjust(curthread, m);
- }
-
- /* Unlock the mutex structure: */
- THR_LOCK_RELEASE(curthread, &m->m_lock);
- }
- }
-}
-
-/*
- * Called when a new thread is added to the mutex waiting queue or
- * when a threads priority changes that is already in the mutex
- * waiting queue.
- *
- * This must be called with the mutex locked by the current thread.
- */
-static void
-mutex_priority_adjust(struct pthread *curthread, pthread_mutex_t mutex)
-{
- pthread_mutex_t m = mutex;
- struct pthread *pthread_next, *pthread = mutex->m_owner;
- int done, temp_prio;
-
- /*
- * Calculate the mutex priority as the maximum of the highest
- * active priority of any waiting threads and the owning threads
- * active priority(*).
- *
- * (*) Because the owning threads current active priority may
- * reflect priority inherited from this mutex (and the mutex
- * priority may have changed) we must recalculate the active
- * priority based on the threads saved inherited priority
- * and its base priority.
- */
- pthread_next = TAILQ_FIRST(&m->m_queue); /* should never be NULL */
- temp_prio = MAX(pthread_next->active_priority,
- MAX(m->m_saved_prio, pthread->base_priority));
-
- /* See if this mutex really needs adjusting: */
- if (temp_prio == m->m_prio)
- /* No need to propagate the priority: */
- return;
-
- /* Set new priority of the mutex: */
- m->m_prio = temp_prio;
-
- /*
- * Don't unlock the mutex passed in as an argument. It is
- * expected to be locked and unlocked by the caller.
- */
- done = 1;
- do {
- /*
- * Save the threads priority before rescanning the
- * owned mutexes:
- */
- temp_prio = pthread->active_priority;
-
- /*
- * Fix the priorities for all mutexes held by the owning
- * thread since taking this mutex. This also has a
- * potential side-effect of changing the threads priority.
- *
- * At this point the mutex is locked by the current thread.
- * The owning thread can't release the mutex until it is
- * unlocked, so we should be able to safely walk its list
- * of owned mutexes.
- */
- mutex_rescan_owned(curthread, pthread, m);
-
- /*
- * If this isn't the first time through the loop,
- * the current mutex needs to be unlocked.
- */
- if (done == 0)
- THR_LOCK_RELEASE(curthread, &m->m_lock);
-
- /* Assume we're done unless told otherwise: */
- done = 1;
-
- /*
- * If the thread is currently waiting on a mutex, check
- * to see if the threads new priority has affected the
- * priority of the mutex.
- */
- if ((temp_prio != pthread->active_priority) &&
- ((pthread->sflags & THR_FLAGS_IN_SYNCQ) != 0) &&
- ((m = pthread->data.mutex) != NULL) &&
- (m->m_protocol == PTHREAD_PRIO_INHERIT)) {
- /* Lock the mutex structure: */
- THR_LOCK_ACQUIRE(curthread, &m->m_lock);
-
- /*
- * Make sure the thread is still waiting on the
- * mutex:
- */
- if (((pthread->sflags & THR_FLAGS_IN_SYNCQ) != 0) &&
- (m == pthread->data.mutex)) {
- /*
- * The priority for this thread has changed.
- * Remove and reinsert this thread into the
- * list of waiting threads to preserve
- * decreasing priority order.
- */
- mutex_queue_remove(m, pthread);
- mutex_queue_enq(m, pthread);
-
- /*
- * Grab the waiting thread with highest
- * priority:
- */
- pthread_next = TAILQ_FIRST(&m->m_queue);
-
- /*
- * Calculate the mutex priority as the maximum
- * of the highest active priority of any
- * waiting threads and the owning threads
- * active priority.
- */
- temp_prio = MAX(pthread_next->active_priority,
- MAX(m->m_saved_prio,
- m->m_owner->base_priority));
-
- if (temp_prio != m->m_prio) {
- /*
- * The priority needs to be propagated
- * to the mutex this thread is waiting
- * on and up to the owner of that mutex.
- */
- m->m_prio = temp_prio;
- pthread = m->m_owner;
-
- /* We're not done yet: */
- done = 0;
- }
- }
- /* Only release the mutex if we're done: */
- if (done != 0)
- THR_LOCK_RELEASE(curthread, &m->m_lock);
- }
- } while (done == 0);
-}
-
-static void
-mutex_rescan_owned(struct pthread *curthread, struct pthread *pthread,
- struct pthread_mutex *mutex)
-{
- struct pthread_mutex *m;
- struct pthread *pthread_next;
- int active_prio, inherited_prio;
-
- /*
- * Start walking the mutexes the thread has taken since
- * taking this mutex.
- */
- if (mutex == NULL) {
- /*
- * A null mutex means start at the beginning of the owned
- * mutex list.
- */
- m = TAILQ_FIRST(&pthread->mutexq);
-
- /* There is no inherited priority yet. */
- inherited_prio = 0;
- } else {
- /*
- * The caller wants to start after a specific mutex. It
- * is assumed that this mutex is a priority inheritence
- * mutex and that its priority has been correctly
- * calculated.
- */
- m = TAILQ_NEXT(mutex, m_qe);
-
- /* Start inheriting priority from the specified mutex. */
- inherited_prio = mutex->m_prio;
- }
- active_prio = MAX(inherited_prio, pthread->base_priority);
-
- for (; m != NULL; m = TAILQ_NEXT(m, m_qe)) {
- /*
- * We only want to deal with priority inheritence
- * mutexes. This might be optimized by only placing
- * priority inheritence mutexes into the owned mutex
- * list, but it may prove to be useful having all
- * owned mutexes in this list. Consider a thread
- * exiting while holding mutexes...
- */
- if (m->m_protocol == PTHREAD_PRIO_INHERIT) {
- /*
- * Fix the owners saved (inherited) priority to
- * reflect the priority of the previous mutex.
- */
- m->m_saved_prio = inherited_prio;
-
- if ((pthread_next = TAILQ_FIRST(&m->m_queue)) != NULL)
- /* Recalculate the priority of the mutex: */
- m->m_prio = MAX(active_prio,
- pthread_next->active_priority);
- else
- m->m_prio = active_prio;
-
- /* Recalculate new inherited and active priorities: */
- inherited_prio = m->m_prio;
- active_prio = MAX(m->m_prio, pthread->base_priority);
- }
- }
-
- /*
- * Fix the threads inherited priority and recalculate its
- * active priority.
- */
- pthread->inherited_priority = inherited_prio;
- active_prio = MAX(inherited_prio, pthread->base_priority);
-
- if (active_prio != pthread->active_priority) {
- /* Lock the thread's scheduling queue: */
- THR_SCHED_LOCK(curthread, pthread);
-
- if ((pthread->flags & THR_FLAGS_IN_RUNQ) == 0) {
- /*
- * This thread is not in a run queue. Just set
- * its active priority.
- */
- pthread->active_priority = active_prio;
- }
- else {
- /*
- * This thread is in a run queue. Remove it from
- * the queue before changing its priority:
- */
- THR_RUNQ_REMOVE(pthread);
-
- /*
- * POSIX states that if the priority is being
- * lowered, the thread must be inserted at the
- * head of the queue for its priority if it owns
- * any priority protection or inheritence mutexes.
- */
- if ((active_prio < pthread->active_priority) &&
- (pthread->priority_mutex_count > 0)) {
- /* Set the new active priority. */
- pthread->active_priority = active_prio;
-
- THR_RUNQ_INSERT_HEAD(pthread);
- } else {
- /* Set the new active priority. */
- pthread->active_priority = active_prio;
-
- THR_RUNQ_INSERT_TAIL(pthread);
- }
- }
- THR_SCHED_UNLOCK(curthread, pthread);
- }
-}
-
-void
-_mutex_unlock_private(pthread_t pthread)
-{
- struct pthread_mutex *m, *m_next;
-
- for (m = TAILQ_FIRST(&pthread->mutexq); m != NULL; m = m_next) {
- m_next = TAILQ_NEXT(m, m_qe);
- if ((m->m_flags & MUTEX_FLAGS_PRIVATE) != 0)
- pthread_mutex_unlock(&m);
- }
-}
-
-/*
- * This is called by the current thread when it wants to back out of a
- * mutex_lock in order to run a signal handler.
- */
-void
-_mutex_lock_backout(struct pthread *curthread)
-{
- struct pthread_mutex *m;
-
- if ((curthread->sflags & THR_FLAGS_IN_SYNCQ) != 0) {
- /*
- * Any other thread may clear the "in sync queue flag",
- * but only the current thread can clear the pointer
- * to the mutex. So if the flag is set, we can
- * guarantee that the pointer to the mutex is valid.
- * The only problem may be if the mutex is destroyed
- * out from under us, but that should be considered
- * an application bug.
- */
- m = curthread->data.mutex;
-
- /* Lock the mutex structure: */
- THR_LOCK_ACQUIRE(curthread, &m->m_lock);
-
-
- /*
- * Check to make sure this thread doesn't already own
- * the mutex. Since mutexes are unlocked with direct
- * handoffs, it is possible the previous owner gave it
- * to us after we checked the sync queue flag and before
- * we locked the mutex structure.
- */
- if (m->m_owner == curthread) {
- THR_LOCK_RELEASE(curthread, &m->m_lock);
- mutex_unlock_common(&m, /* add_reference */ 0);
- } else {
- /*
- * Remove ourselves from the mutex queue and
- * clear the pointer to the mutex. We may no
- * longer be in the mutex queue, but the removal
- * function will DTRT.
- */
- mutex_queue_remove(m, curthread);
- curthread->data.mutex = NULL;
- THR_LOCK_RELEASE(curthread, &m->m_lock);
- }
- }
-}
-
-/*
- * Dequeue a waiting thread from the head of a mutex queue in descending
- * priority order.
- *
- * In order to properly dequeue a thread from the mutex queue and
- * make it runnable without the possibility of errant wakeups, it
- * is necessary to lock the thread's scheduling queue while also
- * holding the mutex lock.
- */
-static void
-mutex_handoff(struct pthread *curthread, struct pthread_mutex *mutex)
-{
- struct pthread *pthread;
-
- /* Keep dequeueing until we find a valid thread: */
- mutex->m_owner = NULL;
- pthread = TAILQ_FIRST(&mutex->m_queue);
- while (pthread != NULL) {
- /* Take the thread's scheduling lock: */
- THR_SCHED_LOCK(curthread, pthread);
-
- /* Remove the thread from the mutex queue: */
- TAILQ_REMOVE(&mutex->m_queue, pthread, sqe);
- pthread->sflags &= ~THR_FLAGS_IN_SYNCQ;
-
- /* This thread is no longer waiting for this mutex. */
- pthread->data.mutex = NULL;
-
- /*
- * Only exit the loop if the thread hasn't been
- * cancelled.
- */
- switch (mutex->m_protocol) {
- case PTHREAD_PRIO_NONE:
- /*
- * Assign the new owner and add the mutex to the
- * thread's list of owned mutexes.
- */
- mutex->m_owner = pthread;
- TAILQ_INSERT_TAIL(&pthread->mutexq, mutex, m_qe);
- break;
-
- case PTHREAD_PRIO_INHERIT:
- /*
- * Assign the new owner and add the mutex to the
- * thread's list of owned mutexes.
- */
- mutex->m_owner = pthread;
- TAILQ_INSERT_TAIL(&pthread->mutexq, mutex, m_qe);
-
- /* Track number of priority mutexes owned: */
- pthread->priority_mutex_count++;
-
- /*
- * Set the priority of the mutex. Since our waiting
- * threads are in descending priority order, the
- * priority of the mutex becomes the active priority
- * of the thread we just dequeued.
- */
- mutex->m_prio = pthread->active_priority;
-
- /* Save the owning threads inherited priority: */
- mutex->m_saved_prio = pthread->inherited_priority;
-
- /*
- * The owning threads inherited priority now becomes
- * his active priority (the priority of the mutex).
- */
- pthread->inherited_priority = mutex->m_prio;
- break;
-
- case PTHREAD_PRIO_PROTECT:
- if (pthread->active_priority > mutex->m_prio) {
- /*
- * Either the mutex ceiling priority has
- * been lowered and/or this threads priority
- * has been raised subsequent to the thread
- * being queued on the waiting list.
- */
- pthread->error = EINVAL;
- }
- else {
- /*
- * Assign the new owner and add the mutex
- * to the thread's list of owned mutexes.
- */
- mutex->m_owner = pthread;
- TAILQ_INSERT_TAIL(&pthread->mutexq,
- mutex, m_qe);
-
- /* Track number of priority mutexes owned: */
- pthread->priority_mutex_count++;
-
- /*
- * Save the owning threads inherited
- * priority:
- */
- mutex->m_saved_prio =
- pthread->inherited_priority;
-
- /*
- * The owning thread inherits the ceiling
- * priority of the mutex and executes at
- * that priority:
- */
- pthread->inherited_priority = mutex->m_prio;
- pthread->active_priority = mutex->m_prio;
-
- }
- break;
- }
-
- /* Make the thread runnable and unlock the scheduling queue: */
- _thr_setrunnable_unlocked(pthread);
- THR_SCHED_UNLOCK(curthread, pthread);
-
- if (mutex->m_owner == pthread)
- /* We're done; a valid owner was found. */
- break;
- else
- /* Get the next thread from the waiting queue: */
- pthread = TAILQ_NEXT(pthread, sqe);
- }
-
- if ((pthread == NULL) && (mutex->m_protocol == PTHREAD_PRIO_INHERIT))
- /* This mutex has no priority: */
- mutex->m_prio = 0;
-}
-
-/*
- * Dequeue a waiting thread from the head of a mutex queue in descending
- * priority order.
- */
-static inline pthread_t
-mutex_queue_deq(struct pthread_mutex *mutex)
-{
- pthread_t pthread;
-
- while ((pthread = TAILQ_FIRST(&mutex->m_queue)) != NULL) {
- TAILQ_REMOVE(&mutex->m_queue, pthread, sqe);
- pthread->sflags &= ~THR_FLAGS_IN_SYNCQ;
-
- /*
- * Only exit the loop if the thread hasn't been
- * cancelled.
- */
- if (pthread->interrupted == 0)
- break;
- }
-
- return (pthread);
-}
-
-/*
- * Remove a waiting thread from a mutex queue in descending priority order.
- */
-static inline void
-mutex_queue_remove(pthread_mutex_t mutex, pthread_t pthread)
-{
- if ((pthread->sflags & THR_FLAGS_IN_SYNCQ) != 0) {
- TAILQ_REMOVE(&mutex->m_queue, pthread, sqe);
- pthread->sflags &= ~THR_FLAGS_IN_SYNCQ;
- }
-}
-
-/*
- * Enqueue a waiting thread to a queue in descending priority order.
- */
-static inline void
-mutex_queue_enq(pthread_mutex_t mutex, pthread_t pthread)
-{
- pthread_t tid = TAILQ_LAST(&mutex->m_queue, mutex_head);
-
- THR_ASSERT_NOT_IN_SYNCQ(pthread);
- /*
- * For the common case of all threads having equal priority,
- * we perform a quick check against the priority of the thread
- * at the tail of the queue.
- */
- if ((tid == NULL) || (pthread->active_priority <= tid->active_priority))
- TAILQ_INSERT_TAIL(&mutex->m_queue, pthread, sqe);
- else {
- tid = TAILQ_FIRST(&mutex->m_queue);
- while (pthread->active_priority <= tid->active_priority)
- tid = TAILQ_NEXT(tid, sqe);
- TAILQ_INSERT_BEFORE(tid, pthread, sqe);
- }
- pthread->sflags |= THR_FLAGS_IN_SYNCQ;
-}
diff --git a/lib/libkse/thread/thr_mutex_prioceiling.c b/lib/libkse/thread/thr_mutex_prioceiling.c
deleted file mode 100644
index a78b5d15c60d..000000000000
--- a/lib/libkse/thread/thr_mutex_prioceiling.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_mutexattr_getprioceiling, pthread_mutexattr_getprioceiling);
-__weak_reference(_pthread_mutexattr_setprioceiling, pthread_mutexattr_setprioceiling);
-__weak_reference(_pthread_mutex_getprioceiling, pthread_mutex_getprioceiling);
-__weak_reference(_pthread_mutex_setprioceiling, pthread_mutex_setprioceiling);
-
-int
-_pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling)
-{
- int ret = 0;
-
- if ((mattr == NULL) || (*mattr == NULL))
- ret = EINVAL;
- else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
- ret = EINVAL;
- else
- *prioceiling = (*mattr)->m_ceiling;
-
- return(ret);
-}
-
-int
-_pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
-{
- int ret = 0;
-
- if ((mattr == NULL) || (*mattr == NULL))
- ret = EINVAL;
- else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
- ret = EINVAL;
- else
- (*mattr)->m_ceiling = prioceiling;
-
- return(ret);
-}
-
-int
-_pthread_mutex_getprioceiling(pthread_mutex_t *mutex,
- int *prioceiling)
-{
- int ret;
-
- if ((mutex == NULL) || (*mutex == NULL))
- ret = EINVAL;
- else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT)
- ret = EINVAL;
- else
- ret = (*mutex)->m_prio;
-
- return(ret);
-}
-
-int
-_pthread_mutex_setprioceiling(pthread_mutex_t *mutex,
- int prioceiling, int *old_ceiling)
-{
- int ret = 0;
-
- if ((mutex == NULL) || (*mutex == NULL))
- ret = EINVAL;
- else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT)
- ret = EINVAL;
- /* Lock the mutex: */
- else if ((ret = pthread_mutex_lock(mutex)) == 0) {
- /* Return the old ceiling and set the new ceiling: */
- *old_ceiling = (*mutex)->m_prio;
- (*mutex)->m_prio = prioceiling;
-
- /* Unlock the mutex: */
- ret = pthread_mutex_unlock(mutex);
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_mutex_protocol.c b/lib/libkse/thread/thr_mutex_protocol.c
deleted file mode 100644
index 9f0f262667d8..000000000000
--- a/lib/libkse/thread/thr_mutex_protocol.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_mutexattr_getprotocol, pthread_mutexattr_getprotocol);
-__weak_reference(_pthread_mutexattr_setprotocol, pthread_mutexattr_setprotocol);
-
-int
-_pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol)
-{
- int ret = 0;
-
- if ((mattr == NULL) || (*mattr == NULL))
- ret = EINVAL;
- else
- *protocol = (*mattr)->m_protocol;
-
- return(ret);
-}
-
-int
-_pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
-{
- int ret = 0;
-
- if ((mattr == NULL) || (*mattr == NULL) ||
- (protocol < PTHREAD_PRIO_NONE) || (protocol > PTHREAD_PRIO_PROTECT))
- ret = EINVAL;
- else {
- (*mattr)->m_protocol = protocol;
- (*mattr)->m_ceiling = THR_MAX_PRIORITY;
- }
- return(ret);
-}
-
diff --git a/lib/libkse/thread/thr_mutexattr_destroy.c b/lib/libkse/thread/thr_mutexattr_destroy.c
deleted file mode 100644
index b9852b57a63c..000000000000
--- a/lib/libkse/thread/thr_mutexattr_destroy.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <stdlib.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_mutexattr_destroy, pthread_mutexattr_destroy);
-
-int
-_pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
-{
- int ret;
- if (attr == NULL || *attr == NULL) {
- ret = EINVAL;
- } else {
- free(*attr);
- *attr = NULL;
- ret = 0;
- }
- return(ret);
-}
diff --git a/lib/libkse/thread/thr_nanosleep.c b/lib/libkse/thread/thr_nanosleep.c
deleted file mode 100644
index bce354128063..000000000000
--- a/lib/libkse/thread/thr_nanosleep.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <stdio.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__nanosleep, nanosleep);
-
-int
-_nanosleep(const struct timespec *time_to_sleep,
- struct timespec *time_remaining)
-{
- struct pthread *curthread = _get_curthread();
- int ret = 0;
- struct timespec ts, ts1;
- struct timespec remaining_time;
-
- /* Check if the time to sleep is legal: */
- if ((time_to_sleep == NULL) || (time_to_sleep->tv_sec < 0) ||
- (time_to_sleep->tv_nsec < 0) ||
- (time_to_sleep->tv_nsec >= 1000000000)) {
- /* Return an EINVAL error : */
- errno = EINVAL;
- ret = -1;
- } else {
- if (!_kse_isthreaded())
- return __sys_nanosleep(time_to_sleep, time_remaining);
-
- KSE_GET_TOD(curthread->kse, &ts);
-
- /* Calculate the time for the current thread to wake up: */
- TIMESPEC_ADD(&curthread->wakeup_time, &ts, time_to_sleep);
-
- THR_LOCK_SWITCH(curthread);
- curthread->interrupted = 0;
- THR_SET_STATE(curthread, PS_SLEEP_WAIT);
-
- /* Reschedule the current thread to sleep: */
- _thr_sched_switch_unlocked(curthread);
-
- /* Calculate the remaining time to sleep: */
- KSE_GET_TOD(curthread->kse, &ts1);
- remaining_time.tv_sec = time_to_sleep->tv_sec
- + ts.tv_sec - ts1.tv_sec;
- remaining_time.tv_nsec = time_to_sleep->tv_nsec
- + ts.tv_nsec - ts1.tv_nsec;
-
- /* Check if the nanosecond field has underflowed: */
- if (remaining_time.tv_nsec < 0) {
- /* Handle the underflow: */
- remaining_time.tv_sec -= 1;
- remaining_time.tv_nsec += 1000000000;
- }
- /* Check if the nanosecond field has overflowed: */
- else if (remaining_time.tv_nsec >= 1000000000) {
- /* Handle the overflow: */
- remaining_time.tv_sec += 1;
- remaining_time.tv_nsec -= 1000000000;
- }
-
- /* Check if the sleep was longer than the required time: */
- if (remaining_time.tv_sec < 0) {
- /* Reset the time left: */
- remaining_time.tv_sec = 0;
- remaining_time.tv_nsec = 0;
- }
-
- /* Check if the time remaining is to be returned: */
- if (time_remaining != NULL) {
- /* Return the actual time slept: */
- time_remaining->tv_sec = remaining_time.tv_sec;
- time_remaining->tv_nsec = remaining_time.tv_nsec;
- }
-
- /* Check if the sleep was interrupted: */
- if (curthread->interrupted) {
- /* Return an EINTR error : */
- errno = EINTR;
- ret = -1;
- }
- }
- return (ret);
-}
-
-int
-__nanosleep(const struct timespec *time_to_sleep,
- struct timespec *time_remaining)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = _nanosleep(time_to_sleep, time_remaining);
- _thr_leave_cancellation_point(curthread);
-
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_once.c b/lib/libkse/thread/thr_once.c
deleted file mode 100644
index 152fdec7b407..000000000000
--- a/lib/libkse/thread/thr_once.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include "namespace.h"
-#include <pthread.h>
-#include "un-namespace.h"
-#include "thr_private.h"
-
-__weak_reference(_pthread_once, pthread_once);
-
-int
-_pthread_once(pthread_once_t *once_control, void (*init_routine) (void))
-{
- if (once_control->state == PTHREAD_NEEDS_INIT) {
- if (_thr_initial == NULL)
- _libpthread_init(NULL);
- _pthread_mutex_lock(&(once_control->mutex));
- if (once_control->state == PTHREAD_NEEDS_INIT) {
- init_routine();
- once_control->state = PTHREAD_DONE_INIT;
- }
- _pthread_mutex_unlock(&(once_control->mutex));
- }
- return (0);
-}
diff --git a/lib/libkse/thread/thr_open.c b/lib/libkse/thread/thr_open.c
deleted file mode 100644
index ec60ba4e723a..000000000000
--- a/lib/libkse/thread/thr_open.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- *
- */
-#include <stdarg.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__open, open);
-
-int
-__open(const char *path, int flags,...)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
- int mode = 0;
- va_list ap;
-
- _thr_enter_cancellation_point(curthread);
-
- /* Check if the file is being created: */
- if (flags & O_CREAT) {
- /* Get the creation mode: */
- va_start(ap, flags);
- mode = va_arg(ap, int);
- va_end(ap);
- }
-
- ret = __sys_open(path, flags, mode);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_pause.c b/lib/libkse/thread/thr_pause.c
deleted file mode 100644
index b6bcc51591ff..000000000000
--- a/lib/libkse/thread/thr_pause.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include <unistd.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pause, pause);
-
-int
-_pause(void)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __pause();
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_poll.c b/lib/libkse/thread/thr_poll.c
deleted file mode 100644
index 0b78047838e0..000000000000
--- a/lib/libkse/thread/thr_poll.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 1999 Daniel Eischen <eischen@vigrid.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <poll.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/fcntl.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__poll, poll);
-
-int
-__poll(struct pollfd *fds, unsigned int nfds, int timeout)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __sys_poll(fds, nfds, timeout);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_printf.c b/lib/libkse/thread/thr_printf.c
deleted file mode 100644
index f0791df46572..000000000000
--- a/lib/libkse/thread/thr_printf.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*-
- * Copyright (c) 2002 Jonathan Mini <mini@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdarg.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "thr_private.h"
-
-static void pchar(int fd, char c);
-static void pstr(int fd, const char *s);
-
-/*
- * Write formatted output to stdout, in a thread-safe manner.
- *
- * Recognises the following conversions:
- * %c -> char
- * %d -> signed int (base 10)
- * %s -> string
- * %u -> unsigned int (base 10)
- * %x -> unsigned int (base 16)
- * %p -> unsigned int (base 16)
- */
-void
-_thread_printf(int fd, const char *fmt, ...)
-{
- static const char digits[16] = "0123456789abcdef";
- va_list ap;
- char buf[10];
- char *s;
- unsigned r, u;
- int c, d;
-
- va_start(ap, fmt);
- while ((c = *fmt++)) {
- if (c == '%') {
- c = *fmt++;
- switch (c) {
- case 'c':
- pchar(fd, va_arg(ap, int));
- continue;
- case 's':
- pstr(fd, va_arg(ap, char *));
- continue;
- case 'd':
- case 'u':
- case 'p':
- case 'x':
- r = ((c == 'u') || (c == 'd')) ? 10 : 16;
- if (c == 'd') {
- d = va_arg(ap, unsigned);
- if (d < 0) {
- pchar(fd, '-');
- u = (unsigned)(d * -1);
- } else
- u = (unsigned)d;
- } else
- u = va_arg(ap, unsigned);
- s = buf;
- do {
- *s++ = digits[u % r];
- } while (u /= r);
- while (--s >= buf)
- pchar(fd, *s);
- continue;
- }
- }
- pchar(fd, c);
- }
- va_end(ap);
-}
-
-/*
- * Write a single character to stdout, in a thread-safe manner.
- */
-static void
-pchar(int fd, char c)
-{
-
- __sys_write(fd, &c, 1);
-}
-
-/*
- * Write a string to stdout, in a thread-safe manner.
- */
-static void
-pstr(int fd, const char *s)
-{
-
- __sys_write(fd, s, strlen(s));
-}
-
diff --git a/lib/libkse/thread/thr_priority_queue.c b/lib/libkse/thread/thr_priority_queue.c
deleted file mode 100644
index 2822aa81e7c4..000000000000
--- a/lib/libkse/thread/thr_priority_queue.c
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <stdlib.h>
-#include <sys/queue.h>
-#include <string.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-/* Prototypes: */
-static void pq_insert_prio_list(pq_queue_t *pq, int prio);
-
-#if defined(_PTHREADS_INVARIANTS)
-
-#define PQ_IN_SCHEDQ (THR_FLAGS_IN_RUNQ | THR_FLAGS_IN_WAITQ)
-
-#define PQ_SET_ACTIVE(pq) (pq)->pq_flags |= PQF_ACTIVE
-#define PQ_CLEAR_ACTIVE(pq) (pq)->pq_flags &= ~PQF_ACTIVE
-#define PQ_ASSERT_ACTIVE(pq, msg) do { \
- if (((pq)->pq_flags & PQF_ACTIVE) == 0) \
- PANIC(msg); \
-} while (0)
-#define PQ_ASSERT_INACTIVE(pq, msg) do { \
- if (((pq)->pq_flags & PQF_ACTIVE) != 0) \
- PANIC(msg); \
-} while (0)
-#define PQ_ASSERT_IN_WAITQ(thrd, msg) do { \
- if (((thrd)->flags & THR_FLAGS_IN_WAITQ) == 0) \
- PANIC(msg); \
-} while (0)
-#define PQ_ASSERT_IN_RUNQ(thrd, msg) do { \
- if (((thrd)->flags & THR_FLAGS_IN_RUNQ) == 0) \
- PANIC(msg); \
-} while (0)
-#define PQ_ASSERT_NOT_QUEUED(thrd, msg) do { \
- if (((thrd)->flags & PQ_IN_SCHEDQ) != 0) \
- PANIC(msg); \
-} while (0)
-
-#else
-
-#define PQ_SET_ACTIVE(pq)
-#define PQ_CLEAR_ACTIVE(pq)
-#define PQ_ASSERT_ACTIVE(pq, msg)
-#define PQ_ASSERT_INACTIVE(pq, msg)
-#define PQ_ASSERT_IN_WAITQ(thrd, msg)
-#define PQ_ASSERT_IN_RUNQ(thrd, msg)
-#define PQ_ASSERT_NOT_QUEUED(thrd, msg)
-
-#endif
-
-int
-_pq_alloc(pq_queue_t *pq, int minprio, int maxprio)
-{
- int ret = 0;
- int prioslots = maxprio - minprio + 1;
-
- if (pq == NULL)
- ret = -1;
-
- /* Create the priority queue with (maxprio - minprio + 1) slots: */
- else if ((pq->pq_lists =
- (pq_list_t *) malloc(sizeof(pq_list_t) * prioslots)) == NULL)
- ret = -1;
-
- else {
- /* Remember the queue size: */
- pq->pq_size = prioslots;
- ret = _pq_init(pq);
- }
- return (ret);
-}
-
-void
-_pq_free(pq_queue_t *pq)
-{
- if ((pq != NULL) && (pq->pq_lists != NULL))
- free(pq->pq_lists);
-}
-
-int
-_pq_init(pq_queue_t *pq)
-{
- int i, ret = 0;
-
- if ((pq == NULL) || (pq->pq_lists == NULL))
- ret = -1;
-
- else {
- /* Initialize the queue for each priority slot: */
- for (i = 0; i < pq->pq_size; i++) {
- TAILQ_INIT(&pq->pq_lists[i].pl_head);
- pq->pq_lists[i].pl_prio = i;
- pq->pq_lists[i].pl_queued = 0;
- }
- /* Initialize the priority queue: */
- TAILQ_INIT(&pq->pq_queue);
- pq->pq_flags = 0;
- pq->pq_threads = 0;
- }
- return (ret);
-}
-
-void
-_pq_remove(pq_queue_t *pq, pthread_t pthread)
-{
- int prio = pthread->active_priority;
-
- /*
- * Make some assertions when debugging is enabled:
- */
- PQ_ASSERT_INACTIVE(pq, "_pq_remove: pq_active");
- PQ_SET_ACTIVE(pq);
- PQ_ASSERT_IN_RUNQ(pthread, "_pq_remove: Not in priority queue");
-
- /*
- * Remove this thread from priority list. Note that if
- * the priority list becomes empty, it is not removed
- * from the priority queue because another thread may be
- * added to the priority list (resulting in a needless
- * removal/insertion). Priority lists are only removed
- * from the priority queue when _pq_first is called.
- */
- TAILQ_REMOVE(&pq->pq_lists[prio].pl_head, pthread, pqe);
- pq->pq_threads--;
- /* This thread is now longer in the priority queue. */
- pthread->flags &= ~THR_FLAGS_IN_RUNQ;
-
- PQ_CLEAR_ACTIVE(pq);
-}
-
-
-void
-_pq_insert_head(pq_queue_t *pq, pthread_t pthread)
-{
- int prio;
-
- /*
- * Make some assertions when debugging is enabled:
- */
- PQ_ASSERT_INACTIVE(pq, "_pq_insert_head: pq_active");
- PQ_SET_ACTIVE(pq);
- PQ_ASSERT_NOT_QUEUED(pthread,
- "_pq_insert_head: Already in priority queue");
-
- prio = pthread->active_priority;
- TAILQ_INSERT_HEAD(&pq->pq_lists[prio].pl_head, pthread, pqe);
- if (pq->pq_lists[prio].pl_queued == 0)
- /* Insert the list into the priority queue: */
- pq_insert_prio_list(pq, prio);
- pq->pq_threads++;
- /* Mark this thread as being in the priority queue. */
- pthread->flags |= THR_FLAGS_IN_RUNQ;
-
- PQ_CLEAR_ACTIVE(pq);
-}
-
-
-void
-_pq_insert_tail(pq_queue_t *pq, pthread_t pthread)
-{
- int prio;
-
- /*
- * Make some assertions when debugging is enabled:
- */
- PQ_ASSERT_INACTIVE(pq, "_pq_insert_tail: pq_active");
- PQ_SET_ACTIVE(pq);
- PQ_ASSERT_NOT_QUEUED(pthread,
- "_pq_insert_tail: Already in priority queue");
-
- prio = pthread->active_priority;
- TAILQ_INSERT_TAIL(&pq->pq_lists[prio].pl_head, pthread, pqe);
- if (pq->pq_lists[prio].pl_queued == 0)
- /* Insert the list into the priority queue: */
- pq_insert_prio_list(pq, prio);
- pq->pq_threads++;
- /* Mark this thread as being in the priority queue. */
- pthread->flags |= THR_FLAGS_IN_RUNQ;
-
- PQ_CLEAR_ACTIVE(pq);
-}
-
-
-pthread_t
-_pq_first(pq_queue_t *pq)
-{
- pq_list_t *pql;
- pthread_t pthread = NULL;
-
- /*
- * Make some assertions when debugging is enabled:
- */
- PQ_ASSERT_INACTIVE(pq, "_pq_first: pq_active");
- PQ_SET_ACTIVE(pq);
-
- while (((pql = TAILQ_FIRST(&pq->pq_queue)) != NULL) &&
- (pthread == NULL)) {
- if ((pthread = TAILQ_FIRST(&pql->pl_head)) == NULL) {
- /*
- * The priority list is empty; remove the list
- * from the queue.
- */
- TAILQ_REMOVE(&pq->pq_queue, pql, pl_link);
-
- /* Mark the list as not being in the queue: */
- pql->pl_queued = 0;
- }
- }
-
- PQ_CLEAR_ACTIVE(pq);
- return (pthread);
-}
-
-
-static void
-pq_insert_prio_list(pq_queue_t *pq, int prio)
-{
- pq_list_t *pql;
-
- /*
- * Make some assertions when debugging is enabled:
- */
- PQ_ASSERT_ACTIVE(pq, "pq_insert_prio_list: pq_active");
-
- /*
- * The priority queue is in descending priority order. Start at
- * the beginning of the queue and find the list before which the
- * new list should be inserted.
- */
- pql = TAILQ_FIRST(&pq->pq_queue);
- while ((pql != NULL) && (pql->pl_prio > prio))
- pql = TAILQ_NEXT(pql, pl_link);
-
- /* Insert the list: */
- if (pql == NULL)
- TAILQ_INSERT_TAIL(&pq->pq_queue, &pq->pq_lists[prio], pl_link);
- else
- TAILQ_INSERT_BEFORE(pql, &pq->pq_lists[prio], pl_link);
-
- /* Mark this list as being in the queue: */
- pq->pq_lists[prio].pl_queued = 1;
-}
diff --git a/lib/libkse/thread/thr_private.h b/lib/libkse/thread/thr_private.h
deleted file mode 100644
index 092f86d84262..000000000000
--- a/lib/libkse/thread/thr_private.h
+++ /dev/null
@@ -1,1232 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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.
- *
- * Private thread definitions for the uthread kernel.
- *
- * $FreeBSD$
- */
-
-#ifndef _THR_PRIVATE_H
-#define _THR_PRIVATE_H
-
-/*
- * Include files.
- */
-#include <setjmp.h>
-#include <signal.h>
-#include <stdio.h>
-#include <sys/queue.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/cdefs.h>
-#include <sys/kse.h>
-#include <sched.h>
-#include <ucontext.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <pthread_np.h>
-
-#include "ksd.h"
-#include "lock.h"
-#include "pthread_md.h"
-
-/*
- * Evaluate the storage class specifier.
- */
-#ifdef GLOBAL_PTHREAD_PRIVATE
-#define SCLASS
-#define SCLASS_PRESET(x...) = x
-#else
-#define SCLASS extern
-#define SCLASS_PRESET(x...)
-#endif
-
-/*
- * Kernel fatal error handler macro.
- */
-#define PANIC(string) _thr_exit(__FILE__,__LINE__,string)
-
-
-/* Output debug messages like this: */
-#define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args)
-#define stderr_debug(args...) _thread_printf(STDOUT_FILENO, ##args)
-
-#define DBG_MUTEX 0x0001
-#define DBG_SIG 0x0002
-
-
-#define THR_ASSERT(cond, msg) do { \
- if (!(cond)) \
- PANIC(msg); \
-} while (0)
-
-
-/*
- * State change macro without scheduling queue change:
- */
-#define THR_SET_STATE(thrd, newstate) do { \
- (thrd)->state = newstate; \
- (thrd)->fname = __FILE__; \
- (thrd)->lineno = __LINE__; \
-} while (0)
-
-
-/*
- * Define the signals to be used for scheduling.
- */
-#define _ITIMER_SCHED_TIMER ITIMER_PROF
-#define _SCHED_SIGNAL SIGPROF
-
-#define TIMESPEC_ADD(dst, src, val) \
- do { \
- (dst)->tv_sec = (src)->tv_sec + (val)->tv_sec; \
- (dst)->tv_nsec = (src)->tv_nsec + (val)->tv_nsec; \
- if ((dst)->tv_nsec > 1000000000) { \
- (dst)->tv_sec++; \
- (dst)->tv_nsec -= 1000000000; \
- } \
- } while (0)
-
-#define TIMESPEC_SUB(dst, src, val) \
- do { \
- (dst)->tv_sec = (src)->tv_sec - (val)->tv_sec; \
- (dst)->tv_nsec = (src)->tv_nsec - (val)->tv_nsec; \
- if ((dst)->tv_nsec < 0) { \
- (dst)->tv_sec--; \
- (dst)->tv_nsec += 1000000000; \
- } \
- } while (0)
-
-/*
- * Priority queues.
- *
- * XXX It'd be nice if these were contained in uthread_priority_queue.[ch].
- */
-typedef struct pq_list {
- TAILQ_HEAD(, pthread) pl_head; /* list of threads at this priority */
- TAILQ_ENTRY(pq_list) pl_link; /* link for queue of priority lists */
- int pl_prio; /* the priority of this list */
- int pl_queued; /* is this in the priority queue */
-} pq_list_t;
-
-typedef struct pq_queue {
- TAILQ_HEAD(, pq_list) pq_queue; /* queue of priority lists */
- pq_list_t *pq_lists; /* array of all priority lists */
- int pq_size; /* number of priority lists */
-#define PQF_ACTIVE 0x0001
- int pq_flags;
- int pq_threads;
-} pq_queue_t;
-
-/*
- * Each KSEG has a scheduling queue. For now, threads that exist in their
- * own KSEG (system scope) will get a full priority queue. In the future
- * this can be optimized for the single thread per KSEG case.
- */
-struct sched_queue {
- pq_queue_t sq_runq;
- TAILQ_HEAD(, pthread) sq_waitq; /* waiting in userland */
-};
-
-/* Used to maintain pending and active signals: */
-struct sigstatus {
- siginfo_t *info; /* arg 2 to signal handler */
- int pending; /* Is this a pending signal? */
- int blocked; /*
- * This signal has occured and hasn't
- * yet been handled; ignore subsequent
- * signals until the handler is done.
- */
- int signo;
-};
-
-typedef struct kse_thr_mailbox *kse_critical_t;
-
-struct kse_group;
-
-#define MAX_KSE_LOCKLEVEL 3
-struct kse {
- struct kse_mailbox k_mbx; /* kernel kse mailbox */
- /* -- location and order specific items for gdb -- */
- struct pthread *k_curthread; /* current thread */
- struct kse_group *k_kseg; /* parent KSEG */
- struct sched_queue *k_schedq; /* scheduling queue */
- /* -- end of location and order specific items -- */
- TAILQ_ENTRY(kse) k_qe; /* KSE list link entry */
- TAILQ_ENTRY(kse) k_kgqe; /* KSEG's KSE list entry */
- struct ksd k_ksd; /* KSE specific data */
- /*
- * Items that are only modified by the kse, or that otherwise
- * don't need to be locked when accessed
- */
- struct lock k_lock;
- struct lockuser k_lockusers[MAX_KSE_LOCKLEVEL];
- int k_locklevel;
- sigset_t k_sigmask;
- struct sigstatus k_sigq[NSIG];
- stack_t k_stack;
- int k_check_sigq;
- int k_flags;
-#define KF_STARTED 0x0001 /* kernel kse created */
-#define KF_INITIALIZED 0x0002 /* initialized on 1st upcall */
- int k_waiting;
- int k_idle; /* kse is idle */
- int k_error; /* syscall errno in critical */
- int k_cpu; /* CPU ID when bound */
- int k_done; /* this KSE is done */
-};
-
-/*
- * Each KSE group contains one or more KSEs in which threads can run.
- * At least for now, there is one scheduling queue per KSE group; KSEs
- * within the same KSE group compete for threads from the same scheduling
- * queue. A scope system thread has one KSE in one KSE group; the group
- * does not use its scheduling queue.
- */
-struct kse_group {
- TAILQ_HEAD(, kse) kg_kseq; /* list of KSEs in group */
- TAILQ_HEAD(, pthread) kg_threadq; /* list of threads in group */
- TAILQ_ENTRY(kse_group) kg_qe; /* link entry */
- struct sched_queue kg_schedq; /* scheduling queue */
- struct lock kg_lock;
- int kg_threadcount; /* # of assigned threads */
- int kg_ksecount; /* # of assigned KSEs */
- int kg_idle_kses;
- int kg_flags;
-#define KGF_SINGLE_THREAD 0x0001 /* scope system kse group */
-#define KGF_SCHEDQ_INITED 0x0002 /* has an initialized schedq */
-};
-
-/*
- * Add/remove threads from a KSE's scheduling queue.
- * For now the scheduling queue is hung off the KSEG.
- */
-#define KSEG_THRQ_ADD(kseg, thr) \
-do { \
- TAILQ_INSERT_TAIL(&(kseg)->kg_threadq, thr, kle);\
- (kseg)->kg_threadcount++; \
-} while (0)
-
-#define KSEG_THRQ_REMOVE(kseg, thr) \
-do { \
- TAILQ_REMOVE(&(kseg)->kg_threadq, thr, kle); \
- (kseg)->kg_threadcount--; \
-} while (0)
-
-
-/*
- * Lock acquire and release for KSEs.
- */
-#define KSE_LOCK_ACQUIRE(kse, lck) \
-do { \
- if ((kse)->k_locklevel >= MAX_KSE_LOCKLEVEL) \
- PANIC("Exceeded maximum lock level"); \
- else { \
- (kse)->k_locklevel++; \
- _lock_acquire((lck), \
- &(kse)->k_lockusers[(kse)->k_locklevel - 1], 0); \
- } \
-} while (0)
-
-#define KSE_LOCK_RELEASE(kse, lck) \
-do { \
- if ((kse)->k_locklevel > 0) { \
- _lock_release((lck), \
- &(kse)->k_lockusers[(kse)->k_locklevel - 1]); \
- (kse)->k_locklevel--; \
- } \
-} while (0)
-
-/*
- * Lock our own KSEG.
- */
-#define KSE_LOCK(curkse) \
- KSE_LOCK_ACQUIRE(curkse, &(curkse)->k_kseg->kg_lock)
-#define KSE_UNLOCK(curkse) \
- KSE_LOCK_RELEASE(curkse, &(curkse)->k_kseg->kg_lock)
-
-/*
- * Lock a potentially different KSEG.
- */
-#define KSE_SCHED_LOCK(curkse, kseg) \
- KSE_LOCK_ACQUIRE(curkse, &(kseg)->kg_lock)
-#define KSE_SCHED_UNLOCK(curkse, kseg) \
- KSE_LOCK_RELEASE(curkse, &(kseg)->kg_lock)
-
-/*
- * Waiting queue manipulation macros (using pqe link):
- */
-#define KSE_WAITQ_REMOVE(kse, thrd) \
-do { \
- if (((thrd)->flags & THR_FLAGS_IN_WAITQ) != 0) { \
- TAILQ_REMOVE(&(kse)->k_schedq->sq_waitq, thrd, pqe); \
- (thrd)->flags &= ~THR_FLAGS_IN_WAITQ; \
- } \
-} while (0)
-#define KSE_WAITQ_INSERT(kse, thrd) kse_waitq_insert(thrd)
-#define KSE_WAITQ_FIRST(kse) TAILQ_FIRST(&(kse)->k_schedq->sq_waitq)
-
-#define KSE_SET_WAIT(kse) atomic_store_rel_int(&(kse)->k_waiting, 1)
-
-#define KSE_CLEAR_WAIT(kse) atomic_store_rel_int(&(kse)->k_waiting, 0)
-
-#define KSE_WAITING(kse) (kse)->k_waiting != 0
-#define KSE_WAKEUP(kse) kse_wakeup(&(kse)->k_mbx)
-
-#define KSE_SET_IDLE(kse) ((kse)->k_idle = 1)
-#define KSE_CLEAR_IDLE(kse) ((kse)->k_idle = 0)
-#define KSE_IS_IDLE(kse) ((kse)->k_idle != 0)
-
-/*
- * TailQ initialization values.
- */
-#define TAILQ_INITIALIZER { NULL, NULL }
-
-/*
- * lock initialization values.
- */
-#define LCK_INITIALIZER { NULL, NULL, LCK_DEFAULT }
-
-struct pthread_mutex {
- /*
- * Lock for accesses to this structure.
- */
- struct lock m_lock;
- enum pthread_mutextype m_type;
- int m_protocol;
- TAILQ_HEAD(mutex_head, pthread) m_queue;
- struct pthread *m_owner;
- long m_flags;
- int m_count;
- int m_refcount;
-
- /*
- * Used for priority inheritence and protection.
- *
- * m_prio - For priority inheritence, the highest active
- * priority (threads locking the mutex inherit
- * this priority). For priority protection, the
- * ceiling priority of this mutex.
- * m_saved_prio - mutex owners inherited priority before
- * taking the mutex, restored when the owner
- * unlocks the mutex.
- */
- int m_prio;
- int m_saved_prio;
-
- /*
- * Link for list of all mutexes a thread currently owns.
- */
- TAILQ_ENTRY(pthread_mutex) m_qe;
-};
-
-/*
- * Flags for mutexes.
- */
-#define MUTEX_FLAGS_PRIVATE 0x01
-#define MUTEX_FLAGS_INITED 0x02
-#define MUTEX_FLAGS_BUSY 0x04
-
-/*
- * Static mutex initialization values.
- */
-#define PTHREAD_MUTEX_STATIC_INITIALIZER \
- { LCK_INITIALIZER, PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, \
- TAILQ_INITIALIZER, NULL, MUTEX_FLAGS_PRIVATE, 0, 0, 0, 0, \
- TAILQ_INITIALIZER }
-
-struct pthread_mutex_attr {
- enum pthread_mutextype m_type;
- int m_protocol;
- int m_ceiling;
- long m_flags;
-};
-
-#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \
- { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE }
-
-/*
- * Condition variable definitions.
- */
-enum pthread_cond_type {
- COND_TYPE_FAST,
- COND_TYPE_MAX
-};
-
-struct pthread_cond {
- /*
- * Lock for accesses to this structure.
- */
- struct lock c_lock;
- enum pthread_cond_type c_type;
- TAILQ_HEAD(cond_head, pthread) c_queue;
- struct pthread_mutex *c_mutex;
- long c_flags;
- long c_seqno;
-};
-
-struct pthread_cond_attr {
- enum pthread_cond_type c_type;
- long c_flags;
-};
-
-/*
- * Flags for condition variables.
- */
-#define COND_FLAGS_PRIVATE 0x01
-#define COND_FLAGS_INITED 0x02
-#define COND_FLAGS_BUSY 0x04
-
-/*
- * Static cond initialization values.
- */
-#define PTHREAD_COND_STATIC_INITIALIZER \
- { LCK_INITIALIZER, COND_TYPE_FAST, TAILQ_INITIALIZER, \
- NULL, NULL, 0, 0 }
-
-/*
- * Semaphore definitions.
- */
-struct sem {
-#define SEM_MAGIC ((u_int32_t) 0x09fa4012)
- u_int32_t magic;
- pthread_mutex_t lock;
- pthread_cond_t gtzero;
- u_int32_t count;
- u_int32_t nwaiters;
-};
-
-/*
- * Cleanup definitions.
- */
-struct pthread_cleanup {
- struct pthread_cleanup *next;
- void (*routine) ();
- void *routine_arg;
-};
-
-struct pthread_attr {
- int sched_policy;
- int sched_inherit;
- int sched_interval;
- int prio;
- int suspend;
-#define THR_STACK_USER 0x100 /* 0xFF reserved for <pthread.h> */
- int flags;
- void *arg_attr;
- void (*cleanup_attr) ();
- void *stackaddr_attr;
- size_t stacksize_attr;
- size_t guardsize_attr;
-};
-
-/*
- * Thread creation state attributes.
- */
-#define THR_CREATE_RUNNING 0
-#define THR_CREATE_SUSPENDED 1
-
-/*
- * Miscellaneous definitions.
- */
-#define THR_STACK_DEFAULT 65536
-
-/*
- * Maximum size of initial thread's stack. This perhaps deserves to be larger
- * than the stacks of other threads, since many applications are likely to run
- * almost entirely on this stack.
- */
-#define THR_STACK_INITIAL 0x100000
-
-/*
- * Define the different priority ranges. All applications have thread
- * priorities constrained within 0-31. The threads library raises the
- * priority when delivering signals in order to ensure that signal
- * delivery happens (from the POSIX spec) "as soon as possible".
- * In the future, the threads library will also be able to map specific
- * threads into real-time (cooperating) processes or kernel threads.
- * The RT and SIGNAL priorities will be used internally and added to
- * thread base priorities so that the scheduling queue can handle both
- * normal and RT priority threads with and without signal handling.
- *
- * The approach taken is that, within each class, signal delivery
- * always has priority over thread execution.
- */
-#define THR_DEFAULT_PRIORITY 15
-#define THR_MIN_PRIORITY 0
-#define THR_MAX_PRIORITY 31 /* 0x1F */
-#define THR_SIGNAL_PRIORITY 32 /* 0x20 */
-#define THR_RT_PRIORITY 64 /* 0x40 */
-#define THR_FIRST_PRIORITY THR_MIN_PRIORITY
-#define THR_LAST_PRIORITY \
- (THR_MAX_PRIORITY + THR_SIGNAL_PRIORITY + THR_RT_PRIORITY)
-#define THR_BASE_PRIORITY(prio) ((prio) & THR_MAX_PRIORITY)
-
-/*
- * Clock resolution in microseconds.
- */
-#define CLOCK_RES_USEC 10000
-
-/*
- * Time slice period in microseconds.
- */
-#define TIMESLICE_USEC 20000
-
-/*
- * XXX - Define a thread-safe macro to get the current time of day
- * which is updated at regular intervals by something.
- *
- * For now, we just make the system call to get the time.
- */
-#define KSE_GET_TOD(curkse, tsp) \
-do { \
- *tsp = (curkse)->k_mbx.km_timeofday; \
- if ((tsp)->tv_sec == 0) \
- clock_gettime(CLOCK_REALTIME, tsp); \
-} while (0)
-
-struct pthread_rwlockattr {
- int pshared;
-};
-
-struct pthread_rwlock {
- pthread_mutex_t lock; /* monitor lock */
- int state; /* 0 = idle >0 = # of readers -1 = writer */
- pthread_cond_t read_signal;
- pthread_cond_t write_signal;
- int blocked_writers;
-};
-
-/*
- * Thread states.
- */
-enum pthread_state {
- PS_RUNNING,
- PS_LOCKWAIT,
- PS_MUTEX_WAIT,
- PS_COND_WAIT,
- PS_SLEEP_WAIT,
- PS_SIGSUSPEND,
- PS_SIGWAIT,
- PS_JOIN,
- PS_SUSPENDED,
- PS_DEAD,
- PS_DEADLOCK,
- PS_STATE_MAX
-};
-
-
-union pthread_wait_data {
- pthread_mutex_t mutex;
- pthread_cond_t cond;
- const sigset_t *sigwait; /* Waiting on a signal in sigwait */
- struct lock *lock;
-};
-
-/*
- * Define a continuation routine that can be used to perform a
- * transfer of control:
- */
-typedef void (*thread_continuation_t) (void *);
-
-/*
- * This stores a thread's state prior to running a signal handler.
- * It is used when a signal is delivered to a thread blocked in
- * userland. If the signal handler returns normally, the thread's
- * state is restored from here.
- */
-struct pthread_sigframe {
- int psf_flags;
- int psf_interrupted;
- int psf_signo;
- enum pthread_state psf_state;
- union pthread_wait_data psf_wait_data;
- struct timespec psf_wakeup_time;
- sigset_t psf_sigset;
- sigset_t psf_sigmask;
- int psf_seqno;
-};
-
-struct join_status {
- struct pthread *thread;
- void *ret;
- int error;
-};
-
-struct pthread_specific_elem {
- const void *data;
- int seqno;
-};
-
-
-#define MAX_THR_LOCKLEVEL 3
-/*
- * Thread structure.
- */
-struct pthread {
- /*
- * Thread mailbox is first so it cal be aligned properly.
- */
- struct kse_thr_mailbox tmbx;
- void *alloc_addr; /* real address (unaligned) */
-
- /*
- * Magic value to help recognize a valid thread structure
- * from an invalid one:
- */
-#define THR_MAGIC ((u_int32_t) 0xd09ba115)
- u_int32_t magic;
- char *name;
- u_int64_t uniqueid; /* for gdb */
-
- /* Queue entry for list of all threads: */
- TAILQ_ENTRY(pthread) tle; /* link for all threads in process */
- TAILQ_ENTRY(pthread) kle; /* link for all threads in KSE/KSEG */
-
- /* Queue entry for GC lists: */
- TAILQ_ENTRY(pthread) gcle;
-
- /*
- * Lock for accesses to this thread structure.
- */
- struct lock lock;
- struct lockuser lockusers[MAX_THR_LOCKLEVEL];
- int locklevel;
- kse_critical_t critical[MAX_KSE_LOCKLEVEL];
- struct kse *kse;
- struct kse_group *kseg;
-
- /*
- * Thread start routine, argument, stack pointer and thread
- * attributes.
- */
- void *(*start_routine)(void *);
- void *arg;
- struct pthread_attr attr;
-
- int active; /* thread running */
- int blocked; /* thread blocked in kernel */
- int need_switchout;
- int need_wakeup;
-
- /*
- * Used for tracking delivery of signal handlers.
- */
- struct pthread_sigframe *curframe;
- siginfo_t siginfo[NSIG];
-
- /*
- * Cancelability flags - the lower 2 bits are used by cancel
- * definitions in pthread.h
- */
-#define THR_AT_CANCEL_POINT 0x0004
-#define THR_CANCELLING 0x0008
-#define THR_CANCEL_NEEDED 0x0010
- int cancelflags;
-
- thread_continuation_t continuation;
-
- /*
- * The thread's base and pending signal masks. The active
- * signal mask is stored in the thread's context (in mailbox).
- */
- sigset_t sigmask;
- sigset_t sigpend;
- int sigmask_seqno;
- int check_pending;
- int have_signals;
- int refcount;
-
- /* Thread state: */
- enum pthread_state state;
- volatile int lock_switch;
-
- /*
- * Number of microseconds accumulated by this thread when
- * time slicing is active.
- */
- long slice_usec;
-
- /*
- * Time to wake up thread. This is used for sleeping threads and
- * for any operation which may time out (such as select).
- */
- struct timespec wakeup_time;
-
- /* TRUE if operation has timed out. */
- int timeout;
-
- /*
- * Error variable used instead of errno. The function __error()
- * returns a pointer to this.
- */
- int error;
-
- /*
- * The joiner is the thread that is joining to this thread. The
- * join status keeps track of a join operation to another thread.
- */
- struct pthread *joiner;
- struct join_status join_status;
-
- /*
- * The current thread can belong to only one scheduling queue at
- * a time (ready or waiting queue). It can also belong to:
- *
- * o A queue of threads waiting for a mutex
- * o A queue of threads waiting for a condition variable
- *
- * It is possible for a thread to belong to more than one of the
- * above queues if it is handling a signal. A thread may only
- * enter a mutex or condition variable queue when it is not
- * being called from a signal handler. If a thread is a member
- * of one of these queues when a signal handler is invoked, it
- * must be removed from the queue before invoking the handler
- * and then added back to the queue after return from the handler.
- *
- * Use pqe for the scheduling queue link (both ready and waiting),
- * sqe for synchronization (mutex, condition variable, and join)
- * queue links, and qe for all other links.
- */
- TAILQ_ENTRY(pthread) pqe; /* priority, wait queues link */
- TAILQ_ENTRY(pthread) sqe; /* synchronization queue link */
-
- /* Wait data. */
- union pthread_wait_data data;
-
- /*
- * Set to TRUE if a blocking operation was
- * interrupted by a signal:
- */
- int interrupted;
-
- /* Signal number when in state PS_SIGWAIT: */
- int signo;
-
- /*
- * Set to non-zero when this thread has entered a critical
- * region. We allow for recursive entries into critical regions.
- */
- int critical_count;
-
- /*
- * Set to TRUE if this thread should yield after leaving a
- * critical region to check for signals, messages, etc.
- */
- int critical_yield;
-
- int sflags;
-#define THR_FLAGS_IN_SYNCQ 0x0001
-
- /* Miscellaneous flags; only set with scheduling lock held. */
- int flags;
-#define THR_FLAGS_PRIVATE 0x0001
-#define THR_FLAGS_IN_WAITQ 0x0002 /* in waiting queue using pqe link */
-#define THR_FLAGS_IN_RUNQ 0x0004 /* in run queue using pqe link */
-#define THR_FLAGS_EXITING 0x0008 /* thread is exiting */
-#define THR_FLAGS_SUSPENDED 0x0010 /* thread is suspended */
-#define THR_FLAGS_GC_SAFE 0x0020 /* thread safe for cleaning */
-#define THR_FLAGS_IN_TDLIST 0x0040 /* thread in all thread list */
-#define THR_FLAGS_IN_GCLIST 0x0080 /* thread in gc list */
- /*
- * Base priority is the user setable and retrievable priority
- * of the thread. It is only affected by explicit calls to
- * set thread priority and upon thread creation via a thread
- * attribute or default priority.
- */
- char base_priority;
-
- /*
- * Inherited priority is the priority a thread inherits by
- * taking a priority inheritence or protection mutex. It
- * is not affected by base priority changes. Inherited
- * priority defaults to and remains 0 until a mutex is taken
- * that is being waited on by any other thread whose priority
- * is non-zero.
- */
- char inherited_priority;
-
- /*
- * Active priority is always the maximum of the threads base
- * priority and inherited priority. When there is a change
- * in either the base or inherited priority, the active
- * priority must be recalculated.
- */
- char active_priority;
-
- /* Number of priority ceiling or protection mutexes owned. */
- int priority_mutex_count;
-
- /*
- * Queue of currently owned mutexes.
- */
- TAILQ_HEAD(, pthread_mutex) mutexq;
-
- void *ret;
- struct pthread_specific_elem *specific;
- int specific_data_count;
-
- /*
- * Current locks bitmap for rtld.
- */
- int rtld_bits;
-
- /* Cleanup handlers Link List */
- struct pthread_cleanup *cleanup;
- char *fname; /* Ptr to source file name */
- int lineno; /* Source line number. */
-};
-
-/*
- * Critical regions can also be detected by looking at the threads
- * current lock level. Ensure these macros increment and decrement
- * the lock levels such that locks can not be held with a lock level
- * of 0.
- */
-#define THR_IN_CRITICAL(thrd) \
- (((thrd)->locklevel > 0) || \
- ((thrd)->critical_count > 0))
-
-#define THR_YIELD_CHECK(thrd) \
-do { \
- if (((thrd)->critical_yield != 0) && \
- !(THR_IN_CRITICAL(thrd))) \
- _thr_sched_switch(thrd); \
- else if (((thrd)->check_pending != 0) && \
- !(THR_IN_CRITICAL(thrd))) \
- _thr_sig_check_pending(thrd); \
-} while (0)
-
-#define THR_LOCK_ACQUIRE(thrd, lck) \
-do { \
- if ((thrd)->locklevel >= MAX_THR_LOCKLEVEL) \
- PANIC("Exceeded maximum lock level"); \
- else { \
- THR_DEACTIVATE_LAST_LOCK(thrd); \
- (thrd)->locklevel++; \
- _lock_acquire((lck), \
- &(thrd)->lockusers[(thrd)->locklevel - 1], \
- (thrd)->active_priority); \
- } \
-} while (0)
-
-#define THR_LOCK_RELEASE(thrd, lck) \
-do { \
- if ((thrd)->locklevel > 0) { \
- _lock_release((lck), \
- &(thrd)->lockusers[(thrd)->locklevel - 1]); \
- (thrd)->locklevel--; \
- THR_ACTIVATE_LAST_LOCK(thrd); \
- if ((thrd)->locklevel == 0) \
- THR_YIELD_CHECK(thrd); \
- } \
-} while (0)
-
-#define THR_ACTIVATE_LAST_LOCK(thrd) \
-do { \
- if ((thrd)->locklevel > 0) \
- _lockuser_setactive( \
- &(thrd)->lockusers[(thrd)->locklevel - 1], 1); \
-} while (0)
-
-#define THR_DEACTIVATE_LAST_LOCK(thrd) \
-do { \
- if ((thrd)->locklevel > 0) \
- _lockuser_setactive( \
- &(thrd)->lockusers[(thrd)->locklevel - 1], 0); \
-} while (0)
-
-/*
- * For now, threads will have their own lock separate from their
- * KSE scheduling lock.
- */
-#define THR_LOCK(thr) THR_LOCK_ACQUIRE(thr, &(thr)->lock)
-#define THR_UNLOCK(thr) THR_LOCK_RELEASE(thr, &(thr)->lock)
-#define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock)
-#define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock)
-
-/*
- * Priority queue manipulation macros (using pqe link). We use
- * the thread's kseg link instead of the kse link because a thread
- * does not (currently) have a statically assigned kse.
- */
-#define THR_RUNQ_INSERT_HEAD(thrd) \
- _pq_insert_head(&(thrd)->kseg->kg_schedq.sq_runq, thrd)
-#define THR_RUNQ_INSERT_TAIL(thrd) \
- _pq_insert_tail(&(thrd)->kseg->kg_schedq.sq_runq, thrd)
-#define THR_RUNQ_REMOVE(thrd) \
- _pq_remove(&(thrd)->kseg->kg_schedq.sq_runq, thrd)
-#define THR_RUNQ_FIRST() \
- _pq_first(&(thrd)->kseg->kg_schedq.sq_runq)
-
-/*
- * Macros to insert/remove threads to the all thread list and
- * the gc list.
- */
-#define THR_LIST_ADD(thrd) do { \
- if (((thrd)->flags & THR_FLAGS_IN_TDLIST) == 0) { \
- TAILQ_INSERT_HEAD(&_thread_list, thrd, tle); \
- (thrd)->flags |= THR_FLAGS_IN_TDLIST; \
- } \
-} while (0)
-#define THR_LIST_REMOVE(thrd) do { \
- if (((thrd)->flags & THR_FLAGS_IN_TDLIST) != 0) { \
- TAILQ_REMOVE(&_thread_list, thrd, tle); \
- (thrd)->flags &= ~THR_FLAGS_IN_TDLIST; \
- } \
-} while (0)
-#define THR_GCLIST_ADD(thrd) do { \
- if (((thrd)->flags & THR_FLAGS_IN_GCLIST) == 0) { \
- TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, gcle);\
- (thrd)->flags |= THR_FLAGS_IN_GCLIST; \
- _gc_count++; \
- } \
-} while (0)
-#define THR_GCLIST_REMOVE(thrd) do { \
- if (((thrd)->flags & THR_FLAGS_IN_GCLIST) != 0) { \
- TAILQ_REMOVE(&_thread_gc_list, thrd, gcle); \
- (thrd)->flags &= ~THR_FLAGS_IN_GCLIST; \
- _gc_count--; \
- } \
-} while (0)
-
-#define GC_NEEDED() (atomic_load_acq_int(&_gc_count) >= 5)
-
-/*
- * Locking the scheduling queue for another thread uses that thread's
- * KSEG lock.
- */
-#define THR_SCHED_LOCK(curthr, thr) do { \
- (curthr)->critical[(curthr)->locklevel] = _kse_critical_enter(); \
- (curthr)->locklevel++; \
- KSE_SCHED_LOCK((curthr)->kse, (thr)->kseg); \
-} while (0)
-
-#define THR_SCHED_UNLOCK(curthr, thr) do { \
- KSE_SCHED_UNLOCK((curthr)->kse, (thr)->kseg); \
- (curthr)->locklevel--; \
- _kse_critical_leave((curthr)->critical[(curthr)->locklevel]); \
-} while (0)
-
-/* Take the scheduling lock with the intent to call the scheduler. */
-#define THR_LOCK_SWITCH(curthr) do { \
- (void)_kse_critical_enter(); \
- KSE_SCHED_LOCK((curthr)->kse, (curthr)->kseg); \
-} while (0)
-
-#define THR_CRITICAL_ENTER(thr) (thr)->critical_count++
-#define THR_CRITICAL_LEAVE(thr) do { \
- (thr)->critical_count--; \
- if (((thr)->critical_yield != 0) && \
- ((thr)->critical_count == 0)) { \
- (thr)->critical_yield = 0; \
- _thr_sched_switch(thr); \
- } \
-} while (0)
-
-#define THR_IS_ACTIVE(thrd) \
- ((thrd)->kse != NULL) && ((thrd)->kse->k_curthread == (thrd))
-
-#define THR_IN_SYNCQ(thrd) (((thrd)->sflags & THR_FLAGS_IN_SYNCQ) != 0)
-
-#define THR_IS_SUSPENDED(thrd) \
- (((thrd)->state == PS_SUSPENDED) || \
- (((thrd)->flags & THR_FLAGS_SUSPENDED) != 0))
-#define THR_IS_EXITING(thrd) (((thrd)->flags & THR_FLAGS_EXITING) != 0)
-
-/*
- * Global variables for the pthread kernel.
- */
-
-SCLASS void *_usrstack SCLASS_PRESET(NULL);
-SCLASS struct kse *_kse_initial SCLASS_PRESET(NULL);
-SCLASS struct pthread *_thr_initial SCLASS_PRESET(NULL);
-
-/* List of all threads: */
-SCLASS TAILQ_HEAD(, pthread) _thread_list
- SCLASS_PRESET(TAILQ_HEAD_INITIALIZER(_thread_list));
-
-/* List of threads needing GC: */
-SCLASS TAILQ_HEAD(, pthread) _thread_gc_list
- SCLASS_PRESET(TAILQ_HEAD_INITIALIZER(_thread_gc_list));
-
-/* Default thread attributes: */
-SCLASS struct pthread_attr _pthread_attr_default
- SCLASS_PRESET({
- SCHED_RR, 0, TIMESLICE_USEC, THR_DEFAULT_PRIORITY,
- THR_CREATE_RUNNING, PTHREAD_CREATE_JOINABLE, NULL,
- NULL, NULL, THR_STACK_DEFAULT
- });
-
-/* Default mutex attributes: */
-SCLASS struct pthread_mutex_attr _pthread_mutexattr_default
- SCLASS_PRESET({PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, 0 });
-
-/* Default condition variable attributes: */
-SCLASS struct pthread_cond_attr _pthread_condattr_default
- SCLASS_PRESET({COND_TYPE_FAST, 0});
-
-/* Clock resolution in usec. */
-SCLASS int _clock_res_usec SCLASS_PRESET(CLOCK_RES_USEC);
-
-/* Array of signal actions for this process: */
-SCLASS struct sigaction _thread_sigact[NSIG];
-
-/*
- * Array of counts of dummy handlers for SIG_DFL signals. This is used to
- * assure that there is always a dummy signal handler installed while there
- * is a thread sigwait()ing on the corresponding signal.
- */
-SCLASS int _thread_dfl_count[NSIG];
-
-/*
- * Lock for above count of dummy handlers and for the process signal
- * mask and pending signal sets.
- */
-SCLASS struct lock _thread_signal_lock;
-
-/* Pending signals and mask for this process: */
-SCLASS sigset_t _thr_proc_sigpending;
-SCLASS sigset_t _thr_proc_sigmask SCLASS_PRESET({{0, 0, 0, 0}});
-SCLASS siginfo_t _thr_proc_siginfo[NSIG];
-
-SCLASS pid_t _thr_pid SCLASS_PRESET(0);
-
-/* Garbage collector lock. */
-SCLASS struct lock _gc_lock;
-SCLASS int _gc_check SCLASS_PRESET(0);
-SCLASS int _gc_count SCLASS_PRESET(0);
-
-SCLASS struct lock _mutex_static_lock;
-SCLASS struct lock _rwlock_static_lock;
-SCLASS struct lock _keytable_lock;
-SCLASS struct lock _thread_list_lock;
-SCLASS int _thr_guard_default;
-SCLASS int _thr_page_size;
-
-SCLASS int _thr_debug_flags SCLASS_PRESET(0);
-
-/* Undefine the storage class and preset specifiers: */
-#undef SCLASS
-#undef SCLASS_PRESET
-
-
-/*
- * Function prototype definitions.
- */
-__BEGIN_DECLS
-int _cond_reinit(pthread_cond_t *);
-void _cond_wait_backout(struct pthread *);
-struct pthread *_get_curthread(void);
-struct kse *_get_curkse(void);
-void _set_curkse(struct kse *);
-struct kse *_kse_alloc(struct pthread *);
-kse_critical_t _kse_critical_enter(void);
-void _kse_critical_leave(kse_critical_t);
-int _kse_in_critical(void);
-void _kse_free(struct pthread *, struct kse *);
-void _kse_init();
-struct kse_group *_kseg_alloc(struct pthread *);
-void _kse_lock_wait(struct lock *, struct lockuser *lu);
-void _kse_lock_wakeup(struct lock *, struct lockuser *lu);
-void _kse_sig_check_pending(struct kse *);
-void _kse_single_thread(struct pthread *);
-void _kse_start(struct kse *);
-int _kse_setthreaded(int);
-int _kse_isthreaded(void);
-void _kseg_free(struct kse_group *);
-int _mutex_cv_lock(pthread_mutex_t *);
-int _mutex_cv_unlock(pthread_mutex_t *);
-void _mutex_lock_backout(struct pthread *);
-void _mutex_notify_priochange(struct pthread *, struct pthread *, int);
-int _mutex_reinit(struct pthread_mutex *);
-void _mutex_unlock_private(struct pthread *);
-void _libpthread_init(struct pthread *);
-int _pq_alloc(struct pq_queue *, int, int);
-void _pq_free(struct pq_queue *);
-int _pq_init(struct pq_queue *);
-void _pq_remove(struct pq_queue *pq, struct pthread *);
-void _pq_insert_head(struct pq_queue *pq, struct pthread *);
-void _pq_insert_tail(struct pq_queue *pq, struct pthread *);
-struct pthread *_pq_first(struct pq_queue *pq);
-void *_pthread_getspecific(pthread_key_t);
-int _pthread_key_create(pthread_key_t *, void (*) (void *));
-int _pthread_key_delete(pthread_key_t);
-int _pthread_mutex_destroy(pthread_mutex_t *);
-int _pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *);
-int _pthread_mutex_lock(pthread_mutex_t *);
-int _pthread_mutex_trylock(pthread_mutex_t *);
-int _pthread_mutex_unlock(pthread_mutex_t *);
-int _pthread_mutexattr_init(pthread_mutexattr_t *);
-int _pthread_mutexattr_destroy(pthread_mutexattr_t *);
-int _pthread_mutexattr_settype(pthread_mutexattr_t *, int);
-int _pthread_once(pthread_once_t *, void (*) (void));
-int _pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *);
-int _pthread_rwlock_destroy (pthread_rwlock_t *);
-struct pthread *_pthread_self(void);
-int _pthread_setspecific(pthread_key_t, const void *);
-struct pthread *_thr_alloc(struct pthread *);
-int _thread_enter_uts(struct kse_thr_mailbox *, struct kse_mailbox *);
-int _thread_switch(struct kse_thr_mailbox *, struct kse_thr_mailbox **);
-void _thr_exit(char *, int, char *);
-void _thr_exit_cleanup(void);
-void _thr_lock_wait(struct lock *lock, struct lockuser *lu);
-void _thr_lock_wakeup(struct lock *lock, struct lockuser *lu);
-int _thr_ref_add(struct pthread *, struct pthread *, int);
-void _thr_ref_delete(struct pthread *, struct pthread *);
-int _thr_schedule_add(struct pthread *, struct pthread *);
-void _thr_schedule_remove(struct pthread *, struct pthread *);
-void _thr_setrunnable(struct pthread *curthread, struct pthread *thread);
-void _thr_setrunnable_unlocked(struct pthread *thread);
-void _thr_sig_add(struct pthread *, int, siginfo_t *);
-void _thr_sig_dispatch(struct kse *, int, siginfo_t *);
-int _thr_stack_alloc(struct pthread_attr *);
-void _thr_stack_free(struct pthread_attr *);
-void _thr_exit_cleanup(void);
-void _thr_free(struct pthread *, struct pthread *);
-void _thr_gc(struct pthread *);
-void _thr_panic_exit(char *, int, char *);
-void _thread_cleanupspecific(void);
-void _thread_dump_info(void);
-void _thread_printf(int, const char *, ...);
-void _thr_sched_frame(struct pthread_sigframe *);
-void _thr_sched_switch(struct pthread *);
-void _thr_sched_switch_unlocked(struct pthread *);
-void _thr_set_timeout(const struct timespec *);
-void _thr_seterrno(struct pthread *, int);
-void _thr_sig_handler(int, siginfo_t *, ucontext_t *);
-void _thr_sig_check_pending(struct pthread *);
-void _thr_sig_rundown(struct pthread *, ucontext_t *,
- struct pthread_sigframe *);
-void _thr_sig_send(struct pthread *pthread, int sig);
-void _thr_sig_wrapper(void);
-void _thr_sigframe_restore(struct pthread *thread, struct pthread_sigframe *psf);
-void _thr_spinlock_init(void);
-void _thr_enter_cancellation_point(struct pthread *);
-void _thr_leave_cancellation_point(struct pthread *);
-int _thr_setconcurrency(int new_level);
-int _thr_setmaxconcurrency(void);
-
-/*
- * Aliases for _pthread functions. Should be called instead of
- * originals if PLT replocation is unwanted at runtme.
- */
-int _thr_cond_broadcast(pthread_cond_t *);
-int _thr_cond_signal(pthread_cond_t *);
-int _thr_cond_wait(pthread_cond_t *, pthread_mutex_t *);
-int _thr_mutex_lock(pthread_mutex_t *);
-int _thr_mutex_unlock(pthread_mutex_t *);
-int _thr_rwlock_rdlock (pthread_rwlock_t *);
-int _thr_rwlock_wrlock (pthread_rwlock_t *);
-int _thr_rwlock_unlock (pthread_rwlock_t *);
-
-/* XXX - Stuff that goes away when my sources get more up to date. */
-/* #include <sys/kse.h> */
-#ifdef SYS_KSE_H
-int __sys_kse_create(struct kse_mailbox *, int);
-int __sys_kse_thr_wakeup(struct kse_mailbox *);
-int __sys_kse_exit(struct kse_mailbox *);
-int __sys_kse_release(struct kse_mailbox *);
-#endif
-
-/* #include <sys/aio.h> */
-#ifdef _SYS_AIO_H_
-int __sys_aio_suspend(const struct aiocb * const[], int, const struct timespec *);
-#endif
-
-/* #include <fcntl.h> */
-#ifdef _SYS_FCNTL_H_
-int __sys_fcntl(int, int, ...);
-int __sys_open(const char *, int, ...);
-#endif
-
-/* #include <sys/ioctl.h> */
-#ifdef _SYS_IOCTL_H_
-int __sys_ioctl(int, unsigned long, ...);
-#endif
-
-/* #inclde <sched.h> */
-#ifdef _SCHED_H_
-int __sys_sched_yield(void);
-#endif
-
-/* #include <signal.h> */
-#ifdef _SIGNAL_H_
-int __sys_kill(pid_t, int);
-int __sys_sigaction(int, const struct sigaction *, struct sigaction *);
-int __sys_sigpending(sigset_t *);
-int __sys_sigprocmask(int, const sigset_t *, sigset_t *);
-int __sys_sigsuspend(const sigset_t *);
-int __sys_sigreturn(ucontext_t *);
-int __sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *);
-#endif
-
-/* #include <sys/socket.h> */
-#ifdef _SYS_SOCKET_H_
-int __sys_sendfile(int, int, off_t, size_t, struct sf_hdtr *,
- off_t *, int);
-#endif
-
-/* #include <sys/uio.h> */
-#ifdef _SYS_UIO_H_
-ssize_t __sys_readv(int, const struct iovec *, int);
-ssize_t __sys_writev(int, const struct iovec *, int);
-#endif
-
-/* #include <time.h> */
-#ifdef _TIME_H_
-int __sys_nanosleep(const struct timespec *, struct timespec *);
-#endif
-
-/* #include <unistd.h> */
-#ifdef _UNISTD_H_
-int __sys_close(int);
-int __sys_execve(const char *, char * const *, char * const *);
-int __sys_fork(void);
-int __sys_fsync(int);
-pid_t __sys_getpid(void);
-int __sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
-ssize_t __sys_read(int, void *, size_t);
-ssize_t __sys_write(int, const void *, size_t);
-void __sys_exit(int);
-#endif
-
-/* #include <poll.h> */
-#ifdef _SYS_POLL_H_
-int __sys_poll(struct pollfd *, unsigned, int);
-#endif
-
-/* #include <sys/mman.h> */
-#ifdef _SYS_MMAN_H_
-int __sys_msync(void *, size_t, int);
-#endif
-
-#endif /* !_THR_PRIVATE_H */
diff --git a/lib/libkse/thread/thr_pselect.c b/lib/libkse/thread/thr_pselect.c
deleted file mode 100644
index c1a4c5ddba0f..000000000000
--- a/lib/libkse/thread/thr_pselect.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*-
- * Copyright (c) 2002 Daniel M. Eischen <deischen@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/select.h>
-#include <sys/time.h>
-
-#include <errno.h>
-#include <signal.h>
-#include <pthread.h>
-
-#include "thr_private.h"
-
-extern int __pselect(int count, fd_set *rfds, fd_set *wfds, fd_set *efds,
- const struct timespec *timo, const sigset_t *mask);
-
-__weak_reference(_pselect, pselect);
-
-int
-_pselect(int count, fd_set *rfds, fd_set *wfds, fd_set *efds,
- const struct timespec *timo, const sigset_t *mask)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __pselect(count, rfds, wfds, efds, timo, mask);
- _thr_leave_cancellation_point(curthread);
-
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_read.c b/lib/libkse/thread/thr_read.c
deleted file mode 100644
index 34dabd35ac4f..000000000000
--- a/lib/libkse/thread/thr_read.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- *
- */
-#include <sys/types.h>
-#include <sys/fcntl.h>
-#include <sys/uio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__read, read);
-
-ssize_t
-__read(int fd, void *buf, size_t nbytes)
-{
- struct pthread *curthread = _get_curthread();
- ssize_t ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __sys_read(fd, buf, nbytes);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_readv.c b/lib/libkse/thread/thr_readv.c
deleted file mode 100644
index 3a8823f90657..000000000000
--- a/lib/libkse/thread/thr_readv.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- *
- */
-#include <sys/types.h>
-#include <sys/fcntl.h>
-#include <sys/uio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__readv, readv);
-
-ssize_t
-__readv(int fd, const struct iovec *iov, int iovcnt)
-{
- struct pthread *curthread = _get_curthread();
- ssize_t ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __sys_readv(fd, iov, iovcnt);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_resume_np.c b/lib/libkse/thread/thr_resume_np.c
deleted file mode 100644
index 1276311c9fa2..000000000000
--- a/lib/libkse/thread/thr_resume_np.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-static void resume_common(struct pthread *);
-
-__weak_reference(_pthread_resume_np, pthread_resume_np);
-__weak_reference(_pthread_resume_all_np, pthread_resume_all_np);
-
-
-/* Resume a thread: */
-int
-_pthread_resume_np(pthread_t thread)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- /* Add a reference to the thread: */
- if ((ret = _thr_ref_add(curthread, thread, /*include dead*/0)) == 0) {
- /* Lock the threads scheduling queue: */
- THR_SCHED_LOCK(curthread, thread);
- resume_common(thread);
- THR_SCHED_UNLOCK(curthread, thread);
- _thr_ref_delete(curthread, thread);
- }
- return (ret);
-}
-
-void
-_pthread_resume_all_np(void)
-{
- struct pthread *curthread = _get_curthread();
- struct pthread *thread;
- kse_critical_t crit;
-
- /* Take the thread list lock: */
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &_thread_list_lock);
-
- TAILQ_FOREACH(thread, &_thread_list, tle) {
- if (thread != curthread) {
- THR_SCHED_LOCK(curthread, thread);
- resume_common(thread);
- THR_SCHED_UNLOCK(curthread, thread);
- }
- }
-
- /* Release the thread list lock: */
- KSE_LOCK_RELEASE(curthread->kse, &_thread_list_lock);
- _kse_critical_leave(crit);
-}
-
-static void
-resume_common(struct pthread *thread)
-{
- /* Clear the suspend flag: */
- thread->flags &= ~THR_FLAGS_SUSPENDED;
-
- /*
- * If the thread's state is suspended, that means it is
- * now runnable but not in any scheduling queue. Set the
- * state to running and insert it into the run queue.
- */
- if (thread->state == PS_SUSPENDED)
- _thr_setrunnable_unlocked(thread);
-}
diff --git a/lib/libkse/thread/thr_rtld.c b/lib/libkse/thread/thr_rtld.c
deleted file mode 100644
index c1ee77e5373d..000000000000
--- a/lib/libkse/thread/thr_rtld.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2001 Alexander Kabaev
- * 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
- * in this position and unchanged.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-#include <sys/cdefs.h>
-#include <rtld_lock.h>
-#include "thr_private.h"
-
-static void *_thr_rtld_lock_create();
-static void _thr_rtld_lock_destroy(void *);
-static void _thr_rtld_rlock_acquire(void *);
-static void _thr_rtld_wlock_acquire(void *);
-static void _thr_rtld_lock_release(void *);
-static int _thr_rtld_set_flag(int);
-static int _thr_rtld_clr_flag(int);
-
-static void *
-_thr_rtld_lock_create()
-{
- pthread_rwlock_t prwlock;
- if (_pthread_rwlock_init(&prwlock, NULL))
- return (NULL);
- return (prwlock);
-}
-
-static void
-_thr_rtld_lock_destroy(void *lock)
-{
- pthread_rwlock_t prwlock = (pthread_rwlock_t)lock;
- if (prwlock != NULL)
- _pthread_rwlock_destroy(&prwlock);
-}
-
-static void
-_thr_rtld_rlock_acquire(void *lock)
-{
- pthread_rwlock_t prwlock = (pthread_rwlock_t)lock;
- _thr_rwlock_rdlock(&prwlock);
-}
-
-static void
-_thr_rtld_wlock_acquire(void *lock)
-{
- pthread_rwlock_t prwlock = (pthread_rwlock_t)lock;
- _thr_rwlock_wrlock(&prwlock);
-}
-
-static void
-_thr_rtld_lock_release(void *lock)
-{
- pthread_rwlock_t prwlock = (pthread_rwlock_t)lock;
- _thr_rwlock_unlock(&prwlock);
-}
-
-
-static int
-_thr_rtld_set_flag(int mask)
-{
- struct pthread *curthread;
- int bits;
-
- curthread = _get_curthread();
-
- if (curthread != NULL) {
- bits = curthread->rtld_bits;
- curthread->rtld_bits |= mask;
- } else {
- bits = 0;
- PANIC("No current thread in rtld call");
- }
-
- return (bits);
-}
-
-static int
-_thr_rtld_clr_flag(int mask)
-{
- struct pthread *curthread;
- int bits;
-
- curthread = _get_curthread();
-
- if (curthread != NULL) {
- bits = curthread->rtld_bits;
- curthread->rtld_bits &= ~mask;
- } else {
- bits = 0;
- PANIC("No current thread in rtld call");
- }
- return (bits);
-}
-
-void
-_thr_rtld_init()
-{
- struct RtldLockInfo li;
- li.lock_create = _thr_rtld_lock_create;
- li.lock_destroy = _thr_rtld_lock_destroy;
- li.rlock_acquire = _thr_rtld_rlock_acquire;
- li.wlock_acquire = _thr_rtld_wlock_acquire;
- li.lock_release = _thr_rtld_lock_release;
- li.thread_set_flag = _thr_rtld_set_flag;
- li.thread_clr_flag = _thr_rtld_clr_flag;
- li.at_fork = NULL;
- _rtld_thread_init(&li);
-}
-
-void
-_thr_rtld_fini()
-{
- _rtld_thread_init(NULL);
-}
diff --git a/lib/libkse/thread/thr_rwlock.c b/lib/libkse/thread/thr_rwlock.c
deleted file mode 100644
index f9559ab79ba7..000000000000
--- a/lib/libkse/thread/thr_rwlock.c
+++ /dev/null
@@ -1,350 +0,0 @@
-/*-
- * Copyright (c) 1998 Alex Nash
- * 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$
- */
-
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-
-#include "namespace.h"
-#include <pthread.h>
-#include "un-namespace.h"
-#include "thr_private.h"
-
-/* maximum number of times a read lock may be obtained */
-#define MAX_READ_LOCKS (INT_MAX - 1)
-
-__weak_reference(_pthread_rwlock_destroy, pthread_rwlock_destroy);
-__weak_reference(_pthread_rwlock_init, pthread_rwlock_init);
-__weak_reference(_pthread_rwlock_rdlock, pthread_rwlock_rdlock);
-__weak_reference(_pthread_rwlock_tryrdlock, pthread_rwlock_tryrdlock);
-__weak_reference(_pthread_rwlock_trywrlock, pthread_rwlock_trywrlock);
-__weak_reference(_pthread_rwlock_unlock, pthread_rwlock_unlock);
-__weak_reference(_pthread_rwlock_wrlock, pthread_rwlock_wrlock);
-
-/*
- * Prototypes
- */
-static int init_static(pthread_rwlock_t *rwlock);
-
-
-static int
-init_static(pthread_rwlock_t *rwlock)
-{
- struct pthread *thread = _get_curthread();
- int ret;
-
- THR_LOCK_ACQUIRE(thread, &_rwlock_static_lock);
-
- if (*rwlock == NULL)
- ret = _pthread_rwlock_init(rwlock, NULL);
- else
- ret = 0;
-
- THR_LOCK_RELEASE(thread, &_rwlock_static_lock);
- return (ret);
-}
-
-int
-_pthread_rwlock_destroy (pthread_rwlock_t *rwlock)
-{
- int ret;
-
- if (rwlock == NULL)
- ret = EINVAL;
- else {
- pthread_rwlock_t prwlock;
-
- prwlock = *rwlock;
-
- _pthread_mutex_destroy(&prwlock->lock);
- _pthread_cond_destroy(&prwlock->read_signal);
- _pthread_cond_destroy(&prwlock->write_signal);
- free(prwlock);
-
- *rwlock = NULL;
-
- ret = 0;
- }
-
- return (ret);
-}
-
-int
-_pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
-{
- pthread_rwlock_t prwlock;
- int ret;
-
- /* allocate rwlock object */
- prwlock = (pthread_rwlock_t)malloc(sizeof(struct pthread_rwlock));
-
- if (prwlock == NULL)
- return (ENOMEM);
-
- /* initialize the lock */
- if ((ret = _pthread_mutex_init(&prwlock->lock, NULL)) != 0)
- free(prwlock);
- else {
- /* initialize the read condition signal */
- ret = _pthread_cond_init(&prwlock->read_signal, NULL);
-
- if (ret != 0) {
- _pthread_mutex_destroy(&prwlock->lock);
- free(prwlock);
- } else {
- /* initialize the write condition signal */
- ret = _pthread_cond_init(&prwlock->write_signal, NULL);
-
- if (ret != 0) {
- _pthread_cond_destroy(&prwlock->read_signal);
- _pthread_mutex_destroy(&prwlock->lock);
- free(prwlock);
- } else {
- /* success */
- prwlock->state = 0;
- prwlock->blocked_writers = 0;
-
- *rwlock = prwlock;
- }
- }
- }
-
- return (ret);
-}
-
-int
-_pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
-{
- pthread_rwlock_t prwlock;
- int ret;
-
- if (rwlock == NULL)
- return (EINVAL);
-
- prwlock = *rwlock;
-
- /* check for static initialization */
- if (prwlock == NULL) {
- if ((ret = init_static(rwlock)) != 0)
- return (ret);
-
- prwlock = *rwlock;
- }
-
- /* grab the monitor lock */
- if ((ret = _thr_mutex_lock(&prwlock->lock)) != 0)
- return (ret);
-
- /* give writers priority over readers */
- while (prwlock->blocked_writers || prwlock->state < 0) {
- ret = _thr_cond_wait(&prwlock->read_signal, &prwlock->lock);
-
- if (ret != 0) {
- /* can't do a whole lot if this fails */
- _thr_mutex_unlock(&prwlock->lock);
- return (ret);
- }
- }
-
- /* check lock count */
- if (prwlock->state == MAX_READ_LOCKS)
- ret = EAGAIN;
- else
- ++prwlock->state; /* indicate we are locked for reading */
-
- /*
- * Something is really wrong if this call fails. Returning
- * error won't do because we've already obtained the read
- * lock. Decrementing 'state' is no good because we probably
- * don't have the monitor lock.
- */
- _thr_mutex_unlock(&prwlock->lock);
-
- return (ret);
-}
-
-__strong_reference(_pthread_rwlock_rdlock, _thr_rwlock_rdlock);
-
-int
-_pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock)
-{
- pthread_rwlock_t prwlock;
- int ret;
-
- if (rwlock == NULL)
- return (EINVAL);
-
- prwlock = *rwlock;
-
- /* check for static initialization */
- if (prwlock == NULL) {
- if ((ret = init_static(rwlock)) != 0)
- return (ret);
-
- prwlock = *rwlock;
- }
-
- /* grab the monitor lock */
- if ((ret = _pthread_mutex_lock(&prwlock->lock)) != 0)
- return (ret);
-
- /* give writers priority over readers */
- if (prwlock->blocked_writers || prwlock->state < 0)
- ret = EBUSY;
- else if (prwlock->state == MAX_READ_LOCKS)
- ret = EAGAIN; /* too many read locks acquired */
- else
- ++prwlock->state; /* indicate we are locked for reading */
-
- /* see the comment on this in pthread_rwlock_rdlock */
- _pthread_mutex_unlock(&prwlock->lock);
-
- return (ret);
-}
-
-int
-_pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock)
-{
- pthread_rwlock_t prwlock;
- int ret;
-
- if (rwlock == NULL)
- return (EINVAL);
-
- prwlock = *rwlock;
-
- /* check for static initialization */
- if (prwlock == NULL) {
- if ((ret = init_static(rwlock)) != 0)
- return (ret);
-
- prwlock = *rwlock;
- }
-
- /* grab the monitor lock */
- if ((ret = _pthread_mutex_lock(&prwlock->lock)) != 0)
- return (ret);
-
- if (prwlock->state != 0)
- ret = EBUSY;
- else
- /* indicate we are locked for writing */
- prwlock->state = -1;
-
- /* see the comment on this in pthread_rwlock_rdlock */
- _pthread_mutex_unlock(&prwlock->lock);
-
- return (ret);
-}
-
-int
-_pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
-{
- pthread_rwlock_t prwlock;
- int ret;
-
- if (rwlock == NULL)
- return (EINVAL);
-
- prwlock = *rwlock;
-
- if (prwlock == NULL)
- return (EINVAL);
-
- /* grab the monitor lock */
- if ((ret = _thr_mutex_lock(&prwlock->lock)) != 0)
- return (ret);
-
- if (prwlock->state > 0) {
- if (--prwlock->state == 0 && prwlock->blocked_writers)
- ret = _thr_cond_signal(&prwlock->write_signal);
- } else if (prwlock->state < 0) {
- prwlock->state = 0;
-
- if (prwlock->blocked_writers)
- ret = _thr_cond_signal(&prwlock->write_signal);
- else
- ret = _thr_cond_broadcast(&prwlock->read_signal);
- } else
- ret = EINVAL;
-
- /* see the comment on this in pthread_rwlock_rdlock */
- _thr_mutex_unlock(&prwlock->lock);
-
- return (ret);
-}
-
-__strong_reference(_pthread_rwlock_unlock, _thr_rwlock_unlock);
-
-int
-_pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
-{
- pthread_rwlock_t prwlock;
- int ret;
-
- if (rwlock == NULL)
- return (EINVAL);
-
- prwlock = *rwlock;
-
- /* check for static initialization */
- if (prwlock == NULL) {
- if ((ret = init_static(rwlock)) != 0)
- return (ret);
-
- prwlock = *rwlock;
- }
-
- /* grab the monitor lock */
- if ((ret = _thr_mutex_lock(&prwlock->lock)) != 0)
- return (ret);
-
- while (prwlock->state != 0) {
- ++prwlock->blocked_writers;
-
- ret = _thr_cond_wait(&prwlock->write_signal, &prwlock->lock);
-
- if (ret != 0) {
- --prwlock->blocked_writers;
- _thr_mutex_unlock(&prwlock->lock);
- return (ret);
- }
-
- --prwlock->blocked_writers;
- }
-
- /* indicate we are locked for writing */
- prwlock->state = -1;
-
- /* see the comment on this in pthread_rwlock_rdlock */
- _thr_mutex_unlock(&prwlock->lock);
-
- return (ret);
-}
-
-__strong_reference(_pthread_rwlock_wrlock, _thr_rwlock_wrlock);
diff --git a/lib/libkse/thread/thr_rwlockattr.c b/lib/libkse/thread/thr_rwlockattr.c
deleted file mode 100644
index 8c0697bd671c..000000000000
--- a/lib/libkse/thread/thr_rwlockattr.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/*-
- * Copyright (c) 1998 Alex Nash
- * 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$
- */
-
-#include <errno.h>
-#include <stdlib.h>
-
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_rwlockattr_destroy, pthread_rwlockattr_destroy);
-__weak_reference(_pthread_rwlockattr_getpshared, pthread_rwlockattr_getpshared);
-__weak_reference(_pthread_rwlockattr_init, pthread_rwlockattr_init);
-__weak_reference(_pthread_rwlockattr_setpshared, pthread_rwlockattr_setpshared);
-
-int
-_pthread_rwlockattr_destroy(pthread_rwlockattr_t *rwlockattr)
-{
- pthread_rwlockattr_t prwlockattr;
-
- if (rwlockattr == NULL)
- return(EINVAL);
-
- prwlockattr = *rwlockattr;
-
- if (prwlockattr == NULL)
- return(EINVAL);
-
- free(prwlockattr);
-
- return(0);
-}
-
-int
-_pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *rwlockattr,
- int *pshared)
-{
- *pshared = (*rwlockattr)->pshared;
-
- return(0);
-}
-
-int
-_pthread_rwlockattr_init(pthread_rwlockattr_t *rwlockattr)
-{
- pthread_rwlockattr_t prwlockattr;
-
- if (rwlockattr == NULL)
- return(EINVAL);
-
- prwlockattr = (pthread_rwlockattr_t)
- malloc(sizeof(struct pthread_rwlockattr));
-
- if (prwlockattr == NULL)
- return(ENOMEM);
-
- prwlockattr->pshared = PTHREAD_PROCESS_PRIVATE;
- *rwlockattr = prwlockattr;
-
- return(0);
-}
-
-int
-_pthread_rwlockattr_setpshared(pthread_rwlockattr_t *rwlockattr, int pshared)
-{
- /* Only PTHREAD_PROCESS_PRIVATE is supported. */
- if (pshared != PTHREAD_PROCESS_PRIVATE)
- return(EINVAL);
-
- (*rwlockattr)->pshared = pshared;
-
- return(0);
-}
-
diff --git a/lib/libkse/thread/thr_select.c b/lib/libkse/thread/thr_select.c
deleted file mode 100644
index 6714af02d1ec..000000000000
--- a/lib/libkse/thread/thr_select.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <unistd.h>
-#include <errno.h>
-#include <poll.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/fcntl.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__select, select);
-
-int
-__select(int numfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
- struct timeval *timeout)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __sys_select(numfds, readfds, writefds, exceptfds, timeout);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_self.c b/lib/libkse/thread/thr_self.c
deleted file mode 100644
index 0c702a66e5d2..000000000000
--- a/lib/libkse/thread/thr_self.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_self, pthread_self);
-
-pthread_t
-_pthread_self(void)
-{
- if (_thr_initial == NULL)
- _libpthread_init(NULL);
-
- /* Return the running thread pointer: */
- return (_get_curthread());
-}
diff --git a/lib/libkse/thread/thr_sem.c b/lib/libkse/thread/thr_sem.c
deleted file mode 100644
index d6021a8ac3a2..000000000000
--- a/lib/libkse/thread/thr_sem.c
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include <stdlib.h>
-#include <errno.h>
-#include <semaphore.h>
-#include "namespace.h"
-#include <pthread.h>
-#include "un-namespace.h"
-#include "thr_private.h"
-
-#define _SEM_CHECK_VALIDITY(sem) \
- if ((*(sem))->magic != SEM_MAGIC) { \
- errno = EINVAL; \
- retval = -1; \
- goto RETURN; \
- }
-
-__weak_reference(_sem_init, sem_init);
-__weak_reference(_sem_destroy, sem_destroy);
-__weak_reference(_sem_open, sem_open);
-__weak_reference(_sem_close, sem_close);
-__weak_reference(_sem_unlink, sem_unlink);
-__weak_reference(_sem_wait, sem_wait);
-__weak_reference(_sem_trywait, sem_trywait);
-__weak_reference(_sem_post, sem_post);
-__weak_reference(_sem_getvalue, sem_getvalue);
-
-
-int
-_sem_init(sem_t *sem, int pshared, unsigned int value)
-{
- int retval;
-
- /*
- * Range check the arguments.
- */
- if (pshared != 0) {
- /*
- * The user wants a semaphore that can be shared among
- * processes, which this implementation can't do. Sounds like a
- * permissions problem to me (yeah right).
- */
- errno = EPERM;
- retval = -1;
- goto RETURN;
- }
-
- if (value > SEM_VALUE_MAX) {
- errno = EINVAL;
- retval = -1;
- goto RETURN;
- }
-
- *sem = (sem_t)malloc(sizeof(struct sem));
- if (*sem == NULL) {
- errno = ENOSPC;
- retval = -1;
- goto RETURN;
- }
-
- /*
- * Initialize the semaphore.
- */
- if (_pthread_mutex_init(&(*sem)->lock, NULL) != 0) {
- free(*sem);
- errno = ENOSPC;
- retval = -1;
- goto RETURN;
- }
-
- if (_pthread_cond_init(&(*sem)->gtzero, NULL) != 0) {
- _pthread_mutex_destroy(&(*sem)->lock);
- free(*sem);
- errno = ENOSPC;
- retval = -1;
- goto RETURN;
- }
-
- (*sem)->count = (u_int32_t)value;
- (*sem)->nwaiters = 0;
- (*sem)->magic = SEM_MAGIC;
-
- retval = 0;
- RETURN:
- return (retval);
-}
-
-int
-_sem_destroy(sem_t *sem)
-{
- int retval;
-
- _SEM_CHECK_VALIDITY(sem);
-
- /* Make sure there are no waiters. */
- _pthread_mutex_lock(&(*sem)->lock);
- if ((*sem)->nwaiters > 0) {
- _pthread_mutex_unlock(&(*sem)->lock);
- errno = EBUSY;
- retval = -1;
- goto RETURN;
- }
- _pthread_mutex_unlock(&(*sem)->lock);
-
- _pthread_mutex_destroy(&(*sem)->lock);
- _pthread_cond_destroy(&(*sem)->gtzero);
- (*sem)->magic = 0;
-
- free(*sem);
-
- retval = 0;
- RETURN:
- return (retval);
-}
-
-sem_t *
-_sem_open(const char *name, int oflag, ...)
-{
- errno = ENOSYS;
- return (SEM_FAILED);
-}
-
-int
-_sem_close(sem_t *sem)
-{
- errno = ENOSYS;
- return (-1);
-}
-
-int
-_sem_unlink(const char *name)
-{
- errno = ENOSYS;
- return (-1);
-}
-
-int
-_sem_wait(sem_t *sem)
-{
- struct pthread *curthread = _get_curthread();
- int retval;
-
- _thr_enter_cancellation_point(curthread);
-
- _SEM_CHECK_VALIDITY(sem);
-
- _pthread_mutex_lock(&(*sem)->lock);
-
- while ((*sem)->count == 0) {
- (*sem)->nwaiters++;
- _pthread_cond_wait(&(*sem)->gtzero, &(*sem)->lock);
- (*sem)->nwaiters--;
- }
- (*sem)->count--;
-
- _pthread_mutex_unlock(&(*sem)->lock);
-
- retval = 0;
- RETURN:
- _thr_leave_cancellation_point(curthread);
- return (retval);
-}
-
-int
-_sem_trywait(sem_t *sem)
-{
- int retval;
-
- _SEM_CHECK_VALIDITY(sem);
-
- _pthread_mutex_lock(&(*sem)->lock);
-
- if ((*sem)->count > 0) {
- (*sem)->count--;
- retval = 0;
- } else {
- errno = EAGAIN;
- retval = -1;
- }
-
- _pthread_mutex_unlock(&(*sem)->lock);
-
- RETURN:
- return (retval);
-}
-
-int
-_sem_post(sem_t *sem)
-{
- kse_critical_t crit;
- int retval;
-
- _SEM_CHECK_VALIDITY(sem);
-
- /*
- * sem_post() is required to be safe to call from within signal
- * handlers. Thus, we must enter a critical region.
- */
- crit = _kse_critical_enter();
-
- _pthread_mutex_lock(&(*sem)->lock);
-
- (*sem)->count++;
- if ((*sem)->nwaiters > 0)
- _pthread_cond_signal(&(*sem)->gtzero);
-
- _pthread_mutex_unlock(&(*sem)->lock);
-
- _kse_critical_leave(crit);
- retval = 0;
- RETURN:
- return (retval);
-}
-
-int
-_sem_getvalue(sem_t *sem, int *sval)
-{
- int retval;
-
- _SEM_CHECK_VALIDITY(sem);
-
- _pthread_mutex_lock(&(*sem)->lock);
- *sval = (int)(*sem)->count;
- _pthread_mutex_unlock(&(*sem)->lock);
-
- retval = 0;
- RETURN:
- return (retval);
-}
diff --git a/lib/libkse/thread/thr_seterrno.c b/lib/libkse/thread/thr_seterrno.c
deleted file mode 100644
index 245d43f19095..000000000000
--- a/lib/libkse/thread/thr_seterrno.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <pthread.h>
-#include "thr_private.h"
-
-/*
- * This function needs to reference the global error variable which is
- * normally hidden from the user.
- */
-#ifdef errno
-#undef errno;
-#endif
-extern int errno;
-
-void
-_thread_seterrno(pthread_t thread, int error)
-{
- /* Check for the initial thread: */
- if (thread == _thr_initial)
- /* The initial thread always uses the global error variable: */
- errno = error;
- else
- /*
- * Threads other than the initial thread always use the error
- * field in the thread structureL
- */
- thread->error = error;
-}
diff --git a/lib/libkse/thread/thr_setprio.c b/lib/libkse/thread/thr_setprio.c
deleted file mode 100644
index c5a950600a13..000000000000
--- a/lib/libkse/thread/thr_setprio.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_setprio, pthread_setprio);
-
-int
-_pthread_setprio(pthread_t pthread, int prio)
-{
- int ret, policy;
- struct sched_param param;
-
- if ((ret = pthread_getschedparam(pthread, &policy, &param)) == 0) {
- param.sched_priority = prio;
- ret = pthread_setschedparam(pthread, policy, &param);
- }
-
- /* Return the error status: */
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_setschedparam.c b/lib/libkse/thread/thr_setschedparam.c
deleted file mode 100644
index 63cd0730a955..000000000000
--- a/lib/libkse/thread/thr_setschedparam.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <sys/param.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_setschedparam, pthread_setschedparam);
-
-int
-_pthread_setschedparam(pthread_t pthread, int policy,
- const struct sched_param *param)
-{
- struct pthread *curthread = _get_curthread();
- int in_syncq;
- int in_readyq = 0;
- int old_prio;
- int ret = 0;
-
- if ((param == NULL) || (policy < SCHED_FIFO) || (policy > SCHED_RR)) {
- /* Return an invalid argument error: */
- ret = EINVAL;
- } else if ((param->sched_priority < THR_MIN_PRIORITY) ||
- (param->sched_priority > THR_MAX_PRIORITY)) {
- /* Return an unsupported value error. */
- ret = ENOTSUP;
-
- /* Find the thread in the list of active threads: */
- } else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0))
- == 0) {
- /*
- * Lock the threads scheduling queue while we change
- * its priority:
- */
- THR_SCHED_LOCK(curthread, pthread);
- if ((pthread->state == PS_DEAD) ||
- (pthread->state == PS_DEADLOCK) ||
- ((pthread->flags & THR_FLAGS_EXITING) != 0)) {
- THR_SCHED_UNLOCK(curthread, pthread);
- _thr_ref_delete(curthread, pthread);
- return (ESRCH);
- }
- in_syncq = pthread->sflags & THR_FLAGS_IN_SYNCQ;
-
- /* Set the scheduling policy: */
- pthread->attr.sched_policy = policy;
-
- if (param->sched_priority ==
- THR_BASE_PRIORITY(pthread->base_priority))
- /*
- * There is nothing to do; unlock the threads
- * scheduling queue.
- */
- THR_SCHED_UNLOCK(curthread, pthread);
- else {
- /*
- * Remove the thread from its current priority
- * queue before any adjustments are made to its
- * active priority:
- */
- old_prio = pthread->active_priority;
- if ((pthread->flags & THR_FLAGS_IN_RUNQ) != 0) {
- in_readyq = 1;
- THR_RUNQ_REMOVE(pthread);
- }
-
- /* Set the thread base priority: */
- pthread->base_priority &=
- (THR_SIGNAL_PRIORITY | THR_RT_PRIORITY);
- pthread->base_priority = param->sched_priority;
-
- /* Recalculate the active priority: */
- pthread->active_priority = MAX(pthread->base_priority,
- pthread->inherited_priority);
-
- if (in_readyq) {
- if ((pthread->priority_mutex_count > 0) &&
- (old_prio > pthread->active_priority)) {
- /*
- * POSIX states that if the priority is
- * being lowered, the thread must be
- * inserted at the head of the queue for
- * its priority if it owns any priority
- * protection or inheritence mutexes.
- */
- THR_RUNQ_INSERT_HEAD(pthread);
- }
- else
- THR_RUNQ_INSERT_TAIL(pthread);
- }
-
- /* Unlock the threads scheduling queue: */
- THR_SCHED_UNLOCK(curthread, pthread);
-
- /*
- * Check for any mutex priority adjustments. This
- * includes checking for a priority mutex on which
- * this thread is waiting.
- */
- _mutex_notify_priochange(curthread, pthread, in_syncq);
- }
- _thr_ref_delete(curthread, pthread);
- }
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_sig.c b/lib/libkse/thread/thr_sig.c
deleted file mode 100644
index 1250a95e4d34..000000000000
--- a/lib/libkse/thread/thr_sig.c
+++ /dev/null
@@ -1,906 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/signalvar.h>
-#include <signal.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <pthread.h>
-#include "thr_private.h"
-#include "pthread_md.h"
-
-/* Prototypes: */
-static void build_siginfo(siginfo_t *info, int signo);
-/* static void thr_sig_add(struct pthread *pthread, int sig, siginfo_t *info); */
-static void thr_sig_check_state(struct pthread *pthread, int sig);
-static struct pthread *thr_sig_find(struct kse *curkse, int sig,
- siginfo_t *info);
-static void handle_special_signals(struct kse *curkse, int sig);
-static void thr_sigframe_add(struct pthread *thread, int sig,
- siginfo_t *info);
-static void thr_sigframe_restore(struct pthread *thread,
- struct pthread_sigframe *psf);
-static void thr_sigframe_save(struct pthread *thread,
- struct pthread_sigframe *psf);
-static void thr_sig_invoke_handler(struct pthread *, int sig,
- siginfo_t *info, ucontext_t *ucp);
-
-/* #define DEBUG_SIGNAL */
-#ifdef DEBUG_SIGNAL
-#define DBG_MSG stdout_debug
-#else
-#define DBG_MSG(x...)
-#endif
-
-/*
- * Signal setup and delivery.
- *
- * 1) Delivering signals to threads in the same KSE.
- * These signals are sent by upcall events and are set in the
- * km_sigscaught field of the KSE mailbox. Since these signals
- * are received while operating on the KSE stack, they can be
- * delivered either by using signalcontext() to add a stack frame
- * to the target thread's stack, or by adding them in the thread's
- * pending set and having the thread run them down after it
- * 2) Delivering signals to threads in other KSEs/KSEGs.
- * 3) Delivering signals to threads in critical regions.
- * 4) Delivering signals to threads after they change their signal masks.
- *
- * Methods of delivering signals.
- *
- * 1) Add a signal frame to the thread's saved context.
- * 2) Add the signal to the thread structure, mark the thread as
- * having signals to handle, and let the thread run them down
- * after it resumes from the KSE scheduler.
- *
- * Problem with 1). You can't do this to a running thread or a
- * thread in a critical region.
- *
- * Problem with 2). You can't do this to a thread that doesn't
- * yield in some way (explicitly enters the scheduler). A thread
- * blocked in the kernel or a CPU hungry thread will not see the
- * signal without entering the scheduler.
- *
- * The solution is to use both 1) and 2) to deliver signals:
- *
- * o Thread in critical region - use 2). When the thread
- * leaves the critical region it will check to see if it
- * has pending signals and run them down.
- *
- * o Thread enters scheduler explicitly - use 2). The thread
- * can check for pending signals after it returns from the
- * the scheduler.
- *
- * o Thread is running and not current thread - use 2). When the
- * thread hits a condition specified by one of the other bullets,
- * the signal will be delivered.
- *
- * o Thread is running and is current thread (e.g., the thread
- * has just changed its signal mask and now sees that it has
- * pending signals) - just run down the pending signals.
- *
- * o Thread is swapped out due to quantum expiration - use 1)
- *
- * o Thread is blocked in kernel - kse_thr_wakeup() and then
- * use 1)
- */
-
-/*
- * Rules for selecting threads for signals received:
- *
- * 1) If the signal is a sychronous signal, it is delivered to
- * the generating (current thread). If the thread has the
- * signal masked, it is added to the threads pending signal
- * set until the thread unmasks it.
- *
- * 2) A thread in sigwait() where the signal is in the thread's
- * waitset.
- *
- * 3) A thread in sigsuspend() where the signal is not in the
- * thread's suspended signal mask.
- *
- * 4) Any thread (first found/easiest to deliver) that has the
- * signal unmasked.
- */
-
-/*
- * This signal handler only delivers asynchronous signals.
- * This must be called with upcalls disabled and without
- * holding any locks.
- */
-void
-_thr_sig_dispatch(struct kse *curkse, int sig, siginfo_t *info)
-{
- struct pthread *thread;
-
- DBG_MSG(">>> _thr_sig_dispatch(%d)\n", sig);
-
- /* Some signals need special handling: */
- handle_special_signals(curkse, sig);
- stderr_debug("dispatch sig:%d\n", sig);
- while ((thread = thr_sig_find(curkse, sig, info)) != NULL) {
- /*
- * Setup the target thread to receive the signal:
- */
- DBG_MSG("Got signal %d, selecting thread %p\n", sig, thread);
- KSE_SCHED_LOCK(curkse, thread->kseg);
- if ((thread->state == PS_DEAD) ||
- (thread->state == PS_DEADLOCK) ||
- THR_IS_EXITING(thread) || THR_IS_SUSPENDED(thread)) {
- KSE_SCHED_UNLOCK(curkse, thread->kseg);
- _thr_ref_delete(NULL, thread);
- } else {
- _thr_sig_add(thread, sig, info);
- KSE_SCHED_UNLOCK(curkse, thread->kseg);
- _thr_ref_delete(NULL, thread);
- break;
- }
- }
-}
-
-void
-_thr_sig_handler(int sig, siginfo_t *info, ucontext_t *ucp)
-{
- __siginfohandler_t *sigfunc;
- struct kse *curkse;
-
- curkse = _get_curkse();
- if ((curkse == NULL) || ((curkse->k_flags & KF_STARTED) == 0)) {
- /* Upcalls are not yet started; just call the handler. */
- sigfunc = _thread_sigact[sig - 1].sa_sigaction;
- ucp->uc_sigmask = _thr_proc_sigmask;
- if (((__sighandler_t *)sigfunc != SIG_DFL) &&
- ((__sighandler_t *)sigfunc != SIG_IGN) &&
- (sigfunc != (__siginfohandler_t *)_thr_sig_handler)) {
- if (((_thread_sigact[sig - 1].sa_flags & SA_SIGINFO)
- != 0) || (info == NULL))
- (*(sigfunc))(sig, info, ucp);
- else
- (*(sigfunc))(sig, (siginfo_t *)info->si_code,
- ucp);
- }
- }
- else {
- /* Nothing. */
- DBG_MSG("Got signal %d\n", sig);
- sigaddset(&curkse->k_mbx.km_sigscaught, sig);
- ucp->uc_sigmask = _thr_proc_sigmask;
- }
-}
-
-static void
-thr_sig_invoke_handler(struct pthread *curthread, int sig, siginfo_t *info,
- ucontext_t *ucp)
-{
- void (*sigfunc)(int, siginfo_t *, void *);
- sigset_t saved_mask;
- int saved_seqno;
-
- /* Invoke the signal handler without going through the scheduler:
- */
- DBG_MSG("Got signal %d, calling handler for current thread %p\n",
- sig, curthread);
-
- /*
- * Setup the threads signal mask.
- *
- * The mask is changed in the thread's active signal mask
- * (in the context) and not in the base signal mask because
- * a thread is allowed to change its signal mask within a
- * signal handler. If it does, the signal mask restored
- * after the handler should be the same as that set by the
- * thread during the handler, not the original mask from
- * before calling the handler. The thread could also
- * modify the signal mask in the context and expect this
- * mask to be used.
- */
- THR_SCHED_LOCK(curthread, curthread);
- saved_mask = curthread->tmbx.tm_context.uc_sigmask;
- saved_seqno = curthread->sigmask_seqno;
- SIGSETOR(curthread->tmbx.tm_context.uc_sigmask,
- _thread_sigact[sig - 1].sa_mask);
- sigaddset(&curthread->tmbx.tm_context.uc_sigmask, sig);
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /*
- * Check that a custom handler is installed and if
- * the signal is not blocked:
- */
- sigfunc = _thread_sigact[sig - 1].sa_sigaction;
- ucp->uc_sigmask = _thr_proc_sigmask;
- if (((__sighandler_t *)sigfunc != SIG_DFL) &&
- ((__sighandler_t *)sigfunc != SIG_IGN)) {
- if (((_thread_sigact[sig - 1].sa_flags & SA_SIGINFO) != 0) ||
- (info == NULL))
- (*(sigfunc))(sig, info, ucp);
- else
- (*(sigfunc))(sig, (siginfo_t *)info->si_code, ucp);
- }
-
- /*
- * Restore the thread's signal mask.
- */
- if (saved_seqno == curthread->sigmask_seqno)
- curthread->tmbx.tm_context.uc_sigmask = saved_mask;
- else
- curthread->tmbx.tm_context.uc_sigmask = curthread->sigmask;
-}
-
-/*
- * Find a thread that can handle the signal. This must be called
- * with upcalls disabled.
- */
-struct pthread *
-thr_sig_find(struct kse *curkse, int sig, siginfo_t *info)
-{
- int handler_installed;
- struct pthread *pthread;
- struct pthread *suspended_thread, *signaled_thread;
-
- DBG_MSG("Looking for thread to handle signal %d\n", sig);
-
- handler_installed = (_thread_sigact[sig - 1].sa_handler != SIG_IGN) &&
- (_thread_sigact[sig - 1].sa_handler != SIG_DFL);
-
- /* Check if the signal requires a dump of thread information: */
- if (sig == SIGINFO) {
- /* Dump thread information to file: */
- _thread_dump_info();
- }
- /*
- * Enter a loop to look for threads that have the signal
- * unmasked. POSIX specifies that a thread in a sigwait
- * will get the signal over any other threads. Second
- * preference will be threads in in a sigsuspend. Third
- * preference will be the current thread. If none of the
- * above, then the signal is delivered to the first thread
- * that is found. Note that if a custom handler is not
- * installed, the signal only affects threads in sigwait.
- */
- suspended_thread = NULL;
- signaled_thread = NULL;
-
- KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
- TAILQ_FOREACH(pthread, &_thread_list, tle) {
- /* Take the scheduling lock. */
- KSE_SCHED_LOCK(curkse, pthread->kseg);
- if ((pthread->state == PS_SIGWAIT) &&
- sigismember(pthread->data.sigwait, sig)) {
- /*
- * Return the signal number and make the
- * thread runnable.
- */
- pthread->signo = sig;
- _thr_setrunnable_unlocked(pthread);
-
- KSE_SCHED_UNLOCK(curkse, pthread->kseg);
-
- /*
- * POSIX doesn't doesn't specify which thread
- * will get the signal if there are multiple
- * waiters, so we give it to the first thread
- * we find.
- *
- * Do not attempt to deliver this signal
- * to other threads and do not add the signal
- * to the process pending set.
- */
- KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
- DBG_MSG("Waking thread %p in sigwait with signal %d\n",
- pthread, sig);
- return (NULL);
- }
- else if ((pthread->state == PS_DEAD) ||
- (pthread->state == PS_DEADLOCK) ||
- THR_IS_EXITING(pthread) || THR_IS_SUSPENDED(pthread))
- ; /* Skip this thread. */
- else if ((handler_installed != 0) &&
- !sigismember(&pthread->tmbx.tm_context.uc_sigmask, sig)) {
- if (pthread->state == PS_SIGSUSPEND) {
- if (suspended_thread == NULL) {
- suspended_thread = pthread;
- suspended_thread->refcount++;
- }
- } else if (signaled_thread == NULL) {
- signaled_thread = pthread;
- signaled_thread->refcount++;
- }
- }
- KSE_SCHED_UNLOCK(curkse, pthread->kseg);
- }
- KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
-
- /*
- * Only perform wakeups and signal delivery if there is a
- * custom handler installed:
- */
- if (handler_installed == 0) {
- /*
- * There is no handler installed; nothing to do here.
- */
- } else if (suspended_thread == NULL &&
- signaled_thread == NULL) {
- /*
- * Add it to the set of signals pending
- * on the process:
- */
- KSE_LOCK_ACQUIRE(curkse, &_thread_signal_lock);
- if (!sigismember(&_thr_proc_sigpending, sig)) {
- sigaddset(&_thr_proc_sigpending, sig);
- if (info == NULL)
- build_siginfo(&_thr_proc_siginfo[sig], sig);
- else
- memcpy(&_thr_proc_siginfo[sig], info,
- sizeof(*info));
- }
- KSE_LOCK_RELEASE(curkse, &_thread_signal_lock);
- } else {
- /*
- * We only deliver the signal to one thread;
- * give preference to the suspended thread:
- */
- if (suspended_thread != NULL) {
- pthread = suspended_thread;
- _thr_ref_delete(NULL, signaled_thread);
- } else
- pthread = signaled_thread;
- return (pthread);
- }
- return (NULL);
-}
-
-static void
-build_siginfo(siginfo_t *info, int signo)
-{
- bzero(info, sizeof(*info));
- info->si_signo = signo;
- info->si_pid = _thr_pid;
-}
-
-/*
- * This is called by a thread when it has pending signals to deliver.
- * It should only be called from the context of the thread.
- */
-void
-_thr_sig_rundown(struct pthread *curthread, ucontext_t *ucp,
- struct pthread_sigframe *psf)
-{
- struct pthread_sigframe psf_save;
- sigset_t sigset;
- int i;
-
- THR_SCHED_LOCK(curthread, curthread);
- memcpy(&sigset, &curthread->sigpend, sizeof(sigset));
- sigemptyset(&curthread->sigpend);
- if (psf != NULL) {
- memcpy(&psf_save, psf, sizeof(*psf));
- SIGSETOR(sigset, psf_save.psf_sigset);
- sigemptyset(&psf->psf_sigset);
- }
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /* Check the threads previous state: */
- if ((psf != NULL) && (psf_save.psf_state != PS_RUNNING)) {
- /*
- * Do a little cleanup handling for those threads in
- * queues before calling the signal handler. Signals
- * for these threads are temporarily blocked until
- * after cleanup handling.
- */
- switch (psf_save.psf_state) {
- case PS_COND_WAIT:
- _cond_wait_backout(curthread);
- psf_save.psf_state = PS_RUNNING;
- break;
-
- case PS_MUTEX_WAIT:
- _mutex_lock_backout(curthread);
- psf_save.psf_state = PS_RUNNING;
- break;
-
- default:
- break;
- }
- }
- /*
- * Lower the priority before calling the handler in case
- * it never returns (longjmps back):
- */
- curthread->active_priority &= ~THR_SIGNAL_PRIORITY;
-
- for (i = 1; i < NSIG; i++) {
- if (sigismember(&sigset, i) != 0) {
- /* Call the handler: */
- thr_sig_invoke_handler(curthread, i,
- &curthread->siginfo[i], ucp);
- }
- }
-
- THR_SCHED_LOCK(curthread, curthread);
- if (psf != NULL)
- thr_sigframe_restore(curthread, &psf_save);
- /* Restore the signal mask. */
- curthread->tmbx.tm_context.uc_sigmask = curthread->sigmask;
- THR_SCHED_UNLOCK(curthread, curthread);
- _thr_sig_check_pending(curthread);
-}
-
-/*
- * This checks pending signals for the current thread. It should be
- * called whenever a thread changes its signal mask. Note that this
- * is called from a thread (using its stack).
- *
- * XXX - We might want to just check to see if there are pending
- * signals for the thread here, but enter the UTS scheduler
- * to actually install the signal handler(s).
- */
-void
-_thr_sig_check_pending(struct pthread *curthread)
-{
- sigset_t sigset;
- sigset_t pending_process;
- sigset_t pending_thread;
- kse_critical_t crit;
- int i;
-
- curthread->check_pending = 0;
-
- /*
- * Check if there are pending signals for the running
- * thread or process that aren't blocked:
- */
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &_thread_signal_lock);
- sigset = _thr_proc_sigpending;
- KSE_LOCK_RELEASE(curthread->kse, &_thread_signal_lock);
- _kse_critical_leave(crit);
-
- THR_SCHED_LOCK(curthread, curthread);
- SIGSETOR(sigset, curthread->sigpend);
- SIGSETNAND(sigset, curthread->tmbx.tm_context.uc_sigmask);
- if (SIGNOTEMPTY(sigset)) {
- ucontext_t uc;
- volatile int once;
-
- curthread->check_pending = 0;
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /*
- * Split the pending signals into those that were
- * pending on the process and those that were pending
- * on the thread.
- */
- sigfillset(&pending_process);
- sigfillset(&pending_thread);
- for (i = 1; i < NSIG; i++) {
- if (sigismember(&sigset, i) != 0) {
- if (sigismember(&curthread->sigpend, i) != 0) {
- build_siginfo(&curthread->siginfo[i], i);
- sigdelset(&pending_thread, i);
- } else {
- memcpy(&curthread->siginfo[i],
- &_thr_proc_siginfo[i],
- sizeof(siginfo_t));
- sigdelset(&pending_process, i);
- }
- }
- }
- /*
- * Remove any process pending signals that were scheduled
- * to be delivered from process' pending set.
- */
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &_thread_signal_lock);
- SIGSETAND(_thr_proc_sigpending, pending_process);
- KSE_LOCK_RELEASE(curthread->kse, &_thread_signal_lock);
- _kse_critical_leave(crit);
-
- /*
- * Remove any thread pending signals that were scheduled
- * to be delivered from thread's pending set.
- */
- THR_SCHED_LOCK(curthread, curthread);
- SIGSETAND(curthread->sigpend, pending_thread);
- THR_SCHED_UNLOCK(curthread, curthread);
-
- once = 0;
- THR_GETCONTEXT(&uc);
- if (once == 0) {
- once = 1;
- for (i = 1; i < NSIG; i++) {
- if (sigismember(&sigset, i) != 0) {
- /* Call the handler: */
- thr_sig_invoke_handler(curthread, i,
- &curthread->siginfo[i], &uc);
- }
- }
- }
- }
- else
- THR_SCHED_UNLOCK(curthread, curthread);
-}
-
-/*
- * This must be called with upcalls disabled.
- */
-static void
-handle_special_signals(struct kse *curkse, int sig)
-{
- switch (sig) {
- /*
- * POSIX says that pending SIGCONT signals are
- * discarded when one of these signals occurs.
- */
- case SIGTSTP:
- case SIGTTIN:
- case SIGTTOU:
- KSE_LOCK_ACQUIRE(curkse, &_thread_signal_lock);
- sigdelset(&_thr_proc_sigpending, SIGCONT);
- KSE_LOCK_RELEASE(curkse, &_thread_signal_lock);
- break;
-
- default:
- break;
- }
-}
-
-/*
- * Perform thread specific actions in response to a signal.
- * This function is only called if there is a handler installed
- * for the signal, and if the target thread has the signal
- * unmasked.
- *
- * This must be called with the thread's scheduling lock held.
- */
-void
-_thr_sig_add(struct pthread *pthread, int sig, siginfo_t *info)
-{
- int restart;
- int suppress_handler = 0;
-
- if (pthread->curframe == NULL) {
- /*
- * This thread is active. Just add it to the
- * thread's pending set.
- */
- sigaddset(&pthread->sigpend, sig);
- pthread->check_pending = 1;
- if (info == NULL)
- build_siginfo(&pthread->siginfo[sig], sig);
- else if (info != &pthread->siginfo[sig])
- memcpy(&pthread->siginfo[sig], info,
- sizeof(*info));
- if ((pthread->blocked != 0) && !THR_IN_CRITICAL(pthread))
- kse_thr_interrupt(&pthread->tmbx /* XXX - restart?!?! */);
- }
- else {
- restart = _thread_sigact[sig - 1].sa_flags & SA_RESTART;
-
- /* Make sure this signal isn't still in the pending set: */
- sigdelset(&pthread->sigpend, sig);
-
- /*
- * Process according to thread state:
- */
- switch (pthread->state) {
- /*
- * States which do not change when a signal is trapped:
- */
- case PS_DEAD:
- case PS_DEADLOCK:
- case PS_LOCKWAIT:
- case PS_SUSPENDED:
- case PS_STATE_MAX:
- /*
- * You can't call a signal handler for threads in these
- * states.
- */
- suppress_handler = 1;
- break;
-
- /*
- * States which do not need any cleanup handling when signals
- * occur:
- */
- case PS_RUNNING:
- /*
- * Remove the thread from the queue before changing its
- * priority:
- */
- if ((pthread->flags & THR_FLAGS_IN_RUNQ) != 0)
- THR_RUNQ_REMOVE(pthread);
- break;
-
- /*
- * States which cannot be interrupted but still require the
- * signal handler to run:
- */
- case PS_COND_WAIT:
- case PS_MUTEX_WAIT:
- /*
- * Remove the thread from the wait queue. It will
- * be added back to the wait queue once all signal
- * handlers have been invoked.
- */
- KSE_WAITQ_REMOVE(pthread->kse, pthread);
- break;
-
- case PS_SLEEP_WAIT:
- /*
- * Unmasked signals always cause sleep to terminate
- * early regardless of SA_RESTART:
- */
- pthread->interrupted = 1;
- KSE_WAITQ_REMOVE(pthread->kse, pthread);
- THR_SET_STATE(pthread, PS_RUNNING);
- break;
-
- case PS_JOIN:
- case PS_SIGSUSPEND:
- KSE_WAITQ_REMOVE(pthread->kse, pthread);
- THR_SET_STATE(pthread, PS_RUNNING);
- break;
-
- case PS_SIGWAIT:
- /*
- * The signal handler is not called for threads in
- * SIGWAIT.
- */
- suppress_handler = 1;
- /* Wake up the thread if the signal is blocked. */
- if (sigismember(pthread->data.sigwait, sig)) {
- /* Return the signal number: */
- pthread->signo = sig;
-
- /* Make the thread runnable: */
- _thr_setrunnable_unlocked(pthread);
- } else
- /* Increment the pending signal count. */
- sigaddset(&pthread->sigpend, sig);
- break;
- }
-
- if (suppress_handler == 0) {
- /*
- * Setup a signal frame and save the current threads
- * state:
- */
- thr_sigframe_add(pthread, sig, info);
-
- if (pthread->state != PS_RUNNING)
- THR_SET_STATE(pthread, PS_RUNNING);
-
- /*
- * The thread should be removed from all scheduling
- * queues at this point. Raise the priority and
- * place the thread in the run queue. It is also
- * possible for a signal to be sent to a suspended
- * thread, mostly via pthread_kill(). If a thread
- * is suspended, don't insert it into the priority
- * queue; just set its state to suspended and it
- * will run the signal handler when it is resumed.
- */
- pthread->active_priority |= THR_SIGNAL_PRIORITY;
- if ((pthread->flags & THR_FLAGS_IN_RUNQ) == 0)
- THR_RUNQ_INSERT_TAIL(pthread);
- }
- }
-}
-
-static void
-thr_sig_check_state(struct pthread *pthread, int sig)
-{
- /*
- * Process according to thread state:
- */
- switch (pthread->state) {
- /*
- * States which do not change when a signal is trapped:
- */
- case PS_RUNNING:
- case PS_LOCKWAIT:
- case PS_MUTEX_WAIT:
- case PS_COND_WAIT:
- case PS_JOIN:
- case PS_SUSPENDED:
- case PS_DEAD:
- case PS_DEADLOCK:
- case PS_STATE_MAX:
- break;
-
- case PS_SIGWAIT:
- /* Wake up the thread if the signal is blocked. */
- if (sigismember(pthread->data.sigwait, sig)) {
- /* Return the signal number: */
- pthread->signo = sig;
-
- /* Change the state of the thread to run: */
- _thr_setrunnable_unlocked(pthread);
- } else
- /* Increment the pending signal count. */
- sigaddset(&pthread->sigpend, sig);
- break;
-
- case PS_SIGSUSPEND:
- case PS_SLEEP_WAIT:
- /*
- * Remove the thread from the wait queue and make it
- * runnable:
- */
- _thr_setrunnable_unlocked(pthread);
-
- /* Flag the operation as interrupted: */
- pthread->interrupted = 1;
- break;
- }
-}
-
-/*
- * Send a signal to a specific thread (ala pthread_kill):
- */
-void
-_thr_sig_send(struct pthread *pthread, int sig)
-{
- struct pthread *curthread = _get_curthread();
-
- /* Lock the scheduling queue of the target thread. */
- THR_SCHED_LOCK(curthread, pthread);
-
- /* Check for signals whose actions are SIG_DFL: */
- if (_thread_sigact[sig - 1].sa_handler == SIG_DFL) {
- /*
- * Check to see if a temporary signal handler is
- * installed for sigwaiters:
- */
- if (_thread_dfl_count[sig] == 0) {
- /*
- * Deliver the signal to the process if a handler
- * is not installed:
- */
- THR_SCHED_UNLOCK(curthread, pthread);
- kill(getpid(), sig);
- THR_SCHED_LOCK(curthread, pthread);
- }
- /*
- * Assuming we're still running after the above kill(),
- * make any necessary state changes to the thread:
- */
- thr_sig_check_state(pthread, sig);
- THR_SCHED_UNLOCK(curthread, pthread);
- }
- /*
- * Check that the signal is not being ignored:
- */
- else if (_thread_sigact[sig - 1].sa_handler != SIG_IGN) {
- if (pthread->state == PS_SIGWAIT &&
- sigismember(pthread->data.sigwait, sig)) {
- /* Return the signal number: */
- pthread->signo = sig;
-
- /* Change the state of the thread to run: */
- _thr_setrunnable_unlocked(pthread);
- THR_SCHED_UNLOCK(curthread, pthread);
- } else if (sigismember(&pthread->tmbx.tm_context.uc_sigmask, sig)) {
- /* Add the signal to the pending set: */
- sigaddset(&pthread->sigpend, sig);
- THR_SCHED_UNLOCK(curthread, pthread);
- } else if (pthread == curthread) {
- ucontext_t uc;
- siginfo_t info;
- volatile int once;
-
- THR_SCHED_UNLOCK(curthread, pthread);
- build_siginfo(&info, sig);
- once = 0;
- THR_GETCONTEXT(&uc);
- if (once == 0) {
- once = 1;
- /*
- * Call the signal handler for the current
- * thread:
- */
- thr_sig_invoke_handler(curthread, sig,
- &info, &uc);
- }
- } else {
- /*
- * Perform any state changes due to signal
- * arrival:
- */
- _thr_sig_add(pthread, sig, NULL);
- THR_SCHED_UNLOCK(curthread, pthread);
- }
- }
-}
-
-static void
-thr_sigframe_add(struct pthread *thread, int sig, siginfo_t *info)
-{
- if (thread->curframe == NULL)
- PANIC("Thread doesn't have signal frame ");
-
- if (thread->have_signals == 0) {
- /*
- * Multiple signals can be added to the same signal
- * frame. Only save the thread's state the first time.
- */
- thr_sigframe_save(thread, thread->curframe);
- thread->have_signals = 1;
- thread->flags &= THR_FLAGS_PRIVATE;
- }
- sigaddset(&thread->curframe->psf_sigset, sig);
- if (info == NULL)
- build_siginfo(&thread->siginfo[sig], sig);
- else if (info != &thread->siginfo[sig])
- memcpy(&thread->siginfo[sig], info, sizeof(*info));
-
- /* Setup the new signal mask. */
- SIGSETOR(thread->tmbx.tm_context.uc_sigmask,
- _thread_sigact[sig - 1].sa_mask);
- sigaddset(&thread->tmbx.tm_context.uc_sigmask, sig);
-}
-
-void
-thr_sigframe_restore(struct pthread *thread, struct pthread_sigframe *psf)
-{
- thread->flags = psf->psf_flags;
- thread->interrupted = psf->psf_interrupted;
- thread->signo = psf->psf_signo;
- thread->state = psf->psf_state;
- thread->data = psf->psf_wait_data;
- thread->wakeup_time = psf->psf_wakeup_time;
- if (thread->sigmask_seqno == psf->psf_seqno)
- thread->tmbx.tm_context.uc_sigmask = psf->psf_sigmask;
- else
- thread->tmbx.tm_context.uc_sigmask = thread->sigmask;
-}
-
-static void
-thr_sigframe_save(struct pthread *thread, struct pthread_sigframe *psf)
-{
- /* This has to initialize all members of the sigframe. */
- psf->psf_flags =
- thread->flags & (THR_FLAGS_PRIVATE|THR_FLAGS_IN_TDLIST);
- psf->psf_interrupted = thread->interrupted;
- psf->psf_signo = thread->signo;
- psf->psf_state = thread->state;
- psf->psf_wait_data = thread->data;
- psf->psf_wakeup_time = thread->wakeup_time;
- psf->psf_sigmask = thread->tmbx.tm_context.uc_sigmask;
- psf->psf_seqno = thread->sigmask_seqno;
- sigemptyset(&psf->psf_sigset);
-}
diff --git a/lib/libkse/thread/thr_sigaction.c b/lib/libkse/thread/thr_sigaction.c
deleted file mode 100644
index 7ede6d2ba3c3..000000000000
--- a/lib/libkse/thread/thr_sigaction.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <signal.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_sigaction, sigaction);
-
-int
-_sigaction(int sig, const struct sigaction * act, struct sigaction * oact)
-{
- int ret = 0;
- struct sigaction gact;
-
- /* Check if the signal number is out of range: */
- if (sig < 1 || sig > NSIG) {
- /* Return an invalid argument: */
- errno = EINVAL;
- ret = -1;
- } else {
- if (_thr_initial == NULL)
- _libpthread_init(NULL);
-
- /*
- * Check if the existing signal action structure contents are
- * to be returned:
- */
- if (oact != NULL) {
- /* Return the existing signal action contents: */
- oact->sa_handler = _thread_sigact[sig - 1].sa_handler;
- oact->sa_mask = _thread_sigact[sig - 1].sa_mask;
- oact->sa_flags = _thread_sigact[sig - 1].sa_flags;
- }
-
- /* Check if a signal action was supplied: */
- if (act != NULL) {
- /* Set the new signal handler: */
- _thread_sigact[sig - 1].sa_mask = act->sa_mask;
- _thread_sigact[sig - 1].sa_flags = act->sa_flags;
- _thread_sigact[sig - 1].sa_handler = act->sa_handler;
- }
-
- /*
- * Check if the kernel needs to be advised of a change
- * in signal action:
- */
- if (act != NULL && sig != SIGINFO) {
- gact.sa_mask = act->sa_mask;
- gact.sa_flags = SA_SIGINFO | act->sa_flags;
-
- /*
- * Check if the signal handler is being set to
- * the default or ignore handlers:
- */
- if (act->sa_handler == SIG_DFL ||
- act->sa_handler == SIG_IGN)
- /* Specify the built in handler: */
- gact.sa_handler = act->sa_handler;
- else
- /*
- * Specify the thread kernel signal
- * handler:
- */
- gact.sa_handler = (void (*) ())_thr_sig_handler;
-
- /* Change the signal action in the kernel: */
- if (__sys_sigaction(sig, &gact, NULL) != 0)
- ret = -1;
- }
- }
-
- /* Return the completion status: */
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_sigmask.c b/lib/libkse/thread/thr_sigmask.c
deleted file mode 100644
index d9cb8396485f..000000000000
--- a/lib/libkse/thread/thr_sigmask.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/signalvar.h>
-#include <errno.h>
-#include <signal.h>
-#include <string.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_pthread_sigmask, pthread_sigmask);
-
-int
-_pthread_sigmask(int how, const sigset_t *set, sigset_t *oset)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- ret = 0;
- if (oset != NULL)
- /* Return the current mask: */
- *oset = curthread->tmbx.tm_context.uc_sigmask;
-
- /* Check if a new signal set was provided by the caller: */
- if (set != NULL) {
- THR_SCHED_LOCK(curthread, curthread);
-
- /* Process according to what to do: */
- switch (how) {
- /* Block signals: */
- case SIG_BLOCK:
- /* Add signals to the existing mask: */
- SIGSETOR(curthread->tmbx.tm_context.uc_sigmask, *set);
- break;
-
- /* Unblock signals: */
- case SIG_UNBLOCK:
- /* Clear signals from the existing mask: */
- SIGSETNAND(curthread->tmbx.tm_context.uc_sigmask, *set);
- break;
-
- /* Set the signal process mask: */
- case SIG_SETMASK:
- /* Set the new mask: */
- curthread->tmbx.tm_context.uc_sigmask = *set;
- break;
-
- /* Trap invalid actions: */
- default:
- /* Return an invalid argument: */
- errno = EINVAL;
- ret = -1;
- break;
- }
-
- if (ret == 0) {
- curthread->sigmask =
- curthread->tmbx.tm_context.uc_sigmask;
- curthread->sigmask_seqno++;
- }
-
- THR_SCHED_UNLOCK(curthread, curthread);
-
- /*
- * Run down any pending signals:
- */
- if (ret == 0)
- _thr_sig_check_pending(curthread);
- }
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_sigpending.c b/lib/libkse/thread/thr_sigpending.c
deleted file mode 100644
index 7f42ff32b117..000000000000
--- a/lib/libkse/thread/thr_sigpending.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 1999 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/signalvar.h>
-#include <signal.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_sigpending, sigpending);
-
-int
-_sigpending(sigset_t *set)
-{
- struct pthread *curthread = _get_curthread();
- kse_critical_t crit;
- int ret = 0;
-
- /* Check for a null signal set pointer: */
- if (set == NULL) {
- /* Return an invalid argument: */
- ret = EINVAL;
- }
- else {
- *set = curthread->sigpend;
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &_thread_signal_lock);
- SIGSETOR(*set, _thr_proc_sigpending);
- KSE_LOCK_RELEASE(curthread->kse, &_thread_signal_lock);
- _kse_critical_leave(crit);
- }
- /* Return the completion status: */
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_sigprocmask.c b/lib/libkse/thread/thr_sigprocmask.c
deleted file mode 100644
index ec39da009a82..000000000000
--- a/lib/libkse/thread/thr_sigprocmask.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/signalvar.h>
-#include <signal.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_sigprocmask, sigprocmask);
-
-int
-_sigprocmask(int how, const sigset_t *set, sigset_t *oset)
-{
- if (_kse_isthreaded() != 0)
- return (pthread_sigmask(how, set, oset));
- else
- return (__sys_sigprocmask(how, set, oset));
-}
diff --git a/lib/libkse/thread/thr_sigsuspend.c b/lib/libkse/thread/thr_sigsuspend.c
deleted file mode 100644
index 59161566bb51..000000000000
--- a/lib/libkse/thread/thr_sigsuspend.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <signal.h>
-#include <errno.h>
-#include <pthread.h>
-#include <string.h>
-#include "thr_private.h"
-
-__weak_reference(__sigsuspend, sigsuspend);
-
-int
-_sigsuspend(const sigset_t *set)
-{
- struct pthread *curthread = _get_curthread();
- int ret = -1;
-
- /* Check if a new signal set was provided by the caller: */
- if (set != NULL) {
- THR_SCHED_LOCK(curthread, curthread);
-
- /* Change the caller's mask: */
- memcpy(&curthread->tmbx.tm_context.uc_sigmask,
- set, sizeof(sigset_t));
-
- THR_LOCK_SWITCH(curthread);
- THR_SET_STATE(curthread, PS_SIGSUSPEND);
-
- /* Wait for a signal: */
- _thr_sched_switch_unlocked(curthread);
-
- /* Always return an interrupted error: */
- errno = EINTR;
-
- /* Restore the signal mask: */
- memcpy(&curthread->tmbx.tm_context.uc_sigmask,
- &curthread->sigmask, sizeof(sigset_t));
- } else {
- /* Return an invalid argument error: */
- errno = EINVAL;
- }
-
- /* Return the completion status: */
- return (ret);
-}
-
-int
-__sigsuspend(const sigset_t * set)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = _sigsuspend(set);
- _thr_leave_cancellation_point(curthread);
-
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_sigwait.c b/lib/libkse/thread/thr_sigwait.c
deleted file mode 100644
index c8c77620663e..000000000000
--- a/lib/libkse/thread/thr_sigwait.c
+++ /dev/null
@@ -1,175 +0,0 @@
-//depot/projects/kse/lib/libpthread/thread/thr_sigwait.c#1 - branch change 15154 (text+ko)
-/*
- * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <signal.h>
-#include <sys/param.h>
-#include <sys/signalvar.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_sigwait, sigwait);
-
-int
-_sigwait(const sigset_t *set, int *sig)
-{
- struct pthread *curthread = _get_curthread();
- int ret = 0;
- int i;
- sigset_t tempset, waitset;
- struct sigaction act;
- kse_critical_t crit;
-
- _thr_enter_cancellation_point(curthread);
-
- /*
- * Specify the thread kernel signal handler.
- */
- act.sa_handler = (void (*) ()) _thr_sig_handler;
- act.sa_flags = SA_RESTART | SA_SIGINFO;
- /* Ensure the signal handler cannot be interrupted by other signals: */
- sigfillset(&act.sa_mask);
-
- /*
- * Initialize the set of signals that will be waited on:
- */
- waitset = *set;
-
- /* These signals can't be waited on. */
- sigdelset(&waitset, SIGKILL);
- sigdelset(&waitset, SIGSTOP);
-
- /*
- * Check to see if a pending signal is in the wait mask.
- * This has to be atomic.
- */
- tempset = curthread->sigpend;
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &_thread_signal_lock);
- SIGSETOR(tempset, _thr_proc_sigpending);
- SIGSETAND(tempset, waitset);
- if (SIGNOTEMPTY(tempset)) {
- /* Enter a loop to find a pending signal: */
- for (i = 1; i < NSIG; i++) {
- if (sigismember (&tempset, i))
- break;
- }
-
- /* Clear the pending signal: */
- if (sigismember(&curthread->sigpend, i))
- sigdelset(&curthread->sigpend, i);
- else
- sigdelset(&_thr_proc_sigpending, i);
-
- KSE_LOCK_RELEASE(curthread->kse, &_thread_signal_lock);
- _kse_critical_leave(crit);
- _thr_leave_cancellation_point(curthread);
- /* Return the signal number to the caller: */
- *sig = i;
- return (0);
- }
-
- /*
- * Enter a loop to find the signals that are SIG_DFL. For
- * these signals we must install a dummy signal handler in
- * order for the kernel to pass them in to us. POSIX says
- * that the _application_ must explicitly install a dummy
- * handler for signals that are SIG_IGN in order to sigwait
- * on them. Note that SIG_IGN signals are left in the
- * mask because a subsequent sigaction could enable an
- * ignored signal.
- */
- sigemptyset(&tempset);
- for (i = 1; i < NSIG; i++) {
- if (sigismember(&waitset, i) &&
- (_thread_sigact[i - 1].sa_handler == SIG_DFL)) {
- _thread_dfl_count[i]++;
- sigaddset(&tempset, i);
- if (_thread_dfl_count[i] == 1) {
- if (__sys_sigaction(i, &act, NULL) != 0)
- ret = -1;
- }
- }
- }
- /* Done accessing _thread_dfl_count for now. */
- KSE_LOCK_RELEASE(curthread->kse, &_thread_signal_lock);
- _kse_critical_leave(crit);
- if (ret == 0) {
- /*
- * Save the wait signal mask. The wait signal
- * mask is independent of the threads signal mask
- * and requires separate storage.
- */
- curthread->data.sigwait = &waitset;
-
- /* Wait for a signal: */
- THR_LOCK_SWITCH(curthread);
- THR_SET_STATE(curthread, PS_SIGWAIT);
- _thr_sched_switch_unlocked(curthread);
- /* Return the signal number to the caller: */
- *sig = curthread->signo;
-
- /*
- * Probably unnecessary, but since it's in a union struct
- * we don't know how it could be used in the future.
- */
- curthread->data.sigwait = NULL;
- }
-
- /*
- * Relock the array of SIG_DFL wait counts.
- */
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &_thread_signal_lock);
-
- /* Restore the sigactions: */
- act.sa_handler = SIG_DFL;
- for (i = 1; i < NSIG; i++) {
- if (sigismember(&tempset, i)) {
- _thread_dfl_count[i]--;
- if ((_thread_sigact[i - 1].sa_handler == SIG_DFL) &&
- (_thread_dfl_count[i] == 0)) {
- if (__sys_sigaction(i, &act, NULL) != 0)
- ret = -1;
- }
- }
- }
- /* Done accessing _thread_dfl_count. */
- KSE_LOCK_RELEASE(curthread->kse, &_thread_signal_lock);
- _kse_critical_leave(crit);
- _thr_leave_cancellation_point(curthread);
-
- /* Return the completion status: */
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_single_np.c b/lib/libkse/thread/thr_single_np.c
deleted file mode 100644
index 1ee5e7918bd9..000000000000
--- a/lib/libkse/thread/thr_single_np.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <pthread.h>
-#include <pthread_np.h>
-
-__weak_reference(_pthread_single_np, pthread_single_np);
-
-int _pthread_single_np()
-{
-
- /* Enter single-threaded (non-POSIX) scheduling mode: */
- pthread_suspend_all_np();
- /*
- * XXX - Do we want to do this?
- * __is_threaded = 0;
- */
- return (0);
-}
diff --git a/lib/libkse/thread/thr_sleep.c b/lib/libkse/thread/thr_sleep.c
deleted file mode 100644
index 0f02db772fb6..000000000000
--- a/lib/libkse/thread/thr_sleep.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include <unistd.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_sleep, sleep);
-
-unsigned int
-_sleep(unsigned int seconds)
-{
- struct pthread *curthread = _get_curthread();
- unsigned int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __sleep(seconds);
- _thr_leave_cancellation_point(curthread);
-
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_spec.c b/lib/libkse/thread/thr_spec.c
deleted file mode 100644
index 2cd18d143b23..000000000000
--- a/lib/libkse/thread/thr_spec.c
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-struct pthread_key {
- volatile int allocated;
- volatile int count;
- int seqno;
- void (*destructor) ();
-};
-
-/* Static variables: */
-static struct pthread_key key_table[PTHREAD_KEYS_MAX];
-
-__weak_reference(_pthread_key_create, pthread_key_create);
-__weak_reference(_pthread_key_delete, pthread_key_delete);
-__weak_reference(_pthread_getspecific, pthread_getspecific);
-__weak_reference(_pthread_setspecific, pthread_setspecific);
-
-
-int
-_pthread_key_create(pthread_key_t *key, void (*destructor) (void *))
-{
- struct pthread *curthread = _get_curthread();
-
- /* Lock the key table: */
- THR_LOCK_ACQUIRE(curthread, &_keytable_lock);
- for ((*key) = 0; (*key) < PTHREAD_KEYS_MAX; (*key)++) {
-
- if (key_table[(*key)].allocated == 0) {
- key_table[(*key)].allocated = 1;
- key_table[(*key)].destructor = destructor;
- key_table[(*key)].seqno++;
-
- /* Unlock the key table: */
- THR_LOCK_RELEASE(curthread, &_keytable_lock);
- return (0);
- }
-
- }
- /* Unlock the key table: */
- THR_LOCK_RELEASE(curthread, &_keytable_lock);
- return (EAGAIN);
-}
-
-int
-_pthread_key_delete(pthread_key_t key)
-{
- struct pthread *curthread = _get_curthread();
- int ret = 0;
-
- if (key < PTHREAD_KEYS_MAX) {
- /* Lock the key table: */
- THR_LOCK_ACQUIRE(curthread, &_keytable_lock);
-
- if (key_table[key].allocated)
- key_table[key].allocated = 0;
- else
- ret = EINVAL;
-
- /* Unlock the key table: */
- THR_LOCK_RELEASE(curthread, &_keytable_lock);
- } else
- ret = EINVAL;
- return (ret);
-}
-
-void
-_thread_cleanupspecific(void)
-{
- struct pthread *curthread = _get_curthread();
- void *data = NULL;
- int key;
- void (*destructor)( void *);
-
- if (curthread->specific != NULL) {
- /* Lock the key table: */
- THR_LOCK_ACQUIRE(curthread, &_keytable_lock);
- for (key = 0; (key < PTHREAD_KEYS_MAX) &&
- (curthread->specific_data_count > 0); key++) {
- destructor = NULL;
-
- if (key_table[key].allocated &&
- (curthread->specific[key].data != NULL)) {
- if (curthread->specific[key].seqno ==
- key_table[key].seqno) {
- data = (void *)curthread->specific[key].data;
- destructor = key_table[key].destructor;
- }
- curthread->specific[key].data = NULL;
- curthread->specific_data_count--;
- }
-
- /*
- * If there is a destructore, call it
- * with the key table entry unlocked:
- */
- if (destructor != NULL) {
- /*
- * Don't hold the lock while calling the
- * destructor:
- */
- THR_LOCK_RELEASE(curthread, &_keytable_lock);
- destructor(data);
- THR_LOCK_ACQUIRE(curthread, &_keytable_lock);
- }
- }
- THR_LOCK_RELEASE(curthread, &_keytable_lock);
- free(curthread->specific);
- curthread->specific = NULL;
- }
-}
-
-static inline struct pthread_specific_elem *
-pthread_key_allocate_data(void)
-{
- struct pthread_specific_elem *new_data;
-
- new_data = (struct pthread_specific_elem *)
- malloc(sizeof(struct pthread_specific_elem) * PTHREAD_KEYS_MAX);
- if (new_data != NULL) {
- memset((void *) new_data, 0,
- sizeof(struct pthread_specific_elem) * PTHREAD_KEYS_MAX);
- }
- return (new_data);
-}
-
-int
-_pthread_setspecific(pthread_key_t key, const void *value)
-{
- struct pthread *pthread;
- int ret = 0;
-
- /* Point to the running thread: */
- pthread = _get_curthread();
-
- if ((pthread->specific) ||
- (pthread->specific = pthread_key_allocate_data())) {
- if (key < PTHREAD_KEYS_MAX) {
- if (key_table[key].allocated) {
- if (pthread->specific[key].data == NULL) {
- if (value != NULL)
- pthread->specific_data_count++;
- } else {
- if (value == NULL)
- pthread->specific_data_count--;
- }
- pthread->specific[key].data = value;
- pthread->specific[key].seqno =
- key_table[key].seqno;
- ret = 0;
- } else
- ret = EINVAL;
- } else
- ret = EINVAL;
- } else
- ret = ENOMEM;
- return (ret);
-}
-
-void *
-_pthread_getspecific(pthread_key_t key)
-{
- struct pthread *pthread;
- void *data;
-
- /* Point to the running thread: */
- pthread = _get_curthread();
-
- /* Check if there is specific data: */
- if (pthread->specific != NULL && key < PTHREAD_KEYS_MAX) {
- /* Check if this key has been used before: */
- if (key_table[key].allocated &&
- (pthread->specific[key].seqno == key_table[key].seqno)) {
- /* Return the value: */
- data = (void *) pthread->specific[key].data;
- } else {
- /*
- * This key has not been used before, so return NULL
- * instead:
- */
- data = NULL;
- }
- } else
- /* No specific data has been created, so just return NULL: */
- data = NULL;
- return (data);
-}
diff --git a/lib/libkse/thread/thr_spinlock.c b/lib/libkse/thread/thr_spinlock.c
deleted file mode 100644
index 6beaf66ff54b..000000000000
--- a/lib/libkse/thread/thr_spinlock.c
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- *
- */
-
-#include <sys/types.h>
-#include <machine/atomic.h>
-
-#include <libc_private.h>
-#include "spinlock.h"
-#include "thr_private.h"
-
-#define MAX_SPINLOCKS 5
-
-struct spinlock_extra {
- struct lock lock;
- kse_critical_t crit;
-};
-
-static void init_spinlock(spinlock_t *lck);
-
-static struct lock spinlock_static_lock;
-static struct spinlock_extra extra[MAX_SPINLOCKS];
-static int spinlock_count = 0;
-static int initialized = 0;
-
-/*
- * These are for compatability only. Spinlocks of this type
- * are deprecated.
- */
-
-void
-_spinunlock(spinlock_t *lck)
-{
- struct spinlock_extra *extra;
- kse_critical_t crit;
-
- extra = (struct spinlock_extra *)lck->fname;
- crit = extra->crit;
- KSE_LOCK_RELEASE(_get_curkse(), &extra->lock);
- _kse_critical_leave(crit);
-}
-
-
-/*
- * Lock a location for the running thread. Yield to allow other
- * threads to run if this thread is blocked because the lock is
- * not available. Note that this function does not sleep. It
- * assumes that the lock will be available very soon.
- */
-void
-_spinlock(spinlock_t *lck)
-{
- struct spinlock_extra *extra;
- kse_critical_t crit;
-
- THR_ASSERT(__isthreaded != 0, "Spinlock called when not threaded.");
- THR_ASSERT(initialized != 0, "Spinlocks not initialized.");
- /*
- * Try to grab the lock and loop if another thread grabs
- * it before we do.
- */
- crit = _kse_critical_enter();
- if (lck->fname == NULL)
- init_spinlock(lck);
- extra = (struct spinlock_extra *)lck->fname;
- KSE_LOCK_ACQUIRE(_get_curkse(), &extra->lock);
- extra->crit = crit;
-}
-
-/*
- * Lock a location for the running thread. Yield to allow other
- * threads to run if this thread is blocked because the lock is
- * not available. Note that this function does not sleep. It
- * assumes that the lock will be available very soon.
- *
- * This function checks if the running thread has already locked the
- * location, warns if this occurs and creates a thread dump before
- * returning.
- */
-void
-_spinlock_debug(spinlock_t *lck, char *fname, int lineno)
-{
- _spinlock(lck);
-}
-
-static void
-init_spinlock(spinlock_t *lck)
-{
- struct kse *curkse = _get_curkse();
-
- KSE_LOCK_ACQUIRE(curkse, &spinlock_static_lock);
- if ((lck->fname == NULL) && (spinlock_count < MAX_SPINLOCKS)) {
- lck->fname = (char *)&extra[spinlock_count];
- spinlock_count++;
- }
- KSE_LOCK_RELEASE(curkse, &spinlock_static_lock);
- THR_ASSERT(lck->fname != NULL, "Exceeded max spinlocks");
-}
-
-void
-_thr_spinlock_init(void)
-{
- int i;
-
- if (initialized != 0) {
- _lock_destroy(&spinlock_static_lock);
- for (i = 0; i < MAX_SPINLOCKS; i++) {
- _lock_destroy(&extra[i].lock);
- }
- }
-
- if (_lock_init(&spinlock_static_lock, LCK_ADAPTIVE,
- _kse_lock_wait, _kse_lock_wakeup) != 0)
- PANIC("Cannot initialize spinlock_static_lock");
- for (i = 0; i < MAX_SPINLOCKS; i++) {
- if (_lock_init(&extra[i].lock, LCK_ADAPTIVE,
- _kse_lock_wait, _kse_lock_wakeup) != 0)
- PANIC("Cannot initialize spinlock extra");
- }
- initialized = 1;
-}
diff --git a/lib/libkse/thread/thr_stack.c b/lib/libkse/thread/thr_stack.c
deleted file mode 100644
index f14289efb962..000000000000
--- a/lib/libkse/thread/thr_stack.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * Copyright (c) 2001 Daniel Eischen <deischen@freebsd.org>
- * Copyright (c) 2000-2001 Jason Evans <jasone@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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$
- */
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/queue.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-/* Spare thread stack. */
-struct stack {
- LIST_ENTRY(stack) qe; /* Stack queue linkage. */
- size_t stacksize; /* Stack size (rounded up). */
- size_t guardsize; /* Guard size. */
- void *stackaddr; /* Stack address. */
-};
-
-/*
- * Default sized (stack and guard) spare stack queue. Stacks are cached
- * to avoid additional complexity managing mmap()ed stack regions. Spare
- * stacks are used in LIFO order to increase cache locality.
- */
-static LIST_HEAD(, stack) dstackq = LIST_HEAD_INITIALIZER(dstackq);
-
-/*
- * Miscellaneous sized (non-default stack and/or guard) spare stack queue.
- * Stacks are cached to avoid additional complexity managing mmap()ed
- * stack regions. This list is unordered, since ordering on both stack
- * size and guard size would be more trouble than it's worth. Stacks are
- * allocated from this cache on a first size match basis.
- */
-static LIST_HEAD(, stack) mstackq = LIST_HEAD_INITIALIZER(mstackq);
-
-/**
- * Base address of the last stack allocated (including its red zone, if
- * there is one). Stacks are allocated contiguously, starting beyond the
- * top of the main stack. When a new stack is created, a red zone is
- * typically created (actually, the red zone is simply left unmapped) above
- * the top of the stack, such that the stack will not be able to grow all
- * the way to the bottom of the next stack. This isn't fool-proof. It is
- * possible for a stack to grow by a large amount, such that it grows into
- * the next stack, and as long as the memory within the red zone is never
- * accessed, nothing will prevent one thread stack from trouncing all over
- * the next.
- *
- * low memory
- * . . . . . . . . . . . . . . . . . .
- * | |
- * | stack 3 | start of 3rd thread stack
- * +-----------------------------------+
- * | |
- * | Red Zone (guard page) | red zone for 2nd thread
- * | |
- * +-----------------------------------+
- * | stack 2 - PTHREAD_STACK_DEFAULT | top of 2nd thread stack
- * | |
- * | |
- * | |
- * | |
- * | stack 2 |
- * +-----------------------------------+ <-- start of 2nd thread stack
- * | |
- * | Red Zone | red zone for 1st thread
- * | |
- * +-----------------------------------+
- * | stack 1 - PTHREAD_STACK_DEFAULT | top of 1st thread stack
- * | |
- * | |
- * | |
- * | |
- * | stack 1 |
- * +-----------------------------------+ <-- start of 1st thread stack
- * | | (initial value of last_stack)
- * | Red Zone |
- * | | red zone for main thread
- * +-----------------------------------+
- * | USRSTACK - PTHREAD_STACK_INITIAL | top of main thread stack
- * | | ^
- * | | |
- * | | |
- * | | | stack growth
- * | |
- * +-----------------------------------+ <-- start of main thread stack
- * (USRSTACK)
- * high memory
- *
- */
-static void *last_stack = NULL;
-
-int
-_thr_stack_alloc(struct pthread_attr *attr)
-{
- struct stack *spare_stack;
- struct kse *curkse;
- kse_critical_t crit;
- size_t stacksize;
- size_t guardsize;
-
- stacksize = attr->stacksize_attr;
- guardsize = attr->guardsize_attr;
-
- /*
- * Round up stack size to nearest multiple of _thr_page_size so
- * that mmap() * will work. If the stack size is not an even
- * multiple, we end up initializing things such that there is
- * unused space above the beginning of the stack, so the stack
- * sits snugly against its guard.
- */
- if ((stacksize % _thr_page_size) != 0)
- stacksize = ((stacksize / _thr_page_size) + 1) *
- _thr_page_size;
- attr->stackaddr_attr = NULL;
- attr->flags &= ~THR_STACK_USER;
-
- /*
- * Use the garbage collector lock for synchronization of the
- * spare stack lists and allocations from usrstack.
- */
- crit = _kse_critical_enter();
- curkse = _get_curkse();
- KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
- /*
- * If the stack and guard sizes are default, try to allocate a stack
- * from the default-size stack cache:
- */
- if ((stacksize == THR_STACK_DEFAULT) &&
- (guardsize == _thr_guard_default)) {
- if ((spare_stack = LIST_FIRST(&dstackq)) != NULL) {
- /* Use the spare stack. */
- LIST_REMOVE(spare_stack, qe);
- attr->stackaddr_attr = spare_stack->stackaddr;
- }
- }
- /*
- * The user specified a non-default stack and/or guard size, so try to
- * allocate a stack from the non-default size stack cache, using the
- * rounded up stack size (stack_size) in the search:
- */
- else {
- LIST_FOREACH(spare_stack, &mstackq, qe) {
- if (spare_stack->stacksize == stacksize &&
- spare_stack->guardsize == guardsize) {
- LIST_REMOVE(spare_stack, qe);
- attr->stackaddr_attr = spare_stack->stackaddr;
- break;
- }
- }
- }
- if (attr->stackaddr_attr != NULL) {
- /* A cached stack was found. Release the lock. */
- KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
- _kse_critical_leave(crit);
- }
- else {
- /* Allocate a stack from usrstack. */
- if (last_stack == NULL)
- last_stack = _usrstack - THR_STACK_INITIAL -
- _thr_guard_default;
-
- /* Allocate a new stack. */
- attr->stackaddr_attr = last_stack - stacksize;
-
- /*
- * Even if stack allocation fails, we don't want to try to
- * use this location again, so unconditionally decrement
- * last_stack. Under normal operating conditions, the most
- * likely reason for an mmap() error is a stack overflow of
- * the adjacent thread stack.
- */
- last_stack -= (stacksize + guardsize);
-
- /* Release the lock before mmap'ing it. */
- KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
- _kse_critical_leave(crit);
-
- /* Map the stack, but not the guard page: */
- if (mmap(attr->stackaddr_attr, stacksize,
- PROT_READ | PROT_WRITE, MAP_STACK, -1, 0) == MAP_FAILED)
- attr->stackaddr_attr = NULL;
- }
- if (attr->stackaddr_attr != NULL)
- return (0);
- else
- return (-1);
-}
-
-/* This function must be called with _thread_list_lock held. */
-void
-_thr_stack_free(struct pthread_attr *attr)
-{
- struct stack *spare_stack;
-
- if ((attr != NULL) && ((attr->flags & THR_STACK_USER) == 0)
- && (attr->stackaddr_attr != NULL)) {
- spare_stack = (attr->stackaddr_attr + attr->stacksize_attr
- - sizeof(struct stack));
- spare_stack->stacksize = attr->stacksize_attr;
- spare_stack->guardsize = attr->guardsize_attr;
- spare_stack->stackaddr = attr->stackaddr_attr;
-
- if (spare_stack->stacksize == THR_STACK_DEFAULT &&
- spare_stack->guardsize == _thr_guard_default) {
- /* Default stack/guard size. */
- LIST_INSERT_HEAD(&dstackq, spare_stack, qe);
- } else {
- /* Non-default stack/guard size. */
- LIST_INSERT_HEAD(&mstackq, spare_stack, qe);
- }
- attr->stackaddr_attr = NULL;
- }
-}
diff --git a/lib/libkse/thread/thr_suspend_np.c b/lib/libkse/thread/thr_suspend_np.c
deleted file mode 100644
index 4813de1ad6e5..000000000000
--- a/lib/libkse/thread/thr_suspend_np.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-static void suspend_common(struct pthread *thread);
-
-__weak_reference(_pthread_suspend_np, pthread_suspend_np);
-__weak_reference(_pthread_suspend_all_np, pthread_suspend_all_np);
-
-/* Suspend a thread: */
-int
-_pthread_suspend_np(pthread_t thread)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- /* Suspending the current thread doesn't make sense. */
- if (thread == _get_curthread())
- ret = EDEADLK;
-
- /* Add a reference to the thread: */
- else if ((ret = _thr_ref_add(curthread, thread, /*include dead*/0))
- == 0) {
- /* Lock the threads scheduling queue: */
- THR_SCHED_LOCK(curthread, thread);
- suspend_common(thread);
- /* Unlock the threads scheduling queue: */
- THR_SCHED_UNLOCK(curthread, thread);
-
- /* Don't forget to remove the reference: */
- _thr_ref_delete(curthread, thread);
- }
- return (ret);
-}
-
-void
-_pthread_suspend_all_np(void)
-{
- struct pthread *curthread = _get_curthread();
- struct pthread *thread;
- kse_critical_t crit;
-
- /* Take the thread list lock: */
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &_thread_list_lock);
-
- TAILQ_FOREACH(thread, &_thread_list, tle) {
- if (thread != curthread) {
- THR_SCHED_LOCK(curthread, thread);
- suspend_common(thread);
- THR_SCHED_UNLOCK(curthread, thread);
- }
- }
-
- /* Release the thread list lock: */
- KSE_LOCK_RELEASE(curthread->kse, &_thread_list_lock);
- _kse_critical_leave(crit);
-}
-
-void
-suspend_common(struct pthread *thread)
-{
- if ((thread->state != PS_DEAD) &&
- (thread->state != PS_DEADLOCK) &&
- ((thread->flags & THR_FLAGS_EXITING) == 0)) {
- thread->flags |= THR_FLAGS_SUSPENDED;
- if ((thread->flags & THR_FLAGS_IN_RUNQ) != 0) {
- THR_RUNQ_REMOVE(thread);
- THR_SET_STATE(thread, PS_SUSPENDED);
- }
-#ifdef NOT_YET
- if ((thread->attr.flags & PTHREAD_SCOPE_SYSTEM) != 0)
- /* ??? */
-#endif
- }
-}
diff --git a/lib/libkse/thread/thr_switch_np.c b/lib/libkse/thread/thr_switch_np.c
deleted file mode 100644
index b70ce7008f29..000000000000
--- a/lib/libkse/thread/thr_switch_np.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Daniel Eischen.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <errno.h>
-#include <pthread.h>
-#include <pthread_np.h>
-#include "thr_private.h"
-
-
-__weak_reference(_pthread_switch_add_np, pthread_switch_add_np);
-__weak_reference(_pthread_switch_delete_np, pthread_switch_delete_np);
-
-int
-_pthread_switch_add_np(pthread_switch_routine_t routine)
-{
- return (ENOTSUP);
-}
-
-int
-_pthread_switch_delete_np(pthread_switch_routine_t routine)
-{
- return (ENOTSUP);
-}
diff --git a/lib/libkse/thread/thr_system.c b/lib/libkse/thread/thr_system.c
deleted file mode 100644
index 28976d397d7b..000000000000
--- a/lib/libkse/thread/thr_system.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include <stdlib.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_system, system);
-
-int
-_system(const char *string)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __system(string);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_tcdrain.c b/lib/libkse/thread/thr_tcdrain.c
deleted file mode 100644
index 6a2002b79a3e..000000000000
--- a/lib/libkse/thread/thr_tcdrain.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include <termios.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_tcdrain, tcdrain);
-
-int
-_tcdrain(int fd)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __tcdrain(fd);
- _thr_leave_cancellation_point(curthread);
-
- return (ret);
-}
diff --git a/lib/libkse/thread/thr_vfork.c b/lib/libkse/thread/thr_vfork.c
deleted file mode 100644
index dbefc6521802..000000000000
--- a/lib/libkse/thread/thr_vfork.c
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * $FreeBSD$
- */
-#include <unistd.h>
-
-__weak_reference(_vfork, vfork);
-
-int
-_vfork(void)
-{
- return (fork());
-}
diff --git a/lib/libkse/thread/thr_wait.c b/lib/libkse/thread/thr_wait.c
deleted file mode 100644
index 98f2c8d558f3..000000000000
--- a/lib/libkse/thread/thr_wait.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_wait, wait);
-
-pid_t
-_wait(int *istat)
-{
- struct pthread *curthread = _get_curthread();
- pid_t ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __wait(istat);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_wait4.c b/lib/libkse/thread/thr_wait4.c
deleted file mode 100644
index 9f235848ed7c..000000000000
--- a/lib/libkse/thread/thr_wait4.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <sys/types.h>
-
-#include <errno.h>
-#include <sys/wait.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__wait4, wait4);
-
-pid_t
-__wait4(pid_t pid, int *istat, int options, struct rusage *rusage)
-{
- struct pthread *curthread = _get_curthread();
- pid_t ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = _wait4(pid, istat, options, rusage);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_waitpid.c b/lib/libkse/thread/thr_waitpid.c
deleted file mode 100644
index 8ee3ce160682..000000000000
--- a/lib/libkse/thread/thr_waitpid.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_waitpid, waitpid);
-
-pid_t
-_waitpid(pid_t wpid, int *status, int options)
-{
- struct pthread *curthread = _get_curthread();
- pid_t ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __waitpid(wpid, status, options);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_write.c b/lib/libkse/thread/thr_write.c
deleted file mode 100644
index 53d897ced1e9..000000000000
--- a/lib/libkse/thread/thr_write.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- *
- */
-#include <sys/types.h>
-#include <sys/fcntl.h>
-#include <sys/uio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__write, write);
-
-ssize_t
-__write(int fd, const void *buf, size_t nbytes)
-{
- struct pthread *curthread = _get_curthread();
- ssize_t ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __sys_write(fd, buf, nbytes);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_writev.c b/lib/libkse/thread/thr_writev.c
deleted file mode 100644
index e13c9d2f2960..000000000000
--- a/lib/libkse/thread/thr_writev.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- *
- */
-#include <sys/types.h>
-#include <sys/fcntl.h>
-#include <sys/uio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(__writev, writev);
-
-ssize_t
-__writev(int fd, const struct iovec *iov, int iovcnt)
-{
- struct pthread *curthread = _get_curthread();
- ssize_t ret;
-
- _thr_enter_cancellation_point(curthread);
- ret = __sys_writev(fd, iov, iovcnt);
- _thr_leave_cancellation_point(curthread);
-
- return ret;
-}
diff --git a/lib/libkse/thread/thr_yield.c b/lib/libkse/thread/thr_yield.c
deleted file mode 100644
index b41072fdd1f8..000000000000
--- a/lib/libkse/thread/thr_yield.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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$
- */
-#include <pthread.h>
-#include "thr_private.h"
-
-__weak_reference(_sched_yield, sched_yield);
-__weak_reference(_pthread_yield, pthread_yield);
-
-int
-_sched_yield(void)
-{
- struct pthread *curthread = _get_curthread();
-
- /* Reset the accumulated time slice value for the current thread: */
- curthread->slice_usec = -1;
-
- /* Schedule the next thread: */
- _thr_sched_switch(curthread);
- /* Always return no error. */
- return(0);
-}
-
-/* Draft 4 yield */
-void
-_pthread_yield(void)
-{
- struct pthread *curthread = _get_curthread();
-
- /* Reset the accumulated time slice value for the current thread: */
- curthread->slice_usec = -1;
-
- /* Schedule the next thread: */
- _thr_sched_switch(curthread);
-}
diff --git a/lib/ncurses/form/Makefile b/lib/ncurses/form/Makefile
deleted file mode 100644
index 7c225887fd9e..000000000000
--- a/lib/ncurses/form/Makefile
+++ /dev/null
@@ -1,97 +0,0 @@
-# Makefile for libform
-# $FreeBSD$
-
-NCURSES=${.CURDIR}/../../contrib/ncurses
-
-.PATH: ${NCURSES}/form
-.PATH: ${NCURSES}/include
-.PATH: ${NCURSES}/man
-
-LIB= form
-AWK?= awk
-
-SRCS= ncurses_def.h \
- fld_arg.c fld_attr.c fld_current.c fld_def.c fld_dup.c fld_ftchoice.c \
- fld_ftlink.c fld_info.c fld_just.c fld_link.c fld_max.c fld_move.c \
- fld_newftyp.c fld_opts.c fld_pad.c fld_page.c fld_stat.c fld_type.c \
- fld_user.c frm_cursor.c frm_data.c frm_def.c frm_driver.c frm_hook.c \
- frm_opts.c frm_page.c frm_post.c frm_req_name.c frm_scale.c frm_sub.c \
- frm_user.c frm_win.c fty_alnum.c fty_alpha.c fty_enum.c fty_int.c \
- fty_ipv4.c fty_num.c fty_regex.c
-INCS= ${NCURSES}/form/form.h
-
-CLEANFILES+= ncurses_def.h
-CFLAGS+= -I.
-.if exists(${.OBJDIR}/../libncurses)
-CFLAGS+= -I${.OBJDIR}/../libncurses
-.endif
-CFLAGS+=-I${.CURDIR}/../libncurses -I${NCURSES}/form -I${NCURSES}/menu \
- -I${NCURSES}/include -Wall -DNDEBUG -DHAVE_CONFIG_H
-
-ncurses_def.h: MKncurses_def.sh ncurses_defs
- AWK=${AWK} sh ${NCURSES}/include/MKncurses_def.sh \
- ${NCURSES}/include/ncurses_defs > ncurses_def.h
-
-MANx= form.3x form_cursor.3x form_data.3x form_driver.3x \
- form_field.3x form_field_attributes.3x form_field_buffer.3x \
- form_field_info.3x form_field_just.3x form_field_new.3x \
- form_field_opts.3x form_field_userptr.3x \
- form_field_validation.3x form_fieldtype.3x form_hook.3x \
- form_new.3x form_new_page.3x form_opts.3x form_page.3x \
- form_post.3x form_requestname.3x form_userptr.3x form_win.3x
-
-# Generate the MAN list from MANx
-.for page in ${MANx}
-CLEANFILES+=${page:T:S/x$//g}
-MAN+=${page:T:S/x$//g}
-${page:T:S/x$//g}: ${page}
- ln -s ${.ALLSRC} ${.TARGET}
-.endfor
-
-MLINKS+=form_cursor.3 pos_form_cursor.3
-MLINKS+=form_data.3 data_ahead.3 form_data.3 data_behind.3
-MLINKS+=form_field.3 field_count.3 form_field.3 form_fields.3 \
- form_field.3 move_field.3 form_field.3 set_form_fields.3
-MLINKS+=form_field_attributes.3 field_back.3 \
- form_field_attributes.3 field_fore.3 \
- form_field_attributes.3 field_pad.3 \
- form_field_attributes.3 set_field_back.3 \
- form_field_attributes.3 set_field_fore.3 \
- form_field_attributes.3 set_field_pad.3
-MLINKS+=form_field_buffer.3 field_buffer.3 \
- form_field_buffer.3 field_status.3 \
- form_field_buffer.3 set_field_buffer.3 \
- form_field_buffer.3 set_field_status.3 \
- form_field_buffer.3 set_max_field.3
-MLINKS+=form_field_info.3 dynamic_fieldinfo.3 form_field_info.3 field_info.3
-MLINKS+=form_field_just.3 field_just.3 form_field_just.3 set_field_just.3
-MLINKS+=form_field_new.3 dup_field.3 form_field_new.3 free_field.3 \
- form_field_new.3 link_field.3 form_field_new.3 new_field.3
-MLINKS+=form_field_opts.3 field_opts.3 form_field_opts.3 field_opts_off.3 \
- form_field_opts.3 field_opts_on.3 form_field_opts.3 set_field_opts.3 \
- form_field_opts.3 set_form_opts.3
-MLINKS+=form_field_userptr.3 field_userptr.3 \
- form_field_userptr.3 set_field_userptr.3
-MLINKS+=form_field_validation.3 field_arg.3 \
- form_field_validation.3 field_type.3 \
- form_field_validation.3 set_field_type.3
-MLINKS+=form_fieldtype.3 link_fieldtype.3 \
- form_fieldtype.3 set_fieldtype_arg.3 \
- form_fieldtype.3 set_fieldtype_choice.3
-MLINKS+=form_hook.3 field_init.3 form_hook.3 field_term.3 \
- form_hook.3 form_init.3 form_hook.3 form_term.3 \
- form_hook.3 set_field_init.3 form_hook.3 set_field_term.3 \
- form_hook.3 set_form_init.3 form_hook.3 set_form_term.3
-MLINKS+=form_new.3 free_form.3 form_new.3 new_form.3
-MLINKS+=form_new_page.3 new_page.3 form_new_page.3 set_new_page.3
-MLINKS+=form_opts.3 form_opts_off.3 form_opts.3 form_opts_on.3
-MLINKS+=form_page.3 current_field.3 form_page.3 field_index.3 \
- form_page.3 set_current_field.3 form_page.3 set_form_page.3
-MLINKS+=form_post.3 post_form.3 form_post.3 unpost_form.3
-MLINKS+=form_requestname.3 form_request_by_name.3 \
- form_requestname.3 form_request_name.3
-MLINKS+=form_userptr.3 set_form_userptr.3
-MLINKS+=form_win.3 form_sub.3 form_win.3 scale_form.3 \
- form_win.3 set_form_sub.3 form_win.3 set_form_win.3
-
-.include <bsd.lib.mk>
diff --git a/lib/ncurses/menu/Makefile b/lib/ncurses/menu/Makefile
deleted file mode 100644
index 0c3088bd6db4..000000000000
--- a/lib/ncurses/menu/Makefile
+++ /dev/null
@@ -1,82 +0,0 @@
-# Makefile for libmenu
-# $FreeBSD$
-
-NCURSES=${.CURDIR}/../../contrib/ncurses
-
-.PATH: ${NCURSES}/menu ${NCURSES}/include
-.PATH: ${NCURSES}/man
-
-LIB= menu
-AWK?= awk
-
-SRCS= ncurses_def.h \
- m_attribs.c m_cursor.c m_driver.c m_format.c m_global.c m_hook.c \
- m_item_cur.c m_item_nam.c m_item_new.c m_item_opt.c m_item_top.c \
- m_item_use.c m_item_val.c m_item_vis.c m_items.c m_new.c m_opts.c \
- m_pad.c m_pattern.c m_post.c m_req_name.c m_scale.c m_spacing.c \
- m_sub.c m_userptr.c m_win.c
-INCS= ${NCURSES}/menu/menu.h ${NCURSES}/menu/eti.h
-
-CLEANFILES+= ncurses_def.h
-CFLAGS+= -I.
-.if exists(${.OBJDIR}/../libncurses)
-CFLAGS+= -I${.OBJDIR}/../libncurses
-.endif
-CFLAGS+=-I${.CURDIR}/../libncurses -I${NCURSES}/menu -I${NCURSES}/include \
- -Wall -DNDEBUG -DHAVE_CONFIG_H
-
-ncurses_def.h: MKncurses_def.sh ncurses_defs
- AWK=${AWK} sh ${NCURSES}/include/MKncurses_def.sh \
- ${NCURSES}/include/ncurses_defs > ncurses_def.h
-
-MANx= menu.3x menu_attributes.3x menu_cursor.3x \
- menu_driver.3x menu_format.3x menu_hook.3x menu_items.3x \
- menu_mark.3x menu_new.3x menu_opts.3x menu_pattern.3x \
- menu_post.3x menu_requestname.3x menu_spacing.3x \
- menu_userptr.3x menu_win.3x mitem_current.3x mitem_name.3x \
- mitem_new.3x mitem_opts.3x mitem_userptr.3x mitem_value.3x \
- mitem_visible.3x
-
-# Generate the MAN list from MANx
-.for page in ${MANx}
-CLEANFILES+=${page:T:S/x$//g}
-MAN+=${page:T:S/x$//g}
-${page:T:S/x$//g}: ${page}
- ln -s ${.ALLSRC} ${.TARGET}
-.endfor
-
-MLINKS+=menu_attributes.3 menu_back.3 menu_attributes.3 menu_fore.3 \
- menu_attributes.3 menu_grey.3 menu_attributes.3 menu_pad.3 \
- menu_attributes.3 set_menu_back.3 menu_attributes.3 set_menu_fore.3 \
- menu_attributes.3 set_menu_grey.3 menu_attributes.3 set_menu_pad.3
-MLINKS+=menu_cursor.3 pos_menu_cursor.3
-MLINKS+=menu_format.3 set_menu_format.3
-MLINKS+=menu_hook.3 item_init.3 menu_hook.3 item_term.3 \
- menu_hook.3 menu_init.3 menu_hook.3 menu_term.3 \
- menu_hook.3 set_item_init.3 menu_hook.3 set_item_term.3 \
- menu_hook.3 set_menu_init.3 menu_hook.3 set_menu_term.3
-MLINKS+=menu_items.3 item_count.3 menu_items.3 set_menu_items.3
-MLINKS+=menu_mark.3 set_menu_mark.3
-MLINKS+=menu_new.3 free_menu.3 menu_new.3 new_menu.3
-MLINKS+=menu_opts.3 menu_opts_off.3 menu_opts.3 menu_opts_on.3
-MLINKS+=menu_pattern.3 set_menu_pattern.3
-MLINKS+=menu_post.3 post_menu.3 menu_post.3 unpost_menu.3
-MLINKS+=menu_requestname.3 menu_request_by_name.3 \
- menu_requestname.3 menu_request_name.3
-MLINKS+=menu_spacing.3 set_menu_spacing.3
-MLINKS+=menu_userptr.3 set_menu_userptr.3
-MLINKS+=menu_win.3 menu_sub.3 menu_win.3 scale_menu.3 \
- menu_win.3 set_menu_sub.3 menu_win.3 set_menu_win.3
-MLINKS+=mitem_current.3 current_item.3 mitem_current.3 item_index.3 \
- mitem_current.3 set_top_row.3 mitem_current.3 top_row.3 \
- mitem_current.3 set_current_item.3
-MLINKS+=mitem_name.3 item_description.3 mitem_name.3 item_name.3
-MLINKS+=mitem_new.3 free_item.3 mitem_new.3 new_item.3
-MLINKS+=mitem_opts.3 item_opts.3 mitem_opts.3 item_opts_off.3 \
- mitem_opts.3 item_opts_on.3 mitem_opts.3 set_item_opts.3 \
- mitem_opts.3 set_menu_opts.3
-MLINKS+=mitem_userptr.3 item_userptr.3 mitem_userptr.3 set_item_userptr.3
-MLINKS+=mitem_value.3 item_value.3 mitem_value.3 set_item_value.3
-MLINKS+=mitem_visible.3 item_visible.3
-
-.include <bsd.lib.mk>
diff --git a/lib/ncurses/ncurses/Makefile b/lib/ncurses/ncurses/Makefile
deleted file mode 100644
index 9be40a00c28f..000000000000
--- a/lib/ncurses/ncurses/Makefile
+++ /dev/null
@@ -1,562 +0,0 @@
-# $FreeBSD$
-
-NCURSES=${.CURDIR}/../../contrib/ncurses
-
-LIB= ncurses
-SHLIB_MAJOR=5
-
-# Should be elsewhere
-AWK?= awk
-TERMINFODIR?= ${SHAREDIR}/misc
-
-NCURSES_MAJOR!=egrep 'NCURSES_MAJOR[ ]*=' ${NCURSES}/dist.mk | sed -e 's%^[^0-9]*%%'
-NCURSES_MINOR!=egrep 'NCURSES_MINOR[ ]*=' ${NCURSES}/dist.mk | sed -e 's%^[^0-9]*%%'
-NCURSES_PATCH!=egrep 'NCURSES_PATCH[ ]*=' ${NCURSES}/dist.mk | sed -e 's%^[^0-9]*%%'
-
-# From autoconf (!)
-NCURSES_CONST= const
-NCURSES_XNAMES= 1
-NCURSES_OSPEED= short
-NCURSES_CH_T= chtype
-NCURSES_EXT_FUNCS= 1
-NCURSES_LIBUTF8= 0
-NCURSES_MBSTATE_T= 0
-BROKEN_LINKER= 0
-BUILTIN_BOOL= 1
-BOOL_TYPE= 0
-HAVE_VSSCANF= 1
-HEADER_STDBOOL= 1
-TYPE_OF_BOOL= unsigned char
-TYPEOF_CHTYPE= long
-WIDEC_SHIFT= 8
-SHIFT_LIMIT= 32
-ONEUL= 1UL
-
-.PATH: ${NCURSES}/ncurses
-.PATH: ${NCURSES}/ncurses/base
-.PATH: ${NCURSES}/ncurses/tinfo
-.PATH: ${NCURSES}/ncurses/tty
-.PATH: ${NCURSES}/ncurses/trace
-.PATH: ${NCURSES}/include
-.PATH: ${NCURSES}/man
-
-CFLAGS+=-I. -I${.CURDIR} -I${NCURSES}/ncurses -I${NCURSES}/include
-CFLAGS+=-Wall -DFREEBSD_NATIVE -DNDEBUG -DHAVE_CONFIG_H -DTERMIOS
-
-GENSRC= \
- codes.c \
- expanded.c \
- fallback.c \
- lib_gen.c \
- lib_keyname.c \
- names.c \
- unctrl.c
-
-GENHDR= \
- curses.h \
- hashsize.h \
- init_keytry.h \
- ncurses_def.h \
- nomacros.h \
- parametrized.h \
- term.h \
- termcap.h \
- unctrl.h
-
-# Installed
-HEADERS=curses.h term.h termcap.h unctrl.h
-SRCHDRS=ncurses_dll.h
-INCS= ${HEADERS} ${SRCHDRS}
-INCSLINKS= curses.h ${INCLUDEDIR}/ncurses.h
-
-# Components of names.c and codes.c
-NAMESRC=boolnames boolfnames numnames numfnames strnames strfnames
-CODESRC=boolcodes numcodes strcodes
-
-SRCS= ${GENHDR} ${GENSRC} \
- access.c \
- add_tries.c \
- alloc_entry.c \
- alloc_ttype.c \
- captoinfo.c \
- comp_captab.c \
- comp_error.c \
- comp_expand.c \
- comp_hash.c \
- comp_parse.c \
- comp_scan.c \
- define_key.c \
- doalloc.c \
- free_ttype.c \
- getenv_num.c \
- hardscroll.c \
- hashmap.c \
- home_terminfo.c \
- init_keytry.c \
- keybound.c \
- keyok.c \
- lib_acs.c \
- lib_addch.c \
- lib_addstr.c \
- lib_baudrate.c \
- lib_beep.c \
- lib_bkgd.c \
- lib_box.c \
- lib_chgat.c \
- lib_clear.c \
- lib_clearok.c \
- lib_clrbot.c \
- lib_clreol.c \
- lib_color.c \
- lib_colorset.c \
- lib_cur_term.c \
- lib_data.c \
- lib_delch.c \
- lib_delwin.c \
- lib_dft_fgbg.c \
- lib_echo.c \
- lib_endwin.c \
- lib_erase.c \
- lib_flash.c \
- lib_freeall.c \
- lib_getch.c \
- lib_getstr.c \
- lib_has_cap.c \
- lib_hline.c \
- lib_immedok.c \
- lib_inchstr.c \
- lib_initscr.c \
- lib_insch.c \
- lib_insdel.c \
- lib_insstr.c \
- lib_instr.c \
- lib_isendwin.c \
- lib_kernel.c \
- lib_leaveok.c \
- lib_longname.c \
- lib_mouse.c \
- lib_move.c \
- lib_mvcur.c \
- lib_mvwin.c \
- lib_napms.c \
- lib_newterm.c \
- lib_newwin.c \
- lib_nl.c \
- lib_options.c \
- lib_overlay.c \
- lib_pad.c \
- lib_print.c \
- lib_printw.c \
- lib_raw.c \
- lib_redrawln.c \
- lib_refresh.c \
- lib_restart.c \
- lib_scanw.c \
- lib_screen.c \
- lib_scroll.c \
- lib_scrollok.c \
- lib_scrreg.c \
- lib_set_term.c \
- lib_setup.c \
- lib_slk.c \
- lib_slkatr_set.c \
- lib_slkatrof.c \
- lib_slkatron.c \
- lib_slkatrset.c \
- lib_slkattr.c \
- lib_slkclear.c \
- lib_slkcolor.c \
- lib_slkinit.c \
- lib_slklab.c \
- lib_slkrefr.c \
- lib_slkset.c \
- lib_slktouch.c \
- lib_termcap.c \
- lib_termname.c \
- lib_tgoto.c \
- lib_ti.c \
- lib_touch.c \
- lib_tparm.c \
- lib_tputs.c \
- lib_trace.c \
- lib_tstp.c \
- lib_ttyflags.c \
- lib_twait.c \
- lib_ungetch.c \
- lib_vidattr.c \
- lib_vline.c \
- lib_wattroff.c \
- lib_wattron.c \
- lib_winch.c \
- lib_window.c \
- memmove.c \
- name_match.c \
- nc_panel.c \
- parse_entry.c \
- read_entry.c \
- resizeterm.c \
- safe_sprintf.c \
- setbuf.c \
- sigaction.c \
- strings.c \
- tries.c \
- tty_update.c \
- varargs.c \
- version.c \
- visbuf.c \
- vsscanf.c \
- wresize.c \
- write_entry.c
-
-# Currently unused, for debugging libncurses itself.
-DBGSRCS=lib_traceatr.c \
- lib_tracebits.c \
- lib_tracechr.c \
- lib_tracedmp.c \
- lib_tracemse.c \
- trace_buf.c \
- trace_tries.c \
- trace_xnames.c
-
-# From our old libtermcap.
-# Used instead of the hideous read_termcap.c abomination.
-SRCS+= termcap.c
-
-CLEANFILES+= ${GENSRC} ${GENHDR} keys.list make_hash term.h.new \
- make_keys MKterm.h.awk comp_captab.c curses.head \
- namehdr nameftr codeftr ${NAMESRC} ${CODESRC}
-
-SYMLINKS+=libncurses.a ${LIBDIR}/libcurses.a
-SYMLINKS+=libncurses.a ${LIBDIR}/libtermcap.a
-SYMLINKS+=libncurses.a ${LIBDIR}/libtermlib.a
-SYMLINKS+=libncurses.a ${LIBDIR}/libmytinfo.a
-SYMLINKS+=libncurses.a ${LIBDIR}/libtinfo.a
-.if !defined(NOPIC)
-# no need for major at all, it's an ld-time redirection only
-SYMLINKS+=libncurses.so ${SHLIBDIR}/libcurses.so
-SYMLINKS+=libncurses.so ${SHLIBDIR}/libtermcap.so
-SYMLINKS+=libncurses.so ${SHLIBDIR}/libtermlib.so
-SYMLINKS+=libncurses.so ${SHLIBDIR}/libmytinfo.so
-SYMLINKS+=libncurses.so ${SHLIBDIR}/libtinfo.so
-.endif
-.if !defined(NOPROFILE)
-SYMLINKS+=libncurses_p.a ${LIBDIR}/libcurses_p.a
-SYMLINKS+=libncurses_p.a ${LIBDIR}/libtermcap_p.a
-SYMLINKS+=libncurses_p.a ${LIBDIR}/libtermlib_p.a
-SYMLINKS+=libncurses_p.a ${LIBDIR}/libmytinfo_p.a
-SYMLINKS+=libncurses_p.a ${LIBDIR}/libtinfo_p.a
-.endif
-
-DOCSDIR= /usr/share/doc/ncurses
-DOCS= ncurses-intro.html hackguide.html
-
-.if !defined(NOHTML)
-afterinstall:
-.for file in ${DOCS}
- cd ${.CURDIR}/../../contrib/ncurses/doc/html ; \
- ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m 444 ${file} \
- ${DESTDIR}${DOCSDIR}
-.endfor
-.endif
-
-# Generated source
-namehdr nameftr codeftr ${NAMESRC} ${CODESRC}: MKnames.awk Caps
- ${AWK} -f ${NCURSES}/ncurses/tinfo/MKnames.awk ${NCURSES}/include/Caps
-
-.ORDER: namehdr ${NAMESRC} ${CODESRC} nameftr codeftr names.c codes.c
-
-names.c: namehdr ${NAMESRC} nameftr
- cat namehdr ${NAMESRC} nameftr > $@
-
-codes.c: namehdr ${CODESRC} codeftr
- cat namehdr ${CODESRC} codeftr > $@
-
-lib_gen.c: MKlib_gen.sh curses.h
- LC_ALL=C sh ${NCURSES}/ncurses/base/MKlib_gen.sh "${CC} -E ${CFLAGS}" \
- "${AWK}" generated < curses.h >$@
-
-lib_keyname.c: keys.list MKkeyname.awk
- ${AWK} -f ${NCURSES}/ncurses/base/MKkeyname.awk keys.list > lib_keyname.c
-
-unctrl.c: MKunctrl.awk
- echo | ${AWK} -f ${NCURSES}/ncurses/base/MKunctrl.awk > unctrl.c
-
-comp_captab.c: MKcaptab.awk Caps make_hash
- sh ${NCURSES}/ncurses/tinfo/MKcaptab.awk "${AWK}" \
- ${NCURSES}/include/Caps > comp_captab.c
-
-expanded.c: MKexpanded.sh
- sh ${NCURSES}/ncurses/tty/MKexpanded.sh "${CC} -E" ${CFLAGS} >expanded.c
-
-fallback.c: MKfallback.sh
- sh ${NCURSES}/ncurses/tinfo/MKfallback.sh > fallback.c
-
-# Generated headers
-ncurses_def.h: MKncurses_def.sh ncurses_defs
- AWK=${AWK} sh ${NCURSES}/include/MKncurses_def.sh \
- ${NCURSES}/include/ncurses_defs > ncurses_def.h
-
-nomacros.h: MKlib_gen.sh curses.h
- LC_ALL=C sh ${NCURSES}/ncurses/base/MKlib_gen.sh "${CC} -E ${CFLAGS}" \
- "${AWK}" generated < curses.h | fgrep undef > $@
-
-init_keytry.h: keys.list make_keys
- ./make_keys keys.list > init_keytry.h
-
-hashsize.h: MKhashsize.sh Caps
- sh ${NCURSES}/include/MKhashsize.sh ${NCURSES}/include/Caps > $@
-
-parametrized.h: MKparametrized.sh Caps
- AWK=${AWK} sh ${NCURSES}/include/MKparametrized.sh \
- ${NCURSES}/include/Caps > $@
-
-term.h: MKterm.h.awk edit_cfg.sh Caps
- ${AWK} -f MKterm.h.awk ${NCURSES}/include/Caps > $@.new
- sh ${NCURSES}/include/edit_cfg.sh ${.CURDIR}/ncurses_cfg.h $@.new
- mv -f $@.new $@
-
-curses.h: curses.head MKkey_defs.sh Caps
- cat curses.head > $@.new
- AWK=${AWK} _POSIX2_VERSION=199209 sh ${NCURSES}/include/MKkey_defs.sh \
- ${NCURSES}/include/Caps >> $@.new
- cat ${NCURSES}/include/curses.tail >> $@.new
- mv -f $@.new $@
-
-# Generated intermediate files
-keys.list: MKkeys_list.sh Caps
- AWK=${AWK} sh ${NCURSES}/ncurses/tinfo/MKkeys_list.sh \
- ${NCURSES}/include/Caps | LC_ALL=C sort > keys.list
-
-# Build tools
-build-tools: make_hash make_keys
-
-make_keys: make_keys.c names.c ncurses_def.h ${HEADERS}
- ${CC} -o $@ ${CFLAGS} ${NCURSES}/ncurses/tinfo/make_keys.c
-
-make_hash: comp_hash.c hashsize.h ncurses_def.h ${HEADERS}
- ${CC} -o $@ ${CFLAGS} -DMAIN_PROGRAM \
- ${NCURSES}/ncurses/tinfo/comp_hash.c
-
-# ./configure generated
-MKterm.h.awk: MKterm.h.awk.in
- sed <${NCURSES}/include/MKterm.h.awk.in >$@ \
- -e "/@NCURSES_MAJOR@/s%%${NCURSES_MAJOR}%" \
- -e "/@NCURSES_MINOR@/s%%${NCURSES_MINOR}%" \
- -e "/@NCURSES_CONST@/s%%${NCURSES_CONST}%" \
- -e "/@NCURSES_XNAMES@/s%%${NCURSES_XNAMES}%"
-
-termcap.h: termcap.h.in
- sed <${NCURSES}/include/termcap.h.in >$@ \
- -e "/@NCURSES_MAJOR@/s%%${NCURSES_MAJOR}%" \
- -e "/@NCURSES_MINOR@/s%%${NCURSES_MINOR}%" \
- -e "/@NCURSES_CONST@/s%%${NCURSES_CONST}%" \
- -e "/@NCURSES_OSPEED@/s%%${NCURSES_OSPEED}%"
-
-curses.head: curses.h.in
- sed <${NCURSES}/include/curses.h.in >$@ \
- -e "/@BROKEN_LINKER@/s%%${BROKEN_LINKER}%" \
- -e "/@HAVE_VSSCANF@/s%%${HAVE_VSSCANF}%" \
- -e "/@NCURSES_CONST@/s%%${NCURSES_CONST}%" \
- -e "/@NCURSES_MAJOR@/s%%${NCURSES_MAJOR}%" \
- -e "/@NCURSES_MINOR@/s%%${NCURSES_MINOR}%" \
- -e "/@NCURSES_PATCH@/s%%${NCURSES_PATCH}%" \
- -e "/@NCURSES_CH_T@/s%%${NCURSES_CH_T}%" \
- -e "/@NCURSES_EXT_FUNCS@/s%%${NCURSES_EXT_FUNCS}%" \
- -e "/@NCURSES_LIBUTF8@/s%%${NCURSES_LIBUTF8}%" \
- -e "/@NCURSES_MBSTATE_T@/s%%${NCURSES_MBSTATE_T}%" \
- -e "s%@cf_cv_1UL@%${ONEUL}%g" \
- -e "s%@cf_cv_builtin_bool@%${BUILTIN_BOOL}%g" \
- -e "s%@cf_cv_cc_bool_type@%${BOOL_TYPE}%g" \
- -e "s%@cf_cv_shift_limit@%${SHIFT_LIMIT}%g" \
- -e "s%@cf_cv_header_stdbool_h@%${HEADER_STDBOOL}%g" \
- -e "s%@cf_cv_type_of_bool@%${TYPE_OF_BOOL}%g" \
- -e "s%@cf_cv_typeof_chtype@%${TYPEOF_CHTYPE}%g" \
- -e "s%@cf_cv_widec_shift@%${WIDEC_SHIFT}%g" \
- -e "s/ _WCHAR_T/ __wchar_t/g" \
- -e "s/ _WINT_T/ __wint_t/g" \
-
-unctrl.h: unctrl.h.in
- sed <${NCURSES}/include/$@.in >$@ \
- -e "/@NCURSES_MAJOR@/s%%${NCURSES_MAJOR}%" \
- -e "/@NCURSES_MINOR@/s%%${NCURSES_MINOR}%"
-
-# MAN page gunk
-terminfo.5: MKterminfo.sh terminfo.head Caps
- sh ${NCURSES}/man/MKterminfo.sh ${NCURSES}/man/terminfo.head \
- ${NCURSES}/include/Caps ${NCURSES}/man/terminfo.tail >$@
-
-CLEANFILES+= terminfo.5
-MANFILTER= sed -e 's%@TERMINFO@%${TERMINFODIR}/terminfo%g' \
- -e 's%@NCURSES_OSPEED@%${NCURSES_OSPEED}%g'
-
-MANx= curs_addch.3x curs_addchstr.3x curs_addstr.3x curs_attr.3x \
- curs_beep.3x curs_bkgd.3x curs_border.3x curs_clear.3x curs_color.3x \
- curs_delch.3x curs_deleteln.3x curs_extend.3x curs_getch.3x \
- curs_getstr.3x \
- curs_getyx.3x curs_inch.3x curs_inchstr.3x curs_initscr.3x \
- curs_inopts.3x curs_insch.3x curs_insstr.3x curs_instr.3x \
- curs_kernel.3x curs_mouse.3x curs_move.3x curs_outopts.3x \
- curs_overlay.3x curs_pad.3x curs_print.3x curs_printw.3x \
- curs_refresh.3x curs_scanw.3x curs_scr_dump.3x curs_scroll.3x \
- curs_slk.3x curs_termattrs.3x curs_termcap.3x curs_terminfo.3x \
- curs_touch.3x curs_trace.3x curs_util.3x curs_window.3x \
- default_colors.3x define_key.3x \
- keybound.3x keyok.3x ncurses.3x resizeterm.3x wresize.3x
-MAN= term.5 terminfo.5
-MAN+= term.7
-
-# Generate the MAN list from MANx
-.for page in ${MANx}
-CLEANFILES+=${page:T:S/x$//g}
-MAN+=${page:T:S/x$//g}
-${page:T:S/x$//g}: ${page}
- ln -sf ${.ALLSRC} ${.TARGET}
-.endfor
-
-MLINKS+=ncurses.3 curses.3
-MLINKS+=curs_addch.3 addch.3 curs_addch.3 echochar.3 curs_addch.3 mvaddch.3 \
- curs_addch.3 mvwaddch.3 curs_addch.3 waddch.3 curs_addch.3 wechochar.3
-MLINKS+=curs_addchstr.3 addchnstr.3 curs_addchstr.3 addchstr.3 \
- curs_addchstr.3 mvaddchnstr.3 curs_addchstr.3 mvaddchstr.3 \
- curs_addchstr.3 mvwaddchnstr.3 curs_addchstr.3 mvwaddchstr.3 \
- curs_addchstr.3 waddchnstr.3 curs_addchstr.3 waddchstr.3
-MLINKS+=curs_addstr.3 addnstr.3 curs_addstr.3 addstr.3 \
- curs_addstr.3 mvaddnstr.3 curs_addstr.3 mvaddstr.3 \
- curs_addstr.3 mvwaddnstr.3 curs_addstr.3 mvwaddstr.3 \
- curs_addstr.3 waddnstr.3 curs_addstr.3 waddstr.3
-MLINKS+=curs_attr.3 PAIR_NUMBER.3 \
- curs_attr.3 attr_get.3 curs_attr.3 attr_off.3 curs_attr.3 attr_on.3 \
- curs_attr.3 attr_set.3 curs_attr.3 attroff.3 curs_attr.3 attron.3 \
- curs_attr.3 attrset.3 curs_attr.3 chgat.3 curs_attr.3 color_set.3 \
- curs_attr.3 mvchgat.3 curs_attr.3 mvwchgat.3 curs_attr.3 standend.3 \
- curs_attr.3 standout.3 curs_attr.3 wattr_get.3 curs_attr.3 wattr_off.3 \
- curs_attr.3 wattr_on.3 curs_attr.3 wattr_set.3 curs_attr.3 wattroff.3 \
- curs_attr.3 wattron.3 curs_attr.3 wattrset.3 curs_attr.3 wchgat.3 \
- curs_attr.3 wcolor_set.3 curs_attr.3 wstandend.3 \
- curs_attr.3 wstandout.3
-MLINKS+=curs_beep.3 beep.3 curs_beep.3 flash.3
-MLINKS+=curs_bkgd.3 bkgd.3 curs_bkgd.3 bkgdset.3 curs_bkgd.3 getbkgd.3 \
- curs_bkgd.3 wbkgd.3 curs_bkgd.3 wbkgdset.3
-MLINKS+=curs_border.3 border.3 curs_border.3 box.3 curs_border.3 hline.3 \
- curs_border.3 mvhline.3 curs_border.3 mvvline.3 \
- curs_border.3 mvwhline.3 \
- curs_border.3 mvwvline.3 curs_border.3 vline.3 curs_border.3 wborder.3 \
- curs_border.3 whline.3 curs_border.3 wvline.3
-MLINKS+=curs_clear.3 clear.3 curs_clear.3 clrtobot.3 curs_clear.3 clrtoeol.3 \
- curs_clear.3 erase.3 curs_clear.3 wclear.3 curs_clear.3 wclrtobot.3 \
- curs_clear.3 wclrtoeol.3 curs_clear.3 werase.3
-MLINKS+=curs_color.3 COLOR_PAIR.3 \
- curs_color.3 can_change_color.3 curs_color.3 color_content.3 \
- curs_color.3 has_colors.3 curs_color.3 init_color.3 \
- curs_color.3 init_pair.3 curs_color.3 pair_content.3 \
- curs_color.3 start_color.3
-MLINKS+=curs_delch.3 delch.3 curs_delch.3 mvdelch.3 curs_delch.3 mvwdelch.3 \
- curs_delch.3 wdelch.3
-MLINKS+=curs_deleteln.3 deleteln.3 curs_deleteln.3 insdelln.3 \
- curs_deleteln.3 insertln.3 curs_deleteln.3 wdeleteln.3 \
- curs_deleteln.3 winsdelln.3 curs_deleteln.3 winsertln.3
-MLINKS+=curs_extend.3 curses_version.3 curs_extend.3 use_extended_names.3
-MLINKS+=curs_getch.3 getch.3 curs_getch.3 has_key.3 curs_getch.3 mvgetch.3 \
- curs_getch.3 mvwgetch.3 curs_getch.3 ungetch.3 curs_getch.3 wgetch.3
-MLINKS+=curs_getstr.3 getnstr.3 curs_getstr.3 getstr.3 \
- curs_getstr.3 mvgetnstr.3 curs_getstr.3 mvgetstr.3 \
- curs_getstr.3 mvwgetnstr.3 curs_getstr.3 mvwgetstr.3 \
- curs_getstr.3 wgetnstr.3 curs_getstr.3 wgetstr.3
-MLINKS+=curs_getyx.3 getbegyx.3 curs_getyx.3 getmaxyx.3 \
- curs_getyx.3 getparyx.3 curs_getyx.3 getyx.3
-MLINKS+=curs_inch.3 inch.3 curs_inch.3 mvinch.3 curs_inch.3 mvwinch.3 \
- curs_inch.3 winch.3
-MLINKS+=curs_inchstr.3 inchnstr.3 curs_inchstr.3 inchstr.3 \
- curs_inchstr.3 mvinchnstr.3 curs_inchstr.3 mvinchstr.3 \
- curs_inchstr.3 mvwinchnstr.3 curs_inchstr.3 mvwinchstr.3 \
- curs_inchstr.3 winchnstr.3 curs_inchstr.3 winchstr.3
-MLINKS+=curs_initscr.3 delscreen.3 curs_initscr.3 endwin.3 \
- curs_initscr.3 initscr.3 curs_initscr.3 isendwin.3 \
- curs_initscr.3 newterm.3 curs_initscr.3 set_term.3
-MLINKS+=curs_inopts.3 cbreak.3 curs_inopts.3 echo.3 curs_inopts.3 halfdelay.3 \
- curs_inopts.3 intrflush.3 curs_inopts.3 keypad.3 curs_inopts.3 meta.3 \
- curs_inopts.3 nocbreak.3 curs_inopts.3 nodelay.3 \
- curs_inopts.3 noecho.3 curs_inopts.3 noqiflush.3 curs_inopts.3 noraw.3 \
- curs_inopts.3 notimeout.3 curs_inopts.3 qiflush.3 curs_inopts.3 raw.3 \
- curs_inopts.3 timeout.3 curs_inopts.3 typeahead.3 \
- curs_inopts.3 wtimeout.3
-MLINKS+=curs_insch.3 insch.3 curs_insch.3 mvinsch.3 curs_insch.3 mvwinsch.3 \
- curs_insch.3 winsch.3
-MLINKS+=curs_insstr.3 insnstr.3 curs_insstr.3 insstr.3 \
- curs_insstr.3 mvinsnstr.3 curs_insstr.3 mvinsstr.3 \
- curs_insstr.3 mvwinsnstr.3 curs_insstr.3 mvwinsstr.3 \
- curs_insstr.3 winsnstr.3 curs_insstr.3 winsstr.3
-MLINKS+=curs_instr.3 innstr.3 curs_instr.3 instr.3 curs_instr.3 mvinnstr.3 \
- curs_instr.3 mvinstr.3 curs_instr.3 mvwinnstr.3 \
- curs_instr.3 mvwinstr.3 curs_instr.3 winnstr.3 curs_instr.3 winstr.3
-MLINKS+=curs_kernel.3 curs_set.3 curs_kernel.3 def_prog_mode.3 \
- curs_kernel.3 def_shell_mode.3 curs_kernel.3 getsyx.3 \
- curs_kernel.3 napms.3 curs_kernel.3 reset_prog_mode.3 \
- curs_kernel.3 reset_shell_mode.3 curs_kernel.3 resetty.3 \
- curs_kernel.3 ripoffline.3 curs_kernel.3 savetty.3 \
- curs_kernel.3 setsyx.3
-MLINKS+=curs_mouse.3 getmouse.3 curs_mouse.3 mouse_trafo.3 \
- curs_mouse.3 mouseinterval.3 \
- curs_mouse.3 mousemask.3 curs_mouse.3 ungetmouse.3 \
- curs_mouse.3 wenclose.3 curs_mouse.3 wmouse_trafo.3
-MLINKS+=curs_move.3 move.3 curs_move.3 wmove.3
-MLINKS+=curs_outopts.3 clearok.3 curs_outopts.3 idcok.3 curs_outopts.3 idlok.3 \
- curs_outopts.3 immedok.3 curs_outopts.3 leaveok.3 curs_outopts.3 nl.3 \
- curs_outopts.3 nonl.3 curs_outopts.3 scrollok.3 \
- curs_outopts.3 setscrreg.3 curs_outopts.3 wsetscrreg.3
-MLINKS+=curs_overlay.3 copywin.3 curs_overlay.3 overlay.3 \
- curs_overlay.3 overwrite.3
-MLINKS+=curs_pad.3 newpad.3 curs_pad.3 pechochar.3 curs_pad.3 pnoutrefresh.3 \
- curs_pad.3 prefresh.3 curs_pad.3 subpad.3
-MLINKS+=curs_print.3 mcprint.3
-MLINKS+=curs_printw.3 mvprintw.3 curs_printw.3 mvwprintw.3 \
- curs_printw.3 printw.3 curs_printw.3 vw_printw.3 \
- curs_printw.3 vwprintw.3 curs_printw.3 wprintw.3
-MLINKS+=curs_refresh.3 doupdate.3 curs_refresh.3 redrawwin.3 \
- curs_refresh.3 refresh.3 curs_refresh.3 wnoutrefresh.3 \
- curs_refresh.3 wredrawln.3 curs_refresh.3 wrefresh.3
-MLINKS+=curs_scanw.3 mvscanw.3 curs_scanw.3 mvwscanw.3 curs_scanw.3 scanw.3 \
- curs_scanw.3 vw_scanw.3 curs_scanw.3 vwscanw.3 curs_scanw.3 wscanw.3
-MLINKS+=curs_scr_dump.3 scr_dump.3 curs_scr_dump.3 scr_init.3 \
- curs_scr_dump.3 scr_restore.3 curs_scr_dump.3 scr_set.3
-MLINKS+=curs_scroll.3 scrl.3 curs_scroll.3 scroll.3 curs_scroll.3 wscrl.3
-MLINKS+=curs_slk.3 slk_attr.3 curs_slk.3 slk_attr_off.3 \
- curs_slk.3 slk_attr_on.3 curs_slk.3 slk_attr_set.3 \
- curs_slk.3 slk_attroff.3 curs_slk.3 slk_attron.3 \
- curs_slk.3 slk_attrset.3 curs_slk.3 slk_clear.3 \
- curs_slk.3 slk_color.3 curs_slk.3 slk_init.3 curs_slk.3 slk_label.3 \
- curs_slk.3 slk_noutrefresh.3 curs_slk.3 slk_refresh.3 \
- curs_slk.3 slk_restore.3 curs_slk.3 slk_set.3 curs_slk.3 slk_touch.3
-MLINKS+=curs_termattrs.3 baudrate.3 curs_termattrs.3 erasechar.3 \
- curs_termattrs.3 has_ic.3 curs_termattrs.3 has_il.3 \
- curs_termattrs.3 killchar.3 curs_termattrs.3 longname.3 \
- curs_termattrs.3 termattrs.3 curs_termattrs.3 termname.3
-MLINKS+=curs_termcap.3 termcap.3 curs_termcap.3 tgetent.3 \
- curs_termcap.3 tgetflag.3 curs_termcap.3 tgetnum.3 \
- curs_termcap.3 tgetstr.3 curs_termcap.3 tgoto.3 \
- curs_termcap.3 tputs.3
-MLINKS+=curs_terminfo.3 del_curterm.3 curs_terminfo.3 mvcur.3 \
- curs_terminfo.3 putp.3 curs_terminfo.3 restartterm.3 \
- curs_terminfo.3 set_curterm.3 curs_terminfo.3 setterm.3 \
- curs_terminfo.3 setupterm.3 curs_terminfo.3 tigetflag.3 \
- curs_terminfo.3 tigetnum.3 curs_terminfo.3 tigetstr.3 \
- curs_terminfo.3 tparm.3 curs_terminfo.3 tputs.3 \
- curs_terminfo.3 vidattr.3 curs_terminfo.3 vidputs.3
-MLINKS+=curs_touch.3 is_linetouched.3 curs_touch.3 is_wintouched.3 \
- curs_touch.3 touchline.3 curs_touch.3 touchwin.3 \
- curs_touch.3 untouchwin.3 curs_touch.3 wtouchln.3
-MLINKS+=curs_util.3 delay_output.3 curs_util.3 filter.3 \
- curs_util.3 flushinp.3 curs_util.3 getwin.3 \
- curs_util.3 keyname.3 curs_util.3 putwin.3 \
- curs_util.3 unctrl.3 curs_util.3 use_env.3
-MLINKS+=curs_window.3 delwin.3 curs_window.3 derwin.3 curs_window.3 dupwin.3 \
- curs_window.3 mvderwin.3 curs_window.3 mvwin.3 curs_window.3 newwin.3 \
- curs_window.3 subwin.3 curs_window.3 syncok.3 \
- curs_window.3 wcursyncup.3 curs_window.3 wsyncdown.3 \
- curs_window.3 wsyncup.3
-MLINKS+=default_colors.3 assume_default_colors.3 \
- default_colors.3 use_default_colors.3
-
-NOLINT= true
-
-.include <bsd.lib.mk>
diff --git a/lib/ncurses/ncurses/ncurses_cfg.h b/lib/ncurses/ncurses/ncurses_cfg.h
deleted file mode 100644
index 3fc4c2b1f91c..000000000000
--- a/lib/ncurses/ncurses/ncurses_cfg.h
+++ /dev/null
@@ -1,155 +0,0 @@
-/* include/ncurses_cfg.h. Generated automatically by configure. */
-/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, 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, distribute with modifications, 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 ABOVE 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. *
- * *
- * Except as contained in this notice, the name(s) of the above copyright *
- * holders shall not be used in advertising or otherwise to promote the *
- * sale, use or other dealings in this Software without prior written *
- * authorization. *
- ****************************************************************************/
-
-/****************************************************************************
- * Author: Thomas E. Dickey <dickey@clark.net> 1997 *
- ****************************************************************************/
-/*
- * $Id: ncurses_cfg.hin,v 1.3 2000/09/02 17:13:32 tom Exp $
- *
- * This is a template-file used to generate the "ncurses_cfg.h" file.
- *
- * Rather than list every definition, the configuration script substitutes the
- * definitions that it finds using 'sed'. You need a patch (original date
- * 971222) to autoconf 2.12 or 2.13 to do this.
- *
- * See:
- * http://dickey.his.com/autoconf/
- * ftp://dickey.his.com/autoconf/
- */
-
-/* $FreeBSD$ */
-
-#ifndef NC_CONFIG_H
-#define NC_CONFIG_H
-
-#define BSD_TPUTS 1
-#define CC_HAS_INLINE_FUNCS 1
-#define CC_HAS_PROTOS 1
-#define GCC_NORETURN __dead2
-#define GCC_PRINTF 1
-#define GCC_SCANF 1
-#define GCC_UNUSED __unused
-#define HAVE_BIG_CORE 1
-#define HAVE_BSD_CGETENT 1
-#define HAVE_CURSES_VERSION 1
-#define HAVE_DIRENT_H 1
-#define HAVE_ERRNO 1
-#define HAVE_FCNTL_H 1
-#define HAVE_FORM_H 1
-#define HAVE_GETCWD 1
-#define HAVE_GETEGID 1
-#define HAVE_GETEUID 1
-#define HAVE_GETTIMEOFDAY 1
-#define HAVE_GETTTYNAM 1
-#define HAVE_HAS_KEY 1
-#define HAVE_ISASCII 1
-#define HAVE_ISSETUGID 1
-#define HAVE_LIBFORM 1
-#define HAVE_LIBMENU 1
-#define HAVE_LIBPANEL 1
-#define HAVE_LIMITS_H 1
-#define HAVE_LINK 1
-#define HAVE_LOCALE_H 1
-#define HAVE_LONG_FILE_NAMES 1
-#define HAVE_MEMCCPY 1
-#define HAVE_MENU_H 1
-#define HAVE_MKSTEMP 1
-#define HAVE_NANOSLEEP 1
-#define HAVE_NC_ALLOC_H 1
-#define HAVE_PANEL_H 1
-#define HAVE_POLL 1
-#define HAVE_POLL_H 1
-#define HAVE_REGEX_H_FUNCS 1
-#define HAVE_REMOVE 1
-#define HAVE_REMOVE 1
-#define HAVE_RESIZETERM 1
-#define HAVE_SELECT 1
-#define HAVE_SETBUF 1
-#define HAVE_SETBUFFER 1
-#define HAVE_SETVBUF 1
-#define HAVE_SIGACTION 1
-#define HAVE_SIGVEC 1
-#define HAVE_SIZECHANGE 1
-#define HAVE_STRDUP 1
-#define HAVE_STRSTR 1
-#define HAVE_SYMLINK 1
-#define HAVE_SYS_IOCTL_H 1
-#define HAVE_SYS_PARAM_H 1
-#define HAVE_SYS_POLL_H 1
-#define HAVE_SYS_SELECT_H 1
-#define HAVE_SYS_TIMES_H 1
-#define HAVE_SYS_TIME_H 1
-#define HAVE_SYS_TIME_SELECT 1
-#define HAVE_TCGETATTR 1
-#define HAVE_TCGETPGRP 1
-#define HAVE_TERMIOS_H 1
-#define HAVE_TIMES 1
-#define HAVE_TTYENT_H 1
-#define HAVE_UNISTD_H 1
-#define HAVE_UNISTD_H 1
-#define HAVE_UNLINK 1
-#define HAVE_USE_DEFAULT_COLORS 1
-#define HAVE_VSNPRINTF 1
-#define HAVE_VSSCANF 1
-#define HAVE_WORKING_POLL 1
-#define HAVE_WRESIZE 1
-#define MIXEDCASE_FILENAMES 1
-#define NCURSES_EXT_FUNCS 1
-#define NCURSES_NO_PADDING 1
-#define NCURSES_PATHSEP ':'
-#define NDEBUG 1
-#define RETSIGTYPE void
-#define STDC_HEADERS 1
-#define SYSTEM_NAME "FreeBSD"
-#define TERMINFO "/usr/share/misc/terminfo"
-#define TERMINFO_DIRS "/usr/share/misc/terminfo"
-#define TIME_WITH_SYS_TIME 1
-#define TYPEOF_CHTYPE long
-#define USE_ASSUMED_COLOR 1
-#define USE_COLORFGBG 1
-#define USE_DATABASE 1
-#define USE_GETCAP 1
-#define USE_HASHMAP 1
-#define USE_SIGWINCH 1
-
-#include <ncurses_def.h>
-
- /* The C compiler may not treat these properly but C++ has to */
-#ifdef __cplusplus
-#undef const
-#undef inline
-#else
-#if defined(lint) || defined(TRACE)
-#undef inline
-#define inline /* nothing */
-#endif
-#endif
-
-#endif /* NC_CONFIG_H */
diff --git a/lib/ncurses/ncurses/pathnames.h b/lib/ncurses/ncurses/pathnames.h
deleted file mode 100644
index 5cac36f3651f..000000000000
--- a/lib/ncurses/ncurses/pathnames.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pathnames.h 8.1 (Berkeley) 6/4/93
- * $FreeBSD$
- */
-
-#define _PATH_DEF ".termcap /usr/share/misc/termcap"
-#define _PATH_DEF_SEC "/usr/share/misc/termcap"
diff --git a/lib/ncurses/ncurses/termcap.c b/lib/ncurses/ncurses/termcap.c
deleted file mode 100644
index 24e71d302df5..000000000000
--- a/lib/ncurses/ncurses/termcap.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/* A portion of this file is from ncurses: */
-/***************************************************************************
-* COPYRIGHT NOTICE *
-****************************************************************************
-* ncurses is copyright (C) 1992-1995 *
-* Zeyd M. Ben-Halim *
-* zmbenhal@netcom.com *
-* Eric S. Raymond *
-* esr@snark.thyrsus.com *
-* *
-* Permission is hereby granted to reproduce and distribute ncurses *
-* by any means and for any fee, whether alone or as part of a *
-* larger distribution, in source or in binary form, PROVIDED *
-* this notice is included with any such distribution, and is not *
-* removed from any of its header files. Mention of ncurses in any *
-* applications linked with it is highly appreciated. *
-* *
-* ncurses comes AS IS with no warranty, implied or expressed. *
-* *
-***************************************************************************/
-
-#include <curses.priv.h>
-
-#include <string.h>
-#include <term.h>
-#include <tic.h>
-#include <term_entry.h>
-
-/* The rest is from BSD */
-/*
- * Copyright (c) 1980, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#ifndef lint
-static const char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93";
-#endif /* not lint */
-
-#include <stdio.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/param.h>
-#include "pathnames.h"
-
-#define PBUFSIZ MAXPATHLEN /* max length of filename path */
-#define PVECSIZ 32 /* max number of names in path */
-#define TBUFSIZ 1024 /* max length of _nc_tgetent buffer */
-
-char _nc_termcap[TBUFSIZ + 1]; /* Last getcap, provided to tgetent() emul */
-
-/*
- * termcap - routines for dealing with the terminal capability data base
- *
- * BUG: Should use a "last" pointer in tbuf, so that searching
- * for capabilities alphabetically would not be a n**2/2
- * process when large numbers of capabilities are given.
- * Note: If we add a last pointer now we will screw up the
- * tc capability. We really should compile termcap.
- *
- * Essentially all the work here is scanning and decoding escapes
- * in string capabilities. We don't use stdio because the editor
- * doesn't, and because living w/o it is not hard.
- */
-
-/*
- * Get an entry for terminal name in buffer _nc_termcap from the termcap
- * file.
- */
-int
-_nc_read_termcap_entry(const char *const name, TERMTYPE *const tp)
-{
- ENTRY *ep;
- char *p;
- char *cp;
- char *dummy;
- char **fname;
- char *home;
- int i;
- char pathbuf[PBUFSIZ]; /* holds raw path of filenames */
- char *pathvec[PVECSIZ]; /* to point to names in pathbuf */
- char **pvec; /* holds usable tail of path vector */
- char *termpath;
-
- _nc_termcap[0] = '\0'; /* in case */
- dummy = NULL;
- fname = pathvec;
- pvec = pathvec;
- p = pathbuf;
- cp = getenv("TERMCAP");
- /*
- * TERMCAP can have one of two things in it. It can be the
- * name of a file to use instead of /etc/termcap. In this
- * case it better start with a "/". Or it can be an entry to
- * use so we don't have to read the file. In this case it
- * has to already have the newlines crunched out. If TERMCAP
- * does not hold a file name then a path of names is searched
- * instead. The path is found in the TERMPATH variable, or
- * becomes "$HOME/.termcap /etc/termcap" if no TERMPATH exists.
- */
- if (!cp || *cp != '/') { /* no TERMCAP or it holds an entry */
- if ( (termpath = getenv("TERMPATH")) )
- strncpy(pathbuf, termpath, PBUFSIZ);
- else {
- if ( (home = getenv("HOME")) ) {/* set up default */
- strncpy(pathbuf, home, PBUFSIZ - 1); /* $HOME first */
- pathbuf[PBUFSIZ - 2] = '\0'; /* -2 because we add a slash */
- p += strlen(pathbuf); /* path, looking in */
- *p++ = '/';
- } /* if no $HOME look in current directory */
- strncpy(p, _PATH_DEF, PBUFSIZ - (p - pathbuf));
- }
- }
- else /* user-defined name in TERMCAP */
- strncpy(pathbuf, cp, PBUFSIZ); /* still can be tokenized */
-
- /* For safety */
- if (issetugid())
- strcpy(pathbuf, _PATH_DEF_SEC);
-
- pathbuf[PBUFSIZ - 1] = '\0';
-
- *fname++ = pathbuf; /* tokenize path into vector of names */
- while (*++p)
- if (*p == ' ' || *p == ':') {
- *p = '\0';
- while (*++p)
- if (*p != ' ' && *p != ':')
- break;
- if (*p == '\0')
- break;
- *fname++ = p;
- if (fname >= pathvec + PVECSIZ) {
- fname--;
- break;
- }
- }
- *fname = (char *) 0; /* mark end of vector */
- if (cp && *cp && *cp != '/')
- if (cgetset(cp) < 0)
- return(-2);
-
- i = cgetent(&dummy, pathvec, (char *)name);
-
- if (i == 0) {
- char *pd, *ps, *tok, *s, *tcs;
- size_t len;
-
- pd = _nc_termcap;
- ps = dummy;
- if ((tok = strchr(ps, ':')) == NULL) {
- len = strlen(ps);
- if (len >= TBUFSIZ)
- i = -1;
- else
- strcpy(pd, ps);
- goto done;
- }
- len = tok - ps + 1;
- if (pd + len + 1 - _nc_termcap >= TBUFSIZ) {
- i = -1;
- goto done;
- }
- memcpy(pd, ps, len);
- ps += len;
- pd += len;
- *pd = '\0';
- tcs = pd - 1;
- for (;;) {
- while ((tok = strsep(&ps, ":")) != NULL &&
- *(tok - 2) != '\\' &&
- (*tok == '\0' || *tok == '\\' || !isgraph(*tok)))
- ;
- if (tok == NULL)
- break;
- for (s = tcs; s != NULL && s[1] != '\0';
- s = strchr(s, ':')) {
- s++;
- if (s[0] == tok[0] && s[1] == tok[1])
- goto skip_it;
- }
- len = strlen(tok);
- if (pd + len + 1 - _nc_termcap >= TBUFSIZ) {
- i = -1;
- break;
- }
- memcpy(pd, tok, len);
- pd += len;
- *pd++ = ':';
- *pd = '\0';
- skip_it: ;
- }
- }
-done:
- if (dummy)
- free(dummy);
-
-
-/*
- * From here on is ncurses-specific glue code
- */
-
- if (i < 0)
- return(ERR);
-
- _nc_set_source("TERMCAP");
- _nc_read_entry_source((FILE *)NULL, _nc_termcap, FALSE, TRUE, NULLHOOK);
-
- if (_nc_head == (ENTRY *)NULL)
- return(ERR);
-
- /* resolve all use references */
- _nc_resolve_uses(TRUE);
-
- for_entry_list(ep)
- if (_nc_name_match(ep->tterm.term_names, name, "|:"))
- {
- /*
- * Make a local copy of the terminal capabilities. free
- * all entry storage except the string table for the
- * loaded type (which we disconnected from the list by
- * NULLing out ep->tterm.str_table above).
- */
- memcpy(tp, &ep->tterm, sizeof(TERMTYPE));
- ep->tterm.str_table = (char *)NULL;
- _nc_free_entries(_nc_head);
- _nc_head = _nc_tail = NULL; /* do not reuse! */
-
- return 1; /* OK */
- }
-
- _nc_free_entries(_nc_head);
- _nc_head = _nc_tail = NULL; /* do not reuse! */
- return(0); /* not found */
-}
diff --git a/lib/ncurses/panel/Makefile b/lib/ncurses/panel/Makefile
deleted file mode 100644
index 5c1f6010dda2..000000000000
--- a/lib/ncurses/panel/Makefile
+++ /dev/null
@@ -1,46 +0,0 @@
-# Makefile for libpanel
-# $FreeBSD$
-
-NCURSES=${.CURDIR}/../../contrib/ncurses
-
-.PATH: ${NCURSES}/panel ${NCURSES}/include
-.PATH: ${NCURSES}/man
-
-LIB= panel
-AWK?= awk
-
-SRCS= ncurses_def.h \
- p_above.c p_below.c p_bottom.c p_delete.c p_hidden.c \
- p_hide.c p_move.c p_new.c p_replace.c p_show.c p_top.c \
- p_update.c p_user.c p_win.c panel.c
-INCS= ${NCURSES}/panel/panel.h
-
-CLEANFILES+= ncurses_def.h
-CFLAGS+= -I.
-.if exists(${.OBJDIR}/../libncurses)
-CFLAGS+= -I${.OBJDIR}/../libncurses
-.endif
-CFLAGS+= -I${.CURDIR}/../libncurses
-CFLAGS+= -I${NCURSES}/panel -I${NCURSES}/include -I${NCURSES}/ncurses \
- -Wall -DNDEBUG -DHAVE_CONFIG_H
-
-ncurses_def.h: MKncurses_def.sh ncurses_defs
- AWK=${AWK} sh ${NCURSES}/include/MKncurses_def.sh \
- ${NCURSES}/include/ncurses_defs > ncurses_def.h
-
-# generate MAN
-CLEANFILES+= panel.3
-MAN= panel.3
-panel.3: panel.3x
- ln -s ${.ALLSRC} ${.TARGET}
-
-MLINKS+=panel.3 bottom_panel.3 panel.3 del_panel.3 panel.3 hide_panel.3 \
- panel.3 move_panel.3 panel.3 new_panel.3 panel.3 panel_above.3 \
- panel.3 panel_below.3 panel.3 panel_hidden.3 \
- panel.3 panel_userptr.3 panel.3 panel_window.3 \
- panel.3 replace_panel.3 panel.3 set_panel_userptr.3 \
- panel.3 show_panel.3 panel.3 top_panel.3 panel.3 update_panels.3
-
-.include <bsd.lib.mk>
-
-.SUFFIXES: .3x .3
diff --git a/release/amd64/boot_crunch.conf b/release/amd64/boot_crunch.conf
deleted file mode 100644
index 3d623bca5e4c..000000000000
--- a/release/amd64/boot_crunch.conf
+++ /dev/null
@@ -1,29 +0,0 @@
-# $FreeBSD$
-
-buildopts -DRELEASE_CRUNCH -Dlint
-
-srcdirs /usr/src/bin
-progs hostname pwd rm sh test
-ln sh -sh
-ln test [
-
-srcdirs /usr/src/gnu/usr.bin
-progs cpio
-
-srcdirs /usr/src/sbin
-progs dhclient fsck_ffs ifconfig
-progs mount_nfs newfs route rtsol
-progs slattach tunefs camcontrol
-
-srcdirs /usr/src/usr.bin
-progs find minigzip sed
-ln minigzip gzip
-ln minigzip gunzip
-ln minigzip zcat
-
-srcdirs /usr/src/usr.sbin /usr/src/usr.sbin/pccard
-progs arp ppp
-progs sysinstall usbd usbdevs
-
-libs -ll -ledit -lutil -lkvm -lmd -lcrypt -lftpio -lz -lnetgraph
-libs -ldialog -lncurses -ldisk -lcam -lsbuf -lufs
diff --git a/release/amd64/dokern.sh b/release/amd64/dokern.sh
deleted file mode 100755
index 42c5ad43a6dc..000000000000
--- a/release/amd64/dokern.sh
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/bin/sh
-#
-# $FreeBSD$
-#
-
-sed \
- -e '/AHC_REG_PRETTY_PRINT/d' \
- -e '/AHD_REG_PRETTY_PRINT/d' \
- -e '/COMPAT_FREEBSD4/d' \
- -e '/DDB/d' \
- -e '/DEBUG/d' \
- -e '/INVARIANTS/d' \
- -e '/INVARIANT_SUPPORT/d' \
- -e '/KTRACE/d' \
- -e '/NFSSERVER/d' \
- -e '/NFS_ROOT/d' \
- -e '/PROCFS/d' \
- -e '/PSEUDOFS/d' \
- -e '/SOFTUPDATES/d' \
- -e '/SYSV/d' \
- -e '/UFS_DIRHASH/d' \
- -e '/WITNESS/d' \
- -e '/_KPOSIX_PRIORITY_SCHEDULING/d' \
- -e '/ atapist /d' \
- -e '/ faith /d' \
- -e '/ gif /d' \
- -e '/ lpt /d' \
- -e '/ pass /d' \
- -e '/ pmtimer$/d' \
- -e '/ ppi /d' \
- -e '/ ppp /d' \
- -e '/ pty /d' \
- -e '/ random /d' \
- -e '/ ses /d' \
- -e '/ splash /d' \
- -e '/ ugen /d' \
- -e '/ uhid /d' \
- -e '/ ulpt /d' \
- -e '/ urio /d' \
- -e '/ uscanner /d' \
- -e 's/ident.*GENERIC/ident BOOTMFS/g'
-
-echo "options MUTEX_NOINLINE"
-
-echo "options NETGRAPH"
-echo "options NETGRAPH_ETHER"
-echo "options NETGRAPH_PPPOE"
-echo "options NETGRAPH_SOCKET"
-
-echo "options SCSI_NO_OP_STRINGS"
-echo "options SCSI_NO_SENSE_STRINGS"
diff --git a/release/amd64/fixit_crunch.conf b/release/amd64/fixit_crunch.conf
deleted file mode 100644
index 45ad00e4de86..000000000000
--- a/release/amd64/fixit_crunch.conf
+++ /dev/null
@@ -1,25 +0,0 @@
-# $FreeBSD$
-
-buildopts -DRELEASE_CRUNCH
-
-srcdirs /usr/src/bin
-progs cat chmod cp dd df echo expr kill
-progs ln ls mkdir mv rm rmdir sleep sync
-
-srcdirs /usr/src/sbin
-progs bsdlabel clri dmesg fdisk mknod
-progs mount mount_cd9660 mount_msdosfs
-progs reboot restore swapon umount
-ln bsdlabel disklabel
-ln restore rrestore
-
-srcdirs /usr/src/usr.bin
-progs ftp telnet vi
-ln vi view
-ln vi ex
-
-srcdirs /usr/src/usr.sbin
-progs chown chroot
-ln chown chgrp
-
-libs -ledit -lgeom -lkvm -lm -lncurses -lutil
diff --git a/release/amd64/mkisoimages.sh b/release/amd64/mkisoimages.sh
deleted file mode 100644
index d0918a0cb947..000000000000
--- a/release/amd64/mkisoimages.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/bin/sh
-#
-# Module: mkisoimages.sh
-# Author: Jordan K Hubbard
-# Date: 22 June 2001
-#
-# $FreeBSD$
-#
-# This script is used by release/Makefile to build the (optional) ISO images
-# for a FreeBSD release. It is considered architecture dependent since each
-# platform has a slightly unique way of making bootable CDs. This script
-# is also allowed to generate any number of images since that is more of
-# publishing decision than anything else.
-#
-# Usage:
-#
-# mkisoimages.sh [-b] image-label image-name base-bits-dir [extra-bits-dir]
-#
-# Where -b is passed if the ISO image should be made "bootable" by
-# whatever standards this architecture supports (may be unsupported),
-# image-label is the ISO image label, image-name is the filename of the
-# resulting ISO image, base-bits-dir contains the image contents and
-# extra-bits-dir, if provided, contains additional files to be merged
-# into base-bits-dir as part of making the image.
-
-if [ "x$1" = "x-b" ]; then
- # This is highly x86-centric and will be used directly below.
- bootable="-b boot/cdboot -no-emul-boot"
- shift
-else
- bootable=""
-fi
-
-if [ $# -lt 3 ]; then
- echo Usage: $0 '[-b] image-label image-name base-bits-dir [extra-bits-dir]'
- exit 1
-fi
-
-type mkisofs 2>&1 | grep " is " >/dev/null
-if [ $? -ne 0 ]; then
- echo The mkisofs port is not installed. Trying to get it now.
- if [ -f /usr/ports/sysutils/mkisofs/Makefile ]; then
- cd /usr/ports/sysutils/mkisofs && make install && make clean
- else
- if ! pkg_add -r mkisofs; then
- echo "Could not get it via pkg_add - please go install this"
- echo "from the ports collection and run this script again."
- exit 2
- fi
- fi
-fi
-
-LABEL=$1; shift
-NAME=$1; shift
-
-mkisofs $bootable -r -J -V $LABEL -o $NAME $*
diff --git a/release/doc/en_US.ISO8859-1/hardware/article.sgml b/release/doc/en_US.ISO8859-1/hardware/article.sgml
deleted file mode 100644
index ce6e3e7e8a20..000000000000
--- a/release/doc/en_US.ISO8859-1/hardware/article.sgml
+++ /dev/null
@@ -1,3676 +0,0 @@
-<!--
-
- The "Supported Devices" section of the release notes.
- Generally processor-independent, with conditional text
- inclusion handling any architecture-dependent text.
-
- Within each subsection describing a class of hardware
- (i.e. Ethernet interfaces), list broad groups of devices
- alphabetically as paragraphs sorted alphabetically (frequently
- these groups will be arranged by manufacturer, i.e. 3Com
- Ethernet interfaces). In cases where a group of devices
- consists of multiple models (such as the 3C501, 3C503, etc.),
- list each specific model or set of closely-related models as
- a separate item in an itemized list, sorted alphabetically.
- Where applicable, a "Miscellaneous" section may follow all
- other named sections.
-
- These guidelines are not hard-and-fast rules, and exceptions
- will occur. Following these guidelines (vague as they may be)
- is highly recommended to try to keep the formatting of
- this section consistent.
-
- We give manpage references using the &man entities where
- possible. If a driver has no manpage (and consequently no
- &man entity, we simply give the name of the driver).
- Please avoid doing &man entity conversions unless you
- know for sure that an entity and manpage exist; sweeps through
- this file to fix "missed" conversions are likely to break the
- build.
--->
-
-<sect1 id="support">
- <sect1info>
- <pubdate>$FreeBSD$</pubdate>
- </sect1info>
-
- <title>Supported Devices</title>
-
- <para>This section describes the devices currently known to be
- supported by with &os; on the &arch.print; platform. Other configurations
- may also work, but simply have not been tested yet. Feedback,
- updates, and corrections to this list are encouraged.</para>
-
- <para>Where possible, the drivers applicable to each device or class
- of devices is listed. If the driver in question has a manual page
- in the &os; base distribution (most should), it is referenced here.</para>
-
- <sect2>
- <title>Disk Controllers</title>
- <para arch="i386,alpha,sparc64,ia64,pc98">IDE/ATA controllers (&man.ata.4; driver)
- <itemizedlist>
- <listitem>
- <para>Acard ATP850 UDMA2, ATP860 UDMA4, ATP865 UDMA6</para>
- </listitem>
- <listitem>
- <para>AMD 756 ATA66, 766 ATA100, 768 ATA100</para>
- </listitem>
- <listitem>
- <para>Cenatek Rocket Drive</para>
- </listitem>
- <listitem>
- <para>CMD 646, 648 ATA66, and 649 ATA100</para>
- </listitem>
- <listitem>
- <para>Cypress 82C693</para>
- </listitem>
- <listitem>
- <para>Cyrix 5530 ATA33</para>
- </listitem>
- <listitem>
- <para>HighPoint HPT366 ATA66, HPT370 ATA100, HPT372 ATA133, HPT374 ATA133</para>
- </listitem>
- <listitem>
- <para>Intel PIIX, PIIX3, PIIX4</para>
- </listitem>
- <listitem>
- <para>Intel ICH ATA66, ICH2 ATA100, ICH3 ATA100, ICH4 ATA100</para>
- </listitem>
- <listitem>
- <para>nVidia nForce ATA100, nForce2 ATA133</para>
- </listitem>
- <listitem>
- <para>Promise ATA100 OEM chip (pdc20265)</para>
- </listitem>
- <listitem>
- <para>Promise ATA133 OEM chip (pdc20269)</para>
- </listitem>
- <listitem>
- <para>Promise Fasttrak-33, -66, -100, -100 TX2/TX4, -133 TX2/TX2000</para>
- </listitem>
- <listitem>
- <para>Promise SATA150 TX2/TX4 Serial ATA/150</para>
- </listitem>
- <listitem>
- <para>Promise Ultra-33, -66, -100, -133 TX2/TX2000/TX4000</para>
- </listitem>
- <listitem>
- <para>ServerWorks ROSB4 ATA33</para>
- </listitem>
- <listitem>
- <para>ServerWorks CSB5 and CSB6 ATA66/ATA100</para>
- </listitem>
- <listitem>
- <para>Sil 0680 UDMA6</para>
- </listitem>
- <listitem>
- <para>SiS 530, 540, 550, 620</para>
- </listitem>
- <listitem>
- <para>SiS 630, 630S, 633, 635, 640, 645, 645DX, 648, 650, 651, 652, 655, 658, 730, 733, 735, 740, 745, 746, 748, 750, 751, 752, 755</para>
- </listitem>
- <listitem>
- <para>SiS 5591 ATA100</para>
- </listitem>
- <listitem>
- <para>VIA 82C586 ATA33, 82C596 ATA66, 82C686a ATA66, 82C686b ATA100</para>
- </listitem>
- <listitem>
- <para>VIA 8233, 8235 ATA133</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="pc98">IDE/ATA controllers (wdc driver)
- <itemizedlist>
- <listitem>
- <para>On-board IDE controller</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98,alpha,sparc64">Adaptec SCSI Controllers
- <itemizedlist>
- <listitem arch="i386">
- <para>Adaptec 1535 ISA SCSI controllers</para>
- </listitem>
- <listitem arch="i386">
- <para>Adaptec 154x series ISA SCSI controllers
- (&man.aha.4; driver)</para>
- </listitem>
- <listitem arch="i386">
- <para>Adaptec 164x series MCA SCSI controllers (&man.aha.4;
- driver)</para>
- </listitem>
- <listitem arch="i386">
- <para>Adaptec 174x series EISA SCSI controller in standard
- and enhanced mode (&man.aha.4; and &man.ahb.4; driver)</para>
- </listitem>
- <listitem arch="i386">
- <para>Adaptec 274x series EISA SCSI controllers, including
- narrow and wide variants (&man.ahc.4;
- driver)</para>
- </listitem>
- <listitem arch="i386">
- <para>Adaptec 284x series VLB SCSI controllers, including
- narrow and wide variants (&man.ahc.4;
- driver)</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>Adaptec 19160/291x/2920/2930/2940/2950/29160/3940/3950/3960/39160/398x/494x
- series PCI SCSI controllers, including
- Narrow/Wide/Twin/Ultra/Ultra2 variants (&man.ahc.4;
- driver)</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>Adaptec AIC7770, AIC7850, AIC7860, AIC7870, AIC7880,
- and AIC789x on-board
- SCSI controllers (&man.ahc.4; driver)</para>
- </listitem>
- <listitem arch="i386">
- <para>Adaptec 1510 series ISA SCSI controllers (not for
- bootable devices)</para>
- </listitem>
- <listitem arch="i386">
- <para>Adaptec 152x series ISA SCSI controllers (&man.aha.4;
- driver)</para>
- </listitem>
- <listitem arch="i386">
- <para>Adaptec AIC-6260 and AIC-6360 based boards, which
- includes the AHA-152x and SoundBlaster SCSI cards
- (&man.aic.4; driver)</para>
- </listitem>
- <listitem arch="pc98">
- <para>NEC PC-9801-100 and Adaptec AHA-1030P,
- 1030B(&man.aic.4; driver)</para>
- </listitem>
- <listitem arch="pc98">
- <para>NEC PC-9821Xt13 and RvII26 internal, NEC
- PC-9821X-B02L/B09, NEC SV-98/2-B03, Adaptec AHA-2940J,
- AHA-2940AU and AHA-2940N (&man.ahc.4; driver)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,sparc64">Ultra-320 SCSI controllers based on the Adaptec
- AIC7901, AIC7901A, and AIC7902 Ultra320 controller chips
- (&man.ahd.4; driver)
- <itemizedlist>
- <listitem>
- <para>Adaptec 29320, 29320A, 29320B, 29320LP</para>
- </listitem>
- <listitem>
- <para>Adaptec 39320, 39320D</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Adaptec 21x0S/32x0S/34x0S SCSI RAID
- controllers (&man.asr.4; driver)</para>
-
- <para arch="i386">Adaptec 2000S/2005S Zero-Channel RAID controllers
- (&man.asr.4; driver)</para>
-
- <para arch="i386">Adaptec 2400A ATA-100 RAID controller
- (&man.asr.4; driver)</para>
-
- <para arch="i386">Adaptec FSA family RAID controllers (&man.aac.4; driver)
- <itemizedlist>
- <listitem>
- <para>Adaptec AAC-2622</para>
- </listitem>
- <listitem>
- <para>Adaptec AAC-364</para>
- </listitem>
- <listitem>
- <para>Adaptec SCSI RAID 2120S</para>
- </listitem>
- <listitem>
- <para>Adaptec SCSI RAID 2200S</para>
- </listitem>
- <listitem>
- <para>Adaptec SCSI RAID 5400S</para>
- </listitem>
- <listitem>
- <para>Dell PERC 2/QC</para>
- </listitem>
- <listitem>
- <para>Dell PERC 2/Si</para>
- </listitem>
- <listitem>
- <para>Dell PERC 3/Di</para>
- </listitem>
- <listitem>
- <para>Dell PERC 3/QC</para>
- </listitem>
- <listitem>
- <para>Dell PERC 3/Si</para>
- </listitem>
- <listitem>
- <para>HP NetRAID-4M</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="pc98">NEC PC-9801-55, 92 and their compatible C-Bus SCSI interfaces (ct driver)
- <itemizedlist>
- <listitem>
- <para>NEC PC-9801-55, 92 and their compatibles</para>
- <para>ICM IF-2660</para>
- <para>Midori-Denshi MDC-554NA</para>
- <para>Logitec LHA-N151</para>
- <note>
- <para><literal>flags 0x00000</literal> is necessary in
- kernel configuration for DMA transfer mode.</para>
- </note>
- </listitem>
- <listitem>
- <para>I-O DATA SC-98II</para>
- <note>
- <para><literal>flags 0x10000</literal> is necessary in
- kernel configuration for DMA transfer mode.</para>
- </note>
- </listitem>
- <listitem>
- <para>TEXA HA-55BS2 and later</para>
- <para>Midori-Denshi MDC-926Rs</para>
- <note>
- <para><literal>flags 0x20000</literal> is necessary in
- kernel configuration for Bus-master transfer mode.</para>
- </note>
- </listitem>
- <listitem>
- <para>ELECOM Bus-master SCSI interfaces</para>
- <note>
- <para><literal>flags 0x30000</literal> is necessary in
- kernel configuration for Bus-master transfer mode.</para>
- </note>
- </listitem>
- <listitem>
- <para>All SMIT transfer type SCSI interfaces</para>
- <note>
- <para><literal>flags 0x40000</literal> is necessary in
- kernel configuration for SMIT transfer mode.</para>
- </note>
- </listitem>
- <listitem>
- <para>Logitec LHA-20x series</para>
- <para>ICM IF-2766, IF-2766ET, IF-2767 and IF-2769</para>
- <note>
- <para><literal>flags 0x50000</literal> is necessary in
- kernel configuration for Bus-master transfer mode.</para>
- </note>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="pc98">NEC PC-9801-55, 92 and their compatible C-Bus SCSI interfaces (bs driver)
- <itemizedlist>
- <listitem>
- <para>NEC PC-9801-55, 92 and their compatibles</para>
- <para>ICM IF-2660</para>
- <para>Midori-Denshi MDC-554NA</para>
- <para>Logitec LHA-N151</para>
- <note>
- <para>"flags 0x00000" is necessary in kernel configuration
- for DMA transfer mode.</para>
- </note>
- </listitem>
- <listitem>
- <para>I-O DATA SC-98II</para>
- <note>
- <para>"flags 0x10000" is necessary in kernel configuration
- for DMA transfer mode.</para>
- </note>
- </listitem>
- <listitem>
- <para>TEXA HA-55BS2 and later</para>
- <para>Midori-Denshi MDC-926Rs</para>
- <note>
- <para>"flags 0x20000" is necessary in kernel configuration
- for Bus-master transfer mode.</para>
- </note>
- </listitem>
- <listitem>
- <para>ELECOM Bus-master SCSI interfaces</para>
- <note>
- <para>"flags 0x30000" is necessary in kernel configuration
- for Bus-master transfer mode.</para>
- </note>
- </listitem>
- <listitem>
- <para>All SMIT transfer type SCSI interfaces</para>
- <note>
- <para>"flags 0x40000" is necessary in kernel configuration
- for SMIT transfer mode.</para>
- </note>
- </listitem>
- <listitem>
- <para>Logitec LHA-20x series</para>
- <para>ICM IF-2766, IF-2766ET, IF-2767 and IF-2769</para>
- <note>
- <para>"flags 0x50000" is necessary in kernel configuration
- for Bus-master transfer mode.</para>
- </note>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98">AdvanSys SCSI controllers (all models, &man.adv.4;
- and &man.adw.4; drivers)
- <itemizedlist>
- <listitem arch="pc98">
- <para>MELCO IFC-USP, RATOC REX-PCI30 and @Nifty FNECHARD
- IFC-USUP-TX (&man.adv.4; driver)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">BusLogic MultiMaster <quote>W</quote> Series Host Adapters
- (&man.bt.4; driver):
- <itemizedlist>
- <listitem>
- <para>BT-948</para>
- </listitem>
- <listitem>
- <para>BT-958</para>
- </listitem>
- <listitem>
- <para>BT-958D</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">BusLogic MultiMaster <quote>C</quote> Series Host Adapters
- (&man.bt.4; driver):
- <itemizedlist>
- <listitem>
- <para>BT-946C</para>
- </listitem>
- <listitem>
- <para>BT-956C</para>
- </listitem>
- <listitem>
- <para>BT-956CD</para>
- </listitem>
- <listitem>
- <para>BT-445C</para>
- </listitem>
- <listitem>
- <para>BT-747C</para>
- </listitem>
- <listitem>
- <para>BT-757C</para>
- </listitem>
- <listitem>
- <para>BT-757CD</para>
- </listitem>
- <listitem>
- <para>BT-545C</para>
- </listitem>
- <listitem>
- <para>BT-540CF</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">BusLogic MultiMaster <quote>S</quote> Series Host Adapters
- (&man.bt.4; driver):
- <itemizedlist>
- <listitem>
- <para>BT-445S</para>
- </listitem>
- <listitem>
- <para>BT-747S</para>
- </listitem>
- <listitem>
- <para>BT-747D</para>
- </listitem>
- <listitem>
- <para>BT-757S</para>
- </listitem>
- <listitem>
- <para>BT-757D</para>
- </listitem>
- <listitem>
- <para>BT-545S</para>
- </listitem>
- <listitem>
- <para>BT-542D</para>
- </listitem>
- <listitem>
- <para>BT-742A</para>
- </listitem>
- <listitem>
- <para>BT-542B</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">BusLogic MultiMaster <quote>A</quote> Series Host Adapters
- (&man.bt.4; driver):
- <itemizedlist>
- <listitem>
- <para>BT-742A</para>
- </listitem>
- <listitem>
- <para>BT-542B</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <note arch="i386">
- <para>BusLogic/Mylex <quote>Flashpoint</quote> adapters are not yet
- supported.</para>
- </note>
- <note arch="i386">
- <para>AMI FastDisk controllers that are true BusLogic
- MultiMaster clones are also supported.</para>
- </note>
-
- <note arch="i386">
- <para>The Buslogic/Bustek BT-640 and Storage Dimensions SDC3211B
- and SDC3211F Microchannel (MCA) bus adapters are also
- supported.</para>
- </note>
-
- <para arch="i386">DPT SmartCACHE Plus, SmartCACHE III, SmartRAID III, SmartCACHE IV and
- SmartRAID IV SCSI/RAID controllers (&man.dpt.4; driver)</para>
-
- <para arch="i386">DPT SmartRAID V and VI SCSI RAID controllers
- (&man.asr.4; driver)
- <itemizedlist>
- <listitem>
- <para>PM1554</para>
- </listitem>
- <listitem>
- <para>PM2554</para>
- </listitem>
- <listitem>
- <para>PM2654</para>
- </listitem>
- <listitem>
- <para>PM2865</para>
- </listitem>
- <listitem>
- <para>PM2754</para>
- </listitem>
- <listitem>
- <para>PM3755</para>
- </listitem>
- <listitem>
- <para>PM3757</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,alpha">AMI MegaRAID Express and Enterprise family RAID controllers
- (&man.amr.4; driver)
- <itemizedlist>
- <listitem>
- <para>MegaRAID Series 418</para>
- </listitem>
- <listitem>
- <para>MegaRAID Enterprise 1200 (Series 428)</para>
- </listitem>
- <listitem>
- <para>MegaRAID Enterprise 1300 (Series 434)</para>
- </listitem>
- <listitem>
- <para>MegaRAID Enterprise 1400 (Series 438)</para>
- </listitem>
- <listitem>
- <para>MegaRAID Enterprise 1500 (Series 467)</para>
- </listitem>
- <listitem>
- <para>MegaRAID Enterprise 1600 (Series 471)</para>
- </listitem>
- <listitem>
- <para>MegaRAID Elite 1500 (Series 467)</para>
- </listitem>
- <listitem>
- <para>MegaRAID Elite 1600 (Series 493)</para>
- </listitem>
- <listitem>
- <para>MegaRAID Express 100 (Series 466WS)</para>
- </listitem>
- <listitem>
- <para>MegaRAID Express 200 (Series 466)</para>
- </listitem>
- <listitem>
- <para>MegaRAID Express 300 (Series 490)</para>
- </listitem>
- <listitem>
- <para>MegaRAID Express 500 (Series 475)</para>
- </listitem>
- <listitem>
- <para>Dell PERC</para>
- </listitem>
- <listitem>
- <para>Dell PERC 2/SC</para>
- </listitem>
- <listitem>
- <para>Dell PERC 2/DC</para>
- </listitem>
- <listitem>
- <para>Dell PERC 3/DCL</para>
- </listitem>
- <listitem>
- <para>HP NetRaid-1si</para>
- </listitem>
- <listitem>
- <para>HP NetRaid-3si</para>
- </listitem>
- <listitem>
- <para>HP Embedded NetRaid</para>
- </listitem>
- </itemizedlist>
-
- <note>
- <para arch="i386">Booting from these controllers is supported. EISA
- adapters are not supported.</para>
-
- <para arch="alpha">Booting from these controllers is not
- supported due to SRM limitations.</para>
- </note>
- </para>
-
- <para arch="i386,alpha">Mylex DAC960 and DAC1100 RAID controllers with 2.x, 3.x, 4.x
- and 5.x firmware (&man.mlx.4; driver)
- <itemizedlist>
- <listitem>
- <para>DAC960P</para>
- </listitem>
- <listitem>
- <para>DAC960PD</para>
- </listitem>
- <listitem>
- <para>DAC960PDU</para>
- </listitem>
- <listitem>
- <para>DAC960PL</para>
- </listitem>
- <listitem>
- <para>DAC960PJ</para>
- </listitem>
- <listitem>
- <para>DAC960PG</para>
- </listitem>
- <listitem>
- <para>AcceleRAID 150</para>
- </listitem>
- <listitem>
- <para>AcceleRAID 250</para>
- </listitem>
- <listitem>
- <para>eXtremeRAID 1100</para>
- </listitem>
- </itemizedlist>
-
- <note>
- <para arch="i386">Booting from these controllers is supported. EISA adapters
- are not supported.</para>
-
- <para arch="alpha">Booting from these controllers is not
- supported due to SRM limitations. This list includes
- controllers sold by Digital/Compaq in Alpha systems in the
- StorageWorks family, e.g. KZPSC or KZPAC.</para>
- </note>
- </para>
-
- <para arch="i386">Mylex PCI to SCSI RAID controllers with 6.x firmware
- (&man.mly.4; driver)
- <itemizedlist>
- <listitem>
- <para>AcceleRAID 160</para>
- </listitem>
- <listitem>
- <para>AcceleRAID 170</para>
- </listitem>
- <listitem>
- <para>AcceleRAID 352</para>
- </listitem>
- <listitem>
- <para>eXtremeRAID 2000</para>
- </listitem>
- <listitem>
- <para>eXtremeRAID 3000</para>
- </listitem>
- </itemizedlist>
-
- <note>
- <para>Compatible Mylex controllers not listed should work, but
- have not been verified.</para>
- </note>
- </para>
-
- <para arch="i386">3ware Escalade ATA RAID controllers (&man.twe.4; driver)
- <itemizedlist>
- <listitem arch="i386">
- <para>5000 series</para>
- </listitem>
-
- <listitem arch="i386">
- <para>6000 series</para>
- </listitem>
-
- <listitem arch="i386">
- <para>7000 series</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha,sparc64">LSI/SymBios (formerly NCR) 53C810, 53C810a, 53C815, 53C825,
- 53C825a, 53C860, 53C875, 53C875a, 53C876, 53C885, 53C895, 53C895a,
- 53C896, 53C1010-33, 53C1010-66, 53C1000, 53C1000R PCI
- SCSI controllers, either embedded on motherboard or on add-on
- boards (&man.ncr.4; and &man.sym.4; drivers)
- <itemizedlist>
- <listitem arch="i386,alpha,sparc64">
- <para>ASUS SC-200, SC-896</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>Data Technology DTC3130 (all variants)</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>DawiControl DC2976UW</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>Diamond FirePort (all)</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>NCR cards (all)</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>Symbios cards (all)</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>Tekram DC390W, 390U, 390F, 390U2B, 390U2W, 390U3D, and
- 390U3W</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>Tyan S1365</para>
- </listitem>
- <listitem arch="pc98">
- <para>I-O DATA SC-98/PCI and SC-PCI (&man.ncr.4; driver)</para>
- </listitem>
- <listitem arch="pc98">
- <para>I-O DATA SC-UPCI and Logitec LHA-521UA (&man.sym.4; driver)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">NCR 53C500 based PC-Card SCSI host adapters (ncv
- driver)
- <itemizedlist>
- <listitem>
- <para>IO DATA PCSC-DV</para>
- </listitem>
- <listitem>
- <para>KME KXLC002 (TAXAN ICD-400PN, etc.), KXLC004</para>
- </listitem>
- <listitem>
- <para>Macnica Miracle SCSI-II mPS110</para>
- </listitem>
- <listitem>
- <para>Media Intelligent MSC-110, MSC-200</para>
- </listitem>
- <listitem>
- <para>NEC PC-9801N-J03R</para>
- </listitem>
- <listitem>
- <para>New Media Corporation BASICS SCSI</para>
- </listitem>
- <listitem>
- <para>Qlogic Fast SCSI</para>
- </listitem>
- <listitem>
- <para>RATOC REX-9530, REX-5572 (as SCSI only)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">TMC 18C30, 18C50 based ISA/PC-Card SCSI host
- adapters (stg driver)
- <itemizedlist>
- <listitem>
- <para>Future Domain SCSI2GO</para>
- </listitem>
- <listitem>
- <para>IBM SCSI PCMCIA Card</para>
- </listitem>
- <listitem>
- <para>ICM PSC-2401 SCSI</para>
- </listitem>
- <listitem>
- <para>MELCO IFC-SC</para>
- </listitem>
- <listitem>
- <para>RATOC REX-5536, REX-5536AM, REX-5536M,
- REX-9836A</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha,ia64,sparc64">Qlogic controllers and variants (&man.isp.4; driver)
- <itemizedlist>
- <listitem arch="i386,alpha,ia64,sparc64">
- <para>Qlogic 1020, 1040 SCSI and Ultra SCSI host
- adapters</para>
- </listitem>
- <listitem arch="i386,alpha,ia64,sparc64">
- <para>Qlogic 1240 dual Ultra SCSI controllers</para>
- </listitem>
- <listitem arch="i386,alpha,ia64,sparc64">
- <para>Qlogic 1080 Ultra2 LVD and 1280 Dual Ultra2 LVD
- controllers</para>
- </listitem>
- <listitem arch="i386,alpha,ia64,sparc64">
- <para>Qlogic 12160 Ultra3 LVD controllers</para>
- </listitem>
- <listitem arch="i386,alpha,ia64,sparc64">
- <para>Qlogic 2100 and Qlogic 2200 Fibre Channel SCSI
- controllers</para>
- </listitem>
- <listitem arch="i386,alpha,ia64,sparc64">
- <para>Qlogic 2300 and Qlogic 2312 2-Gigabit Fibre Channel SCSI
- controllers</para>
- </listitem>
- <listitem arch="i386,alpha,ia64,sparc64">
- <para>Performance Technology SBS440 ISP1000 variants</para>
- </listitem>
- <listitem arch="i386,alpha,ia64,sparc64">
- <para>Performance Technology SBS450 ISP1040 variants</para>
- </listitem>
- <listitem arch="i386,alpha,ia64,sparc64">
- <para>Performance Technology SBS470 ISP2100 variants</para>
- </listitem>
- <listitem arch="i386,alpha,ia64,sparc64">
- <para>Antares Microsystems P-0033 ISP2100 variants</para>
- </listitem>
- <listitem arch="pc98">
- <para>Qlogic SCSI interface</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">DTC 3290 EISA SCSI controller in 1542 emulation mode.</para>
-
- <para arch="i386,pc98">Tekram DC390 and DC390T controllers, maybe other
- cards based on the AMD 53c974 as well (&man.amd.4; driver)
- <itemizedlist arch="pc98">
- <listitem arch="pc98">
- <para>MELCO IFC-DP</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">Workbit Ninja SCSI-3 based PC-Card SCSI host
- adapters (nsp driver)
- <itemizedlist>
- <listitem>
- <para>Alpha-Data AD-PCS201</para>
- </listitem>
- <listitem>
- <para>IO DATA CBSC16</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Parallel to SCSI interfaces (&man.vpo.4; driver)
- <itemizedlist>
- <listitem>
- <para>AIC 7110 SCSI controller (built-in to Iomega ZIP drive)</para>
- </listitem>
- <listitem>
- <para>Iomega Jaz Traveller interface</para>
- </listitem>
- <listitem>
- <para>Iomega MatchMaker SCSI interface (built-in to Iomega
- ZIP+ drive)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Compaq Intelligent Drive Array Controllers
- (&man.ida.4; driver)
-
- <itemizedlist>
- <listitem>
- <para>Compaq SMART Array 221</para>
- </listitem>
-
- <listitem>
- <para>Compaq Integrated SMART Array Controller</para>
- </listitem>
-
- <listitem>
- <para>Compaq SMART Array 4200, 4250ES Controllers</para>
- </listitem>
-
- <listitem>
- <para>Compaq SMART Array 3200, 3100ES Controller</para>
- </listitem>
-
- <listitem>
- <para>Compaq SMART-2/DH, SMART-2/SL, SMART-2/P, SMART-2E, and
- SMART Controllers</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">SCSI adapters utilizing the Command Interface
- for SCSI-3 Support (&man.ciss.4; driver)
- <itemizedlist>
- <listitem>
- <para>Compaq Smart Array 5* series (5300, 5i, 532)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Intel Integrated RAID Controllers (&man.iir.4; driver)
- <itemizedlist>
- <listitem>
- <para>Intel RAID Controller SRCMR</para>
- </listitem>
- <listitem>
- <para>ICP Vortex SCSI RAID controllers (all Wide/Ultra160,
- 32-bit/64-bit PCI models)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Promise SuperTrak ATA RAID controllers (&man.pst.4;
- driver)
- <itemizedlist>
- <listitem>
- <para>Promise SuperTrak SX6000 ATA RAID controller</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">IBM / Adaptec ServeRAID series (ips driver)</para>
-
- <para arch="i386,alpha,pc98,sparc64,ia64">LSI Logic Fusion/MP
- architecture Fiber Channel controllers (mpt driver)
- <itemizedlist>
- <listitem arch="i386,alpha,pc98,sparc64">
- <para>LSI FC909, FC929</para>
- </listitem>
- <listitem>
- <para>LSI 53c1020, 53c1030</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">PCI SCSI host adapters using the Tekram
- TRM-S1040 SCSI chipset (&man.trm.4; driver)
- <itemizedlist>
- <listitem>
- <para>Tekram DC395U/UW/U2W/F</para>
- </listitem>
- <listitem>
- <para>Tekram DC315U</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para>With all supported SCSI controllers, full support is
- provided for SCSI-I, SCSI-II, and SCSI-III peripherals, including
- hard disks, optical disks, tape drives (including DAT, 8mm
- Exabyte, Mammoth, and DLT), medium changers, processor target
- devices and CD-ROM drives. WORM devices that support CD-ROM
- commands are supported for read-only access by the CD-ROM drivers
- (such as &man.cd.4;). WORM/CD-R/CD-RW writing support is provided
- by &man.cdrecord.1;, which is a part of the
- <filename role="package">sysutils/cdrtools</filename> port in the Ports Collection.</para>
-
- <para>The following CD-ROM type systems are supported at this
- time:
- <itemizedlist>
- <listitem>
- <para>SCSI interface (also includes ProAudio Spectrum and
- SoundBlaster SCSI) (&man.cd.4;)</para>
- </listitem>
- <listitem arch="i386">
- <para>Sony proprietary interface (all models) (&man.scd.4;)</para>
- </listitem>
- <listitem>
- <para>ATAPI IDE interface (&man.acd.4;)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">The following drivers were supported under the old SCSI
- subsystem, but are not yet supported under the &man.cam.4; SCSI
- subsystem:
- <itemizedlist>
- <listitem arch="i386">
- <para>NCR5380/NCR53400 (<quote>ProAudio Spectrum</quote>)
- SCSI controller</para>
- </listitem>
- <listitem arch="i386">
- <para>UltraStor 14F, 24F and 34F SCSI controllers.
- <note>
- <para>There is work-in-progress to port the
- UltraStor driver to the new CAM SCSI framework, but no
- estimates on when or if it will be completed.</para>
- </note>
- </para>
- </listitem>
- <listitem arch="i386">
- <para>Seagate ST01/02 SCSI controllers</para>
- </listitem>
- <listitem arch="i386">
- <para>Future Domain 8xx/950 series SCSI controllers</para>
- </listitem>
- <listitem arch="i386">
- <para>WD7000 SCSI controller</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">The following device is unmaintained:
- <itemizedlist>
- <listitem>
- <para>Mitsumi proprietary CD-ROM interface (all
- models) (&man.mcd.4;)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- </sect2>
- <sect2 id="ethernet">
- <title>Ethernet Interfaces</title>
-
- <para arch="i386,pc98,alpha">Adaptec Duralink PCI Fast Ethernet adapters based on the Adaptec
- AIC-6915 Fast Ethernet controller chip (&man.sf.4; driver)
- <itemizedlist>
- <listitem>
- <para>ANA-62011 64-bit single port 10/100baseTX adapter</para>
- </listitem>
- <listitem>
- <para>ANA-62022 64-bit dual port 10/100baseTX adapter</para>
- </listitem>
- <listitem>
- <para>ANA-62044 64-bit quad port 10/100baseTX adapter</para>
- </listitem>
- <listitem>
- <para>ANA-69011 32-bit single port 10/100baseTX
- adapter</para>
- </listitem>
- <listitem>
- <para>ANA-62020 64-bit single port 100baseFX adapter</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">Allied-Telesis AT1700 and RE2000 cards
- (&man.fe.4; driver)
- <itemizedlist>
- <listitem>
- <para>CONTEC C-NET(PC)C PCMCIA Ethernet</para>
- </listitem>
- <listitem>
- <para>Fujitsu MBH10303, MBH10302 Ethernet PCMCIA</para>
- </listitem>
- <listitem>
- <para>Fujitsu Towa LA501 Ethernet</para>
- </listitem>
- <listitem>
- <para>Fujitsu FMV-J182, FMV-J182A</para>
- </listitem>
- <listitem>
- <para>RATOC REX-5588, REX-9822, REX-4886, and REX-R280</para>
- </listitem>
- <listitem>
- <para>Eiger Labs EPX-10BT</para>
- </listitem>
- <listitem>
- <para>HITACHI HT-4840-11</para>
- </listitem>
- <listitem>
- <para>NextCom J Link NC5310</para>
- </listitem>
- <listitem>
- <para>TDK LAK-CD021, LAK-CD021A, LAK-CD021BX</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">Alteon Networks PCI Gigabit Ethernet NICs based on the Tigon
- 1 and Tigon 2 chipsets (&man.ti.4; driver)
- <itemizedlist>
- <listitem>
- <para>3Com 3c985-SX (Tigon 1 and 2)</para>
- </listitem>
- <listitem>
- <para>Alteon AceNIC (Tigon 1 and 2)</para>
- </listitem>
- <listitem>
- <para>Alteon AceNIC 1000baseT (Tigon 2)</para>
- </listitem>
- <listitem>
- <para>Asante PCI 1000BASE-SX Gigabit Ethernet Adapter</para>
- </listitem>
- <listitem>
- <para>Asante GigaNIX1000T Gigabit Ethernet Adapter</para>
- </listitem>
- <listitem>
- <para>DEC/Compaq EtherWORKS 1000</para>
- </listitem>
- <listitem>
- <para>Farallon PN9000SX</para>
- </listitem>
- <listitem>
- <para>NEC Gigabit Ethernet</para>
- </listitem>
- <listitem>
- <para>Netgear GA620 (Tigon 2)</para>
- </listitem>
- <listitem>
- <para>Netgear GA620T (Tigon 2, 1000baseT)</para>
- </listitem>
- <listitem>
- <para>Silicon Graphics Gigabit Ethernet</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">AMD PCnet NICs (&man.lnc.4; and &man.pcn.4; drivers)
- <itemizedlist>
- <listitem arch="i386,alpha">
- <para>AMD PCnet/PCI (79c970 & 53c974 or 79c974)</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>AMD PCnet/FAST</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>Isolan AT 4141-0 (16 bit)</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>Isolink 4110 (8 bit)</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>PCnet/FAST+</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>PCnet/FAST III</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>PCnet/PRO</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>PCnet/Home</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>HomePNA</para>
- </listitem>
- <listitem arch="pc98">
- <para>Contec C-NET(98)S</para>
- </listitem>
- <listitem arch="pc98">
- <para>PCI NIC using AMD AM79C97x (PCnet-PCI/Fast)</para>
- </listitem>
- <listitem arch="pc98">
- <para>NEC SV-98/2-B05, B06 (PCI)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Allied-Telesis LA-PCI (PCI)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">SMC 83c17x (EPIC)-based Ethernet NICs (&man.tx.4; driver)
- <itemizedlist>
- <listitem>
- <para>SMC EtherPower II 9432 series</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">National Semiconductor DS8390-based Ethernet NICs, including
- Novell NE2000 and clones
- (&man.ed.4; driver)
- <note arch="pc98">
- <para>In kernel configuration, you need to set flag for non-PCI
- device.</para>
- </note>
- <itemizedlist>
- <listitem arch="i386,alpha">
- <para>3C503 Etherlink II (&man.ed.4; driver)</para>
- </listitem>
- <listitem arch="i386">
- <para>DEC Etherworks DE305</para>
- </listitem>
- <listitem arch="i386">
- <para>Hewlett-Packard PC Lan+ 27247B and 27252A</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>NetVin 5000</para>
- </listitem>
- <listitem>
- <para>Novell NE1000, NE2000, and NE2100</para>
- </listitem>
- <listitem>
- <para>RealTek 8029</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>SMC Elite 16 WD8013 Ethernet interface</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>SMC Elite Ultra</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>SMC WD8003E, WD8003EBT, WD8003W, WD8013W, WD8003S,
- WD8003SBT and WD8013EBT and clones</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>Surecom NE-34</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>VIA VT86C926</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>Winbond W89C940</para>
- </listitem>
- <listitem arch="pc98">
- <para>I-O DATA ET2/T-PCI</para>
- </listitem>
- <listitem arch="pc98">
- <para>MELCO LGY-PCI-TR</para>
- </listitem>
- <listitem arch="pc98">
- <para>PLANEX ENW-8300-T</para>
- </listitem>
- <listitem arch="pc98">
- <para>Allied Telesis LA-98 (flags 0x000000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Corega Ether98-T (flags 0x000000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>SMC EtherEZ98 (flags 0x000000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>ELECOM LD-BDN, LD-NW801G (flags 0x200000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>PLANEX EN-2298-C (flags 0x200000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>MELCO EGY-98 (flags 0x300000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Contec C-NET(98)E-A, C-NET(98)L-A, C-NET(98)P (flags
- 0x300000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>MELCO LGY-98, LGH-98, IND-SP, IND-SS, LGY-98-N
- (110pin) (flags 0x400000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>MACNICA NE2098 (flags 0x400000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>ICM IF-2766ET, IF-2771ET, AD-ET2-T, DT-ET-25, DT-ET-T5,
- NB-ET-T (110pin) (flags 0x500000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>D-Link DE-298, DE-298P (flags 0x500000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>ELECOM LD-98P (flags 0x500000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>PLANEX EN-2298-T, EN-2298P-T (flags 0x500000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Allied Telesis SIC-98, SIU-98, SIC-98NOTE (110pin) (flags
- 0x600000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Allied Telesis SIU-98-D (flags 0x610000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>NEC PC-9801-107, 108 (flags 0x800000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>I-O DATA LA/T-98, LA/T-98SB, LA2/T-98, ET/T-98 (flags
- 0x900000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>MACNICA ME98 (flags 0x900000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Kansai KLA-98C/T (flags 0x900000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>NEC PC-9801-77, 78 (flags 0x910000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Contec C-NET(98), RT-1007(98), C-NET(9N) (110pin) (flags
- 0xa00000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Contec C-NET(98)E, C-NET(98)L, C-NET(9N)L (110pin) (flags
- 0xb00000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Logitec LAN-98T (flags 0xb00000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Networld 98X3 (flags 0xd00000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Accton EN1644(old model), EN1646(old model), EN2203(old
- model) (110pin) (flags 0xd00000)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Networld EC-98X, EP-98X (flags 0xd10000)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">NE2000 compatible PC-Card (PCMCIA) Ethernet and
- FastEthernet cards (&man.ed.4; driver)
- <itemizedlist>
- <listitem>
- <para>AR-P500 Ethernet</para>
- </listitem>
- <listitem>
- <para>Accton EN2212/EN2216/UE2216</para>
- </listitem>
- <listitem>
- <para>Allied Telesis CentreCOM LA100-PCM_V2</para>
- </listitem>
- <listitem>
- <para>AmbiCom 10BaseT card</para>
- </listitem>
- <listitem>
- <para>BayNetworks NETGEAR FA410TXC Fast Ethernet</para>
- </listitem>
- <listitem>
- <para>CNet BC40 adapter</para>
- </listitem>
- <listitem>
- <para>COREGA Ether PCC-T/EtherII PCC-T/FEther PCC-TXF/PCC-TXD</para>
- </listitem>
- <listitem>
- <para>Compex Net-A adapter</para>
- </listitem>
- <listitem>
- <para>CyQ've ELA-010</para>
- </listitem>
- <listitem>
- <para>D-Link DE-650/660</para>
- </listitem>
- <listitem>
- <para>Danpex EN-6200P2</para>
- </listitem>
- <listitem>
- <para>Elecom Laneed LD-CDL/TX, LD-CDF, LD-CDS, LD-10/100CD, LD-CDWA (DP83902A), MACNICA Ethernet ME1 for JEIDA</para>
- </listitem>
- <listitem>
- <para>IO DATA PCLATE</para>
- </listitem>
- <listitem>
- <para>IBM Creditcard Ethernet I/II</para>
- </listitem>
- <listitem>
- <para>IC-CARD Ethernet/IC-CARD+ Ethernet</para>
- </listitem>
- <listitem>
- <para>Kingston KNE-PC2, KNE-PCM/x Ethernet</para>
- </listitem>
- <listitem>
- <para>Linksys EC2T/PCMPC100/PCM100, PCMLM56, EtherFast 10/100 PC Card, Combo PCMCIA Ethernet Card
- (PCMPC100 V2)</para>
- </listitem>
- <listitem>
- <para>MELCO LPC-T/LPC2-T/LPC2-CLT/LPC2-TX/LPC3-TX/LPC3-CLX</para>
- </listitem>
- <listitem>
- <para>NDC Ethernet Instant-Link</para>
- </listitem>
- <listitem>
- <para>National Semiconductor InfoMover NE4100</para>
- </listitem>
- <listitem>
- <para>NetGear FA-410TX</para>
- </listitem>
- <listitem>
- <para>Network Everywhere Ethernet 10BaseT PC Card</para>
- </listitem>
- <listitem>
- <para>Planex FNW-3600-T</para>
- </listitem>
- <listitem>
- <para>Socket LP-E</para>
- </listitem>
- <listitem>
- <para>Surecom EtherPerfect EP-427</para>
- </listitem>
- <listitem>
- <para>TDK LAK-CD031,Grey Cell GCS2000 Ethernet Card</para>
- </listitem>
- <listitem>
- <para>Telecom Device SuperSocket RE450T</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">RealTek RTL 8002 Pocket Ethernet (&man.rdp.4;
- driver)</para>
-
- <para arch="i386,pc98,alpha,sparc64">RealTek 8129/8139 Fast Ethernet NICs (&man.rl.4; driver)
- <itemizedlist>
- <listitem>
- <para>Accton <quote>Cheetah</quote> EN1207D (MPX 5030/5038;
- RealTek 8139 clone)</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>Allied Telesyn AT2550</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>Allied Telesyn AT2500TX</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>D-Link DFE-530TX+, DFE-538TX</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>Farallon NetLINE 10/100 PCI</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>Genius GF100TXR (RTL8139)</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>KTX-9130TX 10/100 Fast Ethernet</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>NDC Communications NE100TX-E</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>Netronix Inc. EA-1210 NetEther 10/100</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>OvisLink LEF-8129TX</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>OvisLink LEF-8139TX</para>
- </listitem>
- <listitem arch="i386,alpha,sparc64">
- <para>SMC EZ Card 10/100 PCI 1211-TX</para>
- </listitem>
- <listitem arch="pc98">
- <para>SOHO(PRAGMATIC) UE-1211C (PCI)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,alpha">Lite-On 82c168/82c169 PNIC Fast Ethernet NICs (&man.dc.4; driver)
- <itemizedlist>
- <listitem>
- <para>Kingston KNE110TX</para>
- </listitem>
- <listitem>
- <para>LinkSys EtherFast LNE100TX</para>
- </listitem>
- <listitem>
- <para>Matrox FastNIC 10/100</para>
- </listitem>
- <listitem>
- <para>NetGear FA310-TX Rev. D1</para>
- </listitem>
- </itemizedlist
- </para>
-
- <para arch="i386,pc98,alpha">Macronix 98713, 98713A, 98715, 98715A and 98725 Fast
- Ethernet NICs (&man.dc.4; driver)
- <itemizedlist>
- <listitem>
- <para>Accton EN1217 (98715A)</para>
- </listitem>
- <listitem>
- <para>Adico AE310TX (98715A)</para>
- </listitem>
- <listitem>
- <para>Compex RL100-TX (98713 or 98713A)</para>
- </listitem>
- <listitem>
- <para>CNet Pro120A (98713 or 98713A)</para>
- </listitem>
- <listitem>
- <para>CNet Pro120B (98715)</para>
- </listitem>
- <listitem>
- <para>NDC Communications SFA100A (98713A)</para>
- </listitem>
- <listitem>
- <para>SVEC PN102TX (98713)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">Macronix/Lite-On PNIC II LC82C115 Fast Ethernet NICs
- (&man.dc.4; driver)
- <itemizedlist>
- <listitem>
- <para>LinkSys EtherFast LNE100TX Version 2</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">Winbond W89C840F Fast Ethernet NICs (&man.wb.4; driver)
- <itemizedlist>
- <listitem>
- <para>Trendware TE100-PCIE</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">VIA Technologies VT3043 <quote>Rhine I</quote>, VT86C100A
- <quote>Rhine II</quote>, and VT86C105/VT86C105M <quote>Rhine III</quote> Fast Ethernet NICs (&man.vr.4; driver)
- <itemizedlist>
- <listitem arch="i386,alpha">
- <para>AOpen/Acer ALN-320</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>D-Link DFE-530TX</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>Hawking Technologies PN102TX</para>
- </listitem>
- <listitem arch="pc98">
- <para>MELCO LGY-PCI-TXR (PCI)</para>
- </listitem>
- <listitem arch="pc98">
- <para>CO-100MV (PCI)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Corega FastEtherII PCI-TX (PCI)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">Silicon Integrated Systems SiS 900 and SiS 7016 PCI Fast
- Ethernet NICs (&man.sis.4; driver)
- <itemizedlist>
- <listitem arch="i386,alpha">
- <para>SiS 630, 635 and 735 motherboard chipsets</para>
- </listitem>
- <listitem arch="pc98">
- <para>@Nifty FNECHARD IFC-USUP-TX (PCI)</para>
- </listitem>
- <listitem arch="pc98">
- <para>MELCO LGY-PCI-TXC (PCI)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">National Semiconductor DP83815 Fast Ethernet NICs
- (&man.sis.4; driver)
- <itemizedlist>
- <listitem>
- <para>NetGear FA311-TX</para>
- </listitem>
- <listitem>
- <para>NetGear FA312-TX</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">National Semiconductor DP83820 and DP83821 Gigabit Ethernet
- NICs (&man.nge.4; driver)
- <itemizedlist>
- <listitem>
- <para>Addtron AEG320T</para>
- </listitem>
- <listitem>
- <para>Ark PC SOHO-GA2500T (32-bit PCI) and SOHO-GA2000T
- (64-bit PCI)</para>
- </listitem>
- <listitem>
- <para>Asante FriendlyNet GigaNIC 1000TA and 1000TPC</para>
- </listitem>
- <listitem>
- <para>D-Link DGE-500T</para>
- </listitem>
- <listitem>
- <para>LinkSys EG1032 (32-bit PCI) and EG1064 (64-bit PCI)</para>
- </listitem>
- <listitem>
- <para>Netgear GA621 and GA622T</para>
- </listitem>
- <listitem>
- <para>SMC EZ Card 1000 (SMC9462TX)</para>
- </listitem>
- <listitem>
- <para>Surecom Technology EP-320G-TX</para>
- </listitem>
- <listitem>
- <para>Trendware TEG-PCITX (32-bit PCI) and TEG-PCITX2
- (64-bit PCI)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">Sundance Technologies ST201 PCI Fast Ethernet NICs
- (&man.ste.4; driver)
- <itemizedlist>
- <listitem>
- <para>D-Link DFE-550TX</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">SysKonnect SK-984x PCI Gigabit Ethernet cards (&man.sk.4; drivers)
- <itemizedlist>
- <listitem>
- <para>SK-9821 1000baseT copper, single port</para>
- </listitem>
- <listitem>
- <para>SK-9822 1000baseT copper, dual port</para>
- </listitem>
- <listitem>
- <para>SK-9841 1000baseLX single mode fiber, single port</para>
- </listitem>
- <listitem>
- <para>SK-9842 1000baseLX single mode fiber, dual port</para>
- </listitem>
- <listitem>
- <para>SK-9843 1000baseSX multimode fiber, single port</para>
- </listitem>
- <listitem>
- <para>SK-9844 1000baseSX multimode fiber, dual port</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">Texas Instruments ThunderLAN PCI NICs (&man.tl.4; driver)
- <itemizedlist>
- <listitem>
- <para>Compaq Netelligent 10, 10/100, 10/100
- Dual-Port</para>
- </listitem>
- <listitem arch="i386">
- <para>Compaq Netelligent 10/100 Proliant</para>
- </listitem>
- <listitem>
- <para>Compaq Netelligent 10/100 TX Embedded UTP, 10 T PCI
- UTP/Coax, 10/100 TX UTP</para>
- </listitem>
- <listitem>
- <para>Compaq NetFlex 3P, 3P Integrated, 3P w/BNC</para>
- </listitem>
- <listitem>
- <para>Olicom OC-2135/2138, OC-2325, OC-2326 10/100 TX UTP</para>
- </listitem>
- <listitem>
- <para>Racore 8165 10/100baseTX</para>
- </listitem>
- <listitem>
- <para>Racore 8148 10baseT/100baseTX/100baseFX
- multi-personality</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">ADMtek Inc. AL981-based PCI Fast Ethernet NICs (&man.dc.4;
- driver)</para>
-
- <para arch="i386,pc98,alpha">ADMtek Inc. AN985-based PCI Fast Ethernet NICs (&man.dc.4;
- driver)
- <itemizedlist>
- <listitem>
- <para>LinkSys EtherFast LNE100TX v4.0/4.1</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">ADMtek Inc. AN986-based USB Ethernet NICs (&man.aue.4; driver)
- <itemizedlist>
- <listitem>
- <para>Abocom UFE1000, DSB650TX_NA</para>
- </listitem>
- <listitem>
- <para>Accton USB320-EC, SpeedStream</para>
- </listitem>
- <listitem>
- <para>ADMtek AN986, AN8511</para>
- </listitem>
- <listitem>
- <para>Billionton USB100, USB100LP, USB100EL, USBE100</para>
- </listitem>
- <listitem>
- <para>Corega Ether FEther USB-T, FEther USB-TX, FEther USB-TXS</para>
- </listitem>
- <listitem>
- <para>D-Link DSB-650, DSB-650TX, DSB-650TX-PNA</para>
- </listitem>
- <listitem>
- <para>Elecom LD-USBL/TX</para>
- </listitem>
- <listitem>
- <para>Elsa Microlink USB2Ethernet</para>
- </listitem>
- <listitem>
- <para>I-O Data USB ETTX</para>
- </listitem>
- <listitem>
- <para>Kingston KNU101TX</para>
- </listitem>
- <listitem>
- <para>LinkSys USB10T, USB10TA, USB10TX, USB100TX, USB100H1</para>
- </listitem>
- <listitem>
- <para>MELCO LUA-TX, LUA2-TX</para>
- </listitem>
- <listitem>
- <para>Planex UE-200TX</para>
- </listitem>
- <listitem>
- <para>Siemens Speedstream</para>
- </listitem>
- <listitem>
- <para>SmartBridges smartNIC</para>
- </listitem>
- <listitem>
- <para>SMC 2202USB</para>
- </listitem>
- <listitem>
- <para>SOHOware NUB100</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">CATC USB-EL1210A-based USB Ethernet NICs (&man.cue.4; driver)
- <itemizedlist>
- <listitem>
- <para>Belkin F5U011, F5U111</para>
- </listitem>
- <listitem>
- <para>CATC Netmate, Netmate II</para>
- </listitem>
- <listitem>
- <para>SmartBridges SmartLink</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">Kawasaki LSI KU5KUSB101B-based USB Ethernet NICs
- (&man.kue.4; driver)
- <itemizedlist>
- <listitem>
- <para>3Com 3c19250</para>
- </listitem>
- <listitem>
- <para>AOX USB101</para>
- </listitem>
- <listitem>
- <para>Abocom URE 450</para>
- </listitem>
- <listitem>
- <para>ADS Technologies USB-10BT</para>
- </listitem>
- <listitem>
- <para>ATen UC10T</para>
- </listitem>
- <listitem>
- <para>Corega USB-T</para>
- </listitem>
- <listitem>
- <para>D-Link DSB-650C</para>
- </listitem>
- <listitem>
- <para>Entrega NET-USB-E45</para>
- </listitem>
- <listitem>
- <para>I/O Data USB ETT</para>
- </listitem>
- <listitem>
- <para>Kawasaki DU-H3E</para>
- </listitem>
- <listitem>
- <para>LinkSys USB10T</para>
- </listitem>
- <listitem>
- <para>Netgear EA101</para>
- </listitem>
- <listitem>
- <para>Peracom USB Ethernet Adapter</para>
- </listitem>
- <listitem>
- <para>SMC 2102USB, 2104USB</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">ASIX Electronics AX88172-based USB Ethernet NICs
- (&man.axe.4; driver)
-
- <itemizedlist>
- <listitem>
- <para>D-Link DUBE100</para>
- </listitem>
- <listitem>
- <para>Linksys USB200M</para>
- </listitem>
- <listitem>
- <para>Netgear FA120</para>
- </listitem>
- </itemizedlist>
-
- </para>
-
- <para arch="i386,pc98">RealTek RTL8150-based USB Ethernet NICs
- (&man.rue.4; driver)
-
- <itemizedlist>
- <listitem>
- <para>GREEN HOUSE GH-USB100B</para>
- </listitem>
- <listitem>
- <para>MELCO LUA-KTX</para>
- </listitem>
- </itemizedlist>
-
- </para>
-
- <para arch="i386,pc98,alpha">ASIX Electronics AX88140A PCI NICs (&man.dc.4; driver)
- <itemizedlist>
- <listitem>
- <para>Alfa Inc. GFC2204</para>
- </listitem>
- <listitem>
- <para>CNet Pro110B</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">DEC EtherWORKS II and III NICs (&man.le.4; driver)
- <itemizedlist>
- <listitem>
- <para>DE200, DE201, DE202, DE422</para>
- </listitem>
- <listitem>
- <para>DE203, DE204, DE205</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">DEC DC21040, DC21041, DC21140, DC21141, DC21142, and DC21143
- based NICs (&man.de.4; driver)
- <itemizedlist>
- <listitem>
- <para>Asante</para>
- </listitem>
- <listitem>
- <para>Cogent EM100FX and EM440TX</para>
- </listitem>
- <listitem>
- <para>DEC DE425, DE435, DE450, and DE500</para>
- </listitem>
- <listitem>
- <para>SMC Etherpower 8432T, 9332, and 9334</para>
- </listitem>
- <listitem>
- <para>ZYNX ZX 3xx</para>
- </listitem>
- <listitem arch="pc98">
- <para>I-O DATA LA2/T-PCI (PCI)</para>
- </listitem>
- <listitem arch="pc98">
- <para>ELECOM LD-PCI2T, LD-PCITS (PCI)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Corega FastEther PCI-TX (PCI)
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">DEC/Intel 21143 based Fast Ethernet NICs (&man.dc.4; driver)
- <itemizedlist>
- <listitem>
- <para>DEC DE500</para>
- </listitem>
- <listitem>
- <para>Compaq Presario 7900 series built-in Ethernet</para>
- </listitem>
- <listitem>
- <para>D-Link DFE-570TX</para>
- </listitem>
- <listitem>
- <para>Kingston KNE100TX</para>
- </listitem>
- <listitem>
- <para>LinkSys EtherFast 10/100 Instant GigaDrive built-in Ethernet</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">Davicom DM9009, DM9100 and DM9102 PCI Fast Ethernet NICs (&man.dc.4; driver)
- <itemizedlist>
- <listitem>
- <para>Jaton Corporation XpressNet</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Xircom 3201 (Cardbus) (&man.dc.4; driver)</para>
-
- <para arch="i386">Conexant LANfinity RS7112 (MiniPCI) (&man.dc.4; driver)</para>
-
- <para arch="pc98">Cnet Pro120A (PCI) (&man.dc.4; driver)</para>
-
- <para arch="pc98">MELCO LGY-PCI-TXL (PCI) (&man.dc.4; driver)</para>
-
- <para arch="i386,pc98">Fujitsu MB86960A/MB86965A based Fast Ethernet NICs
- (&man.fe.4; driver)
- <itemizedlist>
- <listitem arch="i386">
- <para>CONTEC C-NET(PC)C Ethernet</para>
- </listitem>
- <listitem arch="i386">
- <para>Eiger Labs EPX-10BT</para>
- </listitem>
- <listitem arch="i386">
- <para>Fujitsu FMV-J182, FMV-J182A, MBH10302, MBH10303
- Ethernet PCMCIA</para>
- </listitem>
- <listitem arch="i386">
- <para>Fujitsu Towa LA501 Ethernet</para>
- </listitem>
- <listitem arch="i386">
- <para>HITACHI HT-4840-11</para>
- </listitem>
- <listitem arch="i386">
- <para>NextCom J Link NC5310</para>
- </listitem>
- <listitem arch="i386">
- <para>RATOC REX-5588, REX-9822, REX-4886, REX-R280</para>
- </listitem>
- <listitem arch="i386">
- <para>TDK LAK-CD021, LAK-CD021A, LAK-CD021BX</para>
- </listitem>
- <listitem arch="pc98">
- <para>Allied Telesis RE1000, RE1000Plus, ME1500 (110pin)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Contec C-NET(98)P2, C-NET(9N)E (110pin),
- C-NET(9N)C(ExtCard)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Ungermann-Bass Access/PC N98C+(PC85152,PC85142),
- Access/NOTE N98 (PC86132) (110pin)</para>
- </listitem>
- <listitem arch="pc98">
- <para>TDK LAC-98012, LAC-98013, LAC-98025, LAC-9N011
- (110pin)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Ratoc REX-9880/9881/9882/9883</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha,ia64,sparc64">Intel 82557-, 82258-, 82559-, 82550-
- or 82562-based Fast Ethernet NICs (&man.fxp.4; driver)
- <itemizedlist>
- <listitem>
- <para>Intel EtherExpress Pro/100B PCI Fast Ethernet</para>
- </listitem>
- <listitem arch="i386,alpha,ia64">
- <para>Intel InBusiness 10/100 PCI Network Adapter</para>
- </listitem>
- <listitem>
- <para>Intel PRO/100+ Management Adapter</para>
- </listitem>
- <listitem>
- <para>Intel Pro/100 VE Desktop Adapter</para>
- </listitem>
- <listitem>
- <para>Intel Pro/100 M Desktop Adapter</para>
- </listitem>
- <listitem>
- <para>Intel Pro/100 S Desktop, Server and Dual-Port Server Adapters</para>
- </listitem>
- <listitem arch="i386,ia64">
- <para>On-board Ethernet NICs on many Intel motherboards.</para>
- </listitem>
- <listitem arch="pc98">
- <para>NEC PC-9821Ra20, Rv20, Xv13, Xv20 internal 100Base-TX
- (PCI)</para>
- </listitem>
- <listitem arch="pc98">
- <para>NEC PC-9821X-B06 (PCI)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Contec C-NET(PI)-100TX (PCI)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Intel 82595-based Ethernet NICs (&man.ex.4; driver)
- <itemizedlist>
- <listitem>
- <para>Intel EtherExpress Pro/10 and Pro/10+ Ethernet</para>
- </listitem>
- <listitem>
- <para>Olicom OC2220</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Intel 82586-based Ethernet NICs (&man.ie.4; driver)
- <itemizedlist>
- <listitem>
- <para>3Com 3C507 Etherlink 16/TP</para>
- </listitem>
- <listitem>
- <para>AT&amp;T Starlan 10 and Starlan Fiber</para>
- </listitem>
- <listitem>
- <para>EN100</para>
- </listitem>
- <listitem>
- <para>Intel EtherExpress 16</para>
- </listitem>
- <listitem>
- <para>RACAL Interlan NI5210</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">3Com 3C5x9 Etherlink III NICs (&man.ep.4; driver)
- <itemizedlist>
- <listitem arch="i386">
- <para>3C509</para>
- </listitem>
- <listitem arch="i386">
- <para>3C529 MCA</para>
- </listitem>
- <listitem arch="i386">
- <para>3C579 EISA</para>
- </listitem>
- <listitem arch="i386">
- <para>3CXE589EC, 3CXE589ET PCMCIA</para>
- </listitem>
- <listitem arch="i386">
- <para>3C589/589B/589C/589D/589E/574TX/574B
- PC-card/PCMCIA</para>
- </listitem>
- <listitem arch="i386">
- <para>Megahertz 3CCFEM556BI, 3CXEM556, 3CCFEM556B</para>
- </listitem>
- <listitem arch="i386">
- <para>OfficeConnect 3CXSH572BT</para>
- </listitem>
- <listitem arch="i386">
- <para>Farallon EtherMac</para>
- </listitem>
- <listitem arch="pc98">
- <para>3Com 3C569, 3C569-TPO, 3C569B, 3C569B-COMBO</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">3Com 3C501 8-bit ISA Ethernet NIC
- (&man.el.4; driver)</para>
-
- <para arch="i386,pc98,alpha,sparc64">3Com Etherlink XL-based NICs (&man.xl.4; driver)
- <itemizedlist>
- <listitem>
- <para>3C900/905/905B/905C PCI</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>3C555/556/556B MiniPCI</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>3C450-TX HomeConnect adapter</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>3c980/3c980B Fast Etherlink XL server adapter</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>3cSOHO100-TX OfficeConnect adapter</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>3C575TX/575B/XFE575BT/575C/656/656B/656C (Cardbus)</para>
- </listitem>
- <listitem arch="i386">
- <para>Dell Optiplex GX1 on-board 3C918</para>
- </listitem>
- <listitem arch="i386">
- <para>Dell On-board 3C920</para>
- </listitem>
- <listitem arch="i386">
- <para>Dell Precision on-board 3C905B</para>
- </listitem>
- <listitem arch="i386">
- <para>Dell Latitude laptop docking station embedded 3C905-TX</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">3Com 3C59X series NICs (&man.vx.4; driver)
- <itemizedlist>
- <listitem>
- <para>3C590 Etherlink III (PCI)</para>
- </listitem>
- <listitem>
- <para>3C595 Fast Etherlink III (PCI)</para>
- </listitem>
- <listitem arch="i386">
- <para>3C592/3C597 (EISA)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Crystal Semiconductor CS89x0-based NICs
- (&man.cs.4; driver)
- <itemizedlist>
- <listitem>
- <para>IBM Etherjet ISA</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Megahertz X-Jack Ethernet PC-Card CC-10BT (&man.sn.4;
- driver)</para>
-
- <para arch="i386">Xircom X3201 (Cardbus) based Ethernet cards, including the following:
- <itemizedlist>
- <listitem>
- <para>IBM EtherJet Cardbus Adapter</para>
- </listitem>
- <listitem>
- <para>Intel PRO/100 Mobile Cardbus (versions that use the
- X3201 chipset)</para>
- </listitem>
- <listitem>
- <para>Xircom Cardbus Realport</para>
- </listitem>
- <listitem>
- <para>Xircom Cardbus Ethernet 10/100</para>
- </listitem>
- <listitem>
- <para>Xircom Cardbus Ethernet II 10/100</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Xircom CreditCard adapters (16 bit) and
- workalikes (xe driver)
- <itemizedlist>
- <listitem>
- <para>Accton EN2226/Fast EtherCard (16-bit version)</para>
- </listitem>
- <listitem>
- <para>Compaq Netelligent 10/100 PC Card</para>
- </listitem>
- <listitem>
- <para>Intel EtherExpress PRO/100 Mobile Adapter (16-bit
- version)</para>
- </listitem>
- <listitem>
- <para>Xircom 10/100 Network PC Card adapter</para>
- </listitem>
- <listitem>
- <para>Xircom Realport card + modem(Ethernet part)</para>
- </listitem>
- <listitem>
- <para>Xircom CreditCard Ethernet 10/100</para>
- </listitem>
- <listitem>
- <para>Xircom CreditCard 10Base-T <quote>CreditCard Ethernet
- Adapter IIps</quote> (PS-CE2-10)</para>
- </listitem>
- <listitem>
- <para>Xircom CreditCard Ethernet 10/100 + modem (Ethernet
- part)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="pc98">National Semiconductor DP8393X (SONIC) Ethernet
- cards (snc driver)
- <itemizedlist>
- <listitem>
- <para>NEC PC-9801-83, -84, -103, and -104</para>
- </listitem>
- <listitem>
- <para>NEC PC-9801N-25 and -J02R</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">Gigabit Ethernet cards based on the Level 1
- LXT1001 NetCellerator controller (&man.lge.4; driver)
- <itemizedlist>
- <listitem>
- <para>D-Link DGE-500SX</para>
- </listitem>
- <listitem>
- <para>SMC TigerCard 1000 (SMC9462SX)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">Ethernet and Fast Ethernet NICs based
- on the 3Com 3XP Typhoon/Sidewinder (3CR990) chipset (&man.txp.4; driver)
- <itemizedlist>
- <listitem>
- <para>3Com 3CR990-TX-95</para>
- </listitem>
- <listitem>
- <para>3Com 3CR990-TX-97</para>
- </listitem>
- <listitem>
- <para>3Com 3CR990B-SRV</para>
- </listitem>
- <listitem>
- <para>3Com 3CR990B-TXM</para>
- </listitem>
- <listitem>
- <para>3Com 3CR990SVR95</para>
- </listitem>
- <listitem>
- <para>3Com 3CR990SVR97</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,ia64">Gigabit Ethernet NICs based on the Broadcom BCM570x
- (&man.bge.4; driver)
- <itemizedlist>
- <listitem>
- <para>3Com 3c996-SX, 3c996-T</para>
- </listitem>
- <listitem>
- <para>Netgear GA302T</para>
- </listitem>
- <listitem>
- <para>SysKonnect SK-9D21 and 9D41</para>
- </listitem>
- <listitem arch="i386">
- <para>Integrated Gigabit Ethernet NICs on DELL PowerEdge 2550
- servers</para>
- </listitem>
- <listitem arch="i386">
- <para>Integrated Gigabit Ethernet NICs on IBM x235 servers</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha,ia64">Gigabit Ethernet NICs based on the
- Intel 82542 and 82543 controller chips (&man.gx.4; and &man.em.4;
- drivers), plus NICs supported by the Intel 82540EM, 82544,
- 82545EM, and 82546EB
- controller chips (&man.em.4; driver only)
- <itemizedlist>
- <listitem>
- <para>Intel PRO/1000 Gigabit Ethernet</para>
- </listitem>
- </itemizedlist>
-
- <note>
- <para>The &man.em.4; driver is officially supported by Intel,
- but is only supported on the i386.</para>
- </note>
- </para>
-
- <para arch="sparc64">Sun HME and QFE Ethernet NICs (hme driver)</para>
-
- <para arch="sparc64">Sun GEM (Gigabit Ethernet) and ERI (Fast
- Ethernet) NICs (gem driver)</para>
-
- <para arch="i386,pc98">Myson Ethernet NICs (my driver)
- <itemizedlist>
- <listitem>
- <para>Myson MTD80X Based Fast Ethernet Card</para>
- </listitem>
- <listitem>
- <para>Myson MTD89X Based Gigabit Ethernet Card</para>
- </listitem>
- </itemizedlist>
- </para>
-
- </sect2>
-
- <sect2>
- <title>FDDI Interfaces</title>
- <para arch="i386,pc98,alpha">DEC DEFPA PCI (&man.fpa.4; driver)</para>
- <para arch="i386">DEC DEFEA EISA (&man.fpa.4; driver)</para>
- </sect2>
-
- <sect2>
- <title>ATM Interfaces</title>
-
- <para arch="i386,pc98">Efficient Networks, Inc. ENI-155p ATM PCI
- Adapters (hea driver)</para>
-
- <para arch="i386,pc98">FORE Systems, Inc. PCA-200E ATM PCI
- Adapters (hfa driver)</para>
-
- <para arch="i386,pc98">IDT 77201/211 NICStAR ATM Adapters (idt
- driver)</para>
-
- <para arch="i386,pc98">FORE Systems, Inc. LE155 ATM Adapter (idt
- driver)</para>
-
- <para arch="i386,pc98">The ATM support in &os; supports the following signaling protocols:
- <itemizedlist>
- <listitem>
- <para>The ATM Forum UNI 3.1 signaling protocol</para>
- </listitem>
- <listitem>
- <para>The ATM Forum UNI 3.0 signaling protocol</para>
- </listitem>
- <listitem>
- <para>The ATM Forum ILMI address registration</para>
- </listitem>
- <listitem>
- <para>FORE Systems' proprietary SPANS signaling protocol</para>
- </listitem>
- <listitem>
- <para>Permanent Virtual Channels (PVCs)</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98">Support for the IETF <quote>Classical IP
- and ARP over ATM</quote> model is provided, compliant with the
- following RFCs and Internet Drafts:
- <itemizedlist>
- <listitem>
- <para>RFC 1483, <quote>Multiprotocol Encapsulation over ATM
- Adaptation Layer 5</quote></para>
- </listitem>
- <listitem>
- <para>RFC 1577, <quote>Classical IP and ARP over ATM</quote></para>
- </listitem>
- <listitem>
- <para>RFC 1626, <quote>Default IP MTU for use over ATM
- AAL5</quote></para>
- </listitem>
- <listitem>
- <para>RFC 1755, <quote>ATM Signaling Support for IP over ATM</quote></para>
- </listitem>
- <listitem>
- <para>RFC 2225, <quote>Classical IP and ARP over ATM</quote></para>
- </listitem>
- <listitem>
- <para>RFC 2334, <quote>Server Cache Synchronization Protocol
- (SCSP)</quote></para>
- </listitem>
- <listitem>
- <para>Internet Draft
- <filename>draft-ietf-ion-scsp-atmarp-00.txt</filename>, <quote>A
- Distributed ATMARP Service Using SCSP</quote></para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98">Support for an ATM sockets interface is also provided.</para>
- </sect2>
- <sect2>
- <title>Wireless Network Interfaces</title>
-
- <para arch="i386">NCR / AT&amp;T / Lucent Technologies WaveLan T1-speed
- ISA/radio LAN cards (&man.wl.4; driver)</para>
-
- <para arch="i386,pc98">Lucent Technologies WaveLAN/IEEE 802.11 PCMCIA and ISA
- standard speed (2Mbps) and turbo speed (6Mbps) wireless network
- adapters and workalikes (&man.wi.4; driver)
- <note>
- <para>The ISA versions of these adapters are actually PCMCIA
- cards combined with an ISA to PCMCIA bridge card, so both kinds
- of devices work with the same driver.</para>
- </note>
- <itemizedlist>
- <listitem>
- <para>3COM 3crwe737A AirConnect Wireless LAN PC Card</para>
- </listitem>
- <listitem>
- <para>Accton airDirect WN3301</para>
- </listitem>
- <listitem>
- <para>Addtron AWA100</para>
- </listitem>
- <listitem>
- <para>Adtec ADLINK340APC</para>
- </listitem>
- <listitem>
- <para>Airway 802.11 Adapter</para>
- </listitem>
- <listitem>
- <para>Avaya Wireless PC Card</para>
- </listitem>
- <listitem>
- <para>Blue Concentric Circle CF Wireless LAN Model WL-379F</para>
- </listitem>
- <listitem>
- <para>BreezeNET PC-DS.11</para>
- </listitem>
- <listitem>
- <para>Buffalo WLI-CF-S11G</para>
- </listitem>
- <listitem>
- <para>Cabletron RoamAbout 802.11 DS</para>
- </listitem>
- <listitem>
- <para>Compaq WL100, WL110</para>
- </listitem>
- <listitem>
- <para>Corega KK Wireless LAN PCC-11, PCCA-11, PCCB-11</para>
- </listitem>
- <listitem>
- <para>D-Link DWL-650</para>
- </listitem>
- <listitem>
- <para>Dell TrueMobile 1150 Series</para>
- </listitem>
- <listitem>
- <para>ELECOM Air@Hawk/LD-WL11/PCC</para>
- </listitem>
- <listitem>
- <para>ELSA AirLancer MC-11</para>
- </listitem>
- <listitem>
- <para>Farallon Skyline 11Mbps Wireless</para>
- </listitem>
- <listitem>
- <para>ICOM SL-1100</para>
- </listitem>
- <listitem>
- <para>IBM High Rate Wireless LAN PC Card</para>
- </listitem>
- <listitem>
- <para>Intel PRO/Wireless 2011 LAN PC Card</para>
- </listitem>
- <listitem>
- <para>IO Data WN-B11/PCM</para>
- </listitem>
- <listitem>
- <para>Laneed Wireless card</para>
- </listitem>
- <listitem>
- <para>Linksys Instant Wireless WPC11</para>
- </listitem>
- <listitem>
- <para>Lucent WaveLAN/IEEE 802.11</para>
- </listitem>
- <listitem>
- <para>MELCO Airconnect WLI-PCM-S11, WLI-PCM-L11</para>
- </listitem>
- <listitem>
- <para>NCR WaveLAN/IEEE 802.11</para>
- </listitem>
- <listitem>
- <para>NEC Wireless Card CMZ-RT-WP</para>
- </listitem>
- <listitem>
- <para>NEC Aterm WL11C (PC-WL/11C)</para>
- </listitem>
- <listitem>
- <para>NEC PK-WL001</para>
- </listitem>
- <listitem>
- <para>Netgear MA401</para>
- </listitem>
- <listitem>
- <para>PLANEX GeoWave/GW-NS110</para>
- </listitem>
- <listitem>
- <para>Proxim Harmony, RangeLAN-DS</para>
- </listitem>
- <listitem>
- <para>SMC 2632W, 2602W</para>
- </listitem>
- <listitem>
- <para>Sony PCWA-C100</para>
- </listitem>
- <listitem>
- <para>TDK LAK-CD011WL</para>
- </listitem>
- <listitem>
- <para>Toshiba Wireless LAN Card</para>
- </listitem>
- <listitem>
- <para>US Robotics Wireless Card 2410</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">Aironet 802.11 wireless adapters (&man.an.4; driver)
- <itemizedlist>
- <listitem>
- <para>Aironet 4500/4800 series
- (PCMCIA, PCI, and ISA adapters are all supported)</para>
- </listitem>
- <listitem>
- <para>Cisco Systems Aironet 340 and 350 series
- (PCMCIA, PCI, Mini-PCI, and ISA adapters are all supported)</para>
- </listitem>
- <listitem>
- <para>Xircom Wireless Ethernet adapter (rebadged Aironet)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">Raytheon Raylink 2.4GHz wireless adapters (&man.ray.4; driver)
- <itemizedlist>
- <listitem>
- <para>Webgear Aviator</para>
- </listitem>
- <listitem>
- <para>Webgear Aviator Pro</para>
- </listitem>
- <listitem>
- <para>Raytheon Raylink PC Card</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">AMD Am79C930 and Harris (Intersil) based 802.11 cards (&man.awi.4; driver)
- <itemizedlist>
- <listitem>
- <para>BayStack 650 and 660</para>
- </listitem>
- <listitem>
- <para>Farallon SkyLINE Wireless</para>
- </listitem>
- <listitem>
- <para>Icom SL-200</para>
- </listitem>
- <listitem>
- <para>MELCO WLI-PCM</para>
- </listitem>
- <listitem>
- <para>NEL SSMagic</para>
- </listitem>
- <listitem>
- <para>Netwave AirSurfer Plus and AirSurfer Pro</para>
- </listitem>
- <listitem>
- <para>ZoomAir 4000</para>
- </listitem>
- </itemizedlist>
- </para>
-
- </sect2>
-
- <sect2>
- <title>Miscellaneous Networks</title>
-
- <para arch="i386">Granch SBNI12 point-to-point communications
- adapters (&man.sbni.4; driver)
- <itemizedlist>
- <listitem>
- <para>SBNI12-XX and SBNI12D-XX ISA and PCI</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Granch SBNI16 SHDSL modems (&man.sbsh.4;
- driver)</para>
-
- <para arch="i386">SMC COM90cx6 ARCNET network adapters (cm driver)
- <itemizedlist>
- <listitem>
- <para>SMC 90c26, 90c56, and 90c66 in 90c56 compatability mode</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">LAN Media Corp WAN adapters based on the DEC
- <quote>Tulip</quote> Fast Ethernet controller (&man.lmc.4;
- driver)
-
- <itemizedlist>
- <listitem>
- <para>LMC1000 Synchronous Serial Interface adapter</para>
- </listitem>
-
- <listitem>
- <para>LMC1200 T1/E1 WAN adapter</para>
- </listitem>
-
- <listitem>
- <para>LMC5200 High Speed Synchronous Interface (HSSI)
- adapter</para>
- </listitem>
-
- <listitem>
- <para>LMC5245 DS3 WAN adapter</para>
- </listitem>
- </itemizedlist>
- </para>
-
- </sect2>
-
- <sect2>
- <title>ISDN Interfaces</title>
- <para arch="i386">AcerISDN P10 ISA PnP (experimental)</para>
- <para arch="i386">Asuscom ISDNlink 128K ISA</para>
- <para arch="i386">ASUSCOM P-IN100-ST-D (and other Winbond W6692-based cards)</para>
- <para arch="i386">AVM
- <itemizedlist>
- <listitem>
- <para>A1</para>
- </listitem>
- <listitem>
- <para>B1 ISA (tested with V2.0)</para>
- </listitem>
- <listitem>
- <para>B1 PCI (tested with V4.0)</para>
- </listitem>
- <listitem>
- <para>Fritz!Card classic</para>
- </listitem>
- <listitem>
- <para>Fritz!Card PnP</para>
- </listitem>
- <listitem>
- <para>Fritz!Card PCI</para>
- </listitem>
- <listitem>
- <para>Fritz!Card PCI, Version 2</para>
- </listitem>
- <listitem>
- <para>T1</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386">Creatix
- <itemizedlist>
- <listitem>
- <para>ISDN-S0</para>
- </listitem>
- <listitem>
- <para>ISDN-S0 P&amp;P</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386">Compaq Microcom 610 ISDN (Compaq series PSB2222I) ISA PnP</para>
- <para arch="i386">Dr. Neuhaus Niccy Go@ and compatibles</para>
- <para arch="i386">Dynalink IS64PPH and IS64PPH+</para>
- <para arch="i386">Eicon Diehl DIVA 2.0 and 2.02</para>
- <para arch="i386">ELSA
- <itemizedlist>
- <listitem>
- <para>ELSA PCC-16</para>
- </listitem>
- <listitem>
- <para>QuickStep 1000pro ISA</para>
- </listitem>
- <listitem>
- <para>MicroLink ISDN/PCI</para>
- </listitem>
- <listitem>
- <para>QuickStep 1000pro PCI</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386">ITK ix1 Micro ( &lt; V.3, non-PnP version )</para>
- <para arch="i386">Sedlbauer Win Speed</para>
- <para arch="i386">Siemens I-Surf 2.0</para>
- <para arch="i386">TELEINT ISDN SPEED No.1 (experimental)</para>
- <para arch="i386">Teles
- <itemizedlist>
- <listitem>
- <para>S0/8</para>
- </listitem>
- <listitem>
- <para>S0/16</para>
- </listitem>
- <listitem>
- <para>S0/16.3</para>
- </listitem>
- <listitem>
- <para>S0/16.3 PnP</para>
- </listitem>
- <listitem>
- <para>16.3c ISA PnP (experimental)</para>
- </listitem>
- <listitem>
- <para>Teles PCI-TJ</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386">Traverse Technologies NETjet-S PCI</para>
- <para arch="i386">USRobotics Sportster ISDN TA intern</para>
- <para arch="i386">Winbond W6692 based PCI cards</para>
- </sect2>
-
- <sect2>
- <title>Serial Interfaces</title>
- <para arch="i386,alpha,ia64"><quote>PC standard</quote> 8250, 16450, and 16550-based serial ports (&man.sio.4; driver)</para>
-
- <para arch="sparc64">Serial ports based on the SAB82532 serial
- chip, console only (sab driver)</para>
-
- <para arch="sparc64">Serial ports based on the Zilog 8530 dual uart,
- console only (zs driver)</para>
-
- <para arch="i386,alpha">AST 4 port serial card using shared IRQ</para>
-
- <para arch="i386">ARNET serial cards (&man.ar.4; driver)
- <itemizedlist>
- <listitem>
- <para>ARNET 8 port serial card using shared IRQ</para>
- </listitem>
- <listitem>
- <para>ARNET (now Digiboard) Sync 570/i high-speed serial</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Boca multi-port serial cards
- <itemizedlist>
- <listitem>
- <para>Boca BB1004 4-Port serial card (Modems
- <emphasis>not</emphasis> supported)</para>
- </listitem>
- <listitem>
- <para>Boca IOAT66 6-Port serial card (Modems supported)</para>
- </listitem>
- <listitem>
- <para>Boca BB1008 8-Port serial card (Modems
- <emphasis>not</emphasis> supported)</para>
- </listitem>
- <listitem>
- <para>Boca BB2016 16-Port serial card (Modems supported)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,alpha">Comtrol Rocketport card (&man.rp.4; driver)</para>
-
- <para arch="i386">Cyclades Cyclom-Y serial board (&man.cy.4; driver)</para>
-
- <para arch="i386">STB 4 port card using shared IRQ</para>
-
- <para arch="i386">DigiBoard intelligent serial cards (&man.dgb.4; driver)
- <itemizedlist>
- <listitem>
- <para>DigiBoard PC/Xe series</para>
- </listitem>
- <listitem>
- <para>DigiBoard PC/Xi series</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,ia64">PCI-Based multi-port serial boards (&man.puc.4;
- driver)
- <itemizedlist>
- <listitem arch="i386">
- <para>Actiontech 56K PCI</para>
- </listitem>
- <listitem arch="i386">
- <para>Avlab Technology, PCI IO 2S and PCI IO 4S</para>
- </listitem>
- <listitem arch="i386">
- <para>Comtrol RocketPort 550</para>
- </listitem>
- <listitem arch="i386">
- <para>Decision Computers PCCOM 4-port serial and dual port RS232/422/485</para>
- </listitem>
- <listitem arch="ia64">
- <para>Diva Serial (GSP) Multiport UART (development branch only)</para>
- </listitem>
- <listitem arch="i386">
- <para>Dolphin Peripherals 4025/4035/4036</para>
- </listitem>
- <listitem arch="i386">
- <para>IC Book Labs Dreadnought 16x Lite and Pro</para>
- </listitem>
- <listitem arch="i386">
- <para>Lava Computers 2SP-PCI/DSerial-PCI/Quattro-PCI/Octopus-550</para>
- </listitem>
- <listitem arch="i386">
- <para>Middle Digital, Weasle serial port</para>
- </listitem>
- <listitem arch="i386">
- <para>Moxa Industio CP-114, Smartio C104H-PCI and C168H/PCI</para>
- </listitem>
- <listitem arch="i386">
- <para>NEC PK-UG-X001 and PK-UG-X008</para>
- </listitem>
- <listitem arch="i386">
- <para>Netmos NM9835 PCI-2S-550</para>
- </listitem>
- <listitem arch="i386">
- <para>Oxford Semiconductor OX16PCI954 PCI UART</para>
- </listitem>
- <listitem arch="i386">
- <para>Syba Tech SD-LAB PCI-4S2P-550-ECP</para>
- </listitem>
- <listitem arch="i386">
- <para>SIIG Cyber I/O PCI 16C550/16C650/16C850</para>
- </listitem>
- <listitem arch="i386">
- <para>SIIG Cyber 2P1S PCI 16C550/16C650/16C850</para>
- </listitem>
- <listitem arch="i386">
- <para>SIIG Cyber 2S1P PCI 16C550/16C650/16C850</para>
- </listitem>
- <listitem arch="i386">
- <para>SIIG Cyber 4S PCI 16C550/16C650/16C850</para>
- </listitem>
- <listitem arch="i386">
- <para>SIIG Cyber Serial (Single and Dual) PCI 16C550/16C650/16C850</para>
- </listitem>
- <listitem arch="i386">
- <para>Syba Tech Ltd. PCI-4S2P-550-ECP</para>
- </listitem>
- <listitem arch="i386">
- <para>Titan PCI-200H and PCI-800H</para>
- </listitem>
- <listitem arch="i386">
- <para>US Robotics (3Com) 3CP5609 modem</para>
- </listitem>
- <listitem arch="i386">
- <para>VScom PCI-400 and PCI-800</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">SDL Communication serial boards
- <itemizedlist>
- <listitem>
- <para>SDL Communications Riscom/8 Serial Board (rc driver)</para>
- </listitem>
- <listitem>
- <para>SDL Communications RISCom/N2 and N2pci high-speed sync
- serial boards (&man.sr.4; driver)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Stallion Technologies multiport serial boards
- <itemizedlist>
- <listitem>
- <para>EasyIO (&man.stl.4; driver)</para>
- </listitem>
- <listitem>
- <para>EasyConnection 8/32 (&man.stl.4; driver)</para>
- </listitem>
- <listitem>
- <para>EasyConnection 8/64 (&man.stli.4; driver)</para>
- </listitem>
- <listitem>
- <para>ONboard 4/16 (&man.stli.4; driver)</para>
- </listitem>
- <listitem>
- <para>Brumby (&man.stli.4; driver)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Specialix SI/XIO/SX multiport serial cards, with both the
- older SIHOST2.x and the new <quote>enhanced</quote> (transputer
- based, aka JET) host cards (ISA, EISA and PCI are supported)
- (&man.si.4; driver)</para>
-
- <para arch="pc98">Internel serial interfaces (&man.sio.4; driver)
- <itemizedlist>
- <listitem>
- <para>PC-9801 on-board</para>
- </listitem>
- <listitem>
- <para>PC-9821 2'nd CCU (flags 0x12000000)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="pc98">NEC PC-9861K, PC-9801-101 and Midori-Denshi MDC-926Rs (&man.sio.4; driver)
- <itemizedlist>
- <listitem>
- <para>COM2 (flags 0x01000000)</para>
- </listitem>
- <listitem>
- <para>COM3 (flags 0x02000000)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="pc98">NEC PC-9801-120 (&man.sio.4; driver)</para>
- <note arch="pc98">
- <para>"flags 0x11000000" is necessary in kernel configuration.</para>
- </note>
-
- <para arch="pc98">Microcore MC-16550, MC-16550II, MC-RS98 (&man.sio.4; driver)</para>
- <note arch="pc98">
- <para>"flags 0x14000?01" is necessary in kernel configuration.</para>
- </note>
-
- <para arch="pc98">Media Intelligent RSB-2000, RSB-3000 and AIWA B98-02 (&man.sio.4; driver)</para>
- <note arch="pc98">
- <para>"flags 0x15000?01" is necessary in kernel configuration.</para>
- </note>
-
- <para arch="pc98">Media Intelligent RSB-384 (&man.sio.4; driver)</para>
- <note arch="pc98">
- <para>"flags 0x16000001" is necessary in kernel configuration.</para>
- </note>
-
- <para arch="pc98">I-O DATA RSA-98III (&man.sio.4; driver)</para>
- <note arch="pc98">
- <para>"flags 0x18000?01" is necessary in kernel configuration.</para>
- </note>
-
- <para arch="pc98">Hayes ESP98 (&man.sio.4; driver)</para>
- <note arch="pc98">
- <para>"options COM_ESP" and "flags 0x19000000" are necessary in kernel configuration.</para>
- </note>
-
- </sect2>
- <sect2>
- <title>Audio Devices</title>
-
- <para arch="i386">Advance (&man.sbc.4; driver)
- <itemizedlist>
- <listitem>
- <para>Asound 100 and 110</para>
- </listitem>
- <listitem>
- <para>Logic ALS120 and ALS4000</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">CMedia sound chips
- <itemizedlist>
- <listitem>
- <para>CMI8338/CMI8738</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Crystal Semiconductor (&man.csa.4; driver)
- <itemizedlist>
- <listitem>
- <para>CS461x/462x Audio Accelerator</para>
- </listitem>
- <listitem>
- <para>CS428x Audio Controller</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">ENSONIQ (&man.pcm.4; driver)
- <itemizedlist>
- <listitem>
- <para>AudioPCI ES1370/1371</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,alpha">ESS
- <itemizedlist>
- <listitem>
- <para>ES1868, ES1869, ES1879 and ES1888 (&man.sbc.4; driver)</para>
- </listitem>
- <listitem>
- <para>Maestro-1, Maestro-2, and Maestro-2E</para>
- </listitem>
- <listitem>
- <para>Maestro-3/Allegro</para>
- <note>
- <para>The Maestro-3/Allegro cannot be compiled into the
- &os; kernel due to licensing restrictions. To use this
- driver, add the following line to
- <filename>/boot/loader.conf</filename>:</para>
-
- <screen><userinput>snd_maestro3_load="YES"</userinput></screen>
- </note>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">ForteMedia fm801</para>
-
- <para arch="i386">Gravis (&man.gusc.4; driver)
- <itemizedlist>
- <listitem>
- <para>UltraSound MAX</para>
- </listitem>
- <listitem>
- <para>UltraSound PnP</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Intel 443MX, 810, 815, and 815E integrated sound
- devices (&man.pcm.4; driver)</para>
-
- <para arch="i386,alpha">MSS/WSS Compatible DSPs (&man.pcm.4; driver)</para>
-
- <para arch="i386">NeoMagic 256AV/ZX (&man.pcm.4; driver)</para>
-
- <para arch="i386">OPTi 931/82C931 (&man.pcm.4; driver)</para>
-
- <para arch="i386">S3 Sonicvibes</para>
-
- <para arch="i386,alpha">Creative Technologies SoundBlaster series (&man.sbc.4; driver)
- <itemizedlist>
- <listitem>
- <para>SoundBlaster</para>
- </listitem>
- <listitem>
- <para>SoundBlaster Pro</para>
- </listitem>
- <listitem>
- <para>SoundBlaster AWE-32</para>
- </listitem>
- <listitem>
- <para>SoundBlaster AWE-64</para>
- </listitem>
- <listitem>
- <para>SoundBlaster AWE-64 GOLD</para>
- </listitem>
- <listitem>
- <para>SoundBlaster ViBRA-16</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Creative Technologies Sound Blaster Live! series
- (emu10k1 driver)</para>
-
- <para arch="i386">Trident 4DWave DX/NX (&man.pcm.4; driver)</para>
-
- <para arch="i386">VIA Technologies VT82C686A</para>
-
- <para arch="i386">Yamaha
- <itemizedlist>
- <listitem>
- <para>DS1</para>
- </listitem>
- <listitem>
- <para>DS1e</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="pc98">NEC PC-9801-73, 86 and compatibles (nss driver)
- <itemizedlist>
- <listitem>
- <para>NEC A-MATE internal sound</para>
- </listitem>
- <listitem>
- <para>Q-Vision WaveStar, WaveMaster</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="pc98">NEC X-MATE, CanBe, ValueStar internal (mss driver)</para>
-
- <para arch="pc98">Creative Technologies SoundBlaster(98) (&man.sb.4;
- driver)</para>
-
- <para arch="pc98">I-O DATA CD-BOX (&man.sb.4; driver)</para>
-
- <para arch="pc98">Software PCM using beep (pca driver)</para>
-
- <para arch="pc98">MPU-401 and compatible interfaces (mpu driver)
- <itemizedlist>
- <listitem>
- <para>Q-Vision WaveStar</para>
- </listitem>
- </itemizedlist>
- </para>
- </sect2>
-
- <sect2>
- <title>Camera and Video Capture Devices</title>
- <para arch="i386,pc98">Brooktree Bt848/849/878/879-based frame grabbers (&man.bktr.4;
- driver)
- <itemizedlist>
- <listitem>
- <para>AverMedia cards</para>
- </listitem>
- <listitem>
- <para>Hauppauge Wincast TV and WinTV boards (PCI)</para>
- </listitem>
- <listitem>
- <para>Intel Smart Video Recorder III</para>
- </listitem>
- <listitem>
- <para>Miro PC TV</para>
- </listitem>
- <listitem>
- <para>STB TV PCI</para>
- </listitem>
- <listitem>
- <para>Video Highway XTreme</para>
- </listitem>
- <listitem>
- <para>VideoLogic Captivator PCI</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386">Connectix QuickCam</para>
- <para arch="i386">Cortex1 frame grabber (ctx driver)</para>
- <para arch="i386">Creative Labs Video Spigot frame grabber (spigot driver)</para>
- <para arch="i386">Matrox Meteor Video frame grabber (&man.meteor.4; driver)</para>
- </sect2>
-
- <sect2 id="usb">
- <title>USB Devices</title>
-
- <para arch="alpha,i386,pc98">A range of USB peripherals are supported; devices known to
- work are listed in this section. Owing to the
- generic nature of most USB devices, with some exceptions any
- device of a given class will be supported, even if not explicitly
- listed here.</para>
-
- <note arch="alpha,i386,pc98">
- <para>USB Ethernet adapters can be found in the section listing <link
- linkend="ethernet">Ethernet interfaces</link>.</para>
- </note>
-
- <note arch="alpha,i386,pc98">
- <para>USB Bluetooth adapters can be found in <link
- linkend="bluetooth">Bluetooth</link> section.</para>
- </note>
-
- <para arch="i386,pc98,alpha,ia64">Host Controllers (&man.ohci.4; and &man.uhci.4; drivers)
- <itemizedlist>
- <listitem arch="i386,alpha">
- <para>ALi Aladdin-V</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>AMD-756</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>CMD Tech 670 & 673</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>Intel 82371SB (PIIX3)</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>Intel 82371AB and EB (PIIX4)</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>Intel 82801AA (ICH)</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>Intel 82801AB (ICH0)</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>Intel 82801BA/BAM (ICH2)</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>Intel 82443MX</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>NEC uPD 9210</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>OPTi 82C861 (FireLink)</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>SiS 5571</para>
- </listitem>
- <listitem arch="i386,alpha">
- <para>VIA 83C572 USB</para>
- </listitem>
- <listitem arch="i386,alpha,ia64">
- <para>UHCI or OHCI compliant motherboard chipsets (no
- exceptions known)</para>
- </listitem>
- <listitem arch="pc98">
- <para>NEC PC-9821V200 etc (&man.ohci.4; driver)</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98">USB host controllers (PCI)
- <itemizedlist>
- <listitem arch="i386">
- <para>ADS Electronics PCI plug-in card (2 ports)</para>
- </listitem>
- <listitem arch="i386">
- <para>Entrega PCI plug-in card (4 ports)</para>
- </listitem>
- <listitem arch="pc98">
- <para>TRY CORPORATION JUS-02 (&man.uhci.4; driver)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,ia64,pc98">USB 2.0 controllers using the EHCI
- interface (&man.ehci.4; driver)</para>
-
- <para arch="i386,pc98,alpha">Hubs
- <itemizedlist>
- <listitem>
- <para>Andromeda hub</para>
- </listitem>
- <listitem>
- <para>MacAlly self powered hub (4 ports)</para>
- </listitem>
- <listitem>
- <para>NEC hub</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98,alpha">Keyboards (&man.ukbd.4; driver)
- <itemizedlist>
- <listitem>
- <para>Apple iMac keyboard</para>
- </listitem>
- <listitem>
- <para>BTC BTC7935 keyboard with PS/2 mouse port</para>
- </listitem>
- <listitem>
- <para>Cherry G81-3504 keyboard</para>
- </listitem>
- <listitem>
- <para>Logitech M2452 keyboard</para>
- </listitem>
- <listitem>
- <para>MacAlly iKey keyboard</para>
- </listitem>
- <listitem>
- <para>Microsoft keyboard</para>
- </listitem>
- <listitem>
- <para>Sun Microsystems Type 6 USB keyboard</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98">Miscellaneous
- <itemizedlist>
- <listitem>
- <para>ActiveWire I/O Board</para>
- </listitem>
- <listitem>
- <para>Diamond Rio 500, 600, and 800 MP3 players (&man.urio.4; driver)</para>
- </listitem>
- <listitem>
- <para>D-Link DSB-R100 USB Radio (ufm driver)</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98">Modems (&man.umodem.4; driver)
- <itemizedlist>
- <listitem>
- <para>3Com 5605</para>
- </listitem>
- <listitem>
- <para>Metricom Ricochet GS USB wireless modem</para>
- </listitem>
- <listitem>
- <para>Yamaha Broadband Wireless Router RTW65b</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98,alpha">Mice (&man.ums.4; driver)
- <itemizedlist>
- <listitem>
- <para>Agiler Mouse 29UO</para>
- </listitem>
- <listitem>
- <para>Apple iMac Mouse</para>
- </listitem>
- <listitem>
- <para>Belkin Mouse</para>
- </listitem>
- <listitem>
- <para>Chic mouse</para>
- </listitem>
- <listitem>
- <para>Cypress mouse</para>
- </listitem>
- <listitem>
- <para>Genius Niche mouse</para>
- </listitem>
- <listitem>
- <para>Kensington Mouse-in-a-Box</para>
- </listitem>
- <listitem>
- <para>Logitech wheel mouse (3 buttons)</para>
- </listitem>
- <listitem>
- <para>Logitech PS/2 / USB mouse (3 buttons)</para>
- </listitem>
- <listitem>
- <para>MacAlly mouse (3 buttons)</para>
- </listitem>
- <listitem>
- <para>Microsoft IntelliMouse (3 buttons)</para>
- </listitem>
- <listitem>
- <para>Sun Microsystems Type 6 USB Mouse</para>
- </listitem>
- <listitem>
- <para>Trust Ami Mouse (3 buttons)</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98,alpha">Printers and parallel printer conversion cables (&man.ulpt.4; driver)
- <itemizedlist>
- <listitem>
- <para>ATen parallel printer adapter</para>
- </listitem>
- <listitem>
- <para>Belkin F5U002 parallel printer adapter</para>
- </listitem>
- <listitem>
- <para>Entrega USB-to-parallel printer adapter</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98">Serial devices
- <itemizedlist>
- <listitem>
- <para>Belkin F5U103 and F5U120 (ubsa driver)</para>
- </listitem>
- <listitem>
- <para>e-Tek Labs Kwik232 (ubsa driver)</para>
- </listitem>
- <listitem>
- <para>GoHubs GoCOM232 (ubsa driver)</para>
- </listitem>
- <listitem>
- <para>HP USB-Serial adapter (&man.uftdi.4; driver)</para>
- </listitem>
- <listitem>
- <para>Inland UAS111 (&man.uftdi.4; driver)</para>
- </listitem>
- <listitem>
- <para>Peracom single port serial adapter (ubsa driver)</para>
- </listitem>
- <listitem>
- <para>Prolific PL-2303 serial adapter (&man.uplcom.4; driver)</para>
- </listitem>
- <listitem>
- <para>QVS USC-1000 (&man.uftdi.4; driver)</para>
- </listitem>
- <listitem>
- <para>SUNTAC Slipper U VS-10U (&man.uvscom.4; driver)</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98">Scanners (through <application>SANE</application>) (&man.uscanner.4; driver)
- <itemizedlist>
- <listitem>
- <para>Perfection 636U</para>
- </listitem>
- <listitem>
- <para>HP ScanJet 4100C, 5200C, 6300C</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386,pc98,alpha">Storage (&man.umass.4; driver)
- <itemizedlist>
- <listitem>
- <para>ADTEC Stick Drive AD-UST32M, 64M, 128M, 256M</para>
- </listitem>
- <listitem>
- <para>Denno FireWire/USB2 Removable
- 2.5-inch HDD Case MIFU-25CB20</para>
- </listitem>
- <listitem>
- <para>FujiFilm Zip USB Drive ZDR100 USB A</para>
- </listitem>
- <listitem>
- <para>GREEN HOUSE USB Flash Memory <quote>PicoDrive</quote>
- GH-UFD32M, 64M, 128M</para>
- </listitem>
- <listitem>
- <para>IBM 32MB USB Memory Key (P/N 22P5296)</para>
- </listitem>
- <listitem>
- <para>IBM ThinkPad USB Portable CD-ROM Drive (P/N 33L5151)</para>
- </listitem>
- <listitem>
- <para>I-O DATA USB x6 CD-RW Drive CDRW-i64/USB (CDROM only)</para>
- </listitem>
- <listitem>
- <para>I-O DATA USB CD/CD-R/CD-RW/DVD-R/DVD-RW/DVD-RAM/DVD-ROM Drive DVR-iUH2
- (CDROM, DVD-RAM only)</para>
- </listitem>
- <listitem arch="i386,pc98">
- <para>Iomega USB Zip 100Mb (primitive support still)</para>
- </listitem>
- <listitem>
- <para>Iomega Zip750 USB2.0 Drive</para>
- </listitem>
- <listitem>
- <para>Keian USB1.1/2.0 3.5-inch HDD Case KU350A</para>
- </listitem>
- <listitem>
- <para>Kurouto Shikou USB 2.5-inch HDD Case GAWAP2.5PS-USB2.0</para>
- </listitem>
- <listitem>
- <para>Logitec USB1.1/2.0 HDD Unit SHD-E60U2</para>
- </listitem>
- <listitem>
- <para>Logitec Mobile USB Memory LMC-256UD</para>
- </listitem>
- <listitem>
- <para>Logitec USB Double-Speed Floppy Drive LFD-31U2</para>
- </listitem>
- <listitem>
- <para>Logitec USB/IEEE1394 DVD-RAM/R/RW Unit LDR-N21FU2 (CDROM only)</para>
- </listitem>
- <listitem>
- <para>Matshita CF-VFDU03 floppy drive</para>
- </listitem>
- <listitem>
- <para>MELCO USB2.0 MO Drive MO-CH640U2</para>
- </listitem>
- <listitem>
- <para>I-O DATA USB/IEEE1394 Portable HD Drive HDP-i30P/CI, HDP-i40P/CI</para>
- </listitem>
- <listitem>
- <para>MELCO USB Flash Disk <quote>PetitDrive</quote>,
- RUF-32M, -64M, -128M, -256M</para>
- </listitem>
- <listitem>
- <para>MELCO USB2.0 Flash Disk <quote>PetitDrive2</quote>,
- RUF-256M/U2, -512M/U2</para>
- </listitem>
- <listitem>
- <para>MELCO USB Flash Disk <quote>ClipDrive</quote>,
- RUF-C32M, -C64M, -C128M, -C256M, -C512M</para>
- </listitem>
- <listitem>
- <para>Microtech USB-SCSI-HD 50 USB to SCSI cable</para>
- </listitem>
- <listitem>
- <para>NOVAC USB2.0 2.5/3.5-inch HDD Case NV-HD351U</para>
- </listitem>
- <listitem>
- <para>Panasonic floppy drive</para>
- </listitem>
- <listitem>
- <para>Panasonic USB2.0 Portable CD-RW Drive KXL-RW40AN (CDROM only)</para>
- </listitem>
- <listitem>
- <para>RATOC Systems USB2.0 Removable HDD Case U2-MDK1, U2-MDK1B</para>
- </listitem>
- <listitem>
- <para>Sony Portable CD-R/RW Drive CRX10U (CDROM only)</para>
- </listitem>
- <listitem>
- <para>TEAC Portable USB CD-ROM Unit CD-110PU/210PU</para>
- </listitem>
- <listitem>
- <para>Y-E Data floppy drive (720/1.44/2.88Mb)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">Audio Devices (uaudio driver)
- <itemizedlist>
- <listitem>
- <para>Audio-Technica USB Digital Headphone ATC-HA4USB</para>
- </listitem>
-
- <listitem>
- <para>Ergo Systems AUDIOTRAK OPTOPlay USB</para>
- </listitem>
-
- <listitem>
- <para>KENWOOD MD Personal Stereo System MDX-G7</para>
- </listitem>
-
- <listitem>
- <para>KENWOOD/SOTEC VH-7PC</para>
- </listitem>
-
- <listitem>
- <para>I-O DATA Analog to Digital USB Audio Adapter DAVOX</para>
- </listitem>
-
- <listitem>
- <para>ONKYO PC Speaker GX-R5U(W)</para>
- </listitem>
-
- <listitem>
- <para>ONKYO USB Digital Audio Processor SE-U55X(S)</para>
- </listitem>
-
- <listitem>
- <para>Roland UA-5 USB Audio Interface <quote>Audio Capture</quote></para>
- </listitem>
-
- <listitem>
- <para>Sony PC Active Speaker System SRS-T100PC</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">Handspring Visor and other PalmOS
- devices (&man.uvisor.4; driver)
- <itemizedlist>
- <listitem>
- <para>Handspring Visor</para>
- </listitem>
- <listitem>
- <para>Palm M125, M500, M505</para>
- </listitem>
- <listitem>
- <para>Sony Clie 4.0 and 4.1</para>
- </listitem>
- </itemizedlist>
- </para>
- </sect2>
-
- <sect2 id="firewire">
- <title>IEEE 1394 (Firewire) Devices</title>
-
- <para arch="i386,sparc64">Host Controllers (&man.fwohci.4;
- driver)
-
- <itemizedlist>
- <listitem>
- <para>Ricoh R5C552 chipset</para>
- </listitem>
- <listitem>
- <para>Sony CX3022 chipset</para>
- </listitem>
- <listitem>
- <para>TI TSB12LV22, LV23, 26 and TSB43AA22 chipsets</para>
- </listitem>
- <listitem>
- <para>uPD72861 chipset</para>
- </listitem>
- <listitem>
- <para>VIA VT6306 chipset</para>
- </listitem>
- </itemizedlist>
-
- </para>
-
- <para arch="i386,sparc64">Storage (&man.sbp.4; driver)
-
- <itemizedlist>
- <listitem>
- <para>Apple iPod</para>
- </listitem>
- <listitem>
- <para>Apple Macintosh G4 (target mode)</para>
- </listitem>
- </itemizedlist>
-
- </para>
-
- </sect2>
-
- <sect2 id="bluetooth">
- <title>Bluetooth Devices</title>
-
- <para arch="i386,pc98">PCCARD Host Controllers (&man.ng.bt3c.4; driver)
- <itemizedlist>
- <listitem>
- <para>3Com/HP 3CRWB6096-A PCCARD adapter</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">USB Host Controllers (&man.ng.ubt.4; driver)
- <itemizedlist>
- <listitem>
- <para>3Com 3CREB96</para>
- </listitem>
- <listitem>
- <para>EPoX BT-DG02</para>
- </listitem>
- <listitem>
- <para>Mitsumi USB Bluetooth adapter</para>
- </listitem>
- <listitem>
- <para>MSI MS-6967</para>
- </listitem>
- <listitem>
- <para>TDK Bluetooth USB adapter</para>
- </listitem>
- </itemizedlist>
- </para>
-
- </sect2>
-
- <sect2>
- <title>Cryptographic Accelerators</title>
-
- <para arch="i386,pc98">Accelerators based on
- the Hifn 7751, 7811, or 7951 chipsets (&man.hifn.4; driver)
-
- <itemizedlist>
- <listitem>
- <para>Invertex AEON</para>
- </listitem>
- <listitem>
- <para>Hifn 7751 reference board</para>
- </listitem>
- <listitem>
- <para>Global Technologies Group PowerCrypt and XL-Crypt</para>
- </listitem>
- <listitem>
- <para>NetSec 7751</para>
- </listitem>
- <listitem>
- <para>Soekris Engineering vpn1201 and vpn1211</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98">Accelerators based on
- the Bluesteel 5501 or 5601 chipsets (&man.ubsec.4;
- driver)</para>
-
- <para arch="i386,pc98">Accelerators based on
- the Broadcom BCM5801, BCM5802, BCM5805, BCM5820, BCM 5821,
- BCM5822 chipsets (&man.ubsec.4; driver)</para>
-
- </sect2>
-
- <sect2>
- <title>Miscellaneous</title>
-
- <para arch="i386,pc98">FAX-Modem/PCCARD
- <itemizedlist>
- <listitem>
- <para>MELCO IGM-PCM56K/IGM-PCM56KH</para>
- </listitem>
- <listitem>
- <para>Nokia Card Phone 2.0 (gsm900/dcs1800 HSCSD terminal)</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386,pc98,alpha">Floppy drives (&man.fdc.4; driver)</para>
- <para arch="i386">Genius and Mustek hand scanners</para>
- <para arch="i386">GPB and Transputer drivers</para>
-
- <para arch="i386,alpha,ia64">VGA-compatible video cards
- (&man.vga.4; driver)
-
- <note>
- <para>Information regarding specific video cards and
- compatibility with <application>XFree86</application> can be
- found at <ulink
- url="http://www.xfree86.org/"></ulink>.</para>
- </note>
-
- </para>
-
- <para arch="i386,pc98,alpha,ia64">Keyboards including:
- <itemizedlist>
- <listitem arch="i386,alpha">
- <para>AT-style keyboards (&man.atkbd.4; driver)</para>
- </listitem>
- <listitem arch="i386,alpha,ia64">
- <para>PS/2 keyboards (&man.atkbd.4; driver)</para>
- </listitem>
- <listitem arch="pc98">
- <para>Standard keyboards</para>
- </listitem>
- <listitem arch="i386,pc98,alpha">
- <para>USB keyboards (specific instances are listed in the
- section describing <link linkend="usb">USB devices</link>)</para>
- </listitem>
- </itemizedlist>
- </para>
- <para arch="i386">Loran-C receiver (Dave Mills experimental hardware, loran driver).</para>
- <para arch="i386,pc98,alpha,ia64">Pointing devices including:
- <itemizedlist>
- <listitem arch="i386,pc98">
- <para>Bus mice and compatible devices (&man.mse.4; driver)</para>
- </listitem>
- <listitem arch="i386,alpha,ia64">
- <para>PS/2 mice and compatible devices, including many laptop
- pointing devices (&man.psm.4; driver)</para>
- </listitem>
- <listitem>
- <para>Serial mice and compatible devices</para>
- </listitem>
- <listitem arch="i386,pc98,alpha">
- <para>USB mice (specific instances are listed in the
- section describing <link linkend="usb">USB devices</link>)</para>
- </listitem>
- </itemizedlist>
-
- <note>
- <para>&man.moused.8; has more information on using pointing
- devices with &os;. Information on using pointing devices
- with <application>XFree86</application> can be found at
- <ulink url="http://www.xfree86.org/"></ulink>.</para>
- </note>
- </para>
-
- <para arch="i386,alpha"><quote>PC standard</quote> parallel ports (&man.ppc.4; driver)</para>
- <para arch="pc98"><quote>PC-9821 standard</quote> parallel ports (&man.ppc.4; driver)</para>
-
- <para arch="i386">PC-compatible joysticks (&man.joy.4; driver)</para>
-
- <para arch="pc98">Joystick port of SoundBlaster(98) (&man.joy.4
- driver)</para>
-
- <para arch="i386,pc98">PHS Data Communication Card/PCCARD
- <itemizedlist>
- <listitem>
- <para>NTT DoCoMo P-in Comp@ct</para>
- </listitem>
- <listitem>
- <para>Panasonic KX-PH405</para>
- </listitem>
- <listitem>
- <para>SII MC-P200</para>
- </listitem>
- </itemizedlist>
- </para>
-
- <para arch="i386">Xilinx XC6200-based reconfigurable hardware cards compatible
- with the HOT1 from <ulink url="http://www.vcc.com/">Virtual
- Computers</ulink> (xrpu driver).</para>
-
- <para arch="pc98">Power Management Controller of NEC PC-98 Note (pmc
- driver)</para>
-
- <para arch="sparc64">OpenFirmware console (ofwcons driver)</para>
-
- </sect2>
-</sect1>
diff --git a/release/doc/en_US.ISO8859-1/relnotes/article.sgml b/release/doc/en_US.ISO8859-1/relnotes/article.sgml
deleted file mode 100644
index c9a3cc997ba9..000000000000
--- a/release/doc/en_US.ISO8859-1/relnotes/article.sgml
+++ /dev/null
@@ -1,1088 +0,0 @@
-<articleinfo>
- <title>&os;/&arch; &release.current; Release Notes</title>
-
- <corpauthor>The FreeBSD Project</corpauthor>
-
- <pubdate>$FreeBSD$</pubdate>
-
- <copyright>
- <year>2000</year>
- <year>2001</year>
- <year>2002</year>
- <year>2003</year>
- <holder role="mailto:doc@FreeBSD.org">The FreeBSD Documentation Project</holder>
- </copyright>
-
- <abstract>
- <para>The release notes for &os; &release.current; contain a summary
- of
-<![ %include.historic; [
- the changes made to the &os; base system since &release.prev;.
-]]>
-<![ %no.include.historic; [
- recent changes made to the &os; base system on the &release.branch;
- development branch.
-]]>
- This document lists applicable security advisories that were issued since
- the last release, as well as significant changes to the &os;
- kernel and userland.
- Some brief remarks on upgrading are also presented.</para>
- </abstract>
-</articleinfo>
-
-<sect1 id="intro">
- <title>Introduction</title>
-
- <para>This document contains the release notes for &os;
- &release.current; on the &arch.print; hardware platform. It
- describes recently added, changed, or deleted features of &os;.
- It also provides some notes on upgrading
- from previous versions of &os;.</para>
-
-<![ %release.type.snapshot [
-
- <para>The &release.type; distribution to which these release notes
- apply represents a point along the &release.branch; development
- branch between &release.prev; and the future &release.next;. Some
- pre-built, binary &release.type; distributions along this branch
- can be found at <ulink url="&release.url;"></ulink>.</para>
-
-]]>
-
-<![ %release.type.release [
-
- <para>This distribution of &os; &release.current; is a
- &release.type; distribution. It can be found at <ulink
- url="&release.url;"></ulink> or any of its mirrors. More
- information on obtaining this (or other) &release.type;
- distributions of &os; can be found in the <ulink
- url="http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/handbook/mirrors.html"><quote>Obtaining
- FreeBSD</quote> appendix</ulink> to the <ulink
- url="http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/handbook/">FreeBSD
- Handbook</ulink>.</para>
-
-]]>
-
- <para>Users who are new to the &release.branch; series of &os;
- &release.type;s should also read the <quote>Early Adopters Guide
- to &os; &release.current;</quote>. This document can generally be
- found in the same location as the release notes (either as a part of a
- &os; distribution or on the &os; Web site). It contains important
- information regarding the advantages and disadvantages of using
- &os; &release.current;, as opposed to releases based on the &os;
- 4-STABLE development branch.</para>
-
- <para>All users are encouraged to consult the release errata before
- installing &os;. The errata document is updated with
- <quote>late-breaking</quote> information discovered late in the
- release cycle or after the release. Typically, it contains
- information on known bugs, security advisories, and corrections to
- documentation. An up-to-date copy of the errata for &os;
- &release.current; can be found on the &os; Web site.</para>
-
-</sect1>
-
-<sect1 id="new">
- <title>What's New</title>
-
- <para>This section describes
-<![ %include.historic; [
- the most user-visible new or changed features in &os;
- since &release.prev;.
- In general, changes described here are unique to the &release.branch;
- branch unless specifically marked as &merged; features.
-]]>
-<![ %no.include.historic; [
- many of the user-visible new or changed features in &os;
- since &release.prev;. It includes items that are unique to the
- &release.branch; branch, as well as some features that may have been
- recently merged to
- other branches (after &os; &release.prev.historic;). The latter
- items are marked as &merged;.
-]]>
- </para>
-
- <para>Typical release note items
- document recent security advisories issued after
- &release.prev.historic;,
- new drivers or hardware support, new commands or options,
- major bug fixes, or contributed software upgrades. They may also
- list changes to major ports/packages or release engineering
- practices. Clearly the release notes cannot list every single
- change made to &os; between releases; this document focuses
- primarily on security advisories, user-visible changes, and major
- architectural improvements.</para>
-
- <sect2 id="security">
- <title>Security Advisories</title>
-
- <para>A remotely exploitable vulnerability in
- <application>CVS</application> has been corrected with the
- import of version 1.11.5. More details can be found in security
- advisory <ulink
- url="ftp://ftp.FreeBSD.org/pub/FreeBSD/CERT/advisories/FreeBSD-SA-03:01.cvs.asc">FreeBSD-SA-03:01</ulink>.
- &merged;</para>
-
- <para>A timing-based attack on <application>OpenSSL</application>,
- which could allow a very powerful attacker access to plaintext
- under certain circumstances, has been prevented via an upgrade
- to <application>OpenSSL</application> 0.9.7. See security
- advisory <ulink
- url="ftp://ftp.FreeBSD.org/pub/FreeBSD/CERT/advisories/FreeBSD-SA-03:02.openssl.asc">FreeBSD-SA-03:02</ulink>
- for more details. &merged;</para>
-
- <para>The security and performance of the
- <quote>syncookies</quote> feature has been improved to decrease
- the chance of an attacker being able to spoof connections.
- More details are given in security advisory <ulink
- url="ftp://ftp.FreeBSD.org/pub/FreeBSD/CERT/advisories/FreeBSD-SA-03:03.syncookies.asc">FreeBSD-SA-03:03</ulink>. &merged;</para>
-
- <para>Remotely-exploitable buffer overflow vulnerabilities in
- <application>sendmail</application> have been fixed by updating
- <application>sendmail</application>. For more
- details, see security advisory <ulink
- url="ftp://ftp.FreeBSD.org/pub/FreeBSD/CERT/advisories/FreeBSD-SA-03:04.sendmail.asc">FreeBSD-SA-03:04</ulink>
- and <ulink
- url="ftp://ftp.FreeBSD.org/pub/FreeBSD/CERT/advisories/FreeBSD-SA-03:07.sendmail.asc">FreeBSD-SA-03:07</ulink>.
- &merged;</para>
-
- <para>A bounds-checking bug in the XDR implementation, which could
- allow a remote attacker to cause a denial-of-service, has been
- fixed. For more details see security advisory <ulink
- url="ftp://ftp.FreeBSD.org/pub/FreeBSD/CERT/advisories/FreeBSD-SA-03:05.xdr.asc">FreeBSD-SA-03:05</ulink>.
- &merged;</para>
-
- <para>Two recently-publicized flaws in
- <application>OpenSSL</application> have been corrected. For
- more details, see security advisory <ulink
- url="ftp://ftp.FreeBSD.org/pub/FreeBSD/CERT/advisories/FreeBSD-SA-03:06.openssl.asc">FreeBSD-SA-03:06</ulink>.
- &merged;</para>
-
- </sect2>
-
- <sect2 id="kernel">
- <title>Kernel Changes</title>
-
- <para arch="pc98">Support for the CanBe power management
- controller has been added. &merged;</para>
-
- <para>&man.devfs.5; is now mandatory; the
- <literal>NODEVFS</literal> option has been removed from the set of
- possible kernel configuration options.</para>
-
- <para arch="i386,ia64,pc98">An &man.ehci.4; driver has been added; it supports
- the USB Enhanced Host Controller Interface used by USB 2.0
- controllers.</para>
-
- <para>A minor bug in the permissions handling of
- <filename>/dev/tty</filename> has been fixed. As a result,
- &man.ssh.1; can now be used after &man.su.1;.</para>
-
- <para>A bug that caused &man.fstat.2; to return
- <literal>0</literal> as the number of bytes available to read
- from a TCP socket has been fixed.</para>
-
- <para>A bug that caused &man.kqueue.2; to report
- <literal>0</literal> as the number of bytes available to read
- from a TCP socket has been fixed. The
- <literal>NOTE_LOWAT</literal> flag for
- <literal>EVFILT_READ</literal> has been fixed.</para>
-
- <para>Linux emulation mode now supports IPv6.</para>
-
- <para>&man.madvise.2; now supports a
- <literal>MADV_PROTECT</literal> behavior, which informs the
- virtual memory system that a process is critical and should not
- be killed when swap space has been exhausted. The process must
- be owned by the superuser.</para>
-
- <para arch="i386,pc98">The tw driver for TW-523 power line
- interfaces (used by X-10 home control products) has been
- removed. It is currently non-functional, and would require a
- considerable amount of work to make it work under
- &release.branch;. The xten and xtend userland control programs
- have also been removed.</para>
-
- <!-- Above this line, sort kernel changes by manpage/keyword-->
-
- <para>A second process scheduler, designed to be a general purpose
- scheduler with many SMP benefits, has been added to the scheduler
- framework. Exactly one scheduler must be specified in a kernel
- configuration. The original scheduler may be selected using
- <literal>options&nbsp;SCHED_4BSD</literal>. The newer
- (experimental) scheduler can be selected by using
- <literal>options&nbsp;SCHED_ULE</literal>.</para>
-
- <para>Device major numbers are now allocated dynamically by
- default. This change greatly decreases the need for a static,
- centralized table of major number assignments to device drivers
- (a few drivers retain their old static major numbers for
- compatibility), and also reduces the possibility of running out
- of device major numbers.</para>
-
- <para arch="i386,pc98">A partial lazy switch mechanism for
- in-kernel threads has been implemented; it is designed to reduce
- the overhead of short context switches (such as for interrupt
- handlers) that do not involve another process. This feature can
- be enabled with
- <literal>options&nbsp;LAZY_SWITCH</literal>.</para>
-
- <sect3 id="proc">
- <title>Processor/Motherboard Support</title>
-
- <para arch="i386"><literal>SMP</literal> kernels now have
- rudimentary support for HyperThreading (HTT). The scheduler
- treats the logical CPUs as if they were additional physical
- CPUs. This can actually cause suboptimal performance in some
- cases due to contention for resources. Therefore, logical
- CPUs are halted by default at startup. They can be enabled
- with the <varname>machdep.hlt_logical_cpus</varname> sysctl
- variable. It is also possible to halt any CPU in the idle
- loop with the <varname>machdep.hlt_cpus</varname> sysctl
- variable. The &man.smp.4; manual page has more details.
-
- <note>
- <para>Some other versions of &os;, including early
- 5.0-CURRENT snapshots and 4.8-RELEASE, used
- <literal>options&nbsp;HTT</literal> to enable
- HyperThreading support at kernel configuration time. This
- option is no longer necessary.</para>
- </note>
-
- </para>
-
- <para arch="i386">Support for the Physical Address Extensions
- (PAE) capability on Intel Pentium Pro and higher processors
- has been added. This allows the use of up to 64GB of RAM in a
- machine, although the amount of memory usable by any single
- process (or the &os; kernel) is unchanged. For more
- information, see the &man.pae.4; manual page. Work on this
- feature was sponsored by DARPA and Network Associates
- Laboratories.</para>
-
- <para arch="i386">A new &man.vpd.4; driver has been added to
- read hardware information from the Vital Product Data structure
- on IBM ThinkPad machines.</para>
-
- </sect3>
-
- <sect3 id="boot">
- <title>Boot Loader Changes</title>
-
- <para arch="alpha">The alpha boot loader
- (<filename>boot1</filename>) can now be called
- <filename>boot</filename> for consistency with other
- platforms.</para>
-
- <para arch="i386,pc98">The two parts of the boot loader
- (<filename>boot1</filename> and <filename>boot2</filename>)
- have been combined into a single <filename>boot</filename>
- file, to simplify programs that need to write or otherwise
- manipulate the boot loader.</para>
-
- <para arch="pc98">The PC98 boot loader now has support for
- booting from SCSI MO media. &merged;</para>
-
- <para>The <filename>/modules</filename> directory (once the
- default location for modules on &os; 4.<replaceable>X</replaceable>) is no longer a
- part of the default <varname>kern.module_path</varname>.
- Third-party modules should be placed in
- <filename>/boot/modules</filename>.
-
- <note>
- <para>Modules designed for use with &os; 4.<replaceable>X</replaceable> are likely to
- panic when loaded into a &os; &release.current; kernel and should be used with extreme caution.</para>
- </note>
- </para>
-
- <para arch="i386">Due to code size limitations, the i386 boot
- loader can only load kernels from root file systems that are
- 1.5TB or smaller in size.</para>
-
- <!-- Above this line, order boot loader changes by keyword-->
-
- </sect3>
-
- <sect3 id="net-if">
- <title>Network Interface Support</title>
-
- <para arch="i386,pc98">A new &man.axe.4; network driver has been
- added. It provides support for USB Ethernet adapters based on
- the ASIX Electronics AX88172 USB 2.0 chipset.</para>
-
- <para>The cm driver now supports IPX. &merged;</para>
-
- <para arch="i386,pc98">The &man.rue.4; network driver has been added,
- providing support for Ethernet adapters based on the RealTek
- RTL8150 USB to Fast Ethernet controller chip.</para>
-
- <para arch="i386">The &man.sbsh.4; driver for the Granch SBNI16
- SHDSL modem has been added. &merged;</para>
-
- <para>A new &man.wlan.4; module provides 802.11 link-layer support. The
- &man.wi.4; and &man.an.4; drivers now use this facility.</para>
-
- <para arch="i386,alpha,pc98,sparc64">A timing bug in the
- &man.xl.4; driver, which could cause a kernel panic (or other
- problems) when configuring an interface, has been
- fixed.</para>
-
- </sect3>
-
- <sect3 id="net-proto">
- <title>Network Protocols</title>
-
- <para>&man.ipfw.4; <literal>skipto</literal> rules can once
- again be used with the <literal>log</literal> keyword.
- &man.ipfw.4; <literal>uid</literal> rules are once again
- working.</para>
-
- <para>It is now possible to build the
- <literal>FAST_IPSEC</literal> and <literal>INET6</literal>
- options into the same kernel. (They still cannot be used
- together, however.)</para>
-
- <para>A bug in TCP NewReno, which caused premature exit from
- fast recovery when NewReno was enabled, has been
- fixed. &merged;</para>
-
- <para>TCP now has support for the <quote>Limited
- Transmit</quote> mechanism proposed by RFC 3042. This feature
- is intended to improve the effectiveness of TCP loss recovery
- in certain circumstances. It is off by default but can be
- enabled with the <varname>net.inet.tcp.rfc3042</varname>
- sysctl variable. More information can be found in
- &man.tcp.4;.</para>
-
- <para>TCP now has support for increased initial congestion
- window sizes as described in RFC 3390. This feature can
- improve the throughput of short transfers, as well as
- high-bandwidth, large propagation-delay connections. It is
- off by default but can be enabled with the
- <varname>net.inet.tcp.rfc3390</varname> sysctl variable. More
- information can be found in &man.tcp.4;.</para>
-
- <para>The IP fragment reassembly code behaves more gracefully
- when receiving a large number of packet fragments (it is
- designed to be more resistant to fragment-based denial of
- service attacks). &merged;</para>
-
- <para>TCP connections in the <literal>TIME_WAIT</literal> state
- now use a special protocol control block that uses less space
- than a full-blown TCP PCB. This allows some of the data
- structures and resources used by such a connection to be freed
- earlier.</para>
-
- <para>It is now possible to specify the range of
- <quote>privileged ports</quote> (TCP and UDP ports that
- require superuser access to &man.bind.2; to). The range is
- now specified with the
- <varname>net.inet.ip.portrange.reservedlow</varname> and
- <varname>net.inet.ip.portrange.reservedhigh</varname> sysctl
- variables, defaulting to the traditional UNIX behavior. This
- feature is intended to help network servers bind
- to traditionally privileged ports without requiring superuser
- access. &man.ip.4; has more details.</para>
-
- <para>Some bugs in the non-blocking RPC code has been fixed. As
- a result, &man.amd.8; users are now able to mount volumes from
- a &release.current; server.</para>
-
- <para>Support for XNS networking, which has not worked
- correctly for almost seven years, has been removed.</para>
-
- </sect3>
-
- <sect3 id="disks">
- <title>Disks and Storage</title>
-
- <para>The &man.aac.4; driver now runs free of the Giant kernel
- lock. This change has given a nearly 20% performance speedup
- on an SMP system running multiple I/O intensive loads.</para>
-
- <para>The &man.ata.4; driver now supports all known SiS
- chipsets. (More details can be found in the Hardware
- Notes.)</para>
-
- <para>The &man.ata.4; driver now supports the Promise SATA150
- TX2 and TX4 Serial ATA/150 controllers.</para>
-
- <para>The &man.ata.4; driver now flushes devices on shutdown.
- This change may result in failure messages being printed on
- the console for devices that do not support flushing.</para>
-
- <para>The CAM layer now has support for devices with more than
- 2<superscript>32</superscript> blocks. (Assuming 512-byte
- blocks, this means support for devices larger than 2TB.)
-
- <note>
- <para>For users upgrading across this change, note that all
- userland applications that talk to &man.pass.4; or
- &man.xpt.4; devices must be recompiled. Examples of such
- programs are &man.camcontrol.8; in the base system,
- the <filename role="port">sysutils/cdrtools</filename>
- port, and the
- <filename role="port">multimedia/xmms</filename> port.</para>
- </note>
-
- </para>
-
- <para>A number of changes have been made to the &man.cd.4;
- driver. The primary user-visible change is improved
- compatibility with ATAPI/USB/Firewire CDROM drives.</para>
-
- <para>&man.geom.4; is now mandatory; the
- <literal>NO_GEOM</literal> has been removed from the set of
- kernel configuration options.</para>
-
- <para>The &man.iir.4; driver has been updated; this update is
- believed to fix problems detecting attached disks during
- installation.</para>
-
- <para arch="i386">The ips driver, which supports the IBM (now
- Adaptec) ServeRAID series, has been added.</para>
-
- <para>A bug in the &man.mly.4; driver that caused hangs has been
- corrected.</para>
-
- <para>Support has been added for volume labels on UFS and UFS2
- file systems. These labels are strings that can be used to
- identify a volume, regardless of what device it appears on.
- Labels can be set with the <option>-L</option> options to
- &man.newfs.8; or &man.tunefs.8;. With the
- <literal>GEOM_VOL</literal> module, volumes can be accessed
- using their labels under <filename>/dev/vol</filename>.</para>
-
- <para>The root file system can now be located on a &man.vinum.4;
- volume. More information can be found in the &man.vinum.4;
- manual page.</para>
-
- <para arch="pc98">The wfd and wst drivers, which have been
- broken for some time, have been removed.</para>
-
- </sect3>
-
- <sect3 id="fs">
- <title>File Systems</title>
-
- <para>A new <literal>DIRECTIO</literal> kernel option enables
- support for read operations that bypass the buffer cache and
- put data directly into a userland buffer. This feature
- requires that the <literal>O_DIRECT</literal> flag is set on
- the file descriptor and that both the offset and length for
- the read operation are multiples of the physical media sector
- size. &merged;</para>
-
- <para>NETNCP and Netware File System Support (nwfs) are once
- again working.</para>
-
- <para>Bugs that could cause the unmounting of a smbfs share to
- fail or cause a kernel panic have been fixed.</para>
-
- </sect3>
-
- <sect3 id="pccard">
- <title>PCCARD Support</title>
-
- <para></para>
- </sect3>
-
- <sect3 id="mm">
- <title>Multimedia Support</title>
-
- <para arch="i386,pc98">The <filename>atspeaker.ko</filename> and
- <filename>pcspeaker.ko</filename> modules for the
- &man.speaker.4; device have been renamed
- <filename>speaker.ko</filename>.</para>
- </sect3>
-
- </sect2>
-
- <sect2 id="userland">
- <title>Userland Changes</title>
-
- <para>&man.adduser.8; now correctly handles setting user passwords
- containing special shell characters.</para>
-
- <para>&man.adduser.8; now supports a <option>-g</option> option to
- set a user's default login group.</para>
-
- <para>The &man.bsdlabel.8; utility is a replacement for the older
- disklabel utility. Like its predecessor, it installs, examines,
- or modifies the BSD label on a disk partition, and can install
- bootstrap code. Compared to disklabel, a number of obsolete
- options and parameters have been retired. A new
- <option>-m</option> option instructs &man.bsdlabel.8; to use the
- layout suitable for a specific machine.</para>
-
- <para arch="alpha,i386">The <filename>compat4x</filename>
- distribution now includes the
- <filename>libcrypto.so.2</filename>,
- <filename>libgmp.so.3</filename>, and
- <filename>libssl.so.2</filename> libraries from &os;
- 4.7-RELEASE.</para>
-
- <para>&man.chgrp.1 and &man.chown.8 now, when the owner/group is
- modified, print the old and new uid/gid if the
- <option>-v</option> option is specified more than once.</para>
-
- <para>&man.config.8; now implements a <literal>nodevice</literal>
- kernel configuration file directive that cancels the effect of a
- <literal>device</literal> directive. The new
- <literal>nooption</literal> and <literal>nomakeoption</literal>
- directives cancel prior <literal>options</literal> and
- <literal>makeoptions</literal> directives, respectively.</para>
-
- <para>The &man.diskinfo.8; utility has been added to show
- information about a disk device and optionally to run a naive
- performance test.</para>
-
- <para>The disklabel utility has been replaced by &man.bsdlabel.8;.
- On the alpha, i386, and pc98 platforms, disklabel is a link to
- &man.bsdlabel.8;.</para>
-
- <para>&man.dump.8; now supports caching of disk blocks with the
- <option>-C</option> option. This can improve dump performance
- at the cost of possibly missing file system updates that occur
- between passes.</para>
-
- <para>&man.dumpfs.8; now supports a <option>-m</option> flag to
- print file system parameters in the form of a &man.newfs.8;
- command.</para>
-
- <para>&man.elfdump.1;, a utility to display information about &man.elf.5;
- format executable files, has been added.</para>
-
- <para>&man.fetch.1; uses the <filename>.netrc</filename> support
- in &man.fetch.3; and also supports a <option>-N</option> to
- specify an alternate <filename>.netrc</filename> file.</para>
-
- <para>&man.fetch.3; now has support for
- <filename>.netrc</filename> files (see &man.ftp.1; for more
- details).</para>
-
- <para>&man.ftpd.8; now supports a <option>-h</option> option to
- disable printing any host-specific information, such as the
- &man.ftpd.8; version or hostname, in server messages.
- &merged;</para>
-
- <para>&man.ftpd.8; now supports a <option>-P</option> option to
- specify a port on which to listen in daemon mode. The default
- data port number is now set to be one less than the control port
- number, rather than being hard-coded. &merged;</para>
-
- <para>&man.ftpd.8; now supports an extended format of the
- <filename>/etc/ftpchroot</filename> file. Please refer
- to the &man.ftpchroot.5; manpage, which is now available,
- for details. &merged;</para>
-
- <para>&man.ftpd.8; now supports login directory pathnames
- that specify simultaneously a directory for &man.chroot.2;
- and that to change to in the chrooted environment. The
- <literal>/./</literal> separator is used for
- this purpose, like in other FTP daemons having this feature.
- It may be used in both &man.ftpchroot.5; and &man.passwd.5;.
- &merged;</para>
-
- <para>&man.fwcontrol.8; now supports <option>-R</option> and
- <option>-S</option> options for receiving and sending DV
- streams. &merged;</para>
-
- <para>The &man.gstat.8; utility has been added to show the disk
- activity inside the &man.geom.4; subsystem.</para>
-
- <para>&man.ipfw.8; now supports <literal>enable</literal> and
- <literal>disable</literal> commands to control various aspects
- of the operation of &man.ipfw.4; (including enabling and
- disabling the firewall itself). These provide a more convenient
- and visible interface than the existing sysctl
- variables. &merged;</para>
-
- <para>&man.jail.8; now supports a <option>-i</option> flag to
- output an identifier for a newly-created jail.</para>
-
- <para>The &man.jexec.8; utility has been added to execute a
- command inside an existing jail.</para>
-
- <para>The &man.jls.8; utility has been added to list existing
- jails.</para>
-
- <para>&man.kenv.1; has been moved from
- <filename>/usr/bin</filename> to <filename>/bin</filename> to
- make it available at times during system startup when only the
- root file system is mounted.</para>
-
- <para>&man.killall.1; now supports a <option>-j</option> option to
- kill all processes inside a jail.</para>
-
- <para>The &man.libgeom.3; library has been added to allow some
- userland access to the &man.geom.4; subsystem.</para>
-
- <para>The mac_portacl MAC policy module has been added. It
- provides a simple ACL mechanism to permit users and groups to
- bind ports for TCP or UDP, and is intended to be used in
- conjunction with the recently-added
- <varname>net.inet.ip.portrange.reservedhigh</varname> sysctl.</para>
-
- <para>The <filename>MAKEDEV</filename> script is now unnecessary, due to the mandatory
- presence of &man.devfs.5;, and has been removed.</para>
-
- <para>&man.mergemaster.8; now supports a <option>-P</option>
- option to preserve the contents of files being replaced.</para>
-
- <para>&man.mixer.8; can now implement relative volume
- adjustments.</para>
-
- <para>The &man.mksnap.ffs.8; program has been added to allow
- easier creation of FFS snapshots. It is a
- SUID-<username>root</username> executable designed for use by
- members of the <groupname>operator</groupname> group.</para>
-
- <para>&man.mount.8; and &man.umount.8; now accept a
- <option>-F</option> option to specify an alternate &man.fstab.5;
- file.</para>
-
- <para>&man.mount.nfs.8; now supports a <option>-c</option> flag to
- avoid doing a &man.connect.2; for UDP mount points. This option
- must be used if the server does not reply to requests from the
- standard NFS port number 2049 or if it replies to requests using
- a different IP address (which can occur if the server is
- multi-homed). Setting the
- <varname>vfs.nfs.nfs_ip_paranoia</varname> sysctl to
- <literal>0</literal> will make this option the
- default. &merged;</para>
-
- <para>&man.mount.nfs.8; now supports the <option>noinet4</option>
- and <option>noinet6</option> mount options to prevent NFS mounts
- from using IPv4 or IPv6 respectively.</para>
-
- <para>&man.newfs.8; will now create UFS2 file systems by default,
- unless UFS1 is specifically requested with the
- <option>-O1</option> option.</para>
-
- <para>&man.newsyslog.8; has a number of new features. Among them:
-
- <itemizedlist>
- <listitem>
- <para>A <literal>W</literal> flag forces previously-started
- compression jobs for an entry (or group of entries
- specified with the <literal>G</literal> flag) to finish
- before beginning a new one. This feature is designed to
- prevent system overloads caused by starting several
- compression jobs on big files
- simultaneously. &merged;</para>
- </listitem>
-
- <listitem>
- <para>A <quote>default rotate action</quote>, to be used for
- files specified for rotation but not specified in the
- configuration file. &merged;</para>
- </listitem>
-
- <listitem>
- <para>A <option>-s</option> command-line flag to disable
- sending signals to processes when rotating
- files. &merged;</para>
- </listitem>
-
- <listitem>
- <para>A <literal>N</literal> configuration file flag to
- indicate that no process needs to be signaled when
- rotating a file. &merged;</para>
- </listitem>
-
- <listitem>
- <para>A <literal>U</literal> configuration file flag to
- specify that a process group (rather than a single
- process) should be signaled when rotating
- files. &merged;</para>
- </listitem>
-
- </itemizedlist>
-
- </para>
-
- <para>&man.nsdispatch.3; is now thread-safe and implements support
- for Name Service Switch (NSS) modules. NSS modules may be
- statically built into <filename>libc</filename> or dynamically
- loaded via &man.dlopen.3;. They are loaded/initialized at
- configuration time (i.e. when &man.nsdispatch.3; is called and
- &man.nsswitch.conf.5; is read or re-read).</para>
-
- <para>A new &man.pam.chroot.8; module has been added, which does a
- &man.chroot.2; operation for users into either a predetermined
- directory or one derived from their home directory.</para>
-
- <para>&man.pam.ssh.8; has been rewritten. One side effect of the
- rewrite is that it now starts a separate instance of
- &man.ssh-agent.1; for each session instead of trying to connect
- each session to the agent started by the first session.</para>
-
- <para>&man.ping.8; now supports a <option>-D</option> flag to set
- the <quote>Don't Fragment</quote> bit on outgoing packets.</para>
-
- <para>&man.ping.8; now supports a <option>-M</option> option to use
- ICMP mask request or timestamp request messages instead of ICMP
- echo requests.</para>
-
- <para>&man.ping.8; now supports a <option>-z</option> flag to set
- the Type of Service bits in outgoing packets.</para>
-
- <para>&man.pw.8; can now add a user whose name ends with a
- <literal>$</literal> character; this change is intended to help
- administration of <application>Samba</application>
- services. &merged;</para>
-
- <para>The format of the <filename>/etc/pwd.db</filename> and
- <filename>/etc/spwd.db</filename> password databases created by
- &man.pwd.mkdb.8; is now byte-order independent. The pre-processed
- password databases can now be moved between machines of
- different architectures. The format includes version numbers on
- entries to ensure compatibility with old binaries.</para>
-
- <para>A bug in &man.rand.3; that could cause a sequence to remain
- stuck at <literal>0</literal> has been fixed. (&man.rand.3;
- remains unsuitable for all but trivial uses.)</para>
-
- <para>&man.rtld.1; now has support for the dynamic mapping of
- shared object dependencies. This optional feature is especially
- useful when experimenting with different threading libraries.
- It is not, however, built by default. More information on
- enabling and using this feature can be found in
- &man.libmap.conf.5;.</para>
-
- <para>&man.sem.open.3; now correctly handles multiple opens of the
- same semaphore; as a result, &man.sem.close.3; no longer crashes
- calling programs.</para>
-
- <para>The seeding algorithm used by &man.srandom.3; has been
- strengthened.</para>
-
- <para arch="sparc64">The sunlabel utility, a program analogous to
- &man.bsdlabel.8; that works on Sun disk labels, has been
- added.</para>
-
- <para arch="i386,alpha,sparc64,ia64">&man.sysinstall.8; will now
- select UFS2 as the default layout for new file systems unless
- specifically requested in the disk labeler.
-
- <note arch="i386">
- <para>Due to i386 boot loader limitations, the root file system
- must be 1.5TB or smaller in size.</para>
- </note>
-
- </para>
-
- <para>The &man.swapoff.8; command has been added to disable paging
- and swapping on a device. A related &man.swapctl.8; command has
- been added to provide an interface to &man.swapon.8; and
- &man.swapoff.8; similar to other BSDs.
-
- <note>
- <para>The &man.swapoff.8; feature should be considered
- experimental.</para>
- </note>
- </para>
-
- <para>&man.syslogd.8; now allows multiple hosts or programs to be
- named in host or program specifications in &man.syslog.conf.5;
- files.</para>
-
- <para>&man.systat.1; now includes an <option>-ifstat</option>
- display mode that displays the network traffic going through
- active interfaces on the system.</para>
-
- <para>The &man.usbhidaction.1; command has been added; it performs
- actions according to its configuration in response to USB HID
- controls.</para>
-
- <para>&man.uudecode.1; and &man.b64decode.1; now support a
- <option>-r</option> flag for decoding raw (or broken) files that
- may be missing the initial and possibly final framing
- lines. &merged;</para>
-
- <para>&man.vmstat.8; has re-implemented the <option>-f</option>
- flag, which displays statistics on fork operations.</para>
-
- <para>&man.xargs.1; now supports a <option>-P</option> option to
- execute multiple copies of the same utility in parallel.</para>
-
- <para>&man.xargs.1; now supports a <option>-o</option> flag to
- reopen <filename>/dev/tty</filename> for the child process
- before executing the command. This is useful when the child
- process is an interactive application.</para>
-
- <para arch="i386,pc98">The <filename>libkse</filename> library,
- providing POSIX threading support using KSE, is now enabled and
- installed by default.
- This library currently supports M:N threading. Both process and
- system scope threads are supported, as well as getting/setting
- the concurrency level. By default, the library sets the
- concurrency level to the number of CPUs in the system. Each
- concurrency level correlates to a KSE, and all process scope
- threads run in these KSEs. Each system scope thread gets its
- own KSE in addition to those corresponding to concurrency levels.
- <filename>libkse</filename> is still considered a
- work-in-progress, and is not used by default. However, it can
- be used as a replacement for the <filename>libc_r</filename>
- thread library, by substituting <option>-lkse</option> instead of
- <option>-pthread</option> when linking programs.</para>
-
- <para arch="i386,pc98,sparc64,ia64">A 1:1 threading package (where for every pthread in an
- application there is one KSE and thread) has been implemented.
- Under this model, the kernel handles all thread scheduling
- decisions and all signal delivery. This uses some of the common
- KSE code, and is a restricted case of the M:N threading work
- still in progress. The <filename>libthr</filename> library
- implementing the userland portion of this functionality is a
- drop-in replacement for the <filename>libc_r</filename> library.
- Note that <filename>libthr</filename> is not (at this time)
- built by default.</para>
-
- <para>The historic BSD boot scripts in <filename>/etc</filename>
- have been removed, in favor of the <filename>rc.d</filename>
- system imported from <application>NetBSD</application>
- (sometimes referred to as <quote>rcNG</quote>). All
- functionality of the historic system has been preserved. In
- particular, files such as <filename>/etc/rc.conf</filename>
- continue to be the recommended means of configuring the system
- startup. The <filename>rc.d</filename> system has been the
- default since &os; 5.0-RELEASE, so this change should be largely
- transparent for the vast majority of users. Users who have
- customized their historic-style startup scripts should be aware
- that the following files have been removed from
- <filename>/etc</filename>:
-
- <filename>rc.atm</filename>,
- <filename>rc.devfs</filename>,
- <filename>rc.diskless1</filename>,
- <filename>rc.diskless2</filename>,
- <filename>rc.i386</filename>,
- <filename>rc.alpha</filename>,
- <filename>rc.amd64</filename>,
- <filename>rc.ia64</filename>,
- <filename>rc.sparc64</filename>,
- <filename>rc.isdn</filename>,
- <filename>rc.network</filename>,
- <filename>rc.network6</filename>,
- <filename>rc.pccard</filename>,
- <filename>rc.serial</filename>,
- <filename>rc.syscons</filename>,
- <filename>rc.sysctl</filename>.
-
- &man.mergemaster.8;, when run, will offer to move these files
- out of the way for convenience. More details can be found in
- &man.rc.subr.8;.</para>
-
- </sect2>
-
- <sect2 id="contrib">
- <title>Contributed Software</title>
-
- <para>The <application>ACPI-CA</application> code has been updated
- from the 20021118 snapshot to the 20030228 snapshot.</para>
-
- <para><application>awk</application> from Bell Labs has been
- updated to a 14 March 2003 snapshot.</para>
-
- <para><application>BIND</application> has been updated to version
- 8.3.4. &merged;</para>
-
- <para>All of the <application>bzip2</application> suite of
- applications is now installed in the base system (in particular,
- <command>bzip2recover</command> is now built and
- installed). &merged;</para>
-
- <para><application>CVS</application> has been updated to
- 1.11.5. &merged;</para>
-
- <para arch="i386,pc98">The <application>DRM</application> kernel modules have been updated to
- a snapshot from the DRI CVS repository, as of 24 April 2003.
- The <literal>DRM_LINUX</literal> kernel option hsa been removed
- because the handler is now provided by the Linux compatibility
- code.</para>
-
- <para><application>FILE</application> has been updated to
- 3.41. &merged;</para>
-
- <para><application>GCC</application> has been updated to
- 3.2.2 (release version).
-
- <note arch="i386">
- <para><application>GCC</application> is known to produce
- broken code with the <option>-march=pentium4</option> option
- set. As a workaround to avoid this problem, setting the
- <varname>CPUTYPE=p4</varname> Makefile variable (for example, in
- &man.make.conf.5;) enables GCC's
- <option>-march=pentium3</option> option instead. This
- situation is expected to be resolved when GCC 3.3 is
- imported.</para>
- </note>
- </para>
-
- <para>The <application>gdtoa</application> library, for
- conversions between strings and floating point, has been imported. These sources
- were dated 24 March 2003.</para>
-
- <para><application>groff</application> (and related utilities)
- have been updated from 1.18.1 to 1.19.</para>
-
- <para><application>IPFilter</application> has been updated to
- 3.4.31. &merged;</para>
-
- <para>The <application>ISC DHCP</application> client has been
- updated to 3.0.1RC11. &merged;</para>
-
- <para>The <application>ISC DHCP</application> client now includes
- the &man.omshell.1; utility and the &man.dhcpctl.3; library for
- run-time control of the client.</para>
-
- <para><application>Kerberos IV</application> support (in the form
- of <application>KTH eBones</application>) has been removed.
- Users requiring this functionality can still get it from the
- <filename role="port">security/krb4</filename> port (or
- package). Kerberos IV compatibility mode for Kerberos 5 has
- been removed, and the
- <literal>k5<replaceable>program</replaceable></literal> userland
- utilities have been renamed to
- <literal>k<replaceable>program</replaceable></literal>.</para>
-
- <para><application>Kerberos 5</application> is now built by
- default in <literal>buildworld</literal> operations. Setting
- <varname>MAKE_KERBEROS5</varname> no longer has any effect.
- Disabling the base system Kerberos 5 now requires the
- <varname>NO_KERBEROS</varname> Makefile variable to be
- set.</para>
-
- <para><application>libpcap</application> now has support for
- selecting among multiple data link types on an interface.</para>
-
- <para><application>lukemftpd</application> (not built or installed
- by default) has been updated to a snapshot from 22 January
- 2003.</para>
-
- <para><application>OpenPAM</application> has been updated from the
- <quote>Citronella</quote> release to the
- <quote>Dianthus</quote> release.</para>
-
- <para><application>OpenSSH</application> has been updated to
- 3.6.1p1.</para>
-
- <para><application>OpenSSL</application> has been updated to
- release 0.9.7a. Among other features, this release includes
- support for AES and takes advantage of &man.crypto.4;
- devices. &merged;</para>
-
- <para><application>sendmail</application> has been updated to
- version 8.12.9. &merged;</para>
-
- <para>&man.tcpdump.1; has been updated to version 3.7.2. &merged;
- It also now supports a <option>-L</option> flag to list the data
- link types available on an interface and a <option>-y</option>
- option to specify the data link type to use while capturing
- packets.</para>
-
- <para><application>texinfo</application> has been updated from 4.2
- to 4.5.</para>
-
- <para>The timezone database has been updated from
- <filename>tzdata2002d</filename> to
- <filename>tzdata2003a</filename>. &merged;</para>
-
- </sect2>
-
- <sect2 id="ports">
- <title>Ports/Packages Collection Infrastructure</title>
-
- <para>The one-line <filename>pkg-comment</filename> files have
- been eliminated from each port skeleton; their contents have
- been moved into each port's <filename>Makefile</filename>. This
- change reduces the disk space and inodes used by the ports
- tree. &merged;</para>
-
- <para>When fetching distfiles for building a port, the
- <varname>FETCH_REGET</varname> <filename>Makefile</filename>
- variable can be used to specify the number of times to try
- continuing to fetch a distfile if it fails its MD5 checksum.
- The port infrastructure also supports re-fetching interrupted
- distfiles.</para>
-
- <para>&man.pkg.create.1; now supports a <option>-C</option>
- option, which allows packages to register a list of other
- packages with which they conflict. They will refuse to install
- (via &man.pkg.add.1;) if one of the listed packages is already
- present. The <option>-f</option> flag to &man.pkg.add.1;
- overrides this conflict-checking.</para>
-
- <para>&man.pkg.info.1; now honors the <varname>BLOCKSIZE</varname>
- environment variable in its output when the <option>-b</option>
- flag is given.</para>
-
- <para>&man.pkg.info.1; now implements a <option>-Q</option>
- option, which is similar to the <option>-q</option>
- <quote>quiet</quote> option except that it prefixes the output
- with the package name.</para>
-
- </sect2>
-
- <sect2 id="releng">
- <title>Release Engineering and Integration</title>
-
- <para>The supported release of <application>GNOME</application>
- has been updated to 2.2.1. &merged;</para>
-
- <para>The supported release of <application>KDE</application>
- has been updated to 3.1.2. &merged;</para>
-
- <para>There is no longer a separate <filename>krb5</filename>
- distribution. The Kerberos 5 libraries and utilities have been
- incorporated into the <filename>crypto</filename>
- distribution.</para>
-
- <para>&man.sysinstall.8; once again supports installing individual
- components of <application>XFree86</application>. Supporting
- changes (not user-visible) generalize the concept of installing
- parts of distributions as packages.</para>
-
- <para>The supported release of <application>XFree86</application>
- has been updated to 4.3.0. &merged;</para>
-
- <para>Several upgrade mechanisms designed to permit major version
- upgrades from &os; 2.<replaceable>X</replaceable> to 3.<replaceable>X</replaceable> and from &os; 3.<replaceable>X</replaceable> to 4.<replaceable>X</replaceable> have been
- removed.</para>
-
- </sect2>
-
- <sect2 id="doc">
- <title>Documentation</title>
-
- <para>The following new articles have been added to the
- documentation set: <quote>FreeBSD From Scratch</quote>,
- <quote>The Roadmap for 5-STABLE</quote>.</para>
-
- <para>A new Danish (<filename>da_DK.ISO8859-1</filename>)
- translation project has been started.</para>
-
- </sect2>
-
-</sect1>
-
-<sect1 id="upgrade">
- <title>Upgrading from previous releases of &os;</title>
-
- <para>Users with existing &os; systems are
- <emphasis>highly</emphasis> encouraged to read the <quote>Early
- Adopter's Guide to &os; &release.current;</quote>. This document generally has
- the filename <filename>EARLY.TXT</filename> on the distribution
- media, or any other place that the release notes can be found. It
- offers some notes on upgrading, but more importantly, also
- discusses some of the relative merits of upgrading to &os;
- 5.<replaceable>X</replaceable> versus running &os;
- 4.<replaceable>X</replaceable>.</para>
-
- <important>
- <para>Upgrading &os; should, of course, only be attempted after
- backing up <emphasis>all</emphasis> data and configuration
- files.</para>
- </important>
-</sect1>
diff --git a/sbin/setkey/Makefile b/sbin/setkey/Makefile
deleted file mode 100644
index 782b4780807a..000000000000
--- a/sbin/setkey/Makefile
+++ /dev/null
@@ -1,62 +0,0 @@
-# Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
-# 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (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$
-
-PROG= setkey
-MAN= setkey.8
-SRCS= setkey.c parse.y token.l
-
-CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../../lib/libipsec
-YFLAGS= -d
-
-DPADD= ${LIBL} ${LIBY}
-LDADD= -ll -ly
-
-CLEANFILES= y.tab.c y.tab.h key_test.o keytest
-
-# libpfkey.
-# ipsec_strerror.c is for avoiding shlib reference to non-exported function.
-.PATH: ${.CURDIR}/../../lib/libipsec ${.CURDIR}/../../sys/netkey
-SRCS+= pfkey.c pfkey_dump.c key_debug.c ipsec_strerror.c
-CFLAGS+= -I${.CURDIR}/../../lib/libipsec -I${.CURDIR}/../../sys/netkey
-
-SRCS+= y.tab.h
-y.tab.h: parse.y
-CFLAGS+= -DIPSEC_DEBUG -DINET6 -DYY_NO_UNPUT -I.
-DPADD+= ${LIBIPSEC}
-LDADD+= -lipsec
-CLEANFILES+= scriptdump y.tab.h
-
-#SCRIPTS= scriptdump
-
-LOCALPREFIX= /usr
-
-scriptdump: scriptdump.pl
- sed -e 's#@LOCALPREFIX@#${LOCALPREFIX}#' < $> > scriptdump
-
-.include <bsd.prog.mk>
diff --git a/sbin/setkey/parse.y b/sbin/setkey/parse.y
deleted file mode 100644
index 1d43dc430cd9..000000000000
--- a/sbin/setkey/parse.y
+++ /dev/null
@@ -1,933 +0,0 @@
-/* $FreeBSD$ */
-/* $KAME: kame/kame/kame/setkey/parse.y,v 1.36 2001/06/07 15:53:12 sakane Exp $ */
-
-/*
- * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
- * 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <net/route.h>
-#include <netinet/in.h>
-#include <net/pfkeyv2.h>
-#include <netkey/key_var.h>
-#include <netinet6/ipsec.h>
-#include <arpa/inet.h>
-
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <netdb.h>
-#include <ctype.h>
-#include <errno.h>
-
-#include "libpfkey.h"
-#include "vchar.h"
-
-#define ATOX(c) \
- (isdigit(c) ? (c - '0') : (isupper(c) ? (c - 'A' + 10) : (c - 'a' + 10) ))
-
-u_int p_type;
-u_int32_t p_spi;
-int p_no_spi;
-struct sockaddr *p_src, *p_dst;
-u_int p_prefs, p_prefd, p_upper;
-u_int p_satype, p_ext, p_alg_enc, p_alg_auth, p_replay, p_mode;
-u_int32_t p_reqid;
-u_int p_key_enc_len, p_key_auth_len;
-caddr_t p_key_enc, p_key_auth;
-time_t p_lt_hard, p_lt_soft;
-
-u_int p_policy_len;
-char *p_policy;
-
-/* temporary buffer */
-static struct sockaddr *pp_addr;
-static u_int pp_prefix;
-static u_int pp_port;
-static caddr_t pp_key;
-
-extern u_char m_buf[BUFSIZ];
-extern int m_len;
-extern char cmdarg[8192];
-extern int f_debug;
-
-static struct addrinfo *parse_addr __P((char *, char *, int));
-static int setvarbuf __P((int *, struct sadb_ext *, int, caddr_t, int));
-void parse_init __P((void));
-void free_buffer __P((void));
-
-extern int setkeymsg __P((void));
-extern int sendkeymsg __P((void));
-
-extern int yylex __P((void));
-extern void yyfatal __P((const char *));
-extern void yyerror __P((const char *));
-%}
-
-%union {
- unsigned long num;
- vchar_t val;
-}
-
-%token EOT
-%token ADD GET DELETE FLUSH DUMP
-%token ADDRESS PREFIX PORT PORTANY
-%token UP_PROTO PR_ESP PR_AH PR_IPCOMP
-%token F_PROTOCOL F_AUTH F_ENC F_REPLAY F_COMP F_RAWCPI
-%token F_MODE MODE F_REQID
-%token F_EXT EXTENSION NOCYCLICSEQ
-%token ALG_AUTH ALG_ENC ALG_ENC_DESDERIV ALG_ENC_DES32IV ALG_COMP
-%token F_LIFETIME_HARD F_LIFETIME_SOFT
-%token DECSTRING QUOTEDSTRING HEXSTRING STRING ANY
- /* SPD management */
-%token SPDADD SPDDELETE SPDDUMP SPDFLUSH
-%token F_POLICY PL_REQUESTS
-
-%type <num> PORT PREFIX EXTENSION MODE
-%type <num> UP_PROTO PR_ESP PR_AH PR_IPCOMP
-%type <num> ALG_AUTH ALG_ENC ALG_ENC_DESDERIV ALG_ENC_DES32IV ALG_COMP
-%type <num> DECSTRING
-%type <val> ADDRESS PL_REQUESTS
-%type <val> key_string policy_requests
-%type <val> QUOTEDSTRING HEXSTRING STRING
-
-%%
-commands
- : /*NOTHING*/
- | commands command
- {
- if (f_debug) {
- printf("cmdarg:\n%s\n", cmdarg);
- } else {
- setkeymsg();
- sendkeymsg();
- }
- free_buffer();
- parse_init();
- }
- ;
-
-command
- : add_command
- | get_command
- | delete_command
- | deleteall_command
- | flush_command
- | dump_command
- | spdadd_command
- | spddelete_command
- | spddump_command
- | spdflush_command
- ;
- /* commands concerned with management, there is in tail of this file. */
-
- /* add command */
-add_command
- : ADD { p_type = SADB_ADD; }
- sa_selector_spec extension_spec algorithm_spec EOT
- ;
-
- /* delete */
-delete_command
- : DELETE { p_type = SADB_DELETE; }
- sa_selector_spec extension_spec
- {
- if (p_mode != IPSEC_MODE_ANY)
- yyerror("WARNING: mode is obsoleted.");
- }
- EOT
- ;
-
- /* deleteall command */
-deleteall_command
- : DELETEALL { p_type = SADB_DELETE; }
- ipaddress { p_src = pp_addr; }
- ipaddress { p_dst = pp_addr; }
- protocol_spec
- { p_no_spi = 1; }
- EOT
- ;
-
- /* get command */
-get_command
- : GET { p_type = SADB_GET; }
- sa_selector_spec extension_spec
- {
- if (p_mode != IPSEC_MODE_ANY)
- yyerror("WARNING: mode is obsoleted.");
- }
- EOT
- ;
-
- /* flush */
-flush_command
- : FLUSH { p_type = SADB_FLUSH; }
- protocol_spec EOT
- ;
-
- /* dump */
-dump_command
- : DUMP { p_type = SADB_DUMP; }
- protocol_spec EOT
- ;
-
- /* sa_selector_spec */
-sa_selector_spec
- : ipaddress { p_src = pp_addr; }
- ipaddress { p_dst = pp_addr; }
- protocol_spec spi
- ;
-
-protocol_spec
- : /*NOTHING*/ { p_satype = SADB_SATYPE_UNSPEC; }
- | PR_ESP
- {
- p_satype = SADB_SATYPE_ESP;
- if ($1 == 1)
- p_ext |= SADB_X_EXT_OLD;
- else
- p_ext &= ~SADB_X_EXT_OLD;
- }
- | PR_AH
- {
- p_satype = SADB_SATYPE_AH;
- if ($1 == 1)
- p_ext |= SADB_X_EXT_OLD;
- else
- p_ext &= ~SADB_X_EXT_OLD;
- }
- | PR_IPCOMP
- {
- p_satype = SADB_X_SATYPE_IPCOMP;
- }
- ;
-
-spi
- : DECSTRING { p_spi = $1; }
- | HEXSTRING
- {
- caddr_t bp;
- caddr_t yp = $1.buf;
- char buf0[4], buf[4];
- int i, j;
-
- /* sanity check */
- if ($1.len > 4) {
- yyerror("SPI too big.");
- free($1.buf);
- return -1;
- }
-
- bp = buf0;
- while (*yp) {
- *bp = (ATOX(yp[0]) << 4) | ATOX(yp[1]);
- yp += 2, bp++;
- }
-
- /* initialize */
- for (i = 0; i < 4; i++) buf[i] = 0;
-
- for (j = $1.len - 1, i = 3; j >= 0; j--, i--)
- buf[i] = buf0[j];
-
- /* XXX: endian */
- p_spi = ntohl(*(u_int32_t *)buf);
-
- free($1.buf);
- }
- ;
-
-algorithm_spec
- : esp_spec
- | ah_spec
- | ipcomp_spec
- ;
-
-esp_spec
- : F_ENC enc_alg enc_key F_AUTH auth_alg auth_key
- | F_ENC enc_alg enc_key
- ;
-
-ah_spec
- : F_AUTH auth_alg auth_key
- ;
-
-ipcomp_spec
- : F_COMP ALG_COMP { p_alg_enc = $2; }
- | F_COMP ALG_COMP { p_alg_enc = $2; }
- F_RAWCPI { p_ext |= SADB_X_EXT_RAWCPI; }
- ;
-
-enc_alg
- : ALG_ENC { p_alg_enc = $1; }
- | ALG_ENC_DESDERIV
- {
- p_alg_enc = $1;
- if (p_ext & SADB_X_EXT_OLD) {
- yyerror("algorithm mismatched.");
- return -1;
- }
- p_ext |= SADB_X_EXT_DERIV;
- }
- | ALG_ENC_DES32IV
- {
- p_alg_enc = $1;
- if (!(p_ext & SADB_X_EXT_OLD)) {
- yyerror("algorithm mismatched.");
- return -1;
- }
- p_ext |= SADB_X_EXT_IV4B;
- }
- ;
-
-enc_key
- : /*NOTHING*/
- {
- if (p_alg_enc != SADB_EALG_NULL) {
- yyerror("no key found.");
- return -1;
- }
- }
- | key_string
- {
- p_key_enc_len = $1.len;
- p_key_enc = pp_key;
-
- if (ipsec_check_keylen(SADB_EXT_SUPPORTED_ENCRYPT,
- p_alg_enc,
- PFKEY_UNUNIT64(p_key_enc_len)) < 0) {
- yyerror(ipsec_strerror());
- return -1;
- }
- }
- ;
-
-auth_alg
- : ALG_AUTH { p_alg_auth = $1; }
- ;
-
-auth_key
- : /*NOTHING*/
- {
- if (p_alg_auth != SADB_X_AALG_NULL) {
- yyerror("no key found.");
- return -1;
- }
- }
- | key_string
- {
- p_key_auth_len = $1.len;
- p_key_auth = pp_key;
-
- if (ipsec_check_keylen(SADB_EXT_SUPPORTED_AUTH,
- p_alg_auth,
- PFKEY_UNUNIT64(p_key_auth_len)) < 0) {
- yyerror(ipsec_strerror());
- return -1;
- }
- }
- ;
-
-key_string
- : QUOTEDSTRING
- {
- pp_key = $1.buf;
- /* free pp_key later */
- }
- | HEXSTRING
- {
- caddr_t bp;
- caddr_t yp = $1.buf;
-
- if ((pp_key = malloc($1.len)) == 0) {
- free($1.buf);
- yyerror("not enough core");
- return -1;
- }
- memset(pp_key, 0, $1.len);
-
- bp = pp_key;
- while (*yp) {
- *bp = (ATOX(yp[0]) << 4) | ATOX(yp[1]);
- yp += 2, bp++;
- }
-
- free($1.buf);
- }
- ;
-
-extension_spec
- : /*NOTHING*/
- | extension_spec extension
- ;
-
-extension
- : F_EXT EXTENSION { p_ext |= $2; }
- | F_EXT NOCYCLICSEQ { p_ext &= ~SADB_X_EXT_CYCSEQ; }
- | F_MODE MODE { p_mode = $2; }
- | F_MODE ANY { p_mode = IPSEC_MODE_ANY; }
- | F_REQID DECSTRING { p_reqid = $2; }
- | F_REPLAY DECSTRING
- {
- if (p_ext & SADB_X_EXT_OLD) {
- yyerror("replay prevention "
- "only use on new spec.");
- return -1;
- }
- p_replay = $2;
- }
- | F_LIFETIME_HARD DECSTRING { p_lt_hard = $2; }
- | F_LIFETIME_SOFT DECSTRING { p_lt_soft = $2; }
- ;
-
- /* definition about command for SPD management */
- /* spdadd */
-spdadd_command
- : SPDADD
- {
- p_type = SADB_X_SPDADD;
- p_satype = SADB_SATYPE_UNSPEC;
- }
- sp_selector_spec policy_spec EOT
- ;
-
-spddelete_command:
- SPDDELETE
- {
- p_type = SADB_X_SPDDELETE;
- p_satype = SADB_SATYPE_UNSPEC;
- }
- sp_selector_spec policy_spec EOT
- ;
-
-spddump_command:
- SPDDUMP
- {
- p_type = SADB_X_SPDDUMP;
- p_satype = SADB_SATYPE_UNSPEC;
- }
- EOT
- ;
-
-spdflush_command:
- SPDFLUSH
- {
- p_type = SADB_X_SPDFLUSH;
- p_satype = SADB_SATYPE_UNSPEC;
- }
- EOT
- ;
-
- /* sp_selector_spec */
-sp_selector_spec
- : ipaddress { p_src = pp_addr; }
- prefix { p_prefs = pp_prefix; }
- port
- {
- switch (p_src->sa_family) {
- case AF_INET:
- ((struct sockaddr_in *)p_src)->sin_port =
- htons(pp_port);
- break;
-#ifdef INET6
- case AF_INET6:
- ((struct sockaddr_in6 *)p_src)->sin6_port =
- htons(pp_port);
- break;
-#endif
- default:
- exit(1); /*XXX*/
- }
- }
- ipaddress { p_dst = pp_addr; }
- prefix { p_prefd = pp_prefix; }
- port
- {
- switch (p_dst->sa_family) {
- case AF_INET:
- ((struct sockaddr_in *)p_dst)->sin_port =
- htons(pp_port);
- break;
-#ifdef INET6
- case AF_INET6:
- ((struct sockaddr_in6 *)p_dst)->sin6_port =
- htons(pp_port);
- break;
-#endif
- default:
- exit(1); /*XXX*/
- }
- }
- upper_spec
- {
- /* XXX is it something userland should check? */
-#if 0
- switch (p_upper) {
- case IPPROTO_ICMP:
- case IPPROTO_ICMPV6:
- if (_INPORTBYSA(p_src) != IPSEC_PORT_ANY
- || _INPORTBYSA(p_dst) != IPSEC_PORT_ANY) {
- yyerror("port number must be \"any\".");
- return -1;
- }
- if ((pp_addr->sa_family == AF_INET6
- && p_upper == IPPROTO_ICMP)
- || (pp_addr->sa_family == AF_INET
- && p_upper == IPPROTO_ICMPV6)) {
- yyerror("upper layer protocol "
- "mismatched.\n");
- return -1;
- }
- break;
- default:
- break;
- }
-#endif
- }
- ;
-
-ipaddress
- : ADDRESS
- {
- struct addrinfo *res;
-
- res = parse_addr($1.buf, NULL, AI_NUMERICHOST);
- if (res == NULL) {
- free($1.buf);
- return -1;
- }
- pp_addr = (struct sockaddr *)malloc(res->ai_addrlen);
- if (!pp_addr) {
- yyerror("not enough core");
- goto end;
- }
-
- memcpy(pp_addr, res->ai_addr, res->ai_addrlen);
- end:
- freeaddrinfo(res);
- free($1.buf);
- }
- ;
-
-prefix
- : /*NOTHING*/ { pp_prefix = ~0; }
- | PREFIX { pp_prefix = $1; }
- ;
-
-port
- : /*NOTHING*/ { pp_port = IPSEC_PORT_ANY; }
- | PORT { pp_port = $1; }
- | PORTANY { pp_port = IPSEC_PORT_ANY; }
- ;
-
-upper_spec
- : DECSTRING { p_upper = $1; }
- | UP_PROTO { p_upper = $1; }
- | ANY { p_upper = IPSEC_ULPROTO_ANY; }
- | STRING
- {
- struct protoent *ent;
-
- ent = getprotobyname($1.buf);
- if (ent)
- p_upper = ent->p_proto;
- else {
- if (strcmp("icmp6", $1.buf) == 0) {
- p_upper = IPPROTO_ICMPV6;
- } else if(strcmp("ip4", $1.buf) == 0) {
- p_upper = IPPROTO_IPV4;
- } else {
- yyerror("invalid upper layer protocol");
- free($1.buf);
- return -1;
- }
- }
- free($1.buf);
- }
- ;
-
-policy_spec
- : F_POLICY policy_requests
- {
- p_policy = ipsec_set_policy($2.buf, $2.len);
- if (p_policy == NULL) {
- free($2.buf);
- p_policy = NULL;
- yyerror(ipsec_strerror());
- return -1;
- }
-
- p_policy_len = ipsec_get_policylen(p_policy);
-
- free($2.buf);
- }
- ;
-
-policy_requests
- : PL_REQUESTS { $$ = $1; }
- ;
-
-%%
-
-int
-setkeymsg()
-{
- struct sadb_msg m_msg;
-
- m_msg.sadb_msg_version = PF_KEY_V2;
- m_msg.sadb_msg_type = p_type;
- m_msg.sadb_msg_errno = 0;
- m_msg.sadb_msg_satype = p_satype;
- m_msg.sadb_msg_reserved = 0;
- m_msg.sadb_msg_seq = 0;
- m_msg.sadb_msg_pid = getpid();
-
- m_len = sizeof(struct sadb_msg);
- memcpy(m_buf, &m_msg, m_len);
-
- switch (p_type) {
- case SADB_FLUSH:
- case SADB_DUMP:
- break;
-
- case SADB_ADD:
- /* set encryption algorithm, if present. */
- if (p_satype != SADB_X_SATYPE_IPCOMP && p_alg_enc != SADB_EALG_NONE) {
- struct sadb_key m_key;
-
- m_key.sadb_key_len =
- PFKEY_UNIT64(sizeof(m_key)
- + PFKEY_ALIGN8(p_key_enc_len));
- m_key.sadb_key_exttype = SADB_EXT_KEY_ENCRYPT;
- m_key.sadb_key_bits = p_key_enc_len * 8;
- m_key.sadb_key_reserved = 0;
-
- setvarbuf(&m_len,
- (struct sadb_ext *)&m_key, sizeof(m_key),
- (caddr_t)p_key_enc, p_key_enc_len);
- }
-
- /* set authentication algorithm, if present. */
- if (p_alg_auth != SADB_AALG_NONE) {
- struct sadb_key m_key;
-
- m_key.sadb_key_len =
- PFKEY_UNIT64(sizeof(m_key)
- + PFKEY_ALIGN8(p_key_auth_len));
- m_key.sadb_key_exttype = SADB_EXT_KEY_AUTH;
- m_key.sadb_key_bits = p_key_auth_len * 8;
- m_key.sadb_key_reserved = 0;
-
- setvarbuf(&m_len,
- (struct sadb_ext *)&m_key, sizeof(m_key),
- (caddr_t)p_key_auth, p_key_auth_len);
- }
-
- /* set lifetime for HARD */
- if (p_lt_hard != 0) {
- struct sadb_lifetime m_lt;
- u_int len = sizeof(struct sadb_lifetime);
-
- m_lt.sadb_lifetime_len = PFKEY_UNIT64(len);
- m_lt.sadb_lifetime_exttype = SADB_EXT_LIFETIME_HARD;
- m_lt.sadb_lifetime_allocations = 0;
- m_lt.sadb_lifetime_bytes = 0;
- m_lt.sadb_lifetime_addtime = p_lt_hard;
- m_lt.sadb_lifetime_usetime = 0;
-
- memcpy(m_buf + m_len, &m_lt, len);
- m_len += len;
- }
-
- /* set lifetime for SOFT */
- if (p_lt_soft != 0) {
- struct sadb_lifetime m_lt;
- u_int len = sizeof(struct sadb_lifetime);
-
- m_lt.sadb_lifetime_len = PFKEY_UNIT64(len);
- m_lt.sadb_lifetime_exttype = SADB_EXT_LIFETIME_SOFT;
- m_lt.sadb_lifetime_allocations = 0;
- m_lt.sadb_lifetime_bytes = 0;
- m_lt.sadb_lifetime_addtime = p_lt_soft;
- m_lt.sadb_lifetime_usetime = 0;
-
- memcpy(m_buf + m_len, &m_lt, len);
- m_len += len;
- }
- /* FALLTHROUGH */
-
- case SADB_DELETE:
- case SADB_GET:
- {
- struct sadb_sa m_sa;
- struct sadb_x_sa2 m_sa2;
- struct sadb_address m_addr;
- u_int len;
-
- if (p_no_spi == 0) {
- len = sizeof(struct sadb_sa);
- m_sa.sadb_sa_len = PFKEY_UNIT64(len);
- m_sa.sadb_sa_exttype = SADB_EXT_SA;
- m_sa.sadb_sa_spi = htonl(p_spi);
- m_sa.sadb_sa_replay = p_replay;
- m_sa.sadb_sa_state = 0;
- m_sa.sadb_sa_auth = p_alg_auth;
- m_sa.sadb_sa_encrypt = p_alg_enc;
- m_sa.sadb_sa_flags = p_ext;
-
- memcpy(m_buf + m_len, &m_sa, len);
- m_len += len;
-
- len = sizeof(struct sadb_x_sa2);
- m_sa2.sadb_x_sa2_len = PFKEY_UNIT64(len);
- m_sa2.sadb_x_sa2_exttype = SADB_X_EXT_SA2;
- m_sa2.sadb_x_sa2_mode = p_mode;
- m_sa2.sadb_x_sa2_reqid = p_reqid;
-
- memcpy(m_buf + m_len, &m_sa2, len);
- m_len += len;
- }
-
- /* set src */
- m_addr.sadb_address_len =
- PFKEY_UNIT64(sizeof(m_addr)
- + PFKEY_ALIGN8(p_src->sa_len));
- m_addr.sadb_address_exttype = SADB_EXT_ADDRESS_SRC;
- m_addr.sadb_address_proto = IPSEC_ULPROTO_ANY;
- switch (p_src->sa_family) {
- case AF_INET:
- m_addr.sadb_address_prefixlen =
- sizeof(struct in_addr) << 3;
- break;
-#ifdef INET6
- case AF_INET6:
- m_addr.sadb_address_prefixlen =
- sizeof(struct in6_addr) << 3;
- break;
-#endif
- default:
- yyerror("unsupported address family");
- exit(1); /*XXX*/
- }
- m_addr.sadb_address_reserved = 0;
-
- setvarbuf(&m_len,
- (struct sadb_ext *)&m_addr, sizeof(m_addr),
- (caddr_t)p_src, p_src->sa_len);
-
- /* set dst */
- m_addr.sadb_address_len =
- PFKEY_UNIT64(sizeof(m_addr)
- + PFKEY_ALIGN8(p_dst->sa_len));
- m_addr.sadb_address_exttype = SADB_EXT_ADDRESS_DST;
- m_addr.sadb_address_proto = IPSEC_ULPROTO_ANY;
- switch (p_dst->sa_family) {
- case AF_INET:
- m_addr.sadb_address_prefixlen =
- sizeof(struct in_addr) << 3;
- break;
-#ifdef INET6
- case AF_INET6:
- m_addr.sadb_address_prefixlen =
- sizeof(struct in6_addr) << 3;
- break;
-#endif
- default:
- yyerror("unsupported address family");
- exit(1); /*XXX*/
- }
- m_addr.sadb_address_reserved = 0;
-
- setvarbuf(&m_len,
- (struct sadb_ext *)&m_addr, sizeof(m_addr),
- (caddr_t)p_dst, p_dst->sa_len);
- }
- break;
-
- /* for SPD management */
- case SADB_X_SPDFLUSH:
- case SADB_X_SPDDUMP:
- break;
-
- case SADB_X_SPDADD:
- case SADB_X_SPDDELETE:
- {
- struct sadb_address m_addr;
- u_int8_t plen;
-
- memcpy(m_buf + m_len, p_policy, p_policy_len);
- m_len += p_policy_len;
- free(p_policy);
- p_policy = NULL;
-
- /* set src */
- m_addr.sadb_address_len =
- PFKEY_UNIT64(sizeof(m_addr)
- + PFKEY_ALIGN8(p_src->sa_len));
- m_addr.sadb_address_exttype = SADB_EXT_ADDRESS_SRC;
- m_addr.sadb_address_proto = p_upper;
- switch (p_src->sa_family) {
- case AF_INET:
- plen = sizeof(struct in_addr) << 3;
- break;
-#ifdef INET6
- case AF_INET6:
- plen = sizeof(struct in6_addr) << 3;
- break;
-#endif
- default:
- yyerror("unsupported address family");
- exit(1); /*XXX*/
- }
- m_addr.sadb_address_prefixlen =
- (p_prefs != ~0 ? p_prefs : plen);
- m_addr.sadb_address_reserved = 0;
-
- setvarbuf(&m_len,
- (struct sadb_ext *)&m_addr, sizeof(m_addr),
- (caddr_t)p_src, p_src->sa_len);
-
- /* set dst */
- m_addr.sadb_address_len =
- PFKEY_UNIT64(sizeof(m_addr)
- + PFKEY_ALIGN8(p_dst->sa_len));
- m_addr.sadb_address_exttype = SADB_EXT_ADDRESS_DST;
- m_addr.sadb_address_proto = p_upper;
- switch (p_dst->sa_family) {
- case AF_INET:
- plen = sizeof(struct in_addr) << 3;
- break;
-#ifdef INET6
- case AF_INET6:
- plen = sizeof(struct in6_addr) << 3;
- break;
-#endif
- default:
- yyerror("unsupported address family");
- exit(1); /*XXX*/
- }
- m_addr.sadb_address_prefixlen =
- (p_prefd != ~0 ? p_prefd : plen);
- m_addr.sadb_address_reserved = 0;
-
- setvarbuf(&m_len,
- (struct sadb_ext *)&m_addr, sizeof(m_addr),
- (caddr_t)p_dst, p_dst->sa_len);
- }
- break;
- }
-
- ((struct sadb_msg *)m_buf)->sadb_msg_len = PFKEY_UNIT64(m_len);
-
- return 0;
-}
-
-static struct addrinfo *
-parse_addr(host, port, flag)
- char *host;
- char *port;
- int flag;
-{
- struct addrinfo hints, *res = NULL;
- int error;
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_DGRAM;
- hints.ai_flags = flag;
- error = getaddrinfo(host, port, &hints, &res);
- if (error != 0) {
- yyerror(gai_strerror(error));
- return NULL;
- }
- if (res->ai_next != NULL) {
- yyerror(gai_strerror(error));
- }
- return res;
-}
-
-static int
-setvarbuf(off, ebuf, elen, vbuf, vlen)
- caddr_t vbuf;
- struct sadb_ext *ebuf;
- int *off, elen, vlen;
-{
- memset(m_buf + *off, 0, PFKEY_UNUNIT64(ebuf->sadb_ext_len));
- memcpy(m_buf + *off, (caddr_t)ebuf, elen);
- memcpy(m_buf + *off + elen, vbuf, vlen);
- (*off) += PFKEY_ALIGN8(elen + vlen);
-
- return 0;
-}
-
-void
-parse_init()
-{
- p_type = 0;
- p_spi = 0;
- p_no_spi = 0;
-
- p_src = 0, p_dst = 0;
- pp_prefix = p_prefs = p_prefd = ~0;
- pp_port = IPSEC_PORT_ANY;
- p_upper = 0;
-
- p_satype = 0;
- p_ext = SADB_X_EXT_CYCSEQ;
- p_alg_enc = SADB_EALG_NONE;
- p_alg_auth = SADB_AALG_NONE;
- p_mode = IPSEC_MODE_ANY;
- p_reqid = 0;
- p_replay = 0;
- p_key_enc_len = p_key_auth_len = 0;
- p_key_enc = p_key_auth = 0;
- p_lt_hard = p_lt_soft = 0;
-
- p_policy_len = 0;
- p_policy = NULL;
-
- memset(cmdarg, 0, sizeof(cmdarg));
-
- return;
-}
-
-void
-free_buffer()
-{
- if (p_src) free(p_src);
- if (p_dst) free(p_dst);
- if (p_key_enc) free(p_key_enc);
- if (p_key_auth) free(p_key_auth);
-
- return;
-}
-
diff --git a/sbin/setkey/sample.cf b/sbin/setkey/sample.cf
deleted file mode 100644
index 3318f9b3346e..000000000000
--- a/sbin/setkey/sample.cf
+++ /dev/null
@@ -1,219 +0,0 @@
-# Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
-# 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (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$
-
-# There are sample scripts for IPsec configuration by manual keying.
-# A security association is uniquely identified by a triple consisting
-# of a Security Parameter Index (SPI), an IP Destination Address, and a
-# security protocol (AH or ESP) identifier. You must take care of these
-# parameters when you configure by manual keying.
-
-# ESP transport mode is recommended for TCP port number 110 between
-# Host-A and Host-B. Encryption algorithm is blowfish-cbc whose key
-# is "kamekame", and authentication algorithm is hmac-sha1 whose key
-# is "this is the test key".
-#
-# ============ ESP ============
-# | |
-# Host-A Host-B
-# fec0::10 -------------------- fec0::11
-#
-# At Host-A and Host-B,
-spdadd fec0::10[any] fec0::11[110] tcp -P out ipsec
- esp/transport/fec0::10-fec0::11/use ;
-spdadd fec0::11[110] fec0::10[any] tcp -P in ipsec
- esp/transport/fec0::11-fec0::10/use ;
-add fec0::10 fec0::11 esp 0x10001
- -m transport
- -E blowfish-cbc "kamekame"
- -A hmac-sha1 "this is the test key" ;
-add fec0::11 fec0::10 esp 0x10002
- -m transport
- -E blowfish-cbc "kamekame"
- -A hmac-sha1 "this is the test key" ;
-
-# "[any]" is wildcard of port number. Note that "[0]" is the number of
-# zero in port number.
-
-# Security protocol is old AH tunnel mode, i.e. RFC1826, with keyed-md5
-# whose key is "this is the test" as authentication algorithm.
-# That protocol takes place between Gateway-A and Gateway-B.
-#
-# ======= AH =======
-# | |
-# Network-A Gateway-A Gateway-B Network-B
-# 10.0.1.0/24 ---- 172.16.0.1 ----- 172.16.0.2 ---- 10.0.2.0/24
-#
-# At Gateway-A:
-spdadd 10.0.1.0/24 10.0.2.0/24 any -P out ipsec
- ah/tunnel/172.16.0.1-172.16.0.2/require ;
-spdadd 10.0.2.0/24 10.0.1.0/24 any -P in ipsec
- ah/tunnel/172.16.0.2-172.16.0.1/require ;
-add 172.16.0.1 172.16.0.2 ah-old 0x10003
- -m any
- -A keyed-md5 "this is the test" ;
-add 172.16.0.2 172.16.0.1 ah-old 0x10004
- -m any
- -A keyed-md5 "this is the test" ;
-
-# If port number field is omitted such above then "[any]" is employed.
-# -m specifies the mode of SA to be used. "-m any" means wildcard of
-# mode of security protocol. You can use this SAs for both tunnel and
-# transport mode.
-
-# At Gateway-B. Attention to the selector and peer's IP address for tunnel.
-spdadd 10.0.2.0/24 10.0.1.0/24 any -P out ipsec
- ah/tunnel/172.16.0.2-172.16.0.1/require ;
-spdadd 10.0.1.0/24 10.0.2.0/24 any -P in ipsec
- ah/tunnel/172.16.0.1-172.16.0.2/require ;
-add 172.16.0.1 172.16.0.2 ah-old 0x10003
- -m tunnel
- -A keyed-md5 "this is the test" ;
-add 172.16.0.2 172.16.0.1 ah-old 0x10004
- -m tunnel
- -A keyed-md5 "this is the test" ;
-
-# AH transport mode followed by ESP tunnel mode is required between
-# Gateway-A and Gateway-B.
-# Encryption algorithm is 3des-cbc, and authentication algorithm for ESP
-# is hmac-sha1. Authentication algorithm for AH is hmac-md5.
-#
-# ========== AH =========
-# | ======= ESP ===== |
-# | | | |
-# Network-A Gateway-A Gateway-B Network-B
-# fec0:0:0:1::/64 --- fec0:0:0:1::1 ---- fec0:0:0:2::1 --- fec0:0:0:2::/64
-#
-# At Gateway-A:
-spdadd fec0:0:0:1::/64 fec0:0:0:2::/64 any -P out ipsec
- esp/tunnel/fec0:0:0:1::1-fec0:0:0:2::1/require
- ah/transport/fec0:0:0:1::1-fec0:0:0:2::1/require ;
-spdadd fec0:0:0:2::/64 fec0:0:0:1::/64 any -P in ipsec
- esp/tunnel/fec0:0:0:2::1-fec0:0:0:1::1/require
- ah/transport/fec0:0:0:2::1-fec0:0:0:1::1/require ;
-add fec0:0:0:1::1 fec0:0:0:2::1 esp 0x10001
- -m tunnel
- -E 3des-cbc "kamekame12341234kame1234"
- -A hmac-sha1 "this is the test key" ;
-add fec0:0:0:1::1 fec0:0:0:2::1 ah 0x10001
- -m transport
- -A hmac-md5 "this is the test" ;
-add fec0:0:0:2::1 fec0:0:0:1::1 esp 0x10001
- -m tunnel
- -E 3des-cbc "kamekame12341234kame1234"
- -A hmac-sha1 "this is the test key" ;
-add fec0:0:0:2::1 fec0:0:0:1::1 ah 0x10001
- -m transport
- -A hmac-md5 "this is the test" ;
-
-# ESP tunnel mode is required between Host-A and Gateway-A.
-# Encryption algorithm is cast128-cbc, and authentication algorithm
-# for ESP is hmac-sha1.
-# ESP transport mode is recommended between Host-A and Host-B.
-# Encryption algorithm is rc5-cbc, and authentication algorithm
-# for ESP is hmac-md5.
-#
-# ================== ESP =================
-# | ======= ESP ======= |
-# | | | |
-# Host-A Gateway-A Host-B
-# fec0:0:0:1::1 ---- fec0:0:0:2::1 ---- fec0:0:0:2::2
-#
-# At Host-A:
-spdadd fec0:0:0:1::1[any] fec0:0:0:2::2[80] tcp -P out ipsec
- esp/transport/fec0:0:0:1::1-fec0:0:0:2::2/use
- esp/tunnel/fec0:0:0:1::1-fec0:0:0:2::1/require ;
-spdadd fec0:0:0:2::1[80] fec0:0:0:1::1[any] tcp -P in ipsec
- esp/transport/fec0:0:0:2::2-fec0:0:0:1::1/use
- esp/tunnel/fec0:0:0:2::1-fec0:0:0:1::1/require ;
-add fec0:0:0:1::1 fec0:0:0:2::2 esp 0x10001
- -m transport
- -E cast128-cbc "12341234"
- -A hmac-sha1 "this is the test key" ;
-add fec0:0:0:1::1 fec0:0:0:2::1 esp 0x10002
- -E rc5-cbc "kamekame"
- -A hmac-md5 "this is the test" ;
-add fec0:0:0:2::2 fec0:0:0:1::1 esp 0x10003
- -m transport
- -E cast128-cbc "12341234"
- -A hmac-sha1 "this is the test key" ;
-add fec0:0:0:2::1 fec0:0:0:1::1 esp 0x10004
- -E rc5-cbc "kamekame"
- -A hmac-md5 "this is the test" ;
-
-# By "get" command, you can get an entry of either SP or SA.
-get fec0:0:0:1::1 fec0:0:0:2::2 ah 0x10004 ;
-
-# Also delete command, you can delete an entry of either SP or SA.
-spddelete fec0:0:0:1::/64 fec0:0:0:2::/64 any -P out;
-delete fec0:0:0:1::1 fec0:0:0:2::2 ah 0x10004 ;
-
-# By dump command, you can dump all entry of either SP or SA.
-dump ;
-spddump ;
-dump esp ;
-flush esp ;
-
-# By flush command, you can flush all entry of either SP or SA.
-flush ;
-spdflush ;
-
-# "flush" and "dump" commands can specify a security protocol.
-dump esp ;
-flush ah ;
-
-# XXX
-add ::1 ::1 esp 10001 -m transport -E simple ;
-add ::1 ::1 esp 10002 -m transport -E des-deriv "12341234" ;
-add ::1 ::1 esp-old 10003 -m transport -E des-32iv "12341234" ;
-add ::1 ::1 esp 10004 -m transport -E simple -A null ;
-add ::1 ::1 esp 10005 -m transport -E simple -A hmac-md5 "1234123412341234" ;
-add ::1 ::1 esp 10006 -m tunnel -E simple -A hmac-sha1 "12341234123412341234" ;
-add ::1 ::1 esp 10007 -m transport -E simple -A keyed-md5 "1234123412341234" ;
-add ::1 ::1 esp 10008 -m any -E simple -A keyed-sha1 "12341234123412341234" ;
-add ::1 ::1 esp 10009 -m transport -E des-cbc "testtest" ;
-add ::1 ::1 esp 10010 -m transport -E 3des-cbc "testtest12341234testtest" ;
-add ::1 ::1 esp 10011 -m tunnel -E cast128-cbc "testtest1234" ;
-add ::1 ::1 esp 10012 -m tunnel -E blowfish-cbc "testtest1234" ;
-add ::1 ::1 esp 10013 -m tunnel -E rc5-cbc "testtest1234" ;
-add ::1 ::1 esp 10014 -m any -E rc5-cbc "testtest1234" ;
-add ::1 ::1 esp 10015 -m transport -f zero-pad -E simple ;
-add ::1 ::1 esp 10016 -m tunnel -f random-pad -r 8 -lh 100 -ls 80 -E simple ;
-add ::1 ::1 esp 10017 -m transport -f seq-pad -f nocyclic-seq -E simple ;
-add ::1 ::1 esp 10018 -m transport -E simple ;
-#add ::1 ::1 ah 20000 -m transport -A null ;
-add ::1 ::1 ah 20001 -m any -A hmac-md5 "1234123412341234";
-add ::1 ::1 ah 20002 -m tunnel -A hmac-sha1 "12341234123412341234";
-add ::1 ::1 ah 20003 -m transport -A keyed-md5 "1234123412341234";
-add ::1 ::1 ah-old 20004 -m transport -A keyed-md5 "1234123412341234";
-add ::1 ::1 ah 20005 -m transport -A keyed-sha1 "12341234123412341234";
-#add ::1 ::1 ipcomp 30000 -C oui ;
-add ::1 ::1 ipcomp 30001 -C deflate ;
-#add ::1 ::1 ipcomp 30002 -C lzs ;
-
-# enjoy.
diff --git a/sbin/setkey/scriptdump.pl b/sbin/setkey/scriptdump.pl
deleted file mode 100644
index a1d8adb207bc..000000000000
--- a/sbin/setkey/scriptdump.pl
+++ /dev/null
@@ -1,56 +0,0 @@
-#! @LOCALPREFIX@/bin/perl
-# $FreeBSD$
-
-if ($< != 0) {
- print STDERR "must be root to invoke this\n";
- exit 1;
-}
-
-$mode = 'add';
-while ($i = shift @ARGV) {
- if ($i eq '-d') {
- $mode = 'delete';
- } else {
- print STDERR "usage: scriptdump [-d]\n";
- exit 1;
- }
-}
-
-open(IN, "setkey -D |") || die;
-foreach $_ (<IN>) {
- if (/^[^\t]/) {
- ($src, $dst) = split(/\s+/, $_);
- } elsif (/^\t(esp|ah) mode=(\S+) spi=(\d+).*reqid=(\d+)/) {
- ($proto, $ipsecmode, $spi, $reqid) = ($1, $2, $3, $4);
- } elsif (/^\tE: (\S+) (.*)/) {
- $ealgo = $1;
- $ekey = $2;
- $ekey =~ s/\s//g;
- $ekey =~ s/^/0x/g;
- } elsif (/^\tA: (\S+) (.*)/) {
- $aalgo = $1;
- $akey = $2;
- $akey =~ s/\s//g;
- $akey =~ s/^/0x/g;
- } elsif (/^\tseq=(0x\d+) replay=(\d+) flags=(0x\d+) state=/) {
- print "$mode $src $dst $proto $spi";
- $replay = $2;
- print " -u $reqid" if $reqid;
- if ($mode eq 'add') {
- print " -m $ipsecmode -r $replay" if $replay;
- if ($proto eq 'esp') {
- print " -E $ealgo $ekey" if $ealgo;
- print " -A $aalgo $akey" if $aalgo;
- } elsif ($proto eq 'ah') {
- print " -A $aalgo $akey" if $aalgo;
- }
- }
- print ";\n";
-
- $src = $dst = $upper = $proxy = '';
- $ealgo = $ekey = $aalgo = $akey = '';
- }
-}
-close(IN);
-
-exit 0;
diff --git a/sbin/setkey/setkey.8 b/sbin/setkey/setkey.8
deleted file mode 100644
index 7c8cf38cb304..000000000000
--- a/sbin/setkey/setkey.8
+++ /dev/null
@@ -1,625 +0,0 @@
-.\" $KAME: setkey.8,v 1.49 2001/05/18 05:49:51 sakane Exp $
-.\" $FreeBSD$
-.\"
-.\" Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
-.\" 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (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 November 20, 2000
-.Dt SETKEY 8
-.Os
-.\"
-.Sh NAME
-.Nm setkey
-.Nd "manually manipulate the IPsec SA/SP database"
-.\"
-.Sh SYNOPSIS
-.Nm
-.Op Fl dv
-.Fl c
-.Nm
-.Op Fl dv
-.Fl f Ar filename
-.Nm
-.Op Fl adPlv
-.Fl D
-.Nm
-.Op Fl dPv
-.Fl F
-.Nm
-.Op Fl h
-.Fl x
-.\"
-.Sh DESCRIPTION
-The
-.Nm
-utility adds, updates, dumps, or flushes
-Security Association Database (SAD) entries
-as well as Security Policy Database (SPD) entries in the kernel.
-.Pp
-The
-.Nm
-utility takes a series of operations from the standard input
-(if invoked with
-.Fl c )
-or the file named
-.Ar filename
-(if invoked with
-.Fl f Ar filename ) .
-.Bl -tag -width Ds
-.It Fl D
-Dump the SAD entries.
-If with
-.Fl P ,
-the SPD entries are dumped.
-.It Fl F
-Flush the SAD entries.
-If with
-.Fl P ,
-the SPD entries are flushed.
-.It Fl a
-Dead SAD entries are usually not displayed with
-.Fl D .
-If with
-.Fl a ,
-the dead SAD entries will be displayed as well.
-A dead SAD entry means that
-it has been expired but remains
-because it is referenced by SPD entries.
-.It Fl d
-Enable to print debugging messages for command parser,
-without talking to kernel.
-It is not used usually.
-.It Fl x
-Loop forever and dump all the messages transmitted to
-.Dv PF_KEY
-socket.
-.Fl xx
-makes each timestamps unformatted.
-.It Fl h
-Add hexadecimal dump on
-.Fl x
-mode.
-.It Fl l
-Loop forever with short output on
-.Fl D .
-.It Fl v
-Be verbose.
-The program will dump messages exchanged on
-.Dv PF_KEY
-socket, including messages sent from other processes to the kernel.
-.El
-.Pp
-Operations have the following grammar.
-Note that lines starting with
-hashmarks ('#') are treated as comment lines.
-.Bl -tag -width Ds
-.It Xo
-.Li add
-.Ar src Ar dst Ar protocol Ar spi
-.Op Ar extensions
-.Ar algorithm...
-.Li ;
-.Xc
-Add an SAD entry.
-.\"
-.It Xo
-.Li get
-.Ar src Ar dst Ar protocol Ar spi
-.Li ;
-.Xc
-Show an SAD entry.
-.\"
-.It Xo
-.Li delete
-.Ar src Ar dst Ar protocol Ar spi
-.Li ;
-.Xc
-Remove an SAD entry.
-.\"
-.It Xo
-.Li deleteall
-.Ar src Ar dst Ar protocol
-.Li ;
-.Xc
-Remove all SAD entries that match the specification.
-.\"
-.It Xo
-.Li flush
-.Op Ar protocol
-.Li ;
-.Xc
-Clear all SAD entries matched by the options.
-.\"
-.It Xo
-.Li dump
-.Op Ar protocol
-.Li ;
-.Xc
-Dumps all SAD entries matched by the options.
-.\"
-.It Xo
-.Li spdadd
-.Ar src_range Ar dst_range Ar upperspec Ar policy
-.Li ;
-.Xc
-Add an SPD entry.
-.\"
-.It Xo
-.Li spddelete
-.Ar src_range Ar dst_range Ar upperspec Fl P Ar direction
-.Li ;
-.Xc
-Delete an SPD entry.
-.\"
-.It Xo
-.Li spdflush
-.Li ;
-.Xc
-Clear all SPD entries.
-.\"
-.It Xo
-.Li spddump
-.Li ;
-.Xc
-Dumps all SPD entries.
-.El
-.\"
-.Pp
-Meta-arguments are as follows:
-.Pp
-.Bl -tag -compact -width Ds
-.It Ar src
-.It Ar dst
-Source/destination of the secure communication is specified as
-IPv4/v6 address.
-The
-.Nm
-utility does not consult hostname-to-address for arguments
-.Ar src
-and
-.Ar dst .
-They must be in numeric form.
-.\"
-.Pp
-.It Ar protocol
-.Ar protocol
-is one of following:
-.Bl -tag -width Fl -compact
-.It Li esp
-ESP based on rfc2405
-.It Li esp-old
-ESP based on rfc1827
-.It Li ah
-AH based on rfc2402
-.It Li ah-old
-AH based on rfc1826
-.It Li ipcomp
-IPCOMP
-.El
-.\"
-.Pp
-.It Ar spi
-Security Parameter Index (SPI) for the SAD and the SPD.
-It must be decimal number or hexadecimal number
-You cannot use the set of SPI values in the range 0 through 255.
-(with
-.Li 0x
-attached).
-.\"
-.Pp
-.It Ar extensions
-takes some of the following:
-.Bl -tag -width Fl -compact
-.\"
-.It Fl m Ar mode
-Specify a security protocol mode for use.
-.Ar mode
-is one of following:
-.Li transport , tunnel
-or
-.Li any .
-The default value is
-.Li any .
-.\"
-.It Fl r Ar size
-Specify window size of bytes for replay prevention.
-.Ar size
-must be decimal number in 32-bit word.
-If
-.Ar size
-is zero or not specified, replay check don't take place.
-.\"
-.It Fl u Ar id
-Specify the identifier of the policy entry in SPD.
-See
-.Ar policy .
-.\"
-.It Fl f Ar pad_option
-defines the content of the ESP padding.
-.Ar pad_option
-is one of following:
-.Bl -tag -width random-pad -compact
-.It Li zero-pad
-All of the padding are zero.
-.It Li random-pad
-A series of randomized values are set.
-.It Li seq-pad
-A series of sequential increasing numbers started from 1 are set.
-.El
-.\"
-.It Fl f Li nocyclic-seq
-Don't allow cyclic sequence number.
-.\"
-.It Fl lh Ar time
-.It Fl ls Ar time
-Specify hard/soft life time duration of the SA.
-.El
-.\"
-.Pp
-.It Ar algorithm
-.Bl -tag -width Fl -compact
-.It Fl E Ar ealgo Ar key
-Specify an encryption algorithm.
-.It Fl A Ar aalgo Ar key
-Specify an authentication algorithm.
-If
-.Fl A
-is used with
-.Ar protocol Li esp ,
-it will be treated as ESP payload authentication algorithm.
-.It Fl C Ar calgo Op Fl R
-Specify compression algorithm.
-If
-.Fl R
-is not specified with
-.Li ipcomp
-line, the kernel will use well-known IPComp CPI
-(compression parameter index)
-on IPComp CPI field on packets, and
-.Ar spi
-field will be ignored.
-.Ar spi
-field is only for kernel internal use in this case.
-.\"Therefore, compression protocol number will appear on IPComp CPI field.
-If
-.Fl R
-is used,
-the value on
-.Ar spi
-field will appear on IPComp CPI field on outgoing packets.
-.Ar spi
-field needs to be smaller than
-.Li 0x10000
-in this case.
-.El
-.Pp
-.Ar protocol Li esp
-accepts
-.Fl E
-and
-.Fl A .
-.Ar protocol Li esp-old
-accepts
-.Fl E
-only.
-.Ar protocol Li ah
-and
-.Li ah-old
-accept
-.Fl A
-only.
-.Ar protocol Li ipcomp
-accepts
-.Fl C
-only.
-.Pp
-.Ar key
-must be double-quoted character string or series of hexadecimal digits.
-.Pp
-Possible values for
-.Ar ealgo ,
-.Ar aalgo
-and
-.Ar calgo
-are specified in separate section.
-.\"
-.Pp
-.It Ar src_range
-.It Ar dst_range
-These are selections of the secure communication specified as
-IPv4/v6 address or IPv4/v6 address range, and it may accompany
-TCP/UDP port specification.
-This takes the following form:
-.Bd -literal -offset
-.Ar address
-.Ar address/prefixlen
-.Ar address[port]
-.Ar address/prefixlen[port]
-.Ed
-.Pp
-.Ar prefixlen
-and
-.Ar port
-must be decimal number.
-The square bracket around
-.Ar port
-is really necessary.
-They are not manpage metacharacters.
-.Pp
-The
-.Nm
-utility does not consult hostname-to-address for arguments
-.Ar src
-and
-.Ar dst .
-They must be in numeric form.
-.\"
-.Pp
-.It Ar upperspec
-Upper-layer protocol to be used.
-You can use one of words in
-.Pa /etc/protocols
-as
-.Ar upperspec .
-Or
-.Li icmp6 ,
-.Li ip4 ,
-and
-.Li any
-can be specified.
-.Li any
-stands for
-.Dq any protocol .
-Also you can use the protocol number.
-.Pp
-NOTE:
-.Ar upperspec
-does not work against forwarding case at this moment,
-as it requires extra reassembly at forwarding node
-(not implemented at this moment).
-We have many protocols in
-.Pa /etc/protocols ,
-but protocols except of TCP, UDP and ICMP may not be suitable to use with IPsec.
-You have to consider and be careful to use them.
-.Li icmp
-.Li tcp
-.Li udp
-all protocols
-.\"
-.Pp
-.It Ar policy
-.Ar policy
-is the one of following:
-.Bd -literal -offset
-.Xo
-.Fl P Ar direction Li discard
-.Xc
-.Xo
-.Fl P Ar direction Li none
-.Xc
-.Xo
-.Fl P Ar direction Li ipsec Ar protocol/mode/src-dst/level
-.Xc
-.Ed
-.Pp
-You must specify the direction of its policy as
-.Ar direction .
-Either
-.Li out
-or
-.Li in
-are used.
-.Li discard
-means the packet matching indexes will be discarded.
-.Li none
-means that IPsec operation will not take place onto the packet.
-.Li ipsec
-means that IPsec operation will take place onto the packet.
-Either
-.Li ah ,
-.Li esp
-or
-.Li ipcomp
-is to be set as
-.Ar protocol .
-.Ar mode
-is either
-.Li transport
-or
-.Li tunnel .
-If
-.Ar mode
-is
-.Li tunnel ,
-you must specify the end-points addresses of the SA as
-.Ar src
-and
-.Ar dst
-with
-.Sq -
-between these addresses which is used to specify the SA to use.
-If
-.Ar mode
-is
-.Li transport ,
-both
-.Ar src
-and
-.Ar dst
-can be omitted.
-.Ar level
-is to be one of the following:
-.Li default , use , require
-or
-.Li unique .
-If the SA is not available in every level, the kernel will request
-getting SA to the key exchange daemon.
-.Li default
-means the kernel consults to the system wide default against protocol you
-specified, e.g.\&
-.Li esp_trans_deflev
-sysctl variable, when the kernel processes the packet.
-.Li use
-means that the kernel use a SA if it's available,
-otherwise the kernel keeps normal operation.
-.Li require
-means SA is required whenever the kernel sends a packet matched
-with the policy.
-.Li unique
-is the same to require.
-In addition, it allows the policy to bind with the unique out-bound SA.
-If you use the SA by manual keying,
-you can put the decimal number as the policy identifier after
-.Li unique
-separated by colon
-.Sq \:
-like the following;
-.Li unique:number .
-.Li number
-must be between 1 and 32767.
-It corresponds to
-.Ar extensions Fl u .
-.Pp
-Note that
-.Dq Li discard
-and
-.Dq Li none
-are not in the syntax described in
-.Xr ipsec_set_policy 3 .
-There are little differences in the syntax.
-See
-.Xr ipsec_set_policy 3
-for detail.
-.Pp
-.El
-.Pp
-.\"
-.Sh ALGORITHMS
-The following list shows the supported algorithms.
-.Sy protocol
-and
-.Sy algorithm
-are almost orthogonal.
-Followings are the list of authentication algorithms that can be used as
-.Ar aalgo
-in
-.Fl A Ar aalgo
-of
-.Ar protocol
-parameter:
-.Pp
-.Bd -literal -offset indent
-algorithm keylen (bits) comment
-hmac-md5 128 ah: rfc2403
- 128 ah-old: rfc2085
-hmac-sha1 160 ah: rfc2404
- 160 ah-old: 128bit ICV (no document)
-keyed-md5 128 ah: 96bit ICV (no document)
- 128 ah-old: rfc1828
-keyed-sha1 160 ah: 96bit ICV (no document)
- 160 ah-old: 128bit ICV (no document)
-null 0 to 2048 for debugging
-hmac-sha2-256 256 ah: 96bit ICV (no document)
- 256 ah-old: 128bit ICV (no document)
-hmac-sha2-384 384 ah: 96bit ICV (no document)
- 384 ah-old: 128bit ICV (no document)
-hmac-sha2-512 512 ah: 96bit ICV (no document)
- 512 ah-old: 128bit ICV (no document)
-.Ed
-.Pp
-Followings are the list of encryption algorithms that can be used as
-.Ar ealgo
-in
-.Fl E Ar ealgo
-of
-.Ar protocol
-parameter:
-.Pp
-.Bd -literal -offset indent
-algorithm keylen (bits) comment
-des-cbc 64 esp-old: rfc1829, esp: rfc2405
-3des-cbc 192 rfc2451
-simple 0 to 2048 rfc2410
-blowfish-cbc 40 to 448 rfc2451
-cast128-cbc 40 to 128 rfc2451
-des-deriv 64 ipsec-ciph-des-derived-01 (expired)
-3des-deriv 192 no document
-rijndael-cbc 128/192/256 draft-ietf-ipsec-ciph-aes-cbc-00
-.Ed
-.Pp
-Followings are the list of compression algorithms that can be used as
-.Ar calgo
-in
-.Fl C Ar calgo
-of
-.Ar protocol
-parameter:
-.Pp
-.Bd -literal -offset indent
-algorithm comment
-deflate rfc2394
-lzs rfc2395
-.Ed
-.\"
-.Sh EXAMPLES
-.Bd -literal -offset
-add 3ffe:501:4819::1 3ffe:501:481d::1 esp 123457
- -E des-cbc "ESP SA!!" ;
-
-add 3ffe:501:4819::1 3ffe:501:481d::1 ah 123456
- -A hmac-sha1 "AH SA configuration!" ;
-
-add 10.0.11.41 10.0.11.33 esp 0x10001
- -E des-cbc "ESP with"
- -A hmac-md5 "authentication!!" ;
-
-get 3ffe:501:4819::1 3ffe:501:481d::1 ah 123456 ;
-
-flush ;
-
-dump esp ;
-
-spdadd 10.0.11.41/32[21] 10.0.11.33/32[any] any
- -P out ipsec esp/tunnel/192.168.0.1-192.168.1.2/require ;
-
-.Ed
-.\"
-.Sh RETURN VALUES
-The command exits with 0 on success, and non-zero on errors.
-.\"
-.Sh SEE ALSO
-.Xr ipsec_set_policy 3 ,
-.Xr racoon 8 ,
-.Xr sysctl 8
-.\"
-.Sh HISTORY
-The
-.Nm
-utility first appeared in WIDE Hydrangea IPv6 protocol stack kit.
-The command was completely re-designed in June 1998.
-.\"
-.\" .Sh BUGS
diff --git a/sbin/setkey/setkey.c b/sbin/setkey/setkey.c
deleted file mode 100644
index e3e87f28262e..000000000000
--- a/sbin/setkey/setkey.c
+++ /dev/null
@@ -1,648 +0,0 @@
-/* $FreeBSD$ */
-/* $KAME: setkey.c,v 1.18 2001/05/08 04:36:39 itojun Exp $ */
-
-/*
- * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
- * 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <err.h>
-#include <net/route.h>
-#include <netinet/in.h>
-#include <net/pfkeyv2.h>
-#include <netkey/keydb.h>
-#include <netkey/key_debug.h>
-#include <netinet6/ipsec.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <string.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <errno.h>
-#include <netdb.h>
-
-#include "libpfkey.h"
-
-void Usage __P((void));
-int main __P((int, char **));
-int get_supported __P((void));
-void sendkeyshort __P((u_int));
-void promisc __P((void));
-int sendkeymsg __P((void));
-int postproc __P((struct sadb_msg *, int));
-const char *numstr __P((int));
-void shortdump_hdr __P((void));
-void shortdump __P((struct sadb_msg *));
-static void printdate __P((void));
-static int32_t gmt2local __P((time_t));
-
-#define MODE_SCRIPT 1
-#define MODE_CMDDUMP 2
-#define MODE_CMDFLUSH 3
-#define MODE_PROMISC 4
-
-int so;
-
-int f_forever = 0;
-int f_all = 0;
-int f_debug = 0;
-int f_verbose = 0;
-int f_mode = 0;
-int f_cmddump = 0;
-int f_policy = 0;
-int f_hexdump = 0;
-int f_tflag = 0;
-char *pname;
-
-u_char m_buf[BUFSIZ];
-u_int m_len;
-
-static time_t thiszone;
-
-extern int lineno;
-
-extern int parse __P((FILE **));
-
-void
-Usage()
-{
- printf("Usage:\t%s [-dv] -c\n", pname);
- printf("\t%s [-dv] -f (file)\n", pname);
- printf("\t%s [-Padlv] -D\n", pname);
- printf("\t%s [-Pdv] -F\n", pname);
- printf("\t%s [-h] -x\n", pname);
- pfkey_close(so);
- exit(1);
-}
-
-int
-main(ac, av)
- int ac;
- char **av;
-{
- FILE *fp = stdin;
- int c;
-
- pname = *av;
-
- if (ac == 1) Usage();
-
- thiszone = gmt2local(0);
-
- while ((c = getopt(ac, av, "acdf:hlvxDFP")) != -1) {
- switch (c) {
- case 'c':
- f_mode = MODE_SCRIPT;
- fp = stdin;
- break;
- case 'f':
- f_mode = MODE_SCRIPT;
- if ((fp = fopen(optarg, "r")) == NULL) {
- err(-1, "fopen");
- /*NOTREACHED*/
- }
- break;
- case 'D':
- f_mode = MODE_CMDDUMP;
- break;
- case 'F':
- f_mode = MODE_CMDFLUSH;
- break;
- case 'a':
- f_all = 1;
- break;
- case 'l':
- f_forever = 1;
- break;
- case 'h':
- f_hexdump = 1;
- break;
- case 'x':
- f_mode = MODE_PROMISC;
- f_tflag++;
- break;
- case 'P':
- f_policy = 1;
- break;
- case 'd':
- f_debug = 1;
- break;
- case 'v':
- f_verbose = 1;
- break;
- default:
- Usage();
- /*NOTREACHED*/
- }
- }
-
- switch (f_mode) {
- case MODE_CMDDUMP:
- sendkeyshort(f_policy ? SADB_X_SPDDUMP: SADB_DUMP);
- break;
- case MODE_CMDFLUSH:
- sendkeyshort(f_policy ? SADB_X_SPDFLUSH: SADB_FLUSH);
- pfkey_close(so);
- break;
- case MODE_SCRIPT:
- if (get_supported() < 0) {
- errx(-1, "%s", ipsec_strerror());
- /*NOTREACHED*/
- }
- if (parse(&fp))
- exit (1);
- break;
- case MODE_PROMISC:
- promisc();
- /*NOTREACHED*/
- default:
- Usage();
- /*NOTREACHED*/
- }
-
- exit(0);
-}
-
-int
-get_supported()
-{
- int so;
-
- if ((so = pfkey_open()) < 0) {
- perror("pfkey_open");
- return -1;
- }
-
- /* debug mode ? */
- if (f_debug)
- return 0;
-
- if (pfkey_send_register(so, SADB_SATYPE_UNSPEC) < 0)
- return -1;
-
- if (pfkey_recv_register(so) < 0)
- return -1;
-
- return 0;
-}
-
-void
-sendkeyshort(type)
- u_int type;
-{
- struct sadb_msg *m_msg = (struct sadb_msg *)m_buf;
-
- m_len = sizeof(struct sadb_msg);
-
- m_msg->sadb_msg_version = PF_KEY_V2;
- m_msg->sadb_msg_type = type;
- m_msg->sadb_msg_errno = 0;
- m_msg->sadb_msg_satype = SADB_SATYPE_UNSPEC;
- m_msg->sadb_msg_len = PFKEY_UNIT64(m_len);
- m_msg->sadb_msg_reserved = 0;
- m_msg->sadb_msg_seq = 0;
- m_msg->sadb_msg_pid = getpid();
-
- sendkeymsg();
-
- return;
-}
-
-void
-promisc()
-{
- struct sadb_msg *m_msg = (struct sadb_msg *)m_buf;
- u_char rbuf[1024 * 32]; /* XXX: Enough ? Should I do MSG_PEEK ? */
- int so, len;
-
- m_len = sizeof(struct sadb_msg);
-
- m_msg->sadb_msg_version = PF_KEY_V2;
- m_msg->sadb_msg_type = SADB_X_PROMISC;
- m_msg->sadb_msg_errno = 0;
- m_msg->sadb_msg_satype = 1;
- m_msg->sadb_msg_len = PFKEY_UNIT64(m_len);
- m_msg->sadb_msg_reserved = 0;
- m_msg->sadb_msg_seq = 0;
- m_msg->sadb_msg_pid = getpid();
-
- if ((so = socket(PF_KEY, SOCK_RAW, PF_KEY_V2)) < 0) {
- err(1, "socket(PF_KEY)");
- /*NOTREACHED*/
- }
-
- if ((len = send(so, m_buf, m_len, 0)) < 0) {
- err(1, "send");
- /*NOTREACHED*/
- }
-
- while (1) {
- struct sadb_msg *base;
-
- if ((len = recv(so, rbuf, sizeof(*base), MSG_PEEK)) < 0) {
- err(1, "recv");
- /*NOTREACHED*/
- }
-
- if (len != sizeof(*base))
- continue;
-
- base = (struct sadb_msg *)rbuf;
- if ((len = recv(so, rbuf, PFKEY_UNUNIT64(base->sadb_msg_len),
- 0)) < 0) {
- err(1, "recv");
- /*NOTREACHED*/
- }
- printdate();
- if (f_hexdump) {
- int i;
- for (i = 0; i < len; i++) {
- if (i % 16 == 0)
- printf("%08x: ", i);
- printf("%02x ", rbuf[i] & 0xff);
- if (i % 16 == 15)
- printf("\n");
- }
- if (len % 16)
- printf("\n");
- }
- /* adjust base pointer for promisc mode */
- if (base->sadb_msg_type == SADB_X_PROMISC) {
- if (sizeof(*base) < len)
- base++;
- else
- base = NULL;
- }
- if (base) {
- kdebug_sadb(base);
- printf("\n");
- fflush(stdout);
- }
- }
-}
-
-int
-sendkeymsg()
-{
- int so;
-
- u_char rbuf[1024 * 32]; /* XXX: Enough ? Should I do MSG_PEEK ? */
- int len;
- struct sadb_msg *msg;
-
- if ((so = pfkey_open()) < 0) {
- perror("pfkey_open");
- return -1;
- }
-
- {
- struct timeval tv;
- tv.tv_sec = 1;
- tv.tv_usec = 0;
- if (setsockopt(so, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
- perror("setsockopt");
- goto end;
- }
- }
-
- if (f_forever)
- shortdump_hdr();
-again:
- if (f_verbose) {
- kdebug_sadb((struct sadb_msg *)m_buf);
- printf("\n");
- }
-
- if ((len = send(so, m_buf, m_len, 0)) < 0) {
- perror("send");
- goto end;
- }
-
- msg = (struct sadb_msg *)rbuf;
- do {
- if ((len = recv(so, rbuf, sizeof(rbuf), 0)) < 0) {
- perror("recv");
- goto end;
- }
-
- if (PFKEY_UNUNIT64(msg->sadb_msg_len) != len) {
- warnx("invalid keymsg length");
- break;
- }
-
- if (f_verbose) {
- kdebug_sadb((struct sadb_msg *)rbuf);
- printf("\n");
- }
- if (postproc(msg, len) < 0)
- break;
- } while (msg->sadb_msg_errno || msg->sadb_msg_seq);
-
- if (f_forever) {
- fflush(stdout);
- sleep(1);
- goto again;
- }
-
-end:
- pfkey_close(so);
- return(0);
-}
-
-int
-postproc(msg, len)
- struct sadb_msg *msg;
- int len;
-{
-
- if (msg->sadb_msg_errno != 0) {
- char inf[80];
- char *errmsg = NULL;
-
- if (f_mode == MODE_SCRIPT)
- snprintf(inf, sizeof(inf), "The result of line %d: ", lineno);
- else
- inf[0] = '\0';
-
- switch (msg->sadb_msg_errno) {
- case ENOENT:
- switch (msg->sadb_msg_type) {
- case SADB_DELETE:
- case SADB_GET:
- case SADB_X_SPDDELETE:
- errmsg = "No entry";
- break;
- case SADB_DUMP:
- errmsg = "No SAD entries";
- break;
- case SADB_X_SPDDUMP:
- errmsg = "No SPD entries";
- break;
- }
- break;
- default:
- errmsg = strerror(msg->sadb_msg_errno);
- }
- printf("%s%s.\n", inf, errmsg);
- return(-1);
- }
-
- switch (msg->sadb_msg_type) {
- case SADB_GET:
- pfkey_sadump(msg);
- break;
-
- case SADB_DUMP:
- /* filter out DEAD SAs */
- if (!f_all) {
- caddr_t mhp[SADB_EXT_MAX + 1];
- struct sadb_sa *sa;
- pfkey_align(msg, mhp);
- pfkey_check(mhp);
- if ((sa = (struct sadb_sa *)mhp[SADB_EXT_SA]) != NULL) {
- if (sa->sadb_sa_state == SADB_SASTATE_DEAD)
- break;
- }
- }
- if (f_forever)
- shortdump(msg);
- else
- pfkey_sadump(msg);
- msg = (struct sadb_msg *)((caddr_t)msg +
- PFKEY_UNUNIT64(msg->sadb_msg_len));
- if (f_verbose) {
- kdebug_sadb((struct sadb_msg *)msg);
- printf("\n");
- }
- break;
-
- case SADB_X_SPDDUMP:
- pfkey_spdump(msg);
- if (msg->sadb_msg_seq == 0) break;
- msg = (struct sadb_msg *)((caddr_t)msg +
- PFKEY_UNUNIT64(msg->sadb_msg_len));
- if (f_verbose) {
- kdebug_sadb((struct sadb_msg *)msg);
- printf("\n");
- }
- break;
- }
-
- return(0);
-}
-
-/*------------------------------------------------------------*/
-static char *satype[] = {
- NULL, NULL, "ah", "esp"
-};
-static char *sastate[] = {
- "L", "M", "D", "d"
-};
-static char *ipproto[] = {
-/*0*/ "ip", "icmp", "igmp", "ggp", "ip4",
- NULL, "tcp", NULL, "egp", NULL,
-/*10*/ NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, "udp", NULL, NULL,
-/*20*/ NULL, NULL, "idp", NULL, NULL,
- NULL, NULL, NULL, NULL, "tp",
-/*30*/ NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL,
-/*40*/ NULL, "ip6", NULL, "rt6", "frag6",
- NULL, "rsvp", "gre", NULL, NULL,
-/*50*/ "esp", "ah", NULL, NULL, NULL,
- NULL, NULL, NULL, "icmp6", "none",
-/*60*/ "dst6",
-};
-
-#define STR_OR_ID(x, tab) \
- (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
-
-const char *
-numstr(x)
- int x;
-{
- static char buf[20];
- snprintf(buf, sizeof(buf), "#%d", x);
- return buf;
-}
-
-void
-shortdump_hdr()
-{
- printf("%-4s %-3s %-1s %-8s %-7s %s -> %s\n",
- "time", "p", "s", "spi", "ltime", "src", "dst");
-}
-
-void
-shortdump(msg)
- struct sadb_msg *msg;
-{
- caddr_t mhp[SADB_EXT_MAX + 1];
- char buf[NI_MAXHOST], pbuf[NI_MAXSERV];
- struct sadb_sa *sa;
- struct sadb_address *saddr;
- struct sadb_lifetime *lts, *lth, *ltc;
- struct sockaddr *s;
- u_int t;
- time_t cur = time(0);
-
- pfkey_align(msg, mhp);
- pfkey_check(mhp);
-
- printf("%02lu%02lu", (u_long)(cur % 3600) / 60, (u_long)(cur % 60));
-
- printf(" %-3s", STR_OR_ID(msg->sadb_msg_satype, satype));
-
- if ((sa = (struct sadb_sa *)mhp[SADB_EXT_SA]) != NULL) {
- printf(" %-1s", STR_OR_ID(sa->sadb_sa_state, sastate));
- printf(" %08x", (u_int32_t)ntohl(sa->sadb_sa_spi));
- } else
- printf("%-1s %-8s", "?", "?");
-
- lts = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_SOFT];
- lth = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_HARD];
- ltc = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_CURRENT];
- if (lts && lth && ltc) {
- if (ltc->sadb_lifetime_addtime == 0)
- t = (u_long)0;
- else
- t = (u_long)(cur - ltc->sadb_lifetime_addtime);
- if (t >= 1000)
- strcpy(buf, " big/");
- else
- snprintf(buf, sizeof(buf), " %3lu/", (u_long)t);
- printf("%s", buf);
-
- t = (u_long)lth->sadb_lifetime_addtime;
- if (t >= 1000)
- strcpy(buf, "big");
- else
- snprintf(buf, sizeof(buf), "%-3lu", (u_long)t);
- printf("%s", buf);
- } else
- printf(" ??\?/???"); /* backslash to avoid trigraph ??/ */
-
- printf(" ");
-
- if ((saddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_SRC]) != NULL) {
- if (saddr->sadb_address_proto)
- printf("%s ", STR_OR_ID(saddr->sadb_address_proto, ipproto));
- s = (struct sockaddr *)(saddr + 1);
- getnameinfo(s, s->sa_len, buf, sizeof(buf),
- pbuf, sizeof(pbuf), NI_NUMERICHOST|NI_NUMERICSERV);
- if (strcmp(pbuf, "0") != 0)
- printf("%s[%s]", buf, pbuf);
- else
- printf("%s", buf);
- } else
- printf("?");
-
- printf(" -> ");
-
- if ((saddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_DST]) != NULL) {
- if (saddr->sadb_address_proto)
- printf("%s ", STR_OR_ID(saddr->sadb_address_proto, ipproto));
-
- s = (struct sockaddr *)(saddr + 1);
- getnameinfo(s, s->sa_len, buf, sizeof(buf),
- pbuf, sizeof(pbuf), NI_NUMERICHOST|NI_NUMERICSERV);
- if (strcmp(pbuf, "0") != 0)
- printf("%s[%s]", buf, pbuf);
- else
- printf("%s", buf);
- } else
- printf("?");
-
- printf("\n");
-}
-
-/* From: tcpdump(1):gmt2local.c and util.c */
-/*
- * Print the timestamp
- */
-static void
-printdate()
-{
- struct timeval tp;
- int s;
-
- if (gettimeofday(&tp, NULL) == -1) {
- perror("gettimeofday");
- return;
- }
-
- if (f_tflag == 1) {
- /* Default */
- s = (tp.tv_sec + thiszone ) % 86400;
- (void)printf("%02d:%02d:%02d.%06u ",
- s / 3600, (s % 3600) / 60, s % 60, (u_int32_t)tp.tv_usec);
- } else if (f_tflag > 1) {
- /* Unix timeval style */
- (void)printf("%u.%06u ",
- (u_int32_t)tp.tv_sec, (u_int32_t)tp.tv_usec);
- }
-
- printf("\n");
-}
-
-/*
- * Returns the difference between gmt and local time in seconds.
- * Use gmtime() and localtime() to keep things simple.
- */
-int32_t
-gmt2local(time_t t)
-{
- register int dt, dir;
- register struct tm *gmt, *loc;
- struct tm sgmt;
-
- if (t == 0)
- t = time(NULL);
- gmt = &sgmt;
- *gmt = *gmtime(&t);
- loc = localtime(&t);
- dt = (loc->tm_hour - gmt->tm_hour) * 60 * 60 +
- (loc->tm_min - gmt->tm_min) * 60;
-
- /*
- * If the year or julian day is different, we span 00:00 GMT
- * and must add or subtract a day. Check the year first to
- * avoid problems when the julian day wraps.
- */
- dir = loc->tm_year - gmt->tm_year;
- if (dir == 0)
- dir = loc->tm_yday - gmt->tm_yday;
- dt += dir * 24 * 60 * 60;
-
- return (dt);
-}
diff --git a/sbin/setkey/test-pfkey.c b/sbin/setkey/test-pfkey.c
deleted file mode 100644
index b1fb238c5a41..000000000000
--- a/sbin/setkey/test-pfkey.c
+++ /dev/null
@@ -1,531 +0,0 @@
-/* $FreeBSD$ */
-/* $KAME: test-pfkey.c,v 1.4 2000/06/07 00:29:14 itojun Exp $ */
-
-/*
- * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
- * 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <net/route.h>
-#include <net/pfkeyv2.h>
-#include <netinet/in.h>
-#include <netkey/keydb.h>
-#include <netkey/key_var.h>
-#include <netkey/key_debug.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <string.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <errno.h>
-#include <netdb.h>
-
-u_char m_buf[BUFSIZ];
-u_int m_len;
-char *pname;
-
-void Usage __P((void));
-int sendkeymsg __P((void));
-void key_setsadbmsg __P((u_int));
-void key_setsadbsens __P((void));
-void key_setsadbprop __P((void));
-void key_setsadbid __P((u_int, caddr_t));
-void key_setsadblft __P((u_int, u_int));
-void key_setspirange __P((void));
-void key_setsadbkey __P((u_int, caddr_t));
-void key_setsadbsa __P((void));
-void key_setsadbaddr __P((u_int, u_int, caddr_t));
-void key_setsadbextbuf __P((caddr_t, int, caddr_t, int, caddr_t, int));
-
-void
-Usage()
-{
- printf("Usage:\t%s number\n", pname);
- exit(0);
-}
-
-int
-main(ac, av)
- int ac;
- char **av;
-{
- pname = *av;
-
- if (ac == 1) Usage();
-
- key_setsadbmsg(atoi(*(av+1)));
- sendkeymsg();
-
- exit(0);
-}
-
-/* %%% */
-int
-sendkeymsg()
-{
- u_char rbuf[1024 * 32]; /* XXX: Enough ? Should I do MSG_PEEK ? */
- int so, len;
-
- if ((so = socket(PF_KEY, SOCK_RAW, PF_KEY_V2)) < 0) {
- perror("socket(PF_KEY)");
- goto end;
- }
-#if 0
- {
-#include <sys/time.h>
- struct timeval tv;
- tv.tv_sec = 1;
- tv.tv_usec = 0;
- if (setsockopt(so, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
- perror("setsockopt");
- goto end;
- }
- }
-#endif
-
- pfkey_sadump((struct sadb_msg *)m_buf);
-
- if ((len = send(so, m_buf, m_len, 0)) < 0) {
- perror("send");
- goto end;
- }
-
- if ((len = recv(so, rbuf, sizeof(rbuf), 0)) < 0) {
- perror("recv");
- goto end;
- }
-
- pfkey_sadump((struct sadb_msg *)rbuf);
-
-end:
- (void)close(so);
- return(0);
-}
-
-void
-key_setsadbmsg(type)
- u_int type;
-{
- struct sadb_msg m_msg;
-
- memset(&m_msg, 0, sizeof(m_msg));
- m_msg.sadb_msg_version = PF_KEY_V2;
- m_msg.sadb_msg_type = type;
- m_msg.sadb_msg_errno = 0;
- m_msg.sadb_msg_satype = SADB_SATYPE_ESP;
-#if 0
- m_msg.sadb_msg_reserved = 0;
-#endif
- m_msg.sadb_msg_seq = 0;
- m_msg.sadb_msg_pid = getpid();
-
- m_len = sizeof(struct sadb_msg);
- memcpy(m_buf, &m_msg, m_len);
-
- switch (type) {
- case SADB_GETSPI:
- /*<base, address(SD), SPI range>*/
- key_setsadbaddr(SADB_EXT_ADDRESS_SRC, AF_INET, "10.0.3.4");
- key_setsadbaddr(SADB_EXT_ADDRESS_DST, AF_INET, "127.0.0.1");
- key_setspirange();
- /*<base, SA(*), address(SD)>*/
- break;
-
- case SADB_ADD:
- /* <base, SA, (lifetime(HSC),) address(SD), (address(P),)
- key(AE), (identity(SD),) (sensitivity)> */
- key_setsadbaddr(SADB_EXT_ADDRESS_PROXY, AF_INET6, "3ffe::1");
- case SADB_UPDATE:
- key_setsadbsa();
- key_setsadblft(SADB_EXT_LIFETIME_HARD, 10);
- key_setsadblft(SADB_EXT_LIFETIME_SOFT, 5);
- key_setsadbaddr(SADB_EXT_ADDRESS_SRC, AF_INET, "192.168.1.1");
- key_setsadbaddr(SADB_EXT_ADDRESS_DST, AF_INET, "10.0.3.4");
- /* XXX key_setsadbkey(SADB_EXT_KEY_AUTH, "abcde"); */
- key_setsadbkey(SADB_EXT_KEY_AUTH, "1234567812345678");
- key_setsadbkey(SADB_EXT_KEY_ENCRYPT, "12345678");
- key_setsadbid(SADB_EXT_IDENTITY_SRC, "hoge1234@hoge.com");
- key_setsadbid(SADB_EXT_IDENTITY_DST, "hage5678@hage.net");
- key_setsadbsens();
- /* <base, SA, (lifetime(HSC),) address(SD), (address(P),)
- (identity(SD),) (sensitivity)> */
- break;
-
- case SADB_DELETE:
- /* <base, SA(*), address(SDP)> */
- key_setsadbsa();
- key_setsadbaddr(SADB_EXT_ADDRESS_SRC, AF_INET, "192.168.1.1");
- key_setsadbaddr(SADB_EXT_ADDRESS_DST, AF_INET, "10.0.3.4");
- key_setsadbaddr(SADB_EXT_ADDRESS_PROXY, AF_INET6, "3ffe::1");
- /* <base, SA(*), address(SDP)> */
- break;
-
- case SADB_GET:
- /* <base, SA(*), address(SDP)> */
- key_setsadbsa();
- key_setsadbaddr(SADB_EXT_ADDRESS_SRC, AF_INET, "192.168.1.1");
- key_setsadbaddr(SADB_EXT_ADDRESS_DST, AF_INET, "10.0.3.4");
- key_setsadbaddr(SADB_EXT_ADDRESS_PROXY, AF_INET6, "3ffe::1");
- /* <base, SA, (lifetime(HSC),) address(SD), (address(P),)
- key(AE), (identity(SD),) (sensitivity)> */
- break;
-
- case SADB_ACQUIRE:
- /* <base, address(SD), (address(P),) (identity(SD),)
- (sensitivity,) proposal> */
- key_setsadbaddr(SADB_EXT_ADDRESS_SRC, AF_INET, "192.168.1.1");
- key_setsadbaddr(SADB_EXT_ADDRESS_DST, AF_INET, "10.0.3.4");
- key_setsadbaddr(SADB_EXT_ADDRESS_PROXY, AF_INET6, "3ffe::1");
- key_setsadbid(SADB_EXT_IDENTITY_SRC, "hoge1234@hoge.com");
- key_setsadbid(SADB_EXT_IDENTITY_DST, "hage5678@hage.net");
- key_setsadbsens();
- key_setsadbprop();
- /* <base, address(SD), (address(P),) (identity(SD),)
- (sensitivity,) proposal> */
- break;
-
- case SADB_REGISTER:
- /* <base> */
- /* <base, supported> */
- break;
-
- case SADB_EXPIRE:
- case SADB_FLUSH:
- break;
-
- case SADB_DUMP:
- break;
-
- case SADB_X_PROMISC:
- /* <base> */
- /* <base, base(, others)> */
- break;
-
- case SADB_X_PCHANGE:
- break;
-
- /* for SPD management */
- case SADB_X_SPDFLUSH:
- case SADB_X_SPDDUMP:
- break;
-
- case SADB_X_SPDADD:
-#if 0
- {
- struct sadb_x_policy m_policy;
-
- m_policy.sadb_x_policy_len = PFKEY_UNIT64(sizeof(m_policy));
- m_policy.sadb_x_policy_exttype = SADB_X_EXT_POLICY;
- m_policy.sadb_x_policy_type = SADB_X_PL_IPSEC;
- m_policy.sadb_x_policy_esp_trans = 1;
- m_policy.sadb_x_policy_ah_trans = 2;
- m_policy.sadb_x_policy_esp_network = 3;
- m_policy.sadb_x_policy_ah_network = 4;
- m_policy.sadb_x_policy_reserved = 0;
-
- memcpy(m_buf + m_len, &m_policy, sizeof(struct sadb_x_policy));
- m_len += sizeof(struct sadb_x_policy);
- }
-#endif
-
- case SADB_X_SPDDELETE:
- key_setsadbaddr(SADB_EXT_ADDRESS_SRC, AF_INET, "192.168.1.1");
- key_setsadbaddr(SADB_EXT_ADDRESS_DST, AF_INET, "10.0.3.4");
- break;
- }
-
- ((struct sadb_msg *)m_buf)->sadb_msg_len = PFKEY_UNIT64(m_len);
-
- return;
-}
-
-void
-key_setsadbsens()
-{
- struct sadb_sens m_sens;
- u_char buf[64];
- u_int s, i, slen, ilen, len;
-
- /* make sens & integ */
- s = htonl(0x01234567);
- i = htonl(0x89abcdef);
- slen = sizeof(s);
- ilen = sizeof(i);
- memcpy(buf, &s, slen);
- memcpy(buf + slen, &i, ilen);
-
- len = sizeof(m_sens) + PFKEY_ALIGN8(slen) + PFKEY_ALIGN8(ilen);
- m_sens.sadb_sens_len = PFKEY_UNIT64(len);
- m_sens.sadb_sens_exttype = SADB_EXT_SENSITIVITY;
- m_sens.sadb_sens_dpd = 1;
- m_sens.sadb_sens_sens_level = 2;
- m_sens.sadb_sens_sens_len = PFKEY_ALIGN8(slen);
- m_sens.sadb_sens_integ_level = 3;
- m_sens.sadb_sens_integ_len = PFKEY_ALIGN8(ilen);
- m_sens.sadb_sens_reserved = 0;
-
- key_setsadbextbuf(m_buf, m_len,
- (caddr_t)&m_sens, sizeof(struct sadb_sens),
- buf, slen + ilen);
- m_len += len;
-
- return;
-}
-
-void
-key_setsadbprop()
-{
- struct sadb_prop m_prop;
- struct sadb_comb *m_comb;
- u_char buf[256];
- u_int len = sizeof(m_prop) + sizeof(m_comb) * 2;
-
- /* make prop & comb */
- m_prop.sadb_prop_len = PFKEY_UNIT64(len);
- m_prop.sadb_prop_exttype = SADB_EXT_PROPOSAL;
- m_prop.sadb_prop_replay = 0;
- m_prop.sadb_prop_reserved[0] = 0;
- m_prop.sadb_prop_reserved[1] = 0;
- m_prop.sadb_prop_reserved[2] = 0;
-
- /* the 1st is ESP DES-CBC HMAC-MD5 */
- m_comb = (struct sadb_comb *)buf;
- m_comb->sadb_comb_auth = SADB_AALG_MD5HMAC;
- m_comb->sadb_comb_encrypt = SADB_EALG_DESCBC;
- m_comb->sadb_comb_flags = 0;
- m_comb->sadb_comb_auth_minbits = 8;
- m_comb->sadb_comb_auth_maxbits = 96;
- m_comb->sadb_comb_encrypt_minbits = 64;
- m_comb->sadb_comb_encrypt_maxbits = 64;
- m_comb->sadb_comb_reserved = 0;
- m_comb->sadb_comb_soft_allocations = 0;
- m_comb->sadb_comb_hard_allocations = 0;
- m_comb->sadb_comb_soft_bytes = 0;
- m_comb->sadb_comb_hard_bytes = 0;
- m_comb->sadb_comb_soft_addtime = 0;
- m_comb->sadb_comb_hard_addtime = 0;
- m_comb->sadb_comb_soft_usetime = 0;
- m_comb->sadb_comb_hard_usetime = 0;
-
- /* the 2st is ESP 3DES-CBC and AH HMAC-SHA1 */
- m_comb = (struct sadb_comb *)(buf + sizeof(*m_comb));
- m_comb->sadb_comb_auth = SADB_AALG_SHA1HMAC;
- m_comb->sadb_comb_encrypt = SADB_EALG_3DESCBC;
- m_comb->sadb_comb_flags = 0;
- m_comb->sadb_comb_auth_minbits = 8;
- m_comb->sadb_comb_auth_maxbits = 96;
- m_comb->sadb_comb_encrypt_minbits = 64;
- m_comb->sadb_comb_encrypt_maxbits = 64;
- m_comb->sadb_comb_reserved = 0;
- m_comb->sadb_comb_soft_allocations = 0;
- m_comb->sadb_comb_hard_allocations = 0;
- m_comb->sadb_comb_soft_bytes = 0;
- m_comb->sadb_comb_hard_bytes = 0;
- m_comb->sadb_comb_soft_addtime = 0;
- m_comb->sadb_comb_hard_addtime = 0;
- m_comb->sadb_comb_soft_usetime = 0;
- m_comb->sadb_comb_hard_usetime = 0;
-
- key_setsadbextbuf(m_buf, m_len,
- (caddr_t)&m_prop, sizeof(struct sadb_prop),
- buf, sizeof(*m_comb) * 2);
- m_len += len;
-
- return;
-}
-
-void
-key_setsadbid(ext, str)
- u_int ext;
- caddr_t str;
-{
- struct sadb_ident m_id;
- u_int idlen = strlen(str), len;
-
- len = sizeof(m_id) + PFKEY_ALIGN8(idlen);
- m_id.sadb_ident_len = PFKEY_UNIT64(len);
- m_id.sadb_ident_exttype = ext;
- m_id.sadb_ident_type = SADB_IDENTTYPE_USERFQDN;
- m_id.sadb_ident_reserved = 0;
- m_id.sadb_ident_id = getpid();
-
- key_setsadbextbuf(m_buf, m_len,
- (caddr_t)&m_id, sizeof(struct sadb_ident),
- str, idlen);
- m_len += len;
-
- return;
-}
-
-void
-key_setsadblft(ext, time)
- u_int ext, time;
-{
- struct sadb_lifetime m_lft;
-
- m_lft.sadb_lifetime_len = PFKEY_UNIT64(sizeof(m_lft));
- m_lft.sadb_lifetime_exttype = ext;
- m_lft.sadb_lifetime_allocations = 0x2;
- m_lft.sadb_lifetime_bytes = 0x1000;
- m_lft.sadb_lifetime_addtime = time;
- m_lft.sadb_lifetime_usetime = 0x0020;
-
- memcpy(m_buf + m_len, &m_lft, sizeof(struct sadb_lifetime));
- m_len += sizeof(struct sadb_lifetime);
-
- return;
-}
-
-void
-key_setspirange()
-{
- struct sadb_spirange m_spi;
-
- m_spi.sadb_spirange_len = PFKEY_UNIT64(sizeof(m_spi));
- m_spi.sadb_spirange_exttype = SADB_EXT_SPIRANGE;
- m_spi.sadb_spirange_min = 0x00001000;
- m_spi.sadb_spirange_max = 0x00002000;
- m_spi.sadb_spirange_reserved = 0;
-
- memcpy(m_buf + m_len, &m_spi, sizeof(struct sadb_spirange));
- m_len += sizeof(struct sadb_spirange);
-
- return;
-}
-
-void
-key_setsadbkey(ext, str)
- u_int ext;
- caddr_t str;
-{
- struct sadb_key m_key;
- u_int keylen = strlen(str);
- u_int len;
-
- len = sizeof(struct sadb_key) + PFKEY_ALIGN8(keylen);
- m_key.sadb_key_len = PFKEY_UNIT64(len);
- m_key.sadb_key_exttype = ext;
- m_key.sadb_key_bits = keylen * 8;
- m_key.sadb_key_reserved = 0;
-
- key_setsadbextbuf(m_buf, m_len,
- (caddr_t)&m_key, sizeof(struct sadb_key),
- str, keylen);
- m_len += len;
-
- return;
-}
-
-void
-key_setsadbsa()
-{
- struct sadb_sa m_sa;
-
- m_sa.sadb_sa_len = PFKEY_UNIT64(sizeof(struct sadb_sa));
- m_sa.sadb_sa_exttype = SADB_EXT_SA;
- m_sa.sadb_sa_spi = htonl(0x12345678);
- m_sa.sadb_sa_replay = 4;
- m_sa.sadb_sa_state = 0;
- m_sa.sadb_sa_auth = SADB_AALG_MD5HMAC;
- m_sa.sadb_sa_encrypt = SADB_EALG_DESCBC;
- m_sa.sadb_sa_flags = 0;
-
- memcpy(m_buf + m_len, &m_sa, sizeof(struct sadb_sa));
- m_len += sizeof(struct sadb_sa);
-
- return;
-}
-
-void
-key_setsadbaddr(ext, af, str)
- u_int ext, af;
- caddr_t str;
-{
- struct sadb_address m_addr;
- u_int len;
- struct addrinfo hints, *res;
- const char *serv;
- int plen;
-
- switch (af) {
- case AF_INET:
- plen = sizeof(struct in_addr) << 3;
- break;
- case AF_INET6:
- plen = sizeof(struct in6_addr) << 3;
- break;
- default:
- /* XXX bark */
- exit(1);
- }
-
- /* make sockaddr buffer */
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = af;
- hints.ai_socktype = SOCK_DGRAM; /*dummy*/
- hints.ai_flags = AI_NUMERICHOST;
- serv = (ext == SADB_EXT_ADDRESS_PROXY ? "0" : "4660"); /*0x1234*/
- if (getaddrinfo(str, serv, &hints, &res) != 0 || res->ai_next) {
- /* XXX bark */
- exit(1);
- }
-
- len = sizeof(struct sadb_address) + PFKEY_ALIGN8(res->ai_addrlen);
- m_addr.sadb_address_len = PFKEY_UNIT64(len);
- m_addr.sadb_address_exttype = ext;
- m_addr.sadb_address_proto =
- (ext == SADB_EXT_ADDRESS_PROXY ? 0 : IPPROTO_TCP);
- m_addr.sadb_address_prefixlen = plen;
- m_addr.sadb_address_reserved = 0;
-
- key_setsadbextbuf(m_buf, m_len,
- (caddr_t)&m_addr, sizeof(struct sadb_address),
- (caddr_t)res->ai_addr, res->ai_addrlen);
- m_len += len;
-
- freeaddrinfo(res);
-
- return;
-}
-
-void
-key_setsadbextbuf(dst, off, ebuf, elen, vbuf, vlen)
- caddr_t dst, ebuf, vbuf;
- int off, elen, vlen;
-{
- memset(dst + off, 0, elen + vlen);
- memcpy(dst + off, (caddr_t)ebuf, elen);
- memcpy(dst + off + elen, vbuf, vlen);
-
- return;
-}
-
diff --git a/sbin/setkey/test-policy.c b/sbin/setkey/test-policy.c
deleted file mode 100644
index 27cd478fc939..000000000000
--- a/sbin/setkey/test-policy.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
- * 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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$
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet6/in6.h>
-#include <netkey/keyv2.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <netinet6/ipsec.h>
-
-char *requests[] = {
-"must_error", /* must be error */
-"ipsec must_error", /* must be error */
-"ipsec esp/must_error", /* must be error */
-"discard",
-"none",
-"entrust",
-"bypass", /* may be error */
-"ipsec esp", /* must be error */
-"ipsec ah/require",
-"ipsec ah/use/",
-"ipsec esp/require ah/default/203.178.141.194",
-"ipsec ah/use/203.178.141.195 esp/use/203.178.141.194",
-"ipsec esp/elf.wide.ydc.co.jp esp/www.wide.ydc.co.jp"
-"
-ipsec esp/require ah/use esp/require/10.0.0.1
-ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1
-ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1
-ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1
-ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1
-ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1
-ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1
-ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1
-ah/use/3ffe:501:481d::1 ah/use/3ffe:501:481d::1ah/use/3ffe:501:481d::1
-",
-};
-
-u_char *p_secpolicy;
-
-int test(char *buf, int family);
-char *setpolicy(char *req);
-
-main()
-{
- int i;
- char *buf;
-
- for (i = 0; i < sizeof(requests)/sizeof(requests[0]); i++) {
- printf("* requests:[%s]\n", requests[i]);
- if ((buf = setpolicy(requests[i])) == NULL)
- continue;
- printf("\tsetlen:%d\n", PFKEY_EXTLEN(buf));
-
- printf("\tPF_INET:\n");
- test(buf, PF_INET);
-
- printf("\tPF_INET6:\n");
- test(buf, PF_INET6);
- free(buf);
- }
-}
-
-int test(char *policy, int family)
-{
- int so, proto, optname;
- int len;
- char getbuf[1024];
-
- switch (family) {
- case PF_INET:
- proto = IPPROTO_IP;
- optname = IP_IPSEC_POLICY;
- break;
- case PF_INET6:
- proto = IPPROTO_IPV6;
- optname = IPV6_IPSEC_POLICY;
- break;
- }
-
- if ((so = socket(family, SOCK_DGRAM, 0)) < 0)
- perror("socket");
-
- if (setsockopt(so, proto, optname, policy, PFKEY_EXTLEN(policy)) < 0)
- perror("setsockopt");
-
- len = sizeof(getbuf);
- memset(getbuf, 0, sizeof(getbuf));
- if (getsockopt(so, proto, optname, getbuf, &len) < 0)
- perror("getsockopt");
-
- {
- char *buf = NULL;
-
- printf("\tgetlen:%d\n", len);
-
- if ((buf = ipsec_dump_policy(getbuf, NULL)) == NULL)
- ipsec_strerror();
- else
- printf("\t[%s]\n", buf);
-
- free(buf);
- }
-
- close (so);
-}
-
-char *setpolicy(char *req)
-{
- int len;
- char *buf;
-
- if ((len = ipsec_get_policylen(req)) < 0) {
- printf("ipsec_get_policylen: %s\n", ipsec_strerror());
- return NULL;
- }
-
- if ((buf = malloc(len)) == NULL) {
- perror("malloc");
- return NULL;
- }
-
- if ((len = ipsec_set_policy(buf, len, req)) < 0) {
- printf("ipsec_set_policy: %s\n", ipsec_strerror());
- free(buf);
- return NULL;
- }
-
- return buf;
-}
diff --git a/sbin/setkey/token.l b/sbin/setkey/token.l
deleted file mode 100644
index 208196e3cdc8..000000000000
--- a/sbin/setkey/token.l
+++ /dev/null
@@ -1,322 +0,0 @@
-/* $FreeBSD$ */
-/* $KAME: token.l,v 1.21 2001/05/18 05:35:01 sakane Exp $ */
-
-/*
- * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
- * 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <net/route.h>
-#include <net/pfkeyv2.h>
-#include <netkey/keydb.h>
-#include <netkey/key_debug.h>
-#include <netinet/in.h>
-#include <netinet6/ipsec.h>
-
-#include <stdlib.h>
-#include <limits.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include "vchar.h"
-#ifdef __NetBSD__
-#include "parse.h"
-#else
-#include "y.tab.h"
-#endif
-
-#define DECHO \
- if (f_debug) {printf("<%d>", yy_start); ECHO ; printf("\n"); }
-
-#define CMDARG \
-{ \
- char *__buf__ = strdup(yytext), *__p__; \
- for (__p__ = __buf__; *__p__ != NULL; __p__++) \
- if (*__p__ == '\n' || *__p__ == '\t') \
- *__p__ = ' '; \
- strcat(cmdarg, __buf__); \
- free(__buf__); \
-}
-
-#define PREPROC DECHO CMDARG
-
-int lineno = 1;
-char cmdarg[8192]; /* XXX: BUFSIZ is the better ? */
-
-extern u_char m_buf[BUFSIZ];
-extern u_int m_len;
-extern int f_debug;
-
-int yylex __P((void));
-void yyfatal __P((const char *s));
-void yyerror __P((const char *s));
-extern void parse_init __P((void));
-int parse __P((FILE **));
-int yyparse __P((void));
-
-%}
-
-/* common section */
-nl \n
-ws [ \t]+
-digit [0-9]
-letter [0-9A-Za-z]
-hexdigit [0-9A-Fa-f]
-/*octet (([01]?{digit}?{digit})|((2([0-4]{digit}))|(25[0-5])))*/
-special [()+\|\?\*,]
-dot \.
-comma \,
-hyphen \-
-colon \:
-slash \/
-bcl \{
-ecl \}
-blcl \[
-elcl \]
-percent \%
-semi \;
-usec {dot}{digit}{1,6}
-comment \#.*
-ccomment "/*"
-bracketstring \<[^>]*\>
-quotedstring \"[^"]*\"
-decstring {digit}+
-hexpair {hexdigit}{hexdigit}
-hexstring 0[xX]{hexdigit}+
-octetstring {octet}({dot}{octet})+
-ipaddress [a-fA-F0-9:]([a-fA-F0-9:\.]*|[a-fA-F0-9:\.]*%[a-zA-Z0-9]*)
-ipaddrmask {slash}{digit}{1,3}
-ipaddrport {blcl}{decstring}{elcl}
-keyword {letter}{letter}+
-name {letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
-hostname {name}(({dot}{name})+{dot}?)?
-
-%s S_PL
-
-%%
-
-add { PREPROC; return(ADD); }
-delete { PREPROC; return(DELETE); }
-deleteall { PREPROC; return(DELETEALL); }
-get { PREPROC; return(GET); }
-flush { PREPROC; return(FLUSH); }
-dump { PREPROC; return(DUMP); }
-
- /* for management SPD */
-spdadd { PREPROC; return(SPDADD); }
-spddelete { PREPROC; return(SPDDELETE); }
-spddump { PREPROC; return(SPDDUMP); }
-spdflush { PREPROC; return(SPDFLUSH); }
-{hyphen}P { BEGIN S_PL; PREPROC; return(F_POLICY); }
-<S_PL>[a-zA-Z0-9:\.\-_/ \n\t][a-zA-Z0-9:\.\-_/ \n\t]* {
- yymore();
-
- /* count up for nl */
- {
- char *p;
- for (p = yytext; *p != NULL; p++)
- if (*p == '\n')
- lineno++;
- }
-
- yylval.val.len = strlen(yytext);
- yylval.val.buf = strdup(yytext);
-
- return(PL_REQUESTS);
-}
-<S_PL>{semi} { PREPROC; BEGIN INITIAL; return(EOT); }
-
- /* security protocols */
-ah { PREPROC; yylval.num = 0; return(PR_AH); }
-esp { PREPROC; yylval.num = 0; return(PR_ESP); }
-ah-old { PREPROC; yylval.num = 1; return(PR_AH); }
-esp-old { PREPROC; yylval.num = 1; return(PR_ESP); }
-ipcomp { PREPROC; yylval.num = 0; return(PR_IPCOMP); }
-
- /* authentication alogorithm */
-{hyphen}A { PREPROC; return(F_AUTH); }
-hmac-md5 { PREPROC; yylval.num = SADB_AALG_MD5HMAC; return(ALG_AUTH); }
-hmac-sha1 { PREPROC; yylval.num = SADB_AALG_SHA1HMAC; return(ALG_AUTH); }
-keyed-md5 { PREPROC; yylval.num = SADB_X_AALG_MD5; return(ALG_AUTH); }
-keyed-sha1 { PREPROC; yylval.num = SADB_X_AALG_SHA; return(ALG_AUTH); }
-hmac-sha2-256 { PREPROC; yylval.num = SADB_X_AALG_SHA2_256; return(ALG_AUTH); }
-hmac-sha2-384 { PREPROC; yylval.num = SADB_X_AALG_SHA2_384; return(ALG_AUTH); }
-hmac-sha2-512 { PREPROC; yylval.num = SADB_X_AALG_SHA2_512; return(ALG_AUTH); }
-null { PREPROC; yylval.num = SADB_X_AALG_NULL; return(ALG_AUTH); }
-
- /* encryption alogorithm */
-{hyphen}E { PREPROC; return(F_ENC); }
-des-cbc { PREPROC; yylval.num = SADB_EALG_DESCBC; return(ALG_ENC); }
-3des-cbc { PREPROC; yylval.num = SADB_EALG_3DESCBC; return(ALG_ENC); }
-simple { PREPROC; yylval.num = SADB_EALG_NULL; return(ALG_ENC); }
-blowfish-cbc { PREPROC; yylval.num = SADB_X_EALG_BLOWFISHCBC; return(ALG_ENC); }
-cast128-cbc { PREPROC; yylval.num = SADB_X_EALG_CAST128CBC; return(ALG_ENC); }
-des-deriv { PREPROC; yylval.num = SADB_EALG_DESCBC; return(ALG_ENC_DESDERIV); }
-des-32iv { PREPROC; yylval.num = SADB_EALG_DESCBC; return(ALG_ENC_DES32IV); }
-rijndael-cbc { PREPROC; yylval.num = SADB_X_EALG_RIJNDAELCBC; return(ALG_ENC); }
-
- /* compression algorithms */
-{hyphen}C { PREPROC; return(F_COMP); }
-oui { PREPROC; yylval.num = SADB_X_CALG_OUI; return(ALG_COMP); }
-deflate { PREPROC; yylval.num = SADB_X_CALG_DEFLATE; return(ALG_COMP); }
-lzs { PREPROC; yylval.num = SADB_X_CALG_LZS; return(ALG_COMP); }
-{hyphen}R { PREPROC; return(F_RAWCPI); }
-
- /* extension */
-{hyphen}m { PREPROC; return(F_MODE); }
-transport { PREPROC; yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); }
-tunnel { PREPROC; yylval.num = IPSEC_MODE_TUNNEL; return(MODE); }
-{hyphen}u { PREPROC; return(F_REQID); }
-{hyphen}f { PREPROC; return(F_EXT); }
-random-pad { PREPROC; yylval.num = SADB_X_EXT_PRAND; return(EXTENSION); }
-seq-pad { PREPROC; yylval.num = SADB_X_EXT_PSEQ; return(EXTENSION); }
-zero-pad { PREPROC; yylval.num = SADB_X_EXT_PZERO; return(EXTENSION); }
-nocyclic-seq { PREPROC; return(NOCYCLICSEQ); }
-{hyphen}r { PREPROC; return(F_REPLAY); }
-{hyphen}lh { PREPROC; return(F_LIFETIME_HARD); }
-{hyphen}ls { PREPROC; return(F_LIFETIME_SOFT); }
-
- /* ... */
-any { PREPROC; return(ANY); }
-{ws} { PREPROC; }
-{nl} { lineno++; }
-{comment}
-{semi} { PREPROC; return(EOT); }
-
- /* parameter */
-{decstring} {
- char *bp;
-
- PREPROC;
- yylval.num = strtoul(yytext, &bp, 10);
- return(DECSTRING);
- }
-
-{ipaddress} {
- PREPROC;
-
- yylval.val.len = yyleng;
- yylval.val.buf = strdup(yytext);
-
- return(ADDRESS);
- }
-
-{ipaddrmask} {
- PREPROC;
- yytext++;
- yylval.num = atoi(yytext);
- return(PREFIX);
- }
-
-{ipaddrport} {
- char *p = yytext;
- PREPROC;
- while (*++p != ']') ;
- *p = NULL;
- yytext++;
- yylval.num = atoi(yytext);
- return(PORT);
- }
-
-{blcl}any{elcl} {
- PREPROC;
- return(PORTANY);
- }
-
-{hexstring} {
- int len = yyleng - 2; /* (str - "0x") */
- PREPROC;
- yylval.val.len = (len & 1) + (len / 2);
- /* fixed string if length is odd. */
- if (len & 1) {
- yytext[1] = '0';
- yylval.val.buf = strdup(yytext + 1);
- } else
- yylval.val.buf = strdup(yytext + 2);
-
- return(HEXSTRING);
- }
-
-{quotedstring} {
- char *p = yytext;
- PREPROC;
- while (*++p != '"') ;
- *p = NULL;
- yytext++;
- yylval.val.len = yyleng - 2;
- yylval.val.buf = strdup(yytext);
-
- return(QUOTEDSTRING);
- }
-
-[a-z0-9.\-]* {
- yylval.val.len = yyleng;
- yylval.val.buf = strdup(yytext);
- return(STRING);
- }
-
-. {
- yyfatal("Syntax error");
- /*NOTREACHED*/
- }
-
-%%
-
-void
-yyfatal(s)
- const char *s;
-{
- yyerror(s);
- exit(1);
-}
-
-void
-yyerror(s)
- const char *s;
-{
- printf("line %d: %s at [%s]\n", lineno, s, yytext);
-}
-
-int
-parse(fp)
- FILE **fp;
-{
- yyin = *fp;
-
- parse_init();
-
- if (yyparse()) {
- printf("parse failed, line %d.\n", lineno);
- return(-1);
- }
-
- return(0);
-}
diff --git a/sbin/setkey/vchar.h b/sbin/setkey/vchar.h
deleted file mode 100644
index f3251c7bfed3..000000000000
--- a/sbin/setkey/vchar.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* $FreeBSD$ */
-/* $KAME: vchar.h,v 1.2 2000/06/07 00:29:14 itojun Exp $ */
-
-/*
- * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
- * 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-typedef struct {
- u_int len;
- caddr_t buf;
-} vchar_t;
diff --git a/share/man/man3/pthread_attr.3 b/share/man/man3/pthread_attr.3
deleted file mode 100644
index 37975421e1ad..000000000000
--- a/share/man/man3/pthread_attr.3
+++ /dev/null
@@ -1,238 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd April 28, 2000
-.Dt PTHREAD_ATTR 3
-.Os
-.Sh NAME
-.Nm pthread_attr_init ,
-.Nm pthread_attr_destroy ,
-.Nm pthread_attr_setstack ,
-.Nm pthread_attr_getstack ,
-.Nm pthread_attr_setstacksize ,
-.Nm pthread_attr_getstacksize ,
-.Nm pthread_attr_setguardsize ,
-.Nm pthread_attr_getguardsize ,
-.Nm pthread_attr_setstackaddr ,
-.Nm pthread_attr_getstackaddr ,
-.Nm pthread_attr_setdetachstate ,
-.Nm pthread_attr_getdetachstate ,
-.Nm pthread_attr_setinheritsched ,
-.Nm pthread_attr_getinheritsched ,
-.Nm pthread_attr_setschedparam ,
-.Nm pthread_attr_getschedparam ,
-.Nm pthread_attr_setschedpolicy ,
-.Nm pthread_attr_getschedpolicy ,
-.Nm pthread_attr_setscope ,
-.Nm pthread_attr_getscope
-.Nd thread attribute operations
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_attr_init "pthread_attr_t *attr"
-.Ft int
-.Fn pthread_attr_destroy "pthread_attr_t *attr"
-.Ft int
-.Fn pthread_attr_setstack "pthread_attr_t *attr" " void *stackaddr" "size_t stacksize"
-.Ft int
-.Fn pthread_attr_getstack "const pthread_attr_t * restrict attr" "void ** restrict stackaddr" "size_t * restrict stacksize"
-.Ft int
-.Fn pthread_attr_setstacksize "pthread_attr_t *attr" "size_t stacksize"
-.Ft int
-.Fn pthread_attr_getstacksize "const pthread_attr_t *attr" "size_t *stacksize"
-.Ft int
-.Fn pthread_attr_setguardsize "pthread_attr_t *attr" "size_t guardsize"
-.Ft int
-.Fn pthread_attr_getguardsize "const pthread_attr_t *attr" "size_t *guardsize"
-.Ft int
-.Fn pthread_attr_setstackaddr "pthread_attr_t *attr" "void *stackaddr"
-.Ft int
-.Fn pthread_attr_getstackaddr "const pthread_attr_t *attr" "void **stackaddr"
-.Ft int
-.Fn pthread_attr_setdetachstate "pthread_attr_t *attr" "int detachstate"
-.Ft int
-.Fn pthread_attr_getdetachstate "const pthread_attr_t *attr" "int *detachstate"
-.Ft int
-.Fn pthread_attr_setinheritsched "pthread_attr_t *attr" "int inheritsched"
-.Ft int
-.Fn pthread_attr_getinheritsched "const pthread_attr_t *attr" "int *inheritsched"
-.Ft int
-.Fn pthread_attr_setschedparam "pthread_attr_t *attr" "const struct sched_param *param"
-.Ft int
-.Fn pthread_attr_getschedparam "const pthread_attr_t *attr" "struct sched_param *param"
-.Ft int
-.Fn pthread_attr_setschedpolicy "pthread_attr_t *attr" "int policy"
-.Ft int
-.Fn pthread_attr_getschedpolicy "const pthread_attr_t *attr" "int *policy"
-.Ft int
-.Fn pthread_attr_setscope "pthread_attr_t *attr" "int contentionscope"
-.Ft int
-.Fn pthread_attr_getscope "const pthread_attr_t *attr" "int *contentionscope"
-.Sh DESCRIPTION
-Thread attributes are used to specify parameters to
-.Fn pthread_create .
-One attribute object can be used in multiple calls to
-.Fn pthread_create ,
-with or without modifications between calls.
-.Pp
-The
-.Fn pthread_attr_init
-function initializes
-.Fa attr
-with all the default thread attributes.
-.Pp
-The
-.Fn pthread_attr_destroy
-function destroys
-.Fa attr .
-.Pp
-The
-.Fn pthread_attr_set*
-functions set the attribute that corresponds to each function name.
-.Pp
-The
-.Fn pthread_attr_get*
-functions copy the value of the attribute that corresponds to each function name
-to the location pointed to by the second function parameter.
-.Sh RETURN VALUES
-If successful, these functions return 0.
-Otherwise, an error number is returned to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_attr_init
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er ENOMEM
-Out of memory.
-.El
-.Pp
-The
-.Fn pthread_attr_destroy
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr .
-.El
-.Pp
-The
-.Fn pthread_attr_setstacksize
-and
-.Fn pthread_attr_setstack
-functions will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-.Fa stacksize
-is less than
-.Dv PTHREAD_STACK_MIN .
-.El
-.Pp
-The
-.Fn pthread_attr_setdetachstate
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa detachstate .
-.El
-.Pp
-The
-.Fn pthread_attr_setinheritsched
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr .
-.El
-.Pp
-The
-.Fn pthread_attr_setschedparam
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr .
-.It Bq Er ENOTSUP
-Invalid value for
-.Fa param .
-.El
-.Pp
-The
-.Fn pthread_attr_setschedpolicy
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr .
-.It Bq Er ENOTSUP
-Invalid or unsupported value for
-.Fa policy .
-.El
-.Pp
-The
-.Fn pthread_attr_setscope
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr .
-.It Bq Er ENOTSUP
-Invalid or unsupported value for
-.Fa contentionscope .
-.El
-.Sh SEE ALSO
-.Xr pthread_attr_get_np 3 ,
-.Xr pthread_create 3
-.Sh STANDARDS
-The
-.Fn pthread_attr_init ,
-.Fn pthread_attr_destroy ,
-.Fn pthread_attr_setstacksize ,
-.Fn pthread_attr_getstacksize ,
-.Fn pthread_attr_setstackaddr ,
-.Fn pthread_attr_getstackaddr ,
-.Fn pthread_attr_setdetachstate ,
-and
-.Fn pthread_attr_getdetachstate
-functions conform to
-.St -p1003.1-96
-.Pp
-The
-.Fn pthread_attr_setinheritsched ,
-.Fn pthread_attr_getinheritsched ,
-.Fn pthread_attr_setschedparam ,
-.Fn pthread_attr_getschedparam ,
-.Fn pthread_attr_setschedpolicy ,
-.Fn pthread_attr_getschedpolicy ,
-.Fn pthread_attr_setscope ,
-and
-.Fn pthread_attr_getscope
-functions conform to
-.St -susv2
diff --git a/share/man/man3/pthread_attr_get_np.3 b/share/man/man3/pthread_attr_get_np.3
deleted file mode 100644
index 82e106566b02..000000000000
--- a/share/man/man3/pthread_attr_get_np.3
+++ /dev/null
@@ -1,116 +0,0 @@
-.\" Copyright (c) 2002,2003 Alexey Zelkin <phantom@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd January 31, 2003
-.Dt PTHREAD_ATTR_GET_NP 3
-.Os
-.Sh NAME
-.Nm pthread_attr_get_np
-.Nd get attributes of existent thread
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread_np.h
-.Ft int
-.Fn pthread_attr_get_np "pthread_t pid" "pthread_attr_t *dst"
-.Sh DESCRIPTION
-The
-.Fn pthread_attr_get_np
-function is used to get existent thread's attributes.
-Most fields of
-.Vt pthread_attr_t
-structure are exact values of attributes provided at thread creation
-time (as parameter to
-.Xr pthread_create 3
-function), except for the stack address.
-.Pp
-Value returned as
-.Fa dst
-is supposed to be used in conjunction with
-.Fn pthread_attr_get*
-functions to retrieve individual values from
-.Vt pthread_attr_t
-structure.
-Parameter
-.Fa dst
-should point to allocated memory area big enough to fit this structure.
-.Pp
-It is HIGHLY RECOMMENDED to use
-.Xr pthread_attr_init 3
-function to allocate attribute storage.
-.Sh IMPLEMENTATION NOTES
-The
-.Fn pthread_attr_get_np
-function will always return a pointer to the thread's real stack address,
-regardless of its value in the original attributes structure.
-.Sh EXAMPLES
-.Bd -literal
-size_t
-my_thread_stack_size(pthread_t pid)
-{
- pthread_attr_t attr;
- size_t size;
-
- pthread_attr_init(&attr);
- pthread_attr_get_np(pid, &attr);
- pthread_attr_getstacksize(&attr, &size);
- pthread_attr_destroy(&attr);
- return(size);
-}
-.Ed
-.Sh RETURN VALUES
-If successful,
-.Fn pthread_attr_get_np
-function returns 0.
-Otherwise, an error number is returned to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_attr_get_np
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for one of given parameters.
-.It Bq Er ESRC
-No thread could be found corresponding to that specified by the given
-thread ID.
-.El
-.Sh SEE ALSO
-.Xr pthread_attr_destroy 3 ,
-.Xr pthread_attr_getdetachstate 3 ,
-.Xr pthread_attr_getinheritsched 3 ,
-.Xr pthread_attr_getschedparam 3 ,
-.Xr pthread_attr_getschedpolicy 3 ,
-.Xr pthread_attr_getscope 3 ,
-.Xr pthread_attr_getstack 3 ,
-.Xr pthread_attr_getstackaddr 3 ,
-.Xr pthread_attr_getstacksize 3 ,
-.Xr pthread_attr_init 3
-.Sh AUTHORS
-The
-.Fn pthread_attr_get_np
-function and this manual page were written by
-.An Alexey Zelkin
-.Aq phantom@FreeBSD.org .
diff --git a/share/man/man3/pthread_attr_setcreatesuspend_np.3 b/share/man/man3/pthread_attr_setcreatesuspend_np.3
deleted file mode 100644
index 70599055b574..000000000000
--- a/share/man/man3/pthread_attr_setcreatesuspend_np.3
+++ /dev/null
@@ -1,72 +0,0 @@
-.\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd February 13, 2003
-.Dt PTHREAD_ATTR_SETCREATESUSPEND_NP 3
-.Os
-.Sh NAME
-.Nm pthread_attr_setcreatesuspend_np
-.Nd prepare attribute for creattion of suspended thread
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread_np.h
-.Ft int
-.Fn pthread_attr_setcreatesuspend_np "pthread_attr_t *attr"
-.Sh DESCRIPTION
-The
-.Fn pthread_attr_setcreatesuspend_np
-instructs
-.Xr pthread_create 3
-that the thread created with the
-.Fa attr
-attribute
-should be created and left in a suspended state until explicitly resumed
-by the call to
-.Fn pthread_resume_np
-or
-.Fn pthread_resume_all_np .
-.Sh RETURN VALUES
-.Rv -std pthread_attr_setcreatesuspend_np
-.Sh ERRORS
-The
-.Fn pthread_attr_setcreatesuspend_np
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa attr
-is invalid.
-.El
-.Sh SEE ALSO
-.Xr pthread_attr_destroy 3 ,
-.Xr pthread_attr_init 3 ,
-.Xr pthread_create 3 ,
-.Xr pthread_resume_all_np 3 ,
-.Xr pthread_resume_np 3
-.Sh AUTHORS
-This manual page was written by
-.An Alexey Zelkin Aq phantom@FreeBSD.org .
diff --git a/share/man/man3/pthread_cancel.3 b/share/man/man3/pthread_cancel.3
deleted file mode 100644
index 166dadc0a5c8..000000000000
--- a/share/man/man3/pthread_cancel.3
+++ /dev/null
@@ -1,81 +0,0 @@
-.\" $FreeBSD$
-.Dd January 17, 1999
-.Dt PTHREAD_CANCEL 3
-.Os
-.Sh NAME
-.Nm pthread_cancel
-.Nd cancel execution of a thread
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_cancel "pthread_t thread"
-.Sh DESCRIPTION
-The
-.Fn pthread_cancel
-function requests that
-.Fa thread
-be canceled.
-The target thread's cancelability state and type determines
-when the cancellation takes effect.
-When the cancellation is acted on,
-the cancellation cleanup handlers for
-.Fa thread
-are called.
-When the last cancellation cleanup handler returns,
-the thread-specific data destructor functions will be called for
-.Fa thread .
-When the last destructor function returns,
-.Fa thread
-will be terminated.
-.Pp
-The cancellation processing in the target thread runs asynchronously with
-respect to the calling thread returning from
-.Fn pthread_cancel .
-.Pp
-A status of
-.Dv PTHREAD_CANCELED
-is made available to any threads joining with the target.
-The symbolic
-constant
-.Dv PTHREAD_CANCELED
-expands to a constant expression of type
-.Ft "(void *)" ,
-whose value matches no pointer to an object in memory nor the value
-.Dv NULL .
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_cancel
-functions will return zero.
-Otherwise an error number will be returned to
-indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_cancel
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er ESRCH
-No thread could be found corresponding to that specified by the given
-thread ID.
-.El
-.Sh SEE ALSO
-.Xr pthread_cleanup_pop 3 ,
-.Xr pthread_cleanup_push 3 ,
-.Xr pthread_exit 3 ,
-.Xr pthread_join 3 ,
-.Xr pthread_setcancelstate 3 ,
-.Xr pthread_setcanceltype 3 ,
-.Xr pthread_testcancel 3
-.Sh STANDARDS
-The
-.Fn pthread_cancel
-function conforms to
-.St -p1003.1-96 .
-.Sh AUTHORS
-This man page was written by
-.An David Leonard Aq d@openbsd.org
-for the
-.Ox
-implementation of
-.Fn pthread_cancel .
diff --git a/share/man/man3/pthread_cleanup_pop.3 b/share/man/man3/pthread_cleanup_pop.3
deleted file mode 100644
index a0cb1b628932..000000000000
--- a/share/man/man3/pthread_cleanup_pop.3
+++ /dev/null
@@ -1,66 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 30, 1998
-.Dt PTHREAD_CLEANUP_POP 3
-.Os
-.Sh NAME
-.Nm pthread_cleanup_pop
-.Nd call the first cleanup routine
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft void
-.Fn pthread_cleanup_pop "int execute"
-.Sh DESCRIPTION
-The
-.Fn pthread_cleanup_pop
-function pops the top cleanup routine off of the current threads cleanup
-routine stack, and, if
-.Fa execute
-is non-zero, it will execute the function.
-If there is no cleanup routine
-then
-.Fn pthread_cleanup_pop
-does nothing.
-.Sh RETURN VALUES
-The
-.Fn pthread_cleanup_pop
-function does not return any value.
-.Sh ERRORS
-None
-.Sh SEE ALSO
-.Xr pthread_cleanup_push 3 ,
-.Xr pthread_exit 3
-.Sh STANDARDS
-The
-.Fn pthread_cleanup_pop
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_cleanup_push.3 b/share/man/man3/pthread_cleanup_push.3
deleted file mode 100644
index 7d7f98682ad0..000000000000
--- a/share/man/man3/pthread_cleanup_push.3
+++ /dev/null
@@ -1,68 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 30, 1998
-.Dt PTHREAD_CLEANUP_PUSH 3
-.Os
-.Sh NAME
-.Nm pthread_cleanup_push
-.Nd add a cleanup function for thread exit
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft void
-.Fn pthread_cleanup_push "void \*[lp]*cleanup_routine\*[rp]\*[lp]void *\*[rp]" "void *arg"
-.Sh DESCRIPTION
-The
-.Fn pthread_cleanup_push
-function adds
-.Fa cleanup_routine
-to the top of the stack of cleanup handlers that
-get called when the current thread exits.
-.Pp
-When
-.Fa cleanup_routine
-is called, it is passed
-.Fa arg
-as its only argument.
-.Sh RETURN VALUES
-The
-.Fn pthread_cleanup_push
-function does not return any value.
-.Sh ERRORS
-None
-.Sh SEE ALSO
-.Xr pthread_cleanup_pop 3 ,
-.Xr pthread_exit 3
-.Sh STANDARDS
-The
-.Fn pthread_cleanup_push
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_cond_broadcast.3 b/share/man/man3/pthread_cond_broadcast.3
deleted file mode 100644
index 1c734f3663fe..000000000000
--- a/share/man/man3/pthread_cond_broadcast.3
+++ /dev/null
@@ -1,72 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 28, 1998
-.Dt PTHREAD_COND_BROADCAST 3
-.Os
-.Sh NAME
-.Nm pthread_cond_broadcast
-.Nd unblock all threads waiting for a condition variable
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_cond_broadcast "pthread_cond_t *cond"
-.Sh DESCRIPTION
-The
-.Fn pthread_cond_broadcast
-function unblocks all threads waiting for the condition variable
-.Fa cond .
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_cond_broadcast
-function will return zero, otherwise an error number will be returned
-to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_cond_broadcast
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa cond
-is invalid.
-.El
-.Sh SEE ALSO
-.Xr pthread_cond_destroy 3 ,
-.Xr pthread_cond_init 3 ,
-.Xr pthread_cond_signal 3 ,
-.Xr pthread_cond_timedwait 3 ,
-.Xr pthread_cond_wait 3
-.Sh STANDARDS
-The
-.Fn pthread_cond_broadcast
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_cond_destroy.3 b/share/man/man3/pthread_cond_destroy.3
deleted file mode 100644
index 3b6b45218b3b..000000000000
--- a/share/man/man3/pthread_cond_destroy.3
+++ /dev/null
@@ -1,76 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 28, 1998
-.Dt PTHREAD_COND_DESTROY 3
-.Os
-.Sh NAME
-.Nm pthread_cond_destroy
-.Nd destroy a condition variable
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_cond_destroy "pthread_cond_t *cond"
-.Sh DESCRIPTION
-The
-.Fn pthread_cond_destroy
-function frees the resources allocated by the condition variable
-.Fa cond .
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_cond_destroy
-function will return zero, otherwise an error number will be returned
-to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_cond_destroy
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa cond
-is invalid.
-.It Bq Er EBUSY
-The variable
-.Fa cond
-is locked by another thread.
-.El
-.Sh SEE ALSO
-.Xr pthread_cond_broadcast 3 ,
-.Xr pthread_cond_init 3 ,
-.Xr pthread_cond_signal 3 ,
-.Xr pthread_cond_timedwait 3 ,
-.Xr pthread_cond_wait 3
-.Sh STANDARDS
-The
-.Fn pthread_cond_destroy
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_cond_init.3 b/share/man/man3/pthread_cond_init.3
deleted file mode 100644
index 255c039f077e..000000000000
--- a/share/man/man3/pthread_cond_init.3
+++ /dev/null
@@ -1,82 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 28, 1998
-.Dt PTHREAD_COND_INIT 3
-.Os
-.Sh NAME
-.Nm pthread_cond_init
-.Nd create a condition variable
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_cond_init "pthread_cond_t *cond" "const pthread_condattr_t *attr"
-.Sh DESCRIPTION
-The
-.Fn pthread_cond_init
-function creates a new condition variable, with attributes specified with
-.Fa attr .
-If
-.Fa attr
-is NULL the default attributes are used.
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_cond_init
-function will return zero and put the new condition variable id into
-.Fa cond ,
-otherwise an error number will be returned to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_cond_init
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa attr
-is invalid.
-.It Bq Er ENOMEM
-The process cannot allocate enough memory to create another condition
-variable.
-.It Bq Er EAGAIN
-The system temporarily lacks the resources to create another condition
-variable.
-.El
-.Sh SEE ALSO
-.Xr pthread_cond_broadcast 3 ,
-.Xr pthread_cond_destroy 3 ,
-.Xr pthread_cond_signal 3 ,
-.Xr pthread_cond_timedwait 3 ,
-.Xr pthread_cond_wait 3
-.Sh STANDARDS
-The
-.Fn pthread_cond_init
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_cond_signal.3 b/share/man/man3/pthread_cond_signal.3
deleted file mode 100644
index 7c389ec5423c..000000000000
--- a/share/man/man3/pthread_cond_signal.3
+++ /dev/null
@@ -1,72 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 28, 1998
-.Dt PTHREAD_COND_SIGNAL 3
-.Os
-.Sh NAME
-.Nm pthread_cond_signal
-.Nd unblock a thread waiting for a condition variable
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_cond_signal "pthread_cond_t *cond"
-.Sh DESCRIPTION
-The
-.Fn pthread_cond_signal
-function unblocks one thread waiting for the condition variable
-.Fa cond .
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_cond_signal
-function will return zero, otherwise an error number will be returned
-to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_cond_signal
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa cond
-is invalid.
-.El
-.Sh SEE ALSO
-.Xr pthread_cond_broadcast 3 ,
-.Xr pthread_cond_destroy 3 ,
-.Xr pthread_cond_init 3 ,
-.Xr pthread_cond_timedwait 3 ,
-.Xr pthread_cond_wait 3
-.Sh STANDARDS
-The
-.Fn pthread_cond_signal
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_cond_timedwait.3 b/share/man/man3/pthread_cond_timedwait.3
deleted file mode 100644
index dd4479533890..000000000000
--- a/share/man/man3/pthread_cond_timedwait.3
+++ /dev/null
@@ -1,91 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 28, 1998
-.Dt PTHREAD_COND_TIMEDWAIT 3
-.Os
-.Sh NAME
-.Nm pthread_cond_timedwait
-.Nd "wait on a condition variable for a specific amount of time"
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_cond_timedwait "pthread_cond_t *cond" "pthread_mutex_t *mutex" "const struct timespec *abstime"
-.Sh DESCRIPTION
-The
-.Fn pthread_cond_timedwait
-function atomically blocks the current thread waiting on the condition
-variable specified by
-.Fa cond ,
-and unblocks the mutex specified by
-.Fa mutex .
-The waiting thread unblocks only after another thread calls
-.Xr pthread_cond_signal 3 ,
-or
-.Xr pthread_cond_broadcast 3
-with the same condition variable, or if the system time reaches the
-time specified in
-.Fa abstime ,
-and the current thread reacquires the lock on
-.Fa mutex .
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_cond_timedwait
-function will return zero.
-Otherwise an error number will be returned to
-indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_cond_timedwait
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa cond ,
-.Fa mutex
-or
-.Fa abstime
-is invalid.
-.It Bq Er ETIMEDOUT
-The system time has reached or exceeded the time specified in
-.Fa abstime .
-.El
-.Sh SEE ALSO
-.Xr pthread_cond_broadcast 3 ,
-.Xr pthread_cond_destroy 3 ,
-.Xr pthread_cond_init 3 ,
-.Xr pthread_cond_signal 3 ,
-.Xr pthread_cond_wait 3
-.Sh STANDARDS
-The
-.Fn pthread_cond_timedwait
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_cond_wait.3 b/share/man/man3/pthread_cond_wait.3
deleted file mode 100644
index 02e2f81ab377..000000000000
--- a/share/man/man3/pthread_cond_wait.3
+++ /dev/null
@@ -1,85 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 28, 1998
-.Dt PTHREAD_COND_WAIT 3
-.Os
-.Sh NAME
-.Nm pthread_cond_wait
-.Nd wait on a condition variable
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_cond_wait "pthread_cond_t *cond" "pthread_mutex_t *mutex"
-.Sh DESCRIPTION
-The
-.Fn pthread_cond_wait
-function atomically blocks the current thread waiting on the condition
-variable specified by
-.Fa cond ,
-and unblocks the mutex specified by
-.Fa mutex .
-The waiting thread unblocks only after another thread calls
-.Xr pthread_cond_signal 3 ,
-or
-.Xr pthread_cond_broadcast 3
-with the same condition variable, and the current thread reacquires the lock
-on
-.Fa mutex .
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_cond_wait
-function will return zero.
-Otherwise an error number will be returned to
-indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_cond_wait
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa cond
-or the value specified by
-.Fa mutex
-is invalid.
-.El
-.Sh SEE ALSO
-.Xr pthread_cond_broadcast 3 ,
-.Xr pthread_cond_destroy 3 ,
-.Xr pthread_cond_init 3 ,
-.Xr pthread_cond_signal 3 ,
-.Xr pthread_cond_timedwait 3
-.Sh STANDARDS
-The
-.Fn pthread_cond_wait
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_condattr.3 b/share/man/man3/pthread_condattr.3
deleted file mode 100644
index fb0c3186c1ef..000000000000
--- a/share/man/man3/pthread_condattr.3
+++ /dev/null
@@ -1,88 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd April 28, 2000
-.Dt PTHREAD_CONDATTR 3
-.Os
-.Sh NAME
-.Nm pthread_condattr_init ,
-.Nm pthread_condattr_destroy
-.Nd condition attribute operations
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_condattr_init "pthread_condattr_t *attr"
-.Ft int
-.Fn pthread_condattr_destroy "pthread_condattr_t *attr"
-.Sh DESCRIPTION
-Condition attribute objects are used to specify parameters to
-.Fn pthread_cond_init .
-.Fx Ns 's
-implementation of conditions does not support any non-default
-attributes, so these functions are not very useful, though they are required to
-to be present by
-.Tn POSIX .
-.Pp
-The
-.Fn pthread_condattr_init
-function initializes a condition attribute object with the default attributes.
-.Pp
-The
-.Fn pthread_condattr_destroy
-function destroys a condition attribute object.
-.Sh RETURN VALUES
-If successful, these functions return 0.
-Otherwise, an error number is returned to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_condattr_init
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er ENOMEM
-Out of memory.
-.El
-.Pp
-The
-.Fn pthread_condattr_destroy
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr .
-.El
-.Sh SEE ALSO
-.Xr pthread_cond_init 3
-.Sh STANDARDS
-The
-.Fn pthread_condattr_init
-and
-.Fn pthread_condattr_destroy
-functions conform to
-.St -p1003.1-96
diff --git a/share/man/man3/pthread_create.3 b/share/man/man3/pthread_create.3
deleted file mode 100644
index 32f1875bda70..000000000000
--- a/share/man/man3/pthread_create.3
+++ /dev/null
@@ -1,125 +0,0 @@
-.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by John Birrell.
-.\" 4. Neither the name of the author nor the names of any co-contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd April 4, 1996
-.Dt PTHREAD_CREATE 3
-.Os
-.Sh NAME
-.Nm pthread_create
-.Nd create a new thread
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_create "pthread_t *thread" "const pthread_attr_t *attr" "void *(*start_routine)(void *)" "void *arg"
-.Sh DESCRIPTION
-The
-.Fn pthread_create
-function is used to create a new thread, with attributes specified by
-.Fa attr ,
-within a process.
-If
-.Fa attr
-is
-.Dv NULL ,
-the default attributes are used.
-If the attributes specified by
-.Fa attr
-are modified later, the thread's attributes are not affected.
-Upon
-successful completion
-.Fn pthread_create
-will store the ID of the created thread in the location specified by
-.Fa thread .
-.Pp
-The thread is created executing
-.Fa start_routine
-with
-.Fa arg
-as its sole argument.
-If the
-.Fa start_routine
-returns, the effect is as if there was an implicit call to
-.Fn pthread_exit
-using the return value of
-.Fa start_routine
-as the exit status.
-Note that the thread in which
-.Fn main
-was originally invoked differs from this.
-When it returns from
-.Fn main ,
-the effect is as if there was an implicit call to
-.Fn exit
-using the return value of
-.Fn main
-as the exit status.
-.Pp
-The signal state of the new thread is initialized as:
-.Bl -bullet -offset indent
-.It
-The signal mask is inherited from the creating thread.
-.It
-The set of signals pending for the new thread is empty.
-.El
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_create
-function will return zero.
-Otherwise an error number will be returned to
-indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_create
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EAGAIN
-The system lacked the necessary resources to create another thread, or
-the system-imposed limit on the total number of threads in a process
-[PTHREAD_THREADS_MAX] would be exceeded.
-.It Bq Er EINVAL
-The value specified by
-.Fa attr
-is invalid.
-.El
-.Sh SEE ALSO
-.Xr fork 2 ,
-.Xr pthread_cleanup_pop 3 ,
-.Xr pthread_cleanup_push 3 ,
-.Xr pthread_exit 3 ,
-.Xr pthread_join 3
-.Sh STANDARDS
-The
-.Fn pthread_create
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_detach.3 b/share/man/man3/pthread_detach.3
deleted file mode 100644
index 55dd222ae3c4..000000000000
--- a/share/man/man3/pthread_detach.3
+++ /dev/null
@@ -1,91 +0,0 @@
-.\" Copyright (c) 1996-1998 John Birrell <jb@cimlogic.com.au>.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by John Birrell.
-.\" 4. Neither the name of the author nor the names of any co-contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd April 4, 1996
-.Dt PTHREAD_DETACH 3
-.Os
-.Sh NAME
-.Nm pthread_detach
-.Nd detach a thread
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_detach "pthread_t thread"
-.Sh DESCRIPTION
-The
-.Fn pthread_detach
-function is used to indicate to the implementation that storage for the
-thread
-.Fa thread
-can be reclaimed when the thread terminates.
-If
-.Fa thread
-has not terminated,
-.Fn pthread_detach
-will not cause it to terminate.
-The effect of multiple
-.Fn pthread_detach
-calls on the same target thread is unspecified.
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_detach
-function will return zero.
-Otherwise an error number will be returned to
-indicate the error.
-Note that the function does not change the value
-of errno as it did for some drafts of the standard.
-These early drafts
-also passed a pointer to pthread_t as the argument.
-Beware!
-.Sh ERRORS
-The
-.Fn pthread_detach
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The implementation has detected that the value specified by
-.Fa thread
-does not refer to a joinable thread.
-.It Bq Er ESRCH
-No thread could be found corresponding to that specified by the given
-thread ID,
-.Fa thread .
-.El
-.Sh SEE ALSO
-.Xr pthread_join 3
-.Sh STANDARDS
-The
-.Fn pthread_detach
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_equal.3 b/share/man/man3/pthread_equal.3
deleted file mode 100644
index 9b10fad1e936..000000000000
--- a/share/man/man3/pthread_equal.3
+++ /dev/null
@@ -1,69 +0,0 @@
-.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by John Birrell.
-.\" 4. Neither the name of the author nor the names of any co-contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd April 4, 1996
-.Dt PTHREAD_EQUAL 3
-.Os
-.Sh NAME
-.Nm pthread_equal
-.Nd compare thread IDs
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_equal "pthread_t t1" "pthread_t t2"
-.Sh DESCRIPTION
-The
-.Fn pthread_equal
-function compares the thread IDs
-.Fa t1
-and
-.Fa t2 .
-.Sh RETURN VALUES
-The
-.Fn pthread_equal
-function will return non-zero if the thread IDs
-.Fa t1
-and
-.Fa t2
-correspond to the same thread, otherwise it will return zero.
-.Sh ERRORS
-None.
-.Sh SEE ALSO
-.Xr pthread_create 3 ,
-.Xr pthread_exit 3
-.Sh STANDARDS
-The
-.Fn pthread_equal
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_exit.3 b/share/man/man3/pthread_exit.3
deleted file mode 100644
index 13983079bd16..000000000000
--- a/share/man/man3/pthread_exit.3
+++ /dev/null
@@ -1,105 +0,0 @@
-.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by John Birrell.
-.\" 4. Neither the name of the author nor the names of any co-contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd April 4, 1996
-.Dt PTHREAD_EXIT 3
-.Os
-.Sh NAME
-.Nm pthread_exit
-.Nd terminate the calling thread
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft void
-.Fn pthread_exit "void *value_ptr"
-.Sh DESCRIPTION
-The
-.Fn pthread_exit
-function terminates the calling thread and makes the value
-.Fa value_ptr
-available to any successful join with the terminating thread.
-Any
-cancellation cleanup handlers that have been pushed and are not yet popped
-are popped in the reverse order that they were pushed and then executed.
-After all cancellation handlers have been executed, if the thread has any
-thread-specific data, appropriate destructor functions are called in an
-unspecified order.
-Thread termination does not release any application
-visible process resources, including, but not limited to, mutexes and
-file descriptors, nor does it perform any process level cleanup
-actions, including, but not limited to, calling
-.Fn atexit
-routines that may exist.
-.Pp
-An implicit call to
-.Fn pthread_exit
-is made when a thread other than the thread in which
-.Fn main
-was first invoked returns from the start routine that was used to create
-it. The function's return value serves as the thread's exit status.
-.Pp
-The behavior of
-.Fn pthread_exit
-is undefined if called from a cancellation handler or destructor function
-that was invoked as the result of an implicit or explicit call to
-.Fn pthread_exit .
-.Pp
-After a thread has terminated, the result of access to local (auto)
-variables of the thread is undefined.
-Thus, references to local variables
-of the exiting thread should not be used for the
-.Fn pthread_exit
-.Fa value_ptr
-parameter value.
-.Pp
-The process will exit with an exit status of 0 after the last thread has
-been terminated.
-The behavior is as if the implementation called
-.Fn exit
-with a zero argument at thread termination time.
-.Sh RETURN VALUES
-The
-.Fn pthread_exit
-function cannot return to its caller.
-.Sh ERRORS
-None.
-.Sh SEE ALSO
-.Xr _exit 2 ,
-.Xr exit 3 ,
-.Xr pthread_create 3 ,
-.Xr pthread_join 3
-.Sh STANDARDS
-The
-.Fn pthread_exit
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_getconcurrency.3 b/share/man/man3/pthread_getconcurrency.3
deleted file mode 100644
index d71599a2adf8..000000000000
--- a/share/man/man3/pthread_getconcurrency.3
+++ /dev/null
@@ -1,115 +0,0 @@
-.\" Copyright (c) 2003 Sergey Osokin <osa@FreeBSD.org.ru>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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$
-.Dd April 11, 2003
-.Dt PTHREAD_GETCONCURRENCY 3
-.Os
-.Sh NAME
-.Nm pthread_getconcurrency ,
-.Nm pthread_setconcurrency
-.Nd get or set level of concurrency
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_getconcurrency void
-.Ft int
-.Fn pthread_setconcurrency "int new_level"
-.Sh DESCRIPTION
-The
-.Fn pthread_getconcurrency
-function allows an application to inform the threads implementation
-of its desired concurrency level,
-.Fa new_level .
-The actual level of concurrency provided by the implementation
-as a result of this function call is unspecified.
-If
-.Fa new_level
-is zero, it causes the implementation to maintain the concurrency
-level at its discretion as if
-.Fn pthread_setconcurrency
-was never called.
-The
-.Fn pthread_getconcurrency
-function returns the value set by a previous call to the
-.Fn pthread_setconcurrency
-function.
-If the
-.Fn pthread_setconcurrency
-function was not previously called, this function returns zero to
-indicate that the implementation is maintaining the concurrency
-level.
-When an application calls
-.Fn pthread_setconcurrency ,
-it is informing the implementation of its desired concurrency
-level.
-The implementation uses this as a hint, not a requirement.
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_setconcurrency
-function returns zero.
-Otherwise, an error number is returned
-to indicate the error.
-The
-.Fn pthread_getconcurrency
-function always returns the concurrency level set by a previous
-call to
-.Fn pthread_setconcurrency .
-If the
-.Fn pthread_setconcurrency
-function has never been called,
-.Fn pthread_getconcurrency
-returns zero.
-.Sh ERRORS
-The
-.Fn pthread_setconcurrency
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa new_level
-is negative.
-.It Bq Er EAGAIN
-The value specified by
-.Fa new_level
-would cause a system resource to be exceeded.
-.El
-.Sh APPLICATION USAGE
-Use of these functions changes the state of the underlying
-concurrency upon which the application depends.
-Library developers are advised to not use the
-.Fn pthread_getconcurrency
-and
-.Fn pthread_setconcurrency
-functions since their use may conflict with an application's
-use of these functions.
-.Sh STANDARDS
-The
-.Fn pthread_getconcurrency
-and
-.Fn pthread_setconcurrency
-functions conform to
-.St -susv2 .
diff --git a/share/man/man3/pthread_getspecific.3 b/share/man/man3/pthread_getspecific.3
deleted file mode 100644
index a7999e5a3b7e..000000000000
--- a/share/man/man3/pthread_getspecific.3
+++ /dev/null
@@ -1,85 +0,0 @@
-.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by John Birrell.
-.\" 4. Neither the name of the author nor the names of any co-contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd April 4, 1996
-.Dt PTHREAD_GETSPECIFIC 3
-.Os
-.Sh NAME
-.Nm pthread_getspecific
-.Nd get a thread-specific data value
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft void *
-.Fn pthread_getspecific "pthread_key_t key"
-.Sh DESCRIPTION
-The
-.Fn pthread_getspecific
-function returns the value currently bound to the specified
-.Fa key
-on behalf of the calling thread.
-.Pp
-The effect of calling
-.Fn pthread_getspecific
-with a
-.Fa key
-value not obtained from
-.Fn pthread_key_create
-or after
-.Fa key
-has been deleted with
-.Fn pthread_key_delete
-is undefined.
-.Pp
-The
-.Fn pthread_getspecific
-function may be called from a thread-specific data destructor function.
-.Sh RETURN VALUES
-The
-.Fn pthread_getspecific
-function will return the thread-specific data value associated with the given
-.Fa key .
-If no thread-specific data value is associated with
-.Fa key ,
-then the value NULL is returned.
-.Sh ERRORS
-None.
-.Sh SEE ALSO
-.Xr pthread_key_create 3 ,
-.Xr pthread_key_delete 3 ,
-.Xr pthread_setspecific 3
-.Sh STANDARDS
-The
-.Fn pthread_getspecific
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_join.3 b/share/man/man3/pthread_join.3
deleted file mode 100644
index 513e291e1835..000000000000
--- a/share/man/man3/pthread_join.3
+++ /dev/null
@@ -1,106 +0,0 @@
-.\" Copyright (c) 1996-1998 John Birrell <jb@cimlogic.com.au>.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by John Birrell.
-.\" 4. Neither the name of the author nor the names of any co-contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd April 4, 1996
-.Dt PTHREAD_JOIN 3
-.Os
-.Sh NAME
-.Nm pthread_join
-.Nd wait for thread termination
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_join "pthread_t thread" "void **value_ptr"
-.Sh DESCRIPTION
-The
-.Fn pthread_join
-function suspends execution of the calling thread until the target
-.Fa thread
-terminates unless the target
-.Fa thread
-has already terminated.
-.Pp
-On return from a successful
-.Fn pthread_join
-call with a non-NULL
-.Fa value_ptr
-argument, the value passed to
-.Fn pthread_exit
-by the terminating thread is stored in the location referenced by
-.Fa value_ptr .
-When a
-.Fn pthread_join
-returns successfully, the target thread has been terminated.
-The results
-of multiple simultaneous calls to
-.Fn pthread_join
-specifying the same target thread are undefined.
-If the thread calling
-.Fn pthread_join
-is cancelled, then the target thread is not detached.
-.Pp
-A thread that has exited but remains unjoined counts against
-[_POSIX_THREAD_THREADS_MAX].
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_join
-function will return zero.
-Otherwise an error number will be returned to
-indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_join
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The implementation has detected that the value specified by
-.Fa thread
-does not refer to a joinable thread.
-.It Bq Er ESRCH
-No thread could be found corresponding to that specified by the given
-thread ID,
-.Fa thread .
-.It Bq Er EDEADLK
-A deadlock was detected or the value of
-.Fa thread
-specifies the calling thread.
-.El
-.Sh SEE ALSO
-.Xr wait 2 ,
-.Xr pthread_create 3
-.Sh STANDARDS
-The
-.Fn pthread_join
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_key_create.3 b/share/man/man3/pthread_key_create.3
deleted file mode 100644
index a2b0918bc2e0..000000000000
--- a/share/man/man3/pthread_key_create.3
+++ /dev/null
@@ -1,109 +0,0 @@
-.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by John Birrell.
-.\" 4. Neither the name of the author nor the names of any co-contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd April 4, 1996
-.Dt PTHREAD_KEY_CREATE 3
-.Os
-.Sh NAME
-.Nm pthread_key_create
-.Nd thread-specific data key creation
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_key_create "pthread_key_t *key" "void (*destructor)(void *)"
-.Sh DESCRIPTION
-The
-.Fn pthread_key_create
-function creates a thread-specific data key visible to all threads in the
-process.
-Key values provided by
-.Fn pthread_key_create
-are opaque objects used to locate thread-specific data.
-Although the same
-key value may be used by different threads, the values bound to the key
-by
-.Fn pthread_setspecific
-are maintained on a per-thread basis and persist for the life of the calling
-thread.
-.Pp
-Upon key creation, the value NULL is associated with the new key in all
-active threads.
-Upon thread creation, the value NULL is associated with all
-defined keys in the new thread.
-.Pp
-An optional destructor function may be associated with each key value.
-At
-thread exit, if a key value has a non-NULL destructor pointer, and the
-thread has a non-NULL value associated with the key, the function pointed
-to is called with the current associated value as its sole argument.
-The
-order of destructor calls is unspecified if more than one destructor exists
-for a thread when it exits.
-.Pp
-If, after all the destructors have been called for all non-NULL values
-with associated destructors, there are still some non-NULL values with
-associated destructors, then the process is repeated.
-If, after at least
-[PTHREAD_DESTRUCTOR_ITERATIONS] iterations of destructor calls for
-outstanding non-NULL values, there are still some non-NULL values with
-associated destructors, the implementation stops calling destructors.
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_key_create
-function will store the newly created key value at the location specified by
-.Fa key
-and returns zero.
-Otherwise an error number will be returned to indicate
-the error.
-.Sh ERRORS
-The
-.Fn pthread_key_create
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EAGAIN
-The system lacked the necessary resources to create another thread-specific
-data key, or the system-imposed limit on the total number of keys per process
-[PTHREAD_KEYS_MAX] would be exceeded.
-.It Bq Er ENOMEM
-Insufficient memory exists to create the key.
-.El
-.Sh SEE ALSO
-.Xr pthread_getspecific 3 ,
-.Xr pthread_key_delete 3 ,
-.Xr pthread_setspecific 3
-.Sh STANDARDS
-The
-.Fn pthread_key_create
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_key_delete.3 b/share/man/man3/pthread_key_delete.3
deleted file mode 100644
index c025857e9469..000000000000
--- a/share/man/man3/pthread_key_delete.3
+++ /dev/null
@@ -1,100 +0,0 @@
-.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by John Birrell.
-.\" 4. Neither the name of the author nor the names of any co-contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd April 4, 1996
-.Dt PTHREAD_KEY_DELETE 3
-.Os
-.Sh NAME
-.Nm pthread_key_delete
-.Nd delete a thread-specific data key
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_key_delete "pthread_key_t key"
-.Sh DESCRIPTION
-The
-.Fn pthread_key_delete
-function deletes a thread-specific data key previously returned by
-.Fn pthread_key_create .
-The thread-specific data values associated with
-.Fa key
-need not be NULL at the time that
-.Fn pthread_key_delete
-is called.
-It is the responsibility of the application to free any
-application storage or perform any cleanup actions for data structures
-related to the deleted key or associated thread-specific data in any threads;
-this cleanup can be done either before or after
-.Fn pthread_key_delete
-is called.
-Any attempt to use
-.Fa key
-following the call to
-.Fn pthread_key_delete
-results in undefined behavior.
-.Pp
-The
-.Fn pthread_key_delete
-function is callable from within destructor functions.
-Destructor functions
-are not invoked by
-.Fn pthread_key_delete .
-Any destructor function that may have been associated with
-.Fa key
-will no longer be called upon thread exit.
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_key_delete
-function will return zero.
-Otherwise an error number will be returned to
-indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_key_delete
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The
-.Fa key
-value is invalid.
-.El
-.Sh SEE ALSO
-.Xr pthread_getspecific 3 ,
-.Xr pthread_key_create 3 ,
-.Xr pthread_setspecific 3
-.Sh STANDARDS
-The
-.Fn pthread_key_delete
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_kill.3 b/share/man/man3/pthread_kill.3
deleted file mode 100644
index 94434bf13d35..000000000000
--- a/share/man/man3/pthread_kill.3
+++ /dev/null
@@ -1,77 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd April 27, 2000
-.Dt PTHREAD_KILL 3
-.Os
-.Sh NAME
-.Nm pthread_kill
-.Nd send a signal to a specified thread
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.In signal.h
-.Ft int
-.Fn pthread_kill "pthread_t thread" "int sig"
-.Sh DESCRIPTION
-The
-.Fn pthread_kill
-function sends a signal, specified by
-.Fa sig ,
-to a thread, specified by
-.Fa thread .
-If
-.Fa sig
-is 0, error checking is performed, but no signal is actually sent.
-.Sh RETURN VALUES
-If successful,
-.Fn pthread_kill
-returns 0.
-Otherwise, an error number is returned.
-.Sh ERRORS
-The
-.Fn pthread_kill
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er ESRCH
-.Fa thread
-is an invalid thread ID.
-.It Bq Er EINVAL
-.Fa sig
-is an invalid or unsupported signal number.
-.El
-.Sh SEE ALSO
-.Xr kill 2 ,
-.Xr pthread_self 3 ,
-.Xr raise 3
-.Sh STANDARDS
-The
-.Fn pthread_kill
-function conforms to
-.St -p1003.1-96
diff --git a/share/man/man3/pthread_main_np.3 b/share/man/man3/pthread_main_np.3
deleted file mode 100644
index 9065b90c94fa..000000000000
--- a/share/man/man3/pthread_main_np.3
+++ /dev/null
@@ -1,60 +0,0 @@
-.\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd February 13, 2003
-.Dt PTHREAD_MAIN_NP 3
-.Os
-.Sh NAME
-.Nm pthread_main_np
-.Nd identify the initial thread
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread_np.h
-.Ft int
-.Fn pthread_main_np void
-.Sh DESCRIPTION
-The
-.Fn pthread_main_np
-function
-is used in userland threads environment to identify the initial thread.
-Its semantics is similar to the Solaris's
-.Fn thr_main
-function.
-.Sh RETURN VALUES
-The
-.Fn pthread_main_np
-function returns
-1 if the calling thread is the initial thread,
-0 if the calling thread is not the initial thread,
-and \-1 if the thread's initialization has not yet completed.
-.Sh SEE ALSO
-.Xr pthread_create 3 ,
-.Xr pthread_equal 3 ,
-.Xr pthread_self 3
-.Sh AUTHORS
-This manual page was written by
-.An Alexey Zelkin Aq phantom@FreeBSD.org .
diff --git a/share/man/man3/pthread_multi_np.3 b/share/man/man3/pthread_multi_np.3
deleted file mode 100644
index 5588c6cb75d7..000000000000
--- a/share/man/man3/pthread_multi_np.3
+++ /dev/null
@@ -1,66 +0,0 @@
-.\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd February 13, 2003
-.Dt PTHREAD_MULTI_NP 3
-.Os
-.Sh NAME
-.Nm pthread_multi_np ,
-.Nm pthread_single_np
-.Nd "switch between multi- and single-threaded scheduling modes"
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread_np.h
-.Ft int
-.Fn pthread_multi_np void
-.Ft int
-.Fn pthread_single_np void
-.Sh DESCRIPTION
-The
-.Fn pthread_single_np
-function switches the process to a single-threaded mode, i.e.,
-suspends all threads except the current.
-The semantics of this function is similar to
-.Xr pthread_suspend_all_np 3 .
-.Pp
-The
-.Fn pthread_multi_np
-function switches the process to a multi-threaded mode.
-The semantics of this function is similar to
-.Xr pthread_resume_all_np 3 .
-.Sh RETURN VALUES
-The
-.Fn pthread_multi_np
-and
-.Nm pthread_single_np
-functions always return 0.
-.Sh SEE ALSO
-.Xr pthread_resume_all_np 3 ,
-.Xr pthread_suspend_all_np 3
-.Sh AUTHORS
-This manual page was written by
-.An Alexey Zelkin Aq phantom@FreeBSD.org .
diff --git a/share/man/man3/pthread_mutex_destroy.3 b/share/man/man3/pthread_mutex_destroy.3
deleted file mode 100644
index 1ae514787956..000000000000
--- a/share/man/man3/pthread_mutex_destroy.3
+++ /dev/null
@@ -1,74 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 29, 1998
-.Dt PTHREAD_MUTEX_DESTROY 3
-.Os
-.Sh NAME
-.Nm pthread_mutex_destroy
-.Nd free resources allocated for a mutex
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_mutex_destroy "pthread_mutex_t *mutex"
-.Sh DESCRIPTION
-The
-.Fn pthread_mutex_destroy
-function frees the resources allocated for
-.Fa mutex .
-.Sh RETURN VALUES
-If successful,
-.Fn pthread_mutex_destroy
-will return zero, otherwise an error number will be returned to
-indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_mutex_destroy
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa mutex
-is invalid.
-.It Bq Er EBUSY
-.Fa Mutex
-is locked by another thread.
-.El
-.Sh SEE ALSO
-.Xr pthread_mutex_init 3 ,
-.Xr pthread_mutex_lock 3 ,
-.Xr pthread_mutex_trylock 3 ,
-.Xr pthread_mutex_unlock 3
-.Sh STANDARDS
-The
-.Fn pthread_mutex_destroy
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_mutex_init.3 b/share/man/man3/pthread_mutex_init.3
deleted file mode 100644
index 11fbee9162c8..000000000000
--- a/share/man/man3/pthread_mutex_init.3
+++ /dev/null
@@ -1,79 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 29, 1998
-.Dt PTHREAD_MUTEX_INIT 3
-.Os
-.Sh NAME
-.Nm pthread_mutex_init
-.Nd create a mutex
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_mutex_init "pthread_mutex_t *mutex" "const pthread_mutexattr_t *attr"
-.Sh DESCRIPTION
-The
-.Fn pthread_mutex_init
-function creates a new mutex, with attributes specified with
-.Fa attr .
-If
-.Fa attr
-is NULL the default attributes are used.
-.Sh RETURN VALUES
-If successful,
-.Fn pthread_mutex_init
-will return zero and put the new mutex id into
-.Fa mutex ,
-otherwise an error number will be returned to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_mutex_init
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa attr
-is invalid.
-.It Bq Er ENOMEM
-The process cannot allocate enough memory to create another mutex.
-.It Bq Er EAGAIN
-The temporarily lacks the resources to create another mutex.
-.El
-.Sh SEE ALSO
-.Xr pthread_mutex_destroy 3 ,
-.Xr pthread_mutex_lock 3 ,
-.Xr pthread_mutex_trylock 3 ,
-.Xr pthread_mutex_unlock 3
-.Sh STANDARDS
-The
-.Fn pthread_mutex_init
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_mutex_lock.3 b/share/man/man3/pthread_mutex_lock.3
deleted file mode 100644
index 01628c87aa4a..000000000000
--- a/share/man/man3/pthread_mutex_lock.3
+++ /dev/null
@@ -1,76 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 30, 1998
-.Dt PTHREAD_MUTEX_LOCK 3
-.Os
-.Sh NAME
-.Nm pthread_mutex_lock
-.Nd lock a mutex
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_mutex_lock "pthread_mutex_t *mutex"
-.Sh DESCRIPTION
-The
-.Fn pthread_mutex_lock
-function locks
-.Fa mutex .
-If the mutex is already locked, the calling thread will block until the
-mutex becomes available.
-.Sh RETURN VALUES
-If successful,
-.Fn pthread_mutex_lock
-will return zero, otherwise an error number will be returned to
-indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_mutex_lock
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa mutex
-is invalid.
-.It Bq Er EDEADLK
-A deadlock would occur if the thread blocked waiting for
-.Fa mutex .
-.El
-.Sh SEE ALSO
-.Xr pthread_mutex_destroy 3 ,
-.Xr pthread_mutex_init 3 ,
-.Xr pthread_mutex_trylock 3 ,
-.Xr pthread_mutex_unlock 3
-.Sh STANDARDS
-The
-.Fn pthread_mutex_lock
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_mutex_trylock.3 b/share/man/man3/pthread_mutex_trylock.3
deleted file mode 100644
index a40bf970d920..000000000000
--- a/share/man/man3/pthread_mutex_trylock.3
+++ /dev/null
@@ -1,77 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 30, 1998
-.Dt PTHREAD_MUTEX_TRYLOCK 3
-.Os
-.Sh NAME
-.Nm pthread_mutex_trylock
-.Nd attempt to lock a mutex without blocking
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_mutex_trylock "pthread_mutex_t *mutex"
-.Sh DESCRIPTION
-The
-.Fn pthread_mutex_trylock
-function locks
-.Fa mutex .
-If the mutex is already locked,
-.Fn pthread_mutex_trylock
-will not block waiting for the mutex, but will return an error condition.
-.Sh RETURN VALUES
-If successful,
-.Fn pthread_mutex_trylock
-will return zero, otherwise an error number will be returned to
-indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_mutex_trylock
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa mutex
-is invalid.
-.It Bq Er EBUSY
-.Fa Mutex
-is already locked.
-.El
-.Sh SEE ALSO
-.Xr pthread_mutex_destroy 3 ,
-.Xr pthread_mutex_init 3 ,
-.Xr pthread_mutex_lock 3 ,
-.Xr pthread_mutex_unlock 3
-.Sh STANDARDS
-The
-.Fn pthread_mutex_trylock
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_mutex_unlock.3 b/share/man/man3/pthread_mutex_unlock.3
deleted file mode 100644
index 8e05cce65b9e..000000000000
--- a/share/man/man3/pthread_mutex_unlock.3
+++ /dev/null
@@ -1,76 +0,0 @@
-.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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 JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 30, 1998
-.Dt PTHREAD_MUTEX_UNLOCK 3
-.Os
-.Sh NAME
-.Nm pthread_mutex_unlock
-.Nd unlock a mutex
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_mutex_unlock "pthread_mutex_t *mutex"
-.Sh DESCRIPTION
-If the current thread holds the lock on
-.Fa mutex ,
-then the
-.Fn pthread_mutex_unlock
-function unlocks
-.Fa mutex .
-.Sh RETURN VALUES
-If successful,
-.Fn pthread_mutex_unlock
-will return zero, otherwise an error number will be returned to
-indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_mutex_unlock
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa mutex
-is invalid.
-.It Bq Er EPERM
-The current thread does not hold a lock on
-.Fa mutex .
-.El
-.Sh SEE ALSO
-.Xr pthread_mutex_destroy 3 ,
-.Xr pthread_mutex_init 3 ,
-.Xr pthread_mutex_lock 3 ,
-.Xr pthread_mutex_trylock 3
-.Sh STANDARDS
-The
-.Fn pthread_mutex_unlock
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_mutexattr.3 b/share/man/man3/pthread_mutexattr.3
deleted file mode 100644
index 91fde140e8bb..000000000000
--- a/share/man/man3/pthread_mutexattr.3
+++ /dev/null
@@ -1,187 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd May 1, 2000
-.Dt PTHREAD_MUTEXATTR 3
-.Os
-.Sh NAME
-.Nm pthread_mutexattr_init ,
-.Nm pthread_mutexattr_destroy ,
-.Nm pthread_mutexattr_setprioceiling ,
-.Nm pthread_mutexattr_getprioceiling ,
-.Nm pthread_mutexattr_setprotocol ,
-.Nm pthread_mutexattr_getprotocol ,
-.Nm pthread_mutexattr_settype ,
-.Nm pthread_mutexattr_gettype
-.Nd mutex attribute operations
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_mutexattr_init "pthread_mutexattr_t *attr"
-.Ft int
-.Fn pthread_mutexattr_destroy "pthread_mutexattr_t *attr"
-.Ft int
-.Fn pthread_mutexattr_setprioceiling "pthread_mutexattr_t *attr" "int prioceiling"
-.Ft int
-.Fn pthread_mutexattr_getprioceiling "pthread_mutexattr_t *attr" "int *prioceiling"
-.Ft int
-.Fn pthread_mutexattr_setprotocol "pthread_mutexattr_t *attr" "int protocol"
-.Ft int
-.Fn pthread_mutexattr_getprotocol "pthread_mutexattr_t *attr" "int *protocol"
-.Ft int
-.Fn pthread_mutexattr_settype "pthread_mutexattr_t *attr" "int type"
-.Ft int
-.Fn pthread_mutexattr_gettype "pthread_mutexattr_t *attr" "int *type"
-.Sh DESCRIPTION
-Mutex attributes are used to specify parameters to
-.Fn pthread_mutex_init .
-One attribute object can be used in multiple calls to
-.Fn pthread_mutex_init ,
-with or without modifications between calls.
-.Pp
-The
-.Fn pthread_mutexattr_init
-function initializes
-.Fa attr
-with all the default mutex attributes.
-.Pp
-The
-.Fn pthread_mutexattr_destroy
-function destroys
-.Fa attr .
-.Pp
-The
-.Fn pthread_mutexattr_set*
-functions set the attribute that corresponds to each function name.
-.Pp
-The
-.Fn pthread_mutexattr_get*
-functions copy the value of the attribute that corresponds to each function name
-to the location pointed to by the second function parameter.
-.Sh RETURN VALUES
-If successful, these functions return 0.
-Otherwise, an error number is returned to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_mutexattr_init
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er ENOMEM
-Out of memory.
-.El
-.Pp
-The
-.Fn pthread_mutexattr_destroy
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr .
-.El
-.Pp
-The
-.Fn pthread_mutexattr_setprioceiling
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr ,
-or invalid value for
-.Fa prioceiling .
-.El
-.Pp
-The
-.Fn pthread_mutexattr_getprioceiling
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr .
-.El
-.Pp
-The
-.Fn pthread_mutexattr_setprotocol
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr ,
-or invalid value for
-.Fa protocol .
-.El
-.Pp
-The
-.Fn pthread_mutexattr_getprotocol
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr .
-.El
-.Pp
-The
-.Fn pthread_mutexattr_settype
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr ,
-or invalid value for
-.Fa type .
-.El
-.Pp
-The
-.Fn pthread_mutexattr_gettype
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Fa attr .
-.El
-.Sh SEE ALSO
-.Xr pthread_mutex_init 3
-.Sh STANDARDS
-The
-.Fn pthread_mutexattr_init
-and
-.Fn pthread_mutexattr_destroy
-functions conform to
-.St -p1003.1-96
-.Pp
-The
-.Fn pthread_mutexattr_setprioceiling ,
-.Fn pthread_mutexattr_getprioceiling ,
-.Fn pthread_mutexattr_setprotocol ,
-.Fn pthread_mutexattr_getprotocol ,
-.Fn pthread_mutexattr_settype ,
-and
-.Fn pthread_mutexattr_gettype
-functions conform to
-.St -susv2
diff --git a/share/man/man3/pthread_mutexattr_getkind_np.3 b/share/man/man3/pthread_mutexattr_getkind_np.3
deleted file mode 100644
index 8bb673cd3ec3..000000000000
--- a/share/man/man3/pthread_mutexattr_getkind_np.3
+++ /dev/null
@@ -1,81 +0,0 @@
-.\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd February 13, 2003
-.Dt PTHREAD_MUTEXATTR_GETKIND_NP 3
-.Os
-.Sh NAME
-.Nm pthread_mutexattr_getkind_np ,
-.Nm pthread_mutexattr_setkind_np
-.Nd mutex attribute operations (legacy)
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread_np.h
-.Ft int
-.Fn pthread_mutexattr_getkind_np "pthread_mutexattr_t attr"
-.Ft int
-.Fn pthread_mutexattr_setkind_np "pthread_mutexattr_t *attr" "int kind"
-.Sh DESCRIPTION
-.Bf -symbolic
-These functions are deprecated and non-portable implementation of
-the mutex type manipulation.
-.Ef
-.Pp
-It is recommended to use the
-.Xr pthread_mutexattr_gettype 3
-and
-.Xr pthread_mutexattr_settype 3
-functions instead.
-.Sh RETURN VALUES
-The
-.Fn pthread_mutexattr_getkind_np
-function returns a positive value representing the
-.Dq kind
-of the mutex attribute
-.Fa attr
-if successful; otherwise the value \-1 is returned and the global variable
-.Va errno
-is set to indicate the error.
-.Pp
-.Rv -std pthread_mutexattr_setkind_np
-.Sh ERRORS
-The
-.Fn pthread_mutexattr_getkind_np
-and
-.Fn pthread_mutexattr_setkind_np
-functions will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa attr
-is invalid.
-.El
-.Sh SEE ALSO
-.Xr pthread_mutexattr_gettype 3 ,
-.Xr pthread_mutexattr_settype 3 ,
-.Xr pthread_mutex_create 3 ,
-.Xr pthread_mutex_destroy 3
diff --git a/share/man/man3/pthread_once.3 b/share/man/man3/pthread_once.3
deleted file mode 100644
index aed9698b4404..000000000000
--- a/share/man/man3/pthread_once.3
+++ /dev/null
@@ -1,106 +0,0 @@
-.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by John Birrell.
-.\" 4. Neither the name of the author nor the names of any co-contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd April 4, 1996
-.Dt PTHREAD_ONCE 3
-.Os
-.Sh NAME
-.Nm pthread_once
-.Nd dynamic package initialization
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Pp
-pthread_once_t
-.Fa once_control
-= PTHREAD_ONCE_INIT;
-.Ft int
-.Fn pthread_once "pthread_once_t *once_control" "void (*init_routine)(void)"
-.Sh DESCRIPTION
-The first call to
-.Fn pthread_once
-by any thread in a process, with a given
-.Fa once_control ,
-will call the
-.Fn init_routine
-with no arguments.
-Subsequent calls to
-.Fn pthread_once
-with the same
-.Fa once_control
-will not call the
-.Fn init_routine .
-On return from
-.Fn pthread_once ,
-it is guaranteed that
-.Fn init_routine
-has completed.
-The
-.Fa once_control
-parameter is used to determine whether the associated initialization
-routine has been called.
-.Pp
-The function
-.Fn pthread_once
-is not a cancellation point.
-However, if
-.Fn init_routine
-is a cancellation point and is cancelled, the effect on
-.Fa once_control is as if
-.Fn pthread_once
-was never called.
-.Pp
-The constant
-.Fa PTHREAD_ONCE_INIT
-is defined by header
-.Aq Pa pthread.h .
-.Pp
-The behavior of
-.Fn pthread_once
-is undefined if
-.Fa once_control
-has automatic storage duration or is not initialized by
-.Fa PTHREAD_ONCE_INIT .
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_once
-function will return zero.
-Otherwise an error number will be returned to
-indicate the error.
-.Sh ERRORS
-None.
-.Sh STANDARDS
-The
-.Fn pthread_once
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_resume_all_np.3 b/share/man/man3/pthread_resume_all_np.3
deleted file mode 100644
index 90b2657090d1..000000000000
--- a/share/man/man3/pthread_resume_all_np.3
+++ /dev/null
@@ -1,51 +0,0 @@
-.\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd February 13, 2003
-.Dt PTHREAD_RESUME_ALL_NP 3
-.Os
-.Sh NAME
-.Nm pthread_resume_all_np
-.Nd resume all suspended threads
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread_np.h
-.Ft void
-.Fn pthread_resume_all_np void
-.Sh DESCRIPTION
-The
-.Fn pthread_resume_all_np
-function causes all active threads to be scanned
-and resumes those which were previously suspended.
-.Sh SEE ALSO
-.Xr pthread_attr_setcreatesuspend_np 3 ,
-.Xr pthread_resume_np 3 ,
-.Xr pthread_suspend_all_np 3 ,
-.Xr pthread_suspend_np 3
-.Sh AUTHORS
-This manual page was written by
-.An Alexey Zelkin Aq phantom@FreeBSD.org .
diff --git a/share/man/man3/pthread_resume_np.3 b/share/man/man3/pthread_resume_np.3
deleted file mode 100644
index 4a1a077bd7ff..000000000000
--- a/share/man/man3/pthread_resume_np.3
+++ /dev/null
@@ -1,72 +0,0 @@
-.\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd February 13, 2003
-.Dt PTHREAD_RESUME_NP 3
-.Os
-.Sh NAME
-.Nm pthread_resume_np
-.Nd resume suspended thread
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread_np.h
-.Ft int
-.Fn pthread_resume_np "pthread_t tid"
-.Sh DESCRIPTION
-The
-.Fn pthread_resume_np
-function, called on a suspended thread, causes it to resume.
-If a thread specified by the
-.Fa tid
-argument is not suspended, no actions will be performed.
-.Sh RETURN VALUES
-If successful,
-.Fn pthread_resume_np
-function returns 0.
-Otherwise, an error number is returned to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_resume_np
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by the
-.Fa tid
-argument is invalid.
-.It Bq ESRC
-No thread could be found corresponding to the thread ID specified by the
-.Fa tid
-argument.
-.El
-.Sh SEE ALSO
-.Xr pthread_attr_setcreatesuspend_np 3 ,
-.Xr pthread_resume_all_np 3 ,
-.Xr pthread_suspend_all_np 3 ,
-.Xr pthread_suspend_np 3
-.Sh AUTHORS
-This manual page was written by
-.An Alexey Zelkin Aq phantom@FreeBSD.org .
diff --git a/share/man/man3/pthread_rwlock_destroy.3 b/share/man/man3/pthread_rwlock_destroy.3
deleted file mode 100644
index b65e0656750a..000000000000
--- a/share/man/man3/pthread_rwlock_destroy.3
+++ /dev/null
@@ -1,82 +0,0 @@
-.\" Copyright (c) 1998 Alex Nash
-.\" 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$
-.\"
-.Dd August 4, 1998
-.Dt PTHREAD_RWLOCK_DESTROY 3
-.Os
-.Sh NAME
-.Nm pthread_rwlock_destroy
-.Nd destroy a read/write lock
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_rwlock_destroy "pthread_rwlock_t *lock"
-.Sh DESCRIPTION
-The
-.Fn pthread_rwlock_destroy
-function is used to destroy a read/write lock previously created with
-.Fn pthread_rwlock_init .
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_rwlock_destroy
-function will return zero. Otherwise an error number will be returned
-to indicate the error.
-.Sh SEE ALSO
-.Xr pthread_rwlock_init 3
-.Sh STANDARDS
-The
-.Fn pthread_rwlock_destroy
-function is expected to conform to
-.St -susv2 .
-.Sh ERRORS
-The
-.Fn pthread_rwlock_destroy
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EPERM
-The caller does not have the privilege to perform the operation.
-.El
-.Pp
-The
-.Fn pthread_rwlock_destroy
-function may fail if:
-.Bl -tag -width Er
-.It Bq Er EBUSY
-The system has detected an attempt to destroy the object referenced by
-.Fa lock
-while it is locked.
-.It Bq Er EINVAL
-The value specified by
-.Fa lock
-is invalid.
-.El
-.Sh HISTORY
-The
-.Fn pthread_rwlock_destroy
-function first appeared in
-.Fx 3.0 .
diff --git a/share/man/man3/pthread_rwlock_init.3 b/share/man/man3/pthread_rwlock_init.3
deleted file mode 100644
index 0360987db1e3..000000000000
--- a/share/man/man3/pthread_rwlock_init.3
+++ /dev/null
@@ -1,101 +0,0 @@
-.\" Copyright (c) 1998 Alex Nash
-.\" 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$
-.\"
-.Dd August 4, 1998
-.Dt PTHREAD_RWLOCK_INIT 3
-.Os
-.Sh NAME
-.Nm pthread_rwlock_init
-.Nd initialize a read/write lock
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_rwlock_init "pthread_rwlock_t *lock" "const pthread_rwlockattr_t *attr"
-.Sh DESCRIPTION
-The
-.Fn pthread_rwlock_init
-function is used to initialize a read/write lock, with attributes
-specified by
-.Fa attr .
-If
-.Fa attr
-is NULL, the default read/write lock attributes are used.
-.Pp
-The results of calling
-.Fn pthread_rwlock_init
-with an already initialized lock are undefined.
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_rwlock_init
-function will return zero. Otherwise an error number will be returned
-to indicate the error.
-.Sh SEE ALSO
-.Xr pthread_rwlockattr_init 3 ,
-.Xr pthread_rwlockattr_setpshared 3 ,
-.Xr pthread_rwlock_destroy 3
-.Sh STANDARDS
-The
-.Fn pthread_rwlock_init
-function is expected to conform to
-.St -susv2 .
-.Sh ERRORS
-The
-.Fn pthread_rwlock_init
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EAGAIN
-The system lacked the necessary resources (other than memory) to
-initialize the lock.
-.It Bq Er ENOMEM
-Insufficient memory exists to initialize the lock.
-.It Bq Er EPERM
-The caller does not have sufficient privilege to perform the
-operation.
-.El
-.Pp
-The
-.Fn pthread_rwlock_init
-function may fail if:
-.Bl -tag -width Er
-.It Bq Er EBUSY
-The system has detected an attempt to re-initialize the object
-referenced by
-.Fa lock ,
-a previously initialized but not yet destroyed read/write lock.
-.It Bq Er EINVAL
-The value specified by
-.Fa attr
-is invalid.
-.El
-.Sh HISTORY
-The
-.Fn pthread_rwlock_init
-function first appeared in
-.Fx 3.0 .
-.Sh BUGS
-The PTHREAD_PROCESS_SHARED attribute is not supported.
diff --git a/share/man/man3/pthread_rwlock_rdlock.3 b/share/man/man3/pthread_rwlock_rdlock.3
deleted file mode 100644
index 88dbb17fa599..000000000000
--- a/share/man/man3/pthread_rwlock_rdlock.3
+++ /dev/null
@@ -1,124 +0,0 @@
-.\" Copyright (c) 1998 Alex Nash
-.\" 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$
-.\"
-.Dd August 4, 1998
-.Dt PTHREAD_RWLOCK_RDLOCK 3
-.Os
-.Sh NAME
-.Nm pthread_rwlock_rdlock ,
-.Nm pthread_rwlock_tryrdlock
-.Nd acquire a read/write lock for reading
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_rwlock_rdlock "pthread_rwlock_t *lock"
-.Ft int
-.Fn pthread_rwlock_tryrdlock "pthread_rwlock_t *lock"
-.Sh DESCRIPTION
-The
-.Fn pthread_rwlock_rdlock
-function acquires a read lock on
-.Fa lock
-provided that
-.Fa lock
-is not presently held for writing and no writer threads are
-presently blocked on the lock. If the read lock cannot be
-immediately acquired, the calling thread blocks until it can
-acquire the lock.
-.Pp
-The
-.Fn pthread_rwlock_tryrdlock
-function performs the same action, but does not block if the lock
-cannot be immediately obtained (i.e. the lock is held for writing
-or there are waiting writers).
-.Pp
-A thread may hold multiple concurrent read locks. If so,
-.Fn pthread_rwlock_unlock
-must be called once for each lock obtained.
-.Pp
-The results of acquiring a read lock while the calling thread holds
-a write lock are undefined.
-.Sh IMPLEMENTATION NOTES
-To prevent writer starvation, writers are favored over readers.
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_rwlock_rdlock
-and
-.Fn pthread_rwlock_tryrdlock
-functions will return zero. Otherwise an error number will be returned
-to indicate the error.
-.Sh SEE ALSO
-.Xr pthread_rwlock_init 3 ,
-.Xr pthread_rwlock_trywrlock 3 ,
-.Xr pthread_rwlock_unlock 3 ,
-.Xr pthread_rwlock_wrlock 3
-.Sh STANDARDS
-The
-.Fn pthread_rwlock_rdlock
-and
-.Fn pthread_rwlock_tryrdlock
-functions are expected to conform to
-.St -susv2 .
-.Sh ERRORS
-The
-.Fn pthread_rwlock_tryrdlock
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EBUSY
-The lock could not be acquired because a writer holds the lock or
-was blocked on it.
-.El
-.Pp
-The
-.Fn pthread_rwlock_rdlock
-and
-.Fn pthread_rwlock_tryrdlock
-functions may fail if:
-.Bl -tag -width Er
-.It Bq Er EAGAIN
-The lock could not be acquired because the maximum number of read locks
-against
-.Fa lock
-has been exceeded.
-.It Bq Er EDEADLK
-The current thread already owns
-.Fa lock
-for writing.
-.It Bq Er EINVAL
-The value specified by
-.Fa lock
-is invalid.
-.It Bq Er ENOMEM
-Insufficient memory exists to initialize the lock (applies to
-statically initialized locks only).
-.El
-.Sh HISTORY
-The
-.Fn pthread_rwlock_rdlock
-function first appeared in
-.Fx 3.0 .
diff --git a/share/man/man3/pthread_rwlock_unlock.3 b/share/man/man3/pthread_rwlock_unlock.3
deleted file mode 100644
index 9391f75df7af..000000000000
--- a/share/man/man3/pthread_rwlock_unlock.3
+++ /dev/null
@@ -1,81 +0,0 @@
-.\" Copyright (c) 1998 Alex Nash
-.\" 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$
-.\"
-.Dd August 4, 1998
-.Dt PTHREAD_RWLOCK_UNLOCK 3
-.Os
-.Sh NAME
-.Nm pthread_rwlock_unlock
-.Nd release a read/write lock
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_rwlock_unlock "pthread_rwlock_t *lock"
-.Sh DESCRIPTION
-The
-.Fn pthread_rwlock_unlock
-function is used to release the read/write lock previously obtained by
-.Fn pthread_rwlock_rdlock ,
-.Fn pthread_rwlock_wrlock ,
-.Fn pthread_rwlock_tryrdlock ,
-or
-.Fn pthread_rwlock_trywrlock .
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_rwlock_unlock
-function will return zero. Otherwise an error number will be returned
-to indicate the error.
-.Pp
-The results are undefined if
-.Fa lock
-is not held by the calling thread.
-.Sh SEE ALSO
-.Xr pthread_rwlock_rdlock 3 ,
-.Xr pthread_rwlock_wrlock 3
-.Sh STANDARDS
-The
-.Fn pthread_rwlock_unlock
-function is expected to conform to
-.St -susv2 .
-.Sh ERRORS
-The
-.Fn pthread_rwlock_unlock
-function may fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa lock
-is invalid.
-.It Bq Er EPERM
-The current thread does not own the read/write lock.
-.El
-.Sh HISTORY
-The
-.Fn pthread_rwlock_unlock
-function first appeared in
-.Fx 3.0 .
diff --git a/share/man/man3/pthread_rwlock_wrlock.3 b/share/man/man3/pthread_rwlock_wrlock.3
deleted file mode 100644
index c74a46653a79..000000000000
--- a/share/man/man3/pthread_rwlock_wrlock.3
+++ /dev/null
@@ -1,105 +0,0 @@
-.\" Copyright (c) 1998 Alex Nash
-.\" 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$
-.\"
-.Dd August 4, 1998
-.Dt PTHREAD_RWLOCK_WRLOCK 3
-.Os
-.Sh NAME
-.Nm pthread_rwlock_wrlock ,
-.Nm pthread_rwlock_trywrlock
-.Nd acquire a read/write lock for writing
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_rwlock_wrlock "pthread_rwlock_t *lock"
-.Ft int
-.Fn pthread_rwlock_trywrlock "pthread_rwlock_t *lock"
-.Sh DESCRIPTION
-The
-.Fn pthread_rwlock_wrlock
-function blocks until a write lock can be acquired against
-.Fa lock .
-The
-.Fn pthread_rwlock_trywrlock
-function performs the same action, but does not block if the lock
-cannot be immediately obtained.
-.Pp
-The results are undefined if the calling thread already holds the
-lock at the time the call is made.
-.Sh IMPLEMENTATION NOTES
-To prevent writer starvation, writers are favored over readers.
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_rwlock_wrlock
-and
-.Fn pthread_rwlock_trywrlock
-functions will return zero. Otherwise an error number will be returned
-to indicate the error.
-.Sh SEE ALSO
-.Xr pthread_rwlock_init 3 ,
-.Xr pthread_rwlock_rdlock 3 ,
-.Xr pthread_rwlock_tryrdlock 3 ,
-.Xr pthread_rwlock_unlock 3
-.Sh STANDARDS
-The
-.Fn pthread_rwlock_wrlock
-and
-.Fn pthread_rwlock_trywrlock
-functions are expected to conform to
-.St -susv2 .
-.Sh ERRORS
-The
-.Fn pthread_rwlock_trywrlock
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EBUSY
-The calling thread is not able to acquire the lock without blocking.
-.El
-.Pp
-The
-.Fn pthread_rwlock_wrlock
-and
-.Fn pthread_rwlock_trywrlock
-functions may fail if:
-.Bl -tag -width Er
-.It Bq Er EDEADLK
-The calling thread already owns the read/write lock (for reading
-or writing).
-.It Bq Er EINVAL
-The value specified by
-.Fa lock
-is invalid.
-.It Bq Er ENOMEM
-Insufficient memory exists to initialize the lock (applies to
-statically initialized locks only).
-.El
-.Sh HISTORY
-The
-.Fn pthread_rwlock_wrlock
-function first appeared in
-.Fx 3.0 .
diff --git a/share/man/man3/pthread_rwlockattr_destroy.3 b/share/man/man3/pthread_rwlockattr_destroy.3
deleted file mode 100644
index 65c6d3f4317a..000000000000
--- a/share/man/man3/pthread_rwlockattr_destroy.3
+++ /dev/null
@@ -1,71 +0,0 @@
-.\" Copyright (c) 1998 Alex Nash
-.\" 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$
-.\"
-.Dd August 4, 1998
-.Dt PTHREAD_RWLOCKATTR_DESTROY 3
-.Os
-.Sh NAME
-.Nm pthread_rwlockattr_destroy
-.Nd destroy a read/write lock
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_rwlockattr_destroy "pthread_rwlockattr_t *attr"
-.Sh DESCRIPTION
-The
-.Fn pthread_rwlockattr_destroy
-function is used to destroy a read/write lock attribute object
-previously created with
-.Fn pthread_rwlockattr_init .
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_rwlockattr_destroy
-function will return zero. Otherwise an error number will be returned
-to indicate the error.
-.Sh SEE ALSO
-.Xr pthread_rwlockattr_init 3
-.Sh STANDARDS
-The
-.Fn pthread_rwlockattr_destroy
-function is expected to conform to
-.St -susv2 .
-.Sh ERRORS
-The
-.Fn pthread_rwlockattr_destroy
-function may fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa attr
-is invalid.
-.El
-.Sh HISTORY
-The
-.Fn pthread_rwlockattr_destroy
-function first appeared in
-.Fx 3.0 .
diff --git a/share/man/man3/pthread_rwlockattr_getpshared.3 b/share/man/man3/pthread_rwlockattr_getpshared.3
deleted file mode 100644
index 227f512906c0..000000000000
--- a/share/man/man3/pthread_rwlockattr_getpshared.3
+++ /dev/null
@@ -1,83 +0,0 @@
-.\" Copyright (c) 1998 Alex Nash
-.\" 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$
-.\"
-.Dd March 22, 1999
-.Dt PTHREAD_RWLOCKATTR_GETPSHARED 3
-.Os
-.Sh NAME
-.Nm pthread_rwlockattr_getpshared
-.Nd get the process shared attribute
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_rwlockattr_getpshared "const pthread_rwlockattr_t *attr" "int *pshared"
-.Sh DESCRIPTION
-The
-.Fn pthread_rwlockattr_getpshared
-function is used to get the process shared setting of a read/write
-lock attribute object. The setting is returned via
-.Fa pshared ,
-and may be one of two values:
-.Bl -tag -width PTHREAD_PROCESS_PRIVATE
-.It Dv PTHREAD_PROCESS_SHARED
-Any thread of any process that has access to the memory where the
-read/write lock resides can manipulate the lock.
-.It Dv PTHREAD_PROCESS_PRIVATE
-Only threads created within the same process as the thread that
-initialized the read/write lock can manipulate the lock. This is
-the default value.
-.El
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_rwlockattr_getpshared
-function will return zero. Otherwise an error number will be returned
-to indicate the error.
-.Sh SEE ALSO
-.Xr pthread_rwlockattr_init 3 ,
-.Xr pthread_rwlockattr_setpshared 3 ,
-.Xr pthread_rwlock_init 3
-.Sh STANDARDS
-The
-.Fn pthread_rwlockattr_getpshared
-function is expected to conform to
-.St -susv2 .
-.Sh ERRORS
-The
-.Fn pthread_rwlockattr_getpshared
-function may fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa attr
-is invalid.
-.El
-.Sh HISTORY
-The
-.Fn pthread_rwlockattr_getpshared
-function first appeared in
-.Fx 3.0 .
diff --git a/share/man/man3/pthread_rwlockattr_init.3 b/share/man/man3/pthread_rwlockattr_init.3
deleted file mode 100644
index 4ae4ecfda3e9..000000000000
--- a/share/man/man3/pthread_rwlockattr_init.3
+++ /dev/null
@@ -1,70 +0,0 @@
-.\" Copyright (c) 1998 Alex Nash
-.\" 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$
-.\"
-.Dd August 4, 1998
-.Dt PTHREAD_RWLOCKATTR_INIT 3
-.Os
-.Sh NAME
-.Nm pthread_rwlockattr_init
-.Nd initialize a read/write lock
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_rwlockattr_init "pthread_rwlockattr_t *attr"
-.Sh DESCRIPTION
-The
-.Fn pthread_rwlockattr_init
-function is used to initialize a read/write lock attributes object.
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_rwlockattr_init
-function will return zero. Otherwise an error number will be returned
-to indicate the error.
-.Sh SEE ALSO
-.Xr pthread_rwlockattr_destroy 3 ,
-.Xr pthread_rwlockattr_getpshared 3 ,
-.Xr pthread_rwlockattr_setpshared 3 ,
-.Xr pthread_rwlock_init 3
-.Sh STANDARDS
-The
-.Fn pthread_rwlockattr_init
-function is expected to conform to
-.St -susv2 .
-.Sh ERRORS
-The
-.Fn pthread_rwlockattr_init
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er ENOMEM
-Insufficient memory exists to initialize the attribute object.
-.El
-.Sh HISTORY
-The
-.Fn pthread_rwlockattr_init
-function first appeared in
-.Fx 3.0 .
diff --git a/share/man/man3/pthread_rwlockattr_setpshared.3 b/share/man/man3/pthread_rwlockattr_setpshared.3
deleted file mode 100644
index f04bf9f919f3..000000000000
--- a/share/man/man3/pthread_rwlockattr_setpshared.3
+++ /dev/null
@@ -1,92 +0,0 @@
-.\" Copyright (c) 1998 Alex Nash
-.\" 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$
-.\"
-.Dd August 4, 1998
-.Dt PTHREAD_RWLOCKATTR_SETPSHARED 3
-.Os
-.Sh NAME
-.Nm pthread_rwlockattr_setpshared
-.Nd set the process shared attribute
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_rwlockattr_setpshared "pthread_rwlockattr_t *attr" "int pshared"
-.Sh DESCRIPTION
-The
-.Fn pthread_rwlockattr_setpshared
-function sets the process shared attribute of
-.Fa attr
-to the value referenced by
-.Fa pshared .
-The
-.Fa pshared
-argument may be one of two values:
-.Bl -tag -width PTHREAD_PROCESS_PRIVATE
-.It Dv PTHREAD_PROCESS_SHARED
-Any thread of any process that has access to the memory where the
-read/write lock resides can manipulate the lock.
-.It Dv PTHREAD_PROCESS_PRIVATE
-Only threads created within the same process as the thread that
-initialized the read/write lock can manipulate the lock. This is
-the default value.
-.El
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_rwlockattr_setpshared
-function will return zero. Otherwise an error number will be returned
-to indicate the error.
-.Sh SEE ALSO
-.Xr pthread_rwlockattr_getpshared 3 ,
-.Xr pthread_rwlockattr_init 3 ,
-.Xr pthread_rwlock_init 3
-.Sh STANDARDS
-The
-.Fn pthread_rwlockattr_setpshared
-function is expected to conform to
-.St -susv2 .
-.Sh ERRORS
-The
-.Fn pthread_rwlockattr_setpshared
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa attr
-or
-.Fa pshared
-is invalid.
-.El
-.Sh HISTORY
-The
-.Fn pthread_rwlockattr_setpshared
-function first appeared in
-.Fx 3.0 .
-.Sh BUGS
-The
-.Dv PTHREAD_PROCESS_SHARED
-attribute is not supported.
diff --git a/share/man/man3/pthread_schedparam.3 b/share/man/man3/pthread_schedparam.3
deleted file mode 100644
index ea7208781e84..000000000000
--- a/share/man/man3/pthread_schedparam.3
+++ /dev/null
@@ -1,93 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd May 1, 2000
-.Dt PTHREAD_SCHEDPARAM 3
-.Os
-.Sh NAME
-.Nm pthread_setschedparam ,
-.Nm pthread_getschedparam
-.Nd thread scheduling parameter manipulation
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_setschedparam "pthread_t thread" "int policy" "const struct sched_param *param"
-.Ft int
-.Fn pthread_getschedparam "pthread_t thread" "int *policy" "struct sched_param *param"
-.Sh DESCRIPTION
-The
-.Fn pthread_setschedparam
-and
-.Fn pthread_getschedparam
-functions set and get the scheduling parameters of individual threads.
-The scheduling policy for a thread can either be
-.Dv SCHED_FIFO
-(first in, first out) or
-.Dv SCHED_RR
-(round-robin).
-The thread priority (accessed via
-.Va param->sched_priority )
-must be at least
-.Dv PTHREAD_MIN_PRIORITY
-and no more than
-.Dv PTHREAD_MAX_PRIORITY .
-.Sh RETURN VALUES
-If successful, these functions return 0.
-Otherwise, an error number is returned to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_setschedparam
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Invalid value for
-.Va policy .
-.It Bq Er ENOTSUP
-Invalid value for scheduling parameters.
-.It Bq Er ESRCH
-Non-existent thread
-.Va thread .
-.El
-.Pp
-The
-.Fn pthread_getschedparam
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er ESRCH
-Non-existent thread
-.Va thread .
-.El
-.Sh STANDARDS
-The
-.Fn pthread_setschedparam
-and
-.Fn pthread_getschedparam
-functions conform to
-.St -susv2
diff --git a/share/man/man3/pthread_self.3 b/share/man/man3/pthread_self.3
deleted file mode 100644
index db7dd29d46ec..000000000000
--- a/share/man/man3/pthread_self.3
+++ /dev/null
@@ -1,62 +0,0 @@
-.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by John Birrell.
-.\" 4. Neither the name of the author nor the names of any co-contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd April 4, 1996
-.Dt PTHREAD_SELF 3
-.Os
-.Sh NAME
-.Nm pthread_self
-.Nd get the calling thread's ID
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft pthread_t
-.Fn pthread_self "void"
-.Sh DESCRIPTION
-The
-.Fn pthread_self
-function returns the thread ID of the calling thread.
-.Sh RETURN VALUES
-The
-.Fn pthread_self
-function returns the thread ID of the calling thread.
-.Sh ERRORS
-None.
-.Sh SEE ALSO
-.Xr pthread_create 3 ,
-.Xr pthread_equal 3
-.Sh STANDARDS
-The
-.Fn pthread_self
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_set_name_np.3 b/share/man/man3/pthread_set_name_np.3
deleted file mode 100644
index a768e4c635ea..000000000000
--- a/share/man/man3/pthread_set_name_np.3
+++ /dev/null
@@ -1,55 +0,0 @@
-.\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd February 13, 2003
-.Dt PTHREAD_SET_NAME_NP 3
-.Os
-.Sh NAME
-.Nm pthread_set_name_np
-.Nd set the thread name
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread_np.h
-.Ft void
-.Fn pthread_set_name_np "pthread_t tid" "const char *name"
-.Sh DESCRIPTION
-The
-.Fn pthread_set_name_np
-function sets internal name for thread specified by
-.Fa tid
-argument to string value specified by
-.Fa name
-argument.
-.Pp
-This is a debugging interface and using it on a day-by-day basis makes
-no sense.
-.Sh ERRORS
-Because of the debugging nature of this function, all errors that may
-appear inside are silently ignored.
-.Sh AUTHORS
-This manual page was written by
-.An Alexey Zelkin Aq phantom@FreeBSD.org .
diff --git a/share/man/man3/pthread_setspecific.3 b/share/man/man3/pthread_setspecific.3
deleted file mode 100644
index a2c47d0918bb..000000000000
--- a/share/man/man3/pthread_setspecific.3
+++ /dev/null
@@ -1,98 +0,0 @@
-.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by John Birrell.
-.\" 4. Neither the name of the author nor the names of any co-contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd April 4, 1996
-.Dt PTHREAD_SETSPECIFIC 3
-.Os
-.Sh NAME
-.Nm pthread_setspecific
-.Nd set a thread-specific data value
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_setspecific "pthread_key_t key" "const void *value"
-.Sh DESCRIPTION
-The
-.Fn pthread_setspecific
-function associates a thread-specific value with a
-.Fa key
-obtained via a previous call to
-.Fn pthread_key_create .
-Different threads man bind different values to the same key.
-These values are
-typically pointers to blocks of dynamically allocated memory that have been
-reserved for use by the calling thread.
-.Pp
-The effect of calling
-.Fn pthread_setspecific
-with a key value not obtained from
-.Fn pthread_key_create
-or after
-.Fa key
-has been deleted with
-.Fn pthread_key_delete
-is undefined.
-.Pp
-The
-.Fn pthread_setspecific
-function may be called from a thread-specific data destructor function,
-however this may result in lost storage or infinite loops.
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_setspecific
-function will return zero.
-Otherwise an error number will be returned to
-indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_setspecific
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er ENOMEM
-Insufficient memory exists to associate the value with the
-.Fa key .
-.It Bq Er EINVAL
-The
-.Fa key
-value is invalid.
-.El
-.Sh SEE ALSO
-.Xr pthread_getspecific 3 ,
-.Xr pthread_key_create 3 ,
-.Xr pthread_key_delete 3
-.Sh STANDARDS
-The
-.Fn pthread_setspecific
-function conforms to
-.St -p1003.1-96 .
diff --git a/share/man/man3/pthread_sigmask.3 b/share/man/man3/pthread_sigmask.3
deleted file mode 100644
index df97ce1814b9..000000000000
--- a/share/man/man3/pthread_sigmask.3
+++ /dev/null
@@ -1,98 +0,0 @@
-.\" Copyright (C) 2000 Jason Evans <jasone@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(s), this list of conditions and the following disclaimer as
-.\" the first lines of this file unmodified other than the possible
-.\" addition of one or more copyright notices.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
-.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
-.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
-.Dd April 27, 2000
-.Dt PTHREAD_SIGMASK 3
-.Os
-.Sh NAME
-.Nm pthread_sigmask
-.Nd examine and/or change a thread's signal mask
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.In signal.h
-.Ft int
-.Fn pthread_sigmask "int how" "const sigset_t *set" "sigset_t *oset"
-.Sh DESCRIPTION
-The
-.Fn pthread_sigmask
-function examines and/or changes the calling thread's signal mask.
-.Pp
-If
-.Fa set
-is not
-.Dv NULL ,
-it specifies a set of signals to be modified, and
-.Fa how
-specifies what to set the signal mask to:
-.Bl -tag -width SIG_UNBLOCK
-.It Dv SIG_BLOCK
-Union of the current mask and
-.Fa set .
-.It Dv SIG_UNBLOCK
-Intersection of the current mask and the complement of
-.Fa set .
-.It Dv SIG_SETMASK
-.Fa set .
-.El
-.Pp
-If
-.Fa oset
-is not NULL, the previous signal mask is stored in the location pointed to by
-.Fa oset .
-.Pp
-.Dv SIGKILL
-and
-.Dv SIGSTOP
-cannot be blocked, and will be silently ignored if included in the signal mask.
-.Sh RETURN VALUES
-If successful,
-.Fn pthread_sigmask
-returns 0.
-Otherwise, an error is returned.
-.Sh ERRORS
-The
-.Fn pthread_sigmask
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-.Fa how
-is not one of the defined values.
-.El
-.Sh SEE ALSO
-.Xr sigaction 2 ,
-.Xr sigpending 2 ,
-.Xr sigprocmask 2 ,
-.Xr sigsuspend 2 ,
-.Xr sigsetops 3
-.Sh STANDARDS
-The
-.Fn pthread_sigmask
-function conforms to
-.St -p1003.1-96
diff --git a/share/man/man3/pthread_suspend_all_np.3 b/share/man/man3/pthread_suspend_all_np.3
deleted file mode 100644
index 56c78f1d0ea7..000000000000
--- a/share/man/man3/pthread_suspend_all_np.3
+++ /dev/null
@@ -1,53 +0,0 @@
-.\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd February 13, 2003
-.Dt PTHREAD_SUSPEND_ALL_NP 3
-.Os
-.Sh NAME
-.Nm pthread_suspend_all_np
-.Nd suspend all active threads
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread_np.h
-.Ft void
-.Fn pthread_suspend_all_np void
-.Sh DESCRIPTION
-The
-.Fn pthread_suspend_all_np
-function causes all active threads to be suspended.
-The only exception is the current thread,
-the thread that called the
-.Fn pthread_suspend_all_np
-function.
-.Sh SEE ALSO
-.Xr pthread_resume_all_np 3 ,
-.Xr pthread_resume_np 3 ,
-.Xr pthread_suspend_np 3
-.Sh AUTHORS
-This manual page was written by
-.An Alexey Zelkin Aq phantom@FreeBSD.org .
diff --git a/share/man/man3/pthread_suspend_np.3 b/share/man/man3/pthread_suspend_np.3
deleted file mode 100644
index c8a9c8fc9f0d..000000000000
--- a/share/man/man3/pthread_suspend_np.3
+++ /dev/null
@@ -1,70 +0,0 @@
-.\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd February 13, 2003
-.Dt PTHREAD_SUSPEND_NP 3
-.Os
-.Sh NAME
-.Nm pthread_suspend_np
-.Nd suspend a thread
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread_np.h
-.Ft int
-.Fn pthread_suspend_np "pthread_t tid"
-.Sh DESCRIPTION
-The
-.Fn pthread_suspend_np
-function, called on an active thread, causes it to suspend.
-.Sh RETURN VALUES
-If successful,
-.Fn pthread_suspend_np
-function returns 0.
-Otherwise, an error number is returned to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_suspend_np
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EDEADLK
-An attempt was made to suspend the current thread.
-.It Bq Er EINVAL
-The value specified by the
-.Fa tid
-argument is invalid.
-.It Bq ESRC
-No thread could be found corresponding to the thread ID specified by the
-.Fa tid
-argument.
-.El
-.Sh SEE ALSO
-.Xr pthread_resume_all_np 3 ,
-.Xr pthread_resume_np 3 ,
-.Xr pthread_suspend_all_np 3
-.Sh AUTHORS
-This manual page was written by
-.An Alexey Zelkin Aq phantom@FreeBSD.org .
diff --git a/share/man/man3/pthread_switch_add_np.3 b/share/man/man3/pthread_switch_add_np.3
deleted file mode 100644
index 9e7618c0233c..000000000000
--- a/share/man/man3/pthread_switch_add_np.3
+++ /dev/null
@@ -1,87 +0,0 @@
-.\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd February 13, 2003
-.Dt PTHREAD_SWITCH_ADD_NP 3
-.Os
-.Sh NAME
-.Nm pthread_switch_add_np ,
-.Nm pthread_switch_delete_np
-.Nd thread context switches debugging primitives
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread_np.h
-.Ft int
-.Fn pthread_switch_add_np "pthread_switch_routine_t routine"
-.Ft int
-.Fn pthread_switch_delete_np "pthread_switch_routine_t routine"
-.Sh DESCRIPTION
-An application is allowed to monitor the thread context switches inside
-the threading library.
-An application can install a routine that gets called every time a thread
-(explicitly created by an application with the
-.Xr pthread_create 3
-function) gets the context switched.
-The routine is passed the thread IDs of the threads that are
-being switched in and out.
-Installation and removal of these hooks may be done using the
-.Fn pthread_switch_add_np
-and
-.Fn pthread_switch_delete_np
-functions respectively.
-.Sh RETURN VALUES
-If successful,
-these functions return 0.
-Otherwise, an error number is returned to indicate the error.
-.Sh ERRORS
-The
-.Fn pthread_switch_add_np
-may fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-.Dv NULL
-pointer was passed in the
-.Fa routine
-argument.
-.El
-.Pp
-The
-.Fn pthread_switch_delete_np
-may fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The
-.Fa routine
-argument is different from the argument previously passed to the
-.Fn pthread_switch_add_np
-function.
-.El
-.Sh SEE ALSO
-.Xr pthread_create 3
-.Sh AUTHORS
-This manual page was written by
-.An Alexey Zelkin Aq phantom@FreeBSD.org .
diff --git a/share/man/man3/pthread_testcancel.3 b/share/man/man3/pthread_testcancel.3
deleted file mode 100644
index de692948f75a..000000000000
--- a/share/man/man3/pthread_testcancel.3
+++ /dev/null
@@ -1,210 +0,0 @@
-.\" $FreeBSD$
-.Dd January 17, 1999
-.Dt PTHREAD_TESTCANCEL 3
-.Os
-.Sh NAME
-.Nm pthread_setcancelstate ,
-.Nm pthread_setcanceltype ,
-.Nm pthread_testcancel
-.Nd set cancelability state
-.Sh LIBRARY
-.Lb libc_r
-.Sh SYNOPSIS
-.In pthread.h
-.Ft int
-.Fn pthread_setcancelstate "int state" "int *oldstate"
-.Ft int
-.Fn pthread_setcanceltype "int type" "int *oldtype"
-.Ft void
-.Fn pthread_testcancel "void"
-.Sh DESCRIPTION
-The
-.Fn pthread_setcancelstate
-function atomically both sets the calling thread's cancelability state
-to the indicated
-.Fa state
-and, if
-.Fa oldstate
-is not
-.Dv NULL ,
-returns the previous cancelability state at the location referenced by
-.Fa oldstate .
-Legal values for
-.Fa state
-are
-.Dv PTHREAD_CANCEL_ENABLE
-and
-.Dv PTHREAD_CANCEL_DISABLE .
-.Pp
-The
-.Fn pthread_setcanceltype
-function atomically both sets the calling thread's cancelability type
-to the indicated
-.Fa type
-and, if
-.Fa oldtype
-is not
-.Dv NULL ,
-returns the previous cancelability type at the location referenced by
-.Fa oldtype .
-Legal values for
-.Fa type
-are
-.Dv PTHREAD_CANCEL_DEFERRED
-and
-.Dv PTHREAD_CANCEL_ASYNCHRONOUS .
-.Pp
-The cancelability state and type of any newly created threads, including the
-thread in which
-.Fn main
-was first invoked, are
-.Dv PTHREAD_CANCEL_ENABLE
-and
-.Dv PTHREAD_CANCEL_DEFERRED
-respectively.
-.Pp
-The
-.Fn pthread_testcancel
-function creates a cancellation point in the calling thread.
-The
-.Fn pthread_testcancel
-function has no effect if cancelability is disabled.
-.Pp
-.Ss Cancelability States
-The cancelability state of a thread determines the action taken upon
-receipt of a cancellation request.
-The thread may control cancellation in
-a number of ways.
-.Pp
-Each thread maintains its own
-.Dq cancelability state
-which may be encoded in two bits:
-.Bl -hang
-.It Em Cancelability Enable
-When cancelability is
-.Dv PTHREAD_CANCEL_DISABLE ,
-cancellation requests against the target thread are held pending.
-.It Em Cancelability Type
-When cancelability is enabled and the cancelability type is
-.Dv PTHREAD_CANCEL_ASYNCHRONOUS ,
-new or pending cancellation requests may be acted upon at any time.
-When cancelability is enabled and the cancelability type is
-.Dv PTHREAD_CANCEL_DEFERRED ,
-cancellation requests are held pending until a cancellation point (see
-below) is reached.
-If cancelability is disabled, the setting of the
-cancelability type has no immediate effect as all cancellation requests
-are held pending; however, once cancelability is enabled again the new
-type will be in effect.
-.El
-.Ss Cancellation Points
-Cancellation points will occur when a thread is executing the following
-functions:
-.Fn close ,
-.Fn creat ,
-.Fn fcntl ,
-.Fn fsync ,
-.Fn msync ,
-.Fn nanosleep ,
-.Fn open ,
-.Fn pause ,
-.Fn pthread_cond_timedwait ,
-.Fn pthread_cond_wait ,
-.Fn pthread_join ,
-.Fn pthread_testcancel ,
-.Fn read ,
-.Fn sigwaitinfo ,
-.Fn sigsuspend ,
-.Fn sigwait ,
-.Fn sleep ,
-.Fn system ,
-.Fn tcdrain ,
-.Fn wait ,
-.Fn waitpid ,
-.Fn write .
-.Sh RETURN VALUES
-If successful, the
-.Fn pthread_setcancelstate
-and
-.Fn pthread_setcanceltype
-functions will return zero.
-Otherwise, an error number shall be returned to
-indicate the error.
-.Pp
-The
-.Fn pthread_setcancelstate
-and
-.Fn pthread_setcanceltype
-functions are used to control the points at which a thread may be
-asynchronously canceled.
-For cancellation control to be usable in modular
-fashion, some rules must be followed.
-.Pp
-For purposes of this discussion, consider an object to be a generalization
-of a procedure.
-It is a set of procedures and global variables written as
-a unit and called by clients not known by the object.
-Objects may depend
-on other objects.
-.Pp
-First, cancelability should only be disabled on entry to an object, never
-explicitly enabled.
-On exit from an object, the cancelability state should
-always be restored to its value on entry to the object.
-.Pp
-This follows from a modularity argument: if the client of an object (or the
-client of an object that uses that object) has disabled cancelability, it is
-because the client doesn't want to have to worry about how to clean up if the
-thread is canceled while executing some sequence of actions.
-If an object
-is called in such a state and it enables cancelability and a cancellation
-request is pending for that thread, then the thread will be canceled,
-contrary to the wish of the client that disabled.
-.Pp
-Second, the cancelability type may be explicitly set to either
-.Em deferred
-or
-.Em asynchronous
-upon entry to an object.
-But as with the cancelability state, on exit from
-an object that cancelability type should always be restored to its value on
-entry to the object.
-.Pp
-Finally, only functions that are cancel-safe may be called from a thread that
-is asynchronously cancelable.
-.Sh ERRORS
-The function
-.Fn pthread_setcancelstate
-may fail with:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The specified state is not
-.Dv PTHREAD_CANCEL_ENABLE
-or
-.Dv PTHREAD_CANCEL_DISABLE .
-.El
-.Pp
-The function
-.Fn pthread_setcanceltype
-may fail with:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The specified state is not
-.Dv PTHREAD_CANCEL_DEFERRED
-or
-.Dv PTHREAD_CANCEL_ASYNCHRONOUS .
-.El
-.Sh SEE ALSO
-.Xr pthread_cancel 3
-.Sh STANDARDS
-The
-.Fn pthread_testcancel
-function conforms to
-.St -p1003.1-96 .
-.Sh AUTHORS
-This man page was written by
-.An David Leonard Aq d@openbsd.org
-for the
-.Ox
-implementation of
-.Xr pthread_cancel 3 .
diff --git a/share/man/man4/cy.4 b/share/man/man4/cy.4
deleted file mode 100644
index d044cc655ea6..000000000000
--- a/share/man/man4/cy.4
+++ /dev/null
@@ -1,247 +0,0 @@
-.\" Copyright (c) 1990, 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" the Systems Programming Group of the University of Utah Computer
-.\" Science Department.
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" from: @(#)dca.4 5.2 (Berkeley) 3/27/91
-.\" from: com.4,v 1.1 1993/08/06 11:19:07 cgd Exp
-.\" from: sio.4,v 1.16 1995/06/26 06:05:30 bde Exp $
-.\" $FreeBSD$
-.\"
-.Dd June 14, 1999
-.Dt CY 4 i386
-.Os
-.Sh NAME
-.Nm cy
-.Nd Cyclades Cyclom-Y serial driver
-.Sh SYNOPSIS
-.Cd "options CY_PCI_FASTINTR"
-.Pp
-For one (PCI or ISA) card:
-.Bd -ragged -offset indent -compact
-.Cd "device cy 1"
-.Pp
-For one ISA card, in
-.Pa /boot/device.hints :
-.Cd hint.cy.0.at="isa"
-.Cd hint.cy.0.irq="10"
-.Cd hint.cy.0.maddr="0xd4000"
-.Cd hint.cy.0.msize="0x2000"
-.Ed
-.Pp
-For two (PCI and/or ISA) cards:
-.Bd -ragged -offset indent -compact
-.Cd "device cy 2"
-.Pp
-For two ISA cards, in
-.Pa /boot/device.hints :
-.Cd hint.cy.0.at="isa"
-.Cd hint.cy.0.irq="10"
-.Cd hint.cy.0.maddr="0xd4000"
-.Cd hint.cy.0.msize="0x2000"
-.Cd hint.cy.1.at="isa"
-.Cd hint.cy.1.irq="11"
-.Cd hint.cy.1.maddr="0xd6000"
-.Cd hint.cy.1.msize="0x2000"
-.Ed
-.Pp
-Minor numbering:
-.Bd -literal -offset indent -compact
-0b\fIMMMMMMMMMMMMMMMMxxxxxxxxOLIMMMMM\fR
- call\fBO\fRut
- \fBL\fRock
- \fBI\fRnitial
- \fBMMMMMMMMMMMMMMMM MMMMMM\fRinor
-.Ed
-.Sh DESCRIPTION
-The
-.Nm
-driver provides support for Cirrus Logic CD1400-based
-.Tn EIA
-.Tn RS-232C
-.Pf ( Tn CCITT
-.Tn V.24 )
-communications interfaces (ports) on Cyclades Cyclom-Y boards.
-Each CD1400 provides 4 ports.
-Cyclom-Y boards with various numbers of CD1400's are available.
-This driver supports up to 8 CD1400's (32 ports) per board.
-.Pp
-Input and output for each line may set independently
-to the following speeds:
-50, 75, 110, 134.5, 150, 300, 600, 1200, 1800, 2400, 4800, 9600,
-19200, 38400, 57600, or 115200 bps.
-Other speeds of up to 150000 are supported by the termios interface
-but not by the sgttyb compatibility interface.
-The CD1400 is not fast enough to handle speeds above 115200 bps
-effectively.
-It can transmit on a single line at slightly more than 115200 bps,
-but when 4 lines are active in both directions its limit is about
-90000 bps on each line.
-.\" XXX the following should be true for all serial drivers and
-.\" should not be repeated in the man pages for all serial drivers.
-.\" It was copied from sio.4. The only change was s/sio/cy/g.
-.Pp
-Serial ports controlled by the
-.Nm
-driver can be used for both `callin' and `callout'.
-For each port there is a callin device and a callout device.
-The minor number of the callout device is 128 higher
-than that of the corresponding callin port.
-The callin device is general purpose.
-Processes opening it normally wait for carrier
-and for the callout device to become inactive.
-The callout device is used to steal the port from
-processes waiting for carrier on the callin device.
-Processes opening it do not wait for carrier
-and put any processes waiting for carrier on the callin device into
-a deeper sleep so that they do not conflict with the callout session.
-The callout device is abused for handling programs that are supposed
-to work on general ports and need to open the port without waiting
-but are too stupid to do so.
-.Pp
-The
-.Nm
-driver also supports an initial-state and a lock-state control
-device for each of the callin and the callout "data" devices.
-The minor number of the initial-state device is 32 higher
-than that of the corresponding data device.
-The minor number of the lock-state device is 64 higher
-than that of the corresponding data device.
-The termios settings of a data device are copied
-from those of the corresponding initial-state device
-on first opens and are not inherited from previous opens.
-Use
-.Xr stty 1
-in the normal way on the initial-state devices to program
-initial termios states suitable for your setup.
-.Pp
-The lock termios state acts as flags to disable changing
-the termios state. E.g., to lock a flag variable such as
-CRTSCTS, use
-.Em "stty crtscts"
-on the lock-state device. Speeds and special characters
-may be locked by setting the corresponding value in the lock-state
-device to any nonzero value.
-.Pp
-Correct programs talking to correctly wired external devices
-work with almost arbitrary initial states and almost no locking,
-but other setups may benefit from changing some of the default
-initial state and locking the state.
-In particular, the initial states for non (POSIX) standard flags
-should be set to suit the devices attached and may need to be
-locked to prevent buggy programs from changing them.
-E.g., CRTSCTS should be locked on for devices that support
-RTS/CTS handshaking at all times and off for devices that don't
-support it at all. CLOCAL should be locked on for devices
-that don't support carrier. HUPCL may be locked off if you don't
-want to hang up for some reason. In general, very bad things happen
-if something is locked to the wrong state, and things should not
-be locked for devices that support more than one setting. The
-CLOCAL flag on callin ports should be locked off for logins
-to avoid certain security holes, but this needs to be done by
-getty if the callin port is used for anything else.
-.Ss Kernel Configuration Options
-The
-.Em CY_PCI_FASTINTR
-option should be used to avoid suboptimal interrupt handling for
-PCI Cyclades boards.
-The PCI BIOS must be configured with the
-.Nm
-interrupt not shared with any other active device
-for this option to work.
-This option is not the default because it is currently harmful in
-certain cases where it does not work.
-.Sh FILES
-.\" XXX more cloning: s/d/c/g and add a ? for the card number.
-.Bl -tag -width /dev/ttyic?? -compact
-.It Pa /dev/ttyc??
-for callin ports
-.It Pa /dev/ttyic??
-.It Pa /dev/ttylc??
-corresponding callin initial-state and lock-state devices
-.Pp
-.\" XXX more cloning: s/a/c/g. No consistency :-(.
-.It Pa /dev/cuac??
-for callout ports
-.It Pa /dev/cuaic??
-.It Pa /dev/cualc??
-corresponding callout initial-state and lock-state devices
-.El
-.Pp
-.Bl -tag -width /etc/rc.serial -compact
-.It Pa /etc/rc.serial
-examples of setting the initial-state and lock-state devices
-.El
-.Pp
-The first question mark in these device names is short for the
-card number
-(a decimal number between 0 and 65535 inclusive).
-The second question mark is short for the port number
-(a letter in the range [0-9a-v]).
-.Sh DIAGNOSTICS
-.Bl -diag
-.\" XXX back to s/sio/cy/g.
-.It cy%d: silo overflow.
-Problem in the interrupt handler.
-.El
-.Bl -diag
-.It cy%d: interrupt-level buffer overflow.
-Problem in the bottom half of the driver.
-.El
-.Bl -diag
-.It cy%d: tty-level buffer overflow.
-Problem in the application.
-Input has arrived faster than the given module could process it
-and some has been lost.
-.El
-.\" .Bl -diag
-.\" .It sio%d: reduced fifo trigger level to %d.
-.\" Attempting to avoid further silo overflows.
-.\" .El
-.Sh SEE ALSO
-.Xr stty 1 ,
-.Xr termios 4 ,
-.Xr tty 4 ,
-.Xr comcontrol 8 ,
-.Xr pstat 8
-.Sh HISTORY
-The
-.Nm
-driver is derived from the
-.Nm sio
-driver and the
-.Nx
-.Nm
-driver and is
-.Ud
-.Sh BUGS
-Serial consoles are not implemented.
diff --git a/share/man/man4/en.4 b/share/man/man4/en.4
deleted file mode 100644
index f13160e22807..000000000000
--- a/share/man/man4/en.4
+++ /dev/null
@@ -1,60 +0,0 @@
-.\" $FreeBSD$
-.\"
-.Dd December 29, 1997
-.Dt EN 4 i386
-.Os
-.Sh NAME
-.Nm en
-.Nd device driver for Midway-based ATM interfaces
-.Sh SYNOPSIS
-.Cd "device en"
-.Cd "device atm"
-.Sh DESCRIPTION
-The
-.Nm
-device driver supports Midway-based ATM interfaces including the
-Efficient Networks, Inc. ENI-155 and Adaptec ANA-59x0.
-Midway is an ALL5 SAR (Segmentation and Reassembly) chip.
-.Pp
-The driver only supports ATM PVCs. SVC or ATM-ARP is not supported.
-.Pp
-To configure the card for IP, use something like:
-.Dl # ifconfig en0 128.252.200.1 netmask 0xffffff00 up
-To add a PVC to a host you must use the ``route'' command:
-.Dl # route add -iface <remote IP address> -link en0:z.0.x.y
-where x and y are the byte encoding of the VCI to use, and z is the
-byte encoding of the following flags.
-.Dl 0x01 (use AAL5),
-.Dl 0x02 (if using AAL5, use a LLCSNAP header)
-Thus, parameter 3 means AAL5 and LLC/SNAP encapsulation.
-Note that BPF works only with LLC/SNAP encapsulation.
-.Sh EXAMPLES
-Suppose you have 2 hosts 128.252.200.1 and 128.252.200.2 connected
-by ATM through PVC # 201 (0xc9).
-To enable the link use the following commands:
-.Dl on host 128.252.200.1:
-.Dl # ifconfig en0 128.252.200.1 netmask 0xffffff00 up
-.Dl # route add -iface 128.252.200.2 -link en0:3.0.0.c9
-.Pp
-.Dl on host 128.252.200.2:
-.Dl # ifconfig en0 128.252.200.2 netmask 0xffffff00 up
-.Dl # route add -iface 128.252.200.1 -link en0:3.0.0.c9
-.Sh DIAGNOSTICS
-.Bd -literal
-en0 <Efficient Networks ENI-155p> rev 0 int a irq 5 on pci0:16
-en0: ATM midway v0, board IDs 6.0, Utopia (pipelined), 512KB on-board RAM
-en0: maximum DMA burst length = 64 bytes
-en0: 7 32KB receive buffers, 8 32KB transmit buffers allocated
-.Ed
-.Sh CAVEATS
-The driver extensively uses DMA on PCI.
-The first
-generation PCI chipsets do not work or exhibit poor performance.
-.Sh SEE ALSO
-.Xr ifconfig 8 ,
-.Xr route 8
-.Sh AUTHORS
-.An Chuck Cranor
-of Washington University implemented EN driver
-in 1996 for
-.Nx .
diff --git a/share/man/man4/mac_stub.4 b/share/man/man4/mac_stub.4
deleted file mode 100644
index a9cb6ee7e4a1..000000000000
--- a/share/man/man4/mac_stub.4
+++ /dev/null
@@ -1,98 +0,0 @@
-.\" Copyright (c) 2002 Networks Associates Technology, Inc.
-.\" All rights reserved.
-.\"
-.\" This software was developed for the FreeBSD Project by Chris Costello
-.\" at Safeport Network Services and Network Associates Laboratories, the
-.\" Security Research Division of Network Associates, Inc. under
-.\" DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
-.\" DARPA CHATS research program.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that 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 AUTHORS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (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$
-.Dd DECEMBER 1, 2002
-.Os
-.Dt MAC_NONE 4
-.Sh NAME
-.Nm mac_none
-.Nd sample MAC policy module
-.Sh SYNOPSIS
-To compile the sample policy
-into your kernel, place the following lines in your kernel
-configuration file:
-.Cd "options MAC"
-.Cd "options MAC_NONE"
-.Pp
-Alternately, to load the sample module at boot time, place the following line
-in your kernel configuration file:
-.Cd "options MAC"
-.Pp
-and in
-.Xr loader.conf 5 :
-.Cd mac_none_load= Ns \&"YES"
-.Sh DESCRIPTION
-The
-.Nm
-policy module implements a sample MAC policy that has no effect on
-access control in the system.
-Each MAC entry point is a
-.Dq no-op .
-.Ss Label Format
-No labels are defined for
-.Nm .
-.Sh SEE ALSO
-.Xr mac 4 ,
-.Xr mac_biba 4 ,
-.Xr mac_bsdextended 4 ,
-.Xr mac_ifoff 4 ,
-.Xr mac_lomac 4 ,
-.Xr mac_mls 4 ,
-.Xr mac_partition 4 ,
-.Xr mac_portacl 4 ,
-.Xr mac_seeotheruids 4 ,
-.Xr mac_test 4 ,
-.Xr mac 9
-.Sh HISTORY
-The
-.Nm
-policy module first appeared in
-.Fx 5.0
-and was developed by the TrustedBSD Project.
-.Sh AUTHORS
-This software was contributed to the
-.Fx
-Project by Network Associates Labs,
-the Security Research Division of Network Associates
-Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
-as part of the DARPA CHATS research program.
-.Sh BUGS
-See
-.Xr mac 9
-concerning appropriateness for production use.
-The TrustedBSD MAC Framework is considered experimental in
-.Fx .
-.Pp
-While the MAC Framework design is intended to support the containment of
-the root user, not all attack channels are currently protected by entry
-point checks.
-As such, MAC Framework policies should not be relied on, in isolation,
-to protect against a malicious privileged user.
diff --git a/share/man/man4/snd_csa.4 b/share/man/man4/snd_csa.4
deleted file mode 100644
index 4a535b88ef76..000000000000
--- a/share/man/man4/snd_csa.4
+++ /dev/null
@@ -1,63 +0,0 @@
-.\"
-.\" Copyright (c) 1999 Seigo Tanimura
-.\" 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$
-.\"
-.Dd December 18, 1999
-.Dt CSA 4
-.Os
-.Sh NAME
-.Nm csa
-.Nd Crystal Semiconductor CS461x/462x/4280 PCI bridge device driver
-.Sh SYNOPSIS
-.Cd "device csa"
-.Sh DESCRIPTION
-The
-.Nm
-bridge driver allows the generic audio drivers including
-.Xr pcm 4
-to attach to the following PCI sound cards:
-.Bl -bullet -width 2m
-.It
-Crystal Semiconductor CS461x/462x Audio Accelerator
-.It
-Crystal Semiconductor CS4280 Audio Controller
-.El
-.Pp
-Some onboard CS4610 chips are accompanied by the CS423x ISA codec
-instead of the CS4297 AC97 codec.
-Such configurations are not
-supported by
-.Nm
-yet.
-.Sh HISTORY
-The
-.Nm
-device driver first appeared in
-.Fx 4.0 .
-.Sh SEE ALSO
-.Xr pcm 4
-.Sh AUTHORS
-.An Seigo Tanimura Aq tanimura@r.dl.itc.u-tokyo.ac.jp
diff --git a/share/man/man4/snd_gusc.4 b/share/man/man4/snd_gusc.4
deleted file mode 100644
index 705c53dce6a2..000000000000
--- a/share/man/man4/snd_gusc.4
+++ /dev/null
@@ -1,78 +0,0 @@
-.\"
-.\" Copyright (c) 1999 Seigo Tanimura
-.\" 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$
-.\"
-.Dd December 18, 1999
-.Dt GUSC 4
-.Os
-.Sh NAME
-.Nm gusc
-.Nd Gravis UltraSound ISA bridge device driver
-.Sh SYNOPSIS
-.Cd "device pcm"
-.Cd "device gusc"
-.Pp
-For non-PnP cards, add the following lines in
-.Pa /boot/device.hints .
-.Cd hint.gusc.0.at="isa"
-.Cd hint.gusc.0.port="0x220"
-.Cd hint.gusc.0.irq="5"
-.Cd hint.gusc.0.drq="1"
-.Cd hint.gusc.0.flags="0x13"
-.Sh DESCRIPTION
-The
-.Nm
-bridge driver allows the generic audio drivers including
-.Xr pcm 4
-to attach to the following ISA sound cards:
-.Bl -bullet -width 2m
-.It
-Gravis UltraSound PnP
-.It
-Gravis UltraSound MAX
-.El
-.Pp
-The value of flags specifies the secondary DMA channel.
-If the secondary
-DMA channel is C, set the flags to (C | 0x10). For a sound card without the
-secondary DMA channel, the flags should be set to zero.
-.Sh DIAGNOSTICS
-.Bl -diag
-.It xxx: gus pcm not attached, out of memory
-There are not enough memory to drive the device.
-.El
-.Sh HISTORY
-The
-.Nm
-device driver first appeared in
-.Fx 4.0 .
-.Sh SEE ALSO
-.Xr pcm 4
-.Sh AUTHORS
-.An Ville-Pertti Keinonen Aq will@iki.fi
-.An Seigo Tanimura Aq tanimura@r.dl.itc.u-tokyo.ac.jp
-.Sh BUGS
-Recording pcm sound data is not supported yet.
diff --git a/share/man/man4/snd_maestro3.4 b/share/man/man4/snd_maestro3.4
deleted file mode 100644
index 29a801447df0..000000000000
--- a/share/man/man4/snd_maestro3.4
+++ /dev/null
@@ -1,76 +0,0 @@
-.\" Copyright (c) 2001 Scott Long
-.\" 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$
-.\"
-.Dd October 14, 2001
-.Dt MAESTRO3 4
-.Os
-.Sh NAME
-.Nm maestro3
-.Nd FreeBSD audio sub-driver for ESS Maestro3/Allegro-1 hardware
-.Sh SYNOPSIS
-.Li "kldload snd_maestro3"
-.Sh DESCRIPTION
-The
-.Nm
-driver provides support for the ESS Maestro3 and Allegro-1 sound chips
-under the PCM framework.
-These chips are mostly found in laptop computers and feature an AC97 mixer,
-a multi-channel sample rate converter that can mix up to four digital audio
-streams in hardware, recording support, and external volume control buttons.
-.Pp
-The firmware for the sound processor is licensed under the GNU Public
-License, and thus this driver is not included in the default
-.Pa GENERIC
-kernel, nor is it compiled into the kernel when
-.Cd "device pcm"
-is specified in the kernel config file.
-A convenient way to automatically load the driver is to add the line
-.Pp
-.Dl snd_maestro3_load="YES"
-.Pp
-to the file
-.Pa /boot/loader.conf .
-.Sh DIAGNOSTICS
-The hardware volume control buttons can be connected to two different pin
-sets on the chip, depending on the manufacturer.
-The driver has no way of determining this configuration, so a hint may be
-used to override the default guess.
-Add the line
-.Dq Li hint.pcm.0.hwvol_config="0"
-to the file
-.Pa /boot/device.hints
-to override the default setting.
-.Sh SEE ALSO
-.Xr pcm 4 ,
-.Xr loader.conf 5
-.Sh HISTORY
-The
-.Nm
-driver first appeared in
-.Fx 4.3 .
-.Sh AUTHORS
-.An Scott Long Aq scottl@FreeBSD.org
-.An Darrel Anderson Aq anderson@cs.duke.edu
diff --git a/share/man/man4/snd_sbc.4 b/share/man/man4/snd_sbc.4
deleted file mode 100644
index 95bb542146c4..000000000000
--- a/share/man/man4/snd_sbc.4
+++ /dev/null
@@ -1,79 +0,0 @@
-.\"
-.\" Copyright (c) 1999 Seigo Tanimura
-.\" 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$
-.\"
-.Dd December 18, 1999
-.Dt SBC 4
-.Os
-.Sh NAME
-.Nm sbc
-.Nd Creative Sound Blaster ISA and compatible bridge device driver
-.Sh SYNOPSIS
-.Cd "device sbc"
-.Pp
-Non-PnP cards require the following lines in
-.Pa /boot/device.hints :
-.Cd hint.sbc.0.at="isa"
-.Cd hint.sbc.0.port="0x220"
-.Cd hint.sbc.0.irq="5"
-.Cd hint.sbc.0.drq="1"
-.Cd hint.sbc.0.flags="0x15"
-.Sh DESCRIPTION
-The
-.Nm
-bridge driver allows the generic audio drivers including
-.Xr pcm 4
-to attach to the following ISA sound cards:
-.Bl -bullet -width 2m
-.It
-Creative SB16, SB32, SB AWE64 (including Gold) and ViBRA16
-.It
-Advance Asound 100, 110 and Logic ALS120
-.It
-ESS ES1868, ES1869, ES1879 and ES1888
-.El
-.Pp
-The value of flags specifies the secondary DMA channel.
-If the secondary
-DMA channel is C, set the flags to (C | 0x10). For a sound card without the
-secondary DMA channel, the flags should be set to zero.
-.Sh DIAGNOSTICS
-.Bl -diag
-.It sb_dspwr(XX) timed out.
-A command to the DSP has timed out.
-Check the I/O port configuration.
-.It bad irq XX (5/7/9/10 valid)
-The IRQ given to the driver is not valid.
-.El
-.Sh HISTORY
-The
-.Nm
-device driver first appeared in
-.Fx 4.0 .
-.Sh SEE ALSO
-.Xr pcm 4
-.Sh AUTHORS
-.An Seigo Tanimura Aq tanimura@r.dl.itc.u-tokyo.ac.jp
diff --git a/share/man/man4/spkr.4 b/share/man/man4/spkr.4
deleted file mode 100644
index dec3264bfd01..000000000000
--- a/share/man/man4/spkr.4
+++ /dev/null
@@ -1,236 +0,0 @@
-.\"
-.\" $FreeBSD$
-.\"
-.Dd November 7, 1993
-.Dt SPKR 4 i386
-.Os
-.Sh NAME
-.Nm speaker ,
-.Nm spkr
-.Nd console speaker device driver
-.Sh SYNOPSIS
-.Cd device speaker
-.In machine/speaker.h
-.Sh DESCRIPTION
-The speaker device driver allows applications to control the PC console
-speaker on an
-.Tn IBM-PC Ns --compatible
-machine running
-.Fx .
-.Pp
-Only one process may have this device open at any given time;
-.Xr open 2
-and
-.Xr close 2
-are used to lock and relinquish it.
-An attempt to open when
-another process has the device locked will return -1 with an
-.Er EBUSY
-error
-indication.
-Writes to the device are interpreted as `play strings' in a
-simple ASCII melody notation.
-An
-.Xr ioctl 2
-request
-for tone generation at arbitrary
-frequencies is also supported.
-.Pp
-Sound-generation does not monopolize the processor; in fact, the driver
-spends most of its time sleeping while the PC hardware is emitting
-tones.
-Other processes may emit beeps while the driver is running.
-.Pp
-Applications may call
-.Xr ioctl 2
-on a speaker file descriptor to control the
-speaker driver directly; definitions for the
-.Xr ioctl 2
-interface are in
-.Pa /usr/include/machine/speaker.h .
-The
-.Li tone_t
-structure used in these calls has two fields,
-specifying a frequency (in Hz) and a duration (in 1/100ths of a second).
-A frequency of zero is interpreted as a rest.
-.Pp
-At present there are two such
-.Xr ioctl 2
-calls.
-.Dv SPKRTONE
-accepts a pointer to a
-single tone structure as third argument and plays it.
-.Dv SPKRTUNE
-accepts a
-pointer to the first of an array of tone structures and plays them in
-continuous sequence; this array must be terminated by a final member with
-a zero duration.
-.Pp
-The play-string language is modeled on the PLAY statement conventions of
-.Tn IBM
-Advanced BASIC 2.0. The
-.Li MB ,
-.Li MF ,
-and
-.Li X
-primitives of PLAY are not
-useful in a timesharing environment and are omitted.
-The `octave-tracking'
-feature and the slur mark are new.
-.Pp
-There are 84 accessible notes numbered 1-84 in 7 octaves, each running from
-C to B, numbered 0-6; the scale is equal-tempered A440 and octave 3 starts
-with middle C. By default, the play function emits half-second notes with the
-last 1/16th second being `rest time'.
-.Pp
-Play strings are interpreted left to right as a series of play command groups;
-letter case is ignored.
-Play command groups are as follows:
-.Bl -tag -width CDEFGABxx
-.It Li CDEFGAB
-Letters A through G cause the corresponding note to be played in the
-current octave. A note letter may optionally be followed by an
-.Dq Em "accidental sign" ,
-one of # + or -; the first two of these cause it to be sharped one
-half-tone, the last causes it to be flatted one half-tone. It may
-also be followed by a time value number and by sustain dots (see
-below). Time values are interpreted as for the L command below.
-.It Ns Li O Sy n
-If
-.Sy n
-is numeric, this sets the current octave.
-.Sy n
-may also be one of
-.Li L
-or
-.Li N
-to enable or disable octave-tracking (it is disabled by default).
-When octave-tracking is on, interpretation of a pair of letter notes
-will change octaves if necessary in order to make the smallest
-possible jump between notes.
-Thus ``olbc'' will be played as
-``olb>c'', and ``olcb'' as ``olc<b''. Octave locking is disabled for
-one letter note following >, < and O[0123456]. (The octave-locking
-feature is not supported in
-.Tn IBM
-BASIC.)
-.It Li >
-Bump the current octave up one.
-.It Li <
-Drop the current octave down one.
-.It Ns Li N Sy n
-Play note
-.Sy n ,
-.Sy n
-being 1 to 84 or 0 for a rest of current time value.
-May be followed by sustain dots.
-.It Ns Li L Sy n
-Sets the current time value for notes. The default is
-.Li L4 ,
-quarter or crotchet notes.
-The lowest possible value is 1; values up
-to 64 are accepted.
-.Li L1
-sets whole notes,
-.Li L2
-sets half notes,
-.Li L4
-sets quarter notes, etc.
-.It Ns Li P Sy n
-Pause (rest), with
-.Sy n
-interpreted as for
-.Li L Sy n .
-May be followed by
-sustain dots. May also be written
-.Li ~ .
-.It Ns Li T Sy n
-Sets the number of quarter notes per minute; default is 120. Musical
-names for common tempi are:
-.Bd -literal -offset indent
- Tempo Beats Per Minute
-very slow Larghissimo
- Largo 40-60
- Larghetto 60-66
- Grave
- Lento
- Adagio 66-76
-slow Adagietto
- Andante 76-108
-medium Andantino
- Moderato 108-120
-fast Allegretto
- Allegro 120-168
- Vivace
- Veloce
- Presto 168-208
-very fast Prestissimo
-.Ed
-.It Li M[LNS]
-Set articulation.
-.Li MN
-.Li ( N
-for normal) is the default; the last 1/8th of
-the note's value is rest time.
-You can set
-.Li ML
-for legato (no rest space) or
-.Li MS
-for staccato (1/4 rest space).
-.El
-.Pp
-Notes (that is,
-.Li CDEFGAB
-or
-.Li N
-command character groups) may be followed by
-sustain dots.
-Each dot causes the note's value to be lengthened by one-half
-for each one.
-Thus, a note dotted once is held for 3/2 of its undotted value;
-dotted twice, it is held 9/4, and three times would give 27/8.
-.Pp
-A note and its sustain dots may also be followed by a slur mark (underscore).
-This causes the normal micro-rest after the note to be filled in, slurring it
-to the next one. (The slur feature is not supported in
-.Tn IBM
-BASIC.)
-.Pp
-Whitespace in play strings is simply skipped and may be used to separate
-melody sections.
-.Sh BUGS
-Due to roundoff in the pitch tables and slop in the tone-generation and timer
-hardware (neither of which was designed for precision), neither pitch accuracy
-nor timings will be mathematically exact.
-There is no volume control.
-.Pp
-The action of two or more sustain dots does not reflect standard musical
-notation, in which each dot adds half the value of the previous dot
-modifier, not half the value of the note as modified. Thus, a note dotted
-once is held for 3/2 of its undotted value; dotted twice, it is held 7/4,
-and three times would give 15/8. The multiply-by-3/2 interpretation,
-however, is specified in the
-.Tn IBM
-BASIC manual and has been retained for
-compatibility.
-.Pp
-In play strings which are very long (longer than your system's physical I/O
-blocks) note suffixes or numbers may occasionally be parsed incorrectly due
-to crossing a block boundary.
-.Sh FILES
-.Bl -tag -width /dev/speakerxx
-.It Pa /dev/speaker
-speaker device file
-.El
-.Sh SEE ALSO
-.Xr spkrtest 8
-.Sh AUTHORS
-.An Eric S. Raymond Aq esr@snark.thyrsus.com
-June 1990
-.Sh "PORTED BY"
-.An Andrew A. Chernov Aq ache@astral.msk.su
-.Sh HISTORY
-The
-.Nm
-device appeared in
-.Fx 1.0 .
diff --git a/share/man/man4/tx.4 b/share/man/man4/tx.4
deleted file mode 100644
index c328565c7686..000000000000
--- a/share/man/man4/tx.4
+++ /dev/null
@@ -1,108 +0,0 @@
-.\"
-.\" Copyright (c) 1998-2001 Semen Ustimenko (semenu@FreeBSD.org)
-.\"
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
-.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
-.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-.\" (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$
-.\"
-.Dd February 8, 2001
-.Dt TX 4 i386
-.Os
-.Sh NAME
-.Nm tx
-.Nd "SMC 83c17x Fast Ethernet device driver"
-.Sh SYNOPSIS
-.Cd "device miibus"
-.Cd "device tx"
-.Sh DESCRIPTION
-The
-.Nm
-driver provides support for the Ethernet adapters based on the
-SMC 83c17x (EPIC) chips.
-These are mostly SMC 9432 series cards.
-.Pp
-The
-.Nm
-driver supports the following media types (depending on card's capabilities):
-.Pp
-.Bl -tag -width ".Cm 10baseT/UTP"
-.It autoselect
-Enable autonegotiation (default)
-.It Cm 100baseFX
-Set 100Mbps (fast ethernet) fiber optic operation
-.It Cm 100baseTX
-Set 100Mbps (fast ethernet) twisted pair operation
-.It Cm 10baseT/UTP
-Set 10Mbps on 10baseT port
-.It Cm 10base2/BNC
-Set 10Mbps on 10base2 port
-.El
-.Pp
-The
-.Nm
-driver supports the following media options:
-.Pp
-.Bl -tag -width ".Cm full-duplex"
-.It Cm full-duplex
-Set full-duplex operation
-.El
-.Pp
-Driver supports oversized ethernet packets (up to 1600 bytes).
-Refer to the
-.Xr ifconfig 8
-man page on setting the interface's MTU.
-.Pp
-The old
-.Dq Li "ifconfig tx0 linkN"
-method of configuration is not supported.
-.Ss "VLAN (IEEE 802.1Q) support"
-The
-.Nm
-driver supports the VLAN operation (using
-.Xr vlan 4
-interface) without decreasing the MTU on the
-.Xr vlan 4
-interfaces.
-.Sh DIAGNOSTICS
-.Bl -diag
-.It "tx%d: device timeout %d packets"
-The device stops responding.
-Device and driver reset follows this error.
-.It "tx%d: PCI fatal error occurred (%s)"
-One of following errors occurred: PCI Target Abort, PCI Master Abort, Data
-Parity Error or Address Parity Error.
-Device and driver reset follows this error.
-.It "tx%d: cannot allocate mbuf header/cluster"
-Cannot allocate memory for received packet.
-Packet thrown away.
-.It "tx%d: can't stop %s DMA"
-While reseting, driver failed to stop device correctly.
-.El
-.Sh BUGS
-The auto-negotiation does not work very well.
-.Sh SEE ALSO
-.Xr arp 4 ,
-.Xr miibus 4 ,
-.Xr netintro 4 ,
-.Xr ng_ether 4 ,
-.Xr ifconfig 8
diff --git a/share/man/man9/VOP_VPTOFH.9 b/share/man/man9/VOP_VPTOFH.9
deleted file mode 100644
index 676e2309e9b1..000000000000
--- a/share/man/man9/VOP_VPTOFH.9
+++ /dev/null
@@ -1,61 +0,0 @@
-.\" -*- nroff -*-
-.\"
-.\" Copyright (c) 1996 Doug Rabson
-.\"
-.\" All rights reserved.
-.\"
-.\" This program is free software.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that 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 DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
-.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
-.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-.\" (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$
-.\"
-.Dd July 24, 1996
-.Os
-.Dt VFS_VPTOFH 9
-.Sh NAME
-.Nm VFS_VPTOFH
-.Nd turn a vnode into an NFS filehandle
-.Sh SYNOPSIS
-.In sys/param.h
-.In sys/mount.h
-.In sys/vnode.h
-.Ft int
-.Fn VFS_VPTOFH "struct vnode *vp" "struct fid *fhp"
-.Sh DESCRIPTION
-This is used by the NFS server to create an opaque filehandle which
-uniquely identifies the file and which can be used by an NFS client
-to access the file in the future.
-.Pp
-Its arguments are:
-.Bl -tag -width fhp
-.It Ar vp
-The vnode to make a filehandle for.
-.It Ar fhp
-Return parameter for the filehandle.
-.El
-.Sh SEE ALSO
-.Xr VFS 9 ,
-.Xr VFS_FHTOVP 9 ,
-.Xr vnode 9
-.Sh AUTHORS
-This man page was written by
-.An Doug Rabson .
diff --git a/share/zoneinfo/backward b/share/zoneinfo/backward
index 84f3de51b15a..eace5ab33b98 100644
--- a/share/zoneinfo/backward
+++ b/share/zoneinfo/backward
@@ -1,13 +1,23 @@
-# @(#)backward 7.15
+# @(#)backward 7.23
# This file provides links between current names for time zones
# and their old names. Many names changed in late 1993.
Link America/Adak America/Atka
+Link America/Tijuana America/Ensenada
Link America/Indianapolis America/Fort_Wayne
Link America/Indiana/Knox America/Knox_IN
+Link America/Rio_Branco America/Porto_Acre
+Link America/Cordoba America/Rosario
Link America/St_Thomas America/Virgin
+Link Asia/Ashgabat Asia/Ashkhabad
+Link Asia/Chongqing Asia/Chungking
+Link Asia/Dhaka Asia/Dacca
+Link Asia/Macau Asia/Macao
+Link Asia/Makassar Asia/Ujung_Pandang
Link Asia/Jerusalem Asia/Tel_Aviv
+Link Asia/Thimphu Asia/Thimbu
+Link Asia/Ulaanbaatar Asia/Ulan_Bator
Link Australia/Sydney Australia/ACT
Link Australia/Sydney Australia/Canberra
Link Australia/Lord_Howe Australia/LHI
@@ -37,7 +47,9 @@ Link Pacific/Easter Chile/EasterIsland
Link America/Havana Cuba
Link Africa/Cairo Egypt
Link Europe/Dublin Eire
+Link Europe/Chisinau Europe/Tiraspol
Link Europe/London GB
+Link Europe/London GB-Eire
Link Etc/GMT+0 GMT+0
Link Etc/GMT-0 GMT-0
Link Etc/GMT0 GMT0
@@ -57,9 +69,9 @@ Link America/Denver Navajo
Link Pacific/Auckland NZ
Link Pacific/Chatham NZ-CHAT
Link Pacific/Pago_Pago Pacific/Samoa
-Link Asia/Shanghai PRC
Link Europe/Warsaw Poland
Link Europe/Lisbon Portugal
+Link Asia/Shanghai PRC
Link Asia/Taipei ROC
Link Asia/Seoul ROK
Link Asia/Singapore Singapore
diff --git a/sys/amd64/amd64/amd64_mem.c b/sys/amd64/amd64/amd64_mem.c
deleted file mode 100644
index 589fc64721cb..000000000000
--- a/sys/amd64/amd64/amd64_mem.c
+++ /dev/null
@@ -1,620 +0,0 @@
-/*-
- * Copyright (c) 1999 Michael Smith <msmith@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/memrange.h>
-#include <sys/smp.h>
-#include <sys/sysctl.h>
-
-#include <machine/md_var.h>
-#include <machine/specialreg.h>
-
-/*
- * i686 memory range operations
- *
- * This code will probably be impenetrable without reference to the
- * Intel Pentium Pro documentation.
- */
-
-static char *mem_owner_bios = "BIOS";
-
-#define MR686_FIXMTRR (1<<0)
-
-#define mrwithin(mr, a) \
- (((a) >= (mr)->mr_base) && ((a) < ((mr)->mr_base + (mr)->mr_len)))
-#define mroverlap(mra, mrb) \
- (mrwithin(mra, mrb->mr_base) || mrwithin(mrb, mra->mr_base))
-
-#define mrvalid(base, len) \
- ((!(base & ((1 << 12) - 1))) && /* base is multiple of 4k */ \
- ((len) >= (1 << 12)) && /* length is >= 4k */ \
- powerof2((len)) && /* ... and power of two */ \
- !((base) & ((len) - 1))) /* range is not discontiuous */
-
-#define mrcopyflags(curr, new) (((curr) & ~MDF_ATTRMASK) | ((new) & MDF_ATTRMASK))
-
-static int mtrrs_disabled;
-TUNABLE_INT("machdep.disable_mtrrs", &mtrrs_disabled);
-SYSCTL_INT(_machdep, OID_AUTO, disable_mtrrs, CTLFLAG_RD,
- &mtrrs_disabled, 0, "Disable i686 MTRRs.");
-
-static void i686_mrinit(struct mem_range_softc *sc);
-static int i686_mrset(struct mem_range_softc *sc,
- struct mem_range_desc *mrd,
- int *arg);
-static void i686_mrAPinit(struct mem_range_softc *sc);
-
-static struct mem_range_ops i686_mrops = {
- i686_mrinit,
- i686_mrset,
- i686_mrAPinit
-};
-
-/* XXX for AP startup hook */
-static u_int64_t mtrrcap, mtrrdef;
-
-static struct mem_range_desc *mem_range_match(struct mem_range_softc *sc,
- struct mem_range_desc *mrd);
-static void i686_mrfetch(struct mem_range_softc *sc);
-static int i686_mtrrtype(int flags);
-static int i686_mrt2mtrr(int flags, int oldval);
-static int i686_mtrrconflict(int flag1, int flag2);
-static void i686_mrstore(struct mem_range_softc *sc);
-static void i686_mrstoreone(void *arg);
-static struct mem_range_desc *i686_mtrrfixsearch(struct mem_range_softc *sc,
- u_int64_t addr);
-static int i686_mrsetlow(struct mem_range_softc *sc,
- struct mem_range_desc *mrd,
- int *arg);
-static int i686_mrsetvariable(struct mem_range_softc *sc,
- struct mem_range_desc *mrd,
- int *arg);
-
-/* i686 MTRR type to memory range type conversion */
-static int i686_mtrrtomrt[] = {
- MDF_UNCACHEABLE,
- MDF_WRITECOMBINE,
- MDF_UNKNOWN,
- MDF_UNKNOWN,
- MDF_WRITETHROUGH,
- MDF_WRITEPROTECT,
- MDF_WRITEBACK
-};
-
-#define MTRRTOMRTLEN (sizeof(i686_mtrrtomrt) / sizeof(i686_mtrrtomrt[0]))
-
-static int
-i686_mtrr2mrt(int val) {
- if (val < 0 || val >= MTRRTOMRTLEN)
- return MDF_UNKNOWN;
- return i686_mtrrtomrt[val];
-}
-
-/*
- * i686 MTRR conflicts. Writeback and uncachable may overlap.
- */
-static int
-i686_mtrrconflict(int flag1, int flag2) {
- flag1 &= MDF_ATTRMASK;
- flag2 &= MDF_ATTRMASK;
- if (flag1 == flag2 ||
- (flag1 == MDF_WRITEBACK && flag2 == MDF_UNCACHEABLE) ||
- (flag2 == MDF_WRITEBACK && flag1 == MDF_UNCACHEABLE))
- return 0;
- return 1;
-}
-
-/*
- * Look for an exactly-matching range.
- */
-static struct mem_range_desc *
-mem_range_match(struct mem_range_softc *sc, struct mem_range_desc *mrd)
-{
- struct mem_range_desc *cand;
- int i;
-
- for (i = 0, cand = sc->mr_desc; i < sc->mr_ndesc; i++, cand++)
- if ((cand->mr_base == mrd->mr_base) &&
- (cand->mr_len == mrd->mr_len))
- return(cand);
- return(NULL);
-}
-
-/*
- * Fetch the current mtrr settings from the current CPU (assumed to all
- * be in sync in the SMP case). Note that if we are here, we assume
- * that MTRRs are enabled, and we may or may not have fixed MTRRs.
- */
-static void
-i686_mrfetch(struct mem_range_softc *sc)
-{
- struct mem_range_desc *mrd;
- u_int64_t msrv;
- int i, j, msr;
-
- mrd = sc->mr_desc;
-
- /* Get fixed-range MTRRs */
- if (sc->mr_cap & MR686_FIXMTRR) {
- msr = MSR_MTRR64kBase;
- for (i = 0; i < (MTRR_N64K / 8); i++, msr++) {
- msrv = rdmsr(msr);
- for (j = 0; j < 8; j++, mrd++) {
- mrd->mr_flags = (mrd->mr_flags & ~MDF_ATTRMASK) |
- i686_mtrr2mrt(msrv & 0xff) |
- MDF_ACTIVE;
- if (mrd->mr_owner[0] == 0)
- strcpy(mrd->mr_owner, mem_owner_bios);
- msrv = msrv >> 8;
- }
- }
- msr = MSR_MTRR16kBase;
- for (i = 0; i < (MTRR_N16K / 8); i++, msr++) {
- msrv = rdmsr(msr);
- for (j = 0; j < 8; j++, mrd++) {
- mrd->mr_flags = (mrd->mr_flags & ~MDF_ATTRMASK) |
- i686_mtrr2mrt(msrv & 0xff) |
- MDF_ACTIVE;
- if (mrd->mr_owner[0] == 0)
- strcpy(mrd->mr_owner, mem_owner_bios);
- msrv = msrv >> 8;
- }
- }
- msr = MSR_MTRR4kBase;
- for (i = 0; i < (MTRR_N4K / 8); i++, msr++) {
- msrv = rdmsr(msr);
- for (j = 0; j < 8; j++, mrd++) {
- mrd->mr_flags = (mrd->mr_flags & ~MDF_ATTRMASK) |
- i686_mtrr2mrt(msrv & 0xff) |
- MDF_ACTIVE;
- if (mrd->mr_owner[0] == 0)
- strcpy(mrd->mr_owner, mem_owner_bios);
- msrv = msrv >> 8;
- }
- }
- }
-
- /* Get remainder which must be variable MTRRs */
- msr = MSR_MTRRVarBase;
- for (; (mrd - sc->mr_desc) < sc->mr_ndesc; msr += 2, mrd++) {
- msrv = rdmsr(msr);
- mrd->mr_flags = (mrd->mr_flags & ~MDF_ATTRMASK) |
- i686_mtrr2mrt(msrv & 0xff);
- mrd->mr_base = msrv & 0x0000000ffffff000LL;
- msrv = rdmsr(msr + 1);
- mrd->mr_flags = (msrv & 0x800) ?
- (mrd->mr_flags | MDF_ACTIVE) :
- (mrd->mr_flags & ~MDF_ACTIVE);
- /* Compute the range from the mask. Ick. */
- mrd->mr_len = (~(msrv & 0x0000000ffffff000LL) & 0x0000000fffffffffLL) + 1;
- if (!mrvalid(mrd->mr_base, mrd->mr_len))
- mrd->mr_flags |= MDF_BOGUS;
- /* If unclaimed and active, must be the BIOS */
- if ((mrd->mr_flags & MDF_ACTIVE) && (mrd->mr_owner[0] == 0))
- strcpy(mrd->mr_owner, mem_owner_bios);
- }
-}
-
-/*
- * Return the MTRR memory type matching a region's flags
- */
-static int
-i686_mtrrtype(int flags)
-{
- int i;
-
- flags &= MDF_ATTRMASK;
-
- for (i = 0; i < MTRRTOMRTLEN; i++) {
- if (i686_mtrrtomrt[i] == MDF_UNKNOWN)
- continue;
- if (flags == i686_mtrrtomrt[i])
- return(i);
- }
- return(-1);
-}
-
-static int
-i686_mrt2mtrr(int flags, int oldval)
-{
- int val;
-
- if ((val = i686_mtrrtype(flags)) == -1)
- return oldval & 0xff;
- return val & 0xff;
-}
-
-/*
- * Update running CPU(s) MTRRs to match the ranges in the descriptor
- * list.
- *
- * XXX Must be called with interrupts enabled.
- */
-static void
-i686_mrstore(struct mem_range_softc *sc)
-{
-#ifdef SMP
- /*
- * We should use ipi_all_but_self() to call other CPUs into a
- * locking gate, then call a target function to do this work.
- * The "proper" solution involves a generalised locking gate
- * implementation, not ready yet.
- */
- smp_rendezvous(NULL, i686_mrstoreone, NULL, (void *)sc);
-#else
- disable_intr(); /* disable interrupts */
- i686_mrstoreone((void *)sc);
- enable_intr();
-#endif
-}
-
-/*
- * Update the current CPU's MTRRs with those represented in the
- * descriptor list. Note that we do this wholesale rather than
- * just stuffing one entry; this is simpler (but slower, of course).
- */
-static void
-i686_mrstoreone(void *arg)
-{
- struct mem_range_softc *sc = (struct mem_range_softc *)arg;
- struct mem_range_desc *mrd;
- u_int64_t omsrv, msrv;
- int i, j, msr;
- u_int cr4save;
-
- mrd = sc->mr_desc;
-
- cr4save = rcr4(); /* save cr4 */
- if (cr4save & CR4_PGE)
- load_cr4(cr4save & ~CR4_PGE);
- load_cr0((rcr0() & ~CR0_NW) | CR0_CD); /* disable caches (CD = 1, NW = 0) */
- wbinvd(); /* flush caches, TLBs */
- wrmsr(MSR_MTRRdefType, rdmsr(MSR_MTRRdefType) & ~0x800); /* disable MTRRs (E = 0) */
-
- /* Set fixed-range MTRRs */
- if (sc->mr_cap & MR686_FIXMTRR) {
- msr = MSR_MTRR64kBase;
- for (i = 0; i < (MTRR_N64K / 8); i++, msr++) {
- msrv = 0;
- omsrv = rdmsr(msr);
- for (j = 7; j >= 0; j--) {
- msrv = msrv << 8;
- msrv |= i686_mrt2mtrr((mrd + j)->mr_flags, omsrv >> (j*8));
- }
- wrmsr(msr, msrv);
- mrd += 8;
- }
- msr = MSR_MTRR16kBase;
- for (i = 0; i < (MTRR_N16K / 8); i++, msr++) {
- msrv = 0;
- omsrv = rdmsr(msr);
- for (j = 7; j >= 0; j--) {
- msrv = msrv << 8;
- msrv |= i686_mrt2mtrr((mrd + j)->mr_flags, omsrv >> (j*8));
- }
- wrmsr(msr, msrv);
- mrd += 8;
- }
- msr = MSR_MTRR4kBase;
- for (i = 0; i < (MTRR_N4K / 8); i++, msr++) {
- msrv = 0;
- omsrv = rdmsr(msr);
- for (j = 7; j >= 0; j--) {
- msrv = msrv << 8;
- msrv |= i686_mrt2mtrr((mrd + j)->mr_flags, omsrv >> (j*8));
- }
- wrmsr(msr, msrv);
- mrd += 8;
- }
- }
-
- /* Set remainder which must be variable MTRRs */
- msr = MSR_MTRRVarBase;
- for (; (mrd - sc->mr_desc) < sc->mr_ndesc; msr += 2, mrd++) {
- /* base/type register */
- omsrv = rdmsr(msr);
- if (mrd->mr_flags & MDF_ACTIVE) {
- msrv = mrd->mr_base & 0x0000000ffffff000LL;
- msrv |= i686_mrt2mtrr(mrd->mr_flags, omsrv);
- } else {
- msrv = 0;
- }
- wrmsr(msr, msrv);
-
- /* mask/active register */
- if (mrd->mr_flags & MDF_ACTIVE) {
- msrv = 0x800 | (~(mrd->mr_len - 1) & 0x0000000ffffff000LL);
- } else {
- msrv = 0;
- }
- wrmsr(msr + 1, msrv);
- }
- wbinvd(); /* flush caches, TLBs */
- wrmsr(MSR_MTRRdefType, rdmsr(MSR_MTRRdefType) | 0x800); /* restore MTRR state */
- load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* enable caches CD = 0 and NW = 0 */
- load_cr4(cr4save); /* restore cr4 */
-}
-
-/*
- * Hunt for the fixed MTRR referencing (addr)
- */
-static struct mem_range_desc *
-i686_mtrrfixsearch(struct mem_range_softc *sc, u_int64_t addr)
-{
- struct mem_range_desc *mrd;
- int i;
-
- for (i = 0, mrd = sc->mr_desc; i < (MTRR_N64K + MTRR_N16K + MTRR_N4K); i++, mrd++)
- if ((addr >= mrd->mr_base) && (addr < (mrd->mr_base + mrd->mr_len)))
- return(mrd);
- return(NULL);
-}
-
-/*
- * Try to satisfy the given range request by manipulating the fixed MTRRs that
- * cover low memory.
- *
- * Note that we try to be generous here; we'll bloat the range out to the
- * next higher/lower boundary to avoid the consumer having to know too much
- * about the mechanisms here.
- *
- * XXX note that this will have to be updated when we start supporting "busy" ranges.
- */
-static int
-i686_mrsetlow(struct mem_range_softc *sc, struct mem_range_desc *mrd, int *arg)
-{
- struct mem_range_desc *first_md, *last_md, *curr_md;
-
- /* range check */
- if (((first_md = i686_mtrrfixsearch(sc, mrd->mr_base)) == NULL) ||
- ((last_md = i686_mtrrfixsearch(sc, mrd->mr_base + mrd->mr_len - 1)) == NULL))
- return(EINVAL);
-
- /* check we aren't doing something risky */
- if (!(mrd->mr_flags & MDF_FORCE))
- for (curr_md = first_md; curr_md <= last_md; curr_md++) {
- if ((curr_md->mr_flags & MDF_ATTRMASK) == MDF_UNKNOWN)
- return (EACCES);
- }
-
- /* set flags, clear set-by-firmware flag */
- for (curr_md = first_md; curr_md <= last_md; curr_md++) {
- curr_md->mr_flags = mrcopyflags(curr_md->mr_flags & ~MDF_FIRMWARE, mrd->mr_flags);
- bcopy(mrd->mr_owner, curr_md->mr_owner, sizeof(mrd->mr_owner));
- }
-
- return(0);
-}
-
-
-/*
- * Modify/add a variable MTRR to satisfy the request.
- *
- * XXX needs to be updated to properly support "busy" ranges.
- */
-static int
-i686_mrsetvariable(struct mem_range_softc *sc, struct mem_range_desc *mrd, int *arg)
-{
- struct mem_range_desc *curr_md, *free_md;
- int i;
-
- /*
- * Scan the currently active variable descriptors, look for
- * one we exactly match (straight takeover) and for possible
- * accidental overlaps.
- * Keep track of the first empty variable descriptor in case we
- * can't perform a takeover.
- */
- i = (sc->mr_cap & MR686_FIXMTRR) ? MTRR_N64K + MTRR_N16K + MTRR_N4K : 0;
- curr_md = sc->mr_desc + i;
- free_md = NULL;
- for (; i < sc->mr_ndesc; i++, curr_md++) {
- if (curr_md->mr_flags & MDF_ACTIVE) {
- /* exact match? */
- if ((curr_md->mr_base == mrd->mr_base) &&
- (curr_md->mr_len == mrd->mr_len)) {
- /* whoops, owned by someone */
- if (curr_md->mr_flags & MDF_BUSY)
- return(EBUSY);
- /* check we aren't doing something risky */
- if (!(mrd->mr_flags & MDF_FORCE) &&
- ((curr_md->mr_flags & MDF_ATTRMASK) == MDF_UNKNOWN))
- return (EACCES);
- /* Ok, just hijack this entry */
- free_md = curr_md;
- break;
- }
- /* non-exact overlap ? */
- if (mroverlap(curr_md, mrd)) {
- /* between conflicting region types? */
- if (i686_mtrrconflict(curr_md->mr_flags, mrd->mr_flags))
- return(EINVAL);
- }
- } else if (free_md == NULL) {
- free_md = curr_md;
- }
- }
- /* got somewhere to put it? */
- if (free_md == NULL)
- return(ENOSPC);
-
- /* Set up new descriptor */
- free_md->mr_base = mrd->mr_base;
- free_md->mr_len = mrd->mr_len;
- free_md->mr_flags = mrcopyflags(MDF_ACTIVE, mrd->mr_flags);
- bcopy(mrd->mr_owner, free_md->mr_owner, sizeof(mrd->mr_owner));
- return(0);
-}
-
-/*
- * Handle requests to set memory range attributes by manipulating MTRRs.
- *
- */
-static int
-i686_mrset(struct mem_range_softc *sc, struct mem_range_desc *mrd, int *arg)
-{
- struct mem_range_desc *targ;
- int error = 0;
-
- switch(*arg) {
- case MEMRANGE_SET_UPDATE:
- /* make sure that what's being asked for is even possible at all */
- if (!mrvalid(mrd->mr_base, mrd->mr_len) ||
- i686_mtrrtype(mrd->mr_flags) == -1)
- return(EINVAL);
-
-#define FIXTOP ((MTRR_N64K * 0x10000) + (MTRR_N16K * 0x4000) + (MTRR_N4K * 0x1000))
-
- /* are the "low memory" conditions applicable? */
- if ((sc->mr_cap & MR686_FIXMTRR) &&
- ((mrd->mr_base + mrd->mr_len) <= FIXTOP)) {
- if ((error = i686_mrsetlow(sc, mrd, arg)) != 0)
- return(error);
- } else {
- /* it's time to play with variable MTRRs */
- if ((error = i686_mrsetvariable(sc, mrd, arg)) != 0)
- return(error);
- }
- break;
-
- case MEMRANGE_SET_REMOVE:
- if ((targ = mem_range_match(sc, mrd)) == NULL)
- return(ENOENT);
- if (targ->mr_flags & MDF_FIXACTIVE)
- return(EPERM);
- if (targ->mr_flags & MDF_BUSY)
- return(EBUSY);
- targ->mr_flags &= ~MDF_ACTIVE;
- targ->mr_owner[0] = 0;
- break;
-
- default:
- return(EOPNOTSUPP);
- }
-
- /* update the hardware */
- i686_mrstore(sc);
- i686_mrfetch(sc); /* refetch to see where we're at */
- return(0);
-}
-
-/*
- * Work out how many ranges we support, initialise storage for them,
- * fetch the initial settings.
- */
-static void
-i686_mrinit(struct mem_range_softc *sc)
-{
- struct mem_range_desc *mrd;
- int nmdesc = 0;
- int i;
-
- mtrrcap = rdmsr(MSR_MTRRcap);
- mtrrdef = rdmsr(MSR_MTRRdefType);
-
- /* For now, bail out if MTRRs are not enabled */
- if (!(mtrrdef & 0x800)) {
- if (bootverbose)
- printf("CPU supports MTRRs but not enabled\n");
- return;
- }
- nmdesc = mtrrcap & 0xff;
- printf("Pentium Pro MTRR support enabled\n");
-
- /* If fixed MTRRs supported and enabled */
- if ((mtrrcap & 0x100) && (mtrrdef & 0x400)) {
- sc->mr_cap = MR686_FIXMTRR;
- nmdesc += MTRR_N64K + MTRR_N16K + MTRR_N4K;
- }
-
- sc->mr_desc =
- (struct mem_range_desc *)malloc(nmdesc * sizeof(struct mem_range_desc),
- M_MEMDESC, M_WAITOK | M_ZERO);
- sc->mr_ndesc = nmdesc;
-
- mrd = sc->mr_desc;
-
- /* Populate the fixed MTRR entries' base/length */
- if (sc->mr_cap & MR686_FIXMTRR) {
- for (i = 0; i < MTRR_N64K; i++, mrd++) {
- mrd->mr_base = i * 0x10000;
- mrd->mr_len = 0x10000;
- mrd->mr_flags = MDF_FIXBASE | MDF_FIXLEN | MDF_FIXACTIVE;
- }
- for (i = 0; i < MTRR_N16K; i++, mrd++) {
- mrd->mr_base = i * 0x4000 + 0x80000;
- mrd->mr_len = 0x4000;
- mrd->mr_flags = MDF_FIXBASE | MDF_FIXLEN | MDF_FIXACTIVE;
- }
- for (i = 0; i < MTRR_N4K; i++, mrd++) {
- mrd->mr_base = i * 0x1000 + 0xc0000;
- mrd->mr_len = 0x1000;
- mrd->mr_flags = MDF_FIXBASE | MDF_FIXLEN | MDF_FIXACTIVE;
- }
- }
-
- /*
- * Get current settings, anything set now is considered to have
- * been set by the firmware. (XXX has something already played here?)
- */
- i686_mrfetch(sc);
- mrd = sc->mr_desc;
- for (i = 0; i < sc->mr_ndesc; i++, mrd++) {
- if (mrd->mr_flags & MDF_ACTIVE)
- mrd->mr_flags |= MDF_FIRMWARE;
- }
-}
-
-/*
- * Initialise MTRRs on an AP after the BSP has run the init code.
- */
-static void
-i686_mrAPinit(struct mem_range_softc *sc)
-{
- i686_mrstoreone((void *)sc); /* set MTRRs to match BSP */
- wrmsr(MSR_MTRRdefType, mtrrdef); /* set MTRR behaviour to match BSP */
-}
-
-static void
-i686_mem_drvinit(void *unused)
-{
- /* Try for i686 MTRRs */
- if (!mtrrs_disabled && (cpu_feature & CPUID_MTRR) &&
- ((cpu_id & 0xf00) == 0x600 || (cpu_id & 0xf00) == 0xf00) &&
- ((strcmp(cpu_vendor, "GenuineIntel") == 0) ||
- (strcmp(cpu_vendor, "AuthenticAMD") == 0))) {
- mem_range_softc.mr_op = &i686_mrops;
- }
-}
-
-SYSINIT(i686memdev,SI_SUB_DRIVERS,SI_ORDER_FIRST,i686_mem_drvinit,NULL)
-
-
diff --git a/sys/amd64/amd64/apic_vector.S b/sys/amd64/amd64/apic_vector.S
deleted file mode 100644
index d91ff1ce4cee..000000000000
--- a/sys/amd64/amd64/apic_vector.S
+++ /dev/null
@@ -1,680 +0,0 @@
-/*
- * from: vector.s, 386BSD 0.1 unknown origin
- * $FreeBSD$
- */
-
-#include "opt_swtch.h"
-
-#include <machine/apic.h>
-#include <machine/smp.h>
-
-/* convert an absolute IRQ# into a bitmask */
-#define IRQ_BIT(irq_num) (1 << (irq_num))
-
-/* make an index into the IO APIC from the IRQ# */
-#define REDTBL_IDX(irq_num) (0x10 + ((irq_num) * 2))
-
-/*
- *
- */
-#define PUSH_FRAME \
- pushl $0 ; /* dummy error code */ \
- pushl $0 ; /* dummy trap type */ \
- pushal ; /* 8 ints */ \
- pushl %ds ; /* save data and extra segments ... */ \
- pushl %es ; \
- pushl %fs
-
-#define PUSH_DUMMY \
- pushfl ; /* eflags */ \
- pushl %cs ; /* cs */ \
- pushl 12(%esp) ; /* original caller eip */ \
- pushl $0 ; /* dummy error code */ \
- pushl $0 ; /* dummy trap type */ \
- subl $11*4,%esp ;
-
-#define POP_FRAME \
- popl %fs ; \
- popl %es ; \
- popl %ds ; \
- popal ; \
- addl $4+4,%esp
-
-#define POP_DUMMY \
- addl $16*4,%esp
-
-#define IOAPICADDR(irq_num) CNAME(int_to_apicintpin) + 16 * (irq_num) + 8
-#define REDIRIDX(irq_num) CNAME(int_to_apicintpin) + 16 * (irq_num) + 12
-
-#define MASK_IRQ(irq_num) \
- ICU_LOCK ; /* into critical reg */ \
- testl $IRQ_BIT(irq_num), apic_imen ; \
- jne 7f ; /* masked, don't mask */ \
- orl $IRQ_BIT(irq_num), apic_imen ; /* set the mask bit */ \
- movl IOAPICADDR(irq_num), %ecx ; /* ioapic addr */ \
- movl REDIRIDX(irq_num), %eax ; /* get the index */ \
- movl %eax, (%ecx) ; /* write the index */ \
- movl IOAPIC_WINDOW(%ecx), %eax ; /* current value */ \
- orl $IOART_INTMASK, %eax ; /* set the mask */ \
- movl %eax, IOAPIC_WINDOW(%ecx) ; /* new value */ \
-7: ; /* already masked */ \
- ICU_UNLOCK
-/*
- * Test to see whether we are handling an edge or level triggered INT.
- * Level-triggered INTs must still be masked as we don't clear the source,
- * and the EOI cycle would cause redundant INTs to occur.
- */
-#define MASK_LEVEL_IRQ(irq_num) \
- testl $IRQ_BIT(irq_num), apic_pin_trigger ; \
- jz 9f ; /* edge, don't mask */ \
- MASK_IRQ(irq_num) ; \
-9:
-
-
-#ifdef APIC_INTR_REORDER
-#define EOI_IRQ(irq_num) \
- movl apic_isrbit_location + 8 * (irq_num), %eax ; \
- movl (%eax), %eax ; \
- testl apic_isrbit_location + 4 + 8 * (irq_num), %eax ; \
- jz 9f ; /* not active */ \
- movl $0, lapic+LA_EOI ; \
-9:
-
-#else
-#define EOI_IRQ(irq_num) \
- testl $IRQ_BIT(irq_num), lapic+LA_ISR1; \
- jz 9f ; /* not active */ \
- movl $0, lapic+LA_EOI; \
-9:
-#endif
-
-
-/*
- * Test to see if the source is currently masked, clear if so.
- */
-#define UNMASK_IRQ(irq_num) \
- ICU_LOCK ; /* into critical reg */ \
- testl $IRQ_BIT(irq_num), apic_imen ; \
- je 7f ; /* bit clear, not masked */ \
- andl $~IRQ_BIT(irq_num), apic_imen ;/* clear mask bit */ \
- movl IOAPICADDR(irq_num), %ecx ; /* ioapic addr */ \
- movl REDIRIDX(irq_num), %eax ; /* get the index */ \
- movl %eax, (%ecx) ; /* write the index */ \
- movl IOAPIC_WINDOW(%ecx), %eax ; /* current value */ \
- andl $~IOART_INTMASK, %eax ; /* clear the mask */ \
- movl %eax, IOAPIC_WINDOW(%ecx) ; /* new value */ \
-7: ; /* already unmasked */ \
- ICU_UNLOCK
-
-/*
- * Test to see whether we are handling an edge or level triggered INT.
- * Level-triggered INTs have to be unmasked.
- */
-#define UNMASK_LEVEL_IRQ(irq_num) \
- testl $IRQ_BIT(irq_num), apic_pin_trigger ; \
- jz 9f ; /* edge, don't unmask */ \
- UNMASK_IRQ(irq_num) ; \
-9:
-
-/*
- * Macros for interrupt entry, call to handler, and exit.
- */
-
-#define FAST_INTR(irq_num, vec_name) \
- .text ; \
- SUPERALIGN_TEXT ; \
-IDTVEC(vec_name) ; \
- PUSH_FRAME ; \
- movl $KDSEL,%eax ; \
- mov %ax,%ds ; \
- mov %ax,%es ; \
- movl $KPSEL,%eax ; \
- mov %ax,%fs ; \
- FAKE_MCOUNT(13*4(%esp)) ; \
- movl PCPU(CURTHREAD),%ebx ; \
- cmpl $0,TD_CRITNEST(%ebx) ; \
- je 1f ; \
-; \
- movl $1,PCPU(INT_PENDING) ; \
- orl $IRQ_BIT(irq_num),PCPU(FPENDING) ; \
- MASK_LEVEL_IRQ(irq_num) ; \
- movl $0, lapic+LA_EOI ; \
- jmp 10f ; \
-1: ; \
- incl TD_CRITNEST(%ebx) ; \
- incl TD_INTR_NESTING_LEVEL(%ebx) ; \
- pushl intr_unit + (irq_num) * 4 ; \
- call *intr_handler + (irq_num) * 4 ; /* do the work ASAP */ \
- addl $4, %esp ; \
- movl $0, lapic+LA_EOI ; \
- lock ; \
- incl cnt+V_INTR ; /* book-keeping can wait */ \
- movl intr_countp + (irq_num) * 4, %eax ; \
- lock ; \
- incl (%eax) ; \
- decl TD_CRITNEST(%ebx) ; \
- cmpl $0,PCPU(INT_PENDING) ; \
- je 2f ; \
-; \
- call i386_unpend ; \
-2: ; \
- decl TD_INTR_NESTING_LEVEL(%ebx) ; \
-10: ; \
- MEXITCOUNT ; \
- jmp doreti
-
-/*
- * Restart a fast interrupt that was held up by a critical section.
- * This routine is called from unpend(). unpend() ensures we are
- * in a critical section and deals with the interrupt nesting level
- * for us. If we previously masked the irq, we have to unmask it.
- *
- * We have a choice. We can regenerate the irq using the 'int'
- * instruction or we can create a dummy frame and call the interrupt
- * handler directly. I've chosen to use the dummy-frame method.
- */
-#define FAST_UNPEND(irq_num, vec_name) \
- .text ; \
- SUPERALIGN_TEXT ; \
-IDTVEC(vec_name) ; \
-; \
- pushl %ebp ; \
- movl %esp, %ebp ; \
- PUSH_DUMMY ; \
- pushl intr_unit + (irq_num) * 4 ; \
- call *intr_handler + (irq_num) * 4 ; /* do the work ASAP */ \
- addl $4, %esp ; \
- lock ; \
- incl cnt+V_INTR ; /* book-keeping can wait */ \
- movl intr_countp + (irq_num) * 4, %eax ; \
- lock ; \
- incl (%eax) ; \
- UNMASK_LEVEL_IRQ(irq_num) ; \
- POP_DUMMY ; \
- popl %ebp ; \
- ret ; \
-
-
-/*
- * Slow, threaded interrupts.
- *
- * XXX Most of the parameters here are obsolete. Fix this when we're
- * done.
- * XXX we really shouldn't return via doreti if we just schedule the
- * interrupt handler and don't run anything. We could just do an
- * iret. FIXME.
- */
-#define INTR(irq_num, vec_name, maybe_extra_ipending) \
- .text ; \
- SUPERALIGN_TEXT ; \
-/* _XintrNN: entry point used by IDT/HWIs via _vec[]. */ \
-IDTVEC(vec_name) ; \
- PUSH_FRAME ; \
- movl $KDSEL, %eax ; /* reload with kernel's data segment */ \
- mov %ax, %ds ; \
- mov %ax, %es ; \
- movl $KPSEL, %eax ; \
- mov %ax, %fs ; \
-; \
- maybe_extra_ipending ; \
-; \
- MASK_LEVEL_IRQ(irq_num) ; \
- EOI_IRQ(irq_num) ; \
-; \
- movl PCPU(CURTHREAD),%ebx ; \
- cmpl $0,TD_CRITNEST(%ebx) ; \
- je 1f ; \
- movl $1,PCPU(INT_PENDING) ; \
- orl $IRQ_BIT(irq_num),PCPU(IPENDING) ; \
- jmp 10f ; \
-1: ; \
- incl TD_INTR_NESTING_LEVEL(%ebx) ; \
-; \
- FAKE_MCOUNT(13*4(%esp)) ; /* XXX avoid dbl cnt */ \
- cmpl $0,PCPU(INT_PENDING) ; \
- je 9f ; \
- call i386_unpend ; \
-9: ; \
- pushl $irq_num; /* pass the IRQ */ \
- call sched_ithd ; \
- addl $4, %esp ; /* discard the parameter */ \
-; \
- decl TD_INTR_NESTING_LEVEL(%ebx) ; \
-10: ; \
- MEXITCOUNT ; \
- jmp doreti
-
-/*
- * Handle "spurious INTerrupts".
- * Notes:
- * This is different than the "spurious INTerrupt" generated by an
- * 8259 PIC for missing INTs. See the APIC documentation for details.
- * This routine should NOT do an 'EOI' cycle.
- */
- .text
- SUPERALIGN_TEXT
- .globl Xspuriousint
-Xspuriousint:
-
- /* No EOI cycle used here */
-
- iret
-
-/*
- * Global address space TLB shootdown.
- */
- .text
- SUPERALIGN_TEXT
- .globl Xinvltlb
-Xinvltlb:
- pushl %eax
- pushl %ds
- movl $KDSEL, %eax /* Kernel data selector */
- mov %ax, %ds
-
-#ifdef COUNT_XINVLTLB_HITS
- pushl %fs
- movl $KPSEL, %eax /* Private space selector */
- mov %ax, %fs
- movl PCPU(CPUID), %eax
- popl %fs
- incl xhits_gbl(,%eax,4)
-#endif /* COUNT_XINVLTLB_HITS */
-
- movl %cr3, %eax /* invalidate the TLB */
- movl %eax, %cr3
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- lock
- incl smp_tlb_wait
-
- popl %ds
- popl %eax
- iret
-
-/*
- * Single page TLB shootdown
- */
- .text
- SUPERALIGN_TEXT
- .globl Xinvlpg
-Xinvlpg:
- pushl %eax
- pushl %ds
- movl $KDSEL, %eax /* Kernel data selector */
- mov %ax, %ds
-
-#ifdef COUNT_XINVLTLB_HITS
- pushl %fs
- movl $KPSEL, %eax /* Private space selector */
- mov %ax, %fs
- movl PCPU(CPUID), %eax
- popl %fs
- incl xhits_pg(,%eax,4)
-#endif /* COUNT_XINVLTLB_HITS */
-
- movl smp_tlb_addr1, %eax
- invlpg (%eax) /* invalidate single page */
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- lock
- incl smp_tlb_wait
-
- popl %ds
- popl %eax
- iret
-
-/*
- * Page range TLB shootdown.
- */
- .text
- SUPERALIGN_TEXT
- .globl Xinvlrng
-Xinvlrng:
- pushl %eax
- pushl %edx
- pushl %ds
- movl $KDSEL, %eax /* Kernel data selector */
- mov %ax, %ds
-
-#ifdef COUNT_XINVLTLB_HITS
- pushl %fs
- movl $KPSEL, %eax /* Private space selector */
- mov %ax, %fs
- movl PCPU(CPUID), %eax
- popl %fs
- incl xhits_rng(,%eax,4)
-#endif /* COUNT_XINVLTLB_HITS */
-
- movl smp_tlb_addr1, %edx
- movl smp_tlb_addr2, %eax
-1: invlpg (%edx) /* invalidate single page */
- addl $PAGE_SIZE, %edx
- cmpl %eax, %edx
- jb 1b
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- lock
- incl smp_tlb_wait
-
- popl %ds
- popl %edx
- popl %eax
- iret
-
-/*
- * Forward hardclock to another CPU. Pushes a clockframe and calls
- * forwarded_hardclock().
- */
- .text
- SUPERALIGN_TEXT
- .globl Xhardclock
-Xhardclock:
- PUSH_FRAME
- movl $KDSEL, %eax /* reload with kernel's data segment */
- mov %ax, %ds
- mov %ax, %es
- movl $KPSEL, %eax
- mov %ax, %fs
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- movl PCPU(CURTHREAD),%ebx
- cmpl $0,TD_CRITNEST(%ebx)
- je 1f
- movl $1,PCPU(INT_PENDING)
- orl $1,PCPU(SPENDING);
- jmp 10f
-1:
- incl TD_INTR_NESTING_LEVEL(%ebx)
- pushl $0 /* XXX convert trapframe to clockframe */
- call forwarded_hardclock
- addl $4, %esp /* XXX convert clockframe to trapframe */
- decl TD_INTR_NESTING_LEVEL(%ebx)
-10:
- MEXITCOUNT
- jmp doreti
-
-/*
- * Forward statclock to another CPU. Pushes a clockframe and calls
- * forwarded_statclock().
- */
- .text
- SUPERALIGN_TEXT
- .globl Xstatclock
-Xstatclock:
- PUSH_FRAME
- movl $KDSEL, %eax /* reload with kernel's data segment */
- mov %ax, %ds
- mov %ax, %es
- movl $KPSEL, %eax
- mov %ax, %fs
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- FAKE_MCOUNT(13*4(%esp))
-
- movl PCPU(CURTHREAD),%ebx
- cmpl $0,TD_CRITNEST(%ebx)
- je 1f
- movl $1,PCPU(INT_PENDING)
- orl $2,PCPU(SPENDING);
- jmp 10f
-1:
- incl TD_INTR_NESTING_LEVEL(%ebx)
- pushl $0 /* XXX convert trapframe to clockframe */
- call forwarded_statclock
- addl $4, %esp /* XXX convert clockframe to trapframe */
- decl TD_INTR_NESTING_LEVEL(%ebx)
-10:
- MEXITCOUNT
- jmp doreti
-
-/*
- * Executed by a CPU when it receives an Xcpuast IPI from another CPU,
- *
- * The other CPU has already executed aston() or need_resched() on our
- * current process, so we simply need to ack the interrupt and return
- * via doreti to run ast().
- */
-
- .text
- SUPERALIGN_TEXT
- .globl Xcpuast
-Xcpuast:
- PUSH_FRAME
- movl $KDSEL, %eax
- mov %ax, %ds /* use KERNEL data segment */
- mov %ax, %es
- movl $KPSEL, %eax
- mov %ax, %fs
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- FAKE_MCOUNT(13*4(%esp))
-
- MEXITCOUNT
- jmp doreti
-
-/*
- * Executed by a CPU when it receives an Xcpustop IPI from another CPU,
- *
- * - Signals its receipt.
- * - Waits for permission to restart.
- * - Signals its restart.
- */
- .text
- SUPERALIGN_TEXT
- .globl Xcpustop
-Xcpustop:
- pushl %ebp
- movl %esp, %ebp
- pushl %eax
- pushl %ecx
- pushl %edx
- pushl %ds /* save current data segment */
- pushl %fs
-
- movl $KDSEL, %eax
- mov %ax, %ds /* use KERNEL data segment */
- movl $KPSEL, %eax
- mov %ax, %fs
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- movl PCPU(CPUID), %eax
- imull $PCB_SIZE, %eax
- leal CNAME(stoppcbs)(%eax), %eax
- pushl %eax
- call CNAME(savectx) /* Save process context */
- addl $4, %esp
-
- movl PCPU(CPUID), %eax
-
- lock
- btsl %eax, CNAME(stopped_cpus) /* stopped_cpus |= (1<<id) */
-1:
- btl %eax, CNAME(started_cpus) /* while (!(started_cpus & (1<<id))) */
- jnc 1b
-
- lock
- btrl %eax, CNAME(started_cpus) /* started_cpus &= ~(1<<id) */
- lock
- btrl %eax, CNAME(stopped_cpus) /* stopped_cpus &= ~(1<<id) */
-
- test %eax, %eax
- jnz 2f
-
- movl CNAME(cpustop_restartfunc), %eax
- test %eax, %eax
- jz 2f
- movl $0, CNAME(cpustop_restartfunc) /* One-shot */
-
- call *%eax
-2:
- popl %fs
- popl %ds /* restore previous data segment */
- popl %edx
- popl %ecx
- popl %eax
- movl %ebp, %esp
- popl %ebp
- iret
-
-
-MCOUNT_LABEL(bintr)
- FAST_INTR(0,fastintr0)
- FAST_INTR(1,fastintr1)
- FAST_INTR(2,fastintr2)
- FAST_INTR(3,fastintr3)
- FAST_INTR(4,fastintr4)
- FAST_INTR(5,fastintr5)
- FAST_INTR(6,fastintr6)
- FAST_INTR(7,fastintr7)
- FAST_INTR(8,fastintr8)
- FAST_INTR(9,fastintr9)
- FAST_INTR(10,fastintr10)
- FAST_INTR(11,fastintr11)
- FAST_INTR(12,fastintr12)
- FAST_INTR(13,fastintr13)
- FAST_INTR(14,fastintr14)
- FAST_INTR(15,fastintr15)
- FAST_INTR(16,fastintr16)
- FAST_INTR(17,fastintr17)
- FAST_INTR(18,fastintr18)
- FAST_INTR(19,fastintr19)
- FAST_INTR(20,fastintr20)
- FAST_INTR(21,fastintr21)
- FAST_INTR(22,fastintr22)
- FAST_INTR(23,fastintr23)
- FAST_INTR(24,fastintr24)
- FAST_INTR(25,fastintr25)
- FAST_INTR(26,fastintr26)
- FAST_INTR(27,fastintr27)
- FAST_INTR(28,fastintr28)
- FAST_INTR(29,fastintr29)
- FAST_INTR(30,fastintr30)
- FAST_INTR(31,fastintr31)
-#define CLKINTR_PENDING movl $1,CNAME(clkintr_pending)
-/* Threaded interrupts */
- INTR(0,intr0, CLKINTR_PENDING)
- INTR(1,intr1,)
- INTR(2,intr2,)
- INTR(3,intr3,)
- INTR(4,intr4,)
- INTR(5,intr5,)
- INTR(6,intr6,)
- INTR(7,intr7,)
- INTR(8,intr8,)
- INTR(9,intr9,)
- INTR(10,intr10,)
- INTR(11,intr11,)
- INTR(12,intr12,)
- INTR(13,intr13,)
- INTR(14,intr14,)
- INTR(15,intr15,)
- INTR(16,intr16,)
- INTR(17,intr17,)
- INTR(18,intr18,)
- INTR(19,intr19,)
- INTR(20,intr20,)
- INTR(21,intr21,)
- INTR(22,intr22,)
- INTR(23,intr23,)
- INTR(24,intr24,)
- INTR(25,intr25,)
- INTR(26,intr26,)
- INTR(27,intr27,)
- INTR(28,intr28,)
- INTR(29,intr29,)
- INTR(30,intr30,)
- INTR(31,intr31,)
-
- FAST_UNPEND(0,fastunpend0)
- FAST_UNPEND(1,fastunpend1)
- FAST_UNPEND(2,fastunpend2)
- FAST_UNPEND(3,fastunpend3)
- FAST_UNPEND(4,fastunpend4)
- FAST_UNPEND(5,fastunpend5)
- FAST_UNPEND(6,fastunpend6)
- FAST_UNPEND(7,fastunpend7)
- FAST_UNPEND(8,fastunpend8)
- FAST_UNPEND(9,fastunpend9)
- FAST_UNPEND(10,fastunpend10)
- FAST_UNPEND(11,fastunpend11)
- FAST_UNPEND(12,fastunpend12)
- FAST_UNPEND(13,fastunpend13)
- FAST_UNPEND(14,fastunpend14)
- FAST_UNPEND(15,fastunpend15)
- FAST_UNPEND(16,fastunpend16)
- FAST_UNPEND(17,fastunpend17)
- FAST_UNPEND(18,fastunpend18)
- FAST_UNPEND(19,fastunpend19)
- FAST_UNPEND(20,fastunpend20)
- FAST_UNPEND(21,fastunpend21)
- FAST_UNPEND(22,fastunpend22)
- FAST_UNPEND(23,fastunpend23)
- FAST_UNPEND(24,fastunpend24)
- FAST_UNPEND(25,fastunpend25)
- FAST_UNPEND(26,fastunpend26)
- FAST_UNPEND(27,fastunpend27)
- FAST_UNPEND(28,fastunpend28)
- FAST_UNPEND(29,fastunpend29)
- FAST_UNPEND(30,fastunpend30)
- FAST_UNPEND(31,fastunpend31)
-MCOUNT_LABEL(eintr)
-
-/*
- * Executed by a CPU when it receives a RENDEZVOUS IPI from another CPU.
- *
- * - Calls the generic rendezvous action function.
- */
- .text
- SUPERALIGN_TEXT
- .globl Xrendezvous
-Xrendezvous:
- PUSH_FRAME
- movl $KDSEL, %eax
- mov %ax, %ds /* use KERNEL data segment */
- mov %ax, %es
- movl $KPSEL, %eax
- mov %ax, %fs
-
- call smp_rendezvous_action
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
- POP_FRAME
- iret
-
-#ifdef LAZY_SWITCH
-/*
- * Clean up when we lose out on the lazy context switch optimization.
- * ie: when we are about to release a PTD but a cpu is still borrowing it.
- */
- SUPERALIGN_TEXT
- .globl Xlazypmap
-Xlazypmap:
- PUSH_FRAME
- movl $KDSEL, %eax
- mov %ax, %ds /* use KERNEL data segment */
- mov %ax, %es
- movl $KPSEL, %eax
- mov %ax, %fs
-
- call pmap_lazyfix_action
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
- POP_FRAME
- iret
-#endif
-
- .data
-
- .globl apic_pin_trigger
-apic_pin_trigger:
- .long 0
-
- .text
diff --git a/sys/amd64/amd64/bios.c b/sys/amd64/amd64/bios.c
deleted file mode 100644
index 93574385f5ef..000000000000
--- a/sys/amd64/amd64/bios.c
+++ /dev/null
@@ -1,680 +0,0 @@
-/*-
- * Copyright (c) 1997 Michael Smith
- * Copyright (c) 1998 Jonathan Lemon
- * 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$
- */
-
-/*
- * Code for dealing with the BIOS in x86 PC systems.
- */
-
-#include "opt_isa.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <sys/bus.h>
-#include <sys/pcpu.h>
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <machine/md_var.h>
-#include <machine/segments.h>
-#include <machine/stdarg.h>
-#include <machine/vmparam.h>
-#include <machine/pc/bios.h>
-#ifdef DEV_ISA
-#include <isa/isavar.h>
-#include <isa/pnpreg.h>
-#include <isa/pnpvar.h>
-#endif
-
-#define BIOS_START 0xe0000
-#define BIOS_SIZE 0x20000
-
-/* exported lookup results */
-struct bios32_SDentry PCIbios;
-struct PnPBIOS_table *PnPBIOStable;
-
-static u_int bios32_SDCI;
-
-/* start fairly early */
-static void bios32_init(void *junk);
-SYSINIT(bios32, SI_SUB_CPU, SI_ORDER_ANY, bios32_init, NULL);
-
-/*
- * bios32_init
- *
- * Locate various bios32 entities.
- */
-static void
-bios32_init(void *junk)
-{
- u_long sigaddr;
- struct bios32_SDheader *sdh;
- struct PnPBIOS_table *pt;
- u_int8_t ck, *cv;
- int i;
- char *p;
-
- /*
- * BIOS32 Service Directory, PCI BIOS
- */
-
- /* look for the signature */
- if ((sigaddr = bios_sigsearch(0, "_32_", 4, 16, 0)) != 0) {
-
- /* get a virtual pointer to the structure */
- sdh = (struct bios32_SDheader *)(uintptr_t)BIOS_PADDRTOVADDR(sigaddr);
- for (cv = (u_int8_t *)sdh, ck = 0, i = 0; i < (sdh->len * 16); i++) {
- ck += cv[i];
- }
- /* If checksum is OK, enable use of the entrypoint */
- if ((ck == 0) && (BIOS_START <= sdh->entry ) &&
- (sdh->entry < (BIOS_START + BIOS_SIZE))) {
- bios32_SDCI = BIOS_PADDRTOVADDR(sdh->entry);
- if (bootverbose) {
- printf("bios32: Found BIOS32 Service Directory header at %p\n", sdh);
- printf("bios32: Entry = 0x%x (%x) Rev = %d Len = %d\n",
- sdh->entry, bios32_SDCI, sdh->revision, sdh->len);
- }
-
- /* Allow user override of PCI BIOS search */
- if (((p = getenv("machdep.bios.pci")) == NULL) || strcmp(p, "disable")) {
-
- /* See if there's a PCI BIOS entrypoint here */
- PCIbios.ident.id = 0x49435024; /* PCI systems should have this */
- if (!bios32_SDlookup(&PCIbios) && bootverbose)
- printf("pcibios: PCI BIOS entry at 0x%x+0x%x\n", PCIbios.base, PCIbios.entry);
- }
- if (p != NULL)
- freeenv(p);
- } else {
- printf("bios32: Bad BIOS32 Service Directory\n");
- }
- }
-
- /*
- * PnP BIOS
- *
- * Allow user override of PnP BIOS search
- */
- if ((((p = getenv("machdep.bios.pnp")) == NULL) || strcmp(p, "disable")) &&
- ((sigaddr = bios_sigsearch(0, "$PnP", 4, 16, 0)) != 0)) {
-
- /* get a virtual pointer to the structure */
- pt = (struct PnPBIOS_table *)(uintptr_t)BIOS_PADDRTOVADDR(sigaddr);
- for (cv = (u_int8_t *)pt, ck = 0, i = 0; i < pt->len; i++) {
- ck += cv[i];
- }
- /* If checksum is OK, enable use of the entrypoint */
- if (ck == 0) {
- PnPBIOStable = pt;
- if (bootverbose) {
- printf("pnpbios: Found PnP BIOS data at %p\n", pt);
- printf("pnpbios: Entry = %x:%x Rev = %d.%d\n",
- pt->pmentrybase, pt->pmentryoffset, pt->version >> 4, pt->version & 0xf);
- if ((pt->control & 0x3) == 0x01)
- printf("pnpbios: Event flag at %x\n", pt->evflagaddr);
- if (pt->oemdevid != 0)
- printf("pnpbios: OEM ID %x\n", pt->oemdevid);
-
- }
- } else {
- printf("pnpbios: Bad PnP BIOS data checksum\n");
- }
- }
- if (p != NULL)
- freeenv(p);
- if (bootverbose) {
- /* look for other know signatures */
- printf("Other BIOS signatures found:\n");
- }
-}
-
-/*
- * bios32_SDlookup
- *
- * Query the BIOS32 Service Directory for the service named in (ent),
- * returns nonzero if the lookup fails. The caller must fill in
- * (ent->ident), the remainder are populated on a successful lookup.
- */
-int
-bios32_SDlookup(struct bios32_SDentry *ent)
-{
- struct bios_regs args;
-
- if (bios32_SDCI == 0)
- return (1);
-
- args.eax = ent->ident.id; /* set up arguments */
- args.ebx = args.ecx = args.edx = 0;
- bios32(&args, bios32_SDCI, GSEL(GCODE_SEL, SEL_KPL));
- if ((args.eax & 0xff) == 0) { /* success? */
- ent->base = args.ebx;
- ent->len = args.ecx;
- ent->entry = args.edx;
- ent->ventry = BIOS_PADDRTOVADDR(ent->base + ent->entry);
- return (0); /* all OK */
- }
- return (1); /* failed */
-}
-
-
-/*
- * bios_sigsearch
- *
- * Search some or all of the BIOS region for a signature string.
- *
- * (start) Optional offset returned from this function
- * (for searching for multiple matches), or NULL
- * to start the search from the base of the BIOS.
- * Note that this will be a _physical_ address in
- * the range 0xe0000 - 0xfffff.
- * (sig) is a pointer to the byte(s) of the signature.
- * (siglen) number of bytes in the signature.
- * (paralen) signature paragraph (alignment) size.
- * (sigofs) offset of the signature within the paragraph.
- *
- * Returns the _physical_ address of the found signature, 0 if the
- * signature was not found.
- */
-
-u_int32_t
-bios_sigsearch(u_int32_t start, u_char *sig, int siglen, int paralen, int sigofs)
-{
- u_char *sp, *end;
-
- /* compute the starting address */
- if ((start >= BIOS_START) && (start <= (BIOS_START + BIOS_SIZE))) {
- sp = (char *)BIOS_PADDRTOVADDR(start);
- } else if (start == 0) {
- sp = (char *)BIOS_PADDRTOVADDR(BIOS_START);
- } else {
- return 0; /* bogus start address */
- }
-
- /* compute the end address */
- end = (u_char *)BIOS_PADDRTOVADDR(BIOS_START + BIOS_SIZE);
-
- /* loop searching */
- while ((sp + sigofs + siglen) < end) {
-
- /* compare here */
- if (!bcmp(sp + sigofs, sig, siglen)) {
- /* convert back to physical address */
- return((u_int32_t)BIOS_VADDRTOPADDR(sp));
- }
- sp += paralen;
- }
- return(0);
-}
-
-/*
- * do not staticize, used by bioscall.s
- */
-union {
- struct {
- u_short offset;
- u_short segment;
- } vec16;
- struct {
- u_int offset;
- u_short segment;
- } vec32;
-} bioscall_vector; /* bios jump vector */
-
-void
-set_bios_selectors(struct bios_segments *seg, int flags)
-{
- struct soft_segment_descriptor ssd = {
- 0, /* segment base address (overwritten) */
- 0, /* length (overwritten) */
- SDT_MEMERA, /* segment type (overwritten) */
- 0, /* priority level */
- 1, /* descriptor present */
- 0, 0,
- 1, /* descriptor size (overwritten) */
- 0 /* granularity == byte units */
- };
- union descriptor *p_gdt;
-
-#ifdef SMP
- p_gdt = &gdt[PCPU_GET(cpuid) * NGDT];
-#else
- p_gdt = gdt;
-#endif
-
- ssd.ssd_base = seg->code32.base;
- ssd.ssd_limit = seg->code32.limit;
- ssdtosd(&ssd, &p_gdt[GBIOSCODE32_SEL].sd);
-
- ssd.ssd_def32 = 0;
- if (flags & BIOSCODE_FLAG) {
- ssd.ssd_base = seg->code16.base;
- ssd.ssd_limit = seg->code16.limit;
- ssdtosd(&ssd, &p_gdt[GBIOSCODE16_SEL].sd);
- }
-
- ssd.ssd_type = SDT_MEMRWA;
- if (flags & BIOSDATA_FLAG) {
- ssd.ssd_base = seg->data.base;
- ssd.ssd_limit = seg->data.limit;
- ssdtosd(&ssd, &p_gdt[GBIOSDATA_SEL].sd);
- }
-
- if (flags & BIOSUTIL_FLAG) {
- ssd.ssd_base = seg->util.base;
- ssd.ssd_limit = seg->util.limit;
- ssdtosd(&ssd, &p_gdt[GBIOSUTIL_SEL].sd);
- }
-
- if (flags & BIOSARGS_FLAG) {
- ssd.ssd_base = seg->args.base;
- ssd.ssd_limit = seg->args.limit;
- ssdtosd(&ssd, &p_gdt[GBIOSARGS_SEL].sd);
- }
-}
-
-extern int vm86pa;
-extern void bios16_jmp(void);
-
-/*
- * this routine is really greedy with selectors, and uses 5:
- *
- * 32-bit code selector: to return to kernel
- * 16-bit code selector: for running code
- * data selector: for 16-bit data
- * util selector: extra utility selector
- * args selector: to handle pointers
- *
- * the util selector is set from the util16 entry in bios16_args, if a
- * "U" specifier is seen.
- *
- * See <machine/pc/bios.h> for description of format specifiers
- */
-int
-bios16(struct bios_args *args, char *fmt, ...)
-{
- char *p, *stack, *stack_top;
- va_list ap;
- int flags = BIOSCODE_FLAG | BIOSDATA_FLAG;
- u_int i, arg_start, arg_end;
- pt_entry_t *pte;
- pd_entry_t *ptd;
-
- arg_start = 0xffffffff;
- arg_end = 0;
-
- /*
- * Some BIOS entrypoints attempt to copy the largest-case
- * argument frame (in order to generalise handling for
- * different entry types). If our argument frame is
- * smaller than this, the BIOS will reach off the top of
- * our constructed stack segment. Pad the top of the stack
- * with some garbage to avoid this.
- */
- stack = (caddr_t)PAGE_SIZE - 32;
-
- va_start(ap, fmt);
- for (p = fmt; p && *p; p++) {
- switch (*p) {
- case 'p': /* 32-bit pointer */
- i = va_arg(ap, u_int);
- arg_start = min(arg_start, i);
- arg_end = max(arg_end, i);
- flags |= BIOSARGS_FLAG;
- stack -= 4;
- break;
-
- case 'i': /* 32-bit integer */
- i = va_arg(ap, u_int);
- stack -= 4;
- break;
-
- case 'U': /* 16-bit selector */
- flags |= BIOSUTIL_FLAG;
- /* FALLTHROUGH */
- case 'D': /* 16-bit selector */
- case 'C': /* 16-bit selector */
- stack -= 2;
- break;
-
- case 's': /* 16-bit integer passed as an int */
- i = va_arg(ap, int);
- stack -= 2;
- break;
-
- default:
- return (EINVAL);
- }
- }
-
- if (flags & BIOSARGS_FLAG) {
- if (arg_end - arg_start > ctob(16))
- return (EACCES);
- args->seg.args.base = arg_start;
- args->seg.args.limit = 0xffff;
- }
-
- args->seg.code32.base = (u_int)&bios16_jmp & PG_FRAME;
- args->seg.code32.limit = 0xffff;
-
- ptd = (pd_entry_t *)rcr3();
-#ifdef PAE
- if (ptd == IdlePDPT) {
-#else
- if (ptd == IdlePTD) {
-#endif
- /*
- * no page table, so create one and install it.
- */
- pte = (pt_entry_t *)malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
- ptd = (pd_entry_t *)((u_int)IdlePTD + KERNBASE);
- *ptd = vtophys(pte) | PG_RW | PG_V;
- } else {
- /*
- * this is a user-level page table
- */
- pte = PTmap;
- }
- /*
- * install pointer to page 0. we don't need to flush the tlb,
- * since there should not be a previous mapping for page 0.
- */
- *pte = (vm86pa - PAGE_SIZE) | PG_RW | PG_V;
-
- stack_top = stack;
- va_start(ap, fmt);
- for (p = fmt; p && *p; p++) {
- switch (*p) {
- case 'p': /* 32-bit pointer */
- i = va_arg(ap, u_int);
- *(u_int *)stack = (i - arg_start) |
- (GSEL(GBIOSARGS_SEL, SEL_KPL) << 16);
- stack += 4;
- break;
-
- case 'i': /* 32-bit integer */
- i = va_arg(ap, u_int);
- *(u_int *)stack = i;
- stack += 4;
- break;
-
- case 'U': /* 16-bit selector */
- *(u_short *)stack = GSEL(GBIOSUTIL_SEL, SEL_KPL);
- stack += 2;
- break;
-
- case 'D': /* 16-bit selector */
- *(u_short *)stack = GSEL(GBIOSDATA_SEL, SEL_KPL);
- stack += 2;
- break;
-
- case 'C': /* 16-bit selector */
- *(u_short *)stack = GSEL(GBIOSCODE16_SEL, SEL_KPL);
- stack += 2;
- break;
-
- case 's': /* 16-bit integer passed as an int */
- i = va_arg(ap, int);
- *(u_short *)stack = i;
- stack += 2;
- break;
-
- default:
- return (EINVAL);
- }
- }
-
- set_bios_selectors(&args->seg, flags);
- bioscall_vector.vec16.offset = (u_short)args->entry;
- bioscall_vector.vec16.segment = GSEL(GBIOSCODE16_SEL, SEL_KPL);
-
- i = bios16_call(&args->r, stack_top);
-
- if (pte == PTmap) {
- *pte = 0; /* remove entry */
- } else {
- *ptd = 0; /* remove page table */
- free(pte, M_TEMP); /* ... and free it */
- }
-
- /*
- * XXX only needs to be invlpg(0) but that doesn't work on the 386
- */
- pmap_invalidate_all(kernel_pmap);
-
- return (i);
-}
-
-#ifdef DEV_ISA
-/*
- * PnP BIOS interface; enumerate devices only known to the system
- * BIOS and save information about them for later use.
- */
-
-struct pnp_sysdev
-{
- u_int16_t size;
- u_int8_t handle;
- u_int32_t devid;
- u_int8_t type[3];
- u_int16_t attrib;
-#define PNPATTR_NODISABLE (1<<0) /* can't be disabled */
-#define PNPATTR_NOCONFIG (1<<1) /* can't be configured */
-#define PNPATTR_OUTPUT (1<<2) /* can be primary output */
-#define PNPATTR_INPUT (1<<3) /* can be primary input */
-#define PNPATTR_BOOTABLE (1<<4) /* can be booted from */
-#define PNPATTR_DOCK (1<<5) /* is a docking station */
-#define PNPATTR_REMOVEABLE (1<<6) /* device is removeable */
-#define PNPATTR_CONFIG_STATIC (0)
-#define PNPATTR_CONFIG_DYNAMIC (1)
-#define PNPATTR_CONFIG_DYNONLY (3)
-#define PNPATTR_CONFIG(a) (((a) >> 7) & 0x3)
- /* device-specific data comes here */
- u_int8_t devdata[0];
-} __packed;
-
-/* We have to cluster arguments within a 64k range for the bios16 call */
-struct pnp_sysdevargs
-{
- u_int16_t next;
- struct pnp_sysdev node;
-};
-
-/*
- * This function is called after the bus has assigned resource
- * locations for a logical device.
- */
-static void
-pnpbios_set_config(void *arg, struct isa_config *config, int enable)
-{
-}
-
-/*
- * Quiz the PnP BIOS, build a list of PNP IDs and resource data.
- */
-static void
-pnpbios_identify(driver_t *driver, device_t parent)
-{
- struct PnPBIOS_table *pt = PnPBIOStable;
- struct bios_args args;
- struct pnp_sysdev *pd;
- struct pnp_sysdevargs *pda;
- u_int16_t ndevs, bigdev;
- int error, currdev;
- u_int8_t *devnodebuf, tag;
- u_int32_t *devid, *compid;
- int idx, left;
- device_t dev;
-
- /* no PnP BIOS information */
- if (pt == NULL)
- return;
-
- /* ACPI already active */
- if (devclass_get_softc(devclass_find("ACPI"), 0) != NULL)
- return;
-
- /* get count of PnP devices */
- bzero(&args, sizeof(args));
- args.seg.code16.base = BIOS_PADDRTOVADDR(pt->pmentrybase);
- args.seg.code16.limit = 0xffff; /* XXX ? */
- args.seg.data.base = BIOS_PADDRTOVADDR(pt->pmdataseg);
- args.seg.data.limit = 0xffff;
- args.entry = pt->pmentryoffset;
-
- if ((error = bios16(&args, PNP_COUNT_DEVNODES, &ndevs, &bigdev)) || (args.r.eax & 0xff))
- printf("pnpbios: error %d/%x getting device count/size limit\n", error, args.r.eax);
- ndevs &= 0xff; /* clear high byte garbage */
- if (bootverbose)
- printf("pnpbios: %d devices, largest %d bytes\n", ndevs, bigdev);
-
- devnodebuf = malloc(bigdev + (sizeof(struct pnp_sysdevargs) - sizeof(struct pnp_sysdev)),
- M_DEVBUF, M_NOWAIT);
- pda = (struct pnp_sysdevargs *)devnodebuf;
- pd = &pda->node;
-
- for (currdev = 0, left = ndevs; (currdev != 0xff) && (left > 0); left--) {
-
- bzero(pd, bigdev);
- pda->next = currdev;
- /* get current configuration */
- if ((error = bios16(&args, PNP_GET_DEVNODE, &pda->next, &pda->node, 1))) {
- printf("pnpbios: error %d making BIOS16 call\n", error);
- break;
- }
- if ((error = (args.r.eax & 0xff))) {
- if (bootverbose)
- printf("pnpbios: %s 0x%x fetching node %d\n", error & 0x80 ? "error" : "warning", error, currdev);
- if (error & 0x80)
- break;
- }
- currdev = pda->next;
- if (pd->size < sizeof(struct pnp_sysdev)) {
- printf("pnpbios: bogus system node data, aborting scan\n");
- break;
- }
-
- /*
- * If we are in APIC_IO mode, we should ignore the ISA PIC if it
- * shows up. Likewise, in !APIC_IO mode, we should ignore the
- * APIC (less important).
- * This is significant because the ISA PIC will claim IRQ 2 (which
- * it uses for chaining), while in APIC mode this is a valid IRQ
- * available for general use.
- */
-#ifdef APIC_IO
- if (!strcmp(pnp_eisaformat(pd->devid), "PNP0000")) /* ISA PIC */
- continue;
-#else
- if (!strcmp(pnp_eisaformat(pd->devid), "PNP0003")) /* APIC */
- continue;
-#endif
-
- /* Add the device and parse its resources */
- dev = BUS_ADD_CHILD(parent, ISA_ORDER_PNP, NULL, -1);
- isa_set_vendorid(dev, pd->devid);
- isa_set_logicalid(dev, pd->devid);
- /*
- * It appears that some PnP BIOS doesn't allow us to re-enable
- * the embedded system device once it is disabled. We shall
- * mark all system device nodes as "cannot be disabled", regardless
- * of actual settings in the device attribute byte.
- * XXX
- isa_set_configattr(dev,
- ((pd->attrib & PNPATTR_NODISABLE) ? 0 : ISACFGATTR_CANDISABLE) |
- ((!(pd->attrib & PNPATTR_NOCONFIG) &&
- PNPATTR_CONFIG(pd->attrib) != PNPATTR_CONFIG_STATIC)
- ? ISACFGATTR_DYNAMIC : 0));
- */
- isa_set_configattr(dev,
- (!(pd->attrib & PNPATTR_NOCONFIG) &&
- PNPATTR_CONFIG(pd->attrib) != PNPATTR_CONFIG_STATIC)
- ? ISACFGATTR_DYNAMIC : 0);
- ISA_SET_CONFIG_CALLBACK(parent, dev, pnpbios_set_config, 0);
- pnp_parse_resources(dev, &pd->devdata[0],
- pd->size - sizeof(struct pnp_sysdev), 0);
- if (!device_get_desc(dev))
- device_set_desc_copy(dev, pnp_eisaformat(pd->devid));
-
- /* Find device IDs */
- devid = &pd->devid;
- compid = NULL;
-
- /* look for a compatible device ID too */
- left = pd->size - sizeof(struct pnp_sysdev);
- idx = 0;
- while (idx < left) {
- tag = pd->devdata[idx++];
- if (PNP_RES_TYPE(tag) == 0) {
- /* Small resource */
- switch (PNP_SRES_NUM(tag)) {
- case PNP_TAG_COMPAT_DEVICE:
- compid = (u_int32_t *)(pd->devdata + idx);
- if (bootverbose)
- printf("pnpbios: node %d compat ID 0x%08x\n", pd->handle, *compid);
- /* FALLTHROUGH */
- case PNP_TAG_END:
- idx = left;
- break;
- default:
- idx += PNP_SRES_LEN(tag);
- break;
- }
- } else
- /* Large resource, skip it */
- idx += *(u_int16_t *)(pd->devdata + idx) + 2;
- }
- if (bootverbose) {
- printf("pnpbios: handle %d device ID %s (%08x)",
- pd->handle, pnp_eisaformat(*devid), *devid);
- if (compid != NULL)
- printf(" compat ID %s (%08x)",
- pnp_eisaformat(*compid), *compid);
- printf("\n");
- }
- }
-}
-
-static device_method_t pnpbios_methods[] = {
- /* Device interface */
- DEVMETHOD(device_identify, pnpbios_identify),
-
- { 0, 0 }
-};
-
-static driver_t pnpbios_driver = {
- "pnpbios",
- pnpbios_methods,
- 1, /* no softc */
-};
-
-static devclass_t pnpbios_devclass;
-
-DRIVER_MODULE(pnpbios, isa, pnpbios_driver, pnpbios_devclass, 0, 0);
-#endif /* DEV_ISA */
diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c
deleted file mode 100644
index 2116701c696a..000000000000
--- a/sys/amd64/amd64/fpu.c
+++ /dev/null
@@ -1,724 +0,0 @@
-/*-
- * Copyright (c) 1990 William Jolitz.
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)npx.c 7.2 (Berkeley) 5/12/91
- * $FreeBSD$
- */
-
-#include "opt_debug_npx.h"
-#include "opt_isa.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/module.h>
-#include <sys/mutex.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/sysctl.h>
-#include <machine/bus.h>
-#include <sys/rman.h>
-#ifdef NPX_DEBUG
-#include <sys/syslog.h>
-#endif
-#include <sys/signalvar.h>
-#include <sys/user.h>
-
-#include <machine/cputypes.h>
-#include <machine/frame.h>
-#include <machine/md_var.h>
-#include <machine/pcb.h>
-#include <machine/psl.h>
-#include <machine/resource.h>
-#include <machine/specialreg.h>
-#include <machine/segments.h>
-#include <machine/ucontext.h>
-
-#include <amd64/isa/intr_machdep.h>
-#ifdef DEV_ISA
-#include <isa/isavar.h>
-#endif
-
-/*
- * 387 and 287 Numeric Coprocessor Extension (NPX) Driver.
- */
-
-#if defined(__GNUC__) && !defined(lint)
-
-#define fldcw(addr) __asm("fldcw %0" : : "m" (*(addr)))
-#define fnclex() __asm("fnclex")
-#define fninit() __asm("fninit")
-#define fnstcw(addr) __asm __volatile("fnstcw %0" : "=m" (*(addr)))
-#define fnstsw(addr) __asm __volatile("fnstsw %0" : "=m" (*(addr)))
-#define fxrstor(addr) __asm("fxrstor %0" : : "m" (*(addr)))
-#define fxsave(addr) __asm __volatile("fxsave %0" : "=m" (*(addr)))
-#define start_emulating() __asm("smsw %%ax; orb %0,%%al; lmsw %%ax" \
- : : "n" (CR0_TS) : "ax")
-#define stop_emulating() __asm("clts")
-
-#else /* not __GNUC__ */
-
-void fldcw(caddr_t addr);
-void fnclex(void);
-void fninit(void);
-void fnstcw(caddr_t addr);
-void fnstsw(caddr_t addr);
-void fxsave(caddr_t addr);
-void fxrstor(caddr_t addr);
-void start_emulating(void);
-void stop_emulating(void);
-
-#endif /* __GNUC__ */
-
-#define GET_FPU_CW(thread) ((thread)->td_pcb->pcb_save.sv_env.en_cw)
-#define GET_FPU_SW(thread) ((thread)->td_pcb->pcb_save.sv_env.en_sw)
-
-typedef u_char bool_t;
-
-static int npx_attach(device_t dev);
-static void npx_identify(driver_t *driver, device_t parent);
-static int npx_probe(device_t dev);
-
-int hw_float = 1;
-SYSCTL_INT(_hw,HW_FLOATINGPT, floatingpoint,
- CTLFLAG_RD, &hw_float, 0,
- "Floatingpoint instructions executed in hardware");
-
-static struct savefpu npx_cleanstate;
-static bool_t npx_cleanstate_ready;
-
-/*
- * Identify routine. Create a connection point on our parent for probing.
- */
-static void
-npx_identify(driver, parent)
- driver_t *driver;
- device_t parent;
-{
- device_t child;
-
- child = BUS_ADD_CHILD(parent, 0, "npx", 0);
- if (child == NULL)
- panic("npx_identify");
-}
-
-/*
- * Probe routine. Initialize cr0 to give correct behaviour for [f]wait
- * whether the device exists or not (XXX should be elsewhere).
- * Modify device struct if npx doesn't need to use interrupts.
- * Return 0 if device exists.
- */
-static int
-npx_probe(dev)
- device_t dev;
-{
-
- /*
- * Partially reset the coprocessor, if any. Some BIOS's don't reset
- * it after a warm boot.
- */
- outb(0xf1, 0); /* full reset on some systems, NOP on others */
- outb(0xf0, 0); /* clear BUSY# latch */
- /*
- * Prepare to trap all ESC (i.e., NPX) instructions and all WAIT
- * instructions. We must set the CR0_MP bit and use the CR0_TS
- * bit to control the trap, because setting the CR0_EM bit does
- * not cause WAIT instructions to trap. It's important to trap
- * WAIT instructions - otherwise the "wait" variants of no-wait
- * control instructions would degenerate to the "no-wait" variants
- * after FP context switches but work correctly otherwise. It's
- * particularly important to trap WAITs when there is no NPX -
- * otherwise the "wait" variants would always degenerate.
- *
- * Try setting CR0_NE to get correct error reporting on 486DX's.
- * Setting it should fail or do nothing on lesser processors.
- */
- load_cr0(rcr0() | CR0_MP | CR0_NE);
- /*
- * But don't trap while we're probing.
- */
- stop_emulating();
- /*
- * Finish resetting the coprocessor.
- */
- fninit();
-
- device_set_desc(dev, "math processor");
-
- return (0);
-}
-
-/*
- * Attach routine - announce which it is, and wire into system
- */
-static int
-npx_attach(dev)
- device_t dev;
-{
- register_t s;
-
- device_printf(dev, "INT 16 interface\n");
- npxinit(__INITIAL_NPXCW__);
-
- if (npx_cleanstate_ready == 0) {
- s = intr_disable();
- stop_emulating();
- fxsave(&npx_cleanstate);
- start_emulating();
- npx_cleanstate_ready = 1;
- intr_restore(s);
- }
- return (0); /* XXX unused */
-}
-
-/*
- * Initialize floating point unit.
- */
-void
-npxinit(control)
- u_short control;
-{
- static struct savefpu dummy;
- register_t savecrit;
-
- /*
- * fninit has the same h/w bugs as fnsave. Use the detoxified
- * fnsave to throw away any junk in the fpu. npxsave() initializes
- * the fpu and sets fpcurthread = NULL as important side effects.
- */
- savecrit = intr_disable();
- npxsave(&dummy);
- stop_emulating();
- /* XXX npxsave() doesn't actually initialize the fpu in the SSE case. */
- fninit();
- fldcw(&control);
- start_emulating();
- intr_restore(savecrit);
-}
-
-/*
- * Free coprocessor (if we have it).
- */
-void
-npxexit(td)
- struct thread *td;
-{
-#ifdef NPX_DEBUG
- u_int masked_exceptions;
-#endif
- register_t savecrit;
-
- savecrit = intr_disable();
- if (curthread == PCPU_GET(fpcurthread))
- npxsave(&PCPU_GET(curpcb)->pcb_save);
- intr_restore(savecrit);
-#ifdef NPX_DEBUG
- masked_exceptions = GET_FPU_CW(td) & GET_FPU_SW(td) & 0x7f;
- /*
- * Log exceptions that would have trapped with the old
- * control word (overflow, divide by 0, and invalid operand).
- */
- if (masked_exceptions & 0x0d)
- log(LOG_ERR,
-"pid %d (%s) exited with masked floating point exceptions 0x%02x\n",
- td->td_proc->p_pid, td->td_proc->p_comm,
- masked_exceptions);
-#endif
-}
-
-int
-npxformat()
-{
-
- return (_MC_FPFMT_XMM);
-}
-
-/*
- * The following mechanism is used to ensure that the FPE_... value
- * that is passed as a trapcode to the signal handler of the user
- * process does not have more than one bit set.
- *
- * Multiple bits may be set if the user process modifies the control
- * word while a status word bit is already set. While this is a sign
- * of bad coding, we have no choise than to narrow them down to one
- * bit, since we must not send a trapcode that is not exactly one of
- * the FPE_ macros.
- *
- * The mechanism has a static table with 127 entries. Each combination
- * of the 7 FPU status word exception bits directly translates to a
- * position in this table, where a single FPE_... value is stored.
- * This FPE_... value stored there is considered the "most important"
- * of the exception bits and will be sent as the signal code. The
- * precedence of the bits is based upon Intel Document "Numerical
- * Applications", Chapter "Special Computational Situations".
- *
- * The macro to choose one of these values does these steps: 1) Throw
- * away status word bits that cannot be masked. 2) Throw away the bits
- * currently masked in the control word, assuming the user isn't
- * interested in them anymore. 3) Reinsert status word bit 7 (stack
- * fault) if it is set, which cannot be masked but must be presered.
- * 4) Use the remaining bits to point into the trapcode table.
- *
- * The 6 maskable bits in order of their preference, as stated in the
- * above referenced Intel manual:
- * 1 Invalid operation (FP_X_INV)
- * 1a Stack underflow
- * 1b Stack overflow
- * 1c Operand of unsupported format
- * 1d SNaN operand.
- * 2 QNaN operand (not an exception, irrelavant here)
- * 3 Any other invalid-operation not mentioned above or zero divide
- * (FP_X_INV, FP_X_DZ)
- * 4 Denormal operand (FP_X_DNML)
- * 5 Numeric over/underflow (FP_X_OFL, FP_X_UFL)
- * 6 Inexact result (FP_X_IMP)
- */
-static char fpetable[128] = {
- 0,
- FPE_FLTINV, /* 1 - INV */
- FPE_FLTUND, /* 2 - DNML */
- FPE_FLTINV, /* 3 - INV | DNML */
- FPE_FLTDIV, /* 4 - DZ */
- FPE_FLTINV, /* 5 - INV | DZ */
- FPE_FLTDIV, /* 6 - DNML | DZ */
- FPE_FLTINV, /* 7 - INV | DNML | DZ */
- FPE_FLTOVF, /* 8 - OFL */
- FPE_FLTINV, /* 9 - INV | OFL */
- FPE_FLTUND, /* A - DNML | OFL */
- FPE_FLTINV, /* B - INV | DNML | OFL */
- FPE_FLTDIV, /* C - DZ | OFL */
- FPE_FLTINV, /* D - INV | DZ | OFL */
- FPE_FLTDIV, /* E - DNML | DZ | OFL */
- FPE_FLTINV, /* F - INV | DNML | DZ | OFL */
- FPE_FLTUND, /* 10 - UFL */
- FPE_FLTINV, /* 11 - INV | UFL */
- FPE_FLTUND, /* 12 - DNML | UFL */
- FPE_FLTINV, /* 13 - INV | DNML | UFL */
- FPE_FLTDIV, /* 14 - DZ | UFL */
- FPE_FLTINV, /* 15 - INV | DZ | UFL */
- FPE_FLTDIV, /* 16 - DNML | DZ | UFL */
- FPE_FLTINV, /* 17 - INV | DNML | DZ | UFL */
- FPE_FLTOVF, /* 18 - OFL | UFL */
- FPE_FLTINV, /* 19 - INV | OFL | UFL */
- FPE_FLTUND, /* 1A - DNML | OFL | UFL */
- FPE_FLTINV, /* 1B - INV | DNML | OFL | UFL */
- FPE_FLTDIV, /* 1C - DZ | OFL | UFL */
- FPE_FLTINV, /* 1D - INV | DZ | OFL | UFL */
- FPE_FLTDIV, /* 1E - DNML | DZ | OFL | UFL */
- FPE_FLTINV, /* 1F - INV | DNML | DZ | OFL | UFL */
- FPE_FLTRES, /* 20 - IMP */
- FPE_FLTINV, /* 21 - INV | IMP */
- FPE_FLTUND, /* 22 - DNML | IMP */
- FPE_FLTINV, /* 23 - INV | DNML | IMP */
- FPE_FLTDIV, /* 24 - DZ | IMP */
- FPE_FLTINV, /* 25 - INV | DZ | IMP */
- FPE_FLTDIV, /* 26 - DNML | DZ | IMP */
- FPE_FLTINV, /* 27 - INV | DNML | DZ | IMP */
- FPE_FLTOVF, /* 28 - OFL | IMP */
- FPE_FLTINV, /* 29 - INV | OFL | IMP */
- FPE_FLTUND, /* 2A - DNML | OFL | IMP */
- FPE_FLTINV, /* 2B - INV | DNML | OFL | IMP */
- FPE_FLTDIV, /* 2C - DZ | OFL | IMP */
- FPE_FLTINV, /* 2D - INV | DZ | OFL | IMP */
- FPE_FLTDIV, /* 2E - DNML | DZ | OFL | IMP */
- FPE_FLTINV, /* 2F - INV | DNML | DZ | OFL | IMP */
- FPE_FLTUND, /* 30 - UFL | IMP */
- FPE_FLTINV, /* 31 - INV | UFL | IMP */
- FPE_FLTUND, /* 32 - DNML | UFL | IMP */
- FPE_FLTINV, /* 33 - INV | DNML | UFL | IMP */
- FPE_FLTDIV, /* 34 - DZ | UFL | IMP */
- FPE_FLTINV, /* 35 - INV | DZ | UFL | IMP */
- FPE_FLTDIV, /* 36 - DNML | DZ | UFL | IMP */
- FPE_FLTINV, /* 37 - INV | DNML | DZ | UFL | IMP */
- FPE_FLTOVF, /* 38 - OFL | UFL | IMP */
- FPE_FLTINV, /* 39 - INV | OFL | UFL | IMP */
- FPE_FLTUND, /* 3A - DNML | OFL | UFL | IMP */
- FPE_FLTINV, /* 3B - INV | DNML | OFL | UFL | IMP */
- FPE_FLTDIV, /* 3C - DZ | OFL | UFL | IMP */
- FPE_FLTINV, /* 3D - INV | DZ | OFL | UFL | IMP */
- FPE_FLTDIV, /* 3E - DNML | DZ | OFL | UFL | IMP */
- FPE_FLTINV, /* 3F - INV | DNML | DZ | OFL | UFL | IMP */
- FPE_FLTSUB, /* 40 - STK */
- FPE_FLTSUB, /* 41 - INV | STK */
- FPE_FLTUND, /* 42 - DNML | STK */
- FPE_FLTSUB, /* 43 - INV | DNML | STK */
- FPE_FLTDIV, /* 44 - DZ | STK */
- FPE_FLTSUB, /* 45 - INV | DZ | STK */
- FPE_FLTDIV, /* 46 - DNML | DZ | STK */
- FPE_FLTSUB, /* 47 - INV | DNML | DZ | STK */
- FPE_FLTOVF, /* 48 - OFL | STK */
- FPE_FLTSUB, /* 49 - INV | OFL | STK */
- FPE_FLTUND, /* 4A - DNML | OFL | STK */
- FPE_FLTSUB, /* 4B - INV | DNML | OFL | STK */
- FPE_FLTDIV, /* 4C - DZ | OFL | STK */
- FPE_FLTSUB, /* 4D - INV | DZ | OFL | STK */
- FPE_FLTDIV, /* 4E - DNML | DZ | OFL | STK */
- FPE_FLTSUB, /* 4F - INV | DNML | DZ | OFL | STK */
- FPE_FLTUND, /* 50 - UFL | STK */
- FPE_FLTSUB, /* 51 - INV | UFL | STK */
- FPE_FLTUND, /* 52 - DNML | UFL | STK */
- FPE_FLTSUB, /* 53 - INV | DNML | UFL | STK */
- FPE_FLTDIV, /* 54 - DZ | UFL | STK */
- FPE_FLTSUB, /* 55 - INV | DZ | UFL | STK */
- FPE_FLTDIV, /* 56 - DNML | DZ | UFL | STK */
- FPE_FLTSUB, /* 57 - INV | DNML | DZ | UFL | STK */
- FPE_FLTOVF, /* 58 - OFL | UFL | STK */
- FPE_FLTSUB, /* 59 - INV | OFL | UFL | STK */
- FPE_FLTUND, /* 5A - DNML | OFL | UFL | STK */
- FPE_FLTSUB, /* 5B - INV | DNML | OFL | UFL | STK */
- FPE_FLTDIV, /* 5C - DZ | OFL | UFL | STK */
- FPE_FLTSUB, /* 5D - INV | DZ | OFL | UFL | STK */
- FPE_FLTDIV, /* 5E - DNML | DZ | OFL | UFL | STK */
- FPE_FLTSUB, /* 5F - INV | DNML | DZ | OFL | UFL | STK */
- FPE_FLTRES, /* 60 - IMP | STK */
- FPE_FLTSUB, /* 61 - INV | IMP | STK */
- FPE_FLTUND, /* 62 - DNML | IMP | STK */
- FPE_FLTSUB, /* 63 - INV | DNML | IMP | STK */
- FPE_FLTDIV, /* 64 - DZ | IMP | STK */
- FPE_FLTSUB, /* 65 - INV | DZ | IMP | STK */
- FPE_FLTDIV, /* 66 - DNML | DZ | IMP | STK */
- FPE_FLTSUB, /* 67 - INV | DNML | DZ | IMP | STK */
- FPE_FLTOVF, /* 68 - OFL | IMP | STK */
- FPE_FLTSUB, /* 69 - INV | OFL | IMP | STK */
- FPE_FLTUND, /* 6A - DNML | OFL | IMP | STK */
- FPE_FLTSUB, /* 6B - INV | DNML | OFL | IMP | STK */
- FPE_FLTDIV, /* 6C - DZ | OFL | IMP | STK */
- FPE_FLTSUB, /* 6D - INV | DZ | OFL | IMP | STK */
- FPE_FLTDIV, /* 6E - DNML | DZ | OFL | IMP | STK */
- FPE_FLTSUB, /* 6F - INV | DNML | DZ | OFL | IMP | STK */
- FPE_FLTUND, /* 70 - UFL | IMP | STK */
- FPE_FLTSUB, /* 71 - INV | UFL | IMP | STK */
- FPE_FLTUND, /* 72 - DNML | UFL | IMP | STK */
- FPE_FLTSUB, /* 73 - INV | DNML | UFL | IMP | STK */
- FPE_FLTDIV, /* 74 - DZ | UFL | IMP | STK */
- FPE_FLTSUB, /* 75 - INV | DZ | UFL | IMP | STK */
- FPE_FLTDIV, /* 76 - DNML | DZ | UFL | IMP | STK */
- FPE_FLTSUB, /* 77 - INV | DNML | DZ | UFL | IMP | STK */
- FPE_FLTOVF, /* 78 - OFL | UFL | IMP | STK */
- FPE_FLTSUB, /* 79 - INV | OFL | UFL | IMP | STK */
- FPE_FLTUND, /* 7A - DNML | OFL | UFL | IMP | STK */
- FPE_FLTSUB, /* 7B - INV | DNML | OFL | UFL | IMP | STK */
- FPE_FLTDIV, /* 7C - DZ | OFL | UFL | IMP | STK */
- FPE_FLTSUB, /* 7D - INV | DZ | OFL | UFL | IMP | STK */
- FPE_FLTDIV, /* 7E - DNML | DZ | OFL | UFL | IMP | STK */
- FPE_FLTSUB, /* 7F - INV | DNML | DZ | OFL | UFL | IMP | STK */
-};
-
-/*
- * Preserve the FP status word, clear FP exceptions, then generate a SIGFPE.
- *
- * Clearing exceptions is necessary mainly to avoid IRQ13 bugs. We now
- * depend on longjmp() restoring a usable state. Restoring the state
- * or examining it might fail if we didn't clear exceptions.
- *
- * The error code chosen will be one of the FPE_... macros. It will be
- * sent as the second argument to old BSD-style signal handlers and as
- * "siginfo_t->si_code" (second argument) to SA_SIGINFO signal handlers.
- *
- * XXX the FP state is not preserved across signal handlers. So signal
- * handlers cannot afford to do FP unless they preserve the state or
- * longjmp() out. Both preserving the state and longjmp()ing may be
- * destroyed by IRQ13 bugs. Clearing FP exceptions is not an acceptable
- * solution for signals other than SIGFPE.
- */
-int
-npxtrap()
-{
- register_t savecrit;
- u_short control, status;
-
- savecrit = intr_disable();
-
- /*
- * Interrupt handling (for another interrupt) may have pushed the
- * state to memory. Fetch the relevant parts of the state from
- * wherever they are.
- */
- if (PCPU_GET(fpcurthread) != curthread) {
- control = GET_FPU_CW(curthread);
- status = GET_FPU_SW(curthread);
- } else {
- fnstcw(&control);
- fnstsw(&status);
- }
-
- if (PCPU_GET(fpcurthread) == curthread)
- fnclex();
- intr_restore(savecrit);
- return (fpetable[status & ((~control & 0x3f) | 0x40)]);
-}
-
-/*
- * Implement device not available (DNA) exception
- *
- * It would be better to switch FP context here (if curthread != fpcurthread)
- * and not necessarily for every context switch, but it is too hard to
- * access foreign pcb's.
- */
-
-static int err_count = 0;
-
-int
-npxdna()
-{
- struct pcb *pcb;
- register_t s;
- u_short control;
-
- if (PCPU_GET(fpcurthread) == curthread) {
- printf("npxdna: fpcurthread == curthread %d times\n",
- ++err_count);
- stop_emulating();
- return (1);
- }
- if (PCPU_GET(fpcurthread) != NULL) {
- printf("npxdna: fpcurthread = %p (%d), curthread = %p (%d)\n",
- PCPU_GET(fpcurthread),
- PCPU_GET(fpcurthread)->td_proc->p_pid,
- curthread, curthread->td_proc->p_pid);
- panic("npxdna");
- }
- s = intr_disable();
- stop_emulating();
- /*
- * Record new context early in case frstor causes an IRQ13.
- */
- PCPU_SET(fpcurthread, curthread);
- pcb = PCPU_GET(curpcb);
-
- if ((pcb->pcb_flags & PCB_NPXINITDONE) == 0) {
- /*
- * This is the first time this thread has used the FPU or
- * the PCB doesn't contain a clean FPU state. Explicitly
- * initialize the FPU and load the default control word.
- */
- fninit();
- control = __INITIAL_NPXCW__;
- fldcw(&control);
- pcb->pcb_flags |= PCB_NPXINITDONE;
- } else {
- /*
- * The following frstor may cause a trap when the state
- * being restored has a pending error. The error will
- * appear to have been triggered by the current (npx) user
- * instruction even when that instruction is a no-wait
- * instruction that should not trigger an error (e.g.,
- * instructions are broken the same as frstor, so our
- * treatment does not amplify the breakage.
- */
- fxrstor(&pcb->pcb_save);
- }
- intr_restore(s);
-
- return (1);
-}
-
-/*
- * Wrapper for fnsave instruction, partly to handle hardware bugs. When npx
- * exceptions are reported via IRQ13, spurious IRQ13's may be triggered by
- * no-wait npx instructions. See the Intel application note AP-578 for
- * details. This doesn't cause any additional complications here. IRQ13's
- * are inherently asynchronous unless the CPU is frozen to deliver them --
- * one that started in userland may be delivered many instructions later,
- * after the process has entered the kernel. It may even be delivered after
- * the fnsave here completes. A spurious IRQ13 for the fnsave is handled in
- * the same way as a very-late-arriving non-spurious IRQ13 from user mode:
- * it is normally ignored at first because we set fpcurthread to NULL; it is
- * normally retriggered in npxdna() after return to user mode.
- *
- * npxsave() must be called with interrupts disabled, so that it clears
- * fpcurthread atomically with saving the state. We require callers to do the
- * disabling, since most callers need to disable interrupts anyway to call
- * npxsave() atomically with checking fpcurthread.
- *
- * A previous version of npxsave() went to great lengths to excecute fnsave
- * with interrupts enabled in case executing it froze the CPU. This case
- * can't happen, at least for Intel CPU/NPX's. Spurious IRQ13's don't imply
- * spurious freezes.
- */
-void
-npxsave(addr)
- struct savefpu *addr;
-{
-
- stop_emulating();
- fxsave(addr);
-
- start_emulating();
- PCPU_SET(fpcurthread, NULL);
-}
-
-/*
- * This should be called with interrupts disabled and only when the owning
- * FPU thread is non-null.
- */
-void
-npxdrop()
-{
- struct thread *td;
-
- td = PCPU_GET(fpcurthread);
- PCPU_SET(fpcurthread, NULL);
- td->td_pcb->pcb_flags &= ~PCB_NPXINITDONE;
- start_emulating();
-}
-
-/*
- * Get the state of the FPU without dropping ownership (if possible).
- * It returns the FPU ownership status.
- */
-int
-npxgetregs(td, addr)
- struct thread *td;
- struct savefpu *addr;
-{
- register_t s;
-
- if ((td->td_pcb->pcb_flags & PCB_NPXINITDONE) == 0) {
- if (npx_cleanstate_ready)
- bcopy(&npx_cleanstate, addr, sizeof(npx_cleanstate));
- else
- bzero(addr, sizeof(*addr));
- return (_MC_FPOWNED_NONE);
- }
- s = intr_disable();
- if (td == PCPU_GET(fpcurthread)) {
- fxsave(addr);
- intr_restore(s);
- return (_MC_FPOWNED_FPU);
- } else {
- intr_restore(s);
- bcopy(&td->td_pcb->pcb_save, addr, sizeof(*addr));
- return (_MC_FPOWNED_PCB);
- }
-}
-
-/*
- * Set the state of the FPU.
- */
-void
-npxsetregs(td, addr)
- struct thread *td;
- struct savefpu *addr;
-{
- register_t s;
-
- s = intr_disable();
- if (td == PCPU_GET(fpcurthread)) {
- fxrstor(addr);
- intr_restore(s);
- } else {
- intr_restore(s);
- bcopy(addr, &td->td_pcb->pcb_save, sizeof(*addr));
- }
- curthread->td_pcb->pcb_flags |= PCB_NPXINITDONE;
-}
-
-static device_method_t npx_methods[] = {
- /* Device interface */
- DEVMETHOD(device_identify, npx_identify),
- DEVMETHOD(device_probe, npx_probe),
- DEVMETHOD(device_attach, npx_attach),
- DEVMETHOD(device_detach, bus_generic_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- { 0, 0 }
-};
-
-static driver_t npx_driver = {
- "npx",
- npx_methods,
- 1, /* no softc */
-};
-
-static devclass_t npx_devclass;
-
-/*
- * We prefer to attach to the root nexus so that the usual case (exception 16)
- * doesn't describe the processor as being `on isa'.
- */
-DRIVER_MODULE(npx, nexus, npx_driver, npx_devclass, 0, 0);
-
-#ifdef DEV_ISA
-/*
- * This sucks up the legacy ISA support assignments from PNPBIOS/ACPI.
- */
-static struct isa_pnp_id npxisa_ids[] = {
- { 0x040cd041, "Legacy ISA coprocessor support" }, /* PNP0C04 */
- { 0 }
-};
-
-static int
-npxisa_probe(device_t dev)
-{
- int result;
- if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, npxisa_ids)) <= 0) {
- device_quiet(dev);
- }
- return(result);
-}
-
-static int
-npxisa_attach(device_t dev)
-{
- return (0);
-}
-
-static device_method_t npxisa_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, npxisa_probe),
- DEVMETHOD(device_attach, npxisa_attach),
- DEVMETHOD(device_detach, bus_generic_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- { 0, 0 }
-};
-
-static driver_t npxisa_driver = {
- "npxisa",
- npxisa_methods,
- 1, /* no softc */
-};
-
-static devclass_t npxisa_devclass;
-
-DRIVER_MODULE(npxisa, isa, npxisa_driver, npxisa_devclass, 0, 0);
-DRIVER_MODULE(npxisa, acpi, npxisa_driver, npxisa_devclass, 0, 0);
-#endif /* DEV_ISA */
diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c
deleted file mode 100644
index d630bd583aa4..000000000000
--- a/sys/amd64/amd64/mp_machdep.c
+++ /dev/null
@@ -1,2839 +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$
- */
-
-#include "opt_cpu.h"
-#include "opt_kstack_pages.h"
-#include "opt_swtch.h"
-
-#ifdef SMP
-#include <machine/smptests.h>
-#else
-#error
-#endif
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/cons.h> /* cngetc() */
-#ifdef GPROF
-#include <sys/gmon.h>
-#endif
-#include <sys/kernel.h>
-#include <sys/ktr.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/memrange.h>
-#include <sys/mutex.h>
-#include <sys/pcpu.h>
-#include <sys/proc.h>
-#include <sys/smp.h>
-#include <sys/sysctl.h>
-#include <sys/user.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_extern.h>
-#include <vm/vm_map.h>
-
-#include <machine/apic.h>
-#include <machine/atomic.h>
-#include <machine/clock.h>
-#include <machine/cpu.h>
-#include <machine/cpufunc.h>
-#include <machine/mpapic.h>
-#include <machine/psl.h>
-#include <machine/segments.h>
-#include <machine/smp.h>
-#include <machine/smptests.h> /** TEST_DEFAULT_CONFIG, TEST_TEST1 */
-#include <machine/tss.h>
-#include <machine/specialreg.h>
-#include <machine/privatespace.h>
-
-#if defined(APIC_IO)
-#include <machine/md_var.h> /* setidt() */
-#include <i386/isa/icu.h> /* IPIs */
-#include <i386/isa/intr_machdep.h> /* IPIs */
-#endif /* APIC_IO */
-
-#if defined(TEST_DEFAULT_CONFIG)
-#define MPFPS_MPFB1 TEST_DEFAULT_CONFIG
-#else
-#define MPFPS_MPFB1 mpfps->mpfb1
-#endif /* TEST_DEFAULT_CONFIG */
-
-#define WARMBOOT_TARGET 0
-#define WARMBOOT_OFF (KERNBASE + 0x0467)
-#define WARMBOOT_SEG (KERNBASE + 0x0469)
-
-#ifdef PC98
-#define BIOS_BASE (0xe8000)
-#define BIOS_SIZE (0x18000)
-#else
-#define BIOS_BASE (0xf0000)
-#define BIOS_SIZE (0x10000)
-#endif
-#define BIOS_COUNT (BIOS_SIZE/4)
-
-#define CMOS_REG (0x70)
-#define CMOS_DATA (0x71)
-#define BIOS_RESET (0x0f)
-#define BIOS_WARM (0x0a)
-
-#define PROCENTRY_FLAG_EN 0x01
-#define PROCENTRY_FLAG_BP 0x02
-#define IOAPICENTRY_FLAG_EN 0x01
-
-
-/* MP Floating Pointer Structure */
-typedef struct MPFPS {
- char signature[4];
- void *pap;
- u_char length;
- u_char spec_rev;
- u_char checksum;
- u_char mpfb1;
- u_char mpfb2;
- u_char mpfb3;
- u_char mpfb4;
- u_char mpfb5;
-} *mpfps_t;
-
-/* 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];
- void *oem_table_pointer;
- u_short oem_table_size;
- u_short entry_count;
- void *apic_address;
- u_short extended_table_length;
- u_char extended_table_checksum;
- u_char reserved;
-} *mpcth_t;
-
-
-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;
-
-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;
- void *apic_address;
-} *io_apic_entry_ptr;
-
-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;
-
-/* descriptions of MP basetable entries */
-typedef struct BASETABLE_ENTRY {
- u_char type;
- u_char length;
- char name[16];
-} basetable_entry;
-
-/*
- * this code MUST be enabled here and in mpboot.s.
- * it follows the very early stages of AP boot by placing values in CMOS ram.
- * it NORMALLY will never be needed and thus the primitive method for enabling.
- *
-#define CHECK_POINTS
- */
-
-#if defined(CHECK_POINTS) && !defined(PC98)
-#define CHECK_READ(A) (outb(CMOS_REG, (A)), inb(CMOS_DATA))
-#define CHECK_WRITE(A,D) (outb(CMOS_REG, (A)), outb(CMOS_DATA, (D)))
-
-#define CHECK_INIT(D); \
- CHECK_WRITE(0x34, (D)); \
- CHECK_WRITE(0x35, (D)); \
- CHECK_WRITE(0x36, (D)); \
- CHECK_WRITE(0x37, (D)); \
- CHECK_WRITE(0x38, (D)); \
- CHECK_WRITE(0x39, (D));
-
-#define CHECK_PRINT(S); \
- printf("%s: %d, %d, %d, %d, %d, %d\n", \
- (S), \
- CHECK_READ(0x34), \
- CHECK_READ(0x35), \
- CHECK_READ(0x36), \
- CHECK_READ(0x37), \
- CHECK_READ(0x38), \
- CHECK_READ(0x39));
-
-#else /* CHECK_POINTS */
-
-#define CHECK_INIT(D)
-#define CHECK_PRINT(S)
-
-#endif /* CHECK_POINTS */
-
-/*
- * Values to send to the POST hardware.
- */
-#define MP_BOOTADDRESS_POST 0x10
-#define MP_PROBE_POST 0x11
-#define MPTABLE_PASS1_POST 0x12
-
-#define MP_START_POST 0x13
-#define MP_ENABLE_POST 0x14
-#define MPTABLE_PASS2_POST 0x15
-
-#define START_ALL_APS_POST 0x16
-#define INSTALL_AP_TRAMP_POST 0x17
-#define START_AP_POST 0x18
-
-#define MP_ANNOUNCE_POST 0x19
-
-static int need_hyperthreading_fixup;
-static u_int logical_cpus;
-static u_int logical_cpus_mask;
-
-/* used to hold the AP's until we are ready to release them */
-static struct mtx ap_boot_mtx;
-
-/** XXX FIXME: where does this really belong, isa.h/isa.c perhaps? */
-int current_postcode;
-
-/** XXX FIXME: what system files declare these??? */
-extern struct region_descriptor r_gdt, r_idt;
-
-int bsp_apic_ready = 0; /* flags useability of BSP apic */
-int mp_naps; /* # of Applications processors */
-int mp_nbusses; /* # of busses */
-int mp_napics; /* # of IO APICs */
-int boot_cpu_id; /* designated BSP */
-vm_offset_t cpu_apic_address;
-vm_offset_t io_apic_address[NAPICID]; /* NAPICID is more than enough */
-extern int nkpt;
-
-u_int32_t cpu_apic_versions[MAXCPU];
-u_int32_t *io_apic_versions;
-
-#ifdef APIC_INTR_REORDER
-struct {
- volatile int *location;
- int bit;
-} apic_isrbit_location[32];
-#endif
-
-struct apic_intmapinfo int_to_apicintpin[APIC_INTMAPSIZE];
-
-/*
- * APIC ID logical/physical mapping structures.
- * We oversize these to simplify boot-time config.
- */
-int cpu_num_to_apic_id[NAPICID];
-int io_num_to_apic_id[NAPICID];
-int apic_id_to_logical[NAPICID];
-
-
-/* AP uses this during bootstrap. Do not staticize. */
-char *bootSTK;
-static int bootAP;
-
-/* Hotwire a 0->4MB V==P mapping */
-extern pt_entry_t *KPTphys;
-
-/* SMP page table page */
-extern pt_entry_t *SMPpt;
-
-struct pcb stoppcbs[MAXCPU];
-
-#ifdef APIC_IO
-/* Variables needed for SMP tlb shootdown. */
-vm_offset_t smp_tlb_addr1;
-vm_offset_t smp_tlb_addr2;
-volatile int smp_tlb_wait;
-static struct mtx smp_tlb_mtx;
-#endif
-
-/*
- * Local data and functions.
- */
-
-/* Set to 1 once we're ready to let the APs out of the pen. */
-static volatile int aps_ready = 0;
-
-static int mp_capable;
-static u_int boot_address;
-static u_int base_memory;
-
-static int picmode; /* 0: virtual wire mode, 1: PIC mode */
-static mpfps_t mpfps;
-static int search_for_sig(u_int32_t target, int count);
-static void mp_enable(u_int boot_addr);
-
-static void mptable_hyperthread_fixup(u_int id_mask);
-static void mptable_pass1(void);
-static int mptable_pass2(void);
-static void default_mp_table(int type);
-static void fix_mp_table(void);
-static void setup_apic_irq_mapping(void);
-static void init_locks(void);
-static int start_all_aps(u_int boot_addr);
-static void install_ap_tramp(u_int boot_addr);
-static int start_ap(int logicalCpu, u_int boot_addr);
-void ap_init(void);
-static int apic_int_is_bus_type(int intr, int bus_type);
-static void release_aps(void *dummy);
-
-/*
- * initialize all the SMP locks
- */
-
-/* lock region used by kernel profiling */
-int mcount_lock;
-
-#ifdef USE_COMLOCK
-/* locks com (tty) data/hardware accesses: a FASTINTR() */
-struct mtx com_mtx;
-#endif /* USE_COMLOCK */
-
-static void
-init_locks(void)
-{
-
-#ifdef USE_COMLOCK
- mtx_init(&com_mtx, "com", NULL, MTX_SPIN);
-#endif /* USE_COMLOCK */
-#ifdef APIC_IO
- mtx_init(&smp_tlb_mtx, "tlb", NULL, MTX_SPIN);
-#endif
-}
-
-/*
- * Calculate usable address in base memory for AP trampoline code.
- */
-u_int
-mp_bootaddress(u_int basemem)
-{
- POSTCODE(MP_BOOTADDRESS_POST);
-
- base_memory = basemem * 1024; /* convert to bytes */
-
- boot_address = base_memory & ~0xfff; /* round down to 4k boundary */
- if ((base_memory - boot_address) < bootMP_size)
- boot_address -= 4096; /* not enough, lower by 4k */
-
- return boot_address;
-}
-
-
-/*
- * Look for an Intel MP spec table (ie, SMP capable hardware).
- */
-void
-i386_mp_probe(void)
-{
- int x;
- u_long segment;
- u_int32_t target;
-
- POSTCODE(MP_PROBE_POST);
-
- /* see if EBDA exists */
- if ((segment = (u_long) * (u_short *) (KERNBASE + 0x40e)) != 0) {
- /* search first 1K of EBDA */
- target = (u_int32_t) (segment << 4);
- if ((x = search_for_sig(target, 1024 / 4)) >= 0)
- goto found;
- } else {
- /* last 1K of base memory, effective 'top of base' passed in */
- target = (u_int32_t) (base_memory - 0x400);
- if ((x = search_for_sig(target, 1024 / 4)) >= 0)
- goto found;
- }
-
- /* search the BIOS */
- target = (u_int32_t) BIOS_BASE;
- if ((x = search_for_sig(target, BIOS_COUNT)) >= 0)
- goto found;
-
- /* nothing found */
- mpfps = (mpfps_t)0;
- mp_capable = 0;
- return;
-
-found:
- /* calculate needed resources */
- mpfps = (mpfps_t)x;
- mptable_pass1();
-
- /* flag fact that we are running multiple processors */
- mp_capable = 1;
-}
-
-int
-cpu_mp_probe(void)
-{
- /*
- * Record BSP in CPU map
- * This is done here so that MBUF init code works correctly.
- */
- all_cpus = 1;
-
- return (mp_capable);
-}
-
-/*
- * Initialize the SMP hardware and the APIC and start up the AP's.
- */
-void
-cpu_mp_start(void)
-{
- POSTCODE(MP_START_POST);
-
- /* look for MP capable motherboard */
- if (mp_capable)
- mp_enable(boot_address);
- else
- panic("MP hardware not found!");
-
- cpu_setregs();
-}
-
-
-/*
- * Print various information about the SMP system hardware and setup.
- */
-void
-cpu_mp_announce(void)
-{
- int x;
-
- POSTCODE(MP_ANNOUNCE_POST);
-
- printf(" cpu0 (BSP): apic id: %2d", CPU_TO_ID(0));
- printf(", version: 0x%08x", cpu_apic_versions[0]);
- printf(", at 0x%08x\n", cpu_apic_address);
- for (x = 1; x <= mp_naps; ++x) {
- printf(" cpu%d (AP): apic id: %2d", x, CPU_TO_ID(x));
- printf(", version: 0x%08x", cpu_apic_versions[x]);
- printf(", at 0x%08x\n", cpu_apic_address);
- }
-
-#if defined(APIC_IO)
- for (x = 0; x < mp_napics; ++x) {
- printf(" io%d (APIC): apic id: %2d", x, IO_TO_ID(x));
- printf(", version: 0x%08x", io_apic_versions[x]);
- printf(", at 0x%08x\n", io_apic_address[x]);
- }
-#else
- printf(" Warning: APIC I/O disabled\n");
-#endif /* APIC_IO */
-}
-
-/*
- * AP cpu's call this to sync up protected mode.
- */
-void
-init_secondary(void)
-{
- int gsel_tss;
- int x, myid = bootAP;
- u_int cr0;
-
- gdt_segs[GPRIV_SEL].ssd_base = (int) &SMP_prvspace[myid];
- gdt_segs[GPROC0_SEL].ssd_base =
- (int) &SMP_prvspace[myid].pcpu.pc_common_tss;
- SMP_prvspace[myid].pcpu.pc_prvspace =
- &SMP_prvspace[myid].pcpu;
-
- for (x = 0; x < NGDT; x++) {
- ssdtosd(&gdt_segs[x], &gdt[myid * NGDT + x].sd);
- }
-
- r_gdt.rd_limit = NGDT * sizeof(gdt[0]) - 1;
- r_gdt.rd_base = (int) &gdt[myid * NGDT];
- lgdt(&r_gdt); /* does magic intra-segment return */
-
- lidt(&r_idt);
-
- lldt(_default_ldt);
- PCPU_SET(currentldt, _default_ldt);
-
- gsel_tss = GSEL(GPROC0_SEL, SEL_KPL);
- gdt[myid * NGDT + GPROC0_SEL].sd.sd_type = SDT_SYS386TSS;
- PCPU_SET(common_tss.tss_esp0, 0); /* not used until after switch */
- PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL));
- PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16);
- PCPU_SET(tss_gdt, &gdt[myid * NGDT + GPROC0_SEL].sd);
- PCPU_SET(common_tssd, *PCPU_GET(tss_gdt));
- ltr(gsel_tss);
-
- /*
- * Set to a known state:
- * Set by mpboot.s: CR0_PG, CR0_PE
- * Set by cpu_setregs: CR0_NE, CR0_MP, CR0_TS, CR0_WP, CR0_AM
- */
- cr0 = rcr0();
- cr0 &= ~(CR0_CD | CR0_NW | CR0_EM);
- load_cr0(cr0);
-
- pmap_set_opt();
-}
-
-
-#if defined(APIC_IO)
-/*
- * Final configuration of the BSP's local APIC:
- * - disable 'pic mode'.
- * - disable 'virtual wire mode'.
- * - enable NMI.
- */
-void
-bsp_apic_configure(void)
-{
- u_char byte;
- u_int32_t temp;
-
- /* leave 'pic mode' if necessary */
- if (picmode) {
- outb(0x22, 0x70); /* select IMCR */
- byte = inb(0x23); /* current contents */
- byte |= 0x01; /* mask external INTR */
- outb(0x23, byte); /* disconnect 8259s/NMI */
- }
-
- /* mask lint0 (the 8259 'virtual wire' connection) */
- temp = lapic.lvt_lint0;
- temp |= APIC_LVT_M; /* set the mask */
- lapic.lvt_lint0 = temp;
-
- /* setup lint1 to handle NMI */
- temp = lapic.lvt_lint1;
- temp &= ~APIC_LVT_M; /* clear the mask */
- lapic.lvt_lint1 = temp;
-
- if (bootverbose)
- apic_dump("bsp_apic_configure()");
-}
-#endif /* APIC_IO */
-
-
-/*******************************************************************
- * local functions and data
- */
-
-/*
- * start the SMP system
- */
-static void
-mp_enable(u_int boot_addr)
-{
- int x;
-#if defined(APIC_IO)
- int apic;
- u_int ux;
-#endif /* APIC_IO */
-
- POSTCODE(MP_ENABLE_POST);
-
- /* turn on 4MB of V == P addressing so we can get to MP table */
- *(int *)PTD = PG_V | PG_RW | ((uintptr_t)(void *)KPTphys & PG_FRAME);
- invltlb();
-
- /* examine the MP table for needed info, uses physical addresses */
- x = mptable_pass2();
-
- *(int *)PTD = 0;
- invltlb();
-
- /* can't process default configs till the CPU APIC is pmapped */
- if (x)
- default_mp_table(x);
-
- /* post scan cleanup */
- fix_mp_table();
- setup_apic_irq_mapping();
-
-#if defined(APIC_IO)
-
- /* fill the LOGICAL io_apic_versions table */
- for (apic = 0; apic < mp_napics; ++apic) {
- ux = io_apic_read(apic, IOAPIC_VER);
- io_apic_versions[apic] = ux;
- io_apic_set_id(apic, IO_TO_ID(apic));
- }
-
- /* program each IO APIC in the system */
- for (apic = 0; apic < mp_napics; ++apic)
- if (io_apic_setup(apic) < 0)
- panic("IO APIC setup failure");
-
- /* install a 'Spurious INTerrupt' vector */
- setidt(XSPURIOUSINT_OFFSET, Xspuriousint,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for TLB invalidation */
- setidt(XINVLTLB_OFFSET, Xinvltlb,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- setidt(XINVLPG_OFFSET, Xinvlpg,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- setidt(XINVLRNG_OFFSET, Xinvlrng,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forwarding hardclock() */
- setidt(XHARDCLOCK_OFFSET, Xhardclock,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forwarding statclock() */
- setidt(XSTATCLOCK_OFFSET, Xstatclock,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
-#ifdef LAZY_SWITCH
- /* install an inter-CPU IPI for lazy pmap release */
- setidt(XLAZYPMAP_OFFSET, Xlazypmap,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif
-
- /* install an inter-CPU IPI for all-CPU rendezvous */
- setidt(XRENDEZVOUS_OFFSET, Xrendezvous,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forcing an additional software trap */
- setidt(XCPUAST_OFFSET, Xcpuast,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for CPU stop/restart */
- setidt(XCPUSTOP_OFFSET, Xcpustop,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
-#if defined(TEST_TEST1)
- /* install a "fake hardware INTerrupt" vector */
- setidt(XTEST1_OFFSET, Xtest1,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif /** TEST_TEST1 */
-
-#endif /* APIC_IO */
-
- /* initialize all SMP locks */
- init_locks();
-
- /* start each Application Processor */
- start_all_aps(boot_addr);
-}
-
-
-/*
- * look for the MP spec signature
- */
-
-/* string defined by the Intel MP Spec as identifying the MP table */
-#define MP_SIG 0x5f504d5f /* _MP_ */
-#define NEXT(X) ((X) += 4)
-static int
-search_for_sig(u_int32_t target, int count)
-{
- int x;
- u_int32_t *addr = (u_int32_t *) (KERNBASE + target);
-
- for (x = 0; x < count; NEXT(x))
- if (addr[x] == MP_SIG)
- /* make array index a byte index */
- return (target + (x * sizeof(u_int32_t)));
-
- return -1;
-}
-
-
-static basetable_entry basetable_entry_types[] =
-{
- {0, 20, "Processor"},
- {1, 8, "Bus"},
- {2, 8, "I/O APIC"},
- {3, 8, "I/O INT"},
- {4, 8, "Local INT"}
-};
-
-typedef struct BUSDATA {
- u_char bus_id;
- enum busTypes bus_type;
-} bus_datum;
-
-typedef struct INTDATA {
- 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;
- u_char int_vector;
-} io_int, local_int;
-
-typedef struct BUSTYPENAME {
- u_char type;
- char name[7];
-} bus_type_name;
-
-static bus_type_name bus_type_table[] =
-{
- {CBUS, "CBUS"},
- {CBUSII, "CBUSII"},
- {EISA, "EISA"},
- {MCA, "MCA"},
- {UNKNOWN_BUSTYPE, "---"},
- {ISA, "ISA"},
- {MCA, "MCA"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {PCI, "PCI"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {XPRESS, "XPRESS"},
- {UNKNOWN_BUSTYPE, "---"}
-};
-/* from MP spec v1.4, table 5-1 */
-static int default_data[7][5] =
-{
-/* nbus, id0, type0, id1, type1 */
- {1, 0, ISA, 255, 255},
- {1, 0, EISA, 255, 255},
- {1, 0, EISA, 255, 255},
- {1, 0, MCA, 255, 255},
- {2, 0, ISA, 1, PCI},
- {2, 0, EISA, 1, PCI},
- {2, 0, MCA, 1, PCI}
-};
-
-
-/* the bus data */
-static bus_datum *bus_data;
-
-/* the IO INT data, one entry per possible APIC INTerrupt */
-static io_int *io_apic_ints;
-
-static int nintrs;
-
-static int processor_entry(proc_entry_ptr entry, int cpu);
-static int bus_entry(bus_entry_ptr entry, int bus);
-static int io_apic_entry(io_apic_entry_ptr entry, int apic);
-static int int_entry(int_entry_ptr entry, int intr);
-static int lookup_bus_type(char *name);
-
-
-/*
- * 1st pass on motherboard's Intel MP specification table.
- *
- * initializes:
- * mp_ncpus = 1
- *
- * determines:
- * cpu_apic_address (common to all CPUs)
- * io_apic_address[N]
- * mp_naps
- * mp_nbusses
- * mp_napics
- * nintrs
- */
-static void
-mptable_pass1(void)
-{
- int x;
- mpcth_t cth;
- int totalSize;
- void* position;
- int count;
- int type;
- u_int id_mask;
-
- POSTCODE(MPTABLE_PASS1_POST);
-
- /* clear various tables */
- for (x = 0; x < NAPICID; ++x) {
- io_apic_address[x] = ~0; /* IO APIC address table */
- }
-
- /* init everything to empty */
- mp_naps = 0;
- mp_nbusses = 0;
- mp_napics = 0;
- nintrs = 0;
- id_mask = 0;
-
- /* check for use of 'default' configuration */
- if (MPFPS_MPFB1 != 0) {
- /* use default addresses */
- cpu_apic_address = DEFAULT_APIC_BASE;
- io_apic_address[0] = DEFAULT_IO_APIC_BASE;
-
- /* fill in with defaults */
- mp_naps = 2; /* includes BSP */
- mp_maxid = 1;
- mp_nbusses = default_data[MPFPS_MPFB1 - 1][0];
-#if defined(APIC_IO)
- mp_napics = 1;
- nintrs = 16;
-#endif /* APIC_IO */
- }
- else {
- if ((cth = mpfps->pap) == 0)
- panic("MP Configuration Table Header MISSING!");
-
- cpu_apic_address = (vm_offset_t) cth->apic_address;
-
- /* walk the table, recording info of interest */
- totalSize = cth->base_table_length - sizeof(struct MPCTH);
- position = (u_char *) cth + sizeof(struct MPCTH);
- count = cth->entry_count;
-
- while (count--) {
- switch (type = *(u_char *) position) {
- case 0: /* processor_entry */
- if (((proc_entry_ptr)position)->cpu_flags
- & PROCENTRY_FLAG_EN) {
- ++mp_naps;
- mp_maxid++;
- id_mask |= 1 <<
- ((proc_entry_ptr)position)->apic_id;
- }
- break;
- case 1: /* bus_entry */
- ++mp_nbusses;
- break;
- case 2: /* io_apic_entry */
- if (((io_apic_entry_ptr)position)->apic_flags
- & IOAPICENTRY_FLAG_EN)
- io_apic_address[mp_napics++] =
- (vm_offset_t)((io_apic_entry_ptr)
- position)->apic_address;
- break;
- case 3: /* int_entry */
- ++nintrs;
- break;
- case 4: /* int_entry */
- break;
- default:
- panic("mpfps Base Table HOSED!");
- /* NOTREACHED */
- }
-
- totalSize -= basetable_entry_types[type].length;
- (u_char*)position += basetable_entry_types[type].length;
- }
- }
-
- /* qualify the numbers */
- if (mp_naps > MAXCPU) {
- printf("Warning: only using %d of %d available CPUs!\n",
- MAXCPU, mp_naps);
- mp_naps = MAXCPU;
- }
-
- /* See if we need to fixup HT logical CPUs. */
- mptable_hyperthread_fixup(id_mask);
-
- /*
- * Count the BSP.
- * This is also used as a counter while starting the APs.
- */
- mp_ncpus = 1;
-
- --mp_naps; /* subtract the BSP */
-}
-
-
-/*
- * 2nd pass on motherboard's Intel MP specification table.
- *
- * sets:
- * boot_cpu_id
- * ID_TO_IO(N), phy APIC ID to log CPU/IO table
- * CPU_TO_ID(N), logical CPU to APIC ID table
- * IO_TO_ID(N), logical IO to APIC ID table
- * bus_data[N]
- * io_apic_ints[N]
- */
-static int
-mptable_pass2(void)
-{
- struct PROCENTRY proc;
- int x;
- mpcth_t cth;
- int totalSize;
- void* position;
- int count;
- int type;
- int apic, bus, cpu, intr;
- int i, j;
- int pgeflag;
-
- POSTCODE(MPTABLE_PASS2_POST);
-
- /* Initialize fake proc entry for use with HT fixup. */
- bzero(&proc, sizeof(proc));
- proc.type = 0;
- proc.cpu_flags = PROCENTRY_FLAG_EN;
-
- pgeflag = 0; /* XXX - Not used under SMP yet. */
-
- MALLOC(io_apic_versions, u_int32_t *, sizeof(u_int32_t) * mp_napics,
- M_DEVBUF, M_WAITOK);
- MALLOC(ioapic, volatile ioapic_t **, sizeof(ioapic_t *) * mp_napics,
- M_DEVBUF, M_WAITOK);
- MALLOC(io_apic_ints, io_int *, sizeof(io_int) * (nintrs + 1),
- M_DEVBUF, M_WAITOK);
- MALLOC(bus_data, bus_datum *, sizeof(bus_datum) * mp_nbusses,
- M_DEVBUF, M_WAITOK);
-
- bzero(ioapic, sizeof(ioapic_t *) * mp_napics);
-
- for (i = 0; i < mp_napics; i++) {
- for (j = 0; j < mp_napics; j++) {
- /* same page frame as a previous IO apic? */
- if (((vm_offset_t)SMPpt[NPTEPG-2-j] & PG_FRAME) ==
- (io_apic_address[i] & PG_FRAME)) {
- ioapic[i] = (ioapic_t *)((u_int)SMP_prvspace
- + (NPTEPG-2-j) * PAGE_SIZE
- + (io_apic_address[i] & PAGE_MASK));
- break;
- }
- /* use this slot if available */
- if (((vm_offset_t)SMPpt[NPTEPG-2-j] & PG_FRAME) == 0) {
- SMPpt[NPTEPG-2-j] = (pt_entry_t)(PG_V | PG_RW |
- pgeflag | (io_apic_address[i] & PG_FRAME));
- ioapic[i] = (ioapic_t *)((u_int)SMP_prvspace
- + (NPTEPG-2-j) * PAGE_SIZE
- + (io_apic_address[i] & PAGE_MASK));
- break;
- }
- }
- }
-
- /* clear various tables */
- for (x = 0; x < NAPICID; ++x) {
- ID_TO_IO(x) = -1; /* phy APIC ID to log CPU/IO table */
- CPU_TO_ID(x) = -1; /* logical CPU to APIC ID table */
- IO_TO_ID(x) = -1; /* logical IO to APIC ID table */
- }
-
- /* clear bus data table */
- for (x = 0; x < mp_nbusses; ++x)
- bus_data[x].bus_id = 0xff;
-
- /* clear IO APIC INT table */
- for (x = 0; x < (nintrs + 1); ++x) {
- io_apic_ints[x].int_type = 0xff;
- io_apic_ints[x].int_vector = 0xff;
- }
-
- /* setup the cpu/apic mapping arrays */
- boot_cpu_id = -1;
-
- /* record whether PIC or virtual-wire mode */
- picmode = (mpfps->mpfb2 & 0x80) ? 1 : 0;
-
- /* check for use of 'default' configuration */
- if (MPFPS_MPFB1 != 0)
- return MPFPS_MPFB1; /* return default configuration type */
-
- if ((cth = mpfps->pap) == 0)
- panic("MP Configuration Table Header MISSING!");
-
- /* walk the table, recording info of interest */
- totalSize = cth->base_table_length - sizeof(struct MPCTH);
- position = (u_char *) cth + sizeof(struct MPCTH);
- count = cth->entry_count;
- apic = bus = intr = 0;
- cpu = 1; /* pre-count the BSP */
-
- while (count--) {
- switch (type = *(u_char *) position) {
- case 0:
- if (processor_entry(position, cpu)) {
- if (logical_cpus != 0 &&
- cpu % logical_cpus != 0)
- logical_cpus_mask |= (1 << cpu);
- ++cpu;
- }
- if (need_hyperthreading_fixup) {
- /*
- * Create fake mptable processor entries
- * and feed them to processor_entry() to
- * enumerate the logical CPUs.
- */
- proc.apic_id = ((proc_entry_ptr)position)->apic_id;
- for (i = 1; i < logical_cpus; i++) {
- proc.apic_id++;
- (void)processor_entry(&proc, cpu);
- logical_cpus_mask |= (1 << cpu);
- cpu++;
- }
- }
- break;
- case 1:
- if (bus_entry(position, bus))
- ++bus;
- break;
- case 2:
- if (io_apic_entry(position, apic))
- ++apic;
- break;
- case 3:
- if (int_entry(position, intr))
- ++intr;
- break;
- case 4:
- /* int_entry(position); */
- break;
- default:
- panic("mpfps Base Table HOSED!");
- /* NOTREACHED */
- }
-
- totalSize -= basetable_entry_types[type].length;
- (u_char *) position += basetable_entry_types[type].length;
- }
-
- if (boot_cpu_id == -1)
- panic("NO BSP found!");
-
- /* report fact that its NOT a default configuration */
- return 0;
-}
-
-/*
- * Check if we should perform a hyperthreading "fix-up" to
- * enumerate any logical CPU's that aren't already listed
- * in the table.
- *
- * XXX: We assume that all of the physical CPUs in the
- * system have the same number of logical CPUs.
- *
- * XXX: We assume that APIC ID's are allocated such that
- * the APIC ID's for a physical processor are aligned
- * with the number of logical CPU's in the processor.
- */
-static void
-mptable_hyperthread_fixup(u_int id_mask)
-{
- u_int i, id;
-
- /* Nothing to do if there is no HTT support. */
- if ((cpu_feature & CPUID_HTT) == 0)
- return;
- logical_cpus = (cpu_procinfo & CPUID_HTT_CORES) >> 16;
- if (logical_cpus <= 1)
- return;
-
- /*
- * For each APIC ID of a CPU that is set in the mask,
- * scan the other candidate APIC ID's for this
- * physical processor. If any of those ID's are
- * already in the table, then kill the fixup.
- */
- for (id = 0; id <= MAXCPU; id++) {
- if ((id_mask & 1 << id) == 0)
- continue;
- /* First, make sure we are on a logical_cpus boundary. */
- if (id % logical_cpus != 0)
- return;
- for (i = id + 1; i < id + logical_cpus; i++)
- if ((id_mask & 1 << i) != 0)
- return;
- }
-
- /*
- * Ok, the ID's checked out, so enable the fixup. We have to fixup
- * mp_naps and mp_maxid right now.
- */
- need_hyperthreading_fixup = 1;
- mp_maxid *= logical_cpus;
- mp_naps *= logical_cpus;
-}
-
-void
-assign_apic_irq(int apic, int intpin, int irq)
-{
- int x;
-
- if (int_to_apicintpin[irq].ioapic != -1)
- panic("assign_apic_irq: inconsistent table");
-
- int_to_apicintpin[irq].ioapic = apic;
- int_to_apicintpin[irq].int_pin = intpin;
- int_to_apicintpin[irq].apic_address = ioapic[apic];
- int_to_apicintpin[irq].redirindex = IOAPIC_REDTBL + 2 * intpin;
-
- for (x = 0; x < nintrs; x++) {
- if ((io_apic_ints[x].int_type == 0 ||
- io_apic_ints[x].int_type == 3) &&
- io_apic_ints[x].int_vector == 0xff &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(apic) &&
- io_apic_ints[x].dst_apic_int == intpin)
- io_apic_ints[x].int_vector = irq;
- }
-}
-
-void
-revoke_apic_irq(int irq)
-{
- int x;
- int oldapic;
- int oldintpin;
-
- if (int_to_apicintpin[irq].ioapic == -1)
- panic("revoke_apic_irq: inconsistent table");
-
- oldapic = int_to_apicintpin[irq].ioapic;
- oldintpin = int_to_apicintpin[irq].int_pin;
-
- int_to_apicintpin[irq].ioapic = -1;
- int_to_apicintpin[irq].int_pin = 0;
- int_to_apicintpin[irq].apic_address = NULL;
- int_to_apicintpin[irq].redirindex = 0;
-
- for (x = 0; x < nintrs; x++) {
- if ((io_apic_ints[x].int_type == 0 ||
- io_apic_ints[x].int_type == 3) &&
- io_apic_ints[x].int_vector != 0xff &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(oldapic) &&
- io_apic_ints[x].dst_apic_int == oldintpin)
- io_apic_ints[x].int_vector = 0xff;
- }
-}
-
-
-static void
-allocate_apic_irq(int intr)
-{
- int apic;
- int intpin;
- int irq;
-
- if (io_apic_ints[intr].int_vector != 0xff)
- return; /* Interrupt handler already assigned */
-
- if (io_apic_ints[intr].int_type != 0 &&
- (io_apic_ints[intr].int_type != 3 ||
- (io_apic_ints[intr].dst_apic_id == IO_TO_ID(0) &&
- io_apic_ints[intr].dst_apic_int == 0)))
- return; /* Not INT or ExtInt on != (0, 0) */
-
- irq = 0;
- while (irq < APIC_INTMAPSIZE &&
- int_to_apicintpin[irq].ioapic != -1)
- irq++;
-
- if (irq >= APIC_INTMAPSIZE)
- return; /* No free interrupt handlers */
-
- apic = ID_TO_IO(io_apic_ints[intr].dst_apic_id);
- intpin = io_apic_ints[intr].dst_apic_int;
-
- assign_apic_irq(apic, intpin, irq);
- io_apic_setup_intpin(apic, intpin);
-}
-
-
-static void
-swap_apic_id(int apic, int oldid, int newid)
-{
- int x;
- int oapic;
-
-
- if (oldid == newid)
- return; /* Nothing to do */
-
- printf("Changing APIC ID for IO APIC #%d from %d to %d in MP table\n",
- apic, oldid, newid);
-
- /* Swap physical APIC IDs in interrupt entries */
- for (x = 0; x < nintrs; x++) {
- if (io_apic_ints[x].dst_apic_id == oldid)
- io_apic_ints[x].dst_apic_id = newid;
- else if (io_apic_ints[x].dst_apic_id == newid)
- io_apic_ints[x].dst_apic_id = oldid;
- }
-
- /* Swap physical APIC IDs in IO_TO_ID mappings */
- for (oapic = 0; oapic < mp_napics; oapic++)
- if (IO_TO_ID(oapic) == newid)
- break;
-
- if (oapic < mp_napics) {
- printf("Changing APIC ID for IO APIC #%d from "
- "%d to %d in MP table\n",
- oapic, newid, oldid);
- IO_TO_ID(oapic) = oldid;
- }
- IO_TO_ID(apic) = newid;
-}
-
-
-static void
-fix_id_to_io_mapping(void)
-{
- int x;
-
- for (x = 0; x < NAPICID; x++)
- ID_TO_IO(x) = -1;
-
- for (x = 0; x <= mp_naps; x++)
- if (CPU_TO_ID(x) < NAPICID)
- ID_TO_IO(CPU_TO_ID(x)) = x;
-
- for (x = 0; x < mp_napics; x++)
- if (IO_TO_ID(x) < NAPICID)
- ID_TO_IO(IO_TO_ID(x)) = x;
-}
-
-
-static int
-first_free_apic_id(void)
-{
- int freeid, x;
-
- for (freeid = 0; freeid < NAPICID; freeid++) {
- for (x = 0; x <= mp_naps; x++)
- if (CPU_TO_ID(x) == freeid)
- break;
- if (x <= mp_naps)
- continue;
- for (x = 0; x < mp_napics; x++)
- if (IO_TO_ID(x) == freeid)
- break;
- if (x < mp_napics)
- continue;
- return freeid;
- }
- return freeid;
-}
-
-
-static int
-io_apic_id_acceptable(int apic, int id)
-{
- int cpu; /* Logical CPU number */
- int oapic; /* Logical IO APIC number for other IO APIC */
-
- if (id >= NAPICID)
- return 0; /* Out of range */
-
- for (cpu = 0; cpu <= mp_naps; cpu++)
- if (CPU_TO_ID(cpu) == id)
- return 0; /* Conflict with CPU */
-
- for (oapic = 0; oapic < mp_napics && oapic < apic; oapic++)
- if (IO_TO_ID(oapic) == id)
- return 0; /* Conflict with other APIC */
-
- return 1; /* ID is acceptable for IO APIC */
-}
-
-
-/*
- * parse an Intel MP specification table
- */
-static void
-fix_mp_table(void)
-{
- int x;
- int id;
- int bus_0 = 0; /* Stop GCC warning */
- int bus_pci = 0; /* Stop GCC warning */
- int num_pci_bus;
- int apic; /* IO APIC unit number */
- int freeid; /* Free physical APIC ID */
- int physid; /* Current physical IO APIC ID */
-
- /*
- * Fix mis-numbering of the PCI bus and its INT entries if the BIOS
- * did it wrong. The MP spec says that when more than 1 PCI bus
- * exists the BIOS must begin with bus entries for the PCI bus and use
- * actual PCI bus numbering. This implies that when only 1 PCI bus
- * exists the BIOS can choose to ignore this ordering, and indeed many
- * MP motherboards do ignore it. This causes a problem when the PCI
- * sub-system makes requests of the MP sub-system based on PCI bus
- * numbers. So here we look for the situation and renumber the
- * busses and associated INTs in an effort to "make it right".
- */
-
- /* find bus 0, PCI bus, count the number of PCI busses */
- for (num_pci_bus = 0, x = 0; x < mp_nbusses; ++x) {
- if (bus_data[x].bus_id == 0) {
- bus_0 = x;
- }
- if (bus_data[x].bus_type == PCI) {
- ++num_pci_bus;
- bus_pci = x;
- }
- }
- /*
- * bus_0 == slot of bus with ID of 0
- * bus_pci == slot of last PCI bus encountered
- */
-
- /* check the 1 PCI bus case for sanity */
- /* if it is number 0 all is well */
- if (num_pci_bus == 1 &&
- bus_data[bus_pci].bus_id != 0) {
-
- /* mis-numbered, swap with whichever bus uses slot 0 */
-
- /* swap the bus entry types */
- bus_data[bus_pci].bus_type = bus_data[bus_0].bus_type;
- bus_data[bus_0].bus_type = PCI;
-
- /* swap each relavant INTerrupt entry */
- id = bus_data[bus_pci].bus_id;
- for (x = 0; x < nintrs; ++x) {
- if (io_apic_ints[x].src_bus_id == id) {
- io_apic_ints[x].src_bus_id = 0;
- }
- else if (io_apic_ints[x].src_bus_id == 0) {
- io_apic_ints[x].src_bus_id = id;
- }
- }
- }
-
- /* Assign IO APIC IDs.
- *
- * First try the existing ID. If a conflict is detected, try
- * the ID in the MP table. If a conflict is still detected, find
- * a free id.
- *
- * We cannot use the ID_TO_IO table before all conflicts has been
- * resolved and the table has been corrected.
- */
- for (apic = 0; apic < mp_napics; ++apic) { /* For all IO APICs */
-
- /* First try to use the value set by the BIOS */
- physid = io_apic_get_id(apic);
- if (io_apic_id_acceptable(apic, physid)) {
- if (IO_TO_ID(apic) != physid)
- swap_apic_id(apic, IO_TO_ID(apic), physid);
- continue;
- }
-
- /* Then check if the value in the MP table is acceptable */
- if (io_apic_id_acceptable(apic, IO_TO_ID(apic)))
- continue;
-
- /* Last resort, find a free APIC ID and use it */
- freeid = first_free_apic_id();
- if (freeid >= NAPICID)
- panic("No free physical APIC IDs found");
-
- if (io_apic_id_acceptable(apic, freeid)) {
- swap_apic_id(apic, IO_TO_ID(apic), freeid);
- continue;
- }
- panic("Free physical APIC ID not usable");
- }
- fix_id_to_io_mapping();
-
- /* detect and fix broken Compaq MP table */
- if (apic_int_type(0, 0) == -1) {
- printf("APIC_IO: MP table broken: 8259->APIC entry missing!\n");
- io_apic_ints[nintrs].int_type = 3; /* ExtInt */
- io_apic_ints[nintrs].int_vector = 0xff; /* Unassigned */
- /* XXX fixme, set src bus id etc, but it doesn't seem to hurt */
- io_apic_ints[nintrs].dst_apic_id = IO_TO_ID(0);
- io_apic_ints[nintrs].dst_apic_int = 0; /* Pin 0 */
- nintrs++;
- }
-}
-
-
-/* Assign low level interrupt handlers */
-static void
-setup_apic_irq_mapping(void)
-{
- int x;
- int int_vector;
-
- /* Clear array */
- for (x = 0; x < APIC_INTMAPSIZE; x++) {
- int_to_apicintpin[x].ioapic = -1;
- int_to_apicintpin[x].int_pin = 0;
- int_to_apicintpin[x].apic_address = NULL;
- int_to_apicintpin[x].redirindex = 0;
- }
-
- /* First assign ISA/EISA interrupts */
- for (x = 0; x < nintrs; x++) {
- int_vector = io_apic_ints[x].src_bus_irq;
- if (int_vector < APIC_INTMAPSIZE &&
- io_apic_ints[x].int_vector == 0xff &&
- int_to_apicintpin[int_vector].ioapic == -1 &&
- (apic_int_is_bus_type(x, ISA) ||
- apic_int_is_bus_type(x, EISA)) &&
- io_apic_ints[x].int_type == 0) {
- assign_apic_irq(ID_TO_IO(io_apic_ints[x].dst_apic_id),
- io_apic_ints[x].dst_apic_int,
- int_vector);
- }
- }
-
- /* Assign ExtInt entry if no ISA/EISA interrupt 0 entry */
- for (x = 0; x < nintrs; x++) {
- if (io_apic_ints[x].dst_apic_int == 0 &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(0) &&
- io_apic_ints[x].int_vector == 0xff &&
- int_to_apicintpin[0].ioapic == -1 &&
- io_apic_ints[x].int_type == 3) {
- assign_apic_irq(0, 0, 0);
- break;
- }
- }
- /* PCI interrupt assignment is deferred */
-}
-
-
-static int
-processor_entry(proc_entry_ptr entry, int cpu)
-{
- /* check for usability */
- if (!(entry->cpu_flags & PROCENTRY_FLAG_EN))
- return 0;
-
- if(entry->apic_id >= NAPICID)
- panic("CPU APIC ID out of range (0..%d)", NAPICID - 1);
- /* check for BSP flag */
- if (entry->cpu_flags & PROCENTRY_FLAG_BP) {
- boot_cpu_id = entry->apic_id;
- CPU_TO_ID(0) = entry->apic_id;
- ID_TO_CPU(entry->apic_id) = 0;
- return 0; /* its already been counted */
- }
-
- /* add another AP to list, if less than max number of CPUs */
- else if (cpu < MAXCPU) {
- CPU_TO_ID(cpu) = entry->apic_id;
- ID_TO_CPU(entry->apic_id) = cpu;
- return 1;
- }
-
- return 0;
-}
-
-
-static int
-bus_entry(bus_entry_ptr entry, int bus)
-{
- int x;
- char c, name[8];
-
- /* encode the name into an index */
- for (x = 0; x < 6; ++x) {
- if ((c = entry->bus_type[x]) == ' ')
- break;
- name[x] = c;
- }
- name[x] = '\0';
-
- if ((x = lookup_bus_type(name)) == UNKNOWN_BUSTYPE)
- panic("unknown bus type: '%s'", name);
-
- bus_data[bus].bus_id = entry->bus_id;
- bus_data[bus].bus_type = x;
-
- return 1;
-}
-
-
-static int
-io_apic_entry(io_apic_entry_ptr entry, int apic)
-{
- if (!(entry->apic_flags & IOAPICENTRY_FLAG_EN))
- return 0;
-
- IO_TO_ID(apic) = entry->apic_id;
- if (entry->apic_id < NAPICID)
- ID_TO_IO(entry->apic_id) = apic;
-
- return 1;
-}
-
-
-static int
-lookup_bus_type(char *name)
-{
- int x;
-
- for (x = 0; x < MAX_BUSTYPE; ++x)
- if (strcmp(bus_type_table[x].name, name) == 0)
- return bus_type_table[x].type;
-
- return UNKNOWN_BUSTYPE;
-}
-
-
-static int
-int_entry(int_entry_ptr entry, int intr)
-{
- int apic;
-
- io_apic_ints[intr].int_type = entry->int_type;
- io_apic_ints[intr].int_flags = entry->int_flags;
- io_apic_ints[intr].src_bus_id = entry->src_bus_id;
- io_apic_ints[intr].src_bus_irq = entry->src_bus_irq;
- if (entry->dst_apic_id == 255) {
- /* This signal goes to all IO APICS. Select an IO APIC
- with sufficient number of interrupt pins */
- for (apic = 0; apic < mp_napics; apic++)
- if (((io_apic_read(apic, IOAPIC_VER) &
- IOART_VER_MAXREDIR) >> MAXREDIRSHIFT) >=
- entry->dst_apic_int)
- break;
- if (apic < mp_napics)
- io_apic_ints[intr].dst_apic_id = IO_TO_ID(apic);
- else
- io_apic_ints[intr].dst_apic_id = entry->dst_apic_id;
- } else
- io_apic_ints[intr].dst_apic_id = entry->dst_apic_id;
- io_apic_ints[intr].dst_apic_int = entry->dst_apic_int;
-
- return 1;
-}
-
-
-static int
-apic_int_is_bus_type(int intr, int bus_type)
-{
- int bus;
-
- for (bus = 0; bus < mp_nbusses; ++bus)
- if ((bus_data[bus].bus_id == io_apic_ints[intr].src_bus_id)
- && ((int) bus_data[bus].bus_type == bus_type))
- return 1;
-
- return 0;
-}
-
-
-/*
- * Given a traditional ISA INT mask, return an APIC mask.
- */
-u_int
-isa_apic_mask(u_int isa_mask)
-{
- int isa_irq;
- int apic_pin;
-
-#if defined(SKIP_IRQ15_REDIRECT)
- if (isa_mask == (1 << 15)) {
- printf("skipping ISA IRQ15 redirect\n");
- return isa_mask;
- }
-#endif /* SKIP_IRQ15_REDIRECT */
-
- isa_irq = ffs(isa_mask); /* find its bit position */
- if (isa_irq == 0) /* doesn't exist */
- return 0;
- --isa_irq; /* make it zero based */
-
- apic_pin = isa_apic_irq(isa_irq); /* look for APIC connection */
- if (apic_pin == -1)
- return 0;
-
- return (1 << apic_pin); /* convert pin# to a mask */
-}
-
-
-/*
- * Determine which APIC pin an ISA/EISA INT is attached to.
- */
-#define INTTYPE(I) (io_apic_ints[(I)].int_type)
-#define INTPIN(I) (io_apic_ints[(I)].dst_apic_int)
-#define INTIRQ(I) (io_apic_ints[(I)].int_vector)
-#define INTAPIC(I) (ID_TO_IO(io_apic_ints[(I)].dst_apic_id))
-
-#define SRCBUSIRQ(I) (io_apic_ints[(I)].src_bus_irq)
-int
-isa_apic_irq(int isa_irq)
-{
- int intr;
-
- for (intr = 0; intr < nintrs; ++intr) { /* check each record */
- if (INTTYPE(intr) == 0) { /* standard INT */
- if (SRCBUSIRQ(intr) == isa_irq) {
- if (apic_int_is_bus_type(intr, ISA) ||
- apic_int_is_bus_type(intr, EISA)) {
- if (INTIRQ(intr) == 0xff)
- return -1; /* unassigned */
- return INTIRQ(intr); /* found */
- }
- }
- }
- }
- return -1; /* NOT found */
-}
-
-
-/*
- * Determine which APIC pin a PCI INT is attached to.
- */
-#define SRCBUSID(I) (io_apic_ints[(I)].src_bus_id)
-#define SRCBUSDEVICE(I) ((io_apic_ints[(I)].src_bus_irq >> 2) & 0x1f)
-#define SRCBUSLINE(I) (io_apic_ints[(I)].src_bus_irq & 0x03)
-int
-pci_apic_irq(int pciBus, int pciDevice, int pciInt)
-{
- int intr;
-
- --pciInt; /* zero based */
-
- for (intr = 0; intr < nintrs; ++intr) /* check each record */
- if ((INTTYPE(intr) == 0) /* standard INT */
- && (SRCBUSID(intr) == pciBus)
- && (SRCBUSDEVICE(intr) == pciDevice)
- && (SRCBUSLINE(intr) == pciInt)) /* a candidate IRQ */
- if (apic_int_is_bus_type(intr, PCI)) {
- if (INTIRQ(intr) == 0xff)
- allocate_apic_irq(intr);
- if (INTIRQ(intr) == 0xff)
- return -1; /* unassigned */
- return INTIRQ(intr); /* exact match */
- }
-
- return -1; /* NOT found */
-}
-
-int
-next_apic_irq(int irq)
-{
- int intr, ointr;
- int bus, bustype;
-
- bus = 0;
- bustype = 0;
- for (intr = 0; intr < nintrs; intr++) {
- if (INTIRQ(intr) != irq || INTTYPE(intr) != 0)
- continue;
- bus = SRCBUSID(intr);
- bustype = apic_bus_type(bus);
- if (bustype != ISA &&
- bustype != EISA &&
- bustype != PCI)
- continue;
- break;
- }
- if (intr >= nintrs) {
- return -1;
- }
- for (ointr = intr + 1; ointr < nintrs; ointr++) {
- if (INTTYPE(ointr) != 0)
- continue;
- if (bus != SRCBUSID(ointr))
- continue;
- if (bustype == PCI) {
- if (SRCBUSDEVICE(intr) != SRCBUSDEVICE(ointr))
- continue;
- if (SRCBUSLINE(intr) != SRCBUSLINE(ointr))
- continue;
- }
- if (bustype == ISA || bustype == EISA) {
- if (SRCBUSIRQ(intr) != SRCBUSIRQ(ointr))
- continue;
- }
- if (INTPIN(intr) == INTPIN(ointr))
- continue;
- break;
- }
- if (ointr >= nintrs) {
- return -1;
- }
- return INTIRQ(ointr);
-}
-#undef SRCBUSLINE
-#undef SRCBUSDEVICE
-#undef SRCBUSID
-#undef SRCBUSIRQ
-
-#undef INTPIN
-#undef INTIRQ
-#undef INTAPIC
-#undef INTTYPE
-
-
-/*
- * Reprogram the MB chipset to NOT redirect an ISA INTerrupt.
- *
- * XXX FIXME:
- * Exactly what this means is unclear at this point. It is a solution
- * for motherboards that redirect the MBIRQ0 pin. Generically a motherboard
- * could route any of the ISA INTs to upper (>15) IRQ values. But most would
- * NOT be redirected via MBIRQ0, thus "undirect()ing" them would NOT be an
- * option.
- */
-int
-undirect_isa_irq(int rirq)
-{
-#if defined(READY)
- if (bootverbose)
- printf("Freeing redirected ISA irq %d.\n", rirq);
- /** FIXME: tickle the MB redirector chip */
- return -1;
-#else
- if (bootverbose)
- printf("Freeing (NOT implemented) redirected ISA irq %d.\n", rirq);
- return 0;
-#endif /* READY */
-}
-
-
-/*
- * Reprogram the MB chipset to NOT redirect a PCI INTerrupt
- */
-int
-undirect_pci_irq(int rirq)
-{
-#if defined(READY)
- if (bootverbose)
- printf("Freeing redirected PCI irq %d.\n", rirq);
-
- /** FIXME: tickle the MB redirector chip */
- return -1;
-#else
- if (bootverbose)
- printf("Freeing (NOT implemented) redirected PCI irq %d.\n",
- rirq);
- return 0;
-#endif /* READY */
-}
-
-
-/*
- * given a bus ID, return:
- * the bus type if found
- * -1 if NOT found
- */
-int
-apic_bus_type(int id)
-{
- int x;
-
- for (x = 0; x < mp_nbusses; ++x)
- if (bus_data[x].bus_id == id)
- return bus_data[x].bus_type;
-
- return -1;
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated src bus ID if found
- * -1 if NOT found
- */
-int
-apic_src_bus_id(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].src_bus_id);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated src bus IRQ if found
- * -1 if NOT found
- */
-int
-apic_src_bus_irq(int apic, int pin)
-{
- int x;
-
- for (x = 0; x < nintrs; x++)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].src_bus_irq);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated INTerrupt type if found
- * -1 if NOT found
- */
-int
-apic_int_type(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].int_type);
-
- return -1; /* NOT found */
-}
-
-int
-apic_irq(int apic, int pin)
-{
- int x;
- int res;
-
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int)) {
- res = io_apic_ints[x].int_vector;
- if (res == 0xff)
- return -1;
- if (apic != int_to_apicintpin[res].ioapic)
- panic("apic_irq: inconsistent table");
- if (pin != int_to_apicintpin[res].int_pin)
- panic("apic_irq inconsistent table (2)");
- return res;
- }
- return -1;
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated trigger mode if found
- * -1 if NOT found
- */
-int
-apic_trigger(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return ((io_apic_ints[x].int_flags >> 2) & 0x03);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated 'active' level if found
- * -1 if NOT found
- */
-int
-apic_polarity(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].int_flags & 0x03);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * set data according to MP defaults
- * FIXME: probably not complete yet...
- */
-static void
-default_mp_table(int type)
-{
- int ap_cpu_id;
-#if defined(APIC_IO)
- int io_apic_id;
- int pin;
-#endif /* APIC_IO */
-
-#if 0
- printf(" MP default config type: %d\n", type);
- switch (type) {
- case 1:
- printf(" bus: ISA, APIC: 82489DX\n");
- break;
- case 2:
- printf(" bus: EISA, APIC: 82489DX\n");
- break;
- case 3:
- printf(" bus: EISA, APIC: 82489DX\n");
- break;
- case 4:
- printf(" bus: MCA, APIC: 82489DX\n");
- break;
- case 5:
- printf(" bus: ISA+PCI, APIC: Integrated\n");
- break;
- case 6:
- printf(" bus: EISA+PCI, APIC: Integrated\n");
- break;
- case 7:
- printf(" bus: MCA+PCI, APIC: Integrated\n");
- break;
- default:
- printf(" future type\n");
- break;
- /* NOTREACHED */
- }
-#endif /* 0 */
-
- boot_cpu_id = (lapic.id & APIC_ID_MASK) >> 24;
- ap_cpu_id = (boot_cpu_id == 0) ? 1 : 0;
-
- /* BSP */
- CPU_TO_ID(0) = boot_cpu_id;
- ID_TO_CPU(boot_cpu_id) = 0;
-
- /* one and only AP */
- CPU_TO_ID(1) = ap_cpu_id;
- ID_TO_CPU(ap_cpu_id) = 1;
-
-#if defined(APIC_IO)
- /* one and only IO APIC */
- io_apic_id = (io_apic_read(0, IOAPIC_ID) & APIC_ID_MASK) >> 24;
-
- /*
- * sanity check, refer to MP spec section 3.6.6, last paragraph
- * necessary as some hardware isn't properly setting up the IO APIC
- */
-#if defined(REALLY_ANAL_IOAPICID_VALUE)
- if (io_apic_id != 2) {
-#else
- if ((io_apic_id == 0) || (io_apic_id == 1) || (io_apic_id == 15)) {
-#endif /* REALLY_ANAL_IOAPICID_VALUE */
- io_apic_set_id(0, 2);
- io_apic_id = 2;
- }
- IO_TO_ID(0) = io_apic_id;
- ID_TO_IO(io_apic_id) = 0;
-#endif /* APIC_IO */
-
- /* fill out bus entries */
- switch (type) {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- bus_data[0].bus_id = default_data[type - 1][1];
- bus_data[0].bus_type = default_data[type - 1][2];
- bus_data[1].bus_id = default_data[type - 1][3];
- bus_data[1].bus_type = default_data[type - 1][4];
- break;
-
- /* case 4: case 7: MCA NOT supported */
- default: /* illegal/reserved */
- panic("BAD default MP config: %d", type);
- /* NOTREACHED */
- }
-
-#if defined(APIC_IO)
- /* general cases from MP v1.4, table 5-2 */
- for (pin = 0; pin < 16; ++pin) {
- io_apic_ints[pin].int_type = 0;
- io_apic_ints[pin].int_flags = 0x05; /* edge/active-hi */
- io_apic_ints[pin].src_bus_id = 0;
- io_apic_ints[pin].src_bus_irq = pin; /* IRQ2 caught below */
- io_apic_ints[pin].dst_apic_id = io_apic_id;
- io_apic_ints[pin].dst_apic_int = pin; /* 1-to-1 */
- }
-
- /* special cases from MP v1.4, table 5-2 */
- if (type == 2) {
- io_apic_ints[2].int_type = 0xff; /* N/C */
- io_apic_ints[13].int_type = 0xff; /* N/C */
-#if !defined(APIC_MIXED_MODE)
- /** FIXME: ??? */
- panic("sorry, can't support type 2 default yet");
-#endif /* APIC_MIXED_MODE */
- }
- else
- io_apic_ints[2].src_bus_irq = 0; /* ISA IRQ0 is on APIC INT 2 */
-
- if (type == 7)
- io_apic_ints[0].int_type = 0xff; /* N/C */
- else
- io_apic_ints[0].int_type = 3; /* vectored 8259 */
-#endif /* APIC_IO */
-}
-
-
-/*
- * start each AP in our list
- */
-static int
-start_all_aps(u_int boot_addr)
-{
- int x, i, pg;
-#ifndef PC98
- u_char mpbiosreason;
-#endif
- u_long mpbioswarmvec;
- struct pcpu *pc;
- char *stack;
- uintptr_t kptbase;
-
- POSTCODE(START_ALL_APS_POST);
-
- mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN);
-
- /* initialize BSP's local APIC */
- apic_initialize();
- bsp_apic_ready = 1;
-
- /* install the AP 1st level boot code */
- install_ap_tramp(boot_addr);
-
-
- /* save the current value of the warm-start vector */
- mpbioswarmvec = *((u_long *) WARMBOOT_OFF);
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- mpbiosreason = inb(CMOS_DATA);
-#endif
-
- /* set up temporary P==V mapping for AP boot */
- /* XXX this is a hack, we should boot the AP on its own stack/PTD */
- kptbase = (uintptr_t)(void *)KPTphys;
- for (x = 0; x < NKPT; x++)
- PTD[x] = (pd_entry_t)(PG_V | PG_RW |
- ((kptbase + x * PAGE_SIZE) & PG_FRAME));
- invltlb();
-
- /* start each AP */
- for (x = 1; x <= mp_naps; ++x) {
-
- /* This is a bit verbose, it will go away soon. */
-
- /* first page of AP's private space */
- pg = x * i386_btop(sizeof(struct privatespace));
-
- /* allocate a new private data page */
- pc = (struct pcpu *)kmem_alloc(kernel_map, PAGE_SIZE);
-
- /* wire it into the private page table page */
- SMPpt[pg] = (pt_entry_t)(PG_V | PG_RW | vtophys(pc));
-
- /* allocate and set up an idle stack data page */
- stack = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE); /* XXXKSE */
- for (i = 0; i < KSTACK_PAGES; i++)
- SMPpt[pg + 1 + i] = (pt_entry_t)
- (PG_V | PG_RW | vtophys(PAGE_SIZE * i + stack));
-
- /* prime data page for it to use */
- pcpu_init(pc, x, sizeof(struct pcpu));
-
- /* setup a vector to our boot code */
- *((volatile u_short *) WARMBOOT_OFF) = WARMBOOT_TARGET;
- *((volatile u_short *) WARMBOOT_SEG) = (boot_addr >> 4);
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- outb(CMOS_DATA, BIOS_WARM); /* 'warm-start' */
-#endif
-
- bootSTK = &SMP_prvspace[x].idlekstack[KSTACK_PAGES * PAGE_SIZE];
- bootAP = x;
-
- /* attempt to start the Application Processor */
- CHECK_INIT(99); /* setup checkpoints */
- if (!start_ap(x, boot_addr)) {
- printf("AP #%d (PHY# %d) failed!\n", x, CPU_TO_ID(x));
- CHECK_PRINT("trace"); /* show checkpoints */
- /* better panic as the AP may be running loose */
- printf("panic y/n? [y] ");
- if (cngetc() != 'n')
- panic("bye-bye");
- }
- CHECK_PRINT("trace"); /* show checkpoints */
-
- /* record its version info */
- cpu_apic_versions[x] = cpu_apic_versions[0];
-
- all_cpus |= (1 << x); /* record AP in CPU map */
- }
-
- /* build our map of 'other' CPUs */
- PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
-
- /* fill in our (BSP) APIC version */
- cpu_apic_versions[0] = lapic.version;
-
- /* restore the warmstart vector */
- *(u_long *) WARMBOOT_OFF = mpbioswarmvec;
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- outb(CMOS_DATA, mpbiosreason);
-#endif
-
- /*
- * Set up the idle context for the BSP. Similar to above except
- * that some was done by locore, some by pmap.c and some is implicit
- * because the BSP is cpu#0 and the page is initially zero, and also
- * because we can refer to variables by name on the BSP..
- */
-
- /* Allocate and setup BSP idle stack */
- stack = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE);
- for (i = 0; i < KSTACK_PAGES; i++)
- SMPpt[1 + i] = (pt_entry_t)
- (PG_V | PG_RW | vtophys(PAGE_SIZE * i + stack));
-
- for (x = 0; x < NKPT; x++)
- PTD[x] = 0;
- pmap_set_opt();
-
- /* number of APs actually started */
- return mp_ncpus - 1;
-}
-
-
-/*
- * load the 1st level AP boot code into base memory.
- */
-
-/* targets for relocation */
-extern void bigJump(void);
-extern void bootCodeSeg(void);
-extern void bootDataSeg(void);
-extern void MPentry(void);
-extern u_int MP_GDT;
-extern u_int mp_gdtbase;
-
-static void
-install_ap_tramp(u_int boot_addr)
-{
- int x;
- int size = *(int *) ((u_long) & bootMP_size);
- u_char *src = (u_char *) ((u_long) bootMP);
- u_char *dst = (u_char *) boot_addr + KERNBASE;
- u_int boot_base = (u_int) bootMP;
- u_int8_t *dst8;
- u_int16_t *dst16;
- u_int32_t *dst32;
-
- POSTCODE(INSTALL_AP_TRAMP_POST);
-
- for (x = 0; x < size; ++x)
- *dst++ = *src++;
-
- /*
- * modify addresses in code we just moved to basemem. unfortunately we
- * need fairly detailed info about mpboot.s for this to work. changes
- * to mpboot.s might require changes here.
- */
-
- /* boot code is located in KERNEL space */
- dst = (u_char *) boot_addr + KERNBASE;
-
- /* modify the lgdt arg */
- dst32 = (u_int32_t *) (dst + ((u_int) & mp_gdtbase - boot_base));
- *dst32 = boot_addr + ((u_int) & MP_GDT - boot_base);
-
- /* modify the ljmp target for MPentry() */
- dst32 = (u_int32_t *) (dst + ((u_int) bigJump - boot_base) + 1);
- *dst32 = ((u_int) MPentry - KERNBASE);
-
- /* modify the target for boot code segment */
- dst16 = (u_int16_t *) (dst + ((u_int) bootCodeSeg - boot_base));
- dst8 = (u_int8_t *) (dst16 + 1);
- *dst16 = (u_int) boot_addr & 0xffff;
- *dst8 = ((u_int) boot_addr >> 16) & 0xff;
-
- /* modify the target for boot data segment */
- dst16 = (u_int16_t *) (dst + ((u_int) bootDataSeg - boot_base));
- dst8 = (u_int8_t *) (dst16 + 1);
- *dst16 = (u_int) boot_addr & 0xffff;
- *dst8 = ((u_int) boot_addr >> 16) & 0xff;
-}
-
-
-/*
- * this function starts the AP (application processor) identified
- * by the APIC ID 'physicalCpu'. It does quite a "song and dance"
- * to accomplish this. This is necessary because of the nuances
- * of the different hardware we might encounter. It ain't pretty,
- * but it seems to work.
- */
-static int
-start_ap(int logical_cpu, u_int boot_addr)
-{
- int physical_cpu;
- int vector;
- int cpus;
- u_long icr_lo, icr_hi;
-
- POSTCODE(START_AP_POST);
-
- /* get the PHYSICAL APIC ID# */
- physical_cpu = CPU_TO_ID(logical_cpu);
-
- /* calculate the vector */
- vector = (boot_addr >> 12) & 0xff;
-
- /* used as a watchpoint to signal AP startup */
- cpus = mp_ncpus;
-
- /*
- * first we do an INIT/RESET IPI this INIT IPI might be run, reseting
- * and running the target CPU. OR this INIT IPI might be latched (P5
- * bug), CPU waiting for STARTUP IPI. OR this INIT IPI might be
- * ignored.
- */
-
- /* setup the address for the target AP */
- icr_hi = lapic.icr_hi & ~APIC_ID_MASK;
- icr_hi |= (physical_cpu << 24);
- lapic.icr_hi = icr_hi;
-
- /* do an INIT IPI: assert RESET */
- icr_lo = lapic.icr_lo & 0xfff00000;
- lapic.icr_lo = icr_lo | 0x0000c500;
-
- /* wait for pending status end */
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
-
- /* do an INIT IPI: deassert RESET */
- lapic.icr_lo = icr_lo | 0x00008500;
-
- /* wait for pending status end */
- u_sleep(10000); /* wait ~10mS */
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
-
- /*
- * next we do a STARTUP IPI: the previous INIT IPI might still be
- * latched, (P5 bug) this 1st STARTUP would then terminate
- * immediately, and the previously started INIT IPI would continue. OR
- * the previous INIT IPI has already run. and this STARTUP IPI will
- * run. OR the previous INIT IPI was ignored. and this STARTUP IPI
- * will run.
- */
-
- /* do a STARTUP IPI */
- lapic.icr_lo = icr_lo | 0x00000600 | vector;
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
- u_sleep(200); /* wait ~200uS */
-
- /*
- * finally we do a 2nd STARTUP IPI: this 2nd STARTUP IPI should run IF
- * the previous STARTUP IPI was cancelled by a latched INIT IPI. OR
- * this STARTUP IPI will be ignored, as only ONE STARTUP IPI is
- * recognized after hardware RESET or INIT IPI.
- */
-
- lapic.icr_lo = icr_lo | 0x00000600 | vector;
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
- u_sleep(200); /* wait ~200uS */
-
- /* wait for it to start */
- set_apic_timer(5000000);/* == 5 seconds */
- while (read_apic_timer())
- if (mp_ncpus > cpus)
- return 1; /* return SUCCESS */
-
- return 0; /* return FAILURE */
-}
-
-#if defined(APIC_IO)
-
-#ifdef COUNT_XINVLTLB_HITS
-u_int xhits_gbl[MAXCPU];
-u_int xhits_pg[MAXCPU];
-u_int xhits_rng[MAXCPU];
-SYSCTL_NODE(_debug, OID_AUTO, xhits, CTLFLAG_RW, 0, "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, global, CTLFLAG_RW, &xhits_gbl,
- sizeof(xhits_gbl), "IU", "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, page, CTLFLAG_RW, &xhits_pg,
- sizeof(xhits_pg), "IU", "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, range, CTLFLAG_RW, &xhits_rng,
- sizeof(xhits_rng), "IU", "");
-
-u_int ipi_global;
-u_int ipi_page;
-u_int ipi_range;
-u_int ipi_range_size;
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_global, CTLFLAG_RW, &ipi_global, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_page, CTLFLAG_RW, &ipi_page, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range, CTLFLAG_RW, &ipi_range, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range_size, CTLFLAG_RW, &ipi_range_size,
- 0, "");
-
-u_int ipi_masked_global;
-u_int ipi_masked_page;
-u_int ipi_masked_range;
-u_int ipi_masked_range_size;
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_global, CTLFLAG_RW,
- &ipi_masked_global, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_page, CTLFLAG_RW,
- &ipi_masked_page, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range, CTLFLAG_RW,
- &ipi_masked_range, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range_size, CTLFLAG_RW,
- &ipi_masked_range_size, 0, "");
-#endif
-
-/*
- * Flush the TLB on all other CPU's
- */
-static void
-smp_tlb_shootdown(u_int vector, vm_offset_t addr1, vm_offset_t addr2)
-{
- u_int ncpu;
- register_t eflags;
-
- ncpu = mp_ncpus - 1; /* does not shootdown self */
- if (ncpu < 1)
- return; /* no other cpus */
- eflags = read_eflags();
- if ((eflags & PSL_I) == 0)
- panic("absolutely cannot call smp_ipi_shootdown with interrupts already disabled");
- mtx_lock_spin(&smp_tlb_mtx);
- smp_tlb_addr1 = addr1;
- smp_tlb_addr2 = addr2;
- atomic_store_rel_int(&smp_tlb_wait, 0);
- ipi_all_but_self(vector);
- while (smp_tlb_wait < ncpu)
- ia32_pause();
- mtx_unlock_spin(&smp_tlb_mtx);
-}
-
-/*
- * This is about as magic as it gets. fortune(1) has got similar code
- * for reversing bits in a word. Who thinks up this stuff??
- *
- * Yes, it does appear to be consistently faster than:
- * while (i = ffs(m)) {
- * m >>= i;
- * bits++;
- * }
- * and
- * while (lsb = (m & -m)) { // This is magic too
- * m &= ~lsb; // or: m ^= lsb
- * bits++;
- * }
- * Both of these latter forms do some very strange things on gcc-3.1 with
- * -mcpu=pentiumpro and/or -march=pentiumpro and/or -O or -O2.
- * There is probably an SSE or MMX popcnt instruction.
- *
- * I wonder if this should be in libkern?
- *
- * XXX Stop the presses! Another one:
- * static __inline u_int32_t
- * popcnt1(u_int32_t v)
- * {
- * v -= ((v >> 1) & 0x55555555);
- * v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
- * v = (v + (v >> 4)) & 0x0F0F0F0F;
- * return (v * 0x01010101) >> 24;
- * }
- * The downside is that it has a multiply. With a pentium3 with
- * -mcpu=pentiumpro and -march=pentiumpro then gcc-3.1 will use
- * an imull, and in that case it is faster. In most other cases
- * it appears slightly slower.
- */
-static __inline u_int32_t
-popcnt(u_int32_t m)
-{
-
- m = (m & 0x55555555) + ((m & 0xaaaaaaaa) >> 1);
- m = (m & 0x33333333) + ((m & 0xcccccccc) >> 2);
- m = (m & 0x0f0f0f0f) + ((m & 0xf0f0f0f0) >> 4);
- m = (m & 0x00ff00ff) + ((m & 0xff00ff00) >> 8);
- m = (m & 0x0000ffff) + ((m & 0xffff0000) >> 16);
- return m;
-}
-
-static void
-smp_targeted_tlb_shootdown(u_int mask, u_int vector, vm_offset_t addr1, vm_offset_t addr2)
-{
- int ncpu, othercpus;
- register_t eflags;
-
- othercpus = mp_ncpus - 1;
- if (mask == (u_int)-1) {
- ncpu = othercpus;
- if (ncpu < 1)
- return;
- } else {
- /* XXX there should be a pcpu self mask */
- mask &= ~(1 << PCPU_GET(cpuid));
- if (mask == 0)
- return;
- ncpu = popcnt(mask);
- if (ncpu > othercpus) {
- /* XXX this should be a panic offence */
- printf("SMP: tlb shootdown to %d other cpus (only have %d)\n",
- ncpu, othercpus);
- ncpu = othercpus;
- }
- /* XXX should be a panic, implied by mask == 0 above */
- if (ncpu < 1)
- return;
- }
- eflags = read_eflags();
- if ((eflags & PSL_I) == 0)
- panic("absolutely cannot call smp_targeted_ipi_shootdown with interrupts already disabled");
- mtx_lock_spin(&smp_tlb_mtx);
- smp_tlb_addr1 = addr1;
- smp_tlb_addr2 = addr2;
- atomic_store_rel_int(&smp_tlb_wait, 0);
- if (mask == (u_int)-1)
- ipi_all_but_self(vector);
- else
- ipi_selected(mask, vector);
- while (smp_tlb_wait < ncpu)
- ia32_pause();
- mtx_unlock_spin(&smp_tlb_mtx);
-}
-#endif
-
-void
-smp_invltlb(void)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLTLB, 0, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_global++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_invlpg(vm_offset_t addr)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLPG, addr, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_page++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_invlpg_range(vm_offset_t addr1, vm_offset_t addr2)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLRNG, addr1, addr2);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_range++;
- ipi_range_size += (addr2 - addr1) / PAGE_SIZE;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invltlb(u_int mask)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLTLB, 0, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_global++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invlpg(u_int mask, vm_offset_t addr)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLPG, addr, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_page++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invlpg_range(u_int mask, vm_offset_t addr1, vm_offset_t addr2)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLRNG, addr1, addr2);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_range++;
- ipi_masked_range_size += (addr2 - addr1) / PAGE_SIZE;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-
-/*
- * This is called once the rest of the system is up and running and we're
- * ready to let the AP's out of the pen.
- */
-void
-ap_init(void)
-{
- u_int apic_id;
-
- /* spin until all the AP's are ready */
- while (!aps_ready)
- ia32_pause();
-
- /* BSP may have changed PTD while we were waiting */
- invltlb();
-
-#if defined(I586_CPU) && !defined(NO_F00F_HACK)
- lidt(&r_idt);
-#endif
-
- /* set up CPU registers and state */
- cpu_setregs();
-
- /* set up FPU state on the AP */
- npxinit(__INITIAL_NPXCW__);
-
- /* set up SSE registers */
- enable_sse();
-
- /* A quick check from sanity claus */
- apic_id = (apic_id_to_logical[(lapic.id & 0x0f000000) >> 24]);
- if (PCPU_GET(cpuid) != apic_id) {
- printf("SMP: cpuid = %d\n", PCPU_GET(cpuid));
- printf("SMP: apic_id = %d\n", apic_id);
- printf("PTD[MPPTDI] = %#jx\n", (uintmax_t)PTD[MPPTDI]);
- panic("cpuid mismatch! boom!!");
- }
-
- /* Init local apic for irq's */
- apic_initialize();
-
- /* Set memory range attributes for this CPU to match the BSP */
- mem_range_AP_init();
-
- mtx_lock_spin(&ap_boot_mtx);
-
- smp_cpus++;
-
- CTR1(KTR_SMP, "SMP: AP CPU #%d Launched", PCPU_GET(cpuid));
- printf("SMP: AP CPU #%d Launched!\n", PCPU_GET(cpuid));
-
- /* Build our map of 'other' CPUs. */
- PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
-
- if (bootverbose)
- apic_dump("ap_init()");
-
- if (smp_cpus == mp_ncpus) {
- /* enable IPI's, tlb shootdown, freezes etc */
- atomic_store_rel_int(&smp_started, 1);
- smp_active = 1; /* historic */
- }
-
- mtx_unlock_spin(&ap_boot_mtx);
-
- /* wait until all the AP's are up */
- while (smp_started == 0)
- ia32_pause();
-
- /* ok, now grab sched_lock and enter the scheduler */
- mtx_lock_spin(&sched_lock);
-
- binuptime(PCPU_PTR(switchtime));
- PCPU_SET(switchticks, ticks);
-
- cpu_throw(NULL, choosethread()); /* doesn't return */
-
- panic("scheduler returned us to %s", __func__);
-}
-
-/*
- * For statclock, we send an IPI to all CPU's to have them call this
- * function.
- *
- * WARNING! unpend() will call statclock() directly and skip this
- * routine.
- */
-void
-forwarded_statclock(struct clockframe frame)
-{
-
- if (profprocs != 0)
- profclock(&frame);
- if (pscnt == psdiv)
- statclock(&frame);
-}
-
-void
-forward_statclock(void)
-{
- int map;
-
- CTR0(KTR_SMP, "forward_statclock");
-
- if (!smp_started || cold || panicstr)
- return;
-
- map = PCPU_GET(other_cpus) & ~stopped_cpus ;
- if (map != 0)
- ipi_selected(map, IPI_STATCLOCK);
-}
-
-/*
- * For each hardclock(), we send an IPI to all other CPU's to have them
- * execute this function. It would be nice to reduce contention on
- * sched_lock if we could simply peek at the CPU to determine the user/kernel
- * state and call hardclock_process() on the CPU receiving the clock interrupt
- * and then just use a simple IPI to handle any ast's if needed.
- *
- * WARNING! unpend() will call hardclock_process() directly and skip this
- * routine.
- */
-void
-forwarded_hardclock(struct clockframe frame)
-{
-
- hardclock_process(&frame);
-}
-
-void
-forward_hardclock(void)
-{
- u_int map;
-
- CTR0(KTR_SMP, "forward_hardclock");
-
- if (!smp_started || cold || panicstr)
- return;
-
- map = PCPU_GET(other_cpus) & ~stopped_cpus ;
- if (map != 0)
- ipi_selected(map, IPI_HARDCLOCK);
-}
-
-#ifdef APIC_INTR_REORDER
-/*
- * Maintain mapping from softintr vector to isr bit in local apic.
- */
-void
-set_lapic_isrloc(int intr, int vector)
-{
- if (intr < 0 || intr > 32)
- panic("set_apic_isrloc: bad intr argument: %d",intr);
- if (vector < ICU_OFFSET || vector > 255)
- panic("set_apic_isrloc: bad vector argument: %d",vector);
- apic_isrbit_location[intr].location = &lapic.isr0 + ((vector>>5)<<2);
- apic_isrbit_location[intr].bit = (1<<(vector & 31));
-}
-#endif
-
-/*
- * send an IPI to a set of cpus.
- */
-void
-ipi_selected(u_int32_t cpus, u_int ipi)
-{
-
- CTR3(KTR_SMP, "%s: cpus: %x ipi: %x", __func__, cpus, ipi);
- selected_apic_ipi(cpus, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI INTerrupt containing 'vector' to all CPUs, including myself
- */
-void
-ipi_all(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_ALLISELF, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI to all CPUs EXCEPT myself
- */
-void
-ipi_all_but_self(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_ALLESELF, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI to myself
- */
-void
-ipi_self(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_SELF, ipi, APIC_DELMODE_FIXED);
-}
-
-static void
-release_aps(void *dummy __unused)
-{
-
- if (mp_ncpus == 1)
- return;
- mtx_lock_spin(&sched_lock);
- atomic_store_rel_int(&aps_ready, 1);
- while (smp_started == 0)
- ia32_pause();
- mtx_unlock_spin(&sched_lock);
-}
-
-SYSINIT(start_aps, SI_SUB_SMP, SI_ORDER_FIRST, release_aps, NULL);
-
-static int hlt_cpus_mask;
-static int hlt_logical_cpus = 1;
-static struct sysctl_ctx_list logical_cpu_clist;
-
-static int
-sysctl_hlt_cpus(SYSCTL_HANDLER_ARGS)
-{
- u_int mask;
- int error;
-
- mask = hlt_cpus_mask;
- error = sysctl_handle_int(oidp, &mask, 0, req);
- if (error || !req->newptr)
- return (error);
-
- if (logical_cpus_mask != 0 &&
- (mask & logical_cpus_mask) == logical_cpus_mask)
- hlt_logical_cpus = 1;
- else
- hlt_logical_cpus = 0;
-
- if ((mask & all_cpus) == all_cpus)
- mask &= ~(1<<0);
- hlt_cpus_mask = mask;
- return (error);
-}
-SYSCTL_PROC(_machdep, OID_AUTO, hlt_cpus, CTLTYPE_INT|CTLFLAG_RW,
- 0, 0, sysctl_hlt_cpus, "IU", "");
-
-static int
-sysctl_hlt_logical_cpus(SYSCTL_HANDLER_ARGS)
-{
- int disable, error;
-
- disable = hlt_logical_cpus;
- error = sysctl_handle_int(oidp, &disable, 0, req);
- if (error || !req->newptr)
- return (error);
-
- if (disable)
- hlt_cpus_mask |= logical_cpus_mask;
- else
- hlt_cpus_mask &= ~logical_cpus_mask;
-
- if ((hlt_cpus_mask & all_cpus) == all_cpus)
- hlt_cpus_mask &= ~(1<<0);
-
- hlt_logical_cpus = disable;
- return (error);
-}
-
-static void
-cpu_hlt_setup(void *dummy __unused)
-{
-
- if (logical_cpus_mask != 0) {
- TUNABLE_INT_FETCH("machdep.hlt_logical_cpus",
- &hlt_logical_cpus);
- sysctl_ctx_init(&logical_cpu_clist);
- SYSCTL_ADD_PROC(&logical_cpu_clist,
- SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
- "hlt_logical_cpus", CTLTYPE_INT|CTLFLAG_RW, 0, 0,
- sysctl_hlt_logical_cpus, "IU", "");
- SYSCTL_ADD_UINT(&logical_cpu_clist,
- SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
- "logical_cpus_mask", CTLTYPE_INT|CTLFLAG_RD,
- &logical_cpus_mask, 0, "");
-
- if (hlt_logical_cpus)
- hlt_cpus_mask |= logical_cpus_mask;
- }
-}
-SYSINIT(cpu_hlt, SI_SUB_SMP, SI_ORDER_ANY, cpu_hlt_setup, NULL);
-
-int
-mp_grab_cpu_hlt(void)
-{
- u_int mask = PCPU_GET(cpumask);
- int retval;
-
- retval = mask & hlt_cpus_mask;
- while (mask & hlt_cpus_mask)
- __asm __volatile("sti; hlt" : : : "memory");
- return (retval);
-}
diff --git a/sys/amd64/amd64/mpboot.S b/sys/amd64/amd64/mpboot.S
deleted file mode 100644
index e2450073a3a5..000000000000
--- a/sys/amd64/amd64/mpboot.S
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- * Copyright (c) 1995, Jack F. Vogel
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Jack F. Vogel
- * 4. The name of the developer 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 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.
- *
- * mpboot.s: FreeBSD machine support for the Intel MP Spec
- * multiprocessor systems.
- *
- * $FreeBSD$
- */
-
-#include <machine/asmacros.h> /* miscellaneous asm macros */
-#include <machine/apic.h>
-#include <machine/specialreg.h>
-
-#include "assym.s"
-
-#define R(x) ((x)-KERNBASE)
-
-/*
- * this code MUST be enabled here and in mp_machdep.c
- * it follows the very early stages of AP boot by placing values in CMOS ram.
- * it NORMALLY will never be needed and thus the primitive method for enabling.
- *
-#define CHECK_POINTS
- */
-
-#if defined(CHECK_POINTS) && !defined(PC98)
-
-#define CMOS_REG (0x70)
-#define CMOS_DATA (0x71)
-
-#define CHECKPOINT(A,D) \
- movb $(A),%al ; \
- outb %al,$CMOS_REG ; \
- movb $(D),%al ; \
- outb %al,$CMOS_DATA
-
-#else
-
-#define CHECKPOINT(A,D)
-
-#endif /* CHECK_POINTS */
-
-
-/*
- * the APs enter here from their trampoline code (bootMP, below)
- */
- .p2align 4
-
-NON_GPROF_ENTRY(MPentry)
- CHECKPOINT(0x36, 3)
- /* Now enable paging mode */
-#ifdef PAE
- movl R(IdlePDPT), %eax
- movl %eax, %cr3
- movl %cr4, %eax
- orl $CR4_PAE, %eax
- movl %eax, %cr4
-#else
- movl R(IdlePTD), %eax
- movl %eax,%cr3
-#endif
- movl %cr0,%eax
- orl $CR0_PE|CR0_PG,%eax /* enable paging */
- movl %eax,%cr0 /* let the games begin! */
- movl bootSTK,%esp /* boot stack end loc. */
-
- pushl $mp_begin /* jump to high mem */
- ret
-
- /*
- * Wait for the booting CPU to signal startup
- */
-mp_begin: /* now running relocated at KERNBASE */
- CHECKPOINT(0x37, 4)
- call init_secondary /* load i386 tables */
- CHECKPOINT(0x38, 5)
-
- /*
- * If the [BSP] CPU has support for VME, turn it on.
- */
- testl $CPUID_VME, cpu_feature /* XXX WRONG! BSP! */
- jz 1f
- movl %cr4, %eax
- orl $CR4_VME, %eax
- movl %eax, %cr4
-1:
-
- /* disable the APIC, just to be SURE */
- movl lapic+LA_SVR, %eax /* get spurious vector reg. */
- andl $~APIC_SVR_SWEN, %eax /* clear software enable bit */
- movl %eax, lapic+LA_SVR
-
- /* signal our startup to the BSP */
- movl lapic+LA_VER, %eax /* our version reg contents */
- movl %eax, cpu_apic_versions /* into [ 0 ] */
- incl mp_ncpus /* signal BSP */
-
- CHECKPOINT(0x39, 6)
-
- /* Now, let's prepare for some REAL WORK :-) This doesn't return. */
- call ap_init
-
-/*
- * This is the embedded trampoline or bootstrap that is
- * copied into 'real-mode' low memory, it is where the
- * secondary processor "wakes up". When it is executed
- * the processor will eventually jump into the routine
- * MPentry, which resides in normal kernel text above
- * 1Meg. -jackv
- */
-
- .data
- ALIGN_DATA /* just to be sure */
-
-BOOTMP1:
-
-NON_GPROF_ENTRY(bootMP)
- .code16
- cli
- CHECKPOINT(0x34, 1)
- /* First guarantee a 'clean slate' */
- xorl %eax, %eax
- movl %eax, %ebx
- movl %eax, %ecx
- movl %eax, %edx
- movl %eax, %esi
- movl %eax, %edi
-
- /* set up data segments */
- mov %cs, %ax
- mov %ax, %ds
- mov %ax, %es
- mov %ax, %fs
- mov %ax, %gs
- mov %ax, %ss
- mov $(boot_stk-bootMP), %esp
-
- /* Now load the global descriptor table */
- lgdt MP_GDTptr-bootMP
-
- /* Enable protected mode */
- movl %cr0, %eax
- orl $CR0_PE, %eax
- movl %eax, %cr0
-
- /*
- * make intrasegment jump to flush the processor pipeline and
- * reload CS register
- */
- pushl $0x18
- pushl $(protmode-bootMP)
- lretl
-
- .code32
-protmode:
- CHECKPOINT(0x35, 2)
-
- /*
- * we are NOW running for the first time with %eip
- * having the full physical address, BUT we still
- * are using a segment descriptor with the origin
- * not matching the booting kernel.
- *
- * SO NOW... for the BIG Jump into kernel's segment
- * and physical text above 1 Meg.
- */
- mov $0x10, %ebx
- movw %bx, %ds
- movw %bx, %es
- movw %bx, %fs
- movw %bx, %gs
- movw %bx, %ss
-
- .globl bigJump
-bigJump:
- /* this will be modified by mpInstallTramp() */
- ljmp $0x08, $0 /* far jmp to MPentry() */
-
-dead: hlt /* We should never get here */
- jmp dead
-
-/*
- * MP boot strap Global Descriptor Table
- */
- .p2align 4
- .globl MP_GDT
- .globl bootCodeSeg
- .globl bootDataSeg
-MP_GDT:
-
-nulldesc: /* offset = 0x0 */
-
- .word 0x0
- .word 0x0
- .byte 0x0
- .byte 0x0
- .byte 0x0
- .byte 0x0
-
-kernelcode: /* offset = 0x08 */
-
- .word 0xffff /* segment limit 0..15 */
- .word 0x0000 /* segment base 0..15 */
- .byte 0x0 /* segment base 16..23; set for 0K */
- .byte 0x9f /* flags; Type */
- .byte 0xcf /* flags; Limit */
- .byte 0x0 /* segment base 24..32 */
-
-kerneldata: /* offset = 0x10 */
-
- .word 0xffff /* segment limit 0..15 */
- .word 0x0000 /* segment base 0..15 */
- .byte 0x0 /* segment base 16..23; set for 0k */
- .byte 0x93 /* flags; Type */
- .byte 0xcf /* flags; Limit */
- .byte 0x0 /* segment base 24..32 */
-
-bootcode: /* offset = 0x18 */
-
- .word 0xffff /* segment limit 0..15 */
-bootCodeSeg: /* this will be modified by mpInstallTramp() */
- .word 0x0000 /* segment base 0..15 */
- .byte 0x00 /* segment base 16...23; set for 0x000xx000 */
- .byte 0x9e /* flags; Type */
- .byte 0xcf /* flags; Limit */
- .byte 0x0 /*segment base 24..32 */
-
-bootdata: /* offset = 0x20 */
-
- .word 0xffff
-bootDataSeg: /* this will be modified by mpInstallTramp() */
- .word 0x0000 /* segment base 0..15 */
- .byte 0x00 /* segment base 16...23; set for 0x000xx000 */
- .byte 0x92
- .byte 0xcf
- .byte 0x0
-
-/*
- * GDT pointer for the lgdt call
- */
- .globl mp_gdtbase
-
-MP_GDTptr:
-mp_gdtlimit:
- .word 0x0028
-mp_gdtbase: /* this will be modified by mpInstallTramp() */
- .long 0
-
- .space 0x100 /* space for boot_stk - 1st temporary stack */
-boot_stk:
-
-BOOTMP2:
- .globl bootMP_size
-bootMP_size:
- .long BOOTMP2 - BOOTMP1
diff --git a/sys/amd64/amd64/mptable.c b/sys/amd64/amd64/mptable.c
deleted file mode 100644
index d630bd583aa4..000000000000
--- a/sys/amd64/amd64/mptable.c
+++ /dev/null
@@ -1,2839 +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$
- */
-
-#include "opt_cpu.h"
-#include "opt_kstack_pages.h"
-#include "opt_swtch.h"
-
-#ifdef SMP
-#include <machine/smptests.h>
-#else
-#error
-#endif
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/cons.h> /* cngetc() */
-#ifdef GPROF
-#include <sys/gmon.h>
-#endif
-#include <sys/kernel.h>
-#include <sys/ktr.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/memrange.h>
-#include <sys/mutex.h>
-#include <sys/pcpu.h>
-#include <sys/proc.h>
-#include <sys/smp.h>
-#include <sys/sysctl.h>
-#include <sys/user.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_extern.h>
-#include <vm/vm_map.h>
-
-#include <machine/apic.h>
-#include <machine/atomic.h>
-#include <machine/clock.h>
-#include <machine/cpu.h>
-#include <machine/cpufunc.h>
-#include <machine/mpapic.h>
-#include <machine/psl.h>
-#include <machine/segments.h>
-#include <machine/smp.h>
-#include <machine/smptests.h> /** TEST_DEFAULT_CONFIG, TEST_TEST1 */
-#include <machine/tss.h>
-#include <machine/specialreg.h>
-#include <machine/privatespace.h>
-
-#if defined(APIC_IO)
-#include <machine/md_var.h> /* setidt() */
-#include <i386/isa/icu.h> /* IPIs */
-#include <i386/isa/intr_machdep.h> /* IPIs */
-#endif /* APIC_IO */
-
-#if defined(TEST_DEFAULT_CONFIG)
-#define MPFPS_MPFB1 TEST_DEFAULT_CONFIG
-#else
-#define MPFPS_MPFB1 mpfps->mpfb1
-#endif /* TEST_DEFAULT_CONFIG */
-
-#define WARMBOOT_TARGET 0
-#define WARMBOOT_OFF (KERNBASE + 0x0467)
-#define WARMBOOT_SEG (KERNBASE + 0x0469)
-
-#ifdef PC98
-#define BIOS_BASE (0xe8000)
-#define BIOS_SIZE (0x18000)
-#else
-#define BIOS_BASE (0xf0000)
-#define BIOS_SIZE (0x10000)
-#endif
-#define BIOS_COUNT (BIOS_SIZE/4)
-
-#define CMOS_REG (0x70)
-#define CMOS_DATA (0x71)
-#define BIOS_RESET (0x0f)
-#define BIOS_WARM (0x0a)
-
-#define PROCENTRY_FLAG_EN 0x01
-#define PROCENTRY_FLAG_BP 0x02
-#define IOAPICENTRY_FLAG_EN 0x01
-
-
-/* MP Floating Pointer Structure */
-typedef struct MPFPS {
- char signature[4];
- void *pap;
- u_char length;
- u_char spec_rev;
- u_char checksum;
- u_char mpfb1;
- u_char mpfb2;
- u_char mpfb3;
- u_char mpfb4;
- u_char mpfb5;
-} *mpfps_t;
-
-/* 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];
- void *oem_table_pointer;
- u_short oem_table_size;
- u_short entry_count;
- void *apic_address;
- u_short extended_table_length;
- u_char extended_table_checksum;
- u_char reserved;
-} *mpcth_t;
-
-
-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;
-
-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;
- void *apic_address;
-} *io_apic_entry_ptr;
-
-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;
-
-/* descriptions of MP basetable entries */
-typedef struct BASETABLE_ENTRY {
- u_char type;
- u_char length;
- char name[16];
-} basetable_entry;
-
-/*
- * this code MUST be enabled here and in mpboot.s.
- * it follows the very early stages of AP boot by placing values in CMOS ram.
- * it NORMALLY will never be needed and thus the primitive method for enabling.
- *
-#define CHECK_POINTS
- */
-
-#if defined(CHECK_POINTS) && !defined(PC98)
-#define CHECK_READ(A) (outb(CMOS_REG, (A)), inb(CMOS_DATA))
-#define CHECK_WRITE(A,D) (outb(CMOS_REG, (A)), outb(CMOS_DATA, (D)))
-
-#define CHECK_INIT(D); \
- CHECK_WRITE(0x34, (D)); \
- CHECK_WRITE(0x35, (D)); \
- CHECK_WRITE(0x36, (D)); \
- CHECK_WRITE(0x37, (D)); \
- CHECK_WRITE(0x38, (D)); \
- CHECK_WRITE(0x39, (D));
-
-#define CHECK_PRINT(S); \
- printf("%s: %d, %d, %d, %d, %d, %d\n", \
- (S), \
- CHECK_READ(0x34), \
- CHECK_READ(0x35), \
- CHECK_READ(0x36), \
- CHECK_READ(0x37), \
- CHECK_READ(0x38), \
- CHECK_READ(0x39));
-
-#else /* CHECK_POINTS */
-
-#define CHECK_INIT(D)
-#define CHECK_PRINT(S)
-
-#endif /* CHECK_POINTS */
-
-/*
- * Values to send to the POST hardware.
- */
-#define MP_BOOTADDRESS_POST 0x10
-#define MP_PROBE_POST 0x11
-#define MPTABLE_PASS1_POST 0x12
-
-#define MP_START_POST 0x13
-#define MP_ENABLE_POST 0x14
-#define MPTABLE_PASS2_POST 0x15
-
-#define START_ALL_APS_POST 0x16
-#define INSTALL_AP_TRAMP_POST 0x17
-#define START_AP_POST 0x18
-
-#define MP_ANNOUNCE_POST 0x19
-
-static int need_hyperthreading_fixup;
-static u_int logical_cpus;
-static u_int logical_cpus_mask;
-
-/* used to hold the AP's until we are ready to release them */
-static struct mtx ap_boot_mtx;
-
-/** XXX FIXME: where does this really belong, isa.h/isa.c perhaps? */
-int current_postcode;
-
-/** XXX FIXME: what system files declare these??? */
-extern struct region_descriptor r_gdt, r_idt;
-
-int bsp_apic_ready = 0; /* flags useability of BSP apic */
-int mp_naps; /* # of Applications processors */
-int mp_nbusses; /* # of busses */
-int mp_napics; /* # of IO APICs */
-int boot_cpu_id; /* designated BSP */
-vm_offset_t cpu_apic_address;
-vm_offset_t io_apic_address[NAPICID]; /* NAPICID is more than enough */
-extern int nkpt;
-
-u_int32_t cpu_apic_versions[MAXCPU];
-u_int32_t *io_apic_versions;
-
-#ifdef APIC_INTR_REORDER
-struct {
- volatile int *location;
- int bit;
-} apic_isrbit_location[32];
-#endif
-
-struct apic_intmapinfo int_to_apicintpin[APIC_INTMAPSIZE];
-
-/*
- * APIC ID logical/physical mapping structures.
- * We oversize these to simplify boot-time config.
- */
-int cpu_num_to_apic_id[NAPICID];
-int io_num_to_apic_id[NAPICID];
-int apic_id_to_logical[NAPICID];
-
-
-/* AP uses this during bootstrap. Do not staticize. */
-char *bootSTK;
-static int bootAP;
-
-/* Hotwire a 0->4MB V==P mapping */
-extern pt_entry_t *KPTphys;
-
-/* SMP page table page */
-extern pt_entry_t *SMPpt;
-
-struct pcb stoppcbs[MAXCPU];
-
-#ifdef APIC_IO
-/* Variables needed for SMP tlb shootdown. */
-vm_offset_t smp_tlb_addr1;
-vm_offset_t smp_tlb_addr2;
-volatile int smp_tlb_wait;
-static struct mtx smp_tlb_mtx;
-#endif
-
-/*
- * Local data and functions.
- */
-
-/* Set to 1 once we're ready to let the APs out of the pen. */
-static volatile int aps_ready = 0;
-
-static int mp_capable;
-static u_int boot_address;
-static u_int base_memory;
-
-static int picmode; /* 0: virtual wire mode, 1: PIC mode */
-static mpfps_t mpfps;
-static int search_for_sig(u_int32_t target, int count);
-static void mp_enable(u_int boot_addr);
-
-static void mptable_hyperthread_fixup(u_int id_mask);
-static void mptable_pass1(void);
-static int mptable_pass2(void);
-static void default_mp_table(int type);
-static void fix_mp_table(void);
-static void setup_apic_irq_mapping(void);
-static void init_locks(void);
-static int start_all_aps(u_int boot_addr);
-static void install_ap_tramp(u_int boot_addr);
-static int start_ap(int logicalCpu, u_int boot_addr);
-void ap_init(void);
-static int apic_int_is_bus_type(int intr, int bus_type);
-static void release_aps(void *dummy);
-
-/*
- * initialize all the SMP locks
- */
-
-/* lock region used by kernel profiling */
-int mcount_lock;
-
-#ifdef USE_COMLOCK
-/* locks com (tty) data/hardware accesses: a FASTINTR() */
-struct mtx com_mtx;
-#endif /* USE_COMLOCK */
-
-static void
-init_locks(void)
-{
-
-#ifdef USE_COMLOCK
- mtx_init(&com_mtx, "com", NULL, MTX_SPIN);
-#endif /* USE_COMLOCK */
-#ifdef APIC_IO
- mtx_init(&smp_tlb_mtx, "tlb", NULL, MTX_SPIN);
-#endif
-}
-
-/*
- * Calculate usable address in base memory for AP trampoline code.
- */
-u_int
-mp_bootaddress(u_int basemem)
-{
- POSTCODE(MP_BOOTADDRESS_POST);
-
- base_memory = basemem * 1024; /* convert to bytes */
-
- boot_address = base_memory & ~0xfff; /* round down to 4k boundary */
- if ((base_memory - boot_address) < bootMP_size)
- boot_address -= 4096; /* not enough, lower by 4k */
-
- return boot_address;
-}
-
-
-/*
- * Look for an Intel MP spec table (ie, SMP capable hardware).
- */
-void
-i386_mp_probe(void)
-{
- int x;
- u_long segment;
- u_int32_t target;
-
- POSTCODE(MP_PROBE_POST);
-
- /* see if EBDA exists */
- if ((segment = (u_long) * (u_short *) (KERNBASE + 0x40e)) != 0) {
- /* search first 1K of EBDA */
- target = (u_int32_t) (segment << 4);
- if ((x = search_for_sig(target, 1024 / 4)) >= 0)
- goto found;
- } else {
- /* last 1K of base memory, effective 'top of base' passed in */
- target = (u_int32_t) (base_memory - 0x400);
- if ((x = search_for_sig(target, 1024 / 4)) >= 0)
- goto found;
- }
-
- /* search the BIOS */
- target = (u_int32_t) BIOS_BASE;
- if ((x = search_for_sig(target, BIOS_COUNT)) >= 0)
- goto found;
-
- /* nothing found */
- mpfps = (mpfps_t)0;
- mp_capable = 0;
- return;
-
-found:
- /* calculate needed resources */
- mpfps = (mpfps_t)x;
- mptable_pass1();
-
- /* flag fact that we are running multiple processors */
- mp_capable = 1;
-}
-
-int
-cpu_mp_probe(void)
-{
- /*
- * Record BSP in CPU map
- * This is done here so that MBUF init code works correctly.
- */
- all_cpus = 1;
-
- return (mp_capable);
-}
-
-/*
- * Initialize the SMP hardware and the APIC and start up the AP's.
- */
-void
-cpu_mp_start(void)
-{
- POSTCODE(MP_START_POST);
-
- /* look for MP capable motherboard */
- if (mp_capable)
- mp_enable(boot_address);
- else
- panic("MP hardware not found!");
-
- cpu_setregs();
-}
-
-
-/*
- * Print various information about the SMP system hardware and setup.
- */
-void
-cpu_mp_announce(void)
-{
- int x;
-
- POSTCODE(MP_ANNOUNCE_POST);
-
- printf(" cpu0 (BSP): apic id: %2d", CPU_TO_ID(0));
- printf(", version: 0x%08x", cpu_apic_versions[0]);
- printf(", at 0x%08x\n", cpu_apic_address);
- for (x = 1; x <= mp_naps; ++x) {
- printf(" cpu%d (AP): apic id: %2d", x, CPU_TO_ID(x));
- printf(", version: 0x%08x", cpu_apic_versions[x]);
- printf(", at 0x%08x\n", cpu_apic_address);
- }
-
-#if defined(APIC_IO)
- for (x = 0; x < mp_napics; ++x) {
- printf(" io%d (APIC): apic id: %2d", x, IO_TO_ID(x));
- printf(", version: 0x%08x", io_apic_versions[x]);
- printf(", at 0x%08x\n", io_apic_address[x]);
- }
-#else
- printf(" Warning: APIC I/O disabled\n");
-#endif /* APIC_IO */
-}
-
-/*
- * AP cpu's call this to sync up protected mode.
- */
-void
-init_secondary(void)
-{
- int gsel_tss;
- int x, myid = bootAP;
- u_int cr0;
-
- gdt_segs[GPRIV_SEL].ssd_base = (int) &SMP_prvspace[myid];
- gdt_segs[GPROC0_SEL].ssd_base =
- (int) &SMP_prvspace[myid].pcpu.pc_common_tss;
- SMP_prvspace[myid].pcpu.pc_prvspace =
- &SMP_prvspace[myid].pcpu;
-
- for (x = 0; x < NGDT; x++) {
- ssdtosd(&gdt_segs[x], &gdt[myid * NGDT + x].sd);
- }
-
- r_gdt.rd_limit = NGDT * sizeof(gdt[0]) - 1;
- r_gdt.rd_base = (int) &gdt[myid * NGDT];
- lgdt(&r_gdt); /* does magic intra-segment return */
-
- lidt(&r_idt);
-
- lldt(_default_ldt);
- PCPU_SET(currentldt, _default_ldt);
-
- gsel_tss = GSEL(GPROC0_SEL, SEL_KPL);
- gdt[myid * NGDT + GPROC0_SEL].sd.sd_type = SDT_SYS386TSS;
- PCPU_SET(common_tss.tss_esp0, 0); /* not used until after switch */
- PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL));
- PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16);
- PCPU_SET(tss_gdt, &gdt[myid * NGDT + GPROC0_SEL].sd);
- PCPU_SET(common_tssd, *PCPU_GET(tss_gdt));
- ltr(gsel_tss);
-
- /*
- * Set to a known state:
- * Set by mpboot.s: CR0_PG, CR0_PE
- * Set by cpu_setregs: CR0_NE, CR0_MP, CR0_TS, CR0_WP, CR0_AM
- */
- cr0 = rcr0();
- cr0 &= ~(CR0_CD | CR0_NW | CR0_EM);
- load_cr0(cr0);
-
- pmap_set_opt();
-}
-
-
-#if defined(APIC_IO)
-/*
- * Final configuration of the BSP's local APIC:
- * - disable 'pic mode'.
- * - disable 'virtual wire mode'.
- * - enable NMI.
- */
-void
-bsp_apic_configure(void)
-{
- u_char byte;
- u_int32_t temp;
-
- /* leave 'pic mode' if necessary */
- if (picmode) {
- outb(0x22, 0x70); /* select IMCR */
- byte = inb(0x23); /* current contents */
- byte |= 0x01; /* mask external INTR */
- outb(0x23, byte); /* disconnect 8259s/NMI */
- }
-
- /* mask lint0 (the 8259 'virtual wire' connection) */
- temp = lapic.lvt_lint0;
- temp |= APIC_LVT_M; /* set the mask */
- lapic.lvt_lint0 = temp;
-
- /* setup lint1 to handle NMI */
- temp = lapic.lvt_lint1;
- temp &= ~APIC_LVT_M; /* clear the mask */
- lapic.lvt_lint1 = temp;
-
- if (bootverbose)
- apic_dump("bsp_apic_configure()");
-}
-#endif /* APIC_IO */
-
-
-/*******************************************************************
- * local functions and data
- */
-
-/*
- * start the SMP system
- */
-static void
-mp_enable(u_int boot_addr)
-{
- int x;
-#if defined(APIC_IO)
- int apic;
- u_int ux;
-#endif /* APIC_IO */
-
- POSTCODE(MP_ENABLE_POST);
-
- /* turn on 4MB of V == P addressing so we can get to MP table */
- *(int *)PTD = PG_V | PG_RW | ((uintptr_t)(void *)KPTphys & PG_FRAME);
- invltlb();
-
- /* examine the MP table for needed info, uses physical addresses */
- x = mptable_pass2();
-
- *(int *)PTD = 0;
- invltlb();
-
- /* can't process default configs till the CPU APIC is pmapped */
- if (x)
- default_mp_table(x);
-
- /* post scan cleanup */
- fix_mp_table();
- setup_apic_irq_mapping();
-
-#if defined(APIC_IO)
-
- /* fill the LOGICAL io_apic_versions table */
- for (apic = 0; apic < mp_napics; ++apic) {
- ux = io_apic_read(apic, IOAPIC_VER);
- io_apic_versions[apic] = ux;
- io_apic_set_id(apic, IO_TO_ID(apic));
- }
-
- /* program each IO APIC in the system */
- for (apic = 0; apic < mp_napics; ++apic)
- if (io_apic_setup(apic) < 0)
- panic("IO APIC setup failure");
-
- /* install a 'Spurious INTerrupt' vector */
- setidt(XSPURIOUSINT_OFFSET, Xspuriousint,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for TLB invalidation */
- setidt(XINVLTLB_OFFSET, Xinvltlb,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- setidt(XINVLPG_OFFSET, Xinvlpg,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- setidt(XINVLRNG_OFFSET, Xinvlrng,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forwarding hardclock() */
- setidt(XHARDCLOCK_OFFSET, Xhardclock,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forwarding statclock() */
- setidt(XSTATCLOCK_OFFSET, Xstatclock,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
-#ifdef LAZY_SWITCH
- /* install an inter-CPU IPI for lazy pmap release */
- setidt(XLAZYPMAP_OFFSET, Xlazypmap,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif
-
- /* install an inter-CPU IPI for all-CPU rendezvous */
- setidt(XRENDEZVOUS_OFFSET, Xrendezvous,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forcing an additional software trap */
- setidt(XCPUAST_OFFSET, Xcpuast,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for CPU stop/restart */
- setidt(XCPUSTOP_OFFSET, Xcpustop,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
-#if defined(TEST_TEST1)
- /* install a "fake hardware INTerrupt" vector */
- setidt(XTEST1_OFFSET, Xtest1,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif /** TEST_TEST1 */
-
-#endif /* APIC_IO */
-
- /* initialize all SMP locks */
- init_locks();
-
- /* start each Application Processor */
- start_all_aps(boot_addr);
-}
-
-
-/*
- * look for the MP spec signature
- */
-
-/* string defined by the Intel MP Spec as identifying the MP table */
-#define MP_SIG 0x5f504d5f /* _MP_ */
-#define NEXT(X) ((X) += 4)
-static int
-search_for_sig(u_int32_t target, int count)
-{
- int x;
- u_int32_t *addr = (u_int32_t *) (KERNBASE + target);
-
- for (x = 0; x < count; NEXT(x))
- if (addr[x] == MP_SIG)
- /* make array index a byte index */
- return (target + (x * sizeof(u_int32_t)));
-
- return -1;
-}
-
-
-static basetable_entry basetable_entry_types[] =
-{
- {0, 20, "Processor"},
- {1, 8, "Bus"},
- {2, 8, "I/O APIC"},
- {3, 8, "I/O INT"},
- {4, 8, "Local INT"}
-};
-
-typedef struct BUSDATA {
- u_char bus_id;
- enum busTypes bus_type;
-} bus_datum;
-
-typedef struct INTDATA {
- 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;
- u_char int_vector;
-} io_int, local_int;
-
-typedef struct BUSTYPENAME {
- u_char type;
- char name[7];
-} bus_type_name;
-
-static bus_type_name bus_type_table[] =
-{
- {CBUS, "CBUS"},
- {CBUSII, "CBUSII"},
- {EISA, "EISA"},
- {MCA, "MCA"},
- {UNKNOWN_BUSTYPE, "---"},
- {ISA, "ISA"},
- {MCA, "MCA"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {PCI, "PCI"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {XPRESS, "XPRESS"},
- {UNKNOWN_BUSTYPE, "---"}
-};
-/* from MP spec v1.4, table 5-1 */
-static int default_data[7][5] =
-{
-/* nbus, id0, type0, id1, type1 */
- {1, 0, ISA, 255, 255},
- {1, 0, EISA, 255, 255},
- {1, 0, EISA, 255, 255},
- {1, 0, MCA, 255, 255},
- {2, 0, ISA, 1, PCI},
- {2, 0, EISA, 1, PCI},
- {2, 0, MCA, 1, PCI}
-};
-
-
-/* the bus data */
-static bus_datum *bus_data;
-
-/* the IO INT data, one entry per possible APIC INTerrupt */
-static io_int *io_apic_ints;
-
-static int nintrs;
-
-static int processor_entry(proc_entry_ptr entry, int cpu);
-static int bus_entry(bus_entry_ptr entry, int bus);
-static int io_apic_entry(io_apic_entry_ptr entry, int apic);
-static int int_entry(int_entry_ptr entry, int intr);
-static int lookup_bus_type(char *name);
-
-
-/*
- * 1st pass on motherboard's Intel MP specification table.
- *
- * initializes:
- * mp_ncpus = 1
- *
- * determines:
- * cpu_apic_address (common to all CPUs)
- * io_apic_address[N]
- * mp_naps
- * mp_nbusses
- * mp_napics
- * nintrs
- */
-static void
-mptable_pass1(void)
-{
- int x;
- mpcth_t cth;
- int totalSize;
- void* position;
- int count;
- int type;
- u_int id_mask;
-
- POSTCODE(MPTABLE_PASS1_POST);
-
- /* clear various tables */
- for (x = 0; x < NAPICID; ++x) {
- io_apic_address[x] = ~0; /* IO APIC address table */
- }
-
- /* init everything to empty */
- mp_naps = 0;
- mp_nbusses = 0;
- mp_napics = 0;
- nintrs = 0;
- id_mask = 0;
-
- /* check for use of 'default' configuration */
- if (MPFPS_MPFB1 != 0) {
- /* use default addresses */
- cpu_apic_address = DEFAULT_APIC_BASE;
- io_apic_address[0] = DEFAULT_IO_APIC_BASE;
-
- /* fill in with defaults */
- mp_naps = 2; /* includes BSP */
- mp_maxid = 1;
- mp_nbusses = default_data[MPFPS_MPFB1 - 1][0];
-#if defined(APIC_IO)
- mp_napics = 1;
- nintrs = 16;
-#endif /* APIC_IO */
- }
- else {
- if ((cth = mpfps->pap) == 0)
- panic("MP Configuration Table Header MISSING!");
-
- cpu_apic_address = (vm_offset_t) cth->apic_address;
-
- /* walk the table, recording info of interest */
- totalSize = cth->base_table_length - sizeof(struct MPCTH);
- position = (u_char *) cth + sizeof(struct MPCTH);
- count = cth->entry_count;
-
- while (count--) {
- switch (type = *(u_char *) position) {
- case 0: /* processor_entry */
- if (((proc_entry_ptr)position)->cpu_flags
- & PROCENTRY_FLAG_EN) {
- ++mp_naps;
- mp_maxid++;
- id_mask |= 1 <<
- ((proc_entry_ptr)position)->apic_id;
- }
- break;
- case 1: /* bus_entry */
- ++mp_nbusses;
- break;
- case 2: /* io_apic_entry */
- if (((io_apic_entry_ptr)position)->apic_flags
- & IOAPICENTRY_FLAG_EN)
- io_apic_address[mp_napics++] =
- (vm_offset_t)((io_apic_entry_ptr)
- position)->apic_address;
- break;
- case 3: /* int_entry */
- ++nintrs;
- break;
- case 4: /* int_entry */
- break;
- default:
- panic("mpfps Base Table HOSED!");
- /* NOTREACHED */
- }
-
- totalSize -= basetable_entry_types[type].length;
- (u_char*)position += basetable_entry_types[type].length;
- }
- }
-
- /* qualify the numbers */
- if (mp_naps > MAXCPU) {
- printf("Warning: only using %d of %d available CPUs!\n",
- MAXCPU, mp_naps);
- mp_naps = MAXCPU;
- }
-
- /* See if we need to fixup HT logical CPUs. */
- mptable_hyperthread_fixup(id_mask);
-
- /*
- * Count the BSP.
- * This is also used as a counter while starting the APs.
- */
- mp_ncpus = 1;
-
- --mp_naps; /* subtract the BSP */
-}
-
-
-/*
- * 2nd pass on motherboard's Intel MP specification table.
- *
- * sets:
- * boot_cpu_id
- * ID_TO_IO(N), phy APIC ID to log CPU/IO table
- * CPU_TO_ID(N), logical CPU to APIC ID table
- * IO_TO_ID(N), logical IO to APIC ID table
- * bus_data[N]
- * io_apic_ints[N]
- */
-static int
-mptable_pass2(void)
-{
- struct PROCENTRY proc;
- int x;
- mpcth_t cth;
- int totalSize;
- void* position;
- int count;
- int type;
- int apic, bus, cpu, intr;
- int i, j;
- int pgeflag;
-
- POSTCODE(MPTABLE_PASS2_POST);
-
- /* Initialize fake proc entry for use with HT fixup. */
- bzero(&proc, sizeof(proc));
- proc.type = 0;
- proc.cpu_flags = PROCENTRY_FLAG_EN;
-
- pgeflag = 0; /* XXX - Not used under SMP yet. */
-
- MALLOC(io_apic_versions, u_int32_t *, sizeof(u_int32_t) * mp_napics,
- M_DEVBUF, M_WAITOK);
- MALLOC(ioapic, volatile ioapic_t **, sizeof(ioapic_t *) * mp_napics,
- M_DEVBUF, M_WAITOK);
- MALLOC(io_apic_ints, io_int *, sizeof(io_int) * (nintrs + 1),
- M_DEVBUF, M_WAITOK);
- MALLOC(bus_data, bus_datum *, sizeof(bus_datum) * mp_nbusses,
- M_DEVBUF, M_WAITOK);
-
- bzero(ioapic, sizeof(ioapic_t *) * mp_napics);
-
- for (i = 0; i < mp_napics; i++) {
- for (j = 0; j < mp_napics; j++) {
- /* same page frame as a previous IO apic? */
- if (((vm_offset_t)SMPpt[NPTEPG-2-j] & PG_FRAME) ==
- (io_apic_address[i] & PG_FRAME)) {
- ioapic[i] = (ioapic_t *)((u_int)SMP_prvspace
- + (NPTEPG-2-j) * PAGE_SIZE
- + (io_apic_address[i] & PAGE_MASK));
- break;
- }
- /* use this slot if available */
- if (((vm_offset_t)SMPpt[NPTEPG-2-j] & PG_FRAME) == 0) {
- SMPpt[NPTEPG-2-j] = (pt_entry_t)(PG_V | PG_RW |
- pgeflag | (io_apic_address[i] & PG_FRAME));
- ioapic[i] = (ioapic_t *)((u_int)SMP_prvspace
- + (NPTEPG-2-j) * PAGE_SIZE
- + (io_apic_address[i] & PAGE_MASK));
- break;
- }
- }
- }
-
- /* clear various tables */
- for (x = 0; x < NAPICID; ++x) {
- ID_TO_IO(x) = -1; /* phy APIC ID to log CPU/IO table */
- CPU_TO_ID(x) = -1; /* logical CPU to APIC ID table */
- IO_TO_ID(x) = -1; /* logical IO to APIC ID table */
- }
-
- /* clear bus data table */
- for (x = 0; x < mp_nbusses; ++x)
- bus_data[x].bus_id = 0xff;
-
- /* clear IO APIC INT table */
- for (x = 0; x < (nintrs + 1); ++x) {
- io_apic_ints[x].int_type = 0xff;
- io_apic_ints[x].int_vector = 0xff;
- }
-
- /* setup the cpu/apic mapping arrays */
- boot_cpu_id = -1;
-
- /* record whether PIC or virtual-wire mode */
- picmode = (mpfps->mpfb2 & 0x80) ? 1 : 0;
-
- /* check for use of 'default' configuration */
- if (MPFPS_MPFB1 != 0)
- return MPFPS_MPFB1; /* return default configuration type */
-
- if ((cth = mpfps->pap) == 0)
- panic("MP Configuration Table Header MISSING!");
-
- /* walk the table, recording info of interest */
- totalSize = cth->base_table_length - sizeof(struct MPCTH);
- position = (u_char *) cth + sizeof(struct MPCTH);
- count = cth->entry_count;
- apic = bus = intr = 0;
- cpu = 1; /* pre-count the BSP */
-
- while (count--) {
- switch (type = *(u_char *) position) {
- case 0:
- if (processor_entry(position, cpu)) {
- if (logical_cpus != 0 &&
- cpu % logical_cpus != 0)
- logical_cpus_mask |= (1 << cpu);
- ++cpu;
- }
- if (need_hyperthreading_fixup) {
- /*
- * Create fake mptable processor entries
- * and feed them to processor_entry() to
- * enumerate the logical CPUs.
- */
- proc.apic_id = ((proc_entry_ptr)position)->apic_id;
- for (i = 1; i < logical_cpus; i++) {
- proc.apic_id++;
- (void)processor_entry(&proc, cpu);
- logical_cpus_mask |= (1 << cpu);
- cpu++;
- }
- }
- break;
- case 1:
- if (bus_entry(position, bus))
- ++bus;
- break;
- case 2:
- if (io_apic_entry(position, apic))
- ++apic;
- break;
- case 3:
- if (int_entry(position, intr))
- ++intr;
- break;
- case 4:
- /* int_entry(position); */
- break;
- default:
- panic("mpfps Base Table HOSED!");
- /* NOTREACHED */
- }
-
- totalSize -= basetable_entry_types[type].length;
- (u_char *) position += basetable_entry_types[type].length;
- }
-
- if (boot_cpu_id == -1)
- panic("NO BSP found!");
-
- /* report fact that its NOT a default configuration */
- return 0;
-}
-
-/*
- * Check if we should perform a hyperthreading "fix-up" to
- * enumerate any logical CPU's that aren't already listed
- * in the table.
- *
- * XXX: We assume that all of the physical CPUs in the
- * system have the same number of logical CPUs.
- *
- * XXX: We assume that APIC ID's are allocated such that
- * the APIC ID's for a physical processor are aligned
- * with the number of logical CPU's in the processor.
- */
-static void
-mptable_hyperthread_fixup(u_int id_mask)
-{
- u_int i, id;
-
- /* Nothing to do if there is no HTT support. */
- if ((cpu_feature & CPUID_HTT) == 0)
- return;
- logical_cpus = (cpu_procinfo & CPUID_HTT_CORES) >> 16;
- if (logical_cpus <= 1)
- return;
-
- /*
- * For each APIC ID of a CPU that is set in the mask,
- * scan the other candidate APIC ID's for this
- * physical processor. If any of those ID's are
- * already in the table, then kill the fixup.
- */
- for (id = 0; id <= MAXCPU; id++) {
- if ((id_mask & 1 << id) == 0)
- continue;
- /* First, make sure we are on a logical_cpus boundary. */
- if (id % logical_cpus != 0)
- return;
- for (i = id + 1; i < id + logical_cpus; i++)
- if ((id_mask & 1 << i) != 0)
- return;
- }
-
- /*
- * Ok, the ID's checked out, so enable the fixup. We have to fixup
- * mp_naps and mp_maxid right now.
- */
- need_hyperthreading_fixup = 1;
- mp_maxid *= logical_cpus;
- mp_naps *= logical_cpus;
-}
-
-void
-assign_apic_irq(int apic, int intpin, int irq)
-{
- int x;
-
- if (int_to_apicintpin[irq].ioapic != -1)
- panic("assign_apic_irq: inconsistent table");
-
- int_to_apicintpin[irq].ioapic = apic;
- int_to_apicintpin[irq].int_pin = intpin;
- int_to_apicintpin[irq].apic_address = ioapic[apic];
- int_to_apicintpin[irq].redirindex = IOAPIC_REDTBL + 2 * intpin;
-
- for (x = 0; x < nintrs; x++) {
- if ((io_apic_ints[x].int_type == 0 ||
- io_apic_ints[x].int_type == 3) &&
- io_apic_ints[x].int_vector == 0xff &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(apic) &&
- io_apic_ints[x].dst_apic_int == intpin)
- io_apic_ints[x].int_vector = irq;
- }
-}
-
-void
-revoke_apic_irq(int irq)
-{
- int x;
- int oldapic;
- int oldintpin;
-
- if (int_to_apicintpin[irq].ioapic == -1)
- panic("revoke_apic_irq: inconsistent table");
-
- oldapic = int_to_apicintpin[irq].ioapic;
- oldintpin = int_to_apicintpin[irq].int_pin;
-
- int_to_apicintpin[irq].ioapic = -1;
- int_to_apicintpin[irq].int_pin = 0;
- int_to_apicintpin[irq].apic_address = NULL;
- int_to_apicintpin[irq].redirindex = 0;
-
- for (x = 0; x < nintrs; x++) {
- if ((io_apic_ints[x].int_type == 0 ||
- io_apic_ints[x].int_type == 3) &&
- io_apic_ints[x].int_vector != 0xff &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(oldapic) &&
- io_apic_ints[x].dst_apic_int == oldintpin)
- io_apic_ints[x].int_vector = 0xff;
- }
-}
-
-
-static void
-allocate_apic_irq(int intr)
-{
- int apic;
- int intpin;
- int irq;
-
- if (io_apic_ints[intr].int_vector != 0xff)
- return; /* Interrupt handler already assigned */
-
- if (io_apic_ints[intr].int_type != 0 &&
- (io_apic_ints[intr].int_type != 3 ||
- (io_apic_ints[intr].dst_apic_id == IO_TO_ID(0) &&
- io_apic_ints[intr].dst_apic_int == 0)))
- return; /* Not INT or ExtInt on != (0, 0) */
-
- irq = 0;
- while (irq < APIC_INTMAPSIZE &&
- int_to_apicintpin[irq].ioapic != -1)
- irq++;
-
- if (irq >= APIC_INTMAPSIZE)
- return; /* No free interrupt handlers */
-
- apic = ID_TO_IO(io_apic_ints[intr].dst_apic_id);
- intpin = io_apic_ints[intr].dst_apic_int;
-
- assign_apic_irq(apic, intpin, irq);
- io_apic_setup_intpin(apic, intpin);
-}
-
-
-static void
-swap_apic_id(int apic, int oldid, int newid)
-{
- int x;
- int oapic;
-
-
- if (oldid == newid)
- return; /* Nothing to do */
-
- printf("Changing APIC ID for IO APIC #%d from %d to %d in MP table\n",
- apic, oldid, newid);
-
- /* Swap physical APIC IDs in interrupt entries */
- for (x = 0; x < nintrs; x++) {
- if (io_apic_ints[x].dst_apic_id == oldid)
- io_apic_ints[x].dst_apic_id = newid;
- else if (io_apic_ints[x].dst_apic_id == newid)
- io_apic_ints[x].dst_apic_id = oldid;
- }
-
- /* Swap physical APIC IDs in IO_TO_ID mappings */
- for (oapic = 0; oapic < mp_napics; oapic++)
- if (IO_TO_ID(oapic) == newid)
- break;
-
- if (oapic < mp_napics) {
- printf("Changing APIC ID for IO APIC #%d from "
- "%d to %d in MP table\n",
- oapic, newid, oldid);
- IO_TO_ID(oapic) = oldid;
- }
- IO_TO_ID(apic) = newid;
-}
-
-
-static void
-fix_id_to_io_mapping(void)
-{
- int x;
-
- for (x = 0; x < NAPICID; x++)
- ID_TO_IO(x) = -1;
-
- for (x = 0; x <= mp_naps; x++)
- if (CPU_TO_ID(x) < NAPICID)
- ID_TO_IO(CPU_TO_ID(x)) = x;
-
- for (x = 0; x < mp_napics; x++)
- if (IO_TO_ID(x) < NAPICID)
- ID_TO_IO(IO_TO_ID(x)) = x;
-}
-
-
-static int
-first_free_apic_id(void)
-{
- int freeid, x;
-
- for (freeid = 0; freeid < NAPICID; freeid++) {
- for (x = 0; x <= mp_naps; x++)
- if (CPU_TO_ID(x) == freeid)
- break;
- if (x <= mp_naps)
- continue;
- for (x = 0; x < mp_napics; x++)
- if (IO_TO_ID(x) == freeid)
- break;
- if (x < mp_napics)
- continue;
- return freeid;
- }
- return freeid;
-}
-
-
-static int
-io_apic_id_acceptable(int apic, int id)
-{
- int cpu; /* Logical CPU number */
- int oapic; /* Logical IO APIC number for other IO APIC */
-
- if (id >= NAPICID)
- return 0; /* Out of range */
-
- for (cpu = 0; cpu <= mp_naps; cpu++)
- if (CPU_TO_ID(cpu) == id)
- return 0; /* Conflict with CPU */
-
- for (oapic = 0; oapic < mp_napics && oapic < apic; oapic++)
- if (IO_TO_ID(oapic) == id)
- return 0; /* Conflict with other APIC */
-
- return 1; /* ID is acceptable for IO APIC */
-}
-
-
-/*
- * parse an Intel MP specification table
- */
-static void
-fix_mp_table(void)
-{
- int x;
- int id;
- int bus_0 = 0; /* Stop GCC warning */
- int bus_pci = 0; /* Stop GCC warning */
- int num_pci_bus;
- int apic; /* IO APIC unit number */
- int freeid; /* Free physical APIC ID */
- int physid; /* Current physical IO APIC ID */
-
- /*
- * Fix mis-numbering of the PCI bus and its INT entries if the BIOS
- * did it wrong. The MP spec says that when more than 1 PCI bus
- * exists the BIOS must begin with bus entries for the PCI bus and use
- * actual PCI bus numbering. This implies that when only 1 PCI bus
- * exists the BIOS can choose to ignore this ordering, and indeed many
- * MP motherboards do ignore it. This causes a problem when the PCI
- * sub-system makes requests of the MP sub-system based on PCI bus
- * numbers. So here we look for the situation and renumber the
- * busses and associated INTs in an effort to "make it right".
- */
-
- /* find bus 0, PCI bus, count the number of PCI busses */
- for (num_pci_bus = 0, x = 0; x < mp_nbusses; ++x) {
- if (bus_data[x].bus_id == 0) {
- bus_0 = x;
- }
- if (bus_data[x].bus_type == PCI) {
- ++num_pci_bus;
- bus_pci = x;
- }
- }
- /*
- * bus_0 == slot of bus with ID of 0
- * bus_pci == slot of last PCI bus encountered
- */
-
- /* check the 1 PCI bus case for sanity */
- /* if it is number 0 all is well */
- if (num_pci_bus == 1 &&
- bus_data[bus_pci].bus_id != 0) {
-
- /* mis-numbered, swap with whichever bus uses slot 0 */
-
- /* swap the bus entry types */
- bus_data[bus_pci].bus_type = bus_data[bus_0].bus_type;
- bus_data[bus_0].bus_type = PCI;
-
- /* swap each relavant INTerrupt entry */
- id = bus_data[bus_pci].bus_id;
- for (x = 0; x < nintrs; ++x) {
- if (io_apic_ints[x].src_bus_id == id) {
- io_apic_ints[x].src_bus_id = 0;
- }
- else if (io_apic_ints[x].src_bus_id == 0) {
- io_apic_ints[x].src_bus_id = id;
- }
- }
- }
-
- /* Assign IO APIC IDs.
- *
- * First try the existing ID. If a conflict is detected, try
- * the ID in the MP table. If a conflict is still detected, find
- * a free id.
- *
- * We cannot use the ID_TO_IO table before all conflicts has been
- * resolved and the table has been corrected.
- */
- for (apic = 0; apic < mp_napics; ++apic) { /* For all IO APICs */
-
- /* First try to use the value set by the BIOS */
- physid = io_apic_get_id(apic);
- if (io_apic_id_acceptable(apic, physid)) {
- if (IO_TO_ID(apic) != physid)
- swap_apic_id(apic, IO_TO_ID(apic), physid);
- continue;
- }
-
- /* Then check if the value in the MP table is acceptable */
- if (io_apic_id_acceptable(apic, IO_TO_ID(apic)))
- continue;
-
- /* Last resort, find a free APIC ID and use it */
- freeid = first_free_apic_id();
- if (freeid >= NAPICID)
- panic("No free physical APIC IDs found");
-
- if (io_apic_id_acceptable(apic, freeid)) {
- swap_apic_id(apic, IO_TO_ID(apic), freeid);
- continue;
- }
- panic("Free physical APIC ID not usable");
- }
- fix_id_to_io_mapping();
-
- /* detect and fix broken Compaq MP table */
- if (apic_int_type(0, 0) == -1) {
- printf("APIC_IO: MP table broken: 8259->APIC entry missing!\n");
- io_apic_ints[nintrs].int_type = 3; /* ExtInt */
- io_apic_ints[nintrs].int_vector = 0xff; /* Unassigned */
- /* XXX fixme, set src bus id etc, but it doesn't seem to hurt */
- io_apic_ints[nintrs].dst_apic_id = IO_TO_ID(0);
- io_apic_ints[nintrs].dst_apic_int = 0; /* Pin 0 */
- nintrs++;
- }
-}
-
-
-/* Assign low level interrupt handlers */
-static void
-setup_apic_irq_mapping(void)
-{
- int x;
- int int_vector;
-
- /* Clear array */
- for (x = 0; x < APIC_INTMAPSIZE; x++) {
- int_to_apicintpin[x].ioapic = -1;
- int_to_apicintpin[x].int_pin = 0;
- int_to_apicintpin[x].apic_address = NULL;
- int_to_apicintpin[x].redirindex = 0;
- }
-
- /* First assign ISA/EISA interrupts */
- for (x = 0; x < nintrs; x++) {
- int_vector = io_apic_ints[x].src_bus_irq;
- if (int_vector < APIC_INTMAPSIZE &&
- io_apic_ints[x].int_vector == 0xff &&
- int_to_apicintpin[int_vector].ioapic == -1 &&
- (apic_int_is_bus_type(x, ISA) ||
- apic_int_is_bus_type(x, EISA)) &&
- io_apic_ints[x].int_type == 0) {
- assign_apic_irq(ID_TO_IO(io_apic_ints[x].dst_apic_id),
- io_apic_ints[x].dst_apic_int,
- int_vector);
- }
- }
-
- /* Assign ExtInt entry if no ISA/EISA interrupt 0 entry */
- for (x = 0; x < nintrs; x++) {
- if (io_apic_ints[x].dst_apic_int == 0 &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(0) &&
- io_apic_ints[x].int_vector == 0xff &&
- int_to_apicintpin[0].ioapic == -1 &&
- io_apic_ints[x].int_type == 3) {
- assign_apic_irq(0, 0, 0);
- break;
- }
- }
- /* PCI interrupt assignment is deferred */
-}
-
-
-static int
-processor_entry(proc_entry_ptr entry, int cpu)
-{
- /* check for usability */
- if (!(entry->cpu_flags & PROCENTRY_FLAG_EN))
- return 0;
-
- if(entry->apic_id >= NAPICID)
- panic("CPU APIC ID out of range (0..%d)", NAPICID - 1);
- /* check for BSP flag */
- if (entry->cpu_flags & PROCENTRY_FLAG_BP) {
- boot_cpu_id = entry->apic_id;
- CPU_TO_ID(0) = entry->apic_id;
- ID_TO_CPU(entry->apic_id) = 0;
- return 0; /* its already been counted */
- }
-
- /* add another AP to list, if less than max number of CPUs */
- else if (cpu < MAXCPU) {
- CPU_TO_ID(cpu) = entry->apic_id;
- ID_TO_CPU(entry->apic_id) = cpu;
- return 1;
- }
-
- return 0;
-}
-
-
-static int
-bus_entry(bus_entry_ptr entry, int bus)
-{
- int x;
- char c, name[8];
-
- /* encode the name into an index */
- for (x = 0; x < 6; ++x) {
- if ((c = entry->bus_type[x]) == ' ')
- break;
- name[x] = c;
- }
- name[x] = '\0';
-
- if ((x = lookup_bus_type(name)) == UNKNOWN_BUSTYPE)
- panic("unknown bus type: '%s'", name);
-
- bus_data[bus].bus_id = entry->bus_id;
- bus_data[bus].bus_type = x;
-
- return 1;
-}
-
-
-static int
-io_apic_entry(io_apic_entry_ptr entry, int apic)
-{
- if (!(entry->apic_flags & IOAPICENTRY_FLAG_EN))
- return 0;
-
- IO_TO_ID(apic) = entry->apic_id;
- if (entry->apic_id < NAPICID)
- ID_TO_IO(entry->apic_id) = apic;
-
- return 1;
-}
-
-
-static int
-lookup_bus_type(char *name)
-{
- int x;
-
- for (x = 0; x < MAX_BUSTYPE; ++x)
- if (strcmp(bus_type_table[x].name, name) == 0)
- return bus_type_table[x].type;
-
- return UNKNOWN_BUSTYPE;
-}
-
-
-static int
-int_entry(int_entry_ptr entry, int intr)
-{
- int apic;
-
- io_apic_ints[intr].int_type = entry->int_type;
- io_apic_ints[intr].int_flags = entry->int_flags;
- io_apic_ints[intr].src_bus_id = entry->src_bus_id;
- io_apic_ints[intr].src_bus_irq = entry->src_bus_irq;
- if (entry->dst_apic_id == 255) {
- /* This signal goes to all IO APICS. Select an IO APIC
- with sufficient number of interrupt pins */
- for (apic = 0; apic < mp_napics; apic++)
- if (((io_apic_read(apic, IOAPIC_VER) &
- IOART_VER_MAXREDIR) >> MAXREDIRSHIFT) >=
- entry->dst_apic_int)
- break;
- if (apic < mp_napics)
- io_apic_ints[intr].dst_apic_id = IO_TO_ID(apic);
- else
- io_apic_ints[intr].dst_apic_id = entry->dst_apic_id;
- } else
- io_apic_ints[intr].dst_apic_id = entry->dst_apic_id;
- io_apic_ints[intr].dst_apic_int = entry->dst_apic_int;
-
- return 1;
-}
-
-
-static int
-apic_int_is_bus_type(int intr, int bus_type)
-{
- int bus;
-
- for (bus = 0; bus < mp_nbusses; ++bus)
- if ((bus_data[bus].bus_id == io_apic_ints[intr].src_bus_id)
- && ((int) bus_data[bus].bus_type == bus_type))
- return 1;
-
- return 0;
-}
-
-
-/*
- * Given a traditional ISA INT mask, return an APIC mask.
- */
-u_int
-isa_apic_mask(u_int isa_mask)
-{
- int isa_irq;
- int apic_pin;
-
-#if defined(SKIP_IRQ15_REDIRECT)
- if (isa_mask == (1 << 15)) {
- printf("skipping ISA IRQ15 redirect\n");
- return isa_mask;
- }
-#endif /* SKIP_IRQ15_REDIRECT */
-
- isa_irq = ffs(isa_mask); /* find its bit position */
- if (isa_irq == 0) /* doesn't exist */
- return 0;
- --isa_irq; /* make it zero based */
-
- apic_pin = isa_apic_irq(isa_irq); /* look for APIC connection */
- if (apic_pin == -1)
- return 0;
-
- return (1 << apic_pin); /* convert pin# to a mask */
-}
-
-
-/*
- * Determine which APIC pin an ISA/EISA INT is attached to.
- */
-#define INTTYPE(I) (io_apic_ints[(I)].int_type)
-#define INTPIN(I) (io_apic_ints[(I)].dst_apic_int)
-#define INTIRQ(I) (io_apic_ints[(I)].int_vector)
-#define INTAPIC(I) (ID_TO_IO(io_apic_ints[(I)].dst_apic_id))
-
-#define SRCBUSIRQ(I) (io_apic_ints[(I)].src_bus_irq)
-int
-isa_apic_irq(int isa_irq)
-{
- int intr;
-
- for (intr = 0; intr < nintrs; ++intr) { /* check each record */
- if (INTTYPE(intr) == 0) { /* standard INT */
- if (SRCBUSIRQ(intr) == isa_irq) {
- if (apic_int_is_bus_type(intr, ISA) ||
- apic_int_is_bus_type(intr, EISA)) {
- if (INTIRQ(intr) == 0xff)
- return -1; /* unassigned */
- return INTIRQ(intr); /* found */
- }
- }
- }
- }
- return -1; /* NOT found */
-}
-
-
-/*
- * Determine which APIC pin a PCI INT is attached to.
- */
-#define SRCBUSID(I) (io_apic_ints[(I)].src_bus_id)
-#define SRCBUSDEVICE(I) ((io_apic_ints[(I)].src_bus_irq >> 2) & 0x1f)
-#define SRCBUSLINE(I) (io_apic_ints[(I)].src_bus_irq & 0x03)
-int
-pci_apic_irq(int pciBus, int pciDevice, int pciInt)
-{
- int intr;
-
- --pciInt; /* zero based */
-
- for (intr = 0; intr < nintrs; ++intr) /* check each record */
- if ((INTTYPE(intr) == 0) /* standard INT */
- && (SRCBUSID(intr) == pciBus)
- && (SRCBUSDEVICE(intr) == pciDevice)
- && (SRCBUSLINE(intr) == pciInt)) /* a candidate IRQ */
- if (apic_int_is_bus_type(intr, PCI)) {
- if (INTIRQ(intr) == 0xff)
- allocate_apic_irq(intr);
- if (INTIRQ(intr) == 0xff)
- return -1; /* unassigned */
- return INTIRQ(intr); /* exact match */
- }
-
- return -1; /* NOT found */
-}
-
-int
-next_apic_irq(int irq)
-{
- int intr, ointr;
- int bus, bustype;
-
- bus = 0;
- bustype = 0;
- for (intr = 0; intr < nintrs; intr++) {
- if (INTIRQ(intr) != irq || INTTYPE(intr) != 0)
- continue;
- bus = SRCBUSID(intr);
- bustype = apic_bus_type(bus);
- if (bustype != ISA &&
- bustype != EISA &&
- bustype != PCI)
- continue;
- break;
- }
- if (intr >= nintrs) {
- return -1;
- }
- for (ointr = intr + 1; ointr < nintrs; ointr++) {
- if (INTTYPE(ointr) != 0)
- continue;
- if (bus != SRCBUSID(ointr))
- continue;
- if (bustype == PCI) {
- if (SRCBUSDEVICE(intr) != SRCBUSDEVICE(ointr))
- continue;
- if (SRCBUSLINE(intr) != SRCBUSLINE(ointr))
- continue;
- }
- if (bustype == ISA || bustype == EISA) {
- if (SRCBUSIRQ(intr) != SRCBUSIRQ(ointr))
- continue;
- }
- if (INTPIN(intr) == INTPIN(ointr))
- continue;
- break;
- }
- if (ointr >= nintrs) {
- return -1;
- }
- return INTIRQ(ointr);
-}
-#undef SRCBUSLINE
-#undef SRCBUSDEVICE
-#undef SRCBUSID
-#undef SRCBUSIRQ
-
-#undef INTPIN
-#undef INTIRQ
-#undef INTAPIC
-#undef INTTYPE
-
-
-/*
- * Reprogram the MB chipset to NOT redirect an ISA INTerrupt.
- *
- * XXX FIXME:
- * Exactly what this means is unclear at this point. It is a solution
- * for motherboards that redirect the MBIRQ0 pin. Generically a motherboard
- * could route any of the ISA INTs to upper (>15) IRQ values. But most would
- * NOT be redirected via MBIRQ0, thus "undirect()ing" them would NOT be an
- * option.
- */
-int
-undirect_isa_irq(int rirq)
-{
-#if defined(READY)
- if (bootverbose)
- printf("Freeing redirected ISA irq %d.\n", rirq);
- /** FIXME: tickle the MB redirector chip */
- return -1;
-#else
- if (bootverbose)
- printf("Freeing (NOT implemented) redirected ISA irq %d.\n", rirq);
- return 0;
-#endif /* READY */
-}
-
-
-/*
- * Reprogram the MB chipset to NOT redirect a PCI INTerrupt
- */
-int
-undirect_pci_irq(int rirq)
-{
-#if defined(READY)
- if (bootverbose)
- printf("Freeing redirected PCI irq %d.\n", rirq);
-
- /** FIXME: tickle the MB redirector chip */
- return -1;
-#else
- if (bootverbose)
- printf("Freeing (NOT implemented) redirected PCI irq %d.\n",
- rirq);
- return 0;
-#endif /* READY */
-}
-
-
-/*
- * given a bus ID, return:
- * the bus type if found
- * -1 if NOT found
- */
-int
-apic_bus_type(int id)
-{
- int x;
-
- for (x = 0; x < mp_nbusses; ++x)
- if (bus_data[x].bus_id == id)
- return bus_data[x].bus_type;
-
- return -1;
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated src bus ID if found
- * -1 if NOT found
- */
-int
-apic_src_bus_id(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].src_bus_id);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated src bus IRQ if found
- * -1 if NOT found
- */
-int
-apic_src_bus_irq(int apic, int pin)
-{
- int x;
-
- for (x = 0; x < nintrs; x++)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].src_bus_irq);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated INTerrupt type if found
- * -1 if NOT found
- */
-int
-apic_int_type(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].int_type);
-
- return -1; /* NOT found */
-}
-
-int
-apic_irq(int apic, int pin)
-{
- int x;
- int res;
-
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int)) {
- res = io_apic_ints[x].int_vector;
- if (res == 0xff)
- return -1;
- if (apic != int_to_apicintpin[res].ioapic)
- panic("apic_irq: inconsistent table");
- if (pin != int_to_apicintpin[res].int_pin)
- panic("apic_irq inconsistent table (2)");
- return res;
- }
- return -1;
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated trigger mode if found
- * -1 if NOT found
- */
-int
-apic_trigger(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return ((io_apic_ints[x].int_flags >> 2) & 0x03);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated 'active' level if found
- * -1 if NOT found
- */
-int
-apic_polarity(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].int_flags & 0x03);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * set data according to MP defaults
- * FIXME: probably not complete yet...
- */
-static void
-default_mp_table(int type)
-{
- int ap_cpu_id;
-#if defined(APIC_IO)
- int io_apic_id;
- int pin;
-#endif /* APIC_IO */
-
-#if 0
- printf(" MP default config type: %d\n", type);
- switch (type) {
- case 1:
- printf(" bus: ISA, APIC: 82489DX\n");
- break;
- case 2:
- printf(" bus: EISA, APIC: 82489DX\n");
- break;
- case 3:
- printf(" bus: EISA, APIC: 82489DX\n");
- break;
- case 4:
- printf(" bus: MCA, APIC: 82489DX\n");
- break;
- case 5:
- printf(" bus: ISA+PCI, APIC: Integrated\n");
- break;
- case 6:
- printf(" bus: EISA+PCI, APIC: Integrated\n");
- break;
- case 7:
- printf(" bus: MCA+PCI, APIC: Integrated\n");
- break;
- default:
- printf(" future type\n");
- break;
- /* NOTREACHED */
- }
-#endif /* 0 */
-
- boot_cpu_id = (lapic.id & APIC_ID_MASK) >> 24;
- ap_cpu_id = (boot_cpu_id == 0) ? 1 : 0;
-
- /* BSP */
- CPU_TO_ID(0) = boot_cpu_id;
- ID_TO_CPU(boot_cpu_id) = 0;
-
- /* one and only AP */
- CPU_TO_ID(1) = ap_cpu_id;
- ID_TO_CPU(ap_cpu_id) = 1;
-
-#if defined(APIC_IO)
- /* one and only IO APIC */
- io_apic_id = (io_apic_read(0, IOAPIC_ID) & APIC_ID_MASK) >> 24;
-
- /*
- * sanity check, refer to MP spec section 3.6.6, last paragraph
- * necessary as some hardware isn't properly setting up the IO APIC
- */
-#if defined(REALLY_ANAL_IOAPICID_VALUE)
- if (io_apic_id != 2) {
-#else
- if ((io_apic_id == 0) || (io_apic_id == 1) || (io_apic_id == 15)) {
-#endif /* REALLY_ANAL_IOAPICID_VALUE */
- io_apic_set_id(0, 2);
- io_apic_id = 2;
- }
- IO_TO_ID(0) = io_apic_id;
- ID_TO_IO(io_apic_id) = 0;
-#endif /* APIC_IO */
-
- /* fill out bus entries */
- switch (type) {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- bus_data[0].bus_id = default_data[type - 1][1];
- bus_data[0].bus_type = default_data[type - 1][2];
- bus_data[1].bus_id = default_data[type - 1][3];
- bus_data[1].bus_type = default_data[type - 1][4];
- break;
-
- /* case 4: case 7: MCA NOT supported */
- default: /* illegal/reserved */
- panic("BAD default MP config: %d", type);
- /* NOTREACHED */
- }
-
-#if defined(APIC_IO)
- /* general cases from MP v1.4, table 5-2 */
- for (pin = 0; pin < 16; ++pin) {
- io_apic_ints[pin].int_type = 0;
- io_apic_ints[pin].int_flags = 0x05; /* edge/active-hi */
- io_apic_ints[pin].src_bus_id = 0;
- io_apic_ints[pin].src_bus_irq = pin; /* IRQ2 caught below */
- io_apic_ints[pin].dst_apic_id = io_apic_id;
- io_apic_ints[pin].dst_apic_int = pin; /* 1-to-1 */
- }
-
- /* special cases from MP v1.4, table 5-2 */
- if (type == 2) {
- io_apic_ints[2].int_type = 0xff; /* N/C */
- io_apic_ints[13].int_type = 0xff; /* N/C */
-#if !defined(APIC_MIXED_MODE)
- /** FIXME: ??? */
- panic("sorry, can't support type 2 default yet");
-#endif /* APIC_MIXED_MODE */
- }
- else
- io_apic_ints[2].src_bus_irq = 0; /* ISA IRQ0 is on APIC INT 2 */
-
- if (type == 7)
- io_apic_ints[0].int_type = 0xff; /* N/C */
- else
- io_apic_ints[0].int_type = 3; /* vectored 8259 */
-#endif /* APIC_IO */
-}
-
-
-/*
- * start each AP in our list
- */
-static int
-start_all_aps(u_int boot_addr)
-{
- int x, i, pg;
-#ifndef PC98
- u_char mpbiosreason;
-#endif
- u_long mpbioswarmvec;
- struct pcpu *pc;
- char *stack;
- uintptr_t kptbase;
-
- POSTCODE(START_ALL_APS_POST);
-
- mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN);
-
- /* initialize BSP's local APIC */
- apic_initialize();
- bsp_apic_ready = 1;
-
- /* install the AP 1st level boot code */
- install_ap_tramp(boot_addr);
-
-
- /* save the current value of the warm-start vector */
- mpbioswarmvec = *((u_long *) WARMBOOT_OFF);
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- mpbiosreason = inb(CMOS_DATA);
-#endif
-
- /* set up temporary P==V mapping for AP boot */
- /* XXX this is a hack, we should boot the AP on its own stack/PTD */
- kptbase = (uintptr_t)(void *)KPTphys;
- for (x = 0; x < NKPT; x++)
- PTD[x] = (pd_entry_t)(PG_V | PG_RW |
- ((kptbase + x * PAGE_SIZE) & PG_FRAME));
- invltlb();
-
- /* start each AP */
- for (x = 1; x <= mp_naps; ++x) {
-
- /* This is a bit verbose, it will go away soon. */
-
- /* first page of AP's private space */
- pg = x * i386_btop(sizeof(struct privatespace));
-
- /* allocate a new private data page */
- pc = (struct pcpu *)kmem_alloc(kernel_map, PAGE_SIZE);
-
- /* wire it into the private page table page */
- SMPpt[pg] = (pt_entry_t)(PG_V | PG_RW | vtophys(pc));
-
- /* allocate and set up an idle stack data page */
- stack = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE); /* XXXKSE */
- for (i = 0; i < KSTACK_PAGES; i++)
- SMPpt[pg + 1 + i] = (pt_entry_t)
- (PG_V | PG_RW | vtophys(PAGE_SIZE * i + stack));
-
- /* prime data page for it to use */
- pcpu_init(pc, x, sizeof(struct pcpu));
-
- /* setup a vector to our boot code */
- *((volatile u_short *) WARMBOOT_OFF) = WARMBOOT_TARGET;
- *((volatile u_short *) WARMBOOT_SEG) = (boot_addr >> 4);
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- outb(CMOS_DATA, BIOS_WARM); /* 'warm-start' */
-#endif
-
- bootSTK = &SMP_prvspace[x].idlekstack[KSTACK_PAGES * PAGE_SIZE];
- bootAP = x;
-
- /* attempt to start the Application Processor */
- CHECK_INIT(99); /* setup checkpoints */
- if (!start_ap(x, boot_addr)) {
- printf("AP #%d (PHY# %d) failed!\n", x, CPU_TO_ID(x));
- CHECK_PRINT("trace"); /* show checkpoints */
- /* better panic as the AP may be running loose */
- printf("panic y/n? [y] ");
- if (cngetc() != 'n')
- panic("bye-bye");
- }
- CHECK_PRINT("trace"); /* show checkpoints */
-
- /* record its version info */
- cpu_apic_versions[x] = cpu_apic_versions[0];
-
- all_cpus |= (1 << x); /* record AP in CPU map */
- }
-
- /* build our map of 'other' CPUs */
- PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
-
- /* fill in our (BSP) APIC version */
- cpu_apic_versions[0] = lapic.version;
-
- /* restore the warmstart vector */
- *(u_long *) WARMBOOT_OFF = mpbioswarmvec;
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- outb(CMOS_DATA, mpbiosreason);
-#endif
-
- /*
- * Set up the idle context for the BSP. Similar to above except
- * that some was done by locore, some by pmap.c and some is implicit
- * because the BSP is cpu#0 and the page is initially zero, and also
- * because we can refer to variables by name on the BSP..
- */
-
- /* Allocate and setup BSP idle stack */
- stack = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE);
- for (i = 0; i < KSTACK_PAGES; i++)
- SMPpt[1 + i] = (pt_entry_t)
- (PG_V | PG_RW | vtophys(PAGE_SIZE * i + stack));
-
- for (x = 0; x < NKPT; x++)
- PTD[x] = 0;
- pmap_set_opt();
-
- /* number of APs actually started */
- return mp_ncpus - 1;
-}
-
-
-/*
- * load the 1st level AP boot code into base memory.
- */
-
-/* targets for relocation */
-extern void bigJump(void);
-extern void bootCodeSeg(void);
-extern void bootDataSeg(void);
-extern void MPentry(void);
-extern u_int MP_GDT;
-extern u_int mp_gdtbase;
-
-static void
-install_ap_tramp(u_int boot_addr)
-{
- int x;
- int size = *(int *) ((u_long) & bootMP_size);
- u_char *src = (u_char *) ((u_long) bootMP);
- u_char *dst = (u_char *) boot_addr + KERNBASE;
- u_int boot_base = (u_int) bootMP;
- u_int8_t *dst8;
- u_int16_t *dst16;
- u_int32_t *dst32;
-
- POSTCODE(INSTALL_AP_TRAMP_POST);
-
- for (x = 0; x < size; ++x)
- *dst++ = *src++;
-
- /*
- * modify addresses in code we just moved to basemem. unfortunately we
- * need fairly detailed info about mpboot.s for this to work. changes
- * to mpboot.s might require changes here.
- */
-
- /* boot code is located in KERNEL space */
- dst = (u_char *) boot_addr + KERNBASE;
-
- /* modify the lgdt arg */
- dst32 = (u_int32_t *) (dst + ((u_int) & mp_gdtbase - boot_base));
- *dst32 = boot_addr + ((u_int) & MP_GDT - boot_base);
-
- /* modify the ljmp target for MPentry() */
- dst32 = (u_int32_t *) (dst + ((u_int) bigJump - boot_base) + 1);
- *dst32 = ((u_int) MPentry - KERNBASE);
-
- /* modify the target for boot code segment */
- dst16 = (u_int16_t *) (dst + ((u_int) bootCodeSeg - boot_base));
- dst8 = (u_int8_t *) (dst16 + 1);
- *dst16 = (u_int) boot_addr & 0xffff;
- *dst8 = ((u_int) boot_addr >> 16) & 0xff;
-
- /* modify the target for boot data segment */
- dst16 = (u_int16_t *) (dst + ((u_int) bootDataSeg - boot_base));
- dst8 = (u_int8_t *) (dst16 + 1);
- *dst16 = (u_int) boot_addr & 0xffff;
- *dst8 = ((u_int) boot_addr >> 16) & 0xff;
-}
-
-
-/*
- * this function starts the AP (application processor) identified
- * by the APIC ID 'physicalCpu'. It does quite a "song and dance"
- * to accomplish this. This is necessary because of the nuances
- * of the different hardware we might encounter. It ain't pretty,
- * but it seems to work.
- */
-static int
-start_ap(int logical_cpu, u_int boot_addr)
-{
- int physical_cpu;
- int vector;
- int cpus;
- u_long icr_lo, icr_hi;
-
- POSTCODE(START_AP_POST);
-
- /* get the PHYSICAL APIC ID# */
- physical_cpu = CPU_TO_ID(logical_cpu);
-
- /* calculate the vector */
- vector = (boot_addr >> 12) & 0xff;
-
- /* used as a watchpoint to signal AP startup */
- cpus = mp_ncpus;
-
- /*
- * first we do an INIT/RESET IPI this INIT IPI might be run, reseting
- * and running the target CPU. OR this INIT IPI might be latched (P5
- * bug), CPU waiting for STARTUP IPI. OR this INIT IPI might be
- * ignored.
- */
-
- /* setup the address for the target AP */
- icr_hi = lapic.icr_hi & ~APIC_ID_MASK;
- icr_hi |= (physical_cpu << 24);
- lapic.icr_hi = icr_hi;
-
- /* do an INIT IPI: assert RESET */
- icr_lo = lapic.icr_lo & 0xfff00000;
- lapic.icr_lo = icr_lo | 0x0000c500;
-
- /* wait for pending status end */
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
-
- /* do an INIT IPI: deassert RESET */
- lapic.icr_lo = icr_lo | 0x00008500;
-
- /* wait for pending status end */
- u_sleep(10000); /* wait ~10mS */
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
-
- /*
- * next we do a STARTUP IPI: the previous INIT IPI might still be
- * latched, (P5 bug) this 1st STARTUP would then terminate
- * immediately, and the previously started INIT IPI would continue. OR
- * the previous INIT IPI has already run. and this STARTUP IPI will
- * run. OR the previous INIT IPI was ignored. and this STARTUP IPI
- * will run.
- */
-
- /* do a STARTUP IPI */
- lapic.icr_lo = icr_lo | 0x00000600 | vector;
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
- u_sleep(200); /* wait ~200uS */
-
- /*
- * finally we do a 2nd STARTUP IPI: this 2nd STARTUP IPI should run IF
- * the previous STARTUP IPI was cancelled by a latched INIT IPI. OR
- * this STARTUP IPI will be ignored, as only ONE STARTUP IPI is
- * recognized after hardware RESET or INIT IPI.
- */
-
- lapic.icr_lo = icr_lo | 0x00000600 | vector;
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
- u_sleep(200); /* wait ~200uS */
-
- /* wait for it to start */
- set_apic_timer(5000000);/* == 5 seconds */
- while (read_apic_timer())
- if (mp_ncpus > cpus)
- return 1; /* return SUCCESS */
-
- return 0; /* return FAILURE */
-}
-
-#if defined(APIC_IO)
-
-#ifdef COUNT_XINVLTLB_HITS
-u_int xhits_gbl[MAXCPU];
-u_int xhits_pg[MAXCPU];
-u_int xhits_rng[MAXCPU];
-SYSCTL_NODE(_debug, OID_AUTO, xhits, CTLFLAG_RW, 0, "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, global, CTLFLAG_RW, &xhits_gbl,
- sizeof(xhits_gbl), "IU", "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, page, CTLFLAG_RW, &xhits_pg,
- sizeof(xhits_pg), "IU", "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, range, CTLFLAG_RW, &xhits_rng,
- sizeof(xhits_rng), "IU", "");
-
-u_int ipi_global;
-u_int ipi_page;
-u_int ipi_range;
-u_int ipi_range_size;
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_global, CTLFLAG_RW, &ipi_global, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_page, CTLFLAG_RW, &ipi_page, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range, CTLFLAG_RW, &ipi_range, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range_size, CTLFLAG_RW, &ipi_range_size,
- 0, "");
-
-u_int ipi_masked_global;
-u_int ipi_masked_page;
-u_int ipi_masked_range;
-u_int ipi_masked_range_size;
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_global, CTLFLAG_RW,
- &ipi_masked_global, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_page, CTLFLAG_RW,
- &ipi_masked_page, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range, CTLFLAG_RW,
- &ipi_masked_range, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range_size, CTLFLAG_RW,
- &ipi_masked_range_size, 0, "");
-#endif
-
-/*
- * Flush the TLB on all other CPU's
- */
-static void
-smp_tlb_shootdown(u_int vector, vm_offset_t addr1, vm_offset_t addr2)
-{
- u_int ncpu;
- register_t eflags;
-
- ncpu = mp_ncpus - 1; /* does not shootdown self */
- if (ncpu < 1)
- return; /* no other cpus */
- eflags = read_eflags();
- if ((eflags & PSL_I) == 0)
- panic("absolutely cannot call smp_ipi_shootdown with interrupts already disabled");
- mtx_lock_spin(&smp_tlb_mtx);
- smp_tlb_addr1 = addr1;
- smp_tlb_addr2 = addr2;
- atomic_store_rel_int(&smp_tlb_wait, 0);
- ipi_all_but_self(vector);
- while (smp_tlb_wait < ncpu)
- ia32_pause();
- mtx_unlock_spin(&smp_tlb_mtx);
-}
-
-/*
- * This is about as magic as it gets. fortune(1) has got similar code
- * for reversing bits in a word. Who thinks up this stuff??
- *
- * Yes, it does appear to be consistently faster than:
- * while (i = ffs(m)) {
- * m >>= i;
- * bits++;
- * }
- * and
- * while (lsb = (m & -m)) { // This is magic too
- * m &= ~lsb; // or: m ^= lsb
- * bits++;
- * }
- * Both of these latter forms do some very strange things on gcc-3.1 with
- * -mcpu=pentiumpro and/or -march=pentiumpro and/or -O or -O2.
- * There is probably an SSE or MMX popcnt instruction.
- *
- * I wonder if this should be in libkern?
- *
- * XXX Stop the presses! Another one:
- * static __inline u_int32_t
- * popcnt1(u_int32_t v)
- * {
- * v -= ((v >> 1) & 0x55555555);
- * v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
- * v = (v + (v >> 4)) & 0x0F0F0F0F;
- * return (v * 0x01010101) >> 24;
- * }
- * The downside is that it has a multiply. With a pentium3 with
- * -mcpu=pentiumpro and -march=pentiumpro then gcc-3.1 will use
- * an imull, and in that case it is faster. In most other cases
- * it appears slightly slower.
- */
-static __inline u_int32_t
-popcnt(u_int32_t m)
-{
-
- m = (m & 0x55555555) + ((m & 0xaaaaaaaa) >> 1);
- m = (m & 0x33333333) + ((m & 0xcccccccc) >> 2);
- m = (m & 0x0f0f0f0f) + ((m & 0xf0f0f0f0) >> 4);
- m = (m & 0x00ff00ff) + ((m & 0xff00ff00) >> 8);
- m = (m & 0x0000ffff) + ((m & 0xffff0000) >> 16);
- return m;
-}
-
-static void
-smp_targeted_tlb_shootdown(u_int mask, u_int vector, vm_offset_t addr1, vm_offset_t addr2)
-{
- int ncpu, othercpus;
- register_t eflags;
-
- othercpus = mp_ncpus - 1;
- if (mask == (u_int)-1) {
- ncpu = othercpus;
- if (ncpu < 1)
- return;
- } else {
- /* XXX there should be a pcpu self mask */
- mask &= ~(1 << PCPU_GET(cpuid));
- if (mask == 0)
- return;
- ncpu = popcnt(mask);
- if (ncpu > othercpus) {
- /* XXX this should be a panic offence */
- printf("SMP: tlb shootdown to %d other cpus (only have %d)\n",
- ncpu, othercpus);
- ncpu = othercpus;
- }
- /* XXX should be a panic, implied by mask == 0 above */
- if (ncpu < 1)
- return;
- }
- eflags = read_eflags();
- if ((eflags & PSL_I) == 0)
- panic("absolutely cannot call smp_targeted_ipi_shootdown with interrupts already disabled");
- mtx_lock_spin(&smp_tlb_mtx);
- smp_tlb_addr1 = addr1;
- smp_tlb_addr2 = addr2;
- atomic_store_rel_int(&smp_tlb_wait, 0);
- if (mask == (u_int)-1)
- ipi_all_but_self(vector);
- else
- ipi_selected(mask, vector);
- while (smp_tlb_wait < ncpu)
- ia32_pause();
- mtx_unlock_spin(&smp_tlb_mtx);
-}
-#endif
-
-void
-smp_invltlb(void)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLTLB, 0, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_global++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_invlpg(vm_offset_t addr)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLPG, addr, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_page++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_invlpg_range(vm_offset_t addr1, vm_offset_t addr2)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLRNG, addr1, addr2);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_range++;
- ipi_range_size += (addr2 - addr1) / PAGE_SIZE;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invltlb(u_int mask)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLTLB, 0, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_global++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invlpg(u_int mask, vm_offset_t addr)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLPG, addr, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_page++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invlpg_range(u_int mask, vm_offset_t addr1, vm_offset_t addr2)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLRNG, addr1, addr2);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_range++;
- ipi_masked_range_size += (addr2 - addr1) / PAGE_SIZE;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-
-/*
- * This is called once the rest of the system is up and running and we're
- * ready to let the AP's out of the pen.
- */
-void
-ap_init(void)
-{
- u_int apic_id;
-
- /* spin until all the AP's are ready */
- while (!aps_ready)
- ia32_pause();
-
- /* BSP may have changed PTD while we were waiting */
- invltlb();
-
-#if defined(I586_CPU) && !defined(NO_F00F_HACK)
- lidt(&r_idt);
-#endif
-
- /* set up CPU registers and state */
- cpu_setregs();
-
- /* set up FPU state on the AP */
- npxinit(__INITIAL_NPXCW__);
-
- /* set up SSE registers */
- enable_sse();
-
- /* A quick check from sanity claus */
- apic_id = (apic_id_to_logical[(lapic.id & 0x0f000000) >> 24]);
- if (PCPU_GET(cpuid) != apic_id) {
- printf("SMP: cpuid = %d\n", PCPU_GET(cpuid));
- printf("SMP: apic_id = %d\n", apic_id);
- printf("PTD[MPPTDI] = %#jx\n", (uintmax_t)PTD[MPPTDI]);
- panic("cpuid mismatch! boom!!");
- }
-
- /* Init local apic for irq's */
- apic_initialize();
-
- /* Set memory range attributes for this CPU to match the BSP */
- mem_range_AP_init();
-
- mtx_lock_spin(&ap_boot_mtx);
-
- smp_cpus++;
-
- CTR1(KTR_SMP, "SMP: AP CPU #%d Launched", PCPU_GET(cpuid));
- printf("SMP: AP CPU #%d Launched!\n", PCPU_GET(cpuid));
-
- /* Build our map of 'other' CPUs. */
- PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
-
- if (bootverbose)
- apic_dump("ap_init()");
-
- if (smp_cpus == mp_ncpus) {
- /* enable IPI's, tlb shootdown, freezes etc */
- atomic_store_rel_int(&smp_started, 1);
- smp_active = 1; /* historic */
- }
-
- mtx_unlock_spin(&ap_boot_mtx);
-
- /* wait until all the AP's are up */
- while (smp_started == 0)
- ia32_pause();
-
- /* ok, now grab sched_lock and enter the scheduler */
- mtx_lock_spin(&sched_lock);
-
- binuptime(PCPU_PTR(switchtime));
- PCPU_SET(switchticks, ticks);
-
- cpu_throw(NULL, choosethread()); /* doesn't return */
-
- panic("scheduler returned us to %s", __func__);
-}
-
-/*
- * For statclock, we send an IPI to all CPU's to have them call this
- * function.
- *
- * WARNING! unpend() will call statclock() directly and skip this
- * routine.
- */
-void
-forwarded_statclock(struct clockframe frame)
-{
-
- if (profprocs != 0)
- profclock(&frame);
- if (pscnt == psdiv)
- statclock(&frame);
-}
-
-void
-forward_statclock(void)
-{
- int map;
-
- CTR0(KTR_SMP, "forward_statclock");
-
- if (!smp_started || cold || panicstr)
- return;
-
- map = PCPU_GET(other_cpus) & ~stopped_cpus ;
- if (map != 0)
- ipi_selected(map, IPI_STATCLOCK);
-}
-
-/*
- * For each hardclock(), we send an IPI to all other CPU's to have them
- * execute this function. It would be nice to reduce contention on
- * sched_lock if we could simply peek at the CPU to determine the user/kernel
- * state and call hardclock_process() on the CPU receiving the clock interrupt
- * and then just use a simple IPI to handle any ast's if needed.
- *
- * WARNING! unpend() will call hardclock_process() directly and skip this
- * routine.
- */
-void
-forwarded_hardclock(struct clockframe frame)
-{
-
- hardclock_process(&frame);
-}
-
-void
-forward_hardclock(void)
-{
- u_int map;
-
- CTR0(KTR_SMP, "forward_hardclock");
-
- if (!smp_started || cold || panicstr)
- return;
-
- map = PCPU_GET(other_cpus) & ~stopped_cpus ;
- if (map != 0)
- ipi_selected(map, IPI_HARDCLOCK);
-}
-
-#ifdef APIC_INTR_REORDER
-/*
- * Maintain mapping from softintr vector to isr bit in local apic.
- */
-void
-set_lapic_isrloc(int intr, int vector)
-{
- if (intr < 0 || intr > 32)
- panic("set_apic_isrloc: bad intr argument: %d",intr);
- if (vector < ICU_OFFSET || vector > 255)
- panic("set_apic_isrloc: bad vector argument: %d",vector);
- apic_isrbit_location[intr].location = &lapic.isr0 + ((vector>>5)<<2);
- apic_isrbit_location[intr].bit = (1<<(vector & 31));
-}
-#endif
-
-/*
- * send an IPI to a set of cpus.
- */
-void
-ipi_selected(u_int32_t cpus, u_int ipi)
-{
-
- CTR3(KTR_SMP, "%s: cpus: %x ipi: %x", __func__, cpus, ipi);
- selected_apic_ipi(cpus, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI INTerrupt containing 'vector' to all CPUs, including myself
- */
-void
-ipi_all(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_ALLISELF, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI to all CPUs EXCEPT myself
- */
-void
-ipi_all_but_self(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_ALLESELF, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI to myself
- */
-void
-ipi_self(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_SELF, ipi, APIC_DELMODE_FIXED);
-}
-
-static void
-release_aps(void *dummy __unused)
-{
-
- if (mp_ncpus == 1)
- return;
- mtx_lock_spin(&sched_lock);
- atomic_store_rel_int(&aps_ready, 1);
- while (smp_started == 0)
- ia32_pause();
- mtx_unlock_spin(&sched_lock);
-}
-
-SYSINIT(start_aps, SI_SUB_SMP, SI_ORDER_FIRST, release_aps, NULL);
-
-static int hlt_cpus_mask;
-static int hlt_logical_cpus = 1;
-static struct sysctl_ctx_list logical_cpu_clist;
-
-static int
-sysctl_hlt_cpus(SYSCTL_HANDLER_ARGS)
-{
- u_int mask;
- int error;
-
- mask = hlt_cpus_mask;
- error = sysctl_handle_int(oidp, &mask, 0, req);
- if (error || !req->newptr)
- return (error);
-
- if (logical_cpus_mask != 0 &&
- (mask & logical_cpus_mask) == logical_cpus_mask)
- hlt_logical_cpus = 1;
- else
- hlt_logical_cpus = 0;
-
- if ((mask & all_cpus) == all_cpus)
- mask &= ~(1<<0);
- hlt_cpus_mask = mask;
- return (error);
-}
-SYSCTL_PROC(_machdep, OID_AUTO, hlt_cpus, CTLTYPE_INT|CTLFLAG_RW,
- 0, 0, sysctl_hlt_cpus, "IU", "");
-
-static int
-sysctl_hlt_logical_cpus(SYSCTL_HANDLER_ARGS)
-{
- int disable, error;
-
- disable = hlt_logical_cpus;
- error = sysctl_handle_int(oidp, &disable, 0, req);
- if (error || !req->newptr)
- return (error);
-
- if (disable)
- hlt_cpus_mask |= logical_cpus_mask;
- else
- hlt_cpus_mask &= ~logical_cpus_mask;
-
- if ((hlt_cpus_mask & all_cpus) == all_cpus)
- hlt_cpus_mask &= ~(1<<0);
-
- hlt_logical_cpus = disable;
- return (error);
-}
-
-static void
-cpu_hlt_setup(void *dummy __unused)
-{
-
- if (logical_cpus_mask != 0) {
- TUNABLE_INT_FETCH("machdep.hlt_logical_cpus",
- &hlt_logical_cpus);
- sysctl_ctx_init(&logical_cpu_clist);
- SYSCTL_ADD_PROC(&logical_cpu_clist,
- SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
- "hlt_logical_cpus", CTLTYPE_INT|CTLFLAG_RW, 0, 0,
- sysctl_hlt_logical_cpus, "IU", "");
- SYSCTL_ADD_UINT(&logical_cpu_clist,
- SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
- "logical_cpus_mask", CTLTYPE_INT|CTLFLAG_RD,
- &logical_cpus_mask, 0, "");
-
- if (hlt_logical_cpus)
- hlt_cpus_mask |= logical_cpus_mask;
- }
-}
-SYSINIT(cpu_hlt, SI_SUB_SMP, SI_ORDER_ANY, cpu_hlt_setup, NULL);
-
-int
-mp_grab_cpu_hlt(void)
-{
- u_int mask = PCPU_GET(cpumask);
- int retval;
-
- retval = mask & hlt_cpus_mask;
- while (mask & hlt_cpus_mask)
- __asm __volatile("sti; hlt" : : : "memory");
- return (retval);
-}
diff --git a/sys/amd64/amd64/prof_machdep.c b/sys/amd64/amd64/prof_machdep.c
deleted file mode 100644
index 65d35f832e47..000000000000
--- a/sys/amd64/amd64/prof_machdep.c
+++ /dev/null
@@ -1,359 +0,0 @@
-/*-
- * Copyright (c) 1996 Bruce D. Evans.
- * 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$
- */
-
-#ifdef GUPROF
-#include "opt_i586_guprof.h"
-#include "opt_perfmon.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/gmon.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-
-#include <machine/clock.h>
-#include <machine/perfmon.h>
-#include <machine/profile.h>
-#undef MCOUNT
-#endif
-
-#include <machine/asmacros.h>
-
-#ifdef PC98
-#include <pc98/pc98/pc98.h>
-#else
-#include <i386/isa/isa.h>
-#endif
-#include <i386/isa/timerreg.h>
-
-#ifdef GUPROF
-#define CPUTIME_CLOCK_UNINITIALIZED 0
-#define CPUTIME_CLOCK_I8254 1
-#define CPUTIME_CLOCK_TSC 2
-#define CPUTIME_CLOCK_I586_PMC 3
-#define CPUTIME_CLOCK_I8254_SHIFT 7
-
-int cputime_bias = 1; /* initialize for locality of reference */
-
-static int cputime_clock = CPUTIME_CLOCK_UNINITIALIZED;
-#ifdef I586_PMC_GUPROF
-static u_int cputime_clock_pmc_conf = I586_PMC_GUPROF;
-static int cputime_clock_pmc_init;
-static struct gmonparam saved_gmp;
-#endif
-#endif /* GUPROF */
-
-#ifdef __GNUC__
-__asm(" \n\
-GM_STATE = 0 \n\
-GMON_PROF_OFF = 3 \n\
- \n\
- .text \n\
- .p2align 4,0x90 \n\
- .globl __mcount \n\
- .type __mcount,@function \n\
-__mcount: \n\
- # \n\
- # Check that we are profiling. Do it early for speed. \n\
- # \n\
- cmpl $GMON_PROF_OFF," __XSTRING(CNAME(_gmonparam)) "+GM_STATE \n\
- je .mcount_exit \n\
- # \n\
- # __mcount is the same as [.]mcount except the caller \n\
- # hasn't changed the stack except to call here, so the \n\
- # caller's raddr is above our raddr. \n\
- # \n\
- movl 4(%esp),%edx \n\
- jmp .got_frompc \n\
- \n\
- .p2align 4,0x90 \n\
- .globl " __XSTRING(HIDENAME(mcount)) " \n\
-" __XSTRING(HIDENAME(mcount)) ": \n\
- .globl __cyg_profile_func_enter \n\
-__cyg_profile_func_enter: \n\
- cmpl $GMON_PROF_OFF," __XSTRING(CNAME(_gmonparam)) "+GM_STATE \n\
- je .mcount_exit \n\
- # \n\
- # The caller's stack frame has already been built, so \n\
- # %ebp is the caller's frame pointer. The caller's \n\
- # raddr is in the caller's frame following the caller's \n\
- # caller's frame pointer. \n\
- # \n\
- movl 4(%ebp),%edx \n\
-.got_frompc: \n\
- # \n\
- # Our raddr is the caller's pc. \n\
- # \n\
- movl (%esp),%eax \n\
- \n\
- pushfl \n\
- pushl %eax \n\
- pushl %edx \n\
- cli \n\
- call " __XSTRING(CNAME(mcount)) " \n\
- addl $8,%esp \n\
- popfl \n\
-.mcount_exit: \n\
- ret \n\
-");
-#else /* !__GNUC__ */
-#error
-#endif /* __GNUC__ */
-
-#ifdef GUPROF
-/*
- * [.]mexitcount saves the return register(s), loads selfpc and calls
- * mexitcount(selfpc) to do the work. Someday it should be in a machine
- * dependent file together with cputime(), __mcount and [.]mcount. cputime()
- * can't just be put in machdep.c because it has to be compiled without -pg.
- */
-#ifdef __GNUC__
-__asm(" \n\
- .text \n\
-# \n\
-# Dummy label to be seen when gprof -u hides [.]mexitcount. \n\
-# \n\
- .p2align 4,0x90 \n\
- .globl __mexitcount \n\
- .type __mexitcount,@function \n\
-__mexitcount: \n\
- nop \n\
- \n\
-GMON_PROF_HIRES = 4 \n\
- \n\
- .p2align 4,0x90 \n\
- .globl " __XSTRING(HIDENAME(mexitcount)) " \n\
-" __XSTRING(HIDENAME(mexitcount)) ": \n\
- .globl __cyg_profile_func_exit \n\
-__cyg_profile_func_exit: \n\
- cmpl $GMON_PROF_HIRES," __XSTRING(CNAME(_gmonparam)) "+GM_STATE \n\
- jne .mexitcount_exit \n\
- pushl %edx \n\
- pushl %eax \n\
- movl 8(%esp),%eax \n\
- pushfl \n\
- pushl %eax \n\
- cli \n\
- call " __XSTRING(CNAME(mexitcount)) " \n\
- addl $4,%esp \n\
- popfl \n\
- popl %eax \n\
- popl %edx \n\
-.mexitcount_exit: \n\
- ret \n\
-");
-#else /* !__GNUC__ */
-#error
-#endif /* __GNUC__ */
-
-/*
- * Return the time elapsed since the last call. The units are machine-
- * dependent.
- */
-int
-cputime()
-{
- u_int count;
- int delta;
-#if (defined(I586_CPU) || defined(I686_CPU)) && !defined(SMP) && \
- defined(PERFMON) && defined(I586_PMC_GUPROF)
- u_quad_t event_count;
-#endif
- u_char high, low;
- static u_int prev_count;
-
-#if (defined(I586_CPU) || defined(I686_CPU)) && !defined(SMP)
- if (cputime_clock == CPUTIME_CLOCK_TSC) {
- count = (u_int)rdtsc();
- delta = (int)(count - prev_count);
- prev_count = count;
- return (delta);
- }
-#if defined(PERFMON) && defined(I586_PMC_GUPROF)
- if (cputime_clock == CPUTIME_CLOCK_I586_PMC) {
- /*
- * XXX permon_read() should be inlined so that the
- * perfmon module doesn't need to be compiled with
- * profiling disabled and so that it is fast.
- */
- perfmon_read(0, &event_count);
-
- count = (u_int)event_count;
- delta = (int)(count - prev_count);
- prev_count = count;
- return (delta);
- }
-#endif /* PERFMON && I586_PMC_GUPROF */
-#endif /* (I586_CPU || I686_CPU) && !SMP */
-
- /*
- * Read the current value of the 8254 timer counter 0.
- */
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
- low = inb(TIMER_CNTR0);
- high = inb(TIMER_CNTR0);
- count = ((high << 8) | low) << CPUTIME_CLOCK_I8254_SHIFT;
-
- /*
- * The timer counts down from TIMER_CNTR0_MAX to 0 and then resets.
- * While profiling is enabled, this routine is called at least twice
- * per timer reset (for mcounting and mexitcounting hardclock()),
- * so at most one reset has occurred since the last call, and one
- * has occurred iff the current count is larger than the previous
- * count. This allows counter underflow to be detected faster
- * than in microtime().
- */
- delta = prev_count - count;
- prev_count = count;
- if ((int) delta <= 0)
- return (delta + (timer0_max_count << CPUTIME_CLOCK_I8254_SHIFT));
- return (delta);
-}
-
-static int
-sysctl_machdep_cputime_clock(SYSCTL_HANDLER_ARGS)
-{
- int clock;
- int error;
-#if defined(PERFMON) && defined(I586_PMC_GUPROF)
- int event;
- struct pmc pmc;
-#endif
-
- clock = cputime_clock;
-#if defined(PERFMON) && defined(I586_PMC_GUPROF)
- if (clock == CPUTIME_CLOCK_I586_PMC) {
- pmc.pmc_val = cputime_clock_pmc_conf;
- clock += pmc.pmc_event;
- }
-#endif
- error = sysctl_handle_opaque(oidp, &clock, sizeof clock, req);
- if (error == 0 && req->newptr != NULL) {
-#if defined(PERFMON) && defined(I586_PMC_GUPROF)
- if (clock >= CPUTIME_CLOCK_I586_PMC) {
- event = clock - CPUTIME_CLOCK_I586_PMC;
- if (event >= 256)
- return (EINVAL);
- pmc.pmc_num = 0;
- pmc.pmc_event = event;
- pmc.pmc_unit = 0;
- pmc.pmc_flags = PMCF_E | PMCF_OS | PMCF_USR;
- pmc.pmc_mask = 0;
- cputime_clock_pmc_conf = pmc.pmc_val;
- cputime_clock = CPUTIME_CLOCK_I586_PMC;
- } else
-#endif
- {
- if (clock < 0 || clock >= CPUTIME_CLOCK_I586_PMC)
- return (EINVAL);
- cputime_clock = clock;
- }
- }
- return (error);
-}
-
-SYSCTL_PROC(_machdep, OID_AUTO, cputime_clock, CTLTYPE_INT | CTLFLAG_RW,
- 0, sizeof(u_int), sysctl_machdep_cputime_clock, "I", "");
-
-/*
- * The start and stop routines need not be here since we turn off profiling
- * before calling them. They are here for convenience.
- */
-
-void
-startguprof(gp)
- struct gmonparam *gp;
-{
- if (cputime_clock == CPUTIME_CLOCK_UNINITIALIZED) {
- cputime_clock = CPUTIME_CLOCK_I8254;
-#if (defined(I586_CPU) || defined(I686_CPU)) && !defined(SMP)
- if (tsc_freq != 0)
- cputime_clock = CPUTIME_CLOCK_TSC;
-#endif
- }
- gp->profrate = timer_freq << CPUTIME_CLOCK_I8254_SHIFT;
-#if (defined(I586_CPU) || defined(I686_CPU)) && !defined(SMP)
- if (cputime_clock == CPUTIME_CLOCK_TSC)
- gp->profrate = tsc_freq;
-#if defined(PERFMON) && defined(I586_PMC_GUPROF)
- else if (cputime_clock == CPUTIME_CLOCK_I586_PMC) {
- if (perfmon_avail() &&
- perfmon_setup(0, cputime_clock_pmc_conf) == 0) {
- if (perfmon_start(0) != 0)
- perfmon_fini(0);
- else {
- /* XXX 1 event == 1 us. */
- gp->profrate = 1000000;
-
- saved_gmp = *gp;
-
- /* Zap overheads. They are invalid. */
- gp->cputime_overhead = 0;
- gp->mcount_overhead = 0;
- gp->mcount_post_overhead = 0;
- gp->mcount_pre_overhead = 0;
- gp->mexitcount_overhead = 0;
- gp->mexitcount_post_overhead = 0;
- gp->mexitcount_pre_overhead = 0;
-
- cputime_clock_pmc_init = TRUE;
- }
- }
- }
-#endif /* PERFMON && I586_PMC_GUPROF */
-#endif /* (I586_CPU || I686_CPU) && !SMP */
- cputime_bias = 0;
- cputime();
-}
-
-void
-stopguprof(gp)
- struct gmonparam *gp;
-{
-#if defined(PERFMON) && defined(I586_PMC_GUPROF)
- if (cputime_clock_pmc_init) {
- *gp = saved_gmp;
- perfmon_fini(0);
- cputime_clock_pmc_init = FALSE;
- }
-#endif
-}
-
-#else /* !GUPROF */
-#ifdef __GNUC__
-__asm(" \n\
- .text \n\
- .p2align 4,0x90 \n\
- .globl " __XSTRING(HIDENAME(mexitcount)) " \n\
-" __XSTRING(HIDENAME(mexitcount)) ": \n\
- ret \n\
-");
-#else /* !__GNUC__ */
-#error
-#endif /* __GNUC__ */
-#endif /* GUPROF */
diff --git a/sys/amd64/ia32/ia32_sigtramp.S b/sys/amd64/ia32/ia32_sigtramp.S
deleted file mode 100644
index 2e9f73d41bce..000000000000
--- a/sys/amd64/ia32/ia32_sigtramp.S
+++ /dev/null
@@ -1,87 +0,0 @@
-/*-
- * Copyright (c) 2003 Peter Wemm
- * 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$
- */
-
-#include "opt_compat.h"
-
-#include <machine/asmacros.h>
-#include <sys/syscall.h>
-
-#include "ia32_assym.h"
-
- .text
- .code32
-/*
- * Signal trampoline, copied to top of user stack
- */
- ALIGN_TEXT
- .globl ia32_sigcode
-ia32_sigcode:
- calll *IA32_SIGF_HANDLER(%esp)
- leal IA32_SIGF_UC(%esp),%eax /* get ucontext */
- pushl %eax
- movl IA32_UC_GS(%eax),%gs /* restore %gs */
- movl IA32_UC_FS(%eax),%fs /* restore %fs */
- movl IA32_UC_ES(%eax),%es /* restore %es */
- movl IA32_UC_DS(%eax),%ds /* restore %ds */
- movl $SYS_sigreturn,%eax
- pushl %eax /* junk to fake return addr. */
- int $0x80 /* enter kernel with args */
- /* on stack */
-1:
- jmp 1b
-
-#ifdef COMPAT_FREEBSD4
- ALIGN_TEXT
-freebsd4_ia32_sigcode:
- calll *IA32_SIGF_HANDLER(%esp)
- leal IA32_SIGF_UC4(%esp),%eax/* get ucontext */
- pushl %eax
- movl IA32_UC4_GS(%eax),%gs /* restore %gs */
- movl IA32_UC4_FS(%eax),%fs /* restore %fs */
- movl IA32_UC4_ES(%eax),%es /* restore %es */
- movl IA32_UC4_DS(%eax),%ds /* restore %ds */
- movl $344,%eax /* 4.x SYS_sigreturn */
- pushl %eax /* junk to fake return addr. */
- int $0x80 /* enter kernel with args */
- /* on stack */
-1:
- jmp 1b
-#endif
-
- ALIGN_TEXT
-esigcode:
-
- .data
- .globl sz_ia32_sigcode
-sz_ia32_sigcode:
- .long esigcode-ia32_sigcode
-#ifdef COMPAT_FREEBSD4
- .globl sz_freebsd4_ia32_sigcode
-sz_freebsd4_ia32_sigcode:
- .long esigcode-freebsd4_ia32_sigcode
-#endif
diff --git a/sys/amd64/include/apicreg.h b/sys/amd64/include/apicreg.h
deleted file mode 100644
index e72ffb16063d..000000000000
--- a/sys/amd64/include/apicreg.h
+++ /dev/null
@@ -1,444 +0,0 @@
-/*
- * Copyright (c) 1996, by Peter Wemm and 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_APIC_H_
-#define _MACHINE_APIC_H_
-
-/*
- * Local && I/O APIC definitions.
- */
-
-/*
- * Pentium P54C+ Build-in APIC
- * (Advanced programmable Interrupt Controller)
- *
- * Base Address of Build-in APIC in memory location
- * is 0xfee00000.
- *
- * Map of APIC REgisters:
- *
- * Offset (hex) Description Read/Write state
- * 000 Reserved
- * 010 Reserved
- * 020 ID Local APIC ID R/W
- * 030 VER Local APIC Version R
- * 040 Reserved
- * 050 Reserved
- * 060 Reserved
- * 070 Reserved
- * 080 Task Priority Register R/W
- * 090 Arbitration Priority Register R
- * 0A0 Processor Priority Register R
- * 0B0 EOI Register W
- * 0C0 RRR Remote read R
- * 0D0 Logical Destination R/W
- * 0E0 Destination Format Register 0..27 R; 28..31 R/W
- * 0F0 SVR Spurious Interrupt Vector Reg. 0..3 R; 4..9 R/W
- * 100 ISR 000-031 R
- * 110 ISR 032-063 R
- * 120 ISR 064-095 R
- * 130 ISR 095-128 R
- * 140 ISR 128-159 R
- * 150 ISR 160-191 R
- * 160 ISR 192-223 R
- * 170 ISR 224-255 R
- * 180 TMR 000-031 R
- * 190 TMR 032-063 R
- * 1A0 TMR 064-095 R
- * 1B0 TMR 095-128 R
- * 1C0 TMR 128-159 R
- * 1D0 TMR 160-191 R
- * 1E0 TMR 192-223 R
- * 1F0 TMR 224-255 R
- * 200 IRR 000-031 R
- * 210 IRR 032-063 R
- * 220 IRR 064-095 R
- * 230 IRR 095-128 R
- * 240 IRR 128-159 R
- * 250 IRR 160-191 R
- * 260 IRR 192-223 R
- * 270 IRR 224-255 R
- * 280 Error Status Register R
- * 290 Reserved
- * 2A0 Reserved
- * 2B0 Reserved
- * 2C0 Reserved
- * 2D0 Reserved
- * 2E0 Reserved
- * 2F0 Reserved
- * 300 ICR_LOW Interrupt Command Reg. (0-31) R/W
- * 310 ICR_HI Interrupt Command Reg. (32-63) R/W
- * 320 Local Vector Table (Timer) R/W
- * 330 Reserved
- * 340 Reserved
- * 350 LVT1 Local Vector Table (LINT0) R/W
- * 360 LVT2 Local Vector Table (LINT1) R/W
- * 370 LVT3 Local Vector Table (ERROR) R/W
- * 380 Initial Count Reg. for Timer R/W
- * 390 Current Count of Timer R
- * 3A0 Reserved
- * 3B0 Reserved
- * 3C0 Reserved
- * 3D0 Reserved
- * 3E0 Timer Divide Configuration Reg. R/W
- * 3F0 Reserved
- */
-
-
-/******************************************************************************
- * global defines, etc.
- */
-
-
-/******************************************************************************
- * LOCAL APIC structure
- */
-
-#ifndef LOCORE
-#include <sys/types.h>
-
-#define PAD3 int : 32; int : 32; int : 32
-#define PAD4 int : 32; int : 32; int : 32; int : 32
-
-struct LAPIC {
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- u_int32_t id; PAD3;
- u_int32_t version; PAD3;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- u_int32_t tpr; PAD3;
- u_int32_t apr; PAD3;
- u_int32_t ppr; PAD3;
- u_int32_t eoi; PAD3;
- /* reserved */ PAD4;
- u_int32_t ldr; PAD3;
- u_int32_t dfr; PAD3;
- u_int32_t svr; PAD3;
- u_int32_t isr0; PAD3;
- u_int32_t isr1; PAD3;
- u_int32_t isr2; PAD3;
- u_int32_t isr3; PAD3;
- u_int32_t isr4; PAD3;
- u_int32_t isr5; PAD3;
- u_int32_t isr6; PAD3;
- u_int32_t isr7; PAD3;
- u_int32_t tmr0; PAD3;
- u_int32_t tmr1; PAD3;
- u_int32_t tmr2; PAD3;
- u_int32_t tmr3; PAD3;
- u_int32_t tmr4; PAD3;
- u_int32_t tmr5; PAD3;
- u_int32_t tmr6; PAD3;
- u_int32_t tmr7; PAD3;
- u_int32_t irr0; PAD3;
- u_int32_t irr1; PAD3;
- u_int32_t irr2; PAD3;
- u_int32_t irr3; PAD3;
- u_int32_t irr4; PAD3;
- u_int32_t irr5; PAD3;
- u_int32_t irr6; PAD3;
- u_int32_t irr7; PAD3;
- u_int32_t esr; PAD3;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- u_int32_t icr_lo; PAD3;
- u_int32_t icr_hi; PAD3;
- u_int32_t lvt_timer; PAD3;
- /* reserved */ PAD4;
- u_int32_t lvt_pcint; PAD3;
- u_int32_t lvt_lint0; PAD3;
- u_int32_t lvt_lint1; PAD3;
- u_int32_t lvt_error; PAD3;
- u_int32_t icr_timer; PAD3;
- u_int32_t ccr_timer; PAD3;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- u_int32_t dcr_timer; PAD3;
- /* reserved */ PAD4;
-};
-
-typedef struct LAPIC lapic_t;
-
-/******************************************************************************
- * I/O APIC structure
- */
-
-struct IOAPIC {
- u_int32_t ioregsel; PAD3;
- u_int32_t iowin; PAD3;
-};
-
-typedef struct IOAPIC ioapic_t;
-
-#undef PAD4
-#undef PAD3
-
-#endif /* !LOCORE */
-
-
-/******************************************************************************
- * various code 'logical' values
- */
-
-/******************************************************************************
- * LOCAL APIC defines
- */
-
-/* default physical locations of LOCAL (CPU) APICs */
-#define DEFAULT_APIC_BASE 0xfee00000
-
-/* fields in VER */
-#define APIC_VER_VERSION 0x000000ff
-#define APIC_VER_MAXLVT 0x00ff0000
-#define MAXLVTSHIFT 16
-
-/* fields in SVR */
-#define APIC_SVR_VECTOR 0x000000ff
-#define APIC_SVR_VEC_PROG 0x000000f0
-#define APIC_SVR_VEC_FIX 0x0000000f
-#define APIC_SVR_ENABLE 0x00000100
-# define APIC_SVR_SWDIS 0x00000000
-# define APIC_SVR_SWEN 0x00000100
-#define APIC_SVR_FOCUS 0x00000200
-# define APIC_SVR_FEN 0x00000000
-# define APIC_SVR_FDIS 0x00000200
-
-/* fields in TPR */
-#define APIC_TPR_PRIO 0x000000ff
-# define APIC_TPR_INT 0x000000f0
-# define APIC_TPR_SUB 0x0000000f
-
-
-/* fields in ICR_LOW */
-#define APIC_VECTOR_MASK 0x000000ff
-
-#define APIC_DELMODE_MASK 0x00000700
-# define APIC_DELMODE_FIXED 0x00000000
-# define APIC_DELMODE_LOWPRIO 0x00000100
-# define APIC_DELMODE_SMI 0x00000200
-# define APIC_DELMODE_RR 0x00000300
-# define APIC_DELMODE_NMI 0x00000400
-# define APIC_DELMODE_INIT 0x00000500
-# define APIC_DELMODE_STARTUP 0x00000600
-# define APIC_DELMODE_RESV 0x00000700
-
-#define APIC_DESTMODE_MASK 0x00000800
-# define APIC_DESTMODE_PHY 0x00000000
-# define APIC_DESTMODE_LOG 0x00000800
-
-#define APIC_DELSTAT_MASK 0x00001000
-# define APIC_DELSTAT_IDLE 0x00000000
-# define APIC_DELSTAT_PEND 0x00001000
-
-#define APIC_RESV1_MASK 0x00002000
-
-#define APIC_LEVEL_MASK 0x00004000
-# define APIC_LEVEL_DEASSERT 0x00000000
-# define APIC_LEVEL_ASSERT 0x00004000
-
-#define APIC_TRIGMOD_MASK 0x00008000
-# define APIC_TRIGMOD_EDGE 0x00000000
-# define APIC_TRIGMOD_LEVEL 0x00008000
-
-#define APIC_RRSTAT_MASK 0x00030000
-# define APIC_RRSTAT_INVALID 0x00000000
-# define APIC_RRSTAT_INPROG 0x00010000
-# define APIC_RRSTAT_VALID 0x00020000
-# define APIC_RRSTAT_RESV 0x00030000
-
-#define APIC_DEST_MASK 0x000c0000
-# define APIC_DEST_DESTFLD 0x00000000
-# define APIC_DEST_SELF 0x00040000
-# define APIC_DEST_ALLISELF 0x00080000
-# define APIC_DEST_ALLESELF 0x000c0000
-
-#define APIC_RESV2_MASK 0xfff00000
-
-
-/* fields in ICR_HIGH */
-#define APIC_ID_MASK 0xff000000
-
-
-/* fields in LVT1/2 */
-#define APIC_LVT_VECTOR 0x000000ff
-#define APIC_LVT_DM 0x00000700
-# define APIC_LVT_DM_FIXED 0x00000000
-# define APIC_LVT_DM_NMI 0x00000400
-# define APIC_LVT_DM_EXTINT 0x00000700
-#define APIC_LVT_DS 0x00001000
-#define APIC_LVT_IIPP 0x00002000
-#define APIC_LVT_IIPP_INTALO 0x00002000
-#define APIC_LVT_IIPP_INTAHI 0x00000000
-#define APIC_LVT_RIRR 0x00004000
-#define APIC_LVT_TM 0x00008000
-#define APIC_LVT_M 0x00010000
-
-
-/* fields in LVT Timer */
-#define APIC_LVTT_VECTOR 0x000000ff
-#define APIC_LVTT_DS 0x00001000
-#define APIC_LVTT_M 0x00010000
-#define APIC_LVTT_TM 0x00020000
-
-
-/* fields in TDCR */
-#define APIC_TDCR_2 0x00
-#define APIC_TDCR_4 0x01
-#define APIC_TDCR_8 0x02
-#define APIC_TDCR_16 0x03
-#define APIC_TDCR_32 0x08
-#define APIC_TDCR_64 0x09
-#define APIC_TDCR_128 0x0a
-#define APIC_TDCR_1 0x0b
-
-
-/*
- * fields in IRR
- * ISA INTerrupts are in bits 16-31 of the 1st IRR register.
- * these masks DON'T EQUAL the isa IRQs of the same name.
- */
-#define APIC_IRQ0 0x00000001
-#define APIC_IRQ1 0x00000002
-#define APIC_IRQ2 0x00000004
-#define APIC_IRQ3 0x00000008
-#define APIC_IRQ4 0x00000010
-#define APIC_IRQ5 0x00000020
-#define APIC_IRQ6 0x00000040
-#define APIC_IRQ7 0x00000080
-#define APIC_IRQ8 0x00000100
-#define APIC_IRQ9 0x00000200
-#define APIC_IRQ10 0x00000400
-#define APIC_IRQ11 0x00000800
-#define APIC_IRQ12 0x00001000
-#define APIC_IRQ13 0x00002000
-#define APIC_IRQ14 0x00004000
-#define APIC_IRQ15 0x00008000
-#define APIC_IRQ16 0x00010000
-#define APIC_IRQ17 0x00020000
-#define APIC_IRQ18 0x00040000
-#define APIC_IRQ19 0x00080000
-#define APIC_IRQ20 0x00100000
-#define APIC_IRQ21 0x00200000
-#define APIC_IRQ22 0x00400000
-#define APIC_IRQ23 0x00800000
-
-
-/******************************************************************************
- * I/O APIC defines
- */
-
-/* default physical locations of an IO APIC */
-#define DEFAULT_IO_APIC_BASE 0xfec00000
-
-/* window register offset */
-#define IOAPIC_WINDOW 0x10
-
-/* indexes into IO APIC */
-#define IOAPIC_ID 0x00
-#define IOAPIC_VER 0x01
-#define IOAPIC_ARB 0x02
-#define IOAPIC_REDTBL 0x10
-#define IOAPIC_REDTBL0 IOAPIC_REDTBL
-#define IOAPIC_REDTBL1 (IOAPIC_REDTBL+0x02)
-#define IOAPIC_REDTBL2 (IOAPIC_REDTBL+0x04)
-#define IOAPIC_REDTBL3 (IOAPIC_REDTBL+0x06)
-#define IOAPIC_REDTBL4 (IOAPIC_REDTBL+0x08)
-#define IOAPIC_REDTBL5 (IOAPIC_REDTBL+0x0a)
-#define IOAPIC_REDTBL6 (IOAPIC_REDTBL+0x0c)
-#define IOAPIC_REDTBL7 (IOAPIC_REDTBL+0x0e)
-#define IOAPIC_REDTBL8 (IOAPIC_REDTBL+0x10)
-#define IOAPIC_REDTBL9 (IOAPIC_REDTBL+0x12)
-#define IOAPIC_REDTBL10 (IOAPIC_REDTBL+0x14)
-#define IOAPIC_REDTBL11 (IOAPIC_REDTBL+0x16)
-#define IOAPIC_REDTBL12 (IOAPIC_REDTBL+0x18)
-#define IOAPIC_REDTBL13 (IOAPIC_REDTBL+0x1a)
-#define IOAPIC_REDTBL14 (IOAPIC_REDTBL+0x1c)
-#define IOAPIC_REDTBL15 (IOAPIC_REDTBL+0x1e)
-#define IOAPIC_REDTBL16 (IOAPIC_REDTBL+0x20)
-#define IOAPIC_REDTBL17 (IOAPIC_REDTBL+0x22)
-#define IOAPIC_REDTBL18 (IOAPIC_REDTBL+0x24)
-#define IOAPIC_REDTBL19 (IOAPIC_REDTBL+0x26)
-#define IOAPIC_REDTBL20 (IOAPIC_REDTBL+0x28)
-#define IOAPIC_REDTBL21 (IOAPIC_REDTBL+0x2a)
-#define IOAPIC_REDTBL22 (IOAPIC_REDTBL+0x2c)
-#define IOAPIC_REDTBL23 (IOAPIC_REDTBL+0x2e)
-
-/* fields in VER */
-#define IOART_VER_VERSION 0x000000ff
-#define IOART_VER_MAXREDIR 0x00ff0000
-#define MAXREDIRSHIFT 16
-
-/*
- * fields in the IO APIC's redirection table entries
- */
-#define IOART_DEST APIC_ID_MASK /* broadcast addr: all APICs */
-
-#define IOART_RESV 0x00fe0000 /* reserved */
-
-#define IOART_INTMASK 0x00010000 /* R/W: INTerrupt mask */
-# define IOART_INTMCLR 0x00000000 /* clear, allow INTs */
-# define IOART_INTMSET 0x00010000 /* set, inhibit INTs */
-
-#define IOART_TRGRMOD 0x00008000 /* R/W: trigger mode */
-# define IOART_TRGREDG 0x00000000 /* edge */
-# define IOART_TRGRLVL 0x00008000 /* level */
-
-#define IOART_REM_IRR 0x00004000 /* RO: remote IRR */
-
-#define IOART_INTPOL 0x00002000 /* R/W: INT input pin polarity */
-# define IOART_INTAHI 0x00000000 /* active high */
-# define IOART_INTALO 0x00002000 /* active low */
-
-#define IOART_DELIVS 0x00001000 /* RO: delivery status */
-
-#define IOART_DESTMOD 0x00000800 /* R/W: destination mode */
-# define IOART_DESTPHY 0x00000000 /* physical */
-# define IOART_DESTLOG 0x00000800 /* logical */
-
-#define IOART_DELMOD 0x00000700 /* R/W: delivery mode */
-# define IOART_DELFIXED 0x00000000 /* fixed */
-# define IOART_DELLOPRI 0x00000100 /* lowest priority */
-# define IOART_DELSMI 0x00000200 /* System Management INT */
-# define IOART_DELRSV1 0x00000300 /* reserved */
-# define IOART_DELNMI 0x00000400 /* NMI signal */
-# define IOART_DELINIT 0x00000500 /* INIT signal */
-# define IOART_DELRSV2 0x00000600 /* reserved */
-# define IOART_DELEXINT 0x00000700 /* External INTerrupt */
-
-#define IOART_INTVEC 0x000000ff /* R/W: INTerrupt vector field */
-
-#endif /* _MACHINE_APIC_H_ */
diff --git a/sys/amd64/include/fpu.h b/sys/amd64/include/fpu.h
deleted file mode 100644
index ae576de6b0d1..000000000000
--- a/sys/amd64/include/fpu.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)npx.h 5.3 (Berkeley) 1/18/91
- * $FreeBSD$
- */
-
-/*
- * 287/387 NPX Coprocessor Data Structures and Constants
- * W. Jolitz 1/90
- */
-
-#ifndef _MACHINE_NPX_H_
-#define _MACHINE_NPX_H_
-
-/* Contents of each x87 floating point accumulator */
-struct fpacc87 {
- u_char fp_bytes[10];
-};
-
-/* Contents of each SSE extended accumulator */
-struct xmmacc {
- u_char xmm_bytes[16];
-};
-
-struct envxmm {
- u_int16_t en_cw; /* control word (16bits) */
- u_int16_t en_sw; /* status word (16bits) */
- u_int8_t en_tw; /* tag word (8bits) */
- u_int8_t en_zero;
- u_int16_t en_opcode; /* opcode last executed (11 bits ) */
- u_int64_t en_rip; /* floating point instruction pointer */
- u_int64_t en_rdp; /* floating operand pointer */
- u_int32_t en_mxcsr; /* SSE sontorol/status register */
- u_int32_t en_mxcsr_mask; /* valid bits in mxcsr */
-};
-
-struct savefpu {
- struct envxmm sv_env;
- struct {
- struct fpacc87 fp_acc;
- u_char fp_pad[6]; /* padding */
- } sv_fp[8];
- struct xmmacc sv_xmm[16];
- u_char sv_pad[96];
-} __aligned(16);
-
-/*
- * The hardware default control word for i387's and later coprocessors is
- * 0x37F, giving:
- *
- * round to nearest
- * 64-bit precision
- * all exceptions masked.
- *
- * We modify the affine mode bit and precision bits in this to give:
- *
- * affine mode for 287's (if they work at all) (1 in bitfield 1<<12)
- * 53-bit precision (2 in bitfield 3<<8)
- *
- * 64-bit precision often gives bad results with high level languages
- * because it makes the results of calculations depend on whether
- * intermediate values are stored in memory or in FPU registers.
- */
-#define __INITIAL_NPXCW__ 0x127F
-#define __INITIAL_MXCSR__ 0x1F80
-#define __INITIAL_MXCSR_MASK__ 0xFFBF
-
-#ifdef _KERNEL
-int npxdna(void);
-void npxdrop(void);
-void npxexit(struct thread *td);
-int npxformat(void);
-int npxgetregs(struct thread *td, struct savefpu *addr);
-void npxinit(u_short control);
-void npxsave(struct savefpu *addr);
-void npxsetregs(struct thread *td, struct savefpu *addr);
-int npxtrap(void);
-#endif
-
-#endif /* !_MACHINE_NPX_H_ */
diff --git a/sys/amd64/include/mptable.h b/sys/amd64/include/mptable.h
deleted file mode 100644
index d630bd583aa4..000000000000
--- a/sys/amd64/include/mptable.h
+++ /dev/null
@@ -1,2839 +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$
- */
-
-#include "opt_cpu.h"
-#include "opt_kstack_pages.h"
-#include "opt_swtch.h"
-
-#ifdef SMP
-#include <machine/smptests.h>
-#else
-#error
-#endif
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/cons.h> /* cngetc() */
-#ifdef GPROF
-#include <sys/gmon.h>
-#endif
-#include <sys/kernel.h>
-#include <sys/ktr.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/memrange.h>
-#include <sys/mutex.h>
-#include <sys/pcpu.h>
-#include <sys/proc.h>
-#include <sys/smp.h>
-#include <sys/sysctl.h>
-#include <sys/user.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_extern.h>
-#include <vm/vm_map.h>
-
-#include <machine/apic.h>
-#include <machine/atomic.h>
-#include <machine/clock.h>
-#include <machine/cpu.h>
-#include <machine/cpufunc.h>
-#include <machine/mpapic.h>
-#include <machine/psl.h>
-#include <machine/segments.h>
-#include <machine/smp.h>
-#include <machine/smptests.h> /** TEST_DEFAULT_CONFIG, TEST_TEST1 */
-#include <machine/tss.h>
-#include <machine/specialreg.h>
-#include <machine/privatespace.h>
-
-#if defined(APIC_IO)
-#include <machine/md_var.h> /* setidt() */
-#include <i386/isa/icu.h> /* IPIs */
-#include <i386/isa/intr_machdep.h> /* IPIs */
-#endif /* APIC_IO */
-
-#if defined(TEST_DEFAULT_CONFIG)
-#define MPFPS_MPFB1 TEST_DEFAULT_CONFIG
-#else
-#define MPFPS_MPFB1 mpfps->mpfb1
-#endif /* TEST_DEFAULT_CONFIG */
-
-#define WARMBOOT_TARGET 0
-#define WARMBOOT_OFF (KERNBASE + 0x0467)
-#define WARMBOOT_SEG (KERNBASE + 0x0469)
-
-#ifdef PC98
-#define BIOS_BASE (0xe8000)
-#define BIOS_SIZE (0x18000)
-#else
-#define BIOS_BASE (0xf0000)
-#define BIOS_SIZE (0x10000)
-#endif
-#define BIOS_COUNT (BIOS_SIZE/4)
-
-#define CMOS_REG (0x70)
-#define CMOS_DATA (0x71)
-#define BIOS_RESET (0x0f)
-#define BIOS_WARM (0x0a)
-
-#define PROCENTRY_FLAG_EN 0x01
-#define PROCENTRY_FLAG_BP 0x02
-#define IOAPICENTRY_FLAG_EN 0x01
-
-
-/* MP Floating Pointer Structure */
-typedef struct MPFPS {
- char signature[4];
- void *pap;
- u_char length;
- u_char spec_rev;
- u_char checksum;
- u_char mpfb1;
- u_char mpfb2;
- u_char mpfb3;
- u_char mpfb4;
- u_char mpfb5;
-} *mpfps_t;
-
-/* 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];
- void *oem_table_pointer;
- u_short oem_table_size;
- u_short entry_count;
- void *apic_address;
- u_short extended_table_length;
- u_char extended_table_checksum;
- u_char reserved;
-} *mpcth_t;
-
-
-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;
-
-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;
- void *apic_address;
-} *io_apic_entry_ptr;
-
-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;
-
-/* descriptions of MP basetable entries */
-typedef struct BASETABLE_ENTRY {
- u_char type;
- u_char length;
- char name[16];
-} basetable_entry;
-
-/*
- * this code MUST be enabled here and in mpboot.s.
- * it follows the very early stages of AP boot by placing values in CMOS ram.
- * it NORMALLY will never be needed and thus the primitive method for enabling.
- *
-#define CHECK_POINTS
- */
-
-#if defined(CHECK_POINTS) && !defined(PC98)
-#define CHECK_READ(A) (outb(CMOS_REG, (A)), inb(CMOS_DATA))
-#define CHECK_WRITE(A,D) (outb(CMOS_REG, (A)), outb(CMOS_DATA, (D)))
-
-#define CHECK_INIT(D); \
- CHECK_WRITE(0x34, (D)); \
- CHECK_WRITE(0x35, (D)); \
- CHECK_WRITE(0x36, (D)); \
- CHECK_WRITE(0x37, (D)); \
- CHECK_WRITE(0x38, (D)); \
- CHECK_WRITE(0x39, (D));
-
-#define CHECK_PRINT(S); \
- printf("%s: %d, %d, %d, %d, %d, %d\n", \
- (S), \
- CHECK_READ(0x34), \
- CHECK_READ(0x35), \
- CHECK_READ(0x36), \
- CHECK_READ(0x37), \
- CHECK_READ(0x38), \
- CHECK_READ(0x39));
-
-#else /* CHECK_POINTS */
-
-#define CHECK_INIT(D)
-#define CHECK_PRINT(S)
-
-#endif /* CHECK_POINTS */
-
-/*
- * Values to send to the POST hardware.
- */
-#define MP_BOOTADDRESS_POST 0x10
-#define MP_PROBE_POST 0x11
-#define MPTABLE_PASS1_POST 0x12
-
-#define MP_START_POST 0x13
-#define MP_ENABLE_POST 0x14
-#define MPTABLE_PASS2_POST 0x15
-
-#define START_ALL_APS_POST 0x16
-#define INSTALL_AP_TRAMP_POST 0x17
-#define START_AP_POST 0x18
-
-#define MP_ANNOUNCE_POST 0x19
-
-static int need_hyperthreading_fixup;
-static u_int logical_cpus;
-static u_int logical_cpus_mask;
-
-/* used to hold the AP's until we are ready to release them */
-static struct mtx ap_boot_mtx;
-
-/** XXX FIXME: where does this really belong, isa.h/isa.c perhaps? */
-int current_postcode;
-
-/** XXX FIXME: what system files declare these??? */
-extern struct region_descriptor r_gdt, r_idt;
-
-int bsp_apic_ready = 0; /* flags useability of BSP apic */
-int mp_naps; /* # of Applications processors */
-int mp_nbusses; /* # of busses */
-int mp_napics; /* # of IO APICs */
-int boot_cpu_id; /* designated BSP */
-vm_offset_t cpu_apic_address;
-vm_offset_t io_apic_address[NAPICID]; /* NAPICID is more than enough */
-extern int nkpt;
-
-u_int32_t cpu_apic_versions[MAXCPU];
-u_int32_t *io_apic_versions;
-
-#ifdef APIC_INTR_REORDER
-struct {
- volatile int *location;
- int bit;
-} apic_isrbit_location[32];
-#endif
-
-struct apic_intmapinfo int_to_apicintpin[APIC_INTMAPSIZE];
-
-/*
- * APIC ID logical/physical mapping structures.
- * We oversize these to simplify boot-time config.
- */
-int cpu_num_to_apic_id[NAPICID];
-int io_num_to_apic_id[NAPICID];
-int apic_id_to_logical[NAPICID];
-
-
-/* AP uses this during bootstrap. Do not staticize. */
-char *bootSTK;
-static int bootAP;
-
-/* Hotwire a 0->4MB V==P mapping */
-extern pt_entry_t *KPTphys;
-
-/* SMP page table page */
-extern pt_entry_t *SMPpt;
-
-struct pcb stoppcbs[MAXCPU];
-
-#ifdef APIC_IO
-/* Variables needed for SMP tlb shootdown. */
-vm_offset_t smp_tlb_addr1;
-vm_offset_t smp_tlb_addr2;
-volatile int smp_tlb_wait;
-static struct mtx smp_tlb_mtx;
-#endif
-
-/*
- * Local data and functions.
- */
-
-/* Set to 1 once we're ready to let the APs out of the pen. */
-static volatile int aps_ready = 0;
-
-static int mp_capable;
-static u_int boot_address;
-static u_int base_memory;
-
-static int picmode; /* 0: virtual wire mode, 1: PIC mode */
-static mpfps_t mpfps;
-static int search_for_sig(u_int32_t target, int count);
-static void mp_enable(u_int boot_addr);
-
-static void mptable_hyperthread_fixup(u_int id_mask);
-static void mptable_pass1(void);
-static int mptable_pass2(void);
-static void default_mp_table(int type);
-static void fix_mp_table(void);
-static void setup_apic_irq_mapping(void);
-static void init_locks(void);
-static int start_all_aps(u_int boot_addr);
-static void install_ap_tramp(u_int boot_addr);
-static int start_ap(int logicalCpu, u_int boot_addr);
-void ap_init(void);
-static int apic_int_is_bus_type(int intr, int bus_type);
-static void release_aps(void *dummy);
-
-/*
- * initialize all the SMP locks
- */
-
-/* lock region used by kernel profiling */
-int mcount_lock;
-
-#ifdef USE_COMLOCK
-/* locks com (tty) data/hardware accesses: a FASTINTR() */
-struct mtx com_mtx;
-#endif /* USE_COMLOCK */
-
-static void
-init_locks(void)
-{
-
-#ifdef USE_COMLOCK
- mtx_init(&com_mtx, "com", NULL, MTX_SPIN);
-#endif /* USE_COMLOCK */
-#ifdef APIC_IO
- mtx_init(&smp_tlb_mtx, "tlb", NULL, MTX_SPIN);
-#endif
-}
-
-/*
- * Calculate usable address in base memory for AP trampoline code.
- */
-u_int
-mp_bootaddress(u_int basemem)
-{
- POSTCODE(MP_BOOTADDRESS_POST);
-
- base_memory = basemem * 1024; /* convert to bytes */
-
- boot_address = base_memory & ~0xfff; /* round down to 4k boundary */
- if ((base_memory - boot_address) < bootMP_size)
- boot_address -= 4096; /* not enough, lower by 4k */
-
- return boot_address;
-}
-
-
-/*
- * Look for an Intel MP spec table (ie, SMP capable hardware).
- */
-void
-i386_mp_probe(void)
-{
- int x;
- u_long segment;
- u_int32_t target;
-
- POSTCODE(MP_PROBE_POST);
-
- /* see if EBDA exists */
- if ((segment = (u_long) * (u_short *) (KERNBASE + 0x40e)) != 0) {
- /* search first 1K of EBDA */
- target = (u_int32_t) (segment << 4);
- if ((x = search_for_sig(target, 1024 / 4)) >= 0)
- goto found;
- } else {
- /* last 1K of base memory, effective 'top of base' passed in */
- target = (u_int32_t) (base_memory - 0x400);
- if ((x = search_for_sig(target, 1024 / 4)) >= 0)
- goto found;
- }
-
- /* search the BIOS */
- target = (u_int32_t) BIOS_BASE;
- if ((x = search_for_sig(target, BIOS_COUNT)) >= 0)
- goto found;
-
- /* nothing found */
- mpfps = (mpfps_t)0;
- mp_capable = 0;
- return;
-
-found:
- /* calculate needed resources */
- mpfps = (mpfps_t)x;
- mptable_pass1();
-
- /* flag fact that we are running multiple processors */
- mp_capable = 1;
-}
-
-int
-cpu_mp_probe(void)
-{
- /*
- * Record BSP in CPU map
- * This is done here so that MBUF init code works correctly.
- */
- all_cpus = 1;
-
- return (mp_capable);
-}
-
-/*
- * Initialize the SMP hardware and the APIC and start up the AP's.
- */
-void
-cpu_mp_start(void)
-{
- POSTCODE(MP_START_POST);
-
- /* look for MP capable motherboard */
- if (mp_capable)
- mp_enable(boot_address);
- else
- panic("MP hardware not found!");
-
- cpu_setregs();
-}
-
-
-/*
- * Print various information about the SMP system hardware and setup.
- */
-void
-cpu_mp_announce(void)
-{
- int x;
-
- POSTCODE(MP_ANNOUNCE_POST);
-
- printf(" cpu0 (BSP): apic id: %2d", CPU_TO_ID(0));
- printf(", version: 0x%08x", cpu_apic_versions[0]);
- printf(", at 0x%08x\n", cpu_apic_address);
- for (x = 1; x <= mp_naps; ++x) {
- printf(" cpu%d (AP): apic id: %2d", x, CPU_TO_ID(x));
- printf(", version: 0x%08x", cpu_apic_versions[x]);
- printf(", at 0x%08x\n", cpu_apic_address);
- }
-
-#if defined(APIC_IO)
- for (x = 0; x < mp_napics; ++x) {
- printf(" io%d (APIC): apic id: %2d", x, IO_TO_ID(x));
- printf(", version: 0x%08x", io_apic_versions[x]);
- printf(", at 0x%08x\n", io_apic_address[x]);
- }
-#else
- printf(" Warning: APIC I/O disabled\n");
-#endif /* APIC_IO */
-}
-
-/*
- * AP cpu's call this to sync up protected mode.
- */
-void
-init_secondary(void)
-{
- int gsel_tss;
- int x, myid = bootAP;
- u_int cr0;
-
- gdt_segs[GPRIV_SEL].ssd_base = (int) &SMP_prvspace[myid];
- gdt_segs[GPROC0_SEL].ssd_base =
- (int) &SMP_prvspace[myid].pcpu.pc_common_tss;
- SMP_prvspace[myid].pcpu.pc_prvspace =
- &SMP_prvspace[myid].pcpu;
-
- for (x = 0; x < NGDT; x++) {
- ssdtosd(&gdt_segs[x], &gdt[myid * NGDT + x].sd);
- }
-
- r_gdt.rd_limit = NGDT * sizeof(gdt[0]) - 1;
- r_gdt.rd_base = (int) &gdt[myid * NGDT];
- lgdt(&r_gdt); /* does magic intra-segment return */
-
- lidt(&r_idt);
-
- lldt(_default_ldt);
- PCPU_SET(currentldt, _default_ldt);
-
- gsel_tss = GSEL(GPROC0_SEL, SEL_KPL);
- gdt[myid * NGDT + GPROC0_SEL].sd.sd_type = SDT_SYS386TSS;
- PCPU_SET(common_tss.tss_esp0, 0); /* not used until after switch */
- PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL));
- PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16);
- PCPU_SET(tss_gdt, &gdt[myid * NGDT + GPROC0_SEL].sd);
- PCPU_SET(common_tssd, *PCPU_GET(tss_gdt));
- ltr(gsel_tss);
-
- /*
- * Set to a known state:
- * Set by mpboot.s: CR0_PG, CR0_PE
- * Set by cpu_setregs: CR0_NE, CR0_MP, CR0_TS, CR0_WP, CR0_AM
- */
- cr0 = rcr0();
- cr0 &= ~(CR0_CD | CR0_NW | CR0_EM);
- load_cr0(cr0);
-
- pmap_set_opt();
-}
-
-
-#if defined(APIC_IO)
-/*
- * Final configuration of the BSP's local APIC:
- * - disable 'pic mode'.
- * - disable 'virtual wire mode'.
- * - enable NMI.
- */
-void
-bsp_apic_configure(void)
-{
- u_char byte;
- u_int32_t temp;
-
- /* leave 'pic mode' if necessary */
- if (picmode) {
- outb(0x22, 0x70); /* select IMCR */
- byte = inb(0x23); /* current contents */
- byte |= 0x01; /* mask external INTR */
- outb(0x23, byte); /* disconnect 8259s/NMI */
- }
-
- /* mask lint0 (the 8259 'virtual wire' connection) */
- temp = lapic.lvt_lint0;
- temp |= APIC_LVT_M; /* set the mask */
- lapic.lvt_lint0 = temp;
-
- /* setup lint1 to handle NMI */
- temp = lapic.lvt_lint1;
- temp &= ~APIC_LVT_M; /* clear the mask */
- lapic.lvt_lint1 = temp;
-
- if (bootverbose)
- apic_dump("bsp_apic_configure()");
-}
-#endif /* APIC_IO */
-
-
-/*******************************************************************
- * local functions and data
- */
-
-/*
- * start the SMP system
- */
-static void
-mp_enable(u_int boot_addr)
-{
- int x;
-#if defined(APIC_IO)
- int apic;
- u_int ux;
-#endif /* APIC_IO */
-
- POSTCODE(MP_ENABLE_POST);
-
- /* turn on 4MB of V == P addressing so we can get to MP table */
- *(int *)PTD = PG_V | PG_RW | ((uintptr_t)(void *)KPTphys & PG_FRAME);
- invltlb();
-
- /* examine the MP table for needed info, uses physical addresses */
- x = mptable_pass2();
-
- *(int *)PTD = 0;
- invltlb();
-
- /* can't process default configs till the CPU APIC is pmapped */
- if (x)
- default_mp_table(x);
-
- /* post scan cleanup */
- fix_mp_table();
- setup_apic_irq_mapping();
-
-#if defined(APIC_IO)
-
- /* fill the LOGICAL io_apic_versions table */
- for (apic = 0; apic < mp_napics; ++apic) {
- ux = io_apic_read(apic, IOAPIC_VER);
- io_apic_versions[apic] = ux;
- io_apic_set_id(apic, IO_TO_ID(apic));
- }
-
- /* program each IO APIC in the system */
- for (apic = 0; apic < mp_napics; ++apic)
- if (io_apic_setup(apic) < 0)
- panic("IO APIC setup failure");
-
- /* install a 'Spurious INTerrupt' vector */
- setidt(XSPURIOUSINT_OFFSET, Xspuriousint,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for TLB invalidation */
- setidt(XINVLTLB_OFFSET, Xinvltlb,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- setidt(XINVLPG_OFFSET, Xinvlpg,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- setidt(XINVLRNG_OFFSET, Xinvlrng,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forwarding hardclock() */
- setidt(XHARDCLOCK_OFFSET, Xhardclock,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forwarding statclock() */
- setidt(XSTATCLOCK_OFFSET, Xstatclock,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
-#ifdef LAZY_SWITCH
- /* install an inter-CPU IPI for lazy pmap release */
- setidt(XLAZYPMAP_OFFSET, Xlazypmap,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif
-
- /* install an inter-CPU IPI for all-CPU rendezvous */
- setidt(XRENDEZVOUS_OFFSET, Xrendezvous,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forcing an additional software trap */
- setidt(XCPUAST_OFFSET, Xcpuast,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for CPU stop/restart */
- setidt(XCPUSTOP_OFFSET, Xcpustop,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
-#if defined(TEST_TEST1)
- /* install a "fake hardware INTerrupt" vector */
- setidt(XTEST1_OFFSET, Xtest1,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif /** TEST_TEST1 */
-
-#endif /* APIC_IO */
-
- /* initialize all SMP locks */
- init_locks();
-
- /* start each Application Processor */
- start_all_aps(boot_addr);
-}
-
-
-/*
- * look for the MP spec signature
- */
-
-/* string defined by the Intel MP Spec as identifying the MP table */
-#define MP_SIG 0x5f504d5f /* _MP_ */
-#define NEXT(X) ((X) += 4)
-static int
-search_for_sig(u_int32_t target, int count)
-{
- int x;
- u_int32_t *addr = (u_int32_t *) (KERNBASE + target);
-
- for (x = 0; x < count; NEXT(x))
- if (addr[x] == MP_SIG)
- /* make array index a byte index */
- return (target + (x * sizeof(u_int32_t)));
-
- return -1;
-}
-
-
-static basetable_entry basetable_entry_types[] =
-{
- {0, 20, "Processor"},
- {1, 8, "Bus"},
- {2, 8, "I/O APIC"},
- {3, 8, "I/O INT"},
- {4, 8, "Local INT"}
-};
-
-typedef struct BUSDATA {
- u_char bus_id;
- enum busTypes bus_type;
-} bus_datum;
-
-typedef struct INTDATA {
- 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;
- u_char int_vector;
-} io_int, local_int;
-
-typedef struct BUSTYPENAME {
- u_char type;
- char name[7];
-} bus_type_name;
-
-static bus_type_name bus_type_table[] =
-{
- {CBUS, "CBUS"},
- {CBUSII, "CBUSII"},
- {EISA, "EISA"},
- {MCA, "MCA"},
- {UNKNOWN_BUSTYPE, "---"},
- {ISA, "ISA"},
- {MCA, "MCA"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {PCI, "PCI"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {XPRESS, "XPRESS"},
- {UNKNOWN_BUSTYPE, "---"}
-};
-/* from MP spec v1.4, table 5-1 */
-static int default_data[7][5] =
-{
-/* nbus, id0, type0, id1, type1 */
- {1, 0, ISA, 255, 255},
- {1, 0, EISA, 255, 255},
- {1, 0, EISA, 255, 255},
- {1, 0, MCA, 255, 255},
- {2, 0, ISA, 1, PCI},
- {2, 0, EISA, 1, PCI},
- {2, 0, MCA, 1, PCI}
-};
-
-
-/* the bus data */
-static bus_datum *bus_data;
-
-/* the IO INT data, one entry per possible APIC INTerrupt */
-static io_int *io_apic_ints;
-
-static int nintrs;
-
-static int processor_entry(proc_entry_ptr entry, int cpu);
-static int bus_entry(bus_entry_ptr entry, int bus);
-static int io_apic_entry(io_apic_entry_ptr entry, int apic);
-static int int_entry(int_entry_ptr entry, int intr);
-static int lookup_bus_type(char *name);
-
-
-/*
- * 1st pass on motherboard's Intel MP specification table.
- *
- * initializes:
- * mp_ncpus = 1
- *
- * determines:
- * cpu_apic_address (common to all CPUs)
- * io_apic_address[N]
- * mp_naps
- * mp_nbusses
- * mp_napics
- * nintrs
- */
-static void
-mptable_pass1(void)
-{
- int x;
- mpcth_t cth;
- int totalSize;
- void* position;
- int count;
- int type;
- u_int id_mask;
-
- POSTCODE(MPTABLE_PASS1_POST);
-
- /* clear various tables */
- for (x = 0; x < NAPICID; ++x) {
- io_apic_address[x] = ~0; /* IO APIC address table */
- }
-
- /* init everything to empty */
- mp_naps = 0;
- mp_nbusses = 0;
- mp_napics = 0;
- nintrs = 0;
- id_mask = 0;
-
- /* check for use of 'default' configuration */
- if (MPFPS_MPFB1 != 0) {
- /* use default addresses */
- cpu_apic_address = DEFAULT_APIC_BASE;
- io_apic_address[0] = DEFAULT_IO_APIC_BASE;
-
- /* fill in with defaults */
- mp_naps = 2; /* includes BSP */
- mp_maxid = 1;
- mp_nbusses = default_data[MPFPS_MPFB1 - 1][0];
-#if defined(APIC_IO)
- mp_napics = 1;
- nintrs = 16;
-#endif /* APIC_IO */
- }
- else {
- if ((cth = mpfps->pap) == 0)
- panic("MP Configuration Table Header MISSING!");
-
- cpu_apic_address = (vm_offset_t) cth->apic_address;
-
- /* walk the table, recording info of interest */
- totalSize = cth->base_table_length - sizeof(struct MPCTH);
- position = (u_char *) cth + sizeof(struct MPCTH);
- count = cth->entry_count;
-
- while (count--) {
- switch (type = *(u_char *) position) {
- case 0: /* processor_entry */
- if (((proc_entry_ptr)position)->cpu_flags
- & PROCENTRY_FLAG_EN) {
- ++mp_naps;
- mp_maxid++;
- id_mask |= 1 <<
- ((proc_entry_ptr)position)->apic_id;
- }
- break;
- case 1: /* bus_entry */
- ++mp_nbusses;
- break;
- case 2: /* io_apic_entry */
- if (((io_apic_entry_ptr)position)->apic_flags
- & IOAPICENTRY_FLAG_EN)
- io_apic_address[mp_napics++] =
- (vm_offset_t)((io_apic_entry_ptr)
- position)->apic_address;
- break;
- case 3: /* int_entry */
- ++nintrs;
- break;
- case 4: /* int_entry */
- break;
- default:
- panic("mpfps Base Table HOSED!");
- /* NOTREACHED */
- }
-
- totalSize -= basetable_entry_types[type].length;
- (u_char*)position += basetable_entry_types[type].length;
- }
- }
-
- /* qualify the numbers */
- if (mp_naps > MAXCPU) {
- printf("Warning: only using %d of %d available CPUs!\n",
- MAXCPU, mp_naps);
- mp_naps = MAXCPU;
- }
-
- /* See if we need to fixup HT logical CPUs. */
- mptable_hyperthread_fixup(id_mask);
-
- /*
- * Count the BSP.
- * This is also used as a counter while starting the APs.
- */
- mp_ncpus = 1;
-
- --mp_naps; /* subtract the BSP */
-}
-
-
-/*
- * 2nd pass on motherboard's Intel MP specification table.
- *
- * sets:
- * boot_cpu_id
- * ID_TO_IO(N), phy APIC ID to log CPU/IO table
- * CPU_TO_ID(N), logical CPU to APIC ID table
- * IO_TO_ID(N), logical IO to APIC ID table
- * bus_data[N]
- * io_apic_ints[N]
- */
-static int
-mptable_pass2(void)
-{
- struct PROCENTRY proc;
- int x;
- mpcth_t cth;
- int totalSize;
- void* position;
- int count;
- int type;
- int apic, bus, cpu, intr;
- int i, j;
- int pgeflag;
-
- POSTCODE(MPTABLE_PASS2_POST);
-
- /* Initialize fake proc entry for use with HT fixup. */
- bzero(&proc, sizeof(proc));
- proc.type = 0;
- proc.cpu_flags = PROCENTRY_FLAG_EN;
-
- pgeflag = 0; /* XXX - Not used under SMP yet. */
-
- MALLOC(io_apic_versions, u_int32_t *, sizeof(u_int32_t) * mp_napics,
- M_DEVBUF, M_WAITOK);
- MALLOC(ioapic, volatile ioapic_t **, sizeof(ioapic_t *) * mp_napics,
- M_DEVBUF, M_WAITOK);
- MALLOC(io_apic_ints, io_int *, sizeof(io_int) * (nintrs + 1),
- M_DEVBUF, M_WAITOK);
- MALLOC(bus_data, bus_datum *, sizeof(bus_datum) * mp_nbusses,
- M_DEVBUF, M_WAITOK);
-
- bzero(ioapic, sizeof(ioapic_t *) * mp_napics);
-
- for (i = 0; i < mp_napics; i++) {
- for (j = 0; j < mp_napics; j++) {
- /* same page frame as a previous IO apic? */
- if (((vm_offset_t)SMPpt[NPTEPG-2-j] & PG_FRAME) ==
- (io_apic_address[i] & PG_FRAME)) {
- ioapic[i] = (ioapic_t *)((u_int)SMP_prvspace
- + (NPTEPG-2-j) * PAGE_SIZE
- + (io_apic_address[i] & PAGE_MASK));
- break;
- }
- /* use this slot if available */
- if (((vm_offset_t)SMPpt[NPTEPG-2-j] & PG_FRAME) == 0) {
- SMPpt[NPTEPG-2-j] = (pt_entry_t)(PG_V | PG_RW |
- pgeflag | (io_apic_address[i] & PG_FRAME));
- ioapic[i] = (ioapic_t *)((u_int)SMP_prvspace
- + (NPTEPG-2-j) * PAGE_SIZE
- + (io_apic_address[i] & PAGE_MASK));
- break;
- }
- }
- }
-
- /* clear various tables */
- for (x = 0; x < NAPICID; ++x) {
- ID_TO_IO(x) = -1; /* phy APIC ID to log CPU/IO table */
- CPU_TO_ID(x) = -1; /* logical CPU to APIC ID table */
- IO_TO_ID(x) = -1; /* logical IO to APIC ID table */
- }
-
- /* clear bus data table */
- for (x = 0; x < mp_nbusses; ++x)
- bus_data[x].bus_id = 0xff;
-
- /* clear IO APIC INT table */
- for (x = 0; x < (nintrs + 1); ++x) {
- io_apic_ints[x].int_type = 0xff;
- io_apic_ints[x].int_vector = 0xff;
- }
-
- /* setup the cpu/apic mapping arrays */
- boot_cpu_id = -1;
-
- /* record whether PIC or virtual-wire mode */
- picmode = (mpfps->mpfb2 & 0x80) ? 1 : 0;
-
- /* check for use of 'default' configuration */
- if (MPFPS_MPFB1 != 0)
- return MPFPS_MPFB1; /* return default configuration type */
-
- if ((cth = mpfps->pap) == 0)
- panic("MP Configuration Table Header MISSING!");
-
- /* walk the table, recording info of interest */
- totalSize = cth->base_table_length - sizeof(struct MPCTH);
- position = (u_char *) cth + sizeof(struct MPCTH);
- count = cth->entry_count;
- apic = bus = intr = 0;
- cpu = 1; /* pre-count the BSP */
-
- while (count--) {
- switch (type = *(u_char *) position) {
- case 0:
- if (processor_entry(position, cpu)) {
- if (logical_cpus != 0 &&
- cpu % logical_cpus != 0)
- logical_cpus_mask |= (1 << cpu);
- ++cpu;
- }
- if (need_hyperthreading_fixup) {
- /*
- * Create fake mptable processor entries
- * and feed them to processor_entry() to
- * enumerate the logical CPUs.
- */
- proc.apic_id = ((proc_entry_ptr)position)->apic_id;
- for (i = 1; i < logical_cpus; i++) {
- proc.apic_id++;
- (void)processor_entry(&proc, cpu);
- logical_cpus_mask |= (1 << cpu);
- cpu++;
- }
- }
- break;
- case 1:
- if (bus_entry(position, bus))
- ++bus;
- break;
- case 2:
- if (io_apic_entry(position, apic))
- ++apic;
- break;
- case 3:
- if (int_entry(position, intr))
- ++intr;
- break;
- case 4:
- /* int_entry(position); */
- break;
- default:
- panic("mpfps Base Table HOSED!");
- /* NOTREACHED */
- }
-
- totalSize -= basetable_entry_types[type].length;
- (u_char *) position += basetable_entry_types[type].length;
- }
-
- if (boot_cpu_id == -1)
- panic("NO BSP found!");
-
- /* report fact that its NOT a default configuration */
- return 0;
-}
-
-/*
- * Check if we should perform a hyperthreading "fix-up" to
- * enumerate any logical CPU's that aren't already listed
- * in the table.
- *
- * XXX: We assume that all of the physical CPUs in the
- * system have the same number of logical CPUs.
- *
- * XXX: We assume that APIC ID's are allocated such that
- * the APIC ID's for a physical processor are aligned
- * with the number of logical CPU's in the processor.
- */
-static void
-mptable_hyperthread_fixup(u_int id_mask)
-{
- u_int i, id;
-
- /* Nothing to do if there is no HTT support. */
- if ((cpu_feature & CPUID_HTT) == 0)
- return;
- logical_cpus = (cpu_procinfo & CPUID_HTT_CORES) >> 16;
- if (logical_cpus <= 1)
- return;
-
- /*
- * For each APIC ID of a CPU that is set in the mask,
- * scan the other candidate APIC ID's for this
- * physical processor. If any of those ID's are
- * already in the table, then kill the fixup.
- */
- for (id = 0; id <= MAXCPU; id++) {
- if ((id_mask & 1 << id) == 0)
- continue;
- /* First, make sure we are on a logical_cpus boundary. */
- if (id % logical_cpus != 0)
- return;
- for (i = id + 1; i < id + logical_cpus; i++)
- if ((id_mask & 1 << i) != 0)
- return;
- }
-
- /*
- * Ok, the ID's checked out, so enable the fixup. We have to fixup
- * mp_naps and mp_maxid right now.
- */
- need_hyperthreading_fixup = 1;
- mp_maxid *= logical_cpus;
- mp_naps *= logical_cpus;
-}
-
-void
-assign_apic_irq(int apic, int intpin, int irq)
-{
- int x;
-
- if (int_to_apicintpin[irq].ioapic != -1)
- panic("assign_apic_irq: inconsistent table");
-
- int_to_apicintpin[irq].ioapic = apic;
- int_to_apicintpin[irq].int_pin = intpin;
- int_to_apicintpin[irq].apic_address = ioapic[apic];
- int_to_apicintpin[irq].redirindex = IOAPIC_REDTBL + 2 * intpin;
-
- for (x = 0; x < nintrs; x++) {
- if ((io_apic_ints[x].int_type == 0 ||
- io_apic_ints[x].int_type == 3) &&
- io_apic_ints[x].int_vector == 0xff &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(apic) &&
- io_apic_ints[x].dst_apic_int == intpin)
- io_apic_ints[x].int_vector = irq;
- }
-}
-
-void
-revoke_apic_irq(int irq)
-{
- int x;
- int oldapic;
- int oldintpin;
-
- if (int_to_apicintpin[irq].ioapic == -1)
- panic("revoke_apic_irq: inconsistent table");
-
- oldapic = int_to_apicintpin[irq].ioapic;
- oldintpin = int_to_apicintpin[irq].int_pin;
-
- int_to_apicintpin[irq].ioapic = -1;
- int_to_apicintpin[irq].int_pin = 0;
- int_to_apicintpin[irq].apic_address = NULL;
- int_to_apicintpin[irq].redirindex = 0;
-
- for (x = 0; x < nintrs; x++) {
- if ((io_apic_ints[x].int_type == 0 ||
- io_apic_ints[x].int_type == 3) &&
- io_apic_ints[x].int_vector != 0xff &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(oldapic) &&
- io_apic_ints[x].dst_apic_int == oldintpin)
- io_apic_ints[x].int_vector = 0xff;
- }
-}
-
-
-static void
-allocate_apic_irq(int intr)
-{
- int apic;
- int intpin;
- int irq;
-
- if (io_apic_ints[intr].int_vector != 0xff)
- return; /* Interrupt handler already assigned */
-
- if (io_apic_ints[intr].int_type != 0 &&
- (io_apic_ints[intr].int_type != 3 ||
- (io_apic_ints[intr].dst_apic_id == IO_TO_ID(0) &&
- io_apic_ints[intr].dst_apic_int == 0)))
- return; /* Not INT or ExtInt on != (0, 0) */
-
- irq = 0;
- while (irq < APIC_INTMAPSIZE &&
- int_to_apicintpin[irq].ioapic != -1)
- irq++;
-
- if (irq >= APIC_INTMAPSIZE)
- return; /* No free interrupt handlers */
-
- apic = ID_TO_IO(io_apic_ints[intr].dst_apic_id);
- intpin = io_apic_ints[intr].dst_apic_int;
-
- assign_apic_irq(apic, intpin, irq);
- io_apic_setup_intpin(apic, intpin);
-}
-
-
-static void
-swap_apic_id(int apic, int oldid, int newid)
-{
- int x;
- int oapic;
-
-
- if (oldid == newid)
- return; /* Nothing to do */
-
- printf("Changing APIC ID for IO APIC #%d from %d to %d in MP table\n",
- apic, oldid, newid);
-
- /* Swap physical APIC IDs in interrupt entries */
- for (x = 0; x < nintrs; x++) {
- if (io_apic_ints[x].dst_apic_id == oldid)
- io_apic_ints[x].dst_apic_id = newid;
- else if (io_apic_ints[x].dst_apic_id == newid)
- io_apic_ints[x].dst_apic_id = oldid;
- }
-
- /* Swap physical APIC IDs in IO_TO_ID mappings */
- for (oapic = 0; oapic < mp_napics; oapic++)
- if (IO_TO_ID(oapic) == newid)
- break;
-
- if (oapic < mp_napics) {
- printf("Changing APIC ID for IO APIC #%d from "
- "%d to %d in MP table\n",
- oapic, newid, oldid);
- IO_TO_ID(oapic) = oldid;
- }
- IO_TO_ID(apic) = newid;
-}
-
-
-static void
-fix_id_to_io_mapping(void)
-{
- int x;
-
- for (x = 0; x < NAPICID; x++)
- ID_TO_IO(x) = -1;
-
- for (x = 0; x <= mp_naps; x++)
- if (CPU_TO_ID(x) < NAPICID)
- ID_TO_IO(CPU_TO_ID(x)) = x;
-
- for (x = 0; x < mp_napics; x++)
- if (IO_TO_ID(x) < NAPICID)
- ID_TO_IO(IO_TO_ID(x)) = x;
-}
-
-
-static int
-first_free_apic_id(void)
-{
- int freeid, x;
-
- for (freeid = 0; freeid < NAPICID; freeid++) {
- for (x = 0; x <= mp_naps; x++)
- if (CPU_TO_ID(x) == freeid)
- break;
- if (x <= mp_naps)
- continue;
- for (x = 0; x < mp_napics; x++)
- if (IO_TO_ID(x) == freeid)
- break;
- if (x < mp_napics)
- continue;
- return freeid;
- }
- return freeid;
-}
-
-
-static int
-io_apic_id_acceptable(int apic, int id)
-{
- int cpu; /* Logical CPU number */
- int oapic; /* Logical IO APIC number for other IO APIC */
-
- if (id >= NAPICID)
- return 0; /* Out of range */
-
- for (cpu = 0; cpu <= mp_naps; cpu++)
- if (CPU_TO_ID(cpu) == id)
- return 0; /* Conflict with CPU */
-
- for (oapic = 0; oapic < mp_napics && oapic < apic; oapic++)
- if (IO_TO_ID(oapic) == id)
- return 0; /* Conflict with other APIC */
-
- return 1; /* ID is acceptable for IO APIC */
-}
-
-
-/*
- * parse an Intel MP specification table
- */
-static void
-fix_mp_table(void)
-{
- int x;
- int id;
- int bus_0 = 0; /* Stop GCC warning */
- int bus_pci = 0; /* Stop GCC warning */
- int num_pci_bus;
- int apic; /* IO APIC unit number */
- int freeid; /* Free physical APIC ID */
- int physid; /* Current physical IO APIC ID */
-
- /*
- * Fix mis-numbering of the PCI bus and its INT entries if the BIOS
- * did it wrong. The MP spec says that when more than 1 PCI bus
- * exists the BIOS must begin with bus entries for the PCI bus and use
- * actual PCI bus numbering. This implies that when only 1 PCI bus
- * exists the BIOS can choose to ignore this ordering, and indeed many
- * MP motherboards do ignore it. This causes a problem when the PCI
- * sub-system makes requests of the MP sub-system based on PCI bus
- * numbers. So here we look for the situation and renumber the
- * busses and associated INTs in an effort to "make it right".
- */
-
- /* find bus 0, PCI bus, count the number of PCI busses */
- for (num_pci_bus = 0, x = 0; x < mp_nbusses; ++x) {
- if (bus_data[x].bus_id == 0) {
- bus_0 = x;
- }
- if (bus_data[x].bus_type == PCI) {
- ++num_pci_bus;
- bus_pci = x;
- }
- }
- /*
- * bus_0 == slot of bus with ID of 0
- * bus_pci == slot of last PCI bus encountered
- */
-
- /* check the 1 PCI bus case for sanity */
- /* if it is number 0 all is well */
- if (num_pci_bus == 1 &&
- bus_data[bus_pci].bus_id != 0) {
-
- /* mis-numbered, swap with whichever bus uses slot 0 */
-
- /* swap the bus entry types */
- bus_data[bus_pci].bus_type = bus_data[bus_0].bus_type;
- bus_data[bus_0].bus_type = PCI;
-
- /* swap each relavant INTerrupt entry */
- id = bus_data[bus_pci].bus_id;
- for (x = 0; x < nintrs; ++x) {
- if (io_apic_ints[x].src_bus_id == id) {
- io_apic_ints[x].src_bus_id = 0;
- }
- else if (io_apic_ints[x].src_bus_id == 0) {
- io_apic_ints[x].src_bus_id = id;
- }
- }
- }
-
- /* Assign IO APIC IDs.
- *
- * First try the existing ID. If a conflict is detected, try
- * the ID in the MP table. If a conflict is still detected, find
- * a free id.
- *
- * We cannot use the ID_TO_IO table before all conflicts has been
- * resolved and the table has been corrected.
- */
- for (apic = 0; apic < mp_napics; ++apic) { /* For all IO APICs */
-
- /* First try to use the value set by the BIOS */
- physid = io_apic_get_id(apic);
- if (io_apic_id_acceptable(apic, physid)) {
- if (IO_TO_ID(apic) != physid)
- swap_apic_id(apic, IO_TO_ID(apic), physid);
- continue;
- }
-
- /* Then check if the value in the MP table is acceptable */
- if (io_apic_id_acceptable(apic, IO_TO_ID(apic)))
- continue;
-
- /* Last resort, find a free APIC ID and use it */
- freeid = first_free_apic_id();
- if (freeid >= NAPICID)
- panic("No free physical APIC IDs found");
-
- if (io_apic_id_acceptable(apic, freeid)) {
- swap_apic_id(apic, IO_TO_ID(apic), freeid);
- continue;
- }
- panic("Free physical APIC ID not usable");
- }
- fix_id_to_io_mapping();
-
- /* detect and fix broken Compaq MP table */
- if (apic_int_type(0, 0) == -1) {
- printf("APIC_IO: MP table broken: 8259->APIC entry missing!\n");
- io_apic_ints[nintrs].int_type = 3; /* ExtInt */
- io_apic_ints[nintrs].int_vector = 0xff; /* Unassigned */
- /* XXX fixme, set src bus id etc, but it doesn't seem to hurt */
- io_apic_ints[nintrs].dst_apic_id = IO_TO_ID(0);
- io_apic_ints[nintrs].dst_apic_int = 0; /* Pin 0 */
- nintrs++;
- }
-}
-
-
-/* Assign low level interrupt handlers */
-static void
-setup_apic_irq_mapping(void)
-{
- int x;
- int int_vector;
-
- /* Clear array */
- for (x = 0; x < APIC_INTMAPSIZE; x++) {
- int_to_apicintpin[x].ioapic = -1;
- int_to_apicintpin[x].int_pin = 0;
- int_to_apicintpin[x].apic_address = NULL;
- int_to_apicintpin[x].redirindex = 0;
- }
-
- /* First assign ISA/EISA interrupts */
- for (x = 0; x < nintrs; x++) {
- int_vector = io_apic_ints[x].src_bus_irq;
- if (int_vector < APIC_INTMAPSIZE &&
- io_apic_ints[x].int_vector == 0xff &&
- int_to_apicintpin[int_vector].ioapic == -1 &&
- (apic_int_is_bus_type(x, ISA) ||
- apic_int_is_bus_type(x, EISA)) &&
- io_apic_ints[x].int_type == 0) {
- assign_apic_irq(ID_TO_IO(io_apic_ints[x].dst_apic_id),
- io_apic_ints[x].dst_apic_int,
- int_vector);
- }
- }
-
- /* Assign ExtInt entry if no ISA/EISA interrupt 0 entry */
- for (x = 0; x < nintrs; x++) {
- if (io_apic_ints[x].dst_apic_int == 0 &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(0) &&
- io_apic_ints[x].int_vector == 0xff &&
- int_to_apicintpin[0].ioapic == -1 &&
- io_apic_ints[x].int_type == 3) {
- assign_apic_irq(0, 0, 0);
- break;
- }
- }
- /* PCI interrupt assignment is deferred */
-}
-
-
-static int
-processor_entry(proc_entry_ptr entry, int cpu)
-{
- /* check for usability */
- if (!(entry->cpu_flags & PROCENTRY_FLAG_EN))
- return 0;
-
- if(entry->apic_id >= NAPICID)
- panic("CPU APIC ID out of range (0..%d)", NAPICID - 1);
- /* check for BSP flag */
- if (entry->cpu_flags & PROCENTRY_FLAG_BP) {
- boot_cpu_id = entry->apic_id;
- CPU_TO_ID(0) = entry->apic_id;
- ID_TO_CPU(entry->apic_id) = 0;
- return 0; /* its already been counted */
- }
-
- /* add another AP to list, if less than max number of CPUs */
- else if (cpu < MAXCPU) {
- CPU_TO_ID(cpu) = entry->apic_id;
- ID_TO_CPU(entry->apic_id) = cpu;
- return 1;
- }
-
- return 0;
-}
-
-
-static int
-bus_entry(bus_entry_ptr entry, int bus)
-{
- int x;
- char c, name[8];
-
- /* encode the name into an index */
- for (x = 0; x < 6; ++x) {
- if ((c = entry->bus_type[x]) == ' ')
- break;
- name[x] = c;
- }
- name[x] = '\0';
-
- if ((x = lookup_bus_type(name)) == UNKNOWN_BUSTYPE)
- panic("unknown bus type: '%s'", name);
-
- bus_data[bus].bus_id = entry->bus_id;
- bus_data[bus].bus_type = x;
-
- return 1;
-}
-
-
-static int
-io_apic_entry(io_apic_entry_ptr entry, int apic)
-{
- if (!(entry->apic_flags & IOAPICENTRY_FLAG_EN))
- return 0;
-
- IO_TO_ID(apic) = entry->apic_id;
- if (entry->apic_id < NAPICID)
- ID_TO_IO(entry->apic_id) = apic;
-
- return 1;
-}
-
-
-static int
-lookup_bus_type(char *name)
-{
- int x;
-
- for (x = 0; x < MAX_BUSTYPE; ++x)
- if (strcmp(bus_type_table[x].name, name) == 0)
- return bus_type_table[x].type;
-
- return UNKNOWN_BUSTYPE;
-}
-
-
-static int
-int_entry(int_entry_ptr entry, int intr)
-{
- int apic;
-
- io_apic_ints[intr].int_type = entry->int_type;
- io_apic_ints[intr].int_flags = entry->int_flags;
- io_apic_ints[intr].src_bus_id = entry->src_bus_id;
- io_apic_ints[intr].src_bus_irq = entry->src_bus_irq;
- if (entry->dst_apic_id == 255) {
- /* This signal goes to all IO APICS. Select an IO APIC
- with sufficient number of interrupt pins */
- for (apic = 0; apic < mp_napics; apic++)
- if (((io_apic_read(apic, IOAPIC_VER) &
- IOART_VER_MAXREDIR) >> MAXREDIRSHIFT) >=
- entry->dst_apic_int)
- break;
- if (apic < mp_napics)
- io_apic_ints[intr].dst_apic_id = IO_TO_ID(apic);
- else
- io_apic_ints[intr].dst_apic_id = entry->dst_apic_id;
- } else
- io_apic_ints[intr].dst_apic_id = entry->dst_apic_id;
- io_apic_ints[intr].dst_apic_int = entry->dst_apic_int;
-
- return 1;
-}
-
-
-static int
-apic_int_is_bus_type(int intr, int bus_type)
-{
- int bus;
-
- for (bus = 0; bus < mp_nbusses; ++bus)
- if ((bus_data[bus].bus_id == io_apic_ints[intr].src_bus_id)
- && ((int) bus_data[bus].bus_type == bus_type))
- return 1;
-
- return 0;
-}
-
-
-/*
- * Given a traditional ISA INT mask, return an APIC mask.
- */
-u_int
-isa_apic_mask(u_int isa_mask)
-{
- int isa_irq;
- int apic_pin;
-
-#if defined(SKIP_IRQ15_REDIRECT)
- if (isa_mask == (1 << 15)) {
- printf("skipping ISA IRQ15 redirect\n");
- return isa_mask;
- }
-#endif /* SKIP_IRQ15_REDIRECT */
-
- isa_irq = ffs(isa_mask); /* find its bit position */
- if (isa_irq == 0) /* doesn't exist */
- return 0;
- --isa_irq; /* make it zero based */
-
- apic_pin = isa_apic_irq(isa_irq); /* look for APIC connection */
- if (apic_pin == -1)
- return 0;
-
- return (1 << apic_pin); /* convert pin# to a mask */
-}
-
-
-/*
- * Determine which APIC pin an ISA/EISA INT is attached to.
- */
-#define INTTYPE(I) (io_apic_ints[(I)].int_type)
-#define INTPIN(I) (io_apic_ints[(I)].dst_apic_int)
-#define INTIRQ(I) (io_apic_ints[(I)].int_vector)
-#define INTAPIC(I) (ID_TO_IO(io_apic_ints[(I)].dst_apic_id))
-
-#define SRCBUSIRQ(I) (io_apic_ints[(I)].src_bus_irq)
-int
-isa_apic_irq(int isa_irq)
-{
- int intr;
-
- for (intr = 0; intr < nintrs; ++intr) { /* check each record */
- if (INTTYPE(intr) == 0) { /* standard INT */
- if (SRCBUSIRQ(intr) == isa_irq) {
- if (apic_int_is_bus_type(intr, ISA) ||
- apic_int_is_bus_type(intr, EISA)) {
- if (INTIRQ(intr) == 0xff)
- return -1; /* unassigned */
- return INTIRQ(intr); /* found */
- }
- }
- }
- }
- return -1; /* NOT found */
-}
-
-
-/*
- * Determine which APIC pin a PCI INT is attached to.
- */
-#define SRCBUSID(I) (io_apic_ints[(I)].src_bus_id)
-#define SRCBUSDEVICE(I) ((io_apic_ints[(I)].src_bus_irq >> 2) & 0x1f)
-#define SRCBUSLINE(I) (io_apic_ints[(I)].src_bus_irq & 0x03)
-int
-pci_apic_irq(int pciBus, int pciDevice, int pciInt)
-{
- int intr;
-
- --pciInt; /* zero based */
-
- for (intr = 0; intr < nintrs; ++intr) /* check each record */
- if ((INTTYPE(intr) == 0) /* standard INT */
- && (SRCBUSID(intr) == pciBus)
- && (SRCBUSDEVICE(intr) == pciDevice)
- && (SRCBUSLINE(intr) == pciInt)) /* a candidate IRQ */
- if (apic_int_is_bus_type(intr, PCI)) {
- if (INTIRQ(intr) == 0xff)
- allocate_apic_irq(intr);
- if (INTIRQ(intr) == 0xff)
- return -1; /* unassigned */
- return INTIRQ(intr); /* exact match */
- }
-
- return -1; /* NOT found */
-}
-
-int
-next_apic_irq(int irq)
-{
- int intr, ointr;
- int bus, bustype;
-
- bus = 0;
- bustype = 0;
- for (intr = 0; intr < nintrs; intr++) {
- if (INTIRQ(intr) != irq || INTTYPE(intr) != 0)
- continue;
- bus = SRCBUSID(intr);
- bustype = apic_bus_type(bus);
- if (bustype != ISA &&
- bustype != EISA &&
- bustype != PCI)
- continue;
- break;
- }
- if (intr >= nintrs) {
- return -1;
- }
- for (ointr = intr + 1; ointr < nintrs; ointr++) {
- if (INTTYPE(ointr) != 0)
- continue;
- if (bus != SRCBUSID(ointr))
- continue;
- if (bustype == PCI) {
- if (SRCBUSDEVICE(intr) != SRCBUSDEVICE(ointr))
- continue;
- if (SRCBUSLINE(intr) != SRCBUSLINE(ointr))
- continue;
- }
- if (bustype == ISA || bustype == EISA) {
- if (SRCBUSIRQ(intr) != SRCBUSIRQ(ointr))
- continue;
- }
- if (INTPIN(intr) == INTPIN(ointr))
- continue;
- break;
- }
- if (ointr >= nintrs) {
- return -1;
- }
- return INTIRQ(ointr);
-}
-#undef SRCBUSLINE
-#undef SRCBUSDEVICE
-#undef SRCBUSID
-#undef SRCBUSIRQ
-
-#undef INTPIN
-#undef INTIRQ
-#undef INTAPIC
-#undef INTTYPE
-
-
-/*
- * Reprogram the MB chipset to NOT redirect an ISA INTerrupt.
- *
- * XXX FIXME:
- * Exactly what this means is unclear at this point. It is a solution
- * for motherboards that redirect the MBIRQ0 pin. Generically a motherboard
- * could route any of the ISA INTs to upper (>15) IRQ values. But most would
- * NOT be redirected via MBIRQ0, thus "undirect()ing" them would NOT be an
- * option.
- */
-int
-undirect_isa_irq(int rirq)
-{
-#if defined(READY)
- if (bootverbose)
- printf("Freeing redirected ISA irq %d.\n", rirq);
- /** FIXME: tickle the MB redirector chip */
- return -1;
-#else
- if (bootverbose)
- printf("Freeing (NOT implemented) redirected ISA irq %d.\n", rirq);
- return 0;
-#endif /* READY */
-}
-
-
-/*
- * Reprogram the MB chipset to NOT redirect a PCI INTerrupt
- */
-int
-undirect_pci_irq(int rirq)
-{
-#if defined(READY)
- if (bootverbose)
- printf("Freeing redirected PCI irq %d.\n", rirq);
-
- /** FIXME: tickle the MB redirector chip */
- return -1;
-#else
- if (bootverbose)
- printf("Freeing (NOT implemented) redirected PCI irq %d.\n",
- rirq);
- return 0;
-#endif /* READY */
-}
-
-
-/*
- * given a bus ID, return:
- * the bus type if found
- * -1 if NOT found
- */
-int
-apic_bus_type(int id)
-{
- int x;
-
- for (x = 0; x < mp_nbusses; ++x)
- if (bus_data[x].bus_id == id)
- return bus_data[x].bus_type;
-
- return -1;
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated src bus ID if found
- * -1 if NOT found
- */
-int
-apic_src_bus_id(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].src_bus_id);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated src bus IRQ if found
- * -1 if NOT found
- */
-int
-apic_src_bus_irq(int apic, int pin)
-{
- int x;
-
- for (x = 0; x < nintrs; x++)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].src_bus_irq);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated INTerrupt type if found
- * -1 if NOT found
- */
-int
-apic_int_type(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].int_type);
-
- return -1; /* NOT found */
-}
-
-int
-apic_irq(int apic, int pin)
-{
- int x;
- int res;
-
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int)) {
- res = io_apic_ints[x].int_vector;
- if (res == 0xff)
- return -1;
- if (apic != int_to_apicintpin[res].ioapic)
- panic("apic_irq: inconsistent table");
- if (pin != int_to_apicintpin[res].int_pin)
- panic("apic_irq inconsistent table (2)");
- return res;
- }
- return -1;
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated trigger mode if found
- * -1 if NOT found
- */
-int
-apic_trigger(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return ((io_apic_ints[x].int_flags >> 2) & 0x03);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated 'active' level if found
- * -1 if NOT found
- */
-int
-apic_polarity(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].int_flags & 0x03);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * set data according to MP defaults
- * FIXME: probably not complete yet...
- */
-static void
-default_mp_table(int type)
-{
- int ap_cpu_id;
-#if defined(APIC_IO)
- int io_apic_id;
- int pin;
-#endif /* APIC_IO */
-
-#if 0
- printf(" MP default config type: %d\n", type);
- switch (type) {
- case 1:
- printf(" bus: ISA, APIC: 82489DX\n");
- break;
- case 2:
- printf(" bus: EISA, APIC: 82489DX\n");
- break;
- case 3:
- printf(" bus: EISA, APIC: 82489DX\n");
- break;
- case 4:
- printf(" bus: MCA, APIC: 82489DX\n");
- break;
- case 5:
- printf(" bus: ISA+PCI, APIC: Integrated\n");
- break;
- case 6:
- printf(" bus: EISA+PCI, APIC: Integrated\n");
- break;
- case 7:
- printf(" bus: MCA+PCI, APIC: Integrated\n");
- break;
- default:
- printf(" future type\n");
- break;
- /* NOTREACHED */
- }
-#endif /* 0 */
-
- boot_cpu_id = (lapic.id & APIC_ID_MASK) >> 24;
- ap_cpu_id = (boot_cpu_id == 0) ? 1 : 0;
-
- /* BSP */
- CPU_TO_ID(0) = boot_cpu_id;
- ID_TO_CPU(boot_cpu_id) = 0;
-
- /* one and only AP */
- CPU_TO_ID(1) = ap_cpu_id;
- ID_TO_CPU(ap_cpu_id) = 1;
-
-#if defined(APIC_IO)
- /* one and only IO APIC */
- io_apic_id = (io_apic_read(0, IOAPIC_ID) & APIC_ID_MASK) >> 24;
-
- /*
- * sanity check, refer to MP spec section 3.6.6, last paragraph
- * necessary as some hardware isn't properly setting up the IO APIC
- */
-#if defined(REALLY_ANAL_IOAPICID_VALUE)
- if (io_apic_id != 2) {
-#else
- if ((io_apic_id == 0) || (io_apic_id == 1) || (io_apic_id == 15)) {
-#endif /* REALLY_ANAL_IOAPICID_VALUE */
- io_apic_set_id(0, 2);
- io_apic_id = 2;
- }
- IO_TO_ID(0) = io_apic_id;
- ID_TO_IO(io_apic_id) = 0;
-#endif /* APIC_IO */
-
- /* fill out bus entries */
- switch (type) {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- bus_data[0].bus_id = default_data[type - 1][1];
- bus_data[0].bus_type = default_data[type - 1][2];
- bus_data[1].bus_id = default_data[type - 1][3];
- bus_data[1].bus_type = default_data[type - 1][4];
- break;
-
- /* case 4: case 7: MCA NOT supported */
- default: /* illegal/reserved */
- panic("BAD default MP config: %d", type);
- /* NOTREACHED */
- }
-
-#if defined(APIC_IO)
- /* general cases from MP v1.4, table 5-2 */
- for (pin = 0; pin < 16; ++pin) {
- io_apic_ints[pin].int_type = 0;
- io_apic_ints[pin].int_flags = 0x05; /* edge/active-hi */
- io_apic_ints[pin].src_bus_id = 0;
- io_apic_ints[pin].src_bus_irq = pin; /* IRQ2 caught below */
- io_apic_ints[pin].dst_apic_id = io_apic_id;
- io_apic_ints[pin].dst_apic_int = pin; /* 1-to-1 */
- }
-
- /* special cases from MP v1.4, table 5-2 */
- if (type == 2) {
- io_apic_ints[2].int_type = 0xff; /* N/C */
- io_apic_ints[13].int_type = 0xff; /* N/C */
-#if !defined(APIC_MIXED_MODE)
- /** FIXME: ??? */
- panic("sorry, can't support type 2 default yet");
-#endif /* APIC_MIXED_MODE */
- }
- else
- io_apic_ints[2].src_bus_irq = 0; /* ISA IRQ0 is on APIC INT 2 */
-
- if (type == 7)
- io_apic_ints[0].int_type = 0xff; /* N/C */
- else
- io_apic_ints[0].int_type = 3; /* vectored 8259 */
-#endif /* APIC_IO */
-}
-
-
-/*
- * start each AP in our list
- */
-static int
-start_all_aps(u_int boot_addr)
-{
- int x, i, pg;
-#ifndef PC98
- u_char mpbiosreason;
-#endif
- u_long mpbioswarmvec;
- struct pcpu *pc;
- char *stack;
- uintptr_t kptbase;
-
- POSTCODE(START_ALL_APS_POST);
-
- mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN);
-
- /* initialize BSP's local APIC */
- apic_initialize();
- bsp_apic_ready = 1;
-
- /* install the AP 1st level boot code */
- install_ap_tramp(boot_addr);
-
-
- /* save the current value of the warm-start vector */
- mpbioswarmvec = *((u_long *) WARMBOOT_OFF);
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- mpbiosreason = inb(CMOS_DATA);
-#endif
-
- /* set up temporary P==V mapping for AP boot */
- /* XXX this is a hack, we should boot the AP on its own stack/PTD */
- kptbase = (uintptr_t)(void *)KPTphys;
- for (x = 0; x < NKPT; x++)
- PTD[x] = (pd_entry_t)(PG_V | PG_RW |
- ((kptbase + x * PAGE_SIZE) & PG_FRAME));
- invltlb();
-
- /* start each AP */
- for (x = 1; x <= mp_naps; ++x) {
-
- /* This is a bit verbose, it will go away soon. */
-
- /* first page of AP's private space */
- pg = x * i386_btop(sizeof(struct privatespace));
-
- /* allocate a new private data page */
- pc = (struct pcpu *)kmem_alloc(kernel_map, PAGE_SIZE);
-
- /* wire it into the private page table page */
- SMPpt[pg] = (pt_entry_t)(PG_V | PG_RW | vtophys(pc));
-
- /* allocate and set up an idle stack data page */
- stack = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE); /* XXXKSE */
- for (i = 0; i < KSTACK_PAGES; i++)
- SMPpt[pg + 1 + i] = (pt_entry_t)
- (PG_V | PG_RW | vtophys(PAGE_SIZE * i + stack));
-
- /* prime data page for it to use */
- pcpu_init(pc, x, sizeof(struct pcpu));
-
- /* setup a vector to our boot code */
- *((volatile u_short *) WARMBOOT_OFF) = WARMBOOT_TARGET;
- *((volatile u_short *) WARMBOOT_SEG) = (boot_addr >> 4);
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- outb(CMOS_DATA, BIOS_WARM); /* 'warm-start' */
-#endif
-
- bootSTK = &SMP_prvspace[x].idlekstack[KSTACK_PAGES * PAGE_SIZE];
- bootAP = x;
-
- /* attempt to start the Application Processor */
- CHECK_INIT(99); /* setup checkpoints */
- if (!start_ap(x, boot_addr)) {
- printf("AP #%d (PHY# %d) failed!\n", x, CPU_TO_ID(x));
- CHECK_PRINT("trace"); /* show checkpoints */
- /* better panic as the AP may be running loose */
- printf("panic y/n? [y] ");
- if (cngetc() != 'n')
- panic("bye-bye");
- }
- CHECK_PRINT("trace"); /* show checkpoints */
-
- /* record its version info */
- cpu_apic_versions[x] = cpu_apic_versions[0];
-
- all_cpus |= (1 << x); /* record AP in CPU map */
- }
-
- /* build our map of 'other' CPUs */
- PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
-
- /* fill in our (BSP) APIC version */
- cpu_apic_versions[0] = lapic.version;
-
- /* restore the warmstart vector */
- *(u_long *) WARMBOOT_OFF = mpbioswarmvec;
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- outb(CMOS_DATA, mpbiosreason);
-#endif
-
- /*
- * Set up the idle context for the BSP. Similar to above except
- * that some was done by locore, some by pmap.c and some is implicit
- * because the BSP is cpu#0 and the page is initially zero, and also
- * because we can refer to variables by name on the BSP..
- */
-
- /* Allocate and setup BSP idle stack */
- stack = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE);
- for (i = 0; i < KSTACK_PAGES; i++)
- SMPpt[1 + i] = (pt_entry_t)
- (PG_V | PG_RW | vtophys(PAGE_SIZE * i + stack));
-
- for (x = 0; x < NKPT; x++)
- PTD[x] = 0;
- pmap_set_opt();
-
- /* number of APs actually started */
- return mp_ncpus - 1;
-}
-
-
-/*
- * load the 1st level AP boot code into base memory.
- */
-
-/* targets for relocation */
-extern void bigJump(void);
-extern void bootCodeSeg(void);
-extern void bootDataSeg(void);
-extern void MPentry(void);
-extern u_int MP_GDT;
-extern u_int mp_gdtbase;
-
-static void
-install_ap_tramp(u_int boot_addr)
-{
- int x;
- int size = *(int *) ((u_long) & bootMP_size);
- u_char *src = (u_char *) ((u_long) bootMP);
- u_char *dst = (u_char *) boot_addr + KERNBASE;
- u_int boot_base = (u_int) bootMP;
- u_int8_t *dst8;
- u_int16_t *dst16;
- u_int32_t *dst32;
-
- POSTCODE(INSTALL_AP_TRAMP_POST);
-
- for (x = 0; x < size; ++x)
- *dst++ = *src++;
-
- /*
- * modify addresses in code we just moved to basemem. unfortunately we
- * need fairly detailed info about mpboot.s for this to work. changes
- * to mpboot.s might require changes here.
- */
-
- /* boot code is located in KERNEL space */
- dst = (u_char *) boot_addr + KERNBASE;
-
- /* modify the lgdt arg */
- dst32 = (u_int32_t *) (dst + ((u_int) & mp_gdtbase - boot_base));
- *dst32 = boot_addr + ((u_int) & MP_GDT - boot_base);
-
- /* modify the ljmp target for MPentry() */
- dst32 = (u_int32_t *) (dst + ((u_int) bigJump - boot_base) + 1);
- *dst32 = ((u_int) MPentry - KERNBASE);
-
- /* modify the target for boot code segment */
- dst16 = (u_int16_t *) (dst + ((u_int) bootCodeSeg - boot_base));
- dst8 = (u_int8_t *) (dst16 + 1);
- *dst16 = (u_int) boot_addr & 0xffff;
- *dst8 = ((u_int) boot_addr >> 16) & 0xff;
-
- /* modify the target for boot data segment */
- dst16 = (u_int16_t *) (dst + ((u_int) bootDataSeg - boot_base));
- dst8 = (u_int8_t *) (dst16 + 1);
- *dst16 = (u_int) boot_addr & 0xffff;
- *dst8 = ((u_int) boot_addr >> 16) & 0xff;
-}
-
-
-/*
- * this function starts the AP (application processor) identified
- * by the APIC ID 'physicalCpu'. It does quite a "song and dance"
- * to accomplish this. This is necessary because of the nuances
- * of the different hardware we might encounter. It ain't pretty,
- * but it seems to work.
- */
-static int
-start_ap(int logical_cpu, u_int boot_addr)
-{
- int physical_cpu;
- int vector;
- int cpus;
- u_long icr_lo, icr_hi;
-
- POSTCODE(START_AP_POST);
-
- /* get the PHYSICAL APIC ID# */
- physical_cpu = CPU_TO_ID(logical_cpu);
-
- /* calculate the vector */
- vector = (boot_addr >> 12) & 0xff;
-
- /* used as a watchpoint to signal AP startup */
- cpus = mp_ncpus;
-
- /*
- * first we do an INIT/RESET IPI this INIT IPI might be run, reseting
- * and running the target CPU. OR this INIT IPI might be latched (P5
- * bug), CPU waiting for STARTUP IPI. OR this INIT IPI might be
- * ignored.
- */
-
- /* setup the address for the target AP */
- icr_hi = lapic.icr_hi & ~APIC_ID_MASK;
- icr_hi |= (physical_cpu << 24);
- lapic.icr_hi = icr_hi;
-
- /* do an INIT IPI: assert RESET */
- icr_lo = lapic.icr_lo & 0xfff00000;
- lapic.icr_lo = icr_lo | 0x0000c500;
-
- /* wait for pending status end */
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
-
- /* do an INIT IPI: deassert RESET */
- lapic.icr_lo = icr_lo | 0x00008500;
-
- /* wait for pending status end */
- u_sleep(10000); /* wait ~10mS */
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
-
- /*
- * next we do a STARTUP IPI: the previous INIT IPI might still be
- * latched, (P5 bug) this 1st STARTUP would then terminate
- * immediately, and the previously started INIT IPI would continue. OR
- * the previous INIT IPI has already run. and this STARTUP IPI will
- * run. OR the previous INIT IPI was ignored. and this STARTUP IPI
- * will run.
- */
-
- /* do a STARTUP IPI */
- lapic.icr_lo = icr_lo | 0x00000600 | vector;
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
- u_sleep(200); /* wait ~200uS */
-
- /*
- * finally we do a 2nd STARTUP IPI: this 2nd STARTUP IPI should run IF
- * the previous STARTUP IPI was cancelled by a latched INIT IPI. OR
- * this STARTUP IPI will be ignored, as only ONE STARTUP IPI is
- * recognized after hardware RESET or INIT IPI.
- */
-
- lapic.icr_lo = icr_lo | 0x00000600 | vector;
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
- u_sleep(200); /* wait ~200uS */
-
- /* wait for it to start */
- set_apic_timer(5000000);/* == 5 seconds */
- while (read_apic_timer())
- if (mp_ncpus > cpus)
- return 1; /* return SUCCESS */
-
- return 0; /* return FAILURE */
-}
-
-#if defined(APIC_IO)
-
-#ifdef COUNT_XINVLTLB_HITS
-u_int xhits_gbl[MAXCPU];
-u_int xhits_pg[MAXCPU];
-u_int xhits_rng[MAXCPU];
-SYSCTL_NODE(_debug, OID_AUTO, xhits, CTLFLAG_RW, 0, "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, global, CTLFLAG_RW, &xhits_gbl,
- sizeof(xhits_gbl), "IU", "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, page, CTLFLAG_RW, &xhits_pg,
- sizeof(xhits_pg), "IU", "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, range, CTLFLAG_RW, &xhits_rng,
- sizeof(xhits_rng), "IU", "");
-
-u_int ipi_global;
-u_int ipi_page;
-u_int ipi_range;
-u_int ipi_range_size;
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_global, CTLFLAG_RW, &ipi_global, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_page, CTLFLAG_RW, &ipi_page, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range, CTLFLAG_RW, &ipi_range, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range_size, CTLFLAG_RW, &ipi_range_size,
- 0, "");
-
-u_int ipi_masked_global;
-u_int ipi_masked_page;
-u_int ipi_masked_range;
-u_int ipi_masked_range_size;
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_global, CTLFLAG_RW,
- &ipi_masked_global, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_page, CTLFLAG_RW,
- &ipi_masked_page, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range, CTLFLAG_RW,
- &ipi_masked_range, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range_size, CTLFLAG_RW,
- &ipi_masked_range_size, 0, "");
-#endif
-
-/*
- * Flush the TLB on all other CPU's
- */
-static void
-smp_tlb_shootdown(u_int vector, vm_offset_t addr1, vm_offset_t addr2)
-{
- u_int ncpu;
- register_t eflags;
-
- ncpu = mp_ncpus - 1; /* does not shootdown self */
- if (ncpu < 1)
- return; /* no other cpus */
- eflags = read_eflags();
- if ((eflags & PSL_I) == 0)
- panic("absolutely cannot call smp_ipi_shootdown with interrupts already disabled");
- mtx_lock_spin(&smp_tlb_mtx);
- smp_tlb_addr1 = addr1;
- smp_tlb_addr2 = addr2;
- atomic_store_rel_int(&smp_tlb_wait, 0);
- ipi_all_but_self(vector);
- while (smp_tlb_wait < ncpu)
- ia32_pause();
- mtx_unlock_spin(&smp_tlb_mtx);
-}
-
-/*
- * This is about as magic as it gets. fortune(1) has got similar code
- * for reversing bits in a word. Who thinks up this stuff??
- *
- * Yes, it does appear to be consistently faster than:
- * while (i = ffs(m)) {
- * m >>= i;
- * bits++;
- * }
- * and
- * while (lsb = (m & -m)) { // This is magic too
- * m &= ~lsb; // or: m ^= lsb
- * bits++;
- * }
- * Both of these latter forms do some very strange things on gcc-3.1 with
- * -mcpu=pentiumpro and/or -march=pentiumpro and/or -O or -O2.
- * There is probably an SSE or MMX popcnt instruction.
- *
- * I wonder if this should be in libkern?
- *
- * XXX Stop the presses! Another one:
- * static __inline u_int32_t
- * popcnt1(u_int32_t v)
- * {
- * v -= ((v >> 1) & 0x55555555);
- * v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
- * v = (v + (v >> 4)) & 0x0F0F0F0F;
- * return (v * 0x01010101) >> 24;
- * }
- * The downside is that it has a multiply. With a pentium3 with
- * -mcpu=pentiumpro and -march=pentiumpro then gcc-3.1 will use
- * an imull, and in that case it is faster. In most other cases
- * it appears slightly slower.
- */
-static __inline u_int32_t
-popcnt(u_int32_t m)
-{
-
- m = (m & 0x55555555) + ((m & 0xaaaaaaaa) >> 1);
- m = (m & 0x33333333) + ((m & 0xcccccccc) >> 2);
- m = (m & 0x0f0f0f0f) + ((m & 0xf0f0f0f0) >> 4);
- m = (m & 0x00ff00ff) + ((m & 0xff00ff00) >> 8);
- m = (m & 0x0000ffff) + ((m & 0xffff0000) >> 16);
- return m;
-}
-
-static void
-smp_targeted_tlb_shootdown(u_int mask, u_int vector, vm_offset_t addr1, vm_offset_t addr2)
-{
- int ncpu, othercpus;
- register_t eflags;
-
- othercpus = mp_ncpus - 1;
- if (mask == (u_int)-1) {
- ncpu = othercpus;
- if (ncpu < 1)
- return;
- } else {
- /* XXX there should be a pcpu self mask */
- mask &= ~(1 << PCPU_GET(cpuid));
- if (mask == 0)
- return;
- ncpu = popcnt(mask);
- if (ncpu > othercpus) {
- /* XXX this should be a panic offence */
- printf("SMP: tlb shootdown to %d other cpus (only have %d)\n",
- ncpu, othercpus);
- ncpu = othercpus;
- }
- /* XXX should be a panic, implied by mask == 0 above */
- if (ncpu < 1)
- return;
- }
- eflags = read_eflags();
- if ((eflags & PSL_I) == 0)
- panic("absolutely cannot call smp_targeted_ipi_shootdown with interrupts already disabled");
- mtx_lock_spin(&smp_tlb_mtx);
- smp_tlb_addr1 = addr1;
- smp_tlb_addr2 = addr2;
- atomic_store_rel_int(&smp_tlb_wait, 0);
- if (mask == (u_int)-1)
- ipi_all_but_self(vector);
- else
- ipi_selected(mask, vector);
- while (smp_tlb_wait < ncpu)
- ia32_pause();
- mtx_unlock_spin(&smp_tlb_mtx);
-}
-#endif
-
-void
-smp_invltlb(void)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLTLB, 0, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_global++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_invlpg(vm_offset_t addr)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLPG, addr, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_page++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_invlpg_range(vm_offset_t addr1, vm_offset_t addr2)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLRNG, addr1, addr2);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_range++;
- ipi_range_size += (addr2 - addr1) / PAGE_SIZE;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invltlb(u_int mask)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLTLB, 0, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_global++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invlpg(u_int mask, vm_offset_t addr)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLPG, addr, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_page++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invlpg_range(u_int mask, vm_offset_t addr1, vm_offset_t addr2)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLRNG, addr1, addr2);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_range++;
- ipi_masked_range_size += (addr2 - addr1) / PAGE_SIZE;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-
-/*
- * This is called once the rest of the system is up and running and we're
- * ready to let the AP's out of the pen.
- */
-void
-ap_init(void)
-{
- u_int apic_id;
-
- /* spin until all the AP's are ready */
- while (!aps_ready)
- ia32_pause();
-
- /* BSP may have changed PTD while we were waiting */
- invltlb();
-
-#if defined(I586_CPU) && !defined(NO_F00F_HACK)
- lidt(&r_idt);
-#endif
-
- /* set up CPU registers and state */
- cpu_setregs();
-
- /* set up FPU state on the AP */
- npxinit(__INITIAL_NPXCW__);
-
- /* set up SSE registers */
- enable_sse();
-
- /* A quick check from sanity claus */
- apic_id = (apic_id_to_logical[(lapic.id & 0x0f000000) >> 24]);
- if (PCPU_GET(cpuid) != apic_id) {
- printf("SMP: cpuid = %d\n", PCPU_GET(cpuid));
- printf("SMP: apic_id = %d\n", apic_id);
- printf("PTD[MPPTDI] = %#jx\n", (uintmax_t)PTD[MPPTDI]);
- panic("cpuid mismatch! boom!!");
- }
-
- /* Init local apic for irq's */
- apic_initialize();
-
- /* Set memory range attributes for this CPU to match the BSP */
- mem_range_AP_init();
-
- mtx_lock_spin(&ap_boot_mtx);
-
- smp_cpus++;
-
- CTR1(KTR_SMP, "SMP: AP CPU #%d Launched", PCPU_GET(cpuid));
- printf("SMP: AP CPU #%d Launched!\n", PCPU_GET(cpuid));
-
- /* Build our map of 'other' CPUs. */
- PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
-
- if (bootverbose)
- apic_dump("ap_init()");
-
- if (smp_cpus == mp_ncpus) {
- /* enable IPI's, tlb shootdown, freezes etc */
- atomic_store_rel_int(&smp_started, 1);
- smp_active = 1; /* historic */
- }
-
- mtx_unlock_spin(&ap_boot_mtx);
-
- /* wait until all the AP's are up */
- while (smp_started == 0)
- ia32_pause();
-
- /* ok, now grab sched_lock and enter the scheduler */
- mtx_lock_spin(&sched_lock);
-
- binuptime(PCPU_PTR(switchtime));
- PCPU_SET(switchticks, ticks);
-
- cpu_throw(NULL, choosethread()); /* doesn't return */
-
- panic("scheduler returned us to %s", __func__);
-}
-
-/*
- * For statclock, we send an IPI to all CPU's to have them call this
- * function.
- *
- * WARNING! unpend() will call statclock() directly and skip this
- * routine.
- */
-void
-forwarded_statclock(struct clockframe frame)
-{
-
- if (profprocs != 0)
- profclock(&frame);
- if (pscnt == psdiv)
- statclock(&frame);
-}
-
-void
-forward_statclock(void)
-{
- int map;
-
- CTR0(KTR_SMP, "forward_statclock");
-
- if (!smp_started || cold || panicstr)
- return;
-
- map = PCPU_GET(other_cpus) & ~stopped_cpus ;
- if (map != 0)
- ipi_selected(map, IPI_STATCLOCK);
-}
-
-/*
- * For each hardclock(), we send an IPI to all other CPU's to have them
- * execute this function. It would be nice to reduce contention on
- * sched_lock if we could simply peek at the CPU to determine the user/kernel
- * state and call hardclock_process() on the CPU receiving the clock interrupt
- * and then just use a simple IPI to handle any ast's if needed.
- *
- * WARNING! unpend() will call hardclock_process() directly and skip this
- * routine.
- */
-void
-forwarded_hardclock(struct clockframe frame)
-{
-
- hardclock_process(&frame);
-}
-
-void
-forward_hardclock(void)
-{
- u_int map;
-
- CTR0(KTR_SMP, "forward_hardclock");
-
- if (!smp_started || cold || panicstr)
- return;
-
- map = PCPU_GET(other_cpus) & ~stopped_cpus ;
- if (map != 0)
- ipi_selected(map, IPI_HARDCLOCK);
-}
-
-#ifdef APIC_INTR_REORDER
-/*
- * Maintain mapping from softintr vector to isr bit in local apic.
- */
-void
-set_lapic_isrloc(int intr, int vector)
-{
- if (intr < 0 || intr > 32)
- panic("set_apic_isrloc: bad intr argument: %d",intr);
- if (vector < ICU_OFFSET || vector > 255)
- panic("set_apic_isrloc: bad vector argument: %d",vector);
- apic_isrbit_location[intr].location = &lapic.isr0 + ((vector>>5)<<2);
- apic_isrbit_location[intr].bit = (1<<(vector & 31));
-}
-#endif
-
-/*
- * send an IPI to a set of cpus.
- */
-void
-ipi_selected(u_int32_t cpus, u_int ipi)
-{
-
- CTR3(KTR_SMP, "%s: cpus: %x ipi: %x", __func__, cpus, ipi);
- selected_apic_ipi(cpus, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI INTerrupt containing 'vector' to all CPUs, including myself
- */
-void
-ipi_all(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_ALLISELF, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI to all CPUs EXCEPT myself
- */
-void
-ipi_all_but_self(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_ALLESELF, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI to myself
- */
-void
-ipi_self(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_SELF, ipi, APIC_DELMODE_FIXED);
-}
-
-static void
-release_aps(void *dummy __unused)
-{
-
- if (mp_ncpus == 1)
- return;
- mtx_lock_spin(&sched_lock);
- atomic_store_rel_int(&aps_ready, 1);
- while (smp_started == 0)
- ia32_pause();
- mtx_unlock_spin(&sched_lock);
-}
-
-SYSINIT(start_aps, SI_SUB_SMP, SI_ORDER_FIRST, release_aps, NULL);
-
-static int hlt_cpus_mask;
-static int hlt_logical_cpus = 1;
-static struct sysctl_ctx_list logical_cpu_clist;
-
-static int
-sysctl_hlt_cpus(SYSCTL_HANDLER_ARGS)
-{
- u_int mask;
- int error;
-
- mask = hlt_cpus_mask;
- error = sysctl_handle_int(oidp, &mask, 0, req);
- if (error || !req->newptr)
- return (error);
-
- if (logical_cpus_mask != 0 &&
- (mask & logical_cpus_mask) == logical_cpus_mask)
- hlt_logical_cpus = 1;
- else
- hlt_logical_cpus = 0;
-
- if ((mask & all_cpus) == all_cpus)
- mask &= ~(1<<0);
- hlt_cpus_mask = mask;
- return (error);
-}
-SYSCTL_PROC(_machdep, OID_AUTO, hlt_cpus, CTLTYPE_INT|CTLFLAG_RW,
- 0, 0, sysctl_hlt_cpus, "IU", "");
-
-static int
-sysctl_hlt_logical_cpus(SYSCTL_HANDLER_ARGS)
-{
- int disable, error;
-
- disable = hlt_logical_cpus;
- error = sysctl_handle_int(oidp, &disable, 0, req);
- if (error || !req->newptr)
- return (error);
-
- if (disable)
- hlt_cpus_mask |= logical_cpus_mask;
- else
- hlt_cpus_mask &= ~logical_cpus_mask;
-
- if ((hlt_cpus_mask & all_cpus) == all_cpus)
- hlt_cpus_mask &= ~(1<<0);
-
- hlt_logical_cpus = disable;
- return (error);
-}
-
-static void
-cpu_hlt_setup(void *dummy __unused)
-{
-
- if (logical_cpus_mask != 0) {
- TUNABLE_INT_FETCH("machdep.hlt_logical_cpus",
- &hlt_logical_cpus);
- sysctl_ctx_init(&logical_cpu_clist);
- SYSCTL_ADD_PROC(&logical_cpu_clist,
- SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
- "hlt_logical_cpus", CTLTYPE_INT|CTLFLAG_RW, 0, 0,
- sysctl_hlt_logical_cpus, "IU", "");
- SYSCTL_ADD_UINT(&logical_cpu_clist,
- SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
- "logical_cpus_mask", CTLTYPE_INT|CTLFLAG_RD,
- &logical_cpus_mask, 0, "");
-
- if (hlt_logical_cpus)
- hlt_cpus_mask |= logical_cpus_mask;
- }
-}
-SYSINIT(cpu_hlt, SI_SUB_SMP, SI_ORDER_ANY, cpu_hlt_setup, NULL);
-
-int
-mp_grab_cpu_hlt(void)
-{
- u_int mask = PCPU_GET(cpumask);
- int retval;
-
- retval = mask & hlt_cpus_mask;
- while (mask & hlt_cpus_mask)
- __asm __volatile("sti; hlt" : : : "memory");
- return (retval);
-}
diff --git a/sys/amd64/include/pc/bios.h b/sys/amd64/include/pc/bios.h
deleted file mode 100644
index fe1f7039d16f..000000000000
--- a/sys/amd64/include/pc/bios.h
+++ /dev/null
@@ -1,280 +0,0 @@
-/*-
- * Copyright (c) 1997 Michael Smith
- * Copyright (c) 1998 Jonathan Lemon
- * 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$
- */
-
-/*
- * Signature structure for the BIOS32 Service Directory header
- */
-struct bios32_SDheader
-{
- u_int8_t sig[4];
- u_int32_t entry;
- u_int8_t revision;
- u_int8_t len;
- u_int8_t cksum;
- u_int8_t pad[5];
-};
-
-/*
- * BIOS32 Service Directory entry. Caller supplies name, bios32_SDlookup
- * fills in the rest of the details.
- */
-struct bios32_SDentry
-{
- union
- {
- u_int8_t name[4]; /* service identifier */
- u_int32_t id; /* as a 32-bit value */
- } ident;
- u_int32_t base; /* base of service */
- u_int32_t len; /* service length */
- u_int32_t entry; /* entrypoint offset from base */
- vm_offset_t ventry; /* entrypoint in kernel virtual segment */
-};
-
-extern int bios32_SDlookup(struct bios32_SDentry *ent);
-extern u_int32_t bios_sigsearch(u_int32_t start, u_char *sig, int siglen,
- int paralen, int sigofs);
-
-#define BIOS_PADDRTOVADDR(x) (((x) - ISA_HOLE_START) + atdevbase)
-#define BIOS_VADDRTOPADDR(x) (((x) - atdevbase) + ISA_HOLE_START)
-
-
-/*
- * PnP BIOS presence structure
- */
-struct PnPBIOS_table
-{
- u_int8_t sig[4]; /* "$PnP */
- u_int8_t version; /* should be 0x10 */
- u_int8_t len; /* total structure length */
- u_int16_t control; /* BIOS feature flags */
- u_int8_t cksum; /* checksum */
- u_int32_t evflagaddr; /* address of event notificaton flag */
- u_int16_t rmentryoffset; /* real-mode entry offset */
- u_int16_t rmentryseg; /* segment */
- u_int16_t pmentryoffset; /* protected-mode entry offset */
- u_int32_t pmentrybase; /* segment base */
- u_int32_t oemdevid; /* motherboard EISA ID */
- u_int16_t rmbiosseg; /* real-mode BIOS segment */
- u_int32_t pmdataseg; /* protected-mode data segment */
-} __packed;
-
-
-/*
- * Exported lookup results
- */
-extern struct bios32_SDentry PCIbios;
-extern struct PnPBIOS_table *PnPBIOStable;
-
-struct segment_info {
- u_int base;
- u_int limit;
-};
-
-#define BIOSCODE_FLAG 0x01
-#define BIOSDATA_FLAG 0x02
-#define BIOSUTIL_FLAG 0x04
-#define BIOSARGS_FLAG 0x08
-
-struct bios_segments {
- struct segment_info code32; /* 32-bit code (mandatory) */
- struct segment_info code16; /* 16-bit code */
- struct segment_info data; /* 16-bit data */
- struct segment_info util; /* 16-bit utility */
- struct segment_info args; /* 16-bit args */
-};
-
-struct bios_regs {
- u_int eax;
- u_int ebx;
- u_int ecx;
- u_int edx;
- u_int esi;
- u_int edi;
-};
-
-struct bios_args {
- u_int entry; /* entry point of routine */
- struct bios_regs r;
- struct bios_segments seg;
-};
-
-/*
- * PnP BIOS return codes
- */
-#define PNP_SUCCESS 0x00
-#define PNP_NOT_SET_STATICALLY 0x7f
-#define PNP_UNKNOWN_FUNCTION 0x81
-#define PNP_FUNTION_NOT_SUPPORTED 0x82
-#define PNP_INVALID_HANDLE 0x83
-#define PNP_BAD_PARAMETER 0x84
-#define PNP_SET_FAILED 0x85
-#define PNP_EVENTS_NOT_PENDING 0x86
-#define PNP_SYSTEM_NOT_DOCKED 0x87
-#define PNP_NO_ISA_PNP_CARDS 0x88
-#define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
-#define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY 0x8a
-#define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
-#define PNP_BUFFER_TOO_SMALL 0x8c
-#define PNP_USE_ESCD_SUPPORT 0x8d
-#define PNP_MESSAGE_NOT_SUPPORTED 0x8e
-#define PNP_HARDWARE_ERROR 0x8f
-
-/*
- * DMI return codes
- */
-#define DMI_SUCCESS 0x00
-#define DMI_UNKNOWN_FUNCTION 0x81
-#define DMI_FUNCTION_NOT_SUPPORTED 0x82
-#define DMI_INVALID_HANDLE 0x83
-#define DMI_BAD_PARAMETER 0x84
-#define DMI_INVALID_SUBFUNCTION 0x85
-#define DMI_NO_CHANGE 0x86
-#define DMI_ADD_STRUCTURE_FAILED 0x87
-#define DMI_READ_ONLY 0x8d
-#define DMI_LOCK_NOT_SUPPORTED 0x90
-#define DMI_CURRENTLY_LOCKED 0x91
-#define DMI_INVALID_LOCK 0x92
-
-/*
- * format specifiers and defines for bios16()
- * s = short (16 bits)
- * i = int (32 bits)
- * p = pointer (converted to seg:offset)
- * C,D,U = selector (corresponding to code/data/utility segment)
- */
-#define PNP_COUNT_DEVNODES "sppD", 0x00
-#define PNP_GET_DEVNODE "sppsD", 0x01
-#define PNP_SET_DEVNODE "sspsD", 0x02
-#define PNP_GET_EVENT "spD", 0x03
-#define PNP_SEND_MSG "ssD", 0x04
-#define PNP_GET_DOCK_INFO "spD", 0x05
-
-#define PNP_SEL_PRIBOOT "ssiiisspD", 0x07
-#define PNP_GET_PRIBOOT "sspppppD", 0x08
-#define PNP_SET_RESINFO "spD", 0x09
-#define PNP_GET_RESINFO "spD", 0x0A
-#define PNP_GET_APM_ID "sppD", 0x0B
-
-#define PNP_GET_ISA_INFO "spD", 0x40
-#define PNP_GET_ECSD_INFO "spppD", 0x41
-#define PNP_READ_ESCD "spUD", 0x42
-#define PNP_WRITE_ESCD "spUD", 0x43
-
-#define PNP_GET_DMI_INFO "spppppD", 0x50
-#define PNP_GET_DMI_STRUCTURE "sppUD", 0x51
-#define PNP_SET_DMI_STRUCTURE "sppsUD" 0x52
-#define PNP_GET_DMI_CHANGE "spUD" 0x53
-#define PNP_DMI_CONTROL "sspsUD" 0x54
-#define PNP_GET_GPNV_INFO "sppppD" 0x55
-#define PNP_READ_GPNV_DATA "ssppUD" 0x56
-#define PNP_WRITE_GPNV_DATA "sspsUD" 0x57
-
-#define PNP_BOOT_CHECK "sp", 0x60
-#define PNP_COUNT_IPL "sppp", 0x61
-#define PNP_GET_BOOTPRI "spp", 0x62
-#define PNP_SET_BOOTPRI "sp", 0x63
-#define PNP_GET_LASTBOOT "sp", 0x64
-#define PNP_GET_BOOTFIRST "sp", 0x65
-#define PNP_SET_BOOTFIRST "sp", 0x66
-
-/*
- * PCI BIOS functions
- */
-#define PCIBIOS_BIOS_PRESENT 0xb101
-#define PCIBIOS_READ_CONFIG_BYTE 0xb108
-#define PCIBIOS_READ_CONFIG_WORD 0xb109
-#define PCIBIOS_READ_CONFIG_DWORD 0xb10a
-#define PCIBIOS_WRITE_CONFIG_BYTE 0xb10b
-#define PCIBIOS_WRITE_CONFIG_WORD 0xb10c
-#define PCIBIOS_WRITE_CONFIG_DWORD 0xb10d
-#define PCIBIOS_GET_IRQ_ROUTING 0xb10e
-#define PCIBIOS_ROUTE_INTERRUPT 0xb10f
-
-extern int bios16(struct bios_args *, char *, ...);
-extern int bios16_call(struct bios_regs *, char *);
-extern int bios32(struct bios_regs *, u_int, u_short);
-extern void set_bios_selectors(struct bios_segments *, int);
-
-/*
- * PCI interrupt routing table.
- *
- * $PIR in the BIOS segment contains a PIR_table
- * int 1a:b106 returns PIR_table in buffer at es:(e)di
- * int 1a:b18e returns PIR_table in buffer at es:(e)di
- * int 1a:b406 returns es:di pointing to the BIOS PIR_table
- */
-struct PIR_header
-{
- int8_t ph_signature[4];
- u_int16_t ph_version;
- u_int16_t ph_length;
- u_int8_t ph_router_bus;
- u_int8_t ph_router_dev_fn;
- u_int16_t ph_pci_irqs;
- u_int16_t ph_router_vendor;
- u_int16_t ph_router_device;
- u_int32_t ph_miniport;
- u_int8_t ph_res[11];
- u_int8_t ph_checksum;
-} __packed;
-
-struct PIR_intpin
-{
- u_int8_t link;
- u_int16_t irqs;
-} __packed;
-
-struct PIR_entry
-{
- u_int8_t pe_bus;
- u_int8_t pe_res1:3;
- u_int8_t pe_device:5;
- struct PIR_intpin pe_intpin[4];
- u_int8_t pe_slot;
- u_int8_t pe_res3;
-} __packed;
-
-struct PIR_table
-{
- struct PIR_header pt_header;
- struct PIR_entry pt_entry[0];
-} __packed;
-
-/*
- * Int 15:E820 'SMAP' structure
- *
- * XXX add constants for type
- */
-#define SMAP_SIG 0x534D4150 /* 'SMAP' */
-struct bios_smap {
- u_int64_t base;
- u_int64_t length;
- u_int32_t type;
-} __packed;
diff --git a/sys/amd64/isa/atpic_vector.S b/sys/amd64/isa/atpic_vector.S
deleted file mode 100644
index 1023635b2ae0..000000000000
--- a/sys/amd64/isa/atpic_vector.S
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * from: vector.s, 386BSD 0.1 unknown origin
- * $FreeBSD$
- */
-
-#define IRQ_BIT(irq_num) (1 << ((irq_num) % 8))
-#define IRQ_LBIT(irq_num) (1 << (irq_num))
-#define IRQ_BYTE(irq_num) ((irq_num) >> 3)
-
-#ifdef AUTO_EOI_1
-
-#define ENABLE_ICU1 /* use auto-EOI to reduce i/o */
-#define OUTB_ICU1
-
-#else
-
-#define ENABLE_ICU1 \
- movb $ICU_EOI,%al ; /* as soon as possible send EOI ... */ \
- OUTB_ICU1 /* ... to clear in service bit */
-
-#define OUTB_ICU1 \
- outb %al,$IO_ICU1
-
-#endif
-
-#ifdef AUTO_EOI_2
-/*
- * The data sheet says no auto-EOI on slave, but it sometimes works.
- */
-#define ENABLE_ICU1_AND_2 ENABLE_ICU1
-
-#else
-
-#define ENABLE_ICU1_AND_2 \
- movb $ICU_EOI,%al ; /* as above */ \
- outb %al,$IO_ICU2 ; /* but do second icu first ... */ \
- OUTB_ICU1 /* ... then first icu (if !AUTO_EOI_1) */
-
-#endif
-
-#define PUSH_FRAME \
- pushl $0 ; /* dummy error code */ \
- pushl $0 ; /* dummy trap type */ \
- pushal ; /* 8 ints */ \
- pushl %ds ; /* save data and extra segments ... */ \
- pushl %es ; \
- pushl %fs
-
-#define PUSH_DUMMY \
- pushfl ; /* eflags */ \
- pushl %cs ; /* cs */ \
- pushl 12(%esp) ; /* original caller eip */ \
- pushl $0 ; /* dummy error code */ \
- pushl $0 ; /* dummy trap type */ \
- subl $11*4,%esp
-
-#define POP_FRAME \
- popl %fs ; \
- popl %es ; \
- popl %ds ; \
- popal ; \
- addl $4+4,%esp
-
-#define POP_DUMMY \
- addl $16*4,%esp
-
-#define MASK_IRQ(icu, irq_num) \
- movb imen + IRQ_BYTE(irq_num),%al ; \
- orb $IRQ_BIT(irq_num),%al ; \
- movb %al,imen + IRQ_BYTE(irq_num) ; \
- outb %al,$icu+ICU_IMR_OFFSET
-
-#define UNMASK_IRQ(icu, irq_num) \
- movb imen + IRQ_BYTE(irq_num),%al ; \
- andb $~IRQ_BIT(irq_num),%al ; \
- movb %al,imen + IRQ_BYTE(irq_num) ; \
- outb %al,$icu+ICU_IMR_OFFSET
-/*
- * Macros for interrupt interrupt entry, call to handler, and exit.
- */
-
-#define FAST_INTR(irq_num, vec_name, icu, enable_icus) \
- .text ; \
- SUPERALIGN_TEXT ; \
-IDTVEC(vec_name) ; \
- PUSH_FRAME ; \
- mov $KDSEL,%ax ; \
- mov %ax,%ds ; \
- mov %ax,%es ; \
- mov $KPSEL,%ax ; \
- mov %ax,%fs ; \
- FAKE_MCOUNT((12+ACTUALLY_PUSHED)*4(%esp)) ; \
- movl PCPU(CURTHREAD),%ebx ; \
- cmpl $0,TD_CRITNEST(%ebx) ; \
- je 1f ; \
-; \
- movl $1,PCPU(INT_PENDING) ; \
- orl $IRQ_LBIT(irq_num),PCPU(FPENDING) ; \
- MASK_IRQ(icu, irq_num) ; \
- enable_icus ; \
- jmp 10f ; \
-1: ; \
- incl TD_CRITNEST(%ebx) ; \
- incl TD_INTR_NESTING_LEVEL(%ebx) ; \
- pushl intr_unit + (irq_num) * 4 ; \
- call *intr_handler + (irq_num) * 4 ; \
- addl $4,%esp ; \
- enable_icus ; \
- incl cnt+V_INTR ; /* book-keeping can wait */ \
- movl intr_countp + (irq_num) * 4,%eax ; \
- incl (%eax) ; \
- decl TD_CRITNEST(%ebx) ; \
- cmpl $0,PCPU(INT_PENDING) ; \
- je 2f ; \
-; \
- call i386_unpend ; \
-2: ; \
- decl TD_INTR_NESTING_LEVEL(%ebx) ; \
-10: ; \
- MEXITCOUNT ; \
- jmp doreti
-
-/*
- * Restart a fast interrupt that was held up by a critical section.
- * This routine is called from unpend(). unpend() ensures we are
- * in a critical section and deals with the interrupt nesting level
- * for us. If we previously masked the irq, we have to unmask it.
- *
- * We have a choice. We can regenerate the irq using the 'int'
- * instruction or we can create a dummy frame and call the interrupt
- * handler directly. I've chosen to use the dummy-frame method.
- */
-#define FAST_UNPEND(irq_num, vec_name, icu) \
- .text ; \
- SUPERALIGN_TEXT ; \
-IDTVEC(vec_name) ; \
-; \
- pushl %ebp ; \
- movl %esp, %ebp ; \
- PUSH_DUMMY ; \
- pushl intr_unit + (irq_num) * 4 ; \
- call *intr_handler + (irq_num) * 4 ; /* do the work ASAP */ \
- addl $4, %esp ; \
- incl cnt+V_INTR ; /* book-keeping can wait */ \
- movl intr_countp + (irq_num) * 4,%eax ; \
- incl (%eax) ; \
- UNMASK_IRQ(icu, irq_num) ; \
- POP_DUMMY ; \
- popl %ebp ; \
- ret
-
-/*
- * Slow, threaded interrupts.
- *
- * XXX Most of the parameters here are obsolete. Fix this when we're
- * done.
- * XXX we really shouldn't return via doreti if we just schedule the
- * interrupt handler and don't run anything. We could just do an
- * iret. FIXME.
- */
-#define INTR(irq_num, vec_name, icu, enable_icus, maybe_extra_ipending) \
- .text ; \
- SUPERALIGN_TEXT ; \
-IDTVEC(vec_name) ; \
- PUSH_FRAME ; \
- mov $KDSEL,%ax ; /* load kernel ds, es and fs */ \
- mov %ax,%ds ; \
- mov %ax,%es ; \
- mov $KPSEL,%ax ; \
- mov %ax,%fs ; \
-; \
- maybe_extra_ipending ; \
- MASK_IRQ(icu, irq_num) ; \
- enable_icus ; \
-; \
- movl PCPU(CURTHREAD),%ebx ; \
- cmpl $0,TD_CRITNEST(%ebx) ; \
- je 1f ; \
- movl $1,PCPU(INT_PENDING); \
- orl $IRQ_LBIT(irq_num),PCPU(IPENDING) ; \
- jmp 10f ; \
-1: ; \
- incl TD_INTR_NESTING_LEVEL(%ebx) ; \
-; \
- FAKE_MCOUNT(13*4(%esp)) ; /* XXX late to avoid double count */ \
- cmpl $0,PCPU(INT_PENDING) ; \
- je 9f ; \
- call i386_unpend ; \
-9: ; \
- pushl $irq_num; /* pass the IRQ */ \
- call sched_ithd ; \
- addl $4, %esp ; /* discard the parameter */ \
-; \
- decl TD_INTR_NESTING_LEVEL(%ebx) ; \
-10: ; \
- MEXITCOUNT ; \
- jmp doreti
-
-MCOUNT_LABEL(bintr)
- FAST_INTR(0,fastintr0, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(1,fastintr1, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(2,fastintr2, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(3,fastintr3, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(4,fastintr4, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(5,fastintr5, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(6,fastintr6, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(7,fastintr7, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(8,fastintr8, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(9,fastintr9, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(10,fastintr10, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(11,fastintr11, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(12,fastintr12, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(13,fastintr13, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(14,fastintr14, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(15,fastintr15, IO_ICU2, ENABLE_ICU1_AND_2)
-
-#define CLKINTR_PENDING movl $1,CNAME(clkintr_pending)
-/* Threaded interrupts */
- INTR(0,intr0, IO_ICU1, ENABLE_ICU1, CLKINTR_PENDING)
- INTR(1,intr1, IO_ICU1, ENABLE_ICU1,)
- INTR(2,intr2, IO_ICU1, ENABLE_ICU1,)
- INTR(3,intr3, IO_ICU1, ENABLE_ICU1,)
- INTR(4,intr4, IO_ICU1, ENABLE_ICU1,)
- INTR(5,intr5, IO_ICU1, ENABLE_ICU1,)
- INTR(6,intr6, IO_ICU1, ENABLE_ICU1,)
- INTR(7,intr7, IO_ICU1, ENABLE_ICU1,)
- INTR(8,intr8, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(9,intr9, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(10,intr10, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(11,intr11, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(12,intr12, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(13,intr13, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(14,intr14, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(15,intr15, IO_ICU2, ENABLE_ICU1_AND_2,)
-
- FAST_UNPEND(0,fastunpend0, IO_ICU1)
- FAST_UNPEND(1,fastunpend1, IO_ICU1)
- FAST_UNPEND(2,fastunpend2, IO_ICU1)
- FAST_UNPEND(3,fastunpend3, IO_ICU1)
- FAST_UNPEND(4,fastunpend4, IO_ICU1)
- FAST_UNPEND(5,fastunpend5, IO_ICU1)
- FAST_UNPEND(6,fastunpend6, IO_ICU1)
- FAST_UNPEND(7,fastunpend7, IO_ICU1)
- FAST_UNPEND(8,fastunpend8, IO_ICU2)
- FAST_UNPEND(9,fastunpend9, IO_ICU2)
- FAST_UNPEND(10,fastunpend10, IO_ICU2)
- FAST_UNPEND(11,fastunpend11, IO_ICU2)
- FAST_UNPEND(12,fastunpend12, IO_ICU2)
- FAST_UNPEND(13,fastunpend13, IO_ICU2)
- FAST_UNPEND(14,fastunpend14, IO_ICU2)
- FAST_UNPEND(15,fastunpend15, IO_ICU2)
-MCOUNT_LABEL(eintr)
-
diff --git a/sys/amd64/isa/nmi.c b/sys/amd64/isa/nmi.c
deleted file mode 100644
index b0269555f2fc..000000000000
--- a/sys/amd64/isa/nmi.c
+++ /dev/null
@@ -1,714 +0,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)isa.c 7.2 (Berkeley) 5/13/91
- * $FreeBSD$
- */
-
-#include "opt_auto_eoi.h"
-#include "opt_isa.h"
-#include "opt_mca.h"
-
-#include <sys/param.h>
-#include <sys/bus.h>
-#include <sys/errno.h>
-#include <sys/interrupt.h>
-#include <sys/kernel.h>
-#include <sys/kthread.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/module.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/syslog.h>
-#include <sys/systm.h>
-#include <sys/unistd.h>
-
-#include <machine/md_var.h>
-#include <machine/segments.h>
-
-#if defined(APIC_IO)
-#include <machine/smptests.h> /** FAST_HI */
-#include <machine/smp.h>
-#include <machine/resource.h>
-#endif /* APIC_IO */
-#ifdef PC98
-#include <pc98/pc98/pc98.h>
-#include <pc98/pc98/pc98_machdep.h>
-#include <pc98/pc98/epsonio.h>
-#else
-#include <i386/isa/isa.h>
-#endif
-#include <i386/isa/icu.h>
-
-#ifdef DEV_ISA
-#include <isa/isavar.h>
-#endif
-#include <i386/isa/intr_machdep.h>
-#include <sys/interrupt.h>
-#ifdef APIC_IO
-#include <machine/clock.h>
-#endif
-
-#ifdef DEV_MCA
-#include <i386/bios/mca_machdep.h>
-#endif
-
-/*
- * Per-interrupt data.
- */
-u_long *intr_countp[ICU_LEN]; /* pointers to interrupt counters */
-driver_intr_t *intr_handler[ICU_LEN]; /* first level interrupt handler */
-struct ithd *ithds[ICU_LEN]; /* real interrupt handler */
-void *intr_unit[ICU_LEN];
-
-static struct mtx ithds_table_lock; /* protect the ithds table */
-
-static inthand_t *fastintr[ICU_LEN] = {
- IDTVEC(fastintr0), IDTVEC(fastintr1),
- IDTVEC(fastintr2), IDTVEC(fastintr3),
- IDTVEC(fastintr4), IDTVEC(fastintr5),
- IDTVEC(fastintr6), IDTVEC(fastintr7),
- IDTVEC(fastintr8), IDTVEC(fastintr9),
- IDTVEC(fastintr10), IDTVEC(fastintr11),
- IDTVEC(fastintr12), IDTVEC(fastintr13),
- IDTVEC(fastintr14), IDTVEC(fastintr15),
-#if defined(APIC_IO)
- IDTVEC(fastintr16), IDTVEC(fastintr17),
- IDTVEC(fastintr18), IDTVEC(fastintr19),
- IDTVEC(fastintr20), IDTVEC(fastintr21),
- IDTVEC(fastintr22), IDTVEC(fastintr23),
- IDTVEC(fastintr24), IDTVEC(fastintr25),
- IDTVEC(fastintr26), IDTVEC(fastintr27),
- IDTVEC(fastintr28), IDTVEC(fastintr29),
- IDTVEC(fastintr30), IDTVEC(fastintr31),
-#endif /* APIC_IO */
-};
-
-static unpendhand_t *fastunpend[ICU_LEN] = {
- IDTVEC(fastunpend0), IDTVEC(fastunpend1),
- IDTVEC(fastunpend2), IDTVEC(fastunpend3),
- IDTVEC(fastunpend4), IDTVEC(fastunpend5),
- IDTVEC(fastunpend6), IDTVEC(fastunpend7),
- IDTVEC(fastunpend8), IDTVEC(fastunpend9),
- IDTVEC(fastunpend10), IDTVEC(fastunpend11),
- IDTVEC(fastunpend12), IDTVEC(fastunpend13),
- IDTVEC(fastunpend14), IDTVEC(fastunpend15),
-#if defined(APIC_IO)
- IDTVEC(fastunpend16), IDTVEC(fastunpend17),
- IDTVEC(fastunpend18), IDTVEC(fastunpend19),
- IDTVEC(fastunpend20), IDTVEC(fastunpend21),
- IDTVEC(fastunpend22), IDTVEC(fastunpend23),
- IDTVEC(fastunpend24), IDTVEC(fastunpend25),
- IDTVEC(fastunpend26), IDTVEC(fastunpend27),
- IDTVEC(fastunpend28), IDTVEC(fastunpend29),
- IDTVEC(fastunpend30), IDTVEC(fastunpend31),
-#endif /* APIC_IO */
-};
-
-static inthand_t *slowintr[ICU_LEN] = {
- IDTVEC(intr0), IDTVEC(intr1), IDTVEC(intr2), IDTVEC(intr3),
- IDTVEC(intr4), IDTVEC(intr5), IDTVEC(intr6), IDTVEC(intr7),
- IDTVEC(intr8), IDTVEC(intr9), IDTVEC(intr10), IDTVEC(intr11),
- IDTVEC(intr12), IDTVEC(intr13), IDTVEC(intr14), IDTVEC(intr15),
-#if defined(APIC_IO)
- IDTVEC(intr16), IDTVEC(intr17), IDTVEC(intr18), IDTVEC(intr19),
- IDTVEC(intr20), IDTVEC(intr21), IDTVEC(intr22), IDTVEC(intr23),
- IDTVEC(intr24), IDTVEC(intr25), IDTVEC(intr26), IDTVEC(intr27),
- IDTVEC(intr28), IDTVEC(intr29), IDTVEC(intr30), IDTVEC(intr31),
-#endif /* APIC_IO */
-};
-
-static driver_intr_t isa_strayintr;
-
-static void ithds_init(void *dummy);
-static void ithread_enable(int vector);
-static void ithread_disable(int vector);
-static void init_i8259(void);
-
-#ifdef PC98
-#define NMI_PARITY 0x04
-#define NMI_EPARITY 0x02
-#else
-#define NMI_PARITY (1 << 7)
-#define NMI_IOCHAN (1 << 6)
-#define ENMI_WATCHDOG (1 << 7)
-#define ENMI_BUSTIMER (1 << 6)
-#define ENMI_IOSTATUS (1 << 5)
-#endif
-
-#ifdef DEV_ISA
-/*
- * Bus attachment for the ISA PIC.
- */
-static struct isa_pnp_id atpic_ids[] = {
- { 0x0000d041 /* PNP0000 */, "AT interrupt controller" },
- { 0 }
-};
-
-static int
-atpic_probe(device_t dev)
-{
- int result;
-
- if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, atpic_ids)) <= 0)
- device_quiet(dev);
- return(result);
-}
-
-/*
- * In the APIC_IO case we might be granted IRQ 2, as this is typically
- * consumed by chaining between the two PIC components. If we're using
- * the APIC, however, this may not be the case, and as such we should
- * free the resource. (XXX untested)
- *
- * The generic ISA attachment code will handle allocating any other resources
- * that we don't explicitly claim here.
- */
-static int
-atpic_attach(device_t dev)
-{
-#ifdef APIC_IO
- int rid;
- struct resource *res;
-
- /* try to allocate our IRQ and then free it */
- rid = 0;
- res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 0);
- if (res != NULL)
- bus_release_resource(dev, SYS_RES_IRQ, rid, res);
-#endif
- return(0);
-}
-
-static device_method_t atpic_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, atpic_probe),
- DEVMETHOD(device_attach, atpic_attach),
- DEVMETHOD(device_detach, bus_generic_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
- { 0, 0 }
-};
-
-static driver_t atpic_driver = {
- "atpic",
- atpic_methods,
- 1, /* no softc */
-};
-
-static devclass_t atpic_devclass;
-
-DRIVER_MODULE(atpic, isa, atpic_driver, atpic_devclass, 0, 0);
-DRIVER_MODULE(atpic, acpi, atpic_driver, atpic_devclass, 0, 0);
-#endif /* DEV_ISA */
-
-/*
- * Handle a NMI, possibly a machine check.
- * return true to panic system, false to ignore.
- */
-int
-isa_nmi(cd)
- int cd;
-{
- int retval = 0;
-#ifdef PC98
- int port = inb(0x33);
-
- log(LOG_CRIT, "NMI PC98 port = %x\n", port);
- if (epson_machine_id == 0x20)
- epson_outb(0xc16, epson_inb(0xc16) | 0x1);
- if (port & NMI_PARITY) {
- log(LOG_CRIT, "BASE RAM parity error, likely hardware failure.");
- retval = 1;
- } else if (port & NMI_EPARITY) {
- log(LOG_CRIT, "EXTENDED RAM parity error, likely hardware failure.");
- retval = 1;
- } else {
- log(LOG_CRIT, "\nNMI Resume ??\n");
- }
-#else /* IBM-PC */
- int isa_port = inb(0x61);
- int eisa_port = inb(0x461);
-
- log(LOG_CRIT, "NMI ISA %x, EISA %x\n", isa_port, eisa_port);
-#ifdef DEV_MCA
- if (MCA_system && mca_bus_nmi())
- return(0);
-#endif
-
- if (isa_port & NMI_PARITY) {
- log(LOG_CRIT, "RAM parity error, likely hardware failure.");
- retval = 1;
- }
-
- if (isa_port & NMI_IOCHAN) {
- log(LOG_CRIT, "I/O channel check, likely hardware failure.");
- retval = 1;
- }
-
- /*
- * On a real EISA machine, this will never happen. However it can
- * happen on ISA machines which implement XT style floating point
- * error handling (very rare). Save them from a meaningless panic.
- */
- if (eisa_port == 0xff)
- return(retval);
-
- if (eisa_port & ENMI_WATCHDOG) {
- log(LOG_CRIT, "EISA watchdog timer expired, likely hardware failure.");
- retval = 1;
- }
-
- if (eisa_port & ENMI_BUSTIMER) {
- log(LOG_CRIT, "EISA bus timeout, likely hardware failure.");
- retval = 1;
- }
-
- if (eisa_port & ENMI_IOSTATUS) {
- log(LOG_CRIT, "EISA I/O port status error.");
- retval = 1;
- }
-#endif
- return(retval);
-}
-
-/*
- * ICU reinitialize when ICU configuration has lost.
- */
-void
-icu_reinit()
-{
- int i;
- register_t crit;
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- init_i8259();
- for(i=0;i<ICU_LEN;i++)
- if(intr_handler[i] != isa_strayintr)
- INTREN(1<<i);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-}
-
-/*
- * Create a default interrupt table to avoid problems caused by
- * spurious interrupts during configuration of kernel, then setup
- * interrupt control unit.
- */
-void
-isa_defaultirq()
-{
- int i;
- register_t crit;
-
- /* icu vectors */
- for (i = 0; i < ICU_LEN; i++)
- icu_unset(i, (driver_intr_t *)NULL);
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- init_i8259();
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-}
-
-
-/*
- *initialize 8259's
- */
-static void
-init_i8259()
-{
-
-#ifdef DEV_MCA
- if (MCA_system)
- outb(IO_ICU1, 0x19); /* reset; program device, four bytes */
- else
-#endif
- outb(IO_ICU1, 0x11); /* reset; program device, four bytes */
-
- outb(IO_ICU1+ICU_IMR_OFFSET, NRSVIDT); /* starting at this vector index */
- outb(IO_ICU1+ICU_IMR_OFFSET, IRQ_SLAVE); /* slave on line 7 */
-#ifdef PC98
-#ifdef AUTO_EOI_1
- outb(IO_ICU1+ICU_IMR_OFFSET, 0x1f); /* (master) auto EOI, 8086 mode */
-#else
- outb(IO_ICU1+ICU_IMR_OFFSET, 0x1d); /* (master) 8086 mode */
-#endif
-#else /* IBM-PC */
-#ifdef AUTO_EOI_1
- outb(IO_ICU1+ICU_IMR_OFFSET, 2 | 1); /* auto EOI, 8086 mode */
-#else
- outb(IO_ICU1+ICU_IMR_OFFSET, 1); /* 8086 mode */
-#endif
-#endif /* PC98 */
- outb(IO_ICU1+ICU_IMR_OFFSET, 0xff); /* leave interrupts masked */
- outb(IO_ICU1, 0x0a); /* default to IRR on read */
-#ifndef PC98
- outb(IO_ICU1, 0xc0 | (3 - 1)); /* pri order 3-7, 0-2 (com2 first) */
-#endif /* !PC98 */
-
-#ifdef DEV_MCA
- if (MCA_system)
- outb(IO_ICU2, 0x19); /* reset; program device, four bytes */
- else
-#endif
- outb(IO_ICU2, 0x11); /* reset; program device, four bytes */
-
- outb(IO_ICU2+ICU_IMR_OFFSET, NRSVIDT+8); /* staring at this vector index */
- outb(IO_ICU2+ICU_IMR_OFFSET, ICU_SLAVEID); /* my slave id is 7 */
-#ifdef PC98
- outb(IO_ICU2+ICU_IMR_OFFSET,9); /* 8086 mode */
-#else /* IBM-PC */
-#ifdef AUTO_EOI_2
- outb(IO_ICU2+ICU_IMR_OFFSET, 2 | 1); /* auto EOI, 8086 mode */
-#else
- outb(IO_ICU2+ICU_IMR_OFFSET,1); /* 8086 mode */
-#endif
-#endif /* PC98 */
- outb(IO_ICU2+ICU_IMR_OFFSET, 0xff); /* leave interrupts masked */
- outb(IO_ICU2, 0x0a); /* default to IRR on read */
-}
-
-/*
- * Caught a stray interrupt, notify
- */
-static void
-isa_strayintr(vcookiep)
- void *vcookiep;
-{
- int intr = (void **)vcookiep - &intr_unit[0];
-
- /*
- * XXX TODO print a different message for #7 if it is for a
- * glitch. Glitches can be distinguished from real #7's by
- * testing that the in-service bit is _not_ set. The test
- * must be done before sending an EOI so it can't be done if
- * we are using AUTO_EOI_1.
- */
- if (intrcnt[1 + intr] <= 5)
- log(LOG_ERR, "stray irq %d\n", intr);
- if (intrcnt[1 + intr] == 5)
- log(LOG_CRIT,
- "too many stray irq %d's; not logging any more\n", intr);
-}
-
-#ifdef DEV_ISA
-/*
- * Return a bitmap of the current interrupt requests. This is 8259-specific
- * and is only suitable for use at probe time.
- */
-intrmask_t
-isa_irq_pending()
-{
- u_char irr1;
- u_char irr2;
-
- irr1 = inb(IO_ICU1);
- irr2 = inb(IO_ICU2);
- return ((irr2 << 8) | irr1);
-}
-#endif
-
-/*
- * Update intrnames array with the specified name. This is used by
- * vmstat(8) and the like.
- */
-static void
-update_intrname(int intr, const char *name)
-{
- char buf[32];
- char *cp;
- int name_index, off, strayintr;
-
- /*
- * Initialise strings for bitbucket and stray interrupt counters.
- * These have statically allocated indices 0 and 1 through ICU_LEN.
- */
- if (intrnames[0] == '\0') {
- off = sprintf(intrnames, "???") + 1;
- for (strayintr = 0; strayintr < ICU_LEN; strayintr++)
- off += sprintf(intrnames + off, "stray irq%d",
- strayintr) + 1;
- }
-
- if (name == NULL)
- name = "???";
- if (snprintf(buf, sizeof(buf), "%s irq%d", name, intr) >= sizeof(buf))
- goto use_bitbucket;
-
- /*
- * Search for `buf' in `intrnames'. In the usual case when it is
- * not found, append it to the end if there is enough space (the \0
- * terminator for the previous string, if any, becomes a separator).
- */
- for (cp = intrnames, name_index = 0;
- cp != eintrnames && name_index < NR_INTRNAMES;
- cp += strlen(cp) + 1, name_index++) {
- if (*cp == '\0') {
- if (strlen(buf) >= eintrnames - cp)
- break;
- strcpy(cp, buf);
- goto found;
- }
- if (strcmp(cp, buf) == 0)
- goto found;
- }
-
-use_bitbucket:
- printf("update_intrname: counting %s irq%d as %s\n", name, intr,
- intrnames);
- name_index = 0;
-found:
- intr_countp[intr] = &intrcnt[name_index];
-}
-
-int
-icu_setup(int intr, driver_intr_t *handler, void *arg, int flags)
-{
-#ifdef FAST_HI
- int select; /* the select register is 8 bits */
- int vector;
- u_int32_t value; /* the window register is 32 bits */
-#endif /* FAST_HI */
- register_t crit;
-
-#if defined(APIC_IO)
- if ((u_int)intr >= ICU_LEN) /* no 8259 SLAVE to ignore */
-#else
- if ((u_int)intr >= ICU_LEN || intr == ICU_SLAVEID)
-#endif /* APIC_IO */
- return (EINVAL);
-#if 0
- if (intr_handler[intr] != isa_strayintr)
- return (EBUSY);
-#endif
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- intr_handler[intr] = handler;
- intr_unit[intr] = arg;
-#ifdef FAST_HI
- if (flags & INTR_FAST) {
- vector = TPR_FAST_INTS + intr;
- setidt(vector, fastintr[intr],
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- }
- else {
- vector = TPR_SLOW_INTS + intr;
- setidt(vector, slowintr[intr],
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- }
-#ifdef APIC_INTR_REORDER
- set_lapic_isrloc(intr, vector);
-#endif
- /*
- * Reprogram the vector in the IO APIC.
- */
- if (int_to_apicintpin[intr].ioapic >= 0) {
- select = int_to_apicintpin[intr].redirindex;
- value = io_apic_read(int_to_apicintpin[intr].ioapic,
- select) & ~IOART_INTVEC;
- io_apic_write(int_to_apicintpin[intr].ioapic,
- select, value | vector);
- }
-#else
- setidt(ICU_OFFSET + intr,
- flags & INTR_FAST ? fastintr[intr] : slowintr[intr],
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif /* FAST_HI */
- INTREN(1 << intr);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
- return (0);
-}
-
-/*
- * Dissociate an interrupt handler from an IRQ and set the handler to
- * the stray interrupt handler. The 'handler' parameter is used only
- * for consistency checking.
- */
-int
-icu_unset(intr, handler)
- int intr;
- driver_intr_t *handler;
-{
- register_t crit;
-
- if ((u_int)intr >= ICU_LEN || handler != intr_handler[intr])
- return (EINVAL);
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTRDIS(1 << intr);
- intr_countp[intr] = &intrcnt[1 + intr];
- intr_handler[intr] = isa_strayintr;
- intr_unit[intr] = &intr_unit[intr];
-#ifdef FAST_HI_XXX
- /* XXX how do I re-create dvp here? */
- setidt(flags & INTR_FAST ? TPR_FAST_INTS + intr : TPR_SLOW_INTS + intr,
- slowintr[intr], SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#else /* FAST_HI */
-#ifdef APIC_INTR_REORDER
- set_lapic_isrloc(intr, ICU_OFFSET + intr);
-#endif
- setidt(ICU_OFFSET + intr, slowintr[intr], SDT_SYS386IGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
-#endif /* FAST_HI */
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
- return (0);
-}
-
-static void
-ithds_init(void *dummy)
-{
-
- mtx_init(&ithds_table_lock, "ithread table lock", NULL, MTX_SPIN);
-}
-SYSINIT(ithds_init, SI_SUB_INTR, SI_ORDER_SECOND, ithds_init, NULL);
-
-static void
-ithread_enable(int vector)
-{
- register_t crit;
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTREN(1 << vector);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-}
-
-static void
-ithread_disable(int vector)
-{
- register_t crit;
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTRDIS(1 << vector);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-}
-
-int
-inthand_add(const char *name, int irq, driver_intr_t handler, void *arg,
- enum intr_type flags, void **cookiep)
-{
- struct ithd *ithd; /* descriptor for the IRQ */
- int errcode = 0;
- int created_ithd = 0;
-
- /*
- * Work around a race where more than one CPU may be registering
- * handlers on the same IRQ at the same time.
- */
- mtx_lock_spin(&ithds_table_lock);
- ithd = ithds[irq];
- mtx_unlock_spin(&ithds_table_lock);
- if (ithd == NULL) {
- errcode = ithread_create(&ithd, irq, 0, ithread_disable,
- ithread_enable, "irq%d:", irq);
- if (errcode)
- return (errcode);
- mtx_lock_spin(&ithds_table_lock);
- if (ithds[irq] == NULL) {
- ithds[irq] = ithd;
- created_ithd++;
- mtx_unlock_spin(&ithds_table_lock);
- } else {
- struct ithd *orphan;
-
- orphan = ithd;
- ithd = ithds[irq];
- mtx_unlock_spin(&ithds_table_lock);
- ithread_destroy(orphan);
- }
- }
-
- errcode = ithread_add_handler(ithd, name, handler, arg,
- ithread_priority(flags), flags, cookiep);
-
- if ((flags & INTR_FAST) == 0 || errcode)
- /*
- * The interrupt process must be in place, but
- * not necessarily schedulable, before we
- * initialize the ICU, since it may cause an
- * immediate interrupt.
- */
- if (icu_setup(irq, sched_ithd, arg, flags) != 0)
- panic("inthand_add: Can't initialize ICU");
-
- if (errcode)
- return (errcode);
-
- if (flags & INTR_FAST) {
- errcode = icu_setup(irq, handler, arg, flags);
- if (errcode && bootverbose)
- printf("\tinthand_add(irq%d) failed, result=%d\n",
- irq, errcode);
- if (errcode)
- return (errcode);
- }
-
- update_intrname(irq, name);
- return (0);
-}
-
-/*
- * Deactivate and remove linked list the interrupt handler descriptor
- * data connected created by an earlier call of inthand_add(), then
- * adjust the interrupt masks if necessary.
- *
- * Return the memory held by the interrupt handler descriptor data
- * structure to the system. First ensure the handler is not actively
- * in use.
- */
-int
-inthand_remove(void *cookie)
-{
-
- return (ithread_remove_handler(cookie));
-}
-
-void
-call_fast_unpend(int irq)
-{
- fastunpend[irq]();
-}
-
diff --git a/sys/boot/i386/boot2/boot1.S b/sys/boot/i386/boot2/boot1.S
deleted file mode 100644
index e6cdab0ca156..000000000000
--- a/sys/boot/i386/boot2/boot1.S
+++ /dev/null
@@ -1,361 +0,0 @@
-//
-// Copyright (c) 1998 Robert Nordier
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms are freely
-// permitted provided that the above copyright notice and this
-// paragraph and the following disclaimer are duplicated in all
-// such forms.
-//
-// This software is provided "AS IS" and without any express or
-// implied warranties, including, without limitation, the implied
-// warranties of merchantability and fitness for a particular
-// purpose.
-//
-
-// $FreeBSD$
-
-// Memory Locations
- .set MEM_REL,0x700 // Relocation address
- .set MEM_ARG,0x900 // Arguments
- .set MEM_ORG,0x7c00 // Origin
- .set MEM_BUF,0x8cec // Load area
- .set MEM_BTX,0x9000 // BTX start
- .set MEM_JMP,0x9010 // BTX entry point
- .set MEM_USR,0xa000 // Client start
- .set BDA_BOOT,0x472 // Boot howto flag
-
-// Partition Constants
- .set PRT_OFF,0x1be // Partition offset
- .set PRT_NUM,0x4 // Partitions
- .set PRT_BSD,0xa5 // Partition type
-
-// Flag Bits
- .set FL_PACKET,0x80 // Packet mode
-
-// Misc. Constants
- .set SIZ_PAG,0x1000 // Page size
- .set SIZ_SEC,0x200 // Sector size
-
- .set NSECT,0x10
- .globl start
- .globl xread
- .code16
-
-start: jmp main // Start recognizably
-
-// This is the start of a standard BIOS Parameter Block (BPB). Most bootable
-// FAT disks have this at the start of their MBR. While normal BIOS's will
-// work fine without this section, IBM's El Torito emulation "fixes" up the
-// BPB by writing into the memory copy of the MBR. Rather than have data
-// written into our xread routine, we'll define a BPB to work around it.
-// The data marked with (T) indicates a field required for a ThinkPad to
-// recognize the disk and (W) indicates fields written from IBM BIOS code.
-// The use of the BPB is based on what OpenBSD and NetBSD implemented in
-// their boot code but the required fields were determined by trial and error.
-//
-// Note: If additional space is needed in boot1, one solution would be to
-// move the "prompt" message data (below) to replace the OEM ID.
-
- .org 0x03, 0x00
-oemid: .space 0x08, 0x00 // OEM ID
-
- .org 0x0b, 0x00
-bpb: .word 512 // sector size (T)
- .byte 0 // sectors/clustor
- .word 0 // reserved sectors
- .byte 0 // number of FATs
- .word 0 // root entries
- .word 0 // small sectors
- .byte 0 // media type (W)
- .word 0 // sectors/fat
- .word 18 // sectors per track (T)
- .word 2 // number of heads (T)
- .long 0 // hidden sectors (W)
- .long 0 // large sectors
-
- .org 0x24, 0x00
-ebpb: .byte 0 // BIOS physical drive number (W)
-
- .org 0x25,0x90
-//
-// Trampoline used by boot2 to call read to read data from the disk via
-// the BIOS. Call with:
-//
-// %cx:%ax - long - LBA to read in
-// %es:(%bx) - caddr_t - buffer to read data into
-// %dl - byte - drive to read from
-// %dh - byte - num sectors to read
-//
-
-xread: push %ss // Address
- pop %ds // data
-//
-// Setup an EDD disk packet and pass it to read
-//
-xread.1: // Starting
- pushl $0x0 // absolute
- push %cx // block
- push %ax // number
- push %es // Address of
- push %bx // transfer buffer
- xor %ax,%ax // Number of
- movb %dh,%al // blocks to
- push %ax // transfer
- push $0x10 // Size of packet
- mov %sp,%bp // Packet pointer
- callw read // Read from disk
- lea 0x10(%bp),%sp // Clear stack
- lret // To far caller
-//
-// Load the rest of boot2 and BTX up, copy the parts to the right locations,
-// and start it all up.
-//
-
-//
-// Setup the segment registers to flat addressing (segment 0) and setup the
-// stack to end just below the start of our code.
-//
-main: cld // String ops inc
- xor %cx,%cx // Zero
- mov %cx,%es // Address
- mov %cx,%ds // data
- mov %cx,%ss // Set up
- mov $start,%sp // stack
-//
-// Relocate ourself to MEM_REL. Since %cx == 0, the inc %ch sets
-// %cx == 0x100.
-//
- mov %sp,%si // Source
- mov $MEM_REL,%di // Destination
- incb %ch // Word count
- rep // Copy
- movsw // code
-//
-// If we are on a hard drive, then load the MBR and look for the first
-// FreeBSD slice. We use the fake partition entry below that points to
-// the MBR when we call nread. The first pass looks for the first active
-// FreeBSD slice. The second pass looks for the first non-active FreeBSD
-// slice if the first one fails.
-//
- mov $part4,%si // Partition
- cmpb $0x80,%dl // Hard drive?
- jb main.4 // No
- movb $0x1,%dh // Block count
- callw nread // Read MBR
- mov $0x1,%cx // Two passes
-main.1: mov $MEM_BUF+PRT_OFF,%si // Partition table
- movb $0x1,%dh // Partition
-main.2: cmpb $PRT_BSD,0x4(%si) // Our partition type?
- jne main.3 // No
- jcxz main.5 // If second pass
- testb $0x80,(%si) // Active?
- jnz main.5 // Yes
-main.3: add $0x10,%si // Next entry
- incb %dh // Partition
- cmpb $0x1+PRT_NUM,%dh // In table?
- jb main.2 // Yes
- dec %cx // Do two
- jcxz main.1 // passes
-//
-// If we get here, we didn't find any FreeBSD slices at all, so print an
-// error message and die.
-//
- mov $msg_part,%si // Message
- jmp error // Error
-//
-// Floppies use partition 0 of drive 0.
-//
-main.4: xor %dx,%dx // Partition:drive
-//
-// Ok, we have a slice and drive in %dx now, so use that to locate and load
-// boot2. %si references the start of the slice we are looking for, so go
-// ahead and load up the first 16 sectors (boot1 + boot2) from that. When
-// we read it in, we conveniently use 0x8cec as our transfer buffer. Thus,
-// boot1 ends up at 0x8cec, and boot2 starts at 0x8cec + 0x200 = 0x8eec.
-// The first part of boot2 is the disklabel, which is 0x114 bytes long.
-// The second part is BTX, which is thus loaded into 0x9000, which is where
-// it also runs from. The boot2.bin binary starts right after the end of
-// BTX, so we have to figure out where the start of it is and then move the
-// binary to 0xc000. Normally, BTX clients start at MEM_USR, or 0xa000, but
-// when we use btxld to create boot2, we use an entry point of 0x2000. That
-// entry point is relative to MEM_USR; thus boot2.bin starts at 0xc000.
-//
-main.5: mov %dx,MEM_ARG // Save args
- movb $NSECT,%dh // Sector count
- callw nread // Read disk
- mov $MEM_BTX,%bx // BTX
- mov 0xa(%bx),%si // Get BTX length and set
- add %bx,%si // %si to start of boot2.bin
- mov $MEM_USR+SIZ_PAG*2,%di // Client page 2
- mov $MEM_BTX+(NSECT-1)*SIZ_SEC,%cx // Byte
- sub %si,%cx // count
- rep // Relocate
- movsb // client
- sub %di,%cx // Byte count
- xorb %al,%al // Zero assumed bss from
- rep // the end of boot2.bin
- stosb // up to 0x10000
- callw seta20 // Enable A20
- jmp start+MEM_JMP-MEM_ORG // Start BTX
-//
-// Enable A20 so we can access memory above 1 meg.
-//
-seta20: cli // Disable interrupts
-seta20.1: inb $0x64,%al // Get status
- testb $0x2,%al // Busy?
- jnz seta20.1 // Yes
- movb $0xd1,%al // Command: Write
- outb %al,$0x64 // output port
-seta20.2: inb $0x64,%al // Get status
- testb $0x2,%al // Busy?
- jnz seta20.2 // Yes
- movb $0xdf,%al // Enable
- outb %al,$0x60 // A20
- sti // Enable interrupts
- retw // To caller
-//
-// Trampoline used to call read from within boot1.
-//
-nread: mov $MEM_BUF,%bx // Transfer buffer
- mov 0x8(%si),%ax // Get
- mov 0xa(%si),%cx // LBA
- push %cs // Read from
- callw xread.1 // disk
- jnc return // If success, return
- mov $msg_read,%si // Otherwise, set the error
- // message and fall through to
- // the error routine
-//
-// Print out the error message pointed to by %ds:(%si) followed
-// by a prompt, wait for a keypress, and then reboot the machine.
-//
-error: callw putstr // Display message
- mov $prompt,%si // Display
- callw putstr // prompt
- xorb %ah,%ah // BIOS: Get
- int $0x16 // keypress
- movw $0x1234, BDA_BOOT // Do a warm boot
- ljmp $0xffff,$0x0 // reboot the machine
-//
-// Display a null-terminated string using the BIOS output.
-//
-putstr.0: mov $0x7,%bx // Page:attribute
- movb $0xe,%ah // BIOS: Display
- int $0x10 // character
-putstr: lodsb // Get char
- testb %al,%al // End of string?
- jne putstr.0 // No
-
-//
-// Overused return code. ereturn is used to return an error from the
-// read function. Since we assume putstr succeeds, we (ab)use the
-// same code when we return from putstr.
-//
-ereturn: movb $0x1,%ah // Invalid
- stc // argument
-return: retw // To caller
-//
-// Reads sectors from the disk. If EDD is enabled, then check if it is
-// installed and use it if it is. If it is not installed or not enabled, then
-// fall back to using CHS. Since we use a LBA, if we are using CHS, we have to
-// fetch the drive parameters from the BIOS and divide it out ourselves.
-// Call with:
-//
-// %dl - byte - drive number
-// stack - 10 bytes - EDD Packet
-//
-read: push %dx // Save
- movb $0x8,%ah // BIOS: Get drive
- int $0x13 // parameters
- movb %dh,%ch // Max head number
- pop %dx // Restore
- jc return // If error
- andb $0x3f,%cl // Sectors per track
- jz ereturn // If zero
- cli // Disable interrupts
- mov 0x8(%bp),%eax // Get LBA
- push %dx // Save
- movzbl %cl,%ebx // Divide by
- xor %edx,%edx // sectors
- div %ebx // per track
- movb %ch,%bl // Max head number
- movb %dl,%ch // Sector number
- inc %bx // Divide by
- xorb %dl,%dl // number
- div %ebx // of heads
- movb %dl,%bh // Head number
- pop %dx // Restore
- cmpl $0x3ff,%eax // Cylinder number supportable?
- sti // Enable interrupts
- ja read.7 // No, try EDD
- xchgb %al,%ah // Set up cylinder
- rorb $0x2,%al // number
- orb %ch,%al // Merge
- inc %ax // sector
- xchg %ax,%cx // number
- movb %bh,%dh // Head number
- subb %ah,%al // Sectors this track
- mov 0x2(%bp),%ah // Blocks to read
- cmpb %ah,%al // To read
- jb read.2 // this
- movb %ah,%al // track
-read.2: mov $0x5,%di // Try count
-read.3: les 0x4(%bp),%bx // Transfer buffer
- push %ax // Save
- movb $0x2,%ah // BIOS: Read
- int $0x13 // from disk
- pop %bx // Restore
- jnc read.4 // If success
- dec %di // Retry?
- jz read.6 // No
- xorb %ah,%ah // BIOS: Reset
- int $0x13 // disk system
- xchg %bx,%ax // Block count
- jmp read.3 // Continue
-read.4: movzbw %bl,%ax // Sectors read
- add %ax,0x8(%bp) // Adjust
- jnc read.5 // LBA,
- incw 0xa(%bp) // transfer
-read.5: shlb %bl // buffer
- add %bl,0x5(%bp) // pointer,
- sub %al,0x2(%bp) // block count
- ja read // If not done
-read.6: retw // To caller
-read.7: testb $FL_PACKET,%cs:MEM_REL+flags-start // LBA support enabled?
- jz ereturn // No, so return an error
- mov $0x55aa,%bx // Magic
- push %dx // Save
- movb $0x41,%ah // BIOS: Check
- int $0x13 // extensions present
- pop %dx // Restore
- jc return // If error, return an error
- cmp $0xaa55,%bx // Magic?
- jne ereturn // No, so return an error
- testb $0x1,%cl // Packet interface?
- jz ereturn // No, so return an error
- mov %bp,%si // Disk packet
- movb $0x42,%ah // BIOS: Extended
- int $0x13 // read
- retw // To caller
-
-// Messages
-
-msg_read: .asciz "Read"
-msg_part: .asciz "Boot"
-
-prompt: .asciz " error\r\n"
-
-flags: .byte FLAGS // Flags
-
- .org PRT_OFF,0x90
-
-// Partition table
-
- .fill 0x30,0x1,0x0
-part4: .byte 0x80, 0x00, 0x01, 0x00
- .byte 0xa5, 0xfe, 0xff, 0xff
- .byte 0x00, 0x00, 0x00, 0x00
- .byte 0x50, 0xc3, 0x00, 0x00 // 50000 sectors long, bleh
-
- .word 0xaa55 // Magic number
diff --git a/sys/boot/i386/boot2/sio.S b/sys/boot/i386/boot2/sio.S
deleted file mode 100644
index e29820586a3b..000000000000
--- a/sys/boot/i386/boot2/sio.S
+++ /dev/null
@@ -1,80 +0,0 @@
-#
-# Copyright (c) 1998 Robert Nordier
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms are freely
-# permitted provided that the above copyright notice and this
-# paragraph and the following disclaimer are duplicated in all
-# such forms.
-#
-# This software is provided "AS IS" and without any express or
-# implied warranties, including, without limitation, the implied
-# warranties of merchantability and fitness for a particular
-# purpose.
-#
-
-# $FreeBSD$
-
- .set SIO_PRT,SIOPRT # Base port
- .set SIO_FMT,SIOFMT # 8N1
- .set SIO_DIV,(115200/SIOSPD) # 115200 / SPD
-
- .globl sio_init
- .globl sio_flush
- .globl sio_putc
- .globl sio_getc
- .globl sio_ischar
-
-# void sio_init(void)
-
-sio_init: movw $SIO_PRT+0x3,%dx # Data format reg
- movb $SIO_FMT|0x80,%al # Set format
- outb %al,(%dx) # and DLAB
- pushl %edx # Save
- subb $0x3,%dl # Divisor latch reg
- movw $SIO_DIV,%ax # Set
- outw %ax,(%dx) # BPS
- popl %edx # Restore
- movb $SIO_FMT,%al # Clear
- outb %al,(%dx) # DLAB
- incl %edx # Modem control reg
- movb $0x3,%al # Set RTS,
- outb %al,(%dx) # DTR
- incl %edx # Line status reg
-
-# void sio_flush(void)
-
-sio_flush.0: call sio_getc.1 # Get character
-sio_flush: call sio_ischar # Check for character
- jnz sio_flush.0 # Till none
- ret # To caller
-
-# void sio_putc(int c)
-
-sio_putc: movw $SIO_PRT+0x5,%dx # Line status reg
- xor %ecx,%ecx # Timeout
- movb $0x40,%ch # counter
-sio_putc.1: inb (%dx),%al # Transmitter
- testb $0x20,%al # buffer empty?
- loopz sio_putc.1 # No
- jz sio_putc.2 # If timeout
- movb 0x4(%esp,1),%al # Get character
- subb $0x5,%dl # Transmitter hold reg
- outb %al,(%dx) # Write character
-sio_putc.2: ret $0x4 # To caller
-
-# int sio_getc(void)
-
-sio_getc: call sio_ischar # Character available?
- jz sio_getc # No
-sio_getc.1: subb $0x5,%dl # Receiver buffer reg
- inb (%dx),%al # Read character
- ret # To caller
-
-# int sio_ischar(void)
-
-sio_ischar: movw $SIO_PRT+0x5,%dx # Line status register
- xorl %eax,%eax # Zero
- inb (%dx),%al # Received data
- andb $0x1,%al # ready?
- ret # To caller
diff --git a/sys/boot/i386/btx/btx/btx.S b/sys/boot/i386/btx/btx/btx.S
deleted file mode 100644
index e5c8ec494e3b..000000000000
--- a/sys/boot/i386/btx/btx/btx.S
+++ /dev/null
@@ -1,1173 +0,0 @@
-#
-# Copyright (c) 1998 Robert Nordier
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms are freely
-# permitted provided that the above copyright notice and this
-# paragraph and the following disclaimer are duplicated in all
-# such forms.
-#
-# This software is provided "AS IS" and without any express or
-# implied warranties, including, without limitation, the implied
-# warranties of merchantability and fitness for a particular
-# purpose.
-#
-
-# $FreeBSD$
-
-#
-# Memory layout.
-#
- .set MEM_BTX,0x1000 # Start of BTX memory
- .set MEM_ESP0,0x1800 # Supervisor stack
- .set MEM_BUF,0x1800 # Scratch buffer
- .set MEM_ESP1,0x1e00 # Link stack
- .set MEM_IDT,0x1e00 # IDT
- .set MEM_TSS,0x1f98 # TSS
- .set MEM_MAP,0x2000 # I/O bit map
- .set MEM_DIR,0x4000 # Page directory
- .set MEM_TBL,0x5000 # Page tables
- .set MEM_ORG,0x9000 # BTX code
- .set MEM_USR,0xa000 # Start of user memory
-#
-# Paging control.
-#
- .set PAG_SIZ,0x1000 # Page size
- .set PAG_CNT,0x1000 # Pages to map
-#
-# Segment selectors.
-#
- .set SEL_SCODE,0x8 # Supervisor code
- .set SEL_SDATA,0x10 # Supervisor data
- .set SEL_RCODE,0x18 # Real mode code
- .set SEL_RDATA,0x20 # Real mode data
- .set SEL_UCODE,0x28|3 # User code
- .set SEL_UDATA,0x30|3 # User data
- .set SEL_TSS,0x38 # TSS
-#
-# Task state segment fields.
-#
- .set TSS_ESP0,0x4 # PL 0 ESP
- .set TSS_SS0,0x8 # PL 0 SS
- .set TSS_ESP1,0xc # PL 1 ESP
- .set TSS_MAP,0x66 # I/O bit map base
-#
-# System calls.
-#
- .set SYS_EXIT,0x0 # Exit
- .set SYS_EXEC,0x1 # Exec
-#
-# V86 constants.
-#
- .set V86_FLG,0x208eff # V86 flag mask
- .set V86_STK,0x400 # V86 stack allowance
-#
-# Dump format control bytes.
-#
- .set DMP_X16,0x1 # Word
- .set DMP_X32,0x2 # Long
- .set DMP_MEM,0x4 # Memory
- .set DMP_EOL,0x8 # End of line
-#
-# Screen defaults and assumptions.
-#
- .set SCR_MAT,0x7 # Mode/attribute
- .set SCR_COL,0x50 # Columns per row
- .set SCR_ROW,0x19 # Rows per screen
-#
-# BIOS Data Area locations.
-#
- .set BDA_MEM,0x413 # Free memory
- .set BDA_KEYFLAGS,0x417 # Keyboard shift-state flags
- .set BDA_SCR,0x449 # Video mode
- .set BDA_POS,0x450 # Cursor position
- .set BDA_BOOT,0x472 # Boot howto flag
-#
-# Derivations, for brevity.
-#
- .set _ESP0H,MEM_ESP0>>0x8 # Byte 1 of ESP0
- .set _ESP1H,MEM_ESP1>>0x8 # Byte 1 of ESP1
- .set _TSSIO,MEM_MAP-MEM_TSS # TSS I/O base
- .set _TSSLM,MEM_DIR-MEM_TSS-1 # TSS limit
- .set _IDTLM,MEM_TSS-MEM_IDT-1 # IDT limit
-#
-# Code segment.
-#
- .globl start
- .code16
-start: # Start of code
-#
-# BTX header.
-#
-btx_hdr: .byte 0xeb # Machine ID
- .byte 0xe # Header size
- .ascii "BTX" # Magic
- .byte 0x1 # Major version
- .byte 0x1 # Minor version
- .byte BTX_FLAGS # Flags
- .word PAG_CNT-MEM_ORG>>0xc # Paging control
- .word break-start # Text size
- .long 0x0 # Entry address
-#
-# Initialization routine.
-#
-init: cli # Disable interrupts
- xor %ax,%ax # Zero/segment
- mov %ax,%ss # Set up
- mov $MEM_ESP0,%sp # stack
- mov %ax,%es # Address
- mov %ax,%ds # data
- pushl $0x2 # Clear
- popfl # flags
-#
-# Initialize memory.
-#
- mov $MEM_IDT,%di # Memory to initialize
- mov $(MEM_ORG-MEM_IDT)/2,%cx # Words to zero
- push %di # Save
- rep # Zero-fill
- stosw # memory
- pop %di # Restore
-#
-# Create IDT.
-#
- mov $idtctl,%si # Control string
-init.1: lodsb # Get entry
- cbw # count
- xchg %ax,%cx # as word
- jcxz init.4 # If done
- lodsb # Get segment
- xchg %ax,%dx # P:DPL:type
- lodsw # Get control
- xchg %ax,%bx # set
- lodsw # Get handler offset
- mov $SEL_SCODE,%dh # Segment selector
-init.2: shr %bx # Handle this int?
- jnc init.3 # No
- mov %ax,(%di) # Set handler offset
- mov %dh,0x2(%di) # and selector
- mov %dl,0x5(%di) # Set P:DPL:type
- add $0x4,%ax # Next handler
-init.3: lea 0x8(%di),%di # Next entry
- loop init.2 # Till set done
- jmp init.1 # Continue
-#
-# Initialize TSS.
-#
-init.4: movb $_ESP0H,TSS_ESP0+1(%di) # Set ESP0
- movb $SEL_SDATA,TSS_SS0(%di) # Set SS0
- movb $_ESP1H,TSS_ESP1+1(%di) # Set ESP1
- movb $_TSSIO,TSS_MAP(%di) # Set I/O bit map base
-ifdef(`PAGING',`
-#
-# Create page directory.
-#
- xor %edx,%edx # Page
- mov $PAG_SIZ>>0x8,%dh # size
- xor %eax,%eax # Zero
- mov $MEM_DIR,%di # Page directory
- mov $PAG_CNT>>0xa,%cl # Entries
- mov $MEM_TBL|0x7,%ax # First entry
-init.5: stosl # Write entry
- add %dx,%ax # To next
- loop init.5 # Till done
-#
-# Create page tables.
-#
- mov $MEM_TBL,%di # Page table
- mov $PAG_CNT>>0x8,%ch # Entries
- xor %ax,%ax # Start address
-init.6: mov $0x7,%al # Set U:W:P flags
- cmp btx_hdr+0x8,%cx # Standard user page?
- jb init.7 # Yes
- cmp $PAG_CNT-MEM_BTX>>0xc,%cx # BTX memory?
- jae init.7 # No or first page
- and $~0x2,%al # Clear W flag
- cmp $PAG_CNT-MEM_USR>>0xc,%cx # User page zero?
- jne init.7 # No
- testb $0x80,btx_hdr+0x7 # Unmap it?
- jz init.7 # No
- and $~0x1,%al # Clear P flag
-init.7: stosl # Set entry
- add %edx,%eax # Next address
- loop init.6 # Till done
-')
-#
-# Bring up the system.
-#
- mov $0x2820,%bx # Set protected mode
- callw setpic # IRQ offsets
- lidt idtdesc # Set IDT
-ifdef(`PAGING',`
- xor %eax,%eax # Set base
- mov $MEM_DIR>>0x8,%ah # of page
- mov %eax,%cr3 # directory
-')
- lgdt gdtdesc # Set GDT
- mov %cr0,%eax # Switch to protected
-ifdef(`PAGING',`
- or $0x80000001,%eax # mode and enable paging
-',`
- or $0x01,%eax # mode
-')
- mov %eax,%cr0 #
- ljmp $SEL_SCODE,$init.8 # To 32-bit code
- .code32
-init.8: xorl %ecx,%ecx # Zero
- movb $SEL_SDATA,%cl # To 32-bit
- movw %cx,%ss # stack
-#
-# Launch user task.
-#
- movb $SEL_TSS,%cl # Set task
- ltr %cx # register
- movl $MEM_USR,%edx # User base address
- movzwl %ss:BDA_MEM,%eax # Get free memory
- shll $0xa,%eax # To bytes
- subl $0x1000,%eax # Less arg space
- subl %edx,%eax # Less base
- movb $SEL_UDATA,%cl # User data selector
- pushl %ecx # Set SS
- pushl %eax # Set ESP
- push $0x202 # Set flags (IF set)
- push $SEL_UCODE # Set CS
- pushl btx_hdr+0xc # Set EIP
- pushl %ecx # Set GS
- pushl %ecx # Set FS
- pushl %ecx # Set DS
- pushl %ecx # Set ES
- pushl %edx # Set EAX
- movb $0x7,%cl # Set remaining
-init.9: push $0x0 # general
- loop init.9 # registers
-ifdef(`BTX_SERIAL',`
- call sio_init # setup the serial console
-')
- popa # and initialize
- popl %es # Initialize
- popl %ds # user
- popl %fs # segment
- popl %gs # registers
- iret # To user mode
-#
-# Exit routine.
-#
-exit: cli # Disable interrupts
- movl $MEM_ESP0,%esp # Clear stack
-#
-# Turn off paging.
-#
- movl %cr0,%eax # Get CR0
- andl $~0x80000000,%eax # Disable
- movl %eax,%cr0 # paging
- xorl %ecx,%ecx # Zero
- movl %ecx,%cr3 # Flush TLB
-#
-# Restore the GDT in case we caught a kernel trap.
-#
- lgdt gdtdesc # Set GDT
-#
-# To 16 bits.
-#
- ljmpw $SEL_RCODE,$exit.1 # Reload CS
- .code16
-exit.1: mov $SEL_RDATA,%cl # 16-bit selector
- mov %cx,%ss # Reload SS
- mov %cx,%ds # Load
- mov %cx,%es # remaining
- mov %cx,%fs # segment
- mov %cx,%gs # registers
-#
-# To real-address mode.
-#
- dec %ax # Switch to
- mov %eax,%cr0 # real mode
- ljmp $0x0,$exit.2 # Reload CS
-exit.2: xor %ax,%ax # Real mode segment
- mov %ax,%ss # Reload SS
- mov %ax,%ds # Address data
- mov $0x7008,%bx # Set real mode
- callw setpic # IRQ offsets
- lidt ivtdesc # Set IVT
-#
-# Reboot or await reset.
-#
- sti # Enable interrupts
- testb $0x1,btx_hdr+0x7 # Reboot?
-exit.3: jz exit.3 # No
- movw $0x1234, BDA_BOOT # Do a warm boot
- ljmp $0xffff,$0x0 # reboot the machine
-#
-# Set IRQ offsets by reprogramming 8259A PICs.
-#
-setpic: in $0x21,%al # Save master
- push %ax # IMR
- in $0xa1,%al # Save slave
- push %ax # IMR
- movb $0x11,%al # ICW1 to
- outb %al,$0x20 # master,
- outb %al,$0xa0 # slave
- movb %bl,%al # ICW2 to
- outb %al,$0x21 # master
- movb %bh,%al # ICW2 to
- outb %al,$0xa1 # slave
- movb $0x4,%al # ICW3 to
- outb %al,$0x21 # master
- movb $0x2,%al # ICW3 to
- outb %al,$0xa1 # slave
- movb $0x1,%al # ICW4 to
- outb %al,$0x21 # master,
- outb %al,$0xa1 # slave
- pop %ax # Restore slave
- outb %al,$0xa1 # IMR
- pop %ax # Restore master
- outb %al,$0x21 # IMR
- retw # To caller
- .code32
-#
-# Initiate return from V86 mode to user mode.
-#
-inthlt: hlt # To supervisor mode
-#
-# Exception jump table.
-#
-intx00: push $0x0 # Int 0x0: #DE
- jmp ex_noc # Divide error
- push $0x1 # Int 0x1: #DB
- jmp ex_noc # Debug
- push $0x3 # Int 0x3: #BP
- jmp ex_noc # Breakpoint
- push $0x4 # Int 0x4: #OF
- jmp ex_noc # Overflow
- push $0x5 # Int 0x5: #BR
- jmp ex_noc # BOUND range exceeded
- push $0x6 # Int 0x6: #UD
- jmp ex_noc # Invalid opcode
- push $0x7 # Int 0x7: #NM
- jmp ex_noc # Device not available
- push $0x8 # Int 0x8: #DF
- jmp except # Double fault
- push $0xa # Int 0xa: #TS
- jmp except # Invalid TSS
- push $0xb # Int 0xb: #NP
- jmp except # Segment not present
- push $0xc # Int 0xc: #SS
- jmp except # Stack segment fault
- push $0xd # Int 0xd: #GP
- jmp ex_v86 # General protection
- push $0xe # Int 0xe: #PF
- jmp except # Page fault
-intx10: push $0x10 # Int 0x10: #MF
- jmp ex_noc # Floating-point error
-#
-# Handle #GP exception.
-#
-ex_v86: testb $0x2,0x12(%esp,1) # V86 mode?
- jz except # No
- jmp v86mon # To monitor
-#
-# Save a zero error code.
-#
-ex_noc: pushl (%esp,1) # Duplicate int no
- movb $0x0,0x4(%esp,1) # Fake error code
-#
-# Handle exception.
-#
-except: cld # String ops inc
- pushl %ds # Save
- pushl %es # most
- pusha # registers
- movb $0x6,%al # Push loop count
- testb $0x2,0x3a(%esp,1) # V86 mode?
- jnz except.1 # Yes
- pushl %gs # Set GS
- pushl %fs # Set FS
- pushl %ds # Set DS
- pushl %es # Set ES
- movb $0x2,%al # Push loop count
- cmpw $SEL_SCODE,0x44(%esp,1) # Supervisor mode?
- jne except.1 # No
- pushl %ss # Set SS
- leal 0x50(%esp,1),%eax # Set
- pushl %eax # ESP
- jmp except.2 # Join common code
-except.1: pushl 0x50(%esp,1) # Set GS, FS, DS, ES
- decb %al # (if V86 mode), and
- jne except.1 # SS, ESP
-except.2: push $SEL_SDATA # Set up
- popl %ds # to
- pushl %ds # address
- popl %es # data
- movl %esp,%ebx # Stack frame
- movl $dmpfmt,%esi # Dump format string
- movl $MEM_BUF,%edi # Buffer
- pushl %edi # Dump to
- call dump # buffer
- popl %esi # and
- call putstr # display
- leal 0x18(%esp,1),%esp # Discard frame
- popa # Restore
- popl %es # registers
- popl %ds # saved
- cmpb $0x3,(%esp,1) # Breakpoint?
- je except.3 # Yes
- cmpb $0x1,(%esp,1) # Debug?
- jne except.2a # No
- testl $0x100,0x10(%esp,1) # Trap flag set?
- jnz except.3 # Yes
-except.2a: jmp exit # Exit
-except.3: leal 0x8(%esp,1),%esp # Discard err, int no
- iret # From interrupt
-#
-# Return to user mode from V86 mode.
-#
-intrtn: cld # String ops inc
- pushl %ds # Address
- popl %es # data
- leal 0x3c(%ebp),%edx # V86 Segment registers
- movl MEM_TSS+TSS_ESP1,%esi # Link stack pointer
- lodsl # INT_V86 args pointer
- movl %esi,%ebx # Saved exception frame
- testl %eax,%eax # INT_V86 args?
- jz intrtn.2 # No
- movl $MEM_USR,%edi # User base
- movl 0x1c(%esi),%ebx # User ESP
- movl %eax,(%edi,%ebx,1) # Restore to user stack
- leal 0x8(%edi,%eax,1),%edi # Arg segment registers
- testb $0x4,-0x6(%edi) # Return flags?
- jz intrtn.1 # No
- movl 0x30(%ebp),%eax # Get V86 flags
- movw %ax,0x18(%esi) # Set user flags
-intrtn.1: leal 0x10(%esi),%ebx # Saved exception frame
- xchgl %edx,%esi # Segment registers
- movb $0x4,%cl # Update seg regs
- rep # in INT_V86
- movsl # args
-intrtn.2: movl %edx,%esi # Segment registers
- leal 0x28(%ebp),%edi # Set up seg
- movb $0x4,%cl # regs for
- rep # later
- movsl # pop
- movl %ebx,%esi # Restore exception
- movb $0x5,%cl # frame to
- rep # supervisor
- movsl # stack
- movl %esi,MEM_TSS+TSS_ESP1 # Link stack pointer
- popa # Restore
- leal 0x8(%esp,1),%esp # Discard err, int no
- popl %es # Restore
- popl %ds # user
- popl %fs # segment
- popl %gs # registers
- iret # To user mode
-#
-# V86 monitor.
-#
-v86mon: cld # String ops inc
- pushl $SEL_SDATA # Set up for
- popl %ds # flat addressing
- pusha # Save registers
- movl %esp,%ebp # Address stack frame
- movzwl 0x2c(%ebp),%edi # Load V86 CS
- shll $0x4,%edi # To linear
- movl 0x28(%ebp),%esi # Load V86 IP
- addl %edi,%esi # Code pointer
- xorl %ecx,%ecx # Zero
- movb $0x2,%cl # 16-bit operands
- xorl %eax,%eax # Zero
-v86mon.1: lodsb # Get opcode
- cmpb $0x66,%al # Operand size prefix?
- jne v86mon.2 # No
- movb $0x4,%cl # 32-bit operands
- jmp v86mon.1 # Continue
-v86mon.2: cmpb $0xf4,%al # HLT?
- jne v86mon.3 # No
- cmpl $inthlt+0x1,%esi # Is inthlt?
- jne v86mon.7 # No (ignore)
- jmp intrtn # Return to user mode
-v86mon.3: cmpb $0xf,%al # Prefixed instruction?
- jne v86mon.4 # No
- cmpb $0x09,(%esi) # Is it a WBINVD?
- je v86wbinvd # Yes
- cmpb $0x30,(%esi) # Is it a WRMSR?
- je v86wrmsr # Yes
- cmpb $0x32,(%esi) # Is it a RDMSR?
- je v86rdmsr # Yes
- cmpb $0x20,(%esi) # Is this a
- jne v86mon.4 # MOV EAX,CR0
- cmpb $0xc0,0x1(%esi) # instruction?
- je v86mov # Yes
-v86mon.4: cmpb $0xfa,%al # CLI?
- je v86cli # Yes
- cmpb $0xfb,%al # STI?
- je v86sti # Yes
- movzwl 0x38(%ebp),%ebx # Load V86 SS
- shll $0x4,%ebx # To offset
- pushl %ebx # Save
- addl 0x34(%ebp),%ebx # Add V86 SP
- movl 0x30(%ebp),%edx # Load V86 flags
- cmpb $0x9c,%al # PUSHF/PUSHFD?
- je v86pushf # Yes
- cmpb $0x9d,%al # POPF/POPFD?
- je v86popf # Yes
- cmpb $0xcd,%al # INT imm8?
- je v86intn # Yes
- cmpb $0xcf,%al # IRET/IRETD?
- je v86iret # Yes
- popl %ebx # Restore
- popa # Restore
- jmp except # Handle exception
-v86mon.5: movl %edx,0x30(%ebp) # Save V86 flags
-v86mon.6: popl %edx # V86 SS adjustment
- subl %edx,%ebx # Save V86
- movl %ebx,0x34(%ebp) # SP
-v86mon.7: subl %edi,%esi # From linear
- movl %esi,0x28(%ebp) # Save V86 IP
- popa # Restore
- leal 0x8(%esp,1),%esp # Discard int no, error
- iret # To V86 mode
-#
-# Emulate MOV EAX,CR0.
-#
-v86mov: movl %cr0,%eax # CR0 to
- movl %eax,0x1c(%ebp) # saved EAX
- incl %esi # Adjust IP
-#
-# Return from emulating a 0x0f prefixed instruction
-#
-v86preret: incl %esi # Adjust IP
- jmp v86mon.7 # Finish up
-#
-# Emulate WBINVD
-#
-v86wbinvd: wbinvd # Write back and invalidate
- # cache
- jmp v86preret # Finish up
-#
-# Emulate WRMSR
-#
-v86wrmsr: movl 0x18(%ebp),%ecx # Get user's %ecx (MSR to write)
- movl 0x14(%ebp),%edx # Load the value
- movl 0x1c(%ebp),%eax # to write
- wrmsr # Write MSR
- jmp v86preret # Finish up
-#
-# Emulate RDMSR
-#
-v86rdmsr: movl 0x18(%ebp),%ecx # MSR to read
- rdmsr # Read the MSR
- movl %eax,0x1c(%ebp) # Return the value of
- movl %edx,0x14(%ebp) # the MSR to the user
- jmp v86preret # Finish up
-#
-# Emulate CLI.
-#
-v86cli: andb $~0x2,0x31(%ebp) # Clear IF
- jmp v86mon.7 # Finish up
-#
-# Emulate STI.
-#
-v86sti: orb $0x2,0x31(%ebp) # Set IF
- jmp v86mon.7 # Finish up
-#
-# Emulate PUSHF/PUSHFD.
-#
-v86pushf: subl %ecx,%ebx # Adjust SP
- cmpb $0x4,%cl # 32-bit
- je v86pushf.1 # Yes
- data16 # 16-bit
-v86pushf.1: movl %edx,(%ebx) # Save flags
- jmp v86mon.6 # Finish up
-#
-# Emulate IRET/IRETD.
-#
-v86iret: movzwl (%ebx),%esi # Load V86 IP
- movzwl 0x2(%ebx),%edi # Load V86 CS
- leal 0x4(%ebx),%ebx # Adjust SP
- movl %edi,0x2c(%ebp) # Save V86 CS
- xorl %edi,%edi # No ESI adjustment
-#
-# Emulate POPF/POPFD (and remainder of IRET/IRETD).
-#
-v86popf: cmpb $0x4,%cl # 32-bit?
- je v86popf.1 # Yes
- movl %edx,%eax # Initialize
- data16 # 16-bit
-v86popf.1: movl (%ebx),%eax # Load flags
- addl %ecx,%ebx # Adjust SP
- andl $V86_FLG,%eax # Merge
- andl $~V86_FLG,%edx # the
- orl %eax,%edx # flags
- jmp v86mon.5 # Finish up
-#
-# trap int 15, function 87
-# reads %es:%si from saved registers on stack to find a GDT containing
-# source and destination locations
-# reads count of words from saved %cx
-# returns success by setting %ah to 0
-#
-int15_87: pushl %eax # Save
- pushl %ebx # some information
- pushl %esi # onto the stack.
- pushl %edi
- xorl %eax,%eax # clean EAX
- xorl %ebx,%ebx # clean EBX
- movl 0x4(%ebp),%esi # Get user's ESI
- movl 0x3C(%ebp),%ebx # store ES
- movw %si,%ax # store SI
- shll $0x4,%ebx # Make it a seg.
- addl %eax,%ebx # ebx=(es<<4)+si
- movb 0x14(%ebx),%al # Grab the
- movb 0x17(%ebx),%ah # necessary
- shll $0x10,%eax # information
- movw 0x12(%ebx),%ax # from
- movl %eax,%esi # the
- movb 0x1c(%ebx),%al # GDT in order to
- movb 0x1f(%ebx),%ah # have %esi offset
- shll $0x10,%eax # of source and %edi
- movw 0x1a(%ebx),%ax # of destination.
- movl %eax,%edi
- pushl %ds # Make:
- popl %es # es = ds
- pushl %ecx # stash ECX
- xorl %ecx,%ecx # highw of ECX is clear
- movw 0x18(%ebp),%cx # Get user's ECX
- shll $0x1,%ecx # Convert from num words to num
- # bytes
- rep # repeat...
- movsb # perform copy.
- popl %ecx # Restore
- popl %edi
- popl %esi # previous
- popl %ebx # register
- popl %eax # values.
- movb $0x0,0x1d(%ebp) # set ah = 0 to indicate
- # success
- andb $0xfe,%dl # clear CF
- jmp v86mon.5 # Finish up
-
-#
-# Reboot the machine by setting the reboot flag and exiting
-#
-reboot: orb $0x1,btx_hdr+0x7 # Set the reboot flag
- jmp exit # Terminate BTX and reboot
-
-#
-# Emulate INT imm8... also make sure to check if it's int 15/87
-#
-v86intn: lodsb # Get int no
- cmpb $0x19,%al # is it int 19?
- je reboot # yes, reboot the machine
- cmpb $0x15,%al # is it int 15?
- jne v86intn.3 # no, skip parse
- pushl %eax # stash EAX
- movl 0x1c(%ebp),%eax # user's saved EAX
- cmpb $0x87,%ah # is it the memcpy subfunction?
- jne v86intn.1 # no, keep checking
- popl %eax # get the stack straight
- jmp int15_87 # it's our cue
-v86intn.1: cmpw $0x4f53,%ax # is it the delete key callout?
- jne v86intn.2 # no, handle the int normally
- movb BDA_KEYFLAGS,%al # get the shift key state
- andb $0xc,%al # mask off just Ctrl and Alt
- cmpb $0xc,%al # are both Ctrl and Alt down?
- jne v86intn.2 # no, handle the int normally
- popl %eax # restore EAX
- jmp reboot # reboot the machine
-v86intn.2: popl %eax # restore EAX
-v86intn.3: subl %edi,%esi # From
- shrl $0x4,%edi # linear
- movw %dx,-0x2(%ebx) # Save flags
- movw %di,-0x4(%ebx) # Save CS
- leal -0x6(%ebx),%ebx # Adjust SP
- movw %si,(%ebx) # Save IP
- shll $0x2,%eax # Scale
- movzwl (%eax),%esi # Load IP
- movzwl 0x2(%eax),%edi # Load CS
- movl %edi,0x2c(%ebp) # Save CS
- xorl %edi,%edi # No ESI adjustment
- andb $~0x1,%dh # Clear TF
- jmp v86mon.5 # Finish up
-#
-# Hardware interrupt jump table.
-#
-intx20: push $0x8 # Int 0x20: IRQ0
- jmp int_hw # V86 int 0x8
- push $0x9 # Int 0x21: IRQ1
- jmp int_hw # V86 int 0x9
- push $0xa # Int 0x22: IRQ2
- jmp int_hw # V86 int 0xa
- push $0xb # Int 0x23: IRQ3
- jmp int_hw # V86 int 0xb
- push $0xc # Int 0x24: IRQ4
- jmp int_hw # V86 int 0xc
- push $0xd # Int 0x25: IRQ5
- jmp int_hw # V86 int 0xd
- push $0xe # Int 0x26: IRQ6
- jmp int_hw # V86 int 0xe
- push $0xf # Int 0x27: IRQ7
- jmp int_hw # V86 int 0xf
- push $0x70 # Int 0x28: IRQ8
- jmp int_hw # V86 int 0x70
- push $0x71 # Int 0x29: IRQ9
- jmp int_hw # V86 int 0x71
- push $0x72 # Int 0x2a: IRQ10
- jmp int_hw # V86 int 0x72
- push $0x73 # Int 0x2b: IRQ11
- jmp int_hw # V86 int 0x73
- push $0x74 # Int 0x2c: IRQ12
- jmp int_hw # V86 int 0x74
- push $0x75 # Int 0x2d: IRQ13
- jmp int_hw # V86 int 0x75
- push $0x76 # Int 0x2e: IRQ14
- jmp int_hw # V86 int 0x76
- push $0x77 # Int 0x2f: IRQ15
- jmp int_hw # V86 int 0x77
-#
-# Reflect hardware interrupts.
-#
-int_hw: testb $0x2,0xe(%esp,1) # V86 mode?
- jz intusr # No
- pushl $SEL_SDATA # Address
- popl %ds # data
- xchgl %eax,(%esp,1) # Swap EAX, int no
- pushl %ebp # Address
- movl %esp,%ebp # stack frame
- pushl %ebx # Save
- shll $0x2,%eax # Get int
- movl (%eax),%eax # vector
- subl $0x6,0x14(%ebp) # Adjust V86 ESP
- movzwl 0x18(%ebp),%ebx # V86 SS
- shll $0x4,%ebx # * 0x10
- addl 0x14(%ebp),%ebx # + V86 ESP
- xchgw %ax,0x8(%ebp) # Swap V86 IP
- rorl $0x10,%eax # Swap words
- xchgw %ax,0xc(%ebp) # Swap V86 CS
- roll $0x10,%eax # Swap words
- movl %eax,(%ebx) # CS:IP for IRET
- movl 0x10(%ebp),%eax # V86 flags
- movw %ax,0x4(%ebx) # Flags for IRET
- andb $~0x3,0x11(%ebp) # Clear IF, TF
- popl %ebx # Restore
- popl %ebp # saved
- popl %eax # registers
- iret # To V86 mode
-#
-# Invoke V86 interrupt from user mode, with arguments.
-#
-intx31: stc # Have btx_v86
- pushl %eax # Missing int no
-#
-# Invoke V86 interrupt from user mode.
-#
-intusr: std # String ops dec
- pushl %eax # Expand
- pushl %eax # stack
- pushl %eax # frame
- pusha # Save
- pushl %gs # Save
- movl %esp,%eax # seg regs
- pushl %fs # and
- pushl %ds # point
- pushl %es # to them
- push $SEL_SDATA # Set up
- popl %ds # to
- pushl %ds # address
- popl %es # data
- movl $MEM_USR,%ebx # User base
- movl %ebx,%edx # address
- jc intusr.1 # If btx_v86
- xorl %edx,%edx # Control flags
- xorl %ebp,%ebp # btx_v86 pointer
-intusr.1: leal 0x50(%esp,1),%esi # Base of frame
- pushl %esi # Save
- addl -0x4(%esi),%ebx # User ESP
- movl MEM_TSS+TSS_ESP1,%edi # Link stack pointer
- leal -0x4(%edi),%edi # Adjust for push
- xorl %ecx,%ecx # Zero
- movb $0x5,%cl # Push exception
- rep # frame on
- movsl # link stack
- xchgl %eax,%esi # Saved seg regs
- movl 0x40(%esp,1),%eax # Get int no
- testl %edx,%edx # Have btx_v86?
- jz intusr.2 # No
- movl (%ebx),%ebp # btx_v86 pointer
- movb $0x4,%cl # Count
- addl %ecx,%ebx # Adjust for pop
- rep # Push saved seg regs
- movsl # on link stack
- addl %ebp,%edx # Flatten btx_v86 ptr
- leal 0x14(%edx),%esi # Seg regs pointer
- movl 0x4(%edx),%eax # Get int no/address
- movzwl 0x2(%edx),%edx # Get control flags
-intusr.2: movl %ebp,(%edi) # Push btx_v86 and
- movl %edi,MEM_TSS+TSS_ESP1 # save link stack ptr
- popl %edi # Base of frame
- xchgl %eax,%ebp # Save intno/address
- movl 0x48(%esp,1),%eax # Get flags
- testb $0x2,%dl # Simulate CALLF?
- jnz intusr.3 # Yes
- decl %ebx # Push flags
- decl %ebx # on V86
- movw %ax,(%ebx) # stack
-intusr.3: movb $0x4,%cl # Count
- subl %ecx,%ebx # Push return address
- movl $inthlt,(%ebx) # on V86 stack
- rep # Copy seg regs to
- movsl # exception frame
- xchgl %eax,%ecx # Save flags
- movl %ebx,%eax # User ESP
- subl $V86_STK,%eax # Less bytes
- ja intusr.4 # to
- xorl %eax,%eax # keep
-intusr.4: shrl $0x4,%eax # Gives segment
- stosl # Set SS
- shll $0x4,%eax # To bytes
- xchgl %eax,%ebx # Swap
- subl %ebx,%eax # Gives offset
- stosl # Set ESP
- xchgl %eax,%ecx # Get flags
- btsl $0x11,%eax # Set VM
- andb $~0x1,%ah # Clear TF
- stosl # Set EFL
- xchgl %eax,%ebp # Get int no/address
- testb $0x1,%dl # Address?
- jnz intusr.5 # Yes
- shll $0x2,%eax # Scale
- movl (%eax),%eax # Load int vector
-intusr.5: movl %eax,%ecx # Save
- shrl $0x10,%eax # Gives segment
- stosl # Set CS
- movw %cx,%ax # Restore
- stosl # Set EIP
- leal 0x10(%esp,1),%esp # Discard seg regs
- popa # Restore
- iret # To V86 mode
-#
-# System Call.
-#
-intx30: cmpl $SYS_EXEC,%eax # Exec system call?
- jne intx30.1 # No
- pushl %ss # Set up
- popl %es # all
- pushl %es # segment
- popl %ds # registers
- pushl %ds # for the
- popl %fs # program
- pushl %fs # we're
- popl %gs # invoking
- movl $MEM_USR,%eax # User base address
- addl 0xc(%esp,1),%eax # Change to user
- leal 0x4(%eax),%esp # stack
-ifdef(`PAGING',`
- movl %cr0,%eax # Turn
- andl $~0x80000000,%eax # off
- movl %eax,%cr0 # paging
- xorl %eax,%eax # Flush
- movl %eax,%cr3 # TLB
-')
- popl %eax # Call
- call *%eax # program
-intx30.1: orb $0x1,%ss:btx_hdr+0x7 # Flag reboot
- jmp exit # Exit
-#
-# Dump structure [EBX] to [EDI], using format string [ESI].
-#
-dump.0: stosb # Save char
-dump: lodsb # Load char
- testb %al,%al # End of string?
- jz dump.10 # Yes
- testb $0x80,%al # Control?
- jz dump.0 # No
- movb %al,%ch # Save control
- movb $'=',%al # Append
- stosb # '='
- lodsb # Get offset
- pushl %esi # Save
- movsbl %al,%esi # To
- addl %ebx,%esi # pointer
- testb $DMP_X16,%ch # Dump word?
- jz dump.1 # No
- lodsw # Get and
- call hex16 # dump it
-dump.1: testb $DMP_X32,%ch # Dump long?
- jz dump.2 # No
- lodsl # Get and
- call hex32 # dump it
-dump.2: testb $DMP_MEM,%ch # Dump memory?
- jz dump.8 # No
- pushl %ds # Save
- testb $0x2,0x52(%ebx) # V86 mode?
- jnz dump.3 # Yes
- verr 0x4(%esi) # Readable selector?
- jnz dump.3 # No
- ldsl (%esi),%esi # Load pointer
- jmp dump.4 # Join common code
-dump.3: lodsl # Set offset
- xchgl %eax,%edx # Save
- lodsl # Get segment
- shll $0x4,%eax # * 0x10
- addl %edx,%eax # + offset
- xchgl %eax,%esi # Set pointer
-dump.4: movb $2,%dl # Num lines
-dump.4a: movb $0x10,%cl # Bytes to dump
-dump.5: lodsb # Get byte and
- call hex8 # dump it
- decb %cl # Keep count
- jz dump.6a # If done
- movb $'-',%al # Separator
- cmpb $0x8,%cl # Half way?
- je dump.6 # Yes
- movb $' ',%al # Use space
-dump.6: stosb # Save separator
- jmp dump.5 # Continue
-dump.6a: decb %dl # Keep count
- jz dump.7 # If done
- movb $0xa,%al # Line feed
- stosb # Save one
- movb $7,%cl # Leading
- movb $' ',%al # spaces
-dump.6b: stosb # Dump
- decb %cl # spaces
- jnz dump.6b
- jmp dump.4a # Next line
-dump.7: popl %ds # Restore
-dump.8: popl %esi # Restore
- movb $0xa,%al # Line feed
- testb $DMP_EOL,%ch # End of line?
- jnz dump.9 # Yes
- movb $' ',%al # Use spaces
- stosb # Save one
-dump.9: jmp dump.0 # Continue
-dump.10: stosb # Terminate string
- ret # To caller
-#
-# Convert EAX, AX, or AL to hex, saving the result to [EDI].
-#
-hex32: pushl %eax # Save
- shrl $0x10,%eax # Do upper
- call hex16 # 16
- popl %eax # Restore
-hex16: call hex16.1 # Do upper 8
-hex16.1: xchgb %ah,%al # Save/restore
-hex8: pushl %eax # Save
- shrb $0x4,%al # Do upper
- call hex8.1 # 4
- popl %eax # Restore
-hex8.1: andb $0xf,%al # Get lower 4
- cmpb $0xa,%al # Convert
- sbbb $0x69,%al # to hex
- das # digit
- orb $0x20,%al # To lower case
- stosb # Save char
- ret # (Recursive)
-#
-# Output zero-terminated string [ESI] to the console.
-#
-putstr.0: call putchr # Output char
-putstr: lodsb # Load char
- testb %al,%al # End of string?
- jnz putstr.0 # No
- ret # To caller
-ifdef(`BTX_SERIAL',`
- .set SIO_PRT,SIOPRT # Base port
- .set SIO_FMT,SIOFMT # 8N1
- .set SIO_DIV,(115200/SIOSPD) # 115200 / SPD
-
-# void sio_init(void)
-
-sio_init: movw $SIO_PRT+0x3,%dx # Data format reg
- movb $SIO_FMT|0x80,%al # Set format
- outb %al,(%dx) # and DLAB
- pushl %edx # Save
- subb $0x3,%dl # Divisor latch reg
- movw $SIO_DIV,%ax # Set
- outw %ax,(%dx) # BPS
- popl %edx # Restore
- movb $SIO_FMT,%al # Clear
- outb %al,(%dx) # DLAB
- incl %edx # Modem control reg
- movb $0x3,%al # Set RTS,
- outb %al,(%dx) # DTR
- incl %edx # Line status reg
-
-# void sio_flush(void)
-
-sio_flush.0: call sio_getc.1 # Get character
-sio_flush: call sio_ischar # Check for character
- jnz sio_flush.0 # Till none
- ret # To caller
-
-# void sio_putc(int c)
-
-sio_putc: movw $SIO_PRT+0x5,%dx # Line status reg
- xor %ecx,%ecx # Timeout
- movb $0x40,%ch # counter
-sio_putc.1: inb (%dx),%al # Transmitter
- testb $0x20,%al # buffer empty?
- loopz sio_putc.1 # No
- jz sio_putc.2 # If timeout
- movb 0x4(%esp,1),%al # Get character
- subb $0x5,%dl # Transmitter hold reg
- outb %al,(%dx) # Write character
-sio_putc.2: ret $0x4 # To caller
-
-# int sio_getc(void)
-
-sio_getc: call sio_ischar # Character available?
- jz sio_getc # No
-sio_getc.1: subb $0x5,%dl # Receiver buffer reg
- inb (%dx),%al # Read character
- ret # To caller
-
-# int sio_ischar(void)
-
-sio_ischar: movw $SIO_PRT+0x5,%dx # Line status register
- xorl %eax,%eax # Zero
- inb (%dx),%al # Received data
- andb $0x1,%al # ready?
- ret # To caller
-
-#
-# Output character AL to the serial console.
-#
-putchr: pusha # Save
- cmpb $10, %al # is it a newline?
- jne putchr.1 # no?, then leave
- push $13 # output a carriage
- call sio_putc # return first
- movb $10, %al # restore %al
-putchr.1: pushl %eax # Push the character
- # onto the stack
- call sio_putc # Output the character
- popa # Restore
- ret # To caller
-',`
-#
-# Output character AL to the console.
-#
-putchr: pusha # Save
- xorl %ecx,%ecx # Zero for loops
- movb $SCR_MAT,%ah # Mode/attribute
- movl $BDA_POS,%ebx # BDA pointer
- movw (%ebx),%dx # Cursor position
- movl $0xb8000,%edi # Regen buffer (color)
- cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode?
- jne putchr.1 # No
- xorw %di,%di # Regen buffer (mono)
-putchr.1: cmpb $0xa,%al # New line?
- je putchr.2 # Yes
- xchgl %eax,%ecx # Save char
- movb $SCR_COL,%al # Columns per row
- mulb %dh # * row position
- addb %dl,%al # + column
- adcb $0x0,%ah # position
- shll %eax # * 2
- xchgl %eax,%ecx # Swap char, offset
- movw %ax,(%edi,%ecx,1) # Write attr:char
- incl %edx # Bump cursor
- cmpb $SCR_COL,%dl # Beyond row?
- jb putchr.3 # No
-putchr.2: xorb %dl,%dl # Zero column
- incb %dh # Bump row
-putchr.3: cmpb $SCR_ROW,%dh # Beyond screen?
- jb putchr.4 # No
- leal 2*SCR_COL(%edi),%esi # New top line
- movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
- rep # Scroll
- movsl # screen
- movb $0x20,%al # Space
- movb $SCR_COL,%cl # Columns to clear
- rep # Clear
- stosw # line
- movb $SCR_ROW-1,%dh # Bottom line
-putchr.4: movw %dx,(%ebx) # Update position
- popa # Restore
- ret # To caller
-')
-
- .p2align 4
-#
-# Global descriptor table.
-#
-gdt: .word 0x0,0x0,0x0,0x0 # Null entry
- .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE
- .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA
- .word 0xffff,0x0,0x9a00,0x0 # SEL_RCODE
- .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA
- .word 0xffff,MEM_USR,0xfa00,0xcf# SEL_UCODE
- .word 0xffff,MEM_USR,0xf200,0xcf# SEL_UDATA
- .word _TSSLM,MEM_TSS,0x8900,0x0 # SEL_TSS
-gdt.1:
-#
-# Pseudo-descriptors.
-#
-gdtdesc: .word gdt.1-gdt-1,gdt,0x0 # GDT
-idtdesc: .word _IDTLM,MEM_IDT,0x0 # IDT
-ivtdesc: .word 0x400-0x0-1,0x0,0x0 # IVT
-#
-# IDT construction control string.
-#
-idtctl: .byte 0x10, 0x8e # Int 0x0-0xf
- .word 0x7dfb,intx00 # (exceptions)
- .byte 0x10, 0x8e # Int 0x10
- .word 0x1, intx10 # (exception)
- .byte 0x10, 0x8e # Int 0x20-0x2f
- .word 0xffff,intx20 # (hardware)
- .byte 0x1, 0xee # int 0x30
- .word 0x1, intx30 # (system call)
- .byte 0x2, 0xee # Int 0x31-0x32
- .word 0x1, intx31 # (V86, null)
- .byte 0x0 # End of string
-#
-# Dump format string.
-#
-dmpfmt: .byte '\n' # "\n"
- .ascii "int" # "int="
- .byte 0x80|DMP_X32, 0x40 # "00000000 "
- .ascii "err" # "err="
- .byte 0x80|DMP_X32, 0x44 # "00000000 "
- .ascii "efl" # "efl="
- .byte 0x80|DMP_X32, 0x50 # "00000000 "
- .ascii "eip" # "eip="
- .byte 0x80|DMP_X32|DMP_EOL,0x48 # "00000000\n"
- .ascii "eax" # "eax="
- .byte 0x80|DMP_X32, 0x34 # "00000000 "
- .ascii "ebx" # "ebx="
- .byte 0x80|DMP_X32, 0x28 # "00000000 "
- .ascii "ecx" # "ecx="
- .byte 0x80|DMP_X32, 0x30 # "00000000 "
- .ascii "edx" # "edx="
- .byte 0x80|DMP_X32|DMP_EOL,0x2c # "00000000\n"
- .ascii "esi" # "esi="
- .byte 0x80|DMP_X32, 0x1c # "00000000 "
- .ascii "edi" # "edi="
- .byte 0x80|DMP_X32, 0x18 # "00000000 "
- .ascii "ebp" # "ebp="
- .byte 0x80|DMP_X32, 0x20 # "00000000 "
- .ascii "esp" # "esp="
- .byte 0x80|DMP_X32|DMP_EOL,0x0 # "00000000\n"
- .ascii "cs" # "cs="
- .byte 0x80|DMP_X16, 0x4c # "0000 "
- .ascii "ds" # "ds="
- .byte 0x80|DMP_X16, 0xc # "0000 "
- .ascii "es" # "es="
- .byte 0x80|DMP_X16, 0x8 # "0000 "
- .ascii " " # " "
- .ascii "fs" # "fs="
- .byte 0x80|DMP_X16, 0x10 # "0000 "
- .ascii "gs" # "gs="
- .byte 0x80|DMP_X16, 0x14 # "0000 "
- .ascii "ss" # "ss="
- .byte 0x80|DMP_X16|DMP_EOL,0x4 # "0000\n"
- .ascii "cs:eip" # "cs:eip="
- .byte 0x80|DMP_MEM|DMP_EOL,0x48 # "00 00 ... 00 00\n"
- .ascii "ss:esp" # "ss:esp="
- .byte 0x80|DMP_MEM|DMP_EOL,0x0 # "00 00 ... 00 00\n"
- .asciz "BTX halted\n" # End
-#
-# End of BTX memory.
-#
- .p2align 4
-break:
diff --git a/sys/boot/i386/btx/btxldr/btxldr.S b/sys/boot/i386/btx/btxldr/btxldr.S
deleted file mode 100644
index 67a986c76739..000000000000
--- a/sys/boot/i386/btx/btxldr/btxldr.S
+++ /dev/null
@@ -1,396 +0,0 @@
-#
-# Copyright (c) 1998 Robert Nordier
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms are freely
-# permitted provided that the above copyright notice and this
-# paragraph and the following disclaimer are duplicated in all
-# such forms.
-#
-# This software is provided "AS IS" and without any express or
-# implied warranties, including, without limitation, the implied
-# warranties of merchantability and fitness for a particular
-# purpose.
-#
-
-# $FreeBSD$
-
-#
-# Prototype BTX loader program, written in a couple of hours. The
-# real thing should probably be more flexible, and in C.
-#
-
-#
-# Memory locations.
-#
- .set MEM_STUB,0x600 # Real mode stub
- .set MEM_ESP,0x1000 # New stack pointer
- .set MEM_TBL,0x5000 # BTX page tables
- .set MEM_ENTRY,0x9010 # BTX entry point
- .set MEM_DATA,start+0x1000 # Data segment
-#
-# Segment selectors.
-#
- .set SEL_SCODE,0x8 # 4GB code
- .set SEL_SDATA,0x10 # 4GB data
- .set SEL_RCODE,0x18 # 64K code
- .set SEL_RDATA,0x20 # 64K data
-#
-# Paging constants.
-#
- .set PAG_SIZ,0x1000 # Page size
- .set PAG_ENT,0x4 # Page entry size
-#
-# Screen constants.
-#
- .set SCR_MAT,0x7 # Mode/attribute
- .set SCR_COL,0x50 # Columns per row
- .set SCR_ROW,0x19 # Rows per screen
-#
-# BIOS Data Area locations.
-#
- .set BDA_MEM,0x413 # Free memory
- .set BDA_SCR,0x449 # Video mode
- .set BDA_POS,0x450 # Cursor position
-#
-# Required by aout gas inadequacy.
-#
- .set SIZ_STUB,0x1a # Size of stub
-#
-# We expect to be loaded by boot2 at the origin defined in ./Makefile.
-#
- .globl start
-#
-# BTX program loader for ELF clients.
-#
-start: cld # String ops inc
- movl $m_logo,%esi # Identify
- call putstr # ourselves
- movzwl BDA_MEM,%eax # Get base memory
- shll $0xa,%eax # in bytes
- movl %eax,%ebp # Base of user stack
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_mem,%esi # Display
- call hexout # amount of
- call putstr # base memory
-')
- lgdt gdtdesc # Load new GDT
-#
-# Relocate caller's arguments.
-#
-ifdef('BTXLDR_VERBOSE',`
- movl $m_esp,%esi # Display
- movl %esp,%eax # caller
- call hexout # stack
- call putstr # pointer
- movl $m_args,%esi # Format string
- leal 0x4(%esp,1),%ebx # First argument
- movl $0x6,%ecx # Count
-start.1: movl (%ebx),%eax # Get argument and
- addl $0x4,%ebx # bump pointer
- call hexout # Display it
- loop start.1 # Till done
- call putstr # End message
-')
- movl $0x48,%ecx # Allocate space
- subl %ecx,%ebp # for bootinfo
- movl 0x18(%esp,1),%esi # Source: bootinfo
- cmpl $0x0, %esi # If the bootinfo pointer
- je start_null_bi # is null, don't copy it
- movl %ebp,%edi # Destination
- rep # Copy
- movsb # it
- movl %ebp,0x18(%esp,1) # Update pointer
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_rel_bi,%esi # Display
- movl %ebp,%eax # bootinfo
- call hexout # relocation
- call putstr # message
-')
-start_null_bi: movl $0x18,%ecx # Allocate space
- subl %ecx,%ebp # for arguments
- leal 0x4(%esp,1),%esi # Source
- movl %ebp,%edi # Destination
- rep # Copy
- movsb # them
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_rel_args,%esi # Display
- movl %ebp,%eax # argument
- call hexout # relocation
- call putstr # message
-')
-#
-# Set up BTX kernel.
-#
- movl $MEM_ESP,%esp # Set up new stack
- movl $MEM_DATA,%ebx # Data segment
- movl $m_vers,%esi # Display BTX
- call putstr # version message
- movb 0x5(%ebx),%al # Get major version
- addb $'0',%al # Display
- call putchr # it
- movb $'.',%al # And a
- call putchr # dot
- movb 0x6(%ebx),%al # Get minor
- xorb %ah,%ah # version
- movb $0xa,%dl # Divide
- divb %dl,%al # by 10
- addb $'0',%al # Display
- call putchr # tens
- movb %ah,%al # Get units
- addb $'0',%al # Display
- call putchr # units
- call putstr # End message
- movl %ebx,%esi # BTX image
- movzwl 0x8(%ebx),%edi # Compute
- orl $PAG_SIZ/PAG_ENT-1,%edi # the
- incl %edi # BTX
- shll $0x2,%edi # load
- addl $MEM_TBL,%edi # address
- pushl %edi # Save load address
- movzwl 0xa(%ebx),%ecx # Image size
-ifdef(`BTXLDR_VERBOSE',`
- pushl %ecx # Save image size
-')
- rep # Relocate
- movsb # BTX
- movl %esi,%ebx # Keep place
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_rel_btx,%esi # Restore
- popl %eax # parameters
- call hexout # and
-')
- popl %ebp # display
-ifdef(`BTXLDR_VERBOSE',`
- movl %ebp,%eax # the
- call hexout # relocation
- call putstr # message
-')
- addl $PAG_SIZ,%ebp # Display
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_base,%esi # the
- movl %ebp,%eax # user
- call hexout # base
- call putstr # address
-')
-#
-# Set up ELF-format client program.
-#
- cmpl $0x464c457f,(%ebx) # ELF magic number?
- je start.3 # Yes
- movl $e_fmt,%esi # Display error
- call putstr # message
-start.2: jmp start.2 # Hang
-start.3:
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_elf,%esi # Display ELF
- call putstr # message
- movl $m_segs,%esi # Format string
-')
- movl $0x2,%edi # Segment count
- movl 0x1c(%ebx),%edx # Get e_phoff
- addl %ebx,%edx # To pointer
- movzwl 0x2c(%ebx),%ecx # Get e_phnum
-start.4: cmpl $0x1,(%edx) # Is p_type PT_LOAD?
- jne start.6 # No
-ifdef(`BTXLDR_VERBOSE',`
- movl 0x4(%edx),%eax # Display
- call hexout # p_offset
- movl 0x8(%edx),%eax # Display
- call hexout # p_vaddr
- movl 0x10(%edx),%eax # Display
- call hexout # p_filesz
- movl 0x14(%edx),%eax # Display
- call hexout # p_memsz
- call putstr # End message
-')
- pushl %esi # Save
- pushl %edi # working
- pushl %ecx # registers
- movl 0x4(%edx),%esi # Get p_offset
- addl %ebx,%esi # as pointer
- movl 0x8(%edx),%edi # Get p_vaddr
- addl %ebp,%edi # as pointer
- movl 0x10(%edx),%ecx # Get p_filesz
- rep # Set up
- movsb # segment
- movl 0x14(%edx),%ecx # Any bytes
- subl 0x10(%edx),%ecx # to zero?
- jz start.5 # No
- xorb %al,%al # Then
- rep # zero
- stosb # them
-start.5: popl %ecx # Restore
- popl %edi # working
- popl %esi # registers
- decl %edi # Segments to do
- je start.7 # If none
-start.6: addl $0x20,%edx # To next entry
- loop start.4 # Till done
-start.7:
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_done,%esi # Display done
- call putstr # message
-')
- movl $start.8,%esi # Real mode stub
- movl $MEM_STUB,%edi # Destination
- movl $start.9-start.8,%ecx # Size
- rep # Relocate
- movsb # it
- ljmp $SEL_RCODE,$MEM_STUB # To 16-bit code
- .code16
-start.8: xorw %ax,%ax # Data
- movb $SEL_RDATA,%al # selector
- movw %ax,%ss # Reload SS
- movw %ax,%ds # Reset
- movw %ax,%es # other
- movw %ax,%fs # segment
- movw %ax,%gs # limits
- movl %cr0,%eax # Switch to
- decw %ax # real
- movl %eax,%cr0 # mode
- ljmp $0,$MEM_ENTRY # Jump to BTX entry point
-start.9:
- .code32
-#
-# Output message [ESI] followed by EAX in hex.
-#
-hexout: pushl %eax # Save
- call putstr # Display message
- popl %eax # Restore
- pushl %esi # Save
- pushl %edi # caller's
- movl $buf,%edi # Buffer
- pushl %edi # Save
- call hex32 # To hex
- xorb %al,%al # Terminate
- stosb # string
- popl %esi # Restore
-hexout.1: lodsb # Get a char
- cmpb $'0',%al # Leading zero?
- je hexout.1 # Yes
- testb %al,%al # End of string?
- jne hexout.2 # No
- decl %esi # Undo
-hexout.2: decl %esi # Adjust for inc
- call putstr # Display hex
- popl %edi # Restore
- popl %esi # caller's
- ret # To caller
-#
-# Output zero-terminated string [ESI] to the console.
-#
-putstr.0: call putchr # Output char
-putstr: lodsb # Load char
- testb %al,%al # End of string?
- jne putstr.0 # No
- ret # To caller
-#
-# Output character AL to the console.
-#
-putchr: pusha # Save
- xorl %ecx,%ecx # Zero for loops
- movb $SCR_MAT,%ah # Mode/attribute
- movl $BDA_POS,%ebx # BDA pointer
- movw (%ebx),%dx # Cursor position
- movl $0xb8000,%edi # Regen buffer (color)
- cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode?
- jne putchr.1 # No
- xorw %di,%di # Regen buffer (mono)
-putchr.1: cmpb $0xa,%al # New line?
- je putchr.2 # Yes
- xchgl %eax,%ecx # Save char
- movb $SCR_COL,%al # Columns per row
- mulb %dh # * row position
- addb %dl,%al # + column
- adcb $0x0,%ah # position
- shll %eax # * 2
- xchgl %eax,%ecx # Swap char, offset
- movw %ax,(%edi,%ecx,1) # Write attr:char
- incl %edx # Bump cursor
- cmpb $SCR_COL,%dl # Beyond row?
- jb putchr.3 # No
-putchr.2: xorb %dl,%dl # Zero column
- incb %dh # Bump row
-putchr.3: cmpb $SCR_ROW,%dh # Beyond screen?
- jb putchr.4 # No
- leal 2*SCR_COL(%edi),%esi # New top line
- movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
- rep # Scroll
- movsl # screen
- movb $' ',%al # Space
- movb $SCR_COL,%cl # Columns to clear
- rep # Clear
- stosw # line
- movb $SCR_ROW-1,%dh # Bottom line
-putchr.4: movw %dx,(%ebx) # Update position
- popa # Restore
- ret # To caller
-#
-# Convert EAX, AX, or AL to hex, saving the result to [EDI].
-#
-hex32: pushl %eax # Save
- shrl $0x10,%eax # Do upper
- call hex16 # 16
- popl %eax # Restore
-hex16: call hex16.1 # Do upper 8
-hex16.1: xchgb %ah,%al # Save/restore
-hex8: pushl %eax # Save
- shrb $0x4,%al # Do upper
- call hex8.1 # 4
- popl %eax # Restore
-hex8.1: andb $0xf,%al # Get lower 4
- cmpb $0xa,%al # Convert
- sbbb $0x69,%al # to hex
- das # digit
- orb $0x20,%al # To lower case
- stosb # Save char
- ret # (Recursive)
-
- .data
- .p2align 4
-#
-# Global descriptor table.
-#
-gdt: .word 0x0,0x0,0x0,0x0 # Null entry
- .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE
- .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA
- .word 0xffff,0x0,0x9a00,0x0 # SEL_RCODE
- .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA
-gdt.1:
-gdtdesc: .word gdt.1-gdt-1 # Limit
- .long gdt # Base
-#
-# Messages.
-#
-m_logo: .asciz " \nBTX loader 1.00 "
-m_vers: .asciz "BTX version is \0\n"
-e_fmt: .asciz "Error: Client format not supported\n"
-ifdef(`BTXLDR_VERBOSE',`
-m_mem: .asciz "Starting in protected mode (base mem=\0)\n"
-m_esp: .asciz "Arguments passed (esp=\0):\n"
-m_args: .asciz"<howto="
- .asciz" bootdev="
- .asciz" junk="
- .asciz" "
- .asciz" "
- .asciz" bootinfo=\0>\n"
-m_rel_bi: .asciz "Relocated bootinfo (size=48) to \0\n"
-m_rel_args: .asciz "Relocated arguments (size=18) to \0\n"
-m_rel_btx: .asciz "Relocated kernel (size=\0) to \0\n"
-m_base: .asciz "Client base address is \0\n"
-m_elf: .asciz "Client format is ELF\n"
-m_segs: .asciz "text segment: offset="
- .asciz " vaddr="
- .asciz " filesz="
- .asciz " memsz=\0\n"
- .asciz "data segment: offset="
- .asciz " vaddr="
- .asciz " filesz="
- .asciz " memsz=\0\n"
-m_done: .asciz "Loading complete\n"
-')
-#
-# Uninitialized data area.
-#
-buf: # Scratch buffer
diff --git a/sys/boot/i386/gptboot/Makefile b/sys/boot/i386/gptboot/Makefile
deleted file mode 100644
index 95fec08bd701..000000000000
--- a/sys/boot/i386/gptboot/Makefile
+++ /dev/null
@@ -1,111 +0,0 @@
-# $FreeBSD$
-
-PROG= boot2
-NOMAN=
-STRIP=
-BINDIR?= /boot
-BINMODE= 444
-CLEANFILES= boot boot1 boot1.out boot1.o \
- boot2.ldr boot2.bin boot2.ld boot2.out boot2.o boot2.h \
- boot2.s sio.o
-
-NM?= nm
-
-# A value of 0x80 enables LBA support.
-B1FLAGS= 0x80
-
-BOOT_COMCONSOLE_PORT?= 0x3f8
-BOOT_COMCONSOLE_SPEED?= 9600
-B2SIOFMT?= 0x3
-
-.if exists(${.OBJDIR}/../btx)
-BTX= ${.OBJDIR}/../btx
-.else
-BTX= ${.CURDIR}/../btx
-.endif
-
-REL1= 0x700
-ORG1= 0x7c00
-ORG2= 0x2000
-
-# Decide Level of UFS support. UFS1_AND_UFS2 doesn't fit.
-
-# BOOT2_UFS?= UFS2_ONLY
-BOOT2_UFS?= UFS1_AND_UFS2
-# BOOT2_UFS?= UFS1_ONLY
-
-CFLAGS= -elf -ffreestanding -Os -fno-builtin \
- -fno-guess-branch-probability -fomit-frame-pointer\
- -mno-align-long-strings \
- -mrtd \
- -D${BOOT2_UFS} \
- -I${.CURDIR}/../../common \
- -I${.CURDIR}/../btx/lib -I. \
- -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
- -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
- -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
-
-LDFLAGS=-nostdlib -static -N --gc-sections
-
-all: boot1 boot2 boot
-
-boot: boot1 boot2
- cat boot1 boot2 > boot
-
-boot1: boot1.out
- objcopy -S -O binary boot1.out ${.TARGET}
-
-boot1.out: boot1.o
- ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
-
-boot1.o: boot1.s
- ${CPP} ${CFLAGS} ${.IMPSRC} | \
- ${AS} ${AFLAGS} --defsym FLAGS=${B1FLAGS} -o ${.TARGET}
-
-boot2.o: boot2.c ${.CURDIR}/../../common/ufsread.c
- ${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
- sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
- rm -f boot2.s.tmp
- ${AS} ${AFLAGS} -o boot2.o boot2.s
-
-boot2.h: boot1.out
- ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
- { x = $$1 - ORG1; \
- printf("#define XREADORG %#x\n", REL1 + x) }' \
- ORG1=`printf "%d" ${ORG1}` \
- REL1=`printf "%d" ${REL1}` > boot2.h
-
-boot2: boot2.ldr boot2.bin ${BTX}/btx/btx
- btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
- -o boot2.ld -P 1 boot2.bin
- @ls -l boot2.ld | awk '{ x = 7680 - $$5; \
- print x " bytes available"; if (x < 0) exit 1 }'
- dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync 2>/dev/null
-
-boot2.ldr:
- dd if=/dev/zero of=${.TARGET} bs=276 count=1 2>/dev/null
-
-boot2.bin: boot2.out
- objcopy -S -O binary boot2.out ${.TARGET}
-
-boot2.out: boot2.o sio.o
- ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
- ${BTX}/lib/crt0.o ${.ALLSRC}
-
-boot2.o: boot2.h
-
-sio.o: sio.s
- ${AS} ${AFLAGS} --defsym SIOPRT=${BOOT_COMCONSOLE_PORT} \
- --defsym SIOFMT=${B2SIOFMT} \
- --defsym SIOSPD=${BOOT_COMCONSOLE_SPEED} \
- ${.IMPSRC} -o ${.TARGET}
-
-install:
- ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
- boot ${DESTDIR}${BINDIR}/boot
- ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
- boot1 ${DESTDIR}${BINDIR}/boot1
- ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
- boot2 ${DESTDIR}${BINDIR}/boot2
-
-.include <bsd.prog.mk>
diff --git a/sys/boot/i386/gptboot/gptboot.c b/sys/boot/i386/gptboot/gptboot.c
deleted file mode 100644
index 75216ed414e6..000000000000
--- a/sys/boot/i386/gptboot/gptboot.c
+++ /dev/null
@@ -1,633 +0,0 @@
-/*
- * Copyright (c) 1998 Robert Nordier
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are freely
- * permitted provided that the above copyright notice and this
- * paragraph and the following disclaimer are duplicated in all
- * such forms.
- *
- * This software is provided "AS IS" and without any express or
- * implied warranties, including, without limitation, the implied
- * warranties of merchantability and fitness for a particular
- * purpose.
- */
-
-/*
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/disklabel.h>
-#include <sys/diskmbr.h>
-#include <sys/dirent.h>
-#include <machine/bootinfo.h>
-#include <machine/elf.h>
-
-#include <stdarg.h>
-
-#include <a.out.h>
-
-#include <btxv86.h>
-
-#include "boot2.h"
-#include "lib.h"
-
-#define IO_KEYBOARD 1
-#define IO_SERIAL 2
-
-#define SECOND 18 /* Circa that many ticks in a second. */
-
-#define RBX_ASKNAME 0x0 /* -a */
-#define RBX_SINGLE 0x1 /* -s */
-#define RBX_DFLTROOT 0x5 /* -r */
-#define RBX_KDB 0x6 /* -d */
-#define RBX_CONFIG 0xa /* -c */
-#define RBX_VERBOSE 0xb /* -v */
-#define RBX_SERIAL 0xc /* -h */
-#define RBX_CDROM 0xd /* -C */
-#define RBX_GDB 0xf /* -g */
-#define RBX_MUTE 0x10 /* -m */
-#define RBX_PAUSE 0x12 /* -p */
-#define RBX_NOINTR 0x1c /* -n */
-#define RBX_DUAL 0x1d /* -D */
-#define RBX_PROBEKBD 0x1e /* -P */
-/* 0x1f is reserved for the historical RB_BOOTINFO option */
-
-/* pass: -a, -s, -r, -d, -c, -v, -h, -C, -g, -m, -p, -D */
-#define RBX_MASK 0x2005ffff
-
-#define PATH_CONFIG "/boot.config"
-#define PATH_BOOT3 "/boot/loader"
-#define PATH_KERNEL "/kernel"
-
-#define ARGS 0x900
-#define NOPT 12
-#define NDEV 3
-#define MEM_BASE 0x12
-#define MEM_EXT 0x15
-#define V86_CY(x) ((x) & 1)
-#define V86_ZR(x) ((x) & 0x40)
-
-#define DRV_HARD 0x80
-#define DRV_MASK 0x7f
-
-#define TYPE_AD 0
-#define TYPE_DA 1
-#define TYPE_MAXHARD TYPE_DA
-#define TYPE_FD 2
-
-extern uint32_t _end;
-
-static const char optstr[NOPT] = "DhaCgmnPprsv";
-static const unsigned char flags[NOPT] = {
- RBX_DUAL,
- RBX_SERIAL,
- RBX_ASKNAME,
- RBX_CDROM,
- RBX_GDB,
- RBX_MUTE,
- RBX_NOINTR,
- RBX_PROBEKBD,
- RBX_PAUSE,
- RBX_DFLTROOT,
- RBX_SINGLE,
- RBX_VERBOSE
-};
-
-static const char *const dev_nm[NDEV] = {"ad", "da", "fd"};
-static const unsigned char dev_maj[NDEV] = {30, 4, 2};
-
-static struct dsk {
- unsigned drive;
- unsigned type;
- unsigned unit;
- unsigned slice;
- unsigned part;
- unsigned start;
- int init;
-} dsk;
-static char cmd[512];
-static char kname[1024];
-static uint32_t opts;
-static struct bootinfo bootinfo;
-static uint8_t ioctrl = IO_KEYBOARD;
-
-void exit(int);
-static void load(void);
-static int parse(void);
-static int xfsread(ino_t, void *, size_t);
-static int dskread(void *, unsigned, unsigned);
-static void printf(const char *,...);
-static void putchar(int);
-static uint32_t memsize(void);
-static int drvread(void *, unsigned, unsigned);
-static int keyhit(unsigned);
-static int xputc(int);
-static int xgetc(int);
-static int getc(int);
-
-#define memcpy __builtin_memcpy
-
-static inline int
-strcmp(const char *s1, const char *s2)
-{
- for (; *s1 == *s2 && *s1; s1++, s2++);
- return (unsigned char)*s1 - (unsigned char)*s2;
-}
-
-#include "ufsread.c"
-
-static int
-xfsread(ino_t inode, void *buf, size_t nbyte)
-{
- if ((size_t)fsread(inode, buf, nbyte) != nbyte) {
- printf("Invalid %s\n", "format");
- return -1;
- }
- return 0;
-}
-
-static inline uint32_t
-memsize(void)
-{
- v86.addr = MEM_EXT;
- v86.eax = 0x8800;
- v86int();
- return v86.eax;
-}
-
-static inline void
-getstr(void)
-{
- char *s;
- int c;
-
- s = cmd;
- for (;;) {
- switch (c = xgetc(0)) {
- case 0:
- break;
- case '\177':
- case '\b':
- if (s > cmd) {
- s--;
- printf("\b \b");
- }
- break;
- case '\n':
- case '\r':
- *s = 0;
- return;
- default:
- if (s - cmd < sizeof(cmd) - 1)
- *s++ = c;
- putchar(c);
- }
- }
-}
-
-static inline void
-putc(int c)
-{
- v86.addr = 0x10;
- v86.eax = 0xe00 | (c & 0xff);
- v86.ebx = 0x7;
- v86int();
-}
-
-int
-main(void)
-{
- int autoboot;
- ino_t ino;
-
- dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base);
- v86.ctl = V86_FLAGS;
- dsk.drive = *(uint8_t *)PTOV(ARGS);
- dsk.type = dsk.drive & DRV_HARD ? TYPE_AD : TYPE_FD;
- dsk.unit = dsk.drive & DRV_MASK;
- dsk.slice = *(uint8_t *)PTOV(ARGS + 1) + 1;
- bootinfo.bi_version = BOOTINFO_VERSION;
- bootinfo.bi_size = sizeof(bootinfo);
- bootinfo.bi_basemem = 0; /* XXX will be filled by loader or kernel */
- bootinfo.bi_extmem = memsize();
- bootinfo.bi_memsizes_valid++;
-
- /* Process configuration file */
-
- autoboot = 1;
-
- if ((ino = lookup(PATH_CONFIG)))
- fsread(ino, cmd, sizeof(cmd));
-
- if (*cmd) {
- printf("%s: %s", PATH_CONFIG, cmd);
- if (parse())
- autoboot = 0;
- /* Do not process this command twice */
- *cmd = 0;
- }
-
- /*
- * Try to exec stage 3 boot loader. If interrupted by a keypress,
- * or in case of failure, try to load a kernel directly instead.
- */
-
- if (autoboot && !*kname) {
- memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3));
- if (!keyhit(3*SECOND)) {
- load();
- memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL));
- }
- }
-
- /* Present the user with the boot2 prompt. */
-
- for (;;) {
- printf("\nFreeBSD/i386 boot\n"
- "Default: %u:%s(%u,%c)%s\n"
- "boot: ",
- dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit,
- 'a' + dsk.part, kname);
- if (ioctrl & IO_SERIAL)
- sio_flush();
- if (!autoboot || keyhit(5*SECOND))
- getstr();
- else
- putchar('\n');
- autoboot = 0;
- if (parse())
- putchar('\a');
- else
- load();
- }
-}
-
-/* XXX - Needed for btxld to link the boot2 binary; do not remove. */
-void
-exit(int x)
-{
-}
-
-static void
-load(void)
-{
- union {
- struct exec ex;
- Elf32_Ehdr eh;
- } hdr;
- Elf32_Phdr ep[2];
- Elf32_Shdr es[2];
- caddr_t p;
- ino_t ino;
- uint32_t addr, x;
- int fmt, i, j;
-
- if (!(ino = lookup(kname))) {
- if (!ls)
- printf("No %s\n", kname);
- return;
- }
- if (xfsread(ino, &hdr, sizeof(hdr)))
- return;
- if (N_GETMAGIC(hdr.ex) == ZMAGIC)
- fmt = 0;
- else if (IS_ELF(hdr.eh))
- fmt = 1;
- else {
- printf("Invalid %s\n", "format");
- return;
- }
- if (fmt == 0) {
- addr = hdr.ex.a_entry & 0xffffff;
- p = PTOV(addr);
- fs_off = PAGE_SIZE;
- if (xfsread(ino, p, hdr.ex.a_text))
- return;
- p += roundup2(hdr.ex.a_text, PAGE_SIZE);
- if (xfsread(ino, p, hdr.ex.a_data))
- return;
- p += hdr.ex.a_data + roundup2(hdr.ex.a_bss, PAGE_SIZE);
- bootinfo.bi_symtab = VTOP(p);
- memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms));
- p += sizeof(hdr.ex.a_syms);
- if (hdr.ex.a_syms) {
- if (xfsread(ino, p, hdr.ex.a_syms))
- return;
- p += hdr.ex.a_syms;
- if (xfsread(ino, p, sizeof(int)))
- return;
- x = *(uint32_t *)p;
- p += sizeof(int);
- x -= sizeof(int);
- if (xfsread(ino, p, x))
- return;
- p += x;
- }
- } else {
- fs_off = hdr.eh.e_phoff;
- for (j = i = 0; i < hdr.eh.e_phnum && j < 2; i++) {
- if (xfsread(ino, ep + j, sizeof(ep[0])))
- return;
- if (ep[j].p_type == PT_LOAD)
- j++;
- }
- for (i = 0; i < 2; i++) {
- p = PTOV(ep[i].p_paddr & 0xffffff);
- fs_off = ep[i].p_offset;
- if (xfsread(ino, p, ep[i].p_filesz))
- return;
- }
- p += roundup2(ep[1].p_memsz, PAGE_SIZE);
- bootinfo.bi_symtab = VTOP(p);
- if (hdr.eh.e_shnum == hdr.eh.e_shstrndx + 3) {
- fs_off = hdr.eh.e_shoff + sizeof(es[0]) *
- (hdr.eh.e_shstrndx + 1);
- if (xfsread(ino, &es, sizeof(es)))
- return;
- for (i = 0; i < 2; i++) {
- memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size));
- p += sizeof(es[i].sh_size);
- fs_off = es[i].sh_offset;
- if (xfsread(ino, p, es[i].sh_size))
- return;
- p += es[i].sh_size;
- }
- }
- addr = hdr.eh.e_entry & 0xffffff;
- }
- bootinfo.bi_esymtab = VTOP(p);
- bootinfo.bi_kernelname = VTOP(kname);
- bootinfo.bi_bios_dev = dsk.drive;
- __exec((caddr_t)addr, opts & RBX_MASK,
- MAKEBOOTDEV(dev_maj[dsk.type], 0, dsk.slice, dsk.unit, dsk.part),
- 0, 0, 0, VTOP(&bootinfo));
-}
-
-static int
-parse()
-{
- char *arg = cmd;
- char *p, *q;
- unsigned int drv;
- int c, i;
-
- while ((c = *arg++)) {
- if (c == ' ' || c == '\t' || c == '\n')
- continue;
- for (p = arg; *p && *p != '\n' && *p != ' ' && *p != '\t'; p++);
- if (*p)
- *p++ = 0;
- if (c == '-') {
- while ((c = *arg++)) {
- for (i = 0; c != optstr[i]; i++)
- if (i == NOPT - 1)
- return -1;
- opts ^= 1 << flags[i];
- }
- if (opts & 1 << RBX_PROBEKBD) {
- i = *(uint8_t *)PTOV(0x496) & 0x10;
- printf("Keyboard: %s\n", i ? "yes" : "no");
- if (!i)
- opts |= 1 << RBX_DUAL | 1 << RBX_SERIAL;
- opts &= ~(1 << RBX_PROBEKBD);
- }
- ioctrl = opts & 1 << RBX_DUAL ? (IO_SERIAL|IO_KEYBOARD) :
- opts & 1 << RBX_SERIAL ? IO_SERIAL : IO_KEYBOARD;
- if (ioctrl & IO_SERIAL)
- sio_init();
- } else {
- for (q = arg--; *q && *q != '('; q++);
- if (*q) {
- drv = -1;
- if (arg[1] == ':') {
- drv = *arg - '0';
- if (drv > 9)
- return (-1);
- arg += 2;
- }
- if (q - arg != 2)
- return -1;
- for (i = 0; arg[0] != dev_nm[i][0] ||
- arg[1] != dev_nm[i][1]; i++)
- if (i == NDEV - 1)
- return -1;
- dsk.type = i;
- arg += 3;
- dsk.unit = *arg - '0';
- if (arg[1] != ',' || dsk.unit > 9)
- return -1;
- arg += 2;
- dsk.slice = WHOLE_DISK_SLICE;
- if (arg[1] == ',') {
- dsk.slice = *arg - '0' + 1;
- if (dsk.slice > NDOSPART)
- return -1;
- arg += 2;
- }
- if (arg[1] != ')')
- return -1;
- dsk.part = *arg - 'a';
- if (dsk.part > 7)
- return (-1);
- arg += 2;
- if (drv == -1)
- drv = dsk.unit;
- dsk.drive = (dsk.type <= TYPE_MAXHARD
- ? DRV_HARD : 0) + drv;
- dsk_meta = 0;
- }
- if ((i = p - arg - !*(p - 1))) {
- if ((size_t)i >= sizeof(kname))
- return -1;
- memcpy(kname, arg, i + 1);
- }
- }
- arg = p;
- }
- return 0;
-}
-
-static int
-dskread(void *buf, unsigned lba, unsigned nblk)
-{
- struct dos_partition *dp;
- struct disklabel *d;
- char *sec;
- unsigned sl, i;
-
- if (!dsk_meta) {
- sec = dmadat->secbuf;
- dsk.start = 0;
- if (drvread(sec, DOSBBSECTOR, 1))
- return -1;
- dp = (void *)(sec + DOSPARTOFF);
- sl = dsk.slice;
- if (sl < BASE_SLICE) {
- for (i = 0; i < NDOSPART; i++)
- if (dp[i].dp_typ == DOSPTYP_386BSD &&
- (dp[i].dp_flag & 0x80 || sl < BASE_SLICE)) {
- sl = BASE_SLICE + i;
- if (dp[i].dp_flag & 0x80 ||
- dsk.slice == COMPATIBILITY_SLICE)
- break;
- }
- if (dsk.slice == WHOLE_DISK_SLICE)
- dsk.slice = sl;
- }
- if (sl != WHOLE_DISK_SLICE) {
- if (sl != COMPATIBILITY_SLICE)
- dp += sl - BASE_SLICE;
- if (dp->dp_typ != DOSPTYP_386BSD) {
- printf("Invalid %s\n", "slice");
- return -1;
- }
- dsk.start = dp->dp_start;
- }
- if (drvread(sec, dsk.start + LABELSECTOR, 1))
- return -1;
- d = (void *)(sec + LABELOFFSET);
- if (d->d_magic != DISKMAGIC || d->d_magic2 != DISKMAGIC) {
- if (dsk.part != RAW_PART) {
- printf("Invalid %s\n", "label");
- return -1;
- }
- } else {
- if (!dsk.init) {
- if (d->d_type == DTYPE_SCSI)
- dsk.type = TYPE_DA;
- dsk.init++;
- }
- if (dsk.part >= d->d_npartitions ||
- !d->d_partitions[dsk.part].p_size) {
- printf("Invalid %s\n", "partition");
- return -1;
- }
- dsk.start += d->d_partitions[dsk.part].p_offset;
- dsk.start -= d->d_partitions[RAW_PART].p_offset;
- }
- }
- return drvread(buf, dsk.start + lba, nblk);
-}
-
-static void
-printf(const char *fmt,...)
-{
- va_list ap;
- char buf[10];
- char *s;
- unsigned u;
- int c;
-
- va_start(ap, fmt);
- while ((c = *fmt++)) {
- if (c == '%') {
- c = *fmt++;
- switch (c) {
- case 'c':
- putchar(va_arg(ap, int));
- continue;
- case 's':
- for (s = va_arg(ap, char *); *s; s++)
- putchar(*s);
- continue;
- case 'u':
- u = va_arg(ap, unsigned);
- s = buf;
- do
- *s++ = '0' + u % 10U;
- while (u /= 10U);
- while (--s >= buf)
- putchar(*s);
- continue;
- }
- }
- putchar(c);
- }
- va_end(ap);
- return;
-}
-
-static void
-putchar(int c)
-{
- if (c == '\n')
- xputc('\r');
- xputc(c);
-}
-
-static int
-drvread(void *buf, unsigned lba, unsigned nblk)
-{
- static unsigned c = 0x2d5c7c2f;
-
- printf("%c\b", c = c << 8 | c >> 24);
- v86.ctl = V86_ADDR | V86_CALLF | V86_FLAGS;
- v86.addr = XREADORG; /* call to xread in boot1 */
- v86.es = VTOPSEG(buf);
- v86.eax = lba;
- v86.ebx = VTOPOFF(buf);
- v86.ecx = lba >> 16;
- v86.edx = nblk << 8 | dsk.drive;
- v86int();
- v86.ctl = V86_FLAGS;
- if (V86_CY(v86.efl)) {
- printf("error %u lba %u\n", v86.eax >> 8 & 0xff, lba);
- return -1;
- }
- return 0;
-}
-
-static int
-keyhit(unsigned ticks)
-{
- uint32_t t0, t1;
-
- if (opts & 1 << RBX_NOINTR)
- return 0;
- t0 = 0;
- for (;;) {
- if (xgetc(1))
- return 1;
- t1 = *(uint32_t *)PTOV(0x46c);
- if (!t0)
- t0 = t1;
- if (t1 < t0 || t1 >= t0 + ticks)
- return 0;
- }
-}
-
-static int
-xputc(int c)
-{
- if (ioctrl & IO_KEYBOARD)
- putc(c);
- if (ioctrl & IO_SERIAL)
- sio_putc(c);
- return c;
-}
-
-static int
-xgetc(int fn)
-{
- if (opts & 1 << RBX_NOINTR)
- return 0;
- for (;;) {
- if (ioctrl & IO_KEYBOARD && getc(1))
- return fn ? 1 : getc(0);
- if (ioctrl & IO_SERIAL && sio_ischar())
- return fn ? 1 : sio_getc();
- if (fn)
- return 0;
- }
-}
-
-static int
-getc(int fn)
-{
- v86.addr = 0x16;
- v86.eax = fn << 8;
- v86int();
- return fn == 0 ? v86.eax & 0xff : !V86_ZR(v86.efl);
-}
diff --git a/sys/boot/i386/pxeldr/pxeldr.S b/sys/boot/i386/pxeldr/pxeldr.S
deleted file mode 100644
index 05383e0c0206..000000000000
--- a/sys/boot/i386/pxeldr/pxeldr.S
+++ /dev/null
@@ -1,282 +0,0 @@
-#
-# Copyright (c) 2000 John Baldwin
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms are freely
-# permitted provided that the above copyright notice and this
-# paragraph and the following disclaimer are duplicated in all
-# such forms.
-#
-# This software is provided "AS IS" and without any express or
-# implied warranties, including, without limitation, the implied
-# warranties of merchantability and fitness for a particular
-# purpose.
-#
-
-# $FreeBSD$
-
-#
-# This simple program is a preloader for the normal boot3 loader. It is simply
-# prepended to the beginning of a fully built and btxld'd loader. It then
-# copies the loader to the address boot2 normally loads it, emulates the
-# boot[12] environment (protected mode, a bootinfo struct, etc.), and then jumps
-# to the start of btxldr to start the boot process. This method allows a stock
-# /boot/loader to be booted over the network via PXE w/o having to write a
-# separate PXE-aware client just to load the loader.
-#
-
-#
-# Memory locations.
-#
- .set MEM_PAGE_SIZE,0x1000 # memory page size, 4k
- .set MEM_ARG,0x900 # Arguments at start
- .set MEM_ARG_BTX,0xa100 # Where we move them to so the
- # BTX client can see them
- .set MEM_ARG_SIZE,0x18 # Size of the arguments
- .set MEM_BTX_ADDRESS,0x9000 # where BTX lives
- .set MEM_BTX_ENTRY,0x9010 # where BTX starts to execute
- .set MEM_BTX_OFFSET,MEM_PAGE_SIZE # offset of BTX in the loader
- .set MEM_BTX_CLIENT,0xa000 # where BTX clients live
- .set MEM_BIOS_KEYBOARD,0x496 # BDA byte with keyboard bit
-#
-# a.out header fields
-#
- .set AOUT_TEXT,0x04 # text segment size
- .set AOUT_DATA,0x08 # data segment size
- .set AOUT_BSS,0x0c # zero'd BSS size
- .set AOUT_SYMBOLS,0x10 # symbol table
- .set AOUT_ENTRY,0x14 # entry point
- .set AOUT_HEADER,MEM_PAGE_SIZE # size of the a.out header
-#
-# Flags for kargs->bootflags
-#
- .set KARGS_FLAGS_PXE,0x2 # flag to indicate booting from
- # PXE loader
-#
-# Boot howto bits
-#
- .set RB_SERIAL,0x1000 # serial console
-#
-# Segment selectors.
-#
- .set SEL_SDATA,0x8 # Supervisor data
- .set SEL_RDATA,0x10 # Real mode data
- .set SEL_SCODE,0x18 # PM-32 code
- .set SEL_SCODE16,0x20 # PM-16 code
-#
-# BTX constants
-#
- .set INT_SYS,0x30 # BTX syscall interrupt
-#
-# Bit in MEM_BIOS_KEYBOARD that is set if an enhanced keyboard is present
-#
- .set KEYBOARD_BIT,0x10
-#
-# We expect to be loaded by the BIOS at 0x7c00 (standard boot loader entry
-# point)
-#
- .code16
- .globl start
- .org 0x0, 0x0
-#
-# BTX program loader for PXE network booting
-#
-start: cld # string ops inc
- xorw %ax, %ax # zero %ax
- movw %ax, %ss # setup the
- movw $start, %sp # stack
- movw %es, %cx # save PXENV+ segment
- movw %ax, %ds # setup the
- movw %ax, %es # data segments
- andl $0xffff, %ecx # clear upper words
- andl $0xffff, %ebx # of %ebx and %ecx
- shll $4, %ecx # calculate the offset of
- addl %ebx, %ecx # the PXENV+ struct and
- pushl %ecx # save it on the stack
- movw $welcome_msg, %si # %ds:(%si) -> welcome message
- callw putstr # display the welcome message
-#
-# Setup the arguments that the loader is expecting from boot[12]
-#
- movw $bootinfo_msg, %si # %ds:(%si) -> boot args message
- callw putstr # display the message
- movw $MEM_ARG, %bx # %ds:(%bx) -> boot args
- movw %bx, %di # %es:(%di) -> boot args
- xorl %eax, %eax # zero %eax
- movw $(MEM_ARG_SIZE/4), %cx # Size of arguments in 32-bit
- # dwords
- rep # Clear the arguments
- stosl # to zero
- orb $KARGS_FLAGS_PXE, 0x8(%bx) # kargs->bootflags |=
- # KARGS_FLAGS_PXE
- popl 0xc(%bx) # kargs->pxeinfo = *PXENV+
-ifdef(`PROBE_KEYBOARD',`
-#
-# Look at the BIOS data area to see if we have an enhanced keyboard. If not,
-# set the RBX_SERIAL bit in the howto byte.
- testb $KEYBOARD_BIT, MEM_BIOS_KEYBOARD # keyboard present?
- jnz keyb # yes, so skip
- orl $RB_SERIAL, (%bx) # enable serial console
-keyb:
-')
-#
-# Turn on the A20 address line
-#
- callw seta20 # Turn A20 on
-#
-# Relocate the loader and BTX using a very lazy protected mode
-#
- movw $relocate_msg, %si # Display the
- callw putstr # relocation message
- movl end+AOUT_ENTRY, %edi # %edi is the destination
- movl $(end+AOUT_HEADER), %esi # %esi is
- # the start of the text
- # segment
- movl end+AOUT_TEXT, %ecx # %ecx = length of the text
- # segment
- lgdt gdtdesc # setup our own gdt
- cli # turn off interrupts
- movl %cr0, %eax # Turn on
- orb $0x1, %al # protected
- movl %eax, %cr0 # mode
- ljmp $SEL_SCODE,$pm_start # long jump to clear the
- # instruction pre-fetch queue
- .code32
-pm_start: movw $SEL_SDATA, %ax # Initialize
- movw %ax, %ds # %ds and
- movw %ax, %es # %es to a flat selector
- rep # Relocate the
- movsb # text segment
- addl $(MEM_PAGE_SIZE - 1), %edi # pad %edi out to a new page
- andl $~(MEM_PAGE_SIZE - 1), %edi # for the data segment
- movl end+AOUT_DATA, %ecx # size of the data segment
- rep # Relocate the
- movsb # data segment
- movl end+AOUT_BSS, %ecx # size of the bss
- xorl %eax, %eax # zero %eax
- addb $3, %cl # round %ecx up to
- shrl $2, %ecx # a multiple of 4
- rep # zero the
- stosl # bss
- movl end+AOUT_ENTRY, %esi # %esi -> relocated loader
- addl $MEM_BTX_OFFSET, %esi # %esi -> BTX in the loader
- movl $MEM_BTX_ADDRESS, %edi # %edi -> where BTX needs to go
- movzwl 0xa(%esi), %ecx # %ecx -> length of BTX
- rep # Relocate
- movsb # BTX
- ljmp $SEL_SCODE16,$pm_16 # Jump to 16-bit PM
- .code16
-pm_16: movw $SEL_RDATA, %ax # Initialize
- movw %ax, %ds # %ds and
- movw %ax, %es # %es to a real mode selector
- movl %cr0, %eax # Turn off
- andb $~0x1, %al # protected
- movl %eax, %cr0 # mode
- ljmp $0,$pm_end # Long jump to clear the
- # instruction pre-fetch queue
-pm_end: sti # Turn interrupts back on now
-#
-# Copy the BTX client to MEM_BTX_CLIENT
-#
- xorw %ax, %ax # zero %ax and set
- movw %ax, %ds # %ds and %es
- movw %ax, %es # to segment 0
- movw $MEM_BTX_CLIENT, %di # Prepare to relocate
- movw $btx_client, %si # the simple btx client
- movw $(btx_client_end-btx_client), %cx # length of btx client
- rep # Relocate the
- movsb # simple BTX client
-#
-# Copy the boot[12] args to where the BTX client can see them
-#
- movw $MEM_ARG, %si # where the args are at now
- movw $MEM_ARG_BTX, %di # where the args are moving to
- movw $(MEM_ARG_SIZE/4), %cx # size of the arguments in longs
- rep # Relocate
- movsl # the words
-#
-# Save the entry point so the client can get to it later on
-#
- movl end+AOUT_ENTRY, %eax # load the entry point
- stosl # add it to the end of the
- # arguments
-#
-# Now we just start up BTX and let it do the rest
-#
- movw $jump_message, %si # Display the
- callw putstr # jump message
- ljmp $0,$MEM_BTX_ENTRY # Jump to the BTX entry point
-
-#
-# Display a null-terminated string
-#
-putstr: lodsb # load %al from %ds:(%si)
- testb %al,%al # stop at null
- jnz putc # if the char != null, output it
- retw # return when null is hit
-putc: movw $0x7,%bx # attribute for output
- movb $0xe,%ah # BIOS: put_char
- int $0x10 # call BIOS, print char in %al
- jmp putstr # keep looping
-
-#
-# Enable A20
-#
-seta20: cli # Disable interrupts
-seta20.1: inb $0x64,%al # Get status
- testb $0x2,%al # Busy?
- jnz seta20.1 # Yes
- movb $0xd1,%al # Command: Write
- outb %al,$0x64 # output port
-seta20.2: inb $0x64,%al # Get status
- testb $0x2,%al # Busy?
- jnz seta20.2 # Yes
- movb $0xdf,%al # Enable
- outb %al,$0x60 # A20
- sti # Enable interrupts
- retw # To caller
-
-#
-# BTX client to start btxldr
-#
- .code32
-btx_client: movl $(MEM_ARG_BTX-MEM_BTX_CLIENT+MEM_ARG_SIZE-4), %esi
- # %ds:(%esi) -> end
- # of boot[12] args
- movl $(MEM_ARG_SIZE/4), %ecx # Number of words to push
- std # Go backwards
-push_arg: lodsl # Read argument
- pushl %eax # Push it onto the stack
- loop push_arg # Push all of the arguments
- cld # In case anyone depends on this
- pushl MEM_ARG_BTX-MEM_BTX_CLIENT+MEM_ARG_SIZE # Entry point of
- # the loader
- pushl %eax # Emulate a near call
- movl $0x1, %eax # 'exec' system call
- int $INT_SYS # BTX system call
-btx_client_end:
- .code16
-
- .p2align 4
-#
-# Global descriptor table.
-#
-gdt: .word 0x0,0x0,0x0,0x0 # Null entry
- .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA
- .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA
- .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE (32-bit)
- .word 0xffff,0x0,0x9a00,0x8f # SEL_SCODE16 (16-bit)
-gdt.1:
-#
-# Pseudo-descriptors.
-#
-gdtdesc: .word gdt.1-gdt-1 # Limit
- .long gdt # Base
-
-welcome_msg: .asciz "PXE Loader 1.00\r\n\n"
-bootinfo_msg: .asciz "Building the boot loader arguments\r\n"
-relocate_msg: .asciz "Relocating the loader and the BTX\r\n"
-jump_message: .asciz "Starting the BTX loader\r\n"
-
- .p2align 4
-end:
diff --git a/sys/boot/ia64/common/bootinfo.c b/sys/boot/ia64/common/bootinfo.c
deleted file mode 100644
index 076aed169b5b..000000000000
--- a/sys/boot/ia64/common/bootinfo.c
+++ /dev/null
@@ -1,348 +0,0 @@
-/*-
- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <stand.h>
-#include <string.h>
-#include <sys/param.h>
-#include <sys/reboot.h>
-#include <sys/linker.h>
-#include <machine/elf.h>
-#include <machine/bootinfo.h>
-
-#include <efi.h>
-#include <efilib.h>
-
-#include "bootstrap.h"
-
-static EFI_GUID hcdp = HCDP_TABLE_GUID;
-
-/*
- * Return a 'boothowto' value corresponding to the kernel arguments in
- * (kargs) and any relevant environment variables.
- */
-static struct
-{
- const char *ev;
- int mask;
-} howto_names[] = {
- {"boot_askname", RB_ASKNAME},
- {"boot_cdrom", RB_CDROM},
- {"boot_userconfig", RB_CONFIG},
- {"boot_ddb", RB_KDB},
- {"boot_gdb", RB_GDB},
- {"boot_single", RB_SINGLE},
- {"boot_verbose", RB_VERBOSE},
- {"boot_multicons", RB_MULTIPLE},
- {"boot_serial", RB_SERIAL},
- {NULL, 0}
-};
-
-extern char *efi_fmtdev(void *vdev);
-
-int
-bi_getboothowto(char *kargs)
-{
- char *cp;
- int howto;
- int active;
- int i;
-
- /* Parse kargs */
- howto = 0;
- if (kargs != NULL) {
- cp = kargs;
- active = 0;
- while (*cp != 0) {
- if (!active && (*cp == '-')) {
- active = 1;
- } else if (active)
- switch (*cp) {
- case 'a':
- howto |= RB_ASKNAME;
- break;
- case 'c':
- howto |= RB_CONFIG;
- break;
- case 'C':
- howto |= RB_CDROM;
- break;
- case 'd':
- howto |= RB_KDB;
- break;
- case 'D':
- howto |= RB_MULTIPLE;
- break;
- case 'm':
- howto |= RB_MUTE;
- break;
- case 'g':
- howto |= RB_GDB;
- break;
- case 'h':
- howto |= RB_SERIAL;
- break;
- case 'r':
- howto |= RB_DFLTROOT;
- break;
- case 's':
- howto |= RB_SINGLE;
- break;
- case 'v':
- howto |= RB_VERBOSE;
- break;
- default:
- active = 0;
- break;
- }
- cp++;
- }
- }
- /* get equivalents from the environment */
- for (i = 0; howto_names[i].ev != NULL; i++)
- if (getenv(howto_names[i].ev) != NULL)
- howto |= howto_names[i].mask;
- if (!strcmp(getenv("console"), "comconsole"))
- howto |= RB_SERIAL;
- if (!strcmp(getenv("console"), "nullconsole"))
- howto |= RB_MUTE;
- return(howto);
-}
-
-/*
- * Copy the environment into the load area starting at (addr).
- * Each variable is formatted as <name>=<value>, with a single nul
- * separating each variable, and a double nul terminating the environment.
- */
-vm_offset_t
-bi_copyenv(vm_offset_t addr)
-{
- struct env_var *ep;
-
- /* traverse the environment */
- for (ep = environ; ep != NULL; ep = ep->ev_next) {
- efi_copyin(ep->ev_name, addr, strlen(ep->ev_name));
- addr += strlen(ep->ev_name);
- efi_copyin("=", addr, 1);
- addr++;
- if (ep->ev_value != NULL) {
- efi_copyin(ep->ev_value, addr, strlen(ep->ev_value));
- addr += strlen(ep->ev_value);
- }
- efi_copyin("", addr, 1);
- addr++;
- }
- efi_copyin("", addr, 1);
- addr++;
- return(addr);
-}
-
-/*
- * Copy module-related data into the load area, where it can be
- * used as a directory for loaded modules.
- *
- * Module data is presented in a self-describing format. Each datum
- * is preceded by a 32-bit identifier and a 32-bit size field.
- *
- * Currently, the following data are saved:
- *
- * MOD_NAME (variable) module name (string)
- * MOD_TYPE (variable) module type (string)
- * MOD_ARGS (variable) module parameters (string)
- * MOD_ADDR sizeof(vm_offset_t) module load address
- * MOD_SIZE sizeof(size_t) module size
- * MOD_METADATA (variable) type-specific metadata
- */
-#define COPY32(v, a) { \
- u_int32_t x = (v); \
- efi_copyin(&x, a, sizeof(x)); \
- a += sizeof(x); \
-}
-
-#define MOD_STR(t, a, s) { \
- COPY32(t, a); \
- COPY32(strlen(s) + 1, a); \
- efi_copyin(s, a, strlen(s) + 1); \
- a += roundup(strlen(s) + 1, sizeof(u_int64_t));\
-}
-
-#define MOD_NAME(a, s) MOD_STR(MODINFO_NAME, a, s)
-#define MOD_TYPE(a, s) MOD_STR(MODINFO_TYPE, a, s)
-#define MOD_ARGS(a, s) MOD_STR(MODINFO_ARGS, a, s)
-
-#define MOD_VAR(t, a, s) { \
- COPY32(t, a); \
- COPY32(sizeof(s), a); \
- efi_copyin(&s, a, sizeof(s)); \
- a += roundup(sizeof(s), sizeof(u_int64_t)); \
-}
-
-#define MOD_ADDR(a, s) MOD_VAR(MODINFO_ADDR, a, s)
-#define MOD_SIZE(a, s) MOD_VAR(MODINFO_SIZE, a, s)
-
-#define MOD_METADATA(a, mm) { \
- COPY32(MODINFO_METADATA | mm->md_type, a); \
- COPY32(mm->md_size, a); \
- efi_copyin(mm->md_data, a, mm->md_size); \
- a += roundup(mm->md_size, sizeof(u_int64_t));\
-}
-
-#define MOD_END(a) { \
- COPY32(MODINFO_END, a); \
- COPY32(0, a); \
-}
-
-vm_offset_t
-bi_copymodules(vm_offset_t addr)
-{
- struct preloaded_file *fp;
- struct file_metadata *md;
-
- /* start with the first module on the list, should be the kernel */
- for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
-
- MOD_NAME(addr, fp->f_name); /* this field must come first */
- MOD_TYPE(addr, fp->f_type);
- if (fp->f_args)
- MOD_ARGS(addr, fp->f_args);
- MOD_ADDR(addr, fp->f_addr);
- MOD_SIZE(addr, fp->f_size);
- for (md = fp->f_metadata; md != NULL; md = md->md_next)
- if (!(md->md_type & MODINFOMD_NOCOPY))
- MOD_METADATA(addr, md);
- }
- MOD_END(addr);
- return(addr);
-}
-
-/*
- * Load the information expected by an alpha kernel.
- *
- * - The kernel environment is copied into kernel space.
- * - Module metadata are formatted and placed in kernel space.
- */
-int
-bi_load(struct bootinfo *bi, struct preloaded_file *fp, UINTN *mapkey,
- UINTN pages)
-{
- char *rootdevname;
- struct efi_devdesc *rootdev;
- struct preloaded_file *xp;
- vm_offset_t addr, bootinfo_addr;
- vm_offset_t ssym, esym;
- struct file_metadata *md;
- EFI_STATUS status;
- UINTN bisz, key;
-
- /*
- * Version 1 bootinfo.
- */
- bi->bi_magic = BOOTINFO_MAGIC;
- bi->bi_version = 1;
-
- /*
- * Calculate boothowto.
- */
- bi->bi_boothowto = bi_getboothowto(fp->f_args);
-
- /*
- * Stash EFI System Table.
- */
- bi->bi_systab = (u_int64_t) ST;
-
- /*
- * Allow the environment variable 'rootdev' to override the supplied
- * device. This should perhaps go to MI code and/or have $rootdev
- * tested/set by MI code before launching the kernel.
- */
- rootdevname = getenv("rootdev");
- efi_getdev((void **)(&rootdev), rootdevname, NULL);
- if (rootdev == NULL) { /* bad $rootdev/$currdev */
- printf("can't determine root device\n");
- return(EINVAL);
- }
-
- /* Try reading the /etc/fstab file to select the root device */
- getrootmount(efi_fmtdev((void *)rootdev));
- free(rootdev);
-
- ssym = esym = 0;
- if ((md = file_findmetadata(fp, MODINFOMD_SSYM)) != NULL)
- ssym = *((vm_offset_t *)&(md->md_data));
- if ((md = file_findmetadata(fp, MODINFOMD_ESYM)) != NULL)
- esym = *((vm_offset_t *)&(md->md_data));
- if (ssym == 0 || esym == 0)
- ssym = esym = 0; /* sanity */
-
- bi->bi_symtab = ssym;
- bi->bi_esymtab = esym;
-
- bi->bi_hcdp = (uint64_t)efi_get_table(&hcdp); /* DIG64 HCDP table addr. */
- fpswa_init(&bi->bi_fpswa); /* find FPSWA interface */
-
- /* find the last module in the chain */
- addr = 0;
- for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
- if (addr < (xp->f_addr + xp->f_size))
- addr = xp->f_addr + xp->f_size;
- }
-
- /* pad to a page boundary */
- addr = (addr + PAGE_MASK) & ~PAGE_MASK;
-
- /* copy our environment */
- bi->bi_envp = addr;
- addr = bi_copyenv(addr);
-
- /* pad to a page boundary */
- addr = (addr + PAGE_MASK) & ~PAGE_MASK;
-
- /* copy module list and metadata */
- bi->bi_modulep = addr;
- addr = bi_copymodules(addr);
-
- /* all done copying stuff in, save end of loaded object space */
- bi->bi_kernend = addr;
-
- /*
- * Read the memory map and stash it after bootinfo. Align the memory map
- * on a 16-byte boundary (the bootinfo block is page aligned).
- */
- bisz = (sizeof(struct bootinfo) + 0x0f) & ~0x0f;
- bi->bi_memmap = ((u_int64_t)bi) + bisz;
- bi->bi_memmap_size = EFI_PAGE_SIZE * pages - bisz;
- status = BS->GetMemoryMap(&bi->bi_memmap_size,
- (EFI_MEMORY_DESCRIPTOR *)bi->bi_memmap, &key,
- &bi->bi_memdesc_size, &bi->bi_memdesc_version);
- if (EFI_ERROR(status)) {
- printf("bi_load: Can't read memory map\n");
- return EINVAL;
- }
- *mapkey = key;
-
- return(0);
-}
diff --git a/sys/boot/ia64/common/copy.c b/sys/boot/ia64/common/copy.c
deleted file mode 100644
index 7bc4edf7e15c..000000000000
--- a/sys/boot/ia64/common/copy.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*-
- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * MD primitives supporting placement of module data
- */
-#include <stand.h>
-
-#include <efi.h>
-#include <efilib.h>
-#include <machine/ia64_cpu.h>
-#include <machine/vmparam.h>
-
-int
-efi_copyin(void *src, vm_offset_t dest, size_t len)
-{
- EFI_PHYSICAL_ADDRESS p = IA64_RR_MASK(dest);
-#if 0
- BS->AllocatePages(AllocateAddress, EfiRuntimeServicesData,
- len >> 12, &p);
-#endif
- bcopy(src, (void*) p, len);
- return (len);
-}
-
-int
-efi_copyout(vm_offset_t src, void *dest, size_t len)
-{
- bcopy((void*) IA64_RR_MASK(src), dest, len);
- return (len);
-}
-
-int
-efi_readin(int fd, vm_offset_t dest, size_t len)
-{
- EFI_PHYSICAL_ADDRESS p = IA64_RR_MASK(dest);
-#if 0
- BS->AllocatePages(AllocateAddress, EfiRuntimeServicesData,
- len >> 12, &p);
-#endif
- return (read(fd, (void*) p, len));
-}
diff --git a/sys/boot/ia64/common/devicename.c b/sys/boot/ia64/common/devicename.c
deleted file mode 100644
index dda2fb0fdb3a..000000000000
--- a/sys/boot/ia64/common/devicename.c
+++ /dev/null
@@ -1,240 +0,0 @@
-/*-
- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <stand.h>
-#include <string.h>
-#include <sys/disklabel.h>
-#include "bootstrap.h"
-
-#include <efi.h>
-#include <efilib.h>
-#include "efiboot.h"
-
-static int efi_parsedev(struct efi_devdesc **dev, const char *devspec, const char **path);
-
-/*
- * Point (dev) at an allocated device specifier for the device matching the
- * path in (devspec). If it contains an explicit device specification,
- * use that. If not, use the default device.
- */
-int
-efi_getdev(void **vdev, const char *devspec, const char **path)
-{
- struct efi_devdesc **dev = (struct efi_devdesc **)vdev;
- int rv;
-
- /*
- * If it looks like this is just a path and no
- * device, go with the current device.
- */
- if ((devspec == NULL) ||
- (devspec[0] == '/') ||
- (strchr(devspec, ':') == NULL)) {
-
- if (((rv = efi_parsedev(dev, getenv("currdev"), NULL)) == 0) &&
- (path != NULL))
- *path = devspec;
- return(rv);
- }
-
- /*
- * Try to parse the device name off the beginning of the devspec
- */
- return(efi_parsedev(dev, devspec, path));
-}
-
-/*
- * Point (dev) at an allocated device specifier matching the string version
- * at the beginning of (devspec). Return a pointer to the remaining
- * text in (path).
- *
- * In all cases, the beginning of (devspec) is compared to the names
- * of known devices in the device switch, and then any following text
- * is parsed according to the rules applied to the device type.
- *
- * For disk-type devices, the syntax is:
- *
- * disk<unit>[s<slice>][<partition>]:
- *
- */
-static int
-efi_parsedev(struct efi_devdesc **dev, const char *devspec, const char **path)
-{
- struct efi_devdesc *idev;
- struct devsw *dv;
- int i, unit, slice, partition, err;
- char *cp;
- const char *np;
-
- /* minimum length check */
- if (strlen(devspec) < 2)
- return(EINVAL);
-
- /* look for a device that matches */
- for (i = 0, dv = NULL; devsw[i] != NULL; i++) {
- if (!strncmp(devspec, devsw[i]->dv_name, strlen(devsw[i]->dv_name))) {
- dv = devsw[i];
- break;
- }
- }
-
- if (dv == NULL)
- return(ENOENT);
- idev = malloc(sizeof(struct efi_devdesc));
- err = 0;
- np = (devspec + strlen(dv->dv_name));
-
- switch(dv->dv_type) {
- case DEVT_NONE: /* XXX what to do here? Do we care? */
- break;
-
- case DEVT_DISK:
- unit = -1;
- slice = -1;
- partition = -1;
- if (*np && (*np != ':')) {
- unit = strtol(np, &cp, 10); /* next comes the unit number */
- if (cp == np) {
- err = EUNIT;
- goto fail;
- }
- if (*cp == 's') { /* got a slice number */
- np = cp + 1;
- slice = strtol(np, &cp, 10);
- if (cp == np) {
- err = ESLICE;
- goto fail;
- }
- }
- if (*cp && (*cp != ':')) {
- partition = *cp - 'a'; /* get a partition number */
- if ((partition < 0) || (partition >= MAXPARTITIONS)) {
- err = EPART;
- goto fail;
- }
- cp++;
- }
- }
- if (*cp && (*cp != ':')) {
- err = EINVAL;
- goto fail;
- }
-
- idev->d_kind.efidisk.unit = unit;
- idev->d_kind.efidisk.slice = slice;
- idev->d_kind.efidisk.partition = partition;
-
- if (path != NULL)
- *path = (*cp == 0) ? cp : cp + 1;
- break;
-
- case DEVT_NET:
- unit = 0;
-
- if (*np && (*np != ':')) {
- unit = strtol(np, &cp, 0); /* get unit number if present */
- if (cp == np) {
- err = EUNIT;
- goto fail;
- }
- }
- if (*cp && (*cp != ':')) {
- err = EINVAL;
- goto fail;
- }
-
- idev->d_kind.netif.unit = unit;
- if (path != NULL)
- *path = (*cp == 0) ? cp : cp + 1;
- break;
-
- default:
- err = EINVAL;
- goto fail;
- }
- idev->d_dev = dv;
- idev->d_type = dv->dv_type;
- if (dev == NULL) {
- free(idev);
- } else {
- *dev = idev;
- }
- return(0);
-
- fail:
- free(idev);
- return(err);
-}
-
-
-char *
-efi_fmtdev(void *vdev)
-{
- struct efi_devdesc *dev = (struct efi_devdesc *)vdev;
- static char buf[128]; /* XXX device length constant? */
- char *cp;
-
- switch(dev->d_type) {
- case DEVT_NONE:
- strcpy(buf, "(no device)");
- break;
-
- case DEVT_DISK:
- cp = buf;
- cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_kind.efidisk.unit);
- if (dev->d_kind.efidisk.slice > 0)
- cp += sprintf(cp, "s%d", dev->d_kind.efidisk.slice);
- if (dev->d_kind.efidisk.partition >= 0)
- cp += sprintf(cp, "%c", dev->d_kind.efidisk.partition + 'a');
- strcat(cp, ":");
- break;
-
- case DEVT_NET:
- sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_kind.netif.unit);
- break;
- }
- return(buf);
-}
-
-
-/*
- * Set currdev to suit the value being supplied in (value)
- */
-int
-efi_setcurrdev(struct env_var *ev, int flags, void *value)
-{
- struct efi_devdesc *ncurr;
- int rv;
-
- if ((rv = efi_parsedev(&ncurr, value, NULL)) != 0)
- return(rv);
- free(ncurr);
- env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
- return(0);
-}
-
diff --git a/sys/boot/ia64/common/exec.c b/sys/boot/ia64/common/exec.c
deleted file mode 100644
index 27d2b6e08568..000000000000
--- a/sys/boot/ia64/common/exec.c
+++ /dev/null
@@ -1,223 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD: loadfile.c,v 1.10 1998/06/25 06:45:46 ross Exp $ */
-
-/*-
- * Copyright (c) 1997 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
- * NASA Ames Research Center.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Ralph Campbell.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)boot.c 8.1 (Berkeley) 6/10/93
- */
-
-#include <stand.h>
-#include <string.h>
-
-#include <sys/param.h>
-#include <sys/linker.h>
-#include <machine/elf.h>
-#include <machine/bootinfo.h>
-#include <machine/ia64_cpu.h>
-#include <machine/pte.h>
-#include <machine/vmparam.h>
-
-#include <efi.h>
-#include <efilib.h>
-
-#include "bootstrap.h"
-
-#define _KERNEL
-
-static int elf64_exec(struct preloaded_file *amp);
-
-struct file_format ia64_elf = { elf64_loadfile, elf64_exec };
-
-static __inline u_int64_t
-disable_ic()
-{
- u_int64_t psr;
- __asm __volatile("mov %0=psr;;" : "=r" (psr));
- __asm __volatile("rsm psr.ic|psr.i;; srlz.i;;");
- return psr;
-}
-
-static __inline void
-restore_ic(u_int64_t psr)
-{
- __asm __volatile("mov psr.l=%0;; srlz.i" :: "r" (psr));
-}
-
-/*
- * Entered with psr.ic and psr.i both zero.
- */
-void
-enter_kernel(u_int64_t start, struct bootinfo *bi)
-{
- u_int64_t psr;
-
- __asm __volatile("srlz.i;;");
- __asm __volatile("mov cr.ipsr=%0"
- :: "r"(IA64_PSR_IC
- | IA64_PSR_DT
- | IA64_PSR_RT
- | IA64_PSR_IT
- | IA64_PSR_BN));
- __asm __volatile("mov cr.iip=%0" :: "r"(start));
- __asm __volatile("mov cr.ifs=r0;;");
- __asm __volatile("mov ar.rsc=0;; flushrs;;");
- __asm __volatile("mov r8=%0" :: "r" (bi));
- __asm __volatile("rfi;;");
-}
-
-static int
-elf64_exec(struct preloaded_file *fp)
-{
- struct file_metadata *md;
- Elf_Ehdr *hdr;
- struct ia64_pte pte;
- struct bootinfo *bi;
- u_int64_t psr;
- UINTN mapkey, pages, size;
- UINTN descsz;
- UINT32 descver;
- EFI_STATUS status;
-
- if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)
- return(EFTYPE); /* XXX actually EFUCKUP */
- hdr = (Elf_Ehdr *)&(md->md_data);
-
- /*
- * Allocate enough pages to hold the bootinfo block and the memory
- * map EFI will return to us. The memory map has an unknown size,
- * so we have to determine that first. Note that the AllocatePages
- * call can itself modify the memory map, so we have to take that
- * into account as well. The changes to the memory map are caused
- * by splitting a range of free memory into two (AFAICT), so that
- * one is marked as being loader data.
- */
- size = 0;
- descsz = sizeof(EFI_MEMORY_DESCRIPTOR);
- BS->GetMemoryMap(&size, NULL, &mapkey, &descsz, &descver);
- size += descsz + ((sizeof(struct bootinfo) + 0x0f) & ~0x0f);
- pages = EFI_SIZE_TO_PAGES(size);
- status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData, pages,
- (void*)&bi);
- if (EFI_ERROR(status)) {
- printf("unable to create bootinfo block (status=0x%lx)\n",
- (long)status);
- return (ENOMEM);
- }
-
- bzero(bi, sizeof(struct bootinfo));
- bi_load(bi, fp, &mapkey, pages);
-
- printf("Entering %s at 0x%lx...\n", fp->f_name, hdr->e_entry);
-
- status = BS->ExitBootServices(IH, mapkey);
- if (EFI_ERROR(status)) {
- printf("ExitBootServices returned 0x%lx\n", status);
- return (EINVAL);
- }
-
- psr = disable_ic();
-
- /*
- * Region 6 is direct mapped UC and region 7 is direct mapped
- * WC. The details of this is controlled by the Alt {I,D}TLB
- * handlers. Here we just make sure that they have the largest
- * possible page size to minimise TLB usage.
- */
- ia64_set_rr(IA64_RR_BASE(6), (6 << 8) | (28 << 2));
- ia64_set_rr(IA64_RR_BASE(7), (7 << 8) | (28 << 2));
-
- bzero(&pte, sizeof(pte));
- pte.pte_p = 1;
- pte.pte_ma = PTE_MA_WB;
- pte.pte_a = 1;
- pte.pte_d = 1;
- pte.pte_pl = PTE_PL_KERN;
- pte.pte_ar = PTE_AR_RWX;
- pte.pte_ppn = 0;
-
- __asm __volatile("mov cr.ifa=%0" :: "r"(IA64_RR_BASE(7)));
- __asm __volatile("mov cr.itir=%0" :: "r"(28 << 2));
- __asm __volatile("ptr.i %0,%1" :: "r"(IA64_RR_BASE(7)), "r"(28<<2));
- __asm __volatile("ptr.d %0,%1" :: "r"(IA64_RR_BASE(7)), "r"(28<<2));
- __asm __volatile("srlz.i;;");
- __asm __volatile("itr.i itr[%0]=%1;;"
- :: "r"(0), "r"(*(u_int64_t*)&pte));
- __asm __volatile("srlz.i;;");
- __asm __volatile("itr.d dtr[%0]=%1;;"
- :: "r"(0), "r"(*(u_int64_t*)&pte));
- __asm __volatile("srlz.i;;");
-
- enter_kernel(hdr->e_entry, bi);
-
- restore_ic(psr);
-}
diff --git a/sys/boot/ia64/efi/Makefile b/sys/boot/ia64/efi/Makefile
deleted file mode 100644
index e2f9a84ea786..000000000000
--- a/sys/boot/ia64/efi/Makefile
+++ /dev/null
@@ -1,123 +0,0 @@
-# $FreeBSD$
-
-.PATH: ${.CURDIR}/../common
-
-BASE= loader
-PROG= ${BASE}.efi
-NOMAN=
-NEWVERSWHAT= "EFI boot" ${MACHINE_ARCH}
-BINDIR?= /boot
-STRIP= # We must not strip loader.efi at install time.
-
-SRCS+= main.c conf.c dev_net.c
-
-CFLAGS+= -ffreestanding
-
-.if !defined(NOFORTH)
-# Enable BootForth
-BOOT_FORTH= yes
-CFLAGS+= -DBOOT_FORTH
-CFLAGS+= -I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/${MACHINE_ARCH}
-.if exists(${.OBJDIR}/../../ficl/libficl.a)
-LIBFICL= ${.OBJDIR}/../../ficl/libficl.a
-.else
-LIBFICL= ${.CURDIR}/../../ficl/libficl.a
-.endif
-.endif
-
-# where to get libstand from
-.if exists(${.OBJDIR}/../../../../lib/libstand/libstand.a)
-LIBSTAND= ${.OBJDIR}/../../../../lib/libstand/libstand.a
-.else
-LIBSTAND= ${.CURDIR}/../../../../lib/libstand/libstand.a
-.endif
-
-.if exists(${.OBJDIR}/../libefi/libefi.a)
-LIBEFI= ${.OBJDIR}/../libefi/libefi.a
-.else
-LIBEFI= ${.CURDIR}/../libefi/libefi.a
-.endif
-
-# Always add MI sources
-.PATH: ${.CURDIR}/../../common
-.include <${.CURDIR}/../../common/Makefile.inc>
-
-CFLAGS+= -I-
-CFLAGS+= -I${.CURDIR}/../include
-CFLAGS+= -I${.CURDIR}/../include/${MACHINE_ARCH}
-CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}
-CFLAGS+= -I${.CURDIR}/../../.. -I.
-CFLAGS+= -I${.CURDIR}/../libefi
-CFLAGS+= -I${.CURDIR}/../../../../lib/libstand
-CFLAGS+= -DLOADER
-
-LDSCRIPT= ${.CURDIR}/../libefi/arch/${MACHINE_ARCH}/ldscript.${MACHINE_ARCH}
-LDFLAGS= -nostdlib -T ${LDSCRIPT} -shared -Bsymbolic
-OBJCOPY?= objcopy
-
-CLEANFILES+= setdef0.c setdef0.o setdef1.c setdef1.o setdefs.h start.o \
- vers.c vers.o ${BASE}.efi ${BASE}.sym ${BASE}.list
-CLEANFILES+= loader.help
-CLEANFILES+= machine
-
-CRT= start.o
-
-all: ${BASE}
-
-vers.o: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
- sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT}
- ${CC} -c vers.c
-
-${BASE}: ${BASE}.efi ${BASE}.help
-
-${BASE}.efi: ${BASE}.sym
- ${OBJCOPY} -j .text \
- -j .hash \
- -j .data \
- -j .sdata \
- -j .dynamic \
- -j .rela \
- -j .reloc \
- -j .dynsym \
- -j .dynstr \
- --target=efi-app-${MACHINE_ARCH} \
- ${BASE}.sym ${BASE}.efi
-
-${BASE}.help: help.common
- cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk \
- > ${.TARGET}
-
-beforeinstall:
-.if exists(${.OBJDIR}/loader.help)
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.OBJDIR}/${BASE}.help ${DESTDIR}/boot
-.else
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.CURDIR}/${BASE}.help ${DESTDIR}/boot
-.endif
-.if !exists(${DESTDIR}/boot/loader.rc)
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.CURDIR}/../../forth/loader.rc ${DESTDIR}/boot
-.endif
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.CURDIR}/../../forth/loader.4th ${DESTDIR}/boot
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.CURDIR}/../../forth/support.4th ${DESTDIR}/boot
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.CURDIR}/../../forth/loader.conf ${DESTDIR}/boot/defaults
-
-
-# Other fragments still to be brought in from ../Makfile.booters?
-start.o: ${.CURDIR}/../libefi/arch/${MACHINE_ARCH}/start.S
- ${CC} -c ${CFLAGS} ${.IMPSRC}
-
-machine:
- ln -sf ${.CURDIR}/../../../${MACHINE_ARCH}/include machine
-
-.include <bsd.prog.mk>
-
-${BASE}.sym: ${OBJS} ${LIBFICL} ${LIBEFI} ${LIBSTAND} ${CRT} vers.o
- ${LD} ${LDFLAGS} -o ${BASE}.sym -M ${CRT} ${OBJS} vers.o \
- ${LIBFICL} ${LIBEFI} ${LIBSTAND} > ${.OBJDIR}/${BASE}.list
-
-beforedepend ${OBJS}: machine
diff --git a/sys/boot/ia64/efi/conf.c b/sys/boot/ia64/efi/conf.c
deleted file mode 100644
index 145b16b86115..000000000000
--- a/sys/boot/ia64/efi/conf.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 1997
- * Matthias Drochner. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed for the NetBSD Project
- * by Matthias Drochner.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $NetBSD: conf.c,v 1.2 1997/03/22 09:03:29 thorpej Exp $
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stand.h>
-#include <efi.h>
-#include <efilib.h>
-
-#include "efiboot.h"
-
-/*
- * We could use linker sets for some or all of these, but
- * then we would have to control what ended up linked into
- * the bootstrap. So it's easier to conditionalise things
- * here.
- *
- * XXX rename these arrays to be consistent and less namespace-hostile
- */
-
-/* Exported for libstand */
-struct devsw *devsw[] = {
- &efifs_dev,
- &netdev,
- NULL
-};
-
-struct fs_ops *file_system[] = {
- &efi_fsops,
-/* &ufs_fsops, */
- &nfs_fsops,
- &gzipfs_fsops,
- NULL
-};
-
-struct netif_driver *netif_drivers[] = {
- &efi_net,
- NULL,
-};
-
-/* Exported for ia64 only */
-/*
- * Sort formats so that those that can detect based on arguments
- * rather than reading the file go first.
- */
-extern struct file_format ia64_elf;
-
-struct file_format *file_formats[] = {
- &ia64_elf,
- NULL
-};
-
-/*
- * Consoles
- *
- * We don't prototype these in efiboot.h because they require
- * data structures from bootstrap.h as well.
- */
-extern struct console efi_console;
-
-struct console *consoles[] = {
- &efi_console,
- NULL
-};
diff --git a/sys/boot/ia64/efi/ldscript.ia64 b/sys/boot/ia64/efi/ldscript.ia64
deleted file mode 100644
index aa02808b2f84..000000000000
--- a/sys/boot/ia64/efi/ldscript.ia64
+++ /dev/null
@@ -1,80 +0,0 @@
-/* $FreeBSD$ */
-OUTPUT_FORMAT("elf64-ia64-little", "elf64-ia64-little", "elf64-ia64-little")
-OUTPUT_ARCH(ia64)
-ENTRY(_start_plabel)
-SECTIONS
-{
- /* Read-only sections, merged into text segment: */
- . = 0;
- ImageBase = .;
- . += 4096;
- .text :
- {
- *(.text)
- *(.stub)
- /* .gnu.warning sections are handled specially by elf32.em. */
- *(.gnu.warning)
- *(.gnu.linkonce.t*)
- *(.plt)
- }
- . = ALIGN(4096);
- .hash : { *(.hash) }
- . = ALIGN(4096);
- .data :
- {
- *(.rodata*)
- __start_set_Xcommand_set = .;
- *(set_Xcommand_set)
- __stop_set_Xcommand_set = .;
- *(.ctors)
- *(.data)
- *(.data1)
- *(.gnu.linkonce.d*)
- *(.plabel)
- *(.IA_64.unwind)
- *(.IA_64.unwind_info)
- *(.bss)
- *(.dynbss)
- *(COMMON)
- }
- . = ALIGN(4096);
- __gp = .;
- .sdata :
- {
- *(.got.plt)
- *(.got)
- *(.IA_64.pltoff)
- *(.sdata)
- *(.sbss)
- *(.scommon)
- }
- . = ALIGN(4096);
- .dynamic : { *(.dynamic) }
- . = ALIGN(4096);
- .rela :
- {
- *(.rela.text)
- *(.rela.gnu.linkonce.t*)
- *(.rela.set.*)
- *(.rela.sdata)
- *(.rela.data)
- *(.rela.gnu.linkonce.d*)
- *(.rela.got)
- *(.rela.stab)
- *(.rela.ctors)
- *(.relaset_*)
- *(.rela.IA_64.pltoff)
- }
- . = ALIGN(4096);
- .reloc : { *(.reloc) }
- . = ALIGN(4096);
- .dynsym : { *(.dynsym) }
- . = ALIGN(4096);
- .dynstr : { *(.dynstr) }
- .ignored :
- {
- *(.rela.plabel)
- *(.rela.reloc)
- }
-}
-
diff --git a/sys/boot/ia64/efi/main.c b/sys/boot/ia64/efi/main.c
deleted file mode 100644
index 58b962036677..000000000000
--- a/sys/boot/ia64/efi/main.c
+++ /dev/null
@@ -1,571 +0,0 @@
-/*-
- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
- * Copyright (c) 1998,2000 Doug Rabson <dfr@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stand.h>
-#include <string.h>
-#include <setjmp.h>
-#include <machine/sal.h>
-#include <machine/pal.h>
-#include <machine/pte.h>
-#include <machine/dig64.h>
-
-#include <efi.h>
-#include <efilib.h>
-
-#include "bootstrap.h"
-#include "efiboot.h"
-
-extern char bootprog_name[];
-extern char bootprog_rev[];
-extern char bootprog_date[];
-extern char bootprog_maker[];
-
-struct efi_devdesc currdev; /* our current device */
-struct arch_switch archsw; /* MI/MD interface boundary */
-
-extern u_int64_t ia64_pal_entry;
-
-EFI_GUID acpi = ACPI_TABLE_GUID;
-EFI_GUID acpi20 = ACPI_20_TABLE_GUID;
-EFI_GUID hcdp = HCDP_TABLE_GUID;
-EFI_GUID imgid = LOADED_IMAGE_PROTOCOL;
-EFI_GUID mps = MPS_TABLE_GUID;
-EFI_GUID netid = EFI_SIMPLE_NETWORK_PROTOCOL;
-EFI_GUID sal = SAL_SYSTEM_TABLE_GUID;
-EFI_GUID smbios = SMBIOS_TABLE_GUID;
-
-static void
-find_pal_proc(void)
-{
- int i;
- struct sal_system_table *saltab = 0;
- static int sizes[6] = {
- 48, 32, 16, 32, 16, 16
- };
- u_int8_t *p;
-
- saltab = efi_get_table(&sal);
- if (saltab == NULL) {
- printf("Can't find SAL System Table\n");
- return;
- }
-
- if (memcmp(saltab->sal_signature, "SST_", 4)) {
- printf("Bad signature for SAL System Table\n");
- return;
- }
-
- p = (u_int8_t *) (saltab + 1);
- for (i = 0; i < saltab->sal_entry_count; i++) {
- if (*p == 0) {
- struct sal_entrypoint_descriptor *dp;
- dp = (struct sal_entrypoint_descriptor *) p;
- ia64_pal_entry = dp->sale_pal_proc;
- return;
- }
- p += sizes[*p];
- }
-
- printf("Can't find PAL proc\n");
- return;
-}
-
-EFI_STATUS
-main(int argc, CHAR16 *argv[])
-{
- EFI_LOADED_IMAGE *img;
- EFI_SIMPLE_NETWORK *net;
- EFI_STATUS status;
- int i;
-
- /*
- * XXX Chicken-and-egg problem; we want to have console output
- * early, but some console attributes may depend on reading from
- * eg. the boot device, which we can't do yet. We can use
- * printf() etc. once this is done.
- */
- cons_probe();
-
- /*
- * Initialise the block cache
- */
- bcache_init(32, 512); /* 16k XXX tune this */
-
- find_pal_proc();
-
- /*
- * March through the device switch probing for things.
- */
- for (i = 0; devsw[i] != NULL; i++)
- if (devsw[i]->dv_init != NULL)
- (devsw[i]->dv_init)();
-
- efinet_init_driver();
-
-
- /* Get our loaded image protocol interface structure. */
- BS->HandleProtocol(IH, &imgid, (VOID**)&img);
-
- printf("Image base: 0x%016lx\n", (u_long)img->ImageBase);
-
- printf("\n");
- printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
- printf("(%s, %s)\n", bootprog_maker, bootprog_date);
-
- /*
- * XXX quick and dirty check to see if we're loaded from the
- * network. If so, we set the default device to 'net'. In all
- * other cases we set the default device to 'disk'. We presume
- * fixed positions in devsw for both net and disk.
- */
- status = BS->HandleProtocol(img->DeviceHandle, &netid, (VOID**)&net);
- if (status == EFI_SUCCESS && net != NULL) {
- currdev.d_dev = devsw[1]; /* XXX net */
- currdev.d_kind.netif.unit = 0;
- } else {
- currdev.d_dev = devsw[0]; /* XXX disk */
- currdev.d_kind.efidisk.unit = 0;
- /* XXX should be able to detect this, default to autoprobe */
- currdev.d_kind.efidisk.slice = -1;
- /* default to 'a' */
- currdev.d_kind.efidisk.partition = 0;
- }
- currdev.d_type = currdev.d_dev->dv_type;
-
- /*
- * Disable the watchdog timer. By default the boot manager sets
- * the timer to 5 minutes before invoking a boot option. If we
- * want to return to the boot manager, we have to disable the
- * watchdog timer and since we're an interactive program, we don't
- * want to wait until the user types "quit". The timer may have
- * fired by then. We don't care if this fails. It does not prevent
- * normal functioning in any way...
- */
- BS->SetWatchdogTimer(0, 0, 0, NULL);
-
- env_setenv("currdev", EV_VOLATILE, efi_fmtdev(&currdev),
- efi_setcurrdev, env_nounset);
- env_setenv("loaddev", EV_VOLATILE, efi_fmtdev(&currdev), env_noset,
- env_nounset);
-
- setenv("LINES", "24", 1); /* optional */
-
- archsw.arch_autoload = efi_autoload;
- archsw.arch_getdev = efi_getdev;
- archsw.arch_copyin = efi_copyin;
- archsw.arch_copyout = efi_copyout;
- archsw.arch_readin = efi_readin;
-
- interact(); /* doesn't return */
-
- return (EFI_SUCCESS); /* keep compiler happy */
-}
-
-COMMAND_SET(quit, "quit", "exit the loader", command_quit);
-
-static int
-command_quit(int argc, char *argv[])
-{
- exit(0);
- return (CMD_OK);
-}
-
-COMMAND_SET(memmap, "memmap", "print memory map", command_memmap);
-
-static int
-command_memmap(int argc, char *argv[])
-{
- UINTN sz;
- EFI_MEMORY_DESCRIPTOR *map, *p;
- UINTN key, dsz;
- UINT32 dver;
- EFI_STATUS status;
- int i, ndesc;
- static char *types[] = {
- "Reserved",
- "LoaderCode",
- "LoaderData",
- "BootServicesCode",
- "BootServicesData",
- "RuntimeServicesCode",
- "RuntimeServicesData",
- "ConventionalMemory",
- "UnusableMemory",
- "ACPIReclaimMemory",
- "ACPIMemoryNVS",
- "MemoryMappedIO",
- "MemoryMappedIOPortSpace",
- "PalCode"
- };
-
- sz = 0;
- status = BS->GetMemoryMap(&sz, 0, &key, &dsz, &dver);
- if (status != EFI_BUFFER_TOO_SMALL) {
- printf("Can't determine memory map size\n");
- return CMD_ERROR;
- }
- map = malloc(sz);
- status = BS->GetMemoryMap(&sz, map, &key, &dsz, &dver);
- if (EFI_ERROR(status)) {
- printf("Can't read memory map\n");
- return CMD_ERROR;
- }
-
- ndesc = sz / dsz;
- printf("%23s %12s %12s %8s %4s\n",
- "Type", "Physical", "Virtual", "#Pages", "Attr");
-
- for (i = 0, p = map; i < ndesc;
- i++, p = NextMemoryDescriptor(p, dsz)) {
- printf("%23s %012lx %012lx %08lx ",
- types[p->Type],
- p->PhysicalStart,
- p->VirtualStart,
- p->NumberOfPages);
- if (p->Attribute & EFI_MEMORY_UC)
- printf("UC ");
- if (p->Attribute & EFI_MEMORY_WC)
- printf("WC ");
- if (p->Attribute & EFI_MEMORY_WT)
- printf("WT ");
- if (p->Attribute & EFI_MEMORY_WB)
- printf("WB ");
- if (p->Attribute & EFI_MEMORY_UCE)
- printf("UCE ");
- if (p->Attribute & EFI_MEMORY_WP)
- printf("WP ");
- if (p->Attribute & EFI_MEMORY_RP)
- printf("RP ");
- if (p->Attribute & EFI_MEMORY_XP)
- printf("XP ");
- if (p->Attribute & EFI_MEMORY_RUNTIME)
- printf("RUNTIME");
- printf("\n");
- }
-
- return CMD_OK;
-}
-
-COMMAND_SET(configuration, "configuration",
- "print configuration tables", command_configuration);
-
-static const char *
-guid_to_string(EFI_GUID *guid)
-{
- static char buf[40];
-
- sprintf(buf, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- guid->Data1, guid->Data2, guid->Data3, guid->Data4[0],
- guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4],
- guid->Data4[5], guid->Data4[6], guid->Data4[7]);
- return (buf);
-}
-
-static int
-command_configuration(int argc, char *argv[])
-{
- int i;
-
- printf("NumberOfTableEntries=%ld\n", ST->NumberOfTableEntries);
- for (i = 0; i < ST->NumberOfTableEntries; i++) {
- EFI_GUID *guid;
-
- printf(" ");
- guid = &ST->ConfigurationTable[i].VendorGuid;
- if (!memcmp(guid, &mps, sizeof(EFI_GUID)))
- printf("MPS Table");
- else if (!memcmp(guid, &acpi, sizeof(EFI_GUID)))
- printf("ACPI Table");
- else if (!memcmp(guid, &acpi20, sizeof(EFI_GUID)))
- printf("ACPI 2.0 Table");
- else if (!memcmp(guid, &smbios, sizeof(EFI_GUID)))
- printf("SMBIOS Table");
- else if (!memcmp(guid, &sal, sizeof(EFI_GUID)))
- printf("SAL System Table");
- else if (!memcmp(guid, &hcdp, sizeof(EFI_GUID)))
- printf("DIG64 HCDP Table");
- else
- printf("Unknown Table (%s)", guid_to_string(guid));
- printf(" at %p\n", ST->ConfigurationTable[i].VendorTable);
- }
-
- return CMD_OK;
-}
-
-COMMAND_SET(sal, "sal", "print SAL System Table", command_sal);
-
-static int
-command_sal(int argc, char *argv[])
-{
- int i;
- struct sal_system_table *saltab = 0;
- static int sizes[6] = {
- 48, 32, 16, 32, 16, 16
- };
- u_int8_t *p;
-
- saltab = efi_get_table(&sal);
- if (saltab == NULL) {
- printf("Can't find SAL System Table\n");
- return CMD_ERROR;
- }
-
- if (memcmp(saltab->sal_signature, "SST_", 4)) {
- printf("Bad signature for SAL System Table\n");
- return CMD_ERROR;
- }
-
- printf("SAL Revision %x.%02x\n",
- saltab->sal_rev[1],
- saltab->sal_rev[0]);
- printf("SAL A Version %x.%02x\n",
- saltab->sal_a_version[1],
- saltab->sal_a_version[0]);
- printf("SAL B Version %x.%02x\n",
- saltab->sal_b_version[1],
- saltab->sal_b_version[0]);
-
- p = (u_int8_t *) (saltab + 1);
- for (i = 0; i < saltab->sal_entry_count; i++) {
- printf(" Desc %d", *p);
- if (*p == 0) {
- struct sal_entrypoint_descriptor *dp;
- dp = (struct sal_entrypoint_descriptor *) p;
- printf("\n");
- printf(" PAL Proc at 0x%lx\n",
- dp->sale_pal_proc);
- printf(" SAL Proc at 0x%lx\n",
- dp->sale_sal_proc);
- printf(" SAL GP at 0x%lx\n",
- dp->sale_sal_gp);
- } else if (*p == 1) {
- struct sal_memory_descriptor *dp;
- dp = (struct sal_memory_descriptor *) p;
- printf(" Type %d.%d, ",
- dp->sale_memory_type[0],
- dp->sale_memory_type[1]);
- printf("Address 0x%lx, ",
- dp->sale_physical_address);
- printf("Length 0x%x\n",
- dp->sale_length);
- } else if (*p == 5) {
- struct sal_ap_wakeup_descriptor *dp;
- dp = (struct sal_ap_wakeup_descriptor *) p;
- printf("\n");
- printf(" Mechanism %d\n", dp->sale_mechanism);
- printf(" Vector 0x%lx\n", dp->sale_vector);
- } else
- printf("\n");
-
- p += sizes[*p];
- }
-
- return CMD_OK;
-}
-
-int
-print_trs(int type)
-{
- struct ia64_pal_result res;
- int i, maxtr;
- struct {
- struct ia64_pte pte;
- struct ia64_itir itir;
- struct ia64_ifa ifa;
- struct ia64_rr rr;
- } buf;
- static const char* psnames[] = {
- "1B", "2B", "4B", "8B",
- "16B", "32B", "64B", "128B",
- "256B", "512B", "1K", "2K",
- "4K", "8K", "16K", "32K",
- "64K", "128K", "256K", "512K",
- "1M", "2M", "4M", "8M",
- "16M", "32M", "64M", "128M",
- "256M", "512M", "1G", "2G"
- };
- static const char* manames[] = {
- "WB", "bad", "bad", "bad",
- "UC", "UCE", "WC", "NaT",
-
- };
-
- res = ia64_call_pal_static(PAL_VM_SUMMARY, 0, 0, 0);
- if (res.pal_status != 0) {
- printf("Can't get VM summary\n");
- return CMD_ERROR;
- }
-
- if (type == 0)
- maxtr = (res.pal_result[0] >> 40) & 0xff;
- else
- maxtr = (res.pal_result[0] >> 32) & 0xff;
-
- printf("%d translation registers\n", maxtr);
-
- pager_open();
- pager_output("TR# RID Virtual Page Physical Page PgSz ED AR PL D A MA P KEY\n");
- for (i = 0; i <= maxtr; i++) {
- char lbuf[128];
-
- bzero(&buf, sizeof(buf));
- res = ia64_call_pal_stacked(PAL_VM_TR_READ, i, type,
- (u_int64_t) &buf);
- if (res.pal_status != 0)
- break;
-
- /* Only display valid translations */
- if ((buf.ifa.ifa_ig & 1) == 0)
- continue;
-
- if (!(res.pal_result[0] & 1))
- buf.pte.pte_ar = 0;
- if (!(res.pal_result[0] & 2))
- buf.pte.pte_pl = 0;
- if (!(res.pal_result[0] & 4))
- buf.pte.pte_d = 0;
- if (!(res.pal_result[0] & 8))
- buf.pte.pte_ma = 0;
- sprintf(lbuf,
- "%03d %06x %013lx %013lx %4s %d %d %d %d %d %-3s %d %06x\n",
- i,
- buf.rr.rr_rid,
- buf.ifa.ifa_vpn,
- buf.pte.pte_ppn,
- psnames[buf.itir.itir_ps],
- buf.pte.pte_ed,
- buf.pte.pte_ar,
- buf.pte.pte_pl,
- buf.pte.pte_d,
- buf.pte.pte_a,
- manames[buf.pte.pte_ma],
- buf.pte.pte_p,
- buf.itir.itir_key);
- pager_output(lbuf);
- }
- pager_close();
-
- if (res.pal_status != 0) {
- printf("Error while getting TR contents\n");
- return CMD_ERROR;
- }
- return CMD_OK;
-}
-
-COMMAND_SET(itr, "itr", "print instruction TRs", command_itr);
-
-static int
-command_itr(int argc, char *argv[])
-{
- return print_trs(0);
-}
-
-COMMAND_SET(dtr, "dtr", "print data TRs", command_dtr);
-
-static int
-command_dtr(int argc, char *argv[])
-{
- return print_trs(1);
-}
-
-COMMAND_SET(hcdp, "hcdp", "Dump HCDP info", command_hcdp);
-
-static char *
-hcdp_string(char *s, u_int len)
-{
- static char buffer[256];
-
- memcpy(buffer, s, len);
- buffer[len] = 0;
- return (buffer);
-}
-
-static int
-command_hcdp(int argc, char *argv[])
-{
- struct dig64_hcdp_table *tbl;
- struct dig64_hcdp_entry *ent;
- struct dig64_gas *gas;
- int i;
-
- tbl = efi_get_table(&hcdp);
- if (tbl == NULL) {
- printf("No HCDP table present\n");
- return (CMD_OK);
- }
- if (memcmp(tbl->signature, HCDP_SIGNATURE, sizeof(tbl->signature))) {
- printf("HCDP table has invalid signature\n");
- return (CMD_OK);
- }
- if (tbl->length < sizeof(*tbl) - sizeof(*tbl->entry)) {
- printf("HCDP table too short\n");
- return (CMD_OK);
- }
- printf("HCDP table at 0x%016lx\n", (u_long)tbl);
- printf("Signature = %s\n", hcdp_string(tbl->signature, 4));
- printf("Length = %u\n", tbl->length);
- printf("Revision = %u\n", tbl->revision);
- printf("Checksum = %u\n", tbl->checksum);
- printf("OEM Id = %s\n", hcdp_string(tbl->oem_id, 6));
- printf("Table Id = %s\n", hcdp_string(tbl->oem_tbl_id, 8));
- printf("OEM rev = %u\n", tbl->oem_rev);
- printf("Creator Id = %s\n", hcdp_string(tbl->creator_id, 4));
- printf("Creator rev= %u\n", tbl->creator_rev);
- printf("Entries = %u\n", tbl->entries);
- for (i = 0; i < tbl->entries; i++) {
- ent = tbl->entry + i;
- printf("Entry #%d:\n", i + 1);
- printf(" Type = %u\n", ent->type);
- printf(" Databits = %u\n", ent->databits);
- printf(" Parity = %u\n", ent->parity);
- printf(" Stopbits = %u\n", ent->stopbits);
- printf(" PCI seg = %u\n", ent->pci_segment);
- printf(" PCI bus = %u\n", ent->pci_bus);
- printf(" PCI dev = %u\n", ent->pci_device);
- printf(" PCI func = %u\n", ent->pci_function);
- printf(" Interrupt = %u\n", ent->interrupt);
- printf(" PCI flag = %u\n", ent->pci_flag);
- printf(" Baudrate = %lu\n",
- ((u_long)ent->baud_high << 32) + (u_long)ent->baud_low);
- gas = &ent->address;
- printf(" Addr space= %u\n", gas->addr_space);
- printf(" Bit width = %u\n", gas->bit_width);
- printf(" Bit offset= %u\n", gas->bit_offset);
- printf(" Address = 0x%016lx\n",
- ((u_long)gas->addr_high << 32) + (u_long)gas->addr_low);
- printf(" PCI type = %u\n", ent->pci_devid);
- printf(" PCI vndr = %u\n", ent->pci_vendor);
- printf(" IRQ = %u\n", ent->irq);
- printf(" PClock = %u\n", ent->pclock);
- printf(" PCI iface = %u\n", ent->pci_interface);
- }
- printf("<EOT>\n");
- return (CMD_OK);
-}
diff --git a/sys/boot/ia64/efi/start.S b/sys/boot/ia64/efi/start.S
deleted file mode 100644
index 643f1c94aa73..000000000000
--- a/sys/boot/ia64/efi/start.S
+++ /dev/null
@@ -1,305 +0,0 @@
-/*-
- * Copyright (c) 2001 Doug Rabson
- * 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$
- */
-
- .text
-
-#include <machine/asm.h>
-
-#define EFI_SUCCESS 0
-#define EFI_LOAD_ERROR 1
-#define EFI_BUFFER_TOO_SMALL 5
-
-#define DT_NULL 0 /* Terminating entry. */
-#define DT_NEEDED 1 /* String table offset of a needed shared
- library. */
-#define DT_PLTRELSZ 2 /* Total size in bytes of PLT relocations. */
-#define DT_PLTGOT 3 /* Processor-dependent address. */
-#define DT_HASH 4 /* Address of symbol hash table. */
-#define DT_STRTAB 5 /* Address of string table. */
-#define DT_SYMTAB 6 /* Address of symbol table. */
-#define DT_RELA 7 /* Address of ElfNN_Rela relocations. */
-#define DT_RELASZ 8 /* Total size of ElfNN_Rela relocations. */
-#define DT_RELAENT 9 /* Size of each ElfNN_Rela relocation entry. */
-#define DT_STRSZ 10 /* Size of string table. */
-#define DT_SYMENT 11 /* Size of each symbol table entry. */
-#define DT_INIT 12 /* Address of initialization function. */
-#define DT_FINI 13 /* Address of finalization function. */
-#define DT_SONAME 14 /* String table offset of shared object
- name. */
-#define DT_RPATH 15 /* String table offset of library path. */
-#define DT_SYMBOLIC 16 /* Indicates "symbolic" linking. */
-#define DT_REL 17 /* Address of ElfNN_Rel relocations. */
-#define DT_RELSZ 18 /* Total size of ElfNN_Rel relocations. */
-#define DT_RELENT 19 /* Size of each ElfNN_Rel relocation. */
-#define DT_PLTREL 20 /* Type of relocation used for PLT. */
-#define DT_DEBUG 21 /* Reserved (not used). */
-#define DT_TEXTREL 22 /* Indicates there may be relocations in
- non-writable segments. */
-#define DT_JMPREL 23 /* Address of PLT relocations. */
-
-#define DT_COUNT 24 /* Number of defined d_tag values. */
-
-#define R_IA64_NONE 0 /* None */
-#define R_IA64_DIR64MSB 0x26 /* word64 MSB S + A */
-#define R_IA64_DIR64LSB 0x27 /* word64 LSB S + A */
-#define R_IA64_FPTR64MSB 0x46 /* word64 MSB @fptr(S + A) */
-#define R_IA64_FPTR64LSB 0x47 /* word64 LSB @fptr(S + A) */
-#define R_IA64_REL64MSB 0x6e /* word64 MSB BD + A */
-#define R_IA64_REL64LSB 0x6f /* word64 LSB BD + A */
-#define R_IA64_IPLTLSB 0x81 /* function descriptor LSB speciaal */
-
-ENTRY(_start, 2)
- alloc loc0=ar.pfs,2,3,3,0
- mov loc1=rp
- movl loc2=@gprel(ImageBase)
- ;;
- add loc2=gp,loc2
- ;;
- mov out0=loc2
- mov out1=in1
- ;;
- br.call.sptk.few rp=_reloc // relocate image
-
- cmp.ne p6,p0=EFI_SUCCESS,r8 // did it work?
-(p6) br.cond.dpnt.few 9f
-
- mov out0=in0 // image_handle
- mov out1=in1 // system_table
- br.call.sptk.few rp=efi_main
-9:
- mov ar.pfs=loc0
- mov rp=loc1
- ;;
- br.ret.sptk.few rp
-END(_start)
-
- // PLABEL for PE32+
- .global _start_plabel
- .section .plabel, "a"
- .align 16
-_start_plabel:
- .quad _start
- .quad __gp
- .previous
-
- // A PE32+ relocation entry for the plabel
-
- .section .reloc, "a"
- .long _start_plabel
- .long 12
- .short (10 << 12) + 0
- .short (10 << 12) + 8
- .previous
-
-// in0: image base
-// in1: system table
-//
-// XXX Assumes PLT relocations are of type Elf_Rela
-//
-// r2 = address of fptr_storage
-// r3 = address of fptr_storage_end
-// r4 = address of first free fptr
-//
-// r15 = r_offset
-// r16 = r_info -OR- d_tag
-// r17 = r_addend -OR- d_val (=d_ptr)
-// r18 = address of .rela dynamic section
-// r19 = size of .rela section
-// r20 = size of .rela element (Elf_Rela)
-// r21 = address of first PLT relocation
-// r22 = size of PLT relocations
-// r23 = relocation type
-// r24 = address of symbol
-// r28 = R_IA64_IPLTLSB
-// f8 = address of symbol table
-// f9 = size of symtab element
-
-STATIC_ENTRY(_reloc, 2)
- alloc loc0=ar.pfs,2,2,0,0
- ;;
- mov loc1=rp
- movl r29=@gprel(_DYNAMIC) // find _DYNAMIC etc.
- ;;
- add r15=r29,gp
- movl r29=@gprel(fptr_storage)
- ;;
- add r2=r29,gp
- movl r29=@gprel(fptr_storage_end)
- ;;
- add r3=r29,gp
- mov r4=r2
- mov r19=0
- mov r22=0
- mov r20=24
- mov r28=R_IA64_IPLTLSB
- ;;
-1:
- ld8 r16=[r15],8 // read r15->d_tag
- ;;
- ld8 r17=[r15],8 // and r15->d_val
- ;;
- cmp.eq p6,p0=DT_NULL,r16 // done?
-(p6) br.cond.dpnt.few 2f
- ;;
- cmp.eq p6,p0=DT_RELA,r16 // rela section?
- ;;
-(p6) add r18=r17,in0
- cmp.eq p6,p0=DT_RELASZ,r16 // rela section size?
- ;;
-(p6) mov r19=r17
- cmp.eq p6,p0=DT_RELAENT,r16 // rela entry size?
- ;;
-(p6) mov r20=r17
- cmp.eq p6,p0=DT_JMPREL,r16 // PLT relocs?
- ;;
-(p6) add r21=r17,in0
- cmp.eq p6,p0=DT_PLTRELSZ,r16 // PLT relocs size?
- ;;
-(p6) mov r22=r17
- cmp.eq p6,p0=DT_SYMTAB,r16 // symbol table?
- ;;
-(p6) add r29=r17,in0
- ;;
-(p6) setf.sig f8=r29
- cmp.eq p6,p0=DT_SYMENT,r16 // symbol entry size?
- ;;
-(p6) setf.sig f9=r17
- br.dptk 1b
-
-2:
- cmp.lt p6,p0=0,r19
-(p6) br.cond.dptk 3f
- ;;
- mov r19=r22
- mov r18=r21
- mov r21=0
- mov r22=0
- ;;
- cmp.lt p6,p0=0,r19
-(p6) br.cond.dptk 3f
- ;;
- mov r8=EFI_SUCCESS
- br.dptk 9f
-3:
- ld8 r29=[r18],8 // read r_offset
- ;;
- ld8 r16=[r18],8 // read r_info
- add r15=r29,in0 // relocate r_offset
- ;;
- ld8 r17=[r18],8 // read r_addend
- sub r19=r19,r20 // update relasz
- extr.u r23=r16,0,32 // ELF64_R_TYPE(r16)
- ;;
- cmp.eq p6,p0=R_IA64_NONE,r23
-(p6) br.cond.dpnt.few 2b
- ;;
- cmp.eq p6,p0=R_IA64_REL64LSB,r23
-(p6) br.cond.dptk.few 4f
- ;;
- extr.u r29=r16,32,32 // ELF64_R_SYM(r16)
- ;;
- setf.sig f10=r29 // so we can multiply
- ;;
- xma.lu f10=f10,f9,f8 // f10=symtab + r_sym*syment
- ;;
- getf.sig r29=f10
- ;;
- add r29=8,r29 // address of st_value
- ;;
- ld8 r29=[r29] // read symbol value
- ;;
- add r24=r29,in0 // relocate symbol value
- ;;
- cmp.eq p6,p0=R_IA64_DIR64LSB,r23
-(p6) br.cond.dptk.few 5f
- ;;
- cmp.eq p6,p0=R_IA64_FPTR64LSB,r23
-(p6) br.cond.dptk.few 6f
- ;;
- cmp.ne p6,p0=r28,r23 // IPLTLSB
-(p6) br.cond.dptk.few 2b
-
- // IPLTLSB
- add r29=r24,r17 // S + A
- ;;
- st8 [r15]=r29,8 // fdesc:FP
- ;;
- st8 [r15]=gp // fdesc:GP
- br.cond.sptk.few 2b
-
- // REL64LSB
-4:
- add r29=in0,r17 // BD + A
- ;;
- st8 [r15]=r29 // word64
- br.cond.sptk.few 2b
-
- // DIR64LSB
-5:
- add r29=r24,r17 // S + A
- ;;
- st8 [r15]=r29 // word64
- br.cond.sptk.few 2b
-
-6:
- mov r29=r2 // FPTR64LSB
- ;;
-7:
- cmp.geu p6,p0=r29,r4 // end of fptrs?
-(p6) br.cond.dpnt.few 8f // can't find existing fptr
- ld8 r17=[r29] // read function from fptr
- ;;
- cmp.eq p6,p0=r24,r17 // same function?
- ;;
-(p6) st8 [r15]=r29 // reuse fptr
-(p6) br.cond.sptk.few 2b // done
- add r29=16,r29 // next fptr
- br.sptk.few 7b
-8:
- mov r8=EFI_BUFFER_TOO_SMALL // failure return value
- cmp.geu p6,p0=r4,r3 // space left?
-(p6) br.cond.dpnt.few 9f // bail out
- st8 [r15]=r4 // install fptr
- ;;
- st8 [r4]=r24,8 // write fptr address
- ;;
- st8 [r4]=gp,8 // write fptr gp
- br.cond.sptk.few 2b
-
-9:
- mov ar.pfs=loc0
- mov rp=loc1
- ;;
- br.ret.sptk.few rp
-END(_reloc)
-
- .data
- .align 16
-fptr_storage:
- .space 1024*16 // XXX
-fptr_storage_end:
diff --git a/sys/boot/ia64/efi/version b/sys/boot/ia64/efi/version
deleted file mode 100644
index 71f9400f68b0..000000000000
--- a/sys/boot/ia64/efi/version
+++ /dev/null
@@ -1,16 +0,0 @@
-$FreeBSD$
-
-NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE. The format of this
-file is important. Make sure the current version number is on line 6.
-
-1.1: Pass the HCDP table address to the kernel via bootinfo if one
- is present in the EFI system table.
-1.0: Don't map the I/O port range. We expect the kernel to do it. It
- was done in the loader as a debugging aid and not intended as a
- service/feature.
-0.3: Pass the physical address of the bootinfo block in register r8
- to the kernel. Continue to put it at the fixed address for now.
-0.2: Much improved version. Significant is the support for passing
- the FPSWA interface pointer to the kernel.
-0.1: Initial EFI version, germinated from the NetBSD i386
- standalone, but enormously modified.
diff --git a/sys/boot/ia64/libski/pal_stub.S b/sys/boot/ia64/libski/pal_stub.S
deleted file mode 100644
index e67204c4b30a..000000000000
--- a/sys/boot/ia64/libski/pal_stub.S
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2003 Marcel Moolenaar
- * Copyright (c) 2001 Doug Rabson
- * 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$
- */
-
-#include <machine/asm.h>
-
- .text
-ENTRY(PalProc, 0)
- cmp.eq p6,p0=6,r28 // PAL_PTCE_INFO
-(p6) br.cond.dptk pal_ptce_info
- ;;
- cmp.eq p6,p0=8,r28 // PAL_VM_SUMMARY
-(p6) br.cond.dptk pal_vm_summary
- ;;
- cmp.eq p6,p0=14,r28 // PAL_FREQ_RATIOS
-(p6) br.cond.dptk pal_freq_ratios
- ;;
- mov r15=66 // EXIT
- break.i 0x80000 // SSC
- ;;
-pal_ptce_info:
- mov r8=0
- mov r9=0 // base
- movl r10=0x0000000100000001 // loop counts (outer|inner)
- mov r11=0x0000000000000000 // loop strides (outer|inner)
- br.sptk b0
-pal_vm_summary:
- mov r8=0
- movl r9=(8<<40)|(8<<32) // VM info 1
- mov r10=(18<<8)|(41<<0) // VM info 2
- mov r11=0
- br.sptk b0
-pal_freq_ratios:
- mov r8=0
- movl r9=0x0000000B00000002 // processor ratio 11/2
- movl r10=0x0000000100000001 // bus ratio 1/1
- movl r11=0x0000000B00000002 // ITC ratio 11/2
- br.sptk b0
-END(PalProc)
diff --git a/sys/boot/ia64/ski/Makefile b/sys/boot/ia64/ski/Makefile
deleted file mode 100644
index 8a374a177eb6..000000000000
--- a/sys/boot/ia64/ski/Makefile
+++ /dev/null
@@ -1,84 +0,0 @@
-# $FreeBSD$
-
-.PATH: ${.CURDIR}/../common
-
-PROG= skiload
-NOMAN=
-NEWVERSWHAT= "ia64 SKI boot" ${MACHINE_ARCH}
-BINDIR?= /boot
-
-SRCS+= main.c conf.c
-
-CFLAGS+= -ffreestanding
-
-.if !defined(NOFORTH)
-# Enable BootForth
-BOOT_FORTH= yes
-CFLAGS+= -DBOOT_FORTH
-CFLAGS+= -I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/${MACHINE_ARCH}
-.if exists(${.OBJDIR}/../../ficl/libficl.a)
-LIBFICL= ${.OBJDIR}/../../ficl/libficl.a
-.else
-LIBFICL= ${.CURDIR}/../../ficl/libficl.a
-.endif
-.endif
-
-# where to get libstand from
-.if exists(${.OBJDIR}/../../../../lib/libstand/libstand.a)
-LIBSTAND= ${.OBJDIR}/../../../../lib/libstand/libstand.a
-.else
-LIBSTAND= ${.CURDIR}/../../../../lib/libstand/libstand.a
-.endif
-
-.if exists(${.OBJDIR}/../libski/libski.a)
-LIBSKI= ${.OBJDIR}/../libski/libski.a
-.else
-LIBSKI= ${.CURDIR}/../libski/libski.a
-.endif
-
-# Always add MI sources
-.PATH: ${.CURDIR}/../../common
-.include <${.CURDIR}/../../common/Makefile.inc>
-
-CFLAGS+= -I-
-CFLAGS+= -I${.CURDIR}/../include
-CFLAGS+= -I${.CURDIR}/../include/${MACHINE_ARCH}
-CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}
-CFLAGS+= -I${.CURDIR}/../../.. -I.
-CFLAGS+= -I${.CURDIR}/../libski
-CFLAGS+= -DLOADER
-
-LDFLAGS= -nostdlib -T ${.CURDIR}/ldscript.ia64
-
-CLEANFILES+= vers.c vers.o ${PROG}.list
-CLEANFILES+= loader.help
-CLEANFILES+= machine
-
-all: ${PROG}
-
-vers.o: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
- sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT}
- ${CC} -c vers.c
-
-${PROG}.help: help.common help.efi
- cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk \
- > ${.TARGET}
-
-beforeinstall:
-.if exists(${.OBJDIR}/${PROG}.help)
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.OBJDIR}/${PROG}.help ${DESTDIR}/boot
-.endif
-
-machine:
- ln -sf ${.CURDIR}/../../../${MACHINE_ARCH}/include machine
-
-${PROG}: ${OBJS} ${LIBFICL} ${LIBSKI} ${LIBSTAND} vers.o
- ${LD} ${LDFLAGS} -o ${PROG} -M \
- ${OBJS} vers.o \
- ${LIBFICL} ${LIBSTAND} ${LIBSKI} ${LIBSTAND} \
- > ${.OBJDIR}/${PROG}.list
-
-.include <bsd.prog.mk>
-
-beforedepend ${OBJS}: machine
diff --git a/sys/boot/ia64/ski/acpi_stub.c b/sys/boot/ia64/ski/acpi_stub.c
deleted file mode 100644
index 3187925c6a80..000000000000
--- a/sys/boot/ia64/ski/acpi_stub.c
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (c) 2003 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.
- * 2. Redistributions in binary form must 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.
- *
- * $FreeBSD$
- */
-
-#include <contrib/dev/acpica/acpi.h>
-
-#define APIC_IO_SAPIC 6
-#define APIC_LOCAL_SAPIC 7
-
-#pragma pack(1)
-
-typedef struct /* LOCAL SAPIC */
-{
- APIC_HEADER Header;
- UINT8 ProcessorId; /* ACPI processor id */
- UINT8 LocalSapicId; /* Processor local SAPIC id */
- UINT8 LocalSapicEid; /* Processor local SAPIC eid */
- UINT8 Reserved[3];
- UINT32 ProcessorEnabled: 1;
- UINT32 FlagsReserved: 31;
-} LOCAL_SAPIC;
-
-typedef struct /* IO SAPIC */
-{
- APIC_HEADER Header;
- UINT8 IoSapicId; /* I/O SAPIC ID */
- UINT8 Reserved; /* reserved - must be zero */
- UINT32 Vector; /* interrupt base */
- UINT64 IoSapicAddress; /* SAPIC's physical address */
-} IO_SAPIC;
-
-/*
- */
-
-struct {
- APIC_TABLE Header;
- LOCAL_SAPIC cpu0;
- LOCAL_SAPIC cpu1;
- LOCAL_SAPIC cpu2;
- LOCAL_SAPIC cpu3;
- IO_SAPIC sapic;
-} apic = {
- /* Header. */
- {
- {
- APIC_SIG, /* Signature. */
- sizeof(apic), /* Length of table. */
- 0, /* ACPI minor revision. */
- 0, /* XXX checksum. */
- "FBSD", /* OEM Id. */
- "SKI", /* OEM table Id. */
- 0, /* OEM revision. */
- "FBSD", /* ASL compiler Id. */
- 0 /* ASL revision. */
- },
- 0xfee00000,
- },
- /* cpu0. */
- {
- {
- APIC_LOCAL_SAPIC, /* Type. */
- sizeof(apic.cpu0) /* Length. */
- },
- 0, /* ACPI processor id */
- 0, /* Processor local SAPIC id */
- 0, /* Processor local SAPIC eid */
- { 0, 0, 0 },
- 1, /* FL: Enabled. */
- },
- /* cpu1. */
- {
- {
- APIC_LOCAL_SAPIC, /* Type. */
- sizeof(apic.cpu1) /* Length. */
- },
- 1, /* ACPI processor id */
- 0, /* Processor local SAPIC id */
- 1, /* Processor local SAPIC eid */
- { 0, 0, 0 },
- 1, /* FL: Enabled. */
- },
- /* cpu2. */
- {
- {
- APIC_LOCAL_SAPIC, /* Type. */
- sizeof(apic.cpu2) /* Length. */
- },
- 2, /* ACPI processor id */
- 1, /* Processor local SAPIC id */
- 0, /* Processor local SAPIC eid */
- { 0, 0, 0 },
- 0, /* FL: Enabled. */
- },
- /* cpu3. */
- {
- {
- APIC_LOCAL_SAPIC, /* Type. */
- sizeof(apic.cpu3) /* Length. */
- },
- 3, /* ACPI processor id */
- 1, /* Processor local SAPIC id */
- 1, /* Processor local SAPIC eid */
- { 0, 0, 0 },
- 0, /* FL: Enabled. */
- },
- /* sapic. */
- {
- {
- APIC_IO_SAPIC, /* Type. */
- sizeof(apic.sapic) /* Length. */
- },
- 4, /* IO SAPIC id. */
- 0,
- 16, /* Interrupt base. */
- 0xfec00000 /* IO SAPIC address. */
- }
-};
-
-struct {
- ACPI_TABLE_HEADER Header;
- UINT64 apic_tbl;
-} xsdt = {
- {
- XSDT_SIG, /* Signature. */
- sizeof(xsdt), /* Length of table. */
- 0, /* ACPI minor revision. */
- 0, /* XXX checksum. */
- "FBSD", /* OEM Id. */
- "SKI", /* OEM table Id. */
- 0, /* OEM revision. */
- "FBSD", /* ASL compiler Id. */
- 0 /* ASL revision. */
- },
- NULL /* XXX APIC table address. */
-};
-
-RSDP_DESCRIPTOR acpi_root = {
- RSDP_SIG,
- 0, /* XXX checksum. */
- "FBSD",
- 2, /* ACPI Rev 2.0. */
- NULL,
- sizeof(xsdt), /* XSDT length. */
- NULL, /* XXX PA of XSDT. */
- 0, /* XXX Extended checksum. */
-};
-
-static void
-cksum(void *addr, int sz, UINT8 *sum)
-{
- UINT8 *p, s;
-
- p = addr;
- s = 0;
- while (sz--)
- s += *p++;
- *sum = -s;
-}
-
-void
-acpi_stub_init(void)
-{
- acpi_root.XsdtPhysicalAddress = (UINT64)&xsdt;
- cksum(&acpi_root, 20, &acpi_root.Checksum);
- cksum(&acpi_root, sizeof(acpi_root), &acpi_root.ExtendedChecksum);
-
- xsdt.apic_tbl = (UINT32)&apic;
- cksum(&xsdt, sizeof(xsdt), &xsdt.Header.Checksum);
-}
diff --git a/sys/boot/ia64/ski/bootinfo.c b/sys/boot/ia64/ski/bootinfo.c
deleted file mode 100644
index 404de973c970..000000000000
--- a/sys/boot/ia64/ski/bootinfo.c
+++ /dev/null
@@ -1,315 +0,0 @@
-/*-
- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <stand.h>
-#include <string.h>
-#include <sys/param.h>
-#include <sys/reboot.h>
-#include <sys/linker.h>
-#include <machine/elf.h>
-#include <machine/bootinfo.h>
-
-#include "bootstrap.h"
-
-/*
- * Return a 'boothowto' value corresponding to the kernel arguments in
- * (kargs) and any relevant environment variables.
- */
-static struct
-{
- const char *ev;
- int mask;
-} howto_names[] = {
- {"boot_askname", RB_ASKNAME},
- {"boot_cdrom", RB_CDROM},
- {"boot_userconfig", RB_CONFIG},
- {"boot_ddb", RB_KDB},
- {"boot_gdb", RB_GDB},
- {"boot_single", RB_SINGLE},
- {"boot_verbose", RB_VERBOSE},
- {"boot_multicons", RB_MULTIPLE},
- {"boot_serial", RB_SERIAL},
- {NULL, 0}
-};
-
-extern char *ski_fmtdev(void *vdev);
-extern int ski_init_stubs(struct bootinfo *);
-
-int
-bi_getboothowto(char *kargs)
-{
- char *cp;
- int howto;
- int active;
- int i;
-
- /* Parse kargs */
- howto = 0;
- if (kargs != NULL) {
- cp = kargs;
- active = 0;
- while (*cp != 0) {
- if (!active && (*cp == '-')) {
- active = 1;
- } else if (active)
- switch (*cp) {
- case 'a':
- howto |= RB_ASKNAME;
- break;
- case 'c':
- howto |= RB_CONFIG;
- break;
- case 'C':
- howto |= RB_CDROM;
- break;
- case 'd':
- howto |= RB_KDB;
- break;
- case 'm':
- howto |= RB_MUTE;
- break;
- case 'g':
- howto |= RB_GDB;
- break;
- case 'h':
- howto |= RB_SERIAL;
- break;
- case 'r':
- howto |= RB_DFLTROOT;
- break;
- case 's':
- howto |= RB_SINGLE;
- break;
- case 'v':
- howto |= RB_VERBOSE;
- break;
- default:
- active = 0;
- break;
- }
- cp++;
- }
- }
- /* get equivalents from the environment */
- for (i = 0; howto_names[i].ev != NULL; i++)
- if (getenv(howto_names[i].ev) != NULL)
- howto |= howto_names[i].mask;
- if (!strcmp(getenv("console"), "comconsole"))
- howto |= RB_SERIAL;
- if (!strcmp(getenv("console"), "nullconsole"))
- howto |= RB_MUTE;
- return(howto);
-}
-
-/*
- * Copy the environment into the load area starting at (addr).
- * Each variable is formatted as <name>=<value>, with a single nul
- * separating each variable, and a double nul terminating the environment.
- */
-vm_offset_t
-bi_copyenv(vm_offset_t addr)
-{
- struct env_var *ep;
-
- /* traverse the environment */
- for (ep = environ; ep != NULL; ep = ep->ev_next) {
- ski_copyin(ep->ev_name, addr, strlen(ep->ev_name));
- addr += strlen(ep->ev_name);
- ski_copyin("=", addr, 1);
- addr++;
- if (ep->ev_value != NULL) {
- ski_copyin(ep->ev_value, addr, strlen(ep->ev_value));
- addr += strlen(ep->ev_value);
- }
- ski_copyin("", addr, 1);
- addr++;
- }
- ski_copyin("", addr, 1);
- addr++;
- return(addr);
-}
-
-/*
- * Copy module-related data into the load area, where it can be
- * used as a directory for loaded modules.
- *
- * Module data is presented in a self-describing format. Each datum
- * is preceded by a 32-bit identifier and a 32-bit size field.
- *
- * Currently, the following data are saved:
- *
- * MOD_NAME (variable) module name (string)
- * MOD_TYPE (variable) module type (string)
- * MOD_ARGS (variable) module parameters (string)
- * MOD_ADDR sizeof(vm_offset_t) module load address
- * MOD_SIZE sizeof(size_t) module size
- * MOD_METADATA (variable) type-specific metadata
- */
-#define COPY32(v, a) { \
- u_int32_t x = (v); \
- ski_copyin(&x, a, sizeof(x)); \
- a += sizeof(x); \
-}
-
-#define MOD_STR(t, a, s) { \
- COPY32(t, a); \
- COPY32(strlen(s) + 1, a); \
- ski_copyin(s, a, strlen(s) + 1); \
- a += roundup(strlen(s) + 1, sizeof(u_int64_t));\
-}
-
-#define MOD_NAME(a, s) MOD_STR(MODINFO_NAME, a, s)
-#define MOD_TYPE(a, s) MOD_STR(MODINFO_TYPE, a, s)
-#define MOD_ARGS(a, s) MOD_STR(MODINFO_ARGS, a, s)
-
-#define MOD_VAR(t, a, s) { \
- COPY32(t, a); \
- COPY32(sizeof(s), a); \
- ski_copyin(&s, a, sizeof(s)); \
- a += roundup(sizeof(s), sizeof(u_int64_t)); \
-}
-
-#define MOD_ADDR(a, s) MOD_VAR(MODINFO_ADDR, a, s)
-#define MOD_SIZE(a, s) MOD_VAR(MODINFO_SIZE, a, s)
-
-#define MOD_METADATA(a, mm) { \
- COPY32(MODINFO_METADATA | mm->md_type, a); \
- COPY32(mm->md_size, a); \
- ski_copyin(mm->md_data, a, mm->md_size); \
- a += roundup(mm->md_size, sizeof(u_int64_t));\
-}
-
-#define MOD_END(a) { \
- COPY32(MODINFO_END, a); \
- COPY32(0, a); \
-}
-
-vm_offset_t
-bi_copymodules(vm_offset_t addr)
-{
- struct preloaded_file *fp;
- struct file_metadata *md;
-
- /* start with the first module on the list, should be the kernel */
- for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
-
- MOD_NAME(addr, fp->f_name); /* this field must come first */
- MOD_TYPE(addr, fp->f_type);
- if (fp->f_args)
- MOD_ARGS(addr, fp->f_args);
- MOD_ADDR(addr, fp->f_addr);
- MOD_SIZE(addr, fp->f_size);
- for (md = fp->f_metadata; md != NULL; md = md->md_next)
- if (!(md->md_type & MODINFOMD_NOCOPY))
- MOD_METADATA(addr, md);
- }
- MOD_END(addr);
- return(addr);
-}
-
-/*
- * Load the information expected by an alpha kernel.
- *
- * - The kernel environment is copied into kernel space.
- * - Module metadata are formatted and placed in kernel space.
- */
-int
-bi_load(struct bootinfo *bi, struct preloaded_file *fp, char *args)
-{
- char *rootdevname;
- struct ski_devdesc *rootdev;
- struct preloaded_file *xp;
- vm_offset_t addr, bootinfo_addr;
- char *kernelname;
- vm_offset_t ssym, esym;
- struct file_metadata *md;
-
- /*
- * Version 1 bootinfo.
- */
- bi->bi_magic = BOOTINFO_MAGIC;
- bi->bi_version = 1;
-
- /*
- * Calculate boothowto.
- */
- bi->bi_boothowto = bi_getboothowto(fp->f_args);
-
- /*
- * Allow the environment variable 'rootdev' to override the supplied device
- * This should perhaps go to MI code and/or have $rootdev tested/set by
- * MI code before launching the kernel.
- */
- rootdevname = getenv("rootdev");
- ski_getdev((void **)(&rootdev), rootdevname, NULL);
- if (rootdev == NULL) { /* bad $rootdev/$currdev */
- printf("can't determine root device\n");
- return(EINVAL);
- }
-
- /* Try reading the /etc/fstab file to select the root device */
- getrootmount(ski_fmtdev((void *)rootdev));
- free(rootdev);
-
- ssym = esym = 0;
- if ((md = file_findmetadata(fp, MODINFOMD_SSYM)) != NULL)
- ssym = *((vm_offset_t *)&(md->md_data));
- if ((md = file_findmetadata(fp, MODINFOMD_ESYM)) != NULL)
- esym = *((vm_offset_t *)&(md->md_data));
- if (ssym == 0 || esym == 0)
- ssym = esym = 0; /* sanity */
-
- bi->bi_symtab = ssym;
- bi->bi_esymtab = esym;
-
- /* find the last module in the chain */
- addr = 0;
- for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
- if (addr < (xp->f_addr + xp->f_size))
- addr = xp->f_addr + xp->f_size;
- }
-
- /* pad to a page boundary */
- addr = (addr + PAGE_MASK) & ~PAGE_MASK;
-
- /* copy our environment */
- bi->bi_envp = addr;
- addr = bi_copyenv(addr);
-
- /* pad to a page boundary */
- addr = (addr + PAGE_MASK) & ~PAGE_MASK;
-
- /* copy module list and metadata */
- bi->bi_modulep = addr;
- addr = bi_copymodules(addr);
-
- /* all done copying stuff in, save end of loaded object space */
- bi->bi_kernend = addr;
-
- return (ski_init_stubs(bi));
-}
diff --git a/sys/boot/ia64/ski/conf.c b/sys/boot/ia64/ski/conf.c
deleted file mode 100644
index 5066a77f13cb..000000000000
--- a/sys/boot/ia64/ski/conf.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (c) 1997
- * Matthias Drochner. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed for the NetBSD Project
- * by Matthias Drochner.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $NetBSD: conf.c,v 1.2 1997/03/22 09:03:29 thorpej Exp $
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stand.h>
-
-#include "libski.h"
-
-/*
- * We could use linker sets for some or all of these, but
- * then we would have to control what ended up linked into
- * the bootstrap. So it's easier to conditionalise things
- * here.
- *
- * XXX rename these arrays to be consistent and less namespace-hostile
- */
-
-/* Exported for libstand */
-struct devsw *devsw[] = {
- &skifs_dev,
- NULL
-};
-
-struct fs_ops *file_system[] = {
- &ski_fsops,
- &ufs_fsops,
- &gzipfs_fsops,
- NULL
-};
-
-/* Exported for ia64 only */
-/*
- * Sort formats so that those that can detect based on arguments
- * rather than reading the file go first.
- */
-extern struct file_format ia64_elf;
-
-struct file_format *file_formats[] = {
- &ia64_elf,
- NULL
-};
-
-/*
- * Consoles
- *
- * We don't prototype these in libalpha.h because they require
- * data structures from bootstrap.h as well.
- */
-extern struct console ski_console;
-
-struct console *consoles[] = {
- &ski_console,
- NULL
-};
diff --git a/sys/boot/ia64/ski/copy.c b/sys/boot/ia64/ski/copy.c
deleted file mode 100644
index d86537a14099..000000000000
--- a/sys/boot/ia64/ski/copy.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * MD primitives supporting placement of module data
- *
- * XXX should check load address/size against memory top.
- */
-#include <stand.h>
-
-#include <machine/ia64_cpu.h>
-#include <machine/vmparam.h>
-
-int
-ski_copyin(void *src, vm_offset_t dest, size_t len)
-{
- bcopy(src, (void*) IA64_RR_MASK(dest), len);
- return (len);
-}
-
-int
-ski_copyout(vm_offset_t src, void *dest, size_t len)
-{
- bcopy((void*) IA64_RR_MASK(src), dest, len);
- return (len);
-}
-
-int
-ski_readin(int fd, vm_offset_t dest, size_t len)
-{
- return (read(fd, (void*) IA64_RR_MASK(dest), len));
-}
diff --git a/sys/boot/ia64/ski/delay.c b/sys/boot/ia64/ski/delay.c
deleted file mode 100644
index 2389603edb4a..000000000000
--- a/sys/boot/ia64/ski/delay.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*-
- * Copyright (c) 2001 Doug Rabson
- * 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$");
-
-void
-delay(int usecs)
-{
- return;
-}
diff --git a/sys/boot/ia64/ski/devicename.c b/sys/boot/ia64/ski/devicename.c
deleted file mode 100644
index 35356c32f4f7..000000000000
--- a/sys/boot/ia64/ski/devicename.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/*-
- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <stand.h>
-#include <string.h>
-#include <sys/disklabel.h>
-#include "bootstrap.h"
-#include "libski.h"
-
-static int ski_parsedev(struct ski_devdesc **dev, const char *devspec, const char **path);
-
-/*
- * Point (dev) at an allocated device specifier for the device matching the
- * path in (devspec). If it contains an explicit device specification,
- * use that. If not, use the default device.
- */
-int
-ski_getdev(void **vdev, const char *devspec, const char **path)
-{
- struct ski_devdesc **dev = (struct ski_devdesc **)vdev;
- int rv;
-
- /*
- * If it looks like this is just a path and no
- * device, go with the current device.
- */
- if ((devspec == NULL) ||
- (devspec[0] == '/') ||
- (strchr(devspec, ':') == NULL)) {
-
- if (((rv = ski_parsedev(dev, getenv("currdev"), NULL)) == 0) &&
- (path != NULL))
- *path = devspec;
- return(rv);
- }
-
- /*
- * Try to parse the device name off the beginning of the devspec
- */
- return(ski_parsedev(dev, devspec, path));
-}
-
-/*
- * Point (dev) at an allocated device specifier matching the string version
- * at the beginning of (devspec). Return a pointer to the remaining
- * text in (path).
- *
- * In all cases, the beginning of (devspec) is compared to the names
- * of known devices in the device switch, and then any following text
- * is parsed according to the rules applied to the device type.
- *
- * For disk-type devices, the syntax is:
- *
- * disk<unit>[s<slice>][<partition>]:
- *
- */
-static int
-ski_parsedev(struct ski_devdesc **dev, const char *devspec, const char **path)
-{
- struct ski_devdesc *idev;
- struct devsw *dv;
- int i, unit, slice, partition, err;
- char *cp;
- const char *np;
-
- /* minimum length check */
- if (strlen(devspec) < 2)
- return(EINVAL);
-
- /* look for a device that matches */
- for (i = 0, dv = NULL; devsw[i] != NULL; i++) {
- if (!strncmp(devspec, devsw[i]->dv_name, strlen(devsw[i]->dv_name))) {
- dv = devsw[i];
- break;
- }
- }
-
- if (dv == NULL)
- return(ENOENT);
- idev = malloc(sizeof(struct ski_devdesc));
- err = 0;
- np = (devspec + strlen(dv->dv_name));
-
- switch(dv->dv_type) {
- case DEVT_NONE: /* XXX what to do here? Do we care? */
- break;
-
- case DEVT_DISK:
- unit = -1;
- slice = -1;
- partition = -1;
- if (*np && (*np != ':')) {
- unit = strtol(np, &cp, 10); /* next comes the unit number */
- if (cp == np) {
- err = EUNIT;
- goto fail;
- }
- if (*cp == 's') { /* got a slice number */
- np = cp + 1;
- slice = strtol(np, &cp, 10);
- if (cp == np) {
- err = ESLICE;
- goto fail;
- }
- }
- if (*cp && (*cp != ':')) {
- partition = *cp - 'a'; /* get a partition number */
- if ((partition < 0) || (partition >= MAXPARTITIONS)) {
- err = EPART;
- goto fail;
- }
- cp++;
- }
- }
- if (*cp && (*cp != ':')) {
- err = EINVAL;
- goto fail;
- }
-
- idev->d_kind.skidisk.unit = unit;
- idev->d_kind.skidisk.slice = slice;
- idev->d_kind.skidisk.partition = partition;
-
- if (path != NULL)
- *path = (*cp == 0) ? cp : cp + 1;
- break;
-
- case DEVT_NET:
- unit = 0;
-
- if (*np && (*np != ':')) {
- unit = strtol(np, &cp, 0); /* get unit number if present */
- if (cp == np) {
- err = EUNIT;
- goto fail;
- }
- }
- if (*cp && (*cp != ':')) {
- err = EINVAL;
- goto fail;
- }
-
- idev->d_kind.netif.unit = unit;
- if (path != NULL)
- *path = (*cp == 0) ? cp : cp + 1;
- break;
-
- default:
- err = EINVAL;
- goto fail;
- }
- idev->d_dev = dv;
- idev->d_type = dv->dv_type;
- if (dev == NULL) {
- free(idev);
- } else {
- *dev = idev;
- }
- return(0);
-
- fail:
- free(idev);
- return(err);
-}
-
-
-char *
-ski_fmtdev(void *vdev)
-{
- struct ski_devdesc *dev = (struct ski_devdesc *)vdev;
- static char buf[128]; /* XXX device length constant? */
- char *cp;
-
- switch(dev->d_type) {
- case DEVT_NONE:
- strcpy(buf, "(no device)");
- break;
-
- case DEVT_DISK:
- cp = buf;
- cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_kind.skidisk.unit);
- if (dev->d_kind.skidisk.slice > 0)
- cp += sprintf(cp, "s%d", dev->d_kind.skidisk.slice);
- if (dev->d_kind.skidisk.partition >= 0)
- cp += sprintf(cp, "%c", dev->d_kind.skidisk.partition + 'a');
- strcat(cp, ":");
- break;
-
- case DEVT_NET:
- sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_kind.netif.unit);
- break;
- }
- return(buf);
-}
-
-
-/*
- * Set currdev to suit the value being supplied in (value)
- */
-int
-ski_setcurrdev(struct env_var *ev, int flags, void *value)
-{
- struct ski_devdesc *ncurr;
- int rv;
-
- if ((rv = ski_parsedev(&ncurr, value, NULL)) != 0)
- return(rv);
- free(ncurr);
- env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
- return(0);
-}
-
diff --git a/sys/boot/ia64/ski/efi_stub.c b/sys/boot/ia64/ski/efi_stub.c
deleted file mode 100644
index 36f72c3d2f63..000000000000
--- a/sys/boot/ia64/ski/efi_stub.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Copyright (c) 2003 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.
- * 2. Redistributions in binary form must 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.
- *
- * $FreeBSD$
- */
-
-#include <sys/types.h>
-#include <machine/bootinfo.h>
-#include <efi.h>
-#include <stand.h>
-#include "libski.h"
-
-extern void acpi_root;
-extern void sal_systab;
-
-extern void acpi_stub_init(void);
-extern void sal_stub_init(void);
-
-EFI_CONFIGURATION_TABLE efi_cfgtab[] = {
- { ACPI_20_TABLE_GUID, &acpi_root },
- { SAL_SYSTEM_TABLE_GUID, &sal_systab }
-};
-
-
-static EFI_STATUS GetTime(EFI_TIME *, EFI_TIME_CAPABILITIES *);
-static EFI_STATUS SetTime(EFI_TIME *);
-static EFI_STATUS GetWakeupTime(BOOLEAN *, BOOLEAN *, EFI_TIME *);
-static EFI_STATUS SetWakeupTime(BOOLEAN, EFI_TIME *);
-
-static EFI_STATUS SetVirtualAddressMap(UINTN, UINTN, UINT32,
- EFI_MEMORY_DESCRIPTOR*);
-static EFI_STATUS ConvertPointer(UINTN, VOID **);
-
-static EFI_STATUS GetVariable(CHAR16 *, EFI_GUID *, UINT32 *, UINTN *, VOID *);
-static EFI_STATUS GetNextVariableName(UINTN *, CHAR16 *, EFI_GUID *);
-static EFI_STATUS SetVariable(CHAR16 *, EFI_GUID *, UINT32, UINTN, VOID *);
-
-static EFI_STATUS GetNextHighMonotonicCount(UINT32 *);
-static EFI_STATUS ResetSystem(EFI_RESET_TYPE, EFI_STATUS, UINTN, CHAR16 *);
-
-EFI_RUNTIME_SERVICES efi_rttab = {
- /* Header. */
- { EFI_RUNTIME_SERVICES_SIGNATURE,
- EFI_RUNTIME_SERVICES_REVISION,
- 0, /* XXX HeaderSize */
- 0, /* XXX CRC32 */
- },
-
- /* Time services */
- GetTime,
- SetTime,
- GetWakeupTime,
- SetWakeupTime,
-
- /* Virtual memory services */
- SetVirtualAddressMap,
- ConvertPointer,
-
- /* Variable services */
- GetVariable,
- GetNextVariableName,
- SetVariable,
-
- /* Misc */
- GetNextHighMonotonicCount,
- ResetSystem
-};
-
-EFI_SYSTEM_TABLE efi_systab = {
- /* Header. */
- { EFI_SYSTEM_TABLE_SIGNATURE,
- EFI_SYSTEM_TABLE_REVISION,
- 0, /* XXX HeaderSize */
- 0, /* XXX CRC32 */
- },
-
- /* Firmware info. */
- L"FreeBSD", 0,
-
- /* Console stuff. */
- NULL, NULL,
- NULL, NULL,
- NULL, NULL,
-
- /* Services (runtime first). */
- &efi_rttab,
- NULL,
-
- /* Configuration tables. */
- sizeof(efi_cfgtab)/sizeof(EFI_CONFIGURATION_TABLE),
- efi_cfgtab
-};
-
-static EFI_STATUS
-unsupported(const char *func)
-{
- printf("EFI: %s not supported\n", func);
- return (EFI_UNSUPPORTED);
-}
-
-static EFI_STATUS
-GetTime(EFI_TIME *time, EFI_TIME_CAPABILITIES *caps)
-{
- UINT32 comps[8];
-
- ssc((UINT64)comps, 0, 0, 0, SSC_GET_RTC);
- time->Year = comps[0] + 1900;
- time->Month = comps[1] + 1;
- time->Day = comps[2];
- time->Hour = comps[3];
- time->Minute = comps[4];
- time->Second = comps[5];
- time->Pad1 = time->Pad2 = 0;
- time->Nanosecond = 0;
- time->TimeZone = 0;
- time->Daylight = 0;
- return (EFI_SUCCESS);
-}
-
-static EFI_STATUS
-SetTime(EFI_TIME *time)
-{
- return (EFI_SUCCESS);
-}
-
-static EFI_STATUS
-GetWakeupTime(BOOLEAN *enabled, BOOLEAN *pending, EFI_TIME *time)
-{
- return (unsupported(__func__));
-}
-
-static EFI_STATUS
-SetWakeupTime(BOOLEAN enable, EFI_TIME *time)
-{
- return (unsupported(__func__));
-}
-
-static void
-Reloc(void *addr, UINT64 delta)
-{
- UINT64 **fpp = addr;
-
- *fpp[0] += delta;
- *fpp[1] += delta;
- *fpp += delta >> 3;
-}
-
-static EFI_STATUS
-SetVirtualAddressMap(UINTN mapsz, UINTN descsz, UINT32 version,
- EFI_MEMORY_DESCRIPTOR *memmap)
-{
- UINT64 delta;
-
- delta = memmap->VirtualStart - memmap->PhysicalStart;
- Reloc(&efi_rttab.GetTime, delta);
- Reloc(&efi_rttab.SetTime, delta);
- return (EFI_SUCCESS); /* Hah... */
-}
-
-static EFI_STATUS
-ConvertPointer(UINTN debug, VOID **addr)
-{
- return (unsupported(__func__));
-}
-
-static EFI_STATUS
-GetVariable(CHAR16 *name, EFI_GUID *vendor, UINT32 *attrs, UINTN *datasz,
- VOID *data)
-{
- return (unsupported(__func__));
-}
-
-static EFI_STATUS
-GetNextVariableName(UINTN *namesz, CHAR16 *name, EFI_GUID *vendor)
-{
- return (unsupported(__func__));
-}
-
-static EFI_STATUS
-SetVariable(CHAR16 *name, EFI_GUID *vendor, UINT32 attrs, UINTN datasz,
- VOID *data)
-{
- return (unsupported(__func__));
-}
-
-static EFI_STATUS
-GetNextHighMonotonicCount(UINT32 *high)
-{
- static UINT32 counter = 0;
-
- *high = counter++;
- return (EFI_SUCCESS);
-}
-
-static EFI_STATUS
-ResetSystem(EFI_RESET_TYPE type, EFI_STATUS status, UINTN datasz,
- CHAR16 *data)
-{
- return (unsupported(__func__));
-}
-
-int
-ski_init_stubs(struct bootinfo *bi)
-{
- EFI_MEMORY_DESCRIPTOR *memp;
-
- /* Describe the SKI memory map. */
- bi->bi_memmap = (u_int64_t)(bi + 1);
- bi->bi_memmap_size = 4 * sizeof(EFI_MEMORY_DESCRIPTOR);
- bi->bi_memdesc_size = sizeof(EFI_MEMORY_DESCRIPTOR);
- bi->bi_memdesc_version = 1;
-
- memp = (EFI_MEMORY_DESCRIPTOR *)bi->bi_memmap;
-
- memp[0].Type = EfiPalCode;
- memp[0].PhysicalStart = 0x100000;
- memp[0].VirtualStart = 0;
- memp[0].NumberOfPages = (4L*1024*1024)>>12;
- memp[0].Attribute = EFI_MEMORY_WB | EFI_MEMORY_RUNTIME;
-
- memp[1].Type = EfiConventionalMemory;
- memp[1].PhysicalStart = 5L*1024*1024;
- memp[1].VirtualStart = 0;
- memp[1].NumberOfPages = (128L*1024*1024)>>12;
- memp[1].Attribute = EFI_MEMORY_WB;
-
- memp[2].Type = EfiConventionalMemory;
- memp[2].PhysicalStart = 4L*1024*1024*1024;
- memp[2].VirtualStart = 0;
- memp[2].NumberOfPages = (64L*1024*1024)>>12;
- memp[2].Attribute = EFI_MEMORY_WB;
-
- memp[3].Type = EfiMemoryMappedIOPortSpace;
- memp[3].PhysicalStart = 0xffffc000000;
- memp[3].VirtualStart = 0;
- memp[3].NumberOfPages = (64L*1024*1024)>>12;
- memp[3].Attribute = EFI_MEMORY_UC;
-
- bi->bi_systab = (u_int64_t)&efi_systab;
-
- sal_stub_init();
- acpi_stub_init();
-
- return (0);
-}
diff --git a/sys/boot/ia64/ski/elf_freebsd.c b/sys/boot/ia64/ski/elf_freebsd.c
deleted file mode 100644
index c6599a77a2b6..000000000000
--- a/sys/boot/ia64/ski/elf_freebsd.c
+++ /dev/null
@@ -1,205 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD: loadfile.c,v 1.10 1998/06/25 06:45:46 ross Exp $ */
-
-/*-
- * Copyright (c) 1997 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
- * NASA Ames Research Center.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Ralph Campbell.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)boot.c 8.1 (Berkeley) 6/10/93
- */
-
-#include <stand.h>
-#include <string.h>
-
-#include <sys/param.h>
-#include <sys/linker.h>
-#include <machine/elf.h>
-#include <machine/bootinfo.h>
-#include <machine/ia64_cpu.h>
-#include <machine/vmparam.h>
-
-#include "bootstrap.h"
-#include "libski.h"
-
-#define _KERNEL
-
-static int elf64_exec(struct preloaded_file *amp);
-
-struct file_format ia64_elf = { elf64_loadfile, elf64_exec };
-
-#define PTE_MA_WB 0
-#define PTE_MA_UC 4
-#define PTE_MA_UCE 5
-#define PTE_MA_WC 6
-#define PTE_MA_NATPAGE 7
-
-#define PTE_PL_KERN 0
-#define PTE_PL_USER 3
-
-#define PTE_AR_R 0
-#define PTE_AR_RX 1
-#define PTE_AR_RW 2
-#define PTE_AR_RWX 3
-#define PTE_AR_R_RW 4
-#define PTE_AR_RX_RWX 5
-#define PTE_AR_RWX_RW 6
-#define PTE_AR_X_RX 7
-
-/*
- * A short-format VHPT entry. Also matches the TLB insertion format.
- */
-struct ia64_pte {
- u_int64_t pte_p :1; /* bits 0..0 */
- u_int64_t pte_rv1 :1; /* bits 1..1 */
- u_int64_t pte_ma :3; /* bits 2..4 */
- u_int64_t pte_a :1; /* bits 5..5 */
- u_int64_t pte_d :1; /* bits 6..6 */
- u_int64_t pte_pl :2; /* bits 7..8 */
- u_int64_t pte_ar :3; /* bits 9..11 */
- u_int64_t pte_ppn :38; /* bits 12..49 */
- u_int64_t pte_rv2 :2; /* bits 50..51 */
- u_int64_t pte_ed :1; /* bits 52..52 */
- u_int64_t pte_ig :11; /* bits 53..63 */
-};
-
-static struct bootinfo bootinfo;
-
-void
-enter_kernel(const char* filename, u_int64_t start, struct bootinfo *bi)
-{
- printf("Entering %s at 0x%lx...\n", filename, start);
-
- while (*filename == '/')
- filename++;
- ssc(0, (u_int64_t) filename, 0, 0, SSC_LOAD_SYMBOLS);
-
- __asm __volatile("mov cr.ipsr=%0"
- :: "r"(IA64_PSR_IC
- | IA64_PSR_DT
- | IA64_PSR_RT
- | IA64_PSR_IT
- | IA64_PSR_BN));
- __asm __volatile("mov cr.iip=%0" :: "r"(start));
- __asm __volatile("mov cr.ifs=r0;;");
- __asm __volatile("mov r8=%0" :: "r" (bi));
- __asm __volatile("rfi;;");
-}
-
-static int
-elf64_exec(struct preloaded_file *fp)
-{
- struct file_metadata *md;
- Elf_Ehdr *hdr;
- struct ia64_pte pte;
- struct bootinfo *bi;
-
- if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)
- return(EFTYPE); /* XXX actually EFUCKUP */
- hdr = (Elf_Ehdr *)&(md->md_data);
-
- /*
- * Ugly hack, similar to linux. Dump the bootinfo into a
- * special page reserved in the link map.
- */
- bi = &bootinfo;
- bzero(bi, sizeof(struct bootinfo));
- bi_load(bi, fp);
-
- /*
- * Region 6 is direct mapped UC and region 7 is direct mapped
- * WC. The details of this is controlled by the Alt {I,D}TLB
- * handlers. Here we just make sure that they have the largest
- * possible page size to minimise TLB usage.
- */
- ia64_set_rr(IA64_RR_BASE(6), (6 << 8) | (28 << 2));
- ia64_set_rr(IA64_RR_BASE(7), (7 << 8) | (28 << 2));
-
- bzero(&pte, sizeof(pte));
- pte.pte_p = 1;
- pte.pte_ma = PTE_MA_WB;
- pte.pte_a = 1;
- pte.pte_d = 1;
- pte.pte_pl = PTE_PL_KERN;
- pte.pte_ar = PTE_AR_RWX;
- pte.pte_ppn = 0;
-
- __asm __volatile("mov cr.ifa=%0" :: "r"(IA64_RR_BASE(7)));
- __asm __volatile("mov cr.itir=%0" :: "r"(28 << 2));
- __asm __volatile("srlz.i;;");
- __asm __volatile("itr.i itr[%0]=%1;;"
- :: "r"(0), "r"(*(u_int64_t*)&pte));
- __asm __volatile("srlz.i;;");
- __asm __volatile("itr.d dtr[%0]=%1;;"
- :: "r"(0), "r"(*(u_int64_t*)&pte));
- __asm __volatile("srlz.i;;");
-
- enter_kernel(fp->f_name, hdr->e_entry, bi);
-}
diff --git a/sys/boot/ia64/ski/exit.c b/sys/boot/ia64/ski/exit.c
deleted file mode 100644
index aeac67c49341..000000000000
--- a/sys/boot/ia64/ski/exit.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * 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/time.h>
-#include <stddef.h>
-#include <stand.h>
-#include <stdarg.h>
-
-#include "libski.h"
-
-void
-exit(int code)
-{
- ssc(code, 0, 0, 0, SSC_EXIT);
-}
diff --git a/sys/boot/ia64/ski/ldscript.ia64 b/sys/boot/ia64/ski/ldscript.ia64
deleted file mode 100644
index cb35a4bc8d76..000000000000
--- a/sys/boot/ia64/ski/ldscript.ia64
+++ /dev/null
@@ -1,135 +0,0 @@
-/* $FreeBSD$ */
-OUTPUT_FORMAT("elf64-ia64-little", "elf64-ia64-little", "elf64-ia64-little")
-OUTPUT_ARCH(ia64)
-ENTRY(__start)
-SECTIONS
-{
- /* Read-only sections, merged into text segment: */
- . = 0x100000;
-
- .text :
- {
- *(.text.ivt)
- . += 8192;
- *(.text)
- *(.stub)
- /* .gnu.warning sections are handled specially by elf32.em. */
- *(.gnu.warning)
- *(.gnu.linkonce.t*)
- } =0x47ff041f
- .interp : { *(.interp) }
- .hash : { *(.hash) }
- .dynsym : { *(.dynsym) }
- .dynstr : { *(.dynstr) }
- .gnu.version : { *(.gnu.version) }
- .gnu.version_d : { *(.gnu.version_d) }
- .gnu.version_r : { *(.gnu.version_r) }
- .rel.text :
- { *(.rel.text) *(.rel.gnu.linkonce.t*) }
- .rela.text :
- { *(.rela.text) *(.rela.gnu.linkonce.t*) }
- .rel.data :
- { *(.rel.data) *(.rel.gnu.linkonce.d*) }
- .rela.data :
- { *(.rela.data) *(.rela.gnu.linkonce.d*) }
- .rel.rodata :
- { *(.rel.rodata) *(.rel.gnu.linkonce.r*) }
- .rela.rodata :
- { *(.rela.rodata) *(.rela.gnu.linkonce.r*) }
- .rel.got : { *(.rel.got) }
- .rela.got : { *(.rela.got) }
- .rel.ctors : { *(.rel.ctors) }
- .rela.ctors : { *(.rela.ctors) }
- .rel.dtors : { *(.rel.dtors) }
- .rela.dtors : { *(.rela.dtors) }
- .rel.init : { *(.rel.init) }
- .rela.init : { *(.rela.init) }
- .rel.fini : { *(.rel.fini) }
- .rela.fini : { *(.rela.fini) }
- .rel.bss : { *(.rel.bss) }
- .rela.bss : { *(.rela.bss) }
- .rel.plt : { *(.rel.plt) }
- .rela.plt : { *(.rela.plt) }
- .init : { *(.init) } =0x47ff041f
- _etext = .;
- PROVIDE (etext = .);
- .fini : { *(.fini) } =0x47ff041f
- .rodata : { *(.rodata) *(.gnu.linkonce.r*) }
- .rodata1 : { *(.rodata1) }
- .reginfo : { *(.reginfo) }
- /* Adjust the address for the data segment. We want to adjust up to
- the same address within the page on the next page up. */
- . = .;
- .data :
- {
- *(.data)
- *(.gnu.linkonce.d*)
- CONSTRUCTORS
- }
- .data1 : { *(.data1) }
- .ctors :
- {
- *(.ctors)
- }
- .dtors :
- {
- *(.dtors)
- }
- .plt : { *(.plt) }
- /* gp points at .got+(1<<21) */
- __gp = ALIGN(8) + 0x200000;
- .got : { *(.got.plt) *(.got) }
- .dynamic : { *(.dynamic) }
- /* We want the small data sections together, so single-instruction offsets
- can access them all, and initialized data all before uninitialized, so
- we can shorten the on-disk segment size. */
- .sdata : { *(.sdata) }
- _edata = .;
- PROVIDE (edata = .);
- __bss_start = .;
- .sbss : { *(.sbss) *(.scommon) }
- .bss :
- {
- *(.dynbss)
- *(.bss)
- *(COMMON)
- }
- . = ALIGN(64 / 8);
- _end = . ;
- PROVIDE (end = .);
- /* Stabs debugging sections. */
- .stab 0 : { *(.stab) }
- .stabstr 0 : { *(.stabstr) }
- .stab.excl 0 : { *(.stab.excl) }
- .stab.exclstr 0 : { *(.stab.exclstr) }
- .stab.index 0 : { *(.stab.index) }
- .stab.indexstr 0 : { *(.stab.indexstr) }
- .comment 0 : { *(.comment) }
- /* DWARF debug sections.
- Symbols in the DWARF debugging sections are relative to the beginning
- of the section so we begin them at 0. */
- /* DWARF 1 */
- .debug 0 : { *(.debug) }
- .line 0 : { *(.line) }
- /* GNU DWARF 1 extensions */
- .debug_srcinfo 0 : { *(.debug_srcinfo) }
- .debug_sfnames 0 : { *(.debug_sfnames) }
- /* DWARF 1.1 and DWARF 2 */
- .debug_aranges 0 : { *(.debug_aranges) }
- .debug_pubnames 0 : { *(.debug_pubnames) }
- /* DWARF 2 */
- .debug_info 0 : { *(.debug_info) }
- .debug_abbrev 0 : { *(.debug_abbrev) }
- .debug_line 0 : { *(.debug_line) }
- .debug_frame 0 : { *(.debug_frame) }
- .debug_str 0 : { *(.debug_str) }
- .debug_loc 0 : { *(.debug_loc) }
- .debug_macinfo 0 : { *(.debug_macinfo) }
- /* SGI/MIPS DWARF 2 extensions */
- .debug_weaknames 0 : { *(.debug_weaknames) }
- .debug_funcnames 0 : { *(.debug_funcnames) }
- .debug_typenames 0 : { *(.debug_typenames) }
- .debug_varnames 0 : { *(.debug_varnames) }
- /* These must appear regardless of . */
-}
-
diff --git a/sys/boot/ia64/ski/libski.h b/sys/boot/ia64/ski/libski.h
deleted file mode 100644
index 043177cd2acf..000000000000
--- a/sys/boot/ia64/ski/libski.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*-
- * Copyright (c) 2001 Doug Rabson
- * 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$
- */
-
-/*
- * SKI fully-qualified device descriptor
- */
-struct ski_devdesc {
- struct devsw *d_dev;
- int d_type;
-#define DEVT_NONE 0
-#define DEVT_DISK 1
-#define DEVT_NET 2
- union {
- struct {
- int unit;
- int slice;
- int partition;
- } skidisk;
- struct {
- int unit; /* XXX net layer lives over these? */
- } netif;
- } d_kind;
-};
-
-extern int ski_getdev(void **vdev, const char *devspec, const char **path);
-extern char *ski_fmtdev(void *vdev);
-extern int ski_setcurrdev(struct env_var *ev, int flags, void *value);
-
-#define MAXDEV 31 /* maximum number of distinct devices */
-
-typedef unsigned long physaddr_t;
-
-/* exported devices XXX rename? */
-extern struct devsw skifs_dev;
-extern struct devsw ski_disk;
-extern struct netif_driver ski_net;
-
-/* Wrapper over SKI filesystems. */
-extern struct fs_ops ski_fsops;
-
-/* this is in startup code */
-extern void delay(int);
-extern void reboot(void);
-
-extern ssize_t ski_copyin(const void *src, vm_offset_t dest, size_t len);
-extern ssize_t ski_copyout(const vm_offset_t src, void *dest, size_t len);
-extern ssize_t ski_readin(int fd, vm_offset_t dest, size_t len);
-
-extern int ski_boot(void);
-extern int ski_autoload(void);
-
-struct bootinfo;
-struct preloaded_file;
-extern int bi_load(struct bootinfo *, struct preloaded_file *);
-
-#define SSC_CONSOLE_INIT 20
-#define SSC_GETCHAR 21
-#define SSC_PUTCHAR 31
-#define SSC_OPEN 50
-#define SSC_CLOSE 51
-#define SSC_READ 52
-#define SSC_WRITE 53
-#define SSC_GET_COMPLETION 54
-#define SSC_WAIT_COMPLETION 55
-#define SSC_GET_RTC 65
-#define SSC_EXIT 66
-#define SSC_LOAD_SYMBOLS 69
-#define SSC_SAL_SET_VECTORS 120
-
-u_int64_t ssc(u_int64_t in0, u_int64_t in1, u_int64_t in2, u_int64_t in3,
- int which);
diff --git a/sys/boot/ia64/ski/main.c b/sys/boot/ia64/ski/main.c
deleted file mode 100644
index c4b22250a863..000000000000
--- a/sys/boot/ia64/ski/main.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/*-
- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
- * Copyright (c) 1998,2000 Doug Rabson <dfr@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stand.h>
-#include <string.h>
-#include <setjmp.h>
-#include <machine/fpu.h>
-
-#include "bootstrap.h"
-#include "libski.h"
-
-extern char bootprog_name[];
-extern char bootprog_rev[];
-extern char bootprog_date[];
-extern char bootprog_maker[];
-
-struct ski_devdesc currdev; /* our current device */
-struct arch_switch archsw; /* MI/MD interface boundary */
-
-void
-__start(void)
-{
- static char stack[16384] __aligned(16);
- static char malloc[512*1024];
- int i;
-
- __asm __volatile("movl gp=__gp;;");
- __asm __volatile("mov sp=%0" :: "r"(&stack[16384]));
- __asm __volatile("bsw.1;;");
- __asm __volatile("mov ar.fpsr=%0" :: "r"(IA64_FPSR_DEFAULT));
-
- /*
- * initialise the heap as early as possible. Once this is done,
- * alloc() is usable. The stack is buried inside us, so this is
- * safe.
- */
- setheap((void *)malloc, (void *)(malloc + 512*1024));
-
- /*
- * XXX Chicken-and-egg problem; we want to have console output
- * early, but some console attributes may depend on reading from
- * eg. the boot device, which we can't do yet. We can use
- * printf() etc. once this is done.
- */
- cons_probe();
-
- /*
- * Initialise the block cache
- */
- bcache_init(32, 512); /* 16k XXX tune this */
-
- /*
- * March through the device switch probing for things.
- */
- for (i = 0; devsw[i] != NULL; i++)
- if (devsw[i]->dv_init != NULL)
- (devsw[i]->dv_init)();
-
- printf("\n");
- printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
- printf("(%s, %s)\n", bootprog_maker, bootprog_date);
-#if 0
- printf("Memory: %ld k\n", memsize() / 1024);
-#endif
-
- /* XXX presumes that biosdisk is first in devsw */
- currdev.d_dev = devsw[0];
- currdev.d_type = currdev.d_dev->dv_type;
- currdev.d_kind.skidisk.unit = 0;
- /* XXX should be able to detect this, default to autoprobe */
- currdev.d_kind.skidisk.slice = -1;
- /* default to 'a' */
- currdev.d_kind.skidisk.partition = 0;
-
-#if 0
- /* Create arc-specific variables */
- bootfile = GetEnvironmentVariable(ARCENV_BOOTFILE);
- if (bootfile)
- setenv("bootfile", bootfile, 1);
-#endif
-
- env_setenv("currdev", EV_VOLATILE, ski_fmtdev(&currdev),
- ski_setcurrdev, env_nounset);
- env_setenv("loaddev", EV_VOLATILE, ski_fmtdev(&currdev), env_noset,
- env_nounset);
-
- setenv("LINES", "24", 1); /* optional */
-
- archsw.arch_autoload = ski_autoload;
- archsw.arch_getdev = ski_getdev;
- archsw.arch_copyin = ski_copyin;
- archsw.arch_copyout = ski_copyout;
- archsw.arch_readin = ski_readin;
-
- interact(); /* doesn't return */
-
- exit(0);
-}
-
-COMMAND_SET(quit, "quit", "exit the loader", command_quit);
-
-static int
-command_quit(int argc, char *argv[])
-{
- exit(0);
- return (CMD_OK);
-}
diff --git a/sys/boot/ia64/ski/pal_stub.S b/sys/boot/ia64/ski/pal_stub.S
deleted file mode 100644
index e67204c4b30a..000000000000
--- a/sys/boot/ia64/ski/pal_stub.S
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2003 Marcel Moolenaar
- * Copyright (c) 2001 Doug Rabson
- * 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$
- */
-
-#include <machine/asm.h>
-
- .text
-ENTRY(PalProc, 0)
- cmp.eq p6,p0=6,r28 // PAL_PTCE_INFO
-(p6) br.cond.dptk pal_ptce_info
- ;;
- cmp.eq p6,p0=8,r28 // PAL_VM_SUMMARY
-(p6) br.cond.dptk pal_vm_summary
- ;;
- cmp.eq p6,p0=14,r28 // PAL_FREQ_RATIOS
-(p6) br.cond.dptk pal_freq_ratios
- ;;
- mov r15=66 // EXIT
- break.i 0x80000 // SSC
- ;;
-pal_ptce_info:
- mov r8=0
- mov r9=0 // base
- movl r10=0x0000000100000001 // loop counts (outer|inner)
- mov r11=0x0000000000000000 // loop strides (outer|inner)
- br.sptk b0
-pal_vm_summary:
- mov r8=0
- movl r9=(8<<40)|(8<<32) // VM info 1
- mov r10=(18<<8)|(41<<0) // VM info 2
- mov r11=0
- br.sptk b0
-pal_freq_ratios:
- mov r8=0
- movl r9=0x0000000B00000002 // processor ratio 11/2
- movl r10=0x0000000100000001 // bus ratio 1/1
- movl r11=0x0000000B00000002 // ITC ratio 11/2
- br.sptk b0
-END(PalProc)
diff --git a/sys/boot/ia64/ski/sal_stub.c b/sys/boot/ia64/ski/sal_stub.c
deleted file mode 100644
index caa6671f6191..000000000000
--- a/sys/boot/ia64/ski/sal_stub.c
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (c) 2003 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.
- * 2. Redistributions in binary form must 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.
- *
- * $FreeBSD$
- */
-
-#include <sys/types.h>
-#include <machine/md_var.h>
-#include <machine/sal.h>
-#include <stand.h>
-#include "libski.h"
-
-extern void PalProc(void);
-static sal_entry_t SalProc;
-
-struct {
- struct sal_system_table header;
- struct sal_entrypoint_descriptor entry;
- struct sal_ap_wakeup_descriptor wakeup;
-} sal_systab = {
- /* Header. */
- {
- SAL_SIGNATURE,
- sizeof(sal_systab),
- { 00, 03 }, /* Revision 3.0. */
- 2, /* Number of decsriptors. */
- 0, /* XXX checksum. */
- { 0 },
- { 00, 00 }, /* XXX SAL_A version. */
- { 00, 00 }, /* XXX SAL_B version. */
- "FreeBSD",
- "Ski loader",
- { 0 }
- },
- /* Entrypoint. */
- {
- 0, /* Type=entrypoint descr. */
- { 0 },
- 0, /* XXX PalProc. */
- 0, /* XXX SalProc. */
- 0, /* XXX SalProc GP. */
- { 0 }
- },
- /* AP wakeup. */
- {
- 5, /* Type=AP wakeup descr. */
- 0, /* External interrupt. */
- { 0 },
- 255 /* Wakeup vector. */
- }
-};
-
-static inline void
-puts(const char *s)
-{
- s = (const char *)((7UL << 61) | (u_long)s);
- while (*s)
- ski_cons_putchar(*s++);
-}
-
-static struct ia64_sal_result
-SalProc(u_int64_t a1, u_int64_t a2, u_int64_t a3, u_int64_t a4, u_int64_t a5,
- u_int64_t a6, u_int64_t a7, u_int64_t a8)
-{
- struct ia64_sal_result res;
-
- res.sal_status = -3;
- res.sal_result[0] = 0;
- res.sal_result[1] = 0;
- res.sal_result[2] = 0;
-
- if (a1 == SAL_FREQ_BASE) {
- res.sal_status = 0;
- res.sal_result[0] = 133338184;
- } else if (a1 == SAL_SET_VECTORS) {
- /* XXX unofficial SSC function. */
- ssc(a2, a3, a4, a5, SSC_SAL_SET_VECTORS);
- } else if (a1 != SAL_GET_STATE_INFO_SIZE) {
- puts("SAL: unimplemented function called\n");
- }
-
- return (res);
-}
-
-void
-sal_stub_init(void)
-{
- struct ia64_fdesc *fd;
-
- fd = (void*)PalProc;
- sal_systab.entry.sale_pal_proc = fd->func;
- fd = (void*)SalProc;
- sal_systab.entry.sale_sal_proc = fd->func;
- sal_systab.entry.sale_sal_gp = fd->gp;
-}
diff --git a/sys/boot/ia64/ski/skiconsole.c b/sys/boot/ia64/ski/skiconsole.c
deleted file mode 100644
index e5cea3dc9936..000000000000
--- a/sys/boot/ia64/ski/skiconsole.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * 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 <stand.h>
-
-#include "bootstrap.h"
-#include "libski.h"
-
-static void
-ski_cons_probe(struct console *cp)
-{
- cp->c_flags |= C_PRESENTIN | C_PRESENTOUT;
-}
-
-static int
-ski_cons_init(int arg)
-{
- ssc(0, 0, 0, 0, SSC_CONSOLE_INIT);
- return 0;
-}
-
-void
-ski_cons_putchar(int c)
-{
- ssc(c, 0, 0, 0, SSC_PUTCHAR);
-}
-
-static int pollchar = -1;
-
-int
-ski_cons_getchar()
-{
- int c;
-
- if (pollchar > 0) {
- c = pollchar;
- pollchar = -1;
- return c;
- }
-
- do {
- c = ssc(0, 0, 0, 0, SSC_GETCHAR);
- } while (c == 0);
-
- return c;
-}
-
-int
-ski_cons_poll()
-{
- int c;
- if (pollchar > 0)
- return 1;
- c = ssc(0, 0, 0, 0, SSC_GETCHAR);
- if (!c)
- return 0;
- pollchar = c;
- return 1;
-}
-
-struct console ski_console = {
- "ski",
- "ia64 SKI console",
- 0,
- ski_cons_probe,
- ski_cons_init,
- ski_cons_putchar,
- ski_cons_getchar,
- ski_cons_poll
-};
diff --git a/sys/boot/ia64/ski/skifs.c b/sys/boot/ia64/ski/skifs.c
deleted file mode 100644
index d5b0ee9f57dc..000000000000
--- a/sys/boot/ia64/ski/skifs.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/*-
- * Copyright (c) 2001 Doug Rabson
- * 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$
- */
-
-#include <sys/param.h>
-#include <sys/time.h>
-#include <stddef.h>
-#include <stand.h>
-#include <stdarg.h>
-
-#include "libski.h"
-
-struct disk_req {
- unsigned long addr;
- unsigned len;
-};
-
-struct disk_stat {
- int fd;
- unsigned count;
-};
-
-static int
-skifs_open(const char *path, struct open_file *f)
-{
- int fd;
-
- /*
- * Skip leading '/' so that our pretend filesystem starts in
- * the current working directory.
- */
- while (*path == '/')
- path++;
-
- fd = ssc((u_int64_t) path, 1, 0, 0, SSC_OPEN);
- if (fd > 0) {
- f->f_fsdata = (void*)(u_int64_t) fd;
- return 0;
- }
- return ENOENT;
-}
-
-static int
-skifs_close(struct open_file *f)
-{
- ssc((u_int64_t) f->f_fsdata, 0, 0, 0, SSC_CLOSE);
- return 0;
-}
-
-static int
-skifs_read(struct open_file *f, void *buf, size_t size, size_t *resid)
-{
- struct disk_req req;
- struct disk_stat stat;
-
- req.len = size;
- req.addr = (u_int64_t) buf;
- ssc((u_int64_t) f->f_fsdata, 1, (u_int64_t) &req, f->f_offset, SSC_READ);
- stat.fd = (u_int64_t) f->f_fsdata;
- ssc((u_int64_t)&stat, 0, 0, 0, SSC_WAIT_COMPLETION);
-
- *resid = size - stat.count;
- f->f_offset += stat.count;
- return 0;
-}
-
-static off_t
-skifs_seek(struct open_file *f, off_t offset, int where)
-{
- u_int64_t base;
-
- switch (where) {
- case SEEK_SET:
- base = 0;
- break;
-
- case SEEK_CUR:
- base = f->f_offset;
- break;
-
- case SEEK_END:
- printf("can't find end of file in SKI\n");
- base = f->f_offset;
- break;
- }
-
- f->f_offset = base + offset;
- return base;
-}
-
-static int
-skifs_stat(struct open_file *f, struct stat *sb)
-{
- bzero(sb, sizeof(*sb));
- sb->st_mode = S_IFREG | S_IRUSR;
- return 0;
-}
-
-static int
-skifs_readdir(struct open_file *f, struct dirent *d)
-{
- return ENOENT;
-}
-
-struct fs_ops ski_fsops = {
- "fs",
- skifs_open,
- skifs_close,
- skifs_read,
- null_write,
- skifs_seek,
- skifs_stat,
- skifs_readdir
-};
-
-static int
-skifs_dev_init(void)
-{
- return 0;
-}
-
-/*
- * Print information about disks
- */
-static void
-skifs_dev_print(int verbose)
-{
-}
-
-/*
- * Attempt to open the disk described by (dev) for use by (f).
- *
- * Note that the philosophy here is "give them exactly what
- * they ask for". This is necessary because being too "smart"
- * about what the user might want leads to complications.
- * (eg. given no slice or partition value, with a disk that is
- * sliced - are they after the first BSD slice, or the DOS
- * slice before it?)
- */
-static int
-skifs_dev_open(struct open_file *f, ...)
-{
- return 0;
-}
-
-static int
-skifs_dev_close(struct open_file *f)
-{
-
- return 0;
-}
-
-static int
-skifs_dev_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize)
-{
- return 0;
-}
-
-struct devsw skifs_dev = {
- "fs",
- DEVT_DISK,
- skifs_dev_init,
- skifs_dev_strategy,
- skifs_dev_open,
- skifs_dev_close,
- noioctl,
- skifs_dev_print
-};
diff --git a/sys/boot/ia64/ski/skiload.cmd b/sys/boot/ia64/ski/skiload.cmd
deleted file mode 100644
index 48b77e1e40ba..000000000000
--- a/sys/boot/ia64/ski/skiload.cmd
+++ /dev/null
@@ -1,16 +0,0 @@
-# $FreeBSD$
-iar
-fr
-pa
-b enter_kernel
-c
-b printf
-c
-b rp
-c
-b ssc
-c
-b rp
-c
-bD
-s 11
diff --git a/sys/boot/ia64/ski/ssc.c b/sys/boot/ia64/ski/ssc.c
deleted file mode 100644
index e3e9eb23e683..000000000000
--- a/sys/boot/ia64/ski/ssc.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*-
- * Copyright (c) 2001 Doug Rabson
- * 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$
- */
-
-#include <stand.h>
-#include "libski.h"
-
-/*
- * Ugh... Work around a bug in the Linux version of ski for SSC_GET_RTC. The
- * PSR.dt register is not preserved properly and causes further memory
- * references to be done without translation. All we need to do is preserve
- * PSR.dt across the SSC call. We do this by saving and restoring psr.l
- * completely.
- */
-u_int64_t
-ssc(u_int64_t in0, u_int64_t in1, u_int64_t in2, u_int64_t in3, int which)
-{
- register u_int64_t psr;
- register u_int64_t ret0 __asm("r8");
-
- __asm __volatile("mov %0=psr;;" : "=r"(psr));
- __asm __volatile("mov r15=%1\n\t"
- "break 0x80000;;"
- : "=r"(ret0)
- : "r"(which), "r"(in0), "r"(in1), "r"(in2), "r"(in3));
- __asm __volatile("mov psr.l=%0;; srlz.d" :: "r"(psr));
- return ret0;
-}
diff --git a/sys/boot/ia64/ski/time.c b/sys/boot/ia64/ski/time.c
deleted file mode 100644
index b682c2d3018a..000000000000
--- a/sys/boot/ia64/ski/time.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Copyright (c) 1999, 2000
- * Intel Corporation.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- *
- * This product includes software developed by Intel Corporation and
- * its contributors.
- *
- * 4. Neither the name of Intel Corporation or its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (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 <time.h>
-#include <sys/time.h>
-#include <stand.h>
-
-#include "libski.h"
-
-/*
-// Accurate only for the past couple of centuries;
-// that will probably do.
-//
-// (#defines From FreeBSD 3.2 lib/libc/stdtime/tzfile.h)
-*/
-
-#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
-#define SECSPERHOUR ( 60*60 )
-#define SECSPERDAY (24 * SECSPERHOUR)
-
-struct ssc_time {
- int Year;
- int Month;
- int Day;
- int Hour;
- int Minute;
- int Second;
- int Msec;
- int Wday;
-};
-
-time_t
-EfiTimeToUnixTime(struct ssc_time *ETime)
-{
- /*
- // These arrays give the cumulative number of days up to the first of the
- // month number used as the index (1 -> 12) for regular and leap years.
- // The value at index 13 is for the whole year.
- */
- static time_t CumulativeDays[2][14] = {
- {0,
- 0,
- 31,
- 31 + 28,
- 31 + 28 + 31,
- 31 + 28 + 31 + 30,
- 31 + 28 + 31 + 30 + 31,
- 31 + 28 + 31 + 30 + 31 + 30,
- 31 + 28 + 31 + 30 + 31 + 30 + 31,
- 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
- 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
- 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
- 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
- 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 },
- {0,
- 0,
- 31,
- 31 + 29,
- 31 + 29 + 31,
- 31 + 29 + 31 + 30,
- 31 + 29 + 31 + 30 + 31,
- 31 + 29 + 31 + 30 + 31 + 30,
- 31 + 29 + 31 + 30 + 31 + 30 + 31,
- 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31,
- 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
- 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
- 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
- 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 }};
-
- time_t UTime;
- int Year;
-
- ETime->Year += 1900;
-
- /*
- // Do a santity check
- */
- if ( ETime->Year < 1998 || ETime->Year > 2099 ||
- ETime->Month == 0 || ETime->Month > 12 ||
- ETime->Day == 0 || ETime->Month > 31 ||
- ETime->Hour > 23 ||
- ETime->Minute > 59 ||
- ETime->Second > 59 ) {
- return (0);
- }
-
- /*
- // Years
- */
- UTime = 0;
- for (Year = 1970; Year != ETime->Year; ++Year) {
- UTime += (CumulativeDays[isleap(Year)][13] * SECSPERDAY);
- }
-
- /*
- // UTime should now be set to 00:00:00 on Jan 1 of the file's year.
- //
- // Months
- */
- UTime += (CumulativeDays[isleap(ETime->Year)][ETime->Month] * SECSPERDAY);
-
- /*
- // UTime should now be set to 00:00:00 on the first of the file's month and year
- //
- // Days -- Don't count the file's day
- */
- UTime += (((ETime->Day > 0) ? ETime->Day-1:0) * SECSPERDAY);
-
- /*
- // Hours
- */
- UTime += (ETime->Hour * SECSPERHOUR);
-
- /*
- // Minutes
- */
- UTime += (ETime->Minute * 60);
-
- /*
- // Seconds
- */
- UTime += ETime->Second;
-
- return UTime;
-}
-
-time_t
-time(time_t *tloc)
-{
- struct ssc_time time;
-
- ssc((u_int64_t) &time, 0, 0, 0, SSC_GET_RTC);
-
- return *tloc = EfiTimeToUnixTime(&time);
-}
diff --git a/sys/boot/ia64/ski/version b/sys/boot/ia64/ski/version
deleted file mode 100644
index 6f4fc3c28a46..000000000000
--- a/sys/boot/ia64/ski/version
+++ /dev/null
@@ -1,8 +0,0 @@
-$FreeBSD$
-
-NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE. The format of this
-file is important. Make sure the current version number is on line 6.
-
-0.2: Pass the address of the bootinfo block to the kernel in register
- r8. Keep it at the hardwired address for now.
-0.1: Initial SKI version.
diff --git a/sys/boot/pc98/btx/btx/btx.S b/sys/boot/pc98/btx/btx/btx.S
deleted file mode 100644
index cd35fffe95b7..000000000000
--- a/sys/boot/pc98/btx/btx/btx.S
+++ /dev/null
@@ -1,1306 +0,0 @@
-#
-# Copyright (c) 1998 Robert Nordier
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms are freely
-# permitted provided that the above copyright notice and this
-# paragraph and the following disclaimer are duplicated in all
-# such forms.
-#
-# This software is provided "AS IS" and without any express or
-# implied warranties, including, without limitation, the implied
-# warranties of merchantability and fitness for a particular
-# purpose.
-#
-
-# $FreeBSD$
-
-#
-# Memory layout.
-#
- .set MEM_BTX,0x1000 # Start of BTX memory
- .set MEM_ESP0,0x1800 # Supervisor stack
- .set MEM_BUF,0x1800 # Scratch buffer
- .set MEM_ESP1,0x1e00 # Link stack
- .set MEM_IDT,0x1e00 # IDT
- .set MEM_TSS,0x1f98 # TSS
- .set MEM_MAP,0x2000 # I/O bit map
- .set MEM_DIR,0x4000 # Page directory
- .set MEM_TBL,0x5000 # Page tables
- .set MEM_ORG,0x9000 # BTX code
- .set MEM_USR,0xa000 # Start of user memory
-#
-# Paging control.
-#
- .set PAG_SIZ,0x1000 # Page size
- .set PAG_CNT,0x1000 # Pages to map
-#
-# Segment selectors.
-#
- .set SEL_SCODE,0x8 # Supervisor code
- .set SEL_SDATA,0x10 # Supervisor data
- .set SEL_RCODE,0x18 # Real mode code
- .set SEL_RDATA,0x20 # Real mode data
- .set SEL_UCODE,0x28|3 # User code
- .set SEL_UDATA,0x30|3 # User data
- .set SEL_TSS,0x38 # TSS
-#
-# Task state segment fields.
-#
- .set TSS_ESP0,0x4 # PL 0 ESP
- .set TSS_SS0,0x8 # PL 0 SS
- .set TSS_ESP1,0xc # PL 1 ESP
- .set TSS_MAP,0x66 # I/O bit map base
-#
-# System calls.
-#
- .set SYS_EXIT,0x0 # Exit
- .set SYS_EXEC,0x1 # Exec
-#
-# V86 constants.
-#
- .set V86_FLG,0x208eff # V86 flag mask
- .set V86_STK,0x400 # V86 stack allowance
-#
-# Dump format control bytes.
-#
- .set DMP_X16,0x1 # Word
- .set DMP_X32,0x2 # Long
- .set DMP_MEM,0x4 # Memory
- .set DMP_EOL,0x8 # End of line
-#
-# Screen defaults and assumptions.
-#
-.`ifdef' PC98
- .set SCR_MAT,0xe1 # Mode/attribute
-.else
- .set SCR_MAT,0x7 # Mode/attribute
-.endif
- .set SCR_COL,0x50 # Columns per row
- .set SCR_ROW,0x19 # Rows per screen
-#
-# BIOS Data Area locations.
-#
-.`ifdef' PC98
- .set BDA_MEM,0x501 # Free memory
- .set BDA_KEYFLAGS,0x53a # Keyboard shift-state flags
- .set BDA_POS,0x53e # Cursor position
-.else
- .set BDA_MEM,0x413 # Free memory
- .set BDA_KEYFLAGS,0x417 # Keyboard shift-state flags
- .set BDA_SCR,0x449 # Video mode
- .set BDA_POS,0x450 # Cursor position
- .set BDA_BOOT,0x472 # Boot howto flag
-.endif
-#
-# Derivations, for brevity.
-#
- .set _ESP0H,MEM_ESP0>>0x8 # Byte 1 of ESP0
- .set _ESP1H,MEM_ESP1>>0x8 # Byte 1 of ESP1
- .set _TSSIO,MEM_MAP-MEM_TSS # TSS I/O base
- .set _TSSLM,MEM_DIR-MEM_TSS-1 # TSS limit
- .set _IDTLM,MEM_TSS-MEM_IDT-1 # IDT limit
-#
-# Code segment.
-#
- .globl start
- .code16
-start: # Start of code
-#
-# BTX header.
-#
-btx_hdr: .byte 0xeb # Machine ID
- .byte 0xe # Header size
- .ascii "BTX" # Magic
- .byte 0x1 # Major version
- .byte 0x1 # Minor version
- .byte BTX_FLAGS # Flags
- .word PAG_CNT-MEM_ORG>>0xc # Paging control
- .word break-start # Text size
- .long 0x0 # Entry address
-#
-# Initialization routine.
-#
-init: cli # Disable interrupts
- xor %ax,%ax # Zero/segment
- mov %ax,%ss # Set up
- mov $MEM_ESP0,%sp # stack
- mov %ax,%es # Address
- mov %ax,%ds # data
- pushl $0x2 # Clear
- popfl # flags
-#
-# Initialize memory.
-#
- mov $MEM_IDT,%di # Memory to initialize
- mov $(MEM_ORG-MEM_IDT)/2,%cx # Words to zero
- push %di # Save
- rep # Zero-fill
- stosw # memory
- pop %di # Restore
-#
-# Create IDT.
-#
- mov $idtctl,%si # Control string
-init.1: lodsb # Get entry
- cbw # count
- xchg %ax,%cx # as word
- jcxz init.4 # If done
- lodsb # Get segment
- xchg %ax,%dx # P:DPL:type
- lodsw # Get control
- xchg %ax,%bx # set
- lodsw # Get handler offset
- mov $SEL_SCODE,%dh # Segment selector
-init.2: shr %bx # Handle this int?
- jnc init.3 # No
- mov %ax,(%di) # Set handler offset
- mov %dh,0x2(%di) # and selector
- mov %dl,0x5(%di) # Set P:DPL:type
- add $0x4,%ax # Next handler
-init.3: lea 0x8(%di),%di # Next entry
- loop init.2 # Till set done
- jmp init.1 # Continue
-#
-# Initialize TSS.
-#
-init.4: movb $_ESP0H,TSS_ESP0+1(%di) # Set ESP0
- movb $SEL_SDATA,TSS_SS0(%di) # Set SS0
- movb $_ESP1H,TSS_ESP1+1(%di) # Set ESP1
- movb $_TSSIO,TSS_MAP(%di) # Set I/O bit map base
-ifdef(`PAGING',`
-#
-# Create page directory.
-#
- xor %edx,%edx # Page
- mov $PAG_SIZ>>0x8,%dh # size
- xor %eax,%eax # Zero
- mov $MEM_DIR,%di # Page directory
- mov $PAG_CNT>>0xa,%cl # Entries
- mov $MEM_TBL|0x7,%ax # First entry
-init.5: stosl # Write entry
- add %dx,%ax # To next
- loop init.5 # Till done
-#
-# Create page tables.
-#
- mov $MEM_TBL,%di # Page table
- mov $PAG_CNT>>0x8,%ch # Entries
- xor %ax,%ax # Start address
-init.6: mov $0x7,%al # Set U:W:P flags
- cmp btx_hdr+0x8,%cx # Standard user page?
- jb init.7 # Yes
- cmp $PAG_CNT-MEM_BTX>>0xc,%cx # BTX memory?
- jae init.7 # No or first page
- and $~0x2,%al # Clear W flag
- cmp $PAG_CNT-MEM_USR>>0xc,%cx # User page zero?
- jne init.7 # No
- testb $0x80,btx_hdr+0x7 # Unmap it?
- jz init.7 # No
- and $~0x1,%al # Clear P flag
-init.7: stosl # Set entry
- add %edx,%eax # Next address
- loop init.6 # Till done
-')
-#
-# Bring up the system.
-#
- mov $0x2820,%bx # Set protected mode
- callw setpic # IRQ offsets
- lidt idtdesc # Set IDT
-ifdef(`PAGING',`
- xor %eax,%eax # Set base
- mov $MEM_DIR>>0x8,%ah # of page
- mov %eax,%cr3 # directory
-')
- lgdt gdtdesc # Set GDT
- mov %cr0,%eax # Switch to protected
-ifdef(`PAGING',`
- or $0x80000001,%eax # mode and enable paging
-',`
- or $0x01,%eax # mode
-')
- mov %eax,%cr0 #
- ljmp $SEL_SCODE,$init.8 # To 32-bit code
- .code32
-init.8: xorl %ecx,%ecx # Zero
- movb $SEL_SDATA,%cl # To 32-bit
- movw %cx,%ss # stack
-#
-# Launch user task.
-#
- movb $SEL_TSS,%cl # Set task
- ltr %cx # register
- movl $MEM_USR,%edx # User base address
- movzwl %ss:BDA_MEM,%eax # Get free memory
-.`ifdef' PC98
- andl $0x7,%eax
- incl %eax
- shll $0x11,%eax # To bytes
-.else
- shll $0xa,%eax # To bytes
-.endif
- subl $0x1000,%eax # Less arg space
- subl %edx,%eax # Less base
- movb $SEL_UDATA,%cl # User data selector
- pushl %ecx # Set SS
- pushl %eax # Set ESP
- push $0x202 # Set flags (IF set)
- push $SEL_UCODE # Set CS
- pushl btx_hdr+0xc # Set EIP
- pushl %ecx # Set GS
- pushl %ecx # Set FS
- pushl %ecx # Set DS
- pushl %ecx # Set ES
- pushl %edx # Set EAX
- movb $0x7,%cl # Set remaining
-init.9: push $0x0 # general
- loop init.9 # registers
-ifdef(`BTX_SERIAL',`
- call sio_init # setup the serial console
-')
- popa # and initialize
- popl %es # Initialize
- popl %ds # user
- popl %fs # segment
- popl %gs # registers
- iret # To user mode
-#
-# Exit routine.
-#
-exit: cli # Disable interrupts
- movl $MEM_ESP0,%esp # Clear stack
-#
-# Turn off paging.
-#
- movl %cr0,%eax # Get CR0
- andl $~0x80000000,%eax # Disable
- movl %eax,%cr0 # paging
- xorl %ecx,%ecx # Zero
- movl %ecx,%cr3 # Flush TLB
-#
-# Restore the GDT in case we caught a kernel trap.
-#
- lgdt gdtdesc # Set GDT
-#
-# To 16 bits.
-#
- ljmpw $SEL_RCODE,$exit.1 # Reload CS
- .code16
-exit.1: mov $SEL_RDATA,%cl # 16-bit selector
- mov %cx,%ss # Reload SS
- mov %cx,%ds # Load
- mov %cx,%es # remaining
- mov %cx,%fs # segment
- mov %cx,%gs # registers
-#
-# To real-address mode.
-#
- dec %ax # Switch to
- mov %eax,%cr0 # real mode
- ljmp $0x0,$exit.2 # Reload CS
-exit.2: xor %ax,%ax # Real mode segment
- mov %ax,%ss # Reload SS
- mov %ax,%ds # Address data
-.`ifdef' PC98
- mov $0x1008,%bx # Set real mode
-.else
- mov $0x7008,%bx # Set real mode
-.endif
- callw setpic # IRQ offsets
- lidt ivtdesc # Set IVT
-#
-# Reboot or await reset.
-#
- sti # Enable interrupts
- testb $0x1,btx_hdr+0x7 # Reboot?
-exit.3: jz exit.3 # No
-.`ifdef' PC98
- movb $0xa0,%al
- outb %al,$0x35
- movb 0,%al
- outb %al,$0xf0
-exit.4: jmp exit.4
-.else
- movw $0x1234, BDA_BOOT # Do a warm boot
- ljmp $0xffff,$0x0 # reboot the machine
-.endif
-#
-# Set IRQ offsets by reprogramming 8259A PICs.
-#
-.`ifdef' PC98
-setpic: in $0x02,%al # Save master
- push %ax # IMR
- in $0x0a,%al # Save slave
- push %ax # IMR
- movb $0x11,%al # ICW1 to
- outb %al,$0x00 # master,
- outb %al,$0x08 # slave
- movb %bl,%al # ICW2 to
- outb %al,$0x02 # master
- movb %bh,%al # ICW2 to
- outb %al,$0x0a # slave
- movb $0x80,%al # ICW3 to
- outb %al,$0x02 # master
- movb $0x7,%al # ICW3 to
- outb %al,$0x0a # slave
- movb $0x1d,%al # ICW4 to
- outb %al,$0x02 # master,
- movb $0x9,%al # ICW4 to
- outb %al,$0x0a # slave
- pop %ax # Restore slave
- outb %al,$0x0a # IMR
- pop %ax # Restore master
- outb %al,$0x02 # IMR
-.else
-setpic: in $0x21,%al # Save master
- push %ax # IMR
- in $0xa1,%al # Save slave
- push %ax # IMR
- movb $0x11,%al # ICW1 to
- outb %al,$0x20 # master,
- outb %al,$0xa0 # slave
- movb %bl,%al # ICW2 to
- outb %al,$0x21 # master
- movb %bh,%al # ICW2 to
- outb %al,$0xa1 # slave
- movb $0x4,%al # ICW3 to
- outb %al,$0x21 # master
- movb $0x2,%al # ICW3 to
- outb %al,$0xa1 # slave
- movb $0x1,%al # ICW4 to
- outb %al,$0x21 # master,
- outb %al,$0xa1 # slave
- pop %ax # Restore slave
- outb %al,$0xa1 # IMR
- pop %ax # Restore master
- outb %al,$0x21 # IMR
-.endif
- retw # To caller
- .code32
-#
-# Initiate return from V86 mode to user mode.
-#
-inthlt: hlt # To supervisor mode
-#
-# Exception jump table.
-#
-intx00: push $0x0 # Int 0x0: #DE
- jmp ex_noc # Divide error
- push $0x1 # Int 0x1: #DB
- jmp ex_noc # Debug
- push $0x3 # Int 0x3: #BP
- jmp ex_noc # Breakpoint
- push $0x4 # Int 0x4: #OF
- jmp ex_noc # Overflow
- push $0x5 # Int 0x5: #BR
- jmp ex_noc # BOUND range exceeded
- push $0x6 # Int 0x6: #UD
- jmp ex_noc # Invalid opcode
- push $0x7 # Int 0x7: #NM
- jmp ex_noc # Device not available
- push $0x8 # Int 0x8: #DF
- jmp except # Double fault
- push $0xa # Int 0xa: #TS
- jmp except # Invalid TSS
- push $0xb # Int 0xb: #NP
- jmp except # Segment not present
- push $0xc # Int 0xc: #SS
- jmp except # Stack segment fault
- push $0xd # Int 0xd: #GP
- jmp ex_v86 # General protection
- push $0xe # Int 0xe: #PF
- jmp except # Page fault
-intx10: push $0x10 # Int 0x10: #MF
- jmp ex_noc # Floating-point error
-#
-# Handle #GP exception.
-#
-ex_v86: testb $0x2,0x12(%esp,1) # V86 mode?
- jz except # No
- jmp v86mon # To monitor
-#
-# Save a zero error code.
-#
-ex_noc: pushl (%esp,1) # Duplicate int no
- movb $0x0,0x4(%esp,1) # Fake error code
-#
-# Handle exception.
-#
-except: cld # String ops inc
- pushl %ds # Save
- pushl %es # most
- pusha # registers
- movb $0x6,%al # Push loop count
- testb $0x2,0x3a(%esp,1) # V86 mode?
- jnz except.1 # Yes
- pushl %gs # Set GS
- pushl %fs # Set FS
- pushl %ds # Set DS
- pushl %es # Set ES
- movb $0x2,%al # Push loop count
- cmpw $SEL_SCODE,0x44(%esp,1) # Supervisor mode?
- jne except.1 # No
- pushl %ss # Set SS
- leal 0x50(%esp,1),%eax # Set
- pushl %eax # ESP
- jmp except.2 # Join common code
-except.1: pushl 0x50(%esp,1) # Set GS, FS, DS, ES
- decb %al # (if V86 mode), and
- jne except.1 # SS, ESP
-except.2: push $SEL_SDATA # Set up
- popl %ds # to
- pushl %ds # address
- popl %es # data
- movl %esp,%ebx # Stack frame
- movl $dmpfmt,%esi # Dump format string
- movl $MEM_BUF,%edi # Buffer
-.`ifdef' PC98
- pushl %eax
- pushl %edx
-wait.1:
- inb $0x60,%al
- testb $0x04,%al
- jz wait.1
- movb $0xe0,%al
- outb %al,$0x62
-wait.2:
- inb $0x60,%al
- testb $0x01,%al
- jz wait.2
- xorl %edx,%edx
- inb $0x62,%al
- movb %al,%dl
- inb $0x62,%al
- movb %al,%dh
- inb $0x62,%al
- inb $0x62,%al
- inb $0x62,%al
- movl %edx,%eax
- shlw $1,%ax
- movl $BDA_POS,%edx
- movw %ax,(%edx)
- popl %edx
- popl %eax
-.endif
- pushl %edi # Dump to
- call dump # buffer
- popl %esi # and
- call putstr # display
- leal 0x18(%esp,1),%esp # Discard frame
- popa # Restore
- popl %es # registers
- popl %ds # saved
- cmpb $0x3,(%esp,1) # Breakpoint?
- je except.3 # Yes
- cmpb $0x1,(%esp,1) # Debug?
- jne except.2a # No
- testl $0x100,0x10(%esp,1) # Trap flag set?
- jnz except.3 # Yes
-except.2a: jmp exit # Exit
-except.3: leal 0x8(%esp,1),%esp # Discard err, int no
- iret # From interrupt
-#
-# Return to user mode from V86 mode.
-#
-intrtn: cld # String ops inc
- pushl %ds # Address
- popl %es # data
- leal 0x3c(%ebp),%edx # V86 Segment registers
- movl MEM_TSS+TSS_ESP1,%esi # Link stack pointer
- lodsl # INT_V86 args pointer
- movl %esi,%ebx # Saved exception frame
- testl %eax,%eax # INT_V86 args?
- jz intrtn.2 # No
- movl $MEM_USR,%edi # User base
- movl 0x1c(%esi),%ebx # User ESP
- movl %eax,(%edi,%ebx,1) # Restore to user stack
- leal 0x8(%edi,%eax,1),%edi # Arg segment registers
- testb $0x4,-0x6(%edi) # Return flags?
- jz intrtn.1 # No
- movl 0x30(%ebp),%eax # Get V86 flags
- movw %ax,0x18(%esi) # Set user flags
-intrtn.1: leal 0x10(%esi),%ebx # Saved exception frame
- xchgl %edx,%esi # Segment registers
- movb $0x4,%cl # Update seg regs
- rep # in INT_V86
- movsl # args
-intrtn.2: movl %edx,%esi # Segment registers
- leal 0x28(%ebp),%edi # Set up seg
- movb $0x4,%cl # regs for
- rep # later
- movsl # pop
- movl %ebx,%esi # Restore exception
- movb $0x5,%cl # frame to
- rep # supervisor
- movsl # stack
- movl %esi,MEM_TSS+TSS_ESP1 # Link stack pointer
- popa # Restore
- leal 0x8(%esp,1),%esp # Discard err, int no
- popl %es # Restore
- popl %ds # user
- popl %fs # segment
- popl %gs # registers
- iret # To user mode
-#
-# V86 monitor.
-#
-v86mon: cld # String ops inc
- pushl $SEL_SDATA # Set up for
- popl %ds # flat addressing
- pusha # Save registers
- movl %esp,%ebp # Address stack frame
- movzwl 0x2c(%ebp),%edi # Load V86 CS
- shll $0x4,%edi # To linear
- movl 0x28(%ebp),%esi # Load V86 IP
- addl %edi,%esi # Code pointer
- xorl %ecx,%ecx # Zero
- movb $0x2,%cl # 16-bit operands
- xorl %eax,%eax # Zero
-v86mon.1: lodsb # Get opcode
- cmpb $0x66,%al # Operand size prefix?
- jne v86mon.2 # No
- movb $0x4,%cl # 32-bit operands
- jmp v86mon.1 # Continue
-v86mon.2: cmpb $0xf4,%al # HLT?
- jne v86mon.3 # No
- cmpl $inthlt+0x1,%esi # Is inthlt?
- jne v86mon.7 # No (ignore)
- jmp intrtn # Return to user mode
-v86mon.3: cmpb $0xf,%al # Prefixed instruction?
- jne v86mon.4 # No
- cmpb $0x09,(%esi) # Is it a WBINVD?
- je v86wbinvd # Yes
- cmpb $0x30,(%esi) # Is it a WRMSR?
- je v86wrmsr # Yes
- cmpb $0x32,(%esi) # Is it a RDMSR?
- je v86rdmsr # Yes
- cmpb $0x20,(%esi) # Is this a
- jne v86mon.4 # MOV EAX,CR0
- cmpb $0xc0,0x1(%esi) # instruction?
- je v86mov # Yes
-v86mon.4: cmpb $0xfa,%al # CLI?
- je v86cli # Yes
- cmpb $0xfb,%al # STI?
- je v86sti # Yes
- movzwl 0x38(%ebp),%ebx # Load V86 SS
- shll $0x4,%ebx # To offset
- pushl %ebx # Save
- addl 0x34(%ebp),%ebx # Add V86 SP
- movl 0x30(%ebp),%edx # Load V86 flags
- cmpb $0x9c,%al # PUSHF/PUSHFD?
- je v86pushf # Yes
- cmpb $0x9d,%al # POPF/POPFD?
- je v86popf # Yes
- cmpb $0xcd,%al # INT imm8?
- je v86intn # Yes
- cmpb $0xcf,%al # IRET/IRETD?
- je v86iret # Yes
- popl %ebx # Restore
- popa # Restore
- jmp except # Handle exception
-v86mon.5: movl %edx,0x30(%ebp) # Save V86 flags
-v86mon.6: popl %edx # V86 SS adjustment
- subl %edx,%ebx # Save V86
- movl %ebx,0x34(%ebp) # SP
-v86mon.7: subl %edi,%esi # From linear
- movl %esi,0x28(%ebp) # Save V86 IP
- popa # Restore
- leal 0x8(%esp,1),%esp # Discard int no, error
- iret # To V86 mode
-#
-# Emulate MOV EAX,CR0.
-#
-v86mov: movl %cr0,%eax # CR0 to
- movl %eax,0x1c(%ebp) # saved EAX
- incl %esi # Adjust IP
-#
-# Return from emulating a 0x0f prefixed instruction
-#
-v86preret: incl %esi # Adjust IP
- jmp v86mon.7 # Finish up
-#
-# Emulate WBINVD
-#
-v86wbinvd: wbinvd # Write back and invalidate
- # cache
- jmp v86preret # Finish up
-#
-# Emulate WRMSR
-#
-v86wrmsr: movl 0x18(%ebp),%ecx # Get user's %ecx (MSR to write)
- movl 0x14(%ebp),%edx # Load the value
- movl 0x1c(%ebp),%eax # to write
- wrmsr # Write MSR
- jmp v86preret # Finish up
-#
-# Emulate RDMSR
-#
-v86rdmsr: movl 0x18(%ebp),%ecx # MSR to read
- rdmsr # Read the MSR
- movl %eax,0x1c(%ebp) # Return the value of
- movl %edx,0x14(%ebp) # the MSR to the user
- jmp v86preret # Finish up
-#
-# Emulate CLI.
-#
-v86cli: andb $~0x2,0x31(%ebp) # Clear IF
- jmp v86mon.7 # Finish up
-#
-# Emulate STI.
-#
-v86sti: orb $0x2,0x31(%ebp) # Set IF
- jmp v86mon.7 # Finish up
-#
-# Emulate PUSHF/PUSHFD.
-#
-v86pushf: subl %ecx,%ebx # Adjust SP
- cmpb $0x4,%cl # 32-bit
- je v86pushf.1 # Yes
- data16 # 16-bit
-v86pushf.1: movl %edx,(%ebx) # Save flags
- jmp v86mon.6 # Finish up
-#
-# Emulate IRET/IRETD.
-#
-v86iret: movzwl (%ebx),%esi # Load V86 IP
- movzwl 0x2(%ebx),%edi # Load V86 CS
- leal 0x4(%ebx),%ebx # Adjust SP
- movl %edi,0x2c(%ebp) # Save V86 CS
- xorl %edi,%edi # No ESI adjustment
-#
-# Emulate POPF/POPFD (and remainder of IRET/IRETD).
-#
-v86popf: cmpb $0x4,%cl # 32-bit?
- je v86popf.1 # Yes
- movl %edx,%eax # Initialize
- data16 # 16-bit
-v86popf.1: movl (%ebx),%eax # Load flags
- addl %ecx,%ebx # Adjust SP
- andl $V86_FLG,%eax # Merge
- andl $~V86_FLG,%edx # the
- orl %eax,%edx # flags
- jmp v86mon.5 # Finish up
-#
-# trap int 15, function 87
-# reads %es:%si from saved registers on stack to find a GDT containing
-# source and destination locations
-# reads count of words from saved %cx
-# returns success by setting %ah to 0
-#
-int15_87: pushl %eax # Save
- pushl %ebx # some information
- pushl %esi # onto the stack.
- pushl %edi
- xorl %eax,%eax # clean EAX
- xorl %ebx,%ebx # clean EBX
- movl 0x4(%ebp),%esi # Get user's ESI
- movl 0x3C(%ebp),%ebx # store ES
- movw %si,%ax # store SI
- shll $0x4,%ebx # Make it a seg.
- addl %eax,%ebx # ebx=(es<<4)+si
- movb 0x14(%ebx),%al # Grab the
- movb 0x17(%ebx),%ah # necessary
- shll $0x10,%eax # information
- movw 0x12(%ebx),%ax # from
- movl %eax,%esi # the
- movb 0x1c(%ebx),%al # GDT in order to
- movb 0x1f(%ebx),%ah # have %esi offset
- shll $0x10,%eax # of source and %edi
- movw 0x1a(%ebx),%ax # of destination.
- movl %eax,%edi
- pushl %ds # Make:
- popl %es # es = ds
- pushl %ecx # stash ECX
- xorl %ecx,%ecx # highw of ECX is clear
- movw 0x18(%ebp),%cx # Get user's ECX
- shll $0x1,%ecx # Convert from num words to num
- # bytes
- rep # repeat...
- movsb # perform copy.
- popl %ecx # Restore
- popl %edi
- popl %esi # previous
- popl %ebx # register
- popl %eax # values.
- movb $0x0,0x1d(%ebp) # set ah = 0 to indicate
- # success
- andb $0xfe,%dl # clear CF
- jmp v86mon.5 # Finish up
-
-#
-# Reboot the machine by setting the reboot flag and exiting
-#
-reboot: orb $0x1,btx_hdr+0x7 # Set the reboot flag
- jmp exit # Terminate BTX and reboot
-
-#
-# Emulate INT imm8... also make sure to check if it's int 15/87
-#
-v86intn: lodsb # Get int no
- cmpb $0x19,%al # is it int 19?
- je reboot # yes, reboot the machine
- cmpb $0x15,%al # is it int 15?
- jne v86intn.3 # no, skip parse
- pushl %eax # stash EAX
- movl 0x1c(%ebp),%eax # user's saved EAX
- cmpb $0x87,%ah # is it the memcpy subfunction?
- jne v86intn.1 # no, keep checking
- popl %eax # get the stack straight
- jmp int15_87 # it's our cue
-v86intn.1: cmpw $0x4f53,%ax # is it the delete key callout?
- jne v86intn.2 # no, handle the int normally
- movb BDA_KEYFLAGS,%al # get the shift key state
-.`ifdef' PC98
- andb $0x18,%al # mask off just Ctrl and Alt
- cmpb $0x18,%al # are both Ctrl and Alt down?
-.else
- andb $0xc,%al # mask off just Ctrl and Alt
- cmpb $0xc,%al # are both Ctrl and Alt down?
-.endif
- jne v86intn.2 # no, handle the int normally
- popl %eax # restore EAX
- jmp reboot # reboot the machine
-v86intn.2: popl %eax # restore EAX
-v86intn.3: subl %edi,%esi # From
- shrl $0x4,%edi # linear
- movw %dx,-0x2(%ebx) # Save flags
- movw %di,-0x4(%ebx) # Save CS
- leal -0x6(%ebx),%ebx # Adjust SP
- movw %si,(%ebx) # Save IP
- shll $0x2,%eax # Scale
- movzwl (%eax),%esi # Load IP
- movzwl 0x2(%eax),%edi # Load CS
- movl %edi,0x2c(%ebp) # Save CS
- xorl %edi,%edi # No ESI adjustment
- andb $~0x1,%dh # Clear TF
- jmp v86mon.5 # Finish up
-#
-# Hardware interrupt jump table.
-#
-intx20: push $0x8 # Int 0x20: IRQ0
- jmp int_hw # V86 int 0x8
- push $0x9 # Int 0x21: IRQ1
- jmp int_hw # V86 int 0x9
- push $0xa # Int 0x22: IRQ2
- jmp int_hw # V86 int 0xa
- push $0xb # Int 0x23: IRQ3
- jmp int_hw # V86 int 0xb
- push $0xc # Int 0x24: IRQ4
- jmp int_hw # V86 int 0xc
- push $0xd # Int 0x25: IRQ5
- jmp int_hw # V86 int 0xd
- push $0xe # Int 0x26: IRQ6
- jmp int_hw # V86 int 0xe
- push $0xf # Int 0x27: IRQ7
- jmp int_hw # V86 int 0xf
-.`ifdef' PC98
- push $0x10 # Int 0x28: IRQ8
- jmp int_hw # V86 int 0x10
- push $0x11 # Int 0x29: IRQ9
- jmp int_hw # V86 int 0x11
- push $0x12 # Int 0x2a: IRQ10
- jmp int_hw # V86 int 0x12
- push $0x13 # Int 0x2b: IRQ11
- jmp int_hw # V86 int 0x13
- push $0x14 # Int 0x2c: IRQ12
- jmp int_hw # V86 int 0x14
- push $0x15 # Int 0x2d: IRQ13
- jmp int_hw # V86 int 0x15
- push $0x16 # Int 0x2e: IRQ14
- jmp int_hw # V86 int 0x16
- push $0x17 # Int 0x2f: IRQ15
- jmp int_hw # V86 int 0x17
-.else
- push $0x70 # Int 0x28: IRQ8
- jmp int_hw # V86 int 0x70
- push $0x71 # Int 0x29: IRQ9
- jmp int_hw # V86 int 0x71
- push $0x72 # Int 0x2a: IRQ10
- jmp int_hw # V86 int 0x72
- push $0x73 # Int 0x2b: IRQ11
- jmp int_hw # V86 int 0x73
- push $0x74 # Int 0x2c: IRQ12
- jmp int_hw # V86 int 0x74
- push $0x75 # Int 0x2d: IRQ13
- jmp int_hw # V86 int 0x75
- push $0x76 # Int 0x2e: IRQ14
- jmp int_hw # V86 int 0x76
- push $0x77 # Int 0x2f: IRQ15
- jmp int_hw # V86 int 0x77
-.endif
-#
-# Reflect hardware interrupts.
-#
-int_hw: testb $0x2,0xe(%esp,1) # V86 mode?
- jz intusr # No
- pushl $SEL_SDATA # Address
- popl %ds # data
- xchgl %eax,(%esp,1) # Swap EAX, int no
- pushl %ebp # Address
- movl %esp,%ebp # stack frame
- pushl %ebx # Save
- shll $0x2,%eax # Get int
- movl (%eax),%eax # vector
- subl $0x6,0x14(%ebp) # Adjust V86 ESP
- movzwl 0x18(%ebp),%ebx # V86 SS
- shll $0x4,%ebx # * 0x10
- addl 0x14(%ebp),%ebx # + V86 ESP
- xchgw %ax,0x8(%ebp) # Swap V86 IP
- rorl $0x10,%eax # Swap words
- xchgw %ax,0xc(%ebp) # Swap V86 CS
- roll $0x10,%eax # Swap words
- movl %eax,(%ebx) # CS:IP for IRET
- movl 0x10(%ebp),%eax # V86 flags
- movw %ax,0x4(%ebx) # Flags for IRET
- andb $~0x3,0x11(%ebp) # Clear IF, TF
- popl %ebx # Restore
- popl %ebp # saved
- popl %eax # registers
- iret # To V86 mode
-#
-# Invoke V86 interrupt from user mode, with arguments.
-#
-intx31: stc # Have btx_v86
- pushl %eax # Missing int no
-#
-# Invoke V86 interrupt from user mode.
-#
-intusr: std # String ops dec
- pushl %eax # Expand
- pushl %eax # stack
- pushl %eax # frame
- pusha # Save
- pushl %gs # Save
- movl %esp,%eax # seg regs
- pushl %fs # and
- pushl %ds # point
- pushl %es # to them
- push $SEL_SDATA # Set up
- popl %ds # to
- pushl %ds # address
- popl %es # data
- movl $MEM_USR,%ebx # User base
- movl %ebx,%edx # address
- jc intusr.1 # If btx_v86
- xorl %edx,%edx # Control flags
- xorl %ebp,%ebp # btx_v86 pointer
-intusr.1: leal 0x50(%esp,1),%esi # Base of frame
- pushl %esi # Save
- addl -0x4(%esi),%ebx # User ESP
- movl MEM_TSS+TSS_ESP1,%edi # Link stack pointer
- leal -0x4(%edi),%edi # Adjust for push
- xorl %ecx,%ecx # Zero
- movb $0x5,%cl # Push exception
- rep # frame on
- movsl # link stack
- xchgl %eax,%esi # Saved seg regs
- movl 0x40(%esp,1),%eax # Get int no
- testl %edx,%edx # Have btx_v86?
- jz intusr.2 # No
- movl (%ebx),%ebp # btx_v86 pointer
- movb $0x4,%cl # Count
- addl %ecx,%ebx # Adjust for pop
- rep # Push saved seg regs
- movsl # on link stack
- addl %ebp,%edx # Flatten btx_v86 ptr
- leal 0x14(%edx),%esi # Seg regs pointer
- movl 0x4(%edx),%eax # Get int no/address
- movzwl 0x2(%edx),%edx # Get control flags
-intusr.2: movl %ebp,(%edi) # Push btx_v86 and
- movl %edi,MEM_TSS+TSS_ESP1 # save link stack ptr
- popl %edi # Base of frame
- xchgl %eax,%ebp # Save intno/address
- movl 0x48(%esp,1),%eax # Get flags
- testb $0x2,%dl # Simulate CALLF?
- jnz intusr.3 # Yes
- decl %ebx # Push flags
- decl %ebx # on V86
- movw %ax,(%ebx) # stack
-intusr.3: movb $0x4,%cl # Count
- subl %ecx,%ebx # Push return address
- movl $inthlt,(%ebx) # on V86 stack
- rep # Copy seg regs to
- movsl # exception frame
- xchgl %eax,%ecx # Save flags
- movl %ebx,%eax # User ESP
- subl $V86_STK,%eax # Less bytes
- ja intusr.4 # to
- xorl %eax,%eax # keep
-intusr.4: shrl $0x4,%eax # Gives segment
- stosl # Set SS
- shll $0x4,%eax # To bytes
- xchgl %eax,%ebx # Swap
- subl %ebx,%eax # Gives offset
- stosl # Set ESP
- xchgl %eax,%ecx # Get flags
- btsl $0x11,%eax # Set VM
- andb $~0x1,%ah # Clear TF
- stosl # Set EFL
- xchgl %eax,%ebp # Get int no/address
- testb $0x1,%dl # Address?
- jnz intusr.5 # Yes
- shll $0x2,%eax # Scale
- movl (%eax),%eax # Load int vector
-intusr.5: movl %eax,%ecx # Save
- shrl $0x10,%eax # Gives segment
- stosl # Set CS
- movw %cx,%ax # Restore
- stosl # Set EIP
- leal 0x10(%esp,1),%esp # Discard seg regs
- popa # Restore
- iret # To V86 mode
-#
-# System Call.
-#
-intx30: cmpl $SYS_EXEC,%eax # Exec system call?
- jne intx30.1 # No
- pushl %ss # Set up
- popl %es # all
- pushl %es # segment
- popl %ds # registers
- pushl %ds # for the
- popl %fs # program
- pushl %fs # we're
- popl %gs # invoking
- movl $MEM_USR,%eax # User base address
- addl 0xc(%esp,1),%eax # Change to user
- leal 0x4(%eax),%esp # stack
-ifdef(`PAGING',`
- movl %cr0,%eax # Turn
- andl $~0x80000000,%eax # off
- movl %eax,%cr0 # paging
- xorl %eax,%eax # Flush
- movl %eax,%cr3 # TLB
-')
- popl %eax # Call
- call *%eax # program
-intx30.1: orb $0x1,%ss:btx_hdr+0x7 # Flag reboot
- jmp exit # Exit
-#
-# Dump structure [EBX] to [EDI], using format string [ESI].
-#
-dump.0: stosb # Save char
-dump: lodsb # Load char
- testb %al,%al # End of string?
- jz dump.10 # Yes
- testb $0x80,%al # Control?
- jz dump.0 # No
- movb %al,%ch # Save control
- movb $'=',%al # Append
- stosb # '='
- lodsb # Get offset
- pushl %esi # Save
- movsbl %al,%esi # To
- addl %ebx,%esi # pointer
- testb $DMP_X16,%ch # Dump word?
- jz dump.1 # No
- lodsw # Get and
- call hex16 # dump it
-dump.1: testb $DMP_X32,%ch # Dump long?
- jz dump.2 # No
- lodsl # Get and
- call hex32 # dump it
-dump.2: testb $DMP_MEM,%ch # Dump memory?
- jz dump.8 # No
- pushl %ds # Save
- testb $0x2,0x52(%ebx) # V86 mode?
- jnz dump.3 # Yes
- verr 0x4(%esi) # Readable selector?
- jnz dump.3 # No
- ldsl (%esi),%esi # Load pointer
- jmp dump.4 # Join common code
-dump.3: lodsl # Set offset
- xchgl %eax,%edx # Save
- lodsl # Get segment
- shll $0x4,%eax # * 0x10
- addl %edx,%eax # + offset
- xchgl %eax,%esi # Set pointer
-dump.4: movb $2,%dl # Num lines
-dump.4a: movb $0x10,%cl # Bytes to dump
-dump.5: lodsb # Get byte and
- call hex8 # dump it
- decb %cl # Keep count
- jz dump.6a # If done
- movb $'-',%al # Separator
- cmpb $0x8,%cl # Half way?
- je dump.6 # Yes
- movb $' ',%al # Use space
-dump.6: stosb # Save separator
- jmp dump.5 # Continue
-dump.6a: decb %dl # Keep count
- jz dump.7 # If done
- movb $0xa,%al # Line feed
- stosb # Save one
- movb $7,%cl # Leading
- movb $' ',%al # spaces
-dump.6b: stosb # Dump
- decb %cl # spaces
- jnz dump.6b
- jmp dump.4a # Next line
-dump.7: popl %ds # Restore
-dump.8: popl %esi # Restore
- movb $0xa,%al # Line feed
- testb $DMP_EOL,%ch # End of line?
- jnz dump.9 # Yes
- movb $' ',%al # Use spaces
- stosb # Save one
-dump.9: jmp dump.0 # Continue
-dump.10: stosb # Terminate string
- ret # To caller
-#
-# Convert EAX, AX, or AL to hex, saving the result to [EDI].
-#
-hex32: pushl %eax # Save
- shrl $0x10,%eax # Do upper
- call hex16 # 16
- popl %eax # Restore
-hex16: call hex16.1 # Do upper 8
-hex16.1: xchgb %ah,%al # Save/restore
-hex8: pushl %eax # Save
- shrb $0x4,%al # Do upper
- call hex8.1 # 4
- popl %eax # Restore
-hex8.1: andb $0xf,%al # Get lower 4
- cmpb $0xa,%al # Convert
- sbbb $0x69,%al # to hex
- das # digit
- orb $0x20,%al # To lower case
- stosb # Save char
- ret # (Recursive)
-#
-# Output zero-terminated string [ESI] to the console.
-#
-putstr.0: call putchr # Output char
-putstr: lodsb # Load char
- testb %al,%al # End of string?
- jnz putstr.0 # No
- ret # To caller
-ifdef(`BTX_SERIAL',`
- .set SIO_PRT,SIOPRT # Base port
- .set SIO_FMT,SIOFMT # 8N1
- .set SIO_DIV,(115200/SIOSPD) # 115200 / SPD
-
-# void sio_init(void)
-
-sio_init: movw $SIO_PRT+0x3,%dx # Data format reg
- movb $SIO_FMT|0x80,%al # Set format
- outb %al,(%dx) # and DLAB
- pushl %edx # Save
- subb $0x3,%dl # Divisor latch reg
- movw $SIO_DIV,%ax # Set
- outw %ax,(%dx) # BPS
- popl %edx # Restore
- movb $SIO_FMT,%al # Clear
- outb %al,(%dx) # DLAB
- incl %edx # Modem control reg
- movb $0x3,%al # Set RTS,
- outb %al,(%dx) # DTR
- incl %edx # Line status reg
-
-# void sio_flush(void)
-
-sio_flush.0: call sio_getc.1 # Get character
-sio_flush: call sio_ischar # Check for character
- jnz sio_flush.0 # Till none
- ret # To caller
-
-# void sio_putc(int c)
-
-sio_putc: movw $SIO_PRT+0x5,%dx # Line status reg
- xor %ecx,%ecx # Timeout
- movb $0x40,%ch # counter
-sio_putc.1: inb (%dx),%al # Transmitter
- testb $0x20,%al # buffer empty?
- loopz sio_putc.1 # No
- jz sio_putc.2 # If timeout
- movb 0x4(%esp,1),%al # Get character
- subb $0x5,%dl # Transmitter hold reg
- outb %al,(%dx) # Write character
-sio_putc.2: ret $0x4 # To caller
-
-# int sio_getc(void)
-
-sio_getc: call sio_ischar # Character available?
- jz sio_getc # No
-sio_getc.1: subb $0x5,%dl # Receiver buffer reg
- inb (%dx),%al # Read character
- ret # To caller
-
-# int sio_ischar(void)
-
-sio_ischar: movw $SIO_PRT+0x5,%dx # Line status register
- xorl %eax,%eax # Zero
- inb (%dx),%al # Received data
- andb $0x1,%al # ready?
- ret # To caller
-
-#
-# Output character AL to the serial console.
-#
-putchr: pusha # Save
- cmpb $10, %al # is it a newline?
- jne putchr.1 # no?, then leave
- push $13 # output a carriage
- call sio_putc # return first
- movb $10, %al # restore %al
-putchr.1: pushl %eax # Push the character
- # onto the stack
- call sio_putc # Output the character
- popa # Restore
- ret # To caller
-',`
-#
-# Output character AL to the console.
-#
-putchr: pusha # Save
- xorl %ecx,%ecx # Zero for loops
- movb $SCR_MAT,%ah # Mode/attribute
- movl $BDA_POS,%ebx # BDA pointer
- movw (%ebx),%dx # Cursor position
-.`ifdef' PC98
- movl $0xa0000,%edi
-.else
- movl $0xb8000,%edi # Regen buffer (color)
- cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode?
- jne putchr.1 # No
- xorw %di,%di # Regen buffer (mono)
-.endif
-putchr.1: cmpb $0xa,%al # New line?
- je putchr.2 # Yes
-.`ifdef' PC98
- movw %dx,%cx
- movb %al,(%edi,%ecx,1) # Write char
- addl $0x2000,%ecx
- movb %ah,(%edi,%ecx,1) # Write attr
- addw $0x02,%dx
- jmp putchr.3
-putchr.2: movw %dx,%ax
- movb $SCR_COL*2,%dl
- div %dl
- incb %al
- mul %dl
- movw %ax,%dx
-putchr.3: cmpw $SCR_ROW*SCR_COL*2,%dx
-.else
- xchgl %eax,%ecx # Save char
- movb $SCR_COL,%al # Columns per row
- mulb %dh # * row position
- addb %dl,%al # + column
- adcb $0x0,%ah # position
- shll %eax # * 2
- xchgl %eax,%ecx # Swap char, offset
- movw %ax,(%edi,%ecx,1) # Write attr:char
- incl %edx # Bump cursor
- cmpb $SCR_COL,%dl # Beyond row?
- jb putchr.3 # No
-putchr.2: xorb %dl,%dl # Zero column
- incb %dh # Bump row
-putchr.3: cmpb $SCR_ROW,%dh # Beyond screen?
-.endif
- jb putchr.4 # No
- leal 2*SCR_COL(%edi),%esi # New top line
- movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
- rep # Scroll
- movsl # screen
- movb $0x20,%al # Space
-.`ifdef' PC98
- xorb %ah,%ah
-.endif
- movb $SCR_COL,%cl # Columns to clear
- rep # Clear
- stosw # line
-.`ifdef' PC98
- movw $(SCR_ROW-1)*SCR_COL*2,%dx
-.else
- movb $SCR_ROW-1,%dh # Bottom line
-.endif
-putchr.4: movw %dx,(%ebx) # Update position
- popa # Restore
- ret # To caller
-')
-
- .p2align 4
-#
-# Global descriptor table.
-#
-gdt: .word 0x0,0x0,0x0,0x0 # Null entry
- .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE
- .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA
- .word 0xffff,0x0,0x9a00,0x0 # SEL_RCODE
- .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA
- .word 0xffff,MEM_USR,0xfa00,0xcf# SEL_UCODE
- .word 0xffff,MEM_USR,0xf200,0xcf# SEL_UDATA
- .word _TSSLM,MEM_TSS,0x8900,0x0 # SEL_TSS
-gdt.1:
-#
-# Pseudo-descriptors.
-#
-gdtdesc: .word gdt.1-gdt-1,gdt,0x0 # GDT
-idtdesc: .word _IDTLM,MEM_IDT,0x0 # IDT
-ivtdesc: .word 0x400-0x0-1,0x0,0x0 # IVT
-#
-# IDT construction control string.
-#
-idtctl: .byte 0x10, 0x8e # Int 0x0-0xf
- .word 0x7dfb,intx00 # (exceptions)
- .byte 0x10, 0x8e # Int 0x10
- .word 0x1, intx10 # (exception)
- .byte 0x10, 0x8e # Int 0x20-0x2f
- .word 0xffff,intx20 # (hardware)
- .byte 0x1, 0xee # int 0x30
- .word 0x1, intx30 # (system call)
- .byte 0x2, 0xee # Int 0x31-0x32
- .word 0x1, intx31 # (V86, null)
- .byte 0x0 # End of string
-#
-# Dump format string.
-#
-dmpfmt: .byte '\n' # "\n"
- .ascii "int" # "int="
- .byte 0x80|DMP_X32, 0x40 # "00000000 "
- .ascii "err" # "err="
- .byte 0x80|DMP_X32, 0x44 # "00000000 "
- .ascii "efl" # "efl="
- .byte 0x80|DMP_X32, 0x50 # "00000000 "
- .ascii "eip" # "eip="
- .byte 0x80|DMP_X32|DMP_EOL,0x48 # "00000000\n"
- .ascii "eax" # "eax="
- .byte 0x80|DMP_X32, 0x34 # "00000000 "
- .ascii "ebx" # "ebx="
- .byte 0x80|DMP_X32, 0x28 # "00000000 "
- .ascii "ecx" # "ecx="
- .byte 0x80|DMP_X32, 0x30 # "00000000 "
- .ascii "edx" # "edx="
- .byte 0x80|DMP_X32|DMP_EOL,0x2c # "00000000\n"
- .ascii "esi" # "esi="
- .byte 0x80|DMP_X32, 0x1c # "00000000 "
- .ascii "edi" # "edi="
- .byte 0x80|DMP_X32, 0x18 # "00000000 "
- .ascii "ebp" # "ebp="
- .byte 0x80|DMP_X32, 0x20 # "00000000 "
- .ascii "esp" # "esp="
- .byte 0x80|DMP_X32|DMP_EOL,0x0 # "00000000\n"
- .ascii "cs" # "cs="
- .byte 0x80|DMP_X16, 0x4c # "0000 "
- .ascii "ds" # "ds="
- .byte 0x80|DMP_X16, 0xc # "0000 "
- .ascii "es" # "es="
- .byte 0x80|DMP_X16, 0x8 # "0000 "
- .ascii " " # " "
- .ascii "fs" # "fs="
- .byte 0x80|DMP_X16, 0x10 # "0000 "
- .ascii "gs" # "gs="
- .byte 0x80|DMP_X16, 0x14 # "0000 "
- .ascii "ss" # "ss="
- .byte 0x80|DMP_X16|DMP_EOL,0x4 # "0000\n"
- .ascii "cs:eip" # "cs:eip="
- .byte 0x80|DMP_MEM|DMP_EOL,0x48 # "00 00 ... 00 00\n"
- .ascii "ss:esp" # "ss:esp="
- .byte 0x80|DMP_MEM|DMP_EOL,0x0 # "00 00 ... 00 00\n"
- .asciz "BTX halted\n" # End
-#
-# End of BTX memory.
-#
- .p2align 4
-break:
diff --git a/sys/boot/pc98/btx/btxldr/btxldr.S b/sys/boot/pc98/btx/btxldr/btxldr.S
deleted file mode 100644
index e889afa86153..000000000000
--- a/sys/boot/pc98/btx/btxldr/btxldr.S
+++ /dev/null
@@ -1,471 +0,0 @@
-#
-# Copyright (c) 1998 Robert Nordier
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms are freely
-# permitted provided that the above copyright notice and this
-# paragraph and the following disclaimer are duplicated in all
-# such forms.
-#
-# This software is provided "AS IS" and without any express or
-# implied warranties, including, without limitation, the implied
-# warranties of merchantability and fitness for a particular
-# purpose.
-#
-
-# $FreeBSD$
-
-#
-# Prototype BTX loader program, written in a couple of hours. The
-# real thing should probably be more flexible, and in C.
-#
-
-#
-# Memory locations.
-#
- .set MEM_STUB,0x600 # Real mode stub
- .set MEM_ESP,0x1000 # New stack pointer
- .set MEM_TBL,0x5000 # BTX page tables
- .set MEM_ENTRY,0x9010 # BTX entry point
- .set MEM_DATA,start+0x1000 # Data segment
-#
-# Segment selectors.
-#
- .set SEL_SCODE,0x8 # 4GB code
- .set SEL_SDATA,0x10 # 4GB data
- .set SEL_RCODE,0x18 # 64K code
- .set SEL_RDATA,0x20 # 64K data
-#
-# Paging constants.
-#
- .set PAG_SIZ,0x1000 # Page size
- .set PAG_ENT,0x4 # Page entry size
-#
-# Screen constants.
-#
-ifdef(`PC98',`
- .set SCR_MAT,0xe1 # Mode/attribute
-',`
- .set SCR_MAT,0x7 # Mode/attribute
-')
- .set SCR_COL,0x50 # Columns per row
- .set SCR_ROW,0x19 # Rows per screen
-#
-# BIOS Data Area locations.
-#
-ifdef(`PC98',`
- .set BDA_MEM,0xa1501 # Free memory
- .set BDA_POS,0xa153e # Cursor position
-',`
- .set BDA_MEM,0x413 # Free memory
- .set BDA_SCR,0x449 # Video mode
- .set BDA_POS,0x450 # Cursor position
-')
-#
-# Required by aout gas inadequacy.
-#
- .set SIZ_STUB,0x1a # Size of stub
-#
-# We expect to be loaded by boot2 at the origin defined in ./Makefile.
-#
- .globl start
-#
-# BTX program loader for ELF clients.
-#
-start: cld # String ops inc
-ifdef(`PC98',`
- cli
-gdcwait.1: inb $0x60,%al
- testb $0x04,%al
- jz gdcwait.1
- movb $0xe0,%al
- outb %al,$0x62
- nop
-gdcwait.2: inb $0x60,%al
- testb $0x01,%al
- jz gdcwait.2
- inb $0x62,%al
- movb %al,%dl
- inb $0x62,%al
- movb %al,%dh
- inb $0x62,%al
- inb $0x62,%al
- inb $0x62,%al
- shlw $1,%dx
- movl $BDA_POS,%ebx
- movw %dx,(%ebx)
-')
- movl $m_logo,%esi # Identify
- call putstr # ourselves
- movzwl BDA_MEM,%eax # Get base memory
-ifdef(`PC98',`
- andl $0x7,%eax
- incl %eax
- shll $0x11,%eax # in bytes
-',`
- shll $0xa,%eax # in bytes
-')
- movl %eax,%ebp # Base of user stack
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_mem,%esi # Display
- call hexout # amount of
- call putstr # base memory
-')
- lgdt gdtdesc # Load new GDT
-#
-# Relocate caller's arguments.
-#
-ifdef('BTXLDR_VERBOSE',`
- movl $m_esp,%esi # Display
- movl %esp,%eax # caller
- call hexout # stack
- call putstr # pointer
- movl $m_args,%esi # Format string
- leal 0x4(%esp,1),%ebx # First argument
- movl $0x6,%ecx # Count
-start.1: movl (%ebx),%eax # Get argument and
- addl $0x4,%ebx # bump pointer
- call hexout # Display it
- loop start.1 # Till done
- call putstr # End message
-')
- movl $0x48,%ecx # Allocate space
- subl %ecx,%ebp # for bootinfo
- movl 0x18(%esp,1),%esi # Source: bootinfo
- cmpl $0x0, %esi # If the bootinfo pointer
- je start_null_bi # is null, don't copy it
- movl %ebp,%edi # Destination
- rep # Copy
- movsb # it
- movl %ebp,0x18(%esp,1) # Update pointer
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_rel_bi,%esi # Display
- movl %ebp,%eax # bootinfo
- call hexout # relocation
- call putstr # message
-')
-start_null_bi: movl $0x18,%ecx # Allocate space
- subl %ecx,%ebp # for arguments
- leal 0x4(%esp,1),%esi # Source
- movl %ebp,%edi # Destination
- rep # Copy
- movsb # them
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_rel_args,%esi # Display
- movl %ebp,%eax # argument
- call hexout # relocation
- call putstr # message
-')
-#
-# Set up BTX kernel.
-#
- movl $MEM_ESP,%esp # Set up new stack
- movl $MEM_DATA,%ebx # Data segment
- movl $m_vers,%esi # Display BTX
- call putstr # version message
- movb 0x5(%ebx),%al # Get major version
- addb $'0',%al # Display
- call putchr # it
- movb $'.',%al # And a
- call putchr # dot
- movb 0x6(%ebx),%al # Get minor
- xorb %ah,%ah # version
- movb $0xa,%dl # Divide
- divb %dl,%al # by 10
- addb $'0',%al # Display
- call putchr # tens
- movb %ah,%al # Get units
- addb $'0',%al # Display
- call putchr # units
- call putstr # End message
- movl %ebx,%esi # BTX image
- movzwl 0x8(%ebx),%edi # Compute
- orl $PAG_SIZ/PAG_ENT-1,%edi # the
- incl %edi # BTX
- shll $0x2,%edi # load
- addl $MEM_TBL,%edi # address
- pushl %edi # Save load address
- movzwl 0xa(%ebx),%ecx # Image size
-ifdef(`BTXLDR_VERBOSE',`
- pushl %ecx # Save image size
-')
- rep # Relocate
- movsb # BTX
- movl %esi,%ebx # Keep place
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_rel_btx,%esi # Restore
- popl %eax # parameters
- call hexout # and
-')
- popl %ebp # display
-ifdef(`BTXLDR_VERBOSE',`
- movl %ebp,%eax # the
- call hexout # relocation
- call putstr # message
-')
- addl $PAG_SIZ,%ebp # Display
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_base,%esi # the
- movl %ebp,%eax # user
- call hexout # base
- call putstr # address
-')
-#
-# Set up ELF-format client program.
-#
- cmpl $0x464c457f,(%ebx) # ELF magic number?
- je start.3 # Yes
- movl $e_fmt,%esi # Display error
- call putstr # message
-start.2: jmp start.2 # Hang
-start.3:
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_elf,%esi # Display ELF
- call putstr # message
- movl $m_segs,%esi # Format string
-')
- movl $0x2,%edi # Segment count
- movl 0x1c(%ebx),%edx # Get e_phoff
- addl %ebx,%edx # To pointer
- movzwl 0x2c(%ebx),%ecx # Get e_phnum
-start.4: cmpl $0x1,(%edx) # Is p_type PT_LOAD?
- jne start.6 # No
-ifdef(`BTXLDR_VERBOSE',`
- movl 0x4(%edx),%eax # Display
- call hexout # p_offset
- movl 0x8(%edx),%eax # Display
- call hexout # p_vaddr
- movl 0x10(%edx),%eax # Display
- call hexout # p_filesz
- movl 0x14(%edx),%eax # Display
- call hexout # p_memsz
- call putstr # End message
-')
- pushl %esi # Save
- pushl %edi # working
- pushl %ecx # registers
- movl 0x4(%edx),%esi # Get p_offset
- addl %ebx,%esi # as pointer
- movl 0x8(%edx),%edi # Get p_vaddr
- addl %ebp,%edi # as pointer
- movl 0x10(%edx),%ecx # Get p_filesz
- rep # Set up
- movsb # segment
- movl 0x14(%edx),%ecx # Any bytes
- subl 0x10(%edx),%ecx # to zero?
- jz start.5 # No
- xorb %al,%al # Then
- rep # zero
- stosb # them
-start.5: popl %ecx # Restore
- popl %edi # working
- popl %esi # registers
- decl %edi # Segments to do
- je start.7 # If none
-start.6: addl $0x20,%edx # To next entry
- loop start.4 # Till done
-start.7:
-ifdef(`BTXLDR_VERBOSE',`
- movl $m_done,%esi # Display done
- call putstr # message
-')
- movl $start.8,%esi # Real mode stub
- movl $MEM_STUB,%edi # Destination
- movl $start.9-start.8,%ecx # Size
- rep # Relocate
- movsb # it
- ljmp $SEL_RCODE,$MEM_STUB # To 16-bit code
- .code16
-start.8: xorw %ax,%ax # Data
- movb $SEL_RDATA,%al # selector
- movw %ax,%ss # Reload SS
- movw %ax,%ds # Reset
- movw %ax,%es # other
- movw %ax,%fs # segment
- movw %ax,%gs # limits
- movl %cr0,%eax # Switch to
- decw %ax # real
- movl %eax,%cr0 # mode
- ljmp $0,$MEM_ENTRY # Jump to BTX entry point
-start.9:
- .code32
-#
-# Output message [ESI] followed by EAX in hex.
-#
-hexout: pushl %eax # Save
- call putstr # Display message
- popl %eax # Restore
- pushl %esi # Save
- pushl %edi # caller's
- movl $buf,%edi # Buffer
- pushl %edi # Save
- call hex32 # To hex
- xorb %al,%al # Terminate
- stosb # string
- popl %esi # Restore
-hexout.1: lodsb # Get a char
- cmpb $'0',%al # Leading zero?
- je hexout.1 # Yes
- testb %al,%al # End of string?
- jne hexout.2 # No
- decl %esi # Undo
-hexout.2: decl %esi # Adjust for inc
- call putstr # Display hex
- popl %edi # Restore
- popl %esi # caller's
- ret # To caller
-#
-# Output zero-terminated string [ESI] to the console.
-#
-putstr.0: call putchr # Output char
-putstr: lodsb # Load char
- testb %al,%al # End of string?
- jne putstr.0 # No
- ret # To caller
-#
-# Output character AL to the console.
-#
-putchr: pusha # Save
- xorl %ecx,%ecx # Zero for loops
- movb $SCR_MAT,%ah # Mode/attribute
- movl $BDA_POS,%ebx # BDA pointer
- movw (%ebx),%dx # Cursor position
-ifdef(`PC98',`
- movl $0xa0000,%edi # Regen buffer (color)
-',`
- movl $0xb8000,%edi # Regen buffer (color)
- cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode?
- jne putchr.1 # No
- xorw %di,%di # Regen buffer (mono)
-')
-putchr.1: cmpb $0xa,%al # New line?
- je putchr.2 # Yes
-ifdef(`PC98',`
- movw %dx,%cx
- movb %al,(%edi,%ecx,1) # Write char
- addl $0x2000,%ecx
- movb %ah,(%edi,%ecx,1) # Write attr
- addw $0x2,%dx
- jmp putchr.3
-putchr.2: movw %dx,%ax
- movb $SCR_COL*2,%dl
- div %dl
- incb %al
- mul %dl
- movw %ax,%dx
-putchr.3: cmpw $SCR_COL*SCR_ROW*2,%dx
-',`
- xchgl %eax,%ecx # Save char
- movb $SCR_COL,%al # Columns per row
- mulb %dh # * row position
- addb %dl,%al # + column
- adcb $0x0,%ah # position
- shll %eax # * 2
- xchgl %eax,%ecx # Swap char, offset
- movw %ax,(%edi,%ecx,1) # Write attr:char
- incl %edx # Bump cursor
- cmpb $SCR_COL,%dl # Beyond row?
- jb putchr.3 # No
-putchr.2: xorb %dl,%dl # Zero column
- incb %dh # Bump row
-putchr.3: cmpb $SCR_ROW,%dh # Beyond screen?
-')
- jb putchr.4 # No
- leal 2*SCR_COL(%edi),%esi # New top line
- movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
- rep # Scroll
- movsl # screen
- movb $' ',%al # Space
-ifdef(`PC98',`
- xorb %ah,%ah
-')
- movb $SCR_COL,%cl # Columns to clear
- rep # Clear
- stosw # line
-ifdef(`PC98',`
- movw $(SCR_ROW-1)*SCR_COL*2,%dx
-putchr.4: movw %dx,(%ebx) # Update position
- shrw $1,%dx
-gdcwait.3: inb $0x60,%al
- testb $0x04,%al
- jz gdcwait.3
- movb $0x49,%al
- outb %al,$0x62
- movb %dl,%al
- outb %al,$0x60
- movb %dh,%al
- outb %al,$0x60
-',`
- movb $SCR_ROW-1,%dh # Bottom line
-putchr.4: movw %dx,(%ebx) # Update position
-')
- popa # Restore
- ret # To caller
-#
-# Convert EAX, AX, or AL to hex, saving the result to [EDI].
-#
-hex32: pushl %eax # Save
- shrl $0x10,%eax # Do upper
- call hex16 # 16
- popl %eax # Restore
-hex16: call hex16.1 # Do upper 8
-hex16.1: xchgb %ah,%al # Save/restore
-hex8: pushl %eax # Save
- shrb $0x4,%al # Do upper
- call hex8.1 # 4
- popl %eax # Restore
-hex8.1: andb $0xf,%al # Get lower 4
- cmpb $0xa,%al # Convert
- sbbb $0x69,%al # to hex
- das # digit
- orb $0x20,%al # To lower case
- stosb # Save char
- ret # (Recursive)
-
- .data
- .p2align 4
-#
-# Global descriptor table.
-#
-gdt: .word 0x0,0x0,0x0,0x0 # Null entry
- .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE
- .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA
- .word 0xffff,0x0,0x9a00,0x0 # SEL_RCODE
- .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA
-gdt.1:
-gdtdesc: .word gdt.1-gdt-1 # Limit
- .long gdt # Base
-#
-# Messages.
-#
-m_logo: .asciz " \nBTX loader 1.00 "
-m_vers: .asciz "BTX version is \0\n"
-e_fmt: .asciz "Error: Client format not supported\n"
-ifdef(`BTXLDR_VERBOSE',`
-m_mem: .asciz "Starting in protected mode (base mem=\0)\n"
-m_esp: .asciz "Arguments passed (esp=\0):\n"
-m_args: .asciz"<howto="
- .asciz" bootdev="
- .asciz" junk="
- .asciz" "
- .asciz" "
- .asciz" bootinfo=\0>\n"
-m_rel_bi: .asciz "Relocated bootinfo (size=48) to \0\n"
-m_rel_args: .asciz "Relocated arguments (size=18) to \0\n"
-m_rel_btx: .asciz "Relocated kernel (size=\0) to \0\n"
-m_base: .asciz "Client base address is \0\n"
-m_elf: .asciz "Client format is ELF\n"
-m_segs: .asciz "text segment: offset="
- .asciz " vaddr="
- .asciz " filesz="
- .asciz " memsz=\0\n"
- .asciz "data segment: offset="
- .asciz " vaddr="
- .asciz " filesz="
- .asciz " memsz=\0\n"
-m_done: .asciz "Loading complete\n"
-')
-#
-# Uninitialized data area.
-#
-buf: # Scratch buffer
diff --git a/sys/boot/powerpc/ofw/Makefile b/sys/boot/powerpc/ofw/Makefile
deleted file mode 100644
index 9cf054c3203d..000000000000
--- a/sys/boot/powerpc/ofw/Makefile
+++ /dev/null
@@ -1,115 +0,0 @@
-# $FreeBSD$
-
-BASE= loader
-PROG= ${BASE}
-NOMAN=
-STRIP=
-NEWVERSWHAT= "bootstrap loader" OpenFirmware/PowerPC
-BINDIR?= /boot
-INSTALLFLAGS= -b
-
-LOADER_DISK_SUPPORT?= yes
-LOADER_NET_SUPPORT?= yes
-
-CFLAGS+= -ffreestanding
-# load address
-RELOC?= 0x6c0000
-CFLAGS+= -DRELOC=${RELOC}
-
-# architecture-specific loader code
-SRCS= conf.c metadata.c
-
-# Pull in common loader code
-.PATH: ${.CURDIR}/../../ofw/common
-.include <${.CURDIR}/../../ofw/common/Makefile.inc>
-
-.if defined(LOADER_DISK_SUPPORT)
-CFLAGS+= -DLOADER_DISK_SUPPORT
-.endif
-.if defined(LOADER_NET_SUPPORT)
-CFLAGS+= -DLOADER_NET_SUPPORT
-.endif
-
-.if !defined(NOFORTH)
-# Enable BootForth
-BOOT_FORTH= yes
-CFLAGS+= -DBOOT_FORTH -I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/powerpc
-.if exists(${.OBJDIR}/../../ficl/libficl.a)
-LIBFICL= ${.OBJDIR}/../../ficl/libficl.a
-.else
-LIBFICL= ${.CURDIR}/../../ficl/libficl.a
-.endif
-.endif
-
-# Always add MI sources
-.PATH: ${.CURDIR}/../../common
-.include <${.CURDIR}/../../common/Makefile.inc>
-CFLAGS+= -I${.CURDIR}/../../common
-CFLAGS+= -I${.CURDIR}/../../.. -I.
-
-CLEANFILES+= vers.c vers.o ${BASE}.list ${BASE}.bin ${BASE}.sym ${BASE}.help
-
-LDFLAGS= -nostdlib -static -Ttext ${RELOC}
-
-# OpenFirmware standalone support library
-LIBOFW= ${.OBJDIR}/../../ofw/libofw/libofw.a
-CFLAGS+= -I${.CURDIR}/../../ofw/libofw
-
-# where to get libstand from
-#XXX need a better way to do this
-LIBSTAND= ${.CURDIR}/../../../../lib/libstand/libstand.a
-.if !exists(${LIBSTAND})
-LIBSTAND= ${.OBJDIR}/../../../../lib/libstand/libstand.a
-.if !exists(${LIBSTAND})
-LIBSTAND= -lstand
-.endif
-.endif
-CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/
-
-# OpenFirmware is expecting ELF components
-CFLAGS+= -elf
-
-# Debug me!
-CFLAGS+= -g
-LDFLAGS+= -g
-
-vers.o: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
- sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT}
- ${CC} -c vers.c
-
-${BASE}.help: help.common help.ofw
- cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET}
-
-beforeinstall:
-.if exists(${.OBJDIR}/loader.help)
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.OBJDIR}/${BASE}.help ${DESTDIR}/boot
-.else
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.CURDIR}/${BASE}.help ${DESTDIR}/boot
-.endif
-.if !exists(${DESTDIR}/boot/loader.rc)
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.CURDIR}/../../forth/loader.rc ${DESTDIR}/boot
-.endif
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.CURDIR}/../../forth/loader.4th ${DESTDIR}/boot
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.CURDIR}/../../forth/support.4th ${DESTDIR}/boot
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.CURDIR}/../../forth/loader.conf ${DESTDIR}/boot/defaults
-
-${PROG}: ${OBJS} ${LIBOFW} ${LIBSTAND} ${LIBFICL} start.o vers.o
- ${LD} ${LDFLAGS} -o ${.TARGET} start.o ${OBJS} \
- vers.o ${LIBFICL} ${LIBOFW} ${LIBSTAND}
-
-machine:
- ln -sf ${.CURDIR}/../../../powerpc/include machine
-
-# Cannot use ${OBJS} above this line
-.include <bsd.prog.mk>
-
-beforedepend ${OBJS}: machine
-
-CLEANFILES+= machine setdefs.h setdef0.c setdef1.c setdef0.o setdef1.o \
- start.o
diff --git a/sys/boot/powerpc/ofw/conf.c b/sys/boot/powerpc/ofw/conf.c
deleted file mode 100644
index 95e6bc6bdc65..000000000000
--- a/sys/boot/powerpc/ofw/conf.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*-
- * Copyright (c) 1999 Michael Smith <msmith@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <stand.h>
-#include "bootstrap.h"
-#include "libofw.h"
-#include "openfirm.h"
-
-#if defined(LOADER_NET_SUPPORT)
-#include "dev_net.h"
-#endif
-
-/*
- * We could use linker sets for some or all of these, but
- * then we would have to control what ended up linked into
- * the bootstrap. So it's easier to conditionalise things
- * here.
- *
- * XXX rename these arrays to be consistent and less namespace-hostile
- */
-
-/* Exported for libstand */
-struct devsw *devsw[] = {
-#if defined(LOADER_DISK_SUPPORT) || defined(LOADER_CDROM_SUPPORT)
- &ofwdisk,
-#endif
-#if defined(LOADER_NET_SUPPORT)
- &netdev,
-#endif
- NULL
-};
-
-struct fs_ops *file_system[] = {
-#ifdef LOADER_UFS_SUPPORT
- &ufs_fsops,
-#endif
-#ifdef LOADER_CDROM_SUPPORT
- &cd9660_fsops,
-#endif
-#ifdef LOADER_EXT2FS_SUPPORT
- &ext2fs_fsops,
-#endif
-#ifdef LOADER_NET_SUPPORT
- &nfs_fsops,
-#endif
- &gzipfs_fsops,
- NULL
-};
-
-struct netif_driver *netif_drivers[] = {
-#ifdef LOADER_NET_SUPPORT
- &ofwnet,
-#endif
- NULL,
-};
-
-/* Exported for PowerPC only */
-/*
- * Sort formats so that those that can detect based on arguments
- * rather than reading the file go first.
- */
-
-struct file_format *file_formats[] = {
- &ofw_elf,
- NULL
-};
-
-/*
- * Consoles
- *
- * We don't prototype these in libalpha.h because they require
- * data structures from bootstrap.h as well.
- */
-extern struct console ofwconsole;
-
-struct console *consoles[] = {
- &ofwconsole,
- NULL
-};
-
-/*
- * reloc - our load address
- */
-vm_offset_t reloc = RELOC;
diff --git a/sys/boot/powerpc/ofw/help.ofw b/sys/boot/powerpc/ofw/help.ofw
deleted file mode 100644
index 5873eb0512d2..000000000000
--- a/sys/boot/powerpc/ofw/help.ofw
+++ /dev/null
@@ -1 +0,0 @@
-$FreeBSD$
diff --git a/sys/boot/powerpc/ofw/metadata.c b/sys/boot/powerpc/ofw/metadata.c
deleted file mode 100644
index bb02c5ed851a..000000000000
--- a/sys/boot/powerpc/ofw/metadata.c
+++ /dev/null
@@ -1,316 +0,0 @@
-/*-
- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: FreeBSD: src/sys/boot/sparc64/loader/metadata.c,v 1.6
- * $FreeBSD$
- */
-
-#include <stand.h>
-#include <sys/param.h>
-#include <sys/reboot.h>
-#include <sys/linker.h>
-
-#include <machine/metadata.h>
-
-#include "bootstrap.h"
-#include "libofw.h"
-
-/*
- * Return a 'boothowto' value corresponding to the kernel arguments in
- * (kargs) and any relevant environment variables.
- */
-static struct
-{
- const char *ev;
- int mask;
-} howto_names[] = {
- {"boot_askname", RB_ASKNAME},
- {"boot_cdrom", RB_CDROM},
- {"boot_userconfig", RB_CONFIG},
- {"boot_ddb", RB_KDB},
- {"boot_gdb", RB_GDB},
- {"boot_single", RB_SINGLE},
- {"boot_verbose", RB_VERBOSE},
- {"boot_multicons", RB_MULTIPLE},
- {"boot_serial", RB_SERIAL},
- {NULL, 0}
-};
-
-int
-md_getboothowto(char *kargs)
-{
- char *cp;
- int howto;
- int active;
- int i;
-
- /* Parse kargs */
- howto = 0;
- if (kargs != NULL) {
- cp = kargs;
- active = 0;
- while (*cp != 0) {
- if (!active && (*cp == '-')) {
- active = 1;
- } else if (active)
- switch (*cp) {
- case 'a':
- howto |= RB_ASKNAME;
- break;
- case 'c':
- howto |= RB_CONFIG;
- break;
- case 'C':
- howto |= RB_CDROM;
- break;
- case 'd':
- howto |= RB_KDB;
- break;
- case 'D':
- howto |= RB_MULTIPLE;
- break;
- case 'm':
- howto |= RB_MUTE;
- break;
- case 'g':
- howto |= RB_GDB;
- break;
- case 'h':
- howto |= RB_SERIAL;
- break;
- case 'r':
- howto |= RB_DFLTROOT;
- break;
- case 's':
- howto |= RB_SINGLE;
- break;
- case 'v':
- howto |= RB_VERBOSE;
- break;
- default:
- active = 0;
- break;
- }
- cp++;
- }
- }
- /* get equivalents from the environment */
- for (i = 0; howto_names[i].ev != NULL; i++)
- if (getenv(howto_names[i].ev) != NULL)
- howto |= howto_names[i].mask;
- if (!strcmp(getenv("console"), "comconsole"))
- howto |= RB_SERIAL;
- if (!strcmp(getenv("console"), "nullconsole"))
- howto |= RB_MUTE;
- return(howto);
-}
-
-/*
- * Copy the environment into the load area starting at (addr).
- * Each variable is formatted as <name>=<value>, with a single nul
- * separating each variable, and a double nul terminating the environment.
- */
-vm_offset_t
-md_copyenv(vm_offset_t addr)
-{
- struct env_var *ep;
-
- /* traverse the environment */
- for (ep = environ; ep != NULL; ep = ep->ev_next) {
- archsw.arch_copyin(ep->ev_name, addr, strlen(ep->ev_name));
- addr += strlen(ep->ev_name);
- archsw.arch_copyin("=", addr, 1);
- addr++;
- if (ep->ev_value != NULL) {
- archsw.arch_copyin(ep->ev_value, addr, strlen(ep->ev_value));
- addr += strlen(ep->ev_value);
- }
- archsw.arch_copyin("", addr, 1);
- addr++;
- }
- archsw.arch_copyin("", addr, 1);
- addr++;
- return(addr);
-}
-
-/*
- * Copy module-related data into the load area, where it can be
- * used as a directory for loaded modules.
- *
- * Module data is presented in a self-describing format. Each datum
- * is preceded by a 32-bit identifier and a 32-bit size field.
- *
- * Currently, the following data are saved:
- *
- * MOD_NAME (variable) module name (string)
- * MOD_TYPE (variable) module type (string)
- * MOD_ARGS (variable) module parameters (string)
- * MOD_ADDR sizeof(vm_offset_t) module load address
- * MOD_SIZE sizeof(size_t) module size
- * MOD_METADATA (variable) type-specific metadata
- */
-#define COPY32(v, a, c) { \
- u_int32_t x = (v); \
- if (c) \
- archsw.arch_copyin(&x, a, sizeof(x)); \
- a += sizeof(x); \
-}
-
-#define MOD_STR(t, a, s, c) { \
- COPY32(t, a, c); \
- COPY32(strlen(s) + 1, a, c) \
- if (c) \
- archsw.arch_copyin(s, a, strlen(s) + 1);\
- a += roundup(strlen(s) + 1, sizeof(u_long));\
-}
-
-#define MOD_NAME(a, s, c) MOD_STR(MODINFO_NAME, a, s, c)
-#define MOD_TYPE(a, s, c) MOD_STR(MODINFO_TYPE, a, s, c)
-#define MOD_ARGS(a, s, c) MOD_STR(MODINFO_ARGS, a, s, c)
-
-#define MOD_VAR(t, a, s, c) { \
- COPY32(t, a, c); \
- COPY32(sizeof(s), a, c); \
- if (c) \
- archsw.arch_copyin(&s, a, sizeof(s)); \
- a += roundup(sizeof(s), sizeof(u_long)); \
-}
-
-#define MOD_ADDR(a, s, c) MOD_VAR(MODINFO_ADDR, a, s, c)
-#define MOD_SIZE(a, s, c) MOD_VAR(MODINFO_SIZE, a, s, c)
-
-#define MOD_METADATA(a, mm, c) { \
- COPY32(MODINFO_METADATA | mm->md_type, a, c);\
- COPY32(mm->md_size, a, c); \
- if (c) \
- archsw.arch_copyin(mm->md_data, a, mm->md_size);\
- a += roundup(mm->md_size, sizeof(u_long)); \
-}
-
-#define MOD_END(a, c) { \
- COPY32(MODINFO_END, a, c); \
- COPY32(0, a, c); \
-}
-
-vm_offset_t
-md_copymodules(vm_offset_t addr)
-{
- struct preloaded_file *fp;
- struct file_metadata *md;
- int c;
-
- c = addr != 0;
- /* start with the first module on the list, should be the kernel */
- for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
-
- MOD_NAME(addr, fp->f_name, c); /* this field must come first */
- MOD_TYPE(addr, fp->f_type, c);
- if (fp->f_args)
- MOD_ARGS(addr, fp->f_args, c);
- MOD_ADDR(addr, fp->f_addr, c);
- MOD_SIZE(addr, fp->f_size, c);
- for (md = fp->f_metadata; md != NULL; md = md->md_next) {
- if (!(md->md_type & MODINFOMD_NOCOPY)) {
- MOD_METADATA(addr, md, c);
- }
- }
- }
- MOD_END(addr, c);
- return(addr);
-}
-
-/*
- * Load the information expected by a powerpc kernel.
- *
- * - The 'boothowto' argument is constructed
- * - The 'bootdev' argument is constructed
- * - The kernel environment is copied into kernel space.
- * - Module metadata are formatted and placed in kernel space.
- */
-int
-md_load(char *args, vm_offset_t *modulep)
-{
- struct preloaded_file *kfp;
- struct preloaded_file *xp;
- struct file_metadata *md;
- vm_offset_t kernend;
- vm_offset_t addr;
- vm_offset_t envp;
- vm_offset_t size;
- char *rootdevname;
- int howto;
- int dtlb_slots;
- int itlb_slots;
-
- howto = md_getboothowto(args);
-
- /*
- * Allow the environment variable 'rootdev' to override the supplied device
- * This should perhaps go to MI code and/or have $rootdev tested/set by
- * MI code before launching the kernel.
- */
- rootdevname = getenv("rootdev");
- if (rootdevname == NULL)
- rootdevname = getenv("currdev");
- /* Try reading the /etc/fstab file to select the root device */
- getrootmount(rootdevname);
-
- /* find the last module in the chain */
- addr = 0;
- for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
- if (addr < (xp->f_addr + xp->f_size))
- addr = xp->f_addr + xp->f_size;
- }
- /* pad to a page boundary */
- addr = roundup(addr, PAGE_SIZE);
-
- /* copy our environment */
- envp = addr;
- addr = md_copyenv(addr);
-
- /* pad to a page boundary */
- addr = roundup(addr, PAGE_SIZE);
-
- kernend = 0;
- kfp = file_findfile(NULL, "elf32 kernel");
- if (kfp == NULL)
- kfp = file_findfile(NULL, "elf kernel");
- if (kfp == NULL)
- panic("can't find kernel file");
- file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto);
- file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp);
- file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend);
-
- *modulep = addr;
- size = md_copymodules(0);
- kernend = roundup(addr + size, PAGE_SIZE);
-
- md = file_findmetadata(kfp, MODINFOMD_KERNEND);
- bcopy(&kernend, md->md_data, sizeof kernend);
-
- (void)md_copymodules(addr);
-
- return(0);
-}
diff --git a/sys/boot/powerpc/ofw/start.c b/sys/boot/powerpc/ofw/start.c
deleted file mode 100644
index 9f37ce0027c6..000000000000
--- a/sys/boot/powerpc/ofw/start.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai Exp $ */
-
-/*
- * Copyright (C) 1995, 1996 Wolfgang Solfrank.
- * Copyright (C) 1995, 1996 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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 <stand.h>
-#include "libofw.h"
-
-void startup(void *, int, int (*)(void *), char *, int);
-
-#ifdef XCOFF_GLUE
-asm("
- .text
- .globl _entry
-_entry:
- .long _start,0,0
-");
-#endif
-
-__asm("
- .data
-stack:
- .space 16388
-
- .text
- .globl _start
-_start:
- li 8,0
- li 9,0x100
- mtctr 9
-1:
- dcbf 0,8
- icbi 0,8
- addi 8,8,0x20
- bdnz 1b
- sync
- isync
-
- lis 1,stack@ha
- addi 1,1,stack@l
- addi 1,1,8192
-
- mfmsr 8
- li 0,0
- mtmsr 0
- isync
-
- mtibatu 0,0
- mtibatu 1,0
- mtibatu 2,0
- mtibatu 3,0
- mtdbatu 0,0
- mtdbatu 1,0
- mtdbatu 2,0
- mtdbatu 3,0
-
- li 9,0x12 /* BATL(0, BAT_M, BAT_PP_RW) */
- mtibatl 0,9
- mtdbatl 0,9
- li 9,0x1ffe /* BATU(0, BAT_BL_256M, BAT_Vs) */
- mtibatu 0,9
- mtdbatu 0,9
- isync
-
- mtmsr 8
- isync
-
- b startup
-");
-
-void
-startup(void *vpd, int res, int (*openfirm)(void *), char *arg, int argl)
-{
- main(openfirm);
-}
diff --git a/sys/boot/powerpc/ofw/version b/sys/boot/powerpc/ofw/version
deleted file mode 100644
index cb0f6938f966..000000000000
--- a/sys/boot/powerpc/ofw/version
+++ /dev/null
@@ -1,6 +0,0 @@
-$FreeBSD$
-
-NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE. The format of this
-file is important. Make sure the current version number is on line 6.
-
-0.1: Initial OFW/PowerPC version.
diff --git a/sys/boot/sparc64/boot1/_start.s b/sys/boot/sparc64/boot1/_start.s
deleted file mode 100644
index 30f8019cc863..000000000000
--- a/sys/boot/sparc64/boot1/_start.s
+++ /dev/null
@@ -1,8 +0,0 @@
-/* $FreeBSD$ */
-
- .text
- .globl _start
-_start:
- call ofw_init
- nop
- sir
diff --git a/sys/compat/freebsd32/Makefile b/sys/compat/freebsd32/Makefile
deleted file mode 100644
index 22b5821bb60c..000000000000
--- a/sys/compat/freebsd32/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-# Makefile for syscall tables
-#
-# $FreeBSD$
-
-all:
- @echo "make sysent only"
-
-sysent: ia32_sysent.c ia32_syscall.h ia32_proto.h
-
-ia32_sysent.c ia32_syscalls.c ia32_syscall.h ia32_proto.h: ../../kern/makesyscalls.sh \
- syscalls.master syscalls.conf
- -mv -f ia32_sysent.c ia32_sysent.c.bak
- -mv -f ia32_syscalls.c ia32_syscalls.c.bak
- -mv -f ia32_syscall.h ia32_syscall.h.bak
- -mv -f ia32_proto.h ia32_proto.h.bak
- sh ../../kern/makesyscalls.sh syscalls.master syscalls.conf
diff --git a/sys/compat/freebsd32/freebsd32.h b/sys/compat/freebsd32/freebsd32.h
deleted file mode 100644
index 943b24c61ed3..000000000000
--- a/sys/compat/freebsd32/freebsd32.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*-
- * Copyright (c) 2001 Doug Rabson
- * 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 _IA64_IA32_IA32_H_
-#define _IA64_IA32_IA32_H_
-
-#define PTRIN(v) (void *)(uintptr_t) (v)
-#define PTROUT(v) (u_int32_t)(uintptr_t) (v)
-
-#define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
-#define PTRIN_CP(src,dst,fld) \
- do { (dst).fld = PTRIN((src).fld); } while (0)
-#define PTROUT_CP(src,dst,fld) \
- do { (dst).fld = PTROUT((src).fld); } while (0)
-
-struct timeval32 {
- int32_t tv_sec;
- int32_t tv_usec;
-};
-#define TV_CP(src,dst,fld) do { \
- CP((src).fld,(dst).fld,tv_sec); \
- CP((src).fld,(dst).fld,tv_usec); \
-} while (0);
-
-struct timespec32 {
- u_int32_t tv_sec;
- u_int32_t tv_nsec;
-};
-#define TS_CP(src,dst,fld) do { \
- CP((src).fld,(dst).fld,tv_sec); \
- CP((src).fld,(dst).fld,tv_nsec); \
-} while (0);
-
-struct rusage32 {
- struct timeval32 ru_utime;
- struct timeval32 ru_stime;
- int32_t ru_maxrss;
- int32_t ru_ixrss;
- int32_t ru_idrss;
- int32_t ru_isrss;
- int32_t ru_minflt;
- int32_t ru_majflt;
- int32_t ru_nswap;
- int32_t ru_inblock;
- int32_t ru_oublock;
- int32_t ru_msgsnd;
- int32_t ru_msgrcv;
- int32_t ru_nsignals;
- int32_t ru_nvcsw;
- int32_t ru_nivcsw;
-};
-
-struct statfs32 {
- int32_t f_spare2;
- int32_t f_bsize;
- int32_t f_iosize;
- int32_t f_blocks;
- int32_t f_bfree;
- int32_t f_bavail;
- int32_t f_files;
- int32_t f_ffree;
- fsid_t f_fsid;
- uid_t f_owner;
- int32_t f_type;
- int32_t f_flags;
- int32_t f_syncwrites;
- int32_t f_asyncwrites;
- char f_fstypename[MFSNAMELEN];
- char f_mntonname[MNAMELEN];
- int32_t f_syncreads;
- int32_t f_asyncreads;
- int16_t f_spares1;
- char f_mntfromname[MNAMELEN];
- int16_t f_spares2;
- int32_t f_spare[2];
-};
-
-#endif /* !_IA64_IA32_IA32_H_ */
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
deleted file mode 100644
index 9ef02c5c2421..000000000000
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ /dev/null
@@ -1,1436 +0,0 @@
-/*-
- * Copyright (c) 2002 Doug Rabson
- * 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$
- */
-
-#include "opt_compat.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/exec.h>
-#include <sys/fcntl.h>
-#include <sys/filedesc.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/file.h> /* Must come after sys/malloc.h */
-#include <sys/mman.h>
-#include <sys/module.h>
-#include <sys/mount.h>
-#include <sys/mutex.h>
-#include <sys/namei.h>
-#include <sys/param.h>
-#include <sys/proc.h>
-#include <sys/reboot.h>
-#include <sys/resource.h>
-#include <sys/resourcevar.h>
-#include <sys/selinfo.h>
-#include <sys/pipe.h> /* Must come after sys/selinfo.h */
-#include <sys/signal.h>
-#include <sys/signalvar.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/stat.h>
-#include <sys/syscallsubr.h>
-#include <sys/sysctl.h>
-#include <sys/sysent.h>
-#include <sys/sysproto.h>
-#include <sys/systm.h>
-#include <sys/unistd.h>
-#include <sys/user.h>
-#include <sys/utsname.h>
-#include <sys/vnode.h>
-
-#include <vm/vm.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-#include <vm/vm_extern.h>
-
-#include <amd64/ia32/ia32_util.h>
-#include <amd64/ia32/ia32.h>
-#include <amd64/ia32/ia32_proto.h>
-
-static const char ia32_emul_path[] = "/compat/ia32";
-/*
- * [ taken from the linux emulator ]
- * Search an alternate path before passing pathname arguments on
- * to system calls. Useful for keeping a separate 'emulation tree'.
- *
- * If cflag is set, we check if an attempt can be made to create
- * the named file, i.e. we check if the directory it should
- * be in exists.
- */
-int
-ia32_emul_find(td, sgp, prefix, path, pbuf, cflag)
- struct thread *td;
- caddr_t *sgp; /* Pointer to stackgap memory */
- const char *prefix;
- char *path;
- char **pbuf;
- int cflag;
-{
- int error;
- size_t len, sz;
- char *buf, *cp, *ptr;
- struct ucred *ucred;
- struct nameidata nd;
- struct nameidata ndroot;
- struct vattr vat;
- struct vattr vatroot;
-
- buf = (char *) malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
- *pbuf = path;
-
- for (ptr = buf; (*ptr = *prefix) != '\0'; ptr++, prefix++)
- continue;
-
- sz = MAXPATHLEN - (ptr - buf);
-
- /*
- * If sgp is not given then the path is already in kernel space
- */
- if (sgp == NULL)
- error = copystr(path, ptr, sz, &len);
- else
- error = copyinstr(path, ptr, sz, &len);
-
- if (error) {
- free(buf, M_TEMP);
- return error;
- }
-
- if (*ptr != '/') {
- free(buf, M_TEMP);
- return EINVAL;
- }
-
- /*
- * We know that there is a / somewhere in this pathname.
- * Search backwards for it, to find the file's parent dir
- * to see if it exists in the alternate tree. If it does,
- * and we want to create a file (cflag is set). We don't
- * need to worry about the root comparison in this case.
- */
-
- if (cflag) {
- for (cp = &ptr[len] - 1; *cp != '/'; cp--)
- ;
- *cp = '\0';
-
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, td);
-
- if ((error = namei(&nd)) != 0) {
- free(buf, M_TEMP);
- return error;
- }
-
- *cp = '/';
- } else {
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, td);
-
- if ((error = namei(&nd)) != 0) {
- free(buf, M_TEMP);
- return error;
- }
-
- /*
- * We now compare the vnode of the ia32_root to the one
- * vnode asked. If they resolve to be the same, then we
- * ignore the match so that the real root gets used.
- * This avoids the problem of traversing "../.." to find the
- * root directory and never finding it, because "/" resolves
- * to the emulation root directory. This is expensive :-(
- */
- NDINIT(&ndroot, LOOKUP, FOLLOW, UIO_SYSSPACE, ia32_emul_path,
- td);
-
- if ((error = namei(&ndroot)) != 0) {
- /* Cannot happen! */
- free(buf, M_TEMP);
- vrele(nd.ni_vp);
- return error;
- }
-
- ucred = td->td_ucred;
- if ((error = VOP_GETATTR(nd.ni_vp, &vat, ucred, td)) != 0) {
- goto bad;
- }
-
- if ((error = VOP_GETATTR(ndroot.ni_vp, &vatroot, ucred,
- td)) != 0) {
- goto bad;
- }
-
- if (vat.va_fsid == vatroot.va_fsid &&
- vat.va_fileid == vatroot.va_fileid) {
- error = ENOENT;
- goto bad;
- }
-
- }
- if (sgp == NULL)
- *pbuf = buf;
- else {
- sz = &ptr[len] - buf;
- *pbuf = stackgap_alloc(sgp, sz + 1);
- error = copyout(buf, *pbuf, sz);
- free(buf, M_TEMP);
- }
-
- vrele(nd.ni_vp);
- if (!cflag)
- vrele(ndroot.ni_vp);
-
- return error;
-
-bad:
- vrele(ndroot.ni_vp);
- vrele(nd.ni_vp);
- free(buf, M_TEMP);
- return error;
-}
-
-int
-ia32_open(struct thread *td, struct ia32_open_args *uap)
-{
- caddr_t sg;
-
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, uap->path);
-
- return open(td, (struct open_args *) uap);
-}
-
-int
-ia32_wait4(struct thread *td, struct ia32_wait4_args *uap)
-{
- int error;
- caddr_t sg;
- struct rusage32 *rusage32, ru32;
- struct rusage *rusage = NULL, ru;
-
- rusage32 = uap->rusage;
- if (rusage32) {
- sg = stackgap_init();
- rusage = stackgap_alloc(&sg, sizeof(struct rusage));
- uap->rusage = (struct rusage32 *)rusage;
- }
- error = wait4(td, (struct wait_args *)uap);
- if (error)
- return (error);
- if (rusage32 && (error = copyin(rusage, &ru, sizeof(ru)) == 0)) {
- TV_CP(ru, ru32, ru_utime);
- TV_CP(ru, ru32, ru_stime);
- CP(ru, ru32, ru_maxrss);
- CP(ru, ru32, ru_ixrss);
- CP(ru, ru32, ru_idrss);
- CP(ru, ru32, ru_isrss);
- CP(ru, ru32, ru_minflt);
- CP(ru, ru32, ru_majflt);
- CP(ru, ru32, ru_nswap);
- CP(ru, ru32, ru_inblock);
- CP(ru, ru32, ru_oublock);
- CP(ru, ru32, ru_msgsnd);
- CP(ru, ru32, ru_msgrcv);
- CP(ru, ru32, ru_nsignals);
- CP(ru, ru32, ru_nvcsw);
- CP(ru, ru32, ru_nivcsw);
- error = copyout(&ru32, rusage32, sizeof(ru32));
- }
- return (error);
-}
-
-static void
-copy_statfs(struct statfs *in, struct statfs32 *out)
-{
- CP(*in, *out, f_bsize);
- CP(*in, *out, f_iosize);
- CP(*in, *out, f_blocks);
- CP(*in, *out, f_bfree);
- CP(*in, *out, f_bavail);
- CP(*in, *out, f_files);
- CP(*in, *out, f_ffree);
- CP(*in, *out, f_fsid);
- CP(*in, *out, f_owner);
- CP(*in, *out, f_type);
- CP(*in, *out, f_flags);
- CP(*in, *out, f_flags);
- CP(*in, *out, f_syncwrites);
- CP(*in, *out, f_asyncwrites);
- bcopy(in->f_fstypename,
- out->f_fstypename, MFSNAMELEN);
- bcopy(in->f_mntonname,
- out->f_mntonname, MNAMELEN);
- CP(*in, *out, f_syncreads);
- CP(*in, *out, f_asyncreads);
- bcopy(in->f_mntfromname,
- out->f_mntfromname, MNAMELEN);
-}
-
-int
-ia32_getfsstat(struct thread *td, struct ia32_getfsstat_args *uap)
-{
- int error;
- caddr_t sg;
- struct statfs32 *sp32, stat32;
- struct statfs *sp = NULL, stat;
- int maxcount, count, i;
-
- sp32 = uap->buf;
- maxcount = uap->bufsize / sizeof(struct statfs32);
-
- if (sp32) {
- sg = stackgap_init();
- sp = stackgap_alloc(&sg, sizeof(struct statfs) * maxcount);
- uap->buf = (struct statfs32 *)sp;
- }
- error = getfsstat(td, (struct getfsstat_args *) uap);
- if (sp32 && !error) {
- count = td->td_retval[0];
- for (i = 0; i < count; i++) {
- error = copyin(&sp[i], &stat, sizeof(stat));
- if (error)
- return (error);
- copy_statfs(&stat, &stat32);
- error = copyout(&stat32, &sp32[i], sizeof(stat32));
- if (error)
- return (error);
- }
- }
- return (error);
-}
-
-int
-ia32_access(struct thread *td, struct ia32_access_args *uap)
-{
- caddr_t sg;
-
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, uap->path);
-
- return access(td, (struct access_args *)uap);
-}
-
-int
-ia32_chflags(struct thread *td, struct ia32_chflags_args *uap)
-{
- caddr_t sg;
-
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, uap->path);
-
- return chflags(td, (struct chflags_args *)uap);
-}
-
-struct sigaltstack32 {
- u_int32_t ss_sp;
- u_int32_t ss_size;
- int ss_flags;
-};
-
-int
-ia32_sigaltstack(struct thread *td, struct ia32_sigaltstack_args *uap)
-{
- struct sigaltstack32 s32;
- struct sigaltstack ss, oss, *ssp;
- int error;
-
- if (uap->ss != NULL) {
- error = copyin(uap->ss, &s32, sizeof(s32));
- if (error)
- return (error);
- PTRIN_CP(s32, ss, ss_sp);
- CP(s32, ss, ss_size);
- CP(s32, ss, ss_flags);
- ssp = &ss;
- } else
- ssp = NULL;
- error = kern_sigaltstack(td, ssp, &oss);
- if (error == 0 && uap->oss != NULL) {
- PTROUT_CP(oss, s32, ss_sp);
- CP(oss, s32, ss_size);
- CP(oss, s32, ss_flags);
- error = copyout(&s32, uap->oss, sizeof(s32));
- }
- return (error);
-}
-
-int
-ia32_execve(struct thread *td, struct ia32_execve_args *uap)
-{
- int error;
- caddr_t sg;
- struct execve_args ap;
- u_int32_t *p32, arg;
- char **p;
- int count;
-
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, uap->fname);
- ap.fname = uap->fname;
-
- if (uap->argv) {
- count = 0;
- p32 = uap->argv;
- do {
- error = copyin(p32++, &arg, sizeof(arg));
- if (error)
- return error;
- count++;
- } while (arg != 0);
- p = stackgap_alloc(&sg, count * sizeof(char *));
- ap.argv = p;
- p32 = uap->argv;
- do {
- error = copyin(p32++, &arg, sizeof(arg));
- if (error)
- return error;
- *p++ = PTRIN(arg);
- } while (arg != 0);
- }
- if (uap->envv) {
- count = 0;
- p32 = uap->envv;
- do {
- error = copyin(p32++, &arg, sizeof(arg));
- if (error)
- return error;
- count++;
- } while (arg != 0);
- p = stackgap_alloc(&sg, count * sizeof(char *));
- ap.envv = p;
- p32 = uap->envv;
- do {
- error = copyin(p32++, &arg, sizeof(arg));
- if (error)
- return error;
- *p++ = PTRIN(arg);
- } while (arg != 0);
- }
-
- return execve(td, &ap);
-}
-
-#ifdef __ia64__
-static int
-ia32_mmap_partial(struct thread *td, vm_offset_t start, vm_offset_t end,
- int prot, int fd, off_t pos)
-{
- vm_map_t map;
- vm_map_entry_t entry;
- int rv;
-
- map = &td->td_proc->p_vmspace->vm_map;
- if (fd != -1)
- prot |= VM_PROT_WRITE;
-
- if (vm_map_lookup_entry(map, start, &entry)) {
- if ((entry->protection & prot) != prot) {
- rv = vm_map_protect(map,
- trunc_page(start),
- round_page(end),
- entry->protection | prot,
- FALSE);
- if (rv != KERN_SUCCESS)
- return (EINVAL);
- }
- } else {
- vm_offset_t addr = trunc_page(start);
- rv = vm_map_find(map, 0, 0,
- &addr, PAGE_SIZE, FALSE, prot,
- VM_PROT_ALL, 0);
- if (rv != KERN_SUCCESS)
- return (EINVAL);
- }
-
- if (fd != -1) {
- struct pread_args r;
- r.fd = fd;
- r.buf = (void *) start;
- r.nbyte = end - start;
- r.offset = pos;
- return (pread(td, &r));
- } else {
- while (start < end) {
- subyte((void *) start, 0);
- start++;
- }
- return (0);
- }
-}
-#endif
-
-int
-ia32_mmap(struct thread *td, struct ia32_mmap_args *uap)
-{
- struct mmap_args ap;
- vm_offset_t addr = (vm_offset_t) uap->addr;
- vm_size_t len = uap->len;
- int prot = uap->prot;
- int flags = uap->flags;
- int fd = uap->fd;
- off_t pos = (uap->poslo
- | ((off_t)uap->poshi << 32));
-#ifdef __ia64__
- vm_size_t pageoff;
- int error;
-
- /*
- * Attempt to handle page size hassles.
- */
- pageoff = (pos & PAGE_MASK);
- if (flags & MAP_FIXED) {
- vm_offset_t start, end;
- start = addr;
- end = addr + len;
-
- if (start != trunc_page(start)) {
- error = ia32_mmap_partial(td, start, round_page(start),
- prot, fd, pos);
- if (fd != -1)
- pos += round_page(start) - start;
- start = round_page(start);
- }
- if (end != round_page(end)) {
- vm_offset_t t = trunc_page(end);
- error = ia32_mmap_partial(td, t, end,
- prot, fd,
- pos + t - start);
- end = trunc_page(end);
- }
- if (end > start && fd != -1 && (pos & PAGE_MASK)) {
- /*
- * We can't map this region at all. The specified
- * address doesn't have the same alignment as the file
- * position. Fake the mapping by simply reading the
- * entire region into memory. First we need to make
- * sure the region exists.
- */
- vm_map_t map;
- struct pread_args r;
- int rv;
-
- prot |= VM_PROT_WRITE;
- map = &td->td_proc->p_vmspace->vm_map;
- rv = vm_map_remove(map, start, end);
- if (rv != KERN_SUCCESS)
- return (EINVAL);
- rv = vm_map_find(map, 0, 0,
- &start, end - start, FALSE,
- prot, VM_PROT_ALL, 0);
- if (rv != KERN_SUCCESS)
- return (EINVAL);
- r.fd = fd;
- r.buf = (void *) start;
- r.nbyte = end - start;
- r.offset = pos;
- error = pread(td, &r);
- if (error)
- return (error);
-
- td->td_retval[0] = addr;
- return (0);
- }
- if (end == start) {
- /*
- * After dealing with the ragged ends, there
- * might be none left.
- */
- td->td_retval[0] = addr;
- return (0);
- }
- addr = start;
- len = end - start;
- }
-#endif
-
- ap.addr = (void *) addr;
- ap.len = len;
- ap.prot = prot;
- ap.flags = flags;
- ap.fd = fd;
- ap.pos = pos;
-
- return (mmap(td, &ap));
-}
-
-struct itimerval32 {
- struct timeval32 it_interval;
- struct timeval32 it_value;
-};
-
-int
-ia32_setitimer(struct thread *td, struct ia32_setitimer_args *uap)
-{
- int error;
- caddr_t sg;
- struct itimerval32 *p32, *op32, s32;
- struct itimerval *p = NULL, *op = NULL, s;
-
- p32 = uap->itv;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, sizeof(struct itimerval));
- uap->itv = (struct itimerval32 *)p;
- error = copyin(p32, &s32, sizeof(s32));
- if (error)
- return (error);
- TV_CP(s32, s, it_interval);
- TV_CP(s32, s, it_value);
- error = copyout(&s, p, sizeof(s));
- if (error)
- return (error);
- }
- op32 = uap->oitv;
- if (op32) {
- sg = stackgap_init();
- op = stackgap_alloc(&sg, sizeof(struct itimerval));
- uap->oitv = (struct itimerval32 *)op;
- }
- error = setitimer(td, (struct setitimer_args *) uap);
- if (error)
- return (error);
- if (op32) {
- error = copyin(op, &s, sizeof(s));
- if (error)
- return (error);
- TV_CP(s, s32, it_interval);
- TV_CP(s, s32, it_value);
- error = copyout(&s32, op32, sizeof(s32));
- }
- return (error);
-}
-
-int
-ia32_select(struct thread *td, struct ia32_select_args *uap)
-{
- int error;
- caddr_t sg;
- struct timeval32 *p32, s32;
- struct timeval *p = NULL, s;
-
- p32 = uap->tv;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, sizeof(struct timeval));
- uap->tv = (struct timeval32 *)p;
- error = copyin(p32, &s32, sizeof(s32));
- if (error)
- return (error);
- CP(s32, s, tv_sec);
- CP(s32, s, tv_usec);
- error = copyout(&s, p, sizeof(s));
- if (error)
- return (error);
- }
- /*
- * XXX big-endian needs to convert the fd_sets too.
- */
- return (select(td, (struct select_args *) uap));
-}
-
-struct kevent32 {
- u_int32_t ident; /* identifier for this event */
- short filter; /* filter for event */
- u_short flags;
- u_int fflags;
- int32_t data;
- u_int32_t udata; /* opaque user data identifier */
-};
-
-int
-ia32_kevent(struct thread *td, struct ia32_kevent_args *uap)
-{
- int error;
- caddr_t sg;
- struct timespec32 ts32;
- struct timespec ts;
- struct kevent32 ks32;
- struct kevent *ks;
- struct kevent_args a;
- int i;
-
- sg = stackgap_init();
-
- a.fd = uap->fd;
- a.changelist = uap->changelist;
- a.nchanges = uap->nchanges;
- a.eventlist = uap->eventlist;
- a.nevents = uap->nevents;
- a.timeout = NULL;
-
- if (uap->timeout) {
- a.timeout = stackgap_alloc(&sg, sizeof(struct timespec));
- error = copyin(uap->timeout, &ts32, sizeof(ts32));
- if (error)
- return (error);
- CP(ts32, ts, tv_sec);
- CP(ts32, ts, tv_nsec);
- error = copyout(&ts, (void *)(uintptr_t)a.timeout, sizeof(ts));
- if (error)
- return (error);
- }
- if (uap->changelist) {
- a.changelist = (struct kevent *)stackgap_alloc(&sg, uap->nchanges * sizeof(struct kevent));
- for (i = 0; i < uap->nchanges; i++) {
- error = copyin(&uap->changelist[i], &ks32, sizeof(ks32));
- if (error)
- return (error);
- ks = (struct kevent *)(uintptr_t)&a.changelist[i];
- CP(ks32, *ks, ident);
- CP(ks32, *ks, filter);
- CP(ks32, *ks, flags);
- CP(ks32, *ks, fflags);
- CP(ks32, *ks, data);
- PTRIN_CP(ks32, *ks, udata);
- }
- }
- if (uap->eventlist) {
- a.eventlist = stackgap_alloc(&sg, uap->nevents * sizeof(struct kevent));
- }
- error = kevent(td, &a);
- if (uap->eventlist && error > 0) {
- for (i = 0; i < error; i++) {
- ks = &a.eventlist[i];
- CP(*ks, ks32, ident);
- CP(*ks, ks32, filter);
- CP(*ks, ks32, flags);
- CP(*ks, ks32, fflags);
- CP(*ks, ks32, data);
- PTROUT_CP(*ks, ks32, udata);
- error = copyout(&ks32, &uap->eventlist[i], sizeof(ks32));
- if (error)
- return (error);
- }
- }
- return error;
-}
-
-int
-ia32_gettimeofday(struct thread *td, struct ia32_gettimeofday_args *uap)
-{
- int error;
- caddr_t sg;
- struct timeval32 *p32, s32;
- struct timeval *p = NULL, s;
-
- p32 = uap->tp;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, sizeof(struct timeval));
- uap->tp = (struct timeval32 *)p;
- }
- error = gettimeofday(td, (struct gettimeofday_args *) uap);
- if (error)
- return (error);
- if (p32) {
- error = copyin(p, &s, sizeof(s));
- if (error)
- return (error);
- CP(s, s32, tv_sec);
- CP(s, s32, tv_usec);
- error = copyout(&s32, p32, sizeof(s32));
- if (error)
- return (error);
- }
- return (error);
-}
-
-int
-ia32_getrusage(struct thread *td, struct ia32_getrusage_args *uap)
-{
- int error;
- caddr_t sg;
- struct rusage32 *p32, s32;
- struct rusage *p = NULL, s;
-
- p32 = uap->rusage;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, sizeof(struct rusage));
- uap->rusage = (struct rusage32 *)p;
- }
- error = getrusage(td, (struct getrusage_args *) uap);
- if (error)
- return (error);
- if (p32) {
- error = copyin(p, &s, sizeof(s));
- if (error)
- return (error);
- TV_CP(s, s32, ru_utime);
- TV_CP(s, s32, ru_stime);
- CP(s, s32, ru_maxrss);
- CP(s, s32, ru_ixrss);
- CP(s, s32, ru_idrss);
- CP(s, s32, ru_isrss);
- CP(s, s32, ru_minflt);
- CP(s, s32, ru_majflt);
- CP(s, s32, ru_nswap);
- CP(s, s32, ru_inblock);
- CP(s, s32, ru_oublock);
- CP(s, s32, ru_msgsnd);
- CP(s, s32, ru_msgrcv);
- CP(s, s32, ru_nsignals);
- CP(s, s32, ru_nvcsw);
- CP(s, s32, ru_nivcsw);
- error = copyout(&s32, p32, sizeof(s32));
- }
- return (error);
-}
-
-struct iovec32 {
- u_int32_t iov_base;
- int iov_len;
-};
-#define STACKGAPLEN 400
-
-int
-ia32_readv(struct thread *td, struct ia32_readv_args *uap)
-{
- int error, osize, nsize, i;
- caddr_t sg;
- struct readv_args /* {
- syscallarg(int) fd;
- syscallarg(struct iovec *) iovp;
- syscallarg(u_int) iovcnt;
- } */ a;
- struct iovec32 *oio;
- struct iovec *nio;
-
- sg = stackgap_init();
-
- if (uap->iovcnt > (STACKGAPLEN / sizeof (struct iovec)))
- return (EINVAL);
-
- osize = uap->iovcnt * sizeof (struct iovec32);
- nsize = uap->iovcnt * sizeof (struct iovec);
-
- oio = malloc(osize, M_TEMP, M_WAITOK);
- nio = malloc(nsize, M_TEMP, M_WAITOK);
-
- error = 0;
- if ((error = copyin(uap->iovp, oio, osize)))
- goto punt;
- for (i = 0; i < uap->iovcnt; i++) {
- nio[i].iov_base = PTRIN(oio[i].iov_base);
- nio[i].iov_len = oio[i].iov_len;
- }
-
- a.fd = uap->fd;
- a.iovp = stackgap_alloc(&sg, nsize);
- a.iovcnt = uap->iovcnt;
-
- if ((error = copyout(nio, (caddr_t)a.iovp, nsize)))
- goto punt;
- error = readv(td, &a);
-
-punt:
- free(oio, M_TEMP);
- free(nio, M_TEMP);
- return (error);
-}
-
-int
-ia32_writev(struct thread *td, struct ia32_writev_args *uap)
-{
- int error, i, nsize, osize;
- caddr_t sg;
- struct writev_args /* {
- syscallarg(int) fd;
- syscallarg(struct iovec *) iovp;
- syscallarg(u_int) iovcnt;
- } */ a;
- struct iovec32 *oio;
- struct iovec *nio;
-
- sg = stackgap_init();
-
- if (uap->iovcnt > (STACKGAPLEN / sizeof (struct iovec)))
- return (EINVAL);
-
- osize = uap->iovcnt * sizeof (struct iovec32);
- nsize = uap->iovcnt * sizeof (struct iovec);
-
- oio = malloc(osize, M_TEMP, M_WAITOK);
- nio = malloc(nsize, M_TEMP, M_WAITOK);
-
- error = 0;
- if ((error = copyin(uap->iovp, oio, osize)))
- goto punt;
- for (i = 0; i < uap->iovcnt; i++) {
- nio[i].iov_base = PTRIN(oio[i].iov_base);
- nio[i].iov_len = oio[i].iov_len;
- }
-
- a.fd = uap->fd;
- a.iovp = stackgap_alloc(&sg, nsize);
- a.iovcnt = uap->iovcnt;
-
- if ((error = copyout(nio, (caddr_t)a.iovp, nsize)))
- goto punt;
- error = writev(td, &a);
-
-punt:
- free(oio, M_TEMP);
- free(nio, M_TEMP);
- return (error);
-}
-
-int
-ia32_settimeofday(struct thread *td, struct ia32_settimeofday_args *uap)
-{
- int error;
- caddr_t sg;
- struct timeval32 *p32, s32;
- struct timeval *p = NULL, s;
-
- p32 = uap->tv;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, sizeof(struct timeval));
- uap->tv = (struct timeval32 *)p;
- error = copyin(p32, &s32, sizeof(s32));
- if (error)
- return (error);
- CP(s32, s, tv_sec);
- CP(s32, s, tv_usec);
- error = copyout(&s, p, sizeof(s));
- if (error)
- return (error);
- }
- return (settimeofday(td, (struct settimeofday_args *) uap));
-}
-
-int
-ia32_utimes(struct thread *td, struct ia32_utimes_args *uap)
-{
- int error;
- caddr_t sg;
- struct timeval32 *p32, s32[2];
- struct timeval *p = NULL, s[2];
-
- p32 = uap->tptr;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, 2*sizeof(struct timeval));
- uap->tptr = (struct timeval32 *)p;
- error = copyin(p32, s32, sizeof(s32));
- if (error)
- return (error);
- CP(s32[0], s[0], tv_sec);
- CP(s32[0], s[0], tv_usec);
- CP(s32[1], s[1], tv_sec);
- CP(s32[1], s[1], tv_usec);
- error = copyout(s, p, sizeof(s));
- if (error)
- return (error);
- }
- return (utimes(td, (struct utimes_args *) uap));
-}
-
-int
-ia32_adjtime(struct thread *td, struct ia32_adjtime_args *uap)
-{
- int error;
- caddr_t sg;
- struct timeval32 *p32, *op32, s32;
- struct timeval *p = NULL, *op = NULL, s;
-
- p32 = uap->delta;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, sizeof(struct timeval));
- uap->delta = (struct timeval32 *)p;
- error = copyin(p32, &s32, sizeof(s32));
- if (error)
- return (error);
- CP(s32, s, tv_sec);
- CP(s32, s, tv_usec);
- error = copyout(&s, p, sizeof(s));
- if (error)
- return (error);
- }
- op32 = uap->olddelta;
- if (op32) {
- sg = stackgap_init();
- op = stackgap_alloc(&sg, sizeof(struct timeval));
- uap->olddelta = (struct timeval32 *)op;
- }
- error = utimes(td, (struct utimes_args *) uap);
- if (error)
- return error;
- if (op32) {
- error = copyin(op, &s, sizeof(s));
- if (error)
- return (error);
- CP(s, s32, tv_sec);
- CP(s, s32, tv_usec);
- error = copyout(&s32, op32, sizeof(s32));
- }
- return (error);
-}
-
-int
-ia32_statfs(struct thread *td, struct ia32_statfs_args *uap)
-{
- int error;
- caddr_t sg;
- struct statfs32 *p32, s32;
- struct statfs *p = NULL, s;
-
- p32 = uap->buf;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, sizeof(struct statfs));
- uap->buf = (struct statfs32 *)p;
- }
- error = statfs(td, (struct statfs_args *) uap);
- if (error)
- return (error);
- if (p32) {
- error = copyin(p, &s, sizeof(s));
- if (error)
- return (error);
- copy_statfs(&s, &s32);
- error = copyout(&s32, p32, sizeof(s32));
- }
- return (error);
-}
-
-int
-ia32_fstatfs(struct thread *td, struct ia32_fstatfs_args *uap)
-{
- int error;
- caddr_t sg;
- struct statfs32 *p32, s32;
- struct statfs *p = NULL, s;
-
- p32 = uap->buf;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, sizeof(struct statfs));
- uap->buf = (struct statfs32 *)p;
- }
- error = fstatfs(td, (struct fstatfs_args *) uap);
- if (error)
- return (error);
- if (p32) {
- error = copyin(p, &s, sizeof(s));
- if (error)
- return (error);
- copy_statfs(&s, &s32);
- error = copyout(&s32, p32, sizeof(s32));
- }
- return (error);
-}
-
-int
-ia32_semsys(struct thread *td, struct ia32_semsys_args *uap)
-{
- /*
- * Vector through to semsys if it is loaded.
- */
- return sysent[169].sy_call(td, uap);
-}
-
-int
-ia32_msgsys(struct thread *td, struct ia32_msgsys_args *uap)
-{
- /*
- * Vector through to msgsys if it is loaded.
- */
- return sysent[170].sy_call(td, uap);
-}
-
-int
-ia32_shmsys(struct thread *td, struct ia32_shmsys_args *uap)
-{
- /*
- * Vector through to shmsys if it is loaded.
- */
- return sysent[171].sy_call(td, uap);
-}
-
-int
-ia32_pread(struct thread *td, struct ia32_pread_args *uap)
-{
- struct pread_args ap;
-
- ap.fd = uap->fd;
- ap.buf = uap->buf;
- ap.nbyte = uap->nbyte;
- ap.offset = (uap->offsetlo
- | ((off_t)uap->offsethi << 32));
- return (pread(td, &ap));
-}
-
-int
-ia32_pwrite(struct thread *td, struct ia32_pwrite_args *uap)
-{
- struct pwrite_args ap;
-
- ap.fd = uap->fd;
- ap.buf = uap->buf;
- ap.nbyte = uap->nbyte;
- ap.offset = (uap->offsetlo
- | ((off_t)uap->offsethi << 32));
- return (pwrite(td, &ap));
-}
-
-int
-ia32_lseek(struct thread *td, struct ia32_lseek_args *uap)
-{
- int error;
- struct lseek_args ap;
- off_t pos;
-
- ap.fd = uap->fd;
- ap.offset = (uap->offsetlo
- | ((off_t)uap->offsethi << 32));
- ap.whence = uap->whence;
- error = lseek(td, &ap);
- /* Expand the quad return into two parts for eax and edx */
- pos = *(off_t *)(td->td_retval);
- td->td_retval[0] = pos & 0xffffffff; /* %eax */
- td->td_retval[1] = pos >> 32; /* %edx */
- return error;
-}
-
-int
-ia32_truncate(struct thread *td, struct ia32_truncate_args *uap)
-{
- struct truncate_args ap;
-
- ap.path = uap->path;
- ap.length = (uap->lengthlo
- | ((off_t)uap->lengthhi << 32));
- return (truncate(td, &ap));
-}
-
-int
-ia32_ftruncate(struct thread *td, struct ia32_ftruncate_args *uap)
-{
- struct ftruncate_args ap;
-
- ap.fd = uap->fd;
- ap.length = (uap->lengthlo
- | ((off_t)uap->lengthhi << 32));
- return (ftruncate(td, &ap));
-}
-
-#ifdef COMPAT_FREEBSD4
-int
-freebsd4_ia32_sendfile(struct thread *td,
- struct freebsd4_ia32_sendfile_args *uap)
-{
- struct freebsd4_sendfile_args ap;
-
- ap.fd = uap->fd;
- ap.s = uap->s;
- ap.offset = (uap->offsetlo
- | ((off_t)uap->offsethi << 32));
- ap.nbytes = uap->nbytes; /* XXX check */
- ap.hdtr = uap->hdtr; /* XXX check */
- ap.sbytes = uap->sbytes; /* XXX FIXME!! */
- ap.flags = uap->flags;
- return (freebsd4_sendfile(td, &ap));
-}
-#endif
-
-int
-ia32_sendfile(struct thread *td, struct ia32_sendfile_args *uap)
-{
- struct sendfile_args ap;
-
- ap.fd = uap->fd;
- ap.s = uap->s;
- ap.offset = (uap->offsetlo
- | ((off_t)uap->offsethi << 32));
- ap.nbytes = uap->nbytes; /* XXX check */
- ap.hdtr = uap->hdtr; /* XXX check */
- ap.sbytes = uap->sbytes; /* XXX FIXME!! */
- ap.flags = uap->flags;
- return (sendfile(td, &ap));
-}
-
-struct stat32 {
- udev_t st_dev;
- ino_t st_ino;
- mode_t st_mode;
- nlink_t st_nlink;
- uid_t st_uid;
- gid_t st_gid;
- udev_t st_rdev;
- struct timespec32 st_atimespec;
- struct timespec32 st_mtimespec;
- struct timespec32 st_ctimespec;
- off_t st_size;
- int64_t st_blocks;
- u_int32_t st_blksize;
- u_int32_t st_flags;
- u_int32_t st_gen;
-};
-
-static void
-copy_stat( struct stat *in, struct stat32 *out)
-{
- CP(*in, *out, st_dev);
- CP(*in, *out, st_ino);
- CP(*in, *out, st_mode);
- CP(*in, *out, st_nlink);
- CP(*in, *out, st_uid);
- CP(*in, *out, st_gid);
- CP(*in, *out, st_rdev);
- TS_CP(*in, *out, st_atimespec);
- TS_CP(*in, *out, st_mtimespec);
- TS_CP(*in, *out, st_ctimespec);
- CP(*in, *out, st_size);
- CP(*in, *out, st_blocks);
- CP(*in, *out, st_blksize);
- CP(*in, *out, st_flags);
- CP(*in, *out, st_gen);
-}
-
-int
-ia32_stat(struct thread *td, struct ia32_stat_args *uap)
-{
- int error;
- caddr_t sg;
- struct stat32 *p32, s32;
- struct stat *p = NULL, s;
-
- p32 = uap->ub;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, sizeof(struct stat));
- uap->ub = (struct stat32 *)p;
- }
- error = stat(td, (struct stat_args *) uap);
- if (error)
- return (error);
- if (p32) {
- error = copyin(p, &s, sizeof(s));
- if (error)
- return (error);
- copy_stat(&s, &s32);
- error = copyout(&s32, p32, sizeof(s32));
- }
- return (error);
-}
-
-int
-ia32_fstat(struct thread *td, struct ia32_fstat_args *uap)
-{
- int error;
- caddr_t sg;
- struct stat32 *p32, s32;
- struct stat *p = NULL, s;
-
- p32 = uap->ub;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, sizeof(struct stat));
- uap->ub = (struct stat32 *)p;
- }
- error = fstat(td, (struct fstat_args *) uap);
- if (error)
- return (error);
- if (p32) {
- error = copyin(p, &s, sizeof(s));
- if (error)
- return (error);
- copy_stat(&s, &s32);
- error = copyout(&s32, p32, sizeof(s32));
- }
- return (error);
-}
-
-int
-ia32_lstat(struct thread *td, struct ia32_lstat_args *uap)
-{
- int error;
- caddr_t sg;
- struct stat32 *p32, s32;
- struct stat *p = NULL, s;
-
- p32 = uap->ub;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, sizeof(struct stat));
- uap->ub = (struct stat32 *)p;
- }
- error = lstat(td, (struct lstat_args *) uap);
- if (error)
- return (error);
- if (p32) {
- error = copyin(p, &s, sizeof(s));
- if (error)
- return (error);
- copy_stat(&s, &s32);
- error = copyout(&s32, p32, sizeof(s32));
- }
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-ia32_sysctl(struct thread *td, struct ia32_sysctl_args *uap)
-{
- int error, name[CTL_MAXNAME];
- size_t j, oldlen;
-
- if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
- return (EINVAL);
-
- error = copyin(uap->name, &name, uap->namelen * sizeof(int));
- if (error)
- return (error);
-
- mtx_lock(&Giant);
-
- if (uap->oldlenp)
- oldlen = fuword32(uap->oldlenp);
- else
- oldlen = 0;
- error = userland_sysctl(td, name, uap->namelen,
- uap->old, &oldlen, 1,
- uap->new, uap->newlen, &j);
- if (error && error != ENOMEM)
- goto done2;
- if (uap->oldlenp) {
- suword32(uap->oldlenp, j);
- }
-done2:
- mtx_unlock(&Giant);
- return (error);
-}
-
-struct sigaction32 {
- u_int32_t sa_u;
- int sa_flags;
- sigset_t sa_mask;
-};
-
-int
-ia32_sigaction(struct thread *td, struct ia32_sigaction_args *uap)
-{
- struct sigaction32 s32;
- struct sigaction sa, osa, *sap;
- int error;
-
- if (uap->act) {
- error = copyin(uap->act, &s32, sizeof(s32));
- if (error)
- return (error);
- sa.sa_handler = PTRIN(s32.sa_u);
- CP(s32, sa, sa_flags);
- CP(s32, sa, sa_mask);
- sap = &sa;
- } else
- sap = NULL;
- error = kern_sigaction(td, uap->sig, sap, &osa, 0);
- if (error != 0 && uap->oact != NULL) {
- s32.sa_u = PTROUT(osa.sa_handler);
- CP(osa, s32, sa_flags);
- CP(osa, s32, sa_mask);
- error = copyout(&s32, uap->oact, sizeof(s32));
- }
- return (error);
-}
-
-#ifdef COMPAT_FREEBSD4
-int
-freebsd4_ia32_sigaction(struct thread *td, struct freebsd4_ia32_sigaction_args *uap)
-{
- struct sigaction32 s32;
- struct sigaction sa, osa, *sap;
- int error;
-
- if (uap->act) {
- error = copyin(uap->act, &s32, sizeof(s32));
- if (error)
- return (error);
- sa.sa_handler = PTRIN(s32.sa_u);
- CP(s32, sa, sa_flags);
- CP(s32, sa, sa_mask);
- sap = &sa;
- } else
- sap = NULL;
- error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
- if (error != 0 && uap->oact != NULL) {
- s32.sa_u = PTROUT(osa.sa_handler);
- CP(osa, s32, sa_flags);
- CP(osa, s32, sa_mask);
- error = copyout(&s32, uap->oact, sizeof(s32));
- }
- return (error);
-}
-#endif
-
-#if 0
-
-int
-ia32_xxx(struct thread *td, struct ia32_xxx_args *uap)
-{
- int error;
- caddr_t sg;
- struct yyy32 *p32, s32;
- struct yyy *p = NULL, s;
-
- p32 = uap->zzz;
- if (p32) {
- sg = stackgap_init();
- p = stackgap_alloc(&sg, sizeof(struct yyy));
- uap->zzz = (struct yyy32 *)p;
- error = copyin(p32, &s32, sizeof(s32));
- if (error)
- return (error);
- /* translate in */
- error = copyout(&s, p, sizeof(s));
- if (error)
- return (error);
- }
- error = xxx(td, (struct xxx_args *) uap);
- if (error)
- return (error);
- if (p32) {
- error = copyin(p, &s, sizeof(s));
- if (error)
- return (error);
- /* translate out */
- error = copyout(&s32, p32, sizeof(s32));
- }
- return (error);
-}
-
-#endif
diff --git a/sys/compat/freebsd32/freebsd32_proto.h b/sys/compat/freebsd32/freebsd32_proto.h
deleted file mode 100644
index 5252e88ab795..000000000000
--- a/sys/compat/freebsd32/freebsd32_proto.h
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * System call prototypes.
- *
- * DO NOT EDIT-- this file is automatically generated.
- * $FreeBSD$
- * created from FreeBSD: src/sys/amd64/ia32/syscalls.master,v 1.22 2003/05/14 04:10:49 peter Exp
- */
-
-#ifndef _IA32_SYSPROTO_H_
-#define _IA32_SYSPROTO_H_
-
-#include <sys/signal.h>
-#include <sys/acl.h>
-#include <sys/thr.h>
-#include <sys/umtx.h>
-#include <posix4/_semaphore.h>
-
-#include <sys/ucontext.h>
-
-struct proc;
-
-struct thread;
-
-#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \
- 0 : sizeof(register_t) - sizeof(t))
-
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define PADL_(t) 0
-#define PADR_(t) PAD_(t)
-#else
-#define PADL_(t) PAD_(t)
-#define PADR_(t) 0
-#endif
-
-struct ia32_open_args {
- char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
- char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
- char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)];
-};
-struct ia32_wait4_args {
- char pid_l_[PADL_(int)]; int pid; char pid_r_[PADR_(int)];
- char status_l_[PADL_(int *)]; int * status; char status_r_[PADR_(int *)];
- char options_l_[PADL_(int)]; int options; char options_r_[PADR_(int)];
- char rusage_l_[PADL_(struct rusage32 *)]; struct rusage32 * rusage; char rusage_r_[PADR_(struct rusage32 *)];
-};
-struct ia32_getfsstat_args {
- char buf_l_[PADL_(struct statfs32 *)]; struct statfs32 * buf; char buf_r_[PADR_(struct statfs32 *)];
- char bufsize_l_[PADL_(long)]; long bufsize; char bufsize_r_[PADR_(long)];
- char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
-};
-struct ia32_access_args {
- char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
- char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
-};
-struct ia32_chflags_args {
- char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
- char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
-};
-struct ia32_sigaltstack_args {
- char ss_l_[PADL_(struct sigaltstack32 *)]; struct sigaltstack32 * ss; char ss_r_[PADR_(struct sigaltstack32 *)];
- char oss_l_[PADL_(struct sigaltstack32 *)]; struct sigaltstack32 * oss; char oss_r_[PADR_(struct sigaltstack32 *)];
-};
-struct ia32_execve_args {
- char fname_l_[PADL_(char *)]; char * fname; char fname_r_[PADR_(char *)];
- char argv_l_[PADL_(u_int32_t *)]; u_int32_t * argv; char argv_r_[PADR_(u_int32_t *)];
- char envv_l_[PADL_(u_int32_t *)]; u_int32_t * envv; char envv_r_[PADR_(u_int32_t *)];
-};
-struct ia32_setitimer_args {
- char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)];
- char itv_l_[PADL_(struct itimerval32 *)]; struct itimerval32 * itv; char itv_r_[PADR_(struct itimerval32 *)];
- char oitv_l_[PADL_(struct itimerval32 *)]; struct itimerval32 * oitv; char oitv_r_[PADR_(struct itimerval32 *)];
-};
-struct ia32_select_args {
- char nd_l_[PADL_(int)]; int nd; char nd_r_[PADR_(int)];
- char in_l_[PADL_(fd_set *)]; fd_set * in; char in_r_[PADR_(fd_set *)];
- char ou_l_[PADL_(fd_set *)]; fd_set * ou; char ou_r_[PADR_(fd_set *)];
- char ex_l_[PADL_(fd_set *)]; fd_set * ex; char ex_r_[PADR_(fd_set *)];
- char tv_l_[PADL_(struct timeval32 *)]; struct timeval32 * tv; char tv_r_[PADR_(struct timeval32 *)];
-};
-struct ia32_gettimeofday_args {
- char tp_l_[PADL_(struct timeval32 *)]; struct timeval32 * tp; char tp_r_[PADR_(struct timeval32 *)];
- char tzp_l_[PADL_(struct timezone *)]; struct timezone * tzp; char tzp_r_[PADR_(struct timezone *)];
-};
-struct ia32_getrusage_args {
- char who_l_[PADL_(int)]; int who; char who_r_[PADR_(int)];
- char rusage_l_[PADL_(struct rusage32 *)]; struct rusage32 * rusage; char rusage_r_[PADR_(struct rusage32 *)];
-};
-struct ia32_readv_args {
- char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char iovp_l_[PADL_(struct iovec32 *)]; struct iovec32 * iovp; char iovp_r_[PADR_(struct iovec32 *)];
- char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)];
-};
-struct ia32_writev_args {
- char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char iovp_l_[PADL_(struct iovec32 *)]; struct iovec32 * iovp; char iovp_r_[PADR_(struct iovec32 *)];
- char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)];
-};
-struct ia32_settimeofday_args {
- char tv_l_[PADL_(struct timeval32 *)]; struct timeval32 * tv; char tv_r_[PADR_(struct timeval32 *)];
- char tzp_l_[PADL_(struct timezone *)]; struct timezone * tzp; char tzp_r_[PADR_(struct timezone *)];
-};
-struct ia32_utimes_args {
- char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
- char tptr_l_[PADL_(struct timeval32 *)]; struct timeval32 * tptr; char tptr_r_[PADR_(struct timeval32 *)];
-};
-struct ia32_adjtime_args {
- char delta_l_[PADL_(struct timeval32 *)]; struct timeval32 * delta; char delta_r_[PADR_(struct timeval32 *)];
- char olddelta_l_[PADL_(struct timeval32 *)]; struct timeval32 * olddelta; char olddelta_r_[PADR_(struct timeval32 *)];
-};
-struct ia32_statfs_args {
- char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
- char buf_l_[PADL_(struct statfs32 *)]; struct statfs32 * buf; char buf_r_[PADR_(struct statfs32 *)];
-};
-struct ia32_fstatfs_args {
- char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char buf_l_[PADL_(struct statfs32 *)]; struct statfs32 * buf; char buf_r_[PADR_(struct statfs32 *)];
-};
-struct ia32_semsys_args {
- char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)];
- char a2_l_[PADL_(int)]; int a2; char a2_r_[PADR_(int)];
- char a3_l_[PADL_(int)]; int a3; char a3_r_[PADR_(int)];
- char a4_l_[PADL_(int)]; int a4; char a4_r_[PADR_(int)];
- char a5_l_[PADL_(int)]; int a5; char a5_r_[PADR_(int)];
-};
-struct ia32_msgsys_args {
- char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)];
- char a2_l_[PADL_(int)]; int a2; char a2_r_[PADR_(int)];
- char a3_l_[PADL_(int)]; int a3; char a3_r_[PADR_(int)];
- char a4_l_[PADL_(int)]; int a4; char a4_r_[PADR_(int)];
- char a5_l_[PADL_(int)]; int a5; char a5_r_[PADR_(int)];
- char a6_l_[PADL_(int)]; int a6; char a6_r_[PADR_(int)];
-};
-struct ia32_shmsys_args {
- char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)];
- char a2_l_[PADL_(int)]; int a2; char a2_r_[PADR_(int)];
- char a3_l_[PADL_(int)]; int a3; char a3_r_[PADR_(int)];
- char a4_l_[PADL_(int)]; int a4; char a4_r_[PADR_(int)];
-};
-struct ia32_pread_args {
- char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char buf_l_[PADL_(void *)]; void * buf; char buf_r_[PADR_(void *)];
- char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)];
- char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)];
- char offsetlo_l_[PADL_(u_int32_t)]; u_int32_t offsetlo; char offsetlo_r_[PADR_(u_int32_t)];
- char offsethi_l_[PADL_(u_int32_t)]; u_int32_t offsethi; char offsethi_r_[PADR_(u_int32_t)];
-};
-struct ia32_pwrite_args {
- char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char buf_l_[PADL_(const void *)]; const void * buf; char buf_r_[PADR_(const void *)];
- char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)];
- char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)];
- char offsetlo_l_[PADL_(u_int32_t)]; u_int32_t offsetlo; char offsetlo_r_[PADR_(u_int32_t)];
- char offsethi_l_[PADL_(u_int32_t)]; u_int32_t offsethi; char offsethi_r_[PADR_(u_int32_t)];
-};
-struct ia32_stat_args {
- char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
- char ub_l_[PADL_(struct stat32 *)]; struct stat32 * ub; char ub_r_[PADR_(struct stat32 *)];
-};
-struct ia32_fstat_args {
- char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char ub_l_[PADL_(struct stat32 *)]; struct stat32 * ub; char ub_r_[PADR_(struct stat32 *)];
-};
-struct ia32_lstat_args {
- char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
- char ub_l_[PADL_(struct stat32 *)]; struct stat32 * ub; char ub_r_[PADR_(struct stat32 *)];
-};
-struct ia32_mmap_args {
- char addr_l_[PADL_(caddr_t)]; caddr_t addr; char addr_r_[PADR_(caddr_t)];
- char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)];
- char prot_l_[PADL_(int)]; int prot; char prot_r_[PADR_(int)];
- char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
- char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)];
- char poslo_l_[PADL_(u_int32_t)]; u_int32_t poslo; char poslo_r_[PADR_(u_int32_t)];
- char poshi_l_[PADL_(u_int32_t)]; u_int32_t poshi; char poshi_r_[PADR_(u_int32_t)];
-};
-struct ia32_lseek_args {
- char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)];
- char offsetlo_l_[PADL_(u_int32_t)]; u_int32_t offsetlo; char offsetlo_r_[PADR_(u_int32_t)];
- char offsethi_l_[PADL_(u_int32_t)]; u_int32_t offsethi; char offsethi_r_[PADR_(u_int32_t)];
- char whence_l_[PADL_(int)]; int whence; char whence_r_[PADR_(int)];
-};
-struct ia32_truncate_args {
- char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
- char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)];
- char lengthlo_l_[PADL_(u_int32_t)]; u_int32_t lengthlo; char lengthlo_r_[PADR_(u_int32_t)];
- char lengthhi_l_[PADL_(u_int32_t)]; u_int32_t lengthhi; char lengthhi_r_[PADR_(u_int32_t)];
-};
-struct ia32_ftruncate_args {
- char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)];
- char lengthlo_l_[PADL_(u_int32_t)]; u_int32_t lengthlo; char lengthlo_r_[PADR_(u_int32_t)];
- char lengthhi_l_[PADL_(u_int32_t)]; u_int32_t lengthhi; char lengthhi_r_[PADR_(u_int32_t)];
-};
-struct ia32_sysctl_args {
- char name_l_[PADL_(int *)]; int * name; char name_r_[PADR_(int *)];
- char namelen_l_[PADL_(u_int)]; u_int namelen; char namelen_r_[PADR_(u_int)];
- char old_l_[PADL_(void *)]; void * old; char old_r_[PADR_(void *)];
- char oldlenp_l_[PADL_(u_int32_t *)]; u_int32_t * oldlenp; char oldlenp_r_[PADR_(u_int32_t *)];
- char new_l_[PADL_(void *)]; void * new; char new_r_[PADR_(void *)];
- char newlen_l_[PADL_(u_int32_t)]; u_int32_t newlen; char newlen_r_[PADR_(u_int32_t)];
-};
-struct ia32_kevent_args {
- char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char changelist_l_[PADL_(const struct kevent *)]; const struct kevent * changelist; char changelist_r_[PADR_(const struct kevent *)];
- char nchanges_l_[PADL_(int)]; int nchanges; char nchanges_r_[PADR_(int)];
- char eventlist_l_[PADL_(struct kevent *)]; struct kevent * eventlist; char eventlist_r_[PADR_(struct kevent *)];
- char nevents_l_[PADL_(int)]; int nevents; char nevents_r_[PADR_(int)];
- char timeout_l_[PADL_(const struct timespec *)]; const struct timespec * timeout; char timeout_r_[PADR_(const struct timespec *)];
-};
-struct ia32_sendfile_args {
- char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
- char offsetlo_l_[PADL_(u_int32_t)]; u_int32_t offsetlo; char offsetlo_r_[PADR_(u_int32_t)];
- char offsethi_l_[PADL_(u_int32_t)]; u_int32_t offsethi; char offsethi_r_[PADR_(u_int32_t)];
- char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)];
- char hdtr_l_[PADL_(struct sf_hdtr *)]; struct sf_hdtr * hdtr; char hdtr_r_[PADR_(struct sf_hdtr *)];
- char sbytes_l_[PADL_(off_t *)]; off_t * sbytes; char sbytes_r_[PADR_(off_t *)];
- char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
-};
-struct ia32_sigreturn_args {
- char sigcntxp_l_[PADL_(const struct ia32_ucontext *)]; const struct ia32_ucontext * sigcntxp; char sigcntxp_r_[PADR_(const struct ia32_ucontext *)];
-};
-struct ia32_sigaction_args {
- char sig_l_[PADL_(int)]; int sig; char sig_r_[PADR_(int)];
- char act_l_[PADL_(struct sigaction32 *)]; struct sigaction32 * act; char act_r_[PADR_(struct sigaction32 *)];
- char oact_l_[PADL_(struct sigaction32 *)]; struct sigaction32 * oact; char oact_r_[PADR_(struct sigaction32 *)];
-};
-int ia32_open(struct thread *, struct ia32_open_args *);
-int ia32_wait4(struct thread *, struct ia32_wait4_args *);
-int ia32_getfsstat(struct thread *, struct ia32_getfsstat_args *);
-int ia32_access(struct thread *, struct ia32_access_args *);
-int ia32_chflags(struct thread *, struct ia32_chflags_args *);
-int ia32_sigaltstack(struct thread *, struct ia32_sigaltstack_args *);
-int ia32_execve(struct thread *, struct ia32_execve_args *);
-int ia32_setitimer(struct thread *, struct ia32_setitimer_args *);
-int ia32_select(struct thread *, struct ia32_select_args *);
-int ia32_gettimeofday(struct thread *, struct ia32_gettimeofday_args *);
-int ia32_getrusage(struct thread *, struct ia32_getrusage_args *);
-int ia32_readv(struct thread *, struct ia32_readv_args *);
-int ia32_writev(struct thread *, struct ia32_writev_args *);
-int ia32_settimeofday(struct thread *, struct ia32_settimeofday_args *);
-int ia32_utimes(struct thread *, struct ia32_utimes_args *);
-int ia32_adjtime(struct thread *, struct ia32_adjtime_args *);
-int ia32_statfs(struct thread *, struct ia32_statfs_args *);
-int ia32_fstatfs(struct thread *, struct ia32_fstatfs_args *);
-int ia32_semsys(struct thread *, struct ia32_semsys_args *);
-int ia32_msgsys(struct thread *, struct ia32_msgsys_args *);
-int ia32_shmsys(struct thread *, struct ia32_shmsys_args *);
-int ia32_pread(struct thread *, struct ia32_pread_args *);
-int ia32_pwrite(struct thread *, struct ia32_pwrite_args *);
-int ia32_stat(struct thread *, struct ia32_stat_args *);
-int ia32_fstat(struct thread *, struct ia32_fstat_args *);
-int ia32_lstat(struct thread *, struct ia32_lstat_args *);
-int ia32_mmap(struct thread *, struct ia32_mmap_args *);
-int ia32_lseek(struct thread *, struct ia32_lseek_args *);
-int ia32_truncate(struct thread *, struct ia32_truncate_args *);
-int ia32_ftruncate(struct thread *, struct ia32_ftruncate_args *);
-int ia32_sysctl(struct thread *, struct ia32_sysctl_args *);
-int ia32_kevent(struct thread *, struct ia32_kevent_args *);
-int ia32_sendfile(struct thread *, struct ia32_sendfile_args *);
-int ia32_sigreturn(struct thread *, struct ia32_sigreturn_args *);
-int ia32_sigaction(struct thread *, struct ia32_sigaction_args *);
-
-#ifdef COMPAT_43
-
-
-#endif /* COMPAT_43 */
-
-
-#ifdef COMPAT_FREEBSD4
-
-struct freebsd4_ia32_sendfile_args {
- char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
- char offsetlo_l_[PADL_(u_int32_t)]; u_int32_t offsetlo; char offsetlo_r_[PADR_(u_int32_t)];
- char offsethi_l_[PADL_(u_int32_t)]; u_int32_t offsethi; char offsethi_r_[PADR_(u_int32_t)];
- char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)];
- char hdtr_l_[PADL_(struct sf_hdtr *)]; struct sf_hdtr * hdtr; char hdtr_r_[PADR_(struct sf_hdtr *)];
- char sbytes_l_[PADL_(off_t *)]; off_t * sbytes; char sbytes_r_[PADR_(off_t *)];
- char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
-};
-struct freebsd4_ia32_sigaction_args {
- char sig_l_[PADL_(int)]; int sig; char sig_r_[PADR_(int)];
- char act_l_[PADL_(struct sigaction32 *)]; struct sigaction32 * act; char act_r_[PADR_(struct sigaction32 *)];
- char oact_l_[PADL_(struct sigaction32 *)]; struct sigaction32 * oact; char oact_r_[PADR_(struct sigaction32 *)];
-};
-struct freebsd4_ia32_sigreturn_args {
- char sigcntxp_l_[PADL_(const struct __ucontext *)]; const struct __ucontext * sigcntxp; char sigcntxp_r_[PADR_(const struct __ucontext *)];
-};
-int freebsd4_ia32_sendfile(struct thread *, struct freebsd4_ia32_sendfile_args *);
-int freebsd4_ia32_sigaction(struct thread *, struct freebsd4_ia32_sigaction_args *);
-int freebsd4_ia32_sigreturn(struct thread *, struct freebsd4_ia32_sigreturn_args *);
-
-#endif /* COMPAT_FREEBSD4 */
-
-#undef PAD_
-#undef PADL_
-#undef PADR_
-
-#endif /* !_IA32_SYSPROTO_H_ */
diff --git a/sys/compat/freebsd32/freebsd32_syscall.h b/sys/compat/freebsd32/freebsd32_syscall.h
deleted file mode 100644
index 6699f41c35f2..000000000000
--- a/sys/compat/freebsd32/freebsd32_syscall.h
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * System call numbers.
- *
- * DO NOT EDIT-- this file is automatically generated.
- * $FreeBSD$
- * created from FreeBSD: src/sys/amd64/ia32/syscalls.master,v 1.22 2003/05/14 04:10:49 peter Exp
- */
-
-#define IA32_SYS_syscall 0
-#define IA32_SYS_exit 1
-#define IA32_SYS_fork 2
-#define IA32_SYS_read 3
-#define IA32_SYS_write 4
-#define IA32_SYS_ia32_open 5
-#define IA32_SYS_close 6
-#define IA32_SYS_ia32_wait4 7
- /* 8 is obsolete old creat */
-#define IA32_SYS_link 9
-#define IA32_SYS_unlink 10
- /* 11 is obsolete execv */
-#define IA32_SYS_chdir 12
-#define IA32_SYS_fchdir 13
-#define IA32_SYS_mknod 14
-#define IA32_SYS_chmod 15
-#define IA32_SYS_chown 16
-#define IA32_SYS_break 17
-#define IA32_SYS_ia32_getfsstat 18
- /* 19 is obsolete olseek */
-#define IA32_SYS_getpid 20
-#define IA32_SYS_mount 21
-#define IA32_SYS_unmount 22
-#define IA32_SYS_setuid 23
-#define IA32_SYS_getuid 24
-#define IA32_SYS_geteuid 25
-#define IA32_SYS_ptrace 26
-#define IA32_SYS_sendmsg 28
-#define IA32_SYS_recvfrom 29
-#define IA32_SYS_accept 30
-#define IA32_SYS_getpeername 31
-#define IA32_SYS_getsockname 32
-#define IA32_SYS_ia32_access 33
-#define IA32_SYS_ia32_chflags 34
-#define IA32_SYS_fchflags 35
-#define IA32_SYS_sync 36
-#define IA32_SYS_kill 37
-#define IA32_SYS_getppid 39
-#define IA32_SYS_dup 41
-#define IA32_SYS_pipe 42
-#define IA32_SYS_getegid 43
-#define IA32_SYS_profil 44
-#define IA32_SYS_ktrace 45
-#define IA32_SYS_getgid 47
-#define IA32_SYS_getlogin 49
-#define IA32_SYS_setlogin 50
-#define IA32_SYS_acct 51
-#define IA32_SYS_sigpending 52
-#define IA32_SYS_ia32_sigaltstack 53
-#define IA32_SYS_ioctl 54
-#define IA32_SYS_reboot 55
-#define IA32_SYS_revoke 56
-#define IA32_SYS_symlink 57
-#define IA32_SYS_readlink 58
-#define IA32_SYS_ia32_execve 59
-#define IA32_SYS_umask 60
-#define IA32_SYS_chroot 61
- /* 62 is obsolete ofstat */
- /* 63 is obsolete ogetkerninfo */
- /* 64 is obsolete ogetpagesize */
- /* 65 is obsolete omsync */
- /* 66 is obsolete ovfork */
- /* 67 is obsolete vread */
- /* 68 is obsolete vwrite */
-#define IA32_SYS_sbrk 69
-#define IA32_SYS_sstk 70
- /* 71 is obsolete ommap */
-#define IA32_SYS_vadvise 72
-#define IA32_SYS_munmap 73
-#define IA32_SYS_mprotect 74
-#define IA32_SYS_madvise 75
- /* 76 is obsolete vhangup */
- /* 77 is obsolete vlimit */
-#define IA32_SYS_mincore 78
-#define IA32_SYS_getgroups 79
-#define IA32_SYS_setgroups 80
-#define IA32_SYS_getpgrp 81
-#define IA32_SYS_setpgid 82
-#define IA32_SYS_ia32_setitimer 83
- /* 84 is obsolete owait */
- /* 85 is obsolete oswapon */
- /* 86 is obsolete ogetitimer */
- /* 87 is obsolete ogethostname */
- /* 88 is obsolete osethostname */
-#define IA32_SYS_getdtablesize 89
-#define IA32_SYS_dup2 90
-#define IA32_SYS_fcntl 92
-#define IA32_SYS_ia32_select 93
-#define IA32_SYS_fsync 95
-#define IA32_SYS_setpriority 96
-#define IA32_SYS_socket 97
-#define IA32_SYS_connect 98
-#define IA32_SYS_accept 99
-#define IA32_SYS_getpriority 100
- /* 101 is obsolete osend */
- /* 102 is obsolete orecv */
- /* 103 is obsolete osigreturn */
-#define IA32_SYS_bind 104
-#define IA32_SYS_setsockopt 105
-#define IA32_SYS_listen 106
- /* 107 is obsolete vtimes */
- /* 108 is obsolete osigvec */
- /* 109 is obsolete osigblock */
- /* 110 is obsolete osigsetmask */
- /* 111 is obsolete osigsuspend */
- /* 112 is obsolete osigstack */
- /* 113 is obsolete orecvmsg */
- /* 114 is obsolete osendmsg */
- /* 115 is obsolete vtrace */
-#define IA32_SYS_ia32_gettimeofday 116
-#define IA32_SYS_ia32_getrusage 117
-#define IA32_SYS_getsockopt 118
-#define IA32_SYS_ia32_readv 120
-#define IA32_SYS_ia32_writev 121
-#define IA32_SYS_ia32_settimeofday 122
-#define IA32_SYS_fchown 123
-#define IA32_SYS_fchmod 124
-#define IA32_SYS_recvfrom 125
-#define IA32_SYS_setreuid 126
-#define IA32_SYS_setregid 127
-#define IA32_SYS_rename 128
- /* 129 is obsolete otruncate */
- /* 130 is obsolete ftruncate */
-#define IA32_SYS_flock 131
-#define IA32_SYS_mkfifo 132
-#define IA32_SYS_sendto 133
-#define IA32_SYS_shutdown 134
-#define IA32_SYS_socketpair 135
-#define IA32_SYS_mkdir 136
-#define IA32_SYS_rmdir 137
-#define IA32_SYS_ia32_utimes 138
- /* 139 is obsolete 4.2 sigreturn */
-#define IA32_SYS_ia32_adjtime 140
- /* 141 is obsolete ogetpeername */
- /* 142 is obsolete ogethostid */
- /* 143 is obsolete sethostid */
- /* 144 is obsolete getrlimit */
- /* 145 is obsolete setrlimit */
- /* 146 is obsolete killpg */
-#define IA32_SYS_setsid 147
-#define IA32_SYS_quotactl 148
- /* 149 is obsolete oquota */
- /* 150 is obsolete ogetsockname */
-#define IA32_SYS_getdirentries 156
-#define IA32_SYS_ia32_statfs 157
-#define IA32_SYS_ia32_fstatfs 158
-#define IA32_SYS_getfh 161
-#define IA32_SYS_getdomainname 162
-#define IA32_SYS_setdomainname 163
-#define IA32_SYS_uname 164
-#define IA32_SYS_sysarch 165
-#define IA32_SYS_rtprio 166
-#define IA32_SYS_ia32_semsys 169
-#define IA32_SYS_ia32_msgsys 170
-#define IA32_SYS_ia32_shmsys 171
-#define IA32_SYS_ia32_pread 173
-#define IA32_SYS_ia32_pwrite 174
-#define IA32_SYS_ntp_adjtime 176
-#define IA32_SYS_setgid 181
-#define IA32_SYS_setegid 182
-#define IA32_SYS_seteuid 183
-#define IA32_SYS_ia32_stat 188
-#define IA32_SYS_ia32_fstat 189
-#define IA32_SYS_ia32_lstat 190
-#define IA32_SYS_pathconf 191
-#define IA32_SYS_fpathconf 192
-#define IA32_SYS_getrlimit 194
-#define IA32_SYS_setrlimit 195
-#define IA32_SYS_getdirentries 196
-#define IA32_SYS_ia32_mmap 197
-#define IA32_SYS___syscall 198
-#define IA32_SYS_ia32_lseek 199
-#define IA32_SYS_ia32_truncate 200
-#define IA32_SYS_ia32_ftruncate 201
-#define IA32_SYS_ia32_sysctl 202
-#define IA32_SYS_mlock 203
-#define IA32_SYS_munlock 204
-#define IA32_SYS_undelete 205
-#define IA32_SYS_futimes 206
-#define IA32_SYS_getpgid 207
-#define IA32_SYS_poll 209
-#define IA32_SYS___semctl 220
-#define IA32_SYS_semget 221
-#define IA32_SYS_semop 222
-#define IA32_SYS_msgctl 224
-#define IA32_SYS_msgget 225
-#define IA32_SYS_msgsnd 226
-#define IA32_SYS_msgrcv 227
-#define IA32_SYS_shmat 228
-#define IA32_SYS_shmctl 229
-#define IA32_SYS_shmdt 230
-#define IA32_SYS_shmget 231
-#define IA32_SYS_clock_gettime 232
-#define IA32_SYS_clock_settime 233
-#define IA32_SYS_clock_getres 234
-#define IA32_SYS_nanosleep 240
-#define IA32_SYS_minherit 250
-#define IA32_SYS_rfork 251
-#define IA32_SYS_openbsd_poll 252
-#define IA32_SYS_issetugid 253
-#define IA32_SYS_lchown 254
-#define IA32_SYS_getdents 272
-#define IA32_SYS_lchmod 274
-#define IA32_SYS_netbsd_lchown 275
-#define IA32_SYS_lutimes 276
-#define IA32_SYS_netbsd_msync 277
-#define IA32_SYS_nstat 278
-#define IA32_SYS_nfstat 279
-#define IA32_SYS_nlstat 280
-#define IA32_SYS_fhstatfs 297
-#define IA32_SYS_fhopen 298
-#define IA32_SYS_fhstat 299
-#define IA32_SYS_modnext 300
-#define IA32_SYS_modstat 301
-#define IA32_SYS_modfnext 302
-#define IA32_SYS_modfind 303
-#define IA32_SYS_kldload 304
-#define IA32_SYS_kldunload 305
-#define IA32_SYS_kldfind 306
-#define IA32_SYS_kldnext 307
-#define IA32_SYS_kldstat 308
-#define IA32_SYS_kldfirstmod 309
-#define IA32_SYS_getsid 310
-#define IA32_SYS_setresuid 311
-#define IA32_SYS_setresgid 312
- /* 313 is obsolete signanosleep */
-#define IA32_SYS_yield 321
- /* 322 is obsolete thr_sleep */
- /* 323 is obsolete thr_wakeup */
-#define IA32_SYS_mlockall 324
-#define IA32_SYS_munlockall 325
-#define IA32_SYS___getcwd 326
-#define IA32_SYS_sched_setparam 327
-#define IA32_SYS_sched_getparam 328
-#define IA32_SYS_sched_setscheduler 329
-#define IA32_SYS_sched_getscheduler 330
-#define IA32_SYS_sched_yield 331
-#define IA32_SYS_sched_get_priority_max 332
-#define IA32_SYS_sched_get_priority_min 333
-#define IA32_SYS_sched_rr_get_interval 334
-#define IA32_SYS_utrace 335
- /* 336 is old ia32_sendfile */
-#define IA32_SYS_kldsym 337
-#define IA32_SYS_jail 338
-#define IA32_SYS_sigprocmask 340
-#define IA32_SYS_sigsuspend 341
- /* 342 is old ia32_sigaction */
-#define IA32_SYS_sigpending 343
- /* 344 is old ia32_sigreturn */
-#define IA32_SYS___acl_get_file 347
-#define IA32_SYS___acl_set_file 348
-#define IA32_SYS___acl_get_fd 349
-#define IA32_SYS___acl_set_fd 350
-#define IA32_SYS___acl_delete_file 351
-#define IA32_SYS___acl_delete_fd 352
-#define IA32_SYS___acl_aclcheck_file 353
-#define IA32_SYS___acl_aclcheck_fd 354
-#define IA32_SYS_extattrctl 355
-#define IA32_SYS_extattr_set_file 356
-#define IA32_SYS_extattr_get_file 357
-#define IA32_SYS_extattr_delete_file 358
-#define IA32_SYS_getresuid 360
-#define IA32_SYS_getresgid 361
-#define IA32_SYS_kqueue 362
-#define IA32_SYS_ia32_kevent 363
-#define IA32_SYS_extattr_set_fd 371
-#define IA32_SYS_extattr_get_fd 372
-#define IA32_SYS_extattr_delete_fd 373
-#define IA32_SYS___setugid 374
-#define IA32_SYS_eaccess 376
-#define IA32_SYS_nmount 378
-#define IA32_SYS_kse_exit 379
-#define IA32_SYS_kse_wakeup 380
-#define IA32_SYS_kse_create 381
-#define IA32_SYS_kse_thr_interrupt 382
-#define IA32_SYS_kse_release 383
-#define IA32_SYS_kenv 390
-#define IA32_SYS_lchflags 391
-#define IA32_SYS_uuidgen 392
-#define IA32_SYS_ia32_sendfile 393
-#define IA32_SYS_ia32_sigreturn 416
-#define IA32_SYS_ia32_sigaction 417
-#define IA32_SYS_thr_create 430
-#define IA32_SYS_thr_exit 431
-#define IA32_SYS_thr_self 432
-#define IA32_SYS_thr_kill 433
-#define IA32_SYS__umtx_lock 434
-#define IA32_SYS__umtx_unlock 435
-#define IA32_SYS_jail_attach 436
-#define IA32_SYS_MAXSYSCALL 437
diff --git a/sys/compat/freebsd32/freebsd32_syscalls.c b/sys/compat/freebsd32/freebsd32_syscalls.c
deleted file mode 100644
index ffb5414ef979..000000000000
--- a/sys/compat/freebsd32/freebsd32_syscalls.c
+++ /dev/null
@@ -1,447 +0,0 @@
-/*
- * System call names.
- *
- * DO NOT EDIT-- this file is automatically generated.
- * $FreeBSD$
- * created from FreeBSD: src/sys/amd64/ia32/syscalls.master,v 1.22 2003/05/14 04:10:49 peter Exp
- */
-
-const char *ia32_syscallnames[] = {
- "syscall", /* 0 = syscall */
- "exit", /* 1 = exit */
- "fork", /* 2 = fork */
- "read", /* 3 = read */
- "write", /* 4 = write */
- "ia32_open", /* 5 = ia32_open */
- "close", /* 6 = close */
- "ia32_wait4", /* 7 = ia32_wait4 */
- "obs_old", /* 8 = obsolete old creat */
- "link", /* 9 = link */
- "unlink", /* 10 = unlink */
- "obs_execv", /* 11 = obsolete execv */
- "chdir", /* 12 = chdir */
- "fchdir", /* 13 = fchdir */
- "mknod", /* 14 = mknod */
- "chmod", /* 15 = chmod */
- "chown", /* 16 = chown */
- "break", /* 17 = break */
- "ia32_getfsstat", /* 18 = ia32_getfsstat */
- "obs_olseek", /* 19 = obsolete olseek */
- "getpid", /* 20 = getpid */
- "mount", /* 21 = mount */
- "unmount", /* 22 = unmount */
- "setuid", /* 23 = setuid */
- "getuid", /* 24 = getuid */
- "geteuid", /* 25 = geteuid */
- "ptrace", /* 26 = ptrace */
- "#27", /* 27 = recvmsg */
- "sendmsg", /* 28 = sendmsg */
- "recvfrom", /* 29 = recvfrom */
- "accept", /* 30 = accept */
- "getpeername", /* 31 = getpeername */
- "getsockname", /* 32 = getsockname */
- "ia32_access", /* 33 = ia32_access */
- "ia32_chflags", /* 34 = ia32_chflags */
- "fchflags", /* 35 = fchflags */
- "sync", /* 36 = sync */
- "kill", /* 37 = kill */
- "#38", /* 38 = ostat */
- "getppid", /* 39 = getppid */
- "#40", /* 40 = olstat */
- "dup", /* 41 = dup */
- "pipe", /* 42 = pipe */
- "getegid", /* 43 = getegid */
- "profil", /* 44 = profil */
- "ktrace", /* 45 = ktrace */
- "#46", /* 46 = osigaction */
- "getgid", /* 47 = getgid */
- "#48", /* 48 = osigprocmask */
- "getlogin", /* 49 = getlogin */
- "setlogin", /* 50 = setlogin */
- "acct", /* 51 = acct */
- "sigpending", /* 52 = sigpending */
- "ia32_sigaltstack", /* 53 = ia32_sigaltstack */
- "ioctl", /* 54 = ioctl */
- "reboot", /* 55 = reboot */
- "revoke", /* 56 = revoke */
- "symlink", /* 57 = symlink */
- "readlink", /* 58 = readlink */
- "ia32_execve", /* 59 = ia32_execve */
- "umask", /* 60 = umask */
- "chroot", /* 61 = chroot */
- "obs_ofstat", /* 62 = obsolete ofstat */
- "obs_ogetkerninfo", /* 63 = obsolete ogetkerninfo */
- "obs_ogetpagesize", /* 64 = obsolete ogetpagesize */
- "obs_omsync", /* 65 = obsolete omsync */
- "obs_ovfork", /* 66 = obsolete ovfork */
- "obs_vread", /* 67 = obsolete vread */
- "obs_vwrite", /* 68 = obsolete vwrite */
- "sbrk", /* 69 = sbrk */
- "sstk", /* 70 = sstk */
- "obs_ommap", /* 71 = obsolete ommap */
- "vadvise", /* 72 = vadvise */
- "munmap", /* 73 = munmap */
- "mprotect", /* 74 = mprotect */
- "madvise", /* 75 = madvise */
- "obs_vhangup", /* 76 = obsolete vhangup */
- "obs_vlimit", /* 77 = obsolete vlimit */
- "mincore", /* 78 = mincore */
- "getgroups", /* 79 = getgroups */
- "setgroups", /* 80 = setgroups */
- "getpgrp", /* 81 = getpgrp */
- "setpgid", /* 82 = setpgid */
- "ia32_setitimer", /* 83 = ia32_setitimer */
- "obs_owait", /* 84 = obsolete owait */
- "obs_oswapon", /* 85 = obsolete oswapon */
- "obs_ogetitimer", /* 86 = obsolete ogetitimer */
- "obs_ogethostname", /* 87 = obsolete ogethostname */
- "obs_osethostname", /* 88 = obsolete osethostname */
- "getdtablesize", /* 89 = getdtablesize */
- "dup2", /* 90 = dup2 */
- "#91", /* 91 = getdopt */
- "fcntl", /* 92 = fcntl */
- "ia32_select", /* 93 = ia32_select */
- "#94", /* 94 = setdopt */
- "fsync", /* 95 = fsync */
- "setpriority", /* 96 = setpriority */
- "socket", /* 97 = socket */
- "connect", /* 98 = connect */
- "accept", /* 99 = accept */
- "getpriority", /* 100 = getpriority */
- "obs_osend", /* 101 = obsolete osend */
- "obs_orecv", /* 102 = obsolete orecv */
- "obs_osigreturn", /* 103 = obsolete osigreturn */
- "bind", /* 104 = bind */
- "setsockopt", /* 105 = setsockopt */
- "listen", /* 106 = listen */
- "obs_vtimes", /* 107 = obsolete vtimes */
- "obs_osigvec", /* 108 = obsolete osigvec */
- "obs_osigblock", /* 109 = obsolete osigblock */
- "obs_osigsetmask", /* 110 = obsolete osigsetmask */
- "obs_osigsuspend", /* 111 = obsolete osigsuspend */
- "obs_osigstack", /* 112 = obsolete osigstack */
- "obs_orecvmsg", /* 113 = obsolete orecvmsg */
- "obs_osendmsg", /* 114 = obsolete osendmsg */
- "obs_vtrace", /* 115 = obsolete vtrace */
- "ia32_gettimeofday", /* 116 = ia32_gettimeofday */
- "ia32_getrusage", /* 117 = ia32_getrusage */
- "getsockopt", /* 118 = getsockopt */
- "#119", /* 119 = resuba */
- "ia32_readv", /* 120 = ia32_readv */
- "ia32_writev", /* 121 = ia32_writev */
- "ia32_settimeofday", /* 122 = ia32_settimeofday */
- "fchown", /* 123 = fchown */
- "fchmod", /* 124 = fchmod */
- "recvfrom", /* 125 = recvfrom */
- "setreuid", /* 126 = setreuid */
- "setregid", /* 127 = setregid */
- "rename", /* 128 = rename */
- "obs_otruncate", /* 129 = obsolete otruncate */
- "obs_ftruncate", /* 130 = obsolete ftruncate */
- "flock", /* 131 = flock */
- "mkfifo", /* 132 = mkfifo */
- "sendto", /* 133 = sendto */
- "shutdown", /* 134 = shutdown */
- "socketpair", /* 135 = socketpair */
- "mkdir", /* 136 = mkdir */
- "rmdir", /* 137 = rmdir */
- "ia32_utimes", /* 138 = ia32_utimes */
- "obs_4.2", /* 139 = obsolete 4.2 sigreturn */
- "ia32_adjtime", /* 140 = ia32_adjtime */
- "obs_ogetpeername", /* 141 = obsolete ogetpeername */
- "obs_ogethostid", /* 142 = obsolete ogethostid */
- "obs_sethostid", /* 143 = obsolete sethostid */
- "obs_getrlimit", /* 144 = obsolete getrlimit */
- "obs_setrlimit", /* 145 = obsolete setrlimit */
- "obs_killpg", /* 146 = obsolete killpg */
- "setsid", /* 147 = setsid */
- "quotactl", /* 148 = quotactl */
- "obs_oquota", /* 149 = obsolete oquota */
- "obs_ogetsockname", /* 150 = obsolete ogetsockname */
- "#151", /* 151 = sem_lock */
- "#152", /* 152 = sem_wakeup */
- "#153", /* 153 = asyncdaemon */
- "#154", /* 154 = nosys */
- "#155", /* 155 = nfssvc */
- "getdirentries", /* 156 = getdirentries */
- "ia32_statfs", /* 157 = ia32_statfs */
- "ia32_fstatfs", /* 158 = ia32_fstatfs */
- "#159", /* 159 = nosys */
- "#160", /* 160 = nosys */
- "getfh", /* 161 = getfh */
- "getdomainname", /* 162 = getdomainname */
- "setdomainname", /* 163 = setdomainname */
- "uname", /* 164 = uname */
- "sysarch", /* 165 = sysarch */
- "rtprio", /* 166 = rtprio */
- "#167", /* 167 = nosys */
- "#168", /* 168 = nosys */
- "ia32_semsys", /* 169 = ia32_semsys */
- "ia32_msgsys", /* 170 = ia32_msgsys */
- "ia32_shmsys", /* 171 = ia32_shmsys */
- "#172", /* 172 = nosys */
- "ia32_pread", /* 173 = ia32_pread */
- "ia32_pwrite", /* 174 = ia32_pwrite */
- "#175", /* 175 = nosys */
- "ntp_adjtime", /* 176 = ntp_adjtime */
- "#177", /* 177 = sfork */
- "#178", /* 178 = getdescriptor */
- "#179", /* 179 = setdescriptor */
- "#180", /* 180 = nosys */
- "setgid", /* 181 = setgid */
- "setegid", /* 182 = setegid */
- "seteuid", /* 183 = seteuid */
- "#184", /* 184 = lfs_bmapv */
- "#185", /* 185 = lfs_markv */
- "#186", /* 186 = lfs_segclean */
- "#187", /* 187 = lfs_segwait */
- "ia32_stat", /* 188 = ia32_stat */
- "ia32_fstat", /* 189 = ia32_fstat */
- "ia32_lstat", /* 190 = ia32_lstat */
- "pathconf", /* 191 = pathconf */
- "fpathconf", /* 192 = fpathconf */
- "#193", /* 193 = nosys */
- "getrlimit", /* 194 = getrlimit */
- "setrlimit", /* 195 = setrlimit */
- "getdirentries", /* 196 = getdirentries */
- "ia32_mmap", /* 197 = ia32_mmap */
- "__syscall", /* 198 = __syscall */
- "ia32_lseek", /* 199 = ia32_lseek */
- "ia32_truncate", /* 200 = ia32_truncate */
- "ia32_ftruncate", /* 201 = ia32_ftruncate */
- "ia32_sysctl", /* 202 = ia32_sysctl */
- "mlock", /* 203 = mlock */
- "munlock", /* 204 = munlock */
- "undelete", /* 205 = undelete */
- "futimes", /* 206 = futimes */
- "getpgid", /* 207 = getpgid */
- "#208", /* 208 = newreboot */
- "poll", /* 209 = poll */
- "#210", /* 210 = */
- "#211", /* 211 = */
- "#212", /* 212 = */
- "#213", /* 213 = */
- "#214", /* 214 = */
- "#215", /* 215 = */
- "#216", /* 216 = */
- "#217", /* 217 = */
- "#218", /* 218 = */
- "#219", /* 219 = */
- "__semctl", /* 220 = __semctl */
- "semget", /* 221 = semget */
- "semop", /* 222 = semop */
- "#223", /* 223 = semconfig */
- "msgctl", /* 224 = msgctl */
- "msgget", /* 225 = msgget */
- "msgsnd", /* 226 = msgsnd */
- "msgrcv", /* 227 = msgrcv */
- "shmat", /* 228 = shmat */
- "shmctl", /* 229 = shmctl */
- "shmdt", /* 230 = shmdt */
- "shmget", /* 231 = shmget */
- "clock_gettime", /* 232 = clock_gettime */
- "clock_settime", /* 233 = clock_settime */
- "clock_getres", /* 234 = clock_getres */
- "#235", /* 235 = timer_create */
- "#236", /* 236 = timer_delete */
- "#237", /* 237 = timer_settime */
- "#238", /* 238 = timer_gettime */
- "#239", /* 239 = timer_getoverrun */
- "nanosleep", /* 240 = nanosleep */
- "#241", /* 241 = nosys */
- "#242", /* 242 = nosys */
- "#243", /* 243 = nosys */
- "#244", /* 244 = nosys */
- "#245", /* 245 = nosys */
- "#246", /* 246 = nosys */
- "#247", /* 247 = nosys */
- "#248", /* 248 = nosys */
- "#249", /* 249 = nosys */
- "minherit", /* 250 = minherit */
- "rfork", /* 251 = rfork */
- "openbsd_poll", /* 252 = openbsd_poll */
- "issetugid", /* 253 = issetugid */
- "lchown", /* 254 = lchown */
- "#255", /* 255 = nosys */
- "#256", /* 256 = nosys */
- "#257", /* 257 = nosys */
- "#258", /* 258 = nosys */
- "#259", /* 259 = nosys */
- "#260", /* 260 = nosys */
- "#261", /* 261 = nosys */
- "#262", /* 262 = nosys */
- "#263", /* 263 = nosys */
- "#264", /* 264 = nosys */
- "#265", /* 265 = nosys */
- "#266", /* 266 = nosys */
- "#267", /* 267 = nosys */
- "#268", /* 268 = nosys */
- "#269", /* 269 = nosys */
- "#270", /* 270 = nosys */
- "#271", /* 271 = nosys */
- "getdents", /* 272 = getdents */
- "#273", /* 273 = nosys */
- "lchmod", /* 274 = lchmod */
- "netbsd_lchown", /* 275 = netbsd_lchown */
- "lutimes", /* 276 = lutimes */
- "netbsd_msync", /* 277 = netbsd_msync */
- "nstat", /* 278 = nstat */
- "nfstat", /* 279 = nfstat */
- "nlstat", /* 280 = nlstat */
- "#281", /* 281 = nosys */
- "#282", /* 282 = nosys */
- "#283", /* 283 = nosys */
- "#284", /* 284 = nosys */
- "#285", /* 285 = nosys */
- "#286", /* 286 = nosys */
- "#287", /* 287 = nosys */
- "#288", /* 288 = nosys */
- "#289", /* 289 = nosys */
- "#290", /* 290 = nosys */
- "#291", /* 291 = nosys */
- "#292", /* 292 = nosys */
- "#293", /* 293 = nosys */
- "#294", /* 294 = nosys */
- "#295", /* 295 = nosys */
- "#296", /* 296 = nosys */
- "fhstatfs", /* 297 = fhstatfs */
- "fhopen", /* 298 = fhopen */
- "fhstat", /* 299 = fhstat */
- "modnext", /* 300 = modnext */
- "modstat", /* 301 = modstat */
- "modfnext", /* 302 = modfnext */
- "modfind", /* 303 = modfind */
- "kldload", /* 304 = kldload */
- "kldunload", /* 305 = kldunload */
- "kldfind", /* 306 = kldfind */
- "kldnext", /* 307 = kldnext */
- "kldstat", /* 308 = kldstat */
- "kldfirstmod", /* 309 = kldfirstmod */
- "getsid", /* 310 = getsid */
- "setresuid", /* 311 = setresuid */
- "setresgid", /* 312 = setresgid */
- "obs_signanosleep", /* 313 = obsolete signanosleep */
- "#314", /* 314 = aio_return */
- "#315", /* 315 = aio_suspend */
- "#316", /* 316 = aio_cancel */
- "#317", /* 317 = aio_error */
- "#318", /* 318 = aio_read */
- "#319", /* 319 = aio_write */
- "#320", /* 320 = lio_listio */
- "yield", /* 321 = yield */
- "obs_thr_sleep", /* 322 = obsolete thr_sleep */
- "obs_thr_wakeup", /* 323 = obsolete thr_wakeup */
- "mlockall", /* 324 = mlockall */
- "munlockall", /* 325 = munlockall */
- "__getcwd", /* 326 = __getcwd */
- "sched_setparam", /* 327 = sched_setparam */
- "sched_getparam", /* 328 = sched_getparam */
- "sched_setscheduler", /* 329 = sched_setscheduler */
- "sched_getscheduler", /* 330 = sched_getscheduler */
- "sched_yield", /* 331 = sched_yield */
- "sched_get_priority_max", /* 332 = sched_get_priority_max */
- "sched_get_priority_min", /* 333 = sched_get_priority_min */
- "sched_rr_get_interval", /* 334 = sched_rr_get_interval */
- "utrace", /* 335 = utrace */
- "old.ia32_sendfile", /* 336 = old ia32_sendfile */
- "kldsym", /* 337 = kldsym */
- "jail", /* 338 = jail */
- "#339", /* 339 = pioctl */
- "sigprocmask", /* 340 = sigprocmask */
- "sigsuspend", /* 341 = sigsuspend */
- "old.ia32_sigaction", /* 342 = old ia32_sigaction */
- "sigpending", /* 343 = sigpending */
- "old.ia32_sigreturn", /* 344 = old ia32_sigreturn */
- "#345", /* 345 = sigtimedwait */
- "#346", /* 346 = sigwaitinfo */
- "__acl_get_file", /* 347 = __acl_get_file */
- "__acl_set_file", /* 348 = __acl_set_file */
- "__acl_get_fd", /* 349 = __acl_get_fd */
- "__acl_set_fd", /* 350 = __acl_set_fd */
- "__acl_delete_file", /* 351 = __acl_delete_file */
- "__acl_delete_fd", /* 352 = __acl_delete_fd */
- "__acl_aclcheck_file", /* 353 = __acl_aclcheck_file */
- "__acl_aclcheck_fd", /* 354 = __acl_aclcheck_fd */
- "extattrctl", /* 355 = extattrctl */
- "extattr_set_file", /* 356 = extattr_set_file */
- "extattr_get_file", /* 357 = extattr_get_file */
- "extattr_delete_file", /* 358 = extattr_delete_file */
- "#359", /* 359 = aio_waitcomplete */
- "getresuid", /* 360 = getresuid */
- "getresgid", /* 361 = getresgid */
- "kqueue", /* 362 = kqueue */
- "ia32_kevent", /* 363 = ia32_kevent */
- "#364", /* 364 = __cap_get_proc */
- "#365", /* 365 = __cap_set_proc */
- "#366", /* 366 = __cap_get_fd */
- "#367", /* 367 = __cap_get_file */
- "#368", /* 368 = __cap_set_fd */
- "#369", /* 369 = __cap_set_file */
- "#370", /* 370 = lkmressys */
- "extattr_set_fd", /* 371 = extattr_set_fd */
- "extattr_get_fd", /* 372 = extattr_get_fd */
- "extattr_delete_fd", /* 373 = extattr_delete_fd */
- "__setugid", /* 374 = __setugid */
- "#375", /* 375 = nfsclnt */
- "eaccess", /* 376 = eaccess */
- "#377", /* 377 = afs_syscall */
- "nmount", /* 378 = nmount */
- "kse_exit", /* 379 = kse_exit */
- "kse_wakeup", /* 380 = kse_wakeup */
- "kse_create", /* 381 = kse_create */
- "kse_thr_interrupt", /* 382 = kse_thr_interrupt */
- "kse_release", /* 383 = kse_release */
- "#384", /* 384 = __mac_get_proc */
- "#385", /* 385 = __mac_set_proc */
- "#386", /* 386 = __mac_get_fd */
- "#387", /* 387 = __mac_get_file */
- "#388", /* 388 = __mac_set_fd */
- "#389", /* 389 = __mac_set_file */
- "kenv", /* 390 = kenv */
- "lchflags", /* 391 = lchflags */
- "uuidgen", /* 392 = uuidgen */
- "ia32_sendfile", /* 393 = ia32_sendfile */
- "#394", /* 394 = mac_syscall */
- "#395", /* 395 = nosys */
- "#396", /* 396 = nosys */
- "#397", /* 397 = nosys */
- "#398", /* 398 = nosys */
- "#399", /* 399 = nosys */
- "#400", /* 400 = ksem_close */
- "#401", /* 401 = ksem_post */
- "#402", /* 402 = ksem_wait */
- "#403", /* 403 = ksem_trywait */
- "#404", /* 404 = ksem_init */
- "#405", /* 405 = ksem_open */
- "#406", /* 406 = ksem_unlink */
- "#407", /* 407 = ksem_getvalue */
- "#408", /* 408 = ksem_destroy */
- "#409", /* 409 = __mac_get_pid */
- "#410", /* 410 = __mac_get_link */
- "#411", /* 411 = __mac_set_link */
- "#412", /* 412 = extattr_set_link */
- "#413", /* 413 = extattr_get_link */
- "#414", /* 414 = extattr_delete_link */
- "#415", /* 415 = __mac_execve */
- "ia32_sigreturn", /* 416 = ia32_sigreturn */
- "ia32_sigaction", /* 417 = ia32_sigaction */
- "#418", /* 418 = __xstat */
- "#419", /* 419 = __xfstat */
- "#420", /* 420 = __xlstat */
- "#421", /* 421 = getcontext */
- "#422", /* 422 = setcontext */
- "#423", /* 423 = swapcontext */
- "#424", /* 424 = swapoff */
- "#425", /* 425 = __acl_get_link */
- "#426", /* 426 = __acl_set_link */
- "#427", /* 427 = __acl_delete_link */
- "#428", /* 428 = __acl_aclcheck_link */
- "#429", /* 429 = sigwait */
- "thr_create", /* 430 = thr_create */
- "thr_exit", /* 431 = thr_exit */
- "thr_self", /* 432 = thr_self */
- "thr_kill", /* 433 = thr_kill */
- "_umtx_lock", /* 434 = _umtx_lock */
- "_umtx_unlock", /* 435 = _umtx_unlock */
- "jail_attach", /* 436 = jail_attach */
-};
diff --git a/sys/compat/freebsd32/freebsd32_sysent.c b/sys/compat/freebsd32/freebsd32_sysent.c
deleted file mode 100644
index 4c3f6c766adc..000000000000
--- a/sys/compat/freebsd32/freebsd32_sysent.c
+++ /dev/null
@@ -1,465 +0,0 @@
-/*
- * System call switch table.
- *
- * DO NOT EDIT-- this file is automatically generated.
- * $FreeBSD$
- * created from FreeBSD: src/sys/amd64/ia32/syscalls.master,v 1.22 2003/05/14 04:10:49 peter Exp
- */
-
-#include "opt_compat.h"
-
-#include <sys/param.h>
-#include <sys/sysent.h>
-#include <sys/sysproto.h>
-#include <sys/mount.h>
-#include <amd64/ia32/ia32.h>
-#include <amd64/ia32/ia32_proto.h>
-
-#define AS(name) (sizeof(struct name) / sizeof(register_t))
-
-#ifdef COMPAT_FREEBSD4
-#define compat4(n, name) n, (sy_call_t *)__CONCAT(freebsd4_,name)
-#else
-#define compat4(n, name) 0, (sy_call_t *)nosys
-#endif
-
-/* The casts are bogus but will do for now. */
-struct sysent ia32_sysent[] = {
- { SYF_MPSAFE | 0, (sy_call_t *)nosys }, /* 0 = syscall */
- { SYF_MPSAFE | AS(sys_exit_args), (sy_call_t *)sys_exit }, /* 1 = exit */
- { SYF_MPSAFE | 0, (sy_call_t *)fork }, /* 2 = fork */
- { SYF_MPSAFE | AS(read_args), (sy_call_t *)read }, /* 3 = read */
- { SYF_MPSAFE | AS(write_args), (sy_call_t *)write }, /* 4 = write */
- { AS(ia32_open_args), (sy_call_t *)ia32_open }, /* 5 = ia32_open */
- { SYF_MPSAFE | AS(close_args), (sy_call_t *)close }, /* 6 = close */
- { SYF_MPSAFE | AS(ia32_wait4_args), (sy_call_t *)ia32_wait4 }, /* 7 = ia32_wait4 */
- { 0, (sy_call_t *)nosys }, /* 8 = obsolete old creat */
- { AS(link_args), (sy_call_t *)link }, /* 9 = link */
- { AS(unlink_args), (sy_call_t *)unlink }, /* 10 = unlink */
- { 0, (sy_call_t *)nosys }, /* 11 = obsolete execv */
- { AS(chdir_args), (sy_call_t *)chdir }, /* 12 = chdir */
- { AS(fchdir_args), (sy_call_t *)fchdir }, /* 13 = fchdir */
- { AS(mknod_args), (sy_call_t *)mknod }, /* 14 = mknod */
- { AS(chmod_args), (sy_call_t *)chmod }, /* 15 = chmod */
- { AS(chown_args), (sy_call_t *)chown }, /* 16 = chown */
- { SYF_MPSAFE | AS(obreak_args), (sy_call_t *)obreak }, /* 17 = break */
- { AS(ia32_getfsstat_args), (sy_call_t *)ia32_getfsstat }, /* 18 = ia32_getfsstat */
- { 0, (sy_call_t *)nosys }, /* 19 = obsolete olseek */
- { SYF_MPSAFE | 0, (sy_call_t *)getpid }, /* 20 = getpid */
- { AS(mount_args), (sy_call_t *)mount }, /* 21 = mount */
- { AS(unmount_args), (sy_call_t *)unmount }, /* 22 = unmount */
- { SYF_MPSAFE | AS(setuid_args), (sy_call_t *)setuid }, /* 23 = setuid */
- { SYF_MPSAFE | 0, (sy_call_t *)getuid }, /* 24 = getuid */
- { SYF_MPSAFE | 0, (sy_call_t *)geteuid }, /* 25 = geteuid */
- { AS(ptrace_args), (sy_call_t *)ptrace }, /* 26 = ptrace */
- { 0, (sy_call_t *)nosys }, /* 27 = recvmsg */
- { SYF_MPSAFE | AS(sendmsg_args), (sy_call_t *)sendmsg }, /* 28 = sendmsg */
- { SYF_MPSAFE | AS(recvfrom_args), (sy_call_t *)recvfrom }, /* 29 = recvfrom */
- { SYF_MPSAFE | AS(accept_args), (sy_call_t *)accept }, /* 30 = accept */
- { SYF_MPSAFE | AS(getpeername_args), (sy_call_t *)getpeername }, /* 31 = getpeername */
- { SYF_MPSAFE | AS(getsockname_args), (sy_call_t *)getsockname }, /* 32 = getsockname */
- { AS(ia32_access_args), (sy_call_t *)ia32_access }, /* 33 = ia32_access */
- { AS(ia32_chflags_args), (sy_call_t *)ia32_chflags }, /* 34 = ia32_chflags */
- { AS(fchflags_args), (sy_call_t *)fchflags }, /* 35 = fchflags */
- { 0, (sy_call_t *)sync }, /* 36 = sync */
- { SYF_MPSAFE | AS(kill_args), (sy_call_t *)kill }, /* 37 = kill */
- { 0, (sy_call_t *)nosys }, /* 38 = ostat */
- { SYF_MPSAFE | 0, (sy_call_t *)getppid }, /* 39 = getppid */
- { 0, (sy_call_t *)nosys }, /* 40 = olstat */
- { AS(dup_args), (sy_call_t *)dup }, /* 41 = dup */
- { 0, (sy_call_t *)pipe }, /* 42 = pipe */
- { SYF_MPSAFE | 0, (sy_call_t *)getegid }, /* 43 = getegid */
- { SYF_MPSAFE | AS(profil_args), (sy_call_t *)profil }, /* 44 = profil */
- { AS(ktrace_args), (sy_call_t *)ktrace }, /* 45 = ktrace */
- { 0, (sy_call_t *)nosys }, /* 46 = osigaction */
- { SYF_MPSAFE | 0, (sy_call_t *)getgid }, /* 47 = getgid */
- { 0, (sy_call_t *)nosys }, /* 48 = osigprocmask */
- { SYF_MPSAFE | AS(getlogin_args), (sy_call_t *)getlogin }, /* 49 = getlogin */
- { SYF_MPSAFE | AS(setlogin_args), (sy_call_t *)setlogin }, /* 50 = setlogin */
- { SYF_MPSAFE | AS(acct_args), (sy_call_t *)acct }, /* 51 = acct */
- { SYF_MPSAFE | 0, (sy_call_t *)sigpending }, /* 52 = sigpending */
- { AS(ia32_sigaltstack_args), (sy_call_t *)ia32_sigaltstack }, /* 53 = ia32_sigaltstack */
- { SYF_MPSAFE | AS(ioctl_args), (sy_call_t *)ioctl }, /* 54 = ioctl */
- { SYF_MPSAFE | AS(reboot_args), (sy_call_t *)reboot }, /* 55 = reboot */
- { AS(revoke_args), (sy_call_t *)revoke }, /* 56 = revoke */
- { AS(symlink_args), (sy_call_t *)symlink }, /* 57 = symlink */
- { AS(readlink_args), (sy_call_t *)readlink }, /* 58 = readlink */
- { AS(ia32_execve_args), (sy_call_t *)ia32_execve }, /* 59 = ia32_execve */
- { SYF_MPSAFE | AS(umask_args), (sy_call_t *)umask }, /* 60 = umask */
- { AS(chroot_args), (sy_call_t *)chroot }, /* 61 = chroot */
- { 0, (sy_call_t *)nosys }, /* 62 = obsolete ofstat */
- { 0, (sy_call_t *)nosys }, /* 63 = obsolete ogetkerninfo */
- { 0, (sy_call_t *)nosys }, /* 64 = obsolete ogetpagesize */
- { 0, (sy_call_t *)nosys }, /* 65 = obsolete omsync */
- { 0, (sy_call_t *)nosys }, /* 66 = obsolete ovfork */
- { 0, (sy_call_t *)nosys }, /* 67 = obsolete vread */
- { 0, (sy_call_t *)nosys }, /* 68 = obsolete vwrite */
- { SYF_MPSAFE | AS(sbrk_args), (sy_call_t *)sbrk }, /* 69 = sbrk */
- { SYF_MPSAFE | AS(sstk_args), (sy_call_t *)sstk }, /* 70 = sstk */
- { 0, (sy_call_t *)nosys }, /* 71 = obsolete ommap */
- { SYF_MPSAFE | AS(ovadvise_args), (sy_call_t *)ovadvise }, /* 72 = vadvise */
- { SYF_MPSAFE | AS(munmap_args), (sy_call_t *)munmap }, /* 73 = munmap */
- { SYF_MPSAFE | AS(mprotect_args), (sy_call_t *)mprotect }, /* 74 = mprotect */
- { SYF_MPSAFE | AS(madvise_args), (sy_call_t *)madvise }, /* 75 = madvise */
- { 0, (sy_call_t *)nosys }, /* 76 = obsolete vhangup */
- { 0, (sy_call_t *)nosys }, /* 77 = obsolete vlimit */
- { SYF_MPSAFE | AS(mincore_args), (sy_call_t *)mincore }, /* 78 = mincore */
- { SYF_MPSAFE | AS(getgroups_args), (sy_call_t *)getgroups }, /* 79 = getgroups */
- { SYF_MPSAFE | AS(setgroups_args), (sy_call_t *)setgroups }, /* 80 = setgroups */
- { SYF_MPSAFE | 0, (sy_call_t *)getpgrp }, /* 81 = getpgrp */
- { SYF_MPSAFE | AS(setpgid_args), (sy_call_t *)setpgid }, /* 82 = setpgid */
- { AS(ia32_setitimer_args), (sy_call_t *)ia32_setitimer }, /* 83 = ia32_setitimer */
- { 0, (sy_call_t *)nosys }, /* 84 = obsolete owait */
- { 0, (sy_call_t *)nosys }, /* 85 = obsolete oswapon */
- { 0, (sy_call_t *)nosys }, /* 86 = obsolete ogetitimer */
- { 0, (sy_call_t *)nosys }, /* 87 = obsolete ogethostname */
- { 0, (sy_call_t *)nosys }, /* 88 = obsolete osethostname */
- { SYF_MPSAFE | 0, (sy_call_t *)getdtablesize }, /* 89 = getdtablesize */
- { SYF_MPSAFE | AS(dup2_args), (sy_call_t *)dup2 }, /* 90 = dup2 */
- { 0, (sy_call_t *)nosys }, /* 91 = getdopt */
- { SYF_MPSAFE | AS(fcntl_args), (sy_call_t *)fcntl }, /* 92 = fcntl */
- { AS(ia32_select_args), (sy_call_t *)ia32_select }, /* 93 = ia32_select */
- { 0, (sy_call_t *)nosys }, /* 94 = setdopt */
- { AS(fsync_args), (sy_call_t *)fsync }, /* 95 = fsync */
- { SYF_MPSAFE | AS(setpriority_args), (sy_call_t *)setpriority }, /* 96 = setpriority */
- { SYF_MPSAFE | AS(socket_args), (sy_call_t *)socket }, /* 97 = socket */
- { SYF_MPSAFE | AS(connect_args), (sy_call_t *)connect }, /* 98 = connect */
- { SYF_MPSAFE | AS(accept_args), (sy_call_t *)accept }, /* 99 = accept */
- { SYF_MPSAFE | AS(getpriority_args), (sy_call_t *)getpriority }, /* 100 = getpriority */
- { 0, (sy_call_t *)nosys }, /* 101 = obsolete osend */
- { 0, (sy_call_t *)nosys }, /* 102 = obsolete orecv */
- { 0, (sy_call_t *)nosys }, /* 103 = obsolete osigreturn */
- { SYF_MPSAFE | AS(bind_args), (sy_call_t *)bind }, /* 104 = bind */
- { SYF_MPSAFE | AS(setsockopt_args), (sy_call_t *)setsockopt }, /* 105 = setsockopt */
- { SYF_MPSAFE | AS(listen_args), (sy_call_t *)listen }, /* 106 = listen */
- { 0, (sy_call_t *)nosys }, /* 107 = obsolete vtimes */
- { 0, (sy_call_t *)nosys }, /* 108 = obsolete osigvec */
- { 0, (sy_call_t *)nosys }, /* 109 = obsolete osigblock */
- { 0, (sy_call_t *)nosys }, /* 110 = obsolete osigsetmask */
- { 0, (sy_call_t *)nosys }, /* 111 = obsolete osigsuspend */
- { 0, (sy_call_t *)nosys }, /* 112 = obsolete osigstack */
- { 0, (sy_call_t *)nosys }, /* 113 = obsolete orecvmsg */
- { 0, (sy_call_t *)nosys }, /* 114 = obsolete osendmsg */
- { 0, (sy_call_t *)nosys }, /* 115 = obsolete vtrace */
- { AS(ia32_gettimeofday_args), (sy_call_t *)ia32_gettimeofday }, /* 116 = ia32_gettimeofday */
- { AS(ia32_getrusage_args), (sy_call_t *)ia32_getrusage }, /* 117 = ia32_getrusage */
- { SYF_MPSAFE | AS(getsockopt_args), (sy_call_t *)getsockopt }, /* 118 = getsockopt */
- { 0, (sy_call_t *)nosys }, /* 119 = resuba */
- { AS(ia32_readv_args), (sy_call_t *)ia32_readv }, /* 120 = ia32_readv */
- { AS(ia32_writev_args), (sy_call_t *)ia32_writev }, /* 121 = ia32_writev */
- { AS(ia32_settimeofday_args), (sy_call_t *)ia32_settimeofday }, /* 122 = ia32_settimeofday */
- { AS(fchown_args), (sy_call_t *)fchown }, /* 123 = fchown */
- { AS(fchmod_args), (sy_call_t *)fchmod }, /* 124 = fchmod */
- { SYF_MPSAFE | AS(recvfrom_args), (sy_call_t *)recvfrom }, /* 125 = recvfrom */
- { SYF_MPSAFE | AS(setreuid_args), (sy_call_t *)setreuid }, /* 126 = setreuid */
- { SYF_MPSAFE | AS(setregid_args), (sy_call_t *)setregid }, /* 127 = setregid */
- { AS(rename_args), (sy_call_t *)rename }, /* 128 = rename */
- { 0, (sy_call_t *)nosys }, /* 129 = obsolete otruncate */
- { 0, (sy_call_t *)nosys }, /* 130 = obsolete ftruncate */
- { SYF_MPSAFE | AS(flock_args), (sy_call_t *)flock }, /* 131 = flock */
- { AS(mkfifo_args), (sy_call_t *)mkfifo }, /* 132 = mkfifo */
- { SYF_MPSAFE | AS(sendto_args), (sy_call_t *)sendto }, /* 133 = sendto */
- { SYF_MPSAFE | AS(shutdown_args), (sy_call_t *)shutdown }, /* 134 = shutdown */
- { SYF_MPSAFE | AS(socketpair_args), (sy_call_t *)socketpair }, /* 135 = socketpair */
- { AS(mkdir_args), (sy_call_t *)mkdir }, /* 136 = mkdir */
- { AS(rmdir_args), (sy_call_t *)rmdir }, /* 137 = rmdir */
- { AS(ia32_utimes_args), (sy_call_t *)ia32_utimes }, /* 138 = ia32_utimes */
- { 0, (sy_call_t *)nosys }, /* 139 = obsolete 4.2 sigreturn */
- { AS(ia32_adjtime_args), (sy_call_t *)ia32_adjtime }, /* 140 = ia32_adjtime */
- { 0, (sy_call_t *)nosys }, /* 141 = obsolete ogetpeername */
- { 0, (sy_call_t *)nosys }, /* 142 = obsolete ogethostid */
- { 0, (sy_call_t *)nosys }, /* 143 = obsolete sethostid */
- { 0, (sy_call_t *)nosys }, /* 144 = obsolete getrlimit */
- { 0, (sy_call_t *)nosys }, /* 145 = obsolete setrlimit */
- { 0, (sy_call_t *)nosys }, /* 146 = obsolete killpg */
- { SYF_MPSAFE | 0, (sy_call_t *)setsid }, /* 147 = setsid */
- { AS(quotactl_args), (sy_call_t *)quotactl }, /* 148 = quotactl */
- { 0, (sy_call_t *)nosys }, /* 149 = obsolete oquota */
- { 0, (sy_call_t *)nosys }, /* 150 = obsolete ogetsockname */
- { 0, (sy_call_t *)nosys }, /* 151 = sem_lock */
- { 0, (sy_call_t *)nosys }, /* 152 = sem_wakeup */
- { 0, (sy_call_t *)nosys }, /* 153 = asyncdaemon */
- { 0, (sy_call_t *)nosys }, /* 154 = nosys */
- { 0, (sy_call_t *)nosys }, /* 155 = nfssvc */
- { AS(getdirentries_args), (sy_call_t *)getdirentries }, /* 156 = getdirentries */
- { AS(ia32_statfs_args), (sy_call_t *)ia32_statfs }, /* 157 = ia32_statfs */
- { AS(ia32_fstatfs_args), (sy_call_t *)ia32_fstatfs }, /* 158 = ia32_fstatfs */
- { 0, (sy_call_t *)nosys }, /* 159 = nosys */
- { 0, (sy_call_t *)nosys }, /* 160 = nosys */
- { AS(getfh_args), (sy_call_t *)getfh }, /* 161 = getfh */
- { SYF_MPSAFE | AS(getdomainname_args), (sy_call_t *)getdomainname }, /* 162 = getdomainname */
- { SYF_MPSAFE | AS(setdomainname_args), (sy_call_t *)setdomainname }, /* 163 = setdomainname */
- { SYF_MPSAFE | AS(uname_args), (sy_call_t *)uname }, /* 164 = uname */
- { AS(sysarch_args), (sy_call_t *)sysarch }, /* 165 = sysarch */
- { SYF_MPSAFE | AS(rtprio_args), (sy_call_t *)rtprio }, /* 166 = rtprio */
- { 0, (sy_call_t *)nosys }, /* 167 = nosys */
- { 0, (sy_call_t *)nosys }, /* 168 = nosys */
- { AS(ia32_semsys_args), (sy_call_t *)ia32_semsys }, /* 169 = ia32_semsys */
- { AS(ia32_msgsys_args), (sy_call_t *)ia32_msgsys }, /* 170 = ia32_msgsys */
- { AS(ia32_shmsys_args), (sy_call_t *)ia32_shmsys }, /* 171 = ia32_shmsys */
- { 0, (sy_call_t *)nosys }, /* 172 = nosys */
- { AS(ia32_pread_args), (sy_call_t *)ia32_pread }, /* 173 = ia32_pread */
- { AS(ia32_pwrite_args), (sy_call_t *)ia32_pwrite }, /* 174 = ia32_pwrite */
- { 0, (sy_call_t *)nosys }, /* 175 = nosys */
- { SYF_MPSAFE | AS(ntp_adjtime_args), (sy_call_t *)ntp_adjtime }, /* 176 = ntp_adjtime */
- { 0, (sy_call_t *)nosys }, /* 177 = sfork */
- { 0, (sy_call_t *)nosys }, /* 178 = getdescriptor */
- { 0, (sy_call_t *)nosys }, /* 179 = setdescriptor */
- { 0, (sy_call_t *)nosys }, /* 180 = nosys */
- { SYF_MPSAFE | AS(setgid_args), (sy_call_t *)setgid }, /* 181 = setgid */
- { SYF_MPSAFE | AS(setegid_args), (sy_call_t *)setegid }, /* 182 = setegid */
- { SYF_MPSAFE | AS(seteuid_args), (sy_call_t *)seteuid }, /* 183 = seteuid */
- { 0, (sy_call_t *)nosys }, /* 184 = lfs_bmapv */
- { 0, (sy_call_t *)nosys }, /* 185 = lfs_markv */
- { 0, (sy_call_t *)nosys }, /* 186 = lfs_segclean */
- { 0, (sy_call_t *)nosys }, /* 187 = lfs_segwait */
- { AS(ia32_stat_args), (sy_call_t *)ia32_stat }, /* 188 = ia32_stat */
- { AS(ia32_fstat_args), (sy_call_t *)ia32_fstat }, /* 189 = ia32_fstat */
- { AS(ia32_lstat_args), (sy_call_t *)ia32_lstat }, /* 190 = ia32_lstat */
- { AS(pathconf_args), (sy_call_t *)pathconf }, /* 191 = pathconf */
- { SYF_MPSAFE | AS(fpathconf_args), (sy_call_t *)fpathconf }, /* 192 = fpathconf */
- { 0, (sy_call_t *)nosys }, /* 193 = nosys */
- { SYF_MPSAFE | AS(__getrlimit_args), (sy_call_t *)getrlimit }, /* 194 = getrlimit */
- { SYF_MPSAFE | AS(__setrlimit_args), (sy_call_t *)setrlimit }, /* 195 = setrlimit */
- { AS(getdirentries_args), (sy_call_t *)getdirentries }, /* 196 = getdirentries */
- { AS(ia32_mmap_args), (sy_call_t *)ia32_mmap }, /* 197 = ia32_mmap */
- { 0, (sy_call_t *)nosys }, /* 198 = __syscall */
- { AS(ia32_lseek_args), (sy_call_t *)ia32_lseek }, /* 199 = ia32_lseek */
- { AS(ia32_truncate_args), (sy_call_t *)ia32_truncate }, /* 200 = ia32_truncate */
- { AS(ia32_ftruncate_args), (sy_call_t *)ia32_ftruncate }, /* 201 = ia32_ftruncate */
- { SYF_MPSAFE | AS(ia32_sysctl_args), (sy_call_t *)ia32_sysctl }, /* 202 = ia32_sysctl */
- { SYF_MPSAFE | AS(mlock_args), (sy_call_t *)mlock }, /* 203 = mlock */
- { SYF_MPSAFE | AS(munlock_args), (sy_call_t *)munlock }, /* 204 = munlock */
- { AS(undelete_args), (sy_call_t *)undelete }, /* 205 = undelete */
- { AS(futimes_args), (sy_call_t *)futimes }, /* 206 = futimes */
- { SYF_MPSAFE | AS(getpgid_args), (sy_call_t *)getpgid }, /* 207 = getpgid */
- { 0, (sy_call_t *)nosys }, /* 208 = newreboot */
- { SYF_MPSAFE | AS(poll_args), (sy_call_t *)poll }, /* 209 = poll */
- { 0, (sy_call_t *)nosys }, /* 210 = */
- { 0, (sy_call_t *)nosys }, /* 211 = */
- { 0, (sy_call_t *)nosys }, /* 212 = */
- { 0, (sy_call_t *)nosys }, /* 213 = */
- { 0, (sy_call_t *)nosys }, /* 214 = */
- { 0, (sy_call_t *)nosys }, /* 215 = */
- { 0, (sy_call_t *)nosys }, /* 216 = */
- { 0, (sy_call_t *)nosys }, /* 217 = */
- { 0, (sy_call_t *)nosys }, /* 218 = */
- { 0, (sy_call_t *)nosys }, /* 219 = */
- { SYF_MPSAFE | AS(__semctl_args), (sy_call_t *)__semctl }, /* 220 = __semctl */
- { SYF_MPSAFE | AS(semget_args), (sy_call_t *)semget }, /* 221 = semget */
- { SYF_MPSAFE | AS(semop_args), (sy_call_t *)semop }, /* 222 = semop */
- { 0, (sy_call_t *)nosys }, /* 223 = semconfig */
- { SYF_MPSAFE | AS(msgctl_args), (sy_call_t *)msgctl }, /* 224 = msgctl */
- { SYF_MPSAFE | AS(msgget_args), (sy_call_t *)msgget }, /* 225 = msgget */
- { SYF_MPSAFE | AS(msgsnd_args), (sy_call_t *)msgsnd }, /* 226 = msgsnd */
- { SYF_MPSAFE | AS(msgrcv_args), (sy_call_t *)msgrcv }, /* 227 = msgrcv */
- { SYF_MPSAFE | AS(shmat_args), (sy_call_t *)shmat }, /* 228 = shmat */
- { SYF_MPSAFE | AS(shmctl_args), (sy_call_t *)shmctl }, /* 229 = shmctl */
- { SYF_MPSAFE | AS(shmdt_args), (sy_call_t *)shmdt }, /* 230 = shmdt */
- { SYF_MPSAFE | AS(shmget_args), (sy_call_t *)shmget }, /* 231 = shmget */
- { SYF_MPSAFE | AS(clock_gettime_args), (sy_call_t *)clock_gettime }, /* 232 = clock_gettime */
- { SYF_MPSAFE | AS(clock_settime_args), (sy_call_t *)clock_settime }, /* 233 = clock_settime */
- { SYF_MPSAFE | AS(clock_getres_args), (sy_call_t *)clock_getres }, /* 234 = clock_getres */
- { 0, (sy_call_t *)nosys }, /* 235 = timer_create */
- { 0, (sy_call_t *)nosys }, /* 236 = timer_delete */
- { 0, (sy_call_t *)nosys }, /* 237 = timer_settime */
- { 0, (sy_call_t *)nosys }, /* 238 = timer_gettime */
- { 0, (sy_call_t *)nosys }, /* 239 = timer_getoverrun */
- { SYF_MPSAFE | AS(nanosleep_args), (sy_call_t *)nanosleep }, /* 240 = nanosleep */
- { 0, (sy_call_t *)nosys }, /* 241 = nosys */
- { 0, (sy_call_t *)nosys }, /* 242 = nosys */
- { 0, (sy_call_t *)nosys }, /* 243 = nosys */
- { 0, (sy_call_t *)nosys }, /* 244 = nosys */
- { 0, (sy_call_t *)nosys }, /* 245 = nosys */
- { 0, (sy_call_t *)nosys }, /* 246 = nosys */
- { 0, (sy_call_t *)nosys }, /* 247 = nosys */
- { 0, (sy_call_t *)nosys }, /* 248 = nosys */
- { 0, (sy_call_t *)nosys }, /* 249 = nosys */
- { SYF_MPSAFE | AS(minherit_args), (sy_call_t *)minherit }, /* 250 = minherit */
- { SYF_MPSAFE | AS(rfork_args), (sy_call_t *)rfork }, /* 251 = rfork */
- { SYF_MPSAFE | AS(openbsd_poll_args), (sy_call_t *)openbsd_poll }, /* 252 = openbsd_poll */
- { 0, (sy_call_t *)issetugid }, /* 253 = issetugid */
- { AS(lchown_args), (sy_call_t *)lchown }, /* 254 = lchown */
- { 0, (sy_call_t *)nosys }, /* 255 = nosys */
- { 0, (sy_call_t *)nosys }, /* 256 = nosys */
- { 0, (sy_call_t *)nosys }, /* 257 = nosys */
- { 0, (sy_call_t *)nosys }, /* 258 = nosys */
- { 0, (sy_call_t *)nosys }, /* 259 = nosys */
- { 0, (sy_call_t *)nosys }, /* 260 = nosys */
- { 0, (sy_call_t *)nosys }, /* 261 = nosys */
- { 0, (sy_call_t *)nosys }, /* 262 = nosys */
- { 0, (sy_call_t *)nosys }, /* 263 = nosys */
- { 0, (sy_call_t *)nosys }, /* 264 = nosys */
- { 0, (sy_call_t *)nosys }, /* 265 = nosys */
- { 0, (sy_call_t *)nosys }, /* 266 = nosys */
- { 0, (sy_call_t *)nosys }, /* 267 = nosys */
- { 0, (sy_call_t *)nosys }, /* 268 = nosys */
- { 0, (sy_call_t *)nosys }, /* 269 = nosys */
- { 0, (sy_call_t *)nosys }, /* 270 = nosys */
- { 0, (sy_call_t *)nosys }, /* 271 = nosys */
- { AS(getdents_args), (sy_call_t *)getdents }, /* 272 = getdents */
- { 0, (sy_call_t *)nosys }, /* 273 = nosys */
- { AS(lchmod_args), (sy_call_t *)lchmod }, /* 274 = lchmod */
- { AS(lchown_args), (sy_call_t *)lchown }, /* 275 = netbsd_lchown */
- { AS(lutimes_args), (sy_call_t *)lutimes }, /* 276 = lutimes */
- { SYF_MPSAFE | AS(msync_args), (sy_call_t *)msync }, /* 277 = netbsd_msync */
- { AS(nstat_args), (sy_call_t *)nstat }, /* 278 = nstat */
- { SYF_MPSAFE | AS(nfstat_args), (sy_call_t *)nfstat }, /* 279 = nfstat */
- { AS(nlstat_args), (sy_call_t *)nlstat }, /* 280 = nlstat */
- { 0, (sy_call_t *)nosys }, /* 281 = nosys */
- { 0, (sy_call_t *)nosys }, /* 282 = nosys */
- { 0, (sy_call_t *)nosys }, /* 283 = nosys */
- { 0, (sy_call_t *)nosys }, /* 284 = nosys */
- { 0, (sy_call_t *)nosys }, /* 285 = nosys */
- { 0, (sy_call_t *)nosys }, /* 286 = nosys */
- { 0, (sy_call_t *)nosys }, /* 287 = nosys */
- { 0, (sy_call_t *)nosys }, /* 288 = nosys */
- { 0, (sy_call_t *)nosys }, /* 289 = nosys */
- { 0, (sy_call_t *)nosys }, /* 290 = nosys */
- { 0, (sy_call_t *)nosys }, /* 291 = nosys */
- { 0, (sy_call_t *)nosys }, /* 292 = nosys */
- { 0, (sy_call_t *)nosys }, /* 293 = nosys */
- { 0, (sy_call_t *)nosys }, /* 294 = nosys */
- { 0, (sy_call_t *)nosys }, /* 295 = nosys */
- { 0, (sy_call_t *)nosys }, /* 296 = nosys */
- { AS(fhstatfs_args), (sy_call_t *)fhstatfs }, /* 297 = fhstatfs */
- { AS(fhopen_args), (sy_call_t *)fhopen }, /* 298 = fhopen */
- { AS(fhstat_args), (sy_call_t *)fhstat }, /* 299 = fhstat */
- { SYF_MPSAFE | AS(modnext_args), (sy_call_t *)modnext }, /* 300 = modnext */
- { SYF_MPSAFE | AS(modstat_args), (sy_call_t *)modstat }, /* 301 = modstat */
- { SYF_MPSAFE | AS(modfnext_args), (sy_call_t *)modfnext }, /* 302 = modfnext */
- { SYF_MPSAFE | AS(modfind_args), (sy_call_t *)modfind }, /* 303 = modfind */
- { SYF_MPSAFE | AS(kldload_args), (sy_call_t *)kldload }, /* 304 = kldload */
- { SYF_MPSAFE | AS(kldunload_args), (sy_call_t *)kldunload }, /* 305 = kldunload */
- { SYF_MPSAFE | AS(kldfind_args), (sy_call_t *)kldfind }, /* 306 = kldfind */
- { SYF_MPSAFE | AS(kldnext_args), (sy_call_t *)kldnext }, /* 307 = kldnext */
- { SYF_MPSAFE | AS(kldstat_args), (sy_call_t *)kldstat }, /* 308 = kldstat */
- { SYF_MPSAFE | AS(kldfirstmod_args), (sy_call_t *)kldfirstmod }, /* 309 = kldfirstmod */
- { SYF_MPSAFE | AS(getsid_args), (sy_call_t *)getsid }, /* 310 = getsid */
- { SYF_MPSAFE | AS(setresuid_args), (sy_call_t *)setresuid }, /* 311 = setresuid */
- { SYF_MPSAFE | AS(setresgid_args), (sy_call_t *)setresgid }, /* 312 = setresgid */
- { 0, (sy_call_t *)nosys }, /* 313 = obsolete signanosleep */
- { 0, (sy_call_t *)nosys }, /* 314 = aio_return */
- { 0, (sy_call_t *)nosys }, /* 315 = aio_suspend */
- { 0, (sy_call_t *)nosys }, /* 316 = aio_cancel */
- { 0, (sy_call_t *)nosys }, /* 317 = aio_error */
- { 0, (sy_call_t *)nosys }, /* 318 = aio_read */
- { 0, (sy_call_t *)nosys }, /* 319 = aio_write */
- { 0, (sy_call_t *)nosys }, /* 320 = lio_listio */
- { SYF_MPSAFE | 0, (sy_call_t *)yield }, /* 321 = yield */
- { 0, (sy_call_t *)nosys }, /* 322 = obsolete thr_sleep */
- { 0, (sy_call_t *)nosys }, /* 323 = obsolete thr_wakeup */
- { SYF_MPSAFE | AS(mlockall_args), (sy_call_t *)mlockall }, /* 324 = mlockall */
- { SYF_MPSAFE | 0, (sy_call_t *)munlockall }, /* 325 = munlockall */
- { AS(__getcwd_args), (sy_call_t *)__getcwd }, /* 326 = __getcwd */
- { SYF_MPSAFE | AS(sched_setparam_args), (sy_call_t *)sched_setparam }, /* 327 = sched_setparam */
- { SYF_MPSAFE | AS(sched_getparam_args), (sy_call_t *)sched_getparam }, /* 328 = sched_getparam */
- { SYF_MPSAFE | AS(sched_setscheduler_args), (sy_call_t *)sched_setscheduler }, /* 329 = sched_setscheduler */
- { SYF_MPSAFE | AS(sched_getscheduler_args), (sy_call_t *)sched_getscheduler }, /* 330 = sched_getscheduler */
- { SYF_MPSAFE | 0, (sy_call_t *)sched_yield }, /* 331 = sched_yield */
- { SYF_MPSAFE | AS(sched_get_priority_max_args), (sy_call_t *)sched_get_priority_max }, /* 332 = sched_get_priority_max */
- { SYF_MPSAFE | AS(sched_get_priority_min_args), (sy_call_t *)sched_get_priority_min }, /* 333 = sched_get_priority_min */
- { SYF_MPSAFE | AS(sched_rr_get_interval_args), (sy_call_t *)sched_rr_get_interval }, /* 334 = sched_rr_get_interval */
- { AS(utrace_args), (sy_call_t *)utrace }, /* 335 = utrace */
- { compat4(SYF_MPSAFE | AS(freebsd4_ia32_sendfile_args),ia32_sendfile) }, /* 336 = old ia32_sendfile */
- { AS(kldsym_args), (sy_call_t *)kldsym }, /* 337 = kldsym */
- { SYF_MPSAFE | AS(jail_args), (sy_call_t *)jail }, /* 338 = jail */
- { 0, (sy_call_t *)nosys }, /* 339 = pioctl */
- { SYF_MPSAFE | AS(sigprocmask_args), (sy_call_t *)sigprocmask }, /* 340 = sigprocmask */
- { SYF_MPSAFE | AS(sigsuspend_args), (sy_call_t *)sigsuspend }, /* 341 = sigsuspend */
- { compat4(AS(freebsd4_ia32_sigaction_args),ia32_sigaction) }, /* 342 = old ia32_sigaction */
- { SYF_MPSAFE | AS(sigpending_args), (sy_call_t *)sigpending }, /* 343 = sigpending */
- { compat4(SYF_MPSAFE | AS(freebsd4_ia32_sigreturn_args),ia32_sigreturn) }, /* 344 = old ia32_sigreturn */
- { 0, (sy_call_t *)nosys }, /* 345 = sigtimedwait */
- { 0, (sy_call_t *)nosys }, /* 346 = sigwaitinfo */
- { SYF_MPSAFE | AS(__acl_get_file_args), (sy_call_t *)__acl_get_file }, /* 347 = __acl_get_file */
- { SYF_MPSAFE | AS(__acl_set_file_args), (sy_call_t *)__acl_set_file }, /* 348 = __acl_set_file */
- { SYF_MPSAFE | AS(__acl_get_fd_args), (sy_call_t *)__acl_get_fd }, /* 349 = __acl_get_fd */
- { SYF_MPSAFE | AS(__acl_set_fd_args), (sy_call_t *)__acl_set_fd }, /* 350 = __acl_set_fd */
- { SYF_MPSAFE | AS(__acl_delete_file_args), (sy_call_t *)__acl_delete_file }, /* 351 = __acl_delete_file */
- { SYF_MPSAFE | AS(__acl_delete_fd_args), (sy_call_t *)__acl_delete_fd }, /* 352 = __acl_delete_fd */
- { SYF_MPSAFE | AS(__acl_aclcheck_file_args), (sy_call_t *)__acl_aclcheck_file }, /* 353 = __acl_aclcheck_file */
- { SYF_MPSAFE | AS(__acl_aclcheck_fd_args), (sy_call_t *)__acl_aclcheck_fd }, /* 354 = __acl_aclcheck_fd */
- { AS(extattrctl_args), (sy_call_t *)extattrctl }, /* 355 = extattrctl */
- { AS(extattr_set_file_args), (sy_call_t *)extattr_set_file }, /* 356 = extattr_set_file */
- { AS(extattr_get_file_args), (sy_call_t *)extattr_get_file }, /* 357 = extattr_get_file */
- { AS(extattr_delete_file_args), (sy_call_t *)extattr_delete_file }, /* 358 = extattr_delete_file */
- { 0, (sy_call_t *)nosys }, /* 359 = aio_waitcomplete */
- { SYF_MPSAFE | AS(getresuid_args), (sy_call_t *)getresuid }, /* 360 = getresuid */
- { SYF_MPSAFE | AS(getresgid_args), (sy_call_t *)getresgid }, /* 361 = getresgid */
- { SYF_MPSAFE | 0, (sy_call_t *)kqueue }, /* 362 = kqueue */
- { SYF_MPSAFE | AS(ia32_kevent_args), (sy_call_t *)ia32_kevent }, /* 363 = ia32_kevent */
- { 0, (sy_call_t *)nosys }, /* 364 = __cap_get_proc */
- { 0, (sy_call_t *)nosys }, /* 365 = __cap_set_proc */
- { 0, (sy_call_t *)nosys }, /* 366 = __cap_get_fd */
- { 0, (sy_call_t *)nosys }, /* 367 = __cap_get_file */
- { 0, (sy_call_t *)nosys }, /* 368 = __cap_set_fd */
- { 0, (sy_call_t *)nosys }, /* 369 = __cap_set_file */
- { 0, (sy_call_t *)nosys }, /* 370 = lkmressys */
- { AS(extattr_set_fd_args), (sy_call_t *)extattr_set_fd }, /* 371 = extattr_set_fd */
- { AS(extattr_get_fd_args), (sy_call_t *)extattr_get_fd }, /* 372 = extattr_get_fd */
- { AS(extattr_delete_fd_args), (sy_call_t *)extattr_delete_fd }, /* 373 = extattr_delete_fd */
- { SYF_MPSAFE | AS(__setugid_args), (sy_call_t *)__setugid }, /* 374 = __setugid */
- { 0, (sy_call_t *)nosys }, /* 375 = nfsclnt */
- { AS(eaccess_args), (sy_call_t *)eaccess }, /* 376 = eaccess */
- { 0, (sy_call_t *)nosys }, /* 377 = afs_syscall */
- { AS(nmount_args), (sy_call_t *)nmount }, /* 378 = nmount */
- { 0, (sy_call_t *)kse_exit }, /* 379 = kse_exit */
- { AS(kse_wakeup_args), (sy_call_t *)kse_wakeup }, /* 380 = kse_wakeup */
- { AS(kse_create_args), (sy_call_t *)kse_create }, /* 381 = kse_create */
- { AS(kse_thr_interrupt_args), (sy_call_t *)kse_thr_interrupt }, /* 382 = kse_thr_interrupt */
- { 0, (sy_call_t *)kse_release }, /* 383 = kse_release */
- { 0, (sy_call_t *)nosys }, /* 384 = __mac_get_proc */
- { 0, (sy_call_t *)nosys }, /* 385 = __mac_set_proc */
- { 0, (sy_call_t *)nosys }, /* 386 = __mac_get_fd */
- { 0, (sy_call_t *)nosys }, /* 387 = __mac_get_file */
- { 0, (sy_call_t *)nosys }, /* 388 = __mac_set_fd */
- { 0, (sy_call_t *)nosys }, /* 389 = __mac_set_file */
- { AS(kenv_args), (sy_call_t *)kenv }, /* 390 = kenv */
- { AS(lchflags_args), (sy_call_t *)lchflags }, /* 391 = lchflags */
- { AS(uuidgen_args), (sy_call_t *)uuidgen }, /* 392 = uuidgen */
- { SYF_MPSAFE | AS(ia32_sendfile_args), (sy_call_t *)ia32_sendfile }, /* 393 = ia32_sendfile */
- { 0, (sy_call_t *)nosys }, /* 394 = mac_syscall */
- { 0, (sy_call_t *)nosys }, /* 395 = nosys */
- { 0, (sy_call_t *)nosys }, /* 396 = nosys */
- { 0, (sy_call_t *)nosys }, /* 397 = nosys */
- { 0, (sy_call_t *)nosys }, /* 398 = nosys */
- { 0, (sy_call_t *)nosys }, /* 399 = nosys */
- { 0, (sy_call_t *)nosys }, /* 400 = ksem_close */
- { 0, (sy_call_t *)nosys }, /* 401 = ksem_post */
- { 0, (sy_call_t *)nosys }, /* 402 = ksem_wait */
- { 0, (sy_call_t *)nosys }, /* 403 = ksem_trywait */
- { 0, (sy_call_t *)nosys }, /* 404 = ksem_init */
- { 0, (sy_call_t *)nosys }, /* 405 = ksem_open */
- { 0, (sy_call_t *)nosys }, /* 406 = ksem_unlink */
- { 0, (sy_call_t *)nosys }, /* 407 = ksem_getvalue */
- { 0, (sy_call_t *)nosys }, /* 408 = ksem_destroy */
- { 0, (sy_call_t *)nosys }, /* 409 = __mac_get_pid */
- { 0, (sy_call_t *)nosys }, /* 410 = __mac_get_link */
- { 0, (sy_call_t *)nosys }, /* 411 = __mac_set_link */
- { 0, (sy_call_t *)nosys }, /* 412 = extattr_set_link */
- { 0, (sy_call_t *)nosys }, /* 413 = extattr_get_link */
- { 0, (sy_call_t *)nosys }, /* 414 = extattr_delete_link */
- { 0, (sy_call_t *)nosys }, /* 415 = __mac_execve */
- { SYF_MPSAFE | AS(ia32_sigreturn_args), (sy_call_t *)ia32_sigreturn }, /* 416 = ia32_sigreturn */
- { AS(ia32_sigaction_args), (sy_call_t *)ia32_sigaction }, /* 417 = ia32_sigaction */
- { 0, (sy_call_t *)nosys }, /* 418 = __xstat */
- { 0, (sy_call_t *)nosys }, /* 419 = __xfstat */
- { 0, (sy_call_t *)nosys }, /* 420 = __xlstat */
- { 0, (sy_call_t *)nosys }, /* 421 = getcontext */
- { 0, (sy_call_t *)nosys }, /* 422 = setcontext */
- { 0, (sy_call_t *)nosys }, /* 423 = swapcontext */
- { 0, (sy_call_t *)nosys }, /* 424 = swapoff */
- { 0, (sy_call_t *)nosys }, /* 425 = __acl_get_link */
- { 0, (sy_call_t *)nosys }, /* 426 = __acl_set_link */
- { 0, (sy_call_t *)nosys }, /* 427 = __acl_delete_link */
- { 0, (sy_call_t *)nosys }, /* 428 = __acl_aclcheck_link */
- { 0, (sy_call_t *)nosys }, /* 429 = sigwait */
- { SYF_MPSAFE | AS(thr_create_args), (sy_call_t *)thr_create }, /* 430 = thr_create */
- { SYF_MPSAFE | 0, (sy_call_t *)thr_exit }, /* 431 = thr_exit */
- { SYF_MPSAFE | AS(thr_self_args), (sy_call_t *)thr_self }, /* 432 = thr_self */
- { SYF_MPSAFE | AS(thr_kill_args), (sy_call_t *)thr_kill }, /* 433 = thr_kill */
- { SYF_MPSAFE | AS(_umtx_lock_args), (sy_call_t *)_umtx_lock }, /* 434 = _umtx_lock */
- { SYF_MPSAFE | AS(_umtx_unlock_args), (sy_call_t *)_umtx_unlock }, /* 435 = _umtx_unlock */
- { SYF_MPSAFE | AS(jail_attach_args), (sy_call_t *)jail_attach }, /* 436 = jail_attach */
-};
diff --git a/sys/compat/freebsd32/freebsd32_util.h b/sys/compat/freebsd32/freebsd32_util.h
deleted file mode 100644
index 64fa29320ca8..000000000000
--- a/sys/compat/freebsd32/freebsd32_util.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*-
- * Copyright (c) 1998-1999 Andrew Gallatin
- * 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
- * in this position and unchanged.
- * 2. Redistributions in binary form must 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 withough specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-
-
-#include <sys/exec.h>
-#include <sys/sysent.h>
-#include <sys/cdefs.h>
-
-struct ia32_ps_strings {
- u_int32_t ps_argvstr; /* first of 0 or more argument strings */
- int ps_nargvstr; /* the number of argument strings */
- u_int32_t ps_envstr; /* first of 0 or more environment strings */
- int ps_nenvstr; /* the number of environment strings */
-};
-
-#define IA32_USRSTACK ((1ul << 32) - PAGE_SIZE)
-#define IA32_PS_STRINGS (IA32_USRSTACK - sizeof(struct ia32_ps_strings))
-
-static __inline caddr_t stackgap_init(void);
-static __inline void *stackgap_alloc(caddr_t *, size_t);
-
-static __inline caddr_t
-stackgap_init()
-{
-#define szsigcode (*(curproc->p_sysent->sv_szsigcode))
- return (caddr_t)(((caddr_t)IA32_PS_STRINGS) - szsigcode - SPARE_USRSPACE);
-#undef szsigcode
-}
-
-static __inline void *
-stackgap_alloc(sgp, sz)
- caddr_t *sgp;
- size_t sz;
-{
- void *p;
-
- p = (void *) *sgp;
- *sgp += ALIGN(sz);
- return p;
-}
-
-
-extern const char ia32_emul_path[];
-int ia32_emul_find(struct thread *, caddr_t *, const char *, char *,
- char **, int);
-
-#define CHECKALT(p, sgp, path, i) \
- do { \
- int _error; \
- \
- _error = ia32_emul_find(p, sgp, ia32_emul_path, path, \
- &path, i); \
- if (_error == EFAULT) \
- return (_error); \
- } while (0)
-
-#define CHECKALTEXIST(p, sgp, path) CHECKALT((p), (sgp), (path), 0)
-#define CHECKALTCREAT(p, sgp, path) CHECKALT((p), (sgp), (path), 1)
diff --git a/sys/compat/freebsd32/syscalls.conf b/sys/compat/freebsd32/syscalls.conf
deleted file mode 100644
index 0e1ded310bb4..000000000000
--- a/sys/compat/freebsd32/syscalls.conf
+++ /dev/null
@@ -1,12 +0,0 @@
-# $FreeBSD$
-sysnames="ia32_syscalls.c"
-sysproto="ia32_proto.h"
-sysproto_h=_IA32_SYSPROTO_H_
-syshdr="ia32_syscall.h"
-syssw="ia32_sysent.c"
-sysmk="/dev/null"
-syshide="/dev/null"
-syscallprefix="IA32_SYS_"
-switchname="ia32_sysent"
-namesname="ia32_syscallnames"
-sysvec="\n"
diff --git a/sys/compat/freebsd32/syscalls.master b/sys/compat/freebsd32/syscalls.master
deleted file mode 100644
index 042bf003b1c3..000000000000
--- a/sys/compat/freebsd32/syscalls.master
+++ /dev/null
@@ -1,613 +0,0 @@
- $FreeBSD$
-; from: @(#)syscalls.master 8.2 (Berkeley) 1/13/94
-; from: src/sys/kern/syscalls.master 1.107
-;
-; System call name/number master file.
-; Processed to created init_sysent.c, syscalls.c and syscall.h.
-
-; Columns: number [M]type nargs namespc name alt{name,tag,rtyp}/comments
-; number system call number, must be in order
-; type one of [M]STD, [M]OBSOL, [M]UNIMPL, [M]COMPAT, [M]CPT_NOA,
-; [M]LIBCOMPAT, [M]NODEF, [M]NOARGS, [M]NOPROTO, [M]NOIMPL,
-; [M]NOSTD
-; namespc one of POSIX, BSD, NOHIDE
-; name psuedo-prototype of syscall routine
-; If one of the following alts is different, then all appear:
-; altname name of system call if different
-; alttag name of args struct tag if different from [o]`name'"_args"
-; altrtyp return type if not int (bogus - syscalls always return int)
-; for UNIMPL/OBSOL, name continues with comments
-
-; types:
-; [M] e.g. like MSTD -- means the system call is MP-safe. If no
-; M prefix is used, the syscall wrapper will obtain the Giant
-; lock for the syscall.
-; STD always included
-; COMPAT included on COMPAT #ifdef
-; LIBCOMPAT included on COMPAT #ifdef, and placed in syscall.h
-; OBSOL obsolete, not included in system, only specifies name
-; UNIMPL not implemented, placeholder only
-; NOSTD implemented but as a lkm that can be statically
-; compiled in sysent entry will be filled with lkmsys
-; so the SYSCALL_MODULE macro works
-
-; #ifdef's, etc. may be included, and are copied to the output files.
-
-#include <sys/param.h>
-#include <sys/sysent.h>
-#include <sys/sysproto.h>
-#include <sys/mount.h>
-#include <amd64/ia32/ia32.h>
-#include <amd64/ia32/ia32_proto.h>
-
-; Reserved/unimplemented system calls in the range 0-150 inclusive
-; are reserved for use in future Berkeley releases.
-; Additional system calls implemented in vendor and other
-; redistributions should be placed in the reserved range at the end
-; of the current calls.
-
-0 MNOPROTO NOHIDE { int nosys(void); } syscall nosys_args int
-1 MNOPROTO NOHIDE { void sys_exit(int rval); } exit sys_exit_args void
-2 MNOPROTO POSIX { int fork(void); }
-3 MNOPROTO POSIX { ssize_t read(int fd, void *buf, size_t nbyte); }
-4 MNOPROTO POSIX { ssize_t write(int fd, const void *buf, size_t nbyte); }
-5 STD POSIX { int ia32_open(char *path, int flags, int mode); }
-; XXX should be { int open(const char *path, int flags, ...); }
-; but we're not ready for `const' or varargs.
-; XXX man page says `mode_t mode'.
-6 MNOPROTO POSIX { int close(int fd); }
-7 MSTD BSD { int ia32_wait4(int pid, int *status, int options, \
- struct rusage32 *rusage); }
-8 OBSOL BSD old creat
-9 NOPROTO POSIX { int link(char *path, char *link); }
-10 NOPROTO POSIX { int unlink(char *path); }
-11 OBSOL NOHIDE execv
-12 NOPROTO POSIX { int chdir(char *path); }
-13 NOPROTO BSD { int fchdir(int fd); }
-14 NOPROTO POSIX { int mknod(char *path, int mode, int dev); }
-15 NOPROTO POSIX { int chmod(char *path, int mode); }
-16 NOPROTO POSIX { int chown(char *path, int uid, int gid); }
-17 MNOPROTO BSD { int obreak(char *nsize); } break obreak_args int
-18 STD BSD { int ia32_getfsstat(struct statfs32 *buf, \
- long bufsize, int flags); }
-19 OBSOL POSIX olseek
-20 MNOPROTO POSIX { pid_t getpid(void); }
-21 NOPROTO BSD { int mount(char *type, char *path, int flags, \
- caddr_t data); }
-; XXX `path' should have type `const char *' but we're not ready for that.
-22 NOPROTO BSD { int unmount(char *path, int flags); }
-23 MNOPROTO POSIX { int setuid(uid_t uid); }
-24 MNOPROTO POSIX { uid_t getuid(void); }
-25 MNOPROTO POSIX { uid_t geteuid(void); }
-26 NOPROTO BSD { int ptrace(int req, pid_t pid, caddr_t addr, \
- int data); }
-27 UNIMPL BSD recvmsg
-28 MNOPROTO BSD { int sendmsg(int s, caddr_t msg, int flags); }
-29 MNOPROTO BSD { int recvfrom(int s, caddr_t buf, size_t len, \
- int flags, caddr_t from, int *fromlenaddr); }
-30 MNOPROTO BSD { int accept(int s, caddr_t name, int *anamelen); }
-31 MNOPROTO BSD { int getpeername(int fdes, caddr_t asa, int *alen); }
-32 MNOPROTO BSD { int getsockname(int fdes, caddr_t asa, int *alen); }
-33 STD POSIX { int ia32_access(char *path, int flags); }
-34 STD BSD { int ia32_chflags(char *path, int flags); }
-35 NOPROTO BSD { int fchflags(int fd, int flags); }
-36 NOPROTO BSD { int sync(void); }
-37 MNOPROTO POSIX { int kill(int pid, int signum); }
-38 UNIMPL POSIX ostat
-39 MNOPROTO POSIX { pid_t getppid(void); }
-40 UNIMPL POSIX olstat
-41 NOPROTO POSIX { int dup(u_int fd); }
-42 NOPROTO POSIX { int pipe(void); }
-43 MNOPROTO POSIX { gid_t getegid(void); }
-44 MNOPROTO BSD { int profil(caddr_t samples, size_t size, \
- size_t offset, u_int scale); }
-45 NOPROTO BSD { int ktrace(const char *fname, int ops, int facs, \
- int pid); }
-46 UNIMPL POSIX osigaction
-47 MNOPROTO POSIX { gid_t getgid(void); }
-48 UNIMPL POSIX osigprocmask
-49 MNOPROTO BSD { int getlogin(char *namebuf, u_int namelen); }
-50 MNOPROTO BSD { int setlogin(char *namebuf); }
-51 MNOPROTO BSD { int acct(char *path); }
-52 MNOPROTO POSIX { int sigpending(void); }
-53 STD BSD { int ia32_sigaltstack(struct sigaltstack32 *ss, struct sigaltstack32 *oss); }
-54 MNOPROTO POSIX { int ioctl(int fd, u_long com, caddr_t data); }
-55 MNOPROTO BSD { int reboot(int opt); }
-56 NOPROTO POSIX { int revoke(char *path); }
-57 NOPROTO POSIX { int symlink(char *path, char *link); }
-58 NOPROTO POSIX { int readlink(char *path, char *buf, int count); }
-59 STD POSIX { int ia32_execve(char *fname, u_int32_t *argv, u_int32_t *envv); }
-60 MNOPROTO POSIX { int umask(int newmask); } umask umask_args int
-61 NOPROTO BSD { int chroot(char *path); }
-62 OBSOL POSIX ofstat
-63 OBSOL BSD ogetkerninfo
-64 OBSOL BSD ogetpagesize
-65 OBSOL BSD omsync
-66 OBSOL BSD ovfork
-67 OBSOL NOHIDE vread
-68 OBSOL NOHIDE vwrite
-69 MNOPROTO BSD { int sbrk(int incr); }
-70 MNOPROTO BSD { int sstk(int incr); }
-71 OBSOL BSD ommap
-72 MNOPROTO BSD { int ovadvise(int anom); } vadvise ovadvise_args int
-73 MNOPROTO BSD { int munmap(void *addr, size_t len); }
-74 MNOPROTO BSD { int mprotect(const void *addr, size_t len, int prot); }
-75 MNOPROTO BSD { int madvise(void *addr, size_t len, int behav); }
-76 OBSOL NOHIDE vhangup
-77 OBSOL NOHIDE vlimit
-78 MNOPROTO BSD { int mincore(const void *addr, size_t len, \
- char *vec); }
-79 MNOPROTO POSIX { int getgroups(u_int gidsetsize, gid_t *gidset); }
-80 MNOPROTO POSIX { int setgroups(u_int gidsetsize, gid_t *gidset); }
-81 MNOPROTO POSIX { int getpgrp(void); }
-82 MNOPROTO POSIX { int setpgid(int pid, int pgid); }
-83 STD BSD { int ia32_setitimer(u_int which, \
- struct itimerval32 *itv, \
- struct itimerval32 *oitv); }
-84 OBSOL BSD owait
-85 OBSOL BSD oswapon
-86 OBSOL BSD ogetitimer
-87 OBSOL BSD ogethostname
-88 OBSOL BSD osethostname
-89 MNOPROTO BSD { int getdtablesize(void); }
-90 MNOPROTO POSIX { int dup2(u_int from, u_int to); }
-91 UNIMPL BSD getdopt
-92 MNOPROTO POSIX { int fcntl(int fd, int cmd, long arg); }
-; XXX should be { int fcntl(int fd, int cmd, ...); }
-; but we're not ready for varargs.
-; XXX man page says `int arg' too.
-93 STD BSD { int ia32_select(int nd, fd_set *in, fd_set *ou, \
- fd_set *ex, struct timeval32 *tv); }
-; XXX need to override for big-endian - little-endian should work fine.
-94 UNIMPL BSD setdopt
-95 NOPROTO POSIX { int fsync(int fd); }
-96 MNOPROTO BSD { int setpriority(int which, int who, int prio); }
-97 MNOPROTO BSD { int socket(int domain, int type, int protocol); }
-98 MNOPROTO BSD { int connect(int s, caddr_t name, int namelen); }
-99 MNOPROTO BSD { int accept(int s, caddr_t name, int *anamelen); } \
- accept accept_args int
-100 MNOPROTO BSD { int getpriority(int which, int who); }
-101 OBSOL BSD osend
-102 OBSOL BSD orecv
-103 OBSOL BSD osigreturn
-104 MNOPROTO BSD { int bind(int s, caddr_t name, int namelen); }
-105 MNOPROTO BSD { int setsockopt(int s, int level, int name, \
- caddr_t val, int valsize); }
-106 MNOPROTO BSD { int listen(int s, int backlog); }
-107 OBSOL NOHIDE vtimes
-108 OBSOL BSD osigvec
-109 OBSOL BSD osigblock
-110 OBSOL BSD osigsetmask
-111 OBSOL POSIX osigsuspend
-112 OBSOL BSD osigstack
-113 OBSOL BSD orecvmsg
-114 OBSOL BSD osendmsg
-115 OBSOL NOHIDE vtrace
-116 STD BSD { int ia32_gettimeofday(struct timeval32 *tp, \
- struct timezone *tzp); }
-117 STD BSD { int ia32_getrusage(int who, struct rusage32 *rusage); }
-118 MNOPROTO BSD { int getsockopt(int s, int level, int name, \
- caddr_t val, int *avalsize); }
-119 UNIMPL NOHIDE resuba (BSD/OS 2.x)
-120 STD BSD { int ia32_readv(int fd, struct iovec32 *iovp, u_int iovcnt); }
-121 STD BSD { int ia32_writev(int fd, struct iovec32 *iovp, \
- u_int iovcnt); }
-122 STD BSD { int ia32_settimeofday(struct timeval32 *tv, \
- struct timezone *tzp); }
-123 NOPROTO BSD { int fchown(int fd, int uid, int gid); }
-124 NOPROTO BSD { int fchmod(int fd, int mode); }
-125 MNOPROTO BSD { int recvfrom(int s, caddr_t buf, size_t len, \
- int flags, caddr_t from, int *fromlenaddr); } \
- recvfrom recvfrom_args int
-126 MNOPROTO BSD { int setreuid(int ruid, int euid); }
-127 MNOPROTO BSD { int setregid(int rgid, int egid); }
-128 NOPROTO POSIX { int rename(char *from, char *to); }
-129 OBSOL BSD otruncate
-130 OBSOL BSD ftruncate
-131 MNOPROTO BSD { int flock(int fd, int how); }
-132 NOPROTO POSIX { int mkfifo(char *path, int mode); }
-133 MNOPROTO BSD { int sendto(int s, caddr_t buf, size_t len, \
- int flags, caddr_t to, int tolen); }
-134 MNOPROTO BSD { int shutdown(int s, int how); }
-135 MNOPROTO BSD { int socketpair(int domain, int type, int protocol, \
- int *rsv); }
-136 NOPROTO POSIX { int mkdir(char *path, int mode); }
-137 NOPROTO POSIX { int rmdir(char *path); }
-138 STD BSD { int ia32_utimes(char *path, \
- struct timeval32 *tptr); }
-139 OBSOL NOHIDE 4.2 sigreturn
-140 STD BSD { int ia32_adjtime(struct timeval32 *delta, \
- struct timeval32 *olddelta); }
-141 OBSOL BSD ogetpeername
-142 OBSOL BSD ogethostid
-143 OBSOL BSD sethostid
-144 OBSOL BSD getrlimit
-145 OBSOL BSD setrlimit
-146 OBSOL BSD killpg
-147 MNOPROTO POSIX { int setsid(void); }
-148 NOPROTO BSD { int quotactl(char *path, int cmd, int uid, \
- caddr_t arg); }
-149 OBSOL BSD oquota
-150 OBSOL BSD ogetsockname
-
-; Syscalls 151-180 inclusive are reserved for vendor-specific
-; system calls. (This includes various calls added for compatibity
-; with other Unix variants.)
-; Some of these calls are now supported by BSD...
-151 UNIMPL NOHIDE sem_lock (BSD/OS 2.x)
-152 UNIMPL NOHIDE sem_wakeup (BSD/OS 2.x)
-153 UNIMPL NOHIDE asyncdaemon (BSD/OS 2.x)
-154 UNIMPL NOHIDE nosys
-; 155 is initialized by the NFS code, if present.
-155 UNIMPL NOHIDE nfssvc
-156 NOPROTO BSD { int getdirentries(int fd, char *buf, u_int count, \
- long *basep); }
-157 STD BSD { int ia32_statfs(char *path, struct statfs32 *buf); }
-158 STD BSD { int ia32_fstatfs(int fd, struct statfs32 *buf); }
-159 UNIMPL NOHIDE nosys
-160 UNIMPL NOHIDE nosys
-161 NOPROTO BSD { int getfh(char *fname, struct fhandle *fhp); }
-162 MNOPROTO BSD { int getdomainname(char *domainname, int len); }
-163 MNOPROTO BSD { int setdomainname(char *domainname, int len); }
-164 MNOPROTO BSD { int uname(struct utsname *name); }
-165 NOPROTO BSD { int sysarch(int op, char *parms); }
-166 MNOPROTO BSD { int rtprio(int function, pid_t pid, \
- struct rtprio *rtp); }
-167 UNIMPL NOHIDE nosys
-168 UNIMPL NOHIDE nosys
-169 STD BSD { int ia32_semsys(int which, int a2, int a3, int a4, \
- int a5); }
-170 STD BSD { int ia32_msgsys(int which, int a2, int a3, int a4, \
- int a5, int a6); }
-171 STD BSD { int ia32_shmsys(int which, int a2, int a3, int a4); }
-172 UNIMPL NOHIDE nosys
-173 STD POSIX { ssize_t ia32_pread(int fd, void *buf, size_t nbyte, \
- int pad, u_int32_t offsetlo, u_int32_t offsethi); }
-; XXX note - bigendian is different
-174 STD POSIX { ssize_t ia32_pwrite(int fd, const void *buf, \
- size_t nbyte, int pad, u_int32_t offsetlo, \
- u_int32_t offsethi); }
-; XXX note - bigendian is different
-175 UNIMPL NOHIDE nosys
-176 MNOPROTO BSD { int ntp_adjtime(struct timex *tp); }
-177 UNIMPL NOHIDE sfork (BSD/OS 2.x)
-178 UNIMPL NOHIDE getdescriptor (BSD/OS 2.x)
-179 UNIMPL NOHIDE setdescriptor (BSD/OS 2.x)
-180 UNIMPL NOHIDE nosys
-
-; Syscalls 181-199 are used by/reserved for BSD
-181 MNOPROTO POSIX { int setgid(gid_t gid); }
-182 MNOPROTO BSD { int setegid(gid_t egid); }
-183 MNOPROTO BSD { int seteuid(uid_t euid); }
-184 UNIMPL BSD lfs_bmapv
-185 UNIMPL BSD lfs_markv
-186 UNIMPL BSD lfs_segclean
-187 UNIMPL BSD lfs_segwait
-188 STD POSIX { int ia32_stat(char *path, struct stat32 *ub); }
-189 STD POSIX { int ia32_fstat(int fd, struct stat32 *ub); }
-190 STD POSIX { int ia32_lstat(char *path, struct stat32 *ub); }
-191 NOPROTO POSIX { int pathconf(char *path, int name); }
-192 MNOPROTO POSIX { int fpathconf(int fd, int name); }
-193 UNIMPL NOHIDE nosys
-194 MNOPROTO BSD { int getrlimit(u_int which, \
- struct rlimit *rlp); } \
- getrlimit __getrlimit_args int
-195 MNOPROTO BSD { int setrlimit(u_int which, \
- struct rlimit *rlp); } \
- setrlimit __setrlimit_args int
-196 NOPROTO BSD { int getdirentries(int fd, char *buf, u_int count, \
- long *basep); }
-197 STD BSD { caddr_t ia32_mmap(caddr_t addr, size_t len, \
- int prot, int flags, int fd, int pad, \
- u_int32_t poslo, u_int32_t poshi); }
-198 NOPROTO NOHIDE { int nosys(void); } __syscall __syscall_args int
-; XXX note - bigendian is different
-199 STD POSIX { off_t ia32_lseek(int fd, int pad, \
- u_int32_t offsetlo, u_int32_t offsethi, \
- int whence); }
-; XXX note - bigendian is different
-200 STD BSD { int ia32_truncate(char *path, int pad, \
- u_int32_t lengthlo, u_int32_t lengthhi); }
-; XXX note - bigendian is different
-201 STD BSD { int ia32_ftruncate(int fd, int pad, \
- u_int32_t lengthlo, u_int32_t lengthhi); }
-202 MSTD BSD { int ia32_sysctl(int *name, u_int namelen, \
- void *old, u_int32_t *oldlenp, void *new, \
- u_int32_t newlen); }
-203 MNOPROTO BSD { int mlock(const void *addr, size_t len); }
-204 MNOPROTO BSD { int munlock(const void *addr, size_t len); }
-205 NOPROTO BSD { int undelete(char *path); }
-206 NOPROTO BSD { int futimes(int fd, struct timeval *tptr); }
-207 MNOPROTO BSD { int getpgid(pid_t pid); }
-208 UNIMPL NOHIDE newreboot (NetBSD)
-209 MNOPROTO BSD { int poll(struct pollfd *fds, u_int nfds, \
- int timeout); }
-
-;
-; The following are reserved for loadable syscalls
-;
-210 UNIMPL NOHIDE
-211 UNIMPL NOHIDE
-212 UNIMPL NOHIDE
-213 UNIMPL NOHIDE
-214 UNIMPL NOHIDE
-215 UNIMPL NOHIDE
-216 UNIMPL NOHIDE
-217 UNIMPL NOHIDE
-218 UNIMPL NOHIDE
-219 UNIMPL NOHIDE
-
-;
-; The following were introduced with NetBSD/4.4Lite-2
-; They are initialized by thier respective modules/sysinits
-220 MNOPROTO BSD { int __semctl(int semid, int semnum, int cmd, \
- union semun *arg); }
-221 MNOPROTO BSD { int semget(key_t key, int nsems, int semflg); }
-222 MNOPROTO BSD { int semop(int semid, struct sembuf *sops, \
- u_int nsops); }
-223 UNIMPL NOHIDE semconfig
-224 MNOPROTO BSD { int msgctl(int msqid, int cmd, \
- struct msqid_ds *buf); }
-225 MNOPROTO BSD { int msgget(key_t key, int msgflg); }
-226 MNOPROTO BSD { int msgsnd(int msqid, void *msgp, size_t msgsz, \
- int msgflg); }
-227 MNOPROTO BSD { int msgrcv(int msqid, void *msgp, size_t msgsz, \
- long msgtyp, int msgflg); }
-228 MNOPROTO BSD { int shmat(int shmid, void *shmaddr, int shmflg); }
-229 MNOPROTO BSD { int shmctl(int shmid, int cmd, \
- struct shmid_ds *buf); }
-230 MNOPROTO BSD { int shmdt(void *shmaddr); }
-231 MNOPROTO BSD { int shmget(key_t key, int size, int shmflg); }
-;
-232 MNOPROTO POSIX { int clock_gettime(clockid_t clock_id, \
- struct timespec *tp); }
-233 MNOPROTO POSIX { int clock_settime(clockid_t clock_id, \
- const struct timespec *tp); }
-234 MNOPROTO POSIX { int clock_getres(clockid_t clock_id, \
- struct timespec *tp); }
-235 UNIMPL NOHIDE timer_create
-236 UNIMPL NOHIDE timer_delete
-237 UNIMPL NOHIDE timer_settime
-238 UNIMPL NOHIDE timer_gettime
-239 UNIMPL NOHIDE timer_getoverrun
-240 MNOPROTO POSIX { int nanosleep(const struct timespec *rqtp, \
- struct timespec *rmtp); }
-241 UNIMPL NOHIDE nosys
-242 UNIMPL NOHIDE nosys
-243 UNIMPL NOHIDE nosys
-244 UNIMPL NOHIDE nosys
-245 UNIMPL NOHIDE nosys
-246 UNIMPL NOHIDE nosys
-247 UNIMPL NOHIDE nosys
-248 UNIMPL NOHIDE nosys
-249 UNIMPL NOHIDE nosys
-; syscall numbers initially used in OpenBSD
-250 MNOPROTO BSD { int minherit(void *addr, size_t len, int inherit); }
-251 MNOPROTO BSD { int rfork(int flags); }
-252 MNOPROTO BSD { int openbsd_poll(struct pollfd *fds, u_int nfds, \
- int timeout); }
-253 NOPROTO BSD { int issetugid(void); }
-254 NOPROTO BSD { int lchown(char *path, int uid, int gid); }
-255 UNIMPL NOHIDE nosys
-256 UNIMPL NOHIDE nosys
-257 UNIMPL NOHIDE nosys
-258 UNIMPL NOHIDE nosys
-259 UNIMPL NOHIDE nosys
-260 UNIMPL NOHIDE nosys
-261 UNIMPL NOHIDE nosys
-262 UNIMPL NOHIDE nosys
-263 UNIMPL NOHIDE nosys
-264 UNIMPL NOHIDE nosys
-265 UNIMPL NOHIDE nosys
-266 UNIMPL NOHIDE nosys
-267 UNIMPL NOHIDE nosys
-268 UNIMPL NOHIDE nosys
-269 UNIMPL NOHIDE nosys
-270 UNIMPL NOHIDE nosys
-271 UNIMPL NOHIDE nosys
-272 NOPROTO BSD { int getdents(int fd, char *buf, size_t count); }
-273 UNIMPL NOHIDE nosys
-274 NOPROTO BSD { int lchmod(char *path, mode_t mode); }
-275 NOPROTO BSD { int lchown(char *path, uid_t uid, gid_t gid); } netbsd_lchown lchown_args int
-276 NOPROTO BSD { int lutimes(char *path, struct timeval *tptr); }
-277 MNOPROTO BSD { int msync(void *addr, size_t len, int flags); } netbsd_msync msync_args int
-278 NOPROTO BSD { int nstat(char *path, struct nstat *ub); }
-279 MNOPROTO BSD { int nfstat(int fd, struct nstat *sb); }
-280 NOPROTO BSD { int nlstat(char *path, struct nstat *ub); }
-281 UNIMPL NOHIDE nosys
-282 UNIMPL NOHIDE nosys
-283 UNIMPL NOHIDE nosys
-284 UNIMPL NOHIDE nosys
-285 UNIMPL NOHIDE nosys
-286 UNIMPL NOHIDE nosys
-287 UNIMPL NOHIDE nosys
-288 UNIMPL NOHIDE nosys
-289 UNIMPL NOHIDE nosys
-290 UNIMPL NOHIDE nosys
-291 UNIMPL NOHIDE nosys
-292 UNIMPL NOHIDE nosys
-293 UNIMPL NOHIDE nosys
-294 UNIMPL NOHIDE nosys
-295 UNIMPL NOHIDE nosys
-296 UNIMPL NOHIDE nosys
-; XXX 297 is 300 in NetBSD
-297 NOPROTO BSD { int fhstatfs(const struct fhandle *u_fhp, struct statfs *buf); }
-298 NOPROTO BSD { int fhopen(const struct fhandle *u_fhp, int flags); }
-299 NOPROTO BSD { int fhstat(const struct fhandle *u_fhp, struct stat *sb); }
-; syscall numbers for FreeBSD
-300 MNOPROTO BSD { int modnext(int modid); }
-301 MNOPROTO BSD { int modstat(int modid, struct module_stat* stat); }
-302 MNOPROTO BSD { int modfnext(int modid); }
-303 MNOPROTO BSD { int modfind(const char *name); }
-304 MNOPROTO BSD { int kldload(const char *file); }
-305 MNOPROTO BSD { int kldunload(int fileid); }
-306 MNOPROTO BSD { int kldfind(const char *file); }
-307 MNOPROTO BSD { int kldnext(int fileid); }
-308 MNOPROTO BSD { int kldstat(int fileid, struct kld_file_stat* stat); }
-309 MNOPROTO BSD { int kldfirstmod(int fileid); }
-310 MNOPROTO BSD { int getsid(pid_t pid); }
-311 MNOPROTO BSD { int setresuid(uid_t ruid, uid_t euid, uid_t suid); }
-312 MNOPROTO BSD { int setresgid(gid_t rgid, gid_t egid, gid_t sgid); }
-313 OBSOL NOHIDE signanosleep
-314 UNIMPL NOHIDE aio_return
-315 UNIMPL NOHIDE aio_suspend
-316 UNIMPL NOHIDE aio_cancel
-317 UNIMPL NOHIDE aio_error
-318 UNIMPL NOHIDE aio_read
-319 UNIMPL NOHIDE aio_write
-320 UNIMPL NOHIDE lio_listio
-321 MNOPROTO BSD { int yield(void); }
-322 OBSOL NOHIDE thr_sleep
-323 OBSOL NOHIDE thr_wakeup
-324 MNOPROTO BSD { int mlockall(int how); }
-325 MNOPROTO BSD { int munlockall(void); }
-326 NOPROTO BSD { int __getcwd(u_char *buf, u_int buflen); }
-
-327 MNOPROTO POSIX { int sched_setparam (pid_t pid, const struct sched_param *param); }
-328 MNOPROTO POSIX { int sched_getparam (pid_t pid, struct sched_param *param); }
-
-329 MNOPROTO POSIX { int sched_setscheduler (pid_t pid, int policy, const struct sched_param *param); }
-330 MNOPROTO POSIX { int sched_getscheduler (pid_t pid); }
-
-331 MNOPROTO POSIX { int sched_yield (void); }
-332 MNOPROTO POSIX { int sched_get_priority_max (int policy); }
-333 MNOPROTO POSIX { int sched_get_priority_min (int policy); }
-334 MNOPROTO POSIX { int sched_rr_get_interval (pid_t pid, struct timespec *interval); }
-335 NOPROTO BSD { int utrace(const void *addr, size_t len); }
-; XXX note - bigendian is different
-336 MCOMPAT4 BSD { int ia32_sendfile(int fd, int s, u_int32_t offsetlo,\
- u_int32_t offsethi, size_t nbytes, \
- struct sf_hdtr *hdtr, off_t *sbytes, int flags); }
-337 NOPROTO BSD { int kldsym(int fileid, int cmd, void *data); }
-338 MNOPROTO BSD { int jail(struct jail *jail); }
-339 UNIMPL BSD pioctl
-340 MNOPROTO POSIX { int sigprocmask(int how, const sigset_t *set, \
- sigset_t *oset); }
-341 MNOPROTO POSIX { int sigsuspend(const sigset_t *sigmask); }
-342 COMPAT4 POSIX { int ia32_sigaction(int sig, \
- struct sigaction32 *act, \
- struct sigaction32 *oact); }
-343 MNOPROTO POSIX { int sigpending(sigset_t *set); }
-344 MCOMPAT4 BSD { int ia32_sigreturn(const struct __ucontext *sigcntxp); }
-345 UNIMPL NOHIDE sigtimedwait
-346 UNIMPL NOHIDE sigwaitinfo
-347 MNOPROTO BSD { int __acl_get_file(const char *path, \
- acl_type_t type, struct acl *aclp); }
-348 MNOPROTO BSD { int __acl_set_file(const char *path, \
- acl_type_t type, struct acl *aclp); }
-349 MNOPROTO BSD { int __acl_get_fd(int filedes, acl_type_t type, \
- struct acl *aclp); }
-350 MNOPROTO BSD { int __acl_set_fd(int filedes, acl_type_t type, \
- struct acl *aclp); }
-351 MNOPROTO BSD { int __acl_delete_file(const char *path, \
- acl_type_t type); }
-352 MNOPROTO BSD { int __acl_delete_fd(int filedes, acl_type_t type); }
-353 MNOPROTO BSD { int __acl_aclcheck_file(const char *path, \
- acl_type_t type, struct acl *aclp); }
-354 MNOPROTO BSD { int __acl_aclcheck_fd(int filedes, acl_type_t type, \
- struct acl *aclp); }
-355 NOPROTO BSD { int extattrctl(const char *path, int cmd, \
- const char *filename, int attrnamespace, \
- const char *attrname); }
-356 NOPROTO BSD { int extattr_set_file(const char *path, \
- int attrnamespace, const char *attrname, \
- void *data, size_t nbytes); }
-357 NOPROTO BSD { ssize_t extattr_get_file(const char *path, \
- int attrnamespace, const char *attrname, \
- void *data, size_t nbytes); }
-358 NOPROTO BSD { int extattr_delete_file(const char *path, \
- int attrnamespace, const char *attrname); }
-359 UNIMPL NOHIDE aio_waitcomplete
-360 MNOPROTO BSD { int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid); }
-361 MNOPROTO BSD { int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid); }
-362 MNOPROTO BSD { int kqueue(void); }
-363 MSTD BSD { int ia32_kevent(int fd, \
- const struct kevent *changelist, int nchanges, \
- struct kevent *eventlist, int nevents, \
- const struct timespec *timeout); }
-364 UNIMPL NOHIDE __cap_get_proc
-365 UNIMPL NOHIDE __cap_set_proc
-366 UNIMPL NOHIDE __cap_get_fd
-367 UNIMPL NOHIDE __cap_get_file
-368 UNIMPL NOHIDE __cap_set_fd
-369 UNIMPL NOHIDE __cap_set_file
-370 UNIMPL NOHIDE lkmressys
-371 NOPROTO BSD { int extattr_set_fd(int fd, int attrnamespace, \
- const char *attrname, void *data, \
- size_t nbytes); }
-372 NOPROTO BSD { ssize_t extattr_get_fd(int fd, int attrnamespace, \
- const char *attrname, void *data, size_t nbytes); }
-373 NOPROTO BSD { int extattr_delete_fd(int fd, int attrnamespace, \
- const char *attrname); }
-374 MNOPROTO BSD { int __setugid(int flag); }
-375 UNIMPL BSD nfsclnt
-376 NOPROTO BSD { int eaccess(char *path, int flags); }
-377 UNIMPL BSD afs_syscall
-378 NOPROTO BSD { int nmount(struct iovec *iovp, unsigned int iovcnt, \
- int flags); }
-379 NOPROTO BSD { int kse_exit(void); }
-380 NOPROTO BSD { int kse_wakeup(struct kse_mailbox *mbx); }
-381 NOPROTO BSD { int kse_create(struct kse_mailbox *mbx, \
- int newgroup); }
-382 NOPROTO BSD { int kse_thr_interrupt(struct kse_thr_mailbox *tmbx); }
-383 NOPROTO BSD { int kse_release(void); }
-384 UNIMPL BSD __mac_get_proc
-385 UNIMPL BSD __mac_set_proc
-386 UNIMPL BSD __mac_get_fd
-387 UNIMPL BSD __mac_get_file
-388 UNIMPL BSD __mac_set_fd
-389 UNIMPL BSD __mac_set_file
-390 NOPROTO BSD { int kenv(int what, const char *name, char *value, \
- int len); }
-391 NOPROTO BSD { int lchflags(const char *path, int flags); }
-392 NOPROTO BSD { int uuidgen(struct uuid *store, int count); }
-393 MSTD BSD { int ia32_sendfile(int fd, int s, u_int32_t offsetlo, \
- u_int32_t offsethi, size_t nbytes, \
- struct sf_hdtr *hdtr, off_t *sbytes, int flags); }
-394 UNIMPL NOHIDE mac_syscall
-395 UNIMPL NOHIDE nosys
-396 UNIMPL NOHIDE nosys
-397 UNIMPL NOHIDE nosys
-398 UNIMPL NOHIDE nosys
-399 UNIMPL NOHIDE nosys
-400 UNIMPL NOHIDE ksem_close
-401 UNIMPL NOHIDE ksem_post
-402 UNIMPL NOHIDE ksem_wait
-403 UNIMPL NOHIDE ksem_trywait
-404 UNIMPL NOHIDE ksem_init
-405 UNIMPL NOHIDE ksem_open
-406 UNIMPL NOHIDE ksem_unlink
-407 UNIMPL NOHIDE ksem_getvalue
-408 UNIMPL NOHIDE ksem_destroy
-409 UNIMPL BSD __mac_get_pid
-410 UNIMPL BSD __mac_get_link
-411 UNIMPL BSD __mac_set_link
-412 UNIMPL BSD extattr_set_link
-413 UNIMPL BSD extattr_get_link
-414 UNIMPL BSD extattr_delete_link
-415 UNIMPL BSD __mac_execve
-416 MSTD BSD { int ia32_sigreturn(const struct ia32_ucontext *sigcntxp); }
-417 STD POSIX { int ia32_sigaction(int sig, \
- struct sigaction32 *act, \
- struct sigaction32 *oact); }
-418 UNIMPL BSD __xstat
-419 UNIMPL BSD __xfstat
-420 UNIMPL BSD __xlstat
-421 UNIMPL BSD getcontext
-422 UNIMPL BSD setcontext
-423 UNIMPL BSD swapcontext
-424 UNIMPL BSD swapoff
-425 UNIMPL BSD __acl_get_link
-426 UNIMPL BSD __acl_set_link
-427 UNIMPL BSD __acl_delete_link
-428 UNIMPL BSD __acl_aclcheck_link
-429 UNIMPL NOHIDE sigwait
-430 MNOPROTO BSD { int thr_create(ucontext_t *ctx, thr_id_t *id, \
- int flag s); }
-431 MNOPROTO BSD { void thr_exit(void); }
-432 MNOPROTO BSD { int thr_self(thr_id_t *id); }
-433 MNOPROTO BSD { int thr_kill(thr_id_t id, int sig); }
-434 MNOPROTO BSD { int _umtx_lock(struct umtx *umtx); }
-435 MNOPROTO BSD { int _umtx_unlock(struct umtx *umtx); }
-436 MNOPROTO BSD { int jail_attach(int jid); }
-
diff --git a/sys/compat/ia32/ia32_genassym.c b/sys/compat/ia32/ia32_genassym.c
deleted file mode 100644
index 2134a4477c45..000000000000
--- a/sys/compat/ia32/ia32_genassym.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* $FreeBSD$ */
-
-#include "opt_compat.h"
-
-#include <sys/param.h>
-#include <sys/assym.h>
-#include <sys/systm.h>
-#include <sys/signal.h>
-
-#include <amd64/ia32/ia32_signal.h>
-
-ASSYM(IA32_SIGF_HANDLER, offsetof(struct ia32_sigframe, sf_ah));
-ASSYM(IA32_SIGF_UC, offsetof(struct ia32_sigframe, sf_uc));
-ASSYM(IA32_UC_GS, offsetof(struct ia32_ucontext, uc_mcontext.mc_gs));
-ASSYM(IA32_UC_FS, offsetof(struct ia32_ucontext, uc_mcontext.mc_fs));
-ASSYM(IA32_UC_ES, offsetof(struct ia32_ucontext, uc_mcontext.mc_es));
-ASSYM(IA32_UC_DS, offsetof(struct ia32_ucontext, uc_mcontext.mc_ds));
-#ifdef COMPAT_FREEBSD4
-ASSYM(IA32_SIGF_UC4, offsetof(struct ia32_sigframe, sf_uc));
-ASSYM(IA32_UC4_GS, offsetof(struct ia32_ucontext4, uc_mcontext.mc_gs));
-ASSYM(IA32_UC4_FS, offsetof(struct ia32_ucontext4, uc_mcontext.mc_fs));
-ASSYM(IA32_UC4_ES, offsetof(struct ia32_ucontext4, uc_mcontext.mc_es));
-ASSYM(IA32_UC4_DS, offsetof(struct ia32_ucontext4, uc_mcontext.mc_ds));
-#endif
diff --git a/sys/compat/ia32/ia32_signal.h b/sys/compat/ia32/ia32_signal.h
deleted file mode 100644
index f251e72fb33c..000000000000
--- a/sys/compat/ia32/ia32_signal.h
+++ /dev/null
@@ -1,164 +0,0 @@
-/*-
- * Copyright (c) 1999 Marcel Moolenaar
- * Copyright (c) 2003 Peter Wemm
- * 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
- * in this position and unchanged.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-struct ia32_sigaltstack {
- u_int32_t ss_sp; /* signal stack base */
- u_int32_t ss_size; /* signal stack length */
- int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */
-};
-
-/* XXX should be 640 bytes long; check and see if __packed is needed */
-struct ia32_mcontext {
- int mc_onstack; /* XXX - sigcontext compat. */
- int mc_gs; /* machine state (struct trapframe) */
- int mc_fs;
- int mc_es;
- int mc_ds;
- int mc_edi;
- int mc_esi;
- int mc_ebp;
- int mc_isp;
- int mc_ebx;
- int mc_edx;
- int mc_ecx;
- int mc_eax;
- int mc_trapno;
- int mc_err;
- int mc_eip;
- int mc_cs;
- int mc_eflags;
- int mc_esp;
- int mc_ss;
- int mc_len; /* sizeof(struct ia32_mcontext) */
- /* We use the same values for fpformat and ownedfp */
- int mc_fpformat;
- int mc_ownedfp;
- int mc_spare1[1]; /* align next field to 16 bytes */
- /*
- * See <machine/npx.h> for the internals of mc_fpstate[].
- */
- int mc_fpstate[128] __aligned(16);
- int mc_spare2[8];
-};
-
-/* XXX should be 704 bytes long; check and see if __packed is needed */
-struct ia32_ucontext {
- sigset_t uc_sigmask;
- struct ia32_mcontext uc_mcontext;
- u_int32_t uc_link;
- struct ia32_sigaltstack uc_stack;
- int uc_flags;
- int __spare__[4];
-};
-
-
-#if defined(COMPAT_FREEBSD4)
-struct ia32_mcontext4 {
- int mc_onstack; /* XXX - sigcontext compat. */
- int mc_gs; /* machine state (struct trapframe) */
- int mc_fs;
- int mc_es;
- int mc_ds;
- int mc_edi;
- int mc_esi;
- int mc_ebp;
- int mc_isp;
- int mc_ebx;
- int mc_edx;
- int mc_ecx;
- int mc_eax;
- int mc_trapno;
- int mc_err;
- int mc_eip;
- int mc_cs;
- int mc_eflags;
- int mc_esp;
- int mc_ss;
- int mc_fpregs[28];
- int __spare__[17];
-};
-
-struct ia32_ucontext4 {
- sigset_t uc_sigmask;
- struct ia32_mcontext4 uc_mcontext;
- u_int32_t uc_link;
- struct ia32_sigaltstack uc_stack;
- int __spare__[8];
-};
-#endif
-
-/*
- * Signal frames, arguments passed to application signal handlers.
- */
-union ia32_sigval {
- int sigval_int;
- u_int32_t sigval_ptr;
-};
-struct ia32_siginfo {
- int si_signo; /* signal number */
- int si_errno; /* errno association */
- int si_code; /* signal code */
- int32_t si_pid; /* sending process */
- u_int32_t si_uid; /* sender's ruid */
- int si_status; /* exit value */
- u_int32_t si_addr; /* faulting instruction */
- union ia32_sigval si_value; /* signal value */
- int32_t si_band; /* band event for SIGPOLL */
- int __spare__[7]; /* gimme some slack */
-};
-
-#ifdef COMPAT_FREEBSD4
-struct ia32_sigframe4 {
- u_int32_t sf_signum;
- u_int32_t sf_siginfo; /* code or pointer to sf_si */
- u_int32_t sf_ucontext; /* points to sf_uc */
- u_int32_t sf_addr; /* undocumented 4th arg */
- u_int32_t sf_ah; /* action/handler pointer */
- struct ia32_ucontext4 sf_uc; /* = *sf_ucontext */
- struct ia32_siginfo sf_si; /* = *sf_siginfo (SA_SIGINFO case) */
-};
-#endif
-
-struct ia32_sigframe {
- u_int32_t sf_signum;
- u_int32_t sf_siginfo; /* code or pointer to sf_si */
- u_int32_t sf_ucontext; /* points to sf_uc */
- u_int32_t sf_addr; /* undocumented 4th arg */
- u_int32_t sf_ah; /* action/handler pointer */
- struct ia32_ucontext sf_uc; /* = *sf_ucontext */
- struct ia32_siginfo sf_si; /* = *sf_siginfo (SA_SIGINFO case) */
-};
-
-extern char ia32_sigcode[];
-extern char freebsd4_ia32_sigcode[];
-extern int sz_ia32_sigcode;
-extern int sz_freebsd4_ia32_sigcode;
-extern void ia32_sendsig(sig_t, int, sigset_t *, u_long);
diff --git a/sys/compat/ia32/ia32_sigtramp.S b/sys/compat/ia32/ia32_sigtramp.S
deleted file mode 100644
index 2e9f73d41bce..000000000000
--- a/sys/compat/ia32/ia32_sigtramp.S
+++ /dev/null
@@ -1,87 +0,0 @@
-/*-
- * Copyright (c) 2003 Peter Wemm
- * 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$
- */
-
-#include "opt_compat.h"
-
-#include <machine/asmacros.h>
-#include <sys/syscall.h>
-
-#include "ia32_assym.h"
-
- .text
- .code32
-/*
- * Signal trampoline, copied to top of user stack
- */
- ALIGN_TEXT
- .globl ia32_sigcode
-ia32_sigcode:
- calll *IA32_SIGF_HANDLER(%esp)
- leal IA32_SIGF_UC(%esp),%eax /* get ucontext */
- pushl %eax
- movl IA32_UC_GS(%eax),%gs /* restore %gs */
- movl IA32_UC_FS(%eax),%fs /* restore %fs */
- movl IA32_UC_ES(%eax),%es /* restore %es */
- movl IA32_UC_DS(%eax),%ds /* restore %ds */
- movl $SYS_sigreturn,%eax
- pushl %eax /* junk to fake return addr. */
- int $0x80 /* enter kernel with args */
- /* on stack */
-1:
- jmp 1b
-
-#ifdef COMPAT_FREEBSD4
- ALIGN_TEXT
-freebsd4_ia32_sigcode:
- calll *IA32_SIGF_HANDLER(%esp)
- leal IA32_SIGF_UC4(%esp),%eax/* get ucontext */
- pushl %eax
- movl IA32_UC4_GS(%eax),%gs /* restore %gs */
- movl IA32_UC4_FS(%eax),%fs /* restore %fs */
- movl IA32_UC4_ES(%eax),%es /* restore %es */
- movl IA32_UC4_DS(%eax),%ds /* restore %ds */
- movl $344,%eax /* 4.x SYS_sigreturn */
- pushl %eax /* junk to fake return addr. */
- int $0x80 /* enter kernel with args */
- /* on stack */
-1:
- jmp 1b
-#endif
-
- ALIGN_TEXT
-esigcode:
-
- .data
- .globl sz_ia32_sigcode
-sz_ia32_sigcode:
- .long esigcode-ia32_sigcode
-#ifdef COMPAT_FREEBSD4
- .globl sz_freebsd4_ia32_sigcode
-sz_freebsd4_ia32_sigcode:
- .long esigcode-freebsd4_ia32_sigcode
-#endif
diff --git a/sys/compat/ia32/ia32_sysvec.c b/sys/compat/ia32/ia32_sysvec.c
deleted file mode 100644
index f921ff1c96ea..000000000000
--- a/sys/compat/ia32/ia32_sysvec.c
+++ /dev/null
@@ -1,282 +0,0 @@
-/*-
- * Copyright (c) 2002 Doug Rabson
- * Copyright (c) 2003 Peter Wemm
- * 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$
- */
-
-#include "opt_compat.h"
-
-#define __ELF_WORD_SIZE 32
-
-#include <sys/param.h>
-#include <sys/exec.h>
-#include <sys/fcntl.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/mman.h>
-#include <sys/namei.h>
-#include <sys/pioctl.h>
-#include <sys/proc.h>
-#include <sys/procfs.h>
-#include <sys/resourcevar.h>
-#include <sys/systm.h>
-#include <sys/signalvar.h>
-#include <sys/stat.h>
-#include <sys/sx.h>
-#include <sys/syscall.h>
-#include <sys/sysctl.h>
-#include <sys/sysent.h>
-#include <sys/vnode.h>
-#include <sys/imgact_elf.h>
-
-#include <vm/vm.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-#include <vm/vm_extern.h>
-
-#include <amd64/ia32/ia32_util.h>
-#include <amd64/ia32/ia32_proto.h>
-#include <amd64/ia32/ia32_signal.h>
-#include <machine/psl.h>
-#include <machine/segments.h>
-#include <machine/specialreg.h>
-#include <machine/frame.h>
-#include <machine/md_var.h>
-#include <machine/pcb.h>
-#include <machine/cpufunc.h>
-
-static register_t *ia32_copyout_strings(struct image_params *imgp);
-static void ia32_setregs(struct thread *td, u_long entry, u_long stack,
- u_long ps_strings);
-
-extern struct sysent ia32_sysent[];
-
-struct sysentvec ia32_freebsd_sysvec = {
- SYS_MAXSYSCALL,
- ia32_sysent,
- 0,
- 0,
- NULL,
- 0,
- NULL,
- NULL,
- elf32_freebsd_fixup,
- ia32_sendsig,
- ia32_sigcode,
- &sz_ia32_sigcode,
- NULL,
- "FreeBSD ELF32",
- elf32_coredump,
- NULL,
- MINSIGSTKSZ,
- PAGE_SIZE,
- 0,
- IA32_USRSTACK,
- IA32_USRSTACK,
- IA32_PS_STRINGS,
- VM_PROT_ALL,
- ia32_copyout_strings,
- ia32_setregs
-};
-
-
-
-static Elf32_Brandinfo ia32_brand_info = {
- ELFOSABI_FREEBSD,
- EM_386,
- "FreeBSD",
- "/compat/ia32",
- "/usr/libexec/ld-elf.so.1",
- &ia32_freebsd_sysvec
- };
-
-SYSINIT(ia32, SI_SUB_EXEC, SI_ORDER_ANY,
- (sysinit_cfunc_t) elf32_insert_brand_entry,
- &ia32_brand_info);
-
-extern int _ucode32sel, _udatasel;
-
-static register_t *
-ia32_copyout_strings(struct image_params *imgp)
-{
- int argc, envc;
- u_int32_t *vectp;
- char *stringp, *destp;
- u_int32_t *stack_base;
- struct ia32_ps_strings *arginfo;
- int szsigcode;
-
- /*
- * Calculate string base and vector table pointers.
- * Also deal with signal trampoline code for this exec type.
- */
- arginfo = (struct ia32_ps_strings *)IA32_PS_STRINGS;
- szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
- destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
- roundup((ARG_MAX - imgp->stringspace), sizeof(char *));
-
- /*
- * install sigcode
- */
- if (szsigcode)
- copyout(imgp->proc->p_sysent->sv_sigcode,
- ((caddr_t)arginfo - szsigcode), szsigcode);
-
- /*
- * If we have a valid auxargs ptr, prepare some room
- * on the stack.
- */
- if (imgp->auxargs) {
- /*
- * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
- * lower compatibility.
- */
- imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
- : (AT_COUNT * 2);
- /*
- * The '+ 2' is for the null pointers at the end of each of
- * the arg and env vector sets,and imgp->auxarg_size is room
- * for argument of Runtime loader.
- */
- vectp = (u_int32_t *) (destp - (imgp->argc + imgp->envc + 2 +
- imgp->auxarg_size) * sizeof(u_int32_t));
-
- } else
- /*
- * The '+ 2' is for the null pointers at the end of each of
- * the arg and env vector sets
- */
- vectp = (u_int32_t *)
- (destp - (imgp->argc + imgp->envc + 2) * sizeof(u_int32_t));
-
- /*
- * vectp also becomes our initial stack base
- */
- stack_base = vectp;
-
- stringp = imgp->stringbase;
- argc = imgp->argc;
- envc = imgp->envc;
- /*
- * Copy out strings - arguments and environment.
- */
- copyout(stringp, destp, ARG_MAX - imgp->stringspace);
-
- /*
- * Fill in "ps_strings" struct for ps, w, etc.
- */
- suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
- suword32(&arginfo->ps_nargvstr, argc);
-
- /*
- * Fill in argument portion of vector table.
- */
- for (; argc > 0; --argc) {
- suword32(vectp++, (u_int32_t)(intptr_t)destp);
- while (*stringp++ != 0)
- destp++;
- destp++;
- }
-
- /* a null vector table pointer separates the argp's from the envp's */
- suword32(vectp++, 0);
-
- suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
- suword32(&arginfo->ps_nenvstr, envc);
-
- /*
- * Fill in environment portion of vector table.
- */
- for (; envc > 0; --envc) {
- suword32(vectp++, (u_int32_t)(intptr_t)destp);
- while (*stringp++ != 0)
- destp++;
- destp++;
- }
-
- /* end of vector table is a null pointer */
- suword32(vectp, 0);
-
- return ((register_t *)stack_base);
-}
-
-/*
- * Clear registers on exec
- */
-void
-ia32_setregs(td, entry, stack, ps_strings)
- struct thread *td;
- u_long entry;
- u_long stack;
- u_long ps_strings;
-{
- struct trapframe *regs = td->td_frame;
- struct pcb *pcb = td->td_pcb;
-
- wrmsr(MSR_FSBASE, 0);
- wrmsr(MSR_KGSBASE, 0); /* User value while we're in the kernel */
- pcb->pcb_fsbase = 0;
- pcb->pcb_gsbase = 0;
- load_ds(_udatasel);
- load_es(_udatasel);
- load_fs(_udatasel);
- load_gs(_udatasel);
- pcb->pcb_ds = _udatasel;
- pcb->pcb_es = _udatasel;
- pcb->pcb_fs = _udatasel;
- pcb->pcb_gs = _udatasel;
-
- bzero((char *)regs, sizeof(struct trapframe));
- regs->tf_rip = entry;
- regs->tf_rsp = stack;
- regs->tf_rflags = PSL_USER | (regs->tf_rflags & PSL_T);
- regs->tf_ss = _udatasel;
- regs->tf_cs = _ucode32sel;
- regs->tf_rbx = ps_strings;
-
- /*
- * Arrange to trap the next npx or `fwait' instruction (see npx.c
- * for why fwait must be trapped at least if there is an npx or an
- * emulator). This is mainly to handle the case where npx0 is not
- * configured, since the npx routines normally set up the trap
- * otherwise. It should be done only at boot time, but doing it
- * here allows modifying `npx_exists' for testing the emulator on
- * systems with an npx.
- */
- load_cr0(rcr0() | CR0_MP | CR0_TS);
-
- fpstate_drop(td);
-
- /* Return via doreti so that we can change to a different %cs */
- pcb->pcb_flags |= PCB_FULLCTX;
- td->td_retval[1] = 0;
-}
diff --git a/sys/compat/ia32/ia32_util.h b/sys/compat/ia32/ia32_util.h
deleted file mode 100644
index 64fa29320ca8..000000000000
--- a/sys/compat/ia32/ia32_util.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*-
- * Copyright (c) 1998-1999 Andrew Gallatin
- * 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
- * in this position and unchanged.
- * 2. Redistributions in binary form must 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 withough specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-
-
-#include <sys/exec.h>
-#include <sys/sysent.h>
-#include <sys/cdefs.h>
-
-struct ia32_ps_strings {
- u_int32_t ps_argvstr; /* first of 0 or more argument strings */
- int ps_nargvstr; /* the number of argument strings */
- u_int32_t ps_envstr; /* first of 0 or more environment strings */
- int ps_nenvstr; /* the number of environment strings */
-};
-
-#define IA32_USRSTACK ((1ul << 32) - PAGE_SIZE)
-#define IA32_PS_STRINGS (IA32_USRSTACK - sizeof(struct ia32_ps_strings))
-
-static __inline caddr_t stackgap_init(void);
-static __inline void *stackgap_alloc(caddr_t *, size_t);
-
-static __inline caddr_t
-stackgap_init()
-{
-#define szsigcode (*(curproc->p_sysent->sv_szsigcode))
- return (caddr_t)(((caddr_t)IA32_PS_STRINGS) - szsigcode - SPARE_USRSPACE);
-#undef szsigcode
-}
-
-static __inline void *
-stackgap_alloc(sgp, sz)
- caddr_t *sgp;
- size_t sz;
-{
- void *p;
-
- p = (void *) *sgp;
- *sgp += ALIGN(sz);
- return p;
-}
-
-
-extern const char ia32_emul_path[];
-int ia32_emul_find(struct thread *, caddr_t *, const char *, char *,
- char **, int);
-
-#define CHECKALT(p, sgp, path, i) \
- do { \
- int _error; \
- \
- _error = ia32_emul_find(p, sgp, ia32_emul_path, path, \
- &path, i); \
- if (_error == EFAULT) \
- return (_error); \
- } while (0)
-
-#define CHECKALTEXIST(p, sgp, path) CHECKALT((p), (sgp), (path), 0)
-#define CHECKALTCREAT(p, sgp, path) CHECKALT((p), (sgp), (path), 1)
diff --git a/sys/compat/netbsd/dvcfg.h b/sys/compat/netbsd/dvcfg.h
deleted file mode 100644
index 5485f89faa43..000000000000
--- a/sys/compat/netbsd/dvcfg.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD$ */
-/*
- * [NetBSD for NEC PC98 series]
- * Copyright (c) 1996 NetBSD/pc98 porting staff.
- * 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.
- */
-/*
- * Copyright (c) 1996 Naofumi HONDA. All rights reserved.
- */
-
-#ifndef _I386_DVCFG_H_
-#define _I386_DVCFG_H_
-
-typedef void *dvcfg_hw_t;
-
-struct dvcfg_hwsel {
- int cfg_max;
-
- dvcfg_hw_t *cfg_sel;
-};
-
-#define DVCFG_MAJOR(dvcfg) (((u_int)(dvcfg)) >> 16)
-#define DVCFG_MINOR(dvcfg) (((u_int)(dvcfg)) & 0xffff)
-
-#define DVCFG_MKCFG(major, minor) ((((u_int)(major)) << 16) | ((minor) & 0xffff))
-
-#define DVCFG_HWSEL_SZ(array) (sizeof(array) / sizeof(dvcfg_hw_t))
-
-static __inline dvcfg_hw_t dvcfg_hw(struct dvcfg_hwsel *, u_int);
-
-static __inline dvcfg_hw_t
-dvcfg_hw(selp, num)
- struct dvcfg_hwsel *selp;
- u_int num;
-{
-
- return ((num >= selp->cfg_max) ? 0 : selp->cfg_sel[num]);
-}
-
-#define DVCFG_HW(SELP, NUM) dvcfg_hw((SELP), (NUM))
-#endif /* _I386_DVCFG_H_ */
diff --git a/sys/compat/netbsd/physio_proc.h b/sys/compat/netbsd/physio_proc.h
deleted file mode 100644
index 60033ca3e4e4..000000000000
--- a/sys/compat/netbsd/physio_proc.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* $FreeBSD$ */
-/* $NecBSD: physio_proc.h,v 3.4 1999/07/23 20:47:03 honda Exp $ */
-/* $NetBSD$ */
-
-/*
- * [NetBSD for NEC PC-98 series]
- * Copyright (c) 1998
- * NetBSD/pc98 porting staff. 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.
- */
-#ifndef _I386_PHYSIO_PROC_H_
-#define _I386_PHYSIO_PROC_H_
-#include <sys/queue.h>
-
-struct buf;
-
-struct physio_proc {
-};
-
-static __inline struct physio_proc *physio_proc_enter(struct buf *);
-static __inline void physio_proc_leave(struct physio_proc *);
-
-static __inline struct physio_proc *
-physio_proc_enter(bp)
- struct buf *bp;
-{
- return NULL;
-}
-
-static __inline void
-physio_proc_leave(pp)
- struct physio_proc *pp;
-{
-}
-#endif /* _I386_PHYSIO_PROC_H_ */
diff --git a/sys/contrib/dev/acpica/acdos16.h b/sys/contrib/dev/acpica/acdos16.h
deleted file mode 100644
index 435f2937f392..000000000000
--- a/sys/contrib/dev/acpica/acdos16.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/******************************************************************************
- *
- * Name: acdos16.h - DOS specific defines, etc.
- * $Revision: 2 $
- *
- *****************************************************************************/
-
-/******************************************************************************
- *
- * 1. Copyright Notice
- *
- * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
- * All rights reserved.
- *
- * 2. License
- *
- * 2.1. This is your license from Intel Corp. under its intellectual property
- * rights. You may have additional license terms from the party that provided
- * you this software, covering your right to use that party's intellectual
- * property rights.
- *
- * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
- * copy of the source code appearing in this file ("Covered Code") an
- * irrevocable, perpetual, worldwide license under Intel's copyrights in the
- * base code distributed originally by Intel ("Original Intel Code") to copy,
- * make derivatives, distribute, use and display any portion of the Covered
- * Code in any form, with the right to sublicense such rights; and
- *
- * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
- * license (with the right to sublicense), under only those claims of Intel
- * patents that are infringed by the Original Intel Code, to make, use, sell,
- * offer to sell, and import the Covered Code and derivative works thereof
- * solely to the minimum extent necessary to exercise the above copyright
- * license, and in no event shall the patent license extend to any additions
- * to or modifications of the Original Intel Code. No other license or right
- * is granted directly or by implication, estoppel or otherwise;
- *
- * The above copyright and patent license is granted only if the following
- * conditions are met:
- *
- * 3. Conditions
- *
- * 3.1. Redistribution of Source with Rights to Further Distribute Source.
- * Redistribution of source code of any substantial portion of the Covered
- * Code or modification with rights to further distribute source must include
- * the above Copyright Notice, the above License, this list of Conditions,
- * and the following Disclaimer and Export Compliance provision. In addition,
- * Licensee must cause all Covered Code to which Licensee contributes to
- * contain a file documenting the changes Licensee made to create that Covered
- * Code and the date of any change. Licensee must include in that file the
- * documentation of any changes made by any predecessor Licensee. Licensee
- * must include a prominent statement that the modification is derived,
- * directly or indirectly, from Original Intel Code.
- *
- * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
- * Redistribution of source code of any substantial portion of the Covered
- * Code or modification without rights to further distribute source must
- * include the following Disclaimer and Export Compliance provision in the
- * documentation and/or other materials provided with distribution. In
- * addition, Licensee may not authorize further sublicense of source of any
- * portion of the Covered Code, and must include terms to the effect that the
- * license from Licensee to its licensee is limited to the intellectual
- * property embodied in the software Licensee provides to its licensee, and
- * not to intellectual property embodied in modifications its licensee may
- * make.
- *
- * 3.3. Redistribution of Executable. Redistribution in executable form of any
- * substantial portion of the Covered Code or modification must reproduce the
- * above Copyright Notice, and the following Disclaimer and Export Compliance
- * provision in the documentation and/or other materials provided with the
- * distribution.
- *
- * 3.4. Intel retains all right, title, and interest in and to the Original
- * Intel Code.
- *
- * 3.5. Neither the name Intel nor any other trademark owned or controlled by
- * Intel shall be used in advertising or otherwise to promote the sale, use or
- * other dealings in products derived from or relating to the Covered Code
- * without prior written authorization from Intel.
- *
- * 4. Disclaimer and Export Compliance
- *
- * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
- * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
- * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
- * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
- * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
- * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
- * PARTICULAR PURPOSE.
- *
- * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
- * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
- * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
- * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
- * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
- * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
- * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
- * LIMITED REMEDY.
- *
- * 4.3. Licensee shall not export, either directly or indirectly, any of this
- * software or system incorporating such software without first obtaining any
- * required license or other approval from the U. S. Department of Commerce or
- * any other agency or department of the United States Government. In the
- * event Licensee exports any such software from the United States or
- * re-exports any such software from a foreign destination, Licensee shall
- * ensure that the distribution and export/re-export of the software is in
- * compliance with all laws, regulations, orders, or other restrictions of the
- * U.S. Export Administration Regulations. Licensee agrees that neither it nor
- * any of its subsidiaries will export/re-export any technical data, process,
- * software, or service, directly or indirectly, to any country for which the
- * United States government or any agency thereof requires an export license,
- * other governmental approval, or letter of assurance, without first obtaining
- * such license, approval or letter.
- *
- *****************************************************************************/
-
-#ifndef __ACDOS16_H__
-#define __ACDOS16_H__
-
-#define ACPI_USE_STANDARD_HEADERS
-#define ACPI_OS_NAME "MSDOS"
-
-/*
- * Calling conventions:
- *
- * ACPI_SYSTEM_XFACE - Interfaces to host OS (handlers, threads)
- * ACPI_EXTERNAL_XFACE - External ACPI interfaces
- * ACPI_INTERNAL_XFACE - Internal ACPI interfaces
- * ACPI_INTERNAL_VAR_XFACE - Internal variable-parameter list interfaces
- */
-#define ACPI_SYSTEM_XFACE __cdecl
-#define ACPI_EXTERNAL_XFACE
-#define ACPI_INTERNAL_XFACE
-#define ACPI_INTERNAL_VAR_XFACE __cdecl
-
-#define ACPI_ASM_MACROS
-#define BREAKPOINT3
-#define ACPI_DISABLE_IRQS()
-#define ACPI_ENABLE_IRQS()
-#define halt()
-#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq)
-#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq)
-
-
-
-/* This macro is used to tag functions as "printf-like" because
- * some compilers can catch printf format string problems. MSVC
- * doesn't, so this is proprocessed away.
- */
-#define ACPI_PRINTF_LIKE_FUNC
-
-#endif /* __ACDOS16_H__ */
diff --git a/sys/contrib/dev/acpica/actbl71.h b/sys/contrib/dev/acpica/actbl71.h
deleted file mode 100644
index 6a84009792ac..000000000000
--- a/sys/contrib/dev/acpica/actbl71.h
+++ /dev/null
@@ -1,238 +0,0 @@
-/******************************************************************************
- *
- * Name: actbl71.h - IA-64 Extensions to the ACPI Spec Rev. 0.71
- * This file includes tables specific to this
- * specification revision.
- * $Revision: 12 $
- *
- *****************************************************************************/
-
-/******************************************************************************
- *
- * 1. Copyright Notice
- *
- * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
- * All rights reserved.
- *
- * 2. License
- *
- * 2.1. This is your license from Intel Corp. under its intellectual property
- * rights. You may have additional license terms from the party that provided
- * you this software, covering your right to use that party's intellectual
- * property rights.
- *
- * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
- * copy of the source code appearing in this file ("Covered Code") an
- * irrevocable, perpetual, worldwide license under Intel's copyrights in the
- * base code distributed originally by Intel ("Original Intel Code") to copy,
- * make derivatives, distribute, use and display any portion of the Covered
- * Code in any form, with the right to sublicense such rights; and
- *
- * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
- * license (with the right to sublicense), under only those claims of Intel
- * patents that are infringed by the Original Intel Code, to make, use, sell,
- * offer to sell, and import the Covered Code and derivative works thereof
- * solely to the minimum extent necessary to exercise the above copyright
- * license, and in no event shall the patent license extend to any additions
- * to or modifications of the Original Intel Code. No other license or right
- * is granted directly or by implication, estoppel or otherwise;
- *
- * The above copyright and patent license is granted only if the following
- * conditions are met:
- *
- * 3. Conditions
- *
- * 3.1. Redistribution of Source with Rights to Further Distribute Source.
- * Redistribution of source code of any substantial portion of the Covered
- * Code or modification with rights to further distribute source must include
- * the above Copyright Notice, the above License, this list of Conditions,
- * and the following Disclaimer and Export Compliance provision. In addition,
- * Licensee must cause all Covered Code to which Licensee contributes to
- * contain a file documenting the changes Licensee made to create that Covered
- * Code and the date of any change. Licensee must include in that file the
- * documentation of any changes made by any predecessor Licensee. Licensee
- * must include a prominent statement that the modification is derived,
- * directly or indirectly, from Original Intel Code.
- *
- * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
- * Redistribution of source code of any substantial portion of the Covered
- * Code or modification without rights to further distribute source must
- * include the following Disclaimer and Export Compliance provision in the
- * documentation and/or other materials provided with distribution. In
- * addition, Licensee may not authorize further sublicense of source of any
- * portion of the Covered Code, and must include terms to the effect that the
- * license from Licensee to its licensee is limited to the intellectual
- * property embodied in the software Licensee provides to its licensee, and
- * not to intellectual property embodied in modifications its licensee may
- * make.
- *
- * 3.3. Redistribution of Executable. Redistribution in executable form of any
- * substantial portion of the Covered Code or modification must reproduce the
- * above Copyright Notice, and the following Disclaimer and Export Compliance
- * provision in the documentation and/or other materials provided with the
- * distribution.
- *
- * 3.4. Intel retains all right, title, and interest in and to the Original
- * Intel Code.
- *
- * 3.5. Neither the name Intel nor any other trademark owned or controlled by
- * Intel shall be used in advertising or otherwise to promote the sale, use or
- * other dealings in products derived from or relating to the Covered Code
- * without prior written authorization from Intel.
- *
- * 4. Disclaimer and Export Compliance
- *
- * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
- * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
- * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
- * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
- * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
- * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
- * PARTICULAR PURPOSE.
- *
- * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
- * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
- * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
- * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
- * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
- * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
- * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
- * LIMITED REMEDY.
- *
- * 4.3. Licensee shall not export, either directly or indirectly, any of this
- * software or system incorporating such software without first obtaining any
- * required license or other approval from the U. S. Department of Commerce or
- * any other agency or department of the United States Government. In the
- * event Licensee exports any such software from the United States or
- * re-exports any such software from a foreign destination, Licensee shall
- * ensure that the distribution and export/re-export of the software is in
- * compliance with all laws, regulations, orders, or other restrictions of the
- * U.S. Export Administration Regulations. Licensee agrees that neither it nor
- * any of its subsidiaries will export/re-export any technical data, process,
- * software, or service, directly or indirectly, to any country for which the
- * United States government or any agency thereof requires an export license,
- * other governmental approval, or letter of assurance, without first obtaining
- * such license, approval or letter.
- *
- *****************************************************************************/
-
-#ifndef __ACTBL71_H__
-#define __ACTBL71_H__
-
-
-/* 0.71 FADT AddressSpace data item bitmasks defines */
-/* If the associated bit is zero then it is in memory space else in io space */
-
-#define SMI_CMD_ADDRESS_SPACE 0x01
-#define PM1_BLK_ADDRESS_SPACE 0x02
-#define PM2_CNT_BLK_ADDRESS_SPACE 0x04
-#define PM_TMR_BLK_ADDRESS_SPACE 0x08
-#define GPE0_BLK_ADDRESS_SPACE 0x10
-#define GPE1_BLK_ADDRESS_SPACE 0x20
-
-/* Only for clarity in declarations */
-
-typedef UINT64 IO_ADDRESS;
-
-
-#pragma pack(1)
-typedef struct /* Root System Descriptor Pointer */
-{
- NATIVE_CHAR Signature [8]; /* contains "RSD PTR " */
- UINT8 Checksum; /* to make sum of struct == 0 */
- NATIVE_CHAR OemId [6]; /* OEM identification */
- UINT8 Reserved; /* Must be 0 for 1.0, 2 for 2.0 */
- UINT64 RsdtPhysicalAddress; /* 64-bit physical address of RSDT */
-} RSDP_DESCRIPTOR_REV071;
-
-
-/*****************************************/
-/* IA64 Extensions to ACPI Spec Rev 0.71 */
-/* for the Root System Description Table */
-/*****************************************/
-typedef struct
-{
- ACPI_TABLE_HEADER header; /* Table header */
- UINT32 ReservedPad; /* IA64 alignment, must be 0 */
- UINT64 TableOffsetEntry [1]; /* Array of pointers to other */
- /* tables' headers */
-} RSDT_DESCRIPTOR_REV071;
-
-
-/*******************************************/
-/* IA64 Extensions to ACPI Spec Rev 0.71 */
-/* for the Firmware ACPI Control Structure */
-/*******************************************/
-typedef struct
-{
- NATIVE_CHAR Signature[4]; /* signature "FACS" */
- UINT32 Length; /* length of structure, in bytes */
- UINT32 HardwareSignature; /* hardware configuration signature */
- UINT32 Reserved4; /* must be 0 */
- UINT64 FirmwareWakingVector; /* ACPI OS waking vector */
- UINT64 GlobalLock; /* Global Lock */
- UINT32_BIT S4Bios_f : 1; /* Indicates if S4BIOS support is present */
- UINT32_BIT Reserved1 : 31; /* must be 0 */
- UINT8 Reserved3 [28]; /* reserved - must be zero */
-
-} FACS_DESCRIPTOR_REV071;
-
-
-/******************************************/
-/* IA64 Extensions to ACPI Spec Rev 0.71 */
-/* for the Fixed ACPI Description Table */
-/******************************************/
-typedef struct
-{
- ACPI_TABLE_HEADER header; /* table header */
- UINT32 ReservedPad; /* IA64 alignment, must be 0 */
- UINT64 FirmwareCtrl; /* 64-bit Physical address of FACS */
- UINT64 Dsdt; /* 64-bit Physical address of DSDT */
- UINT8 Model; /* System Interrupt Model */
- UINT8 AddressSpace; /* Address Space Bitmask */
- UINT16 SciInt; /* System vector of SCI interrupt */
- UINT8 AcpiEnable; /* value to write to smi_cmd to enable ACPI */
- UINT8 AcpiDisable; /* value to write to smi_cmd to disable ACPI */
- UINT8 S4BiosReq; /* Value to write to SMI CMD to enter S4BIOS state */
- UINT8 Reserved2; /* reserved - must be zero */
- UINT64 SmiCmd; /* Port address of SMI command port */
- UINT64 Pm1aEvtBlk; /* Port address of Power Mgt 1a AcpiEvent Reg Blk */
- UINT64 Pm1bEvtBlk; /* Port address of Power Mgt 1b AcpiEvent Reg Blk */
- UINT64 Pm1aCntBlk; /* Port address of Power Mgt 1a Control Reg Blk */
- UINT64 Pm1bCntBlk; /* Port address of Power Mgt 1b Control Reg Blk */
- UINT64 Pm2CntBlk; /* Port address of Power Mgt 2 Control Reg Blk */
- UINT64 PmTmrBlk; /* Port address of Power Mgt Timer Ctrl Reg Blk */
- UINT64 Gpe0Blk; /* Port addr of General Purpose AcpiEvent 0 Reg Blk */
- UINT64 Gpe1Blk; /* Port addr of General Purpose AcpiEvent 1 Reg Blk */
- UINT8 Pm1EvtLen; /* Byte Length of ports at pm1X_evt_blk */
- UINT8 Pm1CntLen; /* Byte Length of ports at pm1X_cnt_blk */
- UINT8 Pm2CntLen; /* Byte Length of ports at pm2_cnt_blk */
- UINT8 PmTmLen; /* Byte Length of ports at pm_tm_blk */
- UINT8 Gpe0BlkLen; /* Byte Length of ports at gpe0_blk */
- UINT8 Gpe1BlkLen; /* Byte Length of ports at gpe1_blk */
- UINT8 Gpe1Base; /* offset in gpe model where gpe1 events start */
- UINT8 Reserved3; /* reserved */
- UINT16 Plvl2Lat; /* worst case HW latency to enter/exit C2 state */
- UINT16 Plvl3Lat; /* worst case HW latency to enter/exit C3 state */
- UINT8 DayAlrm; /* index to day-of-month alarm in RTC CMOS RAM */
- UINT8 MonAlrm; /* index to month-of-year alarm in RTC CMOS RAM */
- UINT8 Century; /* index to century in RTC CMOS RAM */
- UINT8 Reserved4; /* reserved */
- UINT32_BIT FlushCash : 1; /* PAL_FLUSH_CACHE is correctly supported */
- UINT32_BIT Reserved5 : 1; /* reserved - must be zero */
- UINT32_BIT ProcC1 : 1; /* all processors support C1 state */
- UINT32_BIT Plvl2Up : 1; /* C2 state works on MP system */
- UINT32_BIT PwrButton : 1; /* Power button is handled as a generic feature */
- UINT32_BIT SleepButton : 1; /* Sleep button is handled as a generic feature, or not present */
- UINT32_BIT FixedRTC : 1; /* RTC wakeup stat not in fixed register space */
- UINT32_BIT Rtcs4 : 1; /* RTC wakeup stat not possible from S4 */
- UINT32_BIT TmrValExt : 1; /* tmr_val is 32 bits */
- UINT32_BIT DockCap : 1; /* Supports Docking */
- UINT32_BIT Reserved6 : 22; /* reserved - must be zero */
-
-} FADT_DESCRIPTOR_REV071;
-
-#pragma pack()
-
-#endif /* __ACTBL71_H__ */
-
diff --git a/sys/contrib/dev/acpica/exdyadic.c b/sys/contrib/dev/acpica/exdyadic.c
deleted file mode 100644
index ef434a298388..000000000000
--- a/sys/contrib/dev/acpica/exdyadic.c
+++ /dev/null
@@ -1,939 +0,0 @@
-/******************************************************************************
- *
- * Module Name: exdyadic - ACPI AML execution for dyadic (2-operand) operators
- * $Revision: 91 $
- *
- *****************************************************************************/
-
-/******************************************************************************
- *
- * 1. Copyright Notice
- *
- * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
- * All rights reserved.
- *
- * 2. License
- *
- * 2.1. This is your license from Intel Corp. under its intellectual property
- * rights. You may have additional license terms from the party that provided
- * you this software, covering your right to use that party's intellectual
- * property rights.
- *
- * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
- * copy of the source code appearing in this file ("Covered Code") an
- * irrevocable, perpetual, worldwide license under Intel's copyrights in the
- * base code distributed originally by Intel ("Original Intel Code") to copy,
- * make derivatives, distribute, use and display any portion of the Covered
- * Code in any form, with the right to sublicense such rights; and
- *
- * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
- * license (with the right to sublicense), under only those claims of Intel
- * patents that are infringed by the Original Intel Code, to make, use, sell,
- * offer to sell, and import the Covered Code and derivative works thereof
- * solely to the minimum extent necessary to exercise the above copyright
- * license, and in no event shall the patent license extend to any additions
- * to or modifications of the Original Intel Code. No other license or right
- * is granted directly or by implication, estoppel or otherwise;
- *
- * The above copyright and patent license is granted only if the following
- * conditions are met:
- *
- * 3. Conditions
- *
- * 3.1. Redistribution of Source with Rights to Further Distribute Source.
- * Redistribution of source code of any substantial portion of the Covered
- * Code or modification with rights to further distribute source must include
- * the above Copyright Notice, the above License, this list of Conditions,
- * and the following Disclaimer and Export Compliance provision. In addition,
- * Licensee must cause all Covered Code to which Licensee contributes to
- * contain a file documenting the changes Licensee made to create that Covered
- * Code and the date of any change. Licensee must include in that file the
- * documentation of any changes made by any predecessor Licensee. Licensee
- * must include a prominent statement that the modification is derived,
- * directly or indirectly, from Original Intel Code.
- *
- * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
- * Redistribution of source code of any substantial portion of the Covered
- * Code or modification without rights to further distribute source must
- * include the following Disclaimer and Export Compliance provision in the
- * documentation and/or other materials provided with distribution. In
- * addition, Licensee may not authorize further sublicense of source of any
- * portion of the Covered Code, and must include terms to the effect that the
- * license from Licensee to its licensee is limited to the intellectual
- * property embodied in the software Licensee provides to its licensee, and
- * not to intellectual property embodied in modifications its licensee may
- * make.
- *
- * 3.3. Redistribution of Executable. Redistribution in executable form of any
- * substantial portion of the Covered Code or modification must reproduce the
- * above Copyright Notice, and the following Disclaimer and Export Compliance
- * provision in the documentation and/or other materials provided with the
- * distribution.
- *
- * 3.4. Intel retains all right, title, and interest in and to the Original
- * Intel Code.
- *
- * 3.5. Neither the name Intel nor any other trademark owned or controlled by
- * Intel shall be used in advertising or otherwise to promote the sale, use or
- * other dealings in products derived from or relating to the Covered Code
- * without prior written authorization from Intel.
- *
- * 4. Disclaimer and Export Compliance
- *
- * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
- * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
- * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
- * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
- * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
- * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
- * PARTICULAR PURPOSE.
- *
- * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
- * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
- * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
- * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
- * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
- * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
- * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
- * LIMITED REMEDY.
- *
- * 4.3. Licensee shall not export, either directly or indirectly, any of this
- * software or system incorporating such software without first obtaining any
- * required license or other approval from the U. S. Department of Commerce or
- * any other agency or department of the United States Government. In the
- * event Licensee exports any such software from the United States or
- * re-exports any such software from a foreign destination, Licensee shall
- * ensure that the distribution and export/re-export of the software is in
- * compliance with all laws, regulations, orders, or other restrictions of the
- * U.S. Export Administration Regulations. Licensee agrees that neither it nor
- * any of its subsidiaries will export/re-export any technical data, process,
- * software, or service, directly or indirectly, to any country for which the
- * United States government or any agency thereof requires an export license,
- * other governmental approval, or letter of assurance, without first obtaining
- * such license, approval or letter.
- *
- *****************************************************************************/
-
-
-#define __EXDYADIC_C__
-
-#include "acpi.h"
-#include "acparser.h"
-#include "acnamesp.h"
-#include "acinterp.h"
-#include "acevents.h"
-#include "amlcode.h"
-#include "acdispat.h"
-
-
-#define _COMPONENT ACPI_EXECUTER
- MODULE_NAME ("exdyadic")
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiExDoConcatenate
- *
- * PARAMETERS: *ObjDesc - Object to be converted. Must be an
- * Integer, Buffer, or String
- * WalkState - Current walk state
- *
- * RETURN: Status
- *
- * DESCRIPTION: Concatenate two objects OF THE SAME TYPE.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExDoConcatenate (
- ACPI_OPERAND_OBJECT *ObjDesc,
- ACPI_OPERAND_OBJECT *ObjDesc2,
- ACPI_OPERAND_OBJECT **ActualRetDesc,
- ACPI_WALK_STATE *WalkState)
-{
- ACPI_STATUS Status;
- UINT32 i;
- ACPI_INTEGER ThisInteger;
- ACPI_OPERAND_OBJECT *RetDesc;
- NATIVE_CHAR *NewBuf;
- UINT32 IntegerSize = sizeof (ACPI_INTEGER);
-
-
- FUNCTION_ENTRY ();
-
-
- /*
- * There are three cases to handle:
- * 1) Two Integers concatenated to produce a buffer
- * 2) Two Strings concatenated to produce a string
- * 3) Two Buffers concatenated to produce a buffer
- */
- switch (ObjDesc->Common.Type)
- {
- case ACPI_TYPE_INTEGER:
-
- /* Handle both ACPI 1.0 and ACPI 2.0 Integer widths */
-
- if (WalkState->MethodNode->Flags & ANOBJ_DATA_WIDTH_32)
- {
- /*
- * We are running a method that exists in a 32-bit ACPI table.
- * Truncate the value to 32 bits by zeroing out the upper
- * 32-bit field
- */
- IntegerSize = sizeof (UINT32);
- }
-
- /* Result of two integers is a buffer */
-
- RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
- if (!RetDesc)
- {
- return (AE_NO_MEMORY);
- }
-
- /* Need enough space for two integers */
-
- RetDesc->Buffer.Length = IntegerSize * 2;
- NewBuf = ACPI_MEM_CALLOCATE (RetDesc->Buffer.Length);
- if (!NewBuf)
- {
- REPORT_ERROR
- (("ExDoConcatenate: Buffer allocation failure\n"));
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- RetDesc->Buffer.Pointer = (UINT8 *) NewBuf;
-
- /* Convert the first integer */
-
- ThisInteger = ObjDesc->Integer.Value;
- for (i = 0; i < IntegerSize; i++)
- {
- NewBuf[i] = (UINT8) ThisInteger;
- ThisInteger >>= 8;
- }
-
- /* Convert the second integer */
-
- ThisInteger = ObjDesc2->Integer.Value;
- for (; i < (IntegerSize * 2); i++)
- {
- NewBuf[i] = (UINT8) ThisInteger;
- ThisInteger >>= 8;
- }
-
- break;
-
-
- case ACPI_TYPE_STRING:
-
- RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
- if (!RetDesc)
- {
- return (AE_NO_MEMORY);
- }
-
- /* Operand1 is string */
-
- NewBuf = ACPI_MEM_ALLOCATE (ObjDesc->String.Length +
- ObjDesc2->String.Length + 1);
- if (!NewBuf)
- {
- REPORT_ERROR
- (("ExDoConcatenate: String allocation failure\n"));
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- STRCPY (NewBuf, ObjDesc->String.Pointer);
- STRCPY (NewBuf + ObjDesc->String.Length,
- ObjDesc2->String.Pointer);
-
- /* Point the return object to the new string */
-
- RetDesc->String.Pointer = NewBuf;
- RetDesc->String.Length = ObjDesc->String.Length +=
- ObjDesc2->String.Length;
- break;
-
-
- case ACPI_TYPE_BUFFER:
-
- /* Operand1 is a buffer */
-
- RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
- if (!RetDesc)
- {
- return (AE_NO_MEMORY);
- }
-
- NewBuf = ACPI_MEM_ALLOCATE (ObjDesc->Buffer.Length +
- ObjDesc2->Buffer.Length);
- if (!NewBuf)
- {
- REPORT_ERROR
- (("ExDoConcatenate: Buffer allocation failure\n"));
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- MEMCPY (NewBuf, ObjDesc->Buffer.Pointer,
- ObjDesc->Buffer.Length);
- MEMCPY (NewBuf + ObjDesc->Buffer.Length, ObjDesc2->Buffer.Pointer,
- ObjDesc2->Buffer.Length);
-
- /*
- * Point the return object to the new buffer
- */
-
- RetDesc->Buffer.Pointer = (UINT8 *) NewBuf;
- RetDesc->Buffer.Length = ObjDesc->Buffer.Length +
- ObjDesc2->Buffer.Length;
- break;
-
- default:
- Status = AE_AML_INTERNAL;
- RetDesc = NULL;
- }
-
-
- *ActualRetDesc = RetDesc;
- return (AE_OK);
-
-
-Cleanup:
-
- AcpiUtRemoveReference (RetDesc);
- return (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiExDyadic1
- *
- * PARAMETERS: WalkState - Current walk state
- *
- * RETURN: Status
- *
- * DESCRIPTION: Execute Type 1 dyadic operator with numeric operands:
- * NotifyOp
- *
- * ALLOCATION: Deletes both operands
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExDyadic1 (
- ACPI_WALK_STATE *WalkState)
-{
- ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
- ACPI_NAMESPACE_NODE *Node;
- ACPI_STATUS Status = AE_OK;
-
-
- FUNCTION_TRACE_PTR ("ExDyadic1", WALK_OPERANDS);
-
-
-
- /* Examine the opcode */
-
- switch (WalkState->Opcode)
- {
-
- case AML_NOTIFY_OP: /* Notify (NotifyObject, NotifyValue) */
-
- /* The first operand is a namespace node */
-
- Node = (ACPI_NAMESPACE_NODE *) Operand[0];
- Operand[0] = NULL;
-
- /* The node must refer to a device or thermal zone */
-
- if (Node && Operand[1])
- {
- switch (Node->Type)
- {
- case ACPI_TYPE_DEVICE:
- case ACPI_TYPE_THERMAL:
-
- /*
- * Dispatch the notify to the appropriate handler
- * NOTE: the request is queued for execution after this method
- * completes. The notify handlers are NOT invoked synchronously
- * from this thread -- because handlers may in turn run other
- * control methods.
- */
- Status = AcpiEvQueueNotifyRequest (Node,
- (UINT32) Operand[1]->Integer.Value);
- break;
-
- default:
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unexpected notify object type %X\n",
- Node->Type));
-
- Status = AE_AML_OPERAND_TYPE;
- break;
- }
- }
- break;
-
- default:
-
- REPORT_ERROR (("AcpiExDyadic1: Unknown dyadic opcode %X\n", WalkState->Opcode));
- Status = AE_AML_BAD_OPCODE;
- }
-
-
- /* Always delete both operands */
-
- AcpiUtRemoveReference (Operand[1]);
- AcpiUtRemoveReference (Operand[0]);
-
-
- return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiExDyadic2R
- *
- * PARAMETERS: WalkState - Current walk state
- *
- * RETURN: Status
- *
- * DESCRIPTION: Execute Type 2 dyadic operator with numeric operands and
- * one or two result operands.
- *
- * ALLOCATION: Deletes one operand descriptor -- other remains on stack
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExDyadic2R (
- ACPI_WALK_STATE *WalkState)
-{
- ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
- ACPI_OPERAND_OBJECT *RetDesc = NULL;
- ACPI_OPERAND_OBJECT *RetDesc2 = NULL;
- ACPI_STATUS Status = AE_OK;
-
-
- FUNCTION_TRACE_U32 ("ExDyadic2R", WalkState->Opcode);
-
-
- /* Create an internal return object if necessary */
-
- switch (WalkState->Opcode)
- {
- case AML_ADD_OP:
- case AML_BIT_AND_OP:
- case AML_BIT_NAND_OP:
- case AML_BIT_OR_OP:
- case AML_BIT_NOR_OP:
- case AML_BIT_XOR_OP:
- case AML_DIVIDE_OP:
- case AML_MOD_OP:
- case AML_MULTIPLY_OP:
- case AML_SHIFT_LEFT_OP:
- case AML_SHIFT_RIGHT_OP:
- case AML_SUBTRACT_OP:
-
- RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
- if (!RetDesc)
- {
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- break;
- }
-
-
- /*
- * Execute the opcode
- */
- switch (WalkState->Opcode)
- {
-
- case AML_ADD_OP: /* Add (Operand1, Operand2, Result) */
-
- RetDesc->Integer.Value = Operand[0]->Integer.Value +
- Operand[1]->Integer.Value;
- break;
-
-
- case AML_BIT_AND_OP: /* And (Operand1, Operand2, Result) */
-
- RetDesc->Integer.Value = Operand[0]->Integer.Value &
- Operand[1]->Integer.Value;
- break;
-
-
- case AML_BIT_NAND_OP: /* NAnd (Operand1, Operand2, Result) */
-
- RetDesc->Integer.Value = ~(Operand[0]->Integer.Value &
- Operand[1]->Integer.Value);
- break;
-
-
- case AML_BIT_OR_OP: /* Or (Operand1, Operand2, Result) */
-
- RetDesc->Integer.Value = Operand[0]->Integer.Value |
- Operand[1]->Integer.Value;
- break;
-
-
- case AML_BIT_NOR_OP: /* NOr (Operand1, Operand2, Result) */
-
- RetDesc->Integer.Value = ~(Operand[0]->Integer.Value |
- Operand[1]->Integer.Value);
- break;
-
-
- case AML_BIT_XOR_OP: /* XOr (Operand1, Operand2, Result) */
-
- RetDesc->Integer.Value = Operand[0]->Integer.Value ^
- Operand[1]->Integer.Value;
- break;
-
-
- case AML_DIVIDE_OP: /* Divide (Dividend, Divisor, RemainderResult QuotientRsult) */
-
- if (!Operand[1]->Integer.Value)
- {
- REPORT_ERROR (("DivideOp: Divide by zero\n"));
-
- Status = AE_AML_DIVIDE_BY_ZERO;
- goto Cleanup;
- }
-
- RetDesc2 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
- if (!RetDesc2)
- {
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- /*
- * RetDesc2 will contain the quotient,
- * RetDesc will contain the remainder
- */
- Status = AcpiUtDivide (&Operand[0]->Integer.Value, &Operand[1]->Integer.Value,
- &RetDesc2->Integer.Value, &RetDesc->Integer.Value);
-
- break;
-
-
- case AML_MOD_OP: /* Mod (Dividend, Divisor, RemainderResult (ACPI 2.0) */
-
- if (!Operand[1]->Integer.Value)
- {
- REPORT_ERROR (("ModOp: Divide by zero\n"));
-
- Status = AE_AML_DIVIDE_BY_ZERO;
- goto Cleanup;
- }
-
- /* RetDesc will contain the remainder */
-
- Status = AcpiUtDivide (&Operand[0]->Integer.Value, &Operand[1]->Integer.Value,
- NULL, &RetDesc->Integer.Value);
-
- break;
-
-
- case AML_MULTIPLY_OP: /* Multiply (Operand1, Operand2, Result) */
-
- RetDesc->Integer.Value = Operand[0]->Integer.Value *
- Operand[1]->Integer.Value;
- break;
-
-
- case AML_SHIFT_LEFT_OP: /* ShiftLeft (Operand, ShiftCount, Result) */
-
- RetDesc->Integer.Value = Operand[0]->Integer.Value <<
- Operand[1]->Integer.Value;
- break;
-
-
- case AML_SHIFT_RIGHT_OP: /* ShiftRight (Operand, ShiftCount, Result) */
-
- RetDesc->Integer.Value = Operand[0]->Integer.Value >>
- Operand[1]->Integer.Value;
- break;
-
-
- case AML_SUBTRACT_OP: /* Subtract (Operand1, Operand2, Result) */
-
- RetDesc->Integer.Value = Operand[0]->Integer.Value -
- Operand[1]->Integer.Value;
- break;
-
-
- case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
-
- /*
- * Convert the second operand if necessary. The first operand
- * determines the type of the second operand, (See the Data Types
- * section of the ACPI specification.) Both object types are
- * guaranteed to be either Integer/String/Buffer by the operand
- * resolution mechanism above.
- */
- switch (Operand[0]->Common.Type)
- {
- case ACPI_TYPE_INTEGER:
- Status = AcpiExConvertToInteger (Operand[1], &Operand[1], WalkState);
- break;
-
- case ACPI_TYPE_STRING:
- Status = AcpiExConvertToString (Operand[1], &Operand[1], 16, ACPI_UINT32_MAX, WalkState);
- break;
-
- case ACPI_TYPE_BUFFER:
- Status = AcpiExConvertToBuffer (Operand[1], &Operand[1], WalkState);
- break;
-
- default:
- Status = AE_AML_INTERNAL;
- }
-
- if (ACPI_FAILURE (Status))
- {
- goto Cleanup;
- }
-
- /*
- * Both operands are now known to be the same object type
- * (Both are Integer, String, or Buffer), and we can now perform the
- * concatenation.
- */
- Status = AcpiExDoConcatenate (Operand[0], Operand[1], &RetDesc, WalkState);
- if (ACPI_FAILURE (Status))
- {
- goto Cleanup;
- }
- break;
-
-
- case AML_TO_STRING_OP: /* ToString (Buffer, Length, Result) (ACPI 2.0) */
-
- Status = AcpiExConvertToString (Operand[0], &RetDesc, 16,
- (UINT32) Operand[1]->Integer.Value, WalkState);
- break;
-
-
- case AML_CONCAT_RES_OP: /* ConcatenateResTemplate (Buffer, Buffer, Result) (ACPI 2.0) */
-
- Status = AE_NOT_IMPLEMENTED;
- goto Cleanup;
- break;
-
-
- default:
-
- REPORT_ERROR (("AcpiExDyadic2R: Unknown dyadic opcode %X\n",
- WalkState->Opcode));
- Status = AE_AML_BAD_OPCODE;
- goto Cleanup;
- }
-
-
- /*
- * Store the result of the operation (which is now in Operand[0]) into
- * the result descriptor, or the location pointed to by the result
- * descriptor (Operand[2]).
- */
- Status = AcpiExStore (RetDesc, Operand[2], WalkState);
- if (ACPI_FAILURE (Status))
- {
- goto Cleanup;
- }
-
- if (AML_DIVIDE_OP == WalkState->Opcode)
- {
- Status = AcpiExStore (RetDesc2, Operand[3], WalkState);
-
- /*
- * Since the remainder is not returned, remove a reference to
- * the object we created earlier
- */
- AcpiUtRemoveReference (RetDesc);
- WalkState->ResultObj = RetDesc2;
- }
-
- else
- {
- WalkState->ResultObj = RetDesc;
- }
-
-
-Cleanup:
-
- /* Always delete the operands */
-
- AcpiUtRemoveReference (Operand[0]);
- AcpiUtRemoveReference (Operand[1]);
-
-
- /* Delete return object on error */
-
- if (ACPI_FAILURE (Status))
- {
- /* On failure, delete the result ops */
-
- AcpiUtRemoveReference (Operand[2]);
- AcpiUtRemoveReference (Operand[3]);
-
- if (RetDesc)
- {
- /* And delete the internal return object */
-
- AcpiUtRemoveReference (RetDesc);
- RetDesc = NULL;
- }
- }
-
- /* Set the return object and exit */
-
- return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiExDyadic2S
- *
- * PARAMETERS: WalkState - Current walk state
- *
- * RETURN: Status
- *
- * DESCRIPTION: Execute Type 2 dyadic synchronization operator
- *
- * ALLOCATION: Deletes one operand descriptor -- other remains on stack
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExDyadic2S (
- ACPI_WALK_STATE *WalkState)
-{
- ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
- ACPI_OPERAND_OBJECT *RetDesc = NULL;
- ACPI_STATUS Status;
-
-
- FUNCTION_TRACE_PTR ("ExDyadic2S", WALK_OPERANDS);
-
-
-
- /* Create the internal return object */
-
- RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
- if (!RetDesc)
- {
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- /* Default return value is FALSE, operation did not time out */
-
- RetDesc->Integer.Value = 0;
-
-
- /* Examine the opcode */
-
- switch (WalkState->Opcode)
- {
-
- case AML_ACQUIRE_OP: /* Acquire (MutexObject, Timeout) */
-
- Status = AcpiExAcquireMutex (Operand[1], Operand[0], WalkState);
- break;
-
-
- case AML_WAIT_OP: /* Wait (EventObject, Timeout) */
-
- Status = AcpiExSystemWaitEvent (Operand[1], Operand[0]);
- break;
-
-
- default:
-
- REPORT_ERROR (("AcpiExDyadic2S: Unknown dyadic synchronization opcode %X\n", WalkState->Opcode));
- Status = AE_AML_BAD_OPCODE;
- goto Cleanup;
- }
-
-
- /*
- * Return a boolean indicating if operation timed out
- * (TRUE) or not (FALSE)
- */
- if (Status == AE_TIME)
- {
- RetDesc->Integer.Value = ACPI_INTEGER_MAX; /* TRUE, op timed out */
- Status = AE_OK;
- }
-
-
-Cleanup:
-
- /* Delete params */
-
- AcpiUtRemoveReference (Operand[1]);
- AcpiUtRemoveReference (Operand[0]);
-
- /* Delete return object on error */
-
- if (ACPI_FAILURE (Status) &&
- (RetDesc))
- {
- AcpiUtRemoveReference (RetDesc);
- RetDesc = NULL;
- }
-
-
- /* Set the return object and exit */
-
- WalkState->ResultObj = RetDesc;
- return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiExDyadic2
- *
- * PARAMETERS: WalkState - Current walk state
- *
- * RETURN: Status
- *
- * DESCRIPTION: Execute Type 2 dyadic operator with numeric operands and
- * no result operands
- *
- * ALLOCATION: Deletes one operand descriptor -- other remains on stack
- * containing result value
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExDyadic2 (
- ACPI_WALK_STATE *WalkState)
-{
- ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
- ACPI_OPERAND_OBJECT *RetDesc = NULL;
- ACPI_STATUS Status = AE_OK;
- BOOLEAN Lboolean;
-
-
- FUNCTION_TRACE_PTR ("ExDyadic2", WALK_OPERANDS);
-
-
- /* Create the internal return object */
-
- RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
- if (!RetDesc)
- {
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- /*
- * Execute the WalkState->Opcode
- */
- Lboolean = FALSE;
- switch (WalkState->Opcode)
- {
-
- case AML_LAND_OP: /* LAnd (Operand1, Operand2) */
-
- Lboolean = (BOOLEAN) (Operand[0]->Integer.Value &&
- Operand[1]->Integer.Value);
- break;
-
-
- case AML_LEQUAL_OP: /* LEqual (Operand1, Operand2) */
-
- Lboolean = (BOOLEAN) (Operand[0]->Integer.Value ==
- Operand[1]->Integer.Value);
- break;
-
-
- case AML_LGREATER_OP: /* LGreater (Operand1, Operand2) */
-
- Lboolean = (BOOLEAN) (Operand[0]->Integer.Value >
- Operand[1]->Integer.Value);
- break;
-
-
- case AML_LLESS_OP: /* LLess (Operand1, Operand2) */
-
- Lboolean = (BOOLEAN) (Operand[0]->Integer.Value <
- Operand[1]->Integer.Value);
- break;
-
-
- case AML_LOR_OP: /* LOr (Operand1, Operand2) */
-
- Lboolean = (BOOLEAN) (Operand[0]->Integer.Value ||
- Operand[1]->Integer.Value);
- break;
-
-
- case AML_COPY_OP: /* Copy (Source, Target) (ACPI 2.0) */
-
- Status = AE_NOT_IMPLEMENTED;
- goto Cleanup;
- break;
-
-
- default:
-
- REPORT_ERROR (("AcpiExDyadic2: Unknown dyadic opcode %X\n", WalkState->Opcode));
- Status = AE_AML_BAD_OPCODE;
- goto Cleanup;
- break;
- }
-
-
- /* Set return value to logical TRUE (all ones) or FALSE (zero) */
-
- if (Lboolean)
- {
- RetDesc->Integer.Value = ACPI_INTEGER_MAX;
- }
- else
- {
- RetDesc->Integer.Value = 0;
- }
-
-
-Cleanup:
-
- /* Always delete operands */
-
- AcpiUtRemoveReference (Operand[0]);
- AcpiUtRemoveReference (Operand[1]);
-
-
- /* Delete return object on error */
-
- if (ACPI_FAILURE (Status) &&
- (RetDesc))
- {
- AcpiUtRemoveReference (RetDesc);
- RetDesc = NULL;
- }
-
-
- /* Set the return object and exit */
-
- WalkState->ResultObj = RetDesc;
- return_ACPI_STATUS (Status);
-}
-
-
diff --git a/sys/contrib/dev/acpica/exmonad.c b/sys/contrib/dev/acpica/exmonad.c
deleted file mode 100644
index 3e6a969da510..000000000000
--- a/sys/contrib/dev/acpica/exmonad.c
+++ /dev/null
@@ -1,1083 +0,0 @@
-
-/******************************************************************************
- *
- * Module Name: exmonad - ACPI AML execution for monadic (1 operand) operators
- * $Revision: 113 $
- *
- *****************************************************************************/
-
-/******************************************************************************
- *
- * 1. Copyright Notice
- *
- * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
- * All rights reserved.
- *
- * 2. License
- *
- * 2.1. This is your license from Intel Corp. under its intellectual property
- * rights. You may have additional license terms from the party that provided
- * you this software, covering your right to use that party's intellectual
- * property rights.
- *
- * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
- * copy of the source code appearing in this file ("Covered Code") an
- * irrevocable, perpetual, worldwide license under Intel's copyrights in the
- * base code distributed originally by Intel ("Original Intel Code") to copy,
- * make derivatives, distribute, use and display any portion of the Covered
- * Code in any form, with the right to sublicense such rights; and
- *
- * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
- * license (with the right to sublicense), under only those claims of Intel
- * patents that are infringed by the Original Intel Code, to make, use, sell,
- * offer to sell, and import the Covered Code and derivative works thereof
- * solely to the minimum extent necessary to exercise the above copyright
- * license, and in no event shall the patent license extend to any additions
- * to or modifications of the Original Intel Code. No other license or right
- * is granted directly or by implication, estoppel or otherwise;
- *
- * The above copyright and patent license is granted only if the following
- * conditions are met:
- *
- * 3. Conditions
- *
- * 3.1. Redistribution of Source with Rights to Further Distribute Source.
- * Redistribution of source code of any substantial portion of the Covered
- * Code or modification with rights to further distribute source must include
- * the above Copyright Notice, the above License, this list of Conditions,
- * and the following Disclaimer and Export Compliance provision. In addition,
- * Licensee must cause all Covered Code to which Licensee contributes to
- * contain a file documenting the changes Licensee made to create that Covered
- * Code and the date of any change. Licensee must include in that file the
- * documentation of any changes made by any predecessor Licensee. Licensee
- * must include a prominent statement that the modification is derived,
- * directly or indirectly, from Original Intel Code.
- *
- * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
- * Redistribution of source code of any substantial portion of the Covered
- * Code or modification without rights to further distribute source must
- * include the following Disclaimer and Export Compliance provision in the
- * documentation and/or other materials provided with distribution. In
- * addition, Licensee may not authorize further sublicense of source of any
- * portion of the Covered Code, and must include terms to the effect that the
- * license from Licensee to its licensee is limited to the intellectual
- * property embodied in the software Licensee provides to its licensee, and
- * not to intellectual property embodied in modifications its licensee may
- * make.
- *
- * 3.3. Redistribution of Executable. Redistribution in executable form of any
- * substantial portion of the Covered Code or modification must reproduce the
- * above Copyright Notice, and the following Disclaimer and Export Compliance
- * provision in the documentation and/or other materials provided with the
- * distribution.
- *
- * 3.4. Intel retains all right, title, and interest in and to the Original
- * Intel Code.
- *
- * 3.5. Neither the name Intel nor any other trademark owned or controlled by
- * Intel shall be used in advertising or otherwise to promote the sale, use or
- * other dealings in products derived from or relating to the Covered Code
- * without prior written authorization from Intel.
- *
- * 4. Disclaimer and Export Compliance
- *
- * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
- * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
- * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
- * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
- * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
- * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
- * PARTICULAR PURPOSE.
- *
- * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
- * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
- * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
- * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
- * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
- * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
- * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
- * LIMITED REMEDY.
- *
- * 4.3. Licensee shall not export, either directly or indirectly, any of this
- * software or system incorporating such software without first obtaining any
- * required license or other approval from the U. S. Department of Commerce or
- * any other agency or department of the United States Government. In the
- * event Licensee exports any such software from the United States or
- * re-exports any such software from a foreign destination, Licensee shall
- * ensure that the distribution and export/re-export of the software is in
- * compliance with all laws, regulations, orders, or other restrictions of the
- * U.S. Export Administration Regulations. Licensee agrees that neither it nor
- * any of its subsidiaries will export/re-export any technical data, process,
- * software, or service, directly or indirectly, to any country for which the
- * United States government or any agency thereof requires an export license,
- * other governmental approval, or letter of assurance, without first obtaining
- * such license, approval or letter.
- *
- *****************************************************************************/
-
-#define __EXMONAD_C__
-
-#include "acpi.h"
-#include "acparser.h"
-#include "acdispat.h"
-#include "acinterp.h"
-#include "amlcode.h"
-#include "acnamesp.h"
-
-
-#define _COMPONENT ACPI_EXECUTER
- MODULE_NAME ("exmonad")
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiExGetObjectReference
- *
- * PARAMETERS: ObjDesc - Create a reference to this object
- * RetDesc - Where to store the reference
- *
- * RETURN: Status
- *
- * DESCRIPTION: Obtain and return a "reference" to the target object
- * Common code for the RefOfOp and the CondRefOfOp.
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiExGetObjectReference (
- ACPI_OPERAND_OBJECT *ObjDesc,
- ACPI_OPERAND_OBJECT **RetDesc,
- ACPI_WALK_STATE *WalkState)
-{
- ACPI_STATUS Status = AE_OK;
-
-
- FUNCTION_TRACE_PTR ("ExGetObjectReference", ObjDesc);
-
-
- if (VALID_DESCRIPTOR_TYPE (ObjDesc, ACPI_DESC_TYPE_INTERNAL))
- {
- if (ObjDesc->Common.Type != INTERNAL_TYPE_REFERENCE)
- {
- *RetDesc = NULL;
- Status = AE_TYPE;
- goto Cleanup;
- }
-
- /*
- * Not a Name -- an indirect name pointer would have
- * been converted to a direct name pointer in AcpiExResolveOperands
- */
- switch (ObjDesc->Reference.Opcode)
- {
- case AML_LOCAL_OP:
- case AML_ARG_OP:
-
- *RetDesc = (void *) AcpiDsMethodDataGetNode (ObjDesc->Reference.Opcode,
- ObjDesc->Reference.Offset, WalkState);
- break;
-
- default:
-
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(Internal) Unknown Ref subtype %02x\n",
- ObjDesc->Reference.Opcode));
- *RetDesc = NULL;
- Status = AE_AML_INTERNAL;
- goto Cleanup;
- }
-
- }
-
- else if (VALID_DESCRIPTOR_TYPE (ObjDesc, ACPI_DESC_TYPE_NAMED))
- {
- /* Must be a named object; Just return the Node */
-
- *RetDesc = ObjDesc;
- }
-
- else
- {
- *RetDesc = NULL;
- Status = AE_TYPE;
- }
-
-
-Cleanup:
-
- ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p Ref=%p\n", ObjDesc, *RetDesc));
- return_ACPI_STATUS (Status);
-}
-
-#define ObjDesc Operand[0]
-#define ResDesc Operand[1]
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiExMonadic1
- *
- * PARAMETERS: WalkState - Current state (contains AML opcode)
- *
- * RETURN: Status
- *
- * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
- * object stack
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExMonadic1 (
- ACPI_WALK_STATE *WalkState)
-{
- ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
- ACPI_STATUS Status;
-
-
- FUNCTION_TRACE_PTR ("ExMonadic1", WALK_OPERANDS);
-
-
- /* Examine the opcode */
-
- switch (WalkState->Opcode)
- {
- case AML_RELEASE_OP: /* Release (MutexObject) */
-
- Status = AcpiExReleaseMutex (ObjDesc, WalkState);
- break;
-
-
- case AML_RESET_OP: /* Reset (EventObject) */
-
- Status = AcpiExSystemResetEvent (ObjDesc);
- break;
-
-
- case AML_SIGNAL_OP: /* Signal (EventObject) */
-
- Status = AcpiExSystemSignalEvent (ObjDesc);
- break;
-
-
- case AML_SLEEP_OP: /* Sleep (MsecTime) */
-
- AcpiExSystemDoSuspend ((UINT32) ObjDesc->Integer.Value);
- break;
-
-
- case AML_STALL_OP: /* Stall (UsecTime) */
-
- AcpiExSystemDoStall ((UINT32) ObjDesc->Integer.Value);
- break;
-
-
- default: /* Unknown opcode */
-
- REPORT_ERROR (("AcpiExMonadic1: Unknown monadic opcode %X\n",
- WalkState->Opcode));
- Status = AE_AML_BAD_OPCODE;
- break;
- }
-
-
- /* Always delete the operand */
-
- AcpiUtRemoveReference (ObjDesc);
-
- return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiExMonadic2R
- *
- * PARAMETERS: WalkState - Current state (contains AML opcode)
- *
- * RETURN: Status
- *
- * DESCRIPTION: Execute Type 2 monadic operator with numeric operand and
- * result operand on operand stack
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExMonadic2R (
- ACPI_WALK_STATE *WalkState)
-{
- ACPI_STATUS Status = AE_OK;
- ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
- ACPI_OPERAND_OBJECT *RetDesc = NULL;
- ACPI_OPERAND_OBJECT *RetDesc2 = NULL;
- UINT32 Temp32;
- UINT32 i;
- UINT32 j;
- ACPI_INTEGER Digit;
-
-
- FUNCTION_TRACE_PTR ("ExMonadic2R", WALK_OPERANDS);
-
-
-
-
- /* Create a return object of type NUMBER for most opcodes */
-
- switch (WalkState->Opcode)
- {
- case AML_BIT_NOT_OP:
- case AML_FIND_SET_LEFT_BIT_OP:
- case AML_FIND_SET_RIGHT_BIT_OP:
- case AML_FROM_BCD_OP:
- case AML_TO_BCD_OP:
- case AML_COND_REF_OF_OP:
-
- RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
- if (!RetDesc)
- {
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- break;
- }
-
-
- switch (WalkState->Opcode)
- {
-
- case AML_BIT_NOT_OP: /* Not (Operand, Result) */
-
- RetDesc->Integer.Value = ~ObjDesc->Integer.Value;
- break;
-
-
- case AML_FIND_SET_LEFT_BIT_OP: /* FindSetLeftBit (Operand, Result) */
-
-
- RetDesc->Integer.Value = ObjDesc->Integer.Value;
-
- /*
- * Acpi specification describes Integer type as a little
- * endian unsigned value, so this boundary condition is valid.
- */
- for (Temp32 = 0; RetDesc->Integer.Value && Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
- {
- RetDesc->Integer.Value >>= 1;
- }
-
- RetDesc->Integer.Value = Temp32;
- break;
-
-
- case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result) */
-
-
- RetDesc->Integer.Value = ObjDesc->Integer.Value;
-
- /*
- * The Acpi specification describes Integer type as a little
- * endian unsigned value, so this boundary condition is valid.
- */
- for (Temp32 = 0; RetDesc->Integer.Value && Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
- {
- RetDesc->Integer.Value <<= 1;
- }
-
- /* Since returns must be 1-based, subtract from 33 (65) */
-
- RetDesc->Integer.Value = Temp32 == 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
- break;
-
-
- case AML_FROM_BCD_OP: /* FromBcd (BCDValue, Result) */
-
- /*
- * The 64-bit ACPI integer can hold 16 4-bit BCD integers
- */
- RetDesc->Integer.Value = 0;
- for (i = 0; i < ACPI_MAX_BCD_DIGITS; i++)
- {
- /* Get one BCD digit */
-
- Digit = (ACPI_INTEGER) ((ObjDesc->Integer.Value >> (i * 4)) & 0xF);
-
- /* Check the range of the digit */
-
- if (Digit > 9)
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "BCD digit too large: \n",
- Digit));
- Status = AE_AML_NUMERIC_OVERFLOW;
- goto Cleanup;
- }
-
- if (Digit > 0)
- {
- /* Sum into the result with the appropriate power of 10 */
-
- for (j = 0; j < i; j++)
- {
- Digit *= 10;
- }
-
- RetDesc->Integer.Value += Digit;
- }
- }
- break;
-
-
- case AML_TO_BCD_OP: /* ToBcd (Operand, Result) */
-
- if (ObjDesc->Integer.Value > ACPI_MAX_BCD_VALUE)
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "BCD overflow: %d\n",
- ObjDesc->Integer.Value));
- Status = AE_AML_NUMERIC_OVERFLOW;
- goto Cleanup;
- }
-
- RetDesc->Integer.Value = 0;
- for (i = 0; i < ACPI_MAX_BCD_DIGITS; i++)
- {
- /* Divide by nth factor of 10 */
-
- Temp32 = 0;
- Digit = ObjDesc->Integer.Value;
- for (j = 0; j < i; j++)
- {
- AcpiUtShortDivide (&Digit, 10, &Digit, &Temp32);
- }
-
- /* Create the BCD digit from the remainder above */
-
- if (Digit > 0)
- {
- RetDesc->Integer.Value += (Temp32 << (i * 4));
- }
- }
- break;
-
-
- case AML_COND_REF_OF_OP: /* CondRefOf (SourceObject, Result) */
-
- /*
- * This op is a little strange because the internal return value is
- * different than the return value stored in the result descriptor
- * (There are really two return values)
- */
- if ((ACPI_NAMESPACE_NODE *) ObjDesc == AcpiGbl_RootNode)
- {
- /*
- * This means that the object does not exist in the namespace,
- * return FALSE
- */
- RetDesc->Integer.Value = 0;
-
- /*
- * Must delete the result descriptor since there is no reference
- * being returned
- */
- AcpiUtRemoveReference (ResDesc);
- goto Cleanup;
- }
-
- /* Get the object reference and store it */
-
- Status = AcpiExGetObjectReference (ObjDesc, &RetDesc2, WalkState);
- if (ACPI_FAILURE (Status))
- {
- goto Cleanup;
- }
-
- Status = AcpiExStore (RetDesc2, ResDesc, WalkState);
-
- /* The object exists in the namespace, return TRUE */
-
- RetDesc->Integer.Value = ACPI_INTEGER_MAX;
- goto Cleanup;
- break;
-
-
- case AML_STORE_OP: /* Store (Source, Target) */
-
- /*
- * A store operand is typically a number, string, buffer or lvalue
- * Be careful about deleting the source object,
- * since the object itself may have been stored.
- */
- Temp32 = ObjDesc->Common.ReferenceCount;
- Status = AcpiExStore (ObjDesc, ResDesc, WalkState);
- if (ACPI_FAILURE (Status))
- {
- /* On failure, just delete the ObjDesc */
-
- AcpiUtRemoveReference (ObjDesc);
- return_ACPI_STATUS (Status);
- }
-
-#if 0
- if ((ObjDesc->Common.ReferenceCount > Temp32) &&
- (!AcpiDsIsResultUsed (WalkState->Op, WalkState)))
- {
- ObjDesc->Common.ReferenceCount++;
- }
-#endif
-
- /*
- * Normally, we would remove a reference on the ObjDesc parameter;
- * But since it is being used as the internal return object
- * (meaning we would normally increment it), the two cancel out,
- * and we simply don't do anything.
- */
- WalkState->ResultObj = ObjDesc;
- return_ACPI_STATUS (Status);
- break;
-
-
- /*
- * ACPI 2.0 Opcodes
- */
- case AML_TO_DECSTRING_OP: /* ToDecimalString (Data, Result) */
-
- Status = AcpiExConvertToString (ObjDesc, &RetDesc, 10, ACPI_UINT32_MAX, WalkState);
- break;
-
-
- case AML_TO_HEXSTRING_OP: /* ToHexString (Data, Result) */
-
- Status = AcpiExConvertToString (ObjDesc, &RetDesc, 16, ACPI_UINT32_MAX, WalkState);
- break;
-
-
- case AML_TO_BUFFER_OP: /* ToBuffer (Data, Result) */
-
- Status = AcpiExConvertToBuffer (ObjDesc, &RetDesc, WalkState);
- break;
-
-
- case AML_TO_INTEGER_OP: /* ToInteger (Data, Result) */
-
- Status = AcpiExConvertToInteger (ObjDesc, &RetDesc, WalkState);
- break;
-
-
- /*
- * These are two obsolete opcodes
- */
- case AML_SHIFT_LEFT_BIT_OP: /* ShiftLeftBit (Source, BitNum) */
- case AML_SHIFT_RIGHT_BIT_OP: /* ShiftRightBit (Source, BitNum) */
-
-
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s is unimplemented\n",
- AcpiPsGetOpcodeName (WalkState->Opcode)));
- Status = AE_SUPPORT;
- goto Cleanup;
- break;
-
-
- default: /* Unknown opcode */
-
- REPORT_ERROR (("AcpiExMonadic2R: Unknown monadic opcode %X\n",
- WalkState->Opcode));
- Status = AE_AML_BAD_OPCODE;
- goto Cleanup;
- }
-
-
- /*
- * Store the return value computed above into the result object
- */
- Status = AcpiExStore (RetDesc, ResDesc, WalkState);
-
-
-Cleanup:
- /* Always delete the operand object */
-
- AcpiUtRemoveReference (ObjDesc);
-
- /* Delete return object(s) on error */
-
- if (ACPI_FAILURE (Status))
- {
- AcpiUtRemoveReference (ResDesc); /* Result descriptor */
- if (RetDesc)
- {
- AcpiUtRemoveReference (RetDesc);
- RetDesc = NULL;
- }
- }
-
- /* Set the return object and exit */
-
- WalkState->ResultObj = RetDesc;
- return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiExMonadic2
- *
- * PARAMETERS: WalkState - Current state (contains AML opcode)
- *
- * RETURN: Status
- *
- * DESCRIPTION: Execute Type 2 monadic operator with numeric operand:
- * DerefOfOp, RefOfOp, SizeOfOp, TypeOp, IncrementOp,
- * DecrementOp, LNotOp,
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExMonadic2 (
- ACPI_WALK_STATE *WalkState)
-{
- ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
- ACPI_OPERAND_OBJECT *TmpDesc;
- ACPI_OPERAND_OBJECT *RetDesc = NULL;
- ACPI_STATUS Status = AE_OK;
- UINT32 Type;
- ACPI_INTEGER Value;
-
-
- FUNCTION_TRACE_PTR ("ExMonadic2", WALK_OPERANDS);
-
-
-
-
- /* Get the operand and decode the opcode */
-
- switch (WalkState->Opcode)
- {
-
- case AML_LNOT_OP: /* LNot (Operand) */
-
- RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
- if (!RetDesc)
- {
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- RetDesc->Integer.Value = !ObjDesc->Integer.Value;
- break;
-
-
- case AML_DECREMENT_OP: /* Decrement (Operand) */
- case AML_INCREMENT_OP: /* Increment (Operand) */
-
- /*
- * Since we are expecting an Reference on the top of the stack, it
- * can be either an Node or an internal object.
- *
- * TBD: [Future] This may be the prototype code for all cases where
- * a Reference is expected!! 10/99
- */
- if (VALID_DESCRIPTOR_TYPE (ObjDesc, ACPI_DESC_TYPE_NAMED))
- {
- RetDesc = ObjDesc;
- }
-
- else
- {
- /*
- * Duplicate the Reference in a new object so that we can resolve it
- * without destroying the original Reference object
- */
- RetDesc = AcpiUtCreateInternalObject (INTERNAL_TYPE_REFERENCE);
- if (!RetDesc)
- {
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- RetDesc->Reference.Opcode = ObjDesc->Reference.Opcode;
- RetDesc->Reference.Offset = ObjDesc->Reference.Offset;
- RetDesc->Reference.Object = ObjDesc->Reference.Object;
- }
-
-
- /*
- * Convert the RetDesc Reference to a Number
- * (This deletes the original RetDesc object)
- */
- Status = AcpiExResolveOperands (AML_LNOT_OP, &RetDesc, WalkState);
- if (ACPI_FAILURE (Status))
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s: bad operand(s) %s\n",
- AcpiPsGetOpcodeName (WalkState->Opcode), AcpiFormatException(Status)));
-
- goto Cleanup;
- }
-
- /* Do the actual increment or decrement */
-
- if (AML_INCREMENT_OP == WalkState->Opcode)
- {
- RetDesc->Integer.Value++;
- }
- else
- {
- RetDesc->Integer.Value--;
- }
-
- /* Store the result back in the original descriptor */
-
- Status = AcpiExStore (RetDesc, ObjDesc, WalkState);
-
- /* Objdesc was just deleted (because it is an Reference) */
-
- ObjDesc = NULL;
-
- break;
-
-
- case AML_TYPE_OP: /* ObjectType (SourceObject) */
-
- if (INTERNAL_TYPE_REFERENCE == ObjDesc->Common.Type)
- {
- /*
- * Not a Name -- an indirect name pointer would have
- * been converted to a direct name pointer in ResolveOperands
- */
- switch (ObjDesc->Reference.Opcode)
- {
- case AML_ZERO_OP:
- case AML_ONE_OP:
- case AML_ONES_OP:
- case AML_REVISION_OP:
-
- /* Constants are of type Number */
-
- Type = ACPI_TYPE_INTEGER;
- break;
-
-
- case AML_DEBUG_OP:
-
- /* Per 1.0b spec, Debug object is of type "DebugObject" */
-
- Type = ACPI_TYPE_DEBUG_OBJECT;
- break;
-
-
- case AML_INDEX_OP:
-
- /* Get the type of this reference (index into another object) */
-
- Type = ObjDesc->Reference.TargetType;
- if (Type == ACPI_TYPE_PACKAGE)
- {
- /*
- * The main object is a package, we want to get the type
- * of the individual package element that is referenced by
- * the index.
- */
- Type = (*(ObjDesc->Reference.Where))->Common.Type;
- }
-
- break;
-
-
- case AML_LOCAL_OP:
- case AML_ARG_OP:
-
- Type = AcpiDsMethodDataGetType (ObjDesc->Reference.Opcode,
- ObjDesc->Reference.Offset, WalkState);
- break;
-
-
- default:
-
- REPORT_ERROR (("AcpiExMonadic2/TypeOp: Internal error - Unknown Reference subtype %X\n",
- ObjDesc->Reference.Opcode));
- Status = AE_AML_INTERNAL;
- goto Cleanup;
- }
- }
-
- else
- {
- /*
- * It's not a Reference, so it must be a direct name pointer.
- */
- Type = AcpiNsGetType ((ACPI_NAMESPACE_NODE *) ObjDesc);
-
- /* Convert internal types to external types */
-
- switch (Type)
- {
- case INTERNAL_TYPE_REGION_FIELD:
- case INTERNAL_TYPE_BANK_FIELD:
- case INTERNAL_TYPE_INDEX_FIELD:
-
- Type = ACPI_TYPE_FIELD_UNIT;
- }
-
- }
-
- /* Allocate a descriptor to hold the type. */
-
- RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
- if (!RetDesc)
- {
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- RetDesc->Integer.Value = Type;
- break;
-
-
- case AML_SIZE_OF_OP: /* SizeOf (SourceObject) */
-
- if (VALID_DESCRIPTOR_TYPE (ObjDesc, ACPI_DESC_TYPE_NAMED))
- {
- ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc);
- }
-
- if (!ObjDesc)
- {
- Value = 0;
- }
-
- else
- {
- switch (ObjDesc->Common.Type)
- {
-
- case ACPI_TYPE_BUFFER:
-
- Value = ObjDesc->Buffer.Length;
- break;
-
-
- case ACPI_TYPE_STRING:
-
- Value = ObjDesc->String.Length;
- break;
-
-
- case ACPI_TYPE_PACKAGE:
-
- Value = ObjDesc->Package.Count;
- break;
-
- case INTERNAL_TYPE_REFERENCE:
-
- Value = 4;
- break;
-
- default:
-
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Not Buf/Str/Pkg - found type %X\n",
- ObjDesc->Common.Type));
- Status = AE_AML_OPERAND_TYPE;
- goto Cleanup;
- }
- }
-
- /*
- * Now that we have the size of the object, create a result
- * object to hold the value
- */
- RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
- if (!RetDesc)
- {
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- RetDesc->Integer.Value = Value;
- break;
-
-
- case AML_REF_OF_OP: /* RefOf (SourceObject) */
-
- Status = AcpiExGetObjectReference (ObjDesc, &RetDesc, WalkState);
- if (ACPI_FAILURE (Status))
- {
- goto Cleanup;
- }
- break;
-
-
- case AML_DEREF_OF_OP: /* DerefOf (ObjReference) */
-
- /* Check for a method local or argument */
-
- if (!VALID_DESCRIPTOR_TYPE (ObjDesc, ACPI_DESC_TYPE_NAMED))
- {
- /*
- * Must resolve/dereference the local/arg reference first
- */
- switch (ObjDesc->Reference.Opcode)
- {
- /* Set ObjDesc to the value of the local/arg */
-
- case AML_LOCAL_OP:
- case AML_ARG_OP:
-
- AcpiDsMethodDataGetValue (ObjDesc->Reference.Opcode,
- ObjDesc->Reference.Offset, WalkState, &TmpDesc);
-
- /*
- * Delete our reference to the input object and
- * point to the object just retrieved
- */
- AcpiUtRemoveReference (ObjDesc);
- ObjDesc = TmpDesc;
- break;
-
- default:
-
- /* Index op - handled below */
- break;
- }
- }
-
-
- /* ObjDesc may have changed from the code above */
-
- if (VALID_DESCRIPTOR_TYPE (ObjDesc, ACPI_DESC_TYPE_NAMED))
- {
- /* Get the actual object from the Node (This is the dereference) */
-
- RetDesc = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Object;
-
- /* Returning a pointer to the object, add another reference! */
-
- AcpiUtAddReference (RetDesc);
- }
-
- else
- {
- /*
- * This must be a reference object produced by the Index
- * ASL operation -- check internal opcode
- */
- if ((ObjDesc->Reference.Opcode != AML_INDEX_OP) &&
- (ObjDesc->Reference.Opcode != AML_REF_OF_OP))
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown opcode in ref(%p) - %X\n",
- ObjDesc, ObjDesc->Reference.Opcode));
-
- Status = AE_TYPE;
- goto Cleanup;
- }
-
-
- switch (ObjDesc->Reference.Opcode)
- {
- case AML_INDEX_OP:
-
- /*
- * Supported target types for the Index operator are
- * 1) A Buffer
- * 2) A Package
- */
- if (ObjDesc->Reference.TargetType == ACPI_TYPE_BUFFER_FIELD)
- {
- /*
- * The target is a buffer, we must create a new object that
- * contains one element of the buffer, the element pointed
- * to by the index.
- *
- * NOTE: index into a buffer is NOT a pointer to a
- * sub-buffer of the main buffer, it is only a pointer to a
- * single element (byte) of the buffer!
- */
- RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
- if (!RetDesc)
- {
- Status = AE_NO_MEMORY;
- goto Cleanup;
- }
-
- TmpDesc = ObjDesc->Reference.Object;
- RetDesc->Integer.Value =
- TmpDesc->Buffer.Pointer[ObjDesc->Reference.Offset];
-
- /* TBD: [Investigate] (see below) Don't add an additional
- * ref!
- */
- }
-
- else if (ObjDesc->Reference.TargetType == ACPI_TYPE_PACKAGE)
- {
- /*
- * The target is a package, we want to return the referenced
- * element of the package. We must add another reference to
- * this object, however.
- */
- RetDesc = *(ObjDesc->Reference.Where);
- if (!RetDesc)
- {
- /*
- * We can't return a NULL dereferenced value. This is
- * an uninitialized package element and is thus a
- * severe error.
- */
-
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "NULL package element obj %p\n",
- ObjDesc));
- Status = AE_AML_UNINITIALIZED_ELEMENT;
- goto Cleanup;
- }
-
- AcpiUtAddReference (RetDesc);
- }
-
- else
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown TargetType %X in obj %p\n",
- ObjDesc->Reference.TargetType, ObjDesc));
- Status = AE_AML_OPERAND_TYPE;
- goto Cleanup;
- }
-
- break;
-
-
- case AML_REF_OF_OP:
-
- RetDesc = ObjDesc->Reference.Object;
-
- /* Add another reference to the object! */
-
- AcpiUtAddReference (RetDesc);
- break;
- }
- }
-
- break;
-
-
- default:
-
- REPORT_ERROR (("AcpiExMonadic2: Unknown monadic opcode %X\n",
- WalkState->Opcode));
- Status = AE_AML_BAD_OPCODE;
- goto Cleanup;
- }
-
-
-Cleanup:
-
- if (ObjDesc)
- {
- AcpiUtRemoveReference (ObjDesc);
- }
-
- /* Delete return object on error */
-
- if (ACPI_FAILURE (Status) &&
- (RetDesc))
- {
- AcpiUtRemoveReference (RetDesc);
- RetDesc = NULL;
- }
-
- WalkState->ResultObj = RetDesc;
- return_ACPI_STATUS (Status);
-}
-
diff --git a/sys/contrib/dev/acpica/psfind.c b/sys/contrib/dev/acpica/psfind.c
deleted file mode 100644
index 6862843fad3d..000000000000
--- a/sys/contrib/dev/acpica/psfind.c
+++ /dev/null
@@ -1,485 +0,0 @@
-
-/******************************************************************************
- *
- * Module Name: psfind - Parse tree search routine
- * $Revision: 42 $
- *
- *****************************************************************************/
-
-/******************************************************************************
- *
- * 1. Copyright Notice
- *
- * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
- * All rights reserved.
- *
- * 2. License
- *
- * 2.1. This is your license from Intel Corp. under its intellectual property
- * rights. You may have additional license terms from the party that provided
- * you this software, covering your right to use that party's intellectual
- * property rights.
- *
- * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
- * copy of the source code appearing in this file ("Covered Code") an
- * irrevocable, perpetual, worldwide license under Intel's copyrights in the
- * base code distributed originally by Intel ("Original Intel Code") to copy,
- * make derivatives, distribute, use and display any portion of the Covered
- * Code in any form, with the right to sublicense such rights; and
- *
- * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
- * license (with the right to sublicense), under only those claims of Intel
- * patents that are infringed by the Original Intel Code, to make, use, sell,
- * offer to sell, and import the Covered Code and derivative works thereof
- * solely to the minimum extent necessary to exercise the above copyright
- * license, and in no event shall the patent license extend to any additions
- * to or modifications of the Original Intel Code. No other license or right
- * is granted directly or by implication, estoppel or otherwise;
- *
- * The above copyright and patent license is granted only if the following
- * conditions are met:
- *
- * 3. Conditions
- *
- * 3.1. Redistribution of Source with Rights to Further Distribute Source.
- * Redistribution of source code of any substantial portion of the Covered
- * Code or modification with rights to further distribute source must include
- * the above Copyright Notice, the above License, this list of Conditions,
- * and the following Disclaimer and Export Compliance provision. In addition,
- * Licensee must cause all Covered Code to which Licensee contributes to
- * contain a file documenting the changes Licensee made to create that Covered
- * Code and the date of any change. Licensee must include in that file the
- * documentation of any changes made by any predecessor Licensee. Licensee
- * must include a prominent statement that the modification is derived,
- * directly or indirectly, from Original Intel Code.
- *
- * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
- * Redistribution of source code of any substantial portion of the Covered
- * Code or modification without rights to further distribute source must
- * include the following Disclaimer and Export Compliance provision in the
- * documentation and/or other materials provided with distribution. In
- * addition, Licensee may not authorize further sublicense of source of any
- * portion of the Covered Code, and must include terms to the effect that the
- * license from Licensee to its licensee is limited to the intellectual
- * property embodied in the software Licensee provides to its licensee, and
- * not to intellectual property embodied in modifications its licensee may
- * make.
- *
- * 3.3. Redistribution of Executable. Redistribution in executable form of any
- * substantial portion of the Covered Code or modification must reproduce the
- * above Copyright Notice, and the following Disclaimer and Export Compliance
- * provision in the documentation and/or other materials provided with the
- * distribution.
- *
- * 3.4. Intel retains all right, title, and interest in and to the Original
- * Intel Code.
- *
- * 3.5. Neither the name Intel nor any other trademark owned or controlled by
- * Intel shall be used in advertising or otherwise to promote the sale, use or
- * other dealings in products derived from or relating to the Covered Code
- * without prior written authorization from Intel.
- *
- * 4. Disclaimer and Export Compliance
- *
- * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
- * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
- * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
- * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
- * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
- * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
- * PARTICULAR PURPOSE.
- *
- * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
- * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
- * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
- * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
- * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
- * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
- * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
- * LIMITED REMEDY.
- *
- * 4.3. Licensee shall not export, either directly or indirectly, any of this
- * software or system incorporating such software without first obtaining any
- * required license or other approval from the U. S. Department of Commerce or
- * any other agency or department of the United States Government. In the
- * event Licensee exports any such software from the United States or
- * re-exports any such software from a foreign destination, Licensee shall
- * ensure that the distribution and export/re-export of the software is in
- * compliance with all laws, regulations, orders, or other restrictions of the
- * U.S. Export Administration Regulations. Licensee agrees that neither it nor
- * any of its subsidiaries will export/re-export any technical data, process,
- * software, or service, directly or indirectly, to any country for which the
- * United States government or any agency thereof requires an export license,
- * other governmental approval, or letter of assurance, without first obtaining
- * such license, approval or letter.
- *
- *****************************************************************************/
-
-
-#define __PSFIND_C__
-
-#include "acpi.h"
-#include "acparser.h"
-#include "amlcode.h"
-
-#define _COMPONENT ACPI_PARSER
- ACPI_MODULE_NAME ("psfind")
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiPsGetParent
- *
- * PARAMETERS: Op - Get the parent of this Op
- *
- * RETURN: The Parent op.
- *
- * DESCRIPTION: Get op's parent
- *
- ******************************************************************************/
-
-ACPI_PARSE_OBJECT*
-AcpiPsGetParent (
- ACPI_PARSE_OBJECT *Op)
-{
- ACPI_PARSE_OBJECT *Parent = Op;
-
-
- /* Traverse the tree upward (to root if necessary) */
-
- while (Parent)
- {
- switch (Parent->Common.AmlOpcode)
- {
- case AML_SCOPE_OP:
- case AML_PACKAGE_OP:
- case AML_METHOD_OP:
- case AML_DEVICE_OP:
- case AML_POWER_RES_OP:
- case AML_THERMAL_ZONE_OP:
-
- return (Parent->Common.Parent);
-
- default:
- break;
- }
-
- Parent = Parent->Common.Parent;
- }
-
- return (Parent);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiPsFindName
- *
- * PARAMETERS: Scope - Scope to search
- * Name - ACPI name to search for
- * Opcode - Opcode to search for
- *
- * RETURN: Op containing the name
- *
- * DESCRIPTION: Find name segment from a list of acpi_ops. Searches a single
- * scope, no more.
- *
- ******************************************************************************/
-
-ACPI_PARSE_OBJECT *
-AcpiPsFindName (
- ACPI_PARSE_OBJECT *Scope,
- UINT32 Name,
- UINT32 Opcode)
-{
- ACPI_PARSE_OBJECT *Op;
- ACPI_PARSE_OBJECT *Field;
- const ACPI_OPCODE_INFO *OpInfo;
-
-
- /* search scope level for matching name segment */
-
- Op = AcpiPsGetChild (Scope);
-
- while (Op)
- {
- OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
-
- /* Check AML_CREATE first (since some opcodes have AML_FIELD set also )*/
-
- if (OpInfo->Flags & AML_CREATE)
- {
- if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
- {
- Field = AcpiPsGetArg (Op, 3);
- }
- else
- {
- /* CreateXXXField, check name */
-
- Field = AcpiPsGetArg (Op, 2);
- }
-
- if ((Field) &&
- (Field->Common.Value.String) &&
- (!ACPI_STRNCMP (Field->Common.Value.String, (char *) &Name, ACPI_NAME_SIZE)))
- {
- return (Op);
- }
- }
- else if (OpInfo->Flags & AML_FIELD)
- {
- /* Field, search named fields */
-
- Field = AcpiPsGetChild (Op);
- while (Field)
- {
- OpInfo = AcpiPsGetOpcodeInfo (Field->Common.AmlOpcode);
-
- if ((OpInfo->Flags & AML_NAMED) &&
- AcpiPsGetName (Field) == Name &&
- (!Opcode || Field->Common.AmlOpcode == Opcode))
- {
- return (Field);
- }
-
- Field = Field->Common.Next;
- }
- }
- else if ((OpInfo->Flags & AML_NAMED) &&
- (AcpiPsGetName (Op) == Name) &&
- (!Opcode || Op->Common.AmlOpcode == Opcode || Opcode == AML_SCOPE_OP))
- {
- break;
- }
-
- Op = Op->Common.Next;
- }
-
- return (Op);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiPsFind
- *
- * PARAMETERS: Scope - Where to begin the search
- * Path - ACPI Path to the named object
- * Opcode - Opcode associated with the object
- * Create - if TRUE, create the object if not found.
- *
- * RETURN: Op if found, NULL otherwise.
- *
- * DESCRIPTION: Find object within scope
- *
- ******************************************************************************/
-
-ACPI_PARSE_OBJECT*
-AcpiPsFind (
- ACPI_PARSE_OBJECT *Scope,
- NATIVE_CHAR *Path,
- UINT16 Opcode,
- UINT32 Create)
-{
- UINT32 SegCount;
- UINT32 Name;
- UINT32 NameOp;
- ACPI_PARSE_OBJECT *Op = NULL;
- BOOLEAN Unprefixed = TRUE;
-
-
- ACPI_FUNCTION_TRACE_PTR ("PsFind", Scope);
-
-
- if (!Scope || !Path)
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Null path (%p) or scope (%p)!\n",
- Path, Scope));
- return_PTR (NULL);
- }
-
- AcpiGbl_PsFindCount++;
-
-#if 0
- if ((Create) && (Opcode == AML_SCOPE_OP))
- {
- Op = AcpiPsAllocOp (AML_SCOPE_OP);
- if (Op)
- {
- AcpiPsSetName (Op, 'XXXX');
- AcpiPsAppendArg (Scope, Op);
- }
-/* return_PTR (Op);*/
- }
-#endif
-
- /* Handle all prefixes in the name path */
-
- while (AcpiPsIsPrefixChar (ACPI_GET8 (Path)))
- {
- switch (ACPI_GET8 (Path))
- {
- case '\\':
-
- /* Could just use a global for "root scope" here */
-
- while (Scope->Common.Parent)
- {
- Scope = Scope->Common.Parent;
- }
- break;
-
-
- case '^':
-
- /* Go up to the next valid scoping Op (method, scope, etc.) */
-
- if (AcpiPsGetParent (Scope))
- {
- Scope = AcpiPsGetParent (Scope);
- }
- break;
-
- default:
- /* Should not get here */
- break;
- }
-
- Unprefixed = FALSE;
- Path++;
- }
-
-
- /* get name segment count */
-
- switch (ACPI_GET8 (Path))
- {
- case 0:
- SegCount = 0;
-
- /* Null name case */
-
- if (Unprefixed)
- {
- Op = NULL;
- }
- else
- {
- Op = Scope;
- }
-
-
- ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
- "Null path, returning current root scope Op=%p\n", Op));
- return_PTR (Op);
-
- case AML_DUAL_NAME_PREFIX:
- SegCount = 2;
- Path++;
- break;
-
- case AML_MULTI_NAME_PREFIX_OP:
- SegCount = ACPI_GET8 (Path + 1);
- Path += 2;
- break;
-
- default:
- SegCount = 1;
- break;
- }
-
- ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
- "Search scope %p Segs=%d Opcode=%4.4hX Create=%d\n",
- Scope, SegCount, Opcode, Create));
-
-
- /* match each name segment */
-
- while (Scope && SegCount)
- {
- ACPI_MOVE_UNALIGNED32_TO_32 (&Name, Path);
- Path += 4;
- SegCount --;
-
- if (SegCount)
- {
- NameOp = 0;
- }
- else
- {
- NameOp = Opcode;
- }
-
- Op = AcpiPsFindName (Scope, Name, NameOp);
- if (Op)
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
- "[%4.4s] Found! Op=%p Opcode=%4.4hX\n",
- (char *) &Name, Op, Op->Common.AmlOpcode));
- }
-
- if (!Op)
- {
- if (Create)
- {
- /* Create a new Scope level */
-
- if (SegCount)
- {
- Op = AcpiPsAllocOp (AML_SCOPE_OP);
- }
- else
- {
- Op = AcpiPsAllocOp (Opcode);
- }
-
- if (Op)
- {
- AcpiPsSetName (Op, Name);
- AcpiPsAppendArg (Scope, Op);
-
- ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
- "[%4.4s] Not found, created Op=%p Opcode=%4.4hX\n",
- (char *) &Name, Op, Opcode));
- }
- }
-
- else if (Unprefixed)
- {
- /* Search higher scopes for unprefixed name */
-
- while (!Op && Scope->Common.Parent)
- {
- Scope = Scope->Common.Parent;
- Op = AcpiPsFindName (Scope, Name, Opcode);
- if (Op)
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
- "[%4.4s] Found in parent tree! Op=%p Opcode=%4.4hX\n",
- (char *) &Name, Op, Op->Common.AmlOpcode));
- }
- else
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
- "[%4.4s] Not found in parent=%p\n",
- (char *) &Name, Scope));
- }
- }
- }
- else
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
- "Segment [%4.4s] Not Found in scope %p!\n",
- (char *) &Name, Scope));
- }
- }
-
- Unprefixed = FALSE;
- Scope = Op;
- }
-
- return_PTR (Op);
-}
-
-
diff --git a/sys/dev/agp/agp.c b/sys/dev/agp/agp.c
deleted file mode 100644
index 5ff24465b232..000000000000
--- a/sys/dev/agp/agp.c
+++ /dev/null
@@ -1,811 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * 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$
- */
-
-#include "opt_bus.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/conf.h>
-#include <sys/ioccom.h>
-#include <sys/agpio.h>
-#include <sys/lock.h>
-#include <sys/lockmgr.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-
-#include <pci/pcivar.h>
-#include <pci/pcireg.h>
-#include <pci/agppriv.h>
-#include <pci/agpvar.h>
-#include <pci/agpreg.h>
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/vm_page.h>
-#include <vm/vm_pageout.h>
-#include <vm/pmap.h>
-
-#include <machine/md_var.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-MODULE_VERSION(agp, 1);
-
-MALLOC_DEFINE(M_AGP, "agp", "AGP data structures");
-
-#define CDEV_MAJOR 148
- /* agp_drv.c */
-static d_open_t agp_open;
-static d_close_t agp_close;
-static d_ioctl_t agp_ioctl;
-static d_mmap_t agp_mmap;
-
-static struct cdevsw agp_cdevsw = {
- .d_open = agp_open,
- .d_close = agp_close,
- .d_ioctl = agp_ioctl,
- .d_mmap = agp_mmap,
- .d_name = "agp",
- .d_maj = CDEV_MAJOR,
- .d_flags = D_TTY,
-};
-
-static devclass_t agp_devclass;
-#define KDEV2DEV(kdev) devclass_get_device(agp_devclass, minor(kdev))
-
-/* Helper functions for implementing chipset mini drivers. */
-
-void
-agp_flush_cache()
-{
-#ifdef __i386__
- wbinvd();
-#endif
-#ifdef __alpha__
- /* FIXME: This is most likely not correct as it doesn't flush CPU
- * write caches, but we don't have a facility to do that and
- * this is all linux does, too */
- alpha_mb();
-#endif
-}
-
-u_int8_t
-agp_find_caps(device_t dev)
-{
- u_int32_t status;
- u_int8_t ptr, next;
-
- /*
- * Check the CAP_LIST bit of the PCI status register first.
- */
- status = pci_read_config(dev, PCIR_STATUS, 2);
- if (!(status & 0x10))
- return 0;
-
- /*
- * Traverse the capabilities list.
- */
- for (ptr = pci_read_config(dev, AGP_CAPPTR, 1);
- ptr != 0;
- ptr = next) {
- u_int32_t capid = pci_read_config(dev, ptr, 4);
- next = AGP_CAPID_GET_NEXT_PTR(capid);
-
- /*
- * If this capability entry ID is 2, then we are done.
- */
- if (AGP_CAPID_GET_CAP_ID(capid) == 2)
- return ptr;
- }
-
- return 0;
-}
-
-/*
- * Find an AGP display device (if any).
- */
-static device_t
-agp_find_display(void)
-{
- devclass_t pci = devclass_find("pci");
- device_t bus, dev = 0;
- device_t *kids;
- int busnum, numkids, i;
-
- for (busnum = 0; busnum < devclass_get_maxunit(pci); busnum++) {
- bus = devclass_get_device(pci, busnum);
- if (!bus)
- continue;
- device_get_children(bus, &kids, &numkids);
- for (i = 0; i < numkids; i++) {
- dev = kids[i];
- if (pci_get_class(dev) == PCIC_DISPLAY
- && pci_get_subclass(dev) == PCIS_DISPLAY_VGA)
- if (agp_find_caps(dev)) {
- free(kids, M_TEMP);
- return dev;
- }
-
- }
- free(kids, M_TEMP);
- }
-
- return 0;
-}
-
-struct agp_gatt *
-agp_alloc_gatt(device_t dev)
-{
- u_int32_t apsize = AGP_GET_APERTURE(dev);
- u_int32_t entries = apsize >> AGP_PAGE_SHIFT;
- struct agp_gatt *gatt;
-
- if (bootverbose)
- device_printf(dev,
- "allocating GATT for aperture of size %dM\n",
- apsize / (1024*1024));
-
- gatt = malloc(sizeof(struct agp_gatt), M_AGP, M_NOWAIT);
- if (!gatt)
- return 0;
-
- gatt->ag_entries = entries;
- gatt->ag_virtual = contigmalloc(entries * sizeof(u_int32_t), M_AGP, 0,
- 0, ~0, PAGE_SIZE, 0);
- if (!gatt->ag_virtual) {
- if (bootverbose)
- device_printf(dev, "contiguous allocation failed\n");
- free(gatt, M_AGP);
- return 0;
- }
- bzero(gatt->ag_virtual, entries * sizeof(u_int32_t));
- gatt->ag_physical = vtophys((vm_offset_t) gatt->ag_virtual);
- agp_flush_cache();
-
- return gatt;
-}
-
-void
-agp_free_gatt(struct agp_gatt *gatt)
-{
- contigfree(gatt->ag_virtual,
- gatt->ag_entries * sizeof(u_int32_t), M_AGP);
- free(gatt, M_AGP);
-}
-
-static int agp_max[][2] = {
- {0, 0},
- {32, 4},
- {64, 28},
- {128, 96},
- {256, 204},
- {512, 440},
- {1024, 942},
- {2048, 1920},
- {4096, 3932}
-};
-#define agp_max_size (sizeof(agp_max) / sizeof(agp_max[0]))
-
-int
-agp_generic_attach(device_t dev)
-{
- struct agp_softc *sc = device_get_softc(dev);
- int rid, memsize, i;
-
- /*
- * Find and map the aperture.
- */
- rid = AGP_APBASE;
- sc->as_aperture = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
- 0, ~0, 1, RF_ACTIVE);
- if (!sc->as_aperture)
- return ENOMEM;
-
- /*
- * Work out an upper bound for agp memory allocation. This
- * uses a heurisitc table from the Linux driver.
- */
- memsize = ptoa(Maxmem) >> 20;
- for (i = 0; i < agp_max_size; i++) {
- if (memsize <= agp_max[i][0])
- break;
- }
- if (i == agp_max_size) i = agp_max_size - 1;
- sc->as_maxmem = agp_max[i][1] << 20U;
-
- /*
- * The lock is used to prevent re-entry to
- * agp_generic_bind_memory() since that function can sleep.
- */
- lockinit(&sc->as_lock, PZERO|PCATCH, "agplk", 0, 0);
-
- /*
- * Initialise stuff for the userland device.
- */
- agp_devclass = devclass_find("agp");
- TAILQ_INIT(&sc->as_memory);
- sc->as_nextid = 1;
-
- sc->as_devnode = make_dev(&agp_cdevsw,
- device_get_unit(dev),
- UID_ROOT,
- GID_WHEEL,
- 0600,
- "agpgart");
-
- return 0;
-}
-
-int
-agp_generic_detach(device_t dev)
-{
- struct agp_softc *sc = device_get_softc(dev);
- bus_release_resource(dev, SYS_RES_MEMORY, AGP_APBASE, sc->as_aperture);
- lockmgr(&sc->as_lock, LK_DRAIN, 0, curthread);
- lockdestroy(&sc->as_lock);
- destroy_dev(sc->as_devnode);
- agp_flush_cache();
- return 0;
-}
-
-int
-agp_generic_enable(device_t dev, u_int32_t mode)
-{
- device_t mdev = agp_find_display();
- u_int32_t tstatus, mstatus;
- u_int32_t command;
- int rq, sba, fw, rate;;
-
- if (!mdev) {
- AGP_DPF("can't find display\n");
- return ENXIO;
- }
-
- tstatus = pci_read_config(dev, agp_find_caps(dev) + AGP_STATUS, 4);
- mstatus = pci_read_config(mdev, agp_find_caps(mdev) + AGP_STATUS, 4);
-
- /* Set RQ to the min of mode, tstatus and mstatus */
- rq = AGP_MODE_GET_RQ(mode);
- if (AGP_MODE_GET_RQ(tstatus) < rq)
- rq = AGP_MODE_GET_RQ(tstatus);
- if (AGP_MODE_GET_RQ(mstatus) < rq)
- rq = AGP_MODE_GET_RQ(mstatus);
-
- /* Set SBA if all three can deal with SBA */
- sba = (AGP_MODE_GET_SBA(tstatus)
- & AGP_MODE_GET_SBA(mstatus)
- & AGP_MODE_GET_SBA(mode));
-
- /* Similar for FW */
- fw = (AGP_MODE_GET_FW(tstatus)
- & AGP_MODE_GET_FW(mstatus)
- & AGP_MODE_GET_FW(mode));
-
- /* Figure out the max rate */
- rate = (AGP_MODE_GET_RATE(tstatus)
- & AGP_MODE_GET_RATE(mstatus)
- & AGP_MODE_GET_RATE(mode));
- if (rate & AGP_MODE_RATE_4x)
- rate = AGP_MODE_RATE_4x;
- else if (rate & AGP_MODE_RATE_2x)
- rate = AGP_MODE_RATE_2x;
- else
- rate = AGP_MODE_RATE_1x;
-
- /* Construct the new mode word and tell the hardware */
- command = AGP_MODE_SET_RQ(0, rq);
- command = AGP_MODE_SET_SBA(command, sba);
- command = AGP_MODE_SET_FW(command, fw);
- command = AGP_MODE_SET_RATE(command, rate);
- command = AGP_MODE_SET_AGP(command, 1);
- pci_write_config(dev, agp_find_caps(dev) + AGP_COMMAND, command, 4);
- pci_write_config(mdev, agp_find_caps(mdev) + AGP_COMMAND, command, 4);
-
- return 0;
-}
-
-struct agp_memory *
-agp_generic_alloc_memory(device_t dev, int type, vm_size_t size)
-{
- struct agp_softc *sc = device_get_softc(dev);
- struct agp_memory *mem;
-
- if ((size & (AGP_PAGE_SIZE - 1)) != 0)
- return 0;
-
- if (sc->as_allocated + size > sc->as_maxmem)
- return 0;
-
- if (type != 0) {
- printf("agp_generic_alloc_memory: unsupported type %d\n",
- type);
- return 0;
- }
-
- mem = malloc(sizeof *mem, M_AGP, M_WAITOK);
- mem->am_id = sc->as_nextid++;
- mem->am_size = size;
- mem->am_type = 0;
- mem->am_obj = vm_object_allocate(OBJT_DEFAULT, atop(round_page(size)));
- mem->am_physical = 0;
- mem->am_offset = 0;
- mem->am_is_bound = 0;
- TAILQ_INSERT_TAIL(&sc->as_memory, mem, am_link);
- sc->as_allocated += size;
-
- return mem;
-}
-
-int
-agp_generic_free_memory(device_t dev, struct agp_memory *mem)
-{
- struct agp_softc *sc = device_get_softc(dev);
-
- if (mem->am_is_bound)
- return EBUSY;
-
- sc->as_allocated -= mem->am_size;
- TAILQ_REMOVE(&sc->as_memory, mem, am_link);
- vm_object_deallocate(mem->am_obj);
- free(mem, M_AGP);
- return 0;
-}
-
-int
-agp_generic_bind_memory(device_t dev, struct agp_memory *mem,
- vm_offset_t offset)
-{
- struct agp_softc *sc = device_get_softc(dev);
- vm_offset_t i, j, k;
- vm_page_t m;
- int error;
-
- lockmgr(&sc->as_lock, LK_EXCLUSIVE, 0, curthread);
-
- if (mem->am_is_bound) {
- device_printf(dev, "memory already bound\n");
- return EINVAL;
- }
-
- if (offset < 0
- || (offset & (AGP_PAGE_SIZE - 1)) != 0
- || offset + mem->am_size > AGP_GET_APERTURE(dev)) {
- device_printf(dev, "binding memory at bad offset %#x\n",
- (int) offset);
- return EINVAL;
- }
-
- /*
- * Bind the individual pages and flush the chipset's
- * TLB.
- *
- * XXX Presumably, this needs to be the pci address on alpha
- * (i.e. use alpha_XXX_dmamap()). I don't have access to any
- * alpha AGP hardware to check.
- */
- for (i = 0; i < mem->am_size; i += PAGE_SIZE) {
- /*
- * Find a page from the object and wire it
- * down. This page will be mapped using one or more
- * entries in the GATT (assuming that PAGE_SIZE >=
- * AGP_PAGE_SIZE. If this is the first call to bind,
- * the pages will be allocated and zeroed.
- */
- m = vm_page_grab(mem->am_obj, OFF_TO_IDX(i),
- VM_ALLOC_WIRED | VM_ALLOC_ZERO | VM_ALLOC_RETRY);
- if ((m->flags & PG_ZERO) == 0)
- pmap_zero_page(m);
- AGP_DPF("found page pa=%#x\n", VM_PAGE_TO_PHYS(m));
-
- /*
- * Install entries in the GATT, making sure that if
- * AGP_PAGE_SIZE < PAGE_SIZE and mem->am_size is not
- * aligned to PAGE_SIZE, we don't modify too many GATT
- * entries.
- */
- for (j = 0; j < PAGE_SIZE && i + j < mem->am_size;
- j += AGP_PAGE_SIZE) {
- vm_offset_t pa = VM_PAGE_TO_PHYS(m) + j;
- AGP_DPF("binding offset %#x to pa %#x\n",
- offset + i + j, pa);
- error = AGP_BIND_PAGE(dev, offset + i + j, pa);
- if (error) {
- /*
- * Bail out. Reverse all the mappings
- * and unwire the pages.
- */
- vm_page_lock_queues();
- vm_page_wakeup(m);
- vm_page_unlock_queues();
- for (k = 0; k < i + j; k += AGP_PAGE_SIZE)
- AGP_UNBIND_PAGE(dev, offset + k);
- for (k = 0; k <= i; k += PAGE_SIZE) {
- m = vm_page_lookup(mem->am_obj,
- OFF_TO_IDX(k));
- vm_page_lock_queues();
- vm_page_unwire(m, 0);
- vm_page_unlock_queues();
- }
- lockmgr(&sc->as_lock, LK_RELEASE, 0, curthread);
- return error;
- }
- }
- vm_page_lock_queues();
- vm_page_wakeup(m);
- vm_page_unlock_queues();
- }
-
- /*
- * Flush the cpu cache since we are providing a new mapping
- * for these pages.
- */
- agp_flush_cache();
-
- /*
- * Make sure the chipset gets the new mappings.
- */
- AGP_FLUSH_TLB(dev);
-
- mem->am_offset = offset;
- mem->am_is_bound = 1;
-
- lockmgr(&sc->as_lock, LK_RELEASE, 0, curthread);
-
- return 0;
-}
-
-int
-agp_generic_unbind_memory(device_t dev, struct agp_memory *mem)
-{
- struct agp_softc *sc = device_get_softc(dev);
- vm_page_t m;
- int i;
-
- lockmgr(&sc->as_lock, LK_EXCLUSIVE, 0, curthread);
-
- if (!mem->am_is_bound) {
- device_printf(dev, "memory is not bound\n");
- return EINVAL;
- }
-
-
- /*
- * Unbind the individual pages and flush the chipset's
- * TLB. Unwire the pages so they can be swapped.
- */
- for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
- AGP_UNBIND_PAGE(dev, mem->am_offset + i);
- for (i = 0; i < mem->am_size; i += PAGE_SIZE) {
- m = vm_page_lookup(mem->am_obj, atop(i));
- vm_page_lock_queues();
- vm_page_unwire(m, 0);
- vm_page_unlock_queues();
- }
-
- agp_flush_cache();
- AGP_FLUSH_TLB(dev);
-
- mem->am_offset = 0;
- mem->am_is_bound = 0;
-
- lockmgr(&sc->as_lock, LK_RELEASE, 0, curthread);
-
- return 0;
-}
-
-/* Helper functions for implementing user/kernel api */
-
-static int
-agp_acquire_helper(device_t dev, enum agp_acquire_state state)
-{
- struct agp_softc *sc = device_get_softc(dev);
-
- if (sc->as_state != AGP_ACQUIRE_FREE)
- return EBUSY;
- sc->as_state = state;
-
- return 0;
-}
-
-static int
-agp_release_helper(device_t dev, enum agp_acquire_state state)
-{
- struct agp_softc *sc = device_get_softc(dev);
-
- if (sc->as_state == AGP_ACQUIRE_FREE)
- return 0;
-
- if (sc->as_state != state)
- return EBUSY;
-
- sc->as_state = AGP_ACQUIRE_FREE;
- return 0;
-}
-
-static struct agp_memory *
-agp_find_memory(device_t dev, int id)
-{
- struct agp_softc *sc = device_get_softc(dev);
- struct agp_memory *mem;
-
- AGP_DPF("searching for memory block %d\n", id);
- TAILQ_FOREACH(mem, &sc->as_memory, am_link) {
- AGP_DPF("considering memory block %d\n", mem->am_id);
- if (mem->am_id == id)
- return mem;
- }
- return 0;
-}
-
-/* Implementation of the userland ioctl api */
-
-static int
-agp_info_user(device_t dev, agp_info *info)
-{
- struct agp_softc *sc = device_get_softc(dev);
-
- bzero(info, sizeof *info);
- info->bridge_id = pci_get_devid(dev);
- info->agp_mode =
- pci_read_config(dev, agp_find_caps(dev) + AGP_STATUS, 4);
- info->aper_base = rman_get_start(sc->as_aperture);
- info->aper_size = AGP_GET_APERTURE(dev) >> 20;
- info->pg_total = info->pg_system = sc->as_maxmem >> AGP_PAGE_SHIFT;
- info->pg_used = sc->as_allocated >> AGP_PAGE_SHIFT;
-
- return 0;
-}
-
-static int
-agp_setup_user(device_t dev, agp_setup *setup)
-{
- return AGP_ENABLE(dev, setup->agp_mode);
-}
-
-static int
-agp_allocate_user(device_t dev, agp_allocate *alloc)
-{
- struct agp_memory *mem;
-
- mem = AGP_ALLOC_MEMORY(dev,
- alloc->type,
- alloc->pg_count << AGP_PAGE_SHIFT);
- if (mem) {
- alloc->key = mem->am_id;
- alloc->physical = mem->am_physical;
- return 0;
- } else {
- return ENOMEM;
- }
-}
-
-static int
-agp_deallocate_user(device_t dev, int id)
-{
- struct agp_memory *mem = agp_find_memory(dev, id);;
-
- if (mem) {
- AGP_FREE_MEMORY(dev, mem);
- return 0;
- } else {
- return ENOENT;
- }
-}
-
-static int
-agp_bind_user(device_t dev, agp_bind *bind)
-{
- struct agp_memory *mem = agp_find_memory(dev, bind->key);
-
- if (!mem)
- return ENOENT;
-
- return AGP_BIND_MEMORY(dev, mem, bind->pg_start << AGP_PAGE_SHIFT);
-}
-
-static int
-agp_unbind_user(device_t dev, agp_unbind *unbind)
-{
- struct agp_memory *mem = agp_find_memory(dev, unbind->key);
-
- if (!mem)
- return ENOENT;
-
- return AGP_UNBIND_MEMORY(dev, mem);
-}
-
-static int
-agp_open(dev_t kdev, int oflags, int devtype, struct thread *td)
-{
- device_t dev = KDEV2DEV(kdev);
- struct agp_softc *sc = device_get_softc(dev);
-
- if (!sc->as_isopen) {
- sc->as_isopen = 1;
- device_busy(dev);
- }
-
- return 0;
-}
-
-static int
-agp_close(dev_t kdev, int fflag, int devtype, struct thread *td)
-{
- device_t dev = KDEV2DEV(kdev);
- struct agp_softc *sc = device_get_softc(dev);
- struct agp_memory *mem;
-
- /*
- * Clear the GATT and force release on last close
- */
- while ((mem = TAILQ_FIRST(&sc->as_memory)) != 0) {
- if (mem->am_is_bound)
- AGP_UNBIND_MEMORY(dev, mem);
- AGP_FREE_MEMORY(dev, mem);
- }
- if (sc->as_state == AGP_ACQUIRE_USER)
- agp_release_helper(dev, AGP_ACQUIRE_USER);
- sc->as_isopen = 0;
- device_unbusy(dev);
-
- return 0;
-}
-
-static int
-agp_ioctl(dev_t kdev, u_long cmd, caddr_t data, int fflag, struct thread *td)
-{
- device_t dev = KDEV2DEV(kdev);
-
- switch (cmd) {
- case AGPIOC_INFO:
- return agp_info_user(dev, (agp_info *) data);
-
- case AGPIOC_ACQUIRE:
- return agp_acquire_helper(dev, AGP_ACQUIRE_USER);
-
- case AGPIOC_RELEASE:
- return agp_release_helper(dev, AGP_ACQUIRE_USER);
-
- case AGPIOC_SETUP:
- return agp_setup_user(dev, (agp_setup *)data);
-
- case AGPIOC_ALLOCATE:
- return agp_allocate_user(dev, (agp_allocate *)data);
-
- case AGPIOC_DEALLOCATE:
- return agp_deallocate_user(dev, *(int *) data);
-
- case AGPIOC_BIND:
- return agp_bind_user(dev, (agp_bind *)data);
-
- case AGPIOC_UNBIND:
- return agp_unbind_user(dev, (agp_unbind *)data);
-
- }
-
- return EINVAL;
-}
-
-static int
-agp_mmap(dev_t kdev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
-{
- device_t dev = KDEV2DEV(kdev);
- struct agp_softc *sc = device_get_softc(dev);
-
- if (offset > AGP_GET_APERTURE(dev))
- return -1;
- *paddr = rman_get_start(sc->as_aperture) + offset;
- return 0;
-}
-
-/* Implementation of the kernel api */
-
-device_t
-agp_find_device()
-{
- if (!agp_devclass)
- return 0;
- return devclass_get_device(agp_devclass, 0);
-}
-
-enum agp_acquire_state
-agp_state(device_t dev)
-{
- struct agp_softc *sc = device_get_softc(dev);
- return sc->as_state;
-}
-
-void
-agp_get_info(device_t dev, struct agp_info *info)
-{
- struct agp_softc *sc = device_get_softc(dev);
-
- info->ai_mode =
- pci_read_config(dev, agp_find_caps(dev) + AGP_STATUS, 4);
- info->ai_aperture_base = rman_get_start(sc->as_aperture);
- info->ai_aperture_size = rman_get_size(sc->as_aperture);
- info->ai_aperture_va = (vm_offset_t) rman_get_virtual(sc->as_aperture);
- info->ai_memory_allowed = sc->as_maxmem;
- info->ai_memory_used = sc->as_allocated;
-}
-
-int
-agp_acquire(device_t dev)
-{
- return agp_acquire_helper(dev, AGP_ACQUIRE_KERNEL);
-}
-
-int
-agp_release(device_t dev)
-{
- return agp_release_helper(dev, AGP_ACQUIRE_KERNEL);
-}
-
-int
-agp_enable(device_t dev, u_int32_t mode)
-{
- return AGP_ENABLE(dev, mode);
-}
-
-void *agp_alloc_memory(device_t dev, int type, vm_size_t bytes)
-{
- return (void *) AGP_ALLOC_MEMORY(dev, type, bytes);
-}
-
-void agp_free_memory(device_t dev, void *handle)
-{
- struct agp_memory *mem = (struct agp_memory *) handle;
- AGP_FREE_MEMORY(dev, mem);
-}
-
-int agp_bind_memory(device_t dev, void *handle, vm_offset_t offset)
-{
- struct agp_memory *mem = (struct agp_memory *) handle;
- return AGP_BIND_MEMORY(dev, mem, offset);
-}
-
-int agp_unbind_memory(device_t dev, void *handle)
-{
- struct agp_memory *mem = (struct agp_memory *) handle;
- return AGP_UNBIND_MEMORY(dev, mem);
-}
-
-void agp_memory_info(device_t dev, void *handle, struct
- agp_memory_info *mi)
-{
- struct agp_memory *mem = (struct agp_memory *) handle;
-
- mi->ami_size = mem->am_size;
- mi->ami_physical = mem->am_physical;
- mi->ami_offset = mem->am_offset;
- mi->ami_is_bound = mem->am_is_bound;
-}
diff --git a/sys/dev/agp/agp_ali.c b/sys/dev/agp/agp_ali.c
deleted file mode 100644
index f89d14be7753..000000000000
--- a/sys/dev/agp/agp_ali.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * 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$
- */
-
-#include "opt_bus.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/lock.h>
-#include <sys/lockmgr.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-
-#include <pci/pcivar.h>
-#include <pci/pcireg.h>
-#include <pci/agppriv.h>
-#include <pci/agpreg.h>
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/pmap.h>
-
-struct agp_ali_softc {
- struct agp_softc agp;
- u_int32_t initial_aperture; /* aperture size at startup */
- struct agp_gatt *gatt;
-};
-
-static const char*
-agp_ali_match(device_t dev)
-{
- if (pci_get_class(dev) != PCIC_BRIDGE
- || pci_get_subclass(dev) != PCIS_BRIDGE_HOST)
- return NULL;
-
- if (agp_find_caps(dev) == 0)
- return NULL;
-
- switch (pci_get_devid(dev)) {
- case 0x154110b9:
- return ("Ali M1541 host to AGP bridge");
- };
-
- if (pci_get_vendor(dev) == 0x10b9)
- return ("Ali Generic host to PCI bridge");
-
- return NULL;
-}
-
-static int
-agp_ali_probe(device_t dev)
-{
- const char *desc;
-
- desc = agp_ali_match(dev);
- if (desc) {
- device_verbose(dev);
- device_set_desc(dev, desc);
- return 0;
- }
-
- return ENXIO;
-}
-
-static int
-agp_ali_attach(device_t dev)
-{
- struct agp_ali_softc *sc = device_get_softc(dev);
- struct agp_gatt *gatt;
- int error;
-
- error = agp_generic_attach(dev);
- if (error)
- return error;
-
- sc->initial_aperture = AGP_GET_APERTURE(dev);
-
- for (;;) {
- gatt = agp_alloc_gatt(dev);
- if (gatt)
- break;
-
- /*
- * Probably contigmalloc failure. Try reducing the
- * aperture so that the gatt size reduces.
- */
- if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2)) {
- agp_generic_detach(dev);
- return ENOMEM;
- }
- }
- sc->gatt = gatt;
-
- /* Install the gatt. */
- pci_write_config(dev, AGP_ALI_ATTBASE,
- (gatt->ag_physical
- | (pci_read_config(dev, AGP_ALI_ATTBASE, 4) & 0xff)),
- 4);
-
- /* Enable the TLB. */
- pci_write_config(dev, AGP_ALI_TLBCTRL, 0x10, 1);
-
- return 0;
-}
-
-static int
-agp_ali_detach(device_t dev)
-{
- struct agp_ali_softc *sc = device_get_softc(dev);
- int error;
-
- error = agp_generic_detach(dev);
- if (error)
- return error;
-
- /* Disable the TLB.. */
- pci_write_config(dev, AGP_ALI_TLBCTRL, 0x90, 1);
-
- /* Put the aperture back the way it started. */
- AGP_SET_APERTURE(dev, sc->initial_aperture);
- pci_write_config(dev, AGP_ALI_ATTBASE,
- pci_read_config(dev, AGP_ALI_ATTBASE, 4) & 0xff,
- 4);
-
- agp_free_gatt(sc->gatt);
- return 0;
-}
-
-#define M 1024*1024
-
-static u_int32_t agp_ali_table[] = {
- 0, /* 0 - invalid */
- 1, /* 1 - invalid */
- 2, /* 2 - invalid */
- 4*M, /* 3 - invalid */
- 8*M, /* 4 - invalid */
- 0, /* 5 - invalid */
- 16*M, /* 6 - invalid */
- 32*M, /* 7 - invalid */
- 64*M, /* 8 - invalid */
- 128*M, /* 9 - invalid */
- 256*M, /* 10 - invalid */
-};
-#define agp_ali_table_size (sizeof(agp_ali_table) / sizeof(agp_ali_table[0]))
-
-static u_int32_t
-agp_ali_get_aperture(device_t dev)
-{
- /*
- * The aperture size is derived from the low bits of attbase.
- * I'm not sure this is correct..
- */
- int i = pci_read_config(dev, AGP_ALI_ATTBASE, 4) & 0xff;
- if (i >= agp_ali_table_size)
- return 0;
- return agp_ali_table[i];
-}
-
-static int
-agp_ali_set_aperture(device_t dev, u_int32_t aperture)
-{
- int i;
-
- for (i = 0; i < agp_ali_table_size; i++)
- if (agp_ali_table[i] == aperture)
- break;
- if (i == agp_ali_table_size)
- return EINVAL;
-
- pci_write_config(dev, AGP_ALI_ATTBASE,
- ((pci_read_config(dev, AGP_ALI_ATTBASE, 4) & ~0xff)
- | i), 4);
- return 0;
-}
-
-static int
-agp_ali_bind_page(device_t dev, int offset, vm_offset_t physical)
-{
- struct agp_ali_softc *sc = device_get_softc(dev);
-
- if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
- return EINVAL;
-
- sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical;
- return 0;
-}
-
-static int
-agp_ali_unbind_page(device_t dev, int offset)
-{
- struct agp_ali_softc *sc = device_get_softc(dev);
-
- if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
- return EINVAL;
-
- sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0;
- return 0;
-}
-
-static void
-agp_ali_flush_tlb(device_t dev)
-{
- pci_write_config(dev, AGP_ALI_TLBCTRL, 0x90, 1);
- pci_write_config(dev, AGP_ALI_TLBCTRL, 0x10, 1);
-}
-
-static device_method_t agp_ali_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, agp_ali_probe),
- DEVMETHOD(device_attach, agp_ali_attach),
- DEVMETHOD(device_detach, agp_ali_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /* AGP interface */
- DEVMETHOD(agp_get_aperture, agp_ali_get_aperture),
- DEVMETHOD(agp_set_aperture, agp_ali_set_aperture),
- DEVMETHOD(agp_bind_page, agp_ali_bind_page),
- DEVMETHOD(agp_unbind_page, agp_ali_unbind_page),
- DEVMETHOD(agp_flush_tlb, agp_ali_flush_tlb),
- DEVMETHOD(agp_enable, agp_generic_enable),
- DEVMETHOD(agp_alloc_memory, agp_generic_alloc_memory),
- DEVMETHOD(agp_free_memory, agp_generic_free_memory),
- DEVMETHOD(agp_bind_memory, agp_generic_bind_memory),
- DEVMETHOD(agp_unbind_memory, agp_generic_unbind_memory),
-
- { 0, 0 }
-};
-
-static driver_t agp_ali_driver = {
- "agp",
- agp_ali_methods,
- sizeof(struct agp_ali_softc),
-};
-
-static devclass_t agp_devclass;
-
-DRIVER_MODULE(agp_ali, pci, agp_ali_driver, agp_devclass, 0, 0);
-MODULE_DEPEND(agp_ali, agp, 1, 1, 1);
-MODULE_DEPEND(agp_ali, pci, 1, 1, 1);
diff --git a/sys/dev/agp/agp_amd.c b/sys/dev/agp/agp_amd.c
deleted file mode 100644
index 24e3cc9a15fb..000000000000
--- a/sys/dev/agp/agp_amd.c
+++ /dev/null
@@ -1,421 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * 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$
- */
-
-#include "opt_bus.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/lock.h>
-#include <sys/lockmgr.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-
-#include <pci/pcivar.h>
-#include <pci/pcireg.h>
-#include <pci/agppriv.h>
-#include <pci/agpreg.h>
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/pmap.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-MALLOC_DECLARE(M_AGP);
-
-#define READ2(off) bus_space_read_2(sc->bst, sc->bsh, off)
-#define READ4(off) bus_space_read_4(sc->bst, sc->bsh, off)
-#define WRITE2(off,v) bus_space_write_2(sc->bst, sc->bsh, off, v)
-#define WRITE4(off,v) bus_space_write_4(sc->bst, sc->bsh, off, v)
-
-struct agp_amd_gatt {
- u_int32_t ag_entries;
- u_int32_t *ag_virtual; /* virtual address of gatt */
- vm_offset_t ag_physical;
- u_int32_t *ag_vdir; /* virtual address of page dir */
- vm_offset_t ag_pdir; /* physical address of page dir */
-};
-
-struct agp_amd_softc {
- struct agp_softc agp;
- struct resource *regs; /* memory mapped control registers */
- bus_space_tag_t bst; /* bus_space tag */
- bus_space_handle_t bsh; /* bus_space handle */
- u_int32_t initial_aperture; /* aperture size at startup */
- struct agp_amd_gatt *gatt;
-};
-
-static struct agp_amd_gatt *
-agp_amd_alloc_gatt(device_t dev)
-{
- u_int32_t apsize = AGP_GET_APERTURE(dev);
- u_int32_t entries = apsize >> AGP_PAGE_SHIFT;
- struct agp_amd_gatt *gatt;
- int i, npages, pdir_offset;
-
- if (bootverbose)
- device_printf(dev,
- "allocating GATT for aperture of size %dM\n",
- apsize / (1024*1024));
-
- gatt = malloc(sizeof(struct agp_amd_gatt), M_AGP, M_NOWAIT);
- if (!gatt)
- return 0;
-
- /*
- * The AMD751 uses a page directory to map a non-contiguous
- * gatt so we don't need to use contigmalloc.
- * Malloc individual gatt pages and map them into the page
- * directory.
- */
- gatt->ag_entries = entries;
- gatt->ag_virtual = malloc(entries * sizeof(u_int32_t),
- M_AGP, M_NOWAIT);
- if (!gatt->ag_virtual) {
- if (bootverbose)
- device_printf(dev, "allocation failed\n");
- free(gatt, M_AGP);
- return 0;
- }
- bzero(gatt->ag_virtual, entries * sizeof(u_int32_t));
-
- /*
- * Allocate the page directory.
- */
- gatt->ag_vdir = malloc(AGP_PAGE_SIZE, M_AGP, M_NOWAIT);
- if (!gatt->ag_vdir) {
- if (bootverbose)
- device_printf(dev,
- "failed to allocate page directory\n");
- free(gatt->ag_virtual, M_AGP);
- free(gatt, M_AGP);
- return 0;
- }
- bzero(gatt->ag_vdir, AGP_PAGE_SIZE);
-
- gatt->ag_pdir = vtophys((vm_offset_t) gatt->ag_vdir);
- if(bootverbose)
- device_printf(dev, "gatt -> ag_pdir %#lx\n",
- (u_long)gatt->ag_pdir);
- /*
- * Allocate the gatt pages
- */
- gatt->ag_entries = entries;
- if(bootverbose)
- device_printf(dev, "allocating GATT for %d AGP page entries\n",
- gatt->ag_entries);
-
- gatt->ag_physical = vtophys((vm_offset_t) gatt->ag_virtual);
-
- /*
- * Map the pages of the GATT into the page directory.
- *
- * The GATT page addresses are mapped into the directory offset by
- * an amount dependent on the base address of the aperture. This
- * is and offset into the page directory, not an offset added to
- * the addresses of the gatt pages.
- */
-
- pdir_offset = pci_read_config(dev, AGP_AMD751_APBASE, 4) >> 22;
-
- npages = ((entries * sizeof(u_int32_t) + AGP_PAGE_SIZE - 1)
- >> AGP_PAGE_SHIFT);
-
- for (i = 0; i < npages; i++) {
- vm_offset_t va;
- vm_offset_t pa;
-
- va = ((vm_offset_t) gatt->ag_virtual) + i * AGP_PAGE_SIZE;
- pa = vtophys(va);
- gatt->ag_vdir[i + pdir_offset] = pa | 1;
- }
-
- /*
- * Make sure the chipset can see everything.
- */
- agp_flush_cache();
-
- return gatt;
-}
-
-static void
-agp_amd_free_gatt(struct agp_amd_gatt *gatt)
-{
- free(gatt->ag_virtual, M_AGP);
- free(gatt->ag_vdir, M_AGP);
- free(gatt, M_AGP);
-}
-
-static const char*
-agp_amd_match(device_t dev)
-{
- if (pci_get_class(dev) != PCIC_BRIDGE
- || pci_get_subclass(dev) != PCIS_BRIDGE_HOST)
- return NULL;
-
- if (agp_find_caps(dev) == 0)
- return NULL;
-
- switch (pci_get_devid(dev)) {
-
- case 0x700e1022:
- return ("AMD 761 host to AGP bridge");
-
- case 0x70061022:
- return ("AMD 751 host to AGP bridge");
-
- case 0x700c1022:
- return ("AMD 762 host to AGP bridge");
-
- };
-
- return NULL;
-}
-
-static int
-agp_amd_probe(device_t dev)
-{
- const char *desc;
-
- desc = agp_amd_match(dev);
- if (desc) {
- device_verbose(dev);
- device_set_desc(dev, desc);
- return 0;
- }
-
- return ENXIO;
-}
-
-static int
-agp_amd_attach(device_t dev)
-{
- struct agp_amd_softc *sc = device_get_softc(dev);
- struct agp_amd_gatt *gatt;
- int error, rid;
-
- error = agp_generic_attach(dev);
- if (error)
- return error;
-
- rid = AGP_AMD751_REGISTERS;
- sc->regs = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
- 0, ~0, 1, RF_ACTIVE);
- if (!sc->regs) {
- agp_generic_detach(dev);
- return ENOMEM;
- }
-
- sc->bst = rman_get_bustag(sc->regs);
- sc->bsh = rman_get_bushandle(sc->regs);
-
- sc->initial_aperture = AGP_GET_APERTURE(dev);
-
- for (;;) {
- gatt = agp_amd_alloc_gatt(dev);
- if (gatt)
- break;
-
- /*
- * Probably contigmalloc failure. Try reducing the
- * aperture so that the gatt size reduces.
- */
- if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2))
- return ENOMEM;
- }
- sc->gatt = gatt;
-
- /* Install the gatt. */
- WRITE4(AGP_AMD751_ATTBASE, gatt->ag_pdir);
-
- /* Enable synchronisation between host and agp. */
- pci_write_config(dev,
- AGP_AMD751_MODECTRL,
- AGP_AMD751_MODECTRL_SYNEN, 1);
-
- /* Set indexing mode for two-level and enable page dir cache */
- pci_write_config(dev,
- AGP_AMD751_MODECTRL2,
- AGP_AMD751_MODECTRL2_GPDCE, 1);
-
- /* Enable the TLB and flush */
- WRITE2(AGP_AMD751_STATUS,
- READ2(AGP_AMD751_STATUS) | AGP_AMD751_STATUS_GCE);
- AGP_FLUSH_TLB(dev);
-
- return 0;
-}
-
-static int
-agp_amd_detach(device_t dev)
-{
- struct agp_amd_softc *sc = device_get_softc(dev);
- int error;
-
- error = agp_generic_detach(dev);
- if (error)
- return error;
-
- /* Disable the TLB.. */
- WRITE2(AGP_AMD751_STATUS,
- READ2(AGP_AMD751_STATUS) & ~AGP_AMD751_STATUS_GCE);
-
- /* Disable host-agp sync */
- pci_write_config(dev, AGP_AMD751_MODECTRL, 0x00, 1);
-
- /* Clear the GATT base */
- WRITE4(AGP_AMD751_ATTBASE, 0);
-
- /* Put the aperture back the way it started. */
- AGP_SET_APERTURE(dev, sc->initial_aperture);
-
- agp_amd_free_gatt(sc->gatt);
-
- bus_release_resource(dev, SYS_RES_MEMORY,
- AGP_AMD751_REGISTERS, sc->regs);
-
- return 0;
-}
-
-static u_int32_t
-agp_amd_get_aperture(device_t dev)
-{
- int vas;
-
- /*
- * The aperture size is equal to 32M<<vas.
- */
- vas = (pci_read_config(dev, AGP_AMD751_APCTRL, 1) & 0x06) >> 1;
- return (32*1024*1024) << vas;
-}
-
-static int
-agp_amd_set_aperture(device_t dev, u_int32_t aperture)
-{
- int vas;
-
- /*
- * Check for a power of two and make sure its within the
- * programmable range.
- */
- if (aperture & (aperture - 1)
- || aperture < 32*1024*1024
- || aperture > 2U*1024*1024*1024)
- return EINVAL;
-
- vas = ffs(aperture / 32*1024*1024) - 1;
-
- /*
- * While the size register is bits 1-3 of APCTRL, bit 0 must be
- * set for the size value to be 'valid'
- */
- pci_write_config(dev, AGP_AMD751_APCTRL,
- (((pci_read_config(dev, AGP_AMD751_APCTRL, 1) & ~0x06)
- | ((vas << 1) | 1))), 1);
-
- return 0;
-}
-
-static int
-agp_amd_bind_page(device_t dev, int offset, vm_offset_t physical)
-{
- struct agp_amd_softc *sc = device_get_softc(dev);
-
- if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
- return EINVAL;
-
- sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical | 1;
-
- /* invalidate the cache */
- AGP_FLUSH_TLB(dev);
- return 0;
-}
-
-static int
-agp_amd_unbind_page(device_t dev, int offset)
-{
- struct agp_amd_softc *sc = device_get_softc(dev);
-
- if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
- return EINVAL;
-
- sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0;
- return 0;
-}
-
-static void
-agp_amd_flush_tlb(device_t dev)
-{
- struct agp_amd_softc *sc = device_get_softc(dev);
-
- /* Set the cache invalidate bit and wait for the chipset to clear */
- WRITE4(AGP_AMD751_TLBCTRL, 1);
- do {
- DELAY(1);
- } while (READ4(AGP_AMD751_TLBCTRL));
-}
-
-static device_method_t agp_amd_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, agp_amd_probe),
- DEVMETHOD(device_attach, agp_amd_attach),
- DEVMETHOD(device_detach, agp_amd_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /* AGP interface */
- DEVMETHOD(agp_get_aperture, agp_amd_get_aperture),
- DEVMETHOD(agp_set_aperture, agp_amd_set_aperture),
- DEVMETHOD(agp_bind_page, agp_amd_bind_page),
- DEVMETHOD(agp_unbind_page, agp_amd_unbind_page),
- DEVMETHOD(agp_flush_tlb, agp_amd_flush_tlb),
- DEVMETHOD(agp_enable, agp_generic_enable),
- DEVMETHOD(agp_alloc_memory, agp_generic_alloc_memory),
- DEVMETHOD(agp_free_memory, agp_generic_free_memory),
- DEVMETHOD(agp_bind_memory, agp_generic_bind_memory),
- DEVMETHOD(agp_unbind_memory, agp_generic_unbind_memory),
-
- { 0, 0 }
-};
-
-static driver_t agp_amd_driver = {
- "agp",
- agp_amd_methods,
- sizeof(struct agp_amd_softc),
-};
-
-static devclass_t agp_devclass;
-
-DRIVER_MODULE(agp_amd, pci, agp_amd_driver, agp_devclass, 0, 0);
-MODULE_DEPEND(agp_amd, agp, 1, 1, 1);
-MODULE_DEPEND(agp_amd, pci, 1, 1, 1);
diff --git a/sys/dev/agp/agp_i810.c b/sys/dev/agp/agp_i810.c
deleted file mode 100644
index 29acc1b42460..000000000000
--- a/sys/dev/agp/agp_i810.c
+++ /dev/null
@@ -1,705 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * Copyright (c) 2000 Ruslan Ermilov
- * 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$
- */
-
-/*
- * Fixes for 830/845G support: David Dawes <dawes@xfree86.org>
- * 852GM/855GM/865G support added by David Dawes <dawes@xfree86.org>
- */
-
-#include "opt_bus.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/lock.h>
-#include <sys/lockmgr.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-
-#include <pci/pcivar.h>
-#include <pci/pcireg.h>
-#include <pci/agppriv.h>
-#include <pci/agpreg.h>
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/vm_page.h>
-#include <vm/vm_pageout.h>
-#include <vm/pmap.h>
-
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-MALLOC_DECLARE(M_AGP);
-
-#define READ1(off) bus_space_read_1(sc->bst, sc->bsh, off)
-#define READ4(off) bus_space_read_4(sc->bst, sc->bsh, off)
-#define WRITE4(off,v) bus_space_write_4(sc->bst, sc->bsh, off, v)
-
-#define CHIP_I810 0 /* i810/i815 */
-#define CHIP_I830 1 /* 830M/845G */
-#define CHIP_I855 2 /* 852GM/855GM/865G */
-
-struct agp_i810_softc {
- struct agp_softc agp;
- u_int32_t initial_aperture; /* aperture size at startup */
- struct agp_gatt *gatt;
- int chiptype; /* i810-like or i830 */
- u_int32_t dcache_size; /* i810 only */
- u_int32_t stolen; /* number of i830/845 gtt entries for stolen memory */
- device_t bdev; /* bridge device */
- struct resource *regs; /* memory mapped GC registers */
- bus_space_tag_t bst; /* bus_space tag */
- bus_space_handle_t bsh; /* bus_space handle */
-};
-
-static const char*
-agp_i810_match(device_t dev)
-{
- if (pci_get_class(dev) != PCIC_DISPLAY
- || pci_get_subclass(dev) != PCIS_DISPLAY_VGA)
- return NULL;
-
- switch (pci_get_devid(dev)) {
- case 0x71218086:
- return ("Intel 82810 (i810 GMCH) SVGA controller");
-
- case 0x71238086:
- return ("Intel 82810-DC100 (i810-DC100 GMCH) SVGA controller");
-
- case 0x71258086:
- return ("Intel 82810E (i810E GMCH) SVGA controller");
-
- case 0x11328086:
- return ("Intel 82815 (i815 GMCH) SVGA controller");
-
- case 0x35778086:
- return ("Intel 82830M (830M GMCH) SVGA controller");
-
- case 0x25628086:
- return ("Intel 82845G (845G GMCH) SVGA controller");
-
- case 0x35828086:
- switch (pci_read_config(dev, AGP_I85X_CAPID, 1)) {
- case AGP_I855_GME:
- return ("Intel 82855GME (855GME GMCH) SVGA controller");
-
- case AGP_I855_GM:
- return ("Intel 82855GM (855GM GMCH) SVGA controller");
-
- case AGP_I852_GME:
- return ("Intel 82852GME (852GME GMCH) SVGA controller");
-
- case AGP_I852_GM:
- return ("Intel 82852GM (852GM GMCH) SVGA controller");
-
- default:
- return ("Intel 8285xM (85xGM GMCH) SVGA controller");
- }
-
- case 0x25728086:
- return ("Intel 82865G (865G GMCH) SVGA controller");
- };
-
- return NULL;
-}
-
-/*
- * Find bridge device.
- */
-static device_t
-agp_i810_find_bridge(device_t dev)
-{
- device_t *children, child;
- int nchildren, i;
- u_int32_t devid;
-
- /*
- * Calculate bridge device's ID.
- */
- devid = pci_get_devid(dev);
- switch (devid) {
- case 0x71218086:
- case 0x71238086:
- case 0x71258086:
- devid -= 0x10000;
- break;
-
- case 0x11328086:
- case 0x35778086:
- case 0x25628086:
- case 0x35828086:
- case 0x25728086:
- devid -= 0x20000;
- break;
- };
- if (device_get_children(device_get_parent(dev), &children, &nchildren))
- return 0;
-
- for (i = 0; i < nchildren; i++) {
- child = children[i];
-
- if (pci_get_devid(child) == devid) {
- free(children, M_TEMP);
- return child;
- }
- }
- free(children, M_TEMP);
- return 0;
-}
-
-static int
-agp_i810_probe(device_t dev)
-{
- const char *desc;
-
- desc = agp_i810_match(dev);
- if (desc) {
- device_t bdev;
- u_int8_t smram;
- int devid = pci_get_devid(dev);
-
- bdev = agp_i810_find_bridge(dev);
- if (!bdev) {
- if (bootverbose)
- printf("I810: can't find bridge device\n");
- return ENXIO;
- }
-
- /*
- * checking whether internal graphics device has been activated.
- */
- if ( (devid == 0x71218086 ) ||
- (devid == 0x71238086 ) ||
- (devid == 0x71258086 ) ||
- (devid == 0x11328086 ) ) {
- smram = pci_read_config(bdev, AGP_I810_SMRAM, 1);
- if ((smram & AGP_I810_SMRAM_GMS)
- == AGP_I810_SMRAM_GMS_DISABLED) {
- if (bootverbose)
- printf("I810: disabled, not probing\n");
- return ENXIO;
- }
- } else { /* I830MG */
- unsigned int gcc1;
- gcc1 = pci_read_config(bdev, AGP_I830_GCC1, 1);
- if ((gcc1 & AGP_I830_GCC1_DEV2) == AGP_I830_GCC1_DEV2_DISABLED) {
- if (bootverbose)
- printf("I830: disabled, not probing\n");
- return ENXIO;
- }
- }
-
- device_verbose(dev);
- device_set_desc(dev, desc);
- return 0;
- }
-
- return ENXIO;
-}
-
-static int
-agp_i810_attach(device_t dev)
-{
- struct agp_i810_softc *sc = device_get_softc(dev);
- struct agp_gatt *gatt;
- int error, rid;
-
- sc->bdev = agp_i810_find_bridge(dev);
- if (!sc->bdev)
- return ENOENT;
-
- error = agp_generic_attach(dev);
- if (error)
- return error;
-
- switch (pci_get_devid(dev)) {
- case 0x71218086:
- case 0x71238086:
- case 0x71258086:
- case 0x11328086:
- sc->chiptype = CHIP_I810;
- break;
- case 0x35778086:
- case 0x25628086:
- sc->chiptype = CHIP_I830;
- break;
- case 0x35828086:
- case 0x25728086:
- sc->chiptype = CHIP_I855;
- break;
- };
-
- /* Same for i810 and i830 */
- rid = AGP_I810_MMADR;
- sc->regs = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
- 0, ~0, 1, RF_ACTIVE);
- if (!sc->regs) {
- agp_generic_detach(dev);
- return ENOMEM;
- }
- sc->bst = rman_get_bustag(sc->regs);
- sc->bsh = rman_get_bushandle(sc->regs);
-
- sc->initial_aperture = AGP_GET_APERTURE(dev);
-
- gatt = malloc( sizeof(struct agp_gatt), M_AGP, M_NOWAIT);
- if (!gatt) {
- agp_generic_detach(dev);
- return ENOMEM;
- }
- sc->gatt = gatt;
-
- gatt->ag_entries = AGP_GET_APERTURE(dev) >> AGP_PAGE_SHIFT;
-
- if ( sc->chiptype == CHIP_I810 ) {
- /* Some i810s have on-chip memory called dcache */
- if (READ1(AGP_I810_DRT) & AGP_I810_DRT_POPULATED)
- sc->dcache_size = 4 * 1024 * 1024;
- else
- sc->dcache_size = 0;
-
- /* According to the specs the gatt on the i810 must be 64k */
- gatt->ag_virtual = contigmalloc( 64 * 1024, M_AGP, 0,
- 0, ~0, PAGE_SIZE, 0);
- if (!gatt->ag_virtual) {
- if (bootverbose)
- device_printf(dev, "contiguous allocation failed\n");
- free(gatt, M_AGP);
- agp_generic_detach(dev);
- return ENOMEM;
- }
- bzero(gatt->ag_virtual, gatt->ag_entries * sizeof(u_int32_t));
-
- gatt->ag_physical = vtophys((vm_offset_t) gatt->ag_virtual);
- agp_flush_cache();
- /* Install the GATT. */
- WRITE4(AGP_I810_PGTBL_CTL, gatt->ag_physical | 1);
- } else if ( sc->chiptype == CHIP_I830 ) {
- /* The i830 automatically initializes the 128k gatt on boot. */
- unsigned int gcc1, pgtblctl;
-
- gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 1);
- switch (gcc1 & AGP_I830_GCC1_GMS) {
- case AGP_I830_GCC1_GMS_STOLEN_512:
- sc->stolen = (512 - 132) * 1024 / 4096;
- break;
- case AGP_I830_GCC1_GMS_STOLEN_1024:
- sc->stolen = (1024 - 132) * 1024 / 4096;
- break;
- case AGP_I830_GCC1_GMS_STOLEN_8192:
- sc->stolen = (8192 - 132) * 1024 / 4096;
- break;
- default:
- sc->stolen = 0;
- device_printf(dev, "unknown memory configuration, disabling\n");
- agp_generic_detach(dev);
- return EINVAL;
- }
- if (sc->stolen > 0)
- device_printf(dev, "detected %dk stolen memory\n", sc->stolen * 4);
- device_printf(dev, "aperture size is %dM\n", sc->initial_aperture / 1024 / 1024);
-
- /* GATT address is already in there, make sure it's enabled */
- pgtblctl = READ4(AGP_I810_PGTBL_CTL);
- pgtblctl |= 1;
- WRITE4(AGP_I810_PGTBL_CTL, pgtblctl);
-
- gatt->ag_physical = pgtblctl & ~1;
- } else { /* CHIP_I855 */
- /* The 855GM automatically initializes the 128k gatt on boot. */
- unsigned int gcc1, pgtblctl;
-
- gcc1 = pci_read_config(sc->bdev, AGP_I855_GCC1, 1);
- switch (gcc1 & AGP_I855_GCC1_GMS) {
- case AGP_I855_GCC1_GMS_STOLEN_1M:
- sc->stolen = (1024 - 132) * 1024 / 4096;
- break;
- case AGP_I855_GCC1_GMS_STOLEN_4M:
- sc->stolen = (4096 - 132) * 1024 / 4096;
- break;
- case AGP_I855_GCC1_GMS_STOLEN_8M:
- sc->stolen = (8192 - 132) * 1024 / 4096;
- break;
- case AGP_I855_GCC1_GMS_STOLEN_16M:
- sc->stolen = (16384 - 132) * 1024 / 4096;
- break;
- case AGP_I855_GCC1_GMS_STOLEN_32M:
- sc->stolen = (32768 - 132) * 1024 / 4096;
- break;
- default:
- sc->stolen = 0;
- device_printf(dev, "unknown memory configuration, disabling\n");
- agp_generic_detach(dev);
- return EINVAL;
- }
- if (sc->stolen > 0)
- device_printf(dev, "detected %dk stolen memory\n", sc->stolen * 4);
- device_printf(dev, "aperture size is %dM\n", sc->initial_aperture / 1024 / 1024);
-
- /* GATT address is already in there, make sure it's enabled */
- pgtblctl = READ4(AGP_I810_PGTBL_CTL);
- pgtblctl |= 1;
- WRITE4(AGP_I810_PGTBL_CTL, pgtblctl);
-
- gatt->ag_physical = pgtblctl & ~1;
- }
-
- return 0;
-}
-
-static int
-agp_i810_detach(device_t dev)
-{
- struct agp_i810_softc *sc = device_get_softc(dev);
- int error;
-
- error = agp_generic_detach(dev);
- if (error)
- return error;
-
- /* Clear the GATT base. */
- if ( sc->chiptype == CHIP_I810 ) {
- WRITE4(AGP_I810_PGTBL_CTL, 0);
- } else {
- unsigned int pgtblctl;
- pgtblctl = READ4(AGP_I810_PGTBL_CTL);
- pgtblctl &= ~1;
- WRITE4(AGP_I810_PGTBL_CTL, pgtblctl);
- }
-
- /* Put the aperture back the way it started. */
- AGP_SET_APERTURE(dev, sc->initial_aperture);
-
- if ( sc->chiptype == CHIP_I810 ) {
- contigfree(sc->gatt->ag_virtual, 64 * 1024, M_AGP);
- }
- free(sc->gatt, M_AGP);
-
- bus_release_resource(dev, SYS_RES_MEMORY,
- AGP_I810_MMADR, sc->regs);
-
- return 0;
-}
-
-static u_int32_t
-agp_i810_get_aperture(device_t dev)
-{
- struct agp_i810_softc *sc = device_get_softc(dev);
-
- if ( sc->chiptype == CHIP_I810 ) {
- u_int16_t miscc;
- miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2);
- if ((miscc & AGP_I810_MISCC_WINSIZE) == AGP_I810_MISCC_WINSIZE_32)
- return 32 * 1024 * 1024;
- else
- return 64 * 1024 * 1024;
- } else if ( sc->chiptype == CHIP_I830 ) {
- unsigned int gcc1;
-
- gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
- if ((gcc1 & AGP_I830_GCC1_GMASIZE) == AGP_I830_GCC1_GMASIZE_64)
- return 64 * 1024 * 1024;
- else
- return 128 * 1024 * 1024;
- } else { /* CHIP_I855 */
- return 128 * 1024 * 1024;
- }
-}
-
-static int
-agp_i810_set_aperture(device_t dev, u_int32_t aperture)
-{
- struct agp_i810_softc *sc = device_get_softc(dev);
- u_int16_t miscc;
-
- if ( sc->chiptype == CHIP_I810 ) {
- /*
- * Double check for sanity.
- */
- if (aperture != 32 * 1024 * 1024 && aperture != 64 * 1024 * 1024) {
- device_printf(dev, "bad aperture size %d\n", aperture);
- return EINVAL;
- }
-
- miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2);
- miscc &= ~AGP_I810_MISCC_WINSIZE;
- if (aperture == 32 * 1024 * 1024)
- miscc |= AGP_I810_MISCC_WINSIZE_32;
- else
- miscc |= AGP_I810_MISCC_WINSIZE_64;
-
- pci_write_config(sc->bdev, AGP_I810_MISCC, miscc, 2);
- } else if ( sc->chiptype == CHIP_I830 ) {
- unsigned int gcc1;
-
- if (aperture != 64 * 1024 * 1024 && aperture != 128 * 1024 * 1024) {
- device_printf(dev, "bad aperture size %d\n", aperture);
- return EINVAL;
- }
- gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
- gcc1 &= ~AGP_I830_GCC1_GMASIZE;
- if (aperture == 64 * 1024 * 1024)
- gcc1 |= AGP_I830_GCC1_GMASIZE_64;
- else
- gcc1 |= AGP_I830_GCC1_GMASIZE_128;
-
- pci_write_config(sc->bdev, AGP_I830_GCC1, gcc1, 2);
- } else { /* CHIP_I855 */
- if (aperture != 128 * 1024 * 1024) {
- device_printf(dev, "bad aperture size %d\n", aperture);
- return EINVAL;
- }
- }
-
- return 0;
-}
-
-static int
-agp_i810_bind_page(device_t dev, int offset, vm_offset_t physical)
-{
- struct agp_i810_softc *sc = device_get_softc(dev);
-
- if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT)) {
- device_printf(dev, "failed: offset is 0x%08x, shift is %d, entries is %d\n", offset, AGP_PAGE_SHIFT, sc->gatt->ag_entries);
- return EINVAL;
- }
-
- if ( sc->chiptype != CHIP_I810 ) {
- if ( (offset >> AGP_PAGE_SHIFT) < sc->stolen ) {
- device_printf(dev, "trying to bind into stolen memory");
- return EINVAL;
- }
- }
-
- WRITE4(AGP_I810_GTT + (offset >> AGP_PAGE_SHIFT) * 4, physical | 1);
- return 0;
-}
-
-static int
-agp_i810_unbind_page(device_t dev, int offset)
-{
- struct agp_i810_softc *sc = device_get_softc(dev);
-
- if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
- return EINVAL;
-
- if ( sc->chiptype != CHIP_I810 ) {
- if ( (offset >> AGP_PAGE_SHIFT) < sc->stolen ) {
- device_printf(dev, "trying to unbind from stolen memory");
- return EINVAL;
- }
- }
-
- WRITE4(AGP_I810_GTT + (offset >> AGP_PAGE_SHIFT) * 4, 0);
- return 0;
-}
-
-/*
- * Writing via memory mapped registers already flushes all TLBs.
- */
-static void
-agp_i810_flush_tlb(device_t dev)
-{
-}
-
-static int
-agp_i810_enable(device_t dev, u_int32_t mode)
-{
-
- return 0;
-}
-
-static struct agp_memory *
-agp_i810_alloc_memory(device_t dev, int type, vm_size_t size)
-{
- struct agp_i810_softc *sc = device_get_softc(dev);
- struct agp_memory *mem;
-
- if ((size & (AGP_PAGE_SIZE - 1)) != 0)
- return 0;
-
- if (sc->agp.as_allocated + size > sc->agp.as_maxmem)
- return 0;
-
- if (type == 1) {
- /*
- * Mapping local DRAM into GATT.
- */
- if ( sc->chiptype != CHIP_I810 )
- return 0;
- if (size != sc->dcache_size)
- return 0;
- } else if (type == 2) {
- /*
- * Bogus mapping of a single page for the hardware cursor.
- */
- if (size != AGP_PAGE_SIZE)
- return 0;
- }
-
- mem = malloc(sizeof *mem, M_AGP, M_WAITOK);
- mem->am_id = sc->agp.as_nextid++;
- mem->am_size = size;
- mem->am_type = type;
- if (type != 1)
- mem->am_obj = vm_object_allocate(OBJT_DEFAULT,
- atop(round_page(size)));
- else
- mem->am_obj = 0;
-
- if (type == 2) {
- /*
- * Allocate and wire down the page now so that we can
- * get its physical address.
- */
- vm_page_t m;
- m = vm_page_grab(mem->am_obj, 0,
- VM_ALLOC_WIRED | VM_ALLOC_ZERO | VM_ALLOC_RETRY);
- if ((m->flags & PG_ZERO) == 0)
- pmap_zero_page(m);
- vm_page_lock_queues();
- mem->am_physical = VM_PAGE_TO_PHYS(m);
- vm_page_wakeup(m);
- vm_page_unlock_queues();
- } else {
- mem->am_physical = 0;
- }
-
- mem->am_offset = 0;
- mem->am_is_bound = 0;
- TAILQ_INSERT_TAIL(&sc->agp.as_memory, mem, am_link);
- sc->agp.as_allocated += size;
-
- return mem;
-}
-
-static int
-agp_i810_free_memory(device_t dev, struct agp_memory *mem)
-{
- struct agp_i810_softc *sc = device_get_softc(dev);
-
- if (mem->am_is_bound)
- return EBUSY;
-
- if (mem->am_type == 2) {
- /*
- * Unwire the page which we wired in alloc_memory.
- */
- vm_page_t m = vm_page_lookup(mem->am_obj, 0);
- vm_page_lock_queues();
- vm_page_unwire(m, 0);
- vm_page_unlock_queues();
- }
-
- sc->agp.as_allocated -= mem->am_size;
- TAILQ_REMOVE(&sc->agp.as_memory, mem, am_link);
- if (mem->am_obj)
- vm_object_deallocate(mem->am_obj);
- free(mem, M_AGP);
- return 0;
-}
-
-static int
-agp_i810_bind_memory(device_t dev, struct agp_memory *mem,
- vm_offset_t offset)
-{
- struct agp_i810_softc *sc = device_get_softc(dev);
- vm_offset_t i;
-
- if (mem->am_type != 1)
- return agp_generic_bind_memory(dev, mem, offset);
-
- if ( sc->chiptype != CHIP_I810 )
- return EINVAL;
-
- for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
- WRITE4(AGP_I810_GTT + (offset >> AGP_PAGE_SHIFT) * 4,
- i | 3);
- }
-
- return 0;
-}
-
-static int
-agp_i810_unbind_memory(device_t dev, struct agp_memory *mem)
-{
- struct agp_i810_softc *sc = device_get_softc(dev);
- vm_offset_t i;
-
- if (mem->am_type != 1)
- return agp_generic_unbind_memory(dev, mem);
-
- if ( sc->chiptype != CHIP_I810 )
- return EINVAL;
-
- for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
- WRITE4(AGP_I810_GTT + (i >> AGP_PAGE_SHIFT) * 4, 0);
-
- return 0;
-}
-
-static device_method_t agp_i810_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, agp_i810_probe),
- DEVMETHOD(device_attach, agp_i810_attach),
- DEVMETHOD(device_detach, agp_i810_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /* AGP interface */
- DEVMETHOD(agp_get_aperture, agp_i810_get_aperture),
- DEVMETHOD(agp_set_aperture, agp_i810_set_aperture),
- DEVMETHOD(agp_bind_page, agp_i810_bind_page),
- DEVMETHOD(agp_unbind_page, agp_i810_unbind_page),
- DEVMETHOD(agp_flush_tlb, agp_i810_flush_tlb),
- DEVMETHOD(agp_enable, agp_i810_enable),
- DEVMETHOD(agp_alloc_memory, agp_i810_alloc_memory),
- DEVMETHOD(agp_free_memory, agp_i810_free_memory),
- DEVMETHOD(agp_bind_memory, agp_i810_bind_memory),
- DEVMETHOD(agp_unbind_memory, agp_i810_unbind_memory),
-
- { 0, 0 }
-};
-
-static driver_t agp_i810_driver = {
- "agp",
- agp_i810_methods,
- sizeof(struct agp_i810_softc),
-};
-
-static devclass_t agp_devclass;
-
-DRIVER_MODULE(agp_i810, pci, agp_i810_driver, agp_devclass, 0, 0);
-MODULE_DEPEND(agp_i810, agp, 1, 1, 1);
-MODULE_DEPEND(agp_i810, pci, 1, 1, 1);
diff --git a/sys/dev/agp/agp_if.m b/sys/dev/agp/agp_if.m
deleted file mode 100644
index 9d81584a8ecd..000000000000
--- a/sys/dev/agp/agp_if.m
+++ /dev/null
@@ -1,134 +0,0 @@
-#
-# Copyright (c) 2000 Doug Rabson
-# 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$
-#
-
-#include <sys/bus.h>
-
-#
-# The AGP interface is used internally to the agp driver to isolate the
-# differences between various AGP chipsets into chipset mini drivers. It
-# should not be used outside the AGP driver. The kernel api for accessing
-# AGP functionality is described in <pci/agpvar.h>
-#
-INTERFACE agp;
-
-#
-# Return the current aperture size.
-#
-METHOD u_int32_t get_aperture {
- device_t dev;
-};
-
-#
-# Set the size of the aperture. Return EINVAL on error or 0 on success.
-#
-METHOD int set_aperture {
- device_t dev;
- u_int32_t aperture;
-};
-
-#
-# Bind a single page in the AGP aperture to a given physical address.
-# The offset is a byte offset within the aperture which must be
-# aligned to an AGP page boundary.
-#
-METHOD int bind_page {
- device_t dev;
- vm_offset_t offset;
- vm_offset_t physical;
-};
-
-#
-# Unbind a single page in the AGP aperture.
-#
-METHOD int unbind_page {
- device_t dev;
- vm_offset_t offset;
-};
-
-#
-# Flush the GATT TLB. This is used after a call to bind_page to
-# ensure that any mappings cached in the chipset are discarded.
-#
-METHOD void flush_tlb {
- device_t dev;
-};
-
-#
-# Enable the agp hardware with the relavent mode. The mode bits are
-# defined in <pci/agpreg.h>
-#
-METHOD int enable {
- device_t dev;
- u_int32_t mode;
-};
-
-#
-# Allocate memory of a given type. The type is a chipset-specific
-# code which is used by certain integrated agp graphics chips
-# (basically just the i810 for now) to access special features of
-# the chipset. An opaque handle representing the memory region is
-# returned and can be used as an argument to free_memory, bind_memory
-# and unbind_memory.
-#
-# The size is specified in bytes but must be a multiple of the AGP
-# page size.
-#
-METHOD struct agp_memory * alloc_memory {
- device_t dev;
- int type;
- vm_size_t size;
-};
-
-#
-# Free a memory region previously allocated with alloc_memory. Return
-# EBUSY if the memory is bound.
-#
-METHOD int free_memory {
- device_t dev;
- struct agp_memory *mem;
-};
-
-#
-# Bind a memory region to a specific byte offset within the chipset's
-# AGP aperture. This effectively defines a range of contiguous
-# physical address which alias the (possibly uncontiguous) pages in
-# the memory region.
-#
-METHOD int bind_memory {
- device_t dev;
- struct agp_memory *mem;
- vm_offset_t offset;
-};
-
-#
-# Unbind a memory region bound with bind_memory.
-#
-METHOD int unbind_memory {
- device_t dev;
- struct agp_memory *handle;
-};
diff --git a/sys/dev/agp/agp_intel.c b/sys/dev/agp/agp_intel.c
deleted file mode 100644
index 48bd361d51c7..000000000000
--- a/sys/dev/agp/agp_intel.c
+++ /dev/null
@@ -1,401 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * 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$
- */
-
-#include "opt_bus.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/lock.h>
-#include <sys/lockmgr.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-
-#include <pci/pcivar.h>
-#include <pci/pcireg.h>
-#include <pci/agppriv.h>
-#include <pci/agpreg.h>
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/pmap.h>
-
-#define MAX_APSIZE 0x3f /* 256 MB */
-
-struct agp_intel_softc {
- struct agp_softc agp;
- u_int32_t initial_aperture; /* aperture size at startup */
- struct agp_gatt *gatt;
- u_int aperture_mask;
-};
-
-static const char*
-agp_intel_match(device_t dev)
-{
- if (pci_get_class(dev) != PCIC_BRIDGE
- || pci_get_subclass(dev) != PCIS_BRIDGE_HOST)
- return NULL;
-
- if (agp_find_caps(dev) == 0)
- return NULL;
-
- switch (pci_get_devid(dev)) {
- /* Intel -- vendor 0x8086 */
- case 0x71808086:
- return ("Intel 82443LX (440 LX) host to PCI bridge");
-
- case 0x71908086:
- return ("Intel 82443BX (440 BX) host to PCI bridge");
-
- case 0x71a08086:
- return ("Intel 82443GX host to PCI bridge");
-
- case 0x71a18086:
- return ("Intel 82443GX host to AGP bridge");
-
- case 0x11308086:
- return ("Intel 82815 (i815 GMCH) host to PCI bridge");
-
- case 0x25008086:
- case 0x25018086:
- return ("Intel 82820 host to AGP bridge");
-
- case 0x35758086:
- return ("Intel 82830 host to AGP bridge");
-
- case 0x1a218086:
- return ("Intel 82840 host to AGP bridge");
-
- case 0x1a308086:
- return ("Intel 82845 host to AGP bridge");
-
- case 0x25308086:
- return ("Intel 82850 host to AGP bridge");
-
- case 0x25318086:
- return ("Intel 82860 host to AGP bridge");
-
- case 0x25708086:
- return ("Intel 82865 host to AGP bridge");
- };
-
- if (pci_get_vendor(dev) == 0x8086)
- return ("Intel Generic host to PCI bridge");
-
- return NULL;
-}
-
-static int
-agp_intel_probe(device_t dev)
-{
- const char *desc;
-
- desc = agp_intel_match(dev);
- if (desc) {
- device_verbose(dev);
- device_set_desc(dev, desc);
- return 0;
- }
-
- return ENXIO;
-}
-
-static int
-agp_intel_attach(device_t dev)
-{
- struct agp_intel_softc *sc = device_get_softc(dev);
- struct agp_gatt *gatt;
- u_int32_t type = pci_get_devid(dev);
- u_int32_t value;
- int error;
-
- error = agp_generic_attach(dev);
- if (error)
- return error;
-
- /* Determine maximum supported aperture size. */
- value = pci_read_config(dev, AGP_INTEL_APSIZE, 1);
- pci_write_config(dev, AGP_INTEL_APSIZE, MAX_APSIZE, 1);
- sc->aperture_mask = pci_read_config(dev, AGP_INTEL_APSIZE, 1) &
- MAX_APSIZE;
- pci_write_config(dev, AGP_INTEL_APSIZE, value, 1);
- sc->initial_aperture = AGP_GET_APERTURE(dev);
-
- for (;;) {
- gatt = agp_alloc_gatt(dev);
- if (gatt)
- break;
-
- /*
- * Probably contigmalloc failure. Try reducing the
- * aperture so that the gatt size reduces.
- */
- if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2)) {
- agp_generic_detach(dev);
- return ENOMEM;
- }
- }
- sc->gatt = gatt;
-
- /* Install the gatt. */
- pci_write_config(dev, AGP_INTEL_ATTBASE, gatt->ag_physical, 4);
-
- /* Enable the GLTB and setup the control register. */
- switch (type) {
- case 0x71908086: /* 440LX/EX */
- pci_write_config(dev, AGP_INTEL_AGPCTRL, 0x2080, 4);
- break;
- case 0x71808086: /* 440BX */
- /*
- * XXX: Should be 0xa080? Bit 9 is undefined, and
- * bit 13 being on and bit 15 being clear is illegal.
- */
- pci_write_config(dev, AGP_INTEL_AGPCTRL, 0x2280, 4);
- break;
- default:
- value = pci_read_config(dev, AGP_INTEL_AGPCTRL, 4);
- pci_write_config(dev, AGP_INTEL_AGPCTRL, value | 0x80, 4);
- }
-
- /* Enable things, clear errors etc. */
- switch (type) {
- case 0x1a218086: /* i840 */
- case 0x25308086: /* i850 */
- case 0x25318086: /* i860 */
- pci_write_config(dev, AGP_INTEL_MCHCFG,
- (pci_read_config(dev, AGP_INTEL_MCHCFG, 2)
- | (1 << 9)), 2);
- break;
-
- case 0x25008086: /* i820 */
- case 0x25018086: /* i820 */
- pci_write_config(dev, AGP_INTEL_I820_RDCR,
- (pci_read_config(dev, AGP_INTEL_I820_RDCR, 1)
- | (1 << 1)), 1);
- break;
-
- case 0x1a308086: /* i845 */
- case 0x25708086: /* i865 */
- pci_write_config(dev, AGP_INTEL_I845_MCHCFG,
- (pci_read_config(dev, AGP_INTEL_I845_MCHCFG, 1)
- | (1 << 1)), 1);
- break;
-
- default: /* Intel Generic (maybe) */
- pci_write_config(dev, AGP_INTEL_NBXCFG,
- (pci_read_config(dev, AGP_INTEL_NBXCFG, 4)
- & ~(1 << 10)) | (1 << 9), 4);
- }
-
- switch (type) {
- case 0x1a218086: /* i840 */
- pci_write_config(dev, AGP_INTEL_I8XX_ERRSTS, 0xc000, 2);
- break;
-
- case 0x25008086: /* i820 */
- case 0x25018086: /* i820 */
- case 0x1a308086: /* i845 */
- case 0x25308086: /* i850 */
- case 0x25318086: /* i860 */
- case 0x25708086: /* i865 */
- pci_write_config(dev, AGP_INTEL_I8XX_ERRSTS, 0x00ff, 2);
- break;
-
- default: /* Intel Generic (maybe) */
- pci_write_config(dev, AGP_INTEL_ERRSTS + 1, 7, 1);
- }
-
- return 0;
-}
-
-static int
-agp_intel_detach(device_t dev)
-{
- struct agp_intel_softc *sc = device_get_softc(dev);
- u_int32_t type = pci_get_devid(dev);
- int error;
-
- error = agp_generic_detach(dev);
- if (error)
- return error;
-
- switch (type) {
- case 0x1a218086: /* i840 */
- case 0x25308086: /* i850 */
- case 0x25318086: /* i860 */
- printf("%s: set MCHCFG to %x\n", __func__, (unsigned)
- (pci_read_config(dev, AGP_INTEL_MCHCFG, 2)
- & ~(1 << 9)));
- pci_write_config(dev, AGP_INTEL_MCHCFG,
- (pci_read_config(dev, AGP_INTEL_MCHCFG, 2)
- & ~(1 << 9)), 2);
-
- case 0x25008086: /* i820 */
- case 0x25018086: /* i820 */
- printf("%s: set RDCR to %x\n", __func__, (unsigned)
- (pci_read_config(dev, AGP_INTEL_I820_RDCR, 1)
- & ~(1 << 1)));
- pci_write_config(dev, AGP_INTEL_I820_RDCR,
- (pci_read_config(dev, AGP_INTEL_I820_RDCR, 1)
- & ~(1 << 1)), 1);
-
- case 0x1a308086: /* i845 */
- case 0x25708086: /* i865 */
- printf("%s: set MCHCFG to %x\n", __func__, (unsigned)
- (pci_read_config(dev, AGP_INTEL_I845_MCHCFG, 1)
- & ~(1 << 1)));
- pci_write_config(dev, AGP_INTEL_MCHCFG,
- (pci_read_config(dev, AGP_INTEL_I845_MCHCFG, 1)
- & ~(1 << 1)), 1);
-
- default: /* Intel Generic (maybe) */
- printf("%s: set NBXCFG to %x\n", __func__,
- (pci_read_config(dev, AGP_INTEL_NBXCFG, 4)
- & ~(1 << 9)));
- pci_write_config(dev, AGP_INTEL_NBXCFG,
- (pci_read_config(dev, AGP_INTEL_NBXCFG, 4)
- & ~(1 << 9)), 4);
- }
- pci_write_config(dev, AGP_INTEL_ATTBASE, 0, 4);
- AGP_SET_APERTURE(dev, sc->initial_aperture);
- agp_free_gatt(sc->gatt);
-
- return 0;
-}
-
-static u_int32_t
-agp_intel_get_aperture(device_t dev)
-{
- struct agp_intel_softc *sc = device_get_softc(dev);
- u_int32_t apsize;
-
- apsize = pci_read_config(dev, AGP_INTEL_APSIZE, 1) & sc->aperture_mask;
-
- /*
- * The size is determined by the number of low bits of
- * register APBASE which are forced to zero. The low 22 bits
- * are always forced to zero and each zero bit in the apsize
- * field just read forces the corresponding bit in the 27:22
- * to be zero. We calculate the aperture size accordingly.
- */
- return (((apsize ^ sc->aperture_mask) << 22) | ((1 << 22) - 1)) + 1;
-}
-
-static int
-agp_intel_set_aperture(device_t dev, u_int32_t aperture)
-{
- struct agp_intel_softc *sc = device_get_softc(dev);
- u_int32_t apsize;
-
- /*
- * Reverse the magic from get_aperture.
- */
- apsize = ((aperture - 1) >> 22) ^ sc->aperture_mask;
-
- /*
- * Double check for sanity.
- */
- if ((((apsize ^ sc->aperture_mask) << 22) | ((1 << 22) - 1)) + 1 != aperture)
- return EINVAL;
-
- pci_write_config(dev, AGP_INTEL_APSIZE, apsize, 1);
-
- return 0;
-}
-
-static int
-agp_intel_bind_page(device_t dev, int offset, vm_offset_t physical)
-{
- struct agp_intel_softc *sc = device_get_softc(dev);
-
- if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
- return EINVAL;
-
- sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical | 0x17;
- return 0;
-}
-
-static int
-agp_intel_unbind_page(device_t dev, int offset)
-{
- struct agp_intel_softc *sc = device_get_softc(dev);
-
- if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
- return EINVAL;
-
- sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0;
- return 0;
-}
-
-static void
-agp_intel_flush_tlb(device_t dev)
-{
- u_int32_t val;
-
- val = pci_read_config(dev, AGP_INTEL_AGPCTRL, 4);
- pci_write_config(dev, AGP_INTEL_AGPCTRL, val & ~(1 << 8), 4);
- pci_write_config(dev, AGP_INTEL_AGPCTRL, val, 4);
-}
-
-static device_method_t agp_intel_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, agp_intel_probe),
- DEVMETHOD(device_attach, agp_intel_attach),
- DEVMETHOD(device_detach, agp_intel_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /* AGP interface */
- DEVMETHOD(agp_get_aperture, agp_intel_get_aperture),
- DEVMETHOD(agp_set_aperture, agp_intel_set_aperture),
- DEVMETHOD(agp_bind_page, agp_intel_bind_page),
- DEVMETHOD(agp_unbind_page, agp_intel_unbind_page),
- DEVMETHOD(agp_flush_tlb, agp_intel_flush_tlb),
- DEVMETHOD(agp_enable, agp_generic_enable),
- DEVMETHOD(agp_alloc_memory, agp_generic_alloc_memory),
- DEVMETHOD(agp_free_memory, agp_generic_free_memory),
- DEVMETHOD(agp_bind_memory, agp_generic_bind_memory),
- DEVMETHOD(agp_unbind_memory, agp_generic_unbind_memory),
-
- { 0, 0 }
-};
-
-static driver_t agp_intel_driver = {
- "agp",
- agp_intel_methods,
- sizeof(struct agp_intel_softc),
-};
-
-static devclass_t agp_devclass;
-
-DRIVER_MODULE(agp_intel, pci, agp_intel_driver, agp_devclass, 0, 0);
-MODULE_DEPEND(agp_intel, agp, 1, 1, 1);
-MODULE_DEPEND(agp_intel, pci, 1, 1, 1);
diff --git a/sys/dev/agp/agp_sis.c b/sys/dev/agp/agp_sis.c
deleted file mode 100644
index 00cb991b126f..000000000000
--- a/sys/dev/agp/agp_sis.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * 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$
- */
-
-#include "opt_bus.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/lock.h>
-#include <sys/lockmgr.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-
-#include <pci/pcivar.h>
-#include <pci/pcireg.h>
-#include <pci/agppriv.h>
-#include <pci/agpreg.h>
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/pmap.h>
-
-struct agp_sis_softc {
- struct agp_softc agp;
- u_int32_t initial_aperture; /* aperture size at startup */
- struct agp_gatt *gatt;
-};
-
-static const char*
-agp_sis_match(device_t dev)
-{
- if (pci_get_class(dev) != PCIC_BRIDGE
- || pci_get_subclass(dev) != PCIS_BRIDGE_HOST)
- return NULL;
-
- if (agp_find_caps(dev) == 0)
- return NULL;
-
- switch (pci_get_devid(dev)) {
- case 0x00011039:
- return ("SiS 5591 host to AGP bridge");
- case 0x06481039:
- return ("SiS 648 host to AGP bridge");
- };
-
- if (pci_get_vendor(dev) == 0x1039)
- return ("SIS Generic host to PCI bridge");
-
- return NULL;
-}
-
-static int
-agp_sis_probe(device_t dev)
-{
- const char *desc;
-
- desc = agp_sis_match(dev);
- if (desc) {
- device_verbose(dev);
- device_set_desc(dev, desc);
- return 0;
- }
-
- return ENXIO;
-}
-
-static int
-agp_sis_attach(device_t dev)
-{
- struct agp_sis_softc *sc = device_get_softc(dev);
- struct agp_gatt *gatt;
- int error;
-
- error = agp_generic_attach(dev);
- if (error)
- return error;
-
- sc->initial_aperture = AGP_GET_APERTURE(dev);
-
- for (;;) {
- gatt = agp_alloc_gatt(dev);
- if (gatt)
- break;
-
- /*
- * Probably contigmalloc failure. Try reducing the
- * aperture so that the gatt size reduces.
- */
- if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2)) {
- agp_generic_detach(dev);
- return ENOMEM;
- }
- }
- sc->gatt = gatt;
-
- /* Install the gatt. */
- pci_write_config(dev, AGP_SIS_ATTBASE, gatt->ag_physical, 4);
-
- /* Enable the aperture. */
- pci_write_config(dev, AGP_SIS_WINCTRL,
- pci_read_config(dev, AGP_SIS_WINCTRL, 1) | 3, 1);
-
- /*
- * Enable the TLB and make it automatically invalidate entries
- * when the GATT is written.
- */
- pci_write_config(dev, AGP_SIS_TLBCTRL, 0x05, 1);
-
- return 0;
-}
-
-static int
-agp_sis_detach(device_t dev)
-{
- struct agp_sis_softc *sc = device_get_softc(dev);
- int error;
-
- error = agp_generic_detach(dev);
- if (error)
- return error;
-
- /* Disable the aperture.. */
- pci_write_config(dev, AGP_SIS_WINCTRL,
- pci_read_config(dev, AGP_SIS_WINCTRL, 1) & ~3, 1);
-
- /* and the TLB. */
- pci_write_config(dev, AGP_SIS_TLBCTRL, 0, 1);
-
- /* Put the aperture back the way it started. */
- AGP_SET_APERTURE(dev, sc->initial_aperture);
-
- agp_free_gatt(sc->gatt);
- return 0;
-}
-
-static u_int32_t
-agp_sis_get_aperture(device_t dev)
-{
- int gws;
-
- /*
- * The aperture size is equal to 4M<<gws.
- */
- gws = (pci_read_config(dev, AGP_SIS_WINCTRL, 1) & 0x70) >> 4;
- return (4*1024*1024) << gws;
-}
-
-static int
-agp_sis_set_aperture(device_t dev, u_int32_t aperture)
-{
- int gws;
-
- /*
- * Check for a power of two and make sure its within the
- * programmable range.
- */
- if (aperture & (aperture - 1)
- || aperture < 4*1024*1024
- || aperture > 256*1024*1024)
- return EINVAL;
-
- gws = ffs(aperture / 4*1024*1024) - 1;
-
- pci_write_config(dev, AGP_SIS_WINCTRL,
- ((pci_read_config(dev, AGP_SIS_WINCTRL, 1) & ~0x70)
- | gws << 4), 1);
-
- return 0;
-}
-
-static int
-agp_sis_bind_page(device_t dev, int offset, vm_offset_t physical)
-{
- struct agp_sis_softc *sc = device_get_softc(dev);
-
- if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
- return EINVAL;
-
- sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical;
- return 0;
-}
-
-static int
-agp_sis_unbind_page(device_t dev, int offset)
-{
- struct agp_sis_softc *sc = device_get_softc(dev);
-
- if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
- return EINVAL;
-
- sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0;
- return 0;
-}
-
-static void
-agp_sis_flush_tlb(device_t dev)
-{
- pci_write_config(dev, AGP_SIS_TLBFLUSH, 0x02, 1);
-}
-
-static device_method_t agp_sis_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, agp_sis_probe),
- DEVMETHOD(device_attach, agp_sis_attach),
- DEVMETHOD(device_detach, agp_sis_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /* AGP interface */
- DEVMETHOD(agp_get_aperture, agp_sis_get_aperture),
- DEVMETHOD(agp_set_aperture, agp_sis_set_aperture),
- DEVMETHOD(agp_bind_page, agp_sis_bind_page),
- DEVMETHOD(agp_unbind_page, agp_sis_unbind_page),
- DEVMETHOD(agp_flush_tlb, agp_sis_flush_tlb),
- DEVMETHOD(agp_enable, agp_generic_enable),
- DEVMETHOD(agp_alloc_memory, agp_generic_alloc_memory),
- DEVMETHOD(agp_free_memory, agp_generic_free_memory),
- DEVMETHOD(agp_bind_memory, agp_generic_bind_memory),
- DEVMETHOD(agp_unbind_memory, agp_generic_unbind_memory),
-
- { 0, 0 }
-};
-
-static driver_t agp_sis_driver = {
- "agp",
- agp_sis_methods,
- sizeof(struct agp_sis_softc),
-};
-
-static devclass_t agp_devclass;
-
-DRIVER_MODULE(agp_sis, pci, agp_sis_driver, agp_devclass, 0, 0);
-MODULE_DEPEND(agp_sis, agp, 1, 1, 1);
-MODULE_DEPEND(agp_sis, pci, 1, 1, 1);
diff --git a/sys/dev/agp/agp_via.c b/sys/dev/agp/agp_via.c
deleted file mode 100644
index 4d13230db422..000000000000
--- a/sys/dev/agp/agp_via.c
+++ /dev/null
@@ -1,259 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * 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$
- */
-
-#include "opt_bus.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/lock.h>
-#include <sys/lockmgr.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-
-#include <pci/pcivar.h>
-#include <pci/pcireg.h>
-#include <pci/agppriv.h>
-#include <pci/agpreg.h>
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/pmap.h>
-
-struct agp_via_softc {
- struct agp_softc agp;
- u_int32_t initial_aperture; /* aperture size at startup */
- struct agp_gatt *gatt;
-};
-
-static const char*
-agp_via_match(device_t dev)
-{
- if (pci_get_class(dev) != PCIC_BRIDGE
- || pci_get_subclass(dev) != PCIS_BRIDGE_HOST)
- return NULL;
-
- if (agp_find_caps(dev) == 0)
- return NULL;
-
- switch (pci_get_devid(dev)) {
- case 0x05011106:
- return ("VIA 8501 (Apollo MVP4) host to PCI bridge");
- case 0x05971106:
- return ("VIA 82C597 (Apollo VP3) host to PCI bridge");
- case 0x05981106:
- return ("VIA 82C598 (Apollo MVP3) host to PCI bridge");
- case 0x06911106:
- return ("VIA 82C691 (Apollo Pro) host to PCI bridge");
- case 0x03051106:
- return ("VIA 82C8363 (Apollo KT133A) host to PCI bridge");
- };
-
- if (pci_get_vendor(dev) == 0x1106)
- return ("VIA Generic host to PCI bridge");
-
- return NULL;
-}
-
-static int
-agp_via_probe(device_t dev)
-{
- const char *desc;
-
- desc = agp_via_match(dev);
- if (desc) {
- device_verbose(dev);
- device_set_desc(dev, desc);
- return 0;
- }
-
- return ENXIO;
-}
-
-static int
-agp_via_attach(device_t dev)
-{
- struct agp_via_softc *sc = device_get_softc(dev);
- struct agp_gatt *gatt;
- int error;
-
- error = agp_generic_attach(dev);
- if (error)
- return error;
-
- sc->initial_aperture = AGP_GET_APERTURE(dev);
-
- for (;;) {
- gatt = agp_alloc_gatt(dev);
- if (gatt)
- break;
-
- /*
- * Probably contigmalloc failure. Try reducing the
- * aperture so that the gatt size reduces.
- */
- if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2)) {
- agp_generic_detach(dev);
- return ENOMEM;
- }
- }
- sc->gatt = gatt;
-
- /* Install the gatt. */
- pci_write_config(dev, AGP_VIA_ATTBASE, gatt->ag_physical | 3, 4);
-
- /* Enable the aperture. */
- pci_write_config(dev, AGP_VIA_GARTCTRL, 0x0f, 4);
-
- return 0;
-}
-
-static int
-agp_via_detach(device_t dev)
-{
- struct agp_via_softc *sc = device_get_softc(dev);
- int error;
-
- error = agp_generic_detach(dev);
- if (error)
- return error;
-
- pci_write_config(dev, AGP_VIA_GARTCTRL, 0, 4);
- pci_write_config(dev, AGP_VIA_ATTBASE, 0, 4);
- AGP_SET_APERTURE(dev, sc->initial_aperture);
- agp_free_gatt(sc->gatt);
-
- return 0;
-}
-
-static u_int32_t
-agp_via_get_aperture(device_t dev)
-{
- u_int32_t apsize;
-
- apsize = pci_read_config(dev, AGP_VIA_APSIZE, 1) & 0x1f;
-
- /*
- * The size is determined by the number of low bits of
- * register APBASE which are forced to zero. The low 20 bits
- * are always forced to zero and each zero bit in the apsize
- * field just read forces the corresponding bit in the 27:20
- * to be zero. We calculate the aperture size accordingly.
- */
- return (((apsize ^ 0xff) << 20) | ((1 << 20) - 1)) + 1;
-}
-
-static int
-agp_via_set_aperture(device_t dev, u_int32_t aperture)
-{
- u_int32_t apsize;
-
- /*
- * Reverse the magic from get_aperture.
- */
- apsize = ((aperture - 1) >> 20) ^ 0xff;
-
- /*
- * Double check for sanity.
- */
- if ((((apsize ^ 0xff) << 20) | ((1 << 20) - 1)) + 1 != aperture)
- return EINVAL;
-
- pci_write_config(dev, AGP_VIA_APSIZE, apsize, 1);
-
- return 0;
-}
-
-static int
-agp_via_bind_page(device_t dev, int offset, vm_offset_t physical)
-{
- struct agp_via_softc *sc = device_get_softc(dev);
-
- if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
- return EINVAL;
-
- sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical;
- return 0;
-}
-
-static int
-agp_via_unbind_page(device_t dev, int offset)
-{
- struct agp_via_softc *sc = device_get_softc(dev);
-
- if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
- return EINVAL;
-
- sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0;
- return 0;
-}
-
-static void
-agp_via_flush_tlb(device_t dev)
-{
- pci_write_config(dev, AGP_VIA_GARTCTRL, 0x8f, 4);
- pci_write_config(dev, AGP_VIA_GARTCTRL, 0x0f, 4);
-}
-
-static device_method_t agp_via_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, agp_via_probe),
- DEVMETHOD(device_attach, agp_via_attach),
- DEVMETHOD(device_detach, agp_via_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /* AGP interface */
- DEVMETHOD(agp_get_aperture, agp_via_get_aperture),
- DEVMETHOD(agp_set_aperture, agp_via_set_aperture),
- DEVMETHOD(agp_bind_page, agp_via_bind_page),
- DEVMETHOD(agp_unbind_page, agp_via_unbind_page),
- DEVMETHOD(agp_flush_tlb, agp_via_flush_tlb),
- DEVMETHOD(agp_enable, agp_generic_enable),
- DEVMETHOD(agp_alloc_memory, agp_generic_alloc_memory),
- DEVMETHOD(agp_free_memory, agp_generic_free_memory),
- DEVMETHOD(agp_bind_memory, agp_generic_bind_memory),
- DEVMETHOD(agp_unbind_memory, agp_generic_unbind_memory),
-
- { 0, 0 }
-};
-
-static driver_t agp_via_driver = {
- "agp",
- agp_via_methods,
- sizeof(struct agp_via_softc),
-};
-
-static devclass_t agp_devclass;
-
-DRIVER_MODULE(agp_via, pci, agp_via_driver, agp_devclass, 0, 0);
-MODULE_DEPEND(agp_via, agp, 1, 1, 1);
-MODULE_DEPEND(agp_via, pci, 1, 1, 1);
diff --git a/sys/dev/agp/agppriv.h b/sys/dev/agp/agppriv.h
deleted file mode 100644
index 1c5f0226390e..000000000000
--- a/sys/dev/agp/agppriv.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * 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 _PCI_AGPPRIV_H_
-#define _PCI_AGPPRIV_H_
-
-/*
- * This file *must not* be included by code outside the agp driver itself.
- */
-
-#include <sys/agpio.h>
-#include <pci/agpvar.h>
-
-#define AGP_DEBUGxx
-
-#ifdef AGP_DEBUG
-#define AGP_DPF(x...) do { \
- printf("agp: "); \
- printf(##x); \
-} while (0)
-#else
-#define AGP_DPF(x...) do {} while (0)
-#endif
-
-#include "agp_if.h"
-
-/*
- * Data structure to describe an AGP memory allocation.
- */
-TAILQ_HEAD(agp_memory_list, agp_memory);
-struct agp_memory {
- TAILQ_ENTRY(agp_memory) am_link; /* wiring for the tailq */
- int am_id; /* unique id for block */
- vm_size_t am_size; /* number of bytes allocated */
- int am_type; /* chipset specific type */
- struct vm_object *am_obj; /* VM object owning pages */
- vm_offset_t am_physical; /* bogus hack for i810 */
- vm_offset_t am_offset; /* page offset if bound */
- int am_is_bound; /* non-zero if bound */
-};
-
-/*
- * All chipset drivers must have this at the start of their softc.
- */
-struct agp_softc {
- struct resource *as_aperture; /* location of aperture */
- u_int32_t as_maxmem; /* allocation upper bound */
- u_int32_t as_allocated; /* amount allocated */
- enum agp_acquire_state as_state;
- struct agp_memory_list as_memory; /* list of allocated memory */
- int as_nextid; /* next memory block id */
- int as_isopen; /* user device is open */
- dev_t as_devnode; /* from make_dev */
- struct lock as_lock; /* lock for access to GATT */
-};
-
-struct agp_gatt {
- u_int32_t ag_entries;
- u_int32_t *ag_virtual;
- vm_offset_t ag_physical;
-};
-
-void agp_flush_cache(void);
-u_int8_t agp_find_caps(device_t dev);
-struct agp_gatt *agp_alloc_gatt(device_t dev);
-void agp_free_gatt(struct agp_gatt *gatt);
-int agp_generic_attach(device_t dev);
-int agp_generic_detach(device_t dev);
-int agp_generic_enable(device_t dev, u_int32_t mode);
-struct agp_memory *agp_generic_alloc_memory(device_t dev, int type,
- vm_size_t size);
-int agp_generic_free_memory(device_t dev,
- struct agp_memory *mem);
-int agp_generic_bind_memory(device_t dev,
- struct agp_memory *mem,
- vm_offset_t offset);
-int agp_generic_unbind_memory(device_t dev,
- struct agp_memory *mem);
-
-#endif /* !_PCI_AGPPRIV_H_ */
diff --git a/sys/dev/agp/agpreg.h b/sys/dev/agp/agpreg.h
deleted file mode 100644
index 17472d7550df..000000000000
--- a/sys/dev/agp/agpreg.h
+++ /dev/null
@@ -1,205 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * 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 _PCI_AGPREG_H_
-#define _PCI_AGPREG_H_
-
-/*
- * Offsets for various AGP configuration registers.
- */
-#define AGP_APBASE 0x10
-#define AGP_CAPPTR 0x34
-
-/*
- * Offsets from the AGP Capability pointer.
- */
-#define AGP_CAPID 0x0
-#define AGP_CAPID_GET_MAJOR(x) (((x) & 0x00f00000U) >> 20)
-#define AGP_CAPID_GET_MINOR(x) (((x) & 0x000f0000U) >> 16)
-#define AGP_CAPID_GET_NEXT_PTR(x) (((x) & 0x0000ff00U) >> 8)
-#define AGP_CAPID_GET_CAP_ID(x) (((x) & 0x000000ffU) >> 0)
-
-#define AGP_STATUS 0x4
-#define AGP_COMMAND 0x8
-
-/*
- * Config offsets for Intel AGP chipsets.
- */
-#define AGP_INTEL_NBXCFG 0x50
-#define AGP_INTEL_ERRSTS 0x91
-#define AGP_INTEL_AGPCTRL 0xb0
-#define AGP_INTEL_APSIZE 0xb4
-#define AGP_INTEL_ATTBASE 0xb8
-
-/*
- * Config offsets for Intel i820/i840/i845/i850/i860/i865 AGP chipsets.
- */
-#define AGP_INTEL_MCHCFG 0x50
-#define AGP_INTEL_I820_RDCR 0x51
-#define AGP_INTEL_I845_MCHCFG 0x51
-#define AGP_INTEL_I8XX_ERRSTS 0xc8
-
-/*
- * Config offsets for VIA AGP chipsets.
- */
-#define AGP_VIA_GARTCTRL 0x80
-#define AGP_VIA_APSIZE 0x84
-#define AGP_VIA_ATTBASE 0x88
-
-/*
- * Config offsets for SiS AGP chipsets.
- */
-#define AGP_SIS_ATTBASE 0x90
-#define AGP_SIS_WINCTRL 0x94
-#define AGP_SIS_TLBCTRL 0x97
-#define AGP_SIS_TLBFLUSH 0x98
-
-/*
- * Config offsets for Ali AGP chipsets.
- */
-#define AGP_ALI_AGPCTRL 0xb8
-#define AGP_ALI_ATTBASE 0xbc
-#define AGP_ALI_TLBCTRL 0xc0
-
-/*
- * Config offsets for the AMD 751 chipset.
- */
-#define AGP_AMD751_APBASE 0x10
-#define AGP_AMD751_REGISTERS 0x14
-#define AGP_AMD751_APCTRL 0xac
-#define AGP_AMD751_MODECTRL 0xb0
-#define AGP_AMD751_MODECTRL_SYNEN 0x80
-#define AGP_AMD751_MODECTRL2 0xb2
-#define AGP_AMD751_MODECTRL2_G1LM 0x01
-#define AGP_AMD751_MODECTRL2_GPDCE 0x02
-#define AGP_AMD751_MODECTRL2_NGSE 0x08
-
-/*
- * Memory mapped register offsets for AMD 751 chipset.
- */
-#define AGP_AMD751_CAPS 0x00
-#define AGP_AMD751_CAPS_EHI 0x0800
-#define AGP_AMD751_CAPS_P2P 0x0400
-#define AGP_AMD751_CAPS_MPC 0x0200
-#define AGP_AMD751_CAPS_VBE 0x0100
-#define AGP_AMD751_CAPS_REV 0x00ff
-#define AGP_AMD751_STATUS 0x02
-#define AGP_AMD751_STATUS_P2PS 0x0800
-#define AGP_AMD751_STATUS_GCS 0x0400
-#define AGP_AMD751_STATUS_MPS 0x0200
-#define AGP_AMD751_STATUS_VBES 0x0100
-#define AGP_AMD751_STATUS_P2PE 0x0008
-#define AGP_AMD751_STATUS_GCE 0x0004
-#define AGP_AMD751_STATUS_VBEE 0x0001
-#define AGP_AMD751_ATTBASE 0x04
-#define AGP_AMD751_TLBCTRL 0x0c
-
-/*
- * Config registers for i810 device 0
- */
-#define AGP_I810_SMRAM 0x70
-#define AGP_I810_SMRAM_GMS 0xc0
-#define AGP_I810_SMRAM_GMS_DISABLED 0x00
-#define AGP_I810_SMRAM_GMS_ENABLED_0 0x40
-#define AGP_I810_SMRAM_GMS_ENABLED_512 0x80
-#define AGP_I810_SMRAM_GMS_ENABLED_1024 0xc0
-#define AGP_I810_MISCC 0x72
-#define AGP_I810_MISCC_WINSIZE 0x0001
-#define AGP_I810_MISCC_WINSIZE_64 0x0000
-#define AGP_I810_MISCC_WINSIZE_32 0x0001
-#define AGP_I810_MISCC_PLCK 0x0008
-#define AGP_I810_MISCC_PLCK_UNLOCKED 0x0000
-#define AGP_I810_MISCC_PLCK_LOCKED 0x0008
-#define AGP_I810_MISCC_WPTC 0x0030
-#define AGP_I810_MISCC_WPTC_NOLIMIT 0x0000
-#define AGP_I810_MISCC_WPTC_62 0x0010
-#define AGP_I810_MISCC_WPTC_50 0x0020
-#define AGP_I810_MISCC_WPTC_37 0x0030
-#define AGP_I810_MISCC_RPTC 0x00c0
-#define AGP_I810_MISCC_RPTC_NOLIMIT 0x0000
-#define AGP_I810_MISCC_RPTC_62 0x0040
-#define AGP_I810_MISCC_RPTC_50 0x0080
-#define AGP_I810_MISCC_RPTC_37 0x00c0
-
-/*
- * Config registers for i810 device 1
- */
-#define AGP_I810_GMADR 0x10
-#define AGP_I810_MMADR 0x14
-
-/*
- * Memory mapped register offsets for i810 chipset.
- */
-#define AGP_I810_PGTBL_CTL 0x2020
-#define AGP_I810_DRT 0x3000
-#define AGP_I810_DRT_UNPOPULATED 0x00
-#define AGP_I810_DRT_POPULATED 0x01
-#define AGP_I810_GTT 0x10000
-
-/*
- * Config registers for i830MG device 0
- */
-#define AGP_I830_GCC1 0x52
-#define AGP_I830_GCC1_DEV2 0x08
-#define AGP_I830_GCC1_DEV2_ENABLED 0x00
-#define AGP_I830_GCC1_DEV2_DISABLED 0x08
-#define AGP_I830_GCC1_GMS 0x70
-#define AGP_I830_GCC1_GMS_STOLEN_512 0x20
-#define AGP_I830_GCC1_GMS_STOLEN_1024 0x30
-#define AGP_I830_GCC1_GMS_STOLEN_8192 0x40
-#define AGP_I830_GCC1_GMASIZE 0x01
-#define AGP_I830_GCC1_GMASIZE_64 0x01
-#define AGP_I830_GCC1_GMASIZE_128 0x00
-
-/*
- * Config registers for 852GM/855GM/865G device 0
- */
-#define AGP_I855_GCC1 0x52
-#define AGP_I855_GCC1_DEV2 0x08
-#define AGP_I855_GCC1_DEV2_ENABLED 0x00
-#define AGP_I855_GCC1_DEV2_DISABLED 0x08
-#define AGP_I855_GCC1_GMS 0x70
-#define AGP_I855_GCC1_GMS_STOLEN_0M 0x00
-#define AGP_I855_GCC1_GMS_STOLEN_1M 0x10
-#define AGP_I855_GCC1_GMS_STOLEN_4M 0x20
-#define AGP_I855_GCC1_GMS_STOLEN_8M 0x30
-#define AGP_I855_GCC1_GMS_STOLEN_16M 0x40
-#define AGP_I855_GCC1_GMS_STOLEN_32M 0x50
-
-/*
- * 852GM/855GM variant identification
- */
-#define AGP_I85X_CAPID 0x44
-#define AGP_I85X_VARIANT_MASK 0x7
-#define AGP_I85X_VARIANT_SHIFT 5
-#define AGP_I855_GME 0x0
-#define AGP_I855_GM 0x4
-#define AGP_I852_GME 0x2
-#define AGP_I852_GM 0x5
-
-#endif /* !_PCI_AGPREG_H_ */
diff --git a/sys/dev/agp/agpvar.h b/sys/dev/agp/agpvar.h
deleted file mode 100644
index 0869c26d2b86..000000000000
--- a/sys/dev/agp/agpvar.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * 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 _PCI_AGPVAR_H_
-#define _PCI_AGPVAR_H_
-
-/*
- * The AGP chipset can be acquired by user or kernel code. If the
- * chipset has already been acquired, it cannot be acquired by another
- * user until the previous user has released it.
- */
-enum agp_acquire_state {
- AGP_ACQUIRE_FREE,
- AGP_ACQUIRE_USER,
- AGP_ACQUIRE_KERNEL
-};
-
-/*
- * This structure is used to query the state of the AGP system.
- */
-struct agp_info {
- u_int32_t ai_mode;
- vm_offset_t ai_aperture_base;
- vm_size_t ai_aperture_size;
- vm_offset_t ai_aperture_va;
- vm_size_t ai_memory_allowed;
- vm_size_t ai_memory_used;
- u_int32_t ai_devid;
-};
-
-struct agp_memory_info {
- vm_size_t ami_size; /* size in bytes */
- vm_offset_t ami_physical; /* bogus hack for i810 */
- vm_offset_t ami_offset; /* page offset if bound */
- int ami_is_bound; /* non-zero if bound */
-};
-
-/*
- * Find the AGP device and return it.
- */
-device_t agp_find_device(void);
-
-/*
- * Return the current owner of the AGP chipset.
- */
-enum agp_acquire_state agp_state(device_t dev);
-
-/*
- * Query the state of the AGP system.
- */
-void agp_get_info(device_t dev, struct agp_info *info);
-
-/*
- * Acquire the AGP chipset for use by the kernel. Returns EBUSY if the
- * AGP chipset is already acquired by another user.
- */
-int agp_acquire(device_t dev);
-
-/*
- * Release the AGP chipset.
- */
-int agp_release(device_t dev);
-
-/*
- * Enable the agp hardware with the relavent mode. The mode bits are
- * defined in <pci/agpreg.h>
- */
-int agp_enable(device_t dev, u_int32_t mode);
-
-/*
- * Allocate physical memory suitable for mapping into the AGP
- * aperture. The value returned is an opaque handle which can be
- * passed to agp_bind(), agp_unbind() or agp_deallocate().
- */
-void *agp_alloc_memory(device_t dev, int type, vm_size_t bytes);
-
-/*
- * Free memory which was allocated with agp_allocate().
- */
-void agp_free_memory(device_t dev, void *handle);
-
-/*
- * Bind memory allocated with agp_allocate() at a given offset within
- * the AGP aperture. Returns EINVAL if the memory is already bound or
- * the offset is not at an AGP page boundary.
- */
-int agp_bind_memory(device_t dev, void *handle, vm_offset_t offset);
-
-/*
- * Unbind memory from the AGP aperture. Returns EINVAL if the memory
- * is not bound.
- */
-int agp_unbind_memory(device_t dev, void *handle);
-
-/*
- * Retrieve information about a memory block allocated with
- * agp_alloc_memory().
- */
-void agp_memory_info(device_t dev, void *handle, struct agp_memory_info *mi);
-
-#endif /* !_PCI_AGPVAR_H_ */
diff --git a/sys/dev/atkbdc/atkbd.c b/sys/dev/atkbdc/atkbd.c
deleted file mode 100644
index edf6489310f8..000000000000
--- a/sys/dev/atkbdc/atkbd.c
+++ /dev/null
@@ -1,1408 +0,0 @@
-/*-
- * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must 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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (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$
- */
-
-#include "opt_kbd.h"
-#include "opt_atkbd.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/proc.h>
-#include <sys/limits.h>
-#include <sys/malloc.h>
-
-#include <machine/bus.h>
-#include <machine/resource.h>
-
-#ifdef __i386__
-#include <machine/md_var.h>
-#include <machine/psl.h>
-#include <machine/vm86.h>
-#include <machine/pc/bios.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#endif /* __i386__ */
-
-#include <sys/kbio.h>
-#include <dev/kbd/kbdreg.h>
-#include <dev/kbd/atkbdreg.h>
-#include <dev/kbd/atkbdcreg.h>
-
-#include <isa/isareg.h>
-
-static timeout_t atkbd_timeout;
-
-int
-atkbd_probe_unit(int unit, int ctlr, int irq, int flags)
-{
- keyboard_switch_t *sw;
- int args[2];
- int error;
-
- sw = kbd_get_switch(ATKBD_DRIVER_NAME);
- if (sw == NULL)
- return ENXIO;
-
- args[0] = ctlr;
- args[1] = irq;
- error = (*sw->probe)(unit, args, flags);
- if (error)
- return error;
- return 0;
-}
-
-int
-atkbd_attach_unit(int unit, keyboard_t **kbd, int ctlr, int irq, int flags)
-{
- keyboard_switch_t *sw;
- int args[2];
- int error;
-
- sw = kbd_get_switch(ATKBD_DRIVER_NAME);
- if (sw == NULL)
- return ENXIO;
-
- /* reset, initialize and enable the device */
- args[0] = ctlr;
- args[1] = irq;
- *kbd = NULL;
- error = (*sw->probe)(unit, args, flags);
- if (error)
- return error;
- error = (*sw->init)(unit, kbd, args, flags);
- if (error)
- return error;
- (*sw->enable)(*kbd);
-
-#ifdef KBD_INSTALL_CDEV
- /* attach a virtual keyboard cdev */
- error = kbd_attach(*kbd);
- if (error)
- return error;
-#endif
-
- /*
- * This is a kludge to compensate for lost keyboard interrupts.
- * A similar code used to be in syscons. See below. XXX
- */
- atkbd_timeout(*kbd);
-
- if (bootverbose)
- (*sw->diag)(*kbd, bootverbose);
- return 0;
-}
-
-static void
-atkbd_timeout(void *arg)
-{
- keyboard_t *kbd;
- int s;
-
- /*
- * The original text of the following comments are extracted
- * from syscons.c (1.287)
- *
- * With release 2.1 of the Xaccel server, the keyboard is left
- * hanging pretty often. Apparently an interrupt from the
- * keyboard is lost, and I don't know why (yet).
- * This ugly hack calls the low-level interrupt routine if input
- * is ready for the keyboard and conveniently hides the problem. XXX
- *
- * Try removing anything stuck in the keyboard controller; whether
- * it's a keyboard scan code or mouse data. The low-level
- * interrupt routine doesn't read the mouse data directly,
- * but the keyboard controller driver will, as a side effect.
- */
- /*
- * And here is bde's original comment about this:
- *
- * This is necessary to handle edge triggered interrupts - if we
- * returned when our IRQ is high due to unserviced input, then there
- * would be no more keyboard IRQs until the keyboard is reset by
- * external powers.
- *
- * The keyboard apparently unwedges the irq in most cases.
- */
- s = spltty();
- kbd = (keyboard_t *)arg;
- if ((*kbdsw[kbd->kb_index]->lock)(kbd, TRUE)) {
- /*
- * We have seen the lock flag is not set. Let's reset
- * the flag early, otherwise the LED update routine fails
- * which may want the lock during the interrupt routine.
- */
- (*kbdsw[kbd->kb_index]->lock)(kbd, FALSE);
- if ((*kbdsw[kbd->kb_index]->check_char)(kbd))
- (*kbdsw[kbd->kb_index]->intr)(kbd, NULL);
- }
- splx(s);
- timeout(atkbd_timeout, arg, hz/10);
-}
-
-/* LOW-LEVEL */
-
-#define ATKBD_DEFAULT 0
-
-typedef struct atkbd_state {
- KBDC kbdc; /* keyboard controller */
- /* XXX: don't move this field; pcvt
- * expects `kbdc' to be the first
- * field in this structure. */
- int ks_mode; /* input mode (K_XLATE,K_RAW,K_CODE) */
- int ks_flags; /* flags */
-#define COMPOSE (1 << 0)
- int ks_polling;
- int ks_state; /* shift/lock key state */
- int ks_accents; /* accent key index (> 0) */
- u_int ks_composed_char; /* composed char code (> 0) */
- u_char ks_prefix; /* AT scan code prefix */
-} atkbd_state_t;
-
-/* keyboard driver declaration */
-static int atkbd_configure(int flags);
-static kbd_probe_t atkbd_probe;
-static kbd_init_t atkbd_init;
-static kbd_term_t atkbd_term;
-static kbd_intr_t atkbd_intr;
-static kbd_test_if_t atkbd_test_if;
-static kbd_enable_t atkbd_enable;
-static kbd_disable_t atkbd_disable;
-static kbd_read_t atkbd_read;
-static kbd_check_t atkbd_check;
-static kbd_read_char_t atkbd_read_char;
-static kbd_check_char_t atkbd_check_char;
-static kbd_ioctl_t atkbd_ioctl;
-static kbd_lock_t atkbd_lock;
-static kbd_clear_state_t atkbd_clear_state;
-static kbd_get_state_t atkbd_get_state;
-static kbd_set_state_t atkbd_set_state;
-static kbd_poll_mode_t atkbd_poll;
-
-static keyboard_switch_t atkbdsw = {
- atkbd_probe,
- atkbd_init,
- atkbd_term,
- atkbd_intr,
- atkbd_test_if,
- atkbd_enable,
- atkbd_disable,
- atkbd_read,
- atkbd_check,
- atkbd_read_char,
- atkbd_check_char,
- atkbd_ioctl,
- atkbd_lock,
- atkbd_clear_state,
- atkbd_get_state,
- atkbd_set_state,
- genkbd_get_fkeystr,
- atkbd_poll,
- genkbd_diag,
-};
-
-KEYBOARD_DRIVER(atkbd, atkbdsw, atkbd_configure);
-
-/* local functions */
-static int get_typematic(keyboard_t *kbd);
-static int setup_kbd_port(KBDC kbdc, int port, int intr);
-static int get_kbd_echo(KBDC kbdc);
-static int probe_keyboard(KBDC kbdc, int flags);
-static int init_keyboard(KBDC kbdc, int *type, int flags);
-static int write_kbd(KBDC kbdc, int command, int data);
-static int get_kbd_id(KBDC kbdc);
-static int typematic(int delay, int rate);
-static int typematic_delay(int delay);
-static int typematic_rate(int rate);
-
-/* local variables */
-
-/* the initial key map, accent map and fkey strings */
-#ifdef ATKBD_DFLT_KEYMAP
-#define KBD_DFLT_KEYMAP
-#include "atkbdmap.h"
-#endif
-#include <dev/kbd/kbdtables.h>
-
-/* structures for the default keyboard */
-static keyboard_t default_kbd;
-static atkbd_state_t default_kbd_state;
-static keymap_t default_keymap;
-static accentmap_t default_accentmap;
-static fkeytab_t default_fkeytab[NUM_FKEYS];
-
-/*
- * The back door to the keyboard driver!
- * This function is called by the console driver, via the kbdio module,
- * to tickle keyboard drivers when the low-level console is being initialized.
- * Almost nothing in the kernel has been initialied yet. Try to probe
- * keyboards if possible.
- * NOTE: because of the way the low-level console is initialized, this routine
- * may be called more than once!!
- */
-static int
-atkbd_configure(int flags)
-{
- keyboard_t *kbd;
- int arg[2];
- int i;
-
- /* probe the keyboard controller */
- atkbdc_configure();
-
- /* if the driver is disabled, unregister the keyboard if any */
- if ((resource_int_value("atkbd", ATKBD_DEFAULT, "disabled", &i) == 0)
- && i != 0) {
- i = kbd_find_keyboard(ATKBD_DRIVER_NAME, ATKBD_DEFAULT);
- if (i >= 0) {
- kbd = kbd_get_keyboard(i);
- kbd_unregister(kbd);
- kbd->kb_flags &= ~KB_REGISTERED;
- }
- return 0;
- }
-
- /* XXX: a kludge to obtain the device configuration flags */
- if (resource_int_value("atkbd", ATKBD_DEFAULT, "flags", &i) == 0)
- flags |= i;
-
- /* probe the default keyboard */
- arg[0] = -1;
- arg[1] = -1;
- kbd = NULL;
- if (atkbd_probe(ATKBD_DEFAULT, arg, flags))
- return 0;
- if (atkbd_init(ATKBD_DEFAULT, &kbd, arg, flags))
- return 0;
-
- /* return the number of found keyboards */
- return 1;
-}
-
-/* low-level functions */
-
-/* detect a keyboard */
-static int
-atkbd_probe(int unit, void *arg, int flags)
-{
- KBDC kbdc;
- int *data = (int *)arg; /* data[0]: controller, data[1]: irq */
-
- /* XXX */
- if (unit == ATKBD_DEFAULT) {
- if (KBD_IS_PROBED(&default_kbd))
- return 0;
- }
-
- kbdc = atkbdc_open(data[0]);
- if (kbdc == NULL)
- return ENXIO;
- if (probe_keyboard(kbdc, flags)) {
- if (flags & KB_CONF_FAIL_IF_NO_KBD)
- return ENXIO;
- }
- return 0;
-}
-
-/* reset and initialize the device */
-static int
-atkbd_init(int unit, keyboard_t **kbdp, void *arg, int flags)
-{
- keyboard_t *kbd;
- atkbd_state_t *state;
- keymap_t *keymap;
- accentmap_t *accmap;
- fkeytab_t *fkeymap;
- int fkeymap_size;
- int delay[2];
- int *data = (int *)arg; /* data[0]: controller, data[1]: irq */
-
- /* XXX */
- if (unit == ATKBD_DEFAULT) {
- *kbdp = kbd = &default_kbd;
- if (KBD_IS_INITIALIZED(kbd) && KBD_IS_CONFIGURED(kbd))
- return 0;
- state = &default_kbd_state;
- keymap = &default_keymap;
- accmap = &default_accentmap;
- fkeymap = default_fkeytab;
- fkeymap_size =
- sizeof(default_fkeytab)/sizeof(default_fkeytab[0]);
- } else if (*kbdp == NULL) {
- *kbdp = kbd = malloc(sizeof(*kbd), M_DEVBUF, M_NOWAIT | M_ZERO);
- state = malloc(sizeof(*state), M_DEVBUF, M_NOWAIT | M_ZERO);
- keymap = malloc(sizeof(key_map), M_DEVBUF, M_NOWAIT);
- accmap = malloc(sizeof(accent_map), M_DEVBUF, M_NOWAIT);
- fkeymap = malloc(sizeof(fkey_tab), M_DEVBUF, M_NOWAIT);
- fkeymap_size = sizeof(fkey_tab)/sizeof(fkey_tab[0]);
- if ((kbd == NULL) || (state == NULL) || (keymap == NULL)
- || (accmap == NULL) || (fkeymap == NULL)) {
- if (state != NULL)
- free(state, M_DEVBUF);
- if (keymap != NULL)
- free(keymap, M_DEVBUF);
- if (accmap != NULL)
- free(accmap, M_DEVBUF);
- if (fkeymap != NULL)
- free(fkeymap, M_DEVBUF);
- if (kbd != NULL)
- free(kbd, M_DEVBUF);
- return ENOMEM;
- }
- } else if (KBD_IS_INITIALIZED(*kbdp) && KBD_IS_CONFIGURED(*kbdp)) {
- return 0;
- } else {
- kbd = *kbdp;
- state = (atkbd_state_t *)kbd->kb_data;
- bzero(state, sizeof(*state));
- keymap = kbd->kb_keymap;
- accmap = kbd->kb_accentmap;
- fkeymap = kbd->kb_fkeytab;
- fkeymap_size = kbd->kb_fkeytab_size;
- }
-
- if (!KBD_IS_PROBED(kbd)) {
- state->kbdc = atkbdc_open(data[0]);
- if (state->kbdc == NULL)
- return ENXIO;
- kbd_init_struct(kbd, ATKBD_DRIVER_NAME, KB_OTHER, unit, flags,
- 0, 0);
- bcopy(&key_map, keymap, sizeof(key_map));
- bcopy(&accent_map, accmap, sizeof(accent_map));
- bcopy(fkey_tab, fkeymap,
- imin(fkeymap_size*sizeof(fkeymap[0]), sizeof(fkey_tab)));
- kbd_set_maps(kbd, keymap, accmap, fkeymap, fkeymap_size);
- kbd->kb_data = (void *)state;
-
- if (probe_keyboard(state->kbdc, flags)) { /* shouldn't happen */
- if (flags & KB_CONF_FAIL_IF_NO_KBD)
- return ENXIO;
- } else {
- KBD_FOUND_DEVICE(kbd);
- }
- atkbd_clear_state(kbd);
- state->ks_mode = K_XLATE;
- /*
- * FIXME: set the initial value for lock keys in ks_state
- * according to the BIOS data?
- */
- KBD_PROBE_DONE(kbd);
- }
- if (!KBD_IS_INITIALIZED(kbd) && !(flags & KB_CONF_PROBE_ONLY)) {
- kbd->kb_config = flags & ~KB_CONF_PROBE_ONLY;
- if (KBD_HAS_DEVICE(kbd)
- && init_keyboard(state->kbdc, &kbd->kb_type, kbd->kb_config)
- && (kbd->kb_config & KB_CONF_FAIL_IF_NO_KBD))
- return ENXIO;
- atkbd_ioctl(kbd, KDSETLED, (caddr_t)&state->ks_state);
- get_typematic(kbd);
- delay[0] = kbd->kb_delay1;
- delay[1] = kbd->kb_delay2;
- atkbd_ioctl(kbd, KDSETREPEAT, (caddr_t)delay);
- KBD_INIT_DONE(kbd);
- }
- if (!KBD_IS_CONFIGURED(kbd)) {
- if (kbd_register(kbd) < 0)
- return ENXIO;
- KBD_CONFIG_DONE(kbd);
- }
-
- return 0;
-}
-
-/* finish using this keyboard */
-static int
-atkbd_term(keyboard_t *kbd)
-{
- kbd_unregister(kbd);
- return 0;
-}
-
-/* keyboard interrupt routine */
-static int
-atkbd_intr(keyboard_t *kbd, void *arg)
-{
- atkbd_state_t *state;
- int delay[2];
- int c;
-
- if (KBD_IS_ACTIVE(kbd) && KBD_IS_BUSY(kbd)) {
- /* let the callback function to process the input */
- (*kbd->kb_callback.kc_func)(kbd, KBDIO_KEYINPUT,
- kbd->kb_callback.kc_arg);
- } else {
- /* read and discard the input; no one is waiting for input */
- do {
- c = atkbd_read_char(kbd, FALSE);
- } while (c != NOKEY);
-
- if (!KBD_HAS_DEVICE(kbd)) {
- /*
- * The keyboard was not detected before;
- * it must have been reconnected!
- */
- state = (atkbd_state_t *)kbd->kb_data;
- init_keyboard(state->kbdc, &kbd->kb_type,
- kbd->kb_config);
- atkbd_ioctl(kbd, KDSETLED, (caddr_t)&state->ks_state);
- get_typematic(kbd);
- delay[0] = kbd->kb_delay1;
- delay[1] = kbd->kb_delay2;
- atkbd_ioctl(kbd, KDSETREPEAT, (caddr_t)delay);
- KBD_FOUND_DEVICE(kbd);
- }
- }
- return 0;
-}
-
-/* test the interface to the device */
-static int
-atkbd_test_if(keyboard_t *kbd)
-{
- int error;
- int s;
-
- error = 0;
- empty_both_buffers(((atkbd_state_t *)kbd->kb_data)->kbdc, 10);
- s = spltty();
- if (!test_controller(((atkbd_state_t *)kbd->kb_data)->kbdc))
- error = EIO;
- else if (test_kbd_port(((atkbd_state_t *)kbd->kb_data)->kbdc) != 0)
- error = EIO;
- splx(s);
-
- return error;
-}
-
-/*
- * Enable the access to the device; until this function is called,
- * the client cannot read from the keyboard.
- */
-static int
-atkbd_enable(keyboard_t *kbd)
-{
- int s;
-
- s = spltty();
- KBD_ACTIVATE(kbd);
- splx(s);
- return 0;
-}
-
-/* disallow the access to the device */
-static int
-atkbd_disable(keyboard_t *kbd)
-{
- int s;
-
- s = spltty();
- KBD_DEACTIVATE(kbd);
- splx(s);
- return 0;
-}
-
-/* read one byte from the keyboard if it's allowed */
-static int
-atkbd_read(keyboard_t *kbd, int wait)
-{
- int c;
-
- if (wait)
- c = read_kbd_data(((atkbd_state_t *)kbd->kb_data)->kbdc);
- else
- c = read_kbd_data_no_wait(((atkbd_state_t *)kbd->kb_data)->kbdc);
- if (c != -1)
- ++kbd->kb_count;
- return (KBD_IS_ACTIVE(kbd) ? c : -1);
-}
-
-/* check if data is waiting */
-static int
-atkbd_check(keyboard_t *kbd)
-{
- if (!KBD_IS_ACTIVE(kbd))
- return FALSE;
- return kbdc_data_ready(((atkbd_state_t *)kbd->kb_data)->kbdc);
-}
-
-/* read char from the keyboard */
-static u_int
-atkbd_read_char(keyboard_t *kbd, int wait)
-{
- atkbd_state_t *state;
- u_int action;
- int scancode;
- int keycode;
-
- state = (atkbd_state_t *)kbd->kb_data;
-next_code:
- /* do we have a composed char to return? */
- if (!(state->ks_flags & COMPOSE) && (state->ks_composed_char > 0)) {
- action = state->ks_composed_char;
- state->ks_composed_char = 0;
- if (action > UCHAR_MAX)
- return ERRKEY;
- return action;
- }
-
- /* see if there is something in the keyboard port */
- if (wait) {
- do {
- scancode = read_kbd_data(state->kbdc);
- } while (scancode == -1);
- } else {
- scancode = read_kbd_data_no_wait(state->kbdc);
- if (scancode == -1)
- return NOKEY;
- }
- ++kbd->kb_count;
-
-#if KBDIO_DEBUG >= 10
- printf("atkbd_read_char(): scancode:0x%x\n", scancode);
-#endif
-
- /* return the byte as is for the K_RAW mode */
- if (state->ks_mode == K_RAW)
- return scancode;
-
- /* translate the scan code into a keycode */
- keycode = scancode & 0x7F;
- switch (state->ks_prefix) {
- case 0x00: /* normal scancode */
- switch(scancode) {
- case 0xB8: /* left alt (compose key) released */
- if (state->ks_flags & COMPOSE) {
- state->ks_flags &= ~COMPOSE;
- if (state->ks_composed_char > UCHAR_MAX)
- state->ks_composed_char = 0;
- }
- break;
- case 0x38: /* left alt (compose key) pressed */
- if (!(state->ks_flags & COMPOSE)) {
- state->ks_flags |= COMPOSE;
- state->ks_composed_char = 0;
- }
- break;
- case 0xE0:
- case 0xE1:
- state->ks_prefix = scancode;
- goto next_code;
- }
- break;
- case 0xE0: /* 0xE0 prefix */
- state->ks_prefix = 0;
- switch (keycode) {
- case 0x1C: /* right enter key */
- keycode = 0x59;
- break;
- case 0x1D: /* right ctrl key */
- keycode = 0x5A;
- break;
- case 0x35: /* keypad divide key */
- keycode = 0x5B;
- break;
- case 0x37: /* print scrn key */
- keycode = 0x5C;
- break;
- case 0x38: /* right alt key (alt gr) */
- keycode = 0x5D;
- break;
- case 0x46: /* ctrl-pause/break on AT 101 (see below) */
- keycode = 0x68;
- break;
- case 0x47: /* grey home key */
- keycode = 0x5E;
- break;
- case 0x48: /* grey up arrow key */
- keycode = 0x5F;
- break;
- case 0x49: /* grey page up key */
- keycode = 0x60;
- break;
- case 0x4B: /* grey left arrow key */
- keycode = 0x61;
- break;
- case 0x4D: /* grey right arrow key */
- keycode = 0x62;
- break;
- case 0x4F: /* grey end key */
- keycode = 0x63;
- break;
- case 0x50: /* grey down arrow key */
- keycode = 0x64;
- break;
- case 0x51: /* grey page down key */
- keycode = 0x65;
- break;
- case 0x52: /* grey insert key */
- keycode = 0x66;
- break;
- case 0x53: /* grey delete key */
- keycode = 0x67;
- break;
- /* the following 3 are only used on the MS "Natural" keyboard */
- case 0x5b: /* left Window key */
- keycode = 0x69;
- break;
- case 0x5c: /* right Window key */
- keycode = 0x6a;
- break;
- case 0x5d: /* menu key */
- keycode = 0x6b;
- break;
- default: /* ignore everything else */
- goto next_code;
- }
- break;
- case 0xE1: /* 0xE1 prefix */
- /*
- * The pause/break key on the 101 keyboard produces:
- * E1-1D-45 E1-9D-C5
- * Ctrl-pause/break produces:
- * E0-46 E0-C6 (See above.)
- */
- state->ks_prefix = 0;
- if (keycode == 0x1D)
- state->ks_prefix = 0x1D;
- goto next_code;
- /* NOT REACHED */
- case 0x1D: /* pause / break */
- state->ks_prefix = 0;
- if (keycode != 0x45)
- goto next_code;
- keycode = 0x68;
- break;
- }
-
- if (kbd->kb_type == KB_84) {
- switch (keycode) {
- case 0x37: /* *(numpad)/print screen */
- if (state->ks_flags & SHIFTS)
- keycode = 0x5c; /* print screen */
- break;
- case 0x45: /* num lock/pause */
- if (state->ks_flags & CTLS)
- keycode = 0x68; /* pause */
- break;
- case 0x46: /* scroll lock/break */
- if (state->ks_flags & CTLS)
- keycode = 0x6c; /* break */
- break;
- }
- } else if (kbd->kb_type == KB_101) {
- switch (keycode) {
- case 0x5c: /* print screen */
- if (state->ks_flags & ALTS)
- keycode = 0x54; /* sysrq */
- break;
- case 0x68: /* pause/break */
- if (state->ks_flags & CTLS)
- keycode = 0x6c; /* break */
- break;
- }
- }
-
- /* return the key code in the K_CODE mode */
- if (state->ks_mode == K_CODE)
- return (keycode | (scancode & 0x80));
-
- /* compose a character code */
- if (state->ks_flags & COMPOSE) {
- switch (keycode | (scancode & 0x80)) {
- /* key pressed, process it */
- case 0x47: case 0x48: case 0x49: /* keypad 7,8,9 */
- state->ks_composed_char *= 10;
- state->ks_composed_char += keycode - 0x40;
- if (state->ks_composed_char > UCHAR_MAX)
- return ERRKEY;
- goto next_code;
- case 0x4B: case 0x4C: case 0x4D: /* keypad 4,5,6 */
- state->ks_composed_char *= 10;
- state->ks_composed_char += keycode - 0x47;
- if (state->ks_composed_char > UCHAR_MAX)
- return ERRKEY;
- goto next_code;
- case 0x4F: case 0x50: case 0x51: /* keypad 1,2,3 */
- state->ks_composed_char *= 10;
- state->ks_composed_char += keycode - 0x4E;
- if (state->ks_composed_char > UCHAR_MAX)
- return ERRKEY;
- goto next_code;
- case 0x52: /* keypad 0 */
- state->ks_composed_char *= 10;
- if (state->ks_composed_char > UCHAR_MAX)
- return ERRKEY;
- goto next_code;
-
- /* key released, no interest here */
- case 0xC7: case 0xC8: case 0xC9: /* keypad 7,8,9 */
- case 0xCB: case 0xCC: case 0xCD: /* keypad 4,5,6 */
- case 0xCF: case 0xD0: case 0xD1: /* keypad 1,2,3 */
- case 0xD2: /* keypad 0 */
- goto next_code;
-
- case 0x38: /* left alt key */
- break;
-
- default:
- if (state->ks_composed_char > 0) {
- state->ks_flags &= ~COMPOSE;
- state->ks_composed_char = 0;
- return ERRKEY;
- }
- break;
- }
- }
-
- /* keycode to key action */
- action = genkbd_keyaction(kbd, keycode, scancode & 0x80,
- &state->ks_state, &state->ks_accents);
- if (action == NOKEY)
- goto next_code;
- else
- return action;
-}
-
-/* check if char is waiting */
-static int
-atkbd_check_char(keyboard_t *kbd)
-{
- atkbd_state_t *state;
-
- if (!KBD_IS_ACTIVE(kbd))
- return FALSE;
- state = (atkbd_state_t *)kbd->kb_data;
- if (!(state->ks_flags & COMPOSE) && (state->ks_composed_char > 0))
- return TRUE;
- return kbdc_data_ready(state->kbdc);
-}
-
-/* some useful control functions */
-static int
-atkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
-{
- /* trasnlate LED_XXX bits into the device specific bits */
- static u_char ledmap[8] = {
- 0, 4, 2, 6, 1, 5, 3, 7,
- };
- atkbd_state_t *state = kbd->kb_data;
- int error;
- int s;
- int i;
-
- s = spltty();
- switch (cmd) {
-
- case KDGKBMODE: /* get keyboard mode */
- *(int *)arg = state->ks_mode;
- break;
- case KDSKBMODE: /* set keyboard mode */
- switch (*(int *)arg) {
- case K_XLATE:
- if (state->ks_mode != K_XLATE) {
- /* make lock key state and LED state match */
- state->ks_state &= ~LOCK_MASK;
- state->ks_state |= KBD_LED_VAL(kbd);
- }
- /* FALLTHROUGH */
- case K_RAW:
- case K_CODE:
- if (state->ks_mode != *(int *)arg) {
- atkbd_clear_state(kbd);
- state->ks_mode = *(int *)arg;
- }
- break;
- default:
- splx(s);
- return EINVAL;
- }
- break;
-
- case KDGETLED: /* get keyboard LED */
- *(int *)arg = KBD_LED_VAL(kbd);
- break;
- case KDSETLED: /* set keyboard LED */
- /* NOTE: lock key state in ks_state won't be changed */
- if (*(int *)arg & ~LOCK_MASK) {
- splx(s);
- return EINVAL;
- }
- i = *(int *)arg;
- /* replace CAPS LED with ALTGR LED for ALTGR keyboards */
- if (state->ks_mode == K_XLATE &&
- kbd->kb_keymap->n_keys > ALTGR_OFFSET) {
- if (i & ALKED)
- i |= CLKED;
- else
- i &= ~CLKED;
- }
- if (KBD_HAS_DEVICE(kbd)) {
- error = write_kbd(state->kbdc, KBDC_SET_LEDS,
- ledmap[i & LED_MASK]);
- if (error) {
- splx(s);
- return error;
- }
- }
- KBD_LED_VAL(kbd) = *(int *)arg;
- break;
-
- case KDGKBSTATE: /* get lock key state */
- *(int *)arg = state->ks_state & LOCK_MASK;
- break;
- case KDSKBSTATE: /* set lock key state */
- if (*(int *)arg & ~LOCK_MASK) {
- splx(s);
- return EINVAL;
- }
- state->ks_state &= ~LOCK_MASK;
- state->ks_state |= *(int *)arg;
- splx(s);
- /* set LEDs and quit */
- return atkbd_ioctl(kbd, KDSETLED, arg);
-
- case KDSETREPEAT: /* set keyboard repeat rate (new interface) */
- splx(s);
- if (!KBD_HAS_DEVICE(kbd))
- return 0;
- i = typematic(((int *)arg)[0], ((int *)arg)[1]);
- error = write_kbd(state->kbdc, KBDC_SET_TYPEMATIC, i);
- if (error == 0) {
- kbd->kb_delay1 = typematic_delay(i);
- kbd->kb_delay2 = typematic_rate(i);
- }
- return error;
-
- case KDSETRAD: /* set keyboard repeat rate (old interface) */
- splx(s);
- if (!KBD_HAS_DEVICE(kbd))
- return 0;
- error = write_kbd(state->kbdc, KBDC_SET_TYPEMATIC, *(int *)arg);
- if (error == 0) {
- kbd->kb_delay1 = typematic_delay(*(int *)arg);
- kbd->kb_delay2 = typematic_rate(*(int *)arg);
- }
- return error;
-
- case PIO_KEYMAP: /* set keyboard translation table */
- case PIO_KEYMAPENT: /* set keyboard translation table entry */
- case PIO_DEADKEYMAP: /* set accent key translation table */
- state->ks_accents = 0;
- /* FALLTHROUGH */
- default:
- splx(s);
- return genkbd_commonioctl(kbd, cmd, arg);
- }
-
- splx(s);
- return 0;
-}
-
-/* lock the access to the keyboard */
-static int
-atkbd_lock(keyboard_t *kbd, int lock)
-{
- return kbdc_lock(((atkbd_state_t *)kbd->kb_data)->kbdc, lock);
-}
-
-/* clear the internal state of the keyboard */
-static void
-atkbd_clear_state(keyboard_t *kbd)
-{
- atkbd_state_t *state;
-
- state = (atkbd_state_t *)kbd->kb_data;
- state->ks_flags = 0;
- state->ks_polling = 0;
- state->ks_state &= LOCK_MASK; /* preserve locking key state */
- state->ks_accents = 0;
- state->ks_composed_char = 0;
-#if 0
- state->ks_prefix = 0; /* XXX */
-#endif
-}
-
-/* save the internal state */
-static int
-atkbd_get_state(keyboard_t *kbd, void *buf, size_t len)
-{
- if (len == 0)
- return sizeof(atkbd_state_t);
- if (len < sizeof(atkbd_state_t))
- return -1;
- bcopy(kbd->kb_data, buf, sizeof(atkbd_state_t));
- return 0;
-}
-
-/* set the internal state */
-static int
-atkbd_set_state(keyboard_t *kbd, void *buf, size_t len)
-{
- if (len < sizeof(atkbd_state_t))
- return ENOMEM;
- if (((atkbd_state_t *)kbd->kb_data)->kbdc
- != ((atkbd_state_t *)buf)->kbdc)
- return ENOMEM;
- bcopy(buf, kbd->kb_data, sizeof(atkbd_state_t));
- return 0;
-}
-
-static int
-atkbd_poll(keyboard_t *kbd, int on)
-{
- atkbd_state_t *state;
- int s;
-
- state = (atkbd_state_t *)kbd->kb_data;
- s = spltty();
- if (on)
- ++state->ks_polling;
- else
- --state->ks_polling;
- splx(s);
- return 0;
-}
-
-/* local functions */
-
-static int
-get_typematic(keyboard_t *kbd)
-{
-#ifdef __i386__
- /*
- * Only some systems allow us to retrieve the keyboard repeat
- * rate previously set via the BIOS...
- */
- struct vm86frame vmf;
- u_int32_t p;
-
- bzero(&vmf, sizeof(vmf));
- vmf.vmf_ax = 0xc000;
- vm86_intcall(0x15, &vmf);
- if ((vmf.vmf_eflags & PSL_C) || vmf.vmf_ah)
- return ENODEV;
- p = BIOS_PADDRTOVADDR(((u_int32_t)vmf.vmf_es << 4) + vmf.vmf_bx);
- if ((readb(p + 6) & 0x40) == 0) /* int 16, function 0x09 supported? */
- return ENODEV;
- vmf.vmf_ax = 0x0900;
- vm86_intcall(0x16, &vmf);
- if ((vmf.vmf_al & 0x08) == 0) /* int 16, function 0x0306 supported? */
- return ENODEV;
- vmf.vmf_ax = 0x0306;
- vm86_intcall(0x16, &vmf);
- kbd->kb_delay1 = typematic_delay(vmf.vmf_bh << 5);
- kbd->kb_delay2 = typematic_rate(vmf.vmf_bl);
- return 0;
-#else
- return ENODEV;
-#endif /* __i386__ */
-}
-
-static int
-setup_kbd_port(KBDC kbdc, int port, int intr)
-{
- if (!set_controller_command_byte(kbdc,
- KBD_KBD_CONTROL_BITS,
- ((port) ? KBD_ENABLE_KBD_PORT : KBD_DISABLE_KBD_PORT)
- | ((intr) ? KBD_ENABLE_KBD_INT : KBD_DISABLE_KBD_INT)))
- return 1;
- return 0;
-}
-
-static int
-get_kbd_echo(KBDC kbdc)
-{
- /* enable the keyboard port, but disable the keyboard intr. */
- if (setup_kbd_port(kbdc, TRUE, FALSE))
- /* CONTROLLER ERROR: there is very little we can do... */
- return ENXIO;
-
- /* see if something is present */
- write_kbd_command(kbdc, KBDC_ECHO);
- if (read_kbd_data(kbdc) != KBD_ECHO) {
- empty_both_buffers(kbdc, 10);
- test_controller(kbdc);
- test_kbd_port(kbdc);
- return ENXIO;
- }
-
- /* enable the keyboard port and intr. */
- if (setup_kbd_port(kbdc, TRUE, TRUE)) {
- /*
- * CONTROLLER ERROR
- * This is serious; the keyboard intr is left disabled!
- */
- return ENXIO;
- }
-
- return 0;
-}
-
-static int
-probe_keyboard(KBDC kbdc, int flags)
-{
- /*
- * Don't try to print anything in this function. The low-level
- * console may not have been initialized yet...
- */
- int err;
- int c;
- int m;
-
- if (!kbdc_lock(kbdc, TRUE)) {
- /* driver error? */
- return ENXIO;
- }
-
- /* temporarily block data transmission from the keyboard */
- write_controller_command(kbdc, KBDC_DISABLE_KBD_PORT);
-
- /* flush any noise in the buffer */
- empty_both_buffers(kbdc, 100);
-
- /* save the current keyboard controller command byte */
- m = kbdc_get_device_mask(kbdc) & ~KBD_KBD_CONTROL_BITS;
- c = get_controller_command_byte(kbdc);
- if (c == -1) {
- /* CONTROLLER ERROR */
- kbdc_set_device_mask(kbdc, m);
- kbdc_lock(kbdc, FALSE);
- return ENXIO;
- }
-
- /*
- * The keyboard may have been screwed up by the boot block.
- * We may just be able to recover from error by testing the controller
- * and the keyboard port. The controller command byte needs to be
- * saved before this recovery operation, as some controllers seem
- * to set the command byte to particular values.
- */
- test_controller(kbdc);
- test_kbd_port(kbdc);
-
- err = get_kbd_echo(kbdc);
-
- /*
- * Even if the keyboard doesn't seem to be present (err != 0),
- * we shall enable the keyboard port and interrupt so that
- * the driver will be operable when the keyboard is attached
- * to the system later. It is NOT recommended to hot-plug
- * the AT keyboard, but many people do so...
- */
- kbdc_set_device_mask(kbdc, m | KBD_KBD_CONTROL_BITS);
- setup_kbd_port(kbdc, TRUE, TRUE);
-#if 0
- if (err == 0) {
- kbdc_set_device_mask(kbdc, m | KBD_KBD_CONTROL_BITS);
- } else {
- /* try to restore the command byte as before */
- set_controller_command_byte(kbdc, 0xff, c);
- kbdc_set_device_mask(kbdc, m);
- }
-#endif
-
- kbdc_lock(kbdc, FALSE);
- return err;
-}
-
-static int
-init_keyboard(KBDC kbdc, int *type, int flags)
-{
- int codeset;
- int id;
- int c;
-
- if (!kbdc_lock(kbdc, TRUE)) {
- /* driver error? */
- return EIO;
- }
-
- /* temporarily block data transmission from the keyboard */
- write_controller_command(kbdc, KBDC_DISABLE_KBD_PORT);
-
- /* save the current controller command byte */
- empty_both_buffers(kbdc, 200);
- c = get_controller_command_byte(kbdc);
- if (c == -1) {
- /* CONTROLLER ERROR */
- kbdc_lock(kbdc, FALSE);
- printf("atkbd: unable to get the current command byte value.\n");
- return EIO;
- }
- if (bootverbose)
- printf("atkbd: the current kbd controller command byte %04x\n",
- c);
-#if 0
- /* override the keyboard lock switch */
- c |= KBD_OVERRIDE_KBD_LOCK;
-#endif
-
- /* enable the keyboard port, but disable the keyboard intr. */
- if (setup_kbd_port(kbdc, TRUE, FALSE)) {
- /* CONTROLLER ERROR: there is very little we can do... */
- printf("atkbd: unable to set the command byte.\n");
- kbdc_lock(kbdc, FALSE);
- return EIO;
- }
-
- /*
- * Check if we have an XT keyboard before we attempt to reset it.
- * The procedure assumes that the keyboard and the controller have
- * been set up properly by BIOS and have not been messed up
- * during the boot process.
- */
- codeset = -1;
- if (flags & KB_CONF_ALT_SCANCODESET)
- /* the user says there is a XT keyboard */
- codeset = 1;
-#ifdef KBD_DETECT_XT_KEYBOARD
- else if ((c & KBD_TRANSLATION) == 0) {
- /* SET_SCANCODE_SET is not always supported; ignore error */
- if (send_kbd_command_and_data(kbdc, KBDC_SET_SCANCODE_SET, 0)
- == KBD_ACK)
- codeset = read_kbd_data(kbdc);
- }
- if (bootverbose)
- printf("atkbd: scancode set %d\n", codeset);
-#endif /* KBD_DETECT_XT_KEYBOARD */
-
- *type = KB_OTHER;
- id = get_kbd_id(kbdc);
- switch(id) {
- case 0x41ab: /* 101/102/... Enhanced */
- case 0x83ab: /* ditto */
- case 0x54ab: /* SpaceSaver */
- case 0x84ab: /* ditto */
-#if 0
- case 0x90ab: /* 'G' */
- case 0x91ab: /* 'P' */
- case 0x92ab: /* 'A' */
-#endif
- *type = KB_101;
- break;
- case -1: /* AT 84 keyboard doesn't return ID */
- *type = KB_84;
- break;
- default:
- break;
- }
- if (bootverbose)
- printf("atkbd: keyboard ID 0x%x (%d)\n", id, *type);
-
- /* reset keyboard hardware */
- if (!(flags & KB_CONF_NO_RESET) && !reset_kbd(kbdc)) {
- /*
- * KEYBOARD ERROR
- * Keyboard reset may fail either because the keyboard
- * doen't exist, or because the keyboard doesn't pass
- * the self-test, or the keyboard controller on the
- * motherboard and the keyboard somehow fail to shake hands.
- * It is just possible, particularly in the last case,
- * that the keyboard controller may be left in a hung state.
- * test_controller() and test_kbd_port() appear to bring
- * the keyboard controller back (I don't know why and how,
- * though.)
- */
- empty_both_buffers(kbdc, 10);
- test_controller(kbdc);
- test_kbd_port(kbdc);
- /*
- * We could disable the keyboard port and interrupt... but,
- * the keyboard may still exist (see above).
- */
- set_controller_command_byte(kbdc, 0xff, c);
- kbdc_lock(kbdc, FALSE);
- if (bootverbose)
- printf("atkbd: failed to reset the keyboard.\n");
- return EIO;
- }
-
- /*
- * Allow us to set the XT_KEYBD flag so that keyboards
- * such as those on the IBM ThinkPad laptop computers can be used
- * with the standard console driver.
- */
- if (codeset == 1) {
- if (send_kbd_command_and_data(kbdc,
- KBDC_SET_SCANCODE_SET, codeset) == KBD_ACK) {
- /* XT kbd doesn't need scan code translation */
- c &= ~KBD_TRANSLATION;
- } else {
- /*
- * KEYBOARD ERROR
- * The XT kbd isn't usable unless the proper scan
- * code set is selected.
- */
- set_controller_command_byte(kbdc, 0xff, c);
- kbdc_lock(kbdc, FALSE);
- printf("atkbd: unable to set the XT keyboard mode.\n");
- return EIO;
- }
- }
-
-#ifdef __alpha__
- if (send_kbd_command_and_data(
- kbdc, KBDC_SET_SCANCODE_SET, 2) != KBD_ACK) {
- printf("atkbd: can't set translation.\n");
-
- }
- c |= KBD_TRANSLATION;
-#endif
-
- /* enable the keyboard port and intr. */
- if (!set_controller_command_byte(kbdc,
- KBD_KBD_CONTROL_BITS | KBD_TRANSLATION | KBD_OVERRIDE_KBD_LOCK,
- (c & (KBD_TRANSLATION | KBD_OVERRIDE_KBD_LOCK))
- | KBD_ENABLE_KBD_PORT | KBD_ENABLE_KBD_INT)) {
- /*
- * CONTROLLER ERROR
- * This is serious; we are left with the disabled
- * keyboard intr.
- */
- set_controller_command_byte(kbdc, 0xff, c);
- kbdc_lock(kbdc, FALSE);
- printf("atkbd: unable to enable the keyboard port and intr.\n");
- return EIO;
- }
-
- kbdc_lock(kbdc, FALSE);
- return 0;
-}
-
-static int
-write_kbd(KBDC kbdc, int command, int data)
-{
- int s;
-
- /* prevent the timeout routine from polling the keyboard */
- if (!kbdc_lock(kbdc, TRUE))
- return EBUSY;
-
- /* disable the keyboard and mouse interrupt */
- s = spltty();
-#if 0
- c = get_controller_command_byte(kbdc);
- if ((c == -1)
- || !set_controller_command_byte(kbdc,
- kbdc_get_device_mask(kbdc),
- KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT
- | KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
- /* CONTROLLER ERROR */
- kbdc_lock(kbdc, FALSE);
- splx(s);
- return EIO;
- }
- /*
- * Now that the keyboard controller is told not to generate
- * the keyboard and mouse interrupts, call `splx()' to allow
- * the other tty interrupts. The clock interrupt may also occur,
- * but the timeout routine (`scrn_timer()') will be blocked
- * by the lock flag set via `kbdc_lock()'
- */
- splx(s);
-#endif
-
- if (send_kbd_command_and_data(kbdc, command, data) != KBD_ACK)
- send_kbd_command(kbdc, KBDC_ENABLE_KBD);
-
-#if 0
- /* restore the interrupts */
- if (!set_controller_command_byte(kbdc,
- kbdc_get_device_mask(kbdc),
- c & (KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS))) {
- /* CONTROLLER ERROR */
- }
-#else
- splx(s);
-#endif
- kbdc_lock(kbdc, FALSE);
-
- return 0;
-}
-
-static int
-get_kbd_id(KBDC kbdc)
-{
- int id1, id2;
-
- empty_both_buffers(kbdc, 10);
- id1 = id2 = -1;
- if (send_kbd_command(kbdc, KBDC_SEND_DEV_ID) != KBD_ACK)
- return -1;
-
- DELAY(10000); /* 10 msec delay */
- id1 = read_kbd_data(kbdc);
- if (id1 != -1)
- id2 = read_kbd_data(kbdc);
-
- if ((id1 == -1) || (id2 == -1)) {
- empty_both_buffers(kbdc, 10);
- test_controller(kbdc);
- test_kbd_port(kbdc);
- return -1;
- }
- return ((id2 << 8) | id1);
-}
-
-static int delays[] = { 250, 500, 750, 1000 };
-static int rates[] = { 34, 38, 42, 46, 50, 55, 59, 63,
- 68, 76, 84, 92, 100, 110, 118, 126,
- 136, 152, 168, 184, 200, 220, 236, 252,
- 272, 304, 336, 368, 400, 440, 472, 504 };
-
-static int
-typematic_delay(int i)
-{
- return delays[(i >> 5) & 3];
-}
-
-static int
-typematic_rate(int i)
-{
- return rates[i & 0x1f];
-}
-
-static int
-typematic(int delay, int rate)
-{
- int value;
- int i;
-
- for (i = sizeof(delays)/sizeof(delays[0]) - 1; i > 0; --i) {
- if (delay >= delays[i])
- break;
- }
- value = i << 5;
- for (i = sizeof(rates)/sizeof(rates[0]) - 1; i > 0; --i) {
- if (rate >= rates[i])
- break;
- }
- value |= i;
- return value;
-}
diff --git a/sys/dev/atkbdc/atkbd_atkbdc.c b/sys/dev/atkbdc/atkbd_atkbdc.c
deleted file mode 100644
index 8b9053d65034..000000000000
--- a/sys/dev/atkbdc/atkbd_atkbdc.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*-
- * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must 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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (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$
- */
-
-#include "opt_kbd.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-#include <sys/kbio.h>
-#include <dev/kbd/kbdreg.h>
-#include <dev/kbd/atkbdreg.h>
-#include <dev/kbd/atkbdcreg.h>
-
-#include <isa/isareg.h>
-#include <isa/isavar.h>
-
-typedef struct {
- struct resource *intr;
- void *ih;
-} atkbd_softc_t;
-
-static devclass_t atkbd_devclass;
-
-static void atkbdidentify(driver_t *driver, device_t dev);
-static int atkbdprobe(device_t dev);
-static int atkbdattach(device_t dev);
-static int atkbdresume(device_t dev);
-static void atkbd_isa_intr(void *arg);
-
-static device_method_t atkbd_methods[] = {
- DEVMETHOD(device_identify, atkbdidentify),
- DEVMETHOD(device_probe, atkbdprobe),
- DEVMETHOD(device_attach, atkbdattach),
- DEVMETHOD(device_resume, atkbdresume),
- { 0, 0 }
-};
-
-static driver_t atkbd_driver = {
- ATKBD_DRIVER_NAME,
- atkbd_methods,
- sizeof(atkbd_softc_t),
-};
-
-static void
-atkbdidentify(driver_t *driver, device_t parent)
-{
-
- /* always add at least one child */
- BUS_ADD_CHILD(parent, KBDC_RID_KBD, driver->name, device_get_unit(parent));
-}
-
-static int
-atkbdprobe(device_t dev)
-{
- struct resource *res;
- u_long irq;
- int flags;
- int rid;
-
- device_set_desc(dev, "AT Keyboard");
-
- /* obtain parameters */
- flags = device_get_flags(dev);
-
- /* see if IRQ is available */
- rid = KBDC_RID_KBD;
- res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE | RF_ACTIVE);
- if (res == NULL) {
- if (bootverbose)
- device_printf(dev, "unable to allocate IRQ\n");
- return ENXIO;
- }
- irq = rman_get_start(res);
- bus_release_resource(dev, SYS_RES_IRQ, rid, res);
-
- /* probe the device */
- return atkbd_probe_unit(device_get_unit(dev),
- device_get_unit(device_get_parent(dev)),
- irq, flags);
-}
-
-static int
-atkbdattach(device_t dev)
-{
- atkbd_softc_t *sc;
- keyboard_t *kbd;
- u_long irq;
- int flags;
- int rid;
- int error;
-
- sc = device_get_softc(dev);
-
- rid = KBDC_RID_KBD;
- irq = bus_get_resource_start(dev, SYS_RES_IRQ, rid);
- flags = device_get_flags(dev);
- error = atkbd_attach_unit(device_get_unit(dev), &kbd,
- device_get_unit(device_get_parent(dev)),
- irq, flags);
- if (error)
- return error;
-
- /* declare our interrupt handler */
- sc->intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE | RF_ACTIVE);
- if (sc->intr == NULL)
- return ENXIO;
- error = bus_setup_intr(dev, sc->intr, INTR_TYPE_TTY, atkbd_isa_intr,
- kbd, &sc->ih);
- if (error)
- bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
-
- return error;
-}
-
-static int
-atkbdresume(device_t dev)
-{
- atkbd_softc_t *sc;
- keyboard_t *kbd;
- int args[2];
-
- sc = device_get_softc(dev);
- kbd = kbd_get_keyboard(kbd_find_keyboard(ATKBD_DRIVER_NAME,
- device_get_unit(dev)));
- if (kbd) {
- kbd->kb_flags &= ~KB_INITIALIZED;
- args[0] = device_get_unit(device_get_parent(dev));
- args[1] = rman_get_start(sc->intr);
- (*kbdsw[kbd->kb_index]->init)(device_get_unit(dev), &kbd,
- args, device_get_flags(dev));
- (*kbdsw[kbd->kb_index]->clear_state)(kbd);
- }
- return 0;
-}
-
-static void
-atkbd_isa_intr(void *arg)
-{
- keyboard_t *kbd;
-
- kbd = (keyboard_t *)arg;
- (*kbdsw[kbd->kb_index]->intr)(kbd, NULL);
-}
-
-DRIVER_MODULE(atkbd, atkbdc, atkbd_driver, atkbd_devclass, 0, 0);
diff --git a/sys/dev/atkbdc/atkbd_isa.c b/sys/dev/atkbdc/atkbd_isa.c
deleted file mode 100644
index 8b9053d65034..000000000000
--- a/sys/dev/atkbdc/atkbd_isa.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*-
- * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must 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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (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$
- */
-
-#include "opt_kbd.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-#include <sys/kbio.h>
-#include <dev/kbd/kbdreg.h>
-#include <dev/kbd/atkbdreg.h>
-#include <dev/kbd/atkbdcreg.h>
-
-#include <isa/isareg.h>
-#include <isa/isavar.h>
-
-typedef struct {
- struct resource *intr;
- void *ih;
-} atkbd_softc_t;
-
-static devclass_t atkbd_devclass;
-
-static void atkbdidentify(driver_t *driver, device_t dev);
-static int atkbdprobe(device_t dev);
-static int atkbdattach(device_t dev);
-static int atkbdresume(device_t dev);
-static void atkbd_isa_intr(void *arg);
-
-static device_method_t atkbd_methods[] = {
- DEVMETHOD(device_identify, atkbdidentify),
- DEVMETHOD(device_probe, atkbdprobe),
- DEVMETHOD(device_attach, atkbdattach),
- DEVMETHOD(device_resume, atkbdresume),
- { 0, 0 }
-};
-
-static driver_t atkbd_driver = {
- ATKBD_DRIVER_NAME,
- atkbd_methods,
- sizeof(atkbd_softc_t),
-};
-
-static void
-atkbdidentify(driver_t *driver, device_t parent)
-{
-
- /* always add at least one child */
- BUS_ADD_CHILD(parent, KBDC_RID_KBD, driver->name, device_get_unit(parent));
-}
-
-static int
-atkbdprobe(device_t dev)
-{
- struct resource *res;
- u_long irq;
- int flags;
- int rid;
-
- device_set_desc(dev, "AT Keyboard");
-
- /* obtain parameters */
- flags = device_get_flags(dev);
-
- /* see if IRQ is available */
- rid = KBDC_RID_KBD;
- res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE | RF_ACTIVE);
- if (res == NULL) {
- if (bootverbose)
- device_printf(dev, "unable to allocate IRQ\n");
- return ENXIO;
- }
- irq = rman_get_start(res);
- bus_release_resource(dev, SYS_RES_IRQ, rid, res);
-
- /* probe the device */
- return atkbd_probe_unit(device_get_unit(dev),
- device_get_unit(device_get_parent(dev)),
- irq, flags);
-}
-
-static int
-atkbdattach(device_t dev)
-{
- atkbd_softc_t *sc;
- keyboard_t *kbd;
- u_long irq;
- int flags;
- int rid;
- int error;
-
- sc = device_get_softc(dev);
-
- rid = KBDC_RID_KBD;
- irq = bus_get_resource_start(dev, SYS_RES_IRQ, rid);
- flags = device_get_flags(dev);
- error = atkbd_attach_unit(device_get_unit(dev), &kbd,
- device_get_unit(device_get_parent(dev)),
- irq, flags);
- if (error)
- return error;
-
- /* declare our interrupt handler */
- sc->intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE | RF_ACTIVE);
- if (sc->intr == NULL)
- return ENXIO;
- error = bus_setup_intr(dev, sc->intr, INTR_TYPE_TTY, atkbd_isa_intr,
- kbd, &sc->ih);
- if (error)
- bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
-
- return error;
-}
-
-static int
-atkbdresume(device_t dev)
-{
- atkbd_softc_t *sc;
- keyboard_t *kbd;
- int args[2];
-
- sc = device_get_softc(dev);
- kbd = kbd_get_keyboard(kbd_find_keyboard(ATKBD_DRIVER_NAME,
- device_get_unit(dev)));
- if (kbd) {
- kbd->kb_flags &= ~KB_INITIALIZED;
- args[0] = device_get_unit(device_get_parent(dev));
- args[1] = rman_get_start(sc->intr);
- (*kbdsw[kbd->kb_index]->init)(device_get_unit(dev), &kbd,
- args, device_get_flags(dev));
- (*kbdsw[kbd->kb_index]->clear_state)(kbd);
- }
- return 0;
-}
-
-static void
-atkbd_isa_intr(void *arg)
-{
- keyboard_t *kbd;
-
- kbd = (keyboard_t *)arg;
- (*kbdsw[kbd->kb_index]->intr)(kbd, NULL);
-}
-
-DRIVER_MODULE(atkbd, atkbdc, atkbd_driver, atkbd_devclass, 0, 0);
diff --git a/sys/dev/atkbdc/atkbdc.c b/sys/dev/atkbdc/atkbdc.c
deleted file mode 100644
index 9f048005b857..000000000000
--- a/sys/dev/atkbdc/atkbdc.c
+++ /dev/null
@@ -1,1041 +0,0 @@
-/*-
- * Copyright (c) 1996-1999
- * Kazutaka YOKOTA (yokota@zodiac.mech.utsunomiya-u.ac.jp)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- * from kbdio.c,v 1.13 1998/09/25 11:55:46 yokota Exp
- */
-
-#include "opt_kbd.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/malloc.h>
-#include <sys/syslog.h>
-#include <machine/bus_pio.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-
-#include <dev/kbd/atkbdcreg.h>
-
-#include <isa/isareg.h>
-
-/* constants */
-
-#define MAXKBDC 1 /* XXX */
-
-/* macros */
-
-#ifndef MAX
-#define MAX(x, y) ((x) > (y) ? (x) : (y))
-#endif
-
-#define kbdcp(p) ((atkbdc_softc_t *)(p))
-#define nextq(i) (((i) + 1) % KBDQ_BUFSIZE)
-#define availq(q) ((q)->head != (q)->tail)
-#if KBDIO_DEBUG >= 2
-#define emptyq(q) ((q)->tail = (q)->head = (q)->qcount = 0)
-#else
-#define emptyq(q) ((q)->tail = (q)->head = 0)
-#endif
-
-#define read_data(k) (bus_space_read_1((k)->iot, (k)->ioh0, 0))
-#define read_status(k) (bus_space_read_1((k)->iot, (k)->ioh1, 0))
-#define write_data(k, d) \
- (bus_space_write_1((k)->iot, (k)->ioh0, 0, (d)))
-#define write_command(k, d) \
- (bus_space_write_1((k)->iot, (k)->ioh1, 0, (d)))
-
-/* local variables */
-
-/*
- * We always need at least one copy of the kbdc_softc struct for the
- * low-level console. As the low-level console accesses the keyboard
- * controller before kbdc, and all other devices, is probed, we
- * statically allocate one entry. XXX
- */
-static atkbdc_softc_t default_kbdc;
-static atkbdc_softc_t *atkbdc_softc[MAXKBDC] = { &default_kbdc };
-
-static int verbose = KBDIO_DEBUG;
-
-/* function prototypes */
-
-static int atkbdc_setup(atkbdc_softc_t *sc, bus_space_tag_t tag,
- bus_space_handle_t h0, bus_space_handle_t h1);
-static int addq(kqueue *q, int c);
-static int removeq(kqueue *q);
-static int wait_while_controller_busy(atkbdc_softc_t *kbdc);
-static int wait_for_data(atkbdc_softc_t *kbdc);
-static int wait_for_kbd_data(atkbdc_softc_t *kbdc);
-static int wait_for_kbd_ack(atkbdc_softc_t *kbdc);
-static int wait_for_aux_data(atkbdc_softc_t *kbdc);
-static int wait_for_aux_ack(atkbdc_softc_t *kbdc);
-
-atkbdc_softc_t
-*atkbdc_get_softc(int unit)
-{
- atkbdc_softc_t *sc;
-
- if (unit >= sizeof(atkbdc_softc)/sizeof(atkbdc_softc[0]))
- return NULL;
- sc = atkbdc_softc[unit];
- if (sc == NULL) {
- sc = atkbdc_softc[unit]
- = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT | M_ZERO);
- if (sc == NULL)
- return NULL;
- }
- return sc;
-}
-
-int
-atkbdc_probe_unit(int unit, struct resource *port0, struct resource *port1)
-{
- if (rman_get_start(port0) <= 0)
- return ENXIO;
- if (rman_get_start(port1) <= 0)
- return ENXIO;
- return 0;
-}
-
-int
-atkbdc_attach_unit(int unit, atkbdc_softc_t *sc, struct resource *port0,
- struct resource *port1)
-{
- return atkbdc_setup(sc, rman_get_bustag(port0),
- rman_get_bushandle(port0),
- rman_get_bushandle(port1));
-}
-
-/* the backdoor to the keyboard controller! XXX */
-int
-atkbdc_configure(void)
-{
- bus_space_tag_t tag;
- bus_space_handle_t h0;
- bus_space_handle_t h1;
- int port0;
- int port1;
-
- port0 = IO_KBD;
- resource_int_value("atkbdc", 0, "port", &port0);
- port1 = IO_KBD + KBD_STATUS_PORT;
-#if 0
- resource_int_value("atkbdc", 0, "port", &port0);
-#endif
-
- /* XXX: tag should be passed from the caller */
-#if defined(__i386__)
- tag = I386_BUS_SPACE_IO;
-#elif defined(__amd64__)
- tag = AMD64_BUS_SPACE_IO;
-#elif defined(__alpha__)
- tag = busspace_isa_io;
-#elif defined(__ia64__)
- tag = IA64_BUS_SPACE_IO;
-#else
-#error "define tag!"
-#endif
-
-#if notyet
- bus_space_map(tag, port0, IO_KBDSIZE, 0, &h0);
- bus_space_map(tag, port1, IO_KBDSIZE, 0, &h1);
-#else
- h0 = (bus_space_handle_t)port0;
- h1 = (bus_space_handle_t)port1;
-#endif
- return atkbdc_setup(atkbdc_softc[0], tag, h0, h1);
-}
-
-static int
-atkbdc_setup(atkbdc_softc_t *sc, bus_space_tag_t tag, bus_space_handle_t h0,
- bus_space_handle_t h1)
-{
- if (sc->ioh0 == 0) { /* XXX */
- sc->command_byte = -1;
- sc->command_mask = 0;
- sc->lock = FALSE;
- sc->kbd.head = sc->kbd.tail = 0;
- sc->aux.head = sc->aux.tail = 0;
-#if KBDIO_DEBUG >= 2
- sc->kbd.call_count = 0;
- sc->kbd.qcount = sc->kbd.max_qcount = 0;
- sc->aux.call_count = 0;
- sc->aux.qcount = sc->aux.max_qcount = 0;
-#endif
- }
- sc->iot = tag;
- sc->ioh0 = h0;
- sc->ioh1 = h1;
- return 0;
-}
-
-/* open a keyboard controller */
-KBDC
-atkbdc_open(int unit)
-{
- if (unit <= 0)
- unit = 0;
- if (unit >= MAXKBDC)
- return NULL;
- if ((atkbdc_softc[unit]->port0 != NULL)
- || (atkbdc_softc[unit]->ioh0 != 0)) /* XXX */
- return (KBDC)atkbdc_softc[unit];
- return NULL;
-}
-
-/*
- * I/O access arbitration in `kbdio'
- *
- * The `kbdio' module uses a simplistic convention to arbitrate
- * I/O access to the controller/keyboard/mouse. The convention requires
- * close cooperation of the calling device driver.
- *
- * The device drivers which utilize the `kbdio' module are assumed to
- * have the following set of routines.
- * a. An interrupt handler (the bottom half of the driver).
- * b. Timeout routines which may briefly poll the keyboard controller.
- * c. Routines outside interrupt context (the top half of the driver).
- * They should follow the rules below:
- * 1. The interrupt handler may assume that it always has full access
- * to the controller/keyboard/mouse.
- * 2. The other routines must issue `spltty()' if they wish to
- * prevent the interrupt handler from accessing
- * the controller/keyboard/mouse.
- * 3. The timeout routines and the top half routines of the device driver
- * arbitrate I/O access by observing the lock flag in `kbdio'.
- * The flag is manipulated via `kbdc_lock()'; when one wants to
- * perform I/O, call `kbdc_lock(kbdc, TRUE)' and proceed only if
- * the call returns with TRUE. Otherwise the caller must back off.
- * Call `kbdc_lock(kbdc, FALSE)' when necessary I/O operaion
- * is finished. This mechanism does not prevent the interrupt
- * handler from being invoked at any time and carrying out I/O.
- * Therefore, `spltty()' must be strategically placed in the device
- * driver code. Also note that the timeout routine may interrupt
- * `kbdc_lock()' called by the top half of the driver, but this
- * interruption is OK so long as the timeout routine observes
- * rule 4 below.
- * 4. The interrupt and timeout routines should not extend I/O operation
- * across more than one interrupt or timeout; they must complete any
- * necessary I/O operation within one invocation of the routine.
- * This means that if the timeout routine acquires the lock flag,
- * it must reset the flag to FALSE before it returns.
- */
-
-/* set/reset polling lock */
-int
-kbdc_lock(KBDC p, int lock)
-{
- int prevlock;
-
- prevlock = kbdcp(p)->lock;
- kbdcp(p)->lock = lock;
-
- return (prevlock != lock);
-}
-
-/* check if any data is waiting to be processed */
-int
-kbdc_data_ready(KBDC p)
-{
- return (availq(&kbdcp(p)->kbd) || availq(&kbdcp(p)->aux)
- || (read_status(kbdcp(p)) & KBDS_ANY_BUFFER_FULL));
-}
-
-/* queuing functions */
-
-static int
-addq(kqueue *q, int c)
-{
- if (nextq(q->tail) != q->head) {
- q->q[q->tail] = c;
- q->tail = nextq(q->tail);
-#if KBDIO_DEBUG >= 2
- ++q->call_count;
- ++q->qcount;
- if (q->qcount > q->max_qcount)
- q->max_qcount = q->qcount;
-#endif
- return TRUE;
- }
- return FALSE;
-}
-
-static int
-removeq(kqueue *q)
-{
- int c;
-
- if (q->tail != q->head) {
- c = q->q[q->head];
- q->head = nextq(q->head);
-#if KBDIO_DEBUG >= 2
- --q->qcount;
-#endif
- return c;
- }
- return -1;
-}
-
-/*
- * device I/O routines
- */
-static int
-wait_while_controller_busy(struct atkbdc_softc *kbdc)
-{
- /* CPU will stay inside the loop for 100msec at most */
- int retry = 5000;
- int f;
-
- while ((f = read_status(kbdc)) & KBDS_INPUT_BUFFER_FULL) {
- if ((f & KBDS_BUFFER_FULL) == KBDS_KBD_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- addq(&kbdc->kbd, read_data(kbdc));
- } else if ((f & KBDS_BUFFER_FULL) == KBDS_AUX_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- addq(&kbdc->aux, read_data(kbdc));
- }
- DELAY(KBDC_DELAYTIME);
- if (--retry < 0)
- return FALSE;
- }
- return TRUE;
-}
-
-/*
- * wait for any data; whether it's from the controller,
- * the keyboard, or the aux device.
- */
-static int
-wait_for_data(struct atkbdc_softc *kbdc)
-{
- /* CPU will stay inside the loop for 200msec at most */
- int retry = 10000;
- int f;
-
- while ((f = read_status(kbdc) & KBDS_ANY_BUFFER_FULL) == 0) {
- DELAY(KBDC_DELAYTIME);
- if (--retry < 0)
- return 0;
- }
- DELAY(KBDD_DELAYTIME);
- return f;
-}
-
-/* wait for data from the keyboard */
-static int
-wait_for_kbd_data(struct atkbdc_softc *kbdc)
-{
- /* CPU will stay inside the loop for 200msec at most */
- int retry = 10000;
- int f;
-
- while ((f = read_status(kbdc) & KBDS_BUFFER_FULL)
- != KBDS_KBD_BUFFER_FULL) {
- if (f == KBDS_AUX_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- addq(&kbdc->aux, read_data(kbdc));
- }
- DELAY(KBDC_DELAYTIME);
- if (--retry < 0)
- return 0;
- }
- DELAY(KBDD_DELAYTIME);
- return f;
-}
-
-/*
- * wait for an ACK(FAh), RESEND(FEh), or RESET_FAIL(FCh) from the keyboard.
- * queue anything else.
- */
-static int
-wait_for_kbd_ack(struct atkbdc_softc *kbdc)
-{
- /* CPU will stay inside the loop for 200msec at most */
- int retry = 10000;
- int f;
- int b;
-
- while (retry-- > 0) {
- if ((f = read_status(kbdc)) & KBDS_ANY_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- b = read_data(kbdc);
- if ((f & KBDS_BUFFER_FULL) == KBDS_KBD_BUFFER_FULL) {
- if ((b == KBD_ACK) || (b == KBD_RESEND)
- || (b == KBD_RESET_FAIL))
- return b;
- addq(&kbdc->kbd, b);
- } else if ((f & KBDS_BUFFER_FULL) == KBDS_AUX_BUFFER_FULL) {
- addq(&kbdc->aux, b);
- }
- }
- DELAY(KBDC_DELAYTIME);
- }
- return -1;
-}
-
-/* wait for data from the aux device */
-static int
-wait_for_aux_data(struct atkbdc_softc *kbdc)
-{
- /* CPU will stay inside the loop for 200msec at most */
- int retry = 10000;
- int f;
-
- while ((f = read_status(kbdc) & KBDS_BUFFER_FULL)
- != KBDS_AUX_BUFFER_FULL) {
- if (f == KBDS_KBD_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- addq(&kbdc->kbd, read_data(kbdc));
- }
- DELAY(KBDC_DELAYTIME);
- if (--retry < 0)
- return 0;
- }
- DELAY(KBDD_DELAYTIME);
- return f;
-}
-
-/*
- * wait for an ACK(FAh), RESEND(FEh), or RESET_FAIL(FCh) from the aux device.
- * queue anything else.
- */
-static int
-wait_for_aux_ack(struct atkbdc_softc *kbdc)
-{
- /* CPU will stay inside the loop for 200msec at most */
- int retry = 10000;
- int f;
- int b;
-
- while (retry-- > 0) {
- if ((f = read_status(kbdc)) & KBDS_ANY_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- b = read_data(kbdc);
- if ((f & KBDS_BUFFER_FULL) == KBDS_AUX_BUFFER_FULL) {
- if ((b == PSM_ACK) || (b == PSM_RESEND)
- || (b == PSM_RESET_FAIL))
- return b;
- addq(&kbdc->aux, b);
- } else if ((f & KBDS_BUFFER_FULL) == KBDS_KBD_BUFFER_FULL) {
- addq(&kbdc->kbd, b);
- }
- }
- DELAY(KBDC_DELAYTIME);
- }
- return -1;
-}
-
-/* write a one byte command to the controller */
-int
-write_controller_command(KBDC p, int c)
-{
- if (!wait_while_controller_busy(kbdcp(p)))
- return FALSE;
- write_command(kbdcp(p), c);
- return TRUE;
-}
-
-/* write a one byte data to the controller */
-int
-write_controller_data(KBDC p, int c)
-{
- if (!wait_while_controller_busy(kbdcp(p)))
- return FALSE;
- write_data(kbdcp(p), c);
- return TRUE;
-}
-
-/* write a one byte keyboard command */
-int
-write_kbd_command(KBDC p, int c)
-{
- if (!wait_while_controller_busy(kbdcp(p)))
- return FALSE;
- write_data(kbdcp(p), c);
- return TRUE;
-}
-
-/* write a one byte auxiliary device command */
-int
-write_aux_command(KBDC p, int c)
-{
- if (!write_controller_command(p, KBDC_WRITE_TO_AUX))
- return FALSE;
- return write_controller_data(p, c);
-}
-
-/* send a command to the keyboard and wait for ACK */
-int
-send_kbd_command(KBDC p, int c)
-{
- int retry = KBD_MAXRETRY;
- int res = -1;
-
- while (retry-- > 0) {
- if (!write_kbd_command(p, c))
- continue;
- res = wait_for_kbd_ack(kbdcp(p));
- if (res == KBD_ACK)
- break;
- }
- return res;
-}
-
-/* send a command to the auxiliary device and wait for ACK */
-int
-send_aux_command(KBDC p, int c)
-{
- int retry = KBD_MAXRETRY;
- int res = -1;
-
- while (retry-- > 0) {
- if (!write_aux_command(p, c))
- continue;
- /*
- * FIXME: XXX
- * The aux device may have already sent one or two bytes of
- * status data, when a command is received. It will immediately
- * stop data transmission, thus, leaving an incomplete data
- * packet in our buffer. We have to discard any unprocessed
- * data in order to remove such packets. Well, we may remove
- * unprocessed, but necessary data byte as well...
- */
- emptyq(&kbdcp(p)->aux);
- res = wait_for_aux_ack(kbdcp(p));
- if (res == PSM_ACK)
- break;
- }
- return res;
-}
-
-/* send a command and a data to the keyboard, wait for ACKs */
-int
-send_kbd_command_and_data(KBDC p, int c, int d)
-{
- int retry;
- int res = -1;
-
- for (retry = KBD_MAXRETRY; retry > 0; --retry) {
- if (!write_kbd_command(p, c))
- continue;
- res = wait_for_kbd_ack(kbdcp(p));
- if (res == KBD_ACK)
- break;
- else if (res != KBD_RESEND)
- return res;
- }
- if (retry <= 0)
- return res;
-
- for (retry = KBD_MAXRETRY, res = -1; retry > 0; --retry) {
- if (!write_kbd_command(p, d))
- continue;
- res = wait_for_kbd_ack(kbdcp(p));
- if (res != KBD_RESEND)
- break;
- }
- return res;
-}
-
-/* send a command and a data to the auxiliary device, wait for ACKs */
-int
-send_aux_command_and_data(KBDC p, int c, int d)
-{
- int retry;
- int res = -1;
-
- for (retry = KBD_MAXRETRY; retry > 0; --retry) {
- if (!write_aux_command(p, c))
- continue;
- emptyq(&kbdcp(p)->aux);
- res = wait_for_aux_ack(kbdcp(p));
- if (res == PSM_ACK)
- break;
- else if (res != PSM_RESEND)
- return res;
- }
- if (retry <= 0)
- return res;
-
- for (retry = KBD_MAXRETRY, res = -1; retry > 0; --retry) {
- if (!write_aux_command(p, d))
- continue;
- res = wait_for_aux_ack(kbdcp(p));
- if (res != PSM_RESEND)
- break;
- }
- return res;
-}
-
-/*
- * read one byte from any source; whether from the controller,
- * the keyboard, or the aux device
- */
-int
-read_controller_data(KBDC p)
-{
- if (availq(&kbdcp(p)->kbd))
- return removeq(&kbdcp(p)->kbd);
- if (availq(&kbdcp(p)->aux))
- return removeq(&kbdcp(p)->aux);
- if (!wait_for_data(kbdcp(p)))
- return -1; /* timeout */
- return read_data(kbdcp(p));
-}
-
-#if KBDIO_DEBUG >= 2
-static int call = 0;
-#endif
-
-/* read one byte from the keyboard */
-int
-read_kbd_data(KBDC p)
-{
-#if KBDIO_DEBUG >= 2
- if (++call > 2000) {
- call = 0;
- log(LOG_DEBUG, "kbdc: kbd q: %d calls, max %d chars, "
- "aux q: %d calls, max %d chars\n",
- kbdcp(p)->kbd.call_count, kbdcp(p)->kbd.max_qcount,
- kbdcp(p)->aux.call_count, kbdcp(p)->aux.max_qcount);
- }
-#endif
-
- if (availq(&kbdcp(p)->kbd))
- return removeq(&kbdcp(p)->kbd);
- if (!wait_for_kbd_data(kbdcp(p)))
- return -1; /* timeout */
- return read_data(kbdcp(p));
-}
-
-/* read one byte from the keyboard, but return immediately if
- * no data is waiting
- */
-int
-read_kbd_data_no_wait(KBDC p)
-{
- int f;
-
-#if KBDIO_DEBUG >= 2
- if (++call > 2000) {
- call = 0;
- log(LOG_DEBUG, "kbdc: kbd q: %d calls, max %d chars, "
- "aux q: %d calls, max %d chars\n",
- kbdcp(p)->kbd.call_count, kbdcp(p)->kbd.max_qcount,
- kbdcp(p)->aux.call_count, kbdcp(p)->aux.max_qcount);
- }
-#endif
-
- if (availq(&kbdcp(p)->kbd))
- return removeq(&kbdcp(p)->kbd);
- f = read_status(kbdcp(p)) & KBDS_BUFFER_FULL;
- if (f == KBDS_AUX_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- addq(&kbdcp(p)->aux, read_data(kbdcp(p)));
- f = read_status(kbdcp(p)) & KBDS_BUFFER_FULL;
- }
- if (f == KBDS_KBD_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- return read_data(kbdcp(p));
- }
- return -1; /* no data */
-}
-
-/* read one byte from the aux device */
-int
-read_aux_data(KBDC p)
-{
- if (availq(&kbdcp(p)->aux))
- return removeq(&kbdcp(p)->aux);
- if (!wait_for_aux_data(kbdcp(p)))
- return -1; /* timeout */
- return read_data(kbdcp(p));
-}
-
-/* read one byte from the aux device, but return immediately if
- * no data is waiting
- */
-int
-read_aux_data_no_wait(KBDC p)
-{
- int f;
-
- if (availq(&kbdcp(p)->aux))
- return removeq(&kbdcp(p)->aux);
- f = read_status(kbdcp(p)) & KBDS_BUFFER_FULL;
- if (f == KBDS_KBD_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- addq(&kbdcp(p)->kbd, read_data(kbdcp(p)));
- f = read_status(kbdcp(p)) & KBDS_BUFFER_FULL;
- }
- if (f == KBDS_AUX_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- return read_data(kbdcp(p));
- }
- return -1; /* no data */
-}
-
-/* discard data from the keyboard */
-void
-empty_kbd_buffer(KBDC p, int wait)
-{
- int t;
- int b;
- int f;
-#if KBDIO_DEBUG >= 2
- int c1 = 0;
- int c2 = 0;
-#endif
- int delta = 2;
-
- for (t = wait; t > 0; ) {
- if ((f = read_status(kbdcp(p))) & KBDS_ANY_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- b = read_data(kbdcp(p));
- if ((f & KBDS_BUFFER_FULL) == KBDS_AUX_BUFFER_FULL) {
- addq(&kbdcp(p)->aux, b);
-#if KBDIO_DEBUG >= 2
- ++c2;
- } else {
- ++c1;
-#endif
- }
- t = wait;
- } else {
- t -= delta;
- }
- DELAY(delta*1000);
- }
-#if KBDIO_DEBUG >= 2
- if ((c1 > 0) || (c2 > 0))
- log(LOG_DEBUG, "kbdc: %d:%d char read (empty_kbd_buffer)\n", c1, c2);
-#endif
-
- emptyq(&kbdcp(p)->kbd);
-}
-
-/* discard data from the aux device */
-void
-empty_aux_buffer(KBDC p, int wait)
-{
- int t;
- int b;
- int f;
-#if KBDIO_DEBUG >= 2
- int c1 = 0;
- int c2 = 0;
-#endif
- int delta = 2;
-
- for (t = wait; t > 0; ) {
- if ((f = read_status(kbdcp(p))) & KBDS_ANY_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- b = read_data(kbdcp(p));
- if ((f & KBDS_BUFFER_FULL) == KBDS_KBD_BUFFER_FULL) {
- addq(&kbdcp(p)->kbd, b);
-#if KBDIO_DEBUG >= 2
- ++c1;
- } else {
- ++c2;
-#endif
- }
- t = wait;
- } else {
- t -= delta;
- }
- DELAY(delta*1000);
- }
-#if KBDIO_DEBUG >= 2
- if ((c1 > 0) || (c2 > 0))
- log(LOG_DEBUG, "kbdc: %d:%d char read (empty_aux_buffer)\n", c1, c2);
-#endif
-
- emptyq(&kbdcp(p)->aux);
-}
-
-/* discard any data from the keyboard or the aux device */
-void
-empty_both_buffers(KBDC p, int wait)
-{
- int t;
- int f;
-#if KBDIO_DEBUG >= 2
- int c1 = 0;
- int c2 = 0;
-#endif
- int delta = 2;
-
- for (t = wait; t > 0; ) {
- if ((f = read_status(kbdcp(p))) & KBDS_ANY_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- (void)read_data(kbdcp(p));
-#if KBDIO_DEBUG >= 2
- if ((f & KBDS_BUFFER_FULL) == KBDS_KBD_BUFFER_FULL)
- ++c1;
- else
- ++c2;
-#endif
- t = wait;
- } else {
- t -= delta;
- }
- DELAY(delta*1000);
- }
-#if KBDIO_DEBUG >= 2
- if ((c1 > 0) || (c2 > 0))
- log(LOG_DEBUG, "kbdc: %d:%d char read (empty_both_buffers)\n", c1, c2);
-#endif
-
- emptyq(&kbdcp(p)->kbd);
- emptyq(&kbdcp(p)->aux);
-}
-
-/* keyboard and mouse device control */
-
-/* NOTE: enable the keyboard port but disable the keyboard
- * interrupt before calling "reset_kbd()".
- */
-int
-reset_kbd(KBDC p)
-{
- int retry = KBD_MAXRETRY;
- int again = KBD_MAXWAIT;
- int c = KBD_RESEND; /* keep the compiler happy */
-
- while (retry-- > 0) {
- empty_both_buffers(p, 10);
- if (!write_kbd_command(p, KBDC_RESET_KBD))
- continue;
- emptyq(&kbdcp(p)->kbd);
- c = read_controller_data(p);
- if (verbose || bootverbose)
- log(LOG_DEBUG, "kbdc: RESET_KBD return code:%04x\n", c);
- if (c == KBD_ACK) /* keyboard has agreed to reset itself... */
- break;
- }
- if (retry < 0)
- return FALSE;
-
- while (again-- > 0) {
- /* wait awhile, well, in fact we must wait quite loooooooooooong */
- DELAY(KBD_RESETDELAY*1000);
- c = read_controller_data(p); /* RESET_DONE/RESET_FAIL */
- if (c != -1) /* wait again if the controller is not ready */
- break;
- }
- if (verbose || bootverbose)
- log(LOG_DEBUG, "kbdc: RESET_KBD status:%04x\n", c);
- if (c != KBD_RESET_DONE)
- return FALSE;
- return TRUE;
-}
-
-/* NOTE: enable the aux port but disable the aux interrupt
- * before calling `reset_aux_dev()'.
- */
-int
-reset_aux_dev(KBDC p)
-{
- int retry = KBD_MAXRETRY;
- int again = KBD_MAXWAIT;
- int c = PSM_RESEND; /* keep the compiler happy */
-
- while (retry-- > 0) {
- empty_both_buffers(p, 10);
- if (!write_aux_command(p, PSMC_RESET_DEV))
- continue;
- emptyq(&kbdcp(p)->aux);
- /* NOTE: Compaq Armada laptops require extra delay here. XXX */
- for (again = KBD_MAXWAIT; again > 0; --again) {
- DELAY(KBD_RESETDELAY*1000);
- c = read_aux_data_no_wait(p);
- if (c != -1)
- break;
- }
- if (verbose || bootverbose)
- log(LOG_DEBUG, "kbdc: RESET_AUX return code:%04x\n", c);
- if (c == PSM_ACK) /* aux dev is about to reset... */
- break;
- }
- if (retry < 0)
- return FALSE;
-
- for (again = KBD_MAXWAIT; again > 0; --again) {
- /* wait awhile, well, quite looooooooooooong */
- DELAY(KBD_RESETDELAY*1000);
- c = read_aux_data_no_wait(p); /* RESET_DONE/RESET_FAIL */
- if (c != -1) /* wait again if the controller is not ready */
- break;
- }
- if (verbose || bootverbose)
- log(LOG_DEBUG, "kbdc: RESET_AUX status:%04x\n", c);
- if (c != PSM_RESET_DONE) /* reset status */
- return FALSE;
-
- c = read_aux_data(p); /* device ID */
- if (verbose || bootverbose)
- log(LOG_DEBUG, "kbdc: RESET_AUX ID:%04x\n", c);
- /* NOTE: we could check the device ID now, but leave it later... */
- return TRUE;
-}
-
-/* controller diagnostics and setup */
-
-int
-test_controller(KBDC p)
-{
- int retry = KBD_MAXRETRY;
- int again = KBD_MAXWAIT;
- int c = KBD_DIAG_FAIL;
-
- while (retry-- > 0) {
- empty_both_buffers(p, 10);
- if (write_controller_command(p, KBDC_DIAGNOSE))
- break;
- }
- if (retry < 0)
- return FALSE;
-
- emptyq(&kbdcp(p)->kbd);
- while (again-- > 0) {
- /* wait awhile */
- DELAY(KBD_RESETDELAY*1000);
- c = read_controller_data(p); /* DIAG_DONE/DIAG_FAIL */
- if (c != -1) /* wait again if the controller is not ready */
- break;
- }
- if (verbose || bootverbose)
- log(LOG_DEBUG, "kbdc: DIAGNOSE status:%04x\n", c);
- return (c == KBD_DIAG_DONE);
-}
-
-int
-test_kbd_port(KBDC p)
-{
- int retry = KBD_MAXRETRY;
- int again = KBD_MAXWAIT;
- int c = -1;
-
- while (retry-- > 0) {
- empty_both_buffers(p, 10);
- if (write_controller_command(p, KBDC_TEST_KBD_PORT))
- break;
- }
- if (retry < 0)
- return FALSE;
-
- emptyq(&kbdcp(p)->kbd);
- while (again-- > 0) {
- c = read_controller_data(p);
- if (c != -1) /* try again if the controller is not ready */
- break;
- }
- if (verbose || bootverbose)
- log(LOG_DEBUG, "kbdc: TEST_KBD_PORT status:%04x\n", c);
- return c;
-}
-
-int
-test_aux_port(KBDC p)
-{
- int retry = KBD_MAXRETRY;
- int again = KBD_MAXWAIT;
- int c = -1;
-
- while (retry-- > 0) {
- empty_both_buffers(p, 10);
- if (write_controller_command(p, KBDC_TEST_AUX_PORT))
- break;
- }
- if (retry < 0)
- return FALSE;
-
- emptyq(&kbdcp(p)->kbd);
- while (again-- > 0) {
- c = read_controller_data(p);
- if (c != -1) /* try again if the controller is not ready */
- break;
- }
- if (verbose || bootverbose)
- log(LOG_DEBUG, "kbdc: TEST_AUX_PORT status:%04x\n", c);
- return c;
-}
-
-int
-kbdc_get_device_mask(KBDC p)
-{
- return kbdcp(p)->command_mask;
-}
-
-void
-kbdc_set_device_mask(KBDC p, int mask)
-{
- kbdcp(p)->command_mask =
- mask & (KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS);
-}
-
-int
-get_controller_command_byte(KBDC p)
-{
- if (kbdcp(p)->command_byte != -1)
- return kbdcp(p)->command_byte;
- if (!write_controller_command(p, KBDC_GET_COMMAND_BYTE))
- return -1;
- emptyq(&kbdcp(p)->kbd);
- kbdcp(p)->command_byte = read_controller_data(p);
- return kbdcp(p)->command_byte;
-}
-
-int
-set_controller_command_byte(KBDC p, int mask, int command)
-{
- if (get_controller_command_byte(p) == -1)
- return FALSE;
-
- command = (kbdcp(p)->command_byte & ~mask) | (command & mask);
- if (command & KBD_DISABLE_KBD_PORT) {
- if (!write_controller_command(p, KBDC_DISABLE_KBD_PORT))
- return FALSE;
- }
- if (!write_controller_command(p, KBDC_SET_COMMAND_BYTE))
- return FALSE;
- if (!write_controller_data(p, command))
- return FALSE;
- kbdcp(p)->command_byte = command;
-
- if (verbose)
- log(LOG_DEBUG, "kbdc: new command byte:%04x (set_controller...)\n",
- command);
-
- return TRUE;
-}
diff --git a/sys/dev/atkbdc/atkbdc_isa.c b/sys/dev/atkbdc/atkbdc_isa.c
deleted file mode 100644
index c3041534bc2d..000000000000
--- a/sys/dev/atkbdc/atkbdc_isa.c
+++ /dev/null
@@ -1,369 +0,0 @@
-/*-
- * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must 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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (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$
- */
-
-#include "opt_kbd.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/malloc.h>
-#include <machine/bus_pio.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-#include <dev/kbd/atkbdcreg.h>
-
-#include <isa/isareg.h>
-#include <isa/isavar.h>
-
-static MALLOC_DEFINE(M_ATKBDDEV, "atkbddev", "AT Keyboard device");
-
-/* children */
-typedef struct atkbdc_device {
- struct resource_list resources;
- int rid;
- u_int32_t vendorid;
- u_int32_t serial;
- u_int32_t logicalid;
- u_int32_t compatid;
-} atkbdc_device_t;
-
-/* kbdc */
-static devclass_t atkbdc_devclass;
-
-static int atkbdc_probe(device_t dev);
-static int atkbdc_attach(device_t dev);
-static device_t atkbdc_add_child(device_t bus, int order, char *name,
- int unit);
-static int atkbdc_print_child(device_t bus, device_t dev);
-static int atkbdc_read_ivar(device_t bus, device_t dev, int index,
- uintptr_t *val);
-static int atkbdc_write_ivar(device_t bus, device_t dev, int index,
- uintptr_t val);
-static struct resource_list
- *atkbdc_get_resource_list (device_t bus, device_t dev);
-static struct resource
- *atkbdc_alloc_resource(device_t bus, device_t dev, int type,
- int *rid, u_long start, u_long end,
- u_long count, u_int flags);
-static int atkbdc_release_resource(device_t bus, device_t dev, int type,
- int rid, struct resource *res);
-
-static device_method_t atkbdc_methods[] = {
- DEVMETHOD(device_probe, atkbdc_probe),
- DEVMETHOD(device_attach, atkbdc_attach),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- DEVMETHOD(bus_add_child, atkbdc_add_child),
- DEVMETHOD(bus_print_child, atkbdc_print_child),
- DEVMETHOD(bus_read_ivar, atkbdc_read_ivar),
- DEVMETHOD(bus_write_ivar, atkbdc_write_ivar),
- DEVMETHOD(bus_get_resource_list,atkbdc_get_resource_list),
- DEVMETHOD(bus_alloc_resource, atkbdc_alloc_resource),
- DEVMETHOD(bus_release_resource, atkbdc_release_resource),
- DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
- DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
- DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
- DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
- DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource),
- DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
- DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
-
- { 0, 0 }
-};
-
-static driver_t atkbdc_driver = {
- ATKBDC_DRIVER_NAME,
- atkbdc_methods,
- sizeof(atkbdc_softc_t *),
-};
-
-static struct isa_pnp_id atkbdc_ids[] = {
- { 0x0303d041, "Keyboard controller (i8042)" }, /* PNP0303 */
- { 0 }
-};
-
-static int
-atkbdc_probe(device_t dev)
-{
- struct resource *port0;
- struct resource *port1;
- u_long start;
- u_long count;
- int error;
- int rid;
-
- /* check PnP IDs */
- if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO)
- return ENXIO;
-
- device_set_desc(dev, "Keyboard controller (i8042)");
-
- /*
- * Adjust I/O port resources.
- * The AT keyboard controller uses two ports (a command/data port
- * 0x60 and a status port 0x64), which may be given to us in
- * one resource (0x60 through 0x64) or as two separate resources
- * (0x60 and 0x64). Furthermore, /boot/device.hints may contain
- * just one port, 0x60. We shall adjust resource settings
- * so that these two ports are available as two separate resources.
- */
- device_quiet(dev);
- rid = 0;
- if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0)
- return ENXIO;
- if (count > 1) /* adjust the count */
- bus_set_resource(dev, SYS_RES_IOPORT, rid, start, 1);
- port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
- RF_ACTIVE);
- if (port0 == NULL)
- return ENXIO;
- rid = 1;
- if (bus_get_resource(dev, SYS_RES_IOPORT, rid, NULL, NULL) != 0)
- bus_set_resource(dev, SYS_RES_IOPORT, 1,
- start + KBD_STATUS_PORT, 1);
- port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
- RF_ACTIVE);
- if (port1 == NULL) {
- bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
- return ENXIO;
- }
- device_verbose(dev);
-
- error = atkbdc_probe_unit(device_get_unit(dev), port0, port1);
- if (error == 0)
- bus_generic_probe(dev);
-
- bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
- bus_release_resource(dev, SYS_RES_IOPORT, 1, port1);
-
- return error;
-}
-
-static int
-atkbdc_attach(device_t dev)
-{
- atkbdc_softc_t *sc;
- int unit;
- int error;
- int rid;
-
- unit = device_get_unit(dev);
- sc = *(atkbdc_softc_t **)device_get_softc(dev);
- if (sc == NULL) {
- /*
- * We have to maintain two copies of the kbdc_softc struct,
- * as the low-level console needs to have access to the
- * keyboard controller before kbdc is probed and attached.
- * kbdc_soft[] contains the default entry for that purpose.
- * See atkbdc.c. XXX
- */
- sc = atkbdc_get_softc(unit);
- if (sc == NULL)
- return ENOMEM;
- }
-
- rid = 0;
- sc->port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
- RF_ACTIVE);
- if (sc->port0 == NULL)
- return ENXIO;
- rid = 1;
- sc->port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
- RF_ACTIVE);
- if (sc->port1 == NULL) {
- bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
- return ENXIO;
- }
-
- error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1);
- if (error) {
- bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
- bus_release_resource(dev, SYS_RES_IOPORT, 1, sc->port1);
- return error;
- }
- *(atkbdc_softc_t **)device_get_softc(dev) = sc;
-
- bus_generic_attach(dev);
-
- return 0;
-}
-
-static device_t
-atkbdc_add_child(device_t bus, int order, char *name, int unit)
-{
- atkbdc_device_t *ivar;
- device_t child;
- int t;
-
- ivar = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV,
- M_NOWAIT | M_ZERO);
- if (!ivar)
- return NULL;
-
- child = device_add_child_ordered(bus, order, name, unit);
- if (child == NULL) {
- free(ivar, M_ATKBDDEV);
- return child;
- }
-
- resource_list_init(&ivar->resources);
- ivar->rid = order;
-
- /*
- * If the device is not created by the PnP BIOS or ACPI,
- * refer to device hints for IRQ.
- */
- if (ISA_PNP_PROBE(device_get_parent(bus), bus, atkbdc_ids) != 0) {
- if (resource_int_value(name, unit, "irq", &t) != 0)
- t = -1;
- } else {
- t = bus_get_resource_start(bus, SYS_RES_IRQ, ivar->rid);
- }
- if (t > 0)
- resource_list_add(&ivar->resources, SYS_RES_IRQ, ivar->rid,
- t, t, 1);
-
- if (resource_int_value(name, unit, "flags", &t) == 0)
- device_set_flags(child, t);
- if (resource_int_value(name, unit, "disabled", &t) == 0 && t != 0)
- device_disable(child);
-
- device_set_ivars(child, ivar);
-
- return child;
-}
-
-static int
-atkbdc_print_child(device_t bus, device_t dev)
-{
- atkbdc_device_t *kbdcdev;
- u_long irq;
- int flags;
- int retval = 0;
-
- kbdcdev = (atkbdc_device_t *)device_get_ivars(dev);
-
- retval += bus_print_child_header(bus, dev);
- flags = device_get_flags(dev);
- if (flags != 0)
- retval += printf(" flags 0x%x", flags);
- irq = bus_get_resource_start(dev, SYS_RES_IRQ, kbdcdev->rid);
- if (irq != 0)
- retval += printf(" irq %ld", irq);
- retval += bus_print_child_footer(bus, dev);
-
- return (retval);
-}
-
-static int
-atkbdc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
-{
- atkbdc_device_t *ivar;
-
- ivar = (atkbdc_device_t *)device_get_ivars(dev);
- switch (index) {
- case KBDC_IVAR_VENDORID:
- *val = (u_long)ivar->vendorid;
- break;
- case KBDC_IVAR_SERIAL:
- *val = (u_long)ivar->serial;
- break;
- case KBDC_IVAR_LOGICALID:
- *val = (u_long)ivar->logicalid;
- break;
- case KBDC_IVAR_COMPATID:
- *val = (u_long)ivar->compatid;
- break;
- default:
- return ENOENT;
- }
- return 0;
-}
-
-static int
-atkbdc_write_ivar(device_t bus, device_t dev, int index, uintptr_t val)
-{
- atkbdc_device_t *ivar;
-
- ivar = (atkbdc_device_t *)device_get_ivars(dev);
- switch (index) {
- case KBDC_IVAR_VENDORID:
- ivar->vendorid = (u_int32_t)val;
- break;
- case KBDC_IVAR_SERIAL:
- ivar->serial = (u_int32_t)val;
- break;
- case KBDC_IVAR_LOGICALID:
- ivar->logicalid = (u_int32_t)val;
- break;
- case KBDC_IVAR_COMPATID:
- ivar->compatid = (u_int32_t)val;
- break;
- default:
- return ENOENT;
- }
- return 0;
-}
-
-static struct resource_list
-*atkbdc_get_resource_list (device_t bus, device_t dev)
-{
- atkbdc_device_t *ivar;
-
- ivar = (atkbdc_device_t *)device_get_ivars(dev);
- return &ivar->resources;
-}
-
-static struct resource
-*atkbdc_alloc_resource(device_t bus, device_t dev, int type, int *rid,
- u_long start, u_long end, u_long count, u_int flags)
-{
- atkbdc_device_t *ivar;
-
- ivar = (atkbdc_device_t *)device_get_ivars(dev);
- return resource_list_alloc(&ivar->resources, bus, dev, type, rid,
- start, end, count, flags);
-}
-
-static int
-atkbdc_release_resource(device_t bus, device_t dev, int type, int rid,
- struct resource *res)
-{
- atkbdc_device_t *ivar;
-
- ivar = (atkbdc_device_t *)device_get_ivars(dev);
- return resource_list_release(&ivar->resources, bus, dev, type, rid,
- res);
-}
-
-DRIVER_MODULE(atkbdc, isa, atkbdc_driver, atkbdc_devclass, 0, 0);
-DRIVER_MODULE(atkbdc, acpi, atkbdc_driver, atkbdc_devclass, 0, 0);
diff --git a/sys/dev/atkbdc/atkbdc_subr.c b/sys/dev/atkbdc/atkbdc_subr.c
deleted file mode 100644
index c3041534bc2d..000000000000
--- a/sys/dev/atkbdc/atkbdc_subr.c
+++ /dev/null
@@ -1,369 +0,0 @@
-/*-
- * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must 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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (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$
- */
-
-#include "opt_kbd.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/malloc.h>
-#include <machine/bus_pio.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-#include <dev/kbd/atkbdcreg.h>
-
-#include <isa/isareg.h>
-#include <isa/isavar.h>
-
-static MALLOC_DEFINE(M_ATKBDDEV, "atkbddev", "AT Keyboard device");
-
-/* children */
-typedef struct atkbdc_device {
- struct resource_list resources;
- int rid;
- u_int32_t vendorid;
- u_int32_t serial;
- u_int32_t logicalid;
- u_int32_t compatid;
-} atkbdc_device_t;
-
-/* kbdc */
-static devclass_t atkbdc_devclass;
-
-static int atkbdc_probe(device_t dev);
-static int atkbdc_attach(device_t dev);
-static device_t atkbdc_add_child(device_t bus, int order, char *name,
- int unit);
-static int atkbdc_print_child(device_t bus, device_t dev);
-static int atkbdc_read_ivar(device_t bus, device_t dev, int index,
- uintptr_t *val);
-static int atkbdc_write_ivar(device_t bus, device_t dev, int index,
- uintptr_t val);
-static struct resource_list
- *atkbdc_get_resource_list (device_t bus, device_t dev);
-static struct resource
- *atkbdc_alloc_resource(device_t bus, device_t dev, int type,
- int *rid, u_long start, u_long end,
- u_long count, u_int flags);
-static int atkbdc_release_resource(device_t bus, device_t dev, int type,
- int rid, struct resource *res);
-
-static device_method_t atkbdc_methods[] = {
- DEVMETHOD(device_probe, atkbdc_probe),
- DEVMETHOD(device_attach, atkbdc_attach),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- DEVMETHOD(bus_add_child, atkbdc_add_child),
- DEVMETHOD(bus_print_child, atkbdc_print_child),
- DEVMETHOD(bus_read_ivar, atkbdc_read_ivar),
- DEVMETHOD(bus_write_ivar, atkbdc_write_ivar),
- DEVMETHOD(bus_get_resource_list,atkbdc_get_resource_list),
- DEVMETHOD(bus_alloc_resource, atkbdc_alloc_resource),
- DEVMETHOD(bus_release_resource, atkbdc_release_resource),
- DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
- DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
- DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
- DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
- DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource),
- DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
- DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
-
- { 0, 0 }
-};
-
-static driver_t atkbdc_driver = {
- ATKBDC_DRIVER_NAME,
- atkbdc_methods,
- sizeof(atkbdc_softc_t *),
-};
-
-static struct isa_pnp_id atkbdc_ids[] = {
- { 0x0303d041, "Keyboard controller (i8042)" }, /* PNP0303 */
- { 0 }
-};
-
-static int
-atkbdc_probe(device_t dev)
-{
- struct resource *port0;
- struct resource *port1;
- u_long start;
- u_long count;
- int error;
- int rid;
-
- /* check PnP IDs */
- if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO)
- return ENXIO;
-
- device_set_desc(dev, "Keyboard controller (i8042)");
-
- /*
- * Adjust I/O port resources.
- * The AT keyboard controller uses two ports (a command/data port
- * 0x60 and a status port 0x64), which may be given to us in
- * one resource (0x60 through 0x64) or as two separate resources
- * (0x60 and 0x64). Furthermore, /boot/device.hints may contain
- * just one port, 0x60. We shall adjust resource settings
- * so that these two ports are available as two separate resources.
- */
- device_quiet(dev);
- rid = 0;
- if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0)
- return ENXIO;
- if (count > 1) /* adjust the count */
- bus_set_resource(dev, SYS_RES_IOPORT, rid, start, 1);
- port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
- RF_ACTIVE);
- if (port0 == NULL)
- return ENXIO;
- rid = 1;
- if (bus_get_resource(dev, SYS_RES_IOPORT, rid, NULL, NULL) != 0)
- bus_set_resource(dev, SYS_RES_IOPORT, 1,
- start + KBD_STATUS_PORT, 1);
- port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
- RF_ACTIVE);
- if (port1 == NULL) {
- bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
- return ENXIO;
- }
- device_verbose(dev);
-
- error = atkbdc_probe_unit(device_get_unit(dev), port0, port1);
- if (error == 0)
- bus_generic_probe(dev);
-
- bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
- bus_release_resource(dev, SYS_RES_IOPORT, 1, port1);
-
- return error;
-}
-
-static int
-atkbdc_attach(device_t dev)
-{
- atkbdc_softc_t *sc;
- int unit;
- int error;
- int rid;
-
- unit = device_get_unit(dev);
- sc = *(atkbdc_softc_t **)device_get_softc(dev);
- if (sc == NULL) {
- /*
- * We have to maintain two copies of the kbdc_softc struct,
- * as the low-level console needs to have access to the
- * keyboard controller before kbdc is probed and attached.
- * kbdc_soft[] contains the default entry for that purpose.
- * See atkbdc.c. XXX
- */
- sc = atkbdc_get_softc(unit);
- if (sc == NULL)
- return ENOMEM;
- }
-
- rid = 0;
- sc->port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
- RF_ACTIVE);
- if (sc->port0 == NULL)
- return ENXIO;
- rid = 1;
- sc->port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
- RF_ACTIVE);
- if (sc->port1 == NULL) {
- bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
- return ENXIO;
- }
-
- error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1);
- if (error) {
- bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
- bus_release_resource(dev, SYS_RES_IOPORT, 1, sc->port1);
- return error;
- }
- *(atkbdc_softc_t **)device_get_softc(dev) = sc;
-
- bus_generic_attach(dev);
-
- return 0;
-}
-
-static device_t
-atkbdc_add_child(device_t bus, int order, char *name, int unit)
-{
- atkbdc_device_t *ivar;
- device_t child;
- int t;
-
- ivar = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV,
- M_NOWAIT | M_ZERO);
- if (!ivar)
- return NULL;
-
- child = device_add_child_ordered(bus, order, name, unit);
- if (child == NULL) {
- free(ivar, M_ATKBDDEV);
- return child;
- }
-
- resource_list_init(&ivar->resources);
- ivar->rid = order;
-
- /*
- * If the device is not created by the PnP BIOS or ACPI,
- * refer to device hints for IRQ.
- */
- if (ISA_PNP_PROBE(device_get_parent(bus), bus, atkbdc_ids) != 0) {
- if (resource_int_value(name, unit, "irq", &t) != 0)
- t = -1;
- } else {
- t = bus_get_resource_start(bus, SYS_RES_IRQ, ivar->rid);
- }
- if (t > 0)
- resource_list_add(&ivar->resources, SYS_RES_IRQ, ivar->rid,
- t, t, 1);
-
- if (resource_int_value(name, unit, "flags", &t) == 0)
- device_set_flags(child, t);
- if (resource_int_value(name, unit, "disabled", &t) == 0 && t != 0)
- device_disable(child);
-
- device_set_ivars(child, ivar);
-
- return child;
-}
-
-static int
-atkbdc_print_child(device_t bus, device_t dev)
-{
- atkbdc_device_t *kbdcdev;
- u_long irq;
- int flags;
- int retval = 0;
-
- kbdcdev = (atkbdc_device_t *)device_get_ivars(dev);
-
- retval += bus_print_child_header(bus, dev);
- flags = device_get_flags(dev);
- if (flags != 0)
- retval += printf(" flags 0x%x", flags);
- irq = bus_get_resource_start(dev, SYS_RES_IRQ, kbdcdev->rid);
- if (irq != 0)
- retval += printf(" irq %ld", irq);
- retval += bus_print_child_footer(bus, dev);
-
- return (retval);
-}
-
-static int
-atkbdc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
-{
- atkbdc_device_t *ivar;
-
- ivar = (atkbdc_device_t *)device_get_ivars(dev);
- switch (index) {
- case KBDC_IVAR_VENDORID:
- *val = (u_long)ivar->vendorid;
- break;
- case KBDC_IVAR_SERIAL:
- *val = (u_long)ivar->serial;
- break;
- case KBDC_IVAR_LOGICALID:
- *val = (u_long)ivar->logicalid;
- break;
- case KBDC_IVAR_COMPATID:
- *val = (u_long)ivar->compatid;
- break;
- default:
- return ENOENT;
- }
- return 0;
-}
-
-static int
-atkbdc_write_ivar(device_t bus, device_t dev, int index, uintptr_t val)
-{
- atkbdc_device_t *ivar;
-
- ivar = (atkbdc_device_t *)device_get_ivars(dev);
- switch (index) {
- case KBDC_IVAR_VENDORID:
- ivar->vendorid = (u_int32_t)val;
- break;
- case KBDC_IVAR_SERIAL:
- ivar->serial = (u_int32_t)val;
- break;
- case KBDC_IVAR_LOGICALID:
- ivar->logicalid = (u_int32_t)val;
- break;
- case KBDC_IVAR_COMPATID:
- ivar->compatid = (u_int32_t)val;
- break;
- default:
- return ENOENT;
- }
- return 0;
-}
-
-static struct resource_list
-*atkbdc_get_resource_list (device_t bus, device_t dev)
-{
- atkbdc_device_t *ivar;
-
- ivar = (atkbdc_device_t *)device_get_ivars(dev);
- return &ivar->resources;
-}
-
-static struct resource
-*atkbdc_alloc_resource(device_t bus, device_t dev, int type, int *rid,
- u_long start, u_long end, u_long count, u_int flags)
-{
- atkbdc_device_t *ivar;
-
- ivar = (atkbdc_device_t *)device_get_ivars(dev);
- return resource_list_alloc(&ivar->resources, bus, dev, type, rid,
- start, end, count, flags);
-}
-
-static int
-atkbdc_release_resource(device_t bus, device_t dev, int type, int rid,
- struct resource *res)
-{
- atkbdc_device_t *ivar;
-
- ivar = (atkbdc_device_t *)device_get_ivars(dev);
- return resource_list_release(&ivar->resources, bus, dev, type, rid,
- res);
-}
-
-DRIVER_MODULE(atkbdc, isa, atkbdc_driver, atkbdc_devclass, 0, 0);
-DRIVER_MODULE(atkbdc, acpi, atkbdc_driver, atkbdc_devclass, 0, 0);
diff --git a/sys/dev/atkbdc/atkbdcreg.h b/sys/dev/atkbdc/atkbdcreg.h
deleted file mode 100644
index f2ec8442f538..000000000000
--- a/sys/dev/atkbdc/atkbdcreg.h
+++ /dev/null
@@ -1,263 +0,0 @@
-/*-
- * Copyright (c) 1996-1999
- * Kazutaka YOKOTA (yokota@zodiac.mech.utsunomiya-u.ac.jp)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- * from kbdio.h,v 1.8 1998/09/25 11:55:46 yokota Exp
- */
-
-#ifndef _DEV_KBD_ATKBDCREG_H_
-#define _DEV_KBD_ATKBDCREG_H_
-
-#include "opt_kbd.h" /* Structures depend on the value if KBDIO_DEBUG */
-
-/* constants */
-
-/* I/O ports */
-#define KBD_STATUS_PORT 4 /* status port, read */
-#define KBD_COMMAND_PORT 4 /* controller command port, write */
-#define KBD_DATA_PORT 0 /* data port, read/write
- * also used as keyboard command
- * and mouse command port
- */
-
-/* controller commands (sent to KBD_COMMAND_PORT) */
-#define KBDC_SET_COMMAND_BYTE 0x0060
-#define KBDC_GET_COMMAND_BYTE 0x0020
-#define KBDC_WRITE_TO_AUX 0x00d4
-#define KBDC_DISABLE_AUX_PORT 0x00a7
-#define KBDC_ENABLE_AUX_PORT 0x00a8
-#define KBDC_TEST_AUX_PORT 0x00a9
-#define KBDC_DIAGNOSE 0x00aa
-#define KBDC_TEST_KBD_PORT 0x00ab
-#define KBDC_DISABLE_KBD_PORT 0x00ad
-#define KBDC_ENABLE_KBD_PORT 0x00ae
-
-/* controller command byte (set by KBDC_SET_COMMAND_BYTE) */
-#define KBD_TRANSLATION 0x0040
-#define KBD_RESERVED_BITS 0x0004
-#define KBD_OVERRIDE_KBD_LOCK 0x0008
-#define KBD_ENABLE_KBD_PORT 0x0000
-#define KBD_DISABLE_KBD_PORT 0x0010
-#define KBD_ENABLE_AUX_PORT 0x0000
-#define KBD_DISABLE_AUX_PORT 0x0020
-#define KBD_ENABLE_AUX_INT 0x0002
-#define KBD_DISABLE_AUX_INT 0x0000
-#define KBD_ENABLE_KBD_INT 0x0001
-#define KBD_DISABLE_KBD_INT 0x0000
-#define KBD_KBD_CONTROL_BITS (KBD_DISABLE_KBD_PORT | KBD_ENABLE_KBD_INT)
-#define KBD_AUX_CONTROL_BITS (KBD_DISABLE_AUX_PORT | KBD_ENABLE_AUX_INT)
-
-/* keyboard device commands (sent to KBD_DATA_PORT) */
-#define KBDC_RESET_KBD 0x00ff
-#define KBDC_ENABLE_KBD 0x00f4
-#define KBDC_DISABLE_KBD 0x00f5
-#define KBDC_SET_DEFAULTS 0x00f6
-#define KBDC_SEND_DEV_ID 0x00f2
-#define KBDC_SET_LEDS 0x00ed
-#define KBDC_ECHO 0x00ee
-#define KBDC_SET_SCANCODE_SET 0x00f0
-#define KBDC_SET_TYPEMATIC 0x00f3
-
-/* aux device commands (sent to KBD_DATA_PORT) */
-#define PSMC_RESET_DEV 0x00ff
-#define PSMC_ENABLE_DEV 0x00f4
-#define PSMC_DISABLE_DEV 0x00f5
-#define PSMC_SET_DEFAULTS 0x00f6
-#define PSMC_SEND_DEV_ID 0x00f2
-#define PSMC_SEND_DEV_STATUS 0x00e9
-#define PSMC_SEND_DEV_DATA 0x00eb
-#define PSMC_SET_SCALING11 0x00e6
-#define PSMC_SET_SCALING21 0x00e7
-#define PSMC_SET_RESOLUTION 0x00e8
-#define PSMC_SET_STREAM_MODE 0x00ea
-#define PSMC_SET_REMOTE_MODE 0x00f0
-#define PSMC_SET_SAMPLING_RATE 0x00f3
-
-/* PSMC_SET_RESOLUTION argument */
-#define PSMD_RES_LOW 0 /* typically 25ppi */
-#define PSMD_RES_MEDIUM_LOW 1 /* typically 50ppi */
-#define PSMD_RES_MEDIUM_HIGH 2 /* typically 100ppi (default) */
-#define PSMD_RES_HIGH 3 /* typically 200ppi */
-#define PSMD_MAX_RESOLUTION PSMD_RES_HIGH
-
-/* PSMC_SET_SAMPLING_RATE */
-#define PSMD_MAX_RATE 255 /* FIXME: not sure if it's possible */
-
-/* status bits (KBD_STATUS_PORT) */
-#define KBDS_BUFFER_FULL 0x0021
-#define KBDS_ANY_BUFFER_FULL 0x0001
-#define KBDS_KBD_BUFFER_FULL 0x0001
-#define KBDS_AUX_BUFFER_FULL 0x0021
-#define KBDS_INPUT_BUFFER_FULL 0x0002
-
-/* return code */
-#define KBD_ACK 0x00fa
-#define KBD_RESEND 0x00fe
-#define KBD_RESET_DONE 0x00aa
-#define KBD_RESET_FAIL 0x00fc
-#define KBD_DIAG_DONE 0x0055
-#define KBD_DIAG_FAIL 0x00fd
-#define KBD_ECHO 0x00ee
-
-#define PSM_ACK 0x00fa
-#define PSM_RESEND 0x00fe
-#define PSM_RESET_DONE 0x00aa
-#define PSM_RESET_FAIL 0x00fc
-
-/* aux device ID */
-#define PSM_MOUSE_ID 0
-#define PSM_BALLPOINT_ID 2
-#define PSM_INTELLI_ID 3
-#define PSM_EXPLORER_ID 4
-#define PSM_4DMOUSE_ID 6
-#define PSM_4DPLUS_ID 8
-
-#ifdef _KERNEL
-
-#define ATKBDC_DRIVER_NAME "atkbdc"
-
-/*
- * driver specific options: the following options may be set by
- * `options' statements in the kernel configuration file.
- */
-
-/* retry count */
-#ifndef KBD_MAXRETRY
-#define KBD_MAXRETRY 3
-#endif
-
-/* timing parameters */
-#ifndef KBD_RESETDELAY
-#define KBD_RESETDELAY 200 /* wait 200msec after kbd/mouse reset */
-#endif
-#ifndef KBD_MAXWAIT
-#define KBD_MAXWAIT 5 /* wait 5 times at most after reset */
-#endif
-
-/* I/O recovery time */
-#define KBDC_DELAYTIME 20
-#define KBDD_DELAYTIME 7
-
-/* debug option */
-#ifndef KBDIO_DEBUG
-#define KBDIO_DEBUG 0
-#endif
-
-/* end of driver specific options */
-
-/* types/structures */
-
-#define KBDQ_BUFSIZE 32
-
-typedef struct _kqueue {
- int head;
- int tail;
- unsigned char q[KBDQ_BUFSIZE];
-#if KBDIO_DEBUG >= 2
- int call_count;
- int qcount;
- int max_qcount;
-#endif
-} kqueue;
-
-struct resource;
-
-typedef struct atkbdc_softc {
- struct resource *port0; /* data port */
- struct resource *port1; /* status port */
- bus_space_tag_t iot;
- bus_space_handle_t ioh0;
- bus_space_handle_t ioh1;
- int command_byte; /* current command byte value */
- int command_mask; /* command byte mask bits for kbd/aux devices */
- int lock; /* FIXME: XXX not quite a semaphore... */
- kqueue kbd; /* keyboard data queue */
- kqueue aux; /* auxiliary data queue */
-} atkbdc_softc_t;
-
-enum kbdc_device_ivar {
- KBDC_IVAR_VENDORID,
- KBDC_IVAR_SERIAL,
- KBDC_IVAR_LOGICALID,
- KBDC_IVAR_COMPATID,
-};
-
-typedef caddr_t KBDC;
-
-#define KBDC_RID_KBD 0
-#define KBDC_RID_AUX 1
-
-/* function prototypes */
-
-atkbdc_softc_t *atkbdc_get_softc(int unit);
-int atkbdc_probe_unit(int unit, struct resource *port0, struct resource *port1);
-int atkbdc_attach_unit(int unit, atkbdc_softc_t *sc, struct resource *port0,
- struct resource *port1);
-int atkbdc_configure(void);
-
-KBDC atkbdc_open(int unit);
-int kbdc_lock(KBDC kbdc, int lock);
-int kbdc_data_ready(KBDC kbdc);
-
-int write_controller_command(KBDC kbdc,int c);
-int write_controller_data(KBDC kbdc,int c);
-
-int write_kbd_command(KBDC kbdc,int c);
-int write_aux_command(KBDC kbdc,int c);
-int send_kbd_command(KBDC kbdc,int c);
-int send_aux_command(KBDC kbdc,int c);
-int send_kbd_command_and_data(KBDC kbdc,int c,int d);
-int send_aux_command_and_data(KBDC kbdc,int c,int d);
-
-int read_controller_data(KBDC kbdc);
-int read_kbd_data(KBDC kbdc);
-int read_kbd_data_no_wait(KBDC kbdc);
-int read_aux_data(KBDC kbdc);
-int read_aux_data_no_wait(KBDC kbdc);
-
-void empty_kbd_buffer(KBDC kbdc, int t);
-void empty_aux_buffer(KBDC kbdc, int t);
-void empty_both_buffers(KBDC kbdc, int t);
-
-int reset_kbd(KBDC kbdc);
-int reset_aux_dev(KBDC kbdc);
-
-int test_controller(KBDC kbdc);
-int test_kbd_port(KBDC kbdc);
-int test_aux_port(KBDC kbdc);
-
-int kbdc_get_device_mask(KBDC kbdc);
-void kbdc_set_device_mask(KBDC kbdc, int mask);
-
-int get_controller_command_byte(KBDC kbdc);
-int set_controller_command_byte(KBDC kbdc, int command, int flag);
-
-#endif /* _KERNEL */
-
-#endif /* !_DEV_KBD_ATKBDCREG_H_ */
diff --git a/sys/dev/atkbdc/atkbdreg.h b/sys/dev/atkbdc/atkbdreg.h
deleted file mode 100644
index 4ae93e3b96ff..000000000000
--- a/sys/dev/atkbdc/atkbdreg.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*-
- * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must 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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (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 _DEV_KBD_ATKBDREG_H_
-#define _DEV_KBD_ATKBDREG_H_
-
-#define ATKBD_DRIVER_NAME "atkbd"
-
-/* device configuration flags (atkbdprobe, atkbdattach) */
-#define KB_CONF_FAIL_IF_NO_KBD (1 << 0) /* don't install if no kbd is found */
-#define KB_CONF_NO_RESET (1 << 1) /* don't reset the keyboard */
-#define KB_CONF_ALT_SCANCODESET (1 << 2) /* assume the XT type keyboard */
-
-#ifdef _KERNEL
-
-int atkbd_probe_unit(int unit, int ctlr, int irq, int flags);
-int atkbd_attach_unit(int unit, keyboard_t **kbd,
- int ctlr, int irq, int flags);
-
-#endif
-
-#endif /* !_DEV_KBD_ATKBDREG_H_ */
diff --git a/sys/dev/atkbdc/psm.c b/sys/dev/atkbdc/psm.c
deleted file mode 100644
index c312dbfaa592..000000000000
--- a/sys/dev/atkbdc/psm.c
+++ /dev/null
@@ -1,2960 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993 Erik Forsberg.
- * Copyright (c) 1996, 1997 Kazutaka YOKOTA.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-/*
- * Ported to 386bsd Oct 17, 1992
- * Sandi Donno, Computer Science, University of Cape Town, South Africa
- * Please send bug reports to sandi@cs.uct.ac.za
- *
- * Thanks are also due to Rick Macklem, rick@snowhite.cis.uoguelph.ca -
- * although I was only partially successful in getting the alpha release
- * of his "driver for the Logitech and ATI Inport Bus mice for use with
- * 386bsd and the X386 port" to work with my Microsoft mouse, I nevertheless
- * found his code to be an invaluable reference when porting this driver
- * to 386bsd.
- *
- * Further modifications for latest 386BSD+patchkit and port to NetBSD,
- * Andrew Herbert <andrew@werple.apana.org.au> - 8 June 1993
- *
- * Cloned from the Microsoft Bus Mouse driver, also by Erik Forsberg, by
- * Andrew Herbert - 12 June 1993
- *
- * Modified for PS/2 mouse by Charles Hannum <mycroft@ai.mit.edu>
- * - 13 June 1993
- *
- * Modified for PS/2 AUX mouse by Shoji Yuen <yuen@nuie.nagoya-u.ac.jp>
- * - 24 October 1993
- *
- * Hardware access routines and probe logic rewritten by
- * Kazutaka Yokota <yokota@zodiac.mech.utsunomiya-u.ac.jp>
- * - 3, 14, 22 October 1996.
- * - 12 November 1996. IOCTLs and rearranging `psmread', `psmioctl'...
- * - 14, 30 November 1996. Uses `kbdio.c'.
- * - 13 December 1996. Uses queuing version of `kbdio.c'.
- * - January/February 1997. Tweaked probe logic for
- * HiNote UltraII/Latitude/Armada laptops.
- * - 30 July 1997. Added APM support.
- * - 5 March 1997. Defined driver configuration flags (PSM_CONFIG_XXX).
- * Improved sync check logic.
- * Vendor specific support routines.
- */
-
-#include "opt_psm.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/module.h>
-#include <sys/bus.h>
-#include <sys/conf.h>
-#include <sys/poll.h>
-#include <sys/syslog.h>
-#include <machine/bus.h>
-#include <sys/rman.h>
-#include <sys/selinfo.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-
-#include <sys/limits.h>
-#include <sys/mouse.h>
-#include <machine/resource.h>
-
-#include <isa/isavar.h>
-#include <dev/kbd/atkbdcreg.h>
-
-/*
- * Driver specific options: the following options may be set by
- * `options' statements in the kernel configuration file.
- */
-
-/* debugging */
-#ifndef PSM_DEBUG
-#define PSM_DEBUG 0 /* logging: 0: none, 1: brief, 2: verbose */
-#endif
-
-#ifndef PSM_SYNCERR_THRESHOLD1
-#define PSM_SYNCERR_THRESHOLD1 20
-#endif
-
-#ifndef PSM_INPUT_TIMEOUT
-#define PSM_INPUT_TIMEOUT 2000000 /* 2 sec */
-#endif
-
-/* end of driver specific options */
-
-#define PSM_DRIVER_NAME "psm"
-#define PSMCPNP_DRIVER_NAME "psmcpnp"
-
-/* input queue */
-#define PSM_BUFSIZE 960
-#define PSM_SMALLBUFSIZE 240
-
-/* operation levels */
-#define PSM_LEVEL_BASE 0
-#define PSM_LEVEL_STANDARD 1
-#define PSM_LEVEL_NATIVE 2
-#define PSM_LEVEL_MIN PSM_LEVEL_BASE
-#define PSM_LEVEL_MAX PSM_LEVEL_NATIVE
-
-/* Logitech PS2++ protocol */
-#define MOUSE_PS2PLUS_CHECKBITS(b) \
- ((((b[2] & 0x03) << 2) | 0x02) == (b[1] & 0x0f))
-#define MOUSE_PS2PLUS_PACKET_TYPE(b) \
- (((b[0] & 0x30) >> 2) | ((b[1] & 0x30) >> 4))
-
-/* some macros */
-#define PSM_UNIT(dev) (minor(dev) >> 1)
-#define PSM_NBLOCKIO(dev) (minor(dev) & 1)
-#define PSM_MKMINOR(unit,block) (((unit) << 1) | ((block) ? 0:1))
-
-/* ring buffer */
-typedef struct ringbuf {
- int count; /* # of valid elements in the buffer */
- int head; /* head pointer */
- int tail; /* tail poiner */
- unsigned char buf[PSM_BUFSIZE];
-} ringbuf_t;
-
-/* driver control block */
-struct psm_softc { /* Driver status information */
- int unit;
- struct selinfo rsel; /* Process selecting for Input */
- unsigned char state; /* Mouse driver state */
- int config; /* driver configuration flags */
- int flags; /* other flags */
- KBDC kbdc; /* handle to access the keyboard controller */
- struct resource *intr; /* IRQ resource */
- void *ih; /* interrupt handle */
- mousehw_t hw; /* hardware information */
- mousemode_t mode; /* operation mode */
- mousemode_t dflt_mode; /* default operation mode */
- mousestatus_t status; /* accumulated mouse movement */
- ringbuf_t queue; /* mouse status queue */
- unsigned char ipacket[16]; /* interim input buffer */
- int inputbytes; /* # of bytes in the input buffer */
- int button; /* the latest button state */
- int xold; /* previous absolute X position */
- int yold; /* previous absolute Y position */
- int syncerrors;
- struct timeval inputtimeout;
- int watchdog; /* watchdog timer flag */
- struct callout_handle callout; /* watchdog timer call out */
- dev_t dev;
- dev_t bdev;
-};
-static devclass_t psm_devclass;
-#define PSM_SOFTC(unit) ((struct psm_softc*)devclass_get_softc(psm_devclass, unit))
-
-/* driver state flags (state) */
-#define PSM_VALID 0x80
-#define PSM_OPEN 1 /* Device is open */
-#define PSM_ASLP 2 /* Waiting for mouse data */
-
-/* driver configuration flags (config) */
-#define PSM_CONFIG_RESOLUTION 0x000f /* resolution */
-#define PSM_CONFIG_ACCEL 0x00f0 /* acceleration factor */
-#define PSM_CONFIG_NOCHECKSYNC 0x0100 /* disable sync. test */
-#define PSM_CONFIG_NOIDPROBE 0x0200 /* disable mouse model probe */
-#define PSM_CONFIG_NORESET 0x0400 /* don't reset the mouse */
-#define PSM_CONFIG_FORCETAP 0x0800 /* assume `tap' action exists */
-#define PSM_CONFIG_IGNPORTERROR 0x1000 /* ignore error in aux port test */
-#define PSM_CONFIG_HOOKRESUME 0x2000 /* hook the system resume event */
-#define PSM_CONFIG_INITAFTERSUSPEND 0x4000 /* init the device at the resume event */
-#define PSM_CONFIG_SYNCHACK 0x8000 /* enable `out-of-sync' hack */
-
-#define PSM_CONFIG_FLAGS (PSM_CONFIG_RESOLUTION \
- | PSM_CONFIG_ACCEL \
- | PSM_CONFIG_NOCHECKSYNC \
- | PSM_CONFIG_SYNCHACK \
- | PSM_CONFIG_NOIDPROBE \
- | PSM_CONFIG_NORESET \
- | PSM_CONFIG_FORCETAP \
- | PSM_CONFIG_IGNPORTERROR \
- | PSM_CONFIG_HOOKRESUME \
- | PSM_CONFIG_INITAFTERSUSPEND)
-
-/* other flags (flags) */
-#define PSM_FLAGS_FINGERDOWN 0x0001 /* VersaPad finger down */
-
-/* for backward compatibility */
-#define OLD_MOUSE_GETHWINFO _IOR('M', 1, old_mousehw_t)
-#define OLD_MOUSE_GETMODE _IOR('M', 2, old_mousemode_t)
-#define OLD_MOUSE_SETMODE _IOW('M', 3, old_mousemode_t)
-
-typedef struct old_mousehw {
- int buttons;
- int iftype;
- int type;
- int hwid;
-} old_mousehw_t;
-
-typedef struct old_mousemode {
- int protocol;
- int rate;
- int resolution;
- int accelfactor;
-} old_mousemode_t;
-
-/* packet formatting function */
-typedef int packetfunc_t(struct psm_softc *, unsigned char *,
- int *, int, mousestatus_t *);
-
-/* function prototypes */
-static void psmidentify(driver_t *, device_t);
-static int psmprobe(device_t);
-static int psmattach(device_t);
-static int psmdetach(device_t);
-static int psmresume(device_t);
-
-static d_open_t psmopen;
-static d_close_t psmclose;
-static d_read_t psmread;
-static d_ioctl_t psmioctl;
-static d_poll_t psmpoll;
-
-static int enable_aux_dev(KBDC);
-static int disable_aux_dev(KBDC);
-static int get_mouse_status(KBDC, int *, int, int);
-static int get_aux_id(KBDC);
-static int set_mouse_sampling_rate(KBDC, int);
-static int set_mouse_scaling(KBDC, int);
-static int set_mouse_resolution(KBDC, int);
-static int set_mouse_mode(KBDC);
-static int get_mouse_buttons(KBDC);
-static int is_a_mouse(int);
-static void recover_from_error(KBDC);
-static int restore_controller(KBDC, int);
-static int doinitialize(struct psm_softc *, mousemode_t *);
-static int doopen(struct psm_softc *, int);
-static int reinitialize(struct psm_softc *, int);
-static char *model_name(int);
-static void psmintr(void *);
-static void psmtimeout(void *);
-
-/* vendor specific features */
-typedef int probefunc_t(struct psm_softc *);
-
-static int mouse_id_proc1(KBDC, int, int, int *);
-static int mouse_ext_command(KBDC, int);
-static probefunc_t enable_groller;
-static probefunc_t enable_gmouse;
-static probefunc_t enable_aglide;
-static probefunc_t enable_kmouse;
-static probefunc_t enable_msexplorer;
-static probefunc_t enable_msintelli;
-static probefunc_t enable_4dmouse;
-static probefunc_t enable_4dplus;
-static probefunc_t enable_mmanplus;
-static probefunc_t enable_versapad;
-static int tame_mouse(struct psm_softc *, mousestatus_t *, unsigned char *);
-
-static struct {
- int model;
- unsigned char syncmask;
- int packetsize;
- probefunc_t *probefunc;
-} vendortype[] = {
- /*
- * WARNING: the order of probe is very important. Don't mess it
- * unless you know what you are doing.
- */
- { MOUSE_MODEL_NET, /* Genius NetMouse */
- 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_gmouse, },
- { MOUSE_MODEL_NETSCROLL, /* Genius NetScroll */
- 0xc8, 6, enable_groller, },
- { MOUSE_MODEL_MOUSEMANPLUS, /* Logitech MouseMan+ */
- 0x08, MOUSE_PS2_PACKETSIZE, enable_mmanplus, },
- { MOUSE_MODEL_EXPLORER, /* Microsoft IntelliMouse Explorer */
- 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msexplorer, },
- { MOUSE_MODEL_4D, /* A4 Tech 4D Mouse */
- 0x08, MOUSE_4D_PACKETSIZE, enable_4dmouse, },
- { MOUSE_MODEL_4DPLUS, /* A4 Tech 4D+ Mouse */
- 0xc8, MOUSE_4DPLUS_PACKETSIZE, enable_4dplus, },
- { MOUSE_MODEL_INTELLI, /* Microsoft IntelliMouse */
- 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msintelli, },
- { MOUSE_MODEL_GLIDEPOINT, /* ALPS GlidePoint */
- 0xc0, MOUSE_PS2_PACKETSIZE, enable_aglide, },
- { MOUSE_MODEL_THINK, /* Kensignton ThinkingMouse */
- 0x80, MOUSE_PS2_PACKETSIZE, enable_kmouse, },
- { MOUSE_MODEL_VERSAPAD, /* Interlink electronics VersaPad */
- 0xe8, MOUSE_PS2VERSA_PACKETSIZE, enable_versapad, },
- { MOUSE_MODEL_GENERIC,
- 0xc0, MOUSE_PS2_PACKETSIZE, NULL, },
-};
-#define GENERIC_MOUSE_ENTRY ((sizeof(vendortype) / sizeof(*vendortype)) - 1)
-
-/* device driver declarateion */
-static device_method_t psm_methods[] = {
- /* Device interface */
- DEVMETHOD(device_identify, psmidentify),
- DEVMETHOD(device_probe, psmprobe),
- DEVMETHOD(device_attach, psmattach),
- DEVMETHOD(device_detach, psmdetach),
- DEVMETHOD(device_resume, psmresume),
-
- { 0, 0 }
-};
-
-static driver_t psm_driver = {
- PSM_DRIVER_NAME,
- psm_methods,
- sizeof(struct psm_softc),
-};
-
-#define CDEV_MAJOR 21
-
-static struct cdevsw psm_cdevsw = {
- .d_open = psmopen,
- .d_close = psmclose,
- .d_read = psmread,
- .d_ioctl = psmioctl,
- .d_poll = psmpoll,
- .d_name = PSM_DRIVER_NAME,
- .d_maj = CDEV_MAJOR,
-};
-
-/* debug message level */
-static int verbose = PSM_DEBUG;
-
-/* device I/O routines */
-static int
-enable_aux_dev(KBDC kbdc)
-{
- int res;
-
- res = send_aux_command(kbdc, PSMC_ENABLE_DEV);
- if (verbose >= 2)
- log(LOG_DEBUG, "psm: ENABLE_DEV return code:%04x\n", res);
-
- return (res == PSM_ACK);
-}
-
-static int
-disable_aux_dev(KBDC kbdc)
-{
- int res;
-
- res = send_aux_command(kbdc, PSMC_DISABLE_DEV);
- if (verbose >= 2)
- log(LOG_DEBUG, "psm: DISABLE_DEV return code:%04x\n", res);
-
- return (res == PSM_ACK);
-}
-
-static int
-get_mouse_status(KBDC kbdc, int *status, int flag, int len)
-{
- int cmd;
- int res;
- int i;
-
- switch (flag) {
- case 0:
- default:
- cmd = PSMC_SEND_DEV_STATUS;
- break;
- case 1:
- cmd = PSMC_SEND_DEV_DATA;
- break;
- }
- empty_aux_buffer(kbdc, 5);
- res = send_aux_command(kbdc, cmd);
- if (verbose >= 2)
- log(LOG_DEBUG, "psm: SEND_AUX_DEV_%s return code:%04x\n",
- (flag == 1) ? "DATA" : "STATUS", res);
- if (res != PSM_ACK)
- return 0;
-
- for (i = 0; i < len; ++i) {
- status[i] = read_aux_data(kbdc);
- if (status[i] < 0)
- break;
- }
-
- if (verbose) {
- log(LOG_DEBUG, "psm: %s %02x %02x %02x\n",
- (flag == 1) ? "data" : "status", status[0], status[1], status[2]);
- }
-
- return i;
-}
-
-static int
-get_aux_id(KBDC kbdc)
-{
- int res;
- int id;
-
- empty_aux_buffer(kbdc, 5);
- res = send_aux_command(kbdc, PSMC_SEND_DEV_ID);
- if (verbose >= 2)
- log(LOG_DEBUG, "psm: SEND_DEV_ID return code:%04x\n", res);
- if (res != PSM_ACK)
- return (-1);
-
- /* 10ms delay */
- DELAY(10000);
-
- id = read_aux_data(kbdc);
- if (verbose >= 2)
- log(LOG_DEBUG, "psm: device ID: %04x\n", id);
-
- return id;
-}
-
-static int
-set_mouse_sampling_rate(KBDC kbdc, int rate)
-{
- int res;
-
- res = send_aux_command_and_data(kbdc, PSMC_SET_SAMPLING_RATE, rate);
- if (verbose >= 2)
- log(LOG_DEBUG, "psm: SET_SAMPLING_RATE (%d) %04x\n", rate, res);
-
- return ((res == PSM_ACK) ? rate : -1);
-}
-
-static int
-set_mouse_scaling(KBDC kbdc, int scale)
-{
- int res;
-
- switch (scale) {
- case 1:
- default:
- scale = PSMC_SET_SCALING11;
- break;
- case 2:
- scale = PSMC_SET_SCALING21;
- break;
- }
- res = send_aux_command(kbdc, scale);
- if (verbose >= 2)
- log(LOG_DEBUG, "psm: SET_SCALING%s return code:%04x\n",
- (scale == PSMC_SET_SCALING21) ? "21" : "11", res);
-
- return (res == PSM_ACK);
-}
-
-/* `val' must be 0 through PSMD_MAX_RESOLUTION */
-static int
-set_mouse_resolution(KBDC kbdc, int val)
-{
- int res;
-
- res = send_aux_command_and_data(kbdc, PSMC_SET_RESOLUTION, val);
- if (verbose >= 2)
- log(LOG_DEBUG, "psm: SET_RESOLUTION (%d) %04x\n", val, res);
-
- return ((res == PSM_ACK) ? val : -1);
-}
-
-/*
- * NOTE: once `set_mouse_mode()' is called, the mouse device must be
- * re-enabled by calling `enable_aux_dev()'
- */
-static int
-set_mouse_mode(KBDC kbdc)
-{
- int res;
-
- res = send_aux_command(kbdc, PSMC_SET_STREAM_MODE);
- if (verbose >= 2)
- log(LOG_DEBUG, "psm: SET_STREAM_MODE return code:%04x\n", res);
-
- return (res == PSM_ACK);
-}
-
-static int
-get_mouse_buttons(KBDC kbdc)
-{
- int c = 2; /* assume two buttons by default */
- int status[3];
-
- /*
- * NOTE: a special sequence to obtain Logitech Mouse specific
- * information: set resolution to 25 ppi, set scaling to 1:1, set
- * scaling to 1:1, set scaling to 1:1. Then the second byte of the
- * mouse status bytes is the number of available buttons.
- * Some manufactures also support this sequence.
- */
- if (set_mouse_resolution(kbdc, PSMD_RES_LOW) != PSMD_RES_LOW)
- return c;
- if (set_mouse_scaling(kbdc, 1) && set_mouse_scaling(kbdc, 1)
- && set_mouse_scaling(kbdc, 1)
- && (get_mouse_status(kbdc, status, 0, 3) >= 3)) {
- if (status[1] != 0)
- return status[1];
- }
- return c;
-}
-
-/* misc subroutines */
-/*
- * Someday, I will get the complete list of valid pointing devices and
- * their IDs... XXX
- */
-static int
-is_a_mouse(int id)
-{
-#if 0
- static int valid_ids[] = {
- PSM_MOUSE_ID, /* mouse */
- PSM_BALLPOINT_ID, /* ballpoint device */
- PSM_INTELLI_ID, /* Intellimouse */
- PSM_EXPLORER_ID, /* Intellimouse Explorer */
- -1 /* end of table */
- };
- int i;
-
- for (i = 0; valid_ids[i] >= 0; ++i)
- if (valid_ids[i] == id)
- return TRUE;
- return FALSE;
-#else
- return TRUE;
-#endif
-}
-
-static char *
-model_name(int model)
-{
- static struct {
- int model_code;
- char *model_name;
- } models[] = {
- { MOUSE_MODEL_NETSCROLL, "NetScroll" },
- { MOUSE_MODEL_NET, "NetMouse/NetScroll Optical" },
- { MOUSE_MODEL_GLIDEPOINT, "GlidePoint" },
- { MOUSE_MODEL_THINK, "ThinkingMouse" },
- { MOUSE_MODEL_INTELLI, "IntelliMouse" },
- { MOUSE_MODEL_MOUSEMANPLUS, "MouseMan+" },
- { MOUSE_MODEL_VERSAPAD, "VersaPad" },
- { MOUSE_MODEL_EXPLORER, "IntelliMouse Explorer" },
- { MOUSE_MODEL_4D, "4D Mouse" },
- { MOUSE_MODEL_4DPLUS, "4D+ Mouse" },
- { MOUSE_MODEL_GENERIC, "Generic PS/2 mouse" },
- { MOUSE_MODEL_UNKNOWN, NULL },
- };
- int i;
-
- for (i = 0; models[i].model_code != MOUSE_MODEL_UNKNOWN; ++i) {
- if (models[i].model_code == model)
- return models[i].model_name;
- }
- return "Unknown";
-}
-
-static void
-recover_from_error(KBDC kbdc)
-{
- /* discard anything left in the output buffer */
- empty_both_buffers(kbdc, 10);
-
-#if 0
- /*
- * NOTE: KBDC_RESET_KBD may not restore the communication between the
- * keyboard and the controller.
- */
- reset_kbd(kbdc);
-#else
- /*
- * NOTE: somehow diagnostic and keyboard port test commands bring the
- * keyboard back.
- */
- if (!test_controller(kbdc))
- log(LOG_ERR, "psm: keyboard controller failed.\n");
- /* if there isn't a keyboard in the system, the following error is OK */
- if (test_kbd_port(kbdc) != 0) {
- if (verbose)
- log(LOG_ERR, "psm: keyboard port failed.\n");
- }
-#endif
-}
-
-static int
-restore_controller(KBDC kbdc, int command_byte)
-{
- empty_both_buffers(kbdc, 10);
-
- if (!set_controller_command_byte(kbdc, 0xff, command_byte)) {
- log(LOG_ERR, "psm: failed to restore the keyboard controller "
- "command byte.\n");
- empty_both_buffers(kbdc, 10);
- return FALSE;
- } else {
- empty_both_buffers(kbdc, 10);
- return TRUE;
- }
-}
-
-/*
- * Re-initialize the aux port and device. The aux port must be enabled
- * and its interrupt must be disabled before calling this routine.
- * The aux device will be disabled before returning.
- * The keyboard controller must be locked via `kbdc_lock()' before
- * calling this routine.
- */
-static int
-doinitialize(struct psm_softc *sc, mousemode_t *mode)
-{
- KBDC kbdc = sc->kbdc;
- int stat[3];
- int i;
-
- switch((i = test_aux_port(kbdc))) {
- case 1: /* ignore this error */
- case PSM_ACK:
- if (verbose)
- log(LOG_DEBUG, "psm%d: strange result for test aux port (%d).\n",
- sc->unit, i);
- /* FALLTHROUGH */
- case 0: /* no error */
- break;
- case -1: /* time out */
- default: /* error */
- recover_from_error(kbdc);
- if (sc->config & PSM_CONFIG_IGNPORTERROR)
- break;
- log(LOG_ERR, "psm%d: the aux port is not functioning (%d).\n",
- sc->unit, i);
- return FALSE;
- }
-
- if (sc->config & PSM_CONFIG_NORESET) {
- /*
- * Don't try to reset the pointing device. It may possibly be
- * left in the unknown state, though...
- */
- } else {
- /*
- * NOTE: some controllers appears to hang the `keyboard' when
- * the aux port doesn't exist and `PSMC_RESET_DEV' is issued.
- */
- if (!reset_aux_dev(kbdc)) {
- recover_from_error(kbdc);
- log(LOG_ERR, "psm%d: failed to reset the aux device.\n", sc->unit);
- return FALSE;
- }
- }
-
- /*
- * both the aux port and the aux device is functioning, see
- * if the device can be enabled.
- */
- if (!enable_aux_dev(kbdc) || !disable_aux_dev(kbdc)) {
- log(LOG_ERR, "psm%d: failed to enable the aux device.\n", sc->unit);
- return FALSE;
- }
- empty_both_buffers(kbdc, 10); /* remove stray data if any */
-
- if (sc->config & PSM_CONFIG_NOIDPROBE) {
- i = GENERIC_MOUSE_ENTRY;
- } else {
- /* FIXME: hardware ID, mouse buttons? */
-
- /* other parameters */
- for (i = 0; vendortype[i].probefunc != NULL; ++i) {
- if ((*vendortype[i].probefunc)(sc)) {
- if (verbose >= 2)
- log(LOG_ERR, "psm%d: found %s\n",
- sc->unit, model_name(vendortype[i].model));
- break;
- }
- }
- }
-
- sc->hw.model = vendortype[i].model;
- sc->mode.packetsize = vendortype[i].packetsize;
-
- /* set mouse parameters */
- if (mode != (mousemode_t *)NULL) {
- if (mode->rate > 0)
- mode->rate = set_mouse_sampling_rate(kbdc, mode->rate);
- if (mode->resolution >= 0)
- mode->resolution = set_mouse_resolution(kbdc, mode->resolution);
- set_mouse_scaling(kbdc, 1);
- set_mouse_mode(kbdc);
- }
-
- /* request a data packet and extract sync. bits */
- if (get_mouse_status(kbdc, stat, 1, 3) < 3) {
- log(LOG_DEBUG, "psm%d: failed to get data (doinitialize).\n",
- sc->unit);
- sc->mode.syncmask[0] = 0;
- } else {
- sc->mode.syncmask[1] = stat[0] & sc->mode.syncmask[0]; /* syncbits */
- /* the NetScroll Mouse will send three more bytes... Ignore them */
- empty_aux_buffer(kbdc, 5);
- }
-
- /* just check the status of the mouse */
- if (get_mouse_status(kbdc, stat, 0, 3) < 3)
- log(LOG_DEBUG, "psm%d: failed to get status (doinitialize).\n",
- sc->unit);
-
- return TRUE;
-}
-
-static int
-doopen(struct psm_softc *sc, int command_byte)
-{
- int stat[3];
-
- /* enable the mouse device */
- if (!enable_aux_dev(sc->kbdc)) {
- /* MOUSE ERROR: failed to enable the mouse because:
- * 1) the mouse is faulty,
- * 2) the mouse has been removed(!?)
- * In the latter case, the keyboard may have hung, and need
- * recovery procedure...
- */
- recover_from_error(sc->kbdc);
-#if 0
- /* FIXME: we could reset the mouse here and try to enable
- * it again. But it will take long time and it's not a good
- * idea to disable the keyboard that long...
- */
- if (!doinitialize(sc, &sc->mode) || !enable_aux_dev(sc->kbdc)) {
- recover_from_error(sc->kbdc);
-#else
- {
-#endif
- restore_controller(sc->kbdc, command_byte);
- /* mark this device is no longer available */
- sc->state &= ~PSM_VALID;
- log(LOG_ERR, "psm%d: failed to enable the device (doopen).\n",
- sc->unit);
- return (EIO);
- }
- }
-
- if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3)
- log(LOG_DEBUG, "psm%d: failed to get status (doopen).\n", sc->unit);
-
- /* enable the aux port and interrupt */
- if (!set_controller_command_byte(sc->kbdc,
- kbdc_get_device_mask(sc->kbdc),
- (command_byte & KBD_KBD_CONTROL_BITS)
- | KBD_ENABLE_AUX_PORT | KBD_ENABLE_AUX_INT)) {
- /* CONTROLLER ERROR */
- disable_aux_dev(sc->kbdc);
- restore_controller(sc->kbdc, command_byte);
- log(LOG_ERR, "psm%d: failed to enable the aux interrupt (doopen).\n",
- sc->unit);
- return (EIO);
- }
-
- /* start the watchdog timer */
- sc->watchdog = FALSE;
- sc->callout = timeout(psmtimeout, (void *)(uintptr_t)sc, hz*2);
-
- return (0);
-}
-
-static int
-reinitialize(struct psm_softc *sc, int doinit)
-{
- int err;
- int c;
- int s;
-
- /* don't let anybody mess with the aux device */
- if (!kbdc_lock(sc->kbdc, TRUE))
- return (EIO);
- s = spltty();
-
- /* block our watchdog timer */
- sc->watchdog = FALSE;
- untimeout(psmtimeout, (void *)(uintptr_t)sc, sc->callout);
- callout_handle_init(&sc->callout);
-
- /* save the current controller command byte */
- empty_both_buffers(sc->kbdc, 10);
- c = get_controller_command_byte(sc->kbdc);
- if (verbose >= 2)
- log(LOG_DEBUG, "psm%d: current command byte: %04x (reinitialize).\n",
- sc->unit, c);
-
- /* enable the aux port but disable the aux interrupt and the keyboard */
- if ((c == -1) || !set_controller_command_byte(sc->kbdc,
- kbdc_get_device_mask(sc->kbdc),
- KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT
- | KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
- /* CONTROLLER ERROR */
- splx(s);
- kbdc_lock(sc->kbdc, FALSE);
- log(LOG_ERR, "psm%d: unable to set the command byte (reinitialize).\n",
- sc->unit);
- return (EIO);
- }
-
- /* flush any data */
- if (sc->state & PSM_VALID) {
- disable_aux_dev(sc->kbdc); /* this may fail; but never mind... */
- empty_aux_buffer(sc->kbdc, 10);
- }
- sc->inputbytes = 0;
- sc->syncerrors = 0;
-
- /* try to detect the aux device; are you still there? */
- err = 0;
- if (doinit) {
- if (doinitialize(sc, &sc->mode)) {
- /* yes */
- sc->state |= PSM_VALID;
- } else {
- /* the device has gone! */
- restore_controller(sc->kbdc, c);
- sc->state &= ~PSM_VALID;
- log(LOG_ERR, "psm%d: the aux device has gone! (reinitialize).\n",
- sc->unit);
- err = ENXIO;
- }
- }
- splx(s);
-
- /* restore the driver state */
- if ((sc->state & PSM_OPEN) && (err == 0)) {
- /* enable the aux device and the port again */
- err = doopen(sc, c);
- if (err != 0)
- log(LOG_ERR, "psm%d: failed to enable the device (reinitialize).\n",
- sc->unit);
- } else {
- /* restore the keyboard port and disable the aux port */
- if (!set_controller_command_byte(sc->kbdc,
- kbdc_get_device_mask(sc->kbdc),
- (c & KBD_KBD_CONTROL_BITS)
- | KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
- /* CONTROLLER ERROR */
- log(LOG_ERR, "psm%d: failed to disable the aux port (reinitialize).\n",
- sc->unit);
- err = EIO;
- }
- }
-
- kbdc_lock(sc->kbdc, FALSE);
- return (err);
-}
-
-/* psm driver entry points */
-
-static void
-psmidentify(driver_t *driver, device_t parent)
-{
- device_t psmc;
- device_t psm;
- u_long irq;
- int unit;
-
- unit = device_get_unit(parent);
-
- /* always add at least one child */
- psm = BUS_ADD_CHILD(parent, KBDC_RID_AUX, driver->name, unit);
- if (psm == NULL)
- return;
-
- irq = bus_get_resource_start(psm, SYS_RES_IRQ, KBDC_RID_AUX);
- if (irq > 0)
- return;
-
- /*
- * If the PS/2 mouse device has already been reported by ACPI or
- * PnP BIOS, obtain the IRQ resource from it.
- * (See psmcpnp_attach() below.)
- */
- psmc = device_find_child(device_get_parent(parent),
- PSMCPNP_DRIVER_NAME, unit);
- if (psmc == NULL)
- return;
- irq = bus_get_resource_start(psmc, SYS_RES_IRQ, 0);
- if (irq <= 0)
- return;
- bus_set_resource(psm, SYS_RES_IRQ, KBDC_RID_AUX, irq, 1);
-}
-
-#define endprobe(v) { if (bootverbose) \
- --verbose; \
- kbdc_set_device_mask(sc->kbdc, mask); \
- kbdc_lock(sc->kbdc, FALSE); \
- return (v); \
- }
-
-static int
-psmprobe(device_t dev)
-{
- int unit = device_get_unit(dev);
- struct psm_softc *sc = device_get_softc(dev);
- int stat[3];
- int command_byte;
- int mask;
- int rid;
- int i;
-
-#if 0
- kbdc_debug(TRUE);
-#endif
-
- /* see if IRQ is available */
- rid = KBDC_RID_AUX;
- sc->intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE | RF_ACTIVE);
- if (sc->intr == NULL) {
- if (bootverbose)
- device_printf(dev, "unable to allocate IRQ\n");
- return (ENXIO);
- }
- bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
-
- sc->unit = unit;
- sc->kbdc = atkbdc_open(device_get_unit(device_get_parent(dev)));
- sc->config = device_get_flags(dev) & PSM_CONFIG_FLAGS;
- /* XXX: for backward compatibility */
-#if defined(PSM_HOOKRESUME) || defined(PSM_HOOKAPM)
- sc->config |=
-#ifdef PSM_RESETAFTERSUSPEND
- PSM_CONFIG_HOOKRESUME | PSM_CONFIG_INITAFTERSUSPEND;
-#else
- PSM_CONFIG_HOOKRESUME;
-#endif
-#endif /* PSM_HOOKRESUME | PSM_HOOKAPM */
- sc->flags = 0;
- if (bootverbose)
- ++verbose;
-
- device_set_desc(dev, "PS/2 Mouse");
-
- if (!kbdc_lock(sc->kbdc, TRUE)) {
- printf("psm%d: unable to lock the controller.\n", unit);
- if (bootverbose)
- --verbose;
- return (ENXIO);
- }
-
- /*
- * NOTE: two bits in the command byte controls the operation of the
- * aux port (mouse port): the aux port disable bit (bit 5) and the aux
- * port interrupt (IRQ 12) enable bit (bit 2).
- */
-
- /* discard anything left after the keyboard initialization */
- empty_both_buffers(sc->kbdc, 10);
-
- /* save the current command byte; it will be used later */
- mask = kbdc_get_device_mask(sc->kbdc) & ~KBD_AUX_CONTROL_BITS;
- command_byte = get_controller_command_byte(sc->kbdc);
- if (verbose)
- printf("psm%d: current command byte:%04x\n", unit, command_byte);
- if (command_byte == -1) {
- /* CONTROLLER ERROR */
- printf("psm%d: unable to get the current command byte value.\n",
- unit);
- endprobe(ENXIO);
- }
-
- /*
- * disable the keyboard port while probing the aux port, which must be
- * enabled during this routine
- */
- if (!set_controller_command_byte(sc->kbdc,
- KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS,
- KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT
- | KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
- /*
- * this is CONTROLLER ERROR; I don't know how to recover
- * from this error...
- */
- restore_controller(sc->kbdc, command_byte);
- printf("psm%d: unable to set the command byte.\n", unit);
- endprobe(ENXIO);
- }
- write_controller_command(sc->kbdc, KBDC_ENABLE_AUX_PORT);
-
- /*
- * NOTE: `test_aux_port()' is designed to return with zero if the aux
- * port exists and is functioning. However, some controllers appears
- * to respond with zero even when the aux port doesn't exist. (It may
- * be that this is only the case when the controller DOES have the aux
- * port but the port is not wired on the motherboard.) The keyboard
- * controllers without the port, such as the original AT, are
- * supporsed to return with an error code or simply time out. In any
- * case, we have to continue probing the port even when the controller
- * passes this test.
- *
- * XXX: some controllers erroneously return the error code 1 when
- * it has the perfectly functional aux port. We have to ignore this
- * error code. Even if the controller HAS error with the aux port,
- * it will be detected later...
- * XXX: another incompatible controller returns PSM_ACK (0xfa)...
- */
- switch ((i = test_aux_port(sc->kbdc))) {
- case 1: /* ignore this error */
- case PSM_ACK:
- if (verbose)
- printf("psm%d: strange result for test aux port (%d).\n",
- unit, i);
- /* FALLTHROUGH */
- case 0: /* no error */
- break;
- case -1: /* time out */
- default: /* error */
- recover_from_error(sc->kbdc);
- if (sc->config & PSM_CONFIG_IGNPORTERROR)
- break;
- restore_controller(sc->kbdc, command_byte);
- if (verbose)
- printf("psm%d: the aux port is not functioning (%d).\n",
- unit, i);
- endprobe(ENXIO);
- }
-
- if (sc->config & PSM_CONFIG_NORESET) {
- /*
- * Don't try to reset the pointing device. It may possibly be
- * left in the unknown state, though...
- */
- } else {
- /*
- * NOTE: some controllers appears to hang the `keyboard' when the aux
- * port doesn't exist and `PSMC_RESET_DEV' is issued.
- */
- if (!reset_aux_dev(sc->kbdc)) {
- recover_from_error(sc->kbdc);
- restore_controller(sc->kbdc, command_byte);
- if (verbose)
- printf("psm%d: failed to reset the aux device.\n", unit);
- endprobe(ENXIO);
- }
- }
-
- /*
- * both the aux port and the aux device is functioning, see if the
- * device can be enabled. NOTE: when enabled, the device will start
- * sending data; we shall immediately disable the device once we know
- * the device can be enabled.
- */
- if (!enable_aux_dev(sc->kbdc) || !disable_aux_dev(sc->kbdc)) {
- /* MOUSE ERROR */
- recover_from_error(sc->kbdc);
- restore_controller(sc->kbdc, command_byte);
- if (verbose)
- printf("psm%d: failed to enable the aux device.\n", unit);
- endprobe(ENXIO);
- }
-
- /* save the default values after reset */
- if (get_mouse_status(sc->kbdc, stat, 0, 3) >= 3) {
- sc->dflt_mode.rate = sc->mode.rate = stat[2];
- sc->dflt_mode.resolution = sc->mode.resolution = stat[1];
- } else {
- sc->dflt_mode.rate = sc->mode.rate = -1;
- sc->dflt_mode.resolution = sc->mode.resolution = -1;
- }
-
- /* hardware information */
- sc->hw.iftype = MOUSE_IF_PS2;
-
- /* verify the device is a mouse */
- sc->hw.hwid = get_aux_id(sc->kbdc);
- if (!is_a_mouse(sc->hw.hwid)) {
- restore_controller(sc->kbdc, command_byte);
- if (verbose)
- printf("psm%d: unknown device type (%d).\n", unit, sc->hw.hwid);
- endprobe(ENXIO);
- }
- switch (sc->hw.hwid) {
- case PSM_BALLPOINT_ID:
- sc->hw.type = MOUSE_TRACKBALL;
- break;
- case PSM_MOUSE_ID:
- case PSM_INTELLI_ID:
- case PSM_EXPLORER_ID:
- case PSM_4DMOUSE_ID:
- case PSM_4DPLUS_ID:
- sc->hw.type = MOUSE_MOUSE;
- break;
- default:
- sc->hw.type = MOUSE_UNKNOWN;
- break;
- }
-
- if (sc->config & PSM_CONFIG_NOIDPROBE) {
- sc->hw.buttons = 2;
- i = GENERIC_MOUSE_ENTRY;
- } else {
- /* # of buttons */
- sc->hw.buttons = get_mouse_buttons(sc->kbdc);
-
- /* other parameters */
- for (i = 0; vendortype[i].probefunc != NULL; ++i) {
- if ((*vendortype[i].probefunc)(sc)) {
- if (verbose >= 2)
- printf("psm%d: found %s\n",
- unit, model_name(vendortype[i].model));
- break;
- }
- }
- }
-
- sc->hw.model = vendortype[i].model;
-
- sc->dflt_mode.level = PSM_LEVEL_BASE;
- sc->dflt_mode.packetsize = MOUSE_PS2_PACKETSIZE;
- sc->dflt_mode.accelfactor = (sc->config & PSM_CONFIG_ACCEL) >> 4;
- if (sc->config & PSM_CONFIG_NOCHECKSYNC)
- sc->dflt_mode.syncmask[0] = 0;
- else
- sc->dflt_mode.syncmask[0] = vendortype[i].syncmask;
- if (sc->config & PSM_CONFIG_FORCETAP)
- sc->mode.syncmask[0] &= ~MOUSE_PS2_TAP;
- sc->dflt_mode.syncmask[1] = 0; /* syncbits */
- sc->mode = sc->dflt_mode;
- sc->mode.packetsize = vendortype[i].packetsize;
-
- /* set mouse parameters */
-#if 0
- /*
- * A version of Logitech FirstMouse+ won't report wheel movement,
- * if SET_DEFAULTS is sent... Don't use this command.
- * This fix was found by Takashi Nishida.
- */
- i = send_aux_command(sc->kbdc, PSMC_SET_DEFAULTS);
- if (verbose >= 2)
- printf("psm%d: SET_DEFAULTS return code:%04x\n", unit, i);
-#endif
- if (sc->config & PSM_CONFIG_RESOLUTION) {
- sc->mode.resolution
- = set_mouse_resolution(sc->kbdc,
- (sc->config & PSM_CONFIG_RESOLUTION) - 1);
- } else if (sc->mode.resolution >= 0) {
- sc->mode.resolution
- = set_mouse_resolution(sc->kbdc, sc->dflt_mode.resolution);
- }
- if (sc->mode.rate > 0) {
- sc->mode.rate = set_mouse_sampling_rate(sc->kbdc, sc->dflt_mode.rate);
- }
- set_mouse_scaling(sc->kbdc, 1);
-
- /* request a data packet and extract sync. bits */
- if (get_mouse_status(sc->kbdc, stat, 1, 3) < 3) {
- printf("psm%d: failed to get data.\n", unit);
- sc->mode.syncmask[0] = 0;
- } else {
- sc->mode.syncmask[1] = stat[0] & sc->mode.syncmask[0]; /* syncbits */
- /* the NetScroll Mouse will send three more bytes... Ignore them */
- empty_aux_buffer(sc->kbdc, 5);
- }
-
- /* just check the status of the mouse */
- /*
- * NOTE: XXX there are some arcane controller/mouse combinations out
- * there, which hung the controller unless there is data transmission
- * after ACK from the mouse.
- */
- if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3) {
- printf("psm%d: failed to get status.\n", unit);
- } else {
- /*
- * When in its native mode, some mice operate with different
- * default parameters than in the PS/2 compatible mode.
- */
- sc->dflt_mode.rate = sc->mode.rate = stat[2];
- sc->dflt_mode.resolution = sc->mode.resolution = stat[1];
- }
-
- /* disable the aux port for now... */
- if (!set_controller_command_byte(sc->kbdc,
- KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS,
- (command_byte & KBD_KBD_CONTROL_BITS)
- | KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
- /*
- * this is CONTROLLER ERROR; I don't know the proper way to
- * recover from this error...
- */
- restore_controller(sc->kbdc, command_byte);
- printf("psm%d: unable to set the command byte.\n", unit);
- endprobe(ENXIO);
- }
-
- /* done */
- kbdc_set_device_mask(sc->kbdc, mask | KBD_AUX_CONTROL_BITS);
- kbdc_lock(sc->kbdc, FALSE);
- return (0);
-}
-
-static int
-psmattach(device_t dev)
-{
- int unit = device_get_unit(dev);
- struct psm_softc *sc = device_get_softc(dev);
- int error;
- int rid;
-
- if (sc == NULL) /* shouldn't happen */
- return (ENXIO);
-
- /* Setup initial state */
- sc->state = PSM_VALID;
- callout_handle_init(&sc->callout);
-
- /* Setup our interrupt handler */
- rid = KBDC_RID_AUX;
- sc->intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE | RF_ACTIVE);
- if (sc->intr == NULL)
- return (ENXIO);
- error = bus_setup_intr(dev, sc->intr, INTR_TYPE_TTY, psmintr, sc, &sc->ih);
- if (error) {
- bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
- return (error);
- }
-
- /* Done */
- sc->dev = make_dev(&psm_cdevsw, PSM_MKMINOR(unit, FALSE), 0, 0, 0666,
- "psm%d", unit);
- sc->bdev = make_dev(&psm_cdevsw, PSM_MKMINOR(unit, TRUE), 0, 0, 0666,
- "bpsm%d", unit);
-
- if (!verbose) {
- printf("psm%d: model %s, device ID %d\n",
- unit, model_name(sc->hw.model), sc->hw.hwid & 0x00ff);
- } else {
- printf("psm%d: model %s, device ID %d-%02x, %d buttons\n",
- unit, model_name(sc->hw.model),
- sc->hw.hwid & 0x00ff, sc->hw.hwid >> 8, sc->hw.buttons);
- printf("psm%d: config:%08x, flags:%08x, packet size:%d\n",
- unit, sc->config, sc->flags, sc->mode.packetsize);
- printf("psm%d: syncmask:%02x, syncbits:%02x\n",
- unit, sc->mode.syncmask[0], sc->mode.syncmask[1]);
- }
-
- if (bootverbose)
- --verbose;
-
- return (0);
-}
-
-static int
-psmdetach(device_t dev)
-{
- struct psm_softc *sc;
- int rid;
-
- sc = device_get_softc(dev);
- if (sc->state & PSM_OPEN)
- return EBUSY;
-
- rid = KBDC_RID_AUX;
- bus_teardown_intr(dev, sc->intr, sc->ih);
- bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
-
- destroy_dev(sc->dev);
- destroy_dev(sc->bdev);
-
- return 0;
-}
-
-static int
-psmopen(dev_t dev, int flag, int fmt, struct thread *td)
-{
- int unit = PSM_UNIT(dev);
- struct psm_softc *sc;
- int command_byte;
- int err;
- int s;
-
- /* Get device data */
- sc = PSM_SOFTC(unit);
- if ((sc == NULL) || (sc->state & PSM_VALID) == 0)
- /* the device is no longer valid/functioning */
- return (ENXIO);
-
- /* Disallow multiple opens */
- if (sc->state & PSM_OPEN)
- return (EBUSY);
-
- device_busy(devclass_get_device(psm_devclass, unit));
-
- /* Initialize state */
- sc->mode.level = sc->dflt_mode.level;
- sc->mode.protocol = sc->dflt_mode.protocol;
- sc->watchdog = FALSE;
-
- /* flush the event queue */
- sc->queue.count = 0;
- sc->queue.head = 0;
- sc->queue.tail = 0;
- sc->status.flags = 0;
- sc->status.button = 0;
- sc->status.obutton = 0;
- sc->status.dx = 0;
- sc->status.dy = 0;
- sc->status.dz = 0;
- sc->button = 0;
-
- /* empty input buffer */
- bzero(sc->ipacket, sizeof(sc->ipacket));
- sc->inputbytes = 0;
- sc->syncerrors = 0;
-
- /* don't let timeout routines in the keyboard driver to poll the kbdc */
- if (!kbdc_lock(sc->kbdc, TRUE))
- return (EIO);
-
- /* save the current controller command byte */
- s = spltty();
- command_byte = get_controller_command_byte(sc->kbdc);
-
- /* enable the aux port and temporalily disable the keyboard */
- if ((command_byte == -1)
- || !set_controller_command_byte(sc->kbdc,
- kbdc_get_device_mask(sc->kbdc),
- KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT
- | KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
- /* CONTROLLER ERROR; do you know how to get out of this? */
- kbdc_lock(sc->kbdc, FALSE);
- splx(s);
- log(LOG_ERR, "psm%d: unable to set the command byte (psmopen).\n",
- unit);
- return (EIO);
- }
- /*
- * Now that the keyboard controller is told not to generate
- * the keyboard and mouse interrupts, call `splx()' to allow
- * the other tty interrupts. The clock interrupt may also occur,
- * but timeout routines will be blocked by the poll flag set
- * via `kbdc_lock()'
- */
- splx(s);
-
- /* enable the mouse device */
- err = doopen(sc, command_byte);
-
- /* done */
- if (err == 0)
- sc->state |= PSM_OPEN;
- kbdc_lock(sc->kbdc, FALSE);
- return (err);
-}
-
-static int
-psmclose(dev_t dev, int flag, int fmt, struct thread *td)
-{
- int unit = PSM_UNIT(dev);
- struct psm_softc *sc = PSM_SOFTC(unit);
- int stat[3];
- int command_byte;
- int s;
-
- /* don't let timeout routines in the keyboard driver to poll the kbdc */
- if (!kbdc_lock(sc->kbdc, TRUE))
- return (EIO);
-
- /* save the current controller command byte */
- s = spltty();
- command_byte = get_controller_command_byte(sc->kbdc);
- if (command_byte == -1) {
- kbdc_lock(sc->kbdc, FALSE);
- splx(s);
- return (EIO);
- }
-
- /* disable the aux interrupt and temporalily disable the keyboard */
- if (!set_controller_command_byte(sc->kbdc,
- kbdc_get_device_mask(sc->kbdc),
- KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT
- | KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
- log(LOG_ERR, "psm%d: failed to disable the aux int (psmclose).\n",
- unit);
- /* CONTROLLER ERROR;
- * NOTE: we shall force our way through. Because the only
- * ill effect we shall see is that we may not be able
- * to read ACK from the mouse, and it doesn't matter much
- * so long as the mouse will accept the DISABLE command.
- */
- }
- splx(s);
-
- /* stop the watchdog timer */
- untimeout(psmtimeout, (void *)(uintptr_t)sc, sc->callout);
- callout_handle_init(&sc->callout);
-
- /* remove anything left in the output buffer */
- empty_aux_buffer(sc->kbdc, 10);
-
- /* disable the aux device, port and interrupt */
- if (sc->state & PSM_VALID) {
- if (!disable_aux_dev(sc->kbdc)) {
- /* MOUSE ERROR;
- * NOTE: we don't return error and continue, pretending
- * we have successfully disabled the device. It's OK because
- * the interrupt routine will discard any data from the mouse
- * hereafter.
- */
- log(LOG_ERR, "psm%d: failed to disable the device (psmclose).\n",
- unit);
- }
-
- if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3)
- log(LOG_DEBUG, "psm%d: failed to get status (psmclose).\n",
- unit);
- }
-
- if (!set_controller_command_byte(sc->kbdc,
- kbdc_get_device_mask(sc->kbdc),
- (command_byte & KBD_KBD_CONTROL_BITS)
- | KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
- /* CONTROLLER ERROR;
- * we shall ignore this error; see the above comment.
- */
- log(LOG_ERR, "psm%d: failed to disable the aux port (psmclose).\n",
- unit);
- }
-
- /* remove anything left in the output buffer */
- empty_aux_buffer(sc->kbdc, 10);
-
- /* close is almost always successful */
- sc->state &= ~PSM_OPEN;
- kbdc_lock(sc->kbdc, FALSE);
- device_unbusy(devclass_get_device(psm_devclass, unit));
- return (0);
-}
-
-static int
-tame_mouse(struct psm_softc *sc, mousestatus_t *status, unsigned char *buf)
-{
- static unsigned char butmapps2[8] = {
- 0,
- MOUSE_PS2_BUTTON1DOWN,
- MOUSE_PS2_BUTTON2DOWN,
- MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON2DOWN,
- MOUSE_PS2_BUTTON3DOWN,
- MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON3DOWN,
- MOUSE_PS2_BUTTON2DOWN | MOUSE_PS2_BUTTON3DOWN,
- MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON2DOWN | MOUSE_PS2_BUTTON3DOWN,
- };
- static unsigned char butmapmsc[8] = {
- MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
- MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
- MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON3UP,
- MOUSE_MSC_BUTTON3UP,
- MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP,
- MOUSE_MSC_BUTTON2UP,
- MOUSE_MSC_BUTTON1UP,
- 0,
- };
- int mapped;
- int i;
-
- if (sc->mode.level == PSM_LEVEL_BASE) {
- mapped = status->button & ~MOUSE_BUTTON4DOWN;
- if (status->button & MOUSE_BUTTON4DOWN)
- mapped |= MOUSE_BUTTON1DOWN;
- status->button = mapped;
- buf[0] = MOUSE_PS2_SYNC | butmapps2[mapped & MOUSE_STDBUTTONS];
- i = imax(imin(status->dx, 255), -256);
- if (i < 0)
- buf[0] |= MOUSE_PS2_XNEG;
- buf[1] = i;
- i = imax(imin(status->dy, 255), -256);
- if (i < 0)
- buf[0] |= MOUSE_PS2_YNEG;
- buf[2] = i;
- return MOUSE_PS2_PACKETSIZE;
- } else if (sc->mode.level == PSM_LEVEL_STANDARD) {
- buf[0] = MOUSE_MSC_SYNC | butmapmsc[status->button & MOUSE_STDBUTTONS];
- i = imax(imin(status->dx, 255), -256);
- buf[1] = i >> 1;
- buf[3] = i - buf[1];
- i = imax(imin(status->dy, 255), -256);
- buf[2] = i >> 1;
- buf[4] = i - buf[2];
- i = imax(imin(status->dz, 127), -128);
- buf[5] = (i >> 1) & 0x7f;
- buf[6] = (i - (i >> 1)) & 0x7f;
- buf[7] = (~status->button >> 3) & 0x7f;
- return MOUSE_SYS_PACKETSIZE;
- }
- return sc->inputbytes;;
-}
-
-static int
-psmread(dev_t dev, struct uio *uio, int flag)
-{
- register struct psm_softc *sc = PSM_SOFTC(PSM_UNIT(dev));
- unsigned char buf[PSM_SMALLBUFSIZE];
- int error = 0;
- int s;
- int l;
-
- if ((sc->state & PSM_VALID) == 0)
- return EIO;
-
- /* block until mouse activity occured */
- s = spltty();
- while (sc->queue.count <= 0) {
- if (PSM_NBLOCKIO(dev)) {
- splx(s);
- return EWOULDBLOCK;
- }
- sc->state |= PSM_ASLP;
- error = tsleep( sc, PZERO | PCATCH, "psmrea", 0);
- sc->state &= ~PSM_ASLP;
- if (error) {
- splx(s);
- return error;
- } else if ((sc->state & PSM_VALID) == 0) {
- /* the device disappeared! */
- splx(s);
- return EIO;
- }
- }
- splx(s);
-
- /* copy data to the user land */
- while ((sc->queue.count > 0) && (uio->uio_resid > 0)) {
- s = spltty();
- l = imin(sc->queue.count, uio->uio_resid);
- if (l > sizeof(buf))
- l = sizeof(buf);
- if (l > sizeof(sc->queue.buf) - sc->queue.head) {
- bcopy(&sc->queue.buf[sc->queue.head], &buf[0],
- sizeof(sc->queue.buf) - sc->queue.head);
- bcopy(&sc->queue.buf[0],
- &buf[sizeof(sc->queue.buf) - sc->queue.head],
- l - (sizeof(sc->queue.buf) - sc->queue.head));
- } else {
- bcopy(&sc->queue.buf[sc->queue.head], &buf[0], l);
- }
- sc->queue.count -= l;
- sc->queue.head = (sc->queue.head + l) % sizeof(sc->queue.buf);
- splx(s);
- error = uiomove(buf, l, uio);
- if (error)
- break;
- }
-
- return error;
-}
-
-static int
-block_mouse_data(struct psm_softc *sc, int *c)
-{
- int s;
-
- if (!kbdc_lock(sc->kbdc, TRUE))
- return EIO;
-
- s = spltty();
- *c = get_controller_command_byte(sc->kbdc);
- if ((*c == -1)
- || !set_controller_command_byte(sc->kbdc,
- kbdc_get_device_mask(sc->kbdc),
- KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT
- | KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
- /* this is CONTROLLER ERROR */
- splx(s);
- kbdc_lock(sc->kbdc, FALSE);
- return EIO;
- }
-
- /*
- * The device may be in the middle of status data transmission.
- * The transmission will be interrupted, thus, incomplete status
- * data must be discarded. Although the aux interrupt is disabled
- * at the keyboard controller level, at most one aux interrupt
- * may have already been pending and a data byte is in the
- * output buffer; throw it away. Note that the second argument
- * to `empty_aux_buffer()' is zero, so that the call will just
- * flush the internal queue.
- * `psmintr()' will be invoked after `splx()' if an interrupt is
- * pending; it will see no data and returns immediately.
- */
- empty_aux_buffer(sc->kbdc, 0); /* flush the queue */
- read_aux_data_no_wait(sc->kbdc); /* throw away data if any */
- sc->inputbytes = 0;
- splx(s);
-
- return 0;
-}
-
-static int
-unblock_mouse_data(struct psm_softc *sc, int c)
-{
- int error = 0;
-
- /*
- * We may have seen a part of status data during `set_mouse_XXX()'.
- * they have been queued; flush it.
- */
- empty_aux_buffer(sc->kbdc, 0);
-
- /* restore ports and interrupt */
- if (!set_controller_command_byte(sc->kbdc,
- kbdc_get_device_mask(sc->kbdc),
- c & (KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS))) {
- /* CONTROLLER ERROR; this is serious, we may have
- * been left with the inaccessible keyboard and
- * the disabled mouse interrupt.
- */
- error = EIO;
- }
-
- kbdc_lock(sc->kbdc, FALSE);
- return error;
-}
-
-static int
-psmioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
-{
- struct psm_softc *sc = PSM_SOFTC(PSM_UNIT(dev));
- mousemode_t mode;
- mousestatus_t status;
-#if (defined(MOUSE_GETVARS))
- mousevar_t *var;
-#endif
- mousedata_t *data;
- int stat[3];
- int command_byte;
- int error = 0;
- int s;
-
- /* Perform IOCTL command */
- switch (cmd) {
-
- case OLD_MOUSE_GETHWINFO:
- s = spltty();
- ((old_mousehw_t *)addr)->buttons = sc->hw.buttons;
- ((old_mousehw_t *)addr)->iftype = sc->hw.iftype;
- ((old_mousehw_t *)addr)->type = sc->hw.type;
- ((old_mousehw_t *)addr)->hwid = sc->hw.hwid & 0x00ff;
- splx(s);
- break;
-
- case MOUSE_GETHWINFO:
- s = spltty();
- *(mousehw_t *)addr = sc->hw;
- if (sc->mode.level == PSM_LEVEL_BASE)
- ((mousehw_t *)addr)->model = MOUSE_MODEL_GENERIC;
- splx(s);
- break;
-
- case OLD_MOUSE_GETMODE:
- s = spltty();
- switch (sc->mode.level) {
- case PSM_LEVEL_BASE:
- ((old_mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
- break;
- case PSM_LEVEL_STANDARD:
- ((old_mousemode_t *)addr)->protocol = MOUSE_PROTO_SYSMOUSE;
- break;
- case PSM_LEVEL_NATIVE:
- ((old_mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
- break;
- }
- ((old_mousemode_t *)addr)->rate = sc->mode.rate;
- ((old_mousemode_t *)addr)->resolution = sc->mode.resolution;
- ((old_mousemode_t *)addr)->accelfactor = sc->mode.accelfactor;
- splx(s);
- break;
-
- case MOUSE_GETMODE:
- s = spltty();
- *(mousemode_t *)addr = sc->mode;
- ((mousemode_t *)addr)->resolution =
- MOUSE_RES_LOW - sc->mode.resolution;
- switch (sc->mode.level) {
- case PSM_LEVEL_BASE:
- ((mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
- ((mousemode_t *)addr)->packetsize = MOUSE_PS2_PACKETSIZE;
- break;
- case PSM_LEVEL_STANDARD:
- ((mousemode_t *)addr)->protocol = MOUSE_PROTO_SYSMOUSE;
- ((mousemode_t *)addr)->packetsize = MOUSE_SYS_PACKETSIZE;
- ((mousemode_t *)addr)->syncmask[0] = MOUSE_SYS_SYNCMASK;
- ((mousemode_t *)addr)->syncmask[1] = MOUSE_SYS_SYNC;
- break;
- case PSM_LEVEL_NATIVE:
- /* FIXME: this isn't quite correct... XXX */
- ((mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
- break;
- }
- splx(s);
- break;
-
- case OLD_MOUSE_SETMODE:
- case MOUSE_SETMODE:
- if (cmd == OLD_MOUSE_SETMODE) {
- mode.rate = ((old_mousemode_t *)addr)->rate;
- /*
- * resolution old I/F new I/F
- * default 0 0
- * low 1 -2
- * medium low 2 -3
- * medium high 3 -4
- * high 4 -5
- */
- if (((old_mousemode_t *)addr)->resolution > 0)
- mode.resolution = -((old_mousemode_t *)addr)->resolution - 1;
- mode.accelfactor = ((old_mousemode_t *)addr)->accelfactor;
- mode.level = -1;
- } else {
- mode = *(mousemode_t *)addr;
- }
-
- /* adjust and validate parameters. */
- if (mode.rate > UCHAR_MAX)
- return EINVAL;
- if (mode.rate == 0)
- mode.rate = sc->dflt_mode.rate;
- else if (mode.rate == -1)
- /* don't change the current setting */
- ;
- else if (mode.rate < 0)
- return EINVAL;
- if (mode.resolution >= UCHAR_MAX)
- return EINVAL;
- if (mode.resolution >= 200)
- mode.resolution = MOUSE_RES_HIGH;
- else if (mode.resolution >= 100)
- mode.resolution = MOUSE_RES_MEDIUMHIGH;
- else if (mode.resolution >= 50)
- mode.resolution = MOUSE_RES_MEDIUMLOW;
- else if (mode.resolution > 0)
- mode.resolution = MOUSE_RES_LOW;
- if (mode.resolution == MOUSE_RES_DEFAULT)
- mode.resolution = sc->dflt_mode.resolution;
- else if (mode.resolution == -1)
- /* don't change the current setting */
- ;
- else if (mode.resolution < 0) /* MOUSE_RES_LOW/MEDIUM/HIGH */
- mode.resolution = MOUSE_RES_LOW - mode.resolution;
- if (mode.level == -1)
- /* don't change the current setting */
- mode.level = sc->mode.level;
- else if ((mode.level < PSM_LEVEL_MIN) || (mode.level > PSM_LEVEL_MAX))
- return EINVAL;
- if (mode.accelfactor == -1)
- /* don't change the current setting */
- mode.accelfactor = sc->mode.accelfactor;
- else if (mode.accelfactor < 0)
- return EINVAL;
-
- /* don't allow anybody to poll the keyboard controller */
- error = block_mouse_data(sc, &command_byte);
- if (error)
- return error;
-
- /* set mouse parameters */
- if (mode.rate > 0)
- mode.rate = set_mouse_sampling_rate(sc->kbdc, mode.rate);
- if (mode.resolution >= 0)
- mode.resolution = set_mouse_resolution(sc->kbdc, mode.resolution);
- set_mouse_scaling(sc->kbdc, 1);
- get_mouse_status(sc->kbdc, stat, 0, 3);
-
- s = spltty();
- sc->mode.rate = mode.rate;
- sc->mode.resolution = mode.resolution;
- sc->mode.accelfactor = mode.accelfactor;
- sc->mode.level = mode.level;
- splx(s);
-
- unblock_mouse_data(sc, command_byte);
- break;
-
- case MOUSE_GETLEVEL:
- *(int *)addr = sc->mode.level;
- break;
-
- case MOUSE_SETLEVEL:
- if ((*(int *)addr < PSM_LEVEL_MIN) || (*(int *)addr > PSM_LEVEL_MAX))
- return EINVAL;
- sc->mode.level = *(int *)addr;
- break;
-
- case MOUSE_GETSTATUS:
- s = spltty();
- status = sc->status;
- sc->status.flags = 0;
- sc->status.obutton = sc->status.button;
- sc->status.button = 0;
- sc->status.dx = 0;
- sc->status.dy = 0;
- sc->status.dz = 0;
- splx(s);
- *(mousestatus_t *)addr = status;
- break;
-
-#if (defined(MOUSE_GETVARS))
- case MOUSE_GETVARS:
- var = (mousevar_t *)addr;
- bzero(var, sizeof(*var));
- s = spltty();
- var->var[0] = MOUSE_VARS_PS2_SIG;
- var->var[1] = sc->config;
- var->var[2] = sc->flags;
- splx(s);
- break;
-
- case MOUSE_SETVARS:
- return ENODEV;
-#endif /* MOUSE_GETVARS */
-
- case MOUSE_READSTATE:
- case MOUSE_READDATA:
- data = (mousedata_t *)addr;
- if (data->len > sizeof(data->buf)/sizeof(data->buf[0]))
- return EINVAL;
-
- error = block_mouse_data(sc, &command_byte);
- if (error)
- return error;
- if ((data->len = get_mouse_status(sc->kbdc, data->buf,
- (cmd == MOUSE_READDATA) ? 1 : 0, data->len)) <= 0)
- error = EIO;
- unblock_mouse_data(sc, command_byte);
- break;
-
-#if (defined(MOUSE_SETRESOLUTION))
- case MOUSE_SETRESOLUTION:
- mode.resolution = *(int *)addr;
- if (mode.resolution >= UCHAR_MAX)
- return EINVAL;
- else if (mode.resolution >= 200)
- mode.resolution = MOUSE_RES_HIGH;
- else if (mode.resolution >= 100)
- mode.resolution = MOUSE_RES_MEDIUMHIGH;
- else if (mode.resolution >= 50)
- mode.resolution = MOUSE_RES_MEDIUMLOW;
- else if (mode.resolution > 0)
- mode.resolution = MOUSE_RES_LOW;
- if (mode.resolution == MOUSE_RES_DEFAULT)
- mode.resolution = sc->dflt_mode.resolution;
- else if (mode.resolution == -1)
- mode.resolution = sc->mode.resolution;
- else if (mode.resolution < 0) /* MOUSE_RES_LOW/MEDIUM/HIGH */
- mode.resolution = MOUSE_RES_LOW - mode.resolution;
-
- error = block_mouse_data(sc, &command_byte);
- if (error)
- return error;
- sc->mode.resolution = set_mouse_resolution(sc->kbdc, mode.resolution);
- if (sc->mode.resolution != mode.resolution)
- error = EIO;
- unblock_mouse_data(sc, command_byte);
- break;
-#endif /* MOUSE_SETRESOLUTION */
-
-#if (defined(MOUSE_SETRATE))
- case MOUSE_SETRATE:
- mode.rate = *(int *)addr;
- if (mode.rate > UCHAR_MAX)
- return EINVAL;
- if (mode.rate == 0)
- mode.rate = sc->dflt_mode.rate;
- else if (mode.rate < 0)
- mode.rate = sc->mode.rate;
-
- error = block_mouse_data(sc, &command_byte);
- if (error)
- return error;
- sc->mode.rate = set_mouse_sampling_rate(sc->kbdc, mode.rate);
- if (sc->mode.rate != mode.rate)
- error = EIO;
- unblock_mouse_data(sc, command_byte);
- break;
-#endif /* MOUSE_SETRATE */
-
-#if (defined(MOUSE_SETSCALING))
- case MOUSE_SETSCALING:
- if ((*(int *)addr <= 0) || (*(int *)addr > 2))
- return EINVAL;
-
- error = block_mouse_data(sc, &command_byte);
- if (error)
- return error;
- if (!set_mouse_scaling(sc->kbdc, *(int *)addr))
- error = EIO;
- unblock_mouse_data(sc, command_byte);
- break;
-#endif /* MOUSE_SETSCALING */
-
-#if (defined(MOUSE_GETHWID))
- case MOUSE_GETHWID:
- error = block_mouse_data(sc, &command_byte);
- if (error)
- return error;
- sc->hw.hwid &= ~0x00ff;
- sc->hw.hwid |= get_aux_id(sc->kbdc);
- *(int *)addr = sc->hw.hwid & 0x00ff;
- unblock_mouse_data(sc, command_byte);
- break;
-#endif /* MOUSE_GETHWID */
-
- default:
- return ENOTTY;
- }
-
- return error;
-}
-
-static void
-psmtimeout(void *arg)
-{
- struct psm_softc *sc;
- int s;
-
- sc = (struct psm_softc *)arg;
- s = spltty();
- if (sc->watchdog && kbdc_lock(sc->kbdc, TRUE)) {
- if (verbose >= 4)
- log(LOG_DEBUG, "psm%d: lost interrupt?\n", sc->unit);
- psmintr(sc);
- kbdc_lock(sc->kbdc, FALSE);
- }
- sc->watchdog = TRUE;
- splx(s);
- sc->callout = timeout(psmtimeout, (void *)(uintptr_t)sc, hz);
-}
-
-static void
-psmintr(void *arg)
-{
- /*
- * the table to turn PS/2 mouse button bits (MOUSE_PS2_BUTTON?DOWN)
- * into `mousestatus' button bits (MOUSE_BUTTON?DOWN).
- */
- static int butmap[8] = {
- 0,
- MOUSE_BUTTON1DOWN,
- MOUSE_BUTTON3DOWN,
- MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN,
- MOUSE_BUTTON2DOWN,
- MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN,
- MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN,
- MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN
- };
- static int butmap_versapad[8] = {
- 0,
- MOUSE_BUTTON3DOWN,
- 0,
- MOUSE_BUTTON3DOWN,
- MOUSE_BUTTON1DOWN,
- MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN,
- MOUSE_BUTTON1DOWN,
- MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN
- };
- register struct psm_softc *sc = arg;
- mousestatus_t ms;
- struct timeval tv;
- int x, y, z;
- int c;
- int l;
- int x0, y0;
-
- /* read until there is nothing to read */
- while((c = read_aux_data_no_wait(sc->kbdc)) != -1) {
-
- /* discard the byte if the device is not open */
- if ((sc->state & PSM_OPEN) == 0)
- continue;
-
- getmicrouptime(&tv);
- if ((sc->inputbytes > 0) && timevalcmp(&tv, &sc->inputtimeout, >)) {
- log(LOG_DEBUG, "psmintr: delay too long; resetting byte count\n");
- sc->inputbytes = 0;
- sc->syncerrors = 0;
- }
- sc->inputtimeout.tv_sec = PSM_INPUT_TIMEOUT/1000000;
- sc->inputtimeout.tv_usec = PSM_INPUT_TIMEOUT%1000000;
- timevaladd(&sc->inputtimeout, &tv);
-
- sc->ipacket[sc->inputbytes++] = c;
- if (sc->inputbytes < sc->mode.packetsize)
- continue;
-
-#if 0
- log(LOG_DEBUG, "psmintr: %02x %02x %02x %02x %02x %02x\n",
- sc->ipacket[0], sc->ipacket[1], sc->ipacket[2],
- sc->ipacket[3], sc->ipacket[4], sc->ipacket[5]);
-#endif
-
- c = sc->ipacket[0];
-
- if ((c & sc->mode.syncmask[0]) != sc->mode.syncmask[1]) {
- log(LOG_DEBUG, "psmintr: out of sync (%04x != %04x).\n",
- c & sc->mode.syncmask[0], sc->mode.syncmask[1]);
- ++sc->syncerrors;
- if (sc->syncerrors < sc->mode.packetsize) {
- log(LOG_DEBUG, "psmintr: discard a byte (%d).\n", sc->syncerrors);
- --sc->inputbytes;
- bcopy(&sc->ipacket[1], &sc->ipacket[0], sc->inputbytes);
- } else if (sc->syncerrors == sc->mode.packetsize) {
- log(LOG_DEBUG, "psmintr: re-enable the mouse.\n");
- sc->inputbytes = 0;
- disable_aux_dev(sc->kbdc);
- enable_aux_dev(sc->kbdc);
- } else if (sc->syncerrors < PSM_SYNCERR_THRESHOLD1) {
- log(LOG_DEBUG, "psmintr: discard a byte (%d).\n", sc->syncerrors);
- --sc->inputbytes;
- bcopy(&sc->ipacket[1], &sc->ipacket[0], sc->inputbytes);
- } else if (sc->syncerrors >= PSM_SYNCERR_THRESHOLD1) {
- log(LOG_DEBUG, "psmintr: reset the mouse.\n");
- reinitialize(sc, TRUE);
- }
- continue;
- }
-
- /*
- * A kludge for Kensington device!
- * The MSB of the horizontal count appears to be stored in
- * a strange place.
- */
- if (sc->hw.model == MOUSE_MODEL_THINK)
- sc->ipacket[1] |= (c & MOUSE_PS2_XOVERFLOW) ? 0x80 : 0;
-
- /* ignore the overflow bits... */
- x = (c & MOUSE_PS2_XNEG) ? sc->ipacket[1] - 256 : sc->ipacket[1];
- y = (c & MOUSE_PS2_YNEG) ? sc->ipacket[2] - 256 : sc->ipacket[2];
- z = 0;
- ms.obutton = sc->button; /* previous button state */
- ms.button = butmap[c & MOUSE_PS2_BUTTONS];
- /* `tapping' action */
- if (sc->config & PSM_CONFIG_FORCETAP)
- ms.button |= ((c & MOUSE_PS2_TAP)) ? 0 : MOUSE_BUTTON4DOWN;
-
- switch (sc->hw.model) {
-
- case MOUSE_MODEL_EXPLORER:
- /*
- * b7 b6 b5 b4 b3 b2 b1 b0
- * byte 1: oy ox sy sx 1 M R L
- * byte 2: x x x x x x x x
- * byte 3: y y y y y y y y
- * byte 4: * * S2 S1 s d2 d1 d0
- *
- * L, M, R, S1, S2: left, middle, right and side buttons
- * s: wheel data sign bit
- * d2-d0: wheel data
- */
- z = (sc->ipacket[3] & MOUSE_EXPLORER_ZNEG)
- ? (sc->ipacket[3] & 0x0f) - 16 : (sc->ipacket[3] & 0x0f);
- ms.button |= (sc->ipacket[3] & MOUSE_EXPLORER_BUTTON4DOWN)
- ? MOUSE_BUTTON4DOWN : 0;
- ms.button |= (sc->ipacket[3] & MOUSE_EXPLORER_BUTTON5DOWN)
- ? MOUSE_BUTTON5DOWN : 0;
- break;
-
- case MOUSE_MODEL_INTELLI:
- case MOUSE_MODEL_NET:
- /* wheel data is in the fourth byte */
- z = (char)sc->ipacket[3];
- /* some mice may send 7 when there is no Z movement?! XXX */
- if ((z >= 7) || (z <= -7))
- z = 0;
- /* some compatible mice have additional buttons */
- ms.button |= (c & MOUSE_PS2INTELLI_BUTTON4DOWN)
- ? MOUSE_BUTTON4DOWN : 0;
- ms.button |= (c & MOUSE_PS2INTELLI_BUTTON5DOWN)
- ? MOUSE_BUTTON5DOWN : 0;
- break;
-
- case MOUSE_MODEL_MOUSEMANPLUS:
- /*
- * PS2++ protocl packet
- *
- * b7 b6 b5 b4 b3 b2 b1 b0
- * byte 1: * 1 p3 p2 1 * * *
- * byte 2: c1 c2 p1 p0 d1 d0 1 0
- *
- * p3-p0: packet type
- * c1, c2: c1 & c2 == 1, if p2 == 0
- * c1 & c2 == 0, if p2 == 1
- *
- * packet type: 0 (device type)
- * See comments in enable_mmanplus() below.
- *
- * packet type: 1 (wheel data)
- *
- * b7 b6 b5 b4 b3 b2 b1 b0
- * byte 3: h * B5 B4 s d2 d1 d0
- *
- * h: 1, if horizontal roller data
- * 0, if vertical roller data
- * B4, B5: button 4 and 5
- * s: sign bit
- * d2-d0: roller data
- *
- * packet type: 2 (reserved)
- */
- if (((c & MOUSE_PS2PLUS_SYNCMASK) == MOUSE_PS2PLUS_SYNC)
- && (abs(x) > 191)
- && MOUSE_PS2PLUS_CHECKBITS(sc->ipacket)) {
- /* the extended data packet encodes button and wheel events */
- switch (MOUSE_PS2PLUS_PACKET_TYPE(sc->ipacket)) {
- case 1:
- /* wheel data packet */
- x = y = 0;
- if (sc->ipacket[2] & 0x80) {
- /* horizontal roller count - ignore it XXX*/
- } else {
- /* vertical roller count */
- z = (sc->ipacket[2] & MOUSE_PS2PLUS_ZNEG)
- ? (sc->ipacket[2] & 0x0f) - 16
- : (sc->ipacket[2] & 0x0f);
- }
- ms.button |= (sc->ipacket[2] & MOUSE_PS2PLUS_BUTTON4DOWN)
- ? MOUSE_BUTTON4DOWN : 0;
- ms.button |= (sc->ipacket[2] & MOUSE_PS2PLUS_BUTTON5DOWN)
- ? MOUSE_BUTTON5DOWN : 0;
- break;
- case 2:
- /* this packet type is reserved by Logitech... */
- /*
- * IBM ScrollPoint Mouse uses this packet type to
- * encode both vertical and horizontal scroll movement.
- */
- x = y = 0;
- /* horizontal count */
- if (sc->ipacket[2] & 0x0f)
- z = (sc->ipacket[2] & MOUSE_SPOINT_WNEG) ? -2 : 2;
- /* vertical count */
- if (sc->ipacket[2] & 0xf0)
- z = (sc->ipacket[2] & MOUSE_SPOINT_ZNEG) ? -1 : 1;
-#if 0
- /* vertical count */
- z = (sc->ipacket[2] & MOUSE_SPOINT_ZNEG)
- ? ((sc->ipacket[2] >> 4) & 0x0f) - 16
- : ((sc->ipacket[2] >> 4) & 0x0f);
- /* horizontal count */
- w = (sc->ipacket[2] & MOUSE_SPOINT_WNEG)
- ? (sc->ipacket[2] & 0x0f) - 16
- : (sc->ipacket[2] & 0x0f);
-#endif
- break;
- case 0:
- /* device type packet - shouldn't happen */
- /* FALLTHROUGH */
- default:
- x = y = 0;
- ms.button = ms.obutton;
- if (bootverbose)
- log(LOG_DEBUG, "psmintr: unknown PS2++ packet type %d: "
- "0x%02x 0x%02x 0x%02x\n",
- MOUSE_PS2PLUS_PACKET_TYPE(sc->ipacket),
- sc->ipacket[0], sc->ipacket[1], sc->ipacket[2]);
- break;
- }
- } else {
- /* preserve button states */
- ms.button |= ms.obutton & MOUSE_EXTBUTTONS;
- }
- break;
-
- case MOUSE_MODEL_GLIDEPOINT:
- /* `tapping' action */
- ms.button |= ((c & MOUSE_PS2_TAP)) ? 0 : MOUSE_BUTTON4DOWN;
- break;
-
- case MOUSE_MODEL_NETSCROLL:
- /* three addtional bytes encode buttons and wheel events */
- ms.button |= (sc->ipacket[3] & MOUSE_PS2_BUTTON3DOWN)
- ? MOUSE_BUTTON4DOWN : 0;
- ms.button |= (sc->ipacket[3] & MOUSE_PS2_BUTTON1DOWN)
- ? MOUSE_BUTTON5DOWN : 0;
- z = (sc->ipacket[3] & MOUSE_PS2_XNEG)
- ? sc->ipacket[4] - 256 : sc->ipacket[4];
- break;
-
- case MOUSE_MODEL_THINK:
- /* the fourth button state in the first byte */
- ms.button |= (c & MOUSE_PS2_TAP) ? MOUSE_BUTTON4DOWN : 0;
- break;
-
- case MOUSE_MODEL_VERSAPAD:
- /* VersaPad PS/2 absolute mode message format
- *
- * [packet1] 7 6 5 4 3 2 1 0(LSB)
- * ipacket[0]: 1 1 0 A 1 L T R
- * ipacket[1]: H7 H6 H5 H4 H3 H2 H1 H0
- * ipacket[2]: V7 V6 V5 V4 V3 V2 V1 V0
- * ipacket[3]: 1 1 1 A 1 L T R
- * ipacket[4]:V11 V10 V9 V8 H11 H10 H9 H8
- * ipacket[5]: 0 P6 P5 P4 P3 P2 P1 P0
- *
- * [note]
- * R: right physical mouse button (1=on)
- * T: touch pad virtual button (1=tapping)
- * L: left physical mouse button (1=on)
- * A: position data is valid (1=valid)
- * H: horizontal data (12bit signed integer. H11 is sign bit.)
- * V: vertical data (12bit signed integer. V11 is sign bit.)
- * P: pressure data
- *
- * Tapping is mapped to MOUSE_BUTTON4.
- */
- ms.button = butmap_versapad[c & MOUSE_PS2VERSA_BUTTONS];
- ms.button |= (c & MOUSE_PS2VERSA_TAP) ? MOUSE_BUTTON4DOWN : 0;
- x = y = 0;
- if (c & MOUSE_PS2VERSA_IN_USE) {
- x0 = sc->ipacket[1] | (((sc->ipacket[4]) & 0x0f) << 8);
- y0 = sc->ipacket[2] | (((sc->ipacket[4]) & 0xf0) << 4);
- if (x0 & 0x800)
- x0 -= 0x1000;
- if (y0 & 0x800)
- y0 -= 0x1000;
- if (sc->flags & PSM_FLAGS_FINGERDOWN) {
- x = sc->xold - x0;
- y = y0 - sc->yold;
- if (x < 0) /* XXX */
- x++;
- else if (x)
- x--;
- if (y < 0)
- y++;
- else if (y)
- y--;
- } else {
- sc->flags |= PSM_FLAGS_FINGERDOWN;
- }
- sc->xold = x0;
- sc->yold = y0;
- } else {
- sc->flags &= ~PSM_FLAGS_FINGERDOWN;
- }
- c = ((x < 0) ? MOUSE_PS2_XNEG : 0)
- | ((y < 0) ? MOUSE_PS2_YNEG : 0);
- break;
-
- case MOUSE_MODEL_4D:
- /*
- * b7 b6 b5 b4 b3 b2 b1 b0
- * byte 1: s2 d2 s1 d1 1 M R L
- * byte 2: sx x x x x x x x
- * byte 3: sy y y y y y y y
- *
- * s1: wheel 1 direction
- * d1: wheel 1 data
- * s2: wheel 2 direction
- * d2: wheel 2 data
- */
- x = (sc->ipacket[1] & 0x80) ? sc->ipacket[1] - 256 : sc->ipacket[1];
- y = (sc->ipacket[2] & 0x80) ? sc->ipacket[2] - 256 : sc->ipacket[2];
- switch (c & MOUSE_4D_WHEELBITS) {
- case 0x10:
- z = 1;
- break;
- case 0x30:
- z = -1;
- break;
- case 0x40: /* 2nd wheel turning right XXX */
- z = 2;
- break;
- case 0xc0: /* 2nd wheel turning left XXX */
- z = -2;
- break;
- }
- break;
-
- case MOUSE_MODEL_4DPLUS:
- if ((x < 16 - 256) && (y < 16 - 256)) {
- /*
- * b7 b6 b5 b4 b3 b2 b1 b0
- * byte 1: 0 0 1 1 1 M R L
- * byte 2: 0 0 0 0 1 0 0 0
- * byte 3: 0 0 0 0 S s d1 d0
- *
- * L, M, R, S: left, middle, right and side buttons
- * s: wheel data sign bit
- * d1-d0: wheel data
- */
- x = y = 0;
- if (sc->ipacket[2] & MOUSE_4DPLUS_BUTTON4DOWN)
- ms.button |= MOUSE_BUTTON4DOWN;
- z = (sc->ipacket[2] & MOUSE_4DPLUS_ZNEG)
- ? ((sc->ipacket[2] & 0x07) - 8)
- : (sc->ipacket[2] & 0x07) ;
- } else {
- /* preserve previous button states */
- ms.button |= ms.obutton & MOUSE_EXTBUTTONS;
- }
- break;
-
- case MOUSE_MODEL_GENERIC:
- default:
- break;
- }
-
- /* scale values */
- if (sc->mode.accelfactor >= 1) {
- if (x != 0) {
- x = x * x / sc->mode.accelfactor;
- if (x == 0)
- x = 1;
- if (c & MOUSE_PS2_XNEG)
- x = -x;
- }
- if (y != 0) {
- y = y * y / sc->mode.accelfactor;
- if (y == 0)
- y = 1;
- if (c & MOUSE_PS2_YNEG)
- y = -y;
- }
- }
-
- ms.dx = x;
- ms.dy = y;
- ms.dz = z;
- ms.flags = ((x || y || z) ? MOUSE_POSCHANGED : 0)
- | (ms.obutton ^ ms.button);
-
- if (sc->mode.level < PSM_LEVEL_NATIVE)
- sc->inputbytes = tame_mouse(sc, &ms, sc->ipacket);
-
- sc->status.flags |= ms.flags;
- sc->status.dx += ms.dx;
- sc->status.dy += ms.dy;
- sc->status.dz += ms.dz;
- sc->status.button = ms.button;
- sc->button = ms.button;
-
- sc->watchdog = FALSE;
-
- /* queue data */
- if (sc->queue.count + sc->inputbytes < sizeof(sc->queue.buf)) {
- l = imin(sc->inputbytes, sizeof(sc->queue.buf) - sc->queue.tail);
- bcopy(&sc->ipacket[0], &sc->queue.buf[sc->queue.tail], l);
- if (sc->inputbytes > l)
- bcopy(&sc->ipacket[l], &sc->queue.buf[0], sc->inputbytes - l);
- sc->queue.tail =
- (sc->queue.tail + sc->inputbytes) % sizeof(sc->queue.buf);
- sc->queue.count += sc->inputbytes;
- }
- sc->inputbytes = 0;
-
- if (sc->state & PSM_ASLP) {
- sc->state &= ~PSM_ASLP;
- wakeup( sc);
- }
- selwakeup(&sc->rsel);
- }
-}
-
-static int
-psmpoll(dev_t dev, int events, struct thread *td)
-{
- struct psm_softc *sc = PSM_SOFTC(PSM_UNIT(dev));
- int s;
- int revents = 0;
-
- /* Return true if a mouse event available */
- s = spltty();
- if (events & (POLLIN | POLLRDNORM)) {
- if (sc->queue.count > 0)
- revents |= events & (POLLIN | POLLRDNORM);
- else
- selrecord(td, &sc->rsel);
- }
- splx(s);
-
- return (revents);
-}
-
-/* vendor/model specific routines */
-
-static int mouse_id_proc1(KBDC kbdc, int res, int scale, int *status)
-{
- if (set_mouse_resolution(kbdc, res) != res)
- return FALSE;
- if (set_mouse_scaling(kbdc, scale)
- && set_mouse_scaling(kbdc, scale)
- && set_mouse_scaling(kbdc, scale)
- && (get_mouse_status(kbdc, status, 0, 3) >= 3))
- return TRUE;
- return FALSE;
-}
-
-static int
-mouse_ext_command(KBDC kbdc, int command)
-{
- int c;
-
- c = (command >> 6) & 0x03;
- if (set_mouse_resolution(kbdc, c) != c)
- return FALSE;
- c = (command >> 4) & 0x03;
- if (set_mouse_resolution(kbdc, c) != c)
- return FALSE;
- c = (command >> 2) & 0x03;
- if (set_mouse_resolution(kbdc, c) != c)
- return FALSE;
- c = (command >> 0) & 0x03;
- if (set_mouse_resolution(kbdc, c) != c)
- return FALSE;
- return TRUE;
-}
-
-#if notyet
-/* Logitech MouseMan Cordless II */
-static int
-enable_lcordless(struct psm_softc *sc)
-{
- int status[3];
- int ch;
-
- if (!mouse_id_proc1(sc->kbdc, PSMD_RES_HIGH, 2, status))
- return FALSE;
- if (status[1] == PSMD_RES_HIGH)
- return FALSE;
- ch = (status[0] & 0x07) - 1; /* channel # */
- if ((ch <= 0) || (ch > 4))
- return FALSE;
- /*
- * status[1]: always one?
- * status[2]: battery status? (0-100)
- */
- return TRUE;
-}
-#endif /* notyet */
-
-/* Genius NetScroll Mouse, MouseSystems SmartScroll Mouse */
-static int
-enable_groller(struct psm_softc *sc)
-{
- int status[3];
-
- /*
- * The special sequence to enable the fourth button and the
- * roller. Immediately after this sequence check status bytes.
- * if the mouse is NetScroll, the second and the third bytes are
- * '3' and 'D'.
- */
-
- /*
- * If the mouse is an ordinary PS/2 mouse, the status bytes should
- * look like the following.
- *
- * byte 1 bit 7 always 0
- * bit 6 stream mode (0)
- * bit 5 disabled (0)
- * bit 4 1:1 scaling (0)
- * bit 3 always 0
- * bit 0-2 button status
- * byte 2 resolution (PSMD_RES_HIGH)
- * byte 3 report rate (?)
- */
-
- if (!mouse_id_proc1(sc->kbdc, PSMD_RES_HIGH, 1, status))
- return FALSE;
- if ((status[1] != '3') || (status[2] != 'D'))
- return FALSE;
- /* FIXME: SmartScroll Mouse has 5 buttons! XXX */
- sc->hw.buttons = 4;
- return TRUE;
-}
-
-/* Genius NetMouse/NetMouse Pro, ASCII Mie Mouse, NetScroll Optical */
-static int
-enable_gmouse(struct psm_softc *sc)
-{
- int status[3];
-
- /*
- * The special sequence to enable the middle, "rubber" button.
- * Immediately after this sequence check status bytes.
- * if the mouse is NetMouse, NetMouse Pro, or ASCII MIE Mouse,
- * the second and the third bytes are '3' and 'U'.
- * NOTE: NetMouse reports that it has three buttons although it has
- * two buttons and a rubber button. NetMouse Pro and MIE Mouse
- * say they have three buttons too and they do have a button on the
- * side...
- */
- if (!mouse_id_proc1(sc->kbdc, PSMD_RES_HIGH, 1, status))
- return FALSE;
- if ((status[1] != '3') || (status[2] != 'U'))
- return FALSE;
- return TRUE;
-}
-
-/* ALPS GlidePoint */
-static int
-enable_aglide(struct psm_softc *sc)
-{
- int status[3];
-
- /*
- * The special sequence to obtain ALPS GlidePoint specific
- * information. Immediately after this sequence, status bytes will
- * contain something interesting.
- * NOTE: ALPS produces several models of GlidePoint. Some of those
- * do not respond to this sequence, thus, cannot be detected this way.
- */
- if (set_mouse_sampling_rate(sc->kbdc, 100) != 100)
- return FALSE;
- if (!mouse_id_proc1(sc->kbdc, PSMD_RES_LOW, 2, status))
- return FALSE;
- if ((status[1] == PSMD_RES_LOW) || (status[2] == 100))
- return FALSE;
- return TRUE;
-}
-
-/* Kensington ThinkingMouse/Trackball */
-static int
-enable_kmouse(struct psm_softc *sc)
-{
- static unsigned char rate[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 };
- KBDC kbdc = sc->kbdc;
- int status[3];
- int id1;
- int id2;
- int i;
-
- id1 = get_aux_id(kbdc);
- if (set_mouse_sampling_rate(kbdc, 10) != 10)
- return FALSE;
- /*
- * The device is now in the native mode? It returns a different
- * ID value...
- */
- id2 = get_aux_id(kbdc);
- if ((id1 == id2) || (id2 != 2))
- return FALSE;
-
- if (set_mouse_resolution(kbdc, PSMD_RES_LOW) != PSMD_RES_LOW)
- return FALSE;
-#if PSM_DEBUG >= 2
- /* at this point, resolution is LOW, sampling rate is 10/sec */
- if (get_mouse_status(kbdc, status, 0, 3) < 3)
- return FALSE;
-#endif
-
- /*
- * The special sequence to enable the third and fourth buttons.
- * Otherwise they behave like the first and second buttons.
- */
- for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i) {
- if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
- return FALSE;
- }
-
- /*
- * At this point, the device is using default resolution and
- * sampling rate for the native mode.
- */
- if (get_mouse_status(kbdc, status, 0, 3) < 3)
- return FALSE;
- if ((status[1] == PSMD_RES_LOW) || (status[2] == rate[i - 1]))
- return FALSE;
-
- /* the device appears be enabled by this sequence, diable it for now */
- disable_aux_dev(kbdc);
- empty_aux_buffer(kbdc, 5);
-
- return TRUE;
-}
-
-/* Logitech MouseMan+/FirstMouse+, IBM ScrollPoint Mouse */
-static int
-enable_mmanplus(struct psm_softc *sc)
-{
- KBDC kbdc = sc->kbdc;
- int data[3];
-
- /* the special sequence to enable the fourth button and the roller. */
- /*
- * NOTE: for ScrollPoint to respond correctly, the SET_RESOLUTION
- * must be called exactly three times since the last RESET command
- * before this sequence. XXX
- */
- if (!set_mouse_scaling(kbdc, 1))
- return FALSE;
- if (!mouse_ext_command(kbdc, 0x39) || !mouse_ext_command(kbdc, 0xdb))
- return FALSE;
- if (get_mouse_status(kbdc, data, 1, 3) < 3)
- return FALSE;
-
- /*
- * PS2++ protocl, packet type 0
- *
- * b7 b6 b5 b4 b3 b2 b1 b0
- * byte 1: * 1 p3 p2 1 * * *
- * byte 2: 1 1 p1 p0 m1 m0 1 0
- * byte 3: m7 m6 m5 m4 m3 m2 m1 m0
- *
- * p3-p0: packet type: 0
- * m7-m0: model ID: MouseMan+:0x50, FirstMouse+:0x51, ScrollPoint:0x58...
- */
- /* check constant bits */
- if ((data[0] & MOUSE_PS2PLUS_SYNCMASK) != MOUSE_PS2PLUS_SYNC)
- return FALSE;
- if ((data[1] & 0xc3) != 0xc2)
- return FALSE;
- /* check d3-d0 in byte 2 */
- if (!MOUSE_PS2PLUS_CHECKBITS(data))
- return FALSE;
- /* check p3-p0 */
- if (MOUSE_PS2PLUS_PACKET_TYPE(data) != 0)
- return FALSE;
-
- sc->hw.hwid &= 0x00ff;
- sc->hw.hwid |= data[2] << 8; /* save model ID */
-
- /*
- * MouseMan+ (or FirstMouse+) is now in its native mode, in which
- * the wheel and the fourth button events are encoded in the
- * special data packet. The mouse may be put in the IntelliMouse mode
- * if it is initialized by the IntelliMouse's method.
- */
- return TRUE;
-}
-
-/* MS IntelliMouse Explorer */
-static int
-enable_msexplorer(struct psm_softc *sc)
-{
- static unsigned char rate0[] = { 200, 100, 80, };
- static unsigned char rate1[] = { 200, 200, 80, };
- KBDC kbdc = sc->kbdc;
- int id;
- int i;
-
- /* the special sequence to enable the extra buttons and the roller. */
- for (i = 0; i < sizeof(rate1)/sizeof(rate1[0]); ++i) {
- if (set_mouse_sampling_rate(kbdc, rate1[i]) != rate1[i])
- return FALSE;
- }
- /* the device will give the genuine ID only after the above sequence */
- id = get_aux_id(kbdc);
- if (id != PSM_EXPLORER_ID)
- return FALSE;
-
- sc->hw.hwid = id;
- sc->hw.buttons = 5; /* IntelliMouse Explorer XXX */
-
- /*
- * XXX: this is a kludge to fool some KVM switch products
- * which think they are clever enough to know the 4-byte IntelliMouse
- * protocol, and assume any other protocols use 3-byte packets.
- * They don't convey 4-byte data packets from the IntelliMouse Explorer
- * correctly to the host computer because of this!
- * The following sequence is actually IntelliMouse's "wake up"
- * sequence; it will make the KVM think the mouse is IntelliMouse
- * when it is in fact IntelliMouse Explorer.
- */
- for (i = 0; i < sizeof(rate0)/sizeof(rate0[0]); ++i) {
- if (set_mouse_sampling_rate(kbdc, rate0[i]) != rate0[i])
- break;
- }
- id = get_aux_id(kbdc);
-
- return TRUE;
-}
-
-/* MS IntelliMouse */
-static int
-enable_msintelli(struct psm_softc *sc)
-{
- /*
- * Logitech MouseMan+ and FirstMouse+ will also respond to this
- * probe routine and act like IntelliMouse.
- */
-
- static unsigned char rate[] = { 200, 100, 80, };
- KBDC kbdc = sc->kbdc;
- int id;
- int i;
-
- /* the special sequence to enable the third button and the roller. */
- for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i) {
- if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
- return FALSE;
- }
- /* the device will give the genuine ID only after the above sequence */
- id = get_aux_id(kbdc);
- if (id != PSM_INTELLI_ID)
- return FALSE;
-
- sc->hw.hwid = id;
- sc->hw.buttons = 3;
-
- return TRUE;
-}
-
-/* A4 Tech 4D Mouse */
-static int
-enable_4dmouse(struct psm_softc *sc)
-{
- /*
- * Newer wheel mice from A4 Tech may use the 4D+ protocol.
- */
-
- static unsigned char rate[] = { 200, 100, 80, 60, 40, 20 };
- KBDC kbdc = sc->kbdc;
- int id;
- int i;
-
- for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i) {
- if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
- return FALSE;
- }
- id = get_aux_id(kbdc);
- /*
- * WinEasy 4D, 4 Way Scroll 4D: 6
- * Cable-Free 4D: 8 (4DPLUS)
- * WinBest 4D+, 4 Way Scroll 4D+: 8 (4DPLUS)
- */
- if (id != PSM_4DMOUSE_ID)
- return FALSE;
-
- sc->hw.hwid = id;
- sc->hw.buttons = 3; /* XXX some 4D mice have 4? */
-
- return TRUE;
-}
-
-/* A4 Tech 4D+ Mouse */
-static int
-enable_4dplus(struct psm_softc *sc)
-{
- /*
- * Newer wheel mice from A4 Tech seem to use this protocol.
- * Older models are recognized as either 4D Mouse or IntelliMouse.
- */
- KBDC kbdc = sc->kbdc;
- int id;
-
- /*
- * enable_4dmouse() already issued the following ID sequence...
- static unsigned char rate[] = { 200, 100, 80, 60, 40, 20 };
- int i;
-
- for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i) {
- if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
- return FALSE;
- }
- */
-
- id = get_aux_id(kbdc);
- if (id != PSM_4DPLUS_ID)
- return FALSE;
-
- sc->hw.hwid = id;
- sc->hw.buttons = 4; /* XXX */
-
- return TRUE;
-}
-
-/* Interlink electronics VersaPad */
-static int
-enable_versapad(struct psm_softc *sc)
-{
- KBDC kbdc = sc->kbdc;
- int data[3];
-
- set_mouse_resolution(kbdc, PSMD_RES_MEDIUM_HIGH); /* set res. 2 */
- set_mouse_sampling_rate(kbdc, 100); /* set rate 100 */
- set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
- set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
- set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
- set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
- if (get_mouse_status(kbdc, data, 0, 3) < 3) /* get status */
- return FALSE;
- if (data[2] != 0xa || data[1] != 0 ) /* rate == 0xa && res. == 0 */
- return FALSE;
- set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
-
- sc->config |= PSM_CONFIG_HOOKRESUME | PSM_CONFIG_INITAFTERSUSPEND;
-
- return TRUE; /* PS/2 absolute mode */
-}
-
-static int
-psmresume(device_t dev)
-{
- struct psm_softc *sc = device_get_softc(dev);
- int unit = device_get_unit(dev);
- int err;
-
- if (verbose >= 2)
- log(LOG_NOTICE, "psm%d: system resume hook called.\n", unit);
-
- if (!(sc->config & PSM_CONFIG_HOOKRESUME))
- return (0);
-
- err = reinitialize(sc, sc->config & PSM_CONFIG_INITAFTERSUSPEND);
-
- if ((sc->state & PSM_ASLP) && !(sc->state & PSM_VALID)) {
- /*
- * Release the blocked process; it must be notified that the device
- * cannot be accessed anymore.
- */
- sc->state &= ~PSM_ASLP;
- wakeup(sc);
- }
-
- if (verbose >= 2)
- log(LOG_DEBUG, "psm%d: system resume hook exiting.\n", unit);
-
- return (err);
-}
-
-DRIVER_MODULE(psm, atkbdc, psm_driver, psm_devclass, 0, 0);
-
-/*
- * This sucks up assignments from PNPBIOS and ACPI.
- */
-
-/*
- * When the PS/2 mouse device is reported by ACPI or PnP BIOS, it may
- * appear BEFORE the AT keyboard controller. As the PS/2 mouse device
- * can be probed and attached only after the AT keyboard controller is
- * attached, we shall quietly reserve the IRQ resource for later use.
- * If the PS/2 mouse device is reported to us AFTER the keyboard controller,
- * copy the IRQ resource to the PS/2 mouse device instance hanging
- * under the keyboard controller, then probe and attach it.
- */
-
-static devclass_t psmcpnp_devclass;
-
-static device_probe_t psmcpnp_probe;
-static device_attach_t psmcpnp_attach;
-
-static device_method_t psmcpnp_methods[] = {
- DEVMETHOD(device_probe, psmcpnp_probe),
- DEVMETHOD(device_attach, psmcpnp_attach),
-
- { 0, 0 }
-};
-
-static driver_t psmcpnp_driver = {
- PSMCPNP_DRIVER_NAME,
- psmcpnp_methods,
- 1, /* no softc */
-};
-
-static struct isa_pnp_id psmcpnp_ids[] = {
- { 0x030fd041, "PS/2 mouse port" }, /* PNP0F03 */
- { 0x130fd041, "PS/2 mouse port" }, /* PNP0F13 */
- { 0x1303d041, "PS/2 port" }, /* PNP0313, XXX */
- { 0x80374d24, "IBM PS/2 mouse port" }, /* IBM3780, ThinkPad */
- { 0x81374d24, "IBM PS/2 mouse port" }, /* IBM3781, ThinkPad */
- { 0x0190d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9001, Vaio */
- { 0x0290d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9002, Vaio */
- { 0x0390d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9003, Vaio */
- { 0x0490d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9004, Vaio */
- { 0 }
-};
-
-static int
-create_a_copy(device_t atkbdc, device_t me)
-{
- device_t psm;
- u_long irq;
-
- /* find the PS/2 mouse device instance under the keyboard controller */
- psm = device_find_child(atkbdc, PSM_DRIVER_NAME,
- device_get_unit(atkbdc));
- if (psm == NULL)
- return ENXIO;
- if (device_get_state(psm) != DS_NOTPRESENT)
- return 0;
-
- /* move our resource to the found device */
- irq = bus_get_resource_start(me, SYS_RES_IRQ, 0);
- bus_set_resource(psm, SYS_RES_IRQ, KBDC_RID_AUX, irq, 1);
-
- /* ...then probe and attach it */
- return device_probe_and_attach(psm);
-}
-
-static int
-psmcpnp_probe(device_t dev)
-{
- struct resource *res;
- u_long irq;
- int rid;
-
- if (ISA_PNP_PROBE(device_get_parent(dev), dev, psmcpnp_ids))
- return ENXIO;
-
- /*
- * The PnP BIOS and ACPI are supposed to assign an IRQ (12)
- * to the PS/2 mouse device node. But, some buggy PnP BIOS
- * declares the PS/2 mouse device node without an IRQ resource!
- * If this happens, we shall refer to device hints.
- * If we still don't find it there, use a hardcoded value... XXX
- */
- rid = 0;
- irq = bus_get_resource_start(dev, SYS_RES_IRQ, rid);
- if (irq <= 0) {
- if (resource_long_value(PSM_DRIVER_NAME,
- device_get_unit(dev), "irq", &irq) != 0)
- irq = 12; /* XXX */
- device_printf(dev, "irq resource info is missing; "
- "assuming irq %ld\n", irq);
- bus_set_resource(dev, SYS_RES_IRQ, rid, irq, 1);
- }
- res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE);
- bus_release_resource(dev, SYS_RES_IRQ, rid, res);
-
- /* keep quiet */
- if (!bootverbose)
- device_quiet(dev);
-
- return ((res == NULL) ? ENXIO : 0);
-}
-
-static int
-psmcpnp_attach(device_t dev)
-{
- device_t atkbdc;
- int rid;
-
- /* find the keyboard controller, which may be on acpi* or isa* bus */
- atkbdc = devclass_get_device(devclass_find(ATKBDC_DRIVER_NAME),
- device_get_unit(dev));
- if ((atkbdc != NULL) && (device_get_state(atkbdc) == DS_ATTACHED)) {
- create_a_copy(atkbdc, dev);
- } else {
- /*
- * If we don't have the AT keyboard controller yet,
- * just reserve the IRQ for later use...
- * (See psmidentify() above.)
- */
- rid = 0;
- bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE);
- }
-
- return 0;
-}
-
-DRIVER_MODULE(psmcpnp, isa, psmcpnp_driver, psmcpnp_devclass, 0, 0);
-DRIVER_MODULE(psmcpnp, acpi, psmcpnp_driver, psmcpnp_devclass, 0, 0);
diff --git a/sys/dev/bktr/ioctl_bt848.h b/sys/dev/bktr/ioctl_bt848.h
deleted file mode 100644
index b6646c699b7c..000000000000
--- a/sys/dev/bktr/ioctl_bt848.h
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * extensions to ioctl_meteor.h for the bt848 cards
- *
- * $FreeBSD$
- */
-
-#ifndef _MACHINE_IOCTL_BT848_H_
-#define _MACHINE_IOCTL_BT848_H_
-
-/*
- * frequency sets
- */
-#define CHNLSET_NABCST 1
-#define CHNLSET_CABLEIRC 2
-#define CHNLSET_CABLEHRC 3
-#define CHNLSET_WEUROPE 4
-#define CHNLSET_JPNBCST 5
-#define CHNLSET_JPNCABLE 6
-#define CHNLSET_XUSSR 7
-#define CHNLSET_AUSTRALIA 8
-#define CHNLSET_FRANCE 9
-#define CHNLSET_MIN CHNLSET_NABCST
-#define CHNLSET_MAX CHNLSET_FRANCE
-
-
-/*
- * constants for various tuner registers
- */
-#define BT848_HUEMIN (-90)
-#define BT848_HUEMAX 90
-#define BT848_HUECENTER 0
-#define BT848_HUERANGE 179.3
-#define BT848_HUEREGMIN (-128)
-#define BT848_HUEREGMAX 127
-#define BT848_HUESTEPS 256
-
-#define BT848_BRIGHTMIN (-50)
-#define BT848_BRIGHTMAX 50
-#define BT848_BRIGHTCENTER 0
-#define BT848_BRIGHTRANGE 99.6
-#define BT848_BRIGHTREGMIN (-128)
-#define BT848_BRIGHTREGMAX 127
-#define BT848_BRIGHTSTEPS 256
-
-#define BT848_CONTRASTMIN 0
-#define BT848_CONTRASTMAX 237
-#define BT848_CONTRASTCENTER 100
-#define BT848_CONTRASTRANGE 236.57
-#define BT848_CONTRASTREGMIN 0
-#define BT848_CONTRASTREGMAX 511
-#define BT848_CONTRASTSTEPS 512
-
-#define BT848_CHROMAMIN 0
-#define BT848_CHROMAMAX 284
-#define BT848_CHROMACENTER 100
-#define BT848_CHROMARANGE 283.89
-#define BT848_CHROMAREGMIN 0
-#define BT848_CHROMAREGMAX 511
-#define BT848_CHROMASTEPS 512
-
-#define BT848_SATUMIN 0
-#define BT848_SATUMAX 202
-#define BT848_SATUCENTER 100
-#define BT848_SATURANGE 201.18
-#define BT848_SATUREGMIN 0
-#define BT848_SATUREGMAX 511
-#define BT848_SATUSTEPS 512
-
-#define BT848_SATVMIN 0
-#define BT848_SATVMAX 284
-#define BT848_SATVCENTER 100
-#define BT848_SATVRANGE 283.89
-#define BT848_SATVREGMIN 0
-#define BT848_SATVREGMAX 511
-#define BT848_SATVSTEPS 512
-
-
-/*
- * audio stuff
- */
-#define AUDIO_TUNER 0x00 /* command for the audio routine */
-#define AUDIO_EXTERN 0x01 /* don't confuse them with bit */
-#define AUDIO_INTERN 0x02 /* settings */
-#define AUDIO_MUTE 0x80
-#define AUDIO_UNMUTE 0x81
-
-
-/*
- * EEProm stuff
- */
-struct eeProm {
- short offset;
- short count;
- u_char bytes[ 256 ];
-};
-
-
-/*
- * XXX: this is a hack, should be in ioctl_meteor.h
- * here to avoid touching that file for now...
- */
-#define TVTUNER_SETCHNL _IOW('x', 32, unsigned int) /* set channel */
-#define TVTUNER_GETCHNL _IOR('x', 32, unsigned int) /* get channel */
-#define TVTUNER_SETTYPE _IOW('x', 33, unsigned int) /* set tuner type */
-#define TVTUNER_GETTYPE _IOR('x', 33, unsigned int) /* get tuner type */
-#define TVTUNER_GETSTATUS _IOR('x', 34, unsigned int) /* get tuner status */
-#define TVTUNER_SETFREQ _IOW('x', 35, unsigned int) /* set frequency */
-#define TVTUNER_GETFREQ _IOR('x', 36, unsigned int) /* get frequency */
-
-
-#define BT848_SHUE _IOW('x', 37, int) /* set hue */
-#define BT848_GHUE _IOR('x', 37, int) /* get hue */
-#define BT848_SBRIG _IOW('x', 38, int) /* set brightness */
-#define BT848_GBRIG _IOR('x', 38, int) /* get brightness */
-#define BT848_SCSAT _IOW('x', 39, int) /* set chroma sat */
-#define BT848_GCSAT _IOR('x', 39, int) /* get UV saturation */
-#define BT848_SCONT _IOW('x', 40, int) /* set contrast */
-#define BT848_GCONT _IOR('x', 40, int) /* get contrast */
-#define BT848_SVSAT _IOW('x', 41, int) /* set chroma V sat */
-#define BT848_GVSAT _IOR('x', 41, int) /* get V saturation */
-#define BT848_SUSAT _IOW('x', 42, int) /* set chroma U sat */
-#define BT848_GUSAT _IOR('x', 42, int) /* get U saturation */
-
-#define BT848_SCBARS _IOR('x', 43, int) /* set colorbar */
-#define BT848_CCBARS _IOR('x', 44, int) /* clear colorbar */
-
-
-#define BT848_SAUDIO _IOW('x', 46, int) /* set audio channel */
-#define BT848_GAUDIO _IOR('x', 47, int) /* get audio channel */
-#define BT848_SBTSC _IOW('x', 48, int) /* set audio channel */
-
-#define BT848_GSTATUS _IOR('x', 49, unsigned int) /* reap status */
-
-#define BT848_WEEPROM _IOWR('x', 50, struct eeProm) /* write to EEProm */
-#define BT848_REEPROM _IOWR('x', 51, struct eeProm) /* read from EEProm */
-
-#define BT848_SIGNATURE _IOWR('x', 52, struct eeProm) /* read card sig */
-
-#define TVTUNER_SETAFC _IOW('x', 53, int) /* turn AFC on/off */
-#define TVTUNER_GETAFC _IOR('x', 54, int) /* query AFC on/off */
-#define BT848_SLNOTCH _IOW('x', 55, int) /* set luma notch */
-#define BT848_GLNOTCH _IOR('x', 56, int) /* get luma notch */
-
-/* Read/Write the BT848's I2C bus directly
- * b7-b0: data (read/write)
- * b15-b8: internal peripheral register (write)
- * b23-b16: i2c addr (write)
- * b31-b24: 1 = write, 0 = read
- */
-#define BT848_I2CWR _IOWR('x', 57, u_long) /* i2c read-write */
-
-struct bktr_msp_control {
- unsigned char function;
- unsigned int address;
- unsigned int data;
-};
-
-#define BT848_MSP_RESET _IO('x', 76) /* MSP chip reset */
-#define BT848_MSP_READ _IOWR('x', 77, struct bktr_msp_control) /* MSP chip read */
-#define BT848_MSP_WRITE _IOWR('x', 78, struct bktr_msp_control) /* MSP chip write */
-
-/* Support for radio tuner */
-#define RADIO_SETMODE _IOW('x', 58, unsigned int) /* set radio modes */
-#define RADIO_GETMODE _IOR('x', 58, unsigned char) /* get radio modes */
-#define RADIO_AFC 0x01 /* These modes will probably not */
-#define RADIO_MONO 0x02 /* work on the FRxxxx. It does */
-#define RADIO_MUTE 0x08 /* work on the FMxxxx. */
-#define RADIO_SETFREQ _IOW('x', 59, unsigned int) /* set frequency */
-#define RADIO_GETFREQ _IOR('x', 59, unsigned int) /* set frequency */
- /* Argument is frequency*100MHz */
-
-/*
- * XXX: more bad magic,
- * we need to fix the METEORGINPUT to return something public
- * duplicate them here for now...
- */
-#define METEOR_DEV0 0x00001000
-#define METEOR_DEV1 0x00002000
-#define METEOR_DEV2 0x00004000
-#define METEOR_DEV3 0x00008000
-#define METEOR_DEV_SVIDEO 0x00006000
-/*
- * right now I don't know were to put these, but as they are suppose to be
- * a part of a common video capture interface, these should be relocated to
- * another place. Probably most of the METEOR_xxx defines need to be
- * renamed and moved to a common header
- */
-
-typedef enum { METEOR_PIXTYPE_RGB, METEOR_PIXTYPE_YUV,
- METEOR_PIXTYPE_YUV_PACKED,
- METEOR_PIXTYPE_YUV_12 } METEOR_PIXTYPE;
-
-
-struct meteor_pixfmt {
- u_int index; /* Index in supported pixfmt list */
- METEOR_PIXTYPE type; /* What's the board gonna feed us */
- u_int Bpp; /* Bytes per pixel */
- u_long masks[3]; /* R,G,B or Y,U,V masks, respectively */
- unsigned swap_bytes :1; /* Bytes swapped within shorts */
- unsigned swap_shorts:1; /* Shorts swapped within longs */
-};
-
-
-struct bktr_clip {
- int x_min;
- int x_max;
- int y_min;
- int y_max;
-};
-
-#define BT848_MAX_CLIP_NODE 100
-struct _bktr_clip {
- struct bktr_clip x[BT848_MAX_CLIP_NODE];
-};
-
-/*
- * I'm using METEOR_xxx just because that will be common to other interface
- * and less of a surprise
- */
-#define METEORSACTPIXFMT _IOW('x', 64, int )
-#define METEORGACTPIXFMT _IOR('x', 64, int )
-#define METEORGSUPPIXFMT _IOWR('x', 65, struct meteor_pixfmt)
-
-/* set clip list */
-#define BT848SCLIP _IOW('x', 66, struct _bktr_clip )
-#define BT848GCLIP _IOR('x', 66, struct _bktr_clip )
-
-
-/* set input format */
-#define BT848SFMT _IOW('x', 67, unsigned long )
-#define BT848GFMT _IOR('x', 67, unsigned long )
-
-/* set clear-buffer-on-start */
-#define BT848SCBUF _IOW('x', 68, int)
-#define BT848GCBUF _IOR('x', 68, int)
-
-/* set capture area */
-/* The capture area is the area of the video image which is grabbed */
-/* Usually the capture area is 640x480 (768x576 PAL) pixels */
-/* This area is then scaled to the dimensions the user requires */
-/* using the METEORGEO ioctl */
-/* However, the capture area could be 400x300 pixels from the top right */
-/* corner of the video image */
-struct bktr_capture_area {
- int x_offset;
- int y_offset;
- int x_size;
- int y_size;
-};
-#define BT848_SCAPAREA _IOW('x', 69, struct bktr_capture_area)
-#define BT848_GCAPAREA _IOR('x', 69, struct bktr_capture_area)
-
-
-/* Get channel Set */
-#define BT848_MAX_CHNLSET_NAME_LEN 16
-struct bktr_chnlset {
- short index;
- short max_channel;
- char name[BT848_MAX_CHNLSET_NAME_LEN];
-};
-#define TVTUNER_GETCHNLSET _IOWR('x', 70, struct bktr_chnlset)
-
-
-
-/* Infra Red Remote Control */
-struct bktr_remote {
- unsigned char data[3];
-};
-#define REMOTE_GETKEY _IOR('x', 71, struct bktr_remote)/*read the remote */
- /*control receiver*/
- /*returns raw data*/
-
-
-/*
- * Direct access to GPIO pins. You must add BKTR_GPIO_ACCESS to your kernel
- * configuration file to use these
- */
-#define BT848_GPIO_SET_EN _IOW('x', 72, int) /* set gpio_out_en */
-#define BT848_GPIO_GET_EN _IOR('x', 73, int) /* get gpio_out_en */
-#define BT848_GPIO_SET_DATA _IOW('x', 74, int) /* set gpio_data */
-#define BT848_GPIO_GET_DATA _IOR('x', 75, int) /* get gpio_data */
-
-
-
-/* XXX - Copied from /sys/pci/brktree_reg.h */
-#define BT848_IFORM_FORMAT (0x7<<0)
-# define BT848_IFORM_F_RSVD (0x7)
-# define BT848_IFORM_F_SECAM (0x6)
-# define BT848_IFORM_F_PALN (0x5)
-# define BT848_IFORM_F_PALM (0x4)
-# define BT848_IFORM_F_PALBDGHI (0x3)
-# define BT848_IFORM_F_NTSCJ (0x2)
-# define BT848_IFORM_F_NTSCM (0x1)
-# define BT848_IFORM_F_AUTO (0x0)
-
-
-#endif /* _MACHINE_IOCTL_BT848_H_ */
-
diff --git a/sys/dev/bktr/ioctl_meteor.h b/sys/dev/bktr/ioctl_meteor.h
deleted file mode 100644
index f62d392ea0ae..000000000000
--- a/sys/dev/bktr/ioctl_meteor.h
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright (c) 1995 Mark Tinguely and Jim Lowe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Mark Tinguely and Jim Lowe
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-/*
- * ioctl constants for Matrox Meteor Capture card.
- */
-
-#ifndef _MACHINE_IOCTL_METEOR_H_
-#define _MACHINE_IOCTL_METEOR_H_
-
-#ifndef _KERNEL
-#include <sys/types.h>
-#endif
-#include <sys/ioccom.h>
-
-struct meteor_capframe {
- short command; /* see below for valid METEORCAPFRM commands */
- short lowat; /* start transfer if < this number */
- short hiwat; /* stop transfer if > this number */
-} ;
-
-/* structure for METEOR[GS]ETGEO - get/set geometry */
-struct meteor_geomet {
- u_short rows;
- u_short columns;
- u_short frames;
- u_long oformat;
-} ;
-
-/* structure for METEORGCOUNT-get count of frames, fifo errors and dma errors */
-struct meteor_counts {
- u_long fifo_errors; /* count of fifo errors since open */
- u_long dma_errors; /* count of dma errors since open */
- u_long frames_captured; /* count of frames captured since open */
- u_long even_fields_captured; /* count of even fields captured */
- u_long odd_fields_captured; /* count of odd fields captured */
-} ;
-
-/* structure for getting and setting direct transfers to vram */
-struct meteor_video {
- u_long addr; /* Address of location to dma to */
- u_long width; /* Width of memory area */
- u_long banksize; /* Size of Vram bank */
- u_long ramsize; /* Size of Vram */
-};
-
-#define METEORCAPTUR _IOW('x', 1, int) /* capture a frame */
-#define METEORCAPFRM _IOW('x', 2, struct meteor_capframe) /* sync capture */
-#define METEORSETGEO _IOW('x', 3, struct meteor_geomet) /* set geometry */
-#define METEORGETGEO _IOR('x', 4, struct meteor_geomet) /* get geometry */
-#define METEORSTATUS _IOR('x', 5, unsigned short) /* get status */
-#define METEORSHUE _IOW('x', 6, signed char) /* set hue */
-#define METEORGHUE _IOR('x', 6, signed char) /* get hue */
-#define METEORSFMT _IOW('x', 7, unsigned long) /* set format */
-#define METEORGFMT _IOR('x', 7, unsigned long) /* get format */
-#define METEORSINPUT _IOW('x', 8, unsigned long) /* set input dev */
-#define METEORGINPUT _IOR('x', 8, unsigned long) /* get input dev */
-#define METEORSCHCV _IOW('x', 9, unsigned char) /* set uv gain */
-#define METEORGCHCV _IOR('x', 9, unsigned char) /* get uv gain */
-#define METEORSCOUNT _IOW('x',10, struct meteor_counts)
-#define METEORGCOUNT _IOR('x',10, struct meteor_counts)
-#define METEORSFPS _IOW('x',11, unsigned short) /* set fps */
-#define METEORGFPS _IOR('x',11, unsigned short) /* get fps */
-#define METEORSSIGNAL _IOW('x', 12, unsigned int) /* set signal */
-#define METEORGSIGNAL _IOR('x', 12, unsigned int) /* get signal */
-#define METEORSVIDEO _IOW('x', 13, struct meteor_video) /* set video */
-#define METEORGVIDEO _IOR('x', 13, struct meteor_video) /* get video */
-#define METEORSBRIG _IOW('x', 14, unsigned char) /* set brightness */
-#define METEORGBRIG _IOR('x', 14, unsigned char) /* get brightness */
-#define METEORSCSAT _IOW('x', 15, unsigned char) /* set chroma sat */
-#define METEORGCSAT _IOR('x', 15, unsigned char) /* get uv saturation */
-#define METEORSCONT _IOW('x', 16, unsigned char) /* set contrast */
-#define METEORGCONT _IOR('x', 16, unsigned char) /* get contrast */
-#define METEORSBT254 _IOW('x', 17, unsigned short) /* set Bt254 reg */
-#define METEORGBT254 _IOR('x', 17, unsigned short) /* get Bt254 reg */
-#define METEORSHWS _IOW('x', 18, unsigned char) /* set hor start reg */
-#define METEORGHWS _IOR('x', 18, unsigned char) /* get hor start reg */
-#define METEORSVWS _IOW('x', 19, unsigned char) /* set vert start reg */
-#define METEORGVWS _IOR('x', 19, unsigned char) /* get vert start reg */
-#define METEORSTS _IOW('x', 20, unsigned char) /* set time stamp */
-#define METEORGTS _IOR('x', 20, unsigned char) /* get time stamp */
-
-#define METEOR_STATUS_ID_MASK 0xf000 /* ID of 7196 */
-#define METEOR_STATUS_DIR 0x0800 /* Direction of Expansion port YUV */
-#define METEOR_STATUS_OEF 0x0200 /* Field detected: Even/Odd */
-#define METEOR_STATUS_SVP 0x0100 /* State of VRAM Port:inactive/active */
-#define METEOR_STATUS_STTC 0x0080 /* Time Constant: TV/VCR */
-#define METEOR_STATUS_HCLK 0x0040 /* Horiz PLL: locked/unlocked */
-#define METEOR_STATUS_FIDT 0x0020 /* Field detect: 50/60hz */
-#define METEOR_STATUS_ALTD 0x0002 /* Line alt: no line alt/line alt */
-#define METEOR_STATUS_CODE 0x0001 /* Colour info: no colour/colour */
-
- /* METEORCAPTUR capture options */
-#define METEOR_CAP_SINGLE 0x0001 /* capture one frame */
-#define METEOR_CAP_CONTINOUS 0x0002 /* continuously capture */
-#define METEOR_CAP_STOP_CONT 0x0004 /* stop the continuous capture */
-
- /* METEORCAPFRM capture commands */
-#define METEOR_CAP_N_FRAMES 0x0001 /* capture N frames */
-#define METEOR_CAP_STOP_FRAMES 0x0002 /* stop capture N frames */
-#define METEOR_HALT_N_FRAMES 0x0003 /* halt of capture N frames */
-#define METEOR_CONT_N_FRAMES 0x0004 /* continue after above halt */
-
- /* valid video input formats: */
-#define METEOR_FMT_NTSC 0x00100 /* NTSC -- initialized default */
-#define METEOR_FMT_PAL 0x00200 /* PAL */
-#define METEOR_FMT_SECAM 0x00400 /* SECAM */
-#define METEOR_FMT_AUTOMODE 0x00800 /* auto-mode */
-#define METEOR_INPUT_DEV0 0x01000 /* camera input 0 -- default */
-#define METEOR_INPUT_DEV_RCA METEOR_INPUT_DEV0
-#define METEOR_INPUT_DEV1 0x02000 /* camera input 1 */
-#define METEOR_INPUT_DEV2 0x04000 /* camera input 2 */
-#define METEOR_INPUT_DEV3 0x08000 /* camera input 3 */
-#define METEOR_INPUT_DEV_RGB 0x0a000 /* for rgb version of meteor */
-#define METEOR_INPUT_DEV_SVIDEO 0x06000 /* S-video input port */
-
- /* valid video output formats: */
-#define METEOR_GEO_RGB16 0x0010000 /* packed -- initialized default */
-#define METEOR_GEO_RGB24 0x0020000 /* RBG 24 bits packed */
- /* internally stored in 32 bits */
-#define METEOR_GEO_YUV_PACKED 0x0040000 /* 4-2-2 YUV 16 bits packed */
-#define METEOR_GEO_YUV_PLANAR 0x0080000 /* 4-2-2 YUV 16 bits planer */
-#define METEOR_GEO_YUV_PLANER METEOR_GEO_YUV_PLANAR
-#define METEOR_GEO_UNSIGNED 0x0400000 /* unsigned uv outputs */
-#define METEOR_GEO_EVEN_ONLY 0x1000000 /* set for even only field capture */
-#define METEOR_GEO_ODD_ONLY 0x2000000 /* set for odd only field capture */
-#define METEOR_GEO_FIELD_MASK 0x3000000
-#define METEOR_GEO_YUV_422 0x4000000 /* 4-2-2 YUV in Y-U-V combined */
-#define METEOR_GEO_OUTPUT_MASK 0x40f0000
-#define METEOR_GEO_YUV_12 0x10000000 /* YUV 12 format */
-#define METEOR_GEO_YUV_9 0x40000000 /* YUV 9 format */
-
-#define METEOR_FIELD_MODE 0x80000000 /* Field cap or Frame cap */
-
-#define METEOR_SIG_MODE_MASK 0xffff0000
-#define METEOR_SIG_FRAME 0x00000000 /* signal every frame */
-#define METEOR_SIG_FIELD 0x00010000 /* signal every field */
-
- /* following structure is used to coordinate the synchronous */
-
-struct meteor_mem {
- /* kernel write only */
- int frame_size; /* row*columns*depth */
- unsigned num_bufs; /* number of frames in buffer (1-32) */
- /* user and kernel change these */
- int lowat; /* kernel starts capture if < this number */
- int hiwat; /* kernel stops capture if > this number.
- hiwat <= numbufs */
- unsigned active; /* bit mask of active frame buffers
- kernel sets, user clears */
- int num_active_bufs; /* count of active frame buffer
- kernel increments, user decrements */
-
- /* reference to mmapped data */
- caddr_t buf; /* The real space (virtual addr) */
-} ;
-
-#endif /* !_MACHINE_IOCTL_METEOR_H_ */
diff --git a/sys/dev/cy/cy.c b/sys/dev/cy/cy.c
deleted file mode 100644
index 4e2e499da1a6..000000000000
--- a/sys/dev/cy/cy.c
+++ /dev/null
@@ -1,2960 +0,0 @@
-/*-
- * cyclades cyclom-y serial driver
- * Andrew Herbert <andrew@werple.apana.org.au>, 17 August 1993
- *
- * Copyright (c) 1993 Andrew Herbert.
- * 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 Andrew Herbert may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include "opt_compat.h"
-#include "cy.h"
-
-/*
- * TODO:
- * Atomic COR change.
- * Consoles.
- */
-
-/*
- * Temporary compile-time configuration options.
- */
-#define RxFifoThreshold (CD1400_RX_FIFO_SIZE / 2)
- /* Number of chars in the receiver FIFO before an
- * an interrupt is generated. Should depend on
- * line speed. Needs to be about 6 on a 486DX33
- * for 4 active ports at 115200 bps. Why doesn't
- * 10 work?
- */
-#define PollMode /* Use polling-based irq service routine, not the
- * hardware svcack lines. Must be defined for
- * Cyclom-16Y boards. Less efficient for Cyclom-8Ys,
- * and stops 4 * 115200 bps from working.
- */
-#undef Smarts /* Enable slightly more CD1400 intelligence. Mainly
- * the output CR/LF processing, plus we can avoid a
- * few checks usually done in ttyinput().
- *
- * XXX not fully implemented, and not particularly
- * worthwhile.
- */
-#undef CyDebug /* Include debugging code (not very expensive). */
-
-/* These will go away. */
-#undef SOFT_CTS_OFLOW
-#define SOFT_HOTCHAR
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/conf.h>
-#include <sys/fcntl.h>
-#include <sys/interrupt.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/syslog.h>
-#include <sys/tty.h>
-
-#include <machine/psl.h>
-
-#include <i386/isa/isa_device.h>
-#include <i386/isa/cyreg.h>
-#include <i386/isa/ic/cd1400.h>
-
-#ifndef COMPAT_OLDISA
-#error "The cy device requires the old isa compatibility shims"
-#endif
-
-#ifdef SMP
-
-#include <machine/smptests.h> /** xxx_LOCK */
-
-#ifdef USE_COMLOCK
-#define COM_LOCK() mtx_lock_spin(&com_mtx)
-#define COM_UNLOCK() mtx_unlock_spin(&com_mtx)
-#else
-#define COM_LOCK()
-#define COM_UNLOCK()
-#endif /* USE_COMLOCK */
-
-#else /* SMP */
-
-#define COM_LOCK()
-#define COM_UNLOCK()
-
-#endif /* SMP */
-
-extern struct mtx com_mtx;
-
-/*
- * Dictionary so that I can name everything *sio* or *com* to compare with
- * sio.c. There is also lots of ugly formatting and unnecessary ifdefs to
- * simplify the comparision. These will go away.
- */
-#define LSR_BI CD1400_RDSR_BREAK
-#define LSR_FE CD1400_RDSR_FE
-#define LSR_OE CD1400_RDSR_OE
-#define LSR_PE CD1400_RDSR_PE
-#define MCR_DTR CD1400_MSVR2_DTR
-#define MCR_RTS CD1400_MSVR1_RTS
-#define MSR_CTS CD1400_MSVR2_CTS
-#define MSR_DCD CD1400_MSVR2_CD
-#define MSR_DSR CD1400_MSVR2_DSR
-#define MSR_RI CD1400_MSVR2_RI
-#define NSIO (NCY * CY_MAX_PORTS)
-#define comconsole cyconsole
-#define comdefaultrate cydefaultrate
-#define com_events cy_events
-#define comhardclose cyhardclose
-#define commctl cymctl
-#define comparam cyparam
-#define comspeed cyspeed
-#define comstart cystart
-#define comwakeup cywakeup
-#define p_com_addr p_cy_addr
-#define sioattach cyattach
-#define sioclose cyclose
-#define siodriver cydriver
-#define siodtrwakeup cydtrwakeup
-#define sioinput cyinput
-#define siointr cyintr
-#define siointr1 cyintr1
-#define sioioctl cyioctl
-#define sioopen cyopen
-#define siopoll cypoll
-#define sioprobe cyprobe
-#define siosettimeout cysettimeout
-#define siosetwater cysetwater
-#define comstop cystop
-#define siowrite cywrite
-#define sio_ih cy_ih
-#define sio_irec cy_irec
-#define sio_timeout cy_timeout
-#define sio_timeout_handle cy_timeout_handle
-#define sio_timeouts_until_log cy_timeouts_until_log
-
-#define CY_MAX_PORTS (CD1400_NO_OF_CHANNELS * CY_MAX_CD1400s)
-
-/* We encode the cyclom unit number (cyu) in spare bits in the IVR's. */
-#define CD1400_xIVR_CHAN_SHIFT 3
-#define CD1400_xIVR_CHAN 0x1F
-
-/*
- * ETC states. com->etc may also contain a hardware ETC command value,
- * meaning that execution of that command is pending.
- */
-#define ETC_NONE 0 /* we depend on bzero() setting this */
-#define ETC_BREAK_STARTING 1
-#define ETC_BREAK_STARTED 2
-#define ETC_BREAK_ENDING 3
-#define ETC_BREAK_ENDED 4
-
-#define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */
-
-#define CALLOUT_MASK 0x80
-#define CONTROL_MASK 0x60
-#define CONTROL_INIT_STATE 0x20
-#define CONTROL_LOCK_STATE 0x40
-#define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
-#define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
-/*
- * Not all of the magic is parametrized in the following macros. 16 and
- * 0xff are related to the bitfields in a udev_t. CY_MAX_PORTS must be
- * ((0xff & ~MINOR_MAGIC_MASK) + 1) for things to work.
- */
-#define MINOR_TO_UNIT(mynor) (((mynor) >> 16) * CY_MAX_PORTS \
- | (((mynor) & 0xff) & ~MINOR_MAGIC_MASK))
-#define UNIT_TO_MINOR(unit) (((unit) / CY_MAX_PORTS) << 16 \
- | (((unit) & 0xff) & ~MINOR_MAGIC_MASK))
-
-/*
- * com state bits.
- * (CS_BUSY | CS_TTGO) and (CS_BUSY | CS_TTGO | CS_ODEVREADY) must be higher
- * than the other bits so that they can be tested as a group without masking
- * off the low bits.
- *
- * The following com and tty flags correspond closely:
- * CS_BUSY = TS_BUSY (maintained by comstart(), siopoll() and
- * comstop())
- * CS_TTGO = ~TS_TTSTOP (maintained by comparam() and comstart())
- * CS_CTS_OFLOW = CCTS_OFLOW (maintained by comparam())
- * CS_RTS_IFLOW = CRTS_IFLOW (maintained by comparam())
- * TS_FLUSH is not used.
- * XXX I think TIOCSETA doesn't clear TS_TTSTOP when it clears IXON.
- * XXX CS_*FLOW should be CF_*FLOW in com->flags (control flags not state).
- */
-#define CS_BUSY 0x80 /* output in progress */
-#define CS_TTGO 0x40 /* output not stopped by XOFF */
-#define CS_ODEVREADY 0x20 /* external device h/w ready (CTS) */
-#define CS_CHECKMSR 1 /* check of MSR scheduled */
-#define CS_CTS_OFLOW 2 /* use CTS output flow control */
-#define CS_DTR_OFF 0x10 /* DTR held off */
-#define CS_ODONE 4 /* output completed */
-#define CS_RTS_IFLOW 8 /* use RTS input flow control */
-#define CSE_ODONE 1 /* output transmitted */
-
-static char const * const error_desc[] = {
-#define CE_OVERRUN 0
- "silo overflow",
-#define CE_INTERRUPT_BUF_OVERFLOW 1
- "interrupt-level buffer overflow",
-#define CE_TTY_BUF_OVERFLOW 2
- "tty-level buffer overflow",
-};
-
-#define CE_NTYPES 3
-#define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum])
-
-/* types. XXX - should be elsewhere */
-typedef u_char bool_t; /* boolean */
-typedef u_char volatile *cy_addr;
-
-/* queue of linear buffers */
-struct lbq {
- u_char *l_head; /* next char to process */
- u_char *l_tail; /* one past the last char to process */
- struct lbq *l_next; /* next in queue */
- bool_t l_queued; /* nonzero if queued */
-};
-
-/* com device structure */
-struct com_s {
- u_char state; /* miscellaneous flag bits */
- bool_t active_out; /* nonzero if the callout device is open */
-#if 0
- u_char cfcr_image; /* copy of value written to CFCR */
-#endif
- u_char etc; /* pending Embedded Transmit Command */
- u_char extra_state; /* more flag bits, separate for order trick */
-#if 0
- u_char fifo_image; /* copy of value written to FIFO */
-#endif
- u_char gfrcr_image; /* copy of value read from GFRCR */
-#if 0
- bool_t hasfifo; /* nonzero for 16550 UARTs */
- bool_t loses_outints; /* nonzero if device loses output interrupts */
-#endif
- u_char mcr_dtr; /* MCR bit that is wired to DTR */
- u_char mcr_image; /* copy of value written to MCR */
- u_char mcr_rts; /* MCR bit that is wired to RTS */
-#if 0
-#ifdef COM_MULTIPORT
- bool_t multiport; /* is this unit part of a multiport device? */
-#endif /* COM_MULTIPORT */
- bool_t no_irq; /* nonzero if irq is not attached */
- bool_t poll; /* nonzero if polling is required */
- bool_t poll_output; /* nonzero if polling for output is required */
-#endif
- int unit; /* unit number */
- int dtr_wait; /* time to hold DTR down on close (* 1/hz) */
-#if 0
- u_int tx_fifo_size;
-#endif
- u_int wopeners; /* # processes waiting for DCD in open() */
-
- /*
- * The high level of the driver never reads status registers directly
- * because there would be too many side effects to handle conveniently.
- * Instead, it reads copies of the registers stored here by the
- * interrupt handler.
- */
- u_char last_modem_status; /* last MSR read by intr handler */
- u_char prev_modem_status; /* last MSR handled by high level */
-
- u_char hotchar; /* ldisc-specific char to be handled ASAP */
- u_char *ibuf; /* start of input buffer */
- u_char *ibufend; /* end of input buffer */
- u_char *ibufold; /* old input buffer, to be freed */
- u_char *ihighwater; /* threshold in input buffer */
- u_char *iptr; /* next free spot in input buffer */
- int ibufsize; /* size of ibuf (not include error bytes) */
- int ierroff; /* offset of error bytes in ibuf */
-
- struct lbq obufq; /* head of queue of output buffers */
- struct lbq obufs[2]; /* output buffers */
-
- int cy_align; /* index for register alignment */
- cy_addr cy_iobase; /* base address of this port's cyclom */
- cy_addr iobase; /* base address of this port's cd1400 */
- int mcr_rts_reg; /* cd1400 reg number of reg holding mcr_rts */
-
- struct tty *tp; /* cross reference */
-
- /* Initial state. */
- struct termios it_in; /* should be in struct tty */
- struct termios it_out;
-
- /* Lock state. */
- struct termios lt_in; /* should be in struct tty */
- struct termios lt_out;
-
- bool_t do_timestamp;
- bool_t do_dcd_timestamp;
- struct timeval timestamp;
- struct timeval dcd_timestamp;
-
- u_long bytes_in; /* statistics */
- u_long bytes_out;
- u_int delta_error_counts[CE_NTYPES];
- u_long error_counts[CE_NTYPES];
-
- u_int recv_exception; /* exception chars received */
- u_int mdm; /* modem signal changes */
-#ifdef CyDebug
- u_int start_count; /* no. of calls to comstart() */
- u_int start_real; /* no. of calls that did something */
-#endif
- u_char car; /* CD1400 CAR shadow (if first unit in cd) */
- u_char channel_control;/* CD1400 CCR control command shadow */
- u_char cor[3]; /* CD1400 COR1-3 shadows */
- u_char intr_enable; /* CD1400 SRER shadow */
-
- /*
- * Data area for output buffers. Someday we should build the output
- * buffer queue without copying data.
- */
- u_char obuf1[256];
- u_char obuf2[256];
-};
-
-/* PCI driver entry point. */
-int cyattach_common(cy_addr cy_iobase, int cy_align);
-ointhand2_t siointr;
-
-static int cy_units(cy_addr cy_iobase, int cy_align);
-static int sioattach(struct isa_device *dev);
-static void cd1400_channel_cmd(struct com_s *com, int cmd);
-static void cd1400_channel_cmd_wait(struct com_s *com);
-static void cd_etc(struct com_s *com, int etc);
-static int cd_getreg(struct com_s *com, int reg);
-static void cd_setreg(struct com_s *com, int reg, int val);
-static timeout_t siodtrwakeup;
-static void comhardclose(struct com_s *com);
-static void sioinput(struct com_s *com);
-#if 0
-static void siointr1(struct com_s *com);
-#endif
-static int commctl(struct com_s *com, int bits, int how);
-static int comparam(struct tty *tp, struct termios *t);
-static void siopoll(void *arg);
-static int sioprobe(struct isa_device *dev);
-static void siosettimeout(void);
-static int siosetwater(struct com_s *com, speed_t speed);
-static int comspeed(speed_t speed, u_long cy_clock, int *prescaler_io);
-static void comstart(struct tty *tp);
-static void comstop(struct tty *tp, int rw);
-static timeout_t comwakeup;
-static void disc_optim(struct tty *tp, struct termios *t,
- struct com_s *com);
-
-#ifdef CyDebug
-void cystatus(int unit);
-#endif
-
-static char driver_name[] = "cy";
-
-/* table and macro for fast conversion from a unit number to its com struct */
-static struct com_s *p_com_addr[NSIO];
-#define com_addr(unit) (p_com_addr[unit])
-
-struct isa_driver siodriver = {
- INTR_TYPE_TTY | INTR_FAST,
- sioprobe,
- sioattach,
- driver_name
-};
-COMPAT_ISA_DRIVER(cy, cydriver); /* XXX */
-
-static d_open_t sioopen;
-static d_close_t sioclose;
-static d_write_t siowrite;
-static d_ioctl_t sioioctl;
-
-#define CDEV_MAJOR 48
-static struct cdevsw sio_cdevsw = {
- .d_open = sioopen,
- .d_close = sioclose,
- .d_read = ttyread,
- .d_write = siowrite,
- .d_ioctl = sioioctl,
- .d_poll = ttypoll,
- .d_name = driver_name,
- .d_maj = CDEV_MAJOR,
- .d_flags = D_TTY,
- .d_kqfilter = ttykqfilter,
-};
-
-static int comconsole = -1;
-static speed_t comdefaultrate = TTYDEF_SPEED;
-static u_int com_events; /* input chars + weighted output completions */
-static void *sio_ih;
-static int sio_timeout;
-static int sio_timeouts_until_log;
-static struct callout_handle sio_timeout_handle
- = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
-
-#ifdef CyDebug
-static u_int cd_inbs;
-static u_int cy_inbs;
-static u_int cd_outbs;
-static u_int cy_outbs;
-static u_int cy_svrr_probes;
-static u_int cy_timeouts;
-#endif
-
-static int cy_chip_offset[] = {
- 0x0000, 0x0400, 0x0800, 0x0c00, 0x0200, 0x0600, 0x0a00, 0x0e00,
-};
-static int cy_nr_cd1400s[NCY];
-static int cy_total_devices;
-#undef RxFifoThreshold
-static int volatile RxFifoThreshold = (CD1400_RX_FIFO_SIZE / 2);
-
-static int
-sioprobe(dev)
- struct isa_device *dev;
-{
- cy_addr iobase;
-
- iobase = (cy_addr)dev->id_maddr;
-
- /* Cyclom-16Y hardware reset (Cyclom-8Ys don't care) */
- cy_inb(iobase, CY16_RESET, 0); /* XXX? */
- DELAY(500); /* wait for the board to get its act together */
-
- /* this is needed to get the board out of reset */
- cy_outb(iobase, CY_CLEAR_INTR, 0, 0);
- DELAY(500);
-
- return (cy_units(iobase, 0) == 0 ? 0 : -1);
-}
-
-static int
-cy_units(cy_iobase, cy_align)
- cy_addr cy_iobase;
- int cy_align;
-{
- int cyu;
- u_char firmware_version;
- int i;
- cy_addr iobase;
-
- for (cyu = 0; cyu < CY_MAX_CD1400s; ++cyu) {
- iobase = cy_iobase + (cy_chip_offset[cyu] << cy_align);
-
- /* wait for chip to become ready for new command */
- for (i = 0; i < 10; i++) {
- DELAY(50);
- if (!cd_inb(iobase, CD1400_CCR, cy_align))
- break;
- }
-
- /* clear the GFRCR register */
- cd_outb(iobase, CD1400_GFRCR, cy_align, 0);
-
- /* issue a reset command */
- cd_outb(iobase, CD1400_CCR, cy_align,
- CD1400_CCR_CMDRESET | CD1400_CCR_FULLRESET);
-
- /* XXX bogus initialization to avoid a gcc bug/warning. */
- firmware_version = 0;
-
- /* wait for the CD1400 to initialize itself */
- for (i = 0; i < 200; i++) {
- DELAY(50);
-
- /* retrieve firmware version */
- firmware_version = cd_inb(iobase, CD1400_GFRCR,
- cy_align);
- if ((firmware_version & 0xf0) == 0x40)
- break;
- }
-
- /*
- * Anything in the 0x40-0x4F range is fine.
- * If one CD1400 is bad then we don't support higher
- * numbered good ones on this board.
- */
- if ((firmware_version & 0xf0) != 0x40)
- break;
- }
- return (cyu);
-}
-
-static int
-sioattach(isdp)
- struct isa_device *isdp;
-{
- int adapter;
-
- adapter = cyattach_common((cy_addr) isdp->id_maddr, 0);
- if (adapter < 0)
- return (0);
-
- /*
- * XXX
- * This kludge is to allow ISA/PCI device specifications in the
- * kernel config file to be in any order.
- */
- if (isdp->id_unit != adapter) {
- printf("cy%d: attached as cy%d\n", isdp->id_unit, adapter);
- isdp->id_unit = adapter; /* XXX */
- }
- isdp->id_ointr = siointr;
- /* isdp->id_ri_flags |= RI_FAST; XXX unimplemented - use newbus! */
- return (1);
-}
-
-int
-cyattach_common(cy_iobase, cy_align)
- cy_addr cy_iobase;
- int cy_align;
-{
- int adapter;
- int cyu;
- u_char firmware_version;
- cy_addr iobase;
- int minorbase;
- int ncyu;
- int unit;
-
- adapter = cy_total_devices;
- if ((u_int)adapter >= NCY) {
- printf(
- "cy%d: can't attach adapter: insufficient cy devices configured\n",
- adapter);
- return (-1);
- }
- ncyu = cy_units(cy_iobase, cy_align);
- if (ncyu == 0)
- return (-1);
- cy_nr_cd1400s[adapter] = ncyu;
- cy_total_devices++;
-
- unit = adapter * CY_MAX_PORTS;
- for (cyu = 0; cyu < ncyu; ++cyu) {
- int cdu;
-
- iobase = (cy_addr) (cy_iobase
- + (cy_chip_offset[cyu] << cy_align));
- firmware_version = cd_inb(iobase, CD1400_GFRCR, cy_align);
-
- /* Set up a receive timeout period of than 1+ ms. */
- cd_outb(iobase, CD1400_PPR, cy_align,
- howmany(CY_CLOCK(firmware_version)
- / CD1400_PPR_PRESCALER, 1000));
-
- for (cdu = 0; cdu < CD1400_NO_OF_CHANNELS; ++cdu, ++unit) {
- struct com_s *com;
- int s;
-
- com = malloc(sizeof *com, M_DEVBUF, M_NOWAIT | M_ZERO);
- if (com == NULL)
- break;
- com->unit = unit;
- com->gfrcr_image = firmware_version;
- if (CY_RTS_DTR_SWAPPED(firmware_version)) {
- com->mcr_dtr = MCR_RTS;
- com->mcr_rts = MCR_DTR;
- com->mcr_rts_reg = CD1400_MSVR2;
- } else {
- com->mcr_dtr = MCR_DTR;
- com->mcr_rts = MCR_RTS;
- com->mcr_rts_reg = CD1400_MSVR1;
- }
- com->dtr_wait = 3 * hz;
- com->obufs[0].l_head = com->obuf1;
- com->obufs[1].l_head = com->obuf2;
-
- com->cy_align = cy_align;
- com->cy_iobase = cy_iobase;
- com->iobase = iobase;
- com->car = ~CD1400_CAR_CHAN;
-
- /*
- * We don't use all the flags from <sys/ttydefaults.h> since they
- * are only relevant for logins. It's important to have echo off
- * initially so that the line doesn't start blathering before the
- * echo flag can be turned off.
- */
- com->it_in.c_iflag = 0;
- com->it_in.c_oflag = 0;
- com->it_in.c_cflag = TTYDEF_CFLAG;
- com->it_in.c_lflag = 0;
- if (unit == comconsole) {
- com->it_in.c_iflag = TTYDEF_IFLAG;
- com->it_in.c_oflag = TTYDEF_OFLAG;
- com->it_in.c_cflag = TTYDEF_CFLAG | CLOCAL;
- com->it_in.c_lflag = TTYDEF_LFLAG;
- com->lt_out.c_cflag = com->lt_in.c_cflag = CLOCAL;
- }
- if (siosetwater(com, com->it_in.c_ispeed) != 0) {
- free(com, M_DEVBUF);
- return (0);
- }
- termioschars(&com->it_in);
- com->it_in.c_ispeed = com->it_in.c_ospeed = comdefaultrate;
- com->it_out = com->it_in;
-
- s = spltty();
- com_addr(unit) = com;
- splx(s);
-
- if (sio_ih == NULL) {
- swi_add(&tty_ithd, "tty:cy", siopoll, NULL, SWI_TTY, 0,
- &sio_ih);
- }
- minorbase = UNIT_TO_MINOR(unit);
- make_dev(&sio_cdevsw, minorbase,
- UID_ROOT, GID_WHEEL, 0600, "ttyc%r%r", adapter,
- unit % CY_MAX_PORTS);
- make_dev(&sio_cdevsw, minorbase | CONTROL_INIT_STATE,
- UID_ROOT, GID_WHEEL, 0600, "ttyic%r%r", adapter,
- unit % CY_MAX_PORTS);
- make_dev(&sio_cdevsw, minorbase | CONTROL_LOCK_STATE,
- UID_ROOT, GID_WHEEL, 0600, "ttylc%r%r", adapter,
- unit % CY_MAX_PORTS);
- make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK,
- UID_UUCP, GID_DIALER, 0660, "cuac%r%r", adapter,
- unit % CY_MAX_PORTS);
- make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK | CONTROL_INIT_STATE,
- UID_UUCP, GID_DIALER, 0660, "cuaic%r%r", adapter,
- unit % CY_MAX_PORTS);
- make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK | CONTROL_LOCK_STATE,
- UID_UUCP, GID_DIALER, 0660, "cualc%r%r", adapter,
- unit % CY_MAX_PORTS);
- }
- }
-
- /* ensure an edge for the next interrupt */
- cy_outb(cy_iobase, CY_CLEAR_INTR, cy_align, 0);
-
- return (adapter);
-}
-
-static int
-sioopen(dev, flag, mode, td)
- dev_t dev;
- int flag;
- int mode;
- struct thread *td;
-{
- struct com_s *com;
- int error;
- int mynor;
- int s;
- struct tty *tp;
- int unit;
-
- mynor = minor(dev);
- unit = MINOR_TO_UNIT(mynor);
- if ((u_int) unit >= NSIO || (com = com_addr(unit)) == NULL)
- return (ENXIO);
- if (mynor & CONTROL_MASK)
- return (0);
- tp = dev->si_tty = com->tp = ttymalloc(com->tp);
- s = spltty();
- /*
- * We jump to this label after all non-interrupted sleeps to pick
- * up any changes of the device state.
- */
-open_top:
- while (com->state & CS_DTR_OFF) {
- error = tsleep(&com->dtr_wait, TTIPRI | PCATCH, "cydtr", 0);
- if (error != 0)
- goto out;
- }
- if (tp->t_state & TS_ISOPEN) {
- /*
- * The device is open, so everything has been initialized.
- * Handle conflicts.
- */
- if (mynor & CALLOUT_MASK) {
- if (!com->active_out) {
- error = EBUSY;
- goto out;
- }
- } else {
- if (com->active_out) {
- if (flag & O_NONBLOCK) {
- error = EBUSY;
- goto out;
- }
- error = tsleep(&com->active_out,
- TTIPRI | PCATCH, "cybi", 0);
- if (error != 0)
- goto out;
- goto open_top;
- }
- }
- if (tp->t_state & TS_XCLUDE &&
- suser(td)) {
- error = EBUSY;
- goto out;
- }
- } else {
- /*
- * The device isn't open, so there are no conflicts.
- * Initialize it. Initialization is done twice in many
- * cases: to preempt sleeping callin opens if we are
- * callout, and to complete a callin open after DCD rises.
- */
- tp->t_oproc = comstart;
- tp->t_stop = comstop;
- tp->t_param = comparam;
- tp->t_dev = dev;
- tp->t_termios = mynor & CALLOUT_MASK
- ? com->it_out : com->it_in;
-
- /* Encode per-board unit in LIVR for access in intr routines. */
- cd_setreg(com, CD1400_LIVR,
- (unit & CD1400_xIVR_CHAN) << CD1400_xIVR_CHAN_SHIFT);
-
- (void)commctl(com, TIOCM_DTR | TIOCM_RTS, DMSET);
-#if 0
- com->poll = com->no_irq;
- com->poll_output = com->loses_outints;
-#endif
- ++com->wopeners;
- error = comparam(tp, &tp->t_termios);
- --com->wopeners;
- if (error != 0)
- goto out;
-#if 0
- if (com->hasfifo) {
- /*
- * (Re)enable and flush fifos.
- *
- * Certain SMC chips cause problems if the fifos
- * are enabled while input is ready. Turn off the
- * fifo if necessary to clear the input. We test
- * the input ready bit after enabling the fifos
- * since we've already enabled them in comparam()
- * and to handle races between enabling and fresh
- * input.
- */
- while (TRUE) {
- outb(iobase + com_fifo,
- FIFO_RCV_RST | FIFO_XMT_RST
- | com->fifo_image);
- DELAY(100);
- if (!(inb(com->line_status_port) & LSR_RXRDY))
- break;
- outb(iobase + com_fifo, 0);
- DELAY(100);
- (void) inb(com->data_port);
- }
- }
-
- critical_enter();
- COM_LOCK();
- (void) inb(com->line_status_port);
- (void) inb(com->data_port);
- com->prev_modem_status = com->last_modem_status
- = inb(com->modem_status_port);
- outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY | IER_ERLS
- | IER_EMSC);
- COM_UNLOCK();
- critical_exit();
-#else /* !0 */
- /*
- * Flush fifos. This requires a full channel reset which
- * also disables the transmitter and receiver. Recover
- * from this.
- */
- cd1400_channel_cmd(com,
- CD1400_CCR_CMDRESET | CD1400_CCR_CHANRESET);
- cd1400_channel_cmd(com, com->channel_control);
-
- critical_enter();
- COM_LOCK();
- com->prev_modem_status = com->last_modem_status
- = cd_getreg(com, CD1400_MSVR2);
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = CD1400_SRER_MDMCH | CD1400_SRER_RXDATA);
- COM_UNLOCK();
- critical_exit();
-#endif /* 0 */
- /*
- * Handle initial DCD. Callout devices get a fake initial
- * DCD (trapdoor DCD). If we are callout, then any sleeping
- * callin opens get woken up and resume sleeping on "cybi"
- * instead of "cydcd".
- */
- /*
- * XXX `mynor & CALLOUT_MASK' should be
- * `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where
- * TRAPDOOR_CARRIER is the default initial state for callout
- * devices and SOFT_CARRIER is like CLOCAL except it hides
- * the true carrier.
- */
- if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK)
- (*linesw[tp->t_line].l_modem)(tp, 1);
- }
- /*
- * Wait for DCD if necessary.
- */
- if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
- && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
- ++com->wopeners;
- error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "cydcd", 0);
- --com->wopeners;
- if (error != 0)
- goto out;
- goto open_top;
- }
- error = (*linesw[tp->t_line].l_open)(dev, tp);
- disc_optim(tp, &tp->t_termios, com);
- if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
- com->active_out = TRUE;
- siosettimeout();
-out:
- splx(s);
- if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
- comhardclose(com);
- return (error);
-}
-
-static int
-sioclose(dev, flag, mode, td)
- dev_t dev;
- int flag;
- int mode;
- struct thread *td;
-{
- struct com_s *com;
- int mynor;
- int s;
- struct tty *tp;
-
- mynor = minor(dev);
- if (mynor & CONTROL_MASK)
- return (0);
- com = com_addr(MINOR_TO_UNIT(mynor));
- tp = com->tp;
- s = spltty();
- cd_etc(com, CD1400_ETC_STOPBREAK);
- (*linesw[tp->t_line].l_close)(tp, flag);
- disc_optim(tp, &tp->t_termios, com);
- comstop(tp, FREAD | FWRITE);
- comhardclose(com);
- ttyclose(tp);
- siosettimeout();
- splx(s);
-#ifdef broken /* session holds a ref to the tty; can't deallocate */
- ttyfree(tp);
- com->tp = NULL;
-#endif
- return (0);
-}
-
-static void
-comhardclose(com)
- struct com_s *com;
-{
- cy_addr iobase;
- int s;
- struct tty *tp;
- int unit;
-
- unit = com->unit;
- iobase = com->iobase;
- s = spltty();
-#if 0
- com->poll = FALSE;
- com->poll_output = FALSE;
-#endif
- com->do_timestamp = 0;
-#if 0
- outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
-#else
- /* XXX */
- critical_enter();
- COM_LOCK();
- com->etc = ETC_NONE;
- cd_setreg(com, CD1400_COR2, com->cor[1] &= ~CD1400_COR2_ETC);
- COM_UNLOCK();
- critical_exit();
- cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
-#endif
-
- {
-#if 0
- outb(iobase + com_ier, 0);
-#else
- critical_enter();
- COM_LOCK();
- cd_setreg(com, CD1400_SRER, com->intr_enable = 0);
- COM_UNLOCK();
- critical_exit();
-#endif
- tp = com->tp;
- if ((tp->t_cflag & HUPCL)
- /*
- * XXX we will miss any carrier drop between here and the
- * next open. Perhaps we should watch DCD even when the
- * port is closed; it is not sufficient to check it at
- * the next open because it might go up and down while
- * we're not watching.
- */
- || (!com->active_out
- && !(com->prev_modem_status & MSR_DCD)
- && !(com->it_in.c_cflag & CLOCAL))
- || !(tp->t_state & TS_ISOPEN)) {
- (void)commctl(com, TIOCM_DTR, DMBIC);
-
- /* Disable receiver (leave transmitter enabled). */
- com->channel_control = CD1400_CCR_CMDCHANCTL
- | CD1400_CCR_XMTEN
- | CD1400_CCR_RCVDIS;
- cd1400_channel_cmd(com, com->channel_control);
-
- if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) {
- timeout(siodtrwakeup, com, com->dtr_wait);
- com->state |= CS_DTR_OFF;
- }
- }
- }
-#if 0
- if (com->hasfifo) {
- /*
- * Disable fifos so that they are off after controlled
- * reboots. Some BIOSes fail to detect 16550s when the
- * fifos are enabled.
- */
- outb(iobase + com_fifo, 0);
- }
-#endif
- com->active_out = FALSE;
- wakeup(&com->active_out);
- wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
- splx(s);
-}
-
-static int
-siowrite(dev, uio, flag)
- dev_t dev;
- struct uio *uio;
- int flag;
-{
- int mynor;
- struct tty *tp;
- int unit;
-
- mynor = minor(dev);
- if (mynor & CONTROL_MASK)
- return (ENODEV);
-
- unit = MINOR_TO_UNIT(mynor);
- tp = com_addr(unit)->tp;
- /*
- * (XXX) We disallow virtual consoles if the physical console is
- * a serial port. This is in case there is a display attached that
- * is not the console. In that situation we don't need/want the X
- * server taking over the console.
- */
- if (constty != NULL && unit == comconsole)
- constty = NULL;
-#ifdef Smarts
- /* XXX duplicate ttwrite(), but without so much output processing on
- * CR & LF chars. Hardly worth the effort, given that high-throughput
- * sessions are raw anyhow.
- */
-#else
- return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
-#endif
-}
-
-static void
-siodtrwakeup(chan)
- void *chan;
-{
- struct com_s *com;
-
- com = (struct com_s *)chan;
- com->state &= ~CS_DTR_OFF;
- wakeup(&com->dtr_wait);
-}
-
-/*
- * This function:
- * a) needs to be called with COM_LOCK() held, and
- * b) needs to return with COM_LOCK() held.
- */
-static void
-sioinput(com)
- struct com_s *com;
-{
- u_char *buf;
- int incc;
- u_char line_status;
- int recv_data;
- struct tty *tp;
-
- buf = com->ibuf;
- tp = com->tp;
- if (!(tp->t_state & TS_ISOPEN)) {
- com_events -= (com->iptr - com->ibuf);
- com->iptr = com->ibuf;
- return;
- }
- if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
- /*
- * Avoid the grotesquely inefficient lineswitch routine
- * (ttyinput) in "raw" mode. It usually takes about 450
- * instructions (that's without canonical processing or echo!).
- * slinput is reasonably fast (usually 40 instructions plus
- * call overhead).
- */
-
- do {
- /*
- * This may look odd, but it is using save-and-enable
- * semantics instead of the save-and-disable semantics
- * that are used everywhere else.
- */
- COM_UNLOCK();
- critical_exit();
- incc = com->iptr - buf;
- if (tp->t_rawq.c_cc + incc > tp->t_ihiwat
- && (com->state & CS_RTS_IFLOW
- || tp->t_iflag & IXOFF)
- && !(tp->t_state & TS_TBLOCK))
- ttyblock(tp);
- com->delta_error_counts[CE_TTY_BUF_OVERFLOW]
- += b_to_q((char *)buf, incc, &tp->t_rawq);
- buf += incc;
- tk_nin += incc;
- tk_rawcc += incc;
- tp->t_rawcc += incc;
- ttwakeup(tp);
- if (tp->t_state & TS_TTSTOP
- && (tp->t_iflag & IXANY
- || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
- tp->t_state &= ~TS_TTSTOP;
- tp->t_lflag &= ~FLUSHO;
- comstart(tp);
- }
- critical_enter();
- COM_LOCK();
- } while (buf < com->iptr);
- } else {
- do {
- /*
- * This may look odd, but it is using save-and-enable
- * semantics instead of the save-and-disable semantics
- * that are used everywhere else.
- */
- COM_UNLOCK();
- critical_exit();
- line_status = buf[com->ierroff];
- recv_data = *buf++;
- if (line_status
- & (LSR_BI | LSR_FE | LSR_OE | LSR_PE)) {
- if (line_status & LSR_BI)
- recv_data |= TTY_BI;
- if (line_status & LSR_FE)
- recv_data |= TTY_FE;
- if (line_status & LSR_OE)
- recv_data |= TTY_OE;
- if (line_status & LSR_PE)
- recv_data |= TTY_PE;
- }
- (*linesw[tp->t_line].l_rint)(recv_data, tp);
- critical_enter();
- COM_LOCK();
- } while (buf < com->iptr);
- }
- com_events -= (com->iptr - com->ibuf);
- com->iptr = com->ibuf;
-
- /*
- * There is now room for another low-level buffer full of input,
- * so enable RTS if it is now disabled and there is room in the
- * high-level buffer.
- */
- if ((com->state & CS_RTS_IFLOW) && !(com->mcr_image & com->mcr_rts) &&
- !(tp->t_state & TS_TBLOCK))
-#if 0
- outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
-#else
- cd_setreg(com, com->mcr_rts_reg,
- com->mcr_image |= com->mcr_rts);
-#endif
-}
-
-void
-siointr(unit)
- int unit;
-{
- int baseu;
- int cy_align;
- cy_addr cy_iobase;
- int cyu;
- cy_addr iobase;
- u_char status;
-
- COM_LOCK(); /* XXX could this be placed down lower in the loop? */
-
- baseu = unit * CY_MAX_PORTS;
- cy_align = com_addr(baseu)->cy_align;
- cy_iobase = com_addr(baseu)->cy_iobase;
-
- /* check each CD1400 in turn */
- for (cyu = 0; cyu < cy_nr_cd1400s[unit]; ++cyu) {
- iobase = (cy_addr) (cy_iobase
- + (cy_chip_offset[cyu] << cy_align));
- /* poll to see if it has any work */
- status = cd_inb(iobase, CD1400_SVRR, cy_align);
- if (status == 0)
- continue;
-#ifdef CyDebug
- ++cy_svrr_probes;
-#endif
- /* service requests as appropriate, giving priority to RX */
- if (status & CD1400_SVRR_RXRDY) {
- struct com_s *com;
- u_int count;
- u_char *ioptr;
- u_char line_status;
- u_char recv_data;
- u_char serv_type;
-#ifdef PollMode
- u_char save_rir;
-#endif
-
-#ifdef PollMode
- save_rir = cd_inb(iobase, CD1400_RIR, cy_align);
-
- /* enter rx service */
- cd_outb(iobase, CD1400_CAR, cy_align, save_rir);
- com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
- = save_rir & CD1400_CAR_CHAN;
-
- serv_type = cd_inb(iobase, CD1400_RIVR, cy_align);
- com = com_addr(baseu
- + ((serv_type >> CD1400_xIVR_CHAN_SHIFT)
- & CD1400_xIVR_CHAN));
-#else
- /* ack receive service */
- serv_type = cy_inb(iobase, CY8_SVCACKR, cy_align);
-
- com = com_addr(baseu +
- + ((serv_type >> CD1400_xIVR_CHAN_SHIFT)
- & CD1400_xIVR_CHAN));
-#endif
-
- if (serv_type & CD1400_RIVR_EXCEPTION) {
- ++com->recv_exception;
- line_status = cd_inb(iobase, CD1400_RDSR, cy_align);
- /* break/unnattached error bits or real input? */
- recv_data = cd_inb(iobase, CD1400_RDSR, cy_align);
-#ifndef SOFT_HOTCHAR
- if (line_status & CD1400_RDSR_SPECIAL
- && com->hotchar != 0)
- swi_sched(sio_ih, 0);
-
-#endif
-#if 1 /* XXX "intelligent" PFO error handling would break O error handling */
- if (line_status & (LSR_PE|LSR_FE|LSR_BI)) {
- /*
- Don't store PE if IGNPAR and BI if IGNBRK,
- this hack allows "raw" tty optimization
- works even if IGN* is set.
- */
- if ( com->tp == NULL
- || !(com->tp->t_state & TS_ISOPEN)
- || ((line_status & (LSR_PE|LSR_FE))
- && (com->tp->t_iflag & IGNPAR))
- || ((line_status & LSR_BI)
- && (com->tp->t_iflag & IGNBRK)))
- goto cont;
- if ( (line_status & (LSR_PE|LSR_FE))
- && (com->tp->t_state & TS_CAN_BYPASS_L_RINT)
- && ((line_status & LSR_FE)
- || ((line_status & LSR_PE)
- && (com->tp->t_iflag & INPCK))))
- recv_data = 0;
- }
-#endif /* 1 */
- ++com->bytes_in;
-#ifdef SOFT_HOTCHAR
- if (com->hotchar != 0 && recv_data == com->hotchar)
- swi_sched(sio_ih, 0);
-#endif
- ioptr = com->iptr;
- if (ioptr >= com->ibufend)
- CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW);
- else {
- if (com->do_timestamp)
- microtime(&com->timestamp);
- ++com_events;
- ioptr[0] = recv_data;
- ioptr[com->ierroff] = line_status;
- com->iptr = ++ioptr;
- if (ioptr == com->ihighwater
- && com->state & CS_RTS_IFLOW)
-#if 0
- outb(com->modem_ctl_port,
- com->mcr_image &= ~MCR_RTS);
-#else
- cd_outb(iobase, com->mcr_rts_reg,
- cy_align,
- com->mcr_image &=
- ~com->mcr_rts);
-#endif
- if (line_status & LSR_OE)
- CE_RECORD(com, CE_OVERRUN);
- }
- goto cont;
- } else {
- int ifree;
-
- count = cd_inb(iobase, CD1400_RDCR, cy_align);
- if (!count)
- goto cont;
- com->bytes_in += count;
- ioptr = com->iptr;
- ifree = com->ibufend - ioptr;
- if (count > ifree) {
- count -= ifree;
- com_events += ifree;
- if (ifree != 0) {
- if (com->do_timestamp)
- microtime(&com->timestamp);
- do {
- recv_data = cd_inb(iobase,
- CD1400_RDSR,
- cy_align);
-#ifdef SOFT_HOTCHAR
- if (com->hotchar != 0
- && recv_data
- == com->hotchar)
- swi_sched(sio_ih, 0);
-#endif
- ioptr[0] = recv_data;
- ioptr[com->ierroff] = 0;
- ++ioptr;
- } while (--ifree != 0);
- }
- com->delta_error_counts
- [CE_INTERRUPT_BUF_OVERFLOW] += count;
- do {
- recv_data = cd_inb(iobase, CD1400_RDSR,
- cy_align);
-#ifdef SOFT_HOTCHAR
- if (com->hotchar != 0
- && recv_data == com->hotchar)
- swi_sched(sio_ih, 0);
-#endif
- } while (--count != 0);
- } else {
- if (com->do_timestamp)
- microtime(&com->timestamp);
- if (ioptr <= com->ihighwater
- && ioptr + count > com->ihighwater
- && com->state & CS_RTS_IFLOW)
-#if 0
- outb(com->modem_ctl_port,
- com->mcr_image &= ~MCR_RTS);
-#else
- cd_outb(iobase, com->mcr_rts_reg,
- cy_align,
- com->mcr_image
- &= ~com->mcr_rts);
-#endif
- com_events += count;
- do {
- recv_data = cd_inb(iobase, CD1400_RDSR,
- cy_align);
-#ifdef SOFT_HOTCHAR
- if (com->hotchar != 0
- && recv_data == com->hotchar)
- swi_sched(sio_ih, 0);
-#endif
- ioptr[0] = recv_data;
- ioptr[com->ierroff] = 0;
- ++ioptr;
- } while (--count != 0);
- }
- com->iptr = ioptr;
- }
-cont:
-
- /* terminate service context */
-#ifdef PollMode
- cd_outb(iobase, CD1400_RIR, cy_align,
- save_rir
- & ~(CD1400_RIR_RDIREQ | CD1400_RIR_RBUSY));
-#else
- cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
-#endif
- }
- if (status & CD1400_SVRR_MDMCH) {
- struct com_s *com;
- u_char modem_status;
-#ifdef PollMode
- u_char save_mir;
-#else
- u_char vector;
-#endif
-
-#ifdef PollMode
- save_mir = cd_inb(iobase, CD1400_MIR, cy_align);
-
- /* enter modem service */
- cd_outb(iobase, CD1400_CAR, cy_align, save_mir);
- com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
- = save_mir & CD1400_CAR_CHAN;
-
- com = com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS
- + (save_mir & CD1400_MIR_CHAN));
-#else
- /* ack modem service */
- vector = cy_inb(iobase, CY8_SVCACKM, cy_align);
-
- com = com_addr(baseu
- + ((vector >> CD1400_xIVR_CHAN_SHIFT)
- & CD1400_xIVR_CHAN));
-#endif
- ++com->mdm;
- modem_status = cd_inb(iobase, CD1400_MSVR2, cy_align);
- if (modem_status != com->last_modem_status) {
- if (com->do_dcd_timestamp
- && !(com->last_modem_status & MSR_DCD)
- && modem_status & MSR_DCD)
- microtime(&com->dcd_timestamp);
-
- /*
- * Schedule high level to handle DCD changes. Note
- * that we don't use the delta bits anywhere. Some
- * UARTs mess them up, and it's easy to remember the
- * previous bits and calculate the delta.
- */
- com->last_modem_status = modem_status;
- if (!(com->state & CS_CHECKMSR)) {
- com_events += LOTS_OF_EVENTS;
- com->state |= CS_CHECKMSR;
- swi_sched(sio_ih, 0);
- }
-
-#ifdef SOFT_CTS_OFLOW
- /* handle CTS change immediately for crisp flow ctl */
- if (com->state & CS_CTS_OFLOW) {
- if (modem_status & MSR_CTS) {
- com->state |= CS_ODEVREADY;
- if (com->state >= (CS_BUSY | CS_TTGO
- | CS_ODEVREADY)
- && !(com->intr_enable
- & CD1400_SRER_TXRDY))
- cd_outb(iobase, CD1400_SRER,
- cy_align,
- com->intr_enable
- = com->intr_enable
- & ~CD1400_SRER_TXMPTY
- | CD1400_SRER_TXRDY);
- } else {
- com->state &= ~CS_ODEVREADY;
- if (com->intr_enable
- & CD1400_SRER_TXRDY)
- cd_outb(iobase, CD1400_SRER,
- cy_align,
- com->intr_enable
- = com->intr_enable
- & ~CD1400_SRER_TXRDY
- | CD1400_SRER_TXMPTY);
- }
- }
-#endif
- }
-
- /* terminate service context */
-#ifdef PollMode
- cd_outb(iobase, CD1400_MIR, cy_align,
- save_mir
- & ~(CD1400_MIR_RDIREQ | CD1400_MIR_RBUSY));
-#else
- cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
-#endif
- }
- if (status & CD1400_SVRR_TXRDY) {
- struct com_s *com;
-#ifdef PollMode
- u_char save_tir;
-#else
- u_char vector;
-#endif
-
-#ifdef PollMode
- save_tir = cd_inb(iobase, CD1400_TIR, cy_align);
-
- /* enter tx service */
- cd_outb(iobase, CD1400_CAR, cy_align, save_tir);
- com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
- = save_tir & CD1400_CAR_CHAN;
-
- com = com_addr(baseu
- + cyu * CD1400_NO_OF_CHANNELS
- + (save_tir & CD1400_TIR_CHAN));
-#else
- /* ack transmit service */
- vector = cy_inb(iobase, CY8_SVCACKT, cy_align);
-
- com = com_addr(baseu
- + ((vector >> CD1400_xIVR_CHAN_SHIFT)
- & CD1400_xIVR_CHAN));
-#endif
-
- if (com->etc != ETC_NONE) {
- if (com->intr_enable & CD1400_SRER_TXRDY) {
- /*
- * Here due to sloppy SRER_TXRDY
- * enabling. Ignore. Come back when
- * tx is empty.
- */
- cd_outb(iobase, CD1400_SRER, cy_align,
- com->intr_enable
- = (com->intr_enable
- & ~CD1400_SRER_TXRDY)
- | CD1400_SRER_TXMPTY);
- goto terminate_tx_service;
- }
- switch (com->etc) {
- case CD1400_ETC_SENDBREAK:
- case CD1400_ETC_STOPBREAK:
- /*
- * Start the command. Come back on
- * next tx empty interrupt, hopefully
- * after command has been executed.
- */
- cd_outb(iobase, CD1400_COR2, cy_align,
- com->cor[1] |= CD1400_COR2_ETC);
- cd_outb(iobase, CD1400_TDR, cy_align,
- CD1400_ETC_CMD);
- cd_outb(iobase, CD1400_TDR, cy_align,
- com->etc);
- if (com->etc == CD1400_ETC_SENDBREAK)
- com->etc = ETC_BREAK_STARTING;
- else
- com->etc = ETC_BREAK_ENDING;
- goto terminate_tx_service;
- case ETC_BREAK_STARTING:
- /*
- * BREAK is now on. Continue with
- * SRER_TXMPTY processing, hopefully
- * don't come back.
- */
- com->etc = ETC_BREAK_STARTED;
- break;
- case ETC_BREAK_STARTED:
- /*
- * Came back due to sloppy SRER_TXMPTY
- * enabling. Hope again.
- */
- break;
- case ETC_BREAK_ENDING:
- /*
- * BREAK is now off. Continue with
- * SRER_TXMPTY processing and don't
- * come back. The SWI handler will
- * restart tx interrupts if necessary.
- */
- cd_outb(iobase, CD1400_COR2, cy_align,
- com->cor[1]
- &= ~CD1400_COR2_ETC);
- com->etc = ETC_BREAK_ENDED;
- if (!(com->state & CS_ODONE)) {
- com_events += LOTS_OF_EVENTS;
- com->state |= CS_ODONE;
- swi_sched(sio_ih, 0);
- }
- break;
- case ETC_BREAK_ENDED:
- /*
- * Shouldn't get here. Hope again.
- */
- break;
- }
- }
- if (com->intr_enable & CD1400_SRER_TXMPTY) {
- if (!(com->extra_state & CSE_ODONE)) {
- com_events += LOTS_OF_EVENTS;
- com->extra_state |= CSE_ODONE;
- swi_sched(sio_ih, 0);
- }
- cd_outb(iobase, CD1400_SRER, cy_align,
- com->intr_enable
- &= ~CD1400_SRER_TXMPTY);
- goto terminate_tx_service;
- }
- if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
- u_char *ioptr;
- u_int ocount;
-
- ioptr = com->obufq.l_head;
- ocount = com->obufq.l_tail - ioptr;
- if (ocount > CD1400_TX_FIFO_SIZE)
- ocount = CD1400_TX_FIFO_SIZE;
- com->bytes_out += ocount;
- do
- cd_outb(iobase, CD1400_TDR, cy_align,
- *ioptr++);
- while (--ocount != 0);
- com->obufq.l_head = ioptr;
- if (ioptr >= com->obufq.l_tail) {
- struct lbq *qp;
-
- qp = com->obufq.l_next;
- qp->l_queued = FALSE;
- qp = qp->l_next;
- if (qp != NULL) {
- com->obufq.l_head = qp->l_head;
- com->obufq.l_tail = qp->l_tail;
- com->obufq.l_next = qp;
- } else {
- /* output just completed */
- com->state &= ~CS_BUSY;
-
- /*
- * The setting of CSE_ODONE may be
- * stale here. We currently only
- * use it when CS_BUSY is set, and
- * fixing it when we clear CS_BUSY
- * is easiest.
- */
- if (com->extra_state & CSE_ODONE) {
- com_events -= LOTS_OF_EVENTS;
- com->extra_state &= ~CSE_ODONE;
- }
-
- cd_outb(iobase, CD1400_SRER, cy_align,
- com->intr_enable
- = (com->intr_enable
- & ~CD1400_SRER_TXRDY)
- | CD1400_SRER_TXMPTY);
- }
- if (!(com->state & CS_ODONE)) {
- com_events += LOTS_OF_EVENTS;
- com->state |= CS_ODONE;
-
- /* handle at high level ASAP */
- swi_sched(sio_ih, 0);
- }
- }
- }
-
- /* terminate service context */
-terminate_tx_service:
-#ifdef PollMode
- cd_outb(iobase, CD1400_TIR, cy_align,
- save_tir
- & ~(CD1400_TIR_RDIREQ | CD1400_TIR_RBUSY));
-#else
- cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
-#endif
- }
- }
-
- /* ensure an edge for the next interrupt */
- cy_outb(cy_iobase, CY_CLEAR_INTR, cy_align, 0);
-
- swi_sched(sio_ih, 0);
-
- COM_UNLOCK();
-}
-
-#if 0
-static void
-siointr1(com)
- struct com_s *com;
-{
-}
-#endif
-
-static int
-sioioctl(dev, cmd, data, flag, td)
- dev_t dev;
- u_long cmd;
- caddr_t data;
- int flag;
- struct thread *td;
-{
- struct com_s *com;
- int error;
- int mynor;
- int s;
- struct tty *tp;
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
- int oldcmd;
- struct termios term;
-#endif
-
- mynor = minor(dev);
- com = com_addr(MINOR_TO_UNIT(mynor));
- if (mynor & CONTROL_MASK) {
- struct termios *ct;
-
- switch (mynor & CONTROL_MASK) {
- case CONTROL_INIT_STATE:
- ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in;
- break;
- case CONTROL_LOCK_STATE:
- ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in;
- break;
- default:
- return (ENODEV); /* /dev/nodev */
- }
- switch (cmd) {
- case TIOCSETA:
- error = suser(td);
- if (error != 0)
- return (error);
- *ct = *(struct termios *)data;
- return (0);
- case TIOCGETA:
- *(struct termios *)data = *ct;
- return (0);
- case TIOCGETD:
- *(int *)data = TTYDISC;
- return (0);
- case TIOCGWINSZ:
- bzero(data, sizeof(struct winsize));
- return (0);
- default:
- return (ENOTTY);
- }
- }
- tp = com->tp;
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
- term = tp->t_termios;
- oldcmd = cmd;
- error = ttsetcompat(tp, &cmd, data, &term);
- if (error != 0)
- return (error);
- if (cmd != oldcmd)
- data = (caddr_t)&term;
-#endif
- if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
- int cc;
- struct termios *dt = (struct termios *)data;
- struct termios *lt = mynor & CALLOUT_MASK
- ? &com->lt_out : &com->lt_in;
-
- dt->c_iflag = (tp->t_iflag & lt->c_iflag)
- | (dt->c_iflag & ~lt->c_iflag);
- dt->c_oflag = (tp->t_oflag & lt->c_oflag)
- | (dt->c_oflag & ~lt->c_oflag);
- dt->c_cflag = (tp->t_cflag & lt->c_cflag)
- | (dt->c_cflag & ~lt->c_cflag);
- dt->c_lflag = (tp->t_lflag & lt->c_lflag)
- | (dt->c_lflag & ~lt->c_lflag);
- for (cc = 0; cc < NCCS; ++cc)
- if (lt->c_cc[cc] != 0)
- dt->c_cc[cc] = tp->t_cc[cc];
- if (lt->c_ispeed != 0)
- dt->c_ispeed = tp->t_ispeed;
- if (lt->c_ospeed != 0)
- dt->c_ospeed = tp->t_ospeed;
- }
- error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
- if (error != ENOIOCTL)
- return (error);
- s = spltty();
- error = ttioctl(tp, cmd, data, flag);
- disc_optim(tp, &tp->t_termios, com);
- if (error != ENOIOCTL) {
- splx(s);
- return (error);
- }
- switch (cmd) {
- case TIOCSBRK:
-#if 0
- outb(iobase + com_cfcr, com->cfcr_image |= CFCR_SBREAK);
-#else
- cd_etc(com, CD1400_ETC_SENDBREAK);
-#endif
- break;
- case TIOCCBRK:
-#if 0
- outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
-#else
- cd_etc(com, CD1400_ETC_STOPBREAK);
-#endif
- break;
- case TIOCSDTR:
- (void)commctl(com, TIOCM_DTR, DMBIS);
- break;
- case TIOCCDTR:
- (void)commctl(com, TIOCM_DTR, DMBIC);
- break;
- /*
- * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The
- * changes get undone on the next call to comparam().
- */
- case TIOCMSET:
- (void)commctl(com, *(int *)data, DMSET);
- break;
- case TIOCMBIS:
- (void)commctl(com, *(int *)data, DMBIS);
- break;
- case TIOCMBIC:
- (void)commctl(com, *(int *)data, DMBIC);
- break;
- case TIOCMGET:
- *(int *)data = commctl(com, 0, DMGET);
- break;
- case TIOCMSDTRWAIT:
- /* must be root since the wait applies to following logins */
- error = suser(td);
- if (error != 0) {
- splx(s);
- return (error);
- }
- com->dtr_wait = *(int *)data * hz / 100;
- break;
- case TIOCMGDTRWAIT:
- *(int *)data = com->dtr_wait * 100 / hz;
- break;
- case TIOCTIMESTAMP:
- com->do_timestamp = TRUE;
- *(struct timeval *)data = com->timestamp;
- break;
- case TIOCDCDTIMESTAMP:
- com->do_dcd_timestamp = TRUE;
- *(struct timeval *)data = com->dcd_timestamp;
- break;
- default:
- splx(s);
- return (ENOTTY);
- }
- splx(s);
- return (0);
-}
-
-static void
-siopoll(void *arg)
-{
- int unit;
-
-#ifdef CyDebug
- ++cy_timeouts;
-#endif
- if (com_events == 0)
- return;
-repeat:
- for (unit = 0; unit < NSIO; ++unit) {
- struct com_s *com;
- int incc;
- struct tty *tp;
-
- com = com_addr(unit);
- if (com == NULL)
- continue;
- tp = com->tp;
- if (tp == NULL) {
- /*
- * XXX forget any events related to closed devices
- * (actually never opened devices) so that we don't
- * loop.
- */
- critical_enter();
- COM_LOCK();
- incc = com->iptr - com->ibuf;
- com->iptr = com->ibuf;
- if (com->state & CS_CHECKMSR) {
- incc += LOTS_OF_EVENTS;
- com->state &= ~CS_CHECKMSR;
- }
- com_events -= incc;
- COM_UNLOCK();
- critical_exit();
- if (incc != 0)
- log(LOG_DEBUG,
- "sio%d: %d events for device with no tp\n",
- unit, incc);
- continue;
- }
- if (com->iptr != com->ibuf) {
- critical_enter();
- COM_LOCK();
- sioinput(com);
- COM_UNLOCK();
- critical_exit();
- }
- if (com->state & CS_CHECKMSR) {
- u_char delta_modem_status;
-
- critical_enter();
- COM_LOCK();
- sioinput(com);
- delta_modem_status = com->last_modem_status
- ^ com->prev_modem_status;
- com->prev_modem_status = com->last_modem_status;
- com_events -= LOTS_OF_EVENTS;
- com->state &= ~CS_CHECKMSR;
- COM_UNLOCK();
- critical_exit();
- if (delta_modem_status & MSR_DCD)
- (*linesw[tp->t_line].l_modem)
- (tp, com->prev_modem_status & MSR_DCD);
- }
- if (com->extra_state & CSE_ODONE) {
- critical_enter();
- COM_LOCK();
- com_events -= LOTS_OF_EVENTS;
- com->extra_state &= ~CSE_ODONE;
- COM_UNLOCK();
- critical_exit();
- if (!(com->state & CS_BUSY)) {
- tp->t_state &= ~TS_BUSY;
- ttwwakeup(com->tp);
- }
- if (com->etc != ETC_NONE) {
- if (com->etc == ETC_BREAK_ENDED)
- com->etc = ETC_NONE;
- wakeup(&com->etc);
- }
- }
- if (com->state & CS_ODONE) {
- critical_enter();
- COM_LOCK();
- com_events -= LOTS_OF_EVENTS;
- com->state &= ~CS_ODONE;
- COM_UNLOCK();
- critical_exit();
- (*linesw[tp->t_line].l_start)(tp);
- }
- if (com_events == 0)
- break;
- }
- if (com_events >= LOTS_OF_EVENTS)
- goto repeat;
-}
-
-static int
-comparam(tp, t)
- struct tty *tp;
- struct termios *t;
-{
- int bits;
- int cflag;
- struct com_s *com;
- u_char cor_change;
- u_long cy_clock;
- int idivisor;
- int iflag;
- int iprescaler;
- int itimeout;
- int odivisor;
- int oprescaler;
- u_char opt;
- int s;
- int unit;
-
- /* do historical conversions */
- if (t->c_ispeed == 0)
- t->c_ispeed = t->c_ospeed;
-
- unit = DEV_TO_UNIT(tp->t_dev);
- com = com_addr(unit);
-
- /* check requested parameters */
- cy_clock = CY_CLOCK(com->gfrcr_image);
- idivisor = comspeed(t->c_ispeed, cy_clock, &iprescaler);
- if (idivisor < 0)
- return (EINVAL);
- odivisor = comspeed(t->c_ospeed, cy_clock, &oprescaler);
- if (odivisor < 0)
- return (EINVAL);
-
- /* parameters are OK, convert them to the com struct and the device */
- s = spltty();
- if (odivisor == 0)
- (void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */
- else
- (void)commctl(com, TIOCM_DTR, DMBIS);
-
- (void) siosetwater(com, t->c_ispeed);
-
- /* XXX we don't actually change the speed atomically. */
-
- if (idivisor != 0) {
- cd_setreg(com, CD1400_RBPR, idivisor);
- cd_setreg(com, CD1400_RCOR, iprescaler);
- }
- if (odivisor != 0) {
- cd_setreg(com, CD1400_TBPR, odivisor);
- cd_setreg(com, CD1400_TCOR, oprescaler);
- }
-
- /*
- * channel control
- * receiver enable
- * transmitter enable (always set)
- */
- cflag = t->c_cflag;
- opt = CD1400_CCR_CMDCHANCTL | CD1400_CCR_XMTEN
- | (cflag & CREAD ? CD1400_CCR_RCVEN : CD1400_CCR_RCVDIS);
- if (opt != com->channel_control) {
- com->channel_control = opt;
- cd1400_channel_cmd(com, opt);
- }
-
-#ifdef Smarts
- /* set special chars */
- /* XXX if one is _POSIX_VDISABLE, can't use some others */
- if (t->c_cc[VSTOP] != _POSIX_VDISABLE)
- cd_setreg(com, CD1400_SCHR1, t->c_cc[VSTOP]);
- if (t->c_cc[VSTART] != _POSIX_VDISABLE)
- cd_setreg(com, CD1400_SCHR2, t->c_cc[VSTART]);
- if (t->c_cc[VINTR] != _POSIX_VDISABLE)
- cd_setreg(com, CD1400_SCHR3, t->c_cc[VINTR]);
- if (t->c_cc[VSUSP] != _POSIX_VDISABLE)
- cd_setreg(com, CD1400_SCHR4, t->c_cc[VSUSP]);
-#endif
-
- /*
- * set channel option register 1 -
- * parity mode
- * stop bits
- * char length
- */
- opt = 0;
- /* parity */
- if (cflag & PARENB) {
- if (cflag & PARODD)
- opt |= CD1400_COR1_PARODD;
- opt |= CD1400_COR1_PARNORMAL;
- }
- iflag = t->c_iflag;
- if (!(iflag & INPCK))
- opt |= CD1400_COR1_NOINPCK;
- bits = 1 + 1;
- /* stop bits */
- if (cflag & CSTOPB) {
- ++bits;
- opt |= CD1400_COR1_STOP2;
- }
- /* char length */
- switch (cflag & CSIZE) {
- case CS5:
- bits += 5;
- opt |= CD1400_COR1_CS5;
- break;
- case CS6:
- bits += 6;
- opt |= CD1400_COR1_CS6;
- break;
- case CS7:
- bits += 7;
- opt |= CD1400_COR1_CS7;
- break;
- default:
- bits += 8;
- opt |= CD1400_COR1_CS8;
- break;
- }
- cor_change = 0;
- if (opt != com->cor[0]) {
- cor_change |= CD1400_CCR_COR1;
- cd_setreg(com, CD1400_COR1, com->cor[0] = opt);
- }
-
- /*
- * Set receive time-out period, normally to max(one char time, 5 ms).
- */
- if (t->c_ispeed == 0)
- itimeout = cd_getreg(com, CD1400_RTPR);
- else {
- itimeout = (1000 * bits + t->c_ispeed - 1) / t->c_ispeed;
-#ifdef SOFT_HOTCHAR
-#define MIN_RTP 1
-#else
-#define MIN_RTP 5
-#endif
- if (itimeout < MIN_RTP)
- itimeout = MIN_RTP;
- }
- if (!(t->c_lflag & ICANON) && t->c_cc[VMIN] != 0 && t->c_cc[VTIME] != 0
- && t->c_cc[VTIME] * 10 > itimeout)
- itimeout = t->c_cc[VTIME] * 10;
- if (itimeout > 255)
- itimeout = 255;
- cd_setreg(com, CD1400_RTPR, itimeout);
-
- /*
- * set channel option register 2 -
- * flow control
- */
- opt = 0;
-#ifdef Smarts
- if (iflag & IXANY)
- opt |= CD1400_COR2_IXANY;
- if (iflag & IXOFF)
- opt |= CD1400_COR2_IXOFF;
-#endif
-#ifndef SOFT_CTS_OFLOW
- if (cflag & CCTS_OFLOW)
- opt |= CD1400_COR2_CCTS_OFLOW;
-#endif
- critical_enter();
- COM_LOCK();
- if (opt != com->cor[1]) {
- cor_change |= CD1400_CCR_COR2;
- cd_setreg(com, CD1400_COR2, com->cor[1] = opt);
- }
- COM_UNLOCK();
- critical_exit();
-
- /*
- * set channel option register 3 -
- * receiver FIFO interrupt threshold
- * flow control
- */
- opt = RxFifoThreshold;
-#ifdef Smarts
- if (t->c_lflag & ICANON)
- opt |= CD1400_COR3_SCD34; /* detect INTR & SUSP chars */
- if (iflag & IXOFF)
- /* detect and transparently handle START and STOP chars */
- opt |= CD1400_COR3_FCT | CD1400_COR3_SCD12;
-#endif
- if (opt != com->cor[2]) {
- cor_change |= CD1400_CCR_COR3;
- cd_setreg(com, CD1400_COR3, com->cor[2] = opt);
- }
-
- /* notify the CD1400 if COR1-3 have changed */
- if (cor_change)
- cd1400_channel_cmd(com, CD1400_CCR_CMDCORCHG | cor_change);
-
- /*
- * set channel option register 4 -
- * CR/NL processing
- * break processing
- * received exception processing
- */
- opt = 0;
- if (iflag & IGNCR)
- opt |= CD1400_COR4_IGNCR;
-#ifdef Smarts
- /*
- * we need a new ttyinput() for this, as we don't want to
- * have ICRNL && INLCR being done in both layers, or to have
- * synchronisation problems
- */
- if (iflag & ICRNL)
- opt |= CD1400_COR4_ICRNL;
- if (iflag & INLCR)
- opt |= CD1400_COR4_INLCR;
-#endif
- if (iflag & IGNBRK)
- opt |= CD1400_COR4_IGNBRK | CD1400_COR4_NOBRKINT;
- /*
- * The `-ignbrk -brkint parmrk' case is not handled by the hardware,
- * so only tell the hardware about -brkint if -parmrk.
- */
- if (!(iflag & (BRKINT | PARMRK)))
- opt |= CD1400_COR4_NOBRKINT;
-#if 0
- /* XXX using this "intelligence" breaks reporting of overruns. */
- if (iflag & IGNPAR)
- opt |= CD1400_COR4_PFO_DISCARD;
- else {
- if (iflag & PARMRK)
- opt |= CD1400_COR4_PFO_ESC;
- else
- opt |= CD1400_COR4_PFO_NUL;
- }
-#else
- opt |= CD1400_COR4_PFO_EXCEPTION;
-#endif
- cd_setreg(com, CD1400_COR4, opt);
-
- /*
- * set channel option register 5 -
- */
- opt = 0;
- if (iflag & ISTRIP)
- opt |= CD1400_COR5_ISTRIP;
- if (t->c_iflag & IEXTEN)
- /* enable LNEXT (e.g. ctrl-v quoting) handling */
- opt |= CD1400_COR5_LNEXT;
-#ifdef Smarts
- if (t->c_oflag & ONLCR)
- opt |= CD1400_COR5_ONLCR;
- if (t->c_oflag & OCRNL)
- opt |= CD1400_COR5_OCRNL;
-#endif
- cd_setreg(com, CD1400_COR5, opt);
-
- /*
- * We always generate modem status change interrupts for CD changes.
- * Among other things, this is necessary to track TS_CARR_ON for
- * pstat to print even when the driver doesn't care. CD changes
- * should be rare so interrupts for them are not worth extra code to
- * avoid. We avoid interrupts for other modem status changes (except
- * for CTS changes when SOFT_CTS_OFLOW is configured) since this is
- * simplest and best.
- */
-
- /*
- * set modem change option register 1
- * generate modem interrupts on which 1 -> 0 input transitions
- * also controls auto-DTR output flow-control, which we don't use
- */
- opt = CD1400_MCOR1_CDzd;
-#ifdef SOFT_CTS_OFLOW
- if (cflag & CCTS_OFLOW)
- opt |= CD1400_MCOR1_CTSzd;
-#endif
- cd_setreg(com, CD1400_MCOR1, opt);
-
- /*
- * set modem change option register 2
- * generate modem interrupts on specific 0 -> 1 input transitions
- */
- opt = CD1400_MCOR2_CDod;
-#ifdef SOFT_CTS_OFLOW
- if (cflag & CCTS_OFLOW)
- opt |= CD1400_MCOR2_CTSod;
-#endif
- cd_setreg(com, CD1400_MCOR2, opt);
-
- /*
- * XXX should have done this long ago, but there is too much state
- * to change all atomically.
- */
- critical_enter();
- COM_LOCK();
-
- com->state &= ~CS_TTGO;
- if (!(tp->t_state & TS_TTSTOP))
- com->state |= CS_TTGO;
- if (cflag & CRTS_IFLOW) {
- com->state |= CS_RTS_IFLOW;
- /*
- * If CS_RTS_IFLOW just changed from off to on, the change
- * needs to be propagated to MCR_RTS. This isn't urgent,
- * so do it later by calling comstart() instead of repeating
- * a lot of code from comstart() here.
- */
- } else if (com->state & CS_RTS_IFLOW) {
- com->state &= ~CS_RTS_IFLOW;
- /*
- * CS_RTS_IFLOW just changed from on to off. Force MCR_RTS
- * on here, since comstart() won't do it later.
- */
-#if 0
- outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
-#else
- cd_setreg(com, com->mcr_rts_reg,
- com->mcr_image |= com->mcr_rts);
-#endif
- }
-
- /*
- * Set up state to handle output flow control.
- * XXX - worth handling MDMBUF (DCD) flow control at the lowest level?
- * Now has 10+ msec latency, while CTS flow has 50- usec latency.
- */
- com->state |= CS_ODEVREADY;
-#ifdef SOFT_CTS_OFLOW
- com->state &= ~CS_CTS_OFLOW;
- if (cflag & CCTS_OFLOW) {
- com->state |= CS_CTS_OFLOW;
- if (!(com->last_modem_status & MSR_CTS))
- com->state &= ~CS_ODEVREADY;
- }
-#endif
- /* XXX shouldn't call functions while intrs are disabled. */
- disc_optim(tp, t, com);
-#if 0
- /*
- * Recover from fiddling with CS_TTGO. We used to call siointr1()
- * unconditionally, but that defeated the careful discarding of
- * stale input in sioopen().
- */
- if (com->state >= (CS_BUSY | CS_TTGO))
- siointr1(com);
-#endif
- if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
- if (!(com->intr_enable & CD1400_SRER_TXRDY))
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable & ~CD1400_SRER_TXMPTY)
- | CD1400_SRER_TXRDY);
- } else {
- if (com->intr_enable & CD1400_SRER_TXRDY)
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable & ~CD1400_SRER_TXRDY)
- | CD1400_SRER_TXMPTY);
- }
-
- COM_UNLOCK();
- critical_exit();
- splx(s);
- comstart(tp);
- if (com->ibufold != NULL) {
- free(com->ibufold, M_DEVBUF);
- com->ibufold = NULL;
- }
- return (0);
-}
-
-static int
-siosetwater(com, speed)
- struct com_s *com;
- speed_t speed;
-{
- int cp4ticks;
- u_char *ibuf;
- int ibufsize;
- struct tty *tp;
-
- /*
- * Make the buffer size large enough to handle a softtty interrupt
- * latency of about 2 ticks without loss of throughput or data
- * (about 3 ticks if input flow control is not used or not honoured,
- * but a bit less for CS5-CS7 modes).
- */
- cp4ticks = speed / 10 / hz * 4;
- for (ibufsize = 128; ibufsize < cp4ticks;)
- ibufsize <<= 1;
- if (ibufsize == com->ibufsize) {
- return (0);
- }
-
- /*
- * Allocate input buffer. The extra factor of 2 in the size is
- * to allow for an error byte for each input byte.
- */
- ibuf = malloc(2 * ibufsize, M_DEVBUF, M_NOWAIT);
- if (ibuf == NULL) {
- return (ENOMEM);
- }
-
- /* Initialize non-critical variables. */
- com->ibufold = com->ibuf;
- com->ibufsize = ibufsize;
- tp = com->tp;
- if (tp != NULL) {
- tp->t_ififosize = 2 * ibufsize;
- tp->t_ispeedwat = (speed_t)-1;
- tp->t_ospeedwat = (speed_t)-1;
- }
-
- /*
- * Read current input buffer, if any. Continue with interrupts
- * disabled.
- */
- critical_enter();
- COM_LOCK();
- if (com->iptr != com->ibuf)
- sioinput(com);
-
- /*-
- * Initialize critical variables, including input buffer watermarks.
- * The external device is asked to stop sending when the buffer
- * exactly reaches high water, or when the high level requests it.
- * The high level is notified immediately (rather than at a later
- * clock tick) when this watermark is reached.
- * The buffer size is chosen so the watermark should almost never
- * be reached.
- * The low watermark is invisibly 0 since the buffer is always
- * emptied all at once.
- */
- com->iptr = com->ibuf = ibuf;
- com->ibufend = ibuf + ibufsize;
- com->ierroff = ibufsize;
- com->ihighwater = ibuf + 3 * ibufsize / 4;
-
- COM_UNLOCK();
- critical_exit();
- return (0);
-}
-
-static void
-comstart(tp)
- struct tty *tp;
-{
- struct com_s *com;
- int s;
-#ifdef CyDebug
- bool_t started;
-#endif
- int unit;
-
- unit = DEV_TO_UNIT(tp->t_dev);
- com = com_addr(unit);
- s = spltty();
-
-#ifdef CyDebug
- ++com->start_count;
- started = FALSE;
-#endif
-
- critical_enter();
- COM_LOCK();
- if (tp->t_state & TS_TTSTOP) {
- com->state &= ~CS_TTGO;
- if (com->intr_enable & CD1400_SRER_TXRDY)
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable & ~CD1400_SRER_TXRDY)
- | CD1400_SRER_TXMPTY);
- } else {
- com->state |= CS_TTGO;
- if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)
- && !(com->intr_enable & CD1400_SRER_TXRDY))
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable & ~CD1400_SRER_TXMPTY)
- | CD1400_SRER_TXRDY);
- }
- if (tp->t_state & TS_TBLOCK) {
- if (com->mcr_image & com->mcr_rts && com->state & CS_RTS_IFLOW)
-#if 0
- outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS);
-#else
- cd_setreg(com, com->mcr_rts_reg,
- com->mcr_image &= ~com->mcr_rts);
-#endif
- } else {
- if (!(com->mcr_image & com->mcr_rts)
- && com->iptr < com->ihighwater
- && com->state & CS_RTS_IFLOW)
-#if 0
- outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
-#else
- cd_setreg(com, com->mcr_rts_reg,
- com->mcr_image |= com->mcr_rts);
-#endif
- }
- COM_UNLOCK();
- critical_exit();
- if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
- ttwwakeup(tp);
- splx(s);
- return;
- }
- if (tp->t_outq.c_cc != 0) {
- struct lbq *qp;
- struct lbq *next;
-
- if (!com->obufs[0].l_queued) {
-#ifdef CyDebug
- started = TRUE;
-#endif
- com->obufs[0].l_tail
- = com->obuf1 + q_to_b(&tp->t_outq, com->obuf1,
- sizeof com->obuf1);
- com->obufs[0].l_next = NULL;
- com->obufs[0].l_queued = TRUE;
- critical_enter();
- COM_LOCK();
- if (com->state & CS_BUSY) {
- qp = com->obufq.l_next;
- while ((next = qp->l_next) != NULL)
- qp = next;
- qp->l_next = &com->obufs[0];
- } else {
- com->obufq.l_head = com->obufs[0].l_head;
- com->obufq.l_tail = com->obufs[0].l_tail;
- com->obufq.l_next = &com->obufs[0];
- com->state |= CS_BUSY;
- if (com->state >= (CS_BUSY | CS_TTGO
- | CS_ODEVREADY))
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable
- & ~CD1400_SRER_TXMPTY)
- | CD1400_SRER_TXRDY);
- }
- COM_UNLOCK();
- critical_exit();
- }
- if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) {
-#ifdef CyDebug
- started = TRUE;
-#endif
- com->obufs[1].l_tail
- = com->obuf2 + q_to_b(&tp->t_outq, com->obuf2,
- sizeof com->obuf2);
- com->obufs[1].l_next = NULL;
- com->obufs[1].l_queued = TRUE;
- critical_enter();
- COM_LOCK();
- if (com->state & CS_BUSY) {
- qp = com->obufq.l_next;
- while ((next = qp->l_next) != NULL)
- qp = next;
- qp->l_next = &com->obufs[1];
- } else {
- com->obufq.l_head = com->obufs[1].l_head;
- com->obufq.l_tail = com->obufs[1].l_tail;
- com->obufq.l_next = &com->obufs[1];
- com->state |= CS_BUSY;
- if (com->state >= (CS_BUSY | CS_TTGO
- | CS_ODEVREADY))
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable
- & ~CD1400_SRER_TXMPTY)
- | CD1400_SRER_TXRDY);
- }
- COM_UNLOCK();
- critical_exit();
- }
- tp->t_state |= TS_BUSY;
- }
-#ifdef CyDebug
- if (started)
- ++com->start_real;
-#endif
-#if 0
- critical_enter();
- COM_LOCK();
- if (com->state >= (CS_BUSY | CS_TTGO))
- siointr1(com); /* fake interrupt to start output */
- COM_UNLOCK();
- critical_exit();
-#endif
- ttwwakeup(tp);
- splx(s);
-}
-
-static void
-comstop(tp, rw)
- struct tty *tp;
- int rw;
-{
- struct com_s *com;
- bool_t wakeup_etc;
-
- com = com_addr(DEV_TO_UNIT(tp->t_dev));
- wakeup_etc = FALSE;
- critical_enter();
- COM_LOCK();
- if (rw & FWRITE) {
- com->obufs[0].l_queued = FALSE;
- com->obufs[1].l_queued = FALSE;
- if (com->extra_state & CSE_ODONE) {
- com_events -= LOTS_OF_EVENTS;
- com->extra_state &= ~CSE_ODONE;
- if (com->etc != ETC_NONE) {
- if (com->etc == ETC_BREAK_ENDED)
- com->etc = ETC_NONE;
- wakeup_etc = TRUE;
- }
- }
- com->tp->t_state &= ~TS_BUSY;
- if (com->state & CS_ODONE)
- com_events -= LOTS_OF_EVENTS;
- com->state &= ~(CS_ODONE | CS_BUSY);
- }
- if (rw & FREAD) {
- /* XXX no way to reset only input fifo. */
- com_events -= (com->iptr - com->ibuf);
- com->iptr = com->ibuf;
- }
- COM_UNLOCK();
- critical_exit();
- if (wakeup_etc)
- wakeup(&com->etc);
- if (rw & FWRITE && com->etc == ETC_NONE)
- cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
- comstart(tp);
-}
-
-static int
-commctl(com, bits, how)
- struct com_s *com;
- int bits;
- int how;
-{
- int mcr;
- int msr;
-
- if (how == DMGET) {
- if (com->channel_control & CD1400_CCR_RCVEN)
- bits |= TIOCM_LE;
- mcr = com->mcr_image;
- if (mcr & com->mcr_dtr)
- bits |= TIOCM_DTR;
- if (mcr & com->mcr_rts)
- /* XXX wired on for Cyclom-8Ys */
- bits |= TIOCM_RTS;
-
- /*
- * We must read the modem status from the hardware because
- * we don't generate modem status change interrupts for all
- * changes, so com->prev_modem_status is not guaranteed to
- * be up to date. This is safe, unlike for sio, because
- * reading the status register doesn't clear pending modem
- * status change interrupts.
- */
- msr = cd_getreg(com, CD1400_MSVR2);
-
- if (msr & MSR_CTS)
- bits |= TIOCM_CTS;
- if (msr & MSR_DCD)
- bits |= TIOCM_CD;
- if (msr & MSR_DSR)
- bits |= TIOCM_DSR;
- if (msr & MSR_RI)
- /* XXX not connected except for Cyclom-16Y? */
- bits |= TIOCM_RI;
- return (bits);
- }
- mcr = 0;
- if (bits & TIOCM_DTR)
- mcr |= com->mcr_dtr;
- if (bits & TIOCM_RTS)
- mcr |= com->mcr_rts;
- critical_enter();
- COM_LOCK();
- switch (how) {
- case DMSET:
- com->mcr_image = mcr;
- cd_setreg(com, CD1400_MSVR1, mcr);
- cd_setreg(com, CD1400_MSVR2, mcr);
- break;
- case DMBIS:
- com->mcr_image = mcr = com->mcr_image | mcr;
- cd_setreg(com, CD1400_MSVR1, mcr);
- cd_setreg(com, CD1400_MSVR2, mcr);
- break;
- case DMBIC:
- com->mcr_image = mcr = com->mcr_image & ~mcr;
- cd_setreg(com, CD1400_MSVR1, mcr);
- cd_setreg(com, CD1400_MSVR2, mcr);
- break;
- }
- COM_UNLOCK();
- critical_exit();
- return (0);
-}
-
-static void
-siosettimeout()
-{
- struct com_s *com;
- bool_t someopen;
- int unit;
-
- /*
- * Set our timeout period to 1 second if no polled devices are open.
- * Otherwise set it to max(1/200, 1/hz).
- * Enable timeouts iff some device is open.
- */
- untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
- sio_timeout = hz;
- someopen = FALSE;
- for (unit = 0; unit < NSIO; ++unit) {
- com = com_addr(unit);
- if (com != NULL && com->tp != NULL
- && com->tp->t_state & TS_ISOPEN) {
- someopen = TRUE;
-#if 0
- if (com->poll || com->poll_output) {
- sio_timeout = hz > 200 ? hz / 200 : 1;
- break;
- }
-#endif
- }
- }
- if (someopen) {
- sio_timeouts_until_log = hz / sio_timeout;
- sio_timeout_handle = timeout(comwakeup, (void *)NULL,
- sio_timeout);
- } else {
- /* Flush error messages, if any. */
- sio_timeouts_until_log = 1;
- comwakeup((void *)NULL);
- untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
- }
-}
-
-static void
-comwakeup(chan)
- void *chan;
-{
- struct com_s *com;
- int unit;
-
- sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout);
-
-#if 0
- /*
- * Recover from lost output interrupts.
- * Poll any lines that don't use interrupts.
- */
- for (unit = 0; unit < NSIO; ++unit) {
- com = com_addr(unit);
- if (com != NULL
- && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) {
- critical_enter();
- COM_LOCK();
- siointr1(com);
- COM_UNLOCK();
- critical_exit();
- }
- }
-#endif
-
- /*
- * Check for and log errors, but not too often.
- */
- if (--sio_timeouts_until_log > 0)
- return;
- sio_timeouts_until_log = hz / sio_timeout;
- for (unit = 0; unit < NSIO; ++unit) {
- int errnum;
-
- com = com_addr(unit);
- if (com == NULL)
- continue;
- for (errnum = 0; errnum < CE_NTYPES; ++errnum) {
- u_int delta;
- u_long total;
-
- critical_enter();
- COM_LOCK();
- delta = com->delta_error_counts[errnum];
- com->delta_error_counts[errnum] = 0;
- COM_UNLOCK();
- critical_exit();
- if (delta == 0)
- continue;
- total = com->error_counts[errnum] += delta;
- log(LOG_ERR, "cy%d: %u more %s%s (total %lu)\n",
- unit, delta, error_desc[errnum],
- delta == 1 ? "" : "s", total);
- }
- }
-}
-
-static void
-disc_optim(tp, t, com)
- struct tty *tp;
- struct termios *t;
- struct com_s *com;
-{
-#ifndef SOFT_HOTCHAR
- u_char opt;
-#endif
-
- /*
- * XXX can skip a lot more cases if Smarts. Maybe
- * (IGNCR | ISTRIP | IXON) in c_iflag. But perhaps we
- * shouldn't skip if (TS_CNTTB | TS_LNCH) is set in t_state.
- */
- if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
- && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
- && (!(t->c_iflag & PARMRK)
- || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
- && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
- && linesw[tp->t_line].l_rint == ttyinput)
- tp->t_state |= TS_CAN_BYPASS_L_RINT;
- else
- tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
- com->hotchar = linesw[tp->t_line].l_hotchar;
-#ifndef SOFT_HOTCHAR
- opt = com->cor[2] & ~CD1400_COR3_SCD34;
- if (com->hotchar != 0) {
- cd_setreg(com, CD1400_SCHR3, com->hotchar);
- cd_setreg(com, CD1400_SCHR4, com->hotchar);
- opt |= CD1400_COR3_SCD34;
- }
- if (opt != com->cor[2]) {
- cd_setreg(com, CD1400_COR3, com->cor[2] = opt);
- cd1400_channel_cmd(com, CD1400_CCR_CMDCORCHG | CD1400_CCR_COR3);
- }
-#endif
-}
-
-#ifdef Smarts
-/* standard line discipline input routine */
-int
-cyinput(c, tp)
- int c;
- struct tty *tp;
-{
- /* XXX duplicate ttyinput(), but without the IXOFF/IXON/ISTRIP/IPARMRK
- * bits, as they are done by the CD1400. Hardly worth the effort,
- * given that high-throughput sessions are raw anyhow.
- */
-}
-#endif /* Smarts */
-
-static int
-comspeed(speed, cy_clock, prescaler_io)
- speed_t speed;
- u_long cy_clock;
- int *prescaler_io;
-{
- int actual;
- int error;
- int divider;
- int prescaler;
- int prescaler_unit;
-
- if (speed == 0)
- return (0);
- if (speed < 0 || speed > 150000)
- return (-1);
-
- /* determine which prescaler to use */
- for (prescaler_unit = 4, prescaler = 2048; prescaler_unit;
- prescaler_unit--, prescaler >>= 2) {
- if (cy_clock / prescaler / speed > 63)
- break;
- }
-
- divider = (cy_clock / prescaler * 2 / speed + 1) / 2; /* round off */
- if (divider > 255)
- divider = 255;
- actual = cy_clock/prescaler/divider;
-
- /* 10 times error in percent: */
- error = ((actual - (long)speed) * 2000 / (long)speed + 1) / 2;
-
- /* 3.0% max error tolerance */
- if (error < -30 || error > 30)
- return (-1);
-
-#if 0
- printf("prescaler = %d (%d)\n", prescaler, prescaler_unit);
- printf("divider = %d (%x)\n", divider, divider);
- printf("actual = %d\n", actual);
- printf("error = %d\n", error);
-#endif
-
- *prescaler_io = prescaler_unit;
- return (divider);
-}
-
-static void
-cd1400_channel_cmd(com, cmd)
- struct com_s *com;
- int cmd;
-{
- cd1400_channel_cmd_wait(com);
- cd_setreg(com, CD1400_CCR, cmd);
- cd1400_channel_cmd_wait(com);
-}
-
-static void
-cd1400_channel_cmd_wait(com)
- struct com_s *com;
-{
- struct timeval start;
- struct timeval tv;
- long usec;
-
- if (cd_getreg(com, CD1400_CCR) == 0)
- return;
- microtime(&start);
- for (;;) {
- if (cd_getreg(com, CD1400_CCR) == 0)
- return;
- microtime(&tv);
- usec = 1000000 * (tv.tv_sec - start.tv_sec) +
- tv.tv_usec - start.tv_usec;
- if (usec >= 5000) {
- log(LOG_ERR,
- "cy%d: channel command timeout (%ld usec)\n",
- com->unit, usec);
- return;
- }
- }
-}
-
-static void
-cd_etc(com, etc)
- struct com_s *com;
- int etc;
-{
-
- /*
- * We can't change the hardware's ETC state while there are any
- * characters in the tx fifo, since those characters would be
- * interpreted as commands! Unputting characters from the fifo
- * is difficult, so we wait up to 12 character times for the fifo
- * to drain. The command will be delayed for up to 2 character
- * times for the tx to become empty. Unputting characters from
- * the tx holding and shift registers is impossible, so we wait
- * for the tx to become empty so that the command is sure to be
- * executed soon after we issue it.
- */
- critical_enter();
- COM_LOCK();
- if (com->etc == etc)
- goto wait;
- if ((etc == CD1400_ETC_SENDBREAK
- && (com->etc == ETC_BREAK_STARTING
- || com->etc == ETC_BREAK_STARTED))
- || (etc == CD1400_ETC_STOPBREAK
- && (com->etc == ETC_BREAK_ENDING || com->etc == ETC_BREAK_ENDED
- || com->etc == ETC_NONE))) {
- COM_UNLOCK();
- critical_exit();
- return;
- }
- com->etc = etc;
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable & ~CD1400_SRER_TXRDY) | CD1400_SRER_TXMPTY);
-wait:
- COM_UNLOCK();
- critical_exit();
- while (com->etc == etc
- && tsleep(&com->etc, TTIPRI | PCATCH, "cyetc", 0) == 0)
- continue;
-}
-
-static int
-cd_getreg(com, reg)
- struct com_s *com;
- int reg;
-{
- struct com_s *basecom;
- u_char car;
- int cy_align;
- register_t eflags;
- cy_addr iobase;
- int val;
-
- basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1));
- car = com->unit & CD1400_CAR_CHAN;
- cy_align = com->cy_align;
- iobase = com->iobase;
- eflags = read_eflags();
- critical_enter();
- if (eflags & PSL_I)
- COM_LOCK();
- if (basecom->car != car)
- cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car);
- val = cd_inb(iobase, reg, cy_align);
- if (eflags & PSL_I)
- COM_UNLOCK();
- critical_exit();
- return (val);
-}
-
-static void
-cd_setreg(com, reg, val)
- struct com_s *com;
- int reg;
- int val;
-{
- struct com_s *basecom;
- u_char car;
- int cy_align;
- register_t eflags;
- cy_addr iobase;
-
- basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1));
- car = com->unit & CD1400_CAR_CHAN;
- cy_align = com->cy_align;
- iobase = com->iobase;
- eflags = read_eflags();
- critical_enter();
- if (eflags & PSL_I)
- COM_LOCK();
- if (basecom->car != car)
- cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car);
- cd_outb(iobase, reg, cy_align, val);
- if (eflags & PSL_I)
- COM_UNLOCK();
- critical_exit();
-}
-
-#ifdef CyDebug
-/* useful in ddb */
-void
-cystatus(unit)
- int unit;
-{
- struct com_s *com;
- cy_addr iobase;
- u_int ocount;
- struct tty *tp;
-
- com = com_addr(unit);
- printf("info for channel %d\n", unit);
- printf("------------------\n");
- printf("total cyclom service probes:\t%d\n", cy_svrr_probes);
- printf("calls to upper layer:\t\t%d\n", cy_timeouts);
- if (com == NULL)
- return;
- iobase = com->iobase;
- printf("\n");
- printf("cd1400 base address:\\tt%p\n", iobase);
- printf("saved channel_control:\t\t0x%02x\n", com->channel_control);
- printf("saved cor1-3:\t\t\t0x%02x 0x%02x 0x%02x\n",
- com->cor[0], com->cor[1], com->cor[2]);
- printf("service request enable reg:\t0x%02x (0x%02x cached)\n",
- cd_getreg(com, CD1400_SRER), com->intr_enable);
- printf("service request register:\t0x%02x\n",
- cd_inb(iobase, CD1400_SVRR, com->cy_align));
- printf("modem status:\t\t\t0x%02x (0x%02x cached)\n",
- cd_getreg(com, CD1400_MSVR2), com->prev_modem_status);
- printf("rx/tx/mdm interrupt registers:\t0x%02x 0x%02x 0x%02x\n",
- cd_inb(iobase, CD1400_RIR, com->cy_align),
- cd_inb(iobase, CD1400_TIR, com->cy_align),
- cd_inb(iobase, CD1400_MIR, com->cy_align));
- printf("\n");
- printf("com state:\t\t\t0x%02x\n", com->state);
- printf("calls to comstart():\t\t%d (%d useful)\n",
- com->start_count, com->start_real);
- printf("rx buffer chars free:\t\t%d\n", com->iptr - com->ibuf);
- ocount = 0;
- if (com->obufs[0].l_queued)
- ocount += com->obufs[0].l_tail - com->obufs[0].l_head;
- if (com->obufs[1].l_queued)
- ocount += com->obufs[1].l_tail - com->obufs[1].l_head;
- printf("tx buffer chars:\t\t%u\n", ocount);
- printf("received chars:\t\t\t%d\n", com->bytes_in);
- printf("received exceptions:\t\t%d\n", com->recv_exception);
- printf("modem signal deltas:\t\t%d\n", com->mdm);
- printf("transmitted chars:\t\t%d\n", com->bytes_out);
- printf("\n");
- tp = com->tp;
- if (tp != NULL) {
- printf("tty state:\t\t\t0x%08x\n", tp->t_state);
- printf(
- "upper layer queue lengths:\t%d raw, %d canon, %d output\n",
- tp->t_rawq.c_cc, tp->t_canq.c_cc, tp->t_outq.c_cc);
- } else
- printf("tty state:\t\t\tclosed\n");
-}
-#endif /* CyDebug */
diff --git a/sys/dev/cy/cy_isa.c b/sys/dev/cy/cy_isa.c
deleted file mode 100644
index 4e2e499da1a6..000000000000
--- a/sys/dev/cy/cy_isa.c
+++ /dev/null
@@ -1,2960 +0,0 @@
-/*-
- * cyclades cyclom-y serial driver
- * Andrew Herbert <andrew@werple.apana.org.au>, 17 August 1993
- *
- * Copyright (c) 1993 Andrew Herbert.
- * 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 Andrew Herbert may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-#include "opt_compat.h"
-#include "cy.h"
-
-/*
- * TODO:
- * Atomic COR change.
- * Consoles.
- */
-
-/*
- * Temporary compile-time configuration options.
- */
-#define RxFifoThreshold (CD1400_RX_FIFO_SIZE / 2)
- /* Number of chars in the receiver FIFO before an
- * an interrupt is generated. Should depend on
- * line speed. Needs to be about 6 on a 486DX33
- * for 4 active ports at 115200 bps. Why doesn't
- * 10 work?
- */
-#define PollMode /* Use polling-based irq service routine, not the
- * hardware svcack lines. Must be defined for
- * Cyclom-16Y boards. Less efficient for Cyclom-8Ys,
- * and stops 4 * 115200 bps from working.
- */
-#undef Smarts /* Enable slightly more CD1400 intelligence. Mainly
- * the output CR/LF processing, plus we can avoid a
- * few checks usually done in ttyinput().
- *
- * XXX not fully implemented, and not particularly
- * worthwhile.
- */
-#undef CyDebug /* Include debugging code (not very expensive). */
-
-/* These will go away. */
-#undef SOFT_CTS_OFLOW
-#define SOFT_HOTCHAR
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/conf.h>
-#include <sys/fcntl.h>
-#include <sys/interrupt.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/syslog.h>
-#include <sys/tty.h>
-
-#include <machine/psl.h>
-
-#include <i386/isa/isa_device.h>
-#include <i386/isa/cyreg.h>
-#include <i386/isa/ic/cd1400.h>
-
-#ifndef COMPAT_OLDISA
-#error "The cy device requires the old isa compatibility shims"
-#endif
-
-#ifdef SMP
-
-#include <machine/smptests.h> /** xxx_LOCK */
-
-#ifdef USE_COMLOCK
-#define COM_LOCK() mtx_lock_spin(&com_mtx)
-#define COM_UNLOCK() mtx_unlock_spin(&com_mtx)
-#else
-#define COM_LOCK()
-#define COM_UNLOCK()
-#endif /* USE_COMLOCK */
-
-#else /* SMP */
-
-#define COM_LOCK()
-#define COM_UNLOCK()
-
-#endif /* SMP */
-
-extern struct mtx com_mtx;
-
-/*
- * Dictionary so that I can name everything *sio* or *com* to compare with
- * sio.c. There is also lots of ugly formatting and unnecessary ifdefs to
- * simplify the comparision. These will go away.
- */
-#define LSR_BI CD1400_RDSR_BREAK
-#define LSR_FE CD1400_RDSR_FE
-#define LSR_OE CD1400_RDSR_OE
-#define LSR_PE CD1400_RDSR_PE
-#define MCR_DTR CD1400_MSVR2_DTR
-#define MCR_RTS CD1400_MSVR1_RTS
-#define MSR_CTS CD1400_MSVR2_CTS
-#define MSR_DCD CD1400_MSVR2_CD
-#define MSR_DSR CD1400_MSVR2_DSR
-#define MSR_RI CD1400_MSVR2_RI
-#define NSIO (NCY * CY_MAX_PORTS)
-#define comconsole cyconsole
-#define comdefaultrate cydefaultrate
-#define com_events cy_events
-#define comhardclose cyhardclose
-#define commctl cymctl
-#define comparam cyparam
-#define comspeed cyspeed
-#define comstart cystart
-#define comwakeup cywakeup
-#define p_com_addr p_cy_addr
-#define sioattach cyattach
-#define sioclose cyclose
-#define siodriver cydriver
-#define siodtrwakeup cydtrwakeup
-#define sioinput cyinput
-#define siointr cyintr
-#define siointr1 cyintr1
-#define sioioctl cyioctl
-#define sioopen cyopen
-#define siopoll cypoll
-#define sioprobe cyprobe
-#define siosettimeout cysettimeout
-#define siosetwater cysetwater
-#define comstop cystop
-#define siowrite cywrite
-#define sio_ih cy_ih
-#define sio_irec cy_irec
-#define sio_timeout cy_timeout
-#define sio_timeout_handle cy_timeout_handle
-#define sio_timeouts_until_log cy_timeouts_until_log
-
-#define CY_MAX_PORTS (CD1400_NO_OF_CHANNELS * CY_MAX_CD1400s)
-
-/* We encode the cyclom unit number (cyu) in spare bits in the IVR's. */
-#define CD1400_xIVR_CHAN_SHIFT 3
-#define CD1400_xIVR_CHAN 0x1F
-
-/*
- * ETC states. com->etc may also contain a hardware ETC command value,
- * meaning that execution of that command is pending.
- */
-#define ETC_NONE 0 /* we depend on bzero() setting this */
-#define ETC_BREAK_STARTING 1
-#define ETC_BREAK_STARTED 2
-#define ETC_BREAK_ENDING 3
-#define ETC_BREAK_ENDED 4
-
-#define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */
-
-#define CALLOUT_MASK 0x80
-#define CONTROL_MASK 0x60
-#define CONTROL_INIT_STATE 0x20
-#define CONTROL_LOCK_STATE 0x40
-#define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
-#define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
-/*
- * Not all of the magic is parametrized in the following macros. 16 and
- * 0xff are related to the bitfields in a udev_t. CY_MAX_PORTS must be
- * ((0xff & ~MINOR_MAGIC_MASK) + 1) for things to work.
- */
-#define MINOR_TO_UNIT(mynor) (((mynor) >> 16) * CY_MAX_PORTS \
- | (((mynor) & 0xff) & ~MINOR_MAGIC_MASK))
-#define UNIT_TO_MINOR(unit) (((unit) / CY_MAX_PORTS) << 16 \
- | (((unit) & 0xff) & ~MINOR_MAGIC_MASK))
-
-/*
- * com state bits.
- * (CS_BUSY | CS_TTGO) and (CS_BUSY | CS_TTGO | CS_ODEVREADY) must be higher
- * than the other bits so that they can be tested as a group without masking
- * off the low bits.
- *
- * The following com and tty flags correspond closely:
- * CS_BUSY = TS_BUSY (maintained by comstart(), siopoll() and
- * comstop())
- * CS_TTGO = ~TS_TTSTOP (maintained by comparam() and comstart())
- * CS_CTS_OFLOW = CCTS_OFLOW (maintained by comparam())
- * CS_RTS_IFLOW = CRTS_IFLOW (maintained by comparam())
- * TS_FLUSH is not used.
- * XXX I think TIOCSETA doesn't clear TS_TTSTOP when it clears IXON.
- * XXX CS_*FLOW should be CF_*FLOW in com->flags (control flags not state).
- */
-#define CS_BUSY 0x80 /* output in progress */
-#define CS_TTGO 0x40 /* output not stopped by XOFF */
-#define CS_ODEVREADY 0x20 /* external device h/w ready (CTS) */
-#define CS_CHECKMSR 1 /* check of MSR scheduled */
-#define CS_CTS_OFLOW 2 /* use CTS output flow control */
-#define CS_DTR_OFF 0x10 /* DTR held off */
-#define CS_ODONE 4 /* output completed */
-#define CS_RTS_IFLOW 8 /* use RTS input flow control */
-#define CSE_ODONE 1 /* output transmitted */
-
-static char const * const error_desc[] = {
-#define CE_OVERRUN 0
- "silo overflow",
-#define CE_INTERRUPT_BUF_OVERFLOW 1
- "interrupt-level buffer overflow",
-#define CE_TTY_BUF_OVERFLOW 2
- "tty-level buffer overflow",
-};
-
-#define CE_NTYPES 3
-#define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum])
-
-/* types. XXX - should be elsewhere */
-typedef u_char bool_t; /* boolean */
-typedef u_char volatile *cy_addr;
-
-/* queue of linear buffers */
-struct lbq {
- u_char *l_head; /* next char to process */
- u_char *l_tail; /* one past the last char to process */
- struct lbq *l_next; /* next in queue */
- bool_t l_queued; /* nonzero if queued */
-};
-
-/* com device structure */
-struct com_s {
- u_char state; /* miscellaneous flag bits */
- bool_t active_out; /* nonzero if the callout device is open */
-#if 0
- u_char cfcr_image; /* copy of value written to CFCR */
-#endif
- u_char etc; /* pending Embedded Transmit Command */
- u_char extra_state; /* more flag bits, separate for order trick */
-#if 0
- u_char fifo_image; /* copy of value written to FIFO */
-#endif
- u_char gfrcr_image; /* copy of value read from GFRCR */
-#if 0
- bool_t hasfifo; /* nonzero for 16550 UARTs */
- bool_t loses_outints; /* nonzero if device loses output interrupts */
-#endif
- u_char mcr_dtr; /* MCR bit that is wired to DTR */
- u_char mcr_image; /* copy of value written to MCR */
- u_char mcr_rts; /* MCR bit that is wired to RTS */
-#if 0
-#ifdef COM_MULTIPORT
- bool_t multiport; /* is this unit part of a multiport device? */
-#endif /* COM_MULTIPORT */
- bool_t no_irq; /* nonzero if irq is not attached */
- bool_t poll; /* nonzero if polling is required */
- bool_t poll_output; /* nonzero if polling for output is required */
-#endif
- int unit; /* unit number */
- int dtr_wait; /* time to hold DTR down on close (* 1/hz) */
-#if 0
- u_int tx_fifo_size;
-#endif
- u_int wopeners; /* # processes waiting for DCD in open() */
-
- /*
- * The high level of the driver never reads status registers directly
- * because there would be too many side effects to handle conveniently.
- * Instead, it reads copies of the registers stored here by the
- * interrupt handler.
- */
- u_char last_modem_status; /* last MSR read by intr handler */
- u_char prev_modem_status; /* last MSR handled by high level */
-
- u_char hotchar; /* ldisc-specific char to be handled ASAP */
- u_char *ibuf; /* start of input buffer */
- u_char *ibufend; /* end of input buffer */
- u_char *ibufold; /* old input buffer, to be freed */
- u_char *ihighwater; /* threshold in input buffer */
- u_char *iptr; /* next free spot in input buffer */
- int ibufsize; /* size of ibuf (not include error bytes) */
- int ierroff; /* offset of error bytes in ibuf */
-
- struct lbq obufq; /* head of queue of output buffers */
- struct lbq obufs[2]; /* output buffers */
-
- int cy_align; /* index for register alignment */
- cy_addr cy_iobase; /* base address of this port's cyclom */
- cy_addr iobase; /* base address of this port's cd1400 */
- int mcr_rts_reg; /* cd1400 reg number of reg holding mcr_rts */
-
- struct tty *tp; /* cross reference */
-
- /* Initial state. */
- struct termios it_in; /* should be in struct tty */
- struct termios it_out;
-
- /* Lock state. */
- struct termios lt_in; /* should be in struct tty */
- struct termios lt_out;
-
- bool_t do_timestamp;
- bool_t do_dcd_timestamp;
- struct timeval timestamp;
- struct timeval dcd_timestamp;
-
- u_long bytes_in; /* statistics */
- u_long bytes_out;
- u_int delta_error_counts[CE_NTYPES];
- u_long error_counts[CE_NTYPES];
-
- u_int recv_exception; /* exception chars received */
- u_int mdm; /* modem signal changes */
-#ifdef CyDebug
- u_int start_count; /* no. of calls to comstart() */
- u_int start_real; /* no. of calls that did something */
-#endif
- u_char car; /* CD1400 CAR shadow (if first unit in cd) */
- u_char channel_control;/* CD1400 CCR control command shadow */
- u_char cor[3]; /* CD1400 COR1-3 shadows */
- u_char intr_enable; /* CD1400 SRER shadow */
-
- /*
- * Data area for output buffers. Someday we should build the output
- * buffer queue without copying data.
- */
- u_char obuf1[256];
- u_char obuf2[256];
-};
-
-/* PCI driver entry point. */
-int cyattach_common(cy_addr cy_iobase, int cy_align);
-ointhand2_t siointr;
-
-static int cy_units(cy_addr cy_iobase, int cy_align);
-static int sioattach(struct isa_device *dev);
-static void cd1400_channel_cmd(struct com_s *com, int cmd);
-static void cd1400_channel_cmd_wait(struct com_s *com);
-static void cd_etc(struct com_s *com, int etc);
-static int cd_getreg(struct com_s *com, int reg);
-static void cd_setreg(struct com_s *com, int reg, int val);
-static timeout_t siodtrwakeup;
-static void comhardclose(struct com_s *com);
-static void sioinput(struct com_s *com);
-#if 0
-static void siointr1(struct com_s *com);
-#endif
-static int commctl(struct com_s *com, int bits, int how);
-static int comparam(struct tty *tp, struct termios *t);
-static void siopoll(void *arg);
-static int sioprobe(struct isa_device *dev);
-static void siosettimeout(void);
-static int siosetwater(struct com_s *com, speed_t speed);
-static int comspeed(speed_t speed, u_long cy_clock, int *prescaler_io);
-static void comstart(struct tty *tp);
-static void comstop(struct tty *tp, int rw);
-static timeout_t comwakeup;
-static void disc_optim(struct tty *tp, struct termios *t,
- struct com_s *com);
-
-#ifdef CyDebug
-void cystatus(int unit);
-#endif
-
-static char driver_name[] = "cy";
-
-/* table and macro for fast conversion from a unit number to its com struct */
-static struct com_s *p_com_addr[NSIO];
-#define com_addr(unit) (p_com_addr[unit])
-
-struct isa_driver siodriver = {
- INTR_TYPE_TTY | INTR_FAST,
- sioprobe,
- sioattach,
- driver_name
-};
-COMPAT_ISA_DRIVER(cy, cydriver); /* XXX */
-
-static d_open_t sioopen;
-static d_close_t sioclose;
-static d_write_t siowrite;
-static d_ioctl_t sioioctl;
-
-#define CDEV_MAJOR 48
-static struct cdevsw sio_cdevsw = {
- .d_open = sioopen,
- .d_close = sioclose,
- .d_read = ttyread,
- .d_write = siowrite,
- .d_ioctl = sioioctl,
- .d_poll = ttypoll,
- .d_name = driver_name,
- .d_maj = CDEV_MAJOR,
- .d_flags = D_TTY,
- .d_kqfilter = ttykqfilter,
-};
-
-static int comconsole = -1;
-static speed_t comdefaultrate = TTYDEF_SPEED;
-static u_int com_events; /* input chars + weighted output completions */
-static void *sio_ih;
-static int sio_timeout;
-static int sio_timeouts_until_log;
-static struct callout_handle sio_timeout_handle
- = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
-
-#ifdef CyDebug
-static u_int cd_inbs;
-static u_int cy_inbs;
-static u_int cd_outbs;
-static u_int cy_outbs;
-static u_int cy_svrr_probes;
-static u_int cy_timeouts;
-#endif
-
-static int cy_chip_offset[] = {
- 0x0000, 0x0400, 0x0800, 0x0c00, 0x0200, 0x0600, 0x0a00, 0x0e00,
-};
-static int cy_nr_cd1400s[NCY];
-static int cy_total_devices;
-#undef RxFifoThreshold
-static int volatile RxFifoThreshold = (CD1400_RX_FIFO_SIZE / 2);
-
-static int
-sioprobe(dev)
- struct isa_device *dev;
-{
- cy_addr iobase;
-
- iobase = (cy_addr)dev->id_maddr;
-
- /* Cyclom-16Y hardware reset (Cyclom-8Ys don't care) */
- cy_inb(iobase, CY16_RESET, 0); /* XXX? */
- DELAY(500); /* wait for the board to get its act together */
-
- /* this is needed to get the board out of reset */
- cy_outb(iobase, CY_CLEAR_INTR, 0, 0);
- DELAY(500);
-
- return (cy_units(iobase, 0) == 0 ? 0 : -1);
-}
-
-static int
-cy_units(cy_iobase, cy_align)
- cy_addr cy_iobase;
- int cy_align;
-{
- int cyu;
- u_char firmware_version;
- int i;
- cy_addr iobase;
-
- for (cyu = 0; cyu < CY_MAX_CD1400s; ++cyu) {
- iobase = cy_iobase + (cy_chip_offset[cyu] << cy_align);
-
- /* wait for chip to become ready for new command */
- for (i = 0; i < 10; i++) {
- DELAY(50);
- if (!cd_inb(iobase, CD1400_CCR, cy_align))
- break;
- }
-
- /* clear the GFRCR register */
- cd_outb(iobase, CD1400_GFRCR, cy_align, 0);
-
- /* issue a reset command */
- cd_outb(iobase, CD1400_CCR, cy_align,
- CD1400_CCR_CMDRESET | CD1400_CCR_FULLRESET);
-
- /* XXX bogus initialization to avoid a gcc bug/warning. */
- firmware_version = 0;
-
- /* wait for the CD1400 to initialize itself */
- for (i = 0; i < 200; i++) {
- DELAY(50);
-
- /* retrieve firmware version */
- firmware_version = cd_inb(iobase, CD1400_GFRCR,
- cy_align);
- if ((firmware_version & 0xf0) == 0x40)
- break;
- }
-
- /*
- * Anything in the 0x40-0x4F range is fine.
- * If one CD1400 is bad then we don't support higher
- * numbered good ones on this board.
- */
- if ((firmware_version & 0xf0) != 0x40)
- break;
- }
- return (cyu);
-}
-
-static int
-sioattach(isdp)
- struct isa_device *isdp;
-{
- int adapter;
-
- adapter = cyattach_common((cy_addr) isdp->id_maddr, 0);
- if (adapter < 0)
- return (0);
-
- /*
- * XXX
- * This kludge is to allow ISA/PCI device specifications in the
- * kernel config file to be in any order.
- */
- if (isdp->id_unit != adapter) {
- printf("cy%d: attached as cy%d\n", isdp->id_unit, adapter);
- isdp->id_unit = adapter; /* XXX */
- }
- isdp->id_ointr = siointr;
- /* isdp->id_ri_flags |= RI_FAST; XXX unimplemented - use newbus! */
- return (1);
-}
-
-int
-cyattach_common(cy_iobase, cy_align)
- cy_addr cy_iobase;
- int cy_align;
-{
- int adapter;
- int cyu;
- u_char firmware_version;
- cy_addr iobase;
- int minorbase;
- int ncyu;
- int unit;
-
- adapter = cy_total_devices;
- if ((u_int)adapter >= NCY) {
- printf(
- "cy%d: can't attach adapter: insufficient cy devices configured\n",
- adapter);
- return (-1);
- }
- ncyu = cy_units(cy_iobase, cy_align);
- if (ncyu == 0)
- return (-1);
- cy_nr_cd1400s[adapter] = ncyu;
- cy_total_devices++;
-
- unit = adapter * CY_MAX_PORTS;
- for (cyu = 0; cyu < ncyu; ++cyu) {
- int cdu;
-
- iobase = (cy_addr) (cy_iobase
- + (cy_chip_offset[cyu] << cy_align));
- firmware_version = cd_inb(iobase, CD1400_GFRCR, cy_align);
-
- /* Set up a receive timeout period of than 1+ ms. */
- cd_outb(iobase, CD1400_PPR, cy_align,
- howmany(CY_CLOCK(firmware_version)
- / CD1400_PPR_PRESCALER, 1000));
-
- for (cdu = 0; cdu < CD1400_NO_OF_CHANNELS; ++cdu, ++unit) {
- struct com_s *com;
- int s;
-
- com = malloc(sizeof *com, M_DEVBUF, M_NOWAIT | M_ZERO);
- if (com == NULL)
- break;
- com->unit = unit;
- com->gfrcr_image = firmware_version;
- if (CY_RTS_DTR_SWAPPED(firmware_version)) {
- com->mcr_dtr = MCR_RTS;
- com->mcr_rts = MCR_DTR;
- com->mcr_rts_reg = CD1400_MSVR2;
- } else {
- com->mcr_dtr = MCR_DTR;
- com->mcr_rts = MCR_RTS;
- com->mcr_rts_reg = CD1400_MSVR1;
- }
- com->dtr_wait = 3 * hz;
- com->obufs[0].l_head = com->obuf1;
- com->obufs[1].l_head = com->obuf2;
-
- com->cy_align = cy_align;
- com->cy_iobase = cy_iobase;
- com->iobase = iobase;
- com->car = ~CD1400_CAR_CHAN;
-
- /*
- * We don't use all the flags from <sys/ttydefaults.h> since they
- * are only relevant for logins. It's important to have echo off
- * initially so that the line doesn't start blathering before the
- * echo flag can be turned off.
- */
- com->it_in.c_iflag = 0;
- com->it_in.c_oflag = 0;
- com->it_in.c_cflag = TTYDEF_CFLAG;
- com->it_in.c_lflag = 0;
- if (unit == comconsole) {
- com->it_in.c_iflag = TTYDEF_IFLAG;
- com->it_in.c_oflag = TTYDEF_OFLAG;
- com->it_in.c_cflag = TTYDEF_CFLAG | CLOCAL;
- com->it_in.c_lflag = TTYDEF_LFLAG;
- com->lt_out.c_cflag = com->lt_in.c_cflag = CLOCAL;
- }
- if (siosetwater(com, com->it_in.c_ispeed) != 0) {
- free(com, M_DEVBUF);
- return (0);
- }
- termioschars(&com->it_in);
- com->it_in.c_ispeed = com->it_in.c_ospeed = comdefaultrate;
- com->it_out = com->it_in;
-
- s = spltty();
- com_addr(unit) = com;
- splx(s);
-
- if (sio_ih == NULL) {
- swi_add(&tty_ithd, "tty:cy", siopoll, NULL, SWI_TTY, 0,
- &sio_ih);
- }
- minorbase = UNIT_TO_MINOR(unit);
- make_dev(&sio_cdevsw, minorbase,
- UID_ROOT, GID_WHEEL, 0600, "ttyc%r%r", adapter,
- unit % CY_MAX_PORTS);
- make_dev(&sio_cdevsw, minorbase | CONTROL_INIT_STATE,
- UID_ROOT, GID_WHEEL, 0600, "ttyic%r%r", adapter,
- unit % CY_MAX_PORTS);
- make_dev(&sio_cdevsw, minorbase | CONTROL_LOCK_STATE,
- UID_ROOT, GID_WHEEL, 0600, "ttylc%r%r", adapter,
- unit % CY_MAX_PORTS);
- make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK,
- UID_UUCP, GID_DIALER, 0660, "cuac%r%r", adapter,
- unit % CY_MAX_PORTS);
- make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK | CONTROL_INIT_STATE,
- UID_UUCP, GID_DIALER, 0660, "cuaic%r%r", adapter,
- unit % CY_MAX_PORTS);
- make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK | CONTROL_LOCK_STATE,
- UID_UUCP, GID_DIALER, 0660, "cualc%r%r", adapter,
- unit % CY_MAX_PORTS);
- }
- }
-
- /* ensure an edge for the next interrupt */
- cy_outb(cy_iobase, CY_CLEAR_INTR, cy_align, 0);
-
- return (adapter);
-}
-
-static int
-sioopen(dev, flag, mode, td)
- dev_t dev;
- int flag;
- int mode;
- struct thread *td;
-{
- struct com_s *com;
- int error;
- int mynor;
- int s;
- struct tty *tp;
- int unit;
-
- mynor = minor(dev);
- unit = MINOR_TO_UNIT(mynor);
- if ((u_int) unit >= NSIO || (com = com_addr(unit)) == NULL)
- return (ENXIO);
- if (mynor & CONTROL_MASK)
- return (0);
- tp = dev->si_tty = com->tp = ttymalloc(com->tp);
- s = spltty();
- /*
- * We jump to this label after all non-interrupted sleeps to pick
- * up any changes of the device state.
- */
-open_top:
- while (com->state & CS_DTR_OFF) {
- error = tsleep(&com->dtr_wait, TTIPRI | PCATCH, "cydtr", 0);
- if (error != 0)
- goto out;
- }
- if (tp->t_state & TS_ISOPEN) {
- /*
- * The device is open, so everything has been initialized.
- * Handle conflicts.
- */
- if (mynor & CALLOUT_MASK) {
- if (!com->active_out) {
- error = EBUSY;
- goto out;
- }
- } else {
- if (com->active_out) {
- if (flag & O_NONBLOCK) {
- error = EBUSY;
- goto out;
- }
- error = tsleep(&com->active_out,
- TTIPRI | PCATCH, "cybi", 0);
- if (error != 0)
- goto out;
- goto open_top;
- }
- }
- if (tp->t_state & TS_XCLUDE &&
- suser(td)) {
- error = EBUSY;
- goto out;
- }
- } else {
- /*
- * The device isn't open, so there are no conflicts.
- * Initialize it. Initialization is done twice in many
- * cases: to preempt sleeping callin opens if we are
- * callout, and to complete a callin open after DCD rises.
- */
- tp->t_oproc = comstart;
- tp->t_stop = comstop;
- tp->t_param = comparam;
- tp->t_dev = dev;
- tp->t_termios = mynor & CALLOUT_MASK
- ? com->it_out : com->it_in;
-
- /* Encode per-board unit in LIVR for access in intr routines. */
- cd_setreg(com, CD1400_LIVR,
- (unit & CD1400_xIVR_CHAN) << CD1400_xIVR_CHAN_SHIFT);
-
- (void)commctl(com, TIOCM_DTR | TIOCM_RTS, DMSET);
-#if 0
- com->poll = com->no_irq;
- com->poll_output = com->loses_outints;
-#endif
- ++com->wopeners;
- error = comparam(tp, &tp->t_termios);
- --com->wopeners;
- if (error != 0)
- goto out;
-#if 0
- if (com->hasfifo) {
- /*
- * (Re)enable and flush fifos.
- *
- * Certain SMC chips cause problems if the fifos
- * are enabled while input is ready. Turn off the
- * fifo if necessary to clear the input. We test
- * the input ready bit after enabling the fifos
- * since we've already enabled them in comparam()
- * and to handle races between enabling and fresh
- * input.
- */
- while (TRUE) {
- outb(iobase + com_fifo,
- FIFO_RCV_RST | FIFO_XMT_RST
- | com->fifo_image);
- DELAY(100);
- if (!(inb(com->line_status_port) & LSR_RXRDY))
- break;
- outb(iobase + com_fifo, 0);
- DELAY(100);
- (void) inb(com->data_port);
- }
- }
-
- critical_enter();
- COM_LOCK();
- (void) inb(com->line_status_port);
- (void) inb(com->data_port);
- com->prev_modem_status = com->last_modem_status
- = inb(com->modem_status_port);
- outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY | IER_ERLS
- | IER_EMSC);
- COM_UNLOCK();
- critical_exit();
-#else /* !0 */
- /*
- * Flush fifos. This requires a full channel reset which
- * also disables the transmitter and receiver. Recover
- * from this.
- */
- cd1400_channel_cmd(com,
- CD1400_CCR_CMDRESET | CD1400_CCR_CHANRESET);
- cd1400_channel_cmd(com, com->channel_control);
-
- critical_enter();
- COM_LOCK();
- com->prev_modem_status = com->last_modem_status
- = cd_getreg(com, CD1400_MSVR2);
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = CD1400_SRER_MDMCH | CD1400_SRER_RXDATA);
- COM_UNLOCK();
- critical_exit();
-#endif /* 0 */
- /*
- * Handle initial DCD. Callout devices get a fake initial
- * DCD (trapdoor DCD). If we are callout, then any sleeping
- * callin opens get woken up and resume sleeping on "cybi"
- * instead of "cydcd".
- */
- /*
- * XXX `mynor & CALLOUT_MASK' should be
- * `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where
- * TRAPDOOR_CARRIER is the default initial state for callout
- * devices and SOFT_CARRIER is like CLOCAL except it hides
- * the true carrier.
- */
- if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK)
- (*linesw[tp->t_line].l_modem)(tp, 1);
- }
- /*
- * Wait for DCD if necessary.
- */
- if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
- && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
- ++com->wopeners;
- error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "cydcd", 0);
- --com->wopeners;
- if (error != 0)
- goto out;
- goto open_top;
- }
- error = (*linesw[tp->t_line].l_open)(dev, tp);
- disc_optim(tp, &tp->t_termios, com);
- if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
- com->active_out = TRUE;
- siosettimeout();
-out:
- splx(s);
- if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
- comhardclose(com);
- return (error);
-}
-
-static int
-sioclose(dev, flag, mode, td)
- dev_t dev;
- int flag;
- int mode;
- struct thread *td;
-{
- struct com_s *com;
- int mynor;
- int s;
- struct tty *tp;
-
- mynor = minor(dev);
- if (mynor & CONTROL_MASK)
- return (0);
- com = com_addr(MINOR_TO_UNIT(mynor));
- tp = com->tp;
- s = spltty();
- cd_etc(com, CD1400_ETC_STOPBREAK);
- (*linesw[tp->t_line].l_close)(tp, flag);
- disc_optim(tp, &tp->t_termios, com);
- comstop(tp, FREAD | FWRITE);
- comhardclose(com);
- ttyclose(tp);
- siosettimeout();
- splx(s);
-#ifdef broken /* session holds a ref to the tty; can't deallocate */
- ttyfree(tp);
- com->tp = NULL;
-#endif
- return (0);
-}
-
-static void
-comhardclose(com)
- struct com_s *com;
-{
- cy_addr iobase;
- int s;
- struct tty *tp;
- int unit;
-
- unit = com->unit;
- iobase = com->iobase;
- s = spltty();
-#if 0
- com->poll = FALSE;
- com->poll_output = FALSE;
-#endif
- com->do_timestamp = 0;
-#if 0
- outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
-#else
- /* XXX */
- critical_enter();
- COM_LOCK();
- com->etc = ETC_NONE;
- cd_setreg(com, CD1400_COR2, com->cor[1] &= ~CD1400_COR2_ETC);
- COM_UNLOCK();
- critical_exit();
- cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
-#endif
-
- {
-#if 0
- outb(iobase + com_ier, 0);
-#else
- critical_enter();
- COM_LOCK();
- cd_setreg(com, CD1400_SRER, com->intr_enable = 0);
- COM_UNLOCK();
- critical_exit();
-#endif
- tp = com->tp;
- if ((tp->t_cflag & HUPCL)
- /*
- * XXX we will miss any carrier drop between here and the
- * next open. Perhaps we should watch DCD even when the
- * port is closed; it is not sufficient to check it at
- * the next open because it might go up and down while
- * we're not watching.
- */
- || (!com->active_out
- && !(com->prev_modem_status & MSR_DCD)
- && !(com->it_in.c_cflag & CLOCAL))
- || !(tp->t_state & TS_ISOPEN)) {
- (void)commctl(com, TIOCM_DTR, DMBIC);
-
- /* Disable receiver (leave transmitter enabled). */
- com->channel_control = CD1400_CCR_CMDCHANCTL
- | CD1400_CCR_XMTEN
- | CD1400_CCR_RCVDIS;
- cd1400_channel_cmd(com, com->channel_control);
-
- if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) {
- timeout(siodtrwakeup, com, com->dtr_wait);
- com->state |= CS_DTR_OFF;
- }
- }
- }
-#if 0
- if (com->hasfifo) {
- /*
- * Disable fifos so that they are off after controlled
- * reboots. Some BIOSes fail to detect 16550s when the
- * fifos are enabled.
- */
- outb(iobase + com_fifo, 0);
- }
-#endif
- com->active_out = FALSE;
- wakeup(&com->active_out);
- wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
- splx(s);
-}
-
-static int
-siowrite(dev, uio, flag)
- dev_t dev;
- struct uio *uio;
- int flag;
-{
- int mynor;
- struct tty *tp;
- int unit;
-
- mynor = minor(dev);
- if (mynor & CONTROL_MASK)
- return (ENODEV);
-
- unit = MINOR_TO_UNIT(mynor);
- tp = com_addr(unit)->tp;
- /*
- * (XXX) We disallow virtual consoles if the physical console is
- * a serial port. This is in case there is a display attached that
- * is not the console. In that situation we don't need/want the X
- * server taking over the console.
- */
- if (constty != NULL && unit == comconsole)
- constty = NULL;
-#ifdef Smarts
- /* XXX duplicate ttwrite(), but without so much output processing on
- * CR & LF chars. Hardly worth the effort, given that high-throughput
- * sessions are raw anyhow.
- */
-#else
- return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
-#endif
-}
-
-static void
-siodtrwakeup(chan)
- void *chan;
-{
- struct com_s *com;
-
- com = (struct com_s *)chan;
- com->state &= ~CS_DTR_OFF;
- wakeup(&com->dtr_wait);
-}
-
-/*
- * This function:
- * a) needs to be called with COM_LOCK() held, and
- * b) needs to return with COM_LOCK() held.
- */
-static void
-sioinput(com)
- struct com_s *com;
-{
- u_char *buf;
- int incc;
- u_char line_status;
- int recv_data;
- struct tty *tp;
-
- buf = com->ibuf;
- tp = com->tp;
- if (!(tp->t_state & TS_ISOPEN)) {
- com_events -= (com->iptr - com->ibuf);
- com->iptr = com->ibuf;
- return;
- }
- if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
- /*
- * Avoid the grotesquely inefficient lineswitch routine
- * (ttyinput) in "raw" mode. It usually takes about 450
- * instructions (that's without canonical processing or echo!).
- * slinput is reasonably fast (usually 40 instructions plus
- * call overhead).
- */
-
- do {
- /*
- * This may look odd, but it is using save-and-enable
- * semantics instead of the save-and-disable semantics
- * that are used everywhere else.
- */
- COM_UNLOCK();
- critical_exit();
- incc = com->iptr - buf;
- if (tp->t_rawq.c_cc + incc > tp->t_ihiwat
- && (com->state & CS_RTS_IFLOW
- || tp->t_iflag & IXOFF)
- && !(tp->t_state & TS_TBLOCK))
- ttyblock(tp);
- com->delta_error_counts[CE_TTY_BUF_OVERFLOW]
- += b_to_q((char *)buf, incc, &tp->t_rawq);
- buf += incc;
- tk_nin += incc;
- tk_rawcc += incc;
- tp->t_rawcc += incc;
- ttwakeup(tp);
- if (tp->t_state & TS_TTSTOP
- && (tp->t_iflag & IXANY
- || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
- tp->t_state &= ~TS_TTSTOP;
- tp->t_lflag &= ~FLUSHO;
- comstart(tp);
- }
- critical_enter();
- COM_LOCK();
- } while (buf < com->iptr);
- } else {
- do {
- /*
- * This may look odd, but it is using save-and-enable
- * semantics instead of the save-and-disable semantics
- * that are used everywhere else.
- */
- COM_UNLOCK();
- critical_exit();
- line_status = buf[com->ierroff];
- recv_data = *buf++;
- if (line_status
- & (LSR_BI | LSR_FE | LSR_OE | LSR_PE)) {
- if (line_status & LSR_BI)
- recv_data |= TTY_BI;
- if (line_status & LSR_FE)
- recv_data |= TTY_FE;
- if (line_status & LSR_OE)
- recv_data |= TTY_OE;
- if (line_status & LSR_PE)
- recv_data |= TTY_PE;
- }
- (*linesw[tp->t_line].l_rint)(recv_data, tp);
- critical_enter();
- COM_LOCK();
- } while (buf < com->iptr);
- }
- com_events -= (com->iptr - com->ibuf);
- com->iptr = com->ibuf;
-
- /*
- * There is now room for another low-level buffer full of input,
- * so enable RTS if it is now disabled and there is room in the
- * high-level buffer.
- */
- if ((com->state & CS_RTS_IFLOW) && !(com->mcr_image & com->mcr_rts) &&
- !(tp->t_state & TS_TBLOCK))
-#if 0
- outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
-#else
- cd_setreg(com, com->mcr_rts_reg,
- com->mcr_image |= com->mcr_rts);
-#endif
-}
-
-void
-siointr(unit)
- int unit;
-{
- int baseu;
- int cy_align;
- cy_addr cy_iobase;
- int cyu;
- cy_addr iobase;
- u_char status;
-
- COM_LOCK(); /* XXX could this be placed down lower in the loop? */
-
- baseu = unit * CY_MAX_PORTS;
- cy_align = com_addr(baseu)->cy_align;
- cy_iobase = com_addr(baseu)->cy_iobase;
-
- /* check each CD1400 in turn */
- for (cyu = 0; cyu < cy_nr_cd1400s[unit]; ++cyu) {
- iobase = (cy_addr) (cy_iobase
- + (cy_chip_offset[cyu] << cy_align));
- /* poll to see if it has any work */
- status = cd_inb(iobase, CD1400_SVRR, cy_align);
- if (status == 0)
- continue;
-#ifdef CyDebug
- ++cy_svrr_probes;
-#endif
- /* service requests as appropriate, giving priority to RX */
- if (status & CD1400_SVRR_RXRDY) {
- struct com_s *com;
- u_int count;
- u_char *ioptr;
- u_char line_status;
- u_char recv_data;
- u_char serv_type;
-#ifdef PollMode
- u_char save_rir;
-#endif
-
-#ifdef PollMode
- save_rir = cd_inb(iobase, CD1400_RIR, cy_align);
-
- /* enter rx service */
- cd_outb(iobase, CD1400_CAR, cy_align, save_rir);
- com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
- = save_rir & CD1400_CAR_CHAN;
-
- serv_type = cd_inb(iobase, CD1400_RIVR, cy_align);
- com = com_addr(baseu
- + ((serv_type >> CD1400_xIVR_CHAN_SHIFT)
- & CD1400_xIVR_CHAN));
-#else
- /* ack receive service */
- serv_type = cy_inb(iobase, CY8_SVCACKR, cy_align);
-
- com = com_addr(baseu +
- + ((serv_type >> CD1400_xIVR_CHAN_SHIFT)
- & CD1400_xIVR_CHAN));
-#endif
-
- if (serv_type & CD1400_RIVR_EXCEPTION) {
- ++com->recv_exception;
- line_status = cd_inb(iobase, CD1400_RDSR, cy_align);
- /* break/unnattached error bits or real input? */
- recv_data = cd_inb(iobase, CD1400_RDSR, cy_align);
-#ifndef SOFT_HOTCHAR
- if (line_status & CD1400_RDSR_SPECIAL
- && com->hotchar != 0)
- swi_sched(sio_ih, 0);
-
-#endif
-#if 1 /* XXX "intelligent" PFO error handling would break O error handling */
- if (line_status & (LSR_PE|LSR_FE|LSR_BI)) {
- /*
- Don't store PE if IGNPAR and BI if IGNBRK,
- this hack allows "raw" tty optimization
- works even if IGN* is set.
- */
- if ( com->tp == NULL
- || !(com->tp->t_state & TS_ISOPEN)
- || ((line_status & (LSR_PE|LSR_FE))
- && (com->tp->t_iflag & IGNPAR))
- || ((line_status & LSR_BI)
- && (com->tp->t_iflag & IGNBRK)))
- goto cont;
- if ( (line_status & (LSR_PE|LSR_FE))
- && (com->tp->t_state & TS_CAN_BYPASS_L_RINT)
- && ((line_status & LSR_FE)
- || ((line_status & LSR_PE)
- && (com->tp->t_iflag & INPCK))))
- recv_data = 0;
- }
-#endif /* 1 */
- ++com->bytes_in;
-#ifdef SOFT_HOTCHAR
- if (com->hotchar != 0 && recv_data == com->hotchar)
- swi_sched(sio_ih, 0);
-#endif
- ioptr = com->iptr;
- if (ioptr >= com->ibufend)
- CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW);
- else {
- if (com->do_timestamp)
- microtime(&com->timestamp);
- ++com_events;
- ioptr[0] = recv_data;
- ioptr[com->ierroff] = line_status;
- com->iptr = ++ioptr;
- if (ioptr == com->ihighwater
- && com->state & CS_RTS_IFLOW)
-#if 0
- outb(com->modem_ctl_port,
- com->mcr_image &= ~MCR_RTS);
-#else
- cd_outb(iobase, com->mcr_rts_reg,
- cy_align,
- com->mcr_image &=
- ~com->mcr_rts);
-#endif
- if (line_status & LSR_OE)
- CE_RECORD(com, CE_OVERRUN);
- }
- goto cont;
- } else {
- int ifree;
-
- count = cd_inb(iobase, CD1400_RDCR, cy_align);
- if (!count)
- goto cont;
- com->bytes_in += count;
- ioptr = com->iptr;
- ifree = com->ibufend - ioptr;
- if (count > ifree) {
- count -= ifree;
- com_events += ifree;
- if (ifree != 0) {
- if (com->do_timestamp)
- microtime(&com->timestamp);
- do {
- recv_data = cd_inb(iobase,
- CD1400_RDSR,
- cy_align);
-#ifdef SOFT_HOTCHAR
- if (com->hotchar != 0
- && recv_data
- == com->hotchar)
- swi_sched(sio_ih, 0);
-#endif
- ioptr[0] = recv_data;
- ioptr[com->ierroff] = 0;
- ++ioptr;
- } while (--ifree != 0);
- }
- com->delta_error_counts
- [CE_INTERRUPT_BUF_OVERFLOW] += count;
- do {
- recv_data = cd_inb(iobase, CD1400_RDSR,
- cy_align);
-#ifdef SOFT_HOTCHAR
- if (com->hotchar != 0
- && recv_data == com->hotchar)
- swi_sched(sio_ih, 0);
-#endif
- } while (--count != 0);
- } else {
- if (com->do_timestamp)
- microtime(&com->timestamp);
- if (ioptr <= com->ihighwater
- && ioptr + count > com->ihighwater
- && com->state & CS_RTS_IFLOW)
-#if 0
- outb(com->modem_ctl_port,
- com->mcr_image &= ~MCR_RTS);
-#else
- cd_outb(iobase, com->mcr_rts_reg,
- cy_align,
- com->mcr_image
- &= ~com->mcr_rts);
-#endif
- com_events += count;
- do {
- recv_data = cd_inb(iobase, CD1400_RDSR,
- cy_align);
-#ifdef SOFT_HOTCHAR
- if (com->hotchar != 0
- && recv_data == com->hotchar)
- swi_sched(sio_ih, 0);
-#endif
- ioptr[0] = recv_data;
- ioptr[com->ierroff] = 0;
- ++ioptr;
- } while (--count != 0);
- }
- com->iptr = ioptr;
- }
-cont:
-
- /* terminate service context */
-#ifdef PollMode
- cd_outb(iobase, CD1400_RIR, cy_align,
- save_rir
- & ~(CD1400_RIR_RDIREQ | CD1400_RIR_RBUSY));
-#else
- cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
-#endif
- }
- if (status & CD1400_SVRR_MDMCH) {
- struct com_s *com;
- u_char modem_status;
-#ifdef PollMode
- u_char save_mir;
-#else
- u_char vector;
-#endif
-
-#ifdef PollMode
- save_mir = cd_inb(iobase, CD1400_MIR, cy_align);
-
- /* enter modem service */
- cd_outb(iobase, CD1400_CAR, cy_align, save_mir);
- com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
- = save_mir & CD1400_CAR_CHAN;
-
- com = com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS
- + (save_mir & CD1400_MIR_CHAN));
-#else
- /* ack modem service */
- vector = cy_inb(iobase, CY8_SVCACKM, cy_align);
-
- com = com_addr(baseu
- + ((vector >> CD1400_xIVR_CHAN_SHIFT)
- & CD1400_xIVR_CHAN));
-#endif
- ++com->mdm;
- modem_status = cd_inb(iobase, CD1400_MSVR2, cy_align);
- if (modem_status != com->last_modem_status) {
- if (com->do_dcd_timestamp
- && !(com->last_modem_status & MSR_DCD)
- && modem_status & MSR_DCD)
- microtime(&com->dcd_timestamp);
-
- /*
- * Schedule high level to handle DCD changes. Note
- * that we don't use the delta bits anywhere. Some
- * UARTs mess them up, and it's easy to remember the
- * previous bits and calculate the delta.
- */
- com->last_modem_status = modem_status;
- if (!(com->state & CS_CHECKMSR)) {
- com_events += LOTS_OF_EVENTS;
- com->state |= CS_CHECKMSR;
- swi_sched(sio_ih, 0);
- }
-
-#ifdef SOFT_CTS_OFLOW
- /* handle CTS change immediately for crisp flow ctl */
- if (com->state & CS_CTS_OFLOW) {
- if (modem_status & MSR_CTS) {
- com->state |= CS_ODEVREADY;
- if (com->state >= (CS_BUSY | CS_TTGO
- | CS_ODEVREADY)
- && !(com->intr_enable
- & CD1400_SRER_TXRDY))
- cd_outb(iobase, CD1400_SRER,
- cy_align,
- com->intr_enable
- = com->intr_enable
- & ~CD1400_SRER_TXMPTY
- | CD1400_SRER_TXRDY);
- } else {
- com->state &= ~CS_ODEVREADY;
- if (com->intr_enable
- & CD1400_SRER_TXRDY)
- cd_outb(iobase, CD1400_SRER,
- cy_align,
- com->intr_enable
- = com->intr_enable
- & ~CD1400_SRER_TXRDY
- | CD1400_SRER_TXMPTY);
- }
- }
-#endif
- }
-
- /* terminate service context */
-#ifdef PollMode
- cd_outb(iobase, CD1400_MIR, cy_align,
- save_mir
- & ~(CD1400_MIR_RDIREQ | CD1400_MIR_RBUSY));
-#else
- cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
-#endif
- }
- if (status & CD1400_SVRR_TXRDY) {
- struct com_s *com;
-#ifdef PollMode
- u_char save_tir;
-#else
- u_char vector;
-#endif
-
-#ifdef PollMode
- save_tir = cd_inb(iobase, CD1400_TIR, cy_align);
-
- /* enter tx service */
- cd_outb(iobase, CD1400_CAR, cy_align, save_tir);
- com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
- = save_tir & CD1400_CAR_CHAN;
-
- com = com_addr(baseu
- + cyu * CD1400_NO_OF_CHANNELS
- + (save_tir & CD1400_TIR_CHAN));
-#else
- /* ack transmit service */
- vector = cy_inb(iobase, CY8_SVCACKT, cy_align);
-
- com = com_addr(baseu
- + ((vector >> CD1400_xIVR_CHAN_SHIFT)
- & CD1400_xIVR_CHAN));
-#endif
-
- if (com->etc != ETC_NONE) {
- if (com->intr_enable & CD1400_SRER_TXRDY) {
- /*
- * Here due to sloppy SRER_TXRDY
- * enabling. Ignore. Come back when
- * tx is empty.
- */
- cd_outb(iobase, CD1400_SRER, cy_align,
- com->intr_enable
- = (com->intr_enable
- & ~CD1400_SRER_TXRDY)
- | CD1400_SRER_TXMPTY);
- goto terminate_tx_service;
- }
- switch (com->etc) {
- case CD1400_ETC_SENDBREAK:
- case CD1400_ETC_STOPBREAK:
- /*
- * Start the command. Come back on
- * next tx empty interrupt, hopefully
- * after command has been executed.
- */
- cd_outb(iobase, CD1400_COR2, cy_align,
- com->cor[1] |= CD1400_COR2_ETC);
- cd_outb(iobase, CD1400_TDR, cy_align,
- CD1400_ETC_CMD);
- cd_outb(iobase, CD1400_TDR, cy_align,
- com->etc);
- if (com->etc == CD1400_ETC_SENDBREAK)
- com->etc = ETC_BREAK_STARTING;
- else
- com->etc = ETC_BREAK_ENDING;
- goto terminate_tx_service;
- case ETC_BREAK_STARTING:
- /*
- * BREAK is now on. Continue with
- * SRER_TXMPTY processing, hopefully
- * don't come back.
- */
- com->etc = ETC_BREAK_STARTED;
- break;
- case ETC_BREAK_STARTED:
- /*
- * Came back due to sloppy SRER_TXMPTY
- * enabling. Hope again.
- */
- break;
- case ETC_BREAK_ENDING:
- /*
- * BREAK is now off. Continue with
- * SRER_TXMPTY processing and don't
- * come back. The SWI handler will
- * restart tx interrupts if necessary.
- */
- cd_outb(iobase, CD1400_COR2, cy_align,
- com->cor[1]
- &= ~CD1400_COR2_ETC);
- com->etc = ETC_BREAK_ENDED;
- if (!(com->state & CS_ODONE)) {
- com_events += LOTS_OF_EVENTS;
- com->state |= CS_ODONE;
- swi_sched(sio_ih, 0);
- }
- break;
- case ETC_BREAK_ENDED:
- /*
- * Shouldn't get here. Hope again.
- */
- break;
- }
- }
- if (com->intr_enable & CD1400_SRER_TXMPTY) {
- if (!(com->extra_state & CSE_ODONE)) {
- com_events += LOTS_OF_EVENTS;
- com->extra_state |= CSE_ODONE;
- swi_sched(sio_ih, 0);
- }
- cd_outb(iobase, CD1400_SRER, cy_align,
- com->intr_enable
- &= ~CD1400_SRER_TXMPTY);
- goto terminate_tx_service;
- }
- if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
- u_char *ioptr;
- u_int ocount;
-
- ioptr = com->obufq.l_head;
- ocount = com->obufq.l_tail - ioptr;
- if (ocount > CD1400_TX_FIFO_SIZE)
- ocount = CD1400_TX_FIFO_SIZE;
- com->bytes_out += ocount;
- do
- cd_outb(iobase, CD1400_TDR, cy_align,
- *ioptr++);
- while (--ocount != 0);
- com->obufq.l_head = ioptr;
- if (ioptr >= com->obufq.l_tail) {
- struct lbq *qp;
-
- qp = com->obufq.l_next;
- qp->l_queued = FALSE;
- qp = qp->l_next;
- if (qp != NULL) {
- com->obufq.l_head = qp->l_head;
- com->obufq.l_tail = qp->l_tail;
- com->obufq.l_next = qp;
- } else {
- /* output just completed */
- com->state &= ~CS_BUSY;
-
- /*
- * The setting of CSE_ODONE may be
- * stale here. We currently only
- * use it when CS_BUSY is set, and
- * fixing it when we clear CS_BUSY
- * is easiest.
- */
- if (com->extra_state & CSE_ODONE) {
- com_events -= LOTS_OF_EVENTS;
- com->extra_state &= ~CSE_ODONE;
- }
-
- cd_outb(iobase, CD1400_SRER, cy_align,
- com->intr_enable
- = (com->intr_enable
- & ~CD1400_SRER_TXRDY)
- | CD1400_SRER_TXMPTY);
- }
- if (!(com->state & CS_ODONE)) {
- com_events += LOTS_OF_EVENTS;
- com->state |= CS_ODONE;
-
- /* handle at high level ASAP */
- swi_sched(sio_ih, 0);
- }
- }
- }
-
- /* terminate service context */
-terminate_tx_service:
-#ifdef PollMode
- cd_outb(iobase, CD1400_TIR, cy_align,
- save_tir
- & ~(CD1400_TIR_RDIREQ | CD1400_TIR_RBUSY));
-#else
- cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
-#endif
- }
- }
-
- /* ensure an edge for the next interrupt */
- cy_outb(cy_iobase, CY_CLEAR_INTR, cy_align, 0);
-
- swi_sched(sio_ih, 0);
-
- COM_UNLOCK();
-}
-
-#if 0
-static void
-siointr1(com)
- struct com_s *com;
-{
-}
-#endif
-
-static int
-sioioctl(dev, cmd, data, flag, td)
- dev_t dev;
- u_long cmd;
- caddr_t data;
- int flag;
- struct thread *td;
-{
- struct com_s *com;
- int error;
- int mynor;
- int s;
- struct tty *tp;
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
- int oldcmd;
- struct termios term;
-#endif
-
- mynor = minor(dev);
- com = com_addr(MINOR_TO_UNIT(mynor));
- if (mynor & CONTROL_MASK) {
- struct termios *ct;
-
- switch (mynor & CONTROL_MASK) {
- case CONTROL_INIT_STATE:
- ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in;
- break;
- case CONTROL_LOCK_STATE:
- ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in;
- break;
- default:
- return (ENODEV); /* /dev/nodev */
- }
- switch (cmd) {
- case TIOCSETA:
- error = suser(td);
- if (error != 0)
- return (error);
- *ct = *(struct termios *)data;
- return (0);
- case TIOCGETA:
- *(struct termios *)data = *ct;
- return (0);
- case TIOCGETD:
- *(int *)data = TTYDISC;
- return (0);
- case TIOCGWINSZ:
- bzero(data, sizeof(struct winsize));
- return (0);
- default:
- return (ENOTTY);
- }
- }
- tp = com->tp;
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
- term = tp->t_termios;
- oldcmd = cmd;
- error = ttsetcompat(tp, &cmd, data, &term);
- if (error != 0)
- return (error);
- if (cmd != oldcmd)
- data = (caddr_t)&term;
-#endif
- if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
- int cc;
- struct termios *dt = (struct termios *)data;
- struct termios *lt = mynor & CALLOUT_MASK
- ? &com->lt_out : &com->lt_in;
-
- dt->c_iflag = (tp->t_iflag & lt->c_iflag)
- | (dt->c_iflag & ~lt->c_iflag);
- dt->c_oflag = (tp->t_oflag & lt->c_oflag)
- | (dt->c_oflag & ~lt->c_oflag);
- dt->c_cflag = (tp->t_cflag & lt->c_cflag)
- | (dt->c_cflag & ~lt->c_cflag);
- dt->c_lflag = (tp->t_lflag & lt->c_lflag)
- | (dt->c_lflag & ~lt->c_lflag);
- for (cc = 0; cc < NCCS; ++cc)
- if (lt->c_cc[cc] != 0)
- dt->c_cc[cc] = tp->t_cc[cc];
- if (lt->c_ispeed != 0)
- dt->c_ispeed = tp->t_ispeed;
- if (lt->c_ospeed != 0)
- dt->c_ospeed = tp->t_ospeed;
- }
- error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
- if (error != ENOIOCTL)
- return (error);
- s = spltty();
- error = ttioctl(tp, cmd, data, flag);
- disc_optim(tp, &tp->t_termios, com);
- if (error != ENOIOCTL) {
- splx(s);
- return (error);
- }
- switch (cmd) {
- case TIOCSBRK:
-#if 0
- outb(iobase + com_cfcr, com->cfcr_image |= CFCR_SBREAK);
-#else
- cd_etc(com, CD1400_ETC_SENDBREAK);
-#endif
- break;
- case TIOCCBRK:
-#if 0
- outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
-#else
- cd_etc(com, CD1400_ETC_STOPBREAK);
-#endif
- break;
- case TIOCSDTR:
- (void)commctl(com, TIOCM_DTR, DMBIS);
- break;
- case TIOCCDTR:
- (void)commctl(com, TIOCM_DTR, DMBIC);
- break;
- /*
- * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The
- * changes get undone on the next call to comparam().
- */
- case TIOCMSET:
- (void)commctl(com, *(int *)data, DMSET);
- break;
- case TIOCMBIS:
- (void)commctl(com, *(int *)data, DMBIS);
- break;
- case TIOCMBIC:
- (void)commctl(com, *(int *)data, DMBIC);
- break;
- case TIOCMGET:
- *(int *)data = commctl(com, 0, DMGET);
- break;
- case TIOCMSDTRWAIT:
- /* must be root since the wait applies to following logins */
- error = suser(td);
- if (error != 0) {
- splx(s);
- return (error);
- }
- com->dtr_wait = *(int *)data * hz / 100;
- break;
- case TIOCMGDTRWAIT:
- *(int *)data = com->dtr_wait * 100 / hz;
- break;
- case TIOCTIMESTAMP:
- com->do_timestamp = TRUE;
- *(struct timeval *)data = com->timestamp;
- break;
- case TIOCDCDTIMESTAMP:
- com->do_dcd_timestamp = TRUE;
- *(struct timeval *)data = com->dcd_timestamp;
- break;
- default:
- splx(s);
- return (ENOTTY);
- }
- splx(s);
- return (0);
-}
-
-static void
-siopoll(void *arg)
-{
- int unit;
-
-#ifdef CyDebug
- ++cy_timeouts;
-#endif
- if (com_events == 0)
- return;
-repeat:
- for (unit = 0; unit < NSIO; ++unit) {
- struct com_s *com;
- int incc;
- struct tty *tp;
-
- com = com_addr(unit);
- if (com == NULL)
- continue;
- tp = com->tp;
- if (tp == NULL) {
- /*
- * XXX forget any events related to closed devices
- * (actually never opened devices) so that we don't
- * loop.
- */
- critical_enter();
- COM_LOCK();
- incc = com->iptr - com->ibuf;
- com->iptr = com->ibuf;
- if (com->state & CS_CHECKMSR) {
- incc += LOTS_OF_EVENTS;
- com->state &= ~CS_CHECKMSR;
- }
- com_events -= incc;
- COM_UNLOCK();
- critical_exit();
- if (incc != 0)
- log(LOG_DEBUG,
- "sio%d: %d events for device with no tp\n",
- unit, incc);
- continue;
- }
- if (com->iptr != com->ibuf) {
- critical_enter();
- COM_LOCK();
- sioinput(com);
- COM_UNLOCK();
- critical_exit();
- }
- if (com->state & CS_CHECKMSR) {
- u_char delta_modem_status;
-
- critical_enter();
- COM_LOCK();
- sioinput(com);
- delta_modem_status = com->last_modem_status
- ^ com->prev_modem_status;
- com->prev_modem_status = com->last_modem_status;
- com_events -= LOTS_OF_EVENTS;
- com->state &= ~CS_CHECKMSR;
- COM_UNLOCK();
- critical_exit();
- if (delta_modem_status & MSR_DCD)
- (*linesw[tp->t_line].l_modem)
- (tp, com->prev_modem_status & MSR_DCD);
- }
- if (com->extra_state & CSE_ODONE) {
- critical_enter();
- COM_LOCK();
- com_events -= LOTS_OF_EVENTS;
- com->extra_state &= ~CSE_ODONE;
- COM_UNLOCK();
- critical_exit();
- if (!(com->state & CS_BUSY)) {
- tp->t_state &= ~TS_BUSY;
- ttwwakeup(com->tp);
- }
- if (com->etc != ETC_NONE) {
- if (com->etc == ETC_BREAK_ENDED)
- com->etc = ETC_NONE;
- wakeup(&com->etc);
- }
- }
- if (com->state & CS_ODONE) {
- critical_enter();
- COM_LOCK();
- com_events -= LOTS_OF_EVENTS;
- com->state &= ~CS_ODONE;
- COM_UNLOCK();
- critical_exit();
- (*linesw[tp->t_line].l_start)(tp);
- }
- if (com_events == 0)
- break;
- }
- if (com_events >= LOTS_OF_EVENTS)
- goto repeat;
-}
-
-static int
-comparam(tp, t)
- struct tty *tp;
- struct termios *t;
-{
- int bits;
- int cflag;
- struct com_s *com;
- u_char cor_change;
- u_long cy_clock;
- int idivisor;
- int iflag;
- int iprescaler;
- int itimeout;
- int odivisor;
- int oprescaler;
- u_char opt;
- int s;
- int unit;
-
- /* do historical conversions */
- if (t->c_ispeed == 0)
- t->c_ispeed = t->c_ospeed;
-
- unit = DEV_TO_UNIT(tp->t_dev);
- com = com_addr(unit);
-
- /* check requested parameters */
- cy_clock = CY_CLOCK(com->gfrcr_image);
- idivisor = comspeed(t->c_ispeed, cy_clock, &iprescaler);
- if (idivisor < 0)
- return (EINVAL);
- odivisor = comspeed(t->c_ospeed, cy_clock, &oprescaler);
- if (odivisor < 0)
- return (EINVAL);
-
- /* parameters are OK, convert them to the com struct and the device */
- s = spltty();
- if (odivisor == 0)
- (void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */
- else
- (void)commctl(com, TIOCM_DTR, DMBIS);
-
- (void) siosetwater(com, t->c_ispeed);
-
- /* XXX we don't actually change the speed atomically. */
-
- if (idivisor != 0) {
- cd_setreg(com, CD1400_RBPR, idivisor);
- cd_setreg(com, CD1400_RCOR, iprescaler);
- }
- if (odivisor != 0) {
- cd_setreg(com, CD1400_TBPR, odivisor);
- cd_setreg(com, CD1400_TCOR, oprescaler);
- }
-
- /*
- * channel control
- * receiver enable
- * transmitter enable (always set)
- */
- cflag = t->c_cflag;
- opt = CD1400_CCR_CMDCHANCTL | CD1400_CCR_XMTEN
- | (cflag & CREAD ? CD1400_CCR_RCVEN : CD1400_CCR_RCVDIS);
- if (opt != com->channel_control) {
- com->channel_control = opt;
- cd1400_channel_cmd(com, opt);
- }
-
-#ifdef Smarts
- /* set special chars */
- /* XXX if one is _POSIX_VDISABLE, can't use some others */
- if (t->c_cc[VSTOP] != _POSIX_VDISABLE)
- cd_setreg(com, CD1400_SCHR1, t->c_cc[VSTOP]);
- if (t->c_cc[VSTART] != _POSIX_VDISABLE)
- cd_setreg(com, CD1400_SCHR2, t->c_cc[VSTART]);
- if (t->c_cc[VINTR] != _POSIX_VDISABLE)
- cd_setreg(com, CD1400_SCHR3, t->c_cc[VINTR]);
- if (t->c_cc[VSUSP] != _POSIX_VDISABLE)
- cd_setreg(com, CD1400_SCHR4, t->c_cc[VSUSP]);
-#endif
-
- /*
- * set channel option register 1 -
- * parity mode
- * stop bits
- * char length
- */
- opt = 0;
- /* parity */
- if (cflag & PARENB) {
- if (cflag & PARODD)
- opt |= CD1400_COR1_PARODD;
- opt |= CD1400_COR1_PARNORMAL;
- }
- iflag = t->c_iflag;
- if (!(iflag & INPCK))
- opt |= CD1400_COR1_NOINPCK;
- bits = 1 + 1;
- /* stop bits */
- if (cflag & CSTOPB) {
- ++bits;
- opt |= CD1400_COR1_STOP2;
- }
- /* char length */
- switch (cflag & CSIZE) {
- case CS5:
- bits += 5;
- opt |= CD1400_COR1_CS5;
- break;
- case CS6:
- bits += 6;
- opt |= CD1400_COR1_CS6;
- break;
- case CS7:
- bits += 7;
- opt |= CD1400_COR1_CS7;
- break;
- default:
- bits += 8;
- opt |= CD1400_COR1_CS8;
- break;
- }
- cor_change = 0;
- if (opt != com->cor[0]) {
- cor_change |= CD1400_CCR_COR1;
- cd_setreg(com, CD1400_COR1, com->cor[0] = opt);
- }
-
- /*
- * Set receive time-out period, normally to max(one char time, 5 ms).
- */
- if (t->c_ispeed == 0)
- itimeout = cd_getreg(com, CD1400_RTPR);
- else {
- itimeout = (1000 * bits + t->c_ispeed - 1) / t->c_ispeed;
-#ifdef SOFT_HOTCHAR
-#define MIN_RTP 1
-#else
-#define MIN_RTP 5
-#endif
- if (itimeout < MIN_RTP)
- itimeout = MIN_RTP;
- }
- if (!(t->c_lflag & ICANON) && t->c_cc[VMIN] != 0 && t->c_cc[VTIME] != 0
- && t->c_cc[VTIME] * 10 > itimeout)
- itimeout = t->c_cc[VTIME] * 10;
- if (itimeout > 255)
- itimeout = 255;
- cd_setreg(com, CD1400_RTPR, itimeout);
-
- /*
- * set channel option register 2 -
- * flow control
- */
- opt = 0;
-#ifdef Smarts
- if (iflag & IXANY)
- opt |= CD1400_COR2_IXANY;
- if (iflag & IXOFF)
- opt |= CD1400_COR2_IXOFF;
-#endif
-#ifndef SOFT_CTS_OFLOW
- if (cflag & CCTS_OFLOW)
- opt |= CD1400_COR2_CCTS_OFLOW;
-#endif
- critical_enter();
- COM_LOCK();
- if (opt != com->cor[1]) {
- cor_change |= CD1400_CCR_COR2;
- cd_setreg(com, CD1400_COR2, com->cor[1] = opt);
- }
- COM_UNLOCK();
- critical_exit();
-
- /*
- * set channel option register 3 -
- * receiver FIFO interrupt threshold
- * flow control
- */
- opt = RxFifoThreshold;
-#ifdef Smarts
- if (t->c_lflag & ICANON)
- opt |= CD1400_COR3_SCD34; /* detect INTR & SUSP chars */
- if (iflag & IXOFF)
- /* detect and transparently handle START and STOP chars */
- opt |= CD1400_COR3_FCT | CD1400_COR3_SCD12;
-#endif
- if (opt != com->cor[2]) {
- cor_change |= CD1400_CCR_COR3;
- cd_setreg(com, CD1400_COR3, com->cor[2] = opt);
- }
-
- /* notify the CD1400 if COR1-3 have changed */
- if (cor_change)
- cd1400_channel_cmd(com, CD1400_CCR_CMDCORCHG | cor_change);
-
- /*
- * set channel option register 4 -
- * CR/NL processing
- * break processing
- * received exception processing
- */
- opt = 0;
- if (iflag & IGNCR)
- opt |= CD1400_COR4_IGNCR;
-#ifdef Smarts
- /*
- * we need a new ttyinput() for this, as we don't want to
- * have ICRNL && INLCR being done in both layers, or to have
- * synchronisation problems
- */
- if (iflag & ICRNL)
- opt |= CD1400_COR4_ICRNL;
- if (iflag & INLCR)
- opt |= CD1400_COR4_INLCR;
-#endif
- if (iflag & IGNBRK)
- opt |= CD1400_COR4_IGNBRK | CD1400_COR4_NOBRKINT;
- /*
- * The `-ignbrk -brkint parmrk' case is not handled by the hardware,
- * so only tell the hardware about -brkint if -parmrk.
- */
- if (!(iflag & (BRKINT | PARMRK)))
- opt |= CD1400_COR4_NOBRKINT;
-#if 0
- /* XXX using this "intelligence" breaks reporting of overruns. */
- if (iflag & IGNPAR)
- opt |= CD1400_COR4_PFO_DISCARD;
- else {
- if (iflag & PARMRK)
- opt |= CD1400_COR4_PFO_ESC;
- else
- opt |= CD1400_COR4_PFO_NUL;
- }
-#else
- opt |= CD1400_COR4_PFO_EXCEPTION;
-#endif
- cd_setreg(com, CD1400_COR4, opt);
-
- /*
- * set channel option register 5 -
- */
- opt = 0;
- if (iflag & ISTRIP)
- opt |= CD1400_COR5_ISTRIP;
- if (t->c_iflag & IEXTEN)
- /* enable LNEXT (e.g. ctrl-v quoting) handling */
- opt |= CD1400_COR5_LNEXT;
-#ifdef Smarts
- if (t->c_oflag & ONLCR)
- opt |= CD1400_COR5_ONLCR;
- if (t->c_oflag & OCRNL)
- opt |= CD1400_COR5_OCRNL;
-#endif
- cd_setreg(com, CD1400_COR5, opt);
-
- /*
- * We always generate modem status change interrupts for CD changes.
- * Among other things, this is necessary to track TS_CARR_ON for
- * pstat to print even when the driver doesn't care. CD changes
- * should be rare so interrupts for them are not worth extra code to
- * avoid. We avoid interrupts for other modem status changes (except
- * for CTS changes when SOFT_CTS_OFLOW is configured) since this is
- * simplest and best.
- */
-
- /*
- * set modem change option register 1
- * generate modem interrupts on which 1 -> 0 input transitions
- * also controls auto-DTR output flow-control, which we don't use
- */
- opt = CD1400_MCOR1_CDzd;
-#ifdef SOFT_CTS_OFLOW
- if (cflag & CCTS_OFLOW)
- opt |= CD1400_MCOR1_CTSzd;
-#endif
- cd_setreg(com, CD1400_MCOR1, opt);
-
- /*
- * set modem change option register 2
- * generate modem interrupts on specific 0 -> 1 input transitions
- */
- opt = CD1400_MCOR2_CDod;
-#ifdef SOFT_CTS_OFLOW
- if (cflag & CCTS_OFLOW)
- opt |= CD1400_MCOR2_CTSod;
-#endif
- cd_setreg(com, CD1400_MCOR2, opt);
-
- /*
- * XXX should have done this long ago, but there is too much state
- * to change all atomically.
- */
- critical_enter();
- COM_LOCK();
-
- com->state &= ~CS_TTGO;
- if (!(tp->t_state & TS_TTSTOP))
- com->state |= CS_TTGO;
- if (cflag & CRTS_IFLOW) {
- com->state |= CS_RTS_IFLOW;
- /*
- * If CS_RTS_IFLOW just changed from off to on, the change
- * needs to be propagated to MCR_RTS. This isn't urgent,
- * so do it later by calling comstart() instead of repeating
- * a lot of code from comstart() here.
- */
- } else if (com->state & CS_RTS_IFLOW) {
- com->state &= ~CS_RTS_IFLOW;
- /*
- * CS_RTS_IFLOW just changed from on to off. Force MCR_RTS
- * on here, since comstart() won't do it later.
- */
-#if 0
- outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
-#else
- cd_setreg(com, com->mcr_rts_reg,
- com->mcr_image |= com->mcr_rts);
-#endif
- }
-
- /*
- * Set up state to handle output flow control.
- * XXX - worth handling MDMBUF (DCD) flow control at the lowest level?
- * Now has 10+ msec latency, while CTS flow has 50- usec latency.
- */
- com->state |= CS_ODEVREADY;
-#ifdef SOFT_CTS_OFLOW
- com->state &= ~CS_CTS_OFLOW;
- if (cflag & CCTS_OFLOW) {
- com->state |= CS_CTS_OFLOW;
- if (!(com->last_modem_status & MSR_CTS))
- com->state &= ~CS_ODEVREADY;
- }
-#endif
- /* XXX shouldn't call functions while intrs are disabled. */
- disc_optim(tp, t, com);
-#if 0
- /*
- * Recover from fiddling with CS_TTGO. We used to call siointr1()
- * unconditionally, but that defeated the careful discarding of
- * stale input in sioopen().
- */
- if (com->state >= (CS_BUSY | CS_TTGO))
- siointr1(com);
-#endif
- if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
- if (!(com->intr_enable & CD1400_SRER_TXRDY))
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable & ~CD1400_SRER_TXMPTY)
- | CD1400_SRER_TXRDY);
- } else {
- if (com->intr_enable & CD1400_SRER_TXRDY)
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable & ~CD1400_SRER_TXRDY)
- | CD1400_SRER_TXMPTY);
- }
-
- COM_UNLOCK();
- critical_exit();
- splx(s);
- comstart(tp);
- if (com->ibufold != NULL) {
- free(com->ibufold, M_DEVBUF);
- com->ibufold = NULL;
- }
- return (0);
-}
-
-static int
-siosetwater(com, speed)
- struct com_s *com;
- speed_t speed;
-{
- int cp4ticks;
- u_char *ibuf;
- int ibufsize;
- struct tty *tp;
-
- /*
- * Make the buffer size large enough to handle a softtty interrupt
- * latency of about 2 ticks without loss of throughput or data
- * (about 3 ticks if input flow control is not used or not honoured,
- * but a bit less for CS5-CS7 modes).
- */
- cp4ticks = speed / 10 / hz * 4;
- for (ibufsize = 128; ibufsize < cp4ticks;)
- ibufsize <<= 1;
- if (ibufsize == com->ibufsize) {
- return (0);
- }
-
- /*
- * Allocate input buffer. The extra factor of 2 in the size is
- * to allow for an error byte for each input byte.
- */
- ibuf = malloc(2 * ibufsize, M_DEVBUF, M_NOWAIT);
- if (ibuf == NULL) {
- return (ENOMEM);
- }
-
- /* Initialize non-critical variables. */
- com->ibufold = com->ibuf;
- com->ibufsize = ibufsize;
- tp = com->tp;
- if (tp != NULL) {
- tp->t_ififosize = 2 * ibufsize;
- tp->t_ispeedwat = (speed_t)-1;
- tp->t_ospeedwat = (speed_t)-1;
- }
-
- /*
- * Read current input buffer, if any. Continue with interrupts
- * disabled.
- */
- critical_enter();
- COM_LOCK();
- if (com->iptr != com->ibuf)
- sioinput(com);
-
- /*-
- * Initialize critical variables, including input buffer watermarks.
- * The external device is asked to stop sending when the buffer
- * exactly reaches high water, or when the high level requests it.
- * The high level is notified immediately (rather than at a later
- * clock tick) when this watermark is reached.
- * The buffer size is chosen so the watermark should almost never
- * be reached.
- * The low watermark is invisibly 0 since the buffer is always
- * emptied all at once.
- */
- com->iptr = com->ibuf = ibuf;
- com->ibufend = ibuf + ibufsize;
- com->ierroff = ibufsize;
- com->ihighwater = ibuf + 3 * ibufsize / 4;
-
- COM_UNLOCK();
- critical_exit();
- return (0);
-}
-
-static void
-comstart(tp)
- struct tty *tp;
-{
- struct com_s *com;
- int s;
-#ifdef CyDebug
- bool_t started;
-#endif
- int unit;
-
- unit = DEV_TO_UNIT(tp->t_dev);
- com = com_addr(unit);
- s = spltty();
-
-#ifdef CyDebug
- ++com->start_count;
- started = FALSE;
-#endif
-
- critical_enter();
- COM_LOCK();
- if (tp->t_state & TS_TTSTOP) {
- com->state &= ~CS_TTGO;
- if (com->intr_enable & CD1400_SRER_TXRDY)
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable & ~CD1400_SRER_TXRDY)
- | CD1400_SRER_TXMPTY);
- } else {
- com->state |= CS_TTGO;
- if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)
- && !(com->intr_enable & CD1400_SRER_TXRDY))
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable & ~CD1400_SRER_TXMPTY)
- | CD1400_SRER_TXRDY);
- }
- if (tp->t_state & TS_TBLOCK) {
- if (com->mcr_image & com->mcr_rts && com->state & CS_RTS_IFLOW)
-#if 0
- outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS);
-#else
- cd_setreg(com, com->mcr_rts_reg,
- com->mcr_image &= ~com->mcr_rts);
-#endif
- } else {
- if (!(com->mcr_image & com->mcr_rts)
- && com->iptr < com->ihighwater
- && com->state & CS_RTS_IFLOW)
-#if 0
- outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
-#else
- cd_setreg(com, com->mcr_rts_reg,
- com->mcr_image |= com->mcr_rts);
-#endif
- }
- COM_UNLOCK();
- critical_exit();
- if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
- ttwwakeup(tp);
- splx(s);
- return;
- }
- if (tp->t_outq.c_cc != 0) {
- struct lbq *qp;
- struct lbq *next;
-
- if (!com->obufs[0].l_queued) {
-#ifdef CyDebug
- started = TRUE;
-#endif
- com->obufs[0].l_tail
- = com->obuf1 + q_to_b(&tp->t_outq, com->obuf1,
- sizeof com->obuf1);
- com->obufs[0].l_next = NULL;
- com->obufs[0].l_queued = TRUE;
- critical_enter();
- COM_LOCK();
- if (com->state & CS_BUSY) {
- qp = com->obufq.l_next;
- while ((next = qp->l_next) != NULL)
- qp = next;
- qp->l_next = &com->obufs[0];
- } else {
- com->obufq.l_head = com->obufs[0].l_head;
- com->obufq.l_tail = com->obufs[0].l_tail;
- com->obufq.l_next = &com->obufs[0];
- com->state |= CS_BUSY;
- if (com->state >= (CS_BUSY | CS_TTGO
- | CS_ODEVREADY))
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable
- & ~CD1400_SRER_TXMPTY)
- | CD1400_SRER_TXRDY);
- }
- COM_UNLOCK();
- critical_exit();
- }
- if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) {
-#ifdef CyDebug
- started = TRUE;
-#endif
- com->obufs[1].l_tail
- = com->obuf2 + q_to_b(&tp->t_outq, com->obuf2,
- sizeof com->obuf2);
- com->obufs[1].l_next = NULL;
- com->obufs[1].l_queued = TRUE;
- critical_enter();
- COM_LOCK();
- if (com->state & CS_BUSY) {
- qp = com->obufq.l_next;
- while ((next = qp->l_next) != NULL)
- qp = next;
- qp->l_next = &com->obufs[1];
- } else {
- com->obufq.l_head = com->obufs[1].l_head;
- com->obufq.l_tail = com->obufs[1].l_tail;
- com->obufq.l_next = &com->obufs[1];
- com->state |= CS_BUSY;
- if (com->state >= (CS_BUSY | CS_TTGO
- | CS_ODEVREADY))
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable
- & ~CD1400_SRER_TXMPTY)
- | CD1400_SRER_TXRDY);
- }
- COM_UNLOCK();
- critical_exit();
- }
- tp->t_state |= TS_BUSY;
- }
-#ifdef CyDebug
- if (started)
- ++com->start_real;
-#endif
-#if 0
- critical_enter();
- COM_LOCK();
- if (com->state >= (CS_BUSY | CS_TTGO))
- siointr1(com); /* fake interrupt to start output */
- COM_UNLOCK();
- critical_exit();
-#endif
- ttwwakeup(tp);
- splx(s);
-}
-
-static void
-comstop(tp, rw)
- struct tty *tp;
- int rw;
-{
- struct com_s *com;
- bool_t wakeup_etc;
-
- com = com_addr(DEV_TO_UNIT(tp->t_dev));
- wakeup_etc = FALSE;
- critical_enter();
- COM_LOCK();
- if (rw & FWRITE) {
- com->obufs[0].l_queued = FALSE;
- com->obufs[1].l_queued = FALSE;
- if (com->extra_state & CSE_ODONE) {
- com_events -= LOTS_OF_EVENTS;
- com->extra_state &= ~CSE_ODONE;
- if (com->etc != ETC_NONE) {
- if (com->etc == ETC_BREAK_ENDED)
- com->etc = ETC_NONE;
- wakeup_etc = TRUE;
- }
- }
- com->tp->t_state &= ~TS_BUSY;
- if (com->state & CS_ODONE)
- com_events -= LOTS_OF_EVENTS;
- com->state &= ~(CS_ODONE | CS_BUSY);
- }
- if (rw & FREAD) {
- /* XXX no way to reset only input fifo. */
- com_events -= (com->iptr - com->ibuf);
- com->iptr = com->ibuf;
- }
- COM_UNLOCK();
- critical_exit();
- if (wakeup_etc)
- wakeup(&com->etc);
- if (rw & FWRITE && com->etc == ETC_NONE)
- cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
- comstart(tp);
-}
-
-static int
-commctl(com, bits, how)
- struct com_s *com;
- int bits;
- int how;
-{
- int mcr;
- int msr;
-
- if (how == DMGET) {
- if (com->channel_control & CD1400_CCR_RCVEN)
- bits |= TIOCM_LE;
- mcr = com->mcr_image;
- if (mcr & com->mcr_dtr)
- bits |= TIOCM_DTR;
- if (mcr & com->mcr_rts)
- /* XXX wired on for Cyclom-8Ys */
- bits |= TIOCM_RTS;
-
- /*
- * We must read the modem status from the hardware because
- * we don't generate modem status change interrupts for all
- * changes, so com->prev_modem_status is not guaranteed to
- * be up to date. This is safe, unlike for sio, because
- * reading the status register doesn't clear pending modem
- * status change interrupts.
- */
- msr = cd_getreg(com, CD1400_MSVR2);
-
- if (msr & MSR_CTS)
- bits |= TIOCM_CTS;
- if (msr & MSR_DCD)
- bits |= TIOCM_CD;
- if (msr & MSR_DSR)
- bits |= TIOCM_DSR;
- if (msr & MSR_RI)
- /* XXX not connected except for Cyclom-16Y? */
- bits |= TIOCM_RI;
- return (bits);
- }
- mcr = 0;
- if (bits & TIOCM_DTR)
- mcr |= com->mcr_dtr;
- if (bits & TIOCM_RTS)
- mcr |= com->mcr_rts;
- critical_enter();
- COM_LOCK();
- switch (how) {
- case DMSET:
- com->mcr_image = mcr;
- cd_setreg(com, CD1400_MSVR1, mcr);
- cd_setreg(com, CD1400_MSVR2, mcr);
- break;
- case DMBIS:
- com->mcr_image = mcr = com->mcr_image | mcr;
- cd_setreg(com, CD1400_MSVR1, mcr);
- cd_setreg(com, CD1400_MSVR2, mcr);
- break;
- case DMBIC:
- com->mcr_image = mcr = com->mcr_image & ~mcr;
- cd_setreg(com, CD1400_MSVR1, mcr);
- cd_setreg(com, CD1400_MSVR2, mcr);
- break;
- }
- COM_UNLOCK();
- critical_exit();
- return (0);
-}
-
-static void
-siosettimeout()
-{
- struct com_s *com;
- bool_t someopen;
- int unit;
-
- /*
- * Set our timeout period to 1 second if no polled devices are open.
- * Otherwise set it to max(1/200, 1/hz).
- * Enable timeouts iff some device is open.
- */
- untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
- sio_timeout = hz;
- someopen = FALSE;
- for (unit = 0; unit < NSIO; ++unit) {
- com = com_addr(unit);
- if (com != NULL && com->tp != NULL
- && com->tp->t_state & TS_ISOPEN) {
- someopen = TRUE;
-#if 0
- if (com->poll || com->poll_output) {
- sio_timeout = hz > 200 ? hz / 200 : 1;
- break;
- }
-#endif
- }
- }
- if (someopen) {
- sio_timeouts_until_log = hz / sio_timeout;
- sio_timeout_handle = timeout(comwakeup, (void *)NULL,
- sio_timeout);
- } else {
- /* Flush error messages, if any. */
- sio_timeouts_until_log = 1;
- comwakeup((void *)NULL);
- untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
- }
-}
-
-static void
-comwakeup(chan)
- void *chan;
-{
- struct com_s *com;
- int unit;
-
- sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout);
-
-#if 0
- /*
- * Recover from lost output interrupts.
- * Poll any lines that don't use interrupts.
- */
- for (unit = 0; unit < NSIO; ++unit) {
- com = com_addr(unit);
- if (com != NULL
- && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) {
- critical_enter();
- COM_LOCK();
- siointr1(com);
- COM_UNLOCK();
- critical_exit();
- }
- }
-#endif
-
- /*
- * Check for and log errors, but not too often.
- */
- if (--sio_timeouts_until_log > 0)
- return;
- sio_timeouts_until_log = hz / sio_timeout;
- for (unit = 0; unit < NSIO; ++unit) {
- int errnum;
-
- com = com_addr(unit);
- if (com == NULL)
- continue;
- for (errnum = 0; errnum < CE_NTYPES; ++errnum) {
- u_int delta;
- u_long total;
-
- critical_enter();
- COM_LOCK();
- delta = com->delta_error_counts[errnum];
- com->delta_error_counts[errnum] = 0;
- COM_UNLOCK();
- critical_exit();
- if (delta == 0)
- continue;
- total = com->error_counts[errnum] += delta;
- log(LOG_ERR, "cy%d: %u more %s%s (total %lu)\n",
- unit, delta, error_desc[errnum],
- delta == 1 ? "" : "s", total);
- }
- }
-}
-
-static void
-disc_optim(tp, t, com)
- struct tty *tp;
- struct termios *t;
- struct com_s *com;
-{
-#ifndef SOFT_HOTCHAR
- u_char opt;
-#endif
-
- /*
- * XXX can skip a lot more cases if Smarts. Maybe
- * (IGNCR | ISTRIP | IXON) in c_iflag. But perhaps we
- * shouldn't skip if (TS_CNTTB | TS_LNCH) is set in t_state.
- */
- if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
- && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
- && (!(t->c_iflag & PARMRK)
- || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
- && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
- && linesw[tp->t_line].l_rint == ttyinput)
- tp->t_state |= TS_CAN_BYPASS_L_RINT;
- else
- tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
- com->hotchar = linesw[tp->t_line].l_hotchar;
-#ifndef SOFT_HOTCHAR
- opt = com->cor[2] & ~CD1400_COR3_SCD34;
- if (com->hotchar != 0) {
- cd_setreg(com, CD1400_SCHR3, com->hotchar);
- cd_setreg(com, CD1400_SCHR4, com->hotchar);
- opt |= CD1400_COR3_SCD34;
- }
- if (opt != com->cor[2]) {
- cd_setreg(com, CD1400_COR3, com->cor[2] = opt);
- cd1400_channel_cmd(com, CD1400_CCR_CMDCORCHG | CD1400_CCR_COR3);
- }
-#endif
-}
-
-#ifdef Smarts
-/* standard line discipline input routine */
-int
-cyinput(c, tp)
- int c;
- struct tty *tp;
-{
- /* XXX duplicate ttyinput(), but without the IXOFF/IXON/ISTRIP/IPARMRK
- * bits, as they are done by the CD1400. Hardly worth the effort,
- * given that high-throughput sessions are raw anyhow.
- */
-}
-#endif /* Smarts */
-
-static int
-comspeed(speed, cy_clock, prescaler_io)
- speed_t speed;
- u_long cy_clock;
- int *prescaler_io;
-{
- int actual;
- int error;
- int divider;
- int prescaler;
- int prescaler_unit;
-
- if (speed == 0)
- return (0);
- if (speed < 0 || speed > 150000)
- return (-1);
-
- /* determine which prescaler to use */
- for (prescaler_unit = 4, prescaler = 2048; prescaler_unit;
- prescaler_unit--, prescaler >>= 2) {
- if (cy_clock / prescaler / speed > 63)
- break;
- }
-
- divider = (cy_clock / prescaler * 2 / speed + 1) / 2; /* round off */
- if (divider > 255)
- divider = 255;
- actual = cy_clock/prescaler/divider;
-
- /* 10 times error in percent: */
- error = ((actual - (long)speed) * 2000 / (long)speed + 1) / 2;
-
- /* 3.0% max error tolerance */
- if (error < -30 || error > 30)
- return (-1);
-
-#if 0
- printf("prescaler = %d (%d)\n", prescaler, prescaler_unit);
- printf("divider = %d (%x)\n", divider, divider);
- printf("actual = %d\n", actual);
- printf("error = %d\n", error);
-#endif
-
- *prescaler_io = prescaler_unit;
- return (divider);
-}
-
-static void
-cd1400_channel_cmd(com, cmd)
- struct com_s *com;
- int cmd;
-{
- cd1400_channel_cmd_wait(com);
- cd_setreg(com, CD1400_CCR, cmd);
- cd1400_channel_cmd_wait(com);
-}
-
-static void
-cd1400_channel_cmd_wait(com)
- struct com_s *com;
-{
- struct timeval start;
- struct timeval tv;
- long usec;
-
- if (cd_getreg(com, CD1400_CCR) == 0)
- return;
- microtime(&start);
- for (;;) {
- if (cd_getreg(com, CD1400_CCR) == 0)
- return;
- microtime(&tv);
- usec = 1000000 * (tv.tv_sec - start.tv_sec) +
- tv.tv_usec - start.tv_usec;
- if (usec >= 5000) {
- log(LOG_ERR,
- "cy%d: channel command timeout (%ld usec)\n",
- com->unit, usec);
- return;
- }
- }
-}
-
-static void
-cd_etc(com, etc)
- struct com_s *com;
- int etc;
-{
-
- /*
- * We can't change the hardware's ETC state while there are any
- * characters in the tx fifo, since those characters would be
- * interpreted as commands! Unputting characters from the fifo
- * is difficult, so we wait up to 12 character times for the fifo
- * to drain. The command will be delayed for up to 2 character
- * times for the tx to become empty. Unputting characters from
- * the tx holding and shift registers is impossible, so we wait
- * for the tx to become empty so that the command is sure to be
- * executed soon after we issue it.
- */
- critical_enter();
- COM_LOCK();
- if (com->etc == etc)
- goto wait;
- if ((etc == CD1400_ETC_SENDBREAK
- && (com->etc == ETC_BREAK_STARTING
- || com->etc == ETC_BREAK_STARTED))
- || (etc == CD1400_ETC_STOPBREAK
- && (com->etc == ETC_BREAK_ENDING || com->etc == ETC_BREAK_ENDED
- || com->etc == ETC_NONE))) {
- COM_UNLOCK();
- critical_exit();
- return;
- }
- com->etc = etc;
- cd_setreg(com, CD1400_SRER,
- com->intr_enable
- = (com->intr_enable & ~CD1400_SRER_TXRDY) | CD1400_SRER_TXMPTY);
-wait:
- COM_UNLOCK();
- critical_exit();
- while (com->etc == etc
- && tsleep(&com->etc, TTIPRI | PCATCH, "cyetc", 0) == 0)
- continue;
-}
-
-static int
-cd_getreg(com, reg)
- struct com_s *com;
- int reg;
-{
- struct com_s *basecom;
- u_char car;
- int cy_align;
- register_t eflags;
- cy_addr iobase;
- int val;
-
- basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1));
- car = com->unit & CD1400_CAR_CHAN;
- cy_align = com->cy_align;
- iobase = com->iobase;
- eflags = read_eflags();
- critical_enter();
- if (eflags & PSL_I)
- COM_LOCK();
- if (basecom->car != car)
- cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car);
- val = cd_inb(iobase, reg, cy_align);
- if (eflags & PSL_I)
- COM_UNLOCK();
- critical_exit();
- return (val);
-}
-
-static void
-cd_setreg(com, reg, val)
- struct com_s *com;
- int reg;
- int val;
-{
- struct com_s *basecom;
- u_char car;
- int cy_align;
- register_t eflags;
- cy_addr iobase;
-
- basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1));
- car = com->unit & CD1400_CAR_CHAN;
- cy_align = com->cy_align;
- iobase = com->iobase;
- eflags = read_eflags();
- critical_enter();
- if (eflags & PSL_I)
- COM_LOCK();
- if (basecom->car != car)
- cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car);
- cd_outb(iobase, reg, cy_align, val);
- if (eflags & PSL_I)
- COM_UNLOCK();
- critical_exit();
-}
-
-#ifdef CyDebug
-/* useful in ddb */
-void
-cystatus(unit)
- int unit;
-{
- struct com_s *com;
- cy_addr iobase;
- u_int ocount;
- struct tty *tp;
-
- com = com_addr(unit);
- printf("info for channel %d\n", unit);
- printf("------------------\n");
- printf("total cyclom service probes:\t%d\n", cy_svrr_probes);
- printf("calls to upper layer:\t\t%d\n", cy_timeouts);
- if (com == NULL)
- return;
- iobase = com->iobase;
- printf("\n");
- printf("cd1400 base address:\\tt%p\n", iobase);
- printf("saved channel_control:\t\t0x%02x\n", com->channel_control);
- printf("saved cor1-3:\t\t\t0x%02x 0x%02x 0x%02x\n",
- com->cor[0], com->cor[1], com->cor[2]);
- printf("service request enable reg:\t0x%02x (0x%02x cached)\n",
- cd_getreg(com, CD1400_SRER), com->intr_enable);
- printf("service request register:\t0x%02x\n",
- cd_inb(iobase, CD1400_SVRR, com->cy_align));
- printf("modem status:\t\t\t0x%02x (0x%02x cached)\n",
- cd_getreg(com, CD1400_MSVR2), com->prev_modem_status);
- printf("rx/tx/mdm interrupt registers:\t0x%02x 0x%02x 0x%02x\n",
- cd_inb(iobase, CD1400_RIR, com->cy_align),
- cd_inb(iobase, CD1400_TIR, com->cy_align),
- cd_inb(iobase, CD1400_MIR, com->cy_align));
- printf("\n");
- printf("com state:\t\t\t0x%02x\n", com->state);
- printf("calls to comstart():\t\t%d (%d useful)\n",
- com->start_count, com->start_real);
- printf("rx buffer chars free:\t\t%d\n", com->iptr - com->ibuf);
- ocount = 0;
- if (com->obufs[0].l_queued)
- ocount += com->obufs[0].l_tail - com->obufs[0].l_head;
- if (com->obufs[1].l_queued)
- ocount += com->obufs[1].l_tail - com->obufs[1].l_head;
- printf("tx buffer chars:\t\t%u\n", ocount);
- printf("received chars:\t\t\t%d\n", com->bytes_in);
- printf("received exceptions:\t\t%d\n", com->recv_exception);
- printf("modem signal deltas:\t\t%d\n", com->mdm);
- printf("transmitted chars:\t\t%d\n", com->bytes_out);
- printf("\n");
- tp = com->tp;
- if (tp != NULL) {
- printf("tty state:\t\t\t0x%08x\n", tp->t_state);
- printf(
- "upper layer queue lengths:\t%d raw, %d canon, %d output\n",
- tp->t_rawq.c_cc, tp->t_canq.c_cc, tp->t_outq.c_cc);
- } else
- printf("tty state:\t\t\tclosed\n");
-}
-#endif /* CyDebug */
diff --git a/sys/dev/cy/cy_pci.c b/sys/dev/cy/cy_pci.c
deleted file mode 100644
index 303f2905d676..000000000000
--- a/sys/dev/cy/cy_pci.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (c) 1996, David Greenman
- * 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.
- *
- * $FreeBSD$
- */
-
-/*
- * Cyclades Y PCI serial interface driver
- */
-
-#include "opt_cy_pci_fastintr.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-
-#include <machine/bus.h>
-#include <sys/rman.h>
-#include <machine/resource.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-
-#include <dev/pci/pcivar.h>
-
-#define CY_PCI_BASE_ADDR0 0x10
-#define CY_PCI_BASE_ADDR1 0x14
-#define CY_PCI_BASE_ADDR2 0x18
-
-#define CY_PLX_9050_ICS 0x4c
-#define CY_PLX_9060_ICS 0x68
-#define CY_PLX_9050_ICS_IENABLE 0x040
-#define CY_PLX_9050_ICS_LOCAL_IENABLE 0x001
-#define CY_PLX_9050_ICS_LOCAL_IPOLARITY 0x002
-#define CY_PLX_9060_ICS_IENABLE 0x100
-#define CY_PLX_9060_ICS_LOCAL_IENABLE 0x800
-
-/* Cyclom-Y Custom Register for PLX ID. */
-#define PLX_VER 0x3400
-#define PLX_9050 0x0b
-#define PLX_9060 0x0c
-#define PLX_9080 0x0d
-
-extern int cyattach_common(void *, int); /* Not exactly correct */
-extern void cyintr(int);
-
-static int cy_pci_attach(device_t dev);
-static int cy_pci_probe(device_t dev);
-
-static device_method_t cy_pci_methods[] = {
- /* Device interface. */
- DEVMETHOD(device_probe, cy_pci_probe),
- DEVMETHOD(device_attach, cy_pci_attach),
-
- { 0, 0 }
-};
-
-static driver_t cy_pci_driver = {
- "cy",
- cy_pci_methods,
- 0,
-};
-
-static devclass_t cy_devclass;
-
-DRIVER_MODULE(cy, pci, cy_pci_driver, cy_devclass, 0, 0);
-MODULE_DEPEND(cy, pci, 1, 1, 1);
-
-static int
-cy_pci_probe(dev)
- device_t dev;
-{
- u_int32_t device_id;
-
- device_id = pci_get_devid(dev);
- device_id &= ~0x00060000;
- if (device_id != 0x0100120e && device_id != 0x0101120e)
- return (ENXIO);
- device_set_desc(dev, "Cyclades Cyclom-Y Serial Adapter");
- return (0);
-}
-
-static int
-cy_pci_attach(dev)
- device_t dev;
-{
- struct resource *ioport_res, *irq_res, *mem_res;
- void *irq_cookie, *vaddr;
- u_int32_t ioport;
- int adapter, irq_setup, ioport_rid, irq_rid, mem_rid;
- u_char plx_ver;
-
- ioport_res = NULL;
- irq_res = NULL;
- mem_res = NULL;
-
- ioport_rid = CY_PCI_BASE_ADDR1;
- ioport_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &ioport_rid,
- 0ul, ~0ul, 0ul, RF_ACTIVE);
- if (ioport_res == NULL) {
- device_printf(dev, "ioport resource allocation failed\n");
- goto fail;
- }
- ioport = rman_get_start(ioport_res);
-
- mem_rid = CY_PCI_BASE_ADDR2;
- mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid,
- 0ul, ~0ul, 0ul, RF_ACTIVE);
- if (mem_res == NULL) {
- device_printf(dev, "memory resource allocation failed\n");
- goto fail;
- }
- vaddr = rman_get_virtual(mem_res);
-
- adapter = cyattach_common(vaddr, 1);
- if (adapter < 0) {
- device_printf(dev, "no ports found!\n");
- goto fail;
- }
-
- /*
- * Allocate our interrupt.
- * XXX Using the ISA interrupt handler directly is a bit of a violation
- * since it doesn't actually take the same argument. For PCI, the
- * argument is a void * token, but for ISA it is a unit. Since
- * there is no overlap in PCI/ISA unit numbers for this driver, and
- * since the ISA driver must handle the interrupt anyway, we use
- * the unit number as the token even for PCI.
- */
- irq_rid = 0;
- irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &irq_rid, 0ul, ~0ul, 0ul,
- RF_SHAREABLE | RF_ACTIVE);
- if (irq_res == NULL) {
- device_printf(dev, "interrupt resource allocation failed\n");
- goto fail;
- }
-#ifdef CY_PCI_FASTINTR
- irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY | INTR_FAST,
- (driver_intr_t *)cyintr, (void *)adapter, &irq_cookie);
-#else
- irq_setup = ENXIO;
-#endif
- if (irq_setup != 0)
- irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY,
- (driver_intr_t *)cyintr, (void *)adapter, &irq_cookie);
- if (irq_setup != 0) {
- device_printf(dev, "interrupt setup failed\n");
- goto fail;
- }
-
- /*
- * Enable the "local" interrupt input to generate a
- * PCI interrupt.
- */
- plx_ver = *((u_char *)vaddr + PLX_VER) & 0x0f;
- switch (plx_ver) {
- case PLX_9050:
- outw(ioport + CY_PLX_9050_ICS,
- CY_PLX_9050_ICS_IENABLE | CY_PLX_9050_ICS_LOCAL_IENABLE |
- CY_PLX_9050_ICS_LOCAL_IPOLARITY);
- break;
- case PLX_9060:
- case PLX_9080:
- default: /* Old board, use PLX_9060 values. */
- outw(ioport + CY_PLX_9060_ICS,
- inw(ioport + CY_PLX_9060_ICS) | CY_PLX_9060_ICS_IENABLE |
- CY_PLX_9060_ICS_LOCAL_IENABLE);
- break;
- }
-
- return (0);
-
-fail:
- if (ioport_res != NULL)
- bus_release_resource(dev, SYS_RES_IOPORT, ioport_rid,
- ioport_res);
- if (irq_res != NULL)
- bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
- if (mem_res != NULL)
- bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
- return (ENXIO);
-}
diff --git a/sys/dev/cy/cyreg.h b/sys/dev/cy/cyreg.h
deleted file mode 100644
index 88a36eb4a65e..000000000000
--- a/sys/dev/cy/cyreg.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * Copyright (c) 1995 Bruce Evans.
- * 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 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.
- *
- * $FreeBSD$
- */
-
-/*
- * Definitions for Cyclades Cyclom-Y serial boards.
- */
-
-/*
- * Cyclades register offsets. These are physical offsets for ISA boards
- * and physical offsets divided by 2 for PCI boards.
- */
-#define CY8_SVCACKR 0x100 /* (r) */
-#define CY8_SVCACKT 0x200 /* (r) */
-#define CY8_SVCACKM 0x300 /* (r) */
-#define CY16_RESET 0x1400 /* (r) */
-#define CY_CLEAR_INTR 0x1800 /* intr ack address (w) */
-
-#define CY_MAX_CD1400s 8 /* for Cyclom-32Y */
-
-#define CY_CLOCK(version) ((version) >= 0x48 ? 60000000 : 25000000)
-#define CY_RTS_DTR_SWAPPED(version) ((version) >= 0x48)
-
-/*
- * The `cd' macros are for access to cd1400 registers. The `cy' macros
- * are for access to Cyclades registers. Both sets of macros scale the
- * register number to get an offset, but the scales are different for
- * mostly historical reasons.
- */
-#ifdef CyDebug
-#define cd_inb(iobase, reg, cy_align) \
- (++cd_inbs, *((iobase) + (2 * (reg) << (cy_align))))
-#define cy_inb(iobase, reg, cy_align) \
- (++cy_inbs, *((iobase) + ((reg) << (cy_align))))
-#define cd_outb(iobase, reg, cy_align, val) \
- (++cd_outbs, (void)(*((iobase) + (2 * (reg) << (cy_align))) = (val)))
-#define cy_outb(iobase, reg, cy_align, val) \
- (++cy_outbs, (void)(*((iobase) + ((reg) << (cy_align))) = (val)))
-#else
-#define cd_inb(iobase, reg, cy_align) \
- (*((iobase) + (2 * (reg) << (cy_align))))
-#define cy_inb(iobase, reg, cy_align) \
- (*((iobase) + ((reg) << (cy_align))))
-#define cd_outb(iobase, reg, cy_align, val) \
- ((void)(*((iobase) + (2 * (reg) << (cy_align))) = (val)))
-#define cy_outb(iobase, reg, cy_align, val) \
- ((void)(*((iobase) + ((reg) << (cy_align))) = (val)))
-#endif
diff --git a/sys/dev/dc/dcphy.c b/sys/dev/dc/dcphy.c
deleted file mode 100644
index 8b6656e9977e..000000000000
--- a/sys/dev/dc/dcphy.c
+++ /dev/null
@@ -1,462 +0,0 @@
-/*
- * Copyright (c) 1997, 1998, 1999
- * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Pseudo-driver for internal NWAY support on DEC 21143 and workalike
- * controllers. Technically we're abusing the miibus code to handle
- * media selection and NWAY support here since there is no MII
- * interface. However the logical operations are roughly the same,
- * and the alternative is to create a fake MII interface in the driver,
- * which is harder to do.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/socket.h>
-#include <sys/errno.h>
-#include <sys/lock.h>
-#include <sys/module.h>
-#include <sys/mutex.h>
-#include <sys/bus.h>
-
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/if_media.h>
-
-#include <dev/mii/mii.h>
-#include <dev/mii/miivar.h>
-#include "miidevs.h"
-
-#include <machine/bus_pio.h>
-#include <machine/bus_memio.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/bus.h>
-
-#include <pci/pcivar.h>
-
-#include <pci/if_dcreg.h>
-
-#include "miibus_if.h"
-
-#define DC_SETBIT(sc, reg, x) \
- CSR_WRITE_4(sc, reg, \
- CSR_READ_4(sc, reg) | x)
-
-#define DC_CLRBIT(sc, reg, x) \
- CSR_WRITE_4(sc, reg, \
- CSR_READ_4(sc, reg) & ~x)
-
-#define MIIF_AUTOTIMEOUT 0x0004
-
-/*
- * This is the subsystem ID for the built-in 21143 ethernet
- * in several Compaq Presario systems. Apparently these are
- * 10Mbps only, so we need to treat them specially.
- */
-#define COMPAQ_PRESARIO_ID 0xb0bb0e11
-
-static int dcphy_probe(device_t);
-static int dcphy_attach(device_t);
-
-static device_method_t dcphy_methods[] = {
- /* device interface */
- DEVMETHOD(device_probe, dcphy_probe),
- DEVMETHOD(device_attach, dcphy_attach),
- DEVMETHOD(device_detach, mii_phy_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- { 0, 0 }
-};
-
-static devclass_t dcphy_devclass;
-
-static driver_t dcphy_driver = {
- "dcphy",
- dcphy_methods,
- sizeof(struct mii_softc)
-};
-
-DRIVER_MODULE(dcphy, miibus, dcphy_driver, dcphy_devclass, 0, 0);
-
-static int dcphy_service(struct mii_softc *, struct mii_data *, int);
-static void dcphy_status(struct mii_softc *);
-static void dcphy_reset(struct mii_softc *);
-static int dcphy_auto(struct mii_softc *);
-
-static int
-dcphy_probe(dev)
- device_t dev;
-{
- struct mii_attach_args *ma;
-
- ma = device_get_ivars(dev);
-
- /*
- * The dc driver will report the 21143 vendor and device
- * ID to let us know that it wants us to attach.
- */
- if (ma->mii_id1 != DC_VENDORID_DEC ||
- ma->mii_id2 != DC_DEVICEID_21143)
- return(ENXIO);
-
- device_set_desc(dev, "Intel 21143 NWAY media interface");
-
- return (0);
-}
-
-static int
-dcphy_attach(dev)
- device_t dev;
-{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
- struct dc_softc *dc_sc;
-
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = device_get_softc(sc->mii_dev);
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_inst = mii->mii_instance;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = dcphy_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOISOLATE;
- mii->mii_instance++;
-
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
-
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst),
- BMCR_ISO);
-
- /*dcphy_reset(sc);*/
- dc_sc = mii->mii_ifp->if_softc;
- CSR_WRITE_4(dc_sc, DC_10BTSTAT, 0);
- CSR_WRITE_4(dc_sc, DC_10BTCTRL, 0);
-
- switch(pci_read_config(device_get_parent(sc->mii_dev),
- DC_PCI_CSID, 4)) {
- case COMPAQ_PRESARIO_ID:
- /* Example of how to only allow 10Mbps modes. */
- sc->mii_capabilities = BMSR_ANEG|BMSR_10TFDX|BMSR_10THDX;
- break;
- default:
- if (dc_sc->dc_pmode == DC_PMODE_SIA) {
- sc->mii_capabilities =
- BMSR_ANEG|BMSR_10TFDX|BMSR_10THDX;
- } else {
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP,
- sc->mii_inst), BMCR_LOOP|BMCR_S100);
-
- sc->mii_capabilities =
- BMSR_ANEG|BMSR_100TXFDX|BMSR_100TXHDX|
- BMSR_10TFDX|BMSR_10THDX;
- }
- break;
- }
-
- sc->mii_capabilities &= ma->mii_capmask;
- device_printf(dev, " ");
- mii_add_media(sc);
- printf("\n");
-#undef ADD
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
- return(0);
-}
-
-static int
-dcphy_service(sc, mii, cmd)
- struct mii_softc *sc;
- struct mii_data *mii;
- int cmd;
-{
- struct dc_softc *dc_sc;
- struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
- int reg;
- u_int32_t mode;
-
- dc_sc = mii->mii_ifp->if_softc;
-
- switch (cmd) {
- case MII_POLLSTAT:
- /*
- * If we're not polling our PHY instance, just return.
- */
- if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
- return (0);
- }
- break;
-
- case MII_MEDIACHG:
- /*
- * If the media indicates a different PHY instance,
- * isolate ourselves.
- */
- if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
- return (0);
- }
-
- /*
- * If the interface is not up, don't do anything.
- */
- if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
- break;
-
- sc->mii_flags = 0;
- mii->mii_media_active = IFM_NONE;
- mode = CSR_READ_4(dc_sc, DC_NETCFG);
- mode &= ~(DC_NETCFG_FULLDUPLEX|DC_NETCFG_PORTSEL|
- DC_NETCFG_PCS|DC_NETCFG_SCRAMBLER|DC_NETCFG_SPEEDSEL);
-
- switch (IFM_SUBTYPE(ife->ifm_media)) {
- case IFM_AUTO:
- /*dcphy_reset(sc);*/
- (void) dcphy_auto(sc);
- break;
- case IFM_100_T4:
- /*
- * XXX Not supported as a manual setting right now.
- */
- return (EINVAL);
- case IFM_100_TX:
- dcphy_reset(sc);
- DC_CLRBIT(dc_sc, DC_10BTCTRL, DC_TCTL_AUTONEGENBL);
- mode |= DC_NETCFG_PORTSEL|DC_NETCFG_PCS|
- DC_NETCFG_SCRAMBLER;
- if ((ife->ifm_media & IFM_GMASK) == IFM_FDX)
- mode |= DC_NETCFG_FULLDUPLEX;
- else
- mode &= ~DC_NETCFG_FULLDUPLEX;
- CSR_WRITE_4(dc_sc, DC_NETCFG, mode);
- break;
- case IFM_10_T:
- DC_CLRBIT(dc_sc, DC_SIARESET, DC_SIA_RESET);
- DC_CLRBIT(dc_sc, DC_10BTCTRL, 0xFFFF);
- if ((ife->ifm_media & IFM_GMASK) == IFM_FDX)
- DC_SETBIT(dc_sc, DC_10BTCTRL, 0x7F3D);
- else
- DC_SETBIT(dc_sc, DC_10BTCTRL, 0x7F3F);
- DC_SETBIT(dc_sc, DC_SIARESET, DC_SIA_RESET);
- DC_CLRBIT(dc_sc, DC_10BTCTRL, DC_TCTL_AUTONEGENBL);
- mode &= ~DC_NETCFG_PORTSEL;
- mode |= DC_NETCFG_SPEEDSEL;
- if ((ife->ifm_media & IFM_GMASK) == IFM_FDX)
- mode |= DC_NETCFG_FULLDUPLEX;
- else
- mode &= ~DC_NETCFG_FULLDUPLEX;
- CSR_WRITE_4(dc_sc, DC_NETCFG, mode);
- break;
- default:
- return(EINVAL);
- break;
- }
- break;
-
- case MII_TICK:
- /*
- * If we're not currently selected, just return.
- */
- if (IFM_INST(ife->ifm_media) != sc->mii_inst)
- return (0);
-
- /*
- * Is the interface even up?
- */
- if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
- return (0);
-
- /*
- * Only used for autonegotiation.
- */
- if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
- break;
-
- reg = CSR_READ_4(dc_sc, DC_10BTSTAT);
- if (!(reg & DC_TSTAT_LS10) || !(reg & DC_TSTAT_LS100))
- break;
-
- /*
- * Only retry autonegotiation every 5 seconds.
- *
- * Otherwise, fall through to calling dcphy_status()
- * since real Intel 21143 chips don't show valid link
- * status until autonegotiation is switched off, and
- * that only happens in dcphy_status(). Without this,
- * successful autonegotation is never recognised on
- * these chips.
- */
- if (++sc->mii_ticks != 50)
- break;
-
- sc->mii_ticks = 0;
- dcphy_auto(sc);
-
- break;
- }
-
- /* Update the media status. */
- dcphy_status(sc);
-
- /* Callback if something changed. */
- mii_phy_update(sc, cmd);
- return (0);
-}
-
-static void
-dcphy_status(sc)
- struct mii_softc *sc;
-{
- struct mii_data *mii = sc->mii_pdata;
- int reg, anlpar, tstat = 0;
- struct dc_softc *dc_sc;
-
- dc_sc = mii->mii_ifp->if_softc;
-
- mii->mii_media_status = IFM_AVALID;
- mii->mii_media_active = IFM_ETHER;
-
- if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
- return;
-
- reg = CSR_READ_4(dc_sc, DC_10BTSTAT);
- if (!(reg & DC_TSTAT_LS10) || !(reg & DC_TSTAT_LS100))
- mii->mii_media_status |= IFM_ACTIVE;
-
- if (CSR_READ_4(dc_sc, DC_10BTCTRL) & DC_TCTL_AUTONEGENBL) {
- /* Erg, still trying, I guess... */
- tstat = CSR_READ_4(dc_sc, DC_10BTSTAT);
- if ((tstat & DC_TSTAT_ANEGSTAT) != DC_ASTAT_AUTONEGCMP) {
- if ((DC_IS_MACRONIX(dc_sc) || DC_IS_PNICII(dc_sc)) &&
- (tstat & DC_TSTAT_ANEGSTAT) == DC_ASTAT_DISABLE)
- goto skip;
- mii->mii_media_active |= IFM_NONE;
- return;
- }
-
- if (tstat & DC_TSTAT_LP_CAN_NWAY) {
- anlpar = tstat >> 16;
- if (anlpar & ANLPAR_T4 &&
- sc->mii_capabilities & BMSR_100TXHDX)
- mii->mii_media_active |= IFM_100_T4;
- else if (anlpar & ANLPAR_TX_FD &&
- sc->mii_capabilities & BMSR_100TXFDX)
- mii->mii_media_active |= IFM_100_TX|IFM_FDX;
- else if (anlpar & ANLPAR_TX &&
- sc->mii_capabilities & BMSR_100TXHDX)
- mii->mii_media_active |= IFM_100_TX;
- else if (anlpar & ANLPAR_10_FD)
- mii->mii_media_active |= IFM_10_T|IFM_FDX;
- else if (anlpar & ANLPAR_10)
- mii->mii_media_active |= IFM_10_T;
- else
- mii->mii_media_active |= IFM_NONE;
- if (DC_IS_INTEL(dc_sc))
- DC_CLRBIT(dc_sc, DC_10BTCTRL,
- DC_TCTL_AUTONEGENBL);
- return;
- }
- /*
- * If the other side doesn't support NWAY, then the
- * best we can do is determine if we have a 10Mbps or
- * 100Mbps link. There's no way to know if the link
- * is full or half duplex, so we default to half duplex
- * and hope that the user is clever enough to manually
- * change the media settings if we're wrong.
- */
- if (!(reg & DC_TSTAT_LS100))
- mii->mii_media_active |= IFM_100_TX;
- else if (!(reg & DC_TSTAT_LS10))
- mii->mii_media_active |= IFM_10_T;
- else
- mii->mii_media_active |= IFM_NONE;
- if (DC_IS_INTEL(dc_sc))
- DC_CLRBIT(dc_sc, DC_10BTCTRL, DC_TCTL_AUTONEGENBL);
- return;
- }
-
-skip:
-
- if (CSR_READ_4(dc_sc, DC_NETCFG) & DC_NETCFG_SPEEDSEL)
- mii->mii_media_active |= IFM_10_T;
- else
- mii->mii_media_active |= IFM_100_TX;
- if (CSR_READ_4(dc_sc, DC_NETCFG) & DC_NETCFG_FULLDUPLEX)
- mii->mii_media_active |= IFM_FDX;
-
- return;
-}
-
-static int
-dcphy_auto(mii)
- struct mii_softc *mii;
-{
- struct dc_softc *sc;
-
- sc = mii->mii_pdata->mii_ifp->if_softc;
-
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_FULLDUPLEX);
- DC_CLRBIT(sc, DC_SIARESET, DC_SIA_RESET);
- if (mii->mii_capabilities & BMSR_100TXHDX)
- CSR_WRITE_4(sc, DC_10BTCTRL, 0x3FFFF);
- else
- CSR_WRITE_4(sc, DC_10BTCTRL, 0xFFFF);
- DC_SETBIT(sc, DC_SIARESET, DC_SIA_RESET);
- DC_SETBIT(sc, DC_10BTCTRL, DC_TCTL_AUTONEGENBL);
- DC_SETBIT(sc, DC_10BTSTAT, DC_ASTAT_TXDISABLE);
-
- return(EJUSTRETURN);
-}
-
-static void
-dcphy_reset(mii)
- struct mii_softc *mii;
-{
- struct dc_softc *sc;
-
- sc = mii->mii_pdata->mii_ifp->if_softc;
-
- DC_CLRBIT(sc, DC_SIARESET, DC_SIA_RESET);
- DELAY(1000);
- DC_SETBIT(sc, DC_SIARESET, DC_SIA_RESET);
-
- return;
-}
-
diff --git a/sys/dev/dc/if_dc.c b/sys/dev/dc/if_dc.c
deleted file mode 100644
index 8c3dceae865c..000000000000
--- a/sys/dev/dc/if_dc.c
+++ /dev/null
@@ -1,3790 +0,0 @@
-/*
- * Copyright (c) 1997, 1998, 1999
- * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * DEC "tulip" clone ethernet driver. Supports the DEC/Intel 21143
- * series chips and several workalikes including the following:
- *
- * Macronix 98713/98715/98725/98727/98732 PMAC (www.macronix.com)
- * Macronix/Lite-On 82c115 PNIC II (www.macronix.com)
- * Lite-On 82c168/82c169 PNIC (www.litecom.com)
- * ASIX Electronics AX88140A (www.asix.com.tw)
- * ASIX Electronics AX88141 (www.asix.com.tw)
- * ADMtek AL981 (www.admtek.com.tw)
- * ADMtek AN985 (www.admtek.com.tw)
- * Davicom DM9100, DM9102, DM9102A (www.davicom8.com)
- * Accton EN1217 (www.accton.com)
- * Xircom X3201 (www.xircom.com)
- * Abocom FE2500
- * Conexant LANfinity (www.conexant.com)
- * 3Com OfficeConnect 10/100B 3CSOHO100B (www.3com.com)
- *
- * Datasheets for the 21143 are available at developer.intel.com.
- * Datasheets for the clone parts can be found at their respective sites.
- * (Except for the PNIC; see www.freebsd.org/~wpaul/PNIC/pnic.ps.gz.)
- * The PNIC II is essentially a Macronix 98715A chip; the only difference
- * worth noting is that its multicast hash table is only 128 bits wide
- * instead of 512.
- *
- * Written by Bill Paul <wpaul@ee.columbia.edu>
- * Electrical Engineering Department
- * Columbia University, New York City
- */
-
-/*
- * The Intel 21143 is the successor to the DEC 21140. It is basically
- * the same as the 21140 but with a few new features. The 21143 supports
- * three kinds of media attachments:
- *
- * o MII port, for 10Mbps and 100Mbps support and NWAY
- * autonegotiation provided by an external PHY.
- * o SYM port, for symbol mode 100Mbps support.
- * o 10baseT port.
- * o AUI/BNC port.
- *
- * The 100Mbps SYM port and 10baseT port can be used together in
- * combination with the internal NWAY support to create a 10/100
- * autosensing configuration.
- *
- * Note that not all tulip workalikes are handled in this driver: we only
- * deal with those which are relatively well behaved. The Winbond is
- * handled separately due to its different register offsets and the
- * special handling needed for its various bugs. The PNIC is handled
- * here, but I'm not thrilled about it.
- *
- * All of the workalike chips use some form of MII transceiver support
- * with the exception of the Macronix chips, which also have a SYM port.
- * The ASIX AX88140A is also documented to have a SYM port, but all
- * the cards I've seen use an MII transceiver, probably because the
- * AX88140A doesn't support internal NWAY.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/sockio.h>
-#include <sys/mbuf.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/socket.h>
-#include <sys/sysctl.h>
-
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/ethernet.h>
-#include <net/if_dl.h>
-#include <net/if_media.h>
-#include <net/if_types.h>
-#include <net/if_vlan_var.h>
-
-#include <net/bpf.h>
-
-#include <vm/vm.h> /* for vtophys */
-#include <vm/pmap.h> /* for vtophys */
-#include <machine/bus_pio.h>
-#include <machine/bus_memio.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/bus.h>
-#include <sys/rman.h>
-
-#include <dev/mii/mii.h>
-#include <dev/mii/miivar.h>
-
-#include <pci/pcireg.h>
-#include <pci/pcivar.h>
-
-#define DC_USEIOSPACE
-#ifdef __alpha__
-#define SRM_MEDIA
-#endif
-
-#include <pci/if_dcreg.h>
-
-MODULE_DEPEND(dc, pci, 1, 1, 1);
-MODULE_DEPEND(dc, ether, 1, 1, 1);
-MODULE_DEPEND(dc, miibus, 1, 1, 1);
-
-/* "controller miibus0" required. See GENERIC if you get errors here. */
-#include "miibus_if.h"
-
-/*
- * Various supported device vendors/types and their names.
- */
-static struct dc_type dc_devs[] = {
- { DC_VENDORID_DEC, DC_DEVICEID_21143,
- "Intel 21143 10/100BaseTX" },
- { DC_VENDORID_DAVICOM, DC_DEVICEID_DM9009,
- "Davicom DM9009 10/100BaseTX" },
- { DC_VENDORID_DAVICOM, DC_DEVICEID_DM9100,
- "Davicom DM9100 10/100BaseTX" },
- { DC_VENDORID_DAVICOM, DC_DEVICEID_DM9102,
- "Davicom DM9102 10/100BaseTX" },
- { DC_VENDORID_DAVICOM, DC_DEVICEID_DM9102,
- "Davicom DM9102A 10/100BaseTX" },
- { DC_VENDORID_ADMTEK, DC_DEVICEID_AL981,
- "ADMtek AL981 10/100BaseTX" },
- { DC_VENDORID_ADMTEK, DC_DEVICEID_AN985,
- "ADMtek AN985 10/100BaseTX" },
- { DC_VENDORID_ASIX, DC_DEVICEID_AX88140A,
- "ASIX AX88140A 10/100BaseTX" },
- { DC_VENDORID_ASIX, DC_DEVICEID_AX88140A,
- "ASIX AX88141 10/100BaseTX" },
- { DC_VENDORID_MX, DC_DEVICEID_98713,
- "Macronix 98713 10/100BaseTX" },
- { DC_VENDORID_MX, DC_DEVICEID_98713,
- "Macronix 98713A 10/100BaseTX" },
- { DC_VENDORID_CP, DC_DEVICEID_98713_CP,
- "Compex RL100-TX 10/100BaseTX" },
- { DC_VENDORID_CP, DC_DEVICEID_98713_CP,
- "Compex RL100-TX 10/100BaseTX" },
- { DC_VENDORID_MX, DC_DEVICEID_987x5,
- "Macronix 98715/98715A 10/100BaseTX" },
- { DC_VENDORID_MX, DC_DEVICEID_987x5,
- "Macronix 98715AEC-C 10/100BaseTX" },
- { DC_VENDORID_MX, DC_DEVICEID_987x5,
- "Macronix 98725 10/100BaseTX" },
- { DC_VENDORID_MX, DC_DEVICEID_98727,
- "Macronix 98727/98732 10/100BaseTX" },
- { DC_VENDORID_LO, DC_DEVICEID_82C115,
- "LC82C115 PNIC II 10/100BaseTX" },
- { DC_VENDORID_LO, DC_DEVICEID_82C168,
- "82c168 PNIC 10/100BaseTX" },
- { DC_VENDORID_LO, DC_DEVICEID_82C168,
- "82c169 PNIC 10/100BaseTX" },
- { DC_VENDORID_ACCTON, DC_DEVICEID_EN1217,
- "Accton EN1217 10/100BaseTX" },
- { DC_VENDORID_ACCTON, DC_DEVICEID_EN2242,
- "Accton EN2242 MiniPCI 10/100BaseTX" },
- { DC_VENDORID_XIRCOM, DC_DEVICEID_X3201,
- "Xircom X3201 10/100BaseTX" },
- { DC_VENDORID_ABOCOM, DC_DEVICEID_FE2500,
- "Abocom FE2500 10/100BaseTX" },
- { DC_VENDORID_CONEXANT, DC_DEVICEID_RS7112,
- "Conexant LANfinity MiniPCI 10/100BaseTX" },
- { DC_VENDORID_HAWKING, DC_DEVICEID_HAWKING_PN672TX,
- "Hawking CB102 CardBus 10/100" },
- { DC_VENDORID_PLANEX, DC_DEVICEID_FNW3602T,
- "PlaneX FNW-3602-T CardBus 10/100" },
- { DC_VENDORID_3COM, DC_DEVICEID_3CSOHOB,
- "3Com OfficeConnect 10/100B" },
- { 0, 0, NULL }
-};
-
-static int dc_probe (device_t);
-static int dc_attach (device_t);
-static int dc_detach (device_t);
-static int dc_suspend (device_t);
-static int dc_resume (device_t);
-static void dc_acpi (device_t);
-static struct dc_type *dc_devtype (device_t);
-static int dc_newbuf (struct dc_softc *, int, struct mbuf *);
-static int dc_encap (struct dc_softc *, struct mbuf *, u_int32_t *);
-static void dc_pnic_rx_bug_war (struct dc_softc *, int);
-static int dc_rx_resync (struct dc_softc *);
-static void dc_rxeof (struct dc_softc *);
-static void dc_txeof (struct dc_softc *);
-static void dc_tick (void *);
-static void dc_tx_underrun (struct dc_softc *);
-static void dc_intr (void *);
-static void dc_start (struct ifnet *);
-static int dc_ioctl (struct ifnet *, u_long, caddr_t);
-static void dc_init (void *);
-static void dc_stop (struct dc_softc *);
-static void dc_watchdog (struct ifnet *);
-static void dc_shutdown (device_t);
-static int dc_ifmedia_upd (struct ifnet *);
-static void dc_ifmedia_sts (struct ifnet *, struct ifmediareq *);
-
-static void dc_delay (struct dc_softc *);
-static void dc_eeprom_idle (struct dc_softc *);
-static void dc_eeprom_putbyte (struct dc_softc *, int);
-static void dc_eeprom_getword (struct dc_softc *, int, u_int16_t *);
-static void dc_eeprom_getword_pnic
- (struct dc_softc *, int, u_int16_t *);
-static void dc_eeprom_getword_xircom
- (struct dc_softc *, int, u_int16_t *);
-static void dc_eeprom_width (struct dc_softc *);
-static void dc_read_eeprom (struct dc_softc *, caddr_t, int, int, int);
-
-static void dc_mii_writebit (struct dc_softc *, int);
-static int dc_mii_readbit (struct dc_softc *);
-static void dc_mii_sync (struct dc_softc *);
-static void dc_mii_send (struct dc_softc *, u_int32_t, int);
-static int dc_mii_readreg (struct dc_softc *, struct dc_mii_frame *);
-static int dc_mii_writereg (struct dc_softc *, struct dc_mii_frame *);
-static int dc_miibus_readreg (device_t, int, int);
-static int dc_miibus_writereg (device_t, int, int, int);
-static void dc_miibus_statchg (device_t);
-static void dc_miibus_mediainit (device_t);
-
-static void dc_setcfg (struct dc_softc *, int);
-static u_int32_t dc_crc_le (struct dc_softc *, caddr_t);
-static u_int32_t dc_crc_be (caddr_t);
-static void dc_setfilt_21143 (struct dc_softc *);
-static void dc_setfilt_asix (struct dc_softc *);
-static void dc_setfilt_admtek (struct dc_softc *);
-static void dc_setfilt_xircom (struct dc_softc *);
-
-static void dc_setfilt (struct dc_softc *);
-
-static void dc_reset (struct dc_softc *);
-static int dc_list_rx_init (struct dc_softc *);
-static int dc_list_tx_init (struct dc_softc *);
-
-static void dc_read_srom (struct dc_softc *, int);
-static void dc_parse_21143_srom (struct dc_softc *);
-static void dc_decode_leaf_sia (struct dc_softc *, struct dc_eblock_sia *);
-static void dc_decode_leaf_mii (struct dc_softc *, struct dc_eblock_mii *);
-static void dc_decode_leaf_sym (struct dc_softc *, struct dc_eblock_sym *);
-static void dc_apply_fixup (struct dc_softc *, int);
-
-#ifdef DC_USEIOSPACE
-#define DC_RES SYS_RES_IOPORT
-#define DC_RID DC_PCI_CFBIO
-#else
-#define DC_RES SYS_RES_MEMORY
-#define DC_RID DC_PCI_CFBMA
-#endif
-
-static device_method_t dc_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, dc_probe),
- DEVMETHOD(device_attach, dc_attach),
- DEVMETHOD(device_detach, dc_detach),
- DEVMETHOD(device_suspend, dc_suspend),
- DEVMETHOD(device_resume, dc_resume),
- DEVMETHOD(device_shutdown, dc_shutdown),
-
- /* bus interface */
- DEVMETHOD(bus_print_child, bus_generic_print_child),
- DEVMETHOD(bus_driver_added, bus_generic_driver_added),
-
- /* MII interface */
- DEVMETHOD(miibus_readreg, dc_miibus_readreg),
- DEVMETHOD(miibus_writereg, dc_miibus_writereg),
- DEVMETHOD(miibus_statchg, dc_miibus_statchg),
- DEVMETHOD(miibus_mediainit, dc_miibus_mediainit),
-
- { 0, 0 }
-};
-
-static driver_t dc_driver = {
- "dc",
- dc_methods,
- sizeof(struct dc_softc)
-};
-
-static devclass_t dc_devclass;
-#ifdef __i386__
-static int dc_quick=1;
-SYSCTL_INT(_hw, OID_AUTO, dc_quick, CTLFLAG_RW,
- &dc_quick,0,"do not mdevget in dc driver");
-#endif
-
-DRIVER_MODULE(dc, cardbus, dc_driver, dc_devclass, 0, 0);
-DRIVER_MODULE(dc, pci, dc_driver, dc_devclass, 0, 0);
-DRIVER_MODULE(miibus, dc, miibus_driver, miibus_devclass, 0, 0);
-
-#define DC_SETBIT(sc, reg, x) \
- CSR_WRITE_4(sc, reg, CSR_READ_4(sc, reg) | (x))
-
-#define DC_CLRBIT(sc, reg, x) \
- CSR_WRITE_4(sc, reg, CSR_READ_4(sc, reg) & ~(x))
-
-#define SIO_SET(x) DC_SETBIT(sc, DC_SIO, (x))
-#define SIO_CLR(x) DC_CLRBIT(sc, DC_SIO, (x))
-
-#define IS_MPSAFE 0
-
-static void
-dc_delay(sc)
- struct dc_softc *sc;
-{
- int idx;
-
- for (idx = (300 / 33) + 1; idx > 0; idx--)
- CSR_READ_4(sc, DC_BUSCTL);
-}
-
-static void
-dc_eeprom_width(sc)
- struct dc_softc *sc;
-{
- int i;
-
- /* Force EEPROM to idle state. */
- dc_eeprom_idle(sc);
-
- /* Enter EEPROM access mode. */
- CSR_WRITE_4(sc, DC_SIO, DC_SIO_EESEL);
- dc_delay(sc);
- DC_SETBIT(sc, DC_SIO, DC_SIO_ROMCTL_READ);
- dc_delay(sc);
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CS);
- dc_delay(sc);
-
- for (i = 3; i--;) {
- if (6 & (1 << i))
- DC_SETBIT(sc, DC_SIO, DC_SIO_EE_DATAIN);
- else
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_DATAIN);
- dc_delay(sc);
- DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- }
-
- for (i = 1; i <= 12; i++) {
- DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- if (!(CSR_READ_4(sc, DC_SIO) & DC_SIO_EE_DATAOUT)) {
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- break;
- }
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- }
-
- /* Turn off EEPROM access mode. */
- dc_eeprom_idle(sc);
-
- if (i < 4 || i > 12)
- sc->dc_romwidth = 6;
- else
- sc->dc_romwidth = i;
-
- /* Enter EEPROM access mode. */
- CSR_WRITE_4(sc, DC_SIO, DC_SIO_EESEL);
- dc_delay(sc);
- DC_SETBIT(sc, DC_SIO, DC_SIO_ROMCTL_READ);
- dc_delay(sc);
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CS);
- dc_delay(sc);
-
- /* Turn off EEPROM access mode. */
- dc_eeprom_idle(sc);
-}
-
-static void
-dc_eeprom_idle(sc)
- struct dc_softc *sc;
-{
- register int i;
-
- CSR_WRITE_4(sc, DC_SIO, DC_SIO_EESEL);
- dc_delay(sc);
- DC_SETBIT(sc, DC_SIO, DC_SIO_ROMCTL_READ);
- dc_delay(sc);
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CS);
- dc_delay(sc);
-
- for (i = 0; i < 25; i++) {
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- }
-
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CS);
- dc_delay(sc);
- CSR_WRITE_4(sc, DC_SIO, 0x00000000);
-
- return;
-}
-
-/*
- * Send a read command and address to the EEPROM, check for ACK.
- */
-static void
-dc_eeprom_putbyte(sc, addr)
- struct dc_softc *sc;
- int addr;
-{
- register int d, i;
-
- d = DC_EECMD_READ >> 6;
- for (i = 3; i--; ) {
- if (d & (1 << i))
- DC_SETBIT(sc, DC_SIO, DC_SIO_EE_DATAIN);
- else
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_DATAIN);
- dc_delay(sc);
- DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- }
-
- /*
- * Feed in each bit and strobe the clock.
- */
- for (i = sc->dc_romwidth; i--;) {
- if (addr & (1 << i)) {
- SIO_SET(DC_SIO_EE_DATAIN);
- } else {
- SIO_CLR(DC_SIO_EE_DATAIN);
- }
- dc_delay(sc);
- SIO_SET(DC_SIO_EE_CLK);
- dc_delay(sc);
- SIO_CLR(DC_SIO_EE_CLK);
- dc_delay(sc);
- }
-
- return;
-}
-
-/*
- * Read a word of data stored in the EEPROM at address 'addr.'
- * The PNIC 82c168/82c169 has its own non-standard way to read
- * the EEPROM.
- */
-static void
-dc_eeprom_getword_pnic(sc, addr, dest)
- struct dc_softc *sc;
- int addr;
- u_int16_t *dest;
-{
- register int i;
- u_int32_t r;
-
- CSR_WRITE_4(sc, DC_PN_SIOCTL, DC_PN_EEOPCODE_READ|addr);
-
- for (i = 0; i < DC_TIMEOUT; i++) {
- DELAY(1);
- r = CSR_READ_4(sc, DC_SIO);
- if (!(r & DC_PN_SIOCTL_BUSY)) {
- *dest = (u_int16_t)(r & 0xFFFF);
- return;
- }
- }
-
- return;
-}
-
-/*
- * Read a word of data stored in the EEPROM at address 'addr.'
- * The Xircom X3201 has its own non-standard way to read
- * the EEPROM, too.
- */
-static void
-dc_eeprom_getword_xircom(sc, addr, dest)
- struct dc_softc *sc;
- int addr;
- u_int16_t *dest;
-{
- SIO_SET(DC_SIO_ROMSEL | DC_SIO_ROMCTL_READ);
-
- addr *= 2;
- CSR_WRITE_4(sc, DC_ROM, addr | 0x160);
- *dest = (u_int16_t)CSR_READ_4(sc, DC_SIO)&0xff;
- addr += 1;
- CSR_WRITE_4(sc, DC_ROM, addr | 0x160);
- *dest |= ((u_int16_t)CSR_READ_4(sc, DC_SIO)&0xff) << 8;
-
- SIO_CLR(DC_SIO_ROMSEL | DC_SIO_ROMCTL_READ);
- return;
-}
-
-/*
- * Read a word of data stored in the EEPROM at address 'addr.'
- */
-static void
-dc_eeprom_getword(sc, addr, dest)
- struct dc_softc *sc;
- int addr;
- u_int16_t *dest;
-{
- register int i;
- u_int16_t word = 0;
-
- /* Force EEPROM to idle state. */
- dc_eeprom_idle(sc);
-
- /* Enter EEPROM access mode. */
- CSR_WRITE_4(sc, DC_SIO, DC_SIO_EESEL);
- dc_delay(sc);
- DC_SETBIT(sc, DC_SIO, DC_SIO_ROMCTL_READ);
- dc_delay(sc);
- DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
- dc_delay(sc);
- DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CS);
- dc_delay(sc);
-
- /*
- * Send address of word we want to read.
- */
- dc_eeprom_putbyte(sc, addr);
-
- /*
- * Start reading bits from EEPROM.
- */
- for (i = 0x8000; i; i >>= 1) {
- SIO_SET(DC_SIO_EE_CLK);
- dc_delay(sc);
- if (CSR_READ_4(sc, DC_SIO) & DC_SIO_EE_DATAOUT)
- word |= i;
- dc_delay(sc);
- SIO_CLR(DC_SIO_EE_CLK);
- dc_delay(sc);
- }
-
- /* Turn off EEPROM access mode. */
- dc_eeprom_idle(sc);
-
- *dest = word;
-
- return;
-}
-
-/*
- * Read a sequence of words from the EEPROM.
- */
-static void
-dc_read_eeprom(sc, dest, off, cnt, swap)
- struct dc_softc *sc;
- caddr_t dest;
- int off;
- int cnt;
- int swap;
-{
- int i;
- u_int16_t word = 0, *ptr;
-
- for (i = 0; i < cnt; i++) {
- if (DC_IS_PNIC(sc))
- dc_eeprom_getword_pnic(sc, off + i, &word);
- else if (DC_IS_XIRCOM(sc))
- dc_eeprom_getword_xircom(sc, off + i, &word);
- else
- dc_eeprom_getword(sc, off + i, &word);
- ptr = (u_int16_t *)(dest + (i * 2));
- if (swap)
- *ptr = ntohs(word);
- else
- *ptr = word;
- }
-
- return;
-}
-
-/*
- * The following two routines are taken from the Macronix 98713
- * Application Notes pp.19-21.
- */
-/*
- * Write a bit to the MII bus.
- */
-static void
-dc_mii_writebit(sc, bit)
- struct dc_softc *sc;
- int bit;
-{
- if (bit)
- CSR_WRITE_4(sc, DC_SIO,
- DC_SIO_ROMCTL_WRITE|DC_SIO_MII_DATAOUT);
- else
- CSR_WRITE_4(sc, DC_SIO, DC_SIO_ROMCTL_WRITE);
-
- DC_SETBIT(sc, DC_SIO, DC_SIO_MII_CLK);
- DC_CLRBIT(sc, DC_SIO, DC_SIO_MII_CLK);
-
- return;
-}
-
-/*
- * Read a bit from the MII bus.
- */
-static int
-dc_mii_readbit(sc)
- struct dc_softc *sc;
-{
- CSR_WRITE_4(sc, DC_SIO, DC_SIO_ROMCTL_READ|DC_SIO_MII_DIR);
- CSR_READ_4(sc, DC_SIO);
- DC_SETBIT(sc, DC_SIO, DC_SIO_MII_CLK);
- DC_CLRBIT(sc, DC_SIO, DC_SIO_MII_CLK);
- if (CSR_READ_4(sc, DC_SIO) & DC_SIO_MII_DATAIN)
- return(1);
-
- return(0);
-}
-
-/*
- * Sync the PHYs by setting data bit and strobing the clock 32 times.
- */
-static void
-dc_mii_sync(sc)
- struct dc_softc *sc;
-{
- register int i;
-
- CSR_WRITE_4(sc, DC_SIO, DC_SIO_ROMCTL_WRITE);
-
- for (i = 0; i < 32; i++)
- dc_mii_writebit(sc, 1);
-
- return;
-}
-
-/*
- * Clock a series of bits through the MII.
- */
-static void
-dc_mii_send(sc, bits, cnt)
- struct dc_softc *sc;
- u_int32_t bits;
- int cnt;
-{
- int i;
-
- for (i = (0x1 << (cnt - 1)); i; i >>= 1)
- dc_mii_writebit(sc, bits & i);
-}
-
-/*
- * Read an PHY register through the MII.
- */
-static int
-dc_mii_readreg(sc, frame)
- struct dc_softc *sc;
- struct dc_mii_frame *frame;
-
-{
- int i, ack;
-
- DC_LOCK(sc);
-
- /*
- * Set up frame for RX.
- */
- frame->mii_stdelim = DC_MII_STARTDELIM;
- frame->mii_opcode = DC_MII_READOP;
- frame->mii_turnaround = 0;
- frame->mii_data = 0;
-
- /*
- * Sync the PHYs.
- */
- dc_mii_sync(sc);
-
- /*
- * Send command/address info.
- */
- dc_mii_send(sc, frame->mii_stdelim, 2);
- dc_mii_send(sc, frame->mii_opcode, 2);
- dc_mii_send(sc, frame->mii_phyaddr, 5);
- dc_mii_send(sc, frame->mii_regaddr, 5);
-
-#ifdef notdef
- /* Idle bit */
- dc_mii_writebit(sc, 1);
- dc_mii_writebit(sc, 0);
-#endif
-
- /* Check for ack */
- ack = dc_mii_readbit(sc);
-
- /*
- * Now try reading data bits. If the ack failed, we still
- * need to clock through 16 cycles to keep the PHY(s) in sync.
- */
- if (ack) {
- for(i = 0; i < 16; i++) {
- dc_mii_readbit(sc);
- }
- goto fail;
- }
-
- for (i = 0x8000; i; i >>= 1) {
- if (!ack) {
- if (dc_mii_readbit(sc))
- frame->mii_data |= i;
- }
- }
-
-fail:
-
- dc_mii_writebit(sc, 0);
- dc_mii_writebit(sc, 0);
-
- DC_UNLOCK(sc);
-
- if (ack)
- return(1);
- return(0);
-}
-
-/*
- * Write to a PHY register through the MII.
- */
-static int
-dc_mii_writereg(sc, frame)
- struct dc_softc *sc;
- struct dc_mii_frame *frame;
-
-{
- DC_LOCK(sc);
- /*
- * Set up frame for TX.
- */
-
- frame->mii_stdelim = DC_MII_STARTDELIM;
- frame->mii_opcode = DC_MII_WRITEOP;
- frame->mii_turnaround = DC_MII_TURNAROUND;
-
- /*
- * Sync the PHYs.
- */
- dc_mii_sync(sc);
-
- dc_mii_send(sc, frame->mii_stdelim, 2);
- dc_mii_send(sc, frame->mii_opcode, 2);
- dc_mii_send(sc, frame->mii_phyaddr, 5);
- dc_mii_send(sc, frame->mii_regaddr, 5);
- dc_mii_send(sc, frame->mii_turnaround, 2);
- dc_mii_send(sc, frame->mii_data, 16);
-
- /* Idle bit. */
- dc_mii_writebit(sc, 0);
- dc_mii_writebit(sc, 0);
-
- DC_UNLOCK(sc);
-
- return(0);
-}
-
-static int
-dc_miibus_readreg(dev, phy, reg)
- device_t dev;
- int phy, reg;
-{
- struct dc_mii_frame frame;
- struct dc_softc *sc;
- int i, rval, phy_reg = 0;
-
- sc = device_get_softc(dev);
- bzero((char *)&frame, sizeof(frame));
-
- /*
- * Note: both the AL981 and AN985 have internal PHYs,
- * however the AL981 provides direct access to the PHY
- * registers while the AN985 uses a serial MII interface.
- * The AN985's MII interface is also buggy in that you
- * can read from any MII address (0 to 31), but only address 1
- * behaves normally. To deal with both cases, we pretend
- * that the PHY is at MII address 1.
- */
- if (DC_IS_ADMTEK(sc) && phy != DC_ADMTEK_PHYADDR)
- return(0);
-
- /*
- * Note: the ukphy probes of the RS7112 report a PHY at
- * MII address 0 (possibly HomePNA?) and 1 (ethernet)
- * so we only respond to correct one.
- */
- if (DC_IS_CONEXANT(sc) && phy != DC_CONEXANT_PHYADDR)
- return(0);
-
- if (sc->dc_pmode != DC_PMODE_MII) {
- if (phy == (MII_NPHY - 1)) {
- switch(reg) {
- case MII_BMSR:
- /*
- * Fake something to make the probe
- * code think there's a PHY here.
- */
- return(BMSR_MEDIAMASK);
- break;
- case MII_PHYIDR1:
- if (DC_IS_PNIC(sc))
- return(DC_VENDORID_LO);
- return(DC_VENDORID_DEC);
- break;
- case MII_PHYIDR2:
- if (DC_IS_PNIC(sc))
- return(DC_DEVICEID_82C168);
- return(DC_DEVICEID_21143);
- break;
- default:
- return(0);
- break;
- }
- } else
- return(0);
- }
-
- if (DC_IS_PNIC(sc)) {
- CSR_WRITE_4(sc, DC_PN_MII, DC_PN_MIIOPCODE_READ |
- (phy << 23) | (reg << 18));
- for (i = 0; i < DC_TIMEOUT; i++) {
- DELAY(1);
- rval = CSR_READ_4(sc, DC_PN_MII);
- if (!(rval & DC_PN_MII_BUSY)) {
- rval &= 0xFFFF;
- return(rval == 0xFFFF ? 0 : rval);
- }
- }
- return(0);
- }
-
- if (DC_IS_COMET(sc)) {
- switch(reg) {
- case MII_BMCR:
- phy_reg = DC_AL_BMCR;
- break;
- case MII_BMSR:
- phy_reg = DC_AL_BMSR;
- break;
- case MII_PHYIDR1:
- phy_reg = DC_AL_VENID;
- break;
- case MII_PHYIDR2:
- phy_reg = DC_AL_DEVID;
- break;
- case MII_ANAR:
- phy_reg = DC_AL_ANAR;
- break;
- case MII_ANLPAR:
- phy_reg = DC_AL_LPAR;
- break;
- case MII_ANER:
- phy_reg = DC_AL_ANER;
- break;
- default:
- printf("dc%d: phy_read: bad phy register %x\n",
- sc->dc_unit, reg);
- return(0);
- break;
- }
-
- rval = CSR_READ_4(sc, phy_reg) & 0x0000FFFF;
-
- if (rval == 0xFFFF)
- return(0);
- return(rval);
- }
-
- frame.mii_phyaddr = phy;
- frame.mii_regaddr = reg;
- if (sc->dc_type == DC_TYPE_98713) {
- phy_reg = CSR_READ_4(sc, DC_NETCFG);
- CSR_WRITE_4(sc, DC_NETCFG, phy_reg & ~DC_NETCFG_PORTSEL);
- }
- dc_mii_readreg(sc, &frame);
- if (sc->dc_type == DC_TYPE_98713)
- CSR_WRITE_4(sc, DC_NETCFG, phy_reg);
-
- return(frame.mii_data);
-}
-
-static int
-dc_miibus_writereg(dev, phy, reg, data)
- device_t dev;
- int phy, reg, data;
-{
- struct dc_softc *sc;
- struct dc_mii_frame frame;
- int i, phy_reg = 0;
-
- sc = device_get_softc(dev);
- bzero((char *)&frame, sizeof(frame));
-
- if (DC_IS_ADMTEK(sc) && phy != DC_ADMTEK_PHYADDR)
- return(0);
-
- if (DC_IS_CONEXANT(sc) && phy != DC_CONEXANT_PHYADDR)
- return(0);
-
- if (DC_IS_PNIC(sc)) {
- CSR_WRITE_4(sc, DC_PN_MII, DC_PN_MIIOPCODE_WRITE |
- (phy << 23) | (reg << 10) | data);
- for (i = 0; i < DC_TIMEOUT; i++) {
- if (!(CSR_READ_4(sc, DC_PN_MII) & DC_PN_MII_BUSY))
- break;
- }
- return(0);
- }
-
- if (DC_IS_COMET(sc)) {
- switch(reg) {
- case MII_BMCR:
- phy_reg = DC_AL_BMCR;
- break;
- case MII_BMSR:
- phy_reg = DC_AL_BMSR;
- break;
- case MII_PHYIDR1:
- phy_reg = DC_AL_VENID;
- break;
- case MII_PHYIDR2:
- phy_reg = DC_AL_DEVID;
- break;
- case MII_ANAR:
- phy_reg = DC_AL_ANAR;
- break;
- case MII_ANLPAR:
- phy_reg = DC_AL_LPAR;
- break;
- case MII_ANER:
- phy_reg = DC_AL_ANER;
- break;
- default:
- printf("dc%d: phy_write: bad phy register %x\n",
- sc->dc_unit, reg);
- return(0);
- break;
- }
-
- CSR_WRITE_4(sc, phy_reg, data);
- return(0);
- }
-
- frame.mii_phyaddr = phy;
- frame.mii_regaddr = reg;
- frame.mii_data = data;
-
- if (sc->dc_type == DC_TYPE_98713) {
- phy_reg = CSR_READ_4(sc, DC_NETCFG);
- CSR_WRITE_4(sc, DC_NETCFG, phy_reg & ~DC_NETCFG_PORTSEL);
- }
- dc_mii_writereg(sc, &frame);
- if (sc->dc_type == DC_TYPE_98713)
- CSR_WRITE_4(sc, DC_NETCFG, phy_reg);
-
- return(0);
-}
-
-static void
-dc_miibus_statchg(dev)
- device_t dev;
-{
- struct dc_softc *sc;
- struct mii_data *mii;
- struct ifmedia *ifm;
-
- sc = device_get_softc(dev);
- if (DC_IS_ADMTEK(sc))
- return;
-
- mii = device_get_softc(sc->dc_miibus);
- ifm = &mii->mii_media;
- if (DC_IS_DAVICOM(sc) &&
- IFM_SUBTYPE(ifm->ifm_media) == IFM_HPNA_1) {
- dc_setcfg(sc, ifm->ifm_media);
- sc->dc_if_media = ifm->ifm_media;
- } else {
- dc_setcfg(sc, mii->mii_media_active);
- sc->dc_if_media = mii->mii_media_active;
- }
-
- return;
-}
-
-/*
- * Special support for DM9102A cards with HomePNA PHYs. Note:
- * with the Davicom DM9102A/DM9801 eval board that I have, it seems
- * to be impossible to talk to the management interface of the DM9801
- * PHY (its MDIO pin is not connected to anything). Consequently,
- * the driver has to just 'know' about the additional mode and deal
- * with it itself. *sigh*
- */
-static void
-dc_miibus_mediainit(dev)
- device_t dev;
-{
- struct dc_softc *sc;
- struct mii_data *mii;
- struct ifmedia *ifm;
- int rev;
-
- rev = pci_read_config(dev, DC_PCI_CFRV, 4) & 0xFF;
-
- sc = device_get_softc(dev);
- mii = device_get_softc(sc->dc_miibus);
- ifm = &mii->mii_media;
-
- if (DC_IS_DAVICOM(sc) && rev >= DC_REVISION_DM9102A)
- ifmedia_add(ifm, IFM_ETHER|IFM_HPNA_1, 0, NULL);
-
- return;
-}
-
-#define DC_POLY 0xEDB88320
-#define DC_BITS_512 9
-#define DC_BITS_128 7
-#define DC_BITS_64 6
-
-static u_int32_t
-dc_crc_le(sc, addr)
- struct dc_softc *sc;
- caddr_t addr;
-{
- u_int32_t idx, bit, data, crc;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (idx = 0; idx < 6; idx++) {
- for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
- crc = (crc >> 1) ^ (((crc ^ data) & 1) ? DC_POLY : 0);
- }
-
- /*
- * The hash table on the PNIC II and the MX98715AEC-C/D/E
- * chips is only 128 bits wide.
- */
- if (sc->dc_flags & DC_128BIT_HASH)
- return (crc & ((1 << DC_BITS_128) - 1));
-
- /* The hash table on the MX98715BEC is only 64 bits wide. */
- if (sc->dc_flags & DC_64BIT_HASH)
- return (crc & ((1 << DC_BITS_64) - 1));
-
- /* Xircom's hash filtering table is different (read: weird) */
- /* Xircom uses the LEAST significant bits */
- if (DC_IS_XIRCOM(sc)) {
- if ((crc & 0x180) == 0x180)
- return (crc & 0x0F) + (crc & 0x70)*3 + (14 << 4);
- else
- return (crc & 0x1F) + ((crc>>1) & 0xF0)*3 + (12 << 4);
- }
-
- return (crc & ((1 << DC_BITS_512) - 1));
-}
-
-/*
- * Calculate CRC of a multicast group address, return the lower 6 bits.
- */
-static u_int32_t
-dc_crc_be(addr)
- caddr_t addr;
-{
- u_int32_t crc, carry;
- int i, j;
- u_int8_t c;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (i = 0; i < 6; i++) {
- c = *(addr + i);
- for (j = 0; j < 8; j++) {
- carry = ((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01);
- crc <<= 1;
- c >>= 1;
- if (carry)
- crc = (crc ^ 0x04c11db6) | carry;
- }
- }
-
- /* return the filter bit position */
- return((crc >> 26) & 0x0000003F);
-}
-
-/*
- * 21143-style RX filter setup routine. Filter programming is done by
- * downloading a special setup frame into the TX engine. 21143, Macronix,
- * PNIC, PNIC II and Davicom chips are programmed this way.
- *
- * We always program the chip using 'hash perfect' mode, i.e. one perfect
- * address (our node address) and a 512-bit hash filter for multicast
- * frames. We also sneak the broadcast address into the hash filter since
- * we need that too.
- */
-static void
-dc_setfilt_21143(sc)
- struct dc_softc *sc;
-{
- struct dc_desc *sframe;
- u_int32_t h, *sp;
- struct ifmultiaddr *ifma;
- struct ifnet *ifp;
- int i;
-
- ifp = &sc->arpcom.ac_if;
-
- i = sc->dc_cdata.dc_tx_prod;
- DC_INC(sc->dc_cdata.dc_tx_prod, DC_TX_LIST_CNT);
- sc->dc_cdata.dc_tx_cnt++;
- sframe = &sc->dc_ldata->dc_tx_list[i];
- sp = (u_int32_t *)&sc->dc_cdata.dc_sbuf;
- bzero((char *)sp, DC_SFRAME_LEN);
-
- sframe->dc_data = vtophys(&sc->dc_cdata.dc_sbuf);
- sframe->dc_ctl = DC_SFRAME_LEN | DC_TXCTL_SETUP | DC_TXCTL_TLINK |
- DC_FILTER_HASHPERF | DC_TXCTL_FINT;
-
- sc->dc_cdata.dc_tx_chain[i] = (struct mbuf *)&sc->dc_cdata.dc_sbuf;
-
- /* If we want promiscuous mode, set the allframes bit. */
- if (ifp->if_flags & IFF_PROMISC)
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
- else
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
-
- if (ifp->if_flags & IFF_ALLMULTI)
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
- else
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
-
- TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
- if (ifma->ifma_addr->sa_family != AF_LINK)
- continue;
- h = dc_crc_le(sc,
- LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
- sp[h >> 4] |= 1 << (h & 0xF);
- }
-
- if (ifp->if_flags & IFF_BROADCAST) {
- h = dc_crc_le(sc, (caddr_t)ifp->if_broadcastaddr);
- sp[h >> 4] |= 1 << (h & 0xF);
- }
-
- /* Set our MAC address */
- sp[39] = ((u_int16_t *)sc->arpcom.ac_enaddr)[0];
- sp[40] = ((u_int16_t *)sc->arpcom.ac_enaddr)[1];
- sp[41] = ((u_int16_t *)sc->arpcom.ac_enaddr)[2];
-
- sframe->dc_status = DC_TXSTAT_OWN;
- CSR_WRITE_4(sc, DC_TXSTART, 0xFFFFFFFF);
-
- /*
- * The PNIC takes an exceedingly long time to process its
- * setup frame; wait 10ms after posting the setup frame
- * before proceeding, just so it has time to swallow its
- * medicine.
- */
- DELAY(10000);
-
- ifp->if_timer = 5;
-
- return;
-}
-
-static void
-dc_setfilt_admtek(sc)
- struct dc_softc *sc;
-{
- struct ifnet *ifp;
- int h = 0;
- u_int32_t hashes[2] = { 0, 0 };
- struct ifmultiaddr *ifma;
-
- ifp = &sc->arpcom.ac_if;
-
- /* Init our MAC address */
- CSR_WRITE_4(sc, DC_AL_PAR0, *(u_int32_t *)(&sc->arpcom.ac_enaddr[0]));
- CSR_WRITE_4(sc, DC_AL_PAR1, *(u_int32_t *)(&sc->arpcom.ac_enaddr[4]));
-
- /* If we want promiscuous mode, set the allframes bit. */
- if (ifp->if_flags & IFF_PROMISC)
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
- else
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
-
- if (ifp->if_flags & IFF_ALLMULTI)
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
- else
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
-
- /* first, zot all the existing hash bits */
- CSR_WRITE_4(sc, DC_AL_MAR0, 0);
- CSR_WRITE_4(sc, DC_AL_MAR1, 0);
-
- /*
- * If we're already in promisc or allmulti mode, we
- * don't have to bother programming the multicast filter.
- */
- if (ifp->if_flags & (IFF_PROMISC|IFF_ALLMULTI))
- return;
-
- /* now program new ones */
- TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
- if (ifma->ifma_addr->sa_family != AF_LINK)
- continue;
- if (DC_IS_CENTAUR(sc))
- h = dc_crc_le(sc, LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
- else
- h = dc_crc_be(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
- if (h < 32)
- hashes[0] |= (1 << h);
- else
- hashes[1] |= (1 << (h - 32));
- }
-
- CSR_WRITE_4(sc, DC_AL_MAR0, hashes[0]);
- CSR_WRITE_4(sc, DC_AL_MAR1, hashes[1]);
-
- return;
-}
-
-static void
-dc_setfilt_asix(sc)
- struct dc_softc *sc;
-{
- struct ifnet *ifp;
- int h = 0;
- u_int32_t hashes[2] = { 0, 0 };
- struct ifmultiaddr *ifma;
-
- ifp = &sc->arpcom.ac_if;
-
- /* Init our MAC address */
- CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_PAR0);
- CSR_WRITE_4(sc, DC_AX_FILTDATA,
- *(u_int32_t *)(&sc->arpcom.ac_enaddr[0]));
- CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_PAR1);
- CSR_WRITE_4(sc, DC_AX_FILTDATA,
- *(u_int32_t *)(&sc->arpcom.ac_enaddr[4]));
-
- /* If we want promiscuous mode, set the allframes bit. */
- if (ifp->if_flags & IFF_PROMISC)
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
- else
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
-
- if (ifp->if_flags & IFF_ALLMULTI)
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
- else
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
-
- /*
- * The ASIX chip has a special bit to enable reception
- * of broadcast frames.
- */
- if (ifp->if_flags & IFF_BROADCAST)
- DC_SETBIT(sc, DC_NETCFG, DC_AX_NETCFG_RX_BROAD);
- else
- DC_CLRBIT(sc, DC_NETCFG, DC_AX_NETCFG_RX_BROAD);
-
- /* first, zot all the existing hash bits */
- CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_MAR0);
- CSR_WRITE_4(sc, DC_AX_FILTDATA, 0);
- CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_MAR1);
- CSR_WRITE_4(sc, DC_AX_FILTDATA, 0);
-
- /*
- * If we're already in promisc or allmulti mode, we
- * don't have to bother programming the multicast filter.
- */
- if (ifp->if_flags & (IFF_PROMISC|IFF_ALLMULTI))
- return;
-
- /* now program new ones */
- TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
- if (ifma->ifma_addr->sa_family != AF_LINK)
- continue;
- h = dc_crc_be(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
- if (h < 32)
- hashes[0] |= (1 << h);
- else
- hashes[1] |= (1 << (h - 32));
- }
-
- CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_MAR0);
- CSR_WRITE_4(sc, DC_AX_FILTDATA, hashes[0]);
- CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_MAR1);
- CSR_WRITE_4(sc, DC_AX_FILTDATA, hashes[1]);
-
- return;
-}
-
-static void
-dc_setfilt_xircom(sc)
- struct dc_softc *sc;
-{
- struct dc_desc *sframe;
- u_int32_t h, *sp;
- struct ifmultiaddr *ifma;
- struct ifnet *ifp;
- int i;
-
- ifp = &sc->arpcom.ac_if;
- DC_CLRBIT(sc, DC_NETCFG, (DC_NETCFG_TX_ON|DC_NETCFG_RX_ON));
-
- i = sc->dc_cdata.dc_tx_prod;
- DC_INC(sc->dc_cdata.dc_tx_prod, DC_TX_LIST_CNT);
- sc->dc_cdata.dc_tx_cnt++;
- sframe = &sc->dc_ldata->dc_tx_list[i];
- sp = (u_int32_t *)&sc->dc_cdata.dc_sbuf;
- bzero((char *)sp, DC_SFRAME_LEN);
-
- sframe->dc_data = vtophys(&sc->dc_cdata.dc_sbuf);
- sframe->dc_ctl = DC_SFRAME_LEN | DC_TXCTL_SETUP | DC_TXCTL_TLINK |
- DC_FILTER_HASHPERF | DC_TXCTL_FINT;
-
- sc->dc_cdata.dc_tx_chain[i] = (struct mbuf *)&sc->dc_cdata.dc_sbuf;
-
- /* If we want promiscuous mode, set the allframes bit. */
- if (ifp->if_flags & IFF_PROMISC)
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
- else
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
-
- if (ifp->if_flags & IFF_ALLMULTI)
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
- else
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
-
- TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
- if (ifma->ifma_addr->sa_family != AF_LINK)
- continue;
- h = dc_crc_le(sc,
- LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
- sp[h >> 4] |= 1 << (h & 0xF);
- }
-
- if (ifp->if_flags & IFF_BROADCAST) {
- h = dc_crc_le(sc, (caddr_t)ifp->if_broadcastaddr);
- sp[h >> 4] |= 1 << (h & 0xF);
- }
-
- /* Set our MAC address */
- sp[0] = ((u_int16_t *)sc->arpcom.ac_enaddr)[0];
- sp[1] = ((u_int16_t *)sc->arpcom.ac_enaddr)[1];
- sp[2] = ((u_int16_t *)sc->arpcom.ac_enaddr)[2];
-
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_TX_ON);
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ON);
- ifp->if_flags |= IFF_RUNNING;
- sframe->dc_status = DC_TXSTAT_OWN;
- CSR_WRITE_4(sc, DC_TXSTART, 0xFFFFFFFF);
-
- /*
- * wait some time...
- */
- DELAY(1000);
-
- ifp->if_timer = 5;
-
- return;
-}
-
-static void
-dc_setfilt(sc)
- struct dc_softc *sc;
-{
- if (DC_IS_INTEL(sc) || DC_IS_MACRONIX(sc) || DC_IS_PNIC(sc) ||
- DC_IS_PNICII(sc) || DC_IS_DAVICOM(sc) || DC_IS_CONEXANT(sc))
- dc_setfilt_21143(sc);
-
- if (DC_IS_ASIX(sc))
- dc_setfilt_asix(sc);
-
- if (DC_IS_ADMTEK(sc))
- dc_setfilt_admtek(sc);
-
- if (DC_IS_XIRCOM(sc))
- dc_setfilt_xircom(sc);
-
- return;
-}
-
-/*
- * In order to fiddle with the
- * 'full-duplex' and '100Mbps' bits in the netconfig register, we
- * first have to put the transmit and/or receive logic in the idle state.
- */
-static void
-dc_setcfg(sc, media)
- struct dc_softc *sc;
- int media;
-{
- int i, restart = 0;
- u_int32_t isr;
-
- if (IFM_SUBTYPE(media) == IFM_NONE)
- return;
-
- if (CSR_READ_4(sc, DC_NETCFG) & (DC_NETCFG_TX_ON|DC_NETCFG_RX_ON)) {
- restart = 1;
- DC_CLRBIT(sc, DC_NETCFG, (DC_NETCFG_TX_ON|DC_NETCFG_RX_ON));
-
- for (i = 0; i < DC_TIMEOUT; i++) {
- isr = CSR_READ_4(sc, DC_ISR);
- if (isr & DC_ISR_TX_IDLE &&
- ((isr & DC_ISR_RX_STATE) == DC_RXSTATE_STOPPED ||
- (isr & DC_ISR_RX_STATE) == DC_RXSTATE_WAIT))
- break;
- DELAY(10);
- }
-
- if (i == DC_TIMEOUT)
- printf("dc%d: failed to force tx and "
- "rx to idle state\n", sc->dc_unit);
- }
-
- if (IFM_SUBTYPE(media) == IFM_100_TX) {
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_SPEEDSEL);
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_HEARTBEAT);
- if (sc->dc_pmode == DC_PMODE_MII) {
- int watchdogreg;
-
- if (DC_IS_INTEL(sc)) {
- /* there's a write enable bit here that reads as 1 */
- watchdogreg = CSR_READ_4(sc, DC_WATCHDOG);
- watchdogreg &= ~DC_WDOG_CTLWREN;
- watchdogreg |= DC_WDOG_JABBERDIS;
- CSR_WRITE_4(sc, DC_WATCHDOG, watchdogreg);
- } else {
- DC_SETBIT(sc, DC_WATCHDOG, DC_WDOG_JABBERDIS);
- }
- DC_CLRBIT(sc, DC_NETCFG, (DC_NETCFG_PCS|
- DC_NETCFG_PORTSEL|DC_NETCFG_SCRAMBLER));
- if (sc->dc_type == DC_TYPE_98713)
- DC_SETBIT(sc, DC_NETCFG, (DC_NETCFG_PCS|
- DC_NETCFG_SCRAMBLER));
- if (!DC_IS_DAVICOM(sc))
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
- DC_CLRBIT(sc, DC_10BTCTRL, 0xFFFF);
- if (DC_IS_INTEL(sc))
- dc_apply_fixup(sc, IFM_AUTO);
- } else {
- if (DC_IS_PNIC(sc)) {
- DC_PN_GPIO_SETBIT(sc, DC_PN_GPIO_SPEEDSEL);
- DC_PN_GPIO_SETBIT(sc, DC_PN_GPIO_100TX_LOOP);
- DC_SETBIT(sc, DC_PN_NWAY, DC_PN_NWAY_SPEEDSEL);
- }
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_PCS);
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_SCRAMBLER);
- if (DC_IS_INTEL(sc))
- dc_apply_fixup(sc,
- (media & IFM_GMASK) == IFM_FDX ?
- IFM_100_TX|IFM_FDX : IFM_100_TX);
- }
- }
-
- if (IFM_SUBTYPE(media) == IFM_10_T) {
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_SPEEDSEL);
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_HEARTBEAT);
- if (sc->dc_pmode == DC_PMODE_MII) {
- int watchdogreg;
-
- /* there's a write enable bit here that reads as 1 */
- if (DC_IS_INTEL(sc)) {
- watchdogreg = CSR_READ_4(sc, DC_WATCHDOG);
- watchdogreg &= ~DC_WDOG_CTLWREN;
- watchdogreg |= DC_WDOG_JABBERDIS;
- CSR_WRITE_4(sc, DC_WATCHDOG, watchdogreg);
- } else {
- DC_SETBIT(sc, DC_WATCHDOG, DC_WDOG_JABBERDIS);
- }
- DC_CLRBIT(sc, DC_NETCFG, (DC_NETCFG_PCS|
- DC_NETCFG_PORTSEL|DC_NETCFG_SCRAMBLER));
- if (sc->dc_type == DC_TYPE_98713)
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_PCS);
- if (!DC_IS_DAVICOM(sc))
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
- DC_CLRBIT(sc, DC_10BTCTRL, 0xFFFF);
- if (DC_IS_INTEL(sc))
- dc_apply_fixup(sc, IFM_AUTO);
- } else {
- if (DC_IS_PNIC(sc)) {
- DC_PN_GPIO_CLRBIT(sc, DC_PN_GPIO_SPEEDSEL);
- DC_PN_GPIO_SETBIT(sc, DC_PN_GPIO_100TX_LOOP);
- DC_CLRBIT(sc, DC_PN_NWAY, DC_PN_NWAY_SPEEDSEL);
- }
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_PCS);
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_SCRAMBLER);
- if (DC_IS_INTEL(sc)) {
- DC_CLRBIT(sc, DC_SIARESET, DC_SIA_RESET);
- DC_CLRBIT(sc, DC_10BTCTRL, 0xFFFF);
- if ((media & IFM_GMASK) == IFM_FDX)
- DC_SETBIT(sc, DC_10BTCTRL, 0x7F3D);
- else
- DC_SETBIT(sc, DC_10BTCTRL, 0x7F3F);
- DC_SETBIT(sc, DC_SIARESET, DC_SIA_RESET);
- DC_CLRBIT(sc, DC_10BTCTRL,
- DC_TCTL_AUTONEGENBL);
- dc_apply_fixup(sc,
- (media & IFM_GMASK) == IFM_FDX ?
- IFM_10_T|IFM_FDX : IFM_10_T);
- DELAY(20000);
- }
- }
- }
-
- /*
- * If this is a Davicom DM9102A card with a DM9801 HomePNA
- * PHY and we want HomePNA mode, set the portsel bit to turn
- * on the external MII port.
- */
- if (DC_IS_DAVICOM(sc)) {
- if (IFM_SUBTYPE(media) == IFM_HPNA_1) {
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
- sc->dc_link = 1;
- } else {
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
- }
- }
-
- if ((media & IFM_GMASK) == IFM_FDX) {
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_FULLDUPLEX);
- if (sc->dc_pmode == DC_PMODE_SYM && DC_IS_PNIC(sc))
- DC_SETBIT(sc, DC_PN_NWAY, DC_PN_NWAY_DUPLEX);
- } else {
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_FULLDUPLEX);
- if (sc->dc_pmode == DC_PMODE_SYM && DC_IS_PNIC(sc))
- DC_CLRBIT(sc, DC_PN_NWAY, DC_PN_NWAY_DUPLEX);
- }
-
- if (restart)
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_TX_ON|DC_NETCFG_RX_ON);
-
- return;
-}
-
-static void
-dc_reset(sc)
- struct dc_softc *sc;
-{
- register int i;
-
- DC_SETBIT(sc, DC_BUSCTL, DC_BUSCTL_RESET);
-
- for (i = 0; i < DC_TIMEOUT; i++) {
- DELAY(10);
- if (!(CSR_READ_4(sc, DC_BUSCTL) & DC_BUSCTL_RESET))
- break;
- }
-
- if (DC_IS_ASIX(sc) || DC_IS_ADMTEK(sc) || DC_IS_CONEXANT(sc) ||
- DC_IS_XIRCOM(sc) || DC_IS_INTEL(sc)) {
- DELAY(10000);
- DC_CLRBIT(sc, DC_BUSCTL, DC_BUSCTL_RESET);
- i = 0;
- }
-
- if (i == DC_TIMEOUT)
- printf("dc%d: reset never completed!\n", sc->dc_unit);
-
- /* Wait a little while for the chip to get its brains in order. */
- DELAY(1000);
-
- CSR_WRITE_4(sc, DC_IMR, 0x00000000);
- CSR_WRITE_4(sc, DC_BUSCTL, 0x00000000);
- CSR_WRITE_4(sc, DC_NETCFG, 0x00000000);
-
- /*
- * Bring the SIA out of reset. In some cases, it looks
- * like failing to unreset the SIA soon enough gets it
- * into a state where it will never come out of reset
- * until we reset the whole chip again.
- */
- if (DC_IS_INTEL(sc)) {
- DC_SETBIT(sc, DC_SIARESET, DC_SIA_RESET);
- CSR_WRITE_4(sc, DC_10BTCTRL, 0);
- CSR_WRITE_4(sc, DC_WATCHDOG, 0);
- }
-
- return;
-}
-
-static struct dc_type *
-dc_devtype(dev)
- device_t dev;
-{
- struct dc_type *t;
- u_int32_t rev;
-
- t = dc_devs;
-
- while(t->dc_name != NULL) {
- if ((pci_get_vendor(dev) == t->dc_vid) &&
- (pci_get_device(dev) == t->dc_did)) {
- /* Check the PCI revision */
- rev = pci_read_config(dev, DC_PCI_CFRV, 4) & 0xFF;
- if (t->dc_did == DC_DEVICEID_98713 &&
- rev >= DC_REVISION_98713A)
- t++;
- if (t->dc_did == DC_DEVICEID_98713_CP &&
- rev >= DC_REVISION_98713A)
- t++;
- if (t->dc_did == DC_DEVICEID_987x5 &&
- rev >= DC_REVISION_98715AEC_C)
- t++;
- if (t->dc_did == DC_DEVICEID_987x5 &&
- rev >= DC_REVISION_98725)
- t++;
- if (t->dc_did == DC_DEVICEID_AX88140A &&
- rev >= DC_REVISION_88141)
- t++;
- if (t->dc_did == DC_DEVICEID_82C168 &&
- rev >= DC_REVISION_82C169)
- t++;
- if (t->dc_did == DC_DEVICEID_DM9102 &&
- rev >= DC_REVISION_DM9102A)
- t++;
- return(t);
- }
- t++;
- }
-
- return(NULL);
-}
-
-/*
- * Probe for a 21143 or clone chip. Check the PCI vendor and device
- * IDs against our list and return a device name if we find a match.
- * We do a little bit of extra work to identify the exact type of
- * chip. The MX98713 and MX98713A have the same PCI vendor/device ID,
- * but different revision IDs. The same is true for 98715/98715A
- * chips and the 98725, as well as the ASIX and ADMtek chips. In some
- * cases, the exact chip revision affects driver behavior.
- */
-static int
-dc_probe(dev)
- device_t dev;
-{
- struct dc_type *t;
-
- t = dc_devtype(dev);
-
- if (t != NULL) {
- device_set_desc(dev, t->dc_name);
- return(0);
- }
-
- return(ENXIO);
-}
-
-static void
-dc_acpi(dev)
- device_t dev;
-{
- int unit;
-
- unit = device_get_unit(dev);
-
- if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
- u_int32_t iobase, membase, irq;
-
- /* Save important PCI config data. */
- iobase = pci_read_config(dev, DC_PCI_CFBIO, 4);
- membase = pci_read_config(dev, DC_PCI_CFBMA, 4);
- irq = pci_read_config(dev, DC_PCI_CFIT, 4);
-
- /* Reset the power state. */
- printf("dc%d: chip is in D%d power mode "
- "-- setting to D0\n", unit,
- pci_get_powerstate(dev));
- pci_set_powerstate(dev, PCI_POWERSTATE_D0);
-
- /* Restore PCI config data. */
- pci_write_config(dev, DC_PCI_CFBIO, iobase, 4);
- pci_write_config(dev, DC_PCI_CFBMA, membase, 4);
- pci_write_config(dev, DC_PCI_CFIT, irq, 4);
- }
-
- return;
-}
-
-static void
-dc_apply_fixup(sc, media)
- struct dc_softc *sc;
- int media;
-{
- struct dc_mediainfo *m;
- u_int8_t *p;
- int i;
- u_int32_t reg;
-
- m = sc->dc_mi;
-
- while (m != NULL) {
- if (m->dc_media == media)
- break;
- m = m->dc_next;
- }
-
- if (m == NULL)
- return;
-
- for (i = 0, p = m->dc_reset_ptr; i < m->dc_reset_len; i++, p += 2) {
- reg = (p[0] | (p[1] << 8)) << 16;
- CSR_WRITE_4(sc, DC_WATCHDOG, reg);
- }
-
- for (i = 0, p = m->dc_gp_ptr; i < m->dc_gp_len; i++, p += 2) {
- reg = (p[0] | (p[1] << 8)) << 16;
- CSR_WRITE_4(sc, DC_WATCHDOG, reg);
- }
-
- return;
-}
-
-static void
-dc_decode_leaf_sia(sc, l)
- struct dc_softc *sc;
- struct dc_eblock_sia *l;
-{
- struct dc_mediainfo *m;
-
- m = malloc(sizeof(struct dc_mediainfo), M_DEVBUF, M_NOWAIT);
- bzero(m, sizeof(struct dc_mediainfo));
- if (l->dc_sia_code == DC_SIA_CODE_10BT)
- m->dc_media = IFM_10_T;
-
- if (l->dc_sia_code == DC_SIA_CODE_10BT_FDX)
- m->dc_media = IFM_10_T|IFM_FDX;
-
- if (l->dc_sia_code == DC_SIA_CODE_10B2)
- m->dc_media = IFM_10_2;
-
- if (l->dc_sia_code == DC_SIA_CODE_10B5)
- m->dc_media = IFM_10_5;
-
- m->dc_gp_len = 2;
- m->dc_gp_ptr = (u_int8_t *)&l->dc_sia_gpio_ctl;
-
- m->dc_next = sc->dc_mi;
- sc->dc_mi = m;
-
- sc->dc_pmode = DC_PMODE_SIA;
-
- return;
-}
-
-static void
-dc_decode_leaf_sym(sc, l)
- struct dc_softc *sc;
- struct dc_eblock_sym *l;
-{
- struct dc_mediainfo *m;
-
- m = malloc(sizeof(struct dc_mediainfo), M_DEVBUF, M_NOWAIT);
- bzero(m, sizeof(struct dc_mediainfo));
- if (l->dc_sym_code == DC_SYM_CODE_100BT)
- m->dc_media = IFM_100_TX;
-
- if (l->dc_sym_code == DC_SYM_CODE_100BT_FDX)
- m->dc_media = IFM_100_TX|IFM_FDX;
-
- m->dc_gp_len = 2;
- m->dc_gp_ptr = (u_int8_t *)&l->dc_sym_gpio_ctl;
-
- m->dc_next = sc->dc_mi;
- sc->dc_mi = m;
-
- sc->dc_pmode = DC_PMODE_SYM;
-
- return;
-}
-
-static void
-dc_decode_leaf_mii(sc, l)
- struct dc_softc *sc;
- struct dc_eblock_mii *l;
-{
- u_int8_t *p;
- struct dc_mediainfo *m;
-
- m = malloc(sizeof(struct dc_mediainfo), M_DEVBUF, M_NOWAIT);
- bzero(m, sizeof(struct dc_mediainfo));
- /* We abuse IFM_AUTO to represent MII. */
- m->dc_media = IFM_AUTO;
- m->dc_gp_len = l->dc_gpr_len;
-
- p = (u_int8_t *)l;
- p += sizeof(struct dc_eblock_mii);
- m->dc_gp_ptr = p;
- p += 2 * l->dc_gpr_len;
- m->dc_reset_len = *p;
- p++;
- m->dc_reset_ptr = p;
-
- m->dc_next = sc->dc_mi;
- sc->dc_mi = m;
-
- return;
-}
-
-static void
-dc_read_srom(sc, bits)
- struct dc_softc *sc;
- int bits;
-{
- int size;
-
- size = 2 << bits;
- sc->dc_srom = malloc(size, M_DEVBUF, M_NOWAIT);
- dc_read_eeprom(sc, (caddr_t)sc->dc_srom, 0, (size / 2), 0);
-}
-
-static void
-dc_parse_21143_srom(sc)
- struct dc_softc *sc;
-{
- struct dc_leaf_hdr *lhdr;
- struct dc_eblock_hdr *hdr;
- int i, loff;
- char *ptr;
- int have_mii;
-
- have_mii = 0;
- loff = sc->dc_srom[27];
- lhdr = (struct dc_leaf_hdr *)&(sc->dc_srom[loff]);
-
- ptr = (char *)lhdr;
- ptr += sizeof(struct dc_leaf_hdr) - 1;
- /*
- * Look if we got a MII media block.
- */
- for (i = 0; i < lhdr->dc_mcnt; i++) {
- hdr = (struct dc_eblock_hdr *)ptr;
- if (hdr->dc_type == DC_EBLOCK_MII)
- have_mii++;
-
- ptr += (hdr->dc_len & 0x7F);
- ptr++;
- }
-
- /*
- * Do the same thing again. Only use SIA and SYM media
- * blocks if no MII media block is available.
- */
- ptr = (char *)lhdr;
- ptr += sizeof(struct dc_leaf_hdr) - 1;
- for (i = 0; i < lhdr->dc_mcnt; i++) {
- hdr = (struct dc_eblock_hdr *)ptr;
- switch(hdr->dc_type) {
- case DC_EBLOCK_MII:
- dc_decode_leaf_mii(sc, (struct dc_eblock_mii *)hdr);
- break;
- case DC_EBLOCK_SIA:
- if (! have_mii)
- dc_decode_leaf_sia(sc,
- (struct dc_eblock_sia *)hdr);
- break;
- case DC_EBLOCK_SYM:
- if (! have_mii)
- dc_decode_leaf_sym(sc,
- (struct dc_eblock_sym *)hdr);
- break;
- default:
- /* Don't care. Yet. */
- break;
- }
- ptr += (hdr->dc_len & 0x7F);
- ptr++;
- }
-
- return;
-}
-
-/*
- * Attach the interface. Allocate softc structures, do ifmedia
- * setup and ethernet/BPF attach.
- */
-static int
-dc_attach(dev)
- device_t dev;
-{
- int tmp = 0;
- u_char eaddr[ETHER_ADDR_LEN];
- u_int32_t command;
- struct dc_softc *sc;
- struct ifnet *ifp;
- u_int32_t revision;
- int unit, error = 0, rid, mac_offset;
- u_int8_t *mac;
-
- sc = device_get_softc(dev);
- unit = device_get_unit(dev);
-
- mtx_init(&sc->dc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
- MTX_DEF | MTX_RECURSE);
-
- /*
- * Handle power management nonsense.
- */
- dc_acpi(dev);
-
- /*
- * Map control/status registers.
- */
- pci_enable_busmaster(dev);
-
- rid = DC_RID;
- sc->dc_res = bus_alloc_resource(dev, DC_RES, &rid,
- 0, ~0, 1, RF_ACTIVE);
-
- if (sc->dc_res == NULL) {
- printf("dc%d: couldn't map ports/memory\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- sc->dc_btag = rman_get_bustag(sc->dc_res);
- sc->dc_bhandle = rman_get_bushandle(sc->dc_res);
-
- /* Allocate interrupt */
- rid = 0;
- sc->dc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE | RF_ACTIVE);
-
- if (sc->dc_irq == NULL) {
- printf("dc%d: couldn't map interrupt\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- /* Need this info to decide on a chip type. */
- sc->dc_info = dc_devtype(dev);
- revision = pci_read_config(dev, DC_PCI_CFRV, 4) & 0x000000FF;
-
- /* Get the eeprom width, but PNIC and XIRCOM have diff eeprom */
- if (sc->dc_info->dc_did != DC_DEVICEID_82C168 &&
- sc->dc_info->dc_did != DC_DEVICEID_X3201)
- dc_eeprom_width(sc);
-
- switch(sc->dc_info->dc_did) {
- case DC_DEVICEID_21143:
- sc->dc_type = DC_TYPE_21143;
- sc->dc_flags |= DC_TX_POLL|DC_TX_USE_TX_INTR;
- sc->dc_flags |= DC_REDUCED_MII_POLL;
- /* Save EEPROM contents so we can parse them later. */
- dc_read_srom(sc, sc->dc_romwidth);
- break;
- case DC_DEVICEID_DM9009:
- case DC_DEVICEID_DM9100:
- case DC_DEVICEID_DM9102:
- sc->dc_type = DC_TYPE_DM9102;
- sc->dc_flags |= DC_TX_COALESCE|DC_TX_INTR_ALWAYS;
- sc->dc_flags |= DC_REDUCED_MII_POLL|DC_TX_STORENFWD;
- sc->dc_pmode = DC_PMODE_MII;
- /* Increase the latency timer value. */
- command = pci_read_config(dev, DC_PCI_CFLT, 4);
- command &= 0xFFFF00FF;
- command |= 0x00008000;
- pci_write_config(dev, DC_PCI_CFLT, command, 4);
- break;
- case DC_DEVICEID_AL981:
- sc->dc_type = DC_TYPE_AL981;
- sc->dc_flags |= DC_TX_USE_TX_INTR;
- sc->dc_flags |= DC_TX_ADMTEK_WAR;
- sc->dc_pmode = DC_PMODE_MII;
- dc_read_srom(sc, sc->dc_romwidth);
- break;
- case DC_DEVICEID_AN985:
- case DC_DEVICEID_FE2500:
- case DC_DEVICEID_EN2242:
- case DC_DEVICEID_HAWKING_PN672TX:
- case DC_DEVICEID_3CSOHOB:
- sc->dc_type = DC_TYPE_AN985;
- sc->dc_flags |= DC_64BIT_HASH;
- sc->dc_flags |= DC_TX_USE_TX_INTR;
- sc->dc_flags |= DC_TX_ADMTEK_WAR;
- sc->dc_pmode = DC_PMODE_MII;
- dc_read_srom(sc, sc->dc_romwidth);
- break;
- case DC_DEVICEID_98713:
- case DC_DEVICEID_98713_CP:
- if (revision < DC_REVISION_98713A) {
- sc->dc_type = DC_TYPE_98713;
- }
- if (revision >= DC_REVISION_98713A) {
- sc->dc_type = DC_TYPE_98713A;
- sc->dc_flags |= DC_21143_NWAY;
- }
- sc->dc_flags |= DC_REDUCED_MII_POLL;
- sc->dc_flags |= DC_TX_POLL|DC_TX_USE_TX_INTR;
- break;
- case DC_DEVICEID_987x5:
- case DC_DEVICEID_EN1217:
- /*
- * Macronix MX98715AEC-C/D/E parts have only a
- * 128-bit hash table. We need to deal with these
- * in the same manner as the PNIC II so that we
- * get the right number of bits out of the
- * CRC routine.
- */
- if (revision >= DC_REVISION_98715AEC_C &&
- revision < DC_REVISION_98725)
- sc->dc_flags |= DC_128BIT_HASH;
- sc->dc_type = DC_TYPE_987x5;
- sc->dc_flags |= DC_TX_POLL|DC_TX_USE_TX_INTR;
- sc->dc_flags |= DC_REDUCED_MII_POLL|DC_21143_NWAY;
- break;
- case DC_DEVICEID_98727:
- sc->dc_type = DC_TYPE_987x5;
- sc->dc_flags |= DC_TX_POLL|DC_TX_USE_TX_INTR;
- sc->dc_flags |= DC_REDUCED_MII_POLL|DC_21143_NWAY;
- break;
- case DC_DEVICEID_82C115:
- sc->dc_type = DC_TYPE_PNICII;
- sc->dc_flags |= DC_TX_POLL|DC_TX_USE_TX_INTR|DC_128BIT_HASH;
- sc->dc_flags |= DC_REDUCED_MII_POLL|DC_21143_NWAY;
- break;
- case DC_DEVICEID_82C168:
- sc->dc_type = DC_TYPE_PNIC;
- sc->dc_flags |= DC_TX_STORENFWD|DC_TX_INTR_ALWAYS;
- sc->dc_flags |= DC_PNIC_RX_BUG_WAR;
- sc->dc_pnic_rx_buf = malloc(DC_RXLEN * 5, M_DEVBUF, M_NOWAIT);
- if (revision < DC_REVISION_82C169)
- sc->dc_pmode = DC_PMODE_SYM;
- break;
- case DC_DEVICEID_AX88140A:
- sc->dc_type = DC_TYPE_ASIX;
- sc->dc_flags |= DC_TX_USE_TX_INTR|DC_TX_INTR_FIRSTFRAG;
- sc->dc_flags |= DC_REDUCED_MII_POLL;
- sc->dc_pmode = DC_PMODE_MII;
- break;
- case DC_DEVICEID_X3201:
- sc->dc_type = DC_TYPE_XIRCOM;
- sc->dc_flags |= DC_TX_INTR_ALWAYS | DC_TX_COALESCE |
- DC_TX_ALIGN;
- /*
- * We don't actually need to coalesce, but we're doing
- * it to obtain a double word aligned buffer.
- * The DC_TX_COALESCE flag is required.
- */
- sc->dc_pmode = DC_PMODE_MII;
- break;
- case DC_DEVICEID_RS7112:
- sc->dc_type = DC_TYPE_CONEXANT;
- sc->dc_flags |= DC_TX_INTR_ALWAYS;
- sc->dc_flags |= DC_REDUCED_MII_POLL;
- sc->dc_pmode = DC_PMODE_MII;
- dc_read_srom(sc, sc->dc_romwidth);
- break;
- default:
- printf("dc%d: unknown device: %x\n", sc->dc_unit,
- sc->dc_info->dc_did);
- break;
- }
-
- /* Save the cache line size. */
- if (DC_IS_DAVICOM(sc))
- sc->dc_cachesize = 0;
- else
- sc->dc_cachesize = pci_read_config(dev,
- DC_PCI_CFLT, 4) & 0xFF;
-
- /* Reset the adapter. */
- dc_reset(sc);
-
- /* Take 21143 out of snooze mode */
- if (DC_IS_INTEL(sc) || DC_IS_XIRCOM(sc)) {
- command = pci_read_config(dev, DC_PCI_CFDD, 4);
- command &= ~(DC_CFDD_SNOOZE_MODE|DC_CFDD_SLEEP_MODE);
- pci_write_config(dev, DC_PCI_CFDD, command, 4);
- }
-
- /*
- * Try to learn something about the supported media.
- * We know that ASIX and ADMtek and Davicom devices
- * will *always* be using MII media, so that's a no-brainer.
- * The tricky ones are the Macronix/PNIC II and the
- * Intel 21143.
- */
- if (DC_IS_INTEL(sc))
- dc_parse_21143_srom(sc);
- else if (DC_IS_MACRONIX(sc) || DC_IS_PNICII(sc)) {
- if (sc->dc_type == DC_TYPE_98713)
- sc->dc_pmode = DC_PMODE_MII;
- else
- sc->dc_pmode = DC_PMODE_SYM;
- } else if (!sc->dc_pmode)
- sc->dc_pmode = DC_PMODE_MII;
-
- /*
- * Get station address from the EEPROM.
- */
- switch(sc->dc_type) {
- case DC_TYPE_98713:
- case DC_TYPE_98713A:
- case DC_TYPE_987x5:
- case DC_TYPE_PNICII:
- dc_read_eeprom(sc, (caddr_t)&mac_offset,
- (DC_EE_NODEADDR_OFFSET / 2), 1, 0);
- dc_read_eeprom(sc, (caddr_t)&eaddr, (mac_offset / 2), 3, 0);
- break;
- case DC_TYPE_PNIC:
- dc_read_eeprom(sc, (caddr_t)&eaddr, 0, 3, 1);
- break;
- case DC_TYPE_DM9102:
- case DC_TYPE_21143:
- case DC_TYPE_ASIX:
- dc_read_eeprom(sc, (caddr_t)&eaddr, DC_EE_NODEADDR, 3, 0);
- break;
- case DC_TYPE_AL981:
- case DC_TYPE_AN985:
- bcopy(&sc->dc_srom[DC_AL_EE_NODEADDR], (caddr_t)&eaddr,
- ETHER_ADDR_LEN);
- dc_read_eeprom(sc, (caddr_t)&eaddr, DC_AL_EE_NODEADDR, 3, 0);
- break;
- case DC_TYPE_CONEXANT:
- bcopy(sc->dc_srom + DC_CONEXANT_EE_NODEADDR, &eaddr, 6);
- break;
- case DC_TYPE_XIRCOM:
- /* The MAC comes from the CIS */
- mac = pci_get_ether(dev);
- if (!mac) {
- device_printf(dev, "No station address in CIS!\n");
- error = ENXIO;
- goto fail;
- }
- bcopy(mac, eaddr, ETHER_ADDR_LEN);
- break;
- default:
- dc_read_eeprom(sc, (caddr_t)&eaddr, DC_EE_NODEADDR, 3, 0);
- break;
- }
-
- /*
- * A 21143 or clone chip was detected. Inform the world.
- */
- printf("dc%d: Ethernet address: %6D\n", unit, eaddr, ":");
-
- sc->dc_unit = unit;
- bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
-
- sc->dc_ldata = contigmalloc(sizeof(struct dc_list_data), M_DEVBUF,
- M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
-
- if (sc->dc_ldata == NULL) {
- printf("dc%d: no memory for list buffers!\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- bzero(sc->dc_ldata, sizeof(struct dc_list_data));
-
- ifp = &sc->arpcom.ac_if;
- ifp->if_softc = sc;
- ifp->if_unit = unit;
- ifp->if_name = "dc";
- /* XXX: bleah, MTU gets overwritten in ether_ifattach() */
- ifp->if_mtu = ETHERMTU;
- ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
- ifp->if_ioctl = dc_ioctl;
- ifp->if_output = ether_output;
- ifp->if_start = dc_start;
- ifp->if_watchdog = dc_watchdog;
- ifp->if_init = dc_init;
- ifp->if_baudrate = 10000000;
- ifp->if_snd.ifq_maxlen = DC_TX_LIST_CNT - 1;
-
- /*
- * Do MII setup. If this is a 21143, check for a PHY on the
- * MII bus after applying any necessary fixups to twiddle the
- * GPIO bits. If we don't end up finding a PHY, restore the
- * old selection (SIA only or SIA/SYM) and attach the dcphy
- * driver instead.
- */
- if (DC_IS_INTEL(sc)) {
- dc_apply_fixup(sc, IFM_AUTO);
- tmp = sc->dc_pmode;
- sc->dc_pmode = DC_PMODE_MII;
- }
-
- error = mii_phy_probe(dev, &sc->dc_miibus,
- dc_ifmedia_upd, dc_ifmedia_sts);
-
- if (error && DC_IS_INTEL(sc)) {
- sc->dc_pmode = tmp;
- if (sc->dc_pmode != DC_PMODE_SIA)
- sc->dc_pmode = DC_PMODE_SYM;
- sc->dc_flags |= DC_21143_NWAY;
- mii_phy_probe(dev, &sc->dc_miibus,
- dc_ifmedia_upd, dc_ifmedia_sts);
- /*
- * For non-MII cards, we need to have the 21143
- * drive the LEDs. Except there are some systems
- * like the NEC VersaPro NoteBook PC which have no
- * LEDs, and twiddling these bits has adverse effects
- * on them. (I.e. you suddenly can't get a link.)
- */
- if (pci_read_config(dev, DC_PCI_CSID, 4) != 0x80281033)
- sc->dc_flags |= DC_TULIP_LEDS;
- error = 0;
- }
-
- if (error) {
- printf("dc%d: MII without any PHY!\n", sc->dc_unit);
- goto fail;
- }
-
- if (DC_IS_XIRCOM(sc)) {
- /*
- * setup General Purpose Port mode and data so the tulip
- * can talk to the MII.
- */
- CSR_WRITE_4(sc, DC_SIAGP, DC_SIAGP_WRITE_EN | DC_SIAGP_INT1_EN |
- DC_SIAGP_MD_GP2_OUTPUT | DC_SIAGP_MD_GP0_OUTPUT);
- DELAY(10);
- CSR_WRITE_4(sc, DC_SIAGP, DC_SIAGP_INT1_EN |
- DC_SIAGP_MD_GP2_OUTPUT | DC_SIAGP_MD_GP0_OUTPUT);
- DELAY(10);
- }
-
- if (DC_IS_ADMTEK(sc)) {
- /*
- * Set automatic TX underrun recovery for the ADMtek chips
- */
- DC_SETBIT(sc, DC_AL_CR, DC_AL_CR_ATUR);
- }
-
- /*
- * Tell the upper layer(s) we support long frames.
- */
- ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
- ifp->if_capabilities |= IFCAP_VLAN_MTU;
-
- callout_init(&sc->dc_stat_ch, IS_MPSAFE);
-
-#ifdef SRM_MEDIA
- sc->dc_srm_media = 0;
-
- /* Remember the SRM console media setting */
- if (DC_IS_INTEL(sc)) {
- command = pci_read_config(dev, DC_PCI_CFDD, 4);
- command &= ~(DC_CFDD_SNOOZE_MODE|DC_CFDD_SLEEP_MODE);
- switch ((command >> 8) & 0xff) {
- case 3:
- sc->dc_srm_media = IFM_10_T;
- break;
- case 4:
- sc->dc_srm_media = IFM_10_T | IFM_FDX;
- break;
- case 5:
- sc->dc_srm_media = IFM_100_TX;
- break;
- case 6:
- sc->dc_srm_media = IFM_100_TX | IFM_FDX;
- break;
- }
- if (sc->dc_srm_media)
- sc->dc_srm_media |= IFM_ACTIVE | IFM_ETHER;
- }
-#endif
-
- /*
- * Call MI attach routine.
- */
- ether_ifattach(ifp, eaddr);
-
- /* Hook interrupt last to avoid having to lock softc */
- error = bus_setup_intr(dev, sc->dc_irq, INTR_TYPE_NET |
- (IS_MPSAFE ? INTR_MPSAFE : 0),
- dc_intr, sc, &sc->dc_intrhand);
-
- if (error) {
- printf("dc%d: couldn't set up irq\n", unit);
- ether_ifdetach(ifp);
- goto fail;
- }
-
-fail:
- if (error)
- dc_detach(dev);
- return (error);
-}
-
-/*
- * Shutdown hardware and free up resources. This can be called any
- * time after the mutex has been initialized. It is called in both
- * the error case in attach and the normal detach case so it needs
- * to be careful about only freeing resources that have actually been
- * allocated.
- */
-static int
-dc_detach(dev)
- device_t dev;
-{
- struct dc_softc *sc;
- struct ifnet *ifp;
- struct dc_mediainfo *m;
-
- sc = device_get_softc(dev);
- KASSERT(mtx_initialized(&sc->dc_mtx), ("dc mutex not initialized"));
- DC_LOCK(sc);
-
- ifp = &sc->arpcom.ac_if;
-
- /* These should only be active if attach succeeded */
- if (device_is_attached(dev)) {
- dc_stop(sc);
- ether_ifdetach(ifp);
- }
- if (sc->dc_miibus)
- device_delete_child(dev, sc->dc_miibus);
- bus_generic_detach(dev);
-
- if (sc->dc_intrhand)
- bus_teardown_intr(dev, sc->dc_irq, sc->dc_intrhand);
- if (sc->dc_irq)
- bus_release_resource(dev, SYS_RES_IRQ, 0, sc->dc_irq);
- if (sc->dc_res)
- bus_release_resource(dev, DC_RES, DC_RID, sc->dc_res);
-
- if (sc->dc_ldata)
- contigfree(sc->dc_ldata, sizeof(struct dc_list_data), M_DEVBUF);
- free(sc->dc_pnic_rx_buf, M_DEVBUF);
-
- while(sc->dc_mi != NULL) {
- m = sc->dc_mi->dc_next;
- free(sc->dc_mi, M_DEVBUF);
- sc->dc_mi = m;
- }
- free(sc->dc_srom, M_DEVBUF);
-
- DC_UNLOCK(sc);
- mtx_destroy(&sc->dc_mtx);
-
- return(0);
-}
-
-/*
- * Initialize the transmit descriptors.
- */
-static int
-dc_list_tx_init(sc)
- struct dc_softc *sc;
-{
- struct dc_chain_data *cd;
- struct dc_list_data *ld;
- int i, nexti;
-
- cd = &sc->dc_cdata;
- ld = sc->dc_ldata;
- for (i = 0; i < DC_TX_LIST_CNT; i++) {
- nexti = (i == (DC_TX_LIST_CNT - 1)) ? 0 : i+1;
- ld->dc_tx_list[i].dc_next = vtophys(&ld->dc_tx_list[nexti]);
- cd->dc_tx_chain[i] = NULL;
- ld->dc_tx_list[i].dc_data = 0;
- ld->dc_tx_list[i].dc_ctl = 0;
- }
-
- cd->dc_tx_prod = cd->dc_tx_cons = cd->dc_tx_cnt = 0;
-
- return(0);
-}
-
-
-/*
- * Initialize the RX descriptors and allocate mbufs for them. Note that
- * we arrange the descriptors in a closed ring, so that the last descriptor
- * points back to the first.
- */
-static int
-dc_list_rx_init(sc)
- struct dc_softc *sc;
-{
- struct dc_chain_data *cd;
- struct dc_list_data *ld;
- int i, nexti;
-
- cd = &sc->dc_cdata;
- ld = sc->dc_ldata;
-
- for (i = 0; i < DC_RX_LIST_CNT; i++) {
- if (dc_newbuf(sc, i, NULL) == ENOBUFS)
- return(ENOBUFS);
- nexti = (i == (DC_RX_LIST_CNT - 1)) ? 0 : i+1;
- ld->dc_rx_list[i].dc_next = vtophys(&ld->dc_rx_list[nexti]);
- }
-
- cd->dc_rx_prod = 0;
-
- return(0);
-}
-
-/*
- * Initialize an RX descriptor and attach an MBUF cluster.
- */
-static int
-dc_newbuf(sc, i, m)
- struct dc_softc *sc;
- int i;
- struct mbuf *m;
-{
- struct mbuf *m_new = NULL;
- struct dc_desc *c;
-
- c = &sc->dc_ldata->dc_rx_list[i];
-
- if (m == NULL) {
- MGETHDR(m_new, M_DONTWAIT, MT_DATA);
- if (m_new == NULL)
- return(ENOBUFS);
-
- MCLGET(m_new, M_DONTWAIT);
- if (!(m_new->m_flags & M_EXT)) {
- m_freem(m_new);
- return(ENOBUFS);
- }
- m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
- } else {
- m_new = m;
- m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
- m_new->m_data = m_new->m_ext.ext_buf;
- }
-
- m_adj(m_new, sizeof(u_int64_t));
-
- /*
- * If this is a PNIC chip, zero the buffer. This is part
- * of the workaround for the receive bug in the 82c168 and
- * 82c169 chips.
- */
- if (sc->dc_flags & DC_PNIC_RX_BUG_WAR)
- bzero((char *)mtod(m_new, char *), m_new->m_len);
-
- sc->dc_cdata.dc_rx_chain[i] = m_new;
- c->dc_data = vtophys(mtod(m_new, caddr_t));
- c->dc_ctl = DC_RXCTL_RLINK | DC_RXLEN;
- c->dc_status = DC_RXSTAT_OWN;
-
- return(0);
-}
-
-/*
- * Grrrrr.
- * The PNIC chip has a terrible bug in it that manifests itself during
- * periods of heavy activity. The exact mode of failure if difficult to
- * pinpoint: sometimes it only happens in promiscuous mode, sometimes it
- * will happen on slow machines. The bug is that sometimes instead of
- * uploading one complete frame during reception, it uploads what looks
- * like the entire contents of its FIFO memory. The frame we want is at
- * the end of the whole mess, but we never know exactly how much data has
- * been uploaded, so salvaging the frame is hard.
- *
- * There is only one way to do it reliably, and it's disgusting.
- * Here's what we know:
- *
- * - We know there will always be somewhere between one and three extra
- * descriptors uploaded.
- *
- * - We know the desired received frame will always be at the end of the
- * total data upload.
- *
- * - We know the size of the desired received frame because it will be
- * provided in the length field of the status word in the last descriptor.
- *
- * Here's what we do:
- *
- * - When we allocate buffers for the receive ring, we bzero() them.
- * This means that we know that the buffer contents should be all
- * zeros, except for data uploaded by the chip.
- *
- * - We also force the PNIC chip to upload frames that include the
- * ethernet CRC at the end.
- *
- * - We gather all of the bogus frame data into a single buffer.
- *
- * - We then position a pointer at the end of this buffer and scan
- * backwards until we encounter the first non-zero byte of data.
- * This is the end of the received frame. We know we will encounter
- * some data at the end of the frame because the CRC will always be
- * there, so even if the sender transmits a packet of all zeros,
- * we won't be fooled.
- *
- * - We know the size of the actual received frame, so we subtract
- * that value from the current pointer location. This brings us
- * to the start of the actual received packet.
- *
- * - We copy this into an mbuf and pass it on, along with the actual
- * frame length.
- *
- * The performance hit is tremendous, but it beats dropping frames all
- * the time.
- */
-
-#define DC_WHOLEFRAME (DC_RXSTAT_FIRSTFRAG|DC_RXSTAT_LASTFRAG)
-static void
-dc_pnic_rx_bug_war(sc, idx)
- struct dc_softc *sc;
- int idx;
-{
- struct dc_desc *cur_rx;
- struct dc_desc *c = NULL;
- struct mbuf *m = NULL;
- unsigned char *ptr;
- int i, total_len;
- u_int32_t rxstat = 0;
-
- i = sc->dc_pnic_rx_bug_save;
- cur_rx = &sc->dc_ldata->dc_rx_list[idx];
- ptr = sc->dc_pnic_rx_buf;
- bzero(ptr, sizeof(DC_RXLEN * 5));
-
- /* Copy all the bytes from the bogus buffers. */
- while (1) {
- c = &sc->dc_ldata->dc_rx_list[i];
- rxstat = c->dc_status;
- m = sc->dc_cdata.dc_rx_chain[i];
- bcopy(mtod(m, char *), ptr, DC_RXLEN);
- ptr += DC_RXLEN;
- /* If this is the last buffer, break out. */
- if (i == idx || rxstat & DC_RXSTAT_LASTFRAG)
- break;
- dc_newbuf(sc, i, m);
- DC_INC(i, DC_RX_LIST_CNT);
- }
-
- /* Find the length of the actual receive frame. */
- total_len = DC_RXBYTES(rxstat);
-
- /* Scan backwards until we hit a non-zero byte. */
- while(*ptr == 0x00)
- ptr--;
-
- /* Round off. */
- if ((uintptr_t)(ptr) & 0x3)
- ptr -= 1;
-
- /* Now find the start of the frame. */
- ptr -= total_len;
- if (ptr < sc->dc_pnic_rx_buf)
- ptr = sc->dc_pnic_rx_buf;
-
- /*
- * Now copy the salvaged frame to the last mbuf and fake up
- * the status word to make it look like a successful
- * frame reception.
- */
- dc_newbuf(sc, i, m);
- bcopy(ptr, mtod(m, char *), total_len);
- cur_rx->dc_status = rxstat | DC_RXSTAT_FIRSTFRAG;
-
- return;
-}
-
-/*
- * This routine searches the RX ring for dirty descriptors in the
- * event that the rxeof routine falls out of sync with the chip's
- * current descriptor pointer. This may happen sometimes as a result
- * of a "no RX buffer available" condition that happens when the chip
- * consumes all of the RX buffers before the driver has a chance to
- * process the RX ring. This routine may need to be called more than
- * once to bring the driver back in sync with the chip, however we
- * should still be getting RX DONE interrupts to drive the search
- * for new packets in the RX ring, so we should catch up eventually.
- */
-static int
-dc_rx_resync(sc)
- struct dc_softc *sc;
-{
- int i, pos;
- struct dc_desc *cur_rx;
-
- pos = sc->dc_cdata.dc_rx_prod;
-
- for (i = 0; i < DC_RX_LIST_CNT; i++) {
- cur_rx = &sc->dc_ldata->dc_rx_list[pos];
- if (!(cur_rx->dc_status & DC_RXSTAT_OWN))
- break;
- DC_INC(pos, DC_RX_LIST_CNT);
- }
-
- /* If the ring really is empty, then just return. */
- if (i == DC_RX_LIST_CNT)
- return(0);
-
- /* We've fallen behing the chip: catch it. */
- sc->dc_cdata.dc_rx_prod = pos;
-
- return(EAGAIN);
-}
-
-/*
- * A frame has been uploaded: pass the resulting mbuf chain up to
- * the higher level protocols.
- */
-static void
-dc_rxeof(sc)
- struct dc_softc *sc;
-{
- struct mbuf *m;
- struct ifnet *ifp;
- struct dc_desc *cur_rx;
- int i, total_len = 0;
- u_int32_t rxstat;
-
- ifp = &sc->arpcom.ac_if;
- i = sc->dc_cdata.dc_rx_prod;
-
- while(!(sc->dc_ldata->dc_rx_list[i].dc_status & DC_RXSTAT_OWN)) {
-
-#ifdef DEVICE_POLLING
- if (ifp->if_flags & IFF_POLLING) {
- if (sc->rxcycles <= 0)
- break;
- sc->rxcycles--;
- }
-#endif /* DEVICE_POLLING */
- cur_rx = &sc->dc_ldata->dc_rx_list[i];
- rxstat = cur_rx->dc_status;
- m = sc->dc_cdata.dc_rx_chain[i];
- total_len = DC_RXBYTES(rxstat);
-
- if (sc->dc_flags & DC_PNIC_RX_BUG_WAR) {
- if ((rxstat & DC_WHOLEFRAME) != DC_WHOLEFRAME) {
- if (rxstat & DC_RXSTAT_FIRSTFRAG)
- sc->dc_pnic_rx_bug_save = i;
- if ((rxstat & DC_RXSTAT_LASTFRAG) == 0) {
- DC_INC(i, DC_RX_LIST_CNT);
- continue;
- }
- dc_pnic_rx_bug_war(sc, i);
- rxstat = cur_rx->dc_status;
- total_len = DC_RXBYTES(rxstat);
- }
- }
-
- sc->dc_cdata.dc_rx_chain[i] = NULL;
-
- /*
- * If an error occurs, update stats, clear the
- * status word and leave the mbuf cluster in place:
- * it should simply get re-used next time this descriptor
- * comes up in the ring. However, don't report long
- * frames as errors since they could be vlans
- */
- if ((rxstat & DC_RXSTAT_RXERR)){
- if (!(rxstat & DC_RXSTAT_GIANT) ||
- (rxstat & (DC_RXSTAT_CRCERR | DC_RXSTAT_DRIBBLE |
- DC_RXSTAT_MIIERE | DC_RXSTAT_COLLSEEN |
- DC_RXSTAT_RUNT | DC_RXSTAT_DE))) {
- ifp->if_ierrors++;
- if (rxstat & DC_RXSTAT_COLLSEEN)
- ifp->if_collisions++;
- dc_newbuf(sc, i, m);
- if (rxstat & DC_RXSTAT_CRCERR) {
- DC_INC(i, DC_RX_LIST_CNT);
- continue;
- } else {
- dc_init(sc);
- return;
- }
- }
- }
-
- /* No errors; receive the packet. */
- total_len -= ETHER_CRC_LEN;
-#ifdef __i386__
- /*
- * On the x86 we do not have alignment problems, so try to
- * allocate a new buffer for the receive ring, and pass up
- * the one where the packet is already, saving the expensive
- * copy done in m_devget().
- * If we are on an architecture with alignment problems, or
- * if the allocation fails, then use m_devget and leave the
- * existing buffer in the receive ring.
- */
- if (dc_quick && dc_newbuf(sc, i, NULL) == 0) {
- m->m_pkthdr.rcvif = ifp;
- m->m_pkthdr.len = m->m_len = total_len;
- DC_INC(i, DC_RX_LIST_CNT);
- } else
-#endif
- {
- struct mbuf *m0;
-
- m0 = m_devget(mtod(m, char *), total_len,
- ETHER_ALIGN, ifp, NULL);
- dc_newbuf(sc, i, m);
- DC_INC(i, DC_RX_LIST_CNT);
- if (m0 == NULL) {
- ifp->if_ierrors++;
- continue;
- }
- m = m0;
- }
-
- ifp->if_ipackets++;
- (*ifp->if_input)(ifp, m);
- }
-
- sc->dc_cdata.dc_rx_prod = i;
-}
-
-/*
- * A frame was downloaded to the chip. It's safe for us to clean up
- * the list buffers.
- */
-
-static void
-dc_txeof(sc)
- struct dc_softc *sc;
-{
- struct dc_desc *cur_tx = NULL;
- struct ifnet *ifp;
- int idx;
-
- ifp = &sc->arpcom.ac_if;
-
- /*
- * Go through our tx list and free mbufs for those
- * frames that have been transmitted.
- */
- idx = sc->dc_cdata.dc_tx_cons;
- while(idx != sc->dc_cdata.dc_tx_prod) {
- u_int32_t txstat;
-
- cur_tx = &sc->dc_ldata->dc_tx_list[idx];
- txstat = cur_tx->dc_status;
-
- if (txstat & DC_TXSTAT_OWN)
- break;
-
- if (!(cur_tx->dc_ctl & DC_TXCTL_LASTFRAG) ||
- cur_tx->dc_ctl & DC_TXCTL_SETUP) {
- if (cur_tx->dc_ctl & DC_TXCTL_SETUP) {
- /*
- * Yes, the PNIC is so brain damaged
- * that it will sometimes generate a TX
- * underrun error while DMAing the RX
- * filter setup frame. If we detect this,
- * we have to send the setup frame again,
- * or else the filter won't be programmed
- * correctly.
- */
- if (DC_IS_PNIC(sc)) {
- if (txstat & DC_TXSTAT_ERRSUM)
- dc_setfilt(sc);
- }
- sc->dc_cdata.dc_tx_chain[idx] = NULL;
- }
- sc->dc_cdata.dc_tx_cnt--;
- DC_INC(idx, DC_TX_LIST_CNT);
- continue;
- }
-
- if (DC_IS_XIRCOM(sc) || DC_IS_CONEXANT(sc)) {
- /*
- * XXX: Why does my Xircom taunt me so?
- * For some reason it likes setting the CARRLOST flag
- * even when the carrier is there. wtf?!?
- * Who knows, but Conexant chips have the
- * same problem. Maybe they took lessons
- * from Xircom.
- */
- if (/*sc->dc_type == DC_TYPE_21143 &&*/
- sc->dc_pmode == DC_PMODE_MII &&
- ((txstat & 0xFFFF) & ~(DC_TXSTAT_ERRSUM|
- DC_TXSTAT_NOCARRIER)))
- txstat &= ~DC_TXSTAT_ERRSUM;
- } else {
- if (/*sc->dc_type == DC_TYPE_21143 &&*/
- sc->dc_pmode == DC_PMODE_MII &&
- ((txstat & 0xFFFF) & ~(DC_TXSTAT_ERRSUM|
- DC_TXSTAT_NOCARRIER|DC_TXSTAT_CARRLOST)))
- txstat &= ~DC_TXSTAT_ERRSUM;
- }
-
- if (txstat & DC_TXSTAT_ERRSUM) {
- ifp->if_oerrors++;
- if (txstat & DC_TXSTAT_EXCESSCOLL)
- ifp->if_collisions++;
- if (txstat & DC_TXSTAT_LATECOLL)
- ifp->if_collisions++;
- if (!(txstat & DC_TXSTAT_UNDERRUN)) {
- dc_init(sc);
- return;
- }
- }
-
- ifp->if_collisions += (txstat & DC_TXSTAT_COLLCNT) >> 3;
-
- ifp->if_opackets++;
- if (sc->dc_cdata.dc_tx_chain[idx] != NULL) {
- m_freem(sc->dc_cdata.dc_tx_chain[idx]);
- sc->dc_cdata.dc_tx_chain[idx] = NULL;
- }
-
- sc->dc_cdata.dc_tx_cnt--;
- DC_INC(idx, DC_TX_LIST_CNT);
- }
-
- if (idx != sc->dc_cdata.dc_tx_cons) {
- /* some buffers have been freed */
- sc->dc_cdata.dc_tx_cons = idx;
- ifp->if_flags &= ~IFF_OACTIVE;
- }
- ifp->if_timer = (sc->dc_cdata.dc_tx_cnt == 0) ? 0 : 5;
-
- return;
-}
-
-static void
-dc_tick(xsc)
- void *xsc;
-{
- struct dc_softc *sc;
- struct mii_data *mii;
- struct ifnet *ifp;
- u_int32_t r;
-
- sc = xsc;
- DC_LOCK(sc);
- ifp = &sc->arpcom.ac_if;
- mii = device_get_softc(sc->dc_miibus);
-
- if (sc->dc_flags & DC_REDUCED_MII_POLL) {
- if (sc->dc_flags & DC_21143_NWAY) {
- r = CSR_READ_4(sc, DC_10BTSTAT);
- if (IFM_SUBTYPE(mii->mii_media_active) ==
- IFM_100_TX && (r & DC_TSTAT_LS100)) {
- sc->dc_link = 0;
- mii_mediachg(mii);
- }
- if (IFM_SUBTYPE(mii->mii_media_active) ==
- IFM_10_T && (r & DC_TSTAT_LS10)) {
- sc->dc_link = 0;
- mii_mediachg(mii);
- }
- if (sc->dc_link == 0)
- mii_tick(mii);
- } else {
- r = CSR_READ_4(sc, DC_ISR);
- if ((r & DC_ISR_RX_STATE) == DC_RXSTATE_WAIT &&
- sc->dc_cdata.dc_tx_cnt == 0) {
- mii_tick(mii);
- if (!(mii->mii_media_status & IFM_ACTIVE))
- sc->dc_link = 0;
- }
- }
- } else
- mii_tick(mii);
-
- /*
- * When the init routine completes, we expect to be able to send
- * packets right away, and in fact the network code will send a
- * gratuitous ARP the moment the init routine marks the interface
- * as running. However, even though the MAC may have been initialized,
- * there may be a delay of a few seconds before the PHY completes
- * autonegotiation and the link is brought up. Any transmissions
- * made during that delay will be lost. Dealing with this is tricky:
- * we can't just pause in the init routine while waiting for the
- * PHY to come ready since that would bring the whole system to
- * a screeching halt for several seconds.
- *
- * What we do here is prevent the TX start routine from sending
- * any packets until a link has been established. After the
- * interface has been initialized, the tick routine will poll
- * the state of the PHY until the IFM_ACTIVE flag is set. Until
- * that time, packets will stay in the send queue, and once the
- * link comes up, they will be flushed out to the wire.
- */
- if (!sc->dc_link && mii->mii_media_status & IFM_ACTIVE &&
- IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
- sc->dc_link++;
- if (ifp->if_snd.ifq_head != NULL)
- dc_start(ifp);
- }
-
- if (sc->dc_flags & DC_21143_NWAY && !sc->dc_link)
- callout_reset(&sc->dc_stat_ch, hz/10, dc_tick, sc);
- else
- callout_reset(&sc->dc_stat_ch, hz, dc_tick, sc);
-
- DC_UNLOCK(sc);
-
- return;
-}
-
-/*
- * A transmit underrun has occurred. Back off the transmit threshold,
- * or switch to store and forward mode if we have to.
- */
-static void
-dc_tx_underrun(sc)
- struct dc_softc *sc;
-{
- u_int32_t isr;
- int i;
-
- if (DC_IS_DAVICOM(sc))
- dc_init(sc);
-
- if (DC_IS_INTEL(sc)) {
- /*
- * The real 21143 requires that the transmitter be idle
- * in order to change the transmit threshold or store
- * and forward state.
- */
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_TX_ON);
-
- for (i = 0; i < DC_TIMEOUT; i++) {
- isr = CSR_READ_4(sc, DC_ISR);
- if (isr & DC_ISR_TX_IDLE)
- break;
- DELAY(10);
- }
- if (i == DC_TIMEOUT) {
- printf("dc%d: failed to force tx to idle state\n",
- sc->dc_unit);
- dc_init(sc);
- }
- }
-
- printf("dc%d: TX underrun -- ", sc->dc_unit);
- sc->dc_txthresh += DC_TXTHRESH_INC;
- if (sc->dc_txthresh > DC_TXTHRESH_MAX) {
- printf("using store and forward mode\n");
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_STORENFWD);
- } else {
- printf("increasing TX threshold\n");
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_TX_THRESH);
- DC_SETBIT(sc, DC_NETCFG, sc->dc_txthresh);
- }
-
- if (DC_IS_INTEL(sc))
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_TX_ON);
-
- return;
-}
-
-#ifdef DEVICE_POLLING
-static poll_handler_t dc_poll;
-
-static void
-dc_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
-{
- struct dc_softc *sc = ifp->if_softc;
-
- if (cmd == POLL_DEREGISTER) { /* final call, enable interrupts */
- /* Re-enable interrupts. */
- CSR_WRITE_4(sc, DC_IMR, DC_INTRS);
- return;
- }
- sc->rxcycles = count;
- dc_rxeof(sc);
- dc_txeof(sc);
- if (ifp->if_snd.ifq_head != NULL && !(ifp->if_flags & IFF_OACTIVE))
- dc_start(ifp);
-
- if (cmd == POLL_AND_CHECK_STATUS) { /* also check status register */
- u_int32_t status;
-
- status = CSR_READ_4(sc, DC_ISR);
- status &= (DC_ISR_RX_WATDOGTIMEO|DC_ISR_RX_NOBUF|
- DC_ISR_TX_NOBUF|DC_ISR_TX_IDLE|DC_ISR_TX_UNDERRUN|
- DC_ISR_BUS_ERR);
- if (!status)
- return;
- /* ack what we have */
- CSR_WRITE_4(sc, DC_ISR, status);
-
- if (status & (DC_ISR_RX_WATDOGTIMEO|DC_ISR_RX_NOBUF)) {
- u_int32_t r = CSR_READ_4(sc, DC_FRAMESDISCARDED);
- ifp->if_ierrors += (r & 0xffff) + ((r >> 17) & 0x7ff);
-
- if (dc_rx_resync(sc))
- dc_rxeof(sc);
- }
- /* restart transmit unit if necessary */
- if (status & DC_ISR_TX_IDLE && sc->dc_cdata.dc_tx_cnt)
- CSR_WRITE_4(sc, DC_TXSTART, 0xFFFFFFFF);
-
- if (status & DC_ISR_TX_UNDERRUN)
- dc_tx_underrun(sc);
-
- if (status & DC_ISR_BUS_ERR) {
- printf("dc_poll: dc%d bus error\n", sc->dc_unit);
- dc_reset(sc);
- dc_init(sc);
- }
- }
-}
-#endif /* DEVICE_POLLING */
-
-static void
-dc_intr(arg)
- void *arg;
-{
- struct dc_softc *sc;
- struct ifnet *ifp;
- u_int32_t status;
-
- sc = arg;
-
- if (sc->suspended) {
- return;
- }
-
- if ((CSR_READ_4(sc, DC_ISR) & DC_INTRS) == 0)
- return;
-
- DC_LOCK(sc);
- ifp = &sc->arpcom.ac_if;
-#ifdef DEVICE_POLLING
- if (ifp->if_flags & IFF_POLLING)
- goto done;
- if (ether_poll_register(dc_poll, ifp)) { /* ok, disable interrupts */
- CSR_WRITE_4(sc, DC_IMR, 0x00000000);
- goto done;
- }
-#endif /* DEVICE_POLLING */
-
- /* Suppress unwanted interrupts */
- if (!(ifp->if_flags & IFF_UP)) {
- if (CSR_READ_4(sc, DC_ISR) & DC_INTRS)
- dc_stop(sc);
- DC_UNLOCK(sc);
- return;
- }
-
- /* Disable interrupts. */
- CSR_WRITE_4(sc, DC_IMR, 0x00000000);
-
- while(((status = CSR_READ_4(sc, DC_ISR)) & DC_INTRS)
- && status != 0xFFFFFFFF) {
-
- CSR_WRITE_4(sc, DC_ISR, status);
-
- if (status & DC_ISR_RX_OK) {
- int curpkts;
- curpkts = ifp->if_ipackets;
- dc_rxeof(sc);
- if (curpkts == ifp->if_ipackets) {
- while(dc_rx_resync(sc))
- dc_rxeof(sc);
- }
- }
-
- if (status & (DC_ISR_TX_OK|DC_ISR_TX_NOBUF))
- dc_txeof(sc);
-
- if (status & DC_ISR_TX_IDLE) {
- dc_txeof(sc);
- if (sc->dc_cdata.dc_tx_cnt) {
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_TX_ON);
- CSR_WRITE_4(sc, DC_TXSTART, 0xFFFFFFFF);
- }
- }
-
- if (status & DC_ISR_TX_UNDERRUN)
- dc_tx_underrun(sc);
-
- if ((status & DC_ISR_RX_WATDOGTIMEO)
- || (status & DC_ISR_RX_NOBUF)) {
- int curpkts;
- curpkts = ifp->if_ipackets;
- dc_rxeof(sc);
- if (curpkts == ifp->if_ipackets) {
- while(dc_rx_resync(sc))
- dc_rxeof(sc);
- }
- }
-
- if (status & DC_ISR_BUS_ERR) {
- dc_reset(sc);
- dc_init(sc);
- }
- }
-
- /* Re-enable interrupts. */
- CSR_WRITE_4(sc, DC_IMR, DC_INTRS);
-
- if (ifp->if_snd.ifq_head != NULL)
- dc_start(ifp);
-
-#ifdef DEVICE_POLLING
-done:
-#endif /* DEVICE_POLLING */
-
- DC_UNLOCK(sc);
-
- return;
-}
-
-/*
- * Encapsulate an mbuf chain in a descriptor by coupling the mbuf data
- * pointers to the fragment pointers.
- */
-static int
-dc_encap(sc, m_head, txidx)
- struct dc_softc *sc;
- struct mbuf *m_head;
- u_int32_t *txidx;
-{
- struct dc_desc *f = NULL;
- struct mbuf *m;
- int frag, cur, cnt = 0, chainlen = 0;
-
- /*
- * If there's no way we can send any packets, return now.
- */
- if (DC_TX_LIST_CNT - sc->dc_cdata.dc_tx_cnt < 6)
- return (ENOBUFS);
-
- /*
- * Count the number of frags in this chain to see if
- * we need to m_defrag. Since the descriptor list is shared
- * by all packets, we'll m_defrag long chains so that they
- * do not use up the entire list, even if they would fit.
- */
-
- for (m = m_head; m != NULL; m = m->m_next)
- chainlen++;
-
- if ((chainlen > DC_TX_LIST_CNT / 4) ||
- ((DC_TX_LIST_CNT - (chainlen + sc->dc_cdata.dc_tx_cnt)) < 6)) {
- m = m_defrag(m_head, M_DONTWAIT);
- if (m == NULL)
- return (ENOBUFS);
- m_head = m;
- }
-
- /*
- * Start packing the mbufs in this chain into
- * the fragment pointers. Stop when we run out
- * of fragments or hit the end of the mbuf chain.
- */
- m = m_head;
- cur = frag = *txidx;
-
- for (m = m_head; m != NULL; m = m->m_next) {
- if (m->m_len != 0) {
- if (sc->dc_flags & DC_TX_ADMTEK_WAR) {
- if (*txidx != sc->dc_cdata.dc_tx_prod &&
- frag == (DC_TX_LIST_CNT - 1))
- return(ENOBUFS);
- }
- if ((DC_TX_LIST_CNT -
- (sc->dc_cdata.dc_tx_cnt + cnt)) < 5)
- return(ENOBUFS);
-
- f = &sc->dc_ldata->dc_tx_list[frag];
- f->dc_ctl = DC_TXCTL_TLINK | m->m_len;
- if (cnt == 0) {
- f->dc_status = 0;
- f->dc_ctl |= DC_TXCTL_FIRSTFRAG;
- } else
- f->dc_status = DC_TXSTAT_OWN;
- f->dc_data = vtophys(mtod(m, vm_offset_t));
- cur = frag;
- DC_INC(frag, DC_TX_LIST_CNT);
- cnt++;
- }
- }
-
- if (m != NULL)
- return(ENOBUFS);
-
- sc->dc_cdata.dc_tx_cnt += cnt;
- sc->dc_cdata.dc_tx_chain[cur] = m_head;
- sc->dc_ldata->dc_tx_list[cur].dc_ctl |= DC_TXCTL_LASTFRAG;
- if (sc->dc_flags & DC_TX_INTR_FIRSTFRAG)
- sc->dc_ldata->dc_tx_list[*txidx].dc_ctl |= DC_TXCTL_FINT;
- if (sc->dc_flags & DC_TX_INTR_ALWAYS)
- sc->dc_ldata->dc_tx_list[cur].dc_ctl |= DC_TXCTL_FINT;
- if (sc->dc_flags & DC_TX_USE_TX_INTR && sc->dc_cdata.dc_tx_cnt > 64)
- sc->dc_ldata->dc_tx_list[cur].dc_ctl |= DC_TXCTL_FINT;
- sc->dc_ldata->dc_tx_list[*txidx].dc_status = DC_TXSTAT_OWN;
- *txidx = frag;
-
- return(0);
-}
-
-/*
- * Main transmit routine. To avoid having to do mbuf copies, we put pointers
- * to the mbuf data regions directly in the transmit lists. We also save a
- * copy of the pointers since the transmit list fragment pointers are
- * physical addresses.
- */
-
-static void
-dc_start(ifp)
- struct ifnet *ifp;
-{
- struct dc_softc *sc;
- struct mbuf *m_head = NULL, *m;
- int idx;
-
- sc = ifp->if_softc;
-
- DC_LOCK(sc);
-
- if (!sc->dc_link && ifp->if_snd.ifq_len < 10) {
- DC_UNLOCK(sc);
- return;
- }
-
- if (ifp->if_flags & IFF_OACTIVE) {
- DC_UNLOCK(sc);
- return;
- }
-
- idx = sc->dc_cdata.dc_tx_prod;
-
- while(sc->dc_cdata.dc_tx_chain[idx] == NULL) {
- IF_DEQUEUE(&ifp->if_snd, m_head);
- if (m_head == NULL)
- break;
-
- if (sc->dc_flags & DC_TX_COALESCE &&
- (m_head->m_next != NULL ||
- sc->dc_flags & DC_TX_ALIGN)) {
- m = m_defrag(m_head, M_DONTWAIT);
- if (m == NULL) {
- IF_PREPEND(&ifp->if_snd, m_head);
- ifp->if_flags |= IFF_OACTIVE;
- break;
- } else {
- m_head = m;
- }
- }
-
- if (dc_encap(sc, m_head, &idx)) {
- IF_PREPEND(&ifp->if_snd, m_head);
- ifp->if_flags |= IFF_OACTIVE;
- break;
- }
-
- /*
- * If there's a BPF listener, bounce a copy of this frame
- * to him.
- */
- BPF_MTAP(ifp, m_head);
-
- if (sc->dc_flags & DC_TX_ONE) {
- ifp->if_flags |= IFF_OACTIVE;
- break;
- }
- }
-
- /* Transmit */
- sc->dc_cdata.dc_tx_prod = idx;
- if (!(sc->dc_flags & DC_TX_POLL))
- CSR_WRITE_4(sc, DC_TXSTART, 0xFFFFFFFF);
-
- /*
- * Set a timeout in case the chip goes out to lunch.
- */
- ifp->if_timer = 5;
-
- DC_UNLOCK(sc);
-
- return;
-}
-
-static void
-dc_init(xsc)
- void *xsc;
-{
- struct dc_softc *sc = xsc;
- struct ifnet *ifp = &sc->arpcom.ac_if;
- struct mii_data *mii;
-
- DC_LOCK(sc);
-
- mii = device_get_softc(sc->dc_miibus);
-
- /*
- * Cancel pending I/O and free all RX/TX buffers.
- */
- dc_stop(sc);
- dc_reset(sc);
-
- /*
- * Set cache alignment and burst length.
- */
- if (DC_IS_ASIX(sc) || DC_IS_DAVICOM(sc))
- CSR_WRITE_4(sc, DC_BUSCTL, 0);
- else
- CSR_WRITE_4(sc, DC_BUSCTL, DC_BUSCTL_MRME|DC_BUSCTL_MRLE);
- /*
- * Evenly share the bus between receive and transmit process.
- */
- if (DC_IS_INTEL(sc))
- DC_SETBIT(sc, DC_BUSCTL, DC_BUSCTL_ARBITRATION);
- if (DC_IS_DAVICOM(sc) || DC_IS_INTEL(sc)) {
- DC_SETBIT(sc, DC_BUSCTL, DC_BURSTLEN_USECA);
- } else {
- DC_SETBIT(sc, DC_BUSCTL, DC_BURSTLEN_16LONG);
- }
- if (sc->dc_flags & DC_TX_POLL)
- DC_SETBIT(sc, DC_BUSCTL, DC_TXPOLL_1);
- switch(sc->dc_cachesize) {
- case 32:
- DC_SETBIT(sc, DC_BUSCTL, DC_CACHEALIGN_32LONG);
- break;
- case 16:
- DC_SETBIT(sc, DC_BUSCTL, DC_CACHEALIGN_16LONG);
- break;
- case 8:
- DC_SETBIT(sc, DC_BUSCTL, DC_CACHEALIGN_8LONG);
- break;
- case 0:
- default:
- DC_SETBIT(sc, DC_BUSCTL, DC_CACHEALIGN_NONE);
- break;
- }
-
- if (sc->dc_flags & DC_TX_STORENFWD)
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_STORENFWD);
- else {
- if (sc->dc_txthresh > DC_TXTHRESH_MAX) {
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_STORENFWD);
- } else {
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_STORENFWD);
- DC_SETBIT(sc, DC_NETCFG, sc->dc_txthresh);
- }
- }
-
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_NO_RXCRC);
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_TX_BACKOFF);
-
- if (DC_IS_MACRONIX(sc) || DC_IS_PNICII(sc)) {
- /*
- * The app notes for the 98713 and 98715A say that
- * in order to have the chips operate properly, a magic
- * number must be written to CSR16. Macronix does not
- * document the meaning of these bits so there's no way
- * to know exactly what they do. The 98713 has a magic
- * number all its own; the rest all use a different one.
- */
- DC_CLRBIT(sc, DC_MX_MAGICPACKET, 0xFFFF0000);
- if (sc->dc_type == DC_TYPE_98713)
- DC_SETBIT(sc, DC_MX_MAGICPACKET, DC_MX_MAGIC_98713);
- else
- DC_SETBIT(sc, DC_MX_MAGICPACKET, DC_MX_MAGIC_98715);
- }
-
- if (DC_IS_XIRCOM(sc)) {
- /*
- * setup General Purpose Port mode and data so the tulip
- * can talk to the MII.
- */
- CSR_WRITE_4(sc, DC_SIAGP, DC_SIAGP_WRITE_EN | DC_SIAGP_INT1_EN |
- DC_SIAGP_MD_GP2_OUTPUT | DC_SIAGP_MD_GP0_OUTPUT);
- DELAY(10);
- CSR_WRITE_4(sc, DC_SIAGP, DC_SIAGP_INT1_EN |
- DC_SIAGP_MD_GP2_OUTPUT | DC_SIAGP_MD_GP0_OUTPUT);
- DELAY(10);
- }
-
- DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_TX_THRESH);
- DC_SETBIT(sc, DC_NETCFG, DC_TXTHRESH_MIN);
-
- /* Init circular RX list. */
- if (dc_list_rx_init(sc) == ENOBUFS) {
- printf("dc%d: initialization failed: no "
- "memory for rx buffers\n", sc->dc_unit);
- dc_stop(sc);
- DC_UNLOCK(sc);
- return;
- }
-
- /*
- * Init tx descriptors.
- */
- dc_list_tx_init(sc);
-
- /*
- * Load the address of the RX list.
- */
- CSR_WRITE_4(sc, DC_RXADDR, vtophys(&sc->dc_ldata->dc_rx_list[0]));
- CSR_WRITE_4(sc, DC_TXADDR, vtophys(&sc->dc_ldata->dc_tx_list[0]));
-
- /*
- * Enable interrupts.
- */
-#ifdef DEVICE_POLLING
- /*
- * ... but only if we are not polling, and make sure they are off in
- * the case of polling. Some cards (e.g. fxp) turn interrupts on
- * after a reset.
- */
- if (ifp->if_flags & IFF_POLLING)
- CSR_WRITE_4(sc, DC_IMR, 0x00000000);
- else
-#endif
- CSR_WRITE_4(sc, DC_IMR, DC_INTRS);
- CSR_WRITE_4(sc, DC_ISR, 0xFFFFFFFF);
-
- /* Enable transmitter. */
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_TX_ON);
-
- /*
- * If this is an Intel 21143 and we're not using the
- * MII port, program the LED control pins so we get
- * link and activity indications.
- */
- if (sc->dc_flags & DC_TULIP_LEDS) {
- CSR_WRITE_4(sc, DC_WATCHDOG,
- DC_WDOG_CTLWREN|DC_WDOG_LINK|DC_WDOG_ACTIVITY);
- CSR_WRITE_4(sc, DC_WATCHDOG, 0);
- }
-
- /*
- * Load the RX/multicast filter. We do this sort of late
- * because the filter programming scheme on the 21143 and
- * some clones requires DMAing a setup frame via the TX
- * engine, and we need the transmitter enabled for that.
- */
- dc_setfilt(sc);
-
- /* Enable receiver. */
- DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ON);
- CSR_WRITE_4(sc, DC_RXSTART, 0xFFFFFFFF);
-
- mii_mediachg(mii);
- dc_setcfg(sc, sc->dc_if_media);
-
- ifp->if_flags |= IFF_RUNNING;
- ifp->if_flags &= ~IFF_OACTIVE;
-
- /* Don't start the ticker if this is a homePNA link. */
- if (IFM_SUBTYPE(mii->mii_media.ifm_media) == IFM_HPNA_1)
- sc->dc_link = 1;
- else {
- if (sc->dc_flags & DC_21143_NWAY)
- callout_reset(&sc->dc_stat_ch, hz/10, dc_tick, sc);
- else
- callout_reset(&sc->dc_stat_ch, hz, dc_tick, sc);
- }
-
-#ifdef SRM_MEDIA
- if(sc->dc_srm_media) {
- struct ifreq ifr;
-
- ifr.ifr_media = sc->dc_srm_media;
- ifmedia_ioctl(ifp, &ifr, &mii->mii_media, SIOCSIFMEDIA);
- sc->dc_srm_media = 0;
- }
-#endif
- DC_UNLOCK(sc);
- return;
-}
-
-/*
- * Set media options.
- */
-static int
-dc_ifmedia_upd(ifp)
- struct ifnet *ifp;
-{
- struct dc_softc *sc;
- struct mii_data *mii;
- struct ifmedia *ifm;
-
- sc = ifp->if_softc;
- mii = device_get_softc(sc->dc_miibus);
- mii_mediachg(mii);
- ifm = &mii->mii_media;
-
- if (DC_IS_DAVICOM(sc) &&
- IFM_SUBTYPE(ifm->ifm_media) == IFM_HPNA_1)
- dc_setcfg(sc, ifm->ifm_media);
- else
- sc->dc_link = 0;
-
- return(0);
-}
-
-/*
- * Report current media status.
- */
-static void
-dc_ifmedia_sts(ifp, ifmr)
- struct ifnet *ifp;
- struct ifmediareq *ifmr;
-{
- struct dc_softc *sc;
- struct mii_data *mii;
- struct ifmedia *ifm;
-
- sc = ifp->if_softc;
- mii = device_get_softc(sc->dc_miibus);
- mii_pollstat(mii);
- ifm = &mii->mii_media;
- if (DC_IS_DAVICOM(sc)) {
- if (IFM_SUBTYPE(ifm->ifm_media) == IFM_HPNA_1) {
- ifmr->ifm_active = ifm->ifm_media;
- ifmr->ifm_status = 0;
- return;
- }
- }
- ifmr->ifm_active = mii->mii_media_active;
- ifmr->ifm_status = mii->mii_media_status;
-
- return;
-}
-
-static int
-dc_ioctl(ifp, command, data)
- struct ifnet *ifp;
- u_long command;
- caddr_t data;
-{
- struct dc_softc *sc = ifp->if_softc;
- struct ifreq *ifr = (struct ifreq *) data;
- struct mii_data *mii;
- int error = 0;
-
- DC_LOCK(sc);
-
- switch(command) {
- case SIOCSIFFLAGS:
- if (ifp->if_flags & IFF_UP) {
- int need_setfilt = (ifp->if_flags ^ sc->dc_if_flags) &
- (IFF_PROMISC | IFF_ALLMULTI);
-
- if (ifp->if_flags & IFF_RUNNING) {
- if (need_setfilt)
- dc_setfilt(sc);
- } else {
- sc->dc_txthresh = 0;
- dc_init(sc);
- }
- } else {
- if (ifp->if_flags & IFF_RUNNING)
- dc_stop(sc);
- }
- sc->dc_if_flags = ifp->if_flags;
- error = 0;
- break;
- case SIOCADDMULTI:
- case SIOCDELMULTI:
- dc_setfilt(sc);
- error = 0;
- break;
- case SIOCGIFMEDIA:
- case SIOCSIFMEDIA:
- mii = device_get_softc(sc->dc_miibus);
- error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
-#ifdef SRM_MEDIA
- if (sc->dc_srm_media)
- sc->dc_srm_media = 0;
-#endif
- break;
- default:
- error = ether_ioctl(ifp, command, data);
- break;
- }
-
- DC_UNLOCK(sc);
-
- return(error);
-}
-
-static void
-dc_watchdog(ifp)
- struct ifnet *ifp;
-{
- struct dc_softc *sc;
-
- sc = ifp->if_softc;
-
- DC_LOCK(sc);
-
- ifp->if_oerrors++;
- printf("dc%d: watchdog timeout\n", sc->dc_unit);
-
- dc_stop(sc);
- dc_reset(sc);
- dc_init(sc);
-
- if (ifp->if_snd.ifq_head != NULL)
- dc_start(ifp);
-
- DC_UNLOCK(sc);
-
- return;
-}
-
-/*
- * Stop the adapter and free any mbufs allocated to the
- * RX and TX lists.
- */
-static void
-dc_stop(sc)
- struct dc_softc *sc;
-{
- register int i;
- struct ifnet *ifp;
-
- DC_LOCK(sc);
-
- ifp = &sc->arpcom.ac_if;
- ifp->if_timer = 0;
-
- callout_stop(&sc->dc_stat_ch);
-
- ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
-#ifdef DEVICE_POLLING
- ether_poll_deregister(ifp);
-#endif
-
- DC_CLRBIT(sc, DC_NETCFG, (DC_NETCFG_RX_ON|DC_NETCFG_TX_ON));
- CSR_WRITE_4(sc, DC_IMR, 0x00000000);
- CSR_WRITE_4(sc, DC_TXADDR, 0x00000000);
- CSR_WRITE_4(sc, DC_RXADDR, 0x00000000);
- sc->dc_link = 0;
-
- /*
- * Free data in the RX lists.
- */
- for (i = 0; i < DC_RX_LIST_CNT; i++) {
- if (sc->dc_cdata.dc_rx_chain[i] != NULL) {
- m_freem(sc->dc_cdata.dc_rx_chain[i]);
- sc->dc_cdata.dc_rx_chain[i] = NULL;
- }
- }
- bzero((char *)&sc->dc_ldata->dc_rx_list,
- sizeof(sc->dc_ldata->dc_rx_list));
-
- /*
- * Free the TX list buffers.
- */
- for (i = 0; i < DC_TX_LIST_CNT; i++) {
- if (sc->dc_cdata.dc_tx_chain[i] != NULL) {
- if (sc->dc_ldata->dc_tx_list[i].dc_ctl &
- DC_TXCTL_SETUP) {
- sc->dc_cdata.dc_tx_chain[i] = NULL;
- continue;
- }
- m_freem(sc->dc_cdata.dc_tx_chain[i]);
- sc->dc_cdata.dc_tx_chain[i] = NULL;
- }
- }
-
- bzero((char *)&sc->dc_ldata->dc_tx_list,
- sizeof(sc->dc_ldata->dc_tx_list));
-
- DC_UNLOCK(sc);
-
- return;
-}
-
-/*
- * Device suspend routine. Stop the interface and save some PCI
- * settings in case the BIOS doesn't restore them properly on
- * resume.
- */
-static int
-dc_suspend(dev)
- device_t dev;
-{
- register int i;
- int s;
- struct dc_softc *sc;
-
- s = splimp();
-
- sc = device_get_softc(dev);
-
- dc_stop(sc);
-
- for (i = 0; i < 5; i++)
- sc->saved_maps[i] = pci_read_config(dev, PCIR_MAPS + i * 4, 4);
- sc->saved_biosaddr = pci_read_config(dev, PCIR_BIOS, 4);
- sc->saved_intline = pci_read_config(dev, PCIR_INTLINE, 1);
- sc->saved_cachelnsz = pci_read_config(dev, PCIR_CACHELNSZ, 1);
- sc->saved_lattimer = pci_read_config(dev, PCIR_LATTIMER, 1);
-
- sc->suspended = 1;
-
- splx(s);
- return (0);
-}
-
-/*
- * Device resume routine. Restore some PCI settings in case the BIOS
- * doesn't, re-enable busmastering, and restart the interface if
- * appropriate.
- */
-static int
-dc_resume(dev)
- device_t dev;
-{
- register int i;
- int s;
- struct dc_softc *sc;
- struct ifnet *ifp;
-
- s = splimp();
-
- sc = device_get_softc(dev);
- ifp = &sc->arpcom.ac_if;
-
- dc_acpi(dev);
-
- /* better way to do this? */
- for (i = 0; i < 5; i++)
- pci_write_config(dev, PCIR_MAPS + i * 4, sc->saved_maps[i], 4);
- pci_write_config(dev, PCIR_BIOS, sc->saved_biosaddr, 4);
- pci_write_config(dev, PCIR_INTLINE, sc->saved_intline, 1);
- pci_write_config(dev, PCIR_CACHELNSZ, sc->saved_cachelnsz, 1);
- pci_write_config(dev, PCIR_LATTIMER, sc->saved_lattimer, 1);
-
- /* reenable busmastering */
- pci_enable_busmaster(dev);
- pci_enable_io(dev, DC_RES);
-
- /* reinitialize interface if necessary */
- if (ifp->if_flags & IFF_UP)
- dc_init(sc);
-
- sc->suspended = 0;
-
- splx(s);
- return (0);
-}
-
-/*
- * Stop all chip I/O so that the kernel's probe routines don't
- * get confused by errant DMAs when rebooting.
- */
-static void
-dc_shutdown(dev)
- device_t dev;
-{
- struct dc_softc *sc;
-
- sc = device_get_softc(dev);
-
- dc_stop(sc);
-
- return;
-}
diff --git a/sys/dev/dc/if_dcreg.h b/sys/dev/dc/if_dcreg.h
deleted file mode 100644
index d15d68cb3c66..000000000000
--- a/sys/dev/dc/if_dcreg.h
+++ /dev/null
@@ -1,1183 +0,0 @@
-/*
- * Copyright (c) 1997, 1998, 1999
- * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-/*
- * 21143 and clone common register definitions.
- */
-
-#define DC_BUSCTL 0x00 /* bus control */
-#define DC_TXSTART 0x08 /* tx start demand */
-#define DC_RXSTART 0x10 /* rx start demand */
-#define DC_RXADDR 0x18 /* rx descriptor list start addr */
-#define DC_TXADDR 0x20 /* tx descriptor list start addr */
-#define DC_ISR 0x28 /* interrupt status register */
-#define DC_NETCFG 0x30 /* network config register */
-#define DC_IMR 0x38 /* interrupt mask */
-#define DC_FRAMESDISCARDED 0x40 /* # of discarded frames */
-#define DC_SIO 0x48 /* MII and ROM/EEPROM access */
-#define DC_ROM 0x50 /* ROM programming address */
-#define DC_TIMER 0x58 /* general timer */
-#define DC_10BTSTAT 0x60 /* SIA status */
-#define DC_SIARESET 0x68 /* SIA connectivity */
-#define DC_10BTCTRL 0x70 /* SIA transmit and receive */
-#define DC_WATCHDOG 0x78 /* SIA and general purpose port */
-#define DC_SIAGP 0x78 /* SIA and general purpose port (X3201) */
-
-/*
- * There are two general 'types' of MX chips that we need to be
- * concerned with. One is the original 98713, which has its internal
- * NWAY support controlled via the MDIO bits in the serial I/O
- * register. The other is everything else (from the 98713A on up),
- * which has its internal NWAY controlled via CSR13, CSR14 and CSR15,
- * just like the 21143. This type setting also governs which of the
- * 'magic' numbers we write to CSR16. The PNIC II falls into the
- * 98713A/98715/98715A/98725 category.
- */
-#define DC_TYPE_98713 0x1
-#define DC_TYPE_98713A 0x2
-#define DC_TYPE_987x5 0x3
-
-/* Other type of supported chips. */
-#define DC_TYPE_21143 0x4 /* Intel 21143 */
-#define DC_TYPE_ASIX 0x5 /* ASIX AX88140A/AX88141 */
-#define DC_TYPE_AL981 0x6 /* ADMtek AL981 Comet */
-#define DC_TYPE_AN985 0x7 /* ADMtek AN985 Centaur */
-#define DC_TYPE_DM9102 0x8 /* Davicom DM9102 */
-#define DC_TYPE_PNICII 0x9 /* 82c115 PNIC II */
-#define DC_TYPE_PNIC 0xA /* 82c168/82c169 PNIC I */
-#define DC_TYPE_XIRCOM 0xB /* Xircom X3201 */
-#define DC_TYPE_CONEXANT 0xC /* Conexant LANfinity RS7112 */
-
-#define DC_IS_MACRONIX(x) \
- (x->dc_type == DC_TYPE_98713 || \
- x->dc_type == DC_TYPE_98713A || \
- x->dc_type == DC_TYPE_987x5)
-
-#define DC_IS_ADMTEK(x) \
- (x->dc_type == DC_TYPE_AL981 || \
- x->dc_type == DC_TYPE_AN985)
-
-#define DC_IS_INTEL(x) (x->dc_type == DC_TYPE_21143)
-#define DC_IS_ASIX(x) (x->dc_type == DC_TYPE_ASIX)
-#define DC_IS_COMET(x) (x->dc_type == DC_TYPE_AL981)
-#define DC_IS_CENTAUR(x) (x->dc_type == DC_TYPE_AN985)
-#define DC_IS_DAVICOM(x) (x->dc_type == DC_TYPE_DM9102)
-#define DC_IS_PNICII(x) (x->dc_type == DC_TYPE_PNICII)
-#define DC_IS_PNIC(x) (x->dc_type == DC_TYPE_PNIC)
-#define DC_IS_XIRCOM(x) (x->dc_type == DC_TYPE_XIRCOM)
-#define DC_IS_CONEXANT(x) (x->dc_type == DC_TYPE_CONEXANT)
-
-/* MII/symbol mode port types */
-#define DC_PMODE_MII 0x1
-#define DC_PMODE_SYM 0x2
-#define DC_PMODE_SIA 0x3
-
-/*
- * Bus control bits.
- */
-#define DC_BUSCTL_RESET 0x00000001
-#define DC_BUSCTL_ARBITRATION 0x00000002
-#define DC_BUSCTL_SKIPLEN 0x0000007C
-#define DC_BUSCTL_BUF_BIGENDIAN 0x00000080
-#define DC_BUSCTL_BURSTLEN 0x00003F00
-#define DC_BUSCTL_CACHEALIGN 0x0000C000
-#define DC_BUSCTL_TXPOLL 0x000E0000
-#define DC_BUSCTL_DBO 0x00100000
-#define DC_BUSCTL_MRME 0x00200000
-#define DC_BUSCTL_MRLE 0x00800000
-#define DC_BUSCTL_MWIE 0x01000000
-#define DC_BUSCTL_ONNOW_ENB 0x04000000
-
-#define DC_SKIPLEN_1LONG 0x00000004
-#define DC_SKIPLEN_2LONG 0x00000008
-#define DC_SKIPLEN_3LONG 0x00000010
-#define DC_SKIPLEN_4LONG 0x00000020
-#define DC_SKIPLEN_5LONG 0x00000040
-
-#define DC_CACHEALIGN_NONE 0x00000000
-#define DC_CACHEALIGN_8LONG 0x00004000
-#define DC_CACHEALIGN_16LONG 0x00008000
-#define DC_CACHEALIGN_32LONG 0x0000C000
-
-#define DC_BURSTLEN_USECA 0x00000000
-#define DC_BURSTLEN_1LONG 0x00000100
-#define DC_BURSTLEN_2LONG 0x00000200
-#define DC_BURSTLEN_4LONG 0x00000400
-#define DC_BURSTLEN_8LONG 0x00000800
-#define DC_BURSTLEN_16LONG 0x00001000
-#define DC_BURSTLEN_32LONG 0x00002000
-
-#define DC_TXPOLL_OFF 0x00000000
-#define DC_TXPOLL_1 0x00020000
-#define DC_TXPOLL_2 0x00040000
-#define DC_TXPOLL_3 0x00060000
-#define DC_TXPOLL_4 0x00080000
-#define DC_TXPOLL_5 0x000A0000
-#define DC_TXPOLL_6 0x000C0000
-#define DC_TXPOLL_7 0x000E0000
-
-/*
- * Interrupt status bits.
- */
-#define DC_ISR_TX_OK 0x00000001
-#define DC_ISR_TX_IDLE 0x00000002
-#define DC_ISR_TX_NOBUF 0x00000004
-#define DC_ISR_TX_JABBERTIMEO 0x00000008
-#define DC_ISR_LINKGOOD 0x00000010
-#define DC_ISR_TX_UNDERRUN 0x00000020
-#define DC_ISR_RX_OK 0x00000040
-#define DC_ISR_RX_NOBUF 0x00000080
-#define DC_ISR_RX_READ 0x00000100
-#define DC_ISR_RX_WATDOGTIMEO 0x00000200
-#define DC_ISR_TX_EARLY 0x00000400
-#define DC_ISR_TIMER_EXPIRED 0x00000800
-#define DC_ISR_LINKFAIL 0x00001000
-#define DC_ISR_BUS_ERR 0x00002000
-#define DC_ISR_RX_EARLY 0x00004000
-#define DC_ISR_ABNORMAL 0x00008000
-#define DC_ISR_NORMAL 0x00010000
-#define DC_ISR_RX_STATE 0x000E0000
-#define DC_ISR_TX_STATE 0x00700000
-#define DC_ISR_BUSERRTYPE 0x03800000
-#define DC_ISR_100MBPSLINK 0x08000000
-#define DC_ISR_MAGICKPACK 0x10000000
-
-#define DC_RXSTATE_STOPPED 0x00000000 /* 000 - Stopped */
-#define DC_RXSTATE_FETCH 0x00020000 /* 001 - Fetching descriptor */
-#define DC_RXSTATE_ENDCHECK 0x00040000 /* 010 - check for rx end */
-#define DC_RXSTATE_WAIT 0x00060000 /* 011 - waiting for packet */
-#define DC_RXSTATE_SUSPEND 0x00080000 /* 100 - suspend rx */
-#define DC_RXSTATE_CLOSE 0x000A0000 /* 101 - close tx desc */
-#define DC_RXSTATE_FLUSH 0x000C0000 /* 110 - flush from FIFO */
-#define DC_RXSTATE_DEQUEUE 0x000E0000 /* 111 - dequeue from FIFO */
-
-#define DC_TXSTATE_RESET 0x00000000 /* 000 - reset */
-#define DC_TXSTATE_FETCH 0x00100000 /* 001 - fetching descriptor */
-#define DC_TXSTATE_WAITEND 0x00200000 /* 010 - wait for tx end */
-#define DC_TXSTATE_READING 0x00300000 /* 011 - read and enqueue */
-#define DC_TXSTATE_RSVD 0x00400000 /* 100 - reserved */
-#define DC_TXSTATE_SETUP 0x00500000 /* 101 - setup packet */
-#define DC_TXSTATE_SUSPEND 0x00600000 /* 110 - suspend tx */
-#define DC_TXSTATE_CLOSE 0x00700000 /* 111 - close tx desc */
-
-/*
- * Network config bits.
- */
-#define DC_NETCFG_RX_HASHPERF 0x00000001
-#define DC_NETCFG_RX_ON 0x00000002
-#define DC_NETCFG_RX_HASHONLY 0x00000004
-#define DC_NETCFG_RX_BADFRAMES 0x00000008
-#define DC_NETCFG_RX_INVFILT 0x00000010
-#define DC_NETCFG_BACKOFFCNT 0x00000020
-#define DC_NETCFG_RX_PROMISC 0x00000040
-#define DC_NETCFG_RX_ALLMULTI 0x00000080
-#define DC_NETCFG_FULLDUPLEX 0x00000200
-#define DC_NETCFG_LOOPBACK 0x00000C00
-#define DC_NETCFG_FORCECOLL 0x00001000
-#define DC_NETCFG_TX_ON 0x00002000
-#define DC_NETCFG_TX_THRESH 0x0000C000
-#define DC_NETCFG_TX_BACKOFF 0x00020000
-#define DC_NETCFG_PORTSEL 0x00040000 /* 0 == 10, 1 == 100 */
-#define DC_NETCFG_HEARTBEAT 0x00080000
-#define DC_NETCFG_STORENFWD 0x00200000
-#define DC_NETCFG_SPEEDSEL 0x00400000 /* 1 == 10, 0 == 100 */
-#define DC_NETCFG_PCS 0x00800000
-#define DC_NETCFG_SCRAMBLER 0x01000000
-#define DC_NETCFG_NO_RXCRC 0x02000000
-#define DC_NETCFG_RX_ALL 0x40000000
-#define DC_NETCFG_CAPEFFECT 0x80000000
-
-#define DC_OPMODE_NORM 0x00000000
-#define DC_OPMODE_INTLOOP 0x00000400
-#define DC_OPMODE_EXTLOOP 0x00000800
-
-#if 0
-#define DC_TXTHRESH_72BYTES 0x00000000
-#define DC_TXTHRESH_96BYTES 0x00004000
-#define DC_TXTHRESH_128BYTES 0x00008000
-#define DC_TXTHRESH_160BYTES 0x0000C000
-#endif
-
-#define DC_TXTHRESH_MIN 0x00000000
-#define DC_TXTHRESH_INC 0x00004000
-#define DC_TXTHRESH_MAX 0x0000C000
-
-
-/*
- * Interrupt mask bits.
- */
-#define DC_IMR_TX_OK 0x00000001
-#define DC_IMR_TX_IDLE 0x00000002
-#define DC_IMR_TX_NOBUF 0x00000004
-#define DC_IMR_TX_JABBERTIMEO 0x00000008
-#define DC_IMR_LINKGOOD 0x00000010
-#define DC_IMR_TX_UNDERRUN 0x00000020
-#define DC_IMR_RX_OK 0x00000040
-#define DC_IMR_RX_NOBUF 0x00000080
-#define DC_IMR_RX_READ 0x00000100
-#define DC_IMR_RX_WATDOGTIMEO 0x00000200
-#define DC_IMR_TX_EARLY 0x00000400
-#define DC_IMR_TIMER_EXPIRED 0x00000800
-#define DC_IMR_LINKFAIL 0x00001000
-#define DC_IMR_BUS_ERR 0x00002000
-#define DC_IMR_RX_EARLY 0x00004000
-#define DC_IMR_ABNORMAL 0x00008000
-#define DC_IMR_NORMAL 0x00010000
-#define DC_IMR_100MBPSLINK 0x08000000
-#define DC_IMR_MAGICKPACK 0x10000000
-
-#define DC_INTRS \
- (DC_IMR_RX_OK|DC_IMR_TX_OK|DC_IMR_RX_NOBUF|DC_IMR_RX_WATDOGTIMEO|\
- DC_IMR_TX_NOBUF|DC_IMR_TX_UNDERRUN|DC_IMR_BUS_ERR| \
- DC_IMR_ABNORMAL|DC_IMR_NORMAL/*|DC_IMR_TX_EARLY*/)
-/*
- * Serial I/O (EEPROM/ROM) bits.
- */
-#define DC_SIO_EE_CS 0x00000001 /* EEPROM chip select */
-#define DC_SIO_EE_CLK 0x00000002 /* EEPROM clock */
-#define DC_SIO_EE_DATAIN 0x00000004 /* EEPROM data output */
-#define DC_SIO_EE_DATAOUT 0x00000008 /* EEPROM data input */
-#define DC_SIO_ROMDATA4 0x00000010
-#define DC_SIO_ROMDATA5 0x00000020
-#define DC_SIO_ROMDATA6 0x00000040
-#define DC_SIO_ROMDATA7 0x00000080
-#define DC_SIO_EESEL 0x00000800
-#define DC_SIO_ROMSEL 0x00001000
-#define DC_SIO_ROMCTL_WRITE 0x00002000
-#define DC_SIO_ROMCTL_READ 0x00004000
-#define DC_SIO_MII_CLK 0x00010000 /* MDIO clock */
-#define DC_SIO_MII_DATAOUT 0x00020000 /* MDIO data out */
-#define DC_SIO_MII_DIR 0x00040000 /* MDIO dir */
-#define DC_SIO_MII_DATAIN 0x00080000 /* MDIO data in */
-
-#define DC_EECMD_WRITE 0x140
-#define DC_EECMD_READ 0x180
-#define DC_EECMD_ERASE 0x1c0
-
-#define DC_EE_NODEADDR_OFFSET 0x70
-#define DC_EE_NODEADDR 10
-
-/*
- * General purpose timer register
- */
-#define DC_TIMER_VALUE 0x0000FFFF
-#define DC_TIMER_CONTINUOUS 0x00010000
-
-/*
- * 10baseT status register
- */
-#define DC_TSTAT_MIIACT 0x00000001 /* MII port activity */
-#define DC_TSTAT_LS100 0x00000002 /* link status of 100baseTX */
-#define DC_TSTAT_LS10 0x00000004 /* link status of 10baseT */
-#define DC_TSTAT_AUTOPOLARITY 0x00000008
-#define DC_TSTAT_AUIACT 0x00000100 /* AUI activity */
-#define DC_TSTAT_10BTACT 0x00000200 /* 10baseT activity */
-#define DC_TSTAT_NSN 0x00000400 /* non-stable FLPs detected */
-#define DC_TSTAT_REMFAULT 0x00000800
-#define DC_TSTAT_ANEGSTAT 0x00007000
-#define DC_TSTAT_LP_CAN_NWAY 0x00008000 /* link partner supports NWAY */
-#define DC_TSTAT_LPCODEWORD 0xFFFF0000 /* link partner's code word */
-
-#define DC_ASTAT_DISABLE 0x00000000
-#define DC_ASTAT_TXDISABLE 0x00001000
-#define DC_ASTAT_ABDETECT 0x00002000
-#define DC_ASTAT_ACKDETECT 0x00003000
-#define DC_ASTAT_CMPACKDETECT 0x00004000
-#define DC_ASTAT_AUTONEGCMP 0x00005000
-#define DC_ASTAT_LINKCHECK 0x00006000
-
-/*
- * PHY reset register
- */
-#define DC_SIA_RESET 0x00000001
-#define DC_SIA_AUI 0x00000008 /* AUI or 10baseT */
-
-/*
- * 10baseT control register
- */
-#define DC_TCTL_ENCODER_ENB 0x00000001
-#define DC_TCTL_LOOPBACK 0x00000002
-#define DC_TCTL_DRIVER_ENB 0x00000004
-#define DC_TCTL_LNKPULSE_ENB 0x00000008
-#define DC_TCTL_HALFDUPLEX 0x00000040
-#define DC_TCTL_AUTONEGENBL 0x00000080
-#define DC_TCTL_RX_SQUELCH 0x00000100
-#define DC_TCTL_COLL_SQUELCH 0x00000200
-#define DC_TCTL_COLL_DETECT 0x00000400
-#define DC_TCTL_SQE_ENB 0x00000800
-#define DC_TCTL_LINKTEST 0x00001000
-#define DC_TCTL_AUTOPOLARITY 0x00002000
-#define DC_TCTL_SET_POL_PLUS 0x00004000
-#define DC_TCTL_AUTOSENSE 0x00008000 /* 10bt/AUI autosense */
-#define DC_TCTL_100BTXHALF 0x00010000
-#define DC_TCTL_100BTXFULL 0x00020000
-#define DC_TCTL_100BT4 0x00040000
-
-/*
- * Watchdog timer register
- */
-#define DC_WDOG_JABBERDIS 0x00000001
-#define DC_WDOG_HOSTUNJAB 0x00000002
-#define DC_WDOG_JABBERCLK 0x00000004
-#define DC_WDOG_RXWDOGDIS 0x00000010
-#define DC_WDOG_RXWDOGCLK 0x00000020
-#define DC_WDOG_MUSTBEZERO 0x00000100
-#define DC_WDOG_AUIBNC 0x00100000
-#define DC_WDOG_ACTIVITY 0x00200000
-#define DC_WDOG_RX_MATCH 0x00400000
-#define DC_WDOG_LINK 0x00800000
-#define DC_WDOG_CTLWREN 0x08000000
-
-/*
- * SIA and General Purpose Port register (X3201)
- */
-#define DC_SIAGP_RXMATCH 0x40000000
-#define DC_SIAGP_INT1 0x20000000
-#define DC_SIAGP_INT0 0x10000000
-#define DC_SIAGP_WRITE_EN 0x08000000
-#define DC_SIAGP_RXMATCH_EN 0x04000000
-#define DC_SIAGP_INT1_EN 0x02000000
-#define DC_SIAGP_INT0_EN 0x01000000
-#define DC_SIAGP_LED3 0x00800000
-#define DC_SIAGP_LED2 0x00400000
-#define DC_SIAGP_LED1 0x00200000
-#define DC_SIAGP_LED0 0x00100000
-#define DC_SIAGP_MD_GP3_OUTPUT 0x00080000
-#define DC_SIAGP_MD_GP2_OUTPUT 0x00040000
-#define DC_SIAGP_MD_GP1_OUTPUT 0x00020000
-#define DC_SIAGP_MD_GP0_OUTPUT 0x00010000
-
-/*
- * Size of a setup frame.
- */
-#define DC_SFRAME_LEN 192
-
-/*
- * 21x4x TX/RX list structure.
- */
-
-struct dc_desc {
- u_int32_t dc_status;
- u_int32_t dc_ctl;
- u_int32_t dc_ptr1;
- u_int32_t dc_ptr2;
-};
-
-#define dc_data dc_ptr1
-#define dc_next dc_ptr2
-
-#define DC_RXSTAT_FIFOOFLOW 0x00000001
-#define DC_RXSTAT_CRCERR 0x00000002
-#define DC_RXSTAT_DRIBBLE 0x00000004
-#define DC_RXSTAT_MIIERE 0x00000008
-#define DC_RXSTAT_WATCHDOG 0x00000010
-#define DC_RXSTAT_FRAMETYPE 0x00000020 /* 0 == IEEE 802.3 */
-#define DC_RXSTAT_COLLSEEN 0x00000040
-#define DC_RXSTAT_GIANT 0x00000080
-#define DC_RXSTAT_LASTFRAG 0x00000100
-#define DC_RXSTAT_FIRSTFRAG 0x00000200
-#define DC_RXSTAT_MULTICAST 0x00000400
-#define DC_RXSTAT_RUNT 0x00000800
-#define DC_RXSTAT_RXTYPE 0x00003000
-#define DC_RXSTAT_DE 0x00004000
-#define DC_RXSTAT_RXERR 0x00008000
-#define DC_RXSTAT_RXLEN 0x3FFF0000
-#define DC_RXSTAT_OWN 0x80000000
-
-#define DC_RXBYTES(x) ((x & DC_RXSTAT_RXLEN) >> 16)
-#define DC_RXSTAT (DC_RXSTAT_FIRSTFRAG|DC_RXSTAT_LASTFRAG|DC_RXSTAT_OWN)
-
-#define DC_RXCTL_BUFLEN1 0x00000FFF
-#define DC_RXCTL_BUFLEN2 0x00FFF000
-#define DC_RXCTL_RLINK 0x01000000
-#define DC_RXCTL_RLAST 0x02000000
-
-#define DC_TXSTAT_DEFER 0x00000001
-#define DC_TXSTAT_UNDERRUN 0x00000002
-#define DC_TXSTAT_LINKFAIL 0x00000003
-#define DC_TXSTAT_COLLCNT 0x00000078
-#define DC_TXSTAT_SQE 0x00000080
-#define DC_TXSTAT_EXCESSCOLL 0x00000100
-#define DC_TXSTAT_LATECOLL 0x00000200
-#define DC_TXSTAT_NOCARRIER 0x00000400
-#define DC_TXSTAT_CARRLOST 0x00000800
-#define DC_TXSTAT_JABTIMEO 0x00004000
-#define DC_TXSTAT_ERRSUM 0x00008000
-#define DC_TXSTAT_OWN 0x80000000
-
-#define DC_TXCTL_BUFLEN1 0x000007FF
-#define DC_TXCTL_BUFLEN2 0x003FF800
-#define DC_TXCTL_FILTTYPE0 0x00400000
-#define DC_TXCTL_PAD 0x00800000
-#define DC_TXCTL_TLINK 0x01000000
-#define DC_TXCTL_TLAST 0x02000000
-#define DC_TXCTL_NOCRC 0x04000000
-#define DC_TXCTL_SETUP 0x08000000
-#define DC_TXCTL_FILTTYPE1 0x10000000
-#define DC_TXCTL_FIRSTFRAG 0x20000000
-#define DC_TXCTL_LASTFRAG 0x40000000
-#define DC_TXCTL_FINT 0x80000000
-
-#define DC_FILTER_PERFECT 0x00000000
-#define DC_FILTER_HASHPERF 0x00400000
-#define DC_FILTER_INVERSE 0x10000000
-#define DC_FILTER_HASHONLY 0x10400000
-
-#define DC_MAXFRAGS 16
-#ifdef DEVICE_POLLING
-#define DC_RX_LIST_CNT 192
-#else
-#define DC_RX_LIST_CNT 64
-#endif
-#define DC_TX_LIST_CNT 256
-#define DC_MIN_FRAMELEN 60
-#define DC_RXLEN 1536
-
-#define DC_INC(x, y) (x) = (x + 1) % y
-
-struct dc_list_data {
- struct dc_desc dc_rx_list[DC_RX_LIST_CNT];
- struct dc_desc dc_tx_list[DC_TX_LIST_CNT];
-};
-
-struct dc_chain_data {
- struct mbuf *dc_rx_chain[DC_RX_LIST_CNT];
- struct mbuf *dc_tx_chain[DC_TX_LIST_CNT];
- u_int32_t dc_sbuf[DC_SFRAME_LEN/sizeof(u_int32_t)];
- u_int8_t dc_pad[DC_MIN_FRAMELEN];
- int dc_tx_prod;
- int dc_tx_cons;
- int dc_tx_cnt;
- int dc_rx_prod;
-};
-
-struct dc_mediainfo {
- int dc_media;
- u_int8_t *dc_gp_ptr;
- u_int8_t dc_gp_len;
- u_int8_t *dc_reset_ptr;
- u_int8_t dc_reset_len;
- struct dc_mediainfo *dc_next;
-};
-
-
-struct dc_type {
- u_int16_t dc_vid;
- u_int16_t dc_did;
- char *dc_name;
-};
-
-struct dc_mii_frame {
- u_int8_t mii_stdelim;
- u_int8_t mii_opcode;
- u_int8_t mii_phyaddr;
- u_int8_t mii_regaddr;
- u_int8_t mii_turnaround;
- u_int16_t mii_data;
-};
-
-/*
- * MII constants
- */
-#define DC_MII_STARTDELIM 0x01
-#define DC_MII_READOP 0x02
-#define DC_MII_WRITEOP 0x01
-#define DC_MII_TURNAROUND 0x02
-
-
-/*
- * Registers specific to clone devices.
- * This mainly relates to RX filter programming: not all 21x4x clones
- * use the standard DEC filter programming mechanism.
- */
-
-/*
- * ADMtek specific registers and constants for the AL981 and AN985.
- * The AN985 doesn't use the magic PHY registers.
- */
-#define DC_AL_CR 0x88 /* command register */
-#define DC_AL_PAR0 0xA4 /* station address */
-#define DC_AL_PAR1 0xA8 /* station address */
-#define DC_AL_MAR0 0xAC /* multicast hash filter */
-#define DC_AL_MAR1 0xB0 /* multicast hash filter */
-#define DC_AL_BMCR 0xB4 /* built in PHY control */
-#define DC_AL_BMSR 0xB8 /* built in PHY status */
-#define DC_AL_VENID 0xBC /* built in PHY ID0 */
-#define DC_AL_DEVID 0xC0 /* built in PHY ID1 */
-#define DC_AL_ANAR 0xC4 /* built in PHY autoneg advert */
-#define DC_AL_LPAR 0xC8 /* bnilt in PHY link part. ability */
-#define DC_AL_ANER 0xCC /* built in PHY autoneg expansion */
-
-#define DC_AL_CR_ATUR 0x00000001 /* automatic TX underrun recovery */
-#define DC_ADMTEK_PHYADDR 0x1
-#define DC_AL_EE_NODEADDR 4
-/* End of ADMtek specific registers */
-
-/*
- * ASIX specific registers.
- */
-#define DC_AX_FILTIDX 0x68 /* RX filter index */
-#define DC_AX_FILTDATA 0x70 /* RX filter data */
-
-/*
- * Special ASIX-specific bits in the ASIX NETCFG register (CSR6).
- */
-#define DC_AX_NETCFG_RX_BROAD 0x00000100
-
-/*
- * RX Filter Index Register values
- */
-#define DC_AX_FILTIDX_PAR0 0x00000000
-#define DC_AX_FILTIDX_PAR1 0x00000001
-#define DC_AX_FILTIDX_MAR0 0x00000002
-#define DC_AX_FILTIDX_MAR1 0x00000003
-/* End of ASIX specific registers */
-
-/*
- * Macronix specific registers. The Macronix chips have a special
- * register for reading the NWAY status, which we don't use, plus
- * a magic packet register, which we need to tweak a bit per the
- * Macronix application notes.
- */
-#define DC_MX_MAGICPACKET 0x80
-#define DC_MX_NWAYSTAT 0xA0
-
-/*
- * Magic packet register
- */
-#define DC_MX_MPACK_DISABLE 0x00400000
-
-/*
- * NWAY status register.
- */
-#define DC_MX_NWAY_10BTHALF 0x08000000
-#define DC_MX_NWAY_10BTFULL 0x10000000
-#define DC_MX_NWAY_100BTHALF 0x20000000
-#define DC_MX_NWAY_100BTFULL 0x40000000
-#define DC_MX_NWAY_100BT4 0x80000000
-
-/*
- * These are magic values that must be written into CSR16
- * (DC_MX_MAGICPACKET) in order to put the chip into proper
- * operating mode. The magic numbers are documented in the
- * Macronix 98715 application notes.
- */
-#define DC_MX_MAGIC_98713 0x0F370000
-#define DC_MX_MAGIC_98713A 0x0B3C0000
-#define DC_MX_MAGIC_98715 0x0B3C0000
-#define DC_MX_MAGIC_98725 0x0B3C0000
-/* End of Macronix specific registers */
-
-/*
- * PNIC 82c168/82c169 specific registers.
- * The PNIC has its own special NWAY support, which doesn't work,
- * and shortcut ways of reading the EEPROM and MII bus.
- */
-#define DC_PN_GPIO 0x60 /* general purpose pins control */
-#define DC_PN_PWRUP_CFG 0x90 /* config register, set by EEPROM */
-#define DC_PN_SIOCTL 0x98 /* serial EEPROM control register */
-#define DC_PN_MII 0xA0 /* MII access register */
-#define DC_PN_NWAY 0xB8 /* Internal NWAY register */
-
-/* Serial I/O EEPROM register */
-#define DC_PN_SIOCTL_DATA 0x0000003F
-#define DC_PN_SIOCTL_OPCODE 0x00000300
-#define DC_PN_SIOCTL_BUSY 0x80000000
-
-#define DC_PN_EEOPCODE_ERASE 0x00000300
-#define DC_PN_EEOPCODE_READ 0x00000600
-#define DC_PN_EEOPCODE_WRITE 0x00000100
-
-/*
- * The first two general purpose pins control speed selection and
- * 100Mbps loopback on the 82c168 chip. The control bits should always
- * be set (to make the data pins outputs) and the speed selction and
- * loopback bits set accordingly when changing media. Physically, this
- * will set the state of a relay mounted on the card.
- */
-#define DC_PN_GPIO_DATA0 0x000000001
-#define DC_PN_GPIO_DATA1 0x000000002
-#define DC_PN_GPIO_DATA2 0x000000004
-#define DC_PN_GPIO_DATA3 0x000000008
-#define DC_PN_GPIO_CTL0 0x000000010
-#define DC_PN_GPIO_CTL1 0x000000020
-#define DC_PN_GPIO_CTL2 0x000000040
-#define DC_PN_GPIO_CTL3 0x000000080
-#define DC_PN_GPIO_SPEEDSEL DC_PN_GPIO_DATA0/* 1 == 100Mbps, 0 == 10Mbps */
-#define DC_PN_GPIO_100TX_LOOP DC_PN_GPIO_DATA1/* 1 == normal, 0 == loop */
-#define DC_PN_GPIO_BNC_ENB DC_PN_GPIO_DATA2
-#define DC_PN_GPIO_100TX_LNK DC_PN_GPIO_DATA3
-#define DC_PN_GPIO_SETBIT(sc, r) \
- DC_SETBIT(sc, DC_PN_GPIO, ((r) | (r << 4)))
-#define DC_PN_GPIO_CLRBIT(sc, r) \
- { \
- DC_SETBIT(sc, DC_PN_GPIO, ((r) << 4)); \
- DC_CLRBIT(sc, DC_PN_GPIO, (r)); \
- }
-
-/* shortcut MII access register */
-#define DC_PN_MII_DATA 0x0000FFFF
-#define DC_PN_MII_RESERVER 0x00020000
-#define DC_PN_MII_REGADDR 0x007C0000
-#define DC_PN_MII_PHYADDR 0x0F800000
-#define DC_PN_MII_OPCODE 0x30000000
-#define DC_PN_MII_BUSY 0x80000000
-
-#define DC_PN_MIIOPCODE_READ 0x60020000
-#define DC_PN_MIIOPCODE_WRITE 0x50020000
-
-/* Internal NWAY bits */
-#define DC_PN_NWAY_RESET 0x00000001 /* reset */
-#define DC_PN_NWAY_PDOWN 0x00000002 /* power down */
-#define DC_PN_NWAY_BYPASS 0x00000004 /* bypass */
-#define DC_PN_NWAY_AUILOWCUR 0x00000008 /* AUI low current */
-#define DC_PN_NWAY_TPEXTEND 0x00000010 /* low squelch voltage */
-#define DC_PN_NWAY_POLARITY 0x00000020 /* 0 == on, 1 == off */
-#define DC_PN_NWAY_TP 0x00000040 /* 1 == tp, 0 == AUI */
-#define DC_PN_NWAY_AUIVOLT 0x00000080 /* 1 == full, 0 == half */
-#define DC_PN_NWAY_DUPLEX 0x00000100 /* LED, 1 == full, 0 == half */
-#define DC_PN_NWAY_LINKTEST 0x00000200 /* 0 == on, 1 == off */
-#define DC_PN_NWAY_AUTODETECT 0x00000400 /* 1 == off, 0 == on */
-#define DC_PN_NWAY_SPEEDSEL 0x00000800 /* LED, 0 = 10, 1 == 100 */
-#define DC_PN_NWAY_NWAY_ENB 0x00001000 /* 0 == off, 1 == on */
-#define DC_PN_NWAY_CAP10HDX 0x00002000
-#define DC_PN_NWAY_CAP10FDX 0x00004000
-#define DC_PN_NWAY_CAP100FDX 0x00008000
-#define DC_PN_NWAY_CAP100HDX 0x00010000
-#define DC_PN_NWAY_CAP100T4 0x00020000
-#define DC_PN_NWAY_ANEGRESTART 0x02000000 /* resets when aneg done */
-#define DC_PN_NWAY_REMFAULT 0x04000000
-#define DC_PN_NWAY_LPAR10HDX 0x08000000
-#define DC_PN_NWAY_LPAR10FDX 0x10000000
-#define DC_PN_NWAY_LPAR100FDX 0x20000000
-#define DC_PN_NWAY_LPAR100HDX 0x40000000
-#define DC_PN_NWAY_LPAR100T4 0x80000000
-
-/* End of PNIC specific registers */
-
-/*
- * CONEXANT specific registers.
- */
-
-#define DC_CONEXANT_PHYADDR 0x1
-#define DC_CONEXANT_EE_NODEADDR 0x19A
-
-/* End of CONEXANT specific registers */
-
-
-struct dc_softc {
- struct arpcom arpcom; /* interface info */
- bus_space_handle_t dc_bhandle; /* bus space handle */
- bus_space_tag_t dc_btag; /* bus space tag */
- void *dc_intrhand;
- struct resource *dc_irq;
- struct resource *dc_res;
- struct dc_type *dc_info; /* adapter info */
- device_t dc_miibus;
- u_int8_t dc_unit; /* interface number */
- u_int8_t dc_type;
- u_int8_t dc_pmode;
- u_int8_t dc_link;
- u_int8_t dc_cachesize;
- int dc_romwidth;
- int dc_pnic_rx_bug_save;
- unsigned char *dc_pnic_rx_buf;
- int dc_if_flags;
- int dc_if_media;
- u_int32_t dc_flags;
- u_int32_t dc_txthresh;
- u_int8_t *dc_srom;
- struct dc_mediainfo *dc_mi;
- struct dc_list_data *dc_ldata;
- struct dc_chain_data dc_cdata;
- struct callout dc_stat_ch;
-#ifdef SRM_MEDIA
- int dc_srm_media;
-#endif
- struct mtx dc_mtx;
-#ifdef DEVICE_POLLING
- int rxcycles; /* ... when polling */
-#endif
- int suspended; /* 0 = normal 1 = suspended */
-
- u_int32_t saved_maps[5]; /* pci data */
- u_int32_t saved_biosaddr;
- u_int8_t saved_intline;
- u_int8_t saved_cachelnsz;
- u_int8_t saved_lattimer;
-};
-
-
-#define DC_LOCK(_sc) mtx_lock(&(_sc)->dc_mtx)
-#define DC_UNLOCK(_sc) mtx_unlock(&(_sc)->dc_mtx)
-
-#define DC_TX_POLL 0x00000001
-#define DC_TX_COALESCE 0x00000002
-#define DC_TX_ADMTEK_WAR 0x00000004
-#define DC_TX_USE_TX_INTR 0x00000008
-#define DC_RX_FILTER_TULIP 0x00000010
-#define DC_TX_INTR_FIRSTFRAG 0x00000020
-#define DC_PNIC_RX_BUG_WAR 0x00000040
-#define DC_TX_FIXED_RING 0x00000080
-#define DC_TX_STORENFWD 0x00000100
-#define DC_REDUCED_MII_POLL 0x00000200
-#define DC_TX_INTR_ALWAYS 0x00000400
-#define DC_21143_NWAY 0x00000800
-#define DC_128BIT_HASH 0x00001000
-#define DC_64BIT_HASH 0x00002000
-#define DC_TULIP_LEDS 0x00004000
-#define DC_TX_ONE 0x00008000
-#define DC_TX_ALIGN 0x00010000 /* align mbuf on tx */
-
-/*
- * register space access macros
- */
-#define CSR_WRITE_4(sc, reg, val) \
- bus_space_write_4(sc->dc_btag, sc->dc_bhandle, reg, val)
-
-#define CSR_READ_4(sc, reg) \
- bus_space_read_4(sc->dc_btag, sc->dc_bhandle, reg)
-
-#define DC_TIMEOUT 1000
-#define ETHER_ALIGN 2
-
-/*
- * General constants that are fun to know.
- */
-
-/*
- * DEC PCI vendor ID
- */
-#define DC_VENDORID_DEC 0x1011
-
-/*
- * DEC/Intel 21143 PCI device ID
- */
-#define DC_DEVICEID_21143 0x0019
-
-/*
- * Macronix PCI vendor ID
- */
-#define DC_VENDORID_MX 0x10D9
-
-/*
- * Macronix PMAC device IDs.
- */
-#define DC_DEVICEID_98713 0x0512
-#define DC_DEVICEID_987x5 0x0531
-#define DC_DEVICEID_98727 0x0532
-#define DC_DEVICEID_98732 0x0532
-
-/* Macronix PCI revision codes. */
-#define DC_REVISION_98713 0x00
-#define DC_REVISION_98713A 0x10
-#define DC_REVISION_98715 0x20
-#define DC_REVISION_98715AEC_C 0x25
-#define DC_REVISION_98725 0x30
-
-/*
- * Compex PCI vendor ID.
- */
-#define DC_VENDORID_CP 0x11F6
-
-/*
- * Compex PMAC PCI device IDs.
- */
-#define DC_DEVICEID_98713_CP 0x9881
-
-/*
- * Lite-On PNIC PCI vendor ID
- */
-#define DC_VENDORID_LO 0x11AD
-
-/*
- * 82c168/82c169 PNIC device IDs. Both chips have the same device
- * ID but different revisions. Revision 0x10 is the 82c168, and
- * 0x20 is the 82c169.
- */
-#define DC_DEVICEID_82C168 0x0002
-
-#define DC_REVISION_82C168 0x10
-#define DC_REVISION_82C169 0x20
-
-/*
- * Lite-On PNIC II device ID. Note: this is actually a Macronix 98715A
- * with wake on lan/magic packet support.
- */
-#define DC_DEVICEID_82C115 0xc115
-
-/*
- * Davicom vendor ID.
- */
-#define DC_VENDORID_DAVICOM 0x1282
-
-/*
- * Davicom device IDs.
- */
-#define DC_DEVICEID_DM9009 0x9009
-#define DC_DEVICEID_DM9100 0x9100
-#define DC_DEVICEID_DM9102 0x9102
-
-/*
- * The DM9102A has the same PCI device ID as the DM9102,
- * but a higher revision code.
- */
-#define DC_REVISION_DM9102 0x10
-#define DC_REVISION_DM9102A 0x30
-
-/*
- * ADMtek vendor ID.
- */
-#define DC_VENDORID_ADMTEK 0x1317
-
-/*
- * ADMtek device IDs.
- */
-#define DC_DEVICEID_AL981 0x0981
-#define DC_DEVICEID_AN985 0x0985
-
-/*
- * 3COM PCI vendor ID
- */
-#define DC_VENDORID_3COM 0x10b7
-
-/*
- * 3COM OfficeConnect 10/100B (3CSOHO100B-TX)
- */
-#define DC_DEVICEID_3CSOHOB 0x9300
-
-/*
- * ASIX vendor ID.
- */
-#define DC_VENDORID_ASIX 0x125B
-
-/*
- * ASIX device IDs.
- */
-#define DC_DEVICEID_AX88140A 0x1400
-
-/*
- * The ASIX AX88140 and ASIX AX88141 have the same vendor and
- * device IDs but different revision values.
- */
-#define DC_REVISION_88140 0x00
-#define DC_REVISION_88141 0x10
-
-/*
- * Accton vendor ID.
- */
-#define DC_VENDORID_ACCTON 0x1113
-
-/*
- * Accton device IDs.
- */
-#define DC_DEVICEID_EN1217 0x1217
-#define DC_DEVICEID_EN2242 0x1216
-
-/*
- * Xircom vendor ID
- */
-#define DC_VENDORID_XIRCOM 0x115d
-
-/*
- * Xircom device IDs.
- */
-#define DC_DEVICEID_X3201 0x0003
-
-/*
- * Abocom vendor ID
- */
-#define DC_VENDORID_ABOCOM 0x13d1
-
-/*
- * Abocom device IDs.
- */
-#define DC_DEVICEID_FE2500 0xAB02
-
-/*
- * Conexant vendor ID.
- */
-#define DC_VENDORID_CONEXANT 0x14f1
-
-/*
- * Conexant device IDs.
- */
-#define DC_DEVICEID_RS7112 0x1803
-
-/*
- * Planex vendor ID
- */
-#define DC_VENDORID_PLANEX 0x14ea
-
-/*
- * Planex device IDs.
- */
-#define DC_DEVICEID_FNW3602T 0xab08
-
-/*
- * Not sure who this vendor should be, so we'll go with HAWKING until
- * I can locate the right one.
- */
-#define DC_VENDORID_HAWKING 0x17b3
-
-/*
- * Sure looks like an abocom device ID, but it found on my hawking PN672TX
- * card. Use that for now, and upgrade later.
- */
-#define DC_DEVICEID_HAWKING_PN672TX 0xab08
-
-/*
- * PCI low memory base and low I/O base register, and
- * other PCI registers.
- */
-
-#define DC_PCI_CFID 0x00 /* Id */
-#define DC_PCI_CFCS 0x04 /* Command and status */
-#define DC_PCI_CFRV 0x08 /* Revision */
-#define DC_PCI_CFLT 0x0C /* Latency timer */
-#define DC_PCI_CFBIO 0x10 /* Base I/O address */
-#define DC_PCI_CFBMA 0x14 /* Base memory address */
-#define DC_PCI_CCIS 0x28 /* Card info struct */
-#define DC_PCI_CSID 0x2C /* Subsystem ID */
-#define DC_PCI_CBER 0x30 /* Expansion ROM base address */
-#define DC_PCI_CCAP 0x34 /* Caps pointer - PD/TD chip only */
-#define DC_PCI_CFIT 0x3C /* Interrupt */
-#define DC_PCI_CFDD 0x40 /* Device and driver area */
-#define DC_PCI_CWUA0 0x44 /* Wake-Up LAN addr 0 */
-#define DC_PCI_CWUA1 0x48 /* Wake-Up LAN addr 1 */
-#define DC_PCI_SOP0 0x4C /* SecureON passwd 0 */
-#define DC_PCI_SOP1 0x50 /* SecureON passwd 1 */
-#define DC_PCI_CWUC 0x54 /* Configuration Wake-Up cmd */
-#define DC_PCI_CCID 0xDC /* Capability ID - PD/TD only */
-#define DC_PCI_CPMC 0xE0 /* Pwrmgmt ctl & sts - PD/TD only */
-
-/* PCI ID register */
-#define DC_CFID_VENDOR 0x0000FFFF
-#define DC_CFID_DEVICE 0xFFFF0000
-
-/* PCI command/status register */
-#define DC_CFCS_IOSPACE 0x00000001 /* I/O space enable */
-#define DC_CFCS_MEMSPACE 0x00000002 /* memory space enable */
-#define DC_CFCS_BUSMASTER 0x00000004 /* bus master enable */
-#define DC_CFCS_MWI_ENB 0x00000010 /* mem write and inval enable */
-#define DC_CFCS_PARITYERR_ENB 0x00000040 /* parity error enable */
-#define DC_CFCS_SYSERR_ENB 0x00000100 /* system error enable */
-#define DC_CFCS_NEWCAPS 0x00100000 /* new capabilities */
-#define DC_CFCS_FAST_B2B 0x00800000 /* fast back-to-back capable */
-#define DC_CFCS_DATAPARITY 0x01000000 /* Parity error report */
-#define DC_CFCS_DEVSELTIM 0x06000000 /* devsel timing */
-#define DC_CFCS_TGTABRT 0x10000000 /* received target abort */
-#define DC_CFCS_MASTERABRT 0x20000000 /* received master abort */
-#define DC_CFCS_SYSERR 0x40000000 /* asserted system error */
-#define DC_CFCS_PARITYERR 0x80000000 /* asserted parity error */
-
-/* PCI revision register */
-#define DC_CFRV_STEPPING 0x0000000F
-#define DC_CFRV_REVISION 0x000000F0
-#define DC_CFRV_SUBCLASS 0x00FF0000
-#define DC_CFRV_BASECLASS 0xFF000000
-
-#define DC_21143_PB_REV 0x00000030
-#define DC_21143_TB_REV 0x00000030
-#define DC_21143_PC_REV 0x00000030
-#define DC_21143_TC_REV 0x00000030
-#define DC_21143_PD_REV 0x00000041
-#define DC_21143_TD_REV 0x00000041
-
-/* PCI latency timer register */
-#define DC_CFLT_CACHELINESIZE 0x000000FF
-#define DC_CFLT_LATENCYTIMER 0x0000FF00
-
-/* PCI subsystem ID register */
-#define DC_CSID_VENDOR 0x0000FFFF
-#define DC_CSID_DEVICE 0xFFFF0000
-
-/* PCI cababilities pointer */
-#define DC_CCAP_OFFSET 0x000000FF
-
-/* PCI interrupt config register */
-#define DC_CFIT_INTLINE 0x000000FF
-#define DC_CFIT_INTPIN 0x0000FF00
-#define DC_CFIT_MIN_GNT 0x00FF0000
-#define DC_CFIT_MAX_LAT 0xFF000000
-
-/* PCI capability register */
-#define DC_CCID_CAPID 0x000000FF
-#define DC_CCID_NEXTPTR 0x0000FF00
-#define DC_CCID_PM_VERS 0x00070000
-#define DC_CCID_PME_CLK 0x00080000
-#define DC_CCID_DVSPEC_INT 0x00200000
-#define DC_CCID_STATE_D1 0x02000000
-#define DC_CCID_STATE_D2 0x04000000
-#define DC_CCID_PME_D0 0x08000000
-#define DC_CCID_PME_D1 0x10000000
-#define DC_CCID_PME_D2 0x20000000
-#define DC_CCID_PME_D3HOT 0x40000000
-#define DC_CCID_PME_D3COLD 0x80000000
-
-/* PCI power management control/status register */
-#define DC_CPMC_STATE 0x00000003
-#define DC_CPMC_PME_ENB 0x00000100
-#define DC_CPMC_PME_STS 0x00008000
-
-#define DC_PSTATE_D0 0x0
-#define DC_PSTATE_D1 0x1
-#define DC_PSTATE_D2 0x2
-#define DC_PSTATE_D3 0x3
-
-/* Device specific region */
-/* Configuration and driver area */
-#define DC_CFDD_DRVUSE 0x0000FFFF
-#define DC_CFDD_SNOOZE_MODE 0x40000000
-#define DC_CFDD_SLEEP_MODE 0x80000000
-
-/* Configuration wake-up command register */
-#define DC_CWUC_MUST_BE_ZERO 0x00000001
-#define DC_CWUC_SECUREON_ENB 0x00000002
-#define DC_CWUC_FORCE_WUL 0x00000004
-#define DC_CWUC_BNC_ABILITY 0x00000008
-#define DC_CWUC_AUI_ABILITY 0x00000010
-#define DC_CWUC_TP10_ABILITY 0x00000020
-#define DC_CWUC_MII_ABILITY 0x00000040
-#define DC_CWUC_SYM_ABILITY 0x00000080
-#define DC_CWUC_LOCK 0x00000100
-
-/*
- * SROM nonsense.
- */
-
-#define DC_IB_CTLRCNT 0x13
-#define DC_IB_LEAF0_CNUM 0x1A
-#define DC_IB_LEAF0_OFFSET 0x1B
-
-struct dc_info_leaf {
- u_int16_t dc_conntype;
- u_int8_t dc_blkcnt;
- u_int8_t dc_rsvd;
- u_int16_t dc_infoblk;
-};
-
-#define DC_CTYPE_10BT 0x0000
-#define DC_CTYPE_10BT_NWAY 0x0100
-#define DC_CTYPE_10BT_FDX 0x0204
-#define DC_CTYPE_10B2 0x0001
-#define DC_CTYPE_10B5 0x0002
-#define DC_CTYPE_100BT 0x0003
-#define DC_CTYPE_100BT_FDX 0x0205
-#define DC_CTYPE_100T4 0x0006
-#define DC_CTYPE_100FX 0x0007
-#define DC_CTYPE_100FX_FDX 0x0208
-#define DC_CTYPE_MII_10BT 0x0009
-#define DC_CTYPE_MII_10BT_FDX 0x020A
-#define DC_CTYPE_MII_100BT 0x000D
-#define DC_CTYPE_MII_100BT_FDX 0x020E
-#define DC_CTYPE_MII_100T4 0x000F
-#define DC_CTYPE_MII_100FX 0x0010
-#define DC_CTYPE_MII_100FX_FDX 0x0211
-#define DC_CTYPE_DYN_PUP_AUTOSENSE 0x0800
-#define DC_CTYPE_PUP_AUTOSENSE 0x8800
-#define DC_CTYPE_NOMEDIA 0xFFFF
-
-#define DC_EBLOCK_SIA 0x0002
-#define DC_EBLOCK_MII 0x0003
-#define DC_EBLOCK_SYM 0x0004
-#define DC_EBLOCK_RESET 0x0005
-#define DC_EBLOCK_PHY_SHUTDOWN 0x0006
-
-struct dc_leaf_hdr {
- u_int16_t dc_mtype;
- u_int8_t dc_mcnt;
- u_int8_t dc_rsvd;
-};
-
-struct dc_eblock_hdr {
- u_int8_t dc_len;
- u_int8_t dc_type;
-};
-
-struct dc_eblock_sia {
- struct dc_eblock_hdr dc_sia_hdr;
- u_int8_t dc_sia_code;
- u_int8_t dc_sia_mediaspec[6]; /* CSR13, CSR14, CSR15 */
- u_int8_t dc_sia_gpio_ctl[2];
- u_int8_t dc_sia_gpio_dat[2];
-};
-
-#define DC_SIA_CODE_10BT 0x00
-#define DC_SIA_CODE_10B2 0x01
-#define DC_SIA_CODE_10B5 0x02
-#define DC_SIA_CODE_10BT_FDX 0x04
-#define DC_SIA_CODE_EXT 0x40
-
-/*
- * Note that the first word in the gpr and reset
- * sequences is always a control word.
- */
-struct dc_eblock_mii {
- struct dc_eblock_hdr dc_mii_hdr;
- u_int8_t dc_mii_phynum;
- u_int8_t dc_gpr_len;
-/* u_int16_t dc_gpr_dat[n]; */
-/* u_int8_t dc_reset_len; */
-/* u_int16_t dc_reset_dat[n]; */
-/* There are other fields after these, but we don't
- * care about them since they can be determined by looking
- * at the PHY.
- */
-};
-
-struct dc_eblock_sym {
- struct dc_eblock_hdr dc_sym_hdr;
- u_int8_t dc_sym_code;
- u_int8_t dc_sym_gpio_ctl[2];
- u_int8_t dc_sym_gpio_dat[2];
- u_int8_t dc_sym_cmd[2];
-};
-
-#define DC_SYM_CODE_100BT 0x03
-#define DC_SYM_CODE_100BT_FDX 0x05
-#define DC_SYM_CODE_100T4 0x06
-#define DC_SYM_CODE_100FX 0x07
-#define DC_SYM_CODE_100FX_FDX 0x08
-
-struct dc_eblock_reset {
- struct dc_eblock_hdr dc_reset_hdr;
- u_int8_t dc_reset_len;
-/* u_int16_t dc_reset_dat[n]; */
-};
-
-#ifdef __alpha__
-#undef vtophys
-#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)va)
-#endif
diff --git a/sys/dev/dc/pnphy.c b/sys/dev/dc/pnphy.c
deleted file mode 100644
index e8022edb2d7a..000000000000
--- a/sys/dev/dc/pnphy.c
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- * Copyright (c) 1997, 1998, 1999
- * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Pseudo-driver for media selection on the Lite-On PNIC 82c168
- * chip. The NWAY support on this chip is horribly broken, so we
- * only support manual mode selection. This is lame, but getting
- * NWAY to work right is amazingly difficult.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/socket.h>
-#include <sys/errno.h>
-#include <sys/lock.h>
-#include <sys/module.h>
-#include <sys/mutex.h>
-#include <sys/bus.h>
-
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/if_media.h>
-
-#include <dev/mii/mii.h>
-#include <dev/mii/miivar.h>
-#include "miidevs.h"
-
-#include <machine/bus_pio.h>
-#include <machine/bus_memio.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/bus.h>
-
-#include <pci/if_dcreg.h>
-
-#include "miibus_if.h"
-
-#define DC_SETBIT(sc, reg, x) \
- CSR_WRITE_4(sc, reg, \
- CSR_READ_4(sc, reg) | x)
-
-#define DC_CLRBIT(sc, reg, x) \
- CSR_WRITE_4(sc, reg, \
- CSR_READ_4(sc, reg) & ~x)
-
-static int pnphy_probe(device_t);
-static int pnphy_attach(device_t);
-
-static device_method_t pnphy_methods[] = {
- /* device interface */
- DEVMETHOD(device_probe, pnphy_probe),
- DEVMETHOD(device_attach, pnphy_attach),
- DEVMETHOD(device_detach, mii_phy_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- { 0, 0 }
-};
-
-static devclass_t pnphy_devclass;
-
-static driver_t pnphy_driver = {
- "pnphy",
- pnphy_methods,
- sizeof(struct mii_softc)
-};
-
-DRIVER_MODULE(pnphy, miibus, pnphy_driver, pnphy_devclass, 0, 0);
-
-static int pnphy_service(struct mii_softc *, struct mii_data *, int);
-static void pnphy_status(struct mii_softc *);
-
-static int
-pnphy_probe(dev)
- device_t dev;
-{
- struct mii_attach_args *ma;
-
- ma = device_get_ivars(dev);
-
- /*
- * The dc driver will report the 82c168 vendor and device
- * ID to let us know that it wants us to attach.
- */
- if (ma->mii_id1 != DC_VENDORID_LO ||
- ma->mii_id2 != DC_DEVICEID_82C168)
- return(ENXIO);
-
- device_set_desc(dev, "PNIC 82c168 media interface");
-
- return (0);
-}
-
-static int
-pnphy_attach(dev)
- device_t dev;
-{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = device_get_softc(sc->mii_dev);
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_inst = mii->mii_instance;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = pnphy_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOISOLATE;
- mii->mii_instance++;
-
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
-
- sc->mii_capabilities =
- BMSR_100TXFDX|BMSR_100TXHDX|BMSR_10TFDX|BMSR_10THDX;
- sc->mii_capabilities &= ma->mii_capmask;
- device_printf(dev, " ");
- mii_add_media(sc);
- printf("\n");
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst),
- BMCR_ISO);
-
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst),
- BMCR_LOOP|BMCR_S100);
-
-#undef ADD
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
- return(0);
-}
-
-static int
-pnphy_service(sc, mii, cmd)
- struct mii_softc *sc;
- struct mii_data *mii;
- int cmd;
-{
- struct dc_softc *dc_sc;
- struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
-
- dc_sc = mii->mii_ifp->if_softc;
-
- switch (cmd) {
- case MII_POLLSTAT:
- /*
- * If we're not polling our PHY instance, just return.
- */
- if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
- return (0);
- }
- break;
-
- case MII_MEDIACHG:
- /*
- * If the media indicates a different PHY instance,
- * isolate ourselves.
- */
- if (IFM_INST(ife->ifm_media) != sc->mii_inst)
- return (0);
-
- /*
- * If the interface is not up, don't do anything.
- */
- if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
- break;
-
- sc->mii_flags = 0;
-
- switch (IFM_SUBTYPE(ife->ifm_media)) {
- case IFM_AUTO:
- /* NWAY is busted on this chip */
- case IFM_100_T4:
- /*
- * XXX Not supported as a manual setting right now.
- */
- return (EINVAL);
- case IFM_100_TX:
- mii->mii_media_active = IFM_ETHER|IFM_100_TX;
- if ((ife->ifm_media & IFM_GMASK) == IFM_FDX)
- mii->mii_media_active |= IFM_FDX;
- MIIBUS_STATCHG(sc->mii_dev);
- return(0);
- break;
- case IFM_10_T:
- mii->mii_media_active = IFM_ETHER|IFM_10_T;
- if ((ife->ifm_media & IFM_GMASK) == IFM_FDX)
- mii->mii_media_active |= IFM_FDX;
- MIIBUS_STATCHG(sc->mii_dev);
- return(0);
- break;
- default:
- return(EINVAL);
- break;
- }
- break;
-
- case MII_TICK:
- /*
- * If we're not currently selected, just return.
- */
- if (IFM_INST(ife->ifm_media) != sc->mii_inst)
- return (0);
-
- /*
- * Is the interface even up?
- */
- if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
- return (0);
-
- break;
- }
-
- /* Update the media status. */
- pnphy_status(sc);
-
- /* Callback if something changed. */
- mii_phy_update(sc, cmd);
- return (0);
-}
-
-static void
-pnphy_status(sc)
- struct mii_softc *sc;
-{
- struct mii_data *mii = sc->mii_pdata;
- int reg;
- struct dc_softc *dc_sc;
-
- dc_sc = mii->mii_ifp->if_softc;
-
- mii->mii_media_status = IFM_AVALID;
- mii->mii_media_active = IFM_ETHER;
-
- reg = CSR_READ_4(dc_sc, DC_ISR);
-
- if (!(reg & DC_ISR_LINKFAIL))
- mii->mii_media_status |= IFM_ACTIVE;
-
- if (CSR_READ_4(dc_sc, DC_NETCFG) & DC_NETCFG_SPEEDSEL)
- mii->mii_media_active |= IFM_10_T;
- else
- mii->mii_media_active |= IFM_100_TX;
- if (CSR_READ_4(dc_sc, DC_NETCFG) & DC_NETCFG_FULLDUPLEX)
- mii->mii_media_active |= IFM_FDX;
-
- return;
-}
diff --git a/sys/dev/de/dc21040reg.h b/sys/dev/de/dc21040reg.h
deleted file mode 100644
index c0ff1916578f..000000000000
--- a/sys/dev/de/dc21040reg.h
+++ /dev/null
@@ -1,583 +0,0 @@
-/* $NetBSD: dc21040reg.h,v 1.15 1998/05/22 18:50:59 matt Exp $ */
-
-/* $FreeBSD$ */
-
-/*-
- * Copyright (c) 1994, 1995, 1996 Matt Thomas <matt@3am-software.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED 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.
- *
- * Id: dc21040reg.h,v 1.24 1997/05/16 19:47:09 thomas Exp
- */
-
-#if !defined(_DC21040_H)
-#define _DC21040_H
-
-#if defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN
-#define TULIP_BITFIELD2(a, b) b, a
-#define TULIP_BITFIELD3(a, b, c) c, b, a
-#define TULIP_BITFIELD4(a, b, c, d) d, c, b, a
-#else
-#define TULIP_BITFIELD2(a, b) a, b
-#define TULIP_BITFIELD3(a, b, c) a, b, c
-#define TULIP_BITFIELD4(a, b, c, d) a, b, c, d
-#endif
-
-typedef struct {
- u_int32_t d_status;
- u_int32_t TULIP_BITFIELD3(d_length1 : 11,
- d_length2 : 11,
- d_flag : 10);
- u_int32_t d_addr1;
- u_int32_t d_addr2;
-} tulip_desc_t;
-
-#define TULIP_DSTS_OWNER 0x80000000 /* Owner (1 = 21040) */
-#define TULIP_DSTS_ERRSUM 0x00008000 /* Error Summary */
-/*
- * Transmit Status
- */
-#define TULIP_DSTS_TxBABBLE 0x00004000 /* Transmitter Babbled */
-#define TULIP_DSTS_TxCARRLOSS 0x00000800 /* Carrier Loss */
-#define TULIP_DSTS_TxNOCARR 0x00000400 /* No Carrier */
-#define TULIP_DSTS_TxLATECOLL 0x00000200 /* Late Collision */
-#define TULIP_DSTS_TxEXCCOLL 0x00000100 /* Excessive Collisions */
-#define TULIP_DSTS_TxNOHRTBT 0x00000080 /* No Heartbeat */
-#define TULIP_DSTS_TxCOLLMASK 0x00000078 /* Collision Count (mask) */
-#define TULIP_DSTS_V_TxCOLLCNT 0x00000003 /* Collision Count (bit) */
-#define TULIP_DSTS_TxLINKFAIL 0x00000004 /* Link Failure */
-#define TULIP_DSTS_TxUNDERFLOW 0x00000002 /* Underflow Error */
-#define TULIP_DSTS_TxDEFERRED 0x00000001 /* Initially Deferred */
-/*
- * Receive Status
- */
-#define TULIP_DSTS_RxBADLENGTH 0x00004000 /* Length Error */
-#define TULIP_DSTS_RxDATATYPE 0x00003000 /* Data Type */
-#define TULIP_DSTS_RxRUNT 0x00000800 /* Runt Frame */
-#define TULIP_DSTS_RxMULTICAST 0x00000400 /* Multicast Frame */
-#define TULIP_DSTS_RxFIRSTDESC 0x00000200 /* First Descriptor */
-#define TULIP_DSTS_RxLASTDESC 0x00000100 /* Last Descriptor */
-#define TULIP_DSTS_RxTOOLONG 0x00000080 /* Frame Too Long */
-#define TULIP_DSTS_RxCOLLSEEN 0x00000040 /* Collision Seen */
-#define TULIP_DSTS_RxFRAMETYPE 0x00000020 /* Frame Type */
-#define TULIP_DSTS_RxWATCHDOG 0x00000010 /* Receive Watchdog */
-#define TULIP_DSTS_RxDRBBLBIT 0x00000004 /* Dribble Bit */
-#define TULIP_DSTS_RxBADCRC 0x00000002 /* CRC Error */
-#define TULIP_DSTS_RxOVERFLOW 0x00000001 /* Overflow */
-
-
-#define TULIP_DFLAG_ENDRING 0x0008 /* End of Transmit Ring */
-#define TULIP_DFLAG_CHAIN 0x0004 /* Chain using d_addr2 */
-
-#define TULIP_DFLAG_TxWANTINTR 0x0200 /* Signal Interrupt on Completion */
-#define TULIP_DFLAG_TxLASTSEG 0x0100 /* Last Segment */
-#define TULIP_DFLAG_TxFIRSTSEG 0x0080 /* First Segment */
-#define TULIP_DFLAG_TxINVRSFILT 0x0040 /* Inverse Filtering */
-#define TULIP_DFLAG_TxSETUPPKT 0x0020 /* Setup Packet */
-#define TULIP_DFLAG_TxHASCRC 0x0010 /* Don't Append the CRC */
-#define TULIP_DFLAG_TxNOPADDING 0x0002 /* Don't AutoPad */
-#define TULIP_DFLAG_TxHASHFILT 0x0001 /* Hash/Perfect Filtering */
-
-/*
- * The 21040 Registers (IO Space Addresses)
- */
-#define TULIP_REG_BUSMODE 0x00 /* CSR0 -- Bus Mode */
-#define TULIP_REG_TXPOLL 0x08 /* CSR1 -- Transmit Poll Demand */
-#define TULIP_REG_RXPOLL 0x10 /* CSR2 -- Receive Poll Demand */
-#define TULIP_REG_RXLIST 0x18 /* CSR3 -- Receive List Base Addr */
-#define TULIP_REG_TXLIST 0x20 /* CSR4 -- Transmit List Base Addr */
-#define TULIP_REG_STATUS 0x28 /* CSR5 -- Status */
-#define TULIP_REG_CMD 0x30 /* CSR6 -- Command */
-#define TULIP_REG_INTR 0x38 /* CSR7 -- Interrupt Control */
-#define TULIP_REG_MISSES 0x40 /* CSR8 -- Missed Frame Counter */
-#define TULIP_REG_ADDRROM 0x48 /* CSR9 -- ENET ROM Register */
-#define TULIP_REG_RSRVD 0x50 /* CSR10 -- Reserved */
-#define TULIP_REG_FULL_DUPLEX 0x58 /* CSR11 -- Full Duplex */
-#define TULIP_REG_SIA_STATUS 0x60 /* CSR12 -- SIA Status */
-#define TULIP_REG_SIA_CONN 0x68 /* CSR13 -- SIA Connectivity */
-#define TULIP_REG_SIA_TXRX 0x70 /* CSR14 -- SIA Tx Rx */
-#define TULIP_REG_SIA_GEN 0x78 /* CSR15 -- SIA General */
-
-/*
- * CSR5 -- Status Register
- * CSR7 -- Interrupt Control
- */
-#define TULIP_STS_ERRORMASK 0x03800000L /* ( R) Error Bits (Valid when SYSERROR is set) */
-#define TULIP_STS_ERR_PARITY 0x00000000L /* 000 - Parity Error (Perform Reset) */
-#define TULIP_STS_ERR_MASTER 0x00800000L /* 001 - Master Abort */
-#define TULIP_STS_ERR_TARGET 0x01000000L /* 010 - Target Abort */
-#define TULIP_STS_ERR_SHIFT 23
-#define TULIP_STS_TXSTATEMASK 0x00700000L /* ( R) Transmission Process State */
-#define TULIP_STS_TXS_RESET 0x00000000L /* 000 - Rset or transmit jabber expired */
-#define TULIP_STS_TXS_FETCH 0x00100000L /* 001 - Fetching transmit descriptor */
-#define TULIP_STS_TXS_WAITEND 0x00200000L /* 010 - Wait for end of transmission */
-#define TULIP_STS_TXS_READING 0x00300000L /* 011 - Read buffer and enqueue data */
-#define TULIP_STS_TXS_RSRVD 0x00400000L /* 100 - Reserved */
-#define TULIP_STS_TXS_SETUP 0x00500000L /* 101 - Setup Packet */
-#define TULIP_STS_TXS_SUSPEND 0x00600000L /* 110 - Transmit FIFO underflow or an
- unavailable transmit descriptor */
-#define TULIP_STS_TXS_CLOSE 0x00700000L /* 111 - Close transmit descriptor */
-#define TULIP_STS_RXSTATEMASK 0x000E0000L /* ( R) Receive Process State*/
-#define TULIP_STS_RXS_STOPPED 0x00000000L /* 000 - Stopped */
-#define TULIP_STS_RXS_FETCH 0x00020000L /* 001 - Running -- Fetch receive descriptor */
-#define TULIP_STS_RXS_ENDCHECK 0x00040000L /* 010 - Running -- Check for end of receive
- packet before prefetch of next descriptor */
-#define TULIP_STS_RXS_WAIT 0x00060000L /* 011 - Running -- Wait for receive packet */
-#define TULIP_STS_RXS_SUSPEND 0x00080000L /* 100 - Suspended -- As a result of
- unavailable receive buffers */
-#define TULIP_STS_RXS_CLOSE 0x000A0000L /* 101 - Running -- Close receive descriptor */
-#define TULIP_STS_RXS_FLUSH 0x000C0000L /* 110 - Running -- Flush the current frame
- from the receive FIFO as a result of
- an unavailable receive buffer */
-#define TULIP_STS_RXS_DEQUEUE 0x000E0000L /* 111 - Running -- Dequeue the receive frame
- from the receive FIFO into the receive
- buffer. */
-#define TULIP_STS_NORMALINTR 0x00010000L /* (RW) Normal Interrupt */
-#define TULIP_STS_ABNRMLINTR 0x00008000L /* (RW) Abnormal Interrupt */
-#define TULIP_STS_SYSERROR 0x00002000L /* (RW) System Error */
-#define TULIP_STS_LINKFAIL 0x00001000L /* (RW) Link Failure (21040) */
-#define TULIP_STS_FULDPLXSHRT 0x00000800L /* (RW) Full Duplex Short Fram Rcvd (21040) */
-#define TULIP_STS_GPTIMEOUT 0x00000800L /* (RW) General Purpose Timeout (21140) */
-#define TULIP_STS_AUI 0x00000400L /* (RW) AUI/TP Switch (21040) */
-#define TULIP_STS_RXTIMEOUT 0x00000200L /* (RW) Receive Watchbog Timeout */
-#define TULIP_STS_RXSTOPPED 0x00000100L /* (RW) Receive Process Stopped */
-#define TULIP_STS_RXNOBUF 0x00000080L /* (RW) Receive Buffer Unavailable */
-#define TULIP_STS_RXINTR 0x00000040L /* (RW) Receive Interrupt */
-#define TULIP_STS_TXUNDERFLOW 0x00000020L /* (RW) Transmit Underflow */
-#define TULIP_STS_LINKPASS 0x00000010L /* (RW) LinkPass (21041) */
-#define TULIP_STS_TXBABBLE 0x00000008L /* (RW) Transmit Jabber Timeout */
-#define TULIP_STS_TXNOBUF 0x00000004L /* (RW) Transmit Buffer Unavailable */
-#define TULIP_STS_TXSTOPPED 0x00000002L /* (RW) Transmit Process Stopped */
-#define TULIP_STS_TXINTR 0x00000001L /* (RW) Transmit Interrupt */
-
-/*
- * CSR6 -- Command (Operation Mode) Register
- */
-#define TULIP_CMD_MUSTBEONE 0x02000000L /* (RW) Must Be One (21140) */
-#define TULIP_CMD_SCRAMBLER 0x01000000L /* (RW) Scrambler Mode (21140) */
-#define TULIP_CMD_PCSFUNCTION 0x00800000L /* (RW) PCS Function (21140) */
-#define TULIP_CMD_TXTHRSHLDCTL 0x00400000L /* (RW) Transmit Threshold Mode (21140) */
-#define TULIP_CMD_STOREFWD 0x00200000L /* (RW) Store and Foward (21140) */
-#define TULIP_CMD_NOHEARTBEAT 0x00080000L /* (RW) No Heartbeat (21140) */
-#define TULIP_CMD_PORTSELECT 0x00040000L /* (RW) Post Select (100Mb) (21140) */
-#define TULIP_CMD_ENHCAPTEFFCT 0x00040000L /* (RW) Enhanced Capture Effecty (21041) */
-#define TULIP_CMD_CAPTREFFCT 0x00020000L /* (RW) Capture Effect (!802.3) */
-#define TULIP_CMD_BACKPRESSURE 0x00010000L /* (RW) Back Pressure (!802.3) (21040) */
-#define TULIP_CMD_THRESHOLDCTL 0x0000C000L /* (RW) Threshold Control */
-#define TULIP_CMD_THRSHLD72 0x00000000L /* 00 - 72 Bytes */
-#define TULIP_CMD_THRSHLD96 0x00004000L /* 01 - 96 Bytes */
-#define TULIP_CMD_THRSHLD128 0x00008000L /* 10 - 128 bytes */
-#define TULIP_CMD_THRSHLD160 0x0000C000L /* 11 - 160 Bytes */
-#define TULIP_CMD_TXRUN 0x00002000L /* (RW) Start/Stop Transmitter */
-#define TULIP_CMD_FORCECOLL 0x00001000L /* (RW) Force Collisions */
-#define TULIP_CMD_OPERMODE 0x00000C00L /* (RW) Operating Mode */
-#define TULIP_CMD_FULLDUPLEX 0x00000200L /* (RW) Full Duplex Mode */
-#define TULIP_CMD_FLAKYOSCDIS 0x00000100L /* (RW) Flakey Oscillator Disable */
-#define TULIP_CMD_ALLMULTI 0x00000080L /* (RW) Pass All Multicasts */
-#define TULIP_CMD_PROMISCUOUS 0x00000040L /* (RW) Promiscuous Mode */
-#define TULIP_CMD_BACKOFFCTR 0x00000020L /* (RW) Start/Stop Backoff Counter (!802.3) */
-#define TULIP_CMD_INVFILTER 0x00000010L /* (R ) Inverse Filtering */
-#define TULIP_CMD_PASSBADPKT 0x00000008L /* (RW) Pass Bad Frames */
-#define TULIP_CMD_HASHONLYFLTR 0x00000004L /* (R ) Hash Only Filtering */
-#define TULIP_CMD_RXRUN 0x00000002L /* (RW) Start/Stop Receive Filtering */
-#define TULIP_CMD_HASHPRFCTFLTR 0x00000001L /* (R ) Hash/Perfect Receive Filtering */
-
-#define TULIP_SIASTS_OTHERRXACTIVITY 0x00000200L
-#define TULIP_SIASTS_RXACTIVITY 0x00000100L
-#define TULIP_SIASTS_LINKFAIL 0x00000004L
-#define TULIP_SIASTS_LINK100FAIL 0x00000002L
-#define TULIP_SIACONN_RESET 0x00000000L
-
-/*
- * 21040 SIA definitions
- */
-#define TULIP_21040_PROBE_10BASET_TIMEOUT 2500
-#define TULIP_21040_PROBE_AUIBNC_TIMEOUT 300
-#define TULIP_21040_PROBE_EXTSIA_TIMEOUT 300
-
-#define TULIP_21040_SIACONN_10BASET 0x0000EF01L
-#define TULIP_21040_SIATXRX_10BASET 0x0000FFFFL
-#define TULIP_21040_SIAGEN_10BASET 0x00000000L
-
-#define TULIP_21040_SIACONN_10BASET_FD 0x0000EF01L
-#define TULIP_21040_SIATXRX_10BASET_FD 0x0000FFFDL
-#define TULIP_21040_SIAGEN_10BASET_FD 0x00000000L
-
-#define TULIP_21040_SIACONN_AUIBNC 0x0000EF09L
-#define TULIP_21040_SIATXRX_AUIBNC 0x00000705L
-#define TULIP_21040_SIAGEN_AUIBNC 0x00000006L
-
-#define TULIP_21040_SIACONN_EXTSIA 0x00003041L
-#define TULIP_21040_SIATXRX_EXTSIA 0x00000000L
-#define TULIP_21040_SIAGEN_EXTSIA 0x00000006L
-
-/*
- * 21041 SIA definitions
- */
-
-#define TULIP_21041_PROBE_10BASET_TIMEOUT 2500
-#define TULIP_21041_PROBE_AUIBNC_TIMEOUT 300
-
-#define TULIP_21041_SIACONN_10BASET 0x0000EF01L
-#define TULIP_21041_SIATXRX_10BASET 0x0000FF3FL
-#define TULIP_21041_SIAGEN_10BASET 0x00000000L
-
-#define TULIP_21041P2_SIACONN_10BASET 0x0000EF01L
-#define TULIP_21041P2_SIATXRX_10BASET 0x0000FFFFL
-#define TULIP_21041P2_SIAGEN_10BASET 0x00000000L
-
-#define TULIP_21041_SIACONN_10BASET_FD 0x0000EF01L
-#define TULIP_21041_SIATXRX_10BASET_FD 0x0000FF3DL
-#define TULIP_21041_SIAGEN_10BASET_FD 0x00000000L
-
-#define TULIP_21041P2_SIACONN_10BASET_FD 0x0000EF01L
-#define TULIP_21041P2_SIATXRX_10BASET_FD 0x0000FFFFL
-#define TULIP_21041P2_SIAGEN_10BASET_FD 0x00000000L
-
-#define TULIP_21041_SIACONN_AUI 0x0000EF09L
-#define TULIP_21041_SIATXRX_AUI 0x0000F73DL
-#define TULIP_21041_SIAGEN_AUI 0x0000000EL
-
-#define TULIP_21041P2_SIACONN_AUI 0x0000EF09L
-#define TULIP_21041P2_SIATXRX_AUI 0x0000F7FDL
-#define TULIP_21041P2_SIAGEN_AUI 0x0000000EL
-
-#define TULIP_21041_SIACONN_BNC 0x0000EF09L
-#define TULIP_21041_SIATXRX_BNC 0x0000F73DL
-#define TULIP_21041_SIAGEN_BNC 0x00000006L
-
-#define TULIP_21041P2_SIACONN_BNC 0x0000EF09L
-#define TULIP_21041P2_SIATXRX_BNC 0x0000F7FDL
-#define TULIP_21041P2_SIAGEN_BNC 0x00000006L
-
-/*
- * 21142 SIA definitions
- */
-
-#define TULIP_21142_PROBE_10BASET_TIMEOUT 2500
-#define TULIP_21142_PROBE_AUIBNC_TIMEOUT 300
-
-#define TULIP_21142_SIACONN_10BASET 0x00000001L
-#define TULIP_21142_SIATXRX_10BASET 0x00007F3FL
-#define TULIP_21142_SIAGEN_10BASET 0x00000008L
-
-#define TULIP_21142_SIACONN_10BASET_FD 0x00000001L
-#define TULIP_21142_SIATXRX_10BASET_FD 0x00007F3DL
-#define TULIP_21142_SIAGEN_10BASET_FD 0x00000008L
-
-#define TULIP_21142_SIACONN_AUI 0x00000009L
-#define TULIP_21142_SIATXRX_AUI 0x00000705L
-#define TULIP_21142_SIAGEN_AUI 0x0000000EL
-
-#define TULIP_21142_SIACONN_BNC 0x00000009L
-#define TULIP_21142_SIATXRX_BNC 0x00000705L
-#define TULIP_21142_SIAGEN_BNC 0x00000006L
-
-
-
-
-#define TULIP_WATCHDOG_TXDISABLE 0x00000001L
-#define TULIP_WATCHDOG_RXDISABLE 0x00000010L
-
-#define TULIP_BUSMODE_SWRESET 0x00000001L
-#define TULIP_BUSMODE_DESCSKIPLEN_MASK 0x0000007CL
-#define TULIP_BUSMODE_BIGENDIAN 0x00000080L
-#define TULIP_BUSMODE_BURSTLEN_MASK 0x00003F00L
-#define TULIP_BUSMODE_BURSTLEN_DEFAULT 0x00000000L
-#define TULIP_BUSMODE_BURSTLEN_1LW 0x00000100L
-#define TULIP_BUSMODE_BURSTLEN_2LW 0x00000200L
-#define TULIP_BUSMODE_BURSTLEN_4LW 0x00000400L
-#define TULIP_BUSMODE_BURSTLEN_8LW 0x00000800L
-#define TULIP_BUSMODE_BURSTLEN_16LW 0x00001000L
-#define TULIP_BUSMODE_BURSTLEN_32LW 0x00002000L
-#define TULIP_BUSMODE_CACHE_NOALIGN 0x00000000L
-#define TULIP_BUSMODE_CACHE_ALIGN8 0x00004000L
-#define TULIP_BUSMODE_CACHE_ALIGN16 0x00008000L
-#define TULIP_BUSMODE_CACHE_ALIGN32 0x0000C000L
-#define TULIP_BUSMODE_TXPOLL_NEVER 0x00000000L
-#define TULIP_BUSMODE_TXPOLL_200000ns 0x00020000L
-#define TULIP_BUSMODE_TXPOLL_800000ns 0x00040000L
-#define TULIP_BUSMODE_TXPOLL_1600000ns 0x00060000L
-#define TULIP_BUSMODE_TXPOLL_12800ns 0x00080000L /* 21041 only */
-#define TULIP_BUSMODE_TXPOLL_25600ns 0x000A0000L /* 21041 only */
-#define TULIP_BUSMODE_TXPOLL_51200ns 0x000C0000L /* 21041 only */
-#define TULIP_BUSMODE_TXPOLL_102400ns 0x000E0000L /* 21041 only */
-#define TULIP_BUSMODE_DESC_BIGENDIAN 0x00100000L /* 21041 only */
-#define TULIP_BUSMODE_READMULTIPLE 0x00200000L /* */
-
-#define TULIP_REG_CFDA 0x40
-#define TULIP_CFDA_SLEEP 0x80000000L
-#define TULIP_CFDA_SNOOZE 0x40000000L
-
-#define TULIP_GP_PINSET 0x00000100L
-/*
- * These are the defintitions used for the DEC 21140
- * evaluation board.
- */
-#define TULIP_GP_EB_PINS 0x0000001F /* General Purpose Pin directions */
-#define TULIP_GP_EB_OK10 0x00000080 /* 10 Mb/sec Signal Detect gep<7> */
-#define TULIP_GP_EB_OK100 0x00000040 /* 100 Mb/sec Signal Detect gep<6> */
-#define TULIP_GP_EB_INIT 0x0000000B /* No loopback --- point-to-point */
-
-/*
- * These are the defintitions used for the SMC9332 (21140) board.
- */
-#define TULIP_GP_SMC_9332_PINS 0x0000003F /* General Purpose Pin directions */
-#define TULIP_GP_SMC_9332_OK10 0x00000080 /* 10 Mb/sec Signal Detect gep<7> */
-#define TULIP_GP_SMC_9332_OK100 0x00000040 /* 100 Mb/sec Signal Detect gep<6> */
-#define TULIP_GP_SMC_9332_INIT 0x00000009 /* No loopback --- point-to-point */
-
-/*
- * There are the definitions used for the DEC DE500
- * 10/100 family of boards
- */
-#define TULIP_GP_DE500_PINS 0x0000001FL
-#define TULIP_GP_DE500_LINK_PASS 0x00000080L
-#define TULIP_GP_DE500_SYM_LINK 0x00000040L
-#define TULIP_GP_DE500_SIGNAL_DETECT 0x00000020L
-#define TULIP_GP_DE500_PHY_RESET 0x00000010L
-#define TULIP_GP_DE500_HALFDUPLEX 0x00000008L
-#define TULIP_GP_DE500_PHY_LOOPBACK 0x00000004L
-#define TULIP_GP_DE500_FORCE_LED 0x00000002L
-#define TULIP_GP_DE500_FORCE_100 0x00000001L
-
-/*
- * These are the defintitions used for the Cogent EM100
- * 21140 board.
- */
-#define TULIP_GP_EM100_PINS 0x0000003F /* General Purpose Pin directions */
-#define TULIP_GP_EM100_INIT 0x00000009 /* No loopback --- point-to-point */
-#define TULIP_COGENT_EM100TX_ID 0x12
-#define TULIP_COGENT_EM100FX_ID 0x15
-
-
-/*
- * These are the defintitions used for the Znyx ZX342
- * 10/100 board
- */
-#define TULIP_ZNYX_ID_ZX312 0x0602
-#define TULIP_ZNYX_ID_ZX312T 0x0622
-#define TULIP_ZNYX_ID_ZX314_INTA 0x0701
-#define TULIP_ZNYX_ID_ZX314 0x0711
-#define TULIP_ZNYX_ID_ZX315_INTA 0x0801
-#define TULIP_ZNYX_ID_ZX315 0x0811
-#define TULIP_ZNYX_ID_ZX342 0x0901
-#define TULIP_ZNYX_ID_ZX342B 0x0921
-#define TULIP_ZNYX_ID_ZX342_X3 0x0902
-#define TULIP_ZNYX_ID_ZX342_X4 0x0903
-#define TULIP_ZNYX_ID_ZX344 0x0A01
-#define TULIP_ZNYX_ID_ZX351 0x0B01
-#define TULIP_ZNYX_ID_ZX345 0x0C01
-#define TULIP_ZNYX_ID_ZX311 0x0D01
-#define TULIP_ZNYX_ID_ZX346 0x0E01
-
-#define TULIP_GP_ZX34X_PINS 0x0000001F /* General Purpose Pin directions */
-#define TULIP_GP_ZX344_PINS 0x0000000B /* General Purpose Pin directions */
-#define TULIP_GP_ZX345_PINS 0x00000003 /* General Purpose Pin directions */
-#define TULIP_GP_ZX346_PINS 0x00000043 /* General Purpose Pin directions */
-#define TULIP_GP_ZX34X_LNKFAIL 0x00000080 /* 10Mb/s Link Failure */
-#define TULIP_GP_ZX34X_SYMDET 0x00000040 /* 100Mb/s Symbol Detect */
-#define TULIP_GP_ZX345_PHYACT 0x00000040 /* PHY Activity */
-#define TULIP_GP_ZX34X_SIGDET 0x00000020 /* 100Mb/s Signal Detect */
-#define TULIP_GP_ZX346_AUTONEG_ENABLED 0x00000020 /* 802.3u autoneg enabled */
-#define TULIP_GP_ZX342_COLENA 0x00000008 /* 10t Ext LB */
-#define TULIP_GP_ZX344_ROTINT 0x00000008 /* PPB IRQ rotation */
-#define TULIP_GP_ZX345_SPEED10 0x00000008 /* 10Mb speed detect */
-#define TULIP_GP_ZX346_SPEED100 0x00000008 /* 100Mb speed detect */
-#define TULIP_GP_ZX34X_NCOLENA 0x00000004 /* 10t Int LB */
-#define TULIP_GP_ZX34X_RXMATCH 0x00000004 /* RX Match */
-#define TULIP_GP_ZX346_FULLDUPLEX 0x00000004 /* Full Duplex Sensed */
-#define TULIP_GP_ZX34X_LB102 0x00000002 /* 100tx twister LB */
-#define TULIP_GP_ZX34X_NLB101 0x00000001 /* PDT/PDR LB */
-#define TULIP_GP_ZX34X_INIT 0x00000009
-
-/*
- * Asante's stuff...
- */
-#define TULIP_GP_ASANTE_PINS 0x000000bf /* GP pin config */
-#define TULIP_GP_ASANTE_PHYRESET 0x00000008 /* Reset PHY */
-
-/*
- * ACCTON EN1207 specialties
- */
-
-#define TULIP_CSR8_EN1207 0x08
-#define TULIP_CSR9_EN1207 0x00
-#define TULIP_CSR10_EN1207 0x03
-#define TULIP_CSR11_EN1207 0x1F
-
-#define TULIP_GP_EN1207_BNC_INIT 0x0000011B
-#define TULIP_GP_EN1207_UTP_INIT 0x9E00000B
-#define TULIP_GP_EN1207_100_INIT 0x6D00031B
-
-/*
- * SROM definitions for the 21140 and 21041.
- */
-#define SROMXREG 0x0400
-#define SROMSEL 0x0800
-#define SROMRD 0x4000
-#define SROMWR 0x2000
-#define SROMDIN 0x0008
-#define SROMDOUT 0x0004
-#define SROMDOUTON 0x0004
-#define SROMDOUTOFF 0x0004
-#define SROMCLKON 0x0002
-#define SROMCLKOFF 0x0002
-#define SROMCSON 0x0001
-#define SROMCSOFF 0x0001
-#define SROMCS 0x0001
-
-#define SROMCMD_MODE 4
-#define SROMCMD_WR 5
-#define SROMCMD_RD 6
-
-#define SROM_BITWIDTH 6
-
-/*
- * MII Definitions for the 21041 and 21140/21140A/21142
- */
-#define MII_PREAMBLE (~0)
-#define MII_TEST 0xAAAAAAAA
-#define MII_RDCMD 0xF6 /* 1111.0110 */
-#define MII_WRCMD 0xF5 /* 1111.0101 */
-#define MII_DIN 0x00080000
-#define MII_RD 0x00040000
-#define MII_WR 0x00000000
-#define MII_DOUT 0x00020000
-#define MII_CLK 0x00010000
-#define MII_CLKON MII_CLK
-#define MII_CLKOFF MII_CLK
-
-#define PHYREG_CONTROL 0
-#define PHYREG_STATUS 1
-#define PHYREG_IDLOW 2
-#define PHYREG_IDHIGH 3
-#define PHYREG_AUTONEG_ADVERTISEMENT 4
-#define PHYREG_AUTONEG_ABILITIES 5
-#define PHYREG_AUTONEG_EXPANSION 6
-#define PHYREG_AUTONEG_NEXTPAGE 7
-
-#define PHYSTS_100BASET4 0x8000
-#define PHYSTS_100BASETX_FD 0x4000
-#define PHYSTS_100BASETX 0x2000
-#define PHYSTS_10BASET_FD 0x1000
-#define PHYSTS_10BASET 0x0800
-#define PHYSTS_AUTONEG_DONE 0x0020
-#define PHYSTS_REMOTE_FAULT 0x0010
-#define PHYSTS_CAN_AUTONEG 0x0008
-#define PHYSTS_LINK_UP 0x0004
-#define PHYSTS_JABBER_DETECT 0x0002
-#define PHYSTS_EXTENDED_REGS 0x0001
-
-#define PHYCTL_RESET 0x8000
-#define PHYCTL_SELECT_100MB 0x2000
-#define PHYCTL_AUTONEG_ENABLE 0x1000
-#define PHYCTL_ISOLATE 0x0400
-#define PHYCTL_AUTONEG_RESTART 0x0200
-#define PHYCTL_FULL_DUPLEX 0x0100
-
-/*
- * Definitions for the DE425.
- */
-#define DE425_CFID 0x08 /* Configuration Id */
-#define DE425_CFCS 0x0C /* Configuration Command-Status */
-#define DE425_CFRV 0x18 /* Configuration Revision */
-#define DE425_CFLT 0x1C /* Configuration Latency Timer */
-#define DE425_CBIO 0x28 /* Configuration Base IO Address */
-#define DE425_CFDA 0x2C /* Configuration Driver Area */
-#define DE425_ENETROM_OFFSET 0xC90 /* Offset in I/O space for ENETROM */
-#define DE425_CFG0 0xC88 /* IRQ register */
-#define DE425_EISAID 0x10a34250 /* EISA device id */
-#define DE425_EISA_IOSIZE 0x100
-
-#define DEC_VENDORID 0x1011
-#define CHIPID_21040 0x0002
-#define CHIPID_21140 0x0009
-#define CHIPID_21041 0x0014
-#define CHIPID_21142 0x0019
-#define PCI_VENDORID(x) ((x) & 0xFFFF)
-#define PCI_CHIPID(x) (((x) >> 16) & 0xFFFF)
-
-/*
- * Generic SROM Format
- *
- *
- */
-
-typedef struct {
- u_int8_t sh_idbuf[18];
- u_int8_t sh_version;
- u_int8_t sh_adapter_count;
- u_int8_t sh_ieee802_address[6];
-} tulip_srom_header_t;
-
-typedef struct {
- u_int8_t sai_device;
- u_int8_t sai_leaf_offset_lowbyte;
- u_int8_t sai_leaf_offset_highbyte;
-} tulip_srom_adapter_info_t;
-
-typedef enum {
- TULIP_SROM_CONNTYPE_10BASET =0x0000,
- TULIP_SROM_CONNTYPE_BNC =0x0001,
- TULIP_SROM_CONNTYPE_AUI =0x0002,
- TULIP_SROM_CONNTYPE_100BASETX =0x0003,
- TULIP_SROM_CONNTYPE_100BASET4 =0x0006,
- TULIP_SROM_CONNTYPE_100BASEFX =0x0007,
- TULIP_SROM_CONNTYPE_MII_10BASET =0x0009,
- TULIP_SROM_CONNTYPE_MII_100BASETX =0x000D,
- TULIP_SROM_CONNTYPE_MII_100BASET4 =0x000F,
- TULIP_SROM_CONNTYPE_MII_100BASEFX =0x0010,
- TULIP_SROM_CONNTYPE_10BASET_NWAY =0x0100,
- TULIP_SROM_CONNTYPE_10BASET_FD =0x0204,
- TULIP_SROM_CONNTYPE_MII_10BASET_FD =0x020A,
- TULIP_SROM_CONNTYPE_100BASETX_FD =0x020E,
- TULIP_SROM_CONNTYPE_MII_100BASETX_FD =0x0211,
- TULIP_SROM_CONNTYPE_10BASET_NOLINKPASS =0x0400,
- TULIP_SROM_CONNTYPE_AUTOSENSE =0x0800,
- TULIP_SROM_CONNTYPE_AUTOSENSE_POWERUP =0x8800,
- TULIP_SROM_CONNTYPE_AUTOSENSE_NWAY =0x9000,
- TULIP_SROM_CONNTYPE_NOT_USED =0xFFFF
-} tulip_srom_connection_t;
-
-typedef enum {
- TULIP_SROM_MEDIA_10BASET =0x0000,
- TULIP_SROM_MEDIA_BNC =0x0001,
- TULIP_SROM_MEDIA_AUI =0x0002,
- TULIP_SROM_MEDIA_100BASETX =0x0003,
- TULIP_SROM_MEDIA_10BASET_FD =0x0004,
- TULIP_SROM_MEDIA_100BASETX_FD =0x0005,
- TULIP_SROM_MEDIA_100BASET4 =0x0006,
- TULIP_SROM_MEDIA_100BASEFX =0x0007,
- TULIP_SROM_MEDIA_100BASEFX_FD =0x0008
-} tulip_srom_media_t;
-
-#define TULIP_SROM_21041_EXTENDED 0x40
-
-#define TULIP_SROM_2114X_NOINDICATOR 0x8000
-#define TULIP_SROM_2114X_DEFAULT 0x4000
-#define TULIP_SROM_2114X_POLARITY 0x0080
-#define TULIP_SROM_2114X_CMDBITS(n) (((n) & 0x0071) << 18)
-#define TULIP_SROM_2114X_BITPOS(b) (1 << (((b) & 0x0E) >> 1))
-
-
-
-#endif /* !defined(_DC21040_H) */
diff --git a/sys/dev/de/if_de.c b/sys/dev/de/if_de.c
deleted file mode 100644
index e6d5892c6756..000000000000
--- a/sys/dev/de/if_de.c
+++ /dev/null
@@ -1,5262 +0,0 @@
-/* $NetBSD: if_de.c,v 1.86 1999/06/01 19:17:59 thorpej Exp $ */
-
-/* $FreeBSD$ */
-
-/*-
- * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED 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.
- *
- * Id: if_de.c,v 1.94 1997/07/03 16:55:07 thomas Exp
- *
- */
-
-/*
- * DEC 21040 PCI Ethernet Controller
- *
- * Written by Matt Thomas
- * BPF support code stolen directly from if_ec.c
- *
- * This driver supports the DEC DE435 or any other PCI
- * board which support 21040, 21041, or 21140 (mostly).
- */
-#define TULIP_HDR_DATA
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/endian.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/eventhandler.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/bus.h>
-#include <sys/rman.h>
-
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/ethernet.h>
-#include <net/if_media.h>
-#include <net/if_dl.h>
-#ifdef TULIP_USE_SOFTINTR
-#include <net/netisr.h>
-#endif
-
-#include <net/bpf.h>
-
-#ifdef INET
-#include <netinet/in.h>
-#include <netinet/if_ether.h>
-#endif
-
-#include <vm/vm.h>
-
-#include <net/if_var.h>
-#include <vm/pmap.h>
-#include <pci/pcivar.h>
-#include <pci/pcireg.h>
-#include <pci/dc21040reg.h>
-
-/*
- * Intel CPUs should use I/O mapped access.
- */
-#if defined(__i386__)
-#define TULIP_IOMAPPED
-#endif
-
-#if 0
-/*
- * This turns on all sort of debugging stuff and make the
- * driver much larger.
- */
-#define TULIP_DEBUG
-#endif
-
-#if 0
-#define TULIP_PERFSTATS
-#endif
-
-#if 0
-#define TULIP_USE_SOFTINTR
-#endif
-
-#define TULIP_HZ 10
-
-#include <pci/if_devar.h>
-
-/*
- * This module supports
- * the DEC 21040 PCI Ethernet Controller.
- * the DEC 21041 PCI Ethernet Controller.
- * the DEC 21140 PCI Fast Ethernet Controller.
- */
-static void tulip_mii_autonegotiate(tulip_softc_t * const sc, const unsigned phyaddr);
-static void tulip_intr_shared(void *arg);
-static void tulip_intr_normal(void *arg);
-static void tulip_init(tulip_softc_t * const sc);
-static void tulip_ifinit(void *);
-static void tulip_reset(tulip_softc_t * const sc);
-static void tulip_ifstart_one(struct ifnet *ifp);
-static void tulip_ifstart(struct ifnet *ifp);
-static struct mbuf *tulip_txput(tulip_softc_t * const sc, struct mbuf *m);
-static void tulip_txput_setup(tulip_softc_t * const sc);
-static void tulip_rx_intr(tulip_softc_t * const sc);
-static void tulip_addr_filter(tulip_softc_t * const sc);
-static unsigned tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno);
-static void tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data);
-static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
-static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t * const sc);
-static int tulip_srom_decode(tulip_softc_t * const sc);
-static int tulip_ifmedia_change(struct ifnet * const ifp);
-static void tulip_ifmedia_status(struct ifnet * const ifp, struct ifmediareq *req);
-/* static void tulip_21140_map_media(tulip_softc_t *sc); */
-
-static void
-tulip_timeout_callback(
- void *arg)
-{
- tulip_softc_t * const sc = arg;
- int s = splimp();
-
- TULIP_PERFSTART(timeout)
-
- sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
- sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
- (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
-
- TULIP_PERFEND(timeout);
- splx(s);
-}
-
-static void
-tulip_timeout(
- tulip_softc_t * const sc)
-{
- if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
- return;
- sc->tulip_flags |= TULIP_TIMEOUTPENDING;
- timeout(tulip_timeout_callback, sc, (hz + TULIP_HZ / 2) / TULIP_HZ);
-}
-
-#if defined(TULIP_NEED_FASTTIMEOUT)
-static void
-tulip_fasttimeout_callback(
- void *arg)
-{
- tulip_softc_t * const sc = arg;
- int s = splimp();
-
- sc->tulip_flags &= ~TULIP_FASTTIMEOUTPENDING;
- (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_FASTTIMER);
- splx(s);
-}
-
-static void
-tulip_fasttimeout(
- tulip_softc_t * const sc)
-{
- if (sc->tulip_flags & TULIP_FASTTIMEOUTPENDING)
- return;
- sc->tulip_flags |= TULIP_FASTTIMEOUTPENDING;
- timeout(tulip_fasttimeout_callback, sc, 1);
-}
-#endif
-
-static int
-tulip_txprobe(
- tulip_softc_t * const sc)
-{
- struct mbuf *m;
- /*
- * Before we are sure this is the right media we need
- * to send a small packet to make sure there's carrier.
- * Strangely, BNC and AUI will "see" receive data if
- * either is connected so the transmit is the only way
- * to verify the connectivity.
- */
- MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (m == NULL)
- return 0;
- /*
- * Construct a LLC TEST message which will point to ourselves.
- */
- bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
- bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6);
- mtod(m, struct ether_header *)->ether_type = htons(3);
- mtod(m, unsigned char *)[14] = 0;
- mtod(m, unsigned char *)[15] = 0;
- mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
- m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
- /*
- * send it!
- */
- sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
- sc->tulip_intrmask |= TULIP_STS_TXINTR;
- sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
- TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
- TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
- if ((m = tulip_txput(sc, m)) != NULL)
- m_freem(m);
- sc->tulip_probe.probe_txprobes++;
- return 1;
-}
-
-#ifdef BIG_PACKET
-#define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
-#else
-#define TULIP_SIAGEN_WATCHDOG 0
-#endif
-
-static void
-tulip_media_set(
- tulip_softc_t * const sc,
- tulip_media_t media)
-{
- const tulip_media_info_t *mi = sc->tulip_mediums[media];
-
- if (mi == NULL)
- return;
-
- /*
- * If we are switching media, make sure we don't think there's
- * any stale RX activity
- */
- sc->tulip_flags &= ~TULIP_RXACT;
- if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
- TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
- TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
- if (sc->tulip_features & TULIP_HAVE_SIAGP) {
- TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
- DELAY(50);
- TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
- } else {
- TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
- }
- TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
- } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
-#define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
- /*
- * If the cmdmode bits don't match the currently operating mode,
- * set the cmdmode appropriately and reset the chip.
- */
- if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
- sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
- sc->tulip_cmdmode |= mi->mi_cmdmode;
- tulip_reset(sc);
- }
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
- DELAY(10);
- TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
- } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
- /*
- * If the cmdmode bits don't match the currently operating mode,
- * set the cmdmode appropriately and reset the chip.
- */
- if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
- sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
- sc->tulip_cmdmode |= mi->mi_cmdmode;
- tulip_reset(sc);
- }
- TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
- TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
- } else if (mi->mi_type == TULIP_MEDIAINFO_MII
- && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
- int idx;
- if (sc->tulip_features & TULIP_HAVE_SIAGP) {
- const u_int8_t *dp;
- dp = &sc->tulip_rombuf[mi->mi_reset_offset];
- for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
- DELAY(10);
- TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
- }
- sc->tulip_phyaddr = mi->mi_phyaddr;
- dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
- for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
- DELAY(10);
- TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
- }
- } else {
- for (idx = 0; idx < mi->mi_reset_length; idx++) {
- DELAY(10);
- TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
- }
- sc->tulip_phyaddr = mi->mi_phyaddr;
- for (idx = 0; idx < mi->mi_gpr_length; idx++) {
- DELAY(10);
- TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
- }
- }
- if (sc->tulip_flags & TULIP_TRYNWAY) {
- tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
- } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
- u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
- data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
- sc->tulip_flags &= ~TULIP_DIDNWAY;
- if (TULIP_IS_MEDIA_FD(media))
- data |= PHYCTL_FULL_DUPLEX;
- if (TULIP_IS_MEDIA_100MB(media))
- data |= PHYCTL_SELECT_100MB;
- tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
- }
- }
-}
-
-static void
-tulip_linkup(
- tulip_softc_t * const sc,
- tulip_media_t media)
-{
- if ((sc->tulip_flags & TULIP_LINKUP) == 0)
- sc->tulip_flags |= TULIP_PRINTLINKUP;
- sc->tulip_flags |= TULIP_LINKUP;
- sc->tulip_if.if_flags &= ~IFF_OACTIVE;
-#if 0 /* XXX how does with work with ifmedia? */
- if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
- if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) {
- if (TULIP_CAN_MEDIA_FD(media)
- && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
- media = TULIP_FD_MEDIA_OF(media);
- } else {
- if (TULIP_IS_MEDIA_FD(media)
- && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
- media = TULIP_HD_MEDIA_OF(media);
- }
- }
-#endif
- if (sc->tulip_media != media) {
-#ifdef TULIP_DEBUG
- sc->tulip_dbg.dbg_last_media = sc->tulip_media;
-#endif
- sc->tulip_media = media;
- sc->tulip_flags |= TULIP_PRINTMEDIA;
- if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
- sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
- } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
- sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
- }
- }
- /*
- * We could set probe_timeout to 0 but setting to 3000 puts this
- * in one central place and the only matters is tulip_link is
- * followed by a tulip_timeout. Therefore setting it should not
- * result in aberrant behavour.
- */
- sc->tulip_probe_timeout = 3000;
- sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
- sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
- if (sc->tulip_flags & TULIP_INRESET) {
- tulip_media_set(sc, sc->tulip_media);
- } else if (sc->tulip_probe_media != sc->tulip_media) {
- /*
- * No reason to change media if we have the right media.
- */
- tulip_reset(sc);
- }
- tulip_init(sc);
-}
-
-static void
-tulip_media_print(
- tulip_softc_t * const sc)
-{
- if ((sc->tulip_flags & TULIP_LINKUP) == 0)
- return;
- if (sc->tulip_flags & TULIP_PRINTMEDIA) {
- printf("%s%d: enabling %s port\n",
- sc->tulip_name, sc->tulip_unit,
- tulip_mediums[sc->tulip_media]);
- sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
- } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
- printf("%s%d: link up\n", sc->tulip_name, sc->tulip_unit);
- sc->tulip_flags &= ~TULIP_PRINTLINKUP;
- }
-}
-
-#if defined(TULIP_DO_GPR_SENSE)
-static tulip_media_t
-tulip_21140_gpr_media_sense(
- tulip_softc_t * const sc)
-{
- tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
- tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
- tulip_media_t media;
-
- /*
- * If one of the media blocks contained a default media flag,
- * use that.
- */
- for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
- const tulip_media_info_t *mi;
- /*
- * Media is not supported (or is full-duplex).
- */
- if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
- continue;
- if (mi->mi_type != TULIP_MEDIAINFO_GPR)
- continue;
-
- /*
- * Remember the media is this is the "default" media.
- */
- if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
- maybe_media = media;
-
- /*
- * No activity mask? Can't see if it is active if there's no mask.
- */
- if (mi->mi_actmask == 0)
- continue;
-
- /*
- * Does the activity data match?
- */
- if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
- continue;
-
-#if defined(TULIP_DEBUG)
- printf("%s%d: gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n",
- sc->tulip_name, sc->tulip_unit, tulip_mediums[media],
- TULIP_CSR_READ(sc, csr_gp) & 0xFF,
- mi->mi_actmask, mi->mi_actdata);
-#endif
- /*
- * It does! If this is the first media we detected, then
- * remember this media. If isn't the first, then there were
- * multiple matches which we equate to no match (since we don't
- * which to select (if any).
- */
- if (last_media == TULIP_MEDIA_UNKNOWN) {
- last_media = media;
- } else if (last_media != media) {
- last_media = TULIP_MEDIA_UNKNOWN;
- }
- }
- return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
-}
-#endif /* TULIP_DO_GPR_SENSE */
-
-static tulip_link_status_t
-tulip_media_link_monitor(
- tulip_softc_t * const sc)
-{
- const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media];
- tulip_link_status_t linkup = TULIP_LINK_DOWN;
-
- if (mi == NULL) {
-#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
- panic("tulip_media_link_monitor: %s: botch at line %d\n",
- tulip_mediums[sc->tulip_media],__LINE__);
-#endif
- return TULIP_LINK_UNKNOWN;
- }
-
-
- /*
- * Have we seen some packets? If so, the link must be good.
- */
- if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
- sc->tulip_flags &= ~TULIP_RXACT;
- sc->tulip_probe_timeout = 3000;
- return TULIP_LINK_UP;
- }
-
- sc->tulip_flags &= ~TULIP_RXACT;
- if (mi->mi_type == TULIP_MEDIAINFO_MII) {
- u_int32_t status;
- /*
- * Read the PHY status register.
- */
- status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
- if (status & PHYSTS_AUTONEG_DONE) {
- /*
- * If the PHY has completed autonegotiation, see the if the
- * remote systems abilities have changed. If so, upgrade or
- * downgrade as appropriate.
- */
- u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
- abilities = (abilities << 6) & status;
- if (abilities != sc->tulip_abilities) {
-#if defined(TULIP_DEBUG)
- loudprintf("%s%d(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n",
- sc->tulip_name, sc->tulip_unit, sc->tulip_phyaddr,
- sc->tulip_abilities, abilities);
-#endif
- if (tulip_mii_map_abilities(sc, abilities)) {
- tulip_linkup(sc, sc->tulip_probe_media);
- return TULIP_LINK_UP;
- }
- /*
- * if we had selected media because of autonegotiation,
- * we need to probe for the new media.
- */
- sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
- if (sc->tulip_flags & TULIP_DIDNWAY)
- return TULIP_LINK_DOWN;
- }
- }
- /*
- * The link is now up. If was down, say its back up.
- */
- if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
- linkup = TULIP_LINK_UP;
- } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
- /*
- * No activity sensor? Assume all's well.
- */
- if (mi->mi_actmask == 0)
- return TULIP_LINK_UNKNOWN;
- /*
- * Does the activity data match?
- */
- if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
- linkup = TULIP_LINK_UP;
- } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
- /*
- * Assume non TP ok for now.
- */
- if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
- return TULIP_LINK_UNKNOWN;
- if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
- linkup = TULIP_LINK_UP;
-#if defined(TULIP_DEBUG)
- if (sc->tulip_probe_timeout <= 0)
- printf("%s%d: sia status = 0x%08x\n", sc->tulip_name,
- sc->tulip_unit, TULIP_CSR_READ(sc, csr_sia_status));
-#endif
- } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
- return TULIP_LINK_UNKNOWN;
- }
- /*
- * We will wait for 3 seconds until the link goes into suspect mode.
- */
- if (sc->tulip_flags & TULIP_LINKUP) {
- if (linkup == TULIP_LINK_UP)
- sc->tulip_probe_timeout = 3000;
- if (sc->tulip_probe_timeout > 0)
- return TULIP_LINK_UP;
-
- sc->tulip_flags &= ~TULIP_LINKUP;
- printf("%s%d: link down: cable problem?\n", sc->tulip_name, sc->tulip_unit);
- }
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_link_downed++;
-#endif
- return TULIP_LINK_DOWN;
-}
-
-static void
-tulip_media_poll(
- tulip_softc_t * const sc,
- tulip_mediapoll_event_t event)
-{
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_events[event]++;
-#endif
- if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
- && event == TULIP_MEDIAPOLL_TIMER) {
- switch (tulip_media_link_monitor(sc)) {
- case TULIP_LINK_DOWN: {
- /*
- * Link Monitor failed. Probe for new media.
- */
- event = TULIP_MEDIAPOLL_LINKFAIL;
- break;
- }
- case TULIP_LINK_UP: {
- /*
- * Check again soon.
- */
- tulip_timeout(sc);
- return;
- }
- case TULIP_LINK_UNKNOWN: {
- /*
- * We can't tell so don't bother.
- */
- return;
- }
- }
- }
-
- if (event == TULIP_MEDIAPOLL_LINKFAIL) {
- if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
- if (TULIP_DO_AUTOSENSE(sc)) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_link_failures++;
-#endif
- sc->tulip_media = TULIP_MEDIA_UNKNOWN;
- if (sc->tulip_if.if_flags & IFF_UP)
- tulip_reset(sc); /* restart probe */
- }
- return;
- }
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_link_pollintrs++;
-#endif
- }
-
- if (event == TULIP_MEDIAPOLL_START) {
- sc->tulip_if.if_flags |= IFF_OACTIVE;
- if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
- return;
- sc->tulip_probe_mediamask = 0;
- sc->tulip_probe_passes = 0;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_media_probes++;
-#endif
- /*
- * If the SROM contained an explicit media to use, use it.
- */
- sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
- sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
- sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
- /*
- * connidx is defaulted to a media_unknown type.
- */
- sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
- if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
- tulip_linkup(sc, sc->tulip_probe_media);
- tulip_timeout(sc);
- return;
- }
-
- if (sc->tulip_features & TULIP_HAVE_GPR) {
- sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
- sc->tulip_probe_timeout = 2000;
- } else {
- sc->tulip_probe_media = TULIP_MEDIA_MAX;
- sc->tulip_probe_timeout = 0;
- sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
- }
- }
-
- /*
- * Ignore txprobe failures or spurious callbacks.
- */
- if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
- && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
- sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
- return;
- }
-
- /*
- * If we really transmitted a packet, then that's the media we'll use.
- */
- if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
- if (event == TULIP_MEDIAPOLL_LINKPASS) {
- /* XXX Check media status just to be sure */
- sc->tulip_probe_media = TULIP_MEDIA_10BASET;
-#if defined(TULIP_DEBUG)
- } else {
- sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
-#endif
- }
- tulip_linkup(sc, sc->tulip_probe_media);
- tulip_timeout(sc);
- return;
- }
-
- if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
-#if defined(TULIP_DO_GPR_SENSE)
- /*
- * Check for media via the general purpose register.
- *
- * Try to sense the media via the GPR. If the same value
- * occurs 3 times in a row then just use that.
- */
- if (sc->tulip_probe_timeout > 0) {
- tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
-#if defined(TULIP_DEBUG)
- printf("%s%d: media_poll: gpr sensing = %s\n",
- sc->tulip_name, sc->tulip_unit, tulip_mediums[new_probe_media]);
-#endif
- if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
- if (new_probe_media == sc->tulip_probe_media) {
- if (--sc->tulip_probe_count == 0)
- tulip_linkup(sc, sc->tulip_probe_media);
- } else {
- sc->tulip_probe_count = 10;
- }
- }
- sc->tulip_probe_media = new_probe_media;
- tulip_timeout(sc);
- return;
- }
-#endif /* TULIP_DO_GPR_SENSE */
- /*
- * Brute force. We cycle through each of the media types
- * and try to transmit a packet.
- */
- sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
- sc->tulip_probe_media = TULIP_MEDIA_MAX;
- sc->tulip_probe_timeout = 0;
- tulip_timeout(sc);
- return;
- }
-
- if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
- && (sc->tulip_features & TULIP_HAVE_MII)) {
- tulip_media_t old_media = sc->tulip_probe_media;
- tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
- switch (sc->tulip_probe_state) {
- case TULIP_PROBE_FAILED:
- case TULIP_PROBE_MEDIATEST: {
- /*
- * Try the next media.
- */
- sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
- sc->tulip_probe_timeout = 0;
-#ifdef notyet
- if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
- break;
- if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
- break;
- sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
-#endif
- break;
- }
- case TULIP_PROBE_PHYAUTONEG: {
- return;
- }
- case TULIP_PROBE_INACTIVE: {
- /*
- * Only probe if we autonegotiated a media that hasn't failed.
- */
- sc->tulip_probe_timeout = 0;
- if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
- sc->tulip_probe_media = old_media;
- break;
- }
- tulip_linkup(sc, sc->tulip_probe_media);
- tulip_timeout(sc);
- return;
- }
- default: {
-#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
- panic("tulip_media_poll: botch at line %d\n", __LINE__);
-#endif
- break;
- }
- }
- }
-
- if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++;
-#endif
- sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
- return;
- }
-
- /*
- * switch to another media if we tried this one enough.
- */
- if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
-#if defined(TULIP_DEBUG)
- if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
- printf("%s%d: poll media unknown!\n",
- sc->tulip_name, sc->tulip_unit);
- sc->tulip_probe_media = TULIP_MEDIA_MAX;
- }
-#endif
- /*
- * Find the next media type to check for. Full Duplex
- * types are not allowed.
- */
- do {
- sc->tulip_probe_media -= 1;
- if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
- if (++sc->tulip_probe_passes == 3) {
- printf("%s%d: autosense failed: cable problem?\n",
- sc->tulip_name, sc->tulip_unit);
- if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
- sc->tulip_if.if_flags &= ~IFF_RUNNING;
- sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
- return;
- }
- }
- sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
- sc->tulip_probe_mediamask = 0;
- sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
- }
- } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
- || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
- || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
-
-#if defined(TULIP_DEBUG)
- printf("%s%d: %s: probing %s\n", sc->tulip_name, sc->tulip_unit,
- event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout",
- tulip_mediums[sc->tulip_probe_media]);
-#endif
- sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
- sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
- sc->tulip_probe.probe_txprobes = 0;
- tulip_reset(sc);
- tulip_media_set(sc, sc->tulip_probe_media);
- sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
- }
- tulip_timeout(sc);
-
- /*
- * If this is hanging off a phy, we know are doing NWAY and we have
- * forced the phy to a specific speed. Wait for link up before
- * before sending a packet.
- */
- switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
- case TULIP_MEDIAINFO_MII: {
- if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
- return;
- break;
- }
- case TULIP_MEDIAINFO_SIA: {
- if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
- if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
- return;
- tulip_linkup(sc, sc->tulip_probe_media);
-#ifdef notyet
- if (sc->tulip_features & TULIP_HAVE_MII)
- tulip_timeout(sc);
-#endif
- return;
- }
- break;
- }
- case TULIP_MEDIAINFO_RESET:
- case TULIP_MEDIAINFO_SYM:
- case TULIP_MEDIAINFO_NONE:
- case TULIP_MEDIAINFO_GPR: {
- break;
- }
- }
- /*
- * Try to send a packet.
- */
- tulip_txprobe(sc);
-}
-
-static void
-tulip_media_select(
- tulip_softc_t * const sc)
-{
- if (sc->tulip_features & TULIP_HAVE_GPR) {
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
- DELAY(10);
- TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
- }
- /*
- * If this board has no media, just return
- */
- if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
- return;
-
- if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
- TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
- (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
- } else {
- tulip_media_set(sc, sc->tulip_media);
- }
-}
-
-static void
-tulip_21040_mediainfo_init(
- tulip_softc_t * const sc,
- tulip_media_t media)
-{
- sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
- |TULIP_CMD_BACKOFFCTR;
- sc->tulip_if.if_baudrate = 10000000;
-
- if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
- TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
- TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
- sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
- }
-
- if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
- TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
- }
-
- if (media == TULIP_MEDIA_UNKNOWN) {
- TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
- }
-}
-
-static void
-tulip_21040_media_probe(
- tulip_softc_t * const sc)
-{
- tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
- return;
-}
-
-static void
-tulip_21040_10baset_only_media_probe(
- tulip_softc_t * const sc)
-{
- tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
- tulip_media_set(sc, TULIP_MEDIA_10BASET);
- sc->tulip_media = TULIP_MEDIA_10BASET;
-}
-
-static void
-tulip_21040_10baset_only_media_select(
- tulip_softc_t * const sc)
-{
- sc->tulip_flags |= TULIP_LINKUP;
- if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
- sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
- sc->tulip_flags &= ~TULIP_SQETEST;
- } else {
- sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
- sc->tulip_flags |= TULIP_SQETEST;
- }
- tulip_media_set(sc, sc->tulip_media);
-}
-
-static void
-tulip_21040_auibnc_only_media_probe(
- tulip_softc_t * const sc)
-{
- tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
- sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
- tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
- sc->tulip_media = TULIP_MEDIA_AUIBNC;
-}
-
-static void
-tulip_21040_auibnc_only_media_select(
- tulip_softc_t * const sc)
-{
- tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
- sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
-}
-
-static const tulip_boardsw_t tulip_21040_boardsw = {
- TULIP_21040_GENERIC,
- tulip_21040_media_probe,
- tulip_media_select,
- tulip_media_poll,
-};
-
-static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
- TULIP_21040_GENERIC,
- tulip_21040_10baset_only_media_probe,
- tulip_21040_10baset_only_media_select,
- NULL,
-};
-
-static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
- TULIP_21040_GENERIC,
- tulip_21040_auibnc_only_media_probe,
- tulip_21040_auibnc_only_media_select,
- NULL,
-};
-
-static void
-tulip_21041_mediainfo_init(
- tulip_softc_t * const sc)
-{
- tulip_media_info_t * const mi = sc->tulip_mediainfo;
-
-#ifdef notyet
- if (sc->tulip_revinfo >= 0x20) {
- TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
- TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
- TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
- TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
- return;
- }
-#endif
- TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
- TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
- TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
- TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
-}
-
-static void
-tulip_21041_media_probe(
- tulip_softc_t * const sc)
-{
- sc->tulip_if.if_baudrate = 10000000;
- sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
- |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
- sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
- tulip_21041_mediainfo_init(sc);
-}
-
-static void
-tulip_21041_media_poll(
- tulip_softc_t * const sc,
- const tulip_mediapoll_event_t event)
-{
- u_int32_t sia_status;
-
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_events[event]++;
-#endif
-
- if (event == TULIP_MEDIAPOLL_LINKFAIL) {
- if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
- || !TULIP_DO_AUTOSENSE(sc))
- return;
- sc->tulip_media = TULIP_MEDIA_UNKNOWN;
- tulip_reset(sc); /* start probe */
- return;
- }
-
- /*
- * If we've been been asked to start a poll or link change interrupt
- * restart the probe (and reset the tulip to a known state).
- */
- if (event == TULIP_MEDIAPOLL_START) {
- sc->tulip_if.if_flags |= IFF_OACTIVE;
- sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
-#ifdef notyet
- if (sc->tulip_revinfo >= 0x20) {
- sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
- sc->tulip_flags |= TULIP_DIDNWAY;
- }
-#endif
- TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
- sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
- sc->tulip_probe_media = TULIP_MEDIA_10BASET;
- sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
- tulip_media_set(sc, TULIP_MEDIA_10BASET);
- tulip_timeout(sc);
- return;
- }
-
- if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
- return;
-
- if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
-#endif
- tulip_linkup(sc, sc->tulip_probe_media);
- return;
- }
-
- sia_status = TULIP_CSR_READ(sc, csr_sia_status);
- TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
- if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
- if (sc->tulip_revinfo >= 0x20) {
- if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
- sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
- }
- /*
- * If the link has passed LinkPass, 10baseT is the
- * proper media to use.
- */
- tulip_linkup(sc, sc->tulip_probe_media);
- return;
- }
-
- /*
- * wait for up to 2.4 seconds for the link to reach pass state.
- * Only then start scanning the other media for activity.
- * choose media with receive activity over those without.
- */
- if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
- if (event != TULIP_MEDIAPOLL_TIMER)
- return;
- if (sc->tulip_probe_timeout > 0
- && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
- tulip_timeout(sc);
- return;
- }
- sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
- sc->tulip_flags |= TULIP_WANTRXACT;
- if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
- sc->tulip_probe_media = TULIP_MEDIA_BNC;
- } else {
- sc->tulip_probe_media = TULIP_MEDIA_AUI;
- }
- tulip_media_set(sc, sc->tulip_probe_media);
- tulip_timeout(sc);
- return;
- }
-
- /*
- * If we failed, clear the txprobe active flag.
- */
- if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
- sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
-
-
- if (event == TULIP_MEDIAPOLL_TIMER) {
- /*
- * If we've received something, then that's our link!
- */
- if (sc->tulip_flags & TULIP_RXACT) {
- tulip_linkup(sc, sc->tulip_probe_media);
- return;
- }
- /*
- * if no txprobe active
- */
- if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
- && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
- || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
- sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
- tulip_txprobe(sc);
- tulip_timeout(sc);
- return;
- }
- /*
- * Take 2 passes through before deciding to not
- * wait for receive activity. Then take another
- * two passes before spitting out a warning.
- */
- if (sc->tulip_probe_timeout <= 0) {
- if (sc->tulip_flags & TULIP_WANTRXACT) {
- sc->tulip_flags &= ~TULIP_WANTRXACT;
- sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
- } else {
- printf("%s%d: autosense failed: cable problem?\n",
- sc->tulip_name, sc->tulip_unit);
- if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
- sc->tulip_if.if_flags &= ~IFF_RUNNING;
- sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
- return;
- }
- }
- }
- }
-
- /*
- * Since this media failed to probe, try the other one.
- */
- sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
- if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
- sc->tulip_probe_media = TULIP_MEDIA_BNC;
- } else {
- sc->tulip_probe_media = TULIP_MEDIA_AUI;
- }
- tulip_media_set(sc, sc->tulip_probe_media);
- sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
- tulip_timeout(sc);
-}
-
-static const tulip_boardsw_t tulip_21041_boardsw = {
- TULIP_21041_GENERIC,
- tulip_21041_media_probe,
- tulip_media_select,
- tulip_21041_media_poll
-};
-
-static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
- { 0x20005c00, 0, /* 08-00-17 */
- {
- { 0x19, 0x0040, 0x0040 }, /* 10TX */
- { 0x19, 0x0040, 0x0000 }, /* 100TX */
- },
-#if defined(TULIP_DEBUG)
- "NS DP83840",
-#endif
- },
- { 0x0281F400, 0, /* 00-A0-7D */
- {
- { 0x12, 0x0010, 0x0000 }, /* 10T */
- { }, /* 100TX */
- { 0x12, 0x0010, 0x0010 }, /* 100T4 */
- { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
- },
-#if defined(TULIP_DEBUG)
- "Seeq 80C240"
-#endif
- },
-#if 0
- { 0x0015F420, 0, /* 00-A0-7D */
- {
- { 0x12, 0x0010, 0x0000 }, /* 10T */
- { }, /* 100TX */
- { 0x12, 0x0010, 0x0010 }, /* 100T4 */
- { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
- },
-#if defined(TULIP_DEBUG)
- "Broadcom BCM5000"
-#endif
- },
-#endif
- { 0x0281F400, 0, /* 00-A0-BE */
- {
- { 0x11, 0x8000, 0x0000 }, /* 10T */
- { 0x11, 0x8000, 0x8000 }, /* 100TX */
- { }, /* 100T4 */
- { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
- },
-#if defined(TULIP_DEBUG)
- "ICS 1890"
-#endif
- },
- { 0 }
-};
-
-static tulip_media_t
-tulip_mii_phy_readspecific(
- tulip_softc_t * const sc)
-{
- const tulip_phy_attr_t *attr;
- u_int16_t data;
- u_int32_t id;
- unsigned idx = 0;
- static const tulip_media_t table[] = {
- TULIP_MEDIA_UNKNOWN,
- TULIP_MEDIA_10BASET,
- TULIP_MEDIA_100BASETX,
- TULIP_MEDIA_100BASET4,
- TULIP_MEDIA_UNKNOWN,
- TULIP_MEDIA_10BASET_FD,
- TULIP_MEDIA_100BASETX_FD,
- TULIP_MEDIA_UNKNOWN
- };
-
- /*
- * Don't read phy specific registers if link is not up.
- */
- data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
- if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
- return TULIP_MEDIA_UNKNOWN;
-
- id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
- tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
- for (attr = tulip_mii_phy_attrlist;; attr++) {
- if (attr->attr_id == 0)
- return TULIP_MEDIA_UNKNOWN;
- if ((id & ~0x0F) == attr->attr_id)
- break;
- }
-
- if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
- const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX];
- data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
- if ((data & pm->pm_mask) == pm->pm_value)
- idx = 2;
- }
- if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
- const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4];
- data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
- if ((data & pm->pm_mask) == pm->pm_value)
- idx = 3;
- }
- if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
- const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T];
- data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
- if ((data & pm->pm_mask) == pm->pm_value)
- idx = 1;
- }
- if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
- const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
- data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
- idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
- }
- return table[idx];
-}
-
-static unsigned
-tulip_mii_get_phyaddr(
- tulip_softc_t * const sc,
- unsigned offset)
-{
- unsigned phyaddr;
-
- for (phyaddr = 1; phyaddr < 32; phyaddr++) {
- unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
- if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
- continue;
- if (offset == 0)
- return phyaddr;
- offset--;
- }
- if (offset == 0) {
- unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
- if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
- return TULIP_MII_NOPHY;
- return 0;
- }
- return TULIP_MII_NOPHY;
-}
-
-static int
-tulip_mii_map_abilities(
- tulip_softc_t * const sc,
- unsigned abilities)
-{
- sc->tulip_abilities = abilities;
- if (abilities & PHYSTS_100BASETX_FD) {
- sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
- } else if (abilities & PHYSTS_100BASET4) {
- sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
- } else if (abilities & PHYSTS_100BASETX) {
- sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
- } else if (abilities & PHYSTS_10BASET_FD) {
- sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
- } else if (abilities & PHYSTS_10BASET) {
- sc->tulip_probe_media = TULIP_MEDIA_10BASET;
- } else {
- sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
- return 0;
- }
- sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
- return 1;
-}
-
-static void
-tulip_mii_autonegotiate(
- tulip_softc_t * const sc,
- const unsigned phyaddr)
-{
- switch (sc->tulip_probe_state) {
- case TULIP_PROBE_MEDIATEST:
- case TULIP_PROBE_INACTIVE: {
- sc->tulip_flags |= TULIP_DIDNWAY;
- tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
- sc->tulip_probe_timeout = 3000;
- sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
- sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
- /* FALLTHROUGH */
- }
- case TULIP_PROBE_PHYRESET: {
- u_int32_t status;
- u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
- if (data & PHYCTL_RESET) {
- if (sc->tulip_probe_timeout > 0) {
- tulip_timeout(sc);
- return;
- }
- printf("%s%d(phy%d): error: reset of PHY never completed!\n",
- sc->tulip_name, sc->tulip_unit, phyaddr);
- sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
- sc->tulip_probe_state = TULIP_PROBE_FAILED;
- sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
- return;
- }
- status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
- if ((status & PHYSTS_CAN_AUTONEG) == 0) {
-#if defined(TULIP_DEBUG)
- loudprintf("%s%d(phy%d): autonegotiation disabled\n",
- sc->tulip_name, sc->tulip_unit, phyaddr);
-#endif
- sc->tulip_flags &= ~TULIP_DIDNWAY;
- sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
- return;
- }
- if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
- tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
- tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
- data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
-#if defined(TULIP_DEBUG)
- if ((data & PHYCTL_AUTONEG_ENABLE) == 0)
- loudprintf("%s%d(phy%d): oops: enable autonegotiation failed: 0x%04x\n",
- sc->tulip_name, sc->tulip_unit, phyaddr, data);
- else
- loudprintf("%s%d(phy%d): autonegotiation restarted: 0x%04x\n",
- sc->tulip_name, sc->tulip_unit, phyaddr, data);
- sc->tulip_dbg.dbg_nway_starts++;
-#endif
- sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
- sc->tulip_probe_timeout = 3000;
- /* FALLTHROUGH */
- }
- case TULIP_PROBE_PHYAUTONEG: {
- u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
- u_int32_t data;
- if ((status & PHYSTS_AUTONEG_DONE) == 0) {
- if (sc->tulip_probe_timeout > 0) {
- tulip_timeout(sc);
- return;
- }
-#if defined(TULIP_DEBUG)
- loudprintf("%s%d(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n",
- sc->tulip_name, sc->tulip_unit, phyaddr, status,
- tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL));
-#endif
- sc->tulip_flags &= ~TULIP_DIDNWAY;
- sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
- return;
- }
- data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
-#if defined(TULIP_DEBUG)
- loudprintf("%s%d(phy%d): autonegotiation complete: 0x%04x\n",
- sc->tulip_name, sc->tulip_unit, phyaddr, data);
-#endif
- data = (data << 6) & status;
- if (!tulip_mii_map_abilities(sc, data))
- sc->tulip_flags &= ~TULIP_DIDNWAY;
- return;
- }
- default: {
-#if defined(DIAGNOSTIC)
- panic("tulip_media_poll: botch at line %d\n", __LINE__);
-#endif
- break;
- }
- }
-#if defined(TULIP_DEBUG)
- loudprintf("%s%d(phy%d): autonegotiation failure: state = %d\n",
- sc->tulip_name, sc->tulip_unit, phyaddr, sc->tulip_probe_state);
- sc->tulip_dbg.dbg_nway_failures++;
-#endif
-}
-
-static void
-tulip_2114x_media_preset(
- tulip_softc_t * const sc)
-{
- const tulip_media_info_t *mi = NULL;
- tulip_media_t media = sc->tulip_media;
-
- if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
- media = sc->tulip_media;
- else
- media = sc->tulip_probe_media;
-
- sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
- sc->tulip_flags &= ~TULIP_SQETEST;
- if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
-#if defined(TULIP_DEBUG)
- if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) {
-#endif
- mi = sc->tulip_mediums[media];
- if (mi->mi_type == TULIP_MEDIAINFO_MII) {
- sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
- } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
- || mi->mi_type == TULIP_MEDIAINFO_SYM) {
- sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
- sc->tulip_cmdmode |= mi->mi_cmdmode;
- } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
- TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
- }
-#if defined(TULIP_DEBUG)
- } else {
- printf("%s%d: preset: bad media %d!\n",
- sc->tulip_name, sc->tulip_unit, media);
- }
-#endif
- }
- switch (media) {
- case TULIP_MEDIA_BNC:
- case TULIP_MEDIA_AUI:
- case TULIP_MEDIA_10BASET: {
- sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
- sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
- sc->tulip_if.if_baudrate = 10000000;
- sc->tulip_flags |= TULIP_SQETEST;
- break;
- }
- case TULIP_MEDIA_10BASET_FD: {
- sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
- sc->tulip_if.if_baudrate = 10000000;
- break;
- }
- case TULIP_MEDIA_100BASEFX:
- case TULIP_MEDIA_100BASET4:
- case TULIP_MEDIA_100BASETX: {
- sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
- sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
- sc->tulip_if.if_baudrate = 100000000;
- break;
- }
- case TULIP_MEDIA_100BASEFX_FD:
- case TULIP_MEDIA_100BASETX_FD: {
- sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
- sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
- sc->tulip_if.if_baudrate = 100000000;
- break;
- }
- default: {
- break;
- }
- }
- TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
-}
-
-/*
- ********************************************************************
- * Start of 21140/21140A support which does not use the MII interface
- */
-
-static void
-tulip_null_media_poll(
- tulip_softc_t * const sc,
- tulip_mediapoll_event_t event)
-{
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_events[event]++;
-#endif
-#if defined(DIAGNOSTIC)
- printf("%s%d: botch(media_poll) at line %d\n",
- sc->tulip_name, sc->tulip_unit, __LINE__);
-#endif
-}
-
-__inline__ static void
-tulip_21140_mediainit(
- tulip_softc_t * const sc,
- tulip_media_info_t * const mip,
- tulip_media_t const media,
- unsigned gpdata,
- unsigned cmdmode)
-{
- sc->tulip_mediums[media] = mip;
- mip->mi_type = TULIP_MEDIAINFO_GPR;
- mip->mi_cmdmode = cmdmode;
- mip->mi_gpdata = gpdata;
-}
-
-static void
-tulip_21140_evalboard_media_probe(
- tulip_softc_t * const sc)
-{
- tulip_media_info_t *mip = sc->tulip_mediainfo;
-
- sc->tulip_gpinit = TULIP_GP_EB_PINS;
- sc->tulip_gpdata = TULIP_GP_EB_INIT;
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
- TULIP_CSR_WRITE(sc, csr_command,
- TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
- TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
- TULIP_CSR_WRITE(sc, csr_command,
- TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
- DELAY(1000000);
- if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
- sc->tulip_media = TULIP_MEDIA_10BASET;
- } else {
- sc->tulip_media = TULIP_MEDIA_100BASETX;
- }
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
- TULIP_GP_EB_INIT,
- TULIP_CMD_TXTHRSHLDCTL);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
- TULIP_GP_EB_INIT,
- TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
- TULIP_GP_EB_INIT,
- TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
- |TULIP_CMD_SCRAMBLER);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
- TULIP_GP_EB_INIT,
- TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
- |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
-}
-
-static const tulip_boardsw_t tulip_21140_eb_boardsw = {
- TULIP_21140_DEC_EB,
- tulip_21140_evalboard_media_probe,
- tulip_media_select,
- tulip_null_media_poll,
- tulip_2114x_media_preset,
-};
-
-static void
-tulip_21140_accton_media_probe(
- tulip_softc_t * const sc)
-{
- tulip_media_info_t *mip = sc->tulip_mediainfo;
- unsigned gpdata;
-
- sc->tulip_gpinit = TULIP_GP_EB_PINS;
- sc->tulip_gpdata = TULIP_GP_EB_INIT;
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
- TULIP_CSR_WRITE(sc, csr_command,
- TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
- TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
- TULIP_CSR_WRITE(sc, csr_command,
- TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
- DELAY(1000000);
- gpdata = TULIP_CSR_READ(sc, csr_gp);
- if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
- sc->tulip_media = TULIP_MEDIA_10BASET;
- } else {
- if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
- sc->tulip_media = TULIP_MEDIA_BNC;
- } else {
- sc->tulip_media = TULIP_MEDIA_100BASETX;
- }
- }
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
- TULIP_GP_EN1207_BNC_INIT,
- TULIP_CMD_TXTHRSHLDCTL);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
- TULIP_GP_EN1207_UTP_INIT,
- TULIP_CMD_TXTHRSHLDCTL);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
- TULIP_GP_EN1207_UTP_INIT,
- TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
- TULIP_GP_EN1207_100_INIT,
- TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
- |TULIP_CMD_SCRAMBLER);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
- TULIP_GP_EN1207_100_INIT,
- TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
- |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
-}
-
-static const tulip_boardsw_t tulip_21140_accton_boardsw = {
- TULIP_21140_EN1207,
- tulip_21140_accton_media_probe,
- tulip_media_select,
- tulip_null_media_poll,
- tulip_2114x_media_preset,
-};
-
-static void
-tulip_21140_smc9332_media_probe(
- tulip_softc_t * const sc)
-{
- tulip_media_info_t *mip = sc->tulip_mediainfo;
- int idx, cnt = 0;
-
- TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
- TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
- DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
- 33MHz that comes to two microseconds but wait a
- bit longer anyways) */
- TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
- TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
- sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
- sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
- DELAY(200000);
- for (idx = 1000; idx > 0; idx--) {
- u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
- if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
- if (++cnt > 100)
- break;
- } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
- break;
- } else {
- cnt = 0;
- }
- DELAY(1000);
- }
- sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
- TULIP_GP_SMC_9332_INIT,
- TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
- |TULIP_CMD_SCRAMBLER);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
- TULIP_GP_SMC_9332_INIT,
- TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
- |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
- TULIP_GP_SMC_9332_INIT,
- TULIP_CMD_TXTHRSHLDCTL);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
- TULIP_GP_SMC_9332_INIT,
- TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
-}
-
-static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
- TULIP_21140_SMC_9332,
- tulip_21140_smc9332_media_probe,
- tulip_media_select,
- tulip_null_media_poll,
- tulip_2114x_media_preset,
-};
-
-static void
-tulip_21140_cogent_em100_media_probe(
- tulip_softc_t * const sc)
-{
- tulip_media_info_t *mip = sc->tulip_mediainfo;
- u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
-
- sc->tulip_gpinit = TULIP_GP_EM100_PINS;
- sc->tulip_gpdata = TULIP_GP_EM100_INIT;
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
-
- cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
- cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
- if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
- TULIP_CSR_WRITE(sc, csr_command, cmdmode);
- sc->tulip_media = TULIP_MEDIA_100BASEFX;
-
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
- TULIP_GP_EM100_INIT,
- TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
- TULIP_GP_EM100_INIT,
- TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
- |TULIP_CMD_FULLDUPLEX);
- } else {
- TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
- sc->tulip_media = TULIP_MEDIA_100BASETX;
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
- TULIP_GP_EM100_INIT,
- TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
- |TULIP_CMD_SCRAMBLER);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
- TULIP_GP_EM100_INIT,
- TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
- |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
- }
-}
-
-static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
- TULIP_21140_COGENT_EM100,
- tulip_21140_cogent_em100_media_probe,
- tulip_media_select,
- tulip_null_media_poll,
- tulip_2114x_media_preset
-};
-
-static void
-tulip_21140_znyx_zx34x_media_probe(
- tulip_softc_t * const sc)
-{
- tulip_media_info_t *mip = sc->tulip_mediainfo;
- int cnt10 = 0, cnt100 = 0, idx;
-
- sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
- sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
- TULIP_CSR_WRITE(sc, csr_command,
- TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
- TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
- TULIP_CSR_WRITE(sc, csr_command,
- TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
-
- DELAY(200000);
- for (idx = 1000; idx > 0; idx--) {
- u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
- if ((csr & (TULIP_GP_ZX34X_LNKFAIL|TULIP_GP_ZX34X_SYMDET|TULIP_GP_ZX34X_SIGDET)) == (TULIP_GP_ZX34X_LNKFAIL|TULIP_GP_ZX34X_SYMDET|TULIP_GP_ZX34X_SIGDET)) {
- if (++cnt100 > 100)
- break;
- } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
- if (++cnt10 > 100)
- break;
- } else {
- cnt10 = 0;
- cnt100 = 0;
- }
- DELAY(1000);
- }
- sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
- TULIP_GP_ZX34X_INIT,
- TULIP_CMD_TXTHRSHLDCTL);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
- TULIP_GP_ZX34X_INIT,
- TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
- TULIP_GP_ZX34X_INIT,
- TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
- |TULIP_CMD_SCRAMBLER);
- tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
- TULIP_GP_ZX34X_INIT,
- TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
- |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
-}
-
-static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
- TULIP_21140_ZNYX_ZX34X,
- tulip_21140_znyx_zx34x_media_probe,
- tulip_media_select,
- tulip_null_media_poll,
- tulip_2114x_media_preset,
-};
-
-static void
-tulip_2114x_media_probe(
- tulip_softc_t * const sc)
-{
- sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE
- |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72;
-}
-
-static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
- TULIP_21140_ISV,
- tulip_2114x_media_probe,
- tulip_media_select,
- tulip_media_poll,
- tulip_2114x_media_preset,
-};
-
-/*
- * ******** END of chip-specific handlers. ***********
- */
-
-/*
- * Code the read the SROM and MII bit streams (I2C)
- */
-#define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
-
-static void
-tulip_srom_idle(
- tulip_softc_t * const sc)
-{
- unsigned bit, csr;
-
- csr = SROMSEL ; EMIT;
- csr = SROMSEL | SROMRD; EMIT;
- csr ^= SROMCS; EMIT;
- csr ^= SROMCLKON; EMIT;
-
- /*
- * Write 25 cycles of 0 which will force the SROM to be idle.
- */
- for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
- csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
- csr ^= SROMCLKON; EMIT; /* clock high; data valid */
- }
- csr ^= SROMCLKOFF; EMIT;
- csr ^= SROMCS; EMIT;
- csr = 0; EMIT;
-}
-
-
-static void
-tulip_srom_read(
- tulip_softc_t * const sc)
-{
- unsigned idx;
- const unsigned bitwidth = SROM_BITWIDTH;
- const unsigned cmdmask = (SROMCMD_RD << bitwidth);
- const unsigned msb = 1 << (bitwidth + 3 - 1);
- unsigned lastidx = (1 << bitwidth) - 1;
-
- tulip_srom_idle(sc);
-
- for (idx = 0; idx <= lastidx; idx++) {
- unsigned lastbit, data, bits, bit, csr;
- csr = SROMSEL ; EMIT;
- csr = SROMSEL | SROMRD; EMIT;
- csr ^= SROMCSON; EMIT;
- csr ^= SROMCLKON; EMIT;
-
- lastbit = 0;
- for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
- const unsigned thisbit = bits & msb;
- csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
- if (thisbit != lastbit) {
- csr ^= SROMDOUT; EMIT; /* clock low; invert data */
- } else {
- EMIT;
- }
- csr ^= SROMCLKON; EMIT; /* clock high; data valid */
- lastbit = thisbit;
- }
- csr ^= SROMCLKOFF; EMIT;
-
- for (data = 0, bits = 0; bits < 16; bits++) {
- data <<= 1;
- csr ^= SROMCLKON; EMIT; /* clock high; data valid */
- data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
- csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
- }
- sc->tulip_rombuf[idx*2] = data & 0xFF;
- sc->tulip_rombuf[idx*2+1] = data >> 8;
- csr = SROMSEL | SROMRD; EMIT;
- csr = 0; EMIT;
- }
- tulip_srom_idle(sc);
-}
-
-#define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
-
-static void
-tulip_mii_writebits(
- tulip_softc_t * const sc,
- unsigned data,
- unsigned bits)
-{
- unsigned msb = 1 << (bits - 1);
- unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
- unsigned lastbit = (csr & MII_DOUT) ? msb : 0;
-
- csr |= MII_WR; MII_EMIT; /* clock low; assert write */
-
- for (; bits > 0; bits--, data <<= 1) {
- const unsigned thisbit = data & msb;
- if (thisbit != lastbit) {
- csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
- }
- csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
- lastbit = thisbit;
- csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
- }
-}
-
-static void
-tulip_mii_turnaround(
- tulip_softc_t * const sc,
- unsigned cmd)
-{
- unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
-
- if (cmd == MII_WRCMD) {
- csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
- csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
- csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
- csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
- } else {
- csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
- }
- csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
- csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
-}
-
-static unsigned
-tulip_mii_readbits(
- tulip_softc_t * const sc)
-{
- unsigned data;
- unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
- int idx;
-
- for (idx = 0, data = 0; idx < 16; idx++) {
- data <<= 1; /* this is NOOP on the first pass through */
- csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
- if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
- data |= 1;
- csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
- }
- csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
-
- return data;
-}
-
-static unsigned
-tulip_mii_readreg(
- tulip_softc_t * const sc,
- unsigned devaddr,
- unsigned regno)
-{
- unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
- unsigned data;
-
- csr &= ~(MII_RD|MII_CLK); MII_EMIT;
- tulip_mii_writebits(sc, MII_PREAMBLE, 32);
- tulip_mii_writebits(sc, MII_RDCMD, 8);
- tulip_mii_writebits(sc, devaddr, 5);
- tulip_mii_writebits(sc, regno, 5);
- tulip_mii_turnaround(sc, MII_RDCMD);
-
- data = tulip_mii_readbits(sc);
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_phyregs[regno][0] = data;
- sc->tulip_dbg.dbg_phyregs[regno][1]++;
-#endif
- return data;
-}
-
-static void
-tulip_mii_writereg(
- tulip_softc_t * const sc,
- unsigned devaddr,
- unsigned regno,
- unsigned data)
-{
- unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
- csr &= ~(MII_RD|MII_CLK); MII_EMIT;
- tulip_mii_writebits(sc, MII_PREAMBLE, 32);
- tulip_mii_writebits(sc, MII_WRCMD, 8);
- tulip_mii_writebits(sc, devaddr, 5);
- tulip_mii_writebits(sc, regno, 5);
- tulip_mii_turnaround(sc, MII_WRCMD);
- tulip_mii_writebits(sc, data, 16);
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_phyregs[regno][2] = data;
- sc->tulip_dbg.dbg_phyregs[regno][3]++;
-#endif
-}
-
-#define tulip_mchash(mca) (tulip_crc32(mca, 6) & 0x1FF)
-#define tulip_srom_crcok(databuf) ( \
- ((tulip_crc32(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
- ((databuf)[126] | ((databuf)[127] << 8)))
-
-static unsigned
-tulip_crc32(
- const unsigned char *databuf,
- size_t datalen)
-{
- u_int idx, crc = 0xFFFFFFFFUL;
- static const u_int crctab[] = {
- 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
- 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
- 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
- 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
- };
-
- for (idx = 0; idx < datalen; idx++) {
- crc ^= *databuf++;
- crc = (crc >> 4) ^ crctab[crc & 0xf];
- crc = (crc >> 4) ^ crctab[crc & 0xf];
- }
- return crc;
-}
-
-static void
-tulip_identify_dec_nic(
- tulip_softc_t * const sc)
-{
- strcpy(sc->tulip_boardid, "DEC ");
-#define D0 4
- if (sc->tulip_chipid <= TULIP_21040)
- return;
- if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
- || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
- bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
- sc->tulip_boardid[D0+8] = ' ';
- }
-#undef D0
-}
-
-static void
-tulip_identify_znyx_nic(
- tulip_softc_t * const sc)
-{
- unsigned id = 0;
- strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
- if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
- unsigned znyx_ptr;
- sc->tulip_boardid[8] = '4';
- znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
- if (znyx_ptr < 26 || znyx_ptr > 116) {
- sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
- return;
- }
- /* ZX344 = 0010 .. 0013FF
- */
- if (sc->tulip_rombuf[znyx_ptr] == 0x4A
- && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
- && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
- id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
- if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
- sc->tulip_boardid[9] = '2';
- if (id == TULIP_ZNYX_ID_ZX342B) {
- sc->tulip_boardid[10] = 'B';
- sc->tulip_boardid[11] = ' ';
- }
- sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
- } else if (id == TULIP_ZNYX_ID_ZX344) {
- sc->tulip_boardid[10] = '4';
- sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
- } else if (id == TULIP_ZNYX_ID_ZX345) {
- sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
- } else if (id == TULIP_ZNYX_ID_ZX346) {
- sc->tulip_boardid[9] = '6';
- } else if (id == TULIP_ZNYX_ID_ZX351) {
- sc->tulip_boardid[8] = '5';
- sc->tulip_boardid[9] = '1';
- }
- }
- if (id == 0) {
- /*
- * Assume it's a ZX342...
- */
- sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
- }
- return;
- }
- sc->tulip_boardid[8] = '1';
- if (sc->tulip_chipid == TULIP_21041) {
- sc->tulip_boardid[10] = '1';
- return;
- }
- if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
- id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
- if (id == TULIP_ZNYX_ID_ZX312T) {
- sc->tulip_boardid[9] = '2';
- sc->tulip_boardid[10] = 'T';
- sc->tulip_boardid[11] = ' ';
- sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
- } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
- sc->tulip_boardid[9] = '4';
- sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
- sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
- } else if (id == TULIP_ZNYX_ID_ZX314) {
- sc->tulip_boardid[9] = '4';
- sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
- sc->tulip_features |= TULIP_HAVE_BASEROM;
- } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
- sc->tulip_boardid[9] = '5';
- sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
- } else if (id == TULIP_ZNYX_ID_ZX315) {
- sc->tulip_boardid[9] = '5';
- sc->tulip_features |= TULIP_HAVE_BASEROM;
- } else {
- id = 0;
- }
- }
- if (id == 0) {
- if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
- sc->tulip_boardid[9] = '4';
- sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
- sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
- } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
- sc->tulip_boardid[9] = '5';
- sc->tulip_boardsw = &tulip_21040_boardsw;
- sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
- } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
- sc->tulip_boardid[9] = '2';
- sc->tulip_boardsw = &tulip_21040_boardsw;
- }
- }
-}
-
-static void
-tulip_identify_smc_nic(
- tulip_softc_t * const sc)
-{
- u_int32_t id1, id2, ei;
- int auibnc = 0, utp = 0;
- char *cp;
-
- strcpy(sc->tulip_boardid, "SMC ");
- if (sc->tulip_chipid == TULIP_21041)
- return;
- if (sc->tulip_chipid != TULIP_21040) {
- if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
- strcpy(&sc->tulip_boardid[4], "9332DST ");
- sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
- } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
- strcpy(&sc->tulip_boardid[4], "9334BDT ");
- } else {
- strcpy(&sc->tulip_boardid[4], "9332BDT ");
- }
- return;
- }
- id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
- id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
- ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
-
- strcpy(&sc->tulip_boardid[4], "8432");
- cp = &sc->tulip_boardid[8];
- if ((id1 & 1) == 0)
- *cp++ = 'B', auibnc = 1;
- if ((id1 & 0xFF) > 0x32)
- *cp++ = 'T', utp = 1;
- if ((id1 & 0x4000) == 0)
- *cp++ = 'A', auibnc = 1;
- if (id2 == 0x15) {
- sc->tulip_boardid[7] = '4';
- *cp++ = '-';
- *cp++ = 'C';
- *cp++ = 'H';
- *cp++ = (ei ? '2' : '1');
- }
- *cp++ = ' ';
- *cp = '\0';
- if (utp && !auibnc)
- sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
- else if (!utp && auibnc)
- sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
-}
-
-static void
-tulip_identify_cogent_nic(
- tulip_softc_t * const sc)
-{
- strcpy(sc->tulip_boardid, "Cogent ");
- if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
- if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
- strcat(sc->tulip_boardid, "EM100TX ");
- sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
-#if defined(TULIP_COGENT_EM110TX_ID)
- } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
- strcat(sc->tulip_boardid, "EM110TX ");
- sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
-#endif
- } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
- strcat(sc->tulip_boardid, "EM100FX ");
- sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
- }
- /*
- * Magic number (0x24001109U) is the SubVendor (0x2400) and
- * SubDevId (0x1109) for the ANA6944TX (EM440TX).
- */
- if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U
- && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
- /*
- * Cogent (Adaptec) is still mapping all INTs to INTA of
- * first 21140. Dumb! Dumb!
- */
- strcat(sc->tulip_boardid, "EM440TX ");
- sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
- }
- } else if (sc->tulip_chipid == TULIP_21040) {
- sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
- }
-}
-
-static void
-tulip_identify_accton_nic(
- tulip_softc_t * const sc)
-{
- strcpy(sc->tulip_boardid, "ACCTON ");
- switch (sc->tulip_chipid) {
- case TULIP_21140A:
- strcat(sc->tulip_boardid, "EN1207 ");
- if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
- sc->tulip_boardsw = &tulip_21140_accton_boardsw;
- break;
- case TULIP_21140:
- strcat(sc->tulip_boardid, "EN1207TX ");
- if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
- sc->tulip_boardsw = &tulip_21140_eb_boardsw;
- break;
- case TULIP_21040:
- strcat(sc->tulip_boardid, "EN1203 ");
- sc->tulip_boardsw = &tulip_21040_boardsw;
- break;
- case TULIP_21041:
- strcat(sc->tulip_boardid, "EN1203 ");
- sc->tulip_boardsw = &tulip_21041_boardsw;
- break;
- default:
- sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
- break;
- }
-}
-
-static void
-tulip_identify_asante_nic(
- tulip_softc_t * const sc)
-{
- strcpy(sc->tulip_boardid, "Asante ");
- if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
- && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
- tulip_media_info_t *mi = sc->tulip_mediainfo;
- int idx;
- /*
- * The Asante Fast Ethernet doesn't always ship with a valid
- * new format SROM. So if isn't in the new format, we cheat
- * set it up as if we had.
- */
-
- sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
- sc->tulip_gpdata = 0;
-
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
- TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
- DELAY(100);
- TULIP_CSR_WRITE(sc, csr_gp, 0);
-
- mi->mi_type = TULIP_MEDIAINFO_MII;
- mi->mi_gpr_length = 0;
- mi->mi_gpr_offset = 0;
- mi->mi_reset_length = 0;
- mi->mi_reset_offset = 0;;
-
- mi->mi_phyaddr = TULIP_MII_NOPHY;
- for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
- DELAY(10000);
- mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
- }
- if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
- printf("%s%d: can't find phy 0\n", sc->tulip_name, sc->tulip_unit);
- return;
- }
-
- sc->tulip_features |= TULIP_HAVE_MII;
- mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
- mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
- mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
- mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
- mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
- tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
-
- sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
- }
-}
-
-static void
-tulip_identify_compex_nic(
- tulip_softc_t * const sc)
-{
- strcpy(sc->tulip_boardid, "COMPEX ");
- if (sc->tulip_chipid == TULIP_21140A) {
- int root_unit;
- tulip_softc_t *root_sc = NULL;
-
- strcat(sc->tulip_boardid, "400TX/PCI ");
- /*
- * All 4 chips on these boards share an interrupt. This code
- * copied from tulip_read_macaddr.
- */
- sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
- for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
- root_sc = tulips[root_unit];
- if (root_sc == NULL
- || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
- break;
- root_sc = NULL;
- }
- if (root_sc != NULL
- && root_sc->tulip_chipid == sc->tulip_chipid
- && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
- sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
- sc->tulip_slaves = root_sc->tulip_slaves;
- root_sc->tulip_slaves = sc;
- } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
- printf("\nCannot find master device for de%d interrupts",
- sc->tulip_unit);
- }
- } else {
- strcat(sc->tulip_boardid, "unknown ");
- }
- /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
- return;
-}
-
-static int
-tulip_srom_decode(
- tulip_softc_t * const sc)
-{
- unsigned idx1, idx2, idx3;
-
- const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
- const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
- tulip_srom_media_t srom_media;
- tulip_media_info_t *mi = sc->tulip_mediainfo;
- const u_int8_t *dp;
- u_int32_t leaf_offset, blocks, data;
-
- for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
- if (shp->sh_adapter_count == 1)
- break;
- if (saip->sai_device == sc->tulip_pci_devno)
- break;
- }
- /*
- * Didn't find the right media block for this card.
- */
- if (idx1 == shp->sh_adapter_count)
- return 0;
-
- /*
- * Save the hardware address.
- */
- bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
- /*
- * If this is a multiple port card, add the adapter index to the last
- * byte of the hardware address. (if it isn't multiport, adding 0
- * won't hurt.
- */
- sc->tulip_enaddr[5] += idx1;
-
- leaf_offset = saip->sai_leaf_offset_lowbyte
- + saip->sai_leaf_offset_highbyte * 256;
- dp = sc->tulip_rombuf + leaf_offset;
-
- sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
-
- for (idx2 = 0;; idx2++) {
- if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
- || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
- break;
- }
- sc->tulip_connidx = idx2;
-
- if (sc->tulip_chipid == TULIP_21041) {
- blocks = *dp++;
- for (idx2 = 0; idx2 < blocks; idx2++) {
- tulip_media_t media;
- data = *dp++;
- srom_media = (tulip_srom_media_t) (data & 0x3F);
- for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
- if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
- break;
- }
- media = tulip_srom_mediums[idx3].sm_type;
- if (media != TULIP_MEDIA_UNKNOWN) {
- if (data & TULIP_SROM_21041_EXTENDED) {
- mi->mi_type = TULIP_MEDIAINFO_SIA;
- sc->tulip_mediums[media] = mi;
- mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
- mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
- mi->mi_sia_general = dp[4] + dp[5] * 256;
- mi++;
- } else {
- switch (media) {
- case TULIP_MEDIA_BNC: {
- TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
- mi++;
- break;
- }
- case TULIP_MEDIA_AUI: {
- TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
- mi++;
- break;
- }
- case TULIP_MEDIA_10BASET: {
- TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
- mi++;
- break;
- }
- case TULIP_MEDIA_10BASET_FD: {
- TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
- mi++;
- break;
- }
- default: {
- break;
- }
- }
- }
- }
- if (data & TULIP_SROM_21041_EXTENDED)
- dp += 6;
- }
-#ifdef notdef
- if (blocks == 0) {
- TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
- TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
- TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
- TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
- }
-#endif
- } else {
- unsigned length, type;
- tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
- if (sc->tulip_features & TULIP_HAVE_GPR)
- sc->tulip_gpinit = *dp++;
- blocks = *dp++;
- for (idx2 = 0; idx2 < blocks; idx2++) {
- const u_int8_t *ep;
- if ((*dp & 0x80) == 0) {
- length = 4;
- type = 0;
- } else {
- length = (*dp++ & 0x7f) - 1;
- type = *dp++ & 0x3f;
- }
- ep = dp + length;
- switch (type & 0x3f) {
- case 0: { /* 21140[A] GPR block */
- tulip_media_t media;
- srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
- for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
- if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
- break;
- }
- media = tulip_srom_mediums[idx3].sm_type;
- if (media == TULIP_MEDIA_UNKNOWN)
- break;
- mi->mi_type = TULIP_MEDIAINFO_GPR;
- sc->tulip_mediums[media] = mi;
- mi->mi_gpdata = dp[1];
- if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
- sc->tulip_gpdata = mi->mi_gpdata;
- gp_media = media;
- }
- data = dp[2] + dp[3] * 256;
- mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
- if (data & TULIP_SROM_2114X_NOINDICATOR) {
- mi->mi_actmask = 0;
- } else {
-#if 0
- mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
-#endif
- mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
- mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
- }
- mi++;
- break;
- }
- case 1: { /* 21140[A] MII block */
- const unsigned phyno = *dp++;
- mi->mi_type = TULIP_MEDIAINFO_MII;
- mi->mi_gpr_length = *dp++;
- mi->mi_gpr_offset = dp - sc->tulip_rombuf;
- dp += mi->mi_gpr_length;
- mi->mi_reset_length = *dp++;
- mi->mi_reset_offset = dp - sc->tulip_rombuf;
- dp += mi->mi_reset_length;
-
- /*
- * Before we probe for a PHY, use the GPR information
- * to select it. If we don't, it may be inaccessible.
- */
- TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
- for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
- DELAY(10);
- TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
- }
- sc->tulip_phyaddr = mi->mi_phyaddr;
- for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
- DELAY(10);
- TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
- }
-
- /*
- * At least write something!
- */
- if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
- TULIP_CSR_WRITE(sc, csr_gp, 0);
-
- mi->mi_phyaddr = TULIP_MII_NOPHY;
- for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
- DELAY(10000);
- mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
- }
- if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
-#if defined(TULIP_DEBUG)
- printf("%s%d: can't find phy %d\n",
- sc->tulip_name, sc->tulip_unit, phyno);
-#endif
- break;
- }
- sc->tulip_features |= TULIP_HAVE_MII;
- mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
- mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
- mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
- mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
- mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
- tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
- mi++;
- break;
- }
- case 2: { /* 2114[23] SIA block */
- tulip_media_t media;
- srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
- for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
- if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
- break;
- }
- media = tulip_srom_mediums[idx3].sm_type;
- if (media == TULIP_MEDIA_UNKNOWN)
- break;
- mi->mi_type = TULIP_MEDIAINFO_SIA;
- sc->tulip_mediums[media] = mi;
- if (dp[0] & 0x40) {
- mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
- mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
- mi->mi_sia_general = dp[5] + dp[6] * 256;
- dp += 6;
- } else {
- switch (media) {
- case TULIP_MEDIA_BNC: {
- TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
- break;
- }
- case TULIP_MEDIA_AUI: {
- TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
- break;
- }
- case TULIP_MEDIA_10BASET: {
- TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
- sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
- break;
- }
- case TULIP_MEDIA_10BASET_FD: {
- TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
- sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
- break;
- }
- default: {
- goto bad_media;
- }
- }
- }
- mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
- mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
- mi++;
- bad_media:
- break;
- }
- case 3: { /* 2114[23] MII PHY block */
- const unsigned phyno = *dp++;
- const u_int8_t *dp0;
- mi->mi_type = TULIP_MEDIAINFO_MII;
- mi->mi_gpr_length = *dp++;
- mi->mi_gpr_offset = dp - sc->tulip_rombuf;
- dp += 2 * mi->mi_gpr_length;
- mi->mi_reset_length = *dp++;
- mi->mi_reset_offset = dp - sc->tulip_rombuf;
- dp += 2 * mi->mi_reset_length;
-
- dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
- for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
- DELAY(10);
- TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
- }
- sc->tulip_phyaddr = mi->mi_phyaddr;
- dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
- for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
- DELAY(10);
- TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
- }
-
- if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
- TULIP_CSR_WRITE(sc, csr_sia_general, 0);
-
- mi->mi_phyaddr = TULIP_MII_NOPHY;
- for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
- DELAY(10000);
- mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
- }
- if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
-#if defined(TULIP_DEBUG)
- printf("%s%d: can't find phy %d\n",
- sc->tulip_name, sc->tulip_unit, phyno);
-#endif
- break;
- }
- sc->tulip_features |= TULIP_HAVE_MII;
- mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
- mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
- mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
- mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
- mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
- TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
- mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
- tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
- mi++;
- break;
- }
- case 4: { /* 21143 SYM block */
- tulip_media_t media;
- srom_media = (tulip_srom_media_t) dp[0];
- for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
- if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
- break;
- }
- media = tulip_srom_mediums[idx3].sm_type;
- if (media == TULIP_MEDIA_UNKNOWN)
- break;
- mi->mi_type = TULIP_MEDIAINFO_SYM;
- sc->tulip_mediums[media] = mi;
- mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
- mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
- data = dp[5] + dp[6] * 256;
- mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
- if (data & TULIP_SROM_2114X_NOINDICATOR) {
- mi->mi_actmask = 0;
- } else {
- mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
- mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
- mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
- }
- if (TULIP_IS_MEDIA_TP(media))
- sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
- mi++;
- break;
- }
-#if 0
- case 5: { /* 21143 Reset block */
- mi->mi_type = TULIP_MEDIAINFO_RESET;
- mi->mi_reset_length = *dp++;
- mi->mi_reset_offset = dp - sc->tulip_rombuf;
- dp += 2 * mi->mi_reset_length;
- mi++;
- break;
- }
-#endif
- default: {
- }
- }
- dp = ep;
- }
- }
- return mi - sc->tulip_mediainfo;
-}
-
-static const struct {
- void (*vendor_identify_nic)(tulip_softc_t * const sc);
- unsigned char vendor_oui[3];
-} tulip_vendors[] = {
- { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
- { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
- { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
- { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
- { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
- { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
- { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
- { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
- { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
- { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
- { NULL }
-};
-
-/*
- * This deals with the vagaries of the address roms and the
- * brain-deadness that various vendors commit in using them.
- */
-static int
-tulip_read_macaddr(
- tulip_softc_t * const sc)
-{
- unsigned cksum, rom_cksum, idx;
- u_int32_t csr;
- unsigned char tmpbuf[8];
- static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
-
- sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
-
- if (sc->tulip_chipid == TULIP_21040) {
- TULIP_CSR_WRITE(sc, csr_enetrom, 1);
- for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
- int cnt = 0;
- while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
- cnt++;
- sc->tulip_rombuf[idx] = csr & 0xFF;
- }
- sc->tulip_boardsw = &tulip_21040_boardsw;
- } else {
- if (sc->tulip_chipid == TULIP_21041) {
- /*
- * Thankfully all 21041's act the same.
- */
- sc->tulip_boardsw = &tulip_21041_boardsw;
- } else {
- /*
- * Assume all 21140 board are compatible with the
- * DEC 10/100 evaluation board. Not really valid but
- * it's the best we can do until every one switches to
- * the new SROM format.
- */
-
- sc->tulip_boardsw = &tulip_21140_eb_boardsw;
- }
- tulip_srom_read(sc);
- if (tulip_srom_crcok(sc->tulip_rombuf)) {
- /*
- * SROM CRC is valid therefore it must be in the
- * new format.
- */
- sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
- } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
- /*
- * No checksum is present. See if the SROM id checks out;
- * the first 18 bytes should be 0 followed by a 1 followed
- * by the number of adapters (which we don't deal with yet).
- */
- for (idx = 0; idx < 18; idx++) {
- if (sc->tulip_rombuf[idx] != 0)
- break;
- }
- if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
- sc->tulip_features |= TULIP_HAVE_ISVSROM;
- } else if (sc->tulip_chipid >= TULIP_21142) {
- sc->tulip_features |= TULIP_HAVE_ISVSROM;
- sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
- }
- if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
- if (sc->tulip_chipid != TULIP_21041)
- sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
-
- /*
- * If the SROM specifies more than one adapter, tag this as a
- * BASE rom.
- */
- if (sc->tulip_rombuf[19] > 1)
- sc->tulip_features |= TULIP_HAVE_BASEROM;
- if (sc->tulip_boardsw == NULL)
- return -6;
- goto check_oui;
- }
- }
-
-
- if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
- /*
- * Some folks don't use the standard ethernet rom format
- * but instead just put the address in the first 6 bytes
- * of the rom and let the rest be all 0xffs. (Can we say
- * ZNYX?) (well sometimes they put in a checksum so we'll
- * start at 8).
- */
- for (idx = 8; idx < 32; idx++) {
- if (sc->tulip_rombuf[idx] != 0xFF)
- return -4;
- }
- /*
- * Make sure the address is not multicast or locally assigned
- * that the OUI is not 00-00-00.
- */
- if ((sc->tulip_rombuf[0] & 3) != 0)
- return -4;
- if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
- && sc->tulip_rombuf[2] == 0)
- return -4;
- bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
- sc->tulip_features |= TULIP_HAVE_OKROM;
- goto check_oui;
- } else {
- /*
- * A number of makers of multiport boards (ZNYX and Cogent)
- * only put on one address ROM on their 21040 boards. So
- * if the ROM is all zeros (or all 0xFFs), look at the
- * previous configured boards (as long as they are on the same
- * PCI bus and the bus number is non-zero) until we find the
- * master board with address ROM. We then use its address ROM
- * as the base for this board. (we add our relative board
- * to the last byte of its address).
- */
- for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
- if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
- break;
- }
- if (idx == sizeof(sc->tulip_rombuf)) {
- int root_unit;
- tulip_softc_t *root_sc = NULL;
- for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
- root_sc = tulips[root_unit];
- if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
- break;
- root_sc = NULL;
- }
- if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
- && root_sc->tulip_chipid == sc->tulip_chipid
- && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
- sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
- sc->tulip_boardsw = root_sc->tulip_boardsw;
- strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
- if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
- bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
- sizeof(sc->tulip_rombuf));
- if (!tulip_srom_decode(sc))
- return -5;
- } else {
- bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
- sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
- }
- /*
- * Now for a truly disgusting kludge: all 4 21040s on
- * the ZX314 share the same INTA line so the mapping
- * setup by the BIOS on the PCI bridge is worthless.
- * Rather than reprogramming the value in the config
- * register, we will handle this internally.
- */
- if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
- sc->tulip_slaves = root_sc->tulip_slaves;
- root_sc->tulip_slaves = sc;
- sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
- }
- return 0;
- }
- }
- }
-
- /*
- * This is the standard DEC address ROM test.
- */
-
- if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
- return -3;
-
- tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
- tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
- tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
- tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
- if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
- return -2;
-
- bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
-
- cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
- cksum *= 2;
- if (cksum > 65535) cksum -= 65535;
- cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
- if (cksum > 65535) cksum -= 65535;
- cksum *= 2;
- if (cksum > 65535) cksum -= 65535;
- cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
- if (cksum >= 65535) cksum -= 65535;
-
- rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
-
- if (cksum != rom_cksum)
- return -1;
-
- check_oui:
- /*
- * Check for various boards based on OUI. Did I say braindead?
- */
- for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
- if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
- (*tulip_vendors[idx].vendor_identify_nic)(sc);
- break;
- }
- }
-
- sc->tulip_features |= TULIP_HAVE_OKROM;
- return 0;
-}
-
-static void
-tulip_ifmedia_add(
- tulip_softc_t * const sc)
-{
- tulip_media_t media;
- int medias = 0;
-
- for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
- if (sc->tulip_mediums[media] != NULL) {
- ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
- 0, 0);
- medias++;
- }
- }
- if (medias == 0) {
- sc->tulip_features |= TULIP_HAVE_NOMEDIA;
- ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
- ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
- } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
- ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
- ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
- } else {
- ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
- sc->tulip_flags |= TULIP_PRINTMEDIA;
- tulip_linkup(sc, sc->tulip_media);
- }
-}
-
-static int
-tulip_ifmedia_change(
- struct ifnet * const ifp)
-{
- tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
-
- sc->tulip_flags |= TULIP_NEEDRESET;
- sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
- sc->tulip_media = TULIP_MEDIA_UNKNOWN;
- if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
- tulip_media_t media;
- for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
- if (sc->tulip_mediums[media] != NULL
- && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
- sc->tulip_flags |= TULIP_PRINTMEDIA;
- sc->tulip_flags &= ~TULIP_DIDNWAY;
- tulip_linkup(sc, media);
- return 0;
- }
- }
- }
- sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
- tulip_reset(sc);
- tulip_init(sc);
- return 0;
-}
-
-/*
- * Media status callback
- */
-static void
-tulip_ifmedia_status(
- struct ifnet * const ifp,
- struct ifmediareq *req)
-{
- tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
-
- if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
- return;
-
- req->ifm_status = IFM_AVALID;
- if (sc->tulip_flags & TULIP_LINKUP)
- req->ifm_status |= IFM_ACTIVE;
-
- req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
-}
-
-static void
-tulip_addr_filter(
- tulip_softc_t * const sc)
-{
- struct ifmultiaddr *ifma;
- u_char *addrp;
- int multicnt;
-
- sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
- sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
- sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
- sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
-#if defined(IFF_ALLMULTI)
- if (sc->tulip_if.if_flags & IFF_ALLMULTI)
- sc->tulip_flags |= TULIP_ALLMULTI ;
-#endif
-
- multicnt = 0;
- TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
-
- if (ifma->ifma_addr->sa_family == AF_LINK)
- multicnt++;
- }
-
- sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
- if (multicnt > 14) {
- u_int32_t *sp = sc->tulip_setupdata;
- unsigned hash;
- /*
- * Some early passes of the 21140 have broken implementations of
- * hash-perfect mode. When we get too many multicasts for perfect
- * filtering with these chips, we need to switch into hash-only
- * mode (this is better than all-multicast on network with lots
- * of multicast traffic).
- */
- if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
- sc->tulip_flags |= TULIP_WANTHASHONLY;
- else
- sc->tulip_flags |= TULIP_WANTHASHPERFECT;
- /*
- * If we have more than 14 multicasts, we have
- * go into hash perfect mode (512 bit multicast
- * hash and one perfect hardware).
- */
- bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
-
- TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
-
- if (ifma->ifma_addr->sa_family != AF_LINK)
- continue;
-
- hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
-#if BYTE_ORDER == BIG_ENDIAN
- sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
-#else
- sp[hash >> 4] |= 1 << (hash & 0xF);
-#endif
- }
- /*
- * No reason to use a hash if we are going to be
- * receiving every multicast.
- */
- if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
- hash = tulip_mchash(sc->tulip_if.if_broadcastaddr);
-#if BYTE_ORDER == BIG_ENDIAN
- sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
-#else
- sp[hash >> 4] |= 1 << (hash & 0xF);
-#endif
- if (sc->tulip_flags & TULIP_WANTHASHONLY) {
- hash = tulip_mchash(sc->tulip_enaddr);
-#if BYTE_ORDER == BIG_ENDIAN
- sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
-#else
- sp[hash >> 4] |= 1 << (hash & 0xF);
-#endif
- } else {
-#if BYTE_ORDER == BIG_ENDIAN
- sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
- sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
- sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
-#else
- sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
- sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
- sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
-#endif
- }
- }
- }
- if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
- u_int32_t *sp = sc->tulip_setupdata;
- int idx = 0;
- if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
- /*
- * Else can get perfect filtering for 16 addresses.
- */
- TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
- if (ifma->ifma_addr->sa_family != AF_LINK)
- continue;
- addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
-#if BYTE_ORDER == BIG_ENDIAN
- *sp++ = ((u_int16_t *) addrp)[0] << 16;
- *sp++ = ((u_int16_t *) addrp)[1] << 16;
- *sp++ = ((u_int16_t *) addrp)[2] << 16;
-#else
- *sp++ = ((u_int16_t *) addrp)[0];
- *sp++ = ((u_int16_t *) addrp)[1];
- *sp++ = ((u_int16_t *) addrp)[2];
-#endif
- idx++;
- }
- /*
- * Add the broadcast address.
- */
- idx++;
-#if BYTE_ORDER == BIG_ENDIAN
- *sp++ = 0xFFFF << 16;
- *sp++ = 0xFFFF << 16;
- *sp++ = 0xFFFF << 16;
-#else
- *sp++ = 0xFFFF;
- *sp++ = 0xFFFF;
- *sp++ = 0xFFFF;
-#endif
- }
- /*
- * Pad the rest with our hardware address
- */
- for (; idx < 16; idx++) {
-#if BYTE_ORDER == BIG_ENDIAN
- *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
- *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
- *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
-#else
- *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
- *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
- *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
-#endif
- }
- }
-#if defined(IFF_ALLMULTI)
- if (sc->tulip_flags & TULIP_ALLMULTI)
- sc->tulip_if.if_flags |= IFF_ALLMULTI;
-#endif
-}
-
-static void
-tulip_reset(
- tulip_softc_t * const sc)
-{
- tulip_ringinfo_t *ri;
- tulip_desc_t *di;
- u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET);
-
- /*
- * Brilliant. Simply brilliant. When switching modes/speeds
- * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
- * bits in CSR6 and then do a software reset to get the 21140
- * to properly reset its internal pathways to the right places.
- * Grrrr.
- */
- if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
- && sc->tulip_boardsw->bd_media_preset != NULL)
- (*sc->tulip_boardsw->bd_media_preset)(sc);
-
- TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
- DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
- 33MHz that comes to two microseconds but wait a
- bit longer anyways) */
-
- if (!inreset) {
- sc->tulip_flags |= TULIP_INRESET;
- sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
- sc->tulip_if.if_flags &= ~IFF_OACTIVE;
- sc->tulip_if.if_start = tulip_ifstart;
- }
-
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txdescmap->dm_segs[0].ds_addr);
-#else
- TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
-#endif
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxdescmap->dm_segs[0].ds_addr);
-#else
- TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
-#endif
- TULIP_CSR_WRITE(sc, csr_busmode,
- (1 << (3 /*pci_max_burst_len*/ + 8))
- |TULIP_BUSMODE_CACHE_ALIGN8
- |TULIP_BUSMODE_READMULTIPLE
- |(BYTE_ORDER != LITTLE_ENDIAN ?
- TULIP_BUSMODE_DESC_BIGENDIAN : 0));
-
- sc->tulip_txtimer = 0;
- sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
- /*
- * Free all the mbufs that were on the transmit ring.
- */
- for (;;) {
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- bus_dmamap_t map;
-#endif
- struct mbuf *m;
- _IF_DEQUEUE(&sc->tulip_txq, m);
- if (m == NULL)
- break;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- map = M_GETCTX(m, bus_dmamap_t);
- bus_dmamap_unload(sc->tulip_dmatag, map);
- sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
-#endif
- m_freem(m);
- }
-
- ri = &sc->tulip_txinfo;
- ri->ri_nextin = ri->ri_nextout = ri->ri_first;
- ri->ri_free = ri->ri_max;
- for (di = ri->ri_first; di < ri->ri_last; di++)
- di->d_status = 0;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap,
- 0, sc->tulip_txdescmap->dm_mapsize,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
-#endif
-
- /*
- * We need to collect all the mbufs were on the
- * receive ring before we reinit it either to put
- * them back on or to know if we have to allocate
- * more.
- */
- ri = &sc->tulip_rxinfo;
- ri->ri_nextin = ri->ri_nextout = ri->ri_first;
- ri->ri_free = ri->ri_max;
- for (di = ri->ri_first; di < ri->ri_last; di++) {
- di->d_status = 0;
- di->d_length1 = 0; di->d_addr1 = 0;
- di->d_length2 = 0; di->d_addr2 = 0;
- }
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap,
- 0, sc->tulip_rxdescmap->dm_mapsize,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
-#endif
- for (;;) {
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- bus_dmamap_t map;
-#endif
- struct mbuf *m;
- _IF_DEQUEUE(&sc->tulip_rxq, m);
- if (m == NULL)
- break;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- map = M_GETCTX(m, bus_dmamap_t);
- bus_dmamap_unload(sc->tulip_dmatag, map);
- sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
-#endif
- m_freem(m);
- }
-
- /*
- * If tulip_reset is being called recurisvely, exit quickly knowing
- * that when the outer tulip_reset returns all the right stuff will
- * have happened.
- */
- if (inreset)
- return;
-
- sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
- |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
- |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
- |TULIP_STS_RXSTOPPED;
-
- if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
- (*sc->tulip_boardsw->bd_media_select)(sc);
-#if defined(TULIP_DEBUG)
- if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET)
- printf("%s%d: tulip_reset: additional reset needed?!?\n",
- sc->tulip_name, sc->tulip_unit);
-#endif
- tulip_media_print(sc);
- if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
- TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
-
- sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
- |TULIP_RXACT);
- tulip_addr_filter(sc);
-}
-
-
-static void
-tulip_ifinit(
- void * sc)
-{
- tulip_init((tulip_softc_t *)sc);
-}
-
-static void
-tulip_init(
- tulip_softc_t * const sc)
-{
- if (sc->tulip_if.if_flags & IFF_UP) {
- if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
- /* initialize the media */
- tulip_reset(sc);
- }
- sc->tulip_if.if_flags |= IFF_RUNNING;
- if (sc->tulip_if.if_flags & IFF_PROMISC) {
- sc->tulip_flags |= TULIP_PROMISC;
- sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
- sc->tulip_intrmask |= TULIP_STS_TXINTR;
- } else {
- sc->tulip_flags &= ~TULIP_PROMISC;
- sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
- if (sc->tulip_flags & TULIP_ALLMULTI) {
- sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
- } else {
- sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
- }
- }
- sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
- if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
- tulip_rx_intr(sc);
- sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
- sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
- } else {
- sc->tulip_if.if_flags |= IFF_OACTIVE;
- sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
- sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
- }
- TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
- TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
- if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
- tulip_txput_setup(sc);
- } else {
- sc->tulip_if.if_flags &= ~IFF_RUNNING;
- tulip_reset(sc);
- }
-}
-
-static void
-tulip_rx_intr(
- tulip_softc_t * const sc)
-{
- TULIP_PERFSTART(rxintr)
- tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
- struct ifnet * const ifp = &sc->tulip_if;
- int fillok = 1;
-#if defined(TULIP_DEBUG)
- int cnt = 0;
-#endif
-
- for (;;) {
- TULIP_PERFSTART(rxget)
- struct ether_header eh;
- tulip_desc_t *eop = ri->ri_nextin;
- int total_len = 0, last_offset = 0;
- struct mbuf *ms = NULL, *me = NULL;
- int accept = 0;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- bus_dmamap_t map;
- int error;
-#endif
-
- if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
- goto queue_mbuf;
-
-#if defined(TULIP_DEBUG)
- if (cnt == ri->ri_max)
- break;
-#endif
- /*
- * If the TULIP has no descriptors, there can't be any receive
- * descriptors to process.
- */
- if (eop == ri->ri_nextout)
- break;
-
- /*
- * 90% of the packets will fit in one descriptor. So we optimize
- * for that case.
- */
- TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
- if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
- _IF_DEQUEUE(&sc->tulip_rxq, ms);
- me = ms;
- } else {
- /*
- * If still owned by the TULIP, don't touch it.
- */
- if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
- break;
-
- /*
- * It is possible (though improbable unless the BIG_PACKET support
- * is enabled or MCLBYTES < 1518) for a received packet to cross
- * more than one receive descriptor.
- */
- while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
- if (++eop == ri->ri_last)
- eop = ri->ri_first;
- TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
- if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_rxintrs++;
- sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
-#endif
- TULIP_PERFEND(rxget);
- TULIP_PERFEND(rxintr);
- return;
- }
- total_len++;
- }
-
- /*
- * Dequeue the first buffer for the start of the packet. Hopefully
- * this will be the only one we need to dequeue. However, if the
- * packet consumed multiple descriptors, then we need to dequeue
- * those buffers and chain to the starting mbuf. All buffers but
- * the last buffer have the same length so we can set that now.
- * (we add to last_offset instead of multiplying since we normally
- * won't go into the loop and thereby saving ourselves from
- * doing a multiplication by 0 in the normal case).
- */
- _IF_DEQUEUE(&sc->tulip_rxq, ms);
- for (me = ms; total_len > 0; total_len--) {
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- map = M_GETCTX(me, bus_dmamap_t);
- TULIP_RXMAP_POSTSYNC(sc, map);
- bus_dmamap_unload(sc->tulip_dmatag, map);
- sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
-#if defined(DIAGNOSTIC)
- M_SETCTX(me, NULL);
-#endif
-#endif /* TULIP_BUS_DMA */
- me->m_len = TULIP_RX_BUFLEN;
- last_offset += TULIP_RX_BUFLEN;
- _IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
- me = me->m_next;
- }
- }
-
- /*
- * Now get the size of received packet (minus the CRC).
- */
- total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
- if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
- && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
-#ifdef BIG_PACKET
- || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
- (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
- TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
- TULIP_DSTS_RxOVERFLOW)) == 0)
-#endif
- )) {
- me->m_len = total_len - last_offset;
-
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- map = M_GETCTX(me, bus_dmamap_t);
- bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len,
- BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
- bus_dmamap_unload(sc->tulip_dmatag, map);
- sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
-#if defined(DIAGNOSTIC)
- M_SETCTX(me, NULL);
-#endif
-#endif /* TULIP_BUS_DMA */
-
- eh = *mtod(ms, struct ether_header *);
-#ifndef __FreeBSD__
- if (sc->tulip_if.if_bpf != NULL) {
- if (me == ms)
- bpf_tap(&sc->tulip_if, mtod(ms, caddr_t), total_len);
- else
- bpf_mtap(&sc->tulip_if, ms);
- }
-#endif
- sc->tulip_flags |= TULIP_RXACT;
- accept = 1;
- } else {
- ifp->if_ierrors++;
- if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
- sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
- } else {
-#if defined(TULIP_VERBOSE)
- const char *error = NULL;
-#endif
- if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
- sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
-#if defined(TULIP_VERBOSE)
- error = "frame too long";
-#endif
- }
- if (eop->d_status & TULIP_DSTS_RxBADCRC) {
- if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
- sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
-#if defined(TULIP_VERBOSE)
- error = "alignment error";
-#endif
- } else {
- sc->tulip_dot3stats.dot3StatsFCSErrors++;
-#if defined(TULIP_VERBOSE)
- error = "bad crc";
-#endif
- }
- }
-#if defined(TULIP_VERBOSE)
- if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) {
- printf("%s%d: receive: %6D: %s\n",
- sc->tulip_name, sc->tulip_unit,
- mtod(ms, u_char *) + 6, ":",
- error);
- sc->tulip_flags |= TULIP_NOMESSAGES;
- }
-#endif
- }
-
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- map = M_GETCTX(me, bus_dmamap_t);
- bus_dmamap_unload(sc->tulip_dmatag, map);
- sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
-#if defined(DIAGNOSTIC)
- M_SETCTX(me, NULL);
-#endif
-#endif /* TULIP_BUS_DMA */
- }
-#if defined(TULIP_DEBUG)
- cnt++;
-#endif
- ifp->if_ipackets++;
- if (++eop == ri->ri_last)
- eop = ri->ri_first;
- ri->ri_nextin = eop;
- queue_mbuf:
- /*
- * Either we are priming the TULIP with mbufs (m == NULL)
- * or we are about to accept an mbuf for the upper layers
- * so we need to allocate an mbuf to replace it. If we
- * can't replace it, send up it anyways. This may cause
- * us to drop packets in the future but that's better than
- * being caught in livelock.
- *
- * Note that if this packet crossed multiple descriptors
- * we don't even try to reallocate all the mbufs here.
- * Instead we rely on the test of the beginning of
- * the loop to refill for the extra consumed mbufs.
- */
- if (accept || ms == NULL) {
- struct mbuf *m0;
- MGETHDR(m0, M_DONTWAIT, MT_DATA);
- if (m0 != NULL) {
-#if defined(TULIP_COPY_RXDATA)
- if (!accept || total_len >= (MHLEN - 2)) {
-#endif
- MCLGET(m0, M_DONTWAIT);
- if ((m0->m_flags & M_EXT) == 0) {
- m_freem(m0);
- m0 = NULL;
- }
-#if defined(TULIP_COPY_RXDATA)
- }
-#endif
- }
- if (accept
-#if defined(TULIP_COPY_RXDATA)
- && m0 != NULL
-#endif
- ) {
-#if !defined(TULIP_COPY_RXDATA)
- ms->m_pkthdr.len = total_len;
- ms->m_pkthdr.rcvif = ifp;
- (*ifp->if_input)(ifp, ms);
-#else
-#ifdef BIG_PACKET
-#error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
-#endif
- m0->m_data += 2; /* align data after header */
- m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
- m0->m_len = m0->m_pkthdr.len = total_len;
- m0->m_pkthdr.rcvif = ifp;
- (*ifp->if_input)(ifp, m0);
- m0 = ms;
-#endif /* ! TULIP_COPY_RXDATA */
- }
- ms = m0;
- }
- if (ms == NULL) {
- /*
- * Couldn't allocate a new buffer. Don't bother
- * trying to replenish the receive queue.
- */
- fillok = 0;
- sc->tulip_flags |= TULIP_RXBUFSLOW;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_rxlowbufs++;
-#endif
- TULIP_PERFEND(rxget);
- continue;
- }
- /*
- * Now give the buffer(s) to the TULIP and save in our
- * receive queue.
- */
- do {
- tulip_desc_t * const nextout = ri->ri_nextout;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- if (sc->tulip_rxmaps_free > 0) {
- map = sc->tulip_rxmaps[--sc->tulip_rxmaps_free];
- } else {
- m_freem(ms);
- sc->tulip_flags |= TULIP_RXBUFSLOW;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_rxlowbufs++;
-#endif
- break;
- }
- M_SETCTX(ms, map);
- error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *),
- TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT);
- if (error) {
- printf("%s%d: unable to load rx map, "
- "error = %d\n", sc->tulip_name, sc->tulip_unit, error);
- panic("tulip_rx_intr"); /* XXX */
- }
- nextout->d_addr1 = map->dm_segs[0].ds_addr;
- nextout->d_length1 = map->dm_segs[0].ds_len;
- if (map->dm_nsegs == 2) {
- nextout->d_addr2 = map->dm_segs[1].ds_addr;
- nextout->d_length2 = map->dm_segs[1].ds_len;
- } else {
- nextout->d_addr2 = 0;
- nextout->d_length2 = 0;
- }
- TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout));
-#else /* TULIP_BUS_DMA */
- nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
- nextout->d_length1 = TULIP_RX_BUFLEN;
-#endif /* TULIP_BUS_DMA */
- nextout->d_status = TULIP_DSTS_OWNER;
- TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
- if (++ri->ri_nextout == ri->ri_last)
- ri->ri_nextout = ri->ri_first;
- me = ms->m_next;
- ms->m_next = NULL;
- _IF_ENQUEUE(&sc->tulip_rxq, ms);
- } while ((ms = me) != NULL);
-
- if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
- sc->tulip_flags &= ~TULIP_RXBUFSLOW;
- TULIP_PERFEND(rxget);
- }
-
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_rxintrs++;
- sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
-#endif
- TULIP_PERFEND(rxintr);
-}
-
-static int
-tulip_tx_intr(
- tulip_softc_t * const sc)
-{
- TULIP_PERFSTART(txintr)
- tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
- struct mbuf *m;
- int xmits = 0;
- int descs = 0;
-
- while (ri->ri_free < ri->ri_max) {
- u_int32_t d_flag;
-
- TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
- if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
- break;
-
- ri->ri_free++;
- descs++;
- d_flag = ri->ri_nextin->d_flag;
- if (d_flag & TULIP_DFLAG_TxLASTSEG) {
- if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
- /*
- * We've just finished processing a setup packet.
- * Mark that we finished it. If there's not
- * another pending, startup the TULIP receiver.
- * Make sure we ack the RXSTOPPED so we won't get
- * an abormal interrupt indication.
- */
- TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
- sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
- if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
- sc->tulip_flags |= TULIP_HASHONLY;
- if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
- tulip_rx_intr(sc);
- sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
- sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
- TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
- TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
- TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
- }
- } else {
- const u_int32_t d_status = ri->ri_nextin->d_status;
- _IF_DEQUEUE(&sc->tulip_txq, m);
- if (m != NULL) {
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- bus_dmamap_t map = M_GETCTX(m, bus_dmamap_t);
- TULIP_TXMAP_POSTSYNC(sc, map);
- sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
-#endif /* TULIP_BUS_DMA */
- m_freem(m);
-#if defined(TULIP_DEBUG)
- } else {
- printf("%s%d: tx_intr: failed to dequeue mbuf?!?\n",
- sc->tulip_name, sc->tulip_unit);
-#endif
- }
- if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
- tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
- if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
-#if defined(TULIP_DEBUG)
- if (d_status & TULIP_DSTS_TxNOCARR)
- sc->tulip_dbg.dbg_txprobe_nocarr++;
- if (d_status & TULIP_DSTS_TxEXCCOLL)
- sc->tulip_dbg.dbg_txprobe_exccoll++;
-#endif
- event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
- }
- (*sc->tulip_boardsw->bd_media_poll)(sc, event);
- /*
- * Escape from the loop before media poll has reset the TULIP!
- */
- break;
- } else {
- xmits++;
- if (d_status & TULIP_DSTS_ERRSUM) {
- sc->tulip_if.if_oerrors++;
- if (d_status & TULIP_DSTS_TxEXCCOLL)
- sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
- if (d_status & TULIP_DSTS_TxLATECOLL)
- sc->tulip_dot3stats.dot3StatsLateCollisions++;
- if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
- sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
- if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
- sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
- if (d_status & TULIP_DSTS_TxUNDERFLOW)
- sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
- if (d_status & TULIP_DSTS_TxBABBLE)
- sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
- } else {
- u_int32_t collisions =
- (d_status & TULIP_DSTS_TxCOLLMASK)
- >> TULIP_DSTS_V_TxCOLLCNT;
- sc->tulip_if.if_collisions += collisions;
- if (collisions == 1)
- sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
- else if (collisions > 1)
- sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
- else if (d_status & TULIP_DSTS_TxDEFERRED)
- sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
- /*
- * SQE is only valid for 10baseT/BNC/AUI when not
- * running in full-duplex. In order to speed up the
- * test, the corresponding bit in tulip_flags needs to
- * set as well to get us to count SQE Test Errors.
- */
- if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
- sc->tulip_dot3stats.dot3StatsSQETestErrors++;
- }
- }
- }
- }
-
- if (++ri->ri_nextin == ri->ri_last)
- ri->ri_nextin = ri->ri_first;
-
- if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
- sc->tulip_if.if_flags &= ~IFF_OACTIVE;
- }
- /*
- * If nothing left to transmit, disable the timer.
- * Else if progress, reset the timer back to 2 ticks.
- */
- if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
- sc->tulip_txtimer = 0;
- else if (xmits > 0)
- sc->tulip_txtimer = TULIP_TXTIMER;
- sc->tulip_if.if_opackets += xmits;
- TULIP_PERFEND(txintr);
- return descs;
-}
-
-static void
-tulip_print_abnormal_interrupt(
- tulip_softc_t * const sc,
- u_int32_t csr)
-{
- const char * const *msgp = tulip_status_bits;
- const char *sep;
- u_int32_t mask;
- const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
-
- csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
- printf("%s%d: abnormal interrupt:", sc->tulip_name, sc->tulip_unit);
- for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
- if ((csr & mask) && *msgp != NULL) {
- printf("%s%s", sep, *msgp);
- if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
- sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
- if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
- printf(" (switching to store-and-forward mode)");
- } else {
- printf(" (raising TX threshold to %s)",
- &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
- }
- }
- sep = ", ";
- }
- }
- printf("\n");
-}
-
-static void
-tulip_intr_handler(
- tulip_softc_t * const sc,
- int *progress_p)
-{
- TULIP_PERFSTART(intr)
- u_int32_t csr;
-
- while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
- *progress_p = 1;
- TULIP_CSR_WRITE(sc, csr_status, csr);
-
- if (csr & TULIP_STS_SYSERROR) {
- sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
- if (sc->tulip_flags & TULIP_NOMESSAGES) {
- sc->tulip_flags |= TULIP_SYSTEMERROR;
- } else {
- printf("%s%d: system error: %s\n",
- sc->tulip_name, sc->tulip_unit,
- tulip_system_errors[sc->tulip_last_system_error]);
- }
- sc->tulip_flags |= TULIP_NEEDRESET;
- sc->tulip_system_errors++;
- break;
- }
- if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_link_intrs++;
-#endif
- if (sc->tulip_boardsw->bd_media_poll != NULL) {
- (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
- ? TULIP_MEDIAPOLL_LINKFAIL
- : TULIP_MEDIAPOLL_LINKPASS);
- csr &= ~TULIP_STS_ABNRMLINTR;
- }
- tulip_media_print(sc);
- }
- if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
- u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
- if (csr & TULIP_STS_RXNOBUF)
- sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
- /*
- * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
- * on receive overflows.
- */
- if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
- sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
- /*
- * Stop the receiver process and spin until it's stopped.
- * Tell rx_intr to drop the packets it dequeues.
- */
- TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
- while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
- ;
- TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
- sc->tulip_flags |= TULIP_RXIGNORE;
- }
- tulip_rx_intr(sc);
- if (sc->tulip_flags & TULIP_RXIGNORE) {
- /*
- * Restart the receiver.
- */
- sc->tulip_flags &= ~TULIP_RXIGNORE;
- TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
- }
- }
- if (csr & TULIP_STS_ABNRMLINTR) {
- u_int32_t tmp = csr & sc->tulip_intrmask
- & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
- if (csr & TULIP_STS_TXUNDERFLOW) {
- if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
- sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
- sc->tulip_flags |= TULIP_NEWTXTHRESH;
- } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
- sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
- sc->tulip_flags |= TULIP_NEWTXTHRESH;
- }
- }
- if (sc->tulip_flags & TULIP_NOMESSAGES) {
- sc->tulip_statusbits |= tmp;
- } else {
- tulip_print_abnormal_interrupt(sc, tmp);
- sc->tulip_flags |= TULIP_NOMESSAGES;
- }
- TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
- }
- if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
- tulip_tx_intr(sc);
- if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
- tulip_ifstart(&sc->tulip_if);
- }
- }
- if (sc->tulip_flags & TULIP_NEEDRESET) {
- tulip_reset(sc);
- tulip_init(sc);
- }
- TULIP_PERFEND(intr);
-}
-
-#if defined(TULIP_USE_SOFTINTR)
-/*
- * This is an experimental idea to alleviate problems due to interrupt
- * livelock. What is interrupt livelock? It's when you spend all your
- * time servicing device interrupts and never drop below device ipl
- * to do "useful" work.
- *
- * So what we do here is see if the device needs service and if so,
- * disable interrupts (dismiss the interrupt), place it in a list of devices
- * needing service, and issue a network software interrupt.
- *
- * When our network software interrupt routine gets called, we simply
- * walk done the list of devices that we have created and deal with them
- * at splnet/splsoftnet.
- *
- */
-static void
-tulip_hardintr_handler(
- tulip_softc_t * const sc,
- int *progress_p)
-{
- if (TULIP_CSR_READ(sc, csr_status) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR) == 0)
- return;
- *progress_p = 1;
- /*
- * disable interrupts
- */
- TULIP_CSR_WRITE(sc, csr_intr, 0);
- /*
- * mark it as needing a software interrupt
- */
- tulip_softintr_mask |= (1U << sc->tulip_unit);
-}
-
-static void
-tulip_softintr(
- void)
-{
- u_int32_t softintr_mask, mask;
- int progress = 0;
- int unit;
- int s;
-
- /*
- * Copy mask to local copy and reset global one to 0.
- */
- s = splimp();
- softintr_mask = tulip_softintr_mask;
- tulip_softintr_mask = 0;
- splx(s);
-
- /*
- * Optimize for the single unit case.
- */
- if (tulip_softintr_max_unit == 0) {
- if (softintr_mask & 1) {
- tulip_softc_t * const sc = tulips[0];
- /*
- * Handle the "interrupt" and then reenable interrupts
- */
- softintr_mask = 0;
- tulip_intr_handler(sc, &progress);
- TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
- }
- return;
- }
-
- /*
- * Handle all "queued" interrupts in a round robin fashion.
- * This is done so as not to favor a particular interface.
- */
- unit = tulip_softintr_last_unit;
- mask = (1U << unit);
- while (softintr_mask != 0) {
- if (tulip_softintr_max_unit == unit) {
- unit = 0; mask = 1;
- } else {
- unit += 1; mask <<= 1;
- }
- if (softintr_mask & mask) {
- tulip_softc_t * const sc = tulips[unit];
- /*
- * Handle the "interrupt" and then reenable interrupts
- */
- softintr_mask ^= mask;
- tulip_intr_handler(sc, &progress);
- TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
- }
- }
-
- /*
- * Save where we ending up.
- */
- tulip_softintr_last_unit = unit;
-}
-#endif /* TULIP_USE_SOFTINTR */
-
-static void
-tulip_intr_shared(
- void *arg)
-{
- tulip_softc_t * sc = arg;
- int progress = 0;
-
- for (; sc != NULL; sc = sc->tulip_slaves) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_intrs++;
-#endif
-#if defined(TULIP_USE_SOFTINTR)
- tulip_hardintr_handler(sc, &progress);
-#else
- tulip_intr_handler(sc, &progress);
-#endif
- }
-#if defined(TULIP_USE_SOFTINTR)
- if (progress)
- schednetisr(NETISR_DE);
-#endif
-}
-
-static void
-tulip_intr_normal(
- void *arg)
-{
- tulip_softc_t * sc = (tulip_softc_t *) arg;
- int progress = 0;
-
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_intrs++;
-#endif
-#if defined(TULIP_USE_SOFTINTR)
- tulip_hardintr_handler(sc, &progress);
- if (progress)
- schednetisr(NETISR_DE);
-#else
- tulip_intr_handler(sc, &progress);
-#endif
-}
-
-static struct mbuf *
-tulip_mbuf_compress(
- struct mbuf *m)
-{
- struct mbuf *m0;
-#if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET)
- MGETHDR(m0, M_DONTWAIT, MT_DATA);
- if (m0 != NULL) {
- if (m->m_pkthdr.len > MHLEN) {
- MCLGET(m0, M_DONTWAIT);
- if ((m0->m_flags & M_EXT) == 0) {
- m_freem(m);
- m_freem(m0);
- return NULL;
- }
- }
- m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
- m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
- }
-#else
- int mlen = MHLEN;
- int len = m->m_pkthdr.len;
- struct mbuf **mp = &m0;
-
- while (len > 0) {
- if (mlen == MHLEN) {
- MGETHDR(*mp, M_DONTWAIT, MT_DATA);
- } else {
- MGET(*mp, M_DONTWAIT, MT_DATA);
- }
- if (*mp == NULL) {
- m_freem(m0);
- m0 = NULL;
- break;
- }
- if (len > MLEN) {
- MCLGET(*mp, M_DONTWAIT);
- if (((*mp)->m_flags & M_EXT) == 0) {
- m_freem(m0);
- m0 = NULL;
- break;
- }
- (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES;
- } else {
- (*mp)->m_len = len <= mlen ? len : mlen;
- }
- m_copydata(m, m->m_pkthdr.len - len,
- (*mp)->m_len, mtod((*mp), caddr_t));
- len -= (*mp)->m_len;
- mp = &(*mp)->m_next;
- mlen = MLEN;
- }
-#endif
- m_freem(m);
- return m0;
-}
-
-static struct mbuf *
-tulip_txput(
- tulip_softc_t * const sc,
- struct mbuf *m)
-{
- TULIP_PERFSTART(txput)
- tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
- tulip_desc_t *eop, *nextout;
- int segcnt, free;
- u_int32_t d_status;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- bus_dmamap_t map;
- int error;
-#else
- struct mbuf *m0;
-#endif
-
-#if defined(TULIP_DEBUG)
- if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
- printf("%s%d: txput%s: tx not running\n",
- sc->tulip_name, sc->tulip_unit,
- (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : "");
- sc->tulip_flags |= TULIP_WANTTXSTART;
- sc->tulip_dbg.dbg_txput_finishes[0]++;
- goto finish;
- }
-#endif
-
- /*
- * Now we try to fill in our transmit descriptors. This is
- * a bit reminiscent of going on the Ark two by two
- * since each descriptor for the TULIP can describe
- * two buffers. So we advance through packet filling
- * each of the two entries at a time to to fill each
- * descriptor. Clear the first and last segment bits
- * in each descriptor (actually just clear everything
- * but the end-of-ring or chain bits) to make sure
- * we don't get messed up by previously sent packets.
- *
- * We may fail to put the entire packet on the ring if
- * there is either not enough ring entries free or if the
- * packet has more than MAX_TXSEG segments. In the former
- * case we will just wait for the ring to empty. In the
- * latter case we have to recopy.
- */
-#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
- again:
- m0 = m;
-#endif
- d_status = 0;
- eop = nextout = ri->ri_nextout;
- segcnt = 0;
- free = ri->ri_free;
-
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- /*
- * Reclaim some dma maps from if we are out.
- */
- if (sc->tulip_txmaps_free == 0) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_no_txmaps++;
-#endif
- free += tulip_tx_intr(sc);
- }
- if (sc->tulip_txmaps_free > 0) {
- map = sc->tulip_txmaps[sc->tulip_txmaps_free-1];
- } else {
- sc->tulip_flags |= TULIP_WANTTXSTART;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[1]++;
-#endif
- goto finish;
- }
- error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
- if (error != 0) {
- if (error == EFBIG) {
- /*
- * The packet exceeds the number of transmit buffer
- * entries that we can use for one packet, so we have
- * to recopy it into one mbuf and then try again.
- */
- m = tulip_mbuf_compress(m);
- if (m == NULL) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[2]++;
-#endif
- goto finish;
- }
- error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
- }
- if (error != 0) {
- printf("%s%d: unable to load tx map, "
- "error = %d\n", sc->tulip_name, sc->tulip_unit, error);
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[3]++;
-#endif
- goto finish;
- }
- }
- if ((free -= (map->dm_nsegs + 1) / 2) <= 0
- /*
- * See if there's any unclaimed space in the transmit ring.
- */
- && (free += tulip_tx_intr(sc)) <= 0) {
- /*
- * There's no more room but since nothing
- * has been committed at this point, just
- * show output is active, put back the
- * mbuf and return.
- */
- sc->tulip_flags |= TULIP_WANTTXSTART;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[4]++;
-#endif
- bus_dmamap_unload(sc->tulip_dmatag, map);
- goto finish;
- }
- for (; map->dm_nsegs - segcnt > 1; segcnt += 2) {
- eop = nextout;
- eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
- eop->d_status = d_status;
- eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
- eop->d_length1 = map->dm_segs[segcnt].ds_len;
- eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr;
- eop->d_length2 = map->dm_segs[segcnt+1].ds_len;
- d_status = TULIP_DSTS_OWNER;
- if (++nextout == ri->ri_last)
- nextout = ri->ri_first;
- }
- if (segcnt < map->dm_nsegs) {
- eop = nextout;
- eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
- eop->d_status = d_status;
- eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
- eop->d_length1 = map->dm_segs[segcnt].ds_len;
- eop->d_addr2 = 0;
- eop->d_length2 = 0;
- if (++nextout == ri->ri_last)
- nextout = ri->ri_first;
- }
- TULIP_TXMAP_PRESYNC(sc, map);
- M_SETCTX(m, map);
- map = NULL;
- --sc->tulip_txmaps_free; /* commit to using the dmamap */
-
-#else /* !TULIP_BUS_DMA */
-
- do {
- int len = m0->m_len;
- caddr_t addr = mtod(m0, caddr_t);
- unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
-
- while (len > 0) {
- unsigned slen = min(len, clsize);
-#ifdef BIG_PACKET
- int partial = 0;
- if (slen >= 2048)
- slen = 2040, partial = 1;
-#endif
- segcnt++;
- if (segcnt > TULIP_MAX_TXSEG) {
- /*
- * The packet exceeds the number of transmit buffer
- * entries that we can use for one packet, so we have
- * recopy it into one mbuf and then try again.
- */
- m = tulip_mbuf_compress(m);
- if (m == NULL)
- goto finish;
- goto again;
- }
- if (segcnt & 1) {
- if (--free == 0) {
- /*
- * See if there's any unclaimed space in the
- * transmit ring.
- */
- if ((free += tulip_tx_intr(sc)) == 0) {
- /*
- * There's no more room but since nothing
- * has been committed at this point, just
- * show output is active, put back the
- * mbuf and return.
- */
- sc->tulip_flags |= TULIP_WANTTXSTART;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[1]++;
-#endif
- goto finish;
- }
- }
- eop = nextout;
- if (++nextout == ri->ri_last)
- nextout = ri->ri_first;
- eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
- eop->d_status = d_status;
- eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
- eop->d_length1 = slen;
- } else {
- /*
- * Fill in second half of descriptor
- */
- eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
- eop->d_length2 = slen;
- }
- d_status = TULIP_DSTS_OWNER;
- len -= slen;
- addr += slen;
-#ifdef BIG_PACKET
- if (partial)
- continue;
-#endif
- clsize = PAGE_SIZE;
- }
- } while ((m0 = m0->m_next) != NULL);
-#endif /* TULIP_BUS_DMA */
-
- /*
- * bounce a copy to the bpf listener, if any.
- */
- BPF_MTAP(&sc->tulip_if, m);
-
- /*
- * The descriptors have been filled in. Now get ready
- * to transmit.
- */
- _IF_ENQUEUE(&sc->tulip_txq, m);
- m = NULL;
-
- /*
- * Make sure the next descriptor after this packet is owned
- * by us since it may have been set up above if we ran out
- * of room in the ring.
- */
- nextout->d_status = 0;
- TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
-
-#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
- /*
- * If we only used the first segment of the last descriptor,
- * make sure the second segment will not be used.
- */
- if (segcnt & 1) {
- eop->d_addr2 = 0;
- eop->d_length2 = 0;
- }
-#endif /* TULIP_BUS_DMA */
-
- /*
- * Mark the last and first segments, indicate we want a transmit
- * complete interrupt, and tell it to transmit!
- */
- eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
-
- /*
- * Note that ri->ri_nextout is still the start of the packet
- * and until we set the OWNER bit, we can still back out of
- * everything we have done.
- */
- ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
-#if defined(TULIP_BUS_MAP) && !defined(TULIP_BUS_DMA_NOTX)
- if (eop < ri->ri_nextout) {
- TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
- (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout);
- TULIP_TXDESC_PRESYNC(sc, ri->ri_first,
- (caddr_t) (eop + 1) - (caddr_t) ri->ri_first);
- } else {
- TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
- (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout);
- }
-#endif
- ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
- TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
-
- /*
- * This advances the ring for us.
- */
- ri->ri_nextout = nextout;
- ri->ri_free = free;
-
- TULIP_PERFEND(txput);
-
- if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
- TULIP_CSR_WRITE(sc, csr_txpoll, 1);
- sc->tulip_if.if_flags |= IFF_OACTIVE;
- sc->tulip_if.if_start = tulip_ifstart;
- TULIP_PERFEND(txput);
- return NULL;
- }
-
- /*
- * switch back to the single queueing ifstart.
- */
- sc->tulip_flags &= ~TULIP_WANTTXSTART;
- if (sc->tulip_txtimer == 0)
- sc->tulip_txtimer = TULIP_TXTIMER;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[5]++;
-#endif
-
- /*
- * If we want a txstart, there must be not enough space in the
- * transmit ring. So we want to enable transmit done interrupts
- * so we can immediately reclaim some space. When the transmit
- * interrupt is posted, the interrupt handler will call tx_intr
- * to reclaim space and then txstart (since WANTTXSTART is set).
- * txstart will move the packet into the transmit ring and clear
- * WANTTXSTART thereby causing TXINTR to be cleared.
- */
- finish:
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[6]++;
-#endif
- if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
- sc->tulip_if.if_flags |= IFF_OACTIVE;
- sc->tulip_if.if_start = tulip_ifstart;
- if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
- sc->tulip_intrmask |= TULIP_STS_TXINTR;
- TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
- }
- } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
- if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
- sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
- TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
- }
- }
- TULIP_CSR_WRITE(sc, csr_txpoll, 1);
- TULIP_PERFEND(txput);
- return m;
-}
-
-static void
-tulip_txput_setup(
- tulip_softc_t * const sc)
-{
- tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
- tulip_desc_t *nextout;
-
- /*
- * We will transmit, at most, one setup packet per call to ifstart.
- */
-
-#if defined(TULIP_DEBUG)
- if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
- printf("%s%d: txput_setup: tx not running\n",
- sc->tulip_name, sc->tulip_unit);
- sc->tulip_flags |= TULIP_WANTTXSTART;
- sc->tulip_if.if_start = tulip_ifstart;
- return;
- }
-#endif
- /*
- * Try to reclaim some free descriptors..
- */
- if (ri->ri_free < 2)
- tulip_tx_intr(sc);
- if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
- sc->tulip_flags |= TULIP_WANTTXSTART;
- sc->tulip_if.if_start = tulip_ifstart;
- return;
- }
- bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
- sizeof(sc->tulip_setupbuf));
- /*
- * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
- * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
- */
- sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
- ri->ri_free--;
- nextout = ri->ri_nextout;
- nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
- nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
- |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
- if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
- nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
- else if (sc->tulip_flags & TULIP_WANTHASHONLY)
- nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
-
- nextout->d_length2 = 0;
- nextout->d_addr2 = 0;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len;
- nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr;
- if (sc->tulip_setupmap->dm_nsegs == 2) {
- nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len;
- nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr;
- }
- TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap);
- TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout));
-#else
- nextout->d_length1 = sizeof(sc->tulip_setupbuf);
- nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
-#endif
-
- /*
- * Advance the ring for the next transmit packet.
- */
- if (++ri->ri_nextout == ri->ri_last)
- ri->ri_nextout = ri->ri_first;
-
- /*
- * Make sure the next descriptor is owned by us since it
- * may have been set up above if we ran out of room in the
- * ring.
- */
- ri->ri_nextout->d_status = 0;
- TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
- nextout->d_status = TULIP_DSTS_OWNER;
- /*
- * Flush the ownwership of the current descriptor
- */
- TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
- TULIP_CSR_WRITE(sc, csr_txpoll, 1);
- if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
- sc->tulip_intrmask |= TULIP_STS_TXINTR;
- TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
- }
-}
-
-
-/*
- * This routine is entered at splnet() (splsoftnet() on NetBSD)
- * and thereby imposes no problems when TULIP_USE_SOFTINTR is
- * defined or not.
- */
-static int
-tulip_ifioctl(
- struct ifnet * ifp,
- u_long cmd,
- caddr_t data)
-{
- TULIP_PERFSTART(ifioctl)
- tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
- struct ifreq *ifr = (struct ifreq *) data;
- int s;
- int error = 0;
-
-#if defined(TULIP_USE_SOFTINTR)
- s = splnet();
-#else
- s = splimp();
-#endif
- switch (cmd) {
- case SIOCSIFFLAGS: {
- tulip_addr_filter(sc); /* reinit multicast filter */
- tulip_init(sc);
- break;
- }
-
- case SIOCSIFMEDIA:
- case SIOCGIFMEDIA: {
- error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
- break;
- }
-
- case SIOCADDMULTI:
- case SIOCDELMULTI: {
- /*
- * Update multicast listeners
- */
- tulip_addr_filter(sc); /* reset multicast filtering */
- tulip_init(sc);
- error = 0;
- break;
- }
-
- case SIOCSIFMTU:
- /*
- * Set the interface MTU.
- */
- if (ifr->ifr_mtu > ETHERMTU
-#ifdef BIG_PACKET
- && sc->tulip_chipid != TULIP_21140
- && sc->tulip_chipid != TULIP_21140A
- && sc->tulip_chipid != TULIP_21041
-#endif
- ) {
- error = EINVAL;
- break;
- }
- ifp->if_mtu = ifr->ifr_mtu;
-#ifdef BIG_PACKET
- tulip_reset(sc);
- tulip_init(sc);
-#endif
- break;
-
-#ifdef SIOCGADDRROM
- case SIOCGADDRROM: {
- error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
- break;
- }
-#endif
-#ifdef SIOCGCHIPID
- case SIOCGCHIPID: {
- ifr->ifr_metric = (int) sc->tulip_chipid;
- break;
- }
-#endif
- default: {
- error = ether_ioctl(ifp, cmd, data);
- break;
- }
- }
-
- splx(s);
- TULIP_PERFEND(ifioctl);
- return error;
-}
-
-/*
- * These routines gets called at device spl (from ether_output). This might
- * pose a problem for TULIP_USE_SOFTINTR if ether_output is called at
- * device spl from another driver.
- */
-
-static void
-tulip_ifstart(
- struct ifnet * const ifp)
-{
- TULIP_PERFSTART(ifstart)
- tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
-
- if (sc->tulip_if.if_flags & IFF_RUNNING) {
-
- if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
- tulip_txput_setup(sc);
-
- while (sc->tulip_if.if_snd.ifq_head != NULL) {
- struct mbuf *m;
- IF_DEQUEUE(&sc->tulip_if.if_snd, m);
- if ((m = tulip_txput(sc, m)) != NULL) {
- IF_PREPEND(&sc->tulip_if.if_snd, m);
- break;
- }
- }
- if (sc->tulip_if.if_snd.ifq_head == NULL)
- sc->tulip_if.if_start = tulip_ifstart_one;
- }
-
- TULIP_PERFEND(ifstart);
-}
-
-static void
-tulip_ifstart_one(
- struct ifnet * const ifp)
-{
- TULIP_PERFSTART(ifstart_one)
- tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
-
- if ((sc->tulip_if.if_flags & IFF_RUNNING)
- && sc->tulip_if.if_snd.ifq_head != NULL) {
- struct mbuf *m;
- IF_DEQUEUE(&sc->tulip_if.if_snd, m);
- if ((m = tulip_txput(sc, m)) != NULL)
- IF_PREPEND(&sc->tulip_if.if_snd, m);
- }
- TULIP_PERFEND(ifstart_one);
-}
-
-/*
- * Even though this routine runs at device spl, it does not break
- * our use of splnet (splsoftnet under NetBSD) for the majority
- * of this driver (if TULIP_USE_SOFTINTR defined) since
- * if_watcbog is called from if_watchdog which is called from
- * splsoftclock which is below spl[soft]net.
- */
-static void
-tulip_ifwatchdog(
- struct ifnet *ifp)
-{
- TULIP_PERFSTART(ifwatchdog)
- tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
-
-#if defined(TULIP_DEBUG)
- u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs;
- if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz)
- sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs;
- sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs;
-#endif /* TULIP_DEBUG */
-
- sc->tulip_if.if_timer = 1;
- /*
- * These should be rare so do a bulk test up front so we can just skip
- * them if needed.
- */
- if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
- /*
- * If the number of receive buffer is low, try to refill
- */
- if (sc->tulip_flags & TULIP_RXBUFSLOW)
- tulip_rx_intr(sc);
-
- if (sc->tulip_flags & TULIP_SYSTEMERROR) {
- printf("%s%d: %d system errors: last was %s\n",
- sc->tulip_name, sc->tulip_unit, sc->tulip_system_errors,
- tulip_system_errors[sc->tulip_last_system_error]);
- }
- if (sc->tulip_statusbits) {
- tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
- sc->tulip_statusbits = 0;
- }
-
- sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
- }
-
- if (sc->tulip_txtimer)
- tulip_tx_intr(sc);
- if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
- printf("%s%d: transmission timeout\n", sc->tulip_name, sc->tulip_unit);
- if (TULIP_DO_AUTOSENSE(sc)) {
- sc->tulip_media = TULIP_MEDIA_UNKNOWN;
- sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
- sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
- }
- tulip_reset(sc);
- tulip_init(sc);
- }
-
- TULIP_PERFEND(ifwatchdog);
- TULIP_PERFMERGE(sc, perf_intr_cycles);
- TULIP_PERFMERGE(sc, perf_ifstart_cycles);
- TULIP_PERFMERGE(sc, perf_ifioctl_cycles);
- TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles);
- TULIP_PERFMERGE(sc, perf_timeout_cycles);
- TULIP_PERFMERGE(sc, perf_ifstart_one_cycles);
- TULIP_PERFMERGE(sc, perf_txput_cycles);
- TULIP_PERFMERGE(sc, perf_txintr_cycles);
- TULIP_PERFMERGE(sc, perf_rxintr_cycles);
- TULIP_PERFMERGE(sc, perf_rxget_cycles);
- TULIP_PERFMERGE(sc, perf_intr);
- TULIP_PERFMERGE(sc, perf_ifstart);
- TULIP_PERFMERGE(sc, perf_ifioctl);
- TULIP_PERFMERGE(sc, perf_ifwatchdog);
- TULIP_PERFMERGE(sc, perf_timeout);
- TULIP_PERFMERGE(sc, perf_ifstart_one);
- TULIP_PERFMERGE(sc, perf_txput);
- TULIP_PERFMERGE(sc, perf_txintr);
- TULIP_PERFMERGE(sc, perf_rxintr);
- TULIP_PERFMERGE(sc, perf_rxget);
-}
-
-/*
- * All printf's are real as of now!
- */
-#ifdef printf
-#undef printf
-#endif
-
-static void
-tulip_attach(
- tulip_softc_t * const sc)
-{
- struct ifnet * const ifp = &sc->tulip_if;
-
- ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
- ifp->if_ioctl = tulip_ifioctl;
- ifp->if_start = tulip_ifstart;
- ifp->if_watchdog = tulip_ifwatchdog;
- ifp->if_timer = 1;
- ifp->if_output = ether_output;
- ifp->if_init = tulip_ifinit;
-
- printf("%s%d: %s%s pass %d.%d%s\n",
- sc->tulip_name, sc->tulip_unit,
- sc->tulip_boardid,
- tulip_chipdescs[sc->tulip_chipid],
- (sc->tulip_revinfo & 0xF0) >> 4,
- sc->tulip_revinfo & 0x0F,
- (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
- == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
- printf("%s%d: address %6D\n",
- sc->tulip_name, sc->tulip_unit, sc->tulip_enaddr, ":");
-
-#if defined(__alpha__)
- /*
- * In case the SRM console told us about a bogus media,
- * we need to check to be safe.
- */
- if (sc->tulip_mediums[sc->tulip_media] == NULL)
- sc->tulip_media = TULIP_MEDIA_UNKNOWN;
-#endif
-
- (*sc->tulip_boardsw->bd_media_probe)(sc);
- ifmedia_init(&sc->tulip_ifmedia, 0,
- tulip_ifmedia_change,
- tulip_ifmedia_status);
- sc->tulip_flags &= ~TULIP_DEVICEPROBE;
- tulip_ifmedia_add(sc);
-
- tulip_reset(sc);
-
- ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr);
- ifp->if_snd.ifq_maxlen = ifqmaxlen;
-}
-
-#if defined(TULIP_BUS_DMA)
-#if !defined(TULIP_BUS_DMA_NOTX) || !defined(TULIP_BUS_DMA_NORX)
-static int
-tulip_busdma_allocmem(
- tulip_softc_t * const sc,
- size_t size,
- bus_dmamap_t *map_p,
- tulip_desc_t **desc_p)
-{
- bus_dma_segment_t segs[1];
- int nsegs, error;
- error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, PAGE_SIZE,
- segs, sizeof(segs)/sizeof(segs[0]),
- &nsegs, BUS_DMA_NOWAIT);
- if (error == 0) {
- void *desc;
- error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size,
- (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
- if (error == 0) {
- bus_dmamap_t map;
- error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0,
- BUS_DMA_NOWAIT, &map);
- if (error == 0) {
- error = bus_dmamap_load(sc->tulip_dmatag, map, desc,
- size, NULL, BUS_DMA_NOWAIT);
- if (error)
- bus_dmamap_destroy(sc->tulip_dmatag, map);
- else
- *map_p = map;
- }
- if (error)
- bus_dmamem_unmap(sc->tulip_dmatag, desc, size);
- }
- if (error)
- bus_dmamem_free(sc->tulip_dmatag, segs, nsegs);
- else
- *desc_p = desc;
- }
- return error;
-}
-#endif
-
-static int
-tulip_busdma_init(
- tulip_softc_t * const sc)
-{
- int error = 0;
-
-#if !defined(TULIP_BUS_DMA_NOTX)
- /*
- * Allocate dmamap for setup descriptor
- */
- error = bus_dmamap_create(sc->tulip_dmatag, sizeof(sc->tulip_setupbuf), 2,
- sizeof(sc->tulip_setupbuf), 0, BUS_DMA_NOWAIT,
- &sc->tulip_setupmap);
- if (error == 0) {
- error = bus_dmamap_load(sc->tulip_dmatag, sc->tulip_setupmap,
- sc->tulip_setupbuf, sizeof(sc->tulip_setupbuf),
- NULL, BUS_DMA_NOWAIT);
- if (error)
- bus_dmamap_destroy(sc->tulip_dmatag, sc->tulip_setupmap);
- }
- /*
- * Allocate space and dmamap for transmit ring
- */
- if (error == 0) {
- error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS,
- &sc->tulip_txdescmap,
- &sc->tulip_txdescs);
- }
-
- /*
- * Allocate dmamaps for each transmit descriptors
- */
- if (error == 0) {
- while (error == 0 && sc->tulip_txmaps_free < TULIP_TXDESCS) {
- bus_dmamap_t map;
- if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0)
- sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
- }
- if (error) {
- while (sc->tulip_txmaps_free > 0)
- bus_dmamap_destroy(sc->tulip_dmatag,
- sc->tulip_txmaps[--sc->tulip_txmaps_free]);
- }
- }
-#else
- if (error == 0) {
- sc->tulip_txdescs = (tulip_desc_t *) malloc(TULIP_TXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT);
- if (sc->tulip_txdescs == NULL)
- error = ENOMEM;
- }
-#endif
-#if !defined(TULIP_BUS_DMA_NORX)
- /*
- * Allocate space and dmamap for receive ring
- */
- if (error == 0) {
- error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS,
- &sc->tulip_rxdescmap,
- &sc->tulip_rxdescs);
- }
-
- /*
- * Allocate dmamaps for each receive descriptors
- */
- if (error == 0) {
- while (error == 0 && sc->tulip_rxmaps_free < TULIP_RXDESCS) {
- bus_dmamap_t map;
- if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0)
- sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
- }
- if (error) {
- while (sc->tulip_rxmaps_free > 0)
- bus_dmamap_destroy(sc->tulip_dmatag,
- sc->tulip_rxmaps[--sc->tulip_rxmaps_free]);
- }
- }
-#else
- if (error == 0) {
- sc->tulip_rxdescs = (tulip_desc_t *) malloc(TULIP_RXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT);
- if (sc->tulip_rxdescs == NULL)
- error = ENOMEM;
- }
-#endif
- return error;
-}
-#endif /* TULIP_BUS_DMA */
-
-static void
-tulip_initcsrs(
- tulip_softc_t * const sc,
- tulip_csrptr_t csr_base,
- size_t csr_size)
-{
- sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
- sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
- sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
- sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
- sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
- sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
- sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
- sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
- sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
- sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
- sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
- sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
- sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
- sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
- sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
- sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
-}
-
-static void
-tulip_initring(
- tulip_softc_t * const sc,
- tulip_ringinfo_t * const ri,
- tulip_desc_t *descs,
- int ndescs)
-{
- ri->ri_max = ndescs;
- ri->ri_first = descs;
- ri->ri_last = ri->ri_first + ri->ri_max;
- bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
- ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
-}
-
-/*
- * This is the PCI configuration support.
- */
-
-#define PCI_CBIO 0x10 /* Configuration Base IO Address */
-#define PCI_CBMA 0x14 /* Configuration Base Memory Address */
-#define PCI_CFDA 0x40 /* Configuration Driver Area */
-
-static int
-tulip_pci_probe(device_t dev)
-{
- const char *name = NULL;
-
- if (pci_get_vendor(dev) != DEC_VENDORID)
- return ENXIO;
-
- /*
- * Some LanMedia WAN cards use the Tulip chip, but they have
- * their own driver, and we should not recognize them
- */
- if (pci_get_subvendor(dev) == 0x1376)
- return ENXIO;
-
- switch (pci_get_device(dev)) {
- case CHIPID_21040:
- name = "Digital 21040 Ethernet";
- break;
- case CHIPID_21041:
- name = "Digital 21041 Ethernet";
- break;
- case CHIPID_21140:
- if (pci_get_revid(dev) >= 0x20)
- name = "Digital 21140A Fast Ethernet";
- else
- name = "Digital 21140 Fast Ethernet";
- break;
- case CHIPID_21142:
- if (pci_get_revid(dev) >= 0x20)
- name = "Digital 21143 Fast Ethernet";
- else
- name = "Digital 21142 Fast Ethernet";
- break;
- }
- if (name) {
- device_set_desc(dev, name);
- return -200;
- }
- return ENXIO;
-}
-
-static int
-tulip_shutdown(device_t dev)
-{
- tulip_softc_t * const sc = device_get_softc(dev);
- TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
- DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
- 33MHz that comes to two microseconds but wait a
- bit longer anyways) */
- return 0;
-}
-
-static int
-tulip_pci_attach(device_t dev)
-{
- tulip_softc_t *sc;
-#if defined(__alpha__)
- tulip_media_t media = TULIP_MEDIA_UNKNOWN;
-#endif
- int retval, idx;
- u_int32_t revinfo, cfdainfo, cfcsinfo;
- unsigned csroffset = TULIP_PCI_CSROFFSET;
- unsigned csrsize = TULIP_PCI_CSRSIZE;
- tulip_csrptr_t csr_base;
- tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
- struct resource *res;
- int rid, unit;
-
- unit = device_get_unit(dev);
-
- if (unit >= TULIP_MAX_DEVICES) {
- printf("de%d", unit);
- printf(": not configured; limit of %d reached or exceeded\n",
- TULIP_MAX_DEVICES);
- return ENXIO;
- }
-
- revinfo = pci_get_revid(dev);
- cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
- cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
-
- /* turn busmaster on in case BIOS doesn't set it */
- if(!(cfcsinfo & PCIM_CMD_BUSMASTEREN)) {
- cfcsinfo |= PCIM_CMD_BUSMASTEREN;
- pci_write_config(dev, PCIR_COMMAND, cfcsinfo, 4);
- }
-
- if (pci_get_vendor(dev) == DEC_VENDORID) {
- if (pci_get_device(dev) == CHIPID_21040)
- chipid = TULIP_21040;
- else if (pci_get_device(dev) == CHIPID_21041)
- chipid = TULIP_21041;
- else if (pci_get_device(dev) == CHIPID_21140)
- chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
- else if (pci_get_device(dev) == CHIPID_21142)
- chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
- }
- if (chipid == TULIP_CHIPID_UNKNOWN)
- return ENXIO;
-
- if (chipid == TULIP_21040 && revinfo < 0x20) {
- printf("de%d", unit);
- printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n",
- revinfo >> 4, revinfo & 0x0f);
- return ENXIO;
- } else if (chipid == TULIP_21140 && revinfo < 0x11) {
- printf("de%d: not configured; 21140 pass 1.1 required (%d.%d found)\n",
- unit, revinfo >> 4, revinfo & 0x0f);
- return ENXIO;
- }
-
- sc = device_get_softc(dev);
- sc->tulip_pci_busno = pci_get_bus(dev);
- sc->tulip_pci_devno = pci_get_slot(dev);
- sc->tulip_chipid = chipid;
- sc->tulip_flags |= TULIP_DEVICEPROBE;
- if (chipid == TULIP_21140 || chipid == TULIP_21140A)
- sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
- if (chipid == TULIP_21140A && revinfo <= 0x22)
- sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
- if (chipid == TULIP_21140)
- sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
- if (chipid != TULIP_21040 && chipid != TULIP_21140)
- sc->tulip_features |= TULIP_HAVE_POWERMGMT;
- if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
- sc->tulip_features |= TULIP_HAVE_DUALSENSE;
- if (chipid != TULIP_21041 || revinfo >= 0x20)
- sc->tulip_features |= TULIP_HAVE_SIANWAY;
- if (chipid != TULIP_21041)
- sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
- if (chipid != TULIP_21041 && revinfo >= 0x20)
- sc->tulip_features |= TULIP_HAVE_SIA100;
- }
-
- if (sc->tulip_features & TULIP_HAVE_POWERMGMT
- && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
- cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
- pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
- DELAY(11*1000);
- }
-#if defined(__alpha__)
- /*
- * The Alpha SRM console encodes a console set media in the driver
- * part of the CFDA register. Note that the Multia presents a
- * problem in that its BNC mode is really EXTSIA. So in that case
- * force a probe.
- */
- switch ((cfdainfo >> 8) & 0xff) {
- case 1: media = chipid > TULIP_21040 ? TULIP_MEDIA_AUI : TULIP_MEDIA_AUIBNC; break;
- case 2: media = chipid > TULIP_21040 ? TULIP_MEDIA_BNC : TULIP_MEDIA_UNKNOWN; break;
- case 3: media = TULIP_MEDIA_10BASET; break;
- case 4: media = TULIP_MEDIA_10BASET_FD; break;
- case 5: media = TULIP_MEDIA_100BASETX; break;
- case 6: media = TULIP_MEDIA_100BASETX_FD; break;
- default: media = TULIP_MEDIA_UNKNOWN; break;
- }
-#endif
-
- sc->tulip_unit = unit;
- sc->tulip_name = "de";
- sc->tulip_revinfo = revinfo;
- sc->tulip_if.if_softc = sc;
-#if defined(TULIP_IOMAPPED)
- rid = PCI_CBIO;
- res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
- 0, ~0, 1, RF_ACTIVE);
-#else
- rid = PCI_CBMA;
- res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
- 0, ~0, 1, RF_ACTIVE);
-#endif
- if (!res)
- return ENXIO;
- sc->tulip_csrs_bst = rman_get_bustag(res);
- sc->tulip_csrs_bsh = rman_get_bushandle(res);
- csr_base = 0;
-
- tulips[unit] = sc;
-
- tulip_initcsrs(sc, csr_base + csroffset, csrsize);
-
-#if defined(TULIP_BUS_DMA)
- if ((retval = tulip_busdma_init(sc)) != 0) {
- printf("error initing bus_dma: %d\n", retval);
- return ENXIO;
- }
-#else
- sc->tulip_rxdescs = (tulip_desc_t *) malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS, M_DEVBUF, M_NOWAIT);
- sc->tulip_txdescs = (tulip_desc_t *) malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS, M_DEVBUF, M_NOWAIT);
- if (sc->tulip_rxdescs == NULL || sc->tulip_txdescs == NULL) {
- printf("malloc failed\n");
- if (sc->tulip_rxdescs)
- free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
- if (sc->tulip_txdescs)
- free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
- return ENXIO;
- }
-#endif
-
- tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
- tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
-
- /*
- * Make sure there won't be any interrupts or such...
- */
- TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
- DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
- 33MHz that comes to two microseconds but wait a
- bit longer anyways) */
-
- if ((retval = tulip_read_macaddr(sc)) < 0) {
- printf("%s%d", sc->tulip_name, sc->tulip_unit);
- printf(": can't read ENET ROM (why=%d) (", retval);
- for (idx = 0; idx < 32; idx++)
- printf("%02x", sc->tulip_rombuf[idx]);
- printf("\n");
- printf("%s%d: %s%s pass %d.%d\n",
- sc->tulip_name, sc->tulip_unit,
- sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
- (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
- printf("%s%d: address unknown\n", sc->tulip_name, sc->tulip_unit);
- } else {
- int s;
- void (*intr_rtn)(void *) = tulip_intr_normal;
-
- if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
- intr_rtn = tulip_intr_shared;
-
- if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
- void *ih;
-
- rid = 0;
- res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
- 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
- if (res == 0 || bus_setup_intr(dev, res, INTR_TYPE_NET,
- intr_rtn, sc, &ih)) {
- printf("%s%d: couldn't map interrupt\n",
- sc->tulip_name, sc->tulip_unit);
- free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
- free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
- return ENXIO;
- }
- }
-#if defined(TULIP_USE_SOFTINTR)
- if (sc->tulip_unit > tulip_softintr_max_unit)
- tulip_softintr_max_unit = sc->tulip_unit;
-#endif
-
- s = splimp();
-#if defined(__alpha__)
- sc->tulip_media = media;
-#endif
- tulip_attach(sc);
-#if defined(__alpha__)
- if (sc->tulip_media != TULIP_MEDIA_UNKNOWN)
- tulip_linkup(sc, media);
-#endif
- splx(s);
- }
- return 0;
-}
-
-static device_method_t tulip_pci_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, tulip_pci_probe),
- DEVMETHOD(device_attach, tulip_pci_attach),
- DEVMETHOD(device_shutdown, tulip_shutdown),
- { 0, 0 }
-};
-static driver_t tulip_pci_driver = {
- "de",
- tulip_pci_methods,
- sizeof(tulip_softc_t),
-};
-static devclass_t tulip_devclass;
-DRIVER_MODULE(de, pci, tulip_pci_driver, tulip_devclass, 0, 0);
diff --git a/sys/dev/de/if_devar.h b/sys/dev/de/if_devar.h
deleted file mode 100644
index f9e63b3fbd26..000000000000
--- a/sys/dev/de/if_devar.h
+++ /dev/null
@@ -1,924 +0,0 @@
-/* $NetBSD: if_devar.h,v 1.32 1999/04/01 14:55:25 tsubai Exp $ */
-
-/* $FreeBSD$ */
-
-/*-
- * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED 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.
- *
- * Id: if_devar.h,v 1.28 1997/07/03 16:55:07 thomas Exp
- */
-
-#if !defined(_DEVAR_H)
-#define _DEVAR_H
-
-typedef bus_addr_t tulip_csrptr_t;
-
-#define TULIP_PCI_CSRSIZE 8
-#define TULIP_PCI_CSROFFSET 0
-
-#define TULIP_CSR_READ(sc, csr) \
- bus_space_read_4((sc)->tulip_csrs_bst, \
- (sc)->tulip_csrs_bsh, \
- (sc)->tulip_csrs.csr)
-#define TULIP_CSR_WRITE(sc, csr, val) \
- bus_space_write_4((sc)->tulip_csrs_bst, \
- (sc)->tulip_csrs_bsh, \
- (sc)->tulip_csrs.csr, val)
-
-#define TULIP_CSR_READBYTE(sc, csr) \
- bus_space_read_1((sc)->tulip_csrs_bst, \
- (sc)->tulip_csrs_bsh, \
- (sc)->tulip_csrs.csr)
-#define TULIP_CSR_WRITEBYTE(sc, csr, val) \
- bus_space_write_1((sc)->tulip_csrs_bst, \
- (sc)->tulip_csrs_bsh, \
- (sc)->tulip_csrs.csr, val)
-
-/*
- * This structure contains "pointers" for the registers on
- * the various 21x4x chips. CSR0 through CSR8 are common
- * to all chips. After that, it gets messy...
- */
-typedef struct {
- tulip_csrptr_t csr_busmode; /* CSR0 */
- tulip_csrptr_t csr_txpoll; /* CSR1 */
- tulip_csrptr_t csr_rxpoll; /* CSR2 */
- tulip_csrptr_t csr_rxlist; /* CSR3 */
- tulip_csrptr_t csr_txlist; /* CSR4 */
- tulip_csrptr_t csr_status; /* CSR5 */
- tulip_csrptr_t csr_command; /* CSR6 */
- tulip_csrptr_t csr_intr; /* CSR7 */
- tulip_csrptr_t csr_missed_frames; /* CSR8 */
- tulip_csrptr_t csr_9; /* CSR9 */
- tulip_csrptr_t csr_10; /* CSR10 */
- tulip_csrptr_t csr_11; /* CSR11 */
- tulip_csrptr_t csr_12; /* CSR12 */
- tulip_csrptr_t csr_13; /* CSR13 */
- tulip_csrptr_t csr_14; /* CSR14 */
- tulip_csrptr_t csr_15; /* CSR15 */
-} tulip_regfile_t;
-
-#define csr_enetrom csr_9 /* 21040 */
-#define csr_reserved csr_10 /* 21040 */
-#define csr_full_duplex csr_11 /* 21040 */
-#define csr_bootrom csr_10 /* 21041/21140A/?? */
-#define csr_gp csr_12 /* 21140* */
-#define csr_watchdog csr_15 /* 21140* */
-#define csr_gp_timer csr_11 /* 21041/21140* */
-#define csr_srom_mii csr_9 /* 21041/21140* */
-#define csr_sia_status csr_12 /* 2104x */
-#define csr_sia_connectivity csr_13 /* 2104x */
-#define csr_sia_tx_rx csr_14 /* 2104x */
-#define csr_sia_general csr_15 /* 2104x */
-
-/*
- * While 21x4x allows chaining of its descriptors, this driver
- * doesn't take advantage of it. We keep the descriptors in a
- * traditional FIFO ring.
- */
-typedef struct {
- tulip_desc_t *ri_first; /* first entry in ring */
- tulip_desc_t *ri_last; /* one after last entry */
- tulip_desc_t *ri_nextin; /* next to processed by host */
- tulip_desc_t *ri_nextout; /* next to processed by adapter */
- int ri_max;
- int ri_free;
-} tulip_ringinfo_t;
-
-/*
- * The 21040 has a stupid restriction in that the receive
- * buffers must be longword aligned. But since Ethernet
- * headers are not a multiple of longwords in size this forces
- * the data to non-longword aligned. Since IP requires the
- * data to be longword aligned, we need to copy it after it has
- * been DMA'ed in our memory.
- *
- * Since we have to copy it anyways, we might as well as allocate
- * dedicated receive space for the input. This allows to use a
- * small receive buffer size and more ring entries to be able to
- * better keep with a flood of tiny Ethernet packets.
- *
- * The receive space MUST ALWAYS be a multiple of the page size.
- * And the number of receive descriptors multiplied by the size
- * of the receive buffers must equal the recevive space. This
- * is so that we can manipulate the page tables so that even if a
- * packet wraps around the end of the receive space, we can
- * treat it as virtually contiguous.
- *
- * The above used to be true (the stupid restriction is still true)
- * but we gone to directly DMA'ing into MBUFs (unless it's on an
- * architecture which can't handle unaligned accesses) because with
- * 100Mb/s cards the copying is just too much of a hit.
- */
-#if !defined(__i386__)
-#define TULIP_COPY_RXDATA 1
-#endif
-
-#define TULIP_DATA_PER_DESC 2032
-#define TULIP_TXTIMER 4
-#define TULIP_RXDESCS 48
-#define TULIP_TXDESCS 128
-#define TULIP_RXQ_TARGET 32
-#if TULIP_RXQ_TARGET >= TULIP_RXDESCS
-#error TULIP_RXQ_TARGET must be less than TULIP_RXDESCS
-#endif
-#define TULIP_RX_BUFLEN ((MCLBYTES < 2048 ? MCLBYTES : 2048) - 16)
-
-/*
- * Forward reference to make C happy.
- */
-typedef struct _tulip_softc_t tulip_softc_t;
-
-/*
- * The various controllers support.
- */
-
-typedef enum {
- TULIP_21040,
- TULIP_21041,
- TULIP_21140, TULIP_21140A, TULIP_21142,
- TULIP_21143,
- TULIP_CHIPID_UNKNOWN
-} tulip_chipid_t;
-
-/*
- * Various physical media types supported.
- * BNCAUI is BNC or AUI since on the 21040 you can't really tell
- * which is in use.
- */
-typedef enum {
- TULIP_MEDIA_UNKNOWN,
- TULIP_MEDIA_10BASET,
- TULIP_MEDIA_10BASET_FD,
- TULIP_MEDIA_BNC,
- TULIP_MEDIA_AUI,
- TULIP_MEDIA_EXTSIA,
- TULIP_MEDIA_AUIBNC,
- TULIP_MEDIA_100BASETX,
- TULIP_MEDIA_100BASETX_FD,
- TULIP_MEDIA_100BASET4,
- TULIP_MEDIA_100BASEFX,
- TULIP_MEDIA_100BASEFX_FD,
- TULIP_MEDIA_MAX
-} tulip_media_t;
-
-#define TULIP_BIT(b) (1L << ((int)(b)))
-#define TULIP_FDBIT(m) (1L << ((int)TULIP_MEDIA_ ## m ## _FD))
-#define TULIP_MBIT(m) (1L << ((int)TULIP_MEDIA_ ## m ))
-#define TULIP_IS_MEDIA_FD(m) (TULIP_BIT(m) & \
- (TULIP_FDBIT(10BASET) \
- |TULIP_FDBIT(100BASETX) \
- |TULIP_FDBIT(100BASEFX)))
-#define TULIP_CAN_MEDIA_FD(m) (TULIP_BIT(m) & \
- (TULIP_MBIT(10BASET) \
- |TULIP_MBIT(100BASETX) \
- |TULIP_MBIT(100BASEFX)))
-#define TULIP_FD_MEDIA_OF(m) ((tulip_media_t)((m) + 1))
-#define TULIP_HD_MEDIA_OF(m) ((tulip_media_t)((m) - 1))
-#define TULIP_IS_MEDIA_100MB(m) ((m) >= TULIP_MEDIA_100BASETX)
-#define TULIP_IS_MEDIA_TP(m) ((TULIP_BIT(m) & \
- (TULIP_MBIT(BNC) \
- |TULIP_MBIT(AUI) \
- |TULIP_MBIT(AUIBNC) \
- |TULIP_MBIT(EXTSIA))) == 0)
-
-#define TULIP_SROM_ATTR_MII 0x0100
-#define TULIP_SROM_ATTR_NWAY 0x0200
-#define TULIP_SROM_ATTR_AUTOSENSE 0x0400
-#define TULIP_SROM_ATTR_POWERUP 0x0800
-#define TULIP_SROM_ATTR_NOLINKPASS 0x1000
-
-typedef struct {
- enum {
- TULIP_MEDIAINFO_NONE,
- TULIP_MEDIAINFO_SIA,
- TULIP_MEDIAINFO_GPR,
- TULIP_MEDIAINFO_MII,
- TULIP_MEDIAINFO_RESET,
- TULIP_MEDIAINFO_SYM
- } mi_type;
- union {
- struct {
- u_int16_t sia_connectivity;
- u_int16_t sia_tx_rx;
- u_int16_t sia_general;
- u_int32_t sia_gp_control; /* 21142/21143 */
- u_int32_t sia_gp_data; /* 21142/21143 */
- } un_sia;
- struct {
- u_int32_t gpr_cmdmode;
- u_int32_t gpr_gpcontrol; /* 21142/21143 */
- u_int32_t gpr_gpdata;
- u_int8_t gpr_actmask;
- u_int8_t gpr_actdata;
- u_int gpr_default : 1;
- } un_gpr;
- struct {
- u_int32_t mii_mediamask;
- u_int16_t mii_capabilities;
- u_int16_t mii_advertisement;
- u_int16_t mii_full_duplex;
- u_int16_t mii_tx_threshold;
- u_int16_t mii_interrupt; /* 21142/21143 */
- u_int8_t mii_phyaddr;
- u_int8_t mii_gpr_length;
- u_int8_t mii_gpr_offset;
- u_int8_t mii_reset_length;
- u_int8_t mii_reset_offset;
- u_int32_t mii_phyid;
- } un_mii;
- } mi_un;
-} tulip_media_info_t;
-
-#define mi_sia_connectivity mi_un.un_sia.sia_connectivity
-#define mi_sia_tx_rx mi_un.un_sia.sia_tx_rx
-#define mi_sia_general mi_un.un_sia.sia_general
-#define mi_sia_gp_control mi_un.un_sia.sia_gp_control
-#define mi_sia_gp_data mi_un.un_sia.sia_gp_data
-
-#define mi_gpcontrol mi_un.un_gpr.gpr_gpcontrol
-#define mi_gpdata mi_un.un_gpr.gpr_gpdata
-#define mi_actmask mi_un.un_gpr.gpr_actmask
-#define mi_actdata mi_un.un_gpr.gpr_actdata
-#define mi_default mi_un.un_gpr.gpr_default
-#define mi_cmdmode mi_un.un_gpr.gpr_cmdmode
-
-#define mi_phyaddr mi_un.un_mii.mii_phyaddr
-#define mi_gpr_length mi_un.un_mii.mii_gpr_length
-#define mi_gpr_offset mi_un.un_mii.mii_gpr_offset
-#define mi_reset_length mi_un.un_mii.mii_reset_length
-#define mi_reset_offset mi_un.un_mii.mii_reset_offset
-#define mi_capabilities mi_un.un_mii.mii_capabilities
-#define mi_advertisement mi_un.un_mii.mii_advertisement
-#define mi_full_duplex mi_un.un_mii.mii_full_duplex
-#define mi_tx_threshold mi_un.un_mii.mii_tx_threshold
-#define mi_mediamask mi_un.un_mii.mii_mediamask
-#define mi_mii_interrupt mi_un.un_mii.mii_interrupt
-#define mi_phyid mi_un.un_mii.mii_phyid
-
-#define TULIP_MEDIAINFO_SIA_INIT(sc, mi, chipid, media) do { \
- (mi)->mi_type = TULIP_MEDIAINFO_SIA; \
- sc->tulip_mediums[TULIP_MEDIA_ ## media] = (mi); \
- (mi)->mi_sia_connectivity = TULIP_ ## chipid ## _SIACONN_ ## media; \
- (mi)->mi_sia_tx_rx = TULIP_ ## chipid ## _SIATXRX_ ## media; \
- (mi)->mi_sia_general = TULIP_ ## chipid ## _SIAGEN_ ## media; \
-} while (0)
-
-#define TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, media) do { \
- if ((sc)->tulip_mediums[TULIP_MEDIA_ ## media] == NULL \
- && ((mi)->mi_capabilities & PHYSTS_ ## media)) { \
- (sc)->tulip_mediums[TULIP_MEDIA_ ## media] = (mi); \
- (mi)->mi_mediamask |= TULIP_BIT(TULIP_MEDIA_ ## media); \
- } \
-} while (0)
-
-#define TULIP_MII_NOPHY 32
-/*
- * Some boards need to treated specially. The following enumeration
- * identifies the cards with quirks (or those we just want to single
- * out for special merit or scorn).
- */
-typedef enum {
- TULIP_21040_GENERIC, /* Generic 21040 (works with most any board) */
- TULIP_21140_ISV, /* Digital Semicondutor 21140 ISV SROM Format */
- TULIP_21142_ISV, /* Digital Semicondutor 21142 ISV SROM Format */
- TULIP_21143_ISV, /* Digital Semicondutor 21143 ISV SROM Format */
- TULIP_21140_DEC_EB, /* Digital Semicondutor 21140 Evaluation Board */
- TULIP_21140_MII, /* 21140[A] with MII */
- TULIP_21140_DEC_DE500, /* Digital DE500-?? 10/100 */
- TULIP_21140_SMC_9332, /* SMC 9332 */
- TULIP_21140_COGENT_EM100, /* Cogent EM100 100 only */
- TULIP_21140_ZNYX_ZX34X, /* ZNYX ZX342 10/100 */
- TULIP_21140_ASANTE, /* AsanteFast 10/100 */
- TULIP_21140_EN1207, /* Accton EN2107 10/100 BNC */
- TULIP_21041_GENERIC /* Generic 21041 card */
-} tulip_board_t;
-
-typedef enum {
- TULIP_MEDIAPOLL_TIMER, /* 100ms timer fired */
- TULIP_MEDIAPOLL_FASTTIMER, /* <100ms timer fired */
- TULIP_MEDIAPOLL_LINKFAIL, /* called from interrupt routine */
- TULIP_MEDIAPOLL_LINKPASS, /* called from interrupt routine */
- TULIP_MEDIAPOLL_START, /* start a media probe (called from reset) */
- TULIP_MEDIAPOLL_TXPROBE_OK, /* txprobe succeeded */
- TULIP_MEDIAPOLL_TXPROBE_FAILED, /* txprobe failed */
- TULIP_MEDIAPOLL_MAX
-} tulip_mediapoll_event_t;
-
-typedef enum {
- TULIP_LINK_DOWN, /* Link is down */
- TULIP_LINK_UP, /* link is ok */
- TULIP_LINK_UNKNOWN /* we can't tell either way */
-} tulip_link_status_t;
-
-
-/*
- * This data structure is used to abstract out the quirks.
- * media_probe = tries to determine the media type.
- * media_select = enables the current media (or autosenses)
- * media_poll = autosenses media
- * media_preset = 21140, etal requires bit to set before the
- * the software reset; hence pre-set. Should be
- * pre-reset but that's ugly.
- */
-
-typedef struct {
- tulip_board_t bd_type;
- void (*bd_media_probe)(tulip_softc_t * const sc);
- void (*bd_media_select)(tulip_softc_t * const sc);
- void (*bd_media_poll)(tulip_softc_t * const sc, tulip_mediapoll_event_t event);
- void (*bd_media_preset)(tulip_softc_t * const sc);
-} tulip_boardsw_t;
-
-/*
- * The next few declarations are for MII/PHY based board.
- *
- * The first enumeration identifies a superset of various datums
- * that can be obtained from various PHY chips. Not all PHYs will
- * support all datums.
- * The modedata structure indicates what register contains
- * a datum, what mask is applied the register contents, and what the
- * result should be.
- * The attr structure records information about a supported PHY.
- * The phy structure records information about a PHY instance.
- */
-
-typedef enum {
- PHY_MODE_10T,
- PHY_MODE_100TX,
- PHY_MODE_100T4,
- PHY_MODE_FULLDUPLEX,
- PHY_MODE_MAX
-} tulip_phy_mode_t;
-
-typedef struct {
- u_int16_t pm_regno;
- u_int16_t pm_mask;
- u_int16_t pm_value;
-} tulip_phy_modedata_t;
-
-typedef struct {
- u_int32_t attr_id;
- u_int16_t attr_flags;
-#define PHY_NEED_HARD_RESET 0x0001
-#define PHY_DUAL_CYCLE_TA 0x0002
- tulip_phy_modedata_t attr_modes[PHY_MODE_MAX];
-#ifdef TULIP_DEBUG
- const char *attr_name;
-#endif
-} tulip_phy_attr_t;
-
-/*
- * Various probe states used when trying to autosense the media.
- */
-
-typedef enum {
- TULIP_PROBE_INACTIVE,
- TULIP_PROBE_PHYRESET,
- TULIP_PROBE_PHYAUTONEG,
- TULIP_PROBE_GPRTEST,
- TULIP_PROBE_MEDIATEST,
- TULIP_PROBE_FAILED
-} tulip_probe_state_t;
-
-typedef struct {
- /*
- * Transmit Statistics
- */
- u_int32_t dot3StatsSingleCollisionFrames;
- u_int32_t dot3StatsMultipleCollisionFrames;
- u_int32_t dot3StatsSQETestErrors;
- u_int32_t dot3StatsDeferredTransmissions;
- u_int32_t dot3StatsLateCollisions;
- u_int32_t dot3StatsExcessiveCollisions;
- u_int32_t dot3StatsCarrierSenseErrors;
- u_int32_t dot3StatsInternalMacTransmitErrors;
- u_int32_t dot3StatsInternalTransmitUnderflows; /* not in rfc1650! */
- u_int32_t dot3StatsInternalTransmitBabbles; /* not in rfc1650! */
- /*
- * Receive Statistics
- */
- u_int32_t dot3StatsMissedFrames; /* not in rfc1650! */
- u_int32_t dot3StatsAlignmentErrors;
- u_int32_t dot3StatsFCSErrors;
- u_int32_t dot3StatsFrameTooLongs;
- u_int32_t dot3StatsInternalMacReceiveErrors;
-} tulip_dot3_stats_t;
-
-/*
- * Now to important stuff. This is softc structure (where does softc
- * come from??? No idea) for the tulip device.
- */
-struct _tulip_softc_t {
- struct ifmedia tulip_ifmedia;
-#if defined(TULIP_BUS_DMA)
- bus_dma_tag_t tulip_dmatag; /* bus DMA tag */
-#if !defined(TULIP_BUS_DMA_NOTX)
- bus_dmamap_t tulip_setupmap;
- bus_dmamap_t tulip_txdescmap;
- bus_dmamap_t tulip_txmaps[TULIP_TXDESCS];
- unsigned tulip_txmaps_free;
-#endif
-#if !defined(TULIP_BUS_DMA_NORX)
- bus_dmamap_t tulip_rxdescmap;
- bus_dmamap_t tulip_rxmaps[TULIP_RXDESCS];
- unsigned tulip_rxmaps_free;
-#endif
-#endif
- struct arpcom tulip_ac;
- bus_space_tag_t tulip_csrs_bst;
- bus_space_handle_t tulip_csrs_bsh;
- tulip_regfile_t tulip_csrs;
- u_int32_t tulip_flags;
-#define TULIP_WANTSETUP 0x00000001
-#define TULIP_WANTHASHPERFECT 0x00000002
-#define TULIP_WANTHASHONLY 0x00000004
-#define TULIP_DOINGSETUP 0x00000008
-#define TULIP_PRINTMEDIA 0x00000010
-#define TULIP_TXPROBE_ACTIVE 0x00000020
-#define TULIP_ALLMULTI 0x00000040
-#define TULIP_WANTRXACT 0x00000080
-#define TULIP_RXACT 0x00000100
-#define TULIP_INRESET 0x00000200
-#define TULIP_NEEDRESET 0x00000400
-#define TULIP_SQETEST 0x00000800
-#define TULIP_xxxxxx0 0x00001000
-#define TULIP_xxxxxx1 0x00002000
-#define TULIP_WANTTXSTART 0x00004000
-#define TULIP_NEWTXTHRESH 0x00008000
-#define TULIP_NOAUTOSENSE 0x00010000
-#define TULIP_PRINTLINKUP 0x00020000
-#define TULIP_LINKUP 0x00040000
-#define TULIP_RXBUFSLOW 0x00080000
-#define TULIP_NOMESSAGES 0x00100000
-#define TULIP_SYSTEMERROR 0x00200000
-#define TULIP_TIMEOUTPENDING 0x00400000
-#define TULIP_xxxxxx2 0x00800000
-#define TULIP_TRYNWAY 0x01000000
-#define TULIP_DIDNWAY 0x02000000
-#define TULIP_RXIGNORE 0x04000000
-#define TULIP_PROBE1STPASS 0x08000000
-#define TULIP_DEVICEPROBE 0x10000000
-#define TULIP_PROMISC 0x20000000
-#define TULIP_HASHONLY 0x40000000
-#define TULIP_xxxxxx3 0x80000000
- /* only 4 bits left! */
- u_int32_t tulip_features; /* static bits indicating features of chip */
-#define TULIP_HAVE_GPR 0x00000001 /* have gp register (140[A]) */
-#define TULIP_HAVE_RXBADOVRFLW 0x00000002 /* RX corrupts on overflow */
-#define TULIP_HAVE_POWERMGMT 0x00000004 /* Snooze/sleep modes */
-#define TULIP_HAVE_MII 0x00000008 /* Some medium on MII */
-#define TULIP_HAVE_SIANWAY 0x00000010 /* SIA does NWAY */
-#define TULIP_HAVE_DUALSENSE 0x00000020 /* SIA senses both AUI & TP */
-#define TULIP_HAVE_SIAGP 0x00000040 /* SIA has a GP port */
-#define TULIP_HAVE_BROKEN_HASH 0x00000080 /* Broken Multicast Hash */
-#define TULIP_HAVE_ISVSROM 0x00000100 /* uses ISV SROM Format */
-#define TULIP_HAVE_BASEROM 0x00000200 /* Board ROM can be cloned */
-#define TULIP_HAVE_SLAVEDROM 0x00000400 /* Board ROM cloned */
-#define TULIP_HAVE_SLAVEDINTR 0x00000800 /* Board slaved interrupt */
-#define TULIP_HAVE_SHAREDINTR 0x00001000 /* Board shares interrupts */
-#define TULIP_HAVE_OKROM 0x00002000 /* ROM was recognized */
-#define TULIP_HAVE_NOMEDIA 0x00004000 /* did not detect any media */
-#define TULIP_HAVE_STOREFWD 0x00008000 /* have CMD_STOREFWD */
-#define TULIP_HAVE_SIA100 0x00010000 /* has LS100 in SIA status */
-#define TULIP_HAVE_OKSROM 0x00020000 /* SROM CRC is OK */
- u_int32_t tulip_intrmask; /* our copy of csr_intr */
- u_int32_t tulip_cmdmode; /* our copy of csr_cmdmode */
- u_int32_t tulip_last_system_error : 3; /* last system error (only value is TULIP_SYSTEMERROR is also set) */
- u_int32_t tulip_txtimer : 2; /* transmission timer */
- u_int32_t tulip_system_errors; /* number of system errors encountered */
- u_int32_t tulip_statusbits; /* status bits from CSR5 that may need to be printed */
-
- tulip_media_info_t *tulip_mediums[TULIP_MEDIA_MAX]; /* indexes into mediainfo */
- tulip_media_t tulip_media; /* current media type */
- u_int32_t tulip_abilities; /* remote system's abiltities (as defined in IEEE 802.3u) */
-
- u_int8_t tulip_revinfo; /* revision of chip */
- u_int8_t tulip_phyaddr; /* 0..31 -- address of current phy */
- u_int8_t tulip_gpinit; /* active pins on 21140 */
- u_int8_t tulip_gpdata; /* default gpdata for 21140 */
-
- struct {
- u_int8_t probe_count; /* count of probe operations */
- int32_t probe_timeout; /* time in ms of probe timeout */
- tulip_probe_state_t probe_state; /* current media probe state */
- tulip_media_t probe_media; /* current media being probed */
- u_int32_t probe_mediamask; /* medias checked */
- u_int32_t probe_passes; /* times autosense failed */
- u_int32_t probe_txprobes; /* txprobes attempted */
- } tulip_probe;
-#define tulip_probe_count tulip_probe.probe_count
-#define tulip_probe_timeout tulip_probe.probe_timeout
-#define tulip_probe_state tulip_probe.probe_state
-#define tulip_probe_media tulip_probe.probe_media
-#define tulip_probe_mediamask tulip_probe.probe_mediamask
-#define tulip_probe_passes tulip_probe.probe_passes
-
- tulip_chipid_t tulip_chipid; /* type of chip we are using */
- const tulip_boardsw_t *tulip_boardsw; /* board/chip characteristics */
- tulip_softc_t *tulip_slaves; /* slaved devices (ZX3xx) */
-#if defined(TULIP_DEBUG)
- /*
- * Debugging/Statistical information
- */
- struct {
- tulip_media_t dbg_last_media;
- u_int32_t dbg_intrs;
- u_int32_t dbg_media_probes;
- u_int32_t dbg_txprobe_nocarr;
- u_int32_t dbg_txprobe_exccoll;
- u_int32_t dbg_link_downed;
- u_int32_t dbg_link_suspected;
- u_int32_t dbg_link_intrs;
- u_int32_t dbg_link_pollintrs;
- u_int32_t dbg_link_failures;
- u_int32_t dbg_nway_starts;
- u_int32_t dbg_nway_failures;
- u_int16_t dbg_phyregs[32][4];
- u_int32_t dbg_rxlowbufs;
- u_int32_t dbg_rxintrs;
- u_int32_t dbg_last_rxintrs;
- u_int32_t dbg_high_rxintrs_hz;
- u_int32_t dbg_no_txmaps;
- u_int32_t dbg_txput_finishes[8];
- u_int32_t dbg_txprobes_ok[TULIP_MEDIA_MAX];
- u_int32_t dbg_txprobes_failed[TULIP_MEDIA_MAX];
- u_int32_t dbg_events[TULIP_MEDIAPOLL_MAX];
- u_int32_t dbg_rxpktsperintr[TULIP_RXDESCS];
- } tulip_dbg;
-#endif
-#if defined(TULIP_PERFSTATS)
-#define TULIP_PERF_CURRENT 0
-#define TULIP_PERF_PREVIOUS 1
-#define TULIP_PERF_TOTAL 2
-#define TULIP_PERF_MAX 3
- struct tulip_perfstats {
- u_quad_t perf_intr_cycles;
- u_quad_t perf_ifstart_cycles;
- u_quad_t perf_ifstart_one_cycles;
- u_quad_t perf_ifioctl_cycles;
- u_quad_t perf_ifwatchdog_cycles;
- u_quad_t perf_timeout_cycles;
- u_quad_t perf_txput_cycles;
- u_quad_t perf_txintr_cycles;
- u_quad_t perf_rxintr_cycles;
- u_quad_t perf_rxget_cycles;
- unsigned perf_intr;
- unsigned perf_ifstart;
- unsigned perf_ifstart_one;
- unsigned perf_ifioctl;
- unsigned perf_ifwatchdog;
- unsigned perf_timeout;
- unsigned perf_txput;
- unsigned perf_txintr;
- unsigned perf_rxintr;
- unsigned perf_rxget;
- } tulip_perfstats[TULIP_PERF_MAX];
-#define tulip_curperfstats tulip_perfstats[TULIP_PERF_CURRENT]
-#endif
- struct ifqueue tulip_txq;
- struct ifqueue tulip_rxq;
- tulip_dot3_stats_t tulip_dot3stats;
- tulip_ringinfo_t tulip_rxinfo;
- tulip_ringinfo_t tulip_txinfo;
- tulip_media_info_t tulip_mediainfo[10];
- /*
- * The setup buffers for sending the setup frame to the chip.
- * one is the one being sent while the other is the one being
- * filled.
- */
- u_int32_t tulip_setupbuf[192/sizeof(u_int32_t)];
- u_int32_t tulip_setupdata[192/sizeof(u_int32_t)];
- char tulip_boardid[16]; /* buffer for board ID */
- u_int8_t tulip_rombuf[128];
- u_int8_t tulip_pci_busno; /* needed for multiport boards */
- u_int8_t tulip_pci_devno; /* needed for multiport boards */
- u_int8_t tulip_connidx;
- tulip_srom_connection_t tulip_conntype;
- tulip_desc_t *tulip_rxdescs;
- tulip_desc_t *tulip_txdescs;
-};
-
-#define TULIP_DO_AUTOSENSE(sc) (IFM_SUBTYPE((sc)->tulip_ifmedia.ifm_media) == IFM_AUTO)
-
-
-#if defined(TULIP_HDR_DATA)
-static const char * const tulip_chipdescs[] = {
- "21040 [10Mb/s]",
- "21041 [10Mb/s]",
- "21140 [10-100Mb/s]",
- "21140A [10-100Mb/s]",
- "21142 [10-100Mb/s]",
- "21143 [10-100Mb/s]",
-};
-
-static const char * const tulip_mediums[] = {
- "unknown", /* TULIP_MEDIA_UNKNOWN */
- "10baseT", /* TULIP_MEDIA_10BASET */
- "Full Duplex 10baseT", /* TULIP_MEDIA_10BASET_FD */
- "BNC", /* TULIP_MEDIA_BNC */
- "AUI", /* TULIP_MEDIA_AUI */
- "External SIA", /* TULIP_MEDIA_EXTSIA */
- "AUI/BNC", /* TULIP_MEDIA_AUIBNC */
- "100baseTX", /* TULIP_MEDIA_100BASET */
- "Full Duplex 100baseTX", /* TULIP_MEDIA_100BASET_FD */
- "100baseT4", /* TULIP_MEDIA_100BASET4 */
- "100baseFX", /* TULIP_MEDIA_100BASEFX */
- "Full Duplex 100baseFX", /* TULIP_MEDIA_100BASEFX_FD */
-};
-
-static const int tulip_media_to_ifmedia[] = {
- IFM_ETHER | IFM_NONE, /* TULIP_MEDIA_UNKNOWN */
- IFM_ETHER | IFM_10_T, /* TULIP_MEDIA_10BASET */
- IFM_ETHER | IFM_10_T | IFM_FDX, /* TULIP_MEDIA_10BASET_FD */
- IFM_ETHER | IFM_10_2, /* TULIP_MEDIA_BNC */
- IFM_ETHER | IFM_10_5, /* TULIP_MEDIA_AUI */
- IFM_ETHER | IFM_MANUAL, /* TULIP_MEDIA_EXTSIA */
- IFM_ETHER | IFM_10_5, /* TULIP_MEDIA_AUIBNC */
- IFM_ETHER | IFM_100_TX, /* TULIP_MEDIA_100BASET */
- IFM_ETHER | IFM_100_TX | IFM_FDX, /* TULIP_MEDIA_100BASET_FD */
- IFM_ETHER | IFM_100_T4, /* TULIP_MEDIA_100BASET4 */
- IFM_ETHER | IFM_100_FX, /* TULIP_MEDIA_100BASEFX */
- IFM_ETHER | IFM_100_FX | IFM_FDX, /* TULIP_MEDIA_100BASEFX_FD */
-};
-
-static const char * const tulip_system_errors[] = {
- "parity error",
- "master abort",
- "target abort",
- "reserved #3",
- "reserved #4",
- "reserved #5",
- "reserved #6",
- "reserved #7",
-};
-
-static const char * const tulip_status_bits[] = {
- NULL,
- "transmit process stopped",
- NULL,
- "transmit jabber timeout",
-
- NULL,
- "transmit underflow",
- NULL,
- "receive underflow",
-
- "receive process stopped",
- "receive watchdog timeout",
- NULL,
- NULL,
-
- "link failure",
- NULL,
- NULL,
-};
-
-static const struct {
- tulip_srom_connection_t sc_type;
- tulip_media_t sc_media;
- u_int32_t sc_attrs;
-} tulip_srom_conninfo[] = {
- { TULIP_SROM_CONNTYPE_10BASET, TULIP_MEDIA_10BASET },
- { TULIP_SROM_CONNTYPE_BNC, TULIP_MEDIA_BNC },
- { TULIP_SROM_CONNTYPE_AUI, TULIP_MEDIA_AUI },
- { TULIP_SROM_CONNTYPE_100BASETX, TULIP_MEDIA_100BASETX },
- { TULIP_SROM_CONNTYPE_100BASET4, TULIP_MEDIA_100BASET4 },
- { TULIP_SROM_CONNTYPE_100BASEFX, TULIP_MEDIA_100BASEFX },
- { TULIP_SROM_CONNTYPE_MII_10BASET, TULIP_MEDIA_10BASET,
- TULIP_SROM_ATTR_MII },
- { TULIP_SROM_CONNTYPE_MII_100BASETX, TULIP_MEDIA_100BASETX,
- TULIP_SROM_ATTR_MII },
- { TULIP_SROM_CONNTYPE_MII_100BASET4, TULIP_MEDIA_100BASET4,
- TULIP_SROM_ATTR_MII },
- { TULIP_SROM_CONNTYPE_MII_100BASEFX, TULIP_MEDIA_100BASEFX,
- TULIP_SROM_ATTR_MII },
- { TULIP_SROM_CONNTYPE_10BASET_NWAY, TULIP_MEDIA_10BASET,
- TULIP_SROM_ATTR_NWAY },
- { TULIP_SROM_CONNTYPE_10BASET_FD, TULIP_MEDIA_10BASET_FD },
- { TULIP_SROM_CONNTYPE_MII_10BASET_FD, TULIP_MEDIA_10BASET_FD,
- TULIP_SROM_ATTR_MII },
- { TULIP_SROM_CONNTYPE_100BASETX_FD, TULIP_MEDIA_100BASETX_FD },
- { TULIP_SROM_CONNTYPE_MII_100BASETX_FD, TULIP_MEDIA_100BASETX_FD,
- TULIP_SROM_ATTR_MII },
- { TULIP_SROM_CONNTYPE_10BASET_NOLINKPASS, TULIP_MEDIA_10BASET,
- TULIP_SROM_ATTR_NOLINKPASS },
- { TULIP_SROM_CONNTYPE_AUTOSENSE, TULIP_MEDIA_UNKNOWN,
- TULIP_SROM_ATTR_AUTOSENSE },
- { TULIP_SROM_CONNTYPE_AUTOSENSE_POWERUP, TULIP_MEDIA_UNKNOWN,
- TULIP_SROM_ATTR_AUTOSENSE|TULIP_SROM_ATTR_POWERUP },
- { TULIP_SROM_CONNTYPE_AUTOSENSE_NWAY, TULIP_MEDIA_UNKNOWN,
- TULIP_SROM_ATTR_AUTOSENSE|TULIP_SROM_ATTR_NWAY },
- { TULIP_SROM_CONNTYPE_NOT_USED, TULIP_MEDIA_UNKNOWN }
-};
-#define TULIP_SROM_LASTCONNIDX \
- (sizeof(tulip_srom_conninfo)/sizeof(tulip_srom_conninfo[0]) - 1)
-
-static const struct {
- tulip_media_t sm_type;
- tulip_srom_media_t sm_srom_type;
-} tulip_srom_mediums[] = {
- { TULIP_MEDIA_100BASEFX_FD, TULIP_SROM_MEDIA_100BASEFX_FD },
- { TULIP_MEDIA_100BASEFX, TULIP_SROM_MEDIA_100BASEFX },
- { TULIP_MEDIA_100BASET4, TULIP_SROM_MEDIA_100BASET4 },
- { TULIP_MEDIA_100BASETX_FD, TULIP_SROM_MEDIA_100BASETX_FD },
- { TULIP_MEDIA_100BASETX, TULIP_SROM_MEDIA_100BASETX },
- { TULIP_MEDIA_10BASET_FD, TULIP_SROM_MEDIA_10BASET_FD },
- { TULIP_MEDIA_AUI, TULIP_SROM_MEDIA_AUI },
- { TULIP_MEDIA_BNC, TULIP_SROM_MEDIA_BNC },
- { TULIP_MEDIA_10BASET, TULIP_SROM_MEDIA_10BASET },
- { TULIP_MEDIA_UNKNOWN }
-};
-#endif /* TULIP_HDR_DATA */
-
-/*
- * This driver supports a maximum of 32 tulip boards.
- * This should be enough for the forseeable future.
- */
-#define TULIP_MAX_DEVICES 32
-
-#if defined(TULIP_USE_SOFTINTR) && defined(TULIP_HDR_DATA)
-static u_int32_t tulip_softintr_mask;
-static int tulip_softintr_last_unit;
-static int tulip_softintr_max_unit;
-static void tulip_softintr(void);
-#endif
-
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
-#define TULIP_RXDESC_PRESYNC(sc, di, s) \
- bus_dmamap_sync((sc)->tulip_dmatag, (sc)->tulip_rxdescmap, \
- (caddr_t) di - (caddr_t) (sc)->tulip_rxdescs, \
- (s), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)
-#define TULIP_RXDESC_POSTSYNC(sc, di, s) \
- bus_dmamap_sync((sc)->tulip_dmatag, (sc)->tulip_rxdescmap, \
- (caddr_t) di - (caddr_t) (sc)->tulip_rxdescs, \
- (s), BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)
-#define TULIP_RXMAP_PRESYNC(sc, map) \
- bus_dmamap_sync((sc)->tulip_dmatag, (map), 0, (map)->dm_mapsize, \
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)
-#define TULIP_RXMAP_POSTSYNC(sc, map) \
- bus_dmamap_sync((sc)->tulip_dmatag, (map), 0, (map)->dm_mapsize, \
- BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)
-#define TULIP_RXMAP_CREATE(sc, mapp) \
- bus_dmamap_create((sc)->tulip_dmatag, TULIP_RX_BUFLEN, 2, \
- TULIP_DATA_PER_DESC, 0, \
- BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW, (mapp))
-#else
-#ifdef __alpha__
-#define TULIP_RXDESC_PRESYNC(sc, di, s) alpha_mb()
-#define TULIP_RXDESC_POSTSYNC(sc, di, s) alpha_mb()
-#define TULIP_RXMAP_PRESYNC(sc, map) alpha_mb()
-#define TULIP_RXMAP_POSTSYNC(sc, map) alpha_mb()
-#else
-#define TULIP_RXDESC_PRESYNC(sc, di, s) do { } while (0)
-#define TULIP_RXDESC_POSTSYNC(sc, di, s) do { } while (0)
-#define TULIP_RXMAP_PRESYNC(sc, map) do { } while (0)
-#define TULIP_RXMAP_POSTSYNC(sc, map) do { } while (0)
-#endif
-#define TULIP_RXMAP_CREATE(sc, mapp) do { } while (0)
-#endif
-
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
-#define TULIP_TXDESC_PRESYNC(sc, di, s) \
- bus_dmamap_sync((sc)->tulip_dmatag, (sc)->tulip_txdescmap, \
- (caddr_t) di - (caddr_t) (sc)->tulip_txdescs, \
- (s), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)
-#define TULIP_TXDESC_POSTSYNC(sc, di, s) \
- bus_dmamap_sync((sc)->tulip_dmatag, (sc)->tulip_txdescmap, \
- (caddr_t) di - (caddr_t) (sc)->tulip_txdescs, \
- (s), BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)
-#define TULIP_TXMAP_PRESYNC(sc, map) \
- bus_dmamap_sync((sc)->tulip_dmatag, (map), 0, (map)->dm_mapsize, \
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)
-#define TULIP_TXMAP_POSTSYNC(sc, map) \
- bus_dmamap_sync((sc)->tulip_dmatag, (map), 0, (map)->dm_mapsize, \
- BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)
-#define TULIP_TXMAP_CREATE(sc, mapp) \
- bus_dmamap_create((sc)->tulip_dmatag, TULIP_DATA_PER_DESC, \
- TULIP_MAX_TXSEG, TULIP_DATA_PER_DESC, \
- 0, BUS_DMA_NOWAIT, (mapp))
-#else
-#ifdef __alpha__
-#define TULIP_TXDESC_PRESYNC(sc, di, s) alpha_mb()
-#define TULIP_TXDESC_POSTSYNC(sc, di, s) alpha_mb()
-#define TULIP_TXMAP_PRESYNC(sc, map) alpha_mb()
-#define TULIP_TXMAP_POSTSYNC(sc, map) alpha_mb()
-#else
-#define TULIP_TXDESC_PRESYNC(sc, di, s) do { } while (0)
-#define TULIP_TXDESC_POSTSYNC(sc, di, s) do { } while (0)
-#define TULIP_TXMAP_PRESYNC(sc, map) do { } while (0)
-#define TULIP_TXMAP_POSTSYNC(sc, map) do { } while (0)
-#endif
-#define TULIP_TXMAP_CREATE(sc, mapp) do { } while (0)
-#endif
-
-#ifdef notyet
-#define SIOCGADDRROM _IOW('i', 240, struct ifreq) /* get 128 bytes of ROM */
-#define SIOCGCHIPID _IOWR('i', 241, struct ifreq) /* get chipid */
-#endif
-
-#if defined(TULIP_HDR_DATA)
-static tulip_softc_t *tulips[TULIP_MAX_DEVICES];
-#endif
-
-#if defined(TULIP_USE_SOFTINTR)
-NETISR_SET(NETISR_DE, tulip_softintr);
-#endif
-
-#define loudprintf if (bootverbose) printf
-
-#ifndef tulip_if
-#define tulip_if tulip_ac.ac_if
-#endif
-#ifndef tulip_unit
-#define tulip_unit tulip_if.if_unit
-#endif
-#define tulip_name tulip_if.if_name
-#ifndef tulip_enaddr
-#define tulip_enaddr tulip_ac.ac_enaddr
-#endif
-
-#if !defined(TULIP_KVATOPHYS) && (!defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NORX) || defined(TULIP_BUS_DMA_NOTX))
-#if defined(__alpha__)
-/* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */
-#define vtobus(va) alpha_XXX_dmamap((vm_offset_t)va)
-#else
-#define vtobus(va) vtophys(va)
-#endif
-#define TULIP_KVATOPHYS(sc, va) vtobus(va)
-#endif
-
-#if defined(TULIP_PERFSTATS)
-#define TULIP_PERFMERGE(sc, member) \
- do { (sc)->tulip_perfstats[TULIP_PERF_TOTAL].member \
- += (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member; \
- (sc)->tulip_perfstats[TULIP_PERF_PREVIOUS].member \
- = (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member; \
- (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member = 0; } while (0)
-#define TULIP_PERFSTART(name) const tulip_cycle_t perfstart_ ## name = TULIP_PERFREAD();
-#define TULIP_PERFEND(name) do { \
- (sc)->tulip_curperfstats.perf_ ## name ## _cycles += TULIP_PERFDIFF(perfstart_ ## name, TULIP_PERFREAD()); \
- (sc)->tulip_curperfstats.perf_ ## name ++; \
- } while (0)
-#if defined(__i386__)
-typedef u_quad_t tulip_cycle_t;
-static __inline__ tulip_cycle_t
-TULIP_PERFREAD(
- void)
-{
- tulip_cycle_t x;
- __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
- return x;
-}
-#define TULIP_PERFDIFF(s, f) ((f) - (s))
-#elif defined(__alpha__)
-typedef unsigned long tulip_cycle_t;
-static __inline__ tulip_cycle_t
-TULIP_PERFREAD(
- void)
-{
- tulip_cycle_t x;
- __asm__ volatile ("rpcc %0" : "=r" (x));
- return x;
-}
-#define TULIP_PERFDIFF(s, f) ((unsigned int) ((f) - (s)))
-#endif
-#else
-#define TULIP_PERFSTART(name)
-#define TULIP_PERFEND(name) do { } while (0)
-#define TULIP_PERFMERGE(s,n) do { } while (0)
-#endif /* TULIP_PERFSTATS */
-
-#define TULIP_CRC32_POLY 0xEDB88320UL /* CRC-32 Poly -- Little Endian */
-#define TULIP_MAX_TXSEG 30
-
-#define TULIP_ADDREQUAL(a1, a2) \
- (((u_int16_t *)a1)[0] == ((u_int16_t *)a2)[0] \
- && ((u_int16_t *)a1)[1] == ((u_int16_t *)a2)[1] \
- && ((u_int16_t *)a1)[2] == ((u_int16_t *)a2)[2])
-#define TULIP_ADDRBRDCST(a1) \
- (((u_int16_t *)a1)[0] == 0xFFFFU \
- && ((u_int16_t *)a1)[1] == 0xFFFFU \
- && ((u_int16_t *)a1)[2] == 0xFFFFU)
-
-#endif /* !defined(_DEVAR_H) */
diff --git a/sys/dev/en/if_en_pci.c b/sys/dev/en/if_en_pci.c
deleted file mode 100644
index b1ab33e40506..000000000000
--- a/sys/dev/en/if_en_pci.c
+++ /dev/null
@@ -1,481 +0,0 @@
-/* $NetBSD: if_en_pci.c,v 1.1 1996/06/22 02:00:31 chuck Exp $ */
-
-/*
- *
- * Copyright (c) 1996 Charles D. Cranor and Washington University.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Charles D. Cranor and
- * Washington University.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-/*
- *
- * i f _ e n _ p c i . c
- *
- * author: Chuck Cranor <chuck@ccrc.wustl.edu>
- * started: spring, 1996.
- *
- * FreeBSD PCI glue for the eni155p card.
- * thanks to Matt Thomas for figuring out FreeBSD vs NetBSD vs etc.. diffs.
- */
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/systm.h>
-#include <sys/socket.h>
-#include <sys/sysctl.h>
-
-#include <sys/bus.h>
-#include <machine/bus.h>
-#include <sys/rman.h>
-#include <machine/resource.h>
-
-#include <vm/uma.h>
-
-#include <net/if.h>
-#include <net/if_atm.h>
-
-#include <pci/pcivar.h>
-#include <pci/pcireg.h>
-
-#include <dev/en/midwayreg.h>
-#include <dev/en/midwayvar.h>
-
-MODULE_DEPEND(en, pci, 1, 1, 1);
-MODULE_DEPEND(en, atm, 1, 1, 1);
-
-/*
- * local structures
- */
-struct en_pci_softc {
- /* bus independent stuff */
- struct en_softc esc; /* includes "device" structure */
-
- /* freebsd newbus glue */
- struct resource *res; /* resource descriptor for registers */
- struct resource *irq; /* resource descriptor for interrupt */
- void *ih; /* interrupt handle */
-};
-
-static void eni_get_macaddr(device_t, struct en_pci_softc *);
-static void adp_get_macaddr(struct en_pci_softc *);
-
-/*
- * address of config base memory address register in PCI config space
- * (this is card specific)
- */
-#define PCI_CBMA 0x10
-
-/*
- * tonga (pci bridge). ENI cards only!
- */
-#define EN_TONGA 0x60 /* PCI config addr of tonga reg */
-
-#define TONGA_SWAP_DMA 0x80 /* endian swap control */
-#define TONGA_SWAP_BYTE 0x40
-#define TONGA_SWAP_WORD 0x20
-#define TONGA_READ_MULT 0x00
-#define TONGA_READ_MEM 0x04
-#define TONGA_READ_IVAN 0x08
-#define TONGA_READ_KEN 0x0C
-
-/*
- * adaptec pci bridge. ADP cards only!
- */
-#define ADP_PCIREG 0x050040 /* PCI control register */
-
-#define ADP_PCIREG_RESET 0x1 /* reset card */
-#define ADP_PCIREG_IENABLE 0x2 /* interrupt enable */
-#define ADP_PCIREG_SWAP_WORD 0x4 /* swap byte on slave access */
-#define ADP_PCIREG_SWAP_DMA 0x8 /* swap byte on DMA */
-
-#define PCI_VENDOR_EFFICIENTNETS 0x111a /* Efficent Networks */
-#define PCI_PRODUCT_EFFICIENTNETS_ENI155PF 0x0000 /* ENI-155P ATM */
-#define PCI_PRODUCT_EFFICIENTNETS_ENI155PA 0x0002 /* ENI-155P ATM */
-#define PCI_VENDOR_ADP 0x9004 /* adaptec */
-#define PCI_PRODUCT_ADP_AIC5900 0x5900
-#define PCI_PRODUCT_ADP_AIC5905 0x5905
-#define PCI_VENDOR(x) ((x) & 0xFFFF)
-#define PCI_CHIPID(x) (((x) >> 16) & 0xFFFF)
-
-/*
- * bus specific reset function [ADP only!]
- */
-static void
-adp_busreset(void *v)
-{
- struct en_softc *sc = (struct en_softc *)v;
- uint32_t dummy;
-
- bus_space_write_4(sc->en_memt, sc->en_base, ADP_PCIREG,
- ADP_PCIREG_RESET);
- DELAY(1000); /* let it reset */
- dummy = bus_space_read_4(sc->en_memt, sc->en_base, ADP_PCIREG);
- bus_space_write_4(sc->en_memt, sc->en_base, ADP_PCIREG,
- (ADP_PCIREG_SWAP_DMA | ADP_PCIREG_IENABLE));
- dummy = bus_space_read_4(sc->en_memt, sc->en_base, ADP_PCIREG);
- if ((dummy & (ADP_PCIREG_SWAP_WORD | ADP_PCIREG_SWAP_DMA)) !=
- ADP_PCIREG_SWAP_DMA)
- if_printf(&sc->ifatm.ifnet, "adp_busreset: Adaptec ATM did "
- "NOT reset!\n");
-}
-
-/***********************************************************************/
-
-/*
- * autoconfig stuff
- */
-static int
-en_pci_probe(device_t dev)
-{
- switch (pci_get_vendor(dev)) {
-
- case PCI_VENDOR_EFFICIENTNETS:
- switch (pci_get_device(dev)) {
-
- case PCI_PRODUCT_EFFICIENTNETS_ENI155PF:
- case PCI_PRODUCT_EFFICIENTNETS_ENI155PA:
- device_set_desc(dev, "Efficient Networks ENI-155p");
- return (0);
- }
- break;
-
- case PCI_VENDOR_ADP:
- switch (pci_get_device(dev)) {
-
- case PCI_PRODUCT_ADP_AIC5900:
- case PCI_PRODUCT_ADP_AIC5905:
- device_set_desc(dev, "Adaptec 155 ATM");
- return (0);
- }
- break;
- }
- return (ENXIO);
-}
-
-static int
-en_pci_attach(device_t dev)
-{
- struct en_softc *sc;
- struct en_pci_softc *scp;
- u_long val;
- int rid, unit, error = 0;
-
- sc = device_get_softc(dev);
- scp = (struct en_pci_softc *)sc;
-
- unit = device_get_unit(dev);
- sc->ifatm.ifnet.if_unit = unit;
- sc->ifatm.ifnet.if_name = "en";
-
- /*
- * Enable bus mastering.
- */
- val = pci_read_config(dev, PCIR_COMMAND, 2);
- val |= (PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN);
- pci_write_config(dev, PCIR_COMMAND, val, 2);
-
- /*
- * Map control/status registers.
- */
- rid = PCI_CBMA;
- scp->res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
- 0, ~0, 1, RF_ACTIVE);
- if (scp->res == NULL) {
- device_printf(dev, "could not map memory\n");
- error = ENXIO;
- goto fail;
- }
-
- sc->dev = dev;
- sc->en_memt = rman_get_bustag(scp->res);
- sc->en_base = rman_get_bushandle(scp->res);
-
- /*
- * Allocate our interrupt.
- */
- rid = 0;
- scp->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE | RF_ACTIVE);
- if (scp->irq == NULL) {
- device_printf(dev, "could not map interrupt\n");
- bus_release_resource(dev, SYS_RES_MEMORY, PCI_CBMA, scp->res);
- error = ENXIO;
- goto fail;
- }
-
- sc->ipl = 1; /* XXX (required to enable interrupt on midway) */
-
- /* figure out if we are an adaptec card or not */
- sc->is_adaptec = (pci_get_vendor(dev) == PCI_VENDOR_ADP) ? 1 : 0;
-
- /*
- * set up pci bridge
- */
- if (sc->is_adaptec) {
- adp_get_macaddr(scp);
- sc->en_busreset = adp_busreset;
- adp_busreset(sc);
- } else {
- eni_get_macaddr(dev, scp);
- sc->en_busreset = NULL;
- pci_write_config(dev, EN_TONGA, TONGA_SWAP_DMA | TONGA_READ_IVAN, 4);
- }
-
- /*
- * Common attach stuff
- */
- if ((error = en_attach(sc)) != 0) {
- device_printf(dev, "attach failed\n");
- bus_teardown_intr(dev, scp->irq, scp->ih);
- bus_release_resource(dev, SYS_RES_IRQ, 0, scp->irq);
- bus_release_resource(dev, SYS_RES_MEMORY, PCI_CBMA, scp->res);
- goto fail;
- }
-
- /*
- * Do the interrupt SETUP last just before returning
- */
- error = bus_setup_intr(dev, scp->irq, INTR_TYPE_NET,
- en_intr, sc, &scp->ih);
- if (error) {
- en_reset(sc);
- atm_ifdetach(&sc->ifatm.ifnet);
- device_printf(dev, "could not setup irq\n");
- bus_release_resource(dev, SYS_RES_IRQ, 0, scp->irq);
- bus_release_resource(dev, SYS_RES_MEMORY, PCI_CBMA, scp->res);
- en_destroy(sc);
- goto fail;
- }
-
- return (0);
-
- fail:
- return (error);
-}
-
-/*
- * Detach the adapter
- */
-static int
-en_pci_detach(device_t dev)
-{
- struct en_softc *sc = device_get_softc(dev);
- struct en_pci_softc *scp = (struct en_pci_softc *)sc;
-
- /*
- * Stop DMA and drop transmit queue.
- */
- if ((sc->ifatm.ifnet.if_flags & IFF_RUNNING)) {
- if_printf(&sc->ifatm.ifnet, "still running\n");
- sc->ifatm.ifnet.if_flags &= ~IFF_RUNNING;
- }
-
- /*
- * Close down routes etc.
- */
- en_reset(sc);
- atm_ifdetach(&sc->ifatm.ifnet);
-
- /*
- * Deallocate resources.
- */
- bus_teardown_intr(dev, scp->irq, scp->ih);
- bus_release_resource(dev, SYS_RES_IRQ, 0, scp->irq);
- bus_release_resource(dev, SYS_RES_MEMORY, PCI_CBMA, scp->res);
-
- /*
- * Free all the driver internal resources
- */
- en_destroy(sc);
-
- return (0);
-}
-
-static int
-en_pci_shutdown(device_t dev)
-{
- struct en_pci_softc *psc = device_get_softc(dev);
-
- en_reset(&psc->esc);
- DELAY(10); /* is this necessary? */
-
- return (0);
-}
-
-/*
- * Get the MAC address from an Adaptec board. No idea how to get
- * serial number or other stuff, because I have no documentation for that
- * card.
- */
-static void
-adp_get_macaddr(struct en_pci_softc *scp)
-{
- struct en_softc * sc = (struct en_softc *)scp;
- int lcv;
-
- for (lcv = 0; lcv < sizeof(sc->ifatm.mib.esi); lcv++)
- sc->ifatm.mib.esi[lcv] = bus_space_read_1(sc->en_memt,
- sc->en_base, MID_ADPMACOFF + lcv);
-}
-
-/*
- * Read station (MAC) address from serial EEPROM.
- * derived from linux drivers/atm/eni.c by Werner Almesberger, EPFL LRC.
- */
-#define EN_PROM_MAGIC 0x0c
-#define EN_PROM_DATA 0x02
-#define EN_PROM_CLK 0x01
-#define EN_ESI 64
-#define EN_SERIAL 112
-
-/*
- * Read a byte from the given address in the EEPROM
- */
-static uint8_t
-eni_get_byte(device_t dev, uint32_t *data, u_int address)
-{
- int j;
- uint8_t tmp;
-
- address = (address << 1) + 1;
-
- /* start operation */
- *data |= EN_PROM_DATA ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data |= EN_PROM_CLK ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data &= ~EN_PROM_DATA ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data &= ~EN_PROM_CLK ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- /* send address with serial line */
- for ( j = 7 ; j >= 0 ; j --) {
- *data = ((address >> j) & 1) ? (*data | EN_PROM_DATA) :
- (*data & ~EN_PROM_DATA);
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data |= EN_PROM_CLK ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data &= ~EN_PROM_CLK ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- }
- /* get ack */
- *data |= EN_PROM_DATA ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data |= EN_PROM_CLK ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data = pci_read_config(dev, EN_TONGA, 4);
- *data &= ~EN_PROM_CLK ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data |= EN_PROM_DATA ;
- pci_write_config(dev, EN_TONGA, *data, 4);
-
- tmp = 0;
-
- for ( j = 7 ; j >= 0 ; j --) {
- tmp <<= 1;
- *data |= EN_PROM_DATA ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data |= EN_PROM_CLK ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data = pci_read_config(dev, EN_TONGA, 4);
- if(*data & EN_PROM_DATA) tmp |= 1;
- *data &= ~EN_PROM_CLK ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data |= EN_PROM_DATA ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- }
- /* get ack */
- *data |= EN_PROM_DATA ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data |= EN_PROM_CLK ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data = pci_read_config(dev, EN_TONGA, 4);
- *data &= ~EN_PROM_CLK ;
- pci_write_config(dev, EN_TONGA, *data, 4);
- *data |= EN_PROM_DATA ;
- pci_write_config(dev, EN_TONGA, *data, 4);
-
- return (tmp);
-}
-
-/*
- * Get MAC address and other stuff from the EEPROM
- */
-static void
-eni_get_macaddr(device_t dev, struct en_pci_softc *scp)
-{
- struct en_softc * sc = (struct en_softc *)scp;
- int i;
- uint32_t data, t_data;
-
- t_data = pci_read_config(dev, EN_TONGA, 4) & 0xffffff00;
-
- data = EN_PROM_MAGIC | EN_PROM_DATA | EN_PROM_CLK;
- pci_write_config(dev, EN_TONGA, data, 4);
-
- for (i = 0; i < sizeof(sc->ifatm.mib.esi); i ++)
- sc->ifatm.mib.esi[i] = eni_get_byte(dev, &data, i + EN_ESI);
-
- sc->ifatm.mib.serial = 0;
- for (i = 0; i < 4; i++) {
- sc->ifatm.mib.serial <<= 8;
- sc->ifatm.mib.serial |= eni_get_byte(dev, &data, i + EN_SERIAL);
- }
- /* stop operation */
- data &= ~EN_PROM_DATA;
- pci_write_config(dev, EN_TONGA, data, 4);
- data |= EN_PROM_CLK;
- pci_write_config(dev, EN_TONGA, data, 4);
- data |= EN_PROM_DATA;
- pci_write_config(dev, EN_TONGA, data, 4);
- pci_write_config(dev, EN_TONGA, t_data, 4);
-}
-
-/*
- * Driver infrastructure
- */
-static device_method_t en_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, en_pci_probe),
- DEVMETHOD(device_attach, en_pci_attach),
- DEVMETHOD(device_detach, en_pci_detach),
- DEVMETHOD(device_shutdown, en_pci_shutdown),
-
- { 0, 0 }
-};
-
-static driver_t en_driver = {
- "en",
- en_methods,
- sizeof(struct en_pci_softc),
-};
-
-static devclass_t en_devclass;
-
-DRIVER_MODULE(en, pci, en_driver, en_devclass, 0, 0);
diff --git a/sys/dev/fb/splash_bmp.c b/sys/dev/fb/splash_bmp.c
deleted file mode 100644
index e4cc5203e8a4..000000000000
--- a/sys/dev/fb/splash_bmp.c
+++ /dev/null
@@ -1,642 +0,0 @@
-/*-
- * Copyright (c) 1999 Michael Smith <msmith@freebsd.org>
- * Copyright (c) 1999 Kazutaka YOKOTA <yokota@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/linker.h>
-#include <sys/fbio.h>
-
-#include <dev/fb/fbreg.h>
-#include <dev/fb/splashreg.h>
-#ifndef PC98
-#include <dev/fb/vgareg.h>
-
-#include <isa/isareg.h>
-#endif
-
-#define FADE_TIMEOUT 15 /* sec */
-#define FADE_LEVELS 10
-
-static int splash_mode = -1;
-static int splash_on = FALSE;
-
-static int bmp_start(video_adapter_t *adp);
-static int bmp_end(video_adapter_t *adp);
-static int bmp_splash(video_adapter_t *adp, int on);
-static int bmp_Init(char *data, int swidth, int sheight, int sdepth);
-static int bmp_Draw(video_adapter_t *adp);
-
-static splash_decoder_t bmp_decoder = {
- "splash_bmp", bmp_start, bmp_end, bmp_splash, SPLASH_IMAGE,
-};
-
-SPLASH_DECODER(splash_bmp, bmp_decoder);
-
-static int
-bmp_start(video_adapter_t *adp)
-{
- /* currently only 256-color modes are supported XXX */
- static int modes[] = {
-#ifdef PC98
- /*
- * As 640x400 doesn't generally look great,
- * it's least preferred here.
- */
- M_PC98_PEGC640x400,
- M_PC98_PEGC640x480,
- M_PC98_EGC640x400,
-#else
- M_VESA_CG640x480,
- M_VESA_CG800x600,
- M_VESA_CG1024x768,
- M_CG640x480,
- /*
- * As 320x200 doesn't generally look great,
- * it's least preferred here.
- */
- M_VGA_CG320,
-#endif
- -1,
- };
- video_info_t info;
- int i;
-
- if ((bmp_decoder.data == NULL) || (bmp_decoder.data_size <= 0)) {
- printf("splash_bmp: No bitmap file found\n");
- return ENODEV;
- }
- for (i = 0; modes[i] >= 0; ++i) {
- if (((*vidsw[adp->va_index]->get_info)(adp, modes[i], &info) == 0)
- && (bmp_Init((u_char *)bmp_decoder.data,
- info.vi_width, info.vi_height, info.vi_depth) == 0))
- break;
- }
- splash_mode = modes[i];
- if (splash_mode < 0)
- printf("splash_bmp: No appropriate video mode found\n");
- if (bootverbose)
- printf("bmp_start(): splash_mode:%d\n", splash_mode);
- return ((splash_mode < 0) ? ENODEV : 0);
-}
-
-static int
-bmp_end(video_adapter_t *adp)
-{
- /* nothing to do */
- return 0;
-}
-
-static int
-bmp_splash(video_adapter_t *adp, int on)
-{
- static u_char pal[256*3];
- static long time_stamp;
- u_char tpal[256*3];
- static int fading = TRUE, brightness = FADE_LEVELS;
- struct timeval tv;
- int i;
-
- if (on) {
- if (!splash_on) {
- /* set up the video mode and draw something */
- if ((*vidsw[adp->va_index]->set_mode)(adp, splash_mode))
- return 1;
- if (bmp_Draw(adp))
- return 1;
- (*vidsw[adp->va_index]->save_palette)(adp, pal);
- time_stamp = 0;
- splash_on = TRUE;
- }
- /*
- * This is a kludge to fade the image away. This section of the
- * code takes effect only after the system is completely up.
- * FADE_TIMEOUT should be configurable.
- */
- if (!cold) {
- getmicrotime(&tv);
- if (time_stamp == 0)
- time_stamp = tv.tv_sec;
- if (tv.tv_sec > time_stamp + FADE_TIMEOUT) {
- if (fading)
- if (brightness == 0) {
- fading = FALSE;
- brightness++;
- }
- else brightness--;
- else
- if (brightness == FADE_LEVELS) {
- fading = TRUE;
- brightness--;
- }
- else brightness++;
- for (i = 0; i < sizeof(pal); ++i) {
- tpal[i] = pal[i] * brightness / FADE_LEVELS;
- }
- (*vidsw[adp->va_index]->load_palette)(adp, tpal);
- time_stamp = tv.tv_sec;
- }
- }
- return 0;
- } else {
- /* the video mode will be restored by the caller */
- splash_on = FALSE;
- return 0;
- }
-}
-
-/*
-** Code to handle Microsoft DIB (".BMP") format images.
-**
-** Blame me (msmith@freebsd.org) if this is broken, not Soren.
-*/
-
-typedef struct tagBITMAPFILEHEADER { /* bmfh */
- u_short bfType __packed;
- int bfSize __packed;
- u_short bfReserved1 __packed;
- u_short bfReserved2 __packed;
- int bfOffBits __packed;
-} BITMAPFILEHEADER;
-
-typedef struct tagBITMAPINFOHEADER { /* bmih */
- int biSize __packed;
- int biWidth __packed;
- int biHeight __packed;
- short biPlanes __packed;
- short biBitCount __packed;
- int biCompression __packed;
- int biSizeImage __packed;
- int biXPelsPerMeter __packed;
- int biYPelsPerMeter __packed;
- int biClrUsed __packed;
- int biClrImportant __packed;
-} BITMAPINFOHEADER;
-
-typedef struct tagRGBQUAD { /* rgbq */
- u_char rgbBlue __packed;
- u_char rgbGreen __packed;
- u_char rgbRed __packed;
- u_char rgbReserved __packed;
-} RGBQUAD;
-
-typedef struct tagBITMAPINFO { /* bmi */
- BITMAPINFOHEADER bmiHeader __packed;
- RGBQUAD bmiColors[256] __packed;
-} BITMAPINFO;
-
-typedef struct tagBITMAPF
-{
- BITMAPFILEHEADER bmfh __packed;
- BITMAPINFO bmfi __packed;
-} BITMAPF;
-
-#define BI_RGB 0
-#define BI_RLE8 1
-#define BI_RLE4 2
-
-/*
-** all we actually care about the image
-*/
-typedef struct
-{
- int width,height; /* image dimensions */
- int swidth,sheight; /* screen dimensions for the current mode */
- u_char depth; /* image depth (1, 4, 8, 24 bits) */
- u_char sdepth; /* screen depth (1, 4, 8 bpp) */
- int ncols; /* number of colours */
- u_char palette[256][3]; /* raw palette data */
- u_char format; /* one of the BI_* constants above */
- u_char *data; /* pointer to the raw data */
- u_char *index; /* running pointer to the data while drawing */
- u_char *vidmem; /* video memory allocated for drawing */
- video_adapter_t *adp;
- int bank;
-#ifdef PC98
- u_char prev_val;
-#endif
-} BMP_INFO;
-
-static BMP_INFO bmp_info;
-
-/*
-** bmp_SetPix
-**
-** Given (info), set the pixel at (x),(y) to (val)
-**
-*/
-static void
-bmp_SetPix(BMP_INFO *info, int x, int y, u_char val)
-{
- int sofs, bofs;
- int newbank;
-
- /*
- * range check to avoid explosions
- */
- if ((x < 0) || (x >= info->swidth) || (y < 0) || (y >= info->sheight))
- return;
-
- /*
- * calculate offset into video memory;
- * because 0,0 is bottom-left for DIB, we have to convert.
- */
- sofs = ((info->height - (y+1) + (info->sheight - info->height) / 2)
- * info->adp->va_line_width);
- x += (info->swidth - info->width) / 2;
-
- switch(info->sdepth) {
-#ifdef PC98
- case 4:
- sofs += (x >> 3);
- bofs = x & 0x7; /* offset within byte */
-
- outb(0x7c, 0x80 | 0x40); /* GRCG on & RMW mode */
- if (val != info->prev_val) {
- outb(0x7e, (val & 1) ? 0xff : 0); /* tile B */
- outb(0x7e, (val & 2) ? 0xff : 0); /* tile R */
- outb(0x7e, (val & 4) ? 0xff : 0); /* tile G */
- outb(0x7e, (val & 8) ? 0xff : 0); /* tile I */
-
- info->prev_val = val;
- }
-
- *(info->vidmem+sofs) = (0x80 >> bofs); /* write new bit */
- outb(0x7c, 0); /* GRCG off */
- break;
-#else
- case 4:
- case 1:
- /* EGA/VGA planar modes */
- sofs += (x >> 3);
- newbank = sofs/info->adp->va_window_size;
- if (info->bank != newbank) {
- (*vidsw[info->adp->va_index]->set_win_org)(info->adp, newbank*info->adp->va_window_size);
- info->bank = newbank;
- }
- sofs %= info->adp->va_window_size;
- bofs = x & 0x7; /* offset within byte */
- outw(GDCIDX, (0x8000 >> bofs) | 0x08); /* bit mask */
- outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
- *(info->vidmem + sofs) ^= 0xff; /* read-modify-write */
- break;
-#endif
-
- case 8:
- sofs += x;
- newbank = sofs/info->adp->va_window_size;
- if (info->bank != newbank) {
- (*vidsw[info->adp->va_index]->set_win_org)(info->adp, newbank*info->adp->va_window_size);
- info->bank = newbank;
- }
- sofs %= info->adp->va_window_size;
- *(info->vidmem+sofs) = val;
- break;
- }
-}
-
-/*
-** bmp_DecodeRLE4
-**
-** Given (data) pointing to a line of RLE4-format data and (line) being the starting
-** line onscreen, decode the line.
-*/
-static void
-bmp_DecodeRLE4(BMP_INFO *info, int line)
-{
- int count; /* run count */
- u_char val;
- int x,y; /* screen position */
-
- x = 0; /* starting position */
- y = line;
-
- /* loop reading data */
- for (;;) {
- /*
- * encoded mode starts with a run length, and then a byte with
- * two colour indexes to alternate between for the run
- */
- if (*info->index) {
- for (count = 0; count < *info->index; count++, x++) {
- if (count & 1) { /* odd count, low nybble */
- bmp_SetPix(info, x, y, *(info->index+1) & 0x0f);
- } else { /* even count, high nybble */
- bmp_SetPix(info, x, y, (*(info->index+1) >>4) & 0x0f);
- }
- }
- info->index += 2;
- /*
- * A leading zero is an escape; it may signal the end of the
- * bitmap, a cursor move, or some absolute data.
- */
- } else { /* zero tag may be absolute mode or an escape */
- switch (*(info->index+1)) {
- case 0: /* end of line */
- info->index += 2;
- return;
- case 1: /* end of bitmap */
- info->index = NULL;
- return;
- case 2: /* move */
- x += *(info->index + 2); /* new coords */
- y += *(info->index + 3);
- info->index += 4;
- break;
- default: /* literal bitmap data */
- for (count = 0; count < *(info->index + 1); count++, x++) {
- val = *(info->index + 2 + (count / 2)); /* byte with nybbles */
- if (count & 1) {
- val &= 0xf; /* get low nybble */
- } else {
- val = (val >> 4); /* get high nybble */
- }
- bmp_SetPix(info, x, y, val);
- }
- /* warning, this depends on integer truncation, do not hand-optimise! */
- info->index += 2 + ((count + 3) / 4) * 2;
- break;
- }
- }
- }
-}
-
-/*
-** bmp_DecodeRLE8
-** Given (data) pointing to a line of RLE8-format data and (line) being the starting
-** line onscreen, decode the line.
-*/
-static void
-bmp_DecodeRLE8(BMP_INFO *info, int line)
-{
- int count; /* run count */
- int x,y; /* screen position */
-
- x = 0; /* starting position */
- y = line;
-
- /* loop reading data */
- for(;;) {
- /*
- * encoded mode starts with a run length, and then a byte with
- * two colour indexes to alternate between for the run
- */
- if (*info->index) {
- for (count = 0; count < *info->index; count++, x++)
- bmp_SetPix(info, x, y, *(info->index+1));
- info->index += 2;
- /*
- * A leading zero is an escape; it may signal the end of the
- * bitmap, a cursor move, or some absolute data.
- */
- } else { /* zero tag may be absolute mode or an escape */
- switch(*(info->index+1)) {
- case 0: /* end of line */
- info->index += 2;
- return;
- case 1: /* end of bitmap */
- info->index = NULL;
- return;
- case 2: /* move */
- x += *(info->index + 2); /* new coords */
- y += *(info->index + 3);
- info->index += 4;
- break;
- default: /* literal bitmap data */
- for (count = 0; count < *(info->index + 1); count++, x++)
- bmp_SetPix(info, x, y, *(info->index + 2 + count));
- /* must be an even count */
- info->index += 2 + count + (count & 1);
- break;
- }
- }
- }
-}
-
-/*
-** bmp_DecodeLine
-**
-** Given (info) pointing to an image being decoded, (line) being the line currently
-** being displayed, decode a line of data.
-*/
-static void
-bmp_DecodeLine(BMP_INFO *info, int line)
-{
- int x;
- u_char val, mask, *p;
-
- switch(info->format) {
- case BI_RGB:
- switch(info->depth) {
- case 8:
- for (x = 0; x < info->width; x++, info->index++)
- bmp_SetPix(info, x, line, *info->index);
- info->index += 3 - (--x % 4);
- break;
- case 4:
- p = info->index;
- for (x = 0; x < info->width; x++) {
- if (x & 1) {
- val = *p & 0xf; /* get low nybble */
- p++;
- } else {
- val = *p >> 4; /* get high nybble */
- }
- bmp_SetPix(info, x, line, val);
- }
- /* warning, this depends on integer truncation, do not hand-optimise! */
- info->index += ((x + 7) / 8) * 4;
- break;
- case 1:
- p = info->index;
- mask = 0x80;
- for (x = 0; x < info->width; x++) {
- val = (*p & mask) ? 1 : 0;
- mask >>= 1;
- if (mask == 0) {
- mask = 0x80;
- p++;
- }
- bmp_SetPix(info, x, line, val);
- }
- /* warning, this depends on integer truncation, do not hand-optimise! */
- info->index += ((x + 31) / 32) * 4;
- break;
- }
- break;
- case BI_RLE4:
- bmp_DecodeRLE4(info, line);
- break;
- case BI_RLE8:
- bmp_DecodeRLE8(info, line);
- break;
- }
-}
-
-/*
-** bmp_Init
-**
-** Given a pointer (data) to the image of a BMP file, fill in bmp_info with what
-** can be learnt from it. Return nonzero if the file isn't usable.
-**
-** Take screen dimensions (swidth), (sheight) and (sdepth) and make sure we
-** can work with these.
-*/
-static int
-bmp_Init(char *data, int swidth, int sheight, int sdepth)
-{
- BITMAPF *bmf = (BITMAPF *)data;
- int pind;
-
- bmp_info.data = NULL; /* assume setup failed */
-
- /* check file ID */
- if (bmf->bmfh.bfType != 0x4d42) {
- printf("splash_bmp: not a BMP file\n");
- return(1); /* XXX check word ordering for big-endian ports? */
- }
-
- /* do we understand this bitmap format? */
- if (bmf->bmfi.bmiHeader.biSize > sizeof(bmf->bmfi.bmiHeader)) {
- printf("splash_bmp: unsupported BMP format (size=%d)\n",
- bmf->bmfi.bmiHeader.biSize);
- return(1);
- }
-
- /* save what we know about the screen */
- bmp_info.swidth = swidth;
- bmp_info.sheight = sheight;
- bmp_info.sdepth = sdepth;
-
- /* where's the data? */
- bmp_info.data = (u_char *)data + bmf->bmfh.bfOffBits;
-
- /* image parameters */
- bmp_info.width = bmf->bmfi.bmiHeader.biWidth;
- bmp_info.height = bmf->bmfi.bmiHeader.biHeight;
- bmp_info.depth = bmf->bmfi.bmiHeader.biBitCount;
- bmp_info.format = bmf->bmfi.bmiHeader.biCompression;
-
- switch(bmp_info.format) { /* check compression format */
- case BI_RGB:
- case BI_RLE4:
- case BI_RLE8:
- break;
- default:
- printf("splash_bmp: unsupported compression format\n");
- return(1); /* unsupported compression format */
- }
-
- /* palette details */
- bmp_info.ncols = (bmf->bmfi.bmiHeader.biClrUsed);
- bzero(bmp_info.palette,sizeof(bmp_info.palette));
- if (bmp_info.ncols == 0) { /* uses all of them */
- bmp_info.ncols = 1 << bmf->bmfi.bmiHeader.biBitCount;
- }
- if ((bmp_info.height > bmp_info.sheight) ||
- (bmp_info.width > bmp_info.swidth) ||
- (bmp_info.ncols > (1 << sdepth))) {
- if (bootverbose)
- printf("splash_bmp: beyond screen capacity (%dx%d, %d colors)\n",
- bmp_info.width, bmp_info.height, bmp_info.ncols);
- return(1);
- }
-
- /* read palette */
- for (pind = 0; pind < bmp_info.ncols; pind++) {
- bmp_info.palette[pind][0] = bmf->bmfi.bmiColors[pind].rgbRed;
- bmp_info.palette[pind][1] = bmf->bmfi.bmiColors[pind].rgbGreen;
- bmp_info.palette[pind][2] = bmf->bmfi.bmiColors[pind].rgbBlue;
- }
- return(0);
-}
-
-/*
-** bmp_Draw
-**
-** Render the image. Return nonzero if that's not possible.
-**
-*/
-static int
-bmp_Draw(video_adapter_t *adp)
-{
- int line;
-#if 0
-#ifndef PC98
- int i;
-#endif
-#endif
-
- if (bmp_info.data == NULL) { /* init failed, do nothing */
- return(1);
- }
-
- /* clear the screen */
- bmp_info.vidmem = (u_char *)adp->va_window;
- bmp_info.adp = adp;
- (*vidsw[adp->va_index]->clear)(adp);
- (*vidsw[adp->va_index]->set_win_org)(adp, 0);
- bmp_info.bank = 0;
-
- /* initialise the info structure for drawing */
- bmp_info.index = bmp_info.data;
-#ifdef PC98
- bmp_info.prev_val = 255;
-#endif
-
- /* set the palette for our image */
- (*vidsw[adp->va_index]->load_palette)(adp, (u_char *)&bmp_info.palette);
-
-#if 0
-#ifndef PC98
- /* XXX: this is ugly, but necessary for EGA/VGA 1bpp/4bpp modes */
- if ((adp->va_type == KD_EGA) || (adp->va_type == KD_VGA)) {
- inb(adp->va_crtc_addr + 6); /* reset flip-flop */
- outb(ATC, 0x14);
- outb(ATC, 0);
- for (i = 0; i < 16; ++i) {
- outb(ATC, i);
- outb(ATC, i);
- }
- inb(adp->va_crtc_addr + 6); /* reset flip-flop */
- outb(ATC, 0x20); /* enable palette */
-
- outw(GDCIDX, 0x0f01); /* set/reset enable */
-
- if (bmp_info.sdepth == 1)
- outw(TSIDX, 0x0102); /* unmask plane #0 */
- }
-#endif
-#endif
-
- for (line = 0; (line < bmp_info.height) && bmp_info.index; line++) {
- bmp_DecodeLine(&bmp_info, line);
- }
- return(0);
-}
diff --git a/sys/dev/fb/splash_pcx.c b/sys/dev/fb/splash_pcx.c
deleted file mode 100644
index 04dea6481bef..000000000000
--- a/sys/dev/fb/splash_pcx.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/*-
- * Copyright (c) 1999 Michael Smith <msmith@freebsd.org>
- * Copyright (c) 1999 Kazutaka YOKOTA <yokota@freebsd.org>
- * Copyright (c) 1999 Dag-Erling Coïdan Smørgrav
- * 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
- * in this position and unchanged.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/linker.h>
-#include <sys/fbio.h>
-
-#include <dev/fb/fbreg.h>
-#include <dev/fb/splashreg.h>
-
-#define FADE_TIMEOUT 300 /* sec */
-
-static int splash_mode = -1;
-static int splash_on = FALSE;
-
-static int pcx_start(video_adapter_t *adp);
-static int pcx_end(video_adapter_t *adp);
-static int pcx_splash(video_adapter_t *adp, int on);
-static int pcx_init(char *data, int sdepth);
-static int pcx_draw(video_adapter_t *adp);
-
-static splash_decoder_t pcx_decoder = {
- "splash_pcx", pcx_start, pcx_end, pcx_splash, SPLASH_IMAGE,
-};
-
-SPLASH_DECODER(splash_pcx, pcx_decoder);
-
-static struct
-{
- int width, height, bpsl;
- int bpp, planes, zlen;
- const u_char *zdata;
- u_char *palette;
-} pcx_info;
-
-static int
-pcx_start(video_adapter_t *adp)
-{
- static int modes[] = {
- M_VGA_CG320,
- M_VESA_CG640x480,
- M_VESA_CG800x600,
- M_VESA_CG1024x768,
- -1,
- };
- video_info_t info;
- int i;
-
- if (pcx_decoder.data == NULL
- || pcx_decoder.data_size <= 0
- || pcx_init((u_char *)pcx_decoder.data, pcx_decoder.data_size))
- return ENODEV;
-
- if (bootverbose)
- printf("splash_pcx: image good:\n"
- " width = %d\n"
- " height = %d\n"
- " depth = %d\n"
- " planes = %d\n",
- pcx_info.width, pcx_info.height,
- pcx_info.bpp, pcx_info.planes);
-
- for (i = 0; modes[i] >= 0; ++i) {
- if (get_mode_info(adp, modes[i], &info) != 0)
- continue;
- if (bootverbose)
- printf("splash_pcx: considering mode %d:\n"
- " vi_width = %d\n"
- " vi_height = %d\n"
- " vi_depth = %d\n"
- " vi_planes = %d\n",
- modes[i],
- info.vi_width, info.vi_height,
- info.vi_depth, info.vi_planes);
- if (info.vi_width >= pcx_info.width
- && info.vi_height >= pcx_info.height
- && info.vi_depth == pcx_info.bpp
- && info.vi_planes == pcx_info.planes)
- break;
- }
-
- splash_mode = modes[i];
- if (splash_mode == -1)
- return ENODEV;
- if (bootverbose)
- printf("pcx_splash: selecting mode %d\n", splash_mode);
- return 0;
-}
-
-static int
-pcx_end(video_adapter_t *adp)
-{
- /* nothing to do */
- return 0;
-}
-
-static int
-pcx_splash(video_adapter_t *adp, int on)
-{
- if (on) {
- if (!splash_on) {
- if (set_video_mode(adp, splash_mode) || pcx_draw(adp))
- return 1;
- splash_on = TRUE;
- }
- return 0;
- } else {
- splash_on = FALSE;
- return 0;
- }
-}
-
-struct pcxheader {
- u_char manufactor;
- u_char version;
- u_char encoding;
- u_char bpp;
- u_short xmin, ymin, xmax, ymax;
- u_short hres, vres;
- u_char colormap[48];
- u_char rsvd;
- u_char nplanes;
- u_short bpsl;
- u_short palinfo;
- u_short hsize, vsize;
-};
-
-#define MAXSCANLINE 1024
-
-static int
-pcx_init(char *data, int size)
-{
- const struct pcxheader *hdr;
-
- hdr = (const struct pcxheader *)data;
-
- if (size < 128 + 1 + 1 + 768
- || hdr->manufactor != 10
- || hdr->version != 5
- || hdr->encoding != 1
- || hdr->nplanes != 1
- || hdr->bpp != 8
- || hdr->bpsl > MAXSCANLINE
- || data[size-769] != 12) {
- printf("splash_pcx: invalid PCX image\n");
- return 1;
- }
- pcx_info.width = hdr->xmax - hdr->xmin + 1;
- pcx_info.height = hdr->ymax - hdr->ymin + 1;
- pcx_info.bpsl = hdr->bpsl;
- pcx_info.bpp = hdr->bpp;
- pcx_info.planes = hdr->nplanes;
- pcx_info.zlen = size - (128 + 1 + 768);
- pcx_info.zdata = data + 128;
- pcx_info.palette = data + size - 768;
- return 0;
-}
-
-static int
-pcx_draw(video_adapter_t *adp)
-{
- u_char *vidmem;
- int swidth, sheight, sbpsl, sdepth, splanes;
- int banksize, origin;
- int c, i, j, pos, scan, x, y;
- u_char line[MAXSCANLINE];
-
- if (pcx_info.zlen < 1)
- return 1;
-
- load_palette(adp, pcx_info.palette);
-
- vidmem = (u_char *)adp->va_window;
- swidth = adp->va_info.vi_width;
- sheight = adp->va_info.vi_height;
- sbpsl = adp->va_line_width;
- sdepth = adp->va_info.vi_depth;
- splanes = adp->va_info.vi_planes;
- banksize = adp->va_window_size;
-
- for (origin = 0; origin < sheight*sbpsl; origin += banksize) {
- set_origin(adp, origin);
- bzero(vidmem, banksize);
- }
-
- x = (swidth - pcx_info.width) / 2;
- y = (sheight - pcx_info.height) / 2;
- origin = 0;
- pos = y * sbpsl + x;
- while (pos > banksize) {
- pos -= banksize;
- origin += banksize;
- }
- set_origin(adp, origin);
-
- for (scan = i = 0; scan < pcx_info.height; ++scan, ++y, pos += sbpsl) {
- for (j = 0; j < pcx_info.bpsl && i < pcx_info.zlen; ++i) {
- if ((pcx_info.zdata[i] & 0xc0) == 0xc0) {
- c = pcx_info.zdata[i++] & 0x3f;
- if (i >= pcx_info.zlen)
- return 1;
- } else {
- c = 1;
- }
- if (j + c > pcx_info.bpsl)
- return 1;
- while (c--)
- line[j++] = pcx_info.zdata[i];
- }
-
- if (pos > banksize) {
- origin += banksize;
- pos -= banksize;
- set_origin(adp, origin);
- }
-
- if (pos + pcx_info.width > banksize) {
- /* scanline crosses bank boundary */
- j = banksize - pos;
- bcopy(line, vidmem + pos, j);
- origin += banksize;
- pos -= banksize;
- set_origin(adp, origin);
- bcopy(line + j, vidmem, pcx_info.width - j);
- } else {
- bcopy(line, vidmem + pos, pcx_info.width);
- }
- }
-
- return 0;
-}
diff --git a/sys/dev/fdc/fdc.c b/sys/dev/fdc/fdc.c
deleted file mode 100644
index 6c6be9243aa5..000000000000
--- a/sys/dev/fdc/fdc.c
+++ /dev/null
@@ -1,2793 +0,0 @@
-/*
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Don Ahn.
- *
- * Libretto PCMCIA floppy support by David Horwitt (dhorwitt@ucsd.edu)
- * aided by the Linux floppy driver modifications from David Bateman
- * (dbateman@eng.uts.edu.au).
- *
- * Copyright (c) 1993, 1994 by
- * jc@irbs.UUCP (John Capo)
- * vak@zebub.msk.su (Serge Vakulenko)
- * ache@astral.msk.su (Andrew A. Chernov)
- *
- * Copyright (c) 1993, 1994, 1995 by
- * joerg_wunsch@uriah.sax.de (Joerg Wunsch)
- * dufault@hda.com (Peter Dufault)
- *
- * Copyright (c) 2001 Joerg Wunsch,
- * joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch)
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)fd.c 7.4 (Berkeley) 5/25/91
- * $FreeBSD$
- */
-
-#include "opt_fdc.h"
-#include "card.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bio.h>
-#include <sys/bus.h>
-#include <sys/conf.h>
-#include <sys/devicestat.h>
-#include <sys/disk.h>
-#include <sys/fcntl.h>
-#include <sys/fdcio.h>
-#include <sys/filio.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/module.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/syslog.h>
-
-#include <machine/bus.h>
-#include <sys/rman.h>
-
-#include <machine/clock.h>
-#include <machine/resource.h>
-#include <machine/stdarg.h>
-
-#include <isa/isavar.h>
-#include <isa/isareg.h>
-#include <isa/fdreg.h>
-#include <isa/rtc.h>
-
-enum fdc_type
-{
- FDC_NE765, FDC_ENHANCED, FDC_UNKNOWN = -1
-};
-
-enum fdc_states {
- DEVIDLE,
- FINDWORK,
- DOSEEK,
- SEEKCOMPLETE ,
- IOCOMPLETE,
- RECALCOMPLETE,
- STARTRECAL,
- RESETCTLR,
- SEEKWAIT,
- RECALWAIT,
- MOTORWAIT,
- IOTIMEDOUT,
- RESETCOMPLETE,
- PIOREAD
-};
-
-#ifdef FDC_DEBUG
-static char const * const fdstates[] = {
- "DEVIDLE",
- "FINDWORK",
- "DOSEEK",
- "SEEKCOMPLETE",
- "IOCOMPLETE",
- "RECALCOMPLETE",
- "STARTRECAL",
- "RESETCTLR",
- "SEEKWAIT",
- "RECALWAIT",
- "MOTORWAIT",
- "IOTIMEDOUT",
- "RESETCOMPLETE",
- "PIOREAD"
-};
-#endif
-
-/*
- * Per controller structure (softc).
- */
-struct fdc_data
-{
- int fdcu; /* our unit number */
- int dmachan;
- int flags;
-#define FDC_ATTACHED 0x01
-#define FDC_STAT_VALID 0x08
-#define FDC_HAS_FIFO 0x10
-#define FDC_NEEDS_RESET 0x20
-#define FDC_NODMA 0x40
-#define FDC_ISPNP 0x80
-#define FDC_ISPCMCIA 0x100
- struct fd_data *fd;
- int fdu; /* the active drive */
- enum fdc_states state;
- int retry;
- int fdout; /* mirror of the w/o digital output reg */
- u_int status[7]; /* copy of the registers */
- enum fdc_type fdct; /* chip version of FDC */
- int fdc_errs; /* number of logged errors */
- int dma_overruns; /* number of DMA overruns */
- struct bio_queue_head head;
- struct bio *bp; /* active buffer */
- struct resource *res_ioport, *res_ctl, *res_irq, *res_drq;
- int rid_ioport, rid_ctl, rid_irq, rid_drq;
- int port_off;
- bus_space_tag_t portt;
- bus_space_handle_t porth;
- bus_space_tag_t ctlt;
- bus_space_handle_t ctlh;
- void *fdc_intr;
- struct device *fdc_dev;
- void (*fdctl_wr)(struct fdc_data *fdc, u_int8_t v);
-};
-
-#define FDBIO_FORMAT BIO_CMD2
-
-typedef int fdu_t;
-typedef int fdcu_t;
-typedef int fdsu_t;
-typedef struct fd_data *fd_p;
-typedef struct fdc_data *fdc_p;
-typedef enum fdc_type fdc_t;
-
-#define FDUNIT(s) (((s) >> 6) & 3)
-#define FDNUMTOUNIT(n) (((n) & 3) << 6)
-#define FDTYPE(s) ((s) & 0x3f)
-
-/*
- * fdc maintains a set (1!) of ivars per child of each controller.
- */
-enum fdc_device_ivars {
- FDC_IVAR_FDUNIT,
-};
-
-/*
- * Simple access macros for the ivars.
- */
-#define FDC_ACCESSOR(A, B, T) \
-static __inline T fdc_get_ ## A(device_t dev) \
-{ \
- uintptr_t v; \
- BUS_READ_IVAR(device_get_parent(dev), dev, FDC_IVAR_ ## B, &v); \
- return (T) v; \
-}
-FDC_ACCESSOR(fdunit, FDUNIT, int)
-
-/* configuration flags for fdc */
-#define FDC_NO_FIFO (1 << 2) /* do not enable FIFO */
-
-/* error returns for fd_cmd() */
-#define FD_FAILED -1
-#define FD_NOT_VALID -2
-#define FDC_ERRMAX 100 /* do not log more */
-/*
- * Stop retrying after this many DMA overruns. Since each retry takes
- * one revolution, with 300 rpm., 25 retries take approximately 5
- * seconds which the read attempt will block in case the DMA overrun
- * is persistent.
- */
-#define FDC_DMAOV_MAX 25
-
-/*
- * Timeout value for the PIO loops to wait until the FDC main status
- * register matches our expectations (request for master, direction
- * bit). This is supposed to be a number of microseconds, although
- * timing might actually not be very accurate.
- *
- * Timeouts of 100 msec are believed to be required for some broken
- * (old) hardware.
- */
-#define FDSTS_TIMEOUT 100000
-
-/*
- * Number of subdevices that can be used for different density types.
- * By now, the lower 6 bit of the minor number are reserved for this,
- * allowing for up to 64 subdevices, but we only use 16 out of this.
- * Density #0 is used for automatic format detection, the other
- * densities are available as programmable densities (for assignment
- * by fdcontrol(8)).
- * The upper 2 bits of the minor number are reserved for the subunit
- * (drive #) per controller.
- */
-#define NUMDENS 16
-
-#define FDBIO_RDSECTID BIO_CMD1
-
-/*
- * List of native drive densities. Order must match enum fd_drivetype
- * in <sys/fdcio.h>. Upon attaching the drive, each of the
- * programmable subdevices is initialized with the native density
- * definition.
- */
-static struct fd_type fd_native_types[] =
-{
-{ 0 }, /* FDT_NONE */
-{ 9,2,0xFF,0x2A,40, 720,FDC_250KBPS,2,0x50,1,0,FL_MFM }, /* FDT_360K */
-{ 15,2,0xFF,0x1B,80,2400,FDC_500KBPS,2,0x54,1,0,FL_MFM }, /* FDT_12M */
-{ 9,2,0xFF,0x20,80,1440,FDC_250KBPS,2,0x50,1,0,FL_MFM }, /* FDT_720K */
-{ 18,2,0xFF,0x1B,80,2880,FDC_500KBPS,2,0x6C,1,0,FL_MFM }, /* FDT_144M */
-#if 0 /* we currently don't handle 2.88 MB */
-{ 36,2,0xFF,0x1B,80,5760,FDC_1MBPS, 2,0x4C,1,1,FL_MFM|FL_PERPND } /*FDT_288M*/
-#else
-{ 18,2,0xFF,0x1B,80,2880,FDC_500KBPS,2,0x6C,1,0,FL_MFM }, /* FDT_144M */
-#endif
-};
-
-/*
- * 360 KB 5.25" and 720 KB 3.5" drives don't have automatic density
- * selection, they just start out with their native density (or lose).
- * So 1.2 MB 5.25", 1.44 MB 3.5", and 2.88 MB 3.5" drives have their
- * respective lists of densities to search for.
- */
-static struct fd_type fd_searchlist_12m[] = {
-{ 15,2,0xFF,0x1B,80,2400,FDC_500KBPS,2,0x54,1,0,FL_MFM }, /* 1.2M */
-{ 9,2,0xFF,0x23,40, 720,FDC_300KBPS,2,0x50,1,0,FL_MFM|FL_2STEP }, /* 360K */
-{ 9,2,0xFF,0x20,80,1440,FDC_300KBPS,2,0x50,1,0,FL_MFM }, /* 720K */
-};
-
-static struct fd_type fd_searchlist_144m[] = {
-{ 18,2,0xFF,0x1B,80,2880,FDC_500KBPS,2,0x6C,1,0,FL_MFM }, /* 1.44M */
-{ 9,2,0xFF,0x20,80,1440,FDC_250KBPS,2,0x50,1,0,FL_MFM }, /* 720K */
-};
-
-/* We search for 1.44M first since this is the most common case. */
-static struct fd_type fd_searchlist_288m[] = {
-{ 18,2,0xFF,0x1B,80,2880,FDC_500KBPS,2,0x6C,1,0,FL_MFM }, /* 1.44M */
-#if 0
-{ 36,2,0xFF,0x1B,80,5760,FDC_1MBPS, 2,0x4C,1,1,FL_MFM|FL_PERPND } /* 2.88M */
-#endif
-{ 9,2,0xFF,0x20,80,1440,FDC_250KBPS,2,0x50,1,0,FL_MFM }, /* 720K */
-};
-
-#define MAX_SEC_SIZE (128 << 3)
-#define MAX_CYLINDER 85 /* some people really stress their drives
- * up to cyl 82 */
-#define MAX_HEAD 1
-
-static devclass_t fdc_devclass;
-
-/*
- * Per drive structure (softc).
- */
-struct fd_data {
- struct fdc_data *fdc; /* pointer to controller structure */
- int fdsu; /* this units number on this controller */
- enum fd_drivetype type; /* drive type */
- struct fd_type *ft; /* pointer to current type descriptor */
- struct fd_type fts[NUMDENS]; /* type descriptors */
- int flags;
-#define FD_OPEN 0x01 /* it's open */
-#define FD_NONBLOCK 0x02 /* O_NONBLOCK set */
-#define FD_ACTIVE 0x04 /* it's active */
-#define FD_MOTOR 0x08 /* motor should be on */
-#define FD_MOTOR_WAIT 0x10 /* motor coming up */
-#define FD_UA 0x20 /* force unit attention */
- int skip;
- int hddrv;
-#define FD_NO_TRACK -2
- int track; /* where we think the head is */
- int options; /* user configurable options, see fdcio.h */
- struct callout_handle toffhandle;
- struct callout_handle tohandle;
- struct devstat *device_stats;
- eventhandler_tag clonetag;
- dev_t masterdev;
- dev_t clonedevs[NUMDENS - 1];
- device_t dev;
- fdu_t fdu;
-};
-
-struct fdc_ivars {
- int fdunit;
-};
-static devclass_t fd_devclass;
-
-/* configuration flags for fd */
-#define FD_TYPEMASK 0x0f /* drive type, matches enum
- * fd_drivetype; on i386 machines, if
- * given as 0, use RTC type for fd0
- * and fd1 */
-#define FD_DTYPE(flags) ((flags) & FD_TYPEMASK)
-#define FD_NO_CHLINE 0x10 /* drive does not support changeline
- * aka. unit attention */
-#define FD_NO_PROBE 0x20 /* don't probe drive (seek test), just
- * assume it is there */
-
-/*
- * Throughout this file the following conventions will be used:
- *
- * fd is a pointer to the fd_data struct for the drive in question
- * fdc is a pointer to the fdc_data struct for the controller
- * fdu is the floppy drive unit number
- * fdcu is the floppy controller unit number
- * fdsu is the floppy drive unit number on that controller. (sub-unit)
- */
-
-/*
- * Function declarations, same (chaotic) order as they appear in the
- * file. Re-ordering is too late now, it would only obfuscate the
- * diffs against old and offspring versions (like the PC98 one).
- *
- * Anyone adding functions here, please keep this sequence the same
- * as below -- makes locating a particular function in the body much
- * easier.
- */
-static void fdout_wr(fdc_p, u_int8_t);
-static u_int8_t fdsts_rd(fdc_p);
-static void fddata_wr(fdc_p, u_int8_t);
-static u_int8_t fddata_rd(fdc_p);
-static void fdctl_wr_isa(fdc_p, u_int8_t);
-#if NCARD > 0
-static void fdctl_wr_pcmcia(fdc_p, u_int8_t);
-#endif
-#if 0
-static u_int8_t fdin_rd(fdc_p);
-#endif
-static int fdc_err(struct fdc_data *, const char *);
-static int fd_cmd(struct fdc_data *, int, ...);
-static int enable_fifo(fdc_p fdc);
-static int fd_sense_drive_status(fdc_p, int *);
-static int fd_sense_int(fdc_p, int *, int *);
-static int fd_read_status(fdc_p);
-static int fdc_alloc_resources(struct fdc_data *);
-static void fdc_release_resources(struct fdc_data *);
-static int fdc_read_ivar(device_t, device_t, int, uintptr_t *);
-static int fdc_probe(device_t);
-#if NCARD > 0
-static int fdc_pccard_probe(device_t);
-#endif
-static int fdc_detach(device_t dev);
-static void fdc_add_child(device_t, const char *, int);
-static int fdc_attach(device_t);
-static int fdc_print_child(device_t, device_t);
-static void fd_clone (void *, char *, int, dev_t *);
-static int fd_probe(device_t);
-static int fd_attach(device_t);
-static int fd_detach(device_t);
-static void set_motor(struct fdc_data *, int, int);
-# define TURNON 1
-# define TURNOFF 0
-static timeout_t fd_turnoff;
-static timeout_t fd_motor_on;
-static void fd_turnon(struct fd_data *);
-static void fdc_reset(fdc_p);
-static int fd_in(struct fdc_data *, int *);
-static int out_fdc(struct fdc_data *, int);
-/*
- * The open function is named Fdopen() to avoid confusion with fdopen()
- * in fd(4). The difference is now only meaningful for debuggers.
- */
-static d_open_t Fdopen;
-static d_close_t fdclose;
-static d_strategy_t fdstrategy;
-static void fdstart(struct fdc_data *);
-static timeout_t fd_iotimeout;
-static timeout_t fd_pseudointr;
-static driver_intr_t fdc_intr;
-static int fdcpio(fdc_p, long, caddr_t, u_int);
-static int fdautoselect(dev_t);
-static int fdstate(struct fdc_data *);
-static int retrier(struct fdc_data *);
-static void fdbiodone(struct bio *);
-static int fdmisccmd(dev_t, u_int, void *);
-static d_ioctl_t fdioctl;
-
-static int fifo_threshold = 8; /* XXX: should be accessible via sysctl */
-
-#ifdef FDC_DEBUG
-/* CAUTION: fd_debug causes huge amounts of logging output */
-static int volatile fd_debug = 0;
-#define TRACE0(arg) do { if (fd_debug) printf(arg); } while (0)
-#define TRACE1(arg1, arg2) do { if (fd_debug) printf(arg1, arg2); } while (0)
-#else /* FDC_DEBUG */
-#define TRACE0(arg) do { } while (0)
-#define TRACE1(arg1, arg2) do { } while (0)
-#endif /* FDC_DEBUG */
-
-/*
- * Bus space handling (access to low-level IO).
- */
-static void
-fdout_wr(fdc_p fdc, u_int8_t v)
-{
- bus_space_write_1(fdc->portt, fdc->porth, FDOUT+fdc->port_off, v);
-}
-
-static u_int8_t
-fdsts_rd(fdc_p fdc)
-{
- return bus_space_read_1(fdc->portt, fdc->porth, FDSTS+fdc->port_off);
-}
-
-static void
-fddata_wr(fdc_p fdc, u_int8_t v)
-{
- bus_space_write_1(fdc->portt, fdc->porth, FDDATA+fdc->port_off, v);
-}
-
-static u_int8_t
-fddata_rd(fdc_p fdc)
-{
- return bus_space_read_1(fdc->portt, fdc->porth, FDDATA+fdc->port_off);
-}
-
-static void
-fdctl_wr_isa(fdc_p fdc, u_int8_t v)
-{
- bus_space_write_1(fdc->ctlt, fdc->ctlh, 0, v);
-}
-
-#if NCARD > 0
-static void
-fdctl_wr_pcmcia(fdc_p fdc, u_int8_t v)
-{
- bus_space_write_1(fdc->portt, fdc->porth, FDCTL+fdc->port_off, v);
-}
-#endif
-
-static u_int8_t
-fdin_rd(fdc_p fdc)
-{
- return bus_space_read_1(fdc->portt, fdc->porth, FDIN);
-}
-
-#define CDEV_MAJOR 9
-static struct cdevsw fd_cdevsw = {
- .d_open = Fdopen,
- .d_close = fdclose,
- .d_read = physread,
- .d_write = physwrite,
- .d_ioctl = fdioctl,
- .d_strategy = fdstrategy,
- .d_name = "fd",
- .d_maj = CDEV_MAJOR,
- .d_flags = D_DISK,
-};
-
-/*
- * Auxiliary functions. Well, some only. Others are scattered
- * throughout the entire file.
- */
-static int
-fdc_err(struct fdc_data *fdc, const char *s)
-{
- fdc->fdc_errs++;
- if (s) {
- if (fdc->fdc_errs < FDC_ERRMAX)
- device_printf(fdc->fdc_dev, "%s", s);
- else if (fdc->fdc_errs == FDC_ERRMAX)
- device_printf(fdc->fdc_dev, "too many errors, not "
- "logging any more\n");
- }
-
- return FD_FAILED;
-}
-
-/*
- * fd_cmd: Send a command to the chip. Takes a varargs with this structure:
- * Unit number,
- * # of output bytes, output bytes as ints ...,
- * # of input bytes, input bytes as ints ...
- */
-static int
-fd_cmd(struct fdc_data *fdc, int n_out, ...)
-{
- u_char cmd;
- int n_in;
- int n;
- va_list ap;
-
- va_start(ap, n_out);
- cmd = (u_char)(va_arg(ap, int));
- va_end(ap);
- va_start(ap, n_out);
- for (n = 0; n < n_out; n++)
- {
- if (out_fdc(fdc, va_arg(ap, int)) < 0)
- {
- char msg[50];
- snprintf(msg, sizeof(msg),
- "cmd %x failed at out byte %d of %d\n",
- cmd, n + 1, n_out);
- return fdc_err(fdc, msg);
- }
- }
- n_in = va_arg(ap, int);
- for (n = 0; n < n_in; n++)
- {
- int *ptr = va_arg(ap, int *);
- if (fd_in(fdc, ptr) < 0)
- {
- char msg[50];
- snprintf(msg, sizeof(msg),
- "cmd %02x failed at in byte %d of %d\n",
- cmd, n + 1, n_in);
- return fdc_err(fdc, msg);
- }
- }
-
- return 0;
-}
-
-static int
-enable_fifo(fdc_p fdc)
-{
- int i, j;
-
- if ((fdc->flags & FDC_HAS_FIFO) == 0) {
-
- /*
- * Cannot use fd_cmd the normal way here, since
- * this might be an invalid command. Thus we send the
- * first byte, and check for an early turn of data directon.
- */
-
- if (out_fdc(fdc, I8207X_CONFIGURE) < 0)
- return fdc_err(fdc, "Enable FIFO failed\n");
-
- /* If command is invalid, return */
- j = FDSTS_TIMEOUT;
- while ((i = fdsts_rd(fdc) & (NE7_DIO | NE7_RQM))
- != NE7_RQM && j-- > 0) {
- if (i == (NE7_DIO | NE7_RQM)) {
- fdc_reset(fdc);
- return FD_FAILED;
- }
- DELAY(1);
- }
- if (j<0 ||
- fd_cmd(fdc, 3,
- 0, (fifo_threshold - 1) & 0xf, 0, 0) < 0) {
- fdc_reset(fdc);
- return fdc_err(fdc, "Enable FIFO failed\n");
- }
- fdc->flags |= FDC_HAS_FIFO;
- return 0;
- }
- if (fd_cmd(fdc, 4,
- I8207X_CONFIGURE, 0, (fifo_threshold - 1) & 0xf, 0, 0) < 0)
- return fdc_err(fdc, "Re-enable FIFO failed\n");
- return 0;
-}
-
-static int
-fd_sense_drive_status(fdc_p fdc, int *st3p)
-{
- int st3;
-
- if (fd_cmd(fdc, 2, NE7CMD_SENSED, fdc->fdu, 1, &st3))
- {
- return fdc_err(fdc, "Sense Drive Status failed\n");
- }
- if (st3p)
- *st3p = st3;
-
- return 0;
-}
-
-static int
-fd_sense_int(fdc_p fdc, int *st0p, int *cylp)
-{
- int cyl, st0, ret;
-
- ret = fd_cmd(fdc, 1, NE7CMD_SENSEI, 1, &st0);
- if (ret) {
- (void)fdc_err(fdc,
- "sense intr err reading stat reg 0\n");
- return ret;
- }
-
- if (st0p)
- *st0p = st0;
-
- if ((st0 & NE7_ST0_IC) == NE7_ST0_IC_IV) {
- /*
- * There doesn't seem to have been an interrupt.
- */
- return FD_NOT_VALID;
- }
-
- if (fd_in(fdc, &cyl) < 0) {
- return fdc_err(fdc, "can't get cyl num\n");
- }
-
- if (cylp)
- *cylp = cyl;
-
- return 0;
-}
-
-
-static int
-fd_read_status(fdc_p fdc)
-{
- int i, ret;
-
- for (i = ret = 0; i < 7; i++) {
- /*
- * XXX types are poorly chosen. Only bytes can be read
- * from the hardware, but fdc->status[] wants u_ints and
- * fd_in() gives ints.
- */
- int status;
-
- ret = fd_in(fdc, &status);
- fdc->status[i] = status;
- if (ret != 0)
- break;
- }
-
- if (ret == 0)
- fdc->flags |= FDC_STAT_VALID;
- else
- fdc->flags &= ~FDC_STAT_VALID;
-
- return ret;
-}
-
-static int
-fdc_alloc_resources(struct fdc_data *fdc)
-{
- device_t dev;
- int ispnp, ispcmcia, nports;
-
- dev = fdc->fdc_dev;
- ispnp = (fdc->flags & FDC_ISPNP) != 0;
- ispcmcia = (fdc->flags & FDC_ISPCMCIA) != 0;
- fdc->rid_ioport = fdc->rid_irq = fdc->rid_drq = 0;
- fdc->res_ioport = fdc->res_irq = fdc->res_drq = 0;
-
- /*
- * On standard ISA, we don't just use an 8 port range
- * (e.g. 0x3f0-0x3f7) since that covers an IDE control
- * register at 0x3f6.
- *
- * Isn't PC hardware wonderful.
- *
- * The Y-E Data PCMCIA FDC doesn't have this problem, it
- * uses the register with offset 6 for pseudo-DMA, and the
- * one with offset 7 as control register.
- */
- nports = ispcmcia ? 8 : (ispnp ? 1 : 6);
- fdc->res_ioport = bus_alloc_resource(dev, SYS_RES_IOPORT,
- &fdc->rid_ioport, 0ul, ~0ul,
- nports, RF_ACTIVE);
- if (fdc->res_ioport == 0) {
- device_printf(dev, "cannot reserve I/O port range (%d ports)\n",
- nports);
- return ENXIO;
- }
- fdc->portt = rman_get_bustag(fdc->res_ioport);
- fdc->porth = rman_get_bushandle(fdc->res_ioport);
-
- if (!ispcmcia) {
- /*
- * Some BIOSen report the device at 0x3f2-0x3f5,0x3f7
- * and some at 0x3f0-0x3f5,0x3f7. We detect the former
- * by checking the size and adjust the port address
- * accordingly.
- */
- if (bus_get_resource_count(dev, SYS_RES_IOPORT, 0) == 4)
- fdc->port_off = -2;
-
- /*
- * Register the control port range as rid 1 if it
- * isn't there already. Most PnP BIOSen will have
- * already done this but non-PnP configurations don't.
- *
- * And some (!!) report 0x3f2-0x3f5 and completely
- * leave out the control register! It seems that some
- * non-antique controller chips have a different
- * method of programming the transfer speed which
- * doesn't require the control register, but it's
- * mighty bogus as the chip still responds to the
- * address for the control register.
- */
- if (bus_get_resource_count(dev, SYS_RES_IOPORT, 1) == 0) {
- u_long ctlstart;
-
- /* Find the control port, usually 0x3f7 */
- ctlstart = rman_get_start(fdc->res_ioport) +
- fdc->port_off + 7;
-
- bus_set_resource(dev, SYS_RES_IOPORT, 1, ctlstart, 1);
- }
-
- /*
- * Now (finally!) allocate the control port.
- */
- fdc->rid_ctl = 1;
- fdc->res_ctl = bus_alloc_resource(dev, SYS_RES_IOPORT,
- &fdc->rid_ctl,
- 0ul, ~0ul, 1, RF_ACTIVE);
- if (fdc->res_ctl == 0) {
- device_printf(dev,
- "cannot reserve control I/O port range (control port)\n");
- return ENXIO;
- }
- fdc->ctlt = rman_get_bustag(fdc->res_ctl);
- fdc->ctlh = rman_get_bushandle(fdc->res_ctl);
- }
-
- fdc->res_irq = bus_alloc_resource(dev, SYS_RES_IRQ,
- &fdc->rid_irq, 0ul, ~0ul, 1,
- RF_ACTIVE);
- if (fdc->res_irq == 0) {
- device_printf(dev, "cannot reserve interrupt line\n");
- return ENXIO;
- }
-
- if ((fdc->flags & FDC_NODMA) == 0) {
- fdc->res_drq = bus_alloc_resource(dev, SYS_RES_DRQ,
- &fdc->rid_drq, 0ul, ~0ul, 1,
- RF_ACTIVE);
- if (fdc->res_drq == 0) {
- device_printf(dev, "cannot reserve DMA request line\n");
- return ENXIO;
- }
- fdc->dmachan = fdc->res_drq->r_start;
- }
-
- return 0;
-}
-
-static void
-fdc_release_resources(struct fdc_data *fdc)
-{
- device_t dev;
-
- dev = fdc->fdc_dev;
- if (fdc->res_irq != 0) {
- bus_deactivate_resource(dev, SYS_RES_IRQ, fdc->rid_irq,
- fdc->res_irq);
- bus_release_resource(dev, SYS_RES_IRQ, fdc->rid_irq,
- fdc->res_irq);
- }
- if (fdc->res_ctl != 0) {
- bus_deactivate_resource(dev, SYS_RES_IOPORT, fdc->rid_ctl,
- fdc->res_ctl);
- bus_release_resource(dev, SYS_RES_IOPORT, fdc->rid_ctl,
- fdc->res_ctl);
- }
- if (fdc->res_ioport != 0) {
- bus_deactivate_resource(dev, SYS_RES_IOPORT, fdc->rid_ioport,
- fdc->res_ioport);
- bus_release_resource(dev, SYS_RES_IOPORT, fdc->rid_ioport,
- fdc->res_ioport);
- }
- if (fdc->res_drq != 0) {
- bus_deactivate_resource(dev, SYS_RES_DRQ, fdc->rid_drq,
- fdc->res_drq);
- bus_release_resource(dev, SYS_RES_DRQ, fdc->rid_drq,
- fdc->res_drq);
- }
-}
-
-/*
- * Configuration/initialization stuff, per controller.
- */
-
-static struct isa_pnp_id fdc_ids[] = {
- {0x0007d041, "PC standard floppy disk controller"}, /* PNP0700 */
- {0x0107d041, "Standard floppy controller supporting MS Device Bay Spec"}, /* PNP0701 */
- {0}
-};
-
-static int
-fdc_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
-{
- struct fdc_ivars *ivars = device_get_ivars(child);
-
- switch (which) {
- case FDC_IVAR_FDUNIT:
- *result = ivars->fdunit;
- break;
- default:
- return ENOENT;
- }
- return 0;
-}
-
-static int
-fdc_probe(device_t dev)
-{
- int error, ic_type;
- struct fdc_data *fdc;
-
- fdc = device_get_softc(dev);
- bzero(fdc, sizeof *fdc);
- fdc->fdc_dev = dev;
- fdc->fdctl_wr = fdctl_wr_isa;
-
- /* Check pnp ids */
- error = ISA_PNP_PROBE(device_get_parent(dev), dev, fdc_ids);
- if (error == ENXIO)
- return ENXIO;
- if (error == 0)
- fdc->flags |= FDC_ISPNP;
-
- /* Attempt to allocate our resources for the duration of the probe */
- error = fdc_alloc_resources(fdc);
- if (error)
- goto out;
-
- /* First - lets reset the floppy controller */
- fdout_wr(fdc, 0);
- DELAY(100);
- fdout_wr(fdc, FDO_FRST);
-
- /* see if it can handle a command */
- if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(3, 240),
- NE7_SPEC_2(2, 0), 0)) {
- error = ENXIO;
- goto out;
- }
-
- if (fd_cmd(fdc, 1, NE7CMD_VERSION, 1, &ic_type) == 0) {
- ic_type = (u_char)ic_type;
- switch (ic_type) {
- case 0x80:
- device_set_desc(dev, "NEC 765 or clone");
- fdc->fdct = FDC_NE765;
- break;
- case 0x81: /* not mentioned in any hardware doc */
- case 0x90:
- device_set_desc(dev,
- "Enhanced floppy controller (i82077, NE72065 or clone)");
- fdc->fdct = FDC_ENHANCED;
- break;
- default:
- device_set_desc(dev, "Generic floppy controller");
- fdc->fdct = FDC_UNKNOWN;
- break;
- }
- }
-
-out:
- fdc_release_resources(fdc);
- return (error);
-}
-
-#if NCARD > 0
-
-static int
-fdc_pccard_probe(device_t dev)
-{
- int error;
- struct fdc_data *fdc;
-
- fdc = device_get_softc(dev);
- bzero(fdc, sizeof *fdc);
- fdc->fdc_dev = dev;
- fdc->fdctl_wr = fdctl_wr_pcmcia;
-
- fdc->flags |= FDC_ISPCMCIA | FDC_NODMA;
-
- /* Attempt to allocate our resources for the duration of the probe */
- error = fdc_alloc_resources(fdc);
- if (error)
- goto out;
-
- /* First - lets reset the floppy controller */
- fdout_wr(fdc, 0);
- DELAY(100);
- fdout_wr(fdc, FDO_FRST);
-
- /* see if it can handle a command */
- if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(3, 240),
- NE7_SPEC_2(2, 0), 0)) {
- error = ENXIO;
- goto out;
- }
-
- device_set_desc(dev, "Y-E Data PCMCIA floppy");
- fdc->fdct = FDC_NE765;
-
-out:
- fdc_release_resources(fdc);
- return (error);
-}
-
-#endif /* NCARD > 0 */
-
-static int
-fdc_detach(device_t dev)
-{
- struct fdc_data *fdc;
- int error;
-
- fdc = device_get_softc(dev);
-
- /* have our children detached first */
- if ((error = bus_generic_detach(dev)))
- return (error);
-
- /* reset controller, turn motor off */
- fdout_wr(fdc, 0);
-
- if ((fdc->flags & FDC_NODMA) == 0)
- isa_dma_release(fdc->dmachan);
-
- if ((fdc->flags & FDC_ATTACHED) == 0) {
- device_printf(dev, "already unloaded\n");
- return (0);
- }
- fdc->flags &= ~FDC_ATTACHED;
-
- BUS_TEARDOWN_INTR(device_get_parent(dev), dev, fdc->res_irq,
- fdc->fdc_intr);
- fdc_release_resources(fdc);
- device_printf(dev, "unload\n");
- return (0);
-}
-
-/*
- * Add a child device to the fdc controller. It will then be probed etc.
- */
-static void
-fdc_add_child(device_t dev, const char *name, int unit)
-{
- int disabled, flags;
- struct fdc_ivars *ivar;
- device_t child;
-
- ivar = malloc(sizeof *ivar, M_DEVBUF /* XXX */, M_NOWAIT | M_ZERO);
- if (ivar == NULL)
- return;
- if (resource_int_value(name, unit, "drive", &ivar->fdunit) != 0)
- ivar->fdunit = 0;
- child = device_add_child(dev, name, unit);
- if (child == NULL) {
- free(ivar, M_DEVBUF);
- return;
- }
- device_set_ivars(child, ivar);
- if (resource_int_value(name, unit, "flags", &flags) == 0)
- device_set_flags(child, flags);
- if (resource_int_value(name, unit, "disabled", &disabled) == 0
- && disabled != 0)
- device_disable(child);
-}
-
-static int
-fdc_attach(device_t dev)
-{
- struct fdc_data *fdc;
- const char *name, *dname;
- int i, error, dunit;
-
- fdc = device_get_softc(dev);
- error = fdc_alloc_resources(fdc);
- if (error) {
- device_printf(dev, "cannot re-acquire resources\n");
- return error;
- }
- error = BUS_SETUP_INTR(device_get_parent(dev), dev, fdc->res_irq,
- INTR_TYPE_BIO | INTR_ENTROPY, fdc_intr, fdc,
- &fdc->fdc_intr);
- if (error) {
- device_printf(dev, "cannot setup interrupt\n");
- return error;
- }
- fdc->fdcu = device_get_unit(dev);
- fdc->flags |= FDC_ATTACHED | FDC_NEEDS_RESET;
-
- if ((fdc->flags & FDC_NODMA) == 0) {
- /*
- * Acquire the DMA channel forever, the driver will do
- * the rest
- * XXX should integrate with rman
- */
- isa_dma_acquire(fdc->dmachan);
- isa_dmainit(fdc->dmachan, MAX_SEC_SIZE);
- }
- fdc->state = DEVIDLE;
-
- /* reset controller, turn motor off, clear fdout mirror reg */
- fdout_wr(fdc, fdc->fdout = 0);
- bioq_init(&fdc->head);
-
- /*
- * Probe and attach any children. We should probably detect
- * devices from the BIOS unless overridden.
- */
- name = device_get_nameunit(dev);
- i = 0;
- while ((resource_find_match(&i, &dname, &dunit, "at", name)) == 0)
- fdc_add_child(dev, dname, dunit);
-
- if ((error = bus_generic_attach(dev)) != 0)
- return (error);
-
- return (0);
-}
-
-static int
-fdc_print_child(device_t me, device_t child)
-{
- int retval = 0, flags;
-
- retval += bus_print_child_header(me, child);
- retval += printf(" on %s drive %d", device_get_nameunit(me),
- fdc_get_fdunit(child));
- if ((flags = device_get_flags(me)) != 0)
- retval += printf(" flags %#x", flags);
- retval += printf("\n");
-
- return (retval);
-}
-
-static device_method_t fdc_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, fdc_probe),
- DEVMETHOD(device_attach, fdc_attach),
- DEVMETHOD(device_detach, fdc_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /* Bus interface */
- DEVMETHOD(bus_print_child, fdc_print_child),
- DEVMETHOD(bus_read_ivar, fdc_read_ivar),
- /* Our children never use any other bus interface methods. */
-
- { 0, 0 }
-};
-
-static driver_t fdc_driver = {
- "fdc",
- fdc_methods,
- sizeof(struct fdc_data)
-};
-
-DRIVER_MODULE(fdc, isa, fdc_driver, fdc_devclass, 0, 0);
-DRIVER_MODULE(fdc, acpi, fdc_driver, fdc_devclass, 0, 0);
-
-#if NCARD > 0
-
-static device_method_t fdc_pccard_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, fdc_pccard_probe),
- DEVMETHOD(device_attach, fdc_attach),
- DEVMETHOD(device_detach, fdc_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /* Bus interface */
- DEVMETHOD(bus_print_child, fdc_print_child),
- DEVMETHOD(bus_read_ivar, fdc_read_ivar),
- /* Our children never use any other bus interface methods. */
-
- { 0, 0 }
-};
-
-static driver_t fdc_pccard_driver = {
- "fdc",
- fdc_pccard_methods,
- sizeof(struct fdc_data)
-};
-
-DRIVER_MODULE(fdc, pccard, fdc_pccard_driver, fdc_devclass, 0, 0);
-
-#endif /* NCARD > 0 */
-
-/*
- * Create a clone device upon request by devfs.
- */
-static void
-fd_clone(void *arg, char *name, int namelen, dev_t *dev)
-{
- struct fd_data *fd;
- int i, u;
- char *n;
- size_t l;
-
- fd = (struct fd_data *)arg;
- if (*dev != NODEV)
- return;
- if (dev_stdclone(name, &n, "fd", &u) != 2)
- return;
- if (u != fd->fdu)
- /* unit # mismatch */
- return;
- l = strlen(n);
- if (l == 1 && *n >= 'a' && *n <= 'h') {
- /*
- * Trailing letters a through h denote
- * pseudo-partitions. We don't support true
- * (UFS-style) partitions, so we just implement them
- * as symlinks if someone asks us nicely.
- */
- *dev = make_dev_alias(fd->masterdev, name);
- return;
- }
- if (l >= 2 && l <= 5 && *n == '.') {
- /*
- * Trailing numbers, preceded by a dot, denote
- * subdevices for different densities. Historically,
- * they have been named by density (like fd0.1440),
- * but we allow arbitrary numbers between 1 and 4
- * digits, so fd0.1 through fd0.15 are possible as
- * well.
- */
- for (i = 1; i < l; i++)
- if (n[i] < '0' || n[i] > '9')
- return;
- for (i = 0; i < NUMDENS - 1; i++)
- if (fd->clonedevs[i] == NODEV) {
- *dev = make_dev(&fd_cdevsw,
- FDNUMTOUNIT(u) + i + 1,
- UID_ROOT, GID_OPERATOR, 0640,
- name);
- fd->clonedevs[i] = *dev;
- return;
- }
- }
-}
-
-/*
- * Configuration/initialization, per drive.
- */
-static int
-fd_probe(device_t dev)
-{
- int i;
- u_int st0, st3;
- struct fd_data *fd;
- struct fdc_data *fdc;
- fdsu_t fdsu;
- int flags;
-
- fdsu = *(int *)device_get_ivars(dev); /* xxx cheat a bit... */
- fd = device_get_softc(dev);
- fdc = device_get_softc(device_get_parent(dev));
- flags = device_get_flags(dev);
-
- bzero(fd, sizeof *fd);
- fd->dev = dev;
- fd->fdc = fdc;
- fd->fdsu = fdsu;
- fd->fdu = device_get_unit(dev);
- fd->flags = FD_UA; /* make sure fdautoselect() will be called */
-
- fd->type = FD_DTYPE(flags);
-/*
- * XXX I think using __i386__ is wrong here since we actually want to probe
- * for the machine type, not the CPU type (so non-PC arch's like the PC98 will
- * fail the probe). However, for whatever reason, testing for _MACHINE_ARCH
- * == i386 breaks the test on FreeBSD/Alpha.
- */
-#ifdef __i386__
- if (fd->type == FDT_NONE && (fd->fdu == 0 || fd->fdu == 1)) {
- /* Look up what the BIOS thinks we have. */
- if (fd->fdu == 0) {
- if ((fdc->flags & FDC_ISPCMCIA))
- /*
- * Somewhat special. No need to force the
- * user to set device flags, since the Y-E
- * Data PCMCIA floppy is always a 1.44 MB
- * device.
- */
- fd->type = FDT_144M;
- else
- fd->type = (rtcin(RTC_FDISKETTE) & 0xf0) >> 4;
- } else {
- fd->type = rtcin(RTC_FDISKETTE) & 0x0f;
- }
- if (fd->type == FDT_288M_1)
- fd->type = FDT_288M;
- }
-#endif /* __i386__ */
- /* is there a unit? */
- if (fd->type == FDT_NONE)
- return (ENXIO);
-
- /* select it */
- set_motor(fdc, fdsu, TURNON);
- fdc_reset(fdc); /* XXX reset, then unreset, etc. */
- DELAY(1000000); /* 1 sec */
-
- /* XXX This doesn't work before the first set_motor() */
- if ((fdc->flags & FDC_HAS_FIFO) == 0 &&
- fdc->fdct == FDC_ENHANCED &&
- (device_get_flags(fdc->fdc_dev) & FDC_NO_FIFO) == 0 &&
- enable_fifo(fdc) == 0) {
- device_printf(device_get_parent(dev),
- "FIFO enabled, %d bytes threshold\n", fifo_threshold);
- }
-
- if ((flags & FD_NO_PROBE) == 0) {
- /* If we're at track 0 first seek inwards. */
- if ((fd_sense_drive_status(fdc, &st3) == 0) &&
- (st3 & NE7_ST3_T0)) {
- /* Seek some steps... */
- if (fd_cmd(fdc, 3, NE7CMD_SEEK, fdsu, 10, 0) == 0) {
- /* ...wait a moment... */
- DELAY(300000);
- /* make ctrlr happy: */
- fd_sense_int(fdc, 0, 0);
- }
- }
-
- for (i = 0; i < 2; i++) {
- /*
- * we must recalibrate twice, just in case the
- * heads have been beyond cylinder 76, since
- * most FDCs still barf when attempting to
- * recalibrate more than 77 steps
- */
- /* go back to 0: */
- if (fd_cmd(fdc, 2, NE7CMD_RECAL, fdsu, 0) == 0) {
- /* a second being enough for full stroke seek*/
- DELAY(i == 0 ? 1000000 : 300000);
-
- /* anything responding? */
- if (fd_sense_int(fdc, &st0, 0) == 0 &&
- (st0 & NE7_ST0_EC) == 0)
- break; /* already probed succesfully */
- }
- }
- }
-
- set_motor(fdc, fdsu, TURNOFF);
-
- if ((flags & FD_NO_PROBE) == 0 &&
- (st0 & NE7_ST0_EC) != 0) /* no track 0 -> no drive present */
- return (ENXIO);
-
- switch (fd->type) {
- case FDT_12M:
- device_set_desc(dev, "1200-KB 5.25\" drive");
- fd->type = FDT_12M;
- break;
- case FDT_144M:
- device_set_desc(dev, "1440-KB 3.5\" drive");
- fd->type = FDT_144M;
- break;
- case FDT_288M:
- device_set_desc(dev, "2880-KB 3.5\" drive (in 1440-KB mode)");
- fd->type = FDT_288M;
- break;
- case FDT_360K:
- device_set_desc(dev, "360-KB 5.25\" drive");
- fd->type = FDT_360K;
- break;
- case FDT_720K:
- device_set_desc(dev, "720-KB 3.5\" drive");
- fd->type = FDT_720K;
- break;
- default:
- return (ENXIO);
- }
- fd->track = FD_NO_TRACK;
- fd->fdc = fdc;
- fd->fdsu = fdsu;
- fd->options = 0;
- callout_handle_init(&fd->toffhandle);
- callout_handle_init(&fd->tohandle);
-
- /* initialize densities for subdevices */
- for (i = 0; i < NUMDENS; i++)
- memcpy(fd->fts + i, fd_native_types + fd->type,
- sizeof(struct fd_type));
- return (0);
-}
-
-static int
-fd_attach(device_t dev)
-{
- struct fd_data *fd;
- int i;
-
- fd = device_get_softc(dev);
- fd->clonetag = EVENTHANDLER_REGISTER(dev_clone, fd_clone, fd, 1000);
- fd->masterdev = make_dev(&fd_cdevsw, fd->fdu << 6,
- UID_ROOT, GID_OPERATOR, 0640, "fd%d", fd->fdu);
- for (i = 0; i < NUMDENS - 1; i++)
- fd->clonedevs[i] = NODEV;
- fd->device_stats = devstat_new_entry(device_get_name(dev),
- device_get_unit(dev), 0, DEVSTAT_NO_ORDERED_TAGS,
- DEVSTAT_TYPE_FLOPPY | DEVSTAT_TYPE_IF_OTHER,
- DEVSTAT_PRIORITY_FD);
- return (0);
-}
-
-static int
-fd_detach(device_t dev)
-{
- struct fd_data *fd;
- int i;
-
- fd = device_get_softc(dev);
- untimeout(fd_turnoff, fd, fd->toffhandle);
- devstat_remove_entry(fd->device_stats);
- destroy_dev(fd->masterdev);
- for (i = 0; i < NUMDENS - 1; i++)
- if (fd->clonedevs[i] != NODEV)
- destroy_dev(fd->clonedevs[i]);
- EVENTHANDLER_DEREGISTER(dev_clone, fd->clonetag);
-
- return (0);
-}
-
-static device_method_t fd_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, fd_probe),
- DEVMETHOD(device_attach, fd_attach),
- DEVMETHOD(device_detach, fd_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend), /* XXX */
- DEVMETHOD(device_resume, bus_generic_resume), /* XXX */
-
- { 0, 0 }
-};
-
-static driver_t fd_driver = {
- "fd",
- fd_methods,
- sizeof(struct fd_data)
-};
-
-DRIVER_MODULE(fd, fdc, fd_driver, fd_devclass, 0, 0);
-
-/*
- * More auxiliary functions.
- */
-/*
- * Motor control stuff.
- * Remember to not deselect the drive we're working on.
- */
-static void
-set_motor(struct fdc_data *fdc, int fdsu, int turnon)
-{
- int fdout;
-
- fdout = fdc->fdout;
- if (turnon) {
- fdout &= ~FDO_FDSEL;
- fdout |= (FDO_MOEN0 << fdsu) | FDO_FDMAEN | FDO_FRST | fdsu;
- } else
- fdout &= ~(FDO_MOEN0 << fdsu);
- fdc->fdout = fdout;
- fdout_wr(fdc, fdout);
- TRACE1("[0x%x->FDOUT]", fdout);
-}
-
-static void
-fd_turnoff(void *xfd)
-{
- int s;
- fd_p fd = xfd;
-
- TRACE1("[fd%d: turnoff]", fd->fdu);
-
- s = splbio();
- /*
- * Don't turn off the motor yet if the drive is active.
- *
- * If we got here, this could only mean we missed an interrupt.
- * This can e. g. happen on the Y-E Date PCMCIA floppy controller
- * after a controller reset. Just schedule a pseudo-interrupt
- * so the state machine gets re-entered.
- */
- if (fd->fdc->state != DEVIDLE && fd->fdc->fdu == fd->fdu) {
- fdc_intr(fd->fdc);
- splx(s);
- return;
- }
-
- fd->flags &= ~FD_MOTOR;
- set_motor(fd->fdc, fd->fdsu, TURNOFF);
- splx(s);
-}
-
-static void
-fd_motor_on(void *xfd)
-{
- int s;
- fd_p fd = xfd;
-
- s = splbio();
- fd->flags &= ~FD_MOTOR_WAIT;
- if((fd->fdc->fd == fd) && (fd->fdc->state == MOTORWAIT))
- {
- fdc_intr(fd->fdc);
- }
- splx(s);
-}
-
-static void
-fd_turnon(fd_p fd)
-{
- if(!(fd->flags & FD_MOTOR))
- {
- fd->flags |= (FD_MOTOR + FD_MOTOR_WAIT);
- set_motor(fd->fdc, fd->fdsu, TURNON);
- timeout(fd_motor_on, fd, hz); /* in 1 sec its ok */
- }
-}
-
-static void
-fdc_reset(fdc_p fdc)
-{
- /* Try a reset, keep motor on */
- fdout_wr(fdc, fdc->fdout & ~(FDO_FRST|FDO_FDMAEN));
- TRACE1("[0x%x->FDOUT]", fdc->fdout & ~(FDO_FRST|FDO_FDMAEN));
- DELAY(100);
- /* enable FDC, but defer interrupts a moment */
- fdout_wr(fdc, fdc->fdout & ~FDO_FDMAEN);
- TRACE1("[0x%x->FDOUT]", fdc->fdout & ~FDO_FDMAEN);
- DELAY(100);
- fdout_wr(fdc, fdc->fdout);
- TRACE1("[0x%x->FDOUT]", fdc->fdout);
-
- /* XXX after a reset, silently believe the FDC will accept commands */
- (void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
- NE7_SPEC_1(3, 240), NE7_SPEC_2(2, 0),
- 0);
- if (fdc->flags & FDC_HAS_FIFO)
- (void) enable_fifo(fdc);
-}
-
-/*
- * FDC IO functions, take care of the main status register, timeout
- * in case the desired status bits are never set.
- *
- * These PIO loops initially start out with short delays between
- * each iteration in the expectation that the required condition
- * is usually met quickly, so it can be handled immediately. After
- * about 1 ms, stepping is increased to achieve a better timing
- * accuracy in the calls to DELAY().
- */
-static int
-fd_in(struct fdc_data *fdc, int *ptr)
-{
- int i, j, step;
-
- for (j = 0, step = 1;
- (i = fdsts_rd(fdc) & (NE7_DIO|NE7_RQM)) != (NE7_DIO|NE7_RQM) &&
- j < FDSTS_TIMEOUT;
- j += step) {
- if (i == NE7_RQM)
- return (fdc_err(fdc, "ready for output in input\n"));
- if (j == 1000)
- step = 1000;
- DELAY(step);
- }
- if (j >= FDSTS_TIMEOUT)
- return (fdc_err(fdc, bootverbose? "input ready timeout\n": 0));
-#ifdef FDC_DEBUG
- i = fddata_rd(fdc);
- TRACE1("[FDDATA->0x%x]", (unsigned char)i);
- *ptr = i;
- return (0);
-#else /* !FDC_DEBUG */
- i = fddata_rd(fdc);
- if (ptr)
- *ptr = i;
- return (0);
-#endif /* FDC_DEBUG */
-}
-
-static int
-out_fdc(struct fdc_data *fdc, int x)
-{
- int i, j, step;
-
- for (j = 0, step = 1;
- (i = fdsts_rd(fdc) & (NE7_DIO|NE7_RQM)) != NE7_RQM &&
- j < FDSTS_TIMEOUT;
- j += step) {
- if (i == (NE7_DIO|NE7_RQM))
- return (fdc_err(fdc, "ready for input in output\n"));
- if (j == 1000)
- step = 1000;
- DELAY(step);
- }
- if (j >= FDSTS_TIMEOUT)
- return (fdc_err(fdc, bootverbose? "output ready timeout\n": 0));
-
- /* Send the command and return */
- fddata_wr(fdc, x);
- TRACE1("[0x%x->FDDATA]", x);
- return (0);
-}
-
-/*
- * Block device driver interface functions (interspersed with even more
- * auxiliary functions).
- */
-static int
-Fdopen(dev_t dev, int flags, int mode, struct thread *td)
-{
- fdu_t fdu = FDUNIT(minor(dev));
- int type = FDTYPE(minor(dev));
- fd_p fd;
- fdc_p fdc;
- int rv, unitattn, dflags;
-
- if ((fd = devclass_get_softc(fd_devclass, fdu)) == 0)
- return (ENXIO);
- fdc = fd->fdc;
- if ((fdc == NULL) || (fd->type == FDT_NONE))
- return (ENXIO);
- if (type > NUMDENS)
- return (ENXIO);
- dflags = device_get_flags(fd->dev);
- /*
- * This is a bit bogus. It's still possible that e. g. a
- * descriptor gets inherited to a child, but then it's at
- * least for the same subdevice. By checking FD_OPEN here, we
- * can ensure that a device isn't attempted to be opened with
- * different densities at the same time where the second open
- * could clobber the settings from the first one.
- */
- if (fd->flags & FD_OPEN)
- return (EBUSY);
-
- if (type == 0) {
- if (flags & FNONBLOCK) {
- /*
- * Unfortunately, physio(9) discards its ioflag
- * argument, thus preventing us from seeing the
- * IO_NDELAY bit. So we need to keep track
- * ourselves.
- */
- fd->flags |= FD_NONBLOCK;
- fd->ft = 0;
- } else {
- /*
- * Figure out a unit attention condition.
- *
- * If UA has been forced, proceed.
- *
- * If motor is off, turn it on for a moment
- * and select our drive, in order to read the
- * UA hardware signal.
- *
- * If motor is on, and our drive is currently
- * selected, just read the hardware bit.
- *
- * If motor is on, but active for another
- * drive on that controller, we are lost. We
- * cannot risk to deselect the other drive, so
- * we just assume a forced UA condition to be
- * on the safe side.
- */
- unitattn = 0;
- if ((dflags & FD_NO_CHLINE) != 0 ||
- (fd->flags & FD_UA) != 0) {
- unitattn = 1;
- fd->flags &= ~FD_UA;
- } else if (fdc->fdout & (FDO_MOEN0 | FDO_MOEN1 |
- FDO_MOEN2 | FDO_MOEN3)) {
- if ((fdc->fdout & FDO_FDSEL) == fd->fdsu)
- unitattn = fdin_rd(fdc) & FDI_DCHG;
- else
- unitattn = 1;
- } else {
- set_motor(fdc, fd->fdsu, TURNON);
- unitattn = fdin_rd(fdc) & FDI_DCHG;
- set_motor(fdc, fd->fdsu, TURNOFF);
- }
- if (unitattn && (rv = fdautoselect(dev)) != 0)
- return (rv);
- }
- } else {
- fd->ft = fd->fts + type;
- }
- fd->flags |= FD_OPEN;
- /*
- * Clearing the DMA overrun counter at open time is a bit messy.
- * Since we're only managing one counter per controller, opening
- * the second drive could mess it up. Anyway, if the DMA overrun
- * condition is really persistent, it will eventually time out
- * still. OTOH, clearing it here will ensure we'll at least start
- * trying again after a previous (maybe even long ago) failure.
- * Also, this is merely a stop-gap measure only that should not
- * happen during normal operation, so we can tolerate it to be a
- * bit sloppy about this.
- */
- fdc->dma_overruns = 0;
-
- return 0;
-}
-
-static int
-fdclose(dev_t dev, int flags, int mode, struct thread *td)
-{
- fdu_t fdu = FDUNIT(minor(dev));
- struct fd_data *fd;
-
- fd = devclass_get_softc(fd_devclass, fdu);
- fd->flags &= ~(FD_OPEN | FD_NONBLOCK);
- fd->options &= ~(FDOPT_NORETRY | FDOPT_NOERRLOG | FDOPT_NOERROR);
-
- return (0);
-}
-
-static void
-fdstrategy(struct bio *bp)
-{
- long blknum, nblocks;
- int s;
- fdu_t fdu;
- fdc_p fdc;
- fd_p fd;
- size_t fdblk;
-
- fdu = FDUNIT(minor(bp->bio_dev));
- fd = devclass_get_softc(fd_devclass, fdu);
- if (fd == 0)
- panic("fdstrategy: buf for nonexistent device (%#lx, %#lx)",
- (u_long)major(bp->bio_dev), (u_long)minor(bp->bio_dev));
- fdc = fd->fdc;
- if (fd->type == FDT_NONE || fd->ft == 0) {
- bp->bio_error = ENXIO;
- bp->bio_flags |= BIO_ERROR;
- goto bad;
- }
- fdblk = 128 << (fd->ft->secsize);
- if (bp->bio_cmd != FDBIO_FORMAT && bp->bio_cmd != FDBIO_RDSECTID) {
- if (fd->flags & FD_NONBLOCK) {
- bp->bio_error = EAGAIN;
- bp->bio_flags |= BIO_ERROR;
- goto bad;
- }
- if (bp->bio_blkno < 0) {
- printf(
- "fd%d: fdstrat: bad request blkno = %lu, bcount = %ld\n",
- fdu, (u_long)bp->bio_blkno, bp->bio_bcount);
- bp->bio_error = EINVAL;
- bp->bio_flags |= BIO_ERROR;
- goto bad;
- }
- if ((bp->bio_bcount % fdblk) != 0) {
- bp->bio_error = EINVAL;
- bp->bio_flags |= BIO_ERROR;
- goto bad;
- }
- }
-
- /*
- * Set up block calculations.
- */
- if (bp->bio_blkno > 20000000) {
- /*
- * Reject unreasonably high block number, prevent the
- * multiplication below from overflowing.
- */
- bp->bio_error = EINVAL;
- bp->bio_flags |= BIO_ERROR;
- goto bad;
- }
- blknum = bp->bio_blkno * DEV_BSIZE / fdblk;
- nblocks = fd->ft->size;
- if (blknum + bp->bio_bcount / fdblk > nblocks) {
- if (blknum >= nblocks) {
- if (bp->bio_cmd == BIO_READ)
- bp->bio_resid = bp->bio_bcount;
- else {
- bp->bio_error = ENOSPC;
- bp->bio_flags |= BIO_ERROR;
- }
- goto bad; /* not always bad, but EOF */
- }
- bp->bio_bcount = (nblocks - blknum) * fdblk;
- }
- bp->bio_pblkno = blknum;
- s = splbio();
- bioq_disksort(&fdc->head, bp);
- untimeout(fd_turnoff, fd, fd->toffhandle); /* a good idea */
- devstat_start_transaction_bio(fd->device_stats, bp);
- device_busy(fd->dev);
- fdstart(fdc);
- splx(s);
- return;
-
-bad:
- biodone(bp);
-}
-
-/*
- * fdstart
- *
- * We have just queued something. If the controller is not busy
- * then simulate the case where it has just finished a command
- * So that it (the interrupt routine) looks on the queue for more
- * work to do and picks up what we just added.
- *
- * If the controller is already busy, we need do nothing, as it
- * will pick up our work when the present work completes.
- */
-static void
-fdstart(struct fdc_data *fdc)
-{
- int s;
-
- s = splbio();
- if(fdc->state == DEVIDLE)
- {
- fdc_intr(fdc);
- }
- splx(s);
-}
-
-static void
-fd_iotimeout(void *xfdc)
-{
- fdc_p fdc;
- int s;
-
- fdc = xfdc;
- TRACE1("fd%d[fd_iotimeout()]", fdc->fdu);
-
- /*
- * Due to IBM's brain-dead design, the FDC has a faked ready
- * signal, hardwired to ready == true. Thus, any command
- * issued if there's no diskette in the drive will _never_
- * complete, and must be aborted by resetting the FDC.
- * Many thanks, Big Blue!
- * The FDC must not be reset directly, since that would
- * interfere with the state machine. Instead, pretend that
- * the command completed but was invalid. The state machine
- * will reset the FDC and retry once.
- */
- s = splbio();
- fdc->status[0] = NE7_ST0_IC_IV;
- fdc->flags &= ~FDC_STAT_VALID;
- fdc->state = IOTIMEDOUT;
- fdc_intr(fdc);
- splx(s);
-}
-
-/* Just ensure it has the right spl. */
-static void
-fd_pseudointr(void *xfdc)
-{
- int s;
-
- s = splbio();
- fdc_intr(xfdc);
- splx(s);
-}
-
-/*
- * fdc_intr
- *
- * Keep calling the state machine until it returns a 0.
- * Always called at splbio.
- */
-static void
-fdc_intr(void *xfdc)
-{
- fdc_p fdc = xfdc;
- while(fdstate(fdc))
- ;
-}
-
-/*
- * Magic pseudo-DMA initialization for YE FDC. Sets count and
- * direction.
- */
-#define SET_BCDR(fdc,wr,cnt,port) \
- bus_space_write_1(fdc->portt, fdc->porth, fdc->port_off + port, \
- ((cnt)-1) & 0xff); \
- bus_space_write_1(fdc->portt, fdc->porth, fdc->port_off + port + 1, \
- ((wr ? 0x80 : 0) | ((((cnt)-1) >> 8) & 0x7f)));
-
-/*
- * fdcpio(): perform programmed IO read/write for YE PCMCIA floppy.
- */
-static int
-fdcpio(fdc_p fdc, long flags, caddr_t addr, u_int count)
-{
- u_char *cptr = (u_char *)addr;
-
- if (flags == BIO_READ) {
- if (fdc->state != PIOREAD) {
- fdc->state = PIOREAD;
- return(0);
- }
- SET_BCDR(fdc, 0, count, 0);
- bus_space_read_multi_1(fdc->portt, fdc->porth, fdc->port_off +
- FDC_YE_DATAPORT, cptr, count);
- } else {
- bus_space_write_multi_1(fdc->portt, fdc->porth, fdc->port_off +
- FDC_YE_DATAPORT, cptr, count);
- SET_BCDR(fdc, 0, count, 0);
- }
- return(1);
-}
-
-/*
- * Try figuring out the density of the media present in our device.
- */
-static int
-fdautoselect(dev_t dev)
-{
- fdu_t fdu;
- fd_p fd;
- struct fd_type *fdtp;
- struct fdc_readid id;
- int i, n, oopts, rv;
-
- fdu = FDUNIT(minor(dev));
- fd = devclass_get_softc(fd_devclass, fdu);
-
- switch (fd->type) {
- default:
- return (ENXIO);
-
- case FDT_360K:
- case FDT_720K:
- /* no autoselection on those drives */
- fd->ft = fd_native_types + fd->type;
- return (0);
-
- case FDT_12M:
- fdtp = fd_searchlist_12m;
- n = sizeof fd_searchlist_12m / sizeof(struct fd_type);
- break;
-
- case FDT_144M:
- fdtp = fd_searchlist_144m;
- n = sizeof fd_searchlist_144m / sizeof(struct fd_type);
- break;
-
- case FDT_288M:
- fdtp = fd_searchlist_288m;
- n = sizeof fd_searchlist_288m / sizeof(struct fd_type);
- break;
- }
-
- /*
- * Try reading sector ID fields, first at cylinder 0, head 0,
- * then at cylinder 2, head N. We don't probe cylinder 1,
- * since for 5.25in DD media in a HD drive, there are no data
- * to read (2 step pulses per media cylinder required). For
- * two-sided media, the second probe always goes to head 1, so
- * we can tell them apart from single-sided media. As a
- * side-effect this means that single-sided media should be
- * mentioned in the search list after two-sided media of an
- * otherwise identical density. Media with a different number
- * of sectors per track but otherwise identical parameters
- * cannot be distinguished at all.
- *
- * If we successfully read an ID field on both cylinders where
- * the recorded values match our expectation, we are done.
- * Otherwise, we try the next density entry from the table.
- *
- * Stepping to cylinder 2 has the side-effect of clearing the
- * unit attention bit.
- */
- oopts = fd->options;
- fd->options |= FDOPT_NOERRLOG | FDOPT_NORETRY;
- for (i = 0; i < n; i++, fdtp++) {
- fd->ft = fdtp;
-
- id.cyl = id.head = 0;
- rv = fdmisccmd(dev, FDBIO_RDSECTID, &id);
- if (rv != 0)
- continue;
- if (id.cyl != 0 || id.head != 0 ||
- id.secshift != fdtp->secsize)
- continue;
- id.cyl = 2;
- id.head = fd->ft->heads - 1;
- rv = fdmisccmd(dev, FDBIO_RDSECTID, &id);
- if (id.cyl != 2 || id.head != fdtp->heads - 1 ||
- id.secshift != fdtp->secsize)
- continue;
- if (rv == 0)
- break;
- }
-
- fd->options = oopts;
- if (i == n) {
- if (bootverbose)
- device_printf(fd->dev, "autoselection failed\n");
- fd->ft = 0;
- return (EIO);
- } else {
- if (bootverbose)
- device_printf(fd->dev, "autoselected %d KB medium\n",
- fd->ft->size / 2);
- return (0);
- }
-}
-
-
-/*
- * The controller state machine.
- *
- * If it returns a non zero value, it should be called again immediately.
- */
-static int
-fdstate(fdc_p fdc)
-{
- struct fdc_readid *idp;
- int read, format, rdsectid, cylinder, head, i, sec = 0, sectrac;
- int st0, cyl, st3, idf, ne7cmd, mfm, steptrac;
- unsigned long blknum;
- fdu_t fdu = fdc->fdu;
- fd_p fd;
- register struct bio *bp;
- struct fd_formb *finfo = NULL;
- size_t fdblk;
-
- bp = fdc->bp;
- if (bp == NULL) {
- bp = bioq_first(&fdc->head);
- if (bp != NULL) {
- bioq_remove(&fdc->head, bp);
- fdc->bp = bp;
- }
- }
- if (bp == NULL) {
- /*
- * Nothing left for this controller to do,
- * force into the IDLE state.
- */
- fdc->state = DEVIDLE;
- if (fdc->fd) {
- device_printf(fdc->fdc_dev,
- "unexpected valid fd pointer\n");
- fdc->fd = (fd_p) 0;
- fdc->fdu = -1;
- }
- TRACE1("[fdc%d IDLE]", fdc->fdcu);
- return (0);
- }
- fdu = FDUNIT(minor(bp->bio_dev));
- fd = devclass_get_softc(fd_devclass, fdu);
- fdblk = 128 << fd->ft->secsize;
- if (fdc->fd && (fd != fdc->fd))
- device_printf(fd->dev, "confused fd pointers\n");
- read = bp->bio_cmd == BIO_READ;
- mfm = (fd->ft->flags & FL_MFM)? NE7CMD_MFM: 0;
- steptrac = (fd->ft->flags & FL_2STEP)? 2: 1;
- if (read)
- idf = ISADMA_READ;
- else
- idf = ISADMA_WRITE;
- format = bp->bio_cmd == FDBIO_FORMAT;
- rdsectid = bp->bio_cmd == FDBIO_RDSECTID;
- if (format)
- finfo = (struct fd_formb *)bp->bio_data;
- TRACE1("fd%d", fdu);
- TRACE1("[%s]", fdstates[fdc->state]);
- TRACE1("(0x%x)", fd->flags);
- untimeout(fd_turnoff, fd, fd->toffhandle);
- fd->toffhandle = timeout(fd_turnoff, fd, 4 * hz);
- switch (fdc->state)
- {
- case DEVIDLE:
- case FINDWORK: /* we have found new work */
- fdc->retry = 0;
- fd->skip = 0;
- fdc->fd = fd;
- fdc->fdu = fdu;
- fdc->fdctl_wr(fdc, fd->ft->trans);
- TRACE1("[0x%x->FDCTL]", fd->ft->trans);
- /*
- * If the next drive has a motor startup pending, then
- * it will start up in its own good time.
- */
- if(fd->flags & FD_MOTOR_WAIT) {
- fdc->state = MOTORWAIT;
- return (0); /* will return later */
- }
- /*
- * Maybe if it's not starting, it SHOULD be starting.
- */
- if (!(fd->flags & FD_MOTOR))
- {
- fdc->state = MOTORWAIT;
- fd_turnon(fd);
- return (0); /* will return later */
- }
- else /* at least make sure we are selected */
- {
- set_motor(fdc, fd->fdsu, TURNON);
- }
- if (fdc->flags & FDC_NEEDS_RESET) {
- fdc->state = RESETCTLR;
- fdc->flags &= ~FDC_NEEDS_RESET;
- } else
- fdc->state = DOSEEK;
- return (1); /* will return immediately */
-
- case DOSEEK:
- blknum = bp->bio_pblkno + fd->skip / fdblk;
- cylinder = blknum / (fd->ft->sectrac * fd->ft->heads);
- if (cylinder == fd->track)
- {
- fdc->state = SEEKCOMPLETE;
- return (1); /* will return immediately */
- }
- if (fd_cmd(fdc, 3, NE7CMD_SEEK,
- fd->fdsu, cylinder * steptrac, 0))
- {
- /*
- * Seek command not accepted, looks like
- * the FDC went off to the Saints...
- */
- fdc->retry = 6; /* try a reset */
- return(retrier(fdc));
- }
- fd->track = FD_NO_TRACK;
- fdc->state = SEEKWAIT;
- return(0); /* will return later */
-
- case SEEKWAIT:
- /* allow heads to settle */
- timeout(fd_pseudointr, fdc, hz / 16);
- fdc->state = SEEKCOMPLETE;
- return(0); /* will return later */
-
- case SEEKCOMPLETE : /* seek done, start DMA */
- blknum = bp->bio_pblkno + fd->skip / fdblk;
- cylinder = blknum / (fd->ft->sectrac * fd->ft->heads);
-
- /* Make sure seek really happened. */
- if(fd->track == FD_NO_TRACK) {
- int descyl = cylinder * steptrac;
- do {
- /*
- * This might be a "ready changed" interrupt,
- * which cannot really happen since the
- * RDY pin is hardwired to + 5 volts. This
- * generally indicates a "bouncing" intr
- * line, so do one of the following:
- *
- * When running on an enhanced FDC that is
- * known to not go stuck after responding
- * with INVALID, fetch all interrupt states
- * until seeing either an INVALID or a
- * real interrupt condition.
- *
- * When running on a dumb old NE765, give
- * up immediately. The controller will
- * provide up to four dummy RC interrupt
- * conditions right after reset (for the
- * corresponding four drives), so this is
- * our only chance to get notice that it
- * was not the FDC that caused the interrupt.
- */
- if (fd_sense_int(fdc, &st0, &cyl)
- == FD_NOT_VALID)
- return (0); /* will return later */
- if(fdc->fdct == FDC_NE765
- && (st0 & NE7_ST0_IC) == NE7_ST0_IC_RC)
- return (0); /* hope for a real intr */
- } while ((st0 & NE7_ST0_IC) == NE7_ST0_IC_RC);
-
- if (0 == descyl) {
- int failed = 0;
- /*
- * seek to cyl 0 requested; make sure we are
- * really there
- */
- if (fd_sense_drive_status(fdc, &st3))
- failed = 1;
- if ((st3 & NE7_ST3_T0) == 0) {
- printf(
- "fd%d: Seek to cyl 0, but not really there (ST3 = %b)\n",
- fdu, st3, NE7_ST3BITS);
- failed = 1;
- }
-
- if (failed) {
- if(fdc->retry < 3)
- fdc->retry = 3;
- return (retrier(fdc));
- }
- }
-
- if (cyl != descyl) {
- printf(
- "fd%d: Seek to cyl %d failed; am at cyl %d (ST0 = 0x%x)\n",
- fdu, descyl, cyl, st0);
- if (fdc->retry < 3)
- fdc->retry = 3;
- return (retrier(fdc));
- }
- }
-
- fd->track = cylinder;
- if (format)
- fd->skip = (char *)&(finfo->fd_formb_cylno(0))
- - (char *)finfo;
- if (!rdsectid && !(fdc->flags & FDC_NODMA))
- isa_dmastart(idf, bp->bio_data+fd->skip,
- format ? bp->bio_bcount : fdblk, fdc->dmachan);
- blknum = bp->bio_pblkno + fd->skip / fdblk;
- sectrac = fd->ft->sectrac;
- sec = blknum % (sectrac * fd->ft->heads);
- head = sec / sectrac;
- sec = sec % sectrac + 1;
- if (head != 0 && fd->ft->offset_side2 != 0)
- sec += fd->ft->offset_side2;
- fd->hddrv = ((head&1)<<2)+fdu;
-
- if(format || !(read || rdsectid))
- {
- /* make sure the drive is writable */
- if(fd_sense_drive_status(fdc, &st3) != 0)
- {
- /* stuck controller? */
- if (!(fdc->flags & FDC_NODMA))
- isa_dmadone(idf,
- bp->bio_data + fd->skip,
- format ? bp->bio_bcount : fdblk,
- fdc->dmachan);
- fdc->retry = 6; /* reset the beast */
- return (retrier(fdc));
- }
- if(st3 & NE7_ST3_WP)
- {
- /*
- * XXX YES! this is ugly.
- * in order to force the current operation
- * to fail, we will have to fake an FDC
- * error - all error handling is done
- * by the retrier()
- */
- fdc->status[0] = NE7_ST0_IC_AT;
- fdc->status[1] = NE7_ST1_NW;
- fdc->status[2] = 0;
- fdc->status[3] = fd->track;
- fdc->status[4] = head;
- fdc->status[5] = sec;
- fdc->retry = 8; /* break out immediately */
- fdc->state = IOTIMEDOUT; /* not really... */
- return (1); /* will return immediately */
- }
- }
-
- if (format) {
- ne7cmd = NE7CMD_FORMAT | mfm;
- if (fdc->flags & FDC_NODMA) {
- /*
- * This seems to be necessary for
- * whatever obscure reason; if we omit
- * it, we end up filling the sector ID
- * fields of the newly formatted track
- * entirely with garbage, causing
- * `wrong cylinder' errors all over
- * the place when trying to read them
- * back.
- *
- * Umpf.
- */
- SET_BCDR(fdc, 1, bp->bio_bcount, 0);
-
- (void)fdcpio(fdc,bp->bio_cmd,
- bp->bio_data+fd->skip,
- bp->bio_bcount);
-
- }
- /* formatting */
- if(fd_cmd(fdc, 6, ne7cmd, head << 2 | fdu,
- finfo->fd_formb_secshift,
- finfo->fd_formb_nsecs,
- finfo->fd_formb_gaplen,
- finfo->fd_formb_fillbyte, 0)) {
- /* controller fell over */
- if (!(fdc->flags & FDC_NODMA))
- isa_dmadone(idf,
- bp->bio_data + fd->skip,
- format ? bp->bio_bcount : fdblk,
- fdc->dmachan);
- fdc->retry = 6;
- return (retrier(fdc));
- }
- } else if (rdsectid) {
- ne7cmd = NE7CMD_READID | mfm;
- if (fd_cmd(fdc, 2, ne7cmd, head << 2 | fdu, 0)) {
- /* controller jamming */
- fdc->retry = 6;
- return (retrier(fdc));
- }
- } else {
- /* read or write operation */
- ne7cmd = (read ? NE7CMD_READ | NE7CMD_SK : NE7CMD_WRITE) | mfm;
- if (fdc->flags & FDC_NODMA) {
- /*
- * This seems to be necessary even when
- * reading data.
- */
- SET_BCDR(fdc, 1, fdblk, 0);
-
- /*
- * Perform the write pseudo-DMA before
- * the WRITE command is sent.
- */
- if (!read)
- (void)fdcpio(fdc,bp->bio_cmd,
- bp->bio_data+fd->skip,
- fdblk);
- }
- if (fd_cmd(fdc, 9,
- ne7cmd,
- head << 2 | fdu, /* head & unit */
- fd->track, /* track */
- head,
- sec, /* sector + 1 */
- fd->ft->secsize, /* sector size */
- sectrac, /* sectors/track */
- fd->ft->gap, /* gap size */
- fd->ft->datalen, /* data length */
- 0)) {
- /* the beast is sleeping again */
- if (!(fdc->flags & FDC_NODMA))
- isa_dmadone(idf,
- bp->bio_data + fd->skip,
- format ? bp->bio_bcount : fdblk,
- fdc->dmachan);
- fdc->retry = 6;
- return (retrier(fdc));
- }
- }
- if (!rdsectid && (fdc->flags & FDC_NODMA))
- /*
- * If this is a read, then simply await interrupt
- * before performing PIO.
- */
- if (read && !fdcpio(fdc,bp->bio_cmd,
- bp->bio_data+fd->skip,fdblk)) {
- fd->tohandle = timeout(fd_iotimeout, fdc, hz);
- return(0); /* will return later */
- }
-
- /*
- * Write (or format) operation will fall through and
- * await completion interrupt.
- */
- fdc->state = IOCOMPLETE;
- fd->tohandle = timeout(fd_iotimeout, fdc, hz);
- return (0); /* will return later */
-
- case PIOREAD:
- /*
- * Actually perform the PIO read. The IOCOMPLETE case
- * removes the timeout for us.
- */
- (void)fdcpio(fdc,bp->bio_cmd,bp->bio_data+fd->skip,fdblk);
- fdc->state = IOCOMPLETE;
- /* FALLTHROUGH */
- case IOCOMPLETE: /* IO done, post-analyze */
- untimeout(fd_iotimeout, fdc, fd->tohandle);
-
- if (fd_read_status(fdc)) {
- if (!rdsectid && !(fdc->flags & FDC_NODMA))
- isa_dmadone(idf, bp->bio_data + fd->skip,
- format ? bp->bio_bcount : fdblk,
- fdc->dmachan);
- if (fdc->retry < 6)
- fdc->retry = 6; /* force a reset */
- return (retrier(fdc));
- }
-
- fdc->state = IOTIMEDOUT;
-
- /* FALLTHROUGH */
- case IOTIMEDOUT:
- if (!rdsectid && !(fdc->flags & FDC_NODMA))
- isa_dmadone(idf, bp->bio_data + fd->skip,
- format ? bp->bio_bcount : fdblk, fdc->dmachan);
- if (fdc->status[0] & NE7_ST0_IC) {
- if ((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_AT
- && fdc->status[1] & NE7_ST1_OR) {
- /*
- * DMA overrun. Someone hogged the bus and
- * didn't release it in time for the next
- * FDC transfer.
- *
- * We normally restart this without bumping
- * the retry counter. However, in case
- * something is seriously messed up (like
- * broken hardware), we rather limit the
- * number of retries so the IO operation
- * doesn't block indefinately.
- */
- if (fdc->dma_overruns++ < FDC_DMAOV_MAX) {
- fdc->state = SEEKCOMPLETE;
- return (1);/* will return immediately */
- } /* else fall through */
- }
- if((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_IV
- && fdc->retry < 6)
- fdc->retry = 6; /* force a reset */
- else if((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_AT
- && fdc->status[2] & NE7_ST2_WC
- && fdc->retry < 3)
- fdc->retry = 3; /* force recalibrate */
- return (retrier(fdc));
- }
- /* All OK */
- if (rdsectid) {
- /* copy out ID field contents */
- idp = (struct fdc_readid *)bp->bio_data;
- idp->cyl = fdc->status[3];
- idp->head = fdc->status[4];
- idp->sec = fdc->status[5];
- idp->secshift = fdc->status[6];
- }
- /* Operation successful, retry DMA overruns again next time. */
- fdc->dma_overruns = 0;
- fd->skip += fdblk;
- if (!rdsectid && !format && fd->skip < bp->bio_bcount) {
- /* set up next transfer */
- fdc->state = DOSEEK;
- } else {
- /* ALL DONE */
- fd->skip = 0;
- bp->bio_resid = 0;
- fdc->bp = NULL;
- device_unbusy(fd->dev);
- biofinish(bp, fd->device_stats, 0);
- fdc->fd = (fd_p) 0;
- fdc->fdu = -1;
- fdc->state = FINDWORK;
- }
- return (1); /* will return immediately */
-
- case RESETCTLR:
- fdc_reset(fdc);
- fdc->retry++;
- fdc->state = RESETCOMPLETE;
- return (0); /* will return later */
-
- case RESETCOMPLETE:
- /*
- * Discard all the results from the reset so that they
- * can't cause an unexpected interrupt later.
- */
- for (i = 0; i < 4; i++)
- (void)fd_sense_int(fdc, &st0, &cyl);
- fdc->state = STARTRECAL;
- /* FALLTHROUGH */
- case STARTRECAL:
- if(fd_cmd(fdc, 2, NE7CMD_RECAL, fdu, 0)) {
- /* arrgl */
- fdc->retry = 6;
- return (retrier(fdc));
- }
- fdc->state = RECALWAIT;
- return (0); /* will return later */
-
- case RECALWAIT:
- /* allow heads to settle */
- timeout(fd_pseudointr, fdc, hz / 8);
- fdc->state = RECALCOMPLETE;
- return (0); /* will return later */
-
- case RECALCOMPLETE:
- do {
- /*
- * See SEEKCOMPLETE for a comment on this:
- */
- if (fd_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
- return (0); /* will return later */
- if(fdc->fdct == FDC_NE765
- && (st0 & NE7_ST0_IC) == NE7_ST0_IC_RC)
- return (0); /* hope for a real intr */
- } while ((st0 & NE7_ST0_IC) == NE7_ST0_IC_RC);
- if ((st0 & NE7_ST0_IC) != NE7_ST0_IC_NT || cyl != 0)
- {
- if(fdc->retry > 3)
- /*
- * A recalibrate from beyond cylinder 77
- * will "fail" due to the FDC limitations;
- * since people used to complain much about
- * the failure message, try not logging
- * this one if it seems to be the first
- * time in a line.
- */
- printf("fd%d: recal failed ST0 %b cyl %d\n",
- fdu, st0, NE7_ST0BITS, cyl);
- if(fdc->retry < 3) fdc->retry = 3;
- return (retrier(fdc));
- }
- fd->track = 0;
- /* Seek (probably) necessary */
- fdc->state = DOSEEK;
- return (1); /* will return immediately */
-
- case MOTORWAIT:
- if(fd->flags & FD_MOTOR_WAIT)
- {
- return (0); /* time's not up yet */
- }
- if (fdc->flags & FDC_NEEDS_RESET) {
- fdc->state = RESETCTLR;
- fdc->flags &= ~FDC_NEEDS_RESET;
- } else
- fdc->state = DOSEEK;
- return (1); /* will return immediately */
-
- default:
- device_printf(fdc->fdc_dev, "unexpected FD int->");
- if (fd_read_status(fdc) == 0)
- printf("FDC status :%x %x %x %x %x %x %x ",
- fdc->status[0],
- fdc->status[1],
- fdc->status[2],
- fdc->status[3],
- fdc->status[4],
- fdc->status[5],
- fdc->status[6] );
- else
- printf("No status available ");
- if (fd_sense_int(fdc, &st0, &cyl) != 0)
- {
- printf("[controller is dead now]\n");
- return (0); /* will return later */
- }
- printf("ST0 = %x, PCN = %x\n", st0, cyl);
- return (0); /* will return later */
- }
- /* noone should ever get here */
-}
-
-static int
-retrier(struct fdc_data *fdc)
-{
- struct bio *bp;
- struct fd_data *fd;
- int fdu;
-
- bp = fdc->bp;
-
- /* XXX shouldn't this be cached somewhere? */
- fdu = FDUNIT(minor(bp->bio_dev));
- fd = devclass_get_softc(fd_devclass, fdu);
- if (fd->options & FDOPT_NORETRY)
- goto fail;
-
- switch (fdc->retry) {
- case 0: case 1: case 2:
- fdc->state = SEEKCOMPLETE;
- break;
- case 3: case 4: case 5:
- fdc->state = STARTRECAL;
- break;
- case 6:
- fdc->state = RESETCTLR;
- break;
- case 7:
- break;
- default:
- fail:
- if ((fd->options & FDOPT_NOERRLOG) == 0) {
- disk_err(bp, "hard error",
- fdc->fd->skip / DEV_BSIZE, 0);
- if (fdc->flags & FDC_STAT_VALID) {
- printf(
- " (ST0 %b ST1 %b ST2 %b cyl %u hd %u sec %u)\n",
- fdc->status[0], NE7_ST0BITS,
- fdc->status[1], NE7_ST1BITS,
- fdc->status[2], NE7_ST2BITS,
- fdc->status[3], fdc->status[4],
- fdc->status[5]);
- }
- else
- printf(" (No status)\n");
- }
- if ((fd->options & FDOPT_NOERROR) == 0) {
- bp->bio_flags |= BIO_ERROR;
- bp->bio_error = EIO;
- bp->bio_resid = bp->bio_bcount - fdc->fd->skip;
- } else
- bp->bio_resid = 0;
- fdc->bp = NULL;
- fdc->fd->skip = 0;
- device_unbusy(fd->dev);
- biofinish(bp, fdc->fd->device_stats, 0);
- fdc->state = FINDWORK;
- fdc->flags |= FDC_NEEDS_RESET;
- fdc->fd = (fd_p) 0;
- fdc->fdu = -1;
- return (1);
- }
- fdc->retry++;
- return (1);
-}
-
-static void
-fdbiodone(struct bio *bp)
-{
- wakeup(bp);
-}
-
-static int
-fdmisccmd(dev_t dev, u_int cmd, void *data)
-{
- fdu_t fdu;
- fd_p fd;
- struct bio *bp;
- struct fd_formb *finfo;
- struct fdc_readid *idfield;
- size_t fdblk;
- int error;
-
- fdu = FDUNIT(minor(dev));
- fd = devclass_get_softc(fd_devclass, fdu);
- fdblk = 128 << fd->ft->secsize;
- finfo = (struct fd_formb *)data;
- idfield = (struct fdc_readid *)data;
-
- bp = malloc(sizeof(struct bio), M_TEMP, M_WAITOK | M_ZERO);
-
- /*
- * Set up a bio request for fdstrategy(). bio_blkno is faked
- * so that fdstrategy() will seek to the the requested
- * cylinder, and use the desired head.
- */
- bp->bio_cmd = cmd;
- if (cmd == FDBIO_FORMAT) {
- bp->bio_blkno =
- (finfo->cyl * (fd->ft->sectrac * fd->ft->heads) +
- finfo->head * fd->ft->sectrac) *
- fdblk / DEV_BSIZE;
- bp->bio_bcount = sizeof(struct fd_idfield_data) *
- finfo->fd_formb_nsecs;
- } else if (cmd == FDBIO_RDSECTID) {
- bp->bio_blkno =
- (idfield->cyl * (fd->ft->sectrac * fd->ft->heads) +
- idfield->head * fd->ft->sectrac) *
- fdblk / DEV_BSIZE;
- bp->bio_bcount = sizeof(struct fdc_readid);
- } else
- panic("wrong cmd in fdmisccmd()");
- bp->bio_data = data;
- bp->bio_dev = dev;
- bp->bio_done = fdbiodone;
- bp->bio_flags = 0;
-
- /* Now run the command. */
- fdstrategy(bp);
- error = biowait(bp, "fdcmd");
-
- free(bp, M_TEMP);
- return (error);
-}
-
-static int
-fdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
-{
- fdu_t fdu;
- fd_p fd;
- struct fdc_status *fsp;
- struct fdc_readid *rid;
- size_t fdblk;
- int error, type;
-
- fdu = FDUNIT(minor(dev));
- type = FDTYPE(minor(dev));
- fd = devclass_get_softc(fd_devclass, fdu);
-
- /*
- * First, handle everything that could be done with
- * FD_NONBLOCK still being set.
- */
- switch (cmd) {
-
- case DIOCGMEDIASIZE:
- *(off_t *)addr = (128 << (fd->ft->secsize)) * fd->ft->size;
- return (0);
-
- case DIOCGSECTORSIZE:
- *(u_int *)addr = 128 << (fd->ft->secsize);
- return (0);
-
- case FIONBIO:
- if (*(int *)addr != 0)
- fd->flags |= FD_NONBLOCK;
- else {
- if (fd->ft == 0) {
- /*
- * No drive type has been selected yet,
- * cannot turn FNONBLOCK off.
- */
- return (EINVAL);
- }
- fd->flags &= ~FD_NONBLOCK;
- }
- return (0);
-
- case FIOASYNC:
- /* keep the generic fcntl() code happy */
- return (0);
-
- case FD_GTYPE: /* get drive type */
- if (fd->ft == 0)
- /* no type known yet, return the native type */
- *(struct fd_type *)addr = fd_native_types[fd->type];
- else
- *(struct fd_type *)addr = *fd->ft;
- return (0);
-
- case FD_STYPE: /* set drive type */
- if (type == 0) {
- /*
- * Allow setting drive type temporarily iff
- * currently unset. Used for fdformat so any
- * user can set it, and then start formatting.
- */
- if (fd->ft)
- return (EINVAL); /* already set */
- fd->ft = fd->fts;
- *fd->ft = *(struct fd_type *)addr;
- fd->flags |= FD_UA;
- } else {
- /*
- * Set density definition permanently. Only
- * allow for superuser.
- */
- if (suser(td) != 0)
- return (EPERM);
- fd->fts[type] = *(struct fd_type *)addr;
- }
- return (0);
-
- case FD_GOPTS: /* get drive options */
- *(int *)addr = fd->options + (type == 0? FDOPT_AUTOSEL: 0);
- return (0);
-
- case FD_SOPTS: /* set drive options */
- fd->options = *(int *)addr & ~FDOPT_AUTOSEL;
- return (0);
-
-#ifdef FDC_DEBUG
- case FD_DEBUG:
- if ((fd_debug != 0) != (*(int *)addr != 0)) {
- fd_debug = (*(int *)addr != 0);
- printf("fd%d: debugging turned %s\n",
- fd->fdu, fd_debug ? "on" : "off");
- }
- return (0);
-#endif
-
- case FD_CLRERR:
- if (suser(td) != 0)
- return (EPERM);
- fd->fdc->fdc_errs = 0;
- return (0);
-
- case FD_GSTAT:
- fsp = (struct fdc_status *)addr;
- if ((fd->fdc->flags & FDC_STAT_VALID) == 0)
- return (EINVAL);
- memcpy(fsp->status, fd->fdc->status, 7 * sizeof(u_int));
- return (0);
-
- case FD_GDTYPE:
- *(enum fd_drivetype *)addr = fd->type;
- return (0);
- }
-
- /*
- * Now handle everything else. Make sure we have a valid
- * drive type.
- */
- if (fd->flags & FD_NONBLOCK)
- return (EAGAIN);
- if (fd->ft == 0)
- return (ENXIO);
- fdblk = 128 << fd->ft->secsize;
- error = 0;
-
- switch (cmd) {
-
- case FD_FORM:
- if ((flag & FWRITE) == 0)
- return (EBADF); /* must be opened for writing */
- if (((struct fd_formb *)addr)->format_version !=
- FD_FORMAT_VERSION)
- return (EINVAL); /* wrong version of formatting prog */
- error = fdmisccmd(dev, FDBIO_FORMAT, addr);
- break;
-
- case FD_GTYPE: /* get drive type */
- *(struct fd_type *)addr = *fd->ft;
- break;
-
- case FD_STYPE: /* set drive type */
- /* this is considered harmful; only allow for superuser */
- if (suser(td) != 0)
- return (EPERM);
- *fd->ft = *(struct fd_type *)addr;
- break;
-
- case FD_GOPTS: /* get drive options */
- *(int *)addr = fd->options;
- break;
-
- case FD_SOPTS: /* set drive options */
- fd->options = *(int *)addr;
- break;
-
-#ifdef FDC_DEBUG
- case FD_DEBUG:
- if ((fd_debug != 0) != (*(int *)addr != 0)) {
- fd_debug = (*(int *)addr != 0);
- printf("fd%d: debugging turned %s\n",
- fd->fdu, fd_debug ? "on" : "off");
- }
- break;
-#endif
-
- case FD_CLRERR:
- if (suser(td) != 0)
- return (EPERM);
- fd->fdc->fdc_errs = 0;
- break;
-
- case FD_GSTAT:
- fsp = (struct fdc_status *)addr;
- if ((fd->fdc->flags & FDC_STAT_VALID) == 0)
- return (EINVAL);
- memcpy(fsp->status, fd->fdc->status, 7 * sizeof(u_int));
- break;
-
- case FD_READID:
- rid = (struct fdc_readid *)addr;
- if (rid->cyl > MAX_CYLINDER || rid->head > MAX_HEAD)
- return (EINVAL);
- error = fdmisccmd(dev, FDBIO_RDSECTID, addr);
- break;
-
- default:
- error = ENOTTY;
- break;
- }
- return (error);
-}
diff --git a/sys/dev/fdc/fdcreg.h b/sys/dev/fdc/fdcreg.h
deleted file mode 100644
index c08266873185..000000000000
--- a/sys/dev/fdc/fdcreg.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)fdreg.h 7.1 (Berkeley) 5/9/91
- * $FreeBSD$
- */
-
-/*
- * AT floppy controller registers and bitfields
- */
-
-/* uses NEC765 controller */
-#include <dev/ic/nec765.h>
-
-/* registers */
-#define FDOUT 2 /* Digital Output Register (W) */
-#define FDO_FDSEL 0x03 /* floppy device select */
-#define FDO_FRST 0x04 /* floppy controller reset */
-#define FDO_FDMAEN 0x08 /* enable floppy DMA and Interrupt */
-#define FDO_MOEN0 0x10 /* motor enable drive 0 */
-#define FDO_MOEN1 0x20 /* motor enable drive 1 */
-#define FDO_MOEN2 0x40 /* motor enable drive 2 */
-#define FDO_MOEN3 0x80 /* motor enable drive 3 */
-
-#define FDSTS 4 /* NEC 765 Main Status Register (R) */
-#define FDDATA 5 /* NEC 765 Data Register (R/W) */
-#define FDCTL 7 /* Control Register (W) */
-
-/*
- * The definitions for FDC_500KBPS etc. have been moved out to <sys/fdcio.h>
- * since they need to be visible in userland. They cover the lower two bits
- * of FDCTL when used for output.
- */
-/*
- * this is the secret PIO data port (offset from base)
- */
-#define FDC_YE_DATAPORT 6
-
-#define FDIN 7 /* Digital Input Register (R) */
-#define FDI_DCHG 0x80 /* diskette has been changed */
- /* requires drive and motor being selected */
- /* is cleared by any step pulse to drive */
diff --git a/sys/dev/fe/mb86960.h b/sys/dev/fe/mb86960.h
deleted file mode 100644
index 971ab6692660..000000000000
--- a/sys/dev/fe/mb86960.h
+++ /dev/null
@@ -1,340 +0,0 @@
-/*
- * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
- *
- * This software may be used, modified, copied, distributed, and sold, in
- * both source and binary form provided that the above copyright, these
- * terms and the following disclaimer are retained. The name of the author
- * and/or the contributor 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 THE CONTRIBUTOR ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED 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 THE CONTRIBUTOR BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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$
- */
-
-/*
- * Registers of Fujitsu MB86960A/MB86965A series Ethernet controllers.
- * Written and contributed by M.S. <seki@sysrap.cs.fujitsu.co.jp>
- */
-
-/*
- * Notes on register naming:
- *
- * Fujitsu documents for MB86960A/MB86965A uses no mnemorable names
- * for their registers. They defined only three names for 32
- * registers and appended numbers to distinguish registers of
- * same name. Surprisingly, the numbers represent I/O address
- * offsets of the registers from the base addresses, and their
- * names correspond to the "bank" the registers are allocated.
- * All this means that, for example, to say "read DLCR8" has no more
- * than to say "read a register at offset 8 on bank DLCR."
- *
- * The following definitions may look silly, but that's what Fujitsu
- * did, and it is necessary to know these names to read Fujitsu
- * documents..
- */
-
-/* Data Link Control Registrs, on invaliant port addresses. */
-#define FE_DLCR0 0
-#define FE_DLCR1 1
-#define FE_DLCR2 2
-#define FE_DLCR3 3
-#define FE_DLCR4 4
-#define FE_DLCR5 5
-#define FE_DLCR6 6
-#define FE_DLCR7 7
-
-/* More DLCRs, on register bank #0. */
-#define FE_DLCR8 8
-#define FE_DLCR9 9
-#define FE_DLCR10 10
-#define FE_DLCR11 11
-#define FE_DLCR12 12
-#define FE_DLCR13 13
-#define FE_DLCR14 14
-#define FE_DLCR15 15
-
-/* Malticast Address Registers. On register bank #1. */
-#define FE_MAR8 8
-#define FE_MAR9 9
-#define FE_MAR10 10
-#define FE_MAR11 11
-#define FE_MAR12 12
-#define FE_MAR13 13
-#define FE_MAR14 14
-#define FE_MAR15 15
-
-/* Buffer Memory Port Registers. On register back #2. */
-#define FE_BMPR8 8
-#define FE_BMPR9 9
-#define FE_BMPR10 10
-#define FE_BMPR11 11
-#define FE_BMPR12 12
-#define FE_BMPR13 13
-#define FE_BMPR14 14
-#define FE_BMPR15 15
-
-/* More BMPRs, only on 86965, accessible only when JLI mode. */
-#define FE_BMPR16 16
-#define FE_BMPR17 17
-#define FE_BMPR18 18
-#define FE_BMPR19 19
-
-/*
- * Definitions of registers.
- * I don't have Fujitsu documents of MB86960A/MB86965A, so I don't
- * know the official names for each flags and fields. The following
- * names are assigned by me (the author of this file,) since I cannot
- * mnemorize hexadecimal constants for all of these functions.
- * Comments?
- *
- * I've got documents from Fujitsu web site, recently. However, it's
- * too late. Names for some fields (bits) are kept different from
- * those used in the Fujitsu documents...
- */
-
-/* DLCR0 -- transmitter status */
-#define FE_D0_BUSERR 0x01 /* Bus write error? */
-#define FE_D0_COLL16 0x02 /* Collision limit (16) encountered */
-#define FE_D0_COLLID 0x04 /* Collision on last transmission */
-#define FE_D0_JABBER 0x08 /* Jabber */
-#define FE_D0_CRLOST 0x10 /* Carrier lost on last transmission */
-#define FE_D0_PKTRCD 0x20 /* Last packet looped back correctly */
-#define FE_D0_NETBSY 0x40 /* Network Busy (Carrier Detected) */
-#define FE_D0_TXDONE 0x80 /* Transmission complete */
-
-/* DLCR1 -- receiver status */
-#define FE_D1_OVRFLO 0x01 /* Receiver buffer overflow */
-#define FE_D1_CRCERR 0x02 /* CRC error on last packet */
-#define FE_D1_ALGERR 0x04 /* Alignment error on last packet */
-#define FE_D1_SRTPKT 0x08 /* Short (RUNT) packet is received */
-#define FE_D1_RMTRST 0x10 /* Remote reset packet (type = 0x0900) */
-#define FE_D1_DMAEOP 0x20 /* Host asserted End of DMA OPeration */
-#define FE_D1_BUSERR 0x40 /* Bus read error */
-#define FE_D1_PKTRDY 0x80 /* Packet(s) ready on receive buffer */
-
-/* DLCR2 -- transmitter interrupt control; same layout as DLCR0 */
-#define FE_D2_BUSERR FE_D0_BUSERR
-#define FE_D2_COLL16 FE_D0_COLL16
-#define FE_D2_COLLID FE_D0_COLLID
-#define FE_D2_JABBER FE_D0_JABBER
-#define FE_D2_TXDONE FE_D0_TXDONE
-
-#define FE_D2_RESERVED 0x70
-
-/* DLCR3 -- receiver interrupt control; same layout as DLCR1 */
-#define FE_D3_OVRFLO FE_D1_OVRFLO
-#define FE_D3_CRCERR FE_D1_CRCERR
-#define FE_D3_ALGERR FE_D1_ALGERR
-#define FE_D3_SRTPKT FE_D1_SRTPKT
-#define FE_D3_RMTRST FE_D1_RMTRST
-#define FE_D3_DMAEOP FE_D1_DMAEOP
-#define FE_D3_BUSERR FE_D1_BUSERR
-#define FE_D3_PKTRDY FE_D1_PKTRDY
-
-/* DLCR4 -- transmitter operation mode */
-#define FE_D4_DSC 0x01 /* Disable carrier sense on trans. */
-#define FE_D4_LBC 0x02 /* Loop back test control */
-#define FE_D4_CNTRL 0x04 /* - tied to CNTRL pin of the chip */
-#define FE_D4_TEST1 0x08 /* Test output #1 */
-#define FE_D4_COL 0xF0 /* Collision counter */
-
-#define FE_D4_LBC_ENABLE 0x00 /* Perform loop back test */
-#define FE_D4_LBC_DISABLE 0x02 /* Normal operation */
-
-#define FE_D4_COL_SHIFT 4
-
-/* DLCR5 -- receiver operation mode */
-#define FE_D5_AFM0 0x01 /* Receive packets for other stations */
-#define FE_D5_AFM1 0x02 /* Receive packets for this station */
-#define FE_D5_RMTRST 0x04 /* Enable remote reset operation */
-#define FE_D5_SRTPKT 0x08 /* Accept short (RUNT) packets */
-#define FE_D5_SRTADR 0x10 /* Short (16 bits?) MAC address */
-#define FE_D5_BADPKT 0x20 /* Accept packets with error */
-#define FE_D5_BUFEMP 0x40 /* Receive buffer is empty */
-#define FE_D5_TEST2 0x80 /* Test output #2 */
-
-/* DLCR6 -- hardware configuration #0 */
-#define FE_D6_BUFSIZ 0x03 /* Size of NIC buffer SRAM */
-#define FE_D6_TXBSIZ 0x0C /* Size (and config)of trans. buffer */
-#define FE_D6_BBW 0x10 /* Buffer SRAM bus width */
-#define FE_D6_SBW 0x20 /* System bus width */
-#define FE_D6_SRAM 0x40 /* Buffer SRAM access time */
-#define FE_D6_DLC 0x80 /* Disable DLC (recever/transmitter) */
-
-#define FE_D6_BUFSIZ_8KB 0x00 /* The board has 8KB SRAM */
-#define FE_D6_BUFSIZ_16KB 0x01 /* The board has 16KB SRAM */
-#define FE_D6_BUFSIZ_32KB 0x02 /* The board has 32KB SRAM */
-#define FE_D6_BUFSIZ_64KB 0x03 /* The board has 64KB SRAM */
-
-#define FE_D6_TXBSIZ_1x2KB 0x00 /* Single 2KB buffer for trans. */
-#define FE_D6_TXBSIZ_2x2KB 0x04 /* Double 2KB buffers */
-#define FE_D6_TXBSIZ_2x4KB 0x08 /* Double 4KB buffers */
-#define FE_D6_TXBSIZ_2x8KB 0x0C /* Double 8KB buffers */
-
-#define FE_D6_BBW_WORD 0x00 /* SRAM has 16 bit data line */
-#define FE_D6_BBW_BYTE 0x10 /* SRAM has 8 bit data line */
-
-#define FE_D6_SBW_WORD 0x00 /* Access with 16 bit (AT) bus */
-#define FE_D6_SBW_BYTE 0x20 /* Access with 8 bit (XT) bus */
-
-#define FE_D6_SRAM_150ns 0x00 /* The board has slow SRAM */
-#define FE_D6_SRAM_100ns 0x40 /* The board has fast SRAM */
-
-#define FE_D6_DLC_ENABLE 0x00 /* Normal operation */
-#define FE_D6_DLC_DISABLE 0x80 /* Stop sending/receiving */
-
-/* DLC7 -- hardware configuration #1 */
-#define FE_D7_BYTSWP 0x01 /* Host byte order control */
-#define FE_D7_EOPPOL 0x02 /* Polarity of DMA EOP signal */
-#define FE_D7_RBS 0x0C /* Register bank select */
-#define FE_D7_RDYPNS 0x10 /* Senses RDYPNSEL input signal */
-#define FE_D7_POWER 0x20 /* Stand-by (power down) mode control */
-#define FE_D7_IDENT 0xC0 /* Chip identification */
-
-#define FE_D7_BYTSWP_LH 0x00 /* DEC/Intel byte order */
-#define FE_D7_BYTSWP_HL 0x01 /* IBM/Motorolla byte order */
-
-#define FE_D7_RBS_DLCR 0x00 /* Select DLCR8-15 */
-#define FE_D7_RBS_MAR 0x04 /* Select MAR8-15 */
-#define FE_D7_RBS_BMPR 0x08 /* Select BMPR8-15 */
-
-#define FE_D7_POWER_DOWN 0x00 /* Power down (stand-by) mode */
-#define FE_D7_POWER_UP 0x20 /* Normal operation */
-
-#define FE_D7_IDENT_TDK 0x00 /* TDK chips? */
-#define FE_D7_IDENT_NICE 0x80 /* Fujitsu NICE (86960) */
-#define FE_D7_IDENT_EC 0xC0 /* Fujitsu EtherCoupler (86965) */
-
-/* DLCR8 thru DLCR13 are for Ethernet station address. */
-
-/* DLCR14 and DLCR15 are for TDR. (TDR is used for cable diagnostic.) */
-
-/* MAR8 thru MAR15 are for Multicast address filter. */
-
-/* BMPR8 and BMPR9 are for packet data. */
-
-/* BMPR10 -- transmitter start trigger */
-#define FE_B10_START 0x80 /* Start transmitter */
-#define FE_B10_COUNT 0x7F /* Packet count */
-
-/* BMPR11 -- 16 collisions control */
-#define FE_B11_CTRL 0x01 /* Skip or resend errored packets */
-#define FE_B11_MODE1 0x02 /* Restart transmitter after COLL16 */
-#define FE_B11_MODE2 0x04 /* Automatic restart enable */
-
-#define FE_B11_CTRL_RESEND 0x00 /* Re-send the collided packet */
-#define FE_B11_CTRL_SKIP 0x01 /* Skip the collided packet */
-
-/* BMPR12 -- DMA enable */
-#define FE_B12_TXDMA 0x01 /* Enable transmitter DMA */
-#define FE_B12_RXDMA 0x02 /* Enable receiver DMA */
-
-/* BMPR13 -- DMA control */
-#define FE_B13_BSTCTL 0x03 /* DMA burst mode control */
-#define FE_B13_TPTYPE 0x04 /* Twisted pair cable impedance */
-#define FE_B13_PORT 0x18 /* Port (TP/AUI) selection */
-#define FE_B13_LNKTST 0x20 /* Link test enable */
-#define FE_B13_SQTHLD 0x40 /* Lower squelch threshold */
-#define FE_B13_IOUNLK 0x80 /* Change I/O base address, on JLI mode */
-
-#define FE_B13_BSTCTL_1 0x00
-#define FE_B13_BSTCTL_4 0x01
-#define FE_B13_BSTCTL_8 0x02
-#define FE_B13_BSTCLT_12 0x03
-
-#define FE_B13_TPTYPE_UTP 0x00 /* Unshielded (standard) cable */
-#define FE_B13_TPTYPE_STP 0x04 /* Shielded (IBM) cable */
-
-#define FE_B13_PORT_AUTO 0x00 /* Auto detected */
-#define FE_B13_PORT_TP 0x08 /* Force TP */
-#define FE_B13_PORT_AUI 0x18 /* Force AUI */
-
-/* BMPR14 -- More receiver control and more transmission interrupts */
-#define FE_B14_FILTER 0x01 /* Filter out self-originated packets */
-#define FE_B14_SQE 0x02 /* SQE interrupt enable */
-#define FE_B14_SKIP 0x04 /* Skip a received packet */
-#define FE_B14_RJAB 0x20 /* RJAB interrupt enable */
-#define FE_B14_LLD 0x40 /* Local-link-down interrupt enable */
-#define FE_B14_RLD 0x80 /* Remote-link-down interrupt enable */
-
-/* BMPR15 -- More transmitter status; basically same layout as BMPR14 */
-#define FE_B15_SQE FE_B14_SQE
-#define FE_B15_RCVPOL 0x08 /* Reversed receive line polarity */
-#define FE_B15_RMTPRT 0x10 /* ??? */
-#define FE_B15_RAJB FE_B14_RJAB
-#define FE_B15_LLD FE_B14_LLD
-#define FE_B15_RLD FE_B14_RLD
-
-/* BMPR16 -- EEPROM control */
-#define FE_B16_DOUT 0x04 /* EEPROM Data in (CPU to EEPROM) */
-#define FE_B16_SELECT 0x20 /* EEPROM chip select */
-#define FE_B16_CLOCK 0x40 /* EEPROM shift clock */
-#define FE_B16_DIN 0x80 /* EEPROM data out (EEPROM to CPU) */
-
-/* BMPR17 -- EEPROM data */
-#define FE_B17_DATA 0x80 /* EEPROM data bit */
-
-/* BMPR18 -- cycle I/O address setting in JLI mode */
-
-/* BMPR19 -- ISA interface configuration in JLI mode */
-#define FE_B19_IRQ 0xC0
-#define FE_B19_IRQ_SHIFT 6
-
-#define FE_B19_ROM 0x38
-#define FE_B19_ROM_SHIFT 3
-
-#define FE_B19_ADDR 0x07
-#define FE_B19_ADDR_SHIFT 0
-
-/*
- * An extra I/O port address to reset 86965. This location is called
- * "ID ROM area" by Fujitsu document.
- */
-
-/*
- * Flags in Receive Packet Header... Basically same layout as DLCR1.
- */
-#define FE_RPH_OVRFLO FE_D1_OVRFLO
-#define FE_RPH_CRCERR FE_D1_CRCERR
-#define FE_RPH_ALGERR FE_D1_ALGERR
-#define FE_RPH_SRTPKT FE_D1_SRTPKT
-#define FE_RPH_RMTRST FE_D1_RMTRST
-#define FE_RPH_GOOD 0x20 /* Good packet follows */
-
-/*
- * EEPROM specification (of JLI mode).
- */
-
-/* Number of bytes in an EEPROM accessible through 86965. */
-#define FE_EEPROM_SIZE 32
-
-/* Offset for JLI config; automatically copied into BMPR19 at startup. */
-#define FE_EEPROM_CONF 0
-
-/*
- * Some 8696x specific constants.
- */
-
-/* Length (in bytes) of a Multicast Address Filter. */
-#define FE_FILTER_LEN 8
-
-/* How many packets we can put in the transmission buffer on NIC memory. */
-#define FE_QUEUEING_MAX 127
-
-/* Length (in bytes) of a "packet length" word in transmission buffer. */
-#define FE_DATA_LEN_LEN 2
-
-/* Special Multicast Address Filter value. */
-#define FE_FILTER_NOTHING { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }
-#define FE_FILTER_ALL { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF }
diff --git a/sys/dev/ic/cd1400.h b/sys/dev/ic/cd1400.h
deleted file mode 100644
index 90672c4ee7e6..000000000000
--- a/sys/dev/ic/cd1400.h
+++ /dev/null
@@ -1,203 +0,0 @@
-/*-
- * cyclades cyclom-y serial driver
- * Andrew Herbert <andrew@werple.apana.org.au>, 17 August 1993
- *
- * Copyright (c) 1993 Andrew Herbert.
- * 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 Andrew Herbert may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-/*
- * Definitions for Cirrus Logic CD1400 serial/parallel chips.
- */
-
-#define CD1400_NO_OF_CHANNELS 4 /* 4 serial channels per chip */
-#define CD1400_RX_FIFO_SIZE 12
-#define CD1400_TX_FIFO_SIZE 12
-
-/*
- * Global registers.
- */
-#define CD1400_GFRCR 0x40 /* global firmware revision code */
-#define CD1400_CAR 0x68 /* channel access */
-#define CD1400_CAR_CHAN (3<<0) /* channel select */
-#define CD1400_GCR 0x4B /* global configuration */
-#define CD1400_GCR_PARALLEL (1<<7) /* channel 0 is parallel */
-#define CD1400_SVRR 0x67 /* service request */
-#define CD1400_SVRR_MDMCH (1<<2)
-#define CD1400_SVRR_TXRDY (1<<1)
-#define CD1400_SVRR_RXRDY (1<<0)
-#define CD1400_RICR 0x44 /* receive interrupting channel */
-#define CD1400_TICR 0x45 /* transmit interrupting channel */
-#define CD1400_MICR 0x46 /* modem interrupting channel */
-#define CD1400_RIR 0x6B /* receive interrupt status */
-#define CD1400_RIR_RDIREQ (1<<7) /* rx service required */
-#define CD1400_RIR_RBUSY (1<<6) /* rx service in progress */
-#define CD1400_RIR_CHAN (3<<0) /* channel select */
-#define CD1400_TIR 0x6A /* transmit interrupt status */
-#define CD1400_TIR_RDIREQ (1<<7) /* tx service required */
-#define CD1400_TIR_RBUSY (1<<6) /* tx service in progress */
-#define CD1400_TIR_CHAN (3<<0) /* channel select */
-#define CD1400_MIR 0x69 /* modem interrupt status */
-#define CD1400_MIR_RDIREQ (1<<7) /* modem service required */
-#define CD1400_MIR_RBUSY (1<<6) /* modem service in progress */
-#define CD1400_MIR_CHAN (3<<0) /* channel select */
-#define CD1400_PPR 0x7E /* prescaler period */
-#define CD1400_PPR_PRESCALER 512
-
-/*
- * Virtual registers.
- */
-#define CD1400_RIVR 0x43 /* receive interrupt vector */
-#define CD1400_RIVR_EXCEPTION (1<<2) /* receive exception bit */
-#define CD1400_TIVR 0x42 /* transmit interrupt vector */
-#define CD1400_MIVR 0x41 /* modem interrupt vector */
-#define CD1400_TDR 0x63 /* transmit data */
-#define CD1400_RDSR 0x62 /* receive data/status */
-#define CD1400_RDSR_TIMEOUT (1<<7) /* rx timeout */
-#define CD1400_RDSR_SPECIAL_SHIFT 4 /* rx special char shift */
-#define CD1400_RDSR_SPECIAL (7<<4) /* rx special char */
-#define CD1400_RDSR_BREAK (1<<3) /* rx break */
-#define CD1400_RDSR_PE (1<<2) /* rx parity error */
-#define CD1400_RDSR_FE (1<<1) /* rx framing error */
-#define CD1400_RDSR_OE (1<<0) /* rx overrun error */
-#define CD1400_MISR 0x4C /* modem interrupt status */
-#define CD1400_MISR_DSRd (1<<7) /* DSR delta */
-#define CD1400_MISR_CTSd (1<<6) /* CTS delta */
-#define CD1400_MISR_RId (1<<5) /* RI delta */
-#define CD1400_MISR_CDd (1<<4) /* CD delta */
-#define CD1400_EOSRR 0x60 /* end of service request */
-
-/*
- * Channel registers.
- */
-#define CD1400_LIVR 0x18 /* local interrupt vector */
-#define CD1400_CCR 0x05 /* channel control */
-#define CD1400_CCR_CMDRESET (1<<7) /* enables following: */
-#define CD1400_CCR_FTF (1<<1) /* flush tx fifo */
-#define CD1400_CCR_FULLRESET (1<<0) /* full reset */
-#define CD1400_CCR_CHANRESET 0 /* current channel */
-#define CD1400_CCR_CMDCORCHG (1<<6) /* enables following: */
-#define CD1400_CCR_COR3 (1<<3) /* COR3 changed */
-#define CD1400_CCR_COR2 (1<<2) /* COR2 changed */
-#define CD1400_CCR_COR1 (1<<1) /* COR1 changed */
-#define CD1400_CCR_CMDSENDSC (1<<5) /* enables following: */
-#define CD1400_CCR_SC (7<<0) /* special char 1-4 */
-#define CD1400_CCR_CMDCHANCTL (1<<4) /* enables following: */
-#define CD1400_CCR_XMTEN (1<<3) /* tx enable */
-#define CD1400_CCR_XMTDIS (1<<2) /* tx disable */
-#define CD1400_CCR_RCVEN (1<<1) /* rx enable */
-#define CD1400_CCR_RCVDIS (1<<0) /* rx disable */
-#define CD1400_SRER 0x06 /* service request enable */
-#define CD1400_SRER_MDMCH (1<<7) /* modem change */
-#define CD1400_SRER_RXDATA (1<<4) /* rx data */
-#define CD1400_SRER_TXRDY (1<<2) /* tx fifo empty */
-#define CD1400_SRER_TXMPTY (1<<1) /* tx shift reg empty */
-#define CD1400_SRER_NNDT (1<<0) /* no new data */
-#define CD1400_COR1 0x08 /* channel option 1 */
-#define CD1400_COR1_PARODD (1<<7)
-#define CD1400_COR1_PARNORMAL (2<<5)
-#define CD1400_COR1_PARFORCE (1<<5) /* odd/even = force 1/0 */
-#define CD1400_COR1_PARNONE (0<<5)
-#define CD1400_COR1_NOINPCK (1<<4)
-#define CD1400_COR1_STOP2 (2<<2)
-#define CD1400_COR1_STOP15 (1<<2) /* 1.5 stop bits */
-#define CD1400_COR1_STOP1 (0<<2)
-#define CD1400_COR1_CS8 (3<<0)
-#define CD1400_COR1_CS7 (2<<0)
-#define CD1400_COR1_CS6 (1<<0)
-#define CD1400_COR1_CS5 (0<<0)
-#define CD1400_COR2 0x09 /* channel option 2 */
-#define CD1400_COR2_IXANY (1<<7) /* implied XON mode */
-#define CD1400_COR2_IXOFF (1<<6) /* in-band tx flow control */
-#define CD1400_COR2_ETC (1<<5) /* embedded tx command */
-#define CD1400_ETC_CMD 0x00 /* start an ETC */
-#define CD1400_ETC_SENDBREAK 0x81
-#define CD1400_ETC_INSERTDELAY 0x82
-#define CD1400_ETC_STOPBREAK 0x83
-#define CD1400_COR2_LLM (1<<4) /* local loopback mode */
-#define CD1400_COR2_RLM (1<<3) /* remote loopback mode */
-#define CD1400_COR2_RTSAO (1<<2) /* RTS auto output */
-#define CD1400_COR2_CCTS_OFLOW (1<<1) /* CTS auto enable */
-#define CD1400_COR2_CDSR_OFLOW (1<<0) /* DSR auto enable */
-#define CD1400_COR3 0x0A /* channel option 3 */
-#define CD1400_COR3_SCDRNG (1<<7) /* special char detect range */
-#define CD1400_COR3_SCD34 (1<<6) /* special char detect 3-4 */
-#define CD1400_COR3_FTC (1<<5) /* flow control transparency */
-#define CD1400_COR3_SCD12 (1<<4) /* special char detect 1-2 */
-#define CD1400_COR3_RXTH (15<<0) /* rx fifo threshold */
-#define CD1400_COR4 0x1E /* channel option 4 */
-#define CD1400_COR4_IGNCR (1<<7)
-#define CD1400_COR4_ICRNL (1<<6)
-#define CD1400_COR4_INLCR (1<<5)
-#define CD1400_COR4_IGNBRK (1<<4)
-#define CD1400_COR4_NOBRKINT (1<<3)
-#define CD1400_COR4_PFO_ESC (4<<0) /* parity/framing/overrun... */
-#define CD1400_COR4_PFO_NUL (3<<0)
-#define CD1400_COR4_PFO_DISCARD (2<<0)
-#define CD1400_COR4_PFO_GOOD (1<<0)
-#define CD1400_COR4_PFO_EXCEPTION (0<<0)
-#define CD1400_COR5 0x1F /* channel option 5 */
-#define CD1400_COR5_ISTRIP (1<<7)
-#define CD1400_COR5_LNEXT (1<<6)
-#define CD1400_COR5_CMOE (1<<5) /* char matching on error */
-#define CD1400_COR5_EBD (1<<2) /* end of break detected */
-#define CD1400_COR5_ONLCR (1<<1)
-#define CD1400_COR5_OCRNL (1<<0)
-#define CD1400_CCSR 0x0B /* channel control status */
-#define CD1400_RDCR 0x0E /* received data count */
-#define CD1400_SCHR1 0x1A /* special character 1 */
-#define CD1400_SCHR2 0x1B /* special character 2 */
-#define CD1400_SCHR3 0x1C /* special character 3 */
-#define CD1400_SCHR4 0x1D /* special character 4 */
-#define CD1400_SCRL 0x22 /* special character range, low */
-#define CD1400_SCRH 0x23 /* special character range, high */
-#define CD1400_LNC 0x24 /* lnext character */
-#define CD1400_MCOR1 0x15 /* modem change option 1 */
-#define CD1400_MCOR1_DSRzd (1<<7) /* DSR one-to-zero delta */
-#define CD1400_MCOR1_CTSzd (1<<6)
-#define CD1400_MCOR1_RIzd (1<<5)
-#define CD1400_MCOR1_CDzd (1<<4)
-#define CD1400_MCOR1_DTRth (15<<0) /* dtrflow threshold */
-#define CD1400_MCOR2 0x16 /* modem change option 2 */
-#define CD1400_MCOR2_DSRod (1<<7) /* DSR zero-to-one delta */
-#define CD1400_MCOR2_CTSod (1<<6)
-#define CD1400_MCOR2_RIod (1<<5)
-#define CD1400_MCOR2_CDod (1<<4)
-#define CD1400_RTPR 0x21 /* receive timeout period */
-#define CD1400_MSVR1 0x6C /* modem signal value 1 */
-#define CD1400_MSVR1_RTS (1<<0) /* RTS line (r/w) */
-#define CD1400_MSVR2 0x6D /* modem signal value 2 */
-#define CD1400_MSVR2_DSR (1<<7) /* !DSR line (r) */
-#define CD1400_MSVR2_CTS (1<<6) /* !CTS line (r) */
-#define CD1400_MSVR2_RI (1<<5) /* !RI line (r) */
-#define CD1400_MSVR2_CD (1<<4) /* !CD line (r) */
-#define CD1400_MSVR2_DTR (1<<1) /* DTR line (r/w) */
-#define CD1400_PSVR 0x6F /* printer signal value */
-#define CD1400_RBPR 0x78 /* receive baud rate period */
-#define CD1400_RCOR 0x7C /* receive clock option */
-#define CD1400_TBPR 0x72 /* transmit baud rate period */
-#define CD1400_TCOR 0x76 /* transmit clock option */
diff --git a/sys/dev/mc146818/mc146818reg.h b/sys/dev/mc146818/mc146818reg.h
deleted file mode 100644
index e60d043f13dd..000000000000
--- a/sys/dev/mc146818/mc146818reg.h
+++ /dev/null
@@ -1,187 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD: mc146818reg.h,v 1.2 1997/03/12 06:53:42 cgd Exp $ */
-
-/*
- * Copyright (c) 1995 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-/*
- * Definitions for the Motorola MC146818A Real Time Clock.
- * They also apply for the (compatible) Dallas Semicontuctor DS1287A RTC.
- *
- * Though there are undoubtedly other (better) sources, this material was
- * culled from the DEC "KN121 System Module Programmer's Reference
- * Information."
- *
- * The MC146818A has 16 registers. The first 10 contain time-of-year
- * and alarm data. The rest contain various control and status bits.
- *
- * To read or write the registers, one writes the register number to
- * the RTC's control port, then either reads from or writes the new
- * data to the RTC's data port. Since the locations of these ports
- * and the method used to access them can be machine-dependent, the
- * low-level details of reading and writing the RTC's registers are
- * handled by machine-specific functions.
- *
- * The time-of-year and alarm data can be expressed in either binary
- * or BCD, and they are selected by a bit in register B.
- *
- * The "hour" time-of-year and alarm fields can either be expressed in
- * AM/PM format, or in 24-hour format. If AM/PM format is chosen, the
- * hour fields can have the values: 1-12 and 81-92 (the latter being
- * PM). If the 24-hour format is chosen, they can have the values
- * 0-24. The hour format is selectable by a bit in register B.
- * (XXX IS AM/PM MODE DESCRIPTION CORRECT?)
- *
- * It is assumed the if systems are going to use BCD (rather than
- * binary) mode, or AM/PM hour format, they'll do the appropriate
- * conversions in machine-dependent code. Also, if the clock is
- * switched between BCD and binary mode, or between AM/PM mode and
- * 24-hour mode, the time-of-day and alarm registers are NOT
- * automatically reset; they must be reprogrammed with correct values.
- */
-
-/*
- * The registers, and the bits within each register.
- */
-
-#define MC_SEC 0x0 /* Time of year: seconds (0-59) */
-#define MC_ASEC 0x1 /* Alarm: seconds */
-#define MC_MIN 0x2 /* Time of year: minutes (0-59) */
-#define MC_AMIN 0x3 /* Alarm: minutes */
-#define MC_HOUR 0x4 /* Time of year: hour (see above) */
-#define MC_AHOUR 0x5 /* Alarm: hour */
-#define MC_DOW 0x6 /* Time of year: day of week (1-7) */
-#define MC_DOM 0x7 /* Time of year: day of month (1-31) */
-#define MC_MONTH 0x8 /* Time of year: month (1-12) */
-#define MC_YEAR 0x9 /* Time of year: year in century (0-99) */
-
-#define MC_REGA 0xa /* Control register A */
-
-#define MC_REGA_RSMASK 0x0f /* Interrupt rate select mask (see below) */
-#define MC_REGA_DVMASK 0x70 /* Divisor select mask (see below) */
-#define MC_REGA_UIP 0x80 /* Update in progress; read only. */
-
-#define MC_REGB 0xb /* Control register B */
-
-#define MC_REGB_DSE 0x01 /* Daylight Savings Enable */
-#define MC_REGB_24HR 0x02 /* 24-hour mode (AM/PM mode when clear) */
-#define MC_REGB_BINARY 0x04 /* Binary mode (BCD mode when clear) */
-#define MC_REGB_SQWE 0x08 /* Square Wave Enable */
-#define MC_REGB_UIE 0x10 /* Update End interrupt enable */
-#define MC_REGB_AIE 0x20 /* Alarm interrupt enable */
-#define MC_REGB_PIE 0x40 /* Periodic interrupt enable */
-#define MC_REGB_SET 0x80 /* Allow time to be set; stops updates */
-
-#define MC_REGC 0xc /* Control register C */
-
-/* MC_REGC_UNUSED 0x0f UNUSED */
-#define MC_REGC_UF 0x10 /* Update End interrupt flag */
-#define MC_REGC_AF 0x20 /* Alarm interrupt flag */
-#define MC_REGC_PF 0x40 /* Periodic interrupt flag */
-#define MC_REGC_IRQF 0x80 /* Interrupt request pending flag */
-
-#define MC_REGD 0xd /* Control register D */
-
-/* MC_REGD_UNUSED 0x7f UNUSED */
-#define MC_REGD_VRT 0x80 /* Valid RAM and Time bit */
-
-
-#define MC_NREGS 0xe /* 14 registers; CMOS follows */
-#define MC_NTODREGS 0xa /* 10 of those regs are for TOD and alarm */
-
-#define MC_NVRAM_START 0xe /* start of NVRAM: offset 14 */
-#define MC_NVRAM_SIZE 50 /* 50 bytes of NVRAM */
-
-/*
- * Periodic Interrupt Rate Select constants (Control register A)
- */
-#define MC_RATE_NONE 0x0 /* No periodic interrupt */
-#define MC_RATE_1 0x1 /* 256 Hz if MC_BASE_32_KHz, else 32768 Hz */
-#define MC_RATE_2 0x2 /* 128 Hz if MC_BASE_32_KHz, else 16384 Hz */
-#define MC_RATE_8192_Hz 0x3 /* 122.070 us period */
-#define MC_RATE_4096_Hz 0x4 /* 244.141 us period */
-#define MC_RATE_2048_Hz 0x5 /* 488.281 us period */
-#define MC_RATE_1024_Hz 0x6 /* 976.562 us period */
-#define MC_RATE_512_Hz 0x7 /* 1.953125 ms period */
-#define MC_RATE_256_Hz 0x8 /* 3.90625 ms period */
-#define MC_RATE_128_Hz 0x9 /* 7.8125 ms period */
-#define MC_RATE_64_Hz 0xa /* 15.625 ms period */
-#define MC_RATE_32_Hz 0xb /* 31.25 ms period */
-#define MC_RATE_16_Hz 0xc /* 62.5 ms period */
-#define MC_RATE_8_Hz 0xd /* 125 ms period */
-#define MC_RATE_4_Hz 0xe /* 250 ms period */
-#define MC_RATE_2_Hz 0xf /* 500 ms period */
-
-/*
- * Time base (divisor select) constants (Control register A)
- */
-#define MC_BASE_4_MHz 0x00 /* 4MHz crystal */
-#define MC_BASE_1_MHz 0x10 /* 1MHz crystal */
-#define MC_BASE_32_KHz 0x20 /* 32KHz crystal */
-#define MC_BASE_NONE 0x60 /* actually, both of these reset */
-#define MC_BASE_RESET 0x70
-
-/*
- * A collection of TOD/Alarm registers.
- */
-typedef u_int mc_todregs[MC_NTODREGS];
-
-/*
- * Get all of the TOD/Alarm registers
- * Must be called at splhigh(), and with the RTC properly set up.
- */
-#define MC146818_GETTOD(dev, regs) \
- do { \
- int i; \
- \
- /* update in progress; spin loop */ \
- while (MCCLOCK_READ(dev, MC_REGA) & MC_REGA_UIP) \
- ; \
- \
- /* read all of the tod/alarm regs */ \
- for (i = 0; i < MC_NTODREGS; i++) \
- (*regs)[i] = MCCLOCK_READ(dev, i); \
- } while (0);
-
-/*
- * Set all of the TOD/Alarm registers
- * Must be called at splhigh(), and with the RTC properly set up.
- */
-#define MC146818_PUTTOD(dev, regs) \
- do { \
- int i; \
- \
- /* stop updates while setting */ \
- MCCLOCK_WRITE(dev, MC_REGB, \
- MCCLOCK_READ(dev, MC_REGB) | MC_REGB_SET); \
- \
- /* write all of the tod/alarm regs */ \
- for (i = 0; i < MC_NTODREGS; i++) \
- MCCLOCK_WRITE(dev, i, (*regs)[i]); \
- \
- /* reenable updates */ \
- MCCLOCK_WRITE(dev, MC_REGB, \
- MCCLOCK_READ(dev, MC_REGB) & ~MC_REGB_SET); \
- } while (0);
diff --git a/sys/dev/mse/mse.c b/sys/dev/mse/mse.c
deleted file mode 100644
index 57b0e7b1f15c..000000000000
--- a/sys/dev/mse/mse.c
+++ /dev/null
@@ -1,915 +0,0 @@
-/*
- * Copyright 1992 by the University of Guelph
- *
- * Permission to use, copy and modify this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation.
- * University of Guelph makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * $FreeBSD$
- */
-/*
- * Driver for the Logitech and ATI Inport Bus mice for use with 386bsd and
- * the X386 port, courtesy of
- * Rick Macklem, rick@snowhite.cis.uoguelph.ca
- * Caveats: The driver currently uses spltty(), but doesn't use any
- * generic tty code. It could use splmse() (that only masks off the
- * bus mouse interrupt, but that would require hacking in i386/isa/icu.s.
- * (This may be worth the effort, since the Logitech generates 30/60
- * interrupts/sec continuously while it is open.)
- * NB: The ATI has NOT been tested yet!
- */
-
-/*
- * Modification history:
- * Sep 6, 1994 -- Lars Fredriksen(fredriks@mcs.com)
- * improved probe based on input from Logitech.
- *
- * Oct 19, 1992 -- E. Stark (stark@cs.sunysb.edu)
- * fixes to make it work with Microsoft InPort busmouse
- *
- * Jan, 1993 -- E. Stark (stark@cs.sunysb.edu)
- * added patches for new "select" interface
- *
- * May 4, 1993 -- E. Stark (stark@cs.sunysb.edu)
- * changed position of some spl()'s in mseread
- *
- * October 8, 1993 -- E. Stark (stark@cs.sunysb.edu)
- * limit maximum negative x/y value to -127 to work around XFree problem
- * that causes spurious button pushes.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/conf.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/poll.h>
-#include <sys/selinfo.h>
-#include <sys/uio.h>
-#include <sys/mouse.h>
-
-#include <machine/bus_pio.h>
-#include <machine/bus.h>
-#include <machine/clock.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-#include <isa/isavar.h>
-
-/* driver configuration flags (config) */
-#define MSE_CONFIG_ACCEL 0x00f0 /* acceleration factor */
-#define MSE_CONFIG_FLAGS (MSE_CONFIG_ACCEL)
-
-/*
- * Software control structure for mouse. The sc_enablemouse(),
- * sc_disablemouse() and sc_getmouse() routines must be called spl'd().
- */
-typedef struct mse_softc {
- int sc_flags;
- int sc_mousetype;
- struct selinfo sc_selp;
- struct resource *sc_port;
- struct resource *sc_intr;
- bus_space_tag_t sc_iot;
- bus_space_handle_t sc_ioh;
- void *sc_ih;
- void (*sc_enablemouse)(bus_space_tag_t t,
- bus_space_handle_t h);
- void (*sc_disablemouse)(bus_space_tag_t t,
- bus_space_handle_t h);
- void (*sc_getmouse)(bus_space_tag_t t, bus_space_handle_t h,
- int *dx, int *dy, int *but);
- int sc_deltax;
- int sc_deltay;
- int sc_obuttons;
- int sc_buttons;
- int sc_bytesread;
- u_char sc_bytes[MOUSE_SYS_PACKETSIZE];
- struct callout_handle sc_callout;
- int sc_watchdog;
- dev_t sc_dev;
- dev_t sc_ndev;
- mousehw_t hw;
- mousemode_t mode;
- mousestatus_t status;
-} mse_softc_t;
-
-static devclass_t mse_devclass;
-
-static int mse_probe(device_t dev);
-static int mse_attach(device_t dev);
-static int mse_detach(device_t dev);
-
-static device_method_t mse_methods[] = {
- DEVMETHOD(device_probe, mse_probe),
- DEVMETHOD(device_attach, mse_attach),
- DEVMETHOD(device_detach, mse_detach),
- { 0, 0 }
-};
-
-static driver_t mse_driver = {
- "mse",
- mse_methods,
- sizeof(mse_softc_t),
-};
-
-DRIVER_MODULE(mse, isa, mse_driver, mse_devclass, 0, 0);
-
-static struct isa_pnp_id mse_ids[] = {
- { 0x000fd041, "Bus mouse" }, /* PNP0F00 */
- { 0x020fd041, "InPort mouse" }, /* PNP0F02 */
- { 0x0d0fd041, "InPort mouse compatible" }, /* PNP0F0D */
- { 0x110fd041, "Bus mouse compatible" }, /* PNP0F11 */
- { 0x150fd041, "Logitech bus mouse" }, /* PNP0F15 */
- { 0x180fd041, "Logitech bus mouse compatible" },/* PNP0F18 */
- { 0 }
-};
-
-static d_open_t mseopen;
-static d_close_t mseclose;
-static d_read_t mseread;
-static d_ioctl_t mseioctl;
-static d_poll_t msepoll;
-
-#define CDEV_MAJOR 27
-static struct cdevsw mse_cdevsw = {
- .d_open = mseopen,
- .d_close = mseclose,
- .d_read = mseread,
- .d_ioctl = mseioctl,
- .d_poll = msepoll,
- .d_name = "mse",
- .d_maj = CDEV_MAJOR,
-};
-
-static void mseintr(void *);
-static timeout_t msetimeout;
-
-/* Flags */
-#define MSESC_OPEN 0x1
-#define MSESC_WANT 0x2
-
-/* and Mouse Types */
-#define MSE_NONE 0 /* don't move this! */
-#define MSE_LOGITECH 0x1
-#define MSE_ATIINPORT 0x2
-#define MSE_LOGI_SIG 0xA5
-
-#define MSE_PORTA 0
-#define MSE_PORTB 1
-#define MSE_PORTC 2
-#define MSE_PORTD 3
-#define MSE_IOSIZE 4
-
-#define MSE_UNIT(dev) (minor(dev) >> 1)
-#define MSE_NBLOCKIO(dev) (minor(dev) & 0x1)
-
-/*
- * Logitech bus mouse definitions
- */
-#define MSE_SETUP 0x91 /* What does this mean? */
- /* The definition for the control port */
- /* is as follows: */
-
- /* D7 = Mode set flag (1 = active) */
- /* D6,D5 = Mode selection (port A) */
- /* 00 = Mode 0 = Basic I/O */
- /* 01 = Mode 1 = Strobed I/O */
- /* 10 = Mode 2 = Bi-dir bus */
- /* D4 = Port A direction (1 = input)*/
- /* D3 = Port C (upper 4 bits) */
- /* direction. (1 = input) */
- /* D2 = Mode selection (port B & C) */
- /* 0 = Mode 0 = Basic I/O */
- /* 1 = Mode 1 = Strobed I/O */
- /* D1 = Port B direction (1 = input)*/
- /* D0 = Port C (lower 4 bits) */
- /* direction. (1 = input) */
-
- /* So 91 means Basic I/O on all 3 ports,*/
- /* Port A is an input port, B is an */
- /* output port, C is split with upper */
- /* 4 bits being an output port and lower*/
- /* 4 bits an input port, and enable the */
- /* sucker. */
- /* Courtesy Intel 8255 databook. Lars */
-#define MSE_HOLD 0x80
-#define MSE_RXLOW 0x00
-#define MSE_RXHIGH 0x20
-#define MSE_RYLOW 0x40
-#define MSE_RYHIGH 0x60
-#define MSE_DISINTR 0x10
-#define MSE_INTREN 0x00
-
-static int mse_probelogi(device_t dev, mse_softc_t *sc);
-static void mse_disablelogi(bus_space_tag_t t,
- bus_space_handle_t h);
-static void mse_getlogi(bus_space_tag_t t, bus_space_handle_t h,
- int *dx, int *dy, int *but);
-static void mse_enablelogi(bus_space_tag_t t,
- bus_space_handle_t h);
-
-/*
- * ATI Inport mouse definitions
- */
-#define MSE_INPORT_RESET 0x80
-#define MSE_INPORT_STATUS 0x00
-#define MSE_INPORT_DX 0x01
-#define MSE_INPORT_DY 0x02
-#define MSE_INPORT_MODE 0x07
-#define MSE_INPORT_HOLD 0x20
-#define MSE_INPORT_INTREN 0x09
-
-static int mse_probeati(device_t dev, mse_softc_t *sc);
-static void mse_enableati(bus_space_tag_t t, bus_space_handle_t h);
-static void mse_disableati(bus_space_tag_t t, bus_space_handle_t h);
-static void mse_getati(bus_space_tag_t t, bus_space_handle_t h,
- int *dx, int *dy, int *but);
-
-#define MSEPRI (PZERO + 3)
-
-/*
- * Table of mouse types.
- * Keep the Logitech last, since I haven't figured out how to probe it
- * properly yet. (Someday I'll have the documentation.)
- */
-static struct mse_types {
- int m_type; /* Type of bus mouse */
- int (*m_probe)(device_t dev, mse_softc_t *sc);
- /* Probe routine to test for it */
- void (*m_enable)(bus_space_tag_t t, bus_space_handle_t h);
- /* Start routine */
- void (*m_disable)(bus_space_tag_t t, bus_space_handle_t h);
- /* Disable interrupts routine */
- void (*m_get)(bus_space_tag_t t, bus_space_handle_t h, int *dx,
- int *dy, int *but);
- /* and get mouse status */
- mousehw_t m_hw; /* buttons iftype type model hwid */
- mousemode_t m_mode; /* proto rate res accel level size mask */
-} mse_types[] = {
- { MSE_ATIINPORT,
- mse_probeati, mse_enableati, mse_disableati, mse_getati,
- { 2, MOUSE_IF_INPORT, MOUSE_MOUSE, MOUSE_MODEL_GENERIC, 0, },
- { MOUSE_PROTO_INPORT, -1, -1, 0, 0, MOUSE_MSC_PACKETSIZE,
- { MOUSE_MSC_SYNCMASK, MOUSE_MSC_SYNC, }, }, },
- { MSE_LOGITECH,
- mse_probelogi, mse_enablelogi, mse_disablelogi, mse_getlogi,
- { 2, MOUSE_IF_BUS, MOUSE_MOUSE, MOUSE_MODEL_GENERIC, 0, },
- { MOUSE_PROTO_BUS, -1, -1, 0, 0, MOUSE_MSC_PACKETSIZE,
- { MOUSE_MSC_SYNCMASK, MOUSE_MSC_SYNC, }, }, },
- { 0, },
-};
-
-static int
-mse_probe(dev)
- device_t dev;
-{
- mse_softc_t *sc;
- int error;
- int rid;
- int i;
-
- /* check PnP IDs */
- error = ISA_PNP_PROBE(device_get_parent(dev), dev, mse_ids);
- if (error == ENXIO)
- return error;
-
- sc = device_get_softc(dev);
- rid = 0;
- sc->sc_port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
- MSE_IOSIZE, RF_ACTIVE);
- if (sc->sc_port == NULL)
- return ENXIO;
- sc->sc_iot = rman_get_bustag(sc->sc_port);
- sc->sc_ioh = rman_get_bushandle(sc->sc_port);
-
- /*
- * Check for each mouse type in the table.
- */
- i = 0;
- while (mse_types[i].m_type) {
- if ((*mse_types[i].m_probe)(dev, sc)) {
- sc->sc_mousetype = mse_types[i].m_type;
- sc->sc_enablemouse = mse_types[i].m_enable;
- sc->sc_disablemouse = mse_types[i].m_disable;
- sc->sc_getmouse = mse_types[i].m_get;
- sc->hw = mse_types[i].m_hw;
- sc->mode = mse_types[i].m_mode;
- bus_release_resource(dev, SYS_RES_IOPORT, rid,
- sc->sc_port);
- device_set_desc(dev, "Bus/InPort Mouse");
- return 0;
- }
- i++;
- }
- bus_release_resource(dev, SYS_RES_IOPORT, rid, sc->sc_port);
- return ENXIO;
-}
-
-static int
-mse_attach(dev)
- device_t dev;
-{
- mse_softc_t *sc;
- int flags;
- int unit;
- int rid;
-
- sc = device_get_softc(dev);
- unit = device_get_unit(dev);
-
- rid = 0;
- sc->sc_port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
- MSE_IOSIZE, RF_ACTIVE);
- if (sc->sc_port == NULL)
- return ENXIO;
- sc->sc_intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_ACTIVE);
- if (sc->sc_intr == NULL) {
- bus_release_resource(dev, SYS_RES_IOPORT, rid, sc->sc_port);
- return ENXIO;
- }
- sc->sc_iot = rman_get_bustag(sc->sc_port);
- sc->sc_ioh = rman_get_bushandle(sc->sc_port);
-
- if (BUS_SETUP_INTR(device_get_parent(dev), dev, sc->sc_intr,
- INTR_TYPE_TTY, mseintr, sc, &sc->sc_ih)) {
- bus_release_resource(dev, SYS_RES_IOPORT, rid, sc->sc_port);
- bus_release_resource(dev, SYS_RES_IRQ, rid, sc->sc_intr);
- return ENXIO;
- }
-
- flags = device_get_flags(dev);
- sc->mode.accelfactor = (flags & MSE_CONFIG_ACCEL) >> 4;
- callout_handle_init(&sc->sc_callout);
-
- sc->sc_dev = make_dev(&mse_cdevsw, unit << 1, 0, 0, 0600,
- "mse%d", unit);
- sc->sc_ndev = make_dev(&mse_cdevsw, (unit<<1)+1, 0, 0, 0600,
- "nmse%d", unit);
-
- return 0;
-}
-
-static int
-mse_detach(dev)
- device_t dev;
-{
- mse_softc_t *sc;
- int rid;
-
- sc = device_get_softc(dev);
- if (sc->sc_flags & MSESC_OPEN)
- return EBUSY;
-
- rid = 0;
- BUS_TEARDOWN_INTR(device_get_parent(dev), dev, sc->sc_intr, sc->sc_ih);
- bus_release_resource(dev, SYS_RES_IRQ, rid, sc->sc_intr);
- bus_release_resource(dev, SYS_RES_IOPORT, rid, sc->sc_port);
-
- destroy_dev(sc->sc_dev);
- destroy_dev(sc->sc_ndev);
-
- return 0;
-}
-
-/*
- * Exclusive open the mouse, initialize it and enable interrupts.
- */
-static int
-mseopen(dev, flags, fmt, td)
- dev_t dev;
- int flags;
- int fmt;
- struct thread *td;
-{
- mse_softc_t *sc;
- int s;
-
- sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
- if (sc == NULL)
- return (ENXIO);
- if (sc->sc_mousetype == MSE_NONE)
- return (ENXIO);
- if (sc->sc_flags & MSESC_OPEN)
- return (EBUSY);
- sc->sc_flags |= MSESC_OPEN;
- sc->sc_obuttons = sc->sc_buttons = MOUSE_MSC_BUTTONS;
- sc->sc_deltax = sc->sc_deltay = 0;
- sc->sc_bytesread = sc->mode.packetsize = MOUSE_MSC_PACKETSIZE;
- sc->sc_watchdog = FALSE;
- sc->sc_callout = timeout(msetimeout, dev, hz*2);
- sc->mode.level = 0;
- sc->status.flags = 0;
- sc->status.button = sc->status.obutton = 0;
- sc->status.dx = sc->status.dy = sc->status.dz = 0;
-
- /*
- * Initialize mouse interface and enable interrupts.
- */
- s = spltty();
- (*sc->sc_enablemouse)(sc->sc_iot, sc->sc_ioh);
- splx(s);
- return (0);
-}
-
-/*
- * mseclose: just turn off mouse innterrupts.
- */
-static int
-mseclose(dev, flags, fmt, td)
- dev_t dev;
- int flags;
- int fmt;
- struct thread *td;
-{
- mse_softc_t *sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
- int s;
-
- untimeout(msetimeout, dev, sc->sc_callout);
- callout_handle_init(&sc->sc_callout);
- s = spltty();
- (*sc->sc_disablemouse)(sc->sc_iot, sc->sc_ioh);
- sc->sc_flags &= ~MSESC_OPEN;
- splx(s);
- return(0);
-}
-
-/*
- * mseread: return mouse info using the MSC serial protocol, but without
- * using bytes 4 and 5.
- * (Yes this is cheesy, but it makes the X386 server happy, so...)
- */
-static int
-mseread(dev, uio, ioflag)
- dev_t dev;
- struct uio *uio;
- int ioflag;
-{
- mse_softc_t *sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
- int xfer, s, error;
-
- /*
- * If there are no protocol bytes to be read, set up a new protocol
- * packet.
- */
- s = spltty(); /* XXX Should be its own spl, but where is imlXX() */
- if (sc->sc_bytesread >= sc->mode.packetsize) {
- while (sc->sc_deltax == 0 && sc->sc_deltay == 0 &&
- (sc->sc_obuttons ^ sc->sc_buttons) == 0) {
- if (MSE_NBLOCKIO(dev)) {
- splx(s);
- return (0);
- }
- sc->sc_flags |= MSESC_WANT;
- error = tsleep(sc, MSEPRI | PCATCH,
- "mseread", 0);
- if (error) {
- splx(s);
- return (error);
- }
- }
-
- /*
- * Generate protocol bytes.
- * For some reason X386 expects 5 bytes but never uses
- * the fourth or fifth?
- */
- sc->sc_bytes[0] = sc->mode.syncmask[1]
- | (sc->sc_buttons & ~sc->mode.syncmask[0]);
- if (sc->sc_deltax > 127)
- sc->sc_deltax = 127;
- if (sc->sc_deltax < -127)
- sc->sc_deltax = -127;
- sc->sc_deltay = -sc->sc_deltay; /* Otherwise mousey goes wrong way */
- if (sc->sc_deltay > 127)
- sc->sc_deltay = 127;
- if (sc->sc_deltay < -127)
- sc->sc_deltay = -127;
- sc->sc_bytes[1] = sc->sc_deltax;
- sc->sc_bytes[2] = sc->sc_deltay;
- sc->sc_bytes[3] = sc->sc_bytes[4] = 0;
- sc->sc_bytes[5] = sc->sc_bytes[6] = 0;
- sc->sc_bytes[7] = MOUSE_SYS_EXTBUTTONS;
- sc->sc_obuttons = sc->sc_buttons;
- sc->sc_deltax = sc->sc_deltay = 0;
- sc->sc_bytesread = 0;
- }
- splx(s);
- xfer = min(uio->uio_resid, sc->mode.packetsize - sc->sc_bytesread);
- error = uiomove(&sc->sc_bytes[sc->sc_bytesread], xfer, uio);
- if (error)
- return (error);
- sc->sc_bytesread += xfer;
- return(0);
-}
-
-/*
- * mseioctl: process ioctl commands.
- */
-static int
-mseioctl(dev, cmd, addr, flag, td)
- dev_t dev;
- u_long cmd;
- caddr_t addr;
- int flag;
- struct thread *td;
-{
- mse_softc_t *sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
- mousestatus_t status;
- int err = 0;
- int s;
-
- switch (cmd) {
-
- case MOUSE_GETHWINFO:
- s = spltty();
- *(mousehw_t *)addr = sc->hw;
- if (sc->mode.level == 0)
- ((mousehw_t *)addr)->model = MOUSE_MODEL_GENERIC;
- splx(s);
- break;
-
- case MOUSE_GETMODE:
- s = spltty();
- *(mousemode_t *)addr = sc->mode;
- switch (sc->mode.level) {
- case 0:
- break;
- case 1:
- ((mousemode_t *)addr)->protocol = MOUSE_PROTO_SYSMOUSE;
- ((mousemode_t *)addr)->syncmask[0] = MOUSE_SYS_SYNCMASK;
- ((mousemode_t *)addr)->syncmask[1] = MOUSE_SYS_SYNC;
- break;
- }
- splx(s);
- break;
-
- case MOUSE_SETMODE:
- switch (((mousemode_t *)addr)->level) {
- case 0:
- case 1:
- break;
- default:
- return (EINVAL);
- }
- if (((mousemode_t *)addr)->accelfactor < -1)
- return (EINVAL);
- else if (((mousemode_t *)addr)->accelfactor >= 0)
- sc->mode.accelfactor =
- ((mousemode_t *)addr)->accelfactor;
- sc->mode.level = ((mousemode_t *)addr)->level;
- switch (sc->mode.level) {
- case 0:
- sc->sc_bytesread = sc->mode.packetsize
- = MOUSE_MSC_PACKETSIZE;
- break;
- case 1:
- sc->sc_bytesread = sc->mode.packetsize
- = MOUSE_SYS_PACKETSIZE;
- break;
- }
- break;
-
- case MOUSE_GETLEVEL:
- *(int *)addr = sc->mode.level;
- break;
-
- case MOUSE_SETLEVEL:
- switch (*(int *)addr) {
- case 0:
- sc->mode.level = *(int *)addr;
- sc->sc_bytesread = sc->mode.packetsize
- = MOUSE_MSC_PACKETSIZE;
- break;
- case 1:
- sc->mode.level = *(int *)addr;
- sc->sc_bytesread = sc->mode.packetsize
- = MOUSE_SYS_PACKETSIZE;
- break;
- default:
- return (EINVAL);
- }
- break;
-
- case MOUSE_GETSTATUS:
- s = spltty();
- status = sc->status;
- sc->status.flags = 0;
- sc->status.obutton = sc->status.button;
- sc->status.button = 0;
- sc->status.dx = 0;
- sc->status.dy = 0;
- sc->status.dz = 0;
- splx(s);
- *(mousestatus_t *)addr = status;
- break;
-
- case MOUSE_READSTATE:
- case MOUSE_READDATA:
- return (ENODEV);
-
-#if (defined(MOUSE_GETVARS))
- case MOUSE_GETVARS:
- case MOUSE_SETVARS:
- return (ENODEV);
-#endif
-
- default:
- return (ENOTTY);
- }
- return (err);
-}
-
-/*
- * msepoll: check for mouse input to be processed.
- */
-static int
-msepoll(dev, events, td)
- dev_t dev;
- int events;
- struct thread *td;
-{
- mse_softc_t *sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
- int s;
- int revents = 0;
-
- s = spltty();
- if (events & (POLLIN | POLLRDNORM)) {
- if (sc->sc_bytesread != sc->mode.packetsize ||
- sc->sc_deltax != 0 || sc->sc_deltay != 0 ||
- (sc->sc_obuttons ^ sc->sc_buttons) != 0)
- revents |= events & (POLLIN | POLLRDNORM);
- else {
- /*
- * Since this is an exclusive open device, any previous
- * proc pointer is trash now, so we can just assign it.
- */
- selrecord(td, &sc->sc_selp);
- }
- }
- splx(s);
- return (revents);
-}
-
-/*
- * msetimeout: watchdog timer routine.
- */
-static void
-msetimeout(arg)
- void *arg;
-{
- dev_t dev;
- mse_softc_t *sc;
-
- dev = (dev_t)arg;
- sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
- if (sc->sc_watchdog) {
- if (bootverbose)
- printf("mse%d: lost interrupt?\n", MSE_UNIT(dev));
- mseintr(sc);
- }
- sc->sc_watchdog = TRUE;
- sc->sc_callout = timeout(msetimeout, dev, hz);
-}
-
-/*
- * mseintr: update mouse status. sc_deltax and sc_deltay are accumulative.
- */
-static void
-mseintr(arg)
- void *arg;
-{
- /*
- * the table to turn MouseSystem button bits (MOUSE_MSC_BUTTON?UP)
- * into `mousestatus' button bits (MOUSE_BUTTON?DOWN).
- */
- static int butmap[8] = {
- 0,
- MOUSE_BUTTON3DOWN,
- MOUSE_BUTTON2DOWN,
- MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN,
- MOUSE_BUTTON1DOWN,
- MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN,
- MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN,
- MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN
- };
- mse_softc_t *sc = arg;
- int dx, dy, but;
- int sign;
-
-#ifdef DEBUG
- static int mse_intrcnt = 0;
- if((mse_intrcnt++ % 10000) == 0)
- printf("mseintr\n");
-#endif /* DEBUG */
- if ((sc->sc_flags & MSESC_OPEN) == 0)
- return;
-
- (*sc->sc_getmouse)(sc->sc_iot, sc->sc_ioh, &dx, &dy, &but);
- if (sc->mode.accelfactor > 0) {
- sign = (dx < 0);
- dx = dx * dx / sc->mode.accelfactor;
- if (dx == 0)
- dx = 1;
- if (sign)
- dx = -dx;
- sign = (dy < 0);
- dy = dy * dy / sc->mode.accelfactor;
- if (dy == 0)
- dy = 1;
- if (sign)
- dy = -dy;
- }
- sc->sc_deltax += dx;
- sc->sc_deltay += dy;
- sc->sc_buttons = but;
-
- but = butmap[~but & MOUSE_MSC_BUTTONS];
- sc->status.dx += dx;
- sc->status.dy += dy;
- sc->status.flags |= ((dx || dy) ? MOUSE_POSCHANGED : 0)
- | (sc->status.button ^ but);
- sc->status.button = but;
-
- sc->sc_watchdog = FALSE;
-
- /*
- * If mouse state has changed, wake up anyone wanting to know.
- */
- if (sc->sc_deltax != 0 || sc->sc_deltay != 0 ||
- (sc->sc_obuttons ^ sc->sc_buttons) != 0) {
- if (sc->sc_flags & MSESC_WANT) {
- sc->sc_flags &= ~MSESC_WANT;
- wakeup(sc);
- }
- selwakeup(&sc->sc_selp);
- }
-}
-
-/*
- * Routines for the Logitech mouse.
- */
-/*
- * Test for a Logitech bus mouse and return 1 if it is.
- * (until I know how to use the signature port properly, just disable
- * interrupts and return 1)
- */
-static int
-mse_probelogi(dev, sc)
- device_t dev;
- mse_softc_t *sc;
-{
-
- int sig;
-
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSE_PORTD, MSE_SETUP);
- /* set the signature port */
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSE_PORTB, MSE_LOGI_SIG);
-
- DELAY(30000); /* 30 ms delay */
- sig = bus_space_read_1(sc->sc_iot, sc->sc_ioh, MSE_PORTB) & 0xFF;
- if (sig == MSE_LOGI_SIG) {
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSE_PORTC,
- MSE_DISINTR);
- return(1);
- } else {
- if (bootverbose)
- device_printf(dev, "wrong signature %x\n", sig);
- return(0);
- }
-}
-
-/*
- * Initialize Logitech mouse and enable interrupts.
- */
-static void
-mse_enablelogi(tag, handle)
- bus_space_tag_t tag;
- bus_space_handle_t handle;
-{
- int dx, dy, but;
-
- bus_space_write_1(tag, handle, MSE_PORTD, MSE_SETUP);
- mse_getlogi(tag, handle, &dx, &dy, &but);
-}
-
-/*
- * Disable interrupts for Logitech mouse.
- */
-static void
-mse_disablelogi(tag, handle)
- bus_space_tag_t tag;
- bus_space_handle_t handle;
-{
-
- bus_space_write_1(tag, handle, MSE_PORTC, MSE_DISINTR);
-}
-
-/*
- * Get the current dx, dy and button up/down state.
- */
-static void
-mse_getlogi(tag, handle, dx, dy, but)
- bus_space_tag_t tag;
- bus_space_handle_t handle;
- int *dx;
- int *dy;
- int *but;
-{
- register char x, y;
-
- bus_space_write_1(tag, handle, MSE_PORTC, MSE_HOLD | MSE_RXLOW);
- x = bus_space_read_1(tag, handle, MSE_PORTA);
- *but = (x >> 5) & MOUSE_MSC_BUTTONS;
- x &= 0xf;
- bus_space_write_1(tag, handle, MSE_PORTC, MSE_HOLD | MSE_RXHIGH);
- x |= (bus_space_read_1(tag, handle, MSE_PORTA) << 4);
- bus_space_write_1(tag, handle, MSE_PORTC, MSE_HOLD | MSE_RYLOW);
- y = (bus_space_read_1(tag, handle, MSE_PORTA) & 0xf);
- bus_space_write_1(tag, handle, MSE_PORTC, MSE_HOLD | MSE_RYHIGH);
- y |= (bus_space_read_1(tag, handle, MSE_PORTA) << 4);
- *dx = x;
- *dy = y;
- bus_space_write_1(tag, handle, MSE_PORTC, MSE_INTREN);
-}
-
-/*
- * Routines for the ATI Inport bus mouse.
- */
-/*
- * Test for an ATI Inport bus mouse and return 1 if it is.
- * (do not enable interrupts)
- */
-static int
-mse_probeati(dev, sc)
- device_t dev;
- mse_softc_t *sc;
-{
- int i;
-
- for (i = 0; i < 2; i++)
- if (bus_space_read_1(sc->sc_iot, sc->sc_ioh, MSE_PORTC) == 0xde)
- return (1);
- return (0);
-}
-
-/*
- * Initialize ATI Inport mouse and enable interrupts.
- */
-static void
-mse_enableati(tag, handle)
- bus_space_tag_t tag;
- bus_space_handle_t handle;
-{
-
- bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_RESET);
- bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_MODE);
- bus_space_write_1(tag, handle, MSE_PORTB, MSE_INPORT_INTREN);
-}
-
-/*
- * Disable interrupts for ATI Inport mouse.
- */
-static void
-mse_disableati(tag, handle)
- bus_space_tag_t tag;
- bus_space_handle_t handle;
-{
-
- bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_MODE);
- bus_space_write_1(tag, handle, MSE_PORTB, 0);
-}
-
-/*
- * Get current dx, dy and up/down button state.
- */
-static void
-mse_getati(tag, handle, dx, dy, but)
- bus_space_tag_t tag;
- bus_space_handle_t handle;
- int *dx;
- int *dy;
- int *but;
-{
- register char byte;
-
- bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_MODE);
- bus_space_write_1(tag, handle, MSE_PORTB, MSE_INPORT_HOLD);
- bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_STATUS);
- *but = ~bus_space_read_1(tag, handle, MSE_PORTB) & MOUSE_MSC_BUTTONS;
- bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_DX);
- byte = bus_space_read_1(tag, handle, MSE_PORTB);
- *dx = byte;
- bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_DY);
- byte = bus_space_read_1(tag, handle, MSE_PORTB);
- *dy = byte;
- bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_MODE);
- bus_space_write_1(tag, handle, MSE_PORTB, MSE_INPORT_INTREN);
-}
diff --git a/sys/dev/pcf/pcf.c b/sys/dev/pcf/pcf.c
deleted file mode 100644
index 8c1d4886ca12..000000000000
--- a/sys/dev/pcf/pcf.c
+++ /dev/null
@@ -1,632 +0,0 @@
-/*-
- * Copyright (c) 1998 Nicolas Souchu, Marc Bouget
- * 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$
- *
- */
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/module.h>
-#include <sys/bus.h>
-
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-#include <isa/isareg.h>
-#include <isa/isavar.h>
-
-#include <i386/isa/isa_device.h>
-
-#include <dev/iicbus/iiconf.h>
-#include "iicbus_if.h"
-
-#define IO_PCFSIZE 2
-
-#define TIMEOUT 9999 /* XXX */
-
-/* Status bits of S1 register (read only) */
-#define nBB 0x01 /* busy when low set/reset by STOP/START*/
-#define LAB 0x02 /* lost arbitration bit in multi-master mode */
-#define AAS 0x04 /* addressed as slave */
-#define LRB 0x08 /* last received byte when not AAS */
-#define AD0 0x08 /* general call received when AAS */
-#define BER 0x10 /* bus error, misplaced START or STOP */
-#define STS 0x20 /* STOP detected in slave receiver mode */
-#define PIN 0x80 /* pending interrupt not (r/w) */
-
-/* Control bits of S1 register (write only) */
-#define ACK 0x01
-#define STO 0x02
-#define STA 0x04
-#define ENI 0x08
-#define ES2 0x10
-#define ES1 0x20
-#define ES0 0x40
-
-#define BUFSIZE 2048
-
-#define SLAVE_TRANSMITTER 0x1
-#define SLAVE_RECEIVER 0x2
-
-#define PCF_DEFAULT_ADDR 0xaa
-
-struct pcf_softc {
-
- int pcf_base; /* isa port */
- int pcf_flags;
- u_char pcf_addr; /* interface I2C address */
-
- int pcf_slave_mode; /* receiver or transmitter */
- int pcf_started; /* 1 if start condition sent */
-
- device_t iicbus; /* the corresponding iicbus */
-
- int rid_irq, rid_ioport;
- struct resource *res_irq, *res_ioport;
- void *intr_cookie;
-};
-
-static int pcf_probe(device_t);
-static int pcf_attach(device_t);
-static void pcfintr(void *arg);
-
-static int pcf_print_child(device_t, device_t);
-
-static int pcf_repeated_start(device_t, u_char, int);
-static int pcf_start(device_t, u_char, int);
-static int pcf_stop(device_t);
-static int pcf_write(device_t, char *, int, int *, int);
-static int pcf_read(device_t, char *, int, int *, int, int);
-static int pcf_rst_card(device_t, u_char, u_char, u_char *);
-
-static device_method_t pcf_methods[] = {
- /* device interface */
- DEVMETHOD(device_probe, pcf_probe),
- DEVMETHOD(device_attach, pcf_attach),
-
- /* bus interface */
- DEVMETHOD(bus_print_child, pcf_print_child),
-
- /* iicbus interface */
- DEVMETHOD(iicbus_callback, iicbus_null_callback),
- DEVMETHOD(iicbus_repeated_start, pcf_repeated_start),
- DEVMETHOD(iicbus_start, pcf_start),
- DEVMETHOD(iicbus_stop, pcf_stop),
- DEVMETHOD(iicbus_write, pcf_write),
- DEVMETHOD(iicbus_read, pcf_read),
- DEVMETHOD(iicbus_reset, pcf_rst_card),
-
- { 0, 0 }
-};
-
-static driver_t pcf_driver = {
- "pcf",
- pcf_methods,
- sizeof(struct pcf_softc),
-};
-
-static devclass_t pcf_devclass;
-
-#define DEVTOSOFTC(dev) ((struct pcf_softc *)device_get_softc(dev))
-
-static int
-pcf_probe(device_t pcfdev)
-{
- struct pcf_softc *pcf = DEVTOSOFTC(pcfdev);
- device_t parent = device_get_parent(pcfdev);
-
- device_set_desc(pcfdev, "PCF8584 I2C bus controller");
-
- pcf = DEVTOSOFTC(pcfdev);
- bzero(pcf, sizeof(struct pcf_softc));
-
- pcf->rid_irq = pcf->rid_ioport = 0;
- pcf->res_irq = pcf->res_ioport = 0;
-
- /* IO port is mandatory */
- pcf->res_ioport = bus_alloc_resource(pcfdev, SYS_RES_IOPORT,
- &pcf->rid_ioport, 0ul, ~0ul,
- IO_PCFSIZE, RF_ACTIVE);
- if (pcf->res_ioport == 0) {
- device_printf(pcfdev, "cannot reserve I/O port range\n");
- goto error;
- }
- BUS_READ_IVAR(parent, pcfdev, ISA_IVAR_PORT, &pcf->pcf_base);
-
- pcf->pcf_flags = device_get_flags(pcfdev);
-
- if (!(pcf->pcf_flags & IIC_POLLED)) {
- pcf->res_irq = bus_alloc_resource(pcfdev, SYS_RES_IRQ, &pcf->rid_irq,
- 0ul, ~0ul, 1, RF_ACTIVE);
- if (pcf->res_irq == 0) {
- device_printf(pcfdev, "can't reserve irq, polled mode.\n");
- pcf->pcf_flags |= IIC_POLLED;
- }
- }
-
- /* reset the chip */
- pcf_rst_card(pcfdev, IIC_FASTEST, PCF_DEFAULT_ADDR, NULL);
-
- return (0);
-error:
- if (pcf->res_ioport != 0) {
- bus_deactivate_resource(pcfdev, SYS_RES_IOPORT, pcf->rid_ioport,
- pcf->res_ioport);
- bus_release_resource(pcfdev, SYS_RES_IOPORT, pcf->rid_ioport,
- pcf->res_ioport);
- }
- return (ENXIO);
-}
-
-static int
-pcf_attach(device_t pcfdev)
-{
- struct pcf_softc *pcf = DEVTOSOFTC(pcfdev);
- device_t parent = device_get_parent(pcfdev);
- int error = 0;
-
- if (pcf->res_irq) {
- /* default to the tty mask for registration */ /* XXX */
- error = BUS_SETUP_INTR(parent, pcfdev, pcf->res_irq, INTR_TYPE_NET,
- pcfintr, pcfdev, &pcf->intr_cookie);
- if (error)
- return (error);
- }
-
- pcf->iicbus = device_add_child(pcfdev, "iicbus", -1);
-
- /* probe and attach the iicbus */
- bus_generic_attach(pcfdev);
-
- return (0);
-}
-
-static int
-pcf_print_child(device_t bus, device_t dev)
-{
- struct pcf_softc *pcf = (struct pcf_softc *)device_get_softc(bus);
- int retval = 0;
-
- retval += bus_print_child_header(bus, dev);
- retval += printf(" on %s addr 0x%x\n", device_get_nameunit(bus),
- (int)pcf->pcf_addr);
-
- return (retval);
-}
-
-/*
- * PCF8584 datasheet : when operate at 8 MHz or more, a minimun time of
- * 6 clocks cycles must be left between two consecutives access
- */
-#define pcf_nops() DELAY(10)
-
-#define dummy_read(pcf) PCF_GET_S0(pcf)
-#define dummy_write(pcf) PCF_SET_S0(pcf, 0)
-
-/*
- * Specific register access to PCF8584
- */
-static void PCF_SET_S0(struct pcf_softc *pcf, int data)
-{
- outb(pcf->pcf_base, data);
- pcf_nops();
-}
-
-static void PCF_SET_S1(struct pcf_softc *pcf, int data)
-{
- outb(pcf->pcf_base+1, data);
- pcf_nops();
-}
-
-static char PCF_GET_S0(struct pcf_softc *pcf)
-{
- char data;
-
- data = inb(pcf->pcf_base);
- pcf_nops();
-
- return (data);
-}
-
-static char PCF_GET_S1(struct pcf_softc *pcf)
-{
- char data;
-
- data = inb(pcf->pcf_base+1);
- pcf_nops();
-
- return (data);
-}
-
-/*
- * Polling mode for master operations wait for a new
- * byte incomming or outgoing
- */
-static int pcf_wait_byte(struct pcf_softc *pcf)
-{
- int counter = TIMEOUT;
-
- while (counter--) {
-
- if ((PCF_GET_S1(pcf) & PIN) == 0)
- return (0);
- }
-
- return (IIC_ETIMEOUT);
-}
-
-static int pcf_stop(device_t pcfdev)
-{
- struct pcf_softc *pcf = DEVTOSOFTC(pcfdev);
-
- /*
- * Send STOP condition iff the START condition was previously sent.
- * STOP is sent only once even if an iicbus_stop() is called after
- * an iicbus_read()... see pcf_read(): the pcf needs to send the stop
- * before the last char is read.
- */
- if (pcf->pcf_started) {
- /* set stop condition and enable IT */
- PCF_SET_S1(pcf, PIN|ES0|ENI|STO|ACK);
-
- pcf->pcf_started = 0;
- }
-
- return (0);
-}
-
-
-static int pcf_noack(struct pcf_softc *pcf, int timeout)
-{
- int noack;
- int k = timeout/10;
-
- do {
- noack = PCF_GET_S1(pcf) & LRB;
- if (!noack)
- break;
- DELAY(10); /* XXX wait 10 us */
- } while (k--);
-
- return (noack);
-}
-
-static int pcf_repeated_start(device_t pcfdev, u_char slave, int timeout)
-{
- struct pcf_softc *pcf = DEVTOSOFTC(pcfdev);
- int error = 0;
-
- /* repeated start */
- PCF_SET_S1(pcf, ES0|STA|STO|ACK);
-
- /* set slave address to PCF. Last bit (LSB) must be set correctly
- * according to transfer direction */
- PCF_SET_S0(pcf, slave);
-
- /* wait for address sent, polling */
- if ((error = pcf_wait_byte(pcf)))
- goto error;
-
- /* check for ack */
- if (pcf_noack(pcf, timeout)) {
- error = IIC_ENOACK;
- goto error;
- }
-
- return (0);
-
-error:
- pcf_stop(pcfdev);
- return (error);
-}
-
-static int pcf_start(device_t pcfdev, u_char slave, int timeout)
-{
- struct pcf_softc *pcf = DEVTOSOFTC(pcfdev);
- int error = 0;
-
- if ((PCF_GET_S1(pcf) & nBB) == 0)
- return (IIC_EBUSBSY);
-
- /* set slave address to PCF. Last bit (LSB) must be set correctly
- * according to transfer direction */
- PCF_SET_S0(pcf, slave);
-
- /* START only */
- PCF_SET_S1(pcf, PIN|ES0|STA|ACK);
-
- pcf->pcf_started = 1;
-
- /* wait for address sent, polling */
- if ((error = pcf_wait_byte(pcf)))
- goto error;
-
- /* check for ACK */
- if (pcf_noack(pcf, timeout)) {
- error = IIC_ENOACK;
- goto error;
- }
-
- return (0);
-
-error:
- pcf_stop(pcfdev);
- return (error);
-}
-
-static void
-pcfintr(void *arg)
-{
- device_t pcfdev = (device_t)arg;
- struct pcf_softc *pcf = DEVTOSOFTC(pcfdev);
-
- char data, status, addr;
- char error = 0;
-
- status = PCF_GET_S1(pcf);
-
- if (status & PIN) {
- device_printf(pcfdev, "spurious interrupt, status=0x%x\n", status & 0xff);
-
- goto error;
- }
-
- if (status & LAB)
- device_printf(pcfdev, "bus arbitration lost!\n");
-
- if (status & BER) {
- error = IIC_EBUSERR;
- iicbus_intr(pcf->iicbus, INTR_ERROR, &error);
-
- goto error;
- }
-
- do {
- status = PCF_GET_S1(pcf);
-
- switch(pcf->pcf_slave_mode) {
-
- case SLAVE_TRANSMITTER:
- if (status & LRB) {
- /* ack interrupt line */
- dummy_write(pcf);
-
- /* no ack, don't send anymore */
- pcf->pcf_slave_mode = SLAVE_RECEIVER;
-
- iicbus_intr(pcf->iicbus, INTR_NOACK, NULL);
- break;
- }
-
- /* get data from upper code */
- iicbus_intr(pcf->iicbus, INTR_TRANSMIT, &data);
-
- PCF_SET_S0(pcf, data);
- break;
-
- case SLAVE_RECEIVER:
- if (status & AAS) {
- addr = PCF_GET_S0(pcf);
-
- if (status & AD0)
- iicbus_intr(pcf->iicbus, INTR_GENERAL, &addr);
- else
- iicbus_intr(pcf->iicbus, INTR_START, &addr);
-
- if (addr & LSB) {
- pcf->pcf_slave_mode = SLAVE_TRANSMITTER;
-
- /* get the first char from upper code */
- iicbus_intr(pcf->iicbus, INTR_TRANSMIT, &data);
-
- /* send first data byte */
- PCF_SET_S0(pcf, data);
- }
-
- break;
- }
-
- /* stop condition received? */
- if (status & STS) {
- /* ack interrupt line */
- dummy_read(pcf);
-
- /* emulate intr stop condition */
- iicbus_intr(pcf->iicbus, INTR_STOP, NULL);
-
- } else {
- /* get data, ack interrupt line */
- data = PCF_GET_S0(pcf);
-
- /* deliver the character */
- iicbus_intr(pcf->iicbus, INTR_RECEIVE, &data);
- }
- break;
-
- default:
- panic("%s: unknown slave mode (%d)!", __func__,
- pcf->pcf_slave_mode);
- }
-
- } while ((PCF_GET_S1(pcf) & PIN) == 0);
-
- return;
-
-error:
- /* unknown event on bus...reset PCF */
- PCF_SET_S1(pcf, PIN|ES0|ENI|ACK);
-
- pcf->pcf_slave_mode = SLAVE_RECEIVER;
-
- return;
-}
-
-static int pcf_rst_card(device_t pcfdev, u_char speed, u_char addr, u_char *oldaddr)
-{
- struct pcf_softc *pcf = DEVTOSOFTC(pcfdev);
-
- if (oldaddr)
- *oldaddr = pcf->pcf_addr;
-
- /* retrieve own address from bus level */
- if (!addr)
- pcf->pcf_addr = PCF_DEFAULT_ADDR;
- else
- pcf->pcf_addr = addr;
-
- PCF_SET_S1(pcf, PIN); /* initialize S1 */
-
- /* own address S'O<>0 */
- PCF_SET_S0(pcf, pcf->pcf_addr >> 1);
-
- /* select clock register */
- PCF_SET_S1(pcf, PIN|ES1);
-
- /* select bus speed : 18=90kb, 19=45kb, 1A=11kb, 1B=1.5kb */
- switch (speed) {
- case IIC_SLOW:
- PCF_SET_S0(pcf, 0x1b);
- break;
-
- case IIC_FAST:
- PCF_SET_S0(pcf, 0x19);
- break;
-
- case IIC_UNKNOWN:
- case IIC_FASTEST:
- default:
- PCF_SET_S0(pcf, 0x18);
- break;
- }
-
- /* set bus on, ack=yes, INT=yes */
- PCF_SET_S1(pcf, PIN|ES0|ENI|ACK);
-
- pcf->pcf_slave_mode = SLAVE_RECEIVER;
-
- return (0);
-}
-
-static int
-pcf_write(device_t pcfdev, char *buf, int len, int *sent, int timeout /* us */)
-{
- struct pcf_softc *pcf = DEVTOSOFTC(pcfdev);
- int bytes, error = 0;
-
-#ifdef PCFDEBUG
- printf("pcf%d: >> writing %d bytes\n", device_get_unit(pcfdev), len);
-#endif
-
- bytes = 0;
- while (len) {
-
- PCF_SET_S0(pcf, *buf++);
-
- /* wait for the byte to be send */
- if ((error = pcf_wait_byte(pcf)))
- goto error;
-
- /* check if ack received */
- if (pcf_noack(pcf, timeout)) {
- error = IIC_ENOACK;
- goto error;
- }
-
- len --;
- bytes ++;
- }
-
-error:
- *sent = bytes;
-
-#ifdef PCFDEBUG
- printf("pcf%d: >> %d bytes written (%d)\n",
- device_get_unit(pcfdev), bytes, error);
-#endif
-
- return (error);
-}
-
-static int
-pcf_read(device_t pcfdev, char *buf, int len, int *read, int last,
- int delay /* us */)
-{
- struct pcf_softc *pcf = DEVTOSOFTC(pcfdev);
- int bytes, error = 0;
-
-#ifdef PCFDEBUG
- printf("pcf%d: << reading %d bytes\n", device_get_unit(pcfdev), len);
-#endif
-
- /* trig the bus to get the first data byte in S0 */
- if (len) {
- if (len == 1 && last)
- /* just one byte to read */
- PCF_SET_S1(pcf, ES0); /* no ack */
-
- dummy_read(pcf);
- }
-
- bytes = 0;
- while (len) {
-
- /* XXX delay needed here */
-
- /* wait for trigged byte */
- if ((error = pcf_wait_byte(pcf))) {
- pcf_stop(pcfdev);
- goto error;
- }
-
- if (len == 1 && last)
- /* ok, last data byte already in S0, no I2C activity
- * on next PCF_GET_S0() */
- pcf_stop(pcfdev);
-
- else if (len == 2 && last)
- /* next trigged byte with no ack */
- PCF_SET_S1(pcf, ES0);
-
- /* receive byte, trig next byte */
- *buf++ = PCF_GET_S0(pcf);
-
- len --;
- bytes ++;
- };
-
-error:
- *read = bytes;
-
-#ifdef PCFDEBUG
- printf("pcf%d: << %d bytes read (%d)\n",
- device_get_unit(pcfdev), bytes, error);
-#endif
-
- return (error);
-}
-
-DRIVER_MODULE(pcf, isa, pcf_driver, pcf_devclass, 0, 0);
diff --git a/sys/dev/ppc/ppc.c b/sys/dev/ppc/ppc.c
deleted file mode 100644
index a32eb44304d6..000000000000
--- a/sys/dev/ppc/ppc.c
+++ /dev/null
@@ -1,2166 +0,0 @@
-/*-
- * Copyright (c) 1997-2000 Nicolas Souchu
- * Copyright (c) 2001 Alcove - Nicolas Souchu
- * 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$
- *
- */
-
-#include "opt_ppc.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/malloc.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <machine/clock.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <machine/vmparam.h>
-#include <sys/rman.h>
-
-#include <isa/isareg.h>
-#include <isa/isavar.h>
-
-#include <dev/ppbus/ppbconf.h>
-#include <dev/ppbus/ppb_msq.h>
-
-#include <isa/ppcreg.h>
-
-#include "ppbus_if.h"
-
-#define LOG_PPC(function, ppc, string) \
- if (bootverbose) printf("%s: %s\n", function, string)
-
-
-#define DEVTOSOFTC(dev) ((struct ppc_data *)device_get_softc(dev))
-
-static devclass_t ppc_devclass;
-
-static int ppc_probe(device_t dev);
-static int ppc_attach(device_t dev);
-static int ppc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val);
-
-static void ppc_reset_epp(device_t);
-static void ppc_ecp_sync(device_t);
-static void ppcintr(void *arg);
-
-static int ppc_exec_microseq(device_t, struct ppb_microseq **);
-static int ppc_setmode(device_t, int);
-
-static int ppc_read(device_t, char *, int, int);
-static int ppc_write(device_t, char *, int, int);
-
-static u_char ppc_io(device_t, int, u_char *, int, u_char);
-
-static int ppc_setup_intr(device_t, device_t, struct resource *, int,
- void (*)(void *), void *, void **);
-static int ppc_teardown_intr(device_t, device_t, struct resource *, void *);
-
-static device_method_t ppc_methods[] = {
- /* device interface */
- DEVMETHOD(device_probe, ppc_probe),
- DEVMETHOD(device_attach, ppc_attach),
-
- /* bus interface */
- DEVMETHOD(bus_read_ivar, ppc_read_ivar),
- DEVMETHOD(bus_setup_intr, ppc_setup_intr),
- DEVMETHOD(bus_teardown_intr, ppc_teardown_intr),
- DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
-
- /* ppbus interface */
- DEVMETHOD(ppbus_io, ppc_io),
- DEVMETHOD(ppbus_exec_microseq, ppc_exec_microseq),
- DEVMETHOD(ppbus_reset_epp, ppc_reset_epp),
- DEVMETHOD(ppbus_setmode, ppc_setmode),
- DEVMETHOD(ppbus_ecp_sync, ppc_ecp_sync),
- DEVMETHOD(ppbus_read, ppc_read),
- DEVMETHOD(ppbus_write, ppc_write),
-
- { 0, 0 }
- };
-
-static driver_t ppc_driver = {
- "ppc",
- ppc_methods,
- sizeof(struct ppc_data),
-};
-
-static char *ppc_models[] = {
- "SMC-like", "SMC FDC37C665GT", "SMC FDC37C666GT", "PC87332", "PC87306",
- "82091AA", "Generic", "W83877F", "W83877AF", "Winbond", "PC87334",
- "SMC FDC37C935", "PC87303", 0
-};
-
-/* list of available modes */
-static char *ppc_avms[] = {
- "COMPATIBLE", "NIBBLE-only", "PS2-only", "PS2/NIBBLE", "EPP-only",
- "EPP/NIBBLE", "EPP/PS2", "EPP/PS2/NIBBLE", "ECP-only",
- "ECP/NIBBLE", "ECP/PS2", "ECP/PS2/NIBBLE", "ECP/EPP",
- "ECP/EPP/NIBBLE", "ECP/EPP/PS2", "ECP/EPP/PS2/NIBBLE", 0
-};
-
-/* list of current executing modes
- * Note that few modes do not actually exist.
- */
-static char *ppc_modes[] = {
- "COMPATIBLE", "NIBBLE", "PS/2", "PS/2", "EPP",
- "EPP", "EPP", "EPP", "ECP",
- "ECP", "ECP+PS2", "ECP+PS2", "ECP+EPP",
- "ECP+EPP", "ECP+EPP", "ECP+EPP", 0
-};
-
-static char *ppc_epp_protocol[] = { " (EPP 1.9)", " (EPP 1.7)", 0 };
-
-#ifdef __i386__
-/*
- * BIOS printer list - used by BIOS probe.
- */
-#define BIOS_PPC_PORTS 0x408
-#define BIOS_PORTS (short *)(KERNBASE+BIOS_PPC_PORTS)
-#define BIOS_MAX_PPC 4
-#endif
-
-/*
- * ppc_ecp_sync() XXX
- */
-static void
-ppc_ecp_sync(device_t dev) {
-
- int i, r;
- struct ppc_data *ppc = DEVTOSOFTC(dev);
-
- if (!(ppc->ppc_avm & PPB_ECP) && !(ppc->ppc_dtm & PPB_ECP))
- return;
-
- r = r_ecr(ppc);
- if ((r & 0xe0) != PPC_ECR_EPP)
- return;
-
- for (i = 0; i < 100; i++) {
- r = r_ecr(ppc);
- if (r & 0x1)
- return;
- DELAY(100);
- }
-
- printf("ppc%d: ECP sync failed as data still " \
- "present in FIFO.\n", ppc->ppc_unit);
-
- return;
-}
-
-/*
- * ppc_detect_fifo()
- *
- * Detect parallel port FIFO
- */
-static int
-ppc_detect_fifo(struct ppc_data *ppc)
-{
- char ecr_sav;
- char ctr_sav, ctr, cc;
- short i;
-
- /* save registers */
- ecr_sav = r_ecr(ppc);
- ctr_sav = r_ctr(ppc);
-
- /* enter ECP configuration mode, no interrupt, no DMA */
- w_ecr(ppc, 0xf4);
-
- /* read PWord size - transfers in FIFO mode must be PWord aligned */
- ppc->ppc_pword = (r_cnfgA(ppc) & PPC_PWORD_MASK);
-
- /* XXX 16 and 32 bits implementations not supported */
- if (ppc->ppc_pword != PPC_PWORD_8) {
- LOG_PPC(__func__, ppc, "PWord not supported");
- goto error;
- }
-
- w_ecr(ppc, 0x34); /* byte mode, no interrupt, no DMA */
- ctr = r_ctr(ppc);
- w_ctr(ppc, ctr | PCD); /* set direction to 1 */
-
- /* enter ECP test mode, no interrupt, no DMA */
- w_ecr(ppc, 0xd4);
-
- /* flush the FIFO */
- for (i=0; i<1024; i++) {
- if (r_ecr(ppc) & PPC_FIFO_EMPTY)
- break;
- cc = r_fifo(ppc);
- }
-
- if (i >= 1024) {
- LOG_PPC(__func__, ppc, "can't flush FIFO");
- goto error;
- }
-
- /* enable interrupts, no DMA */
- w_ecr(ppc, 0xd0);
-
- /* determine readIntrThreshold
- * fill the FIFO until serviceIntr is set
- */
- for (i=0; i<1024; i++) {
- w_fifo(ppc, (char)i);
- if (!ppc->ppc_rthr && (r_ecr(ppc) & PPC_SERVICE_INTR)) {
- /* readThreshold reached */
- ppc->ppc_rthr = i+1;
- }
- if (r_ecr(ppc) & PPC_FIFO_FULL) {
- ppc->ppc_fifo = i+1;
- break;
- }
- }
-
- if (i >= 1024) {
- LOG_PPC(__func__, ppc, "can't fill FIFO");
- goto error;
- }
-
- w_ecr(ppc, 0xd4); /* test mode, no interrupt, no DMA */
- w_ctr(ppc, ctr & ~PCD); /* set direction to 0 */
- w_ecr(ppc, 0xd0); /* enable interrupts */
-
- /* determine writeIntrThreshold
- * empty the FIFO until serviceIntr is set
- */
- for (i=ppc->ppc_fifo; i>0; i--) {
- if (r_fifo(ppc) != (char)(ppc->ppc_fifo-i)) {
- LOG_PPC(__func__, ppc, "invalid data in FIFO");
- goto error;
- }
- if (r_ecr(ppc) & PPC_SERVICE_INTR) {
- /* writeIntrThreshold reached */
- ppc->ppc_wthr = ppc->ppc_fifo - i+1;
- }
- /* if FIFO empty before the last byte, error */
- if (i>1 && (r_ecr(ppc) & PPC_FIFO_EMPTY)) {
- LOG_PPC(__func__, ppc, "data lost in FIFO");
- goto error;
- }
- }
-
- /* FIFO must be empty after the last byte */
- if (!(r_ecr(ppc) & PPC_FIFO_EMPTY)) {
- LOG_PPC(__func__, ppc, "can't empty the FIFO");
- goto error;
- }
-
- w_ctr(ppc, ctr_sav);
- w_ecr(ppc, ecr_sav);
-
- return (0);
-
-error:
- w_ctr(ppc, ctr_sav);
- w_ecr(ppc, ecr_sav);
-
- return (EINVAL);
-}
-
-static int
-ppc_detect_port(struct ppc_data *ppc)
-{
-
- w_ctr(ppc, 0x0c); /* To avoid missing PS2 ports */
- w_dtr(ppc, 0xaa);
- if (r_dtr(ppc) != 0xaa)
- return (0);
-
- return (1);
-}
-
-/*
- * EPP timeout, according to the PC87332 manual
- * Semantics of clearing EPP timeout bit.
- * PC87332 - reading SPP_STR does it...
- * SMC - write 1 to EPP timeout bit XXX
- * Others - (?) write 0 to EPP timeout bit
- */
-static void
-ppc_reset_epp_timeout(struct ppc_data *ppc)
-{
- register char r;
-
- r = r_str(ppc);
- w_str(ppc, r | 0x1);
- w_str(ppc, r & 0xfe);
-
- return;
-}
-
-static int
-ppc_check_epp_timeout(struct ppc_data *ppc)
-{
- ppc_reset_epp_timeout(ppc);
-
- return (!(r_str(ppc) & TIMEOUT));
-}
-
-/*
- * Configure current operating mode
- */
-static int
-ppc_generic_setmode(struct ppc_data *ppc, int mode)
-{
- u_char ecr = 0;
-
- /* check if mode is available */
- if (mode && !(ppc->ppc_avm & mode))
- return (EINVAL);
-
- /* if ECP mode, configure ecr register */
- if ((ppc->ppc_avm & PPB_ECP) || (ppc->ppc_dtm & PPB_ECP)) {
- /* return to byte mode (keeping direction bit),
- * no interrupt, no DMA to be able to change to
- * ECP
- */
- w_ecr(ppc, PPC_ECR_RESET);
- ecr = PPC_DISABLE_INTR;
-
- if (mode & PPB_EPP)
- return (EINVAL);
- else if (mode & PPB_ECP)
- /* select ECP mode */
- ecr |= PPC_ECR_ECP;
- else if (mode & PPB_PS2)
- /* select PS2 mode with ECP */
- ecr |= PPC_ECR_PS2;
- else
- /* select COMPATIBLE/NIBBLE mode */
- ecr |= PPC_ECR_STD;
-
- w_ecr(ppc, ecr);
- }
-
- ppc->ppc_mode = mode;
-
- return (0);
-}
-
-/*
- * The ppc driver is free to choose options like FIFO or DMA
- * if ECP mode is available.
- *
- * The 'RAW' option allows the upper drivers to force the ppc mode
- * even with FIFO, DMA available.
- */
-static int
-ppc_smclike_setmode(struct ppc_data *ppc, int mode)
-{
- u_char ecr = 0;
-
- /* check if mode is available */
- if (mode && !(ppc->ppc_avm & mode))
- return (EINVAL);
-
- /* if ECP mode, configure ecr register */
- if ((ppc->ppc_avm & PPB_ECP) || (ppc->ppc_dtm & PPB_ECP)) {
- /* return to byte mode (keeping direction bit),
- * no interrupt, no DMA to be able to change to
- * ECP or EPP mode
- */
- w_ecr(ppc, PPC_ECR_RESET);
- ecr = PPC_DISABLE_INTR;
-
- if (mode & PPB_EPP)
- /* select EPP mode */
- ecr |= PPC_ECR_EPP;
- else if (mode & PPB_ECP)
- /* select ECP mode */
- ecr |= PPC_ECR_ECP;
- else if (mode & PPB_PS2)
- /* select PS2 mode with ECP */
- ecr |= PPC_ECR_PS2;
- else
- /* select COMPATIBLE/NIBBLE mode */
- ecr |= PPC_ECR_STD;
-
- w_ecr(ppc, ecr);
- }
-
- ppc->ppc_mode = mode;
-
- return (0);
-}
-
-#ifdef PPC_PROBE_CHIPSET
-/*
- * ppc_pc873xx_detect
- *
- * Probe for a Natsemi PC873xx-family part.
- *
- * References in this function are to the National Semiconductor
- * PC87332 datasheet TL/C/11930, May 1995 revision.
- */
-static int pc873xx_basetab[] = {0x0398, 0x026e, 0x015c, 0x002e, 0};
-static int pc873xx_porttab[] = {0x0378, 0x03bc, 0x0278, 0};
-static int pc873xx_irqtab[] = {5, 7, 5, 0};
-
-static int pc873xx_regstab[] = {
- PC873_FER, PC873_FAR, PC873_PTR,
- PC873_FCR, PC873_PCR, PC873_PMC,
- PC873_TUP, PC873_SID, PC873_PNP0,
- PC873_PNP1, PC873_LPTBA, -1
-};
-
-static char *pc873xx_rnametab[] = {
- "FER", "FAR", "PTR", "FCR", "PCR",
- "PMC", "TUP", "SID", "PNP0", "PNP1",
- "LPTBA", NULL
-};
-
-static int
-ppc_pc873xx_detect(struct ppc_data *ppc, int chipset_mode) /* XXX mode never forced */
-{
- static int index = 0;
- int idport, irq;
- int ptr, pcr, val, i;
-
- while ((idport = pc873xx_basetab[index++])) {
-
- /* XXX should check first to see if this location is already claimed */
-
- /*
- * Pull the 873xx through the power-on ID cycle (2.2,1.).
- * We can't use this to locate the chip as it may already have
- * been used by the BIOS.
- */
- (void)inb(idport); (void)inb(idport);
- (void)inb(idport); (void)inb(idport);
-
- /*
- * Read the SID byte. Possible values are :
- *
- * 01010xxx PC87334
- * 0001xxxx PC87332
- * 01110xxx PC87306
- * 00110xxx PC87303
- */
- outb(idport, PC873_SID);
- val = inb(idport + 1);
- if ((val & 0xf0) == 0x10) {
- ppc->ppc_model = NS_PC87332;
- } else if ((val & 0xf8) == 0x70) {
- ppc->ppc_model = NS_PC87306;
- } else if ((val & 0xf8) == 0x50) {
- ppc->ppc_model = NS_PC87334;
- } else if ((val & 0xf8) == 0x40) { /* Should be 0x30 by the
- documentation, but probing
- yielded 0x40... */
- ppc->ppc_model = NS_PC87303;
- } else {
- if (bootverbose && (val != 0xff))
- printf("PC873xx probe at 0x%x got unknown ID 0x%x\n", idport, val);
- continue ; /* not recognised */
- }
-
- /* print registers */
- if (bootverbose) {
- printf("PC873xx");
- for (i=0; pc873xx_regstab[i] != -1; i++) {
- outb(idport, pc873xx_regstab[i]);
- printf(" %s=0x%x", pc873xx_rnametab[i],
- inb(idport + 1) & 0xff);
- }
- printf("\n");
- }
-
- /*
- * We think we have one. Is it enabled and where we want it to be?
- */
- outb(idport, PC873_FER);
- val = inb(idport + 1);
- if (!(val & PC873_PPENABLE)) {
- if (bootverbose)
- printf("PC873xx parallel port disabled\n");
- continue;
- }
- outb(idport, PC873_FAR);
- val = inb(idport + 1);
- /* XXX we should create a driver instance for every port found */
- if (pc873xx_porttab[val & 0x3] != ppc->ppc_base) {
-
- /* First try to change the port address to that requested... */
-
- switch(ppc->ppc_base) {
- case 0x378:
- val &= 0xfc;
- break;
-
- case 0x3bc:
- val &= 0xfd;
- break;
-
- case 0x278:
- val &= 0xfe;
- break;
-
- default:
- val &= 0xfd;
- break;
- }
-
- outb(idport, PC873_FAR);
- outb(idport + 1, val);
- outb(idport + 1, val);
-
- /* Check for success by reading back the value we supposedly
- wrote and comparing...*/
-
- outb(idport, PC873_FAR);
- val = inb(idport + 1) & 0x3;
-
- /* If we fail, report the failure... */
-
- if (pc873xx_porttab[val] != ppc->ppc_base) {
- if (bootverbose)
- printf("PC873xx at 0x%x not for driver at port 0x%x\n",
- pc873xx_porttab[val], ppc->ppc_base);
- }
- continue;
- }
-
- outb(idport, PC873_PTR);
- ptr = inb(idport + 1);
-
- /* get irq settings */
- if (ppc->ppc_base == 0x378)
- irq = (ptr & PC873_LPTBIRQ7) ? 7 : 5;
- else
- irq = pc873xx_irqtab[val];
-
- if (bootverbose)
- printf("PC873xx irq %d at 0x%x\n", irq, ppc->ppc_base);
-
- /*
- * Check if irq settings are correct
- */
- if (irq != ppc->ppc_irq) {
- /*
- * If the chipset is not locked and base address is 0x378,
- * we have another chance
- */
- if (ppc->ppc_base == 0x378 && !(ptr & PC873_CFGLOCK)) {
- if (ppc->ppc_irq == 7) {
- outb(idport + 1, (ptr | PC873_LPTBIRQ7));
- outb(idport + 1, (ptr | PC873_LPTBIRQ7));
- } else {
- outb(idport + 1, (ptr & ~PC873_LPTBIRQ7));
- outb(idport + 1, (ptr & ~PC873_LPTBIRQ7));
- }
- if (bootverbose)
- printf("PC873xx irq set to %d\n", ppc->ppc_irq);
- } else {
- if (bootverbose)
- printf("PC873xx sorry, can't change irq setting\n");
- }
- } else {
- if (bootverbose)
- printf("PC873xx irq settings are correct\n");
- }
-
- outb(idport, PC873_PCR);
- pcr = inb(idport + 1);
-
- if ((ptr & PC873_CFGLOCK) || !chipset_mode) {
- if (bootverbose)
- printf("PC873xx %s", (ptr & PC873_CFGLOCK)?"locked":"unlocked");
-
- ppc->ppc_avm |= PPB_NIBBLE;
- if (bootverbose)
- printf(", NIBBLE");
-
- if (pcr & PC873_EPPEN) {
- ppc->ppc_avm |= PPB_EPP;
-
- if (bootverbose)
- printf(", EPP");
-
- if (pcr & PC873_EPP19)
- ppc->ppc_epp = EPP_1_9;
- else
- ppc->ppc_epp = EPP_1_7;
-
- if ((ppc->ppc_model == NS_PC87332) && bootverbose) {
- outb(idport, PC873_PTR);
- ptr = inb(idport + 1);
- if (ptr & PC873_EPPRDIR)
- printf(", Regular mode");
- else
- printf(", Automatic mode");
- }
- } else if (pcr & PC873_ECPEN) {
- ppc->ppc_avm |= PPB_ECP;
- if (bootverbose)
- printf(", ECP");
-
- if (pcr & PC873_ECPCLK) { /* XXX */
- ppc->ppc_avm |= PPB_PS2;
- if (bootverbose)
- printf(", PS/2");
- }
- } else {
- outb(idport, PC873_PTR);
- ptr = inb(idport + 1);
- if (ptr & PC873_EXTENDED) {
- ppc->ppc_avm |= PPB_SPP;
- if (bootverbose)
- printf(", SPP");
- }
- }
- } else {
- if (bootverbose)
- printf("PC873xx unlocked");
-
- if (chipset_mode & PPB_ECP) {
- if ((chipset_mode & PPB_EPP) && bootverbose)
- printf(", ECP+EPP not supported");
-
- pcr &= ~PC873_EPPEN;
- pcr |= (PC873_ECPEN | PC873_ECPCLK); /* XXX */
- outb(idport + 1, pcr);
- outb(idport + 1, pcr);
-
- if (bootverbose)
- printf(", ECP");
-
- } else if (chipset_mode & PPB_EPP) {
- pcr &= ~(PC873_ECPEN | PC873_ECPCLK);
- pcr |= (PC873_EPPEN | PC873_EPP19);
- outb(idport + 1, pcr);
- outb(idport + 1, pcr);
-
- ppc->ppc_epp = EPP_1_9; /* XXX */
-
- if (bootverbose)
- printf(", EPP1.9");
-
- /* enable automatic direction turnover */
- if (ppc->ppc_model == NS_PC87332) {
- outb(idport, PC873_PTR);
- ptr = inb(idport + 1);
- ptr &= ~PC873_EPPRDIR;
- outb(idport + 1, ptr);
- outb(idport + 1, ptr);
-
- if (bootverbose)
- printf(", Automatic mode");
- }
- } else {
- pcr &= ~(PC873_ECPEN | PC873_ECPCLK | PC873_EPPEN);
- outb(idport + 1, pcr);
- outb(idport + 1, pcr);
-
- /* configure extended bit in PTR */
- outb(idport, PC873_PTR);
- ptr = inb(idport + 1);
-
- if (chipset_mode & PPB_PS2) {
- ptr |= PC873_EXTENDED;
-
- if (bootverbose)
- printf(", PS/2");
-
- } else {
- /* default to NIBBLE mode */
- ptr &= ~PC873_EXTENDED;
-
- if (bootverbose)
- printf(", NIBBLE");
- }
- outb(idport + 1, ptr);
- outb(idport + 1, ptr);
- }
-
- ppc->ppc_avm = chipset_mode;
- }
-
- if (bootverbose)
- printf("\n");
-
- ppc->ppc_type = PPC_TYPE_GENERIC;
- ppc_generic_setmode(ppc, chipset_mode);
-
- return(chipset_mode);
- }
- return(-1);
-}
-
-/*
- * ppc_smc37c66xgt_detect
- *
- * SMC FDC37C66xGT configuration.
- */
-static int
-ppc_smc37c66xgt_detect(struct ppc_data *ppc, int chipset_mode)
-{
- int s, i;
- u_char r;
- int type = -1;
- int csr = SMC66x_CSR; /* initial value is 0x3F0 */
-
- int port_address[] = { -1 /* disabled */ , 0x3bc, 0x378, 0x278 };
-
-
-#define cio csr+1 /* config IO port is either 0x3F1 or 0x371 */
-
- /*
- * Detection: enter configuration mode and read CRD register.
- */
-
- s = splhigh();
- outb(csr, SMC665_iCODE);
- outb(csr, SMC665_iCODE);
- splx(s);
-
- outb(csr, 0xd);
- if (inb(cio) == 0x65) {
- type = SMC_37C665GT;
- goto config;
- }
-
- for (i = 0; i < 2; i++) {
- s = splhigh();
- outb(csr, SMC666_iCODE);
- outb(csr, SMC666_iCODE);
- splx(s);
-
- outb(csr, 0xd);
- if (inb(cio) == 0x66) {
- type = SMC_37C666GT;
- break;
- }
-
- /* Another chance, CSR may be hard-configured to be at 0x370 */
- csr = SMC666_CSR;
- }
-
-config:
- /*
- * If chipset not found, do not continue.
- */
- if (type == -1)
- return (-1);
-
- /* select CR1 */
- outb(csr, 0x1);
-
- /* read the port's address: bits 0 and 1 of CR1 */
- r = inb(cio) & SMC_CR1_ADDR;
- if (port_address[(int)r] != ppc->ppc_base)
- return (-1);
-
- ppc->ppc_model = type;
-
- /*
- * CR1 and CR4 registers bits 3 and 0/1 for mode configuration
- * If SPP mode is detected, try to set ECP+EPP mode
- */
-
- if (bootverbose) {
- outb(csr, 0x1);
- printf("ppc%d: SMC registers CR1=0x%x", ppc->ppc_unit,
- inb(cio) & 0xff);
-
- outb(csr, 0x4);
- printf(" CR4=0x%x", inb(cio) & 0xff);
- }
-
- /* select CR1 */
- outb(csr, 0x1);
-
- if (!chipset_mode) {
- /* autodetect mode */
-
- /* 666GT is ~certainly~ hardwired to an extended ECP+EPP mode */
- if (type == SMC_37C666GT) {
- ppc->ppc_avm |= PPB_ECP | PPB_EPP | PPB_SPP;
- if (bootverbose)
- printf(" configuration hardwired, supposing " \
- "ECP+EPP SPP");
-
- } else
- if ((inb(cio) & SMC_CR1_MODE) == 0) {
- /* already in extended parallel port mode, read CR4 */
- outb(csr, 0x4);
- r = (inb(cio) & SMC_CR4_EMODE);
-
- switch (r) {
- case SMC_SPP:
- ppc->ppc_avm |= PPB_SPP;
- if (bootverbose)
- printf(" SPP");
- break;
-
- case SMC_EPPSPP:
- ppc->ppc_avm |= PPB_EPP | PPB_SPP;
- if (bootverbose)
- printf(" EPP SPP");
- break;
-
- case SMC_ECP:
- ppc->ppc_avm |= PPB_ECP | PPB_SPP;
- if (bootverbose)
- printf(" ECP SPP");
- break;
-
- case SMC_ECPEPP:
- ppc->ppc_avm |= PPB_ECP | PPB_EPP | PPB_SPP;
- if (bootverbose)
- printf(" ECP+EPP SPP");
- break;
- }
- } else {
- /* not an extended port mode */
- ppc->ppc_avm |= PPB_SPP;
- if (bootverbose)
- printf(" SPP");
- }
-
- } else {
- /* mode forced */
- ppc->ppc_avm = chipset_mode;
-
- /* 666GT is ~certainly~ hardwired to an extended ECP+EPP mode */
- if (type == SMC_37C666GT)
- goto end_detect;
-
- r = inb(cio);
- if ((chipset_mode & (PPB_ECP | PPB_EPP)) == 0) {
- /* do not use ECP when the mode is not forced to */
- outb(cio, r | SMC_CR1_MODE);
- if (bootverbose)
- printf(" SPP");
- } else {
- /* an extended mode is selected */
- outb(cio, r & ~SMC_CR1_MODE);
-
- /* read CR4 register and reset mode field */
- outb(csr, 0x4);
- r = inb(cio) & ~SMC_CR4_EMODE;
-
- if (chipset_mode & PPB_ECP) {
- if (chipset_mode & PPB_EPP) {
- outb(cio, r | SMC_ECPEPP);
- if (bootverbose)
- printf(" ECP+EPP");
- } else {
- outb(cio, r | SMC_ECP);
- if (bootverbose)
- printf(" ECP");
- }
- } else {
- /* PPB_EPP is set */
- outb(cio, r | SMC_EPPSPP);
- if (bootverbose)
- printf(" EPP SPP");
- }
- }
- ppc->ppc_avm = chipset_mode;
- }
-
- /* set FIFO threshold to 16 */
- if (ppc->ppc_avm & PPB_ECP) {
- /* select CRA */
- outb(csr, 0xa);
- outb(cio, 16);
- }
-
-end_detect:
-
- if (bootverbose)
- printf ("\n");
-
- if (ppc->ppc_avm & PPB_EPP) {
- /* select CR4 */
- outb(csr, 0x4);
- r = inb(cio);
-
- /*
- * Set the EPP protocol...
- * Low=EPP 1.9 (1284 standard) and High=EPP 1.7
- */
- if (ppc->ppc_epp == EPP_1_9)
- outb(cio, (r & ~SMC_CR4_EPPTYPE));
- else
- outb(cio, (r | SMC_CR4_EPPTYPE));
- }
-
- /* end config mode */
- outb(csr, 0xaa);
-
- ppc->ppc_type = PPC_TYPE_SMCLIKE;
- ppc_smclike_setmode(ppc, chipset_mode);
-
- return (chipset_mode);
-}
-
-/*
- * SMC FDC37C935 configuration
- * Found on many Alpha machines
- */
-static int
-ppc_smc37c935_detect(struct ppc_data *ppc, int chipset_mode)
-{
- int s;
- int type = -1;
-
- s = splhigh();
- outb(SMC935_CFG, 0x55); /* enter config mode */
- outb(SMC935_CFG, 0x55);
- splx(s);
-
- outb(SMC935_IND, SMC935_ID); /* check device id */
- if (inb(SMC935_DAT) == 0x2)
- type = SMC_37C935;
-
- if (type == -1) {
- outb(SMC935_CFG, 0xaa); /* exit config mode */
- return (-1);
- }
-
- ppc->ppc_model = type;
-
- outb(SMC935_IND, SMC935_LOGDEV); /* select parallel port, */
- outb(SMC935_DAT, 3); /* which is logical device 3 */
-
- /* set io port base */
- outb(SMC935_IND, SMC935_PORTHI);
- outb(SMC935_DAT, (u_char)((ppc->ppc_base & 0xff00) >> 8));
- outb(SMC935_IND, SMC935_PORTLO);
- outb(SMC935_DAT, (u_char)(ppc->ppc_base & 0xff));
-
- if (!chipset_mode)
- ppc->ppc_avm = PPB_COMPATIBLE; /* default mode */
- else {
- ppc->ppc_avm = chipset_mode;
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_CENT); /* start in compatible mode */
-
- /* SPP + EPP or just plain SPP */
- if (chipset_mode & (PPB_SPP)) {
- if (chipset_mode & PPB_EPP) {
- if (ppc->ppc_epp == EPP_1_9) {
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_EPP19SPP);
- }
- if (ppc->ppc_epp == EPP_1_7) {
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_EPP17SPP);
- }
- } else {
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_SPP);
- }
- }
-
- /* ECP + EPP or just plain ECP */
- if (chipset_mode & PPB_ECP) {
- if (chipset_mode & PPB_EPP) {
- if (ppc->ppc_epp == EPP_1_9) {
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_ECPEPP19);
- }
- if (ppc->ppc_epp == EPP_1_7) {
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_ECPEPP17);
- }
- } else {
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_ECP);
- }
- }
- }
-
- outb(SMC935_CFG, 0xaa); /* exit config mode */
-
- ppc->ppc_type = PPC_TYPE_SMCLIKE;
- ppc_smclike_setmode(ppc, chipset_mode);
-
- return (chipset_mode);
-}
-
-/*
- * Winbond W83877F stuff
- *
- * EFER: extended function enable register
- * EFIR: extended function index register
- * EFDR: extended function data register
- */
-#define efir ((efer == 0x250) ? 0x251 : 0x3f0)
-#define efdr ((efer == 0x250) ? 0x252 : 0x3f1)
-
-static int w83877f_efers[] = { 0x250, 0x3f0, 0x3f0, 0x250 };
-static int w83877f_keys[] = { 0x89, 0x86, 0x87, 0x88 };
-static int w83877f_keyiter[] = { 1, 2, 2, 1 };
-static int w83877f_hefs[] = { WINB_HEFERE, WINB_HEFRAS, WINB_HEFERE | WINB_HEFRAS, 0 };
-
-static int
-ppc_w83877f_detect(struct ppc_data *ppc, int chipset_mode)
-{
- int i, j, efer;
- unsigned char r, hefere, hefras;
-
- for (i = 0; i < 4; i ++) {
- /* first try to enable configuration registers */
- efer = w83877f_efers[i];
-
- /* write the key to the EFER */
- for (j = 0; j < w83877f_keyiter[i]; j ++)
- outb (efer, w83877f_keys[i]);
-
- /* then check HEFERE and HEFRAS bits */
- outb (efir, 0x0c);
- hefere = inb(efdr) & WINB_HEFERE;
-
- outb (efir, 0x16);
- hefras = inb(efdr) & WINB_HEFRAS;
-
- /*
- * HEFRAS HEFERE
- * 0 1 write 89h to 250h (power-on default)
- * 1 0 write 86h twice to 3f0h
- * 1 1 write 87h twice to 3f0h
- * 0 0 write 88h to 250h
- */
- if ((hefere | hefras) == w83877f_hefs[i])
- goto found;
- }
-
- return (-1); /* failed */
-
-found:
- /* check base port address - read from CR23 */
- outb(efir, 0x23);
- if (ppc->ppc_base != inb(efdr) * 4) /* 4 bytes boundaries */
- return (-1);
-
- /* read CHIP ID from CR9/bits0-3 */
- outb(efir, 0x9);
-
- switch (inb(efdr) & WINB_CHIPID) {
- case WINB_W83877F_ID:
- ppc->ppc_model = WINB_W83877F;
- break;
-
- case WINB_W83877AF_ID:
- ppc->ppc_model = WINB_W83877AF;
- break;
-
- default:
- ppc->ppc_model = WINB_UNKNOWN;
- }
-
- if (bootverbose) {
- /* dump of registers */
- printf("ppc%d: 0x%x - ", ppc->ppc_unit, w83877f_keys[i]);
- for (i = 0; i <= 0xd; i ++) {
- outb(efir, i);
- printf("0x%x ", inb(efdr));
- }
- for (i = 0x10; i <= 0x17; i ++) {
- outb(efir, i);
- printf("0x%x ", inb(efdr));
- }
- outb(efir, 0x1e);
- printf("0x%x ", inb(efdr));
- for (i = 0x20; i <= 0x29; i ++) {
- outb(efir, i);
- printf("0x%x ", inb(efdr));
- }
- printf("\n");
- printf("ppc%d:", ppc->ppc_unit);
- }
-
- ppc->ppc_type = PPC_TYPE_GENERIC;
-
- if (!chipset_mode) {
- /* autodetect mode */
-
- /* select CR0 */
- outb(efir, 0x0);
- r = inb(efdr) & (WINB_PRTMODS0 | WINB_PRTMODS1);
-
- /* select CR9 */
- outb(efir, 0x9);
- r |= (inb(efdr) & WINB_PRTMODS2);
-
- switch (r) {
- case WINB_W83757:
- if (bootverbose)
- printf("ppc%d: W83757 compatible mode\n",
- ppc->ppc_unit);
- return (-1); /* generic or SMC-like */
-
- case WINB_EXTFDC:
- case WINB_EXTADP:
- case WINB_EXT2FDD:
- case WINB_JOYSTICK:
- if (bootverbose)
- printf(" not in parallel port mode\n");
- return (-1);
-
- case (WINB_PARALLEL | WINB_EPP_SPP):
- ppc->ppc_avm |= PPB_EPP | PPB_SPP;
- if (bootverbose)
- printf(" EPP SPP");
- break;
-
- case (WINB_PARALLEL | WINB_ECP):
- ppc->ppc_avm |= PPB_ECP | PPB_SPP;
- if (bootverbose)
- printf(" ECP SPP");
- break;
-
- case (WINB_PARALLEL | WINB_ECP_EPP):
- ppc->ppc_avm |= PPB_ECP | PPB_EPP | PPB_SPP;
- ppc->ppc_type = PPC_TYPE_SMCLIKE;
-
- if (bootverbose)
- printf(" ECP+EPP SPP");
- break;
- default:
- printf("%s: unknown case (0x%x)!\n", __func__, r);
- }
-
- } else {
- /* mode forced */
-
- /* select CR9 and set PRTMODS2 bit */
- outb(efir, 0x9);
- outb(efdr, inb(efdr) & ~WINB_PRTMODS2);
-
- /* select CR0 and reset PRTMODSx bits */
- outb(efir, 0x0);
- outb(efdr, inb(efdr) & ~(WINB_PRTMODS0 | WINB_PRTMODS1));
-
- if (chipset_mode & PPB_ECP) {
- if (chipset_mode & PPB_EPP) {
- outb(efdr, inb(efdr) | WINB_ECP_EPP);
- if (bootverbose)
- printf(" ECP+EPP");
-
- ppc->ppc_type = PPC_TYPE_SMCLIKE;
-
- } else {
- outb(efdr, inb(efdr) | WINB_ECP);
- if (bootverbose)
- printf(" ECP");
- }
- } else {
- /* select EPP_SPP otherwise */
- outb(efdr, inb(efdr) | WINB_EPP_SPP);
- if (bootverbose)
- printf(" EPP SPP");
- }
- ppc->ppc_avm = chipset_mode;
- }
-
- if (bootverbose)
- printf("\n");
-
- /* exit configuration mode */
- outb(efer, 0xaa);
-
- switch (ppc->ppc_type) {
- case PPC_TYPE_SMCLIKE:
- ppc_smclike_setmode(ppc, chipset_mode);
- break;
- default:
- ppc_generic_setmode(ppc, chipset_mode);
- break;
- }
-
- return (chipset_mode);
-}
-#endif
-
-/*
- * ppc_generic_detect
- */
-static int
-ppc_generic_detect(struct ppc_data *ppc, int chipset_mode)
-{
- /* default to generic */
- ppc->ppc_type = PPC_TYPE_GENERIC;
-
- if (bootverbose)
- printf("ppc%d:", ppc->ppc_unit);
-
- /* first, check for ECP */
- w_ecr(ppc, PPC_ECR_PS2);
- if ((r_ecr(ppc) & 0xe0) == PPC_ECR_PS2) {
- ppc->ppc_dtm |= PPB_ECP | PPB_SPP;
- if (bootverbose)
- printf(" ECP SPP");
-
- /* search for SMC style ECP+EPP mode */
- w_ecr(ppc, PPC_ECR_EPP);
- }
-
- /* try to reset EPP timeout bit */
- if (ppc_check_epp_timeout(ppc)) {
- ppc->ppc_dtm |= PPB_EPP;
-
- if (ppc->ppc_dtm & PPB_ECP) {
- /* SMC like chipset found */
- ppc->ppc_model = SMC_LIKE;
- ppc->ppc_type = PPC_TYPE_SMCLIKE;
-
- if (bootverbose)
- printf(" ECP+EPP");
- } else {
- if (bootverbose)
- printf(" EPP");
- }
- } else {
- /* restore to standard mode */
- w_ecr(ppc, PPC_ECR_STD);
- }
-
- /* XXX try to detect NIBBLE and PS2 modes */
- ppc->ppc_dtm |= PPB_NIBBLE;
-
- if (bootverbose)
- printf(" SPP");
-
- if (chipset_mode)
- ppc->ppc_avm = chipset_mode;
- else
- ppc->ppc_avm = ppc->ppc_dtm;
-
- if (bootverbose)
- printf("\n");
-
- switch (ppc->ppc_type) {
- case PPC_TYPE_SMCLIKE:
- ppc_smclike_setmode(ppc, chipset_mode);
- break;
- default:
- ppc_generic_setmode(ppc, chipset_mode);
- break;
- }
-
- return (chipset_mode);
-}
-
-/*
- * ppc_detect()
- *
- * mode is the mode suggested at boot
- */
-static int
-ppc_detect(struct ppc_data *ppc, int chipset_mode) {
-
-#ifdef PPC_PROBE_CHIPSET
- int i, mode;
-
- /* list of supported chipsets */
- int (*chipset_detect[])(struct ppc_data *, int) = {
- ppc_pc873xx_detect,
- ppc_smc37c66xgt_detect,
- ppc_w83877f_detect,
- ppc_smc37c935_detect,
- ppc_generic_detect,
- NULL
- };
-#endif
-
- /* if can't find the port and mode not forced return error */
- if (!ppc_detect_port(ppc) && chipset_mode == 0)
- return (EIO); /* failed, port not present */
-
- /* assume centronics compatible mode is supported */
- ppc->ppc_avm = PPB_COMPATIBLE;
-
-#ifdef PPC_PROBE_CHIPSET
- /* we have to differenciate available chipset modes,
- * chipset running modes and IEEE-1284 operating modes
- *
- * after detection, the port must support running in compatible mode
- */
- if (ppc->ppc_flags & 0x40) {
- if (bootverbose)
- printf("ppc: chipset forced to generic\n");
-#endif
-
- ppc->ppc_mode = ppc_generic_detect(ppc, chipset_mode);
-
-#ifdef PPC_PROBE_CHIPSET
- } else {
- for (i=0; chipset_detect[i] != NULL; i++) {
- if ((mode = chipset_detect[i](ppc, chipset_mode)) != -1) {
- ppc->ppc_mode = mode;
- break;
- }
- }
- }
-#endif
-
- /* configure/detect ECP FIFO */
- if ((ppc->ppc_avm & PPB_ECP) && !(ppc->ppc_flags & 0x80))
- ppc_detect_fifo(ppc);
-
- return (0);
-}
-
-/*
- * ppc_exec_microseq()
- *
- * Execute a microsequence.
- * Microsequence mechanism is supposed to handle fast I/O operations.
- */
-static int
-ppc_exec_microseq(device_t dev, struct ppb_microseq **p_msq)
-{
- struct ppc_data *ppc = DEVTOSOFTC(dev);
- struct ppb_microseq *mi;
- char cc, *p;
- int i, iter, len;
- int error;
-
- register int reg;
- register char mask;
- register int accum = 0;
- register char *ptr = 0;
-
- struct ppb_microseq *stack = 0;
-
-/* microsequence registers are equivalent to PC-like port registers */
-
-#define r_reg(register,ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, register))
-#define w_reg(register, ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, register, byte))
-
-#define INCR_PC (mi ++) /* increment program counter */
-
- mi = *p_msq;
- for (;;) {
- switch (mi->opcode) {
- case MS_OP_RSET:
- cc = r_reg(mi->arg[0].i, ppc);
- cc &= (char)mi->arg[2].i; /* clear mask */
- cc |= (char)mi->arg[1].i; /* assert mask */
- w_reg(mi->arg[0].i, ppc, cc);
- INCR_PC;
- break;
-
- case MS_OP_RASSERT_P:
- reg = mi->arg[1].i;
- ptr = ppc->ppc_ptr;
-
- if ((len = mi->arg[0].i) == MS_ACCUM) {
- accum = ppc->ppc_accum;
- for (; accum; accum--)
- w_reg(reg, ppc, *ptr++);
- ppc->ppc_accum = accum;
- } else
- for (i=0; i<len; i++)
- w_reg(reg, ppc, *ptr++);
- ppc->ppc_ptr = ptr;
-
- INCR_PC;
- break;
-
- case MS_OP_RFETCH_P:
- reg = mi->arg[1].i;
- mask = (char)mi->arg[2].i;
- ptr = ppc->ppc_ptr;
-
- if ((len = mi->arg[0].i) == MS_ACCUM) {
- accum = ppc->ppc_accum;
- for (; accum; accum--)
- *ptr++ = r_reg(reg, ppc) & mask;
- ppc->ppc_accum = accum;
- } else
- for (i=0; i<len; i++)
- *ptr++ = r_reg(reg, ppc) & mask;
- ppc->ppc_ptr = ptr;
-
- INCR_PC;
- break;
-
- case MS_OP_RFETCH:
- *((char *) mi->arg[2].p) = r_reg(mi->arg[0].i, ppc) &
- (char)mi->arg[1].i;
- INCR_PC;
- break;
-
- case MS_OP_RASSERT:
- case MS_OP_DELAY:
-
- /* let's suppose the next instr. is the same */
- prefetch:
- for (;mi->opcode == MS_OP_RASSERT; INCR_PC)
- w_reg(mi->arg[0].i, ppc, (char)mi->arg[1].i);
-
- if (mi->opcode == MS_OP_DELAY) {
- DELAY(mi->arg[0].i);
- INCR_PC;
- goto prefetch;
- }
- break;
-
- case MS_OP_ADELAY:
- if (mi->arg[0].i)
- tsleep(NULL, PPBPRI, "ppbdelay",
- mi->arg[0].i * (hz/1000));
- INCR_PC;
- break;
-
- case MS_OP_TRIG:
- reg = mi->arg[0].i;
- iter = mi->arg[1].i;
- p = (char *)mi->arg[2].p;
-
- /* XXX delay limited to 255 us */
- for (i=0; i<iter; i++) {
- w_reg(reg, ppc, *p++);
- DELAY((unsigned char)*p++);
- }
- INCR_PC;
- break;
-
- case MS_OP_SET:
- ppc->ppc_accum = mi->arg[0].i;
- INCR_PC;
- break;
-
- case MS_OP_DBRA:
- if (--ppc->ppc_accum > 0)
- mi += mi->arg[0].i;
- INCR_PC;
- break;
-
- case MS_OP_BRSET:
- cc = r_str(ppc);
- if ((cc & (char)mi->arg[0].i) == (char)mi->arg[0].i)
- mi += mi->arg[1].i;
- INCR_PC;
- break;
-
- case MS_OP_BRCLEAR:
- cc = r_str(ppc);
- if ((cc & (char)mi->arg[0].i) == 0)
- mi += mi->arg[1].i;
- INCR_PC;
- break;
-
- case MS_OP_BRSTAT:
- cc = r_str(ppc);
- if ((cc & ((char)mi->arg[0].i | (char)mi->arg[1].i)) ==
- (char)mi->arg[0].i)
- mi += mi->arg[2].i;
- INCR_PC;
- break;
-
- case MS_OP_C_CALL:
- /*
- * If the C call returns !0 then end the microseq.
- * The current state of ptr is passed to the C function
- */
- if ((error = mi->arg[0].f(mi->arg[1].p, ppc->ppc_ptr)))
- return (error);
-
- INCR_PC;
- break;
-
- case MS_OP_PTR:
- ppc->ppc_ptr = (char *)mi->arg[0].p;
- INCR_PC;
- break;
-
- case MS_OP_CALL:
- if (stack)
- panic("%s: too much calls", __func__);
-
- if (mi->arg[0].p) {
- /* store the state of the actual
- * microsequence
- */
- stack = mi;
-
- /* jump to the new microsequence */
- mi = (struct ppb_microseq *)mi->arg[0].p;
- } else
- INCR_PC;
-
- break;
-
- case MS_OP_SUBRET:
- /* retrieve microseq and pc state before the call */
- mi = stack;
-
- /* reset the stack */
- stack = 0;
-
- /* XXX return code */
-
- INCR_PC;
- break;
-
- case MS_OP_PUT:
- case MS_OP_GET:
- case MS_OP_RET:
- /* can't return to ppb level during the execution
- * of a submicrosequence */
- if (stack)
- panic("%s: can't return to ppb level",
- __func__);
-
- /* update pc for ppb level of execution */
- *p_msq = mi;
-
- /* return to ppb level of execution */
- return (0);
-
- default:
- panic("%s: unknown microsequence opcode 0x%x",
- __func__, mi->opcode);
- }
- }
-
- /* unreached */
-}
-
-static void
-ppcintr(void *arg)
-{
- device_t dev = (device_t)arg;
- struct ppc_data *ppc = (struct ppc_data *)device_get_softc(dev);
- u_char ctr, ecr, str;
-
- str = r_str(ppc);
- ctr = r_ctr(ppc);
- ecr = r_ecr(ppc);
-
-#if PPC_DEBUG > 1
- printf("![%x/%x/%x]", ctr, ecr, str);
-#endif
-
- /* don't use ecp mode with IRQENABLE set */
- if (ctr & IRQENABLE) {
- return;
- }
-
- /* interrupts are generated by nFault signal
- * only in ECP mode */
- if ((str & nFAULT) && (ppc->ppc_mode & PPB_ECP)) {
- /* check if ppc driver has programmed the
- * nFault interrupt */
- if (ppc->ppc_irqstat & PPC_IRQ_nFAULT) {
-
- w_ecr(ppc, ecr | PPC_nFAULT_INTR);
- ppc->ppc_irqstat &= ~PPC_IRQ_nFAULT;
- } else {
- /* shall be handled by underlying layers XXX */
- return;
- }
- }
-
- if (ppc->ppc_irqstat & PPC_IRQ_DMA) {
- /* disable interrupts (should be done by hardware though) */
- w_ecr(ppc, ecr | PPC_SERVICE_INTR);
- ppc->ppc_irqstat &= ~PPC_IRQ_DMA;
- ecr = r_ecr(ppc);
-
- /* check if DMA completed */
- if ((ppc->ppc_avm & PPB_ECP) && (ecr & PPC_ENABLE_DMA)) {
-#ifdef PPC_DEBUG
- printf("a");
-#endif
- /* stop DMA */
- w_ecr(ppc, ecr & ~PPC_ENABLE_DMA);
- ecr = r_ecr(ppc);
-
- if (ppc->ppc_dmastat == PPC_DMA_STARTED) {
-#ifdef PPC_DEBUG
- printf("d");
-#endif
- isa_dmadone(
- ppc->ppc_dmaflags,
- ppc->ppc_dmaddr,
- ppc->ppc_dmacnt,
- ppc->ppc_dmachan);
-
- ppc->ppc_dmastat = PPC_DMA_COMPLETE;
-
- /* wakeup the waiting process */
- wakeup(ppc);
- }
- }
- } else if (ppc->ppc_irqstat & PPC_IRQ_FIFO) {
-
- /* classic interrupt I/O */
- ppc->ppc_irqstat &= ~PPC_IRQ_FIFO;
- }
-
- return;
-}
-
-static int
-ppc_read(device_t dev, char *buf, int len, int mode)
-{
- return (EINVAL);
-}
-
-/*
- * Call this function if you want to send data in any advanced mode
- * of your parallel port: FIFO, DMA
- *
- * If what you want is not possible (no ECP, no DMA...),
- * EINVAL is returned
- */
-static int
-ppc_write(device_t dev, char *buf, int len, int how)
-{
- struct ppc_data *ppc = DEVTOSOFTC(dev);
- char ecr, ecr_sav, ctr, ctr_sav;
- int s, error = 0;
- int spin;
-
-#ifdef PPC_DEBUG
- printf("w");
-#endif
-
- ecr_sav = r_ecr(ppc);
- ctr_sav = r_ctr(ppc);
-
- /*
- * Send buffer with DMA, FIFO and interrupts
- */
- if ((ppc->ppc_avm & PPB_ECP) && (ppc->ppc_registered)) {
-
- if (ppc->ppc_dmachan > 0) {
-
- /* byte mode, no intr, no DMA, dir=0, flush fifo
- */
- ecr = PPC_ECR_STD | PPC_DISABLE_INTR;
- w_ecr(ppc, ecr);
-
- /* disable nAck interrupts */
- ctr = r_ctr(ppc);
- ctr &= ~IRQENABLE;
- w_ctr(ppc, ctr);
-
- ppc->ppc_dmaflags = 0;
- ppc->ppc_dmaddr = (caddr_t)buf;
- ppc->ppc_dmacnt = (u_int)len;
-
- switch (ppc->ppc_mode) {
- case PPB_COMPATIBLE:
- /* compatible mode with FIFO, no intr, DMA, dir=0 */
- ecr = PPC_ECR_FIFO | PPC_DISABLE_INTR | PPC_ENABLE_DMA;
- break;
- case PPB_ECP:
- ecr = PPC_ECR_ECP | PPC_DISABLE_INTR | PPC_ENABLE_DMA;
- break;
- default:
- error = EINVAL;
- goto error;
- }
-
- w_ecr(ppc, ecr);
- ecr = r_ecr(ppc);
-
- /* enter splhigh() not to be preempted
- * by the dma interrupt, we may miss
- * the wakeup otherwise
- */
- s = splhigh();
-
- ppc->ppc_dmastat = PPC_DMA_INIT;
-
- /* enable interrupts */
- ecr &= ~PPC_SERVICE_INTR;
- ppc->ppc_irqstat = PPC_IRQ_DMA;
- w_ecr(ppc, ecr);
-
- isa_dmastart(
- ppc->ppc_dmaflags,
- ppc->ppc_dmaddr,
- ppc->ppc_dmacnt,
- ppc->ppc_dmachan);
-#ifdef PPC_DEBUG
- printf("s%d", ppc->ppc_dmacnt);
-#endif
- ppc->ppc_dmastat = PPC_DMA_STARTED;
-
- /* Wait for the DMA completed interrupt. We hope we won't
- * miss it, otherwise a signal will be necessary to unlock the
- * process.
- */
- do {
- /* release CPU */
- error = tsleep(ppc,
- PPBPRI | PCATCH, "ppcdma", 0);
-
- } while (error == EWOULDBLOCK);
-
- splx(s);
-
- if (error) {
-#ifdef PPC_DEBUG
- printf("i");
-#endif
- /* stop DMA */
- isa_dmadone(
- ppc->ppc_dmaflags, ppc->ppc_dmaddr,
- ppc->ppc_dmacnt, ppc->ppc_dmachan);
-
- /* no dma, no interrupt, flush the fifo */
- w_ecr(ppc, PPC_ECR_RESET);
-
- ppc->ppc_dmastat = PPC_DMA_INTERRUPTED;
- goto error;
- }
-
- /* wait for an empty fifo */
- while (!(r_ecr(ppc) & PPC_FIFO_EMPTY)) {
-
- for (spin=100; spin; spin--)
- if (r_ecr(ppc) & PPC_FIFO_EMPTY)
- goto fifo_empty;
-#ifdef PPC_DEBUG
- printf("Z");
-#endif
- error = tsleep(ppc, PPBPRI | PCATCH, "ppcfifo", hz/100);
- if (error != EWOULDBLOCK) {
-#ifdef PPC_DEBUG
- printf("I");
-#endif
- /* no dma, no interrupt, flush the fifo */
- w_ecr(ppc, PPC_ECR_RESET);
-
- ppc->ppc_dmastat = PPC_DMA_INTERRUPTED;
- error = EINTR;
- goto error;
- }
- }
-
-fifo_empty:
- /* no dma, no interrupt, flush the fifo */
- w_ecr(ppc, PPC_ECR_RESET);
-
- } else
- error = EINVAL; /* XXX we should FIFO and
- * interrupts */
- } else
- error = EINVAL;
-
-error:
-
- /* PDRQ must be kept unasserted until nPDACK is
- * deasserted for a minimum of 350ns (SMC datasheet)
- *
- * Consequence may be a FIFO that never empty
- */
- DELAY(1);
-
- w_ecr(ppc, ecr_sav);
- w_ctr(ppc, ctr_sav);
-
- return (error);
-}
-
-static void
-ppc_reset_epp(device_t dev)
-{
- struct ppc_data *ppc = DEVTOSOFTC(dev);
-
- ppc_reset_epp_timeout(ppc);
-
- return;
-}
-
-static int
-ppc_setmode(device_t dev, int mode)
-{
- struct ppc_data *ppc = DEVTOSOFTC(dev);
-
- switch (ppc->ppc_type) {
- case PPC_TYPE_SMCLIKE:
- return (ppc_smclike_setmode(ppc, mode));
- break;
-
- case PPC_TYPE_GENERIC:
- default:
- return (ppc_generic_setmode(ppc, mode));
- break;
- }
-
- /* not reached */
- return (ENXIO);
-}
-
-static struct isa_pnp_id lpc_ids[] = {
- { 0x0004d041, "Standard parallel printer port" }, /* PNP0400 */
- { 0x0104d041, "ECP parallel printer port" }, /* PNP0401 */
- { 0 }
-};
-
-static int
-ppc_probe(device_t dev)
-{
-#ifdef __i386__
- static short next_bios_ppc = 0;
-#endif
- struct ppc_data *ppc;
- device_t parent;
- int error;
- u_long port;
-
- parent = device_get_parent(dev);
-
- error = ISA_PNP_PROBE(parent, dev, lpc_ids);
- if (error == ENXIO)
- return (ENXIO);
- else if (error != 0) /* XXX shall be set after detection */
- device_set_desc(dev, "Parallel port");
-
- /*
- * Allocate the ppc_data structure.
- */
- ppc = DEVTOSOFTC(dev);
- bzero(ppc, sizeof(struct ppc_data));
-
- ppc->rid_irq = ppc->rid_drq = ppc->rid_ioport = 0;
- ppc->res_irq = ppc->res_drq = ppc->res_ioport = 0;
-
- /* retrieve ISA parameters */
- error = bus_get_resource(dev, SYS_RES_IOPORT, 0, &port, NULL);
-
-#ifdef __i386__
- /*
- * If port not specified, use bios list.
- */
- if (error) {
- if((next_bios_ppc < BIOS_MAX_PPC) &&
- (*(BIOS_PORTS+next_bios_ppc) != 0) ) {
- port = *(BIOS_PORTS+next_bios_ppc++);
- if (bootverbose)
- device_printf(dev, "parallel port found at 0x%x\n",
- (int) port);
- } else {
- device_printf(dev, "parallel port not found.\n");
- return ENXIO;
- }
- bus_set_resource(dev, SYS_RES_IOPORT, 0, port,
- IO_LPTSIZE_EXTENDED);
- }
-#endif
-#ifdef __alpha__
- /*
- * There isn't a bios list on alpha. Put it in the usual place.
- */
- if (error) {
- bus_set_resource(dev, SYS_RES_IOPORT, 0, 0x3bc,
- IO_LPTSIZE_NORMAL);
- }
-#endif
-
- /* IO port is mandatory */
-
- /* Try "extended" IO port range...*/
- ppc->res_ioport = bus_alloc_resource(dev, SYS_RES_IOPORT,
- &ppc->rid_ioport, 0, ~0,
- IO_LPTSIZE_EXTENDED, RF_ACTIVE);
-
- if (ppc->res_ioport != 0) {
- if (bootverbose)
- device_printf(dev, "using extended I/O port range\n");
- } else {
- /* Failed? If so, then try the "normal" IO port range... */
- ppc->res_ioport = bus_alloc_resource(dev, SYS_RES_IOPORT,
- &ppc->rid_ioport, 0, ~0,
- IO_LPTSIZE_NORMAL,
- RF_ACTIVE);
- if (ppc->res_ioport != 0) {
- if (bootverbose)
- device_printf(dev, "using normal I/O port range\n");
- } else {
- device_printf(dev, "cannot reserve I/O port range\n");
- goto error;
- }
- }
-
- ppc->ppc_base = rman_get_start(ppc->res_ioport);
-
- ppc->bsh = rman_get_bushandle(ppc->res_ioport);
- ppc->bst = rman_get_bustag(ppc->res_ioport);
-
- ppc->ppc_flags = device_get_flags(dev);
-
- if (!(ppc->ppc_flags & 0x20)) {
- ppc->res_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &ppc->rid_irq,
- 0ul, ~0ul, 1, RF_SHAREABLE);
- ppc->res_drq = bus_alloc_resource(dev, SYS_RES_DRQ, &ppc->rid_drq,
- 0ul, ~0ul, 1, RF_ACTIVE);
- }
-
- if (ppc->res_irq)
- ppc->ppc_irq = rman_get_start(ppc->res_irq);
- if (ppc->res_drq)
- ppc->ppc_dmachan = rman_get_start(ppc->res_drq);
-
- ppc->ppc_unit = device_get_unit(dev);
- ppc->ppc_model = GENERIC;
-
- ppc->ppc_mode = PPB_COMPATIBLE;
- ppc->ppc_epp = (ppc->ppc_flags & 0x10) >> 4;
-
- ppc->ppc_type = PPC_TYPE_GENERIC;
-
- /*
- * Try to detect the chipset and its mode.
- */
- if (ppc_detect(ppc, ppc->ppc_flags & 0xf))
- goto error;
-
- return (0);
-
-error:
- if (ppc->res_irq != 0) {
- bus_release_resource(dev, SYS_RES_IRQ, ppc->rid_irq,
- ppc->res_irq);
- }
- if (ppc->res_ioport != 0) {
- bus_deactivate_resource(dev, SYS_RES_IOPORT, ppc->rid_ioport,
- ppc->res_ioport);
- bus_release_resource(dev, SYS_RES_IOPORT, ppc->rid_ioport,
- ppc->res_ioport);
- }
- if (ppc->res_drq != 0) {
- bus_deactivate_resource(dev, SYS_RES_DRQ, ppc->rid_drq,
- ppc->res_drq);
- bus_release_resource(dev, SYS_RES_DRQ, ppc->rid_drq,
- ppc->res_drq);
- }
- return (ENXIO);
-}
-
-static int
-ppc_attach(device_t dev)
-{
- struct ppc_data *ppc = DEVTOSOFTC(dev);
-
- device_t ppbus;
- device_t parent = device_get_parent(dev);
-
- device_printf(dev, "%s chipset (%s) in %s mode%s\n",
- ppc_models[ppc->ppc_model], ppc_avms[ppc->ppc_avm],
- ppc_modes[ppc->ppc_mode], (PPB_IS_EPP(ppc->ppc_mode)) ?
- ppc_epp_protocol[ppc->ppc_epp] : "");
-
- if (ppc->ppc_fifo)
- device_printf(dev, "FIFO with %d/%d/%d bytes threshold\n",
- ppc->ppc_fifo, ppc->ppc_wthr, ppc->ppc_rthr);
-
- if ((ppc->ppc_avm & PPB_ECP) && (ppc->ppc_dmachan > 0)) {
- /* acquire the DMA channel forever */ /* XXX */
- isa_dma_acquire(ppc->ppc_dmachan);
- isa_dmainit(ppc->ppc_dmachan, 1024); /* nlpt.BUFSIZE */
- }
-
- /* add ppbus as a child of this isa to parallel bridge */
- ppbus = device_add_child(dev, "ppbus", -1);
-
- /*
- * Probe the ppbus and attach devices found.
- */
- device_probe_and_attach(ppbus);
-
- /* register the ppc interrupt handler as default */
- if (ppc->res_irq) {
- /* default to the tty mask for registration */ /* XXX */
- if (BUS_SETUP_INTR(parent, dev, ppc->res_irq, INTR_TYPE_TTY,
- ppcintr, dev, &ppc->intr_cookie) == 0) {
-
- /* remember the ppcintr is registered */
- ppc->ppc_registered = 1;
- }
- }
-
- return (0);
-}
-
-static u_char
-ppc_io(device_t ppcdev, int iop, u_char *addr, int cnt, u_char byte)
-{
- struct ppc_data *ppc = DEVTOSOFTC(ppcdev);
- switch (iop) {
- case PPB_OUTSB_EPP:
- bus_space_write_multi_1(ppc->bst, ppc->bsh, PPC_EPP_DATA, addr, cnt);
- break;
- case PPB_OUTSW_EPP:
- bus_space_write_multi_2(ppc->bst, ppc->bsh, PPC_EPP_DATA, (u_int16_t *)addr, cnt);
- break;
- case PPB_OUTSL_EPP:
- bus_space_write_multi_4(ppc->bst, ppc->bsh, PPC_EPP_DATA, (u_int32_t *)addr, cnt);
- break;
- case PPB_INSB_EPP:
- bus_space_read_multi_1(ppc->bst, ppc->bsh, PPC_EPP_DATA, addr, cnt);
- break;
- case PPB_INSW_EPP:
- bus_space_read_multi_2(ppc->bst, ppc->bsh, PPC_EPP_DATA, (u_int16_t *)addr, cnt);
- break;
- case PPB_INSL_EPP:
- bus_space_read_multi_4(ppc->bst, ppc->bsh, PPC_EPP_DATA, (u_int32_t *)addr, cnt);
- break;
- case PPB_RDTR:
- return (r_dtr(ppc));
- break;
- case PPB_RSTR:
- return (r_str(ppc));
- break;
- case PPB_RCTR:
- return (r_ctr(ppc));
- break;
- case PPB_REPP_A:
- return (r_epp_A(ppc));
- break;
- case PPB_REPP_D:
- return (r_epp_D(ppc));
- break;
- case PPB_RECR:
- return (r_ecr(ppc));
- break;
- case PPB_RFIFO:
- return (r_fifo(ppc));
- break;
- case PPB_WDTR:
- w_dtr(ppc, byte);
- break;
- case PPB_WSTR:
- w_str(ppc, byte);
- break;
- case PPB_WCTR:
- w_ctr(ppc, byte);
- break;
- case PPB_WEPP_A:
- w_epp_A(ppc, byte);
- break;
- case PPB_WEPP_D:
- w_epp_D(ppc, byte);
- break;
- case PPB_WECR:
- w_ecr(ppc, byte);
- break;
- case PPB_WFIFO:
- w_fifo(ppc, byte);
- break;
- default:
- panic("%s: unknown I/O operation", __func__);
- break;
- }
-
- return (0); /* not significative */
-}
-
-static int
-ppc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
-{
- struct ppc_data *ppc = (struct ppc_data *)device_get_softc(bus);
-
- switch (index) {
- case PPC_IVAR_EPP_PROTO:
- *val = (u_long)ppc->ppc_epp;
- break;
- case PPC_IVAR_IRQ:
- *val = (u_long)ppc->ppc_irq;
- break;
- default:
- return (ENOENT);
- }
-
- return (0);
-}
-
-/*
- * Resource is useless here since ppbus devices' interrupt handlers are
- * multiplexed to the same resource initially allocated by ppc
- */
-static int
-ppc_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
- void (*ihand)(void *), void *arg, void **cookiep)
-{
- int error;
- struct ppc_data *ppc = DEVTOSOFTC(bus);
-
- if (ppc->ppc_registered) {
- /* XXX refuse registration if DMA is in progress */
-
- /* first, unregister the default interrupt handler */
- if ((error = BUS_TEARDOWN_INTR(device_get_parent(bus),
- bus, ppc->res_irq, ppc->intr_cookie)))
- return (error);
-
-/* bus_deactivate_resource(bus, SYS_RES_IRQ, ppc->rid_irq, */
-/* ppc->res_irq); */
-
- /* DMA/FIFO operation won't be possible anymore */
- ppc->ppc_registered = 0;
- }
-
- /* pass registration to the upper layer, ignore the incoming resource */
- return (BUS_SETUP_INTR(device_get_parent(bus), child,
- r, flags, ihand, arg, cookiep));
-}
-
-/*
- * When no underlying device has a registered interrupt, register the ppc
- * layer one
- */
-static int
-ppc_teardown_intr(device_t bus, device_t child, struct resource *r, void *ih)
-{
- int error;
- struct ppc_data *ppc = DEVTOSOFTC(bus);
- device_t parent = device_get_parent(bus);
-
- /* pass unregistration to the upper layer */
- if ((error = BUS_TEARDOWN_INTR(parent, child, r, ih)))
- return (error);
-
- /* default to the tty mask for registration */ /* XXX */
- if (ppc->ppc_irq &&
- !(error = BUS_SETUP_INTR(parent, bus, ppc->res_irq,
- INTR_TYPE_TTY, ppcintr, bus, &ppc->intr_cookie))) {
-
- /* remember the ppcintr is registered */
- ppc->ppc_registered = 1;
- }
-
- return (error);
-}
-
-DRIVER_MODULE(ppc, isa, ppc_driver, ppc_devclass, 0, 0);
-DRIVER_MODULE(ppc, acpi, ppc_driver, ppc_devclass, 0, 0);
diff --git a/sys/dev/ppc/ppcreg.h b/sys/dev/ppc/ppcreg.h
deleted file mode 100644
index ea12ead9c417..000000000000
--- a/sys/dev/ppc/ppcreg.h
+++ /dev/null
@@ -1,272 +0,0 @@
-/*-
- * Copyright (c) 2001 Alcove - Nicolas Souchu
- * 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 __PPCREG_H
-#define __PPCREG_H
-
-/*
- * Parallel Port Chipset type.
- */
-#define SMC_LIKE 0
-#define SMC_37C665GT 1
-#define SMC_37C666GT 2
-#define NS_PC87332 3
-#define NS_PC87306 4
-#define INTEL_820191AA 5 /* XXX not implemented */
-#define GENERIC 6
-#define WINB_W83877F 7
-#define WINB_W83877AF 8
-#define WINB_UNKNOWN 9
-#define NS_PC87334 10
-#define SMC_37C935 11
-#define NS_PC87303 12
-
-/*
- * Parallel Port Chipset Type. SMC versus GENERIC (others)
- */
-#define PPC_TYPE_SMCLIKE 0
-#define PPC_TYPE_GENERIC 1
-
-/*
- * Generic structure to hold parallel port chipset info.
- */
-struct ppc_data {
-
- int ppc_unit;
- int ppc_model; /* chipset model if detected */
- int ppc_type; /* generic or smclike chipset type */
-
- int ppc_mode; /* chipset current mode */
- int ppc_avm; /* chipset available modes */
- int ppc_dtm; /* chipset detected modes */
-
-#define PPC_IRQ_NONE 0x0
-#define PPC_IRQ_nACK 0x1
-#define PPC_IRQ_DMA 0x2
-#define PPC_IRQ_FIFO 0x4
-#define PPC_IRQ_nFAULT 0x8
- int ppc_irqstat; /* remind irq settings */
-
-#define PPC_DMA_INIT 0x01
-#define PPC_DMA_STARTED 0x02
-#define PPC_DMA_COMPLETE 0x03
-#define PPC_DMA_INTERRUPTED 0x04
-#define PPC_DMA_ERROR 0x05
- int ppc_dmastat; /* dma state */
- int ppc_dmachan; /* dma channel */
- int ppc_dmaflags; /* dma transfer flags */
- caddr_t ppc_dmaddr; /* buffer address */
- u_int ppc_dmacnt; /* count of bytes sent with dma */
-
-#define PPC_PWORD_MASK 0x30
-#define PPC_PWORD_16 0x00
-#define PPC_PWORD_8 0x10
-#define PPC_PWORD_32 0x20
- char ppc_pword; /* PWord size */
- short ppc_fifo; /* FIFO threshold */
-
- short ppc_wthr; /* writeIntrThresold */
- short ppc_rthr; /* readIntrThresold */
-
- char *ppc_ptr; /* microseq current pointer */
- int ppc_accum; /* microseq accumulator */
- int ppc_base; /* parallel port base address */
- int ppc_epp; /* EPP mode (1.7 or 1.9) */
- int ppc_irq;
-
- unsigned char ppc_flags;
-
- device_t ppbus; /* parallel port chipset corresponding ppbus */
-
- int rid_irq, rid_drq, rid_ioport;
- struct resource *res_irq, *res_drq, *res_ioport;
-
- bus_space_handle_t bsh;
- bus_space_tag_t bst;
-
- void *intr_cookie;
-
- int ppc_registered; /* 1 if ppcintr() is the registered interrupt */
-};
-
-/*
- * Parallel Port Chipset registers.
- */
-#define PPC_SPP_DTR 0 /* SPP data register */
-#define PPC_ECP_A_FIFO 0 /* ECP Address fifo register */
-#define PPC_SPP_STR 1 /* SPP status register */
-#define PPC_SPP_CTR 2 /* SPP control register */
-#define PPC_EPP_ADDR 3 /* EPP address register (8 bit) */
-#define PPC_EPP_DATA 4 /* EPP data register (8, 16 or 32 bit) */
-#define PPC_ECP_D_FIFO 0x400 /* ECP Data fifo register */
-#define PPC_ECP_CNFGA 0x400 /* Configuration register A */
-#define PPC_ECP_CNFGB 0x401 /* Configuration register B */
-#define PPC_ECP_ECR 0x402 /* ECP extended control register */
-
-#define PPC_FIFO_EMPTY 0x1 /* ecr register - bit 0 */
-#define PPC_FIFO_FULL 0x2 /* ecr register - bit 1 */
-#define PPC_SERVICE_INTR 0x4 /* ecr register - bit 2 */
-#define PPC_ENABLE_DMA 0x8 /* ecr register - bit 3 */
-#define PPC_nFAULT_INTR 0x10 /* ecr register - bit 4 */
-#define PPC_ECR_STD 0x0
-#define PPC_ECR_PS2 0x20
-#define PPC_ECR_FIFO 0x40
-#define PPC_ECR_ECP 0x60
-#define PPC_ECR_EPP 0x80
-
-#define PPC_DISABLE_INTR (PPC_SERVICE_INTR | PPC_nFAULT_INTR)
-#define PPC_ECR_RESET (PPC_ECR_PS2 | PPC_DISABLE_INTR)
-
-#define r_dtr(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_SPP_DTR))
-#define r_str(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_SPP_STR))
-#define r_ctr(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_SPP_CTR))
-
-#define r_epp_A(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_EPP_ADDR))
-#define r_epp_D(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_EPP_DATA))
-#define r_cnfgA(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_ECP_CNFGA))
-#define r_cnfgB(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_ECP_CNFGB))
-#define r_ecr(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_ECP_ECR))
-#define r_fifo(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_ECP_D_FIFO))
-
-#define w_dtr(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_SPP_DTR, byte))
-#define w_str(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_SPP_STR, byte))
-#define w_ctr(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_SPP_CTR, byte))
-
-#define w_epp_A(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_EPP_ADDR, byte))
-#define w_epp_D(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_EPP_DATA, byte))
-#define w_ecr(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_ECP_ECR, byte))
-#define w_fifo(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_ECP_D_FIFO, byte))
-
-/*
- * Register defines for the PC873xx parts
- */
-
-#define PC873_FER 0x00
-#define PC873_PPENABLE (1<<0)
-#define PC873_FAR 0x01
-#define PC873_PTR 0x02
-#define PC873_CFGLOCK (1<<6)
-#define PC873_EPPRDIR (1<<7)
-#define PC873_EXTENDED (1<<7)
-#define PC873_LPTBIRQ7 (1<<3)
-#define PC873_FCR 0x03
-#define PC873_ZWS (1<<5)
-#define PC873_ZWSPWDN (1<<6)
-#define PC873_PCR 0x04
-#define PC873_EPPEN (1<<0)
-#define PC873_EPP19 (1<<1)
-#define PC873_ECPEN (1<<2)
-#define PC873_ECPCLK (1<<3)
-#define PC873_PMC 0x06
-#define PC873_TUP 0x07
-#define PC873_SID 0x08
-#define PC873_PNP0 0x1b
-#define PC873_PNP1 0x1c
-#define PC873_LPTBA 0x19
-
-/*
- * Register defines for the SMC FDC37C66xGT parts
- */
-
-/* Init codes */
-#define SMC665_iCODE 0x55
-#define SMC666_iCODE 0x44
-
-/* Base configuration ports */
-#define SMC66x_CSR 0x3F0
-#define SMC666_CSR 0x370 /* hard-configured value for 666 */
-
-/* Bits */
-#define SMC_CR1_ADDR 0x3 /* bit 0 and 1 */
-#define SMC_CR1_MODE (1<<3) /* bit 3 */
-#define SMC_CR4_EMODE 0x3 /* bits 0 and 1 */
-#define SMC_CR4_EPPTYPE (1<<6) /* bit 6 */
-
-/* Extended modes */
-#define SMC_SPP 0x0 /* SPP */
-#define SMC_EPPSPP 0x1 /* EPP and SPP */
-#define SMC_ECP 0x2 /* ECP */
-#define SMC_ECPEPP 0x3 /* ECP and EPP */
-
-/*
- * Register defines for the SMC FDC37C935 parts
- */
-
-/* Configuration ports */
-#define SMC935_CFG 0x370
-#define SMC935_IND 0x370
-#define SMC935_DAT 0x371
-
-/* Registers */
-#define SMC935_LOGDEV 0x7
-#define SMC935_ID 0x20
-#define SMC935_PORTHI 0x60
-#define SMC935_PORTLO 0x61
-#define SMC935_PPMODE 0xf0
-
-/* Parallel port modes */
-#define SMC935_SPP 0x38 + 0
-#define SMC935_EPP19SPP 0x38 + 1
-#define SMC935_ECP 0x38 + 2
-#define SMC935_ECPEPP19 0x38 + 3
-#define SMC935_CENT 0x38 + 4
-#define SMC935_EPP17SPP 0x38 + 5
-#define SMC935_UNUSED 0x38 + 6
-#define SMC935_ECPEPP17 0x38 + 7
-
-/*
- * Register defines for the Winbond W83877F parts
- */
-
-#define WINB_W83877F_ID 0xa
-#define WINB_W83877AF_ID 0xb
-
-/* Configuration bits */
-#define WINB_HEFERE (1<<5) /* CROC bit 5 */
-#define WINB_HEFRAS (1<<0) /* CR16 bit 0 */
-
-#define WINB_PNPCVS (1<<2) /* CR16 bit 2 */
-#define WINB_CHIPID 0xf /* CR9 bits 0-3 */
-
-#define WINB_PRTMODS0 (1<<2) /* CR0 bit 2 */
-#define WINB_PRTMODS1 (1<<3) /* CR0 bit 3 */
-#define WINB_PRTMODS2 (1<<7) /* CR9 bit 7 */
-
-/* W83877F modes: CR9/bit7 | CR0/bit3 | CR0/bit2 */
-#define WINB_W83757 0x0
-#define WINB_EXTFDC 0x4
-#define WINB_EXTADP 0x8
-#define WINB_EXT2FDD 0xc
-#define WINB_JOYSTICK 0x80
-
-#define WINB_PARALLEL 0x80
-#define WINB_EPP_SPP 0x4
-#define WINB_ECP 0x8
-#define WINB_ECP_EPP 0xc
-
-#endif
diff --git a/sys/dev/sf/if_sf.c b/sys/dev/sf/if_sf.c
deleted file mode 100644
index af402951bbb4..000000000000
--- a/sys/dev/sf/if_sf.c
+++ /dev/null
@@ -1,1543 +0,0 @@
-/*
- * Copyright (c) 1997, 1998, 1999
- * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Adaptec AIC-6915 "Starfire" PCI fast ethernet driver for FreeBSD.
- * Programming manual is available from:
- * ftp.adaptec.com:/pub/BBS/userguides/aic6915_pg.pdf.
- *
- * Written by Bill Paul <wpaul@ctr.columbia.edu>
- * Department of Electical Engineering
- * Columbia University, New York City
- */
-
-/*
- * The Adaptec AIC-6915 "Starfire" is a 64-bit 10/100 PCI ethernet
- * controller designed with flexibility and reducing CPU load in mind.
- * The Starfire offers high and low priority buffer queues, a
- * producer/consumer index mechanism and several different buffer
- * queue and completion queue descriptor types. Any one of a number
- * of different driver designs can be used, depending on system and
- * OS requirements. This driver makes use of type0 transmit frame
- * descriptors (since BSD fragments packets across an mbuf chain)
- * and two RX buffer queues prioritized on size (one queue for small
- * frames that will fit into a single mbuf, another with full size
- * mbuf clusters for everything else). The producer/consumer indexes
- * and completion queues are also used.
- *
- * One downside to the Starfire has to do with alignment: buffer
- * queues must be aligned on 256-byte boundaries, and receive buffers
- * must be aligned on longword boundaries. The receive buffer alignment
- * causes problems on the Alpha platform, where the packet payload
- * should be longword aligned. There is no simple way around this.
- *
- * For receive filtering, the Starfire offers 16 perfect filter slots
- * and a 512-bit hash table.
- *
- * The Starfire has no internal transceiver, relying instead on an
- * external MII-based transceiver. Accessing registers on external
- * PHYs is done through a special register map rather than with the
- * usual bitbang MDIO method.
- *
- * Acesssing the registers on the Starfire is a little tricky. The
- * Starfire has a 512K internal register space. When programmed for
- * PCI memory mapped mode, the entire register space can be accessed
- * directly. However in I/O space mode, only 256 bytes are directly
- * mapped into PCI I/O space. The other registers can be accessed
- * indirectly using the SF_INDIRECTIO_ADDR and SF_INDIRECTIO_DATA
- * registers inside the 256-byte I/O window.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/sockio.h>
-#include <sys/mbuf.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/socket.h>
-
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/ethernet.h>
-#include <net/if_dl.h>
-#include <net/if_media.h>
-
-#include <net/bpf.h>
-
-#include <vm/vm.h> /* for vtophys */
-#include <vm/pmap.h> /* for vtophys */
-#include <machine/bus_pio.h>
-#include <machine/bus_memio.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/bus.h>
-#include <sys/rman.h>
-
-#include <dev/mii/mii.h>
-#include <dev/mii/miivar.h>
-
-/* "controller miibus0" required. See GENERIC if you get errors here. */
-#include "miibus_if.h"
-
-#include <pci/pcireg.h>
-#include <pci/pcivar.h>
-
-#define SF_USEIOSPACE
-
-#include <pci/if_sfreg.h>
-
-MODULE_DEPEND(sf, pci, 1, 1, 1);
-MODULE_DEPEND(sf, ether, 1, 1, 1);
-MODULE_DEPEND(sf, miibus, 1, 1, 1);
-
-static struct sf_type sf_devs[] = {
- { AD_VENDORID, AD_DEVICEID_STARFIRE,
- "Adaptec AIC-6915 10/100BaseTX" },
- { 0, 0, NULL }
-};
-
-static int sf_probe (device_t);
-static int sf_attach (device_t);
-static int sf_detach (device_t);
-static void sf_intr (void *);
-static void sf_stats_update (void *);
-static void sf_rxeof (struct sf_softc *);
-static void sf_txeof (struct sf_softc *);
-static int sf_encap (struct sf_softc *,
- struct sf_tx_bufdesc_type0 *,
- struct mbuf *);
-static void sf_start (struct ifnet *);
-static int sf_ioctl (struct ifnet *, u_long, caddr_t);
-static void sf_init (void *);
-static void sf_stop (struct sf_softc *);
-static void sf_watchdog (struct ifnet *);
-static void sf_shutdown (device_t);
-static int sf_ifmedia_upd (struct ifnet *);
-static void sf_ifmedia_sts (struct ifnet *, struct ifmediareq *);
-static void sf_reset (struct sf_softc *);
-static int sf_init_rx_ring (struct sf_softc *);
-static void sf_init_tx_ring (struct sf_softc *);
-static int sf_newbuf (struct sf_softc *,
- struct sf_rx_bufdesc_type0 *,
- struct mbuf *);
-static void sf_setmulti (struct sf_softc *);
-static int sf_setperf (struct sf_softc *, int, caddr_t);
-static int sf_sethash (struct sf_softc *, caddr_t, int);
-#ifdef notdef
-static int sf_setvlan (struct sf_softc *, int, u_int32_t);
-#endif
-
-static u_int8_t sf_read_eeprom (struct sf_softc *, int);
-static u_int32_t sf_calchash (caddr_t);
-
-static int sf_miibus_readreg (device_t, int, int);
-static int sf_miibus_writereg (device_t, int, int, int);
-static void sf_miibus_statchg (device_t);
-
-static u_int32_t csr_read_4 (struct sf_softc *, int);
-static void csr_write_4 (struct sf_softc *, int, u_int32_t);
-static void sf_txthresh_adjust (struct sf_softc *);
-
-#ifdef SF_USEIOSPACE
-#define SF_RES SYS_RES_IOPORT
-#define SF_RID SF_PCI_LOIO
-#else
-#define SF_RES SYS_RES_MEMORY
-#define SF_RID SF_PCI_LOMEM
-#endif
-
-static device_method_t sf_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, sf_probe),
- DEVMETHOD(device_attach, sf_attach),
- DEVMETHOD(device_detach, sf_detach),
- DEVMETHOD(device_shutdown, sf_shutdown),
-
- /* bus interface */
- DEVMETHOD(bus_print_child, bus_generic_print_child),
- DEVMETHOD(bus_driver_added, bus_generic_driver_added),
-
- /* MII interface */
- DEVMETHOD(miibus_readreg, sf_miibus_readreg),
- DEVMETHOD(miibus_writereg, sf_miibus_writereg),
- DEVMETHOD(miibus_statchg, sf_miibus_statchg),
-
- { 0, 0 }
-};
-
-static driver_t sf_driver = {
- "sf",
- sf_methods,
- sizeof(struct sf_softc),
-};
-
-static devclass_t sf_devclass;
-
-DRIVER_MODULE(sf, pci, sf_driver, sf_devclass, 0, 0);
-DRIVER_MODULE(miibus, sf, miibus_driver, miibus_devclass, 0, 0);
-
-#define SF_SETBIT(sc, reg, x) \
- csr_write_4(sc, reg, csr_read_4(sc, reg) | (x))
-
-#define SF_CLRBIT(sc, reg, x) \
- csr_write_4(sc, reg, csr_read_4(sc, reg) & ~(x))
-
-static u_int32_t
-csr_read_4(sc, reg)
- struct sf_softc *sc;
- int reg;
-{
- u_int32_t val;
-
-#ifdef SF_USEIOSPACE
- CSR_WRITE_4(sc, SF_INDIRECTIO_ADDR, reg + SF_RMAP_INTREG_BASE);
- val = CSR_READ_4(sc, SF_INDIRECTIO_DATA);
-#else
- val = CSR_READ_4(sc, (reg + SF_RMAP_INTREG_BASE));
-#endif
-
- return(val);
-}
-
-static u_int8_t
-sf_read_eeprom(sc, reg)
- struct sf_softc *sc;
- int reg;
-{
- u_int8_t val;
-
- val = (csr_read_4(sc, SF_EEADDR_BASE +
- (reg & 0xFFFFFFFC)) >> (8 * (reg & 3))) & 0xFF;
-
- return(val);
-}
-
-static void
-csr_write_4(sc, reg, val)
- struct sf_softc *sc;
- int reg;
- u_int32_t val;
-{
-#ifdef SF_USEIOSPACE
- CSR_WRITE_4(sc, SF_INDIRECTIO_ADDR, reg + SF_RMAP_INTREG_BASE);
- CSR_WRITE_4(sc, SF_INDIRECTIO_DATA, val);
-#else
- CSR_WRITE_4(sc, (reg + SF_RMAP_INTREG_BASE), val);
-#endif
- return;
-}
-
-static u_int32_t
-sf_calchash(addr)
- caddr_t addr;
-{
- u_int32_t crc, carry;
- int i, j;
- u_int8_t c;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (i = 0; i < 6; i++) {
- c = *(addr + i);
- for (j = 0; j < 8; j++) {
- carry = ((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01);
- crc <<= 1;
- c >>= 1;
- if (carry)
- crc = (crc ^ 0x04c11db6) | carry;
- }
- }
-
- /* return the filter bit position */
- return(crc >> 23 & 0x1FF);
-}
-
-/*
- * Copy the address 'mac' into the perfect RX filter entry at
- * offset 'idx.' The perfect filter only has 16 entries so do
- * some sanity tests.
- */
-static int
-sf_setperf(sc, idx, mac)
- struct sf_softc *sc;
- int idx;
- caddr_t mac;
-{
- u_int16_t *p;
-
- if (idx < 0 || idx > SF_RXFILT_PERFECT_CNT)
- return(EINVAL);
-
- if (mac == NULL)
- return(EINVAL);
-
- p = (u_int16_t *)mac;
-
- csr_write_4(sc, SF_RXFILT_PERFECT_BASE +
- (idx * SF_RXFILT_PERFECT_SKIP), htons(p[2]));
- csr_write_4(sc, SF_RXFILT_PERFECT_BASE +
- (idx * SF_RXFILT_PERFECT_SKIP) + 4, htons(p[1]));
- csr_write_4(sc, SF_RXFILT_PERFECT_BASE +
- (idx * SF_RXFILT_PERFECT_SKIP) + 8, htons(p[0]));
-
- return(0);
-}
-
-/*
- * Set the bit in the 512-bit hash table that corresponds to the
- * specified mac address 'mac.' If 'prio' is nonzero, update the
- * priority hash table instead of the filter hash table.
- */
-static int
-sf_sethash(sc, mac, prio)
- struct sf_softc *sc;
- caddr_t mac;
- int prio;
-{
- u_int32_t h = 0;
-
- if (mac == NULL)
- return(EINVAL);
-
- h = sf_calchash(mac);
-
- if (prio) {
- SF_SETBIT(sc, SF_RXFILT_HASH_BASE + SF_RXFILT_HASH_PRIOOFF +
- (SF_RXFILT_HASH_SKIP * (h >> 4)), (1 << (h & 0xF)));
- } else {
- SF_SETBIT(sc, SF_RXFILT_HASH_BASE + SF_RXFILT_HASH_ADDROFF +
- (SF_RXFILT_HASH_SKIP * (h >> 4)), (1 << (h & 0xF)));
- }
-
- return(0);
-}
-
-#ifdef notdef
-/*
- * Set a VLAN tag in the receive filter.
- */
-static int
-sf_setvlan(sc, idx, vlan)
- struct sf_softc *sc;
- int idx;
- u_int32_t vlan;
-{
- if (idx < 0 || idx >> SF_RXFILT_HASH_CNT)
- return(EINVAL);
-
- csr_write_4(sc, SF_RXFILT_HASH_BASE +
- (idx * SF_RXFILT_HASH_SKIP) + SF_RXFILT_HASH_VLANOFF, vlan);
-
- return(0);
-}
-#endif
-
-static int
-sf_miibus_readreg(dev, phy, reg)
- device_t dev;
- int phy, reg;
-{
- struct sf_softc *sc;
- int i;
- u_int32_t val = 0;
-
- sc = device_get_softc(dev);
-
- for (i = 0; i < SF_TIMEOUT; i++) {
- val = csr_read_4(sc, SF_PHY_REG(phy, reg));
- if (val & SF_MII_DATAVALID)
- break;
- }
-
- if (i == SF_TIMEOUT)
- return(0);
-
- if ((val & 0x0000FFFF) == 0xFFFF)
- return(0);
-
- return(val & 0x0000FFFF);
-}
-
-static int
-sf_miibus_writereg(dev, phy, reg, val)
- device_t dev;
- int phy, reg, val;
-{
- struct sf_softc *sc;
- int i;
- int busy;
-
- sc = device_get_softc(dev);
-
- csr_write_4(sc, SF_PHY_REG(phy, reg), val);
-
- for (i = 0; i < SF_TIMEOUT; i++) {
- busy = csr_read_4(sc, SF_PHY_REG(phy, reg));
- if (!(busy & SF_MII_BUSY))
- break;
- }
-
- return(0);
-}
-
-static void
-sf_miibus_statchg(dev)
- device_t dev;
-{
- struct sf_softc *sc;
- struct mii_data *mii;
-
- sc = device_get_softc(dev);
- mii = device_get_softc(sc->sf_miibus);
-
- if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
- SF_SETBIT(sc, SF_MACCFG_1, SF_MACCFG1_FULLDUPLEX);
- csr_write_4(sc, SF_BKTOBKIPG, SF_IPGT_FDX);
- } else {
- SF_CLRBIT(sc, SF_MACCFG_1, SF_MACCFG1_FULLDUPLEX);
- csr_write_4(sc, SF_BKTOBKIPG, SF_IPGT_HDX);
- }
-
- return;
-}
-
-static void
-sf_setmulti(sc)
- struct sf_softc *sc;
-{
- struct ifnet *ifp;
- int i;
- struct ifmultiaddr *ifma;
- u_int8_t dummy[] = { 0, 0, 0, 0, 0, 0 };
-
- ifp = &sc->arpcom.ac_if;
-
- /* First zot all the existing filters. */
- for (i = 1; i < SF_RXFILT_PERFECT_CNT; i++)
- sf_setperf(sc, i, (char *)&dummy);
- for (i = SF_RXFILT_HASH_BASE;
- i < (SF_RXFILT_HASH_MAX + 1); i += 4)
- csr_write_4(sc, i, 0);
- SF_CLRBIT(sc, SF_RXFILT, SF_RXFILT_ALLMULTI);
-
- /* Now program new ones. */
- if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
- SF_SETBIT(sc, SF_RXFILT, SF_RXFILT_ALLMULTI);
- } else {
- i = 1;
- TAILQ_FOREACH_REVERSE(ifma, &ifp->if_multiaddrs, ifmultihead, ifma_link) {
- if (ifma->ifma_addr->sa_family != AF_LINK)
- continue;
- /*
- * Program the first 15 multicast groups
- * into the perfect filter. For all others,
- * use the hash table.
- */
- if (i < SF_RXFILT_PERFECT_CNT) {
- sf_setperf(sc, i,
- LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
- i++;
- continue;
- }
-
- sf_sethash(sc,
- LLADDR((struct sockaddr_dl *)ifma->ifma_addr), 0);
- }
- }
-
- return;
-}
-
-/*
- * Set media options.
- */
-static int
-sf_ifmedia_upd(ifp)
- struct ifnet *ifp;
-{
- struct sf_softc *sc;
- struct mii_data *mii;
-
- sc = ifp->if_softc;
- mii = device_get_softc(sc->sf_miibus);
- sc->sf_link = 0;
- if (mii->mii_instance) {
- struct mii_softc *miisc;
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
- mii_mediachg(mii);
-
- return(0);
-}
-
-/*
- * Report current media status.
- */
-static void
-sf_ifmedia_sts(ifp, ifmr)
- struct ifnet *ifp;
- struct ifmediareq *ifmr;
-{
- struct sf_softc *sc;
- struct mii_data *mii;
-
- sc = ifp->if_softc;
- mii = device_get_softc(sc->sf_miibus);
-
- mii_pollstat(mii);
- ifmr->ifm_active = mii->mii_media_active;
- ifmr->ifm_status = mii->mii_media_status;
-
- return;
-}
-
-static int
-sf_ioctl(ifp, command, data)
- struct ifnet *ifp;
- u_long command;
- caddr_t data;
-{
- struct sf_softc *sc = ifp->if_softc;
- struct ifreq *ifr = (struct ifreq *) data;
- struct mii_data *mii;
- int error = 0;
-
- SF_LOCK(sc);
-
- switch(command) {
- case SIOCSIFFLAGS:
- if (ifp->if_flags & IFF_UP) {
- if (ifp->if_flags & IFF_RUNNING &&
- ifp->if_flags & IFF_PROMISC &&
- !(sc->sf_if_flags & IFF_PROMISC)) {
- SF_SETBIT(sc, SF_RXFILT, SF_RXFILT_PROMISC);
- } else if (ifp->if_flags & IFF_RUNNING &&
- !(ifp->if_flags & IFF_PROMISC) &&
- sc->sf_if_flags & IFF_PROMISC) {
- SF_CLRBIT(sc, SF_RXFILT, SF_RXFILT_PROMISC);
- } else if (!(ifp->if_flags & IFF_RUNNING))
- sf_init(sc);
- } else {
- if (ifp->if_flags & IFF_RUNNING)
- sf_stop(sc);
- }
- sc->sf_if_flags = ifp->if_flags;
- error = 0;
- break;
- case SIOCADDMULTI:
- case SIOCDELMULTI:
- sf_setmulti(sc);
- error = 0;
- break;
- case SIOCGIFMEDIA:
- case SIOCSIFMEDIA:
- mii = device_get_softc(sc->sf_miibus);
- error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
- break;
- default:
- error = ether_ioctl(ifp, command, data);
- break;
- }
-
- SF_UNLOCK(sc);
-
- return(error);
-}
-
-static void
-sf_reset(sc)
- struct sf_softc *sc;
-{
- register int i;
-
- csr_write_4(sc, SF_GEN_ETH_CTL, 0);
- SF_SETBIT(sc, SF_MACCFG_1, SF_MACCFG1_SOFTRESET);
- DELAY(1000);
- SF_CLRBIT(sc, SF_MACCFG_1, SF_MACCFG1_SOFTRESET);
-
- SF_SETBIT(sc, SF_PCI_DEVCFG, SF_PCIDEVCFG_RESET);
-
- for (i = 0; i < SF_TIMEOUT; i++) {
- DELAY(10);
- if (!(csr_read_4(sc, SF_PCI_DEVCFG) & SF_PCIDEVCFG_RESET))
- break;
- }
-
- if (i == SF_TIMEOUT)
- printf("sf%d: reset never completed!\n", sc->sf_unit);
-
- /* Wait a little while for the chip to get its brains in order. */
- DELAY(1000);
- return;
-}
-
-/*
- * Probe for an Adaptec AIC-6915 chip. Check the PCI vendor and device
- * IDs against our list and return a device name if we find a match.
- * We also check the subsystem ID so that we can identify exactly which
- * NIC has been found, if possible.
- */
-static int
-sf_probe(dev)
- device_t dev;
-{
- struct sf_type *t;
-
- t = sf_devs;
-
- while(t->sf_name != NULL) {
- if ((pci_get_vendor(dev) == t->sf_vid) &&
- (pci_get_device(dev) == t->sf_did)) {
- switch((pci_read_config(dev,
- SF_PCI_SUBVEN_ID, 4) >> 16) & 0xFFFF) {
- case AD_SUBSYSID_62011_REV0:
- case AD_SUBSYSID_62011_REV1:
- device_set_desc(dev,
- "Adaptec ANA-62011 10/100BaseTX");
- return(0);
- break;
- case AD_SUBSYSID_62022:
- device_set_desc(dev,
- "Adaptec ANA-62022 10/100BaseTX");
- return(0);
- break;
- case AD_SUBSYSID_62044_REV0:
- case AD_SUBSYSID_62044_REV1:
- device_set_desc(dev,
- "Adaptec ANA-62044 10/100BaseTX");
- return(0);
- break;
- case AD_SUBSYSID_62020:
- device_set_desc(dev,
- "Adaptec ANA-62020 10/100BaseFX");
- return(0);
- break;
- case AD_SUBSYSID_69011:
- device_set_desc(dev,
- "Adaptec ANA-69011 10/100BaseTX");
- return(0);
- break;
- default:
- device_set_desc(dev, t->sf_name);
- return(0);
- break;
- }
- }
- t++;
- }
-
- return(ENXIO);
-}
-
-/*
- * Attach the interface. Allocate softc structures, do ifmedia
- * setup and ethernet/BPF attach.
- */
-static int
-sf_attach(dev)
- device_t dev;
-{
- int i;
- struct sf_softc *sc;
- struct ifnet *ifp;
- int unit, rid, error = 0;
-
- sc = device_get_softc(dev);
- unit = device_get_unit(dev);
-
- mtx_init(&sc->sf_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
- MTX_DEF | MTX_RECURSE);
-
- /*
- * Handle power management nonsense.
- */
- if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
- u_int32_t iobase, membase, irq;
-
- /* Save important PCI config data. */
- iobase = pci_read_config(dev, SF_PCI_LOIO, 4);
- membase = pci_read_config(dev, SF_PCI_LOMEM, 4);
- irq = pci_read_config(dev, SF_PCI_INTLINE, 4);
-
- /* Reset the power state. */
- printf("sf%d: chip is in D%d power mode "
- "-- setting to D0\n", unit,
- pci_get_powerstate(dev));
- pci_set_powerstate(dev, PCI_POWERSTATE_D0);
-
- /* Restore PCI config data. */
- pci_write_config(dev, SF_PCI_LOIO, iobase, 4);
- pci_write_config(dev, SF_PCI_LOMEM, membase, 4);
- pci_write_config(dev, SF_PCI_INTLINE, irq, 4);
- }
-
- /*
- * Map control/status registers.
- */
- pci_enable_busmaster(dev);
-
- rid = SF_RID;
- sc->sf_res = bus_alloc_resource(dev, SF_RES, &rid,
- 0, ~0, 1, RF_ACTIVE);
-
- if (sc->sf_res == NULL) {
- printf ("sf%d: couldn't map ports\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- sc->sf_btag = rman_get_bustag(sc->sf_res);
- sc->sf_bhandle = rman_get_bushandle(sc->sf_res);
-
- /* Allocate interrupt */
- rid = 0;
- sc->sf_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE | RF_ACTIVE);
-
- if (sc->sf_irq == NULL) {
- printf("sf%d: couldn't map interrupt\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- callout_handle_init(&sc->sf_stat_ch);
- /* Reset the adapter. */
- sf_reset(sc);
-
- /*
- * Get station address from the EEPROM.
- */
- for (i = 0; i < ETHER_ADDR_LEN; i++)
- sc->arpcom.ac_enaddr[i] =
- sf_read_eeprom(sc, SF_EE_NODEADDR + ETHER_ADDR_LEN - i);
-
- /*
- * An Adaptec chip was detected. Inform the world.
- */
- printf("sf%d: Ethernet address: %6D\n", unit,
- sc->arpcom.ac_enaddr, ":");
-
- sc->sf_unit = unit;
-
- /* Allocate the descriptor queues. */
- sc->sf_ldata = contigmalloc(sizeof(struct sf_list_data), M_DEVBUF,
- M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
-
- if (sc->sf_ldata == NULL) {
- printf("sf%d: no memory for list buffers!\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- bzero(sc->sf_ldata, sizeof(struct sf_list_data));
-
- /* Do MII setup. */
- if (mii_phy_probe(dev, &sc->sf_miibus,
- sf_ifmedia_upd, sf_ifmedia_sts)) {
- printf("sf%d: MII without any phy!\n", sc->sf_unit);
- error = ENXIO;
- goto fail;
- }
-
- ifp = &sc->arpcom.ac_if;
- ifp->if_softc = sc;
- ifp->if_unit = unit;
- ifp->if_name = "sf";
- ifp->if_mtu = ETHERMTU;
- ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
- ifp->if_ioctl = sf_ioctl;
- ifp->if_output = ether_output;
- ifp->if_start = sf_start;
- ifp->if_watchdog = sf_watchdog;
- ifp->if_init = sf_init;
- ifp->if_baudrate = 10000000;
- ifp->if_snd.ifq_maxlen = SF_TX_DLIST_CNT - 1;
-
- /*
- * Call MI attach routine.
- */
- ether_ifattach(ifp, sc->arpcom.ac_enaddr);
-
- /* Hook interrupt last to avoid having to lock softc */
- error = bus_setup_intr(dev, sc->sf_irq, INTR_TYPE_NET,
- sf_intr, sc, &sc->sf_intrhand);
-
- if (error) {
- printf("sf%d: couldn't set up irq\n", unit);
- ether_ifdetach(ifp);
- goto fail;
- }
-
-fail:
- if (error)
- sf_detach(dev);
-
- return(error);
-}
-
-/*
- * Shutdown hardware and free up resources. This can be called any
- * time after the mutex has been initialized. It is called in both
- * the error case in attach and the normal detach case so it needs
- * to be careful about only freeing resources that have actually been
- * allocated.
- */
-static int
-sf_detach(dev)
- device_t dev;
-{
- struct sf_softc *sc;
- struct ifnet *ifp;
-
- sc = device_get_softc(dev);
- KASSERT(mtx_initialized(&sc->sf_mtx), ("sf mutex not initialized"));
- SF_LOCK(sc);
- ifp = &sc->arpcom.ac_if;
-
- /* These should only be active if attach succeeded */
- if (device_is_attached(dev)) {
- sf_stop(sc);
- ether_ifdetach(ifp);
- }
- if (sc->sf_miibus)
- device_delete_child(dev, sc->sf_miibus);
- bus_generic_detach(dev);
-
- if (sc->sf_intrhand)
- bus_teardown_intr(dev, sc->sf_irq, sc->sf_intrhand);
- if (sc->sf_irq)
- bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sf_irq);
- if (sc->sf_res)
- bus_release_resource(dev, SF_RES, SF_RID, sc->sf_res);
-
- if (sc->sf_ldata)
- contigfree(sc->sf_ldata, sizeof(struct sf_list_data), M_DEVBUF);
-
- SF_UNLOCK(sc);
- mtx_destroy(&sc->sf_mtx);
-
- return(0);
-}
-
-static int
-sf_init_rx_ring(sc)
- struct sf_softc *sc;
-{
- struct sf_list_data *ld;
- int i;
-
- ld = sc->sf_ldata;
-
- bzero((char *)ld->sf_rx_dlist_big,
- sizeof(struct sf_rx_bufdesc_type0) * SF_RX_DLIST_CNT);
- bzero((char *)ld->sf_rx_clist,
- sizeof(struct sf_rx_cmpdesc_type3) * SF_RX_CLIST_CNT);
-
- for (i = 0; i < SF_RX_DLIST_CNT; i++) {
- if (sf_newbuf(sc, &ld->sf_rx_dlist_big[i], NULL) == ENOBUFS)
- return(ENOBUFS);
- }
-
- return(0);
-}
-
-static void
-sf_init_tx_ring(sc)
- struct sf_softc *sc;
-{
- struct sf_list_data *ld;
- int i;
-
- ld = sc->sf_ldata;
-
- bzero((char *)ld->sf_tx_dlist,
- sizeof(struct sf_tx_bufdesc_type0) * SF_TX_DLIST_CNT);
- bzero((char *)ld->sf_tx_clist,
- sizeof(struct sf_tx_cmpdesc_type0) * SF_TX_CLIST_CNT);
-
- for (i = 0; i < SF_TX_DLIST_CNT; i++)
- ld->sf_tx_dlist[i].sf_id = SF_TX_BUFDESC_ID;
- for (i = 0; i < SF_TX_CLIST_CNT; i++)
- ld->sf_tx_clist[i].sf_type = SF_TXCMPTYPE_TX;
-
- ld->sf_tx_dlist[SF_TX_DLIST_CNT - 1].sf_end = 1;
- sc->sf_tx_cnt = 0;
-
- return;
-}
-
-static int
-sf_newbuf(sc, c, m)
- struct sf_softc *sc;
- struct sf_rx_bufdesc_type0 *c;
- struct mbuf *m;
-{
- struct mbuf *m_new = NULL;
-
- if (m == NULL) {
- MGETHDR(m_new, M_DONTWAIT, MT_DATA);
- if (m_new == NULL)
- return(ENOBUFS);
-
- MCLGET(m_new, M_DONTWAIT);
- if (!(m_new->m_flags & M_EXT)) {
- m_freem(m_new);
- return(ENOBUFS);
- }
- m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
- } else {
- m_new = m;
- m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
- m_new->m_data = m_new->m_ext.ext_buf;
- }
-
- m_adj(m_new, sizeof(u_int64_t));
-
- c->sf_mbuf = m_new;
- c->sf_addrlo = SF_RX_HOSTADDR(vtophys(mtod(m_new, caddr_t)));
- c->sf_valid = 1;
-
- return(0);
-}
-
-/*
- * The starfire is programmed to use 'normal' mode for packet reception,
- * which means we use the consumer/producer model for both the buffer
- * descriptor queue and the completion descriptor queue. The only problem
- * with this is that it involves a lot of register accesses: we have to
- * read the RX completion consumer and producer indexes and the RX buffer
- * producer index, plus the RX completion consumer and RX buffer producer
- * indexes have to be updated. It would have been easier if Adaptec had
- * put each index in a separate register, especially given that the damn
- * NIC has a 512K register space.
- *
- * In spite of all the lovely features that Adaptec crammed into the 6915,
- * it is marred by one truly stupid design flaw, which is that receive
- * buffer addresses must be aligned on a longword boundary. This forces
- * the packet payload to be unaligned, which is suboptimal on the x86 and
- * completely unuseable on the Alpha. Our only recourse is to copy received
- * packets into properly aligned buffers before handing them off.
- */
-
-static void
-sf_rxeof(sc)
- struct sf_softc *sc;
-{
- struct mbuf *m;
- struct ifnet *ifp;
- struct sf_rx_bufdesc_type0 *desc;
- struct sf_rx_cmpdesc_type3 *cur_rx;
- u_int32_t rxcons, rxprod;
- int cmpprodidx, cmpconsidx, bufprodidx;
-
- ifp = &sc->arpcom.ac_if;
-
- rxcons = csr_read_4(sc, SF_CQ_CONSIDX);
- rxprod = csr_read_4(sc, SF_RXDQ_PTR_Q1);
- cmpprodidx = SF_IDX_LO(csr_read_4(sc, SF_CQ_PRODIDX));
- cmpconsidx = SF_IDX_LO(rxcons);
- bufprodidx = SF_IDX_LO(rxprod);
-
- while (cmpconsidx != cmpprodidx) {
- struct mbuf *m0;
-
- cur_rx = &sc->sf_ldata->sf_rx_clist[cmpconsidx];
- desc = &sc->sf_ldata->sf_rx_dlist_big[cur_rx->sf_endidx];
- m = desc->sf_mbuf;
- SF_INC(cmpconsidx, SF_RX_CLIST_CNT);
- SF_INC(bufprodidx, SF_RX_DLIST_CNT);
-
- if (!(cur_rx->sf_status1 & SF_RXSTAT1_OK)) {
- ifp->if_ierrors++;
- sf_newbuf(sc, desc, m);
- continue;
- }
-
- m0 = m_devget(mtod(m, char *), cur_rx->sf_len, ETHER_ALIGN,
- ifp, NULL);
- sf_newbuf(sc, desc, m);
- if (m0 == NULL) {
- ifp->if_ierrors++;
- continue;
- }
- m = m0;
-
- ifp->if_ipackets++;
- (*ifp->if_input)(ifp, m);
- }
-
- csr_write_4(sc, SF_CQ_CONSIDX,
- (rxcons & ~SF_CQ_CONSIDX_RXQ1) | cmpconsidx);
- csr_write_4(sc, SF_RXDQ_PTR_Q1,
- (rxprod & ~SF_RXDQ_PRODIDX) | bufprodidx);
-
- return;
-}
-
-/*
- * Read the transmit status from the completion queue and release
- * mbufs. Note that the buffer descriptor index in the completion
- * descriptor is an offset from the start of the transmit buffer
- * descriptor list in bytes. This is important because the manual
- * gives the impression that it should match the producer/consumer
- * index, which is the offset in 8 byte blocks.
- */
-static void
-sf_txeof(sc)
- struct sf_softc *sc;
-{
- int txcons, cmpprodidx, cmpconsidx;
- struct sf_tx_cmpdesc_type1 *cur_cmp;
- struct sf_tx_bufdesc_type0 *cur_tx;
- struct ifnet *ifp;
-
- ifp = &sc->arpcom.ac_if;
-
- txcons = csr_read_4(sc, SF_CQ_CONSIDX);
- cmpprodidx = SF_IDX_HI(csr_read_4(sc, SF_CQ_PRODIDX));
- cmpconsidx = SF_IDX_HI(txcons);
-
- while (cmpconsidx != cmpprodidx) {
- cur_cmp = &sc->sf_ldata->sf_tx_clist[cmpconsidx];
- cur_tx = &sc->sf_ldata->sf_tx_dlist[cur_cmp->sf_index >> 7];
-
- if (cur_cmp->sf_txstat & SF_TXSTAT_TX_OK)
- ifp->if_opackets++;
- else {
- if (cur_cmp->sf_txstat & SF_TXSTAT_TX_UNDERRUN)
- sf_txthresh_adjust(sc);
- ifp->if_oerrors++;
- }
-
- sc->sf_tx_cnt--;
- if (cur_tx->sf_mbuf != NULL) {
- m_freem(cur_tx->sf_mbuf);
- cur_tx->sf_mbuf = NULL;
- } else
- break;
- SF_INC(cmpconsidx, SF_TX_CLIST_CNT);
- }
-
- ifp->if_timer = 0;
- ifp->if_flags &= ~IFF_OACTIVE;
-
- csr_write_4(sc, SF_CQ_CONSIDX,
- (txcons & ~SF_CQ_CONSIDX_TXQ) |
- ((cmpconsidx << 16) & 0xFFFF0000));
-
- return;
-}
-
-static void
-sf_txthresh_adjust(sc)
- struct sf_softc *sc;
-{
- u_int32_t txfctl;
- u_int8_t txthresh;
-
- txfctl = csr_read_4(sc, SF_TX_FRAMCTL);
- txthresh = txfctl & SF_TXFRMCTL_TXTHRESH;
- if (txthresh < 0xFF) {
- txthresh++;
- txfctl &= ~SF_TXFRMCTL_TXTHRESH;
- txfctl |= txthresh;
-#ifdef DIAGNOSTIC
- printf("sf%d: tx underrun, increasing "
- "tx threshold to %d bytes\n",
- sc->sf_unit, txthresh * 4);
-#endif
- csr_write_4(sc, SF_TX_FRAMCTL, txfctl);
- }
-
- return;
-}
-
-static void
-sf_intr(arg)
- void *arg;
-{
- struct sf_softc *sc;
- struct ifnet *ifp;
- u_int32_t status;
-
- sc = arg;
- SF_LOCK(sc);
-
- ifp = &sc->arpcom.ac_if;
-
- if (!(csr_read_4(sc, SF_ISR_SHADOW) & SF_ISR_PCIINT_ASSERTED)) {
- SF_UNLOCK(sc);
- return;
- }
-
- /* Disable interrupts. */
- csr_write_4(sc, SF_IMR, 0x00000000);
-
- for (;;) {
- status = csr_read_4(sc, SF_ISR);
- if (status)
- csr_write_4(sc, SF_ISR, status);
-
- if (!(status & SF_INTRS))
- break;
-
- if (status & SF_ISR_RXDQ1_DMADONE)
- sf_rxeof(sc);
-
- if (status & SF_ISR_TX_TXDONE ||
- status & SF_ISR_TX_DMADONE ||
- status & SF_ISR_TX_QUEUEDONE)
- sf_txeof(sc);
-
- if (status & SF_ISR_TX_LOFIFO)
- sf_txthresh_adjust(sc);
-
- if (status & SF_ISR_ABNORMALINTR) {
- if (status & SF_ISR_STATSOFLOW) {
- untimeout(sf_stats_update, sc,
- sc->sf_stat_ch);
- sf_stats_update(sc);
- } else
- sf_init(sc);
- }
- }
-
- /* Re-enable interrupts. */
- csr_write_4(sc, SF_IMR, SF_INTRS);
-
- if (ifp->if_snd.ifq_head != NULL)
- sf_start(ifp);
-
- SF_UNLOCK(sc);
- return;
-}
-
-static void
-sf_init(xsc)
- void *xsc;
-{
- struct sf_softc *sc;
- struct ifnet *ifp;
- struct mii_data *mii;
- int i;
-
- sc = xsc;
- SF_LOCK(sc);
- ifp = &sc->arpcom.ac_if;
- mii = device_get_softc(sc->sf_miibus);
-
- sf_stop(sc);
- sf_reset(sc);
-
- /* Init all the receive filter registers */
- for (i = SF_RXFILT_PERFECT_BASE;
- i < (SF_RXFILT_HASH_MAX + 1); i += 4)
- csr_write_4(sc, i, 0);
-
- /* Empty stats counter registers. */
- for (i = 0; i < sizeof(struct sf_stats)/sizeof(u_int32_t); i++)
- csr_write_4(sc, SF_STATS_BASE +
- (i + sizeof(u_int32_t)), 0);
-
- /* Init our MAC address */
- csr_write_4(sc, SF_PAR0, *(u_int32_t *)(&sc->arpcom.ac_enaddr[0]));
- csr_write_4(sc, SF_PAR1, *(u_int32_t *)(&sc->arpcom.ac_enaddr[4]));
- sf_setperf(sc, 0, (caddr_t)&sc->arpcom.ac_enaddr);
-
- if (sf_init_rx_ring(sc) == ENOBUFS) {
- printf("sf%d: initialization failed: no "
- "memory for rx buffers\n", sc->sf_unit);
- SF_UNLOCK(sc);
- return;
- }
-
- sf_init_tx_ring(sc);
-
- csr_write_4(sc, SF_RXFILT, SF_PERFMODE_NORMAL|SF_HASHMODE_WITHVLAN);
-
- /* If we want promiscuous mode, set the allframes bit. */
- if (ifp->if_flags & IFF_PROMISC) {
- SF_SETBIT(sc, SF_RXFILT, SF_RXFILT_PROMISC);
- } else {
- SF_CLRBIT(sc, SF_RXFILT, SF_RXFILT_PROMISC);
- }
-
- if (ifp->if_flags & IFF_BROADCAST) {
- SF_SETBIT(sc, SF_RXFILT, SF_RXFILT_BROAD);
- } else {
- SF_CLRBIT(sc, SF_RXFILT, SF_RXFILT_BROAD);
- }
-
- /*
- * Load the multicast filter.
- */
- sf_setmulti(sc);
-
- /* Init the completion queue indexes */
- csr_write_4(sc, SF_CQ_CONSIDX, 0);
- csr_write_4(sc, SF_CQ_PRODIDX, 0);
-
- /* Init the RX completion queue */
- csr_write_4(sc, SF_RXCQ_CTL_1,
- vtophys(sc->sf_ldata->sf_rx_clist) & SF_RXCQ_ADDR);
- SF_SETBIT(sc, SF_RXCQ_CTL_1, SF_RXCQTYPE_3);
-
- /* Init RX DMA control. */
- SF_SETBIT(sc, SF_RXDMA_CTL, SF_RXDMA_REPORTBADPKTS);
-
- /* Init the RX buffer descriptor queue. */
- csr_write_4(sc, SF_RXDQ_ADDR_Q1,
- vtophys(sc->sf_ldata->sf_rx_dlist_big));
- csr_write_4(sc, SF_RXDQ_CTL_1, (MCLBYTES << 16) | SF_DESCSPACE_16BYTES);
- csr_write_4(sc, SF_RXDQ_PTR_Q1, SF_RX_DLIST_CNT - 1);
-
- /* Init the TX completion queue */
- csr_write_4(sc, SF_TXCQ_CTL,
- vtophys(sc->sf_ldata->sf_tx_clist) & SF_RXCQ_ADDR);
-
- /* Init the TX buffer descriptor queue. */
- csr_write_4(sc, SF_TXDQ_ADDR_HIPRIO,
- vtophys(sc->sf_ldata->sf_tx_dlist));
- SF_SETBIT(sc, SF_TX_FRAMCTL, SF_TXFRMCTL_CPLAFTERTX);
- csr_write_4(sc, SF_TXDQ_CTL,
- SF_TXBUFDESC_TYPE0|SF_TXMINSPACE_128BYTES|SF_TXSKIPLEN_8BYTES);
- SF_SETBIT(sc, SF_TXDQ_CTL, SF_TXDQCTL_NODMACMP);
-
- /* Enable autopadding of short TX frames. */
- SF_SETBIT(sc, SF_MACCFG_1, SF_MACCFG1_AUTOPAD);
-
- /* Enable interrupts. */
- csr_write_4(sc, SF_IMR, SF_INTRS);
- SF_SETBIT(sc, SF_PCI_DEVCFG, SF_PCIDEVCFG_INTR_ENB);
-
- /* Enable the RX and TX engines. */
- SF_SETBIT(sc, SF_GEN_ETH_CTL, SF_ETHCTL_RX_ENB|SF_ETHCTL_RXDMA_ENB);
- SF_SETBIT(sc, SF_GEN_ETH_CTL, SF_ETHCTL_TX_ENB|SF_ETHCTL_TXDMA_ENB);
-
- /*mii_mediachg(mii);*/
- sf_ifmedia_upd(ifp);
-
- ifp->if_flags |= IFF_RUNNING;
- ifp->if_flags &= ~IFF_OACTIVE;
-
- sc->sf_stat_ch = timeout(sf_stats_update, sc, hz);
-
- SF_UNLOCK(sc);
-
- return;
-}
-
-static int
-sf_encap(sc, c, m_head)
- struct sf_softc *sc;
- struct sf_tx_bufdesc_type0 *c;
- struct mbuf *m_head;
-{
- int frag = 0;
- struct sf_frag *f = NULL;
- struct mbuf *m;
-
- m = m_head;
-
- for (m = m_head, frag = 0; m != NULL; m = m->m_next) {
- if (m->m_len != 0) {
- if (frag == SF_MAXFRAGS)
- break;
- f = &c->sf_frags[frag];
- if (frag == 0)
- f->sf_pktlen = m_head->m_pkthdr.len;
- f->sf_fraglen = m->m_len;
- f->sf_addr = vtophys(mtod(m, vm_offset_t));
- frag++;
- }
- }
-
- if (m != NULL) {
- struct mbuf *m_new = NULL;
-
- MGETHDR(m_new, M_DONTWAIT, MT_DATA);
- if (m_new == NULL) {
- printf("sf%d: no memory for tx list\n", sc->sf_unit);
- return(1);
- }
-
- if (m_head->m_pkthdr.len > MHLEN) {
- MCLGET(m_new, M_DONTWAIT);
- if (!(m_new->m_flags & M_EXT)) {
- m_freem(m_new);
- printf("sf%d: no memory for tx list\n",
- sc->sf_unit);
- return(1);
- }
- }
- m_copydata(m_head, 0, m_head->m_pkthdr.len,
- mtod(m_new, caddr_t));
- m_new->m_pkthdr.len = m_new->m_len = m_head->m_pkthdr.len;
- m_freem(m_head);
- m_head = m_new;
- f = &c->sf_frags[0];
- f->sf_fraglen = f->sf_pktlen = m_head->m_pkthdr.len;
- f->sf_addr = vtophys(mtod(m_head, caddr_t));
- frag = 1;
- }
-
- c->sf_mbuf = m_head;
- c->sf_id = SF_TX_BUFDESC_ID;
- c->sf_fragcnt = frag;
- c->sf_intr = 1;
- c->sf_caltcp = 0;
- c->sf_crcen = 1;
-
- return(0);
-}
-
-static void
-sf_start(ifp)
- struct ifnet *ifp;
-{
- struct sf_softc *sc;
- struct sf_tx_bufdesc_type0 *cur_tx = NULL;
- struct mbuf *m_head = NULL;
- int i, txprod;
-
- sc = ifp->if_softc;
- SF_LOCK(sc);
-
- if (!sc->sf_link && ifp->if_snd.ifq_len < 10) {
- SF_UNLOCK(sc);
- return;
- }
-
- if (ifp->if_flags & IFF_OACTIVE) {
- SF_UNLOCK(sc);
- return;
- }
-
- txprod = csr_read_4(sc, SF_TXDQ_PRODIDX);
- i = SF_IDX_HI(txprod) >> 4;
-
- if (sc->sf_ldata->sf_tx_dlist[i].sf_mbuf != NULL) {
- printf("sf%d: TX ring full, resetting\n", sc->sf_unit);
- sf_init(sc);
- txprod = csr_read_4(sc, SF_TXDQ_PRODIDX);
- i = SF_IDX_HI(txprod) >> 4;
- }
-
- while(sc->sf_ldata->sf_tx_dlist[i].sf_mbuf == NULL) {
- if (sc->sf_tx_cnt >= (SF_TX_DLIST_CNT - 5)) {
- ifp->if_flags |= IFF_OACTIVE;
- cur_tx = NULL;
- break;
- }
- IF_DEQUEUE(&ifp->if_snd, m_head);
- if (m_head == NULL)
- break;
-
- cur_tx = &sc->sf_ldata->sf_tx_dlist[i];
- if (sf_encap(sc, cur_tx, m_head)) {
- IF_PREPEND(&ifp->if_snd, m_head);
- ifp->if_flags |= IFF_OACTIVE;
- cur_tx = NULL;
- break;
- }
-
- /*
- * If there's a BPF listener, bounce a copy of this frame
- * to him.
- */
- BPF_MTAP(ifp, m_head);
-
- SF_INC(i, SF_TX_DLIST_CNT);
- sc->sf_tx_cnt++;
- /*
- * Don't get the TX DMA queue get too full.
- */
- if (sc->sf_tx_cnt > 64)
- break;
- }
-
- if (cur_tx == NULL) {
- SF_UNLOCK(sc);
- return;
- }
-
- /* Transmit */
- csr_write_4(sc, SF_TXDQ_PRODIDX,
- (txprod & ~SF_TXDQ_PRODIDX_HIPRIO) |
- ((i << 20) & 0xFFFF0000));
-
- ifp->if_timer = 5;
-
- SF_UNLOCK(sc);
-
- return;
-}
-
-static void
-sf_stop(sc)
- struct sf_softc *sc;
-{
- int i;
- struct ifnet *ifp;
-
- SF_LOCK(sc);
-
- ifp = &sc->arpcom.ac_if;
-
- untimeout(sf_stats_update, sc, sc->sf_stat_ch);
-
- csr_write_4(sc, SF_GEN_ETH_CTL, 0);
- csr_write_4(sc, SF_CQ_CONSIDX, 0);
- csr_write_4(sc, SF_CQ_PRODIDX, 0);
- csr_write_4(sc, SF_RXDQ_ADDR_Q1, 0);
- csr_write_4(sc, SF_RXDQ_CTL_1, 0);
- csr_write_4(sc, SF_RXDQ_PTR_Q1, 0);
- csr_write_4(sc, SF_TXCQ_CTL, 0);
- csr_write_4(sc, SF_TXDQ_ADDR_HIPRIO, 0);
- csr_write_4(sc, SF_TXDQ_CTL, 0);
- sf_reset(sc);
-
- sc->sf_link = 0;
-
- for (i = 0; i < SF_RX_DLIST_CNT; i++) {
- if (sc->sf_ldata->sf_rx_dlist_big[i].sf_mbuf != NULL) {
- m_freem(sc->sf_ldata->sf_rx_dlist_big[i].sf_mbuf);
- sc->sf_ldata->sf_rx_dlist_big[i].sf_mbuf = NULL;
- }
- }
-
- for (i = 0; i < SF_TX_DLIST_CNT; i++) {
- if (sc->sf_ldata->sf_tx_dlist[i].sf_mbuf != NULL) {
- m_freem(sc->sf_ldata->sf_tx_dlist[i].sf_mbuf);
- sc->sf_ldata->sf_tx_dlist[i].sf_mbuf = NULL;
- }
- }
-
- ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
- SF_UNLOCK(sc);
-
- return;
-}
-
-/*
- * Note: it is important that this function not be interrupted. We
- * use a two-stage register access scheme: if we are interrupted in
- * between setting the indirect address register and reading from the
- * indirect data register, the contents of the address register could
- * be changed out from under us.
- */
-static void
-sf_stats_update(xsc)
- void *xsc;
-{
- struct sf_softc *sc;
- struct ifnet *ifp;
- struct mii_data *mii;
- struct sf_stats stats;
- u_int32_t *ptr;
- int i;
-
- sc = xsc;
- SF_LOCK(sc);
- ifp = &sc->arpcom.ac_if;
- mii = device_get_softc(sc->sf_miibus);
-
- ptr = (u_int32_t *)&stats;
- for (i = 0; i < sizeof(stats)/sizeof(u_int32_t); i++)
- ptr[i] = csr_read_4(sc, SF_STATS_BASE +
- (i + sizeof(u_int32_t)));
-
- for (i = 0; i < sizeof(stats)/sizeof(u_int32_t); i++)
- csr_write_4(sc, SF_STATS_BASE +
- (i + sizeof(u_int32_t)), 0);
-
- ifp->if_collisions += stats.sf_tx_single_colls +
- stats.sf_tx_multi_colls + stats.sf_tx_excess_colls;
-
- mii_tick(mii);
-
- if (!sc->sf_link && mii->mii_media_status & IFM_ACTIVE &&
- IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
- sc->sf_link++;
- if (ifp->if_snd.ifq_head != NULL)
- sf_start(ifp);
- }
-
- sc->sf_stat_ch = timeout(sf_stats_update, sc, hz);
-
- SF_UNLOCK(sc);
-
- return;
-}
-
-static void
-sf_watchdog(ifp)
- struct ifnet *ifp;
-{
- struct sf_softc *sc;
-
- sc = ifp->if_softc;
-
- SF_LOCK(sc);
-
- ifp->if_oerrors++;
- printf("sf%d: watchdog timeout\n", sc->sf_unit);
-
- sf_stop(sc);
- sf_reset(sc);
- sf_init(sc);
-
- if (ifp->if_snd.ifq_head != NULL)
- sf_start(ifp);
-
- SF_UNLOCK(sc);
-
- return;
-}
-
-static void
-sf_shutdown(dev)
- device_t dev;
-{
- struct sf_softc *sc;
-
- sc = device_get_softc(dev);
-
- sf_stop(sc);
-
- return;
-}
diff --git a/sys/dev/sf/if_sfreg.h b/sys/dev/sf/if_sfreg.h
deleted file mode 100644
index 1975cfce14b4..000000000000
--- a/sys/dev/sf/if_sfreg.h
+++ /dev/null
@@ -1,1060 +0,0 @@
-/*
- * Copyright (c) 1997, 1998, 1999
- * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-/*
- * Registers for the Adaptec AIC-6915 Starfire. The Starfire has a 512K
- * register space. These registers can be accessed in the following way:
- * - PCI config registers are always accessible through PCI config space
- * - Full 512K space mapped into memory using PCI memory mapped access
- * - 256-byte I/O space mapped through PCI I/O access
- * - Full 512K space mapped through indirect I/O using PCI I/O access
- * It's possible to use either memory mapped mode or I/O mode to access
- * the registers, but memory mapped is usually the easiest. All registers
- * are 32 bits wide and must be accessed using 32-bit operations.
- */
-
-/*
- * Adaptec PCI vendor ID.
- */
-#define AD_VENDORID 0x9004
-
-/*
- * AIC-6915 PCI device ID.
- */
-#define AD_DEVICEID_STARFIRE 0x6915
-
-/*
- * AIC-6915 subsystem IDs. Adaptec uses the subsystem ID to identify
- * the exact kind of NIC on which the ASIC is mounted. Currently there
- * are six different variations. Note: the Adaptec manual lists code 0x28
- * for two different NICs: the 62044 and the 69011/TX. This is a typo:
- * the code for the 62044 is really 0x18.
- *
- * Note that there also appears to be an 0x19 code for a newer rev
- * 62044 card.
- */
-#define AD_SUBSYSID_62011_REV0 0x0008 /* single port 10/100baseTX 64-bit */
-#define AD_SUBSYSID_62011_REV1 0x0009 /* single port 10/100baseTX 64-bit */
-#define AD_SUBSYSID_62022 0x0010 /* dual port 10/100baseTX 64-bit */
-#define AD_SUBSYSID_62044_REV0 0x0018 /* quad port 10/100baseTX 64-bit */
-#define AD_SUBSYSID_62044_REV1 0x0019 /* quad port 10/100baseTX 64-bit */
-#define AD_SUBSYSID_62020 0x0020 /* single port 10/100baseFX 64-bit */
-#define AD_SUBSYSID_69011 0x0028 /* single port 10/100baseTX 32-bit */
-
-/*
- * Starfire internal register space map. The entire register space
- * is available using PCI memory mapped mode. The SF_RMAP_INTREG
- * space is available using PCI I/O mode. The entire space can be
- * accessed using indirect I/O using the indirect I/O addr and
- * indirect I/O data registers located within the SF_RMAP_INTREG space.
- */
-#define SF_RMAP_ROMADDR_BASE 0x00000 /* Expansion ROM space */
-#define SF_RMAP_ROMADDR_MAX 0x3FFFF
-
-#define SF_RMAP_EXGPIO_BASE 0x40000 /* External general purpose regs */
-#define SF_RMAP_EXGPIO_MAX 0x3FFFF
-
-#define SF_RMAP_INTREG_BASE 0x50000 /* Internal functional registers */
-#define SF_RMAP_INTREG_MAX 0x500FF
-#define SF_RMAP_GENREG_BASE 0x50100 /* General purpose registers */
-#define SF_RMAP_GENREG_MAX 0x5FFFF
-
-#define SF_RMAP_FIFO_BASE 0x60000
-#define SF_RMAP_FIFO_MAX 0x6FFFF
-
-#define SF_RMAP_STS_BASE 0x70000
-#define SF_RMAP_STS_MAX 0x70083
-
-#define SF_RMAP_RSVD_BASE 0x70084
-#define SF_RMAP_RSVD_MAX 0x7FFFF
-
-/*
- * PCI config header registers, 0x0000 to 0x003F
- */
-#define SF_PCI_VENDOR_ID 0x0000
-#define SF_PCI_DEVICE_ID 0x0002
-#define SF_PCI_COMMAND 0x0004
-#define SF_PCI_STATUS 0x0006
-#define SF_PCI_REVID 0x0008
-#define SF_PCI_CLASSCODE 0x0009
-#define SF_PCI_CACHELEN 0x000C
-#define SF_PCI_LATENCY_TIMER 0x000D
-#define SF_PCI_HEADER_TYPE 0x000E
-#define SF_PCI_LOMEM 0x0010
-#define SF_PCI_LOIO 0x0014
-#define SF_PCI_SUBVEN_ID 0x002C
-#define SF_PCI_SYBSYS_ID 0x002E
-#define SF_PCI_BIOSROM 0x0030
-#define SF_PCI_INTLINE 0x003C
-#define SF_PCI_INTPIN 0x003D
-#define SF_PCI_MINGNT 0x003E
-#define SF_PCI_MINLAT 0x003F
-
-/*
- * PCI registers, 0x0040 to 0x006F
- */
-#define SF_PCI_DEVCFG 0x0040
-#define SF_BACCTL 0x0044
-#define SF_PCI_MON1 0x0048
-#define SF_PCI_MON2 0x004C
-#define SF_PCI_CAPID 0x0050 /* 8 bits */
-#define SF_PCI_NEXTPTR 0x0051 /* 8 bits */
-#define SF_PCI_PWRMGMTCAP 0x0052 /* 16 bits */
-#define SF_PCI_PWRMGMTCTRL 0x0054 /* 16 bits */
-#define SF_PCI_PME_EVENT 0x0058
-#define SF_PCI_EECTL 0x0060
-#define SF_PCI_COMPLIANCE 0x0064
-#define SF_INDIRECTIO_ADDR 0x0068
-#define SF_INDIRECTIO_DATA 0x006C
-
-#define SF_PCIDEVCFG_RESET 0x00000001
-#define SF_PCIDEVCFG_FORCE64 0x00000002
-#define SF_PCIDEVCFG_SYSTEM64 0x00000004
-#define SF_PCIDEVCFG_RSVD0 0x00000008
-#define SF_PCIDEVCFG_INCR_INB 0x00000010
-#define SF_PCIDEVCFG_ABTONPERR 0x00000020
-#define SF_PCIDEVCFG_STPONPERR 0x00000040
-#define SF_PCIDEVCFG_MR_ENB 0x00000080
-#define SF_PCIDEVCFG_FIFOTHR 0x00000F00
-#define SF_PCIDEVCFG_STPONCA 0x00001000
-#define SF_PCIDEVCFG_PCIMEN 0x00002000 /* enable PCI bus master */
-#define SF_PCIDEVCFG_LATSTP 0x00004000
-#define SF_PCIDEVCFG_BYTE_ENB 0x00008000
-#define SF_PCIDEVCFG_EECSWIDTH 0x00070000
-#define SF_PCIDEVCFG_STPMWCA 0x00080000
-#define SF_PCIDEVCFG_REGCSWIDTH 0x00700000
-#define SF_PCIDEVCFG_INTR_ENB 0x00800000
-#define SF_PCIDEVCFG_DPR_ENB 0x01000000
-#define SF_PCIDEVCFG_RSVD1 0x02000000
-#define SF_PCIDEVCFG_RSVD2 0x04000000
-#define SF_PCIDEVCFG_STA_ENB 0x08000000
-#define SF_PCIDEVCFG_RTA_ENB 0x10000000
-#define SF_PCIDEVCFG_RMA_ENB 0x20000000
-#define SF_PCIDEVCFG_SSE_ENB 0x40000000
-#define SF_PCIDEVCFG_DPE_ENB 0x80000000
-
-#define SF_BACCTL_BACDMA_ENB 0x00000001
-#define SF_BACCTL_PREFER_RXDMA 0x00000002
-#define SF_BACCTL_PREFER_TXDMA 0x00000004
-#define SF_BACCTL_SINGLE_DMA 0x00000008
-#define SF_BACCTL_SWAPMODE_DATA 0x00000030
-#define SF_BACCTL_SWAPMODE_DESC 0x000000C0
-
-#define SF_SWAPMODE_LE 0x00000000
-#define SF_SWAPMODE_BE 0x00000010
-
-#define SF_PSTATE_MASK 0x0003
-#define SF_PSTATE_D0 0x0000
-#define SF_PSTATE_D1 0x0001
-#define SF_PSTATE_D2 0x0002
-#define SF_PSTATE_D3 0x0003
-#define SF_PME_EN 0x0010
-#define SF_PME_STATUS 0x8000
-
-
-/*
- * Ethernet registers 0x0070 to 0x00FF
- */
-#define SF_GEN_ETH_CTL 0x0070
-#define SF_TIMER_CTL 0x0074
-#define SF_CURTIME 0x0078
-#define SF_ISR 0x0080
-#define SF_ISR_SHADOW 0x0084
-#define SF_IMR 0x0088
-#define SF_GPIO 0x008C
-#define SF_TXDQ_CTL 0x0090
-#define SF_TXDQ_ADDR_HIPRIO 0x0094
-#define SF_TXDQ_ADDR_LOPRIO 0x0098
-#define SF_TXDQ_ADDR_HIADDR 0x009C
-#define SF_TXDQ_PRODIDX 0x00A0
-#define SF_TXDQ_CONSIDX 0x00A4
-#define SF_TXDMA_STS1 0x00A8
-#define SF_TXDMA_STS2 0x00AC
-#define SF_TX_FRAMCTL 0x00B0
-#define SF_TXCQ_ADDR_HI 0x00B4
-#define SF_TXCQ_CTL 0x00B8
-#define SF_RXCQ_CTL_1 0x00BC
-#define SF_RXCQ_CTL_2 0x00C0
-#define SF_CQ_CONSIDX 0x00C4
-#define SF_CQ_PRODIDX 0x00C8
-#define SF_CQ_RXQ2 0x00CC
-#define SF_RXDMA_CTL 0x00D0
-#define SF_RXDQ_CTL_1 0x00D4
-#define SF_RXDQ_CTL_2 0x00D8
-#define SF_RXDQ_ADDR_HIADDR 0x00DC
-#define SF_RXDQ_ADDR_Q1 0x00E0
-#define SF_RXDQ_ADDR_Q2 0x00E4
-#define SF_RXDQ_PTR_Q1 0x00E8
-#define SF_RXDQ_PTR_Q2 0x00EC
-#define SF_RXDMA_STS 0x00F0
-#define SF_RXFILT 0x00F4
-#define SF_RX_FRAMETEST_OUT 0x00F8
-
-/* Ethernet control register */
-#define SF_ETHCTL_RX_ENB 0x00000001
-#define SF_ETHCTL_TX_ENB 0x00000002
-#define SF_ETHCTL_RXDMA_ENB 0x00000004
-#define SF_ETHCTL_TXDMA_ENB 0x00000008
-#define SF_ETHCTL_RXGFP_ENB 0x00000010
-#define SF_ETHCTL_TXGFP_ENB 0x00000020
-#define SF_ETHCTL_SOFTINTR 0x00000800
-
-/* Timer control register */
-#define SF_TIMER_IMASK_INTERVAL 0x0000001F
-#define SF_TIMER_IMASK_MODE 0x00000060
-#define SF_TIMER_SMALLFRAME_BYP 0x00000100
-#define SF_TIMER_SMALLRX_FRAME 0x00000600
-#define SF_TIMER_TIMES_TEN 0x00000800
-#define SF_TIMER_RXHIPRIO_BYP 0x00001000
-#define SF_TIMER_TX_DMADONE_DLY 0x00002000
-#define SF_TIMER_TX_QDONE_DLY 0x00004000
-#define SF_TIMER_TX_FRDONE_DLY 0x00008000
-#define SF_TIMER_GENTIMER 0x00FF0000
-#define SF_TIMER_ONESHOT 0x01000000
-#define SF_TIMER_GENTIMER_RES 0x02000000
-#define SF_TIMER_TIMEST_RES 0x04000000
-#define SF_TIMER_RXQ2DONE_DLY 0x10000000
-#define SF_TIMER_EARLYRX2_DLY 0x20000000
-#define SF_TIMER_RXQ1DONE_DLY 0x40000000
-#define SF_TIMER_EARLYRX1_DLY 0x80000000
-
-/* Interrupt status register */
-#define SF_ISR_PCIINT_ASSERTED 0x00000001
-#define SF_ISR_GFP_TX 0x00000002
-#define SF_ISR_GFP_RX 0x00000004
-#define SF_ISR_TX_BADID_HIPRIO 0x00000008
-#define SF_ISR_TX_BADID_LOPRIO 0x00000010
-#define SF_ISR_NO_TX_CSUM 0x00000020
-#define SF_ISR_RXDQ2_NOBUFS 0x00000040
-#define SF_ISR_RXGFP_NORESP 0x00000080
-#define SF_ISR_RXDQ1_DMADONE 0x00000100
-#define SF_ISR_RXDQ2_DMADONE 0x00000200
-#define SF_ISR_RXDQ1_EARLY 0x00000400
-#define SF_ISR_RXDQ2_EARLY 0x00000800
-#define SF_ISR_TX_QUEUEDONE 0x00001000
-#define SF_ISR_TX_DMADONE 0x00002000
-#define SF_ISR_TX_TXDONE 0x00004000
-#define SF_ISR_NORMALINTR 0x00008000
-#define SF_ISR_RXDQ1_NOBUFS 0x00010000
-#define SF_ISR_RXCQ2_NOBUFS 0x00020000
-#define SF_ISR_TX_LOFIFO 0x00040000
-#define SF_ISR_DMAERR 0x00080000
-#define SF_ISR_PCIINT 0x00100000
-#define SF_ISR_TXCQ_NOBUFS 0x00200000
-#define SF_ISR_RXCQ1_NOBUFS 0x00400000
-#define SF_ISR_SOFTINTR 0x00800000
-#define SF_ISR_GENTIMER 0x01000000
-#define SF_ISR_ABNORMALINTR 0x02000000
-#define SF_ISR_RSVD0 0x04000000
-#define SF_ISR_STATSOFLOW 0x08000000
-#define SF_ISR_GPIO 0xF0000000
-
-/*
- * Shadow interrupt status register. Unlike the normal IRQ register,
- * reading bits here does not automatically cause them to reset.
- */
-#define SF_SISR_PCIINT_ASSERTED 0x00000001
-#define SF_SISR_GFP_TX 0x00000002
-#define SF_SISR_GFP_RX 0x00000004
-#define SF_SISR_TX_BADID_HIPRIO 0x00000008
-#define SF_SISR_TX_BADID_LOPRIO 0x00000010
-#define SF_SISR_NO_TX_CSUM 0x00000020
-#define SF_SISR_RXDQ2_NOBUFS 0x00000040
-#define SF_SISR_RXGFP_NORESP 0x00000080
-#define SF_SISR_RXDQ1_DMADONE 0x00000100
-#define SF_SISR_RXDQ2_DMADONE 0x00000200
-#define SF_SISR_RXDQ1_EARLY 0x00000400
-#define SF_SISR_RXDQ2_EARLY 0x00000800
-#define SF_SISR_TX_QUEUEDONE 0x00001000
-#define SF_SISR_TX_DMADONE 0x00002000
-#define SF_SISR_TX_TXDONE 0x00004000
-#define SF_SISR_NORMALINTR 0x00008000
-#define SF_SISR_RXDQ1_NOBUFS 0x00010000
-#define SF_SISR_RXCQ2_NOBUFS 0x00020000
-#define SF_SISR_TX_LOFIFO 0x00040000
-#define SF_SISR_DMAERR 0x00080000
-#define SF_SISR_PCIINT 0x00100000
-#define SF_SISR_TXCQ_NOBUFS 0x00200000
-#define SF_SISR_RXCQ1_NOBUFS 0x00400000
-#define SF_SISR_SOFTINTR 0x00800000
-#define SF_SISR_GENTIMER 0x01000000
-#define SF_SISR_ABNORMALINTR 0x02000000
-#define SF_SISR_RSVD0 0x04000000
-#define SF_SISR_STATSOFLOW 0x08000000
-#define SF_SISR_GPIO 0xF0000000
-
-/* Interrupt mask register */
-#define SF_IMR_PCIINT_ASSERTED 0x00000001
-#define SF_IMR_GFP_TX 0x00000002
-#define SF_IMR_GFP_RX 0x00000004
-#define SF_IMR_TX_BADID_HIPRIO 0x00000008
-#define SF_IMR_TX_BADID_LOPRIO 0x00000010
-#define SF_IMR_NO_TX_CSUM 0x00000020
-#define SF_IMR_RXDQ2_NOBUFS 0x00000040
-#define SF_IMR_RXGFP_NORESP 0x00000080
-#define SF_IMR_RXDQ1_DMADONE 0x00000100
-#define SF_IMR_RXDQ2_DMADONE 0x00000200
-#define SF_IMR_RXDQ1_EARLY 0x00000400
-#define SF_IMR_RXDQ2_EARLY 0x00000800
-#define SF_IMR_TX_QUEUEDONE 0x00001000
-#define SF_IMR_TX_DMADONE 0x00002000
-#define SF_IMR_TX_TXDONE 0x00004000
-#define SF_IMR_NORMALINTR 0x00008000
-#define SF_IMR_RXDQ1_NOBUFS 0x00010000
-#define SF_IMR_RXCQ2_NOBUFS 0x00020000
-#define SF_IMR_TX_LOFIFO 0x00040000
-#define SF_IMR_DMAERR 0x00080000
-#define SF_IMR_PCIINT 0x00100000
-#define SF_IMR_TXCQ_NOBUFS 0x00200000
-#define SF_IMR_RXCQ1_NOBUFS 0x00400000
-#define SF_IMR_SOFTINTR 0x00800000
-#define SF_IMR_GENTIMER 0x01000000
-#define SF_IMR_ABNORMALINTR 0x02000000
-#define SF_IMR_RSVD0 0x04000000
-#define SF_IMR_STATSOFLOW 0x08000000
-#define SF_IMR_GPIO 0xF0000000
-
-#define SF_INTRS \
- (SF_IMR_RXDQ2_NOBUFS|SF_IMR_RXDQ1_DMADONE|SF_IMR_RXDQ2_DMADONE| \
- SF_IMR_TX_TXDONE|SF_IMR_RXDQ1_NOBUFS|SF_IMR_RXDQ2_DMADONE| \
- SF_IMR_NORMALINTR|SF_IMR_ABNORMALINTR|SF_IMR_TXCQ_NOBUFS| \
- SF_IMR_RXCQ1_NOBUFS|SF_IMR_RXCQ2_NOBUFS|SF_IMR_STATSOFLOW| \
- SF_IMR_TX_LOFIFO)
-
-/* TX descriptor queue control registers */
-#define SF_TXDQCTL_DESCTYPE 0x00000007
-#define SF_TXDQCTL_NODMACMP 0x00000008
-#define SF_TXDQCTL_MINSPACE 0x00000070
-#define SF_TXDQCTL_64BITADDR 0x00000080
-#define SF_TXDQCTL_BURSTLEN 0x00003F00
-#define SF_TXDQCTL_SKIPLEN 0x001F0000
-#define SF_TXDQCTL_HIPRIOTHRESH 0xFF000000
-
-#define SF_TXBUFDESC_TYPE0 0x00000000
-#define SF_TXBUFDESC_TYPE1 0x00000001
-#define SF_TXBUFDESC_TYPE2 0x00000002
-#define SF_TXBUFDESC_TYPE3 0x00000003
-#define SF_TXBUFDESC_TYPE4 0x00000004
-
-#define SF_TXMINSPACE_UNLIMIT 0x00000000
-#define SF_TXMINSPACE_32BYTES 0x00000010
-#define SF_TXMINSPACE_64BYTES 0x00000020
-#define SF_TXMINSPACE_128BYTES 0x00000030
-#define SF_TXMINSPACE_256BYTES 0x00000040
-
-#define SF_TXSKIPLEN_0BYTES 0x00000000
-#define SF_TXSKIPLEN_8BYTES 0x00010000
-#define SF_TXSKIPLEN_16BYTES 0x00020000
-#define SF_TXSKIPLEN_24BYTES 0x00030000
-#define SF_TXSKIPLEN_32BYTES 0x00040000
-
-/* TX frame control register */
-#define SF_TXFRMCTL_TXTHRESH 0x000000FF
-#define SF_TXFRMCTL_CPLAFTERTX 0x00000100
-#define SF_TXFRMCRL_DEBUG 0x0000FE00
-#define SF_TXFRMCTL_STATUS 0x01FF0000
-#define SF_TXFRMCTL_MAC_TXIF 0xFE000000
-
-/* TX completion queue control register */
-#define SF_TXCQ_THRESH 0x0000000F
-#define SF_TXCQ_COMMON 0x00000010
-#define SF_TXCQ_SIZE 0x00000020
-#define SF_TXCQ_WRITEENB 0x00000040
-#define SF_TXCQ_USE_64BIT 0x00000080
-#define SF_TXCQ_ADDR 0xFFFFFF00
-
-/* RX completion queue control register */
-#define SF_RXCQ_THRESH 0x0000000F
-#define SF_RXCQ_TYPE 0x00000030
-#define SF_RXCQ_WRITEENB 0x00000040
-#define SF_RXCQ_USE_64BIT 0x00000080
-#define SF_RXCQ_ADDR 0xFFFFFF00
-
-#define SF_RXCQTYPE_0 0x00000000
-#define SF_RXCQTYPE_1 0x00000010
-#define SF_RXCQTYPE_2 0x00000020
-#define SF_RXCQTYPE_3 0x00000030
-
-/* TX descriptor queue producer index register */
-#define SF_TXDQ_PRODIDX_LOPRIO 0x000007FF
-#define SF_TXDQ_PRODIDX_HIPRIO 0x07FF0000
-
-/* TX descriptor queue consumer index register */
-#define SF_TXDQ_CONSIDX_LOPRIO 0x000007FF
-#define SF_TXDQ_CONSIDX_HIPRIO 0x07FF0000
-
-/* Completion queue consumer index register */
-#define SF_CQ_CONSIDX_RXQ1 0x000003FF
-#define SF_CQ_CONSIDX_RXTHRMODE 0x00008000
-#define SF_CQ_CONSIDX_TXQ 0x03FF0000
-#define SF_CQ_CONSIDX_TXTHRMODE 0x80000000
-
-/* Completion queue producer index register */
-#define SF_CQ_PRODIDX_RXQ1 0x000003FF
-#define SF_CQ_PRODIDX_TXQ 0x03FF0000
-
-/* RX completion queue 2 consumer/producer index register */
-#define SF_CQ_RXQ2_CONSIDX 0x000003FF
-#define SF_CQ_RXQ2_RXTHRMODE 0x00008000
-#define SF_CQ_RXQ2_PRODIDX 0x03FF0000
-
-#define SF_CQ_RXTHRMODE_INT_ON 0x00008000
-#define SF_CQ_RXTHRMODE_INT_OFF 0x00000000
-#define SF_CQ_TXTHRMODE_INT_ON 0x80000000
-#define SF_CQ_TXTHRMODE_INT_OFF 0x00000000
-
-#define SF_IDX_LO(x) ((x) & 0x000007FF)
-#define SF_IDX_HI(x) (((x) >> 16) & 0x000007FF)
-
-/* RX DMA control register */
-#define SF_RXDMA_BURSTSIZE 0x0000007F
-#define SF_RXDMA_FPTESTMODE 0x00000080
-#define SF_RXDMA_HIPRIOTHRESH 0x00000F00
-#define SF_RXDMA_RXEARLYTHRESH 0x0001F000
-#define SF_RXDMA_DMACRC 0x00040000
-#define SF_RXDMA_USEBKUPQUEUE 0x00080000
-#define SF_RXDMA_QUEUEMODE 0x00700000
-#define SF_RXDMA_RXCQ2_ON 0x00800000
-#define SF_RXDMA_CSUMMODE 0x03000000
-#define SF_RXDMA_DMAPAUSEPKTS 0x04000000
-#define SF_RXDMA_DMACTLPKTS 0x08000000
-#define SF_RXDMA_DMACRXERRPKTS 0x10000000
-#define SF_RXDMA_DMABADPKTS 0x20000000
-#define SF_RXDMA_DMARUNTS 0x40000000
-#define SF_RXDMA_REPORTBADPKTS 0x80000000
-
-#define SF_RXDQMODE_Q1ONLY 0x00100000
-#define SF_RXDQMODE_Q2_ON_FP 0x00200000
-#define SF_RXDQMODE_Q2_ON_SHORT 0x00300000
-#define SF_RXDQMODE_Q2_ON_PRIO 0x00400000
-#define SF_RXDQMODE_SPLITHDR 0x00500000
-
-#define SF_RXCSUMMODE_IGNORE 0x00000000
-#define SF_RXCSUMMODE_REJECT_BAD_TCP 0x01000000
-#define SF_RXCSUMMODE_REJECT_BAD_TCPUDP 0x02000000
-#define SF_RXCSUMMODE_RSVD 0x03000000
-
-/* RX descriptor queue control registers */
-#define SF_RXDQCTL_MINDESCTHR 0x0000007F
-#define SF_RXDQCTL_Q1_WE 0x00000080
-#define SF_RXDQCTL_DESCSPACE 0x00000700
-#define SF_RXDQCTL_64BITDADDR 0x00000800
-#define SF_RXDQCTL_64BITBADDR 0x00001000
-#define SF_RXDQCTL_VARIABLE 0x00002000
-#define SF_RXDQCTL_ENTRIES 0x00004000
-#define SF_RXDQCTL_PREFETCH 0x00008000
-#define SF_RXDQCTL_BUFLEN 0xFFFF0000
-
-#define SF_DESCSPACE_4BYTES 0x00000000
-#define SF_DESCSPACE_8BYTES 0x00000100
-#define SF_DESCSPACE_16BYTES 0x00000200
-#define SF_DESCSPACE_32BYTES 0x00000300
-#define SF_DESCSPACE_64BYTES 0x00000400
-#define SF_DESCSPACE_128_BYTES 0x00000500
-
-/* RX buffer consumer/producer index registers */
-#define SF_RXDQ_PRODIDX 0x000007FF
-#define SF_RXDQ_CONSIDX 0x07FF0000
-
-/* RX filter control register */
-#define SF_RXFILT_PROMISC 0x00000001
-#define SF_RXFILT_ALLMULTI 0x00000002
-#define SF_RXFILT_BROAD 0x00000004
-#define SF_RXFILT_HASHPRIO 0x00000008
-#define SF_RXFILT_HASHMODE 0x00000030
-#define SF_RXFILT_PERFMODE 0x000000C0
-#define SF_RXFILT_VLANMODE 0x00000300
-#define SF_RXFILT_WAKEMODE 0x00000C00
-#define SF_RXFILT_MULTI_NOBROAD 0x00001000
-#define SF_RXFILT_MIN_VLANPRIO 0x0000E000
-#define SF_RXFILT_PEFECTPRIO 0xFFFF0000
-
-/* Hash filtering mode */
-#define SF_HASHMODE_OFF 0x00000000
-#define SF_HASHMODE_WITHVLAN 0x00000010
-#define SF_HASHMODE_ANYVLAN 0x00000020
-#define SF_HASHMODE_ANY 0x00000030
-
-/* Perfect filtering mode */
-#define SF_PERFMODE_OFF 0x00000000
-#define SF_PERFMODE_NORMAL 0x00000040
-#define SF_PERFMODE_INVERSE 0x00000080
-#define SF_PERFMODE_VLAN 0x000000C0
-
-/* VLAN mode */
-#define SF_VLANMODE_OFF 0x00000000
-#define SF_VLANMODE_NOSTRIP 0x00000100
-#define SF_VLANMODE_STRIP 0x00000200
-#define SF_VLANMODE_RSVD 0x00000300
-
-/* Wakeup mode */
-#define SF_WAKEMODE_OFF 0x00000000
-#define SF_WAKEMODE_FILTER 0x00000400
-#define SF_WAKEMODE_FP 0x00000800
-#define SF_WAKEMODE_HIPRIO 0x00000C00
-
-/*
- * Extra PCI registers 0x0100 to 0x0FFF
- */
-#define SF_PCI_TARGSTAT 0x0100
-#define SF_PCI_MASTSTAT1 0x0104
-#define SF_PCI_MASTSTAT2 0x0108
-#define SF_PCI_DMAHOSTADDR_LO 0x010C
-#define SF_BAC_DMADIAG0 0x0110
-#define SF_BAC_DMADIAG1 0x0114
-#define SF_BAC_DMADIAG2 0x0118
-#define SF_BAC_DMADIAG3 0x011C
-#define SF_PAR0 0x0120
-#define SF_PAR1 0x0124
-#define SF_PCICB_FUNCEVENT 0x0130
-#define SF_PCICB_FUNCEVENT_MASK 0x0134
-#define SF_PCICB_FUNCSTATE 0x0138
-#define SF_PCICB_FUNCFORCE 0x013C
-
-/*
- * Serial EEPROM registers 0x1000 to 0x1FFF
- * Presumeably the EEPROM is mapped into this 8K window.
- */
-#define SF_EEADDR_BASE 0x1000
-#define SF_EEADDR_MAX 0x1FFF
-
-#define SF_EE_NODEADDR 14
-
-/*
- * MII registers registers 0x2000 to 0x3FFF
- * There are 32 sets of 32 registers, one set for each possible
- * PHY address. Each 32 bit register is split into a 16-bit data
- * port and a couple of status bits.
- */
-
-#define SF_MIIADDR_BASE 0x2000
-#define SF_MIIADDR_MAX 0x3FFF
-#define SF_MII_BLOCKS 32
-
-#define SF_MII_DATAVALID 0x80000000
-#define SF_MII_BUSY 0x40000000
-#define SF_MII_DATAPORT 0x0000FFFF
-
-#define SF_PHY_REG(phy, reg) \
- (SF_MIIADDR_BASE + (phy * SF_MII_BLOCKS * sizeof(u_int32_t)) + \
- (reg * sizeof(u_int32_t)))
-
-/*
- * Ethernet extra registers 0x4000 to 0x4FFF
- */
-#define SF_TESTMODE 0x4000
-#define SF_RX_FRAMEPROC_CTL 0x4004
-#define SF_TX_FRAMEPROC_CTL 0x4008
-
-/*
- * MAC registers 0x5000 to 0x5FFF
- */
-#define SF_MACCFG_1 0x5000
-#define SF_MACCFG_2 0x5004
-#define SF_BKTOBKIPG 0x5008
-#define SF_NONBKTOBKIPG 0x500C
-#define SF_COLRETRY 0x5010
-#define SF_MAXLEN 0x5014
-#define SF_TXNIBBLECNT 0x5018
-#define SF_TXBYTECNT 0x501C
-#define SF_RETXCNT 0x5020
-#define SF_RANDNUM 0x5024
-#define SF_RANDNUM_MASK 0x5028
-#define SF_TOTALTXCNT 0x5034
-#define SF_RXBYTECNT 0x5040
-#define SF_TXPAUSETIMER 0x5060
-#define SF_VLANTYPE 0x5064
-#define SF_MIISTATUS 0x5070
-
-#define SF_MACCFG1_HUGEFRAMES 0x00000001
-#define SF_MACCFG1_FULLDUPLEX 0x00000002
-#define SF_MACCFG1_AUTOPAD 0x00000004
-#define SF_MACCFG1_HDJAM 0x00000008
-#define SF_MACCFG1_DELAYCRC 0x00000010
-#define SF_MACCFG1_NOBACKOFF 0x00000020
-#define SF_MACCFG1_LENGTHCHECK 0x00000040
-#define SF_MACCFG1_PUREPREAMBLE 0x00000080
-#define SF_MACCFG1_PASSALLRX 0x00000100
-#define SF_MACCFG1_PREAM_DETCNT 0x00000200
-#define SF_MACCFG1_RX_FLOWENB 0x00000400
-#define SF_MACCFG1_TX_FLOWENB 0x00000800
-#define SF_MACCFG1_TESTMODE 0x00003000
-#define SF_MACCFG1_MIILOOPBK 0x00004000
-#define SF_MACCFG1_SOFTRESET 0x00008000
-
-/*
- * There are the recommended IPG nibble counter settings
- * specified in the Adaptec manual for full duplex and
- * half duplex operation.
- */
-#define SF_IPGT_FDX 0x15
-#define SF_IPGT_HDX 0x11
-
-/*
- * RX filter registers 0x6000 to 0x6FFF
- */
-#define SF_RXFILT_PERFECT_BASE 0x6000
-#define SF_RXFILT_PERFECT_MAX 0x60FF
-#define SF_RXFILT_PERFECT_SKIP 0x0010
-#define SF_RXFILT_PERFECT_CNT 0x0010
-
-#define SF_RXFILT_HASH_BASE 0x6100
-#define SF_RXFILT_HASH_MAX 0x62FF
-#define SF_RXFILT_HASH_SKIP 0x0010
-#define SF_RXFILT_HASH_CNT 0x001F
-#define SF_RXFILT_HASH_ADDROFF 0x0000
-#define SF_RXFILT_HASH_PRIOOFF 0x0004
-#define SF_RXFILT_HASH_VLANOFF 0x0008
-
-/*
- * Statistics registers 0x7000 to 0x7FFF
- */
-#define SF_STATS_BASE 0x7000
-#define SF_STATS_END 0x7FFF
-
-/*
- * TX frame processor instruction space 0x8000 to 0x9FFF
- */
-
-/*
- * RX frame processor instruction space 0xA000 to 0xBFFF
- */
-
-/*
- * Ethernet FIFO access space 0xC000 to 0xDFFF
- */
-
-/*
- * Reserved 0xE000 to 0xFFFF
- */
-
-/*
- * Descriptor data structures.
- */
-
-
-/* Receive descriptor formats. */
-#define SF_RX_MINSPACING 8
-#define SF_RX_DLIST_CNT 256
-#define SF_RX_CLIST_CNT 1024
-#define SF_RX_HOSTADDR(x) (((x) >> 2) & 0x3FFFFFFF)
-
-/*
- * RX buffer descriptor type 0, 32-bit addressing. Note that we
- * program the RX buffer queue control register(s) to allow a
- * descriptor spacing of 16 bytes, which leaves room after each
- * descriptor to store a pointer to the mbuf for each buffer.
- */
-struct sf_rx_bufdesc_type0 {
- u_int32_t sf_valid:1,
- sf_end:1,
- sf_addrlo:30;
- u_int32_t sf_pad0;
-#ifdef __i386__
- u_int32_t sf_pad1;
-#endif
- struct mbuf *sf_mbuf;
-};
-
-/*
- * RX buffer descriptor type 0, 64-bit addressing.
- */
-struct sf_rx_bufdesc_type1 {
- u_int32_t sf_valid:1,
- sf_end:1,
- sf_addrlo:30;
- u_int32_t sf_addrhi;
-#ifdef __i386__
- u_int32_t sf_pad;
-#endif
- struct mbuf *sf_mbuf;
-};
-
-/*
- * RX completion descriptor, type 0 (short).
- */
-struct sf_rx_cmpdesc_type0 {
- u_int32_t sf_len:16,
- sf_endidx:11,
- sf_status1:3,
- sf_id:2;
-};
-
-/*
- * RX completion descriptor, type 1 (basic). Includes vlan ID
- * if this is a vlan-addressed packet, plus extended status.
- */
-struct sf_rx_cmpdesc_type1 {
- u_int32_t sf_len:16,
- sf_endidx:11,
- sf_status1:3,
- sf_id:2;
- u_int16_t sf_status2;
- u_int16_t sf_vlanid;
-};
-
-/*
- * RX completion descriptor, type 2 (checksum). Includes partial TCP/IP
- * checksum instead of vlan tag, plus extended status.
- */
-struct sf_rx_cmpdesc_type2 {
- u_int32_t sf_len:16,
- sf_endidx:11,
- sf_status1:3,
- sf_id:2;
- u_int16_t sf_status2;
- u_int16_t sf_cksum;
-};
-
-/*
- * RX completion descriptor type 3 (full). Includes timestamp, partial
- * TCP/IP checksum, vlan tag plus priority, two extended status fields.
- */
-struct sf_rx_cmpdesc_type3 {
- u_int32_t sf_len:16,
- sf_endidx:11,
- sf_status1:3,
- sf_id:2;
- u_int32_t sf_startidx:10,
- sf_status3:6,
- sf_status2:16;
- u_int16_t sf_cksum;
- u_int16_t sf_vlanid_prio;
- u_int32_t sf_timestamp;
-};
-
-#define SF_RXSTAT1_QUEUE 0x1
-#define SF_RXSTAT1_FIFOFULL 0x2
-#define SF_RXSTAT1_OK 0x4
-
- /* 0=unknown,5=unsupported */
-#define SF_RXSTAT2_FRAMETYPE 0x0007 /* 1=IPv4,2=IPv2,3=IPX,4=ICMP */
-#define SF_RXSTAT2_UDP 0x0008
-#define SF_RXSTAT2_TCP 0x0010
-#define SF_RXSTAT2_FRAG 0x0020
-#define SF_RXSTAT2_PCSUM_OK 0x0040 /* partial checksum ok */
-#define SF_RXSTAT2_CSUM_BAD 0x0080 /* TCP/IP checksum bad */
-#define SF_RXSTAT2_CSUM_OK 0x0100 /* TCP/IP checksum ok */
-#define SF_RXSTAT2_VLAN 0x0200
-#define SF_RXSTAT2_BADRXCODE 0x0400
-#define SF_RXSTAT2_DRIBBLE 0x0800
-#define SF_RXSTAT2_ISL_CRCERR 0x1000
-#define SF_RXSTAT2_CRCERR 0x2000
-#define SF_RXSTAT2_HASH 0x4000
-#define SF_RXSTAT2_PERFECT 0x8000
-
-#define SF_RXSTAT3_TRAILER 0x01
-#define SF_RXSTAT3_HEADER 0x02
-#define SF_RXSTAT3_CONTROL 0x04
-#define SF_RXSTAT3_PAUSE 0x08
-#define SF_RXSTAT3_ISL 0x10
-
-/*
- * Transmit descriptor formats.
- * Each transmit descriptor type allows for a skip field at the
- * start of each structure. The size of the skip field can vary,
- * however we always set it for 8 bytes, which is enough to hold
- * a pointer (32 bits on x86, 64-bits on alpha) that we can use
- * to hold the address of the head of the mbuf chain for the
- * frame or fragment associated with the descriptor. This saves
- * us from having to create a separate pointer array to hold
- * the mbuf addresses.
- */
-#define SF_TX_BUFDESC_ID 0xB
-#define SF_MAXFRAGS 14
-#define SF_TX_MINSPACING 128
-#define SF_TX_DLIST_CNT 128
-#define SF_TX_DLIST_SIZE 16384
-#define SF_TX_SKIPLEN 1
-#define SF_TX_CLIST_CNT 1024
-
-struct sf_frag {
- u_int32_t sf_addr;
- u_int16_t sf_fraglen;
- u_int16_t sf_pktlen;
-};
-
-struct sf_frag_msdos {
- u_int16_t sf_pktlen;
- u_int16_t sf_fraglen;
- u_int32_t sf_addr;
-};
-
-/*
- * TX frame descriptor type 0, 32-bit addressing. One descriptor can
- * be used to map multiple packet fragments. We use this format since
- * BSD networking fragments packet data across mbuf chains. Note that
- * the number of fragments can be variable depending on how the descriptor
- * spacing is specified in the TX descriptor queue control register.
- * We always use a spacing of 128 bytes, and a skipfield length of 8
- * bytes: this means 16 bytes for the descriptor, including the skipfield,
- * with 121 bytes left for fragment maps. Each fragment requires 8 bytes,
- * which allows for 14 fragments per descriptor. The total size of the
- * transmit buffer queue is limited to 16384 bytes, so with a spacing of
- * 128 bytes per descriptor, we have room for 128 descriptors in the queue.
- */
-struct sf_tx_bufdesc_type0 {
-#ifdef __i386__
- u_int32_t sf_pad;
-#endif
- struct mbuf *sf_mbuf;
- u_int32_t sf_rsvd0:24,
- sf_crcen:1,
- sf_caltcp:1,
- sf_end:1,
- sf_intr:1,
- sf_id:4;
- u_int8_t sf_fragcnt;
- u_int8_t sf_rsvd2;
- u_int16_t sf_rsvd1;
- struct sf_frag sf_frags[14];
-};
-
-/*
- * TX buffer descriptor type 1, 32-bit addressing. Each descriptor
- * maps a single fragment.
- */
-struct sf_tx_bufdesc_type1 {
-#ifdef __i386__
- u_int32_t sf_pad;
-#endif
- struct mbuf *sf_mbuf;
- u_int32_t sf_fraglen:16,
- sf_fragcnt:8,
- sf_crcen:1,
- sf_caltcp:1,
- sf_end:1,
- sf_intr:1,
- sf_id:4;
- u_int32_t sf_addr;
-};
-
-/*
- * TX buffer descriptor type 2, 64-bit addressing. Each descriptor
- * maps a single fragment.
- */
-struct sf_tx_bufdesc_type2 {
-#ifdef __i386__
- u_int32_t sf_pad;
-#endif
- struct mbuf *sf_mbuf;
- u_int32_t sf_fraglen:16,
- sf_fragcnt:8,
- sf_crcen:1,
- sf_caltcp:1,
- sf_end:1,
- sf_intr:1,
- sf_id:4;
- u_int32_t sf_addrlo;
- u_int32_t sf_addrhi;
-};
-
-/* TX buffer descriptor type 3 is not defined. */
-
-/*
- * TX frame descriptor type 4, 32-bit addressing. This is a special
- * case of the type 0 descriptor, identical except that the fragment
- * address and length fields are ordered differently. This is done
- * to optimize copies in MS-DOS and OS/2 drivers.
- */
-struct sf_tx_bufdesc_type4 {
-#ifdef __i386__
- u_int32_t sf_pad;
-#endif
- struct mbuf *sf_mbuf;
- u_int32_t sf_rsvd0:24,
- sf_crcen:1,
- sf_caltcp:1,
- sf_end:1,
- sf_intr:1,
- sf_id:4;
- u_int8_t sf_fragcnt;
- u_int8_t sf_rsvd2;
- u_int16_t sf_rsvd1;
- struct sf_frag_msdos sf_frags[14];
-};
-
-/*
- * Transmit completion queue descriptor formats.
- */
-
-/*
- * Transmit DMA completion descriptor, type 0.
- */
-#define SF_TXCMPTYPE_DMA 0x4
-struct sf_tx_cmpdesc_type0 {
- u_int32_t sf_index:15,
- sf_priority:1,
- sf_timestamp:13,
- sf_type:3;
-};
-
-/*
- * Transmit completion descriptor, type 1.
- */
-#define SF_TXCMPTYPE_TX 0x5
-struct sf_tx_cmpdesc_type1 {
- u_int32_t sf_index:15,
- sf_priority:1,
- sf_txstat:13,
- sf_type:3;
-};
-
-#define SF_TXSTAT_CRCERR 0x0001
-#define SF_TXSTAT_LENCHECKERR 0x0002
-#define SF_TXSTAT_LENRANGEERR 0x0004
-#define SF_TXSTAT_TX_OK 0x0008
-#define SF_TXSTAT_TX_DEFERED 0x0010
-#define SF_TXSTAT_EXCESS_DEFER 0x0020
-#define SF_TXSTAT_EXCESS_COLL 0x0040
-#define SF_TXSTAT_LATE_COLL 0x0080
-#define SF_TXSTAT_TOOBIG 0x0100
-#define SF_TXSTAT_TX_UNDERRUN 0x0200
-#define SF_TXSTAT_CTLFRAME_OK 0x0400
-#define SF_TXSTAT_PAUSEFRAME_OK 0x0800
-#define SF_TXSTAT_PAUSED 0x1000
-
-/* Statistics counters. */
-struct sf_stats {
- u_int32_t sf_tx_frames;
- u_int32_t sf_tx_single_colls;
- u_int32_t sf_tx_multi_colls;
- u_int32_t sf_tx_crcerrs;
- u_int32_t sf_tx_bytes;
- u_int32_t sf_tx_defered;
- u_int32_t sf_tx_late_colls;
- u_int32_t sf_tx_pause_frames;
- u_int32_t sf_tx_control_frames;
- u_int32_t sf_tx_excess_colls;
- u_int32_t sf_tx_excess_defer;
- u_int32_t sf_tx_mcast_frames;
- u_int32_t sf_tx_bcast_frames;
- u_int32_t sf_tx_frames_lost;
- u_int32_t sf_rx_rx_frames;
- u_int32_t sf_rx_crcerrs;
- u_int32_t sf_rx_alignerrs;
- u_int32_t sf_rx_bytes;
- u_int32_t sf_rx_control_frames;
- u_int32_t sf_rx_unsup_control_frames;
- u_int32_t sf_rx_giants;
- u_int32_t sf_rx_runts;
- u_int32_t sf_rx_jabbererrs;
- u_int32_t sf_rx_pkts_64;
- u_int32_t sf_rx_pkts_65_127;
- u_int32_t sf_rx_pkts_128_255;
- u_int32_t sf_rx_pkts_256_511;
- u_int32_t sf_rx_pkts_512_1023;
- u_int32_t sf_rx_pkts_1024_1518;
- u_int32_t sf_rx_frames_lost;
- u_int16_t sf_tx_underruns;
- u_int16_t sf_pad;
-};
-
-/*
- * register space access macros
- */
-#define CSR_WRITE_4(sc, reg, val) \
- bus_space_write_4(sc->sf_btag, sc->sf_bhandle, reg, val)
-
-#define CSR_READ_4(sc, reg) \
- bus_space_read_4(sc->sf_btag, sc->sf_bhandle, reg)
-
-#define CSR_READ_1(sc, reg) \
- bus_space_read_1(sc->sf_btag, sc->sf_bhandle, reg)
-
-
-struct sf_type {
- u_int16_t sf_vid;
- u_int16_t sf_did;
- char *sf_name;
-};
-
-#define SF_INC(x, y) (x) = (x + 1) % y
-
-#define ETHER_ALIGN 2
-
-/*
- * Note: alignment is important here: each list must be aligned to
- * a 256-byte boundary. It turns out that each ring is some multiple
- * of 4K in length, so we can stack them all on top of each other
- * and just worry about aligning the whole mess. There's one transmit
- * buffer ring and two receive buffer rings: one RX ring is for small
- * packets and the other is for large packets. Each buffer ring also
- * has a companion completion queue.
- */
-struct sf_list_data {
- struct sf_tx_bufdesc_type0 sf_tx_dlist[SF_TX_DLIST_CNT];
- struct sf_tx_cmpdesc_type1 sf_tx_clist[SF_TX_CLIST_CNT];
- struct sf_rx_bufdesc_type0 sf_rx_dlist_big[SF_RX_DLIST_CNT];
-#ifdef notdef
- /*
- * Unfortunately, because the Starfire doesn't allow arbitrary
- * byte alignment, we have to copy packets in the RX handler in
- * order to align the payload correctly. This means that we
- * don't gain anything by having separate large and small descriptor
- * lists, so for now we don't bother with the small one.
- */
- struct sf_rx_bufdesc_type0 sf_rx_dlist_small[SF_RX_DLIST_CNT];
-#endif
- struct sf_rx_cmpdesc_type3 sf_rx_clist[SF_RX_CLIST_CNT];
-};
-
-struct sf_softc {
- struct arpcom arpcom; /* interface info */
- bus_space_handle_t sf_bhandle; /* bus space handle */
- bus_space_tag_t sf_btag; /* bus space tag */
- void *sf_intrhand; /* interrupt handler cookie */
- struct resource *sf_irq; /* irq resource descriptor */
- struct resource *sf_res; /* mem/ioport resource */
- struct sf_type *sf_info; /* Starfire adapter info */
- device_t sf_miibus;
- u_int8_t sf_unit; /* interface number */
- struct sf_list_data *sf_ldata;
- int sf_tx_cnt;
- u_int8_t sf_link;
- int sf_if_flags;
- struct callout_handle sf_stat_ch;
- struct mtx sf_mtx;
-};
-
-
-#define SF_LOCK(_sc) mtx_lock(&(_sc)->sf_mtx)
-#define SF_UNLOCK(_sc) mtx_unlock(&(_sc)->sf_mtx)
-
-#define SF_TIMEOUT 1000
-
-#ifdef __alpha__
-#undef vtophys
-#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)va)
-#endif
diff --git a/sys/dev/sk/if_sk.c b/sys/dev/sk/if_sk.c
deleted file mode 100644
index 7e4e423d39a8..000000000000
--- a/sys/dev/sk/if_sk.c
+++ /dev/null
@@ -1,2246 +0,0 @@
-/*
- * Copyright (c) 1997, 1998, 1999, 2000
- * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * SysKonnect SK-NET gigabit ethernet driver for FreeBSD. Supports
- * the SK-984x series adapters, both single port and dual port.
- * References:
- * The XaQti XMAC II datasheet,
- * http://www.freebsd.org/~wpaul/SysKonnect/xmacii_datasheet_rev_c_9-29.pdf
- * The SysKonnect GEnesis manual, http://www.syskonnect.com
- *
- * Note: XaQti has been aquired by Vitesse, and Vitesse does not have the
- * XMAC II datasheet online. I have put my copy at people.freebsd.org as a
- * convenience to others until Vitesse corrects this problem:
- *
- * http://people.freebsd.org/~wpaul/SysKonnect/xmacii_datasheet_rev_c_9-29.pdf
- *
- * Written by Bill Paul <wpaul@ee.columbia.edu>
- * Department of Electrical Engineering
- * Columbia University, New York City
- */
-
-/*
- * The SysKonnect gigabit ethernet adapters consist of two main
- * components: the SysKonnect GEnesis controller chip and the XaQti Corp.
- * XMAC II gigabit ethernet MAC. The XMAC provides all of the MAC
- * components and a PHY while the GEnesis controller provides a PCI
- * interface with DMA support. Each card may have between 512K and
- * 2MB of SRAM on board depending on the configuration.
- *
- * The SysKonnect GEnesis controller can have either one or two XMAC
- * chips connected to it, allowing single or dual port NIC configurations.
- * SysKonnect has the distinction of being the only vendor on the market
- * with a dual port gigabit ethernet NIC. The GEnesis provides dual FIFOs,
- * dual DMA queues, packet/MAC/transmit arbiters and direct access to the
- * XMAC registers. This driver takes advantage of these features to allow
- * both XMACs to operate as independent interfaces.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/sockio.h>
-#include <sys/mbuf.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/socket.h>
-#include <sys/queue.h>
-
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/ethernet.h>
-#include <net/if_dl.h>
-#include <net/if_media.h>
-
-#include <net/bpf.h>
-
-#include <vm/vm.h> /* for vtophys */
-#include <vm/pmap.h> /* for vtophys */
-#include <machine/bus_pio.h>
-#include <machine/bus_memio.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/bus.h>
-#include <sys/rman.h>
-
-#include <dev/mii/mii.h>
-#include <dev/mii/miivar.h>
-#include <dev/mii/brgphyreg.h>
-
-#include <pci/pcireg.h>
-#include <pci/pcivar.h>
-
-#define SK_USEIOSPACE
-
-#include <pci/if_skreg.h>
-#include <pci/xmaciireg.h>
-
-MODULE_DEPEND(sk, pci, 1, 1, 1);
-MODULE_DEPEND(sk, ether, 1, 1, 1);
-MODULE_DEPEND(sk, miibus, 1, 1, 1);
-
-/* "controller miibus0" required. See GENERIC if you get errors here. */
-#include "miibus_if.h"
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif
-
-static struct sk_type sk_devs[] = {
- { SK_VENDORID, SK_DEVICEID_GE, "SysKonnect Gigabit Ethernet" },
- { 0, 0, NULL }
-};
-
-static int sk_probe (device_t);
-static int sk_attach (device_t);
-static int sk_detach (device_t);
-static int sk_detach_xmac (device_t);
-static int sk_probe_xmac (device_t);
-static int sk_attach_xmac (device_t);
-static void sk_tick (void *);
-static void sk_intr (void *);
-static void sk_intr_xmac (struct sk_if_softc *);
-static void sk_intr_bcom (struct sk_if_softc *);
-static void sk_rxeof (struct sk_if_softc *);
-static void sk_txeof (struct sk_if_softc *);
-static int sk_encap (struct sk_if_softc *, struct mbuf *,
- u_int32_t *);
-static void sk_start (struct ifnet *);
-static int sk_ioctl (struct ifnet *, u_long, caddr_t);
-static void sk_init (void *);
-static void sk_init_xmac (struct sk_if_softc *);
-static void sk_stop (struct sk_if_softc *);
-static void sk_watchdog (struct ifnet *);
-static void sk_shutdown (device_t);
-static int sk_ifmedia_upd (struct ifnet *);
-static void sk_ifmedia_sts (struct ifnet *, struct ifmediareq *);
-static void sk_reset (struct sk_softc *);
-static int sk_newbuf (struct sk_if_softc *,
- struct sk_chain *, struct mbuf *);
-static int sk_alloc_jumbo_mem (struct sk_if_softc *);
-static void *sk_jalloc (struct sk_if_softc *);
-static void sk_jfree (void *, void *);
-static int sk_init_rx_ring (struct sk_if_softc *);
-static void sk_init_tx_ring (struct sk_if_softc *);
-static u_int32_t sk_win_read_4 (struct sk_softc *, int);
-static u_int16_t sk_win_read_2 (struct sk_softc *, int);
-static u_int8_t sk_win_read_1 (struct sk_softc *, int);
-static void sk_win_write_4 (struct sk_softc *, int, u_int32_t);
-static void sk_win_write_2 (struct sk_softc *, int, u_int32_t);
-static void sk_win_write_1 (struct sk_softc *, int, u_int32_t);
-static u_int8_t sk_vpd_readbyte (struct sk_softc *, int);
-static void sk_vpd_read_res (struct sk_softc *, struct vpd_res *, int);
-static void sk_vpd_read (struct sk_softc *);
-
-static int sk_miibus_readreg (device_t, int, int);
-static int sk_miibus_writereg (device_t, int, int, int);
-static void sk_miibus_statchg (device_t);
-
-static u_int32_t sk_calchash (caddr_t);
-static void sk_setfilt (struct sk_if_softc *, caddr_t, int);
-static void sk_setmulti (struct sk_if_softc *);
-
-#ifdef SK_USEIOSPACE
-#define SK_RES SYS_RES_IOPORT
-#define SK_RID SK_PCI_LOIO
-#else
-#define SK_RES SYS_RES_MEMORY
-#define SK_RID SK_PCI_LOMEM
-#endif
-
-/*
- * Note that we have newbus methods for both the GEnesis controller
- * itself and the XMAC(s). The XMACs are children of the GEnesis, and
- * the miibus code is a child of the XMACs. We need to do it this way
- * so that the miibus drivers can access the PHY registers on the
- * right PHY. It's not quite what I had in mind, but it's the only
- * design that achieves the desired effect.
- */
-static device_method_t skc_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, sk_probe),
- DEVMETHOD(device_attach, sk_attach),
- DEVMETHOD(device_detach, sk_detach),
- DEVMETHOD(device_shutdown, sk_shutdown),
-
- /* bus interface */
- DEVMETHOD(bus_print_child, bus_generic_print_child),
- DEVMETHOD(bus_driver_added, bus_generic_driver_added),
-
- { 0, 0 }
-};
-
-static driver_t skc_driver = {
- "skc",
- skc_methods,
- sizeof(struct sk_softc)
-};
-
-static devclass_t skc_devclass;
-
-static device_method_t sk_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, sk_probe_xmac),
- DEVMETHOD(device_attach, sk_attach_xmac),
- DEVMETHOD(device_detach, sk_detach_xmac),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
-
- /* bus interface */
- DEVMETHOD(bus_print_child, bus_generic_print_child),
- DEVMETHOD(bus_driver_added, bus_generic_driver_added),
-
- /* MII interface */
- DEVMETHOD(miibus_readreg, sk_miibus_readreg),
- DEVMETHOD(miibus_writereg, sk_miibus_writereg),
- DEVMETHOD(miibus_statchg, sk_miibus_statchg),
-
- { 0, 0 }
-};
-
-static driver_t sk_driver = {
- "sk",
- sk_methods,
- sizeof(struct sk_if_softc)
-};
-
-static devclass_t sk_devclass;
-
-DRIVER_MODULE(sk, pci, skc_driver, skc_devclass, 0, 0);
-DRIVER_MODULE(sk, skc, sk_driver, sk_devclass, 0, 0);
-DRIVER_MODULE(miibus, sk, miibus_driver, miibus_devclass, 0, 0);
-
-#define SK_SETBIT(sc, reg, x) \
- CSR_WRITE_4(sc, reg, CSR_READ_4(sc, reg) | x)
-
-#define SK_CLRBIT(sc, reg, x) \
- CSR_WRITE_4(sc, reg, CSR_READ_4(sc, reg) & ~x)
-
-#define SK_WIN_SETBIT_4(sc, reg, x) \
- sk_win_write_4(sc, reg, sk_win_read_4(sc, reg) | x)
-
-#define SK_WIN_CLRBIT_4(sc, reg, x) \
- sk_win_write_4(sc, reg, sk_win_read_4(sc, reg) & ~x)
-
-#define SK_WIN_SETBIT_2(sc, reg, x) \
- sk_win_write_2(sc, reg, sk_win_read_2(sc, reg) | x)
-
-#define SK_WIN_CLRBIT_2(sc, reg, x) \
- sk_win_write_2(sc, reg, sk_win_read_2(sc, reg) & ~x)
-
-static u_int32_t
-sk_win_read_4(sc, reg)
- struct sk_softc *sc;
- int reg;
-{
- CSR_WRITE_4(sc, SK_RAP, SK_WIN(reg));
- return(CSR_READ_4(sc, SK_WIN_BASE + SK_REG(reg)));
-}
-
-static u_int16_t
-sk_win_read_2(sc, reg)
- struct sk_softc *sc;
- int reg;
-{
- CSR_WRITE_4(sc, SK_RAP, SK_WIN(reg));
- return(CSR_READ_2(sc, SK_WIN_BASE + SK_REG(reg)));
-}
-
-static u_int8_t
-sk_win_read_1(sc, reg)
- struct sk_softc *sc;
- int reg;
-{
- CSR_WRITE_4(sc, SK_RAP, SK_WIN(reg));
- return(CSR_READ_1(sc, SK_WIN_BASE + SK_REG(reg)));
-}
-
-static void
-sk_win_write_4(sc, reg, val)
- struct sk_softc *sc;
- int reg;
- u_int32_t val;
-{
- CSR_WRITE_4(sc, SK_RAP, SK_WIN(reg));
- CSR_WRITE_4(sc, SK_WIN_BASE + SK_REG(reg), val);
- return;
-}
-
-static void
-sk_win_write_2(sc, reg, val)
- struct sk_softc *sc;
- int reg;
- u_int32_t val;
-{
- CSR_WRITE_4(sc, SK_RAP, SK_WIN(reg));
- CSR_WRITE_2(sc, SK_WIN_BASE + SK_REG(reg), (u_int32_t)val);
- return;
-}
-
-static void
-sk_win_write_1(sc, reg, val)
- struct sk_softc *sc;
- int reg;
- u_int32_t val;
-{
- CSR_WRITE_4(sc, SK_RAP, SK_WIN(reg));
- CSR_WRITE_1(sc, SK_WIN_BASE + SK_REG(reg), val);
- return;
-}
-
-/*
- * The VPD EEPROM contains Vital Product Data, as suggested in
- * the PCI 2.1 specification. The VPD data is separared into areas
- * denoted by resource IDs. The SysKonnect VPD contains an ID string
- * resource (the name of the adapter), a read-only area resource
- * containing various key/data fields and a read/write area which
- * can be used to store asset management information or log messages.
- * We read the ID string and read-only into buffers attached to
- * the controller softc structure for later use. At the moment,
- * we only use the ID string during sk_attach().
- */
-static u_int8_t
-sk_vpd_readbyte(sc, addr)
- struct sk_softc *sc;
- int addr;
-{
- int i;
-
- sk_win_write_2(sc, SK_PCI_REG(SK_PCI_VPD_ADDR), addr);
- for (i = 0; i < SK_TIMEOUT; i++) {
- DELAY(1);
- if (sk_win_read_2(sc,
- SK_PCI_REG(SK_PCI_VPD_ADDR)) & SK_VPD_FLAG)
- break;
- }
-
- if (i == SK_TIMEOUT)
- return(0);
-
- return(sk_win_read_1(sc, SK_PCI_REG(SK_PCI_VPD_DATA)));
-}
-
-static void
-sk_vpd_read_res(sc, res, addr)
- struct sk_softc *sc;
- struct vpd_res *res;
- int addr;
-{
- int i;
- u_int8_t *ptr;
-
- ptr = (u_int8_t *)res;
- for (i = 0; i < sizeof(struct vpd_res); i++)
- ptr[i] = sk_vpd_readbyte(sc, i + addr);
-
- return;
-}
-
-static void
-sk_vpd_read(sc)
- struct sk_softc *sc;
-{
- int pos = 0, i;
- struct vpd_res res;
-
- if (sc->sk_vpd_prodname != NULL)
- free(sc->sk_vpd_prodname, M_DEVBUF);
- if (sc->sk_vpd_readonly != NULL)
- free(sc->sk_vpd_readonly, M_DEVBUF);
- sc->sk_vpd_prodname = NULL;
- sc->sk_vpd_readonly = NULL;
-
- sk_vpd_read_res(sc, &res, pos);
-
- if (res.vr_id != VPD_RES_ID) {
- printf("skc%d: bad VPD resource id: expected %x got %x\n",
- sc->sk_unit, VPD_RES_ID, res.vr_id);
- return;
- }
-
- pos += sizeof(res);
- sc->sk_vpd_prodname = malloc(res.vr_len + 1, M_DEVBUF, M_NOWAIT);
- for (i = 0; i < res.vr_len; i++)
- sc->sk_vpd_prodname[i] = sk_vpd_readbyte(sc, i + pos);
- sc->sk_vpd_prodname[i] = '\0';
- pos += i;
-
- sk_vpd_read_res(sc, &res, pos);
-
- if (res.vr_id != VPD_RES_READ) {
- printf("skc%d: bad VPD resource id: expected %x got %x\n",
- sc->sk_unit, VPD_RES_READ, res.vr_id);
- return;
- }
-
- pos += sizeof(res);
- sc->sk_vpd_readonly = malloc(res.vr_len, M_DEVBUF, M_NOWAIT);
- for (i = 0; i < res.vr_len + 1; i++)
- sc->sk_vpd_readonly[i] = sk_vpd_readbyte(sc, i + pos);
-
- return;
-}
-
-static int
-sk_miibus_readreg(dev, phy, reg)
- device_t dev;
- int phy, reg;
-{
- struct sk_if_softc *sc_if;
- int i;
-
- sc_if = device_get_softc(dev);
-
- if (sc_if->sk_phytype == SK_PHYTYPE_XMAC && phy != 0)
- return(0);
-
- SK_IF_LOCK(sc_if);
-
- SK_XM_WRITE_2(sc_if, XM_PHY_ADDR, reg|(phy << 8));
- SK_XM_READ_2(sc_if, XM_PHY_DATA);
- if (sc_if->sk_phytype != SK_PHYTYPE_XMAC) {
- for (i = 0; i < SK_TIMEOUT; i++) {
- DELAY(1);
- if (SK_XM_READ_2(sc_if, XM_MMUCMD) &
- XM_MMUCMD_PHYDATARDY)
- break;
- }
-
- if (i == SK_TIMEOUT) {
- printf("sk%d: phy failed to come ready\n",
- sc_if->sk_unit);
- return(0);
- }
- }
- DELAY(1);
- i = SK_XM_READ_2(sc_if, XM_PHY_DATA);
- SK_IF_UNLOCK(sc_if);
- return(i);
-}
-
-static int
-sk_miibus_writereg(dev, phy, reg, val)
- device_t dev;
- int phy, reg, val;
-{
- struct sk_if_softc *sc_if;
- int i;
-
- sc_if = device_get_softc(dev);
- SK_IF_LOCK(sc_if);
-
- SK_XM_WRITE_2(sc_if, XM_PHY_ADDR, reg|(phy << 8));
- for (i = 0; i < SK_TIMEOUT; i++) {
- if (!(SK_XM_READ_2(sc_if, XM_MMUCMD) & XM_MMUCMD_PHYBUSY))
- break;
- }
-
- if (i == SK_TIMEOUT) {
- printf("sk%d: phy failed to come ready\n", sc_if->sk_unit);
- return(ETIMEDOUT);
- }
-
- SK_XM_WRITE_2(sc_if, XM_PHY_DATA, val);
- for (i = 0; i < SK_TIMEOUT; i++) {
- DELAY(1);
- if (!(SK_XM_READ_2(sc_if, XM_MMUCMD) & XM_MMUCMD_PHYBUSY))
- break;
- }
-
- SK_IF_UNLOCK(sc_if);
-
- if (i == SK_TIMEOUT)
- printf("sk%d: phy write timed out\n", sc_if->sk_unit);
-
- return(0);
-}
-
-static void
-sk_miibus_statchg(dev)
- device_t dev;
-{
- struct sk_if_softc *sc_if;
- struct mii_data *mii;
-
- sc_if = device_get_softc(dev);
- mii = device_get_softc(sc_if->sk_miibus);
- SK_IF_LOCK(sc_if);
- /*
- * If this is a GMII PHY, manually set the XMAC's
- * duplex mode accordingly.
- */
- if (sc_if->sk_phytype != SK_PHYTYPE_XMAC) {
- if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
- SK_XM_SETBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_GMIIFDX);
- } else {
- SK_XM_CLRBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_GMIIFDX);
- }
- }
- SK_IF_UNLOCK(sc_if);
-
- return;
-}
-
-#define SK_POLY 0xEDB88320
-#define SK_BITS 6
-
-static u_int32_t
-sk_calchash(addr)
- caddr_t addr;
-{
- u_int32_t idx, bit, data, crc;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (idx = 0; idx < 6; idx++) {
- for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
- crc = (crc >> 1) ^ (((crc ^ data) & 1) ? SK_POLY : 0);
- }
-
- return (~crc & ((1 << SK_BITS) - 1));
-}
-
-static void
-sk_setfilt(sc_if, addr, slot)
- struct sk_if_softc *sc_if;
- caddr_t addr;
- int slot;
-{
- int base;
-
- base = XM_RXFILT_ENTRY(slot);
-
- SK_XM_WRITE_2(sc_if, base, *(u_int16_t *)(&addr[0]));
- SK_XM_WRITE_2(sc_if, base + 2, *(u_int16_t *)(&addr[2]));
- SK_XM_WRITE_2(sc_if, base + 4, *(u_int16_t *)(&addr[4]));
-
- return;
-}
-
-static void
-sk_setmulti(sc_if)
- struct sk_if_softc *sc_if;
-{
- struct ifnet *ifp;
- u_int32_t hashes[2] = { 0, 0 };
- int h, i;
- struct ifmultiaddr *ifma;
- u_int8_t dummy[] = { 0, 0, 0, 0, 0 ,0 };
-
- ifp = &sc_if->arpcom.ac_if;
-
- /* First, zot all the existing filters. */
- for (i = 1; i < XM_RXFILT_MAX; i++)
- sk_setfilt(sc_if, (caddr_t)&dummy, i);
- SK_XM_WRITE_4(sc_if, XM_MAR0, 0);
- SK_XM_WRITE_4(sc_if, XM_MAR2, 0);
-
- /* Now program new ones. */
- if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
- hashes[0] = 0xFFFFFFFF;
- hashes[1] = 0xFFFFFFFF;
- } else {
- i = 1;
- TAILQ_FOREACH_REVERSE(ifma, &ifp->if_multiaddrs, ifmultihead, ifma_link) {
- if (ifma->ifma_addr->sa_family != AF_LINK)
- continue;
- /*
- * Program the first XM_RXFILT_MAX multicast groups
- * into the perfect filter. For all others,
- * use the hash table.
- */
- if (i < XM_RXFILT_MAX) {
- sk_setfilt(sc_if,
- LLADDR((struct sockaddr_dl *)ifma->ifma_addr), i);
- i++;
- continue;
- }
-
- h = sk_calchash(
- LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
- if (h < 32)
- hashes[0] |= (1 << h);
- else
- hashes[1] |= (1 << (h - 32));
- }
- }
-
- SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_RX_USE_HASH|
- XM_MODE_RX_USE_PERFECT);
- SK_XM_WRITE_4(sc_if, XM_MAR0, hashes[0]);
- SK_XM_WRITE_4(sc_if, XM_MAR2, hashes[1]);
-
- return;
-}
-
-static int
-sk_init_rx_ring(sc_if)
- struct sk_if_softc *sc_if;
-{
- struct sk_chain_data *cd;
- struct sk_ring_data *rd;
- int i;
-
- cd = &sc_if->sk_cdata;
- rd = sc_if->sk_rdata;
-
- bzero((char *)rd->sk_rx_ring,
- sizeof(struct sk_rx_desc) * SK_RX_RING_CNT);
-
- for (i = 0; i < SK_RX_RING_CNT; i++) {
- cd->sk_rx_chain[i].sk_desc = &rd->sk_rx_ring[i];
- if (sk_newbuf(sc_if, &cd->sk_rx_chain[i], NULL) == ENOBUFS)
- return(ENOBUFS);
- if (i == (SK_RX_RING_CNT - 1)) {
- cd->sk_rx_chain[i].sk_next =
- &cd->sk_rx_chain[0];
- rd->sk_rx_ring[i].sk_next =
- vtophys(&rd->sk_rx_ring[0]);
- } else {
- cd->sk_rx_chain[i].sk_next =
- &cd->sk_rx_chain[i + 1];
- rd->sk_rx_ring[i].sk_next =
- vtophys(&rd->sk_rx_ring[i + 1]);
- }
- }
-
- sc_if->sk_cdata.sk_rx_prod = 0;
- sc_if->sk_cdata.sk_rx_cons = 0;
-
- return(0);
-}
-
-static void
-sk_init_tx_ring(sc_if)
- struct sk_if_softc *sc_if;
-{
- struct sk_chain_data *cd;
- struct sk_ring_data *rd;
- int i;
-
- cd = &sc_if->sk_cdata;
- rd = sc_if->sk_rdata;
-
- bzero((char *)sc_if->sk_rdata->sk_tx_ring,
- sizeof(struct sk_tx_desc) * SK_TX_RING_CNT);
-
- for (i = 0; i < SK_TX_RING_CNT; i++) {
- cd->sk_tx_chain[i].sk_desc = &rd->sk_tx_ring[i];
- if (i == (SK_TX_RING_CNT - 1)) {
- cd->sk_tx_chain[i].sk_next =
- &cd->sk_tx_chain[0];
- rd->sk_tx_ring[i].sk_next =
- vtophys(&rd->sk_tx_ring[0]);
- } else {
- cd->sk_tx_chain[i].sk_next =
- &cd->sk_tx_chain[i + 1];
- rd->sk_tx_ring[i].sk_next =
- vtophys(&rd->sk_tx_ring[i + 1]);
- }
- }
-
- sc_if->sk_cdata.sk_tx_prod = 0;
- sc_if->sk_cdata.sk_tx_cons = 0;
- sc_if->sk_cdata.sk_tx_cnt = 0;
-
- return;
-}
-
-static int
-sk_newbuf(sc_if, c, m)
- struct sk_if_softc *sc_if;
- struct sk_chain *c;
- struct mbuf *m;
-{
- struct mbuf *m_new = NULL;
- struct sk_rx_desc *r;
-
- if (m == NULL) {
- caddr_t *buf = NULL;
-
- MGETHDR(m_new, M_DONTWAIT, MT_DATA);
- if (m_new == NULL)
- return(ENOBUFS);
-
- /* Allocate the jumbo buffer */
- buf = sk_jalloc(sc_if);
- if (buf == NULL) {
- m_freem(m_new);
-#ifdef SK_VERBOSE
- printf("sk%d: jumbo allocation failed "
- "-- packet dropped!\n", sc_if->sk_unit);
-#endif
- return(ENOBUFS);
- }
-
- /* Attach the buffer to the mbuf */
- MEXTADD(m_new, buf, SK_JLEN, sk_jfree,
- (struct sk_if_softc *)sc_if, 0, EXT_NET_DRV);
- m_new->m_data = (void *)buf;
- m_new->m_pkthdr.len = m_new->m_len = SK_JLEN;
- } else {
- /*
- * We're re-using a previously allocated mbuf;
- * be sure to re-init pointers and lengths to
- * default values.
- */
- m_new = m;
- m_new->m_len = m_new->m_pkthdr.len = SK_JLEN;
- m_new->m_data = m_new->m_ext.ext_buf;
- }
-
- /*
- * Adjust alignment so packet payload begins on a
- * longword boundary. Mandatory for Alpha, useful on
- * x86 too.
- */
- m_adj(m_new, ETHER_ALIGN);
-
- r = c->sk_desc;
- c->sk_mbuf = m_new;
- r->sk_data_lo = vtophys(mtod(m_new, caddr_t));
- r->sk_ctl = m_new->m_len | SK_RXSTAT;
-
- return(0);
-}
-
-/*
- * Allocate jumbo buffer storage. The SysKonnect adapters support
- * "jumbograms" (9K frames), although SysKonnect doesn't currently
- * use them in their drivers. In order for us to use them, we need
- * large 9K receive buffers, however standard mbuf clusters are only
- * 2048 bytes in size. Consequently, we need to allocate and manage
- * our own jumbo buffer pool. Fortunately, this does not require an
- * excessive amount of additional code.
- */
-static int
-sk_alloc_jumbo_mem(sc_if)
- struct sk_if_softc *sc_if;
-{
- caddr_t ptr;
- register int i;
- struct sk_jpool_entry *entry;
-
- /* Grab a big chunk o' storage. */
- sc_if->sk_cdata.sk_jumbo_buf = contigmalloc(SK_JMEM, M_DEVBUF,
- M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
-
- if (sc_if->sk_cdata.sk_jumbo_buf == NULL) {
- printf("sk%d: no memory for jumbo buffers!\n", sc_if->sk_unit);
- return(ENOBUFS);
- }
-
- SLIST_INIT(&sc_if->sk_jfree_listhead);
- SLIST_INIT(&sc_if->sk_jinuse_listhead);
-
- /*
- * Now divide it up into 9K pieces and save the addresses
- * in an array.
- */
- ptr = sc_if->sk_cdata.sk_jumbo_buf;
- for (i = 0; i < SK_JSLOTS; i++) {
- sc_if->sk_cdata.sk_jslots[i] = ptr;
- ptr += SK_JLEN;
- entry = malloc(sizeof(struct sk_jpool_entry),
- M_DEVBUF, M_NOWAIT);
- if (entry == NULL) {
- free(sc_if->sk_cdata.sk_jumbo_buf, M_DEVBUF);
- sc_if->sk_cdata.sk_jumbo_buf = NULL;
- printf("sk%d: no memory for jumbo "
- "buffer queue!\n", sc_if->sk_unit);
- return(ENOBUFS);
- }
- entry->slot = i;
- SLIST_INSERT_HEAD(&sc_if->sk_jfree_listhead,
- entry, jpool_entries);
- }
-
- return(0);
-}
-
-/*
- * Allocate a jumbo buffer.
- */
-static void *
-sk_jalloc(sc_if)
- struct sk_if_softc *sc_if;
-{
- struct sk_jpool_entry *entry;
-
- entry = SLIST_FIRST(&sc_if->sk_jfree_listhead);
-
- if (entry == NULL) {
-#ifdef SK_VERBOSE
- printf("sk%d: no free jumbo buffers\n", sc_if->sk_unit);
-#endif
- return(NULL);
- }
-
- SLIST_REMOVE_HEAD(&sc_if->sk_jfree_listhead, jpool_entries);
- SLIST_INSERT_HEAD(&sc_if->sk_jinuse_listhead, entry, jpool_entries);
- return(sc_if->sk_cdata.sk_jslots[entry->slot]);
-}
-
-/*
- * Release a jumbo buffer.
- */
-static void
-sk_jfree(buf, args)
- void *buf;
- void *args;
-{
- struct sk_if_softc *sc_if;
- int i;
- struct sk_jpool_entry *entry;
-
- /* Extract the softc struct pointer. */
- sc_if = (struct sk_if_softc *)args;
-
- if (sc_if == NULL)
- panic("sk_jfree: didn't get softc pointer!");
-
- /* calculate the slot this buffer belongs to */
- i = ((vm_offset_t)buf
- - (vm_offset_t)sc_if->sk_cdata.sk_jumbo_buf) / SK_JLEN;
-
- if ((i < 0) || (i >= SK_JSLOTS))
- panic("sk_jfree: asked to free buffer that we don't manage!");
-
- entry = SLIST_FIRST(&sc_if->sk_jinuse_listhead);
- if (entry == NULL)
- panic("sk_jfree: buffer not in use!");
- entry->slot = i;
- SLIST_REMOVE_HEAD(&sc_if->sk_jinuse_listhead, jpool_entries);
- SLIST_INSERT_HEAD(&sc_if->sk_jfree_listhead, entry, jpool_entries);
-
- return;
-}
-
-/*
- * Set media options.
- */
-static int
-sk_ifmedia_upd(ifp)
- struct ifnet *ifp;
-{
- struct sk_if_softc *sc_if;
- struct mii_data *mii;
-
- sc_if = ifp->if_softc;
- mii = device_get_softc(sc_if->sk_miibus);
- sk_init(sc_if);
- mii_mediachg(mii);
-
- return(0);
-}
-
-/*
- * Report current media status.
- */
-static void
-sk_ifmedia_sts(ifp, ifmr)
- struct ifnet *ifp;
- struct ifmediareq *ifmr;
-{
- struct sk_if_softc *sc_if;
- struct mii_data *mii;
-
- sc_if = ifp->if_softc;
- mii = device_get_softc(sc_if->sk_miibus);
-
- mii_pollstat(mii);
- ifmr->ifm_active = mii->mii_media_active;
- ifmr->ifm_status = mii->mii_media_status;
-
- return;
-}
-
-static int
-sk_ioctl(ifp, command, data)
- struct ifnet *ifp;
- u_long command;
- caddr_t data;
-{
- struct sk_if_softc *sc_if = ifp->if_softc;
- struct ifreq *ifr = (struct ifreq *) data;
- int error = 0;
- struct mii_data *mii;
-
- SK_IF_LOCK(sc_if);
-
- switch(command) {
- case SIOCSIFMTU:
- if (ifr->ifr_mtu > SK_JUMBO_MTU)
- error = EINVAL;
- else {
- ifp->if_mtu = ifr->ifr_mtu;
- sk_init(sc_if);
- }
- break;
- case SIOCSIFFLAGS:
- if (ifp->if_flags & IFF_UP) {
- if (ifp->if_flags & IFF_RUNNING &&
- ifp->if_flags & IFF_PROMISC &&
- !(sc_if->sk_if_flags & IFF_PROMISC)) {
- SK_XM_SETBIT_4(sc_if, XM_MODE,
- XM_MODE_RX_PROMISC);
- sk_setmulti(sc_if);
- } else if (ifp->if_flags & IFF_RUNNING &&
- !(ifp->if_flags & IFF_PROMISC) &&
- sc_if->sk_if_flags & IFF_PROMISC) {
- SK_XM_CLRBIT_4(sc_if, XM_MODE,
- XM_MODE_RX_PROMISC);
- sk_setmulti(sc_if);
- } else
- sk_init(sc_if);
- } else {
- if (ifp->if_flags & IFF_RUNNING)
- sk_stop(sc_if);
- }
- sc_if->sk_if_flags = ifp->if_flags;
- error = 0;
- break;
- case SIOCADDMULTI:
- case SIOCDELMULTI:
- sk_setmulti(sc_if);
- error = 0;
- break;
- case SIOCGIFMEDIA:
- case SIOCSIFMEDIA:
- mii = device_get_softc(sc_if->sk_miibus);
- error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
- break;
- default:
- error = ether_ioctl(ifp, command, data);
- break;
- }
-
- SK_IF_UNLOCK(sc_if);
-
- return(error);
-}
-
-/*
- * Probe for a SysKonnect GEnesis chip. Check the PCI vendor and device
- * IDs against our list and return a device name if we find a match.
- */
-static int
-sk_probe(dev)
- device_t dev;
-{
- struct sk_type *t;
-
- t = sk_devs;
-
- while(t->sk_name != NULL) {
- if ((pci_get_vendor(dev) == t->sk_vid) &&
- (pci_get_device(dev) == t->sk_did)) {
- device_set_desc(dev, t->sk_name);
- return(0);
- }
- t++;
- }
-
- return(ENXIO);
-}
-
-/*
- * Force the GEnesis into reset, then bring it out of reset.
- */
-static void
-sk_reset(sc)
- struct sk_softc *sc;
-{
- CSR_WRITE_4(sc, SK_CSR, SK_CSR_SW_RESET);
- CSR_WRITE_4(sc, SK_CSR, SK_CSR_MASTER_RESET);
- DELAY(1000);
- CSR_WRITE_4(sc, SK_CSR, SK_CSR_SW_UNRESET);
- CSR_WRITE_4(sc, SK_CSR, SK_CSR_MASTER_UNRESET);
-
- /* Configure packet arbiter */
- sk_win_write_2(sc, SK_PKTARB_CTL, SK_PKTARBCTL_UNRESET);
- sk_win_write_2(sc, SK_RXPA1_TINIT, SK_PKTARB_TIMEOUT);
- sk_win_write_2(sc, SK_TXPA1_TINIT, SK_PKTARB_TIMEOUT);
- sk_win_write_2(sc, SK_RXPA2_TINIT, SK_PKTARB_TIMEOUT);
- sk_win_write_2(sc, SK_TXPA2_TINIT, SK_PKTARB_TIMEOUT);
-
- /* Enable RAM interface */
- sk_win_write_4(sc, SK_RAMCTL, SK_RAMCTL_UNRESET);
-
- /*
- * Configure interrupt moderation. The moderation timer
- * defers interrupts specified in the interrupt moderation
- * timer mask based on the timeout specified in the interrupt
- * moderation timer init register. Each bit in the timer
- * register represents 18.825ns, so to specify a timeout in
- * microseconds, we have to multiply by 54.
- */
- sk_win_write_4(sc, SK_IMTIMERINIT, SK_IM_USECS(200));
- sk_win_write_4(sc, SK_IMMR, SK_ISR_TX1_S_EOF|SK_ISR_TX2_S_EOF|
- SK_ISR_RX1_EOF|SK_ISR_RX2_EOF);
- sk_win_write_1(sc, SK_IMTIMERCTL, SK_IMCTL_START);
-
- return;
-}
-
-static int
-sk_probe_xmac(dev)
- device_t dev;
-{
- /*
- * Not much to do here. We always know there will be
- * at least one XMAC present, and if there are two,
- * sk_attach() will create a second device instance
- * for us.
- */
- device_set_desc(dev, "XaQti Corp. XMAC II");
-
- return(0);
-}
-
-/*
- * Each XMAC chip is attached as a separate logical IP interface.
- * Single port cards will have only one logical interface of course.
- */
-static int
-sk_attach_xmac(dev)
- device_t dev;
-{
- struct sk_softc *sc;
- struct sk_if_softc *sc_if;
- struct ifnet *ifp;
- int i, port, error;
-
- if (dev == NULL)
- return(EINVAL);
-
- error = 0;
- sc_if = device_get_softc(dev);
- sc = device_get_softc(device_get_parent(dev));
- SK_LOCK(sc);
- port = *(int *)device_get_ivars(dev);
- free(device_get_ivars(dev), M_DEVBUF);
- device_set_ivars(dev, NULL);
-
- sc_if->sk_dev = dev;
- sc_if->sk_unit = device_get_unit(dev);
- sc_if->sk_port = port;
- sc_if->sk_softc = sc;
- sc->sk_if[port] = sc_if;
- if (port == SK_PORT_A)
- sc_if->sk_tx_bmu = SK_BMU_TXS_CSR0;
- if (port == SK_PORT_B)
- sc_if->sk_tx_bmu = SK_BMU_TXS_CSR1;
-
- /*
- * Get station address for this interface. Note that
- * dual port cards actually come with three station
- * addresses: one for each port, plus an extra. The
- * extra one is used by the SysKonnect driver software
- * as a 'virtual' station address for when both ports
- * are operating in failover mode. Currently we don't
- * use this extra address.
- */
- for (i = 0; i < ETHER_ADDR_LEN; i++)
- sc_if->arpcom.ac_enaddr[i] =
- sk_win_read_1(sc, SK_MAC0_0 + (port * 8) + i);
-
- printf("sk%d: Ethernet address: %6D\n",
- sc_if->sk_unit, sc_if->arpcom.ac_enaddr, ":");
-
- /*
- * Set up RAM buffer addresses. The NIC will have a certain
- * amount of SRAM on it, somewhere between 512K and 2MB. We
- * need to divide this up a) between the transmitter and
- * receiver and b) between the two XMACs, if this is a
- * dual port NIC. Our algotithm is to divide up the memory
- * evenly so that everyone gets a fair share.
- */
- if (sk_win_read_1(sc, SK_CONFIG) & SK_CONFIG_SINGLEMAC) {
- u_int32_t chunk, val;
-
- chunk = sc->sk_ramsize / 2;
- val = sc->sk_rboff / sizeof(u_int64_t);
- sc_if->sk_rx_ramstart = val;
- val += (chunk / sizeof(u_int64_t));
- sc_if->sk_rx_ramend = val - 1;
- sc_if->sk_tx_ramstart = val;
- val += (chunk / sizeof(u_int64_t));
- sc_if->sk_tx_ramend = val - 1;
- } else {
- u_int32_t chunk, val;
-
- chunk = sc->sk_ramsize / 4;
- val = (sc->sk_rboff + (chunk * 2 * sc_if->sk_port)) /
- sizeof(u_int64_t);
- sc_if->sk_rx_ramstart = val;
- val += (chunk / sizeof(u_int64_t));
- sc_if->sk_rx_ramend = val - 1;
- sc_if->sk_tx_ramstart = val;
- val += (chunk / sizeof(u_int64_t));
- sc_if->sk_tx_ramend = val - 1;
- }
-
- /* Read and save PHY type and set PHY address */
- sc_if->sk_phytype = sk_win_read_1(sc, SK_EPROM1) & 0xF;
- switch(sc_if->sk_phytype) {
- case SK_PHYTYPE_XMAC:
- sc_if->sk_phyaddr = SK_PHYADDR_XMAC;
- break;
- case SK_PHYTYPE_BCOM:
- sc_if->sk_phyaddr = SK_PHYADDR_BCOM;
- break;
- default:
- printf("skc%d: unsupported PHY type: %d\n",
- sc->sk_unit, sc_if->sk_phytype);
- error = ENODEV;
- goto fail_xmac;
- }
-
- /* Allocate the descriptor queues. */
- sc_if->sk_rdata = contigmalloc(sizeof(struct sk_ring_data), M_DEVBUF,
- M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
-
- if (sc_if->sk_rdata == NULL) {
- printf("sk%d: no memory for list buffers!\n", sc_if->sk_unit);
- error = ENOMEM;
- goto fail_xmac;
- }
-
- bzero(sc_if->sk_rdata, sizeof(struct sk_ring_data));
-
- /* Try to allocate memory for jumbo buffers. */
- if (sk_alloc_jumbo_mem(sc_if)) {
- printf("sk%d: jumbo buffer allocation failed\n",
- sc_if->sk_unit);
- error = ENOMEM;
- goto fail_xmac;
- }
-
- ifp = &sc_if->arpcom.ac_if;
- ifp->if_softc = sc_if;
- ifp->if_unit = sc_if->sk_unit;
- ifp->if_name = "sk";
- ifp->if_mtu = ETHERMTU;
- ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
- ifp->if_ioctl = sk_ioctl;
- ifp->if_output = ether_output;
- ifp->if_start = sk_start;
- ifp->if_watchdog = sk_watchdog;
- ifp->if_init = sk_init;
- ifp->if_baudrate = 1000000000;
- ifp->if_snd.ifq_maxlen = SK_TX_RING_CNT - 1;
-
- callout_handle_init(&sc_if->sk_tick_ch);
-
- /*
- * Call MI attach routine.
- */
- ether_ifattach(ifp, sc_if->arpcom.ac_enaddr);
-
- /*
- * Do miibus setup.
- */
- sk_init_xmac(sc_if);
- if (mii_phy_probe(dev, &sc_if->sk_miibus,
- sk_ifmedia_upd, sk_ifmedia_sts)) {
- printf("skc%d: no PHY found!\n", sc_if->sk_unit);
- ether_ifdetach(ifp);
- error = ENXIO;
- goto fail_xmac;
- }
-
-fail_xmac:
- SK_UNLOCK(sc);
- if (error) {
- /* Access should be ok even though lock has been dropped */
- sc->sk_if[port] = NULL;
- sk_detach_xmac(dev);
- }
-
- return(error);
-}
-
-/*
- * Attach the interface. Allocate softc structures, do ifmedia
- * setup and ethernet/BPF attach.
- */
-static int
-sk_attach(dev)
- device_t dev;
-{
- struct sk_softc *sc;
- int unit, error = 0, rid, *port;
-
- sc = device_get_softc(dev);
- unit = device_get_unit(dev);
-
- mtx_init(&sc->sk_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
- MTX_DEF | MTX_RECURSE);
-
- /*
- * Handle power management nonsense.
- */
- if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
- u_int32_t iobase, membase, irq;
-
- /* Save important PCI config data. */
- iobase = pci_read_config(dev, SK_PCI_LOIO, 4);
- membase = pci_read_config(dev, SK_PCI_LOMEM, 4);
- irq = pci_read_config(dev, SK_PCI_INTLINE, 4);
-
- /* Reset the power state. */
- printf("skc%d: chip is in D%d power mode "
- "-- setting to D0\n", unit,
- pci_get_powerstate(dev));
- pci_set_powerstate(dev, PCI_POWERSTATE_D0);
-
- /* Restore PCI config data. */
- pci_write_config(dev, SK_PCI_LOIO, iobase, 4);
- pci_write_config(dev, SK_PCI_LOMEM, membase, 4);
- pci_write_config(dev, SK_PCI_INTLINE, irq, 4);
- }
-
- /*
- * Map control/status registers.
- */
- pci_enable_busmaster(dev);
-
- rid = SK_RID;
- sc->sk_res = bus_alloc_resource(dev, SK_RES, &rid,
- 0, ~0, 1, RF_ACTIVE);
-
- if (sc->sk_res == NULL) {
- printf("sk%d: couldn't map ports/memory\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- sc->sk_btag = rman_get_bustag(sc->sk_res);
- sc->sk_bhandle = rman_get_bushandle(sc->sk_res);
-
- /* Allocate interrupt */
- rid = 0;
- sc->sk_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE | RF_ACTIVE);
-
- if (sc->sk_irq == NULL) {
- printf("skc%d: couldn't map interrupt\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- /* Reset the adapter. */
- sk_reset(sc);
-
- sc->sk_unit = unit;
-
- /* Read and save vital product data from EEPROM. */
- sk_vpd_read(sc);
-
- /* Read and save RAM size and RAMbuffer offset */
- switch(sk_win_read_1(sc, SK_EPROM0)) {
- case SK_RAMSIZE_512K_64:
- sc->sk_ramsize = 0x80000;
- sc->sk_rboff = SK_RBOFF_0;
- break;
- case SK_RAMSIZE_1024K_64:
- sc->sk_ramsize = 0x100000;
- sc->sk_rboff = SK_RBOFF_80000;
- break;
- case SK_RAMSIZE_1024K_128:
- sc->sk_ramsize = 0x100000;
- sc->sk_rboff = SK_RBOFF_0;
- break;
- case SK_RAMSIZE_2048K_128:
- sc->sk_ramsize = 0x200000;
- sc->sk_rboff = SK_RBOFF_0;
- break;
- default:
- printf("skc%d: unknown ram size: %d\n",
- sc->sk_unit, sk_win_read_1(sc, SK_EPROM0));
- error = ENXIO;
- goto fail;
- }
-
- /* Read and save physical media type */
- switch(sk_win_read_1(sc, SK_PMDTYPE)) {
- case SK_PMD_1000BASESX:
- sc->sk_pmd = IFM_1000_SX;
- break;
- case SK_PMD_1000BASELX:
- sc->sk_pmd = IFM_1000_LX;
- break;
- case SK_PMD_1000BASECX:
- sc->sk_pmd = IFM_1000_CX;
- break;
- case SK_PMD_1000BASETX:
- sc->sk_pmd = IFM_1000_T;
- break;
- default:
- printf("skc%d: unknown media type: 0x%x\n",
- sc->sk_unit, sk_win_read_1(sc, SK_PMDTYPE));
- error = ENXIO;
- goto fail;
- }
-
- /* Announce the product name. */
- printf("skc%d: %s\n", sc->sk_unit, sc->sk_vpd_prodname);
- sc->sk_devs[SK_PORT_A] = device_add_child(dev, "sk", -1);
- port = malloc(sizeof(int), M_DEVBUF, M_NOWAIT);
- *port = SK_PORT_A;
- device_set_ivars(sc->sk_devs[SK_PORT_A], port);
-
- if (!(sk_win_read_1(sc, SK_CONFIG) & SK_CONFIG_SINGLEMAC)) {
- sc->sk_devs[SK_PORT_B] = device_add_child(dev, "sk", -1);
- port = malloc(sizeof(int), M_DEVBUF, M_NOWAIT);
- *port = SK_PORT_B;
- device_set_ivars(sc->sk_devs[SK_PORT_B], port);
- }
-
- /* Turn on the 'driver is loaded' LED. */
- CSR_WRITE_2(sc, SK_LED, SK_LED_GREEN_ON);
-
- bus_generic_attach(dev);
-
- /* Hook interrupt last to avoid having to lock softc */
- error = bus_setup_intr(dev, sc->sk_irq, INTR_TYPE_NET,
- sk_intr, sc, &sc->sk_intrhand);
-
- if (error) {
- printf("skc%d: couldn't set up irq\n", unit);
- goto fail;
- }
-
-fail:
- if (error)
- sk_detach(dev);
-
- return(error);
-}
-
-/*
- * Shutdown hardware and free up resources. This can be called any
- * time after the mutex has been initialized. It is called in both
- * the error case in attach and the normal detach case so it needs
- * to be careful about only freeing resources that have actually been
- * allocated.
- */
-static int
-sk_detach_xmac(dev)
- device_t dev;
-{
- struct sk_softc *sc;
- struct sk_if_softc *sc_if;
- struct ifnet *ifp;
-
- sc = device_get_softc(device_get_parent(dev));
- sc_if = device_get_softc(dev);
- KASSERT(mtx_initialized(&sc_if->sk_softc->sk_mtx),
- ("sk mutex not initialized in sk_detach_xmac"));
- SK_IF_LOCK(sc_if);
-
- ifp = &sc_if->arpcom.ac_if;
- /* These should only be active if attach_xmac succeeded */
- if (device_is_attached(dev)) {
- sk_stop(sc_if);
- ether_ifdetach(ifp);
- }
- if (sc_if->sk_miibus)
- device_delete_child(dev, sc_if->sk_miibus);
- bus_generic_detach(dev);
- if (sc_if->sk_cdata.sk_jumbo_buf)
- contigfree(sc_if->sk_cdata.sk_jumbo_buf, SK_JMEM, M_DEVBUF);
- if (sc_if->sk_rdata) {
- contigfree(sc_if->sk_rdata, sizeof(struct sk_ring_data),
- M_DEVBUF);
- }
- SK_IF_UNLOCK(sc_if);
-
- return(0);
-}
-
-static int
-sk_detach(dev)
- device_t dev;
-{
- struct sk_softc *sc;
-
- sc = device_get_softc(dev);
- KASSERT(mtx_initialized(&sc->sk_mtx), ("sk mutex not initialized"));
- SK_LOCK(sc);
-
- if (device_is_alive(dev)) {
- if (sc->sk_devs[SK_PORT_A] != NULL)
- device_delete_child(dev, sc->sk_devs[SK_PORT_A]);
- if (sc->sk_devs[SK_PORT_B] != NULL)
- device_delete_child(dev, sc->sk_devs[SK_PORT_B]);
- bus_generic_detach(dev);
- }
-
- if (sc->sk_intrhand)
- bus_teardown_intr(dev, sc->sk_irq, sc->sk_intrhand);
- if (sc->sk_irq)
- bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sk_irq);
- if (sc->sk_res)
- bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
-
- SK_UNLOCK(sc);
- mtx_destroy(&sc->sk_mtx);
-
- return(0);
-}
-
-static int
-sk_encap(sc_if, m_head, txidx)
- struct sk_if_softc *sc_if;
- struct mbuf *m_head;
- u_int32_t *txidx;
-{
- struct sk_tx_desc *f = NULL;
- struct mbuf *m;
- u_int32_t frag, cur, cnt = 0;
-
- m = m_head;
- cur = frag = *txidx;
-
- /*
- * Start packing the mbufs in this chain into
- * the fragment pointers. Stop when we run out
- * of fragments or hit the end of the mbuf chain.
- */
- for (m = m_head; m != NULL; m = m->m_next) {
- if (m->m_len != 0) {
- if ((SK_TX_RING_CNT -
- (sc_if->sk_cdata.sk_tx_cnt + cnt)) < 2)
- return(ENOBUFS);
- f = &sc_if->sk_rdata->sk_tx_ring[frag];
- f->sk_data_lo = vtophys(mtod(m, vm_offset_t));
- f->sk_ctl = m->m_len | SK_OPCODE_DEFAULT;
- if (cnt == 0)
- f->sk_ctl |= SK_TXCTL_FIRSTFRAG;
- else
- f->sk_ctl |= SK_TXCTL_OWN;
- cur = frag;
- SK_INC(frag, SK_TX_RING_CNT);
- cnt++;
- }
- }
-
- if (m != NULL)
- return(ENOBUFS);
-
- sc_if->sk_rdata->sk_tx_ring[cur].sk_ctl |=
- SK_TXCTL_LASTFRAG|SK_TXCTL_EOF_INTR;
- sc_if->sk_cdata.sk_tx_chain[cur].sk_mbuf = m_head;
- sc_if->sk_rdata->sk_tx_ring[*txidx].sk_ctl |= SK_TXCTL_OWN;
- sc_if->sk_cdata.sk_tx_cnt += cnt;
-
- *txidx = frag;
-
- return(0);
-}
-
-static void
-sk_start(ifp)
- struct ifnet *ifp;
-{
- struct sk_softc *sc;
- struct sk_if_softc *sc_if;
- struct mbuf *m_head = NULL;
- u_int32_t idx;
-
- sc_if = ifp->if_softc;
- sc = sc_if->sk_softc;
-
- SK_IF_LOCK(sc_if);
-
- idx = sc_if->sk_cdata.sk_tx_prod;
-
- while(sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf == NULL) {
- IF_DEQUEUE(&ifp->if_snd, m_head);
- if (m_head == NULL)
- break;
-
- /*
- * Pack the data into the transmit ring. If we
- * don't have room, set the OACTIVE flag and wait
- * for the NIC to drain the ring.
- */
- if (sk_encap(sc_if, m_head, &idx)) {
- IF_PREPEND(&ifp->if_snd, m_head);
- ifp->if_flags |= IFF_OACTIVE;
- break;
- }
-
- /*
- * If there's a BPF listener, bounce a copy of this frame
- * to him.
- */
- BPF_MTAP(ifp, m_head);
- }
-
- /* Transmit */
- sc_if->sk_cdata.sk_tx_prod = idx;
- CSR_WRITE_4(sc, sc_if->sk_tx_bmu, SK_TXBMU_TX_START);
-
- /* Set a timeout in case the chip goes out to lunch. */
- ifp->if_timer = 5;
- SK_IF_UNLOCK(sc_if);
-
- return;
-}
-
-
-static void
-sk_watchdog(ifp)
- struct ifnet *ifp;
-{
- struct sk_if_softc *sc_if;
-
- sc_if = ifp->if_softc;
-
- printf("sk%d: watchdog timeout\n", sc_if->sk_unit);
- sk_init(sc_if);
-
- return;
-}
-
-static void
-sk_shutdown(dev)
- device_t dev;
-{
- struct sk_softc *sc;
-
- sc = device_get_softc(dev);
- SK_LOCK(sc);
-
- /* Turn off the 'driver is loaded' LED. */
- CSR_WRITE_2(sc, SK_LED, SK_LED_GREEN_OFF);
-
- /*
- * Reset the GEnesis controller. Doing this should also
- * assert the resets on the attached XMAC(s).
- */
- sk_reset(sc);
- SK_UNLOCK(sc);
-
- return;
-}
-
-static void
-sk_rxeof(sc_if)
- struct sk_if_softc *sc_if;
-{
- struct mbuf *m;
- struct ifnet *ifp;
- struct sk_chain *cur_rx;
- int total_len = 0;
- int i;
- u_int32_t rxstat;
-
- ifp = &sc_if->arpcom.ac_if;
- i = sc_if->sk_cdata.sk_rx_prod;
- cur_rx = &sc_if->sk_cdata.sk_rx_chain[i];
-
- while(!(sc_if->sk_rdata->sk_rx_ring[i].sk_ctl & SK_RXCTL_OWN)) {
-
- cur_rx = &sc_if->sk_cdata.sk_rx_chain[i];
- rxstat = sc_if->sk_rdata->sk_rx_ring[i].sk_xmac_rxstat;
- m = cur_rx->sk_mbuf;
- cur_rx->sk_mbuf = NULL;
- total_len = SK_RXBYTES(sc_if->sk_rdata->sk_rx_ring[i].sk_ctl);
- SK_INC(i, SK_RX_RING_CNT);
-
- if (rxstat & XM_RXSTAT_ERRFRAME) {
- ifp->if_ierrors++;
- sk_newbuf(sc_if, cur_rx, m);
- continue;
- }
-
- /*
- * Try to allocate a new jumbo buffer. If that
- * fails, copy the packet to mbufs and put the
- * jumbo buffer back in the ring so it can be
- * re-used. If allocating mbufs fails, then we
- * have to drop the packet.
- */
- if (sk_newbuf(sc_if, cur_rx, NULL) == ENOBUFS) {
- struct mbuf *m0;
- m0 = m_devget(mtod(m, char *), total_len, ETHER_ALIGN,
- ifp, NULL);
- sk_newbuf(sc_if, cur_rx, m);
- if (m0 == NULL) {
- printf("sk%d: no receive buffers "
- "available -- packet dropped!\n",
- sc_if->sk_unit);
- ifp->if_ierrors++;
- continue;
- }
- m = m0;
- } else {
- m->m_pkthdr.rcvif = ifp;
- m->m_pkthdr.len = m->m_len = total_len;
- }
-
- ifp->if_ipackets++;
- (*ifp->if_input)(ifp, m);
- }
-
- sc_if->sk_cdata.sk_rx_prod = i;
-
- return;
-}
-
-static void
-sk_txeof(sc_if)
- struct sk_if_softc *sc_if;
-{
- struct sk_tx_desc *cur_tx = NULL;
- struct ifnet *ifp;
- u_int32_t idx;
-
- ifp = &sc_if->arpcom.ac_if;
-
- /*
- * Go through our tx ring and free mbufs for those
- * frames that have been sent.
- */
- idx = sc_if->sk_cdata.sk_tx_cons;
- while(idx != sc_if->sk_cdata.sk_tx_prod) {
- cur_tx = &sc_if->sk_rdata->sk_tx_ring[idx];
- if (cur_tx->sk_ctl & SK_TXCTL_OWN)
- break;
- if (cur_tx->sk_ctl & SK_TXCTL_LASTFRAG)
- ifp->if_opackets++;
- if (sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf != NULL) {
- m_freem(sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf);
- sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf = NULL;
- }
- sc_if->sk_cdata.sk_tx_cnt--;
- SK_INC(idx, SK_TX_RING_CNT);
- ifp->if_timer = 0;
- }
-
- sc_if->sk_cdata.sk_tx_cons = idx;
-
- if (cur_tx != NULL)
- ifp->if_flags &= ~IFF_OACTIVE;
-
- return;
-}
-
-static void
-sk_tick(xsc_if)
- void *xsc_if;
-{
- struct sk_if_softc *sc_if;
- struct mii_data *mii;
- struct ifnet *ifp;
- int i;
-
- sc_if = xsc_if;
- SK_IF_LOCK(sc_if);
- ifp = &sc_if->arpcom.ac_if;
- mii = device_get_softc(sc_if->sk_miibus);
-
- if (!(ifp->if_flags & IFF_UP)) {
- SK_IF_UNLOCK(sc_if);
- return;
- }
-
- if (sc_if->sk_phytype == SK_PHYTYPE_BCOM) {
- sk_intr_bcom(sc_if);
- SK_IF_UNLOCK(sc_if);
- return;
- }
-
- /*
- * According to SysKonnect, the correct way to verify that
- * the link has come back up is to poll bit 0 of the GPIO
- * register three times. This pin has the signal from the
- * link_sync pin connected to it; if we read the same link
- * state 3 times in a row, we know the link is up.
- */
- for (i = 0; i < 3; i++) {
- if (SK_XM_READ_2(sc_if, XM_GPIO) & XM_GPIO_GP0_SET)
- break;
- }
-
- if (i != 3) {
- sc_if->sk_tick_ch = timeout(sk_tick, sc_if, hz);
- SK_IF_UNLOCK(sc_if);
- return;
- }
-
- /* Turn the GP0 interrupt back on. */
- SK_XM_CLRBIT_2(sc_if, XM_IMR, XM_IMR_GP0_SET);
- SK_XM_READ_2(sc_if, XM_ISR);
- mii_tick(mii);
- untimeout(sk_tick, sc_if, sc_if->sk_tick_ch);
-
- SK_IF_UNLOCK(sc_if);
- return;
-}
-
-static void
-sk_intr_bcom(sc_if)
- struct sk_if_softc *sc_if;
-{
- struct sk_softc *sc;
- struct mii_data *mii;
- struct ifnet *ifp;
- int status;
-
- sc = sc_if->sk_softc;
- mii = device_get_softc(sc_if->sk_miibus);
- ifp = &sc_if->arpcom.ac_if;
-
- SK_XM_CLRBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_TX_ENB|XM_MMUCMD_RX_ENB);
-
- /*
- * Read the PHY interrupt register to make sure
- * we clear any pending interrupts.
- */
- status = sk_miibus_readreg(sc_if->sk_dev,
- SK_PHYADDR_BCOM, BRGPHY_MII_ISR);
-
- if (!(ifp->if_flags & IFF_RUNNING)) {
- sk_init_xmac(sc_if);
- return;
- }
-
- if (status & (BRGPHY_ISR_LNK_CHG|BRGPHY_ISR_AN_PR)) {
- int lstat;
- lstat = sk_miibus_readreg(sc_if->sk_dev,
- SK_PHYADDR_BCOM, BRGPHY_MII_AUXSTS);
-
- if (!(lstat & BRGPHY_AUXSTS_LINK) && sc_if->sk_link) {
- mii_mediachg(mii);
- /* Turn off the link LED. */
- SK_IF_WRITE_1(sc_if, 0,
- SK_LINKLED1_CTL, SK_LINKLED_OFF);
- sc_if->sk_link = 0;
- } else if (status & BRGPHY_ISR_LNK_CHG) {
- sk_miibus_writereg(sc_if->sk_dev, SK_PHYADDR_BCOM,
- BRGPHY_MII_IMR, 0xFF00);
- mii_tick(mii);
- sc_if->sk_link = 1;
- /* Turn on the link LED. */
- SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL,
- SK_LINKLED_ON|SK_LINKLED_LINKSYNC_OFF|
- SK_LINKLED_BLINK_OFF);
- } else {
- mii_tick(mii);
- sc_if->sk_tick_ch = timeout(sk_tick, sc_if, hz);
- }
- }
-
- SK_XM_SETBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_TX_ENB|XM_MMUCMD_RX_ENB);
-
- return;
-}
-
-static void
-sk_intr_xmac(sc_if)
- struct sk_if_softc *sc_if;
-{
- struct sk_softc *sc;
- u_int16_t status;
- struct mii_data *mii;
-
- sc = sc_if->sk_softc;
- mii = device_get_softc(sc_if->sk_miibus);
- status = SK_XM_READ_2(sc_if, XM_ISR);
-
- /*
- * Link has gone down. Start MII tick timeout to
- * watch for link resync.
- */
- if (sc_if->sk_phytype == SK_PHYTYPE_XMAC) {
- if (status & XM_ISR_GP0_SET) {
- SK_XM_SETBIT_2(sc_if, XM_IMR, XM_IMR_GP0_SET);
- sc_if->sk_tick_ch = timeout(sk_tick, sc_if, hz);
- }
-
- if (status & XM_ISR_AUTONEG_DONE) {
- sc_if->sk_tick_ch = timeout(sk_tick, sc_if, hz);
- }
- }
-
- if (status & XM_IMR_TX_UNDERRUN)
- SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_FLUSH_TXFIFO);
-
- if (status & XM_IMR_RX_OVERRUN)
- SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_FLUSH_RXFIFO);
-
- status = SK_XM_READ_2(sc_if, XM_ISR);
-
- return;
-}
-
-static void
-sk_intr(xsc)
- void *xsc;
-{
- struct sk_softc *sc = xsc;
- struct sk_if_softc *sc_if0 = NULL, *sc_if1 = NULL;
- struct ifnet *ifp0 = NULL, *ifp1 = NULL;
- u_int32_t status;
-
- SK_LOCK(sc);
-
- sc_if0 = sc->sk_if[SK_PORT_A];
- sc_if1 = sc->sk_if[SK_PORT_B];
-
- if (sc_if0 != NULL)
- ifp0 = &sc_if0->arpcom.ac_if;
- if (sc_if1 != NULL)
- ifp1 = &sc_if1->arpcom.ac_if;
-
- for (;;) {
- status = CSR_READ_4(sc, SK_ISSR);
- if (!(status & sc->sk_intrmask))
- break;
-
- /* Handle receive interrupts first. */
- if (status & SK_ISR_RX1_EOF) {
- sk_rxeof(sc_if0);
- CSR_WRITE_4(sc, SK_BMU_RX_CSR0,
- SK_RXBMU_CLR_IRQ_EOF|SK_RXBMU_RX_START);
- }
- if (status & SK_ISR_RX2_EOF) {
- sk_rxeof(sc_if1);
- CSR_WRITE_4(sc, SK_BMU_RX_CSR1,
- SK_RXBMU_CLR_IRQ_EOF|SK_RXBMU_RX_START);
- }
-
- /* Then transmit interrupts. */
- if (status & SK_ISR_TX1_S_EOF) {
- sk_txeof(sc_if0);
- CSR_WRITE_4(sc, SK_BMU_TXS_CSR0,
- SK_TXBMU_CLR_IRQ_EOF);
- }
- if (status & SK_ISR_TX2_S_EOF) {
- sk_txeof(sc_if1);
- CSR_WRITE_4(sc, SK_BMU_TXS_CSR1,
- SK_TXBMU_CLR_IRQ_EOF);
- }
-
- /* Then MAC interrupts. */
- if (status & SK_ISR_MAC1 &&
- ifp0->if_flags & IFF_RUNNING)
- sk_intr_xmac(sc_if0);
-
- if (status & SK_ISR_MAC2 &&
- ifp1->if_flags & IFF_RUNNING)
- sk_intr_xmac(sc_if1);
-
- if (status & SK_ISR_EXTERNAL_REG) {
- if (ifp0 != NULL)
- sk_intr_bcom(sc_if0);
- if (ifp1 != NULL)
- sk_intr_bcom(sc_if1);
- }
- }
-
- CSR_WRITE_4(sc, SK_IMR, sc->sk_intrmask);
-
- if (ifp0 != NULL && ifp0->if_snd.ifq_head != NULL)
- sk_start(ifp0);
- if (ifp1 != NULL && ifp1->if_snd.ifq_head != NULL)
- sk_start(ifp1);
-
- SK_UNLOCK(sc);
-
- return;
-}
-
-static void
-sk_init_xmac(sc_if)
- struct sk_if_softc *sc_if;
-{
- struct sk_softc *sc;
- struct ifnet *ifp;
- struct sk_bcom_hack bhack[] = {
- { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1104 }, { 0x17, 0x0013 },
- { 0x15, 0x0404 }, { 0x17, 0x8006 }, { 0x15, 0x0132 }, { 0x17, 0x8006 },
- { 0x15, 0x0232 }, { 0x17, 0x800D }, { 0x15, 0x000F }, { 0x18, 0x0420 },
- { 0, 0 } };
-
- sc = sc_if->sk_softc;
- ifp = &sc_if->arpcom.ac_if;
-
- /* Unreset the XMAC. */
- SK_IF_WRITE_2(sc_if, 0, SK_TXF1_MACCTL, SK_TXMACCTL_XMAC_UNRESET);
- DELAY(1000);
-
- /* Reset the XMAC's internal state. */
- SK_XM_SETBIT_2(sc_if, XM_GPIO, XM_GPIO_RESETMAC);
-
- /* Save the XMAC II revision */
- sc_if->sk_xmac_rev = XM_XMAC_REV(SK_XM_READ_4(sc_if, XM_DEVID));
-
- /*
- * Perform additional initialization for external PHYs,
- * namely for the 1000baseTX cards that use the XMAC's
- * GMII mode.
- */
- if (sc_if->sk_phytype == SK_PHYTYPE_BCOM) {
- int i = 0;
- u_int32_t val;
-
- /* Take PHY out of reset. */
- val = sk_win_read_4(sc, SK_GPIO);
- if (sc_if->sk_port == SK_PORT_A)
- val |= SK_GPIO_DIR0|SK_GPIO_DAT0;
- else
- val |= SK_GPIO_DIR2|SK_GPIO_DAT2;
- sk_win_write_4(sc, SK_GPIO, val);
-
- /* Enable GMII mode on the XMAC. */
- SK_XM_SETBIT_2(sc_if, XM_HWCFG, XM_HWCFG_GMIIMODE);
-
- sk_miibus_writereg(sc_if->sk_dev, SK_PHYADDR_BCOM,
- BRGPHY_MII_BMCR, BRGPHY_BMCR_RESET);
- DELAY(10000);
- sk_miibus_writereg(sc_if->sk_dev, SK_PHYADDR_BCOM,
- BRGPHY_MII_IMR, 0xFFF0);
-
- /*
- * Early versions of the BCM5400 apparently have
- * a bug that requires them to have their reserved
- * registers initialized to some magic values. I don't
- * know what the numbers do, I'm just the messenger.
- */
- if (sk_miibus_readreg(sc_if->sk_dev,
- SK_PHYADDR_BCOM, 0x03) == 0x6041) {
- while(bhack[i].reg) {
- sk_miibus_writereg(sc_if->sk_dev,
- SK_PHYADDR_BCOM, bhack[i].reg,
- bhack[i].val);
- i++;
- }
- }
- }
-
- /* Set station address */
- SK_XM_WRITE_2(sc_if, XM_PAR0,
- *(u_int16_t *)(&sc_if->arpcom.ac_enaddr[0]));
- SK_XM_WRITE_2(sc_if, XM_PAR1,
- *(u_int16_t *)(&sc_if->arpcom.ac_enaddr[2]));
- SK_XM_WRITE_2(sc_if, XM_PAR2,
- *(u_int16_t *)(&sc_if->arpcom.ac_enaddr[4]));
- SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_RX_USE_STATION);
-
- if (ifp->if_flags & IFF_PROMISC) {
- SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_RX_PROMISC);
- } else {
- SK_XM_CLRBIT_4(sc_if, XM_MODE, XM_MODE_RX_PROMISC);
- }
-
- if (ifp->if_flags & IFF_BROADCAST) {
- SK_XM_CLRBIT_4(sc_if, XM_MODE, XM_MODE_RX_NOBROAD);
- } else {
- SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_RX_NOBROAD);
- }
-
- /* We don't need the FCS appended to the packet. */
- SK_XM_SETBIT_2(sc_if, XM_RXCMD, XM_RXCMD_STRIPFCS);
-
- /* We want short frames padded to 60 bytes. */
- SK_XM_SETBIT_2(sc_if, XM_TXCMD, XM_TXCMD_AUTOPAD);
-
- /*
- * Enable the reception of all error frames. This is is
- * a necessary evil due to the design of the XMAC. The
- * XMAC's receive FIFO is only 8K in size, however jumbo
- * frames can be up to 9000 bytes in length. When bad
- * frame filtering is enabled, the XMAC's RX FIFO operates
- * in 'store and forward' mode. For this to work, the
- * entire frame has to fit into the FIFO, but that means
- * that jumbo frames larger than 8192 bytes will be
- * truncated. Disabling all bad frame filtering causes
- * the RX FIFO to operate in streaming mode, in which
- * case the XMAC will start transfering frames out of the
- * RX FIFO as soon as the FIFO threshold is reached.
- */
- SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_RX_BADFRAMES|
- XM_MODE_RX_GIANTS|XM_MODE_RX_RUNTS|XM_MODE_RX_CRCERRS|
- XM_MODE_RX_INRANGELEN);
-
- if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN))
- SK_XM_SETBIT_2(sc_if, XM_RXCMD, XM_RXCMD_BIGPKTOK);
- else
- SK_XM_CLRBIT_2(sc_if, XM_RXCMD, XM_RXCMD_BIGPKTOK);
-
- /*
- * Bump up the transmit threshold. This helps hold off transmit
- * underruns when we're blasting traffic from both ports at once.
- */
- SK_XM_WRITE_2(sc_if, XM_TX_REQTHRESH, SK_XM_TX_FIFOTHRESH);
-
- /* Set multicast filter */
- sk_setmulti(sc_if);
-
- /* Clear and enable interrupts */
- SK_XM_READ_2(sc_if, XM_ISR);
- if (sc_if->sk_phytype == SK_PHYTYPE_XMAC)
- SK_XM_WRITE_2(sc_if, XM_IMR, XM_INTRS);
- else
- SK_XM_WRITE_2(sc_if, XM_IMR, 0xFFFF);
-
- /* Configure MAC arbiter */
- switch(sc_if->sk_xmac_rev) {
- case XM_XMAC_REV_B2:
- sk_win_write_1(sc, SK_RCINIT_RX1, SK_RCINIT_XMAC_B2);
- sk_win_write_1(sc, SK_RCINIT_TX1, SK_RCINIT_XMAC_B2);
- sk_win_write_1(sc, SK_RCINIT_RX2, SK_RCINIT_XMAC_B2);
- sk_win_write_1(sc, SK_RCINIT_TX2, SK_RCINIT_XMAC_B2);
- sk_win_write_1(sc, SK_MINIT_RX1, SK_MINIT_XMAC_B2);
- sk_win_write_1(sc, SK_MINIT_TX1, SK_MINIT_XMAC_B2);
- sk_win_write_1(sc, SK_MINIT_RX2, SK_MINIT_XMAC_B2);
- sk_win_write_1(sc, SK_MINIT_TX2, SK_MINIT_XMAC_B2);
- sk_win_write_1(sc, SK_RECOVERY_CTL, SK_RECOVERY_XMAC_B2);
- break;
- case XM_XMAC_REV_C1:
- sk_win_write_1(sc, SK_RCINIT_RX1, SK_RCINIT_XMAC_C1);
- sk_win_write_1(sc, SK_RCINIT_TX1, SK_RCINIT_XMAC_C1);
- sk_win_write_1(sc, SK_RCINIT_RX2, SK_RCINIT_XMAC_C1);
- sk_win_write_1(sc, SK_RCINIT_TX2, SK_RCINIT_XMAC_C1);
- sk_win_write_1(sc, SK_MINIT_RX1, SK_MINIT_XMAC_C1);
- sk_win_write_1(sc, SK_MINIT_TX1, SK_MINIT_XMAC_C1);
- sk_win_write_1(sc, SK_MINIT_RX2, SK_MINIT_XMAC_C1);
- sk_win_write_1(sc, SK_MINIT_TX2, SK_MINIT_XMAC_C1);
- sk_win_write_1(sc, SK_RECOVERY_CTL, SK_RECOVERY_XMAC_B2);
- break;
- default:
- break;
- }
- sk_win_write_2(sc, SK_MACARB_CTL,
- SK_MACARBCTL_UNRESET|SK_MACARBCTL_FASTOE_OFF);
-
- sc_if->sk_link = 1;
-
- return;
-}
-
-/*
- * Note that to properly initialize any part of the GEnesis chip,
- * you first have to take it out of reset mode.
- */
-static void
-sk_init(xsc)
- void *xsc;
-{
- struct sk_if_softc *sc_if = xsc;
- struct sk_softc *sc;
- struct ifnet *ifp;
- struct mii_data *mii;
-
- SK_IF_LOCK(sc_if);
-
- ifp = &sc_if->arpcom.ac_if;
- sc = sc_if->sk_softc;
- mii = device_get_softc(sc_if->sk_miibus);
-
- /* Cancel pending I/O and free all RX/TX buffers. */
- sk_stop(sc_if);
-
- /* Configure LINK_SYNC LED */
- SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL, SK_LINKLED_ON);
- SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL, SK_LINKLED_LINKSYNC_ON);
-
- /* Configure RX LED */
- SK_IF_WRITE_1(sc_if, 0, SK_RXLED1_CTL, SK_RXLEDCTL_COUNTER_START);
-
- /* Configure TX LED */
- SK_IF_WRITE_1(sc_if, 0, SK_TXLED1_CTL, SK_TXLEDCTL_COUNTER_START);
-
- /* Configure I2C registers */
-
- /* Configure XMAC(s) */
- sk_init_xmac(sc_if);
- mii_mediachg(mii);
-
- /* Configure MAC FIFOs */
- SK_IF_WRITE_4(sc_if, 0, SK_RXF1_CTL, SK_FIFO_UNRESET);
- SK_IF_WRITE_4(sc_if, 0, SK_RXF1_END, SK_FIFO_END);
- SK_IF_WRITE_4(sc_if, 0, SK_RXF1_CTL, SK_FIFO_ON);
-
- SK_IF_WRITE_4(sc_if, 0, SK_TXF1_CTL, SK_FIFO_UNRESET);
- SK_IF_WRITE_4(sc_if, 0, SK_TXF1_END, SK_FIFO_END);
- SK_IF_WRITE_4(sc_if, 0, SK_TXF1_CTL, SK_FIFO_ON);
-
- /* Configure transmit arbiter(s) */
- SK_IF_WRITE_1(sc_if, 0, SK_TXAR1_COUNTERCTL,
- SK_TXARCTL_ON|SK_TXARCTL_FSYNC_ON);
-
- /* Configure RAMbuffers */
- SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_CTLTST, SK_RBCTL_UNRESET);
- SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_START, sc_if->sk_rx_ramstart);
- SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_WR_PTR, sc_if->sk_rx_ramstart);
- SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_RD_PTR, sc_if->sk_rx_ramstart);
- SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_END, sc_if->sk_rx_ramend);
- SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_CTLTST, SK_RBCTL_ON);
-
- SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_CTLTST, SK_RBCTL_UNRESET);
- SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_CTLTST, SK_RBCTL_STORENFWD_ON);
- SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_START, sc_if->sk_tx_ramstart);
- SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_WR_PTR, sc_if->sk_tx_ramstart);
- SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_RD_PTR, sc_if->sk_tx_ramstart);
- SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_END, sc_if->sk_tx_ramend);
- SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_CTLTST, SK_RBCTL_ON);
-
- /* Configure BMUs */
- SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, SK_RXBMU_ONLINE);
- SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_CURADDR_LO,
- vtophys(&sc_if->sk_rdata->sk_rx_ring[0]));
- SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_CURADDR_HI, 0);
-
- SK_IF_WRITE_4(sc_if, 1, SK_TXQS1_BMU_CSR, SK_TXBMU_ONLINE);
- SK_IF_WRITE_4(sc_if, 1, SK_TXQS1_CURADDR_LO,
- vtophys(&sc_if->sk_rdata->sk_tx_ring[0]));
- SK_IF_WRITE_4(sc_if, 1, SK_TXQS1_CURADDR_HI, 0);
-
- /* Init descriptors */
- if (sk_init_rx_ring(sc_if) == ENOBUFS) {
- printf("sk%d: initialization failed: no "
- "memory for rx buffers\n", sc_if->sk_unit);
- sk_stop(sc_if);
- SK_IF_UNLOCK(sc_if);
- return;
- }
- sk_init_tx_ring(sc_if);
-
- /* Configure interrupt handling */
- CSR_READ_4(sc, SK_ISSR);
- if (sc_if->sk_port == SK_PORT_A)
- sc->sk_intrmask |= SK_INTRS1;
- else
- sc->sk_intrmask |= SK_INTRS2;
-
- sc->sk_intrmask |= SK_ISR_EXTERNAL_REG;
-
- CSR_WRITE_4(sc, SK_IMR, sc->sk_intrmask);
-
- /* Start BMUs. */
- SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, SK_RXBMU_RX_START);
-
- /* Enable XMACs TX and RX state machines */
- SK_XM_CLRBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_IGNPAUSE);
- SK_XM_SETBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_TX_ENB|XM_MMUCMD_RX_ENB);
-
- ifp->if_flags |= IFF_RUNNING;
- ifp->if_flags &= ~IFF_OACTIVE;
-
- SK_IF_UNLOCK(sc_if);
-
- return;
-}
-
-static void
-sk_stop(sc_if)
- struct sk_if_softc *sc_if;
-{
- int i;
- struct sk_softc *sc;
- struct ifnet *ifp;
-
- SK_IF_LOCK(sc_if);
- sc = sc_if->sk_softc;
- ifp = &sc_if->arpcom.ac_if;
-
- untimeout(sk_tick, sc_if, sc_if->sk_tick_ch);
-
- if (sc_if->sk_phytype == SK_PHYTYPE_BCOM) {
- u_int32_t val;
-
- /* Put PHY back into reset. */
- val = sk_win_read_4(sc, SK_GPIO);
- if (sc_if->sk_port == SK_PORT_A) {
- val |= SK_GPIO_DIR0;
- val &= ~SK_GPIO_DAT0;
- } else {
- val |= SK_GPIO_DIR2;
- val &= ~SK_GPIO_DAT2;
- }
- sk_win_write_4(sc, SK_GPIO, val);
- }
-
- /* Turn off various components of this interface. */
- SK_XM_SETBIT_2(sc_if, XM_GPIO, XM_GPIO_RESETMAC);
- SK_IF_WRITE_2(sc_if, 0, SK_TXF1_MACCTL, SK_TXMACCTL_XMAC_RESET);
- SK_IF_WRITE_4(sc_if, 0, SK_RXF1_CTL, SK_FIFO_RESET);
- SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, SK_RXBMU_OFFLINE);
- SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_CTLTST, SK_RBCTL_RESET|SK_RBCTL_OFF);
- SK_IF_WRITE_4(sc_if, 1, SK_TXQS1_BMU_CSR, SK_TXBMU_OFFLINE);
- SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_CTLTST, SK_RBCTL_RESET|SK_RBCTL_OFF);
- SK_IF_WRITE_1(sc_if, 0, SK_TXAR1_COUNTERCTL, SK_TXARCTL_OFF);
- SK_IF_WRITE_1(sc_if, 0, SK_RXLED1_CTL, SK_RXLEDCTL_COUNTER_STOP);
- SK_IF_WRITE_1(sc_if, 0, SK_TXLED1_CTL, SK_RXLEDCTL_COUNTER_STOP);
- SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL, SK_LINKLED_OFF);
- SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL, SK_LINKLED_LINKSYNC_OFF);
-
- /* Disable interrupts */
- if (sc_if->sk_port == SK_PORT_A)
- sc->sk_intrmask &= ~SK_INTRS1;
- else
- sc->sk_intrmask &= ~SK_INTRS2;
- CSR_WRITE_4(sc, SK_IMR, sc->sk_intrmask);
-
- SK_XM_READ_2(sc_if, XM_ISR);
- SK_XM_WRITE_2(sc_if, XM_IMR, 0xFFFF);
-
- /* Free RX and TX mbufs still in the queues. */
- for (i = 0; i < SK_RX_RING_CNT; i++) {
- if (sc_if->sk_cdata.sk_rx_chain[i].sk_mbuf != NULL) {
- m_freem(sc_if->sk_cdata.sk_rx_chain[i].sk_mbuf);
- sc_if->sk_cdata.sk_rx_chain[i].sk_mbuf = NULL;
- }
- }
-
- for (i = 0; i < SK_TX_RING_CNT; i++) {
- if (sc_if->sk_cdata.sk_tx_chain[i].sk_mbuf != NULL) {
- m_freem(sc_if->sk_cdata.sk_tx_chain[i].sk_mbuf);
- sc_if->sk_cdata.sk_tx_chain[i].sk_mbuf = NULL;
- }
- }
-
- ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
- SK_IF_UNLOCK(sc_if);
- return;
-}
diff --git a/sys/dev/sk/if_skreg.h b/sys/dev/sk/if_skreg.h
deleted file mode 100644
index 061707c936bd..000000000000
--- a/sys/dev/sk/if_skreg.h
+++ /dev/null
@@ -1,1223 +0,0 @@
-/*
- * Copyright (c) 1997, 1998, 1999, 2000
- * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-/*
- * SysKonnect PCI vendor ID
- */
-#define SK_VENDORID 0x1148
-
-/*
- * SK-NET gigabit ethernet device ID
- */
-#define SK_DEVICEID_GE 0x4300
-
-/*
- * GEnesis registers. The GEnesis chip has a 256-byte I/O window
- * but internally it has a 16K register space. This 16K space is
- * divided into 128-byte blocks. The first 128 bytes of the I/O
- * window represent the first block, which is permanently mapped
- * at the start of the window. The other 127 blocks can be mapped
- * to the second 128 bytes of the I/O window by setting the desired
- * block value in the RAP register in block 0. Not all of the 127
- * blocks are actually used. Most registers are 32 bits wide, but
- * there are a few 16-bit and 8-bit ones as well.
- */
-
-
-/* Start of remappable register window. */
-#define SK_WIN_BASE 0x0080
-
-/* Size of a window */
-#define SK_WIN_LEN 0x80
-
-#define SK_WIN_MASK 0x3F80
-#define SK_REG_MASK 0x7F
-
-/* Compute the window of a given register (for the RAP register) */
-#define SK_WIN(reg) (((reg) & SK_WIN_MASK) / SK_WIN_LEN)
-
-/* Compute the relative offset of a register within the window */
-#define SK_REG(reg) ((reg) & SK_REG_MASK)
-
-#define SK_PORT_A 0
-#define SK_PORT_B 1
-
-/*
- * Compute offset of port-specific register. Since there are two
- * ports, there are two of some GEnesis modules (e.g. two sets of
- * DMA queues, two sets of FIFO control registers, etc...). Normally,
- * the block for port 0 is at offset 0x0 and the block for port 1 is
- * at offset 0x80 (i.e. the next page over). However for the transmit
- * BMUs and RAMbuffers, there are two blocks for each port: one for
- * the sync transmit queue and one for the async queue (which we don't
- * use). However instead of ordering them like this:
- * TX sync 1 / TX sync 2 / TX async 1 / TX async 2
- * SysKonnect has instead ordered them like this:
- * TX sync 1 / TX async 1 / TX sync 2 / TX async 2
- * This means that when referencing the TX BMU and RAMbuffer registers,
- * we have to double the block offset (0x80 * 2) in order to reach the
- * second queue. This prevents us from using the same formula
- * (sk_port * 0x80) to compute the offsets for all of the port-specific
- * blocks: we need an extra offset for the BMU and RAMbuffer registers.
- * The simplest thing is to provide an extra argument to these macros:
- * the 'skip' parameter. The 'skip' value is the number of extra pages
- * for skip when computing the port0/port1 offsets. For most registers,
- * the skip value is 0; for the BMU and RAMbuffer registers, it's 1.
- */
-#define SK_IF_READ_4(sc_if, skip, reg) \
- sk_win_read_4(sc_if->sk_softc, reg + \
- ((sc_if->sk_port * (skip + 1)) * SK_WIN_LEN))
-#define SK_IF_READ_2(sc_if, skip, reg) \
- sk_win_read_2(sc_if->sk_softc, reg + \
- ((sc_if->sk_port * (skip + 1)) * SK_WIN_LEN))
-#define SK_IF_READ_1(sc_if, skip, reg) \
- sk_win_read_1(sc_if->sk_softc, reg + \
- ((sc_if->sk_port * (skip + 1)) * SK_WIN_LEN))
-
-#define SK_IF_WRITE_4(sc_if, skip, reg, val) \
- sk_win_write_4(sc_if->sk_softc, \
- reg + ((sc_if->sk_port * (skip + 1)) * SK_WIN_LEN), val)
-#define SK_IF_WRITE_2(sc_if, skip, reg, val) \
- sk_win_write_2(sc_if->sk_softc, \
- reg + ((sc_if->sk_port * (skip + 1)) * SK_WIN_LEN), val)
-#define SK_IF_WRITE_1(sc_if, skip, reg, val) \
- sk_win_write_1(sc_if->sk_softc, \
- reg + ((sc_if->sk_port * (skip + 1)) * SK_WIN_LEN), val)
-
-/* Block 0 registers, permanently mapped at iobase. */
-#define SK_RAP 0x0000
-#define SK_CSR 0x0004
-#define SK_LED 0x0006
-#define SK_ISR 0x0008 /* interrupt source */
-#define SK_IMR 0x000C /* interrupt mask */
-#define SK_IESR 0x0010 /* interrupt hardware error source */
-#define SK_IEMR 0x0014 /* interrupt hardware error mask */
-#define SK_ISSR 0x0018 /* special interrupt source */
-#define SK_XM_IMR0 0x0020
-#define SK_XM_ISR0 0x0028
-#define SK_XM_PHYADDR0 0x0030
-#define SK_XM_PHYDATA0 0x0034
-#define SK_XM_IMR1 0x0040
-#define SK_XM_ISR1 0x0048
-#define SK_XM_PHYADDR1 0x0050
-#define SK_XM_PHYDATA1 0x0054
-#define SK_BMU_RX_CSR0 0x0060
-#define SK_BMU_RX_CSR1 0x0064
-#define SK_BMU_TXS_CSR0 0x0068
-#define SK_BMU_TXA_CSR0 0x006C
-#define SK_BMU_TXS_CSR1 0x0070
-#define SK_BMU_TXA_CSR1 0x0074
-
-/* SK_CSR register */
-#define SK_CSR_SW_RESET 0x0001
-#define SK_CSR_SW_UNRESET 0x0002
-#define SK_CSR_MASTER_RESET 0x0004
-#define SK_CSR_MASTER_UNRESET 0x0008
-#define SK_CSR_MASTER_STOP 0x0010
-#define SK_CSR_MASTER_DONE 0x0020
-#define SK_CSR_SW_IRQ_CLEAR 0x0040
-#define SK_CSR_SW_IRQ_SET 0x0080
-#define SK_CSR_SLOTSIZE 0x0100 /* 1 == 64 bits, 0 == 32 */
-#define SK_CSR_BUSCLOCK 0x0200 /* 1 == 33/66 Mhz, = 33 */
-
-/* SK_LED register */
-#define SK_LED_GREEN_OFF 0x01
-#define SK_LED_GREEN_ON 0x02
-
-/* SK_ISR register */
-#define SK_ISR_TX2_AS_CHECK 0x00000001
-#define SK_ISR_TX2_AS_EOF 0x00000002
-#define SK_ISR_TX2_AS_EOB 0x00000004
-#define SK_ISR_TX2_S_CHECK 0x00000008
-#define SK_ISR_TX2_S_EOF 0x00000010
-#define SK_ISR_TX2_S_EOB 0x00000020
-#define SK_ISR_TX1_AS_CHECK 0x00000040
-#define SK_ISR_TX1_AS_EOF 0x00000080
-#define SK_ISR_TX1_AS_EOB 0x00000100
-#define SK_ISR_TX1_S_CHECK 0x00000200
-#define SK_ISR_TX1_S_EOF 0x00000400
-#define SK_ISR_TX1_S_EOB 0x00000800
-#define SK_ISR_RX2_CHECK 0x00001000
-#define SK_ISR_RX2_EOF 0x00002000
-#define SK_ISR_RX2_EOB 0x00004000
-#define SK_ISR_RX1_CHECK 0x00008000
-#define SK_ISR_RX1_EOF 0x00010000
-#define SK_ISR_RX1_EOB 0x00020000
-#define SK_ISR_LINK2_OFLOW 0x00040000
-#define SK_ISR_MAC2 0x00080000
-#define SK_ISR_LINK1_OFLOW 0x00100000
-#define SK_ISR_MAC1 0x00200000
-#define SK_ISR_TIMER 0x00400000
-#define SK_ISR_EXTERNAL_REG 0x00800000
-#define SK_ISR_SW 0x01000000
-#define SK_ISR_I2C_RDY 0x02000000
-#define SK_ISR_TX2_TIMEO 0x04000000
-#define SK_ISR_TX1_TIMEO 0x08000000
-#define SK_ISR_RX2_TIMEO 0x10000000
-#define SK_ISR_RX1_TIMEO 0x20000000
-#define SK_ISR_RSVD 0x40000000
-#define SK_ISR_HWERR 0x80000000
-
-/* SK_IMR register */
-#define SK_IMR_TX2_AS_CHECK 0x00000001
-#define SK_IMR_TX2_AS_EOF 0x00000002
-#define SK_IMR_TX2_AS_EOB 0x00000004
-#define SK_IMR_TX2_S_CHECK 0x00000008
-#define SK_IMR_TX2_S_EOF 0x00000010
-#define SK_IMR_TX2_S_EOB 0x00000020
-#define SK_IMR_TX1_AS_CHECK 0x00000040
-#define SK_IMR_TX1_AS_EOF 0x00000080
-#define SK_IMR_TX1_AS_EOB 0x00000100
-#define SK_IMR_TX1_S_CHECK 0x00000200
-#define SK_IMR_TX1_S_EOF 0x00000400
-#define SK_IMR_TX1_S_EOB 0x00000800
-#define SK_IMR_RX2_CHECK 0x00001000
-#define SK_IMR_RX2_EOF 0x00002000
-#define SK_IMR_RX2_EOB 0x00004000
-#define SK_IMR_RX1_CHECK 0x00008000
-#define SK_IMR_RX1_EOF 0x00010000
-#define SK_IMR_RX1_EOB 0x00020000
-#define SK_IMR_LINK2_OFLOW 0x00040000
-#define SK_IMR_MAC2 0x00080000
-#define SK_IMR_LINK1_OFLOW 0x00100000
-#define SK_IMR_MAC1 0x00200000
-#define SK_IMR_TIMER 0x00400000
-#define SK_IMR_EXTERNAL_REG 0x00800000
-#define SK_IMR_SW 0x01000000
-#define SK_IMR_I2C_RDY 0x02000000
-#define SK_IMR_TX2_TIMEO 0x04000000
-#define SK_IMR_TX1_TIMEO 0x08000000
-#define SK_IMR_RX2_TIMEO 0x10000000
-#define SK_IMR_RX1_TIMEO 0x20000000
-#define SK_IMR_RSVD 0x40000000
-#define SK_IMR_HWERR 0x80000000
-
-#define SK_INTRS1 \
- (SK_IMR_RX1_EOF|SK_IMR_TX1_S_EOF|SK_IMR_MAC1)
-
-#define SK_INTRS2 \
- (SK_IMR_RX2_EOF|SK_IMR_TX2_S_EOF|SK_IMR_MAC2)
-
-/* SK_IESR register */
-#define SK_IESR_PAR_RX2 0x00000001
-#define SK_IESR_PAR_RX1 0x00000002
-#define SK_IESR_PAR_MAC2 0x00000004
-#define SK_IESR_PAR_MAC1 0x00000008
-#define SK_IESR_PAR_WR_RAM 0x00000010
-#define SK_IESR_PAR_RD_RAM 0x00000020
-#define SK_IESR_NO_TSTAMP_MAC2 0x00000040
-#define SK_IESR_NO_TSTAMO_MAC1 0x00000080
-#define SK_IESR_NO_STS_MAC2 0x00000100
-#define SK_IESR_NO_STS_MAC1 0x00000200
-#define SK_IESR_IRQ_STS 0x00000400
-#define SK_IESR_MASTERERR 0x00000800
-
-/* SK_IEMR register */
-#define SK_IEMR_PAR_RX2 0x00000001
-#define SK_IEMR_PAR_RX1 0x00000002
-#define SK_IEMR_PAR_MAC2 0x00000004
-#define SK_IEMR_PAR_MAC1 0x00000008
-#define SK_IEMR_PAR_WR_RAM 0x00000010
-#define SK_IEMR_PAR_RD_RAM 0x00000020
-#define SK_IEMR_NO_TSTAMP_MAC2 0x00000040
-#define SK_IEMR_NO_TSTAMO_MAC1 0x00000080
-#define SK_IEMR_NO_STS_MAC2 0x00000100
-#define SK_IEMR_NO_STS_MAC1 0x00000200
-#define SK_IEMR_IRQ_STS 0x00000400
-#define SK_IEMR_MASTERERR 0x00000800
-
-/* Block 2 */
-#define SK_MAC0_0 0x0100
-#define SK_MAC0_1 0x0104
-#define SK_MAC1_0 0x0108
-#define SK_MAC1_1 0x010C
-#define SK_MAC2_0 0x0110
-#define SK_MAC2_1 0x0114
-#define SK_CONNTYPE 0x0118
-#define SK_PMDTYPE 0x0119
-#define SK_CONFIG 0x011A
-#define SK_CHIPVER 0x011B
-#define SK_EPROM0 0x011C
-#define SK_EPROM1 0x011D
-#define SK_EPROM2 0x011E
-#define SK_EPROM3 0x011F
-#define SK_EP_ADDR 0x0120
-#define SK_EP_DATA 0x0124
-#define SK_EP_LOADCTL 0x0128
-#define SK_EP_LOADTST 0x0129
-#define SK_TIMERINIT 0x0130
-#define SK_TIMER 0x0134
-#define SK_TIMERCTL 0x0138
-#define SK_TIMERTST 0x0139
-#define SK_IMTIMERINIT 0x0140
-#define SK_IMTIMER 0x0144
-#define SK_IMTIMERCTL 0x0148
-#define SK_IMTIMERTST 0x0149
-#define SK_IMMR 0x014C
-#define SK_IHWEMR 0x0150
-#define SK_TESTCTL1 0x0158
-#define SK_TESTCTL2 0x0159
-#define SK_GPIO 0x015C
-#define SK_I2CHWCTL 0x0160
-#define SK_I2CHWDATA 0x0164
-#define SK_I2CHWIRQ 0x0168
-#define SK_I2CSW 0x016C
-#define SK_BLNKINIT 0x0170
-#define SK_BLNKCOUNT 0x0174
-#define SK_BLNKCTL 0x0178
-#define SK_BLNKSTS 0x0179
-#define SK_BLNKTST 0x017A
-
-#define SK_IMCTL_STOP 0x02
-#define SK_IMCTL_START 0x04
-
-#define SK_IMTIMER_TICKS 54
-#define SK_IM_USECS(x) ((x) * SK_IMTIMER_TICKS)
-
-/*
- * The SK_EPROM0 register contains a byte that describes the
- * amount of SRAM mounted on the NIC. The value also tells if
- * the chips are 64K or 128K. This affects the RAMbuffer address
- * offset that we need to use.
- */
-#define SK_RAMSIZE_512K_64 0x1
-#define SK_RAMSIZE_1024K_128 0x2
-#define SK_RAMSIZE_1024K_64 0x3
-#define SK_RAMSIZE_2048K_128 0x4
-
-#define SK_RBOFF_0 0x0
-#define SK_RBOFF_80000 0x80000
-
-/*
- * SK_EEPROM1 contains the PHY type, which may be XMAC for
- * fiber-based cards or BCOM for 1000baseT cards with a Broadcom
- * PHY.
- */
-#define SK_PHYTYPE_XMAC 0 /* integeated XMAC II PHY */
-#define SK_PHYTYPE_BCOM 1 /* Broadcom BCM5400 */
-#define SK_PHYTYPE_LONE 2 /* Level One LXT1000 */
-#define SK_PHYTYPE_NAT 3 /* National DP83891 */
-
-/*
- * PHY addresses.
- */
-#define SK_PHYADDR_XMAC 0x0
-#define SK_PHYADDR_BCOM 0x1
-#define SK_PHYADDR_LONE 0x3
-#define SK_PHYADDR_NAT 0x0
-
-#define SK_CONFIG_SINGLEMAC 0x01
-#define SK_CONFIG_DIS_DSL_CLK 0x02
-
-#define SK_PMD_1000BASELX 0x4C
-#define SK_PMD_1000BASESX 0x53
-#define SK_PMD_1000BASECX 0x43
-#define SK_PMD_1000BASETX 0x54
-
-/* GPIO bits */
-#define SK_GPIO_DAT0 0x00000001
-#define SK_GPIO_DAT1 0x00000002
-#define SK_GPIO_DAT2 0x00000004
-#define SK_GPIO_DAT3 0x00000008
-#define SK_GPIO_DAT4 0x00000010
-#define SK_GPIO_DAT5 0x00000020
-#define SK_GPIO_DAT6 0x00000040
-#define SK_GPIO_DAT7 0x00000080
-#define SK_GPIO_DAT8 0x00000100
-#define SK_GPIO_DAT9 0x00000200
-#define SK_GPIO_DIR0 0x00010000
-#define SK_GPIO_DIR1 0x00020000
-#define SK_GPIO_DIR2 0x00040000
-#define SK_GPIO_DIR3 0x00080000
-#define SK_GPIO_DIR4 0x00100000
-#define SK_GPIO_DIR5 0x00200000
-#define SK_GPIO_DIR6 0x00400000
-#define SK_GPIO_DIR7 0x00800000
-#define SK_GPIO_DIR8 0x01000000
-#define SK_GPIO_DIR9 0x02000000
-
-/* Block 3 Ram interface and MAC arbiter registers */
-#define SK_RAMADDR 0x0180
-#define SK_RAMDATA0 0x0184
-#define SK_RAMDATA1 0x0188
-#define SK_TO0 0x0190
-#define SK_TO1 0x0191
-#define SK_TO2 0x0192
-#define SK_TO3 0x0193
-#define SK_TO4 0x0194
-#define SK_TO5 0x0195
-#define SK_TO6 0x0196
-#define SK_TO7 0x0197
-#define SK_TO8 0x0198
-#define SK_TO9 0x0199
-#define SK_TO10 0x019A
-#define SK_TO11 0x019B
-#define SK_RITIMEO_TMR 0x019C
-#define SK_RAMCTL 0x01A0
-#define SK_RITIMER_TST 0x01A2
-
-#define SK_RAMCTL_RESET 0x0001
-#define SK_RAMCTL_UNRESET 0x0002
-#define SK_RAMCTL_CLR_IRQ_WPAR 0x0100
-#define SK_RAMCTL_CLR_IRQ_RPAR 0x0200
-
-/* Mac arbiter registers */
-#define SK_MINIT_RX1 0x01B0
-#define SK_MINIT_RX2 0x01B1
-#define SK_MINIT_TX1 0x01B2
-#define SK_MINIT_TX2 0x01B3
-#define SK_MTIMEO_RX1 0x01B4
-#define SK_MTIMEO_RX2 0x01B5
-#define SK_MTIMEO_TX1 0x01B6
-#define SK_MTIEMO_TX2 0x01B7
-#define SK_MACARB_CTL 0x01B8
-#define SK_MTIMER_TST 0x01BA
-#define SK_RCINIT_RX1 0x01C0
-#define SK_RCINIT_RX2 0x01C1
-#define SK_RCINIT_TX1 0x01C2
-#define SK_RCINIT_TX2 0x01C3
-#define SK_RCTIMEO_RX1 0x01C4
-#define SK_RCTIMEO_RX2 0x01C5
-#define SK_RCTIMEO_TX1 0x01C6
-#define SK_RCTIMEO_TX2 0x01C7
-#define SK_RECOVERY_CTL 0x01C8
-#define SK_RCTIMER_TST 0x01CA
-
-/* Packet arbiter registers */
-#define SK_RXPA1_TINIT 0x01D0
-#define SK_RXPA2_TINIT 0x01D4
-#define SK_TXPA1_TINIT 0x01D8
-#define SK_TXPA2_TINIT 0x01DC
-#define SK_RXPA1_TIMEO 0x01E0
-#define SK_RXPA2_TIMEO 0x01E4
-#define SK_TXPA1_TIMEO 0x01E8
-#define SK_TXPA2_TIMEO 0x01EC
-#define SK_PKTARB_CTL 0x01F0
-#define SK_PKTATB_TST 0x01F2
-
-#define SK_PKTARB_TIMEOUT 0x2000
-
-#define SK_PKTARBCTL_RESET 0x0001
-#define SK_PKTARBCTL_UNRESET 0x0002
-#define SK_PKTARBCTL_RXTO1_OFF 0x0004
-#define SK_PKTARBCTL_RXTO1_ON 0x0008
-#define SK_PKTARBCTL_RXTO2_OFF 0x0010
-#define SK_PKTARBCTL_RXTO2_ON 0x0020
-#define SK_PKTARBCTL_TXTO1_OFF 0x0040
-#define SK_PKTARBCTL_TXTO1_ON 0x0080
-#define SK_PKTARBCTL_TXTO2_OFF 0x0100
-#define SK_PKTARBCTL_TXTO2_ON 0x0200
-#define SK_PKTARBCTL_CLR_IRQ_RXTO1 0x0400
-#define SK_PKTARBCTL_CLR_IRQ_RXTO2 0x0800
-#define SK_PKTARBCTL_CLR_IRQ_TXTO1 0x1000
-#define SK_PKTARBCTL_CLR_IRQ_TXTO2 0x2000
-
-#define SK_MINIT_XMAC_B2 54
-#define SK_MINIT_XMAC_C1 63
-
-#define SK_MACARBCTL_RESET 0x0001
-#define SK_MACARBCTL_UNRESET 0x0002
-#define SK_MACARBCTL_FASTOE_OFF 0x0004
-#define SK_MACARBCRL_FASTOE_ON 0x0008
-
-#define SK_RCINIT_XMAC_B2 54
-#define SK_RCINIT_XMAC_C1 0
-
-#define SK_RECOVERYCTL_RX1_OFF 0x0001
-#define SK_RECOVERYCTL_RX1_ON 0x0002
-#define SK_RECOVERYCTL_RX2_OFF 0x0004
-#define SK_RECOVERYCTL_RX2_ON 0x0008
-#define SK_RECOVERYCTL_TX1_OFF 0x0010
-#define SK_RECOVERYCTL_TX1_ON 0x0020
-#define SK_RECOVERYCTL_TX2_OFF 0x0040
-#define SK_RECOVERYCTL_TX2_ON 0x0080
-
-#define SK_RECOVERY_XMAC_B2 \
- (SK_RECOVERYCTL_RX1_ON|SK_RECOVERYCTL_RX2_ON| \
- SK_RECOVERYCTL_TX1_ON|SK_RECOVERYCTL_TX2_ON)
-
-#define SK_RECOVERY_XMAC_C1 \
- (SK_RECOVERYCTL_RX1_OFF|SK_RECOVERYCTL_RX2_OFF| \
- SK_RECOVERYCTL_TX1_OFF|SK_RECOVERYCTL_TX2_OFF)
-
-/* Block 4 -- TX Arbiter MAC 1 */
-#define SK_TXAR1_TIMERINIT 0x0200
-#define SK_TXAR1_TIMERVAL 0x0204
-#define SK_TXAR1_LIMITINIT 0x0208
-#define SK_TXAR1_LIMITCNT 0x020C
-#define SK_TXAR1_COUNTERCTL 0x0210
-#define SK_TXAR1_COUNTERTST 0x0212
-#define SK_TXAR1_COUNTERSTS 0x0212
-
-/* Block 5 -- TX Arbiter MAC 2 */
-#define SK_TXAR2_TIMERINIT 0x0280
-#define SK_TXAR2_TIMERVAL 0x0284
-#define SK_TXAR2_LIMITINIT 0x0288
-#define SK_TXAR2_LIMITCNT 0x028C
-#define SK_TXAR2_COUNTERCTL 0x0290
-#define SK_TXAR2_COUNTERTST 0x0291
-#define SK_TXAR2_COUNTERSTS 0x0292
-
-#define SK_TXARCTL_OFF 0x01
-#define SK_TXARCTL_ON 0x02
-#define SK_TXARCTL_RATECTL_OFF 0x04
-#define SK_TXARCTL_RATECTL_ON 0x08
-#define SK_TXARCTL_ALLOC_OFF 0x10
-#define SK_TXARCTL_ALLOC_ON 0x20
-#define SK_TXARCTL_FSYNC_OFF 0x40
-#define SK_TXARCTL_FSYNC_ON 0x80
-
-/* Block 6 -- External registers */
-#define SK_EXTREG_BASE 0x300
-#define SK_EXTREG_END 0x37C
-
-/* Block 7 -- PCI config registers */
-#define SK_PCI_BASE 0x0380
-#define SK_PCI_END 0x03FC
-
-/* Compute offset of mirrored PCI register */
-#define SK_PCI_REG(reg) ((reg) + SK_PCI_BASE)
-
-/* Block 8 -- RX queue 1 */
-#define SK_RXQ1_BUFCNT 0x0400
-#define SK_RXQ1_BUFCTL 0x0402
-#define SK_RXQ1_NEXTDESC 0x0404
-#define SK_RXQ1_RXBUF_LO 0x0408
-#define SK_RXQ1_RXBUF_HI 0x040C
-#define SK_RXQ1_RXSTAT 0x0410
-#define SK_RXQ1_TIMESTAMP 0x0414
-#define SK_RXQ1_CSUM1 0x0418
-#define SK_RXQ1_CSUM2 0x041A
-#define SK_RXQ1_CSUM1_START 0x041C
-#define SK_RXQ1_CSUM2_START 0x041E
-#define SK_RXQ1_CURADDR_LO 0x0420
-#define SK_RXQ1_CURADDR_HI 0x0424
-#define SK_RXQ1_CURCNT_LO 0x0428
-#define SK_RXQ1_CURCNT_HI 0x042C
-#define SK_RXQ1_CURBYTES 0x0430
-#define SK_RXQ1_BMU_CSR 0x0434
-#define SK_RXQ1_WATERMARK 0x0438
-#define SK_RXQ1_FLAG 0x043A
-#define SK_RXQ1_TEST1 0x043C
-#define SK_RXQ1_TEST2 0x0440
-#define SK_RXQ1_TEST3 0x0444
-
-/* Block 9 -- RX queue 2 */
-#define SK_RXQ2_BUFCNT 0x0480
-#define SK_RXQ2_BUFCTL 0x0482
-#define SK_RXQ2_NEXTDESC 0x0484
-#define SK_RXQ2_RXBUF_LO 0x0488
-#define SK_RXQ2_RXBUF_HI 0x048C
-#define SK_RXQ2_RXSTAT 0x0490
-#define SK_RXQ2_TIMESTAMP 0x0494
-#define SK_RXQ2_CSUM1 0x0498
-#define SK_RXQ2_CSUM2 0x049A
-#define SK_RXQ2_CSUM1_START 0x049C
-#define SK_RXQ2_CSUM2_START 0x049E
-#define SK_RXQ2_CURADDR_LO 0x04A0
-#define SK_RXQ2_CURADDR_HI 0x04A4
-#define SK_RXQ2_CURCNT_LO 0x04A8
-#define SK_RXQ2_CURCNT_HI 0x04AC
-#define SK_RXQ2_CURBYTES 0x04B0
-#define SK_RXQ2_BMU_CSR 0x04B4
-#define SK_RXQ2_WATERMARK 0x04B8
-#define SK_RXQ2_FLAG 0x04BA
-#define SK_RXQ2_TEST1 0x04BC
-#define SK_RXQ2_TEST2 0x04C0
-#define SK_RXQ2_TEST3 0x04C4
-
-#define SK_RXBMU_CLR_IRQ_ERR 0x00000001
-#define SK_RXBMU_CLR_IRQ_EOF 0x00000002
-#define SK_RXBMU_CLR_IRQ_EOB 0x00000004
-#define SK_RXBMU_CLR_IRQ_PAR 0x00000008
-#define SK_RXBMU_RX_START 0x00000010
-#define SK_RXBMU_RX_STOP 0x00000020
-#define SK_RXBMU_POLL_OFF 0x00000040
-#define SK_RXBMU_POLL_ON 0x00000080
-#define SK_RXBMU_TRANSFER_SM_RESET 0x00000100
-#define SK_RXBMU_TRANSFER_SM_UNRESET 0x00000200
-#define SK_RXBMU_DESCWR_SM_RESET 0x00000400
-#define SK_RXBMU_DESCWR_SM_UNRESET 0x00000800
-#define SK_RXBMU_DESCRD_SM_RESET 0x00001000
-#define SK_RXBMU_DESCRD_SM_UNRESET 0x00002000
-#define SK_RXBMU_SUPERVISOR_SM_RESET 0x00004000
-#define SK_RXBMU_SUPERVISOR_SM_UNRESET 0x00008000
-#define SK_RXBMU_PFI_SM_RESET 0x00010000
-#define SK_RXBMU_PFI_SM_UNRESET 0x00020000
-#define SK_RXBMU_FIFO_RESET 0x00040000
-#define SK_RXBMU_FIFO_UNRESET 0x00080000
-#define SK_RXBMU_DESC_RESET 0x00100000
-#define SK_RXBMU_DESC_UNRESET 0x00200000
-#define SK_RXBMU_SUPERVISOR_IDLE 0x01000000
-
-#define SK_RXBMU_ONLINE \
- (SK_RXBMU_TRANSFER_SM_UNRESET|SK_RXBMU_DESCWR_SM_UNRESET| \
- SK_RXBMU_DESCRD_SM_UNRESET|SK_RXBMU_SUPERVISOR_SM_UNRESET| \
- SK_RXBMU_PFI_SM_UNRESET|SK_RXBMU_FIFO_UNRESET| \
- SK_RXBMU_DESC_UNRESET)
-
-#define SK_RXBMU_OFFLINE \
- (SK_RXBMU_TRANSFER_SM_RESET|SK_RXBMU_DESCWR_SM_RESET| \
- SK_RXBMU_DESCRD_SM_RESET|SK_RXBMU_SUPERVISOR_SM_RESET| \
- SK_RXBMU_PFI_SM_RESET|SK_RXBMU_FIFO_RESET| \
- SK_RXBMU_DESC_RESET)
-
-/* Block 12 -- TX sync queue 1 */
-#define SK_TXQS1_BUFCNT 0x0600
-#define SK_TXQS1_BUFCTL 0x0602
-#define SK_TXQS1_NEXTDESC 0x0604
-#define SK_TXQS1_RXBUF_LO 0x0608
-#define SK_TXQS1_RXBUF_HI 0x060C
-#define SK_TXQS1_RXSTAT 0x0610
-#define SK_TXQS1_CSUM_STARTVAL 0x0614
-#define SK_TXQS1_CSUM_STARTPOS 0x0618
-#define SK_TXQS1_CSUM_WRITEPOS 0x061A
-#define SK_TXQS1_CURADDR_LO 0x0620
-#define SK_TXQS1_CURADDR_HI 0x0624
-#define SK_TXQS1_CURCNT_LO 0x0628
-#define SK_TXQS1_CURCNT_HI 0x062C
-#define SK_TXQS1_CURBYTES 0x0630
-#define SK_TXQS1_BMU_CSR 0x0634
-#define SK_TXQS1_WATERMARK 0x0638
-#define SK_TXQS1_FLAG 0x063A
-#define SK_TXQS1_TEST1 0x063C
-#define SK_TXQS1_TEST2 0x0640
-#define SK_TXQS1_TEST3 0x0644
-
-/* Block 13 -- TX async queue 1 */
-#define SK_TXQA1_BUFCNT 0x0680
-#define SK_TXQA1_BUFCTL 0x0682
-#define SK_TXQA1_NEXTDESC 0x0684
-#define SK_TXQA1_RXBUF_LO 0x0688
-#define SK_TXQA1_RXBUF_HI 0x068C
-#define SK_TXQA1_RXSTAT 0x0690
-#define SK_TXQA1_CSUM_STARTVAL 0x0694
-#define SK_TXQA1_CSUM_STARTPOS 0x0698
-#define SK_TXQA1_CSUM_WRITEPOS 0x069A
-#define SK_TXQA1_CURADDR_LO 0x06A0
-#define SK_TXQA1_CURADDR_HI 0x06A4
-#define SK_TXQA1_CURCNT_LO 0x06A8
-#define SK_TXQA1_CURCNT_HI 0x06AC
-#define SK_TXQA1_CURBYTES 0x06B0
-#define SK_TXQA1_BMU_CSR 0x06B4
-#define SK_TXQA1_WATERMARK 0x06B8
-#define SK_TXQA1_FLAG 0x06BA
-#define SK_TXQA1_TEST1 0x06BC
-#define SK_TXQA1_TEST2 0x06C0
-#define SK_TXQA1_TEST3 0x06C4
-
-/* Block 14 -- TX sync queue 2 */
-#define SK_TXQS2_BUFCNT 0x0700
-#define SK_TXQS2_BUFCTL 0x0702
-#define SK_TXQS2_NEXTDESC 0x0704
-#define SK_TXQS2_RXBUF_LO 0x0708
-#define SK_TXQS2_RXBUF_HI 0x070C
-#define SK_TXQS2_RXSTAT 0x0710
-#define SK_TXQS2_CSUM_STARTVAL 0x0714
-#define SK_TXQS2_CSUM_STARTPOS 0x0718
-#define SK_TXQS2_CSUM_WRITEPOS 0x071A
-#define SK_TXQS2_CURADDR_LO 0x0720
-#define SK_TXQS2_CURADDR_HI 0x0724
-#define SK_TXQS2_CURCNT_LO 0x0728
-#define SK_TXQS2_CURCNT_HI 0x072C
-#define SK_TXQS2_CURBYTES 0x0730
-#define SK_TXQS2_BMU_CSR 0x0734
-#define SK_TXQS2_WATERMARK 0x0738
-#define SK_TXQS2_FLAG 0x073A
-#define SK_TXQS2_TEST1 0x073C
-#define SK_TXQS2_TEST2 0x0740
-#define SK_TXQS2_TEST3 0x0744
-
-/* Block 15 -- TX async queue 2 */
-#define SK_TXQA2_BUFCNT 0x0780
-#define SK_TXQA2_BUFCTL 0x0782
-#define SK_TXQA2_NEXTDESC 0x0784
-#define SK_TXQA2_RXBUF_LO 0x0788
-#define SK_TXQA2_RXBUF_HI 0x078C
-#define SK_TXQA2_RXSTAT 0x0790
-#define SK_TXQA2_CSUM_STARTVAL 0x0794
-#define SK_TXQA2_CSUM_STARTPOS 0x0798
-#define SK_TXQA2_CSUM_WRITEPOS 0x079A
-#define SK_TXQA2_CURADDR_LO 0x07A0
-#define SK_TXQA2_CURADDR_HI 0x07A4
-#define SK_TXQA2_CURCNT_LO 0x07A8
-#define SK_TXQA2_CURCNT_HI 0x07AC
-#define SK_TXQA2_CURBYTES 0x07B0
-#define SK_TXQA2_BMU_CSR 0x07B4
-#define SK_TXQA2_WATERMARK 0x07B8
-#define SK_TXQA2_FLAG 0x07BA
-#define SK_TXQA2_TEST1 0x07BC
-#define SK_TXQA2_TEST2 0x07C0
-#define SK_TXQA2_TEST3 0x07C4
-
-#define SK_TXBMU_CLR_IRQ_ERR 0x00000001
-#define SK_TXBMU_CLR_IRQ_EOF 0x00000002
-#define SK_TXBMU_CLR_IRQ_EOB 0x00000004
-#define SK_TXBMU_TX_START 0x00000010
-#define SK_TXBMU_TX_STOP 0x00000020
-#define SK_TXBMU_POLL_OFF 0x00000040
-#define SK_TXBMU_POLL_ON 0x00000080
-#define SK_TXBMU_TRANSFER_SM_RESET 0x00000100
-#define SK_TXBMU_TRANSFER_SM_UNRESET 0x00000200
-#define SK_TXBMU_DESCWR_SM_RESET 0x00000400
-#define SK_TXBMU_DESCWR_SM_UNRESET 0x00000800
-#define SK_TXBMU_DESCRD_SM_RESET 0x00001000
-#define SK_TXBMU_DESCRD_SM_UNRESET 0x00002000
-#define SK_TXBMU_SUPERVISOR_SM_RESET 0x00004000
-#define SK_TXBMU_SUPERVISOR_SM_UNRESET 0x00008000
-#define SK_TXBMU_PFI_SM_RESET 0x00010000
-#define SK_TXBMU_PFI_SM_UNRESET 0x00020000
-#define SK_TXBMU_FIFO_RESET 0x00040000
-#define SK_TXBMU_FIFO_UNRESET 0x00080000
-#define SK_TXBMU_DESC_RESET 0x00100000
-#define SK_TXBMU_DESC_UNRESET 0x00200000
-#define SK_TXBMU_SUPERVISOR_IDLE 0x01000000
-
-#define SK_TXBMU_ONLINE \
- (SK_TXBMU_TRANSFER_SM_UNRESET|SK_TXBMU_DESCWR_SM_UNRESET| \
- SK_TXBMU_DESCRD_SM_UNRESET|SK_TXBMU_SUPERVISOR_SM_UNRESET| \
- SK_TXBMU_PFI_SM_UNRESET|SK_TXBMU_FIFO_UNRESET| \
- SK_TXBMU_DESC_UNRESET)
-
-#define SK_TXBMU_OFFLINE \
- (SK_TXBMU_TRANSFER_SM_RESET|SK_TXBMU_DESCWR_SM_RESET| \
- SK_TXBMU_DESCRD_SM_RESET|SK_TXBMU_SUPERVISOR_SM_RESET| \
- SK_TXBMU_PFI_SM_RESET|SK_TXBMU_FIFO_RESET| \
- SK_TXBMU_DESC_RESET)
-
-/* Block 16 -- Receive RAMbuffer 1 */
-#define SK_RXRB1_START 0x0800
-#define SK_RXRB1_END 0x0804
-#define SK_RXRB1_WR_PTR 0x0808
-#define SK_RXRB1_RD_PTR 0x080C
-#define SK_RXRB1_UTHR_PAUSE 0x0810
-#define SK_RXRB1_LTHR_PAUSE 0x0814
-#define SK_RXRB1_UTHR_HIPRIO 0x0818
-#define SK_RXRB1_UTHR_LOPRIO 0x081C
-#define SK_RXRB1_PKTCNT 0x0820
-#define SK_RXRB1_LVL 0x0824
-#define SK_RXRB1_CTLTST 0x0828
-
-/* Block 17 -- Receive RAMbuffer 2 */
-#define SK_RXRB2_START 0x0880
-#define SK_RXRB2_END 0x0884
-#define SK_RXRB2_WR_PTR 0x0888
-#define SK_RXRB2_RD_PTR 0x088C
-#define SK_RXRB2_UTHR_PAUSE 0x0890
-#define SK_RXRB2_LTHR_PAUSE 0x0894
-#define SK_RXRB2_UTHR_HIPRIO 0x0898
-#define SK_RXRB2_UTHR_LOPRIO 0x089C
-#define SK_RXRB2_PKTCNT 0x08A0
-#define SK_RXRB2_LVL 0x08A4
-#define SK_RXRB2_CTLTST 0x08A8
-
-/* Block 20 -- Sync. Transmit RAMbuffer 1 */
-#define SK_TXRBS1_START 0x0A00
-#define SK_TXRBS1_END 0x0A04
-#define SK_TXRBS1_WR_PTR 0x0A08
-#define SK_TXRBS1_RD_PTR 0x0A0C
-#define SK_TXRBS1_PKTCNT 0x0A20
-#define SK_TXRBS1_LVL 0x0A24
-#define SK_TXRBS1_CTLTST 0x0A28
-
-/* Block 21 -- Async. Transmit RAMbuffer 1 */
-#define SK_TXRBA1_START 0x0A80
-#define SK_TXRBA1_END 0x0A84
-#define SK_TXRBA1_WR_PTR 0x0A88
-#define SK_TXRBA1_RD_PTR 0x0A8C
-#define SK_TXRBA1_PKTCNT 0x0AA0
-#define SK_TXRBA1_LVL 0x0AA4
-#define SK_TXRBA1_CTLTST 0x0AA8
-
-/* Block 22 -- Sync. Transmit RAMbuffer 2 */
-#define SK_TXRBS2_START 0x0B00
-#define SK_TXRBS2_END 0x0B04
-#define SK_TXRBS2_WR_PTR 0x0B08
-#define SK_TXRBS2_RD_PTR 0x0B0C
-#define SK_TXRBS2_PKTCNT 0x0B20
-#define SK_TXRBS2_LVL 0x0B24
-#define SK_TXRBS2_CTLTST 0x0B28
-
-/* Block 23 -- Async. Transmit RAMbuffer 2 */
-#define SK_TXRBA2_START 0x0B80
-#define SK_TXRBA2_END 0x0B84
-#define SK_TXRBA2_WR_PTR 0x0B88
-#define SK_TXRBA2_RD_PTR 0x0B8C
-#define SK_TXRBA2_PKTCNT 0x0BA0
-#define SK_TXRBA2_LVL 0x0BA4
-#define SK_TXRBA2_CTLTST 0x0BA8
-
-#define SK_RBCTL_RESET 0x00000001
-#define SK_RBCTL_UNRESET 0x00000002
-#define SK_RBCTL_OFF 0x00000004
-#define SK_RBCTL_ON 0x00000008
-#define SK_RBCTL_STORENFWD_OFF 0x00000010
-#define SK_RBCTL_STORENFWD_ON 0x00000020
-
-/* Block 24 -- RX MAC FIFO 1 regisrers and LINK_SYNC counter */
-#define SK_RXF1_END 0x0C00
-#define SK_RXF1_WPTR 0x0C04
-#define SK_RXF1_RPTR 0x0C0C
-#define SK_RXF1_PKTCNT 0x0C10
-#define SK_RXF1_LVL 0x0C14
-#define SK_RXF1_MACCTL 0x0C18
-#define SK_RXF1_CTL 0x0C1C
-#define SK_RXLED1_CNTINIT 0x0C20
-#define SK_RXLED1_COUNTER 0x0C24
-#define SK_RXLED1_CTL 0x0C28
-#define SK_RXLED1_TST 0x0C29
-#define SK_LINK_SYNC1_CINIT 0x0C30
-#define SK_LINK_SYNC1_COUNTER 0x0C34
-#define SK_LINK_SYNC1_CTL 0x0C38
-#define SK_LINK_SYNC1_TST 0x0C39
-#define SK_LINKLED1_CTL 0x0C3C
-
-#define SK_FIFO_END 0x3F
-
-/* Block 25 -- RX MAC FIFO 2 regisrers and LINK_SYNC counter */
-#define SK_RXF2_END 0x0C80
-#define SK_RXF2_WPTR 0x0C84
-#define SK_RXF2_RPTR 0x0C8C
-#define SK_RXF2_PKTCNT 0x0C90
-#define SK_RXF2_LVL 0x0C94
-#define SK_RXF2_MACCTL 0x0C98
-#define SK_RXF2_CTL 0x0C9C
-#define SK_RXLED2_CNTINIT 0x0CA0
-#define SK_RXLED2_COUNTER 0x0CA4
-#define SK_RXLED2_CTL 0x0CA8
-#define SK_RXLED2_TST 0x0CA9
-#define SK_LINK_SYNC2_CINIT 0x0CB0
-#define SK_LINK_SYNC2_COUNTER 0x0CB4
-#define SK_LINK_SYNC2_CTL 0x0CB8
-#define SK_LINK_SYNC2_TST 0x0CB9
-#define SK_LINKLED2_CTL 0x0CBC
-
-#define SK_RXMACCTL_CLR_IRQ_NOSTS 0x00000001
-#define SK_RXMACCTL_CLR_IRQ_NOTSTAMP 0x00000002
-#define SK_RXMACCTL_TSTAMP_OFF 0x00000004
-#define SK_RXMACCTL_RSTAMP_ON 0x00000008
-#define SK_RXMACCTL_FLUSH_OFF 0x00000010
-#define SK_RXMACCTL_FLUSH_ON 0x00000020
-#define SK_RXMACCTL_PAUSE_OFF 0x00000040
-#define SK_RXMACCTL_PAUSE_ON 0x00000080
-#define SK_RXMACCTL_AFULL_OFF 0x00000100
-#define SK_RXMACCTL_AFULL_ON 0x00000200
-#define SK_RXMACCTL_VALIDTIME_PATCH_OFF 0x00000400
-#define SK_RXMACCTL_VALIDTIME_PATCH_ON 0x00000800
-#define SK_RXMACCTL_RXRDY_PATCH_OFF 0x00001000
-#define SK_RXMACCTL_RXRDY_PATCH_ON 0x00002000
-#define SK_RXMACCTL_STS_TIMEO 0x00FF0000
-#define SK_RXMACCTL_TSTAMP_TIMEO 0xFF000000
-
-#define SK_RXLEDCTL_ENABLE 0x0001
-#define SK_RXLEDCTL_COUNTER_STOP 0x0002
-#define SK_RXLEDCTL_COUNTER_START 0x0004
-
-#define SK_LINKLED_OFF 0x0001
-#define SK_LINKLED_ON 0x0002
-#define SK_LINKLED_LINKSYNC_OFF 0x0004
-#define SK_LINKLED_LINKSYNC_ON 0x0008
-#define SK_LINKLED_BLINK_OFF 0x0010
-#define SK_LINKLED_BLINK_ON 0x0020
-
-/* Block 26 -- TX MAC FIFO 1 regisrers */
-#define SK_TXF1_END 0x0D00
-#define SK_TXF1_WPTR 0x0D04
-#define SK_TXF1_RPTR 0x0D0C
-#define SK_TXF1_PKTCNT 0x0D10
-#define SK_TXF1_LVL 0x0D14
-#define SK_TXF1_MACCTL 0x0D18
-#define SK_TXF1_CTL 0x0D1C
-#define SK_TXLED1_CNTINIT 0x0D20
-#define SK_TXLED1_COUNTER 0x0D24
-#define SK_TXLED1_CTL 0x0D28
-#define SK_TXLED1_TST 0x0D29
-
-/* Block 27 -- TX MAC FIFO 2 regisrers */
-#define SK_TXF2_END 0x0D80
-#define SK_TXF2_WPTR 0x0D84
-#define SK_TXF2_RPTR 0x0D8C
-#define SK_TXF2_PKTCNT 0x0D90
-#define SK_TXF2_LVL 0x0D94
-#define SK_TXF2_MACCTL 0x0D98
-#define SK_TXF2_CTL 0x0D9C
-#define SK_TXLED2_CNTINIT 0x0DA0
-#define SK_TXLED2_COUNTER 0x0DA4
-#define SK_TXLED2_CTL 0x0DA8
-#define SK_TXLED2_TST 0x0DA9
-
-#define SK_TXMACCTL_XMAC_RESET 0x00000001
-#define SK_TXMACCTL_XMAC_UNRESET 0x00000002
-#define SK_TXMACCTL_LOOP_OFF 0x00000004
-#define SK_TXMACCTL_LOOP_ON 0x00000008
-#define SK_TXMACCTL_FLUSH_OFF 0x00000010
-#define SK_TXMACCTL_FLUSH_ON 0x00000020
-#define SK_TXMACCTL_WAITEMPTY_OFF 0x00000040
-#define SK_TXMACCTL_WAITEMPTY_ON 0x00000080
-#define SK_TXMACCTL_AFULL_OFF 0x00000100
-#define SK_TXMACCTL_AFULL_ON 0x00000200
-#define SK_TXMACCTL_TXRDY_PATCH_OFF 0x00000400
-#define SK_TXMACCTL_RXRDY_PATCH_ON 0x00000800
-#define SK_TXMACCTL_PKT_RECOVERY_OFF 0x00001000
-#define SK_TXMACCTL_PKT_RECOVERY_ON 0x00002000
-#define SK_TXMACCTL_CLR_IRQ_PERR 0x00008000
-#define SK_TXMACCTL_WAITAFTERFLUSH 0x00010000
-
-#define SK_TXLEDCTL_ENABLE 0x0001
-#define SK_TXLEDCTL_COUNTER_STOP 0x0002
-#define SK_TXLEDCTL_COUNTER_START 0x0004
-
-#define SK_FIFO_RESET 0x00000001
-#define SK_FIFO_UNRESET 0x00000002
-#define SK_FIFO_OFF 0x00000004
-#define SK_FIFO_ON 0x00000008
-
-/* Block 0x40 to 0x4F -- XMAC 1 registers */
-#define SK_XMAC1_BASE 0x2000
-#define SK_XMAC1_END 0x23FF
-
-/* Block 0x60 to 0x6F -- XMAC 2 registers */
-#define SK_XMAC2_BASE 0x3000
-#define SK_XMAC2_END 0x33FF
-
-/* Compute relative offset of an XMAC register in the XMAC window(s). */
-#define SK_XMAC_REG(reg, mac) (((reg) * 2) + SK_XMAC1_BASE + \
- (mac * (SK_XMAC2_BASE - SK_XMAC1_BASE)))
-
-#define SK_XM_READ_4(sc, reg) \
- (sk_win_read_2(sc->sk_softc, \
- SK_XMAC_REG(reg, sc->sk_port)) & 0xFFFF) | \
- ((sk_win_read_2(sc->sk_softc, \
- SK_XMAC_REG(reg + 2, sc->sk_port)) << 16) & 0xFFFF0000)
-
-#define SK_XM_WRITE_4(sc, reg, val) \
- sk_win_write_2(sc->sk_softc, \
- SK_XMAC_REG(reg, sc->sk_port), ((val) & 0xFFFF)); \
- sk_win_write_2(sc->sk_softc, \
- SK_XMAC_REG(reg + 2, sc->sk_port), ((val) >> 16) & 0xFFFF);
-
-#define SK_XM_READ_2(sc, reg) \
- sk_win_read_2(sc->sk_softc, SK_XMAC_REG(reg, sc->sk_port))
-
-#define SK_XM_WRITE_2(sc, reg, val) \
- sk_win_write_2(sc->sk_softc, SK_XMAC_REG(reg, sc->sk_port), val)
-
-#define SK_XM_SETBIT_4(sc, reg, x) \
- SK_XM_WRITE_4(sc, reg, (SK_XM_READ_4(sc, reg)) | (x))
-
-#define SK_XM_CLRBIT_4(sc, reg, x) \
- SK_XM_WRITE_4(sc, reg, (SK_XM_READ_4(sc, reg)) & ~(x))
-
-#define SK_XM_SETBIT_2(sc, reg, x) \
- SK_XM_WRITE_2(sc, reg, (SK_XM_READ_2(sc, reg)) | (x))
-
-#define SK_XM_CLRBIT_2(sc, reg, x) \
- SK_XM_WRITE_2(sc, reg, (SK_XM_READ_2(sc, reg)) & ~(x))
-
-
-/*
- * The default FIFO threshold on the XMAC II is 4 bytes. On
- * dual port NICs, this often leads to transmit underruns, so we
- * bump the threshold a little.
- */
-#define SK_XM_TX_FIFOTHRESH 512
-
-#define SK_PCI_VENDOR_ID 0x0000
-#define SK_PCI_DEVICE_ID 0x0002
-#define SK_PCI_COMMAND 0x0004
-#define SK_PCI_STATUS 0x0006
-#define SK_PCI_REVID 0x0008
-#define SK_PCI_CLASSCODE 0x0009
-#define SK_PCI_CACHELEN 0x000C
-#define SK_PCI_LATENCY_TIMER 0x000D
-#define SK_PCI_HEADER_TYPE 0x000E
-#define SK_PCI_LOMEM 0x0010
-#define SK_PCI_LOIO 0x0014
-#define SK_PCI_SUBVEN_ID 0x002C
-#define SK_PCI_SYBSYS_ID 0x002E
-#define SK_PCI_BIOSROM 0x0030
-#define SK_PCI_INTLINE 0x003C
-#define SK_PCI_INTPIN 0x003D
-#define SK_PCI_MINGNT 0x003E
-#define SK_PCI_MINLAT 0x003F
-
-/* device specific PCI registers */
-#define SK_PCI_OURREG1 0x0040
-#define SK_PCI_OURREG2 0x0044
-#define SK_PCI_CAPID 0x0048 /* 8 bits */
-#define SK_PCI_NEXTPTR 0x0049 /* 8 bits */
-#define SK_PCI_PWRMGMTCAP 0x004A /* 16 bits */
-#define SK_PCI_PWRMGMTCTRL 0x004C /* 16 bits */
-#define SK_PCI_PME_EVENT 0x004F
-#define SK_PCI_VPD_CAPID 0x0050
-#define SK_PCI_VPD_NEXTPTR 0x0051
-#define SK_PCI_VPD_ADDR 0x0052
-#define SK_PCI_VPD_DATA 0x0054
-
-#define SK_PSTATE_MASK 0x0003
-#define SK_PSTATE_D0 0x0000
-#define SK_PSTATE_D1 0x0001
-#define SK_PSTATE_D2 0x0002
-#define SK_PSTATE_D3 0x0003
-#define SK_PME_EN 0x0010
-#define SK_PME_STATUS 0x8000
-
-/*
- * VPD flag bit. Set to 0 to initiate a read, will become 1 when
- * read is complete. Set to 1 to initiate a write, will become 0
- * when write is finished.
- */
-#define SK_VPD_FLAG 0x8000
-
-/* VPD structures */
-struct vpd_res {
- u_int8_t vr_id;
- u_int8_t vr_len;
- u_int8_t vr_pad;
-};
-
-struct vpd_key {
- char vk_key[2];
- u_int8_t vk_len;
-};
-
-#define VPD_RES_ID 0x82 /* ID string */
-#define VPD_RES_READ 0x90 /* start of read only area */
-#define VPD_RES_WRITE 0x81 /* start of read/write area */
-#define VPD_RES_END 0x78 /* end tag */
-
-#define CSR_WRITE_4(sc, reg, val) \
- bus_space_write_4(sc->sk_btag, sc->sk_bhandle, reg, val)
-#define CSR_WRITE_2(sc, reg, val) \
- bus_space_write_2(sc->sk_btag, sc->sk_bhandle, reg, val)
-#define CSR_WRITE_1(sc, reg, val) \
- bus_space_write_1(sc->sk_btag, sc->sk_bhandle, reg, val)
-
-#define CSR_READ_4(sc, reg) \
- bus_space_read_4(sc->sk_btag, sc->sk_bhandle, reg)
-#define CSR_READ_2(sc, reg) \
- bus_space_read_2(sc->sk_btag, sc->sk_bhandle, reg)
-#define CSR_READ_1(sc, reg) \
- bus_space_read_1(sc->sk_btag, sc->sk_bhandle, reg)
-
-struct sk_type {
- u_int16_t sk_vid;
- u_int16_t sk_did;
- char *sk_name;
-};
-
-/* RX queue descriptor data structure */
-struct sk_rx_desc {
- u_int32_t sk_ctl;
- u_int32_t sk_next;
- u_int32_t sk_data_lo;
- u_int32_t sk_data_hi;
- u_int32_t sk_xmac_rxstat;
- u_int32_t sk_timestamp;
- u_int16_t sk_csum2;
- u_int16_t sk_csum1;
- u_int16_t sk_csum2_start;
- u_int16_t sk_csum1_start;
-};
-
-#define SK_OPCODE_DEFAULT 0x00550000
-#define SK_OPCODE_CSUM 0x00560000
-
-#define SK_RXCTL_LEN 0x0000FFFF
-#define SK_RXCTL_OPCODE 0x00FF0000
-#define SK_RXCTL_TSTAMP_VALID 0x01000000
-#define SK_RXCTL_STATUS_VALID 0x02000000
-#define SK_RXCTL_DEV0 0x04000000
-#define SK_RXCTL_EOF_INTR 0x08000000
-#define SK_RXCTL_EOB_INTR 0x10000000
-#define SK_RXCTL_LASTFRAG 0x20000000
-#define SK_RXCTL_FIRSTFRAG 0x40000000
-#define SK_RXCTL_OWN 0x80000000
-
-#define SK_RXSTAT \
- (SK_OPCODE_DEFAULT|SK_RXCTL_EOF_INTR|SK_RXCTL_LASTFRAG| \
- SK_RXCTL_FIRSTFRAG|SK_RXCTL_OWN)
-
-struct sk_tx_desc {
- u_int32_t sk_ctl;
- u_int32_t sk_next;
- u_int32_t sk_data_lo;
- u_int32_t sk_data_hi;
- u_int32_t sk_xmac_txstat;
- u_int16_t sk_rsvd0;
- u_int16_t sk_csum_startval;
- u_int16_t sk_csum_startpos;
- u_int16_t sk_csum_writepos;
- u_int32_t sk_rsvd1;
-};
-
-#define SK_TXCTL_LEN 0x0000FFFF
-#define SK_TXCTL_OPCODE 0x00FF0000
-#define SK_TXCTL_SW 0x01000000
-#define SK_TXCTL_NOCRC 0x02000000
-#define SK_TXCTL_STORENFWD 0x04000000
-#define SK_TXCTL_EOF_INTR 0x08000000
-#define SK_TXCTL_EOB_INTR 0x10000000
-#define SK_TXCTL_LASTFRAG 0x20000000
-#define SK_TXCTL_FIRSTFRAG 0x40000000
-#define SK_TXCTL_OWN 0x80000000
-
-#define SK_TXSTAT \
- (SK_OPCODE_DEFAULT|SK_TXCTL_EOF_INTR|SK_TXCTL_LASTFRAG|SK_TXCTL_OWN)
-
-#define SK_RXBYTES(x) (x) & 0x0000FFFF;
-#define SK_TXBYTES SK_RXBYTES
-
-#define SK_TX_RING_CNT 512
-#define SK_RX_RING_CNT 256
-
-/*
- * Jumbo buffer stuff. Note that we must allocate more jumbo
- * buffers than there are descriptors in the receive ring. This
- * is because we don't know how long it will take for a packet
- * to be released after we hand it off to the upper protocol
- * layers. To be safe, we allocate 1.5 times the number of
- * receive descriptors.
- */
-#define SK_JUMBO_FRAMELEN 9018
-#define SK_JUMBO_MTU (SK_JUMBO_FRAMELEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
-#define SK_JSLOTS 384
-
-#define SK_JRAWLEN (SK_JUMBO_FRAMELEN + ETHER_ALIGN)
-#define SK_JLEN (SK_JRAWLEN + (sizeof(u_int64_t) - \
- (SK_JRAWLEN % sizeof(u_int64_t))))
-#define SK_JPAGESZ PAGE_SIZE
-#define SK_RESID (SK_JPAGESZ - (SK_JLEN * SK_JSLOTS) % SK_JPAGESZ)
-#define SK_JMEM ((SK_JLEN * SK_JSLOTS) + SK_RESID)
-
-struct sk_jpool_entry {
- int slot;
- SLIST_ENTRY(sk_jpool_entry) jpool_entries;
-};
-
-struct sk_chain {
- void *sk_desc;
- struct mbuf *sk_mbuf;
- struct sk_chain *sk_next;
-};
-
-struct sk_chain_data {
- struct sk_chain sk_tx_chain[SK_TX_RING_CNT];
- struct sk_chain sk_rx_chain[SK_RX_RING_CNT];
- int sk_tx_prod;
- int sk_tx_cons;
- int sk_tx_cnt;
- int sk_rx_prod;
- int sk_rx_cons;
- int sk_rx_cnt;
- /* Stick the jumbo mem management stuff here too. */
- caddr_t sk_jslots[SK_JSLOTS];
- void *sk_jumbo_buf;
-
-};
-
-struct sk_ring_data {
- struct sk_tx_desc sk_tx_ring[SK_TX_RING_CNT];
- struct sk_rx_desc sk_rx_ring[SK_RX_RING_CNT];
-};
-
-struct sk_bcom_hack {
- int reg;
- int val;
-};
-
-#define SK_INC(x, y) (x) = (x + 1) % y
-
-/* Forward decl. */
-struct sk_if_softc;
-
-/* Softc for the GEnesis controller. */
-struct sk_softc {
- bus_space_handle_t sk_bhandle; /* bus space handle */
- bus_space_tag_t sk_btag; /* bus space tag */
- void *sk_intrhand; /* irq handler handle */
- struct resource *sk_irq; /* IRQ resource handle */
- struct resource *sk_res; /* I/O or shared mem handle */
- u_int8_t sk_unit; /* controller number */
- u_int8_t sk_type;
- char *sk_vpd_prodname;
- char *sk_vpd_readonly;
- u_int32_t sk_rboff; /* RAMbuffer offset */
- u_int32_t sk_ramsize; /* amount of RAM on NIC */
- u_int32_t sk_pmd; /* physical media type */
- u_int32_t sk_intrmask;
- struct sk_if_softc *sk_if[2];
- device_t sk_devs[2];
- struct mtx sk_mtx;
-};
-
-#define SK_LOCK(_sc) mtx_lock(&(_sc)->sk_mtx)
-#define SK_UNLOCK(_sc) mtx_unlock(&(_sc)->sk_mtx)
-#define SK_IF_LOCK(_sc) mtx_lock(&(_sc)->sk_softc->sk_mtx)
-#define SK_IF_UNLOCK(_sc) mtx_unlock(&(_sc)->sk_softc->sk_mtx)
-
-/* Softc for each logical interface */
-struct sk_if_softc {
- struct arpcom arpcom; /* interface info */
- device_t sk_miibus;
- u_int8_t sk_unit; /* interface number */
- u_int8_t sk_port; /* port # on controller */
- u_int8_t sk_xmac_rev; /* XMAC chip rev (B2 or C1) */
- u_int32_t sk_rx_ramstart;
- u_int32_t sk_rx_ramend;
- u_int32_t sk_tx_ramstart;
- u_int32_t sk_tx_ramend;
- int sk_phytype;
- int sk_phyaddr;
- device_t sk_dev;
- int sk_cnt;
- int sk_link;
- struct callout_handle sk_tick_ch;
- struct sk_chain_data sk_cdata;
- struct sk_ring_data *sk_rdata;
- struct sk_softc *sk_softc; /* parent controller */
- int sk_tx_bmu; /* TX BMU register */
- int sk_if_flags;
- SLIST_HEAD(__sk_jfreehead, sk_jpool_entry) sk_jfree_listhead;
- SLIST_HEAD(__sk_jinusehead, sk_jpool_entry) sk_jinuse_listhead;
-};
-
-#define SK_MAXUNIT 256
-#define SK_TIMEOUT 1000
-#define ETHER_ALIGN 2
-
-#ifdef __alpha__
-#undef vtophys
-#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)va)
-#endif
diff --git a/sys/dev/sk/xmaciireg.h b/sys/dev/sk/xmaciireg.h
deleted file mode 100644
index 137f47ee062b..000000000000
--- a/sys/dev/sk/xmaciireg.h
+++ /dev/null
@@ -1,403 +0,0 @@
-/*
- * Copyright (c) 1997, 1998, 1999, 2000
- * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-/*
- * Registers and data structures for the XaQti Corporation XMAC II
- * Gigabit Ethernet MAC. Datasheet is available from http://www.xaqti.com.
- * The XMAC can be programmed for 16-bit or 32-bit register access modes.
- * The SysKonnect gigabit ethernet adapters use 16-bit mode, so that's
- * how the registers are laid out here.
- */
-
-#define XM_DEVICEID 0x00E0AE20
-#define XM_XAQTI_OUI 0x00E0AE
-
-#define XM_XMAC_REV(x) (((x) & 0x000000E0) >> 5)
-
-#define XM_XMAC_REV_B2 0x0
-#define XM_XMAC_REV_C1 0x1
-
-#define XM_MMUCMD 0x0000
-#define XM_POFF 0x0008
-#define XM_BURST 0x000C
-#define XM_VLAN_TAGLEV1 0x0010
-#define XM_VLAN_TAGLEV2 0x0014
-#define XM_TXCMD 0x0020
-#define XM_TX_RETRYLIMIT 0x0024
-#define XM_TX_SLOTTIME 0x0028
-#define XM_TX_IPG 0x003C
-#define XM_RXCMD 0x0030
-#define XM_PHY_ADDR 0x0034
-#define XM_PHY_DATA 0x0038
-#define XM_GPIO 0x0040
-#define XM_IMR 0x0044
-#define XM_ISR 0x0048
-#define XM_HWCFG 0x004C
-#define XM_TX_LOWAT 0x0060
-#define XM_TX_HIWAT 0x0062
-#define XM_TX_REQTHRESH_LO 0x0064
-#define XM_TX_REQTHRESH_HI 0x0066
-#define XM_TX_REQTHRESH XM_TX_REQTHRESH_LO
-#define XM_PAUSEDST0 0x0068
-#define XM_PAUSEDST1 0x006A
-#define XM_PAUSEDST2 0x006C
-#define XM_CTLPARM_LO 0x0070
-#define XM_CTLPARM_HI 0x0072
-#define XM_CTLPARM XM_CTLPARM_LO
-#define XM_OPCODE_PAUSE_TIMER 0x0074
-#define XM_TXSTAT_LIFO 0x0078
-
-/*
- * Perfect filter registers. The XMAC has a table of 16 perfect
- * filter entries, spaced 8 bytes apart. This is in addition to
- * the station address registers, which appear below.
- */
-#define XM_RXFILT_BASE 0x0080
-#define XM_RXFILT_END 0x0107
-#define XM_RXFILT_MAX 16
-#define XM_RXFILT_ENTRY(ent) (XM_RXFILT_BASE + ((ent * 8)))
-
-/* Primary station address. */
-#define XM_PAR0 0x0108
-#define XM_PAR1 0x010A
-#define XM_PAR2 0x010C
-
-/* 64-bit multicast hash table registers */
-#define XM_MAR0 0x0110
-#define XM_MAR1 0x0112
-#define XM_MAR2 0x0114
-#define XM_MAR3 0x0116
-#define XM_RX_LOWAT 0x0118
-#define XM_RX_HIWAT 0x011A
-#define XM_RX_REQTHRESH_LO 0x011C
-#define XM_RX_REQTHRESH_HI 0x011E
-#define XM_RX_REQTHRESH XM_RX_REQTHRESH_LO
-#define XM_DEVID_LO 0x0120
-#define XM_DEVID_HI 0x0122
-#define XM_DEVID XM_DEVID_LO
-#define XM_MODE_LO 0x0124
-#define XM_MODE_HI 0x0126
-#define XM_MODE XM_MODE_LO
-#define XM_LASTSRC0 0x0128
-#define XM_LASTSRC1 0x012A
-#define XM_LASTSRC2 0x012C
-#define XM_TSTAMP_READ 0x0130
-#define XM_TSTAMP_LOAD 0x0134
-#define XM_STATS_CMD 0x0200
-#define XM_RXCNT_EVENT_LO 0x0204
-#define XM_RXCNT_EVENT_HI 0x0206
-#define XM_RXCNT_EVENT XM_RXCNT_EVENT_LO
-#define XM_TXCNT_EVENT_LO 0x0208
-#define XM_TXCNT_EVENT_HI 0x020A
-#define XM_TXCNT_EVENT XM_TXCNT_EVENT_LO
-#define XM_RXCNT_EVMASK_LO 0x020C
-#define XM_RXCNT_EVMASK_HI 0x020E
-#define XM_RXCNT_EVMASK XM_RXCNT_EVMASK_LO
-#define XM_TXCNT_EVMASK_LO 0x0210
-#define XM_TXCNT_EVMASK_HI 0x0212
-#define XM_TXCNT_EVMASK XM_TXCNT_EVMASK_LO
-
-/* Statistics command register */
-#define XM_STATCMD_CLR_TX 0x0001
-#define XM_STATCMD_CLR_RX 0x0002
-#define XM_STATCMD_COPY_TX 0x0004
-#define XM_STATCMD_COPY_RX 0x0008
-#define XM_STATCMD_SNAP_TX 0x0010
-#define XM_STATCMD_SNAP_RX 0x0020
-
-/* TX statistics registers */
-#define XM_TXSTATS_PKTSOK 0x280
-#define XM_TXSTATS_BYTESOK_HI 0x284
-#define XM_TXSTATS_BYTESOK_LO 0x288
-#define XM_TXSTATS_BCASTSOK 0x28C
-#define XM_TXSTATS_MCASTSOK 0x290
-#define XM_TXSTATS_UCASTSOK 0x294
-#define XM_TXSTATS_GIANTS 0x298
-#define XM_TXSTATS_BURSTCNT 0x29C
-#define XM_TXSTATS_PAUSEPKTS 0x2A0
-#define XM_TXSTATS_MACCTLPKTS 0x2A4
-#define XM_TXSTATS_SINGLECOLS 0x2A8
-#define XM_TXSTATS_MULTICOLS 0x2AC
-#define XM_TXSTATS_EXCESSCOLS 0x2B0
-#define XM_TXSTATS_LATECOLS 0x2B4
-#define XM_TXSTATS_DEFER 0x2B8
-#define XM_TXSTATS_EXCESSDEFER 0x2BC
-#define XM_TXSTATS_UNDERRUN 0x2C0
-#define XM_TXSTATS_CARRIERSENSE 0x2C4
-#define XM_TXSTATS_UTILIZATION 0x2C8
-#define XM_TXSTATS_64 0x2D0
-#define XM_TXSTATS_65_127 0x2D4
-#define XM_TXSTATS_128_255 0x2D8
-#define XM_TXSTATS_256_511 0x2DC
-#define XM_TXSTATS_512_1023 0x2E0
-#define XM_TXSTATS_1024_MAX 0x2E4
-
-/* RX statistics registers */
-#define XM_RXSTATS_PKTSOK 0x300
-#define XM_RXSTATS_BYTESOK_HI 0x304
-#define XM_RXSTATS_BYTESOK_LO 0x308
-#define XM_RXSTATS_BCASTSOK 0x30C
-#define XM_RXSTATS_MCASTSOK 0x310
-#define XM_RXSTATS_UCASTSOK 0x314
-#define XM_RXSTATS_PAUSEPKTS 0x318
-#define XM_RXSTATS_MACCTLPKTS 0x31C
-#define XM_RXSTATS_BADPAUSEPKTS 0x320
-#define XM_RXSTATS_BADMACCTLPKTS 0x324
-#define XM_RXSTATS_BURSTCNT 0x328
-#define XM_RXSTATS_MISSEDPKTS 0x32C
-#define XM_RXSTATS_FRAMEERRS 0x330
-#define XM_RXSTATS_OVERRUN 0x334
-#define XM_RXSTATS_JABBER 0x338
-#define XM_RXSTATS_CARRLOSS 0x33C
-#define XM_RXSTATS_INRNGLENERR 0x340
-#define XM_RXSTATS_SYMERR 0x344
-#define XM_RXSTATS_SHORTEVENT 0x348
-#define XM_RXSTATS_RUNTS 0x34C
-#define XM_RXSTATS_GIANTS 0x350
-#define XM_RXSTATS_CRCERRS 0x354
-#define XM_RXSTATS_CEXTERRS 0x35C
-#define XM_RXSTATS_UTILIZATION 0x360
-#define XM_RXSTATS_64 0x368
-#define XM_RXSTATS_65_127 0x36C
-#define XM_RXSTATS_128_255 0x370
-#define XM_RXSTATS_256_511 0x374
-#define XM_RXSTATS_512_1023 0x378
-#define XM_RXSTATS_1024_MAX 0x37C
-
-#define XM_MMUCMD_TX_ENB 0x0001
-#define XM_MMUCMD_RX_ENB 0x0002
-#define XM_MMUCMD_GMIILOOP 0x0004
-#define XM_MMUCMD_RATECTL 0x0008
-#define XM_MMUCMD_GMIIFDX 0x0010
-#define XM_MMUCMD_NO_MGMT_PRMB 0x0020
-#define XM_MMUCMD_SIMCOL 0x0040
-#define XM_MMUCMD_FORCETX 0x0080
-#define XM_MMUCMD_LOOPENB 0x0200
-#define XM_MMUCMD_IGNPAUSE 0x0400
-#define XM_MMUCMD_PHYBUSY 0x0800
-#define XM_MMUCMD_PHYDATARDY 0x1000
-
-#define XM_TXCMD_AUTOPAD 0x0001
-#define XM_TXCMD_NOCRC 0x0002
-#define XM_TXCMD_NOPREAMBLE 0x0004
-#define XM_TXCMD_NOGIGAMODE 0x0008
-#define XM_TXCMD_SAMPLELINE 0x0010
-#define XM_TXCMD_ENCBYPASS 0x0020
-#define XM_TXCMD_XMITBK2BK 0x0040
-#define XM_TXCMD_FAIRSHARE 0x0080
-
-#define XM_RXCMD_DISABLE_CEXT 0x0001
-#define XM_RXCMD_STRIPPAD 0x0002
-#define XM_RXCMD_SAMPLELINE 0x0004
-#define XM_RXCMD_SELFRX 0x0008
-#define XM_RXCMD_STRIPFCS 0x0010
-#define XM_RXCMD_TRANSPARENT 0x0020
-#define XM_RXCMD_IPGCAPTURE 0x0040
-#define XM_RXCMD_BIGPKTOK 0x0080
-#define XM_RXCMD_LENERROK 0x0100
-
-#define XM_GPIO_GP0_SET 0x0001
-#define XM_GPIO_RESETSTATS 0x0004
-#define XM_GPIO_RESETMAC 0x0008
-#define XM_GPIO_FORCEINT 0x0020
-#define XM_GPIO_ANEGINPROG 0x0040
-
-#define XM_IMR_RX_EOF 0x0001
-#define XM_IMR_TX_EOF 0x0002
-#define XM_IMR_TX_UNDERRUN 0x0004
-#define XM_IMR_RX_OVERRUN 0x0008
-#define XM_IMR_TX_STATS_OFLOW 0x0010
-#define XM_IMR_RX_STATS_OFLOW 0x0020
-#define XM_IMR_TSTAMP_OFLOW 0x0040
-#define XM_IMR_AUTONEG_DONE 0x0080
-#define XM_IMR_NEXTPAGE_RDY 0x0100
-#define XM_IMR_PAGE_RECEIVED 0x0200
-#define XM_IMR_LP_REQCFG 0x0400
-#define XM_IMR_GP0_SET 0x0800
-#define XM_IMR_FORCEINTR 0x1000
-#define XM_IMR_TX_ABORT 0x2000
-#define XM_IMR_LINKEVENT 0x4000
-
-#define XM_INTRS \
- (~(XM_IMR_GP0_SET|XM_IMR_AUTONEG_DONE|XM_IMR_TX_UNDERRUN))
-
-#define XM_ISR_RX_EOF 0x0001
-#define XM_ISR_TX_EOF 0x0002
-#define XM_ISR_TX_UNDERRUN 0x0004
-#define XM_ISR_RX_OVERRUN 0x0008
-#define XM_ISR_TX_STATS_OFLOW 0x0010
-#define XM_ISR_RX_STATS_OFLOW 0x0020
-#define XM_ISR_TSTAMP_OFLOW 0x0040
-#define XM_ISR_AUTONEG_DONE 0x0080
-#define XM_ISR_NEXTPAGE_RDY 0x0100
-#define XM_ISR_PAGE_RECEIVED 0x0200
-#define XM_ISR_LP_REQCFG 0x0400
-#define XM_ISR_GP0_SET 0x0800
-#define XM_ISR_FORCEINTR 0x1000
-#define XM_ISR_TX_ABORT 0x2000
-#define XM_ISR_LINKEVENT 0x4000
-
-#define XM_HWCFG_GENEOP 0x0008
-#define XM_HWCFG_SIGSTATCKH 0x0004
-#define XM_HWCFG_GMIIMODE 0x0001
-
-#define XM_MODE_FLUSH_RXFIFO 0x00000001
-#define XM_MODE_FLUSH_TXFIFO 0x00000002
-#define XM_MODE_BIGENDIAN 0x00000004
-#define XM_MODE_RX_PROMISC 0x00000008
-#define XM_MODE_RX_NOBROAD 0x00000010
-#define XM_MODE_RX_NOMULTI 0x00000020
-#define XM_MODE_RX_NOUNI 0x00000040
-#define XM_MODE_RX_BADFRAMES 0x00000080
-#define XM_MODE_RX_CRCERRS 0x00000100
-#define XM_MODE_RX_GIANTS 0x00000200
-#define XM_MODE_RX_INRANGELEN 0x00000400
-#define XM_MODE_RX_RUNTS 0x00000800
-#define XM_MODE_RX_MACCTL 0x00001000
-#define XM_MODE_RX_USE_PERFECT 0x00002000
-#define XM_MODE_RX_USE_STATION 0x00004000
-#define XM_MODE_RX_USE_HASH 0x00008000
-#define XM_MODE_RX_ADDRPAIR 0x00010000
-#define XM_MODE_PAUSEONHI 0x00020000
-#define XM_MODE_PAUSEONLO 0x00040000
-#define XM_MODE_TIMESTAMP 0x00080000
-#define XM_MODE_SENDPAUSE 0x00100000
-#define XM_MODE_SENDCONTINUOUS 0x00200000
-#define XM_MODE_LE_STATUSWORD 0x00400000
-#define XM_MODE_AUTOFIFOPAUSE 0x00800000
-#define XM_MODE_EXPAUSEGEN 0x02000000
-#define XM_MODE_RX_INVERSE 0x04000000
-
-#define XM_RXSTAT_MACCTL 0x00000001
-#define XM_RXSTAT_ERRFRAME 0x00000002
-#define XM_RXSTAT_CRCERR 0x00000004
-#define XM_RXSTAT_GIANT 0x00000008
-#define XM_RXSTAT_RUNT 0x00000010
-#define XM_RXSTAT_FRAMEERR 0x00000020
-#define XM_RXSTAT_INRANGEERR 0x00000040
-#define XM_RXSTAT_CARRIERERR 0x00000080
-#define XM_RXSTAT_COLLERR 0x00000100
-#define XM_RXSTAT_802_3 0x00000200
-#define XM_RXSTAT_CARREXTERR 0x00000400
-#define XM_RXSTAT_BURSTMODE 0x00000800
-#define XM_RXSTAT_UNICAST 0x00002000
-#define XM_RXSTAT_MULTICAST 0x00004000
-#define XM_RXSTAT_BROADCAST 0x00008000
-#define XM_RXSTAT_VLAN_LEV1 0x00010000
-#define XM_RXSTAT_VLAN_LEV2 0x00020000
-#define XM_RXSTAT_LEN 0xFFFC0000
-
-/*
- * XMAC PHY registers, indirectly accessed through
- * XM_PHY_ADDR and XM_PHY_REG.
- */
-
-#define XM_PHY_BMCR 0x0000 /* control */
-#define XM_PHY_BMSR 0x0001 /* status */
-#define XM_PHY_VENID 0x0002 /* vendor id */
-#define XM_PHY_DEVID 0x0003 /* device id */
-#define XM_PHY_ANAR 0x0004 /* autoneg advertisenemt */
-#define XM_PHY_LPAR 0x0005 /* link partner ability */
-#define XM_PHY_ANEXP 0x0006 /* autoneg expansion */
-#define XM_PHY_NEXTP 0x0007 /* nextpage */
-#define XM_PHY_LPNEXTP 0x0008 /* link partner's nextpage */
-#define XM_PHY_EXTSTS 0x000F /* extented status */
-#define XM_PHY_RESAB 0x0010 /* resolved ability */
-
-#define XM_BMCR_DUPLEX 0x0100
-#define XM_BMCR_RENEGOTIATE 0x0200
-#define XM_BMCR_AUTONEGENBL 0x1000
-#define XM_BMCR_LOOPBACK 0x4000
-#define XM_BMCR_RESET 0x8000
-
-#define XM_BMSR_EXTCAP 0x0001
-#define XM_BMSR_LINKSTAT 0x0004
-#define XM_BMSR_AUTONEGABLE 0x0008
-#define XM_BMSR_REMFAULT 0x0010
-#define XM_BMSR_AUTONEGDONE 0x0020
-#define XM_BMSR_EXTSTAT 0x0100
-
-#define XM_VENID_XAQTI 0xD14C
-#define XM_DEVID_XMAC 0x0002
-
-#define XM_ANAR_FULLDUPLEX 0x0020
-#define XM_ANAR_HALFDUPLEX 0x0040
-#define XM_ANAR_PAUSEBITS 0x0180
-#define XM_ANAR_REMFAULTBITS 0x1800
-#define XM_ANAR_ACK 0x4000
-#define XM_ANAR_NEXTPAGE 0x8000
-
-#define XM_LPAR_FULLDUPLEX 0x0020
-#define XM_LPAR_HALFDUPLEX 0x0040
-#define XM_LPAR_PAUSEBITS 0x0180
-#define XM_LPAR_REMFAULTBITS 0x1800
-#define XM_LPAR_ACK 0x4000
-#define XM_LPAR_NEXTPAGE 0x8000
-
-#define XM_PAUSE_NOPAUSE 0x0000
-#define XM_PAUSE_SYMPAUSE 0x0080
-#define XM_PAUSE_ASYMPAUSE 0x0100
-#define XM_PAUSE_BOTH 0x0180
-
-#define XM_REMFAULT_LINKOK 0x0000
-#define XM_REMFAULT_LINKFAIL 0x0800
-#define XM_REMFAULT_OFFLINE 0x1000
-#define XM_REMFAULT_ANEGERR 0x1800
-
-#define XM_ANEXP_GOTPAGE 0x0002
-#define XM_ANEXP_NEXTPAGE_SELF 0x0004
-#define XM_ANEXP_NEXTPAGE_LP 0x0008
-
-#define XM_NEXTP_MESSAGE 0x07FF
-#define XM_NEXTP_TOGGLE 0x0800
-#define XM_NEXTP_ACK2 0x1000
-#define XM_NEXTP_MPAGE 0x2000
-#define XM_NEXTP_ACK1 0x4000
-#define XM_NEXTP_NPAGE 0x8000
-
-#define XM_LPNEXTP_MESSAGE 0x07FF
-#define XM_LPNEXTP_TOGGLE 0x0800
-#define XM_LPNEXTP_ACK2 0x1000
-#define XM_LPNEXTP_MPAGE 0x2000
-#define XM_LPNEXTP_ACK1 0x4000
-#define XM_LPNEXTP_NPAGE 0x8000
-
-#define XM_EXTSTS_HALFDUPLEX 0x4000
-#define XM_EXTSTS_FULLDUPLEX 0x8000
-
-#define XM_RESAB_PAUSEMISMATCH 0x0008
-#define XM_RESAB_ABLMISMATCH 0x0010
-#define XM_RESAB_FDMODESEL 0x0020
-#define XM_RESAB_HDMODESEL 0x0040
-#define XM_RESAB_PAUSEBITS 0x0180
diff --git a/sys/dev/speaker/speaker.h b/sys/dev/speaker/speaker.h
deleted file mode 100644
index 6b1f0211e516..000000000000
--- a/sys/dev/speaker/speaker.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * speaker.h -- interface definitions for speaker ioctl()
- *
- * v1.4 by Eric S. Raymond (esr@snark.thyrsus.com) Aug 1993
- * modified for FreeBSD by Andrew A. Chernov <ache@astral.msk.su>
- *
- * $FreeBSD$
- */
-
-#ifndef _MACHINE_SPEAKER_H_
-#define _MACHINE_SPEAKER_H_
-
-#include <sys/ioccom.h>
-
-#define SPKRTONE _IOW('S', 1, tone_t) /* emit tone */
-#define SPKRTUNE _IO('S', 2) /* emit tone sequence*/
-
-typedef struct
-{
- int frequency; /* in hertz */
- int duration; /* in 1/100ths of a second */
-} tone_t;
-
-/*
- * Strings written to the speaker device are interpreted as tunes and played;
- * see the spkr(4) man page for details.
- */
-
-#endif /* !_MACHINE_SPEAKER_H_ */
diff --git a/sys/dev/speaker/spkr.c b/sys/dev/speaker/spkr.c
deleted file mode 100644
index f51f4609a4cb..000000000000
--- a/sys/dev/speaker/spkr.c
+++ /dev/null
@@ -1,683 +0,0 @@
-/*
- * spkr.c -- device driver for console speaker
- *
- * v1.4 by Eric S. Raymond (esr@snark.thyrsus.com) Aug 1993
- * modified for FreeBSD by Andrew A. Chernov <ache@astral.msk.su>
- * modified for PC98 by Kakefuda
- *
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/kernel.h>
-#include <sys/module.h>
-#include <sys/uio.h>
-#include <sys/conf.h>
-#include <sys/ctype.h>
-#include <sys/malloc.h>
-#include <isa/isavar.h>
-#ifdef PC98
-#include <pc98/pc98/pc98.h>
-#else
-#include <i386/isa/isa.h>
-#endif
-#include <i386/isa/timerreg.h>
-#include <machine/clock.h>
-#include <machine/speaker.h>
-
-static d_open_t spkropen;
-static d_close_t spkrclose;
-static d_write_t spkrwrite;
-static d_ioctl_t spkrioctl;
-
-#define CDEV_MAJOR 26
-static struct cdevsw spkr_cdevsw = {
- .d_open = spkropen,
- .d_close = spkrclose,
- .d_write = spkrwrite,
- .d_ioctl = spkrioctl,
- .d_name = "spkr",
- .d_maj = CDEV_MAJOR,
-};
-
-static MALLOC_DEFINE(M_SPKR, "spkr", "Speaker buffer");
-
-/**************** MACHINE DEPENDENT PART STARTS HERE *************************
- *
- * This section defines a function tone() which causes a tone of given
- * frequency and duration from the ISA console speaker.
- * Another function endtone() is defined to force sound off, and there is
- * also a rest() entry point to do pauses.
- *
- * Audible sound is generated using the Programmable Interval Timer (PIT) and
- * Programmable Peripheral Interface (PPI) attached to the ISA speaker. The
- * PPI controls whether sound is passed through at all; the PIT's channel 2 is
- * used to generate clicks (a square wave) of whatever frequency is desired.
- */
-
-/*
- * XXX PPI control values should be in a header and used in clock.c.
- */
-#ifdef PC98
-#define SPKR_DESC "PC98 speaker"
-#define PPI_SPKR 0x08 /* turn these PPI bits on to pass sound */
-#define PIT_COUNT 0x3fdb /* PIT count address */
-
-#define SPEAKER_ON outb(IO_PPI, inb(IO_PPI) & ~PPI_SPKR)
-#define SPEAKER_OFF outb(IO_PPI, inb(IO_PPI) | PPI_SPKR)
-#define TIMER_ACQUIRE acquire_timer1(TIMER_SEL1 | TIMER_SQWAVE | TIMER_16BIT)
-#define TIMER_RELEASE release_timer1()
-#define SPEAKER_WRITE(val) { \
- outb(PIT_COUNT, (val & 0xff)); \
- outb(PIT_COUNT, (val >> 8)); \
- }
-#else
-#define SPKR_DESC "PC speaker"
-#define PPI_SPKR 0x03 /* turn these PPI bits on to pass sound */
-
-#define SPEAKER_ON outb(IO_PPI, inb(IO_PPI) | PPI_SPKR)
-#define SPEAKER_OFF outb(IO_PPI, inb(IO_PPI) & ~PPI_SPKR)
-#define TIMER_ACQUIRE acquire_timer2(TIMER_SEL2 | TIMER_SQWAVE | TIMER_16BIT)
-#define TIMER_RELEASE release_timer2()
-#define SPEAKER_WRITE(val) { \
- outb(TIMER_CNTR2, (val & 0xff)); \
- outb(TIMER_CNTR2, (val >> 8)); \
- }
-#endif
-
-#define SPKRPRI PSOCK
-static char endtone, endrest;
-
-static void tone(unsigned int thz, unsigned int ticks);
-static void rest(int ticks);
-static void playinit(void);
-static void playtone(int pitch, int value, int sustain);
-static void playstring(char *cp, size_t slen);
-
-/* emit tone of frequency thz for given number of ticks */
-static void
-tone(thz, ticks)
- unsigned int thz, ticks;
-{
- unsigned int divisor;
- int sps;
-
- if (thz <= 0)
- return;
-
- divisor = timer_freq / thz;
-
-#ifdef DEBUG
- (void) printf("tone: thz=%d ticks=%d\n", thz, ticks);
-#endif /* DEBUG */
-
- /* set timer to generate clicks at given frequency in Hertz */
- sps = splclock();
-
- if (TIMER_ACQUIRE) {
- /* enter list of waiting procs ??? */
- splx(sps);
- return;
- }
- splx(sps);
- disable_intr();
- SPEAKER_WRITE(divisor);
- enable_intr();
-
- /* turn the speaker on */
- SPEAKER_ON;
-
- /*
- * Set timeout to endtone function, then give up the timeslice.
- * This is so other processes can execute while the tone is being
- * emitted.
- */
- if (ticks > 0)
- tsleep(&endtone, SPKRPRI | PCATCH, "spkrtn", ticks);
- SPEAKER_OFF;
- sps = splclock();
- TIMER_RELEASE;
- splx(sps);
-}
-
-/* rest for given number of ticks */
-static void
-rest(ticks)
- int ticks;
-{
- /*
- * Set timeout to endrest function, then give up the timeslice.
- * This is so other processes can execute while the rest is being
- * waited out.
- */
-#ifdef DEBUG
- (void) printf("rest: %d\n", ticks);
-#endif /* DEBUG */
- if (ticks > 0)
- tsleep(&endrest, SPKRPRI | PCATCH, "spkrrs", ticks);
-}
-
-/**************** PLAY STRING INTERPRETER BEGINS HERE **********************
- *
- * Play string interpretation is modelled on IBM BASIC 2.0's PLAY statement;
- * M[LNS] are missing; the ~ synonym and the _ slur mark and the octave-
- * tracking facility are added.
- * Requires tone(), rest(), and endtone(). String play is not interruptible
- * except possibly at physical block boundaries.
- */
-
-typedef int bool;
-#define TRUE 1
-#define FALSE 0
-
-#define dtoi(c) ((c) - '0')
-
-static int octave; /* currently selected octave */
-static int whole; /* whole-note time at current tempo, in ticks */
-static int value; /* whole divisor for note time, quarter note = 1 */
-static int fill; /* controls spacing of notes */
-static bool octtrack; /* octave-tracking on? */
-static bool octprefix; /* override current octave-tracking state? */
-
-/*
- * Magic number avoidance...
- */
-#define SECS_PER_MIN 60 /* seconds per minute */
-#define WHOLE_NOTE 4 /* quarter notes per whole note */
-#define MIN_VALUE 64 /* the most we can divide a note by */
-#define DFLT_VALUE 4 /* default value (quarter-note) */
-#define FILLTIME 8 /* for articulation, break note in parts */
-#define STACCATO 6 /* 6/8 = 3/4 of note is filled */
-#define NORMAL 7 /* 7/8ths of note interval is filled */
-#define LEGATO 8 /* all of note interval is filled */
-#define DFLT_OCTAVE 4 /* default octave */
-#define MIN_TEMPO 32 /* minimum tempo */
-#define DFLT_TEMPO 120 /* default tempo */
-#define MAX_TEMPO 255 /* max tempo */
-#define NUM_MULT 3 /* numerator of dot multiplier */
-#define DENOM_MULT 2 /* denominator of dot multiplier */
-
-/* letter to half-tone: A B C D E F G */
-static int notetab[8] = {9, 11, 0, 2, 4, 5, 7};
-
-/*
- * This is the American Standard A440 Equal-Tempered scale with frequencies
- * rounded to nearest integer. Thank Goddess for the good ol' CRC Handbook...
- * our octave 0 is standard octave 2.
- */
-#define OCTAVE_NOTES 12 /* semitones per octave */
-static int pitchtab[] =
-{
-/* C C# D D# E F F# G G# A A# B*/
-/* 0 */ 65, 69, 73, 78, 82, 87, 93, 98, 103, 110, 117, 123,
-/* 1 */ 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247,
-/* 2 */ 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494,
-/* 3 */ 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988,
-/* 4 */ 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1975,
-/* 5 */ 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951,
-/* 6 */ 4186, 4435, 4698, 4978, 5274, 5588, 5920, 6272, 6644, 7040, 7459, 7902,
-};
-
-static void
-playinit()
-{
- octave = DFLT_OCTAVE;
- whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / DFLT_TEMPO;
- fill = NORMAL;
- value = DFLT_VALUE;
- octtrack = FALSE;
- octprefix = TRUE; /* act as though there was an initial O(n) */
-}
-
-/* play tone of proper duration for current rhythm signature */
-static void
-playtone(pitch, value, sustain)
- int pitch, value, sustain;
-{
- register int sound, silence, snum = 1, sdenom = 1;
-
- /* this weirdness avoids floating-point arithmetic */
- for (; sustain; sustain--)
- {
- /* See the BUGS section in the man page for discussion */
- snum *= NUM_MULT;
- sdenom *= DENOM_MULT;
- }
-
- if (value == 0 || sdenom == 0)
- return;
-
- if (pitch == -1)
- rest(whole * snum / (value * sdenom));
- else
- {
- sound = (whole * snum) / (value * sdenom)
- - (whole * (FILLTIME - fill)) / (value * FILLTIME);
- silence = whole * (FILLTIME-fill) * snum / (FILLTIME * value * sdenom);
-
-#ifdef DEBUG
- (void) printf("playtone: pitch %d for %d ticks, rest for %d ticks\n",
- pitch, sound, silence);
-#endif /* DEBUG */
-
- tone(pitchtab[pitch], sound);
- if (fill != LEGATO)
- rest(silence);
- }
-}
-
-/* interpret and play an item from a notation string */
-static void
-playstring(cp, slen)
- char *cp;
- size_t slen;
-{
- int pitch, oldfill, lastpitch = OCTAVE_NOTES * DFLT_OCTAVE;
-
-#define GETNUM(cp, v) for(v=0; isdigit(cp[1]) && slen > 0; ) \
- {v = v * 10 + (*++cp - '0'); slen--;}
- for (; slen--; cp++)
- {
- int sustain, timeval, tempo;
- register char c = toupper(*cp);
-
-#ifdef DEBUG
- (void) printf("playstring: %c (%x)\n", c, c);
-#endif /* DEBUG */
-
- switch (c)
- {
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
-
- /* compute pitch */
- pitch = notetab[c - 'A'] + octave * OCTAVE_NOTES;
-
- /* this may be followed by an accidental sign */
- if (cp[1] == '#' || cp[1] == '+')
- {
- ++pitch;
- ++cp;
- slen--;
- }
- else if (cp[1] == '-')
- {
- --pitch;
- ++cp;
- slen--;
- }
-
- /*
- * If octave-tracking mode is on, and there has been no octave-
- * setting prefix, find the version of the current letter note
- * closest to the last regardless of octave.
- */
- if (octtrack && !octprefix)
- {
- if (abs(pitch-lastpitch) > abs(pitch+OCTAVE_NOTES-lastpitch))
- {
- ++octave;
- pitch += OCTAVE_NOTES;
- }
-
- if (abs(pitch-lastpitch) > abs((pitch-OCTAVE_NOTES)-lastpitch))
- {
- --octave;
- pitch -= OCTAVE_NOTES;
- }
- }
- octprefix = FALSE;
- lastpitch = pitch;
-
- /* ...which may in turn be followed by an override time value */
- GETNUM(cp, timeval);
- if (timeval <= 0 || timeval > MIN_VALUE)
- timeval = value;
-
- /* ...and/or sustain dots */
- for (sustain = 0; cp[1] == '.'; cp++)
- {
- slen--;
- sustain++;
- }
-
- /* ...and/or a slur mark */
- oldfill = fill;
- if (cp[1] == '_')
- {
- fill = LEGATO;
- ++cp;
- slen--;
- }
-
- /* time to emit the actual tone */
- playtone(pitch, timeval, sustain);
-
- fill = oldfill;
- break;
-
- case 'O':
- if (cp[1] == 'N' || cp[1] == 'n')
- {
- octprefix = octtrack = FALSE;
- ++cp;
- slen--;
- }
- else if (cp[1] == 'L' || cp[1] == 'l')
- {
- octtrack = TRUE;
- ++cp;
- slen--;
- }
- else
- {
- GETNUM(cp, octave);
- if (octave >= sizeof(pitchtab) / sizeof(pitchtab[0]) / OCTAVE_NOTES)
- octave = DFLT_OCTAVE;
- octprefix = TRUE;
- }
- break;
-
- case '>':
- if (octave < sizeof(pitchtab) / sizeof(pitchtab[0]) / OCTAVE_NOTES - 1)
- octave++;
- octprefix = TRUE;
- break;
-
- case '<':
- if (octave > 0)
- octave--;
- octprefix = TRUE;
- break;
-
- case 'N':
- GETNUM(cp, pitch);
- for (sustain = 0; cp[1] == '.'; cp++)
- {
- slen--;
- sustain++;
- }
- oldfill = fill;
- if (cp[1] == '_')
- {
- fill = LEGATO;
- ++cp;
- slen--;
- }
- playtone(pitch - 1, value, sustain);
- fill = oldfill;
- break;
-
- case 'L':
- GETNUM(cp, value);
- if (value <= 0 || value > MIN_VALUE)
- value = DFLT_VALUE;
- break;
-
- case 'P':
- case '~':
- /* this may be followed by an override time value */
- GETNUM(cp, timeval);
- if (timeval <= 0 || timeval > MIN_VALUE)
- timeval = value;
- for (sustain = 0; cp[1] == '.'; cp++)
- {
- slen--;
- sustain++;
- }
- playtone(-1, timeval, sustain);
- break;
-
- case 'T':
- GETNUM(cp, tempo);
- if (tempo < MIN_TEMPO || tempo > MAX_TEMPO)
- tempo = DFLT_TEMPO;
- whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / tempo;
- break;
-
- case 'M':
- if (cp[1] == 'N' || cp[1] == 'n')
- {
- fill = NORMAL;
- ++cp;
- slen--;
- }
- else if (cp[1] == 'L' || cp[1] == 'l')
- {
- fill = LEGATO;
- ++cp;
- slen--;
- }
- else if (cp[1] == 'S' || cp[1] == 's')
- {
- fill = STACCATO;
- ++cp;
- slen--;
- }
- break;
- }
- }
-}
-
-/******************* UNIX DRIVER HOOKS BEGIN HERE **************************
- *
- * This section implements driver hooks to run playstring() and the tone(),
- * endtone(), and rest() functions defined above.
- */
-
-static int spkr_active = FALSE; /* exclusion flag */
-static char *spkr_inbuf; /* incoming buf */
-
-static int
-spkropen(dev, flags, fmt, td)
- dev_t dev;
- int flags;
- int fmt;
- struct thread *td;
-{
-#ifdef DEBUG
- (void) printf("spkropen: entering with dev = %s\n", devtoname(dev));
-#endif /* DEBUG */
-
- if (minor(dev) != 0)
- return(ENXIO);
- else if (spkr_active)
- return(EBUSY);
- else
- {
-#ifdef DEBUG
- (void) printf("spkropen: about to perform play initialization\n");
-#endif /* DEBUG */
- playinit();
- spkr_inbuf = malloc(DEV_BSIZE, M_SPKR, M_WAITOK);
- spkr_active = TRUE;
- return(0);
- }
-}
-
-static int
-spkrwrite(dev, uio, ioflag)
- dev_t dev;
- struct uio *uio;
- int ioflag;
-{
-#ifdef DEBUG
- printf("spkrwrite: entering with dev = %s, count = %d\n",
- devtoname(dev), uio->uio_resid);
-#endif /* DEBUG */
-
- if (minor(dev) != 0)
- return(ENXIO);
- else if (uio->uio_resid > (DEV_BSIZE - 1)) /* prevent system crashes */
- return(E2BIG);
- else
- {
- unsigned n;
- char *cp;
- int error;
-
- n = uio->uio_resid;
- cp = spkr_inbuf;
- error = uiomove(cp, n, uio);
- if (!error) {
- cp[n] = '\0';
- playstring(cp, n);
- }
- return(error);
- }
-}
-
-static int
-spkrclose(dev, flags, fmt, td)
- dev_t dev;
- int flags;
- int fmt;
- struct thread *td;
-{
-#ifdef DEBUG
- (void) printf("spkrclose: entering with dev = %s\n", devtoname(dev));
-#endif /* DEBUG */
-
- if (minor(dev) != 0)
- return(ENXIO);
- else
- {
- wakeup(&endtone);
- wakeup(&endrest);
- free(spkr_inbuf, M_SPKR);
- spkr_active = FALSE;
- return(0);
- }
-}
-
-static int
-spkrioctl(dev, cmd, cmdarg, flags, td)
- dev_t dev;
- unsigned long cmd;
- caddr_t cmdarg;
- int flags;
- struct thread *td;
-{
-#ifdef DEBUG
- (void) printf("spkrioctl: entering with dev = %s, cmd = %lx\n",
- devtoname(dev), cmd);
-#endif /* DEBUG */
-
- if (minor(dev) != 0)
- return(ENXIO);
- else if (cmd == SPKRTONE)
- {
- tone_t *tp = (tone_t *)cmdarg;
-
- if (tp->frequency == 0)
- rest(tp->duration);
- else
- tone(tp->frequency, tp->duration);
- return 0;
- }
- else if (cmd == SPKRTUNE)
- {
- tone_t *tp = (tone_t *)(*(caddr_t *)cmdarg);
- tone_t ttp;
- int error;
-
- for (; ; tp++) {
- error = copyin(tp, &ttp, sizeof(tone_t));
- if (error)
- return(error);
- if (ttp.duration == 0)
- break;
- if (ttp.frequency == 0)
- rest(ttp.duration);
- else
- tone(ttp.frequency, ttp.duration);
- }
- return(0);
- }
- return(EINVAL);
-}
-
-/*
- * Install placeholder to claim the resources owned by the
- * AT tone generator.
- */
-static struct isa_pnp_id speaker_ids[] = {
-#ifndef PC98
- { 0x0008d041 /* PNP0800 */, SPKR_DESC },
-#endif
- { 0 }
-};
-
-static dev_t speaker_dev;
-
-static int
-speaker_probe(device_t dev)
-{
- int error;
-
- error = ISA_PNP_PROBE(device_get_parent(dev), dev, speaker_ids);
-
- /* PnP match */
- if (error == 0)
- return (0);
-
- /* No match */
- if (error == ENXIO)
- return (ENXIO);
-
- /* Not configured by hints. */
- if (strncmp(device_get_name(dev), "speaker", 9))
- return (ENXIO);
-
- device_set_desc(dev, SPKR_DESC);
-
- return (0);
-}
-
-static int
-speaker_attach(device_t dev)
-{
-
- if (speaker_dev) {
- device_printf(dev, "Already attached!\n");
- return (ENXIO);
- }
-
- speaker_dev = make_dev(&spkr_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
- "speaker");
- return (0);
-}
-
-static int
-speaker_detach(device_t dev)
-{
- destroy_dev(speaker_dev);
- return (0);
-}
-
-static device_method_t speaker_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, speaker_probe),
- DEVMETHOD(device_attach, speaker_attach),
- DEVMETHOD(device_detach, speaker_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
- { 0, 0 }
-};
-
-static driver_t speaker_driver = {
- "speaker",
- speaker_methods,
- 1, /* no softc */
-};
-
-static devclass_t speaker_devclass;
-
-DRIVER_MODULE(speaker, isa, speaker_driver, speaker_devclass, 0, 0);
-#ifndef PC98
-DRIVER_MODULE(speaker, acpi, speaker_driver, speaker_devclass, 0, 0);
-#endif
-
-/* spkr.c ends here */
diff --git a/sys/dev/ti/if_ti.c b/sys/dev/ti/if_ti.c
deleted file mode 100644
index 614a4083bad4..000000000000
--- a/sys/dev/ti/if_ti.c
+++ /dev/null
@@ -1,3626 +0,0 @@
-/*
- * Copyright (c) 1997, 1998, 1999
- * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Alteon Networks Tigon PCI gigabit ethernet driver for FreeBSD.
- * Manuals, sample driver and firmware source kits are available
- * from http://www.alteon.com/support/openkits.
- *
- * Written by Bill Paul <wpaul@ctr.columbia.edu>
- * Electrical Engineering Department
- * Columbia University, New York City
- */
-
-/*
- * The Alteon Networks Tigon chip contains an embedded R4000 CPU,
- * gigabit MAC, dual DMA channels and a PCI interface unit. NICs
- * using the Tigon may have anywhere from 512K to 2MB of SRAM. The
- * Tigon supports hardware IP, TCP and UCP checksumming, multicast
- * filtering and jumbo (9014 byte) frames. The hardware is largely
- * controlled by firmware, which must be loaded into the NIC during
- * initialization.
- *
- * The Tigon 2 contains 2 R4000 CPUs and requires a newer firmware
- * revision, which supports new features such as extended commands,
- * extended jumbo receive ring desciptors and a mini receive ring.
- *
- * Alteon Networks is to be commended for releasing such a vast amount
- * of development material for the Tigon NIC without requiring an NDA
- * (although they really should have done it a long time ago). With
- * any luck, the other vendors will finally wise up and follow Alteon's
- * stellar example.
- *
- * The firmware for the Tigon 1 and 2 NICs is compiled directly into
- * this driver by #including it as a C header file. This bloats the
- * driver somewhat, but it's the easiest method considering that the
- * driver code and firmware code need to be kept in sync. The source
- * for the firmware is not provided with the FreeBSD distribution since
- * compiling it requires a GNU toolchain targeted for mips-sgi-irix5.3.
- *
- * The following people deserve special thanks:
- * - Terry Murphy of 3Com, for providing a 3c985 Tigon 1 board
- * for testing
- * - Raymond Lee of Netgear, for providing a pair of Netgear
- * GA620 Tigon 2 boards for testing
- * - Ulf Zimmermann, for bringing the GA260 to my attention and
- * convincing me to write this driver.
- * - Andrew Gallatin for providing FreeBSD/Alpha support.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_ti.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/sockio.h>
-#include <sys/mbuf.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/socket.h>
-#include <sys/queue.h>
-#include <sys/conf.h>
-
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/ethernet.h>
-#include <net/if_dl.h>
-#include <net/if_media.h>
-#include <net/if_types.h>
-#include <net/if_vlan_var.h>
-
-#include <net/bpf.h>
-
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-
-#include <vm/vm.h> /* for vtophys */
-#include <vm/pmap.h> /* for vtophys */
-#include <machine/bus_memio.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/bus.h>
-#include <sys/rman.h>
-
-/* #define TI_PRIVATE_JUMBOS */
-
-#if !defined(TI_PRIVATE_JUMBOS)
-#include <sys/sockio.h>
-#include <sys/uio.h>
-#include <sys/lock.h>
-#include <vm/vm_extern.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <vm/vm_map.h>
-#include <vm/vm_param.h>
-#include <vm/vm_pageout.h>
-#include <sys/vmmeter.h>
-#include <vm/vm_page.h>
-#include <vm/vm_object.h>
-#include <vm/vm_kern.h>
-#include <sys/proc.h>
-#include <sys/jumbo.h>
-#endif /* !TI_PRIVATE_JUMBOS */
-#include <sys/vnode.h> /* for vfindev, vgone */
-
-#include <pci/pcireg.h>
-#include <pci/pcivar.h>
-
-#include <sys/tiio.h>
-#include <pci/if_tireg.h>
-#include <pci/ti_fw.h>
-#include <pci/ti_fw2.h>
-
-#define TI_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP | CSUM_IP_FRAGS)
-/*
- * We can only turn on header splitting if we're using extended receive
- * BDs.
- */
-#if defined(TI_JUMBO_HDRSPLIT) && defined(TI_PRIVATE_JUMBOS)
-#error "options TI_JUMBO_HDRSPLIT and TI_PRIVATE_JUMBOS are mutually exclusive"
-#endif /* TI_JUMBO_HDRSPLIT && TI_JUMBO_HDRSPLIT */
-
-struct ti_softc *tis[8];
-
-typedef enum {
- TI_SWAP_HTON,
- TI_SWAP_NTOH
-} ti_swap_type;
-
-
-/*
- * Various supported device vendors/types and their names.
- */
-
-static struct ti_type ti_devs[] = {
- { ALT_VENDORID, ALT_DEVICEID_ACENIC,
- "Alteon AceNIC 1000baseSX Gigabit Ethernet" },
- { ALT_VENDORID, ALT_DEVICEID_ACENIC_COPPER,
- "Alteon AceNIC 1000baseT Gigabit Ethernet" },
- { TC_VENDORID, TC_DEVICEID_3C985,
- "3Com 3c985-SX Gigabit Ethernet" },
- { NG_VENDORID, NG_DEVICEID_GA620,
- "Netgear GA620 1000baseSX Gigabit Ethernet" },
- { NG_VENDORID, NG_DEVICEID_GA620T,
- "Netgear GA620 1000baseT Gigabit Ethernet" },
- { SGI_VENDORID, SGI_DEVICEID_TIGON,
- "Silicon Graphics Gigabit Ethernet" },
- { DEC_VENDORID, DEC_DEVICEID_FARALLON_PN9000SX,
- "Farallon PN9000SX Gigabit Ethernet" },
- { 0, 0, NULL }
-};
-
-#define TI_CDEV_MAJOR 153
-
-static d_open_t ti_open;
-static d_close_t ti_close;
-static d_ioctl_t ti_ioctl2;
-
-static struct cdevsw ti_cdevsw = {
- .d_open = ti_open,
- .d_close = ti_close,
- .d_ioctl = ti_ioctl2,
- .d_name = "ti",
- .d_maj = TI_CDEV_MAJOR,
-};
-
-static int ti_probe (device_t);
-static int ti_attach (device_t);
-static int ti_detach (device_t);
-static void ti_txeof (struct ti_softc *);
-static void ti_rxeof (struct ti_softc *);
-
-static void ti_stats_update (struct ti_softc *);
-static int ti_encap (struct ti_softc *, struct mbuf *, u_int32_t *);
-
-static void ti_intr (void *);
-static void ti_start (struct ifnet *);
-static int ti_ioctl (struct ifnet *, u_long, caddr_t);
-static void ti_init (void *);
-static void ti_init2 (struct ti_softc *);
-static void ti_stop (struct ti_softc *);
-static void ti_watchdog (struct ifnet *);
-static void ti_shutdown (device_t);
-static int ti_ifmedia_upd (struct ifnet *);
-static void ti_ifmedia_sts (struct ifnet *, struct ifmediareq *);
-
-static u_int32_t ti_eeprom_putbyte (struct ti_softc *, int);
-static u_int8_t ti_eeprom_getbyte (struct ti_softc *, int, u_int8_t *);
-static int ti_read_eeprom (struct ti_softc *, caddr_t, int, int);
-
-static void ti_add_mcast (struct ti_softc *, struct ether_addr *);
-static void ti_del_mcast (struct ti_softc *, struct ether_addr *);
-static void ti_setmulti (struct ti_softc *);
-
-static void ti_mem (struct ti_softc *, u_int32_t,
- u_int32_t, caddr_t);
-static int ti_copy_mem (struct ti_softc *, u_int32_t,
- u_int32_t, caddr_t, int, int);
-static int ti_copy_scratch (struct ti_softc *, u_int32_t,
- u_int32_t, caddr_t, int, int, int);
-static int ti_bcopy_swap (const void *, void *, size_t,
- ti_swap_type);
-static void ti_loadfw (struct ti_softc *);
-static void ti_cmd (struct ti_softc *, struct ti_cmd_desc *);
-static void ti_cmd_ext (struct ti_softc *, struct ti_cmd_desc *,
- caddr_t, int);
-static void ti_handle_events (struct ti_softc *);
-#ifdef TI_PRIVATE_JUMBOS
-static int ti_alloc_jumbo_mem (struct ti_softc *);
-static void *ti_jalloc (struct ti_softc *);
-static void ti_jfree (void *, void *);
-#endif /* TI_PRIVATE_JUMBOS */
-static int ti_newbuf_std (struct ti_softc *, int, struct mbuf *);
-static int ti_newbuf_mini (struct ti_softc *, int, struct mbuf *);
-static int ti_newbuf_jumbo (struct ti_softc *, int, struct mbuf *);
-static int ti_init_rx_ring_std (struct ti_softc *);
-static void ti_free_rx_ring_std (struct ti_softc *);
-static int ti_init_rx_ring_jumbo (struct ti_softc *);
-static void ti_free_rx_ring_jumbo (struct ti_softc *);
-static int ti_init_rx_ring_mini (struct ti_softc *);
-static void ti_free_rx_ring_mini (struct ti_softc *);
-static void ti_free_tx_ring (struct ti_softc *);
-static int ti_init_tx_ring (struct ti_softc *);
-
-static int ti_64bitslot_war (struct ti_softc *);
-static int ti_chipinit (struct ti_softc *);
-static int ti_gibinit (struct ti_softc *);
-
-#ifdef TI_JUMBO_HDRSPLIT
-static __inline void ti_hdr_split (struct mbuf *top, int hdr_len,
- int pkt_len, int idx);
-#endif /* TI_JUMBO_HDRSPLIT */
-
-static device_method_t ti_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, ti_probe),
- DEVMETHOD(device_attach, ti_attach),
- DEVMETHOD(device_detach, ti_detach),
- DEVMETHOD(device_shutdown, ti_shutdown),
- { 0, 0 }
-};
-
-static driver_t ti_driver = {
- "ti",
- ti_methods,
- sizeof(struct ti_softc)
-};
-
-static devclass_t ti_devclass;
-
-DRIVER_MODULE(ti, pci, ti_driver, ti_devclass, 0, 0);
-MODULE_DEPEND(ti, pci, 1, 1, 1);
-MODULE_DEPEND(ti, ether, 1, 1, 1);
-
-/* List of Tigon softcs */
-static STAILQ_HEAD(ti_softc_list, ti_softc) ti_sc_list;
-
-static struct ti_softc *
-ti_lookup_softc(int unit)
-{
- struct ti_softc *sc;
- for (sc = STAILQ_FIRST(&ti_sc_list); sc != NULL;
- sc = STAILQ_NEXT(sc, ti_links))
- if (sc->ti_unit == unit)
- return(sc);
- return(NULL);
-}
-
-/*
- * Send an instruction or address to the EEPROM, check for ACK.
- */
-static u_int32_t ti_eeprom_putbyte(sc, byte)
- struct ti_softc *sc;
- int byte;
-{
- register int i, ack = 0;
-
- /*
- * Make sure we're in TX mode.
- */
- TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN);
-
- /*
- * Feed in each bit and stobe the clock.
- */
- for (i = 0x80; i; i >>= 1) {
- if (byte & i) {
- TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT);
- } else {
- TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT);
- }
- DELAY(1);
- TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
- DELAY(1);
- TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
- }
-
- /*
- * Turn off TX mode.
- */
- TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN);
-
- /*
- * Check for ack.
- */
- TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
- ack = CSR_READ_4(sc, TI_MISC_LOCAL_CTL) & TI_MLC_EE_DIN;
- TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
-
- return(ack);
-}
-
-/*
- * Read a byte of data stored in the EEPROM at address 'addr.'
- * We have to send two address bytes since the EEPROM can hold
- * more than 256 bytes of data.
- */
-static u_int8_t ti_eeprom_getbyte(sc, addr, dest)
- struct ti_softc *sc;
- int addr;
- u_int8_t *dest;
-{
- register int i;
- u_int8_t byte = 0;
-
- EEPROM_START;
-
- /*
- * Send write control code to EEPROM.
- */
- if (ti_eeprom_putbyte(sc, EEPROM_CTL_WRITE)) {
- printf("ti%d: failed to send write command, status: %x\n",
- sc->ti_unit, CSR_READ_4(sc, TI_MISC_LOCAL_CTL));
- return(1);
- }
-
- /*
- * Send first byte of address of byte we want to read.
- */
- if (ti_eeprom_putbyte(sc, (addr >> 8) & 0xFF)) {
- printf("ti%d: failed to send address, status: %x\n",
- sc->ti_unit, CSR_READ_4(sc, TI_MISC_LOCAL_CTL));
- return(1);
- }
- /*
- * Send second byte address of byte we want to read.
- */
- if (ti_eeprom_putbyte(sc, addr & 0xFF)) {
- printf("ti%d: failed to send address, status: %x\n",
- sc->ti_unit, CSR_READ_4(sc, TI_MISC_LOCAL_CTL));
- return(1);
- }
-
- EEPROM_STOP;
- EEPROM_START;
- /*
- * Send read control code to EEPROM.
- */
- if (ti_eeprom_putbyte(sc, EEPROM_CTL_READ)) {
- printf("ti%d: failed to send read command, status: %x\n",
- sc->ti_unit, CSR_READ_4(sc, TI_MISC_LOCAL_CTL));
- return(1);
- }
-
- /*
- * Start reading bits from EEPROM.
- */
- TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN);
- for (i = 0x80; i; i >>= 1) {
- TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
- DELAY(1);
- if (CSR_READ_4(sc, TI_MISC_LOCAL_CTL) & TI_MLC_EE_DIN)
- byte |= i;
- TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
- DELAY(1);
- }
-
- EEPROM_STOP;
-
- /*
- * No ACK generated for read, so just return byte.
- */
-
- *dest = byte;
-
- return(0);
-}
-
-/*
- * Read a sequence of bytes from the EEPROM.
- */
-static int
-ti_read_eeprom(sc, dest, off, cnt)
- struct ti_softc *sc;
- caddr_t dest;
- int off;
- int cnt;
-{
- int err = 0, i;
- u_int8_t byte = 0;
-
- for (i = 0; i < cnt; i++) {
- err = ti_eeprom_getbyte(sc, off + i, &byte);
- if (err)
- break;
- *(dest + i) = byte;
- }
-
- return(err ? 1 : 0);
-}
-
-/*
- * NIC memory access function. Can be used to either clear a section
- * of NIC local memory or (if buf is non-NULL) copy data into it.
- */
-static void
-ti_mem(sc, addr, len, buf)
- struct ti_softc *sc;
- u_int32_t addr, len;
- caddr_t buf;
-{
- int segptr, segsize, cnt;
- caddr_t ti_winbase, ptr;
-
- segptr = addr;
- cnt = len;
- ti_winbase = (caddr_t)(sc->ti_vhandle + TI_WINDOW);
- ptr = buf;
-
- while(cnt) {
- if (cnt < TI_WINLEN)
- segsize = cnt;
- else
- segsize = TI_WINLEN - (segptr % TI_WINLEN);
- CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
- if (buf == NULL)
- bzero((char *)ti_winbase + (segptr &
- (TI_WINLEN - 1)), segsize);
- else {
- bcopy((char *)ptr, (char *)ti_winbase +
- (segptr & (TI_WINLEN - 1)), segsize);
- ptr += segsize;
- }
- segptr += segsize;
- cnt -= segsize;
- }
-
- return;
-}
-
-static int
-ti_copy_mem(sc, tigon_addr, len, buf, useraddr, readdata)
- struct ti_softc *sc;
- u_int32_t tigon_addr, len;
- caddr_t buf;
- int useraddr, readdata;
-{
- int segptr, segsize, cnt;
- caddr_t ptr;
- u_int32_t origwin;
- u_int8_t tmparray[TI_WINLEN], tmparray2[TI_WINLEN];
- int resid, segresid;
- int first_pass;
-
- /*
- * At the moment, we don't handle non-aligned cases, we just bail.
- * If this proves to be a problem, it will be fixed.
- */
- if ((readdata == 0)
- && (tigon_addr & 0x3)) {
- printf("ti%d: ti_copy_mem: tigon address %#x isn't "
- "word-aligned\n", sc->ti_unit, tigon_addr);
- printf("ti%d: ti_copy_mem: unaligned writes aren't yet "
- "supported\n", sc->ti_unit);
- return(EINVAL);
- }
-
- segptr = tigon_addr & ~0x3;
- segresid = tigon_addr - segptr;
-
- /*
- * This is the non-aligned amount left over that we'll need to
- * copy.
- */
- resid = len & 0x3;
-
- /* Add in the left over amount at the front of the buffer */
- resid += segresid;
-
- cnt = len & ~0x3;
- /*
- * If resid + segresid is >= 4, add multiples of 4 to the count and
- * decrease the residual by that much.
- */
- cnt += resid & ~0x3;
- resid -= resid & ~0x3;
-
- ptr = buf;
-
- first_pass = 1;
-
- /*
- * Make sure we aren't interrupted while we're changing the window
- * pointer.
- */
- TI_LOCK(sc);
-
- /*
- * Save the old window base value.
- */
- origwin = CSR_READ_4(sc, TI_WINBASE);
-
- while(cnt) {
- bus_size_t ti_offset;
-
- if (cnt < TI_WINLEN)
- segsize = cnt;
- else
- segsize = TI_WINLEN - (segptr % TI_WINLEN);
- CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
-
- ti_offset = TI_WINDOW + (segptr & (TI_WINLEN -1));
-
- if (readdata) {
-
- bus_space_read_region_4(sc->ti_btag,
- sc->ti_bhandle, ti_offset,
- (u_int32_t *)tmparray,
- segsize >> 2);
- if (useraddr) {
- /*
- * Yeah, this is a little on the kludgy
- * side, but at least this code is only
- * used for debugging.
- */
- ti_bcopy_swap(tmparray, tmparray2, segsize,
- TI_SWAP_NTOH);
-
- if (first_pass) {
- copyout(&tmparray2[segresid], ptr,
- segsize - segresid);
- first_pass = 0;
- } else
- copyout(tmparray2, ptr, segsize);
- } else {
- if (first_pass) {
-
- ti_bcopy_swap(tmparray, tmparray2,
- segsize, TI_SWAP_NTOH);
- bcopy(&tmparray2[segresid], ptr,
- segsize - segresid);
- first_pass = 0;
- } else
- ti_bcopy_swap(tmparray, ptr, segsize,
- TI_SWAP_NTOH);
- }
-
- } else {
- if (useraddr) {
- copyin(ptr, tmparray2, segsize);
- ti_bcopy_swap(tmparray2, tmparray, segsize,
- TI_SWAP_HTON);
- } else
- ti_bcopy_swap(ptr, tmparray, segsize,
- TI_SWAP_HTON);
-
- bus_space_write_region_4(sc->ti_btag,
- sc->ti_bhandle, ti_offset,
- (u_int32_t *)tmparray,
- segsize >> 2);
- }
- segptr += segsize;
- ptr += segsize;
- cnt -= segsize;
- }
-
- /*
- * Handle leftover, non-word-aligned bytes.
- */
- if (resid != 0) {
- u_int32_t tmpval, tmpval2;
- bus_size_t ti_offset;
-
- /*
- * Set the segment pointer.
- */
- CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
-
- ti_offset = TI_WINDOW + (segptr & (TI_WINLEN - 1));
-
- /*
- * First, grab whatever is in our source/destination.
- * We'll obviously need this for reads, but also for
- * writes, since we'll be doing read/modify/write.
- */
- bus_space_read_region_4(sc->ti_btag, sc->ti_bhandle,
- ti_offset, &tmpval, 1);
-
- /*
- * Next, translate this from little-endian to big-endian
- * (at least on i386 boxes).
- */
- tmpval2 = ntohl(tmpval);
-
- if (readdata) {
- /*
- * If we're reading, just copy the leftover number
- * of bytes from the host byte order buffer to
- * the user's buffer.
- */
- if (useraddr)
- copyout(&tmpval2, ptr, resid);
- else
- bcopy(&tmpval2, ptr, resid);
- } else {
- /*
- * If we're writing, first copy the bytes to be
- * written into the network byte order buffer,
- * leaving the rest of the buffer with whatever was
- * originally in there. Then, swap the bytes
- * around into host order and write them out.
- *
- * XXX KDM the read side of this has been verified
- * to work, but the write side of it has not been
- * verified. So user beware.
- */
- if (useraddr)
- copyin(ptr, &tmpval2, resid);
- else
- bcopy(ptr, &tmpval2, resid);
-
- tmpval = htonl(tmpval2);
-
- bus_space_write_region_4(sc->ti_btag, sc->ti_bhandle,
- ti_offset, &tmpval, 1);
- }
- }
-
- CSR_WRITE_4(sc, TI_WINBASE, origwin);
-
- TI_UNLOCK(sc);
-
- return(0);
-}
-
-static int
-ti_copy_scratch(sc, tigon_addr, len, buf, useraddr, readdata, cpu)
- struct ti_softc *sc;
- u_int32_t tigon_addr, len;
- caddr_t buf;
- int useraddr, readdata;
- int cpu;
-{
- u_int32_t segptr;
- int cnt;
- u_int32_t tmpval, tmpval2;
- caddr_t ptr;
-
- /*
- * At the moment, we don't handle non-aligned cases, we just bail.
- * If this proves to be a problem, it will be fixed.
- */
- if (tigon_addr & 0x3) {
- printf("ti%d: ti_copy_scratch: tigon address %#x isn't "
- "word-aligned\n", sc->ti_unit, tigon_addr);
- return(EINVAL);
- }
-
- if (len & 0x3) {
- printf("ti%d: ti_copy_scratch: transfer length %d isn't "
- "word-aligned\n", sc->ti_unit, len);
- return(EINVAL);
- }
-
- segptr = tigon_addr;
- cnt = len;
- ptr = buf;
-
- TI_LOCK(sc);
-
- while (cnt) {
- CSR_WRITE_4(sc, CPU_REG(TI_SRAM_ADDR, cpu), segptr);
-
- if (readdata) {
- tmpval2 = CSR_READ_4(sc, CPU_REG(TI_SRAM_DATA, cpu));
-
- tmpval = ntohl(tmpval2);
-
- /*
- * Note: I've used this debugging interface
- * extensively with Alteon's 12.3.15 firmware,
- * compiled with GCC 2.7.2.1 and binutils 2.9.1.
- *
- * When you compile the firmware without
- * optimization, which is necessary sometimes in
- * order to properly step through it, you sometimes
- * read out a bogus value of 0xc0017c instead of
- * whatever was supposed to be in that scratchpad
- * location. That value is on the stack somewhere,
- * but I've never been able to figure out what was
- * causing the problem.
- *
- * The address seems to pop up in random places,
- * often not in the same place on two subsequent
- * reads.
- *
- * In any case, the underlying data doesn't seem
- * to be affected, just the value read out.
- *
- * KDM, 3/7/2000
- */
-
- if (tmpval2 == 0xc0017c)
- printf("ti%d: found 0xc0017c at %#x "
- "(tmpval2)\n", sc->ti_unit, segptr);
-
- if (tmpval == 0xc0017c)
- printf("ti%d: found 0xc0017c at %#x "
- "(tmpval)\n", sc->ti_unit, segptr);
-
- if (useraddr)
- copyout(&tmpval, ptr, 4);
- else
- bcopy(&tmpval, ptr, 4);
- } else {
- if (useraddr)
- copyin(ptr, &tmpval2, 4);
- else
- bcopy(ptr, &tmpval2, 4);
-
- tmpval = htonl(tmpval2);
-
- CSR_WRITE_4(sc, CPU_REG(TI_SRAM_DATA, cpu), tmpval);
- }
-
- cnt -= 4;
- segptr += 4;
- ptr += 4;
- }
-
- TI_UNLOCK(sc);
-
- return(0);
-}
-
-static int
-ti_bcopy_swap(src, dst, len, swap_type)
- const void *src;
- void *dst;
- size_t len;
- ti_swap_type swap_type;
-{
- const u_int8_t *tmpsrc;
- u_int8_t *tmpdst;
- size_t tmplen;
-
- if (len & 0x3) {
- printf("ti_bcopy_swap: length %zd isn't 32-bit aligned\n",
- len);
- return(-1);
- }
-
- tmpsrc = src;
- tmpdst = dst;
- tmplen = len;
-
- while (tmplen) {
- if (swap_type == TI_SWAP_NTOH)
- *(u_int32_t *)tmpdst =
- ntohl(*(const u_int32_t *)tmpsrc);
- else
- *(u_int32_t *)tmpdst =
- htonl(*(const u_int32_t *)tmpsrc);
-
- tmpsrc += 4;
- tmpdst += 4;
- tmplen -= 4;
- }
-
- return(0);
-}
-
-/*
- * Load firmware image into the NIC. Check that the firmware revision
- * is acceptable and see if we want the firmware for the Tigon 1 or
- * Tigon 2.
- */
-static void
-ti_loadfw(sc)
- struct ti_softc *sc;
-{
- switch(sc->ti_hwrev) {
- case TI_HWREV_TIGON:
- if (tigonFwReleaseMajor != TI_FIRMWARE_MAJOR ||
- tigonFwReleaseMinor != TI_FIRMWARE_MINOR ||
- tigonFwReleaseFix != TI_FIRMWARE_FIX) {
- printf("ti%d: firmware revision mismatch; want "
- "%d.%d.%d, got %d.%d.%d\n", sc->ti_unit,
- TI_FIRMWARE_MAJOR, TI_FIRMWARE_MINOR,
- TI_FIRMWARE_FIX, tigonFwReleaseMajor,
- tigonFwReleaseMinor, tigonFwReleaseFix);
- return;
- }
- ti_mem(sc, tigonFwTextAddr, tigonFwTextLen,
- (caddr_t)tigonFwText);
- ti_mem(sc, tigonFwDataAddr, tigonFwDataLen,
- (caddr_t)tigonFwData);
- ti_mem(sc, tigonFwRodataAddr, tigonFwRodataLen,
- (caddr_t)tigonFwRodata);
- ti_mem(sc, tigonFwBssAddr, tigonFwBssLen, NULL);
- ti_mem(sc, tigonFwSbssAddr, tigonFwSbssLen, NULL);
- CSR_WRITE_4(sc, TI_CPU_PROGRAM_COUNTER, tigonFwStartAddr);
- break;
- case TI_HWREV_TIGON_II:
- if (tigon2FwReleaseMajor != TI_FIRMWARE_MAJOR ||
- tigon2FwReleaseMinor != TI_FIRMWARE_MINOR ||
- tigon2FwReleaseFix != TI_FIRMWARE_FIX) {
- printf("ti%d: firmware revision mismatch; want "
- "%d.%d.%d, got %d.%d.%d\n", sc->ti_unit,
- TI_FIRMWARE_MAJOR, TI_FIRMWARE_MINOR,
- TI_FIRMWARE_FIX, tigon2FwReleaseMajor,
- tigon2FwReleaseMinor, tigon2FwReleaseFix);
- return;
- }
- ti_mem(sc, tigon2FwTextAddr, tigon2FwTextLen,
- (caddr_t)tigon2FwText);
- ti_mem(sc, tigon2FwDataAddr, tigon2FwDataLen,
- (caddr_t)tigon2FwData);
- ti_mem(sc, tigon2FwRodataAddr, tigon2FwRodataLen,
- (caddr_t)tigon2FwRodata);
- ti_mem(sc, tigon2FwBssAddr, tigon2FwBssLen, NULL);
- ti_mem(sc, tigon2FwSbssAddr, tigon2FwSbssLen, NULL);
- CSR_WRITE_4(sc, TI_CPU_PROGRAM_COUNTER, tigon2FwStartAddr);
- break;
- default:
- printf("ti%d: can't load firmware: unknown hardware rev\n",
- sc->ti_unit);
- break;
- }
-
- return;
-}
-
-/*
- * Send the NIC a command via the command ring.
- */
-static void
-ti_cmd(sc, cmd)
- struct ti_softc *sc;
- struct ti_cmd_desc *cmd;
-{
- u_int32_t index;
-
- if (sc->ti_rdata->ti_cmd_ring == NULL)
- return;
-
- index = sc->ti_cmd_saved_prodidx;
- CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4), *(u_int32_t *)(cmd));
- TI_INC(index, TI_CMD_RING_CNT);
- CSR_WRITE_4(sc, TI_MB_CMDPROD_IDX, index);
- sc->ti_cmd_saved_prodidx = index;
-
- return;
-}
-
-/*
- * Send the NIC an extended command. The 'len' parameter specifies the
- * number of command slots to include after the initial command.
- */
-static void
-ti_cmd_ext(sc, cmd, arg, len)
- struct ti_softc *sc;
- struct ti_cmd_desc *cmd;
- caddr_t arg;
- int len;
-{
- u_int32_t index;
- register int i;
-
- if (sc->ti_rdata->ti_cmd_ring == NULL)
- return;
-
- index = sc->ti_cmd_saved_prodidx;
- CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4), *(u_int32_t *)(cmd));
- TI_INC(index, TI_CMD_RING_CNT);
- for (i = 0; i < len; i++) {
- CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4),
- *(u_int32_t *)(&arg[i * 4]));
- TI_INC(index, TI_CMD_RING_CNT);
- }
- CSR_WRITE_4(sc, TI_MB_CMDPROD_IDX, index);
- sc->ti_cmd_saved_prodidx = index;
-
- return;
-}
-
-/*
- * Handle events that have triggered interrupts.
- */
-static void
-ti_handle_events(sc)
- struct ti_softc *sc;
-{
- struct ti_event_desc *e;
-
- if (sc->ti_rdata->ti_event_ring == NULL)
- return;
-
- while (sc->ti_ev_saved_considx != sc->ti_ev_prodidx.ti_idx) {
- e = &sc->ti_rdata->ti_event_ring[sc->ti_ev_saved_considx];
- switch(e->ti_event) {
- case TI_EV_LINKSTAT_CHANGED:
- sc->ti_linkstat = e->ti_code;
- if (e->ti_code == TI_EV_CODE_LINK_UP)
- printf("ti%d: 10/100 link up\n", sc->ti_unit);
- else if (e->ti_code == TI_EV_CODE_GIG_LINK_UP)
- printf("ti%d: gigabit link up\n", sc->ti_unit);
- else if (e->ti_code == TI_EV_CODE_LINK_DOWN)
- printf("ti%d: link down\n", sc->ti_unit);
- break;
- case TI_EV_ERROR:
- if (e->ti_code == TI_EV_CODE_ERR_INVAL_CMD)
- printf("ti%d: invalid command\n", sc->ti_unit);
- else if (e->ti_code == TI_EV_CODE_ERR_UNIMP_CMD)
- printf("ti%d: unknown command\n", sc->ti_unit);
- else if (e->ti_code == TI_EV_CODE_ERR_BADCFG)
- printf("ti%d: bad config data\n", sc->ti_unit);
- break;
- case TI_EV_FIRMWARE_UP:
- ti_init2(sc);
- break;
- case TI_EV_STATS_UPDATED:
- ti_stats_update(sc);
- break;
- case TI_EV_RESET_JUMBO_RING:
- case TI_EV_MCAST_UPDATED:
- /* Who cares. */
- break;
- default:
- printf("ti%d: unknown event: %d\n",
- sc->ti_unit, e->ti_event);
- break;
- }
- /* Advance the consumer index. */
- TI_INC(sc->ti_ev_saved_considx, TI_EVENT_RING_CNT);
- CSR_WRITE_4(sc, TI_GCR_EVENTCONS_IDX, sc->ti_ev_saved_considx);
- }
-
- return;
-}
-
-#ifdef TI_PRIVATE_JUMBOS
-
-/*
- * Memory management for the jumbo receive ring is a pain in the
- * butt. We need to allocate at least 9018 bytes of space per frame,
- * _and_ it has to be contiguous (unless you use the extended
- * jumbo descriptor format). Using malloc() all the time won't
- * work: malloc() allocates memory in powers of two, which means we
- * would end up wasting a considerable amount of space by allocating
- * 9K chunks. We don't have a jumbo mbuf cluster pool. Thus, we have
- * to do our own memory management.
- *
- * The driver needs to allocate a contiguous chunk of memory at boot
- * time. We then chop this up ourselves into 9K pieces and use them
- * as external mbuf storage.
- *
- * One issue here is how much memory to allocate. The jumbo ring has
- * 256 slots in it, but at 9K per slot than can consume over 2MB of
- * RAM. This is a bit much, especially considering we also need
- * RAM for the standard ring and mini ring (on the Tigon 2). To
- * save space, we only actually allocate enough memory for 64 slots
- * by default, which works out to between 500 and 600K. This can
- * be tuned by changing a #define in if_tireg.h.
- */
-
-static int
-ti_alloc_jumbo_mem(sc)
- struct ti_softc *sc;
-{
- caddr_t ptr;
- register int i;
- struct ti_jpool_entry *entry;
-
- /* Grab a big chunk o' storage. */
- sc->ti_cdata.ti_jumbo_buf = contigmalloc(TI_JMEM, M_DEVBUF,
- M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
-
- if (sc->ti_cdata.ti_jumbo_buf == NULL) {
- printf("ti%d: no memory for jumbo buffers!\n", sc->ti_unit);
- return(ENOBUFS);
- }
-
- SLIST_INIT(&sc->ti_jfree_listhead);
- SLIST_INIT(&sc->ti_jinuse_listhead);
-
- /*
- * Now divide it up into 9K pieces and save the addresses
- * in an array.
- */
- ptr = sc->ti_cdata.ti_jumbo_buf;
- for (i = 0; i < TI_JSLOTS; i++) {
- sc->ti_cdata.ti_jslots[i] = ptr;
- ptr += TI_JLEN;
- entry = malloc(sizeof(struct ti_jpool_entry),
- M_DEVBUF, M_NOWAIT);
- if (entry == NULL) {
- contigfree(sc->ti_cdata.ti_jumbo_buf, TI_JMEM,
- M_DEVBUF);
- sc->ti_cdata.ti_jumbo_buf = NULL;
- printf("ti%d: no memory for jumbo "
- "buffer queue!\n", sc->ti_unit);
- return(ENOBUFS);
- }
- entry->slot = i;
- SLIST_INSERT_HEAD(&sc->ti_jfree_listhead, entry, jpool_entries);
- }
-
- return(0);
-}
-
-/*
- * Allocate a jumbo buffer.
- */
-static void *ti_jalloc(sc)
- struct ti_softc *sc;
-{
- struct ti_jpool_entry *entry;
-
- entry = SLIST_FIRST(&sc->ti_jfree_listhead);
-
- if (entry == NULL) {
- printf("ti%d: no free jumbo buffers\n", sc->ti_unit);
- return(NULL);
- }
-
- SLIST_REMOVE_HEAD(&sc->ti_jfree_listhead, jpool_entries);
- SLIST_INSERT_HEAD(&sc->ti_jinuse_listhead, entry, jpool_entries);
- return(sc->ti_cdata.ti_jslots[entry->slot]);
-}
-
-/*
- * Release a jumbo buffer.
- */
-static void
-ti_jfree(buf, args)
- void *buf;
- void *args;
-{
- struct ti_softc *sc;
- int i;
- struct ti_jpool_entry *entry;
-
- /* Extract the softc struct pointer. */
- sc = (struct ti_softc *)args;
-
- if (sc == NULL)
- panic("ti_jfree: didn't get softc pointer!");
-
- /* calculate the slot this buffer belongs to */
- i = ((vm_offset_t)buf
- - (vm_offset_t)sc->ti_cdata.ti_jumbo_buf) / TI_JLEN;
-
- if ((i < 0) || (i >= TI_JSLOTS))
- panic("ti_jfree: asked to free buffer that we don't manage!");
-
- entry = SLIST_FIRST(&sc->ti_jinuse_listhead);
- if (entry == NULL)
- panic("ti_jfree: buffer not in use!");
- entry->slot = i;
- SLIST_REMOVE_HEAD(&sc->ti_jinuse_listhead, jpool_entries);
- SLIST_INSERT_HEAD(&sc->ti_jfree_listhead, entry, jpool_entries);
-
- return;
-}
-
-#endif /* TI_PRIVATE_JUMBOS */
-
-/*
- * Intialize a standard receive ring descriptor.
- */
-static int
-ti_newbuf_std(sc, i, m)
- struct ti_softc *sc;
- int i;
- struct mbuf *m;
-{
- struct mbuf *m_new = NULL;
- struct ti_rx_desc *r;
-
- if (m == NULL) {
- MGETHDR(m_new, M_DONTWAIT, MT_DATA);
- if (m_new == NULL)
- return(ENOBUFS);
-
- MCLGET(m_new, M_DONTWAIT);
- if (!(m_new->m_flags & M_EXT)) {
- m_freem(m_new);
- return(ENOBUFS);
- }
- m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
- } else {
- m_new = m;
- m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
- m_new->m_data = m_new->m_ext.ext_buf;
- }
-
- m_adj(m_new, ETHER_ALIGN);
- sc->ti_cdata.ti_rx_std_chain[i] = m_new;
- r = &sc->ti_rdata->ti_rx_std_ring[i];
- TI_HOSTADDR(r->ti_addr) = vtophys(mtod(m_new, caddr_t));
- r->ti_type = TI_BDTYPE_RECV_BD;
- r->ti_flags = 0;
- if (sc->arpcom.ac_if.if_hwassist)
- r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM | TI_BDFLAG_IP_CKSUM;
- r->ti_len = m_new->m_len;
- r->ti_idx = i;
-
- return(0);
-}
-
-/*
- * Intialize a mini receive ring descriptor. This only applies to
- * the Tigon 2.
- */
-static int
-ti_newbuf_mini(sc, i, m)
- struct ti_softc *sc;
- int i;
- struct mbuf *m;
-{
- struct mbuf *m_new = NULL;
- struct ti_rx_desc *r;
-
- if (m == NULL) {
- MGETHDR(m_new, M_DONTWAIT, MT_DATA);
- if (m_new == NULL) {
- return(ENOBUFS);
- }
- m_new->m_len = m_new->m_pkthdr.len = MHLEN;
- } else {
- m_new = m;
- m_new->m_data = m_new->m_pktdat;
- m_new->m_len = m_new->m_pkthdr.len = MHLEN;
- }
-
- m_adj(m_new, ETHER_ALIGN);
- r = &sc->ti_rdata->ti_rx_mini_ring[i];
- sc->ti_cdata.ti_rx_mini_chain[i] = m_new;
- TI_HOSTADDR(r->ti_addr) = vtophys(mtod(m_new, caddr_t));
- r->ti_type = TI_BDTYPE_RECV_BD;
- r->ti_flags = TI_BDFLAG_MINI_RING;
- if (sc->arpcom.ac_if.if_hwassist)
- r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM | TI_BDFLAG_IP_CKSUM;
- r->ti_len = m_new->m_len;
- r->ti_idx = i;
-
- return(0);
-}
-
-#ifdef TI_PRIVATE_JUMBOS
-
-/*
- * Initialize a jumbo receive ring descriptor. This allocates
- * a jumbo buffer from the pool managed internally by the driver.
- */
-static int
-ti_newbuf_jumbo(sc, i, m)
- struct ti_softc *sc;
- int i;
- struct mbuf *m;
-{
- struct mbuf *m_new = NULL;
- struct ti_rx_desc *r;
-
- if (m == NULL) {
- caddr_t *buf = NULL;
-
- /* Allocate the mbuf. */
- MGETHDR(m_new, M_DONTWAIT, MT_DATA);
- if (m_new == NULL) {
- return(ENOBUFS);
- }
-
- /* Allocate the jumbo buffer */
- buf = ti_jalloc(sc);
- if (buf == NULL) {
- m_freem(m_new);
- printf("ti%d: jumbo allocation failed "
- "-- packet dropped!\n", sc->ti_unit);
- return(ENOBUFS);
- }
-
- /* Attach the buffer to the mbuf. */
- m_new->m_data = (void *) buf;
- m_new->m_len = m_new->m_pkthdr.len = TI_JUMBO_FRAMELEN;
- MEXTADD(m_new, buf, TI_JUMBO_FRAMELEN, ti_jfree,
- (struct ti_softc *)sc, 0, EXT_NET_DRV);
- } else {
- m_new = m;
- m_new->m_data = m_new->m_ext.ext_buf;
- m_new->m_ext.ext_size = TI_JUMBO_FRAMELEN;
- }
-
- m_adj(m_new, ETHER_ALIGN);
- /* Set up the descriptor. */
- r = &sc->ti_rdata->ti_rx_jumbo_ring[i];
- sc->ti_cdata.ti_rx_jumbo_chain[i] = m_new;
- TI_HOSTADDR(r->ti_addr) = vtophys(mtod(m_new, caddr_t));
- r->ti_type = TI_BDTYPE_RECV_JUMBO_BD;
- r->ti_flags = TI_BDFLAG_JUMBO_RING;
- if (sc->arpcom.ac_if.if_hwassist)
- r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM | TI_BDFLAG_IP_CKSUM;
- r->ti_len = m_new->m_len;
- r->ti_idx = i;
-
- return(0);
-}
-
-#else
-#include <vm/vm_page.h>
-
-#if (PAGE_SIZE == 4096)
-#define NPAYLOAD 2
-#else
-#define NPAYLOAD 1
-#endif
-
-#define TCP_HDR_LEN (52 + sizeof(struct ether_header))
-#define UDP_HDR_LEN (28 + sizeof(struct ether_header))
-#define NFS_HDR_LEN (UDP_HDR_LEN)
-static int HDR_LEN = TCP_HDR_LEN;
-
-
- /*
- * Initialize a jumbo receive ring descriptor. This allocates
- * a jumbo buffer from the pool managed internally by the driver.
- */
-static int
-ti_newbuf_jumbo(sc, idx, m_old)
- struct ti_softc *sc;
- int idx;
- struct mbuf *m_old;
-{
- struct mbuf *cur, *m_new = NULL;
- struct mbuf *m[3] = {NULL, NULL, NULL};
- struct ti_rx_desc_ext *r;
- vm_page_t frame;
- /* 1 extra buf to make nobufs easy*/
- caddr_t buf[3] = {NULL, NULL, NULL};
- int i;
-
- if (m_old != NULL) {
- m_new = m_old;
- cur = m_old->m_next;
- for (i = 0; i <= NPAYLOAD; i++){
- m[i] = cur;
- cur = cur->m_next;
- }
- } else {
- /* Allocate the mbufs. */
- MGETHDR(m_new, M_DONTWAIT, MT_DATA);
- if (m_new == NULL) {
- printf("ti%d: mbuf allocation failed "
- "-- packet dropped!\n", sc->ti_unit);
- goto nobufs;
- }
- MGET(m[NPAYLOAD], M_DONTWAIT, MT_DATA);
- if (m[NPAYLOAD] == NULL) {
- printf("ti%d: cluster mbuf allocation failed "
- "-- packet dropped!\n", sc->ti_unit);
- goto nobufs;
- }
- MCLGET(m[NPAYLOAD], M_DONTWAIT);
- if ((m[NPAYLOAD]->m_flags & M_EXT) == 0) {
- printf("ti%d: mbuf allocation failed "
- "-- packet dropped!\n", sc->ti_unit);
- goto nobufs;
- }
- m[NPAYLOAD]->m_len = MCLBYTES;
-
- for (i = 0; i < NPAYLOAD; i++){
- MGET(m[i], M_DONTWAIT, MT_DATA);
- if (m[i] == NULL) {
- printf("ti%d: mbuf allocation failed "
- "-- packet dropped!\n", sc->ti_unit);
- goto nobufs;
- }
- if (!(frame = jumbo_pg_alloc())){
- printf("ti%d: buffer allocation failed "
- "-- packet dropped!\n", sc->ti_unit);
- printf(" index %d page %d\n", idx, i);
- goto nobufs;
- }
- buf[i] = jumbo_phys_to_kva(VM_PAGE_TO_PHYS(frame));
- }
- for (i = 0; i < NPAYLOAD; i++){
- /* Attach the buffer to the mbuf. */
- m[i]->m_data = (void *)buf[i];
- m[i]->m_len = PAGE_SIZE;
- MEXTADD(m[i], (void *)buf[i], PAGE_SIZE,
- jumbo_freem, NULL, 0, EXT_DISPOSABLE);
- m[i]->m_next = m[i+1];
- }
- /* link the buffers to the header */
- m_new->m_next = m[0];
- m_new->m_data += ETHER_ALIGN;
- if (sc->ti_hdrsplit)
- m_new->m_len = MHLEN - ETHER_ALIGN;
- else
- m_new->m_len = HDR_LEN;
- m_new->m_pkthdr.len = NPAYLOAD * PAGE_SIZE + m_new->m_len;
- }
-
- /* Set up the descriptor. */
- r = &sc->ti_rdata->ti_rx_jumbo_ring[idx];
- sc->ti_cdata.ti_rx_jumbo_chain[idx] = m_new;
- TI_HOSTADDR(r->ti_addr0) = vtophys(mtod(m_new, caddr_t));
- r->ti_len0 = m_new->m_len;
-
- TI_HOSTADDR(r->ti_addr1) = vtophys(mtod(m[0], caddr_t));
- r->ti_len1 = PAGE_SIZE;
-
- TI_HOSTADDR(r->ti_addr2) = vtophys(mtod(m[1], caddr_t));
- r->ti_len2 = m[1]->m_ext.ext_size; /* could be PAGE_SIZE or MCLBYTES */
-
- if (PAGE_SIZE == 4096) {
- TI_HOSTADDR(r->ti_addr3) = vtophys(mtod(m[2], caddr_t));
- r->ti_len3 = MCLBYTES;
- } else {
- r->ti_len3 = 0;
- }
- r->ti_type = TI_BDTYPE_RECV_JUMBO_BD;
-
- r->ti_flags = TI_BDFLAG_JUMBO_RING|TI_RCB_FLAG_USE_EXT_RX_BD;
-
- if (sc->arpcom.ac_if.if_hwassist)
- r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM|TI_BDFLAG_IP_CKSUM;
-
- r->ti_idx = idx;
-
- return(0);
-
- nobufs:
-
- /*
- * Warning! :
- * This can only be called before the mbufs are strung together.
- * If the mbufs are strung together, m_freem() will free the chain,
- * so that the later mbufs will be freed multiple times.
- */
- if (m_new)
- m_freem(m_new);
-
- for(i = 0; i < 3; i++){
- if (m[i])
- m_freem(m[i]);
- if (buf[i])
- jumbo_pg_free((vm_offset_t)buf[i]);
- }
- return ENOBUFS;
-}
-#endif
-
-
-
-/*
- * The standard receive ring has 512 entries in it. At 2K per mbuf cluster,
- * that's 1MB or memory, which is a lot. For now, we fill only the first
- * 256 ring entries and hope that our CPU is fast enough to keep up with
- * the NIC.
- */
-static int
-ti_init_rx_ring_std(sc)
- struct ti_softc *sc;
-{
- register int i;
- struct ti_cmd_desc cmd;
-
- for (i = 0; i < TI_SSLOTS; i++) {
- if (ti_newbuf_std(sc, i, NULL) == ENOBUFS)
- return(ENOBUFS);
- };
-
- TI_UPDATE_STDPROD(sc, i - 1);
- sc->ti_std = i - 1;
-
- return(0);
-}
-
-static void
-ti_free_rx_ring_std(sc)
- struct ti_softc *sc;
-{
- register int i;
-
- for (i = 0; i < TI_STD_RX_RING_CNT; i++) {
- if (sc->ti_cdata.ti_rx_std_chain[i] != NULL) {
- m_freem(sc->ti_cdata.ti_rx_std_chain[i]);
- sc->ti_cdata.ti_rx_std_chain[i] = NULL;
- }
- bzero((char *)&sc->ti_rdata->ti_rx_std_ring[i],
- sizeof(struct ti_rx_desc));
- }
-
- return;
-}
-
-static int
-ti_init_rx_ring_jumbo(sc)
- struct ti_softc *sc;
-{
- register int i;
- struct ti_cmd_desc cmd;
-
- for (i = 0; i < TI_JUMBO_RX_RING_CNT; i++) {
- if (ti_newbuf_jumbo(sc, i, NULL) == ENOBUFS)
- return(ENOBUFS);
- };
-
- TI_UPDATE_JUMBOPROD(sc, i - 1);
- sc->ti_jumbo = i - 1;
-
- return(0);
-}
-
-static void
-ti_free_rx_ring_jumbo(sc)
- struct ti_softc *sc;
-{
- register int i;
-
- for (i = 0; i < TI_JUMBO_RX_RING_CNT; i++) {
- if (sc->ti_cdata.ti_rx_jumbo_chain[i] != NULL) {
- m_freem(sc->ti_cdata.ti_rx_jumbo_chain[i]);
- sc->ti_cdata.ti_rx_jumbo_chain[i] = NULL;
- }
- bzero((char *)&sc->ti_rdata->ti_rx_jumbo_ring[i],
- sizeof(struct ti_rx_desc));
- }
-
- return;
-}
-
-static int
-ti_init_rx_ring_mini(sc)
- struct ti_softc *sc;
-{
- register int i;
-
- for (i = 0; i < TI_MSLOTS; i++) {
- if (ti_newbuf_mini(sc, i, NULL) == ENOBUFS)
- return(ENOBUFS);
- };
-
- TI_UPDATE_MINIPROD(sc, i - 1);
- sc->ti_mini = i - 1;
-
- return(0);
-}
-
-static void
-ti_free_rx_ring_mini(sc)
- struct ti_softc *sc;
-{
- register int i;
-
- for (i = 0; i < TI_MINI_RX_RING_CNT; i++) {
- if (sc->ti_cdata.ti_rx_mini_chain[i] != NULL) {
- m_freem(sc->ti_cdata.ti_rx_mini_chain[i]);
- sc->ti_cdata.ti_rx_mini_chain[i] = NULL;
- }
- bzero((char *)&sc->ti_rdata->ti_rx_mini_ring[i],
- sizeof(struct ti_rx_desc));
- }
-
- return;
-}
-
-static void
-ti_free_tx_ring(sc)
- struct ti_softc *sc;
-{
- register int i;
-
- if (sc->ti_rdata->ti_tx_ring == NULL)
- return;
-
- for (i = 0; i < TI_TX_RING_CNT; i++) {
- if (sc->ti_cdata.ti_tx_chain[i] != NULL) {
- m_freem(sc->ti_cdata.ti_tx_chain[i]);
- sc->ti_cdata.ti_tx_chain[i] = NULL;
- }
- bzero((char *)&sc->ti_rdata->ti_tx_ring[i],
- sizeof(struct ti_tx_desc));
- }
-
- return;
-}
-
-static int
-ti_init_tx_ring(sc)
- struct ti_softc *sc;
-{
- sc->ti_txcnt = 0;
- sc->ti_tx_saved_considx = 0;
- CSR_WRITE_4(sc, TI_MB_SENDPROD_IDX, 0);
- return(0);
-}
-
-/*
- * The Tigon 2 firmware has a new way to add/delete multicast addresses,
- * but we have to support the old way too so that Tigon 1 cards will
- * work.
- */
-static void
-ti_add_mcast(sc, addr)
- struct ti_softc *sc;
- struct ether_addr *addr;
-{
- struct ti_cmd_desc cmd;
- u_int16_t *m;
- u_int32_t ext[2] = {0, 0};
-
- m = (u_int16_t *)&addr->octet[0];
-
- switch(sc->ti_hwrev) {
- case TI_HWREV_TIGON:
- CSR_WRITE_4(sc, TI_GCR_MAR0, htons(m[0]));
- CSR_WRITE_4(sc, TI_GCR_MAR1, (htons(m[1]) << 16) | htons(m[2]));
- TI_DO_CMD(TI_CMD_ADD_MCAST_ADDR, 0, 0);
- break;
- case TI_HWREV_TIGON_II:
- ext[0] = htons(m[0]);
- ext[1] = (htons(m[1]) << 16) | htons(m[2]);
- TI_DO_CMD_EXT(TI_CMD_EXT_ADD_MCAST, 0, 0, (caddr_t)&ext, 2);
- break;
- default:
- printf("ti%d: unknown hwrev\n", sc->ti_unit);
- break;
- }
-
- return;
-}
-
-static void
-ti_del_mcast(sc, addr)
- struct ti_softc *sc;
- struct ether_addr *addr;
-{
- struct ti_cmd_desc cmd;
- u_int16_t *m;
- u_int32_t ext[2] = {0, 0};
-
- m = (u_int16_t *)&addr->octet[0];
-
- switch(sc->ti_hwrev) {
- case TI_HWREV_TIGON:
- CSR_WRITE_4(sc, TI_GCR_MAR0, htons(m[0]));
- CSR_WRITE_4(sc, TI_GCR_MAR1, (htons(m[1]) << 16) | htons(m[2]));
- TI_DO_CMD(TI_CMD_DEL_MCAST_ADDR, 0, 0);
- break;
- case TI_HWREV_TIGON_II:
- ext[0] = htons(m[0]);
- ext[1] = (htons(m[1]) << 16) | htons(m[2]);
- TI_DO_CMD_EXT(TI_CMD_EXT_DEL_MCAST, 0, 0, (caddr_t)&ext, 2);
- break;
- default:
- printf("ti%d: unknown hwrev\n", sc->ti_unit);
- break;
- }
-
- return;
-}
-
-/*
- * Configure the Tigon's multicast address filter.
- *
- * The actual multicast table management is a bit of a pain, thanks to
- * slight brain damage on the part of both Alteon and us. With our
- * multicast code, we are only alerted when the multicast address table
- * changes and at that point we only have the current list of addresses:
- * we only know the current state, not the previous state, so we don't
- * actually know what addresses were removed or added. The firmware has
- * state, but we can't get our grubby mits on it, and there is no 'delete
- * all multicast addresses' command. Hence, we have to maintain our own
- * state so we know what addresses have been programmed into the NIC at
- * any given time.
- */
-static void
-ti_setmulti(sc)
- struct ti_softc *sc;
-{
- struct ifnet *ifp;
- struct ifmultiaddr *ifma;
- struct ti_cmd_desc cmd;
- struct ti_mc_entry *mc;
- u_int32_t intrs;
-
- ifp = &sc->arpcom.ac_if;
-
- if (ifp->if_flags & IFF_ALLMULTI) {
- TI_DO_CMD(TI_CMD_SET_ALLMULTI, TI_CMD_CODE_ALLMULTI_ENB, 0);
- return;
- } else {
- TI_DO_CMD(TI_CMD_SET_ALLMULTI, TI_CMD_CODE_ALLMULTI_DIS, 0);
- }
-
- /* Disable interrupts. */
- intrs = CSR_READ_4(sc, TI_MB_HOSTINTR);
- CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
-
- /* First, zot all the existing filters. */
- while (SLIST_FIRST(&sc->ti_mc_listhead) != NULL) {
- mc = SLIST_FIRST(&sc->ti_mc_listhead);
- ti_del_mcast(sc, &mc->mc_addr);
- SLIST_REMOVE_HEAD(&sc->ti_mc_listhead, mc_entries);
- free(mc, M_DEVBUF);
- }
-
- /* Now program new ones. */
- TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
- if (ifma->ifma_addr->sa_family != AF_LINK)
- continue;
- mc = malloc(sizeof(struct ti_mc_entry), M_DEVBUF, M_NOWAIT);
- bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
- (char *)&mc->mc_addr, ETHER_ADDR_LEN);
- SLIST_INSERT_HEAD(&sc->ti_mc_listhead, mc, mc_entries);
- ti_add_mcast(sc, &mc->mc_addr);
- }
-
- /* Re-enable interrupts. */
- CSR_WRITE_4(sc, TI_MB_HOSTINTR, intrs);
-
- return;
-}
-
-/*
- * Check to see if the BIOS has configured us for a 64 bit slot when
- * we aren't actually in one. If we detect this condition, we can work
- * around it on the Tigon 2 by setting a bit in the PCI state register,
- * but for the Tigon 1 we must give up and abort the interface attach.
- */
-static int ti_64bitslot_war(sc)
- struct ti_softc *sc;
-{
- if (!(CSR_READ_4(sc, TI_PCI_STATE) & TI_PCISTATE_32BIT_BUS)) {
- CSR_WRITE_4(sc, 0x600, 0);
- CSR_WRITE_4(sc, 0x604, 0);
- CSR_WRITE_4(sc, 0x600, 0x5555AAAA);
- if (CSR_READ_4(sc, 0x604) == 0x5555AAAA) {
- if (sc->ti_hwrev == TI_HWREV_TIGON)
- return(EINVAL);
- else {
- TI_SETBIT(sc, TI_PCI_STATE,
- TI_PCISTATE_32BIT_BUS);
- return(0);
- }
- }
- }
-
- return(0);
-}
-
-/*
- * Do endian, PCI and DMA initialization. Also check the on-board ROM
- * self-test results.
- */
-static int
-ti_chipinit(sc)
- struct ti_softc *sc;
-{
- u_int32_t cacheline;
- u_int32_t pci_writemax = 0;
- u_int32_t hdrsplit;
-
- /* Initialize link to down state. */
- sc->ti_linkstat = TI_EV_CODE_LINK_DOWN;
-
- if (sc->arpcom.ac_if.if_capenable & IFCAP_HWCSUM)
- sc->arpcom.ac_if.if_hwassist = TI_CSUM_FEATURES;
- else
- sc->arpcom.ac_if.if_hwassist = 0;
-
- /* Set endianness before we access any non-PCI registers. */
-#if BYTE_ORDER == BIG_ENDIAN
- CSR_WRITE_4(sc, TI_MISC_HOST_CTL,
- TI_MHC_BIGENDIAN_INIT | (TI_MHC_BIGENDIAN_INIT << 24));
-#else
- CSR_WRITE_4(sc, TI_MISC_HOST_CTL,
- TI_MHC_LITTLEENDIAN_INIT | (TI_MHC_LITTLEENDIAN_INIT << 24));
-#endif
-
- /* Check the ROM failed bit to see if self-tests passed. */
- if (CSR_READ_4(sc, TI_CPU_STATE) & TI_CPUSTATE_ROMFAIL) {
- printf("ti%d: board self-diagnostics failed!\n", sc->ti_unit);
- return(ENODEV);
- }
-
- /* Halt the CPU. */
- TI_SETBIT(sc, TI_CPU_STATE, TI_CPUSTATE_HALT);
-
- /* Figure out the hardware revision. */
- switch(CSR_READ_4(sc, TI_MISC_HOST_CTL) & TI_MHC_CHIP_REV_MASK) {
- case TI_REV_TIGON_I:
- sc->ti_hwrev = TI_HWREV_TIGON;
- break;
- case TI_REV_TIGON_II:
- sc->ti_hwrev = TI_HWREV_TIGON_II;
- break;
- default:
- printf("ti%d: unsupported chip revision\n", sc->ti_unit);
- return(ENODEV);
- }
-
- /* Do special setup for Tigon 2. */
- if (sc->ti_hwrev == TI_HWREV_TIGON_II) {
- TI_SETBIT(sc, TI_CPU_CTL_B, TI_CPUSTATE_HALT);
- TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_SRAM_BANK_512K);
- TI_SETBIT(sc, TI_MISC_CONF, TI_MCR_SRAM_SYNCHRONOUS);
- }
-
- /*
- * We don't have firmware source for the Tigon 1, so Tigon 1 boards
- * can't do header splitting.
- */
-#ifdef TI_JUMBO_HDRSPLIT
- if (sc->ti_hwrev != TI_HWREV_TIGON)
- sc->ti_hdrsplit = 1;
- else
- printf("ti%d: can't do header splitting on a Tigon I board\n",
- sc->ti_unit);
-#endif /* TI_JUMBO_HDRSPLIT */
-
- /* Set up the PCI state register. */
- CSR_WRITE_4(sc, TI_PCI_STATE, TI_PCI_READ_CMD|TI_PCI_WRITE_CMD);
- if (sc->ti_hwrev == TI_HWREV_TIGON_II) {
- TI_SETBIT(sc, TI_PCI_STATE, TI_PCISTATE_USE_MEM_RD_MULT);
- }
-
- /* Clear the read/write max DMA parameters. */
- TI_CLRBIT(sc, TI_PCI_STATE, (TI_PCISTATE_WRITE_MAXDMA|
- TI_PCISTATE_READ_MAXDMA));
-
- /* Get cache line size. */
- cacheline = CSR_READ_4(sc, TI_PCI_BIST) & 0xFF;
-
- /*
- * If the system has set enabled the PCI memory write
- * and invalidate command in the command register, set
- * the write max parameter accordingly. This is necessary
- * to use MWI with the Tigon 2.
- */
- if (CSR_READ_4(sc, TI_PCI_CMDSTAT) & PCIM_CMD_MWIEN) {
- switch(cacheline) {
- case 1:
- case 4:
- case 8:
- case 16:
- case 32:
- case 64:
- break;
- default:
- /* Disable PCI memory write and invalidate. */
- if (bootverbose)
- printf("ti%d: cache line size %d not "
- "supported; disabling PCI MWI\n",
- sc->ti_unit, cacheline);
- CSR_WRITE_4(sc, TI_PCI_CMDSTAT, CSR_READ_4(sc,
- TI_PCI_CMDSTAT) & ~PCIM_CMD_MWIEN);
- break;
- }
- }
-
-#ifdef __brokenalpha__
- /*
- * From the Alteon sample driver:
- * Must insure that we do not cross an 8K (bytes) boundary
- * for DMA reads. Our highest limit is 1K bytes. This is a
- * restriction on some ALPHA platforms with early revision
- * 21174 PCI chipsets, such as the AlphaPC 164lx
- */
- TI_SETBIT(sc, TI_PCI_STATE, pci_writemax|TI_PCI_READMAX_1024);
-#else
- TI_SETBIT(sc, TI_PCI_STATE, pci_writemax);
-#endif
-
- /* This sets the min dma param all the way up (0xff). */
- TI_SETBIT(sc, TI_PCI_STATE, TI_PCISTATE_MINDMA);
-
- if (sc->ti_hdrsplit)
- hdrsplit = TI_OPMODE_JUMBO_HDRSPLIT;
- else
- hdrsplit = 0;
-
- /* Configure DMA variables. */
-#if BYTE_ORDER == BIG_ENDIAN
- CSR_WRITE_4(sc, TI_GCR_OPMODE, TI_OPMODE_BYTESWAP_BD |
- TI_OPMODE_BYTESWAP_DATA | TI_OPMODE_WORDSWAP_BD |
- TI_OPMODE_WARN_ENB | TI_OPMODE_FATAL_ENB |
- TI_OPMODE_DONT_FRAG_JUMBO | hdrsplit);
-#else /* BYTE_ORDER */
- CSR_WRITE_4(sc, TI_GCR_OPMODE, TI_OPMODE_BYTESWAP_DATA|
- TI_OPMODE_WORDSWAP_BD|TI_OPMODE_DONT_FRAG_JUMBO|
- TI_OPMODE_WARN_ENB|TI_OPMODE_FATAL_ENB | hdrsplit);
-#endif /* BYTE_ORDER */
-
- /*
- * Only allow 1 DMA channel to be active at a time.
- * I don't think this is a good idea, but without it
- * the firmware racks up lots of nicDmaReadRingFull
- * errors. This is not compatible with hardware checksums.
- */
- if (sc->arpcom.ac_if.if_hwassist == 0)
- TI_SETBIT(sc, TI_GCR_OPMODE, TI_OPMODE_1_DMA_ACTIVE);
-
- /* Recommended settings from Tigon manual. */
- CSR_WRITE_4(sc, TI_GCR_DMA_WRITECFG, TI_DMA_STATE_THRESH_8W);
- CSR_WRITE_4(sc, TI_GCR_DMA_READCFG, TI_DMA_STATE_THRESH_8W);
-
- if (ti_64bitslot_war(sc)) {
- printf("ti%d: bios thinks we're in a 64 bit slot, "
- "but we aren't", sc->ti_unit);
- return(EINVAL);
- }
-
- return(0);
-}
-
-/*
- * Initialize the general information block and firmware, and
- * start the CPU(s) running.
- */
-static int
-ti_gibinit(sc)
- struct ti_softc *sc;
-{
- struct ti_rcb *rcb;
- int i;
- struct ifnet *ifp;
-
- ifp = &sc->arpcom.ac_if;
-
- /* Disable interrupts for now. */
- CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
-
- /* Tell the chip where to find the general information block. */
- CSR_WRITE_4(sc, TI_GCR_GENINFO_HI, 0);
- CSR_WRITE_4(sc, TI_GCR_GENINFO_LO, vtophys(&sc->ti_rdata->ti_info));
-
- /* Load the firmware into SRAM. */
- ti_loadfw(sc);
-
- /* Set up the contents of the general info and ring control blocks. */
-
- /* Set up the event ring and producer pointer. */
- rcb = &sc->ti_rdata->ti_info.ti_ev_rcb;
-
- TI_HOSTADDR(rcb->ti_hostaddr) = vtophys(&sc->ti_rdata->ti_event_ring);
- rcb->ti_flags = 0;
- TI_HOSTADDR(sc->ti_rdata->ti_info.ti_ev_prodidx_ptr) =
- vtophys(&sc->ti_ev_prodidx);
- sc->ti_ev_prodidx.ti_idx = 0;
- CSR_WRITE_4(sc, TI_GCR_EVENTCONS_IDX, 0);
- sc->ti_ev_saved_considx = 0;
-
- /* Set up the command ring and producer mailbox. */
- rcb = &sc->ti_rdata->ti_info.ti_cmd_rcb;
-
- sc->ti_rdata->ti_cmd_ring =
- (struct ti_cmd_desc *)(sc->ti_vhandle + TI_GCR_CMDRING);
- TI_HOSTADDR(rcb->ti_hostaddr) = TI_GCR_NIC_ADDR(TI_GCR_CMDRING);
- rcb->ti_flags = 0;
- rcb->ti_max_len = 0;
- for (i = 0; i < TI_CMD_RING_CNT; i++) {
- CSR_WRITE_4(sc, TI_GCR_CMDRING + (i * 4), 0);
- }
- CSR_WRITE_4(sc, TI_GCR_CMDCONS_IDX, 0);
- CSR_WRITE_4(sc, TI_MB_CMDPROD_IDX, 0);
- sc->ti_cmd_saved_prodidx = 0;
-
- /*
- * Assign the address of the stats refresh buffer.
- * We re-use the current stats buffer for this to
- * conserve memory.
- */
- TI_HOSTADDR(sc->ti_rdata->ti_info.ti_refresh_stats_ptr) =
- vtophys(&sc->ti_rdata->ti_info.ti_stats);
-
- /* Set up the standard receive ring. */
- rcb = &sc->ti_rdata->ti_info.ti_std_rx_rcb;
- TI_HOSTADDR(rcb->ti_hostaddr) = vtophys(&sc->ti_rdata->ti_rx_std_ring);
- rcb->ti_max_len = TI_FRAMELEN;
- rcb->ti_flags = 0;
- if (sc->arpcom.ac_if.if_hwassist)
- rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
- TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
- rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
-
- /* Set up the jumbo receive ring. */
- rcb = &sc->ti_rdata->ti_info.ti_jumbo_rx_rcb;
- TI_HOSTADDR(rcb->ti_hostaddr) =
- vtophys(&sc->ti_rdata->ti_rx_jumbo_ring);
-
-#ifdef TI_PRIVATE_JUMBOS
- rcb->ti_max_len = TI_JUMBO_FRAMELEN;
- rcb->ti_flags = 0;
-#else
- rcb->ti_max_len = PAGE_SIZE;
- rcb->ti_flags = TI_RCB_FLAG_USE_EXT_RX_BD;
-#endif
- if (sc->arpcom.ac_if.if_hwassist)
- rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
- TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
- rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
-
- /*
- * Set up the mini ring. Only activated on the
- * Tigon 2 but the slot in the config block is
- * still there on the Tigon 1.
- */
- rcb = &sc->ti_rdata->ti_info.ti_mini_rx_rcb;
- TI_HOSTADDR(rcb->ti_hostaddr) =
- vtophys(&sc->ti_rdata->ti_rx_mini_ring);
- rcb->ti_max_len = MHLEN - ETHER_ALIGN;
- if (sc->ti_hwrev == TI_HWREV_TIGON)
- rcb->ti_flags = TI_RCB_FLAG_RING_DISABLED;
- else
- rcb->ti_flags = 0;
- if (sc->arpcom.ac_if.if_hwassist)
- rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
- TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
- rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
-
- /*
- * Set up the receive return ring.
- */
- rcb = &sc->ti_rdata->ti_info.ti_return_rcb;
- TI_HOSTADDR(rcb->ti_hostaddr) =
- vtophys(&sc->ti_rdata->ti_rx_return_ring);
- rcb->ti_flags = 0;
- rcb->ti_max_len = TI_RETURN_RING_CNT;
- TI_HOSTADDR(sc->ti_rdata->ti_info.ti_return_prodidx_ptr) =
- vtophys(&sc->ti_return_prodidx);
-
- /*
- * Set up the tx ring. Note: for the Tigon 2, we have the option
- * of putting the transmit ring in the host's address space and
- * letting the chip DMA it instead of leaving the ring in the NIC's
- * memory and accessing it through the shared memory region. We
- * do this for the Tigon 2, but it doesn't work on the Tigon 1,
- * so we have to revert to the shared memory scheme if we detect
- * a Tigon 1 chip.
- */
- CSR_WRITE_4(sc, TI_WINBASE, TI_TX_RING_BASE);
- if (sc->ti_hwrev == TI_HWREV_TIGON) {
- sc->ti_rdata->ti_tx_ring_nic =
- (struct ti_tx_desc *)(sc->ti_vhandle + TI_WINDOW);
- }
- bzero((char *)sc->ti_rdata->ti_tx_ring,
- TI_TX_RING_CNT * sizeof(struct ti_tx_desc));
- rcb = &sc->ti_rdata->ti_info.ti_tx_rcb;
- if (sc->ti_hwrev == TI_HWREV_TIGON)
- rcb->ti_flags = 0;
- else
- rcb->ti_flags = TI_RCB_FLAG_HOST_RING;
- rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
- if (sc->arpcom.ac_if.if_hwassist)
- rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
- TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
- rcb->ti_max_len = TI_TX_RING_CNT;
- if (sc->ti_hwrev == TI_HWREV_TIGON)
- TI_HOSTADDR(rcb->ti_hostaddr) = TI_TX_RING_BASE;
- else
- TI_HOSTADDR(rcb->ti_hostaddr) =
- vtophys(&sc->ti_rdata->ti_tx_ring);
- TI_HOSTADDR(sc->ti_rdata->ti_info.ti_tx_considx_ptr) =
- vtophys(&sc->ti_tx_considx);
-
- /* Set up tuneables */
-#if 0
- if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN))
- CSR_WRITE_4(sc, TI_GCR_RX_COAL_TICKS,
- (sc->ti_rx_coal_ticks / 10));
- else
-#endif
- CSR_WRITE_4(sc, TI_GCR_RX_COAL_TICKS, sc->ti_rx_coal_ticks);
- CSR_WRITE_4(sc, TI_GCR_TX_COAL_TICKS, sc->ti_tx_coal_ticks);
- CSR_WRITE_4(sc, TI_GCR_STAT_TICKS, sc->ti_stat_ticks);
- CSR_WRITE_4(sc, TI_GCR_RX_MAX_COAL_BD, sc->ti_rx_max_coal_bds);
- CSR_WRITE_4(sc, TI_GCR_TX_MAX_COAL_BD, sc->ti_tx_max_coal_bds);
- CSR_WRITE_4(sc, TI_GCR_TX_BUFFER_RATIO, sc->ti_tx_buf_ratio);
-
- /* Turn interrupts on. */
- CSR_WRITE_4(sc, TI_GCR_MASK_INTRS, 0);
- CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0);
-
- /* Start CPU. */
- TI_CLRBIT(sc, TI_CPU_STATE, (TI_CPUSTATE_HALT|TI_CPUSTATE_STEP));
-
- return(0);
-}
-
-/*
- * Probe for a Tigon chip. Check the PCI vendor and device IDs
- * against our list and return its name if we find a match.
- */
-static int
-ti_probe(dev)
- device_t dev;
-{
- struct ti_type *t;
-
- t = ti_devs;
-
- while(t->ti_name != NULL) {
- if ((pci_get_vendor(dev) == t->ti_vid) &&
- (pci_get_device(dev) == t->ti_did)) {
- device_set_desc(dev, t->ti_name);
- return(0);
- }
- t++;
- }
-
- return(ENXIO);
-}
-
-#ifdef KLD_MODULE
-static int
-log2rndup(int len)
-{
- int log2size = 0, t = len;
- while (t > 1) {
- log2size++;
- t >>= 1;
- }
- if (len != (1 << log2size))
- log2size++;
- return log2size;
-}
-
-static int
-ti_mbuf_sanity(device_t dev)
-{
- if ((mbstat.m_msize != MSIZE) || mbstat.m_mclbytes != MCLBYTES){
- device_printf(dev, "\n");
- device_printf(dev, "This module was compiled with "
- "-DMCLSHIFT=%d -DMSIZE=%d\n", MCLSHIFT,
- MSIZE);
- device_printf(dev, "The kernel was compiled with MCLSHIFT=%d,"
- " MSIZE=%d\n", log2rndup(mbstat.m_mclbytes),
- (int)mbstat.m_msize);
- return(EINVAL);
- }
- return(0);
-}
-#endif
-
-
-static int
-ti_attach(dev)
- device_t dev;
-{
- struct ifnet *ifp;
- struct ti_softc *sc;
- int unit, error = 0, rid;
-
- sc = NULL;
-
-#ifdef KLD_MODULE
- if (ti_mbuf_sanity(dev)){
- device_printf(dev, "Module mbuf constants do not match "
- "kernel constants!\n");
- device_printf(dev, "Rebuild the module or the kernel so "
- "they match\n");
- device_printf(dev, "\n");
- error = EINVAL;
- goto fail;
- }
-#endif
-
- sc = device_get_softc(dev);
- unit = device_get_unit(dev);
-
- mtx_init(&sc->ti_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
- MTX_DEF | MTX_RECURSE);
- ifmedia_init(&sc->ifmedia, IFM_IMASK, ti_ifmedia_upd, ti_ifmedia_sts);
- sc->arpcom.ac_if.if_capabilities = IFCAP_HWCSUM | IFCAP_VLAN_HWTAGGING;
- sc->arpcom.ac_if.if_capenable = sc->arpcom.ac_if.if_capabilities;
-
- /*
- * Map control/status registers.
- */
- pci_enable_busmaster(dev);
-
- rid = TI_PCI_LOMEM;
- sc->ti_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
- 0, ~0, 1, RF_ACTIVE|PCI_RF_DENSE);
-
- if (sc->ti_res == NULL) {
- printf ("ti%d: couldn't map memory\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- sc->ti_btag = rman_get_bustag(sc->ti_res);
- sc->ti_bhandle = rman_get_bushandle(sc->ti_res);
- sc->ti_vhandle = (vm_offset_t)rman_get_virtual(sc->ti_res);
-
- /* Allocate interrupt */
- rid = 0;
-
- sc->ti_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE | RF_ACTIVE);
-
- if (sc->ti_irq == NULL) {
- printf("ti%d: couldn't map interrupt\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- sc->ti_unit = unit;
-
- if (ti_chipinit(sc)) {
- printf("ti%d: chip initialization failed\n", sc->ti_unit);
- error = ENXIO;
- goto fail;
- }
-
- /* Zero out the NIC's on-board SRAM. */
- ti_mem(sc, 0x2000, 0x100000 - 0x2000, NULL);
-
- /* Init again -- zeroing memory may have clobbered some registers. */
- if (ti_chipinit(sc)) {
- printf("ti%d: chip initialization failed\n", sc->ti_unit);
- error = ENXIO;
- goto fail;
- }
-
- /*
- * Get station address from the EEPROM. Note: the manual states
- * that the MAC address is at offset 0x8c, however the data is
- * stored as two longwords (since that's how it's loaded into
- * the NIC). This means the MAC address is actually preceded
- * by two zero bytes. We need to skip over those.
- */
- if (ti_read_eeprom(sc, (caddr_t)&sc->arpcom.ac_enaddr,
- TI_EE_MAC_OFFSET + 2, ETHER_ADDR_LEN)) {
- printf("ti%d: failed to read station address\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- /*
- * A Tigon chip was detected. Inform the world.
- */
- printf("ti%d: Ethernet address: %6D\n", unit,
- sc->arpcom.ac_enaddr, ":");
-
- /* Allocate the general information block and ring buffers. */
- sc->ti_rdata = contigmalloc(sizeof(struct ti_ring_data), M_DEVBUF,
- M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
-
- if (sc->ti_rdata == NULL) {
- printf("ti%d: no memory for list buffers!\n", sc->ti_unit);
- error = ENXIO;
- goto fail;
- }
-
- bzero(sc->ti_rdata, sizeof(struct ti_ring_data));
-
- /* Try to allocate memory for jumbo buffers. */
-#ifdef TI_PRIVATE_JUMBOS
- if (ti_alloc_jumbo_mem(sc)) {
- printf("ti%d: jumbo buffer allocation failed\n", sc->ti_unit);
- error = ENXIO;
- goto fail;
- }
-#else
- if (!jumbo_vm_init()) {
- printf("ti%d: VM initialization failed!\n", sc->ti_unit);
- error = ENOMEM;
- goto fail;
- }
-#endif
-
- /*
- * We really need a better way to tell a 1000baseTX card
- * from a 1000baseSX one, since in theory there could be
- * OEMed 1000baseTX cards from lame vendors who aren't
- * clever enough to change the PCI ID. For the moment
- * though, the AceNIC is the only copper card available.
- */
- if (pci_get_vendor(dev) == ALT_VENDORID &&
- pci_get_device(dev) == ALT_DEVICEID_ACENIC_COPPER)
- sc->ti_copper = 1;
- /* Ok, it's not the only copper card available. */
- if (pci_get_vendor(dev) == NG_VENDORID &&
- pci_get_device(dev) == NG_DEVICEID_GA620T)
- sc->ti_copper = 1;
-
- /* Set default tuneable values. */
- sc->ti_stat_ticks = 2 * TI_TICKS_PER_SEC;
-#if 0
- sc->ti_rx_coal_ticks = TI_TICKS_PER_SEC / 5000;
-#endif
- sc->ti_rx_coal_ticks = 170;
- sc->ti_tx_coal_ticks = TI_TICKS_PER_SEC / 500;
- sc->ti_rx_max_coal_bds = 64;
-#if 0
- sc->ti_tx_max_coal_bds = 128;
-#endif
- sc->ti_tx_max_coal_bds = 32;
- sc->ti_tx_buf_ratio = 21;
-
- /* Set up ifnet structure */
- ifp = &sc->arpcom.ac_if;
- ifp->if_softc = sc;
- ifp->if_unit = sc->ti_unit;
- ifp->if_name = "ti";
- ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
- tis[unit] = sc;
- ifp->if_ioctl = ti_ioctl;
- ifp->if_output = ether_output;
- ifp->if_start = ti_start;
- ifp->if_watchdog = ti_watchdog;
- ifp->if_init = ti_init;
- ifp->if_mtu = ETHERMTU;
- ifp->if_snd.ifq_maxlen = TI_TX_RING_CNT - 1;
-
- /* Set up ifmedia support. */
- if (sc->ti_copper) {
- /*
- * Copper cards allow manual 10/100 mode selection,
- * but not manual 1000baseTX mode selection. Why?
- * Becuase currently there's no way to specify the
- * master/slave setting through the firmware interface,
- * so Alteon decided to just bag it and handle it
- * via autonegotiation.
- */
- ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL);
- ifmedia_add(&sc->ifmedia,
- IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL);
- ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_TX, 0, NULL);
- ifmedia_add(&sc->ifmedia,
- IFM_ETHER|IFM_100_TX|IFM_FDX, 0, NULL);
- ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_T, 0, NULL);
- ifmedia_add(&sc->ifmedia,
- IFM_ETHER|IFM_1000_T|IFM_FDX, 0, NULL);
- } else {
- /* Fiber cards don't support 10/100 modes. */
- ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_SX, 0, NULL);
- ifmedia_add(&sc->ifmedia,
- IFM_ETHER|IFM_1000_SX|IFM_FDX, 0, NULL);
- }
- ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL);
- ifmedia_set(&sc->ifmedia, IFM_ETHER|IFM_AUTO);
-
- /*
- * We're assuming here that card initialization is a sequential
- * thing. If it isn't, multiple cards probing at the same time
- * could stomp on the list of softcs here.
- */
- /*
- * If this is the first card to be initialized, initialize the
- * softc queue.
- */
- if (unit == 0)
- STAILQ_INIT(&ti_sc_list);
-
- STAILQ_INSERT_TAIL(&ti_sc_list, sc, ti_links);
-
- /* Register the device */
- sc->dev = make_dev(&ti_cdevsw, sc->ti_unit, UID_ROOT, GID_OPERATOR,
- 0600, "ti%d", sc->ti_unit);
-
- /*
- * Call MI attach routine.
- */
- ether_ifattach(ifp, sc->arpcom.ac_enaddr);
-
- /* Hook interrupt last to avoid having to lock softc */
- error = bus_setup_intr(dev, sc->ti_irq, INTR_TYPE_NET,
- ti_intr, sc, &sc->ti_intrhand);
-
- if (error) {
- printf("ti%d: couldn't set up irq\n", unit);
- ether_ifdetach(ifp);
- goto fail;
- }
-
-fail:
- if (sc && error)
- ti_detach(dev);
-
- return(error);
-}
-
-/*
- * Verify that our character special device is not currently
- * open. Also track down any cached vnodes & kill them before
- * the module is unloaded
- */
-static int
-ti_unref_special(device_t dev)
-{
- struct vnode *ti_vn;
- int count;
- struct ti_softc *sc = sc = device_get_softc(dev);
-
- if (!vfinddev(sc->dev, VCHR, &ti_vn)) {
- return 0;
- }
-
- if ((count = vcount(ti_vn))) {
- device_printf(dev, "%d refs to special device, "
- "denying unload\n", count);
- return count;
- }
- /* now we know that there's a vnode in the cache. We hunt it
- down and kill it now, before unloading */
- vgone(ti_vn);
- return(0);
-}
-
-/*
- * Shutdown hardware and free up resources. This can be called any
- * time after the mutex has been initialized. It is called in both
- * the error case in attach and the normal detach case so it needs
- * to be careful about only freeing resources that have actually been
- * allocated.
- */
-static int
-ti_detach(dev)
- device_t dev;
-{
- struct ti_softc *sc;
- struct ifnet *ifp;
-
- if (ti_unref_special(dev))
- return EBUSY;
-
- sc = device_get_softc(dev);
- KASSERT(mtx_initialized(&sc->ti_mtx), ("ti mutex not initialized"));
- TI_LOCK(sc);
- ifp = &sc->arpcom.ac_if;
-
- /* These should only be active if attach succeeded */
- if (device_is_attached(dev)) {
- ti_stop(sc);
- ether_ifdetach(ifp);
- bus_generic_detach(dev);
- }
- ifmedia_removeall(&sc->ifmedia);
-
- if (sc->ti_intrhand)
- bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand);
- if (sc->ti_irq)
- bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
- if (sc->ti_res) {
- bus_release_resource(dev, SYS_RES_MEMORY, TI_PCI_LOMEM,
- sc->ti_res);
- }
-
-#ifdef TI_PRIVATE_JUMBOS
- if (sc->ti_cdata.ti_jumbo_buf)
- contigfree(sc->ti_cdata.ti_jumbo_buf, TI_JMEM, M_DEVBUF);
-#endif
- if (sc->ti_rdata)
- contigfree(sc->ti_rdata, sizeof(struct ti_ring_data), M_DEVBUF);
-
- TI_UNLOCK(sc);
- mtx_destroy(&sc->ti_mtx);
-
- return(0);
-}
-
-#ifdef TI_JUMBO_HDRSPLIT
-/*
- * If hdr_len is 0, that means that header splitting wasn't done on
- * this packet for some reason. The two most likely reasons are that
- * the protocol isn't a supported protocol for splitting, or this
- * packet had a fragment offset that wasn't 0.
- *
- * The header length, if it is non-zero, will always be the length of
- * the headers on the packet, but that length could be longer than the
- * first mbuf. So we take the minimum of the two as the actual
- * length.
- */
-static __inline void
-ti_hdr_split(struct mbuf *top, int hdr_len, int pkt_len, int idx)
-{
- int i = 0;
- int lengths[4] = {0, 0, 0, 0};
- struct mbuf *m, *mp;
-
- if (hdr_len != 0)
- top->m_len = min(hdr_len, top->m_len);
- pkt_len -= top->m_len;
- lengths[i++] = top->m_len;
-
- mp = top;
- for (m = top->m_next; m && pkt_len; m = m->m_next) {
- m->m_len = m->m_ext.ext_size = min(m->m_len, pkt_len);
- pkt_len -= m->m_len;
- lengths[i++] = m->m_len;
- mp = m;
- }
-
-#if 0
- if (hdr_len != 0)
- printf("got split packet: ");
- else
- printf("got non-split packet: ");
-
- printf("%d,%d,%d,%d = %d\n", lengths[0],
- lengths[1], lengths[2], lengths[3],
- lengths[0] + lengths[1] + lengths[2] +
- lengths[3]);
-#endif
-
- if (pkt_len)
- panic("header splitting didn't");
-
- if (m) {
- m_freem(m);
- mp->m_next = NULL;
-
- }
- if (mp->m_next != NULL)
- panic("ti_hdr_split: last mbuf in chain should be null");
-}
-#endif /* TI_JUMBO_HDRSPLIT */
-
-/*
- * Frame reception handling. This is called if there's a frame
- * on the receive return list.
- *
- * Note: we have to be able to handle three possibilities here:
- * 1) the frame is from the mini receive ring (can only happen)
- * on Tigon 2 boards)
- * 2) the frame is from the jumbo recieve ring
- * 3) the frame is from the standard receive ring
- */
-
-static void
-ti_rxeof(sc)
- struct ti_softc *sc;
-{
- struct ifnet *ifp;
- struct ti_cmd_desc cmd;
-
- ifp = &sc->arpcom.ac_if;
-
- while(sc->ti_rx_saved_considx != sc->ti_return_prodidx.ti_idx) {
- struct ti_rx_desc *cur_rx;
- u_int32_t rxidx;
- struct ether_header *eh;
- struct mbuf *m = NULL;
- u_int16_t vlan_tag = 0;
- int have_tag = 0;
-
- cur_rx =
- &sc->ti_rdata->ti_rx_return_ring[sc->ti_rx_saved_considx];
- rxidx = cur_rx->ti_idx;
- TI_INC(sc->ti_rx_saved_considx, TI_RETURN_RING_CNT);
-
- if (cur_rx->ti_flags & TI_BDFLAG_VLAN_TAG) {
- have_tag = 1;
- vlan_tag = cur_rx->ti_vlan_tag & 0xfff;
- }
-
- if (cur_rx->ti_flags & TI_BDFLAG_JUMBO_RING) {
-
- TI_INC(sc->ti_jumbo, TI_JUMBO_RX_RING_CNT);
- m = sc->ti_cdata.ti_rx_jumbo_chain[rxidx];
- sc->ti_cdata.ti_rx_jumbo_chain[rxidx] = NULL;
- if (cur_rx->ti_flags & TI_BDFLAG_ERROR) {
- ifp->if_ierrors++;
- ti_newbuf_jumbo(sc, sc->ti_jumbo, m);
- continue;
- }
- if (ti_newbuf_jumbo(sc, sc->ti_jumbo, NULL) == ENOBUFS) {
- ifp->if_ierrors++;
- ti_newbuf_jumbo(sc, sc->ti_jumbo, m);
- continue;
- }
-#ifdef TI_PRIVATE_JUMBOS
- m->m_len = cur_rx->ti_len;
-#else /* TI_PRIVATE_JUMBOS */
-#ifdef TI_JUMBO_HDRSPLIT
- if (sc->ti_hdrsplit)
- ti_hdr_split(m, TI_HOSTADDR(cur_rx->ti_addr),
- cur_rx->ti_len, rxidx);
- else
-#endif /* TI_JUMBO_HDRSPLIT */
- m_adj(m, cur_rx->ti_len - m->m_pkthdr.len);
-#endif /* TI_PRIVATE_JUMBOS */
- } else if (cur_rx->ti_flags & TI_BDFLAG_MINI_RING) {
- TI_INC(sc->ti_mini, TI_MINI_RX_RING_CNT);
- m = sc->ti_cdata.ti_rx_mini_chain[rxidx];
- sc->ti_cdata.ti_rx_mini_chain[rxidx] = NULL;
- if (cur_rx->ti_flags & TI_BDFLAG_ERROR) {
- ifp->if_ierrors++;
- ti_newbuf_mini(sc, sc->ti_mini, m);
- continue;
- }
- if (ti_newbuf_mini(sc, sc->ti_mini, NULL) == ENOBUFS) {
- ifp->if_ierrors++;
- ti_newbuf_mini(sc, sc->ti_mini, m);
- continue;
- }
- m->m_len = cur_rx->ti_len;
- } else {
- TI_INC(sc->ti_std, TI_STD_RX_RING_CNT);
- m = sc->ti_cdata.ti_rx_std_chain[rxidx];
- sc->ti_cdata.ti_rx_std_chain[rxidx] = NULL;
- if (cur_rx->ti_flags & TI_BDFLAG_ERROR) {
- ifp->if_ierrors++;
- ti_newbuf_std(sc, sc->ti_std, m);
- continue;
- }
- if (ti_newbuf_std(sc, sc->ti_std, NULL) == ENOBUFS) {
- ifp->if_ierrors++;
- ti_newbuf_std(sc, sc->ti_std, m);
- continue;
- }
- m->m_len = cur_rx->ti_len;
- }
-
- m->m_pkthdr.len = cur_rx->ti_len;
- ifp->if_ipackets++;
- eh = mtod(m, struct ether_header *);
- m->m_pkthdr.rcvif = ifp;
-
- if (ifp->if_hwassist) {
- m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED |
- CSUM_DATA_VALID;
- if ((cur_rx->ti_ip_cksum ^ 0xffff) == 0)
- m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
- m->m_pkthdr.csum_data = cur_rx->ti_tcp_udp_cksum;
- }
-
- /*
- * If we received a packet with a vlan tag,
- * tag it before passing the packet upward.
- */
- if (have_tag)
- VLAN_INPUT_TAG(ifp, m, vlan_tag, continue);
- (*ifp->if_input)(ifp, m);
- }
-
- /* Only necessary on the Tigon 1. */
- if (sc->ti_hwrev == TI_HWREV_TIGON)
- CSR_WRITE_4(sc, TI_GCR_RXRETURNCONS_IDX,
- sc->ti_rx_saved_considx);
-
- TI_UPDATE_STDPROD(sc, sc->ti_std);
- TI_UPDATE_MINIPROD(sc, sc->ti_mini);
- TI_UPDATE_JUMBOPROD(sc, sc->ti_jumbo);
-
- return;
-}
-
-static void
-ti_txeof(sc)
- struct ti_softc *sc;
-{
- struct ti_tx_desc *cur_tx = NULL;
- struct ifnet *ifp;
-
- ifp = &sc->arpcom.ac_if;
-
- /*
- * Go through our tx ring and free mbufs for those
- * frames that have been sent.
- */
- while (sc->ti_tx_saved_considx != sc->ti_tx_considx.ti_idx) {
- u_int32_t idx = 0;
-
- idx = sc->ti_tx_saved_considx;
- if (sc->ti_hwrev == TI_HWREV_TIGON) {
- if (idx > 383)
- CSR_WRITE_4(sc, TI_WINBASE,
- TI_TX_RING_BASE + 6144);
- else if (idx > 255)
- CSR_WRITE_4(sc, TI_WINBASE,
- TI_TX_RING_BASE + 4096);
- else if (idx > 127)
- CSR_WRITE_4(sc, TI_WINBASE,
- TI_TX_RING_BASE + 2048);
- else
- CSR_WRITE_4(sc, TI_WINBASE,
- TI_TX_RING_BASE);
- cur_tx = &sc->ti_rdata->ti_tx_ring_nic[idx % 128];
- } else
- cur_tx = &sc->ti_rdata->ti_tx_ring[idx];
- if (cur_tx->ti_flags & TI_BDFLAG_END)
- ifp->if_opackets++;
- if (sc->ti_cdata.ti_tx_chain[idx] != NULL) {
- m_freem(sc->ti_cdata.ti_tx_chain[idx]);
- sc->ti_cdata.ti_tx_chain[idx] = NULL;
- }
- sc->ti_txcnt--;
- TI_INC(sc->ti_tx_saved_considx, TI_TX_RING_CNT);
- ifp->if_timer = 0;
- }
-
- if (cur_tx != NULL)
- ifp->if_flags &= ~IFF_OACTIVE;
-
- return;
-}
-
-static void
-ti_intr(xsc)
- void *xsc;
-{
- struct ti_softc *sc;
- struct ifnet *ifp;
-
- sc = xsc;
- TI_LOCK(sc);
- ifp = &sc->arpcom.ac_if;
-
-/*#ifdef notdef*/
- /* Avoid this for now -- checking this register is expensive. */
- /* Make sure this is really our interrupt. */
- if (!(CSR_READ_4(sc, TI_MISC_HOST_CTL) & TI_MHC_INTSTATE)) {
- TI_UNLOCK(sc);
- return;
- }
-/*#endif*/
-
- /* Ack interrupt and stop others from occuring. */
- CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
-
- if (ifp->if_flags & IFF_RUNNING) {
- /* Check RX return ring producer/consumer */
- ti_rxeof(sc);
-
- /* Check TX ring producer/consumer */
- ti_txeof(sc);
- }
-
- ti_handle_events(sc);
-
- /* Re-enable interrupts. */
- CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0);
-
- if (ifp->if_flags & IFF_RUNNING && ifp->if_snd.ifq_head != NULL)
- ti_start(ifp);
-
- TI_UNLOCK(sc);
-
- return;
-}
-
-static void
-ti_stats_update(sc)
- struct ti_softc *sc;
-{
- struct ifnet *ifp;
-
- ifp = &sc->arpcom.ac_if;
-
- ifp->if_collisions +=
- (sc->ti_rdata->ti_info.ti_stats.dot3StatsSingleCollisionFrames +
- sc->ti_rdata->ti_info.ti_stats.dot3StatsMultipleCollisionFrames +
- sc->ti_rdata->ti_info.ti_stats.dot3StatsExcessiveCollisions +
- sc->ti_rdata->ti_info.ti_stats.dot3StatsLateCollisions) -
- ifp->if_collisions;
-
- return;
-}
-
-/*
- * Encapsulate an mbuf chain in the tx ring by coupling the mbuf data
- * pointers to descriptors.
- */
-static int
-ti_encap(sc, m_head, txidx)
- struct ti_softc *sc;
- struct mbuf *m_head;
- u_int32_t *txidx;
-{
- struct ti_tx_desc *f = NULL;
- struct mbuf *m;
- u_int32_t frag, cur, cnt = 0;
- u_int16_t csum_flags = 0;
- struct m_tag *mtag;
-
- m = m_head;
- cur = frag = *txidx;
-
- if (m_head->m_pkthdr.csum_flags) {
- if (m_head->m_pkthdr.csum_flags & CSUM_IP)
- csum_flags |= TI_BDFLAG_IP_CKSUM;
- if (m_head->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
- csum_flags |= TI_BDFLAG_TCP_UDP_CKSUM;
- if (m_head->m_flags & M_LASTFRAG)
- csum_flags |= TI_BDFLAG_IP_FRAG_END;
- else if (m_head->m_flags & M_FRAG)
- csum_flags |= TI_BDFLAG_IP_FRAG;
- }
-
- mtag = VLAN_OUTPUT_TAG(&sc->arpcom.ac_if, m);
-
- /*
- * Start packing the mbufs in this chain into
- * the fragment pointers. Stop when we run out
- * of fragments or hit the end of the mbuf chain.
- */
- for (m = m_head; m != NULL; m = m->m_next) {
- if (m->m_len != 0) {
- if (sc->ti_hwrev == TI_HWREV_TIGON) {
- if (frag > 383)
- CSR_WRITE_4(sc, TI_WINBASE,
- TI_TX_RING_BASE + 6144);
- else if (frag > 255)
- CSR_WRITE_4(sc, TI_WINBASE,
- TI_TX_RING_BASE + 4096);
- else if (frag > 127)
- CSR_WRITE_4(sc, TI_WINBASE,
- TI_TX_RING_BASE + 2048);
- else
- CSR_WRITE_4(sc, TI_WINBASE,
- TI_TX_RING_BASE);
- f = &sc->ti_rdata->ti_tx_ring_nic[frag % 128];
- } else
- f = &sc->ti_rdata->ti_tx_ring[frag];
- if (sc->ti_cdata.ti_tx_chain[frag] != NULL)
- break;
- TI_HOSTADDR(f->ti_addr) = vtophys(mtod(m, vm_offset_t));
- f->ti_len = m->m_len;
- f->ti_flags = csum_flags;
-
- if (mtag != NULL) {
- f->ti_flags |= TI_BDFLAG_VLAN_TAG;
- f->ti_vlan_tag = VLAN_TAG_VALUE(mtag) & 0xfff;
- } else {
- f->ti_vlan_tag = 0;
- }
-
- /*
- * Sanity check: avoid coming within 16 descriptors
- * of the end of the ring.
- */
- if ((TI_TX_RING_CNT - (sc->ti_txcnt + cnt)) < 16)
- return(ENOBUFS);
- cur = frag;
- TI_INC(frag, TI_TX_RING_CNT);
- cnt++;
- }
- }
-
- if (m != NULL)
- return(ENOBUFS);
-
- if (frag == sc->ti_tx_saved_considx)
- return(ENOBUFS);
-
- if (sc->ti_hwrev == TI_HWREV_TIGON)
- sc->ti_rdata->ti_tx_ring_nic[cur % 128].ti_flags |=
- TI_BDFLAG_END;
- else
- sc->ti_rdata->ti_tx_ring[cur].ti_flags |= TI_BDFLAG_END;
- sc->ti_cdata.ti_tx_chain[cur] = m_head;
- sc->ti_txcnt += cnt;
-
- *txidx = frag;
-
- return(0);
-}
-
-/*
- * Main transmit routine. To avoid having to do mbuf copies, we put pointers
- * to the mbuf data regions directly in the transmit descriptors.
- */
-static void
-ti_start(ifp)
- struct ifnet *ifp;
-{
- struct ti_softc *sc;
- struct mbuf *m_head = NULL;
- u_int32_t prodidx = 0;
-
- sc = ifp->if_softc;
- TI_LOCK(sc);
-
- prodidx = CSR_READ_4(sc, TI_MB_SENDPROD_IDX);
-
- while(sc->ti_cdata.ti_tx_chain[prodidx] == NULL) {
- IF_DEQUEUE(&ifp->if_snd, m_head);
- if (m_head == NULL)
- break;
-
- /*
- * XXX
- * safety overkill. If this is a fragmented packet chain
- * with delayed TCP/UDP checksums, then only encapsulate
- * it if we have enough descriptors to handle the entire
- * chain at once.
- * (paranoia -- may not actually be needed)
- */
- if (m_head->m_flags & M_FIRSTFRAG &&
- m_head->m_pkthdr.csum_flags & (CSUM_DELAY_DATA)) {
- if ((TI_TX_RING_CNT - sc->ti_txcnt) <
- m_head->m_pkthdr.csum_data + 16) {
- IF_PREPEND(&ifp->if_snd, m_head);
- ifp->if_flags |= IFF_OACTIVE;
- break;
- }
- }
-
- /*
- * Pack the data into the transmit ring. If we
- * don't have room, set the OACTIVE flag and wait
- * for the NIC to drain the ring.
- */
- if (ti_encap(sc, m_head, &prodidx)) {
- IF_PREPEND(&ifp->if_snd, m_head);
- ifp->if_flags |= IFF_OACTIVE;
- break;
- }
-
- /*
- * If there's a BPF listener, bounce a copy of this frame
- * to him.
- */
- BPF_MTAP(ifp, m_head);
- }
-
- /* Transmit */
- CSR_WRITE_4(sc, TI_MB_SENDPROD_IDX, prodidx);
-
- /*
- * Set a timeout in case the chip goes out to lunch.
- */
- ifp->if_timer = 5;
- TI_UNLOCK(sc);
-
- return;
-}
-
-static void
-ti_init(xsc)
- void *xsc;
-{
- struct ti_softc *sc = xsc;
-
- /* Cancel pending I/O and flush buffers. */
- ti_stop(sc);
-
- TI_LOCK(sc);
- /* Init the gen info block, ring control blocks and firmware. */
- if (ti_gibinit(sc)) {
- printf("ti%d: initialization failure\n", sc->ti_unit);
- TI_UNLOCK(sc);
- return;
- }
-
- TI_UNLOCK(sc);
-
- return;
-}
-
-static void ti_init2(sc)
- struct ti_softc *sc;
-{
- struct ti_cmd_desc cmd;
- struct ifnet *ifp;
- u_int16_t *m;
- struct ifmedia *ifm;
- int tmp;
-
- ifp = &sc->arpcom.ac_if;
-
- /* Specify MTU and interface index. */
- CSR_WRITE_4(sc, TI_GCR_IFINDEX, ifp->if_unit);
- CSR_WRITE_4(sc, TI_GCR_IFMTU, ifp->if_mtu +
- ETHER_HDR_LEN + ETHER_CRC_LEN);
- TI_DO_CMD(TI_CMD_UPDATE_GENCOM, 0, 0);
-
- /* Load our MAC address. */
- m = (u_int16_t *)&sc->arpcom.ac_enaddr[0];
- CSR_WRITE_4(sc, TI_GCR_PAR0, htons(m[0]));
- CSR_WRITE_4(sc, TI_GCR_PAR1, (htons(m[1]) << 16) | htons(m[2]));
- TI_DO_CMD(TI_CMD_SET_MAC_ADDR, 0, 0);
-
- /* Enable or disable promiscuous mode as needed. */
- if (ifp->if_flags & IFF_PROMISC) {
- TI_DO_CMD(TI_CMD_SET_PROMISC_MODE, TI_CMD_CODE_PROMISC_ENB, 0);
- } else {
- TI_DO_CMD(TI_CMD_SET_PROMISC_MODE, TI_CMD_CODE_PROMISC_DIS, 0);
- }
-
- /* Program multicast filter. */
- ti_setmulti(sc);
-
- /*
- * If this is a Tigon 1, we should tell the
- * firmware to use software packet filtering.
- */
- if (sc->ti_hwrev == TI_HWREV_TIGON) {
- TI_DO_CMD(TI_CMD_FDR_FILTERING, TI_CMD_CODE_FILT_ENB, 0);
- }
-
- /* Init RX ring. */
- ti_init_rx_ring_std(sc);
-
- /* Init jumbo RX ring. */
- if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN))
- ti_init_rx_ring_jumbo(sc);
-
- /*
- * If this is a Tigon 2, we can also configure the
- * mini ring.
- */
- if (sc->ti_hwrev == TI_HWREV_TIGON_II)
- ti_init_rx_ring_mini(sc);
-
- CSR_WRITE_4(sc, TI_GCR_RXRETURNCONS_IDX, 0);
- sc->ti_rx_saved_considx = 0;
-
- /* Init TX ring. */
- ti_init_tx_ring(sc);
-
- /* Tell firmware we're alive. */
- TI_DO_CMD(TI_CMD_HOST_STATE, TI_CMD_CODE_STACK_UP, 0);
-
- /* Enable host interrupts. */
- CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0);
-
- ifp->if_flags |= IFF_RUNNING;
- ifp->if_flags &= ~IFF_OACTIVE;
-
- /*
- * Make sure to set media properly. We have to do this
- * here since we have to issue commands in order to set
- * the link negotiation and we can't issue commands until
- * the firmware is running.
- */
- ifm = &sc->ifmedia;
- tmp = ifm->ifm_media;
- ifm->ifm_media = ifm->ifm_cur->ifm_media;
- ti_ifmedia_upd(ifp);
- ifm->ifm_media = tmp;
-
- return;
-}
-
-/*
- * Set media options.
- */
-static int
-ti_ifmedia_upd(ifp)
- struct ifnet *ifp;
-{
- struct ti_softc *sc;
- struct ifmedia *ifm;
- struct ti_cmd_desc cmd;
- u_int32_t flowctl;
-
- sc = ifp->if_softc;
- ifm = &sc->ifmedia;
-
- if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
- return(EINVAL);
-
- flowctl = 0;
-
- switch(IFM_SUBTYPE(ifm->ifm_media)) {
- case IFM_AUTO:
- /*
- * Transmit flow control doesn't work on the Tigon 1.
- */
- flowctl = TI_GLNK_RX_FLOWCTL_Y;
-
- /*
- * Transmit flow control can also cause problems on the
- * Tigon 2, apparantly with both the copper and fiber
- * boards. The symptom is that the interface will just
- * hang. This was reproduced with Alteon 180 switches.
- */
-#if 0
- if (sc->ti_hwrev != TI_HWREV_TIGON)
- flowctl |= TI_GLNK_TX_FLOWCTL_Y;
-#endif
-
- CSR_WRITE_4(sc, TI_GCR_GLINK, TI_GLNK_PREF|TI_GLNK_1000MB|
- TI_GLNK_FULL_DUPLEX| flowctl |
- TI_GLNK_AUTONEGENB|TI_GLNK_ENB);
-
- flowctl = TI_LNK_RX_FLOWCTL_Y;
-#if 0
- if (sc->ti_hwrev != TI_HWREV_TIGON)
- flowctl |= TI_LNK_TX_FLOWCTL_Y;
-#endif
-
- CSR_WRITE_4(sc, TI_GCR_LINK, TI_LNK_100MB|TI_LNK_10MB|
- TI_LNK_FULL_DUPLEX|TI_LNK_HALF_DUPLEX| flowctl |
- TI_LNK_AUTONEGENB|TI_LNK_ENB);
- TI_DO_CMD(TI_CMD_LINK_NEGOTIATION,
- TI_CMD_CODE_NEGOTIATE_BOTH, 0);
- break;
- case IFM_1000_SX:
- case IFM_1000_T:
- flowctl = TI_GLNK_RX_FLOWCTL_Y;
-#if 0
- if (sc->ti_hwrev != TI_HWREV_TIGON)
- flowctl |= TI_GLNK_TX_FLOWCTL_Y;
-#endif
-
- CSR_WRITE_4(sc, TI_GCR_GLINK, TI_GLNK_PREF|TI_GLNK_1000MB|
- flowctl |TI_GLNK_ENB);
- CSR_WRITE_4(sc, TI_GCR_LINK, 0);
- if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) {
- TI_SETBIT(sc, TI_GCR_GLINK, TI_GLNK_FULL_DUPLEX);
- }
- TI_DO_CMD(TI_CMD_LINK_NEGOTIATION,
- TI_CMD_CODE_NEGOTIATE_GIGABIT, 0);
- break;
- case IFM_100_FX:
- case IFM_10_FL:
- case IFM_100_TX:
- case IFM_10_T:
- flowctl = TI_LNK_RX_FLOWCTL_Y;
-#if 0
- if (sc->ti_hwrev != TI_HWREV_TIGON)
- flowctl |= TI_LNK_TX_FLOWCTL_Y;
-#endif
-
- CSR_WRITE_4(sc, TI_GCR_GLINK, 0);
- CSR_WRITE_4(sc, TI_GCR_LINK, TI_LNK_ENB|TI_LNK_PREF|flowctl);
- if (IFM_SUBTYPE(ifm->ifm_media) == IFM_100_FX ||
- IFM_SUBTYPE(ifm->ifm_media) == IFM_100_TX) {
- TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_100MB);
- } else {
- TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_10MB);
- }
- if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) {
- TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_FULL_DUPLEX);
- } else {
- TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_HALF_DUPLEX);
- }
- TI_DO_CMD(TI_CMD_LINK_NEGOTIATION,
- TI_CMD_CODE_NEGOTIATE_10_100, 0);
- break;
- }
-
- return(0);
-}
-
-/*
- * Report current media status.
- */
-static void
-ti_ifmedia_sts(ifp, ifmr)
- struct ifnet *ifp;
- struct ifmediareq *ifmr;
-{
- struct ti_softc *sc;
- u_int32_t media = 0;
-
- sc = ifp->if_softc;
-
- ifmr->ifm_status = IFM_AVALID;
- ifmr->ifm_active = IFM_ETHER;
-
- if (sc->ti_linkstat == TI_EV_CODE_LINK_DOWN)
- return;
-
- ifmr->ifm_status |= IFM_ACTIVE;
-
- if (sc->ti_linkstat == TI_EV_CODE_GIG_LINK_UP) {
- media = CSR_READ_4(sc, TI_GCR_GLINK_STAT);
- if (sc->ti_copper)
- ifmr->ifm_active |= IFM_1000_T;
- else
- ifmr->ifm_active |= IFM_1000_SX;
- if (media & TI_GLNK_FULL_DUPLEX)
- ifmr->ifm_active |= IFM_FDX;
- else
- ifmr->ifm_active |= IFM_HDX;
- } else if (sc->ti_linkstat == TI_EV_CODE_LINK_UP) {
- media = CSR_READ_4(sc, TI_GCR_LINK_STAT);
- if (sc->ti_copper) {
- if (media & TI_LNK_100MB)
- ifmr->ifm_active |= IFM_100_TX;
- if (media & TI_LNK_10MB)
- ifmr->ifm_active |= IFM_10_T;
- } else {
- if (media & TI_LNK_100MB)
- ifmr->ifm_active |= IFM_100_FX;
- if (media & TI_LNK_10MB)
- ifmr->ifm_active |= IFM_10_FL;
- }
- if (media & TI_LNK_FULL_DUPLEX)
- ifmr->ifm_active |= IFM_FDX;
- if (media & TI_LNK_HALF_DUPLEX)
- ifmr->ifm_active |= IFM_HDX;
- }
-
- return;
-}
-
-static int
-ti_ioctl(ifp, command, data)
- struct ifnet *ifp;
- u_long command;
- caddr_t data;
-{
- struct ti_softc *sc = ifp->if_softc;
- struct ifreq *ifr = (struct ifreq *) data;
- int mask, error = 0;
- struct ti_cmd_desc cmd;
-
- TI_LOCK(sc);
-
- switch(command) {
- case SIOCSIFMTU:
- if (ifr->ifr_mtu > TI_JUMBO_MTU)
- error = EINVAL;
- else {
- ifp->if_mtu = ifr->ifr_mtu;
- ti_init(sc);
- }
- break;
- case SIOCSIFFLAGS:
- if (ifp->if_flags & IFF_UP) {
- /*
- * If only the state of the PROMISC flag changed,
- * then just use the 'set promisc mode' command
- * instead of reinitializing the entire NIC. Doing
- * a full re-init means reloading the firmware and
- * waiting for it to start up, which may take a
- * second or two.
- */
- if (ifp->if_flags & IFF_RUNNING &&
- ifp->if_flags & IFF_PROMISC &&
- !(sc->ti_if_flags & IFF_PROMISC)) {
- TI_DO_CMD(TI_CMD_SET_PROMISC_MODE,
- TI_CMD_CODE_PROMISC_ENB, 0);
- } else if (ifp->if_flags & IFF_RUNNING &&
- !(ifp->if_flags & IFF_PROMISC) &&
- sc->ti_if_flags & IFF_PROMISC) {
- TI_DO_CMD(TI_CMD_SET_PROMISC_MODE,
- TI_CMD_CODE_PROMISC_DIS, 0);
- } else
- ti_init(sc);
- } else {
- if (ifp->if_flags & IFF_RUNNING) {
- ti_stop(sc);
- }
- }
- sc->ti_if_flags = ifp->if_flags;
- error = 0;
- break;
- case SIOCADDMULTI:
- case SIOCDELMULTI:
- if (ifp->if_flags & IFF_RUNNING) {
- ti_setmulti(sc);
- error = 0;
- }
- break;
- case SIOCSIFMEDIA:
- case SIOCGIFMEDIA:
- error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, command);
- break;
- case SIOCSIFCAP:
- mask = ifr->ifr_reqcap ^ ifp->if_capenable;
- if (mask & IFCAP_HWCSUM) {
- if (IFCAP_HWCSUM & ifp->if_capenable)
- ifp->if_capenable &= ~IFCAP_HWCSUM;
- else
- ifp->if_capenable |= IFCAP_HWCSUM;
- if (ifp->if_flags & IFF_RUNNING)
- ti_init(sc);
- }
- error = 0;
- break;
- default:
- error = ether_ioctl(ifp, command, data);
- break;
- }
-
- TI_UNLOCK(sc);
-
- return(error);
-}
-
-static int
-ti_open(dev_t dev, int flags, int fmt, struct thread *td)
-{
- int unit;
- struct ti_softc *sc;
-
- unit = minor(dev) & 0xff;
-
- sc = ti_lookup_softc(unit);
-
- if (sc == NULL)
- return(ENODEV);
-
- TI_LOCK(sc);
- sc->ti_flags |= TI_FLAG_DEBUGING;
- TI_UNLOCK(sc);
-
- return(0);
-}
-
-static int
-ti_close(dev_t dev, int flag, int fmt, struct thread *td)
-{
- int unit;
- struct ti_softc *sc;
-
- unit = minor(dev) & 0xff;
-
- sc = ti_lookup_softc(unit);
-
- if (sc == NULL)
- return(ENODEV);
-
- TI_LOCK(sc);
- sc->ti_flags &= ~TI_FLAG_DEBUGING;
- TI_UNLOCK(sc);
-
- return(0);
-}
-
-/*
- * This ioctl routine goes along with the Tigon character device.
- */
-static int
-ti_ioctl2(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
-{
- int unit, error;
- struct ti_softc *sc;
-
- unit = minor(dev) & 0xff;
-
- sc = ti_lookup_softc(unit);
-
- if (sc == NULL)
- return(ENODEV);
-
- error = 0;
-
- switch(cmd) {
- case TIIOCGETSTATS:
- {
- struct ti_stats *outstats;
-
- outstats = (struct ti_stats *)addr;
-
- bcopy(&sc->ti_rdata->ti_info.ti_stats, outstats,
- sizeof(struct ti_stats));
- break;
- }
- case TIIOCGETPARAMS:
- {
- struct ti_params *params;
-
- params = (struct ti_params *)addr;
-
- params->ti_stat_ticks = sc->ti_stat_ticks;
- params->ti_rx_coal_ticks = sc->ti_rx_coal_ticks;
- params->ti_tx_coal_ticks = sc->ti_tx_coal_ticks;
- params->ti_rx_max_coal_bds = sc->ti_rx_max_coal_bds;
- params->ti_tx_max_coal_bds = sc->ti_tx_max_coal_bds;
- params->ti_tx_buf_ratio = sc->ti_tx_buf_ratio;
- params->param_mask = TI_PARAM_ALL;
-
- error = 0;
-
- break;
- }
- case TIIOCSETPARAMS:
- {
- struct ti_params *params;
-
- params = (struct ti_params *)addr;
-
- if (params->param_mask & TI_PARAM_STAT_TICKS) {
- sc->ti_stat_ticks = params->ti_stat_ticks;
- CSR_WRITE_4(sc, TI_GCR_STAT_TICKS, sc->ti_stat_ticks);
- }
-
- if (params->param_mask & TI_PARAM_RX_COAL_TICKS) {
- sc->ti_rx_coal_ticks = params->ti_rx_coal_ticks;
- CSR_WRITE_4(sc, TI_GCR_RX_COAL_TICKS,
- sc->ti_rx_coal_ticks);
- }
-
- if (params->param_mask & TI_PARAM_TX_COAL_TICKS) {
- sc->ti_tx_coal_ticks = params->ti_tx_coal_ticks;
- CSR_WRITE_4(sc, TI_GCR_TX_COAL_TICKS,
- sc->ti_tx_coal_ticks);
- }
-
- if (params->param_mask & TI_PARAM_RX_COAL_BDS) {
- sc->ti_rx_max_coal_bds = params->ti_rx_max_coal_bds;
- CSR_WRITE_4(sc, TI_GCR_RX_MAX_COAL_BD,
- sc->ti_rx_max_coal_bds);
- }
-
- if (params->param_mask & TI_PARAM_TX_COAL_BDS) {
- sc->ti_tx_max_coal_bds = params->ti_tx_max_coal_bds;
- CSR_WRITE_4(sc, TI_GCR_TX_MAX_COAL_BD,
- sc->ti_tx_max_coal_bds);
- }
-
- if (params->param_mask & TI_PARAM_TX_BUF_RATIO) {
- sc->ti_tx_buf_ratio = params->ti_tx_buf_ratio;
- CSR_WRITE_4(sc, TI_GCR_TX_BUFFER_RATIO,
- sc->ti_tx_buf_ratio);
- }
-
- error = 0;
-
- break;
- }
- case TIIOCSETTRACE: {
- ti_trace_type trace_type;
-
- trace_type = *(ti_trace_type *)addr;
-
- /*
- * Set tracing to whatever the user asked for. Setting
- * this register to 0 should have the effect of disabling
- * tracing.
- */
- CSR_WRITE_4(sc, TI_GCR_NIC_TRACING, trace_type);
-
- error = 0;
-
- break;
- }
- case TIIOCGETTRACE: {
- struct ti_trace_buf *trace_buf;
- u_int32_t trace_start, cur_trace_ptr, trace_len;
-
- trace_buf = (struct ti_trace_buf *)addr;
-
- trace_start = CSR_READ_4(sc, TI_GCR_NICTRACE_START);
- cur_trace_ptr = CSR_READ_4(sc, TI_GCR_NICTRACE_PTR);
- trace_len = CSR_READ_4(sc, TI_GCR_NICTRACE_LEN);
-
-#if 0
- printf("ti%d: trace_start = %#x, cur_trace_ptr = %#x, "
- "trace_len = %d\n", sc->ti_unit, trace_start,
- cur_trace_ptr, trace_len);
- printf("ti%d: trace_buf->buf_len = %d\n", sc->ti_unit,
- trace_buf->buf_len);
-#endif
-
- error = ti_copy_mem(sc, trace_start, min(trace_len,
- trace_buf->buf_len),
- (caddr_t)trace_buf->buf, 1, 1);
-
- if (error == 0) {
- trace_buf->fill_len = min(trace_len,
- trace_buf->buf_len);
- if (cur_trace_ptr < trace_start)
- trace_buf->cur_trace_ptr =
- trace_start - cur_trace_ptr;
- else
- trace_buf->cur_trace_ptr =
- cur_trace_ptr - trace_start;
- } else
- trace_buf->fill_len = 0;
-
-
- break;
- }
-
- /*
- * For debugging, five ioctls are needed:
- * ALT_ATTACH
- * ALT_READ_TG_REG
- * ALT_WRITE_TG_REG
- * ALT_READ_TG_MEM
- * ALT_WRITE_TG_MEM
- */
- case ALT_ATTACH:
- /*
- * From what I can tell, Alteon's Solaris Tigon driver
- * only has one character device, so you have to attach
- * to the Tigon board you're interested in. This seems
- * like a not-so-good way to do things, since unless you
- * subsequently specify the unit number of the device
- * you're interested in in every ioctl, you'll only be
- * able to debug one board at a time.
- */
- error = 0;
- break;
- case ALT_READ_TG_MEM:
- case ALT_WRITE_TG_MEM:
- {
- struct tg_mem *mem_param;
- u_int32_t sram_end, scratch_end;
-
- mem_param = (struct tg_mem *)addr;
-
- if (sc->ti_hwrev == TI_HWREV_TIGON) {
- sram_end = TI_END_SRAM_I;
- scratch_end = TI_END_SCRATCH_I;
- } else {
- sram_end = TI_END_SRAM_II;
- scratch_end = TI_END_SCRATCH_II;
- }
-
- /*
- * For now, we'll only handle accessing regular SRAM,
- * nothing else.
- */
- if ((mem_param->tgAddr >= TI_BEG_SRAM)
- && ((mem_param->tgAddr + mem_param->len) <= sram_end)) {
- /*
- * In this instance, we always copy to/from user
- * space, so the user space argument is set to 1.
- */
- error = ti_copy_mem(sc, mem_param->tgAddr,
- mem_param->len,
- mem_param->userAddr, 1,
- (cmd == ALT_READ_TG_MEM) ? 1 : 0);
- } else if ((mem_param->tgAddr >= TI_BEG_SCRATCH)
- && (mem_param->tgAddr <= scratch_end)) {
- error = ti_copy_scratch(sc, mem_param->tgAddr,
- mem_param->len,
- mem_param->userAddr, 1,
- (cmd == ALT_READ_TG_MEM) ?
- 1 : 0, TI_PROCESSOR_A);
- } else if ((mem_param->tgAddr >= TI_BEG_SCRATCH_B_DEBUG)
- && (mem_param->tgAddr <= TI_BEG_SCRATCH_B_DEBUG)) {
- if (sc->ti_hwrev == TI_HWREV_TIGON) {
- printf("ti%d: invalid memory range for "
- "Tigon I\n", sc->ti_unit);
- error = EINVAL;
- break;
- }
- error = ti_copy_scratch(sc, mem_param->tgAddr -
- TI_SCRATCH_DEBUG_OFF,
- mem_param->len,
- mem_param->userAddr, 1,
- (cmd == ALT_READ_TG_MEM) ?
- 1 : 0, TI_PROCESSOR_B);
- } else {
- printf("ti%d: memory address %#x len %d is out of "
- "supported range\n", sc->ti_unit,
- mem_param->tgAddr, mem_param->len);
- error = EINVAL;
- }
-
- break;
- }
- case ALT_READ_TG_REG:
- case ALT_WRITE_TG_REG:
- {
- struct tg_reg *regs;
- u_int32_t tmpval;
-
- regs = (struct tg_reg *)addr;
-
- /*
- * Make sure the address in question isn't out of range.
- */
- if (regs->addr > TI_REG_MAX) {
- error = EINVAL;
- break;
- }
- if (cmd == ALT_READ_TG_REG) {
- bus_space_read_region_4(sc->ti_btag, sc->ti_bhandle,
- regs->addr, &tmpval, 1);
- regs->data = ntohl(tmpval);
-#if 0
- if ((regs->addr == TI_CPU_STATE)
- || (regs->addr == TI_CPU_CTL_B)) {
- printf("ti%d: register %#x = %#x\n",
- sc->ti_unit, regs->addr, tmpval);
- }
-#endif
- } else {
- tmpval = htonl(regs->data);
- bus_space_write_region_4(sc->ti_btag, sc->ti_bhandle,
- regs->addr, &tmpval, 1);
- }
-
- break;
- }
- default:
- error = ENOTTY;
- break;
- }
- return(error);
-}
-
-static void
-ti_watchdog(ifp)
- struct ifnet *ifp;
-{
- struct ti_softc *sc;
-
- sc = ifp->if_softc;
- TI_LOCK(sc);
-
- /*
- * When we're debugging, the chip is often stopped for long periods
- * of time, and that would normally cause the watchdog timer to fire.
- * Since that impedes debugging, we don't want to do that.
- */
- if (sc->ti_flags & TI_FLAG_DEBUGING) {
- TI_UNLOCK(sc);
- return;
- }
-
- printf("ti%d: watchdog timeout -- resetting\n", sc->ti_unit);
- ti_stop(sc);
- ti_init(sc);
-
- ifp->if_oerrors++;
- TI_UNLOCK(sc);
-
- return;
-}
-
-/*
- * Stop the adapter and free any mbufs allocated to the
- * RX and TX lists.
- */
-static void
-ti_stop(sc)
- struct ti_softc *sc;
-{
- struct ifnet *ifp;
- struct ti_cmd_desc cmd;
-
- TI_LOCK(sc);
-
- ifp = &sc->arpcom.ac_if;
-
- /* Disable host interrupts. */
- CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
- /*
- * Tell firmware we're shutting down.
- */
- TI_DO_CMD(TI_CMD_HOST_STATE, TI_CMD_CODE_STACK_DOWN, 0);
-
- /* Halt and reinitialize. */
- ti_chipinit(sc);
- ti_mem(sc, 0x2000, 0x100000 - 0x2000, NULL);
- ti_chipinit(sc);
-
- /* Free the RX lists. */
- ti_free_rx_ring_std(sc);
-
- /* Free jumbo RX list. */
- ti_free_rx_ring_jumbo(sc);
-
- /* Free mini RX list. */
- ti_free_rx_ring_mini(sc);
-
- /* Free TX buffers. */
- ti_free_tx_ring(sc);
-
- sc->ti_ev_prodidx.ti_idx = 0;
- sc->ti_return_prodidx.ti_idx = 0;
- sc->ti_tx_considx.ti_idx = 0;
- sc->ti_tx_saved_considx = TI_TXCONS_UNSET;
-
- ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
- TI_UNLOCK(sc);
-
- return;
-}
-
-/*
- * Stop all chip I/O so that the kernel's probe routines don't
- * get confused by errant DMAs when rebooting.
- */
-static void
-ti_shutdown(dev)
- device_t dev;
-{
- struct ti_softc *sc;
-
- sc = device_get_softc(dev);
- TI_LOCK(sc);
- ti_chipinit(sc);
- TI_UNLOCK(sc);
-
- return;
-}
diff --git a/sys/dev/ti/if_tireg.h b/sys/dev/ti/if_tireg.h
deleted file mode 100644
index b15b28bb20f0..000000000000
--- a/sys/dev/ti/if_tireg.h
+++ /dev/null
@@ -1,1067 +0,0 @@
-/*
- * Copyright (c) 1997, 1998, 1999
- * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-/*
- * Tigon register offsets. These are memory mapped registers
- * which can be accessed with the CSR_READ_4()/CSR_WRITE_4() macros.
- * Each register must be accessed using 32 bit operations.
- *
- * All reegisters are accessed through a 16K shared memory block.
- * The first group of registers are actually copies of the PCI
- * configuration space registers.
- */
-
-#define TI_PCI_ID 0x000 /* PCI device/vendor ID */
-#define TI_PCI_CMDSTAT 0x004
-#define TI_PCI_CLASSCODE 0x008
-#define TI_PCI_BIST 0x00C
-#define TI_PCI_LOMEM 0x010 /* Shared memory base address */
-#define TI_PCI_SUBSYS 0x02C
-#define TI_PCI_ROMBASE 0x030
-#define TI_PCI_INT 0x03C
-
-#ifndef PCIM_CMD_MWIEN
-#define PCIM_CMD_MWIEN 0x0010
-#endif
-
-/*
- * Alteon AceNIC PCI vendor/device ID.
- */
-#define ALT_VENDORID 0x12AE
-#define ALT_DEVICEID_ACENIC 0x0001
-#define ALT_DEVICEID_ACENIC_COPPER 0x0002
-
-/*
- * 3Com 3c985 PCI vendor/device ID.
- */
-#define TC_VENDORID 0x10B7
-#define TC_DEVICEID_3C985 0x0001
-
-/*
- * Netgear GA620 PCI vendor/device ID.
- */
-#define NG_VENDORID 0x1385
-#define NG_DEVICEID_GA620 0x620A
-#define NG_DEVICEID_GA620T 0x630A
-
-/*
- * SGI device/vendor ID.
- */
-#define SGI_VENDORID 0x10A9
-#define SGI_DEVICEID_TIGON 0x0009
-
-/*
- * DEC vendor ID, Farallon device ID. Apparently, Farallon used
- * the DEC vendor ID in their cards by mistake.
- */
-#define DEC_VENDORID 0x1011
-#define DEC_DEVICEID_FARALLON_PN9000SX 0x001a
-
-/*
- * Tigon configuration and control registers.
- */
-#define TI_MISC_HOST_CTL 0x040
-#define TI_MISC_LOCAL_CTL 0x044
-#define TI_SEM_AB 0x048 /* Tigon 2 only */
-#define TI_MISC_CONF 0x050 /* Tigon 2 only */
-#define TI_TIMER_BITS 0x054
-#define TI_TIMERREF 0x058
-#define TI_PCI_STATE 0x05C
-#define TI_MAIN_EVENT_A 0x060
-#define TI_MAILBOX_EVENT_A 0x064
-#define TI_WINBASE 0x068
-#define TI_WINDATA 0x06C
-#define TI_MAIN_EVENT_B 0x070 /* Tigon 2 only */
-#define TI_MAILBOX_EVENT_B 0x074 /* Tigon 2 only */
-#define TI_TIMERREF_B 0x078 /* Tigon 2 only */
-#define TI_SERIAL 0x07C
-
-/*
- * Misc host control bits.
- */
-#define TI_MHC_INTSTATE 0x00000001
-#define TI_MHC_CLEARINT 0x00000002
-#define TI_MHC_RESET 0x00000008
-#define TI_MHC_BYTE_SWAP_ENB 0x00000010
-#define TI_MHC_WORD_SWAP_ENB 0x00000020
-#define TI_MHC_MASK_INTS 0x00000040
-#define TI_MHC_CHIP_REV_MASK 0xF0000000
-
-#define TI_MHC_BIGENDIAN_INIT \
- (TI_MHC_BYTE_SWAP_ENB|TI_MHC_WORD_SWAP_ENB|TI_MHC_CLEARINT)
-
-#define TI_MHC_LITTLEENDIAN_INIT \
- (TI_MHC_WORD_SWAP_ENB|TI_MHC_CLEARINT)
-
-/*
- * Tigon chip rev values. Rev 4 is the Tigon 1. Rev 6 is the Tigon 2.
- * Rev 5 is also the Tigon 2, but is a broken version which was never
- * used in any actual hardware, so we ignore it.
- */
-#define TI_REV_TIGON_I 0x40000000
-#define TI_REV_TIGON_II 0x60000000
-
-/*
- * Firmware revision that we want.
- */
-#define TI_FIRMWARE_MAJOR 0xc
-#define TI_FIRMWARE_MINOR 0x4
-#define TI_FIRMWARE_FIX 0xb
-
-/*
- * Miscelaneous Local Control register.
- */
-#define TI_MLC_EE_WRITE_ENB 0x00000010
-#define TI_MLC_SRAM_BANK_SIZE 0x00000300 /* Tigon 2 only */
-#define TI_MLC_LOCALADDR_21 0x00004000
-#define TI_MLC_LOCALADDR_22 0x00008000
-#define TI_MLC_SBUS_WRITEERR 0x00080000
-#define TI_MLC_EE_CLK 0x00100000
-#define TI_MLC_EE_TXEN 0x00200000
-#define TI_MLC_EE_DOUT 0x00400000
-#define TI_MLC_EE_DIN 0x00800000
-
-/* Possible memory sizes. */
-#define TI_MLC_SRAM_BANK_DISA 0x00000000
-#define TI_MLC_SRAM_BANK_1024K 0x00000100
-#define TI_MLC_SRAM_BANK_512K 0x00000200
-#define TI_MLC_SRAM_BANK_256K 0x00000300
-
-/*
- * Offset of MAC address inside EEPROM.
- */
-#define TI_EE_MAC_OFFSET 0x8c
-
-#define TI_DMA_ASSIST 0x11C
-#define TI_CPU_STATE 0x140
-#define TI_CPU_PROGRAM_COUNTER 0x144
-#define TI_SRAM_ADDR 0x154
-#define TI_SRAM_DATA 0x158
-#define TI_GEN_0 0x180
-#define TI_GEN_X 0x1FC
-#define TI_MAC_TX_STATE 0x200
-#define TI_MAC_RX_STATE 0x220
-#define TI_CPU_CTL_B 0x240 /* Tigon 2 only */
-#define TI_CPU_PROGRAM_COUNTER_B 0x244 /* Tigon 2 only */
-#define TI_SRAM_ADDR_B 0x254 /* Tigon 2 only */
-#define TI_SRAM_DATA_B 0x258 /* Tigon 2 only */
-#define TI_GEN_B_0 0x280 /* Tigon 2 only */
-#define TI_GEN_B_X 0x2FC /* Tigon 2 only */
-
-/*
- * Misc config register.
- */
-#define TI_MCR_SRAM_SYNCHRONOUS 0x00100000 /* Tigon 2 only */
-
-/*
- * PCI state register.
- */
-#define TI_PCISTATE_FORCE_RESET 0x00000001
-#define TI_PCISTATE_PROVIDE_LEN 0x00000002
-#define TI_PCISTATE_READ_MAXDMA 0x0000001C
-#define TI_PCISTATE_WRITE_MAXDMA 0x000000E0
-#define TI_PCISTATE_MINDMA 0x0000FF00
-#define TI_PCISTATE_FIFO_RETRY_ENB 0x00010000
-#define TI_PCISTATE_USE_MEM_RD_MULT 0x00020000
-#define TI_PCISTATE_NO_SWAP_READ_DMA 0x00040000
-#define TI_PCISTATE_NO_SWAP_WRITE_DMA 0x00080000
-#define TI_PCISTATE_66MHZ_BUS 0x00080000 /* Tigon 2 only */
-#define TI_PCISTATE_32BIT_BUS 0x00100000 /* Tigon 2 only */
-#define TI_PCISTATE_ENB_BYTE_ENABLES 0x00800000 /* Tigon 2 only */
-#define TI_PCISTATE_READ_CMD 0x0F000000
-#define TI_PCISTATE_WRITE_CMD 0xF0000000
-
-#define TI_PCI_READMAX_4 0x04
-#define TI_PCI_READMAX_16 0x08
-#define TI_PCI_READMAX_32 0x0C
-#define TI_PCI_READMAX_64 0x10
-#define TI_PCI_READMAX_128 0x14
-#define TI_PCI_READMAX_256 0x18
-#define TI_PCI_READMAX_1024 0x1C
-
-#define TI_PCI_WRITEMAX_4 0x20
-#define TI_PCI_WRITEMAX_16 0x40
-#define TI_PCI_WRITEMAX_32 0x60
-#define TI_PCI_WRITEMAX_64 0x80
-#define TI_PCI_WRITEMAX_128 0xA0
-#define TI_PCI_WRITEMAX_256 0xC0
-#define TI_PCI_WRITEMAX_1024 0xE0
-
-#define TI_PCI_READ_CMD 0x06000000
-#define TI_PCI_WRITE_CMD 0x70000000
-
-/*
- * DMA state register.
- */
-#define TI_DMASTATE_ENABLE 0x00000001
-#define TI_DMASTATE_PAUSE 0x00000002
-
-/*
- * CPU state register.
- */
-#define TI_CPUSTATE_RESET 0x00000001
-#define TI_CPUSTATE_STEP 0x00000002
-#define TI_CPUSTATE_ROMFAIL 0x00000010
-#define TI_CPUSTATE_HALT 0x00010000
-/*
- * MAC TX state register
- */
-#define TI_TXSTATE_RESET 0x00000001
-#define TI_TXSTATE_ENB 0x00000002
-#define TI_TXSTATE_STOP 0x00000004
-
-/*
- * MAC RX state register
- */
-#define TI_RXSTATE_RESET 0x00000001
-#define TI_RXSTATE_ENB 0x00000002
-#define TI_RXSTATE_STOP 0x00000004
-
-/*
- * Tigon 2 mailbox registers. The mailbox area consists of 256 bytes
- * split into 64 bit registers. Only the lower 32 bits of each mailbox
- * are used.
- */
-#define TI_MB_HOSTINTR_HI 0x500
-#define TI_MB_HOSTINTR_LO 0x504
-#define TI_MB_HOSTINTR TI_MB_HOSTINTR_LO
-#define TI_MB_CMDPROD_IDX_HI 0x508
-#define TI_MB_CMDPROD_IDX_LO 0x50C
-#define TI_MB_CMDPROD_IDX TI_MB_CMDPROD_IDX_LO
-#define TI_MB_SENDPROD_IDX_HI 0x510
-#define TI_MB_SENDPROD_IDX_LO 0x514
-#define TI_MB_SENDPROD_IDX TI_MB_SENDPROD_IDX_LO
-#define TI_MB_STDRXPROD_IDX_HI 0x518 /* Tigon 2 only */
-#define TI_MB_STDRXPROD_IDX_LO 0x51C /* Tigon 2 only */
-#define TI_MB_STDRXPROD_IDX TI_MB_STDRXPROD_IDX_LO
-#define TI_MB_JUMBORXPROD_IDX_HI 0x520 /* Tigon 2 only */
-#define TI_MB_JUMBORXPROD_IDX_LO 0x524 /* Tigon 2 only */
-#define TI_MB_JUMBORXPROD_IDX TI_MB_JUMBORXPROD_IDX_LO
-#define TI_MB_MINIRXPROD_IDX_HI 0x528 /* Tigon 2 only */
-#define TI_MB_MINIRXPROD_IDX_LO 0x52C /* Tigon 2 only */
-#define TI_MB_MINIRXPROD_IDX TI_MB_MINIRXPROD_IDX_LO
-#define TI_MB_RSVD 0x530
-
-/*
- * Tigon 2 general communication registers. These are 64 and 32 bit
- * registers which are only valid after the firmware has been
- * loaded and started. They actually exist in NIC memory but are
- * mapped into the host memory via the shared memory region.
- *
- * The NIC internally maps these registers starting at address 0,
- * so to determine the NIC address of any of these registers, we
- * subtract 0x600 (the address of the first register).
- */
-
-#define TI_GCR_BASE 0x600
-#define TI_GCR_MACADDR 0x600
-#define TI_GCR_PAR0 0x600
-#define TI_GCR_PAR1 0x604
-#define TI_GCR_GENINFO_HI 0x608
-#define TI_GCR_GENINFO_LO 0x60C
-#define TI_GCR_MCASTADDR 0x610 /* obsolete */
-#define TI_GCR_MAR0 0x610 /* obsolete */
-#define TI_GCR_MAR1 0x614 /* obsolete */
-#define TI_GCR_OPMODE 0x618
-#define TI_GCR_DMA_READCFG 0x61C
-#define TI_GCR_DMA_WRITECFG 0x620
-#define TI_GCR_TX_BUFFER_RATIO 0x624
-#define TI_GCR_EVENTCONS_IDX 0x628
-#define TI_GCR_CMDCONS_IDX 0x62C
-#define TI_GCR_TUNEPARMS 0x630
-#define TI_GCR_RX_COAL_TICKS 0x630
-#define TI_GCR_TX_COAL_TICKS 0x634
-#define TI_GCR_STAT_TICKS 0x638
-#define TI_GCR_TX_MAX_COAL_BD 0x63C
-#define TI_GCR_RX_MAX_COAL_BD 0x640
-#define TI_GCR_NIC_TRACING 0x644
-#define TI_GCR_GLINK 0x648
-#define TI_GCR_LINK 0x64C
-#define TI_GCR_NICTRACE_PTR 0x650
-#define TI_GCR_NICTRACE_START 0x654
-#define TI_GCR_NICTRACE_LEN 0x658
-#define TI_GCR_IFINDEX 0x65C
-#define TI_GCR_IFMTU 0x660
-#define TI_GCR_MASK_INTRS 0x664
-#define TI_GCR_GLINK_STAT 0x668
-#define TI_GCR_LINK_STAT 0x66C
-#define TI_GCR_RXRETURNCONS_IDX 0x680
-#define TI_GCR_CMDRING 0x700
-
-#define TI_GCR_NIC_ADDR(x) (x - TI_GCR_BASE);
-
-/*
- * Local memory window. The local memory window is a 2K shared
- * memory region which can be used to access the NIC's internal
- * SRAM. The window can be mapped to a given 2K region using
- * the TI_WINDOW_BASE register.
- */
-#define TI_WINDOW 0x800
-#define TI_WINLEN 0x800
-
-#define TI_TICKS_PER_SEC 1000000
-
-/*
- * Operation mode register.
- */
-#define TI_OPMODE_BYTESWAP_BD 0x00000002
-#define TI_OPMODE_WORDSWAP_BD 0x00000004
-#define TI_OPMODE_WARN_ENB 0x00000008 /* not yet implimented */
-#define TI_OPMODE_BYTESWAP_DATA 0x00000010
-#define TI_OPMODE_1_DMA_ACTIVE 0x00000040
-#define TI_OPMODE_SBUS 0x00000100
-#define TI_OPMODE_DONT_FRAG_JUMBO 0x00000200
-#define TI_OPMODE_INCLUDE_CRC 0x00000400
-#define TI_OPMODE_RX_BADFRAMES 0x00000800
-#define TI_OPMODE_NO_EVENT_INTRS 0x00001000
-#define TI_OPMODE_NO_TX_INTRS 0x00002000
-#define TI_OPMODE_NO_RX_INTRS 0x00004000
-#define TI_OPMODE_FATAL_ENB 0x40000000 /* not yet implimented */
-#define TI_OPMODE_JUMBO_HDRSPLIT 0x00008000
-
-/*
- * DMA configuration thresholds.
- */
-#define TI_DMA_STATE_THRESH_16W 0x00000100
-#define TI_DMA_STATE_THRESH_8W 0x00000080
-#define TI_DMA_STATE_THRESH_4W 0x00000040
-#define TI_DMA_STATE_THRESH_2W 0x00000020
-#define TI_DMA_STATE_THRESH_1W 0x00000010
-
-#define TI_DMA_STATE_FORCE_32_BIT 0x00000008
-
-/*
- * Gigabit link status bits.
- */
-#define TI_GLNK_SENSE_NO_BEG 0x00002000
-#define TI_GLNK_LOOPBACK 0x00004000
-#define TI_GLNK_PREF 0x00008000
-#define TI_GLNK_1000MB 0x00040000
-#define TI_GLNK_FULL_DUPLEX 0x00080000
-#define TI_GLNK_TX_FLOWCTL_Y 0x00200000 /* Tigon 2 only */
-#define TI_GLNK_RX_FLOWCTL_Y 0x00800000
-#define TI_GLNK_AUTONEGENB 0x20000000
-#define TI_GLNK_ENB 0x40000000
-
-/*
- * Link status bits.
- */
-#define TI_LNK_LOOPBACK 0x00004000
-#define TI_LNK_PREF 0x00008000
-#define TI_LNK_10MB 0x00010000
-#define TI_LNK_100MB 0x00020000
-#define TI_LNK_1000MB 0x00040000
-#define TI_LNK_FULL_DUPLEX 0x00080000
-#define TI_LNK_HALF_DUPLEX 0x00100000
-#define TI_LNK_TX_FLOWCTL_Y 0x00200000 /* Tigon 2 only */
-#define TI_LNK_RX_FLOWCTL_Y 0x00800000
-#define TI_LNK_AUTONEGENB 0x20000000
-#define TI_LNK_ENB 0x40000000
-
-/*
- * Ring size constants.
- */
-#define TI_EVENT_RING_CNT 256
-#define TI_CMD_RING_CNT 64
-#define TI_STD_RX_RING_CNT 512
-#define TI_JUMBO_RX_RING_CNT 256
-#define TI_MINI_RX_RING_CNT 1024
-#define TI_RETURN_RING_CNT 2048
-
-/*
- * Possible TX ring sizes.
- */
-#define TI_TX_RING_CNT_128 128
-#define TI_TX_RING_BASE_128 0x3800
-
-#define TI_TX_RING_CNT_256 256
-#define TI_TX_RING_BASE_256 0x3000
-
-#define TI_TX_RING_CNT_512 512
-#define TI_TX_RING_BASE_512 0x2000
-
-#define TI_TX_RING_CNT TI_TX_RING_CNT_512
-#define TI_TX_RING_BASE TI_TX_RING_BASE_512
-
-/*
- * The Tigon can have up to 8MB of external SRAM, however the Tigon 1
- * is limited to 2MB total, and in general I think most adapters have
- * around 1MB. We use this value for zeroing the NIC's SRAM, so to
- * be safe we use the largest possible value (zeroing memory that
- * isn't there doesn't hurt anything).
- */
-#define TI_MEM_MAX 0x7FFFFF
-
-/*
- * Maximum register address on the Tigon.
- */
-#define TI_REG_MAX 0x3fff
-
-/*
- * These values were taken from Alteon's tg.h.
- */
-#define TI_BEG_SRAM 0x0 /* host thinks it's here */
-#define TI_BEG_SCRATCH 0xc00000 /* beg of scratch pad area */
-#define TI_END_SRAM_II 0x800000 /* end of SRAM, for 2 MB stuffed */
-#define TI_END_SCRATCH_II 0xc04000 /* end of scratch pad CPU A (16KB) */
-#define TI_END_SCRATCH_B 0xc02000 /* end of scratch pad CPU B (8KB) */
-#define TI_BEG_SCRATCH_B_DEBUG 0xd00000 /* beg of scratch pad for ioctl */
-#define TI_END_SCRATCH_B_DEBUG 0xd02000 /* end of scratch pad for ioctl */
-#define TI_SCRATCH_DEBUG_OFF 0x100000 /* offset for ioctl usage */
-#define TI_END_SRAM_I 0x200000 /* end of SRAM, for 2 MB stuffed */
-#define TI_END_SCRATCH_I 0xc00800 /* end of scratch pad area (2KB) */
-#define TI_BEG_PROM 0x40000000 /* beg of PROM, special access */
-#define TI_BEG_FLASH 0x80000000 /* beg of EEPROM, special access */
-#define TI_END_FLASH 0x80100000 /* end of EEPROM for 1 MB stuff */
-#define TI_BEG_SER_EEPROM 0xa0000000 /* beg of Serial EEPROM (fake out) */
-#define TI_END_SER_EEPROM 0xa0002000 /* end of Serial EEPROM (fake out) */
-#define TI_BEG_REGS 0xc0000000 /* beg of register area */
-#define TI_END_REGS 0xc0000400 /* end of register area */
-#define TI_END_WRITE_REGS 0xc0000180 /* can't write GPRs currently */
-#define TI_BEG_REGS2 0xc0000200 /* beg of second writeable reg area */
-/* the EEPROM is byte addressable in a pretty odd way */
-#define EEPROM_BYTE_LOC 0xff000000
-
-/*
- * From Alteon's tg.h.
- */
-#define TI_PROCESSOR_A 0
-#define TI_PROCESSOR_B 1
-#define TI_CPU_A TG_PROCESSOR_A
-#define TI_CPU_B TG_PROCESSOR_B
-
-/*
- * Following macro can be used to access to any of the CPU registers
- * It will adjust the address appropriately.
- * Parameters:
- * reg - The register to access, e.g TI_CPU_CONTROL
- * cpu - cpu, i.e PROCESSOR_A or PROCESSOR_B (or TI_CPU_A or TI_CPU_B)
- */
-#define CPU_REG(reg, cpu) ((reg) + (cpu) * 0x100)
-
-/*
- * Even on the alpha, pci addresses are 32-bit quantities
- */
-
-#ifdef __64_bit_pci_addressing__
-typedef struct {
- u_int64_t ti_addr;
-} ti_hostaddr;
-#define TI_HOSTADDR(x) x.ti_addr
-#else
-typedef struct {
- u_int32_t ti_addr_hi;
- u_int32_t ti_addr_lo;
-} ti_hostaddr;
-#define TI_HOSTADDR(x) x.ti_addr_lo
-#endif
-
-/*
- * Ring control block structure. The rules for the max_len field
- * are as follows:
- *
- * For the send ring, max_len indicates the number of entries in the
- * ring (128, 256 or 512).
- *
- * For the standard receive ring, max_len indicates the threshold
- * used to decide when a frame should be put in the jumbo receive ring
- * instead of the standard one.
- *
- * For the mini ring, max_len indicates the size of the buffers in the
- * ring. This is the value used to decide when a frame is small enough
- * to be placed in the mini ring.
- *
- * For the return receive ring, max_len indicates the number of entries
- * in the ring. It can be one of 2048, 1024 or 0 (which is the same as
- * 2048 for backwards compatibility). The value 1024 can only be used
- * if the mini ring is disabled.
- */
-struct ti_rcb {
- ti_hostaddr ti_hostaddr;
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_max_len;
- u_int16_t ti_flags;
-#else
- u_int16_t ti_flags;
- u_int16_t ti_max_len;
-#endif
- u_int32_t ti_unused;
-};
-
-#define TI_RCB_FLAG_TCP_UDP_CKSUM 0x00000001
-#define TI_RCB_FLAG_IP_CKSUM 0x00000002
-#define TI_RCB_FLAG_NO_PHDR_CKSUM 0x00000008
-#define TI_RCB_FLAG_VLAN_ASSIST 0x00000010
-#define TI_RCB_FLAG_COAL_UPD_ONLY 0x00000020
-#define TI_RCB_FLAG_HOST_RING 0x00000040
-#define TI_RCB_FLAG_IEEE_SNAP_CKSUM 0x00000080
-#define TI_RCB_FLAG_USE_EXT_RX_BD 0x00000100
-#define TI_RCB_FLAG_RING_DISABLED 0x00000200
-
-struct ti_producer {
- u_int32_t ti_idx;
- u_int32_t ti_unused;
-};
-
-/*
- * Tigon general information block. This resides in host memory
- * and contains the status counters, ring control blocks and
- * producer pointers.
- */
-
-struct ti_gib {
- struct ti_stats ti_stats;
- struct ti_rcb ti_ev_rcb;
- struct ti_rcb ti_cmd_rcb;
- struct ti_rcb ti_tx_rcb;
- struct ti_rcb ti_std_rx_rcb;
- struct ti_rcb ti_jumbo_rx_rcb;
- struct ti_rcb ti_mini_rx_rcb;
- struct ti_rcb ti_return_rcb;
- ti_hostaddr ti_ev_prodidx_ptr;
- ti_hostaddr ti_return_prodidx_ptr;
- ti_hostaddr ti_tx_considx_ptr;
- ti_hostaddr ti_refresh_stats_ptr;
-};
-
-/*
- * Buffer descriptor structures. There are basically three types
- * of structures: normal receive descriptors, extended receive
- * descriptors and transmit descriptors. The extended receive
- * descriptors are optionally used only for the jumbo receive ring.
- */
-
-struct ti_rx_desc {
- ti_hostaddr ti_addr;
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_idx;
- u_int16_t ti_len;
-#else
- u_int16_t ti_len;
- u_int16_t ti_idx;
-#endif
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_type;
- u_int16_t ti_flags;
-#else
- u_int16_t ti_flags;
- u_int16_t ti_type;
-#endif
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_ip_cksum;
- u_int16_t ti_tcp_udp_cksum;
-#else
- u_int16_t ti_tcp_udp_cksum;
- u_int16_t ti_ip_cksum;
-#endif
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_error_flags;
- u_int16_t ti_vlan_tag;
-#else
- u_int16_t ti_vlan_tag;
- u_int16_t ti_error_flags;
-#endif
- u_int32_t ti_rsvd;
- u_int32_t ti_opaque;
-};
-
-struct ti_rx_desc_ext {
- ti_hostaddr ti_addr1;
- ti_hostaddr ti_addr2;
- ti_hostaddr ti_addr3;
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_len1;
- u_int16_t ti_len2;
-#else
- u_int16_t ti_len2;
- u_int16_t ti_len1;
-#endif
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_len3;
- u_int16_t ti_rsvd0;
-#else
- u_int16_t ti_rsvd0;
- u_int16_t ti_len3;
-#endif
- ti_hostaddr ti_addr0;
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_idx;
- u_int16_t ti_len0;
-#else
- u_int16_t ti_len0;
- u_int16_t ti_idx;
-#endif
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_type;
- u_int16_t ti_flags;
-#else
- u_int16_t ti_flags;
- u_int16_t ti_type;
-#endif
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_ip_cksum;
- u_int16_t ti_tcp_udp_cksum;
-#else
- u_int16_t ti_tcp_udp_cksum;
- u_int16_t ti_ip_cksum;
-#endif
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_error_flags;
- u_int16_t ti_vlan_tag;
-#else
- u_int16_t ti_vlan_tag;
- u_int16_t ti_error_flags;
-#endif
- u_int32_t ti_rsvd1;
- u_int32_t ti_opaque;
-};
-
-/*
- * Transmit descriptors are, mercifully, very small.
- */
-struct ti_tx_desc {
- ti_hostaddr ti_addr;
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_len;
- u_int16_t ti_flags;
-#else
- u_int16_t ti_flags;
- u_int16_t ti_len;
-#endif
-#if BYTE_ORDER == BIG_ENDIAN
- u_int16_t ti_rsvd;
- u_int16_t ti_vlan_tag;
-#else
- u_int16_t ti_vlan_tag;
- u_int16_t ti_rsvd;
-#endif
-};
-
-/*
- * NOTE! On the Alpha, we have an alignment constraint.
- * The first thing in the packet is a 14-byte Ethernet header.
- * This means that the packet is misaligned. To compensate,
- * we actually offset the data 2 bytes into the cluster. This
- * alignes the packet after the Ethernet header at a 32-bit
- * boundary.
- */
-
-#define ETHER_ALIGN 2
-
-#define TI_FRAMELEN 1518
-#define TI_JUMBO_FRAMELEN 9018
-#define TI_JUMBO_MTU (TI_JUMBO_FRAMELEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
-#define TI_PAGE_SIZE PAGE_SIZE
-#define TI_MIN_FRAMELEN 60
-
-/*
- * Buffer descriptor error flags.
- */
-#define TI_BDERR_CRC 0x0001
-#define TI_BDERR_COLLDETECT 0x0002
-#define TI_BDERR_LINKLOST 0x0004
-#define TI_BDERR_DECODE 0x0008
-#define TI_BDERR_ODD_NIBBLES 0x0010
-#define TI_BDERR_MAC_ABRT 0x0020
-#define TI_BDERR_RUNT 0x0040
-#define TI_BDERR_TRUNC 0x0080
-#define TI_BDERR_GIANT 0x0100
-
-/*
- * Buffer descriptor flags.
- */
-#define TI_BDFLAG_TCP_UDP_CKSUM 0x0001
-#define TI_BDFLAG_IP_CKSUM 0x0002
-#define TI_BDFLAG_END 0x0004
-#define TI_BDFLAG_MORE 0x0008
-#define TI_BDFLAG_JUMBO_RING 0x0010
-#define TI_BDFLAG_UCAST_PKT 0x0020
-#define TI_BDFLAG_MCAST_PKT 0x0040
-#define TI_BDFLAG_BCAST_PKT 0x0060
-#define TI_BDFLAG_IP_FRAG 0x0080
-#define TI_BDFLAG_IP_FRAG_END 0x0100
-#define TI_BDFLAG_VLAN_TAG 0x0200
-#define TI_BDFLAG_ERROR 0x0400
-#define TI_BDFLAG_COAL_NOW 0x0800
-#define TI_BDFLAG_MINI_RING 0x1000
-
-/*
- * Descriptor type flags. I think these only have meaning for
- * the Tigon 1. I had to extract them from the sample driver source
- * since they aren't in the manual.
- */
-#define TI_BDTYPE_TYPE_NULL 0x0000
-#define TI_BDTYPE_SEND_BD 0x0001
-#define TI_BDTYPE_RECV_BD 0x0002
-#define TI_BDTYPE_RECV_JUMBO_BD 0x0003
-#define TI_BDTYPE_RECV_BD_LAST 0x0004
-#define TI_BDTYPE_SEND_DATA 0x0005
-#define TI_BDTYPE_SEND_DATA_LAST 0x0006
-#define TI_BDTYPE_RECV_DATA 0x0007
-#define TI_BDTYPE_RECV_DATA_LAST 0x000b
-#define TI_BDTYPE_EVENT_RUPT 0x000c
-#define TI_BDTYPE_EVENT_NO_RUPT 0x000d
-#define TI_BDTYPE_ODD_START 0x000e
-#define TI_BDTYPE_UPDATE_STATS 0x000f
-#define TI_BDTYPE_SEND_DUMMY_DMA 0x0010
-#define TI_BDTYPE_EVENT_PROD 0x0011
-#define TI_BDTYPE_TX_CONS 0x0012
-#define TI_BDTYPE_RX_PROD 0x0013
-#define TI_BDTYPE_REFRESH_STATS 0x0014
-#define TI_BDTYPE_SEND_DATA_LAST_VLAN 0x0015
-#define TI_BDTYPE_SEND_DATA_COAL 0x0016
-#define TI_BDTYPE_SEND_DATA_LAST_COAL 0x0017
-#define TI_BDTYPE_SEND_DATA_LAST_VLAN_COAL 0x0018
-#define TI_BDTYPE_TX_CONS_NO_INTR 0x0019
-
-/*
- * Tigon command structure.
- */
-struct ti_cmd_desc {
-#if BYTE_ORDER == BIG_ENDIAN
- u_int32_t ti_cmd:8;
- u_int32_t ti_code:12;
- u_int32_t ti_idx:12;
-#else
- u_int32_t ti_idx:12;
- u_int32_t ti_code:12;
- u_int32_t ti_cmd:8;
-#endif
-};
-
-#define TI_CMD_HOST_STATE 0x01
-#define TI_CMD_CODE_STACK_UP 0x01
-#define TI_CMD_CODE_STACK_DOWN 0x02
-
-/*
- * This command enables software address filtering. It's a workaround
- * for a bug in the Tigon 1 and not implemented for the Tigon 2.
- */
-#define TI_CMD_FDR_FILTERING 0x02
-#define TI_CMD_CODE_FILT_ENB 0x01
-#define TI_CMD_CODE_FILT_DIS 0x02
-
-#define TI_CMD_SET_RX_PROD_IDX 0x03 /* obsolete */
-#define TI_CMD_UPDATE_GENCOM 0x04
-#define TI_CMD_RESET_JUMBO_RING 0x05
-#define TI_CMD_SET_PARTIAL_RX_CNT 0x06
-#define TI_CMD_ADD_MCAST_ADDR 0x08 /* obsolete */
-#define TI_CMD_DEL_MCAST_ADDR 0x09 /* obsolete */
-
-#define TI_CMD_SET_PROMISC_MODE 0x0A
-#define TI_CMD_CODE_PROMISC_ENB 0x01
-#define TI_CMD_CODE_PROMISC_DIS 0x02
-
-#define TI_CMD_LINK_NEGOTIATION 0x0B
-#define TI_CMD_CODE_NEGOTIATE_BOTH 0x00
-#define TI_CMD_CODE_NEGOTIATE_GIGABIT 0x01
-#define TI_CMD_CODE_NEGOTIATE_10_100 0x02
-
-#define TI_CMD_SET_MAC_ADDR 0x0C
-#define TI_CMD_CLR_PROFILE 0x0D
-
-#define TI_CMD_SET_ALLMULTI 0x0E
-#define TI_CMD_CODE_ALLMULTI_ENB 0x01
-#define TI_CMD_CODE_ALLMULTI_DIS 0x02
-
-#define TI_CMD_CLR_STATS 0x0F
-#define TI_CMD_SET_RX_JUMBO_PROD_IDX 0x10 /* obsolete */
-#define TI_CMD_RFRSH_STATS 0x11
-
-#define TI_CMD_EXT_ADD_MCAST 0x12
-#define TI_CMD_EXT_DEL_MCAST 0x13
-
-/*
- * Utility macros to make issuing commands a little simpler. Assumes
- * that 'sc' and 'cmd' are in local scope.
- */
-#define TI_DO_CMD(x, y, z) \
- cmd.ti_cmd = (x); \
- cmd.ti_code = (y); \
- cmd.ti_idx = (z); \
- ti_cmd(sc, &cmd);
-
-#define TI_DO_CMD_EXT(x, y, z, v, w) \
- cmd.ti_cmd = (x); \
- cmd.ti_code = (y); \
- cmd.ti_idx = (z); \
- ti_cmd_ext(sc, &cmd, (v), (w));
-
-/*
- * Other utility macros.
- */
-#define TI_INC(x, y) (x) = (x + 1) % y
-
-#define TI_UPDATE_JUMBOPROD(x, y) \
- if (x->ti_hwrev == TI_HWREV_TIGON) { \
- TI_DO_CMD(TI_CMD_SET_RX_JUMBO_PROD_IDX, 0, y); \
- } else { \
- CSR_WRITE_4(x, TI_MB_JUMBORXPROD_IDX, y); \
- }
-
-#define TI_UPDATE_MINIPROD(x, y) \
- CSR_WRITE_4(x, TI_MB_MINIRXPROD_IDX, y);
-
-#define TI_UPDATE_STDPROD(x, y) \
- if (x->ti_hwrev == TI_HWREV_TIGON) { \
- TI_DO_CMD(TI_CMD_SET_RX_PROD_IDX, 0, y); \
- } else { \
- CSR_WRITE_4(x, TI_MB_STDRXPROD_IDX, y); \
- }
-
-
-/*
- * Tigon event structure.
- */
-struct ti_event_desc {
-#if BYTE_ORDER == BIG_ENDIAN
- u_int32_t ti_event:8;
- u_int32_t ti_code:12;
- u_int32_t ti_idx:12;
-#else
- u_int32_t ti_idx:12;
- u_int32_t ti_code:12;
- u_int32_t ti_event:8;
-#endif
- u_int32_t ti_rsvd;
-};
-
-/*
- * Tigon events.
- */
-#define TI_EV_FIRMWARE_UP 0x01
-#define TI_EV_STATS_UPDATED 0x04
-
-#define TI_EV_LINKSTAT_CHANGED 0x06
-#define TI_EV_CODE_GIG_LINK_UP 0x01
-#define TI_EV_CODE_LINK_DOWN 0x02
-#define TI_EV_CODE_LINK_UP 0x03
-
-#define TI_EV_ERROR 0x07
-#define TI_EV_CODE_ERR_INVAL_CMD 0x01
-#define TI_EV_CODE_ERR_UNIMP_CMD 0x02
-#define TI_EV_CODE_ERR_BADCFG 0x03
-
-#define TI_EV_MCAST_UPDATED 0x08
-#define TI_EV_CODE_MCAST_ADD 0x01
-#define TI_EV_CODE_MCAST_DEL 0x02
-
-#define TI_EV_RESET_JUMBO_RING 0x09
-/*
- * Register access macros. The Tigon always uses memory mapped register
- * accesses and all registers must be accessed with 32 bit operations.
- */
-
-#define CSR_WRITE_4(sc, reg, val) \
- bus_space_write_4(sc->ti_btag, sc->ti_bhandle, reg, val)
-
-#define CSR_READ_4(sc, reg) \
- bus_space_read_4(sc->ti_btag, sc->ti_bhandle, reg)
-
-#define TI_SETBIT(sc, reg, x) \
- CSR_WRITE_4(sc, reg, (CSR_READ_4(sc, reg) | x))
-#define TI_CLRBIT(sc, reg, x) \
- CSR_WRITE_4(sc, reg, (CSR_READ_4(sc, reg) & ~x))
-
-/*
- * Memory management stuff. Note: the SSLOTS, MSLOTS and JSLOTS
- * values are tuneable. They control the actual amount of buffers
- * allocated for the standard, mini and jumbo receive rings.
- */
-
-#define TI_SSLOTS 256
-#define TI_MSLOTS 256
-#define TI_JSLOTS 384
-
-#define TI_JRAWLEN (TI_JUMBO_FRAMELEN + ETHER_ALIGN)
-#define TI_JLEN (TI_JRAWLEN + (sizeof(u_int64_t) - \
- (TI_JRAWLEN % sizeof(u_int64_t))))
-#define TI_JPAGESZ PAGE_SIZE
-#define TI_RESID (TI_JPAGESZ - (TI_JLEN * TI_JSLOTS) % TI_JPAGESZ)
-#define TI_JMEM ((TI_JLEN * TI_JSLOTS) + TI_RESID)
-
-/*
- * Ring structures. Most of these reside in host memory and we tell
- * the NIC where they are via the ring control blocks. The exceptions
- * are the tx and command rings, which live in NIC memory and which
- * we access via the shared memory window.
- */
-struct ti_ring_data {
- struct ti_rx_desc ti_rx_std_ring[TI_STD_RX_RING_CNT];
-#ifdef PRIVATE_JUMBOS
- struct ti_rx_desc ti_rx_jumbo_ring[TI_JUMBO_RX_RING_CNT];
-#else
- struct ti_rx_desc_ext ti_rx_jumbo_ring[TI_JUMBO_RX_RING_CNT];
-#endif
- struct ti_rx_desc ti_rx_mini_ring[TI_MINI_RX_RING_CNT];
- struct ti_rx_desc ti_rx_return_ring[TI_RETURN_RING_CNT];
- struct ti_event_desc ti_event_ring[TI_EVENT_RING_CNT];
- struct ti_tx_desc ti_tx_ring[TI_TX_RING_CNT];
- /*
- * Make sure producer structures are aligned on 32-byte cache
- * line boundaries.
- */
- struct ti_producer ti_ev_prodidx_r;
- u_int32_t ti_pad0[6];
- struct ti_producer ti_return_prodidx_r;
- u_int32_t ti_pad1[6];
- struct ti_producer ti_tx_considx_r;
- u_int32_t ti_pad2[6];
- struct ti_tx_desc *ti_tx_ring_nic;/* pointer to shared mem */
- struct ti_cmd_desc *ti_cmd_ring; /* pointer to shared mem */
- struct ti_gib ti_info;
-};
-
-/*
- * Mbuf pointers. We need these to keep track of the virtual addresses
- * of our mbuf chains since we can only convert from physical to virtual,
- * not the other way around.
- */
-struct ti_chain_data {
- struct mbuf *ti_tx_chain[TI_TX_RING_CNT];
- struct mbuf *ti_rx_std_chain[TI_STD_RX_RING_CNT];
- struct mbuf *ti_rx_jumbo_chain[TI_JUMBO_RX_RING_CNT];
- struct mbuf *ti_rx_mini_chain[TI_MINI_RX_RING_CNT];
- /* Stick the jumbo mem management stuff here too. */
- caddr_t ti_jslots[TI_JSLOTS];
- void *ti_jumbo_buf;
-};
-
-struct ti_type {
- u_int16_t ti_vid;
- u_int16_t ti_did;
- char *ti_name;
-};
-
-#define TI_HWREV_TIGON 0x01
-#define TI_HWREV_TIGON_II 0x02
-#define TI_TIMEOUT 1000
-#define TI_TXCONS_UNSET 0xFFFF /* impossible value */
-
-struct ti_mc_entry {
- struct ether_addr mc_addr;
- SLIST_ENTRY(ti_mc_entry) mc_entries;
-};
-
-struct ti_jpool_entry {
- int slot;
- SLIST_ENTRY(ti_jpool_entry) jpool_entries;
-};
-
-typedef enum {
- TI_FLAG_NONE = 0x00,
- TI_FLAG_DEBUGING = 0x01,
- TI_FLAG_WAIT_FOR_LINK = 0x02
-} ti_flag_vals;
-
-struct ti_softc {
- STAILQ_ENTRY(ti_softc) ti_links;
- struct arpcom arpcom; /* interface info */
- bus_space_handle_t ti_bhandle;
- vm_offset_t ti_vhandle;
- bus_space_tag_t ti_btag;
- void *ti_intrhand;
- struct resource *ti_irq;
- struct resource *ti_res;
- struct ifmedia ifmedia; /* media info */
- u_int8_t ti_unit; /* interface number */
- u_int8_t ti_hwrev; /* Tigon rev (1 or 2) */
- u_int8_t ti_copper; /* 1000baseTX card */
- u_int8_t ti_linkstat; /* Link state */
- int ti_hdrsplit; /* enable header splitting */
- struct ti_ring_data *ti_rdata; /* rings */
- struct ti_chain_data ti_cdata; /* mbufs */
-#define ti_ev_prodidx ti_rdata->ti_ev_prodidx_r
-#define ti_return_prodidx ti_rdata->ti_return_prodidx_r
-#define ti_tx_considx ti_rdata->ti_tx_considx_r
- u_int16_t ti_tx_saved_considx;
- u_int16_t ti_rx_saved_considx;
- u_int16_t ti_ev_saved_considx;
- u_int16_t ti_cmd_saved_prodidx;
- u_int16_t ti_std; /* current std ring head */
- u_int16_t ti_mini; /* current mini ring head */
- u_int16_t ti_jumbo; /* current jumo ring head */
- SLIST_HEAD(__ti_mchead, ti_mc_entry) ti_mc_listhead;
- SLIST_HEAD(__ti_jfreehead, ti_jpool_entry) ti_jfree_listhead;
- SLIST_HEAD(__ti_jinusehead, ti_jpool_entry) ti_jinuse_listhead;
- u_int32_t ti_stat_ticks;
- u_int32_t ti_rx_coal_ticks;
- u_int32_t ti_tx_coal_ticks;
- u_int32_t ti_rx_max_coal_bds;
- u_int32_t ti_tx_max_coal_bds;
- u_int32_t ti_tx_buf_ratio;
- int ti_if_flags;
- int ti_txcnt;
- struct mtx ti_mtx;
- ti_flag_vals ti_flags;
- dev_t dev;
-};
-
-#define TI_LOCK(_sc) mtx_lock(&(_sc)->ti_mtx)
-#define TI_UNLOCK(_sc) mtx_unlock(&(_sc)->ti_mtx)
-
-/*
- * Microchip Technology 24Cxx EEPROM control bytes
- */
-#define EEPROM_CTL_READ 0xA1 /* 0101 0001 */
-#define EEPROM_CTL_WRITE 0xA0 /* 0101 0000 */
-
-/*
- * Note that EEPROM_START leaves transmission enabled.
- */
-#define EEPROM_START \
- TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); /* Pull clock pin high */\
- TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT); /* Set DATA bit to 1 */ \
- TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN); /* Enable xmit to write bit */\
- TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT); /* Pull DATA bit to 0 again */\
- TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); /* Pull clock low again */
-
-/*
- * EEPROM_STOP ends access to the EEPROM and clears the ETXEN bit so
- * that no further data can be written to the EEPROM I/O pin.
- */
-#define EEPROM_STOP \
- TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN); /* Disable xmit */ \
- TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT); /* Pull DATA to 0 */ \
- TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); /* Pull clock high */ \
- TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN); /* Enable xmit */ \
- TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT); /* Toggle DATA to 1 */ \
- TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN); /* Disable xmit. */ \
- TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); /* Pull clock low again */
-
-
-#ifdef __alpha__
-#undef vtophys
-#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)va)
-#endif
diff --git a/sys/dev/ti/ti_fw.h b/sys/dev/ti/ti_fw.h
deleted file mode 100644
index 89f5c9f9dae7..000000000000
--- a/sys/dev/ti/ti_fw.h
+++ /dev/null
@@ -1,4593 +0,0 @@
-/*
- * Firmware for Alteon Tigon 1 chip.
- * Generated by genfw.c
- *
- * $FreeBSD$
- */
-static int tigonFwReleaseMajor = 0xc;
-static int tigonFwReleaseMinor = 0x4;
-static int tigonFwReleaseFix = 0xb;
-static u_int32_t tigonFwStartAddr = 0x00004000;
-static u_int32_t tigonFwTextAddr = 0x00004000;
-static int tigonFwTextLen = 0x11140;
-static u_int32_t tigonFwRodataAddr = 0x00015140;
-static int tigonFwRodataLen = 0xac0;
-static u_int32_t tigonFwDataAddr = 0x00015c20;
-static int tigonFwDataLen = 0x170;
-static u_int32_t tigonFwSbssAddr = 0x00015d90;
-static int tigonFwSbssLen = 0x38;
-static u_int32_t tigonFwBssAddr = 0x00015dd0;
-static int tigonFwBssLen = 0x2080;
-static u_int32_t tigonFwText[] = {
-0x10000003,
-0x0, 0xd, 0xd, 0x3c1d0001,
-0x8fbd5c54, 0x3a0f021, 0x3c100000, 0x26104000,
-0xc00100c, 0x0, 0xd, 0x27bdffd8,
-0x3c1cc000, 0x3c1b0013, 0x377bd800, 0xd021,
-0x3c170013, 0x36f75418, 0x2e02021, 0x340583e8,
-0xafbf0024, 0xc002488, 0xafb00020, 0xc0023e8,
-0x0, 0x3c040001, 0x248451a4, 0x24050001,
-0x2e03021, 0x3821, 0x3c100001, 0x26107e50,
-0xafb00010, 0xc002403, 0xafbb0014, 0x3c02000f,
-0x3442ffff, 0x2021024, 0x362102b, 0x10400009,
-0x24050003, 0x3c040001, 0x248451b0, 0x2003021,
-0x3603821, 0x3c020010, 0xafa20010, 0xc002403,
-0xafa00014, 0x2021, 0x3405c000, 0x3c010001,
-0x370821, 0xa02083b0, 0x3c010001, 0x370821,
-0xa02083b2, 0x3c010001, 0x370821, 0xa02083b3,
-0x3c010001, 0x370821, 0xac2083b4, 0xa2e004d8,
-0x418c0, 0x24840001, 0x771021, 0xac40727c,
-0x771021, 0xac407280, 0x2e31021, 0xa445727c,
-0x2c820020, 0x1440fff7, 0x418c0, 0x2021,
-0x3405c000, 0x418c0, 0x24840001, 0x771021,
-0xac40737c, 0x771021, 0xac407380, 0x2e31021,
-0xa445737c, 0x2c820080, 0x5440fff7, 0x418c0,
-0xaf800054, 0xaf80011c, 0x8f820044, 0x34420040,
-0xaf820044, 0x8f820044, 0x34420020, 0xaf820044,
-0x8f420218, 0x30420002, 0x10400009, 0x0,
-0x8f420220, 0x3c030002, 0x34630004, 0x431025,
-0xaee204c4, 0x8f42021c, 0x8001074, 0x34420004,
-0x8f420220, 0x3c030002, 0x34630006, 0x431025,
-0xaee204c4, 0x8f42021c, 0x34420006, 0xaee204cc,
-0x8f420218, 0x30420010, 0x1040000a, 0x0,
-0x8f42021c, 0x34420004, 0xaee204c8, 0x8f420220,
-0x3c03000a, 0x34630004, 0x431025, 0x800108a,
-0xaee204c0, 0x8f420220, 0x3c03000a, 0x34630006,
-0x431025, 0xaee204c0, 0x8f42021c, 0x34420006,
-0xaee204c8, 0x8f420218, 0x30420200, 0x10400003,
-0x24020001, 0x8001091, 0xa2e27248, 0xa2e07248,
-0x24020001, 0xaf8200a0, 0xaf8200b0, 0x8f830054,
-0x8f820054, 0x8001099, 0x24630064, 0x8f820054,
-0x621023, 0x2c420065, 0x1440fffc, 0x0,
-0xaf800044, 0x8f420208, 0x8f43020c, 0xaee20010,
-0xaee30014, 0x8ee40010, 0x8ee50014, 0x26e20030,
-0xaee20028, 0x24020490, 0xaee20018, 0xaf840090,
-0xaf850094, 0x8ee20028, 0xaf8200b4, 0x96e2001a,
-0xaf82009c, 0x8f8200b0, 0x8ee304cc, 0x431025,
-0xaf8200b0, 0x8f8200b0, 0x30420004, 0x1440fffd,
-0x0, 0x8ee20450, 0x8ee30454, 0xaee304fc,
-0x8ee204fc, 0x2442e000, 0x2c422001, 0x1440000d,
-0x26e40030, 0x8ee20450, 0x8ee30454, 0x3c040001,
-0x248451bc, 0x3c050001, 0xafa00010, 0xafa00014,
-0x8ee704fc, 0x34a5f000, 0xc002403, 0x603021,
-0x26e40030, 0xc002488, 0x24050400, 0x27440080,
-0xc002488, 0x24050080, 0x26e4777c, 0xc002488,
-0x24050400, 0x8f42025c, 0x26e40094, 0xaee20060,
-0x8f420260, 0x27450200, 0x24060008, 0xaee20068,
-0x24020006, 0xc00249a, 0xaee20064, 0x3c023b9a,
-0x3442ca00, 0x2021, 0x24030002, 0xaee30074,
-0xaee30070, 0xaee2006c, 0x240203e8, 0xaee20104,
-0x24020001, 0xaee30100, 0xaee2010c, 0x3c030001,
-0x641821, 0x90635c20, 0x2e41021, 0x24840001,
-0xa043009c, 0x2c82000f, 0x1440fff8, 0x0,
-0x8f820040, 0x2e41821, 0x24840001, 0x21702,
-0x24420030, 0xa062009c, 0x2e41021, 0xa040009c,
-0x96e2046a, 0x30420003, 0x14400009, 0x0,
-0x96e2047a, 0x30420003, 0x50400131, 0x3c030800,
-0x96e2046a, 0x30420003, 0x1040002a, 0x3c020700,
-0x96e2047a, 0x30420003, 0x10400026, 0x3c020700,
-0x96e3047a, 0x96e2046a, 0x14620022, 0x3c020700,
-0x8ee204c0, 0x24030001, 0xa2e34e20, 0x34420e00,
-0xaee204c0, 0x8f420218, 0x30420100, 0x10400005,
-0x0, 0x3c020001, 0x2442e168, 0x800111d,
-0x21100, 0x3c020001, 0x2442d35c, 0x21100,
-0x21182, 0x3c030800, 0x431025, 0x3c010001,
-0xac221238, 0x3c020001, 0x2442f680, 0x21100,
-0x21182, 0x3c030800, 0x431025, 0x3c010001,
-0xac221278, 0x8ee20000, 0x34424000, 0x8001238,
-0xaee20000, 0x34423000, 0xafa20018, 0x8ee20608,
-0x8f430228, 0x24420001, 0x304900ff, 0x512300e2,
-0xafa00010, 0x8ee20608, 0x210c0, 0x571021,
-0x8fa30018, 0x8fa4001c, 0xac43060c, 0xac440610,
-0x8f870120, 0x27623800, 0x24e80020, 0x102102b,
-0x50400001, 0x27683000, 0x8f820128, 0x11020004,
-0x0, 0x8f820124, 0x15020007, 0x1021,
-0x8ee201a4, 0x3021, 0x24420001, 0xaee201a4,
-0x80011a0, 0x8ee201a4, 0x8ee40608, 0x420c0,
-0x801821, 0x8ee40430, 0x8ee50434, 0xa32821,
-0xa3302b, 0x822021, 0x862021, 0xace40000,
-0xace50004, 0x8ee30608, 0x24020008, 0xa4e2000e,
-0x2402000d, 0xace20018, 0xace9001c, 0x318c0,
-0x2463060c, 0x2e31021, 0xace20008, 0x8ee204c4,
-0xace20010, 0xaf880120, 0x92e24e20, 0x14400037,
-0x24060001, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x8c830000, 0x24020007, 0x1462001f,
-0x0, 0x8ee34e30, 0x8ee24e34, 0x1062001b,
-0x24030040, 0x8c820004, 0x24420001, 0xac820004,
-0x8ee24e34, 0x8ee54e30, 0x24420001, 0x10430007,
-0x0, 0x8ee24e34, 0x24420001, 0x10a20005,
-0x0, 0x800118a, 0x0, 0x14a00005,
-0x0, 0x8f820128, 0x24420020, 0xaf820128,
-0x8f820128, 0x8c820004, 0x2c420011, 0x50400013,
-0xac800000, 0x80011a0, 0x0, 0x8ee24e30,
-0x24030040, 0x24420001, 0x50430003, 0x1021,
-0x8ee24e30, 0x24420001, 0xaee24e30, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0x24020007,
-0xac820000, 0x24020001, 0xac820004, 0x54c0000c,
-0xaee90608, 0x3c040001, 0x248451c8, 0xafa00010,
-0xafa00014, 0x8ee60608, 0x8f470228, 0x3c050009,
-0xc002403, 0x34a5f000, 0x8001223, 0x0,
-0x8f830120, 0x27623800, 0x24660020, 0xc2102b,
-0x50400001, 0x27663000, 0x8f820128, 0x10c20004,
-0x0, 0x8f820124, 0x14c20007, 0x0,
-0x8ee201a4, 0x3021, 0x24420001, 0xaee201a4,
-0x8001207, 0x8ee201a4, 0x8ee20608, 0xac62001c,
-0x8ee404a0, 0x8ee504a4, 0x2462001c, 0xac620008,
-0x24020008, 0xa462000e, 0x24020011, 0xac620018,
-0xac640000, 0xac650004, 0x8ee204c4, 0xac620010,
-0xaf860120, 0x92e24e20, 0x14400037, 0x24060001,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x8c830000, 0x24020012, 0x1462001f, 0x0,
-0x8ee34e30, 0x8ee24e34, 0x1062001b, 0x24030040,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e34,
-0x8ee54e30, 0x24420001, 0x10430007, 0x0,
-0x8ee24e34, 0x24420001, 0x10a20005, 0x0,
-0x80011f1, 0x0, 0x14a00005, 0x0,
-0x8f820128, 0x24420020, 0xaf820128, 0x8f820128,
-0x8c820004, 0x2c420011, 0x50400013, 0xac800000,
-0x8001207, 0x0, 0x8ee24e30, 0x24030040,
-0x24420001, 0x50430003, 0x1021, 0x8ee24e30,
-0x24420001, 0xaee24e30, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x24020012, 0xac820000,
-0x24020001, 0xac820004, 0x14c0001b, 0x0,
-0x3c040001, 0x248451d0, 0xafa00010, 0xafa00014,
-0x8ee60608, 0x8f470228, 0x3c050009, 0xc002403,
-0x34a5f001, 0x8ee201b0, 0x24420001, 0xaee201b0,
-0x8001223, 0x8ee201b0, 0x3c040001, 0x248451dc,
-0xafa00014, 0x8ee60608, 0x8f470228, 0x3c050009,
-0xc002403, 0x34a5f005, 0x8ee201ac, 0x24420001,
-0xaee201ac, 0x8ee201ac, 0x8ee20160, 0x3c040001,
-0x248451e8, 0x3405f001, 0x24420001, 0xaee20160,
-0x8ee20160, 0x3021, 0x3821, 0xafa00010,
-0xc002403, 0xafa00014, 0x8001238, 0x0,
-0x3c020001, 0x2442f5a8, 0x21100, 0x21182,
-0x431025, 0x3c010001, 0xac221278, 0x96e2045a,
-0x30420003, 0x10400025, 0x3c050fff, 0x8ee204c8,
-0x34a5ffff, 0x34420a00, 0xaee204c8, 0x8ee304c8,
-0x3c040001, 0x248451f4, 0x24020001, 0xa2e204ec,
-0xa2e204ed, 0x3c020002, 0x621825, 0x3c020001,
-0x2442a390, 0x451024, 0x21082, 0xaee304c8,
-0x3c030800, 0x431025, 0x3c010001, 0xac221220,
-0x3c020001, 0x2442add4, 0x451024, 0x21082,
-0x431025, 0x3c010001, 0xac221280, 0x96e6045a,
-0x3821, 0x24050011, 0xafa00010, 0xc002403,
-0xafa00014, 0x8001268, 0x0, 0x3c020001,
-0x2442a9d4, 0x21100, 0x21182, 0x3c030800,
-0x431025, 0x3c010001, 0xac221280, 0x96e2046a,
-0x30420010, 0x14400009, 0x0, 0x96e2047a,
-0x30420010, 0x10400112, 0x0, 0x96e2046a,
-0x30420010, 0x10400005, 0x3c020700, 0x96e2047a,
-0x30420010, 0x14400102, 0x3c020700, 0x34423000,
-0xafa20018, 0x8ee20608, 0x8f430228, 0x24420001,
-0x304900ff, 0x512300e2, 0xafa00010, 0x8ee20608,
-0x210c0, 0x571021, 0x8fa30018, 0x8fa4001c,
-0xac43060c, 0xac440610, 0x8f870120, 0x27623800,
-0x24e80020, 0x102102b, 0x50400001, 0x27683000,
-0x8f820128, 0x11020004, 0x0, 0x8f820124,
-0x15020007, 0x1021, 0x8ee201a4, 0x3021,
-0x24420001, 0xaee201a4, 0x80012ea, 0x8ee201a4,
-0x8ee40608, 0x420c0, 0x801821, 0x8ee40430,
-0x8ee50434, 0xa32821, 0xa3302b, 0x822021,
-0x862021, 0xace40000, 0xace50004, 0x8ee30608,
-0x24020008, 0xa4e2000e, 0x2402000d, 0xace20018,
-0xace9001c, 0x318c0, 0x2463060c, 0x2e31021,
-0xace20008, 0x8ee204c4, 0xace20010, 0xaf880120,
-0x92e24e20, 0x14400037, 0x24060001, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0x8c830000,
-0x24020007, 0x1462001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x24030040, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee54e30,
-0x24420001, 0x10430007, 0x0, 0x8ee24e34,
-0x24420001, 0x10a20005, 0x0, 0x80012d4,
-0x0, 0x14a00005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400013, 0xac800000, 0x80012ea,
-0x0, 0x8ee24e30, 0x24030040, 0x24420001,
-0x50430003, 0x1021, 0x8ee24e30, 0x24420001,
-0xaee24e30, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x24020007, 0xac820000, 0x24020001,
-0xac820004, 0x54c0000c, 0xaee90608, 0x3c040001,
-0x248451c8, 0xafa00010, 0xafa00014, 0x8ee60608,
-0x8f470228, 0x3c050009, 0xc002403, 0x34a5f000,
-0x800136d, 0x0, 0x8f830120, 0x27623800,
-0x24660020, 0xc2102b, 0x50400001, 0x27663000,
-0x8f820128, 0x10c20004, 0x0, 0x8f820124,
-0x14c20007, 0x0, 0x8ee201a4, 0x3021,
-0x24420001, 0xaee201a4, 0x8001351, 0x8ee201a4,
-0x8ee20608, 0xac62001c, 0x8ee404a0, 0x8ee504a4,
-0x2462001c, 0xac620008, 0x24020008, 0xa462000e,
-0x24020011, 0xac620018, 0xac640000, 0xac650004,
-0x8ee204c4, 0xac620010, 0xaf860120, 0x92e24e20,
-0x14400037, 0x24060001, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x8c830000, 0x24020012,
-0x1462001f, 0x0, 0x8ee34e30, 0x8ee24e34,
-0x1062001b, 0x24030040, 0x8c820004, 0x24420001,
-0xac820004, 0x8ee24e34, 0x8ee54e30, 0x24420001,
-0x10430007, 0x0, 0x8ee24e34, 0x24420001,
-0x10a20005, 0x0, 0x800133b, 0x0,
-0x14a00005, 0x0, 0x8f820128, 0x24420020,
-0xaf820128, 0x8f820128, 0x8c820004, 0x2c420011,
-0x50400013, 0xac800000, 0x8001351, 0x0,
-0x8ee24e30, 0x24030040, 0x24420001, 0x50430003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x24020012, 0xac820000, 0x24020001, 0xac820004,
-0x14c0001b, 0x0, 0x3c040001, 0x248451d0,
-0xafa00010, 0xafa00014, 0x8ee60608, 0x8f470228,
-0x3c050009, 0xc002403, 0x34a5f001, 0x8ee201b0,
-0x24420001, 0xaee201b0, 0x800136d, 0x8ee201b0,
-0x3c040001, 0x248451dc, 0xafa00014, 0x8ee60608,
-0x8f470228, 0x3c050009, 0xc002403, 0x34a5f005,
-0x8ee201ac, 0x24420001, 0xaee201ac, 0x8ee201ac,
-0x8ee20160, 0x3c040001, 0x248451e8, 0x3405f002,
-0x24420001, 0xaee20160, 0x8ee20160, 0x3021,
-0x3821, 0xafa00010, 0xc002403, 0xafa00014,
-0x96e6047a, 0x96e7046a, 0x3c040001, 0x24845200,
-0x24050012, 0xafa00010, 0xc002403, 0xafa00014,
-0xc004500, 0x0, 0xc002318, 0x0,
-0x3c060001, 0x34c63800, 0xaee00608, 0xaf400228,
-0xaf40022c, 0x96e30458, 0x8ee40000, 0x3c0512d8,
-0x34a5c358, 0x27623800, 0xaee27258, 0x27623800,
-0xaee27260, 0x27623800, 0xaee27264, 0x3661021,
-0xaee27270, 0x2402ffff, 0xaee004d4, 0xaee004e0,
-0xaee004e4, 0xaee004f0, 0xa2e004f4, 0xaee00e0c,
-0xaee00e18, 0xaee00e10, 0xaee00e14, 0xaee00e1c,
-0xaee0724c, 0xaee05244, 0xaee05240, 0xaee0523c,
-0xaee07250, 0xaee07254, 0xaee0725c, 0xaee07268,
-0xaee004d0, 0x2463ffff, 0x852025, 0xaee304f8,
-0xaee40000, 0xaf800060, 0xaf820064, 0x3c020100,
-0xafa20018, 0x8ee20608, 0x8f430228, 0x24420001,
-0x304900ff, 0x512300e2, 0xafa00010, 0x8ee20608,
-0x210c0, 0x571021, 0x8fa30018, 0x8fa4001c,
-0xac43060c, 0xac440610, 0x8f870120, 0x27623800,
-0x24e80020, 0x102102b, 0x50400001, 0x27683000,
-0x8f820128, 0x11020004, 0x0, 0x8f820124,
-0x15020007, 0x1021, 0x8ee201a4, 0x3021,
-0x24420001, 0xaee201a4, 0x8001422, 0x8ee201a4,
-0x8ee40608, 0x420c0, 0x801821, 0x8ee40430,
-0x8ee50434, 0xa32821, 0xa3302b, 0x822021,
-0x862021, 0xace40000, 0xace50004, 0x8ee30608,
-0x24020008, 0xa4e2000e, 0x2402000d, 0xace20018,
-0xace9001c, 0x318c0, 0x2463060c, 0x2e31021,
-0xace20008, 0x8ee204c4, 0xace20010, 0xaf880120,
-0x92e24e20, 0x14400037, 0x24060001, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0x8c830000,
-0x24020007, 0x1462001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x24030040, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee54e30,
-0x24420001, 0x10430007, 0x0, 0x8ee24e34,
-0x24420001, 0x10a20005, 0x0, 0x800140c,
-0x0, 0x14a00005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400013, 0xac800000, 0x8001422,
-0x0, 0x8ee24e30, 0x24030040, 0x24420001,
-0x50430003, 0x1021, 0x8ee24e30, 0x24420001,
-0xaee24e30, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x24020007, 0xac820000, 0x24020001,
-0xac820004, 0x54c0000c, 0xaee90608, 0x3c040001,
-0x248451c8, 0xafa00010, 0xafa00014, 0x8ee60608,
-0x8f470228, 0x3c050009, 0xc002403, 0x34a5f000,
-0x80014a5, 0x0, 0x8f830120, 0x27623800,
-0x24660020, 0xc2102b, 0x50400001, 0x27663000,
-0x8f820128, 0x10c20004, 0x0, 0x8f820124,
-0x14c20007, 0x0, 0x8ee201a4, 0x3021,
-0x24420001, 0xaee201a4, 0x8001489, 0x8ee201a4,
-0x8ee20608, 0xac62001c, 0x8ee404a0, 0x8ee504a4,
-0x2462001c, 0xac620008, 0x24020008, 0xa462000e,
-0x24020011, 0xac620018, 0xac640000, 0xac650004,
-0x8ee204c4, 0xac620010, 0xaf860120, 0x92e24e20,
-0x14400037, 0x24060001, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x8c830000, 0x24020012,
-0x1462001f, 0x0, 0x8ee34e30, 0x8ee24e34,
-0x1062001b, 0x24030040, 0x8c820004, 0x24420001,
-0xac820004, 0x8ee24e34, 0x8ee54e30, 0x24420001,
-0x10430007, 0x0, 0x8ee24e34, 0x24420001,
-0x10a20005, 0x0, 0x8001473, 0x0,
-0x14a00005, 0x0, 0x8f820128, 0x24420020,
-0xaf820128, 0x8f820128, 0x8c820004, 0x2c420011,
-0x50400013, 0xac800000, 0x8001489, 0x0,
-0x8ee24e30, 0x24030040, 0x24420001, 0x50430003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x24020012, 0xac820000, 0x24020001, 0xac820004,
-0x14c0001b, 0x0, 0x3c040001, 0x248451d0,
-0xafa00010, 0xafa00014, 0x8ee60608, 0x8f470228,
-0x3c050009, 0xc002403, 0x34a5f001, 0x8ee201b0,
-0x24420001, 0xaee201b0, 0x80014a5, 0x8ee201b0,
-0x3c040001, 0x248451dc, 0xafa00014, 0x8ee60608,
-0x8f470228, 0x3c050009, 0xc002403, 0x34a5f005,
-0x8ee201ac, 0x24420001, 0xaee201ac, 0x8ee201ac,
-0x8ee20154, 0x24420001, 0xaee20154, 0xc0014dc,
-0x8ee20154, 0x8f8200a0, 0x30420004, 0x1440fffd,
-0x0, 0x8f820040, 0x30420001, 0x14400008,
-0x0, 0x8f430104, 0x24020001, 0x10620004,
-0x0, 0x8f420264, 0x10400006, 0x0,
-0x8ee2017c, 0x24420001, 0xaee2017c, 0x80014c5,
-0x8ee2017c, 0x8f820044, 0x34420004, 0xaf820044,
-0x8ee20178, 0x24420001, 0xaee20178, 0x8ee20178,
-0x8f8200d8, 0x8f8300d4, 0x431023, 0xaee2726c,
-0x8ee2726c, 0x1c400003, 0x3c030001, 0x431021,
-0xaee2726c, 0xc004064, 0x0, 0xc004440,
-0xaf800228, 0x8fbf0024, 0x8fb00020, 0x3e00008,
-0x27bd0028, 0x3e00008, 0x0, 0x3e00008,
-0x0, 0x0, 0x0, 0x2402002c,
-0xaf820050, 0xaee07274, 0x8f420238, 0xaee27278,
-0x8f820054, 0x24420067, 0xaf820058, 0xaee07b88,
-0xaee07b8c, 0xaee07b84, 0x3c010001, 0x370821,
-0xac2083bc, 0x3c010001, 0x370821, 0x3e00008,
-0xa02083b9, 0x27bdffd8, 0xafbf0024, 0xafb00020,
-0x8f820054, 0x3c030001, 0x8c635cd8, 0x24420067,
-0x1060000d, 0xaf820058, 0x3c020001, 0x571021,
-0x904283b8, 0x10400005, 0x3c030200, 0x3c010001,
-0x370821, 0x8001503, 0xa02083b8, 0x8ee20000,
-0x431025, 0xaee20000, 0x8f420218, 0x30420100,
-0x104000c6, 0x0, 0x8f8200b0, 0x30420004,
-0x104000c2, 0x0, 0x3c030001, 0x771821,
-0x8c6383d0, 0x8f820104, 0x146200b4, 0x0,
-0x3c030001, 0x771821, 0x8c6383d4, 0x8f8200b4,
-0x146200ae, 0x0, 0x8f8200b0, 0x3c030080,
-0x431024, 0x1040000d, 0x0, 0x8f82011c,
-0x34420002, 0xaf82011c, 0x8f8200b0, 0x2403fffb,
-0x431024, 0xaf8200b0, 0x8f82011c, 0x2403fffd,
-0x431024, 0x80015cc, 0xaf82011c, 0x3c030001,
-0x771821, 0x8c6383d0, 0x8f820104, 0x14620082,
-0x0, 0x3c030001, 0x771821, 0x8c6383d4,
-0x8f8200b4, 0x1462007c, 0x0, 0x3c070001,
-0xf73821, 0x8ce783d0, 0x8f8200b0, 0x3c040001,
-0x24845270, 0xafa00014, 0xafa20010, 0x8f8600b0,
-0x3c050005, 0xc002403, 0x34a50900, 0x8f82011c,
-0x34420002, 0xaf82011c, 0x8f830104, 0x8f8200b0,
-0x34420001, 0xaf8200b0, 0xaf830104, 0x8f830120,
-0x27623800, 0x24660020, 0xc2102b, 0x50400001,
-0x27663000, 0x8f820128, 0x10c20004, 0x0,
-0x8f820124, 0x14c20006, 0x0, 0x8ee201a4,
-0x24420001, 0xaee201a4, 0x80015a0, 0x8ee201a4,
-0x8f440208, 0x8f45020c, 0x26e20030, 0xac620008,
-0x24020400, 0xa462000e, 0x2402000f, 0xac620018,
-0xac60001c, 0xac640000, 0xac650004, 0x8ee204c4,
-0xac620010, 0xaf860120, 0x92e24e20, 0x14400037,
-0x0, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x8c830000, 0x24020007, 0x1462001f,
-0x0, 0x8ee34e30, 0x8ee24e34, 0x1062001b,
-0x24030040, 0x8c820004, 0x24420001, 0xac820004,
-0x8ee24e34, 0x8ee54e30, 0x24420001, 0x10430007,
-0x0, 0x8ee24e34, 0x24420001, 0x10a20005,
-0x0, 0x800158a, 0x0, 0x14a00005,
-0x0, 0x8f820128, 0x24420020, 0xaf820128,
-0x8f820128, 0x8c820004, 0x2c420011, 0x50400013,
-0xac800000, 0x80015a0, 0x0, 0x8ee24e30,
-0x24030040, 0x24420001, 0x50430003, 0x1021,
-0x8ee24e30, 0x24420001, 0xaee24e30, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0x24020007,
-0xac820000, 0x24020001, 0xac820004, 0x8f82011c,
-0x2403fffd, 0x431024, 0xaf82011c, 0x8ee201e4,
-0x3c070001, 0xf73821, 0x8ce783d0, 0x24420001,
-0xaee201e4, 0x8ee201e4, 0x3c040001, 0x2484527c,
-0x80015bd, 0xafa00010, 0x8f820104, 0x3c010001,
-0x370821, 0xac2283d0, 0x8f8200b4, 0x3c070001,
-0xf73821, 0x8ce783d0, 0x3c040001, 0x24845284,
-0x3c010001, 0x370821, 0xac2283d4, 0xafa00010,
-0xafa00014, 0x8f8600b0, 0x3c050005, 0xc002403,
-0x34a50900, 0x80015cc, 0x0, 0x8f820104,
-0x3c010001, 0x370821, 0xac2283d0, 0x8f8200b4,
-0x3c010001, 0x370821, 0xac2283d4, 0x8ee27274,
-0x92e304f4, 0x24420067, 0x14600006, 0xaee27274,
-0x8ee27274, 0x8f430234, 0x43102b, 0x1440007b,
-0x0, 0x8ee304e4, 0x8ee204f8, 0x14620004,
-0x0, 0x92e204f4, 0x50400074, 0xa2e004f4,
-0x8f830120, 0x27623800, 0x24660020, 0xc2102b,
-0x50400001, 0x27663000, 0x8f820128, 0x10c20004,
-0x0, 0x8f820124, 0x14c20007, 0x0,
-0x8ee201a4, 0x8021, 0x24420001, 0xaee201a4,
-0x8001637, 0x8ee201a4, 0x8ee204e4, 0xac62001c,
-0x8ee404b0, 0x8ee504b4, 0x2462001c, 0xac620008,
-0x24020008, 0xa462000e, 0x24020011, 0xac620018,
-0xac640000, 0xac650004, 0x8ee204c4, 0xac620010,
-0xaf860120, 0x92e24e20, 0x14400037, 0x24100001,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x8c830000, 0x24020012, 0x1462001f, 0x0,
-0x8ee34e30, 0x8ee24e34, 0x1062001b, 0x24030040,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e34,
-0x8ee54e30, 0x24420001, 0x10430007, 0x0,
-0x8ee24e34, 0x24420001, 0x10a20005, 0x0,
-0x8001621, 0x0, 0x14a00005, 0x0,
-0x8f820128, 0x24420020, 0xaf820128, 0x8f820128,
-0x8c820004, 0x2c420011, 0x50400013, 0xac800000,
-0x8001637, 0x0, 0x8ee24e30, 0x24030040,
-0x24420001, 0x50430003, 0x1021, 0x8ee24e30,
-0x24420001, 0xaee24e30, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x24020012, 0xac820000,
-0x24020001, 0xac820004, 0x5600000b, 0x24100001,
-0x8ee204e4, 0x3c040001, 0x2484528c, 0xafa00014,
-0xafa20010, 0x8ee60608, 0x8f470228, 0x3c050009,
-0xc002403, 0x34a5f006, 0x16000003, 0x24020001,
-0x8001650, 0xa2e204f4, 0x8ee20170, 0x24420001,
-0xaee20170, 0x8ee20170, 0x8ee204e4, 0xa2e004f4,
-0xaee004f0, 0xaee07274, 0xaee204f8, 0x8ee20e1c,
-0x1040006d, 0x0, 0x8f830120, 0x27623800,
-0x24660020, 0xc2102b, 0x50400001, 0x27663000,
-0x8f820128, 0x10c20004, 0x0, 0x8f820124,
-0x14c20007, 0x0, 0x8ee201a4, 0x8021,
-0x24420001, 0xaee201a4, 0x80016ad, 0x8ee201a4,
-0x8ee2724c, 0xac62001c, 0x8ee404a8, 0x8ee504ac,
-0x2462001c, 0xac620008, 0x24020008, 0xa462000e,
-0x24020011, 0xac620018, 0xac640000, 0xac650004,
-0x8ee204c4, 0xac620010, 0xaf860120, 0x92e24e20,
-0x14400037, 0x24100001, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x8c830000, 0x24020012,
-0x1462001f, 0x0, 0x8ee34e30, 0x8ee24e34,
-0x1062001b, 0x24030040, 0x8c820004, 0x24420001,
-0xac820004, 0x8ee24e34, 0x8ee54e30, 0x24420001,
-0x10430007, 0x0, 0x8ee24e34, 0x24420001,
-0x10a20005, 0x0, 0x8001697, 0x0,
-0x14a00005, 0x0, 0x8f820128, 0x24420020,
-0xaf820128, 0x8f820128, 0x8c820004, 0x2c420011,
-0x50400013, 0xac800000, 0x80016ad, 0x0,
-0x8ee24e30, 0x24030040, 0x24420001, 0x50430003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x24020012, 0xac820000, 0x24020001, 0xac820004,
-0x5600000b, 0x24100001, 0x8ee2724c, 0x3c040001,
-0x24845298, 0xafa00014, 0xafa20010, 0x8ee6724c,
-0x8f470280, 0x3c050009, 0xc002403, 0x34a5f008,
-0x56000001, 0xaee00e1c, 0x8ee20174, 0x24420001,
-0xaee20174, 0x8ee20174, 0x8ee24e24, 0x10400019,
-0x0, 0xaee04e24, 0x8f820040, 0x30420001,
-0x14400008, 0x0, 0x8f430104, 0x24020001,
-0x10620004, 0x0, 0x8f420264, 0x10400006,
-0x0, 0x8ee2017c, 0x24420001, 0xaee2017c,
-0x80016da, 0x8ee2017c, 0x8f820044, 0x34420004,
-0xaf820044, 0x8ee20178, 0x24420001, 0xaee20178,
-0x8ee20178, 0x8ee27278, 0x2442ff99, 0xaee27278,
-0x8ee27278, 0x1c4002ad, 0x0, 0x8f420238,
-0x104002aa, 0x0, 0x3c020001, 0x571021,
-0x904283e0, 0x144002a5, 0x0, 0x8f420080,
-0xaee2004c, 0x8f4200c0, 0xaee20048, 0x8f420084,
-0xaee20038, 0x8f420084, 0xaee20244, 0x8f420088,
-0xaee20248, 0x8f42008c, 0xaee2024c, 0x8f420090,
-0xaee20250, 0x8f420094, 0xaee20254, 0x8f420098,
-0xaee20258, 0x8f42009c, 0xaee2025c, 0x8f4200a0,
-0xaee20260, 0x8f4200a4, 0xaee20264, 0x8f4200a8,
-0xaee20268, 0x8f4200ac, 0xaee2026c, 0x8f4200b0,
-0xaee20270, 0x8f4200b4, 0xaee20274, 0x8f4200b8,
-0xaee20278, 0x8f4200bc, 0x24040001, 0xaee2027c,
-0xaee0003c, 0x41080, 0x571021, 0x8ee3003c,
-0x8c420244, 0x24840001, 0x621821, 0x2c82000f,
-0xaee3003c, 0x1440fff8, 0x41080, 0x8f4200cc,
-0xaee20050, 0x8f4200d0, 0xaee20054, 0x8f830120,
-0x27623800, 0x24660020, 0xc2102b, 0x50400001,
-0x27663000, 0x8f820128, 0x10c20004, 0x0,
-0x8f820124, 0x14c20007, 0x0, 0x8ee201a4,
-0x8021, 0x24420001, 0xaee201a4, 0x8001775,
-0x8ee201a4, 0x8f440208, 0x8f45020c, 0x26e20030,
-0xac620008, 0x24020400, 0xa462000e, 0x2402000f,
-0xac620018, 0xac60001c, 0xac640000, 0xac650004,
-0x8ee204c4, 0xac620010, 0xaf860120, 0x92e24e20,
-0x14400037, 0x24100001, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x8c830000, 0x24020007,
-0x1462001f, 0x0, 0x8ee34e30, 0x8ee24e34,
-0x1062001b, 0x24030040, 0x8c820004, 0x24420001,
-0xac820004, 0x8ee24e34, 0x8ee54e30, 0x24420001,
-0x10430007, 0x0, 0x8ee24e34, 0x24420001,
-0x10a20005, 0x0, 0x800175f, 0x0,
-0x14a00005, 0x0, 0x8f820128, 0x24420020,
-0xaf820128, 0x8f820128, 0x8c820004, 0x2c420011,
-0x50400013, 0xac800000, 0x8001775, 0x0,
-0x8ee24e30, 0x24030040, 0x24420001, 0x50430003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x24020007, 0xac820000, 0x24020001, 0xac820004,
-0x12000212, 0x3c020400, 0xafa20018, 0x3c020001,
-0x571021, 0x904283b0, 0x1040010b, 0x0,
-0x8ee20608, 0x8f430228, 0x24420001, 0x304a00ff,
-0x514300fd, 0xafa00010, 0x8ee20608, 0x210c0,
-0x571021, 0x8fa30018, 0x8fa4001c, 0xac43060c,
-0xac440610, 0x8f830054, 0x8f820054, 0x24690032,
-0x1221023, 0x2c420033, 0x1040006a, 0x5821,
-0x24180008, 0x240f000d, 0x240d0007, 0x240c0040,
-0x240e0001, 0x8f870120, 0x27623800, 0x24e80020,
-0x102102b, 0x50400001, 0x27683000, 0x8f820128,
-0x11020004, 0x0, 0x8f820124, 0x15020007,
-0x1021, 0x8ee201a4, 0x8021, 0x24420001,
-0xaee201a4, 0x80017f3, 0x8ee201a4, 0x8ee40608,
-0x420c0, 0x801821, 0x8ee40430, 0x8ee50434,
-0xa32821, 0xa3302b, 0x822021, 0x862021,
-0xace40000, 0xace50004, 0x8ee20608, 0xa4f8000e,
-0xacef0018, 0xacea001c, 0x210c0, 0x2442060c,
-0x2e21021, 0xace20008, 0x8ee204c4, 0xace20010,
-0xaf880120, 0x92e24e20, 0x14400033, 0x24100001,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x8c820000, 0x144d001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x0, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee34e30,
-0x24420001, 0x104c0007, 0x0, 0x8ee24e34,
-0x24420001, 0x10620005, 0x0, 0x80017e0,
-0x0, 0x14600005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400010, 0xac800000, 0x80017f3,
-0x0, 0x8ee24e30, 0x24420001, 0x504c0003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0xac8d0000, 0xac8e0004, 0x56000006, 0x240b0001,
-0x8f820054, 0x1221023, 0x2c420033, 0x1440ff9d,
-0x0, 0x316300ff, 0x24020001, 0x14620077,
-0x3c050009, 0xaeea0608, 0x8f830054, 0x8f820054,
-0x24690032, 0x1221023, 0x2c420033, 0x10400061,
-0x5821, 0x240d0008, 0x240c0011, 0x24080012,
-0x24070040, 0x240a0001, 0x8f830120, 0x27623800,
-0x24660020, 0xc2102b, 0x50400001, 0x27663000,
-0x8f820128, 0x10c20004, 0x0, 0x8f820124,
-0x14c20007, 0x0, 0x8ee201a4, 0x8021,
-0x24420001, 0xaee201a4, 0x800185f, 0x8ee201a4,
-0x8ee20608, 0xac62001c, 0x8ee404a0, 0x8ee504a4,
-0x2462001c, 0xac620008, 0xa46d000e, 0xac6c0018,
-0xac640000, 0xac650004, 0x8ee204c4, 0xac620010,
-0xaf860120, 0x92e24e20, 0x14400033, 0x24100001,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x8c820000, 0x1448001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x0, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee34e30,
-0x24420001, 0x10470007, 0x0, 0x8ee24e34,
-0x24420001, 0x10620005, 0x0, 0x800184c,
-0x0, 0x14600005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400010, 0xac800000, 0x800185f,
-0x0, 0x8ee24e30, 0x24420001, 0x50470003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0xac880000, 0xac8a0004, 0x56000006, 0x240b0001,
-0x8f820054, 0x1221023, 0x2c420033, 0x1440ffa6,
-0x0, 0x316300ff, 0x24020001, 0x14620003,
-0x3c050009, 0x800197c, 0x24100001, 0x3c040001,
-0x248452a4, 0xafa00010, 0xafa00014, 0x8f860120,
-0x8f870124, 0x800187b, 0x34a5f011, 0x3c040001,
-0x248452b0, 0xafa00010, 0xafa00014, 0x8f860120,
-0x8f870124, 0x34a5f010, 0xc002403, 0x8021,
-0x800197c, 0x0, 0x3c040001, 0x248452bc,
-0xafa00014, 0x8ee60608, 0x8f470228, 0x3c050009,
-0x8001975, 0x34a5f00f, 0x8ee20608, 0x8f430228,
-0x24420001, 0x304900ff, 0x512300e2, 0xafa00010,
-0x8ee20608, 0x210c0, 0x571021, 0x8fa30018,
-0x8fa4001c, 0xac43060c, 0xac440610, 0x8f870120,
-0x27623800, 0x24e80020, 0x102102b, 0x50400001,
-0x27683000, 0x8f820128, 0x11020004, 0x0,
-0x8f820124, 0x15020007, 0x1021, 0x8ee201a4,
-0x8021, 0x24420001, 0xaee201a4, 0x80018f7,
-0x8ee201a4, 0x8ee40608, 0x420c0, 0x801821,
-0x8ee40430, 0x8ee50434, 0xa32821, 0xa3302b,
-0x822021, 0x862021, 0xace40000, 0xace50004,
-0x8ee30608, 0x24020008, 0xa4e2000e, 0x2402000d,
-0xace20018, 0xace9001c, 0x318c0, 0x2463060c,
-0x2e31021, 0xace20008, 0x8ee204c4, 0xace20010,
-0xaf880120, 0x92e24e20, 0x14400037, 0x24100001,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x8c830000, 0x24020007, 0x1462001f, 0x0,
-0x8ee34e30, 0x8ee24e34, 0x1062001b, 0x24030040,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e34,
-0x8ee54e30, 0x24420001, 0x10430007, 0x0,
-0x8ee24e34, 0x24420001, 0x10a20005, 0x0,
-0x80018e1, 0x0, 0x14a00005, 0x0,
-0x8f820128, 0x24420020, 0xaf820128, 0x8f820128,
-0x8c820004, 0x2c420011, 0x50400013, 0xac800000,
-0x80018f7, 0x0, 0x8ee24e30, 0x24030040,
-0x24420001, 0x50430003, 0x1021, 0x8ee24e30,
-0x24420001, 0xaee24e30, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x24020007, 0xac820000,
-0x24020001, 0xac820004, 0x5600000c, 0xaee90608,
-0x3c040001, 0x248452c8, 0xafa00010, 0xafa00014,
-0x8ee60608, 0x8f470228, 0x3c050009, 0xc002403,
-0x34a5f000, 0x800197c, 0x0, 0x8f830120,
-0x27623800, 0x24660020, 0xc2102b, 0x50400001,
-0x27663000, 0x8f820128, 0x10c20004, 0x0,
-0x8f820124, 0x14c20007, 0x0, 0x8ee201a4,
-0x8021, 0x24420001, 0xaee201a4, 0x800195e,
-0x8ee201a4, 0x8ee20608, 0xac62001c, 0x8ee404a0,
-0x8ee504a4, 0x2462001c, 0xac620008, 0x24020008,
-0xa462000e, 0x24020011, 0xac620018, 0xac640000,
-0xac650004, 0x8ee204c4, 0xac620010, 0xaf860120,
-0x92e24e20, 0x14400037, 0x24100001, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0x8c830000,
-0x24020012, 0x1462001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x24030040, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee54e30,
-0x24420001, 0x10430007, 0x0, 0x8ee24e34,
-0x24420001, 0x10a20005, 0x0, 0x8001948,
-0x0, 0x14a00005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400013, 0xac800000, 0x800195e,
-0x0, 0x8ee24e30, 0x24030040, 0x24420001,
-0x50430003, 0x1021, 0x8ee24e30, 0x24420001,
-0xaee24e30, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x24020012, 0xac820000, 0x24020001,
-0xac820004, 0x5600001d, 0x24100001, 0x3c040001,
-0x248452d0, 0xafa00010, 0xafa00014, 0x8ee60608,
-0x8f470228, 0x3c050009, 0xc002403, 0x34a5f001,
-0x8ee201b0, 0x24420001, 0xaee201b0, 0x800197c,
-0x8ee201b0, 0x3c040001, 0x248452dc, 0xafa00014,
-0x8ee60608, 0x8f470228, 0x3c050009, 0x34a5f005,
-0xc002403, 0x0, 0x8ee201ac, 0x8021,
-0x24420001, 0xaee201ac, 0x8ee201ac, 0x1200000c,
-0x24020001, 0x3c010001, 0x370821, 0xa02083b0,
-0x8f420238, 0x8ee30158, 0x24630001, 0xaee30158,
-0x8ee30158, 0x800198c, 0xaee27278, 0x24020001,
-0x3c010001, 0x370821, 0xa02283b0, 0x3c020001,
-0x8c425cd8, 0x10400187, 0x0, 0x8ee27b84,
-0x24430001, 0x284200c9, 0x144001a4, 0xaee37b84,
-0x8ee204d4, 0x30420002, 0x14400119, 0xaee07b84,
-0x8ee204d4, 0x3c030600, 0x34631000, 0x34420002,
-0xaee204d4, 0xafa30018, 0x8ee20608, 0x8f430228,
-0x24420001, 0x304a00ff, 0x514300fd, 0xafa00010,
-0x8ee20608, 0x210c0, 0x571021, 0x8fa30018,
-0x8fa4001c, 0xac43060c, 0xac440610, 0x8f830054,
-0x8f820054, 0x24690032, 0x1221023, 0x2c420033,
-0x1040006a, 0x5821, 0x24180008, 0x240f000d,
-0x240d0007, 0x240c0040, 0x240e0001, 0x8f870120,
-0x27623800, 0x24e80020, 0x102102b, 0x50400001,
-0x27683000, 0x8f820128, 0x11020004, 0x0,
-0x8f820124, 0x15020007, 0x1021, 0x8ee201a4,
-0x8021, 0x24420001, 0xaee201a4, 0x8001a15,
-0x8ee201a4, 0x8ee40608, 0x420c0, 0x801821,
-0x8ee40430, 0x8ee50434, 0xa32821, 0xa3302b,
-0x822021, 0x862021, 0xace40000, 0xace50004,
-0x8ee20608, 0xa4f8000e, 0xacef0018, 0xacea001c,
-0x210c0, 0x2442060c, 0x2e21021, 0xace20008,
-0x8ee204c4, 0xace20010, 0xaf880120, 0x92e24e20,
-0x14400033, 0x24100001, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x8c820000, 0x144d001f,
-0x0, 0x8ee34e30, 0x8ee24e34, 0x1062001b,
-0x0, 0x8c820004, 0x24420001, 0xac820004,
-0x8ee24e34, 0x8ee34e30, 0x24420001, 0x104c0007,
-0x0, 0x8ee24e34, 0x24420001, 0x10620005,
-0x0, 0x8001a02, 0x0, 0x14600005,
-0x0, 0x8f820128, 0x24420020, 0xaf820128,
-0x8f820128, 0x8c820004, 0x2c420011, 0x50400010,
-0xac800000, 0x8001a15, 0x0, 0x8ee24e30,
-0x24420001, 0x504c0003, 0x1021, 0x8ee24e30,
-0x24420001, 0xaee24e30, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0xac8d0000, 0xac8e0004,
-0x56000006, 0x240b0001, 0x8f820054, 0x1221023,
-0x2c420033, 0x1440ff9d, 0x0, 0x316300ff,
-0x24020001, 0x54620078, 0xafa00010, 0xaeea0608,
-0x8f830054, 0x8f820054, 0x24690032, 0x1221023,
-0x2c420033, 0x10400061, 0x5821, 0x240d0008,
-0x240c0011, 0x24080012, 0x24070040, 0x240a0001,
-0x8f830120, 0x27623800, 0x24660020, 0xc2102b,
-0x50400001, 0x27663000, 0x8f820128, 0x10c20004,
-0x0, 0x8f820124, 0x14c20007, 0x0,
-0x8ee201a4, 0x8021, 0x24420001, 0xaee201a4,
-0x8001a81, 0x8ee201a4, 0x8ee20608, 0xac62001c,
-0x8ee404a0, 0x8ee504a4, 0x2462001c, 0xac620008,
-0xa46d000e, 0xac6c0018, 0xac640000, 0xac650004,
-0x8ee204c4, 0xac620010, 0xaf860120, 0x92e24e20,
-0x14400033, 0x24100001, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x8c820000, 0x1448001f,
-0x0, 0x8ee34e30, 0x8ee24e34, 0x1062001b,
-0x0, 0x8c820004, 0x24420001, 0xac820004,
-0x8ee24e34, 0x8ee34e30, 0x24420001, 0x10470007,
-0x0, 0x8ee24e34, 0x24420001, 0x10620005,
-0x0, 0x8001a6e, 0x0, 0x14600005,
-0x0, 0x8f820128, 0x24420020, 0xaf820128,
-0x8f820128, 0x8c820004, 0x2c420011, 0x50400010,
-0xac800000, 0x8001a81, 0x0, 0x8ee24e30,
-0x24420001, 0x50470003, 0x1021, 0x8ee24e30,
-0x24420001, 0xaee24e30, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0xac880000, 0xac8a0004,
-0x56000006, 0x240b0001, 0x8f820054, 0x1221023,
-0x2c420033, 0x1440ffa6, 0x0, 0x316300ff,
-0x24020001, 0x10620022, 0x0, 0x3c040001,
-0x248452a4, 0xafa00010, 0xafa00014, 0x8f860120,
-0x8f870124, 0x3c050009, 0xc002403, 0x34a5f011,
-0x8001aad, 0x0, 0x3c040001, 0x248452b0,
-0xafa00014, 0x8f860120, 0x8f870124, 0x3c050009,
-0xc002403, 0x34a5f010, 0x8001aad, 0x0,
-0x3c040001, 0x248452bc, 0xafa00014, 0x8ee60608,
-0x8f470228, 0x3c050009, 0xc002403, 0x34a5f00f,
-0x8ee201ac, 0x24420001, 0xaee201ac, 0x8ee201ac,
-0x8ee2015c, 0x24420001, 0xaee2015c, 0x8ee2015c,
-0x8ee204d4, 0x30420001, 0x10400055, 0x0,
-0x8f420218, 0x30420080, 0x10400029, 0x0,
-0x8f820044, 0x34420040, 0xaf820044, 0x8ee27b7c,
-0x402821, 0x8ee200c0, 0x8ee300c4, 0x24060000,
-0x2407ffff, 0x2021, 0x461024, 0x1444000d,
-0x671824, 0x1465000b, 0x0, 0x8ee27b80,
-0x402821, 0x8ee200e0, 0x8ee300e4, 0x2021,
-0x461024, 0x14440003, 0x671824, 0x1065000b,
-0x0, 0x8ee200c0, 0x8ee300c4, 0x8ee400e0,
-0x8ee500e4, 0xaee37b7c, 0xaee57b80, 0x8f820044,
-0x38420020, 0x8001b38, 0xaf820044, 0x8f820044,
-0x2403ffdf, 0x431024, 0x8001b38, 0xaf820044,
-0x8f820044, 0x2403ffdf, 0x431024, 0xaf820044,
-0x8ee27b7c, 0x402821, 0x8ee200c0, 0x8ee300c4,
-0x24060000, 0x2407ffff, 0x2021, 0x461024,
-0x1444000d, 0x671824, 0x1465000b, 0x0,
-0x8ee27b80, 0x402821, 0x8ee200e0, 0x8ee300e4,
-0x2021, 0x461024, 0x14440003, 0x671824,
-0x1065000b, 0x0, 0x8ee200c0, 0x8ee300c4,
-0x8ee400e0, 0x8ee500e4, 0xaee37b7c, 0xaee57b80,
-0x8f820044, 0x38420040, 0x8001b38, 0xaf820044,
-0x8f820044, 0x34420040, 0x8001b38, 0xaf820044,
-0x8f820044, 0x34420040, 0xaf820044, 0x8ee27b8c,
-0x24430001, 0x28420015, 0x14400028, 0xaee37b8c,
-0x8f820044, 0x38420020, 0xaf820044, 0x8001b38,
-0xaee07b8c, 0x8ee204d4, 0x30420001, 0x10400011,
-0x0, 0x8f420218, 0x30420080, 0x10400009,
-0x0, 0x8f820044, 0x34420020, 0xaf820044,
-0x8f820044, 0x2403ffbf, 0x431024, 0x8001b36,
-0xaf820044, 0x8f820044, 0x34420060, 0x8001b36,
-0xaf820044, 0x8f820044, 0x34420040, 0xaf820044,
-0x8ee27b88, 0x24430001, 0x28421389, 0x14400005,
-0xaee37b88, 0x8f820044, 0x38420020, 0xaf820044,
-0xaee07b88, 0xc004603, 0x0, 0x8fbf0024,
-0x8fb00020, 0x3e00008, 0x27bd0028, 0x27bdffb8,
-0xafbf0044, 0xafb60040, 0xafb5003c, 0xafb40038,
-0xafb30034, 0xafb20030, 0xafb1002c, 0xafb00028,
-0x8f960064, 0x32c20004, 0x1040000c, 0x24020004,
-0xaf820064, 0x8f420114, 0xaee204e0, 0x8f820060,
-0x34420008, 0xaf820060, 0x8ee2016c, 0x24420001,
-0xaee2016c, 0x80022f4, 0x8ee2016c, 0x32c20001,
-0x10400004, 0x24020001, 0xaf820064, 0x80022f4,
-0x0, 0x32c20002, 0x1440000c, 0x3c050003,
-0x3c040001, 0x24845354, 0x34a50001, 0x2c03021,
-0x3821, 0xafa00010, 0xc002403, 0xafa00014,
-0x2402fff8, 0x80022f4, 0xaf820064, 0x8f43022c,
-0x8f42010c, 0x5062000c, 0xafa00010, 0x8f42022c,
-0x21080, 0x5a1021, 0x8c420300, 0xafa20020,
-0x8f42022c, 0x24070001, 0x24420001, 0x3042003f,
-0x8001b80, 0xaf42022c, 0x3c040001, 0x24845360,
-0xafa00014, 0x8f46022c, 0x8f47010c, 0x3c050003,
-0xc002403, 0x34a5f01f, 0x3821, 0x14e00003,
-0x0, 0x80022ed, 0xaf960064, 0x93a20020,
-0x2443ffff, 0x2c620011, 0x10400658, 0x31080,
-0x3c010001, 0x220821, 0x8c225418, 0x400008,
-0x0, 0x8fa20020, 0x30420fff, 0xaee20e0c,
-0x8f820060, 0x34420200, 0xaf820060, 0x8ee20118,
-0x24420001, 0xaee20118, 0x80022e8, 0x8ee20118,
-0x8fa20020, 0x24030001, 0x3c010001, 0x370821,
-0xa02383b1, 0x30420fff, 0xaee25238, 0x8f820060,
-0x34420100, 0xaf820060, 0x8ee20144, 0x24420001,
-0xaee20144, 0x80022e8, 0x8ee20144, 0x8fa20020,
-0x21200, 0x22502, 0x24020001, 0x10820005,
-0x24020002, 0x10820009, 0x2402fffe, 0x8001bc9,
-0xafa00010, 0x8ee204d4, 0xaee40070, 0xaee40074,
-0x34420001, 0x8001bbd, 0xaee204d4, 0x8ee304d4,
-0xaee40070, 0xaee40074, 0x621824, 0xaee304d4,
-0x8f840054, 0x41442, 0x41c82, 0x431021,
-0x41cc2, 0x431023, 0x41d02, 0x431021,
-0x41d42, 0x431023, 0x8001bd0, 0xaee20078,
-0x3c040001, 0x2484536c, 0xafa00014, 0x8fa60020,
-0x3c050003, 0xc002403, 0x34a50004, 0x8ee20110,
-0x24420001, 0xaee20110, 0x80022e8, 0x8ee20110,
-0x27440212, 0xc0022fe, 0x24050006, 0x3049001f,
-0x920c0, 0x2e41021, 0x9442727c, 0x30424000,
-0x1040000a, 0x971021, 0x97430212, 0xa443727e,
-0x8f430214, 0x971021, 0xac437280, 0x2e41821,
-0x34028000, 0x8001c79, 0xa462727c, 0x9443727e,
-0x97420212, 0x14620006, 0x2e41021, 0x971021,
-0x8c437280, 0x8f420214, 0x1062009f, 0x2e41021,
-0x9442727c, 0x30428000, 0x1040002a, 0x2406ffff,
-0x2021, 0x410c0, 0x2e21021, 0x9442737c,
-0x30424000, 0x54400005, 0x803021, 0x24840001,
-0x2c820080, 0x1440fff8, 0x410c0, 0x4c10010,
-0x618c0, 0x610c0, 0x571821, 0x8c63737c,
-0x571021, 0xafa30010, 0x8c427380, 0x3c040001,
-0x24845378, 0xafa20014, 0x8f470214, 0x3c050003,
-0xc002403, 0x34a50013, 0x8001c90, 0x3c020800,
-0x97440212, 0x771021, 0xa444737e, 0x8f440214,
-0x771021, 0x2e31821, 0xac447380, 0x34028000,
-0xa462737c, 0x910c0, 0x2e21021, 0x8001c79,
-0xa446727c, 0x2e41021, 0x9445727c, 0x8001c2e,
-0x510c0, 0x9443737e, 0x97420212, 0x14620006,
-0x510c0, 0x971021, 0x8c437380, 0x8f420214,
-0x10620065, 0x510c0, 0x2e21021, 0x9445737c,
-0x510c0, 0x2e21021, 0x9442737c, 0x30428000,
-0x1040fff0, 0x971021, 0x520c0, 0x971021,
-0x9443737e, 0x97420212, 0x14620006, 0x2406ffff,
-0x971021, 0x8c437380, 0x8f420214, 0x10620053,
-0x3c020800, 0x2021, 0x410c0, 0x2e21021,
-0x9442737c, 0x30424000, 0x54400005, 0x803021,
-0x24840001, 0x2c820080, 0x1440fff8, 0x410c0,
-0x4c10023, 0x618c0, 0x910c0, 0x571821,
-0x8c63727c, 0x571021, 0xafa30010, 0x8c427280,
-0x3c040001, 0x24845384, 0xafa20014, 0x8f470214,
-0x3c050003, 0xc002403, 0x34a5f017, 0x8001c90,
-0x3c020800, 0x8f430210, 0xb71021, 0xac43777c,
-0x8f430214, 0xb71021, 0xac437780, 0x3c020001,
-0x571021, 0x8c4283b4, 0x24420001, 0x3c010001,
-0x370821, 0xac2283b4, 0x3c030001, 0x771821,
-0x8c6383b4, 0x2e51021, 0x8001c82, 0xa443777c,
-0x97440212, 0x771021, 0xa444737e, 0x8f440214,
-0x771021, 0x2e31821, 0xac447380, 0x34028000,
-0xa462737c, 0x510c0, 0x2e21021, 0xa446737c,
-0x2021, 0x428c0, 0x2e51021, 0x9442777c,
-0x1040ffdc, 0x24840001, 0x2c820080, 0x5440fffa,
-0x428c0, 0x92e204d8, 0x10400006, 0x24020001,
-0x8ee304dc, 0x1221004, 0x621825, 0x8001c8f,
-0xaee304dc, 0x8f830228, 0x24020001, 0x1221004,
-0x621825, 0xaf830228, 0x3c020800, 0x34421000,
-0xafa20018, 0x8ee20608, 0x8f430228, 0x24420001,
-0x304a00ff, 0x514300fd, 0xafa00010, 0x8ee20608,
-0x210c0, 0x571021, 0x8fa30018, 0x8fa4001c,
-0xac43060c, 0xac440610, 0x8f830054, 0x8f820054,
-0x24690032, 0x1221023, 0x2c420033, 0x1040006a,
-0x5821, 0x24100008, 0x240f000d, 0x240d0007,
-0x240c0040, 0x240e0001, 0x8f870120, 0x27623800,
-0x24e80020, 0x102102b, 0x50400001, 0x27683000,
-0x8f820128, 0x11020004, 0x0, 0x8f820124,
-0x15020007, 0x1021, 0x8ee201a4, 0x3821,
-0x24420001, 0xaee201a4, 0x8001d08, 0x8ee201a4,
-0x8ee40608, 0x420c0, 0x801821, 0x8ee40430,
-0x8ee50434, 0xa32821, 0xa3302b, 0x822021,
-0x862021, 0xace40000, 0xace50004, 0x8ee20608,
-0xa4f0000e, 0xacef0018, 0xacea001c, 0x210c0,
-0x2442060c, 0x2e21021, 0xace20008, 0x8ee204c4,
-0xace20010, 0xaf880120, 0x92e24e20, 0x14400033,
-0x24070001, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x8c820000, 0x144d001f, 0x0,
-0x8ee34e30, 0x8ee24e34, 0x1062001b, 0x0,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e34,
-0x8ee34e30, 0x24420001, 0x104c0007, 0x0,
-0x8ee24e34, 0x24420001, 0x10620005, 0x0,
-0x8001cf5, 0x0, 0x14600005, 0x0,
-0x8f820128, 0x24420020, 0xaf820128, 0x8f820128,
-0x8c820004, 0x2c420011, 0x50400010, 0xac800000,
-0x8001d08, 0x0, 0x8ee24e30, 0x24420001,
-0x504c0003, 0x1021, 0x8ee24e30, 0x24420001,
-0xaee24e30, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0xac8d0000, 0xac8e0004, 0x54e00006,
-0x240b0001, 0x8f820054, 0x1221023, 0x2c420033,
-0x1440ff9d, 0x0, 0x316300ff, 0x24020001,
-0x54620078, 0xafa00010, 0xaeea0608, 0x8f830054,
-0x8f820054, 0x24690032, 0x1221023, 0x2c420033,
-0x10400061, 0x5821, 0x240e0008, 0x240d0011,
-0x240a0012, 0x24080040, 0x240c0001, 0x8f830120,
-0x27623800, 0x24660020, 0xc2102b, 0x50400001,
-0x27663000, 0x8f820128, 0x10c20004, 0x0,
-0x8f820124, 0x14c20007, 0x0, 0x8ee201a4,
-0x3821, 0x24420001, 0xaee201a4, 0x8001d74,
-0x8ee201a4, 0x8ee20608, 0xac62001c, 0x8ee404a0,
-0x8ee504a4, 0x2462001c, 0xac620008, 0xa46e000e,
-0xac6d0018, 0xac640000, 0xac650004, 0x8ee204c4,
-0xac620010, 0xaf860120, 0x92e24e20, 0x14400033,
-0x24070001, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x8c820000, 0x144a001f, 0x0,
-0x8ee34e30, 0x8ee24e34, 0x1062001b, 0x0,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e34,
-0x8ee34e30, 0x24420001, 0x10480007, 0x0,
-0x8ee24e34, 0x24420001, 0x10620005, 0x0,
-0x8001d61, 0x0, 0x14600005, 0x0,
-0x8f820128, 0x24420020, 0xaf820128, 0x8f820128,
-0x8c820004, 0x2c420011, 0x50400010, 0xac800000,
-0x8001d74, 0x0, 0x8ee24e30, 0x24420001,
-0x50480003, 0x1021, 0x8ee24e30, 0x24420001,
-0xaee24e30, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0xac8a0000, 0xac8c0004, 0x54e00006,
-0x240b0001, 0x8f820054, 0x1221023, 0x2c420033,
-0x1440ffa6, 0x0, 0x316300ff, 0x24020001,
-0x10620022, 0x0, 0x3c040001, 0x24845390,
-0xafa00010, 0xafa00014, 0x8f860120, 0x8f870124,
-0x3c050009, 0xc002403, 0x34a5f011, 0x8001da0,
-0x0, 0x3c040001, 0x2484539c, 0xafa00014,
-0x8f860120, 0x8f870124, 0x3c050009, 0xc002403,
-0x34a5f010, 0x8001da0, 0x0, 0x3c040001,
-0x248453a8, 0xafa00014, 0x8ee60608, 0x8f470228,
-0x3c050009, 0xc002403, 0x34a5f00f, 0x8ee201ac,
-0x24420001, 0xaee201ac, 0x8ee201ac, 0x8ee20124,
-0x24420001, 0xaee20124, 0x8001f97, 0x8ee20124,
-0x27440212, 0xc0022fe, 0x24050006, 0x3049001f,
-0x928c0, 0x2e51021, 0x9442727c, 0x30428000,
-0x1040002f, 0x2e51021, 0x9442727c, 0x30424000,
-0x1440001c, 0xb71021, 0x9443727e, 0x97420212,
-0x14620018, 0xb71021, 0x8c437280, 0x8f420214,
-0x54620016, 0xafa20010, 0x92e204d8, 0x10400007,
-0x24020001, 0x8ee304dc, 0x1221004, 0x21027,
-0x621824, 0x8001dc9, 0xaee304dc, 0x8f830228,
-0x1221004, 0x21027, 0x621824, 0xaf830228,
-0x910c0, 0x2e21821, 0x3402c000, 0x8001e4e,
-0xa462727c, 0x8f420214, 0xafa20010, 0x910c0,
-0x571021, 0x8c42727c, 0x3c040001, 0x248453b4,
-0x3c050003, 0xafa20014, 0x8f470210, 0x34a5f01c,
-0xc002403, 0x1203021, 0x8001e83, 0x3c020800,
-0xb71021, 0x9443727e, 0x97420212, 0x14620019,
-0x918c0, 0xb71021, 0x8c437280, 0x8f420214,
-0x14620014, 0x918c0, 0x2e51021, 0x9447727c,
-0x720c0, 0x971021, 0x9443737e, 0xb71021,
-0xa443727e, 0x971021, 0x8c437380, 0xb71021,
-0xac437280, 0x2e41021, 0x9443737c, 0x2e51021,
-0xa443727c, 0x2e41821, 0x3402c000, 0x8001e4e,
-0xa462737c, 0x2e31021, 0x9447727c, 0x3021,
-0x720c0, 0x2e41021, 0x9442737c, 0x4021,
-0x30428000, 0x14400025, 0xe02821, 0x605021,
-0x340bc000, 0x971021, 0x9443737e, 0x97420212,
-0x54620015, 0xe02821, 0x971021, 0x8c437380,
-0x8f420214, 0x54620010, 0xe02821, 0x11000006,
-0x2e41021, 0x9443737c, 0x510c0, 0x2e21021,
-0x8001e1a, 0xa443737c, 0x9443737c, 0x2ea1021,
-0xa443727c, 0x710c0, 0x2e21021, 0xa44b737c,
-0x8001e28, 0x24060001, 0x510c0, 0x2e21021,
-0x9447737c, 0x720c0, 0x2e41021, 0x9442737c,
-0x30428000, 0x1040ffdf, 0x25080001, 0x30c200ff,
-0x14400025, 0x2021, 0x720c0, 0x971021,
-0x9443737e, 0x97420212, 0x1462000f, 0x910c0,
-0x971021, 0x8c437380, 0x8f420214, 0x1462000a,
-0x910c0, 0x2e41821, 0x3402c000, 0x15000015,
-0xa462737c, 0x910c0, 0x2e21821, 0x34028000,
-0x8001e4e, 0xa462727c, 0x571021, 0x8c42727c,
-0x3c040001, 0x248453c0, 0x3c050003, 0xafa20010,
-0x710c0, 0x571021, 0x8c42737c, 0x34a5001e,
-0x1203021, 0xc002403, 0xafa20014, 0x8001e83,
-0x3c020800, 0x2021, 0x428c0, 0xb71021,
-0x9443777e, 0x97420212, 0x5462002b, 0x24840001,
-0xb71021, 0x8c437780, 0x8f420214, 0x54620026,
-0x24840001, 0x3c020001, 0x571021, 0x8c4283b4,
-0x2442ffff, 0x3c010001, 0x370821, 0xac2283b4,
-0x3c020001, 0x571021, 0x8c4283b4, 0x809021,
-0x242102b, 0x1040000e, 0x24b1777c, 0x24b07784,
-0x2f02021, 0x2f12821, 0xc002490, 0x24060008,
-0x26310008, 0x3c020001, 0x571021, 0x8c4283b4,
-0x26520001, 0x242102b, 0x1440fff5, 0x26100008,
-0x3c040001, 0x972021, 0x8c8483b4, 0x24050008,
-0x420c0, 0x2484777c, 0xc002488, 0x2e42021,
-0x8001e83, 0x3c020800, 0x2c820080, 0x1440ffcf,
-0x428c0, 0x3c020800, 0x34422000, 0xafa20018,
-0x8ee20608, 0x8f430228, 0x24420001, 0x304a00ff,
-0x514300fd, 0xafa00010, 0x8ee20608, 0x210c0,
-0x571021, 0x8fa30018, 0x8fa4001c, 0xac43060c,
-0xac440610, 0x8f830054, 0x8f820054, 0x24690032,
-0x1221023, 0x2c420033, 0x1040006a, 0x5821,
-0x24100008, 0x240f000d, 0x240d0007, 0x240c0040,
-0x240e0001, 0x8f870120, 0x27623800, 0x24e80020,
-0x102102b, 0x50400001, 0x27683000, 0x8f820128,
-0x11020004, 0x0, 0x8f820124, 0x15020007,
-0x1021, 0x8ee201a4, 0x3821, 0x24420001,
-0xaee201a4, 0x8001efb, 0x8ee201a4, 0x8ee40608,
-0x420c0, 0x801821, 0x8ee40430, 0x8ee50434,
-0xa32821, 0xa3302b, 0x822021, 0x862021,
-0xace40000, 0xace50004, 0x8ee20608, 0xa4f0000e,
-0xacef0018, 0xacea001c, 0x210c0, 0x2442060c,
-0x2e21021, 0xace20008, 0x8ee204c4, 0xace20010,
-0xaf880120, 0x92e24e20, 0x14400033, 0x24070001,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x8c820000, 0x144d001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x0, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee34e30,
-0x24420001, 0x104c0007, 0x0, 0x8ee24e34,
-0x24420001, 0x10620005, 0x0, 0x8001ee8,
-0x0, 0x14600005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400010, 0xac800000, 0x8001efb,
-0x0, 0x8ee24e30, 0x24420001, 0x504c0003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0xac8d0000, 0xac8e0004, 0x54e00006, 0x240b0001,
-0x8f820054, 0x1221023, 0x2c420033, 0x1440ff9d,
-0x0, 0x316300ff, 0x24020001, 0x54620078,
-0xafa00010, 0xaeea0608, 0x8f830054, 0x8f820054,
-0x24690032, 0x1221023, 0x2c420033, 0x10400061,
-0x5821, 0x240e0008, 0x240d0011, 0x240a0012,
-0x24080040, 0x240c0001, 0x8f830120, 0x27623800,
-0x24660020, 0xc2102b, 0x50400001, 0x27663000,
-0x8f820128, 0x10c20004, 0x0, 0x8f820124,
-0x14c20007, 0x0, 0x8ee201a4, 0x3821,
-0x24420001, 0xaee201a4, 0x8001f67, 0x8ee201a4,
-0x8ee20608, 0xac62001c, 0x8ee404a0, 0x8ee504a4,
-0x2462001c, 0xac620008, 0xa46e000e, 0xac6d0018,
-0xac640000, 0xac650004, 0x8ee204c4, 0xac620010,
-0xaf860120, 0x92e24e20, 0x14400033, 0x24070001,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x8c820000, 0x144a001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x0, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee34e30,
-0x24420001, 0x10480007, 0x0, 0x8ee24e34,
-0x24420001, 0x10620005, 0x0, 0x8001f54,
-0x0, 0x14600005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400010, 0xac800000, 0x8001f67,
-0x0, 0x8ee24e30, 0x24420001, 0x50480003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0xac8a0000, 0xac8c0004, 0x54e00006, 0x240b0001,
-0x8f820054, 0x1221023, 0x2c420033, 0x1440ffa6,
-0x0, 0x316300ff, 0x24020001, 0x10620022,
-0x0, 0x3c040001, 0x24845390, 0xafa00010,
-0xafa00014, 0x8f860120, 0x8f870124, 0x3c050009,
-0xc002403, 0x34a5f011, 0x8001f93, 0x0,
-0x3c040001, 0x2484539c, 0xafa00014, 0x8f860120,
-0x8f870124, 0x3c050009, 0xc002403, 0x34a5f010,
-0x8001f93, 0x0, 0x3c040001, 0x248453a8,
-0xafa00014, 0x8ee60608, 0x8f470228, 0x3c050009,
-0xc002403, 0x34a5f00f, 0x8ee201ac, 0x24420001,
-0xaee201ac, 0x8ee201ac, 0x8ee20128, 0x24420001,
-0xaee20128, 0x8ee20128, 0x8ee20164, 0x24420001,
-0xaee20164, 0x80022e8, 0x8ee20164, 0x8fa20020,
-0x21200, 0x21d02, 0x24020001, 0x10620005,
-0x24020002, 0x1062000d, 0x0, 0x8001fb7,
-0xafa00010, 0x92e204d8, 0x14400006, 0x24020001,
-0x8f820228, 0xaee204dc, 0x2402ffff, 0xaf820228,
-0x24020001, 0x8001fbe, 0xa2e204d8, 0x92e204d8,
-0x5040000c, 0xa2e004d8, 0x8ee204dc, 0xaf820228,
-0x8001fbe, 0xa2e004d8, 0x3c040001, 0x248453c8,
-0xafa00014, 0x8fa60020, 0x3c050003, 0xc002403,
-0x34a5f009, 0x8ee2013c, 0x24420001, 0xaee2013c,
-0x80022e8, 0x8ee2013c, 0x8fa20020, 0x21200,
-0x22502, 0x24020001, 0x10820005, 0x24020002,
-0x1082000f, 0x0, 0x8001fe3, 0xafa00010,
-0x8f820220, 0x3c0308ff, 0x3463ffff, 0x431024,
-0x34420008, 0xaf820220, 0x24020001, 0x3c010001,
-0x370821, 0xa02283b2, 0x8001fea, 0xaee40108,
-0x8f820220, 0x3c0308ff, 0x3463fff7, 0x431024,
-0xaf820220, 0x3c010001, 0x370821, 0xa02083b2,
-0x8001fea, 0xaee40108, 0x3c040001, 0x248453d4,
-0xafa00014, 0x8fa60020, 0x3c050003, 0xc002403,
-0x34a5f00a, 0x8ee2012c, 0x24420001, 0xaee2012c,
-0x80022e8, 0x8ee2012c, 0x8fa20020, 0x21200,
-0x21d02, 0x24020001, 0x10620005, 0x24020002,
-0x1062000e, 0x0, 0x8002011, 0xafa00010,
-0x8f820220, 0x3c0308ff, 0x3463ffff, 0x431024,
-0x34420008, 0xaf820220, 0x24020001, 0x3c010001,
-0x370821, 0x8002018, 0xa02283b3, 0x3c020001,
-0x571021, 0x904283b2, 0x3c010001, 0x370821,
-0x1440000e, 0xa02083b3, 0x8f820220, 0x3c0308ff,
-0x3463fff7, 0x431024, 0x8002018, 0xaf820220,
-0x3c040001, 0x248453e0, 0xafa00014, 0x8fa60020,
-0x3c050003, 0xc002403, 0x34a5f00b, 0x8ee20114,
-0x24420001, 0xaee20114, 0x80022e8, 0x8ee20114,
-0x27840208, 0x27450200, 0xc00249a, 0x24060008,
-0x26e40094, 0x27450200, 0xc00249a, 0x24060008,
-0x8ee20134, 0x24420001, 0xaee20134, 0x80022e8,
-0x8ee20134, 0x8f460248, 0x2021, 0xc005108,
-0x24050004, 0x8ee20130, 0x24420001, 0xaee20130,
-0x80022e8, 0x8ee20130, 0x8ef301cc, 0x8ef401d0,
-0x8ef501d8, 0x8ee20140, 0x26e40030, 0x24420001,
-0xaee20140, 0x8ef00140, 0x8ef10074, 0x8ef20070,
-0xc002488, 0x24050400, 0xaef301cc, 0xaef401d0,
-0xaef501d8, 0xaef00140, 0xaef10074, 0xaef20070,
-0x8f42025c, 0x26e40094, 0xaee20060, 0x8f420260,
-0x27450200, 0x24060008, 0xaee20068, 0x24020006,
-0xc00249a, 0xaee20064, 0x3c023b9a, 0x3442ca00,
-0xaee2006c, 0x240203e8, 0x24040002, 0x24030001,
-0xaee20104, 0xaee40100, 0xaee3010c, 0x8f820220,
-0x30420008, 0x10400004, 0x0, 0xaee30108,
-0x8002061, 0x2021, 0xaee40108, 0x2021,
-0x3c030001, 0x641821, 0x90635c30, 0x2e41021,
-0x24840001, 0xa043009c, 0x2c82000f, 0x1440fff8,
-0x0, 0x8f820040, 0x2e41821, 0x24840001,
-0x21702, 0x24420030, 0xa062009c, 0x2e41021,
-0x80022e8, 0xa040009c, 0x24020001, 0x3c010001,
-0x370821, 0xa02283e0, 0x240b0400, 0x24080014,
-0x240a0040, 0x24090001, 0x8f830100, 0x27623000,
-0x24660020, 0xc2102b, 0x50400001, 0x27662800,
-0x8f820108, 0x10c20004, 0x0, 0x8f820104,
-0x14c20007, 0x26e20030, 0x8ee201a8, 0x3821,
-0x24420001, 0xaee201a8, 0x80020a8, 0x8ee201a8,
-0x8ee404b8, 0x8ee504bc, 0xac620008, 0xa46b000e,
-0xac680018, 0xac60001c, 0xac640000, 0xac650004,
-0x8ee204cc, 0xac620010, 0xaf860100, 0x92e204ec,
-0x1440000e, 0x24070001, 0x8ee24e28, 0x24420001,
-0x504a0003, 0x1021, 0x8ee24e28, 0x24420001,
-0xaee24e28, 0x8ee24e28, 0x210c0, 0x24424e38,
-0x2e21021, 0xac480000, 0xac490004, 0x10e0ffd2,
-0x0, 0x80022e8, 0x0, 0x3c020900,
-0xaee05238, 0xaee0523c, 0xaee05240, 0xaee05244,
-0xaee001d0, 0x3c010001, 0x370821, 0xa02083b1,
-0xafa20018, 0x8ee20608, 0x8f430228, 0x24420001,
-0x304a00ff, 0x514300fd, 0xafa00010, 0x8ee20608,
-0x210c0, 0x571021, 0x8fa30018, 0x8fa4001c,
-0xac43060c, 0xac440610, 0x8f830054, 0x8f820054,
-0x24690032, 0x1221023, 0x2c420033, 0x1040006a,
-0x5821, 0x24100008, 0x240f000d, 0x240d0007,
-0x240c0040, 0x240e0001, 0x8f870120, 0x27623800,
-0x24e80020, 0x102102b, 0x50400001, 0x27683000,
-0x8f820128, 0x11020004, 0x0, 0x8f820124,
-0x15020007, 0x1021, 0x8ee201a4, 0x3821,
-0x24420001, 0xaee201a4, 0x800212c, 0x8ee201a4,
-0x8ee40608, 0x420c0, 0x801821, 0x8ee40430,
-0x8ee50434, 0xa32821, 0xa3302b, 0x822021,
-0x862021, 0xace40000, 0xace50004, 0x8ee20608,
-0xa4f0000e, 0xacef0018, 0xacea001c, 0x210c0,
-0x2442060c, 0x2e21021, 0xace20008, 0x8ee204c4,
-0xace20010, 0xaf880120, 0x92e24e20, 0x14400033,
-0x24070001, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x8c820000, 0x144d001f, 0x0,
-0x8ee34e30, 0x8ee24e34, 0x1062001b, 0x0,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e34,
-0x8ee34e30, 0x24420001, 0x104c0007, 0x0,
-0x8ee24e34, 0x24420001, 0x10620005, 0x0,
-0x8002119, 0x0, 0x14600005, 0x0,
-0x8f820128, 0x24420020, 0xaf820128, 0x8f820128,
-0x8c820004, 0x2c420011, 0x50400010, 0xac800000,
-0x800212c, 0x0, 0x8ee24e30, 0x24420001,
-0x504c0003, 0x1021, 0x8ee24e30, 0x24420001,
-0xaee24e30, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0xac8d0000, 0xac8e0004, 0x54e00006,
-0x240b0001, 0x8f820054, 0x1221023, 0x2c420033,
-0x1440ff9d, 0x0, 0x316300ff, 0x24020001,
-0x54620078, 0xafa00010, 0xaeea0608, 0x8f830054,
-0x8f820054, 0x24690032, 0x1221023, 0x2c420033,
-0x10400061, 0x5821, 0x240e0008, 0x240d0011,
-0x240a0012, 0x24080040, 0x240c0001, 0x8f830120,
-0x27623800, 0x24660020, 0xc2102b, 0x50400001,
-0x27663000, 0x8f820128, 0x10c20004, 0x0,
-0x8f820124, 0x14c20007, 0x0, 0x8ee201a4,
-0x3821, 0x24420001, 0xaee201a4, 0x8002198,
-0x8ee201a4, 0x8ee20608, 0xac62001c, 0x8ee404a0,
-0x8ee504a4, 0x2462001c, 0xac620008, 0xa46e000e,
-0xac6d0018, 0xac640000, 0xac650004, 0x8ee204c4,
-0xac620010, 0xaf860120, 0x92e24e20, 0x14400033,
-0x24070001, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x8c820000, 0x144a001f, 0x0,
-0x8ee34e30, 0x8ee24e34, 0x1062001b, 0x0,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e34,
-0x8ee34e30, 0x24420001, 0x10480007, 0x0,
-0x8ee24e34, 0x24420001, 0x10620005, 0x0,
-0x8002185, 0x0, 0x14600005, 0x0,
-0x8f820128, 0x24420020, 0xaf820128, 0x8f820128,
-0x8c820004, 0x2c420011, 0x50400010, 0xac800000,
-0x8002198, 0x0, 0x8ee24e30, 0x24420001,
-0x50480003, 0x1021, 0x8ee24e30, 0x24420001,
-0xaee24e30, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0xac8a0000, 0xac8c0004, 0x54e00006,
-0x240b0001, 0x8f820054, 0x1221023, 0x2c420033,
-0x1440ffa6, 0x0, 0x316300ff, 0x24020001,
-0x10620022, 0x0, 0x3c040001, 0x24845390,
-0xafa00010, 0xafa00014, 0x8f860120, 0x8f870124,
-0x3c050009, 0xc002403, 0x34a5f011, 0x80021c4,
-0x0, 0x3c040001, 0x2484539c, 0xafa00014,
-0x8f860120, 0x8f870124, 0x3c050009, 0xc002403,
-0x34a5f010, 0x80021c4, 0x0, 0x3c040001,
-0x248453a8, 0xafa00014, 0x8ee60608, 0x8f470228,
-0x3c050009, 0xc002403, 0x34a5f00f, 0x8ee201ac,
-0x24420001, 0xaee201ac, 0x8ee201ac, 0x8ee20120,
-0x24420001, 0xaee20120, 0x8ee20120, 0x8ee20168,
-0x24420001, 0xaee20168, 0x80022e8, 0x8ee20168,
-0x8f42025c, 0x26e40094, 0xaee20060, 0x8f420260,
-0x27450200, 0x24060008, 0xc00249a, 0xaee20068,
-0x8f820220, 0x30420008, 0x14400002, 0x24020001,
-0x24020002, 0xaee20108, 0x8ee2011c, 0x24420001,
-0xaee2011c, 0x80022e8, 0x8ee2011c, 0x3c040001,
-0x248453ec, 0xafa00010, 0xafa00014, 0x8fa60020,
-0x3c050003, 0xc002403, 0x34a5f00f, 0x93a20020,
-0x3c030700, 0x34631000, 0x431025, 0xafa20018,
-0x8ee20608, 0x8f430228, 0x24420001, 0x304900ff,
-0x512300e2, 0xafa00010, 0x8ee20608, 0x210c0,
-0x571021, 0x8fa30018, 0x8fa4001c, 0xac43060c,
-0xac440610, 0x8f870120, 0x27623800, 0x24e80020,
-0x102102b, 0x50400001, 0x27683000, 0x8f820128,
-0x11020004, 0x0, 0x8f820124, 0x15020007,
-0x1021, 0x8ee201a4, 0x3821, 0x24420001,
-0xaee201a4, 0x800225d, 0x8ee201a4, 0x8ee40608,
-0x420c0, 0x801821, 0x8ee40430, 0x8ee50434,
-0xa32821, 0xa3302b, 0x822021, 0x862021,
-0xace40000, 0xace50004, 0x8ee30608, 0x24020008,
-0xa4e2000e, 0x2402000d, 0xace20018, 0xace9001c,
-0x318c0, 0x2463060c, 0x2e31021, 0xace20008,
-0x8ee204c4, 0xace20010, 0xaf880120, 0x92e24e20,
-0x14400037, 0x24070001, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x8c830000, 0x24020007,
-0x1462001f, 0x0, 0x8ee34e30, 0x8ee24e34,
-0x1062001b, 0x24030040, 0x8c820004, 0x24420001,
-0xac820004, 0x8ee24e34, 0x8ee54e30, 0x24420001,
-0x10430007, 0x0, 0x8ee24e34, 0x24420001,
-0x10a20005, 0x0, 0x8002247, 0x0,
-0x14a00005, 0x0, 0x8f820128, 0x24420020,
-0xaf820128, 0x8f820128, 0x8c820004, 0x2c420011,
-0x50400013, 0xac800000, 0x800225d, 0x0,
-0x8ee24e30, 0x24030040, 0x24420001, 0x50430003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x24020007, 0xac820000, 0x24020001, 0xac820004,
-0x54e0000c, 0xaee90608, 0x3c040001, 0x248453f4,
-0xafa00010, 0xafa00014, 0x8ee60608, 0x8f470228,
-0x3c050009, 0xc002403, 0x34a5f000, 0x80022e0,
-0x0, 0x8f830120, 0x27623800, 0x24660020,
-0xc2102b, 0x50400001, 0x27663000, 0x8f820128,
-0x10c20004, 0x0, 0x8f820124, 0x14c20007,
-0x0, 0x8ee201a4, 0x3821, 0x24420001,
-0xaee201a4, 0x80022c4, 0x8ee201a4, 0x8ee20608,
-0xac62001c, 0x8ee404a0, 0x8ee504a4, 0x2462001c,
-0xac620008, 0x24020008, 0xa462000e, 0x24020011,
-0xac620018, 0xac640000, 0xac650004, 0x8ee204c4,
-0xac620010, 0xaf860120, 0x92e24e20, 0x14400037,
-0x24070001, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x8c830000, 0x24020012, 0x1462001f,
-0x0, 0x8ee34e30, 0x8ee24e34, 0x1062001b,
-0x24030040, 0x8c820004, 0x24420001, 0xac820004,
-0x8ee24e34, 0x8ee54e30, 0x24420001, 0x10430007,
-0x0, 0x8ee24e34, 0x24420001, 0x10a20005,
-0x0, 0x80022ae, 0x0, 0x14a00005,
-0x0, 0x8f820128, 0x24420020, 0xaf820128,
-0x8f820128, 0x8c820004, 0x2c420011, 0x50400013,
-0xac800000, 0x80022c4, 0x0, 0x8ee24e30,
-0x24030040, 0x24420001, 0x50430003, 0x1021,
-0x8ee24e30, 0x24420001, 0xaee24e30, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0x24020012,
-0xac820000, 0x24020001, 0xac820004, 0x14e0001b,
-0x0, 0x3c040001, 0x248453fc, 0xafa00010,
-0xafa00014, 0x8ee60608, 0x8f470228, 0x3c050009,
-0xc002403, 0x34a5f001, 0x8ee201b0, 0x24420001,
-0xaee201b0, 0x80022e0, 0x8ee201b0, 0x3c040001,
-0x24845408, 0xafa00014, 0x8ee60608, 0x8f470228,
-0x3c050009, 0xc002403, 0x34a5f005, 0x8ee201ac,
-0x24420001, 0xaee201ac, 0x8ee201ac, 0x8ee20150,
-0x24420001, 0xaee20150, 0x8ee20150, 0x8ee20160,
-0x24420001, 0xaee20160, 0x8ee20160, 0x8f43022c,
-0x8f42010c, 0x14620009, 0x24020002, 0xaf820064,
-0x8f820064, 0x14400005, 0x0, 0x8f43022c,
-0x8f42010c, 0x1462f875, 0x0, 0x8fbf0044,
-0x8fb60040, 0x8fb5003c, 0x8fb40038, 0x8fb30034,
-0x8fb20030, 0x8fb1002c, 0x8fb00028, 0x3e00008,
-0x27bd0048, 0x27bdfff8, 0x2408ffff, 0x10a00014,
-0x4821, 0x3c0aedb8, 0x354a8320, 0x90870000,
-0x24840001, 0x3021, 0x1071026, 0x30420001,
-0x10400002, 0x81842, 0x6a1826, 0x604021,
-0x24c60001, 0x2cc20008, 0x1440fff7, 0x73842,
-0x25290001, 0x125102b, 0x1440fff0, 0x0,
-0x1001021, 0x3e00008, 0x27bd0008, 0x27bdffe8,
-0x27642800, 0xafbf0010, 0xc002488, 0x24051000,
-0x24020021, 0xaf800100, 0xaf800104, 0xaf800108,
-0xaf800110, 0xaf800114, 0xaf800118, 0xaf800120,
-0xaf800124, 0xaf800128, 0xaf800130, 0xaf800134,
-0xaf800138, 0xaee04e28, 0xaee04e2c, 0xaee04e30,
-0xaee04e34, 0xaf82011c, 0x8f420218, 0x30420040,
-0x10400004, 0x0, 0x8f82011c, 0x34420004,
-0xaf82011c, 0x8fbf0010, 0x3e00008, 0x27bd0018,
-0x27bdffe0, 0xafbf0018, 0x8f820104, 0xafa20010,
-0x8f820100, 0x3c050002, 0xafa20014, 0x8f8600b0,
-0x8f87011c, 0x3c040001, 0x248454c0, 0xc002403,
-0x34a5f000, 0x8f8300b0, 0x3c027f00, 0x621824,
-0x3c020400, 0x10620029, 0x43102b, 0x14400008,
-0x3c022000, 0x3c020100, 0x10620024, 0x3c020200,
-0x10620011, 0x0, 0x8002374, 0x0,
-0x10620008, 0x3c024000, 0x1462001c, 0x0,
-0x8ee20190, 0x24420001, 0xaee20190, 0x8002374,
-0x8ee20190, 0x8ee2018c, 0x24420001, 0xaee2018c,
-0x8002374, 0x8ee2018c, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f830104, 0x8f8200b0, 0x34420001,
-0xaf8200b0, 0xaf830104, 0x8f82011c, 0x2403fffd,
-0x431024, 0xaf82011c, 0x8ee201a0, 0x24420001,
-0xaee201a0, 0x8002377, 0x8ee201a0, 0x8f8200b0,
-0x34420001, 0xaf8200b0, 0x8fbf0018, 0x3e00008,
-0x27bd0020, 0x27bdffe0, 0xafbf001c, 0xafb00018,
-0x8f820120, 0xafa20010, 0x8f820124, 0x3c050001,
-0xafa20014, 0x8f8600a0, 0x8f87011c, 0x3c040001,
-0x248454cc, 0xc002403, 0x34a5f000, 0x8f8300a0,
-0x3c027f00, 0x621824, 0x3c020400, 0x10620053,
-0x8021, 0x43102b, 0x14400008, 0x3c042000,
-0x3c020100, 0x1062004d, 0x3c020200, 0x1062003a,
-0x0, 0x80023e0, 0x0, 0x10640003,
-0x3c024000, 0x14620045, 0x0, 0x8f8200a0,
-0x441024, 0x10400006, 0x0, 0x8ee20194,
-0x24420001, 0xaee20194, 0x80023a9, 0x8ee20194,
-0x8ee20198, 0x24420001, 0xaee20198, 0x8ee20198,
-0x8f82011c, 0x34420002, 0xaf82011c, 0x8f82011c,
-0x30420200, 0x1040001b, 0x0, 0x8f8300a0,
-0x8f840124, 0x8f8200ac, 0x14400007, 0x24020001,
-0x3c020001, 0x3442f000, 0x621024, 0x50400001,
-0x24100001, 0x24020001, 0x1200000d, 0xaf8200a0,
-0x8f820124, 0x2442ffe0, 0xaf820124, 0x8f820124,
-0x8f820124, 0x27633000, 0x43102b, 0x10400005,
-0x276237e0, 0xaf820124, 0x80023ca, 0x0,
-0xaf840124, 0x8f82011c, 0x2403fffd, 0x431024,
-0x80023e3, 0xaf82011c, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f830124, 0x8f8200a0, 0x34420001,
-0xaf8200a0, 0xaf830124, 0x8f82011c, 0x2403fffd,
-0x431024, 0xaf82011c, 0x8ee2019c, 0x24420001,
-0xaee2019c, 0x80023e3, 0x8ee2019c, 0x8f8200a0,
-0x34420001, 0xaf8200a0, 0x8fbf001c, 0x8fb00018,
-0x3e00008, 0x27bd0020, 0x0, 0x3c020001,
-0x8c425c58, 0x27bdffe8, 0xafbf0014, 0x14400012,
-0xafb00010, 0x3c100001, 0x26105dd0, 0x2002021,
-0xc002488, 0x24052000, 0x26021fe0, 0x3c010001,
-0xac225d94, 0x3c010001, 0xac225d90, 0xaf420250,
-0x24022000, 0xaf500254, 0xaf420258, 0x24020001,
-0x3c010001, 0xac225c58, 0x8fbf0014, 0x8fb00010,
-0x3e00008, 0x27bd0018, 0x3c030001, 0x8c635d94,
-0x8c820000, 0x8fa80010, 0x8fa90014, 0xac620000,
-0x3c020001, 0x8c425d94, 0x8c830004, 0xac430004,
-0xac450008, 0x8f840054, 0x2443ffe0, 0xac460010,
-0xac470014, 0xac480018, 0xac49001c, 0x3c010001,
-0xac235d94, 0xac44000c, 0x3c020001, 0x24425dd0,
-0x62182b, 0x10600005, 0x0, 0x3c020001,
-0x8c425d90, 0x3c010001, 0xac225d94, 0x3c030001,
-0x8c635d94, 0x3c020001, 0x8c425c40, 0xac620000,
-0x3c030001, 0x8c635d94, 0x3c020001, 0x8c425c40,
-0xac620004, 0x3e00008, 0xaf430250, 0x3c030001,
-0x8c635d94, 0x3c020001, 0x8c425c40, 0x27bdffd0,
-0xafb40020, 0x8fb40040, 0xafb00010, 0x808021,
-0xafb50024, 0x8fb50044, 0x8fa40048, 0xafb10014,
-0xa08821, 0xafbf0028, 0xafb3001c, 0xafb20018,
-0xac620000, 0x3c050001, 0x8ca55d94, 0x3c020001,
-0x8c425c40, 0xc09021, 0xe09821, 0x10800006,
-0xaca20004, 0x24a50008, 0xc002490, 0x24060018,
-0x800244e, 0x0, 0x24a40008, 0xc002488,
-0x24050018, 0x3c020001, 0x8c425d94, 0x3c050001,
-0x24a55dd0, 0x2442ffe0, 0x3c010001, 0xac225d94,
-0x45102b, 0x10400005, 0x0, 0x3c020001,
-0x8c425d90, 0x3c010001, 0xac225d94, 0x3c030001,
-0x8c635d94, 0x8e020000, 0xac620000, 0x3c030001,
-0x8c635d94, 0x8e020004, 0xac620004, 0xac710008,
-0x8f840054, 0x2462ffe0, 0x3c010001, 0xac225d94,
-0x45102b, 0xac720010, 0xac730014, 0xac740018,
-0xac75001c, 0x10400005, 0xac64000c, 0x3c020001,
-0x8c425d90, 0x3c010001, 0xac225d94, 0x3c030001,
-0x8c635d94, 0x3c020001, 0x8c425c40, 0xac620000,
-0x3c030001, 0x8c635d94, 0x3c020001, 0x8c425c40,
-0xac620004, 0xaf430250, 0x8fbf0028, 0x8fb50024,
-0x8fb40020, 0x8fb3001c, 0x8fb20018, 0x8fb10014,
-0x8fb00010, 0x3e00008, 0x27bd0030, 0x10a00005,
-0x0, 0xac800000, 0x24a5fffc, 0x14a0fffd,
-0x24840004, 0x3e00008, 0x0, 0x10c00007,
-0x0, 0x8c820000, 0x24840004, 0x24c6fffc,
-0xaca20000, 0x14c0fffb, 0x24a50004, 0x3e00008,
-0x0, 0x10c00007, 0x0, 0x8ca20000,
-0x24a50004, 0x24c6fffc, 0xac820000, 0x14c0fffb,
-0x24840004, 0x3e00008, 0x0, 0x3e00008,
-0x0, 0x27bdffd8, 0xafbf0020, 0x8ee304e4,
-0x8ee204e0, 0x10620436, 0x0, 0x8ee204e4,
-0x8ee304fc, 0x21100, 0x626021, 0x95870008,
-0x8d8a0000, 0x8d8b0004, 0x958d000a, 0x8ee2725c,
-0x8ee3726c, 0x30e4ffff, 0x441021, 0x62182b,
-0x10600015, 0x31a20004, 0x8f8200d8, 0x8ee37258,
-0x431023, 0xaee2726c, 0x8ee2726c, 0x1c400003,
-0x3c030001, 0x431021, 0xaee2726c, 0x8ee2725c,
-0x8ee3726c, 0x441021, 0x62182b, 0x10600006,
-0x31a20004, 0x8ee201b8, 0x24420001, 0xaee201b8,
-0x80028e1, 0x8ee201b8, 0x10400240, 0x31a20200,
-0x1040014d, 0x4821, 0x96e2045a, 0x30420010,
-0x10400149, 0x0, 0x8f840100, 0x27623000,
-0x24850020, 0xa2102b, 0x50400001, 0x27652800,
-0x8f820108, 0x10a20004, 0x0, 0x8f820104,
-0x14a20006, 0x2402000c, 0x8ee201a8, 0x24420001,
-0xaee201a8, 0x800252c, 0x8ee201a8, 0xac8a0000,
-0xac8b0004, 0x8ee37264, 0x24060005, 0xa482000e,
-0xac860018, 0xac830008, 0x8ee204e4, 0xac82001c,
-0x8ee204c8, 0xac820010, 0xaf850100, 0x92e204ec,
-0x14400036, 0x24090001, 0x8ee24e28, 0x210c0,
-0x24424e38, 0x2e22021, 0x8c820000, 0x1446001f,
-0x0, 0x8ee34e28, 0x8ee24e2c, 0x1062001b,
-0x24030040, 0x8c820004, 0x24420001, 0xac820004,
-0x8ee24e2c, 0x8ee54e28, 0x24420001, 0x10430007,
-0x0, 0x8ee24e2c, 0x24420001, 0x10a20005,
-0x0, 0x8002516, 0x0, 0x14a00005,
-0x0, 0x8f820108, 0x24420020, 0xaf820108,
-0x8f820108, 0x8c820004, 0x2c420011, 0x50400013,
-0xac800000, 0x800252c, 0x0, 0x8ee24e28,
-0x24030040, 0x24420001, 0x50430003, 0x1021,
-0x8ee24e28, 0x24420001, 0xaee24e28, 0x8ee24e28,
-0x210c0, 0x24424e38, 0x2e22021, 0x24020005,
-0xac820000, 0x24020001, 0xac820004, 0x1520000a,
-0x3c040001, 0xafab0010, 0x8ee27264, 0x3c040001,
-0x24845730, 0x3c050004, 0xafa20014, 0x8ee604e4,
-0x80028be, 0x34a5f114, 0x8ee27264, 0x34843800,
-0x3641821, 0x24420010, 0x43102b, 0x14400073,
-0x0, 0x8ee27264, 0x24480010, 0x3641021,
-0x102102b, 0x14400002, 0x3c02ffff, 0x1024021,
-0x8f850100, 0x27623000, 0x24a60020, 0xc2102b,
-0x50400001, 0x27662800, 0x8f820108, 0x10c20004,
-0x0, 0x8f820104, 0x14c20007, 0x2563000c,
-0x8ee201a8, 0x4821, 0x24420001, 0xaee201a8,
-0x80025a0, 0x8ee201a8, 0x2c64000c, 0x1441021,
-0xaca20000, 0xaca30004, 0x24e2fff4, 0xa4a2000e,
-0x24020006, 0xaca80008, 0xaca20018, 0x8ee204e4,
-0xaca2001c, 0x8ee204c8, 0x3c030002, 0x431025,
-0xaca20010, 0xaf860100, 0x92e204ec, 0x14400037,
-0x24090001, 0x8ee24e28, 0x210c0, 0x24424e38,
-0x2e22021, 0x8c830000, 0x24020005, 0x1462001f,
-0x0, 0x8ee34e28, 0x8ee24e2c, 0x1062001b,
-0x24030040, 0x8c820004, 0x24420001, 0xac820004,
-0x8ee24e2c, 0x8ee54e28, 0x24420001, 0x10430007,
-0x0, 0x8ee24e2c, 0x24420001, 0x10a20005,
-0x0, 0x800258a, 0x0, 0x14a00005,
-0x0, 0x8f820108, 0x24420020, 0xaf820108,
-0x8f820108, 0x8c820004, 0x2c420011, 0x50400013,
-0xac800000, 0x80025a0, 0x0, 0x8ee24e28,
-0x24030040, 0x24420001, 0x50430003, 0x1021,
-0x8ee24e28, 0x24420001, 0xaee24e28, 0x8ee24e28,
-0x210c0, 0x24424e38, 0x2e22021, 0x24020005,
-0xac820000, 0x24020001, 0xac820004, 0x1520000a,
-0x2508fffc, 0xafab0010, 0x8ee27264, 0x3c040001,
-0x24845730, 0x3c050004, 0xafa20014, 0x8ee604e4,
-0x80028be, 0x34a5f125, 0x34028100, 0xa5020000,
-0x9582000e, 0x800261d, 0xa5020002, 0x8f850100,
-0x27623000, 0x24a60020, 0xc2102b, 0x50400001,
-0x27662800, 0x8f820108, 0x10c20004, 0x0,
-0x8f820104, 0x14c20007, 0x2563000c, 0x8ee201a8,
-0x4821, 0x24420001, 0xaee201a8, 0x800260d,
-0x8ee201a8, 0x2c64000c, 0x1441021, 0xaca20000,
-0xaca30004, 0x8ee37264, 0x24e2fff4, 0xa4a2000e,
-0x24020006, 0xaca20018, 0x24630010, 0xaca30008,
-0x8ee204e4, 0xaca2001c, 0x8ee204c8, 0x3c030002,
-0x431025, 0xaca20010, 0xaf860100, 0x92e204ec,
-0x14400037, 0x24090001, 0x8ee24e28, 0x210c0,
-0x24424e38, 0x2e22021, 0x8c830000, 0x24020005,
-0x1462001f, 0x0, 0x8ee34e28, 0x8ee24e2c,
-0x1062001b, 0x24030040, 0x8c820004, 0x24420001,
-0xac820004, 0x8ee24e2c, 0x8ee54e28, 0x24420001,
-0x10430007, 0x0, 0x8ee24e2c, 0x24420001,
-0x10a20005, 0x0, 0x80025f7, 0x0,
-0x14a00005, 0x0, 0x8f820108, 0x24420020,
-0xaf820108, 0x8f820108, 0x8c820004, 0x2c420011,
-0x50400013, 0xac800000, 0x800260d, 0x0,
-0x8ee24e28, 0x24030040, 0x24420001, 0x50430003,
-0x1021, 0x8ee24e28, 0x24420001, 0xaee24e28,
-0x8ee24e28, 0x210c0, 0x24424e38, 0x2e22021,
-0x24020005, 0xac820000, 0x24020001, 0xac820004,
-0x1520000a, 0x34028100, 0xafab0010, 0x8ee27264,
-0x3c040001, 0x24845730, 0x3c050004, 0xafa20014,
-0x8ee604e4, 0x80028be, 0x34a5f015, 0x8ee37264,
-0xa462000c, 0x8ee37264, 0x9582000e, 0xa462000e,
-0x8002681, 0x24e70004, 0x8f840100, 0x27623000,
-0x24850020, 0xa2102b, 0x50400001, 0x27652800,
-0x8f820108, 0x10a20004, 0x0, 0x8f820104,
-0x14a20007, 0x24020006, 0x8ee201a8, 0x4821,
-0x24420001, 0xaee201a8, 0x8002677, 0x8ee201a8,
-0xac8a0000, 0xac8b0004, 0x8ee37264, 0xa487000e,
-0xac820018, 0xac830008, 0x8ee204e4, 0xac82001c,
-0x8ee204c8, 0x3c030002, 0x431025, 0xac820010,
-0xaf850100, 0x92e204ec, 0x14400037, 0x24090001,
-0x8ee24e28, 0x210c0, 0x24424e38, 0x2e22021,
-0x8c830000, 0x24020005, 0x1462001f, 0x0,
-0x8ee34e28, 0x8ee24e2c, 0x1062001b, 0x24030040,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e2c,
-0x8ee54e28, 0x24420001, 0x10430007, 0x0,
-0x8ee24e2c, 0x24420001, 0x10a20005, 0x0,
-0x8002661, 0x0, 0x14a00005, 0x0,
-0x8f820108, 0x24420020, 0xaf820108, 0x8f820108,
-0x8c820004, 0x2c420011, 0x50400013, 0xac800000,
-0x8002677, 0x0, 0x8ee24e28, 0x24030040,
-0x24420001, 0x50430003, 0x1021, 0x8ee24e28,
-0x24420001, 0xaee24e28, 0x8ee24e28, 0x210c0,
-0x24424e38, 0x2e22021, 0x24020005, 0xac820000,
-0x24020001, 0xac820004, 0x15200009, 0x3c050004,
-0xafab0010, 0x8ee27264, 0x3c040001, 0x24845730,
-0xafa20014, 0x8ee604e4, 0x80028be, 0x34a5f004,
-0x8ee2725c, 0x30e7ffff, 0x471021, 0xaee2725c,
-0x8ee204e4, 0x8ee304fc, 0x8ee47258, 0x21100,
-0x431021, 0xac44000c, 0x8ee27258, 0xafa20018,
-0x8ee3725c, 0xafa3001c, 0x8ee2725c, 0x2c42003c,
-0x10400004, 0x24620001, 0x2403fffe, 0x431024,
-0xafa2001c, 0x8ee27264, 0x3c060001, 0x34c63800,
-0x8ee3725c, 0x2405fff8, 0x471021, 0x24420007,
-0x451024, 0x24630007, 0xaee27258, 0x8ee2726c,
-0x8ee47258, 0x651824, 0x431023, 0xaee2726c,
-0x3661021, 0x82202b, 0x14800004, 0x3c03ffff,
-0x8ee27258, 0x431021, 0xaee27258, 0x8ee27258,
-0xaee27264, 0x8f8200f0, 0x24470008, 0x27621800,
-0xe2102b, 0x50400001, 0x27671000, 0x8f8200f4,
-0x14e20007, 0x0, 0x8ee201b4, 0x4821,
-0x24420001, 0xaee201b4, 0x80026c4, 0x8ee201b4,
-0x8f8200f0, 0x24090001, 0x8fa30018, 0x8fa4001c,
-0xac430000, 0xac440004, 0xaf8700f0, 0x15200012,
-0xd1142, 0x8f8200f0, 0xafa20010, 0x8f8200f4,
-0x3c040001, 0x2484573c, 0xafa20014, 0x8fa60018,
-0x8fa7001c, 0x3c050004, 0xc002403, 0x34a5f005,
-0x8ee20088, 0x24420001, 0xaee20088, 0x8ee20088,
-0x80028d3, 0xaee0725c, 0x30430003, 0x24020002,
-0x10620016, 0x28620003, 0x10400005, 0x24020001,
-0x10620008, 0x0, 0x8002703, 0x0,
-0x24020003, 0x10620017, 0x0, 0x8002703,
-0x0, 0x8ee200e8, 0x8ee300ec, 0x24630001,
-0x2c640001, 0x441021, 0xaee200e8, 0xaee300ec,
-0x8ee200e8, 0x8002703, 0x8ee300ec, 0x8ee200f0,
-0x8ee300f4, 0x24630001, 0x2c640001, 0x441021,
-0xaee200f0, 0xaee300f4, 0x8ee200f0, 0x8002703,
-0x8ee300f4, 0x8ee200f8, 0x8ee300fc, 0x24630001,
-0x2c640001, 0x441021, 0xaee200f8, 0xaee300fc,
-0x8ee200f8, 0x8ee300fc, 0x8ee2725c, 0x8ee400e0,
-0x8ee500e4, 0x401821, 0x1021, 0xa32821,
-0xa3302b, 0x822021, 0x862021, 0xaee400e0,
-0xaee500e4, 0x80028d3, 0xaee0725c, 0x30e2ffff,
-0x104001c1, 0x31a20200, 0x1040014d, 0x4821,
-0x96e2045a, 0x30420010, 0x10400149, 0x0,
-0x8f840100, 0x27623000, 0x24850020, 0xa2102b,
-0x50400001, 0x27652800, 0x8f820108, 0x10a20004,
-0x0, 0x8f820104, 0x14a20006, 0x2402000c,
-0x8ee201a8, 0x24420001, 0xaee201a8, 0x800276e,
-0x8ee201a8, 0xac8a0000, 0xac8b0004, 0x8ee37264,
-0x24060005, 0xa482000e, 0xac860018, 0xac830008,
-0x8ee204e4, 0xac82001c, 0x8ee204c8, 0xac820010,
-0xaf850100, 0x92e204ec, 0x14400036, 0x24090001,
-0x8ee24e28, 0x210c0, 0x24424e38, 0x2e22021,
-0x8c820000, 0x1446001f, 0x0, 0x8ee34e28,
-0x8ee24e2c, 0x1062001b, 0x24030040, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e2c, 0x8ee54e28,
-0x24420001, 0x10430007, 0x0, 0x8ee24e2c,
-0x24420001, 0x10a20005, 0x0, 0x8002758,
-0x0, 0x14a00005, 0x0, 0x8f820108,
-0x24420020, 0xaf820108, 0x8f820108, 0x8c820004,
-0x2c420011, 0x50400013, 0xac800000, 0x800276e,
-0x0, 0x8ee24e28, 0x24030040, 0x24420001,
-0x50430003, 0x1021, 0x8ee24e28, 0x24420001,
-0xaee24e28, 0x8ee24e28, 0x210c0, 0x24424e38,
-0x2e22021, 0x24020005, 0xac820000, 0x24020001,
-0xac820004, 0x1520000a, 0x3c040001, 0xafab0010,
-0x8ee27264, 0x3c040001, 0x24845730, 0x3c050004,
-0xafa20014, 0x8ee604e4, 0x80028be, 0x34a5f014,
-0x8ee27264, 0x34843800, 0x3641821, 0x24420010,
-0x43102b, 0x14400073, 0x0, 0x8ee27264,
-0x24480010, 0x3641021, 0x102102b, 0x14400002,
-0x3c02ffff, 0x1024021, 0x8f850100, 0x27623000,
-0x24a60020, 0xc2102b, 0x50400001, 0x27662800,
-0x8f820108, 0x10c20004, 0x0, 0x8f820104,
-0x14c20007, 0x2563000c, 0x8ee201a8, 0x4821,
-0x24420001, 0xaee201a8, 0x80027e2, 0x8ee201a8,
-0x2c64000c, 0x1441021, 0xaca20000, 0xaca30004,
-0x24e2fff4, 0xa4a2000e, 0x24020006, 0xaca80008,
-0xaca20018, 0x8ee204e4, 0xaca2001c, 0x8ee204c8,
-0x3c030002, 0x431025, 0xaca20010, 0xaf860100,
-0x92e204ec, 0x14400037, 0x24090001, 0x8ee24e28,
-0x210c0, 0x24424e38, 0x2e22021, 0x8c830000,
-0x24020005, 0x1462001f, 0x0, 0x8ee34e28,
-0x8ee24e2c, 0x1062001b, 0x24030040, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e2c, 0x8ee54e28,
-0x24420001, 0x10430007, 0x0, 0x8ee24e2c,
-0x24420001, 0x10a20005, 0x0, 0x80027cc,
-0x0, 0x14a00005, 0x0, 0x8f820108,
-0x24420020, 0xaf820108, 0x8f820108, 0x8c820004,
-0x2c420011, 0x50400013, 0xac800000, 0x80027e2,
-0x0, 0x8ee24e28, 0x24030040, 0x24420001,
-0x50430003, 0x1021, 0x8ee24e28, 0x24420001,
-0xaee24e28, 0x8ee24e28, 0x210c0, 0x24424e38,
-0x2e22021, 0x24020005, 0xac820000, 0x24020001,
-0xac820004, 0x1520000a, 0x2508fffc, 0xafab0010,
-0x8ee27264, 0x3c040001, 0x24845730, 0x3c050004,
-0xafa20014, 0x8ee604e4, 0x80028be, 0x34a5f015,
-0x34028100, 0xa5020000, 0x9582000e, 0x800285f,
-0xa5020002, 0x8f850100, 0x27623000, 0x24a60020,
-0xc2102b, 0x50400001, 0x27662800, 0x8f820108,
-0x10c20004, 0x0, 0x8f820104, 0x14c20007,
-0x2563000c, 0x8ee201a8, 0x4821, 0x24420001,
-0xaee201a8, 0x800284f, 0x8ee201a8, 0x2c64000c,
-0x1441021, 0xaca20000, 0xaca30004, 0x8ee37264,
-0x24e2fff4, 0xa4a2000e, 0x24020006, 0xaca20018,
-0x24630010, 0xaca30008, 0x8ee204e4, 0xaca2001c,
-0x8ee204c8, 0x3c030002, 0x431025, 0xaca20010,
-0xaf860100, 0x92e204ec, 0x14400037, 0x24090001,
-0x8ee24e28, 0x210c0, 0x24424e38, 0x2e22021,
-0x8c830000, 0x24020005, 0x1462001f, 0x0,
-0x8ee34e28, 0x8ee24e2c, 0x1062001b, 0x24030040,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e2c,
-0x8ee54e28, 0x24420001, 0x10430007, 0x0,
-0x8ee24e2c, 0x24420001, 0x10a20005, 0x0,
-0x8002839, 0x0, 0x14a00005, 0x0,
-0x8f820108, 0x24420020, 0xaf820108, 0x8f820108,
-0x8c820004, 0x2c420011, 0x50400013, 0xac800000,
-0x800284f, 0x0, 0x8ee24e28, 0x24030040,
-0x24420001, 0x50430003, 0x1021, 0x8ee24e28,
-0x24420001, 0xaee24e28, 0x8ee24e28, 0x210c0,
-0x24424e38, 0x2e22021, 0x24020005, 0xac820000,
-0x24020001, 0xac820004, 0x1520000a, 0x34028100,
-0xafab0010, 0x8ee27264, 0x3c040001, 0x24845730,
-0x3c050004, 0xafa20014, 0x8ee604e4, 0x80028be,
-0x34a5f016, 0x8ee37264, 0xa462000c, 0x8ee37264,
-0x9582000e, 0xa462000e, 0x80028c2, 0x24e70004,
-0x8f830100, 0x27623000, 0x24640020, 0x82102b,
-0x50400001, 0x27642800, 0x8f820108, 0x10820004,
-0x0, 0x8f820104, 0x14820007, 0x24050005,
-0x8ee201a8, 0x4821, 0x24420001, 0xaee201a8,
-0x80028b6, 0x8ee201a8, 0xac6a0000, 0xac6b0004,
-0x8ee27264, 0xa467000e, 0xac650018, 0xac620008,
-0x8ee204e4, 0xac62001c, 0x8ee204c8, 0xac620010,
-0xaf840100, 0x92e204ec, 0x14400036, 0x24090001,
-0x8ee24e28, 0x210c0, 0x24424e38, 0x2e22021,
-0x8c820000, 0x1445001f, 0x0, 0x8ee34e28,
-0x8ee24e2c, 0x1062001b, 0x24030040, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e2c, 0x8ee54e28,
-0x24420001, 0x10430007, 0x0, 0x8ee24e2c,
-0x24420001, 0x10a20005, 0x0, 0x80028a0,
-0x0, 0x14a00005, 0x0, 0x8f820108,
-0x24420020, 0xaf820108, 0x8f820108, 0x8c820004,
-0x2c420011, 0x50400013, 0xac800000, 0x80028b6,
-0x0, 0x8ee24e28, 0x24030040, 0x24420001,
-0x50430003, 0x1021, 0x8ee24e28, 0x24420001,
-0xaee24e28, 0x8ee24e28, 0x210c0, 0x24424e38,
-0x2e22021, 0x24020005, 0xac820000, 0x24020001,
-0xac820004, 0x1520000b, 0x3c050004, 0x3c040001,
-0x24845748, 0xafab0010, 0xafa00014, 0x8ee604e4,
-0x34a5f017, 0xc002403, 0x30e7ffff, 0x80028e1,
-0x0, 0x8ee27264, 0x3c050001, 0x30e4ffff,
-0x441021, 0xaee27264, 0x8ee2725c, 0x8ee37264,
-0x34a53800, 0x441021, 0xaee2725c, 0x3651021,
-0x62182b, 0x14600004, 0x3c03ffff, 0x8ee27264,
-0x431021, 0xaee27264, 0x8ee304e4, 0x96e20458,
-0x24630001, 0x2442ffff, 0x621824, 0xaee304e4,
-0x8ee304e4, 0x8ee204e0, 0x14620005, 0x0,
-0x8f820060, 0x2403fff7, 0x431024, 0xaf820060,
-0x8fbf0020, 0x3e00008, 0x27bd0028, 0x27bdffe0,
-0xafbf0018, 0x8ee304e8, 0x8ee204e0, 0x10620189,
-0x0, 0x8ee204e8, 0x8ee304fc, 0x21100,
-0x621821, 0x94670008, 0x92e204ed, 0x8c680000,
-0x8c690004, 0x10400023, 0x946a000a, 0x8ee204c8,
-0x34460400, 0x31420200, 0x1040001f, 0x0,
-0x96e2045a, 0x30420010, 0x1040001b, 0x3c028000,
-0x3c010001, 0x370821, 0xac2283d8, 0x8ee27264,
-0x9464000e, 0x3c050001, 0x34a53800, 0x24420004,
-0xaee27264, 0x8ee37264, 0x42400, 0x3651021,
-0x3c010001, 0x370821, 0xac2483dc, 0x62182b,
-0x14600005, 0x24e70004, 0x8ee27264, 0x3c03ffff,
-0x431021, 0xaee27264, 0x8ee27264, 0x8002917,
-0xaee27258, 0x8ee604c8, 0x8ee2726c, 0x30e4ffff,
-0x44102a, 0x10400015, 0x0, 0x8f8200d8,
-0x8ee37258, 0x431023, 0xaee2726c, 0x8ee2726c,
-0x1c400007, 0x44102a, 0x8ee2726c, 0x3c030001,
-0x431021, 0xaee2726c, 0x8ee2726c, 0x44102a,
-0x10400006, 0x0, 0x8ee201b8, 0x24420001,
-0xaee201b8, 0x8002a72, 0x8ee201b8, 0x3c020001,
-0x571021, 0x8c4283d8, 0x54400001, 0x24e7fffc,
-0x31420004, 0x104000b9, 0x30e2ffff, 0x3c020001,
-0x571021, 0x8c4283d8, 0x1040002f, 0x5021,
-0x8f840100, 0x27623000, 0x24850020, 0xa2102b,
-0x50400001, 0x27652800, 0x8f820108, 0x10a20032,
-0x0, 0x8f820104, 0x10a2002f, 0x24020015,
-0xac880000, 0xac890004, 0x8ee37264, 0xa487000e,
-0xac820018, 0xac830008, 0x8ee204e8, 0x3c030001,
-0x771821, 0x8c6383dc, 0xac860010, 0x431025,
-0xac82001c, 0xaf850100, 0x92e204ec, 0x14400066,
-0x240a0001, 0x8ee24e28, 0x24030040, 0x24420001,
-0x50430003, 0x1021, 0x8ee24e28, 0x24420001,
-0xaee24e28, 0x8ee24e28, 0x210c0, 0x24424e38,
-0x2e21821, 0x24020015, 0xac620000, 0x24020001,
-0x80029bf, 0xac620004, 0x8f840100, 0x27623000,
-0x24850020, 0xa2102b, 0x50400001, 0x27652800,
-0x8f820108, 0x10a20004, 0x0, 0x8f820104,
-0x14a20006, 0x24020006, 0x8ee201a8, 0x24420001,
-0xaee201a8, 0x80029bf, 0x8ee201a8, 0xac880000,
-0xac890004, 0x8ee37264, 0xa487000e, 0xac820018,
-0xac830008, 0x8ee204e8, 0xac860010, 0xac82001c,
-0xaf850100, 0x92e204ec, 0x14400037, 0x240a0001,
-0x8ee24e28, 0x210c0, 0x24424e38, 0x2e22021,
-0x8c830000, 0x24020005, 0x1462001f, 0x0,
-0x8ee34e28, 0x8ee24e2c, 0x1062001b, 0x24030040,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e2c,
-0x8ee54e28, 0x24420001, 0x10430007, 0x0,
-0x8ee24e2c, 0x24420001, 0x10a20005, 0x0,
-0x80029a9, 0x0, 0x14a00005, 0x0,
-0x8f820108, 0x24420020, 0xaf820108, 0x8f820108,
-0x8c820004, 0x2c420011, 0x50400013, 0xac800000,
-0x80029bf, 0x0, 0x8ee24e28, 0x24030040,
-0x24420001, 0x50430003, 0x1021, 0x8ee24e28,
-0x24420001, 0xaee24e28, 0x8ee24e28, 0x210c0,
-0x24424e38, 0x2e22021, 0x24020005, 0xac820000,
-0x24020001, 0xac820004, 0x1540000a, 0x24020001,
-0xafa90010, 0x8ee27264, 0x3c040001, 0x24845730,
-0x3c050004, 0xafa20014, 0x8ee604e4, 0x8002a4f,
-0x34a5f204, 0xa2e204ed, 0x8ee204e8, 0x8ee304fc,
-0x8ee47258, 0x3c060001, 0x34c63800, 0x3c010001,
-0x370821, 0xac2083d8, 0x3c010001, 0x370821,
-0xac2083dc, 0x21100, 0x431021, 0xac44000c,
-0x8ee27264, 0x2405fff8, 0x30e3ffff, 0x431021,
-0x24420007, 0x451024, 0x24630007, 0xaee27258,
-0x8ee2726c, 0x8ee47258, 0x651824, 0x431023,
-0xaee2726c, 0x3661021, 0x82202b, 0x14800004,
-0x3c03ffff, 0x8ee27258, 0x431021, 0xaee27258,
-0x8ee27258, 0x8002a64, 0xaee27264, 0x10400073,
-0x0, 0x8f830100, 0x27623000, 0x24640020,
-0x82102b, 0x14400002, 0x5021, 0x27642800,
-0x8f820108, 0x10820004, 0x0, 0x8f820104,
-0x14820006, 0x24050005, 0x8ee201a8, 0x24420001,
-0xaee201a8, 0x8002a46, 0x8ee201a8, 0xac680000,
-0xac690004, 0x8ee27264, 0xa467000e, 0xac650018,
-0xac620008, 0x8ee204e8, 0xac660010, 0xac62001c,
-0xaf840100, 0x92e204ec, 0x14400036, 0x240a0001,
-0x8ee24e28, 0x210c0, 0x24424e38, 0x2e22021,
-0x8c820000, 0x1445001f, 0x0, 0x8ee34e28,
-0x8ee24e2c, 0x1062001b, 0x24030040, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e2c, 0x8ee54e28,
-0x24420001, 0x10430007, 0x0, 0x8ee24e2c,
-0x24420001, 0x10a20005, 0x0, 0x8002a30,
-0x0, 0x14a00005, 0x0, 0x8f820108,
-0x24420020, 0xaf820108, 0x8f820108, 0x8c820004,
-0x2c420011, 0x50400013, 0xac800000, 0x8002a46,
-0x0, 0x8ee24e28, 0x24030040, 0x24420001,
-0x50430003, 0x1021, 0x8ee24e28, 0x24420001,
-0xaee24e28, 0x8ee24e28, 0x210c0, 0x24424e38,
-0x2e22021, 0x24020005, 0xac820000, 0x24020001,
-0xac820004, 0x1540000c, 0x30e5ffff, 0x3c040001,
-0x24845748, 0x3c050004, 0xafa90010, 0xafa00014,
-0x8ee604e4, 0x34a5f237, 0xc002403, 0x30e7ffff,
-0x8002a72, 0x0, 0x8ee27264, 0x451021,
-0xaee27264, 0x8ee2726c, 0x8ee37264, 0x3c040001,
-0x34843800, 0xa2e004ed, 0x451023, 0xaee2726c,
-0x3641021, 0x62182b, 0x14600004, 0x3c03ffff,
-0x8ee27264, 0x431021, 0xaee27264, 0x8ee304e8,
-0x96e20458, 0x24630001, 0x2442ffff, 0x621824,
-0xaee304e8, 0x8ee304e8, 0x8ee204e0, 0x14620005,
-0x0, 0x8f820060, 0x2403fff7, 0x431024,
-0xaf820060, 0x8fbf0018, 0x3e00008, 0x27bd0020,
-0x27bdffe0, 0xafbf001c, 0xafb00018, 0x8f820100,
-0x8ee34e2c, 0x8f820104, 0x8f850108, 0x24020040,
-0x24630001, 0x50620003, 0x1021, 0x8ee24e2c,
-0x24420001, 0xaee24e2c, 0x8ee24e2c, 0x8ee34e2c,
-0x210c0, 0x24424e38, 0x2e22021, 0x8ee24e28,
-0x8c870004, 0x14620007, 0xa03021, 0x8f820108,
-0x24420020, 0xaf820108, 0x8f820108, 0x8002aa2,
-0xac800000, 0x8ee24e2c, 0x24030040, 0x24420001,
-0x50430003, 0x1021, 0x8ee24e2c, 0x24420001,
-0x210c0, 0x24424e38, 0x2e22021, 0x8c820004,
-0x8f830108, 0x21140, 0x621821, 0xaf830108,
-0xac800000, 0x8cc20018, 0x2443fffe, 0x2c620013,
-0x104000c1, 0x31080, 0x3c010001, 0x220821,
-0x8c225770, 0x400008, 0x0, 0x8ee204f0,
-0x471021, 0xaee204f0, 0x8ee204f0, 0x8f43023c,
-0x43102b, 0x144000be, 0x0, 0x8ee304e4,
-0x8ee204f8, 0x506200ba, 0xa2e004f4, 0x8f830120,
-0x27623800, 0x24660020, 0xc2102b, 0x50400001,
-0x27663000, 0x8f820128, 0x10c20004, 0x0,
-0x8f820124, 0x14c20007, 0x0, 0x8ee201a4,
-0x8021, 0x24420001, 0xaee201a4, 0x8002b12,
-0x8ee201a4, 0x8ee204e4, 0xac62001c, 0x8ee404b0,
-0x8ee504b4, 0x2462001c, 0xac620008, 0x24020008,
-0xa462000e, 0x24020011, 0xac620018, 0xac640000,
-0xac650004, 0x8ee204c4, 0xac620010, 0xaf860120,
-0x92e24e20, 0x14400037, 0x24100001, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0x8c830000,
-0x24020012, 0x1462001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x24030040, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee54e30,
-0x24420001, 0x10430007, 0x0, 0x8ee24e34,
-0x24420001, 0x10a20005, 0x0, 0x8002afc,
-0x0, 0x14a00005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400013, 0xac800000, 0x8002b12,
-0x0, 0x8ee24e30, 0x24030040, 0x24420001,
-0x50430003, 0x1021, 0x8ee24e30, 0x24420001,
-0xaee24e30, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x24020012, 0xac820000, 0x24020001,
-0xac820004, 0x5600000b, 0x24100001, 0x8ee204e4,
-0x3c040001, 0x24845754, 0xafa00014, 0xafa20010,
-0x8ee60608, 0x8f470228, 0x3c050009, 0xc002403,
-0x34a5f006, 0x16000003, 0x24020001, 0x8002b71,
-0xa2e204f4, 0x8ee20170, 0x24420001, 0xaee20170,
-0x8ee20170, 0x8ee204e4, 0xa2e004f4, 0xaee004f0,
-0xaee204f8, 0x8f42023c, 0x50400045, 0xaee07274,
-0x8ee20184, 0x24420001, 0xaee20184, 0x8ee20184,
-0x8002b71, 0xaee07274, 0x8ee20504, 0x24030040,
-0x24420001, 0x50430003, 0x1021, 0x8ee20504,
-0x24420001, 0xaee20504, 0x8ee20504, 0x8cc30018,
-0x21080, 0x571021, 0x8c440508, 0x24020003,
-0x1462000f, 0x0, 0x3c020001, 0x571021,
-0x904283b1, 0x10400014, 0x0, 0x8ee201d0,
-0x8ee35240, 0x441021, 0xaee201d0, 0x8ee201d8,
-0x641821, 0x306300ff, 0x8002b59, 0xaee35240,
-0x8ee201cc, 0x8ee30e10, 0x441021, 0xaee201cc,
-0x8ee201d8, 0x641821, 0x306301ff, 0xaee30e10,
-0x441021, 0xaee201d8, 0x8ee20000, 0x34420040,
-0x8002b71, 0xaee20000, 0x8ee2014c, 0x3c010001,
-0x370821, 0xa02083e0, 0x24420001, 0xaee2014c,
-0x8002b71, 0x8ee2014c, 0x94c7000e, 0x8cc2001c,
-0x3c040001, 0x24845760, 0xafa60014, 0xafa20010,
-0x8cc60018, 0x3c050008, 0xc002403, 0x34a50910,
-0x8fbf001c, 0x8fb00018, 0x3e00008, 0x27bd0020,
-0x27bdff98, 0xafbf0060, 0xafbe005c, 0xafb60058,
-0xafb50054, 0xafb40050, 0xafb3004c, 0xafb20048,
-0xafb10044, 0xafb00040, 0x8f830108, 0x8f820104,
-0xafa00024, 0x106203e7, 0xafa0002c, 0x3c1e0001,
-0x37de3800, 0x3c0bffff, 0x8f930108, 0x8e620018,
-0x8f830104, 0x2443fffe, 0x2c620014, 0x104003cf,
-0x31080, 0x3c010001, 0x220821, 0x8c2257c0,
-0x400008, 0x0, 0x9663000e, 0x8ee2725c,
-0x8ee404f0, 0x431021, 0xaee2725c, 0x8e63001c,
-0x96e20458, 0x24840001, 0xaee404f0, 0x24630001,
-0x2442ffff, 0x621824, 0xaee304e4, 0x8f42023c,
-0x82202b, 0x148003b9, 0x0, 0x8f830120,
-0x27623800, 0x24660020, 0xc2102b, 0x50400001,
-0x27663000, 0x8f820128, 0x10c20004, 0x0,
-0x8f820124, 0x14c20007, 0x0, 0x8ee201a4,
-0x8021, 0x24420001, 0xaee201a4, 0x8002bfe,
-0x8ee201a4, 0x8ee204e4, 0xac62001c, 0x8ee404b0,
-0x8ee504b4, 0x2462001c, 0xac620008, 0x24020008,
-0xa462000e, 0x24020011, 0xac620018, 0xac640000,
-0xac650004, 0x8ee204c4, 0xac620010, 0xaf860120,
-0x92e24e20, 0x14400037, 0x24100001, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0x8c830000,
-0x24020012, 0x1462001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x240c0040, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee34e30,
-0x24420001, 0x104c0007, 0x0, 0x8ee24e34,
-0x24420001, 0x10620005, 0x0, 0x8002be8,
-0x0, 0x14600005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400013, 0xac800000, 0x8002bfe,
-0x0, 0x8ee24e30, 0x240c0040, 0x24420001,
-0x504c0003, 0x1021, 0x8ee24e30, 0x24420001,
-0xaee24e30, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x24020012, 0x240c0001, 0xac820000,
-0xac8c0004, 0x5600000d, 0x24100001, 0x8ee204e4,
-0x3c040001, 0x24845754, 0xafa00014, 0xafa20010,
-0x8ee60608, 0x8f470228, 0x3c050009, 0x34a5f006,
-0xc002403, 0xafab0038, 0x8fab0038, 0x1200030a,
-0x240c0001, 0x8002f19, 0x0, 0x966c001c,
-0xafac002c, 0x9662001e, 0x3c0c8000, 0xafac0024,
-0xae62001c, 0x8e75001c, 0x8ee204fc, 0x8ee404fc,
-0x151900, 0x621021, 0x8c52000c, 0x92e27b98,
-0x641821, 0x9476000a, 0x14400003, 0x32c20002,
-0xaef27ba4, 0xaef57b9c, 0x1040004b, 0x8021,
-0x96e2045a, 0x30420002, 0x10400047, 0x0,
-0x8e63001c, 0x8ee204fc, 0x32100, 0x821021,
-0x8c42000c, 0x37e1821, 0x24420022, 0x43102b,
-0x1440000a, 0x24050014, 0x8ee204fc, 0x821021,
-0x8c44000c, 0xafab0038, 0xc002f75, 0x2484000e,
-0x8fab0038, 0x8002c52, 0x3050ffff, 0x8ee204fc,
-0x821021, 0x8c42000c, 0x9450000e, 0x94430010,
-0x94440012, 0x94450014, 0x2038021, 0x2048021,
-0x2058021, 0x94430016, 0x94440018, 0x9445001a,
-0x2038021, 0x2048021, 0x2058021, 0x9443001c,
-0x9444001e, 0x94420020, 0x2038021, 0x2048021,
-0x2028021, 0x101c02, 0x3202ffff, 0x628021,
-0x8e63001c, 0x8ee204fc, 0x102402, 0x32900,
-0xa21021, 0x8c43000c, 0x3202ffff, 0x828021,
-0x37e1021, 0x24630018, 0x62182b, 0x14600009,
-0x0, 0x8ee204fc, 0xa21021, 0x8c43000c,
-0x101027, 0x3c01ffff, 0x230821, 0x8002c6f,
-0xa4220018, 0x8ee204fc, 0xa21021, 0x8c43000c,
-0x101027, 0xa4620018, 0x96e2045a, 0x8821,
-0x30420008, 0x14400063, 0xa021, 0x8e63001c,
-0x8ee204fc, 0x33100, 0xc21021, 0x8c42000c,
-0x37e1821, 0x24420022, 0x43102b, 0x14400035,
-0x0, 0x8ee204fc, 0xc21021, 0x8c42000c,
-0x24470010, 0x37e1021, 0xe2102b, 0x50400001,
-0xeb3821, 0x8ee204fc, 0x94f10000, 0xc21021,
-0x8c42000c, 0x24470016, 0x37e1021, 0xe2102b,
-0x14400002, 0x2634ffec, 0xeb3821, 0x8ee204fc,
-0x90e30001, 0xc21021, 0x8c42000c, 0x2447001a,
-0x37e1021, 0xe2102b, 0x14400002, 0x2838821,
-0xeb3821, 0x94e20000, 0x24e70002, 0x2228821,
-0x37e1021, 0xe2102b, 0x50400001, 0xeb3821,
-0x94e20000, 0x24e70002, 0x2228821, 0x37e1021,
-0xe2102b, 0x50400001, 0xeb3821, 0x94e20000,
-0x24e70002, 0x2228821, 0x37e1021, 0xe2102b,
-0x50400001, 0xeb3821, 0x94e20000, 0x8002cd0,
-0x2228821, 0x8ee204fc, 0xc21021, 0x8c43000c,
-0x8ee204fc, 0x94710010, 0x8ee304fc, 0xc21021,
-0x8c44000c, 0xc31821, 0x8c62000c, 0x2634ffec,
-0x90840017, 0x8ee304fc, 0x9442001a, 0x2848821,
-0xc31821, 0x8c65000c, 0x8ee304fc, 0x2228821,
-0x8ee204fc, 0xc31821, 0xc21021, 0x8c44000c,
-0x8c62000c, 0x94a3001c, 0x9484001e, 0x94420020,
-0x2238821, 0x2248821, 0x2228821, 0x111c02,
-0x3222ffff, 0x628821, 0x111c02, 0x3222ffff,
-0x628821, 0x32c20001, 0x104000b2, 0x0,
-0x96e2045a, 0x30420001, 0x104000ae, 0x32c20080,
-0x10400008, 0x0, 0x92e27b98, 0x14400005,
-0x0, 0x240c0001, 0xa2ec7b98, 0xaef57b9c,
-0xaef27ba4, 0x8ee304fc, 0x151100, 0x431021,
-0x8c47000c, 0x37e1821, 0x24e2000e, 0x43102b,
-0x14400008, 0xe02021, 0x2405000e, 0xc002f75,
-0xafab0038, 0x3042ffff, 0x8fab0038, 0x8002d09,
-0x2028021, 0x94e60000, 0x24e70002, 0x94e50000,
-0x24e70002, 0x94e30000, 0x24e70002, 0x94e20000,
-0x24e70002, 0x94e40000, 0x24e70002, 0x2068021,
-0x2058021, 0x2038021, 0x2028021, 0x94e20000,
-0x94e30002, 0x2048021, 0x2028021, 0x2038021,
-0x101c02, 0x3202ffff, 0x628021, 0x101c02,
-0x3202ffff, 0x8ee47b9c, 0x628021, 0x14950004,
-0x3205ffff, 0x96620016, 0x8002d17, 0x512021,
-0x96620016, 0x542021, 0x41402, 0x3083ffff,
-0x432021, 0x852023, 0x41402, 0x822021,
-0x3084ffff, 0x50800001, 0x3404ffff, 0x8ee27ba4,
-0x24430017, 0x37e1021, 0x62102b, 0x50400001,
-0x6b1821, 0x90630000, 0x24020011, 0x14620031,
-0x24020006, 0x8ee27ba4, 0x37e1821, 0x24420028,
-0x43102b, 0x14400018, 0x0, 0x8ee27b9c,
-0x12a2000a, 0x32c20100, 0x8ee27ba4, 0x3c01ffff,
-0x220821, 0x94220028, 0x822021, 0x41c02,
-0x3082ffff, 0x622021, 0x32c20100, 0x14400004,
-0x41027, 0x92e27b98, 0x14400002, 0x41027,
-0x3044ffff, 0x8ee27ba4, 0x3c01ffff, 0x220821,
-0x8002d8a, 0xa4240028, 0x8ee27b9c, 0x12a20008,
-0x32c20100, 0x8ee27ba4, 0x94420028, 0x822021,
-0x41c02, 0x3082ffff, 0x622021, 0x32c20100,
-0x14400004, 0x41027, 0x92e27b98, 0x14400002,
-0x41027, 0x3044ffff, 0x8ee27ba4, 0x8002d8a,
-0xa4440028, 0x1462002f, 0x37e1821, 0x8ee27ba4,
-0x24420032, 0x43102b, 0x14400018, 0x0,
-0x8ee27b9c, 0x12a2000a, 0x32c20100, 0x8ee27ba4,
-0x3c01ffff, 0x220821, 0x94220032, 0x822021,
-0x41c02, 0x3082ffff, 0x622021, 0x32c20100,
-0x14400004, 0x41027, 0x92e27b98, 0x14400002,
-0x41027, 0x3044ffff, 0x8ee27ba4, 0x3c01ffff,
-0x220821, 0x8002d8a, 0xa4240032, 0x8ee27b9c,
-0x12a20008, 0x32c20100, 0x8ee27ba4, 0x94420032,
-0x822021, 0x41c02, 0x3082ffff, 0x622021,
-0x32c20100, 0x14400004, 0x41027, 0x92e27b98,
-0x14400002, 0x41027, 0x3044ffff, 0x8ee27ba4,
-0xa4440032, 0x8fac0024, 0x1180002c, 0x37e1821,
-0x8e420000, 0xae42fffc, 0x2642000a, 0x43102b,
-0x1440001b, 0x34038100, 0x26430004, 0x37e1021,
-0x62102b, 0x14400003, 0x602021, 0x6b1821,
-0x602021, 0x8c620000, 0x24630004, 0xae420000,
-0x37e1021, 0x62102b, 0x50400001, 0x6b1821,
-0x8c620000, 0xac820000, 0x34028100, 0xa4620000,
-0x24630002, 0x37e1021, 0x62102b, 0x50400001,
-0x6b1821, 0x97ac002e, 0x8002db4, 0xa46c0000,
-0x8e420004, 0x8e440008, 0xa6430008, 0x97ac002e,
-0xa64c000a, 0xae420000, 0xae440004, 0x9662000e,
-0x2652fffc, 0x24420004, 0xa662000e, 0x9662000e,
-0x8ee3725c, 0x621821, 0xaee3725c, 0xafb20018,
-0x8ee3725c, 0xafa3001c, 0x8ee2725c, 0x2c42003c,
-0x10400004, 0x24620001, 0x2403fffe, 0x431024,
-0xafa2001c, 0x32c20080, 0x1040000c, 0x32c20100,
-0x8ee27ba8, 0x24430001, 0x210c0, 0x571021,
-0xaee37ba8, 0x8fa30018, 0x8fa4001c, 0xac437bac,
-0xac447bb0, 0x8002ea0, 0xaee0725c, 0x10400072,
-0x0, 0x8ee27ba8, 0x24430001, 0x210c0,
-0x571021, 0xaee37ba8, 0x8fa30018, 0x8fa4001c,
-0xac437bac, 0xac447bb0, 0x8ee27ba8, 0x10400063,
-0x4821, 0x5021, 0x8f8200f0, 0x24480008,
-0x27621800, 0x102102b, 0x50400001, 0x27681000,
-0x8f8200f4, 0x15020007, 0x0, 0x8ee201b4,
-0x8021, 0x24420001, 0xaee201b4, 0x8002dfa,
-0x8ee201b4, 0x8f8300f0, 0x24100001, 0x1571021,
-0x8c447bac, 0x8c457bb0, 0xac640000, 0xac650004,
-0xaf8800f0, 0x16000006, 0x2ea1021, 0x8ee20088,
-0x24420001, 0xaee20088, 0x8002e3f, 0x8ee20088,
-0x8c427bb0, 0x8ee400e0, 0x8ee500e4, 0x8ee67b9c,
-0x401821, 0x1021, 0xa32821, 0xa3382b,
-0x822021, 0x872021, 0x8ee204fc, 0xc93021,
-0x63100, 0xaee400e0, 0xaee500e4, 0xc23021,
-0x94c2000a, 0x240c0002, 0x21142, 0x30430003,
-0x106c0016, 0x28620003, 0x10400005, 0x240c0001,
-0x106c0008, 0x0, 0x8002e3f, 0x0,
-0x240c0003, 0x106c0017, 0x0, 0x8002e3f,
-0x0, 0x8ee200e8, 0x8ee300ec, 0x24630001,
-0x2c640001, 0x441021, 0xaee200e8, 0xaee300ec,
-0x8ee200e8, 0x8002e3f, 0x8ee300ec, 0x8ee200f0,
-0x8ee300f4, 0x24630001, 0x2c640001, 0x441021,
-0xaee200f0, 0xaee300f4, 0x8ee200f0, 0x8002e3f,
-0x8ee300f4, 0x8ee200f8, 0x8ee300fc, 0x24630001,
-0x2c640001, 0x441021, 0xaee200f8, 0xaee300fc,
-0x8ee200f8, 0x8ee300fc, 0x8ee27ba8, 0x25290001,
-0x122102b, 0x1440ffa0, 0x254a0008, 0xa2e07b98,
-0x8002e9f, 0xaee07ba8, 0x8f8200f0, 0x24470008,
-0x27621800, 0xe2102b, 0x50400001, 0x27671000,
-0x8f8200f4, 0x14e20007, 0x0, 0x8ee201b4,
-0x8021, 0x24420001, 0xaee201b4, 0x8002e5d,
-0x8ee201b4, 0x8f8200f0, 0x24100001, 0x8fa30018,
-0x8fa4001c, 0xac430000, 0xac440004, 0xaf8700f0,
-0x16000007, 0x0, 0x8ee20088, 0x24420001,
-0xaee20088, 0x8ee20088, 0x8002ea0, 0xaee0725c,
-0x8ee2725c, 0x8ee400e0, 0x8ee500e4, 0x240c0002,
-0x401821, 0x1021, 0xa32821, 0xa3302b,
-0x822021, 0x862021, 0x161142, 0x30430003,
-0xaee400e0, 0xaee500e4, 0x106c0017, 0x2c620003,
-0x10400005, 0x240c0001, 0x106c0008, 0x0,
-0x8002ea0, 0xaee0725c, 0x240c0003, 0x106c0019,
-0x0, 0x8002ea0, 0xaee0725c, 0x8ee200e8,
-0x8ee300ec, 0x24630001, 0x2c640001, 0x441021,
-0xaee200e8, 0xaee300ec, 0x8ee200e8, 0x8ee300ec,
-0x8002ea0, 0xaee0725c, 0x8ee200f0, 0x8ee300f4,
-0x24630001, 0x2c640001, 0x441021, 0xaee200f0,
-0xaee300f4, 0x8ee200f0, 0x8ee300f4, 0x8002ea0,
-0xaee0725c, 0x8ee200f8, 0x8ee300fc, 0x24630001,
-0x2c640001, 0x441021, 0xaee200f8, 0xaee300fc,
-0x8ee200f8, 0x8ee300fc, 0xaee0725c, 0x8e62001c,
-0x96e30458, 0x8ee404f0, 0x24420001, 0x2463ffff,
-0x431024, 0x24840001, 0xaee204e4, 0xaee404f0,
-0x8f42023c, 0x82202b, 0x148000b0, 0x0,
-0x8f830120, 0x27623800, 0x24660020, 0xc2102b,
-0x50400001, 0x27663000, 0x8f820128, 0x10c20004,
-0x0, 0x8f820124, 0x14c20007, 0x0,
-0x8ee201a4, 0x8021, 0x24420001, 0xaee201a4,
-0x8002f07, 0x8ee201a4, 0x8ee204e4, 0xac62001c,
-0x8ee404b0, 0x8ee504b4, 0x2462001c, 0xac620008,
-0x24020008, 0xa462000e, 0x24020011, 0xac620018,
-0xac640000, 0xac650004, 0x8ee204c4, 0xac620010,
-0xaf860120, 0x92e24e20, 0x14400037, 0x24100001,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x8c830000, 0x24020012, 0x1462001f, 0x0,
-0x8ee34e30, 0x8ee24e34, 0x1062001b, 0x240c0040,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e34,
-0x8ee34e30, 0x24420001, 0x104c0007, 0x0,
-0x8ee24e34, 0x24420001, 0x10620005, 0x0,
-0x8002ef1, 0x0, 0x14600005, 0x0,
-0x8f820128, 0x24420020, 0xaf820128, 0x8f820128,
-0x8c820004, 0x2c420011, 0x50400013, 0xac800000,
-0x8002f07, 0x0, 0x8ee24e30, 0x240c0040,
-0x24420001, 0x504c0003, 0x1021, 0x8ee24e30,
-0x24420001, 0xaee24e30, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x24020012, 0x240c0001,
-0xac820000, 0xac8c0004, 0x5600000d, 0x24100001,
-0x8ee204e4, 0x3c040001, 0x24845754, 0xafa00014,
-0xafa20010, 0x8ee60608, 0x8f470228, 0x3c050009,
-0x34a5f006, 0xc002403, 0xafab0038, 0x8fab0038,
-0x16000003, 0x240c0001, 0x8002f5c, 0xa2ec04f4,
-0x8ee20170, 0x24420001, 0xaee20170, 0x8ee20170,
-0x8ee204e4, 0xa2e004f4, 0xaee004f0, 0xaee07274,
-0xaee204f8, 0x8f42023c, 0x10400038, 0x0,
-0x8ee20184, 0x24420001, 0xaee20184, 0x8002f5c,
-0x8ee20184, 0x8ee20504, 0x240c0040, 0x24420001,
-0x504c0003, 0x1021, 0x8ee20504, 0x24420001,
-0xaee20504, 0x8ee20504, 0x8e630018, 0x240c0003,
-0x21080, 0x571021, 0x146c000f, 0x8c440508,
-0x3c020001, 0x571021, 0x904283b1, 0x10400014,
-0x0, 0x8ee201d0, 0x8ee35240, 0x441021,
-0xaee201d0, 0x8ee201d8, 0x641821, 0x306300ff,
-0x8002f4f, 0xaee35240, 0x8ee201cc, 0x8ee30e10,
-0x441021, 0xaee201cc, 0x8ee201d8, 0x641821,
-0x306301ff, 0xaee30e10, 0x441021, 0xaee201d8,
-0x8ee20000, 0x34420040, 0x8002f5c, 0xaee20000,
-0x8ee2014c, 0x3c010001, 0x370821, 0xa02083e0,
-0x24420001, 0xaee2014c, 0x8ee2014c, 0x8f820108,
-0x24420020, 0xaf820108, 0x8f820108, 0x8f820108,
-0x27633000, 0x43102b, 0x14400002, 0x27622800,
-0xaf820108, 0x8f830108, 0x8f820104, 0x1462fc1e,
-0x0, 0x8fbf0060, 0x8fbe005c, 0x8fb60058,
-0x8fb50054, 0x8fb40050, 0x8fb3004c, 0x8fb20048,
-0x8fb10044, 0x8fb00040, 0x3e00008, 0x27bd0068,
-0x52843, 0x10a0000d, 0x3021, 0x3c030001,
-0x34633800, 0x3c07ffff, 0x3631021, 0x82102b,
-0x50400001, 0x872021, 0x94820000, 0x24840002,
-0x24a5ffff, 0x14a0fff8, 0xc23021, 0x61c02,
-0x30c2ffff, 0x623021, 0x61c02, 0x30c2ffff,
-0x623021, 0x3e00008, 0x30c2ffff, 0x27bdff88,
-0x240f0001, 0xafbf0070, 0xafbe006c, 0xafb60068,
-0xafb50064, 0xafb40060, 0xafb3005c, 0xafb20058,
-0xafb10054, 0xafb00050, 0xa3a00027, 0xafaf002c,
-0x8ee204d4, 0x8021, 0x30420001, 0x1440002a,
-0xa3a00037, 0x8f8700e0, 0x8f8800c4, 0x8f8200e8,
-0xe22023, 0x2c821000, 0x50400001, 0x24841000,
-0x420c2, 0x801821, 0x8ee400c8, 0x8ee500cc,
-0x1021, 0xa32821, 0xa3302b, 0x822021,
-0x862021, 0xaee400c8, 0xaee500cc, 0x8f8300c8,
-0x3c02000a, 0x3442efff, 0x1032023, 0x44102b,
-0x10400003, 0x3c02000a, 0x3442f000, 0x822021,
-0x801821, 0x8ee400c0, 0x8ee500c4, 0x1021,
-0xa32821, 0xa3302b, 0x822021, 0x862021,
-0xaee400c0, 0xaee500c4, 0xaf8800c8, 0xaf8700e4,
-0x80034cc, 0xaf8700e8, 0x3c020001, 0x571021,
-0x904283c0, 0x1040000b, 0x0, 0x3c140001,
-0x297a021, 0x8e9483c4, 0x3c130001, 0x2779821,
-0x8e7383c8, 0x3c120001, 0x2579021, 0x8003193,
-0x8e5283cc, 0x8f8300e0, 0x8f8200e4, 0x10430007,
-0x8821, 0x8f8200e4, 0x24110001, 0x8c430000,
-0x8c440004, 0xafa30018, 0xafa4001c, 0x1620000e,
-0x3c02ffff, 0x8f8200c4, 0xafa20010, 0x8f8200c8,
-0x3c040001, 0x24845870, 0xafa20014, 0x8f8600e0,
-0x8f8700e4, 0x3c050006, 0xc002403, 0x34a5f000,
-0x80034cc, 0x0, 0x8fa3001c, 0x8fb20018,
-0x3074ffff, 0x2694fffc, 0x621024, 0x10400058,
-0x2409821, 0x3c020080, 0x621024, 0x1040000a,
-0x3c040040, 0x8ee2007c, 0x24420001, 0xaee2007c,
-0x8ee2007c, 0x8ee201fc, 0x24420001, 0xaee201fc,
-0x80034c6, 0x8ee201fc, 0x3c060004, 0x3c0b0001,
-0x3c0a0002, 0x3c050010, 0x3c090008, 0x8ee20080,
-0x3c080020, 0x34078000, 0x24420001, 0xaee20080,
-0x8ee20080, 0x8fa2001c, 0x441824, 0x10660021,
-0xc3102b, 0x14400007, 0x0, 0x106b0011,
-0x0, 0x106a0015, 0x0, 0x8003049,
-0x42042, 0x10650023, 0xa3102b, 0x14400005,
-0x0, 0x10690019, 0x0, 0x8003049,
-0x42042, 0x10680021, 0x0, 0x8003049,
-0x42042, 0x8ee20034, 0x24420001, 0xaee20034,
-0x8ee20034, 0x8003049, 0x42042, 0x8ee201ec,
-0x24420001, 0xaee201ec, 0x8ee201ec, 0x8003049,
-0x42042, 0x8ee201f0, 0x24420001, 0xaee201f0,
-0x8ee201f0, 0x8003049, 0x42042, 0x8ee201f4,
-0x24420001, 0xaee201f4, 0x8ee201f4, 0x8003049,
-0x42042, 0x8ee20030, 0x24420001, 0xaee20030,
-0x8ee20030, 0x8003049, 0x42042, 0x8ee201f8,
-0x24420001, 0xaee201f8, 0x8ee201f8, 0x42042,
-0x1087047c, 0x0, 0x800300e, 0x0,
-0x3c020001, 0x571021, 0x904283b2, 0x14400084,
-0x24020001, 0x3c030001, 0x771821, 0x906383b3,
-0x1462007f, 0x3c020100, 0x8e430000, 0x621024,
-0x1040006f, 0x2402ffff, 0x14620005, 0x24100001,
-0x96430004, 0x3402ffff, 0x10620075, 0x0,
-0x92e204d8, 0x14400072, 0x0, 0x3c020001,
-0x571021, 0x8c4283b4, 0x28420005, 0x10400020,
-0x3821, 0x3c020001, 0x571021, 0x8c4283b4,
-0x18400016, 0x2821, 0x96660000, 0x520c0,
-0x971021, 0x9442777e, 0x14460009, 0x971021,
-0x94437780, 0x96620002, 0x14620005, 0x971021,
-0x94437782, 0x96620004, 0x50620008, 0x24070001,
-0x3c020001, 0x571021, 0x8c4283b4, 0x24a50001,
-0xa2102a, 0x5440ffee, 0x520c0, 0x30e200ff,
-0x10400440, 0x0, 0x80030d5, 0x0,
-0x2402021, 0xc0022fe, 0x24050006, 0x3044001f,
-0x428c0, 0x2e51021, 0x9442727c, 0x30424000,
-0x14400434, 0xb71021, 0x9443727e, 0x96620000,
-0x1462000b, 0x418c0, 0xb71021, 0x94437280,
-0x96620002, 0x14620006, 0x418c0, 0xb71021,
-0x94437282, 0x96620004, 0x10620035, 0x418c0,
-0x2e31021, 0x9442727c, 0x30428000, 0x14400421,
-0x2e31021, 0x944b727c, 0x96670000, 0xb28c0,
-0xb71021, 0x9442737e, 0x80030b7, 0x3021,
-0x420c0, 0x2e41021, 0x9443737c, 0x2e41021,
-0x944b737c, 0x30638000, 0x14600010, 0xb28c0,
-0xb71021, 0x9442737e, 0x1447fff5, 0x1602021,
-0xb71021, 0x94437380, 0x96620002, 0x5462fff1,
-0x420c0, 0xb71021, 0x94437382, 0x96620004,
-0x5462ffec, 0x420c0, 0x24060001, 0x30c200ff,
-0x10400400, 0x0, 0x80030d5, 0x0,
-0x97430202, 0x96420000, 0x146203fa, 0x0,
-0x97430204, 0x96420002, 0x146203f6, 0x0,
-0x97430206, 0x96420004, 0x146203f2, 0x0,
-0x92420000, 0x3a030001, 0x30420001, 0x431024,
-0x10400074, 0x2402ffff, 0x8e630000, 0x14620004,
-0x3402ffff, 0x96630004, 0x1062006f, 0x240f0002,
-0x3c020001, 0x571021, 0x904283b2, 0x1440006a,
-0x240f0003, 0x92e204d8, 0x54400068, 0xafaf002c,
-0x3c020001, 0x571021, 0x8c4283b4, 0x28420005,
-0x10400020, 0x3821, 0x3c020001, 0x571021,
-0x8c4283b4, 0x18400016, 0x2821, 0x96660000,
-0x520c0, 0x971021, 0x9442777e, 0x14460009,
-0x971021, 0x94437780, 0x96620002, 0x14620005,
-0x971021, 0x94437782, 0x96620004, 0x50620008,
-0x24070001, 0x3c020001, 0x571021, 0x8c4283b4,
-0x24a50001, 0xa2102a, 0x5440ffee, 0x520c0,
-0x30e200ff, 0x14400044, 0x240f0003, 0x80034c6,
-0x0, 0x2402021, 0xc0022fe, 0x24050006,
-0x3044001f, 0x428c0, 0x2e51021, 0x9442727c,
-0x30424000, 0x144003af, 0xb71021, 0x9443727e,
-0x96620000, 0x1462000b, 0x418c0, 0xb71021,
-0x94437280, 0x96620002, 0x14620006, 0x418c0,
-0xb71021, 0x94437282, 0x96620004, 0x10620027,
-0x418c0, 0x2e31021, 0x9442727c, 0x30428000,
-0x1440039c, 0x2e31021, 0x944b727c, 0x96670000,
-0xb28c0, 0xb71021, 0x9442737e, 0x800313c,
-0x3021, 0x420c0, 0x2e41021, 0x9443737c,
-0x2e41021, 0x944b737c, 0x30638000, 0x14600010,
-0xb28c0, 0xb71021, 0x9442737e, 0x1447fff5,
-0x1602021, 0xb71021, 0x94437380, 0x96620002,
-0x5462fff1, 0x420c0, 0xb71021, 0x94437382,
-0x96620004, 0x5462ffec, 0x420c0, 0x24060001,
-0x30c200ff, 0x1040037b, 0x0, 0x800314f,
-0x240f0003, 0x240f0001, 0xafaf002c, 0x8f420260,
-0x54102b, 0x1040003a, 0x0, 0x8f8300e4,
-0x8f8200e0, 0x10620003, 0x24630008, 0xaf8300e4,
-0xaf8300e8, 0x8ee400c0, 0x8ee500c4, 0x2801821,
-0x1021, 0xa32821, 0xa3302b, 0x822021,
-0x862021, 0xaee400c0, 0xaee500c4, 0x8ee20058,
-0x24420001, 0xaee20058, 0x8ee20058, 0x8ee2007c,
-0x24420001, 0xaee2007c, 0x8ee2007c, 0x8f8200e0,
-0xafa20010, 0x8f8200e4, 0x3c040001, 0x24845878,
-0xafa20014, 0x8fa60018, 0x8fa7001c, 0x3c050006,
-0xc002403, 0x34a5f003, 0x80034cc, 0x0,
-0x8ee25240, 0xafa20010, 0x8ee25244, 0x3c040001,
-0x24845884, 0xafa20014, 0x8ee60e10, 0x8ee70e18,
-0x3c050006, 0xc002403, 0x34a5f002, 0x8ee201c0,
-0x24420001, 0xaee201c0, 0x8ee20000, 0x8ee301c0,
-0x2403ffbf, 0x431024, 0x8003470, 0xaee20000,
-0x96e20468, 0x54102b, 0x10400003, 0x0,
-0x240f0001, 0xa3af0027, 0x12800301, 0x24160007,
-0x24150040, 0x241e0001, 0x240e0012, 0x8ee2724c,
-0x8f430280, 0x24420001, 0x304207ff, 0x106202d3,
-0x0, 0x93a20027, 0x10400014, 0x0,
-0x8ee35240, 0x8ee25244, 0x10620009, 0x26ed5244,
-0x8ee65244, 0x8ee35244, 0x21140, 0x24425248,
-0x2e28021, 0x24630001, 0x80031bf, 0x306b00ff,
-0x92e27248, 0x1440ffca, 0x0, 0x8ee201e0,
-0x24420001, 0xaee201e0, 0x8ee201e0, 0x8ee30e10,
-0x8ee20e18, 0x1062ffc2, 0x26ed0e18, 0x8ee60e18,
-0x8ee30e18, 0x21140, 0x24420e20, 0x2e28021,
-0x24630001, 0x306b01ff, 0x96e2046a, 0x30420010,
-0x10400019, 0x0, 0x9642000c, 0x340f8100,
-0x144f0015, 0x0, 0x3c020001, 0x571021,
-0x904283c0, 0x14400010, 0x0, 0x9642000e,
-0xa6020016, 0x8e420008, 0x8e430004, 0x8e440000,
-0x2694fffc, 0xae42000c, 0xae430008, 0xae440004,
-0x9602000e, 0x26730004, 0x240f0001, 0xa3af0037,
-0x34420200, 0xa602000e, 0x8e020000, 0x8e030004,
-0x3c040001, 0x34843800, 0x306a0007, 0x26a9823,
-0x3641021, 0x262102b, 0x10400005, 0x28aa021,
-0x2641023, 0x3621823, 0x3c020020, 0x439823,
-0x26820007, 0x2404fff8, 0x9603000a, 0x446024,
-0x6a1821, 0x6c102b, 0x10400002, 0x1803821,
-0x603821, 0xae130018, 0x8f880120, 0x24e20007,
-0x443824, 0x27623800, 0x25090020, 0x122102b,
-0x50400001, 0x27693000, 0x8f820128, 0x11220004,
-0x0, 0x8f820124, 0x15220007, 0x1401821,
-0x8ee201a4, 0x8821, 0x24420001, 0xaee201a4,
-0x800324c, 0x8ee201a4, 0x8e040000, 0x8e050004,
-0x1021, 0xad130008, 0xa507000e, 0xad160018,
-0xad06001c, 0xa3302b, 0xa32823, 0x822023,
-0x862023, 0xad040000, 0xad050004, 0x8ee204c0,
-0xad020010, 0xaf890120, 0x92e24e20, 0x14400033,
-0x24110001, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x8c820000, 0x1456001f, 0x0,
-0x8ee34e30, 0x8ee24e34, 0x1062001b, 0x0,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e34,
-0x8ee34e30, 0x24420001, 0x10550007, 0x0,
-0x8ee24e34, 0x24420001, 0x10620005, 0x0,
-0x8003239, 0x0, 0x14600005, 0x0,
-0x8f820128, 0x24420020, 0xaf820128, 0x8f820128,
-0x8c820004, 0x2c420011, 0x50400010, 0xac800000,
-0x800324c, 0x0, 0x8ee24e30, 0x24420001,
-0x50550003, 0x1021, 0x8ee24e30, 0x24420001,
-0xaee24e30, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0xac960000, 0xac9e0004, 0x16200018,
-0x3c050006, 0x8e020018, 0x3c040001, 0x24845890,
-0xafa20010, 0x8e020000, 0x8e030004, 0x34a5f009,
-0x2003021, 0xc002403, 0xafa30014, 0x93a20037,
-0x10400216, 0x340f8100, 0x8e420004, 0x8e430008,
-0x8e44000c, 0xa64f000c, 0xae420000, 0xae430004,
-0xae440008, 0x96020016, 0x8003470, 0xa642000e,
-0x14ec0168, 0x28a1823, 0x960c000a, 0x9603000e,
-0x28a1023, 0xa602000a, 0x34620004, 0xa602000e,
-0x8f880120, 0x27623800, 0x25090020, 0x122102b,
-0x14400002, 0x306affff, 0x27693000, 0x8f820128,
-0x11220004, 0x0, 0x8f820124, 0x15220007,
-0x24040020, 0x8ee201a4, 0x8821, 0x24420001,
-0xaee201a4, 0x80032ca, 0x8ee201a4, 0x8ee5724c,
-0x8ee60490, 0x8ee70494, 0xa504000e, 0x24040004,
-0xad100008, 0xad040018, 0x52940, 0xa01821,
-0x1021, 0xe33821, 0xe3202b, 0xc23021,
-0xc43021, 0xad060000, 0xad070004, 0x8ee2724c,
-0xad02001c, 0x8ee204c4, 0xad020010, 0xaf890120,
-0x92e24e20, 0x14400033, 0x24110001, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0x8c820000,
-0x1456001f, 0x0, 0x8ee34e30, 0x8ee24e34,
-0x1062001b, 0x0, 0x8c820004, 0x24420001,
-0xac820004, 0x8ee24e34, 0x8ee34e30, 0x24420001,
-0x10550007, 0x0, 0x8ee24e34, 0x24420001,
-0x10620005, 0x0, 0x80032b7, 0x0,
-0x14600005, 0x0, 0x8f820128, 0x24420020,
-0xaf820128, 0x8f820128, 0x8c820004, 0x2c420011,
-0x50400010, 0xac800000, 0x80032ca, 0x0,
-0x8ee24e30, 0x24420001, 0x50550003, 0x1021,
-0x8ee24e30, 0x24420001, 0xaee24e30, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0xac960000,
-0xac9e0004, 0x1620000d, 0x0, 0xa60c000a,
-0xa60a000e, 0x8f820100, 0xafa20010, 0x8f820104,
-0x3c040001, 0x2484589c, 0x3c050006, 0xafa20014,
-0x8ee6724c, 0x800343b, 0x34a5f00b, 0x3c010001,
-0x370821, 0xa02083c0, 0xadab0000, 0x8ee201d8,
-0x8ee3724c, 0x2442ffff, 0xaee201d8, 0x8ee201d8,
-0x24630001, 0x306307ff, 0x26e25244, 0x15a20006,
-0xaee3724c, 0x8ee201d0, 0x2442ffff, 0xaee201d0,
-0x80032ef, 0x8ee201d0, 0x8ee201cc, 0x2442ffff,
-0xaee201cc, 0x8ee201cc, 0x8f420240, 0x10400073,
-0x0, 0x8ee20e1c, 0x24420001, 0xaee20e1c,
-0x8f430240, 0x43102b, 0x14400176, 0xa021,
-0x8f830120, 0x27623800, 0x24660020, 0xc2102b,
-0x50400001, 0x27663000, 0x8f820128, 0x10c20004,
-0x0, 0x8f820124, 0x14c20007, 0x0,
-0x8ee201a4, 0x8821, 0x24420001, 0xaee201a4,
-0x800334f, 0x8ee201a4, 0x8ee2724c, 0xac62001c,
-0x8ee404a8, 0x8ee504ac, 0x2462001c, 0xac620008,
-0x24020008, 0xa462000e, 0x24020011, 0xac620018,
-0xac640000, 0xac650004, 0x8ee204c4, 0xac620010,
-0xaf860120, 0x92e24e20, 0x14400033, 0x24110001,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x8c820000, 0x144e001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x0, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee34e30,
-0x24420001, 0x10550007, 0x0, 0x8ee24e34,
-0x24420001, 0x10620005, 0x0, 0x800333c,
-0x0, 0x14600005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400010, 0xac800000, 0x800334f,
-0x0, 0x8ee24e30, 0x24420001, 0x50550003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0xac8e0000, 0xac9e0004, 0x5620000d, 0x24110001,
-0x8ee2724c, 0x3c040001, 0x248458a8, 0xafa00014,
-0xafa20010, 0x8ee6724c, 0x8f470280, 0x3c050009,
-0x34a5f008, 0xc002403, 0xafae0048, 0x8fae0048,
-0x56200001, 0xaee00e1c, 0x8ee20188, 0x24420001,
-0xaee20188, 0x80033c8, 0x8ee20188, 0x8f830120,
-0x27623800, 0x24660020, 0xc2102b, 0x50400001,
-0x27663000, 0x8f820128, 0x10c20004, 0x0,
-0x8f820124, 0x14c20007, 0x0, 0x8ee201a4,
-0x8821, 0x24420001, 0xaee201a4, 0x80033ba,
-0x8ee201a4, 0x8ee2724c, 0xac62001c, 0x8ee404a8,
-0x8ee504ac, 0x2462001c, 0xac620008, 0x24020008,
-0xa462000e, 0x24020011, 0xac620018, 0xac640000,
-0xac650004, 0x8ee204c4, 0xac620010, 0xaf860120,
-0x92e24e20, 0x14400033, 0x24110001, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0x8c820000,
-0x144e001f, 0x0, 0x8ee34e30, 0x8ee24e34,
-0x1062001b, 0x0, 0x8c820004, 0x24420001,
-0xac820004, 0x8ee24e34, 0x8ee34e30, 0x24420001,
-0x10550007, 0x0, 0x8ee24e34, 0x24420001,
-0x10620005, 0x0, 0x80033a7, 0x0,
-0x14600005, 0x0, 0x8f820128, 0x24420020,
-0xaf820128, 0x8f820128, 0x8c820004, 0x2c420011,
-0x50400010, 0xac800000, 0x80033ba, 0x0,
-0x8ee24e30, 0x24420001, 0x50550003, 0x1021,
-0x8ee24e30, 0x24420001, 0xaee24e30, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0xac8e0000,
-0xac9e0004, 0x1620000d, 0x0, 0x8ee2724c,
-0x3c040001, 0x248458a8, 0xafa00014, 0xafa20010,
-0x8ee6724c, 0x8f470280, 0x3c050009, 0x34a5f008,
-0xc002403, 0xafae0048, 0x8fae0048, 0x8ee20174,
-0x24420001, 0xaee20174, 0x8ee20174, 0x800346e,
-0xa021, 0x960c000a, 0x183102b, 0x54400001,
-0x1801821, 0xa603000a, 0x8f880120, 0x27623800,
-0x25090020, 0x122102b, 0x50400001, 0x27693000,
-0x8f820128, 0x11220004, 0x0, 0x8f820124,
-0x15220007, 0x24040020, 0x8ee201a4, 0x8821,
-0x24420001, 0xaee201a4, 0x800342f, 0x8ee201a4,
-0x8ee5724c, 0x8ee60490, 0x8ee70494, 0xa504000e,
-0x24040004, 0xad100008, 0xad040018, 0x52940,
-0xa01821, 0x1021, 0xe33821, 0xe3202b,
-0xc23021, 0xc43021, 0xad060000, 0xad070004,
-0x8ee2724c, 0xad02001c, 0x8ee204c4, 0xad020010,
-0xaf890120, 0x92e24e20, 0x14400033, 0x24110001,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x8c820000, 0x1456001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x0, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee34e30,
-0x24420001, 0x10550007, 0x0, 0x8ee24e34,
-0x24420001, 0x10620005, 0x0, 0x800341c,
-0x0, 0x14600005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400010, 0xac800000, 0x800342f,
-0x0, 0x8ee24e30, 0x24420001, 0x50550003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0xac960000, 0xac9e0004, 0x1620001d, 0x0,
-0xa60c000a, 0x8f820100, 0xafa20010, 0x8f820104,
-0x3c040001, 0x2484589c, 0x3c050006, 0xafa20014,
-0x8ee6724c, 0x34a5f00d, 0xc002403, 0x2003821,
-0x93a20037, 0x10400031, 0x340f8100, 0x8e420004,
-0x8e430008, 0x8e44000c, 0xa64f000c, 0xae420000,
-0xae430004, 0xae440008, 0x96020016, 0xa642000e,
-0x9602000e, 0x3042fdff, 0x8003470, 0xa602000e,
-0x8ee201d8, 0x2442ffff, 0xaee201d8, 0x8ee201d8,
-0x8ee201cc, 0x3c04001f, 0x3c010001, 0x370821,
-0xa03e83c0, 0x2442ffff, 0xaee201cc, 0x9603000a,
-0x3484ffff, 0x8ee201cc, 0x6a1821, 0x2639821,
-0x93202b, 0x10800003, 0x3c02fff5, 0x34421000,
-0x2629821, 0xadab0000, 0x8ee2724c, 0x24420001,
-0x304207ff, 0xaee2724c, 0x8f420240, 0x10400004,
-0x283a023, 0x8ee20e1c, 0x24420001, 0xaee20e1c,
-0xa3a00027, 0x1680fd29, 0x0, 0x12800024,
-0x0, 0x3c010001, 0x370821, 0xac3483c4,
-0x3c010001, 0x370821, 0xac3383c8, 0x3c010001,
-0x370821, 0xac3283cc, 0x93a20037, 0x10400008,
-0x0, 0x3c020001, 0x571021, 0x8c4283cc,
-0x24420004, 0x3c010001, 0x370821, 0xac2283cc,
-0x8ee2724c, 0x8f430280, 0x24420001, 0x304207ff,
-0x14620006, 0x0, 0x8ee201c4, 0x24420001,
-0xaee201c4, 0x80034cc, 0x8ee201c4, 0x8ee201bc,
-0x24420001, 0xaee201bc, 0x80034cc, 0x8ee201bc,
-0x97a4001e, 0x2484fffc, 0x801821, 0x8ee400c0,
-0x8ee500c4, 0x1021, 0xa32821, 0xa3302b,
-0x822021, 0x862021, 0xaee400c0, 0xaee500c4,
-0x8faf002c, 0x24020002, 0x11e2000f, 0x29e20003,
-0x14400017, 0x24020003, 0x15e20015, 0x0,
-0x8ee200d0, 0x8ee300d4, 0x24630001, 0x2c640001,
-0x441021, 0xaee200d0, 0xaee300d4, 0x8ee200d0,
-0x80034c6, 0x8ee300d4, 0x8ee200d8, 0x8ee300dc,
-0x24630001, 0x2c640001, 0x441021, 0xaee200d8,
-0xaee300dc, 0x8ee200d8, 0x80034c6, 0x8ee300dc,
-0x8ee200c8, 0x8ee300cc, 0x24630001, 0x2c640001,
-0x441021, 0xaee200c8, 0xaee300cc, 0x8ee200c8,
-0x8ee300cc, 0x8f8300e4, 0x8f8200e0, 0x10620003,
-0x24630008, 0xaf8300e4, 0xaf8300e8, 0x8fbf0070,
-0x8fbe006c, 0x8fb60068, 0x8fb50064, 0x8fb40060,
-0x8fb3005c, 0x8fb20058, 0x8fb10054, 0x8fb00050,
-0x3e00008, 0x27bd0078, 0x27bdffb0, 0xafb50044,
-0xa821, 0xafb00030, 0x8021, 0xafbf004c,
-0xafb60048, 0xafb40040, 0xafb3003c, 0xafb20038,
-0xafb10034, 0x8ee204d4, 0x24140001, 0x30420001,
-0x1440002a, 0xb021, 0x8f8700e0, 0x8f8800c4,
-0x8f8200e8, 0xe22023, 0x2c821000, 0x50400001,
-0x24841000, 0x420c2, 0x801821, 0x8ee400c8,
-0x8ee500cc, 0x1021, 0xa32821, 0xa3302b,
-0x822021, 0x862021, 0xaee400c8, 0xaee500cc,
-0x8f8300c8, 0x3c02000a, 0x3442efff, 0x1032023,
-0x44102b, 0x10400003, 0x3c02000a, 0x3442f000,
-0x822021, 0x801821, 0x8ee400c0, 0x8ee500c4,
-0x1021, 0xa32821, 0xa3302b, 0x822021,
-0x862021, 0xaee400c0, 0xaee500c4, 0xaf8800c8,
-0xaf8700e4, 0x8003850, 0xaf8700e8, 0x3c020001,
-0x571021, 0x904283c0, 0x1040000b, 0x0,
-0x3c130001, 0x2779821, 0x8e7383c4, 0x3c110001,
-0x2378821, 0x8e3183c8, 0x3c120001, 0x2579021,
-0x80036e8, 0x8e5283cc, 0x8f8300e0, 0x8f8200e4,
-0x10430007, 0x4821, 0x8f8200e4, 0x24090001,
-0x8c430000, 0x8c440004, 0xafa30018, 0xafa4001c,
-0x1520000e, 0x3c02ffff, 0x8f8200c4, 0xafa20010,
-0x8f8200c8, 0x3c040001, 0x24845870, 0xafa20014,
-0x8f8600e0, 0x8f8700e4, 0x3c050006, 0xc002403,
-0x34a5f000, 0x8003850, 0x0, 0x8fa3001c,
-0x8fb20018, 0x3073ffff, 0x2673fffc, 0x621024,
-0x10400058, 0x2408821, 0x3c020080, 0x621024,
-0x1040000a, 0x3c040040, 0x8ee2007c, 0x24420001,
-0xaee2007c, 0x8ee2007c, 0x8ee201fc, 0x24420001,
-0xaee201fc, 0x800384a, 0x8ee201fc, 0x3c060004,
-0x3c0b0001, 0x3c0a0002, 0x3c050010, 0x3c090008,
-0x8ee20080, 0x3c080020, 0x34078000, 0x24420001,
-0xaee20080, 0x8ee20080, 0x8fa2001c, 0x441824,
-0x10660021, 0xc3102b, 0x14400007, 0x0,
-0x106b0011, 0x0, 0x106a0015, 0x0,
-0x8003592, 0x42042, 0x10650023, 0xa3102b,
-0x14400005, 0x0, 0x10690019, 0x0,
-0x8003592, 0x42042, 0x10680021, 0x0,
-0x8003592, 0x42042, 0x8ee20034, 0x24420001,
-0xaee20034, 0x8ee20034, 0x8003592, 0x42042,
-0x8ee201ec, 0x24420001, 0xaee201ec, 0x8ee201ec,
-0x8003592, 0x42042, 0x8ee201f0, 0x24420001,
-0xaee201f0, 0x8ee201f0, 0x8003592, 0x42042,
-0x8ee201f4, 0x24420001, 0xaee201f4, 0x8ee201f4,
-0x8003592, 0x42042, 0x8ee20030, 0x24420001,
-0xaee20030, 0x8ee20030, 0x8003592, 0x42042,
-0x8ee201f8, 0x24420001, 0xaee201f8, 0x8ee201f8,
-0x42042, 0x108702b7, 0x0, 0x8003557,
-0x0, 0x3c020001, 0x571021, 0x904283b2,
-0x14400084, 0x24020001, 0x3c030001, 0x771821,
-0x906383b3, 0x1462007f, 0x3c020100, 0x8e430000,
-0x621024, 0x1040006f, 0x2402ffff, 0x14620005,
-0x24100001, 0x96430004, 0x3402ffff, 0x10620075,
-0x0, 0x92e204d8, 0x14400072, 0x0,
-0x3c020001, 0x571021, 0x8c4283b4, 0x28420005,
-0x10400020, 0x3821, 0x3c020001, 0x571021,
-0x8c4283b4, 0x18400016, 0x2821, 0x96260000,
-0x520c0, 0x971021, 0x9442777e, 0x14460009,
-0x971021, 0x94437780, 0x96220002, 0x14620005,
-0x971021, 0x94437782, 0x96220004, 0x50620008,
-0x24070001, 0x3c020001, 0x571021, 0x8c4283b4,
-0x24a50001, 0xa2102a, 0x5440ffee, 0x520c0,
-0x30e200ff, 0x1040027b, 0x0, 0x800361e,
-0x0, 0x2402021, 0xc0022fe, 0x24050006,
-0x3044001f, 0x428c0, 0x2e51021, 0x9442727c,
-0x30424000, 0x1440026f, 0xb71021, 0x9443727e,
-0x96220000, 0x1462000b, 0x418c0, 0xb71021,
-0x94437280, 0x96220002, 0x14620006, 0x418c0,
-0xb71021, 0x94437282, 0x96220004, 0x10620035,
-0x418c0, 0x2e31021, 0x9442727c, 0x30428000,
-0x1440025c, 0x2e31021, 0x9448727c, 0x96270000,
-0x828c0, 0xb71021, 0x9442737e, 0x8003600,
-0x3021, 0x420c0, 0x2e41021, 0x9443737c,
-0x2e41021, 0x9448737c, 0x30638000, 0x14600010,
-0x828c0, 0xb71021, 0x9442737e, 0x1447fff5,
-0x1002021, 0xb71021, 0x94437380, 0x96220002,
-0x5462fff1, 0x420c0, 0xb71021, 0x94437382,
-0x96220004, 0x5462ffec, 0x420c0, 0x24060001,
-0x30c200ff, 0x1040023b, 0x0, 0x800361e,
-0x0, 0x97430202, 0x96420000, 0x14620235,
-0x0, 0x97430204, 0x96420002, 0x14620231,
-0x0, 0x97430206, 0x96420004, 0x1462022d,
-0x0, 0x92420000, 0x3a030001, 0x30420001,
-0x431024, 0x10400074, 0x2402ffff, 0x8e230000,
-0x14620004, 0x3402ffff, 0x96230004, 0x1062006f,
-0x24140002, 0x3c020001, 0x571021, 0x904283b2,
-0x1440006a, 0x24140003, 0x92e204d8, 0x14400067,
-0x0, 0x3c020001, 0x571021, 0x8c4283b4,
-0x28420005, 0x10400020, 0x3821, 0x3c020001,
-0x571021, 0x8c4283b4, 0x18400016, 0x2821,
-0x96260000, 0x520c0, 0x971021, 0x9442777e,
-0x14460009, 0x971021, 0x94437780, 0x96220002,
-0x14620005, 0x971021, 0x94437782, 0x96220004,
-0x50620008, 0x24070001, 0x3c020001, 0x571021,
-0x8c4283b4, 0x24a50001, 0xa2102a, 0x5440ffee,
-0x520c0, 0x30e200ff, 0x14400044, 0x24140003,
-0x800384a, 0x0, 0x2402021, 0xc0022fe,
-0x24050006, 0x3044001f, 0x428c0, 0x2e51021,
-0x9442727c, 0x30424000, 0x144001ea, 0xb71021,
-0x9443727e, 0x96220000, 0x1462000b, 0x418c0,
-0xb71021, 0x94437280, 0x96220002, 0x14620006,
-0x418c0, 0xb71021, 0x94437282, 0x96220004,
-0x10620027, 0x418c0, 0x2e31021, 0x9442727c,
-0x30428000, 0x144001d7, 0x2e31021, 0x9448727c,
-0x96270000, 0x828c0, 0xb71021, 0x9442737e,
-0x8003685, 0x3021, 0x420c0, 0x2e41021,
-0x9443737c, 0x2e41021, 0x9448737c, 0x30638000,
-0x14600010, 0x828c0, 0xb71021, 0x9442737e,
-0x1447fff5, 0x1002021, 0xb71021, 0x94437380,
-0x96220002, 0x5462fff1, 0x420c0, 0xb71021,
-0x94437382, 0x96220004, 0x5462ffec, 0x420c0,
-0x24060001, 0x30c200ff, 0x104001b6, 0x0,
-0x8003698, 0x24140003, 0x24140001, 0x8f420260,
-0x53102b, 0x10400049, 0x0, 0x8f8300e4,
-0x8f8200e0, 0x10620003, 0x24630008, 0xaf8300e4,
-0xaf8300e8, 0x8ee400c0, 0x8ee500c4, 0x2601821,
-0x1021, 0xa32821, 0xa3302b, 0x822021,
-0x862021, 0xaee400c0, 0xaee500c4, 0x8ee20058,
-0x24420001, 0xaee20058, 0x8ee20058, 0x8ee2007c,
-0x24420001, 0xaee2007c, 0x8ee2007c, 0x8f8200e0,
-0xafa20010, 0x8f8200e4, 0x3c040001, 0x24845878,
-0xafa20014, 0x8fa60018, 0x8fa7001c, 0x3c050006,
-0xc002403, 0x34a5f003, 0x8003850, 0x0,
-0x8ee25240, 0xafa20010, 0x8ee25244, 0x3c040001,
-0x24845884, 0xafa20014, 0x8ee60e10, 0x8ee70e18,
-0xc002403, 0x34a5f002, 0x8ee201c0, 0x24420001,
-0xaee201c0, 0x8ee20000, 0x8ee301c0, 0x2403ffbf,
-0x431024, 0x80037f8, 0xaee20000, 0x8ee25240,
-0xafa20010, 0x8ee25244, 0x3c040001, 0x24845884,
-0xafa20014, 0x8ee60e10, 0x8ee70e18, 0x3c050006,
-0xc002403, 0x34a5f002, 0x8ee201c0, 0x24420001,
-0xaee201c0, 0x80037f8, 0x8ee201c0, 0x96e20468,
-0x53102b, 0x54400001, 0x3c158000, 0x12600131,
-0x3c0c001f, 0x358cffff, 0x8ee2724c, 0x8f430280,
-0x24420001, 0x304207ff, 0x10620108, 0x0,
-0x12a00014, 0x0, 0x8ee35240, 0x8ee25244,
-0x10620009, 0x26ee5244, 0x8eeb5244, 0x8ee35244,
-0x21140, 0x24425248, 0x2e28021, 0x24630001,
-0x8003712, 0x306800ff, 0x92e27248, 0x1440ffc0,
-0x3c050006, 0x8ee201e0, 0x24420001, 0xaee201e0,
-0x8ee201e0, 0x8ee30e10, 0x8ee20e18, 0x1062ffcb,
-0x26ee0e18, 0x8eeb0e18, 0xa821, 0x8ee30e18,
-0x21140, 0x24420e20, 0x2e28021, 0x24630001,
-0x306801ff, 0x96e2046a, 0x30420010, 0x10400017,
-0x34028100, 0x9643000c, 0x14620014, 0x0,
-0x3c020001, 0x571021, 0x904283c0, 0x1440000f,
-0x0, 0x9642000e, 0xa6020016, 0x8e420008,
-0x8e430004, 0x8e440000, 0x2673fffc, 0xae42000c,
-0xae430008, 0xae440004, 0x9602000e, 0x26310004,
-0x24160001, 0x34420200, 0xa602000e, 0x9603000a,
-0x2605021, 0x73102b, 0x10400002, 0x2606821,
-0x605021, 0x2d42003d, 0x1040002a, 0x3821,
-0x9623000c, 0x24020800, 0x54620027, 0xae110018,
-0x3c020001, 0x571021, 0x904283c0, 0x54400022,
-0xae110018, 0x26220017, 0x182102b, 0x10400013,
-0x0, 0x3c02fff5, 0x511021, 0x90421017,
-0x38430006, 0x2c630001, 0x38420011, 0x2c420001,
-0x621825, 0x10600013, 0x26220010, 0x182102b,
-0x1040000e, 0x0, 0x3c07fff5, 0xf13821,
-0x94e71010, 0x800375e, 0x24e7000e, 0x92220017,
-0x38430006, 0x2c630001, 0x38420011, 0x2c420001,
-0x621825, 0x50600004, 0xae110018, 0x96270010,
-0x24e7000e, 0xae110018, 0x3c020001, 0x571021,
-0x904283c0, 0x2102b, 0x14e00002, 0x24ec0,
-0x1403821, 0x8f830120, 0x27623800, 0x24660020,
-0xc2102b, 0x50400001, 0x27663000, 0x8f820128,
-0x10c20004, 0x0, 0x8f820124, 0x14c20007,
-0x2402000b, 0x8ee201a4, 0x4821, 0x24420001,
-0xaee201a4, 0x80037bf, 0x8ee201a4, 0x8e040000,
-0x8e050004, 0xac620018, 0x1751025, 0x491025,
-0xac710008, 0xa467000e, 0xac62001c, 0xac640000,
-0xac650004, 0x8ee204c0, 0xac620010, 0xaf860120,
-0x92e24e20, 0x14400038, 0x24090001, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0x8c830000,
-0x24020007, 0x14620020, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001c, 0x0, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee34e34, 0x8ee54e30,
-0x24020040, 0x24630001, 0x10620007, 0x0,
-0x8ee24e34, 0x24420001, 0x10a20005, 0x0,
-0x80037a9, 0x0, 0x14a00005, 0x0,
-0x8f820128, 0x24420020, 0xaf820128, 0x8f820128,
-0x8c820004, 0x2c420011, 0x50400013, 0xac800000,
-0x80037bf, 0x0, 0x8ee24e30, 0x24030040,
-0x24420001, 0x50430003, 0x1021, 0x8ee24e30,
-0x24420001, 0xaee24e30, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x24020007, 0xac820000,
-0x24020001, 0xac820004, 0x15200018, 0x3c050006,
-0x8e020018, 0x3c040001, 0x24845890, 0xafa20010,
-0x8e020000, 0x8e030004, 0x34a5f009, 0x2003021,
-0xc002403, 0xafa30014, 0x32c200ff, 0x1040002b,
-0x34028100, 0x8e430004, 0x8e440008, 0x8e45000c,
-0xa642000c, 0xae430000, 0xae440004, 0xae450008,
-0x96020016, 0x80037f8, 0xa642000e, 0x154d000a,
-0x0, 0x9602000e, 0xa613000a, 0x34420004,
-0xa602000e, 0x3c010001, 0x370821, 0xa02083c0,
-0x80037f6, 0x9821, 0x9604000a, 0x93102b,
-0x10400002, 0x2601821, 0x801821, 0x24020001,
-0xa603000a, 0x3c010001, 0x370821, 0xa02283c0,
-0x9604000a, 0x2248821, 0x191102b, 0x10400003,
-0x3c02fff5, 0x34421000, 0x2228821, 0x2649823,
-0xa821, 0x1660fef4, 0xadc80000, 0x12600021,
-0x32c200ff, 0x3c010001, 0x370821, 0xac3383c4,
-0x3c010001, 0x370821, 0xac3183c8, 0x3c010001,
-0x370821, 0x10400008, 0xac3283cc, 0x3c020001,
-0x571021, 0x8c4283cc, 0x24420004, 0x3c010001,
-0x370821, 0xac2283cc, 0x8ee2724c, 0x8f430280,
-0x24420001, 0x14620006, 0x0, 0x8ee201c4,
-0x24420001, 0xaee201c4, 0x8003850, 0x8ee201c4,
-0x8ee201bc, 0x24420001, 0xaee201bc, 0x8003850,
-0x8ee201bc, 0x97a4001e, 0x2484fffc, 0x801821,
-0x8ee400c0, 0x8ee500c4, 0x1021, 0xa32821,
-0xa3302b, 0x822021, 0x862021, 0x24020002,
-0xaee400c0, 0xaee500c4, 0x1282000f, 0x2a820003,
-0x14400017, 0x24020003, 0x16820015, 0x0,
-0x8ee200d0, 0x8ee300d4, 0x24630001, 0x2c640001,
-0x441021, 0xaee200d0, 0xaee300d4, 0x8ee200d0,
-0x800384a, 0x8ee300d4, 0x8ee200d8, 0x8ee300dc,
-0x24630001, 0x2c640001, 0x441021, 0xaee200d8,
-0xaee300dc, 0x8ee200d8, 0x800384a, 0x8ee300dc,
-0x8ee200c8, 0x8ee300cc, 0x24630001, 0x2c640001,
-0x441021, 0xaee200c8, 0xaee300cc, 0x8ee200c8,
-0x8ee300cc, 0x8f8300e4, 0x8f8200e0, 0x10620003,
-0x24630008, 0xaf8300e4, 0xaf8300e8, 0x8fbf004c,
-0x8fb60048, 0x8fb50044, 0x8fb40040, 0x8fb3003c,
-0x8fb20038, 0x8fb10034, 0x8fb00030, 0x3e00008,
-0x27bd0050, 0x27bdff90, 0xafb60060, 0xb021,
-0xafbf0068, 0xafbe0064, 0xafb5005c, 0xafb40058,
-0xafb30054, 0xafb20050, 0xafb1004c, 0xafb00048,
-0x8ee204d4, 0x8821, 0x24150001, 0x30420001,
-0x1440002a, 0xa3a0002f, 0x8f8700e0, 0x8f8800c4,
-0x8f8200e8, 0xe22023, 0x2c821000, 0x50400001,
-0x24841000, 0x420c2, 0x801821, 0x8ee400c8,
-0x8ee500cc, 0x1021, 0xa32821, 0xa3302b,
-0x822021, 0x862021, 0xaee400c8, 0xaee500cc,
-0x8f8300c8, 0x3c02000a, 0x3442efff, 0x1032023,
-0x44102b, 0x10400003, 0x3c02000a, 0x3442f000,
-0x822021, 0x801821, 0x8ee400c0, 0x8ee500c4,
-0x1021, 0xa32821, 0xa3302b, 0x822021,
-0x862021, 0xaee400c0, 0xaee500c4, 0xaf8800c8,
-0xaf8700e4, 0x8003c5b, 0xaf8700e8, 0x3c020001,
-0x571021, 0x904283c0, 0x1040000b, 0x0,
-0x3c130001, 0x2779821, 0x8e7383c4, 0x3c100001,
-0x2178021, 0x8e1083c8, 0x3c120001, 0x2579021,
-0x8003a59, 0x8e5283cc, 0x8f8300e0, 0x8f8200e4,
-0x10430007, 0x3821, 0x8f8200e4, 0x24070001,
-0x8c430000, 0x8c440004, 0xafa30018, 0xafa4001c,
-0x14e0000e, 0x3c02ffff, 0x8f8200c4, 0xafa20010,
-0x8f8200c8, 0x3c040001, 0x248458b4, 0xafa20014,
-0x8f8600e0, 0x8f8700e4, 0x3c050006, 0xc002403,
-0x34a5f200, 0x8003c5b, 0x0, 0x8fa3001c,
-0x8fb20018, 0x3073ffff, 0x2673fffc, 0x621024,
-0x10400058, 0x2408021, 0x3c020080, 0x621024,
-0x1040000a, 0x3c040040, 0x8ee2007c, 0x24420001,
-0xaee2007c, 0x8ee2007c, 0x8ee201fc, 0x24420001,
-0xaee201fc, 0x8003c55, 0x8ee201fc, 0x3c060004,
-0x3c0b0001, 0x3c0a0002, 0x3c050010, 0x3c090008,
-0x8ee20080, 0x3c080020, 0x34078000, 0x24420001,
-0xaee20080, 0x8ee20080, 0x8fa2001c, 0x441824,
-0x10660021, 0xc3102b, 0x14400007, 0x0,
-0x106b0011, 0x0, 0x106a0015, 0x0,
-0x8003916, 0x42042, 0x10650023, 0xa3102b,
-0x14400005, 0x0, 0x10690019, 0x0,
-0x8003916, 0x42042, 0x10680021, 0x0,
-0x8003916, 0x42042, 0x8ee20034, 0x24420001,
-0xaee20034, 0x8ee20034, 0x8003916, 0x42042,
-0x8ee201ec, 0x24420001, 0xaee201ec, 0x8ee201ec,
-0x8003916, 0x42042, 0x8ee201f0, 0x24420001,
-0xaee201f0, 0x8ee201f0, 0x8003916, 0x42042,
-0x8ee201f4, 0x24420001, 0xaee201f4, 0x8ee201f4,
-0x8003916, 0x42042, 0x8ee20030, 0x24420001,
-0xaee20030, 0x8ee20030, 0x8003916, 0x42042,
-0x8ee201f8, 0x24420001, 0xaee201f8, 0x8ee201f8,
-0x42042, 0x1087033e, 0x0, 0x80038db,
-0x0, 0x3c020001, 0x571021, 0x904283b2,
-0x14400084, 0x24020001, 0x3c030001, 0x771821,
-0x906383b3, 0x1462007f, 0x3c020100, 0x8e430000,
-0x621024, 0x1040006f, 0x2402ffff, 0x14620005,
-0x24110001, 0x96430004, 0x3402ffff, 0x10620075,
-0x0, 0x92e204d8, 0x14400072, 0x0,
-0x3c020001, 0x571021, 0x8c4283b4, 0x28420005,
-0x10400020, 0x3821, 0x3c020001, 0x571021,
-0x8c4283b4, 0x18400016, 0x2821, 0x96060000,
-0x520c0, 0x971021, 0x9442777e, 0x14460009,
-0x971021, 0x94437780, 0x96020002, 0x14620005,
-0x971021, 0x94437782, 0x96020004, 0x50620008,
-0x24070001, 0x3c020001, 0x571021, 0x8c4283b4,
-0x24a50001, 0xa2102a, 0x5440ffee, 0x520c0,
-0x30e200ff, 0x10400302, 0x0, 0x80039a2,
-0x0, 0x2402021, 0xc0022fe, 0x24050006,
-0x3044001f, 0x428c0, 0x2e51021, 0x9442727c,
-0x30424000, 0x144002f6, 0xb71021, 0x9443727e,
-0x96020000, 0x1462000b, 0x418c0, 0xb71021,
-0x94437280, 0x96020002, 0x14620006, 0x418c0,
-0xb71021, 0x94437282, 0x96020004, 0x10620035,
-0x418c0, 0x2e31021, 0x9442727c, 0x30428000,
-0x144002e3, 0x2e31021, 0x944d727c, 0x96070000,
-0xd28c0, 0xb71021, 0x9442737e, 0x8003984,
-0x3021, 0x420c0, 0x2e41021, 0x9443737c,
-0x2e41021, 0x944d737c, 0x30638000, 0x14600010,
-0xd28c0, 0xb71021, 0x9442737e, 0x1447fff5,
-0x1a02021, 0xb71021, 0x94437380, 0x96020002,
-0x5462fff1, 0x420c0, 0xb71021, 0x94437382,
-0x96020004, 0x5462ffec, 0x420c0, 0x24060001,
-0x30c200ff, 0x104002c2, 0x0, 0x80039a2,
-0x0, 0x97430202, 0x96420000, 0x146202bc,
-0x0, 0x97430204, 0x96420002, 0x146202b8,
-0x0, 0x97430206, 0x96420004, 0x146202b4,
-0x0, 0x92420000, 0x3a230001, 0x30420001,
-0x431024, 0x10400074, 0x2402ffff, 0x8e030000,
-0x14620004, 0x3402ffff, 0x96030004, 0x1062006f,
-0x24150002, 0x3c020001, 0x571021, 0x904283b2,
-0x1440006a, 0x24150003, 0x92e204d8, 0x14400067,
-0x0, 0x3c020001, 0x571021, 0x8c4283b4,
-0x28420005, 0x10400020, 0x3821, 0x3c020001,
-0x571021, 0x8c4283b4, 0x18400016, 0x2821,
-0x96060000, 0x520c0, 0x971021, 0x9442777e,
-0x14460009, 0x971021, 0x94437780, 0x96020002,
-0x14620005, 0x971021, 0x94437782, 0x96020004,
-0x50620008, 0x24070001, 0x3c020001, 0x571021,
-0x8c4283b4, 0x24a50001, 0xa2102a, 0x5440ffee,
-0x520c0, 0x30e200ff, 0x14400044, 0x24150003,
-0x8003c55, 0x0, 0x2402021, 0xc0022fe,
-0x24050006, 0x3044001f, 0x428c0, 0x2e51021,
-0x9442727c, 0x30424000, 0x14400271, 0xb71021,
-0x9443727e, 0x96020000, 0x1462000b, 0x418c0,
-0xb71021, 0x94437280, 0x96020002, 0x14620006,
-0x418c0, 0xb71021, 0x94437282, 0x96020004,
-0x10620027, 0x418c0, 0x2e31021, 0x9442727c,
-0x30428000, 0x1440025e, 0x2e31021, 0x944d727c,
-0x96070000, 0xd28c0, 0xb71021, 0x9442737e,
-0x8003a09, 0x3021, 0x420c0, 0x2e41021,
-0x9443737c, 0x2e41021, 0x944d737c, 0x30638000,
-0x14600010, 0xd28c0, 0xb71021, 0x9442737e,
-0x1447fff5, 0x1a02021, 0xb71021, 0x94437380,
-0x96020002, 0x5462fff1, 0x420c0, 0xb71021,
-0x94437382, 0x96020004, 0x5462ffec, 0x420c0,
-0x24060001, 0x30c200ff, 0x1040023d, 0x0,
-0x8003a1c, 0x24150003, 0x24150001, 0x8f420260,
-0x53102b, 0x10400036, 0x0, 0x8f8300e4,
-0x8f8200e0, 0x10620003, 0x24630008, 0xaf8300e4,
-0xaf8300e8, 0x8ee400c0, 0x8ee500c4, 0x2601821,
-0x1021, 0xa32821, 0xa3302b, 0x822021,
-0x862021, 0xaee400c0, 0xaee500c4, 0x8ee20058,
-0x24420001, 0xaee20058, 0x8ee20058, 0x8ee2007c,
-0x24420001, 0xaee2007c, 0x8ee2007c, 0x8f8200e0,
-0xafa20010, 0x8f8200e4, 0x3c040001, 0x248458c0,
-0xafa20014, 0x8fa60018, 0x8fa7001c, 0x3c050006,
-0xc002403, 0x34a5f203, 0x8003c5b, 0x0,
-0x8ee25240, 0xafa20010, 0x8ee25244, 0x3c040001,
-0x248458cc, 0xafa20014, 0x8ee60e10, 0x8ee70e18,
-0x3c050006, 0xc002403, 0x34a5f202, 0x8ee201c0,
-0x24420001, 0xaee201c0, 0x8003c02, 0x8ee201c0,
-0x96e20468, 0x53102b, 0x54400001, 0x3c168000,
-0x126001cb, 0x3c0e001f, 0x35ceffff, 0x3c0ffff5,
-0x35ef1000, 0x241e0040, 0x8ee2724c, 0x8f430280,
-0x24420001, 0x304207ff, 0x1062019e, 0x0,
-0x12c00012, 0x0, 0x8ee35240, 0x8ee25244,
-0x1062000a, 0x26f85244, 0x8ef45244, 0xafb80024,
-0x8ee35244, 0x21140, 0x24425248, 0x2e28821,
-0x24630001, 0x8003a85, 0x306d00ff, 0x8ee201e0,
-0x24420001, 0xaee201e0, 0x8ee201e0, 0x8ee30e10,
-0x8ee20e18, 0x1062ffca, 0x26f80e18, 0x8ef40e18,
-0xb021, 0xafb80024, 0x8ee30e18, 0x21140,
-0x24420e20, 0x2e28821, 0x24630001, 0x306d01ff,
-0x96e2046a, 0x30420010, 0x10400018, 0x34028100,
-0x9643000c, 0x14620015, 0x0, 0x3c020001,
-0x571021, 0x904283c0, 0x14400010, 0x0,
-0x9642000e, 0xa6220016, 0x8e420008, 0x8e430004,
-0x8e440000, 0x2673fffc, 0xae42000c, 0xae430008,
-0xae440004, 0x9622000e, 0x26100004, 0x24180001,
-0xa3b8002f, 0x34420200, 0xa622000e, 0x8e220000,
-0x8e230004, 0x3c040001, 0x34843800, 0x2003021,
-0x306a0007, 0x20a8023, 0x3641021, 0x202102b,
-0x10400005, 0x26a9821, 0x2041023, 0x3621823,
-0x3c020020, 0x438023, 0x26620007, 0x9623000a,
-0x2418fff8, 0x58c824, 0x6a1821, 0x79102b,
-0x10400002, 0x3206021, 0x606021, 0x1801821,
-0x24620007, 0x2418fff8, 0x586024, 0x26c102b,
-0x14400004, 0x1932823, 0x1832823, 0x8003ac3,
-0xc31021, 0xd31021, 0x4a2023, 0x1c4102b,
-0x54400001, 0x8f2021, 0x25420040, 0x4c102b,
-0x14400035, 0x5821, 0x94c3000c, 0x24020800,
-0x54620032, 0xae260018, 0x3c020001, 0x571021,
-0x904283c0, 0x5440002d, 0xae260018, 0x24c20017,
-0x1c2102b, 0x10400013, 0x0, 0x3c02fff5,
-0x461021, 0x90421017, 0x38430006, 0x2c630001,
-0x38420011, 0x2c420001, 0x621825, 0x10600014,
-0x24c20010, 0x1c2102b, 0x1040000e, 0x0,
-0x3c0bfff5, 0x1665821, 0x956b1010, 0x8003af4,
-0x2562000e, 0x90c20017, 0x38430006, 0x2c630001,
-0x38420011, 0x2c420001, 0x621825, 0x10600005,
-0x1601821, 0x94cb0010, 0x2562000e, 0x4a5821,
-0x1601821, 0x24620007, 0x2418fff8, 0x585824,
-0xc31021, 0x4a2023, 0x1c4102b, 0x10400002,
-0x1632823, 0x8f2021, 0xae260018, 0x3c020001,
-0x571021, 0x904283c0, 0x2102b, 0x216c0,
-0x15600002, 0xafa20044, 0x1805821, 0x30820001,
-0x10400007, 0x4021, 0x90880000, 0x24840001,
-0x1c4102b, 0x10400002, 0x24a5ffff, 0x8f2021,
-0x50a00012, 0x81c02, 0x2ca20002, 0x54400009,
-0x24a5ffff, 0x94820000, 0x24840002, 0x1024021,
-0x1c4102b, 0x10400006, 0x24a5fffe, 0x8003b21,
-0x8f2021, 0x90820000, 0x21200, 0x1024021,
-0x14a0fff2, 0x2ca20002, 0x81c02, 0x3102ffff,
-0x624021, 0x3108ffff, 0x1402821, 0x11400011,
-0x2002021, 0x2ca20002, 0x54400009, 0x24a5ffff,
-0x94820000, 0x24840002, 0x1024021, 0x1c4102b,
-0x10400006, 0x24a5fffe, 0x8003b38, 0x8f2021,
-0x90820000, 0x21200, 0x1024021, 0x14a0fff2,
-0x2ca20002, 0x81c02, 0x3102ffff, 0x624021,
-0x81c02, 0x3102ffff, 0x8f890120, 0x624021,
-0x27623800, 0x25230020, 0x62102b, 0x14400002,
-0x3108ffff, 0x27633000, 0x8f820128, 0x10620004,
-0x0, 0x8f820124, 0x14620007, 0x1402821,
-0x8ee201a4, 0x3821, 0x24420001, 0xaee201a4,
-0x8003bc9, 0x8ee201a4, 0x8e260000, 0x8e270004,
-0x81400, 0x3448000b, 0xad300008, 0xa52b000e,
-0xad280018, 0x8fb80044, 0x2021, 0x2961025,
-0x581025, 0xad22001c, 0xe5102b, 0xe53823,
-0xc43023, 0xc23023, 0xad260000, 0xad270004,
-0x8ee204c0, 0xad220010, 0xaf830120, 0x92e24e20,
-0x1440005f, 0x24070001, 0x2502ffee, 0x2c420002,
-0x14400003, 0x24020011, 0x15020024, 0x0,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x8c830000, 0x24020012, 0x1462000f, 0x0,
-0x8ee34e30, 0x8ee24e34, 0x1062000b, 0x0,
-0x8c820004, 0x24420001, 0xac820004, 0x8ee24e34,
-0x8ee34e30, 0x24420001, 0x105e002a, 0x0,
-0x8003ba8, 0x0, 0x8ee24e30, 0x24420001,
-0x505e0003, 0x1021, 0x8ee24e30, 0x24420001,
-0xaee24e30, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x8003bc6, 0x24020012, 0x8ee24e30,
-0x210c0, 0x24425038, 0x2e22021, 0x8c830000,
-0x24020007, 0x1462001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x0, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee34e30,
-0x24420001, 0x105e0007, 0x0, 0x8ee24e34,
-0x24420001, 0x10620005, 0x0, 0x8003bb4,
-0x0, 0x14600005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400012, 0xac800000, 0x8003bc9,
-0x0, 0x8ee24e30, 0x24420001, 0x505e0003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x24020007, 0xac820000, 0x24020001, 0xac820004,
-0x14e00019, 0x3c050006, 0x3c040001, 0x24845890,
-0x8e220018, 0x34a5f209, 0xafa20010, 0x8e220000,
-0x8e230004, 0x2203021, 0x1603821, 0xc002403,
-0xafa30014, 0x93a2002f, 0x1040002a, 0x34028100,
-0x8e430004, 0x8e440008, 0x8e45000c, 0xa642000c,
-0xae430000, 0xae440004, 0xae450008, 0x96220016,
-0x8003c02, 0xa642000e, 0x1599000a, 0x26a1823,
-0x9622000e, 0xa623000a, 0x34420004, 0xa622000e,
-0x3c010001, 0x370821, 0xa02083c0, 0x8003bff,
-0x9821, 0x9624000a, 0x83102b, 0x54400001,
-0x801821, 0x24020001, 0xa623000a, 0x3c010001,
-0x370821, 0xa02283c0, 0x9622000a, 0x4a1821,
-0x2038021, 0x1d0102b, 0x54400001, 0x20f8021,
-0x2639823, 0xb021, 0x8fb80024, 0x1660fe5e,
-0xaf0d0000, 0x12600022, 0x0, 0x3c010001,
-0x370821, 0xac3383c4, 0x3c010001, 0x370821,
-0xac3083c8, 0x3c010001, 0x370821, 0xac3283cc,
-0x93a2002f, 0x10400008, 0x0, 0x3c020001,
-0x571021, 0x8c4283cc, 0x24420004, 0x3c010001,
-0x370821, 0xac2283cc, 0x8f430280, 0x8ee2724c,
-0x14620006, 0x0, 0x8ee201c4, 0x24420001,
-0xaee201c4, 0x8003c5b, 0x8ee201c4, 0x8ee201bc,
-0x24420001, 0xaee201bc, 0x8003c5b, 0x8ee201bc,
-0x97a4001e, 0x2484fffc, 0x801821, 0x8ee400c0,
-0x8ee500c4, 0x1021, 0xa32821, 0xa3302b,
-0x822021, 0x862021, 0x24020002, 0xaee400c0,
-0xaee500c4, 0x12a2000f, 0x2aa20003, 0x14400017,
-0x24020003, 0x16a20015, 0x0, 0x8ee200d0,
-0x8ee300d4, 0x24630001, 0x2c640001, 0x441021,
-0xaee200d0, 0xaee300d4, 0x8ee200d0, 0x8003c55,
-0x8ee300d4, 0x8ee200d8, 0x8ee300dc, 0x24630001,
-0x2c640001, 0x441021, 0xaee200d8, 0xaee300dc,
-0x8ee200d8, 0x8003c55, 0x8ee300dc, 0x8ee200c8,
-0x8ee300cc, 0x24630001, 0x2c640001, 0x441021,
-0xaee200c8, 0xaee300cc, 0x8ee200c8, 0x8ee300cc,
-0x8f8300e4, 0x8f8200e0, 0x10620003, 0x24630008,
-0xaf8300e4, 0xaf8300e8, 0x8fbf0068, 0x8fbe0064,
-0x8fb60060, 0x8fb5005c, 0x8fb40058, 0x8fb30054,
-0x8fb20050, 0x8fb1004c, 0x8fb00048, 0x3e00008,
-0x27bd0070, 0x27bdffe0, 0xafbf0018, 0x8ee30e14,
-0x8ee20e0c, 0x10620074, 0x0, 0x8ee30e0c,
-0x8ee20e14, 0x622023, 0x4820001, 0x24840200,
-0x8ee30e18, 0x8ee20e14, 0x43102b, 0x14400004,
-0x24020200, 0x8ee30e14, 0x8003c7d, 0x431823,
-0x8ee20e18, 0x8ee30e14, 0x431023, 0x2443ffff,
-0x804821, 0x69102a, 0x54400001, 0x604821,
-0x8f870100, 0x27623000, 0x24e80020, 0x102102b,
-0x50400001, 0x27682800, 0x8f820108, 0x11020004,
-0x0, 0x8f820104, 0x15020007, 0x1021,
-0x8ee201a8, 0x2021, 0x24420001, 0xaee201a8,
-0x8003cbf, 0x8ee201a8, 0x8ee40e14, 0x42140,
-0x801821, 0x8ee40460, 0x8ee50464, 0xa32821,
-0xa3302b, 0x822021, 0x862021, 0xace40000,
-0xace50004, 0x8ee30e14, 0x91140, 0xa4e2000e,
-0x24020002, 0xace20018, 0x31940, 0x24630e20,
-0x2e31021, 0xace20008, 0x8ee20e14, 0xace2001c,
-0x8ee204cc, 0xace20010, 0xaf880100, 0x92e204ec,
-0x14400011, 0x24040001, 0x8ee24e28, 0x24030040,
-0x24420001, 0x50430003, 0x1021, 0x8ee24e28,
-0x24420001, 0xaee24e28, 0x8ee24e28, 0x210c0,
-0x24424e38, 0x2e21821, 0x24020002, 0xac620000,
-0x24020001, 0xac620004, 0x1480000e, 0x24030040,
-0x8ee20e14, 0xafa20010, 0x8ee20e18, 0x3c050007,
-0xafa20014, 0x8ee60e0c, 0x8ee70e10, 0x3c040001,
-0x248458d4, 0xc002403, 0x34a5f001, 0x8003cdd,
-0x0, 0x8ee20500, 0x24420001, 0x50430003,
-0x1021, 0x8ee20500, 0x24420001, 0xaee20500,
-0x8ee20500, 0x21080, 0x571021, 0xac490508,
-0x8ee20e14, 0x491021, 0x304201ff, 0xaee20e14,
-0x8ee30e14, 0x8ee20e0c, 0x14620005, 0x0,
-0x8f820060, 0x2403fdff, 0x431024, 0xaf820060,
-0x8fbf0018, 0x3e00008, 0x27bd0020, 0x27bdffe0,
-0xafbf0018, 0x8ee3523c, 0x8ee25238, 0x10620074,
-0x0, 0x8ee35238, 0x8ee2523c, 0x622023,
-0x4820001, 0x24840100, 0x8ee35244, 0x8ee2523c,
-0x43102b, 0x14400004, 0x24020100, 0x8ee3523c,
-0x8003cff, 0x431823, 0x8ee25244, 0x8ee3523c,
-0x431023, 0x2443ffff, 0x804821, 0x69102a,
-0x54400001, 0x604821, 0x8f870100, 0x27623000,
-0x24e80020, 0x102102b, 0x50400001, 0x27682800,
-0x8f820108, 0x11020004, 0x0, 0x8f820104,
-0x15020007, 0x1021, 0x8ee201a8, 0x2021,
-0x24420001, 0xaee201a8, 0x8003d41, 0x8ee201a8,
-0x8ee4523c, 0x42140, 0x801821, 0x8ee40470,
-0x8ee50474, 0xa32821, 0xa3302b, 0x822021,
-0x862021, 0xace40000, 0xace50004, 0x8ee3523c,
-0x91140, 0xa4e2000e, 0x24020003, 0xace20018,
-0x31940, 0x24635248, 0x2e31021, 0xace20008,
-0x8ee2523c, 0xace2001c, 0x8ee204cc, 0xace20010,
-0xaf880100, 0x92e204ec, 0x14400011, 0x24040001,
-0x8ee24e28, 0x24030040, 0x24420001, 0x50430003,
-0x1021, 0x8ee24e28, 0x24420001, 0xaee24e28,
-0x8ee24e28, 0x210c0, 0x24424e38, 0x2e21821,
-0x24020003, 0xac620000, 0x24020001, 0xac620004,
-0x1480000e, 0x24030040, 0x8ee2523c, 0xafa20010,
-0x8ee25244, 0x3c050007, 0xafa20014, 0x8ee65238,
-0x8ee75240, 0x3c040001, 0x248458e0, 0xc002403,
-0x34a5f010, 0x8003d5f, 0x0, 0x8ee20500,
-0x24420001, 0x50430003, 0x1021, 0x8ee20500,
-0x24420001, 0xaee20500, 0x8ee20500, 0x21080,
-0x571021, 0xac490508, 0x8ee2523c, 0x491021,
-0x304200ff, 0xaee2523c, 0x8ee3523c, 0x8ee25238,
-0x14620005, 0x0, 0x8f820060, 0x2403feff,
-0x431024, 0xaf820060, 0x8fbf0018, 0x3e00008,
-0x27bd0020, 0x8f820120, 0x8ee34e34, 0x8f820124,
-0x8f860128, 0x24020040, 0x24630001, 0x50620003,
-0x1021, 0x8ee24e34, 0x24420001, 0xaee24e34,
-0x8ee24e34, 0x8ee44e34, 0x8ee34e30, 0x210c0,
-0x24425038, 0x14830007, 0x2e22821, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8003d92,
-0xaca00000, 0x8ee24e34, 0x24030040, 0x24420001,
-0x50430003, 0x1021, 0x8ee24e34, 0x24420001,
-0x210c0, 0x24425038, 0x2e22821, 0x8ca20004,
-0x8f830128, 0x21140, 0x621821, 0xaf830128,
-0xaca00000, 0x8cc20018, 0x2443fffe, 0x2c620012,
-0x10400008, 0x31080, 0x3c010001, 0x220821,
-0x8c2258f0, 0x400008, 0x0, 0x24020001,
-0xaee24e24, 0x3e00008, 0x0, 0x27bdffc8,
-0xafbf0030, 0xafb5002c, 0xafb40028, 0xafb30024,
-0xafb20020, 0xafb1001c, 0xafb00018, 0x8f830128,
-0x8f820124, 0x106202b0, 0x9821, 0x3c11001f,
-0x3631ffff, 0x3c12fff5, 0x36521000, 0x24150012,
-0x24140040, 0x8f8c0128, 0x8f820128, 0x24420020,
-0xaf820128, 0x9182001b, 0x8f830128, 0x2443fffe,
-0x2c620012, 0x1040029c, 0x31080, 0x3c010001,
-0x220821, 0x8c225948, 0x400008, 0x0,
-0x8f420218, 0x30420100, 0x10400007, 0x0,
-0x95830016, 0x95820018, 0x621823, 0x31402,
-0x431021, 0xa5820016, 0x8d82001c, 0x3c038000,
-0x3044ffff, 0x436824, 0x3c030800, 0x431824,
-0x11a00004, 0xad84001c, 0x41140, 0x8003dd8,
-0x24425248, 0x41140, 0x24420e20, 0x2e25821,
-0x9562000e, 0x3042fffc, 0x10600004, 0xa562000e,
-0x95840016, 0x8003ec0, 0x0, 0x8d690018,
-0x4021, 0x952a0000, 0x25290002, 0x95270000,
-0x25290002, 0x95260000, 0x25290002, 0x95250000,
-0x25290002, 0x95240000, 0x25290002, 0x95230000,
-0x25290002, 0x95220000, 0x25290002, 0x1475021,
-0x1465021, 0x1455021, 0x1445021, 0x1435021,
-0x1425021, 0xa1c02, 0x3142ffff, 0x625021,
-0xa1c02, 0x3142ffff, 0x625021, 0x96e2046a,
-0x314effff, 0x30420002, 0x10400044, 0x5021,
-0x25220014, 0x222102b, 0x10400014, 0x1201821,
-0x2405000a, 0x2021, 0x223102b, 0x54400001,
-0x721821, 0x94620000, 0x24630002, 0x24a5ffff,
-0x14a0fff9, 0x822021, 0x41c02, 0x3082ffff,
-0x622021, 0x41402, 0x3083ffff, 0x431021,
-0x3042ffff, 0x8003e33, 0x1425021, 0x952a0000,
-0x25290002, 0x95280000, 0x25290002, 0x95270000,
-0x25290002, 0x95260000, 0x25290002, 0x95250000,
-0x25290002, 0x95230000, 0x25290002, 0x95220000,
-0x25290002, 0x95240000, 0x25290002, 0x1485021,
-0x1475021, 0x1465021, 0x1455021, 0x1435021,
-0x1425021, 0x95220000, 0x95230002, 0x1445021,
-0x1425021, 0x1435021, 0xa1c02, 0x3142ffff,
-0x625021, 0xa1c02, 0x3142ffff, 0x625021,
-0x3148ffff, 0x51000001, 0x3408ffff, 0x8d620018,
-0x9443000c, 0x24020800, 0x54620005, 0xa5680010,
-0x9562000e, 0x34420002, 0xa562000e, 0xa5680010,
-0x96e2046a, 0x2821, 0x30420008, 0x14400056,
-0x3021, 0x8d630018, 0x24620024, 0x222102b,
-0x10400034, 0x24690010, 0x229102b, 0x54400001,
-0x1324821, 0x95250000, 0x24690014, 0x229102b,
-0x10400002, 0x24a5ffec, 0x1324821, 0x95220000,
-0x30420fff, 0x14400003, 0x25290002, 0x8003e60,
-0x24130001, 0x9821, 0xa03021, 0x229102b,
-0x54400001, 0x1324821, 0x91220001, 0x25290002,
-0xa22821, 0x229102b, 0x54400001, 0x1324821,
-0x25290002, 0x229102b, 0x54400001, 0x1324821,
-0x95220000, 0x25290002, 0xa22821, 0x229102b,
-0x54400001, 0x1324821, 0x95220000, 0x25290002,
-0xa22821, 0x229102b, 0x54400001, 0x1324821,
-0x95220000, 0x25290002, 0xa22821, 0x229102b,
-0x54400001, 0x1324821, 0x95220000, 0x8003e99,
-0xa22821, 0x94650010, 0x94620014, 0x24690016,
-0x30420fff, 0x14400003, 0x24a5ffec, 0x8003e8c,
-0x24130001, 0x9821, 0xa03021, 0x91230001,
-0x25290004, 0x95220000, 0x25290002, 0x95240000,
-0x25290002, 0xa32821, 0xa22821, 0x95220000,
-0x95230002, 0xa42821, 0xa22821, 0xa32821,
-0x51c02, 0x30a2ffff, 0x622821, 0x51c02,
-0x30a2ffff, 0x622821, 0x96e2046a, 0x30420001,
-0x1040001e, 0x2021, 0x95820016, 0x4e2023,
-0x41402, 0x822021, 0x326200ff, 0x50400002,
-0x862021, 0x852021, 0x41402, 0x822021,
-0x3084ffff, 0x50800001, 0x3404ffff, 0x8d620018,
-0x24430017, 0x223102b, 0x54400001, 0x721821,
-0x90620000, 0x38430011, 0x2c630001, 0x38420006,
-0x2c420001, 0x621825, 0x10600004, 0x0,
-0x9562000e, 0x34420001, 0xa562000e, 0x9562000e,
-0x240a0002, 0x30420004, 0x10400002, 0xa5640012,
-0x240a0004, 0x8f880120, 0x27623800, 0x25090020,
-0x122102b, 0x50400001, 0x27693000, 0x8f820128,
-0x11220004, 0x0, 0x8f820124, 0x15220007,
-0x24040020, 0x8ee201a4, 0x8021, 0x24420001,
-0xaee201a4, 0x8003f4f, 0x8ee201a4, 0x8ee5724c,
-0x8ee60490, 0x8ee70494, 0xad0b0008, 0xa504000e,
-0xad0a0018, 0x52940, 0xa01821, 0x1021,
-0xe33821, 0xe3202b, 0xc23021, 0xc43021,
-0xad060000, 0xad070004, 0x8ee2724c, 0x4d1025,
-0xad02001c, 0x8ee204c4, 0xad020010, 0xaf890120,
-0x92e24e20, 0x14400060, 0x24100001, 0x2543ffee,
-0x2c630002, 0x39420011, 0x2c420001, 0x621825,
-0x10600024, 0x0, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x8c820000, 0x1455000f,
-0x0, 0x8ee34e30, 0x8ee24e34, 0x1062000b,
-0x0, 0x8c820004, 0x24420001, 0xac820004,
-0x8ee24e34, 0x8ee34e30, 0x24420001, 0x1054002b,
-0x0, 0x8003f2e, 0x0, 0x8ee24e30,
-0x24420001, 0x50540003, 0x1021, 0x8ee24e30,
-0x24420001, 0xaee24e30, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x24020001, 0x8003f4e,
-0xac950000, 0x8ee24e30, 0x210c0, 0x24425038,
-0x2e22021, 0x8c830000, 0x24020007, 0x1462001f,
-0x0, 0x8ee34e30, 0x8ee24e34, 0x1062001b,
-0x0, 0x8c820004, 0x24420001, 0xac820004,
-0x8ee24e34, 0x8ee34e30, 0x24420001, 0x10540007,
-0x0, 0x8ee24e34, 0x24420001, 0x10620005,
-0x0, 0x8003f3a, 0x0, 0x14600005,
-0x0, 0x8f820128, 0x24420020, 0xaf820128,
-0x8f820128, 0x8c820004, 0x2c420011, 0x50400012,
-0xac800000, 0x8003f4f, 0x0, 0x8ee24e30,
-0x24420001, 0x50540003, 0x1021, 0x8ee24e30,
-0x24420001, 0xaee24e30, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x24020007, 0xac820000,
-0x24020001, 0xac820004, 0x1600000d, 0x0,
-0x8f820120, 0x3c040001, 0x24845938, 0xafa00014,
-0xafa20010, 0x8d86001c, 0x8f870124, 0x3c050008,
-0xc002403, 0x34a50001, 0x8004057, 0x0,
-0x8ee2724c, 0x24420001, 0x304207ff, 0x11a00006,
-0xaee2724c, 0x8ee201d0, 0x2442ffff, 0xaee201d0,
-0x8003f6b, 0x8ee201d0, 0x8ee201cc, 0x2442ffff,
-0xaee201cc, 0x8ee201cc, 0x8ee201d8, 0x2442ffff,
-0xaee201d8, 0x8004057, 0x8ee201d8, 0x8f420240,
-0x104000e5, 0x0, 0x8ee20e1c, 0x24420001,
-0x8004057, 0xaee20e1c, 0x9582001e, 0xad82001c,
-0x8f420240, 0x10400072, 0x0, 0x8ee20e1c,
-0x24420001, 0xaee20e1c, 0x8f430240, 0x43102b,
-0x144000d5, 0x0, 0x8f830120, 0x27623800,
-0x24660020, 0xc2102b, 0x50400001, 0x27663000,
-0x8f820128, 0x10c20004, 0x0, 0x8f820124,
-0x14c20007, 0x0, 0x8ee201a4, 0x8021,
-0x24420001, 0xaee201a4, 0x8003fda, 0x8ee201a4,
-0x8ee2724c, 0xac62001c, 0x8ee404a8, 0x8ee504ac,
-0x2462001c, 0xac620008, 0x24020008, 0xa462000e,
-0x24020011, 0xac620018, 0xac640000, 0xac650004,
-0x8ee204c4, 0xac620010, 0xaf860120, 0x92e24e20,
-0x14400034, 0x24100001, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x8c820000, 0x1455001f,
-0x0, 0x8ee34e30, 0x8ee24e34, 0x1062001b,
-0x0, 0x8c820004, 0x24420001, 0xac820004,
-0x8ee24e34, 0x8ee34e30, 0x24420001, 0x10540007,
-0x0, 0x8ee24e34, 0x24420001, 0x10620005,
-0x0, 0x8003fc6, 0x0, 0x14600005,
-0x0, 0x8f820128, 0x24420020, 0xaf820128,
-0x8f820128, 0x8c820004, 0x2c420011, 0x50400011,
-0xac800000, 0x8003fda, 0x0, 0x8ee24e30,
-0x24420001, 0x50540003, 0x1021, 0x8ee24e30,
-0x24420001, 0xaee24e30, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x24020001, 0xac950000,
-0xac820004, 0x5600000b, 0x24100001, 0x8ee2724c,
-0x3c040001, 0x248458a8, 0xafa00014, 0xafa20010,
-0x8ee6724c, 0x8f470280, 0x3c050009, 0xc002403,
-0x34a5f008, 0x56000001, 0xaee00e1c, 0x8ee20188,
-0x24420001, 0xaee20188, 0x8004050, 0x8ee20188,
-0x8f830120, 0x27623800, 0x24660020, 0xc2102b,
-0x50400001, 0x27663000, 0x8f820128, 0x10c20004,
-0x0, 0x8f820124, 0x14c20007, 0x0,
-0x8ee201a4, 0x8021, 0x24420001, 0xaee201a4,
-0x8004044, 0x8ee201a4, 0x8ee2724c, 0xac62001c,
-0x8ee404a8, 0x8ee504ac, 0x2462001c, 0xac620008,
-0x24020008, 0xa462000e, 0x24020011, 0xac620018,
-0xac640000, 0xac650004, 0x8ee204c4, 0xac620010,
-0xaf860120, 0x92e24e20, 0x14400034, 0x24100001,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x8c820000, 0x1455001f, 0x0, 0x8ee34e30,
-0x8ee24e34, 0x1062001b, 0x0, 0x8c820004,
-0x24420001, 0xac820004, 0x8ee24e34, 0x8ee34e30,
-0x24420001, 0x10540007, 0x0, 0x8ee24e34,
-0x24420001, 0x10620005, 0x0, 0x8004030,
-0x0, 0x14600005, 0x0, 0x8f820128,
-0x24420020, 0xaf820128, 0x8f820128, 0x8c820004,
-0x2c420011, 0x50400011, 0xac800000, 0x8004044,
-0x0, 0x8ee24e30, 0x24420001, 0x50540003,
-0x1021, 0x8ee24e30, 0x24420001, 0xaee24e30,
-0x8ee24e30, 0x210c0, 0x24425038, 0x2e22021,
-0x24020001, 0xac950000, 0xac820004, 0x1600000b,
-0x0, 0x8ee2724c, 0x3c040001, 0x248458a8,
-0xafa00014, 0xafa20010, 0x8ee6724c, 0x8f470280,
-0x3c050009, 0xc002403, 0x34a5f008, 0x8ee20174,
-0x24420001, 0xaee20174, 0x8004057, 0x8ee20174,
-0x24020001, 0xaee24e24, 0x8f830128, 0x8f820124,
-0x1462fd58, 0x0, 0x8fbf0030, 0x8fb5002c,
-0x8fb40028, 0x8fb30024, 0x8fb20020, 0x8fb1001c,
-0x8fb00018, 0x3e00008, 0x27bd0038, 0x27bdffe8,
-0x27840208, 0x27450200, 0x24060008, 0xafbf0014,
-0xc00249a, 0xafb00010, 0x2021, 0x24100001,
-0x2402241f, 0xaf900210, 0xaf900200, 0xaf800204,
-0xaf820214, 0x8f460248, 0x24030004, 0x3c020040,
-0x3c010001, 0xac235cc4, 0x3c010001, 0xac235cc8,
-0x3c010001, 0xac205d9c, 0x3c010001, 0xac225cc0,
-0x3c010001, 0xac235cc8, 0xc005108, 0x24050004,
-0xc004822, 0x0, 0x8ee20000, 0x3c03feff,
-0x3463fffd, 0x431024, 0xaee20000, 0x3c023c00,
-0xaf82021c, 0x3c010001, 0x370821, 0xac3083ac,
-0x8fbf0014, 0x8fb00010, 0x3e00008, 0x27bd0018,
-0x27bdffe0, 0x3c050008, 0x34a50400, 0xafbf0018,
-0xafa00010, 0xafa00014, 0x8f860200, 0x3c040001,
-0x248459f0, 0xc002403, 0x3821, 0x8ee20280,
-0x24420001, 0xaee20280, 0x8ee20280, 0x8f830200,
-0x3c023f00, 0x621824, 0x8fbf0018, 0x3c020400,
-0x3e00008, 0x27bd0020, 0x27bdffd8, 0xafbf0020,
-0xafb1001c, 0xafb00018, 0x8f900220, 0x8ee20214,
-0x3821, 0x24420001, 0xaee20214, 0x8ee20214,
-0x3c020300, 0x2021024, 0x10400027, 0x3c110400,
-0xc00429b, 0x0, 0x3c020100, 0x2021024,
-0x10400007, 0x0, 0x8ee20218, 0x24420001,
-0xaee20218, 0x8ee20218, 0x80040c6, 0x3c03fdff,
-0x8ee2021c, 0x24420001, 0xaee2021c, 0x8ee2021c,
-0x3c03fdff, 0x3463ffff, 0x3c0808ff, 0x3508ffff,
-0x8ee20000, 0x3c040001, 0x248459fc, 0x3c050008,
-0x2003021, 0x431024, 0xaee20000, 0x8f820220,
-0x3821, 0x3c030300, 0x481024, 0x431025,
-0xaf820220, 0xafa00010, 0xc002403, 0xafa00014,
-0x8004296, 0x0, 0x2111024, 0x1040001f,
-0x3c024000, 0x8f830224, 0x24021402, 0x1462000b,
-0x3c03fdff, 0x3c040001, 0x24845a08, 0x3c050008,
-0xafa00010, 0xafa00014, 0x8f860224, 0x34a5ffff,
-0xc002403, 0x3821, 0x3c03fdff, 0x8ee20000,
-0x3463ffff, 0x2002021, 0x431024, 0xc004e54,
-0xaee20000, 0x8ee20220, 0x24420001, 0xaee20220,
-0x8ee20220, 0x8f820220, 0x3c0308ff, 0x3463ffff,
-0x431024, 0x8004295, 0x511025, 0x2021024,
-0x10400142, 0x0, 0x8ee2022c, 0x24420001,
-0xaee2022c, 0x8ee2022c, 0x8f820220, 0x3c0308ff,
-0x3463ffff, 0x431024, 0x34420004, 0xaf820220,
-0x8f830054, 0x8f820054, 0x800410e, 0x24630002,
-0x8f820054, 0x621023, 0x2c420003, 0x1440fffc,
-0x0, 0x8f8600e0, 0x8f8400e4, 0x30c20007,
-0x10400012, 0x0, 0x8f8300e4, 0x2402fff8,
-0xc21024, 0x1043000d, 0x0, 0x8f820054,
-0x8f8300e0, 0x14c30009, 0x24440050, 0x8f820054,
-0x821023, 0x2c420051, 0x10400004, 0x0,
-0x8f8200e0, 0x10c2fff9, 0x0, 0x8f820220,
-0x3c0308ff, 0x3463fffd, 0x431024, 0xaf820220,
-0x8f8600e0, 0x30c20007, 0x10400003, 0x2402fff8,
-0xc23024, 0xaf8600e0, 0x8f8300c4, 0x3c02001f,
-0x3442ffff, 0x24680008, 0x48102b, 0x10400003,
-0x3c02fff5, 0x34421000, 0x1024021, 0x8f8b00c8,
-0x8f850120, 0x8f840124, 0x8004145, 0x6021,
-0x27623800, 0x82102b, 0x50400001, 0x27643000,
-0x10a40010, 0x318200ff, 0x8c820018, 0x38430007,
-0x2c630001, 0x3842000b, 0x2c420001, 0x621825,
-0x5060fff3, 0x24840020, 0x8ee20240, 0x240c0001,
-0x24420001, 0xaee20240, 0x8ee20240, 0x8c8b0008,
-0x318200ff, 0x14400065, 0x0, 0x3c020001,
-0x571021, 0x904283c0, 0x14400060, 0x0,
-0x8f8400e4, 0xc41023, 0x218c3, 0x4620001,
-0x24630200, 0x8f8900c4, 0x10600005, 0x24020001,
-0x10620009, 0x0, 0x8004187, 0x0,
-0x8ee20230, 0x1205821, 0x24420001, 0xaee20230,
-0x80041bc, 0x8ee20230, 0x8ee20234, 0x3c05000a,
-0x24420001, 0xaee20234, 0x8c8b0000, 0x34a5f000,
-0x8ee20234, 0x12b1823, 0xa3102b, 0x54400001,
-0x651821, 0x2c62233f, 0x14400040, 0x0,
-0x8f8200e8, 0x24420008, 0xaf8200e8, 0x8f8200e8,
-0x8f8200e4, 0x1205821, 0x24420008, 0xaf8200e4,
-0x80041bc, 0x8f8200e4, 0x8ee20238, 0x3c03000a,
-0x24420001, 0xaee20238, 0x8c840000, 0x3463f000,
-0x8ee20238, 0x883823, 0x67102b, 0x54400001,
-0xe33821, 0x3c020003, 0x34420d40, 0x47102b,
-0x10400003, 0x0, 0x80041bc, 0x805821,
-0x8f8200e4, 0x24440008, 0xaf8400e4, 0x8f8400e4,
-0x10860018, 0x3c05000a, 0x34a5f000, 0x3c0a0003,
-0x354a0d40, 0x8ee2007c, 0x24420001, 0xaee2007c,
-0x8c830000, 0x8ee2007c, 0x683823, 0xa7102b,
-0x54400001, 0xe53821, 0x147102b, 0x54400007,
-0x605821, 0x8f8200e4, 0x24440008, 0xaf8400e4,
-0x8f8400e4, 0x1486ffef, 0x0, 0x14860005,
-0x0, 0x1205821, 0xaf8600e4, 0x80041bc,
-0xaf8600e8, 0xaf8400e4, 0xaf8400e8, 0x8f8200c8,
-0x3c03000a, 0x3463f000, 0x483823, 0x67102b,
-0x54400001, 0xe33821, 0x3c020003, 0x34420d3f,
-0x47102b, 0x54400007, 0x6021, 0x1683823,
-0x67102b, 0x54400003, 0xe33821, 0x80041cf,
-0x3c020003, 0x3c020003, 0x34420d3f, 0x47102b,
-0x14400016, 0x318200ff, 0x14400006, 0x0,
-0x3c020001, 0x571021, 0x904283c0, 0x1040000f,
-0x0, 0x8ee2023c, 0x3c04fdff, 0x8ee30000,
-0x3484ffff, 0x24420001, 0xaee2023c, 0x8ee2023c,
-0x24020001, 0x641824, 0x3c010001, 0x370821,
-0xa02283b8, 0x800422c, 0xaee30000, 0xaf8b00c8,
-0x8f8300c8, 0x8f8200c4, 0x3c04000a, 0x3484f000,
-0x623823, 0x87102b, 0x54400001, 0xe43821,
-0x3c020003, 0x34420d40, 0x47102b, 0x2ce30001,
-0x431025, 0x10400008, 0x0, 0x8f820220,
-0x3c0308ff, 0x3463ffff, 0x431024, 0x3c034000,
-0x431025, 0xaf820220, 0x8f8600e0, 0x8f8400e4,
-0x10c4002a, 0x0, 0x8ee2007c, 0x24420001,
-0xaee2007c, 0x8ee2007c, 0x24c2fff8, 0xaf8200e0,
-0x3c020001, 0x8c427e30, 0x3c030008, 0x8f8600e0,
-0x431024, 0x1040001d, 0x0, 0x10c4001b,
-0x240dfff8, 0x3c0a000a, 0x354af000, 0x3c0c0080,
-0x24850008, 0x27622800, 0x50a20001, 0x27651800,
-0x8c880004, 0x8c820000, 0x8ca90000, 0x3103ffff,
-0x431021, 0x4d1024, 0x24430010, 0x6b102b,
-0x54400001, 0x6a1821, 0x12b102b, 0x54400001,
-0x12a4821, 0x10690002, 0x10c1025, 0xac820004,
-0xa02021, 0x14c4ffeb, 0x24850008, 0x8f820220,
-0x3c0308ff, 0x3463ffff, 0x431024, 0x34420002,
-0xaf820220, 0x8f830054, 0x8f820054, 0x8004237,
-0x24630001, 0x8f820054, 0x621023, 0x2c420002,
-0x1440fffc, 0x0, 0x8f820220, 0x3c0308ff,
-0x3463fffb, 0x431024, 0xaf820220, 0x6010055,
-0x0, 0x8ee20228, 0x24420001, 0xaee20228,
-0x8ee20228, 0x8f820220, 0x3c0308ff, 0x3463ffff,
-0x431024, 0x34420004, 0xaf820220, 0x8f830054,
-0x8f820054, 0x8004251, 0x24630002, 0x8f820054,
-0x621023, 0x2c420003, 0x1440fffc, 0x0,
-0x8f8600e0, 0x30c20007, 0x10400012, 0x0,
-0x8f8300e4, 0x2402fff8, 0xc21024, 0x1043000d,
-0x0, 0x8f820054, 0x8f8300e0, 0x14c30009,
-0x24440032, 0x8f820054, 0x821023, 0x2c420033,
-0x10400004, 0x0, 0x8f8200e0, 0x10c2fff9,
-0x0, 0x8f820220, 0x3c0308ff, 0x3463fffd,
-0x431024, 0xaf820220, 0x8f8600e0, 0x30c20007,
-0x10400003, 0x2402fff8, 0xc23024, 0xaf8600e0,
-0x240301f5, 0x8f8200e8, 0x673823, 0x718c0,
-0x431021, 0xaf8200e8, 0x8f8200e8, 0xaf8200e4,
-0x8ee2007c, 0x3c0408ff, 0x3484ffff, 0x471021,
-0xaee2007c, 0x8f820220, 0x3c038000, 0x34630002,
-0x441024, 0x431025, 0xaf820220, 0x8f830054,
-0x8f820054, 0x800428d, 0x24630001, 0x8f820054,
-0x621023, 0x2c420002, 0x1440fffc, 0x0,
-0x8f820220, 0x3c0308ff, 0x3463fffb, 0x431024,
-0xaf820220, 0x8fbf0020, 0x8fb1001c, 0x8fb00018,
-0x3e00008, 0x27bd0028, 0x3c020001, 0x8c425cd8,
-0x27bdffd8, 0x10400012, 0xafbf0020, 0x3c040001,
-0x24845a14, 0x3c050008, 0x24020001, 0x3c010001,
-0x370821, 0xac2283ac, 0xafa00010, 0xafa00014,
-0x8f860220, 0x34a50498, 0x3c010001, 0xac205cd8,
-0x3c010001, 0xac225ccc, 0xc002403, 0x3821,
-0x8f420268, 0x3c037fff, 0x3463ffff, 0x431024,
-0xaf420268, 0x8ee204d0, 0x8ee404d4, 0x2403fffe,
-0x431024, 0x30840002, 0x1080011e, 0xaee204d0,
-0x8ee204d4, 0x2403fffd, 0x431024, 0xaee204d4,
-0x8f820044, 0x3c030600, 0x34632000, 0x34420020,
-0xaf820044, 0xafa30018, 0x8ee20608, 0x8f430228,
-0x24420001, 0x304a00ff, 0x514300fe, 0xafa00010,
-0x8ee20608, 0x210c0, 0x571021, 0x8fa30018,
-0x8fa4001c, 0xac43060c, 0xac440610, 0x8f830054,
-0x8f820054, 0x24690032, 0x1221023, 0x2c420033,
-0x1040006a, 0x5821, 0x24180008, 0x240f000d,
-0x240d0007, 0x240c0040, 0x240e0001, 0x8f870120,
-0x27623800, 0x24e80020, 0x102102b, 0x50400001,
-0x27683000, 0x8f820128, 0x11020004, 0x0,
-0x8f820124, 0x15020007, 0x1021, 0x8ee201a4,
-0x2821, 0x24420001, 0xaee201a4, 0x800433d,
-0x8ee201a4, 0x8ee40608, 0x420c0, 0x801821,
-0x8ee40430, 0x8ee50434, 0xa32821, 0xa3302b,
-0x822021, 0x862021, 0xace40000, 0xace50004,
-0x8ee20608, 0xa4f8000e, 0xacef0018, 0xacea001c,
-0x210c0, 0x2442060c, 0x2e21021, 0xace20008,
-0x8ee204c4, 0xace20010, 0xaf880120, 0x92e24e20,
-0x14400033, 0x24050001, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x8c820000, 0x144d001f,
-0x0, 0x8ee34e30, 0x8ee24e34, 0x1062001b,
-0x0, 0x8c820004, 0x24420001, 0xac820004,
-0x8ee24e34, 0x8ee34e30, 0x24420001, 0x104c0007,
-0x0, 0x8ee24e34, 0x24420001, 0x10620005,
-0x0, 0x800432a, 0x0, 0x14600005,
-0x0, 0x8f820128, 0x24420020, 0xaf820128,
-0x8f820128, 0x8c820004, 0x2c420011, 0x50400010,
-0xac800000, 0x800433d, 0x0, 0x8ee24e30,
-0x24420001, 0x504c0003, 0x1021, 0x8ee24e30,
-0x24420001, 0xaee24e30, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0xac8d0000, 0xac8e0004,
-0x54a00006, 0x240b0001, 0x8f820054, 0x1221023,
-0x2c420033, 0x1440ff9d, 0x0, 0x316300ff,
-0x24020001, 0x54620079, 0xafa00010, 0xaeea0608,
-0x8f830054, 0x8f820054, 0x24690032, 0x1221023,
-0x2c420033, 0x10400061, 0x5821, 0x240d0008,
-0x240c0011, 0x24080012, 0x24070040, 0x240a0001,
-0x8f830120, 0x27623800, 0x24660020, 0xc2102b,
-0x50400001, 0x27663000, 0x8f820128, 0x10c20004,
-0x0, 0x8f820124, 0x14c20007, 0x0,
-0x8ee201a4, 0x2821, 0x24420001, 0xaee201a4,
-0x80043a9, 0x8ee201a4, 0x8ee20608, 0xac62001c,
-0x8ee404a0, 0x8ee504a4, 0x2462001c, 0xac620008,
-0xa46d000e, 0xac6c0018, 0xac640000, 0xac650004,
-0x8ee204c4, 0xac620010, 0xaf860120, 0x92e24e20,
-0x14400033, 0x24050001, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0x8c820000, 0x1448001f,
-0x0, 0x8ee34e30, 0x8ee24e34, 0x1062001b,
-0x0, 0x8c820004, 0x24420001, 0xac820004,
-0x8ee24e34, 0x8ee34e30, 0x24420001, 0x10470007,
-0x0, 0x8ee24e34, 0x24420001, 0x10620005,
-0x0, 0x8004396, 0x0, 0x14600005,
-0x0, 0x8f820128, 0x24420020, 0xaf820128,
-0x8f820128, 0x8c820004, 0x2c420011, 0x50400010,
-0xac800000, 0x80043a9, 0x0, 0x8ee24e30,
-0x24420001, 0x50470003, 0x1021, 0x8ee24e30,
-0x24420001, 0xaee24e30, 0x8ee24e30, 0x210c0,
-0x24425038, 0x2e22021, 0xac880000, 0xac8a0004,
-0x54a00006, 0x240b0001, 0x8f820054, 0x1221023,
-0x2c420033, 0x1440ffa6, 0x0, 0x316300ff,
-0x24020001, 0x54620003, 0xafa00010, 0x80043d6,
-0x0, 0x3c040001, 0x24845a20, 0xafa00014,
-0x8f860120, 0x8f870124, 0x3c050009, 0xc002403,
-0x34a5f011, 0x80043d6, 0x0, 0x3c040001,
-0x24845a2c, 0xafa00014, 0x8f860120, 0x8f870124,
-0x3c050009, 0xc002403, 0x34a5f010, 0x80043d6,
-0x0, 0x3c040001, 0x24845a38, 0xafa00014,
-0x8ee60608, 0x8f470228, 0x3c050009, 0xc002403,
-0x34a5f00f, 0x8ee201ac, 0x24420001, 0xaee201ac,
-0x8ee201ac, 0x8ee2015c, 0x24420001, 0xaee2015c,
-0x8ee2015c, 0x8fbf0020, 0x3e00008, 0x27bd0028,
-0x3c020001, 0x8c425cd8, 0x27bdffe0, 0x1440000d,
-0xafbf0018, 0x3c040001, 0x24845a44, 0x3c050008,
-0xafa00010, 0xafa00014, 0x8f860220, 0x34a50499,
-0x24020001, 0x3c010001, 0xac225cd8, 0xc002403,
-0x3821, 0x8ee204d0, 0x3c030001, 0x771821,
-0x946383b2, 0x34420001, 0x10600007, 0xaee204d0,
-0x8f820220, 0x3c0308ff, 0x3463ffff, 0x431024,
-0x34420008, 0xaf820220, 0x2021, 0xc0052a2,
-0x24050004, 0xaf420268, 0x8fbf0018, 0x3e00008,
-0x27bd0020, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x3c120001,
-0x26521200, 0x3c140001, 0x8e945c50, 0x3c100001,
-0x26101120, 0x3c15c000, 0x36b50060, 0x8e8a0000,
-0x8eb30000, 0x26a400b, 0x248000a, 0x200f821,
-0x0, 0xd, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x80014d6,
-0x0, 0x80014d8, 0x3c0a0001, 0x80014d8,
-0x3c0a0002, 0x80014d8, 0x0, 0x80024a6,
-0x0, 0x80014d8, 0x3c0a0003, 0x80014d8,
-0x3c0a0004, 0x8002f8c, 0x0, 0x80014d8,
-0x3c0a0005, 0x8003ce8, 0x0, 0x8003c66,
-0x0, 0x80014d8, 0x3c0a0006, 0x80014d8,
-0x3c0a0007, 0x80014d8, 0x0, 0x80014d8,
-0x0, 0x80014d8, 0x0, 0x8002a75,
-0x0, 0x80014d8, 0x3c0a000b, 0x80014d8,
-0x3c0a000c, 0x80014d8, 0x3c0a000d, 0x800237a,
-0x0, 0x8002339, 0x0, 0x80014d8,
-0x3c0a000e, 0x8001b3c, 0x0, 0x80024a4,
-0x0, 0x80014d8, 0x3c0a000f, 0x80040a7,
-0x0, 0x8004091, 0x0, 0x80014d8,
-0x3c0a0010, 0x80014ee, 0x0, 0x80014d8,
-0x3c0a0011, 0x80014d8, 0x3c0a0012, 0x80014d8,
-0x3c0a0013, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x3c030001,
-0x34633800, 0x24050080, 0x2404001f, 0x2406ffff,
-0x24020001, 0xaf80021c, 0xaf820200, 0xaf820220,
-0x3631021, 0xaf8200c0, 0x3631021, 0xaf8200c4,
-0x3631021, 0xaf8200c8, 0x27623800, 0xaf8200d0,
-0x27623800, 0xaf8200d4, 0x27623800, 0xaf8200d8,
-0x27621800, 0xaf8200e0, 0x27621800, 0xaf8200e4,
-0x27621800, 0xaf8200e8, 0x27621000, 0xaf8200f0,
-0x27621000, 0xaf8200f4, 0x27621000, 0xaf8200f8,
-0xaca00000, 0x2484ffff, 0x1486fffd, 0x24a50004,
-0x8f830040, 0x3c02f000, 0x621824, 0x3c025000,
-0x1062000c, 0x43102b, 0x14400006, 0x3c026000,
-0x3c024000, 0x10620008, 0x24020800, 0x8004539,
-0x0, 0x10620004, 0x24020800, 0x8004539,
-0x0, 0x24020700, 0x3c010001, 0xac225cdc,
-0x3e00008, 0x0, 0x27bdffd8, 0xafbf0024,
-0xafb00020, 0x8f830054, 0x8f820054, 0x3c010001,
-0xac205cc4, 0x8004545, 0x24630064, 0x8f820054,
-0x621023, 0x2c420065, 0x1440fffc, 0x0,
-0xc004d71, 0x0, 0x24040001, 0x2821,
-0x27a60018, 0x34028000, 0xc00498e, 0xa7a20018,
-0x8f830054, 0x8f820054, 0x8004556, 0x24630064,
-0x8f820054, 0x621023, 0x2c420065, 0x1440fffc,
-0x24040001, 0x24050001, 0xc00494c, 0x27a60018,
-0x8f830054, 0x8f820054, 0x8004562, 0x24630064,
-0x8f820054, 0x621023, 0x2c420065, 0x1440fffc,
-0x24040001, 0x24050001, 0xc00494c, 0x27a60018,
-0x8f830054, 0x8f820054, 0x800456e, 0x24630064,
-0x8f820054, 0x621023, 0x2c420065, 0x1440fffc,
-0x24040001, 0x3c060001, 0x24c65da0, 0xc00494c,
-0x24050002, 0x8f830054, 0x8f820054, 0x800457b,
-0x24630064, 0x8f820054, 0x621023, 0x2c420065,
-0x1440fffc, 0x24040001, 0x24050003, 0x3c100001,
-0x26105da2, 0xc00494c, 0x2003021, 0x97a60018,
-0x3c070001, 0x94e75da0, 0x3c040001, 0x24845ab0,
-0xafa00014, 0x96020000, 0x3c05000d, 0x34a50100,
-0xc002403, 0xafa20010, 0x97a20018, 0x1040004c,
-0x24036040, 0x96020000, 0x3042fff0, 0x1443000a,
-0x24020020, 0x3c030001, 0x94635da0, 0x54620009,
-0x24027830, 0x24020003, 0x3c010001, 0xac225cc4,
-0x80045ac, 0x24020005, 0x3c030001, 0x94635da0,
-0x24027830, 0x1462000f, 0x24030010, 0x3c020001,
-0x94425da2, 0x3042fff0, 0x1443000a, 0x24020003,
-0x3c010001, 0xac225cc4, 0x24020006, 0x3c010001,
-0xac225db0, 0x3c010001, 0xac225dbc, 0x80045e6,
-0x3c09fff0, 0x3c020001, 0x8c425cc4, 0x3c030001,
-0x94635da0, 0x34420001, 0x3c010001, 0xac225cc4,
-0x24020015, 0x1462000f, 0x0, 0x3c020001,
-0x94425da2, 0x3042fff0, 0x3843f420, 0x2c630001,
-0x3842f430, 0x2c420001, 0x621825, 0x10600005,
-0x24020003, 0x3c010001, 0xac225dbc, 0x80045e6,
-0x3c09fff0, 0x3c030001, 0x94635da0, 0x24027810,
-0x1462000b, 0x24020002, 0x3c020001, 0x94425da2,
-0x3042fff0, 0x14400006, 0x24020002, 0x24020004,
-0x3c010001, 0xac225dbc, 0x80045e6, 0x3c09fff0,
-0x3c010001, 0xac225dbc, 0x80045e6, 0x3c09fff0,
-0x3c020001, 0x8c425cc4, 0x24030001, 0x3c010001,
-0xac235dbc, 0x34420004, 0x3c010001, 0xac225cc4,
-0x3c09fff0, 0x3529bdc0, 0x3c060001, 0x8cc65cc4,
-0x3c040001, 0x24845ab0, 0x24020001, 0x3c010001,
-0xac225ccc, 0x8f820054, 0x3c070001, 0x8ce75dbc,
-0x3c030001, 0x94635da0, 0x3c080001, 0x95085da2,
-0x3c05000d, 0x34a50100, 0x3c010001, 0xac205cc8,
-0x491021, 0x3c010001, 0xac225dac, 0xafa30010,
-0xc002403, 0xafa80014, 0x8fbf0024, 0x8fb00020,
-0x3e00008, 0x27bd0028, 0x27bdffe8, 0x3c050001,
-0x8ca55cc8, 0x24060004, 0x24020001, 0x14a20014,
-0xafbf0010, 0x3c020001, 0x8c427e3c, 0x30428000,
-0x10400005, 0x3c04000f, 0x3c030001, 0x8c635dbc,
-0x8004617, 0x34844240, 0x3c040004, 0x3c030001,
-0x8c635dbc, 0x348493e0, 0x24020005, 0x14620016,
-0x0, 0x3c04003d, 0x800462f, 0x34840900,
-0x3c020001, 0x8c427e38, 0x30428000, 0x10400005,
-0x3c04001e, 0x3c030001, 0x8c635dbc, 0x800462a,
-0x34848480, 0x3c04000f, 0x3c030001, 0x8c635dbc,
-0x34844240, 0x24020005, 0x14620003, 0x0,
-0x3c04007a, 0x34841200, 0x3c020001, 0x8c425dac,
-0x8f830054, 0x441021, 0x431023, 0x44102b,
-0x14400037, 0x0, 0x3c020001, 0x8c425cd0,
-0x14400033, 0x0, 0x3c010001, 0x10c00025,
-0xac205ce0, 0x3c090001, 0x8d295cc4, 0x24070001,
-0x3c044000, 0x3c080001, 0x25087e3c, 0x250afffc,
-0x52842, 0x14a00002, 0x24c6ffff, 0x24050008,
-0xa91024, 0x10400010, 0x0, 0x14a70008,
-0x0, 0x8d020000, 0x441024, 0x1040000a,
-0x0, 0x3c010001, 0x800465b, 0xac255ce0,
-0x8d420000, 0x441024, 0x10400003, 0x0,
-0x3c010001, 0xac275ce0, 0x3c020001, 0x8c425ce0,
-0x6182b, 0x2c420001, 0x431024, 0x5440ffe5,
-0x52842, 0x8f820054, 0x3c030001, 0x8c635ce0,
-0x3c010001, 0xac225dac, 0x1060002a, 0x24020001,
-0x3c010001, 0xac255cc8, 0x3c010001, 0xac225ccc,
-0x3c020001, 0x8c425ce0, 0x10400022, 0x0,
-0x3c020001, 0x8c425ccc, 0x1040000a, 0x24020001,
-0x3c010001, 0xac205ccc, 0x3c010001, 0x370821,
-0xac2283ac, 0x3c010001, 0xac205d4c, 0x3c010001,
-0xac225d04, 0x3c030001, 0x771821, 0x8c6383ac,
-0x24020008, 0x10620005, 0x24020001, 0xc004695,
-0x0, 0x8004692, 0x0, 0x3c030001,
-0x8c635cc8, 0x10620007, 0x2402000e, 0x3c030001,
-0x8c637dd0, 0x10620003, 0x0, 0xc004e54,
-0x8f840220, 0x8fbf0010, 0x3e00008, 0x27bd0018,
-0x27bdffe0, 0x3c02fdff, 0xafbf0018, 0x8ee30000,
-0x3c050001, 0x8ca55cc8, 0x3c040001, 0x8c845cf0,
-0x3442ffff, 0x621824, 0x14a40008, 0xaee30000,
-0x3c030001, 0x771821, 0x8c6383ac, 0x3c020001,
-0x8c425cf4, 0x10620008, 0x0, 0x3c020001,
-0x571021, 0x8c4283ac, 0x3c010001, 0xac255cf0,
-0x3c010001, 0xac225cf4, 0x3c030001, 0x8c635cc8,
-0x24020002, 0x10620169, 0x2c620003, 0x10400005,
-0x24020001, 0x10620008, 0x0, 0x800481c,
-0x0, 0x24020004, 0x106200b1, 0x24020001,
-0x800481d, 0x0, 0x3c020001, 0x571021,
-0x8c4283ac, 0x2443ffff, 0x2c620008, 0x1040015a,
-0x31080, 0x3c010001, 0x220821, 0x8c225ac8,
-0x400008, 0x0, 0x3c030001, 0x8c635dbc,
-0x24020005, 0x14620014, 0x0, 0x3c020001,
-0x8c425cd4, 0x1040000a, 0x24020003, 0xc004822,
-0x0, 0x24020002, 0x3c010001, 0x370821,
-0xac2283ac, 0x3c010001, 0x80046e0, 0xac205cd4,
-0x3c010001, 0x370821, 0xac2283ac, 0x3c010001,
-0x800481f, 0xac205c60, 0xc004822, 0x0,
-0x3c020001, 0x8c425cd4, 0x3c010001, 0xac205c60,
-0x104000dd, 0x24020002, 0x3c010001, 0x370821,
-0xac2283ac, 0x3c010001, 0x800481f, 0xac205cd4,
-0x3c030001, 0x8c635dbc, 0x24020005, 0x14620003,
-0x24020001, 0x3c010001, 0xac225d00, 0xc0049cf,
-0x0, 0x3c030001, 0x8c635d00, 0x800478e,
-0x24020011, 0x3c050001, 0x8ca55cc8, 0x3c060001,
-0x8cc67e3c, 0xc005108, 0x2021, 0x24020005,
-0x3c010001, 0xac205cd4, 0x3c010001, 0x370821,
-0x800481f, 0xac2283ac, 0x3c040001, 0x24845abc,
-0x3c05000f, 0x34a50100, 0x3021, 0x3821,
-0xafa00010, 0xc002403, 0xafa00014, 0x800481f,
-0x0, 0x8f820220, 0x3c03f700, 0x431025,
-0x80047b7, 0xaf820220, 0x8f820220, 0x3c030004,
-0x431024, 0x144000a9, 0x24020007, 0x8f830054,
-0x3c020001, 0x8c425da4, 0x2463d8f0, 0x431023,
-0x2c422710, 0x144000f8, 0x24020001, 0x800481d,
-0x0, 0x3c050001, 0x8ca55cc8, 0xc0052a2,
-0x2021, 0xc005386, 0x2021, 0x3c030001,
-0x8c637e34, 0x46100ea, 0x24020001, 0x3c020008,
-0x621024, 0x10400006, 0x0, 0x8f820214,
-0x3c03ffff, 0x431024, 0x8004741, 0x3442251f,
-0x8f820214, 0x3c03ffff, 0x431024, 0x3442241f,
-0xaf820214, 0x8ee20000, 0x3c030200, 0x431025,
-0xaee20000, 0x8f820220, 0x2403fffb, 0x431024,
-0xaf820220, 0x8f820220, 0x34420002, 0xaf820220,
-0x24020008, 0x3c010001, 0x370821, 0xac2283ac,
-0x8f820220, 0x3c030004, 0x431024, 0x14400005,
-0x0, 0x8f820220, 0x3c03f700, 0x431025,
-0xaf820220, 0x3c030001, 0x8c635dbc, 0x24020005,
-0x1462000a, 0x0, 0x3c020001, 0x94425da2,
-0x24429fbc, 0x2c420004, 0x10400004, 0x24040018,
-0x24050002, 0xc004d93, 0x24060020, 0xc0043dd,
-0x0, 0x3c010001, 0x800481f, 0xac205d50,
-0x3c020001, 0x571021, 0x8c4283ac, 0x2443ffff,
-0x2c620008, 0x104000ac, 0x31080, 0x3c010001,
-0x220821, 0x8c225ae8, 0x400008, 0x0,
-0xc00429b, 0x0, 0x3c010001, 0xac205ccc,
-0xaf800204, 0x3c010001, 0xc004822, 0xac207e20,
-0x24020001, 0x3c010001, 0xac225ce4, 0x24020002,
-0x3c010001, 0x370821, 0x800481f, 0xac2283ac,
-0xc00489f, 0x0, 0x3c030001, 0x8c635ce4,
-0x24020009, 0x14620090, 0x24020003, 0x3c010001,
-0x370821, 0x800481f, 0xac2283ac, 0x3c020001,
-0x8c427e38, 0x30424000, 0x10400005, 0x0,
-0x8f820044, 0x3c03ffff, 0x800479f, 0x34637fff,
-0x8f820044, 0x2403ff7f, 0x431024, 0xaf820044,
-0x8f830054, 0x80047b9, 0x24020004, 0x8f830054,
-0x3c020001, 0x8c425da4, 0x2463d8f0, 0x431023,
-0x2c422710, 0x14400074, 0x24020005, 0x3c010001,
-0x370821, 0x800481f, 0xac2283ac, 0x8f820220,
-0x3c03f700, 0x431025, 0xaf820220, 0xaf800204,
-0x3c010001, 0xac207e20, 0x8f830054, 0x24020006,
-0x3c010001, 0x370821, 0xac2283ac, 0x3c010001,
-0x800481f, 0xac235da4, 0x8f830054, 0x3c020001,
-0x8c425da4, 0x2463fff6, 0x431023, 0x2c42000a,
-0x14400059, 0x0, 0x24020007, 0x3c010001,
-0x370821, 0x800481f, 0xac2283ac, 0x8f820220,
-0x3c04f700, 0x441025, 0xaf820220, 0x8f820220,
-0x3c030300, 0x431024, 0x14400005, 0x1821,
-0x8f820220, 0x24030001, 0x441025, 0xaf820220,
-0x10600043, 0x24020001, 0x8f820214, 0x3c03ffff,
-0x3c040001, 0x8c845d98, 0x431024, 0x3442251f,
-0xaf820214, 0x24020008, 0x3c010001, 0x370821,
-0x1080000b, 0xac2283ac, 0x3c020001, 0x8c425d74,
-0x14400007, 0x24020001, 0x3c010001, 0xac227dd0,
-0xc004e54, 0x8f840220, 0x800480c, 0x0,
-0x8f820220, 0x3c030008, 0x431024, 0x14400017,
-0x2402000e, 0x3c010001, 0xac227dd0, 0x8ee20000,
-0x2021, 0x3c030200, 0x431025, 0xc005386,
-0xaee20000, 0x8f820220, 0x2403fffb, 0x431024,
-0xaf820220, 0x8f820220, 0x34420002, 0xc0043dd,
-0xaf820220, 0x3c050001, 0x8ca55cc8, 0xc0052a2,
-0x2021, 0x800481f, 0x0, 0x3c020001,
-0x8c425d74, 0x10400010, 0x0, 0x3c020001,
-0x8c425d70, 0x2442ffff, 0x3c010001, 0xac225d70,
-0x14400009, 0x24020002, 0x3c010001, 0xac205d74,
-0x3c010001, 0x800481f, 0xac225d70, 0x24020001,
-0x3c010001, 0xac225ccc, 0x8fbf0018, 0x3e00008,
-0x27bd0020, 0x8f820200, 0x8f820220, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820200, 0x3c060001,
-0x8cc65cc8, 0x34420004, 0xaf820200, 0x24020002,
-0x10c2003a, 0x2cc20003, 0x10400005, 0x24020001,
-0x10c20008, 0x0, 0x8004868, 0x0,
-0x24020004, 0x10c20013, 0x24020001, 0x8004868,
-0x0, 0x3c030001, 0x8c635cb8, 0x3c020001,
-0x8c425cc0, 0x3c040001, 0x8c845cdc, 0x3c050001,
-0x8ca55cbc, 0xaf860200, 0xaf860220, 0x34630022,
-0x441025, 0x451025, 0x34420002, 0x8004867,
-0xaf830200, 0x3c030001, 0x8c635d98, 0xaf820200,
-0x10600009, 0xaf820220, 0x3c020001, 0x8c425d74,
-0x14400005, 0x3c033f00, 0x3c020001, 0x8c425cb0,
-0x800485b, 0x346300e0, 0x3c020001, 0x8c425cb0,
-0x3c033f00, 0x346300e2, 0x431025, 0xaf820200,
-0x3c030001, 0x8c635cb4, 0x3c04f700, 0x3c020001,
-0x8c425cc0, 0x3c050001, 0x8ca55cdc, 0x641825,
-0x431025, 0x451025, 0xaf820220, 0x3e00008,
-0x0, 0x8f820220, 0x3c030001, 0x8c635cc8,
-0x34420004, 0xaf820220, 0x24020001, 0x1062000f,
-0x0, 0x8f830054, 0x8f820054, 0x24630002,
-0x621023, 0x2c420003, 0x10400011, 0x0,
-0x8f820054, 0x621023, 0x2c420003, 0x1040000c,
-0x0, 0x8004879, 0x0, 0x8f830054,
-0x8f820054, 0x8004885, 0x24630007, 0x8f820054,
-0x621023, 0x2c420008, 0x1440fffc, 0x0,
-0x8f8400e0, 0x30820007, 0x1040000d, 0x0,
-0x8f820054, 0x8f8300e0, 0x14830009, 0x24450032,
-0x8f820054, 0xa21023, 0x2c420033, 0x10400004,
-0x0, 0x8f8200e0, 0x1082fff9, 0x0,
-0x8f820220, 0x2403fffd, 0x431024, 0xaf820220,
-0x3e00008, 0x0, 0x3c030001, 0x8c635ce4,
-0x3c020001, 0x8c425ce8, 0x50620004, 0x2463ffff,
-0x3c010001, 0xac235ce8, 0x2463ffff, 0x2c620009,
-0x1040009d, 0x31080, 0x3c010001, 0x220821,
-0x8c225b08, 0x400008, 0x0, 0x8f820044,
-0x34428080, 0xaf820044, 0x8f830054, 0x8004938,
-0x24020002, 0x8f830054, 0x3c020001, 0x8c425da8,
-0x2463d8f0, 0x431023, 0x2c422710, 0x1440008a,
-0x24020003, 0x8004945, 0x0, 0x8f820044,
-0x3c03ffff, 0x34637fff, 0x431024, 0xaf820044,
-0x8f830054, 0x8004938, 0x24020004, 0x8f830054,
-0x3c020001, 0x8c425da8, 0x2463fff6, 0x431023,
-0x2c42000a, 0x14400078, 0x24020005, 0x8004945,
-0x0, 0x8f820220, 0x3c03f700, 0x431025,
-0xaf820220, 0x8f820220, 0x2403fffb, 0x431024,
-0xaf820220, 0x8f820220, 0x34420002, 0xaf820220,
-0x3c023f00, 0x344200e0, 0xaf820200, 0x8f820200,
-0x2403fffd, 0x431024, 0xaf820200, 0x24040001,
-0x3405ffff, 0xaf840204, 0x8f830054, 0x8f820054,
-0x80048ec, 0x24630001, 0x8f820054, 0x621023,
-0x2c420002, 0x1440fffc, 0x0, 0x8f820224,
-0x42040, 0xa4102b, 0x1040fff2, 0x0,
-0x8f820220, 0x3c03f700, 0x431025, 0xaf820220,
-0x8f820214, 0x3c03ffff, 0x431024, 0x3442251f,
-0xaf820214, 0x8f820220, 0x2403fffb, 0x431024,
-0xaf820220, 0x8f820220, 0x3c04f700, 0x34840008,
-0x34420002, 0xaf820220, 0x8f820220, 0x3c033f00,
-0x346300e2, 0x441025, 0xaf820220, 0xaf830200,
-0x8f8400f0, 0x276217f8, 0x14820002, 0x24850008,
-0x27651000, 0x8f8200f4, 0x10a20007, 0x3c038000,
-0x34630040, 0x3c020001, 0x24425c70, 0xac820000,
-0xac830004, 0xaf8500f0, 0x8f830054, 0x8004938,
-0x24020006, 0x8f830054, 0x3c020001, 0x8c425da8,
-0x2463fff6, 0x431023, 0x2c42000a, 0x14400022,
-0x24020007, 0x8004945, 0x0, 0x8f8200e0,
-0xaf8200e4, 0x8f8200e0, 0xaf8200e8, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820220, 0x2403fff7,
-0x431024, 0xaf820220, 0x8f820044, 0x34428080,
-0xaf820044, 0x8f830054, 0x24020008, 0x3c010001,
-0xac225ce4, 0x3c010001, 0x8004947, 0xac235da8,
-0x8f830054, 0x3c020001, 0x8c425da8, 0x2463d8f0,
-0x431023, 0x2c422710, 0x14400003, 0x24020009,
-0x3c010001, 0xac225ce4, 0x3e00008, 0x0,
-0x0, 0x0, 0x0, 0x27bdffd8,
-0xafb20018, 0x809021, 0xafb3001c, 0xa09821,
-0xafb10014, 0xc08821, 0xafb00010, 0x8021,
-0xafbf0020, 0xa6200000, 0xc004d4b, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc004d4b, 0x2021, 0xc004d4b, 0x24040001,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0x24100010, 0x2501024, 0x10400002, 0x2021,
-0x24040001, 0xc004d4b, 0x108042, 0x1600fffa,
-0x2501024, 0x24100010, 0x2701024, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fffa, 0x2701024, 0xc004d71, 0x34108000,
-0xc004d71, 0x0, 0xc004d2b, 0x0,
-0x50400005, 0x108042, 0x96220000, 0x501025,
-0xa6220000, 0x108042, 0x1600fff7, 0x0,
-0xc004d71, 0x0, 0x8fbf0020, 0x8fb3001c,
-0x8fb20018, 0x8fb10014, 0x8fb00010, 0x3e00008,
-0x27bd0028, 0x27bdffd8, 0xafb10014, 0x808821,
-0xafb20018, 0xa09021, 0xafb3001c, 0xc09821,
-0xafb00010, 0x8021, 0xafbf0020, 0xc004d4b,
-0x24040001, 0x26100001, 0x2e020020, 0x1440fffb,
-0x0, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0x24100010, 0x2301024, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fffa, 0x2301024, 0x24100010, 0x2501024,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x2501024, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x2021, 0x34108000,
-0x96620000, 0x501024, 0x10400002, 0x2021,
-0x24040001, 0xc004d4b, 0x108042, 0x1600fff8,
-0x0, 0xc004d71, 0x0, 0x8fbf0020,
-0x8fb3001c, 0x8fb20018, 0x8fb10014, 0x8fb00010,
-0x3e00008, 0x27bd0028, 0x3c030001, 0x8c635d00,
-0x3c020001, 0x8c425d48, 0x27bdffd8, 0xafbf0020,
-0xafb1001c, 0x10620003, 0xafb00018, 0x3c010001,
-0xac235d48, 0x2463ffff, 0x2c620013, 0x10400349,
-0x31080, 0x3c010001, 0x220821, 0x8c225b30,
-0x400008, 0x0, 0xc004d71, 0x8021,
-0x34028000, 0xa7a20010, 0x27b10010, 0xc004d4b,
-0x24040001, 0x26100001, 0x2e020020, 0x1440fffb,
-0x0, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0x24100010, 0x32020001, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fffa, 0x32020001, 0x24100010, 0xc004d4b,
-0x2021, 0x108042, 0x1600fffc, 0x0,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0x34108000, 0x96220000, 0x501024, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fff8, 0x0, 0xc004d71, 0x0,
-0x8004d24, 0x24020002, 0x27b10010, 0xa7a00010,
-0x8021, 0xc004d4b, 0x24040001, 0x26100001,
-0x2e020020, 0x1440fffb, 0x0, 0xc004d4b,
-0x2021, 0xc004d4b, 0x24040001, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x2021, 0x24100010,
-0x32020001, 0x10400002, 0x2021, 0x24040001,
-0xc004d4b, 0x108042, 0x1600fffa, 0x32020001,
-0x24100010, 0xc004d4b, 0x2021, 0x108042,
-0x1600fffc, 0x0, 0xc004d71, 0x34108000,
-0xc004d71, 0x0, 0xc004d2b, 0x0,
-0x50400005, 0x108042, 0x96220000, 0x501025,
-0xa6220000, 0x108042, 0x1600fff7, 0x0,
-0xc004d71, 0x0, 0x97a20010, 0x30428000,
-0x144002dc, 0x24020003, 0x8004d24, 0x0,
-0x24021200, 0xa7a20010, 0x27b10010, 0x8021,
-0xc004d4b, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0xc004d4b, 0x2021, 0x108042, 0x1600fffc,
-0x0, 0xc004d4b, 0x24040001, 0xc004d4b,
-0x2021, 0x34108000, 0x96220000, 0x501024,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fff8, 0x0, 0xc004d71,
-0x0, 0x8f830054, 0x8004d16, 0x24020004,
-0x8f830054, 0x3c020001, 0x8c425db8, 0x2463ff9c,
-0x431023, 0x2c420064, 0x1440029e, 0x24020002,
-0x3c030001, 0x8c635dbc, 0x10620297, 0x2c620003,
-0x14400296, 0x24020011, 0x24020003, 0x10620005,
-0x24020004, 0x10620291, 0x2402000f, 0x8004d24,
-0x24020011, 0x8004d24, 0x24020005, 0x24020014,
-0xa7a20010, 0x27b10010, 0x8021, 0xc004d4b,
-0x24040001, 0x26100001, 0x2e020020, 0x1440fffb,
-0x0, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0x24100010, 0x32020001, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fffa, 0x32020001, 0x24100010, 0x32020012,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x32020012, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x2021, 0x34108000,
-0x96220000, 0x501024, 0x10400002, 0x2021,
-0x24040001, 0xc004d4b, 0x108042, 0x1600fff8,
-0x0, 0xc004d71, 0x0, 0x8f830054,
-0x8004d16, 0x24020006, 0x8f830054, 0x3c020001,
-0x8c425db8, 0x2463ff9c, 0x431023, 0x2c420064,
-0x14400250, 0x24020007, 0x8004d24, 0x0,
-0x24020006, 0xa7a20010, 0x27b10010, 0x8021,
-0xc004d4b, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x32020013, 0x10400002, 0x2021, 0x24040001,
-0xc004d4b, 0x108042, 0x1600fffa, 0x32020013,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0x34108000, 0x96220000, 0x501024, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fff8, 0x0, 0xc004d71, 0x0,
-0x8f830054, 0x8004d16, 0x24020008, 0x8f830054,
-0x3c020001, 0x8c425db8, 0x2463ff9c, 0x431023,
-0x2c420064, 0x1440020f, 0x24020009, 0x8004d24,
-0x0, 0x27b10010, 0xa7a00010, 0x8021,
-0xc004d4b, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x24040001,
-0xc004d4b, 0x2021, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x32020018, 0x10400002, 0x2021, 0x24040001,
-0xc004d4b, 0x108042, 0x1600fffa, 0x32020018,
-0xc004d71, 0x34108000, 0xc004d71, 0x0,
-0xc004d2b, 0x0, 0x50400005, 0x108042,
-0x96220000, 0x501025, 0xa6220000, 0x108042,
-0x1600fff7, 0x0, 0xc004d71, 0x8021,
-0x97a20010, 0x27b10010, 0x34420001, 0xa7a20010,
-0xc004d4b, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x32020018, 0x10400002, 0x2021, 0x24040001,
-0xc004d4b, 0x108042, 0x1600fffa, 0x32020018,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0x34108000, 0x96220000, 0x501024, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fff8, 0x0, 0xc004d71, 0x0,
-0x8f830054, 0x8004d16, 0x2402000a, 0x8f830054,
-0x3c020001, 0x8c425db8, 0x2463ff9c, 0x431023,
-0x2c420064, 0x1440019b, 0x2402000b, 0x8004d24,
-0x0, 0x27b10010, 0xa7a00010, 0x8021,
-0xc004d4b, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x24040001,
-0xc004d4b, 0x2021, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x32020017, 0x10400002, 0x2021, 0x24040001,
-0xc004d4b, 0x108042, 0x1600fffa, 0x32020017,
-0xc004d71, 0x34108000, 0xc004d71, 0x0,
-0xc004d2b, 0x0, 0x50400005, 0x108042,
-0x96220000, 0x501025, 0xa6220000, 0x108042,
-0x1600fff7, 0x0, 0xc004d71, 0x8021,
-0x97a20010, 0x27b10010, 0x34420700, 0xa7a20010,
-0xc004d4b, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x32020017, 0x10400002, 0x2021, 0x24040001,
-0xc004d4b, 0x108042, 0x1600fffa, 0x32020017,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0x34108000, 0x96220000, 0x501024, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fff8, 0x0, 0xc004d71, 0x0,
-0x8f830054, 0x8004d16, 0x2402000c, 0x8f830054,
-0x3c020001, 0x8c425db8, 0x2463ff9c, 0x431023,
-0x2c420064, 0x14400127, 0x24020012, 0x8004d24,
-0x0, 0x27b10010, 0xa7a00010, 0x8021,
-0xc004d4b, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x24040001,
-0xc004d4b, 0x2021, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x32020014, 0x10400002, 0x2021, 0x24040001,
-0xc004d4b, 0x108042, 0x1600fffa, 0x32020014,
-0xc004d71, 0x34108000, 0xc004d71, 0x0,
-0xc004d2b, 0x0, 0x50400005, 0x108042,
-0x96220000, 0x501025, 0xa6220000, 0x108042,
-0x1600fff7, 0x0, 0xc004d71, 0x8021,
-0x97a20010, 0x27b10010, 0x34420010, 0xa7a20010,
-0xc004d4b, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x32020014, 0x10400002, 0x2021, 0x24040001,
-0xc004d4b, 0x108042, 0x1600fffa, 0x32020014,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0x34108000, 0x96220000, 0x501024, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fff8, 0x0, 0xc004d71, 0x0,
-0x8f830054, 0x8004d16, 0x24020013, 0x8f830054,
-0x3c020001, 0x8c425db8, 0x2463ff9c, 0x431023,
-0x2c420064, 0x144000b3, 0x2402000d, 0x8004d24,
-0x0, 0x27b10010, 0xa7a00010, 0x8021,
-0xc004d4b, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x24040001,
-0xc004d4b, 0x2021, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x32020018, 0x10400002, 0x2021, 0x24040001,
-0xc004d4b, 0x108042, 0x1600fffa, 0x32020018,
-0xc004d71, 0x34108000, 0xc004d71, 0x0,
-0xc004d2b, 0x0, 0x50400005, 0x108042,
-0x96220000, 0x501025, 0xa6220000, 0x108042,
-0x1600fff7, 0x0, 0xc004d71, 0x8021,
-0x97a20010, 0x27b10010, 0x3042fffe, 0xa7a20010,
-0xc004d4b, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0xc004d4b, 0x24040001, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x32020018, 0x10400002, 0x2021, 0x24040001,
-0xc004d4b, 0x108042, 0x1600fffa, 0x32020018,
-0xc004d4b, 0x24040001, 0xc004d4b, 0x2021,
-0x34108000, 0x96220000, 0x501024, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fff8, 0x0, 0xc004d71, 0x0,
-0x8f830054, 0x8004d16, 0x2402000e, 0x24020840,
-0xa7a20010, 0x27b10010, 0x8021, 0xc004d4b,
-0x24040001, 0x26100001, 0x2e020020, 0x1440fffb,
-0x0, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0x24100010, 0x32020001, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fffa, 0x32020001, 0x24100010, 0x32020013,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x32020013, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x2021, 0x34108000,
-0x96220000, 0x501024, 0x10400002, 0x2021,
-0x24040001, 0xc004d4b, 0x108042, 0x1600fff8,
-0x0, 0xc004d71, 0x0, 0x8f830054,
-0x24020010, 0x3c010001, 0xac225d00, 0x3c010001,
-0x8004d26, 0xac235db8, 0x8f830054, 0x3c020001,
-0x8c425db8, 0x2463ff9c, 0x431023, 0x2c420064,
-0x14400004, 0x0, 0x24020011, 0x3c010001,
-0xac225d00, 0x8fbf0020, 0x8fb1001c, 0x8fb00018,
-0x3e00008, 0x27bd0028, 0x8f850044, 0x8f820044,
-0x3c030001, 0x431025, 0x3c030008, 0xaf820044,
-0x8f840054, 0x8f820054, 0xa32824, 0x8004d37,
-0x24840001, 0x8f820054, 0x821023, 0x2c420002,
-0x1440fffc, 0x0, 0x8f820044, 0x3c03fffe,
-0x3463ffff, 0x431024, 0xaf820044, 0x8f830054,
-0x8f820054, 0x8004d45, 0x24630001, 0x8f820054,
-0x621023, 0x2c420002, 0x1440fffc, 0x0,
-0x3e00008, 0xa01021, 0x8f830044, 0x3c02fff0,
-0x3442ffff, 0x42480, 0x621824, 0x3c020002,
-0x822025, 0x641825, 0xaf830044, 0x8f820044,
-0x3c03fffe, 0x3463ffff, 0x431024, 0xaf820044,
-0x8f830054, 0x8f820054, 0x8004d5e, 0x24630001,
-0x8f820054, 0x621023, 0x2c420002, 0x1440fffc,
-0x0, 0x8f820044, 0x3c030001, 0x431025,
-0xaf820044, 0x8f830054, 0x8f820054, 0x8004d6b,
-0x24630001, 0x8f820054, 0x621023, 0x2c420002,
-0x1440fffc, 0x0, 0x3e00008, 0x0,
-0x8f820044, 0x3c03fff0, 0x3463ffff, 0x431024,
-0xaf820044, 0x8f820044, 0x3c030001, 0x431025,
-0xaf820044, 0x8f830054, 0x8f820054, 0x8004d7f,
-0x24630001, 0x8f820054, 0x621023, 0x2c420002,
-0x1440fffc, 0x0, 0x8f820044, 0x3c03fffe,
-0x3463ffff, 0x431024, 0xaf820044, 0x8f830054,
-0x8f820054, 0x8004d8d, 0x24630001, 0x8f820054,
-0x621023, 0x2c420002, 0x1440fffc, 0x0,
-0x3e00008, 0x0, 0x27bdffc8, 0xafb30024,
-0x809821, 0xafb5002c, 0xa0a821, 0xafb20020,
-0xc09021, 0x32a2ffff, 0xafbf0030, 0xafb40028,
-0xafb1001c, 0xafb00018, 0x14400034, 0xa7b20010,
-0x3271ffff, 0x27b20010, 0x8021, 0xc004d4b,
-0x24040001, 0x26100001, 0x2e020020, 0x1440fffb,
-0x0, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0x24100010, 0x32020001, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fffa, 0x32020001, 0x24100010, 0x2301024,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x2301024, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x2021, 0x34108000,
-0x96420000, 0x501024, 0x10400002, 0x2021,
-0x24040001, 0xc004d4b, 0x108042, 0x12000075,
-0x0, 0x8004dc9, 0x0, 0x3274ffff,
-0x27b10010, 0xa7a00010, 0x8021, 0xc004d4b,
-0x24040001, 0x26100001, 0x2e020020, 0x1440fffb,
-0x0, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x24040001, 0xc004d4b,
-0x2021, 0x24100010, 0x32020001, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fffa, 0x32020001, 0x24100010, 0x2901024,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x2901024, 0xc004d71,
-0x34108000, 0xc004d71, 0x0, 0xc004d2b,
-0x0, 0x50400005, 0x108042, 0x96220000,
-0x501025, 0xa6220000, 0x108042, 0x1600fff7,
-0x0, 0xc004d71, 0x0, 0x32a5ffff,
-0x24020001, 0x54a20004, 0x24020002, 0x97a20010,
-0x8004e14, 0x521025, 0x14a20006, 0x3271ffff,
-0x97a20010, 0x121827, 0x431024, 0xa7a20010,
-0x3271ffff, 0x27b20010, 0x8021, 0xc004d4b,
-0x24040001, 0x26100001, 0x2e020020, 0x1440fffb,
-0x0, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x2021, 0xc004d4b,
-0x24040001, 0x24100010, 0x32020001, 0x10400002,
-0x2021, 0x24040001, 0xc004d4b, 0x108042,
-0x1600fffa, 0x32020001, 0x24100010, 0x2301024,
-0x10400002, 0x2021, 0x24040001, 0xc004d4b,
-0x108042, 0x1600fffa, 0x2301024, 0xc004d4b,
-0x24040001, 0xc004d4b, 0x2021, 0x34108000,
-0x96420000, 0x501024, 0x10400002, 0x2021,
-0x24040001, 0xc004d4b, 0x108042, 0x1600fff8,
-0x0, 0xc004d71, 0x0, 0x8fbf0030,
-0x8fb5002c, 0x8fb40028, 0x8fb30024, 0x8fb20020,
-0x8fb1001c, 0x8fb00018, 0x3e00008, 0x27bd0038,
-0x0, 0x0, 0x0, 0x27bdffe8,
-0xafbf0010, 0x3c030001, 0x771821, 0x8c6383ac,
-0x24020008, 0x1462022c, 0x803021, 0x3c020001,
-0x8c425d98, 0x14400033, 0x0, 0x8f850224,
-0x38a30020, 0x2c630001, 0x38a20010, 0x2c420001,
-0x621825, 0x1460000d, 0x38a30030, 0x2c630001,
-0x38a20400, 0x2c420001, 0x621825, 0x14600007,
-0x38a30402, 0x2c630001, 0x38a20404, 0x2c420001,
-0x621825, 0x10600005, 0x0, 0xc00429b,
-0x0, 0x8004e8d, 0x2402000e, 0xc0043dd,
-0x0, 0x3c050001, 0x8ca55cc8, 0xc0052a2,
-0x2021, 0x3c030001, 0x8c635cc8, 0x24020004,
-0x14620005, 0x2403fffb, 0x3c020001, 0x8c425cc4,
-0x8004e89, 0x2403fff7, 0x3c020001, 0x8c425cc4,
-0x431024, 0x3c010001, 0xac225cc4, 0x2402000e,
-0x3c010001, 0xc00429b, 0xac227dd0, 0x8005087,
-0x0, 0x8f820220, 0x3c030400, 0x431024,
-0x10400027, 0x2403ffbf, 0x8f850224, 0x3c020001,
-0x8c427ddc, 0xa32024, 0x431024, 0x1482000c,
-0x0, 0x3c020001, 0x8c427de0, 0x24420001,
-0x3c010001, 0xac227de0, 0x2c420002, 0x14400008,
-0x24020001, 0x3c010001, 0x8004ead, 0xac227e00,
-0x3c010001, 0xac207de0, 0x3c010001, 0xac207e00,
-0x3c020001, 0x8c427e00, 0x10400006, 0x30a20040,
-0x10400004, 0x24020001, 0x3c010001, 0x8004eb8,
-0xac227e04, 0x3c010001, 0xac207e04, 0x3c010001,
-0xac257ddc, 0x3c010001, 0x8004ec8, 0xac207e10,
-0x24020001, 0x3c010001, 0xac227e10, 0x3c010001,
-0xac207e00, 0x3c010001, 0xac207de0, 0x3c010001,
-0xac207e04, 0x3c010001, 0xac207ddc, 0x3c030001,
-0x8c637dd0, 0x3c020001, 0x8c427dd4, 0x10620003,
-0x3c020200, 0x3c010001, 0xac237dd4, 0xc21024,
-0x10400007, 0x2463ffff, 0x8f820220, 0x24030001,
-0x3c010001, 0xac235ccc, 0x8005085, 0x3c03f700,
-0x2c62000e, 0x104001a8, 0x31080, 0x3c010001,
-0x220821, 0x8c225b80, 0x400008, 0x0,
-0x3c010001, 0xac207e00, 0x3c010001, 0xac207de0,
-0x3c010001, 0xac207ddc, 0x3c010001, 0xac207e04,
-0x3c010001, 0xac207df8, 0x3c010001, 0xac207df0,
-0xc00486a, 0xaf800224, 0x24020002, 0x3c010001,
-0xac227dd0, 0x3c020001, 0x8c427e10, 0x14400056,
-0x3c03fdff, 0x8ee20000, 0x3463ffff, 0x431024,
-0xc00429b, 0xaee20000, 0xaf800204, 0x8f820200,
-0x2403fffd, 0x431024, 0xaf820200, 0x3c010001,
-0xac207e20, 0x8f830054, 0x3c020001, 0x8c427df8,
-0x24040001, 0x3c010001, 0xac247e0c, 0x24420001,
-0x3c010001, 0xac227df8, 0x2c420004, 0x3c010001,
-0xac237df4, 0x14400006, 0x24020003, 0x3c010001,
-0xac245ccc, 0x3c010001, 0x8005083, 0xac207df8,
-0x3c010001, 0x8005083, 0xac227dd0, 0x8f830054,
-0x3c020001, 0x8c427df4, 0x2463d8f0, 0x431023,
-0x2c422710, 0x14400003, 0x24020004, 0x3c010001,
-0xac227dd0, 0x3c020001, 0x8c427e10, 0x14400026,
-0x3c03fdff, 0x8ee20000, 0x3463ffff, 0x431024,
-0x8005083, 0xaee20000, 0x3c040001, 0x8c845d9c,
-0x3c010001, 0xc00508a, 0xac207de8, 0x3c020001,
-0x8c427e1c, 0xaf820204, 0x3c020001, 0x8c427e10,
-0x14400015, 0x3c03fdff, 0x8ee20000, 0x3463ffff,
-0x431024, 0xaee20000, 0x8f820204, 0x30420030,
-0x1440013c, 0x24020002, 0x3c030001, 0x8c637e1c,
-0x24020005, 0x3c010001, 0xac227dd0, 0x3c010001,
-0x8005083, 0xac237e20, 0x3c020001, 0x8c427e10,
-0x10400010, 0x3c03fdff, 0x3c020001, 0x8c425d6c,
-0x24420001, 0x3c010001, 0xac225d6c, 0x2c420002,
-0x14400131, 0x24020001, 0x3c010001, 0xac225d74,
-0x3c010001, 0xac205d6c, 0x3c010001, 0x8005083,
-0xac225ccc, 0x8ee20000, 0x3463ffff, 0x431024,
-0xaee20000, 0x3c020001, 0x8c427e00, 0x10400122,
-0x0, 0x3c020001, 0x8c427ddc, 0x1040011e,
-0x0, 0x3c010001, 0xac227e08, 0x24020003,
-0x3c010001, 0xac227de0, 0x8005024, 0x24020006,
-0x3c010001, 0xac207de8, 0x8f820204, 0x34420040,
-0xaf820204, 0x3c020001, 0x8c427e20, 0x24030007,
-0x3c010001, 0xac237dd0, 0x34420040, 0x3c010001,
-0xac227e20, 0x3c020001, 0x8c427e00, 0x10400005,
-0x0, 0x3c020001, 0x8c427ddc, 0x104000f9,
-0x24020002, 0x3c050001, 0x24a57de0, 0x8ca20000,
-0x2c424e21, 0x104000f3, 0x24020002, 0x3c020001,
-0x8c427e04, 0x104000f8, 0x2404ffbf, 0x3c020001,
-0x8c427ddc, 0x3c030001, 0x8c637e08, 0x441024,
-0x641824, 0x10430004, 0x24020001, 0x3c010001,
-0x8005083, 0xac227dd0, 0x24020003, 0xaca20000,
-0x24020008, 0x3c010001, 0xac227dd0, 0x3c020001,
-0x8c427e0c, 0x1040000c, 0x24020001, 0x3c040001,
-0xc005097, 0x8c847ddc, 0x3c020001, 0x8c427e28,
-0x14400005, 0x24020001, 0x3c020001, 0x8c427e24,
-0x10400006, 0x24020001, 0x3c010001, 0xac225ccc,
-0x3c010001, 0x8005083, 0xac207df8, 0x3c020001,
-0x8c427df0, 0x3c030001, 0x8c637ddc, 0x2c420001,
-0x210c0, 0x30630008, 0x3c010001, 0xac227df0,
-0x3c010001, 0xac237dec, 0x8f830054, 0x24020009,
-0x3c010001, 0xac227dd0, 0x3c010001, 0x8005083,
-0xac237df4, 0x8f830054, 0x3c020001, 0x8c427df4,
-0x2463d8f0, 0x431023, 0x2c422710, 0x144000a8,
-0x0, 0x3c020001, 0x8c427e00, 0x10400005,
-0x0, 0x3c020001, 0x8c427ddc, 0x104000a9,
-0x24020002, 0x3c030001, 0x24637de0, 0x8c620000,
-0x2c424e21, 0x104000a3, 0x24020002, 0x3c020001,
-0x8c427e0c, 0x1040000e, 0x0, 0x3c020001,
-0x8c427ddc, 0x3c010001, 0xac207e0c, 0x30420080,
-0x1040002f, 0x2402000c, 0x8f820204, 0x30420080,
-0x1440000c, 0x24020003, 0x8005011, 0x2402000c,
-0x3c020001, 0x8c427ddc, 0x30420080, 0x14400005,
-0x24020003, 0x8f820204, 0x30420080, 0x1040001f,
-0x24020003, 0xac620000, 0x2402000a, 0x3c010001,
-0xac227dd0, 0x3c040001, 0x24847e18, 0x8c820000,
-0x3c030001, 0x8c637df0, 0x431025, 0xaf820204,
-0x8c830000, 0x3c040001, 0x8c847df0, 0x2402000b,
-0x3c010001, 0xac227dd0, 0x641825, 0x3c010001,
-0xac237e20, 0x3c050001, 0x24a57de0, 0x8ca20000,
-0x2c424e21, 0x1040006f, 0x24020002, 0x3c020001,
-0x8c427e10, 0x10400005, 0x0, 0x2402000c,
-0x3c010001, 0x8005083, 0xac227dd0, 0x3c020001,
-0x8c427e00, 0x1040006c, 0x0, 0x3c040001,
-0x8c847ddc, 0x1080005e, 0x30820008, 0x3c030001,
-0x8c637dec, 0x10620064, 0x24020003, 0x3c010001,
-0xac247e08, 0xaca20000, 0x24020006, 0x3c010001,
-0x8005083, 0xac227dd0, 0x8f820200, 0x34420002,
-0xaf820200, 0x8f830054, 0x2402000d, 0x3c010001,
-0xac227dd0, 0x3c010001, 0xac237df4, 0x8f830054,
-0x3c020001, 0x8c427df4, 0x2463d8f0, 0x431023,
-0x2c422710, 0x1440003a, 0x0, 0x3c020001,
-0x8c427e10, 0x10400029, 0x2402000e, 0x3c030001,
-0x8c637e24, 0x3c010001, 0x14600015, 0xac227dd0,
-0xc0043dd, 0x0, 0x3c050001, 0x8ca55cc8,
-0xc0052a2, 0x2021, 0x3c030001, 0x8c635cc8,
-0x24020004, 0x14620005, 0x2403fffb, 0x3c020001,
-0x8c425cc4, 0x8005052, 0x2403fff7, 0x3c020001,
-0x8c425cc4, 0x431024, 0x3c010001, 0xac225cc4,
-0x8ee20000, 0x3c030200, 0x431025, 0xaee20000,
-0x8f820224, 0x3c010001, 0xac227e2c, 0x8f820220,
-0x2403fffb, 0x431024, 0xaf820220, 0x8f820220,
-0x34420002, 0x8005083, 0xaf820220, 0x3c020001,
-0x8c427e00, 0x10400005, 0x0, 0x3c020001,
-0x8c427ddc, 0x1040000f, 0x24020002, 0x3c020001,
-0x8c427de0, 0x2c424e21, 0x1040000a, 0x24020002,
-0x3c020001, 0x8c427e00, 0x1040000f, 0x0,
-0x3c020001, 0x8c427ddc, 0x1440000b, 0x0,
-0x24020002, 0x3c010001, 0x8005083, 0xac227dd0,
-0x3c020001, 0x8c427e00, 0x10400003, 0x0,
-0xc00429b, 0x0, 0x8f820220, 0x3c03f700,
-0x431025, 0xaf820220, 0x8fbf0010, 0x3e00008,
-0x27bd0018, 0x3c030001, 0x24637e28, 0x8c620000,
-0x10400005, 0x34422000, 0x3c010001, 0xac227e1c,
-0x8005095, 0xac600000, 0x3c010001, 0xac247e1c,
-0x3e00008, 0x0, 0x27bdffe0, 0x30820030,
-0xafbf0018, 0x3c010001, 0xac227e24, 0x14400067,
-0x3c02ffff, 0x34421f0e, 0x821024, 0x14400061,
-0x24020030, 0x30822000, 0x1040005d, 0x30838000,
-0x31a02, 0x30820001, 0x21200, 0x3c040001,
-0x8c845d9c, 0x621825, 0x331c2, 0x3c030001,
-0x24635d78, 0x30828000, 0x21202, 0x30840001,
-0x42200, 0x441025, 0x239c2, 0x61080,
-0x431021, 0x471021, 0x90430000, 0x24020001,
-0x10620025, 0x0, 0x10600007, 0x24020002,
-0x10620013, 0x24020003, 0x1062002c, 0x3c05000f,
-0x80050f9, 0x0, 0x8f820200, 0x2403feff,
-0x431024, 0xaf820200, 0x8f820220, 0x3c03fffe,
-0x3463ffff, 0x431024, 0xaf820220, 0x3c010001,
-0xac207e44, 0x3c010001, 0x8005104, 0xac207e4c,
-0x8f820200, 0x34420100, 0xaf820200, 0x8f820220,
-0x3c03fffe, 0x3463ffff, 0x431024, 0xaf820220,
-0x24020100, 0x3c010001, 0xac227e44, 0x3c010001,
-0x8005104, 0xac207e4c, 0x8f820200, 0x2403feff,
-0x431024, 0xaf820200, 0x8f820220, 0x3c030001,
-0x431025, 0xaf820220, 0x3c010001, 0xac207e44,
-0x3c010001, 0x8005104, 0xac237e4c, 0x8f820200,
-0x34420100, 0xaf820200, 0x8f820220, 0x3c030001,
-0x431025, 0xaf820220, 0x24020100, 0x3c010001,
-0xac227e44, 0x3c010001, 0x8005104, 0xac237e4c,
-0x34a5ffff, 0x3c040001, 0x24845bb8, 0xafa30010,
-0xc002403, 0xafa00014, 0x8005104, 0x0,
-0x24020030, 0x3c010001, 0xac227e28, 0x8fbf0018,
-0x3e00008, 0x27bd0020, 0x0, 0x27bdffc8,
-0xafb20028, 0x809021, 0xafb3002c, 0xa09821,
-0xafb00020, 0xc08021, 0x3c040001, 0x24845bd0,
-0x3c050009, 0x3c020001, 0x8c425cc8, 0x34a59001,
-0x2403021, 0x2603821, 0xafbf0030, 0xafb10024,
-0xa7a0001a, 0xafb00014, 0xc002403, 0xafa20010,
-0x24020002, 0x12620083, 0x2e620003, 0x10400005,
-0x24020001, 0x1262000a, 0x0, 0x800529b,
-0x0, 0x24020004, 0x126200fa, 0x24020008,
-0x126200f9, 0x3c02ffec, 0x800529b, 0x0,
-0x3c020001, 0x8c425cc4, 0x30420002, 0x14400004,
-0x128940, 0x3c02fffb, 0x3442ffff, 0x2028024,
-0x3c010001, 0x310821, 0xac307e3c, 0x3c024000,
-0x2021024, 0x1040004e, 0x1023c2, 0x30840030,
-0x101382, 0x3042001c, 0x3c030001, 0x24635d08,
-0x431021, 0x823821, 0x3c020020, 0x2021024,
-0x10400006, 0x24020100, 0x3c010001, 0x310821,
-0xac227e40, 0x8005150, 0x3c020080, 0x3c010001,
-0x310821, 0xac207e40, 0x3c020080, 0x2021024,
-0x10400006, 0x121940, 0x3c020001, 0x3c010001,
-0x230821, 0x800515c, 0xac227e48, 0x121140,
-0x3c010001, 0x220821, 0xac207e48, 0x94e40000,
-0x3c030001, 0x8c635dbc, 0x24020005, 0x10620010,
-0xa7a40018, 0x32024000, 0x10400002, 0x34824000,
-0xa7a20018, 0x24040001, 0x94e20002, 0x24050004,
-0x24e60002, 0x34420001, 0xc00498e, 0xa4e20002,
-0x24040001, 0x2821, 0xc00498e, 0x27a60018,
-0x3c020001, 0x8c425cc8, 0x24110001, 0x3c010001,
-0xac315cd4, 0x14530004, 0x32028000, 0xc00429b,
-0x0, 0x32028000, 0x1040011f, 0x0,
-0xc00429b, 0x0, 0x3c030001, 0x8c635dbc,
-0x24020005, 0x10620118, 0x24020002, 0x3c010001,
-0xac315ccc, 0x3c010001, 0x800529b, 0xac225cc8,
-0x24040001, 0x24050004, 0x27b0001a, 0xc00498e,
-0x2003021, 0x24040001, 0x2821, 0xc00498e,
-0x2003021, 0x3c020001, 0x511021, 0x8c427e34,
-0x3c040001, 0x8c845cc8, 0x3c03bfff, 0x3463ffff,
-0x3c010001, 0xac335cd4, 0x431024, 0x3c010001,
-0x310821, 0x109300fa, 0xac227e34, 0x800529b,
-0x0, 0x3c022000, 0x2021024, 0x10400005,
-0x24020001, 0x3c010001, 0xac225d98, 0x80051ad,
-0x128940, 0x3c010001, 0xac205d98, 0x128940,
-0x3c010001, 0x310821, 0xac307e38, 0x3c024000,
-0x2021024, 0x14400016, 0x0, 0x3c020001,
-0x8c425d98, 0x10400008, 0x24040004, 0x24050001,
-0xc004d93, 0x24062000, 0x24020001, 0x3c010001,
-0x370821, 0xac2283ac, 0x3c020001, 0x511021,
-0x8c427e30, 0x3c03bfff, 0x3463ffff, 0x431024,
-0x3c010001, 0x310821, 0x8005299, 0xac227e30,
-0x3c020001, 0x8c425d98, 0x10400028, 0x3c0300a0,
-0x2031024, 0x5443000d, 0x3c020020, 0x3c020001,
-0x8c425d9c, 0x24030100, 0x3c010001, 0x310821,
-0xac237e44, 0x3c030001, 0x3c010001, 0x310821,
-0xac237e4c, 0x80051f0, 0x34420400, 0x2021024,
-0x10400008, 0x24030100, 0x3c020001, 0x8c425d9c,
-0x3c010001, 0x310821, 0xac237e44, 0x80051f0,
-0x34420800, 0x3c020080, 0x2021024, 0x1040002e,
-0x3c030001, 0x3c020001, 0x8c425d9c, 0x3c010001,
-0x310821, 0xac237e4c, 0x34420c00, 0x3c010001,
-0xac225d9c, 0x8005218, 0x24040001, 0x3c020020,
-0x2021024, 0x10400006, 0x24020100, 0x3c010001,
-0x310821, 0xac227e44, 0x8005201, 0x3c020080,
-0x3c010001, 0x310821, 0xac207e44, 0x3c020080,
-0x2021024, 0x10400007, 0x121940, 0x3c020001,
-0x3c010001, 0x230821, 0xac227e4c, 0x800520f,
-0x24040001, 0x121140, 0x3c010001, 0x220821,
-0xac207e4c, 0x24040001, 0x2821, 0x27b0001e,
-0xc00494c, 0x2003021, 0x24040001, 0x2821,
-0xc00494c, 0x2003021, 0x24040001, 0x24050001,
-0x27b0001c, 0xc00494c, 0x2003021, 0x24040001,
-0x24050001, 0xc00494c, 0x2003021, 0x8005299,
-0x0, 0x3c02ffec, 0x3442ffff, 0x2028024,
-0x3c020008, 0x2028025, 0x121140, 0x3c010001,
-0x220821, 0xac307e38, 0x3c022000, 0x2021024,
-0x10400009, 0x0, 0x3c020001, 0x8c425d74,
-0x14400005, 0x24020001, 0x3c010001, 0xac225d98,
-0x800523a, 0x3c024000, 0x3c010001, 0xac205d98,
-0x3c024000, 0x2021024, 0x1440001e, 0x0,
-0x3c020001, 0x8c425d98, 0x3c010001, 0xac205ce0,
-0x10400007, 0x24022020, 0x3c010001, 0xac225d9c,
-0x24020001, 0x3c010001, 0x370821, 0xac2283ac,
-0x3c04bfff, 0x121940, 0x3c020001, 0x431021,
-0x8c427e30, 0x3c050001, 0x8ca55cc8, 0x3484ffff,
-0x441024, 0x3c010001, 0x230821, 0xac227e30,
-0x24020001, 0x10a20044, 0x0, 0x8005299,
-0x0, 0x3c020001, 0x8c425d98, 0x1040001c,
-0x24022000, 0x3c010001, 0xac225d9c, 0x3c0300a0,
-0x2031024, 0x14430005, 0x121140, 0x3402a000,
-0x3c010001, 0x8005294, 0xac225d9c, 0x3c030001,
-0x621821, 0x8c637e38, 0x3c020020, 0x621024,
-0x10400004, 0x24022001, 0x3c010001, 0x8005294,
-0xac225d9c, 0x3c020080, 0x621024, 0x1040001f,
-0x3402a001, 0x3c010001, 0x8005294, 0xac225d9c,
-0x3c020020, 0x2021024, 0x10400007, 0x121940,
-0x24020100, 0x3c010001, 0x230821, 0xac227e44,
-0x8005288, 0x3c020080, 0x121140, 0x3c010001,
-0x220821, 0xac207e44, 0x3c020080, 0x2021024,
-0x10400006, 0x121940, 0x3c020001, 0x3c010001,
-0x230821, 0x8005294, 0xac227e4c, 0x121140,
-0x3c010001, 0x220821, 0xac207e4c, 0x3c030001,
-0x8c635cc8, 0x24020001, 0x10620003, 0x0,
-0xc00429b, 0x0, 0x8fbf0030, 0x8fb3002c,
-0x8fb20028, 0x8fb10024, 0x8fb00020, 0x3e00008,
-0x27bd0038, 0x27bdffd8, 0xafb20020, 0x809021,
-0xafb1001c, 0x8821, 0x24020002, 0xafbf0024,
-0xafb00018, 0xa7a00012, 0x10a200d3, 0xa7a00010,
-0x2ca20003, 0x10400005, 0x24020001, 0x10a2000a,
-0x128140, 0x8005380, 0x2201021, 0x24020004,
-0x10a2007d, 0x24020008, 0x10a2007c, 0x122940,
-0x8005380, 0x2201021, 0x3c030001, 0x701821,
-0x8c637e3c, 0x3c024000, 0x621024, 0x14400009,
-0x24040001, 0x3c027fff, 0x3442ffff, 0x628824,
-0x3c010001, 0x300821, 0xac317e34, 0x8005380,
-0x2201021, 0x24050001, 0xc00494c, 0x27a60010,
-0x24040001, 0x24050001, 0xc00494c, 0x27a60010,
-0x97a20010, 0x30420004, 0x10400034, 0x3c114000,
-0x3c020001, 0x8c425dbc, 0x2443ffff, 0x2c620006,
-0x10400034, 0x31080, 0x3c010001, 0x220821,
-0x8c225be0, 0x400008, 0x0, 0x24040001,
-0x24050011, 0x27b00012, 0xc00494c, 0x2003021,
-0x24040001, 0x24050011, 0xc00494c, 0x2003021,
-0x97a50012, 0x30a24000, 0x10400002, 0x3c040010,
-0x3c040008, 0x3c030001, 0x8005301, 0x30a28000,
-0x24040001, 0x24050014, 0x27b00012, 0xc00494c,
-0x2003021, 0x24040001, 0x24050014, 0xc00494c,
-0x2003021, 0x97a50012, 0x30a21000, 0x10400002,
-0x3c040010, 0x3c040008, 0x3c030001, 0x30a20800,
-0x54400001, 0x3c030002, 0x3c028000, 0x2221025,
-0x641825, 0x800530e, 0x438825, 0x3c110001,
-0x2308821, 0x8e317e3c, 0x3c027fff, 0x3442ffff,
-0x2228824, 0x3c020001, 0x8c425cd8, 0x1040001d,
-0x121140, 0x3c020001, 0x8c425d98, 0x10400002,
-0x3c022000, 0x2228825, 0x121140, 0x3c010001,
-0x220821, 0x8c227e40, 0x10400003, 0x3c020020,
-0x8005322, 0x2228825, 0x3c02ffdf, 0x3442ffff,
-0x2228824, 0x121140, 0x3c010001, 0x220821,
-0x8c227e48, 0x10400003, 0x3c020080, 0x800532d,
-0x2228825, 0x3c02ff7f, 0x3442ffff, 0x2228824,
-0x121140, 0x3c010001, 0x220821, 0xac317e34,
-0x8005380, 0x2201021, 0x122940, 0x3c030001,
-0x651821, 0x8c637e38, 0x3c024000, 0x621024,
-0x14400008, 0x3c027fff, 0x3442ffff, 0x628824,
-0x3c010001, 0x250821, 0xac317e30, 0x8005380,
-0x2201021, 0x3c020001, 0x8c425cd8, 0x10400033,
-0x3c11c00c, 0x3c020001, 0x8c425d74, 0x3c04c00c,
-0x34842000, 0x3c030001, 0x8c635d98, 0x2102b,
-0x21023, 0x441024, 0x10600003, 0x518825,
-0x3c022000, 0x2228825, 0x3c020001, 0x451021,
-0x8c427e44, 0x10400003, 0x3c020020, 0x800535d,
-0x2228825, 0x3c02ffdf, 0x3442ffff, 0x2228824,
-0x121140, 0x3c010001, 0x220821, 0x8c227e4c,
-0x10400003, 0x3c020080, 0x8005368, 0x2228825,
-0x3c02ff7f, 0x3442ffff, 0x2228824, 0x3c020001,
-0x8c425d60, 0x10400002, 0x3c020800, 0x2228825,
-0x3c020001, 0x8c425d64, 0x10400002, 0x3c020400,
-0x2228825, 0x3c020001, 0x8c425d68, 0x10400006,
-0x3c020100, 0x800537b, 0x2228825, 0x3c027fff,
-0x3442ffff, 0x628824, 0x121140, 0x3c010001,
-0x220821, 0xac317e30, 0x2201021, 0x8fbf0024,
-0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x3e00008,
-0x27bd0028, 0x27bdffd8, 0xafb40020, 0x80a021,
-0xafbf0024, 0xafb3001c, 0xafb20018, 0xafb10014,
-0xafb00010, 0x8f900200, 0x3c030001, 0x8c635cc8,
-0x8f930220, 0x24020002, 0x10620063, 0x2c620003,
-0x10400005, 0x24020001, 0x1062000a, 0x141940,
-0x8005448, 0x0, 0x24020004, 0x1062005a,
-0x24020008, 0x10620059, 0x149140, 0x8005448,
-0x0, 0x3c040001, 0x832021, 0x8c847e3c,
-0x3c110001, 0x2238821, 0x8e317e34, 0x3c024000,
-0x821024, 0x1040003e, 0x3c020008, 0x2221024,
-0x10400020, 0x36100002, 0x3c020001, 0x431021,
-0x8c427e40, 0x10400005, 0x36100020, 0x36100100,
-0x3c020020, 0x80053bd, 0x2228825, 0x2402feff,
-0x2028024, 0x3c02ffdf, 0x3442ffff, 0x2228824,
-0x141140, 0x3c010001, 0x220821, 0x8c227e48,
-0x10400005, 0x3c020001, 0x2629825, 0x3c020080,
-0x80053dc, 0x2228825, 0x3c02fffe, 0x3442ffff,
-0x2629824, 0x3c02ff7f, 0x3442ffff, 0x80053dc,
-0x2228824, 0x2402fedf, 0x2028024, 0x3c02fffe,
-0x3442ffff, 0x2629824, 0x3c02ff5f, 0x3442ffff,
-0x2228824, 0x3c010001, 0x230821, 0xac207e40,
-0x3c010001, 0x230821, 0xac207e48, 0xc00486a,
-0x0, 0xaf900200, 0xaf930220, 0x8f820220,
-0x2403fffb, 0x431024, 0xaf820220, 0x8f820220,
-0x34420002, 0xaf820220, 0x80053f3, 0x141140,
-0x8f820200, 0x2403fffd, 0x431024, 0xc00486a,
-0xaf820200, 0x3c02bfff, 0x3442ffff, 0xc00429b,
-0x2228824, 0x141140, 0x3c010001, 0x220821,
-0x8005448, 0xac317e34, 0x149140, 0x3c040001,
-0x922021, 0x8c847e38, 0x3c110001, 0x2328821,
-0x8e317e30, 0x3c024000, 0x821024, 0x14400011,
-0x0, 0x3c020001, 0x8c425d98, 0x14400006,
-0x3c02bfff, 0x8f820200, 0x34420002, 0xc00486a,
-0xaf820200, 0x3c02bfff, 0x3442ffff, 0xc00429b,
-0x2228824, 0x3c010001, 0x320821, 0x8005448,
-0xac317e30, 0x3c020001, 0x8c425d98, 0x10400005,
-0x3c020020, 0x3c020001, 0x8c425d74, 0x1040002b,
-0x3c020020, 0x821024, 0x10400007, 0x36100020,
-0x24020100, 0x3c010001, 0x320821, 0xac227e44,
-0x8005428, 0x36100100, 0x3c010001, 0x320821,
-0xac207e44, 0x2402feff, 0x2028024, 0x3c020080,
-0x821024, 0x10400007, 0x141940, 0x3c020001,
-0x3c010001, 0x230821, 0xac227e4c, 0x8005439,
-0x2629825, 0x141140, 0x3c010001, 0x220821,
-0xac207e4c, 0x3c02fffe, 0x3442ffff, 0x2629824,
-0xc00486a, 0x0, 0xaf900200, 0xaf930220,
-0x8f820220, 0x2403fffb, 0x431024, 0xaf820220,
-0x8f820220, 0x34420002, 0xaf820220, 0x141140,
-0x3c010001, 0x220821, 0xac317e30, 0x8fbf0024,
-0x8fb40020, 0x8fb3001c, 0x8fb20018, 0x8fb10014,
-0x8fb00010, 0x3e00008, 0x27bd0028, 0x0 };
-static u_int32_t tigonFwRodata[] = {
-0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e,
-0x2f66776d, 0x61696e2e, 0x632c7620, 0x312e312e,
-0x322e3131, 0x20313939, 0x382f3034, 0x2f323720,
-0x32323a31, 0x333a3432, 0x20736875, 0x616e6720,
-0x45787020, 0x24000000, 0x7468655f, 0x4441574e,
-0x0, 0x53544143, 0x4b5f3120, 0x0,
-0x42616453, 0x6e64526e, 0x67000000, 0x3f456e71,
-0x45767400, 0x3f6e6f51, 0x64457650, 0x0,
-0x6576526e, 0x6746756c, 0x6c000000, 0x496c6c43,
-0x6f6e6652, 0x78000000, 0x53656e64, 0x436b5375,
-0x6d000000, 0x52656376, 0x566c616e, 0x0,
-0x0, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e,
-0x2f74696d, 0x65722e63, 0x2c762031, 0x2e312e32,
-0x2e382031, 0x3939382f, 0x30372f33, 0x31203137,
-0x3a35383a, 0x34352073, 0x6875616e, 0x67204578,
-0x70202400, 0x542d446d, 0x61526431, 0x0,
-0x542d446d, 0x61424200, 0x542d446d, 0x61320000,
-0x3f6e6f51, 0x64547845, 0x0, 0x3f6e6f51,
-0x64527845, 0x0, 0x656e714d, 0x45765046,
-0x61696c00, 0x656e714d, 0x45764661, 0x696c0000,
-0x6661696c, 0x456e454d, 0x0, 0x3f456e71,
-0x45767400, 0x3f6e6f51, 0x64457650, 0x0,
-0x6576526e, 0x6746756c, 0x6c000000, 0x0,
-0x0, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e,
-0x2f636f6d, 0x6d616e64, 0x2e632c76, 0x20312e31,
-0x2e322e31, 0x30203139, 0x39382f31, 0x312f3138,
-0x2031373a, 0x31313a31, 0x38207368, 0x75616e67,
-0x20457870, 0x20240000, 0x3f4d626f, 0x78457674,
-0x0, 0x4e4f636f, 0x6d616e64, 0x0,
-0x68737465, 0x5f455252, 0x0, 0x412d4572,
-0x72427563, 0x0, 0x4552524f, 0x522d4164,
-0x64000000, 0x656e714d, 0x45765046, 0x61696c00,
-0x656e714d, 0x45764661, 0x696c0000, 0x6661696c,
-0x456e454d, 0x0, 0x442d4572, 0x724c6173,
-0x74000000, 0x442d4572, 0x72320000, 0x6d437374,
-0x4d644552, 0x52000000, 0x70726f6d, 0x4d644552,
-0x52000000, 0x46696c74, 0x4d644552, 0x52000000,
-0x636d645f, 0x45525200, 0x3f456e71, 0x45767400,
-0x3f6e6f51, 0x64457650, 0x0, 0x6576526e,
-0x6746756c, 0x6c000000, 0x0, 0x6ea0,
-0x7fbc, 0x6e38, 0x8734, 0x82b0,
-0x8780, 0x8780, 0x6f54, 0x7694,
-0x7f0c, 0x80a8, 0x8074, 0x8780,
-0x7e70, 0x80cc, 0x6e64, 0x81cc,
-0x0, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e,
-0x2f646d61, 0x2e632c76, 0x20312e31, 0x2e322e33,
-0x20313939, 0x382f3034, 0x2f323720, 0x32323a31,
-0x333a3431, 0x20736875, 0x616e6720, 0x45787020,
-0x24000000, 0x646d6172, 0x6441544e, 0x0,
-0x646d6177, 0x7241544e, 0x0, 0x0,
-0x0, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e,
-0x2f747261, 0x63652e63, 0x2c762031, 0x2e312e32,
-0x2e322031, 0x3939382f, 0x30342f32, 0x37203232,
-0x3a31333a, 0x35302073, 0x6875616e, 0x67204578,
-0x70202400, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e,
-0x2f646174, 0x612e632c, 0x7620312e, 0x312e322e,
-0x32203139, 0x39382f30, 0x342f3237, 0x2032323a,
-0x31333a34, 0x30207368, 0x75616e67, 0x20457870,
-0x20240000, 0x46575f56, 0x45525349, 0x4f4e3a20,
-0x23312046, 0x72692041, 0x70722037, 0x2031373a,
-0x35353a34, 0x38205044, 0x54203230, 0x30300000,
-0x46575f43, 0x4f4d5049, 0x4c455f54, 0x494d453a,
-0x2031373a, 0x35353a34, 0x38000000, 0x46575f43,
-0x4f4d5049, 0x4c455f42, 0x593a2064, 0x65767263,
-0x73000000, 0x46575f43, 0x4f4d5049, 0x4c455f48,
-0x4f53543a, 0x20636f6d, 0x70757465, 0x0,
-0x46575f43, 0x4f4d5049, 0x4c455f44, 0x4f4d4149,
-0x4e3a2065, 0x6e672e61, 0x6374656f, 0x6e2e636f,
-0x6d000000, 0x46575f43, 0x4f4d5049, 0x4c45523a,
-0x20676363, 0x20766572, 0x73696f6e, 0x20322e37,
-0x2e320000, 0x0, 0x0, 0x0,
-0x0, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e,
-0x2f6d656d, 0x2e632c76, 0x20312e31, 0x2e322e32,
-0x20313939, 0x382f3034, 0x2f323720, 0x32323a31,
-0x333a3434, 0x20736875, 0x616e6720, 0x45787020,
-0x24000000, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e,
-0x2f73656e, 0x642e632c, 0x7620312e, 0x312e322e,
-0x31312031, 0x3939382f, 0x31322f32, 0x32203137,
-0x3a31373a, 0x35352073, 0x6875616e, 0x67204578,
-0x70202400, 0x736e6464, 0x654e6f51, 0x20000000,
-0x6e6f454e, 0x515f5458, 0x0, 0x736e6464,
-0x744e6f51, 0x20000000, 0x3f6e6f51, 0x64547845,
-0x0, 0x756e6b72, 0x64747970, 0x65000000,
-0x0, 0xaccc, 0xaccc, 0xad9c,
-0xaab0, 0xaab0, 0xad9c, 0xad9c,
-0xad9c, 0xad9c, 0xad9c, 0xad9c,
-0xad9c, 0xad9c, 0xad9c, 0xad9c,
-0xad9c, 0xad9c, 0xad9c, 0xad7c,
-0x0, 0xbca8, 0xbca8, 0xbd70,
-0xae4c, 0xb058, 0xbd70, 0xbd70,
-0xbd70, 0xbd70, 0xbd70, 0xbd70,
-0xbd70, 0xbd70, 0xbd70, 0xbd70,
-0xbd70, 0xbd70, 0xbd70, 0xbd54,
-0xb040, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e,
-0x2f726563, 0x762e632c, 0x7620312e, 0x312e322e,
-0x31392031, 0x3939382f, 0x30372f32, 0x34203231,
-0x3a33303a, 0x30352073, 0x6875616e, 0x67204578,
-0x70202400, 0x706b5278, 0x45525200, 0x66726d32,
-0x4c617267, 0x65000000, 0x72784e6f, 0x52784264,
-0x0, 0x72785144, 0x6d614446, 0x0,
-0x72785144, 0x6d614246, 0x0, 0x3f6e6f51,
-0x64527845, 0x0, 0x706b5278, 0x45525273,
-0x0, 0x66726d32, 0x4c726753, 0x0,
-0x72784e6f, 0x42645300, 0x3f724264, 0x446d6146,
-0x0, 0x3f724a42, 0x64446d46, 0x0,
-0x0, 0xf678, 0xf678, 0xf678,
-0xf678, 0xf678, 0xf678, 0xf678,
-0xf678, 0xf678, 0xf678, 0xf678,
-0xf678, 0xf678, 0xf678, 0xf678,
-0xf670, 0xf670, 0xf670, 0x572d444d,
-0x41456e46, 0x0, 0x0, 0xfdc0,
-0x1015c, 0xfddc, 0x1015c, 0x1015c,
-0x1015c, 0x1015c, 0x1015c, 0x1015c,
-0xf704, 0x1015c, 0x1015c, 0x1015c,
-0x1015c, 0x1015c, 0x10154, 0x10154,
-0x10154, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e,
-0x2f6d6163, 0x2e632c76, 0x20312e31, 0x2e322e31,
-0x32203139, 0x39382f30, 0x342f3237, 0x2032323a,
-0x31333a34, 0x32207368, 0x75616e67, 0x20457870,
-0x20240000, 0x6d616374, 0x7841544e, 0x0,
-0x4e745379, 0x6e264c6b, 0x0, 0x72656d61,
-0x73737274, 0x0, 0x6c696e6b, 0x444f574e,
-0x0, 0x656e714d, 0x45765046, 0x61696c00,
-0x656e714d, 0x45764661, 0x696c0000, 0x6661696c,
-0x456e454d, 0x0, 0x6c696e6b, 0x55500000,
-0x0, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e,
-0x2f636b73, 0x756d2e63, 0x2c762031, 0x2e312e32,
-0x2e322031, 0x3939382f, 0x30342f32, 0x37203232,
-0x3a31333a, 0x33392073, 0x6875616e, 0x67204578,
-0x70202400, 0x50726f62, 0x65506879, 0x0,
-0x6c6e6b41, 0x53535254, 0x0, 0x11b2c,
-0x11bc4, 0x11bf8, 0x11c2c, 0x11c58,
-0x11c6c, 0x11ca8, 0x1207c, 0x11de4,
-0x11e24, 0x11e50, 0x11e90, 0x11ec0,
-0x11efc, 0x11f30, 0x1207c, 0x122c0,
-0x122d8, 0x12300, 0x12320, 0x12348,
-0x12478, 0x124a0, 0x124f4, 0x1251c,
-0x0, 0x1278c, 0x1285c, 0x12934,
-0x12a04, 0x12a60, 0x12b3c, 0x12b64,
-0x12c40, 0x12c68, 0x12e10, 0x12e38,
-0x12fe0, 0x131d8, 0x1346c, 0x13380,
-0x1346c, 0x13498, 0x13008, 0x131b0,
-0x0, 0x13b84, 0x13bc8, 0x13c60,
-0x13cac, 0x13d1c, 0x13db4, 0x13de8,
-0x13e70, 0x13f08, 0x13fd8, 0x14018,
-0x1409c, 0x140c0, 0x141f4, 0x646f4261,
-0x73655067, 0x0, 0x0, 0x0,
-0x0, 0x73746d61, 0x634c4e4b, 0x0,
-0x0, 0x14c38, 0x14c38, 0x14b80,
-0x14bc4, 0x14c38, 0x14c38, 0x0,
-0x0, 0x0 };
-static u_int32_t tigonFwData[] = {
-0x416c7465,
-0x6f6e2041, 0x63654e49, 0x43205600, 0x416c7465,
-0x6f6e2041, 0x63654e49, 0x43205600, 0x42424242,
-0x0, 0x0, 0x0, 0x135418,
-0x13e7fc, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x60cf00,
-0x60, 0xcf000000, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x3, 0x0,
-0x1, 0x0, 0x0, 0x0,
-0x1, 0x0, 0x1, 0x0,
-0x0, 0x0, 0x0, 0x1,
-0x1, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x1000000, 0x21000000,
-0x12000140, 0x0, 0x0, 0x20000000,
-0x120000a0, 0x0, 0x12000060, 0x12000180,
-0x120001e0, 0x0, 0x0, 0x0,
-0x1, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x2,
-0x0, 0x0, 0x30001, 0x1,
-0x30201, 0x0, 0x0, 0x0 };
diff --git a/sys/dev/ti/ti_fw2.h b/sys/dev/ti/ti_fw2.h
deleted file mode 100644
index e54c920531e5..000000000000
--- a/sys/dev/ti/ti_fw2.h
+++ /dev/null
@@ -1,5232 +0,0 @@
-/*
- * Generated by Ken's special genfw.c
- * Built on Wed Aug 2 17:21:09 MDT 2000 by ken@roadwarrior.plutotech.com
- * OS: FreeBSD 5.0-CURRENT
- * $FreeBSD$
- */
-static int tigon2FwReleaseMajor = 0xc;
-static int tigon2FwReleaseMinor = 0x4;
-static int tigon2FwReleaseFix = 0xb;
-static u_int32_t tigon2FwStartAddr = 0x00004000;
-static u_int32_t tigon2FwTextAddr = 0x00004000;
-int tigon2FwTextLen = 0x132f8;
-static u_int32_t tigon2FwRodataAddr = 0x000172f8;
-int tigon2FwRodataLen = 0x10da;
-static u_int32_t tigon2FwDataAddr = 0x000185c0;
-int tigon2FwDataLen = 0x17c;
-static u_int32_t tigon2FwSbssAddr = 0x0001873c;
-int tigon2FwSbssLen = 0xcc;
-static u_int32_t tigon2FwBssAddr = 0x00018810;
-int tigon2FwBssLen = 0x20c0;
-static u_int32_t tigon2FwText[] = {
-0x0,
-0x10000003, 0x0, 0xd, 0xd,
-0x3c1d0002, 0x8fbd8600, 0x3a0f021, 0x3c100000,
-0x26104000, 0xc001082, 0x0, 0xd,
-0x3c1d0002, 0x8fbd8604, 0x3a0f021, 0x3c100000,
-0x26104000, 0xc0018cc, 0x0, 0xd,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x2000008,
-0x0, 0x80017d9, 0x3c0a0001, 0x80017d9,
-0x3c0a0002, 0x80017d9, 0x0, 0x8002ec4,
-0x0, 0x8002e4e, 0x0, 0x80017d9,
-0x3c0a0004, 0x80035a3, 0x0, 0x8001b5a,
-0x0, 0x8003df3, 0x0, 0x8003d81,
-0x0, 0x80017d9, 0x3c0a0006, 0x8003e7a,
-0x3c0a0007, 0x80017d9, 0x3c0a0008, 0x80017d9,
-0x3c0a0009, 0x8003eeb, 0x0, 0x80030d9,
-0x0, 0x80017d9, 0x3c0a000b, 0x80017d9,
-0x3c0a000c, 0x80017d9, 0x3c0a000d, 0x8002af6,
-0x0, 0x8002a8a, 0x0, 0x80017d9,
-0x3c0a000e, 0x800219b, 0x0, 0x8001a69,
-0x0, 0x8001b0b, 0x0, 0x80041cb,
-0x0, 0x80041b9, 0x0, 0x80017d9,
-0x0, 0x8001a1f, 0x0, 0x80017d9,
-0x0, 0x80017d9, 0x3c0a0013, 0x80017d9,
-0x3c0a0014, 0x27bdffe0, 0x3c1cc000, 0xafbf001c,
-0xafb00018, 0x8f820140, 0x24030003, 0xaf8300ec,
-0x34420004, 0xaf820140, 0xc002d20, 0x0,
-0x3c0100c0, 0xac203ffc, 0xc00184f, 0x0,
-0x401821, 0x3c020010, 0x3c010002, 0xac238758,
-0x10620025, 0x43102b, 0x14400002, 0x3c020020,
-0x3c020008, 0x10620020, 0x24050100, 0x3c040001,
-0x248473ac, 0x3c060002, 0x8cc68758, 0x3821,
-0xafa00010, 0xc002d3b, 0xafa00014, 0x3c040001,
-0x248473b8, 0x24020256, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e773c0, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f830140,
-0x3c020020, 0x3c010002, 0xac228758, 0x3c020001,
-0x621825, 0xaf830140, 0x24020008, 0x3c010002,
-0xac228770, 0x2402001f, 0x3c010002, 0xac228780,
-0x24020016, 0x3c010002, 0xac228754, 0x3c05fffe,
-0x34a56f08, 0x3c020002, 0x8c428758, 0x3c030002,
-0x2463a8d0, 0x3c040002, 0x8c8485c4, 0x431023,
-0x14800002, 0x458021, 0x2610fa38, 0x2402f000,
-0x2028024, 0xc001871, 0x2002021, 0x2022823,
-0x3c040020, 0x821823, 0x651823, 0x247bb000,
-0x3c03fffe, 0x3463bf08, 0x363b821, 0x3c0600bf,
-0x34c6f000, 0x3c070002, 0x8ce785c0, 0x3c0300bf,
-0x3463e000, 0x852023, 0x3c010002, 0xac248764,
-0x822023, 0x3c010002, 0xac25874c, 0x52842,
-0x3c010002, 0xac228740, 0x27620ffc, 0x3c010002,
-0xac228600, 0x27621ffc, 0xdb3023, 0x7b1823,
-0x3c010002, 0xac248744, 0x3c010002, 0xac258768,
-0x3c010002, 0xac228604, 0xaf860150, 0xaf830250,
-0x10e00027, 0x33620fff, 0x10400014, 0x2402028b,
-0x3c040001, 0x248473b8, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e773c0, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x3c1d0002,
-0x8fbd85cc, 0x3a0f021, 0xc001807, 0x0,
-0x3c020002, 0x8c4285d0, 0x3c030002, 0x8c6385d4,
-0x2442fe00, 0x24630200, 0x3c010002, 0xac2285d0,
-0x3c010002, 0xac2385d4, 0x10000004, 0x0,
-0x3c1d0002, 0x8fbd8600, 0x3a0f021, 0x3c020002,
-0x8c4285c4, 0x1040000d, 0x26fafa38, 0x3c020002,
-0x8c4285d0, 0x3c030002, 0x8c6385d4, 0x3c1a0002,
-0x8f5a85d4, 0x2442fa38, 0x246305c8, 0x3c010002,
-0xac2285d0, 0x3c010002, 0xac2385d4, 0x3c020002,
-0x8c4285c8, 0x14400003, 0x0, 0x3c010002,
-0xac2085d0, 0xc001140, 0x0, 0x8fbf001c,
-0x8fb00018, 0x3e00008, 0x27bd0020, 0x3c020002,
-0x8c4285d0, 0x3c030002, 0x8c6385d4, 0x27bdff98,
-0xafb00048, 0x3c100001, 0x8e107d5c, 0xafb20050,
-0x3c120000, 0x26524100, 0xafbf0060, 0xafbe005c,
-0xafb50058, 0xafb30054, 0xafb1004c, 0xafa20034,
-0xafa30030, 0xafa00010, 0xafa00014, 0x8f860040,
-0x3c040001, 0x248473cc, 0x24050200, 0x3c010002,
-0xac32873c, 0xc002d3b, 0x2003821, 0x8f830040,
-0x3c02f000, 0x621824, 0x3c026000, 0x1062001f,
-0xa3a0003f, 0x3c040001, 0x248473d4, 0xafa00010,
-0xafa00014, 0x8f860040, 0x24050300, 0xc002d3b,
-0x2003821, 0x3c040001, 0x248473b8, 0x240202e1,
-0xafa20010, 0xafa00014, 0x8f860144, 0x3c070001,
-0x24e773c0, 0xc002d3b, 0x3405dead, 0x8f82011c,
-0x34420002, 0xaf82011c, 0x8f820220, 0x34420004,
-0xaf820220, 0x8f820140, 0x240e0001, 0x3c030001,
-0xa3ae003f, 0x431025, 0xaf820140, 0x8f820240,
-0x3c030001, 0x431025, 0xaf820240, 0xaf800048,
-0x8f820048, 0x14400005, 0x0, 0xaf800048,
-0x8f820048, 0x10400004, 0x0, 0xaf800048,
-0x10000003, 0x2e02021, 0xaf80004c, 0x2e02021,
-0x3c050001, 0xc002da8, 0x34a540f8, 0x3402021,
-0xc002da8, 0x240505c8, 0x3c020002, 0x8c428764,
-0x3c0d0002, 0x8dad8744, 0x3c030002, 0x8c638740,
-0x3c080002, 0x8d08874c, 0x3c090002, 0x8d298768,
-0x3c0a0002, 0x8d4a8770, 0x3c0b0002, 0x8d6b8780,
-0x3c0c0002, 0x8d8c8754, 0x3c040001, 0x248473e0,
-0x24050400, 0xaf42013c, 0x8f42013c, 0x24060001,
-0x24070001, 0xaf400000, 0xaf4d0138, 0xaf430144,
-0xaf480148, 0xaf49014c, 0xaf4a0150, 0xaf4b0154,
-0xaf4c0158, 0x2442ff80, 0xaf420140, 0x24020001,
-0xafa20010, 0xc002d3b, 0xafa00014, 0x8f420138,
-0xafa20010, 0x8f42013c, 0xafa20014, 0x8f460144,
-0x8f470148, 0x3c040001, 0x248473ec, 0xc002d3b,
-0x24050500, 0xafb70010, 0xafba0014, 0x8f46014c,
-0x8f470150, 0x3c040001, 0x248473f8, 0xc002d3b,
-0x24050600, 0x3c020002, 0x8c428758, 0x3603821,
-0x3c060002, 0x24c6a8d0, 0x2448ffff, 0x1061824,
-0xe81024, 0x43102b, 0x1040001a, 0x24050900,
-0x3c040001, 0x24847404, 0xafa80010, 0xc002d3b,
-0xafa00014, 0x3c040001, 0x248473b8, 0x2402033a,
-0xafa20010, 0xafa00014, 0x8f860144, 0x3c070001,
-0x24e773c0, 0xc002d3b, 0x3405dead, 0x8f82011c,
-0x34420002, 0xaf82011c, 0x8f820220, 0x34420004,
-0xaf820220, 0x8f820140, 0x3c030001, 0x431025,
-0xaf820140, 0x8f82000c, 0xafa20010, 0x8f82003c,
-0xafa20014, 0x8f860000, 0x8f870004, 0x3c040001,
-0x24847410, 0xc002d3b, 0x24051000, 0x8c020220,
-0x8c030224, 0x8c060218, 0x8c07021c, 0x3c040001,
-0x24847418, 0x24051100, 0xafa20010, 0xc002d3b,
-0xafa30014, 0xaf800054, 0xaf80011c, 0x8c020218,
-0x30420002, 0x10400009, 0x0, 0x8c020220,
-0x3c030002, 0x34630004, 0x431025, 0xaf42000c,
-0x8c02021c, 0x10000008, 0x34420004, 0x8c020220,
-0x3c030002, 0x34630006, 0x431025, 0xaf42000c,
-0x8c02021c, 0x34420006, 0xaf420014, 0x8c020218,
-0x30420010, 0x1040000a, 0x0, 0x8c02021c,
-0x34420004, 0xaf420010, 0x8c020220, 0x3c03000a,
-0x34630004, 0x431025, 0x10000009, 0xaf420008,
-0x8c020220, 0x3c03000a, 0x34630006, 0x431025,
-0xaf420008, 0x8c02021c, 0x34420006, 0xaf420010,
-0x24020001, 0xaf8200a0, 0xaf8200b0, 0x8f830054,
-0x8f820054, 0xaf8000d0, 0xaf8000c0, 0x10000002,
-0x24630064, 0x8f820054, 0x621023, 0x2c420065,
-0x1440fffc, 0x0, 0x8c040208, 0x8c05020c,
-0x26e20028, 0xaee20020, 0x24020490, 0xaee20010,
-0xaee40008, 0xaee5000c, 0x26e40008, 0x8c820000,
-0x8c830004, 0xaf820090, 0xaf830094, 0x8c820018,
-0xaf8200b4, 0x9482000a, 0xaf82009c, 0x8f420014,
-0xaf8200b0, 0x8f8200b0, 0x30420004, 0x1440fffd,
-0x0, 0x8f8200b0, 0x3c03ef00, 0x431024,
-0x10400021, 0x0, 0x8f8200b4, 0xafa20010,
-0x8f820090, 0x8f830094, 0x3c040001, 0x24847420,
-0xafa30014, 0x8f8600b0, 0x8f87009c, 0x3c050001,
-0xc002d3b, 0x34a5200d, 0x3c040001, 0x248473b8,
-0x240203c4, 0xafa20010, 0xafa00014, 0x8f860144,
-0x3c070001, 0x24e773c0, 0xc002d3b, 0x3405dead,
-0x8f82011c, 0x34420002, 0xaf82011c, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820140, 0x3c030001,
-0x431025, 0xaf820140, 0x96e20472, 0x96e60452,
-0x96e70462, 0xafa20010, 0x96e20482, 0x3c040001,
-0x2484742c, 0x24051200, 0xc002d3b, 0xafa20014,
-0x96f00452, 0x32020001, 0x10400002, 0xb021,
-0x24160001, 0x32020002, 0x54400001, 0x36d60002,
-0x32020008, 0x54400001, 0x36d60004, 0x32020010,
-0x54400001, 0x36d60008, 0x32020020, 0x54400001,
-0x36d60010, 0x32020040, 0x54400001, 0x36d60020,
-0x32020080, 0x54400001, 0x36d60040, 0x96e60482,
-0x30c20200, 0x54400001, 0x36d64000, 0x96e30472,
-0x30620200, 0x10400003, 0x30620100, 0x10000003,
-0x36d62000, 0x54400001, 0x36d61000, 0x96f00462,
-0x32c24000, 0x14400004, 0x3207009b, 0x30c2009b,
-0x14e20007, 0x0, 0x32c22000, 0x14400022,
-0x32020001, 0x3062009b, 0x10e2001f, 0x32020001,
-0x3c040001, 0x24847438, 0x24051300, 0x2003821,
-0xafa30010, 0xc002d3b, 0xafa00014, 0x3c040001,
-0x248473b8, 0x24020400, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e773c0, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x240e0001, 0x3c030001, 0xa3ae003f, 0x431025,
-0xaf820140, 0x32020001, 0x54400001, 0x36d60080,
-0x32020002, 0x54400001, 0x36d60100, 0x32020008,
-0x54400001, 0x36d60200, 0x32020010, 0x54400001,
-0x36d60400, 0x32020080, 0x54400001, 0x36d60800,
-0x8c020218, 0x30420200, 0x10400002, 0x3c020008,
-0x2c2b025, 0x8c020218, 0x30428000, 0x10400002,
-0x3c021000, 0x2c2b025, 0x8c020218, 0x30420800,
-0x10400002, 0x3c020080, 0x2c2b025, 0x8c020218,
-0x30420400, 0x10400002, 0x3c020100, 0x2c2b025,
-0x8c020218, 0x30420100, 0x10400002, 0x3c020200,
-0x2c2b025, 0x8c020218, 0x30420080, 0x10400002,
-0x3c020400, 0x2c2b025, 0x8c020218, 0x30422000,
-0x10400002, 0x3c020010, 0x2c2b025, 0x8c020218,
-0x30424000, 0x10400002, 0x3c020020, 0x2c2b025,
-0x8c020218, 0x30421000, 0x10400002, 0x3c020040,
-0x2c2b025, 0x8ee20498, 0x8ee3049c, 0xaf420160,
-0xaf430164, 0x8ee204a0, 0x8ee304a4, 0xaf420168,
-0xaf43016c, 0x8ee204a8, 0x8ee304ac, 0xaf420170,
-0xaf430174, 0x8ee20428, 0x8ee3042c, 0xaf420178,
-0xaf43017c, 0x8ee20448, 0x8ee3044c, 0xaf420180,
-0xaf430184, 0x8ee20458, 0x8ee3045c, 0xaf420188,
-0xaf43018c, 0x8ee20468, 0x8ee3046c, 0xaf420190,
-0xaf430194, 0x8ee20478, 0x8ee3047c, 0xaf420198,
-0xaf43019c, 0x8ee20488, 0x8ee3048c, 0xaf4201a0,
-0xaf4301a4, 0x8ee204b0, 0x8ee304b4, 0x24040080,
-0xaf4201a8, 0xaf4301ac, 0xc002da8, 0x24050080,
-0x8c02025c, 0x27440224, 0xaf4201f0, 0x8c020260,
-0x24050200, 0x24060008, 0xaf4201f8, 0xc002dbf,
-0x0, 0x3c043b9a, 0x3484ca00, 0x3821,
-0x24020006, 0x24030002, 0xaf4201f4, 0x240203e8,
-0xaf430204, 0xaf430200, 0xaf4401fc, 0xaf420294,
-0x24020001, 0xaf430290, 0xaf42029c, 0x3c030002,
-0x671821, 0x906385d8, 0x3471021, 0x24e70001,
-0xa043022c, 0x2ce2000f, 0x1440fff8, 0x3471821,
-0x24e70001, 0x3c080001, 0x350840f8, 0x8f820040,
-0x3c040001, 0x24847444, 0x24051400, 0x21702,
-0x24420030, 0xa062022c, 0x3471021, 0xa040022c,
-0x8c070218, 0x2c03021, 0x240205c8, 0xafa20010,
-0xc002d3b, 0xafa80014, 0x3c040001, 0x24847450,
-0x3c050000, 0x24a55f28, 0x24060010, 0x27b10030,
-0x2203821, 0x27b30034, 0xc00188f, 0xafb30010,
-0x3c030002, 0x8c6385c8, 0x1060000a, 0x408021,
-0x8fa30030, 0x2405ff00, 0x8fa20034, 0x246400ff,
-0x852024, 0x831823, 0x431023, 0xafa20034,
-0xafa40030, 0x3c040001, 0x2484745c, 0x3c050000,
-0x24a54100, 0x24060108, 0x2203821, 0xc00188f,
-0xafb30010, 0x409021, 0x32c20003, 0x3c010002,
-0xac32873c, 0x10400059, 0x2203821, 0x8f820050,
-0x3c030010, 0x431024, 0x1040002a, 0x0,
-0x8c020218, 0x30420040, 0x10400023, 0x24020001,
-0x8f820050, 0x8c030218, 0x3c040001, 0x24847468,
-0xafa20010, 0xafa30014, 0x8f870040, 0x24051500,
-0xc002d3b, 0x2c03021, 0x3c040001, 0x248473b8,
-0x24020474, 0xafa20010, 0xafa00014, 0x8f860144,
-0x3c070001, 0x24e773c0, 0xc002d3b, 0x3405dead,
-0x8f82011c, 0x34420002, 0xaf82011c, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820140, 0x240e0001,
-0x3c030001, 0xa3ae003f, 0x431025, 0xaf820140,
-0x10000004, 0x0, 0x3c010001, 0x370821,
-0xa02240f4, 0x3c040001, 0x24847474, 0x3c050001,
-0x24a5a8fc, 0x3c060001, 0x24c6aa20, 0xc53023,
-0x8f420010, 0x27b30030, 0x2603821, 0x27b10034,
-0x34420a00, 0xaf420010, 0xc00188f, 0xafb10010,
-0x3c040001, 0x24847488, 0x3c050001, 0x24a5bfd4,
-0x3c060001, 0x24c6c35c, 0xc53023, 0x2603821,
-0xaf420108, 0xc00188f, 0xafb10010, 0x3c040001,
-0x248474a4, 0x3c050001, 0x24a5c7fc, 0x3c060001,
-0x24c6d53c, 0xc53023, 0x2603821, 0x3c010002,
-0xac2287b0, 0xc00188f, 0xafb10010, 0x3c040001,
-0x248474bc, 0x10000024, 0x24051600, 0x3c040001,
-0x248474c4, 0x3c050001, 0x24a5a744, 0x3c060001,
-0x24c6a8f4, 0xc53023, 0xc00188f, 0xafb30010,
-0x3c040001, 0x248474d4, 0x3c050001, 0x24a5bb10,
-0x3c060001, 0x24c6bfcc, 0xc53023, 0x2203821,
-0xaf420108, 0xc00188f, 0xafb30010, 0x3c040001,
-0x248474e8, 0x3c050001, 0x24a5c364, 0x3c060001,
-0x24c6c7f4, 0xc53023, 0x2203821, 0x3c010002,
-0xac2287b0, 0xc00188f, 0xafb30010, 0x3c040001,
-0x248474fc, 0x24051650, 0x2c03021, 0x3821,
-0x3c010002, 0xac2287b4, 0xafa00010, 0xc002d3b,
-0xafa00014, 0x32c20020, 0x10400021, 0x27a70030,
-0x3c040001, 0x24847508, 0x3c050001, 0x24a5b938,
-0x3c060001, 0x24c6bb08, 0xc53023, 0x24022000,
-0xaf42001c, 0x27a20034, 0xc00188f, 0xafa20010,
-0x21900, 0x31982, 0x3c040800, 0x641825,
-0xae430028, 0x24030010, 0xaf43003c, 0x96e30450,
-0xaf430040, 0x8f430040, 0x3c040001, 0x2484751c,
-0xafa00014, 0xafa30010, 0x8f47001c, 0x24051660,
-0x3c010002, 0xac2287ac, 0x10000039, 0x32c60020,
-0x8ee20448, 0x8ee3044c, 0xaf43001c, 0x8f42001c,
-0x2442e000, 0x2c422001, 0x1440001e, 0x24051700,
-0x3c040001, 0x24847528, 0xafa00010, 0xafa00014,
-0x8f46001c, 0xc002d3b, 0x3821, 0x3c040001,
-0x248473b8, 0x240204dd, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e773c0, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x240e0001, 0x3c030001, 0xa3ae003f, 0x431025,
-0xaf820140, 0x3c020000, 0x24425f64, 0x21100,
-0x21182, 0x3c030800, 0x431025, 0xae420028,
-0x24020008, 0xaf42003c, 0x96e20450, 0xaf420040,
-0x8f420040, 0x3c040001, 0x24847534, 0xafa00014,
-0xafa20010, 0x8f47001c, 0x24051800, 0x32c60020,
-0xc002d3b, 0x0, 0x3c050fff, 0x3c030002,
-0x8c6387b0, 0x34a5ffff, 0x2403021, 0x3c020002,
-0x8c4287b4, 0x3c040800, 0x651824, 0x31882,
-0x641825, 0x451024, 0x21082, 0x441025,
-0xacc20080, 0x32c20180, 0x1040007e, 0xacc30020,
-0x8f82005c, 0x3c030080, 0x431024, 0x10400021,
-0x0, 0x8f820050, 0xafa20010, 0x8f82005c,
-0x3c040001, 0x24847540, 0xafa20014, 0x8f870040,
-0x24051900, 0xc002d3b, 0x2c03021, 0x3c040001,
-0x248473b8, 0x240204fe, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e773c0, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x240e0001, 0x3c030001, 0xa3ae003f, 0x431025,
-0xaf820140, 0x8f820050, 0x3c030010, 0x431024,
-0x1040002a, 0x0, 0x8c020218, 0x30420040,
-0x10400023, 0x24020001, 0x8f820050, 0x8c030218,
-0x3c040001, 0x24847468, 0xafa20010, 0xafa30014,
-0x8f870040, 0x24052000, 0xc002d3b, 0x2c03021,
-0x3c040001, 0x248473b8, 0x2402050c, 0xafa20010,
-0xafa00014, 0x8f860144, 0x3c070001, 0x24e773c0,
-0xc002d3b, 0x3405dead, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f820220, 0x34420004, 0xaf820220,
-0x8f820140, 0x240e0001, 0x3c030001, 0xa3ae003f,
-0x431025, 0xaf820140, 0x10000004, 0x0,
-0x3c010001, 0x370821, 0xa02240f4, 0x3c040001,
-0x2484754c, 0x3c050001, 0x24a5a60c, 0x3c060001,
-0x24c6a73c, 0xc53023, 0x8f420008, 0x27b30030,
-0x2603821, 0x27b10034, 0x34420e00, 0xaf420008,
-0xc00188f, 0xafb10010, 0x3c040001, 0x24847564,
-0x3c050001, 0x24a5e844, 0x3c060001, 0x24c6f5fc,
-0xc53023, 0x2603821, 0xaf42010c, 0xc00188f,
-0xafb10010, 0x3c040001, 0x2484757c, 0x3c050001,
-0x24a5fde8, 0x3c060001, 0x24c60588, 0xc53023,
-0x2603821, 0x3c010002, 0xac2287c0, 0xc00188f,
-0xafb10010, 0x3c040001, 0x24847594, 0x10000027,
-0x24052100, 0x3c040001, 0x2484759c, 0x3c050001,
-0x24a5a444, 0x3c060001, 0x24c6a604, 0xc53023,
-0x27b10030, 0x2203821, 0x27b30034, 0xc00188f,
-0xafb30010, 0x3c040001, 0x248475ac, 0x3c050001,
-0x24a5d738, 0x3c060001, 0x24c6e83c, 0xc53023,
-0x2203821, 0xaf42010c, 0xc00188f, 0xafb30010,
-0x3c040001, 0x248475bc, 0x3c050001, 0x24a5fbac,
-0x3c060001, 0x24c6fde0, 0xc53023, 0x2203821,
-0x3c010002, 0xac2287c0, 0xc00188f, 0xafb30010,
-0x3c040001, 0x248475d0, 0x24052150, 0x2c03021,
-0x3821, 0x3c010002, 0xac2287cc, 0xafa00010,
-0xc002d3b, 0xafa00014, 0x3c110fff, 0x3c030002,
-0x8c6387c0, 0x3631ffff, 0x2409821, 0x3c020002,
-0x8c4287cc, 0x3c0e0800, 0x711824, 0x31882,
-0x6e1825, 0x511024, 0x21082, 0x4e1025,
-0xae630038, 0xae620078, 0x8c020218, 0x30420040,
-0x14400004, 0x24020001, 0x3c010001, 0x370821,
-0xa02240f4, 0x3c040001, 0x248475dc, 0x3c050001,
-0x24a5f604, 0x3c060001, 0x24c6f7c4, 0xc53023,
-0x27be0030, 0x3c03821, 0x27b50034, 0xc00188f,
-0xafb50010, 0x3c010002, 0xac2287b8, 0x511024,
-0x21082, 0x3c0e0800, 0x4e1025, 0xae620050,
-0x32c22000, 0x10400006, 0x3c03821, 0x3c020000,
-0x24425f64, 0x2221024, 0x1000000f, 0x21082,
-0x3c040001, 0x248475f0, 0x3c050001, 0x24a5f7cc,
-0x3c060001, 0x24c6f9e0, 0xc53023, 0xc00188f,
-0xafb50010, 0x3c010002, 0xac2287d0, 0x511024,
-0x21082, 0x3c0e0800, 0x4e1025, 0xae620048,
-0x32c24000, 0x10400005, 0x27a70030, 0x3c020000,
-0x24425f64, 0x1000000e, 0x21100, 0x3c040001,
-0x24847608, 0x3c050001, 0x24a5f9e8, 0x3c060001,
-0x24c6fba4, 0xc53023, 0x27a20034, 0xc00188f,
-0xafa20010, 0x3c010002, 0xac2287c4, 0x21100,
-0x21182, 0x3c030800, 0x431025, 0xae420060,
-0x3c040001, 0x24847620, 0x3c050001, 0x24a5866c,
-0x3c060001, 0x24c68aac, 0xc53023, 0x27b10030,
-0x2203821, 0x27b30034, 0xc00188f, 0xafb30010,
-0x3c0e0fff, 0x35ceffff, 0x3c040001, 0x2484762c,
-0x3c050000, 0x24a5687c, 0x3c060000, 0x24c6699c,
-0xc53023, 0x2203821, 0x240f021, 0x3c010002,
-0xac228798, 0x4e1024, 0x21082, 0x3c150800,
-0x551025, 0xafae0044, 0xafc200b8, 0xc00188f,
-0xafb30010, 0x3c040001, 0x24847638, 0x3c050000,
-0x24a569a4, 0x3c060000, 0x24c66c24, 0x8fae0044,
-0xc53023, 0x2203821, 0x3c010002, 0xac22878c,
-0x4e1024, 0x21082, 0x551025, 0xafc200e8,
-0xc00188f, 0xafb30010, 0x3c040001, 0x24847650,
-0x3c050000, 0x24a56c2c, 0x3c060000, 0x24c66d60,
-0x8fae0044, 0xc53023, 0x2203821, 0x3c010002,
-0xac228784, 0x4e1024, 0x21082, 0x551025,
-0xafc200c0, 0xc00188f, 0xafb30010, 0x3c040001,
-0x24847668, 0x3c050001, 0x24a51034, 0x3c060001,
-0x24c6110c, 0x8fae0044, 0xc53023, 0x2203821,
-0x3c010002, 0xac228790, 0x4e1024, 0x21082,
-0x551025, 0xafc200c8, 0xc00188f, 0xafb30010,
-0x3c040001, 0x24847674, 0x3c050001, 0x24a5d570,
-0x3c060001, 0x24c6d654, 0xc53023, 0x2203821,
-0xaf420110, 0xc00188f, 0xafb30010, 0x3c040001,
-0x24847684, 0x3c050001, 0x24a5d544, 0x3c060001,
-0x24c6d568, 0xc53023, 0x2203821, 0xaf420124,
-0xc00188f, 0xafb30010, 0x3c040001, 0x24847694,
-0x3c050001, 0x24a5d65c, 0x3c060001, 0x24c6d684,
-0xc53023, 0x2203821, 0xaf420120, 0xaf420114,
-0xc00188f, 0xafb30010, 0x3c040001, 0x248476a0,
-0x3c050001, 0x24a5072c, 0x3c060001, 0x24c60c24,
-0xc53023, 0x2203821, 0xaf420118, 0xc00188f,
-0xafb30010, 0x8fae0044, 0x3c010002, 0xac2287d4,
-0x4e1024, 0x21082, 0x551025, 0xc00451b,
-0xafc200d0, 0xc004164, 0x0, 0xc0028c7,
-0x0, 0xac000228, 0xac00022c, 0x96e20450,
-0x2442ffff, 0xaf420038, 0x96e20460, 0xaf420080,
-0x32c24000, 0x14400003, 0x0, 0x96e20480,
-0xaf420084, 0x96e70490, 0x50e00001, 0x24070800,
-0x24e2ffff, 0xaf420088, 0xaf42007c, 0x24020800,
-0x10e20023, 0x32c24000, 0x10400003, 0x24020400,
-0x10e2001f, 0x0, 0x3c040001, 0x248476b0,
-0x96e60490, 0x24052170, 0x2c03821, 0xafa00010,
-0xc002d3b, 0xafa00014, 0x3c040001, 0x248473b8,
-0x240205f1, 0xafa20010, 0xafa00014, 0x8f860144,
-0x3c070001, 0x24e773c0, 0xc002d3b, 0x3405dead,
-0x8f82011c, 0x34420002, 0xaf82011c, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820140, 0x240e0001,
-0x3c030001, 0xa3ae003f, 0x431025, 0xaf820140,
-0x8f430138, 0x8f440138, 0x24020001, 0xa34205c2,
-0xaf430094, 0xaf440098, 0xafa00010, 0xafa00014,
-0x8f460080, 0x8f470084, 0x3c040001, 0x248476bc,
-0xc002d3b, 0x24052200, 0xc0025c6, 0x3c110800,
-0x3c1433d8, 0x3694cb58, 0x3c020800, 0x34420080,
-0x3c040001, 0x248476c8, 0x3c050000, 0x24a55ff8,
-0x3c060000, 0x24c66014, 0xc53023, 0x27a70030,
-0xaf820060, 0x2402ffff, 0xaf820064, 0x27a20034,
-0xc00188f, 0xafa20010, 0x3c010002, 0xac228774,
-0x21100, 0x21182, 0x511025, 0xc0019e8,
-0xae420000, 0x8f820240, 0x3c030001, 0x431025,
-0xaf820240, 0x3c020000, 0x24424034, 0xaf820244,
-0xaf800240, 0x8f820060, 0x511024, 0x14400005,
-0x3c030800, 0x8f820060, 0x431024, 0x1040fffd,
-0x0, 0xc004171, 0x8821, 0x3c020100,
-0xafa20020, 0x8f530018, 0x240200ff, 0x56620001,
-0x26710001, 0x8c020228, 0x1622000e, 0x1330c0,
-0x8f42033c, 0x24420001, 0xaf42033c, 0x8f42033c,
-0x8c020228, 0x3c040001, 0x2484735c, 0x3c050009,
-0xafa00014, 0xafa20010, 0x8fa60020, 0x1000003f,
-0x34a50100, 0xd71021, 0x8fa30020, 0x8fa40024,
-0xac4304c0, 0xac4404c4, 0xc01821, 0x8f440178,
-0x8f45017c, 0x1021, 0x24070004, 0xafa70010,
-0xafb10014, 0x8f48000c, 0x24c604c0, 0x2e63021,
-0xafa80018, 0x8f48010c, 0x24070008, 0xa32821,
-0xa3482b, 0x822021, 0x100f809, 0x892021,
-0x1440000b, 0x24070008, 0x8f820120, 0xafa20010,
-0x8f820124, 0x3c040001, 0x24847364, 0x3c050009,
-0xafa20014, 0x8fa60020, 0x1000001c, 0x34a50200,
-0x8f440160, 0x8f450164, 0x8f43000c, 0xaf510018,
-0x8f860120, 0x24020010, 0xafa20010, 0xafb10014,
-0xafa30018, 0x8f42010c, 0x40f809, 0x24c6001c,
-0x14400010, 0x0, 0x8f420340, 0x24420001,
-0xaf420340, 0x8f420340, 0x8f820120, 0xafa20010,
-0x8f820124, 0x3c040001, 0x2484736c, 0x3c050009,
-0xafa20014, 0x8fa60020, 0x34a50300, 0xc002d3b,
-0x2603821, 0x8f4202e4, 0x24420001, 0xaf4202e4,
-0x8f4202e4, 0x93a2003f, 0x1040007d, 0x3c020700,
-0x34423000, 0xafa20028, 0x8f530018, 0x240200ff,
-0x12620002, 0x8821, 0x26710001, 0x8c020228,
-0x1622000e, 0x1330c0, 0x8f42033c, 0x24420001,
-0xaf42033c, 0x8f42033c, 0x8c020228, 0x3c040001,
-0x2484735c, 0x3c050009, 0xafa00014, 0xafa20010,
-0x8fa60028, 0x1000003f, 0x34a50100, 0xd71021,
-0x8fa30028, 0x8fa4002c, 0xac4304c0, 0xac4404c4,
-0xc01821, 0x8f440178, 0x8f45017c, 0x1021,
-0x24070004, 0xafa70010, 0xafb10014, 0x8f48000c,
-0x24c604c0, 0x2e63021, 0xafa80018, 0x8f48010c,
-0x24070008, 0xa32821, 0xa3482b, 0x822021,
-0x100f809, 0x892021, 0x1440000b, 0x24070008,
-0x8f820120, 0xafa20010, 0x8f820124, 0x3c040001,
-0x24847364, 0x3c050009, 0xafa20014, 0x8fa60028,
-0x1000001c, 0x34a50200, 0x8f440160, 0x8f450164,
-0x8f43000c, 0xaf510018, 0x8f860120, 0x24020010,
-0xafa20010, 0xafb10014, 0xafa30018, 0x8f42010c,
-0x40f809, 0x24c6001c, 0x14400010, 0x0,
-0x8f420340, 0x24420001, 0xaf420340, 0x8f420340,
-0x8f820120, 0xafa20010, 0x8f820124, 0x3c040001,
-0x2484736c, 0x3c050009, 0xafa20014, 0x8fa60028,
-0x34a50300, 0xc002d3b, 0x2603821, 0x8f4202f0,
-0x24420001, 0xaf4202f0, 0x8f4202f0, 0x3c040001,
-0x248476d8, 0xafa00010, 0xafa00014, 0x8fa60028,
-0x24052300, 0xc002d3b, 0x3821, 0x3c040001,
-0x248473b8, 0x24020656, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e773c0, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x10000004,
-0x0, 0x8c020264, 0x10400005, 0x0,
-0x8f8200a0, 0x30420004, 0x1440fffa, 0x0,
-0x8f820044, 0x34420004, 0xaf820044, 0x8f420308,
-0x24420001, 0xaf420308, 0x8f420308, 0x8f8200d8,
-0x8f8300d4, 0x431023, 0x2442ff80, 0xaf420090,
-0x8f420090, 0x2842ff81, 0x10400006, 0x24020001,
-0x8f420090, 0x8f430144, 0x431021, 0xaf420090,
-0x24020001, 0xaf42008c, 0x32c20008, 0x10400006,
-0x0, 0x8f820214, 0x3c038100, 0x3042ffff,
-0x431025, 0xaf820214, 0x3c030002, 0x8c638668,
-0x30620002, 0x10400009, 0x30620001, 0x3c040001,
-0x248476e4, 0x3c050000, 0x24a57174, 0x3c060000,
-0x24c675f8, 0x10000012, 0xc53023, 0x10400009,
-0x0, 0x3c040001, 0x248476f4, 0x3c050000,
-0x24a57600, 0x3c060000, 0x24c67aa8, 0x10000008,
-0xc53023, 0x3c040001, 0x24847704, 0x3c050000,
-0x24a56d68, 0x3c060000, 0x24c6716c, 0xc53023,
-0x27a70030, 0x27a20034, 0xc00188f, 0xafa20010,
-0x3c010002, 0xac228788, 0x3c020002, 0x8c428788,
-0x3c030800, 0x21100, 0x21182, 0x431025,
-0xae420040, 0x8f8200a0, 0xafa20010, 0x8f8200b0,
-0xafa20014, 0x8f86005c, 0x8f87011c, 0x3c040001,
-0x24847714, 0x3c010002, 0xac368760, 0x3c010002,
-0xac208750, 0x3c010002, 0xac3c8748, 0x3c010002,
-0xac3b8778, 0x3c010002, 0xac37877c, 0x3c010002,
-0xac3a875c, 0xc002d3b, 0x24052400, 0x8f820200,
-0xafa20010, 0x8f820220, 0xafa20014, 0x8f860044,
-0x8f870050, 0x3c040001, 0x24847720, 0xc002d3b,
-0x24052500, 0x8f830060, 0x74100b, 0x242000a,
-0x200f821, 0x0, 0xd, 0x8fbf0060,
-0x8fbe005c, 0x8fb50058, 0x8fb30054, 0x8fb20050,
-0x8fb1004c, 0x8fb00048, 0x3e00008, 0x27bd0068,
-0x27bdffe0, 0x3c040001, 0x2484772c, 0x24052600,
-0x3021, 0x3821, 0xafbf0018, 0xafa00010,
-0xc002d3b, 0xafa00014, 0x3c040001, 0x248473b8,
-0x240206bb, 0xafa20010, 0xafa00014, 0x8f860144,
-0x3c070001, 0x24e773c0, 0xc002d3b, 0x3405dead,
-0x8f82011c, 0x34420002, 0xaf82011c, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820140, 0x3c030001,
-0x431025, 0xaf820140, 0x8fbf0018, 0x3e00008,
-0x27bd0020, 0x3e00008, 0x0, 0x3e00008,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x3e00008, 0x0,
-0x3e00008, 0x0, 0x27bdfde0, 0xafb00218,
-0x27b00018, 0x3c0200bf, 0x3442ffff, 0x50102b,
-0x10400015, 0xafbf021c, 0x3c040001, 0x248473b8,
-0x240206df, 0xafa20010, 0xafa00014, 0x8f860144,
-0x3c070001, 0x24e773c0, 0xc002d3b, 0x3405dead,
-0x8f82011c, 0x34420002, 0xaf82011c, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820140, 0x3c030001,
-0x431025, 0xaf820140, 0x3c04dead, 0x3484beef,
-0x8f820150, 0x3c03001f, 0x3463ffff, 0xafa40018,
-0x2028023, 0x2038024, 0x8e020000, 0x1044001e,
-0x0, 0xafb00010, 0x8e020000, 0xafa20014,
-0x8f860150, 0x8f870250, 0x3c040001, 0x24847734,
-0xc002d3b, 0x24052700, 0x3c040001, 0x248473b8,
-0x240206ed, 0xafa20010, 0xafa00014, 0x8f860144,
-0x3c070001, 0x24e773c0, 0xc002d3b, 0x3405dead,
-0x8f82011c, 0x34420002, 0xaf82011c, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820140, 0x3c030001,
-0x431025, 0xaf820140, 0x8fbf021c, 0x8fb00218,
-0x3e00008, 0x27bd0220, 0x27bdffe0, 0x3c06abba,
-0x34c6babe, 0xafb00018, 0x3c100004, 0x3c07007f,
-0x34e7ffff, 0xafbf001c, 0x102840, 0x8e040000,
-0x8ca30000, 0xaca00000, 0xae060000, 0x8ca20000,
-0xaca30000, 0x10460005, 0xae040000, 0xa08021,
-0xf0102b, 0x1040fff5, 0x102840, 0x3c040001,
-0x24847740, 0x24052800, 0x2003021, 0x3821,
-0xafa00010, 0xc002d3b, 0xafa00014, 0x2001021,
-0x8fbf001c, 0x8fb00018, 0x3e00008, 0x27bd0020,
-0x8c020224, 0x3047003f, 0x10e00010, 0x803021,
-0x2821, 0x24030020, 0xe31024, 0x10400002,
-0x63042, 0xa62821, 0x31842, 0x1460fffb,
-0xe31024, 0x2402f000, 0xa22824, 0x3402ffff,
-0x45102b, 0x14400003, 0x3c020001, 0x10000008,
-0x3c020001, 0x3442ffff, 0x851823, 0x43102b,
-0x14400003, 0xa01021, 0x3c02fffe, 0x821021,
-0x3e00008, 0x0, 0x27bdffd0, 0xafb50028,
-0x8fb50040, 0xafb20020, 0xa09021, 0xafb1001c,
-0x24c60003, 0xafbf002c, 0xafb30024, 0xafb00018,
-0x8ea20000, 0x2403fffc, 0xc38024, 0x50102b,
-0x1440001b, 0xe08821, 0x8e330000, 0xafb00010,
-0x8ea20000, 0xafa20014, 0x8e270000, 0x24053000,
-0xc002d3b, 0x2403021, 0x8e230000, 0x702021,
-0x64102b, 0x10400007, 0x2402821, 0x8ca20000,
-0xac620000, 0x24630004, 0x64102b, 0x1440fffb,
-0x24a50004, 0x8ea20000, 0x501023, 0xaea20000,
-0x8e220000, 0x501021, 0x1000000b, 0xae220000,
-0x2402002d, 0xa0820000, 0xafb00010, 0x8ea20000,
-0x2409821, 0xafa20014, 0x8e270000, 0x24053100,
-0xc002d3b, 0x2603021, 0x2601021, 0x8fbf002c,
-0x8fb50028, 0x8fb30024, 0x8fb20020, 0x8fb1001c,
-0x8fb00018, 0x3e00008, 0x27bd0030, 0x27bdffe8,
-0x3c1cc000, 0x3c05fffe, 0x3c030002, 0x8c638740,
-0x3c040002, 0x8c84874c, 0x34a5bf08, 0x24021ffc,
-0x3c010002, 0xac2285d0, 0x3c0200c0, 0x3c010002,
-0xac2285d4, 0x3c020020, 0xafbf0010, 0x3c0100c0,
-0xac201ffc, 0x431023, 0x441023, 0x245bb000,
-0x365b821, 0x3c1d0002, 0x8fbd85cc, 0x3a0f021,
-0x3c0400c0, 0x34840200, 0x3c1a00c0, 0x3c0300c0,
-0x346307c8, 0x24021dfc, 0x3c010002, 0xac2285d0,
-0x24021834, 0x3c010002, 0xac2485d4, 0x3c010002,
-0xac2285d0, 0x3c010002, 0xac2385d4, 0xc0018f9,
-0x375a0200, 0x8fbf0010, 0x3e00008, 0x27bd0018,
-0x27bdffc8, 0x3c040001, 0x2484774c, 0x24053200,
-0x3c020002, 0x8c4285d0, 0x3c030002, 0x8c6385d4,
-0x3021, 0x3603821, 0xafbf0030, 0xafb3002c,
-0xafb20028, 0xafb10024, 0xafb00020, 0xafa2001c,
-0xafa30018, 0xafb70010, 0xc002d3b, 0xafba0014,
-0xc001a1b, 0x0, 0x8f820240, 0x34420004,
-0xaf820240, 0x24020001, 0xaf420000, 0x3c020001,
-0x571021, 0x904240f4, 0x10400093, 0x2403fffc,
-0x3c100001, 0x2610b47b, 0x3c120001, 0x2652b044,
-0x2121023, 0x438024, 0x8fa3001c, 0x3c040001,
-0x24847758, 0x70102b, 0x1440001a, 0x27b30018,
-0x8fb10018, 0x24053000, 0x2403021, 0xafb00010,
-0xafa30014, 0xc002d3b, 0x2203821, 0x8fa30018,
-0x702021, 0x64102b, 0x10400007, 0x2403021,
-0x8cc20000, 0xac620000, 0x24630004, 0x64102b,
-0x1440fffb, 0x24c60004, 0x8fa2001c, 0x501023,
-0xafa2001c, 0x8e620000, 0x501021, 0x1000000a,
-0xae620000, 0x2408821, 0x24053100, 0xafb00010,
-0xafa30014, 0x8fa70018, 0x2203021, 0x2402002d,
-0xc002d3b, 0xa0820000, 0x24070020, 0x8fa3001c,
-0x3c040001, 0x24847774, 0x24120020, 0x3c010002,
-0xac31876c, 0x2c620020, 0x1440001d, 0x27b10018,
-0x8fb00018, 0x24053000, 0x3c060002, 0x24c68810,
-0xafa70010, 0xafa30014, 0xc002d3b, 0x2003821,
-0x8fa30018, 0x3c040002, 0x24848810, 0x24650020,
-0x65102b, 0x10400007, 0x0, 0x8c820000,
-0xac620000, 0x24630004, 0x65102b, 0x1440fffb,
-0x24840004, 0x8fa2001c, 0x521023, 0xafa2001c,
-0x8e220000, 0x521021, 0x1000000b, 0xae220000,
-0x3c100002, 0x26108810, 0x24053100, 0xafa70010,
-0xafa30014, 0x8fa70018, 0x2003021, 0x2402002d,
-0xc002d3b, 0xa0820000, 0x24070020, 0x3c040001,
-0x24847788, 0x8fa3001c, 0x24120020, 0x3c010002,
-0xac3087a0, 0x2c620020, 0x1440001d, 0x27b10018,
-0x8fb00018, 0x24053000, 0x3c060002, 0x24c68830,
-0xafa70010, 0xafa30014, 0xc002d3b, 0x2003821,
-0x8fa30018, 0x3c040002, 0x24848830, 0x24650020,
-0x65102b, 0x10400007, 0x0, 0x8c820000,
-0xac620000, 0x24630004, 0x65102b, 0x1440fffb,
-0x24840004, 0x8fa2001c, 0x521023, 0xafa2001c,
-0x8e220000, 0x521021, 0x1000000b, 0xae220000,
-0x3c100002, 0x26108830, 0x24053100, 0xafa70010,
-0xafa30014, 0x8fa70018, 0x2003021, 0x2402002d,
-0xc002d3b, 0xa0820000, 0x3c010002, 0xac30879c,
-0x10000031, 0x0, 0x3c100001, 0x26108667,
-0x3c120001, 0x265284d8, 0x2121023, 0x438024,
-0x8fa3001c, 0x3c040001, 0x2484779c, 0x70102b,
-0x1440001a, 0x27b30018, 0x8fb10018, 0x24053000,
-0x2403021, 0xafb00010, 0xafa30014, 0xc002d3b,
-0x2203821, 0x8fa30018, 0x702021, 0x64102b,
-0x10400007, 0x2403021, 0x8cc20000, 0xac620000,
-0x24630004, 0x64102b, 0x1440fffb, 0x24c60004,
-0x8fa2001c, 0x501023, 0xafa2001c, 0x8e620000,
-0x501021, 0x1000000a, 0xae620000, 0x2408821,
-0x24053100, 0xafb00010, 0xafa30014, 0x8fa70018,
-0x2203021, 0x2402002d, 0xc002d3b, 0xa0820000,
-0x3c010002, 0xac31876c, 0x3c030002, 0x8c63876c,
-0x24020400, 0xaf820070, 0x60f809, 0x0,
-0x8fbf0030, 0x8fb3002c, 0x8fb20028, 0x8fb10024,
-0x8fb00020, 0x3e00008, 0x27bd0038, 0x27bdffe0,
-0xafbf0018, 0x8f820040, 0x3c03f000, 0x431024,
-0x3c036000, 0x14430008, 0x240201f9, 0x8f820050,
-0x2403ff80, 0x431024, 0x34420055, 0xaf820050,
-0x10000014, 0x0, 0x3c040001, 0x2484785c,
-0xafa20010, 0xafa00014, 0x8f860144, 0x3c070001,
-0x24e7786c, 0xc002d3b, 0x3405dead, 0x8f82011c,
-0x34420002, 0xaf82011c, 0x8f820220, 0x34420004,
-0xaf820220, 0x8f820140, 0x3c030001, 0x431025,
-0xaf820140, 0x8f820054, 0x244203e8, 0xaf820058,
-0x240201f4, 0xaf4200e0, 0x24020004, 0xaf4200e8,
-0x24020002, 0xaf4001b0, 0xaf4000e4, 0xaf4200dc,
-0xaf4000d8, 0xaf4000d4, 0x8fbf0018, 0xaf4000d0,
-0x3e00008, 0x27bd0020, 0x8f820054, 0x24420005,
-0x3e00008, 0xaf820078, 0x27bdffe8, 0xafbf0010,
-0x8f820054, 0x244203e8, 0xaf820058, 0x3c020800,
-0x2c21024, 0x10400004, 0x3c02f7ff, 0x3442ffff,
-0x2c2b024, 0x36940040, 0x3c020002, 0x8c42867c,
-0x10400017, 0x3c020200, 0x3c030002, 0x8c6387d8,
-0x10600016, 0x282a025, 0x3c020002, 0x8c428708,
-0x14400012, 0x3c020200, 0x3c020002, 0x8c428668,
-0x30420003, 0x1440000d, 0x3c020200, 0x8f830224,
-0x3c020002, 0x8c42a8ac, 0x10620008, 0x3c020200,
-0xc00430b, 0x0, 0x10000004, 0x3c020200,
-0xc00470e, 0x0, 0x3c020200, 0x2c21024,
-0x10400003, 0x0, 0xc002058, 0x0,
-0x8f4200d8, 0x8f4300dc, 0x24420001, 0xaf4200d8,
-0x43102b, 0x14400003, 0x0, 0xaf4000d8,
-0x36940080, 0x8c030238, 0x1060000c, 0x0,
-0x8f4201b0, 0x244203e8, 0xaf4201b0, 0x43102b,
-0x14400006, 0x0, 0x934205c5, 0x14400003,
-0x0, 0xc001eac, 0x0, 0x8fbf0010,
-0x3e00008, 0x27bd0018, 0x3e00008, 0x0,
-0x27bdffd8, 0xafbf0020, 0x8f43002c, 0x8f420038,
-0x10620059, 0x0, 0x3c020001, 0x571021,
-0x904240f0, 0x10400026, 0x24070008, 0x8f440170,
-0x8f450174, 0x8f48000c, 0x8f860120, 0x24020020,
-0xafa20010, 0xafa30014, 0xafa80018, 0x8f42010c,
-0x40f809, 0x24c6001c, 0x14400011, 0x24020001,
-0x3c010001, 0x370821, 0xa02240f0, 0x8f820124,
-0xafa20010, 0x8f820128, 0x3c040001, 0x24847840,
-0xafa20014, 0x8f46002c, 0x8f870120, 0x3c050009,
-0xc002d3b, 0x34a50900, 0x1000005d, 0x0,
-0x8f420300, 0x24420001, 0xaf420300, 0x8f420300,
-0x8f42002c, 0xa34005c1, 0x10000027, 0xaf420038,
-0x8f440170, 0x8f450174, 0x8f43002c, 0x8f48000c,
-0x8f860120, 0x24020080, 0xafa20010, 0xafa30014,
-0xafa80018, 0x8f42010c, 0x40f809, 0x24c6001c,
-0x14400011, 0x24020001, 0x3c010001, 0x370821,
-0xa02240f1, 0x8f820124, 0xafa20010, 0x8f820128,
-0x3c040001, 0x2484784c, 0xafa20014, 0x8f46002c,
-0x8f870120, 0x3c050009, 0xc002d3b, 0x34a51100,
-0x10000037, 0x0, 0x8f420300, 0x8f43002c,
-0x24420001, 0xaf420300, 0x8f420300, 0x24020001,
-0xa34205c1, 0xaf430038, 0x3c010001, 0x370821,
-0xa02040f1, 0x3c010001, 0x370821, 0xa02040f0,
-0x10000027, 0xaf400034, 0x934205c1, 0x1040001e,
-0x0, 0xa34005c1, 0x8f820040, 0x30420001,
-0x14400008, 0x2021, 0x8c030104, 0x24020001,
-0x50620005, 0x24040001, 0x8c020264, 0x10400003,
-0x801021, 0x24040001, 0x801021, 0x10400007,
-0x0, 0x8f42030c, 0x24420001, 0xaf42030c,
-0x8f42030c, 0x10000008, 0x0, 0x8f820044,
-0x34420004, 0xaf820044, 0x8f420308, 0x24420001,
-0xaf420308, 0x8f420308, 0x3c010001, 0x370821,
-0xa02040f0, 0x3c010001, 0x370821, 0xa02040f1,
-0x8f420000, 0x10400007, 0x0, 0xaf80004c,
-0x8f82004c, 0x1040fffd, 0x0, 0x10000005,
-0x0, 0xaf800048, 0x8f820048, 0x1040fffd,
-0x0, 0x8f820060, 0x3c03ff7f, 0x3463ffff,
-0x431024, 0xaf820060, 0x8f420000, 0x10400004,
-0x0, 0xaf80004c, 0x10000002, 0x0,
-0xaf800048, 0x8fbf0020, 0x3e00008, 0x27bd0028,
-0x3e00008, 0x0, 0x27bdffd8, 0xafbf0020,
-0x8f430044, 0x8f42007c, 0x10620029, 0x24070008,
-0x8f440168, 0x8f45016c, 0x8f48000c, 0x8f860120,
-0x24020040, 0xafa20010, 0xafa30014, 0xafa80018,
-0x8f42010c, 0x40f809, 0x24c6001c, 0x14400011,
-0x24020001, 0x3c010001, 0x370821, 0xa02240f2,
-0x8f820124, 0xafa20010, 0x8f820128, 0x3c040001,
-0x24847854, 0xafa20014, 0x8f460044, 0x8f870120,
-0x3c050009, 0xc002d3b, 0x34a51300, 0x1000000f,
-0x0, 0x8f420304, 0x24420001, 0xaf420304,
-0x8f420304, 0x8f420044, 0xaf42007c, 0x3c010001,
-0x370821, 0xa02040f2, 0x10000004, 0xaf400078,
-0x3c010001, 0x370821, 0xa02040f2, 0x8f420000,
-0x10400007, 0x0, 0xaf80004c, 0x8f82004c,
-0x1040fffd, 0x0, 0x10000005, 0x0,
-0xaf800048, 0x8f820048, 0x1040fffd, 0x0,
-0x8f820060, 0x3c03feff, 0x3463ffff, 0x431024,
-0xaf820060, 0x8f420000, 0x10400004, 0x0,
-0xaf80004c, 0x10000002, 0x0, 0xaf800048,
-0x8fbf0020, 0x3e00008, 0x27bd0028, 0x3e00008,
-0x0, 0x3c020002, 0x8c42867c, 0x27bdffa8,
-0xafbf0050, 0xafbe004c, 0xafb50048, 0xafb30044,
-0xafb20040, 0xafb1003c, 0xafb00038, 0x8f900044,
-0x104000d5, 0x0, 0x8f4200d0, 0x24430001,
-0x2842000b, 0x144000e4, 0xaf4300d0, 0x8f420004,
-0x30420002, 0x1440009c, 0xaf4000d0, 0x8f420004,
-0x3c030002, 0x8c63866c, 0x34420002, 0xaf420004,
-0x24020001, 0x14620003, 0x3c020600, 0x10000002,
-0x34423000, 0x34421000, 0xafa20020, 0x8f4a0018,
-0xafaa0034, 0x27aa0020, 0xafaa002c, 0x8faa0034,
-0x240200ff, 0x11420002, 0x1821, 0x25430001,
-0x8c020228, 0x609821, 0x1662000e, 0x3c050009,
-0x8f42033c, 0x24420001, 0xaf42033c, 0x8f42033c,
-0x8c020228, 0x8fa70034, 0x3c040001, 0x24847824,
-0xafa00014, 0xafa20010, 0x8fa60020, 0x10000070,
-0x34a50500, 0x8faa0034, 0xa38c0, 0xf71021,
-0x8fa30020, 0x8fa40024, 0xac4304c0, 0xac4404c4,
-0x8f830054, 0x8f820054, 0x247103e8, 0x2221023,
-0x2c4203e9, 0x1040001b, 0xa821, 0xe09021,
-0x265e04c0, 0x8f440178, 0x8f45017c, 0x2401821,
-0x240a0004, 0xafaa0010, 0xafb30014, 0x8f48000c,
-0x1021, 0x2fe3021, 0xafa80018, 0x8f48010c,
-0x24070008, 0xa32821, 0xa3482b, 0x822021,
-0x100f809, 0x892021, 0x54400006, 0x24150001,
-0x8f820054, 0x2221023, 0x2c4203e9, 0x1440ffe9,
-0x0, 0x32a200ff, 0x54400018, 0xaf530018,
-0x8f420378, 0x24420001, 0xaf420378, 0x8f420378,
-0x8f820120, 0x8faa002c, 0x8fa70034, 0xafa20010,
-0x8f820124, 0x3c040001, 0x24847830, 0xafa20014,
-0x8d460000, 0x3c050009, 0x10000035, 0x34a50600,
-0x8f420308, 0x24150001, 0x24420001, 0xaf420308,
-0x8f420308, 0x1000001e, 0x32a200ff, 0x8f830054,
-0x8f820054, 0x247103e8, 0x2221023, 0x2c4203e9,
-0x10400016, 0xa821, 0x3c1e0020, 0x24120010,
-0x8f42000c, 0x8f440160, 0x8f450164, 0x8f860120,
-0xafb20010, 0xafb30014, 0x5e1025, 0xafa20018,
-0x8f42010c, 0x24070008, 0x40f809, 0x24c6001c,
-0x1440ffe3, 0x0, 0x8f820054, 0x2221023,
-0x2c4203e9, 0x1440ffee, 0x0, 0x32a200ff,
-0x14400011, 0x3c050009, 0x8f420378, 0x24420001,
-0xaf420378, 0x8f420378, 0x8f820120, 0x8faa002c,
-0x8fa70034, 0xafa20010, 0x8f820124, 0x3c040001,
-0x24847838, 0xafa20014, 0x8d460000, 0x34a50700,
-0xc002d3b, 0x0, 0x8f4202ec, 0x24420001,
-0xaf4202ec, 0x8f4202ec, 0x8f420004, 0x30420001,
-0x50400029, 0x36100040, 0x3c020400, 0x2c21024,
-0x10400013, 0x2404ffdf, 0x8f420250, 0x8f430254,
-0x8f4401b4, 0x14640006, 0x36100040, 0x8f420270,
-0x8f430274, 0x8f4401b8, 0x10640007, 0x2402ffdf,
-0x8f420250, 0x8f430254, 0x8f440270, 0x8f450274,
-0x10000012, 0x3a100020, 0x1000002b, 0x2028024,
-0x8f420250, 0x8f430254, 0x8f4501b4, 0x14650006,
-0x2048024, 0x8f420270, 0x8f430274, 0x8f4401b8,
-0x50640021, 0x36100040, 0x8f420250, 0x8f430254,
-0x8f440270, 0x8f450274, 0x3a100040, 0xaf4301b4,
-0x10000019, 0xaf4501b8, 0x8f4200d4, 0x24430001,
-0x10000011, 0x28420033, 0x8f420004, 0x30420001,
-0x10400009, 0x3c020400, 0x2c21024, 0x10400004,
-0x2402ffdf, 0x2028024, 0x1000000b, 0x36100040,
-0x10000009, 0x36100060, 0x8f4200d4, 0x36100040,
-0x24430001, 0x284201f5, 0x14400003, 0xaf4300d4,
-0xaf4000d4, 0x3a100020, 0xaf900044, 0x2402ff7f,
-0x282a024, 0x8fbf0050, 0x8fbe004c, 0x8fb50048,
-0x8fb30044, 0x8fb20040, 0x8fb1003c, 0x8fb00038,
-0x3e00008, 0x27bd0058, 0x3e00008, 0x0,
-0x3c020002, 0x8c42867c, 0x27bdffb0, 0xafbf0048,
-0xafbe0044, 0xafb50040, 0xafb3003c, 0xafb20038,
-0xafb10034, 0x104000c9, 0xafb00030, 0x8f4200d0,
-0x24430001, 0x2842000b, 0x144000dd, 0xaf4300d0,
-0x8f420004, 0x30420002, 0x14400097, 0xaf4000d0,
-0x8f420004, 0x3c030002, 0x8c63866c, 0x34420002,
-0xaf420004, 0x24020001, 0x14620003, 0x3c020600,
-0x10000002, 0x34423000, 0x34421000, 0xafa20020,
-0x1821, 0x8f5e0018, 0x27aa0020, 0x240200ff,
-0x13c20002, 0xafaa002c, 0x27c30001, 0x8c020228,
-0x609021, 0x1642000e, 0x1e38c0, 0x8f42033c,
-0x24420001, 0xaf42033c, 0x8f42033c, 0x8c020228,
-0x3c040001, 0x24847824, 0x3c050009, 0xafa00014,
-0xafa20010, 0x8fa60020, 0x1000006d, 0x34a50500,
-0xf71021, 0x8fa30020, 0x8fa40024, 0xac4304c0,
-0xac4404c4, 0x8f830054, 0x8f820054, 0x247003e8,
-0x2021023, 0x2c4203e9, 0x1040001b, 0x9821,
-0xe08821, 0x263504c0, 0x8f440178, 0x8f45017c,
-0x2201821, 0x240a0004, 0xafaa0010, 0xafb20014,
-0x8f48000c, 0x1021, 0x2f53021, 0xafa80018,
-0x8f48010c, 0x24070008, 0xa32821, 0xa3482b,
-0x822021, 0x100f809, 0x892021, 0x54400006,
-0x24130001, 0x8f820054, 0x2021023, 0x2c4203e9,
-0x1440ffe9, 0x0, 0x326200ff, 0x54400017,
-0xaf520018, 0x8f420378, 0x24420001, 0xaf420378,
-0x8f420378, 0x8f820120, 0x8faa002c, 0xafa20010,
-0x8f820124, 0x3c040001, 0x24847830, 0x3c050009,
-0xafa20014, 0x8d460000, 0x10000035, 0x34a50600,
-0x8f420308, 0x24130001, 0x24420001, 0xaf420308,
-0x8f420308, 0x1000001e, 0x326200ff, 0x8f830054,
-0x8f820054, 0x247003e8, 0x2021023, 0x2c4203e9,
-0x10400016, 0x9821, 0x3c150020, 0x24110010,
-0x8f42000c, 0x8f440160, 0x8f450164, 0x8f860120,
-0xafb10010, 0xafb20014, 0x551025, 0xafa20018,
-0x8f42010c, 0x24070008, 0x40f809, 0x24c6001c,
-0x1440ffe3, 0x0, 0x8f820054, 0x2021023,
-0x2c4203e9, 0x1440ffee, 0x0, 0x326200ff,
-0x14400011, 0x0, 0x8f420378, 0x24420001,
-0xaf420378, 0x8f420378, 0x8f820120, 0x8faa002c,
-0xafa20010, 0x8f820124, 0x3c040001, 0x24847838,
-0x3c050009, 0xafa20014, 0x8d460000, 0x34a50700,
-0xc002d3b, 0x3c03821, 0x8f4202ec, 0x24420001,
-0xaf4202ec, 0x8f4202ec, 0x8f420004, 0x30420001,
-0x1040001a, 0x24040001, 0x8f420250, 0x8f430254,
-0x8f4501b4, 0x3c010002, 0xa02485e9, 0x14650006,
-0x0, 0x8f420270, 0x8f430274, 0x8f4401b8,
-0x10640022, 0x0, 0x8f420250, 0x8f430254,
-0x3c040002, 0x908485e8, 0x8f460270, 0x8f470274,
-0x38840001, 0xaf4301b4, 0xaf4701b8, 0x3c010002,
-0xa02485e8, 0x10000026, 0x0, 0x8f4200d4,
-0x3c010002, 0xa02085e8, 0x24430001, 0x28420033,
-0x1440001f, 0xaf4300d4, 0x3c020002, 0x904285e9,
-0xaf4000d4, 0x10000018, 0x38420001, 0x8f420004,
-0x30420001, 0x10400009, 0x0, 0xc005c9f,
-0x2021, 0x3c010002, 0xa02085e9, 0x3c010002,
-0xa02085e8, 0x1000000e, 0x0, 0x8f4200d4,
-0x3c010002, 0xa02085e8, 0x24430001, 0x284201f5,
-0x14400007, 0xaf4300d4, 0x3c020002, 0x904285e9,
-0xaf4000d4, 0x421026, 0x3c010002, 0xa02285e9,
-0x3c030002, 0x8c63866c, 0x24020002, 0x1462000c,
-0x3c030002, 0x3c030002, 0x906385e9, 0x24020001,
-0x5462001f, 0x2021, 0x3c020002, 0x904285e8,
-0x1443001b, 0x24040005, 0x10000019, 0x24040006,
-0x3c020002, 0x8c42a8b4, 0x431024, 0x1040000b,
-0x24020001, 0x3c030002, 0x906385e9, 0x54620010,
-0x2021, 0x3c020002, 0x904285e8, 0x1443000c,
-0x24040003, 0x1000000a, 0x24040004, 0x3c030002,
-0x906385e9, 0x14620006, 0x2021, 0x3c020002,
-0x904285e8, 0x24040001, 0x50440001, 0x24040002,
-0xc005c9f, 0x0, 0x2402ff7f, 0x282a024,
-0x8fbf0048, 0x8fbe0044, 0x8fb50040, 0x8fb3003c,
-0x8fb20038, 0x8fb10034, 0x8fb00030, 0x3e00008,
-0x27bd0050, 0x3e00008, 0x0, 0x3c020002,
-0x8c42867c, 0x27bdffb0, 0xafbf0048, 0xafbe0044,
-0xafb50040, 0xafb3003c, 0xafb20038, 0xafb10034,
-0x104000de, 0xafb00030, 0x8f4200d0, 0x3c040002,
-0x8c84866c, 0x24430001, 0x2842000b, 0xaf4400e8,
-0x144000fe, 0xaf4300d0, 0x8f420004, 0x30420002,
-0x14400095, 0xaf4000d0, 0x8f420004, 0x34420002,
-0xaf420004, 0x24020001, 0x14820003, 0x3c020600,
-0x10000002, 0x34423000, 0x34421000, 0xafa20020,
-0x1821, 0x8f5e0018, 0x27aa0020, 0x240200ff,
-0x13c20002, 0xafaa002c, 0x27c30001, 0x8c020228,
-0x609021, 0x1642000e, 0x1e38c0, 0x8f42033c,
-0x24420001, 0xaf42033c, 0x8f42033c, 0x8c020228,
-0x3c040001, 0x24847824, 0x3c050009, 0xafa00014,
-0xafa20010, 0x8fa60020, 0x1000006d, 0x34a50500,
-0xf71021, 0x8fa30020, 0x8fa40024, 0xac4304c0,
-0xac4404c4, 0x8f830054, 0x8f820054, 0x247003e8,
-0x2021023, 0x2c4203e9, 0x1040001b, 0x9821,
-0xe08821, 0x263504c0, 0x8f440178, 0x8f45017c,
-0x2201821, 0x240a0004, 0xafaa0010, 0xafb20014,
-0x8f48000c, 0x1021, 0x2f53021, 0xafa80018,
-0x8f48010c, 0x24070008, 0xa32821, 0xa3482b,
-0x822021, 0x100f809, 0x892021, 0x54400006,
-0x24130001, 0x8f820054, 0x2021023, 0x2c4203e9,
-0x1440ffe9, 0x0, 0x326200ff, 0x54400017,
-0xaf520018, 0x8f420378, 0x24420001, 0xaf420378,
-0x8f420378, 0x8f820120, 0x8faa002c, 0xafa20010,
-0x8f820124, 0x3c040001, 0x24847830, 0x3c050009,
-0xafa20014, 0x8d460000, 0x10000035, 0x34a50600,
-0x8f420308, 0x24130001, 0x24420001, 0xaf420308,
-0x8f420308, 0x1000001e, 0x326200ff, 0x8f830054,
-0x8f820054, 0x247003e8, 0x2021023, 0x2c4203e9,
-0x10400016, 0x9821, 0x3c150020, 0x24110010,
-0x8f42000c, 0x8f440160, 0x8f450164, 0x8f860120,
-0xafb10010, 0xafb20014, 0x551025, 0xafa20018,
-0x8f42010c, 0x24070008, 0x40f809, 0x24c6001c,
-0x1440ffe3, 0x0, 0x8f820054, 0x2021023,
-0x2c4203e9, 0x1440ffee, 0x0, 0x326200ff,
-0x14400011, 0x0, 0x8f420378, 0x24420001,
-0xaf420378, 0x8f420378, 0x8f820120, 0x8faa002c,
-0xafa20010, 0x8f820124, 0x3c040001, 0x24847838,
-0x3c050009, 0xafa20014, 0x8d460000, 0x34a50700,
-0xc002d3b, 0x3c03821, 0x8f4202ec, 0x24420001,
-0xaf4202ec, 0x8f4202ec, 0x8f420004, 0x30420001,
-0x10400033, 0x3c020400, 0x2c21024, 0x10400017,
-0x0, 0x934205c0, 0x8f440250, 0x8f450254,
-0x8f4301b4, 0x34420020, 0x14a30006, 0xa34205c0,
-0x8f420270, 0x8f430274, 0x8f4401b8, 0x10640008,
-0x0, 0x8f420250, 0x8f430254, 0x934405c0,
-0x8f460270, 0x8f470274, 0x10000016, 0x38840040,
-0x934205c0, 0x10000048, 0x304200bf, 0x934205c0,
-0x8f440250, 0x8f450254, 0x8f4301b4, 0x304200bf,
-0x14a30006, 0xa34205c0, 0x8f420270, 0x8f430274,
-0x8f4401b8, 0x1064000b, 0x0, 0x8f420250,
-0x8f430254, 0x934405c0, 0x8f460270, 0x8f470274,
-0x38840020, 0xaf4301b4, 0xaf4701b8, 0x10000033,
-0xa34405c0, 0x934205c0, 0x1000002f, 0x34420020,
-0x934205c0, 0x8f4300d4, 0x34420020, 0xa34205c0,
-0x24620001, 0x10000023, 0x28630033, 0x8f4200e4,
-0x8f4300e0, 0x24420001, 0xaf4200e4, 0x43102a,
-0x14400006, 0x24030001, 0x8f4200e8, 0x14430002,
-0xaf4000e4, 0x24030004, 0xaf4300e8, 0x8f420004,
-0x30420001, 0x1040000d, 0x3c020400, 0x2c21024,
-0x10400007, 0x0, 0x934205c0, 0x34420040,
-0xa34205c0, 0x934205c0, 0x1000000f, 0x304200df,
-0x934205c0, 0x1000000c, 0x34420060, 0x934205c0,
-0x8f4300d4, 0x34420020, 0xa34205c0, 0x24620001,
-0x286300fb, 0x14600005, 0xaf4200d4, 0x934205c0,
-0xaf4000d4, 0x38420040, 0xa34205c0, 0x934205c0,
-0x8f4300e8, 0x3042007f, 0xa34205c0, 0x24020001,
-0x14620005, 0x0, 0x934405c0, 0x42102,
-0x10000003, 0x348400f0, 0x934405c0, 0x3484000f,
-0xc005c85, 0x0, 0x2402ff7f, 0x282a024,
-0x8fbf0048, 0x8fbe0044, 0x8fb50040, 0x8fb3003c,
-0x8fb20038, 0x8fb10034, 0x8fb00030, 0x3e00008,
-0x27bd0050, 0x3e00008, 0x0, 0x27bdffb0,
-0x274401c0, 0x26e30028, 0x24650400, 0x65102b,
-0xafbf0048, 0xafbe0044, 0xafb50040, 0xafb3003c,
-0xafb20038, 0xafb10034, 0x10400007, 0xafb00030,
-0x8c820000, 0xac620000, 0x24630004, 0x65102b,
-0x1440fffb, 0x24840004, 0x8c020080, 0xaee20044,
-0x8c0200c0, 0xaee20040, 0x8c020084, 0xaee20030,
-0x8c020084, 0xaee2023c, 0x8c020088, 0xaee20240,
-0x8c02008c, 0xaee20244, 0x8c020090, 0xaee20248,
-0x8c020094, 0xaee2024c, 0x8c020098, 0xaee20250,
-0x8c02009c, 0xaee20254, 0x8c0200a0, 0xaee20258,
-0x8c0200a4, 0xaee2025c, 0x8c0200a8, 0xaee20260,
-0x8c0200ac, 0xaee20264, 0x8c0200b0, 0xaee20268,
-0x8c0200b4, 0xaee2026c, 0x8c0200b8, 0xaee20270,
-0x8c0200bc, 0x24040001, 0xaee20274, 0xaee00034,
-0x41080, 0x571021, 0x8ee30034, 0x8c42023c,
-0x24840001, 0x621821, 0x2c82000f, 0xaee30034,
-0x1440fff8, 0x41080, 0x8c0200cc, 0xaee20048,
-0x8c0200d0, 0xaee2004c, 0x8c0200e0, 0xaee201f8,
-0x8c0200e4, 0xaee201fc, 0x8c0200e8, 0xaee20200,
-0x8c0200ec, 0xaee20204, 0x8c0200f0, 0xaee20208,
-0x8ee400c0, 0x8ee500c4, 0x8c0200fc, 0x45102b,
-0x1040000b, 0x0, 0x8ee200c0, 0x8ee300c4,
-0x24040001, 0x24050000, 0x651821, 0x65302b,
-0x441021, 0x461021, 0xaee200c0, 0xaee300c4,
-0x8c0200fc, 0x8ee400c0, 0x8ee500c4, 0x2408ffff,
-0x24090000, 0x401821, 0x1021, 0x882024,
-0xa92824, 0x822025, 0xa32825, 0xaee400c0,
-0xaee500c4, 0x8ee400d0, 0x8ee500d4, 0x8c0200f4,
-0x45102b, 0x1040000b, 0x0, 0x8ee200d0,
-0x8ee300d4, 0x24040001, 0x24050000, 0x651821,
-0x65302b, 0x441021, 0x461021, 0xaee200d0,
-0xaee300d4, 0x8c0200f4, 0x8ee400d0, 0x8ee500d4,
-0x401821, 0x1021, 0x882024, 0xa92824,
-0x822025, 0xa32825, 0xaee400d0, 0xaee500d4,
-0x8ee400c8, 0x8ee500cc, 0x8c0200f8, 0x45102b,
-0x1040000b, 0x0, 0x8ee200c8, 0x8ee300cc,
-0x24040001, 0x24050000, 0x651821, 0x65302b,
-0x441021, 0x461021, 0xaee200c8, 0xaee300cc,
-0x8c0200f8, 0x8ee400c8, 0x8ee500cc, 0x401821,
-0x1021, 0x882024, 0xa92824, 0x822025,
-0xa32825, 0x24020008, 0xaee400c8, 0xaee500cc,
-0xafa20010, 0xafa00014, 0x8f42000c, 0x8c040208,
-0x8c05020c, 0xafa20018, 0x8f42010c, 0x26e60028,
-0x40f809, 0x24070400, 0x104000f1, 0x3c020400,
-0xafa20020, 0x934205c6, 0x10400089, 0x1821,
-0x8f5e0018, 0x27aa0020, 0x240200ff, 0x13c20002,
-0xafaa002c, 0x27c30001, 0x8c020228, 0x609021,
-0x1642000e, 0x1e38c0, 0x8f42033c, 0x24420001,
-0xaf42033c, 0x8f42033c, 0x8c020228, 0x3c040001,
-0x24847824, 0x3c050009, 0xafa00014, 0xafa20010,
-0x8fa60020, 0x1000006b, 0x34a50500, 0xf71021,
-0x8fa30020, 0x8fa40024, 0xac4304c0, 0xac4404c4,
-0x8f830054, 0x8f820054, 0x247003e8, 0x2021023,
-0x2c4203e9, 0x1040001b, 0x9821, 0xe08821,
-0x263504c0, 0x8f440178, 0x8f45017c, 0x2201821,
-0x240a0004, 0xafaa0010, 0xafb20014, 0x8f48000c,
-0x1021, 0x2f53021, 0xafa80018, 0x8f48010c,
-0x24070008, 0xa32821, 0xa3482b, 0x822021,
-0x100f809, 0x892021, 0x54400006, 0x24130001,
-0x8f820054, 0x2021023, 0x2c4203e9, 0x1440ffe9,
-0x0, 0x326200ff, 0x54400017, 0xaf520018,
-0x8f420378, 0x24420001, 0xaf420378, 0x8f420378,
-0x8f820120, 0x8faa002c, 0xafa20010, 0x8f820124,
-0x3c040001, 0x24847830, 0x3c050009, 0xafa20014,
-0x8d460000, 0x10000033, 0x34a50600, 0x8f420308,
-0x24130001, 0x24420001, 0xaf420308, 0x8f420308,
-0x1000001c, 0x326200ff, 0x8f830054, 0x8f820054,
-0x247003e8, 0x2021023, 0x2c4203e9, 0x10400014,
-0x9821, 0x24110010, 0x8f42000c, 0x8f440160,
-0x8f450164, 0x8f860120, 0xafb10010, 0xafb20014,
-0xafa20018, 0x8f42010c, 0x24070008, 0x40f809,
-0x24c6001c, 0x1440ffe5, 0x0, 0x8f820054,
-0x2021023, 0x2c4203e9, 0x1440ffef, 0x0,
-0x326200ff, 0x54400012, 0x24020001, 0x8f420378,
-0x24420001, 0xaf420378, 0x8f420378, 0x8f820120,
-0x8faa002c, 0xafa20010, 0x8f820124, 0x3c040001,
-0x24847838, 0x3c050009, 0xafa20014, 0x8d460000,
-0x34a50700, 0xc002d3b, 0x3c03821, 0x1021,
-0x1440005b, 0x24020001, 0x10000066, 0x0,
-0x8f510018, 0x240200ff, 0x12220002, 0x8021,
-0x26300001, 0x8c020228, 0x1602000e, 0x1130c0,
-0x8f42033c, 0x24420001, 0xaf42033c, 0x8f42033c,
-0x8c020228, 0x3c040001, 0x2484780c, 0x3c050009,
-0xafa00014, 0xafa20010, 0x8fa60020, 0x1000003f,
-0x34a50100, 0xd71021, 0x8fa30020, 0x8fa40024,
-0xac4304c0, 0xac4404c4, 0xc01821, 0x8f440178,
-0x8f45017c, 0x1021, 0x24070004, 0xafa70010,
-0xafb00014, 0x8f48000c, 0x24c604c0, 0x2e63021,
-0xafa80018, 0x8f48010c, 0x24070008, 0xa32821,
-0xa3482b, 0x822021, 0x100f809, 0x892021,
-0x1440000b, 0x24070008, 0x8f820120, 0xafa20010,
-0x8f820124, 0x3c040001, 0x24847814, 0x3c050009,
-0xafa20014, 0x8fa60020, 0x1000001c, 0x34a50200,
-0x8f440160, 0x8f450164, 0x8f43000c, 0xaf500018,
-0x8f860120, 0x24020010, 0xafa20010, 0xafb00014,
-0xafa30018, 0x8f42010c, 0x40f809, 0x24c6001c,
-0x54400011, 0x24020001, 0x8f420340, 0x24420001,
-0xaf420340, 0x8f420340, 0x8f820120, 0xafa20010,
-0x8f820124, 0x3c040001, 0x2484781c, 0x3c050009,
-0xafa20014, 0x8fa60020, 0x34a50300, 0xc002d3b,
-0x2203821, 0x1021, 0x1040000e, 0x24020001,
-0x8f4202e8, 0xa34005c6, 0xaf4001b0, 0x24420001,
-0xaf4202e8, 0x8f4202e8, 0x8ee20150, 0x24420001,
-0xaee20150, 0x8ee20150, 0x10000003, 0x0,
-0x24020001, 0xa34205c6, 0x8fbf0048, 0x8fbe0044,
-0x8fb50040, 0x8fb3003c, 0x8fb20038, 0x8fb10034,
-0x8fb00030, 0x3e00008, 0x27bd0050, 0x27bdffd8,
-0xafbf0020, 0x8f8200b0, 0x30420004, 0x10400069,
-0x0, 0x8f430128, 0x8f820104, 0x14620005,
-0x0, 0x8f430130, 0x8f8200b4, 0x10620006,
-0x0, 0x8f820104, 0xaf420128, 0x8f8200b4,
-0x1000005c, 0xaf420130, 0x8f8200b0, 0x3c030080,
-0x431024, 0x1040000e, 0x0, 0x8f82011c,
-0x34420002, 0xaf82011c, 0x8f8200b0, 0x2403fffb,
-0x431024, 0xaf8200b0, 0x8f82011c, 0x2403fffd,
-0x431024, 0xaf82011c, 0x1000004a, 0x0,
-0x8f430128, 0x8f820104, 0x14620005, 0x0,
-0x8f430130, 0x8f8200b4, 0x10620010, 0x0,
-0x8f820104, 0xaf420128, 0x8f8200b4, 0x8f430128,
-0xaf420130, 0xafa30010, 0x8f420130, 0x3c040001,
-0x24847874, 0xafa20014, 0x8f86011c, 0x8f8700b0,
-0x3c050005, 0x10000031, 0x34a50900, 0x8f420128,
-0xafa20010, 0x8f420130, 0x3c040001, 0x24847880,
-0xafa20014, 0x8f86011c, 0x8f8700b0, 0x3c050005,
-0xc002d3b, 0x34a51000, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f830104, 0x8f8200b0, 0x34420001,
-0xaf8200b0, 0x24020008, 0xaf830104, 0xafa20010,
-0xafa00014, 0x8f42000c, 0x8c040208, 0x8c05020c,
-0xafa20018, 0x8f42010c, 0x26e60028, 0x40f809,
-0x24070400, 0x8f82011c, 0x2403fffd, 0x431024,
-0xaf82011c, 0x8ee201dc, 0x24420001, 0xaee201dc,
-0x8ee201dc, 0x8f420128, 0xafa20010, 0x8f420130,
-0x3c040001, 0x2484788c, 0xafa20014, 0x8f86011c,
-0x8f8700b0, 0x3c050005, 0x34a51100, 0xc002d3b,
-0x0, 0x8f8200a0, 0x30420004, 0x1040006a,
-0x0, 0x8f43012c, 0x8f820124, 0x14620005,
-0x0, 0x8f430134, 0x8f8200a4, 0x10620006,
-0x0, 0x8f820124, 0xaf42012c, 0x8f8200a4,
-0x1000005d, 0xaf420134, 0x8f8200a0, 0x3c030080,
-0x431024, 0x1040000e, 0x0, 0x8f82011c,
-0x34420002, 0xaf82011c, 0x8f8200a0, 0x2403fffb,
-0x431024, 0xaf8200a0, 0x8f82011c, 0x2403fffd,
-0x431024, 0xaf82011c, 0x1000004b, 0x0,
-0x8f43012c, 0x8f820124, 0x14620005, 0x0,
-0x8f430134, 0x8f8200a4, 0x10620010, 0x0,
-0x8f820124, 0xaf42012c, 0x8f8200a4, 0x8f43012c,
-0xaf420134, 0xafa30010, 0x8f420134, 0x3c040001,
-0x24847898, 0xafa20014, 0x8f86011c, 0x8f8700a0,
-0x3c050005, 0x10000032, 0x34a51200, 0x8f42012c,
-0xafa20010, 0x8f420134, 0x3c040001, 0x248478a4,
-0xafa20014, 0x8f86011c, 0x8f8700a0, 0x3c050005,
-0xc002d3b, 0x34a51300, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f830124, 0x8f8200a0, 0x34420001,
-0xaf8200a0, 0x24020080, 0xaf830124, 0xafa20010,
-0xafa00014, 0x8f420014, 0x8c040208, 0x8c05020c,
-0xafa20018, 0x8f420108, 0x3c060002, 0x24c68794,
-0x40f809, 0x24070004, 0x8f82011c, 0x2403fffd,
-0x431024, 0xaf82011c, 0x8ee201dc, 0x24420001,
-0xaee201dc, 0x8ee201dc, 0x8f42012c, 0xafa20010,
-0x8f420134, 0x3c040001, 0x248478b0, 0xafa20014,
-0x8f86011c, 0x8f8700a0, 0x3c050005, 0x34a51400,
-0xc002d3b, 0x0, 0x8fbf0020, 0x3e00008,
-0x27bd0028, 0x3c081000, 0x24070001, 0x3c060080,
-0x3c050100, 0x8f820070, 0x481024, 0x1040fffd,
-0x0, 0x8f820054, 0x24420005, 0xaf820078,
-0x8c040234, 0x10800017, 0x1821, 0x3c020001,
-0x571021, 0x8c4240e8, 0x24420005, 0x3c010001,
-0x370821, 0xac2240e8, 0x3c020001, 0x571021,
-0x8c4240e8, 0x44102b, 0x1440000a, 0x0,
-0x3c030080, 0x3c010001, 0x370821, 0xac2040e8,
-0x3c010001, 0x370821, 0xa02740f0, 0x1000000b,
-0x0, 0x3c020001, 0x571021, 0x904240f0,
-0x54400006, 0x661825, 0x3c020001, 0x571021,
-0x904240f1, 0x54400001, 0x661825, 0x8c040230,
-0x10800013, 0x0, 0x3c020001, 0x571021,
-0x8c4240ec, 0x24420005, 0x3c010001, 0x370821,
-0xac2240ec, 0x3c020001, 0x571021, 0x8c4240ec,
-0x44102b, 0x14400006, 0x0, 0x3c010001,
-0x370821, 0xac2040ec, 0x10000006, 0x651825,
-0x3c020001, 0x571021, 0x904240f2, 0x54400001,
-0x651825, 0x1060ffbb, 0x0, 0x8f420000,
-0x10400007, 0x0, 0xaf80004c, 0x8f82004c,
-0x1040fffd, 0x0, 0x10000005, 0x0,
-0xaf800048, 0x8f820048, 0x1040fffd, 0x0,
-0x8f820060, 0x431025, 0xaf820060, 0x8f420000,
-0x10400004, 0x0, 0xaf80004c, 0x1000ffa5,
-0x0, 0xaf800048, 0x1000ffa2, 0x0,
-0x3e00008, 0x0, 0x27bdffe0, 0xafbf0018,
-0x8f860064, 0x30c20004, 0x10400026, 0x24040004,
-0x8c020114, 0xaf420020, 0xaf840064, 0x8f4202fc,
-0x24420001, 0xaf4202fc, 0x8f4202fc, 0x8f820064,
-0x30420004, 0x14400005, 0x0, 0x8c030114,
-0x8f420020, 0x1462fff2, 0x0, 0x8f420000,
-0x8f43003c, 0x10400007, 0x0, 0xaf80004c,
-0x8f82004c, 0x1040fffd, 0x0, 0x10000005,
-0x0, 0xaf800048, 0x8f820048, 0x1040fffd,
-0x0, 0x8f820060, 0x431025, 0xaf820060,
-0x8f420000, 0x10400074, 0x0, 0x1000006f,
-0x0, 0x30c20008, 0x10400020, 0x24040008,
-0x8c02011c, 0xaf420048, 0xaf840064, 0x8f4202a8,
-0x24420001, 0xaf4202a8, 0x8f4202a8, 0x8f820064,
-0x30420008, 0x14400005, 0x0, 0x8c03011c,
-0x8f420048, 0x1462fff2, 0x0, 0x8f420000,
-0x10400007, 0x0, 0xaf80004c, 0x8f82004c,
-0x1040fffd, 0x0, 0x10000005, 0x0,
-0xaf800048, 0x8f820048, 0x1040fffd, 0x0,
-0x8f820060, 0x1000ffd9, 0x34420200, 0x30c20020,
-0x10400023, 0x24040020, 0x8c02012c, 0xaf420068,
-0xaf840064, 0x8f4202d8, 0x24420001, 0xaf4202d8,
-0x8f4202d8, 0x8f820064, 0x30420020, 0x14400005,
-0x32c24000, 0x8c03012c, 0x8f420068, 0x1462fff2,
-0x32c24000, 0x14400002, 0x3c020001, 0x2c2b025,
-0x8f420000, 0x10400007, 0x0, 0xaf80004c,
-0x8f82004c, 0x1040fffd, 0x0, 0x10000005,
-0x0, 0xaf800048, 0x8f820048, 0x1040fffd,
-0x0, 0x8f820060, 0x1000ffb4, 0x34420800,
-0x30c20010, 0x1040002b, 0x24040010, 0x8c020124,
-0xaf420058, 0xaf840064, 0x8f4202d4, 0x24420001,
-0xaf4202d4, 0x8f4202d4, 0x8f820064, 0x30420010,
-0x14400005, 0x32c22000, 0x8c030124, 0x8f420058,
-0x1462fff2, 0x32c22000, 0x50400001, 0x36d68000,
-0x8f420000, 0x10400007, 0x0, 0xaf80004c,
-0x8f82004c, 0x1040fffd, 0x0, 0x10000005,
-0x0, 0xaf800048, 0x8f820048, 0x1040fffd,
-0x0, 0x8f820060, 0x34420100, 0xaf820060,
-0x8f420000, 0x10400004, 0x0, 0xaf80004c,
-0x10000072, 0x0, 0xaf800048, 0x1000006f,
-0x0, 0x30c20001, 0x10400004, 0x24020001,
-0xaf820064, 0x10000069, 0x0, 0x30c20002,
-0x1440000c, 0x3c050003, 0x3c040001, 0x24847974,
-0x34a50500, 0x3821, 0xafa00010, 0xc002d3b,
-0xafa00014, 0x2402ffc0, 0xaf820064, 0x1000005b,
-0x0, 0x8c05022c, 0x8c02010c, 0x10a2004c,
-0x51080, 0x8c460300, 0x24a20001, 0x3045003f,
-0x24020003, 0xac05022c, 0x61e02, 0x10620005,
-0x24020010, 0x1062001e, 0x30c20fff, 0x1000003d,
-0x0, 0x8f4302a8, 0x8f440000, 0x30c20fff,
-0xaf420048, 0x24630001, 0xaf4302a8, 0x8f4202a8,
-0x10800007, 0x0, 0xaf80004c, 0x8f82004c,
-0x1040fffd, 0x0, 0x10000005, 0x0,
-0xaf800048, 0x8f820048, 0x1040fffd, 0x0,
-0x8f820060, 0x34420200, 0xaf820060, 0x8f420000,
-0x10400021, 0x0, 0x1000001c, 0x0,
-0xaf420058, 0x32c22000, 0x50400001, 0x36d68000,
-0x8f4202d4, 0x8f430000, 0x24420001, 0xaf4202d4,
-0x8f4202d4, 0x10600007, 0x0, 0xaf80004c,
-0x8f82004c, 0x1040fffd, 0x0, 0x10000005,
-0x0, 0xaf800048, 0x8f820048, 0x1040fffd,
-0x0, 0x8f820060, 0x34420100, 0xaf820060,
-0x8f420000, 0x10400004, 0x0, 0xaf80004c,
-0x10000007, 0x0, 0xaf800048, 0x10000004,
-0x0, 0xc0022ad, 0xc02021, 0x402821,
-0x8c02010c, 0x14a20002, 0x24020002, 0xaf820064,
-0x8f820064, 0x30420002, 0x14400004, 0x0,
-0x8c02010c, 0x14a2ffa8, 0x0, 0x8fbf0018,
-0x3e00008, 0x27bd0020, 0x3e00008, 0x0,
-0x27bdffa0, 0xafb00040, 0x808021, 0x101602,
-0x2442ffff, 0x304300ff, 0x2c620013, 0xafbf0058,
-0xafbe0054, 0xafb50050, 0xafb3004c, 0xafb20048,
-0xafb10044, 0x104001fe, 0xafa50034, 0x31080,
-0x3c010001, 0x220821, 0x8c2279b8, 0x400008,
-0x0, 0x101302, 0x30440fff, 0x24020001,
-0x10820005, 0x24020002, 0x1082000c, 0x2402fffe,
-0x10000025, 0x3c050003, 0x8f430004, 0x3c020002,
-0x8c4287c0, 0xaf440200, 0xaf440204, 0x3c040002,
-0x8c84873c, 0x10000009, 0x34630001, 0x8f430004,
-0xaf440200, 0xaf440204, 0x3c040002, 0x8c84873c,
-0x621824, 0x3c020001, 0x2442d68c, 0x21100,
-0x21182, 0xaf430004, 0x3c030800, 0x431025,
-0xac820038, 0x8f840054, 0x41442, 0x41c82,
-0x431021, 0x41cc2, 0x431023, 0x41d02,
-0x431021, 0x41d42, 0x431023, 0xaf420208,
-0x10000009, 0x0, 0x3c040001, 0x24847980,
-0x34a51000, 0x2003021, 0x3821, 0xafa00010,
-0xc002d3b, 0xafa00014, 0x8f4202a0, 0x24420001,
-0xaf4202a0, 0x8f4202a0, 0x10000228, 0x0,
-0x27b00028, 0x2002021, 0x24050210, 0xc002dbf,
-0x24060008, 0xc00263a, 0x2002021, 0x1000021f,
-0x0, 0x8faa0034, 0x27a40028, 0xa1880,
-0x25420001, 0x3042003f, 0xafa20034, 0x8c650300,
-0x8faa0034, 0x21080, 0x8c430300, 0x25420001,
-0x3042003f, 0xafa20034, 0xac02022c, 0xafa50028,
-0xc00263a, 0xafa3002c, 0x1000020c, 0x0,
-0x27b00028, 0x2002021, 0x24050210, 0xc002dbf,
-0x24060008, 0xc002779, 0x2002021, 0x10000203,
-0x0, 0x8faa0034, 0x27a40028, 0xa1880,
-0x25420001, 0x3042003f, 0xafa20034, 0x8c650300,
-0x8faa0034, 0x21080, 0x8c430300, 0x25420001,
-0x3042003f, 0xafa20034, 0xac02022c, 0xafa50028,
-0xc002779, 0xafa3002c, 0x100001f0, 0x0,
-0x101302, 0x30430fff, 0x24020001, 0x10620005,
-0x24020002, 0x1062001e, 0x3c020002, 0x10000033,
-0x3c050003, 0x3c030002, 0x2c31024, 0x54400037,
-0x2c3b025, 0x8f820228, 0x3c010001, 0x370821,
-0xac2238d8, 0x8f82022c, 0x3c010001, 0x370821,
-0xac2238dc, 0x8f820230, 0x3c010001, 0x370821,
-0xac2238e0, 0x8f820234, 0x3c010001, 0x370821,
-0xac2238e4, 0x2402ffff, 0xaf820228, 0xaf82022c,
-0xaf820230, 0xaf820234, 0x10000020, 0x2c3b025,
-0x2c21024, 0x10400012, 0x3c02fffd, 0x3c020001,
-0x571021, 0x8c4238d8, 0xaf820228, 0x3c020001,
-0x571021, 0x8c4238dc, 0xaf82022c, 0x3c020001,
-0x571021, 0x8c4238e0, 0xaf820230, 0x3c020001,
-0x571021, 0x8c4238e4, 0xaf820234, 0x3c02fffd,
-0x3442ffff, 0x10000009, 0x2c2b024, 0x3c040001,
-0x2484798c, 0x34a51100, 0x2003021, 0x3821,
-0xafa00010, 0xc002d3b, 0xafa00014, 0x8f4202cc,
-0x24420001, 0xaf4202cc, 0x8f4202cc, 0x100001a7,
-0x0, 0x101302, 0x30450fff, 0x24020001,
-0x10a20005, 0x24020002, 0x10a2000e, 0x3c0408ff,
-0x10000016, 0x3c050003, 0x3c0208ff, 0x3442ffff,
-0x8f830220, 0x3c040004, 0x2c4b025, 0x621824,
-0x34630008, 0xaf830220, 0xaf450298, 0x10000013,
-0x0, 0x3484fff7, 0x3c03fffb, 0x8f820220,
-0x3463ffff, 0x2c3b024, 0x441024, 0xaf820220,
-0xaf450298, 0x10000009, 0x0, 0x3c040001,
-0x24847998, 0x34a51200, 0x2003021, 0x3821,
-0xafa00010, 0xc002d3b, 0xafa00014, 0x8f4202bc,
-0x24420001, 0xaf4202bc, 0x8f4202bc, 0x1000017b,
-0x0, 0x27840208, 0x24050200, 0xc002dbf,
-0x24060008, 0x27440224, 0x24050200, 0xc002dbf,
-0x24060008, 0x8f4202c4, 0x24420001, 0xaf4202c4,
-0x8f4202c4, 0x1000016d, 0x0, 0x101302,
-0x30430fff, 0x24020001, 0x10620011, 0x28620002,
-0x50400005, 0x24020002, 0x10600007, 0x0,
-0x10000017, 0x0, 0x1062000f, 0x0,
-0x10000013, 0x0, 0x8c060248, 0x2021,
-0xc005738, 0x24050004, 0x10000007, 0x0,
-0x8c060248, 0x2021, 0xc005738, 0x24050004,
-0x10000010, 0x0, 0x8c06024c, 0x2021,
-0xc005738, 0x24050001, 0x1000000a, 0x0,
-0x3c040001, 0x248479a4, 0x3c050003, 0x34a51300,
-0x2003021, 0x3821, 0xafa00010, 0xc002d3b,
-0xafa00014, 0x8f4202c0, 0x24420001, 0xaf4202c0,
-0x8f4202c0, 0x1000013d, 0x0, 0xc002548,
-0x0, 0x10000139, 0x0, 0x24020001,
-0xa34205c5, 0x24100100, 0x8f4401a8, 0x8f4501ac,
-0xafb00010, 0xafa00014, 0x8f420014, 0xafa20018,
-0x8f420108, 0x26e60028, 0x40f809, 0x24070400,
-0x1040fff5, 0x0, 0x10000128, 0x0,
-0x3c03ffff, 0x34637fff, 0x8f420368, 0x8f440360,
-0x2c3b024, 0x1821, 0xaf400058, 0xaf40005c,
-0xaf400060, 0xaf400064, 0x441023, 0xaf420368,
-0x3c020900, 0xaf400360, 0xafa20020, 0x8f5e0018,
-0x27aa0020, 0x240200ff, 0x13c20002, 0xafaa003c,
-0x27c30001, 0x8c020228, 0x609021, 0x1642000e,
-0x1e38c0, 0x8f42033c, 0x24420001, 0xaf42033c,
-0x8f42033c, 0x8c020228, 0x3c040001, 0x2484793c,
-0x3c050009, 0xafa00014, 0xafa20010, 0x8fa60020,
-0x1000006b, 0x34a50500, 0xf71021, 0x8fa30020,
-0x8fa40024, 0xac4304c0, 0xac4404c4, 0x8f830054,
-0x8f820054, 0x247003e8, 0x2021023, 0x2c4203e9,
-0x1040001b, 0x9821, 0xe08821, 0x263504c0,
-0x8f440178, 0x8f45017c, 0x2201821, 0x240a0004,
-0xafaa0010, 0xafb20014, 0x8f48000c, 0x1021,
-0x2f53021, 0xafa80018, 0x8f48010c, 0x24070008,
-0xa32821, 0xa3482b, 0x822021, 0x100f809,
-0x892021, 0x54400006, 0x24130001, 0x8f820054,
-0x2021023, 0x2c4203e9, 0x1440ffe9, 0x0,
-0x326200ff, 0x54400017, 0xaf520018, 0x8f420378,
-0x24420001, 0xaf420378, 0x8f420378, 0x8f820120,
-0x8faa003c, 0xafa20010, 0x8f820124, 0x3c040001,
-0x24847948, 0x3c050009, 0xafa20014, 0x8d460000,
-0x10000033, 0x34a50600, 0x8f420308, 0x24130001,
-0x24420001, 0xaf420308, 0x8f420308, 0x1000001c,
-0x326200ff, 0x8f830054, 0x8f820054, 0x247003e8,
-0x2021023, 0x2c4203e9, 0x10400014, 0x9821,
-0x24110010, 0x8f42000c, 0x8f440160, 0x8f450164,
-0x8f860120, 0xafb10010, 0xafb20014, 0xafa20018,
-0x8f42010c, 0x24070008, 0x40f809, 0x24c6001c,
-0x1440ffe5, 0x0, 0x8f820054, 0x2021023,
-0x2c4203e9, 0x1440ffef, 0x0, 0x326200ff,
-0x14400011, 0x0, 0x8f420378, 0x24420001,
-0xaf420378, 0x8f420378, 0x8f820120, 0x8faa003c,
-0xafa20010, 0x8f820124, 0x3c040001, 0x24847950,
-0x3c050009, 0xafa20014, 0x8d460000, 0x34a50700,
-0xc002d3b, 0x3c03821, 0x8f4202b0, 0x24420001,
-0xaf4202b0, 0x8f4202b0, 0x8f4202f8, 0x24420001,
-0xaf4202f8, 0x8f4202f8, 0x1000008c, 0x0,
-0x8c02025c, 0x27440224, 0xaf4201f0, 0x8c020260,
-0x24050200, 0x24060008, 0xaf4201f8, 0xc002dbf,
-0x0, 0x8f820220, 0x30420008, 0x14400002,
-0x24020001, 0x24020002, 0xaf420298, 0x8f4202ac,
-0x24420001, 0xaf4202ac, 0x8f4202ac, 0x10000077,
-0x0, 0x3c0200ff, 0x3442ffff, 0x2021824,
-0x32c20180, 0x14400006, 0x3402fffb, 0x43102b,
-0x14400003, 0x0, 0x1000006c, 0xaf4300bc,
-0x3c040001, 0x248479b0, 0x3c050003, 0x34a51500,
-0x2003021, 0x3821, 0xafa00010, 0xc002d3b,
-0xafa00014, 0x3c020700, 0x34421000, 0x101e02,
-0x621825, 0xafa30020, 0x8f510018, 0x240200ff,
-0x12220002, 0x8021, 0x26300001, 0x8c020228,
-0x1602000e, 0x1130c0, 0x8f42033c, 0x24420001,
-0xaf42033c, 0x8f42033c, 0x8c020228, 0x3c040001,
-0x24847924, 0x3c050009, 0xafa00014, 0xafa20010,
-0x8fa60020, 0x1000003f, 0x34a50100, 0xd71021,
-0x8fa30020, 0x8fa40024, 0xac4304c0, 0xac4404c4,
-0xc01821, 0x8f440178, 0x8f45017c, 0x1021,
-0x24070004, 0xafa70010, 0xafb00014, 0x8f48000c,
-0x24c604c0, 0x2e63021, 0xafa80018, 0x8f48010c,
-0x24070008, 0xa32821, 0xa3482b, 0x822021,
-0x100f809, 0x892021, 0x1440000b, 0x24070008,
-0x8f820120, 0xafa20010, 0x8f820124, 0x3c040001,
-0x2484792c, 0x3c050009, 0xafa20014, 0x8fa60020,
-0x1000001c, 0x34a50200, 0x8f440160, 0x8f450164,
-0x8f43000c, 0xaf500018, 0x8f860120, 0x24020010,
-0xafa20010, 0xafb00014, 0xafa30018, 0x8f42010c,
-0x40f809, 0x24c6001c, 0x14400010, 0x0,
-0x8f420340, 0x24420001, 0xaf420340, 0x8f420340,
-0x8f820120, 0xafa20010, 0x8f820124, 0x3c040001,
-0x24847934, 0x3c050009, 0xafa20014, 0x8fa60020,
-0x34a50300, 0xc002d3b, 0x2203821, 0x8f4202e0,
-0x24420001, 0xaf4202e0, 0x8f4202e0, 0x8f4202f0,
-0x24420001, 0xaf4202f0, 0x8f4202f0, 0x8fa20034,
-0x8fbf0058, 0x8fbe0054, 0x8fb50050, 0x8fb3004c,
-0x8fb20048, 0x8fb10044, 0x8fb00040, 0x3e00008,
-0x27bd0060, 0x27bdfff8, 0x2408ffff, 0x10a00014,
-0x4821, 0x3c0aedb8, 0x354a8320, 0x90870000,
-0x24840001, 0x3021, 0x1071026, 0x30420001,
-0x10400002, 0x81842, 0x6a1826, 0x604021,
-0x24c60001, 0x2cc20008, 0x1440fff7, 0x73842,
-0x25290001, 0x125102b, 0x1440fff0, 0x0,
-0x1001021, 0x3e00008, 0x27bd0008, 0x27bdffb0,
-0xafbf0048, 0xafbe0044, 0xafb50040, 0xafb3003c,
-0xafb20038, 0xafb10034, 0xafb00030, 0x8f870220,
-0xafa70024, 0x8f870200, 0xafa7002c, 0x8f820220,
-0x3c0308ff, 0x3463ffff, 0x431024, 0x34420004,
-0xaf820220, 0x8f820200, 0x3c03c0ff, 0x3463ffff,
-0x431024, 0x34420004, 0xaf820200, 0x8f530358,
-0x8f55035c, 0x8f5e0360, 0x8f470364, 0xafa70014,
-0x8f470368, 0xafa7001c, 0x8f4202d0, 0x274401c0,
-0x24420001, 0xaf4202d0, 0x8f5002d0, 0x8f510204,
-0x8f520200, 0xc002da8, 0x24050400, 0xaf530358,
-0xaf55035c, 0xaf5e0360, 0x8fa70014, 0xaf470364,
-0x8fa7001c, 0xaf470368, 0xaf5002d0, 0xaf510204,
-0xaf520200, 0x8c02025c, 0x27440224, 0xaf4201f0,
-0x8c020260, 0x24050200, 0x24060008, 0xaf4201f8,
-0x24020006, 0xaf4201f4, 0xc002dbf, 0x0,
-0x3c023b9a, 0x3442ca00, 0xaf4201fc, 0x240203e8,
-0x24040002, 0x24030001, 0xaf420294, 0xaf440290,
-0xaf43029c, 0x8f820220, 0x30420008, 0x10400004,
-0x0, 0xaf430298, 0x10000003, 0x3021,
-0xaf440298, 0x3021, 0x3c030002, 0x661821,
-0x906385ec, 0x3461021, 0x24c60001, 0xa043022c,
-0x2cc2000f, 0x1440fff8, 0x3461821, 0x24c60001,
-0x8f820040, 0x24040080, 0x24050080, 0x21702,
-0x24420030, 0xa062022c, 0x3461021, 0xa040022c,
-0xc002da8, 0x0, 0x8fa70024, 0x30e20004,
-0x14400006, 0x0, 0x8f820220, 0x3c0308ff,
-0x3463fffb, 0x431024, 0xaf820220, 0x8fa7002c,
-0x30e20004, 0x14400006, 0x0, 0x8f820200,
-0x3c03c0ff, 0x3463fffb, 0x431024, 0xaf820200,
-0x8fbf0048, 0x8fbe0044, 0x8fb50040, 0x8fb3003c,
-0x8fb20038, 0x8fb10034, 0x8fb00030, 0x3e00008,
-0x27bd0050, 0xaf400104, 0x24040001, 0x410c0,
-0x2e21821, 0x24820001, 0x3c010001, 0x230821,
-0xa42234d0, 0x402021, 0x2c820080, 0x1440fff8,
-0x410c0, 0x24020001, 0x3c010001, 0x370821,
-0xa42038d0, 0xaf420100, 0xaf800228, 0xaf80022c,
-0xaf800230, 0xaf800234, 0x3e00008, 0x0,
-0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f420104,
-0x28420005, 0x10400026, 0x808021, 0x3c020001,
-0x8f430104, 0x344230d0, 0x2e23021, 0x318c0,
-0x621821, 0x2e33821, 0xc7102b, 0x10400015,
-0x1021, 0x96080000, 0x24c40006, 0x9482fffc,
-0x14480009, 0x2821, 0x9483fffe, 0x96020002,
-0x14620006, 0xa01021, 0x94820000, 0x96030004,
-0x431026, 0x2c450001, 0xa01021, 0x1440000a,
-0x24c60008, 0xc7102b, 0x1440fff0, 0x24840008,
-0x1021, 0x304200ff, 0x14400030, 0x24020001,
-0x1000002e, 0x1021, 0x1000fffa, 0x24020001,
-0x2002021, 0xc00252e, 0x24050006, 0x3042007f,
-0x218c0, 0x2e31021, 0x3c010001, 0x220821,
-0x942230d0, 0x1040fff2, 0x2e31021, 0x3c060001,
-0xc23021, 0x94c630d0, 0x10c0ffed, 0x3c080001,
-0x350834d2, 0x96070000, 0x610c0, 0x572021,
-0x882021, 0x94820000, 0x14470009, 0x2821,
-0x94830002, 0x96020002, 0x14620006, 0xa01021,
-0x94820004, 0x96030004, 0x431026, 0x2c450001,
-0xa01021, 0x14400007, 0x610c0, 0x2e21021,
-0x3c060001, 0xc23021, 0x94c634d0, 0x14c0ffeb,
-0x610c0, 0x10c0ffd2, 0x24020001, 0x8fbf0014,
-0x8fb00010, 0x3e00008, 0x27bd0018, 0x3e00008,
-0x0, 0x27bdffb0, 0x801021, 0xafb00030,
-0x24500002, 0x2002021, 0x24050006, 0xafb10034,
-0x408821, 0xafbf0048, 0xafbe0044, 0xafb50040,
-0xafb3003c, 0xc00252e, 0xafb20038, 0x3047007f,
-0x710c0, 0x2e21021, 0x3c050001, 0xa22821,
-0x94a530d0, 0x50a0001c, 0xa03021, 0x3c090001,
-0x352934d2, 0x96280002, 0x510c0, 0x572021,
-0x892021, 0x94820000, 0x14480009, 0x3021,
-0x94830002, 0x96020002, 0x14620006, 0xc01021,
-0x94820004, 0x96030004, 0x431026, 0x2c460001,
-0xc01021, 0x14400007, 0x510c0, 0x2e21021,
-0x3c050001, 0xa22821, 0x94a534d0, 0x14a0ffeb,
-0x510c0, 0xa03021, 0x10c00014, 0x610c0,
-0x571821, 0x3c010001, 0x230821, 0x8c2334d0,
-0x571021, 0xafa30010, 0x3c010001, 0x220821,
-0x8c2234d4, 0x3c040001, 0x24847ab8, 0xafa20014,
-0x8e260000, 0x8e270004, 0x3c050004, 0xc002d3b,
-0x34a50400, 0x10000063, 0x3c020800, 0x8f450100,
-0x10a00006, 0x510c0, 0x2e21021, 0x3c010001,
-0x220821, 0x942234d0, 0xaf420100, 0xa03021,
-0x14c00011, 0x628c0, 0x710c0, 0x2e21021,
-0xafa70010, 0x3c010001, 0x220821, 0x942230d0,
-0x3c040001, 0x24847ac4, 0xafa20014, 0x8e260000,
-0x8e270004, 0x3c050004, 0xc002d3b, 0x34a50500,
-0x10000048, 0x3c020800, 0xb71821, 0x3c020001,
-0x96040000, 0x344234d2, 0x621821, 0xa4640000,
-0x8e020002, 0x720c0, 0xac620002, 0x2e41021,
-0x3c030001, 0x621821, 0x946330d0, 0x2e51021,
-0x3c010001, 0x220821, 0xa42334d0, 0x2e41021,
-0x3c010001, 0x220821, 0xa42630d0, 0x8f420104,
-0x24420001, 0x28420080, 0x1040000f, 0x3c020002,
-0x8f420104, 0x3c040001, 0x348430d2, 0x96030000,
-0x210c0, 0x571021, 0x441021, 0xa4430000,
-0x8e030002, 0xac430002, 0x8f420104, 0x24420001,
-0xaf420104, 0x3c020002, 0x2c21024, 0x10400011,
-0x72142, 0x3c030001, 0x346338d8, 0x24020003,
-0x441023, 0x21080, 0x572021, 0x832021,
-0x571021, 0x431021, 0x30e5001f, 0x8c430000,
-0x24020001, 0xa21004, 0x621825, 0x1000000c,
-0xac830000, 0x24020003, 0x441023, 0x21080,
-0x5c2821, 0x5c1021, 0x30e4001f, 0x8c430228,
-0x24020001, 0x821004, 0x621825, 0xaca30228,
-0x3c020800, 0x34421000, 0x1821, 0xafa20020,
-0x8f5e0018, 0x27aa0020, 0x240200ff, 0x13c20002,
-0xafaa002c, 0x27c30001, 0x8c020228, 0x609021,
-0x1642000e, 0x1e38c0, 0x8f42033c, 0x24420001,
-0xaf42033c, 0x8f42033c, 0x8c020228, 0x3c040001,
-0x24847a80, 0x3c050009, 0xafa00014, 0xafa20010,
-0x8fa60020, 0x1000006b, 0x34a50500, 0xf71021,
-0x8fa30020, 0x8fa40024, 0xac4304c0, 0xac4404c4,
-0x8f830054, 0x8f820054, 0x247003e8, 0x2021023,
-0x2c4203e9, 0x1040001b, 0x9821, 0xe08821,
-0x263504c0, 0x8f440178, 0x8f45017c, 0x2201821,
-0x240a0004, 0xafaa0010, 0xafb20014, 0x8f48000c,
-0x1021, 0x2f53021, 0xafa80018, 0x8f48010c,
-0x24070008, 0xa32821, 0xa3482b, 0x822021,
-0x100f809, 0x892021, 0x54400006, 0x24130001,
-0x8f820054, 0x2021023, 0x2c4203e9, 0x1440ffe9,
-0x0, 0x326200ff, 0x54400017, 0xaf520018,
-0x8f420378, 0x24420001, 0xaf420378, 0x8f420378,
-0x8f820120, 0x8faa002c, 0xafa20010, 0x8f820124,
-0x3c040001, 0x24847a8c, 0x3c050009, 0xafa20014,
-0x8d460000, 0x10000033, 0x34a50600, 0x8f420308,
-0x24130001, 0x24420001, 0xaf420308, 0x8f420308,
-0x1000001c, 0x326200ff, 0x8f830054, 0x8f820054,
-0x247003e8, 0x2021023, 0x2c4203e9, 0x10400014,
-0x9821, 0x24110010, 0x8f42000c, 0x8f440160,
-0x8f450164, 0x8f860120, 0xafb10010, 0xafb20014,
-0xafa20018, 0x8f42010c, 0x24070008, 0x40f809,
-0x24c6001c, 0x1440ffe5, 0x0, 0x8f820054,
-0x2021023, 0x2c4203e9, 0x1440ffef, 0x0,
-0x326200ff, 0x14400011, 0x0, 0x8f420378,
-0x24420001, 0xaf420378, 0x8f420378, 0x8f820120,
-0x8faa002c, 0xafa20010, 0x8f820124, 0x3c040001,
-0x24847a94, 0x3c050009, 0xafa20014, 0x8d460000,
-0x34a50700, 0xc002d3b, 0x3c03821, 0x8f4202b4,
-0x24420001, 0xaf4202b4, 0x8f4202b4, 0x8f4202f4,
-0x24420001, 0xaf4202f4, 0x8f4202f4, 0x8fbf0048,
-0x8fbe0044, 0x8fb50040, 0x8fb3003c, 0x8fb20038,
-0x8fb10034, 0x8fb00030, 0x3e00008, 0x27bd0050,
-0x27bdffa0, 0x801021, 0xafb00040, 0x24500002,
-0x2002021, 0x24050006, 0xafb10044, 0x408821,
-0xafbf0058, 0xafbe0054, 0xafb50050, 0xafb3004c,
-0xc00252e, 0xafb20048, 0x3048007f, 0x810c0,
-0x2e21021, 0x3c060001, 0xc23021, 0x94c630d0,
-0x10c0001c, 0x3821, 0x3c0a0001, 0x354a34d2,
-0x96290002, 0x610c0, 0x572021, 0x8a2021,
-0x94820000, 0x14490009, 0x2821, 0x94830002,
-0x96020002, 0x14620006, 0xa01021, 0x94820004,
-0x96030004, 0x431026, 0x2c450001, 0xa01021,
-0x14400008, 0x610c0, 0xc03821, 0x2e21021,
-0x3c060001, 0xc23021, 0x94c634d0, 0x14c0ffea,
-0x610c0, 0x14c00011, 0xafa70028, 0x810c0,
-0x2e21021, 0xafa80010, 0x3c010001, 0x220821,
-0x942230d0, 0x3c040001, 0x24847ad0, 0xafa20014,
-0x8e260000, 0x8e270004, 0x3c050004, 0xc002d3b,
-0x34a50900, 0x10000075, 0x3c020800, 0x10e0000c,
-0x610c0, 0x2e21021, 0x3c030001, 0x621821,
-0x946334d0, 0x710c0, 0x2e21021, 0x3c010001,
-0x220821, 0xa42334d0, 0x1000000b, 0x3c040001,
-0x2e21021, 0x3c030001, 0x621821, 0x946334d0,
-0x810c0, 0x2e21021, 0x3c010001, 0x220821,
-0xa42330d0, 0x3c040001, 0x348430d0, 0x8f430100,
-0x610c0, 0x2e21021, 0x3c010001, 0x220821,
-0xa42334d0, 0x8f420104, 0x2e43821, 0x2821,
-0x18400029, 0xaf460100, 0x24e60006, 0x94c3fffc,
-0x96020000, 0x14620009, 0x2021, 0x94c3fffe,
-0x96020002, 0x14620006, 0x801021, 0x94c20000,
-0x96030004, 0x431026, 0x2c440001, 0x801021,
-0x50400014, 0x24a50001, 0x8f420104, 0x2442ffff,
-0xa2102a, 0x1040000b, 0x24e40004, 0x94820006,
-0x8c830008, 0xa482fffe, 0xac830000, 0x8f420104,
-0x24a50001, 0x2442ffff, 0xa2102a, 0x1440fff7,
-0x24840008, 0x8f420104, 0x2442ffff, 0x10000006,
-0xaf420104, 0x8f420104, 0x24c60008, 0xa2102a,
-0x1440ffda, 0x24e70008, 0x810c0, 0x2e21021,
-0x3c010001, 0x220821, 0x942230d0, 0x14400023,
-0x3c020800, 0x3c020002, 0x2c21024, 0x10400012,
-0x82142, 0x3c030001, 0x346338d8, 0x24020003,
-0x441023, 0x21080, 0x572021, 0x832021,
-0x571021, 0x431021, 0x3105001f, 0x24030001,
-0x8c420000, 0xa31804, 0x31827, 0x431024,
-0x1000000d, 0xac820000, 0x24020003, 0x441023,
-0x21080, 0x5c2821, 0x5c1021, 0x3104001f,
-0x24030001, 0x8c420228, 0x831804, 0x31827,
-0x431024, 0xaca20228, 0x3c020800, 0x34422000,
-0x1821, 0xafa20020, 0x8f5e0018, 0x27ab0020,
-0x240200ff, 0x13c20002, 0xafab0034, 0x27c30001,
-0x8c020228, 0x609021, 0x1642000e, 0x1e38c0,
-0x8f42033c, 0x24420001, 0xaf42033c, 0x8f42033c,
-0x8c020228, 0x3c040001, 0x24847a80, 0x3c050009,
-0xafa00014, 0xafa20010, 0x8fa60020, 0x1000006b,
-0x34a50500, 0xf71021, 0x8fa30020, 0x8fa40024,
-0xac4304c0, 0xac4404c4, 0x8f830054, 0x8f820054,
-0x247003e8, 0x2021023, 0x2c4203e9, 0x1040001b,
-0x9821, 0xe08821, 0x263504c0, 0x8f440178,
-0x8f45017c, 0x2201821, 0x240b0004, 0xafab0010,
-0xafb20014, 0x8f48000c, 0x1021, 0x2f53021,
-0xafa80018, 0x8f48010c, 0x24070008, 0xa32821,
-0xa3482b, 0x822021, 0x100f809, 0x892021,
-0x54400006, 0x24130001, 0x8f820054, 0x2021023,
-0x2c4203e9, 0x1440ffe9, 0x0, 0x326200ff,
-0x54400017, 0xaf520018, 0x8f420378, 0x24420001,
-0xaf420378, 0x8f420378, 0x8f820120, 0x8fab0034,
-0xafa20010, 0x8f820124, 0x3c040001, 0x24847a8c,
-0x3c050009, 0xafa20014, 0x8d660000, 0x10000033,
-0x34a50600, 0x8f420308, 0x24130001, 0x24420001,
-0xaf420308, 0x8f420308, 0x1000001c, 0x326200ff,
-0x8f830054, 0x8f820054, 0x247003e8, 0x2021023,
-0x2c4203e9, 0x10400014, 0x9821, 0x24110010,
-0x8f42000c, 0x8f440160, 0x8f450164, 0x8f860120,
-0xafb10010, 0xafb20014, 0xafa20018, 0x8f42010c,
-0x24070008, 0x40f809, 0x24c6001c, 0x1440ffe5,
-0x0, 0x8f820054, 0x2021023, 0x2c4203e9,
-0x1440ffef, 0x0, 0x326200ff, 0x14400011,
-0x0, 0x8f420378, 0x24420001, 0xaf420378,
-0x8f420378, 0x8f820120, 0x8fab0034, 0xafa20010,
-0x8f820124, 0x3c040001, 0x24847a94, 0x3c050009,
-0xafa20014, 0x8d660000, 0x34a50700, 0xc002d3b,
-0x3c03821, 0x8f4202b8, 0x24420001, 0xaf4202b8,
-0x8f4202b8, 0x8f4202f4, 0x24420001, 0xaf4202f4,
-0x8f4202f4, 0x8fbf0058, 0x8fbe0054, 0x8fb50050,
-0x8fb3004c, 0x8fb20048, 0x8fb10044, 0x8fb00040,
-0x3e00008, 0x27bd0060, 0x27bdffe0, 0x27644000,
-0xafbf0018, 0xc002da8, 0x24051000, 0x3c030001,
-0x34632cc0, 0x3c040001, 0x34842ec8, 0x24020020,
-0xaf82011c, 0x2e31021, 0xaf800100, 0xaf800104,
-0xaf800108, 0xaf800110, 0xaf800114, 0xaf800118,
-0xaf800120, 0xaf800124, 0xaf800128, 0xaf800130,
-0xaf800134, 0xaf800138, 0xaf4200ec, 0x2e31021,
-0xaf4200f0, 0x2e41021, 0xaf4200f4, 0x2e41021,
-0xaf4200f8, 0x3c020001, 0x571021, 0x904240f4,
-0x1440001c, 0x3c050001, 0x8f82011c, 0x3c040001,
-0x24847b8c, 0x3c050001, 0x34420001, 0xaf82011c,
-0xafa00010, 0xafa00014, 0x8f86011c, 0x34a50100,
-0xc002d3b, 0x3821, 0x8c020218, 0x30420040,
-0x10400014, 0x0, 0x8f82011c, 0x3c040001,
-0x24847b98, 0x3c050001, 0x34420004, 0xaf82011c,
-0xafa00010, 0xafa00014, 0x8f86011c, 0x10000007,
-0x34a50200, 0x3c040001, 0x24847ba0, 0xafa00010,
-0xafa00014, 0x8f86011c, 0x34a50300, 0xc002d3b,
-0x3821, 0x8fbf0018, 0x3e00008, 0x27bd0020,
-0x27bdffd8, 0xafb1001c, 0x8fb10038, 0xafbf0020,
-0xafb00018, 0x8f83012c, 0x8fa9003c, 0x8faa0040,
-0x1060000a, 0x27624fe0, 0x14620002, 0x24680020,
-0x27684800, 0x8f820128, 0x11020004, 0x0,
-0x8f820124, 0x15020008, 0x0, 0x8f430334,
-0x1021, 0x24630001, 0xaf430334, 0x8f430334,
-0x10000052, 0x0, 0xac640000, 0xac650004,
-0xac660008, 0xa467000e, 0xac710018, 0xac69001c,
-0xac6a0010, 0xac620014, 0xaf880120, 0x8f4200fc,
-0x8f5000f4, 0x2442ffff, 0xaf4200fc, 0x8e020000,
-0x10510005, 0x3042ff8f, 0x10400019, 0x3222ff8f,
-0x10400018, 0x3c020001, 0x8e030004, 0x2c620010,
-0x10400013, 0x3c020001, 0x24630001, 0xae030004,
-0x8f4300f8, 0x344230c8, 0x2e21021, 0x54620004,
-0x24620008, 0x3c020001, 0x34422ec8, 0x2e21021,
-0x1450002e, 0x24020001, 0x8f820128, 0x24420020,
-0xaf820128, 0x8f820128, 0x10000028, 0x24020001,
-0x3c020001, 0x344230c8, 0x2e21021, 0x16020004,
-0x26030008, 0x3c020001, 0x34422ec8, 0x2e21821,
-0x8f4200f8, 0x608021, 0x12020004, 0xaf5000f4,
-0x8e020000, 0x10400016, 0x24020001, 0x24020170,
-0x3c040001, 0x24847ba8, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e77bb0, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x24020001,
-0xae110000, 0xae020004, 0x24020001, 0x8fbf0020,
-0x8fb1001c, 0x8fb00018, 0x3e00008, 0x27bd0028,
-0x3e00008, 0x0, 0x27bdffc8, 0xafb30024,
-0xafb20020, 0x809021, 0xa09821, 0xafb50028,
-0xc0a821, 0xafbf0030, 0xafbe002c, 0xafb1001c,
-0xafb00018, 0x8f900120, 0x27624fe0, 0x16020003,
-0xe0f021, 0x10000002, 0x27714800, 0x26110020,
-0x8f820128, 0x16220008, 0x0, 0x8f430334,
-0x1021, 0x24630001, 0xaf430334, 0x8f430334,
-0x10000028, 0x0, 0x8f820124, 0x16220014,
-0x240201ab, 0x3c040001, 0x24847ba8, 0xafa20010,
-0xafa00014, 0x8f860144, 0x3c070001, 0x24e77bb0,
-0xc002d3b, 0x3405dead, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f820220, 0x34420004, 0xaf820220,
-0x8f820140, 0x3c030001, 0x431025, 0xaf820140,
-0xae120000, 0xae130004, 0xae150008, 0xa61e000e,
-0x8fa80048, 0xae080018, 0x8fa8004c, 0x26020016,
-0xae08001c, 0xae020014, 0x8fa80050, 0xae080010,
-0xaf910120, 0x8f4300fc, 0x24020001, 0x2463ffff,
-0xaf4300fc, 0x8fbf0030, 0x8fbe002c, 0x8fb50028,
-0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018,
-0x3e00008, 0x27bd0038, 0x3e00008, 0x0,
-0x27bdffd8, 0xafb1001c, 0x8fb10038, 0xafbf0020,
-0xafb00018, 0x8f83010c, 0x8fa9003c, 0x8faa0040,
-0x1060000a, 0x276247e0, 0x14620002, 0x24680020,
-0x27684000, 0x8f820108, 0x11020004, 0x0,
-0x8f820104, 0x15020008, 0x0, 0x8f430338,
-0x1021, 0x24630001, 0xaf430338, 0x8f430338,
-0x1000004e, 0x0, 0xac640000, 0xac650004,
-0xac660008, 0xa467000e, 0xac710018, 0xac69001c,
-0xac6a0010, 0xac620014, 0xaf880100, 0x8f5000ec,
-0x8e020000, 0x30420006, 0x10400019, 0x32220006,
-0x10400018, 0x3c020001, 0x8e030004, 0x2c620010,
-0x10400013, 0x3c020001, 0x24630001, 0xae030004,
-0x8f4300f0, 0x34422ec0, 0x2e21021, 0x54620004,
-0x24620008, 0x3c020001, 0x34422cc0, 0x2e21021,
-0x1450002e, 0x24020001, 0x8f820108, 0x24420020,
-0xaf820108, 0x8f820108, 0x10000028, 0x24020001,
-0x3c020001, 0x34422ec0, 0x2e21021, 0x16020004,
-0x26030008, 0x3c020001, 0x34422cc0, 0x2e21821,
-0x8f4200f0, 0x608021, 0x12020004, 0xaf5000ec,
-0x8e020000, 0x10400016, 0x24020001, 0x24020212,
-0x3c040001, 0x24847ba8, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e77bb0, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x24020001,
-0xae110000, 0xae020004, 0x24020001, 0x8fbf0020,
-0x8fb1001c, 0x8fb00018, 0x3e00008, 0x27bd0028,
-0x3e00008, 0x0, 0x27bdffc8, 0xafb30024,
-0xafb20020, 0x809021, 0xa09821, 0xafb50028,
-0xc0a821, 0xafbf0030, 0xafbe002c, 0xafb1001c,
-0xafb00018, 0x8f900100, 0x276247e0, 0x16020003,
-0xe0f021, 0x10000002, 0x27714000, 0x26110020,
-0x8f820108, 0x16220008, 0x0, 0x8f430338,
-0x1021, 0x24630001, 0xaf430338, 0x8f430338,
-0x10000025, 0x0, 0x8f820104, 0x16220014,
-0x2402024d, 0x3c040001, 0x24847ba8, 0xafa20010,
-0xafa00014, 0x8f860144, 0x3c070001, 0x24e77bb0,
-0xc002d3b, 0x3405dead, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f820220, 0x34420004, 0xaf820220,
-0x8f820140, 0x3c030001, 0x431025, 0xaf820140,
-0xae120000, 0xae130004, 0xae150008, 0xa61e000e,
-0x8fa80048, 0xae080018, 0x8fa8004c, 0x26030016,
-0xae08001c, 0xae030014, 0x8fa80050, 0x24020001,
-0xae080010, 0xaf910100, 0x8fbf0030, 0x8fbe002c,
-0x8fb50028, 0x8fb30024, 0x8fb20020, 0x8fb1001c,
-0x8fb00018, 0x3e00008, 0x27bd0038, 0x3e00008,
-0x0, 0x27bdffd8, 0x3c040001, 0x24847bb8,
-0x3c050001, 0xafbf0024, 0xafb20020, 0xafb1001c,
-0xafb00018, 0x8f900104, 0x8f9100b0, 0x8f92011c,
-0x34a52500, 0x8f820100, 0x2403021, 0x2203821,
-0xafa20010, 0xc002d3b, 0xafb00014, 0x8e020008,
-0xafa20010, 0x8e02000c, 0x3c040001, 0x24847bc4,
-0xafa20014, 0x8e060000, 0x8e070004, 0x3c050001,
-0xc002d3b, 0x34a52510, 0x8e020018, 0xafa20010,
-0x8e02001c, 0x3c040001, 0x24847bd0, 0xafa20014,
-0x8e060010, 0x8e070014, 0x3c050001, 0xc002d3b,
-0x34a52520, 0x3c027f00, 0x2221024, 0x3c030800,
-0x54430016, 0x3c030200, 0x8f82009c, 0x3042ffff,
-0x14400012, 0x3c030200, 0x3c040001, 0x24847bdc,
-0x3c050002, 0x34a5f030, 0x3021, 0x3821,
-0x36420002, 0xaf82011c, 0x36220001, 0xaf8200b0,
-0xaf900104, 0xaf92011c, 0xafa00010, 0xc002d3b,
-0xafa00014, 0x10000025, 0x0, 0x2c31024,
-0x1040000e, 0x2231024, 0x1040000c, 0x36420002,
-0xaf82011c, 0x36220001, 0xaf8200b0, 0xaf900104,
-0xaf92011c, 0x8f420330, 0x24420001, 0xaf420330,
-0x8f420330, 0x10000015, 0x0, 0x3c040001,
-0x24847ba8, 0x240202a9, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e77bb0, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x8fbf0024,
-0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x3e00008,
-0x27bd0028, 0x27bdffd8, 0x3c040001, 0x24847be4,
-0x3c050001, 0xafbf0024, 0xafb20020, 0xafb1001c,
-0xafb00018, 0x8f900124, 0x8f9100a0, 0x8f92011c,
-0x34a52600, 0x8f820120, 0x2403021, 0x2203821,
-0xafa20010, 0xc002d3b, 0xafb00014, 0x8e020008,
-0xafa20010, 0x8e02000c, 0x3c040001, 0x24847bf0,
-0xafa20014, 0x8e060000, 0x8e070004, 0x3c050001,
-0xc002d3b, 0x34a52610, 0x8e020018, 0xafa20010,
-0x8e02001c, 0x3c040001, 0x24847bfc, 0xafa20014,
-0x8e060010, 0x8e070014, 0x3c050001, 0xc002d3b,
-0x34a52620, 0x3c027f00, 0x2221024, 0x3c030800,
-0x54430016, 0x3c030200, 0x8f8200ac, 0x3042ffff,
-0x14400012, 0x3c030200, 0x3c040001, 0x24847c08,
-0x3c050001, 0x34a5f030, 0x3021, 0x3821,
-0x36420002, 0xaf82011c, 0x36220001, 0xaf8200a0,
-0xaf900124, 0xaf92011c, 0xafa00010, 0xc002d3b,
-0xafa00014, 0x10000025, 0x0, 0x2c31024,
-0x1040000e, 0x2231024, 0x1040000c, 0x36420002,
-0xaf82011c, 0x36220001, 0xaf8200a0, 0xaf900124,
-0xaf92011c, 0x8f42032c, 0x24420001, 0xaf42032c,
-0x8f42032c, 0x10000015, 0x0, 0x3c040001,
-0x24847ba8, 0x240202e2, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e77bb0, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x8fbf0024,
-0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x3e00008,
-0x27bd0028, 0x6021, 0x5021, 0x3021,
-0x2821, 0x6821, 0x4821, 0x7821,
-0x7021, 0x8f880124, 0x8f870104, 0x8f8b011c,
-0x1580002e, 0x0, 0x11a00014, 0x31620800,
-0x8f820120, 0x10460029, 0x0, 0x3c040002,
-0x8c8487a0, 0x8cc20000, 0x8cc30004, 0xac820000,
-0xac830004, 0x8cc20008, 0xac820008, 0x94c2000e,
-0xa482000e, 0x8cc20010, 0x240c0001, 0xac820010,
-0x8cc20014, 0x10000012, 0x24c60020, 0x10400017,
-0x0, 0x3c040002, 0x8c8487a0, 0x8d020000,
-0x8d030004, 0xac820000, 0xac830004, 0x8d020008,
-0xac820008, 0x9502000e, 0xa482000e, 0x8d020010,
-0x25060020, 0xac820010, 0x8d020014, 0x240c0001,
-0xc01821, 0xac820014, 0x27624fe0, 0x43102b,
-0x54400001, 0x27634800, 0x603021, 0x1540002f,
-0x31620100, 0x11200014, 0x31628000, 0x8f820100,
-0x1045002a, 0x31620100, 0x3c040002, 0x8c84879c,
-0x8ca20000, 0x8ca30004, 0xac820000, 0xac830004,
-0x8ca20008, 0xac820008, 0x94a2000e, 0xa482000e,
-0x8ca20010, 0x240a0001, 0xac820010, 0x8ca20014,
-0x10000012, 0x24a50020, 0x10400018, 0x31620100,
-0x3c040002, 0x8c84879c, 0x8ce20000, 0x8ce30004,
-0xac820000, 0xac830004, 0x8ce20008, 0xac820008,
-0x94e2000e, 0xa482000e, 0x8ce20010, 0x24e50020,
-0xac820010, 0x8ce20014, 0x240a0001, 0xa01821,
-0xac820014, 0x276247e0, 0x43102b, 0x54400001,
-0x27634000, 0x602821, 0x31620100, 0x5440001d,
-0x31621000, 0x11a00009, 0x31a20800, 0x10400004,
-0x25020020, 0x8f8200a8, 0xa5e20000, 0x25020020,
-0xaf820124, 0x8f880124, 0x6821, 0x11800011,
-0x31621000, 0x3c040002, 0x8c8487a0, 0x8c820000,
-0x8c830004, 0xaf820080, 0xaf830084, 0x8c820008,
-0xaf8200a4, 0x9482000e, 0xaf8200ac, 0x8c820010,
-0x6021, 0xaf8200a0, 0x8c8d0010, 0x8c8f0014,
-0x31621000, 0x1440ff81, 0x0, 0x1120000f,
-0x31220800, 0x10400004, 0x3c020002, 0x8f8200b8,
-0xa5c20000, 0x3c020002, 0x1221024, 0x10400004,
-0x24e20020, 0x8f8200b4, 0xaf8200d4, 0x24e20020,
-0xaf820104, 0x8f870104, 0x4821, 0x1140ff6f,
-0x0, 0x3c040002, 0x8c84879c, 0x8c820000,
-0x8c830004, 0xaf820090, 0xaf830094, 0x8c820008,
-0xaf8200b4, 0x9482000e, 0xaf82009c, 0x8c820010,
-0x5021, 0xaf8200b0, 0x8c890010, 0x8c8e0014,
-0x1000ff5e, 0x0, 0x3e00008, 0x0,
-0x6021, 0x5821, 0x3021, 0x2821,
-0x6821, 0x5021, 0x7821, 0x7021,
-0x8f880124, 0x8f870104, 0x3c180100, 0x8f89011c,
-0x1580002e, 0x0, 0x11a00014, 0x31220800,
-0x8f820120, 0x10460029, 0x0, 0x3c040002,
-0x8c8487a0, 0x8cc20000, 0x8cc30004, 0xac820000,
-0xac830004, 0x8cc20008, 0xac820008, 0x94c2000e,
-0xa482000e, 0x8cc20010, 0x240c0001, 0xac820010,
-0x8cc20014, 0x10000012, 0x24c60020, 0x10400017,
-0x0, 0x3c040002, 0x8c8487a0, 0x8d020000,
-0x8d030004, 0xac820000, 0xac830004, 0x8d020008,
-0xac820008, 0x9502000e, 0xa482000e, 0x8d020010,
-0x25060020, 0xac820010, 0x8d020014, 0x240c0001,
-0xc01821, 0xac820014, 0x27624fe0, 0x43102b,
-0x54400001, 0x27634800, 0x603021, 0x1560002f,
-0x31220100, 0x11400014, 0x31228000, 0x8f820100,
-0x1045002a, 0x31220100, 0x3c040002, 0x8c84879c,
-0x8ca20000, 0x8ca30004, 0xac820000, 0xac830004,
-0x8ca20008, 0xac820008, 0x94a2000e, 0xa482000e,
-0x8ca20010, 0x240b0001, 0xac820010, 0x8ca20014,
-0x10000012, 0x24a50020, 0x10400018, 0x31220100,
-0x3c040002, 0x8c84879c, 0x8ce20000, 0x8ce30004,
-0xac820000, 0xac830004, 0x8ce20008, 0xac820008,
-0x94e2000e, 0xa482000e, 0x8ce20010, 0x24e50020,
-0xac820010, 0x8ce20014, 0x240b0001, 0xa01821,
-0xac820014, 0x276247e0, 0x43102b, 0x54400001,
-0x27634000, 0x602821, 0x31220100, 0x5440001d,
-0x31221000, 0x11a00009, 0x31a20800, 0x10400004,
-0x25020020, 0x8f8200a8, 0xa5e20000, 0x25020020,
-0xaf820124, 0x8f880124, 0x6821, 0x11800011,
-0x31221000, 0x3c040002, 0x8c8487a0, 0x8c820000,
-0x8c830004, 0xaf820080, 0xaf830084, 0x8c820008,
-0xaf8200a4, 0x9482000e, 0xaf8200ac, 0x8c820010,
-0x6021, 0xaf8200a0, 0x8c8d0010, 0x8c8f0014,
-0x31221000, 0x14400022, 0x0, 0x1140000f,
-0x31420800, 0x10400004, 0x3c020002, 0x8f8200b8,
-0xa5c20000, 0x3c020002, 0x1421024, 0x10400004,
-0x24e20020, 0x8f8200b4, 0xaf8200d4, 0x24e20020,
-0xaf820104, 0x8f870104, 0x5021, 0x11600010,
-0x0, 0x3c040002, 0x8c84879c, 0x8c820000,
-0x8c830004, 0xaf820090, 0xaf830094, 0x8c820008,
-0xaf8200b4, 0x9482000e, 0xaf82009c, 0x8c820010,
-0x5821, 0xaf8200b0, 0x8c8a0010, 0x8c8e0014,
-0x8f820070, 0x3c031000, 0x431024, 0x1040ff5b,
-0x0, 0x8f820054, 0x24420005, 0xaf820078,
-0x8c040234, 0x10800017, 0x1821, 0x3c020001,
-0x571021, 0x8c4240e8, 0x24420005, 0x3c010001,
-0x370821, 0xac2240e8, 0x3c020001, 0x571021,
-0x8c4240e8, 0x44102b, 0x1440000a, 0x24020001,
-0x3c030080, 0x3c010001, 0x370821, 0xac2040e8,
-0x3c010001, 0x370821, 0xa02240f0, 0x1000000c,
-0x0, 0x3c020001, 0x571021, 0x904240f0,
-0x14400006, 0x3c020080, 0x3c020001, 0x571021,
-0x904240f1, 0x10400002, 0x3c020080, 0x621825,
-0x8c040230, 0x10800013, 0x0, 0x3c020001,
-0x571021, 0x8c4240ec, 0x24420005, 0x3c010001,
-0x370821, 0xac2240ec, 0x3c020001, 0x571021,
-0x8c4240ec, 0x44102b, 0x14400006, 0x0,
-0x3c010001, 0x370821, 0xac2040ec, 0x10000006,
-0x781825, 0x3c020001, 0x571021, 0x904240f2,
-0x54400001, 0x781825, 0x1060ff18, 0x0,
-0x8f420000, 0x10400007, 0x0, 0xaf80004c,
-0x8f82004c, 0x1040fffd, 0x0, 0x10000005,
-0x0, 0xaf800048, 0x8f820048, 0x1040fffd,
-0x0, 0x8f820060, 0x431025, 0xaf820060,
-0x8f420000, 0x10400004, 0x0, 0xaf80004c,
-0x1000ff02, 0x0, 0xaf800048, 0x1000feff,
-0x0, 0x3e00008, 0x0, 0x3c020002,
-0x8c428608, 0x27bdffe8, 0xafbf0014, 0x14400012,
-0xafb00010, 0x3c100002, 0x26108850, 0x2002021,
-0xc002da8, 0x24052000, 0x26021fe0, 0x3c010002,
-0xac2287a8, 0x3c010002, 0xac2287a4, 0xac020250,
-0x24022000, 0xac100254, 0xac020258, 0x24020001,
-0x3c010002, 0xac228608, 0x8fbf0014, 0x8fb00010,
-0x3e00008, 0x27bd0018, 0x3c090002, 0x8d2987a8,
-0x8c820000, 0x8fa30010, 0x8fa80014, 0xad220000,
-0x8c820004, 0xad250008, 0xad220004, 0x8f820054,
-0xad260010, 0xad270014, 0xad230018, 0xad28001c,
-0xad22000c, 0x2529ffe0, 0x3c020002, 0x24428850,
-0x122102b, 0x10400003, 0x0, 0x3c090002,
-0x8d2987a4, 0x3c020002, 0x8c4285fc, 0xad220000,
-0x3c020002, 0x8c4285fc, 0x3c010002, 0xac2987a8,
-0xad220004, 0xac090250, 0x3e00008, 0x0,
-0x27bdffd0, 0xafb00010, 0x3c100002, 0x8e1087a8,
-0x3c020002, 0x8c4285fc, 0xafb10014, 0x808821,
-0xafbe0024, 0x8fbe0040, 0x8fa40048, 0xafb20018,
-0xa09021, 0xafbf0028, 0xafb50020, 0xafb3001c,
-0xae020000, 0x3c020002, 0x8c4285fc, 0xc09821,
-0xe0a821, 0x10800006, 0xae020004, 0x26050008,
-0xc002db3, 0x24060018, 0x10000005, 0x2610ffe0,
-0x26040008, 0xc002da8, 0x24050018, 0x2610ffe0,
-0x3c030002, 0x24638850, 0x203102b, 0x10400003,
-0x0, 0x3c100002, 0x8e1087a4, 0x8e220000,
-0xae020000, 0x8e220004, 0xae120008, 0xae020004,
-0x8f820054, 0xae130010, 0xae150014, 0xae1e0018,
-0x8fa80044, 0xae08001c, 0xae02000c, 0x2610ffe0,
-0x203102b, 0x10400003, 0x0, 0x3c100002,
-0x8e1087a4, 0x3c020002, 0x8c4285fc, 0xae020000,
-0x3c020002, 0x8c4285fc, 0x3c010002, 0xac3087a8,
-0xae020004, 0xac100250, 0x8fbf0028, 0x8fbe0024,
-0x8fb50020, 0x8fb3001c, 0x8fb20018, 0x8fb10014,
-0x8fb00010, 0x3e00008, 0x27bd0030, 0x851821,
-0x83102b, 0x10400006, 0x0, 0xac800000,
-0x24840004, 0x83102b, 0x5440fffd, 0xac800000,
-0x3e00008, 0x0, 0xa61821, 0xa3102b,
-0x10400007, 0x0, 0x8c820000, 0xaca20000,
-0x24a50004, 0xa3102b, 0x1440fffb, 0x24840004,
-0x3e00008, 0x0, 0x861821, 0x83102b,
-0x10400007, 0x0, 0x8ca20000, 0xac820000,
-0x24840004, 0x83102b, 0x1440fffb, 0x24a50004,
-0x3e00008, 0x0, 0x63080, 0x861821,
-0x83102b, 0x10400006, 0x0, 0xac850000,
-0x24840004, 0x83102b, 0x5440fffd, 0xac850000,
-0x3e00008, 0x0, 0x26e50028, 0xa03021,
-0x274301c0, 0x8f4d0358, 0x8f47035c, 0x8f480360,
-0x8f490364, 0x8f4a0368, 0x8f4b0204, 0x8f4c0200,
-0x24640400, 0x64102b, 0x10400008, 0x3c0208ff,
-0x8cc20000, 0xac620000, 0x24630004, 0x64102b,
-0x1440fffb, 0x24c60004, 0x3c0208ff, 0x3442ffff,
-0x3c03c0ff, 0xaf4d0358, 0xaf47035c, 0xaf480360,
-0xaf490364, 0xaf4a0368, 0xaf4b0204, 0xaf4c0200,
-0x8f840220, 0x3463ffff, 0x8f860200, 0x821024,
-0x34420004, 0xc31824, 0x34630004, 0xaf820220,
-0xaf830200, 0x8ca20214, 0xac020084, 0x8ca20218,
-0xac020088, 0x8ca2021c, 0xac02008c, 0x8ca20220,
-0xac020090, 0x8ca20224, 0xac020094, 0x8ca20228,
-0xac020098, 0x8ca2022c, 0xac02009c, 0x8ca20230,
-0xac0200a0, 0x8ca20234, 0xac0200a4, 0x8ca20238,
-0xac0200a8, 0x8ca2023c, 0xac0200ac, 0x8ca20240,
-0xac0200b0, 0x8ca20244, 0xac0200b4, 0x8ca20248,
-0xac0200b8, 0x8ca2024c, 0xac0200bc, 0x8ca2001c,
-0xac020080, 0x8ca20018, 0xac0200c0, 0x8ca20020,
-0xac0200cc, 0x8ca20024, 0xac0200d0, 0x8ca201d0,
-0xac0200e0, 0x8ca201d4, 0xac0200e4, 0x8ca201d8,
-0xac0200e8, 0x8ca201dc, 0xac0200ec, 0x8ca201e0,
-0xac0200f0, 0x8ca20098, 0x8ca3009c, 0xac0300fc,
-0x8ca200a8, 0x8ca300ac, 0xac0300f4, 0x8ca200a0,
-0x8ca300a4, 0x30840004, 0xac0300f8, 0x14800007,
-0x30c20004, 0x8f820220, 0x3c0308ff, 0x3463fffb,
-0x431024, 0xaf820220, 0x30c20004, 0x14400006,
-0x0, 0x8f820200, 0x3c03c0ff, 0x3463fffb,
-0x431024, 0xaf820200, 0x8f4202dc, 0xa34005c5,
-0x24420001, 0xaf4202dc, 0x8f4202dc, 0x3e00008,
-0x0, 0x27bdffd0, 0xafbf0028, 0xafb10024,
-0xafb00020, 0x8f430024, 0x8f420020, 0x1062004e,
-0x0, 0x8f430020, 0x8f420024, 0x628823,
-0x6210003, 0x0, 0x8f420040, 0x2228821,
-0x8f430030, 0x8f420024, 0x43102b, 0x14400005,
-0x0, 0x8f430040, 0x8f420024, 0x10000005,
-0x628023, 0x8f420030, 0x8f430024, 0x431023,
-0x2450ffff, 0x16000016, 0x2006821, 0x3c040001,
-0x24847e74, 0x240202aa, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e77e84, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x2006821,
-0x22d102a, 0x54400001, 0x2206821, 0x8f4b0024,
-0x8f4a0040, 0x8f490024, 0x8f440180, 0x8f450184,
-0x8f460024, 0x8f4c001c, 0xd3900, 0x24080001,
-0xafa80010, 0x94900, 0x1201821, 0x16d5821,
-0x254affff, 0x16a8024, 0xafb00014, 0x8f480014,
-0x1021, 0xa32821, 0xa3482b, 0x822021,
-0x892021, 0xafa80018, 0x8f420108, 0x63100,
-0x40f809, 0x1863021, 0x54400001, 0xaf500024,
-0x8f430024, 0x8f420020, 0x14620019, 0x0,
-0x8f420000, 0x10400007, 0x0, 0xaf80004c,
-0x8f82004c, 0x1040fffd, 0x0, 0x10000005,
-0x0, 0xaf800048, 0x8f820048, 0x1040fffd,
-0x0, 0x8f820060, 0x2403ffef, 0x431024,
-0xaf820060, 0x8f420000, 0x10400004, 0x0,
-0xaf80004c, 0x10000002, 0x0, 0xaf800048,
-0x8fbf0028, 0x8fb10024, 0x8fb00020, 0x3e00008,
-0x27bd0030, 0x3e00008, 0x0, 0x27bdffc0,
-0x32c20020, 0xafbf0038, 0xafb30034, 0xafb20030,
-0xafb1002c, 0x10400004, 0xafb00028, 0x8f530028,
-0x10000002, 0x0, 0x8f530020, 0x8f420030,
-0x10530102, 0x21100, 0x8f43001c, 0x628021,
-0x8e040000, 0x8e050004, 0x96120008, 0x8f420090,
-0x9611000a, 0x3246ffff, 0x46102a, 0x10400018,
-0x0, 0x8f8200d8, 0x8f430098, 0x431023,
-0x2442dcbe, 0xaf420090, 0x8f420090, 0x2842dcbf,
-0x10400005, 0x0, 0x8f420090, 0x8f430144,
-0x431021, 0xaf420090, 0x8f420090, 0x46102a,
-0x10400007, 0x0, 0x8f420348, 0x24420001,
-0xaf420348, 0x8f420348, 0x100000f8, 0x0,
-0x8f8200fc, 0x14400007, 0x0, 0x8f420344,
-0x24420001, 0xaf420344, 0x8f420344, 0x100000ef,
-0x0, 0x934205c2, 0x1040000b, 0x32c20008,
-0x10400008, 0x32220200, 0x10400006, 0x3c034000,
-0x9602000e, 0xaf4300ac, 0x21400, 0x10000002,
-0xaf4200b0, 0xaf4000ac, 0x32220004, 0x10400094,
-0x32220800, 0x10400003, 0x3247ffff, 0x10000002,
-0x24020020, 0x24020004, 0xafa20010, 0x8f420030,
-0xafa20014, 0x8f420010, 0x3c030002, 0x431025,
-0xafa20018, 0x8f460098, 0x8f420108, 0x40f809,
-0x0, 0x104000cd, 0x0, 0x8f42009c,
-0x8f430094, 0x2421021, 0xaf42009c, 0xae03000c,
-0x8f4200ac, 0x10400008, 0x3c034000, 0x8f420094,
-0x431025, 0xafa20020, 0x8f42009c, 0x8f4300b0,
-0x10000004, 0x431025, 0x8f420094, 0xafa20020,
-0x8f42009c, 0xafa20024, 0x8f9000fc, 0x16000014,
-0x240200e1, 0x3c040001, 0x24847e74, 0xafa20010,
-0xafa00014, 0x8f860144, 0x3c070001, 0x24e77e7c,
-0xc002d3b, 0x3405dead, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f820220, 0x34420004, 0xaf820220,
-0x8f820140, 0x3c030001, 0x431025, 0xaf820140,
-0x8fa20020, 0x8fa30024, 0xae020000, 0xae030004,
-0x26020008, 0xaf8200f0, 0x8f42009c, 0x8f440270,
-0x8f450274, 0x401821, 0x1021, 0xa32821,
-0xa3302b, 0x822021, 0x862021, 0x32230060,
-0x24020040, 0xaf440270, 0xaf450274, 0x10620017,
-0x2c620041, 0x10400005, 0x24020020, 0x10620008,
-0x24020001, 0x10000026, 0x0, 0x24020060,
-0x10620019, 0x24020001, 0x10000021, 0x0,
-0x8f420278, 0x8f43027c, 0x24630001, 0x2c640001,
-0x441021, 0xaf420278, 0xaf43027c, 0x8f420278,
-0x8f43027c, 0x10000016, 0x24020001, 0x8f420280,
-0x8f430284, 0x24630001, 0x2c640001, 0x441021,
-0xaf420280, 0xaf430284, 0x8f420280, 0x8f430284,
-0x1000000b, 0x24020001, 0x8f420288, 0x8f43028c,
-0x24630001, 0x2c640001, 0x441021, 0xaf420288,
-0xaf43028c, 0x8f420288, 0x8f43028c, 0x24020001,
-0xa34205c2, 0x8f420098, 0x3244ffff, 0x2406fff8,
-0x8f45013c, 0x441021, 0x24420007, 0x461024,
-0x24840007, 0xaf420094, 0x8f420090, 0x8f430094,
-0x862024, 0x441023, 0x65182b, 0x14600005,
-0xaf420090, 0x8f420094, 0x8f430144, 0x431023,
-0xaf420094, 0x8f420094, 0x10000023, 0xaf40009c,
-0x3247ffff, 0x50e00022, 0x32c20020, 0x14400002,
-0x24020010, 0x24020002, 0xafa20010, 0x8f420030,
-0xafa20014, 0x8f420010, 0xafa20018, 0x8f460098,
-0x8f420108, 0x40f809, 0x0, 0x1040003b,
-0x3245ffff, 0x8f420098, 0x8f430090, 0x8f46013c,
-0x451021, 0xaf420098, 0x8f42009c, 0x8f440098,
-0xa34005c2, 0x651823, 0xaf430090, 0x451021,
-0x86202b, 0x14800005, 0xaf42009c, 0x8f420098,
-0x8f430144, 0x431023, 0xaf420098, 0x32c20020,
-0x10400005, 0x0, 0x8f420358, 0x2442ffff,
-0xaf420358, 0x8f420358, 0x8f420030, 0x8f430040,
-0x24420001, 0x2463ffff, 0x431024, 0xaf420030,
-0x8f420030, 0x14530019, 0x0, 0x8f420000,
-0x10400007, 0x0, 0xaf80004c, 0x8f82004c,
-0x1040fffd, 0x0, 0x10000005, 0x0,
-0xaf800048, 0x8f820048, 0x1040fffd, 0x0,
-0x8f820060, 0x2403fff7, 0x431024, 0xaf820060,
-0x8f420000, 0x10400004, 0x0, 0xaf80004c,
-0x10000002, 0x0, 0xaf800048, 0x8fbf0038,
-0x8fb30034, 0x8fb20030, 0x8fb1002c, 0x8fb00028,
-0x3e00008, 0x27bd0040, 0x3e00008, 0x0,
-0x27bdffd0, 0x32c20020, 0xafbf002c, 0xafb20028,
-0xafb10024, 0x10400004, 0xafb00020, 0x8f520028,
-0x10000002, 0x0, 0x8f520020, 0x8f420030,
-0x105200b7, 0x21100, 0x8f43001c, 0x628021,
-0x8e040000, 0x8e050004, 0x96110008, 0x8f420090,
-0x9607000a, 0x3226ffff, 0x46102a, 0x10400018,
-0x0, 0x8f8200d8, 0x8f430098, 0x431023,
-0x2442dc46, 0xaf420090, 0x8f420090, 0x2842dc47,
-0x10400005, 0x0, 0x8f420090, 0x8f430144,
-0x431021, 0xaf420090, 0x8f420090, 0x46102a,
-0x10400007, 0x0, 0x8f420348, 0x24420001,
-0xaf420348, 0x8f420348, 0x100000ad, 0x0,
-0x8f8600fc, 0x10c0000c, 0x0, 0x8f8200f4,
-0x2403fff8, 0x431024, 0x461023, 0x218c3,
-0x58600001, 0x24630100, 0x8f42008c, 0x43102b,
-0x14400007, 0x712c2, 0x8f420344, 0x24420001,
-0xaf420344, 0x8f420344, 0x10000099, 0x0,
-0x934305c2, 0x1060000f, 0x30460001, 0x8f420010,
-0x34480400, 0x32c20008, 0x10400008, 0x30e20200,
-0x10400006, 0x3c034000, 0x9602000e, 0xaf4300ac,
-0x21400, 0x10000004, 0xaf4200b0, 0x10000002,
-0xaf4000ac, 0x8f480010, 0x30e20004, 0x10400045,
-0x3227ffff, 0x8f4900ac, 0x11200005, 0x30c200ff,
-0x14400006, 0x24020040, 0x10000004, 0x24020008,
-0x14400002, 0x24020020, 0x24020004, 0xafa20010,
-0x8f430030, 0x11200004, 0xafa30014, 0x8f4200b0,
-0x621025, 0xafa20014, 0x3c020002, 0x1021025,
-0xafa20018, 0x8f460098, 0x8f420108, 0x40f809,
-0x0, 0x1040006a, 0x3224ffff, 0x8f42008c,
-0x8f430094, 0x24420001, 0xaf42008c, 0x24020001,
-0xae03000c, 0xa34205c2, 0x8f420098, 0x2406fff8,
-0x8f45013c, 0x441021, 0x24420007, 0x461024,
-0x24840007, 0xaf420094, 0x8f420090, 0x8f430094,
-0x862024, 0x441023, 0x65182b, 0x14600005,
-0xaf420090, 0x8f420094, 0x8f430144, 0x431023,
-0xaf420094, 0x8f430094, 0x8f420140, 0x43102b,
-0x10400009, 0x0, 0x8f43013c, 0x8f440094,
-0x8f420090, 0x8f450138, 0x641823, 0x431023,
-0xaf420090, 0xaf450094, 0x8f420094, 0x1000001f,
-0xaf420098, 0x10e0001d, 0x30c200ff, 0x14400002,
-0x24020010, 0x24020002, 0xafa20010, 0x8f420030,
-0xafa80018, 0xafa20014, 0x8f460098, 0x8f420108,
-0x40f809, 0x0, 0x10400031, 0x3225ffff,
-0x8f420098, 0x8f44013c, 0x451021, 0xaf420098,
-0x8f420090, 0x8f430098, 0xa34005c2, 0x451023,
-0x64182b, 0x14600005, 0xaf420090, 0x8f420098,
-0x8f430144, 0x431023, 0xaf420098, 0x8f420030,
-0x8f430040, 0x24420001, 0x2463ffff, 0x431024,
-0xaf420030, 0x8f420030, 0x14520019, 0x0,
-0x8f420000, 0x10400007, 0x0, 0xaf80004c,
-0x8f82004c, 0x1040fffd, 0x0, 0x10000005,
-0x0, 0xaf800048, 0x8f820048, 0x1040fffd,
-0x0, 0x8f820060, 0x2403fff7, 0x431024,
-0xaf820060, 0x8f420000, 0x10400004, 0x0,
-0xaf80004c, 0x10000002, 0x0, 0xaf800048,
-0x8fbf002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
-0x3e00008, 0x27bd0030, 0x3e00008, 0x0,
-0x27bdffd8, 0xafbf0024, 0xafb00020, 0x8f4300f0,
-0x8f4200ec, 0x8f900108, 0x14620017, 0x3c020001,
-0x3c040001, 0x24847e74, 0x240204ea, 0xafa20010,
-0xafa00014, 0x8f860144, 0x3c070001, 0x24e77e84,
-0xc002d3b, 0x3405dead, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f820220, 0x34420004, 0xaf820220,
-0x8f820140, 0x3c030001, 0x431025, 0xaf820140,
-0x3c020001, 0x8f4300f0, 0x34422ec0, 0x2e21021,
-0x54620004, 0x24620008, 0x3c020001, 0x34422cc0,
-0x2e21021, 0x401821, 0xaf4300f0, 0xac600000,
-0x8f4200ec, 0x8c660004, 0x14620005, 0x3c020001,
-0x26020020, 0xaf820108, 0x1000000f, 0x0,
-0x8f4300f0, 0x34422ec0, 0x2e21021, 0x54620004,
-0x24620008, 0x3c020001, 0x34422cc0, 0x2e21021,
-0x401821, 0x8c620004, 0x21140, 0x2021021,
-0xaf820108, 0xac600000, 0x8e050018, 0x30a20036,
-0x1040006d, 0x30a20001, 0x8e02001c, 0x8f430040,
-0x8f440034, 0x24420001, 0x2463ffff, 0x431024,
-0x862021, 0xaf42002c, 0x30a20030, 0x14400006,
-0xaf440034, 0x8f420034, 0x8c03023c, 0x43102b,
-0x144000cf, 0x0, 0x32c20010, 0x10400028,
-0x24070008, 0x8f440170, 0x8f450174, 0x8f43002c,
-0x8f48000c, 0x8f860120, 0x24020080, 0xafa20010,
-0xafa30014, 0xafa80018, 0x8f42010c, 0x40f809,
-0x24c6001c, 0x14400011, 0x24020001, 0x3c010001,
-0x370821, 0xa02240f1, 0x8f820124, 0xafa20010,
-0x8f820128, 0x3c040001, 0x24847e64, 0xafa20014,
-0x8f46002c, 0x8f870120, 0x3c050009, 0xc002d3b,
-0x34a51100, 0x10000036, 0x0, 0x8f420300,
-0x8f43002c, 0x24420001, 0xaf420300, 0x8f420300,
-0x24020001, 0xa34205c1, 0x10000026, 0xaf430038,
-0x8f440170, 0x8f450174, 0x8f43002c, 0x8f48000c,
-0x8f860120, 0x24020020, 0xafa20010, 0xafa30014,
-0xafa80018, 0x8f42010c, 0x40f809, 0x24c6001c,
-0x14400011, 0x24020001, 0x3c010001, 0x370821,
-0xa02240f0, 0x8f820124, 0xafa20010, 0x8f820128,
-0x3c040001, 0x24847e58, 0xafa20014, 0x8f46002c,
-0x8f870120, 0x3c050009, 0xc002d3b, 0x34a50900,
-0x1000000f, 0x0, 0x8f420300, 0x24420001,
-0xaf420300, 0x8f420300, 0x8f42002c, 0xa34005c1,
-0xaf420038, 0x3c010001, 0x370821, 0xa02040f1,
-0x3c010001, 0x370821, 0xa02040f0, 0xaf400034,
-0x8f420314, 0x24420001, 0xaf420314, 0x8f420314,
-0x10000073, 0x0, 0x10400025, 0x30a27000,
-0x8e05001c, 0x8f420028, 0xa22023, 0x4810003,
-0x0, 0x8f420040, 0x822021, 0x8f420358,
-0x8f430000, 0xaf450028, 0x441021, 0xaf420358,
-0x10600007, 0x0, 0xaf80004c, 0x8f82004c,
-0x1040fffd, 0x0, 0x10000005, 0x0,
-0xaf800048, 0x8f820048, 0x1040fffd, 0x0,
-0x8f820060, 0x34420008, 0xaf820060, 0x8f420000,
-0x10400004, 0x0, 0xaf80004c, 0x10000050,
-0x0, 0xaf800048, 0x1000004d, 0x0,
-0x1040002f, 0x30a21000, 0x1040000c, 0x30a24000,
-0x8e03001c, 0x8f420050, 0x622023, 0x4820001,
-0x24840200, 0x8f42035c, 0x441021, 0xaf42035c,
-0x8f420368, 0x1000001a, 0xaf430050, 0x1040000c,
-0x32c28000, 0x8e03001c, 0x8f420070, 0x622023,
-0x4820001, 0x24840400, 0x8f420364, 0x441021,
-0xaf420364, 0x8f420368, 0x1000000d, 0xaf430070,
-0x1040000e, 0x3c020800, 0x8e03001c, 0x8f420060,
-0x622023, 0x4820001, 0x24840100, 0x8f420360,
-0x441021, 0xaf420360, 0x8f420368, 0xaf430060,
-0x441021, 0xaf420368, 0x3c020800, 0x2c21024,
-0x5040001f, 0x36940040, 0x1000001d, 0x0,
-0x30a20100, 0x10400005, 0x30a20080, 0xc002dd7,
-0x0, 0x10000016, 0x0, 0x14400014,
-0x240205dd, 0x3c040001, 0x24847e74, 0xafa20010,
-0xafa00014, 0x8f860144, 0x3c070001, 0x24e77e84,
-0xc002d3b, 0x3405dead, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f820220, 0x34420004, 0xaf820220,
-0x8f820140, 0x3c030001, 0x431025, 0xaf820140,
-0x8fbf0024, 0x8fb00020, 0x3e00008, 0x27bd0028,
-0x3e00008, 0x0, 0x27bdff98, 0xafbf0060,
-0xafbe005c, 0xafb50058, 0xafb30054, 0xafb20050,
-0xafb1004c, 0xafb00048, 0x8f920108, 0x8f820104,
-0x16420016, 0x26420020, 0x3c040001, 0x24847e74,
-0x240205f8, 0xafa20010, 0xafa00014, 0x8f860144,
-0x3c070001, 0x24e77e84, 0xc002d3b, 0x3405dead,
-0x8f82011c, 0x34420002, 0xaf82011c, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820140, 0x3c030001,
-0x431025, 0xaf820140, 0x26420020, 0xaf820108,
-0x8e530018, 0xa3a0003f, 0x32620024, 0x1040022c,
-0xafa00034, 0x8e50001c, 0x8f42001c, 0x101900,
-0x431021, 0x8c51000c, 0x8f430140, 0x965e0016,
-0x9455000a, 0x71182b, 0x10600014, 0x24020634,
-0x3c040001, 0x24847e74, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e77e84, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x9624000c,
-0x2c8305dd, 0x38828870, 0x2c420001, 0x621825,
-0x10600015, 0x2821, 0x32c20040, 0x10400015,
-0x24020800, 0x96230014, 0x14620012, 0x3402aaaa,
-0x9623000e, 0x14620007, 0x2021, 0x96230010,
-0x24020300, 0x14620004, 0x801021, 0x96220012,
-0x2c440001, 0x801021, 0x54400006, 0x24050016,
-0x10000004, 0x0, 0x24020800, 0x50820001,
-0x2405000e, 0x934205c3, 0x14400008, 0x5021,
-0x240a0001, 0x32a20180, 0xaf4500a8, 0xaf5100a0,
-0x10400002, 0xaf5000a4, 0xa34a05c3, 0x10a00086,
-0x2253821, 0x90e20000, 0x3021, 0x3042000f,
-0x24880, 0x32c20002, 0x10400012, 0xe91821,
-0x32a20002, 0x10400010, 0x32c20001, 0xe02021,
-0x94820000, 0x24840002, 0xc23021, 0x83102b,
-0x1440fffb, 0x30c2ffff, 0x61c02, 0x623021,
-0x61c02, 0x30c2ffff, 0x623021, 0x61027,
-0xa4e2000a, 0x32c20001, 0x1040006b, 0x32a20001,
-0x10400069, 0x0, 0x8f4200a8, 0x10400066,
-0x0, 0x8f4200a0, 0x8f4300a8, 0x431021,
-0x904b0009, 0x316800ff, 0x39030006, 0x3182b,
-0x39020011, 0x2102b, 0x621824, 0x1060000d,
-0x3c050006, 0x3c040001, 0x24847e8c, 0x8f4200a4,
-0x34a54600, 0xafa20010, 0x8f4200a0, 0x2003021,
-0x1003821, 0xc002d3b, 0xafa20014, 0x1000004e,
-0x0, 0x32c20004, 0x14400013, 0x2821,
-0x314200ff, 0x14400004, 0x0, 0x94e20002,
-0x1000000d, 0x492823, 0x94e5000c, 0x94e2000e,
-0x94e30010, 0xa22821, 0xa32821, 0x94e30012,
-0x90e40009, 0x94e20002, 0xa32821, 0xa42821,
-0x491023, 0xa22821, 0x2202021, 0x94820000,
-0x24840002, 0xc23021, 0x87102b, 0x1440fffb,
-0x61c02, 0x30c2ffff, 0x623021, 0x61c02,
-0x30c2ffff, 0x623021, 0x3c52821, 0x51c02,
-0x30a2ffff, 0x622821, 0x51c02, 0x30a2ffff,
-0x622821, 0xa62823, 0x51402, 0xa22821,
-0x30a5ffff, 0x50a00001, 0x3405ffff, 0x314200ff,
-0x14400008, 0x316300ff, 0x8f4300a0, 0x8f4200a8,
-0x623821, 0x90e20000, 0x3042000f, 0x24880,
-0x316300ff, 0x24020006, 0x14620003, 0xe91021,
-0x10000002, 0x24440010, 0x24440006, 0x314200ff,
-0x14400006, 0x0, 0x94820000, 0xa22821,
-0x51c02, 0x30a2ffff, 0x622821, 0x934205c3,
-0x10400003, 0x32a20100, 0x50400003, 0xa4850000,
-0x52827, 0xa4850000, 0x9642000e, 0x8f43009c,
-0x621821, 0xaf43009c, 0x93a2003f, 0x10400007,
-0x3c024000, 0x2221025, 0xafa20020, 0x8f42009c,
-0x8fac0034, 0x10000003, 0x4c1025, 0xafb10020,
-0x8f42009c, 0xafa20024, 0x32a20080, 0x10400027,
-0x32a20100, 0x8f4200b4, 0x2c420100, 0x14400014,
-0x2402076a, 0x3c040001, 0x24847e74, 0xafa20010,
-0xafa00014, 0x8f860144, 0x3c070001, 0x24e77e84,
-0xc002d3b, 0x3405dead, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f820220, 0x34420004, 0xaf820220,
-0x8f820140, 0x3c030001, 0x431025, 0xaf820140,
-0x8f4200b4, 0x24430001, 0x210c0, 0x571021,
-0xaf4300b4, 0x8fa30020, 0x8fa40024, 0x3c010001,
-0x220821, 0xac2338e8, 0x3c010001, 0x220821,
-0xac2438ec, 0x100000e7, 0x32c20020, 0x10400091,
-0x0, 0x8f4200b4, 0x2c420100, 0x14400014,
-0x24020778, 0x3c040001, 0x24847e74, 0xafa20010,
-0xafa00014, 0x8f860144, 0x3c070001, 0x24e77e84,
-0xc002d3b, 0x3405dead, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f820220, 0x34420004, 0xaf820220,
-0x8f820140, 0x3c030001, 0x431025, 0xaf820140,
-0x8f4200b4, 0x24430001, 0x210c0, 0x571021,
-0xaf4300b4, 0x8fa30020, 0x8fa40024, 0x3c010001,
-0x220821, 0xac2338e8, 0x3c010001, 0x220821,
-0xac2438ec, 0x8f4200b4, 0x10400067, 0x8821,
-0x1110c0, 0x571021, 0x3c030001, 0x621821,
-0x8c6338e8, 0x3c040001, 0x822021, 0x8c8438ec,
-0xafa30028, 0xafa4002c, 0x8f9000fc, 0x16000014,
-0x240200f4, 0x3c040001, 0x24847e74, 0xafa20010,
-0xafa00014, 0x8f860144, 0x3c070001, 0x24e77e7c,
-0xc002d3b, 0x3405dead, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f820220, 0x34420004, 0xaf820220,
-0x8f820140, 0x3c030001, 0x431025, 0xaf820140,
-0x8fa20028, 0x8fa3002c, 0xae020000, 0xae030004,
-0x26020008, 0xaf8200f0, 0x8f42008c, 0x2442ffff,
-0xaf42008c, 0x97a2002e, 0x8f440270, 0x8f450274,
-0x401821, 0x1021, 0xa32821, 0xa3302b,
-0x822021, 0x862021, 0xaf440270, 0xaf450274,
-0x8fa30028, 0x3c02001f, 0x3442ffff, 0x622024,
-0x90820000, 0x30420001, 0x1440000c, 0x2402ffff,
-0x8f420278, 0x8f43027c, 0x24630001, 0x2c640001,
-0x441021, 0xaf420278, 0xaf43027c, 0x8f420278,
-0x8f43027c, 0x1000001b, 0x0, 0x8c830000,
-0x1462000f, 0x3402ffff, 0x94830004, 0x1462000c,
-0x0, 0x8f420288, 0x8f43028c, 0x24630001,
-0x2c640001, 0x441021, 0xaf420288, 0xaf43028c,
-0x8f420288, 0x8f43028c, 0x1000000a, 0x0,
-0x8f420280, 0x8f430284, 0x24630001, 0x2c640001,
-0x441021, 0xaf420280, 0xaf430284, 0x8f420280,
-0x8f430284, 0x8f4200b4, 0x26310001, 0x222102b,
-0x1440ff9c, 0x1110c0, 0xa34005c3, 0x10000054,
-0xaf4000b4, 0x8f9000fc, 0x16000014, 0x240200f4,
-0x3c040001, 0x24847e74, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e77e7c, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x8fa20020,
-0x8fa30024, 0xae020000, 0xae030004, 0x26020008,
-0xaf8200f0, 0x8f42009c, 0x8f46008c, 0x8f440270,
-0x8f450274, 0x401821, 0x1021, 0x24c6ffff,
-0xaf46008c, 0xa32821, 0xa3302b, 0x822021,
-0x862021, 0xaf440270, 0xaf450274, 0x92220000,
-0x30420001, 0x1440000c, 0x2402ffff, 0x8f420278,
-0x8f43027c, 0x24630001, 0x2c640001, 0x441021,
-0xaf420278, 0xaf43027c, 0x8f420278, 0x8f43027c,
-0x1000001c, 0x32c20020, 0x8e230000, 0x1462000f,
-0x3402ffff, 0x96230004, 0x1462000c, 0x0,
-0x8f420288, 0x8f43028c, 0x24630001, 0x2c640001,
-0x441021, 0xaf420288, 0xaf43028c, 0x8f420288,
-0x8f43028c, 0x1000000b, 0x32c20020, 0x8f420280,
-0x8f430284, 0x24630001, 0x2c640001, 0x441021,
-0xaf420280, 0xaf430284, 0x8f420280, 0x8f430284,
-0x32c20020, 0x10400005, 0xaf40009c, 0x8f420358,
-0x2442ffff, 0xaf420358, 0x8f420358, 0x8e42001c,
-0x8f430040, 0x24420001, 0x2463ffff, 0x431024,
-0xaf42002c, 0x32620060, 0x14400008, 0x32c20010,
-0x8f420034, 0x24420001, 0xaf420034, 0x8c03023c,
-0x43102b, 0x1440011f, 0x32c20010, 0x10400018,
-0x24070008, 0x8f440170, 0x8f450174, 0x8f43002c,
-0x8f48000c, 0x8f860120, 0x24020080, 0xafa20010,
-0xafa30014, 0xafa80018, 0x8f42010c, 0x40f809,
-0x24c6001c, 0x10400047, 0x24020001, 0x8f420300,
-0x8f43002c, 0x24420001, 0xaf420300, 0x8f420300,
-0x24020001, 0xa34205c1, 0x1000007c, 0xaf430038,
-0x8f440170, 0x8f450174, 0x8f43002c, 0x8f48000c,
-0x8f860120, 0x24020020, 0xafa20010, 0xafa30014,
-0xafa80018, 0x8f42010c, 0x40f809, 0x24c6001c,
-0x10400057, 0x24020001, 0x10000065, 0x0,
-0x32620012, 0x10400076, 0x32620001, 0x9642000e,
-0x8f43009c, 0x621821, 0x32c20020, 0x10400005,
-0xaf43009c, 0x8f420358, 0x2442ffff, 0xaf420358,
-0x8f420358, 0x8e42001c, 0x8f430040, 0x24420001,
-0x2463ffff, 0x431024, 0xaf42002c, 0x32620010,
-0x14400008, 0x32c20010, 0x8f420034, 0x24420001,
-0xaf420034, 0x8c03023c, 0x43102b, 0x144000d9,
-0x32c20010, 0x10400028, 0x24070008, 0x8f440170,
-0x8f450174, 0x8f43002c, 0x8f48000c, 0x8f860120,
-0x24020080, 0xafa20010, 0xafa30014, 0xafa80018,
-0x8f42010c, 0x40f809, 0x24c6001c, 0x14400011,
-0x24020001, 0x3c010001, 0x370821, 0xa02240f1,
-0x8f820124, 0xafa20010, 0x8f820128, 0x3c040001,
-0x24847e64, 0xafa20014, 0x8f46002c, 0x8f870120,
-0x3c050009, 0xc002d3b, 0x34a51100, 0x10000036,
-0x0, 0x8f420300, 0x8f43002c, 0x24420001,
-0xaf420300, 0x8f420300, 0x24020001, 0xa34205c1,
-0x10000026, 0xaf430038, 0x8f440170, 0x8f450174,
-0x8f43002c, 0x8f48000c, 0x8f860120, 0x24020020,
-0xafa20010, 0xafa30014, 0xafa80018, 0x8f42010c,
-0x40f809, 0x24c6001c, 0x14400011, 0x24020001,
-0x3c010001, 0x370821, 0xa02240f0, 0x8f820124,
-0xafa20010, 0x8f820128, 0x3c040001, 0x24847e58,
-0xafa20014, 0x8f46002c, 0x8f870120, 0x3c050009,
-0xc002d3b, 0x34a50900, 0x1000000f, 0x0,
-0x8f420300, 0x24420001, 0xaf420300, 0x8f420300,
-0x8f42002c, 0xa34005c1, 0xaf420038, 0x3c010001,
-0x370821, 0xa02040f1, 0x3c010001, 0x370821,
-0xa02040f0, 0xaf400034, 0x8f420314, 0x24420001,
-0xaf420314, 0x8f420314, 0x1000007e, 0x0,
-0x10400025, 0x32627000, 0x8e45001c, 0x8f420028,
-0xa22023, 0x4810003, 0x0, 0x8f420040,
-0x822021, 0x8f420358, 0x8f430000, 0xaf450028,
-0x441021, 0xaf420358, 0x10600007, 0x0,
-0xaf80004c, 0x8f82004c, 0x1040fffd, 0x0,
-0x10000005, 0x0, 0xaf800048, 0x8f820048,
-0x1040fffd, 0x0, 0x8f820060, 0x34420008,
-0xaf820060, 0x8f420000, 0x10400004, 0x0,
-0xaf80004c, 0x1000005b, 0x0, 0xaf800048,
-0x10000058, 0x0, 0x1040002f, 0x32621000,
-0x1040000c, 0x32624000, 0x8e43001c, 0x8f420050,
-0x622023, 0x4820001, 0x24840200, 0x8f42035c,
-0x441021, 0xaf42035c, 0x8f420368, 0x1000001a,
-0xaf430050, 0x1040000c, 0x32c28000, 0x8e43001c,
-0x8f420070, 0x622023, 0x4820001, 0x24840400,
-0x8f420364, 0x441021, 0xaf420364, 0x8f420368,
-0x1000000d, 0xaf430070, 0x1040000e, 0x3c020800,
-0x8e43001c, 0x8f420060, 0x622023, 0x4820001,
-0x24840100, 0x8f420360, 0x441021, 0xaf420360,
-0x8f420368, 0xaf430060, 0x441021, 0xaf420368,
-0x3c020800, 0x2c21024, 0x5040002a, 0x36940040,
-0x10000028, 0x0, 0x32620048, 0x10400009,
-0x240c0001, 0x8e42001c, 0x3c03ffff, 0xa3ac003f,
-0x431824, 0x3042ffff, 0xafa30034, 0x1000fcfd,
-0xae42001c, 0x32620100, 0x10400005, 0x32620080,
-0xc002dd7, 0x0, 0x10000016, 0x0,
-0x14400014, 0x24020896, 0x3c040001, 0x24847e74,
-0xafa20010, 0xafa00014, 0x8f860144, 0x3c070001,
-0x24e77e84, 0xc002d3b, 0x3405dead, 0x8f82011c,
-0x34420002, 0xaf82011c, 0x8f820220, 0x34420004,
-0xaf820220, 0x8f820140, 0x3c030001, 0x431025,
-0xaf820140, 0x8fbf0060, 0x8fbe005c, 0x8fb50058,
-0x8fb30054, 0x8fb20050, 0x8fb1004c, 0x8fb00048,
-0x3e00008, 0x27bd0068, 0x3e00008, 0x0,
-0x8f8300e4, 0x8f8200e0, 0x2404fff8, 0x441024,
-0x621026, 0x2102b, 0x21023, 0x3e00008,
-0x621024, 0x3e00008, 0x0, 0x27bdffe0,
-0xafbf001c, 0xafb00018, 0x8f8600c4, 0x8f8400e0,
-0x8f8500e4, 0x2402fff8, 0x821824, 0x10a30009,
-0x27623ff8, 0x14a20002, 0x24a20008, 0x27623000,
-0x408021, 0x16030005, 0x30820004, 0x10400004,
-0xc02021, 0x10000022, 0x1021, 0x8e040000,
-0x8f42011c, 0x14a20003, 0x0, 0x8f420120,
-0xaf420114, 0x8ca30000, 0x8f420148, 0x831823,
-0x43102b, 0x10400003, 0x0, 0x8f420148,
-0x621821, 0x94a20006, 0x24420050, 0x62102b,
-0x1440000f, 0xa01021, 0xafa40010, 0xafa30014,
-0x8ca60000, 0x8ca70004, 0x3c040001, 0xc002d3b,
-0x24847f5c, 0x8f42020c, 0x24420001, 0xaf42020c,
-0x8f42020c, 0x1021, 0xaf9000e8, 0xaf9000e4,
-0x8fbf001c, 0x8fb00018, 0x3e00008, 0x27bd0020,
-0x3e00008, 0x0, 0x8f8300e4, 0x27623ff8,
-0x14620002, 0x24620008, 0x27623000, 0x401821,
-0xaf8300e8, 0xaf8300e4, 0x3e00008, 0x0,
-0x3e00008, 0x0, 0x8f8400e0, 0x8f8800c4,
-0x8f8300e8, 0x2402fff8, 0x823824, 0xe32023,
-0x2c821000, 0x50400001, 0x24841000, 0x420c2,
-0x801821, 0x8f440258, 0x8f45025c, 0x1021,
-0xa32821, 0xa3302b, 0x822021, 0x862021,
-0xaf440258, 0xaf45025c, 0x8f8300c8, 0x8f420148,
-0x1032023, 0x82102b, 0x14400004, 0x801821,
-0x8f420148, 0x822021, 0x801821, 0x8f440250,
-0x8f450254, 0x1021, 0xa32821, 0xa3302b,
-0x822021, 0x862021, 0xaf440250, 0xaf450254,
-0xaf8800c8, 0xaf8700e4, 0xaf8700e8, 0x3e00008,
-0x0, 0x27bdff28, 0x240a0001, 0xafbf00d0,
-0xafbe00cc, 0xafb500c8, 0xafb300c4, 0xafb200c0,
-0xafb100bc, 0xafb000b8, 0xa3a0009f, 0xafa0004c,
-0xafaa0064, 0xa7a00096, 0xafa00040, 0x934205c4,
-0x8821, 0x1040000a, 0xa7a0008e, 0x8f4b00c4,
-0xafab006c, 0x8f4a00c0, 0xafaa0074, 0x8f4b00cc,
-0xafab007c, 0x8f4a00c8, 0x1000019f, 0xafaa0084,
-0x8f420114, 0x40f809, 0x0, 0x403021,
-0x10c00418, 0x0, 0x8cc20000, 0x8cc30004,
-0xafa20020, 0xafa30024, 0x8fab0024, 0x8faa0020,
-0x3162ffff, 0x2442fffc, 0xafa20074, 0x3c020006,
-0x2c21024, 0xafab0084, 0x14400015, 0xafaa006c,
-0x91420000, 0x30420001, 0x10400011, 0x2402ffff,
-0x8d430000, 0x14620004, 0x3402ffff, 0x95430004,
-0x1062000b, 0x0, 0xc0025dd, 0x8fa4006c,
-0x304200ff, 0x14400006, 0x0, 0x8f420118,
-0x40f809, 0x0, 0x100003f6, 0x0,
-0x8fa20024, 0x3c03ffbf, 0x3463ffff, 0x431024,
-0x3c03ffff, 0x431824, 0x14600003, 0xafa20024,
-0x10000040, 0x1821, 0x3c020080, 0x621024,
-0x10400007, 0x0, 0x8f42038c, 0x24420001,
-0xaf42038c, 0x8f42038c, 0x10000036, 0x24030001,
-0x8f420210, 0x24420001, 0xaf420210, 0x8f420210,
-0x3c020001, 0x621024, 0x10400006, 0x3c020002,
-0x8f4201c4, 0x24420001, 0xaf4201c4, 0x8f4201c4,
-0x3c020002, 0x621024, 0x10400006, 0x3c020004,
-0x8f42037c, 0x24420001, 0xaf42037c, 0x8f42037c,
-0x3c020004, 0x621024, 0x10400006, 0x3c020008,
-0x8f420380, 0x24420001, 0xaf420380, 0x8f420380,
-0x3c020008, 0x621024, 0x10400006, 0x3c020010,
-0x8f420384, 0x24420001, 0xaf420384, 0x8f420384,
-0x3c020010, 0x621024, 0x10400006, 0x3c020020,
-0x8f4201c0, 0x24420001, 0xaf4201c0, 0x8f4201c0,
-0x3c020020, 0x621024, 0x10400006, 0x24030001,
-0x8f420388, 0x24420001, 0xaf420388, 0x8f420388,
-0x24030001, 0x8c020260, 0x8fab0074, 0x4b102b,
-0x10400014, 0x307000ff, 0x8f4201e8, 0x24420001,
-0xaf4201e8, 0x8f4201e8, 0x8faa0084, 0x8f8200e0,
-0x354a0100, 0xafaa0084, 0xafa20010, 0x8f8200e4,
-0x24100001, 0x3c040001, 0x24847f68, 0xafa20014,
-0x8fa60020, 0x8fa70024, 0x3c050007, 0xc002d3b,
-0x34a50800, 0x12000011, 0x3c020080, 0x2c21024,
-0x1440000f, 0x32c20400, 0x8fab0084, 0x3c020080,
-0x34420100, 0x1621024, 0x10400005, 0x0,
-0x8f42020c, 0x24420001, 0xaf42020c, 0x8f42020c,
-0x8fa30074, 0x10000377, 0x0, 0x32c20400,
-0x10400015, 0x34028100, 0x8faa006c, 0x9543000c,
-0x14620012, 0x3c020100, 0x240b0200, 0xa7ab0096,
-0x9542000e, 0x8d430008, 0x8d440004, 0x8d450000,
-0x8faa0074, 0x8fab006c, 0x254afffc, 0xafaa0074,
-0xa7a2008e, 0xad63000c, 0xad640008, 0xad650004,
-0x256b0004, 0xafab006c, 0x3c020100, 0x2c21024,
-0x10400004, 0x0, 0x8faa0074, 0x254a0004,
-0xafaa0074, 0x16000005, 0x24020800, 0x8fab006c,
-0x9563000c, 0x50620001, 0x2411000e, 0x8f4200bc,
-0x5040000a, 0xafa0007c, 0x8faa0074, 0x4a102b,
-0x50400006, 0xafa0007c, 0x8f4200bc, 0x1421023,
-0xafa2007c, 0x8f4b00bc, 0xafab0074, 0x8f420080,
-0x8faa0074, 0x4a102b, 0x104000c5, 0x32c28000,
-0x104000cd, 0x32c21000, 0x10400058, 0x240b0004,
-0x3c021000, 0x2c21024, 0x104000c7, 0xafab0064,
-0x122000c5, 0x0, 0x8faa006c, 0x8fab0074,
-0x1711023, 0x2c420014, 0x144000c0, 0x1512021,
-0x24830006, 0x90820000, 0x3c05001f, 0x34a5ffff,
-0x3042000f, 0x23080, 0xa3102b, 0x10400003,
-0x0, 0x8f420148, 0x621823, 0x94620000,
-0x30421fff, 0x10400003, 0x2261021, 0x100000ae,
-0xafa20040, 0x24830009, 0xa3102b, 0x10400003,
-0x0, 0x8f420148, 0x621823, 0x90630000,
-0x24020006, 0x14620017, 0x24020011, 0x94820002,
-0x2c420028, 0x144000a0, 0x861821, 0xa3102b,
-0x50400004, 0x2463000c, 0x8f420148, 0x621823,
-0x2463000c, 0xa3102b, 0x10400003, 0x0,
-0x8f420148, 0x621823, 0x90630000, 0x306200f0,
-0x21882, 0x2261021, 0x431021, 0x1000008e,
-0xafa20040, 0x1462008c, 0x0, 0x94820002,
-0x2c42001c, 0x14400088, 0x2263821, 0x94830002,
-0x24e20008, 0x2c63009c, 0x14600083, 0xafa20040,
-0x861821, 0xa3102b, 0x10400003, 0x0,
-0x8f420148, 0x621823, 0x94620000, 0x24040801,
-0x10440004, 0x24e20088, 0x94620002, 0x14440076,
-0x24e20088, 0x10000074, 0xafa20040, 0x10000071,
-0x240a0003, 0x8f420350, 0x2403ffbf, 0x283a024,
-0x24420001, 0xaf420350, 0x8f420350, 0x100002b8,
-0x0, 0x2c2b025, 0x2402ffbf, 0x282a024,
-0x8f830128, 0x3c040001, 0x24847fa0, 0x26620001,
-0xafa20014, 0xafa30010, 0x8f860120, 0x8f870124,
-0x3c050007, 0xc002d3b, 0x34a52250, 0x100002a8,
-0x0, 0x2c2b025, 0x2402ffbf, 0x282a024,
-0x8f830128, 0x3c040001, 0x24847fa0, 0x24020002,
-0xafa20014, 0xafa30010, 0x8f860120, 0x8f870124,
-0x3c050007, 0xc002d3b, 0x34a52450, 0x10000298,
-0x0, 0x8ea20000, 0x8ea30004, 0x3c040001,
-0x24847fb8, 0xafb00010, 0xafbe0014, 0x8ea70018,
-0x34a52800, 0xc002d3b, 0x603021, 0x3c040001,
-0x24847f4c, 0x1000001f, 0x2402058d, 0xa6b1000a,
-0x8f820124, 0x3c040001, 0x24847fc0, 0xafbe0014,
-0xafa20010, 0x8f460044, 0x8f870120, 0x3c050007,
-0xc002d3b, 0x34a53000, 0x3c040001, 0x24847f4c,
-0x10000010, 0x240205c9, 0xa6b1000a, 0xa6b2000e,
-0x8f820124, 0x3c040001, 0x24847fcc, 0xafbe0014,
-0xafa20010, 0x8f460044, 0x8f870120, 0x3c050007,
-0xc002d3b, 0x34a53200, 0x3c040001, 0x24847f4c,
-0x240205fe, 0xafa20010, 0xafa00014, 0x8f860144,
-0x3c070001, 0x24e77f98, 0xc002d3b, 0x3405dead,
-0x8f82011c, 0x34420002, 0xaf82011c, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820140, 0x3c030001,
-0x431025, 0xaf820140, 0x10000259, 0x0,
-0x8f420084, 0x8fab0074, 0x4b102b, 0x14400007,
-0x3c020001, 0x2c21024, 0x10400004, 0x0,
-0x240a0002, 0xafaa0064, 0x8fab0074, 0x1160026d,
-0x27aa0020, 0xafaa00ac, 0x3c0b001f, 0x356bffff,
-0xafab00a4, 0x8faa0064, 0x240b0001, 0x154b0022,
-0x24020002, 0x8f430054, 0x8f420050, 0x1062000b,
-0x274a0054, 0x8f5e0054, 0x3403ecc0, 0xafaa0054,
-0x27c20001, 0x304201ff, 0xafa2005c, 0x1e1140,
-0x431021, 0x10000077, 0x2e2a821, 0x8f420044,
-0x8fab0074, 0x3c040001, 0x24847f74, 0xafab0014,
-0xafa20010, 0x8f460054, 0x8f470050, 0x3c050007,
-0xc002d3b, 0x34a51300, 0x8f430350, 0x2402ffbf,
-0x282a024, 0x24630001, 0xaf430350, 0x8f420350,
-0x10000223, 0x0, 0x1542001d, 0x0,
-0x8f430074, 0x8f420070, 0x1062000a, 0x274b0074,
-0x8f5e0074, 0xafab0054, 0x27c20001, 0x304203ff,
-0xafa2005c, 0x1e1140, 0x24426cc0, 0x10000055,
-0x2e2a821, 0x8f420044, 0x8faa0074, 0x3c040001,
-0x24847f80, 0x3c050007, 0xafaa0014, 0xafa20010,
-0x8f460074, 0x8f470070, 0x34a51500, 0x240b0001,
-0xc002d3b, 0xafab0064, 0x1000ffc2, 0x0,
-0x8f430064, 0x8f420060, 0x1062002b, 0x274a0064,
-0x8f5e0064, 0x8fab0064, 0xafaa0054, 0x27c20001,
-0x304200ff, 0xafa2005c, 0x24020004, 0x1562001f,
-0x1e1140, 0x1e1180, 0x24420cc0, 0x2e21021,
-0xafa2004c, 0x24550020, 0x3c021000, 0x2c21024,
-0x1040000e, 0x0, 0x8faa004c, 0x8fab0074,
-0x9542002a, 0x4b102b, 0x54400006, 0x240a0001,
-0x8fa20040, 0x10400027, 0x0, 0x104b0025,
-0x240a0001, 0x10000023, 0xa3aa009f, 0x8fab004c,
-0x8faa0074, 0x9562002a, 0x4a102b, 0x1040001d,
-0x240b0001, 0x1000001b, 0xa3ab009f, 0x24424cc0,
-0x10000018, 0x2e2a821, 0x8f420044, 0x8faa0074,
-0x3c040001, 0x24847f8c, 0xafaa0014, 0xafa20010,
-0x8f460064, 0x8f470060, 0x3c050007, 0xc002d3b,
-0x34a51800, 0x3c020008, 0x2c21024, 0x1440ff09,
-0x0, 0x8f420370, 0x240b0001, 0xafab0064,
-0x24420001, 0xaf420370, 0x8f420370, 0x1000ff7d,
-0x0, 0x8faa006c, 0xaeaa0018, 0x93a2009f,
-0x104000ae, 0x24050002, 0x8fab004c, 0x8fa40040,
-0x25620020, 0xafa20028, 0x25620008, 0xafa20030,
-0x25620010, 0xafab002c, 0x1080000e, 0xafa20034,
-0x9563002a, 0x83102b, 0x54400001, 0x801821,
-0x1000000b, 0xa7a30038, 0x27a30036, 0x131040,
-0x621821, 0x94620000, 0x441021, 0x10000016,
-0xa4620000, 0x8faa004c, 0x9542002a, 0xa7a20038,
-0x8fab004c, 0x8fa40074, 0x8fa300ac, 0x95620018,
-0xa7a2003a, 0x9562001a, 0xa7a2003c, 0x9562001c,
-0x9821, 0xa7a2003e, 0x94620018, 0x24630002,
-0x822023, 0x1880ffe8, 0x26730001, 0x2e620004,
-0x1440fff9, 0x0, 0x18800014, 0x2402052b,
-0x3c040001, 0x24847f4c, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e77f98, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x8f4200fc,
-0x26650001, 0xa2102a, 0x1440003f, 0x24030001,
-0x8f83012c, 0x10600037, 0x0, 0x8f820124,
-0x431023, 0x22143, 0x58800001, 0x24840040,
-0x8f820128, 0x431023, 0x21943, 0x58600001,
-0x24630040, 0x64102a, 0x54400001, 0x602021,
-0xaf4400fc, 0x8f4200fc, 0xa2102a, 0x10400025,
-0x24030001, 0x10000029, 0x306200ff, 0x8faa006c,
-0x96070018, 0xafaa0010, 0x8e220008, 0x3c040001,
-0x24847fac, 0x8c430004, 0x8c420000, 0x34a52400,
-0x2403021, 0xc002d3b, 0xafa30014, 0x3c040001,
-0x24847f4c, 0x2402054f, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e77f98, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x1000002b,
-0x0, 0x8f420334, 0x1821, 0x24420001,
-0xaf420334, 0x8f420334, 0x306200ff, 0x5040fe7d,
-0x3c020800, 0x12600021, 0x9021, 0x8fb100ac,
-0x2208021, 0x8e220008, 0x96070018, 0x8fa6006c,
-0x8c440000, 0x8c450004, 0x240b0001, 0xafab0010,
-0xafbe0014, 0x8f420008, 0xafa20018, 0x8f42010c,
-0x40f809, 0x0, 0x1040ffc4, 0x3c050007,
-0x96020018, 0x8faa006c, 0x8fab00a4, 0x1425021,
-0x16a102b, 0x10400004, 0xafaa006c, 0x8f420148,
-0x1425023, 0xafaa006c, 0x26100002, 0x26520001,
-0x253102b, 0x1440ffe3, 0x26310004, 0x8fb00074,
-0x97b10038, 0x10000035, 0x0, 0x8f4200fc,
-0xa2102a, 0x1440001b, 0x24030001, 0x8f83012c,
-0x10600013, 0x0, 0x8f820124, 0x431023,
-0x22143, 0x58800001, 0x24840040, 0x8f820128,
-0x431023, 0x21943, 0x58600001, 0x24630040,
-0x64102a, 0x54400001, 0x602021, 0xaf4400fc,
-0x8f4200fc, 0xa2102a, 0x14400006, 0x24030001,
-0x8f420334, 0x1821, 0x24420001, 0xaf420334,
-0x8f420334, 0x306200ff, 0x1040fe46, 0x3c020800,
-0x96b1000a, 0x8fb00074, 0x3223ffff, 0x70102b,
-0x54400001, 0x608021, 0x8ea40000, 0x8ea50004,
-0x240a0001, 0xafaa0010, 0xafbe0014, 0x8f420008,
-0x8fa6006c, 0xafa20018, 0x8f42010c, 0x40f809,
-0x2003821, 0x1040fe43, 0x3c050007, 0x96a4000e,
-0x97ab0096, 0x11600007, 0x809021, 0x934205c4,
-0x14400004, 0x0, 0x97aa008e, 0x8b2025,
-0xa6aa0016, 0x8fab0084, 0x3c02ffff, 0x1621024,
-0x10400003, 0xb1402, 0x34840400, 0xa6a20014,
-0x3c021000, 0x2c21024, 0x10400006, 0x0,
-0x8fa20040, 0x401821, 0x1021, 0xaea20000,
-0xaea30004, 0x8faa0074, 0x560a0073, 0xa6a4000e,
-0x34820004, 0xa6a2000e, 0x8fab007c, 0x14b1021,
-0xa6a2000a, 0x8f430044, 0x8f4401a0, 0x8f4501a4,
-0x34028000, 0xafa20010, 0x8f420044, 0x2a03021,
-0x24070020, 0xafa20014, 0x8f42000c, 0x31940,
-0x604821, 0xafa20018, 0x8f42010c, 0x4021,
-0xa92821, 0xa9182b, 0x882021, 0x40f809,
-0x832021, 0x5040fe19, 0xa6b2000e, 0x8f420368,
-0xafa00074, 0xa34005c4, 0x2442ffff, 0xaf420368,
-0x8faa0064, 0x240b0001, 0x8f420368, 0x154b0006,
-0x24020002, 0x8f42035c, 0x2442ffff, 0xaf42035c,
-0x1000000c, 0x8f42035c, 0x15420006, 0x0,
-0x8f420364, 0x2442ffff, 0xaf420364, 0x10000005,
-0x8f420364, 0x8f420360, 0x2442ffff, 0xaf420360,
-0x8f420360, 0x8faa005c, 0x8fab0054, 0xad6a0000,
-0x8f420044, 0x8f440088, 0x8f430078, 0x24420001,
-0x441024, 0x24630001, 0xaf420044, 0xaf430078,
-0x8c020240, 0x62182b, 0x14600076, 0x24070008,
-0x8f440168, 0x8f45016c, 0x8f430044, 0x8f48000c,
-0x8f860120, 0x24020040, 0xafa20010, 0xafa30014,
-0xafa80018, 0x8f42010c, 0x40f809, 0x24c6001c,
-0x14400011, 0x240b0001, 0x3c010001, 0x370821,
-0xa02b40f2, 0x8f820124, 0xafa20010, 0x8f820128,
-0x3c040001, 0x24847f44, 0xafa20014, 0x8f460044,
-0x8f870120, 0x3c050009, 0xc002d3b, 0x34a51300,
-0x1000000b, 0x0, 0x8f420304, 0x24420001,
-0xaf420304, 0x8f420304, 0x8f420044, 0xaf42007c,
-0x3c010001, 0x370821, 0xa02040f2, 0xaf400078,
-0x8f420318, 0x24420001, 0xaf420318, 0x8f420318,
-0x10000048, 0x0, 0xa6b0000a, 0x8f430044,
-0x8f4401a0, 0x8f4501a4, 0x34028000, 0xafa20010,
-0x8f420044, 0x2a03021, 0x24070020, 0xafa20014,
-0x8f42000c, 0x31940, 0x604821, 0xafa20018,
-0x8f42010c, 0x4021, 0xa92821, 0xa9182b,
-0x882021, 0x40f809, 0x832021, 0x1040fdba,
-0x240a0001, 0xa34a05c4, 0x8fab0074, 0x8faa006c,
-0x1705823, 0xafab0074, 0x8fab00a4, 0x1505021,
-0x16a102b, 0x10400004, 0xafaa006c, 0x8f420148,
-0x1425023, 0xafaa006c, 0x8f420368, 0x2442ffff,
-0xaf420368, 0x8faa0064, 0x240b0001, 0x8f420368,
-0x154b0006, 0x24020002, 0x8f42035c, 0x2442ffff,
-0xaf42035c, 0x1000000c, 0x8f42035c, 0x11420006,
-0x0, 0x8f420360, 0x2442ffff, 0xaf420360,
-0x10000005, 0x8f420360, 0x8f420364, 0x2442ffff,
-0xaf420364, 0x8f420364, 0x8faa005c, 0x8fab0054,
-0xad6a0000, 0x8f420044, 0x8f440088, 0x8f430078,
-0x24420001, 0x441024, 0x24630001, 0xaf420044,
-0xaf430078, 0x8fab0074, 0x1560fdba, 0x0,
-0x8faa0074, 0x1140001f, 0x0, 0x934205c4,
-0x10400009, 0x0, 0x8fab006c, 0xaf4b00c4,
-0xaf4a00c0, 0x8faa0084, 0xaf4a00c8, 0x8fab007c,
-0x1000000e, 0xaf4b00cc, 0x97aa0096, 0x1140000b,
-0x34038100, 0x8fa20020, 0x8c46000c, 0xa443000c,
-0x97ab008e, 0x8c440004, 0x8c450008, 0xa44b000e,
-0xac440000, 0xac450004, 0xac460008, 0x8f42034c,
-0x24420001, 0xaf42034c, 0x8f42034c, 0x10000011,
-0x0, 0x8faa0084, 0x3144ffff, 0x2484fffc,
-0x801821, 0x8f440250, 0x8f450254, 0x8f460118,
-0x1021, 0xa32821, 0xa3382b, 0x822021,
-0x872021, 0xaf440250, 0xaf450254, 0xc0f809,
-0x0, 0x8fbf00d0, 0x8fbe00cc, 0x8fb500c8,
-0x8fb300c4, 0x8fb200c0, 0x8fb100bc, 0x8fb000b8,
-0x3e00008, 0x27bd00d8, 0x3e00008, 0x0,
-0x27bdff30, 0x240b0001, 0xafbf00c8, 0xafbe00c4,
-0xafb500c0, 0xafb300bc, 0xafb200b8, 0xafb100b4,
-0xafb000b0, 0xa3a0008f, 0xafa0004c, 0xafab0064,
-0xa7a0007e, 0xafa00040, 0x934205c4, 0x8821,
-0x10400007, 0xa7a00086, 0x8f4c00c0, 0xafac006c,
-0x8f4b00c8, 0x8f5e00c4, 0x10000184, 0xafab0074,
-0x8f420114, 0x40f809, 0x0, 0x403021,
-0x10c00348, 0x0, 0x8cc20000, 0x8cc30004,
-0xafa20020, 0xafa30024, 0x8fac0024, 0x8fbe0020,
-0x3182ffff, 0x2442fffc, 0xafa2006c, 0x3c020006,
-0x2c21024, 0x14400015, 0xafac0074, 0x93c20000,
-0x30420001, 0x10400011, 0x2402ffff, 0x8fc30000,
-0x14620004, 0x3402ffff, 0x97c30004, 0x1062000b,
-0x0, 0xc0025dd, 0x3c02021, 0x304200ff,
-0x14400006, 0x0, 0x8f420118, 0x40f809,
-0x0, 0x10000327, 0x0, 0x8fa20024,
-0x3c03ffbf, 0x3463ffff, 0x431024, 0x3c03ffff,
-0x431824, 0x14600003, 0xafa20024, 0x10000040,
-0x8021, 0x3c020080, 0x621024, 0x10400007,
-0x0, 0x8f42038c, 0x24420001, 0xaf42038c,
-0x8f42038c, 0x10000036, 0x24100001, 0x8f420210,
-0x24420001, 0xaf420210, 0x8f420210, 0x3c020001,
-0x621024, 0x10400006, 0x3c020002, 0x8f4201c4,
-0x24420001, 0xaf4201c4, 0x8f4201c4, 0x3c020002,
-0x621024, 0x10400006, 0x3c020004, 0x8f42037c,
-0x24420001, 0xaf42037c, 0x8f42037c, 0x3c020004,
-0x621024, 0x10400006, 0x3c020008, 0x8f420380,
-0x24420001, 0xaf420380, 0x8f420380, 0x3c020008,
-0x621024, 0x10400006, 0x3c020010, 0x8f420384,
-0x24420001, 0xaf420384, 0x8f420384, 0x3c020010,
-0x621024, 0x10400006, 0x3c020020, 0x8f4201c0,
-0x24420001, 0xaf4201c0, 0x8f4201c0, 0x3c020020,
-0x621024, 0x10400006, 0x24100001, 0x8f420388,
-0x24420001, 0xaf420388, 0x8f420388, 0x24100001,
-0x8c020260, 0x8fab006c, 0x4b102b, 0x10400015,
-0x320200ff, 0x8f4201e8, 0x24420001, 0xaf4201e8,
-0x8f4201e8, 0x8fac0074, 0x8f8200e0, 0x358c0100,
-0xafac0074, 0xafa20010, 0x8f8200e4, 0x24100001,
-0x3c040001, 0x24847f68, 0xafa20014, 0x8fa60020,
-0x8fa70024, 0x3c050007, 0xc002d3b, 0x34a53600,
-0x320200ff, 0x10400011, 0x3c020080, 0x2c21024,
-0x1440000f, 0x32c20400, 0x8fab0074, 0x3c020080,
-0x34420100, 0x1621024, 0x10400005, 0x0,
-0x8f42020c, 0x24420001, 0xaf42020c, 0x8f42020c,
-0x8fa3006c, 0x100002a7, 0x0, 0x32c20400,
-0x10400012, 0x34028100, 0x97c3000c, 0x1462000f,
-0x0, 0x240c0200, 0xa7ac007e, 0x97c2000e,
-0x8fc30008, 0x8fc40004, 0x8fab006c, 0x8fc50000,
-0x256bfffc, 0xafab006c, 0xa7a20086, 0xafc3000c,
-0xafc40008, 0xafc50004, 0x27de0004, 0x8fa7006c,
-0x320200ff, 0x14400033, 0x3c020100, 0x97c4000c,
-0x2c8305dd, 0x38828870, 0x2c420001, 0x621825,
-0x10600014, 0x32c20800, 0x10400015, 0x24020800,
-0x97c30014, 0x14620012, 0x3402aaaa, 0x97c3000e,
-0x14620007, 0x2021, 0x97c30010, 0x24020300,
-0x14620004, 0x801021, 0x97c20012, 0x2c440001,
-0x801021, 0x54400006, 0x24110016, 0x10000004,
-0x0, 0x24020800, 0x50820001, 0x2411000e,
-0x12200013, 0x3d12021, 0x24830009, 0x3c02001f,
-0x3442ffff, 0x43102b, 0x10400003, 0x0,
-0x8f420148, 0x621823, 0x90620000, 0x38430006,
-0x2c630001, 0x38420011, 0x2c420001, 0x621825,
-0x10600004, 0x3c020100, 0x94820002, 0x513821,
-0x3c020100, 0x2c21024, 0x5040000e, 0xafa7006c,
-0x8fac006c, 0x10ec0008, 0x3c050007, 0x3c040001,
-0x24847fd8, 0x8fa6006c, 0x34a54000, 0xafa00010,
-0xc002d3b, 0xafa00014, 0x8fab006c, 0x256b0004,
-0xafab006c, 0x8f420080, 0x8fac006c, 0x4c102b,
-0x10400080, 0x32c28000, 0x10400088, 0x32c21000,
-0x10400055, 0x240b0004, 0x3c021000, 0x2c21024,
-0x10400082, 0xafab0064, 0x12200080, 0x1911023,
-0x2c420014, 0x1440007d, 0x3d12021, 0x24830006,
-0x90820000, 0x3c05001f, 0x34a5ffff, 0x3042000f,
-0x23080, 0xa3102b, 0x10400003, 0x0,
-0x8f420148, 0x621823, 0x94620000, 0x30421fff,
-0x10400003, 0x2261021, 0x1000006c, 0xafa20040,
-0x24830009, 0xa3102b, 0x10400003, 0x0,
-0x8f420148, 0x621823, 0x90630000, 0x24020006,
-0x14620017, 0x24020011, 0x94820002, 0x2c420028,
-0x1440005e, 0x861821, 0xa3102b, 0x50400004,
-0x2463000c, 0x8f420148, 0x621823, 0x2463000c,
-0xa3102b, 0x10400003, 0x0, 0x8f420148,
-0x621823, 0x90630000, 0x306200f0, 0x21882,
-0x2261021, 0x431021, 0x1000004c, 0xafa20040,
-0x1462004a, 0x0, 0x94820002, 0x2c42001c,
-0x14400046, 0x2263821, 0x94830002, 0x24e20008,
-0x2c63009c, 0x14600041, 0xafa20040, 0x861821,
-0xa3102b, 0x10400003, 0x0, 0x8f420148,
-0x621823, 0x94620000, 0x24040801, 0x10440004,
-0x24e20088, 0x94620002, 0x14440034, 0x24e20088,
-0x10000032, 0xafa20040, 0x1000002f, 0x240c0003,
-0x8f420350, 0x2403ffbf, 0x283a024, 0x24420001,
-0xaf420350, 0x8f420350, 0x100001c4, 0x0,
-0x3c020800, 0x2c2b025, 0x2402ffbf, 0x282a024,
-0x8f830128, 0x3c040001, 0x24847fa0, 0x26620001,
-0xafa20014, 0xafa30010, 0x8f860120, 0x8f870124,
-0x3c050007, 0xc002d3b, 0x34a55300, 0x100001b3,
-0x0, 0x8ea20000, 0x8ea30004, 0x3c040001,
-0x24847fb8, 0xafb00010, 0xafb10014, 0x8ea70018,
-0x34a55900, 0xc002d3b, 0x603021, 0x100001a7,
-0x0, 0x8f420084, 0x8fab006c, 0x4b102b,
-0x14400007, 0x3c020001, 0x2c21024, 0x10400004,
-0x0, 0x240c0002, 0xafac0064, 0x8fab006c,
-0x116001b8, 0x27ac0020, 0xafac0094, 0x8fab0064,
-0x240c0001, 0x556c0022, 0x240c0002, 0x8f430054,
-0x8f420050, 0x1062000b, 0x274b0054, 0x8f510054,
-0x3403ecc0, 0xafab0054, 0x26220001, 0x304201ff,
-0xafa2005c, 0x111140, 0x431021, 0x10000077,
-0x2e2a821, 0x8f420044, 0x8fac006c, 0x3c040001,
-0x24847f74, 0xafac0014, 0xafa20010, 0x8f460054,
-0x8f470050, 0x3c050007, 0xc002d3b, 0x34a54300,
-0x8f430350, 0x2402ffbf, 0x282a024, 0x24630001,
-0xaf430350, 0x8f420350, 0x10000174, 0x0,
-0x156c001d, 0x0, 0x8f430074, 0x8f420070,
-0x1062000a, 0x274b0074, 0x8f510074, 0xafab0054,
-0x26220001, 0x304203ff, 0xafa2005c, 0x111140,
-0x24426cc0, 0x10000055, 0x2e2a821, 0x8f420044,
-0x8fac006c, 0x3c040001, 0x24847f80, 0x3c050007,
-0xafac0014, 0xafa20010, 0x8f460074, 0x8f470070,
-0x34a54500, 0x240b0001, 0xc002d3b, 0xafab0064,
-0x1000ffc2, 0x0, 0x8f430064, 0x8f420060,
-0x1062002b, 0x274c0064, 0x8f510064, 0x8fab0064,
-0xafac0054, 0x26220001, 0x304200ff, 0xafa2005c,
-0x24020004, 0x1562001f, 0x111140, 0x111180,
-0x24420cc0, 0x2e21021, 0xafa2004c, 0x24550020,
-0x3c021000, 0x2c21024, 0x1040000e, 0x0,
-0x8fac004c, 0x8fab006c, 0x9582002a, 0x4b102b,
-0x54400006, 0x240c0001, 0x8fa20040, 0x50400028,
-0xaebe0018, 0x104b0025, 0x240c0001, 0x10000023,
-0xa3ac008f, 0x8fab004c, 0x8fac006c, 0x9562002a,
-0x4c102b, 0x1040001d, 0x240b0001, 0x1000001b,
-0xa3ab008f, 0x24424cc0, 0x10000018, 0x2e2a821,
-0x8f420044, 0x8fac006c, 0x3c040001, 0x24847f8c,
-0xafac0014, 0xafa20010, 0x8f460064, 0x8f470060,
-0x3c050007, 0xc002d3b, 0x34a54800, 0x3c020008,
-0x2c21024, 0x1440ff4e, 0x0, 0x8f420370,
-0x240b0001, 0xafab0064, 0x24420001, 0xaf420370,
-0x8f420370, 0x1000ff7d, 0x0, 0xaebe0018,
-0x93a2008f, 0x104000bf, 0x0, 0x8fac004c,
-0x8fa40040, 0x25820020, 0xafa20028, 0x25820008,
-0xafa20030, 0x25820010, 0xafac002c, 0x1080000e,
-0xafa20034, 0x9583002a, 0x83102b, 0x54400001,
-0x801821, 0x1000000b, 0xa7a30038, 0x27a30036,
-0x131040, 0x621821, 0x94620000, 0x441021,
-0x10000016, 0xa4620000, 0x8fab004c, 0x9562002a,
-0xa7a20038, 0x8fac004c, 0x8fa4006c, 0x8fa30094,
-0x95820018, 0xa7a2003a, 0x9582001a, 0xa7a2003c,
-0x9582001c, 0x9821, 0xa7a2003e, 0x94620018,
-0x24630002, 0x822023, 0x1880ffe8, 0x26730001,
-0x2e620004, 0x1440fff9, 0x0, 0x18800014,
-0x240207c2, 0x3c040001, 0x24847f4c, 0xafa20010,
-0xafa00014, 0x8f860144, 0x3c070001, 0x24e77f98,
-0xc002d3b, 0x3405dead, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f820220, 0x34420004, 0xaf820220,
-0x8f820140, 0x3c030001, 0x431025, 0xaf820140,
-0x8f4200fc, 0x262102a, 0x14400044, 0x24030001,
-0x8f83012c, 0x1060003c, 0x0, 0x8f820124,
-0x431023, 0x22143, 0x58800001, 0x24840040,
-0x8f820128, 0x431023, 0x21943, 0x58600001,
-0x24630040, 0x64102a, 0x54400001, 0x602021,
-0xaf4400fc, 0x8f4200fc, 0x262102a, 0x1040002a,
-0x24030001, 0x1000002e, 0x306200ff, 0x8fab0094,
-0x101040, 0x4b1021, 0x94470018, 0x101080,
-0x4b1021, 0xafbe0010, 0x8c420008, 0x3c040001,
-0x24847fac, 0x3c050007, 0x8c430004, 0x8c420000,
-0x34a55500, 0x2003021, 0xc002d3b, 0xafa30014,
-0x3c040001, 0x24847f4c, 0x240207f4, 0xafa20010,
-0xafa00014, 0x8f860144, 0x3c070001, 0x24e77f98,
-0xc002d3b, 0x3405dead, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f820220, 0x34420004, 0xaf820220,
-0x8f820140, 0x3c030001, 0x431025, 0xaf820140,
-0x10000039, 0x0, 0x8f420334, 0x1821,
-0x24420001, 0xaf420334, 0x8f420334, 0x306200ff,
-0x1040febf, 0x8021, 0x8f430008, 0x2402fbff,
-0x1260002d, 0x625024, 0x3c0c4000, 0x22c4025,
-0x8fb10094, 0x2669ffff, 0x2209021, 0x8e420008,
-0x96270018, 0x8c440000, 0x8c450004, 0x56090004,
-0x240c0001, 0x240b0002, 0x10000002, 0xafab0010,
-0xafac0010, 0x16000004, 0xafa80014, 0x8f420008,
-0x10000002, 0xafa20018, 0xafaa0018, 0x8f42010c,
-0x3c03021, 0xafa800a0, 0xafa900a4, 0x40f809,
-0xafaa00a8, 0x8fa800a0, 0x8fa900a4, 0x8faa00a8,
-0x1040ffae, 0x3c02001f, 0x96230018, 0x3442ffff,
-0x3c3f021, 0x5e102b, 0x10400003, 0x26310002,
-0x8f420148, 0x3c2f023, 0x26100001, 0x213102b,
-0x1440ffda, 0x26520004, 0x8fb0006c, 0x1000001a,
-0x0, 0x96a3000a, 0x8fb0006c, 0x70102b,
-0x54400001, 0x608021, 0x8ea40000, 0x8ea50004,
-0x8fac0064, 0x240b0002, 0xafab0010, 0x934305c4,
-0xc1700, 0x10600003, 0x2223025, 0x3c020800,
-0xc23025, 0xafa60014, 0x8f420008, 0xafa20018,
-0x8f42010c, 0x3c03021, 0x40f809, 0x2003821,
-0x1040fe84, 0x3c050007, 0x97ab007e, 0x96a3000e,
-0x11600007, 0x0, 0x934205c4, 0x14400004,
-0x0, 0x97ac0086, 0x6b1825, 0xa6ac0016,
-0x8fab0074, 0x3c02ffff, 0x1621024, 0x10400003,
-0xb1402, 0x34630400, 0xa6a20014, 0xa6b0000a,
-0x8fac006c, 0x560c0006, 0x3d0f021, 0x34620004,
-0xafa0006c, 0xa6a2000e, 0x1000000d, 0xa34005c4,
-0x8fab006c, 0x3c02001f, 0x3442ffff, 0x5e102b,
-0x1705823, 0xafab006c, 0xa6a3000e, 0x240c0001,
-0x10400003, 0xa34c05c4, 0x8f420148, 0x3c2f023,
-0x3c021000, 0x2c21024, 0x10400006, 0x0,
-0x8fa20040, 0x401821, 0x1021, 0xaea20000,
-0xaea30004, 0x8fac005c, 0x8fab0054, 0xad6c0000,
-0x8fab006c, 0x1560fe69, 0x0, 0x8fac006c,
-0x1180001c, 0x0, 0x934205c4, 0x10400006,
-0x0, 0xaf5e00c4, 0xaf4c00c0, 0x8fab0074,
-0x1000000e, 0xaf4b00c8, 0x97ac007e, 0x1180000b,
-0x34038100, 0x8fa20020, 0x8c46000c, 0xa443000c,
-0x97ab0086, 0x8c440004, 0x8c450008, 0xa44b000e,
-0xac440000, 0xac450004, 0xac460008, 0x8f42034c,
-0x24420001, 0xaf42034c, 0x8f42034c, 0x10000011,
-0x0, 0x8fac0074, 0x3184ffff, 0x2484fffc,
-0x801821, 0x8f440250, 0x8f450254, 0x8f460118,
-0x1021, 0xa32821, 0xa3382b, 0x822021,
-0x872021, 0xaf440250, 0xaf450254, 0xc0f809,
-0x0, 0x8fbf00c8, 0x8fbe00c4, 0x8fb500c0,
-0x8fb300bc, 0x8fb200b8, 0x8fb100b4, 0x8fb000b0,
-0x3e00008, 0x27bd00d0, 0x3e00008, 0x0,
-0x27bdffd0, 0xafbf0028, 0xafb10024, 0xafb00020,
-0x8f43004c, 0x8f420048, 0x1062004a, 0x0,
-0x8f430048, 0x8f42004c, 0x628823, 0x6220001,
-0x26310200, 0x8f430054, 0x8f42004c, 0x43102b,
-0x14400004, 0x24020200, 0x8f43004c, 0x10000005,
-0x438023, 0x8f420054, 0x8f43004c, 0x431023,
-0x2450ffff, 0x16000016, 0x2005821, 0x3c040001,
-0x24847f4c, 0x24020888, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e77f98, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x2005821,
-0x22b102a, 0x54400001, 0x2205821, 0x8f4a004c,
-0x8f49004c, 0x8f440188, 0x8f45018c, 0x8f46004c,
-0xb3940, 0x24081000, 0xafa80010, 0x94940,
-0x1201821, 0x1021, 0x14b5021, 0x315001ff,
-0xafb00014, 0x8f480014, 0xa32821, 0xa3482b,
-0x822021, 0x892021, 0x63140, 0x3402ecc0,
-0xafa80018, 0x8f430108, 0xc23021, 0x60f809,
-0x2e63021, 0x54400001, 0xaf50004c, 0x8f43004c,
-0x8f420048, 0x14620019, 0x0, 0x8f420000,
-0x10400007, 0x0, 0xaf80004c, 0x8f82004c,
-0x1040fffd, 0x0, 0x10000005, 0x0,
-0xaf800048, 0x8f820048, 0x1040fffd, 0x0,
-0x8f820060, 0x2403fdff, 0x431024, 0xaf820060,
-0x8f420000, 0x10400004, 0x0, 0xaf80004c,
-0x10000002, 0x0, 0xaf800048, 0x8fbf0028,
-0x8fb10024, 0x8fb00020, 0x3e00008, 0x27bd0030,
-0x3e00008, 0x0, 0x27bdffd0, 0xafbf0028,
-0xafb10024, 0xafb00020, 0x8f43005c, 0x8f420058,
-0x1062005f, 0x0, 0x8f430058, 0x8f42005c,
-0x628823, 0x6220001, 0x26310100, 0x8f430064,
-0x8f42005c, 0x43102b, 0x14400004, 0x24020100,
-0x8f43005c, 0x10000005, 0x438023, 0x8f420064,
-0x8f43005c, 0x431023, 0x2450ffff, 0x16000016,
-0x2003821, 0x3c040001, 0x24847f4c, 0x240208e2,
-0xafa20010, 0xafa00014, 0x8f860144, 0x3c070001,
-0x24e77f98, 0xc002d3b, 0x3405dead, 0x8f82011c,
-0x34420002, 0xaf82011c, 0x8f820220, 0x34420004,
-0xaf820220, 0x8f820140, 0x3c030001, 0x431025,
-0xaf820140, 0x2003821, 0x227102a, 0x54400001,
-0x2203821, 0x8f42005c, 0x471021, 0x305000ff,
-0x32c21000, 0x10400015, 0x24082000, 0x8f49005c,
-0x8f440190, 0x8f450194, 0x8f46005c, 0x73980,
-0xafa80010, 0xafb00014, 0x8f480014, 0x94980,
-0x1201821, 0x1021, 0xa32821, 0xa3482b,
-0x822021, 0x892021, 0x63180, 0xafa80018,
-0x8f420108, 0x10000014, 0x24c60cc0, 0x8f49005c,
-0x8f440190, 0x8f450194, 0x8f46005c, 0x73940,
-0xafa80010, 0xafb00014, 0x8f480014, 0x94940,
-0x1201821, 0x1021, 0xa32821, 0xa3482b,
-0x822021, 0x892021, 0x63140, 0xafa80018,
-0x8f420108, 0x24c64cc0, 0x40f809, 0x2e63021,
-0x54400001, 0xaf50005c, 0x8f43005c, 0x8f420058,
-0x14620019, 0x0, 0x8f420000, 0x10400007,
-0x0, 0xaf80004c, 0x8f82004c, 0x1040fffd,
-0x0, 0x10000005, 0x0, 0xaf800048,
-0x8f820048, 0x1040fffd, 0x0, 0x8f820060,
-0x2403feff, 0x431024, 0xaf820060, 0x8f420000,
-0x10400004, 0x0, 0xaf80004c, 0x10000002,
-0x0, 0xaf800048, 0x8fbf0028, 0x8fb10024,
-0x8fb00020, 0x3e00008, 0x27bd0030, 0x3e00008,
-0x0, 0x27bdffd0, 0xafbf0028, 0xafb10024,
-0xafb00020, 0x8f43006c, 0x8f420068, 0x10620049,
-0x0, 0x8f430068, 0x8f42006c, 0x628823,
-0x6220001, 0x26310400, 0x8f430074, 0x8f42006c,
-0x43102b, 0x14400004, 0x24020400, 0x8f43006c,
-0x10000005, 0x438023, 0x8f420074, 0x8f43006c,
-0x431023, 0x2450ffff, 0x16000016, 0x2005821,
-0x3c040001, 0x24847f4c, 0x2402094b, 0xafa20010,
-0xafa00014, 0x8f860144, 0x3c070001, 0x24e77f98,
-0xc002d3b, 0x3405dead, 0x8f82011c, 0x34420002,
-0xaf82011c, 0x8f820220, 0x34420004, 0xaf820220,
-0x8f820140, 0x3c030001, 0x431025, 0xaf820140,
-0x2005821, 0x22b102a, 0x54400001, 0x2205821,
-0x8f4a006c, 0x8f49006c, 0x8f440198, 0x8f45019c,
-0x8f46006c, 0xb3940, 0x24084000, 0xafa80010,
-0x94940, 0x1201821, 0x1021, 0x14b5021,
-0x315003ff, 0xafb00014, 0x8f480014, 0xa32821,
-0xa3482b, 0x822021, 0x892021, 0x63140,
-0xafa80018, 0x8f420108, 0x24c66cc0, 0x40f809,
-0x2e63021, 0x54400001, 0xaf50006c, 0x8f43006c,
-0x8f420068, 0x14620019, 0x0, 0x8f420000,
-0x10400007, 0x0, 0xaf80004c, 0x8f82004c,
-0x1040fffd, 0x0, 0x10000005, 0x0,
-0xaf800048, 0x8f820048, 0x1040fffd, 0x0,
-0x8f820060, 0x2403f7ff, 0x431024, 0xaf820060,
-0x8f420000, 0x10400004, 0x0, 0xaf80004c,
-0x10000002, 0x0, 0xaf800048, 0x8fbf0028,
-0x8fb10024, 0x8fb00020, 0x3e00008, 0x27bd0030,
-0x3e00008, 0x0, 0x27bdffe0, 0xafbf001c,
-0xafb00018, 0x8f4200fc, 0x8f4400f8, 0x8f4300f4,
-0x24420001, 0xaf4200fc, 0x8f900128, 0x14830016,
-0x3c020001, 0x3c040001, 0x24847f4c, 0x240209b3,
-0xafa20010, 0xafa00014, 0x8f860144, 0x3c070001,
-0x24e77f98, 0xc002d3b, 0x3405dead, 0x8f82011c,
-0x34420002, 0xaf82011c, 0x8f820220, 0x34420004,
-0xaf820220, 0x8f820140, 0x3c030001, 0x431025,
-0xaf820140, 0x3c020001, 0x8f4300f8, 0x344230c8,
-0x2e21021, 0x54620004, 0x24620008, 0x3c020001,
-0x34422ec8, 0x2e21021, 0x401821, 0xaf4300f8,
-0xac600000, 0x8f4200f4, 0x14620005, 0x3c020001,
-0x26020020, 0xaf820128, 0x1000000f, 0x0,
-0x8f4300f8, 0x344230c8, 0x2e21021, 0x54620004,
-0x24620008, 0x3c020001, 0x34422ec8, 0x2e21021,
-0x401821, 0x8c620004, 0x21140, 0x2021021,
-0xaf820128, 0xac600000, 0x8e030018, 0x30620070,
-0x10400030, 0x30620020, 0x10400004, 0x3c020010,
-0x2c21024, 0x1040000d, 0x0, 0x30620040,
-0x10400004, 0x3c020020, 0x2c21024, 0x10400007,
-0x0, 0x30620010, 0x10400038, 0x3c020040,
-0x2c21024, 0x14400035, 0x0, 0x8f820040,
-0x30420001, 0x14400008, 0x2021, 0x8c030104,
-0x24020001, 0x50620005, 0x24040001, 0x8c020264,
-0x10400003, 0x801021, 0x24040001, 0x801021,
-0x10400007, 0x0, 0x8f42030c, 0x24420001,
-0xaf42030c, 0x8f42030c, 0x10000020, 0x0,
-0x8f820044, 0x34420004, 0xaf820044, 0x8f420308,
-0x24420001, 0xaf420308, 0x8f420308, 0x10000017,
-0x0, 0x3062b08f, 0x14400014, 0x240209e4,
-0x3c040001, 0x24847f4c, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070001, 0x24e77f98, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x8fbf001c,
-0x8fb00018, 0x3e00008, 0x27bd0020, 0x3e00008,
-0x0, 0x27bdff98, 0xafbf0060, 0xafbe005c,
-0xafb50058, 0xafb30054, 0xafb20050, 0xafb1004c,
-0xafb00048, 0x8f4200fc, 0x24420001, 0xaf4200fc,
-0x8f880128, 0x25020020, 0xaf820128, 0x8d030018,
-0x30620070, 0x10400030, 0x30620020, 0x10400004,
-0x3c020010, 0x2c21024, 0x1040000d, 0x0,
-0x30620040, 0x10400004, 0x3c020020, 0x2c21024,
-0x10400007, 0x0, 0x30620010, 0x104001c0,
-0x3c020040, 0x2c21024, 0x144001bd, 0x0,
-0x8f820040, 0x30420001, 0x14400008, 0x2021,
-0x8c030104, 0x24020001, 0x50620005, 0x24040001,
-0x8c020264, 0x10400003, 0x801021, 0x24040001,
-0x801021, 0x10400007, 0x0, 0x8f42030c,
-0x24420001, 0xaf42030c, 0x8f42030c, 0x100001a8,
-0x0, 0x8f820044, 0x34420004, 0xaf820044,
-0x8f420308, 0x24420001, 0xaf420308, 0x8f420308,
-0x1000019f, 0x0, 0x30620002, 0x10400160,
-0x3c020800, 0x8d1e001c, 0x1e5702, 0xafaa0034,
-0x950a0016, 0x3c22024, 0xafaa0024, 0x8faa0034,
-0x24020001, 0x15420006, 0x33deffff, 0x1e1140,
-0x3403ecc0, 0x431021, 0x10000010, 0x2e2a821,
-0x24020002, 0x15420005, 0x24020003, 0x1e1140,
-0x24426cc0, 0x10000009, 0x2e2a821, 0x15420005,
-0x1e1180, 0x1e1140, 0x24424cc0, 0x10000003,
-0x2e2a821, 0x571021, 0x24550ce0, 0x96a2000e,
-0x304afffc, 0x30420400, 0x10400003, 0xafaa002c,
-0x100000e1, 0x8821, 0x10800004, 0x8821,
-0x97b10026, 0x100000dd, 0xa6b10012, 0x8eb30018,
-0x966a000c, 0xa7aa003e, 0x97a5003e, 0x2ca305dd,
-0x38a28870, 0x2c420001, 0x621825, 0x10600015,
-0x2021, 0x32c20800, 0x10400015, 0x24020800,
-0x96630014, 0x14620012, 0x3402aaaa, 0x9663000e,
-0x14620007, 0x2821, 0x96630010, 0x24020300,
-0x14620004, 0xa01021, 0x96620012, 0x2c450001,
-0xa01021, 0x54400006, 0x24040016, 0x10000004,
-0x0, 0x24020800, 0x50a20001, 0x2404000e,
-0x108000b9, 0x2649021, 0x92420000, 0x3042000f,
-0x28080, 0x32c20100, 0x10400020, 0x2501821,
-0x3c020020, 0x43102b, 0x1440000e, 0x2402021,
-0x2821, 0x94820000, 0x24840002, 0xa22821,
-0x83102b, 0x1440fffb, 0x30a2ffff, 0x51c02,
-0x622821, 0x51c02, 0x30a2ffff, 0x10000009,
-0x622821, 0x8f470148, 0x8f420110, 0x102842,
-0x3c060020, 0x40f809, 0xafa80040, 0x3045ffff,
-0x8fa80040, 0x50a00001, 0x3405ffff, 0x8faa002c,
-0x354a0002, 0x10000002, 0xafaa002c, 0x2821,
-0x32c20080, 0x10400090, 0xa6a50010, 0x26430009,
-0x3c02001f, 0x3442ffff, 0x43102b, 0x10400003,
-0x0, 0x8f420148, 0x621823, 0x90660000,
-0x30c200ff, 0x38430006, 0x2c630001, 0x38420011,
-0x2c420001, 0x621825, 0x1060007f, 0x24020800,
-0x8821, 0x97a3003e, 0x1462000f, 0x2602021,
-0x96710000, 0x96620002, 0x96630004, 0x96640006,
-0x2228821, 0x2238821, 0x2248821, 0x96620008,
-0x9663000a, 0x9664000c, 0x2228821, 0x2238821,
-0x10000007, 0x2248821, 0x94820000, 0x24840002,
-0x2228821, 0x92102b, 0x1440fffb, 0x0,
-0x111c02, 0x3222ffff, 0x628821, 0x111c02,
-0x3222ffff, 0x628821, 0x32c20200, 0x10400003,
-0x26440006, 0x1000003e, 0x8021, 0x3c05001f,
-0x34a5ffff, 0xa4102b, 0x10400003, 0x0,
-0x8f420148, 0x822023, 0x94820000, 0x30421fff,
-0x10400004, 0x2644000c, 0x96420002, 0x10000030,
-0x508023, 0x96420002, 0x26430014, 0x508023,
-0x3c020020, 0x43102b, 0x1440000a, 0xd08021,
-0x9642000c, 0x2028021, 0x9642000e, 0x96430010,
-0x96440012, 0x2028021, 0x2038021, 0x10000020,
-0x2048021, 0xa4102b, 0x10400003, 0x0,
-0x8f420148, 0x822023, 0x94820000, 0x24840002,
-0x2028021, 0xa4102b, 0x10400003, 0x0,
-0x8f420148, 0x822023, 0x94820000, 0x24840002,
-0x2028021, 0xa4102b, 0x10400003, 0x0,
-0x8f420148, 0x822023, 0x94820000, 0x24840002,
-0x2028021, 0xa4102b, 0x10400003, 0x0,
-0x8f420148, 0x822023, 0x94820000, 0x2028021,
-0x3c020100, 0x2c21024, 0x1040000e, 0x0,
-0x8faa002c, 0x31420004, 0x1040000a, 0x0,
-0x9504000e, 0x2642021, 0xc004445, 0x2484fffc,
-0x3042ffff, 0x2228821, 0x111c02, 0x3222ffff,
-0x628821, 0x8faa0024, 0x1518823, 0x111402,
-0x2228821, 0x2308821, 0x111402, 0x2228821,
-0x3231ffff, 0x52200001, 0x3411ffff, 0x8faa002c,
-0x354a0001, 0xafaa002c, 0xa6b10012, 0x97aa002e,
-0xa6aa000e, 0x8faa002c, 0x31420004, 0x10400002,
-0x24091000, 0x34098000, 0x8f480044, 0x8f4401a0,
-0x8f4501a4, 0xafa90010, 0x8f490044, 0x84140,
-0x1001821, 0xafa90014, 0x8f48000c, 0x2a03021,
-0x24070020, 0xafa80018, 0x8f48010c, 0x1021,
-0xa32821, 0xa3482b, 0x822021, 0x100f809,
-0x892021, 0x1440001f, 0x0, 0x8f820128,
-0x3c040001, 0x24847fe4, 0xafbe0014, 0xafa20010,
-0x8f860124, 0x8f870120, 0x3c050007, 0xc002d3b,
-0x34a59920, 0x3c040001, 0x24847f4c, 0x24020bfa,
-0xafa20010, 0xafa00014, 0x8f860144, 0x3c070001,
-0x24e77f98, 0xc002d3b, 0x3405dead, 0x8f82011c,
-0x34420002, 0xaf82011c, 0x8f820220, 0x34420004,
-0xaf820220, 0x8f820140, 0x3c030001, 0x431025,
-0xaf820140, 0x8f420368, 0x2442ffff, 0xaf420368,
-0x8f420044, 0x8f430088, 0x24420001, 0x431024,
-0xaf420044, 0x8faa0034, 0x8f440368, 0x24020001,
-0x15420006, 0x24020002, 0x8f42035c, 0x2442ffff,
-0xaf42035c, 0x1000004a, 0x8f42035c, 0x15420006,
-0x0, 0x8f420364, 0x2442ffff, 0xaf420364,
-0x10000043, 0x8f420364, 0x8f420360, 0x2442ffff,
-0xaf420360, 0x8f420360, 0x1000003d, 0x0,
-0x30621000, 0x10400005, 0x30628000, 0x8f420078,
-0x24420001, 0x10000036, 0xaf420078, 0x10400034,
-0x0, 0x8f420078, 0x24420001, 0xaf420078,
-0x8c030240, 0x43102b, 0x1440002d, 0x24070008,
-0x8f440168, 0x8f45016c, 0x8f430044, 0x8f48000c,
-0x8f860120, 0x24020040, 0xafa20010, 0xafa30014,
-0xafa80018, 0x8f42010c, 0x40f809, 0x24c6001c,
-0x14400011, 0x24020001, 0x3c010001, 0x370821,
-0xa02240f2, 0x8f820124, 0xafa20010, 0x8f820128,
-0x3c040001, 0x24847f44, 0xafa20014, 0x8f460044,
-0x8f870120, 0x3c050009, 0xc002d3b, 0x34a51300,
-0x1000000b, 0x0, 0x8f420304, 0x24420001,
-0xaf420304, 0x8f420304, 0x8f420044, 0xaf42007c,
-0x3c010001, 0x370821, 0xa02040f2, 0xaf400078,
-0x8f420318, 0x24420001, 0xaf420318, 0x8f420318,
-0x8fbf0060, 0x8fbe005c, 0x8fb50058, 0x8fb30054,
-0x8fb20050, 0x8fb1004c, 0x8fb00048, 0x3e00008,
-0x27bd0068, 0x3e00008, 0x0, 0x8f42013c,
-0xaf8200c0, 0x8f42013c, 0xaf8200c4, 0x8f42013c,
-0xaf8200c8, 0x8f420138, 0xaf8200d0, 0x8f420138,
-0xaf8200d4, 0x8f420138, 0x3e00008, 0xaf8200d8,
-0x27bdffe0, 0x27840208, 0x24050200, 0xafbf0018,
-0xc002dbf, 0x24060008, 0x8c020204, 0xaf820210,
-0xc004586, 0x0, 0x3c020002, 0x8c428668,
-0x30420002, 0x1040000e, 0x2021, 0x8c060248,
-0x24020002, 0x3c010002, 0xac22866c, 0xc005738,
-0x24050002, 0x2021, 0x8c060248, 0x24020001,
-0x3c010002, 0xac22866c, 0x10000011, 0x24050001,
-0x8c060248, 0x24020004, 0x3c010002, 0xac22866c,
-0xc005738, 0x24050004, 0x3c020002, 0x8c428668,
-0x30420001, 0x10400008, 0x24020001, 0x3c010002,
-0xac22866c, 0x2021, 0x24050001, 0x3c06601b,
-0xc005738, 0x0, 0x3c040002, 0x248480b0,
-0x8f420150, 0x8f430154, 0x3c050008, 0x8f460158,
-0x21640, 0x31940, 0x34630403, 0x431025,
-0x633c0, 0x461025, 0xaf82021c, 0xafa00010,
-0xafa00014, 0x8f86021c, 0x34a50200, 0xc002d3b,
-0x3821, 0x3c010002, 0xac208664, 0x3c010002,
-0xac20867c, 0x8fbf0018, 0x3e00008, 0x27bd0020,
-0x27bdffe0, 0x3c050008, 0x34a50300, 0xafbf0018,
-0xafa00010, 0xafa00014, 0x8f860200, 0x3c040002,
-0x248480bc, 0xc002d3b, 0x3821, 0x8f420410,
-0x24420001, 0xaf420410, 0x8f420410, 0x8fbf0018,
-0x3e00008, 0x27bd0020, 0x27bdffd8, 0xafbf0020,
-0xafb1001c, 0xafb00018, 0x8f4203a4, 0x24420001,
-0xaf4203a4, 0x8f4203a4, 0x8f900220, 0x8f8200e0,
-0xafa20010, 0x8f8200e4, 0xafa20014, 0x8f8600c4,
-0x8f8700c8, 0x3c040002, 0x248480c8, 0xc002d3b,
-0x2002821, 0x3c044000, 0x2041024, 0x504000bc,
-0x3c040100, 0x8f4203bc, 0x24420001, 0xaf4203bc,
-0x8f4203bc, 0x8f8700c4, 0x8f8300c8, 0x8f420148,
-0x671823, 0x43102b, 0x10400003, 0x0,
-0x8f420148, 0x621821, 0x10600005, 0x0,
-0x8f42014c, 0x43102b, 0x1040000d, 0x0,
-0x8f8200e0, 0x8f430124, 0xaf42011c, 0xaf430114,
-0x8f820220, 0x3c0308ff, 0x3463fffb, 0x431024,
-0x441025, 0xaf820220, 0x10000104, 0x0,
-0x8f820220, 0x3c0308ff, 0x3463ffff, 0x431024,
-0x34420004, 0xaf820220, 0x8f8200e0, 0x8f430124,
-0xaf42011c, 0xaf430114, 0x8f8600c8, 0x8f840120,
-0x8f830124, 0x10000005, 0x2821, 0x14620002,
-0x24620020, 0x27624800, 0x401821, 0x1064000c,
-0x30a200ff, 0x8c620018, 0x30420003, 0x1040fff7,
-0x27624fe0, 0x8f4203d0, 0x24050001, 0x24420001,
-0xaf4203d0, 0x8f4203d0, 0x8c660008, 0x30a200ff,
-0x1440005b, 0x0, 0x934205c4, 0x14400058,
-0x0, 0x8f8700c4, 0x8f8800e0, 0x8f8400e4,
-0x2402fff8, 0x1024024, 0x1041023, 0x218c3,
-0x4620001, 0x24630200, 0x10600005, 0x24020001,
-0x1062000a, 0x0, 0x10000021, 0x0,
-0x8f4203c0, 0xe03021, 0x24420001, 0xaf4203c0,
-0x8f4203c0, 0x10000042, 0x0, 0x8f4203c4,
-0x24420001, 0xaf4203c4, 0x8c860000, 0x8f420148,
-0x8f4303c4, 0xe61823, 0x43102b, 0x10400004,
-0x2c62233f, 0x8f420148, 0x621821, 0x2c62233f,
-0x14400033, 0x0, 0x8f42020c, 0x24420001,
-0xaf42020c, 0x8f42020c, 0xe03021, 0x24820008,
-0xaf8200e4, 0xaf8200e8, 0x10000029, 0x0,
-0x8f4203c8, 0x24420001, 0xaf4203c8, 0x8f4203c8,
-0x8c850000, 0x8f420148, 0xa71823, 0x43102b,
-0x10400003, 0x0, 0x8f420148, 0x621821,
-0x8f42014c, 0x43102b, 0x5440000b, 0xa03021,
-0x8f42020c, 0x24420001, 0xaf42020c, 0x8f42020c,
-0x24820008, 0xaf8200e4, 0x8f8400e4, 0xaf8400e8,
-0x1488ffeb, 0x0, 0x1488000d, 0x27623000,
-0x14820002, 0x2482fff8, 0x27623ff8, 0x94430006,
-0x3c02001f, 0x3442ffff, 0xc33021, 0x46102b,
-0x10400003, 0x0, 0x8f420148, 0xc23023,
-0xaf8600c8, 0x8f8300c4, 0x8f420148, 0xc31823,
-0x43102b, 0x10400003, 0x0, 0x8f420148,
-0x621821, 0x10600005, 0x0, 0x8f42014c,
-0x43102b, 0x1040000a, 0x3c02fdff, 0x8f820220,
-0x3c0308ff, 0x3463fffb, 0x431024, 0x3c034000,
-0x431025, 0xaf820220, 0x10000070, 0x0,
-0x8f4303cc, 0x3442ffff, 0x282a024, 0x24630001,
-0xaf4303cc, 0x8f4203cc, 0x10000068, 0x0,
-0x2041024, 0x1040000f, 0x3c110200, 0x8f4203a8,
-0x24420001, 0xaf4203a8, 0x8f4203a8, 0x8f820220,
-0x3c0308ff, 0x3463ffff, 0x431024, 0x441025,
-0xaf820220, 0xc00430b, 0x0, 0x10000057,
-0x0, 0x2111024, 0x50400009, 0x3c110400,
-0x8f4203ac, 0x24420001, 0xaf4203ac, 0x8f4203ac,
-0xc00430b, 0x0, 0x1000002e, 0x0,
-0x2111024, 0x10400033, 0x3c02b800, 0x8f830224,
-0x24021402, 0x1462001d, 0x3c050008, 0x3c040002,
-0x248480d4, 0xafa00010, 0xafa00014, 0x8f860224,
-0x34a50500, 0xc002d3b, 0x3821, 0x3c040002,
-0x248480a0, 0x240203b3, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070002, 0x24e780e0, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x8f4203b0,
-0x24420001, 0xaf4203b0, 0x8f4203b0, 0x8f820220,
-0x2002021, 0x34420002, 0xaf820220, 0xc0054be,
-0x0, 0x8f820220, 0x3c0308ff, 0x3463ffff,
-0x431024, 0x511025, 0xaf820220, 0x10000017,
-0x0, 0x2021024, 0x10400014, 0x240203c7,
-0x3c040002, 0x248480a0, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070002, 0x24e780e0, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x8fbf0020,
-0x8fb1001c, 0x8fb00018, 0x3e00008, 0x27bd0028,
-0x3e00008, 0x0, 0x3c020002, 0x8c42867c,
-0x27bdffb0, 0xafbf0048, 0xafbe0044, 0xafb50040,
-0xafb3003c, 0xafb20038, 0xafb10034, 0x1040000f,
-0xafb00030, 0x3c040002, 0x248480e8, 0x3c050008,
-0xafa00010, 0xafa00014, 0x8f860220, 0x34a50600,
-0x24020001, 0x3c010002, 0xac20867c, 0x3c010002,
-0xac228670, 0xc002d3b, 0x3821, 0x3c037fff,
-0x8c020268, 0x3463ffff, 0x3c04fdff, 0x431024,
-0xac020268, 0x8f420004, 0x3484ffff, 0x30420002,
-0x10400092, 0x284a024, 0x3c040600, 0x34842000,
-0x8f420004, 0x2821, 0x2403fffd, 0x431024,
-0xaf420004, 0xafa40020, 0x8f5e0018, 0x27aa0020,
-0x240200ff, 0x13c20002, 0xafaa002c, 0x27c50001,
-0x8c020228, 0xa09021, 0x1642000e, 0x1e38c0,
-0x8f42033c, 0x24420001, 0xaf42033c, 0x8f42033c,
-0x8c020228, 0x3c040002, 0x24848068, 0x3c050009,
-0xafa00014, 0xafa20010, 0x8fa60020, 0x1000006d,
-0x34a50500, 0xf71021, 0x8fa30020, 0x8fa40024,
-0xac4304c0, 0xac4404c4, 0x8f830054, 0x8f820054,
-0x247003e8, 0x2021023, 0x2c4203e9, 0x1040001b,
-0x9821, 0xe08821, 0x263504c0, 0x8f440178,
-0x8f45017c, 0x2201821, 0x240a0004, 0xafaa0010,
-0xafb20014, 0x8f48000c, 0x1021, 0x2f53021,
-0xafa80018, 0x8f48010c, 0x24070008, 0xa32821,
-0xa3482b, 0x822021, 0x100f809, 0x892021,
-0x54400006, 0x24130001, 0x8f820054, 0x2021023,
-0x2c4203e9, 0x1440ffe9, 0x0, 0x326200ff,
-0x54400017, 0xaf520018, 0x8f420378, 0x24420001,
-0xaf420378, 0x8f420378, 0x8f820120, 0x8faa002c,
-0xafa20010, 0x8f820124, 0x3c040002, 0x24848074,
-0x3c050009, 0xafa20014, 0x8d460000, 0x10000035,
-0x34a50600, 0x8f420308, 0x24130001, 0x24420001,
-0xaf420308, 0x8f420308, 0x1000001e, 0x326200ff,
-0x8f830054, 0x8f820054, 0x247003e8, 0x2021023,
-0x2c4203e9, 0x10400016, 0x9821, 0x3c150020,
-0x24110010, 0x8f42000c, 0x8f440160, 0x8f450164,
-0x8f860120, 0xafb10010, 0xafb20014, 0x551025,
-0xafa20018, 0x8f42010c, 0x24070008, 0x40f809,
-0x24c6001c, 0x1440ffe3, 0x0, 0x8f820054,
-0x2021023, 0x2c4203e9, 0x1440ffee, 0x0,
-0x326200ff, 0x14400011, 0x0, 0x8f420378,
-0x24420001, 0xaf420378, 0x8f420378, 0x8f820120,
-0x8faa002c, 0xafa20010, 0x8f820124, 0x3c040002,
-0x2484807c, 0x3c050009, 0xafa20014, 0x8d460000,
-0x34a50700, 0xc002d3b, 0x3c03821, 0x8f4202ec,
-0x24420001, 0xaf4202ec, 0x8f4202ec, 0x8fbf0048,
-0x8fbe0044, 0x8fb50040, 0x8fb3003c, 0x8fb20038,
-0x8fb10034, 0x8fb00030, 0x3e00008, 0x27bd0050,
-0x3c020002, 0x8c42867c, 0x27bdffe0, 0x1440000d,
-0xafbf0018, 0x3c040002, 0x248480f4, 0x3c050008,
-0xafa00010, 0xafa00014, 0x8f860220, 0x34a50700,
-0x24020001, 0x3c010002, 0xac22867c, 0xc002d3b,
-0x3821, 0x3c020004, 0x2c21024, 0x10400007,
-0x0, 0x8f820220, 0x3c0308ff, 0x3463ffff,
-0x431024, 0x34420008, 0xaf820220, 0x3c050002,
-0x8ca5866c, 0x24020001, 0x14a20007, 0x2021,
-0xc0058d7, 0x24050001, 0xac02026c, 0x8c03026c,
-0x10000006, 0x3c020007, 0xc0058d7, 0x2021,
-0xac020268, 0x8c030268, 0x3c020007, 0x621824,
-0x3c020002, 0x5062000d, 0x3c0205f5, 0x43102b,
-0x14400006, 0x3c020004, 0x3c020001, 0x10620009,
-0x3c020098, 0x1000000b, 0x0, 0x14620009,
-0x3c023b9a, 0x10000004, 0x3442ca00, 0x10000002,
-0x3442e100, 0x34429680, 0xaf4201fc, 0x8f4201fc,
-0xaee20064, 0x8fbf0018, 0x3e00008, 0x27bd0020,
-0x86102b, 0x50400001, 0x872023, 0xc41023,
-0x24843, 0x125102b, 0x1040001b, 0x91040,
-0x824021, 0x88102b, 0x10400007, 0x1821,
-0x94820000, 0x24840002, 0x621821, 0x88102b,
-0x1440fffb, 0x0, 0x602021, 0xc73023,
-0xa91023, 0x21040, 0xc22821, 0xc5102b,
-0x10400007, 0x1821, 0x94c20000, 0x24c60002,
-0x621821, 0xc5102b, 0x1440fffb, 0x0,
-0x1000000d, 0x832021, 0x51040, 0x822821,
-0x85102b, 0x10400007, 0x1821, 0x94820000,
-0x24840002, 0x621821, 0x85102b, 0x1440fffb,
-0x0, 0x602021, 0x41c02, 0x3082ffff,
-0x622021, 0x41c02, 0x3082ffff, 0x622021,
-0x3e00008, 0x3082ffff, 0x3e00008, 0x0,
-0x802821, 0x30a20001, 0x1040002b, 0x3c03001f,
-0x3463ffff, 0x24a20004, 0x62102b, 0x54400007,
-0x65102b, 0x90a20001, 0x90a40003, 0x90a30000,
-0x90a50002, 0x1000002a, 0x441021, 0x10400003,
-0x0, 0x8f420148, 0xa22823, 0x90a40000,
-0x24a50001, 0x65102b, 0x10400003, 0x0,
-0x8f420148, 0xa22823, 0x90a20000, 0x24a50001,
-0x21200, 0x822021, 0x65102b, 0x10400003,
-0x0, 0x8f420148, 0xa22823, 0x90a20000,
-0x24a50001, 0x822021, 0x65102b, 0x10400003,
-0x0, 0x8f420148, 0xa22823, 0x90a20000,
-0x1000002d, 0x21200, 0x3463ffff, 0x24a20004,
-0x62102b, 0x5440000a, 0x65102b, 0x90a20000,
-0x90a40002, 0x90a30001, 0x90a50003, 0x441021,
-0x21200, 0x651821, 0x10000020, 0x432021,
-0x10400003, 0x0, 0x8f420148, 0xa22823,
-0x90a20000, 0x24a50001, 0x22200, 0x65102b,
-0x10400003, 0x0, 0x8f420148, 0xa22823,
-0x90a20000, 0x24a50001, 0x822021, 0x65102b,
-0x10400003, 0x0, 0x8f420148, 0xa22823,
-0x90a20000, 0x24a50001, 0x21200, 0x822021,
-0x65102b, 0x10400003, 0x0, 0x8f420148,
-0xa22823, 0x90a20000, 0x822021, 0x41c02,
-0x3082ffff, 0x622021, 0x41c02, 0x3082ffff,
-0x622021, 0x3e00008, 0x3082ffff, 0x8f820220,
-0x34420002, 0xaf820220, 0x3c020002, 0x8c42a8b8,
-0x30424000, 0x10400054, 0x24040001, 0x8f820200,
-0x24067fff, 0x8f830200, 0x30450002, 0x2402fffd,
-0x621824, 0xaf830200, 0xaf840204, 0x8f830054,
-0x8f820054, 0x10000002, 0x24630001, 0x8f820054,
-0x621023, 0x2c420002, 0x1440fffc, 0x0,
-0x8f820224, 0x1444004d, 0x42040, 0xc4102b,
-0x1040fff1, 0x0, 0x8f820200, 0x451025,
-0xaf820200, 0x8f820220, 0x34428000, 0xaf820220,
-0x8f830054, 0x8f820054, 0x10000002, 0x24630001,
-0x8f820054, 0x621023, 0x2c420002, 0x1440fffc,
-0x0, 0x8f820220, 0x3c030004, 0x431024,
-0x1440000f, 0x0, 0x8f820220, 0x3c03ffff,
-0x34637fff, 0x431024, 0xaf820220, 0x8f830054,
-0x8f820054, 0x10000002, 0x24630001, 0x8f820054,
-0x621023, 0x2c420002, 0x1440fffc, 0x0,
-0x8f820220, 0x3c030004, 0x431024, 0x1440000d,
-0x0, 0x8f820220, 0x34428000, 0xaf820220,
-0x8f830054, 0x8f820054, 0x10000002, 0x24630001,
-0x8f820054, 0x621023, 0x2c420002, 0x1440fffc,
-0x0, 0x8f820220, 0x3c030004, 0x431024,
-0x1040001b, 0x1021, 0x8f830220, 0x24020001,
-0x10000015, 0x3c04f700, 0x8f820220, 0x3c04f700,
-0x441025, 0xaf820220, 0x8f820220, 0x2403fffd,
-0x431024, 0xaf820220, 0x8f820220, 0x3c030300,
-0x431024, 0x14400003, 0x0, 0x10000008,
-0x1021, 0x8f820220, 0x34420002, 0xaf820220,
-0x8f830220, 0x24020001, 0x641825, 0xaf830220,
-0x3e00008, 0x0, 0x27bdffe0, 0x2021,
-0x3c050100, 0x24020001, 0xafbf0018, 0xaf80021c,
-0xaf820200, 0xaf820220, 0x27625000, 0xaf8200c0,
-0x27625000, 0xaf8200c4, 0x27625000, 0xaf8200c8,
-0x27625000, 0xaf8200d0, 0x27625000, 0xaf8200d4,
-0x27625000, 0xaf8200d8, 0x27623000, 0xaf8200e0,
-0x27623000, 0xaf8200e4, 0x27623000, 0xaf8200e8,
-0x27622800, 0xaf8200f0, 0x27622800, 0xaf8200f4,
-0x27622800, 0xaf8200f8, 0x418c0, 0x24840001,
-0x3631021, 0xac453004, 0x3631021, 0xac403000,
-0x28820200, 0x1440fff9, 0x418c0, 0x2021,
-0x418c0, 0x24840001, 0x3631021, 0xac402804,
-0x3631021, 0xac402800, 0x28820100, 0x1440fff9,
-0x418c0, 0xaf80023c, 0x24030080, 0x24040100,
-0xac600000, 0x24630004, 0x64102b, 0x5440fffd,
-0xac600000, 0x8f830040, 0x3c02f000, 0x621824,
-0x3c025000, 0x1062000c, 0x43102b, 0x14400006,
-0x3c026000, 0x3c024000, 0x1062000c, 0x24020800,
-0x1000000e, 0x240202a9, 0x10620008, 0x24020800,
-0x1000000a, 0x240202a9, 0x24020700, 0x3c010002,
-0xac228680, 0x10000018, 0x0, 0x3c010002,
-0xac228680, 0x10000014, 0x0, 0x3c040002,
-0x248481c0, 0xafa20010, 0xafa00014, 0x8f860144,
-0x3c070002, 0x24e781d8, 0xc002d3b, 0x3405dead,
-0x8f82011c, 0x34420002, 0xaf82011c, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820140, 0x3c030001,
-0x431025, 0xaf820140, 0x8fbf0018, 0x3e00008,
-0x27bd0020, 0x3c020002, 0x8c428690, 0x27bdffd0,
-0xafbf002c, 0xafb20028, 0xafb10024, 0xafb00020,
-0x3c010002, 0xac208668, 0x10400005, 0x0,
-0xc0053c3, 0x0, 0x3c010002, 0xac208690,
-0x8f830054, 0x8f820054, 0x10000002, 0x24630064,
-0x8f820054, 0x621023, 0x2c420065, 0x1440fffc,
-0x0, 0xc0053de, 0x0, 0x24040001,
-0x2821, 0x27a60018, 0x34028000, 0xc004bdc,
-0xa7a20018, 0x8f830054, 0x8f820054, 0x10000002,
-0x24630064, 0x8f820054, 0x621023, 0x2c420065,
-0x1440fffc, 0x24040001, 0x24050001, 0xc004b9a,
-0x27a60018, 0x8f830054, 0x8f820054, 0x10000002,
-0x24630064, 0x8f820054, 0x621023, 0x2c420065,
-0x1440fffc, 0x24040001, 0x24050001, 0xc004b9a,
-0x27a60018, 0x8f830054, 0x8f820054, 0x10000002,
-0x24630064, 0x8f820054, 0x621023, 0x2c420065,
-0x1440fffc, 0x24040001, 0x3c060002, 0x24c687e0,
-0xc004b9a, 0x24050002, 0x8f830054, 0x8f820054,
-0x10000002, 0x24630064, 0x8f820054, 0x621023,
-0x2c420065, 0x1440fffc, 0x24040001, 0x24050003,
-0x3c100002, 0x261087e2, 0xc004b9a, 0x2003021,
-0x97a60018, 0x3c070002, 0x94e787e0, 0x3c040002,
-0x248481f0, 0xafa00014, 0x96020000, 0x3c05000d,
-0x34a50100, 0xc002d3b, 0xafa20010, 0x97a20018,
-0x10400050, 0x24036040, 0x96020000, 0x3042fff0,
-0x1443000d, 0x24020020, 0x3c030002, 0x946387e0,
-0x1462000c, 0x24027830, 0x24020003, 0x3c010002,
-0xac228668, 0x24020005, 0x3c010002, 0xac2287f0,
-0x10000041, 0x0, 0x3c030002, 0x946387e0,
-0x24027830, 0x1462000d, 0x24030010, 0x3c020002,
-0x944287e2, 0x3042fff0, 0x14430008, 0x24020003,
-0x3c010002, 0xac228668, 0x24020006, 0x3c010002,
-0xac2287f0, 0x10000030, 0x0, 0x3c020002,
-0x8c428668, 0x3c030002, 0x946387e0, 0x34420001,
-0x3c010002, 0xac228668, 0x24020015, 0x1462000b,
-0x0, 0x3c020002, 0x944287e2, 0x3042fff0,
-0x3843f420, 0x2c630001, 0x3842f430, 0x2c420001,
-0x621825, 0x1460001c, 0x24020003, 0x3c030002,
-0x946387e0, 0x24027810, 0x14620017, 0x24020002,
-0x3c020002, 0x944287e2, 0x3042fff0, 0x14400012,
-0x24020002, 0x10000010, 0x24020004, 0x3c020002,
-0x8c428668, 0x34420008, 0x3c010002, 0xac228668,
-0x1000005f, 0x24020004, 0x3c020002, 0x8c428668,
-0x34420004, 0x3c010002, 0xac228668, 0x100000af,
-0x0, 0x24020001, 0x3c010002, 0xac2287fc,
-0x3c020002, 0x8c428668, 0x30420002, 0x144000b2,
-0x3c09fff0, 0x24020e00, 0xaf820238, 0x8f840054,
-0x8f820054, 0x24030008, 0x3c010002, 0xac23866c,
-0x10000002, 0x248401f4, 0x8f820054, 0x821023,
-0x2c4201f5, 0x1440fffc, 0x3c0200c8, 0x344201fb,
-0xaf820238, 0x8f830054, 0x8f820054, 0x10000002,
-0x246301f4, 0x8f820054, 0x621023, 0x2c4201f5,
-0x1440fffc, 0x8021, 0x24120001, 0x24110009,
-0xc004a53, 0x0, 0x3c010002, 0xac328688,
-0xc004b1d, 0x0, 0x3c020002, 0x8c428688,
-0x1451fffb, 0x3c0200c8, 0x344201f6, 0xaf820238,
-0x8f830054, 0x8f820054, 0x10000002, 0x2463000a,
-0x8f820054, 0x621023, 0x2c42000b, 0x1440fffc,
-0x0, 0x8f820220, 0x24040001, 0x34420002,
-0xaf820220, 0x8f830200, 0x24057fff, 0x2402fffd,
-0x621824, 0xaf830200, 0xaf840204, 0x8f830054,
-0x8f820054, 0x10000002, 0x24630001, 0x8f820054,
-0x621023, 0x2c420002, 0x1440fffc, 0x0,
-0x8f820224, 0x14440005, 0x34028000, 0x42040,
-0xa4102b, 0x1040fff0, 0x34028000, 0x1082ff9f,
-0x26100001, 0x2e020014, 0x1440ffcd, 0x24020004,
-0x3c010002, 0xac22866c, 0x8021, 0x24120009,
-0x3c11ffff, 0x36313f7f, 0xc004a53, 0x0,
-0x24020001, 0x3c010002, 0xac228688, 0xc004b1d,
-0x0, 0x3c020002, 0x8c428688, 0x1452fffb,
-0x0, 0x8f820044, 0x511024, 0x34425080,
-0xaf820044, 0x8f830054, 0x8f820054, 0x10000002,
-0x2463000a, 0x8f820054, 0x621023, 0x2c42000b,
-0x1440fffc, 0x0, 0x8f820044, 0x511024,
-0x3442f080, 0xaf820044, 0x8f830054, 0x8f820054,
-0x10000002, 0x2463000a, 0x8f820054, 0x621023,
-0x2c42000b, 0x1440fffc, 0x0, 0x8f820220,
-0x3c03f700, 0x431025, 0xaf820220, 0x8f830054,
-0x8f820054, 0x10000002, 0x24630064, 0x8f820054,
-0x621023, 0x2c420065, 0x1440fffc, 0x0,
-0x8f820220, 0x24040001, 0x34420002, 0xaf820220,
-0x8f830200, 0x24057fff, 0x2402fffd, 0x621824,
-0xaf830200, 0xaf840204, 0x8f830054, 0x8f820054,
-0x10000002, 0x24630001, 0x8f820054, 0x621023,
-0x2c420002, 0x1440fffc, 0x0, 0x8f820224,
-0x14440005, 0x34028000, 0x42040, 0xa4102b,
-0x1040fff0, 0x34028000, 0x1082ff4f, 0x26100001,
-0x2e020064, 0x1440ffb0, 0x0, 0x3c020002,
-0x8c428668, 0x30420004, 0x14400007, 0x3c09fff0,
-0x8f820044, 0x3c03ffff, 0x34633f7f, 0x431024,
-0xaf820044, 0x3c09fff0, 0x3529bdc0, 0x3c060002,
-0x8cc68668, 0x3c040002, 0x248481f0, 0x24020001,
-0x3c010002, 0xac228670, 0x8f820054, 0x3c070002,
-0x8ce787fc, 0x3c030002, 0x946387e0, 0x3c080002,
-0x950887e2, 0x3c05000d, 0x34a50100, 0x3c010002,
-0xac20866c, 0x491021, 0x3c010002, 0xac2287ec,
-0xafa30010, 0xc002d3b, 0xafa80014, 0x8fbf002c,
-0x8fb20028, 0x8fb10024, 0x8fb00020, 0x3e00008,
-0x27bd0030, 0x27bdffe8, 0x3c050002, 0x8ca5866c,
-0x24060004, 0x24020001, 0x14a20014, 0xafbf0010,
-0x3c020002, 0x8c42a8bc, 0x30428000, 0x10400005,
-0x3c04000f, 0x3c030002, 0x8c6387fc, 0x10000005,
-0x34844240, 0x3c040004, 0x3c030002, 0x8c6387fc,
-0x348493e0, 0x24020005, 0x14620016, 0x0,
-0x3c04003d, 0x10000013, 0x34840900, 0x3c020002,
-0x8c42a8b8, 0x30428000, 0x10400005, 0x3c04001e,
-0x3c030002, 0x8c6387fc, 0x10000005, 0x34848480,
-0x3c04000f, 0x3c030002, 0x8c6387fc, 0x34844240,
-0x24020005, 0x14620003, 0x0, 0x3c04007a,
-0x34841200, 0x3c020002, 0x8c4287ec, 0x8f830054,
-0x441021, 0x431023, 0x44102b, 0x1440004e,
-0x0, 0x3c020002, 0x8c428674, 0x1440004a,
-0x0, 0x3c010002, 0xac208684, 0x10c00026,
-0x0, 0x3c090002, 0x8d298668, 0x24070001,
-0x3c044000, 0x3c080002, 0x2508a8bc, 0x250afffc,
-0x52842, 0x14a00002, 0x24c6ffff, 0x24050008,
-0xa91024, 0x10400011, 0x0, 0x14a70009,
-0x0, 0x8d020000, 0x441024, 0x1040000b,
-0x0, 0x3c010002, 0xac258684, 0x10000007,
-0x0, 0x8d420000, 0x441024, 0x10400003,
-0x0, 0x3c010002, 0xac278684, 0x3c020002,
-0x8c428684, 0x6182b, 0x2c420001, 0x431024,
-0x5440ffe4, 0x52842, 0x8f820054, 0x3c030002,
-0x8c638684, 0x3c010002, 0xac2287ec, 0x1060003b,
-0x24020005, 0x3c030002, 0x8c6387fc, 0x3c010002,
-0xac25866c, 0x14620012, 0x24020001, 0x3c020002,
-0x8c42a8b8, 0x3c032000, 0x34635000, 0x431024,
-0x14400006, 0x24020001, 0x3c010002, 0xac2087d8,
-0x3c010002, 0xac22866c, 0x24020001, 0x3c010002,
-0xac2286f0, 0x3c010002, 0xac228678, 0x24020001,
-0x3c010002, 0xac228670, 0x3c020002, 0x8c428684,
-0x1040001e, 0x0, 0x3c020002, 0x8c428670,
-0x10400008, 0x24020001, 0x3c010002, 0xac208670,
-0xaee204b8, 0x3c010002, 0xac2086e8, 0x3c010002,
-0xac2286a0, 0x8ee304b8, 0x24020008, 0x10620005,
-0x24020001, 0xc0047b3, 0x0, 0x1000000b,
-0x0, 0x3c030002, 0x8c63866c, 0x10620007,
-0x2402000e, 0x3c030002, 0x8c63a850, 0x10620003,
-0x0, 0xc0054be, 0x8f840220, 0x8fbf0010,
-0x3e00008, 0x27bd0018, 0x27bdffd8, 0x3c03fdff,
-0x3c040002, 0x8c84866c, 0x3c020002, 0x8c428694,
-0x3463ffff, 0x283a024, 0x14820006, 0xafbf0020,
-0x8ee304b8, 0x3c020002, 0x8c428698, 0x10620006,
-0x0, 0x8ee204b8, 0x3c010002, 0xac248694,
-0x3c010002, 0xac228698, 0x3c030002, 0x8c63866c,
-0x24020002, 0x106201cc, 0x2c620003, 0x10400005,
-0x24020001, 0x1062000a, 0x0, 0x1000027d,
-0x0, 0x24020004, 0x106200eb, 0x24020008,
-0x1062014e, 0x24020001, 0x10000276, 0x0,
-0x8ee204b8, 0x2443ffff, 0x2c620008, 0x10400273,
-0x31080, 0x3c010002, 0x220821, 0x8c228210,
-0x400008, 0x0, 0x3c030002, 0x8c6387fc,
-0x24020005, 0x14620012, 0x0, 0x3c020002,
-0x8c428678, 0x10400009, 0x24020003, 0xc004a53,
-0x0, 0x24020002, 0xaee204b8, 0x3c010002,
-0xac208678, 0x10000002, 0x0, 0xaee204b8,
-0x3c010002, 0xac20860c, 0x10000258, 0x0,
-0xc004a53, 0x0, 0x3c020002, 0x8c428678,
-0x3c010002, 0xac20860c, 0x144001a8, 0x24020002,
-0x100001f1, 0x24020007, 0x3c030002, 0x8c6387fc,
-0x24020005, 0x14620003, 0x24020001, 0x3c010002,
-0xac22869c, 0xc004c1d, 0x0, 0x3c030002,
-0x8c63869c, 0x100001a3, 0x24020011, 0x3c050002,
-0x8ca5866c, 0x3c060002, 0x8cc6a8bc, 0xc005738,
-0x2021, 0x24020005, 0x3c010002, 0xac208678,
-0x10000236, 0xaee204b8, 0x3c040002, 0x248481fc,
-0x3c05000f, 0x34a50100, 0x3021, 0x3821,
-0xafa00010, 0xc002d3b, 0xafa00014, 0x3c040002,
-0x248481c0, 0x240204b0, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070002, 0x24e781d8, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x10000217,
-0x0, 0x24040001, 0x2405001a, 0x8f820220,
-0x27a60018, 0x3c03f700, 0x431025, 0xaf820220,
-0xc004b9a, 0x0, 0x97a60018, 0x30c20200,
-0x104001a1, 0x3c05000c, 0x3c040002, 0x24848208,
-0x34a50111, 0x3c020002, 0x8c42866c, 0x3c030002,
-0x8c6387d8, 0x3821, 0xafa20010, 0xc002d3b,
-0xafa30014, 0x2021, 0x2821, 0xc005400,
-0x24064040, 0x1000018e, 0x24020002, 0x8f820220,
-0x3c030004, 0x431024, 0x14400197, 0x24020007,
-0x8f830054, 0x3c020002, 0x8c4287e4, 0x2463d8f0,
-0x431023, 0x2c422710, 0x14400003, 0x24020001,
-0x3c010002, 0xac228670, 0x3c020002, 0x8c42a8bc,
-0x30425000, 0x104001e5, 0x0, 0x8f820220,
-0x30428000, 0x1040019f, 0x0, 0x10000197,
-0x0, 0x3c050002, 0x8ca5866c, 0xc0058d7,
-0x2021, 0xc005b59, 0x2021, 0x3c030002,
-0x8c63a8b4, 0x46101d3, 0x24020001, 0x3c020008,
-0x621024, 0x10400006, 0x0, 0x8f820214,
-0x3c03ffff, 0x431024, 0x10000005, 0x3442251f,
-0x8f820214, 0x3c03ffff, 0x431024, 0x3442241f,
-0xaf820214, 0x8f820220, 0x3c030200, 0x34420002,
-0xaf820220, 0x24020008, 0xaee204b8, 0x8f820220,
-0x283a025, 0x3c030004, 0x431024, 0x14400016,
-0x0, 0x3c020002, 0x8c42a8bc, 0x30425000,
-0x1040000d, 0x0, 0x8f820220, 0x30428000,
-0x10400006, 0x0, 0x8f820220, 0x3c03ffff,
-0x34637fff, 0x10000003, 0x431024, 0x8f820220,
-0x34428000, 0xaf820220, 0x8f820220, 0x3c03f700,
-0x431025, 0xaf820220, 0x3c030002, 0x8c6387fc,
-0x24020005, 0x1462000a, 0x0, 0x3c020002,
-0x944287e2, 0x24429fbc, 0x2c420004, 0x10400004,
-0x24040018, 0x24050002, 0xc005400, 0x24060020,
-0xc0043c9, 0x0, 0x3c010002, 0xac2086ec,
-0x10000192, 0x0, 0x8ee204b8, 0x2443ffff,
-0x2c620008, 0x1040018d, 0x31080, 0x3c010002,
-0x220821, 0x8c228230, 0x400008, 0x0,
-0xc00430b, 0x0, 0x3c010002, 0xac208670,
-0xaf800204, 0x3c010002, 0xac20a8a0, 0xc004a53,
-0x0, 0x24020001, 0x3c010002, 0xac228688,
-0x1000010f, 0x24020002, 0xc004b1d, 0x0,
-0x3c030002, 0x8c638688, 0x100000d6, 0x24020009,
-0x3c020002, 0x8c42a8b8, 0x30424000, 0x10400004,
-0x0, 0x8f820044, 0x10000006, 0x3442f080,
-0x8f820044, 0x3c03ffff, 0x34633f7f, 0x431024,
-0x3442a080, 0xaf820044, 0x8f830054, 0x100000fc,
-0x24020004, 0x8f830054, 0x3c020002, 0x8c4287e4,
-0x2463d8f0, 0x431023, 0x2c422710, 0x1440015b,
-0x24020005, 0x100000c6, 0x0, 0x8f820220,
-0x3c03f700, 0x431025, 0xaf820220, 0xaf800204,
-0x3c010002, 0xac20a8a0, 0x100000e7, 0x0,
-0x8f830054, 0x3c020002, 0x8c4287e4, 0x2463fff6,
-0x431023, 0x2c42000a, 0x14400148, 0x24020007,
-0x100000e9, 0x0, 0xc0044a8, 0x0,
-0x10400140, 0x24020001, 0x8f820214, 0x3c03ffff,
-0x3c040002, 0x8c8487d8, 0x431024, 0x3442241f,
-0xaf820214, 0x24020008, 0x10800005, 0xaee204b8,
-0x3c020002, 0x8c428708, 0x1040004e, 0x24020001,
-0x8f820220, 0x3c030008, 0x431024, 0x10400054,
-0x3c020200, 0x10000063, 0x0, 0x8ee204b8,
-0x2443ffff, 0x2c620007, 0x10400128, 0x31080,
-0x3c010002, 0x220821, 0x8c228250, 0x400008,
-0x0, 0xc004b1d, 0x0, 0x3c030002,
-0x8c638688, 0x1000007f, 0x24020009, 0x3c020002,
-0x8c42a8b8, 0x30424000, 0x10400003, 0x3c0200c8,
-0x10000002, 0x344201f6, 0x344201fe, 0xaf820238,
-0x8f830054, 0x100000aa, 0x24020004, 0x8f830054,
-0x3c020002, 0x8c4287e4, 0x2463d8f0, 0x431023,
-0x2c422710, 0x14400109, 0x24020005, 0x10000074,
-0x0, 0x8f830054, 0x3c020002, 0x8c4287e4,
-0x2463fff6, 0x431023, 0x2c42000a, 0x144000ff,
-0x24020007, 0x100000a0, 0x0, 0xc0044a8,
-0x0, 0x104000f7, 0x24020001, 0x8f820214,
-0x3c03ffff, 0x3c040002, 0x8c8487d8, 0x431024,
-0x3442241f, 0xaf820214, 0x24020008, 0x1080000f,
-0xaee204b8, 0x3c020002, 0x8c428708, 0x1440000b,
-0x0, 0x8f820220, 0x34420002, 0xaf820220,
-0x24020001, 0x3c010002, 0xac22a850, 0xc0054be,
-0x8f840220, 0x10000017, 0x0, 0x8f820220,
-0x3c030008, 0x431024, 0x14400012, 0x3c020200,
-0x282a025, 0x2402000e, 0x3c010002, 0xac22a850,
-0xc005b59, 0x2021, 0x8f820220, 0x34420002,
-0xaf820220, 0xc0043c9, 0x0, 0x3c050002,
-0x8ca5866c, 0xc0058d7, 0x2021, 0x100000cb,
-0x0, 0x3c020002, 0x8c428708, 0x104000c7,
-0x0, 0x3c020002, 0x8c428704, 0x2442ffff,
-0x3c010002, 0xac228704, 0x144000c0, 0x24020002,
-0x3c010002, 0xac208708, 0x3c010002, 0xac228704,
-0x100000ba, 0x0, 0x8ee204b8, 0x2443ffff,
-0x2c620007, 0x104000b5, 0x31080, 0x3c010002,
-0x220821, 0x8c228270, 0x400008, 0x0,
-0x3c020002, 0x8c428678, 0x10400019, 0x24020005,
-0xc004a53, 0x0, 0x24020002, 0xaee204b8,
-0x3c010002, 0xac208678, 0x100000a4, 0x0,
-0xc004f82, 0x0, 0x3c030002, 0x8c6386a0,
-0x24020006, 0x1462009d, 0x24020003, 0x1000009b,
-0xaee204b8, 0x3c050002, 0x8ca5866c, 0x3c060002,
-0x8cc6a8b8, 0xc005738, 0x2021, 0x24020005,
-0x10000092, 0xaee204b8, 0x24040001, 0x2405001a,
-0x8f820220, 0x27a60018, 0x3c03f700, 0x431025,
-0xaf820220, 0xc004b9a, 0x0, 0x97a60018,
-0x30c20200, 0x1040001c, 0x3c05000c, 0x3c040002,
-0x24848208, 0x34a50112, 0x3c020002, 0x8c42866c,
-0x3c030002, 0x8c6387d8, 0x3821, 0xafa20010,
-0xc002d3b, 0xafa30014, 0x2021, 0x2821,
-0xc005400, 0x24064040, 0x3c020002, 0x8c4287d8,
-0x10400006, 0x2021, 0x2821, 0xc005400,
-0x24061000, 0x1000006d, 0x0, 0x24020002,
-0x1000006a, 0xaee204b8, 0x8f830054, 0x24020006,
-0xaee204b8, 0x3c010002, 0xac2387e4, 0x10000063,
-0x0, 0x8f820220, 0x3c030004, 0x431024,
-0x10400003, 0x24020007, 0x1000005c, 0xaee204b8,
-0x8f830054, 0x3c020002, 0x8c4287e4, 0x2463d8f0,
-0x431023, 0x2c422710, 0x14400003, 0x24020001,
-0x3c010002, 0xac228670, 0x3c020002, 0x8c42a8b8,
-0x30425000, 0x1040004d, 0x0, 0x8f820220,
-0x30428000, 0x10400007, 0x0, 0x8f820220,
-0x3c03ffff, 0x34637fff, 0x431024, 0x10000043,
-0xaf820220, 0x8f820220, 0x34428000, 0xaf820220,
-0x1000003e, 0x0, 0x3c050002, 0x8ca5866c,
-0xc0058d7, 0x2021, 0xc005b59, 0x2021,
-0x3c020002, 0x8c42a8b0, 0x4410032, 0x24020001,
-0x8f820214, 0x3c03ffff, 0x431024, 0x3442241f,
-0xaf820214, 0x24020008, 0xaee204b8, 0x8f820220,
-0x34420002, 0xaf820220, 0x8f820220, 0x3c030004,
-0x431024, 0x14400016, 0x0, 0x3c020002,
-0x8c42a8b8, 0x30425000, 0x1040000d, 0x0,
-0x8f820220, 0x30428000, 0x10400006, 0x0,
-0x8f820220, 0x3c03ffff, 0x34637fff, 0x10000003,
-0x431024, 0x8f820220, 0x34428000, 0xaf820220,
-0x8f820220, 0x3c03f700, 0x431025, 0xaf820220,
-0x3c020002, 0x944287e2, 0x24429fbc, 0x2c420004,
-0x10400004, 0x24040018, 0x24050002, 0xc005400,
-0x24060020, 0xc0043c9, 0x0, 0x10000003,
-0x0, 0x3c010002, 0xac228670, 0x8fbf0020,
-0x3e00008, 0x27bd0028, 0x8f820200, 0x8f820220,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820200,
-0x3c050002, 0x8ca5866c, 0x34420004, 0xaf820200,
-0x24020002, 0x10a2004d, 0x2ca20003, 0x10400005,
-0x24020001, 0x10a2000a, 0x0, 0x100000b6,
-0x0, 0x24020004, 0x10a20075, 0x24020008,
-0x10a20089, 0x3c02f0ff, 0x100000af, 0x0,
-0x8f830050, 0x3c02f0ff, 0x3442ffff, 0x3c040002,
-0x8c8487fc, 0x621824, 0x3c020700, 0x621825,
-0x24020e00, 0x2484fffb, 0x2c840002, 0xaf830050,
-0xaf850200, 0xaf850220, 0xaf820238, 0x14800006,
-0x0, 0x8f820044, 0x3c03ffff, 0x34633f7f,
-0x431024, 0xaf820044, 0x3c030002, 0x8c6387fc,
-0x24020005, 0x14620004, 0x0, 0x8f820044,
-0x34425000, 0xaf820044, 0x3c020002, 0x8c42865c,
-0x3c030002, 0x8c6387fc, 0x34420022, 0x2463fffc,
-0x2c630002, 0xaf820200, 0x1460000c, 0x0,
-0x3c020002, 0x8c428680, 0x3c030002, 0x8c638664,
-0x3c040002, 0x8c848660, 0x34428000, 0x621825,
-0x641825, 0x1000000a, 0x34620002, 0x3c020002,
-0x8c428664, 0x3c030002, 0x8c638680, 0x3c040002,
-0x8c848660, 0x431025, 0x441025, 0x34420002,
-0xaf820220, 0x1000002f, 0x24020001, 0x24020e01,
-0xaf820238, 0x8f830050, 0x3c02f0ff, 0x3442ffff,
-0x3c040002, 0x8c8487d8, 0x621824, 0x3c020d00,
-0x621825, 0x24020001, 0xaf830050, 0xaf820200,
-0xaf820220, 0x10800005, 0x3c033f00, 0x3c020002,
-0x8c428654, 0x10000004, 0x34630070, 0x3c020002,
-0x8c428654, 0x34630072, 0x431025, 0xaf820200,
-0x3c030002, 0x8c638658, 0x3c02f700, 0x621825,
-0x3c020002, 0x8c428664, 0x3c040002, 0x8c848680,
-0x3c050002, 0x8ca587fc, 0x431025, 0x441025,
-0xaf820220, 0x24020005, 0x14a20006, 0x24020001,
-0x8f820044, 0x2403afff, 0x431024, 0xaf820044,
-0x24020001, 0xaf820238, 0x1000003f, 0x0,
-0x8f830050, 0x3c02f0ff, 0x3442ffff, 0x3c040002,
-0x8c8487d8, 0x621824, 0x3c020a00, 0x621825,
-0x24020001, 0xaf830050, 0xaf820200, 0xaf820220,
-0x1080001f, 0x0, 0x3c020002, 0x8c428708,
-0x1440001b, 0x3c033f00, 0x3c020002, 0x8c428654,
-0x1000001b, 0x346300e0, 0x8f830050, 0x3c040002,
-0x8c8487d8, 0x3442ffff, 0x621824, 0xaf830050,
-0x1080000f, 0x0, 0x3c020002, 0x8c428708,
-0x1440000b, 0x3c043f00, 0x3c030002, 0x8c638654,
-0x348400e0, 0x24020001, 0xaf820200, 0xaf820220,
-0x641825, 0xaf830200, 0x10000008, 0x3c05f700,
-0x3c020002, 0x8c428654, 0x3c033f00, 0x346300e2,
-0x431025, 0xaf820200, 0x3c05f700, 0x34a58000,
-0x3c030002, 0x8c638658, 0x3c020002, 0x8c428664,
-0x3c040002, 0x8c848680, 0x651825, 0x431025,
-0x441025, 0xaf820220, 0x3e00008, 0x0,
-0x3c030002, 0x8c638688, 0x3c020002, 0x8c42868c,
-0x27bdffe0, 0x10620003, 0xafbf0018, 0x3c010002,
-0xac23868c, 0x24020002, 0x1062003c, 0x2c620003,
-0x10400005, 0x24020001, 0x10620008, 0x24020004,
-0x10000055, 0x0, 0x24020009, 0x1062003f,
-0x240209e3, 0x10000050, 0x0, 0x3c030002,
-0x8c63866c, 0x10620008, 0x24020008, 0x14620010,
-0x240209ca, 0x3c0200c8, 0x344201fb, 0xaf820238,
-0x1000001e, 0x0, 0x24020e01, 0xaf820238,
-0x8f820044, 0x3c03ffff, 0x34633f7f, 0x431024,
-0x34420080, 0xaf820044, 0x10000014, 0x0,
-0x3c040002, 0x248481c0, 0xafa20010, 0xafa00014,
-0x8f860144, 0x3c070002, 0x24e781d8, 0xc002d3b,
-0x3405dead, 0x8f82011c, 0x34420002, 0xaf82011c,
-0x8f820220, 0x34420004, 0xaf820220, 0x8f820140,
-0x3c030001, 0x431025, 0xaf820140, 0x8f830054,
-0x24020002, 0x3c010002, 0xac228688, 0x3c010002,
-0xac2387e8, 0x10000034, 0x0, 0x8f830054,
-0x3c020002, 0x8c4287e8, 0x2463d8f0, 0x431023,
-0x2c422710, 0x1440002c, 0x24020009, 0x3c010002,
-0xac228688, 0x10000028, 0x0, 0x3c040002,
-0x248481c0, 0xafa20010, 0xafa00014, 0x8f860144,
-0x3c070002, 0x24e781d8, 0xc002d3b, 0x3405dead,
-0x8f82011c, 0x34420002, 0xaf82011c, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820140, 0x3c030001,
-0x431025, 0xaf820140, 0x3c040002, 0x248481c0,
-0x240209e9, 0xafa20010, 0xafa00014, 0x8f860144,
-0x3c070002, 0x24e781d8, 0xc002d3b, 0x3405dead,
-0x8f82011c, 0x34420002, 0xaf82011c, 0x8f820220,
-0x34420004, 0xaf820220, 0x8f820140, 0x3c030001,
-0x431025, 0xaf820140, 0x8fbf0018, 0x3e00008,
-0x27bd0020, 0x27bdffd8, 0xafb20018, 0x809021,
-0xafb3001c, 0xa09821, 0xafb10014, 0xc08821,
-0xafb00010, 0x8021, 0xafbf0020, 0xa6200000,
-0xc00539d, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc00539d, 0x2021,
-0xc00539d, 0x24040001, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x24100010, 0x2501024,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fffa, 0x2501024, 0x24100010,
-0x2701024, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fffa, 0x2701024,
-0xc0053de, 0x34108000, 0xc0053de, 0x0,
-0xc00537d, 0x0, 0x50400005, 0x108042,
-0x96220000, 0x501025, 0xa6220000, 0x108042,
-0x1600fff7, 0x0, 0xc0053de, 0x0,
-0x8fbf0020, 0x8fb3001c, 0x8fb20018, 0x8fb10014,
-0x8fb00010, 0x3e00008, 0x27bd0028, 0x27bdffd8,
-0xafb10014, 0x808821, 0xafb20018, 0xa09021,
-0xafb3001c, 0xc09821, 0xafb00010, 0x8021,
-0xafbf0020, 0xc00539d, 0x24040001, 0x26100001,
-0x2e020020, 0x1440fffb, 0x0, 0xc00539d,
-0x2021, 0xc00539d, 0x24040001, 0xc00539d,
-0x2021, 0xc00539d, 0x24040001, 0x24100010,
-0x2301024, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fffa, 0x2301024,
-0x24100010, 0x2501024, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x2501024, 0xc00539d, 0x24040001, 0xc00539d,
-0x2021, 0x34108000, 0x96620000, 0x501024,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fff8, 0x0, 0xc0053de,
-0x0, 0x8fbf0020, 0x8fb3001c, 0x8fb20018,
-0x8fb10014, 0x8fb00010, 0x3e00008, 0x27bd0028,
-0x3c040002, 0x8c84869c, 0x3c020002, 0x8c4286e4,
-0x27bdffd8, 0xafbf0020, 0xafb1001c, 0x10820003,
-0xafb00018, 0x3c010002, 0xac2486e4, 0x3c030002,
-0x8c6387fc, 0x24020005, 0x14620005, 0x2483ffff,
-0xc004f82, 0x0, 0x1000034d, 0x0,
-0x2c620013, 0x1040034a, 0x31080, 0x3c010002,
-0x220821, 0x8c2282a8, 0x400008, 0x0,
-0xc0053de, 0x8021, 0x34028000, 0xa7a20010,
-0x27b10010, 0xc00539d, 0x24040001, 0x26100001,
-0x2e020020, 0x1440fffb, 0x0, 0xc00539d,
-0x2021, 0xc00539d, 0x24040001, 0xc00539d,
-0x2021, 0xc00539d, 0x24040001, 0x24100010,
-0x32020001, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fffa, 0x32020001,
-0x24100010, 0xc00539d, 0x2021, 0x108042,
-0x1600fffc, 0x0, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x34108000, 0x96220000,
-0x501024, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fff8, 0x0,
-0xc0053de, 0x0, 0x1000030f, 0x24020002,
-0x27b10010, 0xa7a00010, 0x8021, 0xc00539d,
-0x24040001, 0x26100001, 0x2e020020, 0x1440fffb,
-0x0, 0xc00539d, 0x2021, 0xc00539d,
-0x24040001, 0xc00539d, 0x24040001, 0xc00539d,
-0x2021, 0x24100010, 0x32020001, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020001, 0x24100010, 0xc00539d,
-0x2021, 0x108042, 0x1600fffc, 0x0,
-0xc0053de, 0x34108000, 0xc0053de, 0x0,
-0xc00537d, 0x0, 0x50400005, 0x108042,
-0x96220000, 0x501025, 0xa6220000, 0x108042,
-0x1600fff7, 0x0, 0xc0053de, 0x0,
-0x97a20010, 0x30428000, 0x144002dd, 0x24020003,
-0x100002d9, 0x0, 0x24021200, 0xa7a20010,
-0x27b10010, 0x8021, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0x24100010, 0x32020001, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020001, 0x24100010, 0xc00539d, 0x2021,
-0x108042, 0x1600fffc, 0x0, 0xc00539d,
-0x24040001, 0xc00539d, 0x2021, 0x34108000,
-0x96220000, 0x501024, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fff8,
-0x0, 0xc0053de, 0x0, 0x8f830054,
-0x10000296, 0x24020004, 0x8f830054, 0x3c020002,
-0x8c4287f8, 0x2463ff9c, 0x431023, 0x2c420064,
-0x1440029f, 0x24020002, 0x3c030002, 0x8c6387fc,
-0x10620298, 0x2c620003, 0x14400297, 0x24020011,
-0x24020003, 0x10620005, 0x24020004, 0x10620292,
-0x2402000f, 0x10000290, 0x24020011, 0x1000028e,
-0x24020005, 0x24020014, 0xa7a20010, 0x27b10010,
-0x8021, 0xc00539d, 0x24040001, 0x26100001,
-0x2e020020, 0x1440fffb, 0x0, 0xc00539d,
-0x2021, 0xc00539d, 0x24040001, 0xc00539d,
-0x2021, 0xc00539d, 0x24040001, 0x24100010,
-0x32020001, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fffa, 0x32020001,
-0x24100010, 0x32020012, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020012, 0xc00539d, 0x24040001, 0xc00539d,
-0x2021, 0x34108000, 0x96220000, 0x501024,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fff8, 0x0, 0xc0053de,
-0x0, 0x8f830054, 0x10000248, 0x24020006,
-0x8f830054, 0x3c020002, 0x8c4287f8, 0x2463ff9c,
-0x431023, 0x2c420064, 0x14400251, 0x24020007,
-0x1000024d, 0x0, 0x24020006, 0xa7a20010,
-0x27b10010, 0x8021, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0x24100010, 0x32020001, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020001, 0x24100010, 0x32020013, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020013, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x34108000, 0x96220000,
-0x501024, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fff8, 0x0,
-0xc0053de, 0x0, 0x8f830054, 0x10000207,
-0x24020008, 0x8f830054, 0x3c020002, 0x8c4287f8,
-0x2463ff9c, 0x431023, 0x2c420064, 0x14400210,
-0x24020009, 0x1000020c, 0x0, 0x27b10010,
-0xa7a00010, 0x8021, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x24040001, 0xc00539d, 0x2021,
-0x24100010, 0x32020001, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020001, 0x24100010, 0x32020018, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020018, 0xc0053de, 0x34108000,
-0xc0053de, 0x0, 0xc00537d, 0x0,
-0x50400005, 0x108042, 0x96220000, 0x501025,
-0xa6220000, 0x108042, 0x1600fff7, 0x0,
-0xc0053de, 0x8021, 0x97a20010, 0x27b10010,
-0x34420001, 0xa7a20010, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0x24100010, 0x32020001, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020001, 0x24100010, 0x32020018, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020018, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x34108000, 0x96220000,
-0x501024, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fff8, 0x0,
-0xc0053de, 0x0, 0x8f830054, 0x10000193,
-0x2402000a, 0x8f830054, 0x3c020002, 0x8c4287f8,
-0x2463ff9c, 0x431023, 0x2c420064, 0x1440019c,
-0x2402000b, 0x10000198, 0x0, 0x27b10010,
-0xa7a00010, 0x8021, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x24040001, 0xc00539d, 0x2021,
-0x24100010, 0x32020001, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020001, 0x24100010, 0x32020017, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020017, 0xc0053de, 0x34108000,
-0xc0053de, 0x0, 0xc00537d, 0x0,
-0x50400005, 0x108042, 0x96220000, 0x501025,
-0xa6220000, 0x108042, 0x1600fff7, 0x0,
-0xc0053de, 0x8021, 0x97a20010, 0x27b10010,
-0x34420700, 0xa7a20010, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0x24100010, 0x32020001, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020001, 0x24100010, 0x32020017, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020017, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x34108000, 0x96220000,
-0x501024, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fff8, 0x0,
-0xc0053de, 0x0, 0x8f830054, 0x1000011f,
-0x2402000c, 0x8f830054, 0x3c020002, 0x8c4287f8,
-0x2463ff9c, 0x431023, 0x2c420064, 0x14400128,
-0x24020012, 0x10000124, 0x0, 0x27b10010,
-0xa7a00010, 0x8021, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x24040001, 0xc00539d, 0x2021,
-0x24100010, 0x32020001, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020001, 0x24100010, 0x32020014, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020014, 0xc0053de, 0x34108000,
-0xc0053de, 0x0, 0xc00537d, 0x0,
-0x50400005, 0x108042, 0x96220000, 0x501025,
-0xa6220000, 0x108042, 0x1600fff7, 0x0,
-0xc0053de, 0x8021, 0x97a20010, 0x27b10010,
-0x34420010, 0xa7a20010, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0x24100010, 0x32020001, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020001, 0x24100010, 0x32020014, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020014, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x34108000, 0x96220000,
-0x501024, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fff8, 0x0,
-0xc0053de, 0x0, 0x8f830054, 0x100000ab,
-0x24020013, 0x8f830054, 0x3c020002, 0x8c4287f8,
-0x2463ff9c, 0x431023, 0x2c420064, 0x144000b4,
-0x2402000d, 0x100000b0, 0x0, 0x27b10010,
-0xa7a00010, 0x8021, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x24040001, 0xc00539d, 0x2021,
-0x24100010, 0x32020001, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020001, 0x24100010, 0x32020018, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020018, 0xc0053de, 0x34108000,
-0xc0053de, 0x0, 0xc00537d, 0x0,
-0x50400005, 0x108042, 0x96220000, 0x501025,
-0xa6220000, 0x108042, 0x1600fff7, 0x0,
-0xc0053de, 0x8021, 0x97a20010, 0x27b10010,
-0x3042fffe, 0xa7a20010, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0x24100010, 0x32020001, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020001, 0x24100010, 0x32020018, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020018, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x34108000, 0x96220000,
-0x501024, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fff8, 0x0,
-0xc0053de, 0x0, 0x8f830054, 0x10000037,
-0x2402000e, 0x24020840, 0xa7a20010, 0x27b10010,
-0x8021, 0xc00539d, 0x24040001, 0x26100001,
-0x2e020020, 0x1440fffb, 0x0, 0xc00539d,
-0x2021, 0xc00539d, 0x24040001, 0xc00539d,
-0x2021, 0xc00539d, 0x24040001, 0x24100010,
-0x32020001, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fffa, 0x32020001,
-0x24100010, 0x32020013, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020013, 0xc00539d, 0x24040001, 0xc00539d,
-0x2021, 0x34108000, 0x96220000, 0x501024,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fff8, 0x0, 0xc0053de,
-0x0, 0x8f830054, 0x24020010, 0x3c010002,
-0xac22869c, 0x3c010002, 0xac2387f8, 0x1000000c,
-0x0, 0x8f830054, 0x3c020002, 0x8c4287f8,
-0x2463ff9c, 0x431023, 0x2c420064, 0x14400004,
-0x0, 0x24020011, 0x3c010002, 0xac22869c,
-0x8fbf0020, 0x8fb1001c, 0x8fb00018, 0x3e00008,
-0x27bd0028, 0x3c030002, 0x8c63866c, 0x27bdffc8,
-0x24020002, 0xafbf0034, 0xafb20030, 0xafb1002c,
-0x14620005, 0xafb00028, 0x3c120002, 0x8e52a8b8,
-0x10000003, 0x0, 0x3c120002, 0x8e52a8bc,
-0x3c030002, 0x8c6386a0, 0x3c020002, 0x8c4286e8,
-0x50620004, 0x2463ffff, 0x3c010002, 0xac2386e8,
-0x2463ffff, 0x2c620006, 0x1040037c, 0x31080,
-0x3c010002, 0x220821, 0x8c228300, 0x400008,
-0x0, 0x2021, 0x2821, 0xc005400,
-0x34068000, 0x24040010, 0x24050002, 0x24060002,
-0x24020002, 0xc005400, 0xa7a20018, 0x24020002,
-0x3c010002, 0xac2286a0, 0x10000368, 0x0,
-0x27b10018, 0xa7a00018, 0x8021, 0xc00539d,
-0x24040001, 0x26100001, 0x2e020020, 0x1440fffb,
-0x0, 0xc00539d, 0x2021, 0xc00539d,
-0x24040001, 0xc00539d, 0x24040001, 0xc00539d,
-0x2021, 0x24100010, 0x32020001, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020001, 0x24100010, 0xc00539d,
-0x2021, 0x108042, 0x1600fffc, 0x0,
-0xc0053de, 0x34108000, 0xc0053de, 0x0,
-0xc00537d, 0x0, 0x50400005, 0x108042,
-0x96220000, 0x501025, 0xa6220000, 0x108042,
-0x1600fff7, 0x0, 0xc0053de, 0x0,
-0x97a20018, 0x30428000, 0x14400004, 0x24020003,
-0x3c010002, 0xac2286a0, 0x24020003, 0x3c010002,
-0xac2286a0, 0x1000032d, 0x0, 0x24040010,
-0x24050002, 0x24060002, 0x24020002, 0xc005400,
-0xa7a20018, 0x3c030002, 0x8c6386ec, 0x24020001,
-0x146201e1, 0x8021, 0x27b10018, 0xa7a00018,
-0xc00539d, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc00539d, 0x2021,
-0xc00539d, 0x24040001, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x32020018, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fffa, 0x32020018,
-0xc0053de, 0x34108000, 0xc0053de, 0x0,
-0xc00537d, 0x0, 0x50400005, 0x108042,
-0x96220000, 0x501025, 0xa6220000, 0x108042,
-0x1600fff7, 0x0, 0xc0053de, 0x8021,
-0x27b10018, 0xa7a00018, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x24040001, 0xc00539d, 0x2021,
-0x24100010, 0x32020001, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020001, 0x24100010, 0x32020018, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020018, 0xc0053de, 0x34108000,
-0xc0053de, 0x0, 0xc00537d, 0x0,
-0x50400005, 0x108042, 0x96220000, 0x501025,
-0xa6220000, 0x108042, 0x1600fff7, 0x0,
-0xc0053de, 0x8021, 0x24040018, 0x2821,
-0xc005400, 0x24060404, 0xa7a0001a, 0xc00539d,
-0x24040001, 0x26100001, 0x2e020020, 0x1440fffb,
-0x0, 0xc00539d, 0x2021, 0xc00539d,
-0x24040001, 0xc00539d, 0x24040001, 0xc00539d,
-0x2021, 0x24100010, 0x32020001, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x32020001, 0x24100010, 0x32020018,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fffa, 0x32020018, 0xc0053de,
-0x34108000, 0xc0053de, 0x0, 0xc00537d,
-0x0, 0x50400005, 0x108042, 0x97a2001a,
-0x501025, 0xa7a2001a, 0x108042, 0x1600fff7,
-0x0, 0xc0053de, 0x8021, 0xa7a0001a,
-0xc00539d, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc00539d, 0x2021,
-0xc00539d, 0x24040001, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x32020018, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fffa, 0x32020018,
-0xc0053de, 0x34108000, 0xc0053de, 0x0,
-0xc00537d, 0x0, 0x50400005, 0x108042,
-0x97a2001a, 0x501025, 0xa7a2001a, 0x108042,
-0x1600fff7, 0x0, 0xc0053de, 0x8021,
-0xa7a0001c, 0xc00539d, 0x24040001, 0x26100001,
-0x2e020020, 0x1440fffb, 0x0, 0xc00539d,
-0x2021, 0xc00539d, 0x24040001, 0xc00539d,
-0x24040001, 0xc00539d, 0x2021, 0x24100010,
-0xc00539d, 0x2021, 0x108042, 0x1600fffc,
-0x0, 0x24100010, 0x3202001e, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fffa, 0x3202001e, 0xc0053de, 0x34108000,
-0xc0053de, 0x0, 0xc00537d, 0x0,
-0x50400005, 0x108042, 0x97a2001c, 0x501025,
-0xa7a2001c, 0x108042, 0x1600fff7, 0x0,
-0xc0053de, 0x8021, 0xa7a0001c, 0xc00539d,
-0x24040001, 0x26100001, 0x2e020020, 0x1440fffb,
-0x0, 0xc00539d, 0x2021, 0xc00539d,
-0x24040001, 0xc00539d, 0x24040001, 0xc00539d,
-0x2021, 0x24100010, 0xc00539d, 0x2021,
-0x108042, 0x1600fffc, 0x0, 0x24100010,
-0x3202001e, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fffa, 0x3202001e,
-0xc0053de, 0x34108000, 0xc0053de, 0x0,
-0xc00537d, 0x0, 0x50400005, 0x108042,
-0x97a2001c, 0x501025, 0xa7a2001c, 0x108042,
-0x1600fff7, 0x0, 0xc0053de, 0x8021,
-0x24020002, 0xa7a2001e, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0x24100010, 0xc00539d, 0x2021, 0x108042,
-0x1600fffc, 0x0, 0x24100010, 0x3202001e,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fffa, 0x3202001e, 0xc00539d,
-0x24040001, 0xc00539d, 0x2021, 0x34108000,
-0x97a2001e, 0x501024, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fff8,
-0x0, 0xc0053de, 0x8021, 0xa7a00020,
-0xc00539d, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc00539d, 0x2021,
-0xc00539d, 0x24040001, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x24100010, 0xc00539d,
-0x2021, 0x108042, 0x1600fffc, 0x0,
-0x24100010, 0x3202001e, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x3202001e, 0xc0053de, 0x34108000, 0xc0053de,
-0x0, 0xc00537d, 0x0, 0x50400005,
-0x108042, 0x97a20020, 0x501025, 0xa7a20020,
-0x108042, 0x1600fff7, 0x0, 0xc0053de,
-0x8021, 0xa7a00020, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x24040001, 0xc00539d, 0x2021,
-0x24100010, 0xc00539d, 0x2021, 0x108042,
-0x1600fffc, 0x0, 0x24100010, 0x3202001e,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fffa, 0x3202001e, 0xc0053de,
-0x34108000, 0xc0053de, 0x0, 0xc00537d,
-0x0, 0x50400005, 0x108042, 0x97a20020,
-0x501025, 0xa7a20020, 0x108042, 0x1600fff7,
-0x0, 0xc0053de, 0x8021, 0xa7a00022,
-0xc00539d, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc00539d, 0x2021,
-0xc00539d, 0x24040001, 0xc00539d, 0x2021,
-0xc00539d, 0x24040001, 0x24100010, 0xc00539d,
-0x2021, 0x108042, 0x1600fffc, 0x0,
-0x24100010, 0xc00539d, 0x2021, 0x108042,
-0x1600fffc, 0x0, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x34108000, 0x97a20022,
-0x501024, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fff8, 0x0,
-0xc0053de, 0x0, 0x24040018, 0x24050002,
-0xc005400, 0x24060004, 0x3c100002, 0x8e1086f0,
-0x24020001, 0x1602011e, 0x0, 0x3c020002,
-0x944287e2, 0x3c010002, 0xac2086f0, 0x24429fbc,
-0x2c420004, 0x1040000c, 0x24040009, 0x24050001,
-0xc005400, 0x24060400, 0x24040018, 0x24050001,
-0xc005400, 0x24060020, 0x24040018, 0x24050001,
-0xc005400, 0x24062000, 0x3c024000, 0x2421024,
-0x10400126, 0x3c022000, 0x2421024, 0x10400005,
-0x0, 0x3c010002, 0xac3087d8, 0x10000003,
-0x0, 0x3c010002, 0xac2087d8, 0x3c030002,
-0x8c6387f0, 0x24020005, 0x146200f9, 0x0,
-0x3c020002, 0x8c4287d8, 0x10400067, 0x3c020004,
-0x2421024, 0x10400011, 0xa7a00018, 0x3c020008,
-0x2421024, 0x10400002, 0x24020200, 0xa7a20018,
-0x3c020010, 0x2421024, 0x10400004, 0x0,
-0x97a20018, 0x34420100, 0xa7a20018, 0x97a60018,
-0x24040009, 0x10000004, 0x2821, 0x24040009,
-0x2821, 0x3021, 0xc005400, 0x0,
-0x24020001, 0xa7a2001a, 0x3c020008, 0x2421024,
-0x1040000c, 0x3c020002, 0x2421024, 0x10400002,
-0x24020101, 0xa7a2001a, 0x3c020001, 0x2421024,
-0x10400005, 0x3c020010, 0x97a2001a, 0x34420040,
-0xa7a2001a, 0x3c020010, 0x2421024, 0x1040000e,
-0x3c020002, 0x2421024, 0x10400005, 0x3c020001,
-0x97a2001a, 0x34420080, 0xa7a2001a, 0x3c020001,
-0x2421024, 0x10400005, 0x3c0300a0, 0x97a2001a,
-0x34420020, 0xa7a2001a, 0x3c0300a0, 0x2431024,
-0x54430004, 0x3c020020, 0x97a2001a, 0x1000000c,
-0x34420400, 0x2421024, 0x50400004, 0x3c020080,
-0x97a2001a, 0x10000006, 0x34420800, 0x2421024,
-0x10400004, 0x0, 0x97a2001a, 0x34420c00,
-0xa7a2001a, 0x97a6001a, 0x24040004, 0xc005400,
-0x2821, 0x3c020004, 0x2421024, 0x10400004,
-0xa7a0001c, 0x32425000, 0x14400004, 0x0,
-0x32424000, 0x10400005, 0x2021, 0xc00531e,
-0x2402021, 0x10000096, 0x0, 0x97a6001c,
-0x2821, 0x34c61200, 0xc005400, 0xa7a6001c,
-0x1000008f, 0x0, 0x2421024, 0x10400004,
-0xa7a00018, 0x32425000, 0x14400004, 0x0,
-0x32424000, 0x10400005, 0x3c020010, 0xc00531e,
-0x2402021, 0x10000019, 0xa7a0001a, 0x2421024,
-0x10400004, 0x0, 0x97a20018, 0x10000004,
-0xa7a20018, 0x97a20018, 0x34420100, 0xa7a20018,
-0x3c020001, 0x2421024, 0x10400004, 0x0,
-0x97a20018, 0x10000004, 0xa7a20018, 0x97a20018,
-0x34422000, 0xa7a20018, 0x97a60018, 0x2021,
-0xc005400, 0x2821, 0xa7a0001a, 0x8021,
-0xc00539d, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc00539d, 0x2021,
-0xc00539d, 0x24040001, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0xc00539d, 0x2021, 0x108042, 0x1600fffc,
-0x0, 0xc0053de, 0x34108000, 0xc0053de,
-0x0, 0xc00537d, 0x0, 0x50400005,
-0x108042, 0x97a2001a, 0x501025, 0xa7a2001a,
-0x108042, 0x1600fff7, 0x0, 0xc0053de,
-0x8021, 0xa7a0001a, 0xc00539d, 0x24040001,
-0x26100001, 0x2e020020, 0x1440fffb, 0x0,
-0xc00539d, 0x2021, 0xc00539d, 0x24040001,
-0xc00539d, 0x24040001, 0xc00539d, 0x2021,
-0x24100010, 0x32020001, 0x10400002, 0x2021,
-0x24040001, 0xc00539d, 0x108042, 0x1600fffa,
-0x32020001, 0x24100010, 0xc00539d, 0x2021,
-0x108042, 0x1600fffc, 0x0, 0xc0053de,
-0x34108000, 0xc0053de, 0x0, 0xc00537d,
-0x0, 0x50400005, 0x108042, 0x97a2001a,
-0x501025, 0xa7a2001a, 0x108042, 0x1600fff7,
-0x0, 0xc0053de, 0x0, 0x3c040002,
-0x248482f4, 0x97a60018, 0x97a7001a, 0x3c020002,
-0x8c42866c, 0x3c030002, 0x8c6387d8, 0x3c05000d,
-0x34a50205, 0xafa20010, 0xc002d3b, 0xafa30014,
-0x8f830054, 0x24020004, 0x3c010002, 0xac2286a0,
-0x3c010002, 0xac2387f4, 0x10000018, 0x0,
-0x8f830054, 0x3c020002, 0x8c4287f4, 0x2463ff9c,
-0x431023, 0x2c420064, 0x14400010, 0x0,
-0x8f820220, 0x24030005, 0x3c010002, 0xac2386a0,
-0x3c03f700, 0x431025, 0xaf820220, 0x10000007,
-0x0, 0x24020006, 0x3c010002, 0xac2286a0,
-0x24020011, 0x3c010002, 0xac22869c, 0x8fbf0034,
-0x8fb20030, 0x8fb1002c, 0x8fb00028, 0x3e00008,
-0x27bd0038, 0x27bdffd8, 0xafb00018, 0x808021,
-0xafb1001c, 0x8821, 0x32024000, 0x10400013,
-0xafbf0020, 0x3c020010, 0x2021024, 0x2c420001,
-0x21023, 0x30434100, 0x3c020001, 0x2021024,
-0x14400006, 0x34714000, 0x3c020002, 0x2021024,
-0x14400002, 0x34716000, 0x34714040, 0x2021,
-0x2821, 0x10000036, 0x2203021, 0x32021000,
-0x10400035, 0x2021, 0x2821, 0xc005400,
-0x24060040, 0x24040018, 0x2821, 0xc005400,
-0x24060c00, 0x24040017, 0x2821, 0xc005400,
-0x24060400, 0x24040016, 0x2821, 0xc005400,
-0x24060006, 0x24040017, 0x2821, 0xc005400,
-0x24062500, 0x24040016, 0x2821, 0xc005400,
-0x24060006, 0x24040017, 0x2821, 0xc005400,
-0x24064600, 0x24040016, 0x2821, 0xc005400,
-0x24060006, 0x24040017, 0x2821, 0xc005400,
-0x24066700, 0x24040016, 0x2821, 0xc005400,
-0x24060006, 0x2404001f, 0x2821, 0xc005400,
-0x24060010, 0x24040009, 0x2821, 0xc005400,
-0x24061500, 0x24040009, 0x2821, 0x24061d00,
-0xc005400, 0x0, 0x3c040002, 0x24848318,
-0x3c05000e, 0x34a50100, 0x2003021, 0x2203821,
-0xafa00010, 0xc002d3b, 0xafa00014, 0x8fbf0020,
-0x8fb1001c, 0x8fb00018, 0x3e00008, 0x27bd0028,
-0x8f850044, 0x8f820044, 0x3c030001, 0x431025,
-0x3c030008, 0xaf820044, 0x8f840054, 0x8f820054,
-0xa32824, 0x10000002, 0x24840001, 0x8f820054,
-0x821023, 0x2c420002, 0x1440fffc, 0x0,
-0x8f820044, 0x3c03fffe, 0x3463ffff, 0x431024,
-0xaf820044, 0x8f830054, 0x8f820054, 0x10000002,
-0x24630001, 0x8f820054, 0x621023, 0x2c420002,
-0x1440fffc, 0x0, 0x3e00008, 0xa01021,
-0x8f830044, 0x3c02fff0, 0x3442ffff, 0x42480,
-0x621824, 0x3c020002, 0x822025, 0x641825,
-0xaf830044, 0x8f820044, 0x3c03fffe, 0x3463ffff,
-0x431024, 0xaf820044, 0x8f830054, 0x8f820054,
-0x10000002, 0x24630001, 0x8f820054, 0x621023,
-0x2c420002, 0x1440fffc, 0x0, 0x8f820044,
-0x3c030001, 0x431025, 0xaf820044, 0x8f830054,
-0x8f820054, 0x10000002, 0x24630001, 0x8f820054,
-0x621023, 0x2c420002, 0x1440fffc, 0x0,
-0x3e00008, 0x0, 0x8f820044, 0x2403ff7f,
-0x431024, 0xaf820044, 0x8f830054, 0x8f820054,
-0x10000002, 0x24630001, 0x8f820054, 0x621023,
-0x2c420002, 0x1440fffc, 0x0, 0x8f820044,
-0x34420080, 0xaf820044, 0x8f830054, 0x8f820054,
-0x10000002, 0x24630001, 0x8f820054, 0x621023,
-0x2c420002, 0x1440fffc, 0x0, 0x3e00008,
-0x0, 0x8f820044, 0x3c03fff0, 0x3463ffff,
-0x431024, 0xaf820044, 0x8f820044, 0x3c030001,
-0x431025, 0xaf820044, 0x8f830054, 0x8f820054,
-0x10000002, 0x24630001, 0x8f820054, 0x621023,
-0x2c420002, 0x1440fffc, 0x0, 0x8f820044,
-0x3c03fffe, 0x3463ffff, 0x431024, 0xaf820044,
-0x8f830054, 0x8f820054, 0x10000002, 0x24630001,
-0x8f820054, 0x621023, 0x2c420002, 0x1440fffc,
-0x0, 0x3e00008, 0x0, 0x27bdffc8,
-0xafb30024, 0x809821, 0xafbe002c, 0xa0f021,
-0xafb20020, 0xc09021, 0x33c2ffff, 0xafbf0030,
-0xafb50028, 0xafb1001c, 0xafb00018, 0x14400034,
-0xa7b20010, 0x3271ffff, 0x27b20010, 0x8021,
-0xc00539d, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc00539d, 0x2021,
-0xc00539d, 0x24040001, 0xc00539d, 0x2021,
-0xc00539d, 0x24040001, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x2301024, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fffa, 0x2301024,
-0xc00539d, 0x24040001, 0xc00539d, 0x2021,
-0x34108000, 0x96420000, 0x501024, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x12000075, 0x0, 0x1000fff6, 0x0,
-0x3275ffff, 0x27b10010, 0xa7a00010, 0x8021,
-0xc00539d, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc00539d, 0x2021,
-0xc00539d, 0x24040001, 0xc00539d, 0x24040001,
-0xc00539d, 0x2021, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x2b01024, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fffa, 0x2b01024,
-0xc0053de, 0x34108000, 0xc0053de, 0x0,
-0xc00537d, 0x0, 0x50400005, 0x108042,
-0x96220000, 0x501025, 0xa6220000, 0x108042,
-0x1600fff7, 0x0, 0xc0053de, 0x0,
-0x33c5ffff, 0x24020001, 0x54a20004, 0x24020002,
-0x97a20010, 0x10000006, 0x521025, 0x14a20006,
-0x3271ffff, 0x97a20010, 0x121827, 0x431024,
-0xa7a20010, 0x3271ffff, 0x27b20010, 0x8021,
-0xc00539d, 0x24040001, 0x26100001, 0x2e020020,
-0x1440fffb, 0x0, 0xc00539d, 0x2021,
-0xc00539d, 0x24040001, 0xc00539d, 0x2021,
-0xc00539d, 0x24040001, 0x24100010, 0x32020001,
-0x10400002, 0x2021, 0x24040001, 0xc00539d,
-0x108042, 0x1600fffa, 0x32020001, 0x24100010,
-0x2301024, 0x10400002, 0x2021, 0x24040001,
-0xc00539d, 0x108042, 0x1600fffa, 0x2301024,
-0xc00539d, 0x24040001, 0xc00539d, 0x2021,
-0x34108000, 0x96420000, 0x501024, 0x10400002,
-0x2021, 0x24040001, 0xc00539d, 0x108042,
-0x1600fff8, 0x0, 0xc0053de, 0x0,
-0x8fbf0030, 0x8fbe002c, 0x8fb50028, 0x8fb30024,
-0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x3e00008,
-0x27bd0038, 0x27bdffe8, 0xafbf0010, 0x8ee304b8,
-0x24020008, 0x146201f1, 0x0, 0x3c020002,
-0x8c4287d8, 0x14400006, 0x0, 0x8f840224,
-0xc00430b, 0x0, 0x100001e8, 0x0,
-0x8f820220, 0x3c030008, 0x431024, 0x10400029,
-0x24020001, 0x8f840224, 0x8f820220, 0x3c030400,
-0x431024, 0x10400007, 0x0, 0x3c010002,
-0xac20a860, 0x3c010002, 0xac20a880, 0x1000000b,
-0x0, 0x3c030002, 0x2463a860, 0x8c620000,
-0x24420001, 0xac620000, 0x2c420002, 0x14400003,
-0x24020001, 0x3c010002, 0xac22a880, 0x3c020002,
-0x8c42a880, 0x10400007, 0x30820040, 0x10400005,
-0x24020001, 0x3c010002, 0xac22a884, 0x10000003,
-0x0, 0x3c010002, 0xac20a884, 0x3c010002,
-0xac24a85c, 0x3c010002, 0xac20a890, 0x1000000b,
-0x0, 0x3c010002, 0xac22a890, 0x3c010002,
-0xac20a880, 0x3c010002, 0xac20a860, 0x3c010002,
-0xac20a884, 0x3c010002, 0xac20a85c, 0x3c030002,
-0x8c63a850, 0x3c020002, 0x8c42a854, 0x50620004,
-0x2463ffff, 0x3c010002, 0xac23a854, 0x2463ffff,
-0x2c62000e, 0x104001a1, 0x31080, 0x3c010002,
-0x220821, 0x8c228338, 0x400008, 0x0,
-0x24020002, 0x3c010002, 0xac20a880, 0x3c010002,
-0xac20a860, 0x3c010002, 0xac20a85c, 0x3c010002,
-0xac20a884, 0x3c010002, 0xac20a878, 0x3c010002,
-0xac20a870, 0xaf800224, 0x3c010002, 0xac22a850,
-0x3c020002, 0x8c42a890, 0x14400053, 0x3c02fdff,
-0x3442ffff, 0xc00430b, 0x282a024, 0xaf800204,
-0x8f820200, 0x2403fffd, 0x431024, 0xaf820200,
-0x3c010002, 0xac20a8a0, 0x8f830054, 0x3c020002,
-0x8c42a878, 0x24040001, 0x3c010002, 0xac24a88c,
-0x24420001, 0x3c010002, 0xac22a878, 0x2c420004,
-0x3c010002, 0xac23a874, 0x14400007, 0x24020003,
-0x3c010002, 0xac248670, 0x3c010002, 0xac20a878,
-0x1000016a, 0x0, 0x3c010002, 0xac22a850,
-0x10000166, 0x0, 0x8f830054, 0x3c020002,
-0x8c42a874, 0x2463d8f0, 0x431023, 0x2c422710,
-0x14400003, 0x24020004, 0x3c010002, 0xac22a850,
-0x3c020002, 0x8c42a890, 0x14400023, 0x3c02fdff,
-0x3442ffff, 0x10000155, 0x282a024, 0x3c040002,
-0x8c8487dc, 0x3c010002, 0xac20a868, 0xc0056b7,
-0x0, 0x3c020002, 0x8c42a89c, 0xaf820204,
-0x3c020002, 0x8c42a890, 0x14400013, 0x3c03fdff,
-0x8f820204, 0x3463ffff, 0x30420030, 0x14400138,
-0x283a024, 0x3c030002, 0x8c63a89c, 0x24020005,
-0x3c010002, 0xac22a850, 0x3c010002, 0xac23a8a0,
-0x1000013a, 0x0, 0x3c020002, 0x8c42a890,
-0x10400011, 0x3c02fdff, 0x3c020002, 0x8c428700,
-0x24420001, 0x3c010002, 0xac228700, 0x2c420002,
-0x1440012e, 0x24020001, 0x3c010002, 0xac228708,
-0x3c010002, 0xac208700, 0x3c010002, 0xac228670,
-0x10000126, 0x0, 0x3c030002, 0x8c63a880,
-0x3442ffff, 0x10600121, 0x282a024, 0x3c020002,
-0x8c42a85c, 0x1040011d, 0x0, 0x3c010002,
-0xac22a888, 0x24020003, 0x3c010002, 0xac22a860,
-0x100000bd, 0x24020006, 0x3c010002, 0xac20a868,
-0x8f820204, 0x34420040, 0xaf820204, 0x3c020002,
-0x8c42a8a0, 0x24030007, 0x3c010002, 0xac23a850,
-0x34420040, 0x3c010002, 0xac22a8a0, 0x3c020002,
-0x8c42a880, 0x10400005, 0x0, 0x3c020002,
-0x8c42a85c, 0x104000f7, 0x24020002, 0x3c050002,
-0x24a5a860, 0x8ca20000, 0x2c424e21, 0x104000f1,
-0x24020002, 0x3c020002, 0x8c42a884, 0x104000f7,
-0x2404ffbf, 0x3c020002, 0x8c42a85c, 0x3c030002,
-0x8c63a888, 0x441024, 0x641824, 0x10430005,
-0x24020001, 0x3c010002, 0xac22a850, 0x100000eb,
-0x0, 0x24020003, 0xaca20000, 0x24020008,
-0x3c010002, 0xac22a850, 0x3c020002, 0x8c42a88c,
-0x1040000d, 0x24020001, 0x3c040002, 0x8c84a85c,
-0xc0056c4, 0x0, 0x3c020002, 0x8c42a8a8,
-0x14400005, 0x24020001, 0x3c020002, 0x8c42a8a4,
-0x10400007, 0x24020001, 0x3c010002, 0xac228670,
-0x3c010002, 0xac20a878, 0x100000d0, 0x0,
-0x3c020002, 0x8c42a870, 0x3c030002, 0x8c63a85c,
-0x2c420001, 0x210c0, 0x30630008, 0x3c010002,
-0xac22a870, 0x3c010002, 0xac23a86c, 0x8f830054,
-0x24020009, 0x3c010002, 0xac22a850, 0x3c010002,
-0xac23a874, 0x100000bd, 0x0, 0x8f830054,
-0x3c020002, 0x8c42a874, 0x2463d8f0, 0x431023,
-0x2c422710, 0x144000a2, 0x0, 0x3c020002,
-0x8c42a880, 0x10400005, 0x0, 0x3c020002,
-0x8c42a85c, 0x104000a3, 0x24020002, 0x3c030002,
-0x2463a860, 0x8c620000, 0x2c424e21, 0x1040009d,
-0x24020002, 0x3c020002, 0x8c42a88c, 0x1040000e,
-0x0, 0x3c020002, 0x8c42a85c, 0x3c010002,
-0xac20a88c, 0x30420080, 0x1040002f, 0x2402000c,
-0x8f820204, 0x30420080, 0x1440000c, 0x24020003,
-0x10000029, 0x2402000c, 0x3c020002, 0x8c42a85c,
-0x30420080, 0x14400005, 0x24020003, 0x8f820204,
-0x30420080, 0x1040001f, 0x24020003, 0xac620000,
-0x2402000a, 0x3c010002, 0xac22a850, 0x3c040002,
-0x2484a898, 0x8c820000, 0x3c030002, 0x8c63a870,
-0x431025, 0xaf820204, 0x8c830000, 0x3c040002,
-0x8c84a870, 0x2402000b, 0x3c010002, 0xac22a850,
-0x641825, 0x3c010002, 0xac23a8a0, 0x3c050002,
-0x24a5a860, 0x8ca20000, 0x2c424e21, 0x10400069,
-0x24020002, 0x3c020002, 0x8c42a890, 0x10400006,
-0x0, 0x2402000c, 0x3c010002, 0xac22a850,
-0x1000006a, 0x0, 0x3c020002, 0x8c42a880,
-0x10400066, 0x0, 0x3c040002, 0x8c84a85c,
-0x10800057, 0x30820008, 0x3c030002, 0x8c63a86c,
-0x1062005e, 0x24020003, 0x3c010002, 0xac24a888,
-0xaca20000, 0x24020006, 0x3c010002, 0xac22a850,
-0x10000056, 0x0, 0x8f820200, 0x34420002,
-0xaf820200, 0x8f830054, 0x2402000d, 0x3c010002,
-0xac22a850, 0x3c010002, 0xac23a874, 0x8f830054,
-0x3c020002, 0x8c42a874, 0x2463d8f0, 0x431023,
-0x2c422710, 0x14400032, 0x0, 0x3c020002,
-0x8c42a890, 0x10400021, 0x2402000e, 0x3c030002,
-0x8c63a8a4, 0x3c010002, 0xac22a850, 0x14600015,
-0x0, 0xc0043c9, 0x0, 0x3c050002,
-0x8ca5866c, 0xc0058d7, 0x2021, 0x3c030002,
-0x8c63866c, 0x24020004, 0x14620005, 0x2403fffb,
-0x3c020002, 0x8c428668, 0x10000003, 0x2403fff7,
-0x3c020002, 0x8c428668, 0x431024, 0x3c010002,
-0xac228668, 0x8f830224, 0x3c020200, 0x3c010002,
-0xac23a8ac, 0x10000021, 0x282a025, 0x3c020002,
-0x8c42a880, 0x10400005, 0x0, 0x3c020002,
-0x8c42a85c, 0x1040000f, 0x24020002, 0x3c020002,
-0x8c42a860, 0x2c424e21, 0x1040000a, 0x24020002,
-0x3c020002, 0x8c42a880, 0x10400010, 0x0,
-0x3c020002, 0x8c42a85c, 0x1440000c, 0x0,
-0x24020002, 0x3c010002, 0xac22a850, 0x10000007,
-0x0, 0x3c020002, 0x8c42a880, 0x10400003,
-0x0, 0xc00430b, 0x0, 0x8f820220,
-0x3c03f700, 0x431025, 0xaf820220, 0x8fbf0010,
-0x3e00008, 0x27bd0018, 0x3c030002, 0x2463a8a8,
-0x8c620000, 0x10400005, 0x34422000, 0x3c010002,
-0xac22a89c, 0x10000003, 0xac600000, 0x3c010002,
-0xac24a89c, 0x3e00008, 0x0, 0x27bdffe0,
-0x30820030, 0xafbf0018, 0x3c010002, 0xac22a8a4,
-0x1440006b, 0x3c02ffff, 0x34421f0e, 0x821024,
-0x14400065, 0x24020030, 0x30822000, 0x10400061,
-0x30838000, 0x31a02, 0x30820001, 0x21200,
-0x3c040002, 0x8c8487dc, 0x621825, 0x331c2,
-0x3c030002, 0x2463870c, 0x30828000, 0x21202,
-0x30840001, 0x42200, 0x441025, 0x239c2,
-0x61080, 0x431021, 0x471021, 0x90430000,
-0x24020001, 0x10620027, 0x0, 0x10600007,
-0x24020002, 0x10620014, 0x24020003, 0x1062002f,
-0x3c05000f, 0x1000003b, 0x0, 0x8f820200,
-0x2403feff, 0x431024, 0xaf820200, 0x8f820220,
-0x3c03fffe, 0x3463ffff, 0x431024, 0xaf820220,
-0x3c010002, 0xac20a8c4, 0x3c010002, 0xac20a8cc,
-0x10000037, 0x0, 0x8f820200, 0x34420100,
-0xaf820200, 0x8f820220, 0x3c03fffe, 0x3463ffff,
-0x431024, 0xaf820220, 0x24020100, 0x3c010002,
-0xac22a8c4, 0x3c010002, 0xac20a8cc, 0x10000028,
-0x0, 0x8f820200, 0x2403feff, 0x431024,
-0xaf820200, 0x8f820220, 0x3c030001, 0x431025,
-0xaf820220, 0x3c010002, 0xac20a8c4, 0x3c010002,
-0xac23a8cc, 0x1000001a, 0x0, 0x8f820200,
-0x34420100, 0xaf820200, 0x8f820220, 0x3c030001,
-0x431025, 0xaf820220, 0x24020100, 0x3c010002,
-0xac22a8c4, 0x3c010002, 0xac23a8cc, 0x1000000c,
-0x0, 0x34a5ffff, 0x3c040002, 0x24848370,
-0xafa30010, 0xc002d3b, 0xafa00014, 0x10000004,
-0x0, 0x24020030, 0x3c010002, 0xac22a8a8,
-0x8fbf0018, 0x3e00008, 0x27bd0020, 0x27bdffc8,
-0xafb20028, 0x809021, 0xafb3002c, 0xa09821,
-0xafb00020, 0xc08021, 0x3c040002, 0x24848398,
-0x3c050009, 0x3c020002, 0x8c42866c, 0x34a59001,
-0x2403021, 0x2603821, 0xafbf0030, 0xafb10024,
-0xa7a0001a, 0xafb00014, 0xc002d3b, 0xafa20010,
-0x24020002, 0x12620086, 0x2e620003, 0x10400005,
-0x24020001, 0x1262000a, 0x0, 0x1000017b,
-0x0, 0x24020004, 0x126200fc, 0x24020008,
-0x126200fb, 0x3c02ffec, 0x10000174, 0x0,
-0x3c020002, 0x8c428668, 0x30420002, 0x14400004,
-0x128940, 0x3c02fffb, 0x3442ffff, 0x2028024,
-0x3c010002, 0x310821, 0xac30a8bc, 0x3c024000,
-0x2021024, 0x10400050, 0x1023c2, 0x30840030,
-0x101382, 0x3042001c, 0x3c030002, 0x246386a4,
-0x431021, 0x823821, 0x3c020020, 0x2021024,
-0x10400006, 0x24020100, 0x3c010002, 0x310821,
-0xac22a8c0, 0x10000005, 0x3c020080, 0x3c010002,
-0x310821, 0xac20a8c0, 0x3c020080, 0x2021024,
-0x10400007, 0x121940, 0x3c020001, 0x3c010002,
-0x230821, 0xac22a8c8, 0x10000005, 0x0,
-0x121140, 0x3c010002, 0x220821, 0xac20a8c8,
-0x94e40000, 0x3c030002, 0x8c6387fc, 0x24020005,
-0x10620010, 0xa7a40018, 0x32024000, 0x10400002,
-0x34824000, 0xa7a20018, 0x24040001, 0x94e20002,
-0x24050004, 0x24e60002, 0x34420001, 0xc004bdc,
-0xa4e20002, 0x24040001, 0x2821, 0xc004bdc,
-0x27a60018, 0x3c020002, 0x8c42866c, 0x24110001,
-0x3c010002, 0xac318678, 0x14530004, 0x32028000,
-0xc00430b, 0x0, 0x32028000, 0x10400123,
-0x0, 0xc00430b, 0x0, 0x3c030002,
-0x8c6387fc, 0x24020005, 0x1062011c, 0x24020002,
-0x3c010002, 0xac318670, 0x3c010002, 0xac22866c,
-0x10000116, 0x0, 0x24040001, 0x24050004,
-0x27b0001a, 0xc004bdc, 0x2003021, 0x24040001,
-0x2821, 0xc004bdc, 0x2003021, 0x3c020002,
-0x511021, 0x8c42a8b4, 0x3c040002, 0x8c84866c,
-0x3c03bfff, 0x3463ffff, 0x3c010002, 0xac338678,
-0x431024, 0x3c010002, 0x310821, 0xac22a8b4,
-0x109300fc, 0x0, 0x100000fc, 0x0,
-0x3c022000, 0x2021024, 0x10400005, 0x24020001,
-0x3c010002, 0xac2287d8, 0x10000004, 0x128940,
-0x3c010002, 0xac2087d8, 0x128940, 0x3c010002,
-0x310821, 0xac30a8b8, 0x3c024000, 0x2021024,
-0x14400015, 0x0, 0x3c020002, 0x8c4287d8,
-0x10400006, 0x24040004, 0x24050001, 0xc005400,
-0x24062000, 0x24020001, 0xaee204b8, 0x3c020002,
-0x511021, 0x8c42a8b0, 0x3c03bfff, 0x3463ffff,
-0x431024, 0x3c010002, 0x310821, 0xac22a8b0,
-0x100000d4, 0x0, 0x3c020002, 0x8c4287d8,
-0x10400028, 0x3c0300a0, 0x2031024, 0x5443000d,
-0x3c020020, 0x3c020002, 0x8c4287dc, 0x24030100,
-0x3c010002, 0x310821, 0xac23a8c4, 0x3c030001,
-0x3c010002, 0x310821, 0xac23a8cc, 0x10000015,
-0x34420400, 0x2021024, 0x10400008, 0x24030100,
-0x3c020002, 0x8c4287dc, 0x3c010002, 0x310821,
-0xac23a8c4, 0x1000000b, 0x34420800, 0x3c020080,
-0x2021024, 0x1040002e, 0x3c030001, 0x3c020002,
-0x8c4287dc, 0x3c010002, 0x310821, 0xac23a8cc,
-0x34420c00, 0x3c010002, 0xac2287dc, 0x10000025,
-0x24040001, 0x3c020020, 0x2021024, 0x10400006,
-0x24020100, 0x3c010002, 0x310821, 0xac22a8c4,
-0x10000005, 0x3c020080, 0x3c010002, 0x310821,
-0xac20a8c4, 0x3c020080, 0x2021024, 0x10400007,
-0x121940, 0x3c020001, 0x3c010002, 0x230821,
-0xac22a8cc, 0x10000006, 0x24040001, 0x121140,
-0x3c010002, 0x220821, 0xac20a8cc, 0x24040001,
-0x2821, 0x27b0001e, 0xc004b9a, 0x2003021,
-0x24040001, 0x2821, 0xc004b9a, 0x2003021,
-0x24040001, 0x24050001, 0x27b0001c, 0xc004b9a,
-0x2003021, 0x24040001, 0x24050001, 0xc004b9a,
-0x2003021, 0x1000007b, 0x0, 0x3c02ffec,
-0x3442ffff, 0x2028024, 0x3c020008, 0x2028025,
-0x121140, 0x3c010002, 0x220821, 0xac30a8b8,
-0x3c022000, 0x2021024, 0x10400009, 0x0,
-0x3c020002, 0x8c428708, 0x14400005, 0x24020001,
-0x3c010002, 0xac2287d8, 0x10000004, 0x3c024000,
-0x3c010002, 0xac2087d8, 0x3c024000, 0x2021024,
-0x1440001d, 0x24020e01, 0x3c030002, 0x8c6387d8,
-0xaf820238, 0x3c010002, 0xac208684, 0x10600005,
-0x24022020, 0x3c010002, 0xac2287dc, 0x24020001,
-0xaee204b8, 0x3c04bfff, 0x121940, 0x3c020002,
-0x431021, 0x8c42a8b0, 0x3c050002, 0x8ca5866c,
-0x3484ffff, 0x441024, 0x3c010002, 0x230821,
-0xac22a8b0, 0x24020001, 0x10a20048, 0x0,
-0x10000044, 0x0, 0x3c020002, 0x8c4287d8,
-0x1040001f, 0x24022000, 0x3c010002, 0xac2287dc,
-0x3c0300a0, 0x2031024, 0x14430006, 0x121140,
-0x3402a000, 0x3c010002, 0xac2287dc, 0x10000030,
-0x0, 0x3c030002, 0x621821, 0x8c63a8b8,
-0x3c020020, 0x621024, 0x10400005, 0x24022001,
-0x3c010002, 0xac2287dc, 0x10000025, 0x0,
-0x3c020080, 0x621024, 0x10400021, 0x3402a001,
-0x3c010002, 0xac2287dc, 0x1000001d, 0x0,
-0x3c020020, 0x2021024, 0x10400007, 0x121940,
-0x24020100, 0x3c010002, 0x230821, 0xac22a8c4,
-0x10000006, 0x3c020080, 0x121140, 0x3c010002,
-0x220821, 0xac20a8c4, 0x3c020080, 0x2021024,
-0x10400007, 0x121940, 0x3c020001, 0x3c010002,
-0x230821, 0xac22a8cc, 0x10000005, 0x0,
-0x121140, 0x3c010002, 0x220821, 0xac20a8cc,
-0x3c030002, 0x8c63866c, 0x24020001, 0x10620003,
-0x0, 0xc00430b, 0x0, 0x8fbf0030,
-0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
-0x3e00008, 0x27bd0038, 0x27bdffb0, 0xafb3003c,
-0x9821, 0xafb50040, 0xa821, 0xafb10034,
-0x8821, 0x24020002, 0xafbf0048, 0xafbe0044,
-0xafb20038, 0xafb00030, 0xafa4002c, 0xa7a0001a,
-0xa7a00018, 0xa7a00020, 0xa7a0001e, 0xa7a00022,
-0x10a20131, 0xa7a0001c, 0x2ca20003, 0x10400005,
-0x24020001, 0x10a2000a, 0x3c024000, 0x1000025f,
-0x2201021, 0x24020004, 0x10a2020c, 0x24020008,
-0x10a2020a, 0x2201021, 0x10000258, 0x0,
-0x8fa8002c, 0x88140, 0x3c030002, 0x701821,
-0x8c63a8bc, 0x621024, 0x14400009, 0x24040001,
-0x3c027fff, 0x3442ffff, 0x628824, 0x3c010002,
-0x300821, 0xac31a8b4, 0x10000248, 0x2201021,
-0x24050001, 0xc004b9a, 0x27a60018, 0x24040001,
-0x24050001, 0xc004b9a, 0x27a60018, 0x97a20018,
-0x30420004, 0x104000da, 0x3c114000, 0x3c020002,
-0x8c4287fc, 0x2443ffff, 0x2c620006, 0x104000da,
-0x31080, 0x3c010002, 0x220821, 0x8c2283b0,
-0x400008, 0x0, 0x24040001, 0x24050011,
-0x27b0001a, 0xc004b9a, 0x2003021, 0x24040001,
-0x24050011, 0xc004b9a, 0x2003021, 0x97a3001a,
-0x30624000, 0x10400002, 0x3c150010, 0x3c150008,
-0x30628000, 0x104000ab, 0x3c130001, 0x100000a9,
-0x3c130002, 0x24040001, 0x24050014, 0x27b0001a,
-0xc004b9a, 0x2003021, 0x24040001, 0x24050014,
-0xc004b9a, 0x2003021, 0x97a3001a, 0x30621000,
-0x10400002, 0x3c150010, 0x3c150008, 0x30620800,
-0x10400098, 0x3c130001, 0x10000096, 0x3c130002,
-0x24040001, 0x24050019, 0x27b0001c, 0xc004b9a,
-0x2003021, 0x24040001, 0x24050019, 0xc004b9a,
-0x2003021, 0x97a2001c, 0x30430700, 0x24020400,
-0x10620027, 0x28620401, 0x1040000e, 0x24020200,
-0x1062001f, 0x28620201, 0x10400005, 0x24020100,
-0x5062001e, 0x3c130001, 0x1000001e, 0x24040001,
-0x24020300, 0x50620019, 0x3c130002, 0x10000019,
-0x24040001, 0x24020600, 0x1062000d, 0x28620601,
-0x10400005, 0x24020500, 0x5062000b, 0x3c130002,
-0x10000010, 0x24040001, 0x24020700, 0x1462000d,
-0x24040001, 0x3c130004, 0x1000000a, 0x3c150008,
-0x10000006, 0x3c130004, 0x10000005, 0x3c150008,
-0x3c130001, 0x10000002, 0x3c150008, 0x3c150010,
-0x24040001, 0x24050018, 0x27b0001e, 0xc004b9a,
-0x2003021, 0x24040001, 0x24050018, 0xc004b9a,
-0x2003021, 0x8fa8002c, 0x97a7001e, 0x81140,
-0x3c060002, 0xc23021, 0x8cc6a8b4, 0x97a20022,
-0x3c100002, 0x261083a4, 0x2002021, 0xafa20010,
-0x97a2001c, 0x3c05000c, 0x34a50303, 0xc002d3b,
-0xafa20014, 0x3c020004, 0x16620010, 0x3c020001,
-0x8f840054, 0x24030001, 0x24020002, 0x3c010002,
-0xac238670, 0x3c010002, 0xac22866c, 0x3c010002,
-0xac238678, 0x3c010002, 0xac2386f0, 0x3c010002,
-0xac2487ec, 0x10000050, 0x2b38825, 0x1662003a,
-0x3c028000, 0x3c020002, 0x8c4286ec, 0x1440001f,
-0x24040018, 0x2021, 0x2821, 0xc005400,
-0x34068000, 0x8f830054, 0x8f820054, 0x2b38825,
-0x10000002, 0x24630032, 0x8f820054, 0x621023,
-0x2c420033, 0x1440fffc, 0x0, 0x8f830054,
-0x24020001, 0x3c010002, 0xac2286ec, 0x3c010002,
-0xac228670, 0x3c010002, 0xac22866c, 0x3c010002,
-0xac228678, 0x3c010002, 0xac2286f0, 0x3c010002,
-0xac2387ec, 0x1000002c, 0x0, 0x2821,
-0xc005400, 0x24060404, 0x2021, 0x2405001e,
-0x27a60018, 0x24020002, 0xc004bdc, 0xa7a20018,
-0x2021, 0x2821, 0x27a60018, 0xc004bdc,
-0xa7a00018, 0x24040018, 0x24050002, 0xc005400,
-0x24060004, 0x3c028000, 0x2221025, 0x2b31825,
-0x10000015, 0x438825, 0x2221025, 0x2751825,
-0x438825, 0x2002021, 0x97a6001c, 0x3c070002,
-0x8ce7866c, 0x3c05000c, 0x34a50326, 0xafb30010,
-0xc002d3b, 0xafb10014, 0x10000007, 0x0,
-0x3c110002, 0x2308821, 0x8e31a8bc, 0x3c027fff,
-0x3442ffff, 0x2228824, 0x3c020002, 0x8c42867c,
-0x1040001e, 0x0, 0x3c020002, 0x8c4287d8,
-0x10400002, 0x3c022000, 0x2228825, 0x8fa8002c,
-0x81140, 0x3c010002, 0x220821, 0x8c22a8c0,
-0x10400003, 0x3c020020, 0x10000005, 0x2228825,
-0x3c02ffdf, 0x3442ffff, 0x2228824, 0x8fa8002c,
-0x81140, 0x3c010002, 0x220821, 0x8c22a8c8,
-0x10400003, 0x3c020080, 0x10000004, 0x2228825,
-0x3c02ff7f, 0x3442ffff, 0x2228824, 0x8fa8002c,
-0x81140, 0x3c010002, 0x220821, 0xac31a8b4,
-0x10000136, 0x2201021, 0x8fa8002c, 0x8f140,
-0x3c030002, 0x7e1821, 0x8c63a8b8, 0x3c024000,
-0x621024, 0x14400009, 0x24040001, 0x3c027fff,
-0x3442ffff, 0x628824, 0x3c010002, 0x3e0821,
-0xac31a8b0, 0x10000125, 0x2201021, 0x2821,
-0xc004b9a, 0x27a60018, 0x24040001, 0x2821,
-0xc004b9a, 0x27a60018, 0x24040001, 0x24050001,
-0x27b20020, 0xc004b9a, 0x2403021, 0x24040001,
-0x24050001, 0xc004b9a, 0x2403021, 0x24040001,
-0x24050004, 0x27b1001e, 0xc004b9a, 0x2203021,
-0x24040001, 0x24050004, 0xc004b9a, 0x2203021,
-0x24040001, 0x24050005, 0x27b00022, 0xc004b9a,
-0x2003021, 0x24040001, 0x24050005, 0xc004b9a,
-0x2003021, 0x24040001, 0x24050010, 0xc004b9a,
-0x27a60018, 0x24040001, 0x24050010, 0xc004b9a,
-0x27a60018, 0x24040001, 0x2405000a, 0xc004b9a,
-0x2403021, 0x24040001, 0x2405000a, 0xc004b9a,
-0x2403021, 0x24040001, 0x24050018, 0xc004b9a,
-0x2203021, 0x24040001, 0x24050018, 0xc004b9a,
-0x2203021, 0x24040001, 0x24050001, 0xc004b9a,
-0x27a60018, 0x24040001, 0x24050001, 0xc004b9a,
-0x27a60018, 0x97a20018, 0x30420004, 0x10400067,
-0x3c114000, 0x3c030002, 0x8c6387f0, 0x24020005,
-0x14620068, 0x24040001, 0x24050019, 0x27b0001c,
-0xc004b9a, 0x2003021, 0x24040001, 0x24050019,
-0xc004b9a, 0x2003021, 0x97a2001c, 0x30430700,
-0x24020400, 0x10620027, 0x28620401, 0x1040000e,
-0x24020200, 0x1062001f, 0x28620201, 0x10400005,
-0x24020100, 0x5062001e, 0x3c130001, 0x1000001e,
-0x3c020004, 0x24020300, 0x50620019, 0x3c130002,
-0x10000019, 0x3c020004, 0x24020600, 0x1062000d,
-0x28620601, 0x10400005, 0x24020500, 0x5062000b,
-0x3c130002, 0x10000010, 0x3c020004, 0x24020700,
-0x1462000d, 0x3c020004, 0x3c130004, 0x1000000a,
-0x3c150008, 0x10000006, 0x3c130004, 0x10000005,
-0x3c150008, 0x3c130001, 0x10000002, 0x3c150008,
-0x3c150010, 0x3c020004, 0x12620018, 0x3c028000,
-0x8f820054, 0x24100001, 0x3c010002, 0xac308670,
-0x3c010002, 0xac30866c, 0x3c010002, 0xac308678,
-0x3c010002, 0xac3086f0, 0x3c010002, 0xac2287ec,
-0x3c020001, 0x16620023, 0x2758825, 0x2021,
-0x2821, 0xc005400, 0x34068000, 0x3c010002,
-0xac3086ec, 0x1000001b, 0x0, 0x2221025,
-0x2b31825, 0x438825, 0x97a6001c, 0x3c020002,
-0x8c4287d8, 0x3c070002, 0x8ce7866c, 0x3c040002,
-0x248483a4, 0xafa20010, 0x97a2001e, 0x3c05000c,
-0x34a50323, 0x3c010002, 0xac2086ec, 0xc002d3b,
-0xafa20014, 0x10000007, 0x0, 0x3c110002,
-0x23e8821, 0x8e31a8b0, 0x3c027fff, 0x3442ffff,
-0x2228824, 0x3c020002, 0x8c42867c, 0x10400069,
-0x0, 0x3c020002, 0x8c4287d8, 0x10400002,
-0x3c022000, 0x2228825, 0x8fa8002c, 0x81140,
-0x3c010002, 0x220821, 0x8c22a8c4, 0x10400003,
-0x3c020020, 0x10000005, 0x2228825, 0x3c02ffdf,
-0x3442ffff, 0x2228824, 0x8fa8002c, 0x81140,
-0x3c010002, 0x220821, 0x8c22a8cc, 0x10400003,
-0x3c020080, 0x1000004f, 0x2228825, 0x3c02ff7f,
-0x3442ffff, 0x1000004b, 0x2228824, 0x8fa8002c,
-0x82940, 0x3c030002, 0x651821, 0x8c63a8b8,
-0x3c024000, 0x621024, 0x14400008, 0x3c027fff,
-0x3442ffff, 0x628824, 0x3c010002, 0x250821,
-0xac31a8b0, 0x10000041, 0x2201021, 0x3c020002,
-0x8c42867c, 0x10400034, 0x3c11c00c, 0x3c020002,
-0x8c428708, 0x3c04c00c, 0x34842000, 0x3c030002,
-0x8c6387d8, 0x2102b, 0x21023, 0x441024,
-0x10600003, 0x518825, 0x3c022000, 0x2228825,
-0x3c020002, 0x451021, 0x8c42a8c4, 0x10400003,
-0x3c020020, 0x10000004, 0x2228825, 0x3c02ffdf,
-0x3442ffff, 0x2228824, 0x8fa8002c, 0x81140,
-0x3c010002, 0x220821, 0x8c22a8cc, 0x10400003,
-0x3c020080, 0x10000004, 0x2228825, 0x3c02ff7f,
-0x3442ffff, 0x2228824, 0x3c020002, 0x8c4286f4,
-0x10400002, 0x3c020800, 0x2228825, 0x3c020002,
-0x8c4286f8, 0x10400002, 0x3c020400, 0x2228825,
-0x3c020002, 0x8c4286fc, 0x10400006, 0x3c020100,
-0x10000004, 0x2228825, 0x3c027fff, 0x3442ffff,
-0x628824, 0x8fa8002c, 0x81140, 0x3c010002,
-0x220821, 0xac31a8b0, 0x2201021, 0x8fbf0048,
-0x8fbe0044, 0x8fb50040, 0x8fb3003c, 0x8fb20038,
-0x8fb10034, 0x8fb00030, 0x3e00008, 0x27bd0050,
-0x27bdffd0, 0xafb20028, 0x809021, 0xafbf002c,
-0xafb10024, 0xafb00020, 0x8f840200, 0x3c100002,
-0x8e10866c, 0x8f860220, 0x24020002, 0x1202005e,
-0x2e020003, 0x10400005, 0x24020001, 0x1202000a,
-0x121940, 0x10000114, 0x0, 0x24020004,
-0x120200c6, 0x24020008, 0x120200c5, 0x128940,
-0x1000010d, 0x0, 0x3c050002, 0xa32821,
-0x8ca5a8bc, 0x3c100002, 0x2038021, 0x8e10a8b4,
-0x3c024000, 0xa21024, 0x10400038, 0x3c020008,
-0x2021024, 0x10400020, 0x34840002, 0x3c020002,
-0x431021, 0x8c42a8c0, 0x10400005, 0x34840020,
-0x34840100, 0x3c020020, 0x10000006, 0x2028025,
-0x2402feff, 0x822024, 0x3c02ffdf, 0x3442ffff,
-0x2028024, 0x121140, 0x3c010002, 0x220821,
-0x8c22a8c8, 0x10400005, 0x3c020001, 0xc23025,
-0x3c020080, 0x10000016, 0x2028025, 0x3c02fffe,
-0x3442ffff, 0xc23024, 0x3c02ff7f, 0x3442ffff,
-0x1000000f, 0x2028024, 0x2402fedf, 0x822024,
-0x3c02fffe, 0x3442ffff, 0xc23024, 0x3c02ff5f,
-0x3442ffff, 0x2028024, 0x3c010002, 0x230821,
-0xac20a8c0, 0x3c010002, 0x230821, 0xac20a8c8,
-0xaf840200, 0xaf860220, 0x8f820220, 0x34420002,
-0xaf820220, 0x1000000b, 0x121140, 0x3c02bfff,
-0x3442ffff, 0x8f830200, 0x2028024, 0x2402fffd,
-0x621824, 0xaf830200, 0xc00430b, 0x0,
-0x121140, 0x3c010002, 0x220821, 0xac30a8b4,
-0x100000bd, 0x0, 0x3c020002, 0x8c4287d8,
-0x1040006e, 0x24050004, 0x24040001, 0xc004b9a,
-0x27a60018, 0x24040001, 0x24050005, 0xc004b9a,
-0x27a6001a, 0x97a30018, 0x97a2001a, 0x3c040002,
-0x2484870c, 0x30630c00, 0x31a82, 0x30420c00,
-0x21282, 0xa7a2001a, 0x21080, 0x441021,
-0x431021, 0xa7a30018, 0x90480000, 0x24020001,
-0x3103ffff, 0x1062002b, 0x28620002, 0x10400005,
-0x0, 0x10600009, 0x0, 0x10000041,
-0x0, 0x10700014, 0x24020003, 0x1062002f,
-0x0, 0x1000003b, 0x0, 0x8f820200,
-0x2403feff, 0x431024, 0xaf820200, 0x8f820220,
-0x3c03fffe, 0x3463ffff, 0x431024, 0xaf820220,
-0x3c010002, 0xac20a8c4, 0x3c010002, 0xac20a8cc,
-0x10000035, 0x0, 0x8f820200, 0x34420100,
-0xaf820200, 0x8f820220, 0x3c03fffe, 0x3463ffff,
-0x431024, 0xaf820220, 0x24020100, 0x3c010002,
-0xac22a8c4, 0x3c010002, 0xac20a8cc, 0x10000026,
-0x0, 0x8f820200, 0x2403feff, 0x431024,
-0xaf820200, 0x8f820220, 0x3c030001, 0x431025,
-0xaf820220, 0x3c010002, 0xac20a8c4, 0x3c010002,
-0xac23a8cc, 0x10000018, 0x0, 0x8f820200,
-0x34420100, 0xaf820200, 0x8f820220, 0x3c030001,
-0x431025, 0xaf820220, 0x24020100, 0x3c010002,
-0xac22a8c4, 0x3c010002, 0xac23a8cc, 0x1000000a,
-0x0, 0x3c040002, 0x248483c8, 0x97a6001a,
-0x97a70018, 0x3c050001, 0x34a5ffff, 0xafa80010,
-0xc002d3b, 0xafa00014, 0x8f820200, 0x34420002,
-0xaf820200, 0x1000004c, 0x0, 0x128940,
-0x3c050002, 0xb12821, 0x8ca5a8b8, 0x3c100002,
-0x2118021, 0x8e10a8b0, 0x3c024000, 0xa21024,
-0x14400011, 0x0, 0x3c020002, 0x8c4287d8,
-0x14400005, 0x3c02bfff, 0x8f820200, 0x34420002,
-0xaf820200, 0x3c02bfff, 0x3442ffff, 0xc00430b,
-0x2028024, 0x3c010002, 0x310821, 0xac30a8b0,
-0x10000031, 0x0, 0x3c020002, 0x8c4287d8,
-0x10400005, 0x3c020020, 0x3c020002, 0x8c428708,
-0x10400025, 0x3c020020, 0xa21024, 0x10400007,
-0x34840020, 0x24020100, 0x3c010002, 0x310821,
-0xac22a8c4, 0x10000006, 0x34840100, 0x3c010002,
-0x310821, 0xac20a8c4, 0x2402feff, 0x822024,
-0x3c020080, 0xa21024, 0x10400007, 0x121940,
-0x3c020001, 0x3c010002, 0x230821, 0xac22a8cc,
-0x10000008, 0xc23025, 0x121140, 0x3c010002,
-0x220821, 0xac20a8cc, 0x3c02fffe, 0x3442ffff,
-0xc23024, 0xaf840200, 0xaf860220, 0x8f820220,
-0x34420002, 0xaf820220, 0x121140, 0x3c010002,
-0x220821, 0xac30a8b0, 0x8fbf002c, 0x8fb20028,
-0x8fb10024, 0x8fb00020, 0x3e00008, 0x27bd0030,
-0x1821, 0x308400ff, 0x2405ffdf, 0x2406ffbf,
-0x641007, 0x30420001, 0x10400004, 0x0,
-0x8f820044, 0x10000003, 0x34420040, 0x8f820044,
-0x461024, 0xaf820044, 0x8f820044, 0x34420020,
-0xaf820044, 0x8f820044, 0x451024, 0xaf820044,
-0x24630001, 0x28620008, 0x5440ffee, 0x641007,
-0x3e00008, 0x0, 0x2c820008, 0x1040001b,
-0x0, 0x2405ffdf, 0x2406ffbf, 0x41880,
-0x3c020002, 0x2442871c, 0x621821, 0x24640004,
-0x90620000, 0x10400004, 0x0, 0x8f820044,
-0x10000003, 0x34420040, 0x8f820044, 0x461024,
-0xaf820044, 0x8f820044, 0x34420020, 0xaf820044,
-0x8f820044, 0x451024, 0xaf820044, 0x24630001,
-0x64102b, 0x1440ffee, 0x0, 0x3e00008,
-0x0, 0x0 };
-static u_int32_t tigon2FwRodata[] = {
-0x24486561,
-0x6465723a, 0x202f7072, 0x6f6a6563, 0x74732f72,
-0x63732f73, 0x772f6765, 0x2f2e2f6e, 0x69632f66,
-0x77322f63, 0x6f6d6d6f, 0x6e2f6677, 0x6d61696e,
-0x2e632c76, 0x20312e31, 0x2e322e34, 0x35203139,
-0x39392f30, 0x312f3234, 0x2030303a, 0x31303a35,
-0x35207368, 0x75616e67, 0x20457870, 0x20240000,
-0x65767452, 0x6e674600, 0x51657674, 0x46000000,
-0x51657674, 0x505f4600, 0x4d657674, 0x526e6746,
-0x0, 0x4d516576, 0x74460000, 0x4d516576,
-0x505f4600, 0x5173436f, 0x6e495f46, 0x0,
-0x5173436f, 0x6e734600, 0x51725072, 0x6f644600,
-0x6261644d, 0x656d537a, 0x0, 0x2a50414e,
-0x49432a00, 0x66776d61, 0x696e2e63, 0x0,
-0x68775665, 0x72000000, 0x62616448, 0x77566572,
-0x0, 0x2a2a4441, 0x574e5f41, 0x0,
-0x74785278, 0x4266537a, 0x0, 0x62664174,
-0x6e4d726b, 0x0, 0x7265645a, 0x6f6e6531,
-0x0, 0x70636943, 0x6f6e6600, 0x67656e43,
-0x6f6e6600, 0x2a646d61, 0x5244666c, 0x0,
-0x72636246, 0x6c616773, 0x0, 0x62616452,
-0x78526362, 0x0, 0x676c6f62, 0x466c6773,
-0x0, 0x2b5f6469, 0x73705f6c, 0x6f6f7000,
-0x2b65765f, 0x68616e64, 0x6c657200, 0x63616e74,
-0x31446d61, 0x0, 0x2b715f64, 0x6d615f74,
-0x6f5f6e69, 0x635f636b, 0x73756d00, 0x2b685f73,
-0x656e645f, 0x64617461, 0x5f726561, 0x64795f63,
-0x6b73756d, 0x0, 0x2b685f64, 0x6d615f72,
-0x645f6173, 0x73697374, 0x5f636b73, 0x756d0000,
-0x74436b73, 0x6d4f6e00, 0x2b715f64, 0x6d615f74,
-0x6f5f6e69, 0x63000000, 0x2b685f73, 0x656e645f,
-0x64617461, 0x5f726561, 0x64790000, 0x2b685f64,
-0x6d615f72, 0x645f6173, 0x73697374, 0x0,
-0x74436b73, 0x6d4f6666, 0x0, 0x2b685f73,
-0x656e645f, 0x62645f72, 0x65616479, 0x0,
-0x68737453, 0x52696e67, 0x0, 0x62616453,
-0x52696e67, 0x0, 0x6e696353, 0x52696e67,
-0x0, 0x77446d61, 0x416c6c41, 0x0,
-0x2b715f64, 0x6d615f74, 0x6f5f686f, 0x73745f63,
-0x6b73756d, 0x0, 0x2b685f6d, 0x61635f72,
-0x785f636f, 0x6d705f63, 0x6b73756d, 0x0,
-0x2b685f64, 0x6d615f77, 0x725f6173, 0x73697374,
-0x5f636b73, 0x756d0000, 0x72436b73, 0x6d4f6e00,
-0x2b715f64, 0x6d615f74, 0x6f5f686f, 0x73740000,
-0x2b685f6d, 0x61635f72, 0x785f636f, 0x6d700000,
-0x2b685f64, 0x6d615f77, 0x725f6173, 0x73697374,
-0x0, 0x72436b73, 0x6d4f6666, 0x0,
-0x2b685f72, 0x6563765f, 0x62645f72, 0x65616479,
-0x0, 0x2b685f72, 0x6563765f, 0x6a756d62,
-0x6f5f6264, 0x5f726561, 0x64790000, 0x2b685f72,
-0x6563765f, 0x6d696e69, 0x5f62645f, 0x72656164,
-0x79000000, 0x2b6d685f, 0x636f6d6d, 0x616e6400,
-0x2b685f74, 0x696d6572, 0x0, 0x2b685f64,
-0x6f5f7570, 0x64617465, 0x5f74785f, 0x636f6e73,
-0x0, 0x2b685f64, 0x6f5f7570, 0x64617465,
-0x5f72785f, 0x70726f64, 0x0, 0x2b636b73,
-0x756d3136, 0x0, 0x2b706565, 0x6b5f6d61,
-0x635f7278, 0x5f776100, 0x2b706565, 0x6b5f6d61,
-0x635f7278, 0x0, 0x2b646571, 0x5f6d6163,
-0x5f727800, 0x2b685f6d, 0x61635f72, 0x785f6174,
-0x746e0000, 0x62616452, 0x6574537a, 0x0,
-0x72784264, 0x4266537a, 0x0, 0x2b6e756c,
-0x6c5f6861, 0x6e646c65, 0x72000000, 0x66774f70,
-0x4661696c, 0x0, 0x2b685f75, 0x70646174,
-0x655f6c65, 0x64340000, 0x2b685f75, 0x70646174,
-0x655f6c65, 0x64360000, 0x2b685f75, 0x70646174,
-0x655f6c65, 0x64320000, 0x696e7453, 0x74617465,
-0x0, 0x2a2a696e, 0x69744370, 0x0,
-0x23736372, 0x65616d00, 0x69537461, 0x636b4572,
-0x0, 0x70726f62, 0x654d656d, 0x0,
-0x2a2a4441, 0x574e5f42, 0x0, 0x2b73775f,
-0x646d615f, 0x61737369, 0x73745f70, 0x6c75735f,
-0x74696d65, 0x72000000, 0x2b267072, 0x656c6f61,
-0x645f7772, 0x5f646573, 0x63720000, 0x2b267072,
-0x656c6f61, 0x645f7264, 0x5f646573, 0x63720000,
-0x2b685f68, 0x665f7469, 0x6d657200, 0x24486561,
-0x6465723a, 0x202f7072, 0x6f6a6563, 0x74732f72,
-0x63732f73, 0x772f6765, 0x2f2e2f6e, 0x69632f66,
-0x77322f63, 0x6f6d6d6f, 0x6e2f7469, 0x6d65722e,
-0x632c7620, 0x312e312e, 0x322e3335, 0x20313939,
-0x392f3031, 0x2f323720, 0x31393a30, 0x393a3530,
-0x20686179, 0x65732045, 0x78702024, 0x0,
-0x65767452, 0x6e674600, 0x51657674, 0x46000000,
-0x51657674, 0x505f4600, 0x4d657674, 0x526e6746,
-0x0, 0x4d516576, 0x74460000, 0x4d516576,
-0x505f4600, 0x5173436f, 0x6e495f46, 0x0,
-0x5173436f, 0x6e734600, 0x51725072, 0x6f644600,
-0x2a50414e, 0x49432a00, 0x6d61632e, 0x68000000,
-0x74696d65, 0x722e6300, 0x542d446d, 0x61526432,
-0x0, 0x542d446d, 0x61526431, 0x0,
-0x542d446d, 0x61526442, 0x0, 0x542d446d,
-0x61577232, 0x0, 0x542d446d, 0x61577231,
-0x0, 0x542d446d, 0x61577242, 0x0,
-0x0, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x77322f63, 0x6f6d6d6f,
-0x6e2f636f, 0x6d6d616e, 0x642e632c, 0x7620312e,
-0x312e322e, 0x32382031, 0x3939392f, 0x30312f32,
-0x30203139, 0x3a34393a, 0x34392073, 0x6875616e,
-0x67204578, 0x70202400, 0x65767452, 0x6e674600,
-0x51657674, 0x46000000, 0x51657674, 0x505f4600,
-0x4d657674, 0x526e6746, 0x0, 0x4d516576,
-0x74460000, 0x4d516576, 0x505f4600, 0x5173436f,
-0x6e495f46, 0x0, 0x5173436f, 0x6e734600,
-0x51725072, 0x6f644600, 0x3f48636d, 0x644d6278,
-0x0, 0x3f636d64, 0x48737453, 0x0,
-0x3f636d64, 0x4d634d64, 0x0, 0x3f636d64,
-0x50726f6d, 0x0, 0x3f636d64, 0x4c696e6b,
-0x0, 0x3f636d64, 0x45727200, 0x8b08,
-0x92e4, 0x92e4, 0x9264, 0x8ff4,
-0x92b8, 0x92e4, 0x8bf4, 0x8c64,
-0x8df8, 0x8ee0, 0x8ea8, 0x92e4,
-0x8cd4, 0x8fa0, 0x92e4, 0x8fb0,
-0x8c18, 0x8c88, 0x24486561, 0x6465723a,
-0x202f7072, 0x6f6a6563, 0x74732f72, 0x63732f73,
-0x772f6765, 0x2f2e2f6e, 0x69632f66, 0x77322f63,
-0x6f6d6d6f, 0x6e2f6d63, 0x6173742e, 0x632c7620,
-0x312e312e, 0x322e3820, 0x31393938, 0x2f31322f,
-0x30382030, 0x323a3336, 0x3a333620, 0x73687561,
-0x6e672045, 0x78702024, 0x0, 0x65767452,
-0x6e674600, 0x51657674, 0x46000000, 0x51657674,
-0x505f4600, 0x4d657674, 0x526e6746, 0x0,
-0x4d516576, 0x74460000, 0x4d516576, 0x505f4600,
-0x5173436f, 0x6e495f46, 0x0, 0x5173436f,
-0x6e734600, 0x51725072, 0x6f644600, 0x6164644d,
-0x63447570, 0x0, 0x6164644d, 0x6346756c,
-0x0, 0x64656c4d, 0x634e6f45, 0x0,
-0x24486561, 0x6465723a, 0x202f7072, 0x6f6a6563,
-0x74732f72, 0x63732f73, 0x772f6765, 0x2f2e2f6e,
-0x69632f66, 0x77322f63, 0x6f6d6d6f, 0x6e2f646d,
-0x612e632c, 0x7620312e, 0x312e322e, 0x32342031,
-0x3939382f, 0x31322f32, 0x31203030, 0x3a33333a,
-0x30392073, 0x6875616e, 0x67204578, 0x70202400,
-0x65767452, 0x6e674600, 0x51657674, 0x46000000,
-0x51657674, 0x505f4600, 0x4d657674, 0x526e6746,
-0x0, 0x4d516576, 0x74460000, 0x4d516576,
-0x505f4600, 0x5173436f, 0x6e495f46, 0x0,
-0x5173436f, 0x6e734600, 0x51725072, 0x6f644600,
-0x7377446d, 0x614f6666, 0x0, 0x31446d61,
-0x4f6e0000, 0x7377446d, 0x614f6e00, 0x2a50414e,
-0x49432a00, 0x646d612e, 0x63000000, 0x2372446d,
-0x6141544e, 0x0, 0x72446d61, 0x41544e30,
-0x0, 0x72446d61, 0x41544e31, 0x0,
-0x72446d61, 0x34476200, 0x2377446d, 0x6141544e,
-0x0, 0x77446d61, 0x41544e30, 0x0,
-0x77446d61, 0x41544e31, 0x0, 0x77446d61,
-0x34476200, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x77322f63, 0x6f6d6d6f,
-0x6e2f7472, 0x6163652e, 0x632c7620, 0x312e312e,
-0x322e3520, 0x31393938, 0x2f30392f, 0x33302031,
-0x383a3530, 0x3a323820, 0x73687561, 0x6e672045,
-0x78702024, 0x0, 0x24486561, 0x6465723a,
-0x202f7072, 0x6f6a6563, 0x74732f72, 0x63732f73,
-0x772f6765, 0x2f2e2f6e, 0x69632f66, 0x77322f63,
-0x6f6d6d6f, 0x6e2f6461, 0x74612e63, 0x2c762031,
-0x2e312e32, 0x2e313220, 0x31393939, 0x2f30312f,
-0x32302031, 0x393a3439, 0x3a353120, 0x73687561,
-0x6e672045, 0x78702024, 0x0, 0x46575f56,
-0x45525349, 0x4f4e3a20, 0x58585800, 0x46575f43,
-0x4f4d5049, 0x4c455f54, 0x494d453a, 0x20585858,
-0x0, 0x46575f43, 0x4f4d5049, 0x4c455f42,
-0x593a2058, 0x58580000, 0x46575f43, 0x4f4d5049,
-0x4c455f48, 0x4f53543a, 0x20585858, 0x0,
-0x46575f43, 0x4f4d5049, 0x4c455f44, 0x4f4d4149,
-0x4e3a2058, 0x58580000, 0x46575f43, 0x4f4d5049,
-0x4c45523a, 0x20585858, 0x0, 0x0,
-0x12041100, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x77322f63, 0x6f6d6d6f,
-0x6e2f6d65, 0x6d2e632c, 0x7620312e, 0x312e322e,
-0x35203139, 0x39382f30, 0x392f3330, 0x2031383a,
-0x35303a30, 0x38207368, 0x75616e67, 0x20457870,
-0x20240000, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x77322f63, 0x6f6d6d6f,
-0x6e2f7365, 0x6e642e63, 0x2c762031, 0x2e312e32,
-0x2e343420, 0x31393938, 0x2f31322f, 0x32312030,
-0x303a3333, 0x3a313820, 0x73687561, 0x6e672045,
-0x78702024, 0x0, 0x65767452, 0x6e674600,
-0x51657674, 0x46000000, 0x51657674, 0x505f4600,
-0x4d657674, 0x526e6746, 0x0, 0x4d516576,
-0x74460000, 0x4d516576, 0x505f4600, 0x5173436f,
-0x6e495f46, 0x0, 0x5173436f, 0x6e734600,
-0x51725072, 0x6f644600, 0x2a50414e, 0x49432a00,
-0x6d61632e, 0x68000000, 0x73656e64, 0x2e630000,
-0x69736e74, 0x54637055, 0x0, 0x24486561,
-0x6465723a, 0x202f7072, 0x6f6a6563, 0x74732f72,
-0x63732f73, 0x772f6765, 0x2f2e2f6e, 0x69632f66,
-0x77322f63, 0x6f6d6d6f, 0x6e2f7265, 0x63762e63,
-0x2c762031, 0x2e312e32, 0x2e353320, 0x31393939,
-0x2f30312f, 0x31362030, 0x323a3535, 0x3a343320,
-0x73687561, 0x6e672045, 0x78702024, 0x0,
-0x65767452, 0x6e674600, 0x51657674, 0x46000000,
-0x51657674, 0x505f4600, 0x4d657674, 0x526e6746,
-0x0, 0x4d516576, 0x74460000, 0x4d516576,
-0x505f4600, 0x5173436f, 0x6e495f46, 0x0,
-0x5173436f, 0x6e734600, 0x51725072, 0x6f644600,
-0x2a50414e, 0x49432a00, 0x6d61632e, 0x68000000,
-0x724d6163, 0x43686b30, 0x0, 0x72784672,
-0x6d324c67, 0x0, 0x72784e6f, 0x53744264,
-0x0, 0x72784e6f, 0x4d694264, 0x0,
-0x72784e6f, 0x4a6d4264, 0x0, 0x72656376,
-0x2e630000, 0x7278436b, 0x446d6146, 0x0,
-0x72785144, 0x6d457846, 0x0, 0x72785144,
-0x6d614600, 0x72785144, 0x4c426446, 0x0,
-0x72785144, 0x6d426446, 0x0, 0x72784372,
-0x63506164, 0x0, 0x72536d51, 0x446d6146,
-0x0, 0x24486561, 0x6465723a, 0x202f7072,
-0x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
-0x2f2e2f6e, 0x69632f66, 0x77322f63, 0x6f6d6d6f,
-0x6e2f6d61, 0x632e632c, 0x7620312e, 0x312e322e,
-0x32322031, 0x3939382f, 0x31322f30, 0x38203032,
-0x3a33363a, 0x33302073, 0x6875616e, 0x67204578,
-0x70202400, 0x65767452, 0x6e674600, 0x51657674,
-0x46000000, 0x51657674, 0x505f4600, 0x4d657674,
-0x526e6746, 0x0, 0x4d516576, 0x74460000,
-0x4d516576, 0x505f4600, 0x5173436f, 0x6e495f46,
-0x0, 0x5173436f, 0x6e734600, 0x51725072,
-0x6f644600, 0x2a50414e, 0x49432a00, 0x6d61632e,
-0x68000000, 0x6d616354, 0x68726573, 0x0,
-0x23744d61, 0x6341544e, 0x0, 0x23724d61,
-0x6341544e, 0x0, 0x72656d41, 0x73737274,
-0x0, 0x6d61632e, 0x63000000, 0x6c696e6b,
-0x444f574e, 0x0, 0x6c696e6b, 0x55500000,
-0x24486561, 0x6465723a, 0x202f7072, 0x6f6a6563,
-0x74732f72, 0x63732f73, 0x772f6765, 0x2f2e2f6e,
-0x69632f66, 0x77322f63, 0x6f6d6d6f, 0x6e2f636b,
-0x73756d2e, 0x632c7620, 0x312e312e, 0x322e3920,
-0x31393939, 0x2f30312f, 0x31342030, 0x303a3033,
-0x3a343820, 0x73687561, 0x6e672045, 0x78702024,
-0x0, 0x65767452, 0x6e674600, 0x51657674,
-0x46000000, 0x51657674, 0x505f4600, 0x4d657674,
-0x526e6746, 0x0, 0x4d516576, 0x74460000,
-0x4d516576, 0x505f4600, 0x5173436f, 0x6e495f46,
-0x0, 0x5173436f, 0x6e734600, 0x51725072,
-0x6f644600, 0x2a50414e, 0x49432a00, 0x6d61632e,
-0x68000000, 0x2a50414e, 0x49432a00, 0x2e2e2f63,
-0x6f6d6d6f, 0x6e2f6d61, 0x632e6800, 0x2e2e2f2e,
-0x2e2f2e2e, 0x2f636f6d, 0x6d6f6e2f, 0x6c696e6b,
-0x2e630000, 0x50726f62, 0x65506879, 0x0,
-0x6c6e6b41, 0x53535254, 0x0, 0x6e6f4863,
-0x644c6b00, 0x11f8c, 0x1200c, 0x12040,
-0x1206c, 0x120e8, 0x12160, 0x121c8,
-0x12940, 0x12324, 0x1235c, 0x12374,
-0x123b8, 0x123e0, 0x12404, 0x1242c,
-0x12940, 0x12324, 0x124b8, 0x124d0,
-0x12500, 0x123e0, 0x12528, 0x12550,
-0x0, 0x12684, 0x126b4, 0x126d8,
-0x12940, 0x126fc, 0x127b8, 0x1284c,
-0x0, 0x2a50414e, 0x49432a00, 0x2e2e2f63,
-0x6f6d6d6f, 0x6e2f6d61, 0x632e6800, 0x130e4,
-0x131b4, 0x1328c, 0x1335c, 0x133b8,
-0x13494, 0x134bc, 0x13598, 0x135c0,
-0x13768, 0x13790, 0x13938, 0x13b30,
-0x13dc8, 0x13cd8, 0x13dc8, 0x13df4,
-0x13960, 0x13b08, 0x7273745f, 0x676d6969,
-0x0, 0x13e88, 0x13ec4, 0x13fb0,
-0x14c04, 0x14c48, 0x14c60, 0x7365746c,
-0x6f6f7000, 0x2a50414e, 0x49432a00, 0x2e2e2f63,
-0x6f6d6d6f, 0x6e2f6d61, 0x632e6800, 0x15454,
-0x15494, 0x1552c, 0x15570, 0x155dc,
-0x1566c, 0x156a0, 0x1572c, 0x157d0,
-0x158a0, 0x158e0, 0x1596c, 0x15990,
-0x15aa8, 0x646f4261, 0x73655067, 0x0,
-0x0, 0x2a50414e, 0x49432a00, 0x2e2e2f63,
-0x6f6d6d6f, 0x6e2f6d61, 0x632e6800, 0x73746d61,
-0x634c4e4b, 0x0, 0x6765746d, 0x636c6e6b,
-0x0, 0x167cc, 0x167cc, 0x1647c,
-0x164c8, 0x16514, 0x167cc, 0x7365746d,
-0x61636163, 0x74000000, 0x0 };
-static u_int32_t tigon2FwData[] = {
-0x1,
-0x1, 0x1, 0xc001fc, 0x3ffc,
-0xc00000, 0x416c7465, 0x6f6e2041, 0x63654e49,
-0x43205600, 0x0, 0x416c7465, 0x6f6e2041,
-0x63654e49, 0x43205600, 0x42424242, 0x1ffffc,
-0x1fff7c, 0x0, 0x0, 0x0,
-0x60cf00, 0x60, 0xcf000000, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x0, 0x0, 0x3,
-0x0, 0x1, 0x0, 0x0,
-0x0, 0x1, 0x0, 0x1,
-0x0, 0x0, 0x1, 0x1,
-0x0, 0x0, 0x0, 0x0,
-0x0, 0x1000000, 0x21000000, 0x12000140,
-0x0, 0x0, 0x20000000, 0x120000a0,
-0x0, 0x12000060, 0x12000180, 0x120001e0,
-0x0, 0x0, 0x0, 0x1,
-0x0, 0x0, 0x0, 0x0,
-0x2, 0x0, 0x0, 0x30001,
-0x1, 0x30201, 0x1010101, 0x1010100,
-0x10100, 0x1010001, 0x10001, 0x1000101,
-0x101, 0x0, 0x0 };
diff --git a/sys/dev/vr/if_vr.c b/sys/dev/vr/if_vr.c
deleted file mode 100644
index 2c6e93375708..000000000000
--- a/sys/dev/vr/if_vr.c
+++ /dev/null
@@ -1,1805 +0,0 @@
-/*
- * Copyright (c) 1997, 1998
- * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * VIA Rhine fast ethernet PCI NIC driver
- *
- * Supports various network adapters based on the VIA Rhine
- * and Rhine II PCI controllers, including the D-Link DFE530TX.
- * Datasheets are available at http://www.via.com.tw.
- *
- * Written by Bill Paul <wpaul@ctr.columbia.edu>
- * Electrical Engineering Department
- * Columbia University, New York City
- */
-
-/*
- * The VIA Rhine controllers are similar in some respects to the
- * the DEC tulip chips, except less complicated. The controller
- * uses an MII bus and an external physical layer interface. The
- * receiver has a one entry perfect filter and a 64-bit hash table
- * multicast filter. Transmit and receive descriptors are similar
- * to the tulip.
- *
- * The Rhine has a serious flaw in its transmit DMA mechanism:
- * transmit buffers must be longword aligned. Unfortunately,
- * FreeBSD doesn't guarantee that mbufs will be filled in starting
- * at longword boundaries, so we have to do a buffer copy before
- * transmission.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/sockio.h>
-#include <sys/mbuf.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/socket.h>
-
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/ethernet.h>
-#include <net/if_dl.h>
-#include <net/if_media.h>
-
-#include <net/bpf.h>
-
-#include <vm/vm.h> /* for vtophys */
-#include <vm/pmap.h> /* for vtophys */
-#include <machine/bus_pio.h>
-#include <machine/bus_memio.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/bus.h>
-#include <sys/rman.h>
-
-#include <dev/mii/mii.h>
-#include <dev/mii/miivar.h>
-
-#include <pci/pcireg.h>
-#include <pci/pcivar.h>
-
-#define VR_USEIOSPACE
-
-#include <pci/if_vrreg.h>
-
-MODULE_DEPEND(vr, pci, 1, 1, 1);
-MODULE_DEPEND(vr, ether, 1, 1, 1);
-MODULE_DEPEND(vr, miibus, 1, 1, 1);
-
-/* "controller miibus0" required. See GENERIC if you get errors here. */
-#include "miibus_if.h"
-
-#undef VR_USESWSHIFT
-
-/*
- * Various supported device vendors/types and their names.
- */
-static struct vr_type vr_devs[] = {
- { VIA_VENDORID, VIA_DEVICEID_RHINE,
- "VIA VT3043 Rhine I 10/100BaseTX" },
- { VIA_VENDORID, VIA_DEVICEID_RHINE_II,
- "VIA VT86C100A Rhine II 10/100BaseTX" },
- { VIA_VENDORID, VIA_DEVICEID_RHINE_II_2,
- "VIA VT6102 Rhine II 10/100BaseTX" },
- { VIA_VENDORID, VIA_DEVICEID_RHINE_III,
- "VIA VT6105 Rhine III 10/100BaseTX" },
- { VIA_VENDORID, VIA_DEVICEID_RHINE_III_M,
- "VIA VT6105M Rhine III 10/100BaseTX" },
- { DELTA_VENDORID, DELTA_DEVICEID_RHINE_II,
- "Delta Electronics Rhine II 10/100BaseTX" },
- { ADDTRON_VENDORID, ADDTRON_DEVICEID_RHINE_II,
- "Addtron Technology Rhine II 10/100BaseTX" },
- { 0, 0, NULL }
-};
-
-static int vr_probe (device_t);
-static int vr_attach (device_t);
-static int vr_detach (device_t);
-
-static int vr_newbuf (struct vr_softc *,
- struct vr_chain_onefrag *,
- struct mbuf *);
-static int vr_encap (struct vr_softc *, struct vr_chain *,
- struct mbuf * );
-
-static void vr_rxeof (struct vr_softc *);
-static void vr_rxeoc (struct vr_softc *);
-static void vr_txeof (struct vr_softc *);
-static void vr_txeoc (struct vr_softc *);
-static void vr_tick (void *);
-static void vr_intr (void *);
-static void vr_start (struct ifnet *);
-static int vr_ioctl (struct ifnet *, u_long, caddr_t);
-static void vr_init (void *);
-static void vr_stop (struct vr_softc *);
-static void vr_watchdog (struct ifnet *);
-static void vr_shutdown (device_t);
-static int vr_ifmedia_upd (struct ifnet *);
-static void vr_ifmedia_sts (struct ifnet *, struct ifmediareq *);
-
-#ifdef VR_USESWSHIFT
-static void vr_mii_sync (struct vr_softc *);
-static void vr_mii_send (struct vr_softc *, u_int32_t, int);
-#endif
-static int vr_mii_readreg (struct vr_softc *, struct vr_mii_frame *);
-static int vr_mii_writereg (struct vr_softc *, struct vr_mii_frame *);
-static int vr_miibus_readreg (device_t, int, int);
-static int vr_miibus_writereg (device_t, int, int, int);
-static void vr_miibus_statchg (device_t);
-
-static void vr_setcfg (struct vr_softc *, int);
-static u_int8_t vr_calchash (u_int8_t *);
-static void vr_setmulti (struct vr_softc *);
-static void vr_reset (struct vr_softc *);
-static int vr_list_rx_init (struct vr_softc *);
-static int vr_list_tx_init (struct vr_softc *);
-
-#ifdef VR_USEIOSPACE
-#define VR_RES SYS_RES_IOPORT
-#define VR_RID VR_PCI_LOIO
-#else
-#define VR_RES SYS_RES_MEMORY
-#define VR_RID VR_PCI_LOMEM
-#endif
-
-static device_method_t vr_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, vr_probe),
- DEVMETHOD(device_attach, vr_attach),
- DEVMETHOD(device_detach, vr_detach),
- DEVMETHOD(device_shutdown, vr_shutdown),
-
- /* bus interface */
- DEVMETHOD(bus_print_child, bus_generic_print_child),
- DEVMETHOD(bus_driver_added, bus_generic_driver_added),
-
- /* MII interface */
- DEVMETHOD(miibus_readreg, vr_miibus_readreg),
- DEVMETHOD(miibus_writereg, vr_miibus_writereg),
- DEVMETHOD(miibus_statchg, vr_miibus_statchg),
-
- { 0, 0 }
-};
-
-static driver_t vr_driver = {
- "vr",
- vr_methods,
- sizeof(struct vr_softc)
-};
-
-static devclass_t vr_devclass;
-
-DRIVER_MODULE(vr, pci, vr_driver, vr_devclass, 0, 0);
-DRIVER_MODULE(miibus, vr, miibus_driver, miibus_devclass, 0, 0);
-
-#define VR_SETBIT(sc, reg, x) \
- CSR_WRITE_1(sc, reg, \
- CSR_READ_1(sc, reg) | (x))
-
-#define VR_CLRBIT(sc, reg, x) \
- CSR_WRITE_1(sc, reg, \
- CSR_READ_1(sc, reg) & ~(x))
-
-#define VR_SETBIT16(sc, reg, x) \
- CSR_WRITE_2(sc, reg, \
- CSR_READ_2(sc, reg) | (x))
-
-#define VR_CLRBIT16(sc, reg, x) \
- CSR_WRITE_2(sc, reg, \
- CSR_READ_2(sc, reg) & ~(x))
-
-#define VR_SETBIT32(sc, reg, x) \
- CSR_WRITE_4(sc, reg, \
- CSR_READ_4(sc, reg) | (x))
-
-#define VR_CLRBIT32(sc, reg, x) \
- CSR_WRITE_4(sc, reg, \
- CSR_READ_4(sc, reg) & ~(x))
-
-#define SIO_SET(x) \
- CSR_WRITE_1(sc, VR_MIICMD, \
- CSR_READ_1(sc, VR_MIICMD) | (x))
-
-#define SIO_CLR(x) \
- CSR_WRITE_1(sc, VR_MIICMD, \
- CSR_READ_1(sc, VR_MIICMD) & ~(x))
-
-#ifdef VR_USESWSHIFT
-/*
- * Sync the PHYs by setting data bit and strobing the clock 32 times.
- */
-static void
-vr_mii_sync(sc)
- struct vr_softc *sc;
-{
- register int i;
-
- SIO_SET(VR_MIICMD_DIR|VR_MIICMD_DATAIN);
-
- for (i = 0; i < 32; i++) {
- SIO_SET(VR_MIICMD_CLK);
- DELAY(1);
- SIO_CLR(VR_MIICMD_CLK);
- DELAY(1);
- }
-
- return;
-}
-
-/*
- * Clock a series of bits through the MII.
- */
-static void
-vr_mii_send(sc, bits, cnt)
- struct vr_softc *sc;
- u_int32_t bits;
- int cnt;
-{
- int i;
-
- SIO_CLR(VR_MIICMD_CLK);
-
- for (i = (0x1 << (cnt - 1)); i; i >>= 1) {
- if (bits & i) {
- SIO_SET(VR_MIICMD_DATAIN);
- } else {
- SIO_CLR(VR_MIICMD_DATAIN);
- }
- DELAY(1);
- SIO_CLR(VR_MIICMD_CLK);
- DELAY(1);
- SIO_SET(VR_MIICMD_CLK);
- }
-}
-#endif
-
-/*
- * Read an PHY register through the MII.
- */
-static int
-vr_mii_readreg(sc, frame)
- struct vr_softc *sc;
- struct vr_mii_frame *frame;
-
-#ifdef VR_USESWSHIFT
-{
- int i, ack;
-
- VR_LOCK(sc);
-
- /*
- * Set up frame for RX.
- */
- frame->mii_stdelim = VR_MII_STARTDELIM;
- frame->mii_opcode = VR_MII_READOP;
- frame->mii_turnaround = 0;
- frame->mii_data = 0;
-
- CSR_WRITE_1(sc, VR_MIICMD, 0);
- VR_SETBIT(sc, VR_MIICMD, VR_MIICMD_DIRECTPGM);
-
- /*
- * Turn on data xmit.
- */
- SIO_SET(VR_MIICMD_DIR);
-
- vr_mii_sync(sc);
-
- /*
- * Send command/address info.
- */
- vr_mii_send(sc, frame->mii_stdelim, 2);
- vr_mii_send(sc, frame->mii_opcode, 2);
- vr_mii_send(sc, frame->mii_phyaddr, 5);
- vr_mii_send(sc, frame->mii_regaddr, 5);
-
- /* Idle bit */
- SIO_CLR((VR_MIICMD_CLK|VR_MIICMD_DATAIN));
- DELAY(1);
- SIO_SET(VR_MIICMD_CLK);
- DELAY(1);
-
- /* Turn off xmit. */
- SIO_CLR(VR_MIICMD_DIR);
-
- /* Check for ack */
- SIO_CLR(VR_MIICMD_CLK);
- DELAY(1);
- ack = CSR_READ_4(sc, VR_MIICMD) & VR_MIICMD_DATAOUT;
- SIO_SET(VR_MIICMD_CLK);
- DELAY(1);
-
- /*
- * Now try reading data bits. If the ack failed, we still
- * need to clock through 16 cycles to keep the PHY(s) in sync.
- */
- if (ack) {
- for(i = 0; i < 16; i++) {
- SIO_CLR(VR_MIICMD_CLK);
- DELAY(1);
- SIO_SET(VR_MIICMD_CLK);
- DELAY(1);
- }
- goto fail;
- }
-
- for (i = 0x8000; i; i >>= 1) {
- SIO_CLR(VR_MIICMD_CLK);
- DELAY(1);
- if (!ack) {
- if (CSR_READ_4(sc, VR_MIICMD) & VR_MIICMD_DATAOUT)
- frame->mii_data |= i;
- DELAY(1);
- }
- SIO_SET(VR_MIICMD_CLK);
- DELAY(1);
- }
-
-fail:
-
- SIO_CLR(VR_MIICMD_CLK);
- DELAY(1);
- SIO_SET(VR_MIICMD_CLK);
- DELAY(1);
-
- VR_UNLOCK(sc);
-
- if (ack)
- return(1);
- return(0);
-}
-#else
-{
- int s, i;
-
- s = splimp();
-
- /* Set the PHY-adress */
- CSR_WRITE_1(sc, VR_PHYADDR, (CSR_READ_1(sc, VR_PHYADDR)& 0xe0)|
- frame->mii_phyaddr);
-
- /* Set the register-adress */
- CSR_WRITE_1(sc, VR_MIIADDR, frame->mii_regaddr);
- VR_SETBIT(sc, VR_MIICMD, VR_MIICMD_READ_ENB);
-
- for (i = 0; i < 10000; i++) {
- if ((CSR_READ_1(sc, VR_MIICMD) & VR_MIICMD_READ_ENB) == 0)
- break;
- DELAY(1);
- }
-
- frame->mii_data = CSR_READ_2(sc, VR_MIIDATA);
-
- (void)splx(s);
-
- return(0);
-}
-#endif
-
-
-/*
- * Write to a PHY register through the MII.
- */
-static int
-vr_mii_writereg(sc, frame)
- struct vr_softc *sc;
- struct vr_mii_frame *frame;
-
-#ifdef VR_USESWSHIFT
-{
- VR_LOCK(sc);
-
- CSR_WRITE_1(sc, VR_MIICMD, 0);
- VR_SETBIT(sc, VR_MIICMD, VR_MIICMD_DIRECTPGM);
-
- /*
- * Set up frame for TX.
- */
-
- frame->mii_stdelim = VR_MII_STARTDELIM;
- frame->mii_opcode = VR_MII_WRITEOP;
- frame->mii_turnaround = VR_MII_TURNAROUND;
-
- /*
- * Turn on data output.
- */
- SIO_SET(VR_MIICMD_DIR);
-
- vr_mii_sync(sc);
-
- vr_mii_send(sc, frame->mii_stdelim, 2);
- vr_mii_send(sc, frame->mii_opcode, 2);
- vr_mii_send(sc, frame->mii_phyaddr, 5);
- vr_mii_send(sc, frame->mii_regaddr, 5);
- vr_mii_send(sc, frame->mii_turnaround, 2);
- vr_mii_send(sc, frame->mii_data, 16);
-
- /* Idle bit. */
- SIO_SET(VR_MIICMD_CLK);
- DELAY(1);
- SIO_CLR(VR_MIICMD_CLK);
- DELAY(1);
-
- /*
- * Turn off xmit.
- */
- SIO_CLR(VR_MIICMD_DIR);
-
- VR_UNLOCK(sc);
-
- return(0);
-}
-#else
-{
- int s, i;
-
- s = splimp();
-
- /* Set the PHY-adress */
- CSR_WRITE_1(sc, VR_PHYADDR, (CSR_READ_1(sc, VR_PHYADDR)& 0xe0)|
- frame->mii_phyaddr);
-
- /* Set the register-adress and data to write */
- CSR_WRITE_1(sc, VR_MIIADDR, frame->mii_regaddr);
- CSR_WRITE_2(sc, VR_MIIDATA, frame->mii_data);
-
- VR_SETBIT(sc, VR_MIICMD, VR_MIICMD_WRITE_ENB);
-
- for (i = 0; i < 10000; i++) {
- if ((CSR_READ_1(sc, VR_MIICMD) & VR_MIICMD_WRITE_ENB) == 0)
- break;
- DELAY(1);
- }
-
- (void)splx(s);
-
- return(0);
-}
-#endif
-
-static int
-vr_miibus_readreg(dev, phy, reg)
- device_t dev;
- int phy, reg;
-{
- struct vr_softc *sc;
- struct vr_mii_frame frame;
-
- sc = device_get_softc(dev);
-
- switch (sc->vr_revid) {
- case REV_ID_VT6102_APOLLO:
- if (phy != 1)
- return 0;
- default:
- break;
- }
-
- bzero((char *)&frame, sizeof(frame));
-
- frame.mii_phyaddr = phy;
- frame.mii_regaddr = reg;
- vr_mii_readreg(sc, &frame);
-
- return(frame.mii_data);
-}
-
-static int
-vr_miibus_writereg(dev, phy, reg, data)
- device_t dev;
- u_int16_t phy, reg, data;
-{
- struct vr_softc *sc;
- struct vr_mii_frame frame;
-
- sc = device_get_softc(dev);
-
- switch (sc->vr_revid) {
- case REV_ID_VT6102_APOLLO:
- if (phy != 1)
- return 0;
- default:
- break;
- }
-
- bzero((char *)&frame, sizeof(frame));
-
- frame.mii_phyaddr = phy;
- frame.mii_regaddr = reg;
- frame.mii_data = data;
-
- vr_mii_writereg(sc, &frame);
-
- return(0);
-}
-
-static void
-vr_miibus_statchg(dev)
- device_t dev;
-{
- struct vr_softc *sc;
- struct mii_data *mii;
-
- sc = device_get_softc(dev);
- VR_LOCK(sc);
- mii = device_get_softc(sc->vr_miibus);
- vr_setcfg(sc, mii->mii_media_active);
- VR_UNLOCK(sc);
-
- return;
-}
-
-/*
- * Calculate CRC of a multicast group address, return the lower 6 bits.
- */
-static u_int8_t vr_calchash(addr)
- u_int8_t *addr;
-{
- u_int32_t crc, carry;
- int i, j;
- u_int8_t c;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (i = 0; i < 6; i++) {
- c = *(addr + i);
- for (j = 0; j < 8; j++) {
- carry = ((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01);
- crc <<= 1;
- c >>= 1;
- if (carry)
- crc = (crc ^ 0x04c11db6) | carry;
- }
- }
-
- /* return the filter bit position */
- return((crc >> 26) & 0x0000003F);
-}
-
-/*
- * Program the 64-bit multicast hash filter.
- */
-static void
-vr_setmulti(sc)
- struct vr_softc *sc;
-{
- struct ifnet *ifp;
- int h = 0;
- u_int32_t hashes[2] = { 0, 0 };
- struct ifmultiaddr *ifma;
- u_int8_t rxfilt;
- int mcnt = 0;
-
- ifp = &sc->arpcom.ac_if;
-
- rxfilt = CSR_READ_1(sc, VR_RXCFG);
-
- if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
- rxfilt |= VR_RXCFG_RX_MULTI;
- CSR_WRITE_1(sc, VR_RXCFG, rxfilt);
- CSR_WRITE_4(sc, VR_MAR0, 0xFFFFFFFF);
- CSR_WRITE_4(sc, VR_MAR1, 0xFFFFFFFF);
- return;
- }
-
- /* first, zot all the existing hash bits */
- CSR_WRITE_4(sc, VR_MAR0, 0);
- CSR_WRITE_4(sc, VR_MAR1, 0);
-
- /* now program new ones */
- TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
- if (ifma->ifma_addr->sa_family != AF_LINK)
- continue;
- h = vr_calchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
- if (h < 32)
- hashes[0] |= (1 << h);
- else
- hashes[1] |= (1 << (h - 32));
- mcnt++;
- }
-
- if (mcnt)
- rxfilt |= VR_RXCFG_RX_MULTI;
- else
- rxfilt &= ~VR_RXCFG_RX_MULTI;
-
- CSR_WRITE_4(sc, VR_MAR0, hashes[0]);
- CSR_WRITE_4(sc, VR_MAR1, hashes[1]);
- CSR_WRITE_1(sc, VR_RXCFG, rxfilt);
-
- return;
-}
-
-/*
- * In order to fiddle with the
- * 'full-duplex' and '100Mbps' bits in the netconfig register, we
- * first have to put the transmit and/or receive logic in the idle state.
- */
-static void
-vr_setcfg(sc, media)
- struct vr_softc *sc;
- int media;
-{
- int restart = 0;
-
- if (CSR_READ_2(sc, VR_COMMAND) & (VR_CMD_TX_ON|VR_CMD_RX_ON)) {
- restart = 1;
- VR_CLRBIT16(sc, VR_COMMAND, (VR_CMD_TX_ON|VR_CMD_RX_ON));
- }
-
- if ((media & IFM_GMASK) == IFM_FDX)
- VR_SETBIT16(sc, VR_COMMAND, VR_CMD_FULLDUPLEX);
- else
- VR_CLRBIT16(sc, VR_COMMAND, VR_CMD_FULLDUPLEX);
-
- if (restart)
- VR_SETBIT16(sc, VR_COMMAND, VR_CMD_TX_ON|VR_CMD_RX_ON);
-
- return;
-}
-
-static void
-vr_reset(sc)
- struct vr_softc *sc;
-{
- register int i;
-
- VR_SETBIT16(sc, VR_COMMAND, VR_CMD_RESET);
-
- for (i = 0; i < VR_TIMEOUT; i++) {
- DELAY(10);
- if (!(CSR_READ_2(sc, VR_COMMAND) & VR_CMD_RESET))
- break;
- }
- if (i == VR_TIMEOUT) {
- if (sc->vr_revid < REV_ID_VT3065_A)
- printf("vr%d: reset never completed!\n", sc->vr_unit);
- else {
- /* Use newer force reset command */
- printf("vr%d: Using force reset command.\n", sc->vr_unit);
- VR_SETBIT(sc, VR_MISC_CR1, VR_MISCCR1_FORSRST);
- }
- }
-
- /* Wait a little while for the chip to get its brains in order. */
- DELAY(1000);
-
- return;
-}
-
-/*
- * Probe for a VIA Rhine chip. Check the PCI vendor and device
- * IDs against our list and return a device name if we find a match.
- */
-static int
-vr_probe(dev)
- device_t dev;
-{
- struct vr_type *t;
-
- t = vr_devs;
-
- while(t->vr_name != NULL) {
- if ((pci_get_vendor(dev) == t->vr_vid) &&
- (pci_get_device(dev) == t->vr_did)) {
- device_set_desc(dev, t->vr_name);
- return(0);
- }
- t++;
- }
-
- return(ENXIO);
-}
-
-/*
- * Attach the interface. Allocate softc structures, do ifmedia
- * setup and ethernet/BPF attach.
- */
-static int
-vr_attach(dev)
- device_t dev;
-{
- int i;
- u_char eaddr[ETHER_ADDR_LEN];
- struct vr_softc *sc;
- struct ifnet *ifp;
- int unit, error = 0, rid;
-
- sc = device_get_softc(dev);
- unit = device_get_unit(dev);
-
- mtx_init(&sc->vr_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
- MTX_DEF | MTX_RECURSE);
-
- /*
- * Handle power management nonsense.
- */
- if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
- u_int32_t iobase, membase, irq;
-
- /* Save important PCI config data. */
- iobase = pci_read_config(dev, VR_PCI_LOIO, 4);
- membase = pci_read_config(dev, VR_PCI_LOMEM, 4);
- irq = pci_read_config(dev, VR_PCI_INTLINE, 4);
-
- /* Reset the power state. */
- printf("vr%d: chip is in D%d power mode "
- "-- setting to D0\n", unit,
- pci_get_powerstate(dev));
- pci_set_powerstate(dev, PCI_POWERSTATE_D0);
-
- /* Restore PCI config data. */
- pci_write_config(dev, VR_PCI_LOIO, iobase, 4);
- pci_write_config(dev, VR_PCI_LOMEM, membase, 4);
- pci_write_config(dev, VR_PCI_INTLINE, irq, 4);
- }
-
- /*
- * Map control/status registers.
- */
- pci_enable_busmaster(dev);
- sc->vr_revid = pci_read_config(dev, VR_PCI_REVID, 4) & 0x000000FF;
-
- rid = VR_RID;
- sc->vr_res = bus_alloc_resource(dev, VR_RES, &rid,
- 0, ~0, 1, RF_ACTIVE);
-
- if (sc->vr_res == NULL) {
- printf("vr%d: couldn't map ports/memory\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- sc->vr_btag = rman_get_bustag(sc->vr_res);
- sc->vr_bhandle = rman_get_bushandle(sc->vr_res);
-
- /* Allocate interrupt */
- rid = 0;
- sc->vr_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
- RF_SHAREABLE | RF_ACTIVE);
-
- if (sc->vr_irq == NULL) {
- printf("vr%d: couldn't map interrupt\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- /*
- * Windows may put the chip in suspend mode when it
- * shuts down. Be sure to kick it in the head to wake it
- * up again.
- */
- VR_CLRBIT(sc, VR_STICKHW, (VR_STICKHW_DS0|VR_STICKHW_DS1));
-
- /* Reset the adapter. */
- vr_reset(sc);
-
- /*
- * Turn on bit2 (MIION) in PCI configuration register 0x53 during
- * initialization and disable AUTOPOLL.
- */
- pci_write_config(dev, VR_PCI_MODE,
- pci_read_config(dev, VR_PCI_MODE, 4) | (VR_MODE3_MIION << 24), 4);
- VR_CLRBIT(sc, VR_MIICMD, VR_MIICMD_AUTOPOLL);
-
- /*
- * Get station address. The way the Rhine chips work,
- * you're not allowed to directly access the EEPROM once
- * they've been programmed a special way. Consequently,
- * we need to read the node address from the PAR0 and PAR1
- * registers.
- */
- VR_SETBIT(sc, VR_EECSR, VR_EECSR_LOAD);
- DELAY(200);
- for (i = 0; i < ETHER_ADDR_LEN; i++)
- eaddr[i] = CSR_READ_1(sc, VR_PAR0 + i);
-
- /*
- * A Rhine chip was detected. Inform the world.
- */
- printf("vr%d: Ethernet address: %6D\n", unit, eaddr, ":");
-
- sc->vr_unit = unit;
- bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
-
- sc->vr_ldata = contigmalloc(sizeof(struct vr_list_data), M_DEVBUF,
- M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
-
- if (sc->vr_ldata == NULL) {
- printf("vr%d: no memory for list buffers!\n", unit);
- error = ENXIO;
- goto fail;
- }
-
- bzero(sc->vr_ldata, sizeof(struct vr_list_data));
-
- ifp = &sc->arpcom.ac_if;
- ifp->if_softc = sc;
- ifp->if_unit = unit;
- ifp->if_name = "vr";
- ifp->if_mtu = ETHERMTU;
- ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
- ifp->if_ioctl = vr_ioctl;
- ifp->if_output = ether_output;
- ifp->if_start = vr_start;
- ifp->if_watchdog = vr_watchdog;
- ifp->if_init = vr_init;
- ifp->if_baudrate = 10000000;
- ifp->if_snd.ifq_maxlen = VR_TX_LIST_CNT - 1;
-
- /*
- * Do MII setup.
- */
- if (mii_phy_probe(dev, &sc->vr_miibus,
- vr_ifmedia_upd, vr_ifmedia_sts)) {
- printf("vr%d: MII without any phy!\n", sc->vr_unit);
- error = ENXIO;
- goto fail;
- }
-
- callout_handle_init(&sc->vr_stat_ch);
-
- /*
- * Call MI attach routine.
- */
- ether_ifattach(ifp, eaddr);
-
- /* Hook interrupt last to avoid having to lock softc */
- error = bus_setup_intr(dev, sc->vr_irq, INTR_TYPE_NET,
- vr_intr, sc, &sc->vr_intrhand);
-
- if (error) {
- printf("vr%d: couldn't set up irq\n", unit);
- ether_ifdetach(ifp);
- goto fail;
- }
-
-fail:
- if (error)
- vr_detach(dev);
-
- return(error);
-}
-
-/*
- * Shutdown hardware and free up resources. This can be called any
- * time after the mutex has been initialized. It is called in both
- * the error case in attach and the normal detach case so it needs
- * to be careful about only freeing resources that have actually been
- * allocated.
- */
-static int
-vr_detach(dev)
- device_t dev;
-{
- struct vr_softc *sc;
- struct ifnet *ifp;
-
- sc = device_get_softc(dev);
- KASSERT(mtx_initialized(&sc->vr_mtx), ("vr mutex not initialized"));
- VR_LOCK(sc);
- ifp = &sc->arpcom.ac_if;
-
- /* These should only be active if attach succeeded */
- if (device_is_attached(dev)) {
- vr_stop(sc);
- ether_ifdetach(ifp);
- }
- if (sc->vr_miibus)
- device_delete_child(dev, sc->vr_miibus);
- bus_generic_detach(dev);
-
- if (sc->vr_intrhand)
- bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand);
- if (sc->vr_irq)
- bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq);
- if (sc->vr_res)
- bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res);
-
- if (sc->vr_ldata)
- contigfree(sc->vr_ldata, sizeof(struct vr_list_data), M_DEVBUF);
-
- VR_UNLOCK(sc);
- mtx_destroy(&sc->vr_mtx);
-
- return(0);
-}
-
-/*
- * Initialize the transmit descriptors.
- */
-static int
-vr_list_tx_init(sc)
- struct vr_softc *sc;
-{
- struct vr_chain_data *cd;
- struct vr_list_data *ld;
- int i;
-
- cd = &sc->vr_cdata;
- ld = sc->vr_ldata;
- for (i = 0; i < VR_TX_LIST_CNT; i++) {
- cd->vr_tx_chain[i].vr_ptr = &ld->vr_tx_list[i];
- if (i == (VR_TX_LIST_CNT - 1))
- cd->vr_tx_chain[i].vr_nextdesc =
- &cd->vr_tx_chain[0];
- else
- cd->vr_tx_chain[i].vr_nextdesc =
- &cd->vr_tx_chain[i + 1];
- }
-
- cd->vr_tx_free = &cd->vr_tx_chain[0];
- cd->vr_tx_tail = cd->vr_tx_head = NULL;
-
- return(0);
-}
-
-
-/*
- * Initialize the RX descriptors and allocate mbufs for them. Note that
- * we arrange the descriptors in a closed ring, so that the last descriptor
- * points back to the first.
- */
-static int
-vr_list_rx_init(sc)
- struct vr_softc *sc;
-{
- struct vr_chain_data *cd;
- struct vr_list_data *ld;
- int i;
-
- cd = &sc->vr_cdata;
- ld = sc->vr_ldata;
-
- for (i = 0; i < VR_RX_LIST_CNT; i++) {
- cd->vr_rx_chain[i].vr_ptr =
- (struct vr_desc *)&ld->vr_rx_list[i];
- if (vr_newbuf(sc, &cd->vr_rx_chain[i], NULL) == ENOBUFS)
- return(ENOBUFS);
- if (i == (VR_RX_LIST_CNT - 1)) {
- cd->vr_rx_chain[i].vr_nextdesc =
- &cd->vr_rx_chain[0];
- ld->vr_rx_list[i].vr_next =
- vtophys(&ld->vr_rx_list[0]);
- } else {
- cd->vr_rx_chain[i].vr_nextdesc =
- &cd->vr_rx_chain[i + 1];
- ld->vr_rx_list[i].vr_next =
- vtophys(&ld->vr_rx_list[i + 1]);
- }
- }
-
- cd->vr_rx_head = &cd->vr_rx_chain[0];
-
- return(0);
-}
-
-/*
- * Initialize an RX descriptor and attach an MBUF cluster.
- * Note: the length fields are only 11 bits wide, which means the
- * largest size we can specify is 2047. This is important because
- * MCLBYTES is 2048, so we have to subtract one otherwise we'll
- * overflow the field and make a mess.
- */
-static int
-vr_newbuf(sc, c, m)
- struct vr_softc *sc;
- struct vr_chain_onefrag *c;
- struct mbuf *m;
-{
- struct mbuf *m_new = NULL;
-
- if (m == NULL) {
- MGETHDR(m_new, M_DONTWAIT, MT_DATA);
- if (m_new == NULL)
- return(ENOBUFS);
-
- MCLGET(m_new, M_DONTWAIT);
- if (!(m_new->m_flags & M_EXT)) {
- m_freem(m_new);
- return(ENOBUFS);
- }
- m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
- } else {
- m_new = m;
- m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
- m_new->m_data = m_new->m_ext.ext_buf;
- }
-
- m_adj(m_new, sizeof(u_int64_t));
-
- c->vr_mbuf = m_new;
- c->vr_ptr->vr_status = VR_RXSTAT;
- c->vr_ptr->vr_data = vtophys(mtod(m_new, caddr_t));
- c->vr_ptr->vr_ctl = VR_RXCTL | VR_RXLEN;
-
- return(0);
-}
-
-/*
- * A frame has been uploaded: pass the resulting mbuf chain up to
- * the higher level protocols.
- */
-static void
-vr_rxeof(sc)
- struct vr_softc *sc;
-{
- struct mbuf *m;
- struct ifnet *ifp;
- struct vr_chain_onefrag *cur_rx;
- int total_len = 0;
- u_int32_t rxstat;
-
- ifp = &sc->arpcom.ac_if;
-
- while(!((rxstat = sc->vr_cdata.vr_rx_head->vr_ptr->vr_status) &
- VR_RXSTAT_OWN)) {
- struct mbuf *m0 = NULL;
-
- cur_rx = sc->vr_cdata.vr_rx_head;
- sc->vr_cdata.vr_rx_head = cur_rx->vr_nextdesc;
- m = cur_rx->vr_mbuf;
-
- /*
- * If an error occurs, update stats, clear the
- * status word and leave the mbuf cluster in place:
- * it should simply get re-used next time this descriptor
- * comes up in the ring.
- */
- if (rxstat & VR_RXSTAT_RXERR) {
- ifp->if_ierrors++;
- printf("vr%d: rx error (%02x):",
- sc->vr_unit, rxstat & 0x000000ff);
- if (rxstat & VR_RXSTAT_CRCERR)
- printf(" crc error");
- if (rxstat & VR_RXSTAT_FRAMEALIGNERR)
- printf(" frame alignment error\n");
- if (rxstat & VR_RXSTAT_FIFOOFLOW)
- printf(" FIFO overflow");
- if (rxstat & VR_RXSTAT_GIANT)
- printf(" received giant packet");
- if (rxstat & VR_RXSTAT_RUNT)
- printf(" received runt packet");
- if (rxstat & VR_RXSTAT_BUSERR)
- printf(" system bus error");
- if (rxstat & VR_RXSTAT_BUFFERR)
- printf("rx buffer error");
- printf("\n");
- vr_newbuf(sc, cur_rx, m);
- continue;
- }
-
- /* No errors; receive the packet. */
- total_len = VR_RXBYTES(cur_rx->vr_ptr->vr_status);
-
- /*
- * XXX The VIA Rhine chip includes the CRC with every
- * received frame, and there's no way to turn this
- * behavior off (at least, I can't find anything in
- * the manual that explains how to do it) so we have
- * to trim off the CRC manually.
- */
- total_len -= ETHER_CRC_LEN;
-
- m0 = m_devget(mtod(m, char *), total_len, ETHER_ALIGN, ifp,
- NULL);
- vr_newbuf(sc, cur_rx, m);
- if (m0 == NULL) {
- ifp->if_ierrors++;
- continue;
- }
- m = m0;
-
- ifp->if_ipackets++;
- (*ifp->if_input)(ifp, m);
- }
-
- return;
-}
-
-static void
-vr_rxeoc(sc)
- struct vr_softc *sc;
-{
- struct ifnet *ifp;
- int i;
-
- ifp = &sc->arpcom.ac_if;
-
- ifp->if_ierrors++;
-
- VR_CLRBIT16(sc, VR_COMMAND, VR_CMD_RX_ON);
- DELAY(10000);
-
- for (i = 0x400;
- i && (CSR_READ_2(sc, VR_COMMAND) & VR_CMD_RX_ON);
- i--)
- ; /* Wait for receiver to stop */
-
- if (!i) {
- printf("vr%d: rx shutdown error!\n", sc->vr_unit);
- sc->vr_flags |= VR_F_RESTART;
- return;
- }
-
- vr_rxeof(sc);
-
- CSR_WRITE_4(sc, VR_RXADDR, vtophys(sc->vr_cdata.vr_rx_head->vr_ptr));
- VR_SETBIT16(sc, VR_COMMAND, VR_CMD_RX_ON);
- VR_SETBIT16(sc, VR_COMMAND, VR_CMD_RX_GO);
-
- return;
-}
-
-/*
- * A frame was downloaded to the chip. It's safe for us to clean up
- * the list buffers.
- */
-
-static void
-vr_txeof(sc)
- struct vr_softc *sc;
-{
- struct vr_chain *cur_tx;
- struct ifnet *ifp;
-
- ifp = &sc->arpcom.ac_if;
-
- /* Reset the timeout timer; if_txeoc will clear it. */
- ifp->if_timer = 5;
-
- /* Sanity check. */
- if (sc->vr_cdata.vr_tx_head == NULL)
- return;
-
- /*
- * Go through our tx list and free mbufs for those
- * frames that have been transmitted.
- */
- while(sc->vr_cdata.vr_tx_head->vr_mbuf != NULL) {
- u_int32_t txstat;
- int i;
-
- cur_tx = sc->vr_cdata.vr_tx_head;
- txstat = cur_tx->vr_ptr->vr_status;
-
- if ((txstat & VR_TXSTAT_ABRT) ||
- (txstat & VR_TXSTAT_UDF)) {
- for (i = 0x400;
- i && (CSR_READ_2(sc, VR_COMMAND) & VR_CMD_TX_ON);
- i--)
- ; /* Wait for chip to shutdown */
- if (!i) {
- printf("vr%d: tx shutdown timeout\n", sc->vr_unit);
- sc->vr_flags |= VR_F_RESTART;
- break;
- }
- VR_TXOWN(cur_tx) = VR_TXSTAT_OWN;
- CSR_WRITE_4(sc, VR_TXADDR, vtophys(cur_tx->vr_ptr));
- break;
- }
-
- if (txstat & VR_TXSTAT_OWN)
- break;
-
- if (txstat & VR_TXSTAT_ERRSUM) {
- ifp->if_oerrors++;
- if (txstat & VR_TXSTAT_DEFER)
- ifp->if_collisions++;
- if (txstat & VR_TXSTAT_LATECOLL)
- ifp->if_collisions++;
- }
-
- ifp->if_collisions +=(txstat & VR_TXSTAT_COLLCNT) >> 3;
-
- ifp->if_opackets++;
- if (cur_tx->vr_mbuf != NULL) {
- m_freem(cur_tx->vr_mbuf);
- cur_tx->vr_mbuf = NULL;
- }
-
- if (sc->vr_cdata.vr_tx_head == sc->vr_cdata.vr_tx_tail) {
- sc->vr_cdata.vr_tx_head = NULL;
- sc->vr_cdata.vr_tx_tail = NULL;
- break;
- }
-
- sc->vr_cdata.vr_tx_head = cur_tx->vr_nextdesc;
- }
-
- return;
-}
-
-/*
- * TX 'end of channel' interrupt handler.
- */
-static void
-vr_txeoc(sc)
- struct vr_softc *sc;
-{
- struct ifnet *ifp;
-
- ifp = &sc->arpcom.ac_if;
-
- if (sc->vr_cdata.vr_tx_head == NULL) {
- ifp->if_flags &= ~IFF_OACTIVE;
- sc->vr_cdata.vr_tx_tail = NULL;
- ifp->if_timer = 0;
- }
-
- return;
-}
-
-static void
-vr_tick(xsc)
- void *xsc;
-{
- struct vr_softc *sc;
- struct mii_data *mii;
-
- sc = xsc;
- VR_LOCK(sc);
- if (sc->vr_flags & VR_F_RESTART) {
- printf("vr%d: restarting\n", sc->vr_unit);
- vr_stop(sc);
- vr_reset(sc);
- vr_init(sc);
- sc->vr_flags &= ~VR_F_RESTART;
- }
-
- mii = device_get_softc(sc->vr_miibus);
- mii_tick(mii);
-
- sc->vr_stat_ch = timeout(vr_tick, sc, hz);
-
- VR_UNLOCK(sc);
-
- return;
-}
-
-static void
-vr_intr(arg)
- void *arg;
-{
- struct vr_softc *sc;
- struct ifnet *ifp;
- u_int16_t status;
-
- sc = arg;
- VR_LOCK(sc);
- ifp = &sc->arpcom.ac_if;
-
- /* Supress unwanted interrupts. */
- if (!(ifp->if_flags & IFF_UP)) {
- vr_stop(sc);
- VR_UNLOCK(sc);
- return;
- }
-
- /* Disable interrupts. */
- CSR_WRITE_2(sc, VR_IMR, 0x0000);
-
- for (;;) {
-
- status = CSR_READ_2(sc, VR_ISR);
- if (status)
- CSR_WRITE_2(sc, VR_ISR, status);
-
- if ((status & VR_INTRS) == 0)
- break;
-
- if (status & VR_ISR_RX_OK)
- vr_rxeof(sc);
-
- if (status & VR_ISR_RX_DROPPED) {
- printf("vr%d: rx packet lost\n", sc->vr_unit);
- ifp->if_ierrors++;
- }
-
- if ((status & VR_ISR_RX_ERR) || (status & VR_ISR_RX_NOBUF) ||
- (status & VR_ISR_RX_NOBUF) || (status & VR_ISR_RX_OFLOW)) {
- printf("vr%d: receive error (%04x)",
- sc->vr_unit, status);
- if (status & VR_ISR_RX_NOBUF)
- printf(" no buffers");
- if (status & VR_ISR_RX_OFLOW)
- printf(" overflow");
- if (status & VR_ISR_RX_DROPPED)
- printf(" packet lost");
- printf("\n");
- vr_rxeoc(sc);
- }
-
- if ((status & VR_ISR_BUSERR) || (status & VR_ISR_TX_UNDERRUN)) {
- vr_reset(sc);
- vr_init(sc);
- break;
- }
-
- if ((status & VR_ISR_TX_OK) || (status & VR_ISR_TX_ABRT) ||
- (status & VR_ISR_TX_ABRT2) || (status & VR_ISR_UDFI)) {
- vr_txeof(sc);
- if ((status & VR_ISR_UDFI) ||
- (status & VR_ISR_TX_ABRT2) ||
- (status & VR_ISR_TX_ABRT)) {
- ifp->if_oerrors++;
- if (sc->vr_cdata.vr_tx_head != NULL) {
- VR_SETBIT16(sc, VR_COMMAND, VR_CMD_TX_ON);
- VR_SETBIT16(sc, VR_COMMAND, VR_CMD_TX_GO);
- }
- } else
- vr_txeoc(sc);
- }
-
- }
-
- /* Re-enable interrupts. */
- CSR_WRITE_2(sc, VR_IMR, VR_INTRS);
-
- if (ifp->if_snd.ifq_head != NULL) {
- vr_start(ifp);
- }
-
- VR_UNLOCK(sc);
-
- return;
-}
-
-/*
- * Encapsulate an mbuf chain in a descriptor by coupling the mbuf data
- * pointers to the fragment pointers.
- */
-static int
-vr_encap(sc, c, m_head)
- struct vr_softc *sc;
- struct vr_chain *c;
- struct mbuf *m_head;
-{
- int frag = 0;
- struct vr_desc *f = NULL;
- int total_len;
- struct mbuf *m;
-
- m = m_head;
- total_len = 0;
-
- /*
- * The VIA Rhine wants packet buffers to be longword
- * aligned, but very often our mbufs aren't. Rather than
- * waste time trying to decide when to copy and when not
- * to copy, just do it all the time.
- */
- if (m != NULL) {
- struct mbuf *m_new = NULL;
-
- m_new = m_defrag(m_head, M_DONTWAIT);
- if (m_new == NULL) {
- return(1);
- }
-
- m_head = m_new;
- /*
- * The Rhine chip doesn't auto-pad, so we have to make
- * sure to pad short frames out to the minimum frame length
- * ourselves.
- */
- if (m_head->m_len < VR_MIN_FRAMELEN) {
- m_new->m_pkthdr.len += VR_MIN_FRAMELEN - m_new->m_len;
- m_new->m_len = m_new->m_pkthdr.len;
- }
- f = c->vr_ptr;
- f->vr_data = vtophys(mtod(m_new, caddr_t));
- f->vr_ctl = total_len = m_new->m_len;
- f->vr_ctl |= VR_TXCTL_TLINK|VR_TXCTL_FIRSTFRAG;
- f->vr_status = 0;
- frag = 1;
- }
-
- c->vr_mbuf = m_head;
- c->vr_ptr->vr_ctl |= VR_TXCTL_LASTFRAG|VR_TXCTL_FINT;
- c->vr_ptr->vr_next = vtophys(c->vr_nextdesc->vr_ptr);
-
- return(0);
-}
-
-/*
- * Main transmit routine. To avoid having to do mbuf copies, we put pointers
- * to the mbuf data regions directly in the transmit lists. We also save a
- * copy of the pointers since the transmit list fragment pointers are
- * physical addresses.
- */
-
-static void
-vr_start(ifp)
- struct ifnet *ifp;
-{
- struct vr_softc *sc;
- struct mbuf *m_head = NULL;
- struct vr_chain *cur_tx = NULL, *start_tx, *prev_tx;
-
- sc = ifp->if_softc;
-
- VR_LOCK(sc);
-
- /*
- * Check for an available queue slot. If there are none,
- * punt.
- */
- if (sc->vr_cdata.vr_tx_free->vr_mbuf != NULL) {
- VR_UNLOCK(sc);
- return;
- }
-
- start_tx = sc->vr_cdata.vr_tx_free;
-
- while(sc->vr_cdata.vr_tx_free->vr_mbuf == NULL) {
- IF_DEQUEUE(&ifp->if_snd, m_head);
- if (m_head == NULL)
- break;
-
- /* Pick a descriptor off the free list. */
- prev_tx = cur_tx;
- cur_tx = sc->vr_cdata.vr_tx_free;
- sc->vr_cdata.vr_tx_free = cur_tx->vr_nextdesc;
-
- /* Pack the data into the descriptor. */
- if (vr_encap(sc, cur_tx, m_head)) {
- /* Rollback, send what we were able to encap. */
- IF_PREPEND(&ifp->if_snd, m_head);
- sc->vr_cdata.vr_tx_free = cur_tx;
- cur_tx = prev_tx;
- break;
- }
-
- if (cur_tx != start_tx)
- VR_TXOWN(cur_tx) = VR_TXSTAT_OWN;
-
- /*
- * If there's a BPF listener, bounce a copy of this frame
- * to him.
- */
- BPF_MTAP(ifp, cur_tx->vr_mbuf);
-
- VR_TXOWN(cur_tx) = VR_TXSTAT_OWN;
- }
-
- /*
- * If there are no frames queued, bail.
- */
- if (cur_tx == NULL) {
- VR_UNLOCK(sc);
- return;
- }
-
- sc->vr_cdata.vr_tx_tail = cur_tx;
-
- if (sc->vr_cdata.vr_tx_head == NULL)
- sc->vr_cdata.vr_tx_head = start_tx;
-
- /* Tell the chip to start transmitting. */
- VR_SETBIT16(sc, VR_COMMAND, /*VR_CMD_TX_ON|*/VR_CMD_TX_GO);
-
- /*
- * Set a timeout in case the chip goes out to lunch.
- */
- ifp->if_timer = 5;
- VR_UNLOCK(sc);
-
- return;
-}
-
-static void
-vr_init(xsc)
- void *xsc;
-{
- struct vr_softc *sc = xsc;
- struct ifnet *ifp = &sc->arpcom.ac_if;
- struct mii_data *mii;
- int i;
-
- VR_LOCK(sc);
-
- mii = device_get_softc(sc->vr_miibus);
-
- /*
- * Cancel pending I/O and free all RX/TX buffers.
- */
- vr_stop(sc);
- vr_reset(sc);
-
- /*
- * Set our station address.
- */
- for (i = 0; i < ETHER_ADDR_LEN; i++)
- CSR_WRITE_1(sc, VR_PAR0 + i, sc->arpcom.ac_enaddr[i]);
-
- /* Set DMA size */
- VR_CLRBIT(sc, VR_BCR0, VR_BCR0_DMA_LENGTH);
- VR_SETBIT(sc, VR_BCR0, VR_BCR0_DMA_STORENFWD);
-
- /*
- * BCR0 and BCR1 can override the RXCFG and TXCFG registers,
- * so we must set both.
- */
- VR_CLRBIT(sc, VR_BCR0, VR_BCR0_RX_THRESH);
- VR_SETBIT(sc, VR_BCR0, VR_BCR0_RXTHRESH128BYTES);
-
- VR_CLRBIT(sc, VR_BCR1, VR_BCR1_TX_THRESH);
- VR_SETBIT(sc, VR_BCR1, VR_BCR1_TXTHRESHSTORENFWD);
-
- VR_CLRBIT(sc, VR_RXCFG, VR_RXCFG_RX_THRESH);
- VR_SETBIT(sc, VR_RXCFG, VR_RXTHRESH_128BYTES);
-
- VR_CLRBIT(sc, VR_TXCFG, VR_TXCFG_TX_THRESH);
- VR_SETBIT(sc, VR_TXCFG, VR_TXTHRESH_STORENFWD);
-
- /* Init circular RX list. */
- if (vr_list_rx_init(sc) == ENOBUFS) {
- printf("vr%d: initialization failed: no "
- "memory for rx buffers\n", sc->vr_unit);
- vr_stop(sc);
- VR_UNLOCK(sc);
- return;
- }
-
- /*
- * Init tx descriptors.
- */
- vr_list_tx_init(sc);
-
- /* If we want promiscuous mode, set the allframes bit. */
- if (ifp->if_flags & IFF_PROMISC)
- VR_SETBIT(sc, VR_RXCFG, VR_RXCFG_RX_PROMISC);
- else
- VR_CLRBIT(sc, VR_RXCFG, VR_RXCFG_RX_PROMISC);
-
- /* Set capture broadcast bit to capture broadcast frames. */
- if (ifp->if_flags & IFF_BROADCAST)
- VR_SETBIT(sc, VR_RXCFG, VR_RXCFG_RX_BROAD);
- else
- VR_CLRBIT(sc, VR_RXCFG, VR_RXCFG_RX_BROAD);
-
- /*
- * Program the multicast filter, if necessary.
- */
- vr_setmulti(sc);
-
- /*
- * Load the address of the RX list.
- */
- CSR_WRITE_4(sc, VR_RXADDR, vtophys(sc->vr_cdata.vr_rx_head->vr_ptr));
-
- /* Enable receiver and transmitter. */
- CSR_WRITE_2(sc, VR_COMMAND, VR_CMD_TX_NOPOLL|VR_CMD_START|
- VR_CMD_TX_ON|VR_CMD_RX_ON|
- VR_CMD_RX_GO);
-
- CSR_WRITE_4(sc, VR_TXADDR, vtophys(&sc->vr_ldata->vr_tx_list[0]));
-
- /*
- * Enable interrupts.
- */
- CSR_WRITE_2(sc, VR_ISR, 0xFFFF);
- CSR_WRITE_2(sc, VR_IMR, VR_INTRS);
-
- mii_mediachg(mii);
-
- ifp->if_flags |= IFF_RUNNING;
- ifp->if_flags &= ~IFF_OACTIVE;
-
- sc->vr_stat_ch = timeout(vr_tick, sc, hz);
-
- VR_UNLOCK(sc);
-
- return;
-}
-
-/*
- * Set media options.
- */
-static int
-vr_ifmedia_upd(ifp)
- struct ifnet *ifp;
-{
- struct vr_softc *sc;
-
- sc = ifp->if_softc;
-
- if (ifp->if_flags & IFF_UP)
- vr_init(sc);
-
- return(0);
-}
-
-/*
- * Report current media status.
- */
-static void
-vr_ifmedia_sts(ifp, ifmr)
- struct ifnet *ifp;
- struct ifmediareq *ifmr;
-{
- struct vr_softc *sc;
- struct mii_data *mii;
-
- sc = ifp->if_softc;
- mii = device_get_softc(sc->vr_miibus);
- mii_pollstat(mii);
- ifmr->ifm_active = mii->mii_media_active;
- ifmr->ifm_status = mii->mii_media_status;
-
- return;
-}
-
-static int
-vr_ioctl(ifp, command, data)
- struct ifnet *ifp;
- u_long command;
- caddr_t data;
-{
- struct vr_softc *sc = ifp->if_softc;
- struct ifreq *ifr = (struct ifreq *) data;
- struct mii_data *mii;
- int error = 0;
-
- VR_LOCK(sc);
-
- switch(command) {
- case SIOCSIFFLAGS:
- if (ifp->if_flags & IFF_UP) {
- vr_init(sc);
- } else {
- if (ifp->if_flags & IFF_RUNNING)
- vr_stop(sc);
- }
- error = 0;
- break;
- case SIOCADDMULTI:
- case SIOCDELMULTI:
- vr_setmulti(sc);
- error = 0;
- break;
- case SIOCGIFMEDIA:
- case SIOCSIFMEDIA:
- mii = device_get_softc(sc->vr_miibus);
- error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
- break;
- default:
- error = ether_ioctl(ifp, command, data);
- break;
- }
-
- VR_UNLOCK(sc);
-
- return(error);
-}
-
-static void
-vr_watchdog(ifp)
- struct ifnet *ifp;
-{
- struct vr_softc *sc;
-
- sc = ifp->if_softc;
-
- VR_LOCK(sc);
- ifp->if_oerrors++;
- printf("vr%d: watchdog timeout\n", sc->vr_unit);
-
- vr_stop(sc);
- vr_reset(sc);
- vr_init(sc);
-
- if (ifp->if_snd.ifq_head != NULL)
- vr_start(ifp);
-
- VR_UNLOCK(sc);
-
- return;
-}
-
-/*
- * Stop the adapter and free any mbufs allocated to the
- * RX and TX lists.
- */
-static void
-vr_stop(sc)
- struct vr_softc *sc;
-{
- register int i;
- struct ifnet *ifp;
-
- VR_LOCK(sc);
-
- ifp = &sc->arpcom.ac_if;
- ifp->if_timer = 0;
-
- untimeout(vr_tick, sc, sc->vr_stat_ch);
-
- VR_SETBIT16(sc, VR_COMMAND, VR_CMD_STOP);
- VR_CLRBIT16(sc, VR_COMMAND, (VR_CMD_RX_ON|VR_CMD_TX_ON));
- CSR_WRITE_2(sc, VR_IMR, 0x0000);
- CSR_WRITE_4(sc, VR_TXADDR, 0x00000000);
- CSR_WRITE_4(sc, VR_RXADDR, 0x00000000);
-
- /*
- * Free data in the RX lists.
- */
- for (i = 0; i < VR_RX_LIST_CNT; i++) {
- if (sc->vr_cdata.vr_rx_chain[i].vr_mbuf != NULL) {
- m_freem(sc->vr_cdata.vr_rx_chain[i].vr_mbuf);
- sc->vr_cdata.vr_rx_chain[i].vr_mbuf = NULL;
- }
- }
- bzero((char *)&sc->vr_ldata->vr_rx_list,
- sizeof(sc->vr_ldata->vr_rx_list));
-
- /*
- * Free the TX list buffers.
- */
- for (i = 0; i < VR_TX_LIST_CNT; i++) {
- if (sc->vr_cdata.vr_tx_chain[i].vr_mbuf != NULL) {
- m_freem(sc->vr_cdata.vr_tx_chain[i].vr_mbuf);
- sc->vr_cdata.vr_tx_chain[i].vr_mbuf = NULL;
- }
- }
-
- bzero((char *)&sc->vr_ldata->vr_tx_list,
- sizeof(sc->vr_ldata->vr_tx_list));
-
- ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
- VR_UNLOCK(sc);
-
- return;
-}
-
-/*
- * Stop all chip I/O so that the kernel's probe routines don't
- * get confused by errant DMAs when rebooting.
- */
-static void
-vr_shutdown(dev)
- device_t dev;
-{
- struct vr_softc *sc;
-
- sc = device_get_softc(dev);
-
- vr_stop(sc);
-
- return;
-}
diff --git a/sys/dev/vr/if_vrreg.h b/sys/dev/vr/if_vrreg.h
deleted file mode 100644
index 043c3edd36fe..000000000000
--- a/sys/dev/vr/if_vrreg.h
+++ /dev/null
@@ -1,594 +0,0 @@
-/*
- * Copyright (c) 1997, 1998
- * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (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$
- */
-
-/*
- * Rhine register definitions.
- */
-
-#define VR_PAR0 0x00 /* node address 0 to 4 */
-#define VR_PAR1 0x04 /* node address 2 to 6 */
-#define VR_RXCFG 0x06 /* receiver config register */
-#define VR_TXCFG 0x07 /* transmit config register */
-#define VR_COMMAND 0x08 /* command register */
-#define VR_ISR 0x0C /* interrupt/status register */
-#define VR_IMR 0x0E /* interrupt mask register */
-#define VR_MAR0 0x10 /* multicast hash 0 */
-#define VR_MAR1 0x14 /* multicast hash 1 */
-#define VR_RXADDR 0x18 /* rx descriptor list start addr */
-#define VR_TXADDR 0x1C /* tx descriptor list start addr */
-#define VR_CURRXDESC0 0x20
-#define VR_CURRXDESC1 0x24
-#define VR_CURRXDESC2 0x28
-#define VR_CURRXDESC3 0x2C
-#define VR_NEXTRXDESC0 0x30
-#define VR_NEXTRXDESC1 0x34
-#define VR_NEXTRXDESC2 0x38
-#define VR_NEXTRXDESC3 0x3C
-#define VR_CURTXDESC0 0x40
-#define VR_CURTXDESC1 0x44
-#define VR_CURTXDESC2 0x48
-#define VR_CURTXDESC3 0x4C
-#define VR_NEXTTXDESC0 0x50
-#define VR_NEXTTXDESC1 0x54
-#define VR_NEXTTXDESC2 0x58
-#define VR_NEXTTXDESC3 0x5C
-#define VR_CURRXDMA 0x60 /* current RX DMA address */
-#define VR_CURTXDMA 0x64 /* current TX DMA address */
-#define VR_TALLYCNT 0x68 /* tally counter test register */
-#define VR_PHYADDR 0x6C
-#define VR_MIISTAT 0x6D
-#define VR_BCR0 0x6E
-#define VR_BCR1 0x6F
-#define VR_MIICMD 0x70
-#define VR_MIIADDR 0x71
-#define VR_MIIDATA 0x72
-#define VR_EECSR 0x74
-#define VR_TEST 0x75
-#define VR_GPIO 0x76
-#define VR_CONFIG 0x78
-#define VR_MPA_CNT 0x7C
-#define VR_CRC_CNT 0x7E
-#define VR_STICKHW 0x83
-
-/* Misc Registers */
-#define VR_MISC_CR1 0x81
-#define VR_MISCCR1_FORSRST 0x40
-
-/*
- * RX config bits.
- */
-#define VR_RXCFG_RX_ERRPKTS 0x01
-#define VR_RXCFG_RX_RUNT 0x02
-#define VR_RXCFG_RX_MULTI 0x04
-#define VR_RXCFG_RX_BROAD 0x08
-#define VR_RXCFG_RX_PROMISC 0x10
-#define VR_RXCFG_RX_THRESH 0xE0
-
-#define VR_RXTHRESH_32BYTES 0x00
-#define VR_RXTHRESH_64BYTES 0x20
-#define VR_RXTHRESH_128BYTES 0x40
-#define VR_RXTHRESH_256BYTES 0x60
-#define VR_RXTHRESH_512BYTES 0x80
-#define VR_RXTHRESH_768BYTES 0xA0
-#define VR_RXTHRESH_1024BYTES 0xC0
-#define VR_RXTHRESH_STORENFWD 0xE0
-
-/*
- * TX config bits.
- */
-#define VR_TXCFG_RSVD0 0x01
-#define VR_TXCFG_LOOPBKMODE 0x06
-#define VR_TXCFG_BACKOFF 0x08
-#define VR_TXCFG_RSVD1 0x10
-#define VR_TXCFG_TX_THRESH 0xE0
-
-#define VR_TXTHRESH_32BYTES 0x00
-#define VR_TXTHRESH_64BYTES 0x20
-#define VR_TXTHRESH_128BYTES 0x40
-#define VR_TXTHRESH_256BYTES 0x60
-#define VR_TXTHRESH_512BYTES 0x80
-#define VR_TXTHRESH_768BYTES 0xA0
-#define VR_TXTHRESH_1024BYTES 0xC0
-#define VR_TXTHRESH_STORENFWD 0xE0
-
-/*
- * Command register bits.
- */
-#define VR_CMD_INIT 0x0001
-#define VR_CMD_START 0x0002
-#define VR_CMD_STOP 0x0004
-#define VR_CMD_RX_ON 0x0008
-#define VR_CMD_TX_ON 0x0010
-#define VR_CMD_TX_GO 0x0020
-#define VR_CMD_RX_GO 0x0040
-#define VR_CMD_RSVD 0x0080
-#define VR_CMD_RX_EARLY 0x0100
-#define VR_CMD_TX_EARLY 0x0200
-#define VR_CMD_FULLDUPLEX 0x0400
-#define VR_CMD_TX_NOPOLL 0x0800
-
-#define VR_CMD_RESET 0x8000
-
-/*
- * Interrupt status bits.
- */
-#define VR_ISR_RX_OK 0x0001 /* packet rx ok */
-#define VR_ISR_TX_OK 0x0002 /* packet tx ok */
-#define VR_ISR_RX_ERR 0x0004 /* packet rx with err */
-#define VR_ISR_TX_ABRT 0x0008 /* tx aborted due to excess colls */
-#define VR_ISR_TX_UNDERRUN 0x0010 /* tx buffer underflow */
-#define VR_ISR_RX_NOBUF 0x0020 /* no rx buffer available */
-#define VR_ISR_BUSERR 0x0040 /* PCI bus error */
-#define VR_ISR_STATSOFLOW 0x0080 /* stats counter oflow */
-#define VR_ISR_RX_EARLY 0x0100 /* rx early */
-#define VR_ISR_LINKSTAT 0x0200 /* MII status change */
-#define VR_ISR_ETI 0x0200 /* Tx early (3043/3071) */
-#define VR_ISR_UDFI 0x0200 /* Tx FIFO underflow (3065) */
-#define VR_ISR_RX_OFLOW 0x0400 /* rx FIFO overflow */
-#define VR_ISR_RX_DROPPED 0x0800
-#define VR_ISR_RX_NOBUF2 0x1000
-#define VR_ISR_TX_ABRT2 0x2000
-#define VR_ISR_LINKSTAT2 0x4000
-#define VR_ISR_MAGICPACKET 0x8000
-
-/*
- * Interrupt mask bits.
- */
-#define VR_IMR_RX_OK 0x0001 /* packet rx ok */
-#define VR_IMR_TX_OK 0x0002 /* packet tx ok */
-#define VR_IMR_RX_ERR 0x0004 /* packet rx with err */
-#define VR_IMR_TX_ABRT 0x0008 /* tx aborted due to excess colls */
-#define VR_IMR_TX_UNDERRUN 0x0010 /* tx buffer underflow */
-#define VR_IMR_RX_NOBUF 0x0020 /* no rx buffer available */
-#define VR_IMR_BUSERR 0x0040 /* PCI bus error */
-#define VR_IMR_STATSOFLOW 0x0080 /* stats counter oflow */
-#define VR_IMR_RX_EARLY 0x0100 /* rx early */
-#define VR_IMR_LINKSTAT 0x0200 /* MII status change */
-#define VR_IMR_RX_OFLOW 0x0400 /* rx FIFO overflow */
-#define VR_IMR_RX_DROPPED 0x0800
-#define VR_IMR_RX_NOBUF2 0x1000
-#define VR_IMR_TX_ABRT2 0x2000
-#define VR_IMR_LINKSTAT2 0x4000
-#define VR_IMR_MAGICPACKET 0x8000
-
-#define VR_INTRS \
- (VR_IMR_RX_OK|VR_IMR_TX_OK|VR_IMR_RX_NOBUF| \
- VR_IMR_TX_ABRT|VR_IMR_TX_UNDERRUN|VR_IMR_BUSERR| \
- VR_IMR_RX_ERR|VR_ISR_RX_DROPPED)
-
-/*
- * MII status register.
- */
-
-#define VR_MIISTAT_SPEED 0x01
-#define VR_MIISTAT_LINKFAULT 0x02
-#define VR_MIISTAT_MGTREADERR 0x04
-#define VR_MIISTAT_MIIERR 0x08
-#define VR_MIISTAT_PHYOPT 0x10
-#define VR_MIISTAT_MDC_SPEED 0x20
-#define VR_MIISTAT_RSVD 0x40
-#define VR_MIISTAT_GPIO1POLL 0x80
-
-/*
- * MII command register bits.
- */
-#define VR_MIICMD_CLK 0x01
-#define VR_MIICMD_DATAOUT 0x02
-#define VR_MIICMD_DATAIN 0x04
-#define VR_MIICMD_DIR 0x08
-#define VR_MIICMD_DIRECTPGM 0x10
-#define VR_MIICMD_WRITE_ENB 0x20
-#define VR_MIICMD_READ_ENB 0x40
-#define VR_MIICMD_AUTOPOLL 0x80
-
-/*
- * EEPROM control bits.
- */
-#define VR_EECSR_DATAIN 0x01 /* data out */
-#define VR_EECSR_DATAOUT 0x02 /* data in */
-#define VR_EECSR_CLK 0x04 /* clock */
-#define VR_EECSR_CS 0x08 /* chip select */
-#define VR_EECSR_DPM 0x10
-#define VR_EECSR_LOAD 0x20
-#define VR_EECSR_EMBP 0x40
-#define VR_EECSR_EEPR 0x80
-
-#define VR_EECMD_WRITE 0x140
-#define VR_EECMD_READ 0x180
-#define VR_EECMD_ERASE 0x1c0
-
-/*
- * Test register bits.
- */
-#define VR_TEST_TEST0 0x01
-#define VR_TEST_TEST1 0x02
-#define VR_TEST_TEST2 0x04
-#define VR_TEST_TSTUD 0x08
-#define VR_TEST_TSTOV 0x10
-#define VR_TEST_BKOFF 0x20
-#define VR_TEST_FCOL 0x40
-#define VR_TEST_HBDES 0x80
-
-/*
- * Config register bits.
- */
-#define VR_CFG_GPIO2OUTENB 0x00000001
-#define VR_CFG_GPIO2OUT 0x00000002 /* gen. purp. pin */
-#define VR_CFG_GPIO2IN 0x00000004 /* gen. purp. pin */
-#define VR_CFG_AUTOOPT 0x00000008 /* enable rx/tx autopoll */
-#define VR_CFG_MIIOPT 0x00000010
-#define VR_CFG_MMIENB 0x00000020 /* memory mapped mode enb */
-#define VR_CFG_JUMPER 0x00000040 /* PHY and oper. mode select */
-#define VR_CFG_EELOAD 0x00000080 /* enable EEPROM programming */
-#define VR_CFG_LATMENB 0x00000100 /* larency timer effect enb. */
-#define VR_CFG_MRREADWAIT 0x00000200
-#define VR_CFG_MRWRITEWAIT 0x00000400
-#define VR_CFG_RX_ARB 0x00000800
-#define VR_CFG_TX_ARB 0x00001000
-#define VR_CFG_READMULTI 0x00002000
-#define VR_CFG_TX_PACE 0x00004000
-#define VR_CFG_TX_QDIS 0x00008000
-#define VR_CFG_ROMSEL0 0x00010000
-#define VR_CFG_ROMSEL1 0x00020000
-#define VR_CFG_ROMSEL2 0x00040000
-#define VR_CFG_ROMTIMESEL 0x00080000
-#define VR_CFG_RSVD0 0x00100000
-#define VR_CFG_ROMDLY 0x00200000
-#define VR_CFG_ROMOPT 0x00400000
-#define VR_CFG_RSVD1 0x00800000
-#define VR_CFG_BACKOFFOPT 0x01000000
-#define VR_CFG_BACKOFFMOD 0x02000000
-#define VR_CFG_CAPEFFECT 0x04000000
-#define VR_CFG_BACKOFFRAND 0x08000000
-#define VR_CFG_MAGICKPACKET 0x10000000
-#define VR_CFG_PCIREADLINE 0x20000000
-#define VR_CFG_DIAG 0x40000000
-#define VR_CFG_GPIOEN 0x80000000
-
-/* Sticky HW bits */
-#define VR_STICKHW_DS0 0x01
-#define VR_STICKHW_DS1 0x02
-#define VR_STICKHW_WOL_ENB 0x04
-#define VR_STICKHW_WOL_STS 0x08
-#define VR_STICKHW_LEGWOL_ENB 0x80
-
-/*
- * BCR0 register bits. (At least for the VT6102 chip.)
- */
-#define VR_BCR0_DMA_LENGTH 0x07
-
-#define VR_BCR0_DMA_32BYTES 0x00
-#define VR_BCR0_DMA_64BYTES 0x01
-#define VR_BCR0_DMA_128BYTES 0x02
-#define VR_BCR0_DMA_256BYTES 0x03
-#define VR_BCR0_DMA_512BYTES 0x04
-#define VR_BCR0_DMA_1024BYTES 0x05
-#define VR_BCR0_DMA_STORENFWD 0x07
-
-#define VR_BCR0_RX_THRESH 0x38
-
-#define VR_BCR0_RXTHRESHCFG 0x00
-#define VR_BCR0_RXTHRESH64BYTES 0x08
-#define VR_BCR0_RXTHRESH128BYTES 0x10
-#define VR_BCR0_RXTHRESH256BYTES 0x18
-#define VR_BCR0_RXTHRESH512BYTES 0x20
-#define VR_BCR0_RXTHRESH1024BYTES 0x28
-#define VR_BCR0_RXTHRESHSTORENFWD 0x38
-#define VR_BCR0_EXTLED 0x40
-#define VR_BCR0_MED2 0x80
-
-/*
- * BCR1 register bits. (At least for the VT6102 chip.)
- */
-#define VR_BCR1_POT0 0x01
-#define VR_BCR1_POT1 0x02
-#define VR_BCR1_POT2 0x04
-#define VR_BCR1_TX_THRESH 0x38
-#define VR_BCR1_TXTHRESHCFG 0x00
-#define VR_BCR1_TXTHRESH64BYTES 0x08
-#define VR_BCR1_TXTHRESH128BYTES 0x10
-#define VR_BCR1_TXTHRESH256BYTES 0x18
-#define VR_BCR1_TXTHRESH512BYTES 0x20
-#define VR_BCR1_TXTHRESH1024BYTES 0x28
-#define VR_BCR1_TXTHRESHSTORENFWD 0x38
-
-/*
- * Rhine TX/RX list structure.
- */
-
-struct vr_desc {
- u_int32_t vr_status;
- u_int32_t vr_ctl;
- u_int32_t vr_ptr1;
- u_int32_t vr_ptr2;
-};
-
-#define vr_data vr_ptr1
-#define vr_next vr_ptr2
-
-
-#define VR_RXSTAT_RXERR 0x00000001
-#define VR_RXSTAT_CRCERR 0x00000002
-#define VR_RXSTAT_FRAMEALIGNERR 0x00000004
-#define VR_RXSTAT_FIFOOFLOW 0x00000008
-#define VR_RXSTAT_GIANT 0x00000010
-#define VR_RXSTAT_RUNT 0x00000020
-#define VR_RXSTAT_BUSERR 0x00000040
-#define VR_RXSTAT_BUFFERR 0x00000080
-#define VR_RXSTAT_LASTFRAG 0x00000100
-#define VR_RXSTAT_FIRSTFRAG 0x00000200
-#define VR_RXSTAT_RLINK 0x00000400
-#define VR_RXSTAT_RX_PHYS 0x00000800
-#define VR_RXSTAT_RX_BROAD 0x00001000
-#define VR_RXSTAT_RX_MULTI 0x00002000
-#define VR_RXSTAT_RX_OK 0x00004000
-#define VR_RXSTAT_RXLEN 0x07FF0000
-#define VR_RXSTAT_RXLEN_EXT 0x78000000
-#define VR_RXSTAT_OWN 0x80000000
-
-#define VR_RXBYTES(x) ((x & VR_RXSTAT_RXLEN) >> 16)
-#define VR_RXSTAT (VR_RXSTAT_FIRSTFRAG|VR_RXSTAT_LASTFRAG|VR_RXSTAT_OWN)
-
-#define VR_RXCTL_BUFLEN 0x000007FF
-#define VR_RXCTL_BUFLEN_EXT 0x00007800
-#define VR_RXCTL_CHAIN 0x00008000
-#define VR_RXCTL_RX_INTR 0x00800000
-
-#define VR_RXCTL (VR_RXCTL_CHAIN|VR_RXCTL_RX_INTR)
-
-#define VR_TXSTAT_DEFER 0x00000001
-#define VR_TXSTAT_UNDERRUN 0x00000002
-#define VR_TXSTAT_COLLCNT 0x00000078
-#define VR_TXSTAT_SQE 0x00000080
-#define VR_TXSTAT_ABRT 0x00000100
-#define VR_TXSTAT_LATECOLL 0x00000200
-#define VR_TXSTAT_CARRLOST 0x00000400
-#define VR_TXSTAT_UDF 0x00000800
-#define VR_TXSTAT_BUSERR 0x00002000
-#define VR_TXSTAT_JABTIMEO 0x00004000
-#define VR_TXSTAT_ERRSUM 0x00008000
-#define VR_TXSTAT_OWN 0x80000000
-
-#define VR_TXCTL_BUFLEN 0x000007FF
-#define VR_TXCTL_BUFLEN_EXT 0x00007800
-#define VR_TXCTL_TLINK 0x00008000
-#define VR_TXCTL_FIRSTFRAG 0x00200000
-#define VR_TXCTL_LASTFRAG 0x00400000
-#define VR_TXCTL_FINT 0x00800000
-
-
-#define VR_MAXFRAGS 16
-#define VR_RX_LIST_CNT 64
-#define VR_TX_LIST_CNT 128
-#define VR_MIN_FRAMELEN 60
-#define VR_FRAMELEN 1536
-#define VR_RXLEN 1520
-
-#define VR_TXOWN(x) x->vr_ptr->vr_status
-
-struct vr_list_data {
- struct vr_desc vr_rx_list[VR_RX_LIST_CNT];
- struct vr_desc vr_tx_list[VR_TX_LIST_CNT];
-};
-
-struct vr_chain {
- struct vr_desc *vr_ptr;
- struct mbuf *vr_mbuf;
- struct vr_chain *vr_nextdesc;
-};
-
-struct vr_chain_onefrag {
- struct vr_desc *vr_ptr;
- struct mbuf *vr_mbuf;
- struct vr_chain_onefrag *vr_nextdesc;
-};
-
-struct vr_chain_data {
- struct vr_chain_onefrag vr_rx_chain[VR_RX_LIST_CNT];
- struct vr_chain vr_tx_chain[VR_TX_LIST_CNT];
-
- struct vr_chain_onefrag *vr_rx_head;
-
- struct vr_chain *vr_tx_head;
- struct vr_chain *vr_tx_tail;
- struct vr_chain *vr_tx_free;
-};
-
-struct vr_type {
- u_int16_t vr_vid;
- u_int16_t vr_did;
- char *vr_name;
-};
-
-struct vr_mii_frame {
- u_int8_t mii_stdelim;
- u_int8_t mii_opcode;
- u_int8_t mii_phyaddr;
- u_int8_t mii_regaddr;
- u_int8_t mii_turnaround;
- u_int16_t mii_data;
-};
-
-/*
- * MII constants
- */
-#define VR_MII_STARTDELIM 0x01
-#define VR_MII_READOP 0x02
-#define VR_MII_WRITEOP 0x01
-#define VR_MII_TURNAROUND 0x02
-
-#define VR_FLAG_FORCEDELAY 1
-#define VR_FLAG_SCHEDDELAY 2
-#define VR_FLAG_DELAYTIMEO 3
-
-struct vr_softc {
- struct arpcom arpcom; /* interface info */
- bus_space_handle_t vr_bhandle; /* bus space handle */
- bus_space_tag_t vr_btag; /* bus space tag */
- struct resource *vr_res;
- struct resource *vr_irq;
- void *vr_intrhand;
- device_t vr_miibus;
- struct vr_type *vr_info; /* Rhine adapter info */
- u_int8_t vr_unit; /* interface number */
- u_int8_t vr_type;
- u_int8_t vr_revid; /* Rhine chip revision */
- u_int8_t vr_flags; /* See VR_F_* below */
- struct vr_list_data *vr_ldata;
- struct vr_chain_data vr_cdata;
- struct callout_handle vr_stat_ch;
- struct mtx vr_mtx;
-};
-
-#define VR_F_RESTART 0x01 /* Restart unit on next tick */
-
-#define VR_LOCK(_sc) mtx_lock(&(_sc)->vr_mtx)
-#define VR_UNLOCK(_sc) mtx_unlock(&(_sc)->vr_mtx)
-
-/*
- * register space access macros
- */
-#define CSR_WRITE_4(sc, reg, val) \
- bus_space_write_4(sc->vr_btag, sc->vr_bhandle, reg, val)
-#define CSR_WRITE_2(sc, reg, val) \
- bus_space_write_2(sc->vr_btag, sc->vr_bhandle, reg, val)
-#define CSR_WRITE_1(sc, reg, val) \
- bus_space_write_1(sc->vr_btag, sc->vr_bhandle, reg, val)
-
-#define CSR_READ_4(sc, reg) \
- bus_space_read_4(sc->vr_btag, sc->vr_bhandle, reg)
-#define CSR_READ_2(sc, reg) \
- bus_space_read_2(sc->vr_btag, sc->vr_bhandle, reg)
-#define CSR_READ_1(sc, reg) \
- bus_space_read_1(sc->vr_btag, sc->vr_bhandle, reg)
-
-#define VR_TIMEOUT 1000
-#define ETHER_ALIGN 2
-
-/*
- * General constants that are fun to know.
- *
- * VIA vendor ID
- */
-#define VIA_VENDORID 0x1106
-
-/*
- * VIA Rhine device IDs.
- */
-#define VIA_DEVICEID_RHINE 0x3043
-#define VIA_DEVICEID_RHINE_II 0x6100
-#define VIA_DEVICEID_RHINE_II_2 0x3065
-#define VIA_DEVICEID_RHINE_III 0x3106
-#define VIA_DEVICEID_RHINE_III_M 0x3053
-
-/*
- * Delta Electronics device ID.
- */
-#define DELTA_VENDORID 0x1500
-
-/*
- * Delta device IDs.
- */
-#define DELTA_DEVICEID_RHINE_II 0x1320
-
-/*
- * Addtron vendor ID.
- */
-#define ADDTRON_VENDORID 0x4033
-
-/*
- * Addtron device IDs.
- */
-#define ADDTRON_DEVICEID_RHINE_II 0x1320
-
-/*
- * VIA Rhine revision IDs
- */
-
-#define REV_ID_VT3043_E 0x04
-#define REV_ID_VT3071_A 0x20
-#define REV_ID_VT3071_B 0x21
-#define REV_ID_VT3065_A 0x40
-#define REV_ID_VT3065_B 0x41
-#define REV_ID_VT3065_C 0x42
-#define REV_ID_VT6102_APOLLO 0x74
-#define REV_ID_VT3106 0x80
-#define REV_ID_VT3106_J 0x80 /* 0x80-0x8F */
-#define REV_ID_VT3106_S 0x90 /* 0x90-0xA0 */
-
-/*
- * PCI low memory base and low I/O base register, and
- * other PCI registers.
- */
-
-#define VR_PCI_VENDOR_ID 0x00
-#define VR_PCI_DEVICE_ID 0x02
-#define VR_PCI_COMMAND 0x04
-#define VR_PCI_STATUS 0x06
-#define VR_PCI_REVID 0x08
-#define VR_PCI_CLASSCODE 0x09
-#define VR_PCI_LATENCY_TIMER 0x0D
-#define VR_PCI_HEADER_TYPE 0x0E
-#define VR_PCI_LOIO 0x10
-#define VR_PCI_LOMEM 0x14
-#define VR_PCI_BIOSROM 0x30
-#define VR_PCI_INTLINE 0x3C
-#define VR_PCI_INTPIN 0x3D
-#define VR_PCI_MINGNT 0x3E
-#define VR_PCI_MINLAT 0x0F
-#define VR_PCI_RESETOPT 0x48
-#define VR_PCI_EEPROM_DATA 0x4C
-#define VR_PCI_MODE 0x50
-
-#define VR_MODE3_MIION 0x04
-
-/* power management registers */
-#define VR_PCI_CAPID 0xDC /* 8 bits */
-#define VR_PCI_NEXTPTR 0xDD /* 8 bits */
-#define VR_PCI_PWRMGMTCAP 0xDE /* 16 bits */
-#define VR_PCI_PWRMGMTCTRL 0xE0 /* 16 bits */
-
-#define VR_PSTATE_MASK 0x0003
-#define VR_PSTATE_D0 0x0000
-#define VR_PSTATE_D1 0x0002
-#define VR_PSTATE_D2 0x0002
-#define VR_PSTATE_D3 0x0003
-#define VR_PME_EN 0x0010
-#define VR_PME_STATUS 0x8000
-
-
-#ifdef __alpha__
-#undef vtophys
-#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)va)
-#endif
diff --git a/sys/fs/cd9660/TODO b/sys/fs/cd9660/TODO
deleted file mode 100644
index b8d7f3efebb9..000000000000
--- a/sys/fs/cd9660/TODO
+++ /dev/null
@@ -1,43 +0,0 @@
-# $FreeBSD$
-
- 2) should understand Rock Ridge
-
- Yes, we have follows function.
-
- o Symbolic Link
- o Real Name(long name)
- o File Attribute
- o Time stamp
- o uid, gid
- o Devices
- o Relocated directories
-
- Except follows:
-
- o POSIX device number mapping
-
- There is some preliminary stuff in there that (ab-)uses the mknod
- system call, but this needs a writable filesystem
-
- 5) should have name translation enabled by mount flag
-
- Yes. we can disable the Rock Ridge Extension by follows option;
-
- "mount -t isofs -o -norrip /dev/cd0d /cdrom"
-
- 6) should run as a user process, and not take up kernel space (cdroms
- are slow)
-
- Not yet.
-
- 7) ECMA support.
-
- Not yet. we need not only a technical spec but also ECMA format
- cd-rom itself!
-
- 8) Character set change by SVD ( multi SVD support )
-
- Not yet. We should also hack the other part of system as 8 bit
- clean. As far as I know, if you export the cdrom by NFS, the client
- can access the 8 bit clean (ie. Solaris Japanese with EUC code )
-
diff --git a/sys/fs/cd9660/TODO.hibler b/sys/fs/cd9660/TODO.hibler
deleted file mode 100644
index e0842da82d5a..000000000000
--- a/sys/fs/cd9660/TODO.hibler
+++ /dev/null
@@ -1,16 +0,0 @@
-$FreeBSD$
-
-1. Investiate making ISOFS another UFS shared filesystem (ala FFS/MFS/LFS).
- Since it was modelled after the inode code, we might be able to merge
- them back. It looks like a separate (but very similar) lookup routine
- will be needed due to the associated file stuff.
-
-2. It would be nice to be able to use the vfs_cluster code.
- Unfortunately, if the logical block size is smaller than the page size,
- it won't work. Also, if throughtput is relatively constant for any
- block size (as it is for the HP drive--150kbs) then clustering may not
- buy much (or may even hurt when vfs_cluster comes up with a large sync
- cluster).
-
-3. Seems like there should be a "notrans" or some such mount option to show
- filenames as they really are without lower-casing. Does this make sense?
diff --git a/sys/fs/cd9660/cd9660_bmap.c b/sys/fs/cd9660/cd9660_bmap.c
deleted file mode 100644
index 42692897485f..000000000000
--- a/sys/fs/cd9660/cd9660_bmap.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*-
- * Copyright (c) 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley
- * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
- * Support code is derived from software contributed to Berkeley
- * by Atsushi Murai (amurai@spec.co.jp).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)cd9660_bmap.c 8.3 (Berkeley) 1/23/94
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-
-#include <isofs/cd9660/iso.h>
-#include <isofs/cd9660/cd9660_node.h>
-
-/*
- * Bmap converts a the logical block number of a file to its physical block
- * number on the disk. The conversion is done by using the logical block
- * number to index into the data block (extent) for the file.
- */
-int
-cd9660_bmap(ap)
- struct vop_bmap_args /* {
- struct vnode *a_vp;
- daddr_t a_bn;
- struct vnode **a_vpp;
- daddr_t *a_bnp;
- int *a_runp;
- int *a_runb;
- } */ *ap;
-{
- struct iso_node *ip = VTOI(ap->a_vp);
- daddr_t lblkno = ap->a_bn;
- int bshift;
-
- /*
- * Check for underlying vnode requests and ensure that logical
- * to physical mapping is requested.
- */
- if (ap->a_vpp != NULL)
- *ap->a_vpp = ip->i_devvp;
- if (ap->a_bnp == NULL)
- return (0);
-
- /*
- * Compute the requested block number
- */
- bshift = ip->i_mnt->im_bshift;
- *ap->a_bnp = (ip->iso_start + lblkno) << (bshift - DEV_BSHIFT);
-
- /*
- * Determine maximum number of readahead blocks following the
- * requested block.
- */
- if (ap->a_runp) {
- int nblk;
-
- nblk = (ip->i_size >> bshift) - (lblkno + 1);
- if (nblk <= 0)
- *ap->a_runp = 0;
- else if (nblk >= (MAXBSIZE >> bshift))
- *ap->a_runp = (MAXBSIZE >> bshift) - 1;
- else
- *ap->a_runp = nblk;
- }
-
- if (ap->a_runb) {
- *ap->a_runb = 0;
- }
-
- return 0;
-}
diff --git a/sys/fs/cd9660/cd9660_lookup.c b/sys/fs/cd9660/cd9660_lookup.c
deleted file mode 100644
index 5c7805e64ab8..000000000000
--- a/sys/fs/cd9660/cd9660_lookup.c
+++ /dev/null
@@ -1,452 +0,0 @@
-/*-
- * 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 Pace Willisson (pace@blitz.com). The Rock Ridge Extension
- * Support code is derived from software contributed to Berkeley
- * by Atsushi Murai (amurai@spec.co.jp).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)ufs_lookup.c 7.33 (Berkeley) 5/19/91
- *
- * @(#)cd9660_lookup.c 8.2 (Berkeley) 1/23/94
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/namei.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-
-#include <isofs/cd9660/iso.h>
-#include <isofs/cd9660/cd9660_node.h>
-#include <isofs/cd9660/iso_rrip.h>
-
-/*
- * Convert a component of a pathname into a pointer to a locked inode.
- * This is a very central and rather complicated routine.
- * If the filesystem is not maintained in a strict tree hierarchy,
- * this can result in a deadlock situation (see comments in code below).
- *
- * The flag argument is LOOKUP, CREATE, RENAME, or DELETE depending on
- * whether the name is to be looked up, created, renamed, or deleted.
- * When CREATE, RENAME, or DELETE is specified, information usable in
- * creating, renaming, or deleting a directory entry may be calculated.
- * If flag has LOCKPARENT or'ed into it and the target of the pathname
- * exists, lookup returns both the target and its parent directory locked.
- * When creating or renaming and LOCKPARENT is specified, the target may
- * not be ".". When deleting and LOCKPARENT is specified, the target may
- * be "."., but the caller must check to ensure it does an vrele and iput
- * instead of two iputs.
- *
- * Overall outline of ufs_lookup:
- *
- * search for name in directory, to found or notfound
- * notfound:
- * if creating, return locked directory, leaving info on available slots
- * else return error
- * found:
- * if at end of path and deleting, return information to allow delete
- * if at end of path and rewriting (RENAME and LOCKPARENT), lock target
- * inode and return info to allow rewrite
- * if not at end, add name to cache; if at end and neither creating
- * nor deleting, add name to cache
- *
- * NOTE: (LOOKUP | LOCKPARENT) currently returns the parent inode unlocked.
- */
-int
-cd9660_lookup(ap)
- struct vop_cachedlookup_args /* {
- struct vnode *a_dvp;
- struct vnode **a_vpp;
- struct componentname *a_cnp;
- } */ *ap;
-{
- register struct vnode *vdp; /* vnode for directory being searched */
- register struct iso_node *dp; /* inode for directory being searched */
- register struct iso_mnt *imp; /* filesystem that directory is in */
- struct buf *bp; /* a buffer of directory entries */
- struct iso_directory_record *ep = 0;/* the current directory entry */
- int entryoffsetinblock; /* offset of ep in bp's buffer */
- int saveoffset = 0; /* offset of last directory entry in dir */
- int numdirpasses; /* strategy for directory search */
- doff_t endsearch; /* offset to end directory search */
- struct vnode *pdp; /* saved dp during symlink work */
- struct vnode *tdp; /* returned by cd9660_vget_internal */
- u_long bmask; /* block offset mask */
- int lockparent; /* 1 => lockparent flag is set */
- int wantparent; /* 1 => wantparent or lockparent flag */
- int error;
- ino_t ino = 0;
- int reclen;
- u_short namelen;
- int isoflags;
- char altname[NAME_MAX];
- int res;
- int assoc, len;
- char *name;
- struct vnode **vpp = ap->a_vpp;
- struct componentname *cnp = ap->a_cnp;
- int flags = cnp->cn_flags;
- int nameiop = cnp->cn_nameiop;
- struct thread *td = cnp->cn_thread;
-
- bp = NULL;
- *vpp = NULL;
- vdp = ap->a_dvp;
- dp = VTOI(vdp);
- imp = dp->i_mnt;
- lockparent = flags & LOCKPARENT;
- wantparent = flags & (LOCKPARENT|WANTPARENT);
- cnp->cn_flags &= ~PDIRUNLOCK;
-
- /*
- * We now have a segment name to search for, and a directory to search.
- */
-
- len = cnp->cn_namelen;
- name = cnp->cn_nameptr;
- /*
- * A leading `=' means, we are looking for an associated file
- */
- if ((assoc = (imp->iso_ftype != ISO_FTYPE_RRIP && *name == ASSOCCHAR)))
- {
- len--;
- name++;
- }
-
- /*
- * If there is cached information on a previous search of
- * this directory, pick up where we last left off.
- * We cache only lookups as these are the most common
- * and have the greatest payoff. Caching CREATE has little
- * benefit as it usually must search the entire directory
- * to determine that the entry does not exist. Caching the
- * location of the last DELETE or RENAME has not reduced
- * profiling time and hence has been removed in the interest
- * of simplicity.
- */
- bmask = imp->im_bmask;
- if (nameiop != LOOKUP || dp->i_diroff == 0 ||
- dp->i_diroff > dp->i_size) {
- entryoffsetinblock = 0;
- dp->i_offset = 0;
- numdirpasses = 1;
- } else {
- dp->i_offset = dp->i_diroff;
- if ((entryoffsetinblock = dp->i_offset & bmask) &&
- (error = cd9660_blkatoff(vdp, (off_t)dp->i_offset, NULL, &bp)))
- return (error);
- numdirpasses = 2;
- nchstats.ncs_2passes++;
- }
- endsearch = dp->i_size;
-
-searchloop:
- while (dp->i_offset < endsearch) {
- /*
- * If offset is on a block boundary,
- * read the next directory block.
- * Release previous if it exists.
- */
- if ((dp->i_offset & bmask) == 0) {
- if (bp != NULL)
- brelse(bp);
- if ((error =
- cd9660_blkatoff(vdp, (off_t)dp->i_offset, NULL, &bp)) != 0)
- return (error);
- entryoffsetinblock = 0;
- }
- /*
- * Get pointer to next entry.
- */
- ep = (struct iso_directory_record *)
- ((char *)bp->b_data + entryoffsetinblock);
-
- reclen = isonum_711(ep->length);
- if (reclen == 0) {
- /* skip to next block, if any */
- dp->i_offset =
- (dp->i_offset & ~bmask) + imp->logical_block_size;
- continue;
- }
-
- if (reclen < ISO_DIRECTORY_RECORD_SIZE)
- /* illegal entry, stop */
- break;
-
- if (entryoffsetinblock + reclen > imp->logical_block_size)
- /* entries are not allowed to cross boundaries */
- break;
-
- namelen = isonum_711(ep->name_len);
- isoflags = isonum_711(imp->iso_ftype == ISO_FTYPE_HIGH_SIERRA?
- &ep->date[6]: ep->flags);
-
- if (reclen < ISO_DIRECTORY_RECORD_SIZE + namelen)
- /* illegal entry, stop */
- break;
-
- /*
- * Check for a name match.
- */
- switch (imp->iso_ftype) {
- default:
- if (!(isoflags & 4) == !assoc) {
- if ((len == 1
- && *name == '.')
- || (flags & ISDOTDOT)) {
- if (namelen == 1
- && ep->name[0] == ((flags & ISDOTDOT) ? 1 : 0)) {
- /*
- * Save directory entry's inode number and
- * release directory buffer.
- */
- dp->i_ino = isodirino(ep, imp);
- goto found;
- }
- if (namelen != 1
- || ep->name[0] != 0)
- goto notfound;
- } else if (!(res = isofncmp(name, len, ep->name, namelen, imp->joliet_level))) {
- if (isoflags & 2)
- ino = isodirino(ep, imp);
- else
- ino = dbtob(bp->b_blkno)
- + entryoffsetinblock;
- saveoffset = dp->i_offset;
- } else if (ino)
- goto foundino;
-#ifdef NOSORTBUG /* On some CDs directory entries are not sorted correctly */
- else if (res < 0)
- goto notfound;
- else if (res > 0 && numdirpasses == 2)
- numdirpasses++;
-#endif
- }
- break;
- case ISO_FTYPE_RRIP:
- if (isonum_711(ep->flags)&2)
- ino = isodirino(ep, imp);
- else
- ino = dbtob(bp->b_blkno) + entryoffsetinblock;
- dp->i_ino = ino;
- cd9660_rrip_getname(ep,altname,&namelen,&dp->i_ino,imp);
- if (namelen == cnp->cn_namelen
- && !bcmp(name,altname,namelen))
- goto found;
- ino = 0;
- break;
- }
- dp->i_offset += reclen;
- entryoffsetinblock += reclen;
- }
- if (ino) {
-foundino:
- dp->i_ino = ino;
- if (saveoffset != dp->i_offset) {
- if (lblkno(imp, dp->i_offset) !=
- lblkno(imp, saveoffset)) {
- if (bp != NULL)
- brelse(bp);
- if ((error = cd9660_blkatoff(vdp,
- (off_t)saveoffset, NULL, &bp)) != 0)
- return (error);
- }
- entryoffsetinblock = saveoffset & bmask;
- ep = (struct iso_directory_record *)
- ((char *)bp->b_data + entryoffsetinblock);
- dp->i_offset = saveoffset;
- }
- goto found;
- }
-notfound:
- /*
- * If we started in the middle of the directory and failed
- * to find our target, we must check the beginning as well.
- */
- if (numdirpasses == 2) {
- numdirpasses--;
- dp->i_offset = 0;
- endsearch = dp->i_diroff;
- goto searchloop;
- }
- if (bp != NULL)
- brelse(bp);
-
- /*
- * Insert name into cache (as non-existent) if appropriate.
- */
- if (cnp->cn_flags & MAKEENTRY)
- cache_enter(vdp, *vpp, cnp);
- if (nameiop == CREATE || nameiop == RENAME)
- return (EROFS);
- return (ENOENT);
-
-found:
- if (numdirpasses == 2)
- nchstats.ncs_pass2++;
-
- /*
- * Found component in pathname.
- * If the final component of path name, save information
- * in the cache as to where the entry was found.
- */
- if ((flags & ISLASTCN) && nameiop == LOOKUP)
- dp->i_diroff = dp->i_offset;
-
- /*
- * Step through the translation in the name. We do not `iput' the
- * directory because we may need it again if a symbolic link
- * is relative to the current directory. Instead we save it
- * unlocked as "pdp". We must get the target inode before unlocking
- * the directory to insure that the inode will not be removed
- * before we get it. We prevent deadlock by always fetching
- * inodes from the root, moving down the directory tree. Thus
- * when following backward pointers ".." we must unlock the
- * parent directory before getting the requested directory.
- * There is a potential race condition here if both the current
- * and parent directories are removed before the `iget' for the
- * inode associated with ".." returns. We hope that this occurs
- * infrequently since we cannot avoid this race condition without
- * implementing a sophisticated deadlock detection algorithm.
- * Note also that this simple deadlock detection scheme will not
- * work if the filesystem has any hard links other than ".."
- * that point backwards in the directory structure.
- */
- pdp = vdp;
- /*
- * If ino is different from dp->i_ino,
- * it's a relocated directory.
- */
- if (flags & ISDOTDOT) {
- VOP_UNLOCK(pdp, 0, td); /* race to get the inode */
- error = cd9660_vget_internal(vdp->v_mount, dp->i_ino,
- LK_EXCLUSIVE, &tdp,
- dp->i_ino != ino, ep);
- brelse(bp);
- if (error) {
- vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY, td);
- return (error);
- }
- if (lockparent && (flags & ISLASTCN)) {
- if ((error = vn_lock(pdp, LK_EXCLUSIVE, td)) != 0) {
- cnp->cn_flags |= PDIRUNLOCK;
- vput(tdp);
- return (error);
- }
- } else
- cnp->cn_flags |= PDIRUNLOCK;
- *vpp = tdp;
- } else if (dp->i_number == dp->i_ino) {
- brelse(bp);
- VREF(vdp); /* we want ourself, ie "." */
- *vpp = vdp;
- } else {
- error = cd9660_vget_internal(vdp->v_mount, dp->i_ino,
- LK_EXCLUSIVE, &tdp,
- dp->i_ino != ino, ep);
- brelse(bp);
- if (error)
- return (error);
- if (!lockparent || !(flags & ISLASTCN)) {
- cnp->cn_flags |= PDIRUNLOCK;
- VOP_UNLOCK(pdp, 0, td);
- }
- *vpp = tdp;
- }
-
- /*
- * Insert name into cache if appropriate.
- */
- if (cnp->cn_flags & MAKEENTRY)
- cache_enter(vdp, *vpp, cnp);
- return (0);
-}
-
-/*
- * Return buffer with the contents of block "offset" from the beginning of
- * directory "ip". If "res" is non-zero, fill it in with a pointer to the
- * remaining space in the directory.
- */
-int
-cd9660_blkatoff(vp, offset, res, bpp)
- struct vnode *vp;
- off_t offset;
- char **res;
- struct buf **bpp;
-{
- struct iso_node *ip;
- register struct iso_mnt *imp;
- struct buf *bp;
- daddr_t lbn;
- int bsize, error;
-
- ip = VTOI(vp);
- imp = ip->i_mnt;
- lbn = lblkno(imp, offset);
- bsize = blksize(imp, ip, lbn);
-
- if ((error = bread(vp, lbn, bsize, NOCRED, &bp)) != 0) {
- brelse(bp);
- *bpp = NULL;
- return (error);
- }
-
- /*
- * We must BMAP the buffer because the directory code may use b_blkno
- * to calculate the inode for certain types of directory entries.
- * We could get away with not doing it before we VMIO-backed the
- * directories because the buffers would get freed atomically with
- * the invalidation of their data. But with VMIO-backed buffers
- * the buffers may be freed and then later reconstituted - and the
- * reconstituted buffer will have no knowledge of b_blkno.
- */
- if (bp->b_blkno == bp->b_lblkno) {
- error = VOP_BMAP(vp, bp->b_lblkno, NULL,
- &bp->b_blkno, NULL, NULL);
- if (error) {
- bp->b_error = error;
- bp->b_ioflags |= BIO_ERROR;
- brelse(bp);
- *bpp = NULL;
- return (error);
- }
- }
-
- if (res)
- *res = (char *)bp->b_data + blkoff(imp, offset);
- *bpp = bp;
- return (0);
-}
diff --git a/sys/fs/cd9660/cd9660_mount.h b/sys/fs/cd9660/cd9660_mount.h
deleted file mode 100644
index 8cc6a8655fa4..000000000000
--- a/sys/fs/cd9660/cd9660_mount.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 1995
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley
- * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
- * Support code is derived from software contributed to Berkeley
- * by Atsushi Murai (amurai@spec.co.jp).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)cd9660_mount.h 8.1 (Berkeley) 5/24/95
- * $FreeBSD$
- */
-
-/*
- * Arguments to mount ISO 9660 filesystems.
- */
-struct iso_args {
- char *fspec; /* block special device to mount */
- struct export_args export; /* network export info */
- int flags; /* mounting flags, see below */
- int ssector; /* starting sector, 0 for 1st session */
-};
-#define ISOFSMNT_NORRIP 0x00000001 /* disable Rock Ridge Ext.*/
-#define ISOFSMNT_GENS 0x00000002 /* enable generation numbers */
-#define ISOFSMNT_EXTATT 0x00000004 /* enable extended attributes */
-#define ISOFSMNT_NOJOLIET 0x00000008 /* disable Joliet Ext.*/
-#define ISOFSMNT_BROKENJOLIET 0x00000010/* allow broken Joliet disks */
diff --git a/sys/fs/cd9660/cd9660_node.c b/sys/fs/cd9660/cd9660_node.c
deleted file mode 100644
index e120bc4c00e2..000000000000
--- a/sys/fs/cd9660/cd9660_node.c
+++ /dev/null
@@ -1,444 +0,0 @@
-/*-
- * Copyright (c) 1982, 1986, 1989, 1994, 1995
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley
- * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
- * Support code is derived from software contributed to Berkeley
- * by Atsushi Murai (amurai@spec.co.jp).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)cd9660_node.c 8.2 (Berkeley) 1/23/94
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/mount.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/vnode.h>
-#include <sys/malloc.h>
-#include <sys/stat.h>
-#include <sys/mutex.h>
-
-#include <isofs/cd9660/iso.h>
-#include <isofs/cd9660/cd9660_node.h>
-#include <isofs/cd9660/cd9660_mount.h>
-
-/*
- * Structures associated with iso_node caching.
- */
-static struct iso_node **isohashtbl;
-static u_long isohash;
-#define INOHASH(device, inum) ((minor(device) + ((inum)>>12)) & isohash)
-static struct mtx cd9660_ihash_mtx;
-
-static void cd9660_ihashrem(struct iso_node *);
-static unsigned cd9660_chars2ui(unsigned char *begin, int len);
-
-/*
- * Initialize hash links for inodes and dnodes.
- */
-int
-cd9660_init(vfsp)
- struct vfsconf *vfsp;
-{
-
- isohashtbl = hashinit(desiredvnodes, M_ISOFSMNT, &isohash);
- mtx_init(&cd9660_ihash_mtx, "cd9660_ihash", NULL, MTX_DEF);
- return (0);
-}
-
-int
-cd9660_uninit(vfsp)
- struct vfsconf *vfsp;
-{
-
- if (isohashtbl != NULL)
- free(isohashtbl, M_ISOFSMNT);
- return (0);
-}
-
-
-/*
- * Use the device/inum pair to find the incore inode, and return a pointer
- * to it. If it is in core, but locked, wait for it.
- */
-int
-cd9660_ihashget(dev, inum, flags, vpp)
- dev_t dev;
- ino_t inum;
- int flags;
- struct vnode **vpp;
-{
- struct thread *td = curthread; /* XXX */
- struct iso_node *ip;
- struct vnode *vp;
- int error;
-
- *vpp = NULL;
-loop:
- mtx_lock(&cd9660_ihash_mtx);
- for (ip = isohashtbl[INOHASH(dev, inum)]; ip; ip = ip->i_next) {
- if (inum == ip->i_number && dev == ip->i_dev) {
- vp = ITOV(ip);
- mtx_lock(&vp->v_interlock);
- mtx_unlock(&cd9660_ihash_mtx);
- error = vget(vp, flags | LK_INTERLOCK, td);
- if (error == ENOENT)
- goto loop;
- if (error)
- return (error);
- *vpp = vp;
- return (0);
- }
- }
- mtx_unlock(&cd9660_ihash_mtx);
- return (0);
-}
-
-/*
- * Insert the inode into the hash table, and return it locked.
- */
-void
-cd9660_ihashins(ip)
- struct iso_node *ip;
-{
- struct iso_node **ipp, *iq;
-
- mtx_lock(&cd9660_ihash_mtx);
- ipp = &isohashtbl[INOHASH(ip->i_dev, ip->i_number)];
- if ((iq = *ipp) != NULL)
- iq->i_prev = &ip->i_next;
- ip->i_next = iq;
- ip->i_prev = ipp;
- *ipp = ip;
- mtx_unlock(&cd9660_ihash_mtx);
-
- vn_lock(ITOV(ip), LK_EXCLUSIVE | LK_RETRY, curthread);
-}
-
-/*
- * Remove the inode from the hash table.
- */
-static void
-cd9660_ihashrem(ip)
- register struct iso_node *ip;
-{
- register struct iso_node *iq;
-
- mtx_lock(&cd9660_ihash_mtx);
- if ((iq = ip->i_next) != NULL)
- iq->i_prev = ip->i_prev;
- *ip->i_prev = iq;
-#ifdef DIAGNOSTIC
- ip->i_next = NULL;
- ip->i_prev = NULL;
-#endif
- mtx_unlock(&cd9660_ihash_mtx);
-}
-
-/*
- * Last reference to an inode, write the inode out and if necessary,
- * truncate and deallocate the file.
- */
-int
-cd9660_inactive(ap)
- struct vop_inactive_args /* {
- struct vnode *a_vp;
- struct thread *a_td;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct thread *td = ap->a_td;
- register struct iso_node *ip = VTOI(vp);
- int error = 0;
-
- if (prtactive && vrefcnt(vp) != 0)
- vprint("cd9660_inactive: pushing active", vp);
-
- ip->i_flag = 0;
- VOP_UNLOCK(vp, 0, td);
- /*
- * If we are done with the inode, reclaim it
- * so that it can be reused immediately.
- */
- if (ip->inode.iso_mode == 0)
- vrecycle(vp, NULL, td);
- return error;
-}
-
-/*
- * Reclaim an inode so that it can be used for other purposes.
- */
-int
-cd9660_reclaim(ap)
- struct vop_reclaim_args /* {
- struct vnode *a_vp;
- struct thread *a_td;
- } */ *ap;
-{
- register struct vnode *vp = ap->a_vp;
- register struct iso_node *ip = VTOI(vp);
-
- if (prtactive && vrefcnt(vp) != 0)
- vprint("cd9660_reclaim: pushing active", vp);
- /*
- * Remove the inode from its hash chain.
- */
- cd9660_ihashrem(ip);
- /*
- * Purge old data structures associated with the inode.
- */
- cache_purge(vp);
- if (ip->i_devvp) {
- vrele(ip->i_devvp);
- ip->i_devvp = 0;
- }
- FREE(vp->v_data, M_ISOFSNODE);
- vp->v_data = NULL;
- return (0);
-}
-
-/*
- * File attributes
- */
-void
-cd9660_defattr(isodir, inop, bp, ftype)
- struct iso_directory_record *isodir;
- struct iso_node *inop;
- struct buf *bp;
- enum ISO_FTYPE ftype;
-{
- struct buf *bp2 = NULL;
- struct iso_mnt *imp;
- struct iso_extended_attributes *ap = NULL;
- int off;
-
- /* high sierra does not have timezone data, flag is one byte ahead */
- if (isonum_711(ftype == ISO_FTYPE_HIGH_SIERRA?
- &isodir->date[6]: isodir->flags)&2) {
- inop->inode.iso_mode = S_IFDIR;
- /*
- * If we return 2, fts() will assume there are no subdirectories
- * (just links for the path and .), so instead we return 1.
- */
- inop->inode.iso_links = 1;
- } else {
- inop->inode.iso_mode = S_IFREG;
- inop->inode.iso_links = 1;
- }
- if (!bp
- && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
- && (off = isonum_711(isodir->ext_attr_length))) {
- cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL,
- &bp2);
- bp = bp2;
- }
- if (bp) {
- ap = (struct iso_extended_attributes *)bp->b_data;
-
- if (isonum_711(ap->version) == 1) {
- if (!(ap->perm[0]&0x40))
- inop->inode.iso_mode |= VEXEC >> 6;
- if (!(ap->perm[0]&0x10))
- inop->inode.iso_mode |= VREAD >> 6;
- if (!(ap->perm[0]&4))
- inop->inode.iso_mode |= VEXEC >> 3;
- if (!(ap->perm[0]&1))
- inop->inode.iso_mode |= VREAD >> 3;
- if (!(ap->perm[1]&0x40))
- inop->inode.iso_mode |= VEXEC;
- if (!(ap->perm[1]&0x10))
- inop->inode.iso_mode |= VREAD;
- inop->inode.iso_uid = isonum_723(ap->owner); /* what about 0? */
- inop->inode.iso_gid = isonum_723(ap->group); /* what about 0? */
- } else
- ap = NULL;
- }
- if (!ap) {
- inop->inode.iso_mode |= VREAD|VEXEC|(VREAD|VEXEC)>>3|(VREAD|VEXEC)>>6;
- inop->inode.iso_uid = (uid_t)0;
- inop->inode.iso_gid = (gid_t)0;
- }
- if (bp2)
- brelse(bp2);
-}
-
-/*
- * Time stamps
- */
-void
-cd9660_deftstamp(isodir,inop,bp,ftype)
- struct iso_directory_record *isodir;
- struct iso_node *inop;
- struct buf *bp;
- enum ISO_FTYPE ftype;
-{
- struct buf *bp2 = NULL;
- struct iso_mnt *imp;
- struct iso_extended_attributes *ap = NULL;
- int off;
-
- if (!bp
- && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
- && (off = isonum_711(isodir->ext_attr_length))) {
- cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL,
- &bp2);
- bp = bp2;
- }
- if (bp) {
- ap = (struct iso_extended_attributes *)bp->b_data;
-
- if (ftype != ISO_FTYPE_HIGH_SIERRA
- && isonum_711(ap->version) == 1) {
- if (!cd9660_tstamp_conv17(ap->ftime,&inop->inode.iso_atime))
- cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_atime);
- if (!cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_ctime))
- inop->inode.iso_ctime = inop->inode.iso_atime;
- if (!cd9660_tstamp_conv17(ap->mtime,&inop->inode.iso_mtime))
- inop->inode.iso_mtime = inop->inode.iso_ctime;
- } else
- ap = NULL;
- }
- if (!ap) {
- cd9660_tstamp_conv7(isodir->date,&inop->inode.iso_ctime,ftype);
- inop->inode.iso_atime = inop->inode.iso_ctime;
- inop->inode.iso_mtime = inop->inode.iso_ctime;
- }
- if (bp2)
- brelse(bp2);
-}
-
-int
-cd9660_tstamp_conv7(pi,pu,ftype)
- u_char *pi;
- struct timespec *pu;
- enum ISO_FTYPE ftype;
-{
- int crtime, days;
- int y, m, d, hour, minute, second, tz;
-
- y = pi[0] + 1900;
- m = pi[1];
- d = pi[2];
- hour = pi[3];
- minute = pi[4];
- second = pi[5];
- if(ftype != ISO_FTYPE_HIGH_SIERRA)
- tz = pi[6];
- else
- /* original high sierra misses timezone data */
- tz = 0;
-
- if (y < 1970) {
- pu->tv_sec = 0;
- pu->tv_nsec = 0;
- return 0;
- } else {
-#ifdef ORIGINAL
- /* computes day number relative to Sept. 19th,1989 */
- /* don't even *THINK* about changing formula. It works! */
- days = 367*(y-1980)-7*(y+(m+9)/12)/4-3*((y+(m-9)/7)/100+1)/4+275*m/9+d-100;
-#else
- /*
- * Changed :-) to make it relative to Jan. 1st, 1970
- * and to disambiguate negative division
- */
- days = 367*(y-1960)-7*(y+(m+9)/12)/4-3*((y+(m+9)/12-1)/100+1)/4+275*m/9+d-239;
-#endif
- crtime = ((((days * 24) + hour) * 60 + minute) * 60) + second;
-
- /* timezone offset is unreliable on some disks */
- if (-48 <= tz && tz <= 52)
- crtime -= tz * 15 * 60;
- }
- pu->tv_sec = crtime;
- pu->tv_nsec = 0;
- return 1;
-}
-
-static u_int
-cd9660_chars2ui(begin,len)
- u_char *begin;
- int len;
-{
- u_int rc;
-
- for (rc = 0; --len >= 0;) {
- rc *= 10;
- rc += *begin++ - '0';
- }
- return rc;
-}
-
-int
-cd9660_tstamp_conv17(pi,pu)
- u_char *pi;
- struct timespec *pu;
-{
- u_char buf[7];
-
- /* year:"0001"-"9999" -> -1900 */
- buf[0] = cd9660_chars2ui(pi,4) - 1900;
-
- /* month: " 1"-"12" -> 1 - 12 */
- buf[1] = cd9660_chars2ui(pi + 4,2);
-
- /* day: " 1"-"31" -> 1 - 31 */
- buf[2] = cd9660_chars2ui(pi + 6,2);
-
- /* hour: " 0"-"23" -> 0 - 23 */
- buf[3] = cd9660_chars2ui(pi + 8,2);
-
- /* minute:" 0"-"59" -> 0 - 59 */
- buf[4] = cd9660_chars2ui(pi + 10,2);
-
- /* second:" 0"-"59" -> 0 - 59 */
- buf[5] = cd9660_chars2ui(pi + 12,2);
-
- /* difference of GMT */
- buf[6] = pi[16];
-
- return cd9660_tstamp_conv7(buf, pu, ISO_FTYPE_DEFAULT);
-}
-
-ino_t
-isodirino(isodir, imp)
- struct iso_directory_record *isodir;
- struct iso_mnt *imp;
-{
- ino_t ino;
-
- ino = (isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length))
- << imp->im_bshift;
- return (ino);
-}
diff --git a/sys/fs/cd9660/cd9660_node.h b/sys/fs/cd9660/cd9660_node.h
deleted file mode 100644
index 47ea9dd3a0e5..000000000000
--- a/sys/fs/cd9660/cd9660_node.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/*-
- * Copyright (c) 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley
- * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
- * Support code is derived from software contributed to Berkeley
- * by Atsushi Murai (amurai@spec.co.jp).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)cd9660_node.h 8.6 (Berkeley) 5/14/95
- * $FreeBSD$
- */
-
-/*
- * Theoretically, directories can be more than 2Gb in length,
- * however, in practice this seems unlikely. So, we define
- * the type doff_t as a long to keep down the cost of doing
- * lookup on a 32-bit machine. If you are porting to a 64-bit
- * architecture, you should make doff_t the same as off_t.
- */
-#define doff_t long
-
-typedef struct {
- struct timespec iso_atime; /* time of last access */
- struct timespec iso_mtime; /* time of last modification */
- struct timespec iso_ctime; /* time file changed */
- u_short iso_mode; /* files access mode and type */
- uid_t iso_uid; /* owner user id */
- gid_t iso_gid; /* owner group id */
- short iso_links; /* links of file */
- udev_t iso_rdev; /* Major/Minor number for special */
-} ISO_RRIP_INODE;
-
-
-struct iso_node {
- struct iso_node *i_next, **i_prev; /* hash chain */
- struct vnode *i_vnode; /* vnode associated with this inode */
- struct vnode *i_devvp; /* vnode for block I/O */
- u_long i_flag; /* see below */
- dev_t i_dev; /* device where inode resides */
- ino_t i_number; /* the identity of the inode */
- /* we use the actual starting block of the file */
- struct iso_mnt *i_mnt; /* filesystem associated with this inode */
- struct lockf *i_lockf; /* head of byte-level lock list */
- doff_t i_endoff; /* end of useful stuff in directory */
- doff_t i_diroff; /* offset in dir, where we found last entry */
- doff_t i_offset; /* offset of free space in directory */
- ino_t i_ino; /* inode number of found directory */
-
- long iso_extent; /* extent of file */
- long i_size;
- long iso_start; /* actual start of data of file (may be different */
- /* from iso_extent, if file has extended attributes) */
- ISO_RRIP_INODE inode;
-};
-
-#define i_forw i_chain[0]
-#define i_back i_chain[1]
-
-/* flags */
-#define IN_ACCESS 0x0020 /* inode access time to be updated */
-
-#define VTOI(vp) ((struct iso_node *)(vp)->v_data)
-#define ITOV(ip) ((ip)->i_vnode)
-
-#ifdef _KERNEL
-
-#ifdef MALLOC_DECLARE
-MALLOC_DECLARE(M_ISOFSMNT);
-MALLOC_DECLARE(M_ISOFSNODE);
-#endif
-
-struct buf;
-struct vop_bmap_args;
-struct vop_cachedlookup_args;
-struct vop_inactive_args;
-struct vop_reclaim_args;
-
-/*
- * Prototypes for ISOFS vnode operations
- */
-int cd9660_lookup(struct vop_cachedlookup_args *);
-int cd9660_inactive(struct vop_inactive_args *);
-int cd9660_reclaim(struct vop_reclaim_args *);
-int cd9660_bmap(struct vop_bmap_args *);
-int cd9660_blkatoff(struct vnode *vp, off_t offset, char **res, struct buf **bpp);
-
-void cd9660_defattr(struct iso_directory_record *,
- struct iso_node *, struct buf *, enum ISO_FTYPE);
-void cd9660_deftstamp(struct iso_directory_record *,
- struct iso_node *, struct buf *, enum ISO_FTYPE);
-int cd9660_ihashget(dev_t, ino_t, int, struct vnode **);
-void cd9660_ihashins(struct iso_node *);
-int cd9660_tstamp_conv7(u_char *, struct timespec *, enum ISO_FTYPE);
-int cd9660_tstamp_conv17(u_char *, struct timespec *);
-
-#endif /* _KERNEL */
diff --git a/sys/fs/cd9660/cd9660_rrip.c b/sys/fs/cd9660/cd9660_rrip.c
deleted file mode 100644
index 88f47fa4c187..000000000000
--- a/sys/fs/cd9660/cd9660_rrip.c
+++ /dev/null
@@ -1,717 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley
- * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
- * Support code is derived from software contributed to Berkeley
- * by Atsushi Murai (amurai@spec.co.jp).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)cd9660_rrip.c 8.6 (Berkeley) 12/5/94
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/kernel.h>
-
-#include <isofs/cd9660/iso.h>
-#include <isofs/cd9660/cd9660_node.h>
-#include <isofs/cd9660/cd9660_rrip.h>
-#include <isofs/cd9660/iso_rrip.h>
-
-typedef int rrt_func_t(void *, ISO_RRIP_ANALYZE *ana);
-
-typedef struct {
- char type[2];
- rrt_func_t *func;
- void (*func2)(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana);
- int result;
-} RRIP_TABLE;
-
-static int cd9660_rrip_altname(ISO_RRIP_ALTNAME *p, ISO_RRIP_ANALYZE *ana);
-static int cd9660_rrip_attr(ISO_RRIP_ATTR *p, ISO_RRIP_ANALYZE *ana);
-static int cd9660_rrip_cont(ISO_RRIP_CONT *p, ISO_RRIP_ANALYZE *ana);
-static void cd9660_rrip_defattr(struct iso_directory_record *isodir,
- ISO_RRIP_ANALYZE *ana);
-static void cd9660_rrip_defname(struct iso_directory_record *isodir,
- ISO_RRIP_ANALYZE *ana);
-static void cd9660_rrip_deftstamp(struct iso_directory_record *isodir,
- ISO_RRIP_ANALYZE *ana);
-static int cd9660_rrip_device(ISO_RRIP_DEVICE *p, ISO_RRIP_ANALYZE *ana);
-static int cd9660_rrip_extref(ISO_RRIP_EXTREF *p, ISO_RRIP_ANALYZE *ana);
-static int cd9660_rrip_idflag(ISO_RRIP_IDFLAG *p, ISO_RRIP_ANALYZE *ana);
-static int cd9660_rrip_loop(struct iso_directory_record *isodir,
- ISO_RRIP_ANALYZE *ana, RRIP_TABLE *table);
-static int cd9660_rrip_pclink(ISO_RRIP_CLINK *p, ISO_RRIP_ANALYZE *ana);
-static int cd9660_rrip_reldir(ISO_RRIP_RELDIR *p, ISO_RRIP_ANALYZE *ana);
-static int cd9660_rrip_slink(ISO_RRIP_SLINK *p, ISO_RRIP_ANALYZE *ana);
-static int cd9660_rrip_stop(ISO_SUSP_HEADER *p, ISO_RRIP_ANALYZE *ana);
-static int cd9660_rrip_tstamp(ISO_RRIP_TSTAMP *p, ISO_RRIP_ANALYZE *ana);
-
-/*
- * POSIX file attribute
- */
-static int
-cd9660_rrip_attr(p,ana)
- ISO_RRIP_ATTR *p;
- ISO_RRIP_ANALYZE *ana;
-{
- ana->inop->inode.iso_mode = isonum_733(p->mode);
- ana->inop->inode.iso_uid = isonum_733(p->uid);
- ana->inop->inode.iso_gid = isonum_733(p->gid);
- ana->inop->inode.iso_links = isonum_733(p->links);
- ana->fields &= ~ISO_SUSP_ATTR;
- return ISO_SUSP_ATTR;
-}
-
-static void
-cd9660_rrip_defattr(isodir,ana)
- struct iso_directory_record *isodir;
- ISO_RRIP_ANALYZE *ana;
-{
- /* But this is a required field! */
- printf("RRIP without PX field?\n");
- cd9660_defattr(isodir,ana->inop,NULL,ISO_FTYPE_RRIP);
-}
-
-/*
- * Symbolic Links
- */
-static int
-cd9660_rrip_slink(p,ana)
- ISO_RRIP_SLINK *p;
- ISO_RRIP_ANALYZE *ana;
-{
- register ISO_RRIP_SLINK_COMPONENT *pcomp;
- register ISO_RRIP_SLINK_COMPONENT *pcompe;
- int len, wlen, cont;
- char *outbuf, *inbuf;
-
- pcomp = (ISO_RRIP_SLINK_COMPONENT *)p->component;
- pcompe = (ISO_RRIP_SLINK_COMPONENT *)((char *)p + isonum_711(p->h.length));
- len = *ana->outlen;
- outbuf = ana->outbuf;
- cont = ana->cont;
-
- /*
- * Gathering a Symbolic name from each component with path
- */
- for (;
- pcomp < pcompe;
- pcomp = (ISO_RRIP_SLINK_COMPONENT *)((char *)pcomp + ISO_RRIP_SLSIZ
- + isonum_711(pcomp->clen))) {
-
- if (!cont) {
- if (len < ana->maxlen) {
- len++;
- *outbuf++ = '/';
- }
- }
- cont = 0;
-
- inbuf = "..";
- wlen = 0;
-
- switch (*pcomp->cflag) {
-
- case ISO_SUSP_CFLAG_CURRENT:
- /* Inserting Current */
- wlen = 1;
- break;
-
- case ISO_SUSP_CFLAG_PARENT:
- /* Inserting Parent */
- wlen = 2;
- break;
-
- case ISO_SUSP_CFLAG_ROOT:
- /* Inserting slash for ROOT */
- /* start over from beginning(?) */
- outbuf -= len;
- len = 0;
- break;
-
- case ISO_SUSP_CFLAG_VOLROOT:
- /* Inserting a mount point i.e. "/cdrom" */
- /* same as above */
- outbuf -= len;
- len = 0;
- inbuf = ana->imp->im_mountp->mnt_stat.f_mntonname;
- wlen = strlen(inbuf);
- break;
-
- case ISO_SUSP_CFLAG_HOST:
- /* Inserting hostname i.e. "kurt.tools.de" */
- inbuf = hostname;
- wlen = strlen(hostname);
- break;
-
- case ISO_SUSP_CFLAG_CONTINUE:
- cont = 1;
- /* FALLTHROUGH */
- case 0:
- /* Inserting component */
- wlen = isonum_711(pcomp->clen);
- inbuf = pcomp->name;
- break;
- default:
- printf("RRIP with incorrect flags?");
- wlen = ana->maxlen + 1;
- break;
- }
-
- if (len + wlen > ana->maxlen) {
- /* indicate error to caller */
- ana->cont = 1;
- ana->fields = 0;
- ana->outbuf -= *ana->outlen;
- *ana->outlen = 0;
- return 0;
- }
-
- bcopy(inbuf,outbuf,wlen);
- outbuf += wlen;
- len += wlen;
-
- }
- ana->outbuf = outbuf;
- *ana->outlen = len;
- ana->cont = cont;
-
- if (!isonum_711(p->flags)) {
- ana->fields &= ~ISO_SUSP_SLINK;
- return ISO_SUSP_SLINK;
- }
- return 0;
-}
-
-/*
- * Alternate name
- */
-static int
-cd9660_rrip_altname(p,ana)
- ISO_RRIP_ALTNAME *p;
- ISO_RRIP_ANALYZE *ana;
-{
- char *inbuf;
- int wlen;
- int cont;
-
- inbuf = "..";
- wlen = 0;
- cont = 0;
-
- switch (*p->flags) {
- case ISO_SUSP_CFLAG_CURRENT:
- /* Inserting Current */
- wlen = 1;
- break;
-
- case ISO_SUSP_CFLAG_PARENT:
- /* Inserting Parent */
- wlen = 2;
- break;
-
- case ISO_SUSP_CFLAG_HOST:
- /* Inserting hostname i.e. "kurt.tools.de" */
- inbuf = hostname;
- wlen = strlen(hostname);
- break;
-
- case ISO_SUSP_CFLAG_CONTINUE:
- cont = 1;
- /* FALLTHROUGH */
- case 0:
- /* Inserting component */
- wlen = isonum_711(p->h.length) - 5;
- inbuf = (char *)p + 5;
- break;
-
- default:
- printf("RRIP with incorrect NM flags?\n");
- wlen = ana->maxlen + 1;
- break;
- }
-
- if ((*ana->outlen += wlen) > ana->maxlen) {
- /* treat as no name field */
- ana->fields &= ~ISO_SUSP_ALTNAME;
- ana->outbuf -= *ana->outlen - wlen;
- *ana->outlen = 0;
- return 0;
- }
-
- bcopy(inbuf,ana->outbuf,wlen);
- ana->outbuf += wlen;
-
- if (!cont) {
- ana->fields &= ~ISO_SUSP_ALTNAME;
- return ISO_SUSP_ALTNAME;
- }
- return 0;
-}
-
-static void
-cd9660_rrip_defname(isodir,ana)
- struct iso_directory_record *isodir;
- ISO_RRIP_ANALYZE *ana;
-{
- isofntrans(isodir->name,isonum_711(isodir->name_len),
- ana->outbuf,ana->outlen,
- 1,isonum_711(isodir->flags)&4, ana->imp->joliet_level);
- switch (*ana->outbuf) {
- default:
- break;
- case 1:
- *ana->outlen = 2;
- /* FALLTHROUGH */
- case 0:
- /* outlen is 1 already */
- strcpy(ana->outbuf,"..");
- break;
- }
-}
-
-/*
- * Parent or Child Link
- */
-static int
-cd9660_rrip_pclink(p,ana)
- ISO_RRIP_CLINK *p;
- ISO_RRIP_ANALYZE *ana;
-{
- *ana->inump = isonum_733(p->dir_loc) << ana->imp->im_bshift;
- ana->fields &= ~(ISO_SUSP_CLINK|ISO_SUSP_PLINK);
- return *p->h.type == 'C' ? ISO_SUSP_CLINK : ISO_SUSP_PLINK;
-}
-
-/*
- * Relocated directory
- */
-static int
-cd9660_rrip_reldir(p,ana)
- ISO_RRIP_RELDIR *p;
- ISO_RRIP_ANALYZE *ana;
-{
- /* special hack to make caller aware of RE field */
- *ana->outlen = 0;
- ana->fields = 0;
- return ISO_SUSP_RELDIR|ISO_SUSP_ALTNAME|ISO_SUSP_CLINK|ISO_SUSP_PLINK;
-}
-
-static int
-cd9660_rrip_tstamp(p,ana)
- ISO_RRIP_TSTAMP *p;
- ISO_RRIP_ANALYZE *ana;
-{
- u_char *ptime;
-
- ptime = p->time;
-
- /* Check a format of time stamp (7bytes/17bytes) */
- if (!(*p->flags&ISO_SUSP_TSTAMP_FORM17)) {
- if (*p->flags&ISO_SUSP_TSTAMP_CREAT)
- ptime += 7;
-
- if (*p->flags&ISO_SUSP_TSTAMP_MODIFY) {
- cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_mtime,
- ISO_FTYPE_RRIP);
- ptime += 7;
- } else
- bzero(&ana->inop->inode.iso_mtime,sizeof(struct timespec));
-
- if (*p->flags&ISO_SUSP_TSTAMP_ACCESS) {
- cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_atime,
- ISO_FTYPE_RRIP);
- ptime += 7;
- } else
- ana->inop->inode.iso_atime = ana->inop->inode.iso_mtime;
-
- if (*p->flags&ISO_SUSP_TSTAMP_ATTR)
- cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_ctime,
- ISO_FTYPE_RRIP);
- else
- ana->inop->inode.iso_ctime = ana->inop->inode.iso_mtime;
-
- } else {
- if (*p->flags&ISO_SUSP_TSTAMP_CREAT)
- ptime += 17;
-
- if (*p->flags&ISO_SUSP_TSTAMP_MODIFY) {
- cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_mtime);
- ptime += 17;
- } else
- bzero(&ana->inop->inode.iso_mtime,sizeof(struct timespec));
-
- if (*p->flags&ISO_SUSP_TSTAMP_ACCESS) {
- cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_atime);
- ptime += 17;
- } else
- ana->inop->inode.iso_atime = ana->inop->inode.iso_mtime;
-
- if (*p->flags&ISO_SUSP_TSTAMP_ATTR)
- cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_ctime);
- else
- ana->inop->inode.iso_ctime = ana->inop->inode.iso_mtime;
-
- }
- ana->fields &= ~ISO_SUSP_TSTAMP;
- return ISO_SUSP_TSTAMP;
-}
-
-static void
-cd9660_rrip_deftstamp(isodir,ana)
- struct iso_directory_record *isodir;
- ISO_RRIP_ANALYZE *ana;
-{
- cd9660_deftstamp(isodir,ana->inop,NULL,ISO_FTYPE_RRIP);
-}
-
-/*
- * POSIX device modes
- */
-static int
-cd9660_rrip_device(p,ana)
- ISO_RRIP_DEVICE *p;
- ISO_RRIP_ANALYZE *ana;
-{
- u_int high, low;
-
- high = isonum_733(p->dev_t_high);
- low = isonum_733(p->dev_t_low);
-
- if (high == 0)
- ana->inop->inode.iso_rdev = makeudev(umajor(low), uminor(low));
- else
- ana->inop->inode.iso_rdev = makeudev(high, uminor(low));
- ana->fields &= ~ISO_SUSP_DEVICE;
- return ISO_SUSP_DEVICE;
-}
-
-/*
- * Flag indicating
- */
-static int
-cd9660_rrip_idflag(p,ana)
- ISO_RRIP_IDFLAG *p;
- ISO_RRIP_ANALYZE *ana;
-{
- ana->fields &= isonum_711(p->flags)|~0xff; /* don't touch high bits */
- /* special handling of RE field */
- if (ana->fields&ISO_SUSP_RELDIR)
- return cd9660_rrip_reldir(/* XXX */ (ISO_RRIP_RELDIR *)p,ana);
-
- return ISO_SUSP_IDFLAG;
-}
-
-/*
- * Continuation pointer
- */
-static int
-cd9660_rrip_cont(p,ana)
- ISO_RRIP_CONT *p;
- ISO_RRIP_ANALYZE *ana;
-{
- ana->iso_ce_blk = isonum_733(p->location);
- ana->iso_ce_off = isonum_733(p->offset);
- ana->iso_ce_len = isonum_733(p->length);
- return ISO_SUSP_CONT;
-}
-
-/*
- * System Use end
- */
-static int
-cd9660_rrip_stop(p,ana)
- ISO_SUSP_HEADER *p;
- ISO_RRIP_ANALYZE *ana;
-{
- return ISO_SUSP_STOP;
-}
-
-/*
- * Extension reference
- */
-static int
-cd9660_rrip_extref(p,ana)
- ISO_RRIP_EXTREF *p;
- ISO_RRIP_ANALYZE *ana;
-{
- if (isonum_711(p->len_id) != 10
- || bcmp((char *)p + 8,"RRIP_1991A",10)
- || isonum_711(p->version) != 1)
- return 0;
- ana->fields &= ~ISO_SUSP_EXTREF;
- return ISO_SUSP_EXTREF;
-}
-
-static int
-cd9660_rrip_loop(isodir,ana,table)
- struct iso_directory_record *isodir;
- ISO_RRIP_ANALYZE *ana;
- RRIP_TABLE *table;
-{
- register RRIP_TABLE *ptable;
- register ISO_SUSP_HEADER *phead;
- register ISO_SUSP_HEADER *pend;
- struct buf *bp = NULL;
- char *pwhead;
- u_char c;
- int result;
-
- /*
- * Note: If name length is odd,
- * it will be padding 1 byte after the name
- */
- pwhead = isodir->name + isonum_711(isodir->name_len);
- if (!(isonum_711(isodir->name_len)&1))
- pwhead++;
- isochar(isodir->name, pwhead, ana->imp->joliet_level, &c);
-
- /* If it's not the '.' entry of the root dir obey SP field */
- if (c != 0 || isonum_733(isodir->extent) != ana->imp->root_extent)
- pwhead += ana->imp->rr_skip;
- else
- pwhead += ana->imp->rr_skip0;
-
- phead = (ISO_SUSP_HEADER *)pwhead;
- pend = (ISO_SUSP_HEADER *)((char *)isodir + isonum_711(isodir->length));
-
- result = 0;
- while (1) {
- ana->iso_ce_len = 0;
- /*
- * Note: "pend" should be more than one SUSP header
- */
- while (pend >= phead + 1) {
- if (isonum_711(phead->version) == 1) {
- for (ptable = table; ptable->func; ptable++) {
- if (*phead->type == *ptable->type
- && phead->type[1] == ptable->type[1]) {
- result |= ptable->func(phead,ana);
- break;
- }
- }
- if (!ana->fields)
- break;
- }
- if (result&ISO_SUSP_STOP) {
- result &= ~ISO_SUSP_STOP;
- break;
- }
- /* plausibility check */
- if (isonum_711(phead->length) < sizeof(*phead))
- break;
- /*
- * move to next SUSP
- * Hopefully this works with newer versions, too
- */
- phead = (ISO_SUSP_HEADER *)((char *)phead + isonum_711(phead->length));
- }
-
- if (ana->fields && ana->iso_ce_len) {
- if (ana->iso_ce_blk >= ana->imp->volume_space_size
- || ana->iso_ce_off + ana->iso_ce_len > ana->imp->logical_block_size
- || bread(ana->imp->im_devvp,
- ana->iso_ce_blk <<
- (ana->imp->im_bshift - DEV_BSHIFT),
- ana->imp->logical_block_size, NOCRED, &bp))
- /* what to do now? */
- break;
- phead = (ISO_SUSP_HEADER *)(bp->b_data + ana->iso_ce_off);
- pend = (ISO_SUSP_HEADER *) ((char *)phead + ana->iso_ce_len);
- } else
- break;
- }
- if (bp)
- brelse(bp);
- /*
- * If we don't find the Basic SUSP stuffs, just set default value
- * (attribute/time stamp)
- */
- for (ptable = table; ptable->func2; ptable++)
- if (!(ptable->result&result))
- ptable->func2(isodir,ana);
-
- return result;
-}
-
-/*
- * Get Attributes.
- */
-/*
- * XXX the casts are bogus but will do for now.
- */
-#define BC (rrt_func_t *)
-static RRIP_TABLE rrip_table_analyze[] = {
- { "PX", BC cd9660_rrip_attr, cd9660_rrip_defattr, ISO_SUSP_ATTR },
- { "TF", BC cd9660_rrip_tstamp, cd9660_rrip_deftstamp, ISO_SUSP_TSTAMP },
- { "PN", BC cd9660_rrip_device, 0, ISO_SUSP_DEVICE },
- { "RR", BC cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG },
- { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT },
- { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP },
- { "", 0, 0, 0 }
-};
-
-int
-cd9660_rrip_analyze(isodir,inop,imp)
- struct iso_directory_record *isodir;
- struct iso_node *inop;
- struct iso_mnt *imp;
-{
- ISO_RRIP_ANALYZE analyze;
-
- analyze.inop = inop;
- analyze.imp = imp;
- analyze.fields = ISO_SUSP_ATTR|ISO_SUSP_TSTAMP|ISO_SUSP_DEVICE;
-
- return cd9660_rrip_loop(isodir,&analyze,rrip_table_analyze);
-}
-
-/*
- * Get Alternate Name.
- */
-static RRIP_TABLE rrip_table_getname[] = {
- { "NM", BC cd9660_rrip_altname, cd9660_rrip_defname, ISO_SUSP_ALTNAME },
- { "CL", BC cd9660_rrip_pclink, 0, ISO_SUSP_CLINK|ISO_SUSP_PLINK },
- { "PL", BC cd9660_rrip_pclink, 0, ISO_SUSP_CLINK|ISO_SUSP_PLINK },
- { "RE", BC cd9660_rrip_reldir, 0, ISO_SUSP_RELDIR },
- { "RR", BC cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG },
- { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT },
- { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP },
- { "", 0, 0, 0 }
-};
-
-int
-cd9660_rrip_getname(isodir,outbuf,outlen,inump,imp)
- struct iso_directory_record *isodir;
- char *outbuf;
- u_short *outlen;
- ino_t *inump;
- struct iso_mnt *imp;
-{
- ISO_RRIP_ANALYZE analyze;
- RRIP_TABLE *tab;
- u_char c;
-
- analyze.outbuf = outbuf;
- analyze.outlen = outlen;
- analyze.maxlen = NAME_MAX;
- analyze.inump = inump;
- analyze.imp = imp;
- analyze.fields = ISO_SUSP_ALTNAME|ISO_SUSP_RELDIR|ISO_SUSP_CLINK|ISO_SUSP_PLINK;
- *outlen = 0;
-
- isochar(isodir->name, isodir->name + isonum_711(isodir->name_len),
- imp->joliet_level, &c);
- tab = rrip_table_getname;
- if (c == 0 || c == 1) {
- cd9660_rrip_defname(isodir,&analyze);
-
- analyze.fields &= ~ISO_SUSP_ALTNAME;
- tab++;
- }
-
- return cd9660_rrip_loop(isodir,&analyze,tab);
-}
-
-/*
- * Get Symbolic Link.
- */
-static RRIP_TABLE rrip_table_getsymname[] = {
- { "SL", BC cd9660_rrip_slink, 0, ISO_SUSP_SLINK },
- { "RR", BC cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG },
- { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT },
- { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP },
- { "", 0, 0, 0 }
-};
-
-int
-cd9660_rrip_getsymname(isodir,outbuf,outlen,imp)
- struct iso_directory_record *isodir;
- char *outbuf;
- u_short *outlen;
- struct iso_mnt *imp;
-{
- ISO_RRIP_ANALYZE analyze;
-
- analyze.outbuf = outbuf;
- analyze.outlen = outlen;
- *outlen = 0;
- analyze.maxlen = MAXPATHLEN;
- analyze.cont = 1; /* don't start with a slash */
- analyze.imp = imp;
- analyze.fields = ISO_SUSP_SLINK;
-
- return (cd9660_rrip_loop(isodir,&analyze,rrip_table_getsymname)&ISO_SUSP_SLINK);
-}
-
-static RRIP_TABLE rrip_table_extref[] = {
- { "ER", BC cd9660_rrip_extref, 0, ISO_SUSP_EXTREF },
- { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT },
- { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP },
- { "", 0, 0, 0 }
-};
-
-/*
- * Check for Rock Ridge Extension and return offset of its fields.
- * Note: We insist on the ER field.
- */
-int
-cd9660_rrip_offset(isodir,imp)
- struct iso_directory_record *isodir;
- struct iso_mnt *imp;
-{
- ISO_RRIP_OFFSET *p;
- ISO_RRIP_ANALYZE analyze;
-
- imp->rr_skip0 = 0;
- p = (ISO_RRIP_OFFSET *)(isodir->name + 1);
- if (bcmp(p,"SP\7\1\276\357",6)) {
- /* Maybe, it's a CDROM XA disc? */
- imp->rr_skip0 = 15;
- p = (ISO_RRIP_OFFSET *)((char *)p + 15);
- if (bcmp(p,"SP\7\1\276\357",6))
- return -1;
- }
-
- analyze.imp = imp;
- analyze.fields = ISO_SUSP_EXTREF;
- if (!(cd9660_rrip_loop(isodir,&analyze,rrip_table_extref)&ISO_SUSP_EXTREF))
- return -1;
-
- return isonum_711(p->skip);
-}
diff --git a/sys/fs/cd9660/cd9660_rrip.h b/sys/fs/cd9660/cd9660_rrip.h
deleted file mode 100644
index 5008abf2a0ac..000000000000
--- a/sys/fs/cd9660/cd9660_rrip.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley
- * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
- * Support code is derived from software contributed to Berkeley
- * by Atsushi Murai (amurai@spec.co.jp).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)cd9660_rrip.h 8.2 (Berkeley) 12/5/94
- * $FreeBSD$
- */
-
-typedef struct {
- char type [ISODCL ( 0, 1)];
- u_char length [ISODCL ( 2, 2)]; /* 711 */
- u_char version [ISODCL ( 3, 3)];
-} ISO_SUSP_HEADER;
-
-typedef struct {
- ISO_SUSP_HEADER h;
- char mode [ISODCL ( 4, 11)]; /* 733 */
- char links [ISODCL ( 12, 19)]; /* 733 */
- char uid [ISODCL ( 20, 27)]; /* 733 */
- char gid [ISODCL ( 28, 35)]; /* 733 */
-} ISO_RRIP_ATTR;
-
-typedef struct {
- ISO_SUSP_HEADER h;
- char dev_t_high [ISODCL ( 4, 11)]; /* 733 */
- char dev_t_low [ISODCL ( 12, 19)]; /* 733 */
-} ISO_RRIP_DEVICE;
-
-#define ISO_SUSP_CFLAG_CONTINUE 0x01
-#define ISO_SUSP_CFLAG_CURRENT 0x02
-#define ISO_SUSP_CFLAG_PARENT 0x04
-#define ISO_SUSP_CFLAG_ROOT 0x08
-#define ISO_SUSP_CFLAG_VOLROOT 0x10
-#define ISO_SUSP_CFLAG_HOST 0x20
-
-typedef struct {
- u_char cflag [ISODCL ( 1, 1)];
- u_char clen [ISODCL ( 2, 2)];
- u_char name [1]; /* XXX */
-} ISO_RRIP_SLINK_COMPONENT;
-#define ISO_RRIP_SLSIZ 2
-
-typedef struct {
- ISO_SUSP_HEADER h;
- u_char flags [ISODCL ( 4, 4)];
- u_char component [ISODCL ( 5, 5)];
-} ISO_RRIP_SLINK;
-
-typedef struct {
- ISO_SUSP_HEADER h;
- char flags [ISODCL ( 4, 4)];
-} ISO_RRIP_ALTNAME;
-
-typedef struct {
- ISO_SUSP_HEADER h;
- char dir_loc [ISODCL ( 4, 11)]; /* 733 */
-} ISO_RRIP_CLINK;
-
-typedef struct {
- ISO_SUSP_HEADER h;
- char dir_loc [ISODCL ( 4, 11)]; /* 733 */
-} ISO_RRIP_PLINK;
-
-typedef struct {
- ISO_SUSP_HEADER h;
-} ISO_RRIP_RELDIR;
-
-#define ISO_SUSP_TSTAMP_FORM17 0x80
-#define ISO_SUSP_TSTAMP_FORM7 0x00
-#define ISO_SUSP_TSTAMP_CREAT 0x01
-#define ISO_SUSP_TSTAMP_MODIFY 0x02
-#define ISO_SUSP_TSTAMP_ACCESS 0x04
-#define ISO_SUSP_TSTAMP_ATTR 0x08
-#define ISO_SUSP_TSTAMP_BACKUP 0x10
-#define ISO_SUSP_TSTAMP_EXPIRE 0x20
-#define ISO_SUSP_TSTAMP_EFFECT 0x40
-
-typedef struct {
- ISO_SUSP_HEADER h;
- u_char flags [ISODCL ( 4, 4)];
- u_char time [ISODCL ( 5, 5)];
-} ISO_RRIP_TSTAMP;
-
-typedef struct {
- ISO_SUSP_HEADER h;
- u_char flags [ISODCL ( 4, 4)];
-} ISO_RRIP_IDFLAG;
-
-typedef struct {
- ISO_SUSP_HEADER h;
- char len_id [ISODCL ( 4, 4)];
- char len_des [ISODCL ( 5, 5)];
- char len_src [ISODCL ( 6, 6)];
- char version [ISODCL ( 7, 7)];
-} ISO_RRIP_EXTREF;
-
-typedef struct {
- ISO_SUSP_HEADER h;
- char check [ISODCL ( 4, 5)];
- char skip [ISODCL ( 6, 6)];
-} ISO_RRIP_OFFSET;
-
-typedef struct {
- ISO_SUSP_HEADER h;
- char location [ISODCL ( 4, 11)];
- char offset [ISODCL ( 12, 19)];
- char length [ISODCL ( 20, 27)];
-} ISO_RRIP_CONT;
diff --git a/sys/fs/cd9660/cd9660_util.c b/sys/fs/cd9660/cd9660_util.c
deleted file mode 100644
index 87475e6c4fd2..000000000000
--- a/sys/fs/cd9660/cd9660_util.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/*-
- * Copyright (c) 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley
- * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
- * Support code is derived from software contributed to Berkeley
- * by Atsushi Murai (amurai@spec.co.jp). Joliet support was added by
- * Joachim Kuebart (joki@kuebart.stuttgart.netsurf.de).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)cd9660_util.c 8.3 (Berkeley) 12/5/94
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/mount.h>
-#include <sys/vnode.h>
-
-#include <isofs/cd9660/iso.h>
-
-/*
- * XXX: limited support for loading of Unicode
- * conversion routine as a kld at a run-time.
- * Should be removed when native Unicode kernel
- * interfaces have been introduced.
- */
-u_char (*cd9660_wchar2char)(u_int32_t wchar) = NULL;
-
-/*
- * Get one character out of an iso filename
- * Obey joliet_level
- * Return number of bytes consumed
- */
-int
-isochar(isofn, isoend, joliet_level, c)
- u_char *isofn;
- u_char *isoend;
- int joliet_level;
- u_char *c;
-{
- *c = *isofn++;
- if (joliet_level == 0 || isofn == isoend)
- /* (00) and (01) are one byte in Joliet, too */
- return 1;
-
- /* No Unicode support yet :-( */
- switch (*c) {
- default:
- *c = '?';
- break;
- case '\0':
- *c = *isofn;
- break;
- }
- /* XXX: if Unicode conversion routine is loaded then use it */
- if (cd9660_wchar2char != NULL)
- *c = cd9660_wchar2char((*(isofn - 1) << 8) | *isofn);
-
- return 2;
-}
-
-/*
- * translate and compare a filename
- * returns (fn - isofn)
- * Note: Version number plus ';' may be omitted.
- */
-int
-isofncmp(fn, fnlen, isofn, isolen, joliet_level)
- u_char *fn;
- int fnlen;
- u_char *isofn;
- int isolen;
- int joliet_level;
-{
- int i, j;
- u_char c, *fnend = fn + fnlen, *isoend = isofn + isolen;
-
- for (; fn != fnend; fn++) {
- if (isofn == isoend)
- return *fn;
- isofn += isochar(isofn, isoend, joliet_level, &c);
- if (c == ';') {
- if (*fn++ != ';')
- return fn[-1];
- for (i = 0; fn != fnend; i = i * 10 + *fn++ - '0') {
- if (*fn < '0' || *fn > '9') {
- return -1;
- }
- }
- for (j = 0; isofn != isoend; j = j * 10 + c - '0')
- isofn += isochar(isofn, isoend,
- joliet_level, &c);
- return i - j;
- }
- if (c != *fn) {
- if (c >= 'A' && c <= 'Z') {
- if (c + ('a' - 'A') != *fn) {
- if (*fn >= 'a' && *fn <= 'z')
- return *fn - ('a' - 'A') - c;
- else
- return *fn - c;
- }
- } else
- return *fn - c;
- }
- }
- if (isofn != isoend) {
- isofn += isochar(isofn, isoend, joliet_level, &c);
- switch (c) {
- default:
- return -c;
- case '.':
- if (isofn != isoend) {
- isochar(isofn, isoend, joliet_level, &c);
- if (c == ';')
- return 0;
- }
- return -1;
- case ';':
- return 0;
- }
- }
- return 0;
-}
-
-/*
- * translate a filename of length > 0
- */
-void
-isofntrans(infn, infnlen, outfn, outfnlen, original, assoc, joliet_level)
- u_char *infn;
- int infnlen;
- u_char *outfn;
- u_short *outfnlen;
- int original;
- int assoc;
- int joliet_level;
-{
- int fnidx = 0;
- u_char c, d = '\0', *infnend = infn + infnlen;
-
- if (assoc) {
- *outfn++ = ASSOCCHAR;
- fnidx++;
- }
- for (; infn != infnend; fnidx++) {
- infn += isochar(infn, infnend, joliet_level, &c);
-
- if (!original && !joliet_level && c >= 'A' && c <= 'Z')
- *outfn++ = c + ('a' - 'A');
- else if (!original && c == ';') {
- fnidx -= (d == '.');
- break;
- } else
- *outfn++ = c;
- d = c;
- }
- *outfnlen = fnidx;
-}
diff --git a/sys/fs/cd9660/cd9660_vfsops.c b/sys/fs/cd9660/cd9660_vfsops.c
deleted file mode 100644
index b5aff73b0f49..000000000000
--- a/sys/fs/cd9660/cd9660_vfsops.c
+++ /dev/null
@@ -1,898 +0,0 @@
-/*-
- * Copyright (c) 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley
- * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
- * Support code is derived from software contributed to Berkeley
- * by Atsushi Murai (amurai@spec.co.jp).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)cd9660_vfsops.c 8.18 (Berkeley) 5/22/95
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/namei.h>
-#include <sys/proc.h>
-#include <sys/kernel.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/cdio.h>
-#include <sys/conf.h>
-#include <sys/fcntl.h>
-#include <sys/malloc.h>
-#include <sys/stat.h>
-#include <sys/syslog.h>
-
-
-#include <isofs/cd9660/iso.h>
-#include <isofs/cd9660/iso_rrip.h>
-#include <isofs/cd9660/cd9660_node.h>
-#include <isofs/cd9660/cd9660_mount.h>
-
-MALLOC_DEFINE(M_ISOFSMNT, "ISOFS mount", "ISOFS mount structure");
-MALLOC_DEFINE(M_ISOFSNODE, "ISOFS node", "ISOFS vnode private part");
-
-static vfs_mount_t cd9660_mount;
-static vfs_unmount_t cd9660_unmount;
-static vfs_root_t cd9660_root;
-static vfs_statfs_t cd9660_statfs;
-static vfs_vget_t cd9660_vget;
-static vfs_fhtovp_t cd9660_fhtovp;
-static vfs_vptofh_t cd9660_vptofh;
-
-static struct vfsops cd9660_vfsops = {
- cd9660_mount,
- vfs_stdstart,
- cd9660_unmount,
- cd9660_root,
- vfs_stdquotactl,
- cd9660_statfs,
- vfs_stdnosync,
- cd9660_vget,
- cd9660_fhtovp,
- vfs_stdcheckexp,
- cd9660_vptofh,
- cd9660_init,
- cd9660_uninit,
- vfs_stdextattrctl,
-};
-VFS_SET(cd9660_vfsops, cd9660, VFCF_READONLY);
-MODULE_VERSION(cd9660, 1);
-
-
-/*
- * Called by vfs_mountroot when iso is going to be mounted as root.
- */
-
-static int iso_get_ssector(dev_t dev, struct thread *td);
-static int iso_mountfs(struct vnode *devvp, struct mount *mp,
- struct thread *td, struct iso_args *argp);
-
-/*
- * Try to find the start of the last data track on this CD-ROM. This
- * is used to mount the last session of a multi-session CD. Bail out
- * and return 0 if we fail, this is always a safe bet.
- */
-static int
-iso_get_ssector(dev, td)
- dev_t dev;
- struct thread *td;
-{
- struct ioc_toc_header h;
- struct ioc_read_toc_single_entry t;
- int i;
- struct cdevsw *bd;
- d_ioctl_t *ioctlp;
-
- bd = devsw(dev);
- ioctlp = bd->d_ioctl;
- if (ioctlp == NULL)
- return 0;
-
- if (ioctlp(dev, CDIOREADTOCHEADER, (caddr_t)&h, FREAD, td) != 0)
- return 0;
-
- for (i = h.ending_track; i >= 0; i--) {
- t.address_format = CD_LBA_FORMAT;
- t.track = i;
- if (ioctlp(dev, CDIOREADTOCENTRY, (caddr_t)&t, FREAD, td) != 0)
- return 0;
- if ((t.entry.control & 4) != 0)
- /* found a data track */
- break;
- }
-
- if (i < 0)
- return 0;
-
- return ntohl(t.entry.addr.lba);
-}
-
-static int iso_mountroot(struct mount *mp, struct thread *td);
-
-static int
-iso_mountroot(mp, td)
- struct mount *mp;
- struct thread *td;
-{
- struct iso_args args;
- int error;
-
- if ((error = bdevvp(rootdev, &rootvp))) {
- printf("iso_mountroot: can't find rootvp\n");
- return (error);
- }
- args.flags = ISOFSMNT_ROOT;
-
- vn_lock(rootvp, LK_EXCLUSIVE | LK_RETRY, td);
- error = VOP_OPEN(rootvp, FREAD, FSCRED, td);
- VOP_UNLOCK(rootvp, 0, td);
- if (error)
- return error;
-
- args.ssector = iso_get_ssector(rootdev, td);
-
- (void)VOP_CLOSE(rootvp, FREAD, NOCRED, td);
-
- if (bootverbose)
- printf("iso_mountroot(): using session at block %d\n",
- args.ssector);
- if ((error = iso_mountfs(rootvp, mp, td, &args)) != 0)
- return (error);
-
- (void)cd9660_statfs(mp, &mp->mnt_stat, td);
- return (0);
-}
-
-/*
- * VFS Operations.
- *
- * mount system call
- */
-static int
-cd9660_mount(mp, path, data, ndp, td)
- register struct mount *mp;
- char *path;
- caddr_t data;
- struct nameidata *ndp;
- struct thread *td;
-{
- struct vnode *devvp;
- struct iso_args args;
- size_t size;
- int error;
- mode_t accessmode;
- struct iso_mnt *imp = 0;
-
- if (path == NULL) /* We are doing the initial root mount */
- return (iso_mountroot(mp, td));
- if ((error = copyin(data, (caddr_t)&args, sizeof (struct iso_args))))
- return (error);
-
- if ((mp->mnt_flag & MNT_RDONLY) == 0)
- return (EROFS);
-
- /*
- * If updating, check whether changing from read-only to
- * read/write; if there is no device name, that's all we do.
- */
- if (mp->mnt_flag & MNT_UPDATE) {
- imp = VFSTOISOFS(mp);
- if (args.fspec == 0)
- return (vfs_export(mp, &args.export));
- }
- /*
- * Not an update, or updating the name: look up the name
- * and verify that it refers to a sensible block device.
- */
- NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, td);
- if ((error = namei(ndp)))
- return (error);
- NDFREE(ndp, NDF_ONLY_PNBUF);
- devvp = ndp->ni_vp;
-
- if (!vn_isdisk(devvp, &error)) {
- vrele(devvp);
- return (error);
- }
-
- /*
- * Verify that user has necessary permissions on the device,
- * or has superuser abilities
- */
- accessmode = VREAD;
- vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
- error = VOP_ACCESS(devvp, accessmode, td->td_ucred, td);
- if (error)
- error = suser(td);
- if (error) {
- vput(devvp);
- return (error);
- }
- VOP_UNLOCK(devvp, 0, td);
-
- if ((mp->mnt_flag & MNT_UPDATE) == 0) {
- error = iso_mountfs(devvp, mp, td, &args);
- } else {
- if (devvp != imp->im_devvp)
- error = EINVAL; /* needs translation */
- else
- vrele(devvp);
- }
- if (error) {
- vrele(devvp);
- return error;
- }
- imp = VFSTOISOFS(mp);
- (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
- &size);
- bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
- (void) cd9660_statfs(mp, &mp->mnt_stat, td);
- return 0;
-}
-
-/*
- * Common code for mount and mountroot
- */
-static int
-iso_mountfs(devvp, mp, td, argp)
- register struct vnode *devvp;
- struct mount *mp;
- struct thread *td;
- struct iso_args *argp;
-{
- register struct iso_mnt *isomp = (struct iso_mnt *)0;
- struct buf *bp = NULL;
- struct buf *pribp = NULL, *supbp = NULL;
- dev_t dev = devvp->v_rdev;
- int error = EINVAL;
- int needclose = 0;
- int high_sierra = 0;
- int iso_bsize;
- int iso_blknum;
- int joliet_level;
- struct iso_volume_descriptor *vdp = 0;
- struct iso_primary_descriptor *pri = NULL;
- struct iso_sierra_primary_descriptor *pri_sierra = NULL;
- struct iso_supplementary_descriptor *sup = NULL;
- struct iso_directory_record *rootp;
- int logical_block_size;
-
- if (!(mp->mnt_flag & MNT_RDONLY))
- return EROFS;
-
- /*
- * Disallow multiple mounts of the same device.
- * Disallow mounting of a device that is currently in use
- * (except for root, which might share swap device for miniroot).
- * Flush out any old buffers remaining from a previous use.
- */
- if ((error = vfs_mountedon(devvp)))
- return error;
- if (vcount(devvp) > 1 && devvp != rootvp)
- return EBUSY;
- if ((error = vinvalbuf(devvp, V_SAVE, td->td_ucred, td, 0, 0)))
- return (error);
-
- vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
- error = VOP_OPEN(devvp, FREAD, FSCRED, td);
- VOP_UNLOCK(devvp, 0, td);
- if (error)
- return error;
- if (devvp->v_rdev->si_iosize_max != 0)
- mp->mnt_iosize_max = devvp->v_rdev->si_iosize_max;
- if (mp->mnt_iosize_max > MAXPHYS)
- mp->mnt_iosize_max = MAXPHYS;
-
- needclose = 1;
-
- /* This is the "logical sector size". The standard says this
- * should be 2048 or the physical sector size on the device,
- * whichever is greater. For now, we'll just use a constant.
- */
- iso_bsize = ISO_DEFAULT_BLOCK_SIZE;
-
- joliet_level = 0;
- for (iso_blknum = 16 + argp->ssector;
- iso_blknum < 100 + argp->ssector;
- iso_blknum++) {
- if ((error = bread(devvp, iso_blknum * btodb(iso_bsize),
- iso_bsize, NOCRED, &bp)) != 0)
- goto out;
-
- vdp = (struct iso_volume_descriptor *)bp->b_data;
- if (bcmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) != 0) {
- if (bcmp (vdp->id_sierra, ISO_SIERRA_ID,
- sizeof vdp->id) != 0) {
- error = EINVAL;
- goto out;
- } else
- high_sierra = 1;
- }
- switch (isonum_711 (high_sierra? vdp->type_sierra: vdp->type)){
- case ISO_VD_PRIMARY:
- if (pribp == NULL) {
- pribp = bp;
- bp = NULL;
- pri = (struct iso_primary_descriptor *)vdp;
- pri_sierra =
- (struct iso_sierra_primary_descriptor *)vdp;
- }
- break;
-
- case ISO_VD_SUPPLEMENTARY:
- if (supbp == NULL) {
- supbp = bp;
- bp = NULL;
- sup = (struct iso_supplementary_descriptor *)vdp;
-
- if (!(argp->flags & ISOFSMNT_NOJOLIET)) {
- if (bcmp(sup->escape, "%/@", 3) == 0)
- joliet_level = 1;
- if (bcmp(sup->escape, "%/C", 3) == 0)
- joliet_level = 2;
- if (bcmp(sup->escape, "%/E", 3) == 0)
- joliet_level = 3;
-
- if ((isonum_711 (sup->flags) & 1) &&
- (argp->flags & ISOFSMNT_BROKENJOLIET) == 0)
- joliet_level = 0;
- }
- }
- break;
-
- case ISO_VD_END:
- goto vd_end;
-
- default:
- break;
- }
- if (bp) {
- brelse(bp);
- bp = NULL;
- }
- }
- vd_end:
- if (bp) {
- brelse(bp);
- bp = NULL;
- }
-
- if (pri == NULL) {
- error = EINVAL;
- goto out;
- }
-
- logical_block_size =
- isonum_723 (high_sierra?
- pri_sierra->logical_block_size:
- pri->logical_block_size);
-
- if (logical_block_size < DEV_BSIZE || logical_block_size > MAXBSIZE
- || (logical_block_size & (logical_block_size - 1)) != 0) {
- error = EINVAL;
- goto out;
- }
-
- rootp = (struct iso_directory_record *)
- (high_sierra?
- pri_sierra->root_directory_record:
- pri->root_directory_record);
-
- isomp = malloc(sizeof *isomp, M_ISOFSMNT, M_WAITOK | M_ZERO);
- isomp->logical_block_size = logical_block_size;
- isomp->volume_space_size =
- isonum_733 (high_sierra?
- pri_sierra->volume_space_size:
- pri->volume_space_size);
- isomp->joliet_level = 0;
- /*
- * Since an ISO9660 multi-session CD can also access previous
- * sessions, we have to include them into the space consider-
- * ations. This doesn't yield a very accurate number since
- * parts of the old sessions might be inaccessible now, but we
- * can't do much better. This is also important for the NFS
- * filehandle validation.
- */
- isomp->volume_space_size += argp->ssector;
- bcopy (rootp, isomp->root, sizeof isomp->root);
- isomp->root_extent = isonum_733 (rootp->extent);
- isomp->root_size = isonum_733 (rootp->size);
-
- isomp->im_bmask = logical_block_size - 1;
- isomp->im_bshift = ffs(logical_block_size) - 1;
-
- pribp->b_flags |= B_AGE;
- brelse(pribp);
- pribp = NULL;
-
- mp->mnt_data = (qaddr_t)isomp;
- mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
- mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
- mp->mnt_maxsymlinklen = 0;
- mp->mnt_flag |= MNT_LOCAL;
- isomp->im_mountp = mp;
- isomp->im_dev = dev;
- isomp->im_devvp = devvp;
-
- devvp->v_rdev->si_mountpoint = mp;
-
- /* Check the Rock Ridge Extention support */
- if (!(argp->flags & ISOFSMNT_NORRIP)) {
- if ((error = bread(isomp->im_devvp,
- (isomp->root_extent + isonum_711(rootp->ext_attr_length)) <<
- (isomp->im_bshift - DEV_BSHIFT),
- isomp->logical_block_size, NOCRED, &bp)) != 0)
- goto out;
-
- rootp = (struct iso_directory_record *)bp->b_data;
-
- if ((isomp->rr_skip = cd9660_rrip_offset(rootp,isomp)) < 0) {
- argp->flags |= ISOFSMNT_NORRIP;
- } else {
- argp->flags &= ~ISOFSMNT_GENS;
- }
-
- /*
- * The contents are valid,
- * but they will get reread as part of another vnode, so...
- */
- bp->b_flags |= B_AGE;
- brelse(bp);
- bp = NULL;
- }
- isomp->im_flags = argp->flags & (ISOFSMNT_NORRIP | ISOFSMNT_GENS |
- ISOFSMNT_EXTATT | ISOFSMNT_NOJOLIET);
-
- if (high_sierra) {
- /* this effectively ignores all the mount flags */
- log(LOG_INFO, "cd9660: High Sierra Format\n");
- isomp->iso_ftype = ISO_FTYPE_HIGH_SIERRA;
- } else
- switch (isomp->im_flags&(ISOFSMNT_NORRIP|ISOFSMNT_GENS)) {
- default:
- isomp->iso_ftype = ISO_FTYPE_DEFAULT;
- break;
- case ISOFSMNT_GENS|ISOFSMNT_NORRIP:
- isomp->iso_ftype = ISO_FTYPE_9660;
- break;
- case 0:
- log(LOG_INFO, "cd9660: RockRidge Extension\n");
- isomp->iso_ftype = ISO_FTYPE_RRIP;
- break;
- }
-
- /* Decide whether to use the Joliet descriptor */
-
- if (isomp->iso_ftype != ISO_FTYPE_RRIP && joliet_level) {
- log(LOG_INFO, "cd9660: Joliet Extension (Level %d)\n", joliet_level);
- rootp = (struct iso_directory_record *)
- sup->root_directory_record;
- bcopy (rootp, isomp->root, sizeof isomp->root);
- isomp->root_extent = isonum_733 (rootp->extent);
- isomp->root_size = isonum_733 (rootp->size);
- isomp->joliet_level = joliet_level;
- supbp->b_flags |= B_AGE;
- }
-
- if (supbp) {
- brelse(supbp);
- supbp = NULL;
- }
-
- return 0;
-out:
- devvp->v_rdev->si_mountpoint = NULL;
- if (bp)
- brelse(bp);
- if (pribp)
- brelse(pribp);
- if (supbp)
- brelse(supbp);
- if (needclose)
- (void)VOP_CLOSE(devvp, FREAD, NOCRED, td);
- if (isomp) {
- free((caddr_t)isomp, M_ISOFSMNT);
- mp->mnt_data = (qaddr_t)0;
- }
- return error;
-}
-
-/*
- * unmount system call
- */
-static int
-cd9660_unmount(mp, mntflags, td)
- struct mount *mp;
- int mntflags;
- struct thread *td;
-{
- register struct iso_mnt *isomp;
- int error, flags = 0;
-
- if (mntflags & MNT_FORCE)
- flags |= FORCECLOSE;
-#if 0
- mntflushbuf(mp, 0);
- if (mntinvalbuf(mp))
- return EBUSY;
-#endif
- if ((error = vflush(mp, 0, flags)))
- return (error);
-
- isomp = VFSTOISOFS(mp);
-
- isomp->im_devvp->v_rdev->si_mountpoint = NULL;
- error = VOP_CLOSE(isomp->im_devvp, FREAD, NOCRED, td);
- vrele(isomp->im_devvp);
- free((caddr_t)isomp, M_ISOFSMNT);
- mp->mnt_data = (qaddr_t)0;
- mp->mnt_flag &= ~MNT_LOCAL;
- return (error);
-}
-
-/*
- * Return root of a filesystem
- */
-static int
-cd9660_root(mp, vpp)
- struct mount *mp;
- struct vnode **vpp;
-{
- struct iso_mnt *imp = VFSTOISOFS(mp);
- struct iso_directory_record *dp =
- (struct iso_directory_record *)imp->root;
- ino_t ino = isodirino(dp, imp);
-
- /*
- * With RRIP we must use the `.' entry of the root directory.
- * Simply tell vget, that it's a relocated directory.
- */
- return (cd9660_vget_internal(mp, ino, LK_EXCLUSIVE, vpp,
- imp->iso_ftype == ISO_FTYPE_RRIP, dp));
-}
-
-/*
- * Get filesystem statistics.
- */
-static int
-cd9660_statfs(mp, sbp, td)
- struct mount *mp;
- register struct statfs *sbp;
- struct thread *td;
-{
- register struct iso_mnt *isomp;
-
- isomp = VFSTOISOFS(mp);
-
- sbp->f_bsize = isomp->logical_block_size;
- sbp->f_iosize = sbp->f_bsize; /* XXX */
- sbp->f_blocks = isomp->volume_space_size;
- sbp->f_bfree = 0; /* total free blocks */
- sbp->f_bavail = 0; /* blocks free for non superuser */
- sbp->f_files = 0; /* total files */
- sbp->f_ffree = 0; /* free file nodes */
- if (sbp != &mp->mnt_stat) {
- sbp->f_type = mp->mnt_vfc->vfc_typenum;
- bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
- bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
- }
- return 0;
-}
-
-/*
- * File handle to vnode
- *
- * Have to be really careful about stale file handles:
- * - check that the inode number is in range
- * - call iget() to get the locked inode
- * - check for an unallocated inode (i_mode == 0)
- * - check that the generation number matches
- */
-
-struct ifid {
- ushort ifid_len;
- ushort ifid_pad;
- int ifid_ino;
- long ifid_start;
-};
-
-/* ARGSUSED */
-static int
-cd9660_fhtovp(mp, fhp, vpp)
- register struct mount *mp;
- struct fid *fhp;
- struct vnode **vpp;
-{
- struct ifid *ifhp = (struct ifid *)fhp;
- register struct iso_node *ip;
- struct vnode *nvp;
- int error;
-
-#ifdef ISOFS_DBG
- printf("fhtovp: ino %d, start %ld\n",
- ifhp->ifid_ino, ifhp->ifid_start);
-#endif
-
- if ((error = VFS_VGET(mp, ifhp->ifid_ino, LK_EXCLUSIVE, &nvp)) != 0) {
- *vpp = NULLVP;
- return (error);
- }
- ip = VTOI(nvp);
- if (ip->inode.iso_mode == 0) {
- vput(nvp);
- *vpp = NULLVP;
- return (ESTALE);
- }
- *vpp = nvp;
- return (0);
-}
-
-static int
-cd9660_vget(mp, ino, flags, vpp)
- struct mount *mp;
- ino_t ino;
- int flags;
- struct vnode **vpp;
-{
-
- /*
- * XXXX
- * It would be nice if we didn't always set the `relocated' flag
- * and force the extra read, but I don't want to think about fixing
- * that right now.
- */
- return (cd9660_vget_internal(mp, ino, flags, vpp,
-#if 0
- VFSTOISOFS(mp)->iso_ftype == ISO_FTYPE_RRIP,
-#else
- 0,
-#endif
- (struct iso_directory_record *)0));
-}
-
-int
-cd9660_vget_internal(mp, ino, flags, vpp, relocated, isodir)
- struct mount *mp;
- ino_t ino;
- int flags;
- struct vnode **vpp;
- int relocated;
- struct iso_directory_record *isodir;
-{
- struct iso_mnt *imp;
- struct iso_node *ip;
- struct buf *bp;
- struct vnode *vp;
- dev_t dev;
- int error;
-
- imp = VFSTOISOFS(mp);
- dev = imp->im_dev;
- if ((error = cd9660_ihashget(dev, ino, flags, vpp)) != 0)
- return (error);
- if (*vpp != NULL)
- return (0);
-
- /* Allocate a new vnode/iso_node. */
- if ((error = getnewvnode("isofs", mp, cd9660_vnodeop_p, &vp)) != 0) {
- *vpp = NULLVP;
- return (error);
- }
- MALLOC(ip, struct iso_node *, sizeof(struct iso_node), M_ISOFSNODE,
- M_WAITOK | M_ZERO);
- vp->v_data = ip;
- ip->i_vnode = vp;
- ip->i_dev = dev;
- ip->i_number = ino;
-
- /*
- * Check to be sure that it did not show up. We have to put it
- * on the hash chain as the cleanup from vput expects to find
- * it there.
- */
- if ((error = cd9660_ihashget(dev, ino, flags, vpp)) != 0 ||
- *vpp != NULL) {
- cd9660_ihashins(ip);
- vput(vp);
- return (error);
- }
-
- /*
- * Put it onto its hash chain and lock it so that other requests for
- * this inode will block if they arrive while we are sleeping waiting
- * for old data structures to be purged or for the contents of the
- * disk portion of this inode to be read.
- */
- cd9660_ihashins(ip);
-
- if (isodir == 0) {
- int lbn, off;
-
- lbn = lblkno(imp, ino);
- if (lbn >= imp->volume_space_size) {
- vput(vp);
- printf("fhtovp: lbn exceed volume space %d\n", lbn);
- return (ESTALE);
- }
-
- off = blkoff(imp, ino);
- if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) {
- vput(vp);
- printf("fhtovp: crosses block boundary %d\n",
- off + ISO_DIRECTORY_RECORD_SIZE);
- return (ESTALE);
- }
-
- error = bread(imp->im_devvp,
- lbn << (imp->im_bshift - DEV_BSHIFT),
- imp->logical_block_size, NOCRED, &bp);
- if (error) {
- vput(vp);
- brelse(bp);
- printf("fhtovp: bread error %d\n",error);
- return (error);
- }
- isodir = (struct iso_directory_record *)(bp->b_data + off);
-
- if (off + isonum_711(isodir->length) >
- imp->logical_block_size) {
- vput(vp);
- if (bp != 0)
- brelse(bp);
- printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n",
- off +isonum_711(isodir->length), off,
- isonum_711(isodir->length));
- return (ESTALE);
- }
-
-#if 0
- if (isonum_733(isodir->extent) +
- isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) {
- if (bp != 0)
- brelse(bp);
- printf("fhtovp: file start miss %d vs %d\n",
- isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length),
- ifhp->ifid_start);
- return (ESTALE);
- }
-#endif
- } else
- bp = 0;
-
- ip->i_mnt = imp;
- ip->i_devvp = imp->im_devvp;
- VREF(ip->i_devvp);
-
- if (relocated) {
- /*
- * On relocated directories we must
- * read the `.' entry out of a dir.
- */
- ip->iso_start = ino >> imp->im_bshift;
- if (bp != 0)
- brelse(bp);
- if ((error = cd9660_blkatoff(vp, (off_t)0, NULL, &bp)) != 0) {
- vput(vp);
- return (error);
- }
- isodir = (struct iso_directory_record *)bp->b_data;
- }
-
- ip->iso_extent = isonum_733(isodir->extent);
- ip->i_size = isonum_733(isodir->size);
- ip->iso_start = isonum_711(isodir->ext_attr_length) + ip->iso_extent;
-
- /*
- * Setup time stamp, attribute
- */
- vp->v_type = VNON;
- switch (imp->iso_ftype) {
- default: /* ISO_FTYPE_9660 */
- {
- struct buf *bp2;
- int off;
- if ((imp->im_flags & ISOFSMNT_EXTATT)
- && (off = isonum_711(isodir->ext_attr_length)))
- cd9660_blkatoff(vp, (off_t)-(off << imp->im_bshift), NULL,
- &bp2);
- else
- bp2 = NULL;
- cd9660_defattr(isodir, ip, bp2, ISO_FTYPE_9660);
- cd9660_deftstamp(isodir, ip, bp2, ISO_FTYPE_9660);
- if (bp2)
- brelse(bp2);
- break;
- }
- case ISO_FTYPE_RRIP:
- cd9660_rrip_analyze(isodir, ip, imp);
- break;
- }
-
- if (bp != 0)
- brelse(bp);
-
- /*
- * Initialize the associated vnode
- */
- switch (vp->v_type = IFTOVT(ip->inode.iso_mode)) {
- case VFIFO:
- vp->v_op = cd9660_fifoop_p;
- break;
- case VCHR:
- case VBLK:
- vp->v_op = cd9660_specop_p;
- vp = addaliasu(vp, ip->inode.iso_rdev);
- ip->i_vnode = vp;
- break;
- default:
- break;
- }
-
- if (ip->iso_extent == imp->root_extent)
- vp->v_vflag |= VV_ROOT;
-
- /*
- * XXX need generation number?
- */
-
- *vpp = vp;
- return (0);
-}
-
-/*
- * Vnode pointer to File handle
- */
-/* ARGSUSED */
-static int
-cd9660_vptofh(vp, fhp)
- struct vnode *vp;
- struct fid *fhp;
-{
- register struct iso_node *ip = VTOI(vp);
- register struct ifid *ifhp;
-
- ifhp = (struct ifid *)fhp;
- ifhp->ifid_len = sizeof(struct ifid);
-
- ifhp->ifid_ino = ip->i_number;
- ifhp->ifid_start = ip->iso_start;
-
-#ifdef ISOFS_DBG
- printf("vptofh: ino %d, start %ld\n",
- ifhp->ifid_ino,ifhp->ifid_start);
-#endif
- return 0;
-}
diff --git a/sys/fs/cd9660/cd9660_vnops.c b/sys/fs/cd9660/cd9660_vnops.c
deleted file mode 100644
index 6798fa59661d..000000000000
--- a/sys/fs/cd9660/cd9660_vnops.c
+++ /dev/null
@@ -1,834 +0,0 @@
-/*-
- * Copyright (c) 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley
- * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
- * Support code is derived from software contributed to Berkeley
- * by Atsushi Murai (amurai@spec.co.jp).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)cd9660_vnops.c 8.19 (Berkeley) 5/27/95
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/namei.h>
-#include <sys/kernel.h>
-#include <sys/stat.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/mount.h>
-#include <sys/vnode.h>
-#include <fs/fifofs/fifo.h>
-#include <sys/malloc.h>
-#include <sys/dirent.h>
-#include <sys/unistd.h>
-#include <sys/filio.h>
-
-#include <vm/vm.h>
-#include <vm/vnode_pager.h>
-#include <vm/uma.h>
-
-#include <isofs/cd9660/iso.h>
-#include <isofs/cd9660/cd9660_node.h>
-#include <isofs/cd9660/iso_rrip.h>
-
-static int cd9660_setattr(struct vop_setattr_args *);
-static int cd9660_access(struct vop_access_args *);
-static int cd9660_getattr(struct vop_getattr_args *);
-static int cd9660_ioctl(struct vop_ioctl_args *);
-static int cd9660_pathconf(struct vop_pathconf_args *);
-static int cd9660_read(struct vop_read_args *);
-struct isoreaddir;
-static int iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off);
-static int iso_shipdir(struct isoreaddir *idp);
-static int cd9660_readdir(struct vop_readdir_args *);
-static int cd9660_readlink(struct vop_readlink_args *ap);
-static int cd9660_strategy(struct vop_strategy_args *);
-
-/*
- * Setattr call. Only allowed for block and character special devices.
- */
-static int
-cd9660_setattr(ap)
- struct vop_setattr_args /* {
- struct vnodeop_desc *a_desc;
- struct vnode *a_vp;
- struct vattr *a_vap;
- struct ucred *a_cred;
- struct thread *a_td;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct vattr *vap = ap->a_vap;
-
- if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
- vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
- vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL)
- return (EROFS);
- if (vap->va_size != (u_quad_t)VNOVAL) {
- switch (vp->v_type) {
- case VDIR:
- return (EISDIR);
- case VLNK:
- case VREG:
- return (EROFS);
- case VCHR:
- case VBLK:
- case VSOCK:
- case VFIFO:
- case VNON:
- case VBAD:
- return (0);
- }
- }
- return (0);
-}
-
-/*
- * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
- * The mode is shifted to select the owner/group/other fields. The
- * super user is granted all permissions.
- */
-/* ARGSUSED */
-static int
-cd9660_access(ap)
- struct vop_access_args /* {
- struct vnode *a_vp;
- int a_mode;
- struct ucred *a_cred;
- struct thread *a_td;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct iso_node *ip = VTOI(vp);
- mode_t mode = ap->a_mode;
-
- /*
- * Disallow write attempts unless the file is a socket,
- * fifo, or a block or character device resident on the
- * filesystem.
- */
- if (mode & VWRITE) {
- switch (vp->v_type) {
- case VDIR:
- case VLNK:
- case VREG:
- return (EROFS);
- /* NOT REACHED */
- default:
- break;
- }
- }
-
- return (vaccess(vp->v_type, ip->inode.iso_mode, ip->inode.iso_uid,
- ip->inode.iso_gid, ap->a_mode, ap->a_cred, NULL));
-}
-
-static int
-cd9660_getattr(ap)
- struct vop_getattr_args /* {
- struct vnode *a_vp;
- struct vattr *a_vap;
- struct ucred *a_cred;
- struct thread *a_td;
- } */ *ap;
-
-{
- struct vnode *vp = ap->a_vp;
- struct vattr *vap = ap->a_vap;
- struct iso_node *ip = VTOI(vp);
-
- vap->va_fsid = dev2udev(ip->i_dev);
-
- /*
- * Don't use ip->i_ino for this since it is wrong for hard links.
- * ip->i_ino should be the same as ip->iso_start (or not exist),
- * but this currently doesn't work since we abuse it to look up
- * parent directories from inodes.
- */
- vap->va_fileid = ip->iso_start;
-
- vap->va_mode = ip->inode.iso_mode;
- vap->va_nlink = ip->inode.iso_links;
- vap->va_uid = ip->inode.iso_uid;
- vap->va_gid = ip->inode.iso_gid;
- vap->va_atime = ip->inode.iso_atime;
- vap->va_mtime = ip->inode.iso_mtime;
- vap->va_ctime = ip->inode.iso_ctime;
- vap->va_rdev = ip->inode.iso_rdev;
-
- vap->va_size = (u_quad_t) ip->i_size;
- if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
- struct vop_readlink_args rdlnk;
- struct iovec aiov;
- struct uio auio;
- char *cp;
-
- MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
- aiov.iov_base = cp;
- aiov.iov_len = MAXPATHLEN;
- auio.uio_iov = &aiov;
- auio.uio_iovcnt = 1;
- auio.uio_offset = 0;
- auio.uio_rw = UIO_READ;
- auio.uio_segflg = UIO_SYSSPACE;
- auio.uio_td = ap->a_td;
- auio.uio_resid = MAXPATHLEN;
- rdlnk.a_uio = &auio;
- rdlnk.a_vp = ap->a_vp;
- rdlnk.a_cred = ap->a_cred;
- if (cd9660_readlink(&rdlnk) == 0)
- vap->va_size = MAXPATHLEN - auio.uio_resid;
- FREE(cp, M_TEMP);
- }
- vap->va_flags = 0;
- vap->va_gen = 1;
- vap->va_blocksize = ip->i_mnt->logical_block_size;
- vap->va_bytes = (u_quad_t) ip->i_size;
- vap->va_type = vp->v_type;
- vap->va_filerev = 0;
- return (0);
-}
-
-/*
- * Vnode op for ioctl.
- */
-static int
-cd9660_ioctl(ap)
- struct vop_ioctl_args /* {
- struct vnode *a_vp;
- u_long a_command;
- caddr_t a_data;
- int a_fflag;
- struct ucred *a_cred;
- struct thread *a_td;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct iso_node *ip = VTOI(vp);
-
- switch (ap->a_command) {
-
- case FIOGETLBA:
- *(int *)(ap->a_data) = ip->iso_start;
- return 0;
- default:
- return (ENOTTY);
- }
-}
-
-/*
- * Vnode op for reading.
- */
-static int
-cd9660_read(ap)
- struct vop_read_args /* {
- struct vnode *a_vp;
- struct uio *a_uio;
- int a_ioflag;
- struct ucred *a_cred;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct uio *uio = ap->a_uio;
- struct iso_node *ip = VTOI(vp);
- struct iso_mnt *imp;
- struct buf *bp;
- daddr_t lbn, rablock;
- off_t diff;
- int rasize, error = 0;
- int seqcount;
- long size, n, on;
-
- seqcount = ap->a_ioflag >> 16;
-
- if (uio->uio_resid == 0)
- return (0);
- if (uio->uio_offset < 0)
- return (EINVAL);
- ip->i_flag |= IN_ACCESS;
- imp = ip->i_mnt;
- do {
- lbn = lblkno(imp, uio->uio_offset);
- on = blkoff(imp, uio->uio_offset);
- n = min((u_int)(imp->logical_block_size - on),
- uio->uio_resid);
- diff = (off_t)ip->i_size - uio->uio_offset;
- if (diff <= 0)
- return (0);
- if (diff < n)
- n = diff;
- size = blksize(imp, ip, lbn);
- rablock = lbn + 1;
- if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
- if (lblktosize(imp, rablock) < ip->i_size)
- error = cluster_read(vp, (off_t)ip->i_size,
- lbn, size, NOCRED, uio->uio_resid,
- (ap->a_ioflag >> 16), &bp);
- else
- error = bread(vp, lbn, size, NOCRED, &bp);
- } else {
- if (seqcount > 1 &&
- lblktosize(imp, rablock) < ip->i_size) {
- rasize = blksize(imp, ip, rablock);
- error = breadn(vp, lbn, size, &rablock,
- &rasize, 1, NOCRED, &bp);
- } else
- error = bread(vp, lbn, size, NOCRED, &bp);
- }
- n = min(n, size - bp->b_resid);
- if (error) {
- brelse(bp);
- return (error);
- }
-
- error = uiomove(bp->b_data + on, (int)n, uio);
- brelse(bp);
- } while (error == 0 && uio->uio_resid > 0 && n != 0);
- return (error);
-}
-
-/*
- * Structure for reading directories
- */
-struct isoreaddir {
- struct dirent saveent;
- struct dirent assocent;
- struct dirent current;
- off_t saveoff;
- off_t assocoff;
- off_t curroff;
- struct uio *uio;
- off_t uio_off;
- int eofflag;
- u_long *cookies;
- int ncookies;
-};
-
-static int
-iso_uiodir(idp,dp,off)
- struct isoreaddir *idp;
- struct dirent *dp;
- off_t off;
-{
- int error;
-
- dp->d_name[dp->d_namlen] = 0;
- dp->d_reclen = GENERIC_DIRSIZ(dp);
-
- if (idp->uio->uio_resid < dp->d_reclen) {
- idp->eofflag = 0;
- return (-1);
- }
-
- if (idp->cookies) {
- if (idp->ncookies <= 0) {
- idp->eofflag = 0;
- return (-1);
- }
-
- *idp->cookies++ = off;
- --idp->ncookies;
- }
-
- if ((error = uiomove(dp, dp->d_reclen, idp->uio)) != 0)
- return (error);
- idp->uio_off = off;
- return (0);
-}
-
-static int
-iso_shipdir(idp)
- struct isoreaddir *idp;
-{
- struct dirent *dp;
- int cl, sl, assoc;
- int error;
- char *cname, *sname;
-
- cl = idp->current.d_namlen;
- cname = idp->current.d_name;
-assoc = (cl > 1) && (*cname == ASSOCCHAR);
- if (assoc) {
- cl--;
- cname++;
- }
-
- dp = &idp->saveent;
- sname = dp->d_name;
- if (!(sl = dp->d_namlen)) {
- dp = &idp->assocent;
- sname = dp->d_name + 1;
- sl = dp->d_namlen - 1;
- }
- if (sl > 0) {
- if (sl != cl
- || bcmp(sname,cname,sl)) {
- if (idp->assocent.d_namlen) {
- if ((error = iso_uiodir(idp,&idp->assocent,idp->assocoff)) != 0)
- return (error);
- idp->assocent.d_namlen = 0;
- }
- if (idp->saveent.d_namlen) {
- if ((error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) != 0)
- return (error);
- idp->saveent.d_namlen = 0;
- }
- }
- }
- idp->current.d_reclen = GENERIC_DIRSIZ(&idp->current);
- if (assoc) {
- idp->assocoff = idp->curroff;
- bcopy(&idp->current,&idp->assocent,idp->current.d_reclen);
- } else {
- idp->saveoff = idp->curroff;
- bcopy(&idp->current,&idp->saveent,idp->current.d_reclen);
- }
- return (0);
-}
-
-/*
- * Vnode op for readdir
- */
-static int
-cd9660_readdir(ap)
- struct vop_readdir_args /* {
- struct vnode *a_vp;
- struct uio *a_uio;
- struct ucred *a_cred;
- int *a_eofflag;
- int *a_ncookies;
- u_long *a_cookies;
- } */ *ap;
-{
- struct uio *uio = ap->a_uio;
- struct isoreaddir *idp;
- struct vnode *vdp = ap->a_vp;
- struct iso_node *dp;
- struct iso_mnt *imp;
- struct buf *bp = NULL;
- struct iso_directory_record *ep;
- int entryoffsetinblock;
- doff_t endsearch;
- u_long bmask;
- int error = 0;
- int reclen;
- u_short namelen;
- int ncookies = 0;
- u_long *cookies = NULL;
-
- dp = VTOI(vdp);
- imp = dp->i_mnt;
- bmask = imp->im_bmask;
-
- MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
- idp->saveent.d_namlen = idp->assocent.d_namlen = 0;
- /*
- * XXX
- * Is it worth trying to figure out the type?
- */
- idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type =
- DT_UNKNOWN;
- idp->uio = uio;
- if (ap->a_ncookies == NULL) {
- idp->cookies = NULL;
- } else {
- /*
- * Guess the number of cookies needed.
- */
- ncookies = uio->uio_resid / 16;
- MALLOC(cookies, u_long *, ncookies * sizeof(u_int), M_TEMP,
- M_WAITOK);
- idp->cookies = cookies;
- idp->ncookies = ncookies;
- }
- idp->eofflag = 1;
- idp->curroff = uio->uio_offset;
-
- if ((entryoffsetinblock = idp->curroff & bmask) &&
- (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
- FREE(idp, M_TEMP);
- return (error);
- }
- endsearch = dp->i_size;
-
- while (idp->curroff < endsearch) {
- /*
- * If offset is on a block boundary,
- * read the next directory block.
- * Release previous if it exists.
- */
- if ((idp->curroff & bmask) == 0) {
- if (bp != NULL)
- brelse(bp);
- if ((error =
- cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0)
- break;
- entryoffsetinblock = 0;
- }
- /*
- * Get pointer to next entry.
- */
- ep = (struct iso_directory_record *)
- ((char *)bp->b_data + entryoffsetinblock);
-
- reclen = isonum_711(ep->length);
- if (reclen == 0) {
- /* skip to next block, if any */
- idp->curroff =
- (idp->curroff & ~bmask) + imp->logical_block_size;
- continue;
- }
-
- if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
- error = EINVAL;
- /* illegal entry, stop */
- break;
- }
-
- if (entryoffsetinblock + reclen > imp->logical_block_size) {
- error = EINVAL;
- /* illegal directory, so stop looking */
- break;
- }
-
- idp->current.d_namlen = isonum_711(ep->name_len);
-
- if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
- error = EINVAL;
- /* illegal entry, stop */
- break;
- }
-
- /*
- * The "inode number" is iso_start, not i_ino, as in
- * cd9660_getattr().
- */
- idp->current.d_fileno = isonum_711(ep->ext_attr_length) +
- isonum_733(ep->extent);
-
- idp->curroff += reclen;
-
- switch (imp->iso_ftype) {
- case ISO_FTYPE_RRIP:
- cd9660_rrip_getname(ep,idp->current.d_name, &namelen,
- &idp->current.d_fileno,imp);
- idp->current.d_namlen = (u_char)namelen;
- if (idp->current.d_namlen)
- error = iso_uiodir(idp,&idp->current,idp->curroff);
- break;
- default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
- strcpy(idp->current.d_name,"..");
- if (idp->current.d_namlen == 1 && ep->name[0] == 0) {
- idp->current.d_namlen = 1;
- error = iso_uiodir(idp,&idp->current,idp->curroff);
- } else if (idp->current.d_namlen == 1 && ep->name[0] == 1) {
- idp->current.d_namlen = 2;
- error = iso_uiodir(idp,&idp->current,idp->curroff);
- } else {
- isofntrans(ep->name,idp->current.d_namlen,
- idp->current.d_name, &namelen,
- imp->iso_ftype == ISO_FTYPE_9660,
- isonum_711(ep->flags)&4,
- imp->joliet_level);
- idp->current.d_namlen = (u_char)namelen;
- if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
- error = iso_shipdir(idp);
- else
- error = iso_uiodir(idp,&idp->current,idp->curroff);
- }
- }
- if (error)
- break;
-
- entryoffsetinblock += reclen;
- }
-
- if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
- idp->current.d_namlen = 0;
- error = iso_shipdir(idp);
- }
- if (error < 0)
- error = 0;
-
- if (ap->a_ncookies != NULL) {
- if (error)
- free(cookies, M_TEMP);
- else {
- /*
- * Work out the number of cookies actually used.
- */
- *ap->a_ncookies = ncookies - idp->ncookies;
- *ap->a_cookies = cookies;
- }
- }
-
- if (bp)
- brelse (bp);
-
- uio->uio_offset = idp->uio_off;
- *ap->a_eofflag = idp->eofflag;
-
- FREE(idp, M_TEMP);
-
- return (error);
-}
-
-/*
- * Return target name of a symbolic link
- * Shouldn't we get the parent vnode and read the data from there?
- * This could eventually result in deadlocks in cd9660_lookup.
- * But otherwise the block read here is in the block buffer two times.
- */
-typedef struct iso_directory_record ISODIR;
-typedef struct iso_node ISONODE;
-typedef struct iso_mnt ISOMNT;
-static int
-cd9660_readlink(ap)
- struct vop_readlink_args /* {
- struct vnode *a_vp;
- struct uio *a_uio;
- struct ucred *a_cred;
- } */ *ap;
-{
- ISONODE *ip;
- ISODIR *dirp;
- ISOMNT *imp;
- struct buf *bp;
- struct uio *uio;
- u_short symlen;
- int error;
- char *symname;
-
- ip = VTOI(ap->a_vp);
- imp = ip->i_mnt;
- uio = ap->a_uio;
-
- if (imp->iso_ftype != ISO_FTYPE_RRIP)
- return (EINVAL);
-
- /*
- * Get parents directory record block that this inode included.
- */
- error = bread(imp->im_devvp,
- (ip->i_number >> imp->im_bshift) <<
- (imp->im_bshift - DEV_BSHIFT),
- imp->logical_block_size, NOCRED, &bp);
- if (error) {
- brelse(bp);
- return (EINVAL);
- }
-
- /*
- * Setup the directory pointer for this inode
- */
- dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
-
- /*
- * Just make sure, we have a right one....
- * 1: Check not cross boundary on block
- */
- if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
- > (unsigned)imp->logical_block_size) {
- brelse(bp);
- return (EINVAL);
- }
-
- /*
- * Now get a buffer
- * Abuse a namei buffer for now.
- */
- if (uio->uio_segflg == UIO_SYSSPACE)
- symname = uio->uio_iov->iov_base;
- else
- symname = uma_zalloc(namei_zone, M_WAITOK);
-
- /*
- * Ok, we just gathering a symbolic name in SL record.
- */
- if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
- if (uio->uio_segflg != UIO_SYSSPACE)
- uma_zfree(namei_zone, symname);
- brelse(bp);
- return (EINVAL);
- }
- /*
- * Don't forget before you leave from home ;-)
- */
- brelse(bp);
-
- /*
- * return with the symbolic name to caller's.
- */
- if (uio->uio_segflg != UIO_SYSSPACE) {
- error = uiomove(symname, symlen, uio);
- uma_zfree(namei_zone, symname);
- return (error);
- }
- uio->uio_resid -= symlen;
- uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + symlen;
- uio->uio_iov->iov_len -= symlen;
- return (0);
-}
-
-/*
- * Calculate the logical to physical mapping if not done already,
- * then call the device strategy routine.
- */
-static int
-cd9660_strategy(ap)
- struct vop_strategy_args /* {
- struct buf *a_vp;
- struct buf *a_bp;
- } */ *ap;
-{
- struct buf *bp = ap->a_bp;
- struct vnode *vp = bp->b_vp;
- struct iso_node *ip;
-
- ip = VTOI(vp);
- if (vp->v_type == VBLK || vp->v_type == VCHR)
- panic("cd9660_strategy: spec");
- if (bp->b_blkno == bp->b_lblkno) {
- bp->b_blkno = (ip->iso_start + bp->b_lblkno) <<
- (ip->i_mnt->im_bshift - DEV_BSHIFT);
- if ((long)bp->b_blkno == -1) /* XXX: cut&paste junk ? */
- clrbuf(bp);
- }
- if ((long)bp->b_blkno == -1) { /* XXX: cut&paste junk ? */
- bufdone(bp);
- return (0);
- }
- vp = ip->i_devvp;
- bp->b_dev = vp->v_rdev;
- VOP_SPECSTRATEGY(vp, bp);
- return (0);
-}
-
-/*
- * Return POSIX pathconf information applicable to cd9660 filesystems.
- */
-static int
-cd9660_pathconf(ap)
- struct vop_pathconf_args /* {
- struct vnode *a_vp;
- int a_name;
- register_t *a_retval;
- } */ *ap;
-{
-
- switch (ap->a_name) {
- case _PC_LINK_MAX:
- *ap->a_retval = 1;
- return (0);
- case _PC_NAME_MAX:
- if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
- *ap->a_retval = NAME_MAX;
- else
- *ap->a_retval = 37;
- return (0);
- case _PC_PATH_MAX:
- *ap->a_retval = PATH_MAX;
- return (0);
- case _PC_PIPE_BUF:
- *ap->a_retval = PIPE_BUF;
- return (0);
- case _PC_CHOWN_RESTRICTED:
- *ap->a_retval = 1;
- return (0);
- case _PC_NO_TRUNC:
- *ap->a_retval = 1;
- return (0);
- default:
- return (EINVAL);
- }
- /* NOTREACHED */
-}
-
-/*
- * Global vfs data structures for cd9660
- */
-vop_t **cd9660_vnodeop_p;
-static struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
- { &vop_default_desc, (vop_t *) vop_defaultop },
- { &vop_access_desc, (vop_t *) cd9660_access },
- { &vop_bmap_desc, (vop_t *) cd9660_bmap },
- { &vop_cachedlookup_desc, (vop_t *) cd9660_lookup },
- { &vop_getattr_desc, (vop_t *) cd9660_getattr },
- { &vop_inactive_desc, (vop_t *) cd9660_inactive },
- { &vop_ioctl_desc, (vop_t *) cd9660_ioctl },
- { &vop_lookup_desc, (vop_t *) vfs_cache_lookup },
- { &vop_pathconf_desc, (vop_t *) cd9660_pathconf },
- { &vop_read_desc, (vop_t *) cd9660_read },
- { &vop_readdir_desc, (vop_t *) cd9660_readdir },
- { &vop_readlink_desc, (vop_t *) cd9660_readlink },
- { &vop_reclaim_desc, (vop_t *) cd9660_reclaim },
- { &vop_setattr_desc, (vop_t *) cd9660_setattr },
- { &vop_strategy_desc, (vop_t *) cd9660_strategy },
- { NULL, NULL }
-};
-static struct vnodeopv_desc cd9660_vnodeop_opv_desc =
- { &cd9660_vnodeop_p, cd9660_vnodeop_entries };
-VNODEOP_SET(cd9660_vnodeop_opv_desc);
-
-/*
- * Special device vnode ops
- */
-vop_t **cd9660_specop_p;
-static struct vnodeopv_entry_desc cd9660_specop_entries[] = {
- { &vop_default_desc, (vop_t *) spec_vnoperate },
- { &vop_access_desc, (vop_t *) cd9660_access },
- { &vop_getattr_desc, (vop_t *) cd9660_getattr },
- { &vop_inactive_desc, (vop_t *) cd9660_inactive },
- { &vop_reclaim_desc, (vop_t *) cd9660_reclaim },
- { &vop_setattr_desc, (vop_t *) cd9660_setattr },
- { NULL, NULL }
-};
-static struct vnodeopv_desc cd9660_specop_opv_desc =
- { &cd9660_specop_p, cd9660_specop_entries };
-VNODEOP_SET(cd9660_specop_opv_desc);
-
-vop_t **cd9660_fifoop_p;
-static struct vnodeopv_entry_desc cd9660_fifoop_entries[] = {
- { &vop_default_desc, (vop_t *) fifo_vnoperate },
- { &vop_access_desc, (vop_t *) cd9660_access },
- { &vop_getattr_desc, (vop_t *) cd9660_getattr },
- { &vop_inactive_desc, (vop_t *) cd9660_inactive },
- { &vop_reclaim_desc, (vop_t *) cd9660_reclaim },
- { &vop_setattr_desc, (vop_t *) cd9660_setattr },
- { NULL, NULL }
-};
-static struct vnodeopv_desc cd9660_fifoop_opv_desc =
- { &cd9660_fifoop_p, cd9660_fifoop_entries };
-
-VNODEOP_SET(cd9660_fifoop_opv_desc);
diff --git a/sys/fs/cd9660/iso.h b/sys/fs/cd9660/iso.h
deleted file mode 100644
index b41cd0cc5a82..000000000000
--- a/sys/fs/cd9660/iso.h
+++ /dev/null
@@ -1,357 +0,0 @@
-/*-
- * Copyright (c) 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley
- * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
- * Support code is derived from software contributed to Berkeley
- * by Atsushi Murai (amurai@spec.co.jp).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)iso.h 8.6 (Berkeley) 5/10/95
- * $FreeBSD$
- */
-
-#define ISODCL(from, to) (to - from + 1)
-
-struct iso_volume_descriptor {
- char type[ISODCL(1,1)]; /* 711 */
- char id[ISODCL(2,6)];
- char version[ISODCL(7,7)];
- char unused[ISODCL(8,8)];
- char type_sierra[ISODCL(9,9)]; /* 711 */
- char id_sierra[ISODCL(10,14)];
- char version_sierra[ISODCL(15,15)];
- char data[ISODCL(16,2048)];
-};
-
-/* volume descriptor types */
-#define ISO_VD_PRIMARY 1
-#define ISO_VD_SUPPLEMENTARY 2
-#define ISO_VD_END 255
-
-#define ISO_STANDARD_ID "CD001"
-#define ISO_ECMA_ID "CDW01"
-
-#define ISO_SIERRA_ID "CDROM"
-
-struct iso_primary_descriptor {
- char type [ISODCL ( 1, 1)]; /* 711 */
- char id [ISODCL ( 2, 6)];
- char version [ISODCL ( 7, 7)]; /* 711 */
- char unused1 [ISODCL ( 8, 8)];
- char system_id [ISODCL ( 9, 40)]; /* achars */
- char volume_id [ISODCL ( 41, 72)]; /* dchars */
- char unused2 [ISODCL ( 73, 80)];
- char volume_space_size [ISODCL ( 81, 88)]; /* 733 */
- char unused3 [ISODCL ( 89, 120)];
- char volume_set_size [ISODCL (121, 124)]; /* 723 */
- char volume_sequence_number [ISODCL (125, 128)]; /* 723 */
- char logical_block_size [ISODCL (129, 132)]; /* 723 */
- char path_table_size [ISODCL (133, 140)]; /* 733 */
- char type_l_path_table [ISODCL (141, 144)]; /* 731 */
- char opt_type_l_path_table [ISODCL (145, 148)]; /* 731 */
- char type_m_path_table [ISODCL (149, 152)]; /* 732 */
- char opt_type_m_path_table [ISODCL (153, 156)]; /* 732 */
- char root_directory_record [ISODCL (157, 190)]; /* 9.1 */
- char volume_set_id [ISODCL (191, 318)]; /* dchars */
- char publisher_id [ISODCL (319, 446)]; /* achars */
- char preparer_id [ISODCL (447, 574)]; /* achars */
- char application_id [ISODCL (575, 702)]; /* achars */
- char copyright_file_id [ISODCL (703, 739)]; /* 7.5 dchars */
- char abstract_file_id [ISODCL (740, 776)]; /* 7.5 dchars */
- char bibliographic_file_id [ISODCL (777, 813)]; /* 7.5 dchars */
- char creation_date [ISODCL (814, 830)]; /* 8.4.26.1 */
- char modification_date [ISODCL (831, 847)]; /* 8.4.26.1 */
- char expiration_date [ISODCL (848, 864)]; /* 8.4.26.1 */
- char effective_date [ISODCL (865, 881)]; /* 8.4.26.1 */
- char file_structure_version [ISODCL (882, 882)]; /* 711 */
- char unused4 [ISODCL (883, 883)];
- char application_data [ISODCL (884, 1395)];
- char unused5 [ISODCL (1396, 2048)];
-};
-#define ISO_DEFAULT_BLOCK_SIZE 2048
-
-/*
- * Used by Microsoft Joliet extension to ISO9660. Almost the same
- * as PVD, but byte position 8 is a flag, and 89-120 is for escape.
- */
-
-struct iso_supplementary_descriptor {
- char type [ISODCL ( 1, 1)]; /* 711 */
- char id [ISODCL ( 2, 6)];
- char version [ISODCL ( 7, 7)]; /* 711 */
- char flags [ISODCL ( 8, 8)]; /* 711? */
- char system_id [ISODCL ( 9, 40)]; /* achars */
- char volume_id [ISODCL ( 41, 72)]; /* dchars */
- char unused2 [ISODCL ( 73, 80)];
- char volume_space_size [ISODCL ( 81, 88)]; /* 733 */
- char escape [ISODCL ( 89, 120)];
- char volume_set_size [ISODCL (121, 124)]; /* 723 */
- char volume_sequence_number [ISODCL (125, 128)]; /* 723 */
- char logical_block_size [ISODCL (129, 132)]; /* 723 */
- char path_table_size [ISODCL (133, 140)]; /* 733 */
- char type_l_path_table [ISODCL (141, 144)]; /* 731 */
- char opt_type_l_path_table [ISODCL (145, 148)]; /* 731 */
- char type_m_path_table [ISODCL (149, 152)]; /* 732 */
- char opt_type_m_path_table [ISODCL (153, 156)]; /* 732 */
- char root_directory_record [ISODCL (157, 190)]; /* 9.1 */
- char volume_set_id [ISODCL (191, 318)]; /* dchars */
- char publisher_id [ISODCL (319, 446)]; /* achars */
- char preparer_id [ISODCL (447, 574)]; /* achars */
- char application_id [ISODCL (575, 702)]; /* achars */
- char copyright_file_id [ISODCL (703, 739)]; /* 7.5 dchars */
- char abstract_file_id [ISODCL (740, 776)]; /* 7.5 dchars */
- char bibliographic_file_id [ISODCL (777, 813)]; /* 7.5 dchars */
- char creation_date [ISODCL (814, 830)]; /* 8.4.26.1 */
- char modification_date [ISODCL (831, 847)]; /* 8.4.26.1 */
- char expiration_date [ISODCL (848, 864)]; /* 8.4.26.1 */
- char effective_date [ISODCL (865, 881)]; /* 8.4.26.1 */
- char file_structure_version [ISODCL (882, 882)]; /* 711 */
- char unused4 [ISODCL (883, 883)];
- char application_data [ISODCL (884, 1395)];
- char unused5 [ISODCL (1396, 2048)];
-};
-
-struct iso_sierra_primary_descriptor {
- char unknown1 [ISODCL ( 1, 8)]; /* 733 */
- char type [ISODCL ( 9, 9)]; /* 711 */
- char id [ISODCL ( 10, 14)];
- char version [ISODCL ( 15, 15)]; /* 711 */
- char unused1 [ISODCL ( 16, 16)];
- char system_id [ISODCL ( 17, 48)]; /* achars */
- char volume_id [ISODCL ( 49, 80)]; /* dchars */
- char unused2 [ISODCL ( 81, 88)];
- char volume_space_size [ISODCL ( 89, 96)]; /* 733 */
- char unused3 [ISODCL ( 97, 128)];
- char volume_set_size [ISODCL (129, 132)]; /* 723 */
- char volume_sequence_number [ISODCL (133, 136)]; /* 723 */
- char logical_block_size [ISODCL (137, 140)]; /* 723 */
- char path_table_size [ISODCL (141, 148)]; /* 733 */
- char type_l_path_table [ISODCL (149, 152)]; /* 731 */
- char opt_type_l_path_table [ISODCL (153, 156)]; /* 731 */
- char unknown2 [ISODCL (157, 160)]; /* 731 */
- char unknown3 [ISODCL (161, 164)]; /* 731 */
- char type_m_path_table [ISODCL (165, 168)]; /* 732 */
- char opt_type_m_path_table [ISODCL (169, 172)]; /* 732 */
- char unknown4 [ISODCL (173, 176)]; /* 732 */
- char unknown5 [ISODCL (177, 180)]; /* 732 */
- char root_directory_record [ISODCL (181, 214)]; /* 9.1 */
- char volume_set_id [ISODCL (215, 342)]; /* dchars */
- char publisher_id [ISODCL (343, 470)]; /* achars */
- char preparer_id [ISODCL (471, 598)]; /* achars */
- char application_id [ISODCL (599, 726)]; /* achars */
- char copyright_id [ISODCL (727, 790)]; /* achars */
- char creation_date [ISODCL (791, 806)]; /* ? */
- char modification_date [ISODCL (807, 822)]; /* ? */
- char expiration_date [ISODCL (823, 838)]; /* ? */
- char effective_date [ISODCL (839, 854)]; /* ? */
- char file_structure_version [ISODCL (855, 855)]; /* 711 */
- char unused4 [ISODCL (856, 2048)];
-};
-
-struct iso_directory_record {
- char length [ISODCL (1, 1)]; /* 711 */
- char ext_attr_length [ISODCL (2, 2)]; /* 711 */
- u_char extent [ISODCL (3, 10)]; /* 733 */
- u_char size [ISODCL (11, 18)]; /* 733 */
- char date [ISODCL (19, 25)]; /* 7 by 711 */
- char flags [ISODCL (26, 26)];
- char file_unit_size [ISODCL (27, 27)]; /* 711 */
- char interleave [ISODCL (28, 28)]; /* 711 */
- char volume_sequence_number [ISODCL (29, 32)]; /* 723 */
- char name_len [ISODCL (33, 33)]; /* 711 */
- char name [1]; /* XXX */
-};
-/* can't take sizeof(iso_directory_record), because of possible alignment
- of the last entry (34 instead of 33) */
-#define ISO_DIRECTORY_RECORD_SIZE 33
-
-struct iso_extended_attributes {
- u_char owner [ISODCL (1, 4)]; /* 723 */
- u_char group [ISODCL (5, 8)]; /* 723 */
- u_char perm [ISODCL (9, 10)]; /* 9.5.3 */
- char ctime [ISODCL (11, 27)]; /* 8.4.26.1 */
- char mtime [ISODCL (28, 44)]; /* 8.4.26.1 */
- char xtime [ISODCL (45, 61)]; /* 8.4.26.1 */
- char ftime [ISODCL (62, 78)]; /* 8.4.26.1 */
- char recfmt [ISODCL (79, 79)]; /* 711 */
- char recattr [ISODCL (80, 80)]; /* 711 */
- u_char reclen [ISODCL (81, 84)]; /* 723 */
- char system_id [ISODCL (85, 116)]; /* achars */
- char system_use [ISODCL (117, 180)];
- char version [ISODCL (181, 181)]; /* 711 */
- char len_esc [ISODCL (182, 182)]; /* 711 */
- char reserved [ISODCL (183, 246)];
- u_char len_au [ISODCL (247, 250)]; /* 723 */
-};
-
-#ifdef _KERNEL
-
-/* CD-ROM Format type */
-enum ISO_FTYPE { ISO_FTYPE_DEFAULT, ISO_FTYPE_9660, ISO_FTYPE_RRIP,
- ISO_FTYPE_JOLIET, ISO_FTYPE_ECMA, ISO_FTYPE_HIGH_SIERRA };
-
-#ifndef ISOFSMNT_ROOT
-#define ISOFSMNT_ROOT 0
-#endif
-
-struct iso_mnt {
- int im_flags;
-
- struct mount *im_mountp;
- dev_t im_dev;
- struct vnode *im_devvp;
-
- int logical_block_size;
- int im_bshift;
- int im_bmask;
-
- int volume_space_size;
-
- char root[ISODCL (157, 190)];
- int root_extent;
- int root_size;
- enum ISO_FTYPE iso_ftype;
-
- int rr_skip;
- int rr_skip0;
-
- int joliet_level;
-};
-
-#define VFSTOISOFS(mp) ((struct iso_mnt *)((mp)->mnt_data))
-
-#define blkoff(imp, loc) ((loc) & (imp)->im_bmask)
-#define lblktosize(imp, blk) ((blk) << (imp)->im_bshift)
-#define lblkno(imp, loc) ((loc) >> (imp)->im_bshift)
-#define blksize(imp, ip, lbn) ((imp)->logical_block_size)
-
-int cd9660_vget_internal(struct mount *, ino_t, int, struct vnode **, int,
- struct iso_directory_record *);
-int cd9660_init(struct vfsconf *);
-int cd9660_uninit(struct vfsconf *);
-#define cd9660_sysctl ((int (*)(int *, u_int, void *, size_t *, void *, \
- size_t, struct proc *))eopnotsupp)
-
-extern vop_t **cd9660_vnodeop_p;
-extern vop_t **cd9660_specop_p;
-extern vop_t **cd9660_fifoop_p;
-
-int isochar(u_char *, u_char *, int, u_char *);
-int isofncmp(u_char *, int, u_char *, int, int);
-void isofntrans(u_char *, int, u_char *, u_short *, int, int, int);
-ino_t isodirino(struct iso_directory_record *, struct iso_mnt *);
-
-#endif /* _KERNEL */
-
-/*
- * The isonum_xxx functions are inlined anyway, and could come handy even
- * outside the kernel. Thus we don't hide them here.
- */
-
-static __inline int isonum_711(u_char *);
-static __inline int
-isonum_711(p)
- u_char *p;
-{
- return *p;
-}
-
-static __inline int isonum_712(char *);
-static __inline int
-isonum_712(p)
- char *p;
-{
- return *p;
-}
-
-#ifndef UNALIGNED_ACCESS
-
-static __inline int isonum_723(u_char *);
-static __inline int
-isonum_723(p)
- u_char *p;
-{
- return *p|(p[1] << 8);
-}
-
-static __inline int isonum_733(u_char *);
-static __inline int
-isonum_733(p)
- u_char *p;
-{
- return *p|(p[1] << 8)|(p[2] << 16)|(p[3] << 24);
-}
-
-#else /* UNALIGNED_ACCESS */
-
-#if BYTE_ORDER == LITTLE_ENDIAN
-
-static __inline int
-isonum_723(p)
- u_char *p
-{
- return *(u_int16t *)p;
-}
-
-static __inline int
-isonum_733(p)
- u_char *p;
-{
- return *(u_int32t *)p;
-}
-
-#endif
-
-#if BYTE_ORDER == BIG_ENDIAN
-
-static __inline int
-isonum_723(p)
- u_char *p
-{
- return *(u_int16t *)(p + 2);
-}
-
-static __inline int
-isonum_733(p)
- u_char *p;
-{
- return *(u_int32t *)(p + 4);
-}
-
-#endif
-
-#endif /* UNALIGNED_ACCESS */
-
-/*
- * Associated files have a leading '='.
- */
-#define ASSOCCHAR '='
diff --git a/sys/fs/cd9660/iso_rrip.h b/sys/fs/cd9660/iso_rrip.h
deleted file mode 100644
index 313918fcbdb4..000000000000
--- a/sys/fs/cd9660/iso_rrip.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley
- * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
- * Support code is derived from software contributed to Berkeley
- * by Atsushi Murai (amurai@spec.co.jp).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)iso_rrip.h 8.2 (Berkeley) 1/23/94
- * $FreeBSD$
- */
-
-
-/*
- * Analyze function flag (similar to RR field bits)
- */
-#define ISO_SUSP_ATTR 0x0001
-#define ISO_SUSP_DEVICE 0x0002
-#define ISO_SUSP_SLINK 0x0004
-#define ISO_SUSP_ALTNAME 0x0008
-#define ISO_SUSP_CLINK 0x0010
-#define ISO_SUSP_PLINK 0x0020
-#define ISO_SUSP_RELDIR 0x0040
-#define ISO_SUSP_TSTAMP 0x0080
-#define ISO_SUSP_IDFLAG 0x0100
-#define ISO_SUSP_EXTREF 0x0200
-#define ISO_SUSP_CONT 0x0400
-#define ISO_SUSP_OFFSET 0x0800
-#define ISO_SUSP_STOP 0x1000
-#define ISO_SUSP_UNKNOWN 0x8000
-
-typedef struct {
- struct iso_node *inop;
- int fields; /* interesting fields in this analysis */
- daddr_t iso_ce_blk; /* block of continuation area */
- off_t iso_ce_off; /* offset of continuation area */
- int iso_ce_len; /* length of continuation area */
- struct iso_mnt *imp; /* mount structure */
- ino_t *inump; /* inode number pointer */
- char *outbuf; /* name/symbolic link output area */
- u_short *outlen; /* length of above */
- u_short maxlen; /* maximum length of above */
- int cont; /* continuation of above */
-} ISO_RRIP_ANALYZE;
-
-struct iso_directory_record;
-
-int cd9660_rrip_analyze(struct iso_directory_record *isodir,
- struct iso_node *inop, struct iso_mnt *imp);
-int cd9660_rrip_getname(struct iso_directory_record *isodir,
- char *outbuf, u_short *outlen,
- ino_t *inump, struct iso_mnt *imp);
-int cd9660_rrip_getsymname(struct iso_directory_record *isodir,
- char *outbuf, u_short *outlen,
- struct iso_mnt *imp);
-int cd9660_rrip_offset(struct iso_directory_record *isodir,
- struct iso_mnt *imp);
diff --git a/sys/fs/coda/README b/sys/fs/coda/README
deleted file mode 100644
index 19de799c0eac..000000000000
--- a/sys/fs/coda/README
+++ /dev/null
@@ -1,62 +0,0 @@
-$FreeBSD$
-
- Announcing the Availability of the
- Coda Distributed
- Filesystem
- for
- BSD Unix Systems
-
- Coda is a distributed filesystem like NFS and AFS. It is
-freely available, like NFS. But it functions much like AFS in being a
-"stateful" filesystem. Coda and AFS cache files on your local
-machine to improve performance. But Coda goes a step further than AFS
-by letting you access the cached files when there is no available
-network, viz. disconnected laptops and network outages. In Coda, both
-the client and server are outside the kernel which makes them easier
-to experiment with.
-
-To get more information on Coda, I would like to refer people to
- http://www.coda.cs.cmu.edu
-There is a wealth of documents, papers, and theses there. There is
-also a good introduction to the Coda File System in
- http://www.coda.cs.cmu.edu/ljpaper/lj.html
-
-Coda was originally developed as an academic prototype/testbed. It is
-being polished and rewritten where necessary. Coda is a work in
-progress and does have bugs. It is, though, very usable. Our
-interest is in making Coda available to as many people as possible and
-to have Coda evolve and flourish.
-
-The bulk of the Coda filesystem code supports the Coda client
-program, the Coda server program and the utilities needed by both.
-All these programs are unix programs and can run equally well on any
-Unix platform. Our main development thrust is improving these
-programs. There is a small part of Coda that deals with the kernel to
-filesystem interface. This code is OS specific (but should not be
-platform specific).
-
-Coda is currently available for several OS's and platforms:
- Freebsd-2.2.5: i386
- Freebsd-2.2.6: i386
- Freebsd -current: i386
- linux 2.0: i386 & sparc
- linux 2.1: i386 & sparc
- NetBSD 1.3: i386
- NetBSD -current: i386
-The relevant sources, binaries, and docs can be found in
- ftp://ftp.coda.cs.cmu.edu/pub/coda/
-
-We intend to come out with new Coda releases often, not daily. We
-don't want to slight any OS/platform not mentioned above. We are just
-limited in our resources as to what we can support internally. We
-will be happy to integrate OpenBSD support as well as other OS
-support. Also, adding platform support should be relatively easy and
-we can discuss this. The only difficulty is that Coda has a light weight
-process package. It does some manipulations in assembler which would
-have to be redone for a different platform.
-
-There are several mailing lists @coda.cs.cmu.edu that discuss coda:
-coda-announce and linux-coda. We are going to revise linux-coda to be
-OS neutral, since it is mainly Coda we want to discuss. We appreciate
-comments, feedback, bug reports, bug fixes, enhancements, etc.
-
diff --git a/sys/fs/coda/TODO b/sys/fs/coda/TODO
deleted file mode 100644
index eac514394b38..000000000000
--- a/sys/fs/coda/TODO
+++ /dev/null
@@ -1,17 +0,0 @@
-OOPS:
- FreeBSD does not fsync!!!
-
-Near term:
- Fix bug in executing/mapping new files.
- cfs_mount bug: interaction with cfs_inactive no cfs_unsave.
- vref/vn_lock == vget except no VXWANT which may be on.
- Review locks: vn_lock/VOP_UNLOCK/lockmgr ...
-
-Medium term:
- Add missing VFS methods.
- Do performance profile.
- Tune hash algorithm used in cfs_namecache.
- Tune hash algorithm used in cfs_subr.
-
-Eventually:
- Use standard queue macros.
diff --git a/sys/fs/coda/cnode.h b/sys/fs/coda/cnode.h
deleted file mode 100644
index 450adc3256ab..000000000000
--- a/sys/fs/coda/cnode.h
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/cnode.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/*
- * Mach Operating System
- * Copyright (c) 1990 Carnegie-Mellon University
- * Copyright (c) 1989 Carnegie-Mellon University
- * All rights reserved. The CMU software License Agreement specifies
- * the terms and conditions for use and redistribution.
- */
-
-/*
- * This code was written for the Coda filesystem at Carnegie Mellon University.
- * Contributers include David Steere, James Kistler, and M. Satyanarayanan.
- */
-
-#ifndef _CNODE_H_
-#define _CNODE_H_
-
-#include <sys/vnode.h>
-#include <sys/lock.h>
-#include <machine/clock.h>
-
-MALLOC_DECLARE(M_CODA);
-
-/*
- * tmp below since we need struct queue
- */
-#include <coda/coda_kernel.h>
-
-/*
- * Cnode lookup stuff.
- * NOTE: CODA_CACHESIZE must be a power of 2 for cfshash to work!
- */
-#define CODA_CACHESIZE 512
-
-#define CODA_ALLOC(ptr, cast, size) \
-do { \
- ptr = (cast)malloc((unsigned long) size, M_CODA, M_WAITOK); \
- if (ptr == 0) { \
- panic("kernel malloc returns 0 at %s:%d\n", __FILE__, __LINE__); \
- } \
-} while (0)
-
-#define CODA_FREE(ptr, size) free((ptr), M_CODA)
-
-/*
- * global cache state control
- */
-extern int coda_nc_use;
-
-/*
- * Used to select debugging statements throughout the cfs code.
- */
-extern int codadebug;
-extern int coda_nc_debug;
-extern int coda_printf_delay;
-extern int coda_vnop_print_entry;
-extern int coda_psdev_print_entry;
-extern int coda_vfsop_print_entry;
-
-#define CODADBGMSK(N) (1 << N)
-#define CODADEBUG(N, STMT) { if (codadebug & CODADBGMSK(N)) { STMT } }
-#define myprintf(args) \
-do { \
- if (coda_printf_delay) \
- DELAY(coda_printf_delay);\
- printf args ; \
-} while (0)
-
-struct cnode {
- struct vnode *c_vnode;
- u_short c_flags; /* flags (see below) */
- ViceFid c_fid; /* file handle */
- struct lock c_lock; /* new lock protocol */
- struct vnode *c_ovp; /* open vnode pointer */
- u_short c_ocount; /* count of openers */
- u_short c_owrite; /* count of open for write */
- struct vattr c_vattr; /* attributes */
- char *c_symlink; /* pointer to symbolic link */
- u_short c_symlen; /* length of symbolic link */
- dev_t c_device; /* associated vnode device */
- ino_t c_inode; /* associated vnode inode */
- struct cnode *c_next; /* links if on NetBSD machine */
-};
-#define VTOC(vp) ((struct cnode *)(vp)->v_data)
-#define CTOV(cp) ((struct vnode *)((cp)->c_vnode))
-
-/* flags */
-#define C_VATTR 0x01 /* Validity of vattr in the cnode */
-#define C_SYMLINK 0x02 /* Validity of symlink pointer in the Code */
-#define C_WANTED 0x08 /* Set if lock wanted */
-#define C_LOCKED 0x10 /* Set if lock held */
-#define C_UNMOUNTING 0X20 /* Set if unmounting */
-#define C_PURGING 0x40 /* Set if purging a fid */
-
-#define VALID_VATTR(cp) ((cp->c_flags) & C_VATTR)
-#define VALID_SYMLINK(cp) ((cp->c_flags) & C_SYMLINK)
-#define IS_UNMOUNTING(cp) ((cp)->c_flags & C_UNMOUNTING)
-
-struct vcomm {
- u_long vc_seq;
- struct selinfo vc_selproc;
- struct queue vc_requests;
- struct queue vc_replys;
-};
-
-#define VC_OPEN(vcp) ((vcp)->vc_requests.forw != NULL)
-#define MARK_VC_CLOSED(vcp) (vcp)->vc_requests.forw = NULL;
-#define MARK_VC_OPEN(vcp) /* MT */
-
-struct coda_clstat {
- int ncalls; /* client requests */
- int nbadcalls; /* upcall failures */
- int reqs[CODA_NCALLS]; /* count of each request */
-};
-extern struct coda_clstat coda_clstat;
-
-/*
- * CODA structure to hold mount/filesystem information
- */
-struct coda_mntinfo {
- struct vnode *mi_rootvp;
- struct mount *mi_vfsp;
- struct vcomm mi_vcomm;
- dev_t dev;
- int mi_started;
-};
-extern struct coda_mntinfo coda_mnttbl[]; /* indexed by minor device number */
-
-/*
- * vfs pointer to mount info
- */
-#define vftomi(vfsp) ((struct coda_mntinfo *)(vfsp->mnt_data))
-#define CODA_MOUNTED(vfsp) (vftomi((vfsp)) != (struct coda_mntinfo *)0)
-
-/*
- * vnode pointer to mount info
- */
-#define vtomi(vp) ((struct coda_mntinfo *)(vp->v_mount->mnt_data))
-
-/*
- * Used for identifying usage of "Control" object
- */
-extern struct vnode *coda_ctlvp;
-#define IS_CTL_VP(vp) ((vp) == coda_ctlvp)
-#define IS_CTL_NAME(vp, name, l)((l == CODA_CONTROLLEN) \
- && ((vp) == vtomi((vp))->mi_rootvp) \
- && strncmp(name, CODA_CONTROL, l) == 0)
-
-/*
- * An enum to tell us whether something that will remove a reference
- * to a cnode was a downcall or not
- */
-enum dc_status {
- IS_DOWNCALL = 6,
- NOT_DOWNCALL = 7
-};
-
-/* cfs_psdev.h */
-extern int coda_call(struct coda_mntinfo *mntinfo, int inSize, int *outSize, caddr_t buffer);
-extern int coda_kernel_version;
-
-/* cfs_subr.h */
-extern int handleDownCall(int opcode, union outputArgs *out);
-extern void coda_unmounting(struct mount *whoIam);
-extern int coda_vmflush(struct cnode *cp);
-
-/* cfs_vnodeops.h */
-extern struct cnode *make_coda_node(ViceFid *fid, struct mount *vfsp, short type);
-extern int coda_vnodeopstats_init(void);
-
-/* coda_vfsops.h */
-extern struct mount *devtomp(dev_t dev);
-
-/* sigh */
-#define CODA_RDWR ((u_long) 31)
-
-#endif /* _CNODE_H_ */
-
diff --git a/sys/fs/coda/coda.h b/sys/fs/coda/coda.h
deleted file mode 100644
index 2e59cfcf7d21..000000000000
--- a/sys/fs/coda/coda.h
+++ /dev/null
@@ -1,761 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-
-/*
- *
- * Based on cfs.h from Mach, but revamped for increased simplicity.
- * Linux modifications by Peter Braam, Aug 1996
- */
-
-#ifndef _CODA_HEADER_
-#define _CODA_HEADER_
-
-
-
-/* Catch new _KERNEL defn for NetBSD */
-#ifdef __NetBSD__
-#include <sys/types.h>
-#endif
-
-#ifndef CODA_MAXSYMLINKS
-#define CODA_MAXSYMLINKS 10
-#endif
-
-#if defined(DJGPP) || defined(__CYGWIN32__)
-#ifdef _KERNEL
-typedef unsigned long u_long;
-typedef unsigned int u_int;
-typedef unsigned short u_short;
-typedef u_long ino_t;
-typedef u_long dev_t;
-typedef void * caddr_t;
-#ifdef DOS
-typedef unsigned __int64 u_quad_t;
-#else
-typedef unsigned long long u_quad_t;
-#endif
-
-#define inline
-
-struct timespec {
- long ts_sec;
- long ts_nsec;
-};
-#else /* DJGPP but not _KERNEL */
-#include <sys/types.h>
-#include <sys/time.h>
-typedef unsigned long long u_quad_t;
-#endif /* !_KERNEL */
-#endif /* !DJGPP */
-
-
-#if defined(__linux__)
-#define cdev_t u_quad_t
-#if !defined(_UQUAD_T_) && (!defined(__GLIBC__) || __GLIBC__ < 2)
-#define _UQUAD_T_ 1
-typedef unsigned long long u_quad_t;
-#endif
-#else
-#define cdev_t udev_t
-#endif
-
-#ifdef __CYGWIN32__
-typedef unsigned char u_int8_t;
-struct timespec {
- time_t tv_sec; /* seconds */
- long tv_nsec; /* nanoseconds */
-};
-#endif
-
-
-/*
- * Cfs constants
- */
-#define CODA_MAXNAMLEN 255
-#define CODA_MAXPATHLEN 1024
-#define CODA_MAXSYMLINK 10
-
-/* these are Coda's version of O_RDONLY etc combinations
- * to deal with VFS open modes
- */
-#define C_O_READ 0x001
-#define C_O_WRITE 0x002
-#define C_O_TRUNC 0x010
-#define C_O_EXCL 0x100
-#define C_O_CREAT 0x200
-
-/* these are to find mode bits in Venus */
-#define C_M_READ 00400
-#define C_M_WRITE 00200
-
-/* for access Venus will use */
-#define C_A_C_OK 8 /* Test for writing upon create. */
-#define C_A_R_OK 4 /* Test for read permission. */
-#define C_A_W_OK 2 /* Test for write permission. */
-#define C_A_X_OK 1 /* Test for execute permission. */
-#define C_A_F_OK 0 /* Test for existence. */
-
-
-
-#ifndef _VENUS_DIRENT_T_
-#define _VENUS_DIRENT_T_ 1
-struct venus_dirent {
- unsigned long d_fileno; /* file number of entry */
- unsigned short d_reclen; /* length of this record */
- char d_type; /* file type, see below */
- char d_namlen; /* length of string in d_name */
- char d_name[CODA_MAXNAMLEN + 1];/* name must be no longer than this */
-};
-#undef DIRSIZ
-#define DIRSIZ(dp) ((sizeof (struct venus_dirent) - (CODA_MAXNAMLEN+1)) + \
- (((dp)->d_namlen+1 + 3) &~ 3))
-
-/*
- * File types
- */
-#define CDT_UNKNOWN 0
-#define CDT_FIFO 1
-#define CDT_CHR 2
-#define CDT_DIR 4
-#define CDT_BLK 6
-#define CDT_REG 8
-#define CDT_LNK 10
-#define CDT_SOCK 12
-#define CDT_WHT 14
-
-/*
- * Convert between stat structure types and directory types.
- */
-#define IFTOCDT(mode) (((mode) & 0170000) >> 12)
-#define CDTTOIF(dirtype) ((dirtype) << 12)
-
-#endif
-
-#ifndef _FID_T_
-#define _FID_T_ 1
-typedef u_long VolumeId;
-typedef u_long VnodeId;
-typedef u_long Unique_t;
-typedef u_long FileVersion;
-#endif
-
-#ifndef _VICEFID_T_
-#define _VICEFID_T_ 1
-typedef struct ViceFid {
- VolumeId Volume;
- VnodeId Vnode;
- Unique_t Unique;
-} ViceFid;
-#endif /* VICEFID */
-
-
-#ifdef __linux__
-static __inline__ ino_t coda_f2i(struct ViceFid *fid)
-{
- if ( ! fid )
- return 0;
- if (fid->Vnode == 0xfffffffe || fid->Vnode == 0xffffffff)
- return ((fid->Volume << 20) | (fid->Unique & 0xfffff));
- else
- return (fid->Unique + (fid->Vnode<<10) + (fid->Volume<<20));
-}
-
-#else
-#define coda_f2i(fid)\
- ((fid) ? ((fid)->Unique + ((fid)->Vnode<<10) + ((fid)->Volume<<20)) : 0)
-#endif
-
-
-#ifndef __BIT_TYPES_DEFINED__
-#define u_int32_t unsigned int
-#endif
-
-
-#ifndef _VUID_T_
-#define _VUID_T_
-typedef u_int32_t vuid_t;
-typedef u_int32_t vgid_t;
-#endif /*_VUID_T_ */
-
-#ifndef _CODACRED_T_
-#define _CODACRED_T_
-struct coda_cred {
- vuid_t cr_uid, cr_euid, cr_suid, cr_fsuid; /* Real, efftve, set, fs uid*/
- vgid_t cr_groupid, cr_egid, cr_sgid, cr_fsgid; /* same for groups */
-};
-#endif
-
-#ifndef _VENUS_VATTR_T_
-#define _VENUS_VATTR_T_
-/*
- * Vnode types. VNON means no type.
- */
-enum coda_vtype { C_VNON, C_VREG, C_VDIR, C_VBLK, C_VCHR, C_VLNK, C_VSOCK, C_VFIFO, C_VBAD };
-
-struct coda_vattr {
- int va_type; /* vnode type (for create) */
- u_short va_mode; /* files access mode and type */
- short va_nlink; /* number of references to file */
- vuid_t va_uid; /* owner user id */
- vgid_t va_gid; /* owner group id */
- long va_fileid; /* file id */
- u_quad_t va_size; /* file size in bytes */
- long va_blocksize; /* blocksize preferred for i/o */
- struct timespec va_atime; /* time of last access */
- struct timespec va_mtime; /* time of last modification */
- struct timespec va_ctime; /* time file changed */
- u_long va_gen; /* generation number of file */
- u_long va_flags; /* flags defined for file */
- cdev_t va_rdev; /* device special file represents */
- u_quad_t va_bytes; /* bytes of disk space held by file */
- u_quad_t va_filerev; /* file modification number */
-};
-
-#endif
-
-/*
- * Kernel <--> Venus communications.
- */
-
-#define CODA_ROOT 2
-#define CODA_SYNC 3
-#define CODA_OPEN 4
-#define CODA_CLOSE 5
-#define CODA_IOCTL 6
-#define CODA_GETATTR 7
-#define CODA_SETATTR 8
-#define CODA_ACCESS 9
-#define CODA_LOOKUP 10
-#define CODA_CREATE 11
-#define CODA_REMOVE 12
-#define CODA_LINK 13
-#define CODA_RENAME 14
-#define CODA_MKDIR 15
-#define CODA_RMDIR 16
-#define CODA_READDIR 17
-#define CODA_SYMLINK 18
-#define CODA_READLINK 19
-#define CODA_FSYNC 20
-#define CODA_INACTIVE 21
-#define CODA_VGET 22
-#define CODA_SIGNAL 23
-#define CODA_REPLACE 24
-#define CODA_FLUSH 25
-#define CODA_PURGEUSER 26
-#define CODA_ZAPFILE 27
-#define CODA_ZAPDIR 28
-#define CODA_PURGEFID 30
-#define CODA_OPEN_BY_PATH 31
-#define CODA_RESOLVE 32
-#define CODA_REINTEGRATE 33
-#define CODA_NCALLS 34
-
-#define DOWNCALL(opcode) (opcode >= CODA_REPLACE && opcode <= CODA_PURGEFID)
-
-#define VC_MAXDATASIZE 8192
-#define VC_MAXMSGSIZE sizeof(union inputArgs)+sizeof(union outputArgs) +\
- VC_MAXDATASIZE
-
-#define CIOC_KERNEL_VERSION _IOWR('c', 10, sizeof (int))
-#if 0
- /* don't care about kernel version number */
-#define CODA_KERNEL_VERSION 0
- /* The old venus 4.6 compatible interface */
-#define CODA_KERNEL_VERSION 1
-#endif
- /* venus_lookup gets an extra parameter to aid windows.*/
-#define CODA_KERNEL_VERSION 2
-
-/*
- * Venus <-> Coda RPC arguments
- */
-struct coda_in_hdr {
- unsigned long opcode;
- unsigned long unique; /* Keep multiple outstanding msgs distinct */
- u_short pid; /* Common to all */
- u_short pgid; /* Common to all */
- u_short sid; /* Common to all */
- struct coda_cred cred; /* Common to all */
-};
-
-/* Really important that opcode and unique are 1st two fields! */
-struct coda_out_hdr {
- unsigned long opcode;
- unsigned long unique;
- unsigned long result;
-};
-
-/* coda_root: NO_IN */
-struct coda_root_out {
- struct coda_out_hdr oh;
- ViceFid VFid;
-};
-
-struct coda_root_in {
- struct coda_in_hdr in;
-};
-
-/* coda_sync: */
-/* Nothing needed for coda_sync */
-
-/* coda_open: */
-struct coda_open_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- int flags;
-};
-
-struct coda_open_out {
- struct coda_out_hdr oh;
- cdev_t dev;
- ino_t inode;
-};
-
-
-/* coda_close: */
-struct coda_close_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- int flags;
-};
-
-struct coda_close_out {
- struct coda_out_hdr out;
-};
-
-/* coda_ioctl: */
-struct coda_ioctl_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- int cmd;
- int len;
- int rwflag;
- char *data; /* Place holder for data. */
-};
-
-struct coda_ioctl_out {
- struct coda_out_hdr oh;
- int len;
- caddr_t data; /* Place holder for data. */
-};
-
-
-/* coda_getattr: */
-struct coda_getattr_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
-};
-
-struct coda_getattr_out {
- struct coda_out_hdr oh;
- struct coda_vattr attr;
-};
-
-
-/* coda_setattr: NO_OUT */
-struct coda_setattr_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- struct coda_vattr attr;
-};
-
-struct coda_setattr_out {
- struct coda_out_hdr out;
-};
-
-/* coda_access: NO_OUT */
-struct coda_access_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- int flags;
-};
-
-struct coda_access_out {
- struct coda_out_hdr out;
-};
-
-
-/* lookup flags */
-#define CLU_CASE_SENSITIVE 0x01
-#define CLU_CASE_INSENSITIVE 0x02
-
-/* coda_lookup: */
-struct coda_lookup_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- int name; /* Place holder for data. */
- int flags;
-};
-
-struct coda_lookup_out {
- struct coda_out_hdr oh;
- ViceFid VFid;
- int vtype;
-};
-
-
-/* coda_create: */
-struct coda_create_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- struct coda_vattr attr;
- int excl;
- int mode;
- int name; /* Place holder for data. */
-};
-
-struct coda_create_out {
- struct coda_out_hdr oh;
- ViceFid VFid;
- struct coda_vattr attr;
-};
-
-
-/* coda_remove: NO_OUT */
-struct coda_remove_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- int name; /* Place holder for data. */
-};
-
-struct coda_remove_out {
- struct coda_out_hdr out;
-};
-
-/* coda_link: NO_OUT */
-struct coda_link_in {
- struct coda_in_hdr ih;
- ViceFid sourceFid; /* cnode to link *to* */
- ViceFid destFid; /* Directory in which to place link */
- int tname; /* Place holder for data. */
-};
-
-struct coda_link_out {
- struct coda_out_hdr out;
-};
-
-
-/* coda_rename: NO_OUT */
-struct coda_rename_in {
- struct coda_in_hdr ih;
- ViceFid sourceFid;
- int srcname;
- ViceFid destFid;
- int destname;
-};
-
-struct coda_rename_out {
- struct coda_out_hdr out;
-};
-
-/* coda_mkdir: */
-struct coda_mkdir_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- struct coda_vattr attr;
- int name; /* Place holder for data. */
-};
-
-struct coda_mkdir_out {
- struct coda_out_hdr oh;
- ViceFid VFid;
- struct coda_vattr attr;
-};
-
-
-/* coda_rmdir: NO_OUT */
-struct coda_rmdir_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- int name; /* Place holder for data. */
-};
-
-struct coda_rmdir_out {
- struct coda_out_hdr out;
-};
-
-/* coda_readdir: */
-struct coda_readdir_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- int count;
- int offset;
-};
-
-struct coda_readdir_out {
- struct coda_out_hdr oh;
- int size;
- caddr_t data; /* Place holder for data. */
-};
-
-/* coda_symlink: NO_OUT */
-struct coda_symlink_in {
- struct coda_in_hdr ih;
- ViceFid VFid; /* Directory to put symlink in */
- int srcname;
- struct coda_vattr attr;
- int tname;
-};
-
-struct coda_symlink_out {
- struct coda_out_hdr out;
-};
-
-/* coda_readlink: */
-struct coda_readlink_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
-};
-
-struct coda_readlink_out {
- struct coda_out_hdr oh;
- int count;
- caddr_t data; /* Place holder for data. */
-};
-
-
-/* coda_fsync: NO_OUT */
-struct coda_fsync_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
-};
-
-struct coda_fsync_out {
- struct coda_out_hdr out;
-};
-
-/* coda_inactive: NO_OUT */
-struct coda_inactive_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
-};
-
-/* coda_vget: */
-struct coda_vget_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
-};
-
-struct coda_vget_out {
- struct coda_out_hdr oh;
- ViceFid VFid;
- int vtype;
-};
-
-
-/* CODA_SIGNAL is out-of-band, doesn't need data. */
-/* CODA_INVALIDATE is a venus->kernel call */
-/* CODA_FLUSH is a venus->kernel call */
-
-/* coda_purgeuser: */
-/* CODA_PURGEUSER is a venus->kernel call */
-struct coda_purgeuser_out {
- struct coda_out_hdr oh;
- struct coda_cred cred;
-};
-
-/* coda_zapfile: */
-/* CODA_ZAPFILE is a venus->kernel call */
-struct coda_zapfile_out {
- struct coda_out_hdr oh;
- ViceFid CodaFid;
-};
-
-/* coda_zapdir: */
-/* CODA_ZAPDIR is a venus->kernel call */
-struct coda_zapdir_out {
- struct coda_out_hdr oh;
- ViceFid CodaFid;
-};
-
-/* coda_zapnode: */
-/* CODA_ZAPVNODE is a venus->kernel call */
-struct coda_zapvnode_out {
- struct coda_out_hdr oh;
- struct coda_cred cred;
- ViceFid VFid;
-};
-
-/* coda_purgefid: */
-/* CODA_PURGEFID is a venus->kernel call */
-struct coda_purgefid_out {
- struct coda_out_hdr oh;
- ViceFid CodaFid;
-};
-
-/* coda_rdwr: */
-struct coda_rdwr_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- int rwflag;
- int count;
- int offset;
- int ioflag;
- caddr_t data; /* Place holder for data. */
-};
-
-struct coda_rdwr_out {
- struct coda_out_hdr oh;
- int rwflag;
- int count;
- caddr_t data; /* Place holder for data. */
-};
-
-
-/* coda_replace: */
-/* CODA_REPLACE is a venus->kernel call */
-struct coda_replace_out { /* coda_replace is a venus->kernel call */
- struct coda_out_hdr oh;
- ViceFid NewFid;
- ViceFid OldFid;
-};
-
-/* coda_open_by_path: */
-struct coda_open_by_path_in {
- struct coda_in_hdr ih;
- ViceFid VFid;
- int flags;
-};
-
-struct coda_open_by_path_out {
- struct coda_out_hdr oh;
- int path;
-};
-
-/*
- * Occasionally, we don't cache the fid returned by CODA_LOOKUP.
- * For instance, if the fid is inconsistent.
- * This case is handled by setting the top bit of the type result parameter.
- */
-#define CODA_NOCACHE 0x80000000
-
-union inputArgs {
- struct coda_in_hdr ih; /* NB: every struct below begins with an ih */
- struct coda_open_in coda_open;
- struct coda_close_in coda_close;
- struct coda_ioctl_in coda_ioctl;
- struct coda_getattr_in coda_getattr;
- struct coda_setattr_in coda_setattr;
- struct coda_access_in coda_access;
- struct coda_lookup_in coda_lookup;
- struct coda_create_in coda_create;
- struct coda_remove_in coda_remove;
- struct coda_link_in coda_link;
- struct coda_rename_in coda_rename;
- struct coda_mkdir_in coda_mkdir;
- struct coda_rmdir_in coda_rmdir;
- struct coda_readdir_in coda_readdir;
- struct coda_symlink_in coda_symlink;
- struct coda_readlink_in coda_readlink;
- struct coda_fsync_in coda_fsync;
- struct coda_inactive_in coda_inactive;
- struct coda_vget_in coda_vget;
- struct coda_rdwr_in coda_rdwr;
- struct coda_open_by_path_in coda_open_by_path;
-};
-
-union outputArgs {
- struct coda_out_hdr oh; /* NB: every struct below begins with an oh */
- struct coda_root_out coda_root;
- struct coda_open_out coda_open;
- struct coda_ioctl_out coda_ioctl;
- struct coda_getattr_out coda_getattr;
- struct coda_lookup_out coda_lookup;
- struct coda_create_out coda_create;
- struct coda_mkdir_out coda_mkdir;
- struct coda_readdir_out coda_readdir;
- struct coda_readlink_out coda_readlink;
- struct coda_vget_out coda_vget;
- struct coda_purgeuser_out coda_purgeuser;
- struct coda_zapfile_out coda_zapfile;
- struct coda_zapdir_out coda_zapdir;
- struct coda_zapvnode_out coda_zapvnode;
- struct coda_purgefid_out coda_purgefid;
- struct coda_rdwr_out coda_rdwr;
- struct coda_replace_out coda_replace;
- struct coda_open_by_path_out coda_open_by_path;
-};
-
-union coda_downcalls {
- /* CODA_INVALIDATE is a venus->kernel call */
- /* CODA_FLUSH is a venus->kernel call */
- struct coda_purgeuser_out purgeuser;
- struct coda_zapfile_out zapfile;
- struct coda_zapdir_out zapdir;
- struct coda_zapvnode_out zapvnode;
- struct coda_purgefid_out purgefid;
- struct coda_replace_out replace;
-};
-
-
-/*
- * Used for identifying usage of "Control" and pioctls
- */
-
-#define PIOCPARM_MASK 0x0000ffff
-struct ViceIoctl {
- caddr_t in, out; /* Data to be transferred in, or out */
- short in_size; /* Size of input buffer <= 2K */
- short out_size; /* Maximum size of output buffer, <= 2K */
-};
-
-#if defined(__CYGWIN32__) || defined(DJGPP)
-struct PioctlData {
- unsigned long cmd;
- const char *path;
- int follow;
- struct ViceIoctl vi;
-};
-#else
-struct PioctlData {
- const char *path;
- int follow;
- struct ViceIoctl vi;
-};
-#endif
-
-#define CODA_CONTROL ".CONTROL"
-#define CODA_CONTROLLEN 8
-#define CTL_VOL -1
-#define CTL_VNO -1
-#define CTL_UNI -1
-#define CTL_INO -1
-#define CTL_FILE "/coda/.CONTROL"
-
-
-#define IS_CTL_FID(fidp) ((fidp)->Volume == CTL_VOL &&\
- (fidp)->Vnode == CTL_VNO &&\
- (fidp)->Unique == CTL_UNI)
-#endif
-
diff --git a/sys/fs/coda/coda_fbsd.c b/sys/fs/coda/coda_fbsd.c
deleted file mode 100644
index 9d2bf6e86fed..000000000000
--- a/sys/fs/coda/coda_fbsd.c
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_fbsd.cr,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-#include "vcoda.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/conf.h>
-#include <sys/fcntl.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/ucred.h>
-#include <sys/vnode.h>
-
-#include <vm/vm.h>
-#include <vm/vnode_pager.h>
-
-#include <coda/coda.h>
-#include <coda/cnode.h>
-#include <coda/coda_vnops.h>
-#include <coda/coda_psdev.h>
-
-/*
- From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
- Subject: Re: New 3.0 SNAPshot CDROM about ready for production..
- To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
- Date: Fri, 20 Feb 1998 15:57:01 -0800
-
- > Also I need a character device major number. (and might want to reserve
- > a block of 10 syscalls.)
-
- Just one char device number? No block devices? Very well, cdev 93 is yours!
-*/
-
-#define VC_DEV_NO 93
-
-static struct cdevsw codadevsw = {
- .d_open = vc_nb_open,
- .d_close = vc_nb_close,
- .d_read = vc_nb_read,
- .d_write = vc_nb_write,
- .d_ioctl = vc_nb_ioctl,
- .d_poll = vc_nb_poll,
- .d_name = "Coda",
- .d_maj = VC_DEV_NO,
-};
-
-int vcdebug = 1;
-#define VCDEBUG if (vcdebug) printf
-
-static int
-codadev_modevent(module_t mod, int type, void *data)
-{
-
- switch (type) {
- case MOD_LOAD:
- break;
- case MOD_UNLOAD:
- break;
- default:
- break;
- }
- return 0;
-}
-static moduledata_t codadev_mod = {
- "codadev",
- codadev_modevent,
- NULL
-};
-DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+VC_DEV_NO);
-
-int
-coda_fbsd_getpages(v)
- void *v;
-{
- struct vop_getpages_args *ap = v;
-
-#if 1
- return vop_stdgetpages(ap);
-#else
- {
- struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
- struct vnode *cfvp = cp->c_ovp;
- int opened_internally = 0;
- struct ucred *cred = (struct ucred *) 0;
- struct proc *p = curproc;
- int error = 0;
-
- if (IS_CTL_VP(vp)) {
- return(EINVAL);
- }
-
- /* Redirect the request to UFS. */
-
- if (cfvp == NULL) {
- opened_internally = 1;
-
- error = VOP_OPEN(vp, FREAD, cred, p);
-printf("coda_getp: Internally Opening %p\n", vp);
-
- if (error) {
- printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
- return (error);
- }
- if (vp->v_type == VREG) {
- error = vfs_object_create(vp, p, cred);
- if (error != 0) {
- printf("coda_getpage: vfs_object_create() returns %d\n", error);
- vput(vp);
- return(error);
- }
- }
-
- cfvp = cp->c_ovp;
- } else {
-printf("coda_getp: has container %p\n", cfvp);
- }
-
-printf("coda_fbsd_getpages: using container ");
-/*
- error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
- ap->a_reqpage);
-*/
- error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
- ap->a_reqpage, ap->a_offset);
-printf("error = %d\n", error);
-
- /* Do an internal close if necessary. */
- if (opened_internally) {
- (void)VOP_CLOSE(vp, FREAD, cred, p);
- }
-
- return(error);
- }
-#endif
-}
-
-
-/* for DEVFS, using bpf & tun drivers as examples*/
-static void coda_fbsd_drvinit(void *unused);
-static void coda_fbsd_drvuninit(void *unused);
-static void coda_fbsd_clone(void *arg, char *name, int namelen, dev_t *dev);
-
-static eventhandler_tag clonetag;
-
-static void coda_fbsd_clone(arg, name, namelen, dev)
- void *arg;
- char *name;
- int namelen;
- dev_t *dev;
-{
- int u;
-
- if (*dev != NODEV)
- return;
- if (dev_stdclone(name,NULL,"cfs",&u) != 1)
- return;
-
- *dev = make_dev(&codadevsw,unit2minor(u),UID_ROOT,GID_WHEEL,0600,"cfs%d",u);
- coda_mnttbl[unit2minor(u)].dev = *dev;
-
-}
-
-static void coda_fbsd_drvinit(unused)
- void *unused;
-{
- int i;
-
- clonetag = EVENTHANDLER_REGISTER(dev_clone,coda_fbsd_clone,0,1000);
- for(i=0;i<NVCODA;i++)
- coda_mnttbl[i].dev = NULL;
-}
-
-static void coda_fbsd_drvuninit(unused)
- void *unused;
-{
- int i;
-
- EVENTHANDLER_DEREGISTER(dev_clone,clonetag);
- for(i=0;i<NVCODA;i++)
- if(coda_mnttbl[i].dev)
- destroy_dev(coda_mnttbl[i].dev);
-}
-
-SYSINIT(coda_fbsd_dev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,coda_fbsd_drvinit,NULL);
-
-SYSUNINIT(coda_fbsd_dev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,coda_fbsd_drvuninit,NULL);
diff --git a/sys/fs/coda/coda_io.h b/sys/fs/coda/coda_io.h
deleted file mode 100644
index 4daede1e4c13..000000000000
--- a/sys/fs/coda/coda_io.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_io.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/*
- * Mach Operating System
- * Copyright (c) 1990 Carnegie-Mellon University
- * Copyright (c) 1989 Carnegie-Mellon University
- * All rights reserved. The CMU software License Agreement specifies
- * the terms and conditions for use and redistribution.
- */
-
-/*
- * This code was written for the Coda filesystem at Carnegie Mellon University.
- * Contributers include David Steere, James Kistler, and M. Satyanarayanan.
- */
-
-#ifndef _CODAIO_H_
-#define _CODAIO_H_
-
-/* Define ioctl commands for vcioctl, /dev/cfs */
-
-#define CODARESIZE _IOW('c', 1, struct coda_resize ) /* Resize CODA NameCache */
-#define CODASTATS _IO('c', 2) /* Collect stats */
-#define CODAPRINT _IO('c', 3) /* Print Cache */
-#define CODATEST _IO('c', 4) /* Print Cache */
-
-struct coda_resize { int hashsize, heapsize; };
-
-#endif
diff --git a/sys/fs/coda/coda_kernel.h b/sys/fs/coda/coda_kernel.h
deleted file mode 100644
index cc0fd957f81c..000000000000
--- a/sys/fs/coda/coda_kernel.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_kernel.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/* Macros to manipulate the queue */
-#ifndef INIT_QUEUE
-struct queue {
- struct queue *forw, *back;
-};
-
-#define INIT_QUEUE(head) \
-do { \
- (head).forw = (struct queue *)&(head); \
- (head).back = (struct queue *)&(head); \
-} while (0)
-
-#define GETNEXT(head) (head).forw
-
-#define EMPTY(head) ((head).forw == &(head))
-
-#define EOQ(el, head) ((struct queue *)(el) == (struct queue *)&(head))
-
-#define INSQUE(el, head) \
-do { \
- (el).forw = ((head).back)->forw; \
- (el).back = (head).back; \
- ((head).back)->forw = (struct queue *)&(el); \
- (head).back = (struct queue *)&(el); \
-} while (0)
-
-#define REMQUE(el) \
-do { \
- ((el).forw)->back = (el).back; \
- (el).back->forw = (el).forw; \
-} while (0)
-
-#endif
diff --git a/sys/fs/coda/coda_namecache.c b/sys/fs/coda/coda_namecache.c
deleted file mode 100644
index f9bf03f5f4bf..000000000000
--- a/sys/fs/coda/coda_namecache.c
+++ /dev/null
@@ -1,763 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_namecache.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/*
- * Mach Operating System
- * Copyright (c) 1990 Carnegie-Mellon University
- * Copyright (c) 1989 Carnegie-Mellon University
- * All rights reserved. The CMU software License Agreement specifies
- * the terms and conditions for use and redistribution.
- */
-
-/*
- * This code was written for the Coda filesystem at Carnegie Mellon University.
- * Contributers include David Steere, James Kistler, and M. Satyanarayanan.
- */
-
-/*
- * This module contains the routines to implement the CODA name cache. The
- * purpose of this cache is to reduce the cost of translating pathnames
- * into Vice FIDs. Each entry in the cache contains the name of the file,
- * the vnode (FID) of the parent directory, and the cred structure of the
- * user accessing the file.
- *
- * The first time a file is accessed, it is looked up by the local Venus
- * which first insures that the user has access to the file. In addition
- * we are guaranteed that Venus will invalidate any name cache entries in
- * case the user no longer should be able to access the file. For these
- * reasons we do not need to keep access list information as well as a
- * cred structure for each entry.
- *
- * The table can be accessed through the routines cnc_init(), cnc_enter(),
- * cnc_lookup(), cnc_rmfidcred(), cnc_rmfid(), cnc_rmcred(), and cnc_purge().
- * There are several other routines which aid in the implementation of the
- * hash table.
- */
-
-/*
- * NOTES: rvb@cs
- * 1. The name cache holds a reference to every vnode in it. Hence files can not be
- * closed or made inactive until they are released.
- * 2. coda_nc_name(cp) was added to get a name for a cnode pointer for debugging.
- * 3. coda_nc_find() has debug code to detect when entries are stored with different
- * credentials. We don't understand yet, if/how entries are NOT EQ but still
- * EQUAL
- * 4. I wonder if this name cache could be replace by the vnode name cache.
- * The latter has no zapping functions, so probably not.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/errno.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/ucred.h>
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-
-#include <coda/coda.h>
-#include <coda/cnode.h>
-#include <coda/coda_namecache.h>
-
-#ifdef DEBUG
-#include <coda/coda_vnops.h>
-#endif
-
-/*
- * Declaration of the name cache data structure.
- */
-
-int coda_nc_use = 1; /* Indicate use of CODA Name Cache */
-int coda_nc_size = CODA_NC_CACHESIZE; /* size of the cache */
-int coda_nc_hashsize = CODA_NC_HASHSIZE; /* size of the primary hash */
-
-struct coda_cache *coda_nc_heap; /* pointer to the cache entries */
-struct coda_hash *coda_nc_hash; /* hash table of coda_cache pointers */
-struct coda_lru coda_nc_lru; /* head of lru chain */
-
-struct coda_nc_statistics coda_nc_stat; /* Keep various stats */
-
-/*
- * for testing purposes
- */
-int coda_nc_debug = 0;
-
-/*
- * Entry points for the CODA Name Cache
- */
-static struct coda_cache *coda_nc_find(struct cnode *dcp, const char *name, int namelen,
- struct ucred *cred, int hash);
-static void coda_nc_remove(struct coda_cache *cncp, enum dc_status dcstat);
-
-/*
- * Initialize the cache, the LRU structure and the Hash structure(s)
- */
-
-#define TOTAL_CACHE_SIZE (sizeof(struct coda_cache) * coda_nc_size)
-#define TOTAL_HASH_SIZE (sizeof(struct coda_hash) * coda_nc_hashsize)
-
-int coda_nc_initialized = 0; /* Initially the cache has not been initialized */
-
-void
-coda_nc_init(void)
-{
- int i;
-
- /* zero the statistics structure */
-
- bzero(&coda_nc_stat, (sizeof(struct coda_nc_statistics)));
-
-#ifdef CODA_VERBOSE
- printf("CODA NAME CACHE: CACHE %d, HASH TBL %d\n", CODA_NC_CACHESIZE, CODA_NC_HASHSIZE);
-#endif
- CODA_ALLOC(coda_nc_heap, struct coda_cache *, TOTAL_CACHE_SIZE);
- CODA_ALLOC(coda_nc_hash, struct coda_hash *, TOTAL_HASH_SIZE);
-
- coda_nc_lru.lru_next =
- coda_nc_lru.lru_prev = (struct coda_cache *)LRU_PART(&coda_nc_lru);
-
-
- for (i=0; i < coda_nc_size; i++) { /* initialize the heap */
- CODA_NC_LRUINS(&coda_nc_heap[i], &coda_nc_lru);
- CODA_NC_HSHNUL(&coda_nc_heap[i]);
- coda_nc_heap[i].cp = coda_nc_heap[i].dcp = (struct cnode *)0;
- }
-
- for (i=0; i < coda_nc_hashsize; i++) { /* initialize the hashtable */
- CODA_NC_HSHNUL((struct coda_cache *)&coda_nc_hash[i]);
- }
-
- coda_nc_initialized++;
-}
-
-/*
- * Auxillary routines -- shouldn't be entry points
- */
-
-static struct coda_cache *
-coda_nc_find(dcp, name, namelen, cred, hash)
- struct cnode *dcp;
- const char *name;
- int namelen;
- struct ucred *cred;
- int hash;
-{
- /*
- * hash to find the appropriate bucket, look through the chain
- * for the right entry (especially right cred, unless cred == 0)
- */
- struct coda_cache *cncp;
- int count = 1;
-
- CODA_NC_DEBUG(CODA_NC_FIND,
- myprintf(("coda_nc_find(dcp %p, name %s, len %d, cred %p, hash %d\n",
- dcp, name, namelen, cred, hash));)
-
- for (cncp = coda_nc_hash[hash].hash_next;
- cncp != (struct coda_cache *)&coda_nc_hash[hash];
- cncp = cncp->hash_next, count++)
- {
-
- if ((CODA_NAMEMATCH(cncp, name, namelen, dcp)) &&
- ((cred == 0) || (cncp->cred == cred)))
- {
- /* compare cr_uid instead */
- coda_nc_stat.Search_len += count;
- return(cncp);
- }
-#ifdef DEBUG
- else if (CODA_NAMEMATCH(cncp, name, namelen, dcp)) {
- printf("coda_nc_find: name %s, new cred = %p, cred = %p\n",
- name, cred, cncp->cred);
- printf("nref %d, nuid %d, ngid %d // oref %d, ocred %d, ogid %d\n",
- cred->cr_ref, cred->cr_uid, cred->cr_gid,
- cncp->cred->cr_ref, cncp->cred->cr_uid, cncp->cred->cr_gid);
- print_cred(cred);
- print_cred(cncp->cred);
- }
-#endif
- }
-
- return((struct coda_cache *)0);
-}
-
-/*
- * Enter a new (dir cnode, name) pair into the cache, updating the
- * LRU and Hash as needed.
- */
-void
-coda_nc_enter(dcp, name, namelen, cred, cp)
- struct cnode *dcp;
- const char *name;
- int namelen;
- struct ucred *cred;
- struct cnode *cp;
-{
- struct coda_cache *cncp;
- int hash;
-
- if (coda_nc_use == 0) /* Cache is off */
- return;
-
- CODA_NC_DEBUG(CODA_NC_ENTER,
- myprintf(("Enter: dcp %p cp %p name %s cred %p \n",
- dcp, cp, name, cred)); )
-
- if (namelen > CODA_NC_NAMELEN) {
- CODA_NC_DEBUG(CODA_NC_ENTER,
- myprintf(("long name enter %s\n",name));)
- coda_nc_stat.long_name_enters++; /* record stats */
- return;
- }
-
- hash = CODA_NC_HASH(name, namelen, dcp);
- cncp = coda_nc_find(dcp, name, namelen, cred, hash);
- if (cncp != (struct coda_cache *) 0) {
- coda_nc_stat.dbl_enters++; /* duplicate entry */
- return;
- }
-
- coda_nc_stat.enters++; /* record the enters statistic */
-
- /* Grab the next element in the lru chain */
- cncp = CODA_NC_LRUGET(coda_nc_lru);
-
- CODA_NC_LRUREM(cncp); /* remove it from the lists */
-
- if (CODA_NC_VALID(cncp)) {
- /* Seems really ugly, but we have to decrement the appropriate
- hash bucket length here, so we have to find the hash bucket
- */
- coda_nc_hash[CODA_NC_HASH(cncp->name, cncp->namelen, cncp->dcp)].length--;
-
- coda_nc_stat.lru_rm++; /* zapped a valid entry */
- CODA_NC_HSHREM(cncp);
- vrele(CTOV(cncp->dcp));
- vrele(CTOV(cncp->cp));
- crfree(cncp->cred);
- }
-
- /*
- * Put a hold on the current vnodes and fill in the cache entry.
- */
- vref(CTOV(cp));
- vref(CTOV(dcp));
- cncp->dcp = dcp;
- cncp->cp = cp;
- cncp->namelen = namelen;
- cncp->cred = crhold(cred);
-
- bcopy(name, cncp->name, (unsigned)namelen);
-
- /* Insert into the lru and hash chains. */
-
- CODA_NC_LRUINS(cncp, &coda_nc_lru);
- CODA_NC_HSHINS(cncp, &coda_nc_hash[hash]);
- coda_nc_hash[hash].length++; /* Used for tuning */
-
- CODA_NC_DEBUG(CODA_NC_PRINTCODA_NC, print_coda_nc(); )
-}
-
-/*
- * Find the (dir cnode, name) pair in the cache, if it's cred
- * matches the input, return it, otherwise return 0
- */
-struct cnode *
-coda_nc_lookup(dcp, name, namelen, cred)
- struct cnode *dcp;
- const char *name;
- int namelen;
- struct ucred *cred;
-{
- int hash;
- struct coda_cache *cncp;
-
- if (coda_nc_use == 0) /* Cache is off */
- return((struct cnode *) 0);
-
- if (namelen > CODA_NC_NAMELEN) {
- CODA_NC_DEBUG(CODA_NC_LOOKUP,
- myprintf(("long name lookup %s\n",name));)
- coda_nc_stat.long_name_lookups++; /* record stats */
- return((struct cnode *) 0);
- }
-
- /* Use the hash function to locate the starting point,
- then the search routine to go down the list looking for
- the correct cred.
- */
-
- hash = CODA_NC_HASH(name, namelen, dcp);
- cncp = coda_nc_find(dcp, name, namelen, cred, hash);
- if (cncp == (struct coda_cache *) 0) {
- coda_nc_stat.misses++; /* record miss */
- return((struct cnode *) 0);
- }
-
- coda_nc_stat.hits++;
-
- /* put this entry at the end of the LRU */
- CODA_NC_LRUREM(cncp);
- CODA_NC_LRUINS(cncp, &coda_nc_lru);
-
- /* move it to the front of the hash chain */
- /* don't need to change the hash bucket length */
- CODA_NC_HSHREM(cncp);
- CODA_NC_HSHINS(cncp, &coda_nc_hash[hash]);
-
- CODA_NC_DEBUG(CODA_NC_LOOKUP,
- printf("lookup: dcp %p, name %s, cred %p = cp %p\n",
- dcp, name, cred, cncp->cp); )
-
- return(cncp->cp);
-}
-
-static void
-coda_nc_remove(cncp, dcstat)
- struct coda_cache *cncp;
- enum dc_status dcstat;
-{
- /*
- * remove an entry -- vrele(cncp->dcp, cp), crfree(cred),
- * remove it from it's hash chain, and
- * place it at the head of the lru list.
- */
- CODA_NC_DEBUG(CODA_NC_REMOVE,
- myprintf(("coda_nc_remove %s from parent %lx.%lx.%lx\n",
- cncp->name, (cncp->dcp)->c_fid.Volume,
- (cncp->dcp)->c_fid.Vnode, (cncp->dcp)->c_fid.Unique));)
-
- CODA_NC_HSHREM(cncp);
-
- CODA_NC_HSHNUL(cncp); /* have it be a null chain */
- if ((dcstat == IS_DOWNCALL) && (vrefcnt(CTOV(cncp->dcp)) == 1)) {
- cncp->dcp->c_flags |= C_PURGING;
- }
- vrele(CTOV(cncp->dcp));
-
- if ((dcstat == IS_DOWNCALL) && (vrefcnt(CTOV(cncp->cp)) == 1)) {
- cncp->cp->c_flags |= C_PURGING;
- }
- vrele(CTOV(cncp->cp));
-
- crfree(cncp->cred);
- bzero(DATA_PART(cncp),DATA_SIZE);
-
- /* Put the null entry just after the least-recently-used entry */
- /* LRU_TOP adjusts the pointer to point to the top of the structure. */
- CODA_NC_LRUREM(cncp);
- CODA_NC_LRUINS(cncp, LRU_TOP(coda_nc_lru.lru_prev));
-}
-
-/*
- * Remove all entries with a parent which has the input fid.
- */
-void
-coda_nc_zapParentfid(fid, dcstat)
- ViceFid *fid;
- enum dc_status dcstat;
-{
- /* To get to a specific fid, we might either have another hashing
- function or do a sequential search through the cache for the
- appropriate entries. The later may be acceptable since I don't
- think callbacks or whatever Case 1 covers are frequent occurences.
- */
- struct coda_cache *cncp, *ncncp;
- int i;
-
- if (coda_nc_use == 0) /* Cache is off */
- return;
-
- CODA_NC_DEBUG(CODA_NC_ZAPPFID,
- myprintf(("ZapParent: fid 0x%lx, 0x%lx, 0x%lx \n",
- fid->Volume, fid->Vnode, fid->Unique)); )
-
- coda_nc_stat.zapPfids++;
-
- for (i = 0; i < coda_nc_hashsize; i++) {
-
- /*
- * Need to save the hash_next pointer in case we remove the
- * entry. remove causes hash_next to point to itself.
- */
-
- for (cncp = coda_nc_hash[i].hash_next;
- cncp != (struct coda_cache *)&coda_nc_hash[i];
- cncp = ncncp) {
- ncncp = cncp->hash_next;
- if ((cncp->dcp->c_fid.Volume == fid->Volume) &&
- (cncp->dcp->c_fid.Vnode == fid->Vnode) &&
- (cncp->dcp->c_fid.Unique == fid->Unique)) {
- coda_nc_hash[i].length--; /* Used for tuning */
- coda_nc_remove(cncp, dcstat);
- }
- }
- }
-}
-
-
-/*
- * Remove all entries which have the same fid as the input
- */
-void
-coda_nc_zapfid(fid, dcstat)
- ViceFid *fid;
- enum dc_status dcstat;
-{
- /* See comment for zapParentfid. This routine will be used
- if attributes are being cached.
- */
- struct coda_cache *cncp, *ncncp;
- int i;
-
- if (coda_nc_use == 0) /* Cache is off */
- return;
-
- CODA_NC_DEBUG(CODA_NC_ZAPFID,
- myprintf(("Zapfid: fid 0x%lx, 0x%lx, 0x%lx \n",
- fid->Volume, fid->Vnode, fid->Unique)); )
-
- coda_nc_stat.zapFids++;
-
- for (i = 0; i < coda_nc_hashsize; i++) {
- for (cncp = coda_nc_hash[i].hash_next;
- cncp != (struct coda_cache *)&coda_nc_hash[i];
- cncp = ncncp) {
- ncncp = cncp->hash_next;
- if ((cncp->cp->c_fid.Volume == fid->Volume) &&
- (cncp->cp->c_fid.Vnode == fid->Vnode) &&
- (cncp->cp->c_fid.Unique == fid->Unique)) {
- coda_nc_hash[i].length--; /* Used for tuning */
- coda_nc_remove(cncp, dcstat);
- }
- }
- }
-}
-
-/*
- * Remove all entries which match the fid and the cred
- */
-void
-coda_nc_zapvnode(fid, cred, dcstat)
- ViceFid *fid;
- struct ucred *cred;
- enum dc_status dcstat;
-{
- /* See comment for zapfid. I don't think that one would ever
- want to zap a file with a specific cred from the kernel.
- We'll leave this one unimplemented.
- */
- if (coda_nc_use == 0) /* Cache is off */
- return;
-
- CODA_NC_DEBUG(CODA_NC_ZAPVNODE,
- myprintf(("Zapvnode: fid 0x%lx, 0x%lx, 0x%lx cred %p\n",
- fid->Volume, fid->Vnode, fid->Unique, cred)); )
-
-}
-
-/*
- * Remove all entries which have the (dir vnode, name) pair
- */
-void
-coda_nc_zapfile(dcp, name, namelen)
- struct cnode *dcp;
- const char *name;
- int namelen;
-{
- /* use the hash function to locate the file, then zap all
- entries of it regardless of the cred.
- */
- struct coda_cache *cncp;
- int hash;
-
- if (coda_nc_use == 0) /* Cache is off */
- return;
-
- CODA_NC_DEBUG(CODA_NC_ZAPFILE,
- myprintf(("Zapfile: dcp %p name %s \n",
- dcp, name)); )
-
- if (namelen > CODA_NC_NAMELEN) {
- coda_nc_stat.long_remove++; /* record stats */
- return;
- }
-
- coda_nc_stat.zapFile++;
-
- hash = CODA_NC_HASH(name, namelen, dcp);
- cncp = coda_nc_find(dcp, name, namelen, 0, hash);
-
- while (cncp) {
- coda_nc_hash[hash].length--; /* Used for tuning */
-
- coda_nc_remove(cncp, NOT_DOWNCALL);
- cncp = coda_nc_find(dcp, name, namelen, 0, hash);
- }
-}
-
-/*
- * Remove all the entries for a particular user. Used when tokens expire.
- * A user is determined by his/her effective user id (id_uid).
- */
-void
-coda_nc_purge_user(uid, dcstat)
- vuid_t uid;
- enum dc_status dcstat;
-{
- /*
- * I think the best approach is to go through the entire cache
- * via HASH or whatever and zap all entries which match the
- * input cred. Or just flush the whole cache. It might be
- * best to go through on basis of LRU since cache will almost
- * always be full and LRU is more straightforward.
- */
-
- struct coda_cache *cncp, *ncncp;
- int hash;
-
- if (coda_nc_use == 0) /* Cache is off */
- return;
-
- CODA_NC_DEBUG(CODA_NC_PURGEUSER,
- myprintf(("ZapDude: uid %x\n", uid)); )
- coda_nc_stat.zapUsers++;
-
- for (cncp = CODA_NC_LRUGET(coda_nc_lru);
- cncp != (struct coda_cache *)(&coda_nc_lru);
- cncp = ncncp) {
- ncncp = CODA_NC_LRUGET(*cncp);
-
- if ((CODA_NC_VALID(cncp)) &&
- ((cncp->cred)->cr_uid == uid)) {
- /* Seems really ugly, but we have to decrement the appropriate
- hash bucket length here, so we have to find the hash bucket
- */
- hash = CODA_NC_HASH(cncp->name, cncp->namelen, cncp->dcp);
- coda_nc_hash[hash].length--; /* For performance tuning */
-
- coda_nc_remove(cncp, dcstat);
- }
- }
-}
-
-/*
- * Flush the entire name cache. In response to a flush of the Venus cache.
- */
-void
-coda_nc_flush(dcstat)
- enum dc_status dcstat;
-{
- /* One option is to deallocate the current name cache and
- call init to start again. Or just deallocate, then rebuild.
- Or again, we could just go through the array and zero the
- appropriate fields.
- */
-
- /*
- * Go through the whole lru chain and kill everything as we go.
- * I don't use remove since that would rebuild the lru chain
- * as it went and that seemed unneccesary.
- */
- struct coda_cache *cncp;
- int i;
-
- if (coda_nc_use == 0) /* Cache is off */
- return;
-
- coda_nc_stat.Flushes++;
-
- for (cncp = CODA_NC_LRUGET(coda_nc_lru);
- cncp != (struct coda_cache *)&coda_nc_lru;
- cncp = CODA_NC_LRUGET(*cncp)) {
- if (CODA_NC_VALID(cncp)) {
-
- CODA_NC_HSHREM(cncp); /* only zero valid nodes */
- CODA_NC_HSHNUL(cncp);
- if ((dcstat == IS_DOWNCALL)
- && (vrefcnt(CTOV(cncp->dcp)) == 1))
- {
- cncp->dcp->c_flags |= C_PURGING;
- }
- vrele(CTOV(cncp->dcp));
-
- ASSERT_VOP_LOCKED(CTOV(cncp->cp), "coda_nc_flush");
- if (CTOV(cncp->cp)->v_vflag & VV_TEXT) {
- if (coda_vmflush(cncp->cp))
- CODADEBUG(CODA_FLUSH,
- myprintf(("coda_nc_flush: (%lx.%lx.%lx) busy\n", cncp->cp->c_fid.Volume, cncp->cp->c_fid.Vnode, cncp->cp->c_fid.Unique)); )
- }
-
- if ((dcstat == IS_DOWNCALL)
- && (vrefcnt(CTOV(cncp->cp)) == 1))
- {
- cncp->cp->c_flags |= C_PURGING;
- }
- vrele(CTOV(cncp->cp));
-
- crfree(cncp->cred);
- bzero(DATA_PART(cncp),DATA_SIZE);
- }
- }
-
- for (i = 0; i < coda_nc_hashsize; i++)
- coda_nc_hash[i].length = 0;
-}
-
-/*
- * Debugging routines
- */
-
-/*
- * This routine should print out all the hash chains to the console.
- */
-void
-print_coda_nc(void)
-{
- int hash;
- struct coda_cache *cncp;
-
- for (hash = 0; hash < coda_nc_hashsize; hash++) {
- myprintf(("\nhash %d\n",hash));
-
- for (cncp = coda_nc_hash[hash].hash_next;
- cncp != (struct coda_cache *)&coda_nc_hash[hash];
- cncp = cncp->hash_next) {
- myprintf(("cp %p dcp %p cred %p name %s\n",
- cncp->cp, cncp->dcp,
- cncp->cred, cncp->name));
- }
- }
-}
-
-void
-coda_nc_gather_stats(void)
-{
- int i, max = 0, sum = 0, temp, zeros = 0, ave, n;
-
- for (i = 0; i < coda_nc_hashsize; i++) {
- if (coda_nc_hash[i].length) {
- sum += coda_nc_hash[i].length;
- } else {
- zeros++;
- }
-
- if (coda_nc_hash[i].length > max)
- max = coda_nc_hash[i].length;
- }
-
- /*
- * When computing the Arithmetic mean, only count slots which
- * are not empty in the distribution.
- */
- coda_nc_stat.Sum_bucket_len = sum;
- coda_nc_stat.Num_zero_len = zeros;
- coda_nc_stat.Max_bucket_len = max;
-
- if ((n = coda_nc_hashsize - zeros) > 0)
- ave = sum / n;
- else
- ave = 0;
-
- sum = 0;
- for (i = 0; i < coda_nc_hashsize; i++) {
- if (coda_nc_hash[i].length) {
- temp = coda_nc_hash[i].length - ave;
- sum += temp * temp;
- }
- }
- coda_nc_stat.Sum2_bucket_len = sum;
-}
-
-/*
- * The purpose of this routine is to allow the hash and cache sizes to be
- * changed dynamically. This should only be used in controlled environments,
- * it makes no effort to lock other users from accessing the cache while it
- * is in an improper state (except by turning the cache off).
- */
-int
-coda_nc_resize(hashsize, heapsize, dcstat)
- int hashsize, heapsize;
- enum dc_status dcstat;
-{
- if ((hashsize % 2) || (heapsize % 2)) { /* Illegal hash or cache sizes */
- return(EINVAL);
- }
-
- coda_nc_use = 0; /* Turn the cache off */
-
- coda_nc_flush(dcstat); /* free any cnodes in the cache */
-
- /* WARNING: free must happen *before* size is reset */
- CODA_FREE(coda_nc_heap,TOTAL_CACHE_SIZE);
- CODA_FREE(coda_nc_hash,TOTAL_HASH_SIZE);
-
- coda_nc_hashsize = hashsize;
- coda_nc_size = heapsize;
-
- coda_nc_init(); /* Set up a cache with the new size */
-
- coda_nc_use = 1; /* Turn the cache back on */
- return(0);
-}
-
-#ifdef DEBUG
-char coda_nc_name_buf[CODA_MAXNAMLEN+1];
-
-void
-coda_nc_name(struct cnode *cp)
-{
- struct coda_cache *cncp, *ncncp;
- int i;
-
- if (coda_nc_use == 0) /* Cache is off */
- return;
-
- for (i = 0; i < coda_nc_hashsize; i++) {
- for (cncp = coda_nc_hash[i].hash_next;
- cncp != (struct coda_cache *)&coda_nc_hash[i];
- cncp = ncncp) {
- ncncp = cncp->hash_next;
- if (cncp->cp == cp) {
- bcopy(cncp->name, coda_nc_name_buf, cncp->namelen);
- coda_nc_name_buf[cncp->namelen] = 0;
- printf(" is %s (%p,%p)@%p",
- coda_nc_name_buf, cncp->cp, cncp->dcp, cncp);
- }
-
- }
- }
-}
-#endif
diff --git a/sys/fs/coda/coda_namecache.h b/sys/fs/coda/coda_namecache.h
deleted file mode 100644
index fb9ae8c2346a..000000000000
--- a/sys/fs/coda/coda_namecache.h
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_namecache.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/*
- * Mach Operating System
- * Copyright (c) 1990 Carnegie-Mellon University
- * Copyright (c) 1989 Carnegie-Mellon University
- * All rights reserved. The CMU software License Agreement specifies
- * the terms and conditions for use and redistribution.
- */
-
-/*
- * This code was written for the Coda filesystem at Carnegie Mellon University.
- * Contributers include David Steere, James Kistler, and M. Satyanarayanan.
- */
-
-#ifndef _CODA_NC_HEADER_
-#define _CODA_NC_HEADER_
-
-/*
- * Coda constants
- */
-#define CODA_NC_NAMELEN 15 /* longest name stored in cache */
-#define CODA_NC_CACHESIZE 256 /* Default cache size */
-#define CODA_NC_HASHSIZE 64 /* Must be multiple of 2 */
-
-/*
- * Hash function for the primary hash.
- */
-
-/*
- * First try -- (first + last letters + length + (int)cp) mod size
- * 2nd try -- same, except dir fid.vnode instead of cp
- */
-
-#ifdef oldhash
-#define CODA_NC_HASH(name, namelen, cp) \
- ((name[0] + name[namelen-1] + namelen + (int)(intptr_t)(cp)) & (coda_nc_hashsize-1))
-#else
-#define CODA_NC_HASH(name, namelen, cp) \
- ((name[0] + (name[namelen-1]<<4) + namelen + (((int)(intptr_t)cp)>>8)) & (coda_nc_hashsize-1))
-#endif
-
-#define CODA_NAMEMATCH(cp, name, namelen, dcp) \
- ((namelen == cp->namelen) && (dcp == cp->dcp) && \
- (bcmp(cp->name,name,namelen) == 0))
-
-/*
- * Functions to modify the hash and lru chains.
- * insque and remque assume that the pointers are the first thing
- * in the list node, thus the trickery for lru.
- */
-
-#define CODA_NC_HSHINS(elem, pred) insque(elem,pred)
-#define CODA_NC_HSHREM(elem) remque(elem)
-#define CODA_NC_HSHNUL(elem) (elem)->hash_next = \
- (elem)->hash_prev = (elem)
-
-#define CODA_NC_LRUINS(elem, pred) insque(LRU_PART(elem), LRU_PART(pred))
-#define CODA_NC_LRUREM(elem) remque(LRU_PART(elem));
-#define CODA_NC_LRUGET(lruhead) LRU_TOP((lruhead).lru_prev)
-
-#define CODA_NC_VALID(cncp) (cncp->dcp != (struct cnode *)0)
-
-#define LRU_PART(cncp) (struct coda_cache *) \
- ((char *)cncp + (2*sizeof(struct coda_cache *)))
-#define LRU_TOP(cncp) (struct coda_cache *) \
- ((char *)cncp - (2*sizeof(struct coda_cache *)))
-#define DATA_PART(cncp) (struct coda_cache *) \
- ((char *)cncp + (4*sizeof(struct coda_cache *)))
-#define DATA_SIZE (sizeof(struct coda_cache)-(4*sizeof(struct coda_cache *)))
-
-/*
- * Structure for an element in the CODA Name Cache.
- * NOTE: I use the position of arguments and their size in the
- * implementation of the functions CODA_NC_LRUINS, CODA_NC_LRUREM, and
- * DATA_PART.
- */
-
-struct coda_cache {
- struct coda_cache *hash_next,*hash_prev; /* Hash list */
- struct coda_cache *lru_next, *lru_prev; /* LRU list */
- struct cnode *cp; /* vnode of the file */
- struct cnode *dcp; /* parent's cnode */
- struct ucred *cred; /* user credentials */
- char name[CODA_NC_NAMELEN]; /* segment name */
- int namelen; /* length of name */
-};
-
-struct coda_lru { /* Start of LRU chain */
- char *dummy1, *dummy2; /* place holders */
- struct coda_cache *lru_next, *lru_prev; /* position of pointers is important */
-};
-
-
-struct coda_hash { /* Start of Hash chain */
- struct coda_cache *hash_next, *hash_prev; /* NOTE: chain pointers must be first */
- int length; /* used for tuning purposes */
-};
-
-
-/*
- * Symbols to aid in debugging the namecache code. Assumes the existence
- * of the variable coda_nc_debug, which is defined in cfs_namecache.c
- */
-#define CODA_NC_DEBUG(N, STMT) { if (coda_nc_debug & (1 <<N)) { STMT } }
-
-/* Prototypes of functions exported within cfs */
-extern void coda_nc_init(void);
-extern void coda_nc_enter(struct cnode *, const char *, int, struct ucred *, struct cnode *);
-extern struct cnode *coda_nc_lookup(struct cnode *, const char *, int, struct ucred *);
-
-extern void coda_nc_zapParentfid(ViceFid *, enum dc_status);
-extern void coda_nc_zapfid(ViceFid *, enum dc_status);
-extern void coda_nc_zapvnode(ViceFid *, struct ucred *, enum dc_status);
-extern void coda_nc_zapfile(struct cnode *, const char *, int);
-extern void coda_nc_purge_user(vuid_t, enum dc_status);
-extern void coda_nc_flush(enum dc_status);
-
-extern void print_coda_nc(void);
-extern void coda_nc_gather_stats(void);
-extern int coda_nc_resize(int, int, enum dc_status);
-extern void coda_nc_name(struct cnode *cp);
-
-/*
- * Structure to contain statistics on the cache usage
- */
-
-struct coda_nc_statistics {
- unsigned hits;
- unsigned misses;
- unsigned enters;
- unsigned dbl_enters;
- unsigned long_name_enters;
- unsigned long_name_lookups;
- unsigned long_remove;
- unsigned lru_rm;
- unsigned zapPfids;
- unsigned zapFids;
- unsigned zapFile;
- unsigned zapUsers;
- unsigned Flushes;
- unsigned Sum_bucket_len;
- unsigned Sum2_bucket_len;
- unsigned Max_bucket_len;
- unsigned Num_zero_len;
- unsigned Search_len;
-};
-
-#define CODA_NC_FIND ((u_long) 1)
-#define CODA_NC_REMOVE ((u_long) 2)
-#define CODA_NC_INIT ((u_long) 3)
-#define CODA_NC_ENTER ((u_long) 4)
-#define CODA_NC_LOOKUP ((u_long) 5)
-#define CODA_NC_ZAPPFID ((u_long) 6)
-#define CODA_NC_ZAPFID ((u_long) 7)
-#define CODA_NC_ZAPVNODE ((u_long) 8)
-#define CODA_NC_ZAPFILE ((u_long) 9)
-#define CODA_NC_PURGEUSER ((u_long) 10)
-#define CODA_NC_FLUSH ((u_long) 11)
-#define CODA_NC_PRINTCODA_NC ((u_long) 12)
-#define CODA_NC_PRINTSTATS ((u_long) 13)
-
-#endif
diff --git a/sys/fs/coda/coda_opstats.h b/sys/fs/coda/coda_opstats.h
deleted file mode 100644
index 8661a07ebfa0..000000000000
--- a/sys/fs/coda/coda_opstats.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_opstats.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/*
- * operation stats: what the minicache can intercept that
- * *isn't* seen by venus. These stats are kept to augment
- * the stats maintained by the Volume-Session mechanism.
- */
-
-/* vfsops:
- * mount: not currently bounced to Venus
- * umount: nope
- * root: only first call, rest is cached.
- * statfs: none (bogus)
- * sync: none (bogus)
- * vget: all
- */
-
-#define CODA_MOUNT_STATS 0
-#define CODA_UMOUNT_STATS 1
-#define CODA_ROOT_STATS 2
-#define CODA_STATFS_STATS 3
-#define CODA_SYNC_STATS 4
-#define CODA_VGET_STATS 5
-#define CODA_VFSOPS_SIZE 6
-
-/* vnodeops:
- * open: all to venus
- * close: all to venus
- * rdrw: bogus. Maybe redirected to UFS.
- * May call open/close for internal opens/closes
- * (Does exec not call open?)
- * ioctl: causes a lookupname
- * passes through
- * select: can't get there from here.
- * getattr: can be satsified by cache
- * setattr: all go through
- * access: can be satisfied by cache
- * readlink: can be satisfied by cache
- * fsync: passes through
- * inactive: passes through
- * lookup: can be satisfied by cache
- * create: passes through
- * remove: passes through
- * link: passes through
- * rename: passes through
- * mkdir: passes through
- * rmdir: passes through
- * symlink: passes through
- * readdir: may be redirected to UFS
- * may cause an "internal" open/close
- */
-
-#define CODA_OPEN_STATS 0
-#define CODA_CLOSE_STATS 1
-#define CODA_RDWR_STATS 2
-#define CODA_IOCTL_STATS 3
-#define CODA_SELECT_STATS 4
-#define CODA_GETATTR_STATS 5
-#define CODA_SETATTR_STATS 6
-#define CODA_ACCESS_STATS 7
-#define CODA_READLINK_STATS 8
-#define CODA_FSYNC_STATS 9
-#define CODA_INACTIVE_STATS 10
-#define CODA_LOOKUP_STATS 11
-#define CODA_CREATE_STATS 12
-#define CODA_REMOVE_STATS 13
-#define CODA_LINK_STATS 14
-#define CODA_RENAME_STATS 15
-#define CODA_MKDIR_STATS 16
-#define CODA_RMDIR_STATS 17
-#define CODA_SYMLINK_STATS 18
-#define CODA_READDIR_STATS 19
-#define CODA_VNODEOPS_SIZE 20
-
-/*
- * I propose the following structres:
- */
-
-struct coda_op_stats {
- int opcode; /* vfs opcode */
- long entries; /* number of times call attempted */
- long sat_intrn; /* number of times call satisfied by cache */
- long unsat_intrn; /* number of times call failed in cache, but
- was not bounced to venus proper. */
- long gen_intrn; /* number of times call generated internally */
- /* (do we need that?) */
-};
-
-/*
- * With each call to the minicache, we'll bump the counters whenver
- * a call is satisfied internally (through the cache or through a
- * redirect), and whenever an operation is caused internally.
- * Then, we can add the total operations caught by the minicache
- * to the world-wide totals, and leave a caveat for the specific
- * graphs later.
- */
diff --git a/sys/fs/coda/coda_pioctl.h b/sys/fs/coda/coda_pioctl.h
deleted file mode 100644
index a76c653e9f7b..000000000000
--- a/sys/fs/coda/coda_pioctl.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_pioctl.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/*
- * Mach Operating System
- * Copyright (c) 1989 Carnegie-Mellon University
- * Copyright (c) 1988 Carnegie-Mellon University
- * Copyright (c) 1987 Carnegie-Mellon University
- * All rights reserved. The CMU software License Agreement specifies
- * the terms and conditions for use and redistribution.
- */
-
-/*
- * ITC Remote filesystem - vice ioctl interface module
- */
-
-/*
- * TODO: Find /usr/local/include/viceioctl.h.
- */
-
-#ifndef _SYS_PIOCTL_H_
-#define _SYS_PIOCTL_H_
-
-/* The 2K limits above are a consequence of the size of the kernel buffer
- used to buffer requests from the user to venus--2*MAXPATHLEN.
- The buffer pointers may be null, or the counts may be 0 if there
- are no input or output parameters
- */
-
-#define _VICEIOCTL(id) ((unsigned int ) _IOW('V', id, struct ViceIoctl))
-
-/* Use this macro to define up to 256 vice ioctl's. These ioctl's
- all potentially have in/out parameters--this depends upon the
- values in the ViceIoctl structure. This structure is itself passed
- into the kernel by the normal ioctl parameter passing mechanism.
- */
-
-#define _VALIDVICEIOCTL(com) (com >= _VICEIOCTL(0) && com <= _VICEIOCTL(255))
-
-#endif
diff --git a/sys/fs/coda/coda_psdev.c b/sys/fs/coda/coda_psdev.c
deleted file mode 100644
index ef237c47e4a6..000000000000
--- a/sys/fs/coda/coda_psdev.c
+++ /dev/null
@@ -1,685 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_psdev.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/*
- * Mach Operating System
- * Copyright (c) 1989 Carnegie-Mellon University
- * All rights reserved. The CMU software License Agreement specifies
- * the terms and conditions for use and redistribution.
- */
-
-/*
- * This code was written for the Coda filesystem at Carnegie Mellon
- * University. Contributers include David Steere, James Kistler, and
- * M. Satyanarayanan. */
-
-/*
- * These routines define the psuedo device for communication between
- * Coda's Venus and Minicache in Mach 2.6. They used to be in cfs_subr.c,
- * but I moved them to make it easier to port the Minicache without
- * porting coda. -- DCS 10/12/94
- */
-
-/* These routines are the device entry points for Venus. */
-
-extern int coda_nc_initialized; /* Set if cache has been initialized */
-
-#include <vcoda.h>
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/ioccom.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/file.h> /* must come after sys/malloc.h */
-#include <sys/mount.h>
-#include <sys/mutex.h>
-#include <sys/poll.h>
-#include <sys/proc.h>
-
-#include <coda/coda.h>
-#include <coda/cnode.h>
-#include <coda/coda_namecache.h>
-#include <coda/coda_io.h>
-#include <coda/coda_psdev.h>
-
-#define CTL_C
-
-#ifdef CTL_C
-#include <sys/signalvar.h>
-#endif
-
-int coda_psdev_print_entry = 0;
-static
-int outstanding_upcalls = 0;
-int coda_call_sleep = PZERO - 1;
-#ifdef CTL_C
-int coda_pcatch = PCATCH;
-#else
-#endif
-
-#define ENTRY if(coda_psdev_print_entry) myprintf(("Entered %s\n",__func__))
-
-void vcodaattach(int n);
-
-struct vmsg {
- struct queue vm_chain;
- caddr_t vm_data;
- u_short vm_flags;
- u_short vm_inSize; /* Size is at most 5000 bytes */
- u_short vm_outSize;
- u_short vm_opcode; /* copied from data to save ptr lookup */
- int vm_unique;
- caddr_t vm_sleep; /* Not used by Mach. */
-};
-
-#define VM_READ 1
-#define VM_WRITE 2
-#define VM_INTR 4
-
-/* vcodaattach: do nothing */
-void
-vcodaattach(n)
- int n;
-{
-}
-
-int
-vc_nb_open(dev, flag, mode, td)
- dev_t dev;
- int flag;
- int mode;
- struct thread *td; /* NetBSD only */
-{
- register struct vcomm *vcp;
-
- ENTRY;
-
- if (minor(dev) >= NVCODA || minor(dev) < 0)
- return(ENXIO);
-
- if (!coda_nc_initialized)
- coda_nc_init();
-
- vcp = &coda_mnttbl[minor(dev)].mi_vcomm;
- if (VC_OPEN(vcp))
- return(EBUSY);
-
- bzero(&(vcp->vc_selproc), sizeof (struct selinfo));
- INIT_QUEUE(vcp->vc_requests);
- INIT_QUEUE(vcp->vc_replys);
- MARK_VC_OPEN(vcp);
-
- coda_mnttbl[minor(dev)].mi_vfsp = NULL;
- coda_mnttbl[minor(dev)].mi_rootvp = NULL;
-
- return(0);
-}
-
-int
-vc_nb_close (dev, flag, mode, td)
- dev_t dev;
- int flag;
- int mode;
- struct thread *td;
-{
- register struct vcomm *vcp;
- register struct vmsg *vmp, *nvmp = NULL;
- struct coda_mntinfo *mi;
- int err;
-
- ENTRY;
-
- if (minor(dev) >= NVCODA || minor(dev) < 0)
- return(ENXIO);
-
- mi = &coda_mnttbl[minor(dev)];
- vcp = &(mi->mi_vcomm);
-
- if (!VC_OPEN(vcp))
- panic("vcclose: not open");
-
- /* prevent future operations on this vfs from succeeding by auto-
- * unmounting any vfs mounted via this device. This frees user or
- * sysadm from having to remember where all mount points are located.
- * Put this before WAKEUPs to avoid queuing new messages between
- * the WAKEUP and the unmount (which can happen if we're unlucky)
- */
- if (!mi->mi_rootvp) {
- /* just a simple open/close w no mount */
- MARK_VC_CLOSED(vcp);
- return 0;
- }
-
- /* Let unmount know this is for real */
- VTOC(mi->mi_rootvp)->c_flags |= C_UNMOUNTING;
- coda_unmounting(mi->mi_vfsp);
-
- outstanding_upcalls = 0;
- /* Wakeup clients so they can return. */
- for (vmp = (struct vmsg *)GETNEXT(vcp->vc_requests);
- !EOQ(vmp, vcp->vc_requests);
- vmp = nvmp)
- {
- nvmp = (struct vmsg *)GETNEXT(vmp->vm_chain);
- /* Free signal request messages and don't wakeup cause
- no one is waiting. */
- if (vmp->vm_opcode == CODA_SIGNAL) {
- CODA_FREE((caddr_t)vmp->vm_data, (u_int)VC_IN_NO_DATA);
- CODA_FREE((caddr_t)vmp, (u_int)sizeof(struct vmsg));
- continue;
- }
- outstanding_upcalls++;
- wakeup(&vmp->vm_sleep);
- }
-
- for (vmp = (struct vmsg *)GETNEXT(vcp->vc_replys);
- !EOQ(vmp, vcp->vc_replys);
- vmp = (struct vmsg *)GETNEXT(vmp->vm_chain))
- {
- outstanding_upcalls++;
- wakeup(&vmp->vm_sleep);
- }
-
- MARK_VC_CLOSED(vcp);
-
- if (outstanding_upcalls) {
-#ifdef CODA_VERBOSE
- printf("presleep: outstanding_upcalls = %d\n", outstanding_upcalls);
- (void) tsleep(&outstanding_upcalls, coda_call_sleep, "coda_umount", 0);
- printf("postsleep: outstanding_upcalls = %d\n", outstanding_upcalls);
-#else
- (void) tsleep(&outstanding_upcalls, coda_call_sleep, "coda_umount", 0);
-#endif
- }
-
- err = dounmount(mi->mi_vfsp, flag, td);
- if (err)
- myprintf(("Error %d unmounting vfs in vcclose(%d)\n",
- err, minor(dev)));
- return 0;
-}
-
-int
-vc_nb_read(dev, uiop, flag)
- dev_t dev;
- struct uio *uiop;
- int flag;
-{
- register struct vcomm * vcp;
- register struct vmsg *vmp;
- int error = 0;
-
- ENTRY;
-
- if (minor(dev) >= NVCODA || minor(dev) < 0)
- return(ENXIO);
-
- vcp = &coda_mnttbl[minor(dev)].mi_vcomm;
- /* Get message at head of request queue. */
- if (EMPTY(vcp->vc_requests))
- return(0); /* Nothing to read */
-
- vmp = (struct vmsg *)GETNEXT(vcp->vc_requests);
-
- /* Move the input args into userspace */
- uiop->uio_rw = UIO_READ;
- error = uiomove(vmp->vm_data, vmp->vm_inSize, uiop);
- if (error) {
- myprintf(("vcread: error (%d) on uiomove\n", error));
- error = EINVAL;
- }
-
-#ifdef OLD_DIAGNOSTIC
- if (vmp->vm_chain.forw == 0 || vmp->vm_chain.back == 0)
- panic("vc_nb_read: bad chain");
-#endif
-
- REMQUE(vmp->vm_chain);
-
- /* If request was a signal, free up the message and don't
- enqueue it in the reply queue. */
- if (vmp->vm_opcode == CODA_SIGNAL) {
- if (codadebug)
- myprintf(("vcread: signal msg (%d, %d)\n",
- vmp->vm_opcode, vmp->vm_unique));
- CODA_FREE((caddr_t)vmp->vm_data, (u_int)VC_IN_NO_DATA);
- CODA_FREE((caddr_t)vmp, (u_int)sizeof(struct vmsg));
- return(error);
- }
-
- vmp->vm_flags |= VM_READ;
- INSQUE(vmp->vm_chain, vcp->vc_replys);
-
- return(error);
-}
-
-int
-vc_nb_write(dev, uiop, flag)
- dev_t dev;
- struct uio *uiop;
- int flag;
-{
- register struct vcomm * vcp;
- register struct vmsg *vmp;
- struct coda_out_hdr *out;
- u_long seq;
- u_long opcode;
- int buf[2];
- int error = 0;
-
- ENTRY;
-
- if (minor(dev) >= NVCODA || minor(dev) < 0)
- return(ENXIO);
-
- vcp = &coda_mnttbl[minor(dev)].mi_vcomm;
-
- /* Peek at the opcode, unique without transfering the data. */
- uiop->uio_rw = UIO_WRITE;
- error = uiomove((caddr_t)buf, sizeof(int) * 2, uiop);
- if (error) {
- myprintf(("vcwrite: error (%d) on uiomove\n", error));
- return(EINVAL);
- }
-
- opcode = buf[0];
- seq = buf[1];
-
- if (codadebug)
- myprintf(("vcwrite got a call for %ld.%ld\n", opcode, seq));
-
- if (DOWNCALL(opcode)) {
- union outputArgs pbuf;
-
- /* get the rest of the data. */
- uiop->uio_rw = UIO_WRITE;
- error = uiomove((caddr_t)&pbuf.coda_purgeuser.oh.result, sizeof(pbuf) - (sizeof(int)*2), uiop);
- if (error) {
- myprintf(("vcwrite: error (%d) on uiomove (Op %ld seq %ld)\n",
- error, opcode, seq));
- return(EINVAL);
- }
-
- return handleDownCall(opcode, &pbuf);
- }
-
- /* Look for the message on the (waiting for) reply queue. */
- for (vmp = (struct vmsg *)GETNEXT(vcp->vc_replys);
- !EOQ(vmp, vcp->vc_replys);
- vmp = (struct vmsg *)GETNEXT(vmp->vm_chain))
- {
- if (vmp->vm_unique == seq) break;
- }
-
- if (EOQ(vmp, vcp->vc_replys)) {
- if (codadebug)
- myprintf(("vcwrite: msg (%ld, %ld) not found\n", opcode, seq));
-
- return(ESRCH);
- }
-
- /* Remove the message from the reply queue */
- REMQUE(vmp->vm_chain);
-
- /* move data into response buffer. */
- out = (struct coda_out_hdr *)vmp->vm_data;
- /* Don't need to copy opcode and uniquifier. */
-
- /* get the rest of the data. */
- if (vmp->vm_outSize < uiop->uio_resid) {
- myprintf(("vcwrite: more data than asked for (%d < %d)\n",
- vmp->vm_outSize, uiop->uio_resid));
- wakeup(&vmp->vm_sleep); /* Notify caller of the error. */
- return(EINVAL);
- }
-
- buf[0] = uiop->uio_resid; /* Save this value. */
- uiop->uio_rw = UIO_WRITE;
- error = uiomove((caddr_t) &out->result, vmp->vm_outSize - (sizeof(int) * 2), uiop);
- if (error) {
- myprintf(("vcwrite: error (%d) on uiomove (op %ld seq %ld)\n",
- error, opcode, seq));
- return(EINVAL);
- }
-
- /* I don't think these are used, but just in case. */
- /* XXX - aren't these two already correct? -bnoble */
- out->opcode = opcode;
- out->unique = seq;
- vmp->vm_outSize = buf[0]; /* Amount of data transferred? */
- vmp->vm_flags |= VM_WRITE;
- wakeup(&vmp->vm_sleep);
-
- return(0);
-}
-
-int
-vc_nb_ioctl(dev, cmd, addr, flag, td)
- dev_t dev;
- u_long cmd;
- caddr_t addr;
- int flag;
- struct thread *td;
-{
- ENTRY;
-
- switch(cmd) {
- case CODARESIZE: {
- struct coda_resize *data = (struct coda_resize *)addr;
- return(coda_nc_resize(data->hashsize, data->heapsize, IS_DOWNCALL));
- break;
- }
- case CODASTATS:
- if (coda_nc_use) {
- coda_nc_gather_stats();
- return(0);
- } else {
- return(ENODEV);
- }
- break;
- case CODAPRINT:
- if (coda_nc_use) {
- print_coda_nc();
- return(0);
- } else {
- return(ENODEV);
- }
- break;
- case CIOC_KERNEL_VERSION:
- switch (*(u_int *)addr) {
- case 0:
- *(u_int *)addr = coda_kernel_version;
- return 0;
- break;
- case 1:
- case 2:
- if (coda_kernel_version != *(u_int *)addr)
- return ENOENT;
- else
- return 0;
- default:
- return ENOENT;
- }
- break;
- default :
- return(EINVAL);
- break;
- }
-}
-
-int
-vc_nb_poll(dev, events, td)
- dev_t dev;
- int events;
- struct thread *td;
-{
- register struct vcomm *vcp;
- int event_msk = 0;
-
- ENTRY;
-
- if (minor(dev) >= NVCODA || minor(dev) < 0)
- return(ENXIO);
-
- vcp = &coda_mnttbl[minor(dev)].mi_vcomm;
-
- event_msk = events & (POLLIN|POLLRDNORM);
- if (!event_msk)
- return(0);
-
- if (!EMPTY(vcp->vc_requests))
- return(events & (POLLIN|POLLRDNORM));
-
- selrecord(td, &(vcp->vc_selproc));
-
- return(0);
-}
-
-/*
- * Statistics
- */
-struct coda_clstat coda_clstat;
-
-/*
- * Key question: whether to sleep interuptably or uninteruptably when
- * waiting for Venus. The former seems better (cause you can ^C a
- * job), but then GNU-EMACS completion breaks. Use tsleep with no
- * timeout, and no longjmp happens. But, when sleeping
- * "uninterruptibly", we don't get told if it returns abnormally
- * (e.g. kill -9).
- */
-
-int
-coda_call(mntinfo, inSize, outSize, buffer)
- struct coda_mntinfo *mntinfo; int inSize; int *outSize; caddr_t buffer;
-{
- struct vcomm *vcp;
- struct vmsg *vmp;
- int error;
-#ifdef CTL_C
- struct thread *td = curthread;
- struct proc *p = td->td_proc;
- sigset_t psig_omask;
- sigset_t tempset;
- int i;
-#endif
- if (mntinfo == NULL) {
- /* Unlikely, but could be a race condition with a dying warden */
- return ENODEV;
- }
-
- vcp = &(mntinfo->mi_vcomm);
-
- coda_clstat.ncalls++;
- coda_clstat.reqs[((struct coda_in_hdr *)buffer)->opcode]++;
-
- if (!VC_OPEN(vcp))
- return(ENODEV);
-
- CODA_ALLOC(vmp,struct vmsg *,sizeof(struct vmsg));
- /* Format the request message. */
- vmp->vm_data = buffer;
- vmp->vm_flags = 0;
- vmp->vm_inSize = inSize;
- vmp->vm_outSize
- = *outSize ? *outSize : inSize; /* |buffer| >= inSize */
- vmp->vm_opcode = ((struct coda_in_hdr *)buffer)->opcode;
- vmp->vm_unique = ++vcp->vc_seq;
- if (codadebug)
- myprintf(("Doing a call for %d.%d\n",
- vmp->vm_opcode, vmp->vm_unique));
-
- /* Fill in the common input args. */
- ((struct coda_in_hdr *)buffer)->unique = vmp->vm_unique;
-
- /* Append msg to request queue and poke Venus. */
- INSQUE(vmp->vm_chain, vcp->vc_requests);
- selwakeup(&(vcp->vc_selproc));
-
- /* We can be interrupted while we wait for Venus to process
- * our request. If the interrupt occurs before Venus has read
- * the request, we dequeue and return. If it occurs after the
- * read but before the reply, we dequeue, send a signal
- * message, and return. If it occurs after the reply we ignore
- * it. In no case do we want to restart the syscall. If it
- * was interrupted by a venus shutdown (vcclose), return
- * ENODEV. */
-
- /* Ignore return, We have to check anyway */
-#ifdef CTL_C
- /* This is work in progress. Setting coda_pcatch lets tsleep reawaken
- on a ^c or ^z. The problem is that emacs sets certain interrupts
- as SA_RESTART. This means that we should exit sleep handle the
- "signal" and then go to sleep again. Mostly this is done by letting
- the syscall complete and be restarted. We are not idempotent and
- can not do this. A better solution is necessary.
- */
- i = 0;
- PROC_LOCK(p);
- psig_omask = td->td_sigmask;
- do {
- error = msleep(&vmp->vm_sleep, &p->p_mtx,
- (coda_call_sleep|coda_pcatch), "coda_call",
- hz*2);
- if (error == 0)
- break;
- else if (error == EWOULDBLOCK) {
-#ifdef CODA_VERBOSE
- printf("coda_call: tsleep TIMEOUT %d sec\n", 2+2*i);
-#endif
- }
- else {
- SIGEMPTYSET(tempset);
- SIGADDSET(tempset, SIGIO);
- if (SIGSETEQ(td->td_siglist, tempset)) {
- SIGADDSET(td->td_sigmask, SIGIO);
-#ifdef CODA_VERBOSE
- printf("coda_call: tsleep returns %d SIGIO, cnt %d\n",
- error, i);
-#endif
- } else {
- SIGDELSET(tempset, SIGIO);
- SIGADDSET(tempset, SIGALRM);
- if (SIGSETEQ(td->td_siglist, tempset)) {
- SIGADDSET(td->td_sigmask, SIGALRM);
-#ifdef CODA_VERBOSE
- printf("coda_call: tsleep returns %d SIGALRM, cnt %d\n",
- error, i);
-#endif
- }
- else {
- printf("coda_call: tsleep returns %d, cnt %d\n",
- error, i);
-
-#if notyet
- tempset = td->td_siglist;
- SIGSETNAND(tempset, td->td_sigmask);
- printf("coda_call: siglist = %p, sigmask = %p, mask %p\n",
- td->td_siglist, td->td_sigmask,
- tempset);
- break;
- SIGSETOR(td->td_sigmask, td->td_siglist);
- tempset = td->td_siglist;
- SIGSETNAND(tempset, td->td_sigmask);
- printf("coda_call: new mask, siglist = %p, sigmask = %p, mask %p\n",
- td->td_siglist, td->td_sigmask,
- tempset);
-#endif
- }
- }
- }
- } while (error && i++ < 128 && VC_OPEN(vcp));
- td->td_sigmask = psig_omask;
- signotify(td);
- PROC_UNLOCK(p);
-#else
- (void) tsleep(&vmp->vm_sleep, coda_call_sleep, "coda_call", 0);
-#endif
- if (VC_OPEN(vcp)) { /* Venus is still alive */
- /* Op went through, interrupt or not... */
- if (vmp->vm_flags & VM_WRITE) {
- error = 0;
- *outSize = vmp->vm_outSize;
- }
-
- else if (!(vmp->vm_flags & VM_READ)) {
- /* Interrupted before venus read it. */
-#ifdef CODA_VERBOSE
- if (1)
-#else
- if (codadebug)
-#endif
- myprintf(("interrupted before read: op = %d.%d, flags = %x\n",
- vmp->vm_opcode, vmp->vm_unique, vmp->vm_flags));
- REMQUE(vmp->vm_chain);
- error = EINTR;
- }
-
- else {
- /* (!(vmp->vm_flags & VM_WRITE)) means interrupted after
- upcall started */
- /* Interrupted after start of upcall, send venus a signal */
- struct coda_in_hdr *dog;
- struct vmsg *svmp;
-
-#ifdef CODA_VERBOSE
- if (1)
-#else
- if (codadebug)
-#endif
- myprintf(("Sending Venus a signal: op = %d.%d, flags = %x\n",
- vmp->vm_opcode, vmp->vm_unique, vmp->vm_flags));
-
- REMQUE(vmp->vm_chain);
- error = EINTR;
-
- CODA_ALLOC(svmp, struct vmsg *, sizeof (struct vmsg));
-
- CODA_ALLOC((svmp->vm_data), char *, sizeof (struct coda_in_hdr));
- dog = (struct coda_in_hdr *)svmp->vm_data;
-
- svmp->vm_flags = 0;
- dog->opcode = svmp->vm_opcode = CODA_SIGNAL;
- dog->unique = svmp->vm_unique = vmp->vm_unique;
- svmp->vm_inSize = sizeof (struct coda_in_hdr);
-/*??? rvb */ svmp->vm_outSize = sizeof (struct coda_in_hdr);
-
- if (codadebug)
- myprintf(("coda_call: enqueing signal msg (%d, %d)\n",
- svmp->vm_opcode, svmp->vm_unique));
-
- /* insert at head of queue! */
- INSQUE(svmp->vm_chain, vcp->vc_requests);
- selwakeup(&(vcp->vc_selproc));
- }
- }
-
- else { /* If venus died (!VC_OPEN(vcp)) */
- if (codadebug)
- myprintf(("vcclose woke op %d.%d flags %d\n",
- vmp->vm_opcode, vmp->vm_unique, vmp->vm_flags));
-
- error = ENODEV;
- }
-
- CODA_FREE(vmp, sizeof(struct vmsg));
-
- if (outstanding_upcalls > 0 && (--outstanding_upcalls == 0))
- wakeup(&outstanding_upcalls);
-
- if (!error)
- error = ((struct coda_out_hdr *)buffer)->result;
- return(error);
-}
diff --git a/sys/fs/coda/coda_psdev.h b/sys/fs/coda/coda_psdev.h
deleted file mode 100644
index c6ecf7f435e2..000000000000
--- a/sys/fs/coda/coda_psdev.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_psdev.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-int vc_nb_open(dev_t dev, int flag, int mode, struct thread *p);
-int vc_nb_close (dev_t dev, int flag, int mode, struct thread *p);
-int vc_nb_read(dev_t dev, struct uio *uiop, int flag);
-int vc_nb_write(dev_t dev, struct uio *uiop, int flag);
-int vc_nb_ioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *p);
-int vc_nb_poll(dev_t dev, int events, struct thread *p);
diff --git a/sys/fs/coda/coda_subr.c b/sys/fs/coda/coda_subr.c
deleted file mode 100644
index 53c43464e3f2..000000000000
--- a/sys/fs/coda/coda_subr.c
+++ /dev/null
@@ -1,571 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_subr.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/*
- * Mach Operating System
- * Copyright (c) 1989 Carnegie-Mellon University
- * All rights reserved. The CMU software License Agreement specifies
- * the terms and conditions for use and redistribution.
- */
-
-/*
- * This code was written for the Coda filesystem at Carnegie Mellon
- * University. Contributers include David Steere, James Kistler, and
- * M. Satyanarayanan.
- */
-
-/* NOTES: rvb
- * 1. Added coda_unmounting to mark all cnodes as being UNMOUNTING. This has to
- * be done before dounmount is called. Because some of the routines that
- * dounmount calls before coda_unmounted might try to force flushes to venus.
- * The vnode pager does this.
- * 2. coda_unmounting marks all cnodes scanning coda_cache.
- * 3. cfs_checkunmounting (under DEBUG) checks all cnodes by chasing the vnodes
- * under the /coda mount point.
- * 4. coda_cacheprint (under DEBUG) prints names with vnode/cnode address
- */
-
-#include <vcoda.h>
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mount.h>
-
-#include <coda/coda.h>
-#include <coda/cnode.h>
-#include <coda/coda_subr.h>
-#include <coda/coda_namecache.h>
-
-int coda_active = 0;
-int coda_reuse = 0;
-int coda_new = 0;
-
-struct cnode *coda_freelist = NULL;
-struct cnode *coda_cache[CODA_CACHESIZE];
-
-#define coda_hash(fid) (((fid)->Volume + (fid)->Vnode) & (CODA_CACHESIZE-1))
-#define CNODE_NEXT(cp) ((cp)->c_next)
-#define ODD(vnode) ((vnode) & 0x1)
-
-/*
- * Allocate a cnode.
- */
-struct cnode *
-coda_alloc(void)
-{
- struct cnode *cp;
-
- if (coda_freelist) {
- cp = coda_freelist;
- coda_freelist = CNODE_NEXT(cp);
- coda_reuse++;
- }
- else {
- CODA_ALLOC(cp, struct cnode *, sizeof(struct cnode));
- /* NetBSD vnodes don't have any Pager info in them ('cause there are
- no external pagers, duh!) */
-#define VNODE_VM_INFO_INIT(vp) /* MT */
- VNODE_VM_INFO_INIT(CTOV(cp));
- coda_new++;
- }
- bzero(cp, sizeof (struct cnode));
-
- return(cp);
-}
-
-/*
- * Deallocate a cnode.
- */
-void
-coda_free(cp)
- register struct cnode *cp;
-{
-
- CNODE_NEXT(cp) = coda_freelist;
- coda_freelist = cp;
-}
-
-/*
- * Put a cnode in the hash table
- */
-void
-coda_save(cp)
- struct cnode *cp;
-{
- CNODE_NEXT(cp) = coda_cache[coda_hash(&cp->c_fid)];
- coda_cache[coda_hash(&cp->c_fid)] = cp;
-}
-
-/*
- * Remove a cnode from the hash table
- */
-void
-coda_unsave(cp)
- struct cnode *cp;
-{
- struct cnode *ptr;
- struct cnode *ptrprev = NULL;
-
- ptr = coda_cache[coda_hash(&cp->c_fid)];
- while (ptr != NULL) {
- if (ptr == cp) {
- if (ptrprev == NULL) {
- coda_cache[coda_hash(&cp->c_fid)]
- = CNODE_NEXT(ptr);
- } else {
- CNODE_NEXT(ptrprev) = CNODE_NEXT(ptr);
- }
- CNODE_NEXT(cp) = (struct cnode *)NULL;
-
- return;
- }
- ptrprev = ptr;
- ptr = CNODE_NEXT(ptr);
- }
-}
-
-/*
- * Lookup a cnode by fid. If the cnode is dying, it is bogus so skip it.
- * NOTE: this allows multiple cnodes with same fid -- dcs 1/25/95
- */
-struct cnode *
-coda_find(fid)
- ViceFid *fid;
-{
- struct cnode *cp;
-
- cp = coda_cache[coda_hash(fid)];
- while (cp) {
- if ((cp->c_fid.Vnode == fid->Vnode) &&
- (cp->c_fid.Volume == fid->Volume) &&
- (cp->c_fid.Unique == fid->Unique) &&
- (!IS_UNMOUNTING(cp)))
- {
- coda_active++;
- return(cp);
- }
- cp = CNODE_NEXT(cp);
- }
- return(NULL);
-}
-
-/*
- * coda_kill is called as a side effect to vcopen. To prevent any
- * cnodes left around from an earlier run of a venus or warden from
- * causing problems with the new instance, mark any outstanding cnodes
- * as dying. Future operations on these cnodes should fail (excepting
- * coda_inactive of course!). Since multiple venii/wardens can be
- * running, only kill the cnodes for a particular entry in the
- * coda_mnttbl. -- DCS 12/1/94 */
-
-int
-coda_kill(whoIam, dcstat)
- struct mount *whoIam;
- enum dc_status dcstat;
-{
- int hash, count = 0;
- struct cnode *cp;
-
- /*
- * Algorithm is as follows:
- * Second, flush whatever vnodes we can from the name cache.
- *
- * Finally, step through whatever is left and mark them dying.
- * This prevents any operation at all.
- */
-
- /* This is slightly overkill, but should work. Eventually it'd be
- * nice to only flush those entries from the namecache that
- * reference a vnode in this vfs. */
- coda_nc_flush(dcstat);
-
- for (hash = 0; hash < CODA_CACHESIZE; hash++) {
- for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) {
- if (CTOV(cp)->v_mount == whoIam) {
-#ifdef DEBUG
- printf("coda_kill: vp %p, cp %p\n", CTOV(cp), cp);
-#endif
- count++;
- CODADEBUG(CODA_FLUSH,
- myprintf(("Live cnode fid %lx.%lx.%lx flags %d count %d\n",
- (cp->c_fid).Volume,
- (cp->c_fid).Vnode,
- (cp->c_fid).Unique,
- cp->c_flags,
- vrefcnt(CTOV(cp)))); );
- }
- }
- }
- return count;
-}
-
-/*
- * There are two reasons why a cnode may be in use, it may be in the
- * name cache or it may be executing.
- */
-void
-coda_flush(dcstat)
- enum dc_status dcstat;
-{
- int hash;
- struct cnode *cp;
-
- coda_clstat.ncalls++;
- coda_clstat.reqs[CODA_FLUSH]++;
-
- coda_nc_flush(dcstat); /* flush files from the name cache */
-
- for (hash = 0; hash < CODA_CACHESIZE; hash++) {
- for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) {
- if (!ODD(cp->c_fid.Vnode)) /* only files can be executed */
- coda_vmflush(cp);
- }
- }
-}
-
-/*
- * As a debugging measure, print out any cnodes that lived through a
- * name cache flush.
- */
-void
-coda_testflush(void)
-{
- int hash;
- struct cnode *cp;
-
- for (hash = 0; hash < CODA_CACHESIZE; hash++) {
- for (cp = coda_cache[hash];
- cp != NULL;
- cp = CNODE_NEXT(cp)) {
- myprintf(("Live cnode fid %lx.%lx.%lx count %d\n",
- (cp->c_fid).Volume,(cp->c_fid).Vnode,
- (cp->c_fid).Unique, vrefcnt(CTOV(cp))));
- }
- }
-}
-
-/*
- * First, step through all cnodes and mark them unmounting.
- * NetBSD kernels may try to fsync them now that venus
- * is dead, which would be a bad thing.
- *
- */
-void
-coda_unmounting(whoIam)
- struct mount *whoIam;
-{
- int hash;
- struct cnode *cp;
-
- for (hash = 0; hash < CODA_CACHESIZE; hash++) {
- for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) {
- if (CTOV(cp)->v_mount == whoIam) {
- if (cp->c_flags & (C_LOCKED|C_WANTED)) {
- printf("coda_unmounting: Unlocking %p\n", cp);
- cp->c_flags &= ~(C_LOCKED|C_WANTED);
- wakeup((caddr_t) cp);
- }
- cp->c_flags |= C_UNMOUNTING;
- }
- }
- }
-}
-
-#ifdef DEBUG
-void
-coda_checkunmounting(mp)
- struct mount *mp;
-{
- register struct vnode *vp, *nvp;
- struct cnode *cp;
- int count = 0, bad = 0;
-loop:
- for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist); vp; vp = nvp) {
- if (vp->v_mount != mp)
- goto loop;
- nvp = TAILQ_NEXT(vp, v_nmntvnodes);
- cp = VTOC(vp);
- count++;
- if (!(cp->c_flags & C_UNMOUNTING)) {
- bad++;
- printf("vp %p, cp %p missed\n", vp, cp);
- cp->c_flags |= C_UNMOUNTING;
- }
- }
-}
-
-void
-coda_cacheprint(whoIam)
- struct mount *whoIam;
-{
- int hash;
- struct cnode *cp;
- int count = 0;
-
- printf("coda_cacheprint: coda_ctlvp %p, cp %p", coda_ctlvp, VTOC(coda_ctlvp));
- coda_nc_name(VTOC(coda_ctlvp));
- printf("\n");
-
- for (hash = 0; hash < CODA_CACHESIZE; hash++) {
- for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) {
- if (CTOV(cp)->v_mount == whoIam) {
- printf("coda_cacheprint: vp %p, cp %p", CTOV(cp), cp);
- coda_nc_name(cp);
- printf("\n");
- count++;
- }
- }
- }
- printf("coda_cacheprint: count %d\n", count);
-}
-#endif
-
-/*
- * There are 6 cases where invalidations occur. The semantics of each
- * is listed here.
- *
- * CODA_FLUSH -- flush all entries from the name cache and the cnode cache.
- * CODA_PURGEUSER -- flush all entries from the name cache for a specific user
- * This call is a result of token expiration.
- *
- * The next two are the result of callbacks on a file or directory.
- * CODA_ZAPDIR -- flush the attributes for the dir from its cnode.
- * Zap all children of this directory from the namecache.
- * CODA_ZAPFILE -- flush the attributes for a file.
- *
- * The fifth is a result of Venus detecting an inconsistent file.
- * CODA_PURGEFID -- flush the attribute for the file
- * If it is a dir (odd vnode), purge its
- * children from the namecache
- * remove the file from the namecache.
- *
- * The sixth allows Venus to replace local fids with global ones
- * during reintegration.
- *
- * CODA_REPLACE -- replace one ViceFid with another throughout the name cache
- */
-
-int handleDownCall(opcode, out)
- int opcode; union outputArgs *out;
-{
- int error;
-
- /* Handle invalidate requests. */
- switch (opcode) {
- case CODA_FLUSH : {
-
- coda_flush(IS_DOWNCALL);
-
- CODADEBUG(CODA_FLUSH,coda_testflush();) /* print remaining cnodes */
- return(0);
- }
-
- case CODA_PURGEUSER : {
- coda_clstat.ncalls++;
- coda_clstat.reqs[CODA_PURGEUSER]++;
-
- /* XXX - need to prevent fsync's */
- coda_nc_purge_user(out->coda_purgeuser.cred.cr_uid, IS_DOWNCALL);
- return(0);
- }
-
- case CODA_ZAPFILE : {
- struct cnode *cp;
-
- error = 0;
- coda_clstat.ncalls++;
- coda_clstat.reqs[CODA_ZAPFILE]++;
-
- cp = coda_find(&out->coda_zapfile.CodaFid);
- if (cp != NULL) {
- vref(CTOV(cp));
-
- cp->c_flags &= ~C_VATTR;
- ASSERT_VOP_LOCKED(CTOV(cp), "coda HandleDownCall");
- if (CTOV(cp)->v_vflag & VV_TEXT)
- error = coda_vmflush(cp);
- CODADEBUG(CODA_ZAPFILE, myprintf((
-"zapfile: fid = (%lx.%lx.%lx), refcnt = %d, error = %d\n",
- cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique,
- vrefcnt(CTOV(cp)) - 1, error)););
- if (vrefcnt(CTOV(cp)) == 1) {
- cp->c_flags |= C_PURGING;
- }
- vrele(CTOV(cp));
- }
-
- return(error);
- }
-
- case CODA_ZAPDIR : {
- struct cnode *cp;
-
- coda_clstat.ncalls++;
- coda_clstat.reqs[CODA_ZAPDIR]++;
-
- cp = coda_find(&out->coda_zapdir.CodaFid);
- if (cp != NULL) {
- vref(CTOV(cp));
-
- cp->c_flags &= ~C_VATTR;
- coda_nc_zapParentfid(&out->coda_zapdir.CodaFid, IS_DOWNCALL);
-
- CODADEBUG(CODA_ZAPDIR, myprintf((
-"zapdir: fid = (%lx.%lx.%lx), refcnt = %d\n",
- cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique,
- vrefcnt(CTOV(cp)) - 1)););
- if (vrefcnt(CTOV(cp)) == 1) {
- cp->c_flags |= C_PURGING;
- }
- vrele(CTOV(cp));
- }
-
- return(0);
- }
-
- case CODA_PURGEFID : {
- struct cnode *cp;
-
- error = 0;
- coda_clstat.ncalls++;
- coda_clstat.reqs[CODA_PURGEFID]++;
-
- cp = coda_find(&out->coda_purgefid.CodaFid);
- if (cp != NULL) {
- vref(CTOV(cp));
- if (ODD(out->coda_purgefid.CodaFid.Vnode)) { /* Vnode is a directory */
- coda_nc_zapParentfid(&out->coda_purgefid.CodaFid,
- IS_DOWNCALL);
- }
- cp->c_flags &= ~C_VATTR;
- coda_nc_zapfid(&out->coda_purgefid.CodaFid, IS_DOWNCALL);
- ASSERT_VOP_LOCKED(CTOV(cp), "coda HandleDownCall");
- if (!(ODD(out->coda_purgefid.CodaFid.Vnode))
- && (CTOV(cp)->v_vflag & VV_TEXT)) {
-
- error = coda_vmflush(cp);
- }
- CODADEBUG(CODA_PURGEFID, myprintf(("purgefid: fid = (%lx.%lx.%lx), refcnt = %d, error = %d\n",
- cp->c_fid.Volume, cp->c_fid.Vnode,
- cp->c_fid.Unique,
- vrefcnt(CTOV(cp)) - 1, error)););
- if (vrefcnt(CTOV(cp)) == 1) {
- cp->c_flags |= C_PURGING;
- }
- vrele(CTOV(cp));
- }
- return(error);
- }
-
- case CODA_REPLACE : {
- struct cnode *cp = NULL;
-
- coda_clstat.ncalls++;
- coda_clstat.reqs[CODA_REPLACE]++;
-
- cp = coda_find(&out->coda_replace.OldFid);
- if (cp != NULL) {
- /* remove the cnode from the hash table, replace the fid, and reinsert */
- vref(CTOV(cp));
- coda_unsave(cp);
- cp->c_fid = out->coda_replace.NewFid;
- coda_save(cp);
-
- CODADEBUG(CODA_REPLACE, myprintf(("replace: oldfid = (%lx.%lx.%lx), newfid = (%lx.%lx.%lx), cp = %p\n",
- out->coda_replace.OldFid.Volume,
- out->coda_replace.OldFid.Vnode,
- out->coda_replace.OldFid.Unique,
- cp->c_fid.Volume, cp->c_fid.Vnode,
- cp->c_fid.Unique, cp));)
- vrele(CTOV(cp));
- }
- return (0);
- }
- default:
- myprintf(("handleDownCall: unknown opcode %d\n", opcode));
- return (EINVAL);
- }
-}
-
-/* coda_grab_vnode: lives in either cfs_mach.c or cfs_nbsd.c */
-
-int
-coda_vmflush(cp)
- struct cnode *cp;
-{
- return 0;
-}
-
-
-/*
- * kernel-internal debugging switches
- */
-void coda_debugon(void)
-{
- codadebug = -1;
- coda_nc_debug = -1;
- coda_vnop_print_entry = 1;
- coda_psdev_print_entry = 1;
- coda_vfsop_print_entry = 1;
-}
-
-void coda_debugoff(void)
-{
- codadebug = 0;
- coda_nc_debug = 0;
- coda_vnop_print_entry = 0;
- coda_psdev_print_entry = 0;
- coda_vfsop_print_entry = 0;
-}
-
-/*
- * Utilities used by both client and server
- * Standard levels:
- * 0) no debugging
- * 1) hard failures
- * 2) soft failures
- * 3) current test software
- * 4) main procedure entry points
- * 5) main procedure exit points
- * 6) utility procedure entry points
- * 7) utility procedure exit points
- * 8) obscure procedure entry points
- * 9) obscure procedure exit points
- * 10) random stuff
- * 11) all <= 1
- * 12) all <= 2
- * 13) all <= 3
- * ...
- */
diff --git a/sys/fs/coda/coda_subr.h b/sys/fs/coda/coda_subr.h
deleted file mode 100644
index 71c8a3de3812..000000000000
--- a/sys/fs/coda/coda_subr.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_subr.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-struct cnode *coda_alloc(void);
-void coda_free(struct cnode *cp);
-struct cnode *coda_find(ViceFid *fid);
-void coda_flush(enum dc_status dcstat);
-void coda_testflush(void);
-void coda_checkunmounting(struct mount *mp);
-void coda_cacheprint(struct mount *whoIam);
-void coda_debugon(void);
-void coda_debugoff(void);
-int coda_kill(struct mount *whoIam, enum dc_status dcstat);
-void coda_save(struct cnode *cp);
-void coda_unsave(struct cnode *cp);
diff --git a/sys/fs/coda/coda_venus.c b/sys/fs/coda/coda_venus.c
deleted file mode 100644
index 66a0b19d0c09..000000000000
--- a/sys/fs/coda/coda_venus.c
+++ /dev/null
@@ -1,665 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/cfs/coda_venus.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/fcntl.h>
-#include <sys/ioccom.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/sx.h>
-
-#include <coda/coda.h>
-#include <coda/cnode.h>
-#include <coda/coda_venus.h>
-#include <coda/coda_pioctl.h>
-
-#define DECL_NO_IN(name) \
- struct coda_in_hdr *inp; \
- struct name ## _out *outp; \
- int name ## _size = sizeof (struct coda_in_hdr); \
- int Isize = sizeof (struct coda_in_hdr); \
- int Osize = sizeof (struct name ## _out); \
- int error
-
-#define DECL(name) \
- struct name ## _in *inp; \
- struct name ## _out *outp; \
- int name ## _size = sizeof (struct name ## _in); \
- int Isize = sizeof (struct name ## _in); \
- int Osize = sizeof (struct name ## _out); \
- int error
-
-#define DECL_NO_OUT(name) \
- struct name ## _in *inp; \
- struct coda_out_hdr *outp; \
- int name ## _size = sizeof (struct name ## _in); \
- int Isize = sizeof (struct name ## _in); \
- int Osize = sizeof (struct coda_out_hdr); \
- int error
-
-#define ALLOC_NO_IN(name) \
- if (Osize > name ## _size) \
- name ## _size = Osize; \
- CODA_ALLOC(inp, struct coda_in_hdr *, name ## _size);\
- outp = (struct name ## _out *) inp
-
-#define ALLOC(name) \
- if (Osize > name ## _size) \
- name ## _size = Osize; \
- CODA_ALLOC(inp, struct name ## _in *, name ## _size);\
- outp = (struct name ## _out *) inp
-
-#define ALLOC_NO_OUT(name) \
- if (Osize > name ## _size) \
- name ## _size = Osize; \
- CODA_ALLOC(inp, struct name ## _in *, name ## _size);\
- outp = (struct coda_out_hdr *) inp
-
-#define STRCPY(struc, name, len) \
- bcopy(name, (char *)inp + (int)inp->struc, len); \
- ((char*)inp + (int)inp->struc)[len++] = 0; \
- Isize += len
-
-#define INIT_IN(in, op, ident, p) \
- (in)->opcode = (op); \
- sx_slock(&proctree_lock); \
- (in)->pid = p ? p->p_pid : -1; \
- (in)->pgid = p ? p->p_pgid : -1; \
- (in)->sid = (p && p->p_session && p->p_session->s_leader) ? (p->p_session->s_leader->p_pid) : -1; \
- sx_sunlock(&proctree_lock); \
- if (ident != NOCRED) { \
- (in)->cred.cr_uid = ident->cr_uid; \
- (in)->cred.cr_groupid = ident->cr_gid; \
- } else { \
- bzero(&((in)->cred),sizeof(struct coda_cred)); \
- (in)->cred.cr_uid = -1; \
- (in)->cred.cr_groupid = -1; \
- } \
-
-#define CNV_OFLAG(to, from) \
- do { \
- to = 0; \
- if (from & FREAD) to |= C_O_READ; \
- if (from & FWRITE) to |= C_O_WRITE; \
- if (from & O_TRUNC) to |= C_O_TRUNC; \
- if (from & O_EXCL) to |= C_O_EXCL; \
- if (from & O_CREAT) to |= C_O_CREAT; \
- } while (0)
-
-#define CNV_VV2V_ATTR(top, fromp) \
- do { \
- (top)->va_type = (fromp)->va_type; \
- (top)->va_mode = (fromp)->va_mode; \
- (top)->va_nlink = (fromp)->va_nlink; \
- (top)->va_uid = (fromp)->va_uid; \
- (top)->va_gid = (fromp)->va_gid; \
- (top)->va_fsid = VNOVAL; \
- (top)->va_fileid = (fromp)->va_fileid; \
- (top)->va_size = (fromp)->va_size; \
- (top)->va_blocksize = (fromp)->va_blocksize; \
- (top)->va_atime = (fromp)->va_atime; \
- (top)->va_mtime = (fromp)->va_mtime; \
- (top)->va_ctime = (fromp)->va_ctime; \
- (top)->va_gen = (fromp)->va_gen; \
- (top)->va_flags = (fromp)->va_flags; \
- (top)->va_rdev = (fromp)->va_rdev; \
- (top)->va_bytes = (fromp)->va_bytes; \
- (top)->va_filerev = (fromp)->va_filerev; \
- (top)->va_vaflags = VNOVAL; \
- (top)->va_spare = VNOVAL; \
- } while (0)
-
-#define CNV_V2VV_ATTR(top, fromp) \
- do { \
- (top)->va_type = (fromp)->va_type; \
- (top)->va_mode = (fromp)->va_mode; \
- (top)->va_nlink = (fromp)->va_nlink; \
- (top)->va_uid = (fromp)->va_uid; \
- (top)->va_gid = (fromp)->va_gid; \
- (top)->va_fileid = (fromp)->va_fileid; \
- (top)->va_size = (fromp)->va_size; \
- (top)->va_blocksize = (fromp)->va_blocksize; \
- (top)->va_atime = (fromp)->va_atime; \
- (top)->va_mtime = (fromp)->va_mtime; \
- (top)->va_ctime = (fromp)->va_ctime; \
- (top)->va_gen = (fromp)->va_gen; \
- (top)->va_flags = (fromp)->va_flags; \
- (top)->va_rdev = (fromp)->va_rdev; \
- (top)->va_bytes = (fromp)->va_bytes; \
- (top)->va_filerev = (fromp)->va_filerev; \
- } while (0)
-
-
-int coda_kernel_version = CODA_KERNEL_VERSION;
-
-int
-venus_root(void *mdp,
- struct ucred *cred, struct proc *p,
-/*out*/ ViceFid *VFid)
-{
- DECL_NO_IN(coda_root); /* sets Isize & Osize */
- ALLOC_NO_IN(coda_root); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(inp, CODA_ROOT, cred, p);
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
- if (!error)
- *VFid = outp->VFid;
-
- CODA_FREE(inp, coda_root_size);
- return error;
-}
-
-int
-venus_open(void *mdp, ViceFid *fid, int flag,
- struct ucred *cred, struct proc *p,
-/*out*/ dev_t *dev, ino_t *inode)
-{
- int cflag;
- DECL(coda_open); /* sets Isize & Osize */
- ALLOC(coda_open); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_OPEN, cred, p);
- inp->VFid = *fid;
- CNV_OFLAG(cflag, flag);
- inp->flags = cflag;
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
- if (!error) {
-/* 5/11 *dev = udev2dev(outp->dev, 2); */
- *dev = udev2dev(outp->dev, 0);
- *inode = outp->inode;
- }
-
- CODA_FREE(inp, coda_open_size);
- return error;
-}
-
-int
-venus_close(void *mdp, ViceFid *fid, int flag,
- struct ucred *cred, struct proc *p)
-{
- int cflag;
- DECL_NO_OUT(coda_close); /* sets Isize & Osize */
- ALLOC_NO_OUT(coda_close); /* sets inp & outp */
-
- INIT_IN(&inp->ih, CODA_CLOSE, cred, p);
- inp->VFid = *fid;
- CNV_OFLAG(cflag, flag);
- inp->flags = cflag;
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
-
- CODA_FREE(inp, coda_close_size);
- return error;
-}
-
-/*
- * these two calls will not exist!!! the container file is read/written
- * directly.
- */
-void
-venus_read(void)
-{
-}
-
-void
-venus_write(void)
-{
-}
-
-/*
- * this is a bit sad too. the ioctl's are for the control file, not for
- * normal files.
- */
-int
-venus_ioctl(void *mdp, ViceFid *fid,
- int com, int flag, caddr_t data,
- struct ucred *cred, struct proc *p)
-{
- DECL(coda_ioctl); /* sets Isize & Osize */
- struct PioctlData *iap = (struct PioctlData *)data;
- int tmp;
-
- coda_ioctl_size = VC_MAXMSGSIZE;
- ALLOC(coda_ioctl); /* sets inp & outp */
-
- INIT_IN(&inp->ih, CODA_IOCTL, cred, p);
- inp->VFid = *fid;
-
- /* command was mutated by increasing its size field to reflect the
- * path and follow args. we need to subtract that out before sending
- * the command to venus.
- */
- inp->cmd = (com & ~(IOCPARM_MASK << 16));
- tmp = ((com >> 16) & IOCPARM_MASK) - sizeof (char *) - sizeof (int);
- inp->cmd |= (tmp & IOCPARM_MASK) << 16;
-
- inp->rwflag = flag;
- inp->len = iap->vi.in_size;
- inp->data = (char *)(sizeof (struct coda_ioctl_in));
-
- error = copyin(iap->vi.in, (char*)inp + (long)inp->data,
- iap->vi.in_size);
- if (error) {
- CODA_FREE(inp, coda_ioctl_size);
- return(error);
- }
-
- Osize = VC_MAXMSGSIZE;
- error = coda_call(mdp, Isize + iap->vi.in_size, &Osize, (char *)inp);
-
- /* copy out the out buffer. */
- if (!error) {
- if (outp->len > iap->vi.out_size) {
- error = EINVAL;
- } else {
- error = copyout((char *)outp + (long)outp->data,
- iap->vi.out, iap->vi.out_size);
- }
- }
-
- CODA_FREE(inp, coda_ioctl_size);
- return error;
-}
-
-int
-venus_getattr(void *mdp, ViceFid *fid,
- struct ucred *cred, struct proc *p,
-/*out*/ struct vattr *vap)
-{
- DECL(coda_getattr); /* sets Isize & Osize */
- ALLOC(coda_getattr); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_GETATTR, cred, p);
- inp->VFid = *fid;
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
- if (!error) {
- CNV_VV2V_ATTR(vap, &outp->attr);
- }
-
- CODA_FREE(inp, coda_getattr_size);
- return error;
-}
-
-int
-venus_setattr(void *mdp, ViceFid *fid, struct vattr *vap,
- struct ucred *cred, struct proc *p)
-{
- DECL_NO_OUT(coda_setattr); /* sets Isize & Osize */
- ALLOC_NO_OUT(coda_setattr); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_SETATTR, cred, p);
- inp->VFid = *fid;
- CNV_V2VV_ATTR(&inp->attr, vap);
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
-
- CODA_FREE(inp, coda_setattr_size);
- return error;
-}
-
-int
-venus_access(void *mdp, ViceFid *fid, int mode,
- struct ucred *cred, struct proc *p)
-{
- DECL_NO_OUT(coda_access); /* sets Isize & Osize */
- ALLOC_NO_OUT(coda_access); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_ACCESS, cred, p);
- inp->VFid = *fid;
- /* NOTE:
- * NetBSD and Venus internals use the "data" in the low 3 bits.
- * Hence, the conversion.
- */
- inp->flags = mode>>6;
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
-
- CODA_FREE(inp, coda_access_size);
- return error;
-}
-
-int
-venus_readlink(void *mdp, ViceFid *fid,
- struct ucred *cred, struct proc *p,
-/*out*/ char **str, int *len)
-{
- DECL(coda_readlink); /* sets Isize & Osize */
- coda_readlink_size += CODA_MAXPATHLEN;
- ALLOC(coda_readlink); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_READLINK, cred, p);
- inp->VFid = *fid;
-
- Osize += CODA_MAXPATHLEN;
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
- if (!error) {
- CODA_ALLOC(*str, char *, outp->count);
- *len = outp->count;
- bcopy((char *)outp + (long)outp->data, *str, *len);
- }
-
- CODA_FREE(inp, coda_readlink_size);
- return error;
-}
-
-int
-venus_fsync(void *mdp, ViceFid *fid,
- struct ucred *cred, struct proc *p)
-{
- DECL_NO_OUT(coda_fsync); /* sets Isize & Osize */
- ALLOC_NO_OUT(coda_fsync); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_FSYNC, cred, p);
- inp->VFid = *fid;
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
-
- CODA_FREE(inp, coda_fsync_size);
- return error;
-}
-
-int
-venus_lookup(void *mdp, ViceFid *fid,
- const char *nm, int len,
- struct ucred *cred, struct proc *p,
-/*out*/ ViceFid *VFid, int *vtype)
-{
- DECL(coda_lookup); /* sets Isize & Osize */
- coda_lookup_size += len + 1;
- ALLOC(coda_lookup); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_LOOKUP, cred, p);
- inp->VFid = *fid;
-
- /* NOTE:
- * Between version 1 and version 2 we have added an extra flag field
- * to this structure. But because the string was at the end and because
- * of the wierd way we represent strings by having the slot point to
- * where the string characters are in the "heap", we can just slip the
- * flag parameter in after the string slot pointer and veni that don't
- * know better won't see this new flag field ...
- * Otherwise we'd need two different venus_lookup functions.
- */
- inp->name = Isize;
- inp->flags = CLU_CASE_SENSITIVE; /* doesn't really matter for BSD */
- STRCPY(name, nm, len); /* increments Isize */
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
- if (!error) {
- *VFid = outp->VFid;
- *vtype = outp->vtype;
- }
-
- CODA_FREE(inp, coda_lookup_size);
- return error;
-}
-
-int
-venus_create(void *mdp, ViceFid *fid,
- const char *nm, int len, int exclusive, int mode, struct vattr *va,
- struct ucred *cred, struct proc *p,
-/*out*/ ViceFid *VFid, struct vattr *attr)
-{
- DECL(coda_create); /* sets Isize & Osize */
- coda_create_size += len + 1;
- ALLOC(coda_create); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_CREATE, cred, p);
- inp->VFid = *fid;
- inp->excl = exclusive ? C_O_EXCL : 0;
- inp->mode = mode;
- CNV_V2VV_ATTR(&inp->attr, va);
-
- inp->name = Isize;
- STRCPY(name, nm, len); /* increments Isize */
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
- if (!error) {
- *VFid = outp->VFid;
- CNV_VV2V_ATTR(attr, &outp->attr);
- }
-
- CODA_FREE(inp, coda_create_size);
- return error;
-}
-
-int
-venus_remove(void *mdp, ViceFid *fid,
- const char *nm, int len,
- struct ucred *cred, struct proc *p)
-{
- DECL_NO_OUT(coda_remove); /* sets Isize & Osize */
- coda_remove_size += len + 1;
- ALLOC_NO_OUT(coda_remove); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_REMOVE, cred, p);
- inp->VFid = *fid;
-
- inp->name = Isize;
- STRCPY(name, nm, len); /* increments Isize */
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
-
- CODA_FREE(inp, coda_remove_size);
- return error;
-}
-
-int
-venus_link(void *mdp, ViceFid *fid, ViceFid *tfid,
- const char *nm, int len,
- struct ucred *cred, struct proc *p)
-{
- DECL_NO_OUT(coda_link); /* sets Isize & Osize */
- coda_link_size += len + 1;
- ALLOC_NO_OUT(coda_link); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_LINK, cred, p);
- inp->sourceFid = *fid;
- inp->destFid = *tfid;
-
- inp->tname = Isize;
- STRCPY(tname, nm, len); /* increments Isize */
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
-
- CODA_FREE(inp, coda_link_size);
- return error;
-}
-
-int
-venus_rename(void *mdp, ViceFid *fid, ViceFid *tfid,
- const char *nm, int len, const char *tnm, int tlen,
- struct ucred *cred, struct proc *p)
-{
- DECL_NO_OUT(coda_rename); /* sets Isize & Osize */
- coda_rename_size += len + 1 + tlen + 1;
- ALLOC_NO_OUT(coda_rename); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_RENAME, cred, p);
- inp->sourceFid = *fid;
- inp->destFid = *tfid;
-
- inp->srcname = Isize;
- STRCPY(srcname, nm, len); /* increments Isize */
-
- inp->destname = Isize;
- STRCPY(destname, tnm, tlen); /* increments Isize */
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
-
- CODA_FREE(inp, coda_rename_size);
- return error;
-}
-
-int
-venus_mkdir(void *mdp, ViceFid *fid,
- const char *nm, int len, struct vattr *va,
- struct ucred *cred, struct proc *p,
-/*out*/ ViceFid *VFid, struct vattr *ova)
-{
- DECL(coda_mkdir); /* sets Isize & Osize */
- coda_mkdir_size += len + 1;
- ALLOC(coda_mkdir); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_MKDIR, cred, p);
- inp->VFid = *fid;
- CNV_V2VV_ATTR(&inp->attr, va);
-
- inp->name = Isize;
- STRCPY(name, nm, len); /* increments Isize */
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
- if (!error) {
- *VFid = outp->VFid;
- CNV_VV2V_ATTR(ova, &outp->attr);
- }
-
- CODA_FREE(inp, coda_mkdir_size);
- return error;
-}
-
-int
-venus_rmdir(void *mdp, ViceFid *fid,
- const char *nm, int len,
- struct ucred *cred, struct proc *p)
-{
- DECL_NO_OUT(coda_rmdir); /* sets Isize & Osize */
- coda_rmdir_size += len + 1;
- ALLOC_NO_OUT(coda_rmdir); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_RMDIR, cred, p);
- inp->VFid = *fid;
-
- inp->name = Isize;
- STRCPY(name, nm, len); /* increments Isize */
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
-
- CODA_FREE(inp, coda_rmdir_size);
- return error;
-}
-
-int
-venus_symlink(void *mdp, ViceFid *fid,
- const char *lnm, int llen, const char *nm, int len, struct vattr *va,
- struct ucred *cred, struct proc *p)
-{
- DECL_NO_OUT(coda_symlink); /* sets Isize & Osize */
- coda_symlink_size += llen + 1 + len + 1;
- ALLOC_NO_OUT(coda_symlink); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_SYMLINK, cred, p);
- inp->VFid = *fid;
- CNV_V2VV_ATTR(&inp->attr, va);
-
- inp->srcname = Isize;
- STRCPY(srcname, lnm, llen); /* increments Isize */
-
- inp->tname = Isize;
- STRCPY(tname, nm, len); /* increments Isize */
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
-
- CODA_FREE(inp, coda_symlink_size);
- return error;
-}
-
-int
-venus_readdir(void *mdp, ViceFid *fid,
- int count, int offset,
- struct ucred *cred, struct proc *p,
-/*out*/ char *buffer, int *len)
-{
- DECL(coda_readdir); /* sets Isize & Osize */
- coda_readdir_size = VC_MAXMSGSIZE;
- ALLOC(coda_readdir); /* sets inp & outp */
-
- /* send the open to venus. */
- INIT_IN(&inp->ih, CODA_READDIR, cred, p);
- inp->VFid = *fid;
- inp->count = count;
- inp->offset = offset;
-
- Osize = VC_MAXMSGSIZE;
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
- if (!error) {
- bcopy((char *)outp + (long)outp->data, buffer, outp->size);
- *len = outp->size;
- }
-
- CODA_FREE(inp, coda_readdir_size);
- return error;
-}
-
-int
-venus_fhtovp(void *mdp, ViceFid *fid,
- struct ucred *cred, struct proc *p,
-/*out*/ ViceFid *VFid, int *vtype)
-{
- DECL(coda_vget); /* sets Isize & Osize */
- ALLOC(coda_vget); /* sets inp & outp */
-
- /* Send the open to Venus. */
- INIT_IN(&inp->ih, CODA_VGET, cred, p);
- inp->VFid = *fid;
-
- error = coda_call(mdp, Isize, &Osize, (char *)inp);
- if (!error) {
- *VFid = outp->VFid;
- *vtype = outp->vtype;
- }
-
- CODA_FREE(inp, coda_vget_size);
- return error;
-}
diff --git a/sys/fs/coda/coda_venus.h b/sys/fs/coda/coda_venus.h
deleted file mode 100644
index 392a73f07114..000000000000
--- a/sys/fs/coda/coda_venus.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_venus.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-int
-venus_root(void *mdp,
- struct ucred *cred, struct proc *p,
-/*out*/ ViceFid *VFid);
-
-int
-venus_open(void *mdp, ViceFid *fid, int flag,
- struct ucred *cred, struct proc *p,
-/*out*/ dev_t *dev, ino_t *inode);
-
-int
-venus_close(void *mdp, ViceFid *fid, int flag,
- struct ucred *cred, struct proc *p);
-
-void
-venus_read(void);
-
-void
-venus_write(void);
-
-int
-venus_ioctl(void *mdp, ViceFid *fid,
- int com, int flag, caddr_t data,
- struct ucred *cred, struct proc *p);
-
-int
-venus_getattr(void *mdp, ViceFid *fid,
- struct ucred *cred, struct proc *p,
-/*out*/ struct vattr *vap);
-
-int
-venus_setattr(void *mdp, ViceFid *fid, struct vattr *vap,
- struct ucred *cred, struct proc *p);
-
-int
-venus_access(void *mdp, ViceFid *fid, int mode,
- struct ucred *cred, struct proc *p);
-
-int
-venus_readlink(void *mdp, ViceFid *fid,
- struct ucred *cred, struct proc *p,
-/*out*/ char **str, int *len);
-
-int
-venus_fsync(void *mdp, ViceFid *fid,
- struct ucred *cred, struct proc *p);
-
-int
-venus_lookup(void *mdp, ViceFid *fid,
- const char *nm, int len,
- struct ucred *cred, struct proc *p,
-/*out*/ ViceFid *VFid, int *vtype);
-
-int
-venus_create(void *mdp, ViceFid *fid,
- const char *nm, int len, int exclusive, int mode, struct vattr *va,
- struct ucred *cred, struct proc *p,
-/*out*/ ViceFid *VFid, struct vattr *attr);
-
-int
-venus_remove(void *mdp, ViceFid *fid,
- const char *nm, int len,
- struct ucred *cred, struct proc *p);
-
-int
-venus_link(void *mdp, ViceFid *fid, ViceFid *tfid,
- const char *nm, int len,
- struct ucred *cred, struct proc *p);
-
-int
-venus_rename(void *mdp, ViceFid *fid, ViceFid *tfid,
- const char *nm, int len, const char *tnm, int tlen,
- struct ucred *cred, struct proc *p);
-
-int
-venus_mkdir(void *mdp, ViceFid *fid,
- const char *nm, int len, struct vattr *va,
- struct ucred *cred, struct proc *p,
-/*out*/ ViceFid *VFid, struct vattr *ova);
-
-int
-venus_rmdir(void *mdp, ViceFid *fid,
- const char *nm, int len,
- struct ucred *cred, struct proc *p);
-
-int
-venus_symlink(void *mdp, ViceFid *fid,
- const char *lnm, int llen, const char *nm, int len, struct vattr *va,
- struct ucred *cred, struct proc *p);
-
-int
-venus_readdir(void *mdp, ViceFid *fid,
- int count, int offset,
- struct ucred *cred, struct proc *p,
-/*out*/ char *buffer, int *len);
-
-int
-venus_fhtovp(void *mdp, ViceFid *fid,
- struct ucred *cred, struct proc *p,
-/*out*/ ViceFid *VFid, int *vtype);
diff --git a/sys/fs/coda/coda_vfsops.c b/sys/fs/coda/coda_vfsops.c
deleted file mode 100644
index f25738fb0763..000000000000
--- a/sys/fs/coda/coda_vfsops.c
+++ /dev/null
@@ -1,570 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/cfs/coda_vfsops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/*
- * Mach Operating System
- * Copyright (c) 1989 Carnegie-Mellon University
- * All rights reserved. The CMU software License Agreement specifies
- * the terms and conditions for use and redistribution.
- */
-
-/*
- * This code was written for the Coda filesystem at Carnegie Mellon
- * University. Contributers include David Steere, James Kistler, and
- * M. Satyanarayanan.
- */
-
-#include <vcoda.h>
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/conf.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mount.h>
-#include <sys/namei.h>
-#include <sys/proc.h>
-
-#include <coda/coda.h>
-#include <coda/cnode.h>
-#include <coda/coda_vfsops.h>
-#include <coda/coda_venus.h>
-#include <coda/coda_subr.h>
-#include <coda/coda_opstats.h>
-
-MALLOC_DEFINE(M_CODA, "CODA storage", "Various Coda Structures");
-
-int codadebug = 0;
-int coda_vfsop_print_entry = 0;
-#define ENTRY if(coda_vfsop_print_entry) myprintf(("Entered %s\n",__func__))
-
-struct vnode *coda_ctlvp;
-struct coda_mntinfo coda_mnttbl[NVCODA]; /* indexed by minor device number */
-
-/* structure to keep statistics of internally generated/satisfied calls */
-
-struct coda_op_stats coda_vfsopstats[CODA_VFSOPS_SIZE];
-
-#define MARK_ENTRY(op) (coda_vfsopstats[op].entries++)
-#define MARK_INT_SAT(op) (coda_vfsopstats[op].sat_intrn++)
-#define MARK_INT_FAIL(op) (coda_vfsopstats[op].unsat_intrn++)
-#define MRAK_INT_GEN(op) (coda_vfsopstats[op].gen_intrn++)
-
-extern int coda_nc_initialized; /* Set if cache has been initialized */
-extern int vc_nb_open(dev_t, int, int, struct thread *);
-
-int
-coda_vfsopstats_init(void)
-{
- register int i;
-
- for (i=0;i<CODA_VFSOPS_SIZE;i++) {
- coda_vfsopstats[i].opcode = i;
- coda_vfsopstats[i].entries = 0;
- coda_vfsopstats[i].sat_intrn = 0;
- coda_vfsopstats[i].unsat_intrn = 0;
- coda_vfsopstats[i].gen_intrn = 0;
- }
-
- return 0;
-}
-
-/*
- * cfs mount vfsop
- * Set up mount info record and attach it to vfs struct.
- */
-/*ARGSUSED*/
-int
-coda_mount(vfsp, path, data, ndp, td)
- struct mount *vfsp; /* Allocated and initialized by mount(2) */
- char *path; /* path covered: ignored by the fs-layer */
- caddr_t data; /* Need to define a data type for this in netbsd? */
- struct nameidata *ndp; /* Clobber this to lookup the device name */
- struct thread *td;
-{
- struct vnode *dvp;
- struct cnode *cp;
- dev_t dev;
- struct coda_mntinfo *mi;
- struct vnode *rootvp;
- ViceFid rootfid;
- ViceFid ctlfid;
- int error;
-
- ENTRY;
-
- coda_vfsopstats_init();
- coda_vnodeopstats_init();
-
- MARK_ENTRY(CODA_MOUNT_STATS);
- if (CODA_MOUNTED(vfsp)) {
- MARK_INT_FAIL(CODA_MOUNT_STATS);
- return(EBUSY);
- }
-
- /* Validate mount device. Similar to getmdev(). */
- NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, data, td);
- error = namei(ndp);
- dvp = ndp->ni_vp;
-
- if (error) {
- MARK_INT_FAIL(CODA_MOUNT_STATS);
- return (error);
- }
- if (dvp->v_type != VCHR) {
- MARK_INT_FAIL(CODA_MOUNT_STATS);
- vrele(dvp);
- NDFREE(ndp, NDF_ONLY_PNBUF);
- return(ENXIO);
- }
- dev = dvp->v_rdev;
- vrele(dvp);
- NDFREE(ndp, NDF_ONLY_PNBUF);
-
- /*
- * See if the device table matches our expectations.
- */
- if (devsw(dev)->d_open != vc_nb_open)
- {
- MARK_INT_FAIL(CODA_MOUNT_STATS);
- return(ENXIO);
- }
-
- if (minor(dev) >= NVCODA || minor(dev) < 0) {
- MARK_INT_FAIL(CODA_MOUNT_STATS);
- return(ENXIO);
- }
-
- /*
- * Initialize the mount record and link it to the vfs struct
- */
- mi = &coda_mnttbl[minor(dev)];
-
- if (!VC_OPEN(&mi->mi_vcomm)) {
- MARK_INT_FAIL(CODA_MOUNT_STATS);
- return(ENODEV);
- }
-
- /* No initialization (here) of mi_vcomm! */
- vfsp->mnt_data = (qaddr_t)mi;
- vfs_getnewfsid (vfsp);
-
- mi->mi_vfsp = vfsp;
- mi->mi_started = 0; /* XXX See coda_root() */
-
- /*
- * Make a root vnode to placate the Vnode interface, but don't
- * actually make the CODA_ROOT call to venus until the first call
- * to coda_root in case a server is down while venus is starting.
- */
- rootfid.Volume = 0;
- rootfid.Vnode = 0;
- rootfid.Unique = 0;
- cp = make_coda_node(&rootfid, vfsp, VDIR);
- rootvp = CTOV(cp);
- rootvp->v_vflag |= VV_ROOT;
-
- ctlfid.Volume = CTL_VOL;
- ctlfid.Vnode = CTL_VNO;
- ctlfid.Unique = CTL_UNI;
-/* cp = make_coda_node(&ctlfid, vfsp, VCHR);
- The above code seems to cause a loop in the cnode links.
- I don't totally understand when it happens, it is caught
- when closing down the system.
- */
- cp = make_coda_node(&ctlfid, 0, VCHR);
-
- coda_ctlvp = CTOV(cp);
-
- /* Add vfs and rootvp to chain of vfs hanging off mntinfo */
- mi->mi_vfsp = vfsp;
- mi->mi_rootvp = rootvp;
-
- /* set filesystem block size */
- vfsp->mnt_stat.f_bsize = 8192; /* XXX -JJK */
-
- /* Set f_iosize. XXX -- inamura@isl.ntt.co.jp.
- For vnode_pager_haspage() references. The value should be obtained
- from underlying UFS. */
- /* Checked UFS. iosize is set as 8192 */
- vfsp->mnt_stat.f_iosize = 8192;
-
- /* error is currently guaranteed to be zero, but in case some
- code changes... */
- CODADEBUG(1,
- myprintf(("coda_mount returned %d\n",error)););
- if (error)
- MARK_INT_FAIL(CODA_MOUNT_STATS);
- else
- MARK_INT_SAT(CODA_MOUNT_STATS);
-
- return(error);
-}
-
-int
-coda_unmount(vfsp, mntflags, td)
- struct mount *vfsp;
- int mntflags;
- struct thread *td;
-{
- struct coda_mntinfo *mi = vftomi(vfsp);
- int active, error = 0;
-
- ENTRY;
- MARK_ENTRY(CODA_UMOUNT_STATS);
- if (!CODA_MOUNTED(vfsp)) {
- MARK_INT_FAIL(CODA_UMOUNT_STATS);
- return(EINVAL);
- }
-
- if (mi->mi_vfsp == vfsp) { /* We found the victim */
- if (!IS_UNMOUNTING(VTOC(mi->mi_rootvp)))
- return (EBUSY); /* Venus is still running */
-
-#ifdef DEBUG
- printf("coda_unmount: ROOT: vp %p, cp %p\n", mi->mi_rootvp, VTOC(mi->mi_rootvp));
-#endif
- vrele(mi->mi_rootvp);
-
- active = coda_kill(vfsp, NOT_DOWNCALL);
- ASSERT_VOP_LOCKED(mi->mi_rootvp, "coda_unmount");
- mi->mi_rootvp->v_vflag &= ~VV_ROOT;
- error = vflush(mi->mi_vfsp, 0, FORCECLOSE);
- printf("coda_unmount: active = %d, vflush active %d\n", active, error);
- error = 0;
- /* I'm going to take this out to allow lookups to go through. I'm
- * not sure it's important anyway. -- DCS 2/2/94
- */
- /* vfsp->VFS_DATA = NULL; */
-
- /* No more vfsp's to hold onto */
- mi->mi_vfsp = NULL;
- mi->mi_rootvp = NULL;
-
- if (error)
- MARK_INT_FAIL(CODA_UMOUNT_STATS);
- else
- MARK_INT_SAT(CODA_UMOUNT_STATS);
-
- return(error);
- }
- return (EINVAL);
-}
-
-/*
- * find root of cfs
- */
-int
-coda_root(vfsp, vpp)
- struct mount *vfsp;
- struct vnode **vpp;
-{
- struct coda_mntinfo *mi = vftomi(vfsp);
- struct vnode **result;
- int error;
- struct thread *td = curthread; /* XXX - bnoble */
- struct proc *p = td->td_proc;
- ViceFid VFid;
-
- ENTRY;
- MARK_ENTRY(CODA_ROOT_STATS);
- result = NULL;
-
- if (vfsp == mi->mi_vfsp) {
- /*
- * Cache the root across calls. We only need to pass the request
- * on to Venus if the root vnode is the dummy we installed in
- * coda_mount() with all c_fid members zeroed.
- *
- * XXX In addition, if we are called between coda_mount() and
- * coda_start(), we assume that the request is from vfs_mount()
- * (before the call to checkdirs()) and return the dummy root
- * node to avoid a deadlock. This bug is fixed in the Coda CVS
- * repository but not in any released versions as of 6 Mar 2003.
- */
- if ((VTOC(mi->mi_rootvp)->c_fid.Volume != 0) ||
- (VTOC(mi->mi_rootvp)->c_fid.Vnode != 0) ||
- (VTOC(mi->mi_rootvp)->c_fid.Unique != 0) ||
- mi->mi_started == 0)
- { /* Found valid root. */
- *vpp = mi->mi_rootvp;
- /* On Mach, this is vref. On NetBSD, VOP_LOCK */
-#if 1
- vref(*vpp);
- vn_lock(*vpp, LK_EXCLUSIVE, td);
-#else
- vget(*vpp, LK_EXCLUSIVE, td);
-#endif
- MARK_INT_SAT(CODA_ROOT_STATS);
- return(0);
- }
- }
-
- error = venus_root(vftomi(vfsp), td->td_ucred, p, &VFid);
-
- if (!error) {
- /*
- * Save the new rootfid in the cnode, and rehash the cnode into the
- * cnode hash with the new fid key.
- */
- coda_unsave(VTOC(mi->mi_rootvp));
- VTOC(mi->mi_rootvp)->c_fid = VFid;
- coda_save(VTOC(mi->mi_rootvp));
-
- *vpp = mi->mi_rootvp;
-#if 1
- vref(*vpp);
- vn_lock(*vpp, LK_EXCLUSIVE, td);
-#else
- vget(*vpp, LK_EXCLUSIVE, td);
-#endif
-
- MARK_INT_SAT(CODA_ROOT_STATS);
- goto exit;
- } else if (error == ENODEV || error == EINTR) {
- /* Gross hack here! */
- /*
- * If Venus fails to respond to the CODA_ROOT call, coda_call returns
- * ENODEV. Return the uninitialized root vnode to allow vfs
- * operations such as unmount to continue. Without this hack,
- * there is no way to do an unmount if Venus dies before a
- * successful CODA_ROOT call is done. All vnode operations
- * will fail.
- */
- *vpp = mi->mi_rootvp;
-#if 1
- vref(*vpp);
- vn_lock(*vpp, LK_EXCLUSIVE, td);
-#else
- vget(*vpp, LK_EXCLUSIVE, td);
-#endif
-
- MARK_INT_FAIL(CODA_ROOT_STATS);
- error = 0;
- goto exit;
- } else {
- CODADEBUG( CODA_ROOT, myprintf(("error %d in CODA_ROOT\n", error)); );
- MARK_INT_FAIL(CODA_ROOT_STATS);
-
- goto exit;
- }
-
- exit:
- return(error);
-}
-
-int
-coda_start(mp, flags, td)
- struct mount *mp;
- int flags;
- struct thread *td;
-{
-
- /* XXX See coda_root(). */
- vftomi(mp)->mi_started = 1;
- return (0);
-}
-
-/*
- * Get filesystem statistics.
- */
-int
-coda_nb_statfs(vfsp, sbp, td)
- register struct mount *vfsp;
- struct statfs *sbp;
- struct thread *td;
-{
- ENTRY;
-/* MARK_ENTRY(CODA_STATFS_STATS); */
- if (!CODA_MOUNTED(vfsp)) {
-/* MARK_INT_FAIL(CODA_STATFS_STATS);*/
- return(EINVAL);
- }
-
- bzero(sbp, sizeof(struct statfs));
- /* XXX - what to do about f_flags, others? --bnoble */
- /* Below This is what AFS does
- #define NB_SFS_SIZ 0x895440
- */
- /* Note: Normal fs's have a bsize of 0x400 == 1024 */
- sbp->f_type = vfsp->mnt_vfc->vfc_typenum;
- sbp->f_bsize = 8192; /* XXX */
- sbp->f_iosize = 8192; /* XXX */
-#define NB_SFS_SIZ 0x8AB75D
- sbp->f_blocks = NB_SFS_SIZ;
- sbp->f_bfree = NB_SFS_SIZ;
- sbp->f_bavail = NB_SFS_SIZ;
- sbp->f_files = NB_SFS_SIZ;
- sbp->f_ffree = NB_SFS_SIZ;
- bcopy((caddr_t)&(vfsp->mnt_stat.f_fsid), (caddr_t)&(sbp->f_fsid), sizeof (fsid_t));
- snprintf(sbp->f_mntonname, sizeof(sbp->f_mntonname), "/coda");
- snprintf(sbp->f_mntfromname, sizeof(sbp->f_mntfromname), "CODA");
- snprintf(sbp->f_fstypename, sizeof(sbp->f_fstypename), "coda");
-/* MARK_INT_SAT(CODA_STATFS_STATS); */
- return(0);
-}
-
-/*
- * Flush any pending I/O.
- */
-int
-coda_sync(vfsp, waitfor, cred, td)
- struct mount *vfsp;
- int waitfor;
- struct ucred *cred;
- struct thread *td;
-{
- ENTRY;
- MARK_ENTRY(CODA_SYNC_STATS);
- MARK_INT_SAT(CODA_SYNC_STATS);
- return(0);
-}
-
-/*
- * fhtovp is now what vget used to be in 4.3-derived systems. For
- * some silly reason, vget is now keyed by a 32 bit ino_t, rather than
- * a type-specific fid.
- */
-int
-coda_fhtovp(vfsp, fhp, nam, vpp, exflagsp, creadanonp)
- register struct mount *vfsp;
- struct fid *fhp;
- struct mbuf *nam;
- struct vnode **vpp;
- int *exflagsp;
- struct ucred **creadanonp;
-{
- struct cfid *cfid = (struct cfid *)fhp;
- struct cnode *cp = 0;
- int error;
- struct thread *td = curthread; /* XXX -mach */
- struct proc *p = td->td_proc;
- ViceFid VFid;
- int vtype;
-
- ENTRY;
-
- MARK_ENTRY(CODA_VGET_STATS);
- /* Check for vget of control object. */
- if (IS_CTL_FID(&cfid->cfid_fid)) {
- *vpp = coda_ctlvp;
- vref(coda_ctlvp);
- MARK_INT_SAT(CODA_VGET_STATS);
- return(0);
- }
-
- error = venus_fhtovp(vftomi(vfsp), &cfid->cfid_fid, td->td_ucred, p, &VFid, &vtype);
-
- if (error) {
- CODADEBUG(CODA_VGET, myprintf(("vget error %d\n",error));)
- *vpp = (struct vnode *)0;
- } else {
- CODADEBUG(CODA_VGET,
- myprintf(("vget: vol %lx vno %lx uni %lx type %d result %d\n",
- VFid.Volume, VFid.Vnode, VFid.Unique, vtype, error)); )
-
- cp = make_coda_node(&VFid, vfsp, vtype);
- *vpp = CTOV(cp);
- }
- return(error);
-}
-
-/*
- * To allow for greater ease of use, some vnodes may be orphaned when
- * Venus dies. Certain operations should still be allowed to go
- * through, but without propagating ophan-ness. So this function will
- * get a new vnode for the file from the current run of Venus. */
-
-int
-getNewVnode(vpp)
- struct vnode **vpp;
-{
- struct cfid cfid;
- struct coda_mntinfo *mi = vftomi((*vpp)->v_mount);
-
- ENTRY;
-
- cfid.cfid_len = (short)sizeof(ViceFid);
- cfid.cfid_fid = VTOC(*vpp)->c_fid; /* Structure assignment. */
- /* XXX ? */
-
- /* We're guessing that if set, the 1st element on the list is a
- * valid vnode to use. If not, return ENODEV as venus is dead.
- */
- if (mi->mi_vfsp == NULL)
- return ENODEV;
-
- return coda_fhtovp(mi->mi_vfsp, (struct fid*)&cfid, NULL, vpp,
- NULL, NULL);
-}
-
-#include <ufs/ufs/extattr.h>
-#include <ufs/ufs/quota.h>
-#include <ufs/ufs/ufsmount.h>
-/* get the mount structure corresponding to a given device. Assume
- * device corresponds to a UFS. Return NULL if no device is found.
- */
-struct mount *devtomp(dev)
- dev_t dev;
-{
- struct mount *mp;
-
- TAILQ_FOREACH(mp, &mountlist, mnt_list) {
- if (((VFSTOUFS(mp))->um_dev == dev)) {
- /* mount corresponds to UFS and the device matches one we want */
- return(mp);
- }
- }
- /* mount structure wasn't found */
- return(NULL);
-}
-
-struct vfsops coda_vfsops = {
- coda_mount,
- coda_start,
- coda_unmount,
- coda_root,
- vfs_stdquotactl,
- coda_nb_statfs,
- coda_sync,
- vfs_stdvget,
- vfs_stdfhtovp,
- vfs_stdcheckexp,
- vfs_stdvptofh,
- vfs_stdinit,
- vfs_stduninit,
- vfs_stdextattrctl,
-};
-
-VFS_SET(coda_vfsops, coda, VFCF_NETWORK);
diff --git a/sys/fs/coda/coda_vfsops.h b/sys/fs/coda/coda_vfsops.h
deleted file mode 100644
index 57b9a5a9a8bc..000000000000
--- a/sys/fs/coda/coda_vfsops.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/cfs/coda_vfsops.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/*
- * cfid structure:
- * This overlays the fid structure (see vfs.h)
- * Only used below and will probably go away.
- */
-
-struct cfid {
- u_short cfid_len;
- u_short padding;
- ViceFid cfid_fid;
-};
-
-struct mbuf;
-struct mount;
-
-int coda_vfsopstats_init(void);
-int coda_mount(struct mount *, char *, caddr_t, struct nameidata *,
- struct thread *);
-int coda_start(struct mount *, int, struct thread *);
-int coda_unmount(struct mount *, int, struct thread *);
-int coda_root(struct mount *, struct vnode **);
-int coda_quotactl(struct mount *, int, uid_t, caddr_t, struct thread *);
-int coda_nb_statfs(struct mount *, struct statfs *, struct thread *);
-int coda_sync(struct mount *, int, struct ucred *, struct thread *);
-int coda_vget(struct mount *, ino_t, struct vnode **);
-int coda_fhtovp(struct mount *, struct fid *, struct mbuf *, struct vnode **,
- int *, struct ucred **);
-int coda_vptofh(struct vnode *, struct fid *);
-int coda_init(struct vfsconf *vfsp);
-
-int getNewVnode(struct vnode **vpp);
diff --git a/sys/fs/coda/coda_vnops.c b/sys/fs/coda/coda_vnops.c
deleted file mode 100644
index a94cd06d942c..000000000000
--- a/sys/fs/coda/coda_vnops.c
+++ /dev/null
@@ -1,2007 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_vnops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/*
- * Mach Operating System
- * Copyright (c) 1990 Carnegie-Mellon University
- * Copyright (c) 1989 Carnegie-Mellon University
- * All rights reserved. The CMU software License Agreement specifies
- * the terms and conditions for use and redistribution.
- */
-
-/*
- * This code was written for the Coda filesystem at Carnegie Mellon
- * University. Contributers include David Steere, James Kistler, and
- * M. Satyanarayanan.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/acct.h>
-#include <sys/errno.h>
-#include <sys/fcntl.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/file.h> /* Must come after sys/malloc.h */
-#include <sys/mount.h>
-#include <sys/mutex.h>
-#include <sys/namei.h>
-#include <sys/proc.h>
-#include <sys/uio.h>
-#include <sys/unistd.h>
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/vm_extern.h>
-
-#include <coda/coda.h>
-#include <coda/cnode.h>
-#include <coda/coda_vnops.h>
-#include <coda/coda_venus.h>
-#include <coda/coda_opstats.h>
-#include <coda/coda_subr.h>
-#include <coda/coda_namecache.h>
-#include <coda/coda_pioctl.h>
-
-/*
- * These flags select various performance enhancements.
- */
-int coda_attr_cache = 1; /* Set to cache attributes in the kernel */
-int coda_symlink_cache = 1; /* Set to cache symbolic link information */
-int coda_access_cache = 1; /* Set to handle some access checks directly */
-
-/* structure to keep track of vfs calls */
-
-struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
-
-#define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
-#define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
-#define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
-#define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
-
-/* What we are delaying for in printf */
-int coda_printf_delay = 0; /* in microseconds */
-int coda_vnop_print_entry = 0;
-static int coda_lockdebug = 0;
-
-/* Definition of the vfs operation vector */
-static int (**coda_vnodeop_p)(void *);
-
-/*
- * Some NetBSD details:
- *
- * coda_start is called at the end of the mount syscall.
- * coda_init is called at boot time.
- */
-
-#define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__func__))
-
-/* Definition of the vnode operation vector */
-
-struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
- { &vop_default_desc, coda_vop_error },
- { &vop_lookup_desc, coda_lookup }, /* lookup */
- { &vop_create_desc, coda_create }, /* create */
- { &vop_mknod_desc, coda_vop_error }, /* mknod */
- { &vop_open_desc, coda_open }, /* open */
- { &vop_close_desc, coda_close }, /* close */
- { &vop_access_desc, coda_access }, /* access */
- { &vop_getattr_desc, coda_getattr }, /* getattr */
- { &vop_setattr_desc, coda_setattr }, /* setattr */
- { &vop_read_desc, coda_read }, /* read */
- { &vop_write_desc, coda_write }, /* write */
- { &vop_ioctl_desc, coda_ioctl }, /* ioctl */
- { &vop_fsync_desc, coda_fsync }, /* fsync */
- { &vop_remove_desc, coda_remove }, /* remove */
- { &vop_link_desc, coda_link }, /* link */
- { &vop_rename_desc, coda_rename }, /* rename */
- { &vop_mkdir_desc, coda_mkdir }, /* mkdir */
- { &vop_rmdir_desc, coda_rmdir }, /* rmdir */
- { &vop_symlink_desc, coda_symlink }, /* symlink */
- { &vop_readdir_desc, coda_readdir }, /* readdir */
- { &vop_readlink_desc, coda_readlink }, /* readlink */
- { &vop_inactive_desc, coda_inactive }, /* inactive */
- { &vop_reclaim_desc, coda_reclaim }, /* reclaim */
- { &vop_lock_desc, coda_lock }, /* lock */
- { &vop_unlock_desc, coda_unlock }, /* unlock */
- { &vop_bmap_desc, coda_bmap }, /* bmap */
- { &vop_strategy_desc, coda_strategy }, /* strategy */
- { &vop_print_desc, coda_vop_error }, /* print */
- { &vop_islocked_desc, coda_islocked }, /* islocked */
- { &vop_pathconf_desc, coda_pathconf }, /* pathconf */
- { &vop_advlock_desc, coda_vop_nop }, /* advlock */
- { &vop_lease_desc, coda_vop_nop }, /* lease */
- { &vop_poll_desc, (vop_t *) vop_stdpoll },
- { &vop_getpages_desc, (vop_t*)vop_stdgetpages }, /* pager intf.*/
- { &vop_putpages_desc, (vop_t*)vop_stdputpages }, /* pager intf.*/
- { &vop_createvobject_desc, (vop_t*)vop_stdcreatevobject },
- { &vop_destroyvobject_desc, (vop_t*)vop_stddestroyvobject },
- { &vop_getvobject_desc, (vop_t*)vop_stdgetvobject },
-
-#if 0
-
- we need to define these someday
-#define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd)
-#define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd)
-#define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc)
-#define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee)
-#define UFS_UPDATE(aa, bb) VFSTOUFS((aa)->v_mount)->um_update(aa, bb)
-
- missing
- { &vop_reallocblks_desc, (vop_t *) ufs_missingop },
- { &vop_cachedlookup_desc, (vop_t *) ufs_lookup },
- { &vop_whiteout_desc, (vop_t *) ufs_whiteout },
-#endif
-
- { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject },
- { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject },
- { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject },
- { &vop_getwritemount_desc, (vop_t *) vop_stdgetwritemount },
- { (struct vnodeop_desc*)NULL, (int(*)(void *))NULL }
-};
-
-static struct vnodeopv_desc coda_vnodeop_opv_desc =
- { &coda_vnodeop_p, coda_vnodeop_entries };
-
-VNODEOP_SET(coda_vnodeop_opv_desc);
-
-/* A generic panic: we were called with something we didn't define yet */
-int
-coda_vop_error(void *anon) {
- struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
-
- myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
- (*desc)->vdesc_name));
- /*
- panic("coda_vop_error");
- */
- return EIO;
-}
-
-/* A generic do-nothing. For lease_check, advlock */
-int
-coda_vop_nop(void *anon) {
- struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
-
- if (codadebug) {
- myprintf(("Vnode operation %s called, but unsupported\n",
- (*desc)->vdesc_name));
- }
- return (0);
-}
-
-int
-coda_vnodeopstats_init(void)
-{
- register int i;
-
- for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
- coda_vnodeopstats[i].opcode = i;
- coda_vnodeopstats[i].entries = 0;
- coda_vnodeopstats[i].sat_intrn = 0;
- coda_vnodeopstats[i].unsat_intrn = 0;
- coda_vnodeopstats[i].gen_intrn = 0;
- }
- return 0;
-}
-
-/*
- * coda_open calls Venus to return the device, inode pair of the cache
- * file holding the data. Using iget, coda_open finds the vnode of the
- * cache file, and then opens it.
- */
-int
-coda_open(v)
- void *v;
-{
- /*
- * NetBSD can pass the O_EXCL flag in mode, even though the check
- * has already happened. Venus defensively assumes that if open
- * is passed the EXCL, it must be a bug. We strip the flag here.
- */
-/* true args */
- struct vop_open_args *ap = v;
- register struct vnode **vpp = &(ap->a_vp);
- struct cnode *cp = VTOC(*vpp);
- int flag = ap->a_mode & (~O_EXCL);
- struct ucred *cred = ap->a_cred;
- struct thread *td = ap->a_td;
-/* locals */
- int error;
- struct vnode *vp;
- dev_t dev;
- ino_t inode;
-
- MARK_ENTRY(CODA_OPEN_STATS);
-
- /* Check for open of control file. */
- if (IS_CTL_VP(*vpp)) {
- /* XXX */
- /* if (WRITEABLE(flag)) */
- if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
- MARK_INT_FAIL(CODA_OPEN_STATS);
- return(EACCES);
- }
- MARK_INT_SAT(CODA_OPEN_STATS);
- return(0);
- }
-
- error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td->td_proc, &dev, &inode);
- if (error)
- return (error);
- if (!error) {
- CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
- (u_long)dev2udev(dev), (u_long)inode,
- error)); )
- }
-
- /* Translate the <device, inode> pair for the cache file into
- an inode pointer. */
- error = coda_grab_vnode(dev, inode, &vp);
- if (error)
- return (error);
-
- /* We get the vnode back locked. Needs unlocked */
- VOP_UNLOCK(vp, 0, td);
- /* Keep a reference until the close comes in. */
- vref(*vpp);
-
- /* Save the vnode pointer for the cache file. */
- if (cp->c_ovp == NULL) {
- cp->c_ovp = vp;
- } else {
- if (cp->c_ovp != vp)
- panic("coda_open: cp->c_ovp != ITOV(ip)");
- }
- cp->c_ocount++;
-
- /* Flush the attribute cached if writing the file. */
- if (flag & FWRITE) {
- cp->c_owrite++;
- cp->c_flags &= ~C_VATTR;
- }
-
- /* Save the <device, inode> pair for the cache file to speed
- up subsequent page_read's. */
- cp->c_device = dev;
- cp->c_inode = inode;
-
- /* Open the cache file. */
- error = VOP_OPEN(vp, flag, cred, td);
- if (error) {
- printf("coda_open: VOP_OPEN on container failed %d\n", error);
- return (error);
- }
-/* grab (above) does this when it calls newvnode unless it's in the cache*/
- if (vp->v_type == VREG) {
- error = vfs_object_create(vp, td, cred);
- if (error != 0) {
- printf("coda_open: vfs_object_create() returns %d\n", error);
- vput(vp);
- }
- }
-
- return(error);
-}
-
-/*
- * Close the cache file used for I/O and notify Venus.
- */
-int
-coda_close(v)
- void *v;
-{
-/* true args */
- struct vop_close_args *ap = v;
- struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
- int flag = ap->a_fflag;
- struct ucred *cred = ap->a_cred;
- struct thread *td = ap->a_td;
-/* locals */
- int error;
-
- MARK_ENTRY(CODA_CLOSE_STATS);
-
- /* Check for close of control file. */
- if (IS_CTL_VP(vp)) {
- MARK_INT_SAT(CODA_CLOSE_STATS);
- return(0);
- }
-
- if (IS_UNMOUNTING(cp)) {
- if (cp->c_ovp) {
-#ifdef CODA_VERBOSE
- printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
- vrefcnt(vp), cp->c_ovp, vp, cp);
-#endif
-#ifdef hmm
- vgone(cp->c_ovp);
-#else
- VOP_CLOSE(cp->c_ovp, flag, cred, td); /* Do errors matter here? */
- vrele(cp->c_ovp);
-#endif
- } else {
-#ifdef CODA_VERBOSE
- printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
-#endif
- }
- return ENODEV;
- } else {
- VOP_CLOSE(cp->c_ovp, flag, cred, td); /* Do errors matter here? */
- vrele(cp->c_ovp);
- }
-
- if (--cp->c_ocount == 0)
- cp->c_ovp = NULL;
-
- if (flag & FWRITE) /* file was opened for write */
- --cp->c_owrite;
-
- error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, td->td_proc);
- vrele(CTOV(cp));
-
- CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
- return(error);
-}
-
-int
-coda_read(v)
- void *v;
-{
- struct vop_read_args *ap = v;
-
- ENTRY;
- return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
- ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
-}
-
-int
-coda_write(v)
- void *v;
-{
- struct vop_write_args *ap = v;
-
- ENTRY;
- return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
- ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
-}
-
-int
-coda_rdwr(vp, uiop, rw, ioflag, cred, td)
- struct vnode *vp;
- struct uio *uiop;
- enum uio_rw rw;
- int ioflag;
- struct ucred *cred;
- struct thread *td;
-{
-/* upcall decl */
- /* NOTE: container file operation!!! */
-/* locals */
- struct cnode *cp = VTOC(vp);
- struct vnode *cfvp = cp->c_ovp;
- struct proc *p = td->td_proc;
- struct thread *ltd = td;
- int igot_internally = 0;
- int opened_internally = 0;
- int error = 0;
- int iscore = 0;
-
- MARK_ENTRY(CODA_RDWR_STATS);
-
- CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw,
- (void *)uiop->uio_iov->iov_base, uiop->uio_resid,
- (long long)uiop->uio_offset, uiop->uio_segflg)); )
-
- /* Check for rdwr of control object. */
- if (IS_CTL_VP(vp)) {
- MARK_INT_FAIL(CODA_RDWR_STATS);
- return(EINVAL);
- }
-
- /*
- * If file is not already open this must be a page
- * {read,write} request. Iget the cache file's inode
- * pointer if we still have its <device, inode> pair.
- * Otherwise, we must do an internal open to derive the
- * pair.
- */
- if (cfvp == NULL) {
- /*
- * If we're dumping core, do the internal open. Otherwise
- * venus won't have the correct size of the core when
- * it's completely written.
- */
- if (p) {
- PROC_LOCK(p);
- iscore = (p->p_acflag & ACORE);
- PROC_UNLOCK(p);
- }
- else
- ltd = curthread;
-
- if (cp->c_inode != 0 && !iscore) {
- igot_internally = 1;
- error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
- if (error) {
- MARK_INT_FAIL(CODA_RDWR_STATS);
- return(error);
- }
- /*
- * We get the vnode back locked by curthread in both Mach and
- * NetBSD. Needs unlocked
- */
- VOP_UNLOCK(cfvp, 0, ltd);
- }
- else {
- opened_internally = 1;
- MARK_INT_GEN(CODA_OPEN_STATS);
- error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE),
- cred, td);
-printf("coda_rdwr: Internally Opening %p\n", vp);
- if (error) {
- printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
- return (error);
- }
- if (vp->v_type == VREG) {
- error = vfs_object_create(vp, td, cred);
- if (error != 0) {
- printf("coda_rdwr: vfs_object_create() returns %d\n", error);
- vput(vp);
- }
- }
- if (error) {
- MARK_INT_FAIL(CODA_RDWR_STATS);
- return(error);
- }
- cfvp = cp->c_ovp;
- }
- }
-
- /* Have UFS handle the call. */
- CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
- cp->c_fid.Volume, cp->c_fid.Vnode,
- cp->c_fid.Unique, vrefcnt(CTOV(cp)))); )
-
- if (rw == UIO_READ) {
- error = VOP_READ(cfvp, uiop, ioflag, cred);
- } else {
- error = VOP_WRITE(cfvp, uiop, ioflag, cred);
- /* ufs_write updates the vnode_pager_setsize for the vnode/object */
-
- { struct vattr attr;
-
- if (VOP_GETATTR(cfvp, &attr, cred, td) == 0) {
- vnode_pager_setsize(vp, attr.va_size);
- }
- }
- }
-
- if (error)
- MARK_INT_FAIL(CODA_RDWR_STATS);
- else
- MARK_INT_SAT(CODA_RDWR_STATS);
-
- /* Do an internal close if necessary. */
- if (opened_internally) {
- MARK_INT_GEN(CODA_CLOSE_STATS);
- (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, td);
- }
-
- /* Invalidate cached attributes if writing. */
- if (rw == UIO_WRITE)
- cp->c_flags &= ~C_VATTR;
- return(error);
-}
-
-
-
-int
-coda_ioctl(v)
- void *v;
-{
-/* true args */
- struct vop_ioctl_args *ap = v;
- struct vnode *vp = ap->a_vp;
- int com = ap->a_command;
- caddr_t data = ap->a_data;
- int flag = ap->a_fflag;
- struct ucred *cred = ap->a_cred;
- struct thread *td = ap->a_td;
-/* locals */
- int error;
- struct vnode *tvp;
- struct nameidata ndp;
- struct PioctlData *iap = (struct PioctlData *)data;
-
- MARK_ENTRY(CODA_IOCTL_STATS);
-
- CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
-
- /* Don't check for operation on a dying object, for ctlvp it
- shouldn't matter */
-
- /* Must be control object to succeed. */
- if (!IS_CTL_VP(vp)) {
- MARK_INT_FAIL(CODA_IOCTL_STATS);
- CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
- return (EOPNOTSUPP);
- }
- /* Look up the pathname. */
-
- /* Should we use the name cache here? It would get it from
- lookupname sooner or later anyway, right? */
-
- NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE, iap->path, td);
- error = namei(&ndp);
- tvp = ndp.ni_vp;
-
- if (error) {
- MARK_INT_FAIL(CODA_IOCTL_STATS);
- CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
- error));)
- return(error);
- }
-
- /*
- * Make sure this is a coda style cnode, but it may be a
- * different vfsp
- */
- if (tvp->v_op != coda_vnodeop_p) {
- vrele(tvp);
- NDFREE(&ndp, NDF_ONLY_PNBUF);
- MARK_INT_FAIL(CODA_IOCTL_STATS);
- CODADEBUG(CODA_IOCTL,
- myprintf(("coda_ioctl error: %s not a coda object\n",
- iap->path));)
- return(EINVAL);
- }
-
- if (iap->vi.in_size > VC_MAXDATASIZE) {
- NDFREE(&ndp, 0);
- return(EINVAL);
- }
- error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td->td_proc);
-
- if (error)
- MARK_INT_FAIL(CODA_IOCTL_STATS);
- else
- CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
-
- vrele(tvp);
- NDFREE(&ndp, NDF_ONLY_PNBUF);
- return(error);
-}
-
-/*
- * To reduce the cost of a user-level venus;we cache attributes in
- * the kernel. Each cnode has storage allocated for an attribute. If
- * c_vattr is valid, return a reference to it. Otherwise, get the
- * attributes from venus and store them in the cnode. There is some
- * question if this method is a security leak. But I think that in
- * order to make this call, the user must have done a lookup and
- * opened the file, and therefore should already have access.
- */
-int
-coda_getattr(v)
- void *v;
-{
-/* true args */
- struct vop_getattr_args *ap = v;
- struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
- struct vattr *vap = ap->a_vap;
- struct ucred *cred = ap->a_cred;
- struct thread *td = ap->a_td;
-/* locals */
- int error;
-
- MARK_ENTRY(CODA_GETATTR_STATS);
-
- if (IS_UNMOUNTING(cp))
- return ENODEV;
-
- /* Check for getattr of control object. */
- if (IS_CTL_VP(vp)) {
- MARK_INT_FAIL(CODA_GETATTR_STATS);
- return(ENOENT);
- }
-
- /* Check to see if the attributes have already been cached */
- if (VALID_VATTR(cp)) {
- CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
- cp->c_fid.Volume,
- cp->c_fid.Vnode,
- cp->c_fid.Unique));});
- CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
- print_vattr(&cp->c_vattr); );
-
- *vap = cp->c_vattr;
- MARK_INT_SAT(CODA_GETATTR_STATS);
- return(0);
- }
-
- error = venus_getattr(vtomi(vp), &cp->c_fid, cred, td->td_proc, vap);
-
- if (!error) {
- CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
- cp->c_fid.Volume,
- cp->c_fid.Vnode,
- cp->c_fid.Unique,
- error)); )
-
- CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
- print_vattr(vap); );
-
- { int size = vap->va_size;
- struct vnode *convp = cp->c_ovp;
- if (convp != (struct vnode *)0) {
- vnode_pager_setsize(convp, size);
- }
- }
- /* If not open for write, store attributes in cnode */
- if ((cp->c_owrite == 0) && (coda_attr_cache)) {
- cp->c_vattr = *vap;
- cp->c_flags |= C_VATTR;
- }
-
- }
- return(error);
-}
-
-int
-coda_setattr(v)
- void *v;
-{
-/* true args */
- struct vop_setattr_args *ap = v;
- register struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
- register struct vattr *vap = ap->a_vap;
- struct ucred *cred = ap->a_cred;
- struct thread *td = ap->a_td;
-/* locals */
- int error;
-
- MARK_ENTRY(CODA_SETATTR_STATS);
-
- /* Check for setattr of control object. */
- if (IS_CTL_VP(vp)) {
- MARK_INT_FAIL(CODA_SETATTR_STATS);
- return(ENOENT);
- }
-
- if (codadebug & CODADBGMSK(CODA_SETATTR)) {
- print_vattr(vap);
- }
- error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td->td_proc);
-
- if (!error)
- cp->c_flags &= ~C_VATTR;
-
- { int size = vap->va_size;
- struct vnode *convp = cp->c_ovp;
- if (size != VNOVAL && convp != (struct vnode *)0) {
- vnode_pager_setsize(convp, size);
- }
- }
- CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
- return(error);
-}
-
-int
-coda_access(v)
- void *v;
-{
-/* true args */
- struct vop_access_args *ap = v;
- struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
- int mode = ap->a_mode;
- struct ucred *cred = ap->a_cred;
- struct thread *td = ap->a_td;
-/* locals */
- int error;
-
- MARK_ENTRY(CODA_ACCESS_STATS);
-
- /* Check for access of control object. Only read access is
- allowed on it. */
- if (IS_CTL_VP(vp)) {
- /* bogus hack - all will be marked as successes */
- MARK_INT_SAT(CODA_ACCESS_STATS);
- return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
- ? 0 : EACCES);
- }
-
- /*
- * if the file is a directory, and we are checking exec (eg lookup)
- * access, and the file is in the namecache, then the user must have
- * lookup access to it.
- */
- if (coda_access_cache) {
- if ((vp->v_type == VDIR) && (mode & VEXEC)) {
- if (coda_nc_lookup(cp, ".", 1, cred)) {
- MARK_INT_SAT(CODA_ACCESS_STATS);
- return(0); /* it was in the cache */
- }
- }
- }
-
- error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td->td_proc);
-
- return(error);
-}
-
-int
-coda_readlink(v)
- void *v;
-{
-/* true args */
- struct vop_readlink_args *ap = v;
- struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
- struct uio *uiop = ap->a_uio;
- struct ucred *cred = ap->a_cred;
- struct thread *td = ap->a_uio->uio_td;
-/* locals */
- int error;
- char *str;
- int len;
-
- MARK_ENTRY(CODA_READLINK_STATS);
-
- /* Check for readlink of control object. */
- if (IS_CTL_VP(vp)) {
- MARK_INT_FAIL(CODA_READLINK_STATS);
- return(ENOENT);
- }
-
- if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
- uiop->uio_rw = UIO_READ;
- error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
- if (error)
- MARK_INT_FAIL(CODA_READLINK_STATS);
- else
- MARK_INT_SAT(CODA_READLINK_STATS);
- return(error);
- }
-
- error = venus_readlink(vtomi(vp), &cp->c_fid, cred,
- td != NULL ? td->td_proc : NULL, &str, &len);
-
- if (!error) {
- uiop->uio_rw = UIO_READ;
- error = uiomove(str, len, uiop);
-
- if (coda_symlink_cache) {
- cp->c_symlink = str;
- cp->c_symlen = len;
- cp->c_flags |= C_SYMLINK;
- } else
- CODA_FREE(str, len);
- }
-
- CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
- return(error);
-}
-
-int
-coda_fsync(v)
- void *v;
-{
-/* true args */
- struct vop_fsync_args *ap = v;
- struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
- struct ucred *cred = ap->a_cred;
- struct thread *td = ap->a_td;
-/* locals */
- struct vnode *convp = cp->c_ovp;
- int error;
-
- MARK_ENTRY(CODA_FSYNC_STATS);
-
- /* Check for fsync on an unmounting object */
- /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
- * after an unmount has been initiated. This is a Bad Thing,
- * which we have to avoid. Not a legitimate failure for stats.
- */
- if (IS_UNMOUNTING(cp)) {
- return(ENODEV);
- }
-
- /* Check for fsync of control object. */
- if (IS_CTL_VP(vp)) {
- MARK_INT_SAT(CODA_FSYNC_STATS);
- return(0);
- }
-
- if (convp)
- VOP_FSYNC(convp, cred, MNT_WAIT, td);
-
- /*
- * We see fsyncs with usecount == 1 then usecount == 0.
- * For now we ignore them.
- */
- /*
- VI_LOCK(vp);
- if (!vp->v_usecount) {
- printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n",
- vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
- }
- VI_UNLOCK(vp);
- */
-
- /*
- * We can expect fsync on any vnode at all if venus is pruging it.
- * Venus can't very well answer the fsync request, now can it?
- * Hopefully, it won't have to, because hopefully, venus preserves
- * the (possibly untrue) invariant that it never purges an open
- * vnode. Hopefully.
- */
- if (cp->c_flags & C_PURGING) {
- return(0);
- }
-
- /* needs research */
- return 0;
- error = venus_fsync(vtomi(vp), &cp->c_fid, cred, td->td_proc);
-
- CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
- return(error);
-}
-
-int
-coda_inactive(v)
- void *v;
-{
- /* XXX - at the moment, inactive doesn't look at cred, and doesn't
- have a proc pointer. Oops. */
-/* true args */
- struct vop_inactive_args *ap = v;
- struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
- struct ucred *cred __attribute__((unused)) = NULL;
- struct thread *td __attribute__((unused)) = curthread;
-/* upcall decl */
-/* locals */
-
- /* We don't need to send inactive to venus - DCS */
- MARK_ENTRY(CODA_INACTIVE_STATS);
-
- if (IS_CTL_VP(vp)) {
- MARK_INT_SAT(CODA_INACTIVE_STATS);
- return 0;
- }
-
- CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
- cp->c_fid.Volume, cp->c_fid.Vnode,
- cp->c_fid.Unique, vp->v_mount));)
-
- /* If an array has been allocated to hold the symlink, deallocate it */
- if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
- if (cp->c_symlink == NULL)
- panic("coda_inactive: null symlink pointer in cnode");
-
- CODA_FREE(cp->c_symlink, cp->c_symlen);
- cp->c_flags &= ~C_SYMLINK;
- cp->c_symlen = 0;
- }
-
- /* Remove it from the table so it can't be found. */
- coda_unsave(cp);
- if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
- myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
- panic("badness in coda_inactive\n");
- }
-
- if (IS_UNMOUNTING(cp)) {
-#ifdef DEBUG
- printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vrefcnt(vp), vp, cp);
- if (cp->c_ovp != NULL)
- printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
- vrefcnt(vp), vp, cp);
-#endif
- lockmgr(&cp->c_lock, LK_RELEASE, &vp->v_interlock, td);
- } else {
-#ifdef OLD_DIAGNOSTIC
- if (vrefcnt(CTOV(cp))) {
- panic("coda_inactive: nonzero reference count");
- }
- if (cp->c_ovp != NULL) {
- panic("coda_inactive: cp->ovp != NULL");
- }
-#endif
- VOP_UNLOCK(vp, 0, td);
- vgone(vp);
- }
-
- MARK_INT_SAT(CODA_INACTIVE_STATS);
- return(0);
-}
-
-/*
- * Remote filesystem operations having to do with directory manipulation.
- */
-
-/*
- * It appears that in NetBSD, lookup is supposed to return the vnode locked
- */
-int
-coda_lookup(v)
- void *v;
-{
-/* true args */
- struct vop_lookup_args *ap = v;
- struct vnode *dvp = ap->a_dvp;
- struct cnode *dcp = VTOC(dvp);
- struct vnode **vpp = ap->a_vpp;
- /*
- * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
- * of the string to xlate, and that we must try to get at least
- * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
- * could be wrong.
- */
- struct componentname *cnp = ap->a_cnp;
- struct ucred *cred = cnp->cn_cred;
- struct thread *td = cnp->cn_thread;
-/* locals */
- struct cnode *cp;
- const char *nm = cnp->cn_nameptr;
- int len = cnp->cn_namelen;
- ViceFid VFid;
- int vtype;
- int error = 0;
-
- MARK_ENTRY(CODA_LOOKUP_STATS);
-
- CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
- nm, dcp->c_fid.Volume,
- dcp->c_fid.Vnode, dcp->c_fid.Unique)););
-
- /* Check for lookup of control object. */
- if (IS_CTL_NAME(dvp, nm, len)) {
- *vpp = coda_ctlvp;
- vref(*vpp);
- MARK_INT_SAT(CODA_LOOKUP_STATS);
- goto exit;
- }
-
- if (len+1 > CODA_MAXNAMLEN) {
- MARK_INT_FAIL(CODA_LOOKUP_STATS);
- CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
- dcp->c_fid.Volume, dcp->c_fid.Vnode,
- dcp->c_fid.Unique, nm)););
- *vpp = (struct vnode *)0;
- error = EINVAL;
- goto exit;
- }
- /* First try to look the file up in the cfs name cache */
- /* lock the parent vnode? */
- cp = coda_nc_lookup(dcp, nm, len, cred);
- if (cp) {
- *vpp = CTOV(cp);
- vref(*vpp);
- CODADEBUG(CODA_LOOKUP,
- myprintf(("lookup result %d vpp %p\n",error,*vpp));)
- } else {
-
- /* The name wasn't cached, so we need to contact Venus */
- error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td->td_proc, &VFid, &vtype);
-
- if (error) {
- MARK_INT_FAIL(CODA_LOOKUP_STATS);
- CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
- dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
- *vpp = (struct vnode *)0;
- } else {
- MARK_INT_SAT(CODA_LOOKUP_STATS);
- CODADEBUG(CODA_LOOKUP,
- myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
- VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
- error)); )
-
- cp = make_coda_node(&VFid, dvp->v_mount, vtype);
- *vpp = CTOV(cp);
-
- /* enter the new vnode in the Name Cache only if the top bit isn't set */
- /* And don't enter a new vnode for an invalid one! */
- if (!(vtype & CODA_NOCACHE))
- coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
- }
- }
-
- exit:
- /*
- * If we are creating, and this was the last name to be looked up,
- * and the error was ENOENT, then there really shouldn't be an
- * error and we can make the leaf NULL and return success. Since
- * this is supposed to work under Mach as well as NetBSD, we're
- * leaving this fn wrapped. We also must tell lookup/namei that
- * we need to save the last component of the name. (Create will
- * have to free the name buffer later...lucky us...)
- */
- if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME))
- && (cnp->cn_flags & ISLASTCN)
- && (error == ENOENT))
- {
- error = EJUSTRETURN;
- cnp->cn_flags |= SAVENAME;
- *ap->a_vpp = NULL;
- }
-
- /*
- * If we are removing, and we are at the last element, and we
- * found it, then we need to keep the name around so that the
- * removal will go ahead as planned. Unfortunately, this will
- * probably also lock the to-be-removed vnode, which may or may
- * not be a good idea. I'll have to look at the bits of
- * coda_remove to make sure. We'll only save the name if we did in
- * fact find the name, otherwise coda_remove won't have a chance
- * to free the pathname.
- */
- if ((cnp->cn_nameiop == DELETE)
- && (cnp->cn_flags & ISLASTCN)
- && !error)
- {
- cnp->cn_flags |= SAVENAME;
- }
-
- /*
- * If the lookup went well, we need to (potentially?) unlock the
- * parent, and lock the child. We are only responsible for
- * checking to see if the parent is supposed to be unlocked before
- * we return. We must always lock the child (provided there is
- * one, and (the parent isn't locked or it isn't the same as the
- * parent.) Simple, huh? We can never leave the parent locked unless
- * we are ISLASTCN
- */
- if (!error || (error == EJUSTRETURN)) {
- if (!(cnp->cn_flags & LOCKPARENT) || !(cnp->cn_flags & ISLASTCN)) {
- if ((error = VOP_UNLOCK(dvp, 0, td))) {
- return error;
- }
- /*
- * The parent is unlocked. As long as there is a child,
- * lock it without bothering to check anything else.
- */
- if (*ap->a_vpp) {
- if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
- printf("coda_lookup: ");
- panic("unlocked parent but couldn't lock child");
- }
- }
- } else {
- /* The parent is locked, and may be the same as the child */
- if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
- /* Different, go ahead and lock it. */
- if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
- printf("coda_lookup: ");
- panic("unlocked parent but couldn't lock child");
- }
- }
- }
- } else {
- /* If the lookup failed, we need to ensure that the leaf is NULL */
- /* Don't change any locking? */
- *ap->a_vpp = NULL;
- }
- return(error);
-}
-
-/*ARGSUSED*/
-int
-coda_create(v)
- void *v;
-{
-/* true args */
- struct vop_create_args *ap = v;
- struct vnode *dvp = ap->a_dvp;
- struct cnode *dcp = VTOC(dvp);
- struct vattr *va = ap->a_vap;
- int exclusive = 1;
- int mode = ap->a_vap->va_mode;
- struct vnode **vpp = ap->a_vpp;
- struct componentname *cnp = ap->a_cnp;
- struct ucred *cred = cnp->cn_cred;
- struct thread *td = cnp->cn_thread;
-/* locals */
- int error;
- struct cnode *cp;
- const char *nm = cnp->cn_nameptr;
- int len = cnp->cn_namelen;
- ViceFid VFid;
- struct vattr attr;
-
- MARK_ENTRY(CODA_CREATE_STATS);
-
- /* All creates are exclusive XXX */
- /* I'm assuming the 'mode' argument is the file mode bits XXX */
-
- /* Check for create of control object. */
- if (IS_CTL_NAME(dvp, nm, len)) {
- *vpp = (struct vnode *)0;
- MARK_INT_FAIL(CODA_CREATE_STATS);
- return(EACCES);
- }
-
- error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td->td_proc, &VFid, &attr);
-
- if (!error) {
-
- /* If this is an exclusive create, panic if the file already exists. */
- /* Venus should have detected the file and reported EEXIST. */
-
- if ((exclusive == 1) &&
- (coda_find(&VFid) != NULL))
- panic("cnode existed for newly created file!");
-
- cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
- *vpp = CTOV(cp);
-
- /* Update va to reflect the new attributes. */
- (*va) = attr;
-
- /* Update the attribute cache and mark it as valid */
- if (coda_attr_cache) {
- VTOC(*vpp)->c_vattr = attr;
- VTOC(*vpp)->c_flags |= C_VATTR;
- }
-
- /* Invalidate the parent's attr cache, the modification time has changed */
- VTOC(dvp)->c_flags &= ~C_VATTR;
-
- /* enter the new vnode in the Name Cache */
- coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
-
- CODADEBUG(CODA_CREATE,
- myprintf(("create: (%lx.%lx.%lx), result %d\n",
- VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
- } else {
- *vpp = (struct vnode *)0;
- CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
- }
-
- if (!error) {
- if (cnp->cn_flags & LOCKLEAF) {
- if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
- printf("coda_create: ");
- panic("unlocked parent but couldn't lock child");
- }
- }
-#ifdef OLD_DIAGNOSTIC
- else {
- printf("coda_create: LOCKLEAF not set!\n");
- }
-#endif
- }
- return(error);
-}
-
-int
-coda_remove(v)
- void *v;
-{
-/* true args */
- struct vop_remove_args *ap = v;
- struct vnode *dvp = ap->a_dvp;
- struct cnode *cp = VTOC(dvp);
- struct componentname *cnp = ap->a_cnp;
- struct ucred *cred = cnp->cn_cred;
- struct thread *td = cnp->cn_thread;
-/* locals */
- int error;
- const char *nm = cnp->cn_nameptr;
- int len = cnp->cn_namelen;
- struct cnode *tp;
-
- MARK_ENTRY(CODA_REMOVE_STATS);
-
- CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
- nm, cp->c_fid.Volume, cp->c_fid.Vnode,
- cp->c_fid.Unique)););
-
- /* Remove the file's entry from the CODA Name Cache */
- /* We're being conservative here, it might be that this person
- * doesn't really have sufficient access to delete the file
- * but we feel zapping the entry won't really hurt anyone -- dcs
- */
- /* I'm gonna go out on a limb here. If a file and a hardlink to it
- * exist, and one is removed, the link count on the other will be
- * off by 1. We could either invalidate the attrs if cached, or
- * fix them. I'll try to fix them. DCS 11/8/94
- */
- tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
- if (tp) {
- if (VALID_VATTR(tp)) { /* If attrs are cached */
- if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
- tp->c_vattr.va_nlink--;
- }
- }
-
- coda_nc_zapfile(VTOC(dvp), nm, len);
- /* No need to flush it if it doesn't exist! */
- }
- /* Invalidate the parent's attr cache, the modification time has changed */
- VTOC(dvp)->c_flags &= ~C_VATTR;
-
- /* Check for remove of control object. */
- if (IS_CTL_NAME(dvp, nm, len)) {
- MARK_INT_FAIL(CODA_REMOVE_STATS);
- return(ENOENT);
- }
-
- error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td->td_proc);
-
- CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
-
- return(error);
-}
-
-int
-coda_link(v)
- void *v;
-{
-/* true args */
- struct vop_link_args *ap = v;
- struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
- struct vnode *tdvp = ap->a_tdvp;
- struct cnode *tdcp = VTOC(tdvp);
- struct componentname *cnp = ap->a_cnp;
- struct ucred *cred = cnp->cn_cred;
- struct thread *td = cnp->cn_thread;
-/* locals */
- int error;
- const char *nm = cnp->cn_nameptr;
- int len = cnp->cn_namelen;
-
- MARK_ENTRY(CODA_LINK_STATS);
-
- if (codadebug & CODADBGMSK(CODA_LINK)) {
-
- myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
- cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
- myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
- tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
-
- }
- if (codadebug & CODADBGMSK(CODA_LINK)) {
- myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
- cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
- myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
- tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
-
- }
-
- /* Check for link to/from control object. */
- if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
- MARK_INT_FAIL(CODA_LINK_STATS);
- return(EACCES);
- }
-
- error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td->td_proc);
-
- /* Invalidate the parent's attr cache, the modification time has changed */
- VTOC(tdvp)->c_flags &= ~C_VATTR;
- VTOC(vp)->c_flags &= ~C_VATTR;
-
- CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
-
- return(error);
-}
-
-int
-coda_rename(v)
- void *v;
-{
-/* true args */
- struct vop_rename_args *ap = v;
- struct vnode *odvp = ap->a_fdvp;
- struct cnode *odcp = VTOC(odvp);
- struct componentname *fcnp = ap->a_fcnp;
- struct vnode *ndvp = ap->a_tdvp;
- struct cnode *ndcp = VTOC(ndvp);
- struct componentname *tcnp = ap->a_tcnp;
- struct ucred *cred = fcnp->cn_cred;
- struct thread *td = fcnp->cn_thread;
-/* true args */
- int error;
- const char *fnm = fcnp->cn_nameptr;
- int flen = fcnp->cn_namelen;
- const char *tnm = tcnp->cn_nameptr;
- int tlen = tcnp->cn_namelen;
-
- MARK_ENTRY(CODA_RENAME_STATS);
-
- /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
- This could be Bad. XXX */
-#ifdef OLD_DIAGNOSTIC
- if ((fcnp->cn_cred != tcnp->cn_cred)
- || (fcnp->cn_thread != tcnp->cn_thread))
- {
- panic("coda_rename: component names don't agree");
- }
-#endif
-
- /* Check for rename involving control object. */
- if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
- MARK_INT_FAIL(CODA_RENAME_STATS);
- return(EACCES);
- }
-
- /* Problem with moving directories -- need to flush entry for .. */
- if (odvp != ndvp) {
- struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
- if (ovcp) {
- struct vnode *ovp = CTOV(ovcp);
- if ((ovp) &&
- (ovp->v_type == VDIR)) /* If it's a directory */
- coda_nc_zapfile(VTOC(ovp),"..", 2);
- }
- }
-
- /* Remove the entries for both source and target files */
- coda_nc_zapfile(VTOC(odvp), fnm, flen);
- coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
-
- /* Invalidate the parent's attr cache, the modification time has changed */
- VTOC(odvp)->c_flags &= ~C_VATTR;
- VTOC(ndvp)->c_flags &= ~C_VATTR;
-
- if (flen+1 > CODA_MAXNAMLEN) {
- MARK_INT_FAIL(CODA_RENAME_STATS);
- error = EINVAL;
- goto exit;
- }
-
- if (tlen+1 > CODA_MAXNAMLEN) {
- MARK_INT_FAIL(CODA_RENAME_STATS);
- error = EINVAL;
- goto exit;
- }
-
- error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td->td_proc);
-
- exit:
- CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
- /* XXX - do we need to call cache pureg on the moved vnode? */
- cache_purge(ap->a_fvp);
-
- /* It seems to be incumbent on us to drop locks on all four vnodes */
- /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
-
- vrele(ap->a_fvp);
- vrele(odvp);
-
- if (ap->a_tvp) {
- if (ap->a_tvp == ndvp) {
- vrele(ap->a_tvp);
- } else {
- vput(ap->a_tvp);
- }
- }
-
- vput(ndvp);
- return(error);
-}
-
-int
-coda_mkdir(v)
- void *v;
-{
-/* true args */
- struct vop_mkdir_args *ap = v;
- struct vnode *dvp = ap->a_dvp;
- struct cnode *dcp = VTOC(dvp);
- struct componentname *cnp = ap->a_cnp;
- register struct vattr *va = ap->a_vap;
- struct vnode **vpp = ap->a_vpp;
- struct ucred *cred = cnp->cn_cred;
- struct thread *td = cnp->cn_thread;
-/* locals */
- int error;
- const char *nm = cnp->cn_nameptr;
- int len = cnp->cn_namelen;
- struct cnode *cp;
- ViceFid VFid;
- struct vattr ova;
-
- MARK_ENTRY(CODA_MKDIR_STATS);
-
- /* Check for mkdir of target object. */
- if (IS_CTL_NAME(dvp, nm, len)) {
- *vpp = (struct vnode *)0;
- MARK_INT_FAIL(CODA_MKDIR_STATS);
- return(EACCES);
- }
-
- if (len+1 > CODA_MAXNAMLEN) {
- *vpp = (struct vnode *)0;
- MARK_INT_FAIL(CODA_MKDIR_STATS);
- return(EACCES);
- }
-
- error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td->td_proc, &VFid, &ova);
-
- if (!error) {
- if (coda_find(&VFid) != NULL)
- panic("cnode existed for newly created directory!");
-
-
- cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
- *vpp = CTOV(cp);
-
- /* enter the new vnode in the Name Cache */
- coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
-
- /* as a side effect, enter "." and ".." for the directory */
- coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
- coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
-
- if (coda_attr_cache) {
- VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
- VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
- }
-
- /* Invalidate the parent's attr cache, the modification time has changed */
- VTOC(dvp)->c_flags &= ~C_VATTR;
-
- CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
- VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
- } else {
- *vpp = (struct vnode *)0;
- CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
- }
-
- return(error);
-}
-
-int
-coda_rmdir(v)
- void *v;
-{
-/* true args */
- struct vop_rmdir_args *ap = v;
- struct vnode *dvp = ap->a_dvp;
- struct cnode *dcp = VTOC(dvp);
- struct componentname *cnp = ap->a_cnp;
- struct ucred *cred = cnp->cn_cred;
- struct thread *td = cnp->cn_thread;
-/* true args */
- int error;
- const char *nm = cnp->cn_nameptr;
- int len = cnp->cn_namelen;
- struct cnode *cp;
-
- MARK_ENTRY(CODA_RMDIR_STATS);
-
- /* Check for rmdir of control object. */
- if (IS_CTL_NAME(dvp, nm, len)) {
- MARK_INT_FAIL(CODA_RMDIR_STATS);
- return(ENOENT);
- }
-
- /* We're being conservative here, it might be that this person
- * doesn't really have sufficient access to delete the file
- * but we feel zapping the entry won't really hurt anyone -- dcs
- */
- /*
- * As a side effect of the rmdir, remove any entries for children of
- * the directory, especially "." and "..".
- */
- cp = coda_nc_lookup(dcp, nm, len, cred);
- if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
-
- /* Remove the file's entry from the CODA Name Cache */
- coda_nc_zapfile(dcp, nm, len);
-
- /* Invalidate the parent's attr cache, the modification time has changed */
- dcp->c_flags &= ~C_VATTR;
-
- error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td->td_proc);
-
- CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
-
- return(error);
-}
-
-int
-coda_symlink(v)
- void *v;
-{
-/* true args */
- struct vop_symlink_args *ap = v;
- struct vnode *tdvp = ap->a_dvp;
- struct cnode *tdcp = VTOC(tdvp);
- struct componentname *cnp = ap->a_cnp;
- struct vattr *tva = ap->a_vap;
- char *path = ap->a_target;
- struct ucred *cred = cnp->cn_cred;
- struct thread *td = cnp->cn_thread;
- struct vnode **vpp = ap->a_vpp;
-/* locals */
- int error;
- /*
- * XXX I'm assuming the following things about coda_symlink's
- * arguments:
- * t(foo) is the new name/parent/etc being created.
- * lname is the contents of the new symlink.
- */
- char *nm = cnp->cn_nameptr;
- int len = cnp->cn_namelen;
- int plen = strlen(path);
-
- /*
- * Here's the strategy for the moment: perform the symlink, then
- * do a lookup to grab the resulting vnode. I know this requires
- * two communications with Venus for a new sybolic link, but
- * that's the way the ball bounces. I don't yet want to change
- * the way the Mach symlink works. When Mach support is
- * deprecated, we should change symlink so that the common case
- * returns the resultant vnode in a vpp argument.
- */
-
- MARK_ENTRY(CODA_SYMLINK_STATS);
-
- /* Check for symlink of control object. */
- if (IS_CTL_NAME(tdvp, nm, len)) {
- MARK_INT_FAIL(CODA_SYMLINK_STATS);
- return(EACCES);
- }
-
- if (plen+1 > CODA_MAXPATHLEN) {
- MARK_INT_FAIL(CODA_SYMLINK_STATS);
- return(EINVAL);
- }
-
- if (len+1 > CODA_MAXNAMLEN) {
- MARK_INT_FAIL(CODA_SYMLINK_STATS);
- error = EINVAL;
- goto exit;
- }
-
- error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td->td_proc);
-
- /* Invalidate the parent's attr cache, the modification time has changed */
- tdcp->c_flags &= ~C_VATTR;
-
- if (error == 0)
- error = VOP_LOOKUP(tdvp, vpp, cnp);
-
- exit:
- CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
- return(error);
-}
-
-/*
- * Read directory entries.
- */
-int
-coda_readdir(v)
- void *v;
-{
-/* true args */
- struct vop_readdir_args *ap = v;
- struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
- register struct uio *uiop = ap->a_uio;
- struct ucred *cred = ap->a_cred;
- int *eofflag = ap->a_eofflag;
- u_long **cookies = ap->a_cookies;
- int *ncookies = ap->a_ncookies;
- struct thread *td = ap->a_uio->uio_td;
-/* upcall decl */
-/* locals */
- int error = 0;
-
- MARK_ENTRY(CODA_READDIR_STATS);
-
- CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
- (void *)uiop->uio_iov->iov_base,
- uiop->uio_resid,
- (long long)uiop->uio_offset,
- uiop->uio_segflg)); )
-
- /* Check for readdir of control object. */
- if (IS_CTL_VP(vp)) {
- MARK_INT_FAIL(CODA_READDIR_STATS);
- return(ENOENT);
- }
-
- {
- /* If directory is not already open do an "internal open" on it. */
- int opened_internally = 0;
- if (cp->c_ovp == NULL) {
- opened_internally = 1;
- MARK_INT_GEN(CODA_OPEN_STATS);
- error = VOP_OPEN(vp, FREAD, cred, td);
-printf("coda_readdir: Internally Opening %p\n", vp);
- if (error) {
- printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
- return (error);
- }
- if (vp->v_type == VREG) {
- error = vfs_object_create(vp, td, cred);
- if (error != 0) {
- printf("coda_readdir: vfs_object_create() returns %d\n", error);
- vput(vp);
- }
- }
- if (error) return(error);
- }
-
- /* Have UFS handle the call. */
- CODADEBUG(CODA_READDIR, myprintf(("indirect readdir: fid = (%lx.%lx.%lx), refcnt = %d\n",cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique, vrefcnt(vp))); )
- error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
- cookies);
-
- if (error)
- MARK_INT_FAIL(CODA_READDIR_STATS);
- else
- MARK_INT_SAT(CODA_READDIR_STATS);
-
- /* Do an "internal close" if necessary. */
- if (opened_internally) {
- MARK_INT_GEN(CODA_CLOSE_STATS);
- (void)VOP_CLOSE(vp, FREAD, cred, td);
- }
- }
-
- return(error);
-}
-
-/*
- * Convert from filesystem blocks to device blocks
- */
-int
-coda_bmap(v)
- void *v;
-{
- /* XXX on the global proc */
-/* true args */
- struct vop_bmap_args *ap = v;
- struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */
- daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */
- struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */
- daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */
- struct thread *td __attribute__((unused)) = curthread;
-/* upcall decl */
-/* locals */
-
- int ret = 0;
- struct cnode *cp;
-
- cp = VTOC(vp);
- if (cp->c_ovp) {
- return EINVAL;
- ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
-#if 0
- printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %lld, ap->a_runp %p, ap->a_runb %p) = %d\n",
- cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
-#endif
- return ret;
- } else {
-#if 0
- printf("coda_bmap: no container\n");
-#endif
- return(EOPNOTSUPP);
- }
-}
-
-/*
- * I don't think the following two things are used anywhere, so I've
- * commented them out
- *
- * struct buf *async_bufhead;
- * int async_daemon_count;
- */
-int
-coda_strategy(v)
- void *v;
-{
-/* true args */
- struct vop_strategy_args *ap = v;
- register struct buf *bp __attribute__((unused)) = ap->a_bp;
- struct thread *td __attribute__((unused)) = curthread;
-/* upcall decl */
-/* locals */
-
- printf("coda_strategy: called ???\n");
- return(EOPNOTSUPP);
-}
-
-int
-coda_reclaim(v)
- void *v;
-{
-/* true args */
- struct vop_reclaim_args *ap = v;
- struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
-/* upcall decl */
-/* locals */
-
-/*
- * Forced unmount/flush will let vnodes with non zero use be destroyed!
- */
- ENTRY;
-
- if (IS_UNMOUNTING(cp)) {
-#ifdef DEBUG
- if (VTOC(vp)->c_ovp) {
- if (IS_UNMOUNTING(cp))
- printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
- }
-#endif
- } else {
-#ifdef OLD_DIAGNOSTIC
- if (vrefcnt(vp) != 0)
- print("coda_reclaim: pushing active %p\n", vp);
- if (VTOC(vp)->c_ovp) {
- panic("coda_reclaim: c_ovp not void");
- }
-#endif
- }
- cache_purge(vp);
- lockdestroy(&(VTOC(vp)->c_lock));
- coda_free(VTOC(vp));
- VTOC(vp) = NULL;
- return (0);
-}
-
-int
-coda_lock(v)
- void *v;
-{
-/* true args */
- struct vop_lock_args *ap = v;
- struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
- struct thread *td = ap->a_td;
-/* upcall decl */
-/* locals */
-
- ENTRY;
-
- if (coda_lockdebug) {
- myprintf(("Attempting lock on %lx.%lx.%lx\n",
- cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
- }
-
-#ifndef DEBUG_LOCKS
- return (lockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td));
-#else
- return (debuglockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td,
- "coda_lock", vp->filename, vp->line));
-#endif
-}
-
-int
-coda_unlock(v)
- void *v;
-{
-/* true args */
- struct vop_unlock_args *ap = v;
- struct vnode *vp = ap->a_vp;
- struct cnode *cp = VTOC(vp);
- struct thread *td = ap->a_td;
-/* upcall decl */
-/* locals */
-
- ENTRY;
- if (coda_lockdebug) {
- myprintf(("Attempting unlock on %lx.%lx.%lx\n",
- cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
- }
-
- return (lockmgr(&cp->c_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, td));
-}
-
-int
-coda_islocked(v)
- void *v;
-{
-/* true args */
- struct vop_islocked_args *ap = v;
- struct cnode *cp = VTOC(ap->a_vp);
- ENTRY;
-
- return (lockstatus(&cp->c_lock, ap->a_td));
-}
-
-/* How one looks up a vnode given a device/inode pair: */
-int
-coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
-{
- /* This is like VFS_VGET() or igetinode()! */
- int error;
- struct mount *mp;
-
- if (!(mp = devtomp(dev))) {
- myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
- (u_long)dev2udev(dev)));
- return(ENXIO);
- }
-
- /* XXX - ensure that nonzero-return means failure */
- error = VFS_VGET(mp,ino,LK_EXCLUSIVE,vpp);
- if (error) {
- myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n",
- (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
- return(ENOENT);
- }
- return(0);
-}
-
-void
-print_vattr( attr )
- struct vattr *attr;
-{
- char *typestr;
-
- switch (attr->va_type) {
- case VNON:
- typestr = "VNON";
- break;
- case VREG:
- typestr = "VREG";
- break;
- case VDIR:
- typestr = "VDIR";
- break;
- case VBLK:
- typestr = "VBLK";
- break;
- case VCHR:
- typestr = "VCHR";
- break;
- case VLNK:
- typestr = "VLNK";
- break;
- case VSOCK:
- typestr = "VSCK";
- break;
- case VFIFO:
- typestr = "VFFO";
- break;
- case VBAD:
- typestr = "VBAD";
- break;
- default:
- typestr = "????";
- break;
- }
-
-
- myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
- typestr, (int)attr->va_mode, (int)attr->va_uid,
- (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
-
- myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
- (int)attr->va_fileid, (int)attr->va_nlink,
- (int)attr->va_size,
- (int)attr->va_blocksize,(int)attr->va_bytes));
- myprintf((" gen %ld flags %ld vaflags %d\n",
- attr->va_gen, attr->va_flags, attr->va_vaflags));
- myprintf((" atime sec %d nsec %d\n",
- (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
- myprintf((" mtime sec %d nsec %d\n",
- (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
- myprintf((" ctime sec %d nsec %d\n",
- (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
-}
-
-/* How to print a ucred */
-void
-print_cred(cred)
- struct ucred *cred;
-{
-
- int i;
-
- myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
-
- for (i=0; i < cred->cr_ngroups; i++)
- myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
- myprintf(("\n"));
-
-}
-
-/*
- * Return a vnode for the given fid.
- * If no cnode exists for this fid create one and put it
- * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
- * this fid is already in the table return it (ref count is
- * incremented by coda_find. The cnode will be flushed from the
- * table when coda_inactive calls coda_unsave.
- */
-struct cnode *
-make_coda_node(fid, vfsp, type)
- ViceFid *fid; struct mount *vfsp; short type;
-{
- struct cnode *cp;
- int err;
-
- if ((cp = coda_find(fid)) == NULL) {
- struct vnode *vp;
-
- cp = coda_alloc();
- lockinit(&cp->c_lock, PINOD, "cnode", 0, 0);
- cp->c_fid = *fid;
-
- err = getnewvnode("coda", vfsp, coda_vnodeop_p, &vp);
- if (err) {
- panic("coda: getnewvnode returned error %d\n", err);
- }
- vp->v_data = cp;
- vp->v_type = type;
- cp->c_vnode = vp;
- coda_save(cp);
-
- } else {
- vref(CTOV(cp));
- }
-
- return cp;
-}
-
-int
-coda_pathconf(v)
- void *v;
-{
- struct vop_pathconf_args *ap;
- int error;
- register_t *retval;
-
- ap = v;
- retval = ap->a_retval;
- error = 0;
-
- switch (ap->a_name) {
- case _PC_NAME_MAX:
- *retval = CODA_MAXNAMLEN;
- break;
- case _PC_PATH_MAX:
- *retval = CODA_MAXPATHLEN;
- break;
- default:
- error = vop_stdpathconf(ap);
- break;
- }
-
- return (error);
-}
diff --git a/sys/fs/coda/coda_vnops.h b/sys/fs/coda/coda_vnops.h
deleted file mode 100644
index 8a3184b83c99..000000000000
--- a/sys/fs/coda/coda_vnops.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- *
- * Coda: an Experimental Distributed File System
- * Release 3.1
- *
- * Copyright (c) 1987-1998 Carnegie Mellon University
- * All Rights Reserved
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation, and
- * that credit is given to Carnegie Mellon University in all documents
- * and publicity pertaining to direct or indirect use of this code or its
- * derivatives.
- *
- * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
- * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
- * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
- * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
- * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
- * ANY DERIVATIVE WORK.
- *
- * Carnegie Mellon encourages users of this software to return any
- * improvements or extensions that they make, and to grant Carnegie
- * Mellon the rights to redistribute these changes without encumbrance.
- *
- * @(#) src/sys/coda/coda_vnops.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
- * $FreeBSD$
- *
- */
-
-/*
- * Mach Operating System
- * Copyright (c) 1990 Carnegie-Mellon University
- * Copyright (c) 1989 Carnegie-Mellon University
- * All rights reserved. The CMU software License Agreement specifies
- * the terms and conditions for use and redistribution.
- */
-
-/*
- * This code was written for the Coda filesystem at Carnegie Mellon
- * University. Contributers include David Steere, James Kistler, and
- * M. Satyanarayanan.
- */
-
-
-/* NetBSD interfaces to the vnodeops */
-int coda_open(void *);
-int coda_close(void *);
-int coda_read(void *);
-int coda_write(void *);
-int coda_ioctl(void *);
-/* 1.3 int cfs_select(void *);*/
-int coda_getattr(void *);
-int coda_setattr(void *);
-int coda_access(void *);
-int coda_abortop(void *);
-int coda_readlink(void *);
-int coda_fsync(void *);
-int coda_inactive(void *);
-int coda_lookup(void *);
-int coda_create(void *);
-int coda_remove(void *);
-int coda_link(void *);
-int coda_rename(void *);
-int coda_mkdir(void *);
-int coda_rmdir(void *);
-int coda_symlink(void *);
-int coda_readdir(void *);
-int coda_bmap(void *);
-int coda_strategy(void *);
-int coda_reclaim(void *);
-int coda_lock(void *);
-int coda_unlock(void *);
-int coda_islocked(void *);
-int coda_vop_error(void *);
-int coda_vop_nop(void *);
-int coda_fbsd_getpages (void *);
-int coda_pathconf(void *);
-
-int coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw,
- int ioflag, struct ucred *cred, struct thread *td);
-int coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp);
-void print_vattr(struct vattr *attr);
-void print_cred(struct ucred *cred);
diff --git a/sys/geom/geom_ccd.c b/sys/geom/geom_ccd.c
deleted file mode 100644
index 9af6b4a51af3..000000000000
--- a/sys/geom/geom_ccd.c
+++ /dev/null
@@ -1,1268 +0,0 @@
-/*
- * Copyright (c) 2003 Poul-Henning Kamp.
- * Copyright (c) 1995 Jason R. Thorpe.
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- * All rights reserved.
- * Copyright (c) 1988 University of Utah.
- *
- * This code is derived from software contributed to Berkeley by
- * the Systems Programming Group of the University of Utah Computer
- * Science Department.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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 Jason R. Thorpe.
- * 4. The names of the authors may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE 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.
- *
- * Dynamic configuration and disklabel support by:
- * Jason R. Thorpe <thorpej@nas.nasa.gov>
- * Numerical Aerodynamic Simulation Facility
- * Mail Stop 258-6
- * NASA Ames Research Center
- * Moffett Field, CA 94035
- *
- * from: Utah $Hdr: cd.c 1.6 90/11/28$
- *
- * @(#)cd.c 8.2 (Berkeley) 11/16/93
- *
- * $NetBSD: ccd.c,v 1.22 1995/12/08 19:13:26 thorpej Exp $
- *
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/module.h>
-#include <sys/proc.h>
-#include <sys/bio.h>
-#include <sys/malloc.h>
-#include <sys/namei.h>
-#include <sys/conf.h>
-#include <sys/stat.h>
-#include <sys/sysctl.h>
-#include <sys/disk.h>
-#include <sys/fcntl.h>
-#include <sys/vnode.h>
-#include <geom/geom_disk.h>
-
-#include <sys/ccdvar.h>
-
-MALLOC_DEFINE(M_CCD, "CCD driver", "Concatenated Disk driver");
-
-/*
- This is how mirroring works (only writes are special):
-
- When initiating a write, ccdbuffer() returns two "struct ccdbuf *"s
- linked together by the cb_mirror field. "cb_pflags &
- CCDPF_MIRROR_DONE" is set to 0 on both of them.
-
- When a component returns to ccdiodone(), it checks if "cb_pflags &
- CCDPF_MIRROR_DONE" is set or not. If not, it sets the partner's
- flag and returns. If it is, it means its partner has already
- returned, so it will go to the regular cleanup.
-
- */
-
-struct ccdbuf {
- struct bio cb_buf; /* new I/O buf */
- struct bio *cb_obp; /* ptr. to original I/O buf */
- struct ccdbuf *cb_freenext; /* free list link */
- struct ccd_s *cb_softc;
- int cb_comp; /* target component */
- int cb_pflags; /* mirror/parity status flag */
- struct ccdbuf *cb_mirror; /* mirror counterpart */
-};
-
-/* bits in cb_pflags */
-#define CCDPF_MIRROR_DONE 1 /* if set, mirror counterpart is done */
-
-/* convinient macros for often-used statements */
-#define IS_ALLOCATED(unit) (ccdfind(unit) != NULL)
-#define IS_INITED(cs) (((cs)->sc_flags & CCDF_INITED) != 0)
-
-static dev_t ccdctldev;
-
-static disk_strategy_t ccdstrategy;
-static d_ioctl_t ccdctlioctl;
-
-#define NCCDFREEHIWAT 16
-
-#define CDEV_MAJOR 74
-
-static struct cdevsw ccdctl_cdevsw = {
- .d_open = nullopen,
- .d_close = nullclose,
- .d_ioctl = ccdctlioctl,
- .d_name = "ccdctl",
- .d_maj = CDEV_MAJOR,
-};
-
-static LIST_HEAD(, ccd_s) ccd_softc_list =
- LIST_HEAD_INITIALIZER(&ccd_softc_list);
-
-static struct ccd_s *ccdfind(int);
-static struct ccd_s *ccdnew(int);
-static int ccddestroy(struct ccd_s *);
-
-/* called during module initialization */
-static void ccdattach(void);
-static int ccd_modevent(module_t, int, void *);
-
-/* called by biodone() at interrupt time */
-static void ccdiodone(struct bio *bp);
-
-static void ccdstart(struct ccd_s *, struct bio *);
-static void ccdinterleave(struct ccd_s *, int);
-static int ccdinit(struct ccd_s *, char **, struct thread *);
-static int ccdlookup(char *, struct thread *p, struct vnode **);
-static int ccdbuffer(struct ccdbuf **ret, struct ccd_s *,
- struct bio *, daddr_t, caddr_t, long);
-static int ccdlock(struct ccd_s *);
-static void ccdunlock(struct ccd_s *);
-
-
-/*
- * Number of blocks to untouched in front of a component partition.
- * This is to avoid violating its disklabel area when it starts at the
- * beginning of the slice.
- */
-#if !defined(CCD_OFFSET)
-#define CCD_OFFSET 16
-#endif
-
-static struct ccd_s *
-ccdfind(int unit)
-{
- struct ccd_s *sc = NULL;
-
- /* XXX: LOCK(unique unit numbers) */
- LIST_FOREACH(sc, &ccd_softc_list, list) {
- if (sc->sc_unit == unit)
- break;
- }
- /* XXX: UNLOCK(unique unit numbers) */
- return ((sc == NULL) || (sc->sc_unit != unit) ? NULL : sc);
-}
-
-static struct ccd_s *
-ccdnew(int unit)
-{
- struct ccd_s *sc;
-
- /* XXX: LOCK(unique unit numbers) */
- if (IS_ALLOCATED(unit) || unit > 32)
- return (NULL);
-
- MALLOC(sc, struct ccd_s *, sizeof(*sc), M_CCD, M_WAITOK | M_ZERO);
- sc->sc_unit = unit;
- LIST_INSERT_HEAD(&ccd_softc_list, sc, list);
- /* XXX: UNLOCK(unique unit numbers) */
- return (sc);
-}
-
-static int
-ccddestroy(struct ccd_s *sc)
-{
-
- /* XXX: LOCK(unique unit numbers) */
- LIST_REMOVE(sc, list);
- /* XXX: UNLOCK(unique unit numbers) */
- FREE(sc, M_CCD);
- return (0);
-}
-
-/*
- * Called by main() during pseudo-device attachment. All we need
- * to do is to add devsw entries.
- */
-static void
-ccdattach()
-{
-
- ccdctldev = make_dev(&ccdctl_cdevsw, 0xffff00ff,
- UID_ROOT, GID_OPERATOR, 0640, "ccd.ctl");
- ccdctldev->si_drv1 = ccdctldev;
-}
-
-static int
-ccd_modevent(module_t mod, int type, void *data)
-{
- int error = 0;
-
- switch (type) {
- case MOD_LOAD:
- ccdattach();
- break;
-
- case MOD_UNLOAD:
- printf("ccd0: Unload not supported!\n");
- error = EOPNOTSUPP;
- break;
-
- case MOD_SHUTDOWN:
- break;
-
- default:
- error = EOPNOTSUPP;
- }
- return (error);
-}
-
-DEV_MODULE(ccd, ccd_modevent, NULL);
-
-static int
-ccdinit(struct ccd_s *cs, char **cpaths, struct thread *td)
-{
- struct ccdcinfo *ci = NULL; /* XXX */
- size_t size;
- int ix;
- struct vnode *vp;
- size_t minsize;
- int maxsecsize;
- struct ccdgeom *ccg = &cs->sc_geom;
- char *tmppath = NULL;
- int error = 0;
- off_t mediasize;
- u_int sectorsize;
-
-
- cs->sc_size = 0;
-
- /* Allocate space for the component info. */
- cs->sc_cinfo = malloc(cs->sc_nccdisks * sizeof(struct ccdcinfo),
- M_CCD, M_WAITOK);
-
- /*
- * Verify that each component piece exists and record
- * relevant information about it.
- */
- maxsecsize = 0;
- minsize = 0;
- tmppath = malloc(MAXPATHLEN, M_CCD, M_WAITOK);
- for (ix = 0; ix < cs->sc_nccdisks; ix++) {
- vp = cs->sc_vpp[ix];
- ci = &cs->sc_cinfo[ix];
- ci->ci_vp = vp;
-
- /*
- * Copy in the pathname of the component.
- */
- if ((error = copyinstr(cpaths[ix], tmppath,
- MAXPATHLEN, &ci->ci_pathlen)) != 0) {
- goto fail;
- }
- ci->ci_path = malloc(ci->ci_pathlen, M_CCD, M_WAITOK);
- bcopy(tmppath, ci->ci_path, ci->ci_pathlen);
-
- ci->ci_dev = vn_todev(vp);
-
- /*
- * Get partition information for the component.
- */
- error = VOP_IOCTL(vp, DIOCGMEDIASIZE, (caddr_t)&mediasize,
- FREAD, td->td_ucred, td);
- if (error != 0) {
- goto fail;
- }
- /*
- * Get partition information for the component.
- */
- error = VOP_IOCTL(vp, DIOCGSECTORSIZE, (caddr_t)&sectorsize,
- FREAD, td->td_ucred, td);
- if (error != 0) {
- goto fail;
- }
- if (sectorsize > maxsecsize)
- maxsecsize = sectorsize;
- size = mediasize / DEV_BSIZE - CCD_OFFSET;
-
- /*
- * Calculate the size, truncating to an interleave
- * boundary if necessary.
- */
-
- if (cs->sc_ileave > 1)
- size -= size % cs->sc_ileave;
-
- if (size == 0) {
- error = ENODEV;
- goto fail;
- }
-
- if (minsize == 0 || size < minsize)
- minsize = size;
- ci->ci_size = size;
- cs->sc_size += size;
- }
-
- free(tmppath, M_CCD);
- tmppath = NULL;
-
- /*
- * Don't allow the interleave to be smaller than
- * the biggest component sector.
- */
- if ((cs->sc_ileave > 0) &&
- (cs->sc_ileave < (maxsecsize / DEV_BSIZE))) {
- error = EINVAL;
- goto fail;
- }
-
- /*
- * If uniform interleave is desired set all sizes to that of
- * the smallest component. This will guarentee that a single
- * interleave table is generated.
- *
- * Lost space must be taken into account when calculating the
- * overall size. Half the space is lost when CCDF_MIRROR is
- * specified.
- */
- if (cs->sc_flags & CCDF_UNIFORM) {
- for (ci = cs->sc_cinfo;
- ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) {
- ci->ci_size = minsize;
- }
- if (cs->sc_flags & CCDF_MIRROR) {
- /*
- * Check to see if an even number of components
- * have been specified. The interleave must also
- * be non-zero in order for us to be able to
- * guarentee the topology.
- */
- if (cs->sc_nccdisks % 2) {
- printf("ccd%d: mirroring requires an even number of disks\n", cs->sc_unit );
- error = EINVAL;
- goto fail;
- }
- if (cs->sc_ileave == 0) {
- printf("ccd%d: an interleave must be specified when mirroring\n", cs->sc_unit);
- error = EINVAL;
- goto fail;
- }
- cs->sc_size = (cs->sc_nccdisks/2) * minsize;
- } else {
- if (cs->sc_ileave == 0) {
- printf("ccd%d: an interleave must be specified when using parity\n", cs->sc_unit);
- error = EINVAL;
- goto fail;
- }
- cs->sc_size = cs->sc_nccdisks * minsize;
- }
- }
-
- /*
- * Construct the interleave table.
- */
- ccdinterleave(cs, cs->sc_unit);
-
- /*
- * Create pseudo-geometry based on 1MB cylinders. It's
- * pretty close.
- */
- ccg->ccg_secsize = maxsecsize;
- ccg->ccg_ntracks = 1;
- ccg->ccg_nsectors = 1024 * 1024 / ccg->ccg_secsize;
- ccg->ccg_ncylinders = cs->sc_size / ccg->ccg_nsectors;
-
- cs->sc_flags |= CCDF_INITED;
- cs->sc_cflags = cs->sc_flags; /* So we can find out later... */
- return (0);
-fail:
- while (ci > cs->sc_cinfo) {
- ci--;
- free(ci->ci_path, M_CCD);
- }
- if (tmppath != NULL)
- free(tmppath, M_CCD);
- free(cs->sc_cinfo, M_CCD);
- ccddestroy(cs);
- return (error);
-}
-
-static void
-ccdinterleave(struct ccd_s *cs, int unit)
-{
- struct ccdcinfo *ci, *smallci;
- struct ccdiinfo *ii;
- daddr_t bn, lbn;
- int ix;
- u_long size;
-
-
- /*
- * Allocate an interleave table. The worst case occurs when each
- * of N disks is of a different size, resulting in N interleave
- * tables.
- *
- * Chances are this is too big, but we don't care.
- */
- size = (cs->sc_nccdisks + 1) * sizeof(struct ccdiinfo);
- cs->sc_itable = (struct ccdiinfo *)malloc(size, M_CCD,
- M_WAITOK | M_ZERO);
-
- /*
- * Trivial case: no interleave (actually interleave of disk size).
- * Each table entry represents a single component in its entirety.
- *
- * An interleave of 0 may not be used with a mirror setup.
- */
- if (cs->sc_ileave == 0) {
- bn = 0;
- ii = cs->sc_itable;
-
- for (ix = 0; ix < cs->sc_nccdisks; ix++) {
- /* Allocate space for ii_index. */
- ii->ii_index = malloc(sizeof(int), M_CCD, M_WAITOK);
- ii->ii_ndisk = 1;
- ii->ii_startblk = bn;
- ii->ii_startoff = 0;
- ii->ii_index[0] = ix;
- bn += cs->sc_cinfo[ix].ci_size;
- ii++;
- }
- ii->ii_ndisk = 0;
- return;
- }
-
- /*
- * The following isn't fast or pretty; it doesn't have to be.
- */
- size = 0;
- bn = lbn = 0;
- for (ii = cs->sc_itable; ; ii++) {
- /*
- * Allocate space for ii_index. We might allocate more then
- * we use.
- */
- ii->ii_index = malloc((sizeof(int) * cs->sc_nccdisks),
- M_CCD, M_WAITOK);
-
- /*
- * Locate the smallest of the remaining components
- */
- smallci = NULL;
- for (ci = cs->sc_cinfo; ci < &cs->sc_cinfo[cs->sc_nccdisks];
- ci++) {
- if (ci->ci_size > size &&
- (smallci == NULL ||
- ci->ci_size < smallci->ci_size)) {
- smallci = ci;
- }
- }
-
- /*
- * Nobody left, all done
- */
- if (smallci == NULL) {
- ii->ii_ndisk = 0;
- free(ii->ii_index, M_CCD);
- break;
- }
-
- /*
- * Record starting logical block using an sc_ileave blocksize.
- */
- ii->ii_startblk = bn / cs->sc_ileave;
-
- /*
- * Record starting comopnent block using an sc_ileave
- * blocksize. This value is relative to the beginning of
- * a component disk.
- */
- ii->ii_startoff = lbn;
-
- /*
- * Determine how many disks take part in this interleave
- * and record their indices.
- */
- ix = 0;
- for (ci = cs->sc_cinfo;
- ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) {
- if (ci->ci_size >= smallci->ci_size) {
- ii->ii_index[ix++] = ci - cs->sc_cinfo;
- }
- }
- ii->ii_ndisk = ix;
- bn += ix * (smallci->ci_size - size);
- lbn = smallci->ci_size / cs->sc_ileave;
- size = smallci->ci_size;
- }
-}
-
-static void
-ccdstrategy(struct bio *bp)
-{
- struct ccd_s *cs;
- int pbn; /* in sc_secsize chunks */
- long sz; /* in sc_secsize chunks */
-
- cs = bp->bio_disk->d_drv1;
-
- pbn = bp->bio_blkno / (cs->sc_geom.ccg_secsize / DEV_BSIZE);
- sz = howmany(bp->bio_bcount, cs->sc_geom.ccg_secsize);
-
- /*
- * If out of bounds return an error. If at the EOF point,
- * simply read or write less.
- */
-
- if (pbn < 0 || pbn >= cs->sc_size) {
- bp->bio_resid = bp->bio_bcount;
- if (pbn != cs->sc_size)
- biofinish(bp, NULL, EINVAL);
- else
- biodone(bp);
- return;
- }
-
- /*
- * If the request crosses EOF, truncate the request.
- */
- if (pbn + sz > cs->sc_size) {
- bp->bio_bcount = (cs->sc_size - pbn) *
- cs->sc_geom.ccg_secsize;
- }
-
- bp->bio_resid = bp->bio_bcount;
-
- /*
- * "Start" the unit.
- */
- ccdstart(cs, bp);
- return;
-}
-
-static void
-ccdstart(struct ccd_s *cs, struct bio *bp)
-{
- long bcount, rcount;
- struct ccdbuf *cbp[2];
- caddr_t addr;
- daddr_t bn;
- int err;
- int sent;
-
- /*
- * Translate the partition-relative block number to an absolute.
- */
- bn = bp->bio_blkno;
-
- /*
- * Allocate component buffers and fire off the requests
- */
- addr = bp->bio_data;
- sent = 0;
- for (bcount = bp->bio_bcount; bcount > 0; bcount -= rcount) {
- err = ccdbuffer(cbp, cs, bp, bn, addr, bcount);
- if (err) {
- printf("ccdbuffer error %d\n", err);
- if (!sent)
- biofinish(bp, NULL, err);
- else {
- /*
- * XXX: maybe a race where the partners
- * XXX: we sent already have been in
- * XXX: ccdiodone(). Single-threaded g_down
- * XXX: may protect against this.
- */
- bp->bio_resid -= bcount;
- bp->bio_error = err;
- bp->bio_flags |= BIO_ERROR;
- }
- return;
- }
- rcount = cbp[0]->cb_buf.bio_bcount;
-
- if (cs->sc_cflags & CCDF_MIRROR) {
- /*
- * Mirroring. Writes go to both disks, reads are
- * taken from whichever disk seems most appropriate.
- *
- * We attempt to localize reads to the disk whos arm
- * is nearest the read request. We ignore seeks due
- * to writes when making this determination and we
- * also try to avoid hogging.
- */
- if (cbp[0]->cb_buf.bio_cmd == BIO_WRITE) {
- BIO_STRATEGY(&cbp[0]->cb_buf);
- BIO_STRATEGY(&cbp[1]->cb_buf);
- sent++;
- } else {
- int pick = cs->sc_pick;
- daddr_t range = cs->sc_size / 16;
-
- if (bn < cs->sc_blk[pick] - range ||
- bn > cs->sc_blk[pick] + range
- ) {
- cs->sc_pick = pick = 1 - pick;
- }
- cs->sc_blk[pick] = bn + btodb(rcount);
- BIO_STRATEGY(&cbp[pick]->cb_buf);
- sent++;
- }
- } else {
- /*
- * Not mirroring
- */
- BIO_STRATEGY(&cbp[0]->cb_buf);
- sent++;
- }
- bn += btodb(rcount);
- addr += rcount;
- }
-}
-
-/*
- * Build a component buffer header.
- */
-static int
-ccdbuffer(struct ccdbuf **cb, struct ccd_s *cs, struct bio *bp, daddr_t bn, caddr_t addr, long bcount)
-{
- struct ccdcinfo *ci, *ci2 = NULL; /* XXX */
- struct ccdbuf *cbp;
- daddr_t cbn, cboff;
- off_t cbc;
-
- /*
- * Determine which component bn falls in.
- */
- cbn = bn;
- cboff = 0;
-
- if (cs->sc_ileave == 0) {
- /*
- * Serially concatenated and neither a mirror nor a parity
- * config. This is a special case.
- */
- daddr_t sblk;
-
- sblk = 0;
- for (ci = cs->sc_cinfo; cbn >= sblk + ci->ci_size; ci++)
- sblk += ci->ci_size;
- cbn -= sblk;
- } else {
- struct ccdiinfo *ii;
- int ccdisk, off;
-
- /*
- * Calculate cbn, the logical superblock (sc_ileave chunks),
- * and cboff, a normal block offset (DEV_BSIZE chunks) relative
- * to cbn.
- */
- cboff = cbn % cs->sc_ileave; /* DEV_BSIZE gran */
- cbn = cbn / cs->sc_ileave; /* DEV_BSIZE * ileave gran */
-
- /*
- * Figure out which interleave table to use.
- */
- for (ii = cs->sc_itable; ii->ii_ndisk; ii++) {
- if (ii->ii_startblk > cbn)
- break;
- }
- ii--;
-
- /*
- * off is the logical superblock relative to the beginning
- * of this interleave block.
- */
- off = cbn - ii->ii_startblk;
-
- /*
- * We must calculate which disk component to use (ccdisk),
- * and recalculate cbn to be the superblock relative to
- * the beginning of the component. This is typically done by
- * adding 'off' and ii->ii_startoff together. However, 'off'
- * must typically be divided by the number of components in
- * this interleave array to be properly convert it from a
- * CCD-relative logical superblock number to a
- * component-relative superblock number.
- */
- if (ii->ii_ndisk == 1) {
- /*
- * When we have just one disk, it can't be a mirror
- * or a parity config.
- */
- ccdisk = ii->ii_index[0];
- cbn = ii->ii_startoff + off;
- } else {
- if (cs->sc_cflags & CCDF_MIRROR) {
- /*
- * We have forced a uniform mapping, resulting
- * in a single interleave array. We double
- * up on the first half of the available
- * components and our mirror is in the second
- * half. This only works with a single
- * interleave array because doubling up
- * doubles the number of sectors, so there
- * cannot be another interleave array because
- * the next interleave array's calculations
- * would be off.
- */
- int ndisk2 = ii->ii_ndisk / 2;
- ccdisk = ii->ii_index[off % ndisk2];
- cbn = ii->ii_startoff + off / ndisk2;
- ci2 = &cs->sc_cinfo[ccdisk + ndisk2];
- } else {
- ccdisk = ii->ii_index[off % ii->ii_ndisk];
- cbn = ii->ii_startoff + off / ii->ii_ndisk;
- }
- }
-
- ci = &cs->sc_cinfo[ccdisk];
-
- /*
- * Convert cbn from a superblock to a normal block so it
- * can be used to calculate (along with cboff) the normal
- * block index into this particular disk.
- */
- cbn *= cs->sc_ileave;
- }
-
- /*
- * Fill in the component buf structure.
- */
- cbp = malloc(sizeof(struct ccdbuf), M_CCD, M_NOWAIT | M_ZERO);
- if (cbp == NULL)
- return (ENOMEM);
- cbp->cb_buf.bio_cmd = bp->bio_cmd;
- cbp->cb_buf.bio_done = ccdiodone;
- cbp->cb_buf.bio_dev = ci->ci_dev; /* XXX */
- cbp->cb_buf.bio_blkno = cbn + cboff + CCD_OFFSET;
- cbp->cb_buf.bio_offset = dbtob(cbn + cboff + CCD_OFFSET);
- cbp->cb_buf.bio_data = addr;
- cbp->cb_buf.bio_caller2 = cbp;
- if (cs->sc_ileave == 0)
- cbc = dbtob((off_t)(ci->ci_size - cbn));
- else
- cbc = dbtob((off_t)(cs->sc_ileave - cboff));
- cbp->cb_buf.bio_bcount = (cbc < bcount) ? cbc : bcount;
- cbp->cb_buf.bio_caller1 = (void*)cbp->cb_buf.bio_bcount;
-
- /*
- * context for ccdiodone
- */
- cbp->cb_obp = bp;
- cbp->cb_softc = cs;
- cbp->cb_comp = ci - cs->sc_cinfo;
-
- cb[0] = cbp;
-
- /*
- * Note: both I/O's setup when reading from mirror, but only one
- * will be executed.
- */
- if (cs->sc_cflags & CCDF_MIRROR) {
- /* mirror, setup second I/O */
- cbp = malloc(sizeof(struct ccdbuf), M_CCD, M_NOWAIT);
- if (cbp == NULL) {
- free(cb[0], M_CCD);
- cb[0] = NULL;
- return (ENOMEM);
- }
- bcopy(cb[0], cbp, sizeof(struct ccdbuf));
- cbp->cb_buf.bio_caller2 = cbp;
- cbp->cb_buf.bio_dev = ci2->ci_dev;
- cbp->cb_comp = ci2 - cs->sc_cinfo;
- cb[1] = cbp;
- /* link together the ccdbuf's and clear "mirror done" flag */
- cb[0]->cb_mirror = cb[1];
- cb[1]->cb_mirror = cb[0];
- cb[0]->cb_pflags &= ~CCDPF_MIRROR_DONE;
- cb[1]->cb_pflags &= ~CCDPF_MIRROR_DONE;
- }
- return (0);
-}
-
-/*
- * Called at interrupt time.
- * Mark the component as done and if all components are done,
- * take a ccd interrupt.
- */
-static void
-ccdiodone(struct bio *ibp)
-{
- struct ccdbuf *cbp;
- struct bio *bp;
- struct ccd_s *cs;
- int count;
-
- cbp = ibp->bio_caller2;
- cs = cbp->cb_softc;
- bp = cbp->cb_obp;
- /*
- * If an error occured, report it. If this is a mirrored
- * configuration and the first of two possible reads, do not
- * set the error in the bp yet because the second read may
- * succeed.
- */
-
- if (cbp->cb_buf.bio_flags & BIO_ERROR) {
- const char *msg = "";
-
- if ((cs->sc_cflags & CCDF_MIRROR) &&
- (cbp->cb_buf.bio_cmd == BIO_READ) &&
- (cbp->cb_pflags & CCDPF_MIRROR_DONE) == 0) {
- /*
- * We will try our read on the other disk down
- * below, also reverse the default pick so if we
- * are doing a scan we do not keep hitting the
- * bad disk first.
- */
-
- msg = ", trying other disk";
- cs->sc_pick = 1 - cs->sc_pick;
- cs->sc_blk[cs->sc_pick] = bp->bio_blkno;
- } else {
- bp->bio_flags |= BIO_ERROR;
- bp->bio_error = cbp->cb_buf.bio_error ?
- cbp->cb_buf.bio_error : EIO;
- }
- printf("ccd%d: error %d on component %d block %jd "
- "(ccd block %jd)%s\n", cs->sc_unit, bp->bio_error,
- cbp->cb_comp,
- (intmax_t)cbp->cb_buf.bio_blkno, (intmax_t)bp->bio_blkno,
- msg);
- }
-
- /*
- * Process mirror. If we are writing, I/O has been initiated on both
- * buffers and we fall through only after both are finished.
- *
- * If we are reading only one I/O is initiated at a time. If an
- * error occurs we initiate the second I/O and return, otherwise
- * we free the second I/O without initiating it.
- */
-
- if (cs->sc_cflags & CCDF_MIRROR) {
- if (cbp->cb_buf.bio_cmd == BIO_WRITE) {
- /*
- * When writing, handshake with the second buffer
- * to determine when both are done. If both are not
- * done, return here.
- */
- if ((cbp->cb_pflags & CCDPF_MIRROR_DONE) == 0) {
- cbp->cb_mirror->cb_pflags |= CCDPF_MIRROR_DONE;
- free(cbp, M_CCD);
- return;
- }
- } else {
- /*
- * When reading, either dispose of the second buffer
- * or initiate I/O on the second buffer if an error
- * occured with this one.
- */
- if ((cbp->cb_pflags & CCDPF_MIRROR_DONE) == 0) {
- if (cbp->cb_buf.bio_flags & BIO_ERROR) {
- cbp->cb_mirror->cb_pflags |=
- CCDPF_MIRROR_DONE;
- BIO_STRATEGY(&cbp->cb_mirror->cb_buf);
- free(cbp, M_CCD);
- return;
- } else {
- free(cbp->cb_mirror, M_CCD);
- }
- }
- }
- }
-
- /*
- * use bio_caller1 to determine how big the original request was rather
- * then bio_bcount, because bio_bcount may have been truncated for EOF.
- *
- * XXX We check for an error, but we do not test the resid for an
- * aligned EOF condition. This may result in character & block
- * device access not recognizing EOF properly when read or written
- * sequentially, but will not effect filesystems.
- */
- count = (long)cbp->cb_buf.bio_caller1;
- free(cbp, M_CCD);
-
- /*
- * If all done, "interrupt".
- */
- bp->bio_resid -= count;
- if (bp->bio_resid < 0)
- panic("ccdiodone: count");
- if (bp->bio_resid == 0) {
- if (bp->bio_flags & BIO_ERROR)
- bp->bio_resid = bp->bio_bcount;
- biodone(bp);
- }
-}
-
-static int ccdioctltoo(int unit, u_long cmd, caddr_t data, int flag, struct thread *td);
-
-static int
-ccdctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
-{
- struct ccd_ioctl *ccio;
- u_int unit;
- dev_t dev2;
- int error;
-
- switch (cmd) {
- case CCDIOCSET:
- case CCDIOCCLR:
- ccio = (struct ccd_ioctl *)data;
- unit = ccio->ccio_size;
- return (ccdioctltoo(unit, cmd, data, flag, td));
- case CCDCONFINFO:
- {
- int ninit = 0;
- struct ccdconf *conf = (struct ccdconf *)data;
- struct ccd_s *tmpcs;
- struct ccd_s *ubuf = conf->buffer;
-
- /* XXX: LOCK(unique unit numbers) */
- LIST_FOREACH(tmpcs, &ccd_softc_list, list)
- if (IS_INITED(tmpcs))
- ninit++;
-
- if (conf->size == 0) {
- conf->size = sizeof(struct ccd_s) * ninit;
- return (0);
- } else if ((conf->size / sizeof(struct ccd_s) != ninit) ||
- (conf->size % sizeof(struct ccd_s) != 0)) {
- /* XXX: UNLOCK(unique unit numbers) */
- return (EINVAL);
- }
-
- ubuf += ninit;
- LIST_FOREACH(tmpcs, &ccd_softc_list, list) {
- if (!IS_INITED(tmpcs))
- continue;
- error = copyout(tmpcs, --ubuf,
- sizeof(struct ccd_s));
- if (error != 0)
- /* XXX: UNLOCK(unique unit numbers) */
- return (error);
- }
- /* XXX: UNLOCK(unique unit numbers) */
- return (0);
- }
-
- case CCDCPPINFO:
- {
- struct ccdcpps *cpps = (struct ccdcpps *)data;
- char *ubuf = cpps->buffer;
- struct ccd_s *cs;
-
-
- error = copyin(ubuf, &unit, sizeof (unit));
- if (error)
- return (error);
-
- if (!IS_ALLOCATED(unit))
- return (ENXIO);
- dev2 = makedev(CDEV_MAJOR, unit * 8 + 2);
- cs = ccdfind(unit);
- if (!IS_INITED(cs))
- return (ENXIO);
-
- {
- int len = 0, i;
- struct ccdcpps *cpps = (struct ccdcpps *)data;
- char *ubuf = cpps->buffer;
-
-
- for (i = 0; i < cs->sc_nccdisks; ++i)
- len += cs->sc_cinfo[i].ci_pathlen;
-
- if (cpps->size < len)
- return (ENOMEM);
-
- for (i = 0; i < cs->sc_nccdisks; ++i) {
- len = cs->sc_cinfo[i].ci_pathlen;
- error = copyout(cs->sc_cinfo[i].ci_path, ubuf,
- len);
- if (error != 0)
- return (error);
- ubuf += len;
- }
- return(copyout("", ubuf, 1));
- }
- break;
- }
-
- default:
- return (ENXIO);
- }
-}
-
-static int
-ccdioctltoo(int unit, u_long cmd, caddr_t data, int flag, struct thread *td)
-{
- int i, j, lookedup = 0, error = 0;
- struct ccd_s *cs;
- struct ccd_ioctl *ccio = (struct ccd_ioctl *)data;
- struct ccdgeom *ccg;
- char **cpp;
- struct vnode **vpp;
-
- cs = ccdfind(unit);
- switch (cmd) {
- case CCDIOCSET:
- if (cs == NULL)
- cs = ccdnew(unit);
- if (IS_INITED(cs))
- return (EBUSY);
-
- if ((flag & FWRITE) == 0)
- return (EBADF);
-
- if ((error = ccdlock(cs)) != 0)
- return (error);
-
- if (ccio->ccio_ndisks > CCD_MAXNDISKS)
- return (EINVAL);
-
- /* Fill in some important bits. */
- cs->sc_ileave = ccio->ccio_ileave;
- if (cs->sc_ileave == 0 && (ccio->ccio_flags & CCDF_MIRROR)) {
- printf("ccd%d: disabling mirror, interleave is 0\n",
- unit);
- ccio->ccio_flags &= ~(CCDF_MIRROR);
- }
- if ((ccio->ccio_flags & CCDF_MIRROR) &&
- !(ccio->ccio_flags & CCDF_UNIFORM)) {
- printf("ccd%d: mirror/parity forces uniform flag\n",
- unit);
- ccio->ccio_flags |= CCDF_UNIFORM;
- }
- cs->sc_flags = ccio->ccio_flags & CCDF_USERMASK;
-
- /*
- * Allocate space for and copy in the array of
- * componet pathnames and device numbers.
- */
- cpp = malloc(ccio->ccio_ndisks * sizeof(char *),
- M_CCD, M_WAITOK);
- vpp = malloc(ccio->ccio_ndisks * sizeof(struct vnode *),
- M_CCD, M_WAITOK);
-
- error = copyin((caddr_t)ccio->ccio_disks, (caddr_t)cpp,
- ccio->ccio_ndisks * sizeof(char **));
- if (error) {
- free(vpp, M_CCD);
- free(cpp, M_CCD);
- ccdunlock(cs);
- return (error);
- }
-
-
- for (i = 0; i < ccio->ccio_ndisks; ++i) {
- if ((error = ccdlookup(cpp[i], td, &vpp[i])) != 0) {
- for (j = 0; j < lookedup; ++j)
- (void)vn_close(vpp[j], FREAD|FWRITE,
- td->td_ucred, td);
- free(vpp, M_CCD);
- free(cpp, M_CCD);
- ccdunlock(cs);
- return (error);
- }
- ++lookedup;
- }
- cs->sc_vpp = vpp;
- cs->sc_nccdisks = ccio->ccio_ndisks;
-
- /*
- * Initialize the ccd. Fills in the softc for us.
- */
- if ((error = ccdinit(cs, cpp, td)) != 0) {
- for (j = 0; j < lookedup; ++j)
- (void)vn_close(vpp[j], FREAD|FWRITE,
- td->td_ucred, td);
- /*
- * We can't ccddestroy() cs just yet, because nothing
- * prevents user-level app to do another ioctl()
- * without closing the device first, therefore
- * declare unit null and void and let ccdclose()
- * destroy it when it is safe to do so.
- */
- cs->sc_flags &= (CCDF_WANTED | CCDF_LOCKED);
- free(vpp, M_CCD);
- free(cpp, M_CCD);
- ccdunlock(cs);
- return (error);
- }
- free(cpp, M_CCD);
-
- /*
- * The ccd has been successfully initialized, so
- * we can place it into the array and read the disklabel.
- */
- ccio->ccio_unit = unit;
- ccio->ccio_size = cs->sc_size;
- ccg = &cs->sc_geom;
- cs->sc_disk = malloc(sizeof(struct disk), M_CCD,
- M_ZERO | M_WAITOK);
- cs->sc_disk->d_strategy = ccdstrategy;
- cs->sc_disk->d_name = "ccd";
- cs->sc_disk->d_sectorsize = ccg->ccg_secsize;
- cs->sc_disk->d_mediasize =
- cs->sc_size * (off_t)ccg->ccg_secsize;
- cs->sc_disk->d_fwsectors = ccg->ccg_nsectors;
- cs->sc_disk->d_fwheads = ccg->ccg_ntracks;
- cs->sc_disk->d_drv1 = cs;
- cs->sc_disk->d_maxsize = MAXPHYS;
- disk_create(unit, cs->sc_disk, 0, NULL, NULL);
-
- ccdunlock(cs);
-
- break;
-
- case CCDIOCCLR:
- if (cs == NULL)
- return (ENXIO);
-
- if (!IS_INITED(cs))
- return (ENXIO);
-
- if ((flag & FWRITE) == 0)
- return (EBADF);
-
- if ((error = ccdlock(cs)) != 0)
- return (error);
-
- /* Don't unconfigure if any other partitions are open */
- if (cs->sc_disk->d_flags & DISKFLAG_OPEN) {
- ccdunlock(cs);
- return (EBUSY);
- }
-
- disk_destroy(cs->sc_disk);
- free(cs->sc_disk, M_CCD);
- cs->sc_disk = NULL;
- /* Declare unit null and void (reset all flags) */
- cs->sc_flags &= (CCDF_WANTED | CCDF_LOCKED);
-
- /* Close the components and free their pathnames. */
- for (i = 0; i < cs->sc_nccdisks; ++i) {
- /*
- * XXX: this close could potentially fail and
- * cause Bad Things. Maybe we need to force
- * the close to happen?
- */
- (void)vn_close(cs->sc_cinfo[i].ci_vp, FREAD|FWRITE,
- td->td_ucred, td);
- free(cs->sc_cinfo[i].ci_path, M_CCD);
- }
-
- /* Free interleave index. */
- for (i = 0; cs->sc_itable[i].ii_ndisk; ++i)
- free(cs->sc_itable[i].ii_index, M_CCD);
-
- /* Free component info and interleave table. */
- free(cs->sc_cinfo, M_CCD);
- free(cs->sc_itable, M_CCD);
- free(cs->sc_vpp, M_CCD);
-
- /* This must be atomic. */
- ccdunlock(cs);
- ccddestroy(cs);
-
- break;
- }
-
- return (0);
-}
-
-
-/*
- * Lookup the provided name in the filesystem. If the file exists,
- * is a valid block device, and isn't being used by anyone else,
- * set *vpp to the file's vnode.
- */
-static int
-ccdlookup(char *path, struct thread *td, struct vnode **vpp)
-{
- struct nameidata nd;
- struct vnode *vp;
- int error, flags;
-
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, path, td);
- flags = FREAD | FWRITE;
- if ((error = vn_open(&nd, &flags, 0)) != 0) {
- return (error);
- }
- vp = nd.ni_vp;
-
- if (vrefcnt(vp) > 1) {
- error = EBUSY;
- goto bad;
- }
-
- if (!vn_isdisk(vp, &error))
- goto bad;
-
-
- VOP_UNLOCK(vp, 0, td);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- *vpp = vp;
- return (0);
-bad:
- VOP_UNLOCK(vp, 0, td);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- /* vn_close does vrele() for vp */
- (void)vn_close(vp, FREAD|FWRITE, td->td_ucred, td);
- return (error);
-}
-
-/*
-
- * Wait interruptibly for an exclusive lock.
- *
- * XXX
- * Several drivers do this; it should be abstracted and made MP-safe.
- */
-static int
-ccdlock(struct ccd_s *cs)
-{
- int error;
-
- while ((cs->sc_flags & CCDF_LOCKED) != 0) {
- cs->sc_flags |= CCDF_WANTED;
- if ((error = tsleep(cs, PRIBIO | PCATCH, "ccdlck", 0)) != 0)
- return (error);
- }
- cs->sc_flags |= CCDF_LOCKED;
- return (0);
-}
-
-/*
- * Unlock and wake up any waiters.
- */
-static void
-ccdunlock(struct ccd_s *cs)
-{
-
- cs->sc_flags &= ~CCDF_LOCKED;
- if ((cs->sc_flags & CCDF_WANTED) != 0) {
- cs->sc_flags &= ~CCDF_WANTED;
- wakeup(cs);
- }
-}
diff --git a/sys/gnu/fs/ext2fs/COPYRIGHT.INFO b/sys/gnu/fs/ext2fs/COPYRIGHT.INFO
deleted file mode 100644
index 699f519c02a8..000000000000
--- a/sys/gnu/fs/ext2fs/COPYRIGHT.INFO
+++ /dev/null
@@ -1,35 +0,0 @@
-$FreeBSD$
-
-Most of the files in this directory are written by Godmar Back or modified
-by him using the CSRG sources. Those files are covered by the Berkeley-style
-copyright. However the following files are covered by GPL. Since the policy
-of the FreeBSD project is to keep the files with the more restrictive
-copyright in the gnu tree and it is a good idea to keep the filesystem code
-all together, the EXT2FS in its entirety resides under the gnu tree. Note
-that only the files below are under the GPL. In the eventuality that these
-files are redesigned or rewritten, this tree can be moved back into the less
-restrictive FreeBSD tree.
-
- ext2_bitmap.c (in the cvs attic)
- ext2_fs.h
- ext2_fs_i.h
- ext2_fs_sb.h
- ext2_linux_balloc.c
- ext2_linux_ialloc.c
- ext2_super.c (in the cvs attic)
- ext2_vfsops.c (has some GPL'ed code from ext2_super.c)
- i386-bitops.h
-
-PS.
- THANKS GODMAR!!!
-
-Note that this port has been modified by John Dyson and others on
-the FreeBSD team, and it is best to send the bug reports to the FreeBSD
-team. If there are any non-FreeBSD specific bugs, fixes will be sent to
-Godmar to help him fix the original code base. It is also our intention
-to send Godmar any FreeBSD specific porting changes so that he can keep
-control of his code....
-
-John
-dyson@freebsd.org
-
diff --git a/sys/gnu/fs/ext2fs/ext2_alloc.c b/sys/gnu/fs/ext2fs/ext2_alloc.c
deleted file mode 100644
index a99a8ee83448..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_alloc.c
+++ /dev/null
@@ -1,539 +0,0 @@
-/*
- * modified for Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- */
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ffs_alloc.c 8.8 (Berkeley) 2/21/94
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/conf.h>
-#include <sys/vnode.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
-#include <sys/syslog.h>
-
-#include <gnu/ext2fs/inode.h>
-#include <gnu/ext2fs/ext2_mount.h>
-#include <gnu/ext2fs/ext2_fs.h>
-#include <gnu/ext2fs/ext2_fs_sb.h>
-#include <gnu/ext2fs/fs.h>
-#include <gnu/ext2fs/ext2_extern.h>
-
-static void ext2_fserr(struct ext2_sb_info *, u_int, char *);
-
-/*
- * Linux calls this functions at the following locations:
- * (1) the inode is freed
- * (2) a preallocation miss occurs
- * (3) truncate is called
- * (4) release_file is called and f_mode & 2
- *
- * I call it in ext2_inactive, ext2_truncate, ext2_vfree and in (2)
- * the call in vfree might be redundant
- */
-void
-ext2_discard_prealloc(ip)
- struct inode * ip;
-{
-#ifdef EXT2_PREALLOCATE
- if (ip->i_prealloc_count) {
- int i = ip->i_prealloc_count;
- ip->i_prealloc_count = 0;
- ext2_free_blocks (ITOV(ip)->v_mount,
- ip->i_prealloc_block,
- i);
- }
-#endif
-}
-
-/*
- * Allocate a block in the file system.
- *
- * this takes the framework from ffs_alloc. To implement the
- * actual allocation, it calls ext2_new_block, the ported version
- * of the same Linux routine.
- *
- * we note that this is always called in connection with ext2_blkpref
- *
- * preallocation is done as Linux does it
- */
-int
-ext2_alloc(ip, lbn, bpref, size, cred, bnp)
- struct inode *ip;
- int32_t lbn, bpref;
- int size;
- struct ucred *cred;
- int32_t *bnp;
-{
- struct ext2_sb_info *fs;
- int32_t bno;
-
- *bnp = 0;
- fs = ip->i_e2fs;
-#if DIAGNOSTIC
- if ((u_int)size > fs->s_blocksize || blkoff(fs, size) != 0) {
- printf("dev = %s, bsize = %lu, size = %d, fs = %s\n",
- devtoname(ip->i_dev), fs->s_blocksize, size, fs->fs_fsmnt);
- panic("ext2_alloc: bad size");
- }
- if (cred == NOCRED)
- panic("ext2_alloc: missing credential");
-#endif /* DIAGNOSTIC */
- if (size == fs->s_blocksize && fs->s_es->s_free_blocks_count == 0)
- goto nospace;
- if (cred->cr_uid != 0 &&
- fs->s_es->s_free_blocks_count < fs->s_es->s_r_blocks_count)
- goto nospace;
- if (bpref >= fs->s_es->s_blocks_count)
- bpref = 0;
- /* call the Linux code */
-#ifdef EXT2_PREALLOCATE
- /* To have a preallocation hit, we must
- * - have at least one block preallocated
- * - and our preferred block must have that block number or one below
- */
- if (ip->i_prealloc_count &&
- (bpref == ip->i_prealloc_block ||
- bpref + 1 == ip->i_prealloc_block))
- {
- bno = ip->i_prealloc_block++;
- ip->i_prealloc_count--;
- /* ext2_debug ("preallocation hit (%lu/%lu).\n",
- ++alloc_hits, ++alloc_attempts); */
-
- /* Linux gets, clears, and releases the buffer at this
- point - we don't have to that; we leave it to the caller
- */
- } else {
- ext2_discard_prealloc (ip);
- /* ext2_debug ("preallocation miss (%lu/%lu).\n",
- alloc_hits, ++alloc_attempts); */
- if (S_ISREG(ip->i_mode))
- bno = ext2_new_block
- (ITOV(ip)->v_mount, bpref,
- &ip->i_prealloc_count,
- &ip->i_prealloc_block);
- else
- bno = (int32_t)ext2_new_block(ITOV(ip)->v_mount,
- bpref, 0, 0);
- }
-#else
- bno = (int32_t)ext2_new_block(ITOV(ip)->v_mount, bpref, 0, 0);
-#endif
-
- if (bno > 0) {
- /* set next_alloc fields as done in block_getblk */
- ip->i_next_alloc_block = lbn;
- ip->i_next_alloc_goal = bno;
-
- ip->i_blocks += btodb(size);
- ip->i_flag |= IN_CHANGE | IN_UPDATE;
- *bnp = bno;
- return (0);
- }
-nospace:
- ext2_fserr(fs, cred->cr_uid, "file system full");
- uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt);
- return (ENOSPC);
-}
-
-/*
- * Reallocate a sequence of blocks into a contiguous sequence of blocks.
- *
- * The vnode and an array of buffer pointers for a range of sequential
- * logical blocks to be made contiguous is given. The allocator attempts
- * to find a range of sequential blocks starting as close as possible to
- * an fs_rotdelay offset from the end of the allocation for the logical
- * block immediately preceding the current range. If successful, the
- * physical block numbers in the buffer pointers and in the inode are
- * changed to reflect the new allocation. If unsuccessful, the allocation
- * is left unchanged. The success in doing the reallocation is returned.
- * Note that the error return is not reflected back to the user. Rather
- * the previous block allocation will be used.
- */
-
-#ifdef FANCY_REALLOC
-#include <sys/sysctl.h>
-static int doasyncfree = 1;
-#ifdef OPT_DEBUG
-SYSCTL_INT(_debug, 14, doasyncfree, CTLFLAG_RW, &doasyncfree, 0, "");
-#endif /* OPT_DEBUG */
-#endif
-
-int
-ext2_reallocblks(ap)
- struct vop_reallocblks_args /* {
- struct vnode *a_vp;
- struct cluster_save *a_buflist;
- } */ *ap;
-{
-#ifndef FANCY_REALLOC
-/* printf("ext2_reallocblks not implemented\n"); */
-return ENOSPC;
-#else
-
- struct ext2_sb_info *fs;
- struct inode *ip;
- struct vnode *vp;
- struct buf *sbp, *ebp;
- int32_t *bap, *sbap, *ebap;
- struct cluster_save *buflist;
- int32_t start_lbn, end_lbn, soff, eoff, newblk, blkno;
- struct indir start_ap[NIADDR + 1], end_ap[NIADDR + 1], *idp;
- int i, len, start_lvl, end_lvl, pref, ssize;
-
- vp = ap->a_vp;
- ip = VTOI(vp);
- fs = ip->i_e2fs;
-#ifdef UNKLAR
- if (fs->fs_contigsumsize <= 0)
- return (ENOSPC);
-#endif
- buflist = ap->a_buflist;
- len = buflist->bs_nchildren;
- start_lbn = buflist->bs_children[0]->b_lblkno;
- end_lbn = start_lbn + len - 1;
-#if DIAGNOSTIC
- for (i = 1; i < len; i++)
- if (buflist->bs_children[i]->b_lblkno != start_lbn + i)
- panic("ext2_reallocblks: non-cluster");
-#endif
- /*
- * If the latest allocation is in a new cylinder group, assume that
- * the filesystem has decided to move and do not force it back to
- * the previous cylinder group.
- */
- if (dtog(fs, dbtofsb(fs, buflist->bs_children[0]->b_blkno)) !=
- dtog(fs, dbtofsb(fs, buflist->bs_children[len - 1]->b_blkno)))
- return (ENOSPC);
- if (ufs_getlbns(vp, start_lbn, start_ap, &start_lvl) ||
- ufs_getlbns(vp, end_lbn, end_ap, &end_lvl))
- return (ENOSPC);
- /*
- * Get the starting offset and block map for the first block.
- */
- if (start_lvl == 0) {
- sbap = &ip->i_db[0];
- soff = start_lbn;
- } else {
- idp = &start_ap[start_lvl - 1];
- if (bread(vp, idp->in_lbn, (int)fs->s_blocksize, NOCRED, &sbp)) {
- brelse(sbp);
- return (ENOSPC);
- }
- sbap = (int32_t *)sbp->b_data;
- soff = idp->in_off;
- }
- /*
- * Find the preferred location for the cluster.
- */
- pref = ext2_blkpref(ip, start_lbn, soff, sbap);
- /*
- * If the block range spans two block maps, get the second map.
- */
- if (end_lvl == 0 || (idp = &end_ap[end_lvl - 1])->in_off + 1 >= len) {
- ssize = len;
- } else {
-#if DIAGNOSTIC
- if (start_ap[start_lvl-1].in_lbn == idp->in_lbn)
- panic("ext2_reallocblk: start == end");
-#endif
- ssize = len - (idp->in_off + 1);
- if (bread(vp, idp->in_lbn, (int)fs->s_blocksize, NOCRED, &ebp))
- goto fail;
- ebap = (int32_t *)ebp->b_data;
- }
- /*
- * Search the block map looking for an allocation of the desired size.
- */
- if ((newblk = (int32_t)ext2_hashalloc(ip, dtog(fs, pref), (long)pref,
- len, (u_long (*)())ext2_clusteralloc)) == 0)
- goto fail;
- /*
- * We have found a new contiguous block.
- *
- * First we have to replace the old block pointers with the new
- * block pointers in the inode and indirect blocks associated
- * with the file.
- */
- blkno = newblk;
- for (bap = &sbap[soff], i = 0; i < len; i++, blkno += fs->s_frags_per_block) {
- if (i == ssize)
- bap = ebap;
-#if DIAGNOSTIC
- if (buflist->bs_children[i]->b_blkno != fsbtodb(fs, *bap))
- panic("ext2_reallocblks: alloc mismatch");
-#endif
- *bap++ = blkno;
- }
- /*
- * Next we must write out the modified inode and indirect blocks.
- * For strict correctness, the writes should be synchronous since
- * the old block values may have been written to disk. In practise
- * they are almost never written, but if we are concerned about
- * strict correctness, the `doasyncfree' flag should be set to zero.
- *
- * The test on `doasyncfree' should be changed to test a flag
- * that shows whether the associated buffers and inodes have
- * been written. The flag should be set when the cluster is
- * started and cleared whenever the buffer or inode is flushed.
- * We can then check below to see if it is set, and do the
- * synchronous write only when it has been cleared.
- */
- if (sbap != &ip->i_db[0]) {
- if (doasyncfree)
- bdwrite(sbp);
- else
- bwrite(sbp);
- } else {
- ip->i_flag |= IN_CHANGE | IN_UPDATE;
- if (!doasyncfree)
- ext2_update(vp, 1);
- }
- if (ssize < len)
- if (doasyncfree)
- bdwrite(ebp);
- else
- bwrite(ebp);
- /*
- * Last, free the old blocks and assign the new blocks to the buffers.
- */
- for (blkno = newblk, i = 0; i < len; i++, blkno += fs->s_frags_per_block) {
- ext2_blkfree(ip, dbtofsb(fs, buflist->bs_children[i]->b_blkno),
- fs->s_blocksize);
- buflist->bs_children[i]->b_blkno = fsbtodb(fs, blkno);
- }
- return (0);
-
-fail:
- if (ssize < len)
- brelse(ebp);
- if (sbap != &ip->i_db[0])
- brelse(sbp);
- return (ENOSPC);
-
-#endif /* FANCY_REALLOC */
-}
-
-/*
- * Allocate an inode in the file system.
- *
- * we leave the actual allocation strategy to the (modified)
- * ext2_new_inode(), to make sure we get the policies right
- */
-int
-ext2_valloc(pvp, mode, cred, vpp)
- struct vnode *pvp;
- int mode;
- struct ucred *cred;
- struct vnode **vpp;
-{
- struct inode *pip;
- struct ext2_sb_info *fs;
- struct inode *ip;
- ino_t ino;
- int i, error;
-
- *vpp = NULL;
- pip = VTOI(pvp);
- fs = pip->i_e2fs;
- if (fs->s_es->s_free_inodes_count == 0)
- goto noinodes;
-
- /* call the Linux routine - it returns the inode number only */
- ino = ext2_new_inode(pip, mode);
-
- if (ino == 0)
- goto noinodes;
- error = VFS_VGET(pvp->v_mount, ino, LK_EXCLUSIVE, vpp);
- if (error) {
- ext2_vfree(pvp, ino, mode);
- return (error);
- }
- ip = VTOI(*vpp);
-
- /*
- the question is whether using VGET was such good idea at all -
- Linux doesn't read the old inode in when it's allocating a
- new one. I will set at least i_size & i_blocks the zero.
- */
- ip->i_mode = 0;
- ip->i_size = 0;
- ip->i_blocks = 0;
- ip->i_flags = 0;
- /* now we want to make sure that the block pointers are zeroed out */
- for (i = 0; i < NDADDR; i++)
- ip->i_db[i] = 0;
- for (i = 0; i < NIADDR; i++)
- ip->i_ib[i] = 0;
-
- /*
- * Set up a new generation number for this inode.
- * XXX check if this makes sense in ext2
- */
- if (ip->i_gen == 0 || ++ip->i_gen == 0)
- ip->i_gen = random() / 2 + 1;
-/*
-printf("ext2_valloc: allocated inode %d\n", ino);
-*/
- return (0);
-noinodes:
- ext2_fserr(fs, cred->cr_uid, "out of inodes");
- uprintf("\n%s: create/symlink failed, no inodes free\n", fs->fs_fsmnt);
- return (ENOSPC);
-}
-
-/*
- * Select the desired position for the next block in a file.
- *
- * we try to mimic what Remy does in inode_getblk/block_getblk
- *
- * we note: blocknr == 0 means that we're about to allocate either
- * a direct block or a pointer block at the first level of indirection
- * (In other words, stuff that will go in i_db[] or i_ib[])
- *
- * blocknr != 0 means that we're allocating a block that is none
- * of the above. Then, blocknr tells us the number of the block
- * that will hold the pointer
- */
-int32_t
-ext2_blkpref(ip, lbn, indx, bap, blocknr)
- struct inode *ip;
- int32_t lbn;
- int indx;
- int32_t *bap;
- int32_t blocknr;
-{
- int tmp;
-
- /* if the next block is actually what we thought it is,
- then set the goal to what we thought it should be
- */
- if(ip->i_next_alloc_block == lbn)
- return ip->i_next_alloc_goal;
-
- /* now check whether we were provided with an array that basically
- tells us previous blocks to which we want to stay closeby
- */
- if(bap)
- for (tmp = indx - 1; tmp >= 0; tmp--)
- if (bap[tmp])
- return bap[tmp];
-
- /* else let's fall back to the blocknr, or, if there is none,
- follow the rule that a block should be allocated near its inode
- */
- return blocknr ? blocknr :
- (int32_t)(ip->i_block_group *
- EXT2_BLOCKS_PER_GROUP(ip->i_e2fs)) +
- ip->i_e2fs->s_es->s_first_data_block;
-}
-
-/*
- * Free a block or fragment.
- *
- * pass on to the Linux code
- */
-void
-ext2_blkfree(ip, bno, size)
- struct inode *ip;
- int32_t bno;
- long size;
-{
- struct ext2_sb_info *fs;
-
- fs = ip->i_e2fs;
- /*
- * call Linux code with mount *, block number, count
- */
- ext2_free_blocks(ITOV(ip)->v_mount, bno, size / fs->s_frag_size);
-}
-
-/*
- * Free an inode.
- *
- * the maintenance of the actual bitmaps is again up to the linux code
- */
-int
-ext2_vfree(pvp, ino, mode)
- struct vnode *pvp;
- ino_t ino;
- int mode;
-{
- struct ext2_sb_info *fs;
- struct inode *pip;
- mode_t save_i_mode;
-
- pip = VTOI(pvp);
- fs = pip->i_e2fs;
- if ((u_int)ino > fs->s_inodes_per_group * fs->s_groups_count)
- panic("ext2_vfree: range: dev = (%d, %d), ino = %d, fs = %s",
- major(pip->i_dev), minor(pip->i_dev), ino, fs->fs_fsmnt);
-
-/* ext2_debug("ext2_vfree (%d, %d) called\n", pip->i_number, mode);
- */
- ext2_discard_prealloc(pip);
-
- /* we need to make sure that ext2_free_inode can adjust the
- used_dir_counts in the group summary information - I'd
- really like to know what the rationale behind this
- 'set i_mode to zero to denote an unused inode' is
- */
- save_i_mode = pip->i_mode;
- pip->i_mode = mode;
- ext2_free_inode(pip);
- pip->i_mode = save_i_mode;
- return (0);
-}
-
-/*
- * Fserr prints the name of a file system with an error diagnostic.
- *
- * The form of the error message is:
- * fs: error message
- */
-static void
-ext2_fserr(fs, uid, cp)
- struct ext2_sb_info *fs;
- u_int uid;
- char *cp;
-{
-
- log(LOG_ERR, "uid %d on %s: %s\n", uid, fs->fs_fsmnt, cp);
-}
diff --git a/sys/gnu/fs/ext2fs/ext2_balloc.c b/sys/gnu/fs/ext2fs/ext2_balloc.c
deleted file mode 100644
index 53946e54d37f..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_balloc.c
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- * modified for Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- */
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ffs_balloc.c 8.4 (Berkeley) 9/23/93
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/lock.h>
-#include <sys/ucred.h>
-#include <sys/vnode.h>
-
-#include <gnu/ext2fs/inode.h>
-#include <gnu/ext2fs/ext2_fs.h>
-#include <gnu/ext2fs/ext2_fs_sb.h>
-#include <gnu/ext2fs/fs.h>
-#include <gnu/ext2fs/ext2_extern.h>
-
-/*
- * Balloc defines the structure of file system storage
- * by allocating the physical blocks on a device given
- * the inode and the logical block number in a file.
- */
-int
-ext2_balloc(ip, bn, size, cred, bpp, flags)
- struct inode *ip;
- int32_t bn;
- int size;
- struct ucred *cred;
- struct buf **bpp;
- int flags;
-{
- struct ext2_sb_info *fs;
- int32_t nb;
- struct buf *bp, *nbp;
- struct vnode *vp = ITOV(ip);
- struct indir indirs[NIADDR + 2];
- int32_t newb, lbn, *bap, pref;
- int osize, nsize, num, i, error;
-/*
-ext2_debug("ext2_balloc called (%d, %d, %d)\n",
- ip->i_number, (int)bn, (int)size);
-*/
- *bpp = NULL;
- if (bn < 0)
- return (EFBIG);
- fs = ip->i_e2fs;
- lbn = bn;
-
- /*
- * check if this is a sequential block allocation.
- * If so, increment next_alloc fields to allow ext2_blkpref
- * to make a good guess
- */
- if (lbn == ip->i_next_alloc_block + 1) {
- ip->i_next_alloc_block++;
- ip->i_next_alloc_goal++;
- }
-
- /*
- * The first NDADDR blocks are direct blocks
- */
- if (bn < NDADDR) {
- nb = ip->i_db[bn];
- /* no new block is to be allocated, and no need to expand
- the file */
- if (nb != 0 && ip->i_size >= (bn + 1) * fs->s_blocksize) {
- error = bread(vp, bn, fs->s_blocksize, NOCRED, &bp);
- if (error) {
- brelse(bp);
- return (error);
- }
- bp->b_blkno = fsbtodb(fs, nb);
- *bpp = bp;
- return (0);
- }
- if (nb != 0) {
- /*
- * Consider need to reallocate a fragment.
- */
- osize = fragroundup(fs, blkoff(fs, ip->i_size));
- nsize = fragroundup(fs, size);
- if (nsize <= osize) {
- error = bread(vp, bn, osize, NOCRED, &bp);
- if (error) {
- brelse(bp);
- return (error);
- }
- bp->b_blkno = fsbtodb(fs, nb);
- } else {
- /* Godmar thinks: this shouldn't happen w/o fragments */
- printf("nsize %d(%d) > osize %d(%d) nb %d\n",
- (int)nsize, (int)size, (int)osize,
- (int)ip->i_size, (int)nb);
- panic(
- "ext2_balloc: Something is terribly wrong");
-/*
- * please note there haven't been any changes from here on -
- * FFS seems to work.
- */
- }
- } else {
- if (ip->i_size < (bn + 1) * fs->s_blocksize)
- nsize = fragroundup(fs, size);
- else
- nsize = fs->s_blocksize;
- error = ext2_alloc(ip, bn,
- ext2_blkpref(ip, bn, (int)bn, &ip->i_db[0], 0),
- nsize, cred, &newb);
- if (error)
- return (error);
- bp = getblk(vp, bn, nsize, 0, 0, 0);
- bp->b_blkno = fsbtodb(fs, newb);
- if (flags & B_CLRBUF)
- vfs_bio_clrbuf(bp);
- }
- ip->i_db[bn] = dbtofsb(fs, bp->b_blkno);
- ip->i_flag |= IN_CHANGE | IN_UPDATE;
- *bpp = bp;
- return (0);
- }
- /*
- * Determine the number of levels of indirection.
- */
- pref = 0;
- if ((error = ext2_getlbns(vp, bn, indirs, &num)) != 0)
- return(error);
-#if DIAGNOSTIC
- if (num < 1)
- panic ("ext2_balloc: ext2_getlbns returned indirect block");
-#endif
- /*
- * Fetch the first indirect block allocating if necessary.
- */
- --num;
- nb = ip->i_ib[indirs[0].in_off];
- if (nb == 0) {
-#if 0
- pref = ext2_blkpref(ip, lbn, 0, (int32_t *)0, 0);
-#else
- /* see the comment by ext2_blkpref. What we do here is
- to pretend that it'd be good for a block holding indirect
- pointers to be allocated near its predecessor in terms
- of indirection, or the last direct block.
- We shamelessly exploit the fact that i_ib immediately
- follows i_db.
- Godmar thinks it make sense to allocate i_ib[0] immediately
- after i_db[11], but it's not utterly clear whether this also
- applies to i_ib[1] and i_ib[0]
- */
-
- pref = ext2_blkpref(ip, lbn, indirs[0].in_off +
- EXT2_NDIR_BLOCKS, &ip->i_db[0], 0);
-#endif
- if ((error = ext2_alloc(ip, lbn, pref, (int)fs->s_blocksize,
- cred, &newb)) != 0)
- return (error);
- nb = newb;
- bp = getblk(vp, indirs[1].in_lbn, fs->s_blocksize, 0, 0, 0);
- bp->b_blkno = fsbtodb(fs, newb);
- vfs_bio_clrbuf(bp);
- /*
- * Write synchronously so that indirect blocks
- * never point at garbage.
- */
- if ((error = bwrite(bp)) != 0) {
- ext2_blkfree(ip, nb, fs->s_blocksize);
- return (error);
- }
- ip->i_ib[indirs[0].in_off] = newb;
- ip->i_flag |= IN_CHANGE | IN_UPDATE;
- }
- /*
- * Fetch through the indirect blocks, allocating as necessary.
- */
- for (i = 1;;) {
- error = bread(vp,
- indirs[i].in_lbn, (int)fs->s_blocksize, NOCRED, &bp);
- if (error) {
- brelse(bp);
- return (error);
- }
- bap = (int32_t *)bp->b_data;
- nb = bap[indirs[i].in_off];
- if (i == num)
- break;
- i += 1;
- if (nb != 0) {
- brelse(bp);
- continue;
- }
- if (pref == 0)
-#if 1
- /* see the comment above and by ext2_blkpref
- * I think this implements Linux policy, but
- * does it really make sense to allocate to
- * block containing pointers together ?
- * Also, will it ever succeed ?
- */
- pref = ext2_blkpref(ip, lbn, indirs[i].in_off, bap,
- bp->b_lblkno);
-#else
- pref = ext2_blkpref(ip, lbn, 0, (int32_t *)0, 0);
-#endif
- if ((error =
- ext2_alloc(ip, lbn, pref, (int)fs->s_blocksize, cred, &newb)) != 0) {
- brelse(bp);
- return (error);
- }
- nb = newb;
- nbp = getblk(vp, indirs[i].in_lbn, fs->s_blocksize, 0, 0, 0);
- nbp->b_blkno = fsbtodb(fs, nb);
- vfs_bio_clrbuf(nbp);
- /*
- * Write synchronously so that indirect blocks
- * never point at garbage.
- */
- if ((error = bwrite(nbp)) != 0) {
- ext2_blkfree(ip, nb, fs->s_blocksize);
- brelse(bp);
- return (error);
- }
- bap[indirs[i - 1].in_off] = nb;
- /*
- * If required, write synchronously, otherwise use
- * delayed write.
- */
- if (flags & B_SYNC) {
- bwrite(bp);
- } else {
- bdwrite(bp);
- }
- }
- /*
- * Get the data block, allocating if necessary.
- */
- if (nb == 0) {
- pref = ext2_blkpref(ip, lbn, indirs[i].in_off, &bap[0],
- bp->b_lblkno);
- if ((error = ext2_alloc(ip,
- lbn, pref, (int)fs->s_blocksize, cred, &newb)) != 0) {
- brelse(bp);
- return (error);
- }
- nb = newb;
- nbp = getblk(vp, lbn, fs->s_blocksize, 0, 0, 0);
- nbp->b_blkno = fsbtodb(fs, nb);
- if (flags & B_CLRBUF)
- vfs_bio_clrbuf(nbp);
- bap[indirs[i].in_off] = nb;
- /*
- * If required, write synchronously, otherwise use
- * delayed write.
- */
- if (flags & B_SYNC) {
- bwrite(bp);
- } else {
- bdwrite(bp);
- }
- *bpp = nbp;
- return (0);
- }
- brelse(bp);
- if (flags & B_CLRBUF) {
- error = bread(vp, lbn, (int)fs->s_blocksize, NOCRED, &nbp);
- if (error) {
- brelse(nbp);
- return (error);
- }
- } else {
- nbp = getblk(vp, lbn, fs->s_blocksize, 0, 0, 0);
- nbp->b_blkno = fsbtodb(fs, nb);
- }
- *bpp = nbp;
- return (0);
-}
diff --git a/sys/gnu/fs/ext2fs/ext2_bmap.c b/sys/gnu/fs/ext2fs/ext2_bmap.c
deleted file mode 100644
index 1260d97f3eef..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_bmap.c
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * Copyright (c) 1989, 1991, 1993
- * The Regents of the University of California. All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ufs_bmap.c 8.7 (Berkeley) 3/21/95
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/proc.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/resourcevar.h>
-#include <sys/stat.h>
-
-#include <gnu/ext2fs/inode.h>
-#include <gnu/ext2fs/ext2_mount.h>
-#include <gnu/ext2fs/ext2_extern.h>
-
-/*
- * Bmap converts a the logical block number of a file to its physical block
- * number on the disk. The conversion is done by using the logical block
- * number to index into the array of block pointers described by the dinode.
- */
-int
-ext2_bmap(ap)
- struct vop_bmap_args /* {
- struct vnode *a_vp;
- daddr_t a_bn;
- struct vnode **a_vpp;
- daddr_t *a_bnp;
- int *a_runp;
- int *a_runb;
- } */ *ap;
-{
- int32_t blkno;
- int error;
-
- /*
- * Check for underlying vnode requests and ensure that logical
- * to physical mapping is requested.
- */
- if (ap->a_vpp != NULL)
- *ap->a_vpp = VTOI(ap->a_vp)->i_devvp;
- if (ap->a_bnp == NULL)
- return (0);
-
- error = ext2_bmaparray(ap->a_vp, ap->a_bn, &blkno,
- ap->a_runp, ap->a_runb);
- *ap->a_bnp = blkno;
- return (error);
-}
-
-/*
- * Indirect blocks are now on the vnode for the file. They are given negative
- * logical block numbers. Indirect blocks are addressed by the negative
- * address of the first data block to which they point. Double indirect blocks
- * are addressed by one less than the address of the first indirect block to
- * which they point. Triple indirect blocks are addressed by one less than
- * the address of the first double indirect block to which they point.
- *
- * ufs_bmaparray does the bmap conversion, and if requested returns the
- * array of logical blocks which must be traversed to get to a block.
- * Each entry contains the offset into that block that gets you to the
- * next block and the disk address of the block (if it is assigned).
- */
-
-int
-ext2_bmaparray(vp, bn, bnp, runp, runb)
- struct vnode *vp;
- int32_t bn;
- int32_t *bnp;
- int *runp;
- int *runb;
-{
- struct inode *ip;
- struct buf *bp;
- struct ext2mount *ump;
- struct mount *mp;
- struct vnode *devvp;
- struct indir a[NIADDR+1], *ap;
- int32_t daddr;
- long metalbn;
- int error, num, maxrun = 0;
- int *nump;
-
- ap = NULL;
- ip = VTOI(vp);
- mp = vp->v_mount;
- ump = VFSTOEXT2(mp);
- devvp = ump->um_devvp;
-
- if (runp) {
- maxrun = mp->mnt_iosize_max / mp->mnt_stat.f_iosize - 1;
- *runp = 0;
- }
-
- if (runb) {
- *runb = 0;
- }
-
-
- ap = a;
- nump = &num;
- error = ext2_getlbns(vp, bn, ap, nump);
- if (error)
- return (error);
-
- num = *nump;
- if (num == 0) {
- *bnp = blkptrtodb(ump, ip->i_db[bn]);
- if (*bnp == 0) {
- *bnp = -1;
- } else if (runp) {
- int32_t bnb = bn;
- for (++bn; bn < NDADDR && *runp < maxrun &&
- is_sequential(ump, ip->i_db[bn - 1], ip->i_db[bn]);
- ++bn, ++*runp);
- bn = bnb;
- if (runb && (bn > 0)) {
- for (--bn; (bn >= 0) && (*runb < maxrun) &&
- is_sequential(ump, ip->i_db[bn],
- ip->i_db[bn+1]);
- --bn, ++*runb);
- }
- }
- return (0);
- }
-
-
- /* Get disk address out of indirect block array */
- daddr = ip->i_ib[ap->in_off];
-
- for (bp = NULL, ++ap; --num; ++ap) {
- /*
- * Exit the loop if there is no disk address assigned yet and
- * the indirect block isn't in the cache, or if we were
- * looking for an indirect block and we've found it.
- */
-
- metalbn = ap->in_lbn;
- if ((daddr == 0 && !incore(vp, metalbn)) || metalbn == bn)
- break;
- /*
- * If we get here, we've either got the block in the cache
- * or we have a disk address for it, go fetch it.
- */
- if (bp)
- bqrelse(bp);
-
- ap->in_exists = 1;
- bp = getblk(vp, metalbn, mp->mnt_stat.f_iosize, 0, 0, 0);
- if ((bp->b_flags & B_CACHE) == 0) {
-#ifdef DIAGNOSTIC
- if (!daddr)
- panic("ufs_bmaparray: indirect block not in cache");
-#endif
- bp->b_blkno = blkptrtodb(ump, daddr);
- bp->b_iocmd = BIO_READ;
- bp->b_flags &= ~B_INVAL;
- bp->b_ioflags &= ~BIO_ERROR;
- vfs_busy_pages(bp, 0);
- VOP_STRATEGY(bp->b_vp, bp);
- curproc->p_stats->p_ru.ru_inblock++; /* XXX */
- error = bufwait(bp);
- if (error) {
- brelse(bp);
- return (error);
- }
- }
-
- daddr = ((int32_t *)bp->b_data)[ap->in_off];
- if (num == 1 && daddr && runp) {
- for (bn = ap->in_off + 1;
- bn < MNINDIR(ump) && *runp < maxrun &&
- is_sequential(ump,
- ((int32_t *)bp->b_data)[bn - 1],
- ((int32_t *)bp->b_data)[bn]);
- ++bn, ++*runp);
- bn = ap->in_off;
- if (runb && bn) {
- for(--bn; bn >= 0 && *runb < maxrun &&
- is_sequential(ump, ((int32_t *)bp->b_data)[bn],
- ((int32_t *)bp->b_data)[bn+1]);
- --bn, ++*runb);
- }
- }
- }
- if (bp)
- bqrelse(bp);
-
- /*
- * Since this is FFS independent code, we are out of scope for the
- * definitions of BLK_NOCOPY and BLK_SNAP, but we do know that they
- * will fall in the range 1..um_seqinc, so we use that test and
- * return a request for a zeroed out buffer if attempts are made
- * to read a BLK_NOCOPY or BLK_SNAP block.
- */
- if ((ip->i_flags & SF_SNAPSHOT) && daddr > 0 && daddr < ump->um_seqinc){
- *bnp = -1;
- return (0);
- }
- *bnp = blkptrtodb(ump, daddr);
- if (*bnp == 0) {
- *bnp = -1;
- }
- return (0);
-}
-
-/*
- * Create an array of logical block number/offset pairs which represent the
- * path of indirect blocks required to access a data block. The first "pair"
- * contains the logical block number of the appropriate single, double or
- * triple indirect block and the offset into the inode indirect block array.
- * Note, the logical block number of the inode single/double/triple indirect
- * block appears twice in the array, once with the offset into the i_ib and
- * once with the offset into the page itself.
- */
-int
-ext2_getlbns(vp, bn, ap, nump)
- struct vnode *vp;
- int32_t bn;
- struct indir *ap;
- int *nump;
-{
- long blockcnt, metalbn, realbn;
- struct ext2mount *ump;
- int i, numlevels, off;
- int64_t qblockcnt;
-
- ump = VFSTOEXT2(vp->v_mount);
- if (nump)
- *nump = 0;
- numlevels = 0;
- realbn = bn;
- if ((long)bn < 0)
- bn = -(long)bn;
-
- /* The first NDADDR blocks are direct blocks. */
- if (bn < NDADDR)
- return (0);
-
- /*
- * Determine the number of levels of indirection. After this loop
- * is done, blockcnt indicates the number of data blocks possible
- * at the previous level of indirection, and NIADDR - i is the number
- * of levels of indirection needed to locate the requested block.
- */
- for (blockcnt = 1, i = NIADDR, bn -= NDADDR;; i--, bn -= blockcnt) {
- if (i == 0)
- return (EFBIG);
- /*
- * Use int64_t's here to avoid overflow for triple indirect
- * blocks when longs have 32 bits and the block size is more
- * than 4K.
- */
- qblockcnt = (int64_t)blockcnt * MNINDIR(ump);
- if (bn < qblockcnt)
- break;
- blockcnt = qblockcnt;
- }
-
- /* Calculate the address of the first meta-block. */
- if (realbn >= 0)
- metalbn = -(realbn - bn + NIADDR - i);
- else
- metalbn = -(-realbn - bn + NIADDR - i);
-
- /*
- * At each iteration, off is the offset into the bap array which is
- * an array of disk addresses at the current level of indirection.
- * The logical block number and the offset in that block are stored
- * into the argument array.
- */
- ap->in_lbn = metalbn;
- ap->in_off = off = NIADDR - i;
- ap->in_exists = 0;
- ap++;
- for (++numlevels; i <= NIADDR; i++) {
- /* If searching for a meta-data block, quit when found. */
- if (metalbn == realbn)
- break;
-
- off = (bn / blockcnt) % MNINDIR(ump);
-
- ++numlevels;
- ap->in_lbn = metalbn;
- ap->in_off = off;
- ap->in_exists = 0;
- ++ap;
-
- metalbn -= -1 + off * blockcnt;
- blockcnt /= MNINDIR(ump);
- }
- if (nump)
- *nump = numlevels;
- return (0);
-}
diff --git a/sys/gnu/fs/ext2fs/ext2_extern.h b/sys/gnu/fs/ext2fs/ext2_extern.h
deleted file mode 100644
index a8fcf09fc812..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_extern.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * modified for EXT2FS support in Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- */
-/*-
- * Copyright (c) 1991, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ffs_extern.h 8.3 (Berkeley) 4/16/94
- * $FreeBSD$
- */
-
-#ifndef _SYS_GNU_EXT2FS_EXT2_EXTERN_H_
-#define _SYS_GNU_EXT2FS_EXT2_EXTERN_H_
-
-struct ext2_inode;
-struct indir;
-struct inode;
-struct mount;
-struct vfsconf;
-struct vnode;
-
-int ext2_alloc(struct inode *,
- int32_t, int32_t, int, struct ucred *, int32_t *);
-int ext2_balloc(struct inode *,
- int32_t, int, struct ucred *, struct buf **, int);
-int ext2_blkatoff(struct vnode *, off_t, char **, struct buf **);
-void ext2_blkfree(struct inode *, int32_t, long);
-int32_t ext2_blkpref(struct inode *, int32_t, int, int32_t *, int32_t);
-int ext2_bmap(struct vop_bmap_args *);
-int ext2_bmaparray(struct vnode *, int32_t, int32_t *, int *, int *);
-void ext2_dirbad(struct inode *ip, doff_t offset, char *how);
-void ext2_ei2i(struct ext2_inode *, struct inode *);
-int ext2_getlbns(struct vnode *, int32_t, struct indir *, int *);
-void ext2_i2ei(struct inode *, struct ext2_inode *);
-int ext2_ihashget(dev_t, ino_t, int, struct vnode **);
-void ext2_ihashinit(void);
-void ext2_ihashins(struct inode *);
-struct vnode *
- ext2_ihashlookup(dev_t, ino_t);
-void ext2_ihashrem(struct inode *);
-void ext2_ihashuninit(void);
-void ext2_itimes(struct vnode *vp);
-int ext2_reallocblks(struct vop_reallocblks_args *);
-int ext2_reclaim(struct vop_reclaim_args *);
-void ext2_setblock(struct ext2_sb_info *, u_char *, int32_t);
-int ext2_truncate(struct vnode *, off_t, int, struct ucred *, struct thread *);
-int ext2_update(struct vnode *, int);
-int ext2_valloc(struct vnode *, int, struct ucred *, struct vnode **);
-int ext2_vfree(struct vnode *, ino_t, int);
-int ext2_vinit(struct mount *, vop_t **, vop_t **, struct vnode **vpp);
-int ext2_lookup(struct vop_cachedlookup_args *);
-int ext2_readdir(struct vop_readdir_args *);
-void ext2_print_inode(struct inode *);
-int ext2_direnter(struct inode *,
- struct vnode *, struct componentname *);
-int ext2_dirremove(struct vnode *, struct componentname *);
-int ext2_dirrewrite(struct inode *,
- struct inode *, struct componentname *);
-int ext2_dirempty(struct inode *, ino_t, struct ucred *);
-int ext2_checkpath(struct inode *, struct inode *, struct ucred *);
-struct ext2_group_desc * get_group_desc(struct mount * ,
- unsigned int , struct buf ** );
-int ext2_group_sparse(int group);
-void ext2_discard_prealloc(struct inode *);
-int ext2_inactive(struct vop_inactive_args *);
-int ext2_new_block(struct mount * mp, unsigned long goal,
- u_int32_t *prealloc_count, u_int32_t *prealloc_block);
-ino_t ext2_new_inode(const struct inode * dir, int mode);
-unsigned long ext2_count_free(struct buf *map, unsigned int numchars);
-void ext2_free_blocks(struct mount *mp, unsigned long block,
- unsigned long count);
-void ext2_free_inode(struct inode * inode);
-void mark_buffer_dirty(struct buf *bh);
-
-/* Flags to low-level allocation routines. */
-#define B_CLRBUF 0x01 /* Request allocated buffer be cleared. */
-#define B_SYNC 0x02 /* Do all allocations synchronously. */
-#define B_METAONLY 0x04 /* Return indirect block buffer. */
-#define B_NOWAIT 0x08 /* do not sleep to await lock */
-
-extern vop_t **ext2_vnodeop_p;
-extern vop_t **ext2_specop_p;
-extern vop_t **ext2_fifoop_p;
-
-#endif /* !_SYS_GNU_EXT2FS_EXT2_EXTERN_H_ */
diff --git a/sys/gnu/fs/ext2fs/ext2_fs.h b/sys/gnu/fs/ext2fs/ext2_fs.h
deleted file mode 100644
index 29435937181b..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_fs.h
+++ /dev/null
@@ -1,549 +0,0 @@
-/*
- * modified for EXT2FS support in Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- *
- * $FreeBSD$
- */
-/*
- * linux/include/linux/ext2_fs.h
- *
- * Copyright (C) 1992, 1993, 1994, 1995
- * Remy Card (card@masi.ibp.fr)
- * Laboratoire MASI - Institut Blaise Pascal
- * Universite Pierre et Marie Curie (Paris VI)
- *
- * from
- *
- * linux/include/linux/minix_fs.h
- *
- * Copyright (C) 1991, 1992 Linus Torvalds
- */
-
-#ifndef _LINUX_EXT2_FS_H
-#define _LINUX_EXT2_FS_H
-
-#include <sys/types.h>
-
-#define __u32 u_int32_t
-#define u32 u_int32_t
-#define __u16 u_int16_t
-#define __u8 u_int8_t
-
-#define __s32 int32_t
-#define __s16 int16_t
-#define __s8 int8_t
-
-#define umode_t mode_t
-#define loff_t off_t
-
-/*
- * The second extended filesystem constants/structures
- */
-
-/*
- * Define EXT2FS_DEBUG to produce debug messages
- */
-#undef EXT2FS_DEBUG
-
-/*
- * Define EXT2_PREALLOCATE to preallocate data blocks for expanding files
- */
-#define EXT2_PREALLOCATE
-#define EXT2_DEFAULT_PREALLOC_BLOCKS 8
-
-/*
- * The second extended file system version
- */
-#define EXT2FS_DATE "95/08/09"
-#define EXT2FS_VERSION "0.5b"
-
-/*
- * Debug code
- */
-#ifdef EXT2FS_DEBUG
-# define ext2_debug(f, a...) { \
- printf ("EXT2-fs DEBUG (%s, %d): %s:", \
- __FILE__, __LINE__, __func__); \
- printf (f, ## a); \
- }
-#else
-# define ext2_debug(f, a...) /**/
-#endif
-
-/*
- * Special inodes numbers
- */
-#define EXT2_BAD_INO 1 /* Bad blocks inode */
-#define EXT2_ROOT_INO 2 /* Root inode */
-#define EXT2_ACL_IDX_INO 3 /* ACL inode */
-#define EXT2_ACL_DATA_INO 4 /* ACL inode */
-#define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
-#define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
-
-/* First non-reserved inode for old ext2 filesystems */
-#define EXT2_GOOD_OLD_FIRST_INO 11
-
-/*
- * The second extended file system magic number
- */
-#define EXT2_SUPER_MAGIC 0xEF53
-
-/*
- * Maximal count of links to a file
- */
-#define EXT2_LINK_MAX 32000
-
-/*
- * Note: under FreeBSD, the "user" versions of the following macros are
- * used (and must be used) in most cases, because ((s)->u.ext2_sb.s_es is
- * not accessible. This depends on __KERNEL__ not being defined for
- * kernel builds under FreeBSD.
- */
-
-/*
- * Macro-instructions used to manage several block sizes
- */
-#define EXT2_MIN_BLOCK_SIZE 1024
-#define EXT2_MAX_BLOCK_SIZE 4096
-#define EXT2_MIN_BLOCK_LOG_SIZE 10
-#if defined(__KERNEL__) || (defined(__FreeBSD__) && defined(_KERNEL))
-# define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize)
-#else
-# define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
-#endif
-#define EXT2_ACLE_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
-#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
-#ifdef __KERNEL__
-# define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
-#else
-# define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
-#endif
-#ifdef notyet
-#ifdef __KERNEL__
-#define EXT2_ADDR_PER_BLOCK_BITS(s) ((s)->u.ext2_sb.s_addr_per_block_bits)
-#define EXT2_INODE_SIZE(s) ((s)->u.ext2_sb.s_inode_size)
-#define EXT2_FIRST_INO(s) ((s)->u.ext2_sb.s_first_ino)
-#else
-#define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
- EXT2_GOOD_OLD_INODE_SIZE : \
- (s)->s_inode_size)
-#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
- EXT2_GOOD_OLD_FIRST_INO : \
- (s)->s_first_ino)
-#endif
-#else /* !notyet */
-#define EXT2_INODES_PER_BLOCK(s) ((s)->s_inodes_per_block)
-/* Should be sizeof(struct ext2_inode): */
-#define EXT2_INODE_SIZE 128
-#define EXT2_FIRST_INO 11
-#endif /* notyet */
-
-/*
- * Macro-instructions used to manage fragments
- */
-#define EXT2_MIN_FRAG_SIZE 1024
-#define EXT2_MAX_FRAG_SIZE 4096
-#define EXT2_MIN_FRAG_LOG_SIZE 10
-#ifdef __KERNEL__
-# define EXT2_FRAG_SIZE(s) ((s)->u.ext2_sb.s_frag_size)
-# define EXT2_FRAGS_PER_BLOCK(s) ((s)->u.ext2_sb.s_frags_per_block)
-#else
-# if defined(_KERNEL) && defined(__FreeBSD__)
-# define EXT2_FRAG_SIZE(s) ((s)->s_frag_size)
-# else
-# define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
-# endif
-# define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
-#endif
-
-/*
- * ACL structures
- */
-struct ext2_acl_header /* Header of Access Control Lists */
-{
- __u32 aclh_size;
- __u32 aclh_file_count;
- __u32 aclh_acle_count;
- __u32 aclh_first_acle;
-};
-
-struct ext2_acl_entry /* Access Control List Entry */
-{
- __u32 acle_size;
- __u16 acle_perms; /* Access permissions */
- __u16 acle_type; /* Type of entry */
- __u16 acle_tag; /* User or group identity */
- __u16 acle_pad1;
- __u32 acle_next; /* Pointer on next entry for the */
- /* same inode or on next free entry */
-};
-
-/*
- * Structure of a blocks group descriptor
- */
-struct ext2_group_desc
-{
- __u32 bg_block_bitmap; /* Blocks bitmap block */
- __u32 bg_inode_bitmap; /* Inodes bitmap block */
- __u32 bg_inode_table; /* Inodes table block */
- __u16 bg_free_blocks_count; /* Free blocks count */
- __u16 bg_free_inodes_count; /* Free inodes count */
- __u16 bg_used_dirs_count; /* Directories count */
- __u16 bg_pad;
- __u32 bg_reserved[3];
-};
-
-/*
- * Macro-instructions used to manage group descriptors
- */
-#ifdef __KERNEL__
-# define EXT2_BLOCKS_PER_GROUP(s) ((s)->u.ext2_sb.s_blocks_per_group)
-# define EXT2_DESC_PER_BLOCK(s) ((s)->u.ext2_sb.s_desc_per_block)
-# define EXT2_INODES_PER_GROUP(s) ((s)->u.ext2_sb.s_inodes_per_group)
-# define EXT2_DESC_PER_BLOCK_BITS(s) ((s)->u.ext2_sb.s_desc_per_block_bits)
-#else
-# define EXT2_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
-# define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
-# define EXT2_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
-#endif
-
-/*
- * Constants relative to the data blocks
- */
-#define EXT2_NDIR_BLOCKS 12
-#define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
-#define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
-#define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
-#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
-#define EXT2_MAXSYMLINKLEN (EXT2_N_BLOCKS * sizeof (__u32))
-
-/*
- * Inode flags
- */
-#define EXT2_SECRM_FL 0x00000001 /* Secure deletion */
-#define EXT2_UNRM_FL 0x00000002 /* Undelete */
-#define EXT2_COMPR_FL 0x00000004 /* Compress file */
-#define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */
-#define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */
-#define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */
-#define EXT2_NODUMP_FL 0x00000040 /* do not dump file */
-#define EXT2_NOATIME_FL 0x00000080 /* do not update atime */
-/* Reserved for compression usage... */
-#define EXT2_DIRTY_FL 0x00000100
-#define EXT2_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
-#define EXT2_NOCOMP_FL 0x00000400 /* Don't compress */
-#define EXT2_ECOMPR_FL 0x00000800 /* Compression error */
-/* End compression flags --- maybe not all used */
-#define EXT2_BTREE_FL 0x00001000 /* btree format dir */
-#define EXT2_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
-
-#define EXT2_FL_USER_VISIBLE 0x00001FFF /* User visible flags */
-#define EXT2_FL_USER_MODIFIABLE 0x000000FF /* User modifiable flags */
-
-/*
- * ioctl commands
- */
-#define EXT2_IOC_GETFLAGS _IOR('f', 1, long)
-#define EXT2_IOC_SETFLAGS _IOW('f', 2, long)
-#define EXT2_IOC_GETVERSION _IOR('v', 1, long)
-#define EXT2_IOC_SETVERSION _IOW('v', 2, long)
-
-/*
- * Structure of an inode on the disk
- */
-struct ext2_inode {
- __u16 i_mode; /* File mode */
- __u16 i_uid; /* Owner Uid */
- __u32 i_size; /* Size in bytes */
- __u32 i_atime; /* Access time */
- __u32 i_ctime; /* Creation time */
- __u32 i_mtime; /* Modification time */
- __u32 i_dtime; /* Deletion Time */
- __u16 i_gid; /* Group Id */
- __u16 i_links_count; /* Links count */
- __u32 i_blocks; /* Blocks count */
- __u32 i_flags; /* File flags */
- union {
- struct {
- __u32 l_i_reserved1;
- } linux1;
- struct {
- __u32 h_i_translator;
- } hurd1;
- struct {
- __u32 m_i_reserved1;
- } masix1;
- } osd1; /* OS dependent 1 */
- __u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
- __u32 i_generation; /* File version (for NFS) */
- __u32 i_file_acl; /* File ACL */
- __u32 i_dir_acl; /* Directory ACL */
- __u32 i_faddr; /* Fragment address */
- union {
- struct {
- __u8 l_i_frag; /* Fragment number */
- __u8 l_i_fsize; /* Fragment size */
- __u16 i_pad1;
- __u32 l_i_reserved2[2];
- } linux2;
- struct {
- __u8 h_i_frag; /* Fragment number */
- __u8 h_i_fsize; /* Fragment size */
- __u16 h_i_mode_high;
- __u16 h_i_uid_high;
- __u16 h_i_gid_high;
- __u32 h_i_author;
- } hurd2;
- struct {
- __u8 m_i_frag; /* Fragment number */
- __u8 m_i_fsize; /* Fragment size */
- __u16 m_pad1;
- __u32 m_i_reserved2[2];
- } masix2;
- } osd2; /* OS dependent 2 */
-};
-
-#define i_size_high i_dir_acl
-
-#if defined(__KERNEL__) || defined(__linux__)
-#define i_reserved1 osd1.linux1.l_i_reserved1
-#define i_frag osd2.linux2.l_i_frag
-#define i_fsize osd2.linux2.l_i_fsize
-#define i_reserved2 osd2.linux2.l_i_reserved2
-#endif
-
-#ifdef __hurd__
-#define i_translator osd1.hurd1.h_i_translator
-#define i_frag osd2.hurd2.h_i_frag;
-#define i_fsize osd2.hurd2.h_i_fsize;
-#define i_uid_high osd2.hurd2.h_i_uid_high
-#define i_gid_high osd2.hurd2.h_i_gid_high
-#define i_author osd2.hurd2.h_i_author
-#endif
-
-#ifdef __masix__
-#define i_reserved1 osd1.masix1.m_i_reserved1
-#define i_frag osd2.masix2.m_i_frag
-#define i_fsize osd2.masix2.m_i_fsize
-#define i_reserved2 osd2.masix2.m_i_reserved2
-#endif
-
-/*
- * File system states
- */
-#define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
-#define EXT2_ERROR_FS 0x0002 /* Errors detected */
-
-/*
- * Mount flags
- */
-#define EXT2_MOUNT_CHECK_NORMAL 0x0001 /* Do some more checks */
-#define EXT2_MOUNT_CHECK_STRICT 0x0002 /* Do again more checks */
-#define EXT2_MOUNT_CHECK (EXT2_MOUNT_CHECK_NORMAL | \
- EXT2_MOUNT_CHECK_STRICT)
-#define EXT2_MOUNT_GRPID 0x0004 /* Create files with directory's group */
-#define EXT2_MOUNT_DEBUG 0x0008 /* Some debugging messages */
-#define EXT2_MOUNT_ERRORS_CONT 0x0010 /* Continue on errors */
-#define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */
-#define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
-#define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
-
-#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
-#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
-#define test_opt(sb, opt) ((sb)->u.ext2_sb.s_mount_opt & \
- EXT2_MOUNT_##opt)
-/*
- * Maximal mount counts between two filesystem checks
- */
-#define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
-#define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
-
-/*
- * Behaviour when detecting errors
- */
-#define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
-#define EXT2_ERRORS_RO 2 /* Remount fs read-only */
-#define EXT2_ERRORS_PANIC 3 /* Panic */
-#define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
-
-/*
- * Structure of the super block
- */
-struct ext2_super_block {
- __u32 s_inodes_count; /* Inodes count */
- __u32 s_blocks_count; /* Blocks count */
- __u32 s_r_blocks_count; /* Reserved blocks count */
- __u32 s_free_blocks_count; /* Free blocks count */
- __u32 s_free_inodes_count; /* Free inodes count */
- __u32 s_first_data_block; /* First Data Block */
- __u32 s_log_block_size; /* Block size */
- __s32 s_log_frag_size; /* Fragment size */
- __u32 s_blocks_per_group; /* # Blocks per group */
- __u32 s_frags_per_group; /* # Fragments per group */
- __u32 s_inodes_per_group; /* # Inodes per group */
- __u32 s_mtime; /* Mount time */
- __u32 s_wtime; /* Write time */
- __u16 s_mnt_count; /* Mount count */
- __s16 s_max_mnt_count; /* Maximal mount count */
- __u16 s_magic; /* Magic signature */
- __u16 s_state; /* File system state */
- __u16 s_errors; /* Behaviour when detecting errors */
- __u16 s_minor_rev_level; /* minor revision level */
- __u32 s_lastcheck; /* time of last check */
- __u32 s_checkinterval; /* max. time between checks */
- __u32 s_creator_os; /* OS */
- __u32 s_rev_level; /* Revision level */
- __u16 s_def_resuid; /* Default uid for reserved blocks */
- __u16 s_def_resgid; /* Default gid for reserved blocks */
- /*
- * These fields are for EXT2_DYNAMIC_REV superblocks only.
- *
- * Note: the difference between the compatible feature set and
- * the incompatible feature set is that if there is a bit set
- * in the incompatible feature set that the kernel doesn't
- * know about, it should refuse to mount the filesystem.
- *
- * e2fsck's requirements are more strict; if it doesn't know
- * about a feature in either the compatible or incompatible
- * feature set, it must abort and not try to meddle with
- * things it doesn't understand...
- */
- __u32 s_first_ino; /* First non-reserved inode */
- __u16 s_inode_size; /* size of inode structure */
- __u16 s_block_group_nr; /* block group # of this superblock */
- __u32 s_feature_compat; /* compatible feature set */
- __u32 s_feature_incompat; /* incompatible feature set */
- __u32 s_feature_ro_compat; /* readonly-compatible feature set */
- __u8 s_uuid[16]; /* 128-bit uuid for volume */
- char s_volume_name[16]; /* volume name */
- char s_last_mounted[64]; /* directory where last mounted */
- __u32 s_algorithm_usage_bitmap; /* For compression */
- /*
- * Performance hints. Directory preallocation should only
- * happen if the EXT2_COMPAT_PREALLOC flag is on.
- */
- __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
- __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
- __u16 s_padding1;
- __u32 s_reserved[204]; /* Padding to the end of the block */
-};
-
-#ifdef __KERNEL__
-#define EXT2_SB(sb) (&((sb)->u.ext2_sb))
-#else
-/* Assume that user mode programs are passing in an ext2fs superblock, not
- * a kernel struct super_block. This will allow us to call the feature-test
- * macros from user land. */
-#define EXT2_SB(sb) (sb)
-#endif
-
-/*
- * Codes for operating systems
- */
-#define EXT2_OS_LINUX 0
-#define EXT2_OS_HURD 1
-#define EXT2_OS_MASIX 2
-#define EXT2_OS_FREEBSD 3
-#define EXT2_OS_LITES 4
-
-/*
- * Revision levels
- */
-#define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
-#define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
-
-#define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
-#define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
-
-#define EXT2_GOOD_OLD_INODE_SIZE 128
-
-/*
- * Feature set definitions
- */
-
-#define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
- ( EXT2_SB(sb)->s_feature_compat & (mask) )
-#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
- ( EXT2_SB(sb)->s_feature_ro_compat & (mask) )
-#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
- ( EXT2_SB(sb)->s_feature_incompat & (mask) )
-
-#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
-
-#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
-#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
-#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
-
-#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
-#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
-
-#define EXT2_FEATURE_COMPAT_SUPP 0
-#define EXT2_FEATURE_INCOMPAT_SUPP EXT2_FEATURE_INCOMPAT_FILETYPE
-#ifdef notyet
-#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
- EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
- EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
-#else
-#define EXT2_FEATURE_RO_COMPAT_SUPP EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
-#endif
-
-/*
- * Default values for user and/or group using reserved blocks
- */
-#define EXT2_DEF_RESUID 0
-#define EXT2_DEF_RESGID 0
-
-/*
- * Structure of a directory entry
- */
-#define EXT2_NAME_LEN 255
-
-struct ext2_dir_entry {
- __u32 inode; /* Inode number */
- __u16 rec_len; /* Directory entry length */
- __u16 name_len; /* Name length */
- char name[EXT2_NAME_LEN]; /* File name */
-};
-
-/*
- * The new version of the directory entry. Since EXT2 structures are
- * stored in intel byte order, and the name_len field could never be
- * bigger than 255 chars, it's safe to reclaim the extra byte for the
- * file_type field.
- */
-struct ext2_dir_entry_2 {
- __u32 inode; /* Inode number */
- __u16 rec_len; /* Directory entry length */
- __u8 name_len; /* Name length */
- __u8 file_type;
- char name[EXT2_NAME_LEN]; /* File name */
-};
-
-/*
- * Ext2 directory file types. Only the low 3 bits are used. The
- * other bits are reserved for now.
- */
-#define EXT2_FT_UNKNOWN 0
-#define EXT2_FT_REG_FILE 1
-#define EXT2_FT_DIR 2
-#define EXT2_FT_CHRDEV 3
-#define EXT2_FT_BLKDEV 4
-#define EXT2_FT_FIFO 5
-#define EXT2_FT_SOCK 6
-#define EXT2_FT_SYMLINK 7
-
-#define EXT2_FT_MAX 8
-
-/*
- * EXT2_DIR_PAD defines the directory entries boundaries
- *
- * NOTE: It must be a multiple of 4
- */
-#define EXT2_DIR_PAD 4
-#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
-#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
- ~EXT2_DIR_ROUND)
-
-#endif /* _LINUX_EXT2_FS_H */
diff --git a/sys/gnu/fs/ext2fs/ext2_fs_sb.h b/sys/gnu/fs/ext2fs/ext2_fs_sb.h
deleted file mode 100644
index 85f71bf39c7e..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_fs_sb.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * modified for EXT2FS support in Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- */
-/*
- * linux/include/linux/ext2_fs_sb.h
- *
- * Copyright (C) 1992, 1993, 1994, 1995
- * Remy Card (card@masi.ibp.fr)
- * Laboratoire MASI - Institut Blaise Pascal
- * Universite Pierre et Marie Curie (Paris VI)
- *
- * from
- *
- * linux/include/linux/minix_fs_sb.h
- *
- * Copyright (C) 1991, 1992 Linus Torvalds
- */
-
-#ifndef _LINUX_EXT2_FS_SB
-#define _LINUX_EXT2_FS_SB
-
-/*
- * The following is not needed anymore since the descriptors buffer
- * heads are now dynamically allocated
- */
-/* #define EXT2_MAX_GROUP_DESC 8 */
-
-#define EXT2_MAX_GROUP_LOADED 8
-
-#define buffer_head buf
-#define MAXMNTLEN 512
-
-/*
- * second extended-fs super-block data in memory
- */
-struct ext2_sb_info {
- unsigned long s_frag_size; /* Size of a fragment in bytes */
- unsigned long s_frags_per_block;/* Number of fragments per block */
- unsigned long s_inodes_per_block;/* Number of inodes per block */
- unsigned long s_frags_per_group;/* Number of fragments in a group */
- unsigned long s_blocks_per_group;/* Number of blocks in a group */
- unsigned long s_inodes_per_group;/* Number of inodes in a group */
- unsigned long s_itb_per_group; /* Number of inode table blocks per group */
- unsigned long s_db_per_group; /* Number of descriptor blocks per group */
- unsigned long s_desc_per_block; /* Number of group descriptors per block */
- unsigned long s_groups_count; /* Number of groups in the fs */
- struct buffer_head * s_sbh; /* Buffer containing the super block */
- struct ext2_super_block * s_es; /* Pointer to the super block in the buffer */
- struct buffer_head ** s_group_desc;
- unsigned short s_loaded_inode_bitmaps;
- unsigned short s_loaded_block_bitmaps;
- unsigned long s_inode_bitmap_number[EXT2_MAX_GROUP_LOADED];
- struct buffer_head * s_inode_bitmap[EXT2_MAX_GROUP_LOADED];
- unsigned long s_block_bitmap_number[EXT2_MAX_GROUP_LOADED];
- struct buffer_head * s_block_bitmap[EXT2_MAX_GROUP_LOADED];
- int s_rename_lock;
- unsigned long s_mount_opt;
- unsigned short s_resuid;
- unsigned short s_resgid;
- unsigned short s_mount_state;
- /*
- stuff that FFS keeps in its super block or that linux
- has in its non-ext2 specific super block and which is
- generally considered useful
- */
- unsigned long s_blocksize;
- unsigned long s_blocksize_bits;
- unsigned int s_bshift; /* = log2(s_blocksize) */
- quad_t s_qbmask; /* = s_blocksize - 1 */
- unsigned int s_fsbtodb; /* shift to get disk block */
- char s_rd_only; /* read-only */
- char s_dirt; /* fs modified flag */
- char s_wasvalid; /* valid at mount time */
-
- char fs_fsmnt[MAXMNTLEN]; /* name mounted on */
-};
-
-#endif /* _LINUX_EXT2_FS_SB */
diff --git a/sys/gnu/fs/ext2fs/ext2_inode.c b/sys/gnu/fs/ext2fs/ext2_inode.c
deleted file mode 100644
index 806c8a333113..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_inode.c
+++ /dev/null
@@ -1,552 +0,0 @@
-/*
- * modified for Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- */
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ffs_inode.c 8.5 (Berkeley) 12/30/93
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/mount.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/vnode.h>
-#include <sys/malloc.h>
-
-#include <vm/vm.h>
-#include <vm/vm_extern.h>
-
-#include <gnu/ext2fs/inode.h>
-#include <gnu/ext2fs/ext2_mount.h>
-#include <gnu/ext2fs/ext2_fs.h>
-#include <gnu/ext2fs/ext2_fs_sb.h>
-#include <gnu/ext2fs/fs.h>
-#include <gnu/ext2fs/ext2_extern.h>
-
-static int ext2_indirtrunc(struct inode *, int32_t, int32_t, int32_t, int,
- long *);
-
-/*
- * Update the access, modified, and inode change times as specified by the
- * IN_ACCESS, IN_UPDATE, and IN_CHANGE flags respectively. Write the inode
- * to disk if the IN_MODIFIED flag is set (it may be set initially, or by
- * the timestamp update). The IN_LAZYMOD flag is set to force a write
- * later if not now. If we write now, then clear both IN_MODIFIED and
- * IN_LAZYMOD to reflect the presumably successful write, and if waitfor is
- * set, then wait for the write to complete.
- */
-int
-ext2_update(vp, waitfor)
- struct vnode *vp;
- int waitfor;
-{
- struct ext2_sb_info *fs;
- struct buf *bp;
- struct inode *ip;
- int error;
-
- ext2_itimes(vp);
- ip = VTOI(vp);
- if ((ip->i_flag & IN_MODIFIED) == 0)
- return (0);
- ip->i_flag &= ~(IN_LAZYMOD | IN_MODIFIED);
- if (vp->v_mount->mnt_flag & MNT_RDONLY)
- return (0);
- fs = ip->i_e2fs;
- if ((error = bread(ip->i_devvp,
- fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
- (int)fs->s_blocksize, NOCRED, &bp)) != 0) {
- brelse(bp);
- return (error);
- }
- ext2_i2ei(ip, (struct ext2_inode *)((char *)bp->b_data +
- EXT2_INODE_SIZE * ino_to_fsbo(fs, ip->i_number)));
-/*
- if (waitfor && (vp->v_mount->mnt_flag & MNT_ASYNC) == 0)
- return (bwrite(bp));
- else {
-*/
- bdwrite(bp);
- return (0);
-/*
- }
-*/
-}
-
-#define SINGLE 0 /* index of single indirect block */
-#define DOUBLE 1 /* index of double indirect block */
-#define TRIPLE 2 /* index of triple indirect block */
-/*
- * Truncate the inode oip to at most length size, freeing the
- * disk blocks.
- */
-int
-ext2_truncate(vp, length, flags, cred, td)
- struct vnode *vp;
- off_t length;
- int flags;
- struct ucred *cred;
- struct thread *td;
-{
- struct vnode *ovp = vp;
- int32_t lastblock;
- struct inode *oip;
- int32_t bn, lbn, lastiblock[NIADDR], indir_lbn[NIADDR];
- int32_t oldblks[NDADDR + NIADDR], newblks[NDADDR + NIADDR];
- struct ext2_sb_info *fs;
- struct buf *bp;
- int offset, size, level;
- long count, nblocks, blocksreleased = 0;
- int aflags, error, i, allerror;
- off_t osize;
-/*
-printf("ext2_truncate called %d to %d\n", VTOI(ovp)->i_number, length);
-*/ /*
- * negative file sizes will totally break the code below and
- * are not meaningful anyways.
- */
- if (length < 0)
- return EFBIG;
-
- oip = VTOI(ovp);
- if (ovp->v_type == VLNK &&
- oip->i_size < ovp->v_mount->mnt_maxsymlinklen) {
-#if DIAGNOSTIC
- if (length != 0)
- panic("ext2_truncate: partial truncate of symlink");
-#endif
- bzero((char *)&oip->i_shortlink, (u_int)oip->i_size);
- oip->i_size = 0;
- oip->i_flag |= IN_CHANGE | IN_UPDATE;
- return (ext2_update(ovp, 1));
- }
- if (oip->i_size == length) {
- oip->i_flag |= IN_CHANGE | IN_UPDATE;
- return (ext2_update(ovp, 0));
- }
- fs = oip->i_e2fs;
- osize = oip->i_size;
- ext2_discard_prealloc(oip);
- /*
- * Lengthen the size of the file. We must ensure that the
- * last byte of the file is allocated. Since the smallest
- * value of oszie is 0, length will be at least 1.
- */
- if (osize < length) {
- offset = blkoff(fs, length - 1);
- lbn = lblkno(fs, length - 1);
- aflags = B_CLRBUF;
- if (flags & IO_SYNC)
- aflags |= B_SYNC;
- vnode_pager_setsize(ovp, length);
- if ((error = ext2_balloc(oip, lbn, offset + 1, cred, &bp,
- aflags)) != 0)
- return (error);
- oip->i_size = length;
- if (aflags & IO_SYNC)
- bwrite(bp);
- else
- bawrite(bp);
- oip->i_flag |= IN_CHANGE | IN_UPDATE;
- return (ext2_update(ovp, 1));
- }
- /*
- * Shorten the size of the file. If the file is not being
- * truncated to a block boundry, the contents of the
- * partial block following the end of the file must be
- * zero'ed in case it ever become accessible again because
- * of subsequent file growth.
- */
- /* I don't understand the comment above */
- offset = blkoff(fs, length);
- if (offset == 0) {
- oip->i_size = length;
- } else {
- lbn = lblkno(fs, length);
- aflags = B_CLRBUF;
- if (flags & IO_SYNC)
- aflags |= B_SYNC;
- if ((error = ext2_balloc(oip, lbn, offset, cred, &bp,
- aflags)) != 0)
- return (error);
- oip->i_size = length;
- size = blksize(fs, oip, lbn);
- bzero((char *)bp->b_data + offset, (u_int)(size - offset));
- allocbuf(bp, size);
- if (aflags & IO_SYNC)
- bwrite(bp);
- else
- bawrite(bp);
- }
- /*
- * Calculate index into inode's block list of
- * last direct and indirect blocks (if any)
- * which we want to keep. Lastblock is -1 when
- * the file is truncated to 0.
- */
- lastblock = lblkno(fs, length + fs->s_blocksize - 1) - 1;
- lastiblock[SINGLE] = lastblock - NDADDR;
- lastiblock[DOUBLE] = lastiblock[SINGLE] - NINDIR(fs);
- lastiblock[TRIPLE] = lastiblock[DOUBLE] - NINDIR(fs) * NINDIR(fs);
- nblocks = btodb(fs->s_blocksize);
- /*
- * Update file and block pointers on disk before we start freeing
- * blocks. If we crash before free'ing blocks below, the blocks
- * will be returned to the free list. lastiblock values are also
- * normalized to -1 for calls to ext2_indirtrunc below.
- */
- bcopy((caddr_t)&oip->i_db[0], (caddr_t)oldblks, sizeof oldblks);
- for (level = TRIPLE; level >= SINGLE; level--)
- if (lastiblock[level] < 0) {
- oip->i_ib[level] = 0;
- lastiblock[level] = -1;
- }
- for (i = NDADDR - 1; i > lastblock; i--)
- oip->i_db[i] = 0;
- oip->i_flag |= IN_CHANGE | IN_UPDATE;
- allerror = ext2_update(ovp, 1);
-
- /*
- * Having written the new inode to disk, save its new configuration
- * and put back the old block pointers long enough to process them.
- * Note that we save the new block configuration so we can check it
- * when we are done.
- */
- bcopy((caddr_t)&oip->i_db[0], (caddr_t)newblks, sizeof newblks);
- bcopy((caddr_t)oldblks, (caddr_t)&oip->i_db[0], sizeof oldblks);
- oip->i_size = osize;
- error = vtruncbuf(ovp, cred, td, length, (int)fs->s_blocksize);
- if (error && (allerror == 0))
- allerror = error;
-
- /*
- * Indirect blocks first.
- */
- indir_lbn[SINGLE] = -NDADDR;
- indir_lbn[DOUBLE] = indir_lbn[SINGLE] - NINDIR(fs) - 1;
- indir_lbn[TRIPLE] = indir_lbn[DOUBLE] - NINDIR(fs) * NINDIR(fs) - 1;
- for (level = TRIPLE; level >= SINGLE; level--) {
- bn = oip->i_ib[level];
- if (bn != 0) {
- error = ext2_indirtrunc(oip, indir_lbn[level],
- fsbtodb(fs, bn), lastiblock[level], level, &count);
- if (error)
- allerror = error;
- blocksreleased += count;
- if (lastiblock[level] < 0) {
- oip->i_ib[level] = 0;
- ext2_blkfree(oip, bn, fs->s_frag_size);
- blocksreleased += nblocks;
- }
- }
- if (lastiblock[level] >= 0)
- goto done;
- }
-
- /*
- * All whole direct blocks or frags.
- */
- for (i = NDADDR - 1; i > lastblock; i--) {
- long bsize;
-
- bn = oip->i_db[i];
- if (bn == 0)
- continue;
- oip->i_db[i] = 0;
- bsize = blksize(fs, oip, i);
- ext2_blkfree(oip, bn, bsize);
- blocksreleased += btodb(bsize);
- }
- if (lastblock < 0)
- goto done;
-
- /*
- * Finally, look for a change in size of the
- * last direct block; release any frags.
- */
- bn = oip->i_db[lastblock];
- if (bn != 0) {
- long oldspace, newspace;
-
- /*
- * Calculate amount of space we're giving
- * back as old block size minus new block size.
- */
- oldspace = blksize(fs, oip, lastblock);
- oip->i_size = length;
- newspace = blksize(fs, oip, lastblock);
- if (newspace == 0)
- panic("itrunc: newspace");
- if (oldspace - newspace > 0) {
- /*
- * Block number of space to be free'd is
- * the old block # plus the number of frags
- * required for the storage we're keeping.
- */
- bn += numfrags(fs, newspace);
- ext2_blkfree(oip, bn, oldspace - newspace);
- blocksreleased += btodb(oldspace - newspace);
- }
- }
-done:
-#if DIAGNOSTIC
- for (level = SINGLE; level <= TRIPLE; level++)
- if (newblks[NDADDR + level] != oip->i_ib[level])
- panic("itrunc1");
- for (i = 0; i < NDADDR; i++)
- if (newblks[i] != oip->i_db[i])
- panic("itrunc2");
- VI_LOCK(ovp);
- if (length == 0 && (!TAILQ_EMPTY(&ovp->v_dirtyblkhd) ||
- !TAILQ_EMPTY(&ovp->v_cleanblkhd)))
- panic("itrunc3");
- VI_UNLOCK(ovp);
-#endif /* DIAGNOSTIC */
- /*
- * Put back the real size.
- */
- oip->i_size = length;
- oip->i_blocks -= blocksreleased;
- if (oip->i_blocks < 0) /* sanity */
- oip->i_blocks = 0;
- oip->i_flag |= IN_CHANGE;
- vnode_pager_setsize(ovp, length);
- return (allerror);
-}
-
-/*
- * Release blocks associated with the inode ip and stored in the indirect
- * block bn. Blocks are free'd in LIFO order up to (but not including)
- * lastbn. If level is greater than SINGLE, the block is an indirect block
- * and recursive calls to indirtrunc must be used to cleanse other indirect
- * blocks.
- *
- * NB: triple indirect blocks are untested.
- */
-
-static int
-ext2_indirtrunc(ip, lbn, dbn, lastbn, level, countp)
- struct inode *ip;
- int32_t lbn, lastbn;
- int32_t dbn;
- int level;
- long *countp;
-{
- struct buf *bp;
- struct ext2_sb_info *fs = ip->i_e2fs;
- struct vnode *vp;
- int32_t *bap, *copy, nb, nlbn, last;
- long blkcount, factor;
- int i, nblocks, blocksreleased = 0;
- int error = 0, allerror = 0;
-
- /*
- * Calculate index in current block of last
- * 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);
- last = lastbn;
- if (lastbn > 0)
- last /= factor;
- nblocks = btodb(fs->s_blocksize);
- /*
- * Get buffer of block pointers, zero those entries corresponding
- * to blocks to be free'd, and update on disk copy first. Since
- * double(triple) indirect before single(double) indirect, calls
- * to bmap on these blocks will fail. However, we already have
- * the on disk address, so we have to set the b_blkno field
- * explicitly instead of letting bread do everything for us.
- */
- vp = ITOV(ip);
- bp = getblk(vp, lbn, (int)fs->s_blocksize, 0, 0, 0);
- if (bp->b_flags & (B_DONE | B_DELWRI)) {
- } else {
- bp->b_iocmd = BIO_READ;
- if (bp->b_bcount > bp->b_bufsize)
- panic("ext2_indirtrunc: bad buffer size");
- bp->b_blkno = dbn;
- vfs_busy_pages(bp, 0);
- VOP_STRATEGY(vp, bp);
- error = bufwait(bp);
- }
- if (error) {
- brelse(bp);
- *countp = 0;
- return (error);
- }
-
- bap = (int32_t *)bp->b_data;
- MALLOC(copy, int32_t *, fs->s_blocksize, M_TEMP, M_WAITOK);
- bcopy((caddr_t)bap, (caddr_t)copy, (u_int)fs->s_blocksize);
- bzero((caddr_t)&bap[last + 1],
- (u_int)(NINDIR(fs) - (last + 1)) * sizeof (int32_t));
- if (last == -1)
- bp->b_flags |= B_INVAL;
- error = bwrite(bp);
- if (error)
- allerror = error;
- bap = copy;
-
- /*
- * Recursively free totally unused blocks.
- */
- for (i = NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last;
- i--, nlbn += factor) {
- nb = bap[i];
- if (nb == 0)
- continue;
- if (level > SINGLE) {
- if ((error = ext2_indirtrunc(ip, nlbn,
- fsbtodb(fs, nb), (int32_t)-1, level - 1, &blkcount)) != 0)
- allerror = error;
- blocksreleased += blkcount;
- }
- ext2_blkfree(ip, nb, fs->s_blocksize);
- blocksreleased += nblocks;
- }
-
- /*
- * Recursively free last partial block.
- */
- if (level > SINGLE && lastbn >= 0) {
- last = lastbn % factor;
- nb = bap[i];
- if (nb != 0) {
- if ((error = ext2_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
- last, level - 1, &blkcount)) != 0)
- allerror = error;
- blocksreleased += blkcount;
- }
- }
- FREE(copy, M_TEMP);
- *countp = blocksreleased;
- return (allerror);
-}
-
-/*
- * discard preallocated blocks
- */
-int
-ext2_inactive(ap)
- struct vop_inactive_args /* {
- struct vnode *a_vp;
- struct thread *a_td;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct inode *ip = VTOI(vp);
- struct thread *td = ap->a_td;
- int mode, error = 0;
-
- ext2_discard_prealloc(ip);
- if (prtactive && vrefcnt(vp) != 0)
- vprint("ext2_inactive: pushing active", vp);
-
- /*
- * Ignore inodes related to stale file handles.
- */
- if (ip->i_mode == 0)
- goto out;
- if (ip->i_nlink <= 0) {
- (void) vn_write_suspend_wait(vp, NULL, V_WAIT);
- error = ext2_truncate(vp, (off_t)0, 0, NOCRED, td);
- ip->i_rdev = 0;
- mode = ip->i_mode;
- ip->i_mode = 0;
- ip->i_flag |= IN_CHANGE | IN_UPDATE;
- ext2_vfree(vp, ip->i_number, mode);
- }
- if (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) {
- if ((ip->i_flag & (IN_CHANGE | IN_UPDATE | IN_MODIFIED)) == 0 &&
- vn_write_suspend_wait(vp, NULL, V_NOWAIT)) {
- ip->i_flag &= ~IN_ACCESS;
- } else {
- (void) vn_write_suspend_wait(vp, NULL, V_WAIT);
- ext2_update(vp, 0);
- }
- }
-out:
- VOP_UNLOCK(vp, 0, td);
- /*
- * If we are done with the inode, reclaim it
- * so that it can be reused immediately.
- */
- if (ip->i_mode == 0)
- vrecycle(vp, NULL, td);
- return (error);
-}
-
-/*
- * Reclaim an inode so that it can be used for other purposes.
- */
-int
-ext2_reclaim(ap)
- struct vop_reclaim_args /* {
- struct vnode *a_vp;
- struct thread *a_td;
- } */ *ap;
-{
- struct inode *ip;
- struct vnode *vp = ap->a_vp;
-
- if (prtactive && vrefcnt(vp) != 0)
- vprint("ufs_reclaim: pushing active", vp);
- ip = VTOI(vp);
- if (ip->i_flag & IN_LAZYMOD) {
- ip->i_flag |= IN_MODIFIED;
- ext2_update(vp, 0);
- }
- /*
- * Remove the inode from its hash chain.
- */
- ext2_ihashrem(ip);
- /*
- * Purge old data structures associated with the inode.
- */
- cache_purge(vp);
- if (ip->i_devvp) {
- vrele(ip->i_devvp);
- ip->i_devvp = 0;
- }
- FREE(vp->v_data, M_EXT2NODE);
- vp->v_data = 0;
- return (0);
-}
diff --git a/sys/gnu/fs/ext2fs/ext2_inode_cnv.c b/sys/gnu/fs/ext2fs/ext2_inode_cnv.c
deleted file mode 100644
index d64e5498776b..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_inode_cnv.c
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright (c) 1995 The University of Utah and
- * the Computer Systems Laboratory at the University of Utah (CSL).
- * All rights reserved.
- *
- * Permission to use, copy, modify and distribute this software is hereby
- * granted provided that (1) source code retains these copyright, permission,
- * and disclaimer notices, and (2) redistributions including binaries
- * reproduce the notices in supporting documentation, and (3) all advertising
- * materials mentioning features or use of this software display the following
- * acknowledgement: ``This product includes software developed by the
- * Computer Systems Laboratory at the University of Utah.''
- *
- * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
- * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
- * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * CSL requests users of this software to return to csl-dist@cs.utah.edu any
- * improvements that they make and grant CSL redistribution rights.
- *
- * Utah $Hdr$
- * $FreeBSD$
- */
-
-/*
- * routines to convert on disk ext2 inodes into inodes and back
- */
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/lock.h>
-#include <sys/stat.h>
-#include <sys/vnode.h>
-
-#include <gnu/ext2fs/inode.h>
-#include <gnu/ext2fs/ext2_fs.h>
-#include <gnu/ext2fs/ext2_extern.h>
-
-void
-ext2_print_inode( in )
- struct inode *in;
-{
- int i;
-
- printf( "Inode: %5d", in->i_number);
- printf( /* "Inode: %5d" */
- " Type: %10s Mode: 0x%o Flags: 0x%x Version: %d\n",
- "n/a", in->i_mode, in->i_flags, in->i_gen);
- printf( "User: %5lu Group: %5lu Size: %lu\n",
- (unsigned long)in->i_uid, (unsigned long)in->i_gid,
- (unsigned long)in->i_size);
- printf( "Links: %3d Blockcount: %d\n",
- in->i_nlink, in->i_blocks);
- printf( "ctime: 0x%x", in->i_ctime);
- printf( "atime: 0x%x", in->i_atime);
- printf( "mtime: 0x%x", in->i_mtime);
- printf( "BLOCKS: ");
- for(i=0; i < (in->i_blocks <= 24 ? ((in->i_blocks+1)/2): 12); i++)
- printf("%d ", in->i_db[i]);
- printf("\n");
-}
-
-/*
- * raw ext2 inode to inode
- */
-void
-ext2_ei2i(ei, ip)
- struct ext2_inode *ei;
- struct inode *ip;
-{
- int i;
-
- ip->i_nlink = ei->i_links_count;
- /* Godmar thinks - if the link count is zero, then the inode is
- unused - according to ext2 standards. Ufs marks this fact
- by setting i_mode to zero - why ?
- I can see that this might lead to problems in an undelete.
- */
- ip->i_mode = ei->i_links_count ? ei->i_mode : 0;
- ip->i_size = ei->i_size;
- ip->i_atime = ei->i_atime;
- ip->i_mtime = ei->i_mtime;
- ip->i_ctime = ei->i_ctime;
- ip->i_flags = 0;
- ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
- ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
- ip->i_blocks = ei->i_blocks;
- ip->i_gen = ei->i_generation;
- ip->i_uid = ei->i_uid;
- ip->i_gid = ei->i_gid;
- /* XXX use memcpy */
- for(i = 0; i < NDADDR; i++)
- ip->i_db[i] = ei->i_block[i];
- for(i = 0; i < NIADDR; i++)
- ip->i_ib[i] = ei->i_block[EXT2_NDIR_BLOCKS + i];
-}
-
-/*
- * inode to raw ext2 inode
- */
-void
-ext2_i2ei(ip, ei)
- struct inode *ip;
- struct ext2_inode *ei;
-{
- int i;
-
- ei->i_mode = ip->i_mode;
- ei->i_links_count = ip->i_nlink;
- /*
- Godmar thinks: if dtime is nonzero, ext2 says this inode
- has been deleted, this would correspond to a zero link count
- */
- ei->i_dtime = ei->i_links_count ? 0 : ip->i_mtime;
- ei->i_size = ip->i_size;
- ei->i_atime = ip->i_atime;
- ei->i_mtime = ip->i_mtime;
- ei->i_ctime = ip->i_ctime;
- ei->i_flags = ip->i_flags;
- ei->i_flags = 0;
- ei->i_flags |= (ip->i_flags & APPEND) ? EXT2_APPEND_FL: 0;
- ei->i_flags |= (ip->i_flags & IMMUTABLE) ? EXT2_IMMUTABLE_FL: 0;
- ei->i_blocks = ip->i_blocks;
- ei->i_generation = ip->i_gen;
- ei->i_uid = ip->i_uid;
- ei->i_gid = ip->i_gid;
- /* XXX use memcpy */
- for(i = 0; i < NDADDR; i++)
- ei->i_block[i] = ip->i_db[i];
- for(i = 0; i < NIADDR; i++)
- ei->i_block[EXT2_NDIR_BLOCKS + i] = ip->i_ib[i];
-}
diff --git a/sys/gnu/fs/ext2fs/ext2_linux_balloc.c b/sys/gnu/fs/ext2fs/ext2_linux_balloc.c
deleted file mode 100644
index 435661bb57da..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_linux_balloc.c
+++ /dev/null
@@ -1,610 +0,0 @@
-/*
- * modified for Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- *
- * $FreeBSD$
- */
-/*
- * linux/fs/ext2/balloc.c
- *
- * Copyright (C) 1992, 1993, 1994, 1995
- * Remy Card (card@masi.ibp.fr)
- * Laboratoire MASI - Institut Blaise Pascal
- * Universite Pierre et Marie Curie (Paris VI)
- *
- * Enhanced block allocation by Stephen Tweedie (sct@dcs.ed.ac.uk), 1993
- */
-
-/*
- * The free blocks are managed by bitmaps. A file system contains several
- * blocks groups. Each group contains 1 bitmap block for blocks, 1 bitmap
- * block for inodes, N blocks for the inode table and data blocks.
- *
- * The file system contains group descriptors which are located after the
- * super block. Each descriptor contains the number of the bitmap block and
- * the free blocks count in the block. The descriptors are loaded in memory
- * when a file system is mounted (see ext2_read_super).
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/mount.h>
-#include <sys/vnode.h>
-
-#include <gnu/ext2fs/inode.h>
-#include <gnu/ext2fs/ext2_mount.h>
-#include <gnu/ext2fs/ext2_extern.h>
-#include <gnu/ext2fs/ext2_fs.h>
-#include <gnu/ext2fs/ext2_fs_sb.h>
-#include <gnu/ext2fs/fs.h>
-
-#ifdef __i386__
-#include <gnu/ext2fs/i386-bitops.h>
-#elif __alpha__
-#include <gnu/ext2fs/alpha-bitops.h>
-#else
-#error Provide a bitops.h file, please!
-#endif
-
-#define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
-
-/* got rid of get_group_desc since it can already be found in
- * ext2_linux_ialloc.c
- */
-
-static void read_block_bitmap (struct mount * mp,
- unsigned int block_group,
- unsigned long bitmap_nr)
-{
- struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
- struct ext2_group_desc * gdp;
- struct buffer_head * bh;
- int error;
-
- gdp = get_group_desc (mp, block_group, NULL);
- if ((error = bread (VFSTOEXT2(mp)->um_devvp,
- fsbtodb(sb, gdp->bg_block_bitmap),sb->s_blocksize, NOCRED, &bh)) != 0)
- panic ( "read_block_bitmap: "
- "Cannot read block bitmap - "
- "block_group = %d, block_bitmap = %lu",
- block_group, (unsigned long) gdp->bg_block_bitmap);
- sb->s_block_bitmap_number[bitmap_nr] = block_group;
- sb->s_block_bitmap[bitmap_nr] = bh;
- LCK_BUF(bh)
-}
-
-/*
- * load_block_bitmap loads the block bitmap for a blocks group
- *
- * It maintains a cache for the last bitmaps loaded. This cache is managed
- * with a LRU algorithm.
- *
- * Notes:
- * 1/ There is one cache per mounted file system.
- * 2/ If the file system contains less than EXT2_MAX_GROUP_LOADED groups,
- * this function reads the bitmap without maintaining a LRU cache.
- */
-static int load__block_bitmap (struct mount * mp,
- unsigned int block_group)
-{
- int i, j;
- struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
- unsigned long block_bitmap_number;
- struct buffer_head * block_bitmap;
-
- if (block_group >= sb->s_groups_count)
- panic ( "load_block_bitmap: "
- "block_group >= groups_count - "
- "block_group = %d, groups_count = %lu",
- block_group, sb->s_groups_count);
-
- if (sb->s_groups_count <= EXT2_MAX_GROUP_LOADED) {
- if (sb->s_block_bitmap[block_group]) {
- if (sb->s_block_bitmap_number[block_group] !=
- block_group)
- panic ( "load_block_bitmap: "
- "block_group != block_bitmap_number");
- else
- return block_group;
- } else {
- read_block_bitmap (mp, block_group, block_group);
- return block_group;
- }
- }
-
- for (i = 0; i < sb->s_loaded_block_bitmaps &&
- sb->s_block_bitmap_number[i] != block_group; i++)
- ;
- if (i < sb->s_loaded_block_bitmaps &&
- sb->s_block_bitmap_number[i] == block_group) {
- block_bitmap_number = sb->s_block_bitmap_number[i];
- block_bitmap = sb->s_block_bitmap[i];
- for (j = i; j > 0; j--) {
- sb->s_block_bitmap_number[j] =
- sb->s_block_bitmap_number[j - 1];
- sb->s_block_bitmap[j] =
- sb->s_block_bitmap[j - 1];
- }
- sb->s_block_bitmap_number[0] = block_bitmap_number;
- sb->s_block_bitmap[0] = block_bitmap;
- } else {
- if (sb->s_loaded_block_bitmaps < EXT2_MAX_GROUP_LOADED)
- sb->s_loaded_block_bitmaps++;
- else
- ULCK_BUF(sb->s_block_bitmap[EXT2_MAX_GROUP_LOADED - 1])
-
- for (j = sb->s_loaded_block_bitmaps - 1; j > 0; j--) {
- sb->s_block_bitmap_number[j] =
- sb->s_block_bitmap_number[j - 1];
- sb->s_block_bitmap[j] =
- sb->s_block_bitmap[j - 1];
- }
- read_block_bitmap (mp, block_group, 0);
- }
- return 0;
-}
-
-static __inline int load_block_bitmap (struct mount * mp,
- unsigned int block_group)
-{
- struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
- if (sb->s_loaded_block_bitmaps > 0 &&
- sb->s_block_bitmap_number[0] == block_group)
- return 0;
-
- if (sb->s_groups_count <= EXT2_MAX_GROUP_LOADED &&
- sb->s_block_bitmap_number[block_group] == block_group &&
- sb->s_block_bitmap[block_group])
- return block_group;
-
- return load__block_bitmap (mp, block_group);
-}
-
-void ext2_free_blocks (struct mount * mp, unsigned long block,
- unsigned long count)
-{
- struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
- struct buffer_head * bh;
- struct buffer_head * bh2;
- unsigned long block_group;
- unsigned long bit;
- unsigned long i;
- int bitmap_nr;
- struct ext2_group_desc * gdp;
- struct ext2_super_block * es = sb->s_es;
-
- if (!sb) {
- printf ("ext2_free_blocks: nonexistent device");
- return;
- }
- lock_super (VFSTOEXT2(mp)->um_devvp);
- if (block < es->s_first_data_block ||
- (block + count) > es->s_blocks_count) {
- printf ( "ext2_free_blocks: "
- "Freeing blocks not in datazone - "
- "block = %lu, count = %lu", block, count);
- unlock_super (VFSTOEXT2(mp)->um_devvp);
- return;
- }
-
- ext2_debug ("freeing blocks %lu to %lu\n", block, block+count-1);
-
- block_group = (block - es->s_first_data_block) /
- EXT2_BLOCKS_PER_GROUP(sb);
- bit = (block - es->s_first_data_block) % EXT2_BLOCKS_PER_GROUP(sb);
- if (bit + count > EXT2_BLOCKS_PER_GROUP(sb))
- panic ( "ext2_free_blocks: "
- "Freeing blocks across group boundary - "
- "Block = %lu, count = %lu",
- block, count);
- bitmap_nr = load_block_bitmap (mp, block_group);
- bh = sb->s_block_bitmap[bitmap_nr];
- gdp = get_group_desc (mp, block_group, &bh2);
-
- if (/* test_opt (sb, CHECK_STRICT) && assume always strict ! */
- (in_range (gdp->bg_block_bitmap, block, count) ||
- in_range (gdp->bg_inode_bitmap, block, count) ||
- in_range (block, gdp->bg_inode_table,
- sb->s_itb_per_group) ||
- in_range (block + count - 1, gdp->bg_inode_table,
- sb->s_itb_per_group)))
- panic ( "ext2_free_blocks: "
- "Freeing blocks in system zones - "
- "Block = %lu, count = %lu",
- block, count);
-
- for (i = 0; i < count; i++) {
- if (!clear_bit (bit + i, bh->b_data))
- printf ("ext2_free_blocks: "
- "bit already cleared for block %lu",
- block);
- else {
- gdp->bg_free_blocks_count++;
- es->s_free_blocks_count++;
- }
- }
-
- mark_buffer_dirty(bh2);
- mark_buffer_dirty(bh);
-/****
- if (sb->s_flags & MS_SYNCHRONOUS) {
- ll_rw_block (WRITE, 1, &bh);
- wait_on_buffer (bh);
- }
-****/
- sb->s_dirt = 1;
- unlock_super (VFSTOEXT2(mp)->um_devvp);
- return;
-}
-
-/*
- * ext2_new_block uses a goal block to assist allocation. If the goal is
- * free, or there is a free block within 32 blocks of the goal, that block
- * is allocated. Otherwise a forward search is made for a free block; within
- * each block group the search first looks for an entire free byte in the block
- * bitmap, and then for any free bit if that fails.
- */
-int ext2_new_block (struct mount * mp, unsigned long goal,
- u_int32_t * prealloc_count,
- u_int32_t * prealloc_block)
-{
- struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
- struct buffer_head * bh;
- struct buffer_head * bh2;
- char * p, * r;
- int i, j, k, tmp;
- int bitmap_nr;
- struct ext2_group_desc * gdp;
- struct ext2_super_block * es = sb->s_es;
-
-#ifdef EXT2FS_DEBUG
- static int goal_hits = 0, goal_attempts = 0;
-#endif
- if (!sb) {
- printf ("ext2_new_block: nonexistent device");
- return 0;
- }
- lock_super (VFSTOEXT2(mp)->um_devvp);
-
- ext2_debug ("goal=%lu.\n", goal);
-
-repeat:
- /*
- * First, test whether the goal block is free.
- */
- if (goal < es->s_first_data_block || goal >= es->s_blocks_count)
- goal = es->s_first_data_block;
- i = (goal - es->s_first_data_block) / EXT2_BLOCKS_PER_GROUP(sb);
- gdp = get_group_desc (mp, i, &bh2);
- if (gdp->bg_free_blocks_count > 0) {
- j = ((goal - es->s_first_data_block) % EXT2_BLOCKS_PER_GROUP(sb));
-#ifdef EXT2FS_DEBUG
- if (j)
- goal_attempts++;
-#endif
- bitmap_nr = load_block_bitmap (mp, i);
- bh = sb->s_block_bitmap[bitmap_nr];
-
- ext2_debug ("goal is at %d:%d.\n", i, j);
-
- if (!test_bit(j, bh->b_data)) {
-#ifdef EXT2FS_DEBUG
- goal_hits++;
- ext2_debug ("goal bit allocated.\n");
-#endif
- goto got_block;
- }
- if (j) {
- /*
- * The goal was occupied; search forward for a free
- * block within the next XX blocks.
- *
- * end_goal is more or less random, but it has to be
- * less than EXT2_BLOCKS_PER_GROUP. Aligning up to the
- * next 64-bit boundary is simple..
- */
- int end_goal = (j + 63) & ~63;
- j = find_next_zero_bit(bh->b_data, end_goal, j);
- if (j < end_goal)
- goto got_block;
- }
-
- ext2_debug ("Bit not found near goal\n");
-
- /*
- * There has been no free block found in the near vicinity
- * of the goal: do a search forward through the block groups,
- * searching in each group first for an entire free byte in
- * the bitmap and then for any free bit.
- *
- * Search first in the remainder of the current group; then,
- * cyclicly search through the rest of the groups.
- */
- p = ((char *) bh->b_data) + (j >> 3);
- r = memscan(p, 0, (EXT2_BLOCKS_PER_GROUP(sb) - j + 7) >> 3);
- k = (r - ((char *) bh->b_data)) << 3;
- if (k < EXT2_BLOCKS_PER_GROUP(sb)) {
- j = k;
- goto search_back;
- }
- k = find_next_zero_bit ((unsigned long *) bh->b_data,
- EXT2_BLOCKS_PER_GROUP(sb),
- j);
- if (k < EXT2_BLOCKS_PER_GROUP(sb)) {
- j = k;
- goto got_block;
- }
- }
-
- ext2_debug ("Bit not found in block group %d.\n", i);
-
- /*
- * Now search the rest of the groups. We assume that
- * i and gdp correctly point to the last group visited.
- */
- for (k = 0; k < sb->s_groups_count; k++) {
- i++;
- if (i >= sb->s_groups_count)
- i = 0;
- gdp = get_group_desc (mp, i, &bh2);
- if (gdp->bg_free_blocks_count > 0)
- break;
- }
- if (k >= sb->s_groups_count) {
- unlock_super (VFSTOEXT2(mp)->um_devvp);
- return 0;
- }
- bitmap_nr = load_block_bitmap (mp, i);
- bh = sb->s_block_bitmap[bitmap_nr];
- r = memscan(bh->b_data, 0, EXT2_BLOCKS_PER_GROUP(sb) >> 3);
- j = (r - bh->b_data) << 3;
-
- if (j < EXT2_BLOCKS_PER_GROUP(sb))
- goto search_back;
- else
- j = find_first_zero_bit ((unsigned long *) bh->b_data,
- EXT2_BLOCKS_PER_GROUP(sb));
- if (j >= EXT2_BLOCKS_PER_GROUP(sb)) {
- printf ( "ext2_new_block: "
- "Free blocks count corrupted for block group %d", i);
- unlock_super (VFSTOEXT2(mp)->um_devvp);
- return 0;
- }
-
-search_back:
- /*
- * We have succeeded in finding a free byte in the block
- * bitmap. Now search backwards up to 7 bits to find the
- * start of this group of free blocks.
- */
- for (k = 0; k < 7 && j > 0 && !test_bit (j - 1, bh->b_data); k++, j--);
-
-got_block:
-
- ext2_debug ("using block group %d(%d)\n", i, gdp->bg_free_blocks_count);
-
- tmp = j + i * EXT2_BLOCKS_PER_GROUP(sb) + es->s_first_data_block;
-
- if (/* test_opt (sb, CHECK_STRICT) && we are always strict. */
- (tmp == gdp->bg_block_bitmap ||
- tmp == gdp->bg_inode_bitmap ||
- in_range (tmp, gdp->bg_inode_table, sb->s_itb_per_group)))
- panic ( "ext2_new_block: "
- "Allocating block in system zone - "
- "%dth block = %u in group %u", j, tmp, i);
-
- if (set_bit (j, bh->b_data)) {
- printf ( "ext2_new_block: "
- "bit already set for block %d", j);
- goto repeat;
- }
-
- ext2_debug ("found bit %d\n", j);
-
- /*
- * Do block preallocation now if required.
- */
-#ifdef EXT2_PREALLOCATE
- if (prealloc_block) {
- *prealloc_count = 0;
- *prealloc_block = tmp + 1;
- for (k = 1;
- k < 8 && (j + k) < EXT2_BLOCKS_PER_GROUP(sb); k++) {
- if (set_bit (j + k, bh->b_data))
- break;
- (*prealloc_count)++;
- }
- gdp->bg_free_blocks_count -= *prealloc_count;
- es->s_free_blocks_count -= *prealloc_count;
- ext2_debug ("Preallocated a further %lu bits.\n",
- *prealloc_count);
- }
-#endif
-
- j = tmp;
-
- mark_buffer_dirty(bh);
-/****
- if (sb->s_flags & MS_SYNCHRONOUS) {
- ll_rw_block (WRITE, 1, &bh);
- wait_on_buffer (bh);
- }
-****/
- if (j >= es->s_blocks_count) {
- printf ( "ext2_new_block: "
- "block >= blocks count - "
- "block_group = %d, block=%d", i, j);
- unlock_super (VFSTOEXT2(mp)->um_devvp);
- return 0;
- }
-
- ext2_debug ("allocating block %d. "
- "Goal hits %d of %d.\n", j, goal_hits, goal_attempts);
-
- gdp->bg_free_blocks_count--;
- mark_buffer_dirty(bh2);
- es->s_free_blocks_count--;
- sb->s_dirt = 1;
- unlock_super (VFSTOEXT2(mp)->um_devvp);
- return j;
-}
-
-#ifdef unused
-static unsigned long ext2_count_free_blocks (struct mount * mp)
-{
- struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
-#ifdef EXT2FS_DEBUG
- struct ext2_super_block * es;
- unsigned long desc_count, bitmap_count, x;
- int bitmap_nr;
- struct ext2_group_desc * gdp;
- int i;
-
- lock_super (VFSTOEXT2(mp)->um_devvp);
- es = sb->s_es;
- desc_count = 0;
- bitmap_count = 0;
- gdp = NULL;
- for (i = 0; i < sb->s_groups_count; i++) {
- gdp = get_group_desc (mp, i, NULL);
- desc_count += gdp->bg_free_blocks_count;
- bitmap_nr = load_block_bitmap (mp, i);
- x = ext2_count_free (sb->s_block_bitmap[bitmap_nr],
- sb->s_blocksize);
- ext2_debug ("group %d: stored = %d, counted = %lu\n",
- i, gdp->bg_free_blocks_count, x);
- bitmap_count += x;
- }
- ext2_debug( "stored = %lu, computed = %lu, %lu\n",
- es->s_free_blocks_count, desc_count, bitmap_count);
- unlock_super (VFSTOEXT2(mp)->um_devvp);
- return bitmap_count;
-#else
- return sb->s_es->s_free_blocks_count;
-#endif
-}
-#endif /* unused */
-
-static __inline int block_in_use (unsigned long block,
- struct ext2_sb_info * sb,
- unsigned char * map)
-{
- return test_bit ((block - sb->s_es->s_first_data_block) %
- EXT2_BLOCKS_PER_GROUP(sb), map);
-}
-
-static int test_root(int a, int b)
-{
- if (a == 0)
- return 1;
- while (1) {
- if (a == 1)
- return 1;
- if (a % b)
- return 0;
- a = a / b;
- }
-}
-
-int ext2_group_sparse(int group)
-{
- return (test_root(group, 3) || test_root(group, 5) ||
- test_root(group, 7));
-}
-
-#ifdef unused
-static void ext2_check_blocks_bitmap (struct mount * mp)
-{
- struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
- struct buffer_head * bh;
- struct ext2_super_block * es;
- unsigned long desc_count, bitmap_count, x;
- unsigned long desc_blocks;
- int bitmap_nr;
- struct ext2_group_desc * gdp;
- int i, j;
-
- lock_super (VFSTOEXT2(mp)->um_devvp);
- es = sb->s_es;
- desc_count = 0;
- bitmap_count = 0;
- gdp = NULL;
- desc_blocks = (sb->s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
- EXT2_DESC_PER_BLOCK(sb);
- for (i = 0; i < sb->s_groups_count; i++) {
- gdp = get_group_desc (mp, i, NULL);
- desc_count += gdp->bg_free_blocks_count;
- bitmap_nr = load_block_bitmap (mp, i);
- bh = sb->s_block_bitmap[bitmap_nr];
-
- if (!(es->s_feature_ro_compat &
- EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) ||
- ext2_group_sparse(i)) {
- if (!test_bit (0, bh->b_data))
- printf ("ext2_check_blocks_bitmap: "
- "Superblock in group %d "
- "is marked free", i);
-
- for (j = 0; j < desc_blocks; j++)
- if (!test_bit (j + 1, bh->b_data))
- printf ("ext2_check_blocks_bitmap: "
- "Descriptor block #%d in group "
- "%d is marked free", j, i);
- }
-
- if (!block_in_use (gdp->bg_block_bitmap, sb, bh->b_data))
- printf ("ext2_check_blocks_bitmap: "
- "Block bitmap for group %d is marked free",
- i);
-
- if (!block_in_use (gdp->bg_inode_bitmap, sb, bh->b_data))
- printf ("ext2_check_blocks_bitmap: "
- "Inode bitmap for group %d is marked free",
- i);
-
- for (j = 0; j < sb->s_itb_per_group; j++)
- if (!block_in_use (gdp->bg_inode_table + j, sb, bh->b_data))
- printf ("ext2_check_blocks_bitmap: "
- "Block #%d of the inode table in "
- "group %d is marked free", j, i);
-
- x = ext2_count_free (bh, sb->s_blocksize);
- if (gdp->bg_free_blocks_count != x)
- printf ("ext2_check_blocks_bitmap: "
- "Wrong free blocks count for group %d, "
- "stored = %d, counted = %lu", i,
- gdp->bg_free_blocks_count, x);
- bitmap_count += x;
- }
- if (es->s_free_blocks_count != bitmap_count)
- printf ("ext2_check_blocks_bitmap: "
- "Wrong free blocks count in super block, "
- "stored = %lu, counted = %lu",
- (unsigned long) es->s_free_blocks_count, bitmap_count);
- unlock_super (VFSTOEXT2(mp)->um_devvp);
-}
-#endif /* unused */
-
-/*
- * this function is taken from
- * linux/fs/ext2/bitmap.c
- */
-
-static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
-
-unsigned long ext2_count_free (struct buffer_head * map, unsigned int numchars)
-{
- unsigned int i;
- unsigned long sum = 0;
-
- if (!map)
- return (0);
- for (i = 0; i < numchars; i++)
- sum += nibblemap[map->b_data[i] & 0xf] +
- nibblemap[(map->b_data[i] >> 4) & 0xf];
- return (sum);
-}
diff --git a/sys/gnu/fs/ext2fs/ext2_linux_ialloc.c b/sys/gnu/fs/ext2fs/ext2_linux_ialloc.c
deleted file mode 100644
index 64d96b21104c..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_linux_ialloc.c
+++ /dev/null
@@ -1,514 +0,0 @@
-/*
- * modified for Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- *
- * $FreeBSD$
- */
-/*
- * linux/fs/ext2/ialloc.c
- *
- * Copyright (C) 1992, 1993, 1994, 1995
- * Remy Card (card@masi.ibp.fr)
- * Laboratoire MASI - Institut Blaise Pascal
- * Universite Pierre et Marie Curie (Paris VI)
- *
- * BSD ufs-inspired inode and directory allocation by
- * Stephen Tweedie (sct@dcs.ed.ac.uk), 1993
- */
-
-/*
- * The free inodes are managed by bitmaps. A file system contains several
- * blocks groups. Each group contains 1 bitmap block for blocks, 1 bitmap
- * block for inodes, N blocks for the inode table and data blocks.
- *
- * The file system contains group descriptors which are located after the
- * super block. Each descriptor contains the number of the bitmap block and
- * the free blocks count in the block. The descriptors are loaded in memory
- * when a file system is mounted (see ext2_read_super).
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/mount.h>
-#include <sys/vnode.h>
-
-#include <gnu/ext2fs/inode.h>
-#include <gnu/ext2fs/ext2_mount.h>
-#include <gnu/ext2fs/ext2_extern.h>
-#include <gnu/ext2fs/ext2_fs.h>
-#include <gnu/ext2fs/ext2_fs_sb.h>
-#include <gnu/ext2fs/fs.h>
-#include <sys/stat.h>
-
-#ifdef __i386__
-#include <gnu/ext2fs/i386-bitops.h>
-#elif __alpha__
-#include <gnu/ext2fs/alpha-bitops.h>
-#else
-#error please provide bit operation functions
-#endif
-
-/* this is supposed to mark a buffer dirty on ready for delayed writing
- */
-void mark_buffer_dirty(struct buf *bh)
-{
- int s;
-
- s = splbio();
- bh->b_flags |= B_DIRTY;
- splx(s);
-}
-
-struct ext2_group_desc * get_group_desc (struct mount * mp,
- unsigned int block_group,
- struct buffer_head ** bh)
-{
- struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
- unsigned long group_desc;
- unsigned long desc;
- struct ext2_group_desc * gdp;
-
- if (block_group >= sb->s_groups_count)
- panic ("get_group_desc: "
- "block_group >= groups_count - "
- "block_group = %d, groups_count = %lu",
- block_group, sb->s_groups_count);
-
- group_desc = block_group / EXT2_DESC_PER_BLOCK(sb);
- desc = block_group % EXT2_DESC_PER_BLOCK(sb);
- if (!sb->s_group_desc[group_desc])
- panic ( "get_group_desc:"
- "Group descriptor not loaded - "
- "block_group = %d, group_desc = %lu, desc = %lu",
- block_group, group_desc, desc);
- gdp = (struct ext2_group_desc *)
- sb->s_group_desc[group_desc]->b_data;
- if (bh)
- *bh = sb->s_group_desc[group_desc];
- return gdp + desc;
-}
-
-static void read_inode_bitmap (struct mount * mp,
- unsigned long block_group,
- unsigned int bitmap_nr)
-{
- struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
- struct ext2_group_desc * gdp;
- struct buffer_head * bh;
- int error;
-
- gdp = get_group_desc (mp, block_group, NULL);
- if ((error = bread (VFSTOEXT2(mp)->um_devvp,
- fsbtodb(sb, gdp->bg_inode_bitmap),
- sb->s_blocksize,
- NOCRED, &bh)) != 0)
- panic ( "read_inode_bitmap:"
- "Cannot read inode bitmap - "
- "block_group = %lu, inode_bitmap = %lu",
- block_group, (unsigned long) gdp->bg_inode_bitmap);
- sb->s_inode_bitmap_number[bitmap_nr] = block_group;
- sb->s_inode_bitmap[bitmap_nr] = bh;
- LCK_BUF(bh)
-}
-
-/*
- * load_inode_bitmap loads the inode bitmap for a blocks group
- *
- * It maintains a cache for the last bitmaps loaded. This cache is managed
- * with a LRU algorithm.
- *
- * Notes:
- * 1/ There is one cache per mounted file system.
- * 2/ If the file system contains less than EXT2_MAX_GROUP_LOADED groups,
- * this function reads the bitmap without maintaining a LRU cache.
- */
-static int load_inode_bitmap (struct mount * mp,
- unsigned int block_group)
-{
- struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
- int i, j;
- unsigned long inode_bitmap_number;
- struct buffer_head * inode_bitmap;
-
- if (block_group >= sb->s_groups_count)
- panic ("load_inode_bitmap:"
- "block_group >= groups_count - "
- "block_group = %d, groups_count = %lu",
- block_group, sb->s_groups_count);
- if (sb->s_loaded_inode_bitmaps > 0 &&
- sb->s_inode_bitmap_number[0] == block_group)
- return 0;
- if (sb->s_groups_count <= EXT2_MAX_GROUP_LOADED) {
- if (sb->s_inode_bitmap[block_group]) {
- if (sb->s_inode_bitmap_number[block_group] !=
- block_group)
- panic ( "load_inode_bitmap:"
- "block_group != inode_bitmap_number");
- else
- return block_group;
- } else {
- read_inode_bitmap (mp, block_group, block_group);
- return block_group;
- }
- }
-
- for (i = 0; i < sb->s_loaded_inode_bitmaps &&
- sb->s_inode_bitmap_number[i] != block_group;
- i++)
- ;
- if (i < sb->s_loaded_inode_bitmaps &&
- sb->s_inode_bitmap_number[i] == block_group) {
- inode_bitmap_number = sb->s_inode_bitmap_number[i];
- inode_bitmap = sb->s_inode_bitmap[i];
- for (j = i; j > 0; j--) {
- sb->s_inode_bitmap_number[j] =
- sb->s_inode_bitmap_number[j - 1];
- sb->s_inode_bitmap[j] =
- sb->s_inode_bitmap[j - 1];
- }
- sb->s_inode_bitmap_number[0] = inode_bitmap_number;
- sb->s_inode_bitmap[0] = inode_bitmap;
- } else {
- if (sb->s_loaded_inode_bitmaps < EXT2_MAX_GROUP_LOADED)
- sb->s_loaded_inode_bitmaps++;
- else
- ULCK_BUF(sb->s_inode_bitmap[EXT2_MAX_GROUP_LOADED - 1])
- for (j = sb->s_loaded_inode_bitmaps - 1; j > 0; j--) {
- sb->s_inode_bitmap_number[j] =
- sb->s_inode_bitmap_number[j - 1];
- sb->s_inode_bitmap[j] =
- sb->s_inode_bitmap[j - 1];
- }
- read_inode_bitmap (mp, block_group, 0);
- }
- return 0;
-}
-
-
-void ext2_free_inode (struct inode * inode)
-{
- struct ext2_sb_info * sb;
- struct buffer_head * bh;
- struct buffer_head * bh2;
- unsigned long block_group;
- unsigned long bit;
- int bitmap_nr;
- struct ext2_group_desc * gdp;
- struct ext2_super_block * es;
-
- if (!inode)
- return;
-
- if (inode->i_nlink) {
- printf ("ext2_free_inode: inode has nlink=%d\n",
- inode->i_nlink);
- return;
- }
-
- ext2_debug ("freeing inode %lu\n", inode->i_number);
-
- sb = inode->i_e2fs;
- lock_super (DEVVP(inode));
- if (inode->i_number < EXT2_FIRST_INO ||
- inode->i_number > sb->s_es->s_inodes_count) {
- printf ("free_inode reserved inode or nonexistent inode");
- unlock_super (DEVVP(inode));
- return;
- }
- es = sb->s_es;
- block_group = (inode->i_number - 1) / EXT2_INODES_PER_GROUP(sb);
- bit = (inode->i_number - 1) % EXT2_INODES_PER_GROUP(sb);
- bitmap_nr = load_inode_bitmap (ITOV(inode)->v_mount, block_group);
- bh = sb->s_inode_bitmap[bitmap_nr];
- if (!clear_bit (bit, bh->b_data))
- printf ( "ext2_free_inode:"
- "bit already cleared for inode %lu",
- (unsigned long)inode->i_number);
- else {
- gdp = get_group_desc (ITOV(inode)->v_mount, block_group, &bh2);
- gdp->bg_free_inodes_count++;
- if (S_ISDIR(inode->i_mode))
- gdp->bg_used_dirs_count--;
- mark_buffer_dirty(bh2);
- es->s_free_inodes_count++;
- }
- mark_buffer_dirty(bh);
-/*** XXX
- if (sb->s_flags & MS_SYNCHRONOUS) {
- ll_rw_block (WRITE, 1, &bh);
- wait_on_buffer (bh);
- }
-***/
- sb->s_dirt = 1;
- unlock_super (DEVVP(inode));
-}
-
-#if linux
-/*
- * This function increments the inode version number
- *
- * This may be used one day by the NFS server
- */
-static void inc_inode_version (struct inode * inode,
- struct ext2_group_desc *gdp,
- int mode)
-{
- unsigned long inode_block;
- struct buffer_head * bh;
- struct ext2_inode * raw_inode;
-
- inode_block = gdp->bg_inode_table + (((inode->i_number - 1) %
- EXT2_INODES_PER_GROUP(inode->i_sb)) /
- EXT2_INODES_PER_BLOCK(inode->i_sb));
- bh = bread (inode->i_sb->s_dev, inode_block, inode->i_sb->s_blocksize);
- if (!bh) {
- printf ("inc_inode_version Cannot load inode table block - "
- "inode=%lu, inode_block=%lu\n",
- inode->i_number, inode_block);
- inode->u.ext2_i.i_version = 1;
- return;
- }
- raw_inode = ((struct ext2_inode *) bh->b_data) +
- (((inode->i_number - 1) %
- EXT2_INODES_PER_GROUP(inode->i_sb)) %
- EXT2_INODES_PER_BLOCK(inode->i_sb));
- raw_inode->i_version++;
- inode->u.ext2_i.i_version = raw_inode->i_version;
- bdwrite (bh);
-}
-
-#endif /* linux */
-
-/*
- * There are two policies for allocating an inode. If the new inode is
- * a directory, then a forward search is made for a block group with both
- * free space and a low directory-to-inode ratio; if that fails, then of
- * the groups with above-average free space, that group with the fewest
- * directories already is chosen.
- *
- * For other inodes, search forward from the parent directory\'s block
- * group to find a free inode.
- */
-/*
- * this functino has been reduced to the actual 'find the inode number' part
- */
-ino_t ext2_new_inode (const struct inode * dir, int mode)
-{
- struct ext2_sb_info * sb;
- struct buffer_head * bh;
- struct buffer_head * bh2;
- int i, j, avefreei;
- int bitmap_nr;
- struct ext2_group_desc * gdp;
- struct ext2_group_desc * tmp;
- struct ext2_super_block * es;
-
- if (!dir)
- return 0;
- sb = dir->i_e2fs;
-
- lock_super (DEVVP(dir));
- es = sb->s_es;
-repeat:
- gdp = NULL; i=0;
-
- if (S_ISDIR(mode)) {
- avefreei = es->s_free_inodes_count /
- sb->s_groups_count;
-/* I am not yet convinced that this next bit is necessary.
- i = dir->u.ext2_i.i_block_group;
- for (j = 0; j < sb->u.ext2_sb.s_groups_count; j++) {
- tmp = get_group_desc (sb, i, &bh2);
- if ((tmp->bg_used_dirs_count << 8) <
- tmp->bg_free_inodes_count) {
- gdp = tmp;
- break;
- }
- else
- i = ++i % sb->u.ext2_sb.s_groups_count;
- }
-*/
- if (!gdp) {
- for (j = 0; j < sb->s_groups_count; j++) {
- tmp = get_group_desc(ITOV(dir)->v_mount,j,&bh2);
- if (tmp->bg_free_inodes_count &&
- tmp->bg_free_inodes_count >= avefreei) {
- if (!gdp ||
- (tmp->bg_free_blocks_count >
- gdp->bg_free_blocks_count)) {
- i = j;
- gdp = tmp;
- }
- }
- }
- }
- }
- else
- {
- /*
- * Try to place the inode in its parent directory
- */
- i = dir->i_block_group;
- tmp = get_group_desc (ITOV(dir)->v_mount, i, &bh2);
- if (tmp->bg_free_inodes_count)
- gdp = tmp;
- else
- {
- /*
- * Use a quadratic hash to find a group with a
- * free inode
- */
- for (j = 1; j < sb->s_groups_count; j <<= 1) {
- i += j;
- if (i >= sb->s_groups_count)
- i -= sb->s_groups_count;
- tmp = get_group_desc(ITOV(dir)->v_mount,i,&bh2);
- if (tmp->bg_free_inodes_count) {
- gdp = tmp;
- break;
- }
- }
- }
- if (!gdp) {
- /*
- * That failed: try linear search for a free inode
- */
- i = dir->i_block_group + 1;
- for (j = 2; j < sb->s_groups_count; j++) {
- if (++i >= sb->s_groups_count)
- i = 0;
- tmp = get_group_desc(ITOV(dir)->v_mount,i,&bh2);
- if (tmp->bg_free_inodes_count) {
- gdp = tmp;
- break;
- }
- }
- }
- }
-
- if (!gdp) {
- unlock_super (DEVVP(dir));
- return 0;
- }
- bitmap_nr = load_inode_bitmap (ITOV(dir)->v_mount, i);
- bh = sb->s_inode_bitmap[bitmap_nr];
- if ((j = find_first_zero_bit ((unsigned long *) bh->b_data,
- EXT2_INODES_PER_GROUP(sb))) <
- EXT2_INODES_PER_GROUP(sb)) {
- if (set_bit (j, bh->b_data)) {
- printf ( "ext2_new_inode:"
- "bit already set for inode %d", j);
- goto repeat;
- }
-/* Linux now does the following:
- mark_buffer_dirty(bh);
- if (sb->s_flags & MS_SYNCHRONOUS) {
- ll_rw_block (WRITE, 1, &bh);
- wait_on_buffer (bh);
- }
-*/
- mark_buffer_dirty(bh);
- } else {
- if (gdp->bg_free_inodes_count != 0) {
- printf ( "ext2_new_inode:"
- "Free inodes count corrupted in group %d",
- i);
- unlock_super (DEVVP(dir));
- return 0;
- }
- goto repeat;
- }
- j += i * EXT2_INODES_PER_GROUP(sb) + 1;
- if (j < EXT2_FIRST_INO || j > es->s_inodes_count) {
- printf ( "ext2_new_inode:"
- "reserved inode or inode > inodes count - "
- "block_group = %d,inode=%d", i, j);
- unlock_super (DEVVP(dir));
- return 0;
- }
- gdp->bg_free_inodes_count--;
- if (S_ISDIR(mode))
- gdp->bg_used_dirs_count++;
- mark_buffer_dirty(bh2);
- es->s_free_inodes_count--;
- /* mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1); */
- sb->s_dirt = 1;
- unlock_super (DEVVP(dir));
- return j;
-}
-
-#ifdef unused
-static unsigned long ext2_count_free_inodes (struct mount * mp)
-{
-#ifdef EXT2FS_DEBUG
- struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
- struct ext2_super_block * es;
- unsigned long desc_count, bitmap_count, x;
- int bitmap_nr;
- struct ext2_group_desc * gdp;
- int i;
-
- lock_super (VFSTOEXT2(mp)->um_devvp);
- es = sb->s_es;
- desc_count = 0;
- bitmap_count = 0;
- gdp = NULL;
- for (i = 0; i < sb->s_groups_count; i++) {
- gdp = get_group_desc (mp, i, NULL);
- desc_count += gdp->bg_free_inodes_count;
- bitmap_nr = load_inode_bitmap (mp, i);
- x = ext2_count_free (sb->s_inode_bitmap[bitmap_nr],
- EXT2_INODES_PER_GROUP(sb) / 8);
- ext2_debug ("group %d: stored = %d, counted = %lu\n",
- i, gdp->bg_free_inodes_count, x);
- bitmap_count += x;
- }
- ext2_debug("stored = %lu, computed = %lu, %lu\n",
- es->s_free_inodes_count, desc_count, bitmap_count);
- unlock_super (VFSTOEXT2(mp)->um_devvp);
- return desc_count;
-#else
- return VFSTOEXT2(mp)->um_e2fsb->s_free_inodes_count;
-#endif
-}
-#endif /* unused */
-
-#ifdef LATER
-void ext2_check_inodes_bitmap (struct mount * mp)
-{
- struct ext2_super_block * es;
- unsigned long desc_count, bitmap_count, x;
- int bitmap_nr;
- struct ext2_group_desc * gdp;
- int i;
-
- lock_super (sb);
- es = sb->u.ext2_sb.s_es;
- desc_count = 0;
- bitmap_count = 0;
- gdp = NULL;
- for (i = 0; i < sb->u.ext2_sb.s_groups_count; i++) {
- gdp = get_group_desc (sb, i, NULL);
- desc_count += gdp->bg_free_inodes_count;
- bitmap_nr = load_inode_bitmap (sb, i);
- x = ext2_count_free (sb->u.ext2_sb.s_inode_bitmap[bitmap_nr],
- EXT2_INODES_PER_GROUP(sb) / 8);
- if (gdp->bg_free_inodes_count != x)
- printf ( "ext2_check_inodes_bitmap:"
- "Wrong free inodes count in group %d, "
- "stored = %d, counted = %lu", i,
- gdp->bg_free_inodes_count, x);
- bitmap_count += x;
- }
- if (es->s_free_inodes_count != bitmap_count)
- printf ( "ext2_check_inodes_bitmap:"
- "Wrong free inodes count in super block, "
- "stored = %lu, counted = %lu",
- (unsigned long) es->s_free_inodes_count, bitmap_count);
- unlock_super (sb);
-}
-#endif
diff --git a/sys/gnu/fs/ext2fs/ext2_lookup.c b/sys/gnu/fs/ext2fs/ext2_lookup.c
deleted file mode 100644
index 02ee48406bd8..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_lookup.c
+++ /dev/null
@@ -1,1108 +0,0 @@
-/*
- * modified for Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- */
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ufs_lookup.c 8.6 (Berkeley) 4/1/94
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/namei.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/mount.h>
-#include <sys/vnode.h>
-#include <sys/malloc.h>
-#include <sys/dirent.h>
-#include <sys/sysctl.h>
-
-#include <ufs/ufs/dir.h>
-
-#include <gnu/ext2fs/inode.h>
-#include <gnu/ext2fs/ext2_mount.h>
-#include <gnu/ext2fs/ext2_extern.h>
-#include <gnu/ext2fs/ext2_fs.h>
-#include <gnu/ext2fs/ext2_fs_sb.h>
-
-#ifdef DIAGNOSTIC
-static int dirchk = 1;
-#else
-static int dirchk = 0;
-#endif
-
-SYSCTL_NODE(_vfs, OID_AUTO, e2fs, CTLFLAG_RD, 0, "EXT2FS filesystem");
-SYSCTL_INT(_vfs_e2fs, OID_AUTO, dircheck, CTLFLAG_RW, &dirchk, 0, "");
-
-/*
- DIRBLKSIZE in ffs is DEV_BSIZE (in most cases 512)
- while it is the native blocksize in ext2fs - thus, a #define
- is no longer appropriate
-*/
-#undef DIRBLKSIZ
-
-static u_char ext2_ft_to_dt[] = {
- DT_UNKNOWN, /* EXT2_FT_UNKNOWN */
- DT_REG, /* EXT2_FT_REG_FILE */
- DT_DIR, /* EXT2_FT_DIR */
- DT_CHR, /* EXT2_FT_CHRDEV */
- DT_BLK, /* EXT2_FT_BLKDEV */
- DT_FIFO, /* EXT2_FT_FIFO */
- DT_SOCK, /* EXT2_FT_SOCK */
- DT_LNK, /* EXT2_FT_SYMLINK */
-};
-#define FTTODT(ft) \
- ((ft) > sizeof(ext2_ft_to_dt) / sizeof(ext2_ft_to_dt[0]) ? \
- DT_UNKNOWN : ext2_ft_to_dt[(ft)])
-
-static u_char dt_to_ext2_ft[] = {
- EXT2_FT_UNKNOWN, /* DT_UNKNOWN */
- EXT2_FT_FIFO, /* DT_FIFO */
- EXT2_FT_CHRDEV, /* DT_CHR */
- EXT2_FT_UNKNOWN, /* unused */
- EXT2_FT_DIR, /* DT_DIR */
- EXT2_FT_UNKNOWN, /* unused */
- EXT2_FT_BLKDEV, /* DT_BLK */
- EXT2_FT_UNKNOWN, /* unused */
- EXT2_FT_REG_FILE, /* DT_REG */
- EXT2_FT_UNKNOWN, /* unused */
- EXT2_FT_SYMLINK, /* DT_LNK */
- EXT2_FT_UNKNOWN, /* unused */
- EXT2_FT_SOCK, /* DT_SOCK */
- EXT2_FT_UNKNOWN, /* unused */
- EXT2_FT_UNKNOWN, /* DT_WHT */
-};
-#define DTTOFT(dt) \
- ((dt) > sizeof(dt_to_ext2_ft) / sizeof(dt_to_ext2_ft[0]) ? \
- EXT2_FT_UNKNOWN : dt_to_ext2_ft[(dt)])
-
-static int ext2_dirbadentry(struct vnode *dp, struct ext2_dir_entry_2 *de,
- int entryoffsetinblock);
-
-/*
- * Vnode op for reading directories.
- *
- * The routine below assumes that the on-disk format of a directory
- * is the same as that defined by <sys/dirent.h>. If the on-disk
- * format changes, then it will be necessary to do a conversion
- * from the on-disk format that read returns to the format defined
- * by <sys/dirent.h>.
- */
-/*
- * this is exactly what we do here - the problem is that the conversion
- * will blow up some entries by four bytes, so it can't be done in place.
- * This is too bad. Right now the conversion is done entry by entry, the
- * converted entry is sent via uiomove.
- *
- * XXX allocate a buffer, convert as many entries as possible, then send
- * the whole buffer to uiomove
- */
-int
-ext2_readdir(ap)
- struct vop_readdir_args /* {
- struct vnode *a_vp;
- struct uio *a_uio;
- struct ucred *a_cred;
- } */ *ap;
-{
- struct uio *uio = ap->a_uio;
- int count, error;
-
- struct ext2_dir_entry_2 *edp, *dp;
- int ncookies;
- struct dirent dstdp;
- struct uio auio;
- struct iovec aiov;
- caddr_t dirbuf;
- int DIRBLKSIZ = VTOI(ap->a_vp)->i_e2fs->s_blocksize;
- int readcnt;
- off_t startoffset = uio->uio_offset;
-
- count = uio->uio_resid;
- /*
- * Avoid complications for partial directory entries by adjusting
- * the i/o to end at a block boundary. Don't give up (like ufs
- * does) if the initial adjustment gives a negative count, since
- * many callers don't supply a large enough buffer. The correct
- * size is a little larger than DIRBLKSIZ to allow for expansion
- * of directory entries, but some callers just use 512.
- */
- count -= (uio->uio_offset + count) & (DIRBLKSIZ -1);
- if (count <= 0)
- count += DIRBLKSIZ;
-
-#ifdef EXT2FS_DEBUG
- printf("ext2_readdir: uio_offset = %lld, uio_resid = %d, count = %d\n",
- uio->uio_offset, uio->uio_resid, count);
-#endif
-
- auio = *uio;
- auio.uio_iov = &aiov;
- auio.uio_iovcnt = 1;
- auio.uio_resid = count;
- auio.uio_segflg = UIO_SYSSPACE;
- aiov.iov_len = count;
- MALLOC(dirbuf, caddr_t, count, M_TEMP, M_WAITOK);
- aiov.iov_base = dirbuf;
- error = VOP_READ(ap->a_vp, &auio, 0, ap->a_cred);
- if (error == 0) {
- readcnt = count - auio.uio_resid;
- edp = (struct ext2_dir_entry_2 *)&dirbuf[readcnt];
- ncookies = 0;
- bzero(&dstdp, offsetof(struct dirent, d_name));
- for (dp = (struct ext2_dir_entry_2 *)dirbuf;
- !error && uio->uio_resid > 0 && dp < edp; ) {
- /*-
- * "New" ext2fs directory entries differ in 3 ways
- * from ufs on-disk ones:
- * - the name is not necessarily NUL-terminated.
- * - the file type field always exists and always
- * follows the name length field.
- * - the file type is encoded in a different way.
- *
- * "Old" ext2fs directory entries need no special
- * conversions, since they binary compatible with
- * "new" entries having a file type of 0 (i.e.,
- * EXT2_FT_UNKNOWN). Splitting the old name length
- * field didn't make a mess like it did in ufs,
- * because ext2fs uses a machine-dependent disk
- * layout.
- */
- dstdp.d_fileno = dp->inode;
- dstdp.d_type = FTTODT(dp->file_type);
- dstdp.d_namlen = dp->name_len;
- dstdp.d_reclen = GENERIC_DIRSIZ(&dstdp);
- bcopy(dp->name, dstdp.d_name, dstdp.d_namlen);
- bzero(dstdp.d_name + dstdp.d_namlen,
- dstdp.d_reclen - offsetof(struct dirent, d_name) -
- dstdp.d_namlen);
-
- if (dp->rec_len > 0) {
- if(dstdp.d_reclen <= uio->uio_resid) {
- /* advance dp */
- dp = (struct ext2_dir_entry_2 *)
- ((char *)dp + dp->rec_len);
- error =
- uiomove(&dstdp, dstdp.d_reclen, uio);
- if (!error)
- ncookies++;
- } else
- break;
- } else {
- error = EIO;
- break;
- }
- }
- /* we need to correct uio_offset */
- uio->uio_offset = startoffset + (caddr_t)dp - dirbuf;
-
- if (!error && ap->a_ncookies != NULL) {
- u_long *cookiep, *cookies, *ecookies;
- off_t off;
-
- if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
- panic("ext2fs_readdir: unexpected uio from NFS server");
- MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
- M_WAITOK);
- off = startoffset;
- for (dp = (struct ext2_dir_entry_2 *)dirbuf,
- cookiep = cookies, ecookies = cookies + ncookies;
- cookiep < ecookies;
- dp = (struct ext2_dir_entry_2 *)((caddr_t) dp + dp->rec_len)) {
- off += dp->rec_len;
- *cookiep++ = (u_long) off;
- }
- *ap->a_ncookies = ncookies;
- *ap->a_cookies = cookies;
- }
- }
- FREE(dirbuf, M_TEMP);
- if (ap->a_eofflag)
- *ap->a_eofflag = VTOI(ap->a_vp)->i_size <= uio->uio_offset;
- return (error);
-}
-
-/*
- * Convert a component of a pathname into a pointer to a locked inode.
- * This is a very central and rather complicated routine.
- * If the file system is not maintained in a strict tree hierarchy,
- * this can result in a deadlock situation (see comments in code below).
- *
- * The cnp->cn_nameiop argument is LOOKUP, CREATE, RENAME, or DELETE depending
- * on whether the name is to be looked up, created, renamed, or deleted.
- * When CREATE, RENAME, or DELETE is specified, information usable in
- * creating, renaming, or deleting a directory entry may be calculated.
- * If flag has LOCKPARENT or'ed into it and the target of the pathname
- * exists, lookup returns both the target and its parent directory locked.
- * When creating or renaming and LOCKPARENT is specified, the target may
- * not be ".". When deleting and LOCKPARENT is specified, the target may
- * be "."., but the caller must check to ensure it does an vrele and vput
- * instead of two vputs.
- *
- * Overall outline of ufs_lookup:
- *
- * search for name in directory, to found or notfound
- * notfound:
- * if creating, return locked directory, leaving info on available slots
- * else return error
- * found:
- * if at end of path and deleting, return information to allow delete
- * if at end of path and rewriting (RENAME and LOCKPARENT), lock target
- * inode and return info to allow rewrite
- * if not at end, add name to cache; if at end and neither creating
- * nor deleting, add name to cache
- */
-int
-ext2_lookup(ap)
- struct vop_cachedlookup_args /* {
- struct vnode *a_dvp;
- struct vnode **a_vpp;
- struct componentname *a_cnp;
- } */ *ap;
-{
- struct vnode *vdp; /* vnode for directory being searched */
- struct inode *dp; /* inode for directory being searched */
- struct buf *bp; /* a buffer of directory entries */
- struct ext2_dir_entry_2 *ep; /* the current directory entry */
- int entryoffsetinblock; /* offset of ep in bp's buffer */
- enum {NONE, COMPACT, FOUND} slotstatus;
- doff_t slotoffset; /* offset of area with free space */
- int slotsize; /* size of area at slotoffset */
- int slotfreespace; /* amount of space free in slot */
- int slotneeded; /* size of the entry we're seeking */
- int numdirpasses; /* strategy for directory search */
- doff_t endsearch; /* offset to end directory search */
- doff_t prevoff; /* prev entry dp->i_offset */
- struct vnode *pdp; /* saved dp during symlink work */
- struct vnode *tdp; /* returned by VFS_VGET */
- doff_t enduseful; /* pointer past last used dir slot */
- u_long bmask; /* block offset mask */
- int lockparent; /* 1 => lockparent flag is set */
- int wantparent; /* 1 => wantparent or lockparent flag */
- int namlen, error;
- struct vnode **vpp = ap->a_vpp;
- struct componentname *cnp = ap->a_cnp;
- struct ucred *cred = cnp->cn_cred;
- int flags = cnp->cn_flags;
- int nameiop = cnp->cn_nameiop;
- struct thread *td = cnp->cn_thread;
-
- int DIRBLKSIZ = VTOI(ap->a_dvp)->i_e2fs->s_blocksize;
-
- bp = NULL;
- slotoffset = -1;
- *vpp = NULL;
- vdp = ap->a_dvp;
- dp = VTOI(vdp);
- lockparent = flags & LOCKPARENT;
- wantparent = flags & (LOCKPARENT|WANTPARENT);
-
- /*
- * We now have a segment name to search for, and a directory to search.
- */
-
- /*
- * Suppress search for slots unless creating
- * file and at end of pathname, in which case
- * we watch for a place to put the new file in
- * case it doesn't already exist.
- */
- slotstatus = FOUND;
- slotfreespace = slotsize = slotneeded = 0;
- if ((nameiop == CREATE || nameiop == RENAME) &&
- (flags & ISLASTCN)) {
- slotstatus = NONE;
- slotneeded = EXT2_DIR_REC_LEN(cnp->cn_namelen);
- /* was
- slotneeded = (sizeof(struct direct) - MAXNAMLEN +
- cnp->cn_namelen + 3) &~ 3; */
- }
-
- /*
- * If there is cached information on a previous search of
- * this directory, pick up where we last left off.
- * We cache only lookups as these are the most common
- * and have the greatest payoff. Caching CREATE has little
- * benefit as it usually must search the entire directory
- * to determine that the entry does not exist. Caching the
- * location of the last DELETE or RENAME has not reduced
- * profiling time and hence has been removed in the interest
- * of simplicity.
- */
- bmask = VFSTOEXT2(vdp->v_mount)->um_mountp->mnt_stat.f_iosize - 1;
- if (nameiop != LOOKUP || dp->i_diroff == 0 ||
- dp->i_diroff > dp->i_size) {
- entryoffsetinblock = 0;
- dp->i_offset = 0;
- numdirpasses = 1;
- } else {
- dp->i_offset = dp->i_diroff;
- if ((entryoffsetinblock = dp->i_offset & bmask) &&
- (error = ext2_blkatoff(vdp, (off_t)dp->i_offset, NULL,
- &bp)))
- return (error);
- numdirpasses = 2;
- nchstats.ncs_2passes++;
- }
- prevoff = dp->i_offset;
- endsearch = roundup(dp->i_size, DIRBLKSIZ);
- enduseful = 0;
-
-searchloop:
- while (dp->i_offset < endsearch) {
- /*
- * If necessary, get the next directory block.
- */
- if ((dp->i_offset & bmask) == 0) {
- if (bp != NULL)
- brelse(bp);
- if ((error =
- ext2_blkatoff(vdp, (off_t)dp->i_offset, NULL,
- &bp)) != 0)
- return (error);
- entryoffsetinblock = 0;
- }
- /*
- * If still looking for a slot, and at a DIRBLKSIZE
- * boundary, have to start looking for free space again.
- */
- if (slotstatus == NONE &&
- (entryoffsetinblock & (DIRBLKSIZ - 1)) == 0) {
- slotoffset = -1;
- slotfreespace = 0;
- }
- /*
- * Get pointer to next entry.
- * Full validation checks are slow, so we only check
- * enough to insure forward progress through the
- * directory. Complete checks can be run by setting
- * "vfs.e2fs.dirchk" to be true.
- */
- ep = (struct ext2_dir_entry_2 *)
- ((char *)bp->b_data + entryoffsetinblock);
- if (ep->rec_len == 0 ||
- (dirchk && ext2_dirbadentry(vdp, ep, entryoffsetinblock))) {
- int i;
- ext2_dirbad(dp, dp->i_offset, "mangled entry");
- i = DIRBLKSIZ - (entryoffsetinblock & (DIRBLKSIZ - 1));
- dp->i_offset += i;
- entryoffsetinblock += i;
- continue;
- }
-
- /*
- * If an appropriate sized slot has not yet been found,
- * check to see if one is available. Also accumulate space
- * in the current block so that we can determine if
- * compaction is viable.
- */
- if (slotstatus != FOUND) {
- int size = ep->rec_len;
-
- if (ep->inode != 0)
- size -= EXT2_DIR_REC_LEN(ep->name_len);
- if (size > 0) {
- if (size >= slotneeded) {
- slotstatus = FOUND;
- slotoffset = dp->i_offset;
- slotsize = ep->rec_len;
- } else if (slotstatus == NONE) {
- slotfreespace += size;
- if (slotoffset == -1)
- slotoffset = dp->i_offset;
- if (slotfreespace >= slotneeded) {
- slotstatus = COMPACT;
- slotsize = dp->i_offset +
- ep->rec_len - slotoffset;
- }
- }
- }
- }
-
- /*
- * Check for a name match.
- */
- if (ep->inode) {
- namlen = ep->name_len;
- if (namlen == cnp->cn_namelen &&
- !bcmp(cnp->cn_nameptr, ep->name,
- (unsigned)namlen)) {
- /*
- * Save directory entry's inode number and
- * reclen in ndp->ni_ufs area, and release
- * directory buffer.
- */
- dp->i_ino = ep->inode;
- dp->i_reclen = ep->rec_len;
- goto found;
- }
- }
- prevoff = dp->i_offset;
- dp->i_offset += ep->rec_len;
- entryoffsetinblock += ep->rec_len;
- if (ep->inode)
- enduseful = dp->i_offset;
- }
-/* notfound: */
- /*
- * If we started in the middle of the directory and failed
- * to find our target, we must check the beginning as well.
- */
- if (numdirpasses == 2) {
- numdirpasses--;
- dp->i_offset = 0;
- endsearch = dp->i_diroff;
- goto searchloop;
- }
- if (bp != NULL)
- brelse(bp);
- /*
- * If creating, and at end of pathname and current
- * directory has not been removed, then can consider
- * allowing file to be created.
- */
- if ((nameiop == CREATE || nameiop == RENAME) &&
- (flags & ISLASTCN) && dp->i_nlink != 0) {
- /*
- * Access for write is interpreted as allowing
- * creation of files in the directory.
- */
- if ((error = VOP_ACCESS(vdp, VWRITE, cred, cnp->cn_thread)) != 0)
- return (error);
- /*
- * Return an indication of where the new directory
- * entry should be put. If we didn't find a slot,
- * then set dp->i_count to 0 indicating
- * that the new slot belongs at the end of the
- * directory. If we found a slot, then the new entry
- * can be put in the range from dp->i_offset to
- * dp->i_offset + dp->i_count.
- */
- if (slotstatus == NONE) {
- dp->i_offset = roundup(dp->i_size, DIRBLKSIZ);
- dp->i_count = 0;
- enduseful = dp->i_offset;
- } else {
- dp->i_offset = slotoffset;
- dp->i_count = slotsize;
- if (enduseful < slotoffset + slotsize)
- enduseful = slotoffset + slotsize;
- }
- dp->i_endoff = roundup(enduseful, DIRBLKSIZ);
- dp->i_flag |= IN_CHANGE | IN_UPDATE;
- /*
- * We return with the directory locked, so that
- * the parameters we set up above will still be
- * valid if we actually decide to do a direnter().
- * We return ni_vp == NULL to indicate that the entry
- * does not currently exist; we leave a pointer to
- * the (locked) directory inode in ndp->ni_dvp.
- * The pathname buffer is saved so that the name
- * can be obtained later.
- *
- * NB - if the directory is unlocked, then this
- * information cannot be used.
- */
- cnp->cn_flags |= SAVENAME;
- if (!lockparent)
- VOP_UNLOCK(vdp, 0, td);
- return (EJUSTRETURN);
- }
- /*
- * Insert name into cache (as non-existent) if appropriate.
- */
- if ((cnp->cn_flags & MAKEENTRY) && nameiop != CREATE)
- cache_enter(vdp, *vpp, cnp);
- return (ENOENT);
-
-found:
- if (numdirpasses == 2)
- nchstats.ncs_pass2++;
- /*
- * Check that directory length properly reflects presence
- * of this entry.
- */
- if (entryoffsetinblock + EXT2_DIR_REC_LEN(ep->name_len)
- > dp->i_size) {
- ext2_dirbad(dp, dp->i_offset, "i_size too small");
- dp->i_size = entryoffsetinblock+EXT2_DIR_REC_LEN(ep->name_len);
- dp->i_flag |= IN_CHANGE | IN_UPDATE;
- }
- brelse(bp);
-
- /*
- * Found component in pathname.
- * If the final component of path name, save information
- * in the cache as to where the entry was found.
- */
- if ((flags & ISLASTCN) && nameiop == LOOKUP)
- dp->i_diroff = dp->i_offset &~ (DIRBLKSIZ - 1);
-
- /*
- * If deleting, and at end of pathname, return
- * parameters which can be used to remove file.
- * If the wantparent flag isn't set, we return only
- * the directory (in ndp->ni_dvp), otherwise we go
- * on and lock the inode, being careful with ".".
- */
- if (nameiop == DELETE && (flags & ISLASTCN)) {
- /*
- * Write access to directory required to delete files.
- */
- if ((error = VOP_ACCESS(vdp, VWRITE, cred, cnp->cn_thread)) != 0)
- return (error);
- /*
- * Return pointer to current entry in dp->i_offset,
- * and distance past previous entry (if there
- * is a previous entry in this block) in dp->i_count.
- * Save directory inode pointer in ndp->ni_dvp for dirremove().
- */
- if ((dp->i_offset & (DIRBLKSIZ - 1)) == 0)
- dp->i_count = 0;
- else
- dp->i_count = dp->i_offset - prevoff;
- if (dp->i_number == dp->i_ino) {
- VREF(vdp);
- *vpp = vdp;
- return (0);
- }
- if ((error = VFS_VGET(vdp->v_mount, dp->i_ino, LK_EXCLUSIVE,
- &tdp)) != 0)
- return (error);
- /*
- * If directory is "sticky", then user must own
- * the directory, or the file in it, else she
- * may not delete it (unless she's root). This
- * implements append-only directories.
- */
- if ((dp->i_mode & ISVTX) &&
- cred->cr_uid != 0 &&
- cred->cr_uid != dp->i_uid &&
- VTOI(tdp)->i_uid != cred->cr_uid) {
- vput(tdp);
- return (EPERM);
- }
- *vpp = tdp;
- if (!lockparent)
- VOP_UNLOCK(vdp, 0, td);
- return (0);
- }
-
- /*
- * If rewriting (RENAME), return the inode and the
- * information required to rewrite the present directory
- * Must get inode of directory entry to verify it's a
- * regular file, or empty directory.
- */
- if (nameiop == RENAME && wantparent &&
- (flags & ISLASTCN)) {
- if ((error = VOP_ACCESS(vdp, VWRITE, cred, cnp->cn_thread)) != 0)
- return (error);
- /*
- * Careful about locking second inode.
- * This can only occur if the target is ".".
- */
- if (dp->i_number == dp->i_ino)
- return (EISDIR);
- if ((error = VFS_VGET(vdp->v_mount, dp->i_ino, LK_EXCLUSIVE,
- &tdp)) != 0)
- return (error);
- *vpp = tdp;
- cnp->cn_flags |= SAVENAME;
- if (!lockparent)
- VOP_UNLOCK(vdp, 0, td);
- return (0);
- }
-
- /*
- * Step through the translation in the name. We do not `vput' the
- * directory because we may need it again if a symbolic link
- * is relative to the current directory. Instead we save it
- * unlocked as "pdp". We must get the target inode before unlocking
- * the directory to insure that the inode will not be removed
- * before we get it. We prevent deadlock by always fetching
- * inodes from the root, moving down the directory tree. Thus
- * when following backward pointers ".." we must unlock the
- * parent directory before getting the requested directory.
- * There is a potential race condition here if both the current
- * and parent directories are removed before the VFS_VGET for the
- * inode associated with ".." returns. We hope that this occurs
- * infrequently since we cannot avoid this race condition without
- * implementing a sophisticated deadlock detection algorithm.
- * Note also that this simple deadlock detection scheme will not
- * work if the file system has any hard links other than ".."
- * that point backwards in the directory structure.
- */
- pdp = vdp;
- if (flags & ISDOTDOT) {
- VOP_UNLOCK(pdp, 0, td); /* race to get the inode */
- if ((error = VFS_VGET(vdp->v_mount, dp->i_ino, LK_EXCLUSIVE,
- &tdp)) != 0) {
- vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY, td);
- return (error);
- }
- if (lockparent && (flags & ISLASTCN) &&
- (error = vn_lock(pdp, LK_EXCLUSIVE, td))) {
- vput(tdp);
- return (error);
- }
- *vpp = tdp;
- } else if (dp->i_number == dp->i_ino) {
- VREF(vdp); /* we want ourself, ie "." */
- *vpp = vdp;
- } else {
- if ((error = VFS_VGET(vdp->v_mount, dp->i_ino, LK_EXCLUSIVE,
- &tdp)) != 0)
- return (error);
- if (!lockparent || !(flags & ISLASTCN))
- VOP_UNLOCK(pdp, 0, td);
- *vpp = tdp;
- }
-
- /*
- * Insert name into cache if appropriate.
- */
- if (cnp->cn_flags & MAKEENTRY)
- cache_enter(vdp, *vpp, cnp);
- return (0);
-}
-
-void
-ext2_dirbad(ip, offset, how)
- struct inode *ip;
- doff_t offset;
- char *how;
-{
- struct mount *mp;
-
- mp = ITOV(ip)->v_mount;
- (void)printf("%s: bad dir ino %lu at offset %ld: %s\n",
- mp->mnt_stat.f_mntonname, (u_long)ip->i_number, (long)offset, how);
- if ((mp->mnt_flag & MNT_RDONLY) == 0)
- panic("ext2_dirbad: bad dir");
-}
-
-/*
- * Do consistency checking on a directory entry:
- * record length must be multiple of 4
- * entry must fit in rest of its DIRBLKSIZ block
- * record must be large enough to contain entry
- * name is not longer than MAXNAMLEN
- * name must be as long as advertised, and null terminated
- */
-/*
- * changed so that it confirms to ext2_check_dir_entry
- */
-static int
-ext2_dirbadentry(dp, de, entryoffsetinblock)
- struct vnode *dp;
- struct ext2_dir_entry_2 *de;
- int entryoffsetinblock;
-{
- int DIRBLKSIZ = VTOI(dp)->i_e2fs->s_blocksize;
-
- char * error_msg = NULL;
-
- if (de->rec_len < EXT2_DIR_REC_LEN(1))
- error_msg = "rec_len is smaller than minimal";
- else if (de->rec_len % 4 != 0)
- error_msg = "rec_len % 4 != 0";
- else if (de->rec_len < EXT2_DIR_REC_LEN(de->name_len))
- error_msg = "reclen is too small for name_len";
- else if (entryoffsetinblock + de->rec_len > DIRBLKSIZ)
- error_msg = "directory entry across blocks";
- /* else LATER
- if (de->inode > dir->i_sb->u.ext2_sb.s_es->s_inodes_count)
- error_msg = "inode out of bounds";
- */
-
- if (error_msg != NULL) {
- printf("bad directory entry: %s\n", error_msg);
- printf("offset=%d, inode=%lu, rec_len=%u, name_len=%u\n",
- entryoffsetinblock, (unsigned long)de->inode,
- de->rec_len, de->name_len);
- }
- return error_msg == NULL ? 0 : 1;
-}
-
-/*
- * Write a directory entry after a call to namei, using the parameters
- * that it left in nameidata. The argument ip is the inode which the new
- * directory entry will refer to. Dvp is a pointer to the directory to
- * be written, which was left locked by namei. Remaining parameters
- * (dp->i_offset, dp->i_count) indicate how the space for the new
- * entry is to be obtained.
- */
-int
-ext2_direnter(ip, dvp, cnp)
- struct inode *ip;
- struct vnode *dvp;
- struct componentname *cnp;
-{
- struct ext2_dir_entry_2 *ep, *nep;
- struct inode *dp;
- struct buf *bp;
- struct ext2_dir_entry_2 newdir;
- struct iovec aiov;
- struct uio auio;
- u_int dsize;
- int error, loc, newentrysize, spacefree;
- char *dirbuf;
- int DIRBLKSIZ = ip->i_e2fs->s_blocksize;
-
-
-#if DIAGNOSTIC
- if ((cnp->cn_flags & SAVENAME) == 0)
- panic("direnter: missing name");
-#endif
- dp = VTOI(dvp);
- newdir.inode = ip->i_number;
- newdir.name_len = cnp->cn_namelen;
- if (EXT2_HAS_INCOMPAT_FEATURE(ip->i_e2fs->s_es,
- EXT2_FEATURE_INCOMPAT_FILETYPE))
- newdir.file_type = DTTOFT(IFTODT(ip->i_mode));
- else
- newdir.file_type = EXT2_FT_UNKNOWN;
- bcopy(cnp->cn_nameptr, newdir.name, (unsigned)cnp->cn_namelen + 1);
- newentrysize = EXT2_DIR_REC_LEN(newdir.name_len);
- if (dp->i_count == 0) {
- /*
- * If dp->i_count is 0, then namei could find no
- * space in the directory. Here, dp->i_offset will
- * be on a directory block boundary and we will write the
- * new entry into a fresh block.
- */
- if (dp->i_offset & (DIRBLKSIZ - 1))
- panic("ext2_direnter: newblk");
- auio.uio_offset = dp->i_offset;
- newdir.rec_len = DIRBLKSIZ;
- auio.uio_resid = newentrysize;
- aiov.iov_len = newentrysize;
- aiov.iov_base = (caddr_t)&newdir;
- auio.uio_iov = &aiov;
- auio.uio_iovcnt = 1;
- auio.uio_rw = UIO_WRITE;
- auio.uio_segflg = UIO_SYSSPACE;
- auio.uio_td = (struct thread *)0;
- error = VOP_WRITE(dvp, &auio, IO_SYNC, cnp->cn_cred);
- if (DIRBLKSIZ >
- VFSTOEXT2(dvp->v_mount)->um_mountp->mnt_stat.f_bsize)
- /* XXX should grow with balloc() */
- panic("ext2_direnter: frag size");
- else if (!error) {
- dp->i_size = roundup(dp->i_size, DIRBLKSIZ);
- dp->i_flag |= IN_CHANGE;
- }
- return (error);
- }
-
- /*
- * If dp->i_count is non-zero, then namei found space
- * for the new entry in the range dp->i_offset to
- * dp->i_offset + dp->i_count in the directory.
- * To use this space, we may have to compact the entries located
- * there, by copying them together towards the beginning of the
- * block, leaving the free space in one usable chunk at the end.
- */
-
- /*
- * Increase size of directory if entry eats into new space.
- * This should never push the size past a new multiple of
- * DIRBLKSIZE.
- *
- * N.B. - THIS IS AN ARTIFACT OF 4.2 AND SHOULD NEVER HAPPEN.
- */
- if (dp->i_offset + dp->i_count > dp->i_size)
- dp->i_size = dp->i_offset + dp->i_count;
- /*
- * Get the block containing the space for the new directory entry.
- */
- if ((error = ext2_blkatoff(dvp, (off_t)dp->i_offset, &dirbuf,
- &bp)) != 0)
- return (error);
- /*
- * Find space for the new entry. In the simple case, the entry at
- * offset base will have the space. If it does not, then namei
- * arranged that compacting the region dp->i_offset to
- * dp->i_offset + dp->i_count would yield the
- * space.
- */
- ep = (struct ext2_dir_entry_2 *)dirbuf;
- dsize = EXT2_DIR_REC_LEN(ep->name_len);
- spacefree = ep->rec_len - dsize;
- for (loc = ep->rec_len; loc < dp->i_count; ) {
- nep = (struct ext2_dir_entry_2 *)(dirbuf + loc);
- if (ep->inode) {
- /* trim the existing slot */
- ep->rec_len = dsize;
- ep = (struct ext2_dir_entry_2 *)((char *)ep + dsize);
- } else {
- /* overwrite; nothing there; header is ours */
- spacefree += dsize;
- }
- dsize = EXT2_DIR_REC_LEN(nep->name_len);
- spacefree += nep->rec_len - dsize;
- loc += nep->rec_len;
- bcopy((caddr_t)nep, (caddr_t)ep, dsize);
- }
- /*
- * Update the pointer fields in the previous entry (if any),
- * copy in the new entry, and write out the block.
- */
- if (ep->inode == 0) {
- if (spacefree + dsize < newentrysize)
- panic("ext2_direnter: compact1");
- newdir.rec_len = spacefree + dsize;
- } else {
- if (spacefree < newentrysize)
- panic("ext2_direnter: compact2");
- newdir.rec_len = spacefree;
- ep->rec_len = dsize;
- ep = (struct ext2_dir_entry_2 *)((char *)ep + dsize);
- }
- bcopy((caddr_t)&newdir, (caddr_t)ep, (u_int)newentrysize);
- error = BUF_WRITE(bp);
- dp->i_flag |= IN_CHANGE | IN_UPDATE;
- if (!error && dp->i_endoff && dp->i_endoff < dp->i_size)
- error = ext2_truncate(dvp, (off_t)dp->i_endoff, IO_SYNC,
- cnp->cn_cred, cnp->cn_thread);
- return (error);
-}
-
-/*
- * Remove a directory entry after a call to namei, using
- * the parameters which it left in nameidata. The entry
- * dp->i_offset contains the offset into the directory of the
- * entry to be eliminated. The dp->i_count field contains the
- * size of the previous record in the directory. If this
- * is 0, the first entry is being deleted, so we need only
- * zero the inode number to mark the entry as free. If the
- * entry is not the first in the directory, we must reclaim
- * the space of the now empty record by adding the record size
- * to the size of the previous entry.
- */
-int
-ext2_dirremove(dvp, cnp)
- struct vnode *dvp;
- struct componentname *cnp;
-{
- struct inode *dp;
- struct ext2_dir_entry_2 *ep;
- struct buf *bp;
- int error;
-
- dp = VTOI(dvp);
- if (dp->i_count == 0) {
- /*
- * First entry in block: set d_ino to zero.
- */
- if ((error =
- ext2_blkatoff(dvp, (off_t)dp->i_offset, (char **)&ep,
- &bp)) != 0)
- return (error);
- ep->inode = 0;
- error = BUF_WRITE(bp);
- dp->i_flag |= IN_CHANGE | IN_UPDATE;
- return (error);
- }
- /*
- * Collapse new free space into previous entry.
- */
- if ((error = ext2_blkatoff(dvp, (off_t)(dp->i_offset - dp->i_count),
- (char **)&ep, &bp)) != 0)
- return (error);
- ep->rec_len += dp->i_reclen;
- error = BUF_WRITE(bp);
- dp->i_flag |= IN_CHANGE | IN_UPDATE;
- return (error);
-}
-
-/*
- * Rewrite an existing directory entry to point at the inode
- * supplied. The parameters describing the directory entry are
- * set up by a call to namei.
- */
-int
-ext2_dirrewrite(dp, ip, cnp)
- struct inode *dp, *ip;
- struct componentname *cnp;
-{
- struct buf *bp;
- struct ext2_dir_entry_2 *ep;
- struct vnode *vdp = ITOV(dp);
- int error;
-
- if ((error = ext2_blkatoff(vdp, (off_t)dp->i_offset, (char **)&ep,
- &bp)) != 0)
- return (error);
- ep->inode = ip->i_number;
- if (EXT2_HAS_INCOMPAT_FEATURE(ip->i_e2fs->s_es,
- EXT2_FEATURE_INCOMPAT_FILETYPE))
- ep->file_type = DTTOFT(IFTODT(ip->i_mode));
- else
- ep->file_type = EXT2_FT_UNKNOWN;
- error = BUF_WRITE(bp);
- dp->i_flag |= IN_CHANGE | IN_UPDATE;
- return (error);
-}
-
-/*
- * Check if a directory is empty or not.
- * Inode supplied must be locked.
- *
- * Using a struct dirtemplate here is not precisely
- * what we want, but better than using a struct direct.
- *
- * NB: does not handle corrupted directories.
- */
-int
-ext2_dirempty(ip, parentino, cred)
- struct inode *ip;
- ino_t parentino;
- struct ucred *cred;
-{
- off_t off;
- struct dirtemplate dbuf;
- struct ext2_dir_entry_2 *dp = (struct ext2_dir_entry_2 *)&dbuf;
- int error, count, namlen;
-
-#define MINDIRSIZ (sizeof (struct dirtemplate) / 2)
-
- for (off = 0; off < ip->i_size; off += dp->rec_len) {
- error = vn_rdwr(UIO_READ, ITOV(ip), (caddr_t)dp, MINDIRSIZ,
- off, UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK, cred,
- NOCRED, &count, (struct thread *)0);
- /*
- * Since we read MINDIRSIZ, residual must
- * be 0 unless we're at end of file.
- */
- if (error || count != 0)
- return (0);
- /* avoid infinite loops */
- if (dp->rec_len == 0)
- return (0);
- /* skip empty entries */
- if (dp->inode == 0)
- continue;
- /* accept only "." and ".." */
- namlen = dp->name_len;
- if (namlen > 2)
- return (0);
- if (dp->name[0] != '.')
- return (0);
- /*
- * At this point namlen must be 1 or 2.
- * 1 implies ".", 2 implies ".." if second
- * char is also "."
- */
- if (namlen == 1)
- continue;
- if (dp->name[1] == '.' && dp->inode == parentino)
- continue;
- return (0);
- }
- return (1);
-}
-
-/*
- * Check if source directory is in the path of the target directory.
- * Target is supplied locked, source is unlocked.
- * The target is always vput before returning.
- */
-int
-ext2_checkpath(source, target, cred)
- struct inode *source, *target;
- struct ucred *cred;
-{
- struct vnode *vp;
- int error, rootino, namlen;
- struct dirtemplate dirbuf;
-
- vp = ITOV(target);
- if (target->i_number == source->i_number) {
- error = EEXIST;
- goto out;
- }
- rootino = ROOTINO;
- error = 0;
- if (target->i_number == rootino)
- goto out;
-
- for (;;) {
- if (vp->v_type != VDIR) {
- error = ENOTDIR;
- break;
- }
- error = vn_rdwr(UIO_READ, vp, (caddr_t)&dirbuf,
- sizeof (struct dirtemplate), (off_t)0, UIO_SYSSPACE,
- IO_NODELOCKED | IO_NOMACCHECK, cred, NOCRED, (int *)0,
- (struct thread *)0);
- if (error != 0)
- break;
- namlen = dirbuf.dotdot_type; /* like ufs little-endian */
- if (namlen != 2 ||
- dirbuf.dotdot_name[0] != '.' ||
- dirbuf.dotdot_name[1] != '.') {
- error = ENOTDIR;
- break;
- }
- if (dirbuf.dotdot_ino == source->i_number) {
- error = EINVAL;
- break;
- }
- if (dirbuf.dotdot_ino == rootino)
- break;
- vput(vp);
- if ((error = VFS_VGET(vp->v_mount, dirbuf.dotdot_ino,
- LK_EXCLUSIVE, &vp)) != 0) {
- vp = NULL;
- break;
- }
- }
-
-out:
- if (error == ENOTDIR)
- printf("checkpath: .. not a directory\n");
- if (vp != NULL)
- vput(vp);
- return (error);
-}
diff --git a/sys/gnu/fs/ext2fs/ext2_mount.h b/sys/gnu/fs/ext2fs/ext2_mount.h
deleted file mode 100644
index 4e4894f17ab2..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_mount.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ufsmount.h 8.6 (Berkeley) 3/30/95
- * $FreeBSD$
- */
-
-#ifndef _SYS_GNU_EXT2FS_EXT2_MOUNT_H_
-#define _SYS_GNU_EXT2FS_EXT2_MOUNT_H_
-
-#ifdef _KERNEL
-
-#ifdef MALLOC_DECLARE
-MALLOC_DECLARE(M_EXT2NODE);
-#endif
-
-struct vnode;
-
-/* This structure describes the ext2fs specific mount structure data. */
-struct ext2mount {
- struct mount *um_mountp; /* filesystem vfs structure */
- dev_t um_dev; /* device mounted */
- struct vnode *um_devvp; /* block device mounted vnode */
-
- struct ext2_sb_info *um_e2fs; /* EXT2FS */
-#define em_e2fsb um_e2fs->s_es
-
- u_long um_nindir; /* indirect ptrs per block */
- u_long um_bptrtodb; /* indir ptr to disk block */
- u_long um_seqinc; /* inc between seq blocks */
-};
-
-/* Convert mount ptr to ext2fsmount ptr. */
-#define VFSTOEXT2(mp) ((struct ext2mount *)((mp)->mnt_data))
-
-/*
- * Macros to access file system parameters in the ufsmount structure.
- * Used by ufs_bmap.
- */
-#define MNINDIR(ump) ((ump)->um_nindir)
-#define blkptrtodb(ump, b) ((b) << (ump)->um_bptrtodb)
-#define is_sequential(ump, a, b) ((b) == (a) + ump->um_seqinc)
-#endif /* _KERNEL */
-
-#endif
diff --git a/sys/gnu/fs/ext2fs/ext2_readwrite.c b/sys/gnu/fs/ext2fs/ext2_readwrite.c
deleted file mode 100644
index 232e46f71ddf..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_readwrite.c
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * modified for Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- */
-/*
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ufs_readwrite.c 8.7 (Berkeley) 1/21/94
- * $FreeBSD$
- */
-
-#define BLKSIZE(a, b, c) blksize(a, b, c)
-#define FS struct ext2_sb_info
-#define I_FS i_e2fs
-#define READ ext2_read
-#define READ_S "ext2_read"
-#define WRITE ext2_write
-#define WRITE_S "ext2_write"
-
-/*
- * Vnode op for reading.
- */
-/* ARGSUSED */
-static int
-READ(ap)
- struct vop_read_args /* {
- struct vnode *a_vp;
- struct uio *a_uio;
- int a_ioflag;
- struct ucred *a_cred;
- } */ *ap;
-{
- struct vnode *vp;
- struct inode *ip;
- struct uio *uio;
- FS *fs;
- struct buf *bp;
- daddr_t lbn, nextlbn;
- off_t bytesinfile;
- long size, xfersize, blkoffset;
- int error, orig_resid;
- int seqcount = ap->a_ioflag >> 16;
- u_short mode;
-
- vp = ap->a_vp;
- ip = VTOI(vp);
- mode = ip->i_mode;
- uio = ap->a_uio;
-
-#ifdef DIAGNOSTIC
- if (uio->uio_rw != UIO_READ)
- panic("%s: mode", READ_S);
-
- if (vp->v_type == VLNK) {
- if ((int)ip->i_size < vp->v_mount->mnt_maxsymlinklen)
- panic("%s: short symlink", READ_S);
- } else if (vp->v_type != VREG && vp->v_type != VDIR)
- panic("%s: type %d", READ_S, vp->v_type);
-#endif
- fs = ip->I_FS;
-#if 0
- if ((u_quad_t)uio->uio_offset > fs->fs_maxfilesize)
- return (EFBIG);
-#endif
-
- orig_resid = uio->uio_resid;
- for (error = 0, bp = NULL; uio->uio_resid > 0; bp = NULL) {
- if ((bytesinfile = ip->i_size - uio->uio_offset) <= 0)
- break;
- lbn = lblkno(fs, uio->uio_offset);
- nextlbn = lbn + 1;
- size = BLKSIZE(fs, ip, lbn);
- blkoffset = blkoff(fs, uio->uio_offset);
-
- xfersize = fs->s_frag_size - blkoffset;
- if (uio->uio_resid < xfersize)
- xfersize = uio->uio_resid;
- if (bytesinfile < xfersize)
- xfersize = bytesinfile;
-
- if (lblktosize(fs, nextlbn) >= ip->i_size)
- error = bread(vp, lbn, size, NOCRED, &bp);
- else if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0)
- error = cluster_read(vp,
- ip->i_size, lbn, size, NOCRED,
- uio->uio_resid, (ap->a_ioflag >> 16), &bp);
- else if (seqcount > 1) {
- int nextsize = BLKSIZE(fs, ip, nextlbn);
- error = breadn(vp, lbn,
- size, &nextlbn, &nextsize, 1, NOCRED, &bp);
- } else
- error = bread(vp, lbn, size, NOCRED, &bp);
- if (error) {
- brelse(bp);
- bp = NULL;
- break;
- }
-
- /*
- * We should only get non-zero b_resid when an I/O error
- * has occurred, which should cause us to break above.
- * However, if the short read did not cause an error,
- * then we want to ensure that we do not uiomove bad
- * or uninitialized data.
- */
- size -= bp->b_resid;
- if (size < xfersize) {
- if (size == 0)
- break;
- xfersize = size;
- }
- error =
- uiomove((char *)bp->b_data + blkoffset, (int)xfersize, uio);
- if (error)
- break;
-
- bqrelse(bp);
- }
- if (bp != NULL)
- bqrelse(bp);
- if (orig_resid > 0 && (error == 0 || uio->uio_resid != orig_resid) &&
- (vp->v_mount->mnt_flag & MNT_NOATIME) == 0)
- ip->i_flag |= IN_ACCESS;
- return (error);
-}
-
-/*
- * Vnode op for writing.
- */
-static int
-WRITE(ap)
- struct vop_write_args /* {
- struct vnode *a_vp;
- struct uio *a_uio;
- int a_ioflag;
- struct ucred *a_cred;
- } */ *ap;
-{
- struct vnode *vp;
- struct uio *uio;
- struct inode *ip;
- FS *fs;
- struct buf *bp;
- struct thread *td;
- daddr_t lbn;
- off_t osize;
- int seqcount;
- int blkoffset, error, flags, ioflag, resid, size, xfersize;
-
- ioflag = ap->a_ioflag;
- seqcount = ap->a_ioflag >> 16;
- uio = ap->a_uio;
- vp = ap->a_vp;
- ip = VTOI(vp);
-
-#ifdef DIAGNOSTIC
- if (uio->uio_rw != UIO_WRITE)
- panic("%s: mode", WRITE_S);
-#endif
-
- switch (vp->v_type) {
- case VREG:
- if (ioflag & IO_APPEND)
- uio->uio_offset = ip->i_size;
- if ((ip->i_flags & APPEND) && uio->uio_offset != ip->i_size)
- return (EPERM);
- /* FALLTHROUGH */
- case VLNK:
- break;
- case VDIR:
- if ((ioflag & IO_SYNC) == 0)
- panic("%s: nonsync dir write", WRITE_S);
- break;
- default:
- panic("%s: type", WRITE_S);
- }
-
- fs = ip->I_FS;
-#if 0
- if (uio->uio_offset < 0 ||
- (u_quad_t)uio->uio_offset + uio->uio_resid > fs->fs_maxfilesize)
- return (EFBIG);
-#endif
- /*
- * Maybe this should be above the vnode op call, but so long as
- * file servers have no limits, I don't think it matters.
- */
- td = uio->uio_td;
- /* For p_rlimit. */
- mtx_assert(&Giant, MA_OWNED);
- if (vp->v_type == VREG && td &&
- uio->uio_offset + uio->uio_resid >
- td->td_proc->p_rlimit[RLIMIT_FSIZE].rlim_cur) {
- PROC_LOCK(td->td_proc);
- psignal(td->td_proc, SIGXFSZ);
- PROC_UNLOCK(td->td_proc);
- return (EFBIG);
- }
-
- resid = uio->uio_resid;
- osize = ip->i_size;
- flags = ioflag & IO_SYNC ? B_SYNC : 0;
-
- for (error = 0; uio->uio_resid > 0;) {
- lbn = lblkno(fs, uio->uio_offset);
- blkoffset = blkoff(fs, uio->uio_offset);
- xfersize = fs->s_frag_size - blkoffset;
- if (uio->uio_resid < xfersize)
- xfersize = uio->uio_resid;
-
- if (uio->uio_offset + xfersize > ip->i_size)
- vnode_pager_setsize(vp, uio->uio_offset + xfersize);
-
- /*
- * Avoid a data-consistency race between write() and mmap()
- * by ensuring that newly allocated blocks are zerod. The
- * race can occur even in the case where the write covers
- * the entire block.
- */
- flags |= B_CLRBUF;
-#if 0
- if (fs->s_frag_size > xfersize)
- flags |= B_CLRBUF;
- else
- flags &= ~B_CLRBUF;
-#endif
-
- error = ext2_balloc(ip,
- lbn, blkoffset + xfersize, ap->a_cred, &bp, flags);
- if (error)
- break;
-
- if (uio->uio_offset + xfersize > ip->i_size) {
- ip->i_size = uio->uio_offset + xfersize;
- }
-
- size = BLKSIZE(fs, ip, lbn) - bp->b_resid;
- if (size < xfersize)
- xfersize = size;
-
- error =
- uiomove((char *)bp->b_data + blkoffset, (int)xfersize, uio);
- if ((ioflag & IO_VMIO) &&
- (LIST_FIRST(&bp->b_dep) == NULL)) /* in ext2fs? */
- bp->b_flags |= B_RELBUF;
-
- if (ioflag & IO_SYNC) {
- (void)bwrite(bp);
- } else if (xfersize + blkoffset == fs->s_frag_size) {
- if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERW) == 0) {
- bp->b_flags |= B_CLUSTEROK;
- cluster_write(bp, ip->i_size, seqcount);
- } else {
- bawrite(bp);
- }
- } else {
- bp->b_flags |= B_CLUSTEROK;
- bdwrite(bp);
- }
- if (error || xfersize == 0)
- break;
- ip->i_flag |= IN_CHANGE | IN_UPDATE;
- }
- /*
- * If we successfully wrote any data, and we are not the superuser
- * we clear the setuid and setgid bits as a precaution against
- * tampering.
- */
- if (resid > uio->uio_resid && ap->a_cred && ap->a_cred->cr_uid != 0)
- ip->i_mode &= ~(ISUID | ISGID);
- if (error) {
- if (ioflag & IO_UNIT) {
- (void)ext2_truncate(vp, osize,
- ioflag & IO_SYNC, ap->a_cred, uio->uio_td);
- uio->uio_offset -= resid - uio->uio_resid;
- uio->uio_resid = resid;
- }
- } else if (resid > uio->uio_resid && (ioflag & IO_SYNC))
- error = ext2_update(vp, 1);
- return (error);
-}
diff --git a/sys/gnu/fs/ext2fs/ext2_subr.c b/sys/gnu/fs/ext2fs/ext2_subr.c
deleted file mode 100644
index e762b38e3a2a..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_subr.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * modified for Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- */
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ffs_subr.c 8.2 (Berkeley) 9/21/93
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/lock.h>
-#include <sys/ucred.h>
-#include <sys/vnode.h>
-
-#include <gnu/ext2fs/inode.h>
-#include <gnu/ext2fs/ext2_extern.h>
-#include <gnu/ext2fs/ext2_fs_sb.h>
-#include <gnu/ext2fs/fs.h>
-
-#include "opt_ddb.h"
-
-#ifdef DDB
-void ext2_checkoverlap(struct buf *, struct inode *);
-#endif
-
-/*
- * Return buffer with the contents of block "offset" from the beginning of
- * directory "ip". If "res" is non-zero, fill it in with a pointer to the
- * remaining space in the directory.
- */
-int
-ext2_blkatoff(vp, offset, res, bpp)
- struct vnode *vp;
- off_t offset;
- char **res;
- struct buf **bpp;
-{
- struct inode *ip;
- struct ext2_sb_info *fs;
- struct buf *bp;
- int32_t lbn;
- int bsize, error;
-
- ip = VTOI(vp);
- fs = ip->i_e2fs;
- lbn = lblkno(fs, offset);
- bsize = blksize(fs, ip, lbn);
-
- *bpp = NULL;
- if ((error = bread(vp, lbn, bsize, NOCRED, &bp)) != 0) {
- brelse(bp);
- return (error);
- }
- if (res)
- *res = (char *)bp->b_data + blkoff(fs, offset);
- *bpp = bp;
- return (0);
-}
-
-#ifdef DDB
-void
-ext2_checkoverlap(bp, ip)
- struct buf *bp;
- struct inode *ip;
-{
- struct buf *ebp, *ep;
- int32_t start, last;
- struct vnode *vp;
-
- ebp = &buf[nbuf];
- start = bp->b_blkno;
- last = start + btodb(bp->b_bcount) - 1;
- for (ep = buf; ep < ebp; ep++) {
- if (ep == bp || (ep->b_flags & B_INVAL) ||
- ep->b_vp == NULLVP)
- continue;
- vp = ip->i_devvp;
- /* look for overlap */
- if (ep->b_bcount == 0 || ep->b_blkno > last ||
- ep->b_blkno + btodb(ep->b_bcount) <= start)
- continue;
- vprint("Disk overlap", vp);
- (void)printf("\tstart %d, end %d overlap start %lld, end %ld\n",
- start, last, (long long)ep->b_blkno,
- (long)(ep->b_blkno + btodb(ep->b_bcount) - 1));
- panic("Disk buffer overlap");
- }
-}
-#endif /* DDB */
diff --git a/sys/gnu/fs/ext2fs/ext2_vfsops.c b/sys/gnu/fs/ext2fs/ext2_vfsops.c
deleted file mode 100644
index 964be9f8d4b4..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_vfsops.c
+++ /dev/null
@@ -1,1230 +0,0 @@
-/*
- * modified for EXT2FS support in Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- */
-/*
- * Copyright (c) 1989, 1991, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ffs_vfsops.c 8.8 (Berkeley) 4/18/94
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/namei.h>
-#include <sys/proc.h>
-#include <sys/kernel.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/conf.h>
-#include <sys/fcntl.h>
-#include <sys/malloc.h>
-#include <sys/stat.h>
-#include <sys/mutex.h>
-
-#include <gnu/ext2fs/ext2_mount.h>
-#include <gnu/ext2fs/inode.h>
-
-#include <gnu/ext2fs/fs.h>
-#include <gnu/ext2fs/ext2_extern.h>
-#include <gnu/ext2fs/ext2_fs.h>
-#include <gnu/ext2fs/ext2_fs_sb.h>
-
-static int ext2_fhtovp(struct mount *, struct fid *, struct vnode **);
-static int ext2_flushfiles(struct mount *mp, int flags, struct thread *td);
-static int ext2_init(struct vfsconf *);
-static int ext2_mount(struct mount *, struct nameidata *, struct thread *);
-static int ext2_mountfs(struct vnode *, struct mount *, struct thread *);
-static int ext2_reload(struct mount *mountp, struct ucred *cred,
- struct thread *td);
-static int ext2_root(struct mount *, struct vnode **vpp);
-static int ext2_sbupdate(struct ext2mount *, int);
-static int ext2_statfs(struct mount *, struct statfs *, struct thread *);
-static int ext2_sync(struct mount *, int, struct ucred *, struct thread *);
-static int ext2_uninit(struct vfsconf *);
-static int ext2_unmount(struct mount *, int, struct thread *);
-static int ext2_vget(struct mount *, ino_t, int, struct vnode **);
-static int ext2_vptofh(struct vnode *, struct fid *);
-
-MALLOC_DEFINE(M_EXT2NODE, "EXT2 node", "EXT2 vnode private part");
-static MALLOC_DEFINE(M_EXT2MNT, "EXT2 mount", "EXT2 mount structure");
-
-static struct vfsops ext2fs_vfsops = {
- NULL,
- vfs_stdstart,
- ext2_unmount,
- ext2_root, /* root inode via vget */
- vfs_stdquotactl,
- ext2_statfs,
- ext2_sync,
- ext2_vget,
- ext2_fhtovp,
- vfs_stdcheckexp,
- ext2_vptofh,
- ext2_init,
- ext2_uninit,
- vfs_stdextattrctl,
- ext2_mount,
-};
-
-VFS_SET(ext2fs_vfsops, ext2fs, 0);
-#define bsd_malloc malloc
-#define bsd_free free
-
-static int ext2fs_inode_hash_lock;
-
-static int ext2_check_sb_compat(struct ext2_super_block *es, dev_t dev,
- int ronly);
-static int compute_sb_data(struct vnode * devvp,
- struct ext2_super_block * es, struct ext2_sb_info * fs);
-
-#ifdef notyet
-static int ext2_mountroot(void);
-
-/*
- * Called by main() when ext2fs is going to be mounted as root.
- *
- * Name is updated by mount(8) after booting.
- */
-#define ROOTNAME "root_device"
-
-static int
-ext2_mountroot()
-{
- struct ext2_sb_info *fs;
- struct mount *mp;
- struct thread *td = curthread;
- struct ext2mount *ump;
- u_int size;
- int error;
-
- if ((error = bdevvp(rootdev, &rootvp))) {
- printf("ext2_mountroot: can't find rootvp\n");
- return (error);
- }
- mp = bsd_malloc((u_long)sizeof(struct mount), M_MOUNT, M_WAITOK);
- bzero((char *)mp, (u_long)sizeof(struct mount));
- TAILQ_INIT(&mp->mnt_nvnodelist);
- TAILQ_INIT(&mp->mnt_reservedvnlist);
- mp->mnt_op = &ext2fs_vfsops;
- mp->mnt_flag = MNT_RDONLY;
- if (error = ext2_mountfs(rootvp, mp, td)) {
- bsd_free(mp, M_MOUNT);
- return (error);
- }
- if (error = vfs_lock(mp)) {
- (void)ext2_unmount(mp, 0, td);
- bsd_free(mp, M_MOUNT);
- return (error);
- }
- TAILQ_INSERT_HEAD(&mountlist, mp, mnt_list);
- mp->mnt_flag |= MNT_ROOTFS;
- mp->mnt_vnodecovered = NULLVP;
- ump = VFSTOEXT2(mp);
- fs = ump->um_e2fs;
- bzero(fs->fs_fsmnt, sizeof(fs->fs_fsmnt));
- fs->fs_fsmnt[0] = '/';
- bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname,
- MNAMELEN);
- (void) copystr(ROOTNAME, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
- &size);
- bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
- (void)ext2_statfs(mp, &mp->mnt_stat, td);
- vfs_unlock(mp);
- inittodr(fs->s_es->s_wtime); /* this helps to set the time */
- return (0);
-}
-#endif
-
-/*
- * VFS Operations.
- *
- * mount system call
- */
-static int
-ext2_mount(mp, ndp, td)
- struct mount *mp;
- struct nameidata *ndp;
- struct thread *td;
-{
- struct export_args *export;
- struct vfsoptlist *opts;
- struct vnode *devvp;
- struct ext2mount *ump = 0;
- struct ext2_sb_info *fs;
- char *path, *fspec;
- size_t size;
- int error, flags, len;
- mode_t accessmode;
-
- opts = mp->mnt_optnew;
-
- vfs_getopt(opts, "fspath", (void **)&path, NULL);
- /* Double-check the length of path.. */
- if (strlen(path) >= MAXMNTLEN - 1)
- return (ENAMETOOLONG);
-
- fspec = NULL;
- error = vfs_getopt(opts, "from", (void **)&fspec, &len);
- if (!error && fspec[len - 1] != '\0')
- return (EINVAL);
-
- /*
- * If updating, check whether changing from read-only to
- * read/write; if there is no device name, that's all we do.
- */
- if (mp->mnt_flag & MNT_UPDATE) {
- ump = VFSTOEXT2(mp);
- fs = ump->um_e2fs;
- error = 0;
- if (fs->s_rd_only == 0 && (mp->mnt_flag & MNT_RDONLY)) {
- flags = WRITECLOSE;
- if (mp->mnt_flag & MNT_FORCE)
- flags |= FORCECLOSE;
- if (vfs_busy(mp, LK_NOWAIT, 0, td))
- return (EBUSY);
- error = ext2_flushfiles(mp, flags, td);
- vfs_unbusy(mp, td);
- if (!error && fs->s_wasvalid) {
- fs->s_es->s_state |= EXT2_VALID_FS;
- ext2_sbupdate(ump, MNT_WAIT);
- }
- fs->s_rd_only = 1;
- }
- if (!error && (mp->mnt_flag & MNT_RELOAD))
- error = ext2_reload(mp, ndp->ni_cnd.cn_cred, td);
- if (error)
- return (error);
- devvp = ump->um_devvp;
- if (ext2_check_sb_compat(fs->s_es, devvp->v_rdev,
- (mp->mnt_kern_flag & MNTK_WANTRDWR) == 0) != 0)
- return (EPERM);
- if (fs->s_rd_only && (mp->mnt_kern_flag & MNTK_WANTRDWR)) {
- /*
- * If upgrade to read-write by non-root, then verify
- * that user has necessary permissions on the device.
- */
- if (suser(td)) {
- vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
- if ((error = VOP_ACCESS(devvp, VREAD | VWRITE,
- td->td_ucred, td)) != 0) {
- VOP_UNLOCK(devvp, 0, td);
- return (error);
- }
- VOP_UNLOCK(devvp, 0, td);
- }
-
- if ((fs->s_es->s_state & EXT2_VALID_FS) == 0 ||
- (fs->s_es->s_state & EXT2_ERROR_FS)) {
- if (mp->mnt_flag & MNT_FORCE) {
- printf(
-"WARNING: %s was not properly dismounted\n",
- fs->fs_fsmnt);
- } else {
- printf(
-"WARNING: R/W mount of %s denied. Filesystem is not clean - run fsck\n",
- fs->fs_fsmnt);
- return (EPERM);
- }
- }
- fs->s_es->s_state &= ~EXT2_VALID_FS;
- ext2_sbupdate(ump, MNT_WAIT);
- fs->s_rd_only = 0;
- }
- if (fspec == NULL) {
- error = vfs_getopt(opts, "export", (void **)&export,
- &len);
- if (error || len != sizeof(struct export_args))
- return (EINVAL);
- /* Process export requests. */
- return (vfs_export(mp, export));
- }
- }
- /*
- * Not an update, or updating the name: look up the name
- * and verify that it refers to a sensible block device.
- */
- if (fspec == NULL)
- return (EINVAL);
- NDINIT(ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, fspec, td);
- if ((error = namei(ndp)) != 0)
- return (error);
- NDFREE(ndp, NDF_ONLY_PNBUF);
- devvp = ndp->ni_vp;
-
- if (!vn_isdisk(devvp, &error)) {
- vrele(devvp);
- return (error);
- }
-
- /*
- * If mount by non-root, then verify that user has necessary
- * permissions on the device.
- */
- if (suser(td)) {
- accessmode = VREAD;
- if ((mp->mnt_flag & MNT_RDONLY) == 0)
- accessmode |= VWRITE;
- vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
- if ((error = VOP_ACCESS(devvp, accessmode, td->td_ucred, td)) != 0) {
- vput(devvp);
- return (error);
- }
- VOP_UNLOCK(devvp, 0, td);
- }
-
- if ((mp->mnt_flag & MNT_UPDATE) == 0) {
- error = ext2_mountfs(devvp, mp, td);
- } else {
- if (devvp != ump->um_devvp)
- error = EINVAL; /* needs translation */
- else
- vrele(devvp);
- }
- if (error) {
- vrele(devvp);
- return (error);
- }
- ump = VFSTOEXT2(mp);
- fs = ump->um_e2fs;
- /*
- * Note that this strncpy() is ok because of a check at the start
- * of ext2_mount().
- */
- strncpy(fs->fs_fsmnt, path, MAXMNTLEN);
- fs->fs_fsmnt[MAXMNTLEN - 1] = '\0';
- (void)copystr(fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
- bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
- (void)ext2_statfs(mp, &mp->mnt_stat, td);
- return (0);
-}
-
-/*
- * checks that the data in the descriptor blocks make sense
- * this is taken from ext2/super.c
- */
-static int ext2_check_descriptors (struct ext2_sb_info * sb)
-{
- int i;
- int desc_block = 0;
- unsigned long block = sb->s_es->s_first_data_block;
- struct ext2_group_desc * gdp = NULL;
-
- /* ext2_debug ("Checking group descriptors"); */
-
- for (i = 0; i < sb->s_groups_count; i++)
- {
- /* examine next descriptor block */
- if ((i % EXT2_DESC_PER_BLOCK(sb)) == 0)
- gdp = (struct ext2_group_desc *)
- sb->s_group_desc[desc_block++]->b_data;
- if (gdp->bg_block_bitmap < block ||
- gdp->bg_block_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
- {
- printf ("ext2_check_descriptors: "
- "Block bitmap for group %d"
- " not in group (block %lu)!\n",
- i, (unsigned long) gdp->bg_block_bitmap);
- return 0;
- }
- if (gdp->bg_inode_bitmap < block ||
- gdp->bg_inode_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
- {
- printf ("ext2_check_descriptors: "
- "Inode bitmap for group %d"
- " not in group (block %lu)!\n",
- i, (unsigned long) gdp->bg_inode_bitmap);
- return 0;
- }
- if (gdp->bg_inode_table < block ||
- gdp->bg_inode_table + sb->s_itb_per_group >=
- block + EXT2_BLOCKS_PER_GROUP(sb))
- {
- printf ("ext2_check_descriptors: "
- "Inode table for group %d"
- " not in group (block %lu)!\n",
- i, (unsigned long) gdp->bg_inode_table);
- return 0;
- }
- block += EXT2_BLOCKS_PER_GROUP(sb);
- gdp++;
- }
- return 1;
-}
-
-static int
-ext2_check_sb_compat(es, dev, ronly)
- struct ext2_super_block *es;
- dev_t dev;
- int ronly;
-{
-
- if (es->s_magic != EXT2_SUPER_MAGIC) {
- printf("ext2fs: %s: wrong magic number %#x (expected %#x)\n",
- devtoname(dev), es->s_magic, EXT2_SUPER_MAGIC);
- return (1);
- }
- if (es->s_rev_level > EXT2_GOOD_OLD_REV) {
- if (es->s_feature_incompat & ~EXT2_FEATURE_INCOMPAT_SUPP) {
- printf(
-"WARNING: mount of %s denied due to unsupported optional features\n",
- devtoname(dev));
- return (1);
- }
- if (!ronly &&
- (es->s_feature_ro_compat & ~EXT2_FEATURE_RO_COMPAT_SUPP)) {
- printf(
-"WARNING: R/W mount of %s denied due to unsupported optional features\n",
- devtoname(dev));
- return (1);
- }
- }
- return (0);
-}
-
-/*
- * this computes the fields of the ext2_sb_info structure from the
- * data in the ext2_super_block structure read in
- */
-static int compute_sb_data(devvp, es, fs)
- struct vnode * devvp;
- struct ext2_super_block * es;
- struct ext2_sb_info * fs;
-{
- int db_count, error;
- int i, j;
- int logic_sb_block = 1; /* XXX for now */
-
-#if 1
-#define V(v)
-#else
-#define V(v) printf(#v"= %d\n", fs->v);
-#endif
-
- fs->s_blocksize = EXT2_MIN_BLOCK_SIZE << es->s_log_block_size;
- V(s_blocksize)
- fs->s_bshift = EXT2_MIN_BLOCK_LOG_SIZE + es->s_log_block_size;
- V(s_bshift)
- fs->s_fsbtodb = es->s_log_block_size + 1;
- V(s_fsbtodb)
- fs->s_qbmask = fs->s_blocksize - 1;
- V(s_bmask)
- fs->s_blocksize_bits = EXT2_BLOCK_SIZE_BITS(es);
- V(s_blocksize_bits)
- fs->s_frag_size = EXT2_MIN_FRAG_SIZE << es->s_log_frag_size;
- V(s_frag_size)
- if (fs->s_frag_size)
- fs->s_frags_per_block = fs->s_blocksize / fs->s_frag_size;
- V(s_frags_per_block)
- fs->s_blocks_per_group = es->s_blocks_per_group;
- V(s_blocks_per_group)
- fs->s_frags_per_group = es->s_frags_per_group;
- V(s_frags_per_group)
- fs->s_inodes_per_group = es->s_inodes_per_group;
- V(s_inodes_per_group)
- fs->s_inodes_per_block = fs->s_blocksize / EXT2_INODE_SIZE;
- V(s_inodes_per_block)
- fs->s_itb_per_group = fs->s_inodes_per_group /fs->s_inodes_per_block;
- V(s_itb_per_group)
- fs->s_desc_per_block = fs->s_blocksize / sizeof (struct ext2_group_desc);
- V(s_desc_per_block)
- /* s_resuid / s_resgid ? */
- fs->s_groups_count = (es->s_blocks_count -
- es->s_first_data_block +
- EXT2_BLOCKS_PER_GROUP(fs) - 1) /
- EXT2_BLOCKS_PER_GROUP(fs);
- V(s_groups_count)
- db_count = (fs->s_groups_count + EXT2_DESC_PER_BLOCK(fs) - 1) /
- EXT2_DESC_PER_BLOCK(fs);
- fs->s_db_per_group = db_count;
- V(s_db_per_group)
-
- fs->s_group_desc = bsd_malloc(db_count * sizeof (struct buf *),
- M_EXT2MNT, M_WAITOK);
-
- /* adjust logic_sb_block */
- if(fs->s_blocksize > SBSIZE)
- /* Godmar thinks: if the blocksize is greater than 1024, then
- the superblock is logically part of block zero.
- */
- logic_sb_block = 0;
-
- for (i = 0; i < db_count; i++) {
- error = bread(devvp , fsbtodb(fs, logic_sb_block + i + 1),
- fs->s_blocksize, NOCRED, &fs->s_group_desc[i]);
- if(error) {
- for (j = 0; j < i; j++)
- brelse(fs->s_group_desc[j]);
- bsd_free(fs->s_group_desc, M_EXT2MNT);
- printf("EXT2-fs: unable to read group descriptors (%d)\n", error);
- return EIO;
- }
- /* Set the B_LOCKED flag on the buffer, then brelse() it */
- LCK_BUF(fs->s_group_desc[i])
- }
- if(!ext2_check_descriptors(fs)) {
- for (j = 0; j < db_count; j++)
- ULCK_BUF(fs->s_group_desc[j])
- bsd_free(fs->s_group_desc, M_EXT2MNT);
- printf("EXT2-fs: (ext2_check_descriptors failure) "
- "unable to read group descriptors\n");
- return EIO;
- }
-
- for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) {
- fs->s_inode_bitmap_number[i] = 0;
- fs->s_inode_bitmap[i] = NULL;
- fs->s_block_bitmap_number[i] = 0;
- fs->s_block_bitmap[i] = NULL;
- }
- fs->s_loaded_inode_bitmaps = 0;
- fs->s_loaded_block_bitmaps = 0;
- return 0;
-}
-
-/*
- * Reload all incore data for a filesystem (used after running fsck on
- * the root filesystem and finding things to fix). The filesystem must
- * be mounted read-only.
- *
- * Things to do to update the mount:
- * 1) invalidate all cached meta-data.
- * 2) re-read superblock from disk.
- * 3) re-read summary information from disk.
- * 4) invalidate all inactive vnodes.
- * 5) invalidate all cached file data.
- * 6) re-read inode data for all active vnodes.
- */
-static int
-ext2_reload(mountp, cred, td)
- struct mount *mountp;
- struct ucred *cred;
- struct thread *td;
-{
- struct vnode *vp, *nvp, *devvp;
- struct inode *ip;
- struct buf *bp;
- struct ext2_super_block * es;
- struct ext2_sb_info *fs;
- int error;
-
- if ((mountp->mnt_flag & MNT_RDONLY) == 0)
- return (EINVAL);
- /*
- * Step 1: invalidate all cached meta-data.
- */
- devvp = VFSTOEXT2(mountp)->um_devvp;
- if (vinvalbuf(devvp, 0, cred, td, 0, 0))
- panic("ext2_reload: dirty1");
- /*
- * Step 2: re-read superblock from disk.
- * constants have been adjusted for ext2
- */
- if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0)
- return (error);
- es = (struct ext2_super_block *)bp->b_data;
- if (ext2_check_sb_compat(es, devvp->v_rdev, 0) != 0) {
- brelse(bp);
- return (EIO); /* XXX needs translation */
- }
- fs = VFSTOEXT2(mountp)->um_e2fs;
- bcopy(bp->b_data, fs->s_es, sizeof(struct ext2_super_block));
-
- if((error = compute_sb_data(devvp, es, fs)) != 0) {
- brelse(bp);
- return error;
- }
-#ifdef UNKLAR
- if (fs->fs_sbsize < SBSIZE)
- bp->b_flags |= B_INVAL;
-#endif
- brelse(bp);
-
-loop:
- mtx_lock(&mntvnode_mtx);
- for (vp = TAILQ_FIRST(&mountp->mnt_nvnodelist); vp != NULL; vp = nvp) {
- if (vp->v_mount != mountp) {
- mtx_unlock(&mntvnode_mtx);
- goto loop;
- }
- nvp = TAILQ_NEXT(vp, v_nmntvnodes);
- mtx_unlock(&mntvnode_mtx);
- /*
- * Step 4: invalidate all inactive vnodes.
- */
- if (vrecycle(vp, NULL, td))
- goto loop;
- /*
- * Step 5: invalidate all cached file data.
- */
- mtx_lock(&vp->v_interlock);
- if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, td)) {
- goto loop;
- }
- if (vinvalbuf(vp, 0, cred, td, 0, 0))
- panic("ext2_reload: dirty2");
- /*
- * Step 6: re-read inode data for all active vnodes.
- */
- ip = VTOI(vp);
- error =
- bread(devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
- (int)fs->s_blocksize, NOCRED, &bp);
- if (error) {
- vput(vp);
- return (error);
- }
- ext2_ei2i((struct ext2_inode *) ((char *)bp->b_data +
- EXT2_INODE_SIZE * ino_to_fsbo(fs, ip->i_number)), ip);
- brelse(bp);
- vput(vp);
- mtx_lock(&mntvnode_mtx);
- }
- mtx_unlock(&mntvnode_mtx);
- return (0);
-}
-
-/*
- * Common code for mount and mountroot
- */
-static int
-ext2_mountfs(devvp, mp, td)
- struct vnode *devvp;
- struct mount *mp;
- struct thread *td;
-{
- struct ext2mount *ump;
- struct buf *bp;
- struct ext2_sb_info *fs;
- struct ext2_super_block * es;
- dev_t dev = devvp->v_rdev;
- int error;
- int ronly;
-
- /*
- * Disallow multiple mounts of the same device.
- * Disallow mounting of a device that is currently in use
- * (except for root, which might share swap device for miniroot).
- * Flush out any old buffers remaining from a previous use.
- */
- if ((error = vfs_mountedon(devvp)) != 0)
- return (error);
- if (vcount(devvp) > 1 && devvp != rootvp)
- return (EBUSY);
- if ((error = vinvalbuf(devvp, V_SAVE, td->td_ucred, td, 0, 0)) != 0)
- return (error);
-#ifdef READONLY
-/* turn on this to force it to be read-only */
- mp->mnt_flag |= MNT_RDONLY;
-#endif
-
- ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
- vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
- error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, td);
- VOP_UNLOCK(devvp, 0, td);
- if (error)
- return (error);
- if (devvp->v_rdev->si_iosize_max != 0)
- mp->mnt_iosize_max = devvp->v_rdev->si_iosize_max;
- if (mp->mnt_iosize_max > MAXPHYS)
- mp->mnt_iosize_max = MAXPHYS;
-
- bp = NULL;
- ump = NULL;
- if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0)
- goto out;
- es = (struct ext2_super_block *)bp->b_data;
- if (ext2_check_sb_compat(es, dev, ronly) != 0) {
- error = EINVAL; /* XXX needs translation */
- goto out;
- }
- if ((es->s_state & EXT2_VALID_FS) == 0 ||
- (es->s_state & EXT2_ERROR_FS)) {
- if (ronly || (mp->mnt_flag & MNT_FORCE)) {
- printf(
-"WARNING: Filesystem was not properly dismounted\n");
- } else {
- printf(
-"WARNING: R/W mount denied. Filesystem is not clean - run fsck\n");
- error = EPERM;
- goto out;
- }
- }
- ump = bsd_malloc(sizeof *ump, M_EXT2MNT, M_WAITOK);
- bzero((caddr_t)ump, sizeof *ump);
- /* I don't know whether this is the right strategy. Note that
- we dynamically allocate both an ext2_sb_info and an ext2_super_block
- while Linux keeps the super block in a locked buffer
- */
- ump->um_e2fs = bsd_malloc(sizeof(struct ext2_sb_info),
- M_EXT2MNT, M_WAITOK);
- ump->um_e2fs->s_es = bsd_malloc(sizeof(struct ext2_super_block),
- M_EXT2MNT, M_WAITOK);
- bcopy(es, ump->um_e2fs->s_es, (u_int)sizeof(struct ext2_super_block));
- if ((error = compute_sb_data(devvp, ump->um_e2fs->s_es, ump->um_e2fs)))
- goto out;
- /*
- * We don't free the group descriptors allocated by compute_sb_data()
- * until ext2_unmount(). This is OK since the mount will succeed.
- */
- brelse(bp);
- bp = NULL;
- fs = ump->um_e2fs;
- fs->s_rd_only = ronly; /* ronly is set according to mnt_flags */
- /* if the fs is not mounted read-only, make sure the super block is
- always written back on a sync()
- */
- fs->s_wasvalid = fs->s_es->s_state & EXT2_VALID_FS ? 1 : 0;
- if (ronly == 0) {
- fs->s_dirt = 1; /* mark it modified */
- fs->s_es->s_state &= ~EXT2_VALID_FS; /* set fs invalid */
- }
- mp->mnt_data = (qaddr_t)ump;
- mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
- mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
- mp->mnt_maxsymlinklen = EXT2_MAXSYMLINKLEN;
- mp->mnt_flag |= MNT_LOCAL;
- ump->um_mountp = mp;
- ump->um_dev = dev;
- ump->um_devvp = devvp;
- /* setting those two parameters allowed us to use
- ufs_bmap w/o changse !
- */
- ump->um_nindir = EXT2_ADDR_PER_BLOCK(fs);
- ump->um_bptrtodb = fs->s_es->s_log_block_size + 1;
- ump->um_seqinc = EXT2_FRAGS_PER_BLOCK(fs);
- devvp->v_rdev->si_mountpoint = mp;
- if (ronly == 0)
- ext2_sbupdate(ump, MNT_WAIT);
- return (0);
-out:
- if (bp)
- brelse(bp);
- (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, td);
- if (ump) {
- bsd_free(ump->um_e2fs->s_es, M_EXT2MNT);
- bsd_free(ump->um_e2fs, M_EXT2MNT);
- bsd_free(ump, M_EXT2MNT);
- mp->mnt_data = (qaddr_t)0;
- }
- return (error);
-}
-
-/*
- * unmount system call
- */
-static int
-ext2_unmount(mp, mntflags, td)
- struct mount *mp;
- int mntflags;
- struct thread *td;
-{
- struct ext2mount *ump;
- struct ext2_sb_info *fs;
- int error, flags, ronly, i;
-
- flags = 0;
- if (mntflags & MNT_FORCE) {
- if (mp->mnt_flag & MNT_ROOTFS)
- return (EINVAL);
- flags |= FORCECLOSE;
- }
- if ((error = ext2_flushfiles(mp, flags, td)) != 0)
- return (error);
- ump = VFSTOEXT2(mp);
- fs = ump->um_e2fs;
- ronly = fs->s_rd_only;
- if (ronly == 0) {
- if (fs->s_wasvalid)
- fs->s_es->s_state |= EXT2_VALID_FS;
- ext2_sbupdate(ump, MNT_WAIT);
- }
-
- /* release buffers containing group descriptors */
- for(i = 0; i < fs->s_db_per_group; i++)
- ULCK_BUF(fs->s_group_desc[i])
- bsd_free(fs->s_group_desc, M_EXT2MNT);
-
- /* release cached inode/block bitmaps */
- for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
- if (fs->s_inode_bitmap[i])
- ULCK_BUF(fs->s_inode_bitmap[i])
-
- for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
- if (fs->s_block_bitmap[i])
- ULCK_BUF(fs->s_block_bitmap[i])
-
- ump->um_devvp->v_rdev->si_mountpoint = NULL;
- error = VOP_CLOSE(ump->um_devvp, ronly ? FREAD : FREAD|FWRITE,
- NOCRED, td);
- vrele(ump->um_devvp);
- bsd_free(fs->s_es, M_EXT2MNT);
- bsd_free(fs, M_EXT2MNT);
- bsd_free(ump, M_EXT2MNT);
- mp->mnt_data = (qaddr_t)0;
- mp->mnt_flag &= ~MNT_LOCAL;
- return (error);
-}
-
-/*
- * Flush out all the files in a filesystem.
- */
-static int
-ext2_flushfiles(mp, flags, td)
- struct mount *mp;
- int flags;
- struct thread *td;
-{
- int error;
-
- error = vflush(mp, 0, flags);
- return (error);
-}
-
-/*
- * Get file system statistics.
- * taken from ext2/super.c ext2_statfs
- */
-static int
-ext2_statfs(mp, sbp, td)
- struct mount *mp;
- struct statfs *sbp;
- struct thread *td;
-{
- unsigned long overhead;
- struct ext2mount *ump;
- struct ext2_sb_info *fs;
- struct ext2_super_block *es;
- int i, nsb;
-
- ump = VFSTOEXT2(mp);
- fs = ump->um_e2fs;
- es = fs->s_es;
-
- if (es->s_magic != EXT2_SUPER_MAGIC)
- panic("ext2_statfs - magic number spoiled");
-
- /*
- * Compute the overhead (FS structures)
- */
- if (es->s_feature_ro_compat & EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) {
- nsb = 0;
- for (i = 0 ; i < fs->s_groups_count; i++)
- if (ext2_group_sparse(i))
- nsb++;
- } else
- nsb = fs->s_groups_count;
- overhead = es->s_first_data_block +
- /* Superblocks and block group descriptors: */
- nsb * (1 + fs->s_db_per_group) +
- /* Inode bitmap, block bitmap, and inode table: */
- fs->s_groups_count * (1 + 1 + fs->s_itb_per_group);
-
- sbp->f_bsize = EXT2_FRAG_SIZE(fs);
- sbp->f_iosize = EXT2_BLOCK_SIZE(fs);
- sbp->f_blocks = es->s_blocks_count - overhead;
- sbp->f_bfree = es->s_free_blocks_count;
- sbp->f_bavail = sbp->f_bfree - es->s_r_blocks_count;
- sbp->f_files = es->s_inodes_count;
- sbp->f_ffree = es->s_free_inodes_count;
- if (sbp != &mp->mnt_stat) {
- sbp->f_type = mp->mnt_vfc->vfc_typenum;
- bcopy((caddr_t)mp->mnt_stat.f_mntonname,
- (caddr_t)&sbp->f_mntonname[0], MNAMELEN);
- bcopy((caddr_t)mp->mnt_stat.f_mntfromname,
- (caddr_t)&sbp->f_mntfromname[0], MNAMELEN);
- }
- return (0);
-}
-
-/*
- * Go through the disk queues to initiate sandbagged IO;
- * go through the inodes to write those that have been modified;
- * initiate the writing of the super block if it has been modified.
- *
- * Note: we are always called with the filesystem marked `MPBUSY'.
- */
-static int
-ext2_sync(mp, waitfor, cred, td)
- struct mount *mp;
- int waitfor;
- struct ucred *cred;
- struct thread *td;
-{
- struct vnode *nvp, *vp;
- struct inode *ip;
- struct ext2mount *ump = VFSTOEXT2(mp);
- struct ext2_sb_info *fs;
- int error, allerror = 0;
-
- fs = ump->um_e2fs;
- if (fs->s_dirt != 0 && fs->s_rd_only != 0) { /* XXX */
- printf("fs = %s\n", fs->fs_fsmnt);
- panic("ext2_sync: rofs mod");
- }
- /*
- * Write back each (modified) inode.
- */
- mtx_lock(&mntvnode_mtx);
-loop:
- for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist); vp != NULL; vp = nvp) {
- /*
- * If the vnode that we are about to sync is no longer
- * associated with this mount point, start over.
- */
- if (vp->v_mount != mp)
- goto loop;
- nvp = TAILQ_NEXT(vp, v_nmntvnodes);
- mtx_unlock(&mntvnode_mtx);
- VI_LOCK(vp);
- ip = VTOI(vp);
- if (vp->v_type == VNON ||
- ((ip->i_flag &
- (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) == 0 &&
- (TAILQ_EMPTY(&vp->v_dirtyblkhd) || waitfor == MNT_LAZY))) {
- VI_UNLOCK(vp);
- mtx_lock(&mntvnode_mtx);
- continue;
- }
- error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK, td);
- if (error) {
- mtx_lock(&mntvnode_mtx);
- if (error == ENOENT)
- goto loop;
- continue;
- }
- if ((error = VOP_FSYNC(vp, cred, waitfor, td)) != 0)
- allerror = error;
- VOP_UNLOCK(vp, 0, td);
- vrele(vp);
- mtx_lock(&mntvnode_mtx);
- }
- mtx_unlock(&mntvnode_mtx);
- /*
- * Force stale file system control information to be flushed.
- */
- if (waitfor != MNT_LAZY) {
- vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY, td);
- if ((error = VOP_FSYNC(ump->um_devvp, cred, waitfor, td)) != 0)
- allerror = error;
- VOP_UNLOCK(ump->um_devvp, 0, td);
- }
- /*
- * Write back modified superblock.
- */
- if (fs->s_dirt != 0) {
- fs->s_dirt = 0;
- fs->s_es->s_wtime = time_second;
- if ((error = ext2_sbupdate(ump, waitfor)) != 0)
- allerror = error;
- }
- return (allerror);
-}
-
-/*
- * Look up an EXT2FS dinode number to find its incore vnode, otherwise read it
- * in from disk. If it is in core, wait for the lock bit to clear, then
- * return the inode locked. Detection and handling of mount points must be
- * done by the calling routine.
- */
-static int
-ext2_vget(mp, ino, flags, vpp)
- struct mount *mp;
- ino_t ino;
- int flags;
- struct vnode **vpp;
-{
- struct ext2_sb_info *fs;
- struct inode *ip;
- struct ext2mount *ump;
- struct buf *bp;
- struct vnode *vp;
- dev_t dev;
- int i, error;
- int used_blocks;
-
- ump = VFSTOEXT2(mp);
- dev = ump->um_dev;
-restart:
- if ((error = ext2_ihashget(dev, ino, flags, vpp)) != 0)
- return (error);
- if (*vpp != NULL)
- return (0);
-
- /*
- * Lock out the creation of new entries in the FFS hash table in
- * case getnewvnode() or MALLOC() blocks, otherwise a duplicate
- * may occur!
- */
- if (ext2fs_inode_hash_lock) {
- while (ext2fs_inode_hash_lock) {
- ext2fs_inode_hash_lock = -1;
- tsleep(&ext2fs_inode_hash_lock, PVM, "e2vget", 0);
- }
- goto restart;
- }
- ext2fs_inode_hash_lock = 1;
-
- /*
- * If this MALLOC() is performed after the getnewvnode()
- * it might block, leaving a vnode with a NULL v_data to be
- * found by ext2_sync() if a sync happens to fire right then,
- * which will cause a panic because ext2_sync() blindly
- * dereferences vp->v_data (as well it should).
- */
- MALLOC(ip, struct inode *, sizeof(struct inode), M_EXT2NODE, M_WAITOK);
-
- /* Allocate a new vnode/inode. */
- if ((error = getnewvnode("ext2fs", mp, ext2_vnodeop_p, &vp)) != 0) {
- if (ext2fs_inode_hash_lock < 0)
- wakeup(&ext2fs_inode_hash_lock);
- ext2fs_inode_hash_lock = 0;
- *vpp = NULL;
- FREE(ip, M_EXT2NODE);
- return (error);
- }
- bzero((caddr_t)ip, sizeof(struct inode));
- vp->v_data = ip;
- ip->i_vnode = vp;
- ip->i_e2fs = fs = ump->um_e2fs;
- ip->i_dev = dev;
- ip->i_number = ino;
- /*
- * Put it onto its hash chain and lock it so that other requests for
- * this inode will block if they arrive while we are sleeping waiting
- * for old data structures to be purged or for the contents of the
- * disk portion of this inode to be read.
- */
- ext2_ihashins(ip);
-
- if (ext2fs_inode_hash_lock < 0)
- wakeup(&ext2fs_inode_hash_lock);
- ext2fs_inode_hash_lock = 0;
-
- /* Read in the disk contents for the inode, copy into the inode. */
-#if 0
-printf("ext2_vget(%d) dbn= %d ", ino, fsbtodb(fs, ino_to_fsba(fs, ino)));
-#endif
- if ((error = bread(ump->um_devvp, fsbtodb(fs, ino_to_fsba(fs, ino)),
- (int)fs->s_blocksize, NOCRED, &bp)) != 0) {
- /*
- * The inode does not contain anything useful, so it would
- * be misleading to leave it on its hash chain. With mode
- * still zero, it will be unlinked and returned to the free
- * list by vput().
- */
- vput(vp);
- brelse(bp);
- *vpp = NULL;
- return (error);
- }
- /* convert ext2 inode to dinode */
- ext2_ei2i((struct ext2_inode *) ((char *)bp->b_data + EXT2_INODE_SIZE *
- ino_to_fsbo(fs, ino)), ip);
- ip->i_block_group = ino_to_cg(fs, ino);
- ip->i_next_alloc_block = 0;
- ip->i_next_alloc_goal = 0;
- ip->i_prealloc_count = 0;
- ip->i_prealloc_block = 0;
- /* now we want to make sure that block pointers for unused
- blocks are zeroed out - ext2_balloc depends on this
- although for regular files and directories only
- */
- if(S_ISDIR(ip->i_mode) || S_ISREG(ip->i_mode)) {
- used_blocks = (ip->i_size+fs->s_blocksize-1) / fs->s_blocksize;
- for(i = used_blocks; i < EXT2_NDIR_BLOCKS; i++)
- ip->i_db[i] = 0;
- }
-/*
- ext2_print_inode(ip);
-*/
- brelse(bp);
-
- /*
- * Initialize the vnode from the inode, check for aliases.
- * Note that the underlying vnode may have changed.
- */
- if ((error = ext2_vinit(mp, ext2_specop_p, ext2_fifoop_p, &vp)) != 0) {
- vput(vp);
- *vpp = NULL;
- return (error);
- }
- /*
- * Finish inode initialization now that aliasing has been resolved.
- */
- ip->i_devvp = ump->um_devvp;
- VREF(ip->i_devvp);
- /*
- * Set up a generation number for this inode if it does not
- * already have one. This should only happen on old filesystems.
- */
- if (ip->i_gen == 0) {
- ip->i_gen = random() / 2 + 1;
- if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
- ip->i_flag |= IN_MODIFIED;
- }
- *vpp = vp;
- return (0);
-}
-
-/*
- * File handle to vnode
- *
- * Have to be really careful about stale file handles:
- * - check that the inode number is valid
- * - call ext2_vget() to get the locked inode
- * - check for an unallocated inode (i_mode == 0)
- * - check that the given client host has export rights and return
- * those rights via. exflagsp and credanonp
- */
-static int
-ext2_fhtovp(mp, fhp, vpp)
- struct mount *mp;
- struct fid *fhp;
- struct vnode **vpp;
-{
- struct inode *ip;
- struct ufid *ufhp;
- struct vnode *nvp;
- struct ext2_sb_info *fs;
- int error;
-
- ufhp = (struct ufid *)fhp;
- fs = VFSTOEXT2(mp)->um_e2fs;
- if (ufhp->ufid_ino < ROOTINO ||
- ufhp->ufid_ino > fs->s_groups_count * fs->s_es->s_inodes_per_group)
- return (ESTALE);
-
- error = VFS_VGET(mp, ufhp->ufid_ino, LK_EXCLUSIVE, &nvp);
- if (error) {
- *vpp = NULLVP;
- return (error);
- }
- ip = VTOI(nvp);
- if (ip->i_mode == 0 ||
- ip->i_gen != ufhp->ufid_gen || ip->i_nlink <= 0) {
- vput(nvp);
- *vpp = NULLVP;
- return (ESTALE);
- }
- *vpp = nvp;
- return (0);
-}
-
-/*
- * Vnode pointer to File handle
- */
-/* ARGSUSED */
-static int
-ext2_vptofh(vp, fhp)
- struct vnode *vp;
- struct fid *fhp;
-{
- struct inode *ip;
- struct ufid *ufhp;
-
- ip = VTOI(vp);
- ufhp = (struct ufid *)fhp;
- ufhp->ufid_len = sizeof(struct ufid);
- ufhp->ufid_ino = ip->i_number;
- ufhp->ufid_gen = ip->i_gen;
- return (0);
-}
-
-/*
- * Write a superblock and associated information back to disk.
- */
-static int
-ext2_sbupdate(mp, waitfor)
- struct ext2mount *mp;
- int waitfor;
-{
- struct ext2_sb_info *fs = mp->um_e2fs;
- struct ext2_super_block *es = fs->s_es;
- struct buf *bp;
- int error = 0;
-/*
-printf("\nupdating superblock, waitfor=%s\n", waitfor == MNT_WAIT ? "yes":"no");
-*/
- bp = getblk(mp->um_devvp, SBLOCK, SBSIZE, 0, 0, 0);
- bcopy((caddr_t)es, bp->b_data, (u_int)sizeof(struct ext2_super_block));
- if (waitfor == MNT_WAIT)
- error = bwrite(bp);
- else
- bawrite(bp);
-
- /*
- * The buffers for group descriptors, inode bitmaps and block bitmaps
- * are not busy at this point and are (hopefully) written by the
- * usual sync mechanism. No need to write them here
- */
-
- return (error);
-}
-
-/*
- * Return the root of a filesystem.
- */
-static int
-ext2_root(mp, vpp)
- struct mount *mp;
- struct vnode **vpp;
-{
- struct vnode *nvp;
- int error;
-
- error = VFS_VGET(mp, (ino_t)ROOTINO, LK_EXCLUSIVE, &nvp);
- if (error)
- return (error);
- *vpp = nvp;
- return (0);
-}
-
-static int
-ext2_init(struct vfsconf *vfsp)
-{
-
- ext2_ihashinit();
- return (0);
-}
-
-static int
-ext2_uninit(struct vfsconf *vfsp)
-{
-
- ext2_ihashuninit();
- return (0);
-}
diff --git a/sys/gnu/fs/ext2fs/ext2_vnops.c b/sys/gnu/fs/ext2fs/ext2_vnops.c
deleted file mode 100644
index 7f76f7c44364..000000000000
--- a/sys/gnu/fs/ext2fs/ext2_vnops.c
+++ /dev/null
@@ -1,1962 +0,0 @@
-/*
- * modified for EXT2FS support in Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- */
-/*
- * Copyright (c) 1982, 1986, 1989, 1993
- * The Regents of the University of California. All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ufs_vnops.c 8.7 (Berkeley) 2/3/94
- * @(#)ufs_vnops.c 8.27 (Berkeley) 5/27/95
- * $FreeBSD$
- */
-
-#include "opt_suiddir.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/resourcevar.h>
-#include <sys/kernel.h>
-#include <sys/fcntl.h>
-#include <sys/stat.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/proc.h>
-#include <sys/mount.h>
-#include <sys/unistd.h>
-#include <sys/time.h>
-#include <sys/vnode.h>
-#include <sys/namei.h>
-#include <sys/lockf.h>
-#include <sys/event.h>
-#include <sys/conf.h>
-#include <sys/file.h>
-
-#include <vm/vm.h>
-#include <vm/vm_extern.h>
-#include <vm/vnode_pager.h>
-
-#include <fs/fifofs/fifo.h>
-
-#include <sys/signalvar.h>
-#include <ufs/ufs/dir.h>
-
-#include <gnu/ext2fs/inode.h>
-#include <gnu/ext2fs/ext2_mount.h>
-#include <gnu/ext2fs/ext2_fs_sb.h>
-#include <gnu/ext2fs/fs.h>
-#include <gnu/ext2fs/ext2_extern.h>
-#include <gnu/ext2fs/ext2_fs.h>
-
-static int ext2_makeinode(int mode, struct vnode *, struct vnode **, struct componentname *);
-
-static int ext2_access(struct vop_access_args *);
-static int ext2_advlock(struct vop_advlock_args *);
-static int ext2_chmod(struct vnode *, int, struct ucred *, struct thread *);
-static int ext2_chown(struct vnode *, uid_t, gid_t, struct ucred *,
- struct thread *);
-static int ext2_close(struct vop_close_args *);
-static int ext2_create(struct vop_create_args *);
-static int ext2_fsync(struct vop_fsync_args *);
-static int ext2_getattr(struct vop_getattr_args *);
-static int ext2_kqfilter(struct vop_kqfilter_args *ap);
-static int ext2_link(struct vop_link_args *);
-static int ext2_mkdir(struct vop_mkdir_args *);
-static int ext2_mknod(struct vop_mknod_args *);
-static int ext2_open(struct vop_open_args *);
-static int ext2_pathconf(struct vop_pathconf_args *);
-static int ext2_print(struct vop_print_args *);
-static int ext2_read(struct vop_read_args *);
-static int ext2_readlink(struct vop_readlink_args *);
-static int ext2_remove(struct vop_remove_args *);
-static int ext2_rename(struct vop_rename_args *);
-static int ext2_rmdir(struct vop_rmdir_args *);
-static int ext2_setattr(struct vop_setattr_args *);
-static int ext2_strategy(struct vop_strategy_args *);
-static int ext2_symlink(struct vop_symlink_args *);
-static int ext2_write(struct vop_write_args *);
-static int ext2fifo_close(struct vop_close_args *);
-static int ext2fifo_kqfilter(struct vop_kqfilter_args *);
-static int ext2fifo_read(struct vop_read_args *);
-static int ext2fifo_write(struct vop_write_args *);
-static int ext2spec_close(struct vop_close_args *);
-static int ext2spec_read(struct vop_read_args *);
-static int ext2spec_write(struct vop_write_args *);
-static int filt_ext2read(struct knote *kn, long hint);
-static int filt_ext2write(struct knote *kn, long hint);
-static int filt_ext2vnode(struct knote *kn, long hint);
-static void filt_ext2detach(struct knote *kn);
-
-/* Global vfs data structures for ext2. */
-vop_t **ext2_vnodeop_p;
-static struct vnodeopv_entry_desc ext2_vnodeop_entries[] = {
- { &vop_default_desc, (vop_t *) vop_defaultop },
- { &vop_access_desc, (vop_t *) ext2_access },
- { &vop_advlock_desc, (vop_t *) ext2_advlock },
- { &vop_bmap_desc, (vop_t *) ext2_bmap },
- { &vop_cachedlookup_desc, (vop_t *) ext2_lookup },
- { &vop_close_desc, (vop_t *) ext2_close },
- { &vop_create_desc, (vop_t *) ext2_create },
- { &vop_fsync_desc, (vop_t *) ext2_fsync },
- { &vop_getattr_desc, (vop_t *) ext2_getattr },
- { &vop_getwritemount_desc, (vop_t *) vop_stdgetwritemount },
- { &vop_inactive_desc, (vop_t *) ext2_inactive },
- { &vop_link_desc, (vop_t *) ext2_link },
- { &vop_lookup_desc, (vop_t *) vfs_cache_lookup },
- { &vop_mkdir_desc, (vop_t *) ext2_mkdir },
- { &vop_mknod_desc, (vop_t *) ext2_mknod },
- { &vop_open_desc, (vop_t *) ext2_open },
- { &vop_pathconf_desc, (vop_t *) ext2_pathconf },
- { &vop_poll_desc, (vop_t *) vop_stdpoll },
- { &vop_kqfilter_desc, (vop_t *) ext2_kqfilter },
- { &vop_print_desc, (vop_t *) ext2_print },
- { &vop_read_desc, (vop_t *) ext2_read },
- { &vop_readdir_desc, (vop_t *) ext2_readdir },
- { &vop_readlink_desc, (vop_t *) ext2_readlink },
- { &vop_reallocblks_desc, (vop_t *) ext2_reallocblks },
- { &vop_reclaim_desc, (vop_t *) ext2_reclaim },
- { &vop_remove_desc, (vop_t *) ext2_remove },
- { &vop_rename_desc, (vop_t *) ext2_rename },
- { &vop_rmdir_desc, (vop_t *) ext2_rmdir },
- { &vop_setattr_desc, (vop_t *) ext2_setattr },
- { &vop_strategy_desc, (vop_t *) ext2_strategy },
- { &vop_symlink_desc, (vop_t *) ext2_symlink },
- { &vop_write_desc, (vop_t *) ext2_write },
- { NULL, NULL }
-};
-static struct vnodeopv_desc ext2fs_vnodeop_opv_desc =
- { &ext2_vnodeop_p, ext2_vnodeop_entries };
-
-vop_t **ext2_specop_p;
-static struct vnodeopv_entry_desc ext2_specop_entries[] = {
- { &vop_default_desc, (vop_t *) spec_vnoperate },
- { &vop_access_desc, (vop_t *) ext2_access },
- { &vop_close_desc, (vop_t *) ext2spec_close },
- { &vop_fsync_desc, (vop_t *) ext2_fsync },
- { &vop_getattr_desc, (vop_t *) ext2_getattr },
- { &vop_inactive_desc, (vop_t *) ext2_inactive },
- { &vop_print_desc, (vop_t *) ext2_print },
- { &vop_read_desc, (vop_t *) ext2spec_read },
- { &vop_reclaim_desc, (vop_t *) ext2_reclaim },
- { &vop_setattr_desc, (vop_t *) ext2_setattr },
- { &vop_write_desc, (vop_t *) ext2spec_write },
- { NULL, NULL }
-};
-static struct vnodeopv_desc ext2fs_specop_opv_desc =
- { &ext2_specop_p, ext2_specop_entries };
-
-vop_t **ext2_fifoop_p;
-static struct vnodeopv_entry_desc ext2_fifoop_entries[] = {
- { &vop_default_desc, (vop_t *) fifo_vnoperate },
- { &vop_access_desc, (vop_t *) ext2_access },
- { &vop_close_desc, (vop_t *) ext2fifo_close },
- { &vop_fsync_desc, (vop_t *) ext2_fsync },
- { &vop_getattr_desc, (vop_t *) ext2_getattr },
- { &vop_inactive_desc, (vop_t *) ext2_inactive },
- { &vop_kqfilter_desc, (vop_t *) ext2fifo_kqfilter },
- { &vop_print_desc, (vop_t *) ext2_print },
- { &vop_read_desc, (vop_t *) ext2fifo_read },
- { &vop_reclaim_desc, (vop_t *) ext2_reclaim },
- { &vop_setattr_desc, (vop_t *) ext2_setattr },
- { &vop_write_desc, (vop_t *) ext2fifo_write },
- { NULL, NULL }
-};
-static struct vnodeopv_desc ext2fs_fifoop_opv_desc =
- { &ext2_fifoop_p, ext2_fifoop_entries };
-
- VNODEOP_SET(ext2fs_vnodeop_opv_desc);
- VNODEOP_SET(ext2fs_specop_opv_desc);
- VNODEOP_SET(ext2fs_fifoop_opv_desc);
-
-#include <gnu/ext2fs/ext2_readwrite.c>
-
-union _qcvt {
- int64_t qcvt;
- int32_t val[2];
-};
-#define SETHIGH(q, h) { \
- union _qcvt tmp; \
- tmp.qcvt = (q); \
- tmp.val[_QUAD_HIGHWORD] = (h); \
- (q) = tmp.qcvt; \
-}
-#define SETLOW(q, l) { \
- union _qcvt tmp; \
- tmp.qcvt = (q); \
- tmp.val[_QUAD_LOWWORD] = (l); \
- (q) = tmp.qcvt; \
-}
-
-/*
- * A virgin directory (no blushing please).
- * Note that the type and namlen fields are reversed relative to ext2.
- * Also, we don't use `struct odirtemplate', since it would just cause
- * endianness problems.
- */
-static struct dirtemplate mastertemplate = {
- 0, 12, 1, EXT2_FT_DIR, ".",
- 0, DIRBLKSIZ - 12, 2, EXT2_FT_DIR, ".."
-};
-static struct dirtemplate omastertemplate = {
- 0, 12, 1, EXT2_FT_UNKNOWN, ".",
- 0, DIRBLKSIZ - 12, 2, EXT2_FT_UNKNOWN, ".."
-};
-
-void
-ext2_itimes(vp)
- struct vnode *vp;
-{
- struct inode *ip;
- struct timespec ts;
-
- ip = VTOI(vp);
- if ((ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) == 0)
- return;
- if ((vp->v_type == VBLK || vp->v_type == VCHR))
- ip->i_flag |= IN_LAZYMOD;
- else
- ip->i_flag |= IN_MODIFIED;
- if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
- vfs_timestamp(&ts);
- if (ip->i_flag & IN_ACCESS) {
- ip->i_atime = ts.tv_sec;
- ip->i_atimensec = ts.tv_nsec;
- }
- if (ip->i_flag & IN_UPDATE) {
- ip->i_mtime = ts.tv_sec;
- ip->i_mtimensec = ts.tv_nsec;
- ip->i_modrev++;
- }
- if (ip->i_flag & IN_CHANGE) {
- ip->i_ctime = ts.tv_sec;
- ip->i_ctimensec = ts.tv_nsec;
- }
- }
- ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);
-}
-
-/*
- * Create a regular file
- */
-static int
-ext2_create(ap)
- struct vop_create_args /* {
- struct vnode *a_dvp;
- struct vnode **a_vpp;
- struct componentname *a_cnp;
- struct vattr *a_vap;
- } */ *ap;
-{
- int error;
-
- error =
- ext2_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode),
- ap->a_dvp, ap->a_vpp, ap->a_cnp);
- if (error)
- return (error);
- return (0);
-}
-
-/*
- * Open called.
- *
- * Nothing to do.
- */
-static int
-ext2_open(ap)
- struct vop_open_args /* {
- struct vnode *a_vp;
- int a_mode;
- struct ucred *a_cred;
- struct thread *a_td;
- } */ *ap;
-{
-
- /*
- * Files marked append-only must be opened for appending.
- */
- if ((VTOI(ap->a_vp)->i_flags & APPEND) &&
- (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
- return (EPERM);
- return (0);
-}
-
-/*
- * Close called.
- *
- * Update the times on the inode.
- */
-static int
-ext2_close(ap)
- struct vop_close_args /* {
- struct vnode *a_vp;
- int a_fflag;
- struct ucred *a_cred;
- struct thread *a_td;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct mount *mp;
-
- VI_LOCK(vp);
- if (vp->v_usecount > 1) {
- ext2_itimes(vp);
- VI_UNLOCK(vp);
- } else {
- VI_UNLOCK(vp);
- /*
- * If we are closing the last reference to an unlinked
- * file, then it will be freed by the inactive routine.
- * Because the freeing causes a the filesystem to be
- * modified, it must be held up during periods when the
- * filesystem is suspended.
- *
- * XXX - EAGAIN is returned to prevent vn_close from
- * repeating the vrele operation.
- */
- if (vp->v_type == VREG && VTOI(vp)->i_nlink == 0) {
- (void) vn_start_write(vp, &mp, V_WAIT);
- vrele(vp);
- vn_finished_write(mp);
- return (EAGAIN);
- }
- }
- return (0);
-}
-
-static int
-ext2_access(ap)
- struct vop_access_args /* {
- struct vnode *a_vp;
- int a_mode;
- struct ucred *a_cred;
- struct thread *a_td;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct inode *ip = VTOI(vp);
- mode_t mode = ap->a_mode;
- int error;
-
- /*
- * Disallow write attempts on read-only file systems;
- * unless the file is a socket, fifo, or a block or
- * character device resident on the file system.
- */
- if (mode & VWRITE) {
- switch (vp->v_type) {
- case VDIR:
- case VLNK:
- case VREG:
- if (vp->v_mount->mnt_flag & MNT_RDONLY)
- return (EROFS);
- break;
- default:
- break;
- }
- }
-
- /* If immutable bit set, nobody gets to write it. */
- if ((mode & VWRITE) && (ip->i_flags & (IMMUTABLE | SF_SNAPSHOT)))
- return (EPERM);
-
- error = vaccess(vp->v_type, ip->i_mode, ip->i_uid, ip->i_gid,
- ap->a_mode, ap->a_cred, NULL);
- return (error);
-}
-
-static int
-ext2_getattr(ap)
- struct vop_getattr_args /* {
- struct vnode *a_vp;
- struct vattr *a_vap;
- struct ucred *a_cred;
- struct thread *a_td;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct inode *ip = VTOI(vp);
- struct vattr *vap = ap->a_vap;
-
- ext2_itimes(vp);
- /*
- * Copy from inode table
- */
- vap->va_fsid = dev2udev(ip->i_dev);
- vap->va_fileid = ip->i_number;
- vap->va_mode = ip->i_mode & ~IFMT;
- vap->va_nlink = ip->i_nlink;
- vap->va_uid = ip->i_uid;
- vap->va_gid = ip->i_gid;
- vap->va_rdev = ip->i_rdev;
- vap->va_size = ip->i_size;
- vap->va_atime.tv_sec = ip->i_atime;
- vap->va_atime.tv_nsec = ip->i_atimensec;
- vap->va_mtime.tv_sec = ip->i_mtime;
- vap->va_mtime.tv_nsec = ip->i_mtimensec;
- vap->va_ctime.tv_sec = ip->i_ctime;
- vap->va_ctime.tv_nsec = ip->i_ctimensec;
- vap->va_flags = ip->i_flags;
- vap->va_gen = ip->i_gen;
- vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
- vap->va_bytes = dbtob((u_quad_t)ip->i_blocks);
- vap->va_type = IFTOVT(ip->i_mode);
- vap->va_filerev = ip->i_modrev;
- return (0);
-}
-
-/*
- * Set attribute vnode op. called from several syscalls
- */
-static int
-ext2_setattr(ap)
- struct vop_setattr_args /* {
- struct vnode *a_vp;
- struct vattr *a_vap;
- struct ucred *a_cred;
- struct thread *a_td;
- } */ *ap;
-{
- struct vattr *vap = ap->a_vap;
- struct vnode *vp = ap->a_vp;
- struct inode *ip = VTOI(vp);
- struct ucred *cred = ap->a_cred;
- struct thread *td = ap->a_td;
- int error;
-
- /*
- * Check for unsettable attributes.
- */
- if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
- (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
- (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
- ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
- return (EINVAL);
- }
- if (vap->va_flags != VNOVAL) {
- if (vp->v_mount->mnt_flag & MNT_RDONLY)
- return (EROFS);
- /*
- * Callers may only modify the file flags on objects they
- * have VADMIN rights for.
- */
- if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
- return (error);
- /*
- * Unprivileged processes and privileged processes in
- * jail() are not permitted to unset system flags, or
- * modify flags if any system flags are set.
- * Privileged non-jail processes may not modify system flags
- * if securelevel > 0 and any existing system flags are set.
- */
- if (!suser_cred(cred, PRISON_ROOT)) {
- if (ip->i_flags
- & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) {
- error = securelevel_gt(cred, 0);
- if (error)
- return (error);
- }
- ip->i_flags = vap->va_flags;
- } else {
- if (ip->i_flags
- & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND) ||
- (vap->va_flags & UF_SETTABLE) != vap->va_flags)
- return (EPERM);
- ip->i_flags &= SF_SETTABLE;
- ip->i_flags |= (vap->va_flags & UF_SETTABLE);
- }
- ip->i_flag |= IN_CHANGE;
- if (vap->va_flags & (IMMUTABLE | APPEND))
- return (0);
- }
- if (ip->i_flags & (IMMUTABLE | APPEND))
- return (EPERM);
- /*
- * Go through the fields and update iff not VNOVAL.
- */
- if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
- if (vp->v_mount->mnt_flag & MNT_RDONLY)
- return (EROFS);
- if ((error = ext2_chown(vp, vap->va_uid, vap->va_gid, cred,
- td)) != 0)
- return (error);
- }
- if (vap->va_size != VNOVAL) {
- /*
- * Disallow write attempts on read-only file systems;
- * unless the file is a socket, fifo, or a block or
- * character device resident on the file system.
- */
- switch (vp->v_type) {
- case VDIR:
- return (EISDIR);
- case VLNK:
- case VREG:
- if (vp->v_mount->mnt_flag & MNT_RDONLY)
- return (EROFS);
- break;
- default:
- break;
- }
- if ((error = ext2_truncate(vp, vap->va_size, 0, cred, td)) != 0)
- return (error);
- }
- if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
- if (vp->v_mount->mnt_flag & MNT_RDONLY)
- return (EROFS);
- /*
- * From utimes(2):
- * If times is NULL, ... The caller must be the owner of
- * the file, have permission to write the file, or be the
- * super-user.
- * If times is non-NULL, ... The caller must be the owner of
- * the file or be the super-user.
- */
- if ((error = VOP_ACCESS(vp, VADMIN, cred, td)) &&
- ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
- (error = VOP_ACCESS(vp, VWRITE, cred, td))))
- return (error);
- if (vap->va_atime.tv_sec != VNOVAL)
- ip->i_flag |= IN_ACCESS;
- if (vap->va_mtime.tv_sec != VNOVAL)
- ip->i_flag |= IN_CHANGE | IN_UPDATE;
- ext2_itimes(vp);
- if (vap->va_atime.tv_sec != VNOVAL) {
- ip->i_atime = vap->va_atime.tv_sec;
- ip->i_atimensec = vap->va_atime.tv_nsec;
- }
- if (vap->va_mtime.tv_sec != VNOVAL) {
- ip->i_mtime = vap->va_mtime.tv_sec;
- ip->i_mtimensec = vap->va_mtime.tv_nsec;
- }
- error = ext2_update(vp, 0);
- if (error)
- return (error);
- }
- error = 0;
- if (vap->va_mode != (mode_t)VNOVAL) {
- if (vp->v_mount->mnt_flag & MNT_RDONLY)
- return (EROFS);
- error = ext2_chmod(vp, (int)vap->va_mode, cred, td);
- }
- VN_KNOTE(vp, NOTE_ATTRIB);
- return (error);
-}
-
-/*
- * Change the mode on a file.
- * Inode must be locked before calling.
- */
-static int
-ext2_chmod(vp, mode, cred, td)
- struct vnode *vp;
- int mode;
- struct ucred *cred;
- struct thread *td;
-{
- struct inode *ip = VTOI(vp);
- int error;
-
- /*
- * To modify the permissions on a file, must possess VADMIN
- * for that file.
- */
- if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
- return (error);
- /*
- * Privileged processes may set the sticky bit on non-directories,
- * as well as set the setgid bit on a file with a group that the
- * process is not a member of.
- */
- if (suser_cred(cred, PRISON_ROOT)) {
- if (vp->v_type != VDIR && (mode & S_ISTXT))
- return (EFTYPE);
- if (!groupmember(ip->i_gid, cred) && (mode & ISGID))
- return (EPERM);
- }
- ip->i_mode &= ~ALLPERMS;
- ip->i_mode |= (mode & ALLPERMS);
- ip->i_flag |= IN_CHANGE;
- return (0);
-}
-
-/*
- * Perform chown operation on inode ip;
- * inode must be locked prior to call.
- */
-static int
-ext2_chown(vp, uid, gid, cred, td)
- struct vnode *vp;
- uid_t uid;
- gid_t gid;
- struct ucred *cred;
- struct thread *td;
-{
- struct inode *ip = VTOI(vp);
- uid_t ouid;
- gid_t ogid;
- int error = 0;
-
- if (uid == (uid_t)VNOVAL)
- uid = ip->i_uid;
- if (gid == (gid_t)VNOVAL)
- gid = ip->i_gid;
- /*
- * To modify the ownership of a file, must possess VADMIN
- * for that file.
- */
- if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
- return (error);
- /*
- * To change the owner of a file, or change the group of a file
- * to a group of which we are not a member, the caller must
- * have privilege.
- */
- if ((uid != ip->i_uid ||
- (gid != ip->i_gid && !groupmember(gid, cred))) &&
- (error = suser_cred(cred, PRISON_ROOT)))
- return (error);
- ogid = ip->i_gid;
- ouid = ip->i_uid;
- ip->i_gid = gid;
- ip->i_uid = uid;
- ip->i_flag |= IN_CHANGE;
- if (suser_cred(cred, PRISON_ROOT) && (ouid != uid || ogid != gid))
- ip->i_mode &= ~(ISUID | ISGID);
- return (0);
-}
-
-/*
- * Synch an open file.
- */
-/* ARGSUSED */
-static int
-ext2_fsync(ap)
- struct vop_fsync_args /* {
- struct vnode *a_vp;
- struct ucred *a_cred;
- int a_waitfor;
- struct thread *a_td;
- } */ *ap;
-{
- /*
- * Flush all dirty buffers associated with a vnode.
- */
- ext2_discard_prealloc(VTOI(ap->a_vp));
-
- vop_stdfsync(ap);
-
- return (ext2_update(ap->a_vp, ap->a_waitfor == MNT_WAIT));
-}
-
-/*
- * Mknod vnode call
- */
-/* ARGSUSED */
-static int
-ext2_mknod(ap)
- struct vop_mknod_args /* {
- struct vnode *a_dvp;
- struct vnode **a_vpp;
- struct componentname *a_cnp;
- struct vattr *a_vap;
- } */ *ap;
-{
- struct vattr *vap = ap->a_vap;
- struct vnode **vpp = ap->a_vpp;
- struct inode *ip;
- ino_t ino;
- int error;
-
- error = ext2_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
- ap->a_dvp, vpp, ap->a_cnp);
- if (error)
- return (error);
- ip = VTOI(*vpp);
- ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
- if (vap->va_rdev != VNOVAL) {
- /*
- * Want to be able to use this to make badblock
- * inodes, so don't truncate the dev number.
- */
- ip->i_rdev = vap->va_rdev;
- }
- /*
- * Remove inode, then reload it through VFS_VGET so it is
- * checked to see if it is an alias of an existing entry in
- * the inode cache.
- */
- vput(*vpp);
- (*vpp)->v_type = VNON;
- ino = ip->i_number; /* Save this before vgone() invalidates ip. */
- vgone(*vpp);
- error = VFS_VGET(ap->a_dvp->v_mount, ino, LK_EXCLUSIVE, vpp);
- if (error) {
- *vpp = NULL;
- return (error);
- }
- return (0);
-}
-
-static int
-ext2_remove(ap)
- struct vop_remove_args /* {
- struct vnode *a_dvp;
- struct vnode *a_vp;
- struct componentname *a_cnp;
- } */ *ap;
-{
- struct inode *ip;
- struct vnode *vp = ap->a_vp;
- struct vnode *dvp = ap->a_dvp;
- int error;
-
- ip = VTOI(vp);
- if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
- (VTOI(dvp)->i_flags & APPEND)) {
- error = EPERM;
- goto out;
- }
- error = ext2_dirremove(dvp, ap->a_cnp);
- if (error == 0) {
- ip->i_nlink--;
- ip->i_flag |= IN_CHANGE;
- }
-out:
- return (error);
-}
-
-/*
- * link vnode call
- */
-static int
-ext2_link(ap)
- struct vop_link_args /* {
- struct vnode *a_tdvp;
- struct vnode *a_vp;
- struct componentname *a_cnp;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct vnode *tdvp = ap->a_tdvp;
- struct componentname *cnp = ap->a_cnp;
- struct inode *ip;
- int error;
-
-#ifdef DIAGNOSTIC
- if ((cnp->cn_flags & HASBUF) == 0)
- panic("ext2_link: no name");
-#endif
- if (tdvp->v_mount != vp->v_mount) {
- error = EXDEV;
- goto out;
- }
- ip = VTOI(vp);
- if ((nlink_t)ip->i_nlink >= LINK_MAX) {
- error = EMLINK;
- goto out;
- }
- if (ip->i_flags & (IMMUTABLE | APPEND)) {
- error = EPERM;
- goto out;
- }
- ip->i_nlink++;
- ip->i_flag |= IN_CHANGE;
- error = ext2_update(vp, 1);
- if (!error)
- error = ext2_direnter(ip, tdvp, cnp);
- if (error) {
- ip->i_nlink--;
- ip->i_flag |= IN_CHANGE;
- }
-out:
- return (error);
-}
-
-/*
- * Rename system call.
- * See comments in sys/ufs/ufs/ufs_vnops.c
- */
-static int
-ext2_rename(ap)
- struct vop_rename_args /* {
- struct vnode *a_fdvp;
- struct vnode *a_fvp;
- struct componentname *a_fcnp;
- struct vnode *a_tdvp;
- struct vnode *a_tvp;
- struct componentname *a_tcnp;
- } */ *ap;
-{
- struct vnode *tvp = ap->a_tvp;
- struct vnode *tdvp = ap->a_tdvp;
- struct vnode *fvp = ap->a_fvp;
- struct vnode *fdvp = ap->a_fdvp;
- struct componentname *tcnp = ap->a_tcnp;
- struct componentname *fcnp = ap->a_fcnp;
- struct thread *td = fcnp->cn_thread;
- struct inode *ip, *xp, *dp;
- struct dirtemplate dirbuf;
- int doingdirectory = 0, oldparent = 0, newparent = 0;
- int error = 0;
- u_char namlen;
-
-#ifdef DIAGNOSTIC
- if ((tcnp->cn_flags & HASBUF) == 0 ||
- (fcnp->cn_flags & HASBUF) == 0)
- panic("ext2_rename: no name");
-#endif
- /*
- * Check for cross-device rename.
- */
- if ((fvp->v_mount != tdvp->v_mount) ||
- (tvp && (fvp->v_mount != tvp->v_mount))) {
- error = EXDEV;
-abortit:
- if (tdvp == tvp)
- vrele(tdvp);
- else
- vput(tdvp);
- if (tvp)
- vput(tvp);
- vrele(fdvp);
- vrele(fvp);
- return (error);
- }
-
- if (tvp && ((VTOI(tvp)->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
- (VTOI(tdvp)->i_flags & APPEND))) {
- error = EPERM;
- goto abortit;
- }
-
- /*
- * Renaming a file to itself has no effect. The upper layers should
- * not call us in that case. Temporarily just warn if they do.
- */
- if (fvp == tvp) {
- printf("ext2_rename: fvp == tvp (can't happen)\n");
- error = 0;
- goto abortit;
- }
-
- if ((error = vn_lock(fvp, LK_EXCLUSIVE, td)) != 0)
- goto abortit;
- dp = VTOI(fdvp);
- ip = VTOI(fvp);
- if (ip->i_nlink >= LINK_MAX) {
- VOP_UNLOCK(fvp, 0, td);
- error = EMLINK;
- goto abortit;
- }
- if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))
- || (dp->i_flags & APPEND)) {
- VOP_UNLOCK(fvp, 0, td);
- error = EPERM;
- goto abortit;
- }
- if ((ip->i_mode & IFMT) == IFDIR) {
- /*
- * Avoid ".", "..", and aliases of "." for obvious reasons.
- */
- if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
- dp == ip || (fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT ||
- (ip->i_flag & IN_RENAME)) {
- VOP_UNLOCK(fvp, 0, td);
- error = EINVAL;
- goto abortit;
- }
- ip->i_flag |= IN_RENAME;
- oldparent = dp->i_number;
- doingdirectory++;
- }
- vrele(fdvp);
-
- /*
- * When the target exists, both the directory
- * and target vnodes are returned locked.
- */
- dp = VTOI(tdvp);
- xp = NULL;
- if (tvp)
- xp = VTOI(tvp);
-
- /*
- * 1) Bump link count while we're moving stuff
- * around. If we crash somewhere before
- * completing our work, the link count
- * may be wrong, but correctable.
- */
- ip->i_nlink++;
- ip->i_flag |= IN_CHANGE;
- if ((error = ext2_update(fvp, 1)) != 0) {
- VOP_UNLOCK(fvp, 0, td);
- goto bad;
- }
-
- /*
- * If ".." must be changed (ie the directory gets a new
- * parent) then the source directory must not be in the
- * directory heirarchy above the target, as this would
- * orphan everything below the source directory. Also
- * the user must have write permission in the source so
- * as to be able to change "..". We must repeat the call
- * to namei, as the parent directory is unlocked by the
- * call to checkpath().
- */
- error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread);
- VOP_UNLOCK(fvp, 0, td);
- if (oldparent != dp->i_number)
- newparent = dp->i_number;
- if (doingdirectory && newparent) {
- if (error) /* write access check above */
- goto bad;
- if (xp != NULL)
- vput(tvp);
- error = ext2_checkpath(ip, dp, tcnp->cn_cred);
- if (error)
- goto out;
- VREF(tdvp);
- error = relookup(tdvp, &tvp, tcnp);
- if (error)
- goto out;
- vrele(tdvp);
- dp = VTOI(tdvp);
- xp = NULL;
- if (tvp)
- xp = VTOI(tvp);
- }
- /*
- * 2) If target doesn't exist, link the target
- * to the source and unlink the source.
- * Otherwise, rewrite the target directory
- * entry to reference the source inode and
- * expunge the original entry's existence.
- */
- if (xp == NULL) {
- if (dp->i_dev != ip->i_dev)
- panic("ext2_rename: EXDEV");
- /*
- * Account for ".." in new directory.
- * When source and destination have the same
- * parent we don't fool with the link count.
- */
- if (doingdirectory && newparent) {
- if ((nlink_t)dp->i_nlink >= LINK_MAX) {
- error = EMLINK;
- goto bad;
- }
- dp->i_nlink++;
- dp->i_flag |= IN_CHANGE;
- error = ext2_update(tdvp, 1);
- if (error)
- goto bad;
- }
- error = ext2_direnter(ip, tdvp, tcnp);
- if (error) {
- if (doingdirectory && newparent) {
- dp->i_nlink--;
- dp->i_flag |= IN_CHANGE;
- (void)ext2_update(tdvp, 1);
- }
- goto bad;
- }
- vput(tdvp);
- } else {
- if (xp->i_dev != dp->i_dev || xp->i_dev != ip->i_dev)
- panic("ext2_rename: EXDEV");
- /*
- * Short circuit rename(foo, foo).
- */
- if (xp->i_number == ip->i_number)
- panic("ext2_rename: same file");
- /*
- * If the parent directory is "sticky", then the user must
- * own the parent directory, or the destination of the rename,
- * otherwise the destination may not be changed (except by
- * root). This implements append-only directories.
- */
- if ((dp->i_mode & S_ISTXT) && tcnp->cn_cred->cr_uid != 0 &&
- tcnp->cn_cred->cr_uid != dp->i_uid &&
- xp->i_uid != tcnp->cn_cred->cr_uid) {
- error = EPERM;
- goto bad;
- }
- /*
- * Target must be empty if a directory and have no links
- * to it. Also, ensure source and target are compatible
- * (both directories, or both not directories).
- */
- if ((xp->i_mode&IFMT) == IFDIR) {
- if (! ext2_dirempty(xp, dp->i_number, tcnp->cn_cred) ||
- xp->i_nlink > 2) {
- error = ENOTEMPTY;
- goto bad;
- }
- if (!doingdirectory) {
- error = ENOTDIR;
- goto bad;
- }
- cache_purge(tdvp);
- } else if (doingdirectory) {
- error = EISDIR;
- goto bad;
- }
- error = ext2_dirrewrite(dp, ip, tcnp);
- if (error)
- goto bad;
- /*
- * If the target directory is in the same
- * directory as the source directory,
- * decrement the link count on the parent
- * of the target directory.
- */
- if (doingdirectory && !newparent) {
- dp->i_nlink--;
- dp->i_flag |= IN_CHANGE;
- }
- vput(tdvp);
- /*
- * Adjust the link count of the target to
- * reflect the dirrewrite above. If this is
- * a directory it is empty and there are
- * no links to it, so we can squash the inode and
- * any space associated with it. We disallowed
- * renaming over top of a directory with links to
- * it above, as the remaining link would point to
- * a directory without "." or ".." entries.
- */
- xp->i_nlink--;
- if (doingdirectory) {
- if (--xp->i_nlink != 0)
- panic("ext2_rename: linked directory");
- error = ext2_truncate(tvp, (off_t)0, IO_SYNC,
- tcnp->cn_cred, tcnp->cn_thread);
- }
- xp->i_flag |= IN_CHANGE;
- vput(tvp);
- xp = NULL;
- }
-
- /*
- * 3) Unlink the source.
- */
- fcnp->cn_flags &= ~MODMASK;
- fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
- VREF(fdvp);
- error = relookup(fdvp, &fvp, fcnp);
- if (error == 0)
- vrele(fdvp);
- if (fvp != NULL) {
- xp = VTOI(fvp);
- dp = VTOI(fdvp);
- } else {
- /*
- * From name has disappeared.
- */
- if (doingdirectory)
- panic("ext2_rename: lost dir entry");
- vrele(ap->a_fvp);
- return (0);
- }
- /*
- * Ensure that the directory entry still exists and has not
- * changed while the new name has been entered. If the source is
- * a file then the entry may have been unlinked or renamed. In
- * either case there is no further work to be done. If the source
- * is a directory then it cannot have been rmdir'ed; its link
- * count of three would cause a rmdir to fail with ENOTEMPTY.
- * The IN_RENAME flag ensures that it cannot be moved by another
- * rename.
- */
- if (xp != ip) {
- if (doingdirectory)
- panic("ext2_rename: lost dir entry");
- } else {
- /*
- * If the source is a directory with a
- * new parent, the link count of the old
- * parent directory must be decremented
- * and ".." set to point to the new parent.
- */
- if (doingdirectory && newparent) {
- dp->i_nlink--;
- dp->i_flag |= IN_CHANGE;
- error = vn_rdwr(UIO_READ, fvp, (caddr_t)&dirbuf,
- sizeof (struct dirtemplate), (off_t)0,
- UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK,
- tcnp->cn_cred, NOCRED, (int *)0,
- (struct thread *)0);
- if (error == 0) {
- /* Like ufs little-endian: */
- namlen = dirbuf.dotdot_type;
- if (namlen != 2 ||
- dirbuf.dotdot_name[0] != '.' ||
- dirbuf.dotdot_name[1] != '.') {
- ext2_dirbad(xp, (doff_t)12,
- "rename: mangled dir");
- } else {
- dirbuf.dotdot_ino = newparent;
- (void) vn_rdwr(UIO_WRITE, fvp,
- (caddr_t)&dirbuf,
- sizeof (struct dirtemplate),
- (off_t)0, UIO_SYSSPACE,
- IO_NODELOCKED | IO_SYNC |
- IO_NOMACCHECK, tcnp->cn_cred,
- NOCRED, (int *)0,
- (struct thread *)0);
- cache_purge(fdvp);
- }
- }
- }
- error = ext2_dirremove(fdvp, fcnp);
- if (!error) {
- xp->i_nlink--;
- xp->i_flag |= IN_CHANGE;
- }
- xp->i_flag &= ~IN_RENAME;
- }
- if (dp)
- vput(fdvp);
- if (xp)
- vput(fvp);
- vrele(ap->a_fvp);
- return (error);
-
-bad:
- if (xp)
- vput(ITOV(xp));
- vput(ITOV(dp));
-out:
- if (doingdirectory)
- ip->i_flag &= ~IN_RENAME;
- if (vn_lock(fvp, LK_EXCLUSIVE, td) == 0) {
- ip->i_nlink--;
- ip->i_flag |= IN_CHANGE;
- ip->i_flag &= ~IN_RENAME;
- vput(fvp);
- } else
- vrele(fvp);
- return (error);
-}
-
-/*
- * Mkdir system call
- */
-static int
-ext2_mkdir(ap)
- struct vop_mkdir_args /* {
- struct vnode *a_dvp;
- struct vnode **a_vpp;
- struct componentname *a_cnp;
- struct vattr *a_vap;
- } */ *ap;
-{
- struct vnode *dvp = ap->a_dvp;
- struct vattr *vap = ap->a_vap;
- struct componentname *cnp = ap->a_cnp;
- struct inode *ip, *dp;
- struct vnode *tvp;
- struct dirtemplate dirtemplate, *dtp;
- int error, dmode;
-
-#ifdef DIAGNOSTIC
- if ((cnp->cn_flags & HASBUF) == 0)
- panic("ext2_mkdir: no name");
-#endif
- dp = VTOI(dvp);
- if ((nlink_t)dp->i_nlink >= LINK_MAX) {
- error = EMLINK;
- goto out;
- }
- dmode = vap->va_mode & 0777;
- dmode |= IFDIR;
- /*
- * Must simulate part of ext2_makeinode here to acquire the inode,
- * but not have it entered in the parent directory. The entry is
- * made later after writing "." and ".." entries.
- */
- error = ext2_valloc(dvp, dmode, cnp->cn_cred, &tvp);
- if (error)
- goto out;
- ip = VTOI(tvp);
- ip->i_gid = dp->i_gid;
-#ifdef SUIDDIR
- {
- /*
- * if we are hacking owners here, (only do this where told to)
- * and we are not giving it TOO root, (would subvert quotas)
- * then go ahead and give it to the other user.
- * The new directory also inherits the SUID bit.
- * If user's UID and dir UID are the same,
- * 'give it away' so that the SUID is still forced on.
- */
- if ( (dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
- (dp->i_mode & ISUID) && dp->i_uid) {
- dmode |= ISUID;
- ip->i_uid = dp->i_uid;
- } else {
- ip->i_uid = cnp->cn_cred->cr_uid;
- }
- }
-#else
- ip->i_uid = cnp->cn_cred->cr_uid;
-#endif
- ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
- ip->i_mode = dmode;
- tvp->v_type = VDIR; /* Rest init'd in getnewvnode(). */
- ip->i_nlink = 2;
- if (cnp->cn_flags & ISWHITEOUT)
- ip->i_flags |= UF_OPAQUE;
- error = ext2_update(tvp, 1);
-
- /*
- * Bump link count in parent directory
- * to reflect work done below. Should
- * be done before reference is created
- * so reparation is possible if we crash.
- */
- dp->i_nlink++;
- dp->i_flag |= IN_CHANGE;
- error = ext2_update(dvp, 1);
- if (error)
- goto bad;
-
- /* Initialize directory with "." and ".." from static template. */
- if (EXT2_HAS_INCOMPAT_FEATURE(ip->i_e2fs->s_es,
- EXT2_FEATURE_INCOMPAT_FILETYPE))
- dtp = &mastertemplate;
- else
- dtp = &omastertemplate;
- dirtemplate = *dtp;
- dirtemplate.dot_ino = ip->i_number;
- dirtemplate.dotdot_ino = dp->i_number;
- /* note that in ext2 DIRBLKSIZ == blocksize, not DEV_BSIZE
- * so let's just redefine it - for this function only
- */
-#undef DIRBLKSIZ
-#define DIRBLKSIZ VTOI(dvp)->i_e2fs->s_blocksize
- dirtemplate.dotdot_reclen = DIRBLKSIZ - 12;
- error = vn_rdwr(UIO_WRITE, tvp, (caddr_t)&dirtemplate,
- sizeof (dirtemplate), (off_t)0, UIO_SYSSPACE,
- IO_NODELOCKED | IO_SYNC | IO_NOMACCHECK, cnp->cn_cred, NOCRED,
- (int *)0, (struct thread *)0);
- if (error) {
- dp->i_nlink--;
- dp->i_flag |= IN_CHANGE;
- goto bad;
- }
- if (DIRBLKSIZ > VFSTOEXT2(dvp->v_mount)->um_mountp->mnt_stat.f_bsize)
- /* XXX should grow with balloc() */
- panic("ext2_mkdir: blksize");
- else {
- ip->i_size = DIRBLKSIZ;
- ip->i_flag |= IN_CHANGE;
- }
-
- /* Directory set up, now install its entry in the parent directory. */
- error = ext2_direnter(ip, dvp, cnp);
- if (error) {
- dp->i_nlink--;
- dp->i_flag |= IN_CHANGE;
- }
-bad:
- /*
- * No need to do an explicit VOP_TRUNCATE here, vrele will do this
- * for us because we set the link count to 0.
- */
- if (error) {
- ip->i_nlink = 0;
- ip->i_flag |= IN_CHANGE;
- vput(tvp);
- } else
- *ap->a_vpp = tvp;
-out:
- return (error);
-#undef DIRBLKSIZ
-#define DIRBLKSIZ DEV_BSIZE
-}
-
-/*
- * Rmdir system call.
- */
-static int
-ext2_rmdir(ap)
- struct vop_rmdir_args /* {
- struct vnode *a_dvp;
- struct vnode *a_vp;
- struct componentname *a_cnp;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct vnode *dvp = ap->a_dvp;
- struct componentname *cnp = ap->a_cnp;
- struct thread *td = cnp->cn_thread;
- struct inode *ip, *dp;
- int error;
-
- ip = VTOI(vp);
- dp = VTOI(dvp);
-
- /*
- * Verify the directory is empty (and valid).
- * (Rmdir ".." won't be valid since
- * ".." will contain a reference to
- * the current directory and thus be
- * non-empty.)
- */
- error = 0;
- if (ip->i_nlink != 2 || !ext2_dirempty(ip, dp->i_number, cnp->cn_cred)) {
- error = ENOTEMPTY;
- goto out;
- }
- if ((dp->i_flags & APPEND)
- || (ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
- error = EPERM;
- goto out;
- }
- /*
- * Delete reference to directory before purging
- * inode. If we crash in between, the directory
- * will be reattached to lost+found,
- */
- error = ext2_dirremove(dvp, cnp);
- if (error)
- goto out;
- dp->i_nlink--;
- dp->i_flag |= IN_CHANGE;
- cache_purge(dvp);
- VOP_UNLOCK(dvp, 0, td);
- /*
- * Truncate inode. The only stuff left
- * in the directory is "." and "..". The
- * "." reference is inconsequential since
- * we're quashing it. The ".." reference
- * has already been adjusted above. We've
- * removed the "." reference and the reference
- * in the parent directory, but there may be
- * other hard links so decrement by 2 and
- * worry about them later.
- */
- ip->i_nlink -= 2;
- error = ext2_truncate(vp, (off_t)0, IO_SYNC, cnp->cn_cred, td);
- cache_purge(ITOV(ip));
- vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
-out:
- return (error);
-}
-
-/*
- * symlink -- make a symbolic link
- */
-static int
-ext2_symlink(ap)
- struct vop_symlink_args /* {
- struct vnode *a_dvp;
- struct vnode **a_vpp;
- struct componentname *a_cnp;
- struct vattr *a_vap;
- char *a_target;
- } */ *ap;
-{
- struct vnode *vp, **vpp = ap->a_vpp;
- struct inode *ip;
- int len, error;
-
- error = ext2_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp,
- vpp, ap->a_cnp);
- if (error)
- return (error);
- vp = *vpp;
- len = strlen(ap->a_target);
- if (len < vp->v_mount->mnt_maxsymlinklen) {
- ip = VTOI(vp);
- bcopy(ap->a_target, (char *)ip->i_shortlink, len);
- ip->i_size = len;
- ip->i_flag |= IN_CHANGE | IN_UPDATE;
- } else
- error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
- UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK,
- ap->a_cnp->cn_cred, NOCRED, (int *)0, (struct thread *)0);
- if (error)
- vput(vp);
- return (error);
-}
-
-/*
- * Return target name of a symbolic link
- */
-static int
-ext2_readlink(ap)
- struct vop_readlink_args /* {
- struct vnode *a_vp;
- struct uio *a_uio;
- struct ucred *a_cred;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct inode *ip = VTOI(vp);
- int isize;
-
- isize = ip->i_size;
- if (isize < vp->v_mount->mnt_maxsymlinklen) {
- uiomove((char *)ip->i_shortlink, isize, ap->a_uio);
- return (0);
- }
- return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
-}
-
-/*
- * Calculate the logical to physical mapping if not done already,
- * then call the device strategy routine.
- *
- * In order to be able to swap to a file, the ext2_bmaparray() operation may not
- * deadlock on memory. See ext2_bmap() for details.
- */
-static int
-ext2_strategy(ap)
- struct vop_strategy_args /* {
- struct vnode *a_vp;
- struct buf *a_bp;
- } */ *ap;
-{
- struct buf *bp = ap->a_bp;
- struct vnode *vp = ap->a_vp;
- struct inode *ip;
- int32_t blkno;
- int error;
-
- ip = VTOI(vp);
- if (vp->v_type == VBLK || vp->v_type == VCHR)
- panic("ext2_strategy: spec");
- if (bp->b_blkno == bp->b_lblkno) {
- error = ext2_bmaparray(vp, bp->b_lblkno, &blkno, NULL, NULL);
- bp->b_blkno = blkno;
- if (error) {
- bp->b_error = error;
- bp->b_ioflags |= BIO_ERROR;
- bufdone(bp);
- return (error);
- }
- if ((long)bp->b_blkno == -1)
- vfs_bio_clrbuf(bp);
- }
- if ((long)bp->b_blkno == -1) {
- bufdone(bp);
- return (0);
- }
- vp = ip->i_devvp;
- bp->b_dev = vp->v_rdev;
- VOP_SPECSTRATEGY(vp, bp);
- return (0);
-}
-
-/*
- * Print out the contents of an inode.
- */
-static int
-ext2_print(ap)
- struct vop_print_args /* {
- struct vnode *a_vp;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct inode *ip = VTOI(vp);
-
- printf("\tino %lu, on dev %s (%d, %d)", (u_long)ip->i_number,
- devtoname(ip->i_dev), major(ip->i_dev), minor(ip->i_dev));
- if (vp->v_type == VFIFO)
- fifo_printinfo(vp);
- printf("\n");
- return (0);
-}
-
-/*
- * Read wrapper for special devices.
- */
-static int
-ext2spec_read(ap)
- struct vop_read_args /* {
- struct vnode *a_vp;
- struct uio *a_uio;
- int a_ioflag;
- struct ucred *a_cred;
- } */ *ap;
-{
- int error, resid;
- struct inode *ip;
- struct uio *uio;
-
- uio = ap->a_uio;
- resid = uio->uio_resid;
- error = VOCALL(spec_vnodeop_p, VOFFSET(vop_read), ap);
- /*
- * The inode may have been revoked during the call, so it must not
- * be accessed blindly here or in the other wrapper functions.
- */
- ip = VTOI(ap->a_vp);
- if (ip != NULL && (uio->uio_resid != resid || (error == 0 && resid != 0)))
- ip->i_flag |= IN_ACCESS;
- return (error);
-}
-
-/*
- * Write wrapper for special devices.
- */
-static int
-ext2spec_write(ap)
- struct vop_write_args /* {
- struct vnode *a_vp;
- struct uio *a_uio;
- int a_ioflag;
- struct ucred *a_cred;
- } */ *ap;
-{
- int error, resid;
- struct inode *ip;
- struct uio *uio;
-
- uio = ap->a_uio;
- resid = uio->uio_resid;
- error = VOCALL(spec_vnodeop_p, VOFFSET(vop_write), ap);
- ip = VTOI(ap->a_vp);
- if (ip != NULL && (uio->uio_resid != resid || (error == 0 && resid != 0)))
- VTOI(ap->a_vp)->i_flag |= IN_CHANGE | IN_UPDATE;
- return (error);
-}
-
-/*
- * Close wrapper for special devices.
- *
- * Update the times on the inode then do device close.
- */
-static int
-ext2spec_close(ap)
- struct vop_close_args /* {
- struct vnode *a_vp;
- int a_fflag;
- struct ucred *a_cred;
- struct thread *a_td;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
-
- VI_LOCK(vp);
- if (vp->v_usecount > 1)
- ext2_itimes(vp);
- VI_UNLOCK(vp);
- return (VOCALL(spec_vnodeop_p, VOFFSET(vop_close), ap));
-}
-
-/*
- * Read wrapper for fifos.
- */
-static int
-ext2fifo_read(ap)
- struct vop_read_args /* {
- struct vnode *a_vp;
- struct uio *a_uio;
- int a_ioflag;
- struct ucred *a_cred;
- } */ *ap;
-{
- int error, resid;
- struct inode *ip;
- struct uio *uio;
-
- uio = ap->a_uio;
- resid = uio->uio_resid;
- error = VOCALL(fifo_vnodeop_p, VOFFSET(vop_read), ap);
- ip = VTOI(ap->a_vp);
- if ((ap->a_vp->v_mount->mnt_flag & MNT_NOATIME) == 0 && ip != NULL &&
- (uio->uio_resid != resid || (error == 0 && resid != 0)))
- VTOI(ap->a_vp)->i_flag |= IN_ACCESS;
- return (error);
-}
-
-/*
- * Write wrapper for fifos.
- */
-static int
-ext2fifo_write(ap)
- struct vop_write_args /* {
- struct vnode *a_vp;
- struct uio *a_uio;
- int a_ioflag;
- struct ucred *a_cred;
- } */ *ap;
-{
- int error, resid;
- struct inode *ip;
- struct uio *uio;
-
- uio = ap->a_uio;
- resid = uio->uio_resid;
- error = VOCALL(fifo_vnodeop_p, VOFFSET(vop_write), ap);
- ip = VTOI(ap->a_vp);
- if (ip != NULL && (uio->uio_resid != resid || (error == 0 && resid != 0)))
- VTOI(ap->a_vp)->i_flag |= IN_CHANGE | IN_UPDATE;
- return (error);
-}
-
-/*
- * Close wrapper for fifos.
- *
- * Update the times on the inode then do device close.
- */
-static int
-ext2fifo_close(ap)
- struct vop_close_args /* {
- struct vnode *a_vp;
- int a_fflag;
- struct ucred *a_cred;
- struct thread *a_td;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
-
- VI_LOCK(vp);
- if (vp->v_usecount > 1)
- ext2_itimes(vp);
- VI_UNLOCK(vp);
- return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_close), ap));
-}
-
-/*
- * Kqfilter wrapper for fifos.
- *
- * Fall through to ext2 kqfilter routines if needed
- */
-static int
-ext2fifo_kqfilter(ap)
- struct vop_kqfilter_args *ap;
-{
- int error;
-
- error = VOCALL(fifo_vnodeop_p, VOFFSET(vop_kqfilter), ap);
- if (error)
- error = ext2_kqfilter(ap);
- return (error);
-}
-
-/*
- * Return POSIX pathconf information applicable to ext2 filesystems.
- */
-static int
-ext2_pathconf(ap)
- struct vop_pathconf_args /* {
- struct vnode *a_vp;
- int a_name;
- int *a_retval;
- } */ *ap;
-{
-
- switch (ap->a_name) {
- case _PC_LINK_MAX:
- *ap->a_retval = LINK_MAX;
- return (0);
- case _PC_NAME_MAX:
- *ap->a_retval = NAME_MAX;
- return (0);
- case _PC_PATH_MAX:
- *ap->a_retval = PATH_MAX;
- return (0);
- case _PC_PIPE_BUF:
- *ap->a_retval = PIPE_BUF;
- return (0);
- case _PC_CHOWN_RESTRICTED:
- *ap->a_retval = 1;
- return (0);
- case _PC_NO_TRUNC:
- *ap->a_retval = 1;
- return (0);
- default:
- return (EINVAL);
- }
- /* NOTREACHED */
-}
-
-/*
- * Advisory record locking support
- */
-static int
-ext2_advlock(ap)
- struct vop_advlock_args /* {
- struct vnode *a_vp;
- caddr_t a_id;
- int a_op;
- struct flock *a_fl;
- int a_flags;
- } */ *ap;
-{
- struct inode *ip = VTOI(ap->a_vp);
-
- return (lf_advlock(ap, &(ip->i_lockf), ip->i_size));
-}
-
-/*
- * Initialize the vnode associated with a new inode, handle aliased
- * vnodes.
- */
-int
-ext2_vinit(mntp, specops, fifoops, vpp)
- struct mount *mntp;
- vop_t **specops;
- vop_t **fifoops;
- struct vnode **vpp;
-{
- struct inode *ip;
- struct vnode *vp;
- struct timeval tv;
-
- vp = *vpp;
- ip = VTOI(vp);
- switch(vp->v_type = IFTOVT(ip->i_mode)) {
- case VCHR:
- case VBLK:
- vp->v_op = specops;
- vp = addaliasu(vp, ip->i_rdev);
- ip->i_vnode = vp;
- break;
- case VFIFO:
- vp->v_op = fifoops;
- break;
- default:
- break;
-
- }
- if (ip->i_number == ROOTINO)
- vp->v_vflag |= VV_ROOT;
- /*
- * Initialize modrev times
- */
- getmicrouptime(&tv);
- SETHIGH(ip->i_modrev, tv.tv_sec);
- SETLOW(ip->i_modrev, tv.tv_usec * 4294);
- *vpp = vp;
- return (0);
-}
-
-/*
- * Allocate a new inode.
- */
-static int
-ext2_makeinode(mode, dvp, vpp, cnp)
- int mode;
- struct vnode *dvp;
- struct vnode **vpp;
- struct componentname *cnp;
-{
- struct inode *ip, *pdir;
- struct vnode *tvp;
- int error;
-
- pdir = VTOI(dvp);
-#ifdef DIAGNOSTIC
- if ((cnp->cn_flags & HASBUF) == 0)
- panic("ext2_makeinode: no name");
-#endif
- *vpp = NULL;
- if ((mode & IFMT) == 0)
- mode |= IFREG;
-
- error = ext2_valloc(dvp, mode, cnp->cn_cred, &tvp);
- if (error) {
- return (error);
- }
- ip = VTOI(tvp);
- ip->i_gid = pdir->i_gid;
-#ifdef SUIDDIR
- {
- /*
- * if we are
- * not the owner of the directory,
- * and we are hacking owners here, (only do this where told to)
- * and we are not giving it TOO root, (would subvert quotas)
- * then go ahead and give it to the other user.
- * Note that this drops off the execute bits for security.
- */
- if ( (dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
- (pdir->i_mode & ISUID) &&
- (pdir->i_uid != cnp->cn_cred->cr_uid) && pdir->i_uid) {
- ip->i_uid = pdir->i_uid;
- mode &= ~07111;
- } else {
- ip->i_uid = cnp->cn_cred->cr_uid;
- }
- }
-#else
- ip->i_uid = cnp->cn_cred->cr_uid;
-#endif
- ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
- ip->i_mode = mode;
- tvp->v_type = IFTOVT(mode); /* Rest init'd in getnewvnode(). */
- ip->i_nlink = 1;
- if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, cnp->cn_cred) &&
- suser_cred(cnp->cn_cred, PRISON_ROOT))
- ip->i_mode &= ~ISGID;
-
- if (cnp->cn_flags & ISWHITEOUT)
- ip->i_flags |= UF_OPAQUE;
-
- /*
- * Make sure inode goes to disk before directory entry.
- */
- error = ext2_update(tvp, 1);
- if (error)
- goto bad;
- error = ext2_direnter(ip, dvp, cnp);
- if (error)
- goto bad;
-
- *vpp = tvp;
- return (0);
-
-bad:
- /*
- * Write error occurred trying to update the inode
- * or the directory so must deallocate the inode.
- */
- ip->i_nlink = 0;
- ip->i_flag |= IN_CHANGE;
- vput(tvp);
- return (error);
-}
-
-static struct filterops ext2read_filtops =
- { 1, NULL, filt_ext2detach, filt_ext2read };
-static struct filterops ext2write_filtops =
- { 1, NULL, filt_ext2detach, filt_ext2write };
-static struct filterops ext2vnode_filtops =
- { 1, NULL, filt_ext2detach, filt_ext2vnode };
-
-static int
-ext2_kqfilter(ap)
- struct vop_kqfilter_args /* {
- struct vnode *a_vp;
- struct knote *a_kn;
- } */ *ap;
-{
- struct vnode *vp = ap->a_vp;
- struct knote *kn = ap->a_kn;
-
- switch (kn->kn_filter) {
- case EVFILT_READ:
- kn->kn_fop = &ext2read_filtops;
- break;
- case EVFILT_WRITE:
- kn->kn_fop = &ext2write_filtops;
- break;
- case EVFILT_VNODE:
- kn->kn_fop = &ext2vnode_filtops;
- break;
- default:
- return (1);
- }
-
- kn->kn_hook = (caddr_t)vp;
-
- if (vp->v_pollinfo == NULL)
- v_addpollinfo(vp);
- mtx_lock(&vp->v_pollinfo->vpi_lock);
- SLIST_INSERT_HEAD(&vp->v_pollinfo->vpi_selinfo.si_note, kn, kn_selnext);
- mtx_unlock(&vp->v_pollinfo->vpi_lock);
-
- return (0);
-}
-
-static void
-filt_ext2detach(struct knote *kn)
-{
- struct vnode *vp = (struct vnode *)kn->kn_hook;
-
- KASSERT(vp->v_pollinfo != NULL, ("Mising v_pollinfo"));
- mtx_lock(&vp->v_pollinfo->vpi_lock);
- SLIST_REMOVE(&vp->v_pollinfo->vpi_selinfo.si_note,
- kn, knote, kn_selnext);
- mtx_unlock(&vp->v_pollinfo->vpi_lock);
-}
-
-/*ARGSUSED*/
-static int
-filt_ext2read(struct knote *kn, long hint)
-{
- struct vnode *vp = (struct vnode *)kn->kn_hook;
- struct inode *ip = VTOI(vp);
-
- /*
- * filesystem is gone, so set the EOF flag and schedule
- * the knote for deletion.
- */
- if (hint == NOTE_REVOKE) {
- kn->kn_flags |= (EV_EOF | EV_ONESHOT);
- return (1);
- }
-
- kn->kn_data = ip->i_size - kn->kn_fp->f_offset;
- return (kn->kn_data != 0);
-}
-
-/*ARGSUSED*/
-static int
-filt_ext2write(struct knote *kn, long hint)
-{
-
- /*
- * filesystem is gone, so set the EOF flag and schedule
- * the knote for deletion.
- */
- if (hint == NOTE_REVOKE)
- kn->kn_flags |= (EV_EOF | EV_ONESHOT);
-
- kn->kn_data = 0;
- return (1);
-}
-
-static int
-filt_ext2vnode(struct knote *kn, long hint)
-{
-
- if (kn->kn_sfflags & hint)
- kn->kn_fflags |= hint;
- if (hint == NOTE_REVOKE) {
- kn->kn_flags |= EV_EOF;
- return (1);
- }
- return (kn->kn_fflags != 0);
-}
diff --git a/sys/gnu/fs/ext2fs/fs.h b/sys/gnu/fs/ext2fs/fs.h
deleted file mode 100644
index 9c0cf71a56da..000000000000
--- a/sys/gnu/fs/ext2fs/fs.h
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * modified for EXT2FS support in Lites 1.1
- *
- * Aug 1995, Godmar Back (gback@cs.utah.edu)
- * University of Utah, Department of Computer Science
- */
-/*
- * Copyright (c) 1982, 1986, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)fs.h 8.7 (Berkeley) 4/19/94
- * $FreeBSD$
- */
-
-/*
- * Each disk drive contains some number of file systems.
- * A file system consists of a number of cylinder groups.
- * Each cylinder group has inodes and data.
- *
- * A file system is described by its super-block, which in turn
- * describes the cylinder groups. The super-block is critical
- * data and is replicated in each cylinder group to protect against
- * catastrophic loss. This is done at `newfs' time and the critical
- * super-block data does not change, so the copies need not be
- * referenced further unless disaster strikes.
- *
- * The first boot and super blocks are given in absolute disk addresses.
- * The byte-offset forms are preferred, as they don't imply a sector size.
- */
-#define SBSIZE 1024
-#define SBLOCK 2
-
-/*
- * The path name on which the file system is mounted is maintained
- * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
- * the super block for this name.
- */
-#define MAXMNTLEN 512
-
-/*
- * Macros for access to superblock array structures
- */
-
-/*
- * Convert cylinder group to base address of its global summary info.
- */
-#define fs_cs(fs, cgindx) (((struct ext2_group_desc *) \
- (fs->s_group_desc[cgindx / EXT2_DESC_PER_BLOCK(fs)]->b_data)) \
- [cgindx % EXT2_DESC_PER_BLOCK(fs)])
-
-/*
- * Turn file system block numbers into disk block addresses.
- * This maps file system blocks to device size blocks.
- */
-#define fsbtodb(fs, b) ((b) << ((fs)->s_fsbtodb))
-#define dbtofsb(fs, b) ((b) >> ((fs)->s_fsbtodb))
-
-/* get group containing inode */
-#define ino_to_cg(fs, x) (((x) - 1) / EXT2_INODES_PER_GROUP(fs))
-
-/* get block containing inode from its number x */
-#define ino_to_fsba(fs, x) fs_cs(fs, ino_to_cg(fs, x)).bg_inode_table + \
- (((x)-1) % EXT2_INODES_PER_GROUP(fs))/EXT2_INODES_PER_BLOCK(fs)
-
-/* get offset for inode in block */
-#define ino_to_fsbo(fs, x) ((x-1) % EXT2_INODES_PER_BLOCK(fs))
-
-/*
- * Give cylinder group number for a file system block.
- * Give cylinder group block number for a file system block.
- */
-#define dtog(fs, d) (((d) - fs->s_es->s_first_data_block) / \
- EXT2_BLOCKS_PER_GROUP(fs))
-#define dtogd(fs, d) (((d) - fs->s_es->s_first_data_block) % \
- EXT2_BLOCKS_PER_GROUP(fs))
-
-/*
- * The following macros optimize certain frequently calculated
- * quantities by using shifts and masks in place of divisions
- * modulos and multiplications.
- */
-#define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \
- ((loc) & (fs)->s_qbmask)
-
-#define lblktosize(fs, blk) /* calculates (blk * fs->fs_bsize) */ \
- ((blk) << (fs->s_bshift))
-
-#define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \
- ((loc) >> (fs->s_bshift))
-
-/* no fragments -> logical block number equal # of frags */
-#define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \
- ((loc) >> (fs->s_bshift))
-
-#define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \
- roundup(size, fs->s_frag_size)
- /* was (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask) */
-
-/*
- * Determining the size of a file block in the file system.
- * easy w/o fragments
- */
-#define blksize(fs, ip, lbn) ((fs)->s_frag_size)
-
-/*
- * INOPB is the number of inodes in a secondary storage block.
- */
-#define INOPB(fs) EXT2_INODES_PER_BLOCK(fs)
-
-/*
- * NINDIR is the number of indirects in a file system block.
- */
-#define NINDIR(fs) (EXT2_ADDR_PER_BLOCK(fs))
-
-extern int inside[], around[];
-extern u_char *fragtbl[];
-
-/* a few remarks about superblock locking/unlocking
- * Linux provides special routines for doing so
- * I haven't figured out yet what BSD does
- * I think I'll try a VOP_LOCK/VOP_UNLOCK on the device vnode
- */
-#define DEVVP(inode) (VFSTOEXT2(ITOV(inode)->v_mount)->um_devvp)
-#define lock_super(devvp) vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, curthread)
-#define unlock_super(devvp) VOP_UNLOCK(devvp, 0, curthread)
-
-/*
- * To lock a buffer, set the B_LOCKED flag and then brelse() it. To unlock,
- * reset the B_LOCKED flag and brelse() the buffer back on the LRU list
- */
-#define LCK_BUF(bp) { \
- int s; \
- s = splbio(); \
- (bp)->b_flags |= B_LOCKED; \
- splx(s); \
- brelse(bp); \
-}
-
-#define ULCK_BUF(bp) { \
- long flags; \
- int s; \
- s = splbio(); \
- BUF_LOCK(bp, LK_EXCLUSIVE, NULL); \
- flags = (bp)->b_flags; \
- (bp)->b_flags &= ~(B_DIRTY | B_LOCKED); \
- bremfree(bp); \
- splx(s); \
- if (flags & B_DIRTY) \
- bwrite(bp); \
- else \
- brelse(bp); \
-}
diff --git a/sys/gnu/fs/ext2fs/i386-bitops.h b/sys/gnu/fs/ext2fs/i386-bitops.h
deleted file mode 100644
index 595e870526b3..000000000000
--- a/sys/gnu/fs/ext2fs/i386-bitops.h
+++ /dev/null
@@ -1,162 +0,0 @@
-/* $FreeBSD$ */
-/*
- * this is mixture of i386/bitops.h and asm/string.h
- * taken from the Linux source tree
- *
- * XXX replace with Mach routines or reprogram in C
- */
-#ifndef _SYS_GNU_EXT2FS_I386_BITOPS_H_
-#define _SYS_GNU_EXT2FS_I386_BITOPS_H_
-
-/*
- * Copyright 1992, Linus Torvalds.
- */
-
-/*
- * These have to be done with inline assembly: that way the bit-setting
- * is guaranteed to be atomic. All bit operations return 0 if the bit
- * was cleared before the operation and != 0 if it was not.
- *
- * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
- */
-
-/*
- * Some hacks to defeat gcc over-optimizations..
- */
-struct __dummy { unsigned long a[100]; };
-#define ADDR (*(struct __dummy *) addr)
-
-static __inline__ int set_bit(int nr, void * addr)
-{
- int oldbit;
-
- __asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0"
- :"=r" (oldbit),"=m" (ADDR)
- :"ir" (nr));
- return oldbit;
-}
-
-static __inline__ int clear_bit(int nr, void * addr)
-{
- int oldbit;
-
- __asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0"
- :"=r" (oldbit),"=m" (ADDR)
- :"ir" (nr));
- return oldbit;
-}
-
-static __inline__ int change_bit(int nr, void * addr)
-{
- int oldbit;
-
- __asm__ __volatile__("btcl %2,%1\n\tsbbl %0,%0"
- :"=r" (oldbit),"=m" (ADDR)
- :"ir" (nr));
- return oldbit;
-}
-
-/*
- * This routine doesn't need to be atomic, but it's faster to code it
- * this way.
- */
-static __inline__ int test_bit(int nr, void * addr)
-{
- int oldbit;
-
- __asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0"
- :"=r" (oldbit)
- :"m" (ADDR),"ir" (nr));
- return oldbit;
-}
-
-/*
- * Find-bit routines..
- */
-static __inline__ int find_first_zero_bit(void * addr, unsigned size)
-{
- int res;
- int _count = (size + 31) >> 5;
-
- if (!size)
- return 0;
- __asm__(" \n\
- cld \n\
- movl $-1,%%eax \n\
- xorl %%edx,%%edx \n\
- repe; scasl \n\
- je 1f \n\
- xorl -4(%%edi),%%eax \n\
- subl $4,%%edi \n\
- bsfl %%eax,%%edx \n\
-1: subl %%ebx,%%edi \n\
- shll $3,%%edi \n\
- addl %%edi,%%edx"
- : "=c" (_count), "=D" (addr), "=d" (res)
- : "0" (_count), "1" (addr), "b" (addr)
- : "ax");
- return res;
-}
-
-static __inline__ int find_next_zero_bit (void * addr, int size, int offset)
-{
- unsigned long * p = ((unsigned long *) addr) + (offset >> 5);
- int set = 0, bit = offset & 31, res;
-
- if (bit) {
- /*
- * Look for zero in first byte
- */
- __asm__(" \n\
- bsfl %1,%0 \n\
- jne 1f \n\
- movl $32, %0 \n\
-1: "
- : "=r" (set)
- : "r" (~(*p >> bit)));
- if (set < (32 - bit))
- return set + offset;
- set = 32 - bit;
- p++;
- }
- /*
- * No zero yet, search remaining full bytes for a zero
- */
- res = find_first_zero_bit (p, size - 32 * (p - (unsigned long *) addr));
- return (offset + set + res);
-}
-
-/*
- * ffz = Find First Zero in word. Undefined if no zero exists,
- * so code should check against ~0UL first..
- */
-static __inline__ unsigned long ffz(unsigned long word)
-{
- __asm__("bsfl %1,%0"
- :"=r" (word)
- :"r" (~word));
- return word;
-}
-
-/*
- * memscan() taken from linux asm/string.h
- */
-/*
- * find the first occurrence of byte 'c', or 1 past the area if none
- */
-static __inline__ char * memscan(void * addr, unsigned char c, int size)
-{
- if (!size)
- return addr;
- __asm__(" \n\
- cld \n\
- repnz; scasb \n\
- jnz 1f \n\
- dec %%edi \n\
-1: "
- : "=D" (addr), "=c" (size)
- : "0" (addr), "1" (size), "a" (c));
- return addr;
-}
-
-#endif /* !_SYS_GNU_EXT2FS_I386_BITOPS_H_ */
diff --git a/sys/gnu/fs/ext2fs/inode.h b/sys/gnu/fs/ext2fs/inode.h
deleted file mode 100644
index 47046198e8bd..000000000000
--- a/sys/gnu/fs/ext2fs/inode.h
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright (c) 1982, 1989, 1993
- * The Regents of the University of California. All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)inode.h 8.9 (Berkeley) 5/14/95
- * $FreeBSD$
- */
-
-#ifndef _SYS_GNU_EXT2FS_INODE_H_
-#define _SYS_GNU_EXT2FS_INODE_H_
-
-#include <sys/lock.h>
-#include <sys/queue.h>
-
-#define ROOTINO ((ino_t)2)
-
-#define NDADDR 12 /* Direct addresses in inode. */
-#define NIADDR 3 /* Indirect addresses in inode. */
-
-/*
- * This must agree with the definition in <ufs/ufs/dir.h>.
- */
-#define doff_t int32_t
-
-/*
- * The inode is used to describe each active (or recently active) file in the
- * EXT2FS filesystem. It is composed of two types of information. The first
- * part is the information that is needed only while the file is active (such
- * as the identity of the file and linkage to speed its lookup). The second
- * part is the permanent meta-data associated with the file which is read in
- * from the permanent dinode from long term storage when the file becomes
- * active, and is put back when the file is no longer being used.
- */
-struct inode {
- LIST_ENTRY(inode) i_hash;/* Hash chain. */
- struct vnode *i_vnode;/* Vnode associated with this inode. */
- struct vnode *i_devvp;/* Vnode for block I/O. */
- u_int32_t i_flag; /* flags, see below */
- dev_t i_dev; /* Device associated with the inode. */
- ino_t i_number; /* The identity of the inode. */
-
- struct ext2_sb_info *i_e2fs; /* EXT2FS */
- u_quad_t i_modrev; /* Revision level for NFS lease. */
- struct lockf *i_lockf;/* Head of byte-level lock list. */
- /*
- * Side effects; used during directory lookup.
- */
- int32_t i_count; /* Size of free slot in directory. */
- doff_t i_endoff; /* End of useful stuff in directory. */
- doff_t i_diroff; /* Offset in dir, where we found last entry. */
- doff_t i_offset; /* Offset of free space in directory. */
- ino_t i_ino; /* Inode number of found directory. */
- u_int32_t i_reclen; /* Size of found directory entry. */
-
- u_int32_t i_block_group;
- u_int32_t i_next_alloc_block;
- u_int32_t i_next_alloc_goal;
- u_int32_t i_prealloc_block;
- u_int32_t i_prealloc_count;
-
- /* Fields from struct dinode in UFS. */
- u_int16_t i_mode; /* IFMT, permissions; see below. */
- int16_t i_nlink; /* File link count. */
- u_int64_t i_size; /* File byte count. */
- int32_t i_atime; /* Last access time. */
- int32_t i_atimensec; /* Last access time. */
- int32_t i_mtime; /* Last modified time. */
- int32_t i_mtimensec; /* Last modified time. */
- int32_t i_ctime; /* Last inode change time. */
- int32_t i_ctimensec; /* Last inode change time. */
- int32_t i_db[NDADDR]; /* Direct disk blocks. */
- int32_t i_ib[NIADDR]; /* Indirect disk blocks. */
- u_int32_t i_flags; /* Status flags (chflags). */
- int32_t i_blocks; /* Blocks actually held. */
- int32_t i_gen; /* Generation number. */
- u_int32_t i_uid; /* File owner. */
- u_int32_t i_gid; /* File group. */
-};
-
-/*
- * The di_db fields may be overlaid with other information for
- * file types that do not have associated disk storage. Block
- * and character devices overlay the first data block with their
- * dev_t value. Short symbolic links place their path in the
- * di_db area.
- */
-#define i_shortlink i_db
-#define i_rdev i_db[0]
-#define MAXSYMLINKLEN ((NDADDR + NIADDR) * sizeof(int32_t))
-
-/* File permissions. */
-#define IEXEC 0000100 /* Executable. */
-#define IWRITE 0000200 /* Writeable. */
-#define IREAD 0000400 /* Readable. */
-#define ISVTX 0001000 /* Sticky bit. */
-#define ISGID 0002000 /* Set-gid. */
-#define ISUID 0004000 /* Set-uid. */
-
-/* File types. */
-#define IFMT 0170000 /* Mask of file type. */
-#define IFIFO 0010000 /* Named pipe (fifo). */
-#define IFCHR 0020000 /* Character device. */
-#define IFDIR 0040000 /* Directory file. */
-#define IFBLK 0060000 /* Block device. */
-#define IFREG 0100000 /* Regular file. */
-#define IFLNK 0120000 /* Symbolic link. */
-#define IFSOCK 0140000 /* UNIX domain socket. */
-#define IFWHT 0160000 /* Whiteout. */
-
-/* These flags are kept in i_flag. */
-#define IN_ACCESS 0x0001 /* Access time update request. */
-#define IN_CHANGE 0x0002 /* Inode change time update request. */
-#define IN_UPDATE 0x0004 /* Modification time update request. */
-#define IN_MODIFIED 0x0008 /* Inode has been modified. */
-#define IN_RENAME 0x0010 /* Inode is being renamed. */
-#define IN_HASHED 0x0020 /* Inode is on hash list */
-#define IN_LAZYMOD 0x0040 /* Modified, but don't write yet. */
-#define IN_SPACECOUNTED 0x0080 /* Blocks to be freed in free count. */
-
-#ifdef _KERNEL
-/*
- * Structure used to pass around logical block paths generated by
- * ext2_getlbns and used by truncate and bmap code.
- */
-struct indir {
- int32_t in_lbn; /* Logical block number. */
- int in_off; /* Offset in buffer. */
- int in_exists; /* Flag if the block exists. */
-};
-
-/* Convert between inode pointers and vnode pointers. */
-#define VTOI(vp) ((struct inode *)(vp)->v_data)
-#define ITOV(ip) ((ip)->i_vnode)
-
-/* This overlays the fid structure (see mount.h). */
-struct ufid {
- u_int16_t ufid_len; /* Length of structure. */
- u_int16_t ufid_pad; /* Force 32-bit alignment. */
- ino_t ufid_ino; /* File number (ino). */
- int32_t ufid_gen; /* Generation number. */
-};
-#endif /* _KERNEL */
-
-#endif /* !_SYS_GNU_EXT2FS_INODE_H_ */
diff --git a/sys/gnu/fs/ext2fs/sparc64-bitops.h b/sys/gnu/fs/ext2fs/sparc64-bitops.h
deleted file mode 100644
index 26e3716ccea3..000000000000
--- a/sys/gnu/fs/ext2fs/sparc64-bitops.h
+++ /dev/null
@@ -1,248 +0,0 @@
-/* $Id: bitops.h,v 1.31 2000/09/23 02:09:21 davem Exp $
- * bitops.h: Bit string operations on the V9.
- *
- * Copyright 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
- */
-
-#ifndef _SPARC64_BITOPS_H
-#define _SPARC64_BITOPS_H
-
-#include <asm/byteorder.h>
-
-extern long __test_and_set_bit(unsigned long nr, volatile void *addr);
-extern long __test_and_clear_bit(unsigned long nr, volatile void *addr);
-extern long __test_and_change_bit(unsigned long nr, volatile void *addr);
-
-#define test_and_set_bit(nr,addr) (__test_and_set_bit(nr,addr)!=0)
-#define test_and_clear_bit(nr,addr) (__test_and_clear_bit(nr,addr)!=0)
-#define test_and_change_bit(nr,addr) (__test_and_change_bit(nr,addr)!=0)
-#define set_bit(nr,addr) ((void)__test_and_set_bit(nr,addr))
-#define clear_bit(nr,addr) ((void)__test_and_clear_bit(nr,addr))
-#define change_bit(nr,addr) ((void)__test_and_change_bit(nr,addr))
-
-#define smp_mb__before_clear_bit() do { } while(0)
-#define smp_mb__after_clear_bit() do { } while(0)
-
-extern __inline__ int test_bit(int nr, __const__ void *addr)
-{
- return (1UL & (((__const__ long *) addr)[nr >> 6] >> (nr & 63))) != 0UL;
-}
-
-/* The easy/cheese version for now. */
-extern __inline__ unsigned long ffz(unsigned long word)
-{
- unsigned long result;
-
-#ifdef ULTRA_HAS_POPULATION_COUNT /* Thanks for nothing Sun... */
- __asm__ __volatile__("
- brz,pn %0, 1f
- neg %0, %%g1
- xnor %0, %%g1, %%g2
- popc %%g2, %0
-1: " : "=&r" (result)
- : "0" (word)
- : "g1", "g2");
-#else
-#if 1 /* def EASY_CHEESE_VERSION */
- result = 0;
- while(word & 1) {
- result++;
- word >>= 1;
- }
-#else
- unsigned long tmp;
-
- result = 0;
- tmp = ~word & -~word;
- if (!(unsigned)tmp) {
- tmp >>= 32;
- result = 32;
- }
- if (!(unsigned short)tmp) {
- tmp >>= 16;
- result += 16;
- }
- if (!(unsigned char)tmp) {
- tmp >>= 8;
- result += 8;
- }
- if (tmp & 0xf0) result += 4;
- if (tmp & 0xcc) result += 2;
- if (tmp & 0xaa) result ++;
-#endif
-#endif
- return result;
-}
-
-#ifdef __KERNEL__
-
-/*
- * ffs: find first bit set. This is defined the same way as
- * the libc and compiler builtin ffs routines, therefore
- * differs in spirit from the above ffz (man ffs).
- */
-
-#define ffs(x) generic_ffs(x)
-
-/*
- * hweightN: returns the hamming weight (i.e. the number
- * of bits set) of a N-bit word
- */
-
-#ifdef ULTRA_HAS_POPULATION_COUNT
-
-extern __inline__ unsigned int hweight32(unsigned int w)
-{
- unsigned int res;
-
- __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffffffff));
- return res;
-}
-
-extern __inline__ unsigned int hweight16(unsigned int w)
-{
- unsigned int res;
-
- __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffff));
- return res;
-}
-
-extern __inline__ unsigned int hweight8(unsigned int w)
-{
- unsigned int res;
-
- __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xff));
- return res;
-}
-
-#else
-
-#define hweight32(x) generic_hweight32(x)
-#define hweight16(x) generic_hweight16(x)
-#define hweight8(x) generic_hweight8(x)
-
-#endif
-#endif /* __KERNEL__ */
-
-/* find_next_zero_bit() finds the first zero bit in a bit string of length
- * 'size' bits, starting the search at bit 'offset'. This is largely based
- * on Linus's ALPHA routines, which are pretty portable BTW.
- */
-
-extern __inline__ unsigned long find_next_zero_bit(void *addr, unsigned long size, unsigned long offset)
-{
- unsigned long *p = ((unsigned long *) addr) + (offset >> 6);
- unsigned long result = offset & ~63UL;
- unsigned long tmp;
-
- if (offset >= size)
- return size;
- size -= result;
- offset &= 63UL;
- if (offset) {
- tmp = *(p++);
- tmp |= ~0UL >> (64-offset);
- if (size < 64)
- goto found_first;
- if (~tmp)
- goto found_middle;
- size -= 64;
- result += 64;
- }
- while (size & ~63UL) {
- if (~(tmp = *(p++)))
- goto found_middle;
- result += 64;
- size -= 64;
- }
- if (!size)
- return result;
- tmp = *p;
-
-found_first:
- tmp |= ~0UL << size;
- if (tmp == ~0UL) /* Are any bits zero? */
- return result + size; /* Nope. */
-found_middle:
- return result + ffz(tmp);
-}
-
-#define find_first_zero_bit(addr, size) \
- find_next_zero_bit((addr), (size), 0)
-
-extern long __test_and_set_le_bit(int nr, volatile void *addr);
-extern long __test_and_clear_le_bit(int nr, volatile void *addr);
-
-#define test_and_set_le_bit(nr,addr) (__test_and_set_le_bit(nr,addr)!=0)
-#define test_and_clear_le_bit(nr,addr) (__test_and_clear_le_bit(nr,addr)!=0)
-#define set_le_bit(nr,addr) ((void)__test_and_set_le_bit(nr,addr))
-#define clear_le_bit(nr,addr) ((void)__test_and_clear_le_bit(nr,addr))
-
-extern __inline__ int test_le_bit(int nr, __const__ void * addr)
-{
- int mask;
- __const__ unsigned char *ADDR = (__const__ unsigned char *) addr;
-
- ADDR += nr >> 3;
- mask = 1 << (nr & 0x07);
- return ((mask & *ADDR) != 0);
-}
-
-#define find_first_zero_le_bit(addr, size) \
- find_next_zero_le_bit((addr), (size), 0)
-
-extern __inline__ unsigned long find_next_zero_le_bit(void *addr, unsigned long size, unsigned long offset)
-{
- unsigned long *p = ((unsigned long *) addr) + (offset >> 6);
- unsigned long result = offset & ~63UL;
- unsigned long tmp;
-
- if (offset >= size)
- return size;
- size -= result;
- offset &= 63UL;
- if(offset) {
- tmp = __swab64p(p++);
- tmp |= (~0UL >> (64-offset));
- if(size < 64)
- goto found_first;
- if(~tmp)
- goto found_middle;
- size -= 64;
- result += 64;
- }
- while(size & ~63) {
- if(~(tmp = __swab64p(p++)))
- goto found_middle;
- result += 64;
- size -= 64;
- }
- if(!size)
- return result;
- tmp = __swab64p(p);
-found_first:
- tmp |= (~0UL << size);
- if (tmp == ~0UL) /* Are any bits zero? */
- return result + size; /* Nope. */
-found_middle:
- return result + ffz(tmp);
-}
-
-#ifdef __KERNEL__
-
-#define ext2_set_bit test_and_set_le_bit
-#define ext2_clear_bit test_and_clear_le_bit
-#define ext2_test_bit test_le_bit
-#define ext2_find_first_zero_bit find_first_zero_le_bit
-#define ext2_find_next_zero_bit find_next_zero_le_bit
-
-/* Bitmap functions for the minix filesystem. */
-#define minix_test_and_set_bit(nr,addr) test_and_set_bit(nr,addr)
-#define minix_set_bit(nr,addr) set_bit(nr,addr)
-#define minix_test_and_clear_bit(nr,addr) test_and_clear_bit(nr,addr)
-#define minix_test_bit(nr,addr) test_bit(nr,addr)
-#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
-
-#endif /* __KERNEL__ */
-
-#endif /* defined(_SPARC64_BITOPS_H) */
diff --git a/sys/i386/i386/apic_vector.s b/sys/i386/i386/apic_vector.s
deleted file mode 100644
index d91ff1ce4cee..000000000000
--- a/sys/i386/i386/apic_vector.s
+++ /dev/null
@@ -1,680 +0,0 @@
-/*
- * from: vector.s, 386BSD 0.1 unknown origin
- * $FreeBSD$
- */
-
-#include "opt_swtch.h"
-
-#include <machine/apic.h>
-#include <machine/smp.h>
-
-/* convert an absolute IRQ# into a bitmask */
-#define IRQ_BIT(irq_num) (1 << (irq_num))
-
-/* make an index into the IO APIC from the IRQ# */
-#define REDTBL_IDX(irq_num) (0x10 + ((irq_num) * 2))
-
-/*
- *
- */
-#define PUSH_FRAME \
- pushl $0 ; /* dummy error code */ \
- pushl $0 ; /* dummy trap type */ \
- pushal ; /* 8 ints */ \
- pushl %ds ; /* save data and extra segments ... */ \
- pushl %es ; \
- pushl %fs
-
-#define PUSH_DUMMY \
- pushfl ; /* eflags */ \
- pushl %cs ; /* cs */ \
- pushl 12(%esp) ; /* original caller eip */ \
- pushl $0 ; /* dummy error code */ \
- pushl $0 ; /* dummy trap type */ \
- subl $11*4,%esp ;
-
-#define POP_FRAME \
- popl %fs ; \
- popl %es ; \
- popl %ds ; \
- popal ; \
- addl $4+4,%esp
-
-#define POP_DUMMY \
- addl $16*4,%esp
-
-#define IOAPICADDR(irq_num) CNAME(int_to_apicintpin) + 16 * (irq_num) + 8
-#define REDIRIDX(irq_num) CNAME(int_to_apicintpin) + 16 * (irq_num) + 12
-
-#define MASK_IRQ(irq_num) \
- ICU_LOCK ; /* into critical reg */ \
- testl $IRQ_BIT(irq_num), apic_imen ; \
- jne 7f ; /* masked, don't mask */ \
- orl $IRQ_BIT(irq_num), apic_imen ; /* set the mask bit */ \
- movl IOAPICADDR(irq_num), %ecx ; /* ioapic addr */ \
- movl REDIRIDX(irq_num), %eax ; /* get the index */ \
- movl %eax, (%ecx) ; /* write the index */ \
- movl IOAPIC_WINDOW(%ecx), %eax ; /* current value */ \
- orl $IOART_INTMASK, %eax ; /* set the mask */ \
- movl %eax, IOAPIC_WINDOW(%ecx) ; /* new value */ \
-7: ; /* already masked */ \
- ICU_UNLOCK
-/*
- * Test to see whether we are handling an edge or level triggered INT.
- * Level-triggered INTs must still be masked as we don't clear the source,
- * and the EOI cycle would cause redundant INTs to occur.
- */
-#define MASK_LEVEL_IRQ(irq_num) \
- testl $IRQ_BIT(irq_num), apic_pin_trigger ; \
- jz 9f ; /* edge, don't mask */ \
- MASK_IRQ(irq_num) ; \
-9:
-
-
-#ifdef APIC_INTR_REORDER
-#define EOI_IRQ(irq_num) \
- movl apic_isrbit_location + 8 * (irq_num), %eax ; \
- movl (%eax), %eax ; \
- testl apic_isrbit_location + 4 + 8 * (irq_num), %eax ; \
- jz 9f ; /* not active */ \
- movl $0, lapic+LA_EOI ; \
-9:
-
-#else
-#define EOI_IRQ(irq_num) \
- testl $IRQ_BIT(irq_num), lapic+LA_ISR1; \
- jz 9f ; /* not active */ \
- movl $0, lapic+LA_EOI; \
-9:
-#endif
-
-
-/*
- * Test to see if the source is currently masked, clear if so.
- */
-#define UNMASK_IRQ(irq_num) \
- ICU_LOCK ; /* into critical reg */ \
- testl $IRQ_BIT(irq_num), apic_imen ; \
- je 7f ; /* bit clear, not masked */ \
- andl $~IRQ_BIT(irq_num), apic_imen ;/* clear mask bit */ \
- movl IOAPICADDR(irq_num), %ecx ; /* ioapic addr */ \
- movl REDIRIDX(irq_num), %eax ; /* get the index */ \
- movl %eax, (%ecx) ; /* write the index */ \
- movl IOAPIC_WINDOW(%ecx), %eax ; /* current value */ \
- andl $~IOART_INTMASK, %eax ; /* clear the mask */ \
- movl %eax, IOAPIC_WINDOW(%ecx) ; /* new value */ \
-7: ; /* already unmasked */ \
- ICU_UNLOCK
-
-/*
- * Test to see whether we are handling an edge or level triggered INT.
- * Level-triggered INTs have to be unmasked.
- */
-#define UNMASK_LEVEL_IRQ(irq_num) \
- testl $IRQ_BIT(irq_num), apic_pin_trigger ; \
- jz 9f ; /* edge, don't unmask */ \
- UNMASK_IRQ(irq_num) ; \
-9:
-
-/*
- * Macros for interrupt entry, call to handler, and exit.
- */
-
-#define FAST_INTR(irq_num, vec_name) \
- .text ; \
- SUPERALIGN_TEXT ; \
-IDTVEC(vec_name) ; \
- PUSH_FRAME ; \
- movl $KDSEL,%eax ; \
- mov %ax,%ds ; \
- mov %ax,%es ; \
- movl $KPSEL,%eax ; \
- mov %ax,%fs ; \
- FAKE_MCOUNT(13*4(%esp)) ; \
- movl PCPU(CURTHREAD),%ebx ; \
- cmpl $0,TD_CRITNEST(%ebx) ; \
- je 1f ; \
-; \
- movl $1,PCPU(INT_PENDING) ; \
- orl $IRQ_BIT(irq_num),PCPU(FPENDING) ; \
- MASK_LEVEL_IRQ(irq_num) ; \
- movl $0, lapic+LA_EOI ; \
- jmp 10f ; \
-1: ; \
- incl TD_CRITNEST(%ebx) ; \
- incl TD_INTR_NESTING_LEVEL(%ebx) ; \
- pushl intr_unit + (irq_num) * 4 ; \
- call *intr_handler + (irq_num) * 4 ; /* do the work ASAP */ \
- addl $4, %esp ; \
- movl $0, lapic+LA_EOI ; \
- lock ; \
- incl cnt+V_INTR ; /* book-keeping can wait */ \
- movl intr_countp + (irq_num) * 4, %eax ; \
- lock ; \
- incl (%eax) ; \
- decl TD_CRITNEST(%ebx) ; \
- cmpl $0,PCPU(INT_PENDING) ; \
- je 2f ; \
-; \
- call i386_unpend ; \
-2: ; \
- decl TD_INTR_NESTING_LEVEL(%ebx) ; \
-10: ; \
- MEXITCOUNT ; \
- jmp doreti
-
-/*
- * Restart a fast interrupt that was held up by a critical section.
- * This routine is called from unpend(). unpend() ensures we are
- * in a critical section and deals with the interrupt nesting level
- * for us. If we previously masked the irq, we have to unmask it.
- *
- * We have a choice. We can regenerate the irq using the 'int'
- * instruction or we can create a dummy frame and call the interrupt
- * handler directly. I've chosen to use the dummy-frame method.
- */
-#define FAST_UNPEND(irq_num, vec_name) \
- .text ; \
- SUPERALIGN_TEXT ; \
-IDTVEC(vec_name) ; \
-; \
- pushl %ebp ; \
- movl %esp, %ebp ; \
- PUSH_DUMMY ; \
- pushl intr_unit + (irq_num) * 4 ; \
- call *intr_handler + (irq_num) * 4 ; /* do the work ASAP */ \
- addl $4, %esp ; \
- lock ; \
- incl cnt+V_INTR ; /* book-keeping can wait */ \
- movl intr_countp + (irq_num) * 4, %eax ; \
- lock ; \
- incl (%eax) ; \
- UNMASK_LEVEL_IRQ(irq_num) ; \
- POP_DUMMY ; \
- popl %ebp ; \
- ret ; \
-
-
-/*
- * Slow, threaded interrupts.
- *
- * XXX Most of the parameters here are obsolete. Fix this when we're
- * done.
- * XXX we really shouldn't return via doreti if we just schedule the
- * interrupt handler and don't run anything. We could just do an
- * iret. FIXME.
- */
-#define INTR(irq_num, vec_name, maybe_extra_ipending) \
- .text ; \
- SUPERALIGN_TEXT ; \
-/* _XintrNN: entry point used by IDT/HWIs via _vec[]. */ \
-IDTVEC(vec_name) ; \
- PUSH_FRAME ; \
- movl $KDSEL, %eax ; /* reload with kernel's data segment */ \
- mov %ax, %ds ; \
- mov %ax, %es ; \
- movl $KPSEL, %eax ; \
- mov %ax, %fs ; \
-; \
- maybe_extra_ipending ; \
-; \
- MASK_LEVEL_IRQ(irq_num) ; \
- EOI_IRQ(irq_num) ; \
-; \
- movl PCPU(CURTHREAD),%ebx ; \
- cmpl $0,TD_CRITNEST(%ebx) ; \
- je 1f ; \
- movl $1,PCPU(INT_PENDING) ; \
- orl $IRQ_BIT(irq_num),PCPU(IPENDING) ; \
- jmp 10f ; \
-1: ; \
- incl TD_INTR_NESTING_LEVEL(%ebx) ; \
-; \
- FAKE_MCOUNT(13*4(%esp)) ; /* XXX avoid dbl cnt */ \
- cmpl $0,PCPU(INT_PENDING) ; \
- je 9f ; \
- call i386_unpend ; \
-9: ; \
- pushl $irq_num; /* pass the IRQ */ \
- call sched_ithd ; \
- addl $4, %esp ; /* discard the parameter */ \
-; \
- decl TD_INTR_NESTING_LEVEL(%ebx) ; \
-10: ; \
- MEXITCOUNT ; \
- jmp doreti
-
-/*
- * Handle "spurious INTerrupts".
- * Notes:
- * This is different than the "spurious INTerrupt" generated by an
- * 8259 PIC for missing INTs. See the APIC documentation for details.
- * This routine should NOT do an 'EOI' cycle.
- */
- .text
- SUPERALIGN_TEXT
- .globl Xspuriousint
-Xspuriousint:
-
- /* No EOI cycle used here */
-
- iret
-
-/*
- * Global address space TLB shootdown.
- */
- .text
- SUPERALIGN_TEXT
- .globl Xinvltlb
-Xinvltlb:
- pushl %eax
- pushl %ds
- movl $KDSEL, %eax /* Kernel data selector */
- mov %ax, %ds
-
-#ifdef COUNT_XINVLTLB_HITS
- pushl %fs
- movl $KPSEL, %eax /* Private space selector */
- mov %ax, %fs
- movl PCPU(CPUID), %eax
- popl %fs
- incl xhits_gbl(,%eax,4)
-#endif /* COUNT_XINVLTLB_HITS */
-
- movl %cr3, %eax /* invalidate the TLB */
- movl %eax, %cr3
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- lock
- incl smp_tlb_wait
-
- popl %ds
- popl %eax
- iret
-
-/*
- * Single page TLB shootdown
- */
- .text
- SUPERALIGN_TEXT
- .globl Xinvlpg
-Xinvlpg:
- pushl %eax
- pushl %ds
- movl $KDSEL, %eax /* Kernel data selector */
- mov %ax, %ds
-
-#ifdef COUNT_XINVLTLB_HITS
- pushl %fs
- movl $KPSEL, %eax /* Private space selector */
- mov %ax, %fs
- movl PCPU(CPUID), %eax
- popl %fs
- incl xhits_pg(,%eax,4)
-#endif /* COUNT_XINVLTLB_HITS */
-
- movl smp_tlb_addr1, %eax
- invlpg (%eax) /* invalidate single page */
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- lock
- incl smp_tlb_wait
-
- popl %ds
- popl %eax
- iret
-
-/*
- * Page range TLB shootdown.
- */
- .text
- SUPERALIGN_TEXT
- .globl Xinvlrng
-Xinvlrng:
- pushl %eax
- pushl %edx
- pushl %ds
- movl $KDSEL, %eax /* Kernel data selector */
- mov %ax, %ds
-
-#ifdef COUNT_XINVLTLB_HITS
- pushl %fs
- movl $KPSEL, %eax /* Private space selector */
- mov %ax, %fs
- movl PCPU(CPUID), %eax
- popl %fs
- incl xhits_rng(,%eax,4)
-#endif /* COUNT_XINVLTLB_HITS */
-
- movl smp_tlb_addr1, %edx
- movl smp_tlb_addr2, %eax
-1: invlpg (%edx) /* invalidate single page */
- addl $PAGE_SIZE, %edx
- cmpl %eax, %edx
- jb 1b
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- lock
- incl smp_tlb_wait
-
- popl %ds
- popl %edx
- popl %eax
- iret
-
-/*
- * Forward hardclock to another CPU. Pushes a clockframe and calls
- * forwarded_hardclock().
- */
- .text
- SUPERALIGN_TEXT
- .globl Xhardclock
-Xhardclock:
- PUSH_FRAME
- movl $KDSEL, %eax /* reload with kernel's data segment */
- mov %ax, %ds
- mov %ax, %es
- movl $KPSEL, %eax
- mov %ax, %fs
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- movl PCPU(CURTHREAD),%ebx
- cmpl $0,TD_CRITNEST(%ebx)
- je 1f
- movl $1,PCPU(INT_PENDING)
- orl $1,PCPU(SPENDING);
- jmp 10f
-1:
- incl TD_INTR_NESTING_LEVEL(%ebx)
- pushl $0 /* XXX convert trapframe to clockframe */
- call forwarded_hardclock
- addl $4, %esp /* XXX convert clockframe to trapframe */
- decl TD_INTR_NESTING_LEVEL(%ebx)
-10:
- MEXITCOUNT
- jmp doreti
-
-/*
- * Forward statclock to another CPU. Pushes a clockframe and calls
- * forwarded_statclock().
- */
- .text
- SUPERALIGN_TEXT
- .globl Xstatclock
-Xstatclock:
- PUSH_FRAME
- movl $KDSEL, %eax /* reload with kernel's data segment */
- mov %ax, %ds
- mov %ax, %es
- movl $KPSEL, %eax
- mov %ax, %fs
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- FAKE_MCOUNT(13*4(%esp))
-
- movl PCPU(CURTHREAD),%ebx
- cmpl $0,TD_CRITNEST(%ebx)
- je 1f
- movl $1,PCPU(INT_PENDING)
- orl $2,PCPU(SPENDING);
- jmp 10f
-1:
- incl TD_INTR_NESTING_LEVEL(%ebx)
- pushl $0 /* XXX convert trapframe to clockframe */
- call forwarded_statclock
- addl $4, %esp /* XXX convert clockframe to trapframe */
- decl TD_INTR_NESTING_LEVEL(%ebx)
-10:
- MEXITCOUNT
- jmp doreti
-
-/*
- * Executed by a CPU when it receives an Xcpuast IPI from another CPU,
- *
- * The other CPU has already executed aston() or need_resched() on our
- * current process, so we simply need to ack the interrupt and return
- * via doreti to run ast().
- */
-
- .text
- SUPERALIGN_TEXT
- .globl Xcpuast
-Xcpuast:
- PUSH_FRAME
- movl $KDSEL, %eax
- mov %ax, %ds /* use KERNEL data segment */
- mov %ax, %es
- movl $KPSEL, %eax
- mov %ax, %fs
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- FAKE_MCOUNT(13*4(%esp))
-
- MEXITCOUNT
- jmp doreti
-
-/*
- * Executed by a CPU when it receives an Xcpustop IPI from another CPU,
- *
- * - Signals its receipt.
- * - Waits for permission to restart.
- * - Signals its restart.
- */
- .text
- SUPERALIGN_TEXT
- .globl Xcpustop
-Xcpustop:
- pushl %ebp
- movl %esp, %ebp
- pushl %eax
- pushl %ecx
- pushl %edx
- pushl %ds /* save current data segment */
- pushl %fs
-
- movl $KDSEL, %eax
- mov %ax, %ds /* use KERNEL data segment */
- movl $KPSEL, %eax
- mov %ax, %fs
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
-
- movl PCPU(CPUID), %eax
- imull $PCB_SIZE, %eax
- leal CNAME(stoppcbs)(%eax), %eax
- pushl %eax
- call CNAME(savectx) /* Save process context */
- addl $4, %esp
-
- movl PCPU(CPUID), %eax
-
- lock
- btsl %eax, CNAME(stopped_cpus) /* stopped_cpus |= (1<<id) */
-1:
- btl %eax, CNAME(started_cpus) /* while (!(started_cpus & (1<<id))) */
- jnc 1b
-
- lock
- btrl %eax, CNAME(started_cpus) /* started_cpus &= ~(1<<id) */
- lock
- btrl %eax, CNAME(stopped_cpus) /* stopped_cpus &= ~(1<<id) */
-
- test %eax, %eax
- jnz 2f
-
- movl CNAME(cpustop_restartfunc), %eax
- test %eax, %eax
- jz 2f
- movl $0, CNAME(cpustop_restartfunc) /* One-shot */
-
- call *%eax
-2:
- popl %fs
- popl %ds /* restore previous data segment */
- popl %edx
- popl %ecx
- popl %eax
- movl %ebp, %esp
- popl %ebp
- iret
-
-
-MCOUNT_LABEL(bintr)
- FAST_INTR(0,fastintr0)
- FAST_INTR(1,fastintr1)
- FAST_INTR(2,fastintr2)
- FAST_INTR(3,fastintr3)
- FAST_INTR(4,fastintr4)
- FAST_INTR(5,fastintr5)
- FAST_INTR(6,fastintr6)
- FAST_INTR(7,fastintr7)
- FAST_INTR(8,fastintr8)
- FAST_INTR(9,fastintr9)
- FAST_INTR(10,fastintr10)
- FAST_INTR(11,fastintr11)
- FAST_INTR(12,fastintr12)
- FAST_INTR(13,fastintr13)
- FAST_INTR(14,fastintr14)
- FAST_INTR(15,fastintr15)
- FAST_INTR(16,fastintr16)
- FAST_INTR(17,fastintr17)
- FAST_INTR(18,fastintr18)
- FAST_INTR(19,fastintr19)
- FAST_INTR(20,fastintr20)
- FAST_INTR(21,fastintr21)
- FAST_INTR(22,fastintr22)
- FAST_INTR(23,fastintr23)
- FAST_INTR(24,fastintr24)
- FAST_INTR(25,fastintr25)
- FAST_INTR(26,fastintr26)
- FAST_INTR(27,fastintr27)
- FAST_INTR(28,fastintr28)
- FAST_INTR(29,fastintr29)
- FAST_INTR(30,fastintr30)
- FAST_INTR(31,fastintr31)
-#define CLKINTR_PENDING movl $1,CNAME(clkintr_pending)
-/* Threaded interrupts */
- INTR(0,intr0, CLKINTR_PENDING)
- INTR(1,intr1,)
- INTR(2,intr2,)
- INTR(3,intr3,)
- INTR(4,intr4,)
- INTR(5,intr5,)
- INTR(6,intr6,)
- INTR(7,intr7,)
- INTR(8,intr8,)
- INTR(9,intr9,)
- INTR(10,intr10,)
- INTR(11,intr11,)
- INTR(12,intr12,)
- INTR(13,intr13,)
- INTR(14,intr14,)
- INTR(15,intr15,)
- INTR(16,intr16,)
- INTR(17,intr17,)
- INTR(18,intr18,)
- INTR(19,intr19,)
- INTR(20,intr20,)
- INTR(21,intr21,)
- INTR(22,intr22,)
- INTR(23,intr23,)
- INTR(24,intr24,)
- INTR(25,intr25,)
- INTR(26,intr26,)
- INTR(27,intr27,)
- INTR(28,intr28,)
- INTR(29,intr29,)
- INTR(30,intr30,)
- INTR(31,intr31,)
-
- FAST_UNPEND(0,fastunpend0)
- FAST_UNPEND(1,fastunpend1)
- FAST_UNPEND(2,fastunpend2)
- FAST_UNPEND(3,fastunpend3)
- FAST_UNPEND(4,fastunpend4)
- FAST_UNPEND(5,fastunpend5)
- FAST_UNPEND(6,fastunpend6)
- FAST_UNPEND(7,fastunpend7)
- FAST_UNPEND(8,fastunpend8)
- FAST_UNPEND(9,fastunpend9)
- FAST_UNPEND(10,fastunpend10)
- FAST_UNPEND(11,fastunpend11)
- FAST_UNPEND(12,fastunpend12)
- FAST_UNPEND(13,fastunpend13)
- FAST_UNPEND(14,fastunpend14)
- FAST_UNPEND(15,fastunpend15)
- FAST_UNPEND(16,fastunpend16)
- FAST_UNPEND(17,fastunpend17)
- FAST_UNPEND(18,fastunpend18)
- FAST_UNPEND(19,fastunpend19)
- FAST_UNPEND(20,fastunpend20)
- FAST_UNPEND(21,fastunpend21)
- FAST_UNPEND(22,fastunpend22)
- FAST_UNPEND(23,fastunpend23)
- FAST_UNPEND(24,fastunpend24)
- FAST_UNPEND(25,fastunpend25)
- FAST_UNPEND(26,fastunpend26)
- FAST_UNPEND(27,fastunpend27)
- FAST_UNPEND(28,fastunpend28)
- FAST_UNPEND(29,fastunpend29)
- FAST_UNPEND(30,fastunpend30)
- FAST_UNPEND(31,fastunpend31)
-MCOUNT_LABEL(eintr)
-
-/*
- * Executed by a CPU when it receives a RENDEZVOUS IPI from another CPU.
- *
- * - Calls the generic rendezvous action function.
- */
- .text
- SUPERALIGN_TEXT
- .globl Xrendezvous
-Xrendezvous:
- PUSH_FRAME
- movl $KDSEL, %eax
- mov %ax, %ds /* use KERNEL data segment */
- mov %ax, %es
- movl $KPSEL, %eax
- mov %ax, %fs
-
- call smp_rendezvous_action
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
- POP_FRAME
- iret
-
-#ifdef LAZY_SWITCH
-/*
- * Clean up when we lose out on the lazy context switch optimization.
- * ie: when we are about to release a PTD but a cpu is still borrowing it.
- */
- SUPERALIGN_TEXT
- .globl Xlazypmap
-Xlazypmap:
- PUSH_FRAME
- movl $KDSEL, %eax
- mov %ax, %ds /* use KERNEL data segment */
- mov %ax, %es
- movl $KPSEL, %eax
- mov %ax, %fs
-
- call pmap_lazyfix_action
-
- movl $0, lapic+LA_EOI /* End Of Interrupt to APIC */
- POP_FRAME
- iret
-#endif
-
- .data
-
- .globl apic_pin_trigger
-apic_pin_trigger:
- .long 0
-
- .text
diff --git a/sys/i386/i386/mptable.c b/sys/i386/i386/mptable.c
deleted file mode 100644
index d630bd583aa4..000000000000
--- a/sys/i386/i386/mptable.c
+++ /dev/null
@@ -1,2839 +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$
- */
-
-#include "opt_cpu.h"
-#include "opt_kstack_pages.h"
-#include "opt_swtch.h"
-
-#ifdef SMP
-#include <machine/smptests.h>
-#else
-#error
-#endif
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/cons.h> /* cngetc() */
-#ifdef GPROF
-#include <sys/gmon.h>
-#endif
-#include <sys/kernel.h>
-#include <sys/ktr.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/memrange.h>
-#include <sys/mutex.h>
-#include <sys/pcpu.h>
-#include <sys/proc.h>
-#include <sys/smp.h>
-#include <sys/sysctl.h>
-#include <sys/user.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_extern.h>
-#include <vm/vm_map.h>
-
-#include <machine/apic.h>
-#include <machine/atomic.h>
-#include <machine/clock.h>
-#include <machine/cpu.h>
-#include <machine/cpufunc.h>
-#include <machine/mpapic.h>
-#include <machine/psl.h>
-#include <machine/segments.h>
-#include <machine/smp.h>
-#include <machine/smptests.h> /** TEST_DEFAULT_CONFIG, TEST_TEST1 */
-#include <machine/tss.h>
-#include <machine/specialreg.h>
-#include <machine/privatespace.h>
-
-#if defined(APIC_IO)
-#include <machine/md_var.h> /* setidt() */
-#include <i386/isa/icu.h> /* IPIs */
-#include <i386/isa/intr_machdep.h> /* IPIs */
-#endif /* APIC_IO */
-
-#if defined(TEST_DEFAULT_CONFIG)
-#define MPFPS_MPFB1 TEST_DEFAULT_CONFIG
-#else
-#define MPFPS_MPFB1 mpfps->mpfb1
-#endif /* TEST_DEFAULT_CONFIG */
-
-#define WARMBOOT_TARGET 0
-#define WARMBOOT_OFF (KERNBASE + 0x0467)
-#define WARMBOOT_SEG (KERNBASE + 0x0469)
-
-#ifdef PC98
-#define BIOS_BASE (0xe8000)
-#define BIOS_SIZE (0x18000)
-#else
-#define BIOS_BASE (0xf0000)
-#define BIOS_SIZE (0x10000)
-#endif
-#define BIOS_COUNT (BIOS_SIZE/4)
-
-#define CMOS_REG (0x70)
-#define CMOS_DATA (0x71)
-#define BIOS_RESET (0x0f)
-#define BIOS_WARM (0x0a)
-
-#define PROCENTRY_FLAG_EN 0x01
-#define PROCENTRY_FLAG_BP 0x02
-#define IOAPICENTRY_FLAG_EN 0x01
-
-
-/* MP Floating Pointer Structure */
-typedef struct MPFPS {
- char signature[4];
- void *pap;
- u_char length;
- u_char spec_rev;
- u_char checksum;
- u_char mpfb1;
- u_char mpfb2;
- u_char mpfb3;
- u_char mpfb4;
- u_char mpfb5;
-} *mpfps_t;
-
-/* 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];
- void *oem_table_pointer;
- u_short oem_table_size;
- u_short entry_count;
- void *apic_address;
- u_short extended_table_length;
- u_char extended_table_checksum;
- u_char reserved;
-} *mpcth_t;
-
-
-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;
-
-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;
- void *apic_address;
-} *io_apic_entry_ptr;
-
-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;
-
-/* descriptions of MP basetable entries */
-typedef struct BASETABLE_ENTRY {
- u_char type;
- u_char length;
- char name[16];
-} basetable_entry;
-
-/*
- * this code MUST be enabled here and in mpboot.s.
- * it follows the very early stages of AP boot by placing values in CMOS ram.
- * it NORMALLY will never be needed and thus the primitive method for enabling.
- *
-#define CHECK_POINTS
- */
-
-#if defined(CHECK_POINTS) && !defined(PC98)
-#define CHECK_READ(A) (outb(CMOS_REG, (A)), inb(CMOS_DATA))
-#define CHECK_WRITE(A,D) (outb(CMOS_REG, (A)), outb(CMOS_DATA, (D)))
-
-#define CHECK_INIT(D); \
- CHECK_WRITE(0x34, (D)); \
- CHECK_WRITE(0x35, (D)); \
- CHECK_WRITE(0x36, (D)); \
- CHECK_WRITE(0x37, (D)); \
- CHECK_WRITE(0x38, (D)); \
- CHECK_WRITE(0x39, (D));
-
-#define CHECK_PRINT(S); \
- printf("%s: %d, %d, %d, %d, %d, %d\n", \
- (S), \
- CHECK_READ(0x34), \
- CHECK_READ(0x35), \
- CHECK_READ(0x36), \
- CHECK_READ(0x37), \
- CHECK_READ(0x38), \
- CHECK_READ(0x39));
-
-#else /* CHECK_POINTS */
-
-#define CHECK_INIT(D)
-#define CHECK_PRINT(S)
-
-#endif /* CHECK_POINTS */
-
-/*
- * Values to send to the POST hardware.
- */
-#define MP_BOOTADDRESS_POST 0x10
-#define MP_PROBE_POST 0x11
-#define MPTABLE_PASS1_POST 0x12
-
-#define MP_START_POST 0x13
-#define MP_ENABLE_POST 0x14
-#define MPTABLE_PASS2_POST 0x15
-
-#define START_ALL_APS_POST 0x16
-#define INSTALL_AP_TRAMP_POST 0x17
-#define START_AP_POST 0x18
-
-#define MP_ANNOUNCE_POST 0x19
-
-static int need_hyperthreading_fixup;
-static u_int logical_cpus;
-static u_int logical_cpus_mask;
-
-/* used to hold the AP's until we are ready to release them */
-static struct mtx ap_boot_mtx;
-
-/** XXX FIXME: where does this really belong, isa.h/isa.c perhaps? */
-int current_postcode;
-
-/** XXX FIXME: what system files declare these??? */
-extern struct region_descriptor r_gdt, r_idt;
-
-int bsp_apic_ready = 0; /* flags useability of BSP apic */
-int mp_naps; /* # of Applications processors */
-int mp_nbusses; /* # of busses */
-int mp_napics; /* # of IO APICs */
-int boot_cpu_id; /* designated BSP */
-vm_offset_t cpu_apic_address;
-vm_offset_t io_apic_address[NAPICID]; /* NAPICID is more than enough */
-extern int nkpt;
-
-u_int32_t cpu_apic_versions[MAXCPU];
-u_int32_t *io_apic_versions;
-
-#ifdef APIC_INTR_REORDER
-struct {
- volatile int *location;
- int bit;
-} apic_isrbit_location[32];
-#endif
-
-struct apic_intmapinfo int_to_apicintpin[APIC_INTMAPSIZE];
-
-/*
- * APIC ID logical/physical mapping structures.
- * We oversize these to simplify boot-time config.
- */
-int cpu_num_to_apic_id[NAPICID];
-int io_num_to_apic_id[NAPICID];
-int apic_id_to_logical[NAPICID];
-
-
-/* AP uses this during bootstrap. Do not staticize. */
-char *bootSTK;
-static int bootAP;
-
-/* Hotwire a 0->4MB V==P mapping */
-extern pt_entry_t *KPTphys;
-
-/* SMP page table page */
-extern pt_entry_t *SMPpt;
-
-struct pcb stoppcbs[MAXCPU];
-
-#ifdef APIC_IO
-/* Variables needed for SMP tlb shootdown. */
-vm_offset_t smp_tlb_addr1;
-vm_offset_t smp_tlb_addr2;
-volatile int smp_tlb_wait;
-static struct mtx smp_tlb_mtx;
-#endif
-
-/*
- * Local data and functions.
- */
-
-/* Set to 1 once we're ready to let the APs out of the pen. */
-static volatile int aps_ready = 0;
-
-static int mp_capable;
-static u_int boot_address;
-static u_int base_memory;
-
-static int picmode; /* 0: virtual wire mode, 1: PIC mode */
-static mpfps_t mpfps;
-static int search_for_sig(u_int32_t target, int count);
-static void mp_enable(u_int boot_addr);
-
-static void mptable_hyperthread_fixup(u_int id_mask);
-static void mptable_pass1(void);
-static int mptable_pass2(void);
-static void default_mp_table(int type);
-static void fix_mp_table(void);
-static void setup_apic_irq_mapping(void);
-static void init_locks(void);
-static int start_all_aps(u_int boot_addr);
-static void install_ap_tramp(u_int boot_addr);
-static int start_ap(int logicalCpu, u_int boot_addr);
-void ap_init(void);
-static int apic_int_is_bus_type(int intr, int bus_type);
-static void release_aps(void *dummy);
-
-/*
- * initialize all the SMP locks
- */
-
-/* lock region used by kernel profiling */
-int mcount_lock;
-
-#ifdef USE_COMLOCK
-/* locks com (tty) data/hardware accesses: a FASTINTR() */
-struct mtx com_mtx;
-#endif /* USE_COMLOCK */
-
-static void
-init_locks(void)
-{
-
-#ifdef USE_COMLOCK
- mtx_init(&com_mtx, "com", NULL, MTX_SPIN);
-#endif /* USE_COMLOCK */
-#ifdef APIC_IO
- mtx_init(&smp_tlb_mtx, "tlb", NULL, MTX_SPIN);
-#endif
-}
-
-/*
- * Calculate usable address in base memory for AP trampoline code.
- */
-u_int
-mp_bootaddress(u_int basemem)
-{
- POSTCODE(MP_BOOTADDRESS_POST);
-
- base_memory = basemem * 1024; /* convert to bytes */
-
- boot_address = base_memory & ~0xfff; /* round down to 4k boundary */
- if ((base_memory - boot_address) < bootMP_size)
- boot_address -= 4096; /* not enough, lower by 4k */
-
- return boot_address;
-}
-
-
-/*
- * Look for an Intel MP spec table (ie, SMP capable hardware).
- */
-void
-i386_mp_probe(void)
-{
- int x;
- u_long segment;
- u_int32_t target;
-
- POSTCODE(MP_PROBE_POST);
-
- /* see if EBDA exists */
- if ((segment = (u_long) * (u_short *) (KERNBASE + 0x40e)) != 0) {
- /* search first 1K of EBDA */
- target = (u_int32_t) (segment << 4);
- if ((x = search_for_sig(target, 1024 / 4)) >= 0)
- goto found;
- } else {
- /* last 1K of base memory, effective 'top of base' passed in */
- target = (u_int32_t) (base_memory - 0x400);
- if ((x = search_for_sig(target, 1024 / 4)) >= 0)
- goto found;
- }
-
- /* search the BIOS */
- target = (u_int32_t) BIOS_BASE;
- if ((x = search_for_sig(target, BIOS_COUNT)) >= 0)
- goto found;
-
- /* nothing found */
- mpfps = (mpfps_t)0;
- mp_capable = 0;
- return;
-
-found:
- /* calculate needed resources */
- mpfps = (mpfps_t)x;
- mptable_pass1();
-
- /* flag fact that we are running multiple processors */
- mp_capable = 1;
-}
-
-int
-cpu_mp_probe(void)
-{
- /*
- * Record BSP in CPU map
- * This is done here so that MBUF init code works correctly.
- */
- all_cpus = 1;
-
- return (mp_capable);
-}
-
-/*
- * Initialize the SMP hardware and the APIC and start up the AP's.
- */
-void
-cpu_mp_start(void)
-{
- POSTCODE(MP_START_POST);
-
- /* look for MP capable motherboard */
- if (mp_capable)
- mp_enable(boot_address);
- else
- panic("MP hardware not found!");
-
- cpu_setregs();
-}
-
-
-/*
- * Print various information about the SMP system hardware and setup.
- */
-void
-cpu_mp_announce(void)
-{
- int x;
-
- POSTCODE(MP_ANNOUNCE_POST);
-
- printf(" cpu0 (BSP): apic id: %2d", CPU_TO_ID(0));
- printf(", version: 0x%08x", cpu_apic_versions[0]);
- printf(", at 0x%08x\n", cpu_apic_address);
- for (x = 1; x <= mp_naps; ++x) {
- printf(" cpu%d (AP): apic id: %2d", x, CPU_TO_ID(x));
- printf(", version: 0x%08x", cpu_apic_versions[x]);
- printf(", at 0x%08x\n", cpu_apic_address);
- }
-
-#if defined(APIC_IO)
- for (x = 0; x < mp_napics; ++x) {
- printf(" io%d (APIC): apic id: %2d", x, IO_TO_ID(x));
- printf(", version: 0x%08x", io_apic_versions[x]);
- printf(", at 0x%08x\n", io_apic_address[x]);
- }
-#else
- printf(" Warning: APIC I/O disabled\n");
-#endif /* APIC_IO */
-}
-
-/*
- * AP cpu's call this to sync up protected mode.
- */
-void
-init_secondary(void)
-{
- int gsel_tss;
- int x, myid = bootAP;
- u_int cr0;
-
- gdt_segs[GPRIV_SEL].ssd_base = (int) &SMP_prvspace[myid];
- gdt_segs[GPROC0_SEL].ssd_base =
- (int) &SMP_prvspace[myid].pcpu.pc_common_tss;
- SMP_prvspace[myid].pcpu.pc_prvspace =
- &SMP_prvspace[myid].pcpu;
-
- for (x = 0; x < NGDT; x++) {
- ssdtosd(&gdt_segs[x], &gdt[myid * NGDT + x].sd);
- }
-
- r_gdt.rd_limit = NGDT * sizeof(gdt[0]) - 1;
- r_gdt.rd_base = (int) &gdt[myid * NGDT];
- lgdt(&r_gdt); /* does magic intra-segment return */
-
- lidt(&r_idt);
-
- lldt(_default_ldt);
- PCPU_SET(currentldt, _default_ldt);
-
- gsel_tss = GSEL(GPROC0_SEL, SEL_KPL);
- gdt[myid * NGDT + GPROC0_SEL].sd.sd_type = SDT_SYS386TSS;
- PCPU_SET(common_tss.tss_esp0, 0); /* not used until after switch */
- PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL));
- PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16);
- PCPU_SET(tss_gdt, &gdt[myid * NGDT + GPROC0_SEL].sd);
- PCPU_SET(common_tssd, *PCPU_GET(tss_gdt));
- ltr(gsel_tss);
-
- /*
- * Set to a known state:
- * Set by mpboot.s: CR0_PG, CR0_PE
- * Set by cpu_setregs: CR0_NE, CR0_MP, CR0_TS, CR0_WP, CR0_AM
- */
- cr0 = rcr0();
- cr0 &= ~(CR0_CD | CR0_NW | CR0_EM);
- load_cr0(cr0);
-
- pmap_set_opt();
-}
-
-
-#if defined(APIC_IO)
-/*
- * Final configuration of the BSP's local APIC:
- * - disable 'pic mode'.
- * - disable 'virtual wire mode'.
- * - enable NMI.
- */
-void
-bsp_apic_configure(void)
-{
- u_char byte;
- u_int32_t temp;
-
- /* leave 'pic mode' if necessary */
- if (picmode) {
- outb(0x22, 0x70); /* select IMCR */
- byte = inb(0x23); /* current contents */
- byte |= 0x01; /* mask external INTR */
- outb(0x23, byte); /* disconnect 8259s/NMI */
- }
-
- /* mask lint0 (the 8259 'virtual wire' connection) */
- temp = lapic.lvt_lint0;
- temp |= APIC_LVT_M; /* set the mask */
- lapic.lvt_lint0 = temp;
-
- /* setup lint1 to handle NMI */
- temp = lapic.lvt_lint1;
- temp &= ~APIC_LVT_M; /* clear the mask */
- lapic.lvt_lint1 = temp;
-
- if (bootverbose)
- apic_dump("bsp_apic_configure()");
-}
-#endif /* APIC_IO */
-
-
-/*******************************************************************
- * local functions and data
- */
-
-/*
- * start the SMP system
- */
-static void
-mp_enable(u_int boot_addr)
-{
- int x;
-#if defined(APIC_IO)
- int apic;
- u_int ux;
-#endif /* APIC_IO */
-
- POSTCODE(MP_ENABLE_POST);
-
- /* turn on 4MB of V == P addressing so we can get to MP table */
- *(int *)PTD = PG_V | PG_RW | ((uintptr_t)(void *)KPTphys & PG_FRAME);
- invltlb();
-
- /* examine the MP table for needed info, uses physical addresses */
- x = mptable_pass2();
-
- *(int *)PTD = 0;
- invltlb();
-
- /* can't process default configs till the CPU APIC is pmapped */
- if (x)
- default_mp_table(x);
-
- /* post scan cleanup */
- fix_mp_table();
- setup_apic_irq_mapping();
-
-#if defined(APIC_IO)
-
- /* fill the LOGICAL io_apic_versions table */
- for (apic = 0; apic < mp_napics; ++apic) {
- ux = io_apic_read(apic, IOAPIC_VER);
- io_apic_versions[apic] = ux;
- io_apic_set_id(apic, IO_TO_ID(apic));
- }
-
- /* program each IO APIC in the system */
- for (apic = 0; apic < mp_napics; ++apic)
- if (io_apic_setup(apic) < 0)
- panic("IO APIC setup failure");
-
- /* install a 'Spurious INTerrupt' vector */
- setidt(XSPURIOUSINT_OFFSET, Xspuriousint,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for TLB invalidation */
- setidt(XINVLTLB_OFFSET, Xinvltlb,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- setidt(XINVLPG_OFFSET, Xinvlpg,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- setidt(XINVLRNG_OFFSET, Xinvlrng,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forwarding hardclock() */
- setidt(XHARDCLOCK_OFFSET, Xhardclock,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forwarding statclock() */
- setidt(XSTATCLOCK_OFFSET, Xstatclock,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
-#ifdef LAZY_SWITCH
- /* install an inter-CPU IPI for lazy pmap release */
- setidt(XLAZYPMAP_OFFSET, Xlazypmap,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif
-
- /* install an inter-CPU IPI for all-CPU rendezvous */
- setidt(XRENDEZVOUS_OFFSET, Xrendezvous,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forcing an additional software trap */
- setidt(XCPUAST_OFFSET, Xcpuast,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for CPU stop/restart */
- setidt(XCPUSTOP_OFFSET, Xcpustop,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
-#if defined(TEST_TEST1)
- /* install a "fake hardware INTerrupt" vector */
- setidt(XTEST1_OFFSET, Xtest1,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif /** TEST_TEST1 */
-
-#endif /* APIC_IO */
-
- /* initialize all SMP locks */
- init_locks();
-
- /* start each Application Processor */
- start_all_aps(boot_addr);
-}
-
-
-/*
- * look for the MP spec signature
- */
-
-/* string defined by the Intel MP Spec as identifying the MP table */
-#define MP_SIG 0x5f504d5f /* _MP_ */
-#define NEXT(X) ((X) += 4)
-static int
-search_for_sig(u_int32_t target, int count)
-{
- int x;
- u_int32_t *addr = (u_int32_t *) (KERNBASE + target);
-
- for (x = 0; x < count; NEXT(x))
- if (addr[x] == MP_SIG)
- /* make array index a byte index */
- return (target + (x * sizeof(u_int32_t)));
-
- return -1;
-}
-
-
-static basetable_entry basetable_entry_types[] =
-{
- {0, 20, "Processor"},
- {1, 8, "Bus"},
- {2, 8, "I/O APIC"},
- {3, 8, "I/O INT"},
- {4, 8, "Local INT"}
-};
-
-typedef struct BUSDATA {
- u_char bus_id;
- enum busTypes bus_type;
-} bus_datum;
-
-typedef struct INTDATA {
- 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;
- u_char int_vector;
-} io_int, local_int;
-
-typedef struct BUSTYPENAME {
- u_char type;
- char name[7];
-} bus_type_name;
-
-static bus_type_name bus_type_table[] =
-{
- {CBUS, "CBUS"},
- {CBUSII, "CBUSII"},
- {EISA, "EISA"},
- {MCA, "MCA"},
- {UNKNOWN_BUSTYPE, "---"},
- {ISA, "ISA"},
- {MCA, "MCA"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {PCI, "PCI"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {XPRESS, "XPRESS"},
- {UNKNOWN_BUSTYPE, "---"}
-};
-/* from MP spec v1.4, table 5-1 */
-static int default_data[7][5] =
-{
-/* nbus, id0, type0, id1, type1 */
- {1, 0, ISA, 255, 255},
- {1, 0, EISA, 255, 255},
- {1, 0, EISA, 255, 255},
- {1, 0, MCA, 255, 255},
- {2, 0, ISA, 1, PCI},
- {2, 0, EISA, 1, PCI},
- {2, 0, MCA, 1, PCI}
-};
-
-
-/* the bus data */
-static bus_datum *bus_data;
-
-/* the IO INT data, one entry per possible APIC INTerrupt */
-static io_int *io_apic_ints;
-
-static int nintrs;
-
-static int processor_entry(proc_entry_ptr entry, int cpu);
-static int bus_entry(bus_entry_ptr entry, int bus);
-static int io_apic_entry(io_apic_entry_ptr entry, int apic);
-static int int_entry(int_entry_ptr entry, int intr);
-static int lookup_bus_type(char *name);
-
-
-/*
- * 1st pass on motherboard's Intel MP specification table.
- *
- * initializes:
- * mp_ncpus = 1
- *
- * determines:
- * cpu_apic_address (common to all CPUs)
- * io_apic_address[N]
- * mp_naps
- * mp_nbusses
- * mp_napics
- * nintrs
- */
-static void
-mptable_pass1(void)
-{
- int x;
- mpcth_t cth;
- int totalSize;
- void* position;
- int count;
- int type;
- u_int id_mask;
-
- POSTCODE(MPTABLE_PASS1_POST);
-
- /* clear various tables */
- for (x = 0; x < NAPICID; ++x) {
- io_apic_address[x] = ~0; /* IO APIC address table */
- }
-
- /* init everything to empty */
- mp_naps = 0;
- mp_nbusses = 0;
- mp_napics = 0;
- nintrs = 0;
- id_mask = 0;
-
- /* check for use of 'default' configuration */
- if (MPFPS_MPFB1 != 0) {
- /* use default addresses */
- cpu_apic_address = DEFAULT_APIC_BASE;
- io_apic_address[0] = DEFAULT_IO_APIC_BASE;
-
- /* fill in with defaults */
- mp_naps = 2; /* includes BSP */
- mp_maxid = 1;
- mp_nbusses = default_data[MPFPS_MPFB1 - 1][0];
-#if defined(APIC_IO)
- mp_napics = 1;
- nintrs = 16;
-#endif /* APIC_IO */
- }
- else {
- if ((cth = mpfps->pap) == 0)
- panic("MP Configuration Table Header MISSING!");
-
- cpu_apic_address = (vm_offset_t) cth->apic_address;
-
- /* walk the table, recording info of interest */
- totalSize = cth->base_table_length - sizeof(struct MPCTH);
- position = (u_char *) cth + sizeof(struct MPCTH);
- count = cth->entry_count;
-
- while (count--) {
- switch (type = *(u_char *) position) {
- case 0: /* processor_entry */
- if (((proc_entry_ptr)position)->cpu_flags
- & PROCENTRY_FLAG_EN) {
- ++mp_naps;
- mp_maxid++;
- id_mask |= 1 <<
- ((proc_entry_ptr)position)->apic_id;
- }
- break;
- case 1: /* bus_entry */
- ++mp_nbusses;
- break;
- case 2: /* io_apic_entry */
- if (((io_apic_entry_ptr)position)->apic_flags
- & IOAPICENTRY_FLAG_EN)
- io_apic_address[mp_napics++] =
- (vm_offset_t)((io_apic_entry_ptr)
- position)->apic_address;
- break;
- case 3: /* int_entry */
- ++nintrs;
- break;
- case 4: /* int_entry */
- break;
- default:
- panic("mpfps Base Table HOSED!");
- /* NOTREACHED */
- }
-
- totalSize -= basetable_entry_types[type].length;
- (u_char*)position += basetable_entry_types[type].length;
- }
- }
-
- /* qualify the numbers */
- if (mp_naps > MAXCPU) {
- printf("Warning: only using %d of %d available CPUs!\n",
- MAXCPU, mp_naps);
- mp_naps = MAXCPU;
- }
-
- /* See if we need to fixup HT logical CPUs. */
- mptable_hyperthread_fixup(id_mask);
-
- /*
- * Count the BSP.
- * This is also used as a counter while starting the APs.
- */
- mp_ncpus = 1;
-
- --mp_naps; /* subtract the BSP */
-}
-
-
-/*
- * 2nd pass on motherboard's Intel MP specification table.
- *
- * sets:
- * boot_cpu_id
- * ID_TO_IO(N), phy APIC ID to log CPU/IO table
- * CPU_TO_ID(N), logical CPU to APIC ID table
- * IO_TO_ID(N), logical IO to APIC ID table
- * bus_data[N]
- * io_apic_ints[N]
- */
-static int
-mptable_pass2(void)
-{
- struct PROCENTRY proc;
- int x;
- mpcth_t cth;
- int totalSize;
- void* position;
- int count;
- int type;
- int apic, bus, cpu, intr;
- int i, j;
- int pgeflag;
-
- POSTCODE(MPTABLE_PASS2_POST);
-
- /* Initialize fake proc entry for use with HT fixup. */
- bzero(&proc, sizeof(proc));
- proc.type = 0;
- proc.cpu_flags = PROCENTRY_FLAG_EN;
-
- pgeflag = 0; /* XXX - Not used under SMP yet. */
-
- MALLOC(io_apic_versions, u_int32_t *, sizeof(u_int32_t) * mp_napics,
- M_DEVBUF, M_WAITOK);
- MALLOC(ioapic, volatile ioapic_t **, sizeof(ioapic_t *) * mp_napics,
- M_DEVBUF, M_WAITOK);
- MALLOC(io_apic_ints, io_int *, sizeof(io_int) * (nintrs + 1),
- M_DEVBUF, M_WAITOK);
- MALLOC(bus_data, bus_datum *, sizeof(bus_datum) * mp_nbusses,
- M_DEVBUF, M_WAITOK);
-
- bzero(ioapic, sizeof(ioapic_t *) * mp_napics);
-
- for (i = 0; i < mp_napics; i++) {
- for (j = 0; j < mp_napics; j++) {
- /* same page frame as a previous IO apic? */
- if (((vm_offset_t)SMPpt[NPTEPG-2-j] & PG_FRAME) ==
- (io_apic_address[i] & PG_FRAME)) {
- ioapic[i] = (ioapic_t *)((u_int)SMP_prvspace
- + (NPTEPG-2-j) * PAGE_SIZE
- + (io_apic_address[i] & PAGE_MASK));
- break;
- }
- /* use this slot if available */
- if (((vm_offset_t)SMPpt[NPTEPG-2-j] & PG_FRAME) == 0) {
- SMPpt[NPTEPG-2-j] = (pt_entry_t)(PG_V | PG_RW |
- pgeflag | (io_apic_address[i] & PG_FRAME));
- ioapic[i] = (ioapic_t *)((u_int)SMP_prvspace
- + (NPTEPG-2-j) * PAGE_SIZE
- + (io_apic_address[i] & PAGE_MASK));
- break;
- }
- }
- }
-
- /* clear various tables */
- for (x = 0; x < NAPICID; ++x) {
- ID_TO_IO(x) = -1; /* phy APIC ID to log CPU/IO table */
- CPU_TO_ID(x) = -1; /* logical CPU to APIC ID table */
- IO_TO_ID(x) = -1; /* logical IO to APIC ID table */
- }
-
- /* clear bus data table */
- for (x = 0; x < mp_nbusses; ++x)
- bus_data[x].bus_id = 0xff;
-
- /* clear IO APIC INT table */
- for (x = 0; x < (nintrs + 1); ++x) {
- io_apic_ints[x].int_type = 0xff;
- io_apic_ints[x].int_vector = 0xff;
- }
-
- /* setup the cpu/apic mapping arrays */
- boot_cpu_id = -1;
-
- /* record whether PIC or virtual-wire mode */
- picmode = (mpfps->mpfb2 & 0x80) ? 1 : 0;
-
- /* check for use of 'default' configuration */
- if (MPFPS_MPFB1 != 0)
- return MPFPS_MPFB1; /* return default configuration type */
-
- if ((cth = mpfps->pap) == 0)
- panic("MP Configuration Table Header MISSING!");
-
- /* walk the table, recording info of interest */
- totalSize = cth->base_table_length - sizeof(struct MPCTH);
- position = (u_char *) cth + sizeof(struct MPCTH);
- count = cth->entry_count;
- apic = bus = intr = 0;
- cpu = 1; /* pre-count the BSP */
-
- while (count--) {
- switch (type = *(u_char *) position) {
- case 0:
- if (processor_entry(position, cpu)) {
- if (logical_cpus != 0 &&
- cpu % logical_cpus != 0)
- logical_cpus_mask |= (1 << cpu);
- ++cpu;
- }
- if (need_hyperthreading_fixup) {
- /*
- * Create fake mptable processor entries
- * and feed them to processor_entry() to
- * enumerate the logical CPUs.
- */
- proc.apic_id = ((proc_entry_ptr)position)->apic_id;
- for (i = 1; i < logical_cpus; i++) {
- proc.apic_id++;
- (void)processor_entry(&proc, cpu);
- logical_cpus_mask |= (1 << cpu);
- cpu++;
- }
- }
- break;
- case 1:
- if (bus_entry(position, bus))
- ++bus;
- break;
- case 2:
- if (io_apic_entry(position, apic))
- ++apic;
- break;
- case 3:
- if (int_entry(position, intr))
- ++intr;
- break;
- case 4:
- /* int_entry(position); */
- break;
- default:
- panic("mpfps Base Table HOSED!");
- /* NOTREACHED */
- }
-
- totalSize -= basetable_entry_types[type].length;
- (u_char *) position += basetable_entry_types[type].length;
- }
-
- if (boot_cpu_id == -1)
- panic("NO BSP found!");
-
- /* report fact that its NOT a default configuration */
- return 0;
-}
-
-/*
- * Check if we should perform a hyperthreading "fix-up" to
- * enumerate any logical CPU's that aren't already listed
- * in the table.
- *
- * XXX: We assume that all of the physical CPUs in the
- * system have the same number of logical CPUs.
- *
- * XXX: We assume that APIC ID's are allocated such that
- * the APIC ID's for a physical processor are aligned
- * with the number of logical CPU's in the processor.
- */
-static void
-mptable_hyperthread_fixup(u_int id_mask)
-{
- u_int i, id;
-
- /* Nothing to do if there is no HTT support. */
- if ((cpu_feature & CPUID_HTT) == 0)
- return;
- logical_cpus = (cpu_procinfo & CPUID_HTT_CORES) >> 16;
- if (logical_cpus <= 1)
- return;
-
- /*
- * For each APIC ID of a CPU that is set in the mask,
- * scan the other candidate APIC ID's for this
- * physical processor. If any of those ID's are
- * already in the table, then kill the fixup.
- */
- for (id = 0; id <= MAXCPU; id++) {
- if ((id_mask & 1 << id) == 0)
- continue;
- /* First, make sure we are on a logical_cpus boundary. */
- if (id % logical_cpus != 0)
- return;
- for (i = id + 1; i < id + logical_cpus; i++)
- if ((id_mask & 1 << i) != 0)
- return;
- }
-
- /*
- * Ok, the ID's checked out, so enable the fixup. We have to fixup
- * mp_naps and mp_maxid right now.
- */
- need_hyperthreading_fixup = 1;
- mp_maxid *= logical_cpus;
- mp_naps *= logical_cpus;
-}
-
-void
-assign_apic_irq(int apic, int intpin, int irq)
-{
- int x;
-
- if (int_to_apicintpin[irq].ioapic != -1)
- panic("assign_apic_irq: inconsistent table");
-
- int_to_apicintpin[irq].ioapic = apic;
- int_to_apicintpin[irq].int_pin = intpin;
- int_to_apicintpin[irq].apic_address = ioapic[apic];
- int_to_apicintpin[irq].redirindex = IOAPIC_REDTBL + 2 * intpin;
-
- for (x = 0; x < nintrs; x++) {
- if ((io_apic_ints[x].int_type == 0 ||
- io_apic_ints[x].int_type == 3) &&
- io_apic_ints[x].int_vector == 0xff &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(apic) &&
- io_apic_ints[x].dst_apic_int == intpin)
- io_apic_ints[x].int_vector = irq;
- }
-}
-
-void
-revoke_apic_irq(int irq)
-{
- int x;
- int oldapic;
- int oldintpin;
-
- if (int_to_apicintpin[irq].ioapic == -1)
- panic("revoke_apic_irq: inconsistent table");
-
- oldapic = int_to_apicintpin[irq].ioapic;
- oldintpin = int_to_apicintpin[irq].int_pin;
-
- int_to_apicintpin[irq].ioapic = -1;
- int_to_apicintpin[irq].int_pin = 0;
- int_to_apicintpin[irq].apic_address = NULL;
- int_to_apicintpin[irq].redirindex = 0;
-
- for (x = 0; x < nintrs; x++) {
- if ((io_apic_ints[x].int_type == 0 ||
- io_apic_ints[x].int_type == 3) &&
- io_apic_ints[x].int_vector != 0xff &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(oldapic) &&
- io_apic_ints[x].dst_apic_int == oldintpin)
- io_apic_ints[x].int_vector = 0xff;
- }
-}
-
-
-static void
-allocate_apic_irq(int intr)
-{
- int apic;
- int intpin;
- int irq;
-
- if (io_apic_ints[intr].int_vector != 0xff)
- return; /* Interrupt handler already assigned */
-
- if (io_apic_ints[intr].int_type != 0 &&
- (io_apic_ints[intr].int_type != 3 ||
- (io_apic_ints[intr].dst_apic_id == IO_TO_ID(0) &&
- io_apic_ints[intr].dst_apic_int == 0)))
- return; /* Not INT or ExtInt on != (0, 0) */
-
- irq = 0;
- while (irq < APIC_INTMAPSIZE &&
- int_to_apicintpin[irq].ioapic != -1)
- irq++;
-
- if (irq >= APIC_INTMAPSIZE)
- return; /* No free interrupt handlers */
-
- apic = ID_TO_IO(io_apic_ints[intr].dst_apic_id);
- intpin = io_apic_ints[intr].dst_apic_int;
-
- assign_apic_irq(apic, intpin, irq);
- io_apic_setup_intpin(apic, intpin);
-}
-
-
-static void
-swap_apic_id(int apic, int oldid, int newid)
-{
- int x;
- int oapic;
-
-
- if (oldid == newid)
- return; /* Nothing to do */
-
- printf("Changing APIC ID for IO APIC #%d from %d to %d in MP table\n",
- apic, oldid, newid);
-
- /* Swap physical APIC IDs in interrupt entries */
- for (x = 0; x < nintrs; x++) {
- if (io_apic_ints[x].dst_apic_id == oldid)
- io_apic_ints[x].dst_apic_id = newid;
- else if (io_apic_ints[x].dst_apic_id == newid)
- io_apic_ints[x].dst_apic_id = oldid;
- }
-
- /* Swap physical APIC IDs in IO_TO_ID mappings */
- for (oapic = 0; oapic < mp_napics; oapic++)
- if (IO_TO_ID(oapic) == newid)
- break;
-
- if (oapic < mp_napics) {
- printf("Changing APIC ID for IO APIC #%d from "
- "%d to %d in MP table\n",
- oapic, newid, oldid);
- IO_TO_ID(oapic) = oldid;
- }
- IO_TO_ID(apic) = newid;
-}
-
-
-static void
-fix_id_to_io_mapping(void)
-{
- int x;
-
- for (x = 0; x < NAPICID; x++)
- ID_TO_IO(x) = -1;
-
- for (x = 0; x <= mp_naps; x++)
- if (CPU_TO_ID(x) < NAPICID)
- ID_TO_IO(CPU_TO_ID(x)) = x;
-
- for (x = 0; x < mp_napics; x++)
- if (IO_TO_ID(x) < NAPICID)
- ID_TO_IO(IO_TO_ID(x)) = x;
-}
-
-
-static int
-first_free_apic_id(void)
-{
- int freeid, x;
-
- for (freeid = 0; freeid < NAPICID; freeid++) {
- for (x = 0; x <= mp_naps; x++)
- if (CPU_TO_ID(x) == freeid)
- break;
- if (x <= mp_naps)
- continue;
- for (x = 0; x < mp_napics; x++)
- if (IO_TO_ID(x) == freeid)
- break;
- if (x < mp_napics)
- continue;
- return freeid;
- }
- return freeid;
-}
-
-
-static int
-io_apic_id_acceptable(int apic, int id)
-{
- int cpu; /* Logical CPU number */
- int oapic; /* Logical IO APIC number for other IO APIC */
-
- if (id >= NAPICID)
- return 0; /* Out of range */
-
- for (cpu = 0; cpu <= mp_naps; cpu++)
- if (CPU_TO_ID(cpu) == id)
- return 0; /* Conflict with CPU */
-
- for (oapic = 0; oapic < mp_napics && oapic < apic; oapic++)
- if (IO_TO_ID(oapic) == id)
- return 0; /* Conflict with other APIC */
-
- return 1; /* ID is acceptable for IO APIC */
-}
-
-
-/*
- * parse an Intel MP specification table
- */
-static void
-fix_mp_table(void)
-{
- int x;
- int id;
- int bus_0 = 0; /* Stop GCC warning */
- int bus_pci = 0; /* Stop GCC warning */
- int num_pci_bus;
- int apic; /* IO APIC unit number */
- int freeid; /* Free physical APIC ID */
- int physid; /* Current physical IO APIC ID */
-
- /*
- * Fix mis-numbering of the PCI bus and its INT entries if the BIOS
- * did it wrong. The MP spec says that when more than 1 PCI bus
- * exists the BIOS must begin with bus entries for the PCI bus and use
- * actual PCI bus numbering. This implies that when only 1 PCI bus
- * exists the BIOS can choose to ignore this ordering, and indeed many
- * MP motherboards do ignore it. This causes a problem when the PCI
- * sub-system makes requests of the MP sub-system based on PCI bus
- * numbers. So here we look for the situation and renumber the
- * busses and associated INTs in an effort to "make it right".
- */
-
- /* find bus 0, PCI bus, count the number of PCI busses */
- for (num_pci_bus = 0, x = 0; x < mp_nbusses; ++x) {
- if (bus_data[x].bus_id == 0) {
- bus_0 = x;
- }
- if (bus_data[x].bus_type == PCI) {
- ++num_pci_bus;
- bus_pci = x;
- }
- }
- /*
- * bus_0 == slot of bus with ID of 0
- * bus_pci == slot of last PCI bus encountered
- */
-
- /* check the 1 PCI bus case for sanity */
- /* if it is number 0 all is well */
- if (num_pci_bus == 1 &&
- bus_data[bus_pci].bus_id != 0) {
-
- /* mis-numbered, swap with whichever bus uses slot 0 */
-
- /* swap the bus entry types */
- bus_data[bus_pci].bus_type = bus_data[bus_0].bus_type;
- bus_data[bus_0].bus_type = PCI;
-
- /* swap each relavant INTerrupt entry */
- id = bus_data[bus_pci].bus_id;
- for (x = 0; x < nintrs; ++x) {
- if (io_apic_ints[x].src_bus_id == id) {
- io_apic_ints[x].src_bus_id = 0;
- }
- else if (io_apic_ints[x].src_bus_id == 0) {
- io_apic_ints[x].src_bus_id = id;
- }
- }
- }
-
- /* Assign IO APIC IDs.
- *
- * First try the existing ID. If a conflict is detected, try
- * the ID in the MP table. If a conflict is still detected, find
- * a free id.
- *
- * We cannot use the ID_TO_IO table before all conflicts has been
- * resolved and the table has been corrected.
- */
- for (apic = 0; apic < mp_napics; ++apic) { /* For all IO APICs */
-
- /* First try to use the value set by the BIOS */
- physid = io_apic_get_id(apic);
- if (io_apic_id_acceptable(apic, physid)) {
- if (IO_TO_ID(apic) != physid)
- swap_apic_id(apic, IO_TO_ID(apic), physid);
- continue;
- }
-
- /* Then check if the value in the MP table is acceptable */
- if (io_apic_id_acceptable(apic, IO_TO_ID(apic)))
- continue;
-
- /* Last resort, find a free APIC ID and use it */
- freeid = first_free_apic_id();
- if (freeid >= NAPICID)
- panic("No free physical APIC IDs found");
-
- if (io_apic_id_acceptable(apic, freeid)) {
- swap_apic_id(apic, IO_TO_ID(apic), freeid);
- continue;
- }
- panic("Free physical APIC ID not usable");
- }
- fix_id_to_io_mapping();
-
- /* detect and fix broken Compaq MP table */
- if (apic_int_type(0, 0) == -1) {
- printf("APIC_IO: MP table broken: 8259->APIC entry missing!\n");
- io_apic_ints[nintrs].int_type = 3; /* ExtInt */
- io_apic_ints[nintrs].int_vector = 0xff; /* Unassigned */
- /* XXX fixme, set src bus id etc, but it doesn't seem to hurt */
- io_apic_ints[nintrs].dst_apic_id = IO_TO_ID(0);
- io_apic_ints[nintrs].dst_apic_int = 0; /* Pin 0 */
- nintrs++;
- }
-}
-
-
-/* Assign low level interrupt handlers */
-static void
-setup_apic_irq_mapping(void)
-{
- int x;
- int int_vector;
-
- /* Clear array */
- for (x = 0; x < APIC_INTMAPSIZE; x++) {
- int_to_apicintpin[x].ioapic = -1;
- int_to_apicintpin[x].int_pin = 0;
- int_to_apicintpin[x].apic_address = NULL;
- int_to_apicintpin[x].redirindex = 0;
- }
-
- /* First assign ISA/EISA interrupts */
- for (x = 0; x < nintrs; x++) {
- int_vector = io_apic_ints[x].src_bus_irq;
- if (int_vector < APIC_INTMAPSIZE &&
- io_apic_ints[x].int_vector == 0xff &&
- int_to_apicintpin[int_vector].ioapic == -1 &&
- (apic_int_is_bus_type(x, ISA) ||
- apic_int_is_bus_type(x, EISA)) &&
- io_apic_ints[x].int_type == 0) {
- assign_apic_irq(ID_TO_IO(io_apic_ints[x].dst_apic_id),
- io_apic_ints[x].dst_apic_int,
- int_vector);
- }
- }
-
- /* Assign ExtInt entry if no ISA/EISA interrupt 0 entry */
- for (x = 0; x < nintrs; x++) {
- if (io_apic_ints[x].dst_apic_int == 0 &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(0) &&
- io_apic_ints[x].int_vector == 0xff &&
- int_to_apicintpin[0].ioapic == -1 &&
- io_apic_ints[x].int_type == 3) {
- assign_apic_irq(0, 0, 0);
- break;
- }
- }
- /* PCI interrupt assignment is deferred */
-}
-
-
-static int
-processor_entry(proc_entry_ptr entry, int cpu)
-{
- /* check for usability */
- if (!(entry->cpu_flags & PROCENTRY_FLAG_EN))
- return 0;
-
- if(entry->apic_id >= NAPICID)
- panic("CPU APIC ID out of range (0..%d)", NAPICID - 1);
- /* check for BSP flag */
- if (entry->cpu_flags & PROCENTRY_FLAG_BP) {
- boot_cpu_id = entry->apic_id;
- CPU_TO_ID(0) = entry->apic_id;
- ID_TO_CPU(entry->apic_id) = 0;
- return 0; /* its already been counted */
- }
-
- /* add another AP to list, if less than max number of CPUs */
- else if (cpu < MAXCPU) {
- CPU_TO_ID(cpu) = entry->apic_id;
- ID_TO_CPU(entry->apic_id) = cpu;
- return 1;
- }
-
- return 0;
-}
-
-
-static int
-bus_entry(bus_entry_ptr entry, int bus)
-{
- int x;
- char c, name[8];
-
- /* encode the name into an index */
- for (x = 0; x < 6; ++x) {
- if ((c = entry->bus_type[x]) == ' ')
- break;
- name[x] = c;
- }
- name[x] = '\0';
-
- if ((x = lookup_bus_type(name)) == UNKNOWN_BUSTYPE)
- panic("unknown bus type: '%s'", name);
-
- bus_data[bus].bus_id = entry->bus_id;
- bus_data[bus].bus_type = x;
-
- return 1;
-}
-
-
-static int
-io_apic_entry(io_apic_entry_ptr entry, int apic)
-{
- if (!(entry->apic_flags & IOAPICENTRY_FLAG_EN))
- return 0;
-
- IO_TO_ID(apic) = entry->apic_id;
- if (entry->apic_id < NAPICID)
- ID_TO_IO(entry->apic_id) = apic;
-
- return 1;
-}
-
-
-static int
-lookup_bus_type(char *name)
-{
- int x;
-
- for (x = 0; x < MAX_BUSTYPE; ++x)
- if (strcmp(bus_type_table[x].name, name) == 0)
- return bus_type_table[x].type;
-
- return UNKNOWN_BUSTYPE;
-}
-
-
-static int
-int_entry(int_entry_ptr entry, int intr)
-{
- int apic;
-
- io_apic_ints[intr].int_type = entry->int_type;
- io_apic_ints[intr].int_flags = entry->int_flags;
- io_apic_ints[intr].src_bus_id = entry->src_bus_id;
- io_apic_ints[intr].src_bus_irq = entry->src_bus_irq;
- if (entry->dst_apic_id == 255) {
- /* This signal goes to all IO APICS. Select an IO APIC
- with sufficient number of interrupt pins */
- for (apic = 0; apic < mp_napics; apic++)
- if (((io_apic_read(apic, IOAPIC_VER) &
- IOART_VER_MAXREDIR) >> MAXREDIRSHIFT) >=
- entry->dst_apic_int)
- break;
- if (apic < mp_napics)
- io_apic_ints[intr].dst_apic_id = IO_TO_ID(apic);
- else
- io_apic_ints[intr].dst_apic_id = entry->dst_apic_id;
- } else
- io_apic_ints[intr].dst_apic_id = entry->dst_apic_id;
- io_apic_ints[intr].dst_apic_int = entry->dst_apic_int;
-
- return 1;
-}
-
-
-static int
-apic_int_is_bus_type(int intr, int bus_type)
-{
- int bus;
-
- for (bus = 0; bus < mp_nbusses; ++bus)
- if ((bus_data[bus].bus_id == io_apic_ints[intr].src_bus_id)
- && ((int) bus_data[bus].bus_type == bus_type))
- return 1;
-
- return 0;
-}
-
-
-/*
- * Given a traditional ISA INT mask, return an APIC mask.
- */
-u_int
-isa_apic_mask(u_int isa_mask)
-{
- int isa_irq;
- int apic_pin;
-
-#if defined(SKIP_IRQ15_REDIRECT)
- if (isa_mask == (1 << 15)) {
- printf("skipping ISA IRQ15 redirect\n");
- return isa_mask;
- }
-#endif /* SKIP_IRQ15_REDIRECT */
-
- isa_irq = ffs(isa_mask); /* find its bit position */
- if (isa_irq == 0) /* doesn't exist */
- return 0;
- --isa_irq; /* make it zero based */
-
- apic_pin = isa_apic_irq(isa_irq); /* look for APIC connection */
- if (apic_pin == -1)
- return 0;
-
- return (1 << apic_pin); /* convert pin# to a mask */
-}
-
-
-/*
- * Determine which APIC pin an ISA/EISA INT is attached to.
- */
-#define INTTYPE(I) (io_apic_ints[(I)].int_type)
-#define INTPIN(I) (io_apic_ints[(I)].dst_apic_int)
-#define INTIRQ(I) (io_apic_ints[(I)].int_vector)
-#define INTAPIC(I) (ID_TO_IO(io_apic_ints[(I)].dst_apic_id))
-
-#define SRCBUSIRQ(I) (io_apic_ints[(I)].src_bus_irq)
-int
-isa_apic_irq(int isa_irq)
-{
- int intr;
-
- for (intr = 0; intr < nintrs; ++intr) { /* check each record */
- if (INTTYPE(intr) == 0) { /* standard INT */
- if (SRCBUSIRQ(intr) == isa_irq) {
- if (apic_int_is_bus_type(intr, ISA) ||
- apic_int_is_bus_type(intr, EISA)) {
- if (INTIRQ(intr) == 0xff)
- return -1; /* unassigned */
- return INTIRQ(intr); /* found */
- }
- }
- }
- }
- return -1; /* NOT found */
-}
-
-
-/*
- * Determine which APIC pin a PCI INT is attached to.
- */
-#define SRCBUSID(I) (io_apic_ints[(I)].src_bus_id)
-#define SRCBUSDEVICE(I) ((io_apic_ints[(I)].src_bus_irq >> 2) & 0x1f)
-#define SRCBUSLINE(I) (io_apic_ints[(I)].src_bus_irq & 0x03)
-int
-pci_apic_irq(int pciBus, int pciDevice, int pciInt)
-{
- int intr;
-
- --pciInt; /* zero based */
-
- for (intr = 0; intr < nintrs; ++intr) /* check each record */
- if ((INTTYPE(intr) == 0) /* standard INT */
- && (SRCBUSID(intr) == pciBus)
- && (SRCBUSDEVICE(intr) == pciDevice)
- && (SRCBUSLINE(intr) == pciInt)) /* a candidate IRQ */
- if (apic_int_is_bus_type(intr, PCI)) {
- if (INTIRQ(intr) == 0xff)
- allocate_apic_irq(intr);
- if (INTIRQ(intr) == 0xff)
- return -1; /* unassigned */
- return INTIRQ(intr); /* exact match */
- }
-
- return -1; /* NOT found */
-}
-
-int
-next_apic_irq(int irq)
-{
- int intr, ointr;
- int bus, bustype;
-
- bus = 0;
- bustype = 0;
- for (intr = 0; intr < nintrs; intr++) {
- if (INTIRQ(intr) != irq || INTTYPE(intr) != 0)
- continue;
- bus = SRCBUSID(intr);
- bustype = apic_bus_type(bus);
- if (bustype != ISA &&
- bustype != EISA &&
- bustype != PCI)
- continue;
- break;
- }
- if (intr >= nintrs) {
- return -1;
- }
- for (ointr = intr + 1; ointr < nintrs; ointr++) {
- if (INTTYPE(ointr) != 0)
- continue;
- if (bus != SRCBUSID(ointr))
- continue;
- if (bustype == PCI) {
- if (SRCBUSDEVICE(intr) != SRCBUSDEVICE(ointr))
- continue;
- if (SRCBUSLINE(intr) != SRCBUSLINE(ointr))
- continue;
- }
- if (bustype == ISA || bustype == EISA) {
- if (SRCBUSIRQ(intr) != SRCBUSIRQ(ointr))
- continue;
- }
- if (INTPIN(intr) == INTPIN(ointr))
- continue;
- break;
- }
- if (ointr >= nintrs) {
- return -1;
- }
- return INTIRQ(ointr);
-}
-#undef SRCBUSLINE
-#undef SRCBUSDEVICE
-#undef SRCBUSID
-#undef SRCBUSIRQ
-
-#undef INTPIN
-#undef INTIRQ
-#undef INTAPIC
-#undef INTTYPE
-
-
-/*
- * Reprogram the MB chipset to NOT redirect an ISA INTerrupt.
- *
- * XXX FIXME:
- * Exactly what this means is unclear at this point. It is a solution
- * for motherboards that redirect the MBIRQ0 pin. Generically a motherboard
- * could route any of the ISA INTs to upper (>15) IRQ values. But most would
- * NOT be redirected via MBIRQ0, thus "undirect()ing" them would NOT be an
- * option.
- */
-int
-undirect_isa_irq(int rirq)
-{
-#if defined(READY)
- if (bootverbose)
- printf("Freeing redirected ISA irq %d.\n", rirq);
- /** FIXME: tickle the MB redirector chip */
- return -1;
-#else
- if (bootverbose)
- printf("Freeing (NOT implemented) redirected ISA irq %d.\n", rirq);
- return 0;
-#endif /* READY */
-}
-
-
-/*
- * Reprogram the MB chipset to NOT redirect a PCI INTerrupt
- */
-int
-undirect_pci_irq(int rirq)
-{
-#if defined(READY)
- if (bootverbose)
- printf("Freeing redirected PCI irq %d.\n", rirq);
-
- /** FIXME: tickle the MB redirector chip */
- return -1;
-#else
- if (bootverbose)
- printf("Freeing (NOT implemented) redirected PCI irq %d.\n",
- rirq);
- return 0;
-#endif /* READY */
-}
-
-
-/*
- * given a bus ID, return:
- * the bus type if found
- * -1 if NOT found
- */
-int
-apic_bus_type(int id)
-{
- int x;
-
- for (x = 0; x < mp_nbusses; ++x)
- if (bus_data[x].bus_id == id)
- return bus_data[x].bus_type;
-
- return -1;
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated src bus ID if found
- * -1 if NOT found
- */
-int
-apic_src_bus_id(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].src_bus_id);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated src bus IRQ if found
- * -1 if NOT found
- */
-int
-apic_src_bus_irq(int apic, int pin)
-{
- int x;
-
- for (x = 0; x < nintrs; x++)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].src_bus_irq);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated INTerrupt type if found
- * -1 if NOT found
- */
-int
-apic_int_type(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].int_type);
-
- return -1; /* NOT found */
-}
-
-int
-apic_irq(int apic, int pin)
-{
- int x;
- int res;
-
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int)) {
- res = io_apic_ints[x].int_vector;
- if (res == 0xff)
- return -1;
- if (apic != int_to_apicintpin[res].ioapic)
- panic("apic_irq: inconsistent table");
- if (pin != int_to_apicintpin[res].int_pin)
- panic("apic_irq inconsistent table (2)");
- return res;
- }
- return -1;
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated trigger mode if found
- * -1 if NOT found
- */
-int
-apic_trigger(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return ((io_apic_ints[x].int_flags >> 2) & 0x03);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated 'active' level if found
- * -1 if NOT found
- */
-int
-apic_polarity(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].int_flags & 0x03);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * set data according to MP defaults
- * FIXME: probably not complete yet...
- */
-static void
-default_mp_table(int type)
-{
- int ap_cpu_id;
-#if defined(APIC_IO)
- int io_apic_id;
- int pin;
-#endif /* APIC_IO */
-
-#if 0
- printf(" MP default config type: %d\n", type);
- switch (type) {
- case 1:
- printf(" bus: ISA, APIC: 82489DX\n");
- break;
- case 2:
- printf(" bus: EISA, APIC: 82489DX\n");
- break;
- case 3:
- printf(" bus: EISA, APIC: 82489DX\n");
- break;
- case 4:
- printf(" bus: MCA, APIC: 82489DX\n");
- break;
- case 5:
- printf(" bus: ISA+PCI, APIC: Integrated\n");
- break;
- case 6:
- printf(" bus: EISA+PCI, APIC: Integrated\n");
- break;
- case 7:
- printf(" bus: MCA+PCI, APIC: Integrated\n");
- break;
- default:
- printf(" future type\n");
- break;
- /* NOTREACHED */
- }
-#endif /* 0 */
-
- boot_cpu_id = (lapic.id & APIC_ID_MASK) >> 24;
- ap_cpu_id = (boot_cpu_id == 0) ? 1 : 0;
-
- /* BSP */
- CPU_TO_ID(0) = boot_cpu_id;
- ID_TO_CPU(boot_cpu_id) = 0;
-
- /* one and only AP */
- CPU_TO_ID(1) = ap_cpu_id;
- ID_TO_CPU(ap_cpu_id) = 1;
-
-#if defined(APIC_IO)
- /* one and only IO APIC */
- io_apic_id = (io_apic_read(0, IOAPIC_ID) & APIC_ID_MASK) >> 24;
-
- /*
- * sanity check, refer to MP spec section 3.6.6, last paragraph
- * necessary as some hardware isn't properly setting up the IO APIC
- */
-#if defined(REALLY_ANAL_IOAPICID_VALUE)
- if (io_apic_id != 2) {
-#else
- if ((io_apic_id == 0) || (io_apic_id == 1) || (io_apic_id == 15)) {
-#endif /* REALLY_ANAL_IOAPICID_VALUE */
- io_apic_set_id(0, 2);
- io_apic_id = 2;
- }
- IO_TO_ID(0) = io_apic_id;
- ID_TO_IO(io_apic_id) = 0;
-#endif /* APIC_IO */
-
- /* fill out bus entries */
- switch (type) {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- bus_data[0].bus_id = default_data[type - 1][1];
- bus_data[0].bus_type = default_data[type - 1][2];
- bus_data[1].bus_id = default_data[type - 1][3];
- bus_data[1].bus_type = default_data[type - 1][4];
- break;
-
- /* case 4: case 7: MCA NOT supported */
- default: /* illegal/reserved */
- panic("BAD default MP config: %d", type);
- /* NOTREACHED */
- }
-
-#if defined(APIC_IO)
- /* general cases from MP v1.4, table 5-2 */
- for (pin = 0; pin < 16; ++pin) {
- io_apic_ints[pin].int_type = 0;
- io_apic_ints[pin].int_flags = 0x05; /* edge/active-hi */
- io_apic_ints[pin].src_bus_id = 0;
- io_apic_ints[pin].src_bus_irq = pin; /* IRQ2 caught below */
- io_apic_ints[pin].dst_apic_id = io_apic_id;
- io_apic_ints[pin].dst_apic_int = pin; /* 1-to-1 */
- }
-
- /* special cases from MP v1.4, table 5-2 */
- if (type == 2) {
- io_apic_ints[2].int_type = 0xff; /* N/C */
- io_apic_ints[13].int_type = 0xff; /* N/C */
-#if !defined(APIC_MIXED_MODE)
- /** FIXME: ??? */
- panic("sorry, can't support type 2 default yet");
-#endif /* APIC_MIXED_MODE */
- }
- else
- io_apic_ints[2].src_bus_irq = 0; /* ISA IRQ0 is on APIC INT 2 */
-
- if (type == 7)
- io_apic_ints[0].int_type = 0xff; /* N/C */
- else
- io_apic_ints[0].int_type = 3; /* vectored 8259 */
-#endif /* APIC_IO */
-}
-
-
-/*
- * start each AP in our list
- */
-static int
-start_all_aps(u_int boot_addr)
-{
- int x, i, pg;
-#ifndef PC98
- u_char mpbiosreason;
-#endif
- u_long mpbioswarmvec;
- struct pcpu *pc;
- char *stack;
- uintptr_t kptbase;
-
- POSTCODE(START_ALL_APS_POST);
-
- mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN);
-
- /* initialize BSP's local APIC */
- apic_initialize();
- bsp_apic_ready = 1;
-
- /* install the AP 1st level boot code */
- install_ap_tramp(boot_addr);
-
-
- /* save the current value of the warm-start vector */
- mpbioswarmvec = *((u_long *) WARMBOOT_OFF);
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- mpbiosreason = inb(CMOS_DATA);
-#endif
-
- /* set up temporary P==V mapping for AP boot */
- /* XXX this is a hack, we should boot the AP on its own stack/PTD */
- kptbase = (uintptr_t)(void *)KPTphys;
- for (x = 0; x < NKPT; x++)
- PTD[x] = (pd_entry_t)(PG_V | PG_RW |
- ((kptbase + x * PAGE_SIZE) & PG_FRAME));
- invltlb();
-
- /* start each AP */
- for (x = 1; x <= mp_naps; ++x) {
-
- /* This is a bit verbose, it will go away soon. */
-
- /* first page of AP's private space */
- pg = x * i386_btop(sizeof(struct privatespace));
-
- /* allocate a new private data page */
- pc = (struct pcpu *)kmem_alloc(kernel_map, PAGE_SIZE);
-
- /* wire it into the private page table page */
- SMPpt[pg] = (pt_entry_t)(PG_V | PG_RW | vtophys(pc));
-
- /* allocate and set up an idle stack data page */
- stack = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE); /* XXXKSE */
- for (i = 0; i < KSTACK_PAGES; i++)
- SMPpt[pg + 1 + i] = (pt_entry_t)
- (PG_V | PG_RW | vtophys(PAGE_SIZE * i + stack));
-
- /* prime data page for it to use */
- pcpu_init(pc, x, sizeof(struct pcpu));
-
- /* setup a vector to our boot code */
- *((volatile u_short *) WARMBOOT_OFF) = WARMBOOT_TARGET;
- *((volatile u_short *) WARMBOOT_SEG) = (boot_addr >> 4);
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- outb(CMOS_DATA, BIOS_WARM); /* 'warm-start' */
-#endif
-
- bootSTK = &SMP_prvspace[x].idlekstack[KSTACK_PAGES * PAGE_SIZE];
- bootAP = x;
-
- /* attempt to start the Application Processor */
- CHECK_INIT(99); /* setup checkpoints */
- if (!start_ap(x, boot_addr)) {
- printf("AP #%d (PHY# %d) failed!\n", x, CPU_TO_ID(x));
- CHECK_PRINT("trace"); /* show checkpoints */
- /* better panic as the AP may be running loose */
- printf("panic y/n? [y] ");
- if (cngetc() != 'n')
- panic("bye-bye");
- }
- CHECK_PRINT("trace"); /* show checkpoints */
-
- /* record its version info */
- cpu_apic_versions[x] = cpu_apic_versions[0];
-
- all_cpus |= (1 << x); /* record AP in CPU map */
- }
-
- /* build our map of 'other' CPUs */
- PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
-
- /* fill in our (BSP) APIC version */
- cpu_apic_versions[0] = lapic.version;
-
- /* restore the warmstart vector */
- *(u_long *) WARMBOOT_OFF = mpbioswarmvec;
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- outb(CMOS_DATA, mpbiosreason);
-#endif
-
- /*
- * Set up the idle context for the BSP. Similar to above except
- * that some was done by locore, some by pmap.c and some is implicit
- * because the BSP is cpu#0 and the page is initially zero, and also
- * because we can refer to variables by name on the BSP..
- */
-
- /* Allocate and setup BSP idle stack */
- stack = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE);
- for (i = 0; i < KSTACK_PAGES; i++)
- SMPpt[1 + i] = (pt_entry_t)
- (PG_V | PG_RW | vtophys(PAGE_SIZE * i + stack));
-
- for (x = 0; x < NKPT; x++)
- PTD[x] = 0;
- pmap_set_opt();
-
- /* number of APs actually started */
- return mp_ncpus - 1;
-}
-
-
-/*
- * load the 1st level AP boot code into base memory.
- */
-
-/* targets for relocation */
-extern void bigJump(void);
-extern void bootCodeSeg(void);
-extern void bootDataSeg(void);
-extern void MPentry(void);
-extern u_int MP_GDT;
-extern u_int mp_gdtbase;
-
-static void
-install_ap_tramp(u_int boot_addr)
-{
- int x;
- int size = *(int *) ((u_long) & bootMP_size);
- u_char *src = (u_char *) ((u_long) bootMP);
- u_char *dst = (u_char *) boot_addr + KERNBASE;
- u_int boot_base = (u_int) bootMP;
- u_int8_t *dst8;
- u_int16_t *dst16;
- u_int32_t *dst32;
-
- POSTCODE(INSTALL_AP_TRAMP_POST);
-
- for (x = 0; x < size; ++x)
- *dst++ = *src++;
-
- /*
- * modify addresses in code we just moved to basemem. unfortunately we
- * need fairly detailed info about mpboot.s for this to work. changes
- * to mpboot.s might require changes here.
- */
-
- /* boot code is located in KERNEL space */
- dst = (u_char *) boot_addr + KERNBASE;
-
- /* modify the lgdt arg */
- dst32 = (u_int32_t *) (dst + ((u_int) & mp_gdtbase - boot_base));
- *dst32 = boot_addr + ((u_int) & MP_GDT - boot_base);
-
- /* modify the ljmp target for MPentry() */
- dst32 = (u_int32_t *) (dst + ((u_int) bigJump - boot_base) + 1);
- *dst32 = ((u_int) MPentry - KERNBASE);
-
- /* modify the target for boot code segment */
- dst16 = (u_int16_t *) (dst + ((u_int) bootCodeSeg - boot_base));
- dst8 = (u_int8_t *) (dst16 + 1);
- *dst16 = (u_int) boot_addr & 0xffff;
- *dst8 = ((u_int) boot_addr >> 16) & 0xff;
-
- /* modify the target for boot data segment */
- dst16 = (u_int16_t *) (dst + ((u_int) bootDataSeg - boot_base));
- dst8 = (u_int8_t *) (dst16 + 1);
- *dst16 = (u_int) boot_addr & 0xffff;
- *dst8 = ((u_int) boot_addr >> 16) & 0xff;
-}
-
-
-/*
- * this function starts the AP (application processor) identified
- * by the APIC ID 'physicalCpu'. It does quite a "song and dance"
- * to accomplish this. This is necessary because of the nuances
- * of the different hardware we might encounter. It ain't pretty,
- * but it seems to work.
- */
-static int
-start_ap(int logical_cpu, u_int boot_addr)
-{
- int physical_cpu;
- int vector;
- int cpus;
- u_long icr_lo, icr_hi;
-
- POSTCODE(START_AP_POST);
-
- /* get the PHYSICAL APIC ID# */
- physical_cpu = CPU_TO_ID(logical_cpu);
-
- /* calculate the vector */
- vector = (boot_addr >> 12) & 0xff;
-
- /* used as a watchpoint to signal AP startup */
- cpus = mp_ncpus;
-
- /*
- * first we do an INIT/RESET IPI this INIT IPI might be run, reseting
- * and running the target CPU. OR this INIT IPI might be latched (P5
- * bug), CPU waiting for STARTUP IPI. OR this INIT IPI might be
- * ignored.
- */
-
- /* setup the address for the target AP */
- icr_hi = lapic.icr_hi & ~APIC_ID_MASK;
- icr_hi |= (physical_cpu << 24);
- lapic.icr_hi = icr_hi;
-
- /* do an INIT IPI: assert RESET */
- icr_lo = lapic.icr_lo & 0xfff00000;
- lapic.icr_lo = icr_lo | 0x0000c500;
-
- /* wait for pending status end */
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
-
- /* do an INIT IPI: deassert RESET */
- lapic.icr_lo = icr_lo | 0x00008500;
-
- /* wait for pending status end */
- u_sleep(10000); /* wait ~10mS */
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
-
- /*
- * next we do a STARTUP IPI: the previous INIT IPI might still be
- * latched, (P5 bug) this 1st STARTUP would then terminate
- * immediately, and the previously started INIT IPI would continue. OR
- * the previous INIT IPI has already run. and this STARTUP IPI will
- * run. OR the previous INIT IPI was ignored. and this STARTUP IPI
- * will run.
- */
-
- /* do a STARTUP IPI */
- lapic.icr_lo = icr_lo | 0x00000600 | vector;
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
- u_sleep(200); /* wait ~200uS */
-
- /*
- * finally we do a 2nd STARTUP IPI: this 2nd STARTUP IPI should run IF
- * the previous STARTUP IPI was cancelled by a latched INIT IPI. OR
- * this STARTUP IPI will be ignored, as only ONE STARTUP IPI is
- * recognized after hardware RESET or INIT IPI.
- */
-
- lapic.icr_lo = icr_lo | 0x00000600 | vector;
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
- u_sleep(200); /* wait ~200uS */
-
- /* wait for it to start */
- set_apic_timer(5000000);/* == 5 seconds */
- while (read_apic_timer())
- if (mp_ncpus > cpus)
- return 1; /* return SUCCESS */
-
- return 0; /* return FAILURE */
-}
-
-#if defined(APIC_IO)
-
-#ifdef COUNT_XINVLTLB_HITS
-u_int xhits_gbl[MAXCPU];
-u_int xhits_pg[MAXCPU];
-u_int xhits_rng[MAXCPU];
-SYSCTL_NODE(_debug, OID_AUTO, xhits, CTLFLAG_RW, 0, "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, global, CTLFLAG_RW, &xhits_gbl,
- sizeof(xhits_gbl), "IU", "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, page, CTLFLAG_RW, &xhits_pg,
- sizeof(xhits_pg), "IU", "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, range, CTLFLAG_RW, &xhits_rng,
- sizeof(xhits_rng), "IU", "");
-
-u_int ipi_global;
-u_int ipi_page;
-u_int ipi_range;
-u_int ipi_range_size;
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_global, CTLFLAG_RW, &ipi_global, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_page, CTLFLAG_RW, &ipi_page, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range, CTLFLAG_RW, &ipi_range, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range_size, CTLFLAG_RW, &ipi_range_size,
- 0, "");
-
-u_int ipi_masked_global;
-u_int ipi_masked_page;
-u_int ipi_masked_range;
-u_int ipi_masked_range_size;
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_global, CTLFLAG_RW,
- &ipi_masked_global, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_page, CTLFLAG_RW,
- &ipi_masked_page, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range, CTLFLAG_RW,
- &ipi_masked_range, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range_size, CTLFLAG_RW,
- &ipi_masked_range_size, 0, "");
-#endif
-
-/*
- * Flush the TLB on all other CPU's
- */
-static void
-smp_tlb_shootdown(u_int vector, vm_offset_t addr1, vm_offset_t addr2)
-{
- u_int ncpu;
- register_t eflags;
-
- ncpu = mp_ncpus - 1; /* does not shootdown self */
- if (ncpu < 1)
- return; /* no other cpus */
- eflags = read_eflags();
- if ((eflags & PSL_I) == 0)
- panic("absolutely cannot call smp_ipi_shootdown with interrupts already disabled");
- mtx_lock_spin(&smp_tlb_mtx);
- smp_tlb_addr1 = addr1;
- smp_tlb_addr2 = addr2;
- atomic_store_rel_int(&smp_tlb_wait, 0);
- ipi_all_but_self(vector);
- while (smp_tlb_wait < ncpu)
- ia32_pause();
- mtx_unlock_spin(&smp_tlb_mtx);
-}
-
-/*
- * This is about as magic as it gets. fortune(1) has got similar code
- * for reversing bits in a word. Who thinks up this stuff??
- *
- * Yes, it does appear to be consistently faster than:
- * while (i = ffs(m)) {
- * m >>= i;
- * bits++;
- * }
- * and
- * while (lsb = (m & -m)) { // This is magic too
- * m &= ~lsb; // or: m ^= lsb
- * bits++;
- * }
- * Both of these latter forms do some very strange things on gcc-3.1 with
- * -mcpu=pentiumpro and/or -march=pentiumpro and/or -O or -O2.
- * There is probably an SSE or MMX popcnt instruction.
- *
- * I wonder if this should be in libkern?
- *
- * XXX Stop the presses! Another one:
- * static __inline u_int32_t
- * popcnt1(u_int32_t v)
- * {
- * v -= ((v >> 1) & 0x55555555);
- * v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
- * v = (v + (v >> 4)) & 0x0F0F0F0F;
- * return (v * 0x01010101) >> 24;
- * }
- * The downside is that it has a multiply. With a pentium3 with
- * -mcpu=pentiumpro and -march=pentiumpro then gcc-3.1 will use
- * an imull, and in that case it is faster. In most other cases
- * it appears slightly slower.
- */
-static __inline u_int32_t
-popcnt(u_int32_t m)
-{
-
- m = (m & 0x55555555) + ((m & 0xaaaaaaaa) >> 1);
- m = (m & 0x33333333) + ((m & 0xcccccccc) >> 2);
- m = (m & 0x0f0f0f0f) + ((m & 0xf0f0f0f0) >> 4);
- m = (m & 0x00ff00ff) + ((m & 0xff00ff00) >> 8);
- m = (m & 0x0000ffff) + ((m & 0xffff0000) >> 16);
- return m;
-}
-
-static void
-smp_targeted_tlb_shootdown(u_int mask, u_int vector, vm_offset_t addr1, vm_offset_t addr2)
-{
- int ncpu, othercpus;
- register_t eflags;
-
- othercpus = mp_ncpus - 1;
- if (mask == (u_int)-1) {
- ncpu = othercpus;
- if (ncpu < 1)
- return;
- } else {
- /* XXX there should be a pcpu self mask */
- mask &= ~(1 << PCPU_GET(cpuid));
- if (mask == 0)
- return;
- ncpu = popcnt(mask);
- if (ncpu > othercpus) {
- /* XXX this should be a panic offence */
- printf("SMP: tlb shootdown to %d other cpus (only have %d)\n",
- ncpu, othercpus);
- ncpu = othercpus;
- }
- /* XXX should be a panic, implied by mask == 0 above */
- if (ncpu < 1)
- return;
- }
- eflags = read_eflags();
- if ((eflags & PSL_I) == 0)
- panic("absolutely cannot call smp_targeted_ipi_shootdown with interrupts already disabled");
- mtx_lock_spin(&smp_tlb_mtx);
- smp_tlb_addr1 = addr1;
- smp_tlb_addr2 = addr2;
- atomic_store_rel_int(&smp_tlb_wait, 0);
- if (mask == (u_int)-1)
- ipi_all_but_self(vector);
- else
- ipi_selected(mask, vector);
- while (smp_tlb_wait < ncpu)
- ia32_pause();
- mtx_unlock_spin(&smp_tlb_mtx);
-}
-#endif
-
-void
-smp_invltlb(void)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLTLB, 0, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_global++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_invlpg(vm_offset_t addr)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLPG, addr, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_page++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_invlpg_range(vm_offset_t addr1, vm_offset_t addr2)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLRNG, addr1, addr2);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_range++;
- ipi_range_size += (addr2 - addr1) / PAGE_SIZE;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invltlb(u_int mask)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLTLB, 0, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_global++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invlpg(u_int mask, vm_offset_t addr)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLPG, addr, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_page++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invlpg_range(u_int mask, vm_offset_t addr1, vm_offset_t addr2)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLRNG, addr1, addr2);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_range++;
- ipi_masked_range_size += (addr2 - addr1) / PAGE_SIZE;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-
-/*
- * This is called once the rest of the system is up and running and we're
- * ready to let the AP's out of the pen.
- */
-void
-ap_init(void)
-{
- u_int apic_id;
-
- /* spin until all the AP's are ready */
- while (!aps_ready)
- ia32_pause();
-
- /* BSP may have changed PTD while we were waiting */
- invltlb();
-
-#if defined(I586_CPU) && !defined(NO_F00F_HACK)
- lidt(&r_idt);
-#endif
-
- /* set up CPU registers and state */
- cpu_setregs();
-
- /* set up FPU state on the AP */
- npxinit(__INITIAL_NPXCW__);
-
- /* set up SSE registers */
- enable_sse();
-
- /* A quick check from sanity claus */
- apic_id = (apic_id_to_logical[(lapic.id & 0x0f000000) >> 24]);
- if (PCPU_GET(cpuid) != apic_id) {
- printf("SMP: cpuid = %d\n", PCPU_GET(cpuid));
- printf("SMP: apic_id = %d\n", apic_id);
- printf("PTD[MPPTDI] = %#jx\n", (uintmax_t)PTD[MPPTDI]);
- panic("cpuid mismatch! boom!!");
- }
-
- /* Init local apic for irq's */
- apic_initialize();
-
- /* Set memory range attributes for this CPU to match the BSP */
- mem_range_AP_init();
-
- mtx_lock_spin(&ap_boot_mtx);
-
- smp_cpus++;
-
- CTR1(KTR_SMP, "SMP: AP CPU #%d Launched", PCPU_GET(cpuid));
- printf("SMP: AP CPU #%d Launched!\n", PCPU_GET(cpuid));
-
- /* Build our map of 'other' CPUs. */
- PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
-
- if (bootverbose)
- apic_dump("ap_init()");
-
- if (smp_cpus == mp_ncpus) {
- /* enable IPI's, tlb shootdown, freezes etc */
- atomic_store_rel_int(&smp_started, 1);
- smp_active = 1; /* historic */
- }
-
- mtx_unlock_spin(&ap_boot_mtx);
-
- /* wait until all the AP's are up */
- while (smp_started == 0)
- ia32_pause();
-
- /* ok, now grab sched_lock and enter the scheduler */
- mtx_lock_spin(&sched_lock);
-
- binuptime(PCPU_PTR(switchtime));
- PCPU_SET(switchticks, ticks);
-
- cpu_throw(NULL, choosethread()); /* doesn't return */
-
- panic("scheduler returned us to %s", __func__);
-}
-
-/*
- * For statclock, we send an IPI to all CPU's to have them call this
- * function.
- *
- * WARNING! unpend() will call statclock() directly and skip this
- * routine.
- */
-void
-forwarded_statclock(struct clockframe frame)
-{
-
- if (profprocs != 0)
- profclock(&frame);
- if (pscnt == psdiv)
- statclock(&frame);
-}
-
-void
-forward_statclock(void)
-{
- int map;
-
- CTR0(KTR_SMP, "forward_statclock");
-
- if (!smp_started || cold || panicstr)
- return;
-
- map = PCPU_GET(other_cpus) & ~stopped_cpus ;
- if (map != 0)
- ipi_selected(map, IPI_STATCLOCK);
-}
-
-/*
- * For each hardclock(), we send an IPI to all other CPU's to have them
- * execute this function. It would be nice to reduce contention on
- * sched_lock if we could simply peek at the CPU to determine the user/kernel
- * state and call hardclock_process() on the CPU receiving the clock interrupt
- * and then just use a simple IPI to handle any ast's if needed.
- *
- * WARNING! unpend() will call hardclock_process() directly and skip this
- * routine.
- */
-void
-forwarded_hardclock(struct clockframe frame)
-{
-
- hardclock_process(&frame);
-}
-
-void
-forward_hardclock(void)
-{
- u_int map;
-
- CTR0(KTR_SMP, "forward_hardclock");
-
- if (!smp_started || cold || panicstr)
- return;
-
- map = PCPU_GET(other_cpus) & ~stopped_cpus ;
- if (map != 0)
- ipi_selected(map, IPI_HARDCLOCK);
-}
-
-#ifdef APIC_INTR_REORDER
-/*
- * Maintain mapping from softintr vector to isr bit in local apic.
- */
-void
-set_lapic_isrloc(int intr, int vector)
-{
- if (intr < 0 || intr > 32)
- panic("set_apic_isrloc: bad intr argument: %d",intr);
- if (vector < ICU_OFFSET || vector > 255)
- panic("set_apic_isrloc: bad vector argument: %d",vector);
- apic_isrbit_location[intr].location = &lapic.isr0 + ((vector>>5)<<2);
- apic_isrbit_location[intr].bit = (1<<(vector & 31));
-}
-#endif
-
-/*
- * send an IPI to a set of cpus.
- */
-void
-ipi_selected(u_int32_t cpus, u_int ipi)
-{
-
- CTR3(KTR_SMP, "%s: cpus: %x ipi: %x", __func__, cpus, ipi);
- selected_apic_ipi(cpus, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI INTerrupt containing 'vector' to all CPUs, including myself
- */
-void
-ipi_all(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_ALLISELF, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI to all CPUs EXCEPT myself
- */
-void
-ipi_all_but_self(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_ALLESELF, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI to myself
- */
-void
-ipi_self(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_SELF, ipi, APIC_DELMODE_FIXED);
-}
-
-static void
-release_aps(void *dummy __unused)
-{
-
- if (mp_ncpus == 1)
- return;
- mtx_lock_spin(&sched_lock);
- atomic_store_rel_int(&aps_ready, 1);
- while (smp_started == 0)
- ia32_pause();
- mtx_unlock_spin(&sched_lock);
-}
-
-SYSINIT(start_aps, SI_SUB_SMP, SI_ORDER_FIRST, release_aps, NULL);
-
-static int hlt_cpus_mask;
-static int hlt_logical_cpus = 1;
-static struct sysctl_ctx_list logical_cpu_clist;
-
-static int
-sysctl_hlt_cpus(SYSCTL_HANDLER_ARGS)
-{
- u_int mask;
- int error;
-
- mask = hlt_cpus_mask;
- error = sysctl_handle_int(oidp, &mask, 0, req);
- if (error || !req->newptr)
- return (error);
-
- if (logical_cpus_mask != 0 &&
- (mask & logical_cpus_mask) == logical_cpus_mask)
- hlt_logical_cpus = 1;
- else
- hlt_logical_cpus = 0;
-
- if ((mask & all_cpus) == all_cpus)
- mask &= ~(1<<0);
- hlt_cpus_mask = mask;
- return (error);
-}
-SYSCTL_PROC(_machdep, OID_AUTO, hlt_cpus, CTLTYPE_INT|CTLFLAG_RW,
- 0, 0, sysctl_hlt_cpus, "IU", "");
-
-static int
-sysctl_hlt_logical_cpus(SYSCTL_HANDLER_ARGS)
-{
- int disable, error;
-
- disable = hlt_logical_cpus;
- error = sysctl_handle_int(oidp, &disable, 0, req);
- if (error || !req->newptr)
- return (error);
-
- if (disable)
- hlt_cpus_mask |= logical_cpus_mask;
- else
- hlt_cpus_mask &= ~logical_cpus_mask;
-
- if ((hlt_cpus_mask & all_cpus) == all_cpus)
- hlt_cpus_mask &= ~(1<<0);
-
- hlt_logical_cpus = disable;
- return (error);
-}
-
-static void
-cpu_hlt_setup(void *dummy __unused)
-{
-
- if (logical_cpus_mask != 0) {
- TUNABLE_INT_FETCH("machdep.hlt_logical_cpus",
- &hlt_logical_cpus);
- sysctl_ctx_init(&logical_cpu_clist);
- SYSCTL_ADD_PROC(&logical_cpu_clist,
- SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
- "hlt_logical_cpus", CTLTYPE_INT|CTLFLAG_RW, 0, 0,
- sysctl_hlt_logical_cpus, "IU", "");
- SYSCTL_ADD_UINT(&logical_cpu_clist,
- SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
- "logical_cpus_mask", CTLTYPE_INT|CTLFLAG_RD,
- &logical_cpus_mask, 0, "");
-
- if (hlt_logical_cpus)
- hlt_cpus_mask |= logical_cpus_mask;
- }
-}
-SYSINIT(cpu_hlt, SI_SUB_SMP, SI_ORDER_ANY, cpu_hlt_setup, NULL);
-
-int
-mp_grab_cpu_hlt(void)
-{
- u_int mask = PCPU_GET(cpumask);
- int retval;
-
- retval = mask & hlt_cpus_mask;
- while (mask & hlt_cpus_mask)
- __asm __volatile("sti; hlt" : : : "memory");
- return (retval);
-}
diff --git a/sys/i386/include/apicreg.h b/sys/i386/include/apicreg.h
deleted file mode 100644
index e72ffb16063d..000000000000
--- a/sys/i386/include/apicreg.h
+++ /dev/null
@@ -1,444 +0,0 @@
-/*
- * Copyright (c) 1996, by Peter Wemm and 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_APIC_H_
-#define _MACHINE_APIC_H_
-
-/*
- * Local && I/O APIC definitions.
- */
-
-/*
- * Pentium P54C+ Build-in APIC
- * (Advanced programmable Interrupt Controller)
- *
- * Base Address of Build-in APIC in memory location
- * is 0xfee00000.
- *
- * Map of APIC REgisters:
- *
- * Offset (hex) Description Read/Write state
- * 000 Reserved
- * 010 Reserved
- * 020 ID Local APIC ID R/W
- * 030 VER Local APIC Version R
- * 040 Reserved
- * 050 Reserved
- * 060 Reserved
- * 070 Reserved
- * 080 Task Priority Register R/W
- * 090 Arbitration Priority Register R
- * 0A0 Processor Priority Register R
- * 0B0 EOI Register W
- * 0C0 RRR Remote read R
- * 0D0 Logical Destination R/W
- * 0E0 Destination Format Register 0..27 R; 28..31 R/W
- * 0F0 SVR Spurious Interrupt Vector Reg. 0..3 R; 4..9 R/W
- * 100 ISR 000-031 R
- * 110 ISR 032-063 R
- * 120 ISR 064-095 R
- * 130 ISR 095-128 R
- * 140 ISR 128-159 R
- * 150 ISR 160-191 R
- * 160 ISR 192-223 R
- * 170 ISR 224-255 R
- * 180 TMR 000-031 R
- * 190 TMR 032-063 R
- * 1A0 TMR 064-095 R
- * 1B0 TMR 095-128 R
- * 1C0 TMR 128-159 R
- * 1D0 TMR 160-191 R
- * 1E0 TMR 192-223 R
- * 1F0 TMR 224-255 R
- * 200 IRR 000-031 R
- * 210 IRR 032-063 R
- * 220 IRR 064-095 R
- * 230 IRR 095-128 R
- * 240 IRR 128-159 R
- * 250 IRR 160-191 R
- * 260 IRR 192-223 R
- * 270 IRR 224-255 R
- * 280 Error Status Register R
- * 290 Reserved
- * 2A0 Reserved
- * 2B0 Reserved
- * 2C0 Reserved
- * 2D0 Reserved
- * 2E0 Reserved
- * 2F0 Reserved
- * 300 ICR_LOW Interrupt Command Reg. (0-31) R/W
- * 310 ICR_HI Interrupt Command Reg. (32-63) R/W
- * 320 Local Vector Table (Timer) R/W
- * 330 Reserved
- * 340 Reserved
- * 350 LVT1 Local Vector Table (LINT0) R/W
- * 360 LVT2 Local Vector Table (LINT1) R/W
- * 370 LVT3 Local Vector Table (ERROR) R/W
- * 380 Initial Count Reg. for Timer R/W
- * 390 Current Count of Timer R
- * 3A0 Reserved
- * 3B0 Reserved
- * 3C0 Reserved
- * 3D0 Reserved
- * 3E0 Timer Divide Configuration Reg. R/W
- * 3F0 Reserved
- */
-
-
-/******************************************************************************
- * global defines, etc.
- */
-
-
-/******************************************************************************
- * LOCAL APIC structure
- */
-
-#ifndef LOCORE
-#include <sys/types.h>
-
-#define PAD3 int : 32; int : 32; int : 32
-#define PAD4 int : 32; int : 32; int : 32; int : 32
-
-struct LAPIC {
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- u_int32_t id; PAD3;
- u_int32_t version; PAD3;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- u_int32_t tpr; PAD3;
- u_int32_t apr; PAD3;
- u_int32_t ppr; PAD3;
- u_int32_t eoi; PAD3;
- /* reserved */ PAD4;
- u_int32_t ldr; PAD3;
- u_int32_t dfr; PAD3;
- u_int32_t svr; PAD3;
- u_int32_t isr0; PAD3;
- u_int32_t isr1; PAD3;
- u_int32_t isr2; PAD3;
- u_int32_t isr3; PAD3;
- u_int32_t isr4; PAD3;
- u_int32_t isr5; PAD3;
- u_int32_t isr6; PAD3;
- u_int32_t isr7; PAD3;
- u_int32_t tmr0; PAD3;
- u_int32_t tmr1; PAD3;
- u_int32_t tmr2; PAD3;
- u_int32_t tmr3; PAD3;
- u_int32_t tmr4; PAD3;
- u_int32_t tmr5; PAD3;
- u_int32_t tmr6; PAD3;
- u_int32_t tmr7; PAD3;
- u_int32_t irr0; PAD3;
- u_int32_t irr1; PAD3;
- u_int32_t irr2; PAD3;
- u_int32_t irr3; PAD3;
- u_int32_t irr4; PAD3;
- u_int32_t irr5; PAD3;
- u_int32_t irr6; PAD3;
- u_int32_t irr7; PAD3;
- u_int32_t esr; PAD3;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- u_int32_t icr_lo; PAD3;
- u_int32_t icr_hi; PAD3;
- u_int32_t lvt_timer; PAD3;
- /* reserved */ PAD4;
- u_int32_t lvt_pcint; PAD3;
- u_int32_t lvt_lint0; PAD3;
- u_int32_t lvt_lint1; PAD3;
- u_int32_t lvt_error; PAD3;
- u_int32_t icr_timer; PAD3;
- u_int32_t ccr_timer; PAD3;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- /* reserved */ PAD4;
- u_int32_t dcr_timer; PAD3;
- /* reserved */ PAD4;
-};
-
-typedef struct LAPIC lapic_t;
-
-/******************************************************************************
- * I/O APIC structure
- */
-
-struct IOAPIC {
- u_int32_t ioregsel; PAD3;
- u_int32_t iowin; PAD3;
-};
-
-typedef struct IOAPIC ioapic_t;
-
-#undef PAD4
-#undef PAD3
-
-#endif /* !LOCORE */
-
-
-/******************************************************************************
- * various code 'logical' values
- */
-
-/******************************************************************************
- * LOCAL APIC defines
- */
-
-/* default physical locations of LOCAL (CPU) APICs */
-#define DEFAULT_APIC_BASE 0xfee00000
-
-/* fields in VER */
-#define APIC_VER_VERSION 0x000000ff
-#define APIC_VER_MAXLVT 0x00ff0000
-#define MAXLVTSHIFT 16
-
-/* fields in SVR */
-#define APIC_SVR_VECTOR 0x000000ff
-#define APIC_SVR_VEC_PROG 0x000000f0
-#define APIC_SVR_VEC_FIX 0x0000000f
-#define APIC_SVR_ENABLE 0x00000100
-# define APIC_SVR_SWDIS 0x00000000
-# define APIC_SVR_SWEN 0x00000100
-#define APIC_SVR_FOCUS 0x00000200
-# define APIC_SVR_FEN 0x00000000
-# define APIC_SVR_FDIS 0x00000200
-
-/* fields in TPR */
-#define APIC_TPR_PRIO 0x000000ff
-# define APIC_TPR_INT 0x000000f0
-# define APIC_TPR_SUB 0x0000000f
-
-
-/* fields in ICR_LOW */
-#define APIC_VECTOR_MASK 0x000000ff
-
-#define APIC_DELMODE_MASK 0x00000700
-# define APIC_DELMODE_FIXED 0x00000000
-# define APIC_DELMODE_LOWPRIO 0x00000100
-# define APIC_DELMODE_SMI 0x00000200
-# define APIC_DELMODE_RR 0x00000300
-# define APIC_DELMODE_NMI 0x00000400
-# define APIC_DELMODE_INIT 0x00000500
-# define APIC_DELMODE_STARTUP 0x00000600
-# define APIC_DELMODE_RESV 0x00000700
-
-#define APIC_DESTMODE_MASK 0x00000800
-# define APIC_DESTMODE_PHY 0x00000000
-# define APIC_DESTMODE_LOG 0x00000800
-
-#define APIC_DELSTAT_MASK 0x00001000
-# define APIC_DELSTAT_IDLE 0x00000000
-# define APIC_DELSTAT_PEND 0x00001000
-
-#define APIC_RESV1_MASK 0x00002000
-
-#define APIC_LEVEL_MASK 0x00004000
-# define APIC_LEVEL_DEASSERT 0x00000000
-# define APIC_LEVEL_ASSERT 0x00004000
-
-#define APIC_TRIGMOD_MASK 0x00008000
-# define APIC_TRIGMOD_EDGE 0x00000000
-# define APIC_TRIGMOD_LEVEL 0x00008000
-
-#define APIC_RRSTAT_MASK 0x00030000
-# define APIC_RRSTAT_INVALID 0x00000000
-# define APIC_RRSTAT_INPROG 0x00010000
-# define APIC_RRSTAT_VALID 0x00020000
-# define APIC_RRSTAT_RESV 0x00030000
-
-#define APIC_DEST_MASK 0x000c0000
-# define APIC_DEST_DESTFLD 0x00000000
-# define APIC_DEST_SELF 0x00040000
-# define APIC_DEST_ALLISELF 0x00080000
-# define APIC_DEST_ALLESELF 0x000c0000
-
-#define APIC_RESV2_MASK 0xfff00000
-
-
-/* fields in ICR_HIGH */
-#define APIC_ID_MASK 0xff000000
-
-
-/* fields in LVT1/2 */
-#define APIC_LVT_VECTOR 0x000000ff
-#define APIC_LVT_DM 0x00000700
-# define APIC_LVT_DM_FIXED 0x00000000
-# define APIC_LVT_DM_NMI 0x00000400
-# define APIC_LVT_DM_EXTINT 0x00000700
-#define APIC_LVT_DS 0x00001000
-#define APIC_LVT_IIPP 0x00002000
-#define APIC_LVT_IIPP_INTALO 0x00002000
-#define APIC_LVT_IIPP_INTAHI 0x00000000
-#define APIC_LVT_RIRR 0x00004000
-#define APIC_LVT_TM 0x00008000
-#define APIC_LVT_M 0x00010000
-
-
-/* fields in LVT Timer */
-#define APIC_LVTT_VECTOR 0x000000ff
-#define APIC_LVTT_DS 0x00001000
-#define APIC_LVTT_M 0x00010000
-#define APIC_LVTT_TM 0x00020000
-
-
-/* fields in TDCR */
-#define APIC_TDCR_2 0x00
-#define APIC_TDCR_4 0x01
-#define APIC_TDCR_8 0x02
-#define APIC_TDCR_16 0x03
-#define APIC_TDCR_32 0x08
-#define APIC_TDCR_64 0x09
-#define APIC_TDCR_128 0x0a
-#define APIC_TDCR_1 0x0b
-
-
-/*
- * fields in IRR
- * ISA INTerrupts are in bits 16-31 of the 1st IRR register.
- * these masks DON'T EQUAL the isa IRQs of the same name.
- */
-#define APIC_IRQ0 0x00000001
-#define APIC_IRQ1 0x00000002
-#define APIC_IRQ2 0x00000004
-#define APIC_IRQ3 0x00000008
-#define APIC_IRQ4 0x00000010
-#define APIC_IRQ5 0x00000020
-#define APIC_IRQ6 0x00000040
-#define APIC_IRQ7 0x00000080
-#define APIC_IRQ8 0x00000100
-#define APIC_IRQ9 0x00000200
-#define APIC_IRQ10 0x00000400
-#define APIC_IRQ11 0x00000800
-#define APIC_IRQ12 0x00001000
-#define APIC_IRQ13 0x00002000
-#define APIC_IRQ14 0x00004000
-#define APIC_IRQ15 0x00008000
-#define APIC_IRQ16 0x00010000
-#define APIC_IRQ17 0x00020000
-#define APIC_IRQ18 0x00040000
-#define APIC_IRQ19 0x00080000
-#define APIC_IRQ20 0x00100000
-#define APIC_IRQ21 0x00200000
-#define APIC_IRQ22 0x00400000
-#define APIC_IRQ23 0x00800000
-
-
-/******************************************************************************
- * I/O APIC defines
- */
-
-/* default physical locations of an IO APIC */
-#define DEFAULT_IO_APIC_BASE 0xfec00000
-
-/* window register offset */
-#define IOAPIC_WINDOW 0x10
-
-/* indexes into IO APIC */
-#define IOAPIC_ID 0x00
-#define IOAPIC_VER 0x01
-#define IOAPIC_ARB 0x02
-#define IOAPIC_REDTBL 0x10
-#define IOAPIC_REDTBL0 IOAPIC_REDTBL
-#define IOAPIC_REDTBL1 (IOAPIC_REDTBL+0x02)
-#define IOAPIC_REDTBL2 (IOAPIC_REDTBL+0x04)
-#define IOAPIC_REDTBL3 (IOAPIC_REDTBL+0x06)
-#define IOAPIC_REDTBL4 (IOAPIC_REDTBL+0x08)
-#define IOAPIC_REDTBL5 (IOAPIC_REDTBL+0x0a)
-#define IOAPIC_REDTBL6 (IOAPIC_REDTBL+0x0c)
-#define IOAPIC_REDTBL7 (IOAPIC_REDTBL+0x0e)
-#define IOAPIC_REDTBL8 (IOAPIC_REDTBL+0x10)
-#define IOAPIC_REDTBL9 (IOAPIC_REDTBL+0x12)
-#define IOAPIC_REDTBL10 (IOAPIC_REDTBL+0x14)
-#define IOAPIC_REDTBL11 (IOAPIC_REDTBL+0x16)
-#define IOAPIC_REDTBL12 (IOAPIC_REDTBL+0x18)
-#define IOAPIC_REDTBL13 (IOAPIC_REDTBL+0x1a)
-#define IOAPIC_REDTBL14 (IOAPIC_REDTBL+0x1c)
-#define IOAPIC_REDTBL15 (IOAPIC_REDTBL+0x1e)
-#define IOAPIC_REDTBL16 (IOAPIC_REDTBL+0x20)
-#define IOAPIC_REDTBL17 (IOAPIC_REDTBL+0x22)
-#define IOAPIC_REDTBL18 (IOAPIC_REDTBL+0x24)
-#define IOAPIC_REDTBL19 (IOAPIC_REDTBL+0x26)
-#define IOAPIC_REDTBL20 (IOAPIC_REDTBL+0x28)
-#define IOAPIC_REDTBL21 (IOAPIC_REDTBL+0x2a)
-#define IOAPIC_REDTBL22 (IOAPIC_REDTBL+0x2c)
-#define IOAPIC_REDTBL23 (IOAPIC_REDTBL+0x2e)
-
-/* fields in VER */
-#define IOART_VER_VERSION 0x000000ff
-#define IOART_VER_MAXREDIR 0x00ff0000
-#define MAXREDIRSHIFT 16
-
-/*
- * fields in the IO APIC's redirection table entries
- */
-#define IOART_DEST APIC_ID_MASK /* broadcast addr: all APICs */
-
-#define IOART_RESV 0x00fe0000 /* reserved */
-
-#define IOART_INTMASK 0x00010000 /* R/W: INTerrupt mask */
-# define IOART_INTMCLR 0x00000000 /* clear, allow INTs */
-# define IOART_INTMSET 0x00010000 /* set, inhibit INTs */
-
-#define IOART_TRGRMOD 0x00008000 /* R/W: trigger mode */
-# define IOART_TRGREDG 0x00000000 /* edge */
-# define IOART_TRGRLVL 0x00008000 /* level */
-
-#define IOART_REM_IRR 0x00004000 /* RO: remote IRR */
-
-#define IOART_INTPOL 0x00002000 /* R/W: INT input pin polarity */
-# define IOART_INTAHI 0x00000000 /* active high */
-# define IOART_INTALO 0x00002000 /* active low */
-
-#define IOART_DELIVS 0x00001000 /* RO: delivery status */
-
-#define IOART_DESTMOD 0x00000800 /* R/W: destination mode */
-# define IOART_DESTPHY 0x00000000 /* physical */
-# define IOART_DESTLOG 0x00000800 /* logical */
-
-#define IOART_DELMOD 0x00000700 /* R/W: delivery mode */
-# define IOART_DELFIXED 0x00000000 /* fixed */
-# define IOART_DELLOPRI 0x00000100 /* lowest priority */
-# define IOART_DELSMI 0x00000200 /* System Management INT */
-# define IOART_DELRSV1 0x00000300 /* reserved */
-# define IOART_DELNMI 0x00000400 /* NMI signal */
-# define IOART_DELINIT 0x00000500 /* INIT signal */
-# define IOART_DELRSV2 0x00000600 /* reserved */
-# define IOART_DELEXINT 0x00000700 /* External INTerrupt */
-
-#define IOART_INTVEC 0x000000ff /* R/W: INTerrupt vector field */
-
-#endif /* _MACHINE_APIC_H_ */
diff --git a/sys/i386/include/mptable.h b/sys/i386/include/mptable.h
deleted file mode 100644
index d630bd583aa4..000000000000
--- a/sys/i386/include/mptable.h
+++ /dev/null
@@ -1,2839 +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$
- */
-
-#include "opt_cpu.h"
-#include "opt_kstack_pages.h"
-#include "opt_swtch.h"
-
-#ifdef SMP
-#include <machine/smptests.h>
-#else
-#error
-#endif
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/cons.h> /* cngetc() */
-#ifdef GPROF
-#include <sys/gmon.h>
-#endif
-#include <sys/kernel.h>
-#include <sys/ktr.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/memrange.h>
-#include <sys/mutex.h>
-#include <sys/pcpu.h>
-#include <sys/proc.h>
-#include <sys/smp.h>
-#include <sys/sysctl.h>
-#include <sys/user.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_extern.h>
-#include <vm/vm_map.h>
-
-#include <machine/apic.h>
-#include <machine/atomic.h>
-#include <machine/clock.h>
-#include <machine/cpu.h>
-#include <machine/cpufunc.h>
-#include <machine/mpapic.h>
-#include <machine/psl.h>
-#include <machine/segments.h>
-#include <machine/smp.h>
-#include <machine/smptests.h> /** TEST_DEFAULT_CONFIG, TEST_TEST1 */
-#include <machine/tss.h>
-#include <machine/specialreg.h>
-#include <machine/privatespace.h>
-
-#if defined(APIC_IO)
-#include <machine/md_var.h> /* setidt() */
-#include <i386/isa/icu.h> /* IPIs */
-#include <i386/isa/intr_machdep.h> /* IPIs */
-#endif /* APIC_IO */
-
-#if defined(TEST_DEFAULT_CONFIG)
-#define MPFPS_MPFB1 TEST_DEFAULT_CONFIG
-#else
-#define MPFPS_MPFB1 mpfps->mpfb1
-#endif /* TEST_DEFAULT_CONFIG */
-
-#define WARMBOOT_TARGET 0
-#define WARMBOOT_OFF (KERNBASE + 0x0467)
-#define WARMBOOT_SEG (KERNBASE + 0x0469)
-
-#ifdef PC98
-#define BIOS_BASE (0xe8000)
-#define BIOS_SIZE (0x18000)
-#else
-#define BIOS_BASE (0xf0000)
-#define BIOS_SIZE (0x10000)
-#endif
-#define BIOS_COUNT (BIOS_SIZE/4)
-
-#define CMOS_REG (0x70)
-#define CMOS_DATA (0x71)
-#define BIOS_RESET (0x0f)
-#define BIOS_WARM (0x0a)
-
-#define PROCENTRY_FLAG_EN 0x01
-#define PROCENTRY_FLAG_BP 0x02
-#define IOAPICENTRY_FLAG_EN 0x01
-
-
-/* MP Floating Pointer Structure */
-typedef struct MPFPS {
- char signature[4];
- void *pap;
- u_char length;
- u_char spec_rev;
- u_char checksum;
- u_char mpfb1;
- u_char mpfb2;
- u_char mpfb3;
- u_char mpfb4;
- u_char mpfb5;
-} *mpfps_t;
-
-/* 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];
- void *oem_table_pointer;
- u_short oem_table_size;
- u_short entry_count;
- void *apic_address;
- u_short extended_table_length;
- u_char extended_table_checksum;
- u_char reserved;
-} *mpcth_t;
-
-
-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;
-
-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;
- void *apic_address;
-} *io_apic_entry_ptr;
-
-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;
-
-/* descriptions of MP basetable entries */
-typedef struct BASETABLE_ENTRY {
- u_char type;
- u_char length;
- char name[16];
-} basetable_entry;
-
-/*
- * this code MUST be enabled here and in mpboot.s.
- * it follows the very early stages of AP boot by placing values in CMOS ram.
- * it NORMALLY will never be needed and thus the primitive method for enabling.
- *
-#define CHECK_POINTS
- */
-
-#if defined(CHECK_POINTS) && !defined(PC98)
-#define CHECK_READ(A) (outb(CMOS_REG, (A)), inb(CMOS_DATA))
-#define CHECK_WRITE(A,D) (outb(CMOS_REG, (A)), outb(CMOS_DATA, (D)))
-
-#define CHECK_INIT(D); \
- CHECK_WRITE(0x34, (D)); \
- CHECK_WRITE(0x35, (D)); \
- CHECK_WRITE(0x36, (D)); \
- CHECK_WRITE(0x37, (D)); \
- CHECK_WRITE(0x38, (D)); \
- CHECK_WRITE(0x39, (D));
-
-#define CHECK_PRINT(S); \
- printf("%s: %d, %d, %d, %d, %d, %d\n", \
- (S), \
- CHECK_READ(0x34), \
- CHECK_READ(0x35), \
- CHECK_READ(0x36), \
- CHECK_READ(0x37), \
- CHECK_READ(0x38), \
- CHECK_READ(0x39));
-
-#else /* CHECK_POINTS */
-
-#define CHECK_INIT(D)
-#define CHECK_PRINT(S)
-
-#endif /* CHECK_POINTS */
-
-/*
- * Values to send to the POST hardware.
- */
-#define MP_BOOTADDRESS_POST 0x10
-#define MP_PROBE_POST 0x11
-#define MPTABLE_PASS1_POST 0x12
-
-#define MP_START_POST 0x13
-#define MP_ENABLE_POST 0x14
-#define MPTABLE_PASS2_POST 0x15
-
-#define START_ALL_APS_POST 0x16
-#define INSTALL_AP_TRAMP_POST 0x17
-#define START_AP_POST 0x18
-
-#define MP_ANNOUNCE_POST 0x19
-
-static int need_hyperthreading_fixup;
-static u_int logical_cpus;
-static u_int logical_cpus_mask;
-
-/* used to hold the AP's until we are ready to release them */
-static struct mtx ap_boot_mtx;
-
-/** XXX FIXME: where does this really belong, isa.h/isa.c perhaps? */
-int current_postcode;
-
-/** XXX FIXME: what system files declare these??? */
-extern struct region_descriptor r_gdt, r_idt;
-
-int bsp_apic_ready = 0; /* flags useability of BSP apic */
-int mp_naps; /* # of Applications processors */
-int mp_nbusses; /* # of busses */
-int mp_napics; /* # of IO APICs */
-int boot_cpu_id; /* designated BSP */
-vm_offset_t cpu_apic_address;
-vm_offset_t io_apic_address[NAPICID]; /* NAPICID is more than enough */
-extern int nkpt;
-
-u_int32_t cpu_apic_versions[MAXCPU];
-u_int32_t *io_apic_versions;
-
-#ifdef APIC_INTR_REORDER
-struct {
- volatile int *location;
- int bit;
-} apic_isrbit_location[32];
-#endif
-
-struct apic_intmapinfo int_to_apicintpin[APIC_INTMAPSIZE];
-
-/*
- * APIC ID logical/physical mapping structures.
- * We oversize these to simplify boot-time config.
- */
-int cpu_num_to_apic_id[NAPICID];
-int io_num_to_apic_id[NAPICID];
-int apic_id_to_logical[NAPICID];
-
-
-/* AP uses this during bootstrap. Do not staticize. */
-char *bootSTK;
-static int bootAP;
-
-/* Hotwire a 0->4MB V==P mapping */
-extern pt_entry_t *KPTphys;
-
-/* SMP page table page */
-extern pt_entry_t *SMPpt;
-
-struct pcb stoppcbs[MAXCPU];
-
-#ifdef APIC_IO
-/* Variables needed for SMP tlb shootdown. */
-vm_offset_t smp_tlb_addr1;
-vm_offset_t smp_tlb_addr2;
-volatile int smp_tlb_wait;
-static struct mtx smp_tlb_mtx;
-#endif
-
-/*
- * Local data and functions.
- */
-
-/* Set to 1 once we're ready to let the APs out of the pen. */
-static volatile int aps_ready = 0;
-
-static int mp_capable;
-static u_int boot_address;
-static u_int base_memory;
-
-static int picmode; /* 0: virtual wire mode, 1: PIC mode */
-static mpfps_t mpfps;
-static int search_for_sig(u_int32_t target, int count);
-static void mp_enable(u_int boot_addr);
-
-static void mptable_hyperthread_fixup(u_int id_mask);
-static void mptable_pass1(void);
-static int mptable_pass2(void);
-static void default_mp_table(int type);
-static void fix_mp_table(void);
-static void setup_apic_irq_mapping(void);
-static void init_locks(void);
-static int start_all_aps(u_int boot_addr);
-static void install_ap_tramp(u_int boot_addr);
-static int start_ap(int logicalCpu, u_int boot_addr);
-void ap_init(void);
-static int apic_int_is_bus_type(int intr, int bus_type);
-static void release_aps(void *dummy);
-
-/*
- * initialize all the SMP locks
- */
-
-/* lock region used by kernel profiling */
-int mcount_lock;
-
-#ifdef USE_COMLOCK
-/* locks com (tty) data/hardware accesses: a FASTINTR() */
-struct mtx com_mtx;
-#endif /* USE_COMLOCK */
-
-static void
-init_locks(void)
-{
-
-#ifdef USE_COMLOCK
- mtx_init(&com_mtx, "com", NULL, MTX_SPIN);
-#endif /* USE_COMLOCK */
-#ifdef APIC_IO
- mtx_init(&smp_tlb_mtx, "tlb", NULL, MTX_SPIN);
-#endif
-}
-
-/*
- * Calculate usable address in base memory for AP trampoline code.
- */
-u_int
-mp_bootaddress(u_int basemem)
-{
- POSTCODE(MP_BOOTADDRESS_POST);
-
- base_memory = basemem * 1024; /* convert to bytes */
-
- boot_address = base_memory & ~0xfff; /* round down to 4k boundary */
- if ((base_memory - boot_address) < bootMP_size)
- boot_address -= 4096; /* not enough, lower by 4k */
-
- return boot_address;
-}
-
-
-/*
- * Look for an Intel MP spec table (ie, SMP capable hardware).
- */
-void
-i386_mp_probe(void)
-{
- int x;
- u_long segment;
- u_int32_t target;
-
- POSTCODE(MP_PROBE_POST);
-
- /* see if EBDA exists */
- if ((segment = (u_long) * (u_short *) (KERNBASE + 0x40e)) != 0) {
- /* search first 1K of EBDA */
- target = (u_int32_t) (segment << 4);
- if ((x = search_for_sig(target, 1024 / 4)) >= 0)
- goto found;
- } else {
- /* last 1K of base memory, effective 'top of base' passed in */
- target = (u_int32_t) (base_memory - 0x400);
- if ((x = search_for_sig(target, 1024 / 4)) >= 0)
- goto found;
- }
-
- /* search the BIOS */
- target = (u_int32_t) BIOS_BASE;
- if ((x = search_for_sig(target, BIOS_COUNT)) >= 0)
- goto found;
-
- /* nothing found */
- mpfps = (mpfps_t)0;
- mp_capable = 0;
- return;
-
-found:
- /* calculate needed resources */
- mpfps = (mpfps_t)x;
- mptable_pass1();
-
- /* flag fact that we are running multiple processors */
- mp_capable = 1;
-}
-
-int
-cpu_mp_probe(void)
-{
- /*
- * Record BSP in CPU map
- * This is done here so that MBUF init code works correctly.
- */
- all_cpus = 1;
-
- return (mp_capable);
-}
-
-/*
- * Initialize the SMP hardware and the APIC and start up the AP's.
- */
-void
-cpu_mp_start(void)
-{
- POSTCODE(MP_START_POST);
-
- /* look for MP capable motherboard */
- if (mp_capable)
- mp_enable(boot_address);
- else
- panic("MP hardware not found!");
-
- cpu_setregs();
-}
-
-
-/*
- * Print various information about the SMP system hardware and setup.
- */
-void
-cpu_mp_announce(void)
-{
- int x;
-
- POSTCODE(MP_ANNOUNCE_POST);
-
- printf(" cpu0 (BSP): apic id: %2d", CPU_TO_ID(0));
- printf(", version: 0x%08x", cpu_apic_versions[0]);
- printf(", at 0x%08x\n", cpu_apic_address);
- for (x = 1; x <= mp_naps; ++x) {
- printf(" cpu%d (AP): apic id: %2d", x, CPU_TO_ID(x));
- printf(", version: 0x%08x", cpu_apic_versions[x]);
- printf(", at 0x%08x\n", cpu_apic_address);
- }
-
-#if defined(APIC_IO)
- for (x = 0; x < mp_napics; ++x) {
- printf(" io%d (APIC): apic id: %2d", x, IO_TO_ID(x));
- printf(", version: 0x%08x", io_apic_versions[x]);
- printf(", at 0x%08x\n", io_apic_address[x]);
- }
-#else
- printf(" Warning: APIC I/O disabled\n");
-#endif /* APIC_IO */
-}
-
-/*
- * AP cpu's call this to sync up protected mode.
- */
-void
-init_secondary(void)
-{
- int gsel_tss;
- int x, myid = bootAP;
- u_int cr0;
-
- gdt_segs[GPRIV_SEL].ssd_base = (int) &SMP_prvspace[myid];
- gdt_segs[GPROC0_SEL].ssd_base =
- (int) &SMP_prvspace[myid].pcpu.pc_common_tss;
- SMP_prvspace[myid].pcpu.pc_prvspace =
- &SMP_prvspace[myid].pcpu;
-
- for (x = 0; x < NGDT; x++) {
- ssdtosd(&gdt_segs[x], &gdt[myid * NGDT + x].sd);
- }
-
- r_gdt.rd_limit = NGDT * sizeof(gdt[0]) - 1;
- r_gdt.rd_base = (int) &gdt[myid * NGDT];
- lgdt(&r_gdt); /* does magic intra-segment return */
-
- lidt(&r_idt);
-
- lldt(_default_ldt);
- PCPU_SET(currentldt, _default_ldt);
-
- gsel_tss = GSEL(GPROC0_SEL, SEL_KPL);
- gdt[myid * NGDT + GPROC0_SEL].sd.sd_type = SDT_SYS386TSS;
- PCPU_SET(common_tss.tss_esp0, 0); /* not used until after switch */
- PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL));
- PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16);
- PCPU_SET(tss_gdt, &gdt[myid * NGDT + GPROC0_SEL].sd);
- PCPU_SET(common_tssd, *PCPU_GET(tss_gdt));
- ltr(gsel_tss);
-
- /*
- * Set to a known state:
- * Set by mpboot.s: CR0_PG, CR0_PE
- * Set by cpu_setregs: CR0_NE, CR0_MP, CR0_TS, CR0_WP, CR0_AM
- */
- cr0 = rcr0();
- cr0 &= ~(CR0_CD | CR0_NW | CR0_EM);
- load_cr0(cr0);
-
- pmap_set_opt();
-}
-
-
-#if defined(APIC_IO)
-/*
- * Final configuration of the BSP's local APIC:
- * - disable 'pic mode'.
- * - disable 'virtual wire mode'.
- * - enable NMI.
- */
-void
-bsp_apic_configure(void)
-{
- u_char byte;
- u_int32_t temp;
-
- /* leave 'pic mode' if necessary */
- if (picmode) {
- outb(0x22, 0x70); /* select IMCR */
- byte = inb(0x23); /* current contents */
- byte |= 0x01; /* mask external INTR */
- outb(0x23, byte); /* disconnect 8259s/NMI */
- }
-
- /* mask lint0 (the 8259 'virtual wire' connection) */
- temp = lapic.lvt_lint0;
- temp |= APIC_LVT_M; /* set the mask */
- lapic.lvt_lint0 = temp;
-
- /* setup lint1 to handle NMI */
- temp = lapic.lvt_lint1;
- temp &= ~APIC_LVT_M; /* clear the mask */
- lapic.lvt_lint1 = temp;
-
- if (bootverbose)
- apic_dump("bsp_apic_configure()");
-}
-#endif /* APIC_IO */
-
-
-/*******************************************************************
- * local functions and data
- */
-
-/*
- * start the SMP system
- */
-static void
-mp_enable(u_int boot_addr)
-{
- int x;
-#if defined(APIC_IO)
- int apic;
- u_int ux;
-#endif /* APIC_IO */
-
- POSTCODE(MP_ENABLE_POST);
-
- /* turn on 4MB of V == P addressing so we can get to MP table */
- *(int *)PTD = PG_V | PG_RW | ((uintptr_t)(void *)KPTphys & PG_FRAME);
- invltlb();
-
- /* examine the MP table for needed info, uses physical addresses */
- x = mptable_pass2();
-
- *(int *)PTD = 0;
- invltlb();
-
- /* can't process default configs till the CPU APIC is pmapped */
- if (x)
- default_mp_table(x);
-
- /* post scan cleanup */
- fix_mp_table();
- setup_apic_irq_mapping();
-
-#if defined(APIC_IO)
-
- /* fill the LOGICAL io_apic_versions table */
- for (apic = 0; apic < mp_napics; ++apic) {
- ux = io_apic_read(apic, IOAPIC_VER);
- io_apic_versions[apic] = ux;
- io_apic_set_id(apic, IO_TO_ID(apic));
- }
-
- /* program each IO APIC in the system */
- for (apic = 0; apic < mp_napics; ++apic)
- if (io_apic_setup(apic) < 0)
- panic("IO APIC setup failure");
-
- /* install a 'Spurious INTerrupt' vector */
- setidt(XSPURIOUSINT_OFFSET, Xspuriousint,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for TLB invalidation */
- setidt(XINVLTLB_OFFSET, Xinvltlb,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- setidt(XINVLPG_OFFSET, Xinvlpg,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- setidt(XINVLRNG_OFFSET, Xinvlrng,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forwarding hardclock() */
- setidt(XHARDCLOCK_OFFSET, Xhardclock,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forwarding statclock() */
- setidt(XSTATCLOCK_OFFSET, Xstatclock,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
-#ifdef LAZY_SWITCH
- /* install an inter-CPU IPI for lazy pmap release */
- setidt(XLAZYPMAP_OFFSET, Xlazypmap,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif
-
- /* install an inter-CPU IPI for all-CPU rendezvous */
- setidt(XRENDEZVOUS_OFFSET, Xrendezvous,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for forcing an additional software trap */
- setidt(XCPUAST_OFFSET, Xcpuast,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
- /* install an inter-CPU IPI for CPU stop/restart */
- setidt(XCPUSTOP_OFFSET, Xcpustop,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-
-#if defined(TEST_TEST1)
- /* install a "fake hardware INTerrupt" vector */
- setidt(XTEST1_OFFSET, Xtest1,
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif /** TEST_TEST1 */
-
-#endif /* APIC_IO */
-
- /* initialize all SMP locks */
- init_locks();
-
- /* start each Application Processor */
- start_all_aps(boot_addr);
-}
-
-
-/*
- * look for the MP spec signature
- */
-
-/* string defined by the Intel MP Spec as identifying the MP table */
-#define MP_SIG 0x5f504d5f /* _MP_ */
-#define NEXT(X) ((X) += 4)
-static int
-search_for_sig(u_int32_t target, int count)
-{
- int x;
- u_int32_t *addr = (u_int32_t *) (KERNBASE + target);
-
- for (x = 0; x < count; NEXT(x))
- if (addr[x] == MP_SIG)
- /* make array index a byte index */
- return (target + (x * sizeof(u_int32_t)));
-
- return -1;
-}
-
-
-static basetable_entry basetable_entry_types[] =
-{
- {0, 20, "Processor"},
- {1, 8, "Bus"},
- {2, 8, "I/O APIC"},
- {3, 8, "I/O INT"},
- {4, 8, "Local INT"}
-};
-
-typedef struct BUSDATA {
- u_char bus_id;
- enum busTypes bus_type;
-} bus_datum;
-
-typedef struct INTDATA {
- 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;
- u_char int_vector;
-} io_int, local_int;
-
-typedef struct BUSTYPENAME {
- u_char type;
- char name[7];
-} bus_type_name;
-
-static bus_type_name bus_type_table[] =
-{
- {CBUS, "CBUS"},
- {CBUSII, "CBUSII"},
- {EISA, "EISA"},
- {MCA, "MCA"},
- {UNKNOWN_BUSTYPE, "---"},
- {ISA, "ISA"},
- {MCA, "MCA"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {PCI, "PCI"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {UNKNOWN_BUSTYPE, "---"},
- {XPRESS, "XPRESS"},
- {UNKNOWN_BUSTYPE, "---"}
-};
-/* from MP spec v1.4, table 5-1 */
-static int default_data[7][5] =
-{
-/* nbus, id0, type0, id1, type1 */
- {1, 0, ISA, 255, 255},
- {1, 0, EISA, 255, 255},
- {1, 0, EISA, 255, 255},
- {1, 0, MCA, 255, 255},
- {2, 0, ISA, 1, PCI},
- {2, 0, EISA, 1, PCI},
- {2, 0, MCA, 1, PCI}
-};
-
-
-/* the bus data */
-static bus_datum *bus_data;
-
-/* the IO INT data, one entry per possible APIC INTerrupt */
-static io_int *io_apic_ints;
-
-static int nintrs;
-
-static int processor_entry(proc_entry_ptr entry, int cpu);
-static int bus_entry(bus_entry_ptr entry, int bus);
-static int io_apic_entry(io_apic_entry_ptr entry, int apic);
-static int int_entry(int_entry_ptr entry, int intr);
-static int lookup_bus_type(char *name);
-
-
-/*
- * 1st pass on motherboard's Intel MP specification table.
- *
- * initializes:
- * mp_ncpus = 1
- *
- * determines:
- * cpu_apic_address (common to all CPUs)
- * io_apic_address[N]
- * mp_naps
- * mp_nbusses
- * mp_napics
- * nintrs
- */
-static void
-mptable_pass1(void)
-{
- int x;
- mpcth_t cth;
- int totalSize;
- void* position;
- int count;
- int type;
- u_int id_mask;
-
- POSTCODE(MPTABLE_PASS1_POST);
-
- /* clear various tables */
- for (x = 0; x < NAPICID; ++x) {
- io_apic_address[x] = ~0; /* IO APIC address table */
- }
-
- /* init everything to empty */
- mp_naps = 0;
- mp_nbusses = 0;
- mp_napics = 0;
- nintrs = 0;
- id_mask = 0;
-
- /* check for use of 'default' configuration */
- if (MPFPS_MPFB1 != 0) {
- /* use default addresses */
- cpu_apic_address = DEFAULT_APIC_BASE;
- io_apic_address[0] = DEFAULT_IO_APIC_BASE;
-
- /* fill in with defaults */
- mp_naps = 2; /* includes BSP */
- mp_maxid = 1;
- mp_nbusses = default_data[MPFPS_MPFB1 - 1][0];
-#if defined(APIC_IO)
- mp_napics = 1;
- nintrs = 16;
-#endif /* APIC_IO */
- }
- else {
- if ((cth = mpfps->pap) == 0)
- panic("MP Configuration Table Header MISSING!");
-
- cpu_apic_address = (vm_offset_t) cth->apic_address;
-
- /* walk the table, recording info of interest */
- totalSize = cth->base_table_length - sizeof(struct MPCTH);
- position = (u_char *) cth + sizeof(struct MPCTH);
- count = cth->entry_count;
-
- while (count--) {
- switch (type = *(u_char *) position) {
- case 0: /* processor_entry */
- if (((proc_entry_ptr)position)->cpu_flags
- & PROCENTRY_FLAG_EN) {
- ++mp_naps;
- mp_maxid++;
- id_mask |= 1 <<
- ((proc_entry_ptr)position)->apic_id;
- }
- break;
- case 1: /* bus_entry */
- ++mp_nbusses;
- break;
- case 2: /* io_apic_entry */
- if (((io_apic_entry_ptr)position)->apic_flags
- & IOAPICENTRY_FLAG_EN)
- io_apic_address[mp_napics++] =
- (vm_offset_t)((io_apic_entry_ptr)
- position)->apic_address;
- break;
- case 3: /* int_entry */
- ++nintrs;
- break;
- case 4: /* int_entry */
- break;
- default:
- panic("mpfps Base Table HOSED!");
- /* NOTREACHED */
- }
-
- totalSize -= basetable_entry_types[type].length;
- (u_char*)position += basetable_entry_types[type].length;
- }
- }
-
- /* qualify the numbers */
- if (mp_naps > MAXCPU) {
- printf("Warning: only using %d of %d available CPUs!\n",
- MAXCPU, mp_naps);
- mp_naps = MAXCPU;
- }
-
- /* See if we need to fixup HT logical CPUs. */
- mptable_hyperthread_fixup(id_mask);
-
- /*
- * Count the BSP.
- * This is also used as a counter while starting the APs.
- */
- mp_ncpus = 1;
-
- --mp_naps; /* subtract the BSP */
-}
-
-
-/*
- * 2nd pass on motherboard's Intel MP specification table.
- *
- * sets:
- * boot_cpu_id
- * ID_TO_IO(N), phy APIC ID to log CPU/IO table
- * CPU_TO_ID(N), logical CPU to APIC ID table
- * IO_TO_ID(N), logical IO to APIC ID table
- * bus_data[N]
- * io_apic_ints[N]
- */
-static int
-mptable_pass2(void)
-{
- struct PROCENTRY proc;
- int x;
- mpcth_t cth;
- int totalSize;
- void* position;
- int count;
- int type;
- int apic, bus, cpu, intr;
- int i, j;
- int pgeflag;
-
- POSTCODE(MPTABLE_PASS2_POST);
-
- /* Initialize fake proc entry for use with HT fixup. */
- bzero(&proc, sizeof(proc));
- proc.type = 0;
- proc.cpu_flags = PROCENTRY_FLAG_EN;
-
- pgeflag = 0; /* XXX - Not used under SMP yet. */
-
- MALLOC(io_apic_versions, u_int32_t *, sizeof(u_int32_t) * mp_napics,
- M_DEVBUF, M_WAITOK);
- MALLOC(ioapic, volatile ioapic_t **, sizeof(ioapic_t *) * mp_napics,
- M_DEVBUF, M_WAITOK);
- MALLOC(io_apic_ints, io_int *, sizeof(io_int) * (nintrs + 1),
- M_DEVBUF, M_WAITOK);
- MALLOC(bus_data, bus_datum *, sizeof(bus_datum) * mp_nbusses,
- M_DEVBUF, M_WAITOK);
-
- bzero(ioapic, sizeof(ioapic_t *) * mp_napics);
-
- for (i = 0; i < mp_napics; i++) {
- for (j = 0; j < mp_napics; j++) {
- /* same page frame as a previous IO apic? */
- if (((vm_offset_t)SMPpt[NPTEPG-2-j] & PG_FRAME) ==
- (io_apic_address[i] & PG_FRAME)) {
- ioapic[i] = (ioapic_t *)((u_int)SMP_prvspace
- + (NPTEPG-2-j) * PAGE_SIZE
- + (io_apic_address[i] & PAGE_MASK));
- break;
- }
- /* use this slot if available */
- if (((vm_offset_t)SMPpt[NPTEPG-2-j] & PG_FRAME) == 0) {
- SMPpt[NPTEPG-2-j] = (pt_entry_t)(PG_V | PG_RW |
- pgeflag | (io_apic_address[i] & PG_FRAME));
- ioapic[i] = (ioapic_t *)((u_int)SMP_prvspace
- + (NPTEPG-2-j) * PAGE_SIZE
- + (io_apic_address[i] & PAGE_MASK));
- break;
- }
- }
- }
-
- /* clear various tables */
- for (x = 0; x < NAPICID; ++x) {
- ID_TO_IO(x) = -1; /* phy APIC ID to log CPU/IO table */
- CPU_TO_ID(x) = -1; /* logical CPU to APIC ID table */
- IO_TO_ID(x) = -1; /* logical IO to APIC ID table */
- }
-
- /* clear bus data table */
- for (x = 0; x < mp_nbusses; ++x)
- bus_data[x].bus_id = 0xff;
-
- /* clear IO APIC INT table */
- for (x = 0; x < (nintrs + 1); ++x) {
- io_apic_ints[x].int_type = 0xff;
- io_apic_ints[x].int_vector = 0xff;
- }
-
- /* setup the cpu/apic mapping arrays */
- boot_cpu_id = -1;
-
- /* record whether PIC or virtual-wire mode */
- picmode = (mpfps->mpfb2 & 0x80) ? 1 : 0;
-
- /* check for use of 'default' configuration */
- if (MPFPS_MPFB1 != 0)
- return MPFPS_MPFB1; /* return default configuration type */
-
- if ((cth = mpfps->pap) == 0)
- panic("MP Configuration Table Header MISSING!");
-
- /* walk the table, recording info of interest */
- totalSize = cth->base_table_length - sizeof(struct MPCTH);
- position = (u_char *) cth + sizeof(struct MPCTH);
- count = cth->entry_count;
- apic = bus = intr = 0;
- cpu = 1; /* pre-count the BSP */
-
- while (count--) {
- switch (type = *(u_char *) position) {
- case 0:
- if (processor_entry(position, cpu)) {
- if (logical_cpus != 0 &&
- cpu % logical_cpus != 0)
- logical_cpus_mask |= (1 << cpu);
- ++cpu;
- }
- if (need_hyperthreading_fixup) {
- /*
- * Create fake mptable processor entries
- * and feed them to processor_entry() to
- * enumerate the logical CPUs.
- */
- proc.apic_id = ((proc_entry_ptr)position)->apic_id;
- for (i = 1; i < logical_cpus; i++) {
- proc.apic_id++;
- (void)processor_entry(&proc, cpu);
- logical_cpus_mask |= (1 << cpu);
- cpu++;
- }
- }
- break;
- case 1:
- if (bus_entry(position, bus))
- ++bus;
- break;
- case 2:
- if (io_apic_entry(position, apic))
- ++apic;
- break;
- case 3:
- if (int_entry(position, intr))
- ++intr;
- break;
- case 4:
- /* int_entry(position); */
- break;
- default:
- panic("mpfps Base Table HOSED!");
- /* NOTREACHED */
- }
-
- totalSize -= basetable_entry_types[type].length;
- (u_char *) position += basetable_entry_types[type].length;
- }
-
- if (boot_cpu_id == -1)
- panic("NO BSP found!");
-
- /* report fact that its NOT a default configuration */
- return 0;
-}
-
-/*
- * Check if we should perform a hyperthreading "fix-up" to
- * enumerate any logical CPU's that aren't already listed
- * in the table.
- *
- * XXX: We assume that all of the physical CPUs in the
- * system have the same number of logical CPUs.
- *
- * XXX: We assume that APIC ID's are allocated such that
- * the APIC ID's for a physical processor are aligned
- * with the number of logical CPU's in the processor.
- */
-static void
-mptable_hyperthread_fixup(u_int id_mask)
-{
- u_int i, id;
-
- /* Nothing to do if there is no HTT support. */
- if ((cpu_feature & CPUID_HTT) == 0)
- return;
- logical_cpus = (cpu_procinfo & CPUID_HTT_CORES) >> 16;
- if (logical_cpus <= 1)
- return;
-
- /*
- * For each APIC ID of a CPU that is set in the mask,
- * scan the other candidate APIC ID's for this
- * physical processor. If any of those ID's are
- * already in the table, then kill the fixup.
- */
- for (id = 0; id <= MAXCPU; id++) {
- if ((id_mask & 1 << id) == 0)
- continue;
- /* First, make sure we are on a logical_cpus boundary. */
- if (id % logical_cpus != 0)
- return;
- for (i = id + 1; i < id + logical_cpus; i++)
- if ((id_mask & 1 << i) != 0)
- return;
- }
-
- /*
- * Ok, the ID's checked out, so enable the fixup. We have to fixup
- * mp_naps and mp_maxid right now.
- */
- need_hyperthreading_fixup = 1;
- mp_maxid *= logical_cpus;
- mp_naps *= logical_cpus;
-}
-
-void
-assign_apic_irq(int apic, int intpin, int irq)
-{
- int x;
-
- if (int_to_apicintpin[irq].ioapic != -1)
- panic("assign_apic_irq: inconsistent table");
-
- int_to_apicintpin[irq].ioapic = apic;
- int_to_apicintpin[irq].int_pin = intpin;
- int_to_apicintpin[irq].apic_address = ioapic[apic];
- int_to_apicintpin[irq].redirindex = IOAPIC_REDTBL + 2 * intpin;
-
- for (x = 0; x < nintrs; x++) {
- if ((io_apic_ints[x].int_type == 0 ||
- io_apic_ints[x].int_type == 3) &&
- io_apic_ints[x].int_vector == 0xff &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(apic) &&
- io_apic_ints[x].dst_apic_int == intpin)
- io_apic_ints[x].int_vector = irq;
- }
-}
-
-void
-revoke_apic_irq(int irq)
-{
- int x;
- int oldapic;
- int oldintpin;
-
- if (int_to_apicintpin[irq].ioapic == -1)
- panic("revoke_apic_irq: inconsistent table");
-
- oldapic = int_to_apicintpin[irq].ioapic;
- oldintpin = int_to_apicintpin[irq].int_pin;
-
- int_to_apicintpin[irq].ioapic = -1;
- int_to_apicintpin[irq].int_pin = 0;
- int_to_apicintpin[irq].apic_address = NULL;
- int_to_apicintpin[irq].redirindex = 0;
-
- for (x = 0; x < nintrs; x++) {
- if ((io_apic_ints[x].int_type == 0 ||
- io_apic_ints[x].int_type == 3) &&
- io_apic_ints[x].int_vector != 0xff &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(oldapic) &&
- io_apic_ints[x].dst_apic_int == oldintpin)
- io_apic_ints[x].int_vector = 0xff;
- }
-}
-
-
-static void
-allocate_apic_irq(int intr)
-{
- int apic;
- int intpin;
- int irq;
-
- if (io_apic_ints[intr].int_vector != 0xff)
- return; /* Interrupt handler already assigned */
-
- if (io_apic_ints[intr].int_type != 0 &&
- (io_apic_ints[intr].int_type != 3 ||
- (io_apic_ints[intr].dst_apic_id == IO_TO_ID(0) &&
- io_apic_ints[intr].dst_apic_int == 0)))
- return; /* Not INT or ExtInt on != (0, 0) */
-
- irq = 0;
- while (irq < APIC_INTMAPSIZE &&
- int_to_apicintpin[irq].ioapic != -1)
- irq++;
-
- if (irq >= APIC_INTMAPSIZE)
- return; /* No free interrupt handlers */
-
- apic = ID_TO_IO(io_apic_ints[intr].dst_apic_id);
- intpin = io_apic_ints[intr].dst_apic_int;
-
- assign_apic_irq(apic, intpin, irq);
- io_apic_setup_intpin(apic, intpin);
-}
-
-
-static void
-swap_apic_id(int apic, int oldid, int newid)
-{
- int x;
- int oapic;
-
-
- if (oldid == newid)
- return; /* Nothing to do */
-
- printf("Changing APIC ID for IO APIC #%d from %d to %d in MP table\n",
- apic, oldid, newid);
-
- /* Swap physical APIC IDs in interrupt entries */
- for (x = 0; x < nintrs; x++) {
- if (io_apic_ints[x].dst_apic_id == oldid)
- io_apic_ints[x].dst_apic_id = newid;
- else if (io_apic_ints[x].dst_apic_id == newid)
- io_apic_ints[x].dst_apic_id = oldid;
- }
-
- /* Swap physical APIC IDs in IO_TO_ID mappings */
- for (oapic = 0; oapic < mp_napics; oapic++)
- if (IO_TO_ID(oapic) == newid)
- break;
-
- if (oapic < mp_napics) {
- printf("Changing APIC ID for IO APIC #%d from "
- "%d to %d in MP table\n",
- oapic, newid, oldid);
- IO_TO_ID(oapic) = oldid;
- }
- IO_TO_ID(apic) = newid;
-}
-
-
-static void
-fix_id_to_io_mapping(void)
-{
- int x;
-
- for (x = 0; x < NAPICID; x++)
- ID_TO_IO(x) = -1;
-
- for (x = 0; x <= mp_naps; x++)
- if (CPU_TO_ID(x) < NAPICID)
- ID_TO_IO(CPU_TO_ID(x)) = x;
-
- for (x = 0; x < mp_napics; x++)
- if (IO_TO_ID(x) < NAPICID)
- ID_TO_IO(IO_TO_ID(x)) = x;
-}
-
-
-static int
-first_free_apic_id(void)
-{
- int freeid, x;
-
- for (freeid = 0; freeid < NAPICID; freeid++) {
- for (x = 0; x <= mp_naps; x++)
- if (CPU_TO_ID(x) == freeid)
- break;
- if (x <= mp_naps)
- continue;
- for (x = 0; x < mp_napics; x++)
- if (IO_TO_ID(x) == freeid)
- break;
- if (x < mp_napics)
- continue;
- return freeid;
- }
- return freeid;
-}
-
-
-static int
-io_apic_id_acceptable(int apic, int id)
-{
- int cpu; /* Logical CPU number */
- int oapic; /* Logical IO APIC number for other IO APIC */
-
- if (id >= NAPICID)
- return 0; /* Out of range */
-
- for (cpu = 0; cpu <= mp_naps; cpu++)
- if (CPU_TO_ID(cpu) == id)
- return 0; /* Conflict with CPU */
-
- for (oapic = 0; oapic < mp_napics && oapic < apic; oapic++)
- if (IO_TO_ID(oapic) == id)
- return 0; /* Conflict with other APIC */
-
- return 1; /* ID is acceptable for IO APIC */
-}
-
-
-/*
- * parse an Intel MP specification table
- */
-static void
-fix_mp_table(void)
-{
- int x;
- int id;
- int bus_0 = 0; /* Stop GCC warning */
- int bus_pci = 0; /* Stop GCC warning */
- int num_pci_bus;
- int apic; /* IO APIC unit number */
- int freeid; /* Free physical APIC ID */
- int physid; /* Current physical IO APIC ID */
-
- /*
- * Fix mis-numbering of the PCI bus and its INT entries if the BIOS
- * did it wrong. The MP spec says that when more than 1 PCI bus
- * exists the BIOS must begin with bus entries for the PCI bus and use
- * actual PCI bus numbering. This implies that when only 1 PCI bus
- * exists the BIOS can choose to ignore this ordering, and indeed many
- * MP motherboards do ignore it. This causes a problem when the PCI
- * sub-system makes requests of the MP sub-system based on PCI bus
- * numbers. So here we look for the situation and renumber the
- * busses and associated INTs in an effort to "make it right".
- */
-
- /* find bus 0, PCI bus, count the number of PCI busses */
- for (num_pci_bus = 0, x = 0; x < mp_nbusses; ++x) {
- if (bus_data[x].bus_id == 0) {
- bus_0 = x;
- }
- if (bus_data[x].bus_type == PCI) {
- ++num_pci_bus;
- bus_pci = x;
- }
- }
- /*
- * bus_0 == slot of bus with ID of 0
- * bus_pci == slot of last PCI bus encountered
- */
-
- /* check the 1 PCI bus case for sanity */
- /* if it is number 0 all is well */
- if (num_pci_bus == 1 &&
- bus_data[bus_pci].bus_id != 0) {
-
- /* mis-numbered, swap with whichever bus uses slot 0 */
-
- /* swap the bus entry types */
- bus_data[bus_pci].bus_type = bus_data[bus_0].bus_type;
- bus_data[bus_0].bus_type = PCI;
-
- /* swap each relavant INTerrupt entry */
- id = bus_data[bus_pci].bus_id;
- for (x = 0; x < nintrs; ++x) {
- if (io_apic_ints[x].src_bus_id == id) {
- io_apic_ints[x].src_bus_id = 0;
- }
- else if (io_apic_ints[x].src_bus_id == 0) {
- io_apic_ints[x].src_bus_id = id;
- }
- }
- }
-
- /* Assign IO APIC IDs.
- *
- * First try the existing ID. If a conflict is detected, try
- * the ID in the MP table. If a conflict is still detected, find
- * a free id.
- *
- * We cannot use the ID_TO_IO table before all conflicts has been
- * resolved and the table has been corrected.
- */
- for (apic = 0; apic < mp_napics; ++apic) { /* For all IO APICs */
-
- /* First try to use the value set by the BIOS */
- physid = io_apic_get_id(apic);
- if (io_apic_id_acceptable(apic, physid)) {
- if (IO_TO_ID(apic) != physid)
- swap_apic_id(apic, IO_TO_ID(apic), physid);
- continue;
- }
-
- /* Then check if the value in the MP table is acceptable */
- if (io_apic_id_acceptable(apic, IO_TO_ID(apic)))
- continue;
-
- /* Last resort, find a free APIC ID and use it */
- freeid = first_free_apic_id();
- if (freeid >= NAPICID)
- panic("No free physical APIC IDs found");
-
- if (io_apic_id_acceptable(apic, freeid)) {
- swap_apic_id(apic, IO_TO_ID(apic), freeid);
- continue;
- }
- panic("Free physical APIC ID not usable");
- }
- fix_id_to_io_mapping();
-
- /* detect and fix broken Compaq MP table */
- if (apic_int_type(0, 0) == -1) {
- printf("APIC_IO: MP table broken: 8259->APIC entry missing!\n");
- io_apic_ints[nintrs].int_type = 3; /* ExtInt */
- io_apic_ints[nintrs].int_vector = 0xff; /* Unassigned */
- /* XXX fixme, set src bus id etc, but it doesn't seem to hurt */
- io_apic_ints[nintrs].dst_apic_id = IO_TO_ID(0);
- io_apic_ints[nintrs].dst_apic_int = 0; /* Pin 0 */
- nintrs++;
- }
-}
-
-
-/* Assign low level interrupt handlers */
-static void
-setup_apic_irq_mapping(void)
-{
- int x;
- int int_vector;
-
- /* Clear array */
- for (x = 0; x < APIC_INTMAPSIZE; x++) {
- int_to_apicintpin[x].ioapic = -1;
- int_to_apicintpin[x].int_pin = 0;
- int_to_apicintpin[x].apic_address = NULL;
- int_to_apicintpin[x].redirindex = 0;
- }
-
- /* First assign ISA/EISA interrupts */
- for (x = 0; x < nintrs; x++) {
- int_vector = io_apic_ints[x].src_bus_irq;
- if (int_vector < APIC_INTMAPSIZE &&
- io_apic_ints[x].int_vector == 0xff &&
- int_to_apicintpin[int_vector].ioapic == -1 &&
- (apic_int_is_bus_type(x, ISA) ||
- apic_int_is_bus_type(x, EISA)) &&
- io_apic_ints[x].int_type == 0) {
- assign_apic_irq(ID_TO_IO(io_apic_ints[x].dst_apic_id),
- io_apic_ints[x].dst_apic_int,
- int_vector);
- }
- }
-
- /* Assign ExtInt entry if no ISA/EISA interrupt 0 entry */
- for (x = 0; x < nintrs; x++) {
- if (io_apic_ints[x].dst_apic_int == 0 &&
- io_apic_ints[x].dst_apic_id == IO_TO_ID(0) &&
- io_apic_ints[x].int_vector == 0xff &&
- int_to_apicintpin[0].ioapic == -1 &&
- io_apic_ints[x].int_type == 3) {
- assign_apic_irq(0, 0, 0);
- break;
- }
- }
- /* PCI interrupt assignment is deferred */
-}
-
-
-static int
-processor_entry(proc_entry_ptr entry, int cpu)
-{
- /* check for usability */
- if (!(entry->cpu_flags & PROCENTRY_FLAG_EN))
- return 0;
-
- if(entry->apic_id >= NAPICID)
- panic("CPU APIC ID out of range (0..%d)", NAPICID - 1);
- /* check for BSP flag */
- if (entry->cpu_flags & PROCENTRY_FLAG_BP) {
- boot_cpu_id = entry->apic_id;
- CPU_TO_ID(0) = entry->apic_id;
- ID_TO_CPU(entry->apic_id) = 0;
- return 0; /* its already been counted */
- }
-
- /* add another AP to list, if less than max number of CPUs */
- else if (cpu < MAXCPU) {
- CPU_TO_ID(cpu) = entry->apic_id;
- ID_TO_CPU(entry->apic_id) = cpu;
- return 1;
- }
-
- return 0;
-}
-
-
-static int
-bus_entry(bus_entry_ptr entry, int bus)
-{
- int x;
- char c, name[8];
-
- /* encode the name into an index */
- for (x = 0; x < 6; ++x) {
- if ((c = entry->bus_type[x]) == ' ')
- break;
- name[x] = c;
- }
- name[x] = '\0';
-
- if ((x = lookup_bus_type(name)) == UNKNOWN_BUSTYPE)
- panic("unknown bus type: '%s'", name);
-
- bus_data[bus].bus_id = entry->bus_id;
- bus_data[bus].bus_type = x;
-
- return 1;
-}
-
-
-static int
-io_apic_entry(io_apic_entry_ptr entry, int apic)
-{
- if (!(entry->apic_flags & IOAPICENTRY_FLAG_EN))
- return 0;
-
- IO_TO_ID(apic) = entry->apic_id;
- if (entry->apic_id < NAPICID)
- ID_TO_IO(entry->apic_id) = apic;
-
- return 1;
-}
-
-
-static int
-lookup_bus_type(char *name)
-{
- int x;
-
- for (x = 0; x < MAX_BUSTYPE; ++x)
- if (strcmp(bus_type_table[x].name, name) == 0)
- return bus_type_table[x].type;
-
- return UNKNOWN_BUSTYPE;
-}
-
-
-static int
-int_entry(int_entry_ptr entry, int intr)
-{
- int apic;
-
- io_apic_ints[intr].int_type = entry->int_type;
- io_apic_ints[intr].int_flags = entry->int_flags;
- io_apic_ints[intr].src_bus_id = entry->src_bus_id;
- io_apic_ints[intr].src_bus_irq = entry->src_bus_irq;
- if (entry->dst_apic_id == 255) {
- /* This signal goes to all IO APICS. Select an IO APIC
- with sufficient number of interrupt pins */
- for (apic = 0; apic < mp_napics; apic++)
- if (((io_apic_read(apic, IOAPIC_VER) &
- IOART_VER_MAXREDIR) >> MAXREDIRSHIFT) >=
- entry->dst_apic_int)
- break;
- if (apic < mp_napics)
- io_apic_ints[intr].dst_apic_id = IO_TO_ID(apic);
- else
- io_apic_ints[intr].dst_apic_id = entry->dst_apic_id;
- } else
- io_apic_ints[intr].dst_apic_id = entry->dst_apic_id;
- io_apic_ints[intr].dst_apic_int = entry->dst_apic_int;
-
- return 1;
-}
-
-
-static int
-apic_int_is_bus_type(int intr, int bus_type)
-{
- int bus;
-
- for (bus = 0; bus < mp_nbusses; ++bus)
- if ((bus_data[bus].bus_id == io_apic_ints[intr].src_bus_id)
- && ((int) bus_data[bus].bus_type == bus_type))
- return 1;
-
- return 0;
-}
-
-
-/*
- * Given a traditional ISA INT mask, return an APIC mask.
- */
-u_int
-isa_apic_mask(u_int isa_mask)
-{
- int isa_irq;
- int apic_pin;
-
-#if defined(SKIP_IRQ15_REDIRECT)
- if (isa_mask == (1 << 15)) {
- printf("skipping ISA IRQ15 redirect\n");
- return isa_mask;
- }
-#endif /* SKIP_IRQ15_REDIRECT */
-
- isa_irq = ffs(isa_mask); /* find its bit position */
- if (isa_irq == 0) /* doesn't exist */
- return 0;
- --isa_irq; /* make it zero based */
-
- apic_pin = isa_apic_irq(isa_irq); /* look for APIC connection */
- if (apic_pin == -1)
- return 0;
-
- return (1 << apic_pin); /* convert pin# to a mask */
-}
-
-
-/*
- * Determine which APIC pin an ISA/EISA INT is attached to.
- */
-#define INTTYPE(I) (io_apic_ints[(I)].int_type)
-#define INTPIN(I) (io_apic_ints[(I)].dst_apic_int)
-#define INTIRQ(I) (io_apic_ints[(I)].int_vector)
-#define INTAPIC(I) (ID_TO_IO(io_apic_ints[(I)].dst_apic_id))
-
-#define SRCBUSIRQ(I) (io_apic_ints[(I)].src_bus_irq)
-int
-isa_apic_irq(int isa_irq)
-{
- int intr;
-
- for (intr = 0; intr < nintrs; ++intr) { /* check each record */
- if (INTTYPE(intr) == 0) { /* standard INT */
- if (SRCBUSIRQ(intr) == isa_irq) {
- if (apic_int_is_bus_type(intr, ISA) ||
- apic_int_is_bus_type(intr, EISA)) {
- if (INTIRQ(intr) == 0xff)
- return -1; /* unassigned */
- return INTIRQ(intr); /* found */
- }
- }
- }
- }
- return -1; /* NOT found */
-}
-
-
-/*
- * Determine which APIC pin a PCI INT is attached to.
- */
-#define SRCBUSID(I) (io_apic_ints[(I)].src_bus_id)
-#define SRCBUSDEVICE(I) ((io_apic_ints[(I)].src_bus_irq >> 2) & 0x1f)
-#define SRCBUSLINE(I) (io_apic_ints[(I)].src_bus_irq & 0x03)
-int
-pci_apic_irq(int pciBus, int pciDevice, int pciInt)
-{
- int intr;
-
- --pciInt; /* zero based */
-
- for (intr = 0; intr < nintrs; ++intr) /* check each record */
- if ((INTTYPE(intr) == 0) /* standard INT */
- && (SRCBUSID(intr) == pciBus)
- && (SRCBUSDEVICE(intr) == pciDevice)
- && (SRCBUSLINE(intr) == pciInt)) /* a candidate IRQ */
- if (apic_int_is_bus_type(intr, PCI)) {
- if (INTIRQ(intr) == 0xff)
- allocate_apic_irq(intr);
- if (INTIRQ(intr) == 0xff)
- return -1; /* unassigned */
- return INTIRQ(intr); /* exact match */
- }
-
- return -1; /* NOT found */
-}
-
-int
-next_apic_irq(int irq)
-{
- int intr, ointr;
- int bus, bustype;
-
- bus = 0;
- bustype = 0;
- for (intr = 0; intr < nintrs; intr++) {
- if (INTIRQ(intr) != irq || INTTYPE(intr) != 0)
- continue;
- bus = SRCBUSID(intr);
- bustype = apic_bus_type(bus);
- if (bustype != ISA &&
- bustype != EISA &&
- bustype != PCI)
- continue;
- break;
- }
- if (intr >= nintrs) {
- return -1;
- }
- for (ointr = intr + 1; ointr < nintrs; ointr++) {
- if (INTTYPE(ointr) != 0)
- continue;
- if (bus != SRCBUSID(ointr))
- continue;
- if (bustype == PCI) {
- if (SRCBUSDEVICE(intr) != SRCBUSDEVICE(ointr))
- continue;
- if (SRCBUSLINE(intr) != SRCBUSLINE(ointr))
- continue;
- }
- if (bustype == ISA || bustype == EISA) {
- if (SRCBUSIRQ(intr) != SRCBUSIRQ(ointr))
- continue;
- }
- if (INTPIN(intr) == INTPIN(ointr))
- continue;
- break;
- }
- if (ointr >= nintrs) {
- return -1;
- }
- return INTIRQ(ointr);
-}
-#undef SRCBUSLINE
-#undef SRCBUSDEVICE
-#undef SRCBUSID
-#undef SRCBUSIRQ
-
-#undef INTPIN
-#undef INTIRQ
-#undef INTAPIC
-#undef INTTYPE
-
-
-/*
- * Reprogram the MB chipset to NOT redirect an ISA INTerrupt.
- *
- * XXX FIXME:
- * Exactly what this means is unclear at this point. It is a solution
- * for motherboards that redirect the MBIRQ0 pin. Generically a motherboard
- * could route any of the ISA INTs to upper (>15) IRQ values. But most would
- * NOT be redirected via MBIRQ0, thus "undirect()ing" them would NOT be an
- * option.
- */
-int
-undirect_isa_irq(int rirq)
-{
-#if defined(READY)
- if (bootverbose)
- printf("Freeing redirected ISA irq %d.\n", rirq);
- /** FIXME: tickle the MB redirector chip */
- return -1;
-#else
- if (bootverbose)
- printf("Freeing (NOT implemented) redirected ISA irq %d.\n", rirq);
- return 0;
-#endif /* READY */
-}
-
-
-/*
- * Reprogram the MB chipset to NOT redirect a PCI INTerrupt
- */
-int
-undirect_pci_irq(int rirq)
-{
-#if defined(READY)
- if (bootverbose)
- printf("Freeing redirected PCI irq %d.\n", rirq);
-
- /** FIXME: tickle the MB redirector chip */
- return -1;
-#else
- if (bootverbose)
- printf("Freeing (NOT implemented) redirected PCI irq %d.\n",
- rirq);
- return 0;
-#endif /* READY */
-}
-
-
-/*
- * given a bus ID, return:
- * the bus type if found
- * -1 if NOT found
- */
-int
-apic_bus_type(int id)
-{
- int x;
-
- for (x = 0; x < mp_nbusses; ++x)
- if (bus_data[x].bus_id == id)
- return bus_data[x].bus_type;
-
- return -1;
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated src bus ID if found
- * -1 if NOT found
- */
-int
-apic_src_bus_id(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].src_bus_id);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated src bus IRQ if found
- * -1 if NOT found
- */
-int
-apic_src_bus_irq(int apic, int pin)
-{
- int x;
-
- for (x = 0; x < nintrs; x++)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].src_bus_irq);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated INTerrupt type if found
- * -1 if NOT found
- */
-int
-apic_int_type(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].int_type);
-
- return -1; /* NOT found */
-}
-
-int
-apic_irq(int apic, int pin)
-{
- int x;
- int res;
-
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int)) {
- res = io_apic_ints[x].int_vector;
- if (res == 0xff)
- return -1;
- if (apic != int_to_apicintpin[res].ioapic)
- panic("apic_irq: inconsistent table");
- if (pin != int_to_apicintpin[res].int_pin)
- panic("apic_irq inconsistent table (2)");
- return res;
- }
- return -1;
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated trigger mode if found
- * -1 if NOT found
- */
-int
-apic_trigger(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return ((io_apic_ints[x].int_flags >> 2) & 0x03);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * given a LOGICAL APIC# and pin#, return:
- * the associated 'active' level if found
- * -1 if NOT found
- */
-int
-apic_polarity(int apic, int pin)
-{
- int x;
-
- /* search each of the possible INTerrupt sources */
- for (x = 0; x < nintrs; ++x)
- if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
- (pin == io_apic_ints[x].dst_apic_int))
- return (io_apic_ints[x].int_flags & 0x03);
-
- return -1; /* NOT found */
-}
-
-
-/*
- * set data according to MP defaults
- * FIXME: probably not complete yet...
- */
-static void
-default_mp_table(int type)
-{
- int ap_cpu_id;
-#if defined(APIC_IO)
- int io_apic_id;
- int pin;
-#endif /* APIC_IO */
-
-#if 0
- printf(" MP default config type: %d\n", type);
- switch (type) {
- case 1:
- printf(" bus: ISA, APIC: 82489DX\n");
- break;
- case 2:
- printf(" bus: EISA, APIC: 82489DX\n");
- break;
- case 3:
- printf(" bus: EISA, APIC: 82489DX\n");
- break;
- case 4:
- printf(" bus: MCA, APIC: 82489DX\n");
- break;
- case 5:
- printf(" bus: ISA+PCI, APIC: Integrated\n");
- break;
- case 6:
- printf(" bus: EISA+PCI, APIC: Integrated\n");
- break;
- case 7:
- printf(" bus: MCA+PCI, APIC: Integrated\n");
- break;
- default:
- printf(" future type\n");
- break;
- /* NOTREACHED */
- }
-#endif /* 0 */
-
- boot_cpu_id = (lapic.id & APIC_ID_MASK) >> 24;
- ap_cpu_id = (boot_cpu_id == 0) ? 1 : 0;
-
- /* BSP */
- CPU_TO_ID(0) = boot_cpu_id;
- ID_TO_CPU(boot_cpu_id) = 0;
-
- /* one and only AP */
- CPU_TO_ID(1) = ap_cpu_id;
- ID_TO_CPU(ap_cpu_id) = 1;
-
-#if defined(APIC_IO)
- /* one and only IO APIC */
- io_apic_id = (io_apic_read(0, IOAPIC_ID) & APIC_ID_MASK) >> 24;
-
- /*
- * sanity check, refer to MP spec section 3.6.6, last paragraph
- * necessary as some hardware isn't properly setting up the IO APIC
- */
-#if defined(REALLY_ANAL_IOAPICID_VALUE)
- if (io_apic_id != 2) {
-#else
- if ((io_apic_id == 0) || (io_apic_id == 1) || (io_apic_id == 15)) {
-#endif /* REALLY_ANAL_IOAPICID_VALUE */
- io_apic_set_id(0, 2);
- io_apic_id = 2;
- }
- IO_TO_ID(0) = io_apic_id;
- ID_TO_IO(io_apic_id) = 0;
-#endif /* APIC_IO */
-
- /* fill out bus entries */
- switch (type) {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- bus_data[0].bus_id = default_data[type - 1][1];
- bus_data[0].bus_type = default_data[type - 1][2];
- bus_data[1].bus_id = default_data[type - 1][3];
- bus_data[1].bus_type = default_data[type - 1][4];
- break;
-
- /* case 4: case 7: MCA NOT supported */
- default: /* illegal/reserved */
- panic("BAD default MP config: %d", type);
- /* NOTREACHED */
- }
-
-#if defined(APIC_IO)
- /* general cases from MP v1.4, table 5-2 */
- for (pin = 0; pin < 16; ++pin) {
- io_apic_ints[pin].int_type = 0;
- io_apic_ints[pin].int_flags = 0x05; /* edge/active-hi */
- io_apic_ints[pin].src_bus_id = 0;
- io_apic_ints[pin].src_bus_irq = pin; /* IRQ2 caught below */
- io_apic_ints[pin].dst_apic_id = io_apic_id;
- io_apic_ints[pin].dst_apic_int = pin; /* 1-to-1 */
- }
-
- /* special cases from MP v1.4, table 5-2 */
- if (type == 2) {
- io_apic_ints[2].int_type = 0xff; /* N/C */
- io_apic_ints[13].int_type = 0xff; /* N/C */
-#if !defined(APIC_MIXED_MODE)
- /** FIXME: ??? */
- panic("sorry, can't support type 2 default yet");
-#endif /* APIC_MIXED_MODE */
- }
- else
- io_apic_ints[2].src_bus_irq = 0; /* ISA IRQ0 is on APIC INT 2 */
-
- if (type == 7)
- io_apic_ints[0].int_type = 0xff; /* N/C */
- else
- io_apic_ints[0].int_type = 3; /* vectored 8259 */
-#endif /* APIC_IO */
-}
-
-
-/*
- * start each AP in our list
- */
-static int
-start_all_aps(u_int boot_addr)
-{
- int x, i, pg;
-#ifndef PC98
- u_char mpbiosreason;
-#endif
- u_long mpbioswarmvec;
- struct pcpu *pc;
- char *stack;
- uintptr_t kptbase;
-
- POSTCODE(START_ALL_APS_POST);
-
- mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN);
-
- /* initialize BSP's local APIC */
- apic_initialize();
- bsp_apic_ready = 1;
-
- /* install the AP 1st level boot code */
- install_ap_tramp(boot_addr);
-
-
- /* save the current value of the warm-start vector */
- mpbioswarmvec = *((u_long *) WARMBOOT_OFF);
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- mpbiosreason = inb(CMOS_DATA);
-#endif
-
- /* set up temporary P==V mapping for AP boot */
- /* XXX this is a hack, we should boot the AP on its own stack/PTD */
- kptbase = (uintptr_t)(void *)KPTphys;
- for (x = 0; x < NKPT; x++)
- PTD[x] = (pd_entry_t)(PG_V | PG_RW |
- ((kptbase + x * PAGE_SIZE) & PG_FRAME));
- invltlb();
-
- /* start each AP */
- for (x = 1; x <= mp_naps; ++x) {
-
- /* This is a bit verbose, it will go away soon. */
-
- /* first page of AP's private space */
- pg = x * i386_btop(sizeof(struct privatespace));
-
- /* allocate a new private data page */
- pc = (struct pcpu *)kmem_alloc(kernel_map, PAGE_SIZE);
-
- /* wire it into the private page table page */
- SMPpt[pg] = (pt_entry_t)(PG_V | PG_RW | vtophys(pc));
-
- /* allocate and set up an idle stack data page */
- stack = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE); /* XXXKSE */
- for (i = 0; i < KSTACK_PAGES; i++)
- SMPpt[pg + 1 + i] = (pt_entry_t)
- (PG_V | PG_RW | vtophys(PAGE_SIZE * i + stack));
-
- /* prime data page for it to use */
- pcpu_init(pc, x, sizeof(struct pcpu));
-
- /* setup a vector to our boot code */
- *((volatile u_short *) WARMBOOT_OFF) = WARMBOOT_TARGET;
- *((volatile u_short *) WARMBOOT_SEG) = (boot_addr >> 4);
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- outb(CMOS_DATA, BIOS_WARM); /* 'warm-start' */
-#endif
-
- bootSTK = &SMP_prvspace[x].idlekstack[KSTACK_PAGES * PAGE_SIZE];
- bootAP = x;
-
- /* attempt to start the Application Processor */
- CHECK_INIT(99); /* setup checkpoints */
- if (!start_ap(x, boot_addr)) {
- printf("AP #%d (PHY# %d) failed!\n", x, CPU_TO_ID(x));
- CHECK_PRINT("trace"); /* show checkpoints */
- /* better panic as the AP may be running loose */
- printf("panic y/n? [y] ");
- if (cngetc() != 'n')
- panic("bye-bye");
- }
- CHECK_PRINT("trace"); /* show checkpoints */
-
- /* record its version info */
- cpu_apic_versions[x] = cpu_apic_versions[0];
-
- all_cpus |= (1 << x); /* record AP in CPU map */
- }
-
- /* build our map of 'other' CPUs */
- PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
-
- /* fill in our (BSP) APIC version */
- cpu_apic_versions[0] = lapic.version;
-
- /* restore the warmstart vector */
- *(u_long *) WARMBOOT_OFF = mpbioswarmvec;
-#ifndef PC98
- outb(CMOS_REG, BIOS_RESET);
- outb(CMOS_DATA, mpbiosreason);
-#endif
-
- /*
- * Set up the idle context for the BSP. Similar to above except
- * that some was done by locore, some by pmap.c and some is implicit
- * because the BSP is cpu#0 and the page is initially zero, and also
- * because we can refer to variables by name on the BSP..
- */
-
- /* Allocate and setup BSP idle stack */
- stack = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE);
- for (i = 0; i < KSTACK_PAGES; i++)
- SMPpt[1 + i] = (pt_entry_t)
- (PG_V | PG_RW | vtophys(PAGE_SIZE * i + stack));
-
- for (x = 0; x < NKPT; x++)
- PTD[x] = 0;
- pmap_set_opt();
-
- /* number of APs actually started */
- return mp_ncpus - 1;
-}
-
-
-/*
- * load the 1st level AP boot code into base memory.
- */
-
-/* targets for relocation */
-extern void bigJump(void);
-extern void bootCodeSeg(void);
-extern void bootDataSeg(void);
-extern void MPentry(void);
-extern u_int MP_GDT;
-extern u_int mp_gdtbase;
-
-static void
-install_ap_tramp(u_int boot_addr)
-{
- int x;
- int size = *(int *) ((u_long) & bootMP_size);
- u_char *src = (u_char *) ((u_long) bootMP);
- u_char *dst = (u_char *) boot_addr + KERNBASE;
- u_int boot_base = (u_int) bootMP;
- u_int8_t *dst8;
- u_int16_t *dst16;
- u_int32_t *dst32;
-
- POSTCODE(INSTALL_AP_TRAMP_POST);
-
- for (x = 0; x < size; ++x)
- *dst++ = *src++;
-
- /*
- * modify addresses in code we just moved to basemem. unfortunately we
- * need fairly detailed info about mpboot.s for this to work. changes
- * to mpboot.s might require changes here.
- */
-
- /* boot code is located in KERNEL space */
- dst = (u_char *) boot_addr + KERNBASE;
-
- /* modify the lgdt arg */
- dst32 = (u_int32_t *) (dst + ((u_int) & mp_gdtbase - boot_base));
- *dst32 = boot_addr + ((u_int) & MP_GDT - boot_base);
-
- /* modify the ljmp target for MPentry() */
- dst32 = (u_int32_t *) (dst + ((u_int) bigJump - boot_base) + 1);
- *dst32 = ((u_int) MPentry - KERNBASE);
-
- /* modify the target for boot code segment */
- dst16 = (u_int16_t *) (dst + ((u_int) bootCodeSeg - boot_base));
- dst8 = (u_int8_t *) (dst16 + 1);
- *dst16 = (u_int) boot_addr & 0xffff;
- *dst8 = ((u_int) boot_addr >> 16) & 0xff;
-
- /* modify the target for boot data segment */
- dst16 = (u_int16_t *) (dst + ((u_int) bootDataSeg - boot_base));
- dst8 = (u_int8_t *) (dst16 + 1);
- *dst16 = (u_int) boot_addr & 0xffff;
- *dst8 = ((u_int) boot_addr >> 16) & 0xff;
-}
-
-
-/*
- * this function starts the AP (application processor) identified
- * by the APIC ID 'physicalCpu'. It does quite a "song and dance"
- * to accomplish this. This is necessary because of the nuances
- * of the different hardware we might encounter. It ain't pretty,
- * but it seems to work.
- */
-static int
-start_ap(int logical_cpu, u_int boot_addr)
-{
- int physical_cpu;
- int vector;
- int cpus;
- u_long icr_lo, icr_hi;
-
- POSTCODE(START_AP_POST);
-
- /* get the PHYSICAL APIC ID# */
- physical_cpu = CPU_TO_ID(logical_cpu);
-
- /* calculate the vector */
- vector = (boot_addr >> 12) & 0xff;
-
- /* used as a watchpoint to signal AP startup */
- cpus = mp_ncpus;
-
- /*
- * first we do an INIT/RESET IPI this INIT IPI might be run, reseting
- * and running the target CPU. OR this INIT IPI might be latched (P5
- * bug), CPU waiting for STARTUP IPI. OR this INIT IPI might be
- * ignored.
- */
-
- /* setup the address for the target AP */
- icr_hi = lapic.icr_hi & ~APIC_ID_MASK;
- icr_hi |= (physical_cpu << 24);
- lapic.icr_hi = icr_hi;
-
- /* do an INIT IPI: assert RESET */
- icr_lo = lapic.icr_lo & 0xfff00000;
- lapic.icr_lo = icr_lo | 0x0000c500;
-
- /* wait for pending status end */
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
-
- /* do an INIT IPI: deassert RESET */
- lapic.icr_lo = icr_lo | 0x00008500;
-
- /* wait for pending status end */
- u_sleep(10000); /* wait ~10mS */
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
-
- /*
- * next we do a STARTUP IPI: the previous INIT IPI might still be
- * latched, (P5 bug) this 1st STARTUP would then terminate
- * immediately, and the previously started INIT IPI would continue. OR
- * the previous INIT IPI has already run. and this STARTUP IPI will
- * run. OR the previous INIT IPI was ignored. and this STARTUP IPI
- * will run.
- */
-
- /* do a STARTUP IPI */
- lapic.icr_lo = icr_lo | 0x00000600 | vector;
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
- u_sleep(200); /* wait ~200uS */
-
- /*
- * finally we do a 2nd STARTUP IPI: this 2nd STARTUP IPI should run IF
- * the previous STARTUP IPI was cancelled by a latched INIT IPI. OR
- * this STARTUP IPI will be ignored, as only ONE STARTUP IPI is
- * recognized after hardware RESET or INIT IPI.
- */
-
- lapic.icr_lo = icr_lo | 0x00000600 | vector;
- while (lapic.icr_lo & APIC_DELSTAT_MASK)
- /* spin */ ;
- u_sleep(200); /* wait ~200uS */
-
- /* wait for it to start */
- set_apic_timer(5000000);/* == 5 seconds */
- while (read_apic_timer())
- if (mp_ncpus > cpus)
- return 1; /* return SUCCESS */
-
- return 0; /* return FAILURE */
-}
-
-#if defined(APIC_IO)
-
-#ifdef COUNT_XINVLTLB_HITS
-u_int xhits_gbl[MAXCPU];
-u_int xhits_pg[MAXCPU];
-u_int xhits_rng[MAXCPU];
-SYSCTL_NODE(_debug, OID_AUTO, xhits, CTLFLAG_RW, 0, "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, global, CTLFLAG_RW, &xhits_gbl,
- sizeof(xhits_gbl), "IU", "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, page, CTLFLAG_RW, &xhits_pg,
- sizeof(xhits_pg), "IU", "");
-SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, range, CTLFLAG_RW, &xhits_rng,
- sizeof(xhits_rng), "IU", "");
-
-u_int ipi_global;
-u_int ipi_page;
-u_int ipi_range;
-u_int ipi_range_size;
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_global, CTLFLAG_RW, &ipi_global, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_page, CTLFLAG_RW, &ipi_page, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range, CTLFLAG_RW, &ipi_range, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range_size, CTLFLAG_RW, &ipi_range_size,
- 0, "");
-
-u_int ipi_masked_global;
-u_int ipi_masked_page;
-u_int ipi_masked_range;
-u_int ipi_masked_range_size;
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_global, CTLFLAG_RW,
- &ipi_masked_global, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_page, CTLFLAG_RW,
- &ipi_masked_page, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range, CTLFLAG_RW,
- &ipi_masked_range, 0, "");
-SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range_size, CTLFLAG_RW,
- &ipi_masked_range_size, 0, "");
-#endif
-
-/*
- * Flush the TLB on all other CPU's
- */
-static void
-smp_tlb_shootdown(u_int vector, vm_offset_t addr1, vm_offset_t addr2)
-{
- u_int ncpu;
- register_t eflags;
-
- ncpu = mp_ncpus - 1; /* does not shootdown self */
- if (ncpu < 1)
- return; /* no other cpus */
- eflags = read_eflags();
- if ((eflags & PSL_I) == 0)
- panic("absolutely cannot call smp_ipi_shootdown with interrupts already disabled");
- mtx_lock_spin(&smp_tlb_mtx);
- smp_tlb_addr1 = addr1;
- smp_tlb_addr2 = addr2;
- atomic_store_rel_int(&smp_tlb_wait, 0);
- ipi_all_but_self(vector);
- while (smp_tlb_wait < ncpu)
- ia32_pause();
- mtx_unlock_spin(&smp_tlb_mtx);
-}
-
-/*
- * This is about as magic as it gets. fortune(1) has got similar code
- * for reversing bits in a word. Who thinks up this stuff??
- *
- * Yes, it does appear to be consistently faster than:
- * while (i = ffs(m)) {
- * m >>= i;
- * bits++;
- * }
- * and
- * while (lsb = (m & -m)) { // This is magic too
- * m &= ~lsb; // or: m ^= lsb
- * bits++;
- * }
- * Both of these latter forms do some very strange things on gcc-3.1 with
- * -mcpu=pentiumpro and/or -march=pentiumpro and/or -O or -O2.
- * There is probably an SSE or MMX popcnt instruction.
- *
- * I wonder if this should be in libkern?
- *
- * XXX Stop the presses! Another one:
- * static __inline u_int32_t
- * popcnt1(u_int32_t v)
- * {
- * v -= ((v >> 1) & 0x55555555);
- * v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
- * v = (v + (v >> 4)) & 0x0F0F0F0F;
- * return (v * 0x01010101) >> 24;
- * }
- * The downside is that it has a multiply. With a pentium3 with
- * -mcpu=pentiumpro and -march=pentiumpro then gcc-3.1 will use
- * an imull, and in that case it is faster. In most other cases
- * it appears slightly slower.
- */
-static __inline u_int32_t
-popcnt(u_int32_t m)
-{
-
- m = (m & 0x55555555) + ((m & 0xaaaaaaaa) >> 1);
- m = (m & 0x33333333) + ((m & 0xcccccccc) >> 2);
- m = (m & 0x0f0f0f0f) + ((m & 0xf0f0f0f0) >> 4);
- m = (m & 0x00ff00ff) + ((m & 0xff00ff00) >> 8);
- m = (m & 0x0000ffff) + ((m & 0xffff0000) >> 16);
- return m;
-}
-
-static void
-smp_targeted_tlb_shootdown(u_int mask, u_int vector, vm_offset_t addr1, vm_offset_t addr2)
-{
- int ncpu, othercpus;
- register_t eflags;
-
- othercpus = mp_ncpus - 1;
- if (mask == (u_int)-1) {
- ncpu = othercpus;
- if (ncpu < 1)
- return;
- } else {
- /* XXX there should be a pcpu self mask */
- mask &= ~(1 << PCPU_GET(cpuid));
- if (mask == 0)
- return;
- ncpu = popcnt(mask);
- if (ncpu > othercpus) {
- /* XXX this should be a panic offence */
- printf("SMP: tlb shootdown to %d other cpus (only have %d)\n",
- ncpu, othercpus);
- ncpu = othercpus;
- }
- /* XXX should be a panic, implied by mask == 0 above */
- if (ncpu < 1)
- return;
- }
- eflags = read_eflags();
- if ((eflags & PSL_I) == 0)
- panic("absolutely cannot call smp_targeted_ipi_shootdown with interrupts already disabled");
- mtx_lock_spin(&smp_tlb_mtx);
- smp_tlb_addr1 = addr1;
- smp_tlb_addr2 = addr2;
- atomic_store_rel_int(&smp_tlb_wait, 0);
- if (mask == (u_int)-1)
- ipi_all_but_self(vector);
- else
- ipi_selected(mask, vector);
- while (smp_tlb_wait < ncpu)
- ia32_pause();
- mtx_unlock_spin(&smp_tlb_mtx);
-}
-#endif
-
-void
-smp_invltlb(void)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLTLB, 0, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_global++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_invlpg(vm_offset_t addr)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLPG, addr, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_page++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_invlpg_range(vm_offset_t addr1, vm_offset_t addr2)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_tlb_shootdown(IPI_INVLRNG, addr1, addr2);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_range++;
- ipi_range_size += (addr2 - addr1) / PAGE_SIZE;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invltlb(u_int mask)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLTLB, 0, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_global++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invlpg(u_int mask, vm_offset_t addr)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLPG, addr, 0);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_page++;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-void
-smp_masked_invlpg_range(u_int mask, vm_offset_t addr1, vm_offset_t addr2)
-{
-#if defined(APIC_IO)
- if (smp_started) {
- smp_targeted_tlb_shootdown(mask, IPI_INVLRNG, addr1, addr2);
-#ifdef COUNT_XINVLTLB_HITS
- ipi_masked_range++;
- ipi_masked_range_size += (addr2 - addr1) / PAGE_SIZE;
-#endif
- }
-#endif /* APIC_IO */
-}
-
-
-/*
- * This is called once the rest of the system is up and running and we're
- * ready to let the AP's out of the pen.
- */
-void
-ap_init(void)
-{
- u_int apic_id;
-
- /* spin until all the AP's are ready */
- while (!aps_ready)
- ia32_pause();
-
- /* BSP may have changed PTD while we were waiting */
- invltlb();
-
-#if defined(I586_CPU) && !defined(NO_F00F_HACK)
- lidt(&r_idt);
-#endif
-
- /* set up CPU registers and state */
- cpu_setregs();
-
- /* set up FPU state on the AP */
- npxinit(__INITIAL_NPXCW__);
-
- /* set up SSE registers */
- enable_sse();
-
- /* A quick check from sanity claus */
- apic_id = (apic_id_to_logical[(lapic.id & 0x0f000000) >> 24]);
- if (PCPU_GET(cpuid) != apic_id) {
- printf("SMP: cpuid = %d\n", PCPU_GET(cpuid));
- printf("SMP: apic_id = %d\n", apic_id);
- printf("PTD[MPPTDI] = %#jx\n", (uintmax_t)PTD[MPPTDI]);
- panic("cpuid mismatch! boom!!");
- }
-
- /* Init local apic for irq's */
- apic_initialize();
-
- /* Set memory range attributes for this CPU to match the BSP */
- mem_range_AP_init();
-
- mtx_lock_spin(&ap_boot_mtx);
-
- smp_cpus++;
-
- CTR1(KTR_SMP, "SMP: AP CPU #%d Launched", PCPU_GET(cpuid));
- printf("SMP: AP CPU #%d Launched!\n", PCPU_GET(cpuid));
-
- /* Build our map of 'other' CPUs. */
- PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
-
- if (bootverbose)
- apic_dump("ap_init()");
-
- if (smp_cpus == mp_ncpus) {
- /* enable IPI's, tlb shootdown, freezes etc */
- atomic_store_rel_int(&smp_started, 1);
- smp_active = 1; /* historic */
- }
-
- mtx_unlock_spin(&ap_boot_mtx);
-
- /* wait until all the AP's are up */
- while (smp_started == 0)
- ia32_pause();
-
- /* ok, now grab sched_lock and enter the scheduler */
- mtx_lock_spin(&sched_lock);
-
- binuptime(PCPU_PTR(switchtime));
- PCPU_SET(switchticks, ticks);
-
- cpu_throw(NULL, choosethread()); /* doesn't return */
-
- panic("scheduler returned us to %s", __func__);
-}
-
-/*
- * For statclock, we send an IPI to all CPU's to have them call this
- * function.
- *
- * WARNING! unpend() will call statclock() directly and skip this
- * routine.
- */
-void
-forwarded_statclock(struct clockframe frame)
-{
-
- if (profprocs != 0)
- profclock(&frame);
- if (pscnt == psdiv)
- statclock(&frame);
-}
-
-void
-forward_statclock(void)
-{
- int map;
-
- CTR0(KTR_SMP, "forward_statclock");
-
- if (!smp_started || cold || panicstr)
- return;
-
- map = PCPU_GET(other_cpus) & ~stopped_cpus ;
- if (map != 0)
- ipi_selected(map, IPI_STATCLOCK);
-}
-
-/*
- * For each hardclock(), we send an IPI to all other CPU's to have them
- * execute this function. It would be nice to reduce contention on
- * sched_lock if we could simply peek at the CPU to determine the user/kernel
- * state and call hardclock_process() on the CPU receiving the clock interrupt
- * and then just use a simple IPI to handle any ast's if needed.
- *
- * WARNING! unpend() will call hardclock_process() directly and skip this
- * routine.
- */
-void
-forwarded_hardclock(struct clockframe frame)
-{
-
- hardclock_process(&frame);
-}
-
-void
-forward_hardclock(void)
-{
- u_int map;
-
- CTR0(KTR_SMP, "forward_hardclock");
-
- if (!smp_started || cold || panicstr)
- return;
-
- map = PCPU_GET(other_cpus) & ~stopped_cpus ;
- if (map != 0)
- ipi_selected(map, IPI_HARDCLOCK);
-}
-
-#ifdef APIC_INTR_REORDER
-/*
- * Maintain mapping from softintr vector to isr bit in local apic.
- */
-void
-set_lapic_isrloc(int intr, int vector)
-{
- if (intr < 0 || intr > 32)
- panic("set_apic_isrloc: bad intr argument: %d",intr);
- if (vector < ICU_OFFSET || vector > 255)
- panic("set_apic_isrloc: bad vector argument: %d",vector);
- apic_isrbit_location[intr].location = &lapic.isr0 + ((vector>>5)<<2);
- apic_isrbit_location[intr].bit = (1<<(vector & 31));
-}
-#endif
-
-/*
- * send an IPI to a set of cpus.
- */
-void
-ipi_selected(u_int32_t cpus, u_int ipi)
-{
-
- CTR3(KTR_SMP, "%s: cpus: %x ipi: %x", __func__, cpus, ipi);
- selected_apic_ipi(cpus, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI INTerrupt containing 'vector' to all CPUs, including myself
- */
-void
-ipi_all(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_ALLISELF, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI to all CPUs EXCEPT myself
- */
-void
-ipi_all_but_self(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_ALLESELF, ipi, APIC_DELMODE_FIXED);
-}
-
-/*
- * send an IPI to myself
- */
-void
-ipi_self(u_int ipi)
-{
-
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- apic_ipi(APIC_DEST_SELF, ipi, APIC_DELMODE_FIXED);
-}
-
-static void
-release_aps(void *dummy __unused)
-{
-
- if (mp_ncpus == 1)
- return;
- mtx_lock_spin(&sched_lock);
- atomic_store_rel_int(&aps_ready, 1);
- while (smp_started == 0)
- ia32_pause();
- mtx_unlock_spin(&sched_lock);
-}
-
-SYSINIT(start_aps, SI_SUB_SMP, SI_ORDER_FIRST, release_aps, NULL);
-
-static int hlt_cpus_mask;
-static int hlt_logical_cpus = 1;
-static struct sysctl_ctx_list logical_cpu_clist;
-
-static int
-sysctl_hlt_cpus(SYSCTL_HANDLER_ARGS)
-{
- u_int mask;
- int error;
-
- mask = hlt_cpus_mask;
- error = sysctl_handle_int(oidp, &mask, 0, req);
- if (error || !req->newptr)
- return (error);
-
- if (logical_cpus_mask != 0 &&
- (mask & logical_cpus_mask) == logical_cpus_mask)
- hlt_logical_cpus = 1;
- else
- hlt_logical_cpus = 0;
-
- if ((mask & all_cpus) == all_cpus)
- mask &= ~(1<<0);
- hlt_cpus_mask = mask;
- return (error);
-}
-SYSCTL_PROC(_machdep, OID_AUTO, hlt_cpus, CTLTYPE_INT|CTLFLAG_RW,
- 0, 0, sysctl_hlt_cpus, "IU", "");
-
-static int
-sysctl_hlt_logical_cpus(SYSCTL_HANDLER_ARGS)
-{
- int disable, error;
-
- disable = hlt_logical_cpus;
- error = sysctl_handle_int(oidp, &disable, 0, req);
- if (error || !req->newptr)
- return (error);
-
- if (disable)
- hlt_cpus_mask |= logical_cpus_mask;
- else
- hlt_cpus_mask &= ~logical_cpus_mask;
-
- if ((hlt_cpus_mask & all_cpus) == all_cpus)
- hlt_cpus_mask &= ~(1<<0);
-
- hlt_logical_cpus = disable;
- return (error);
-}
-
-static void
-cpu_hlt_setup(void *dummy __unused)
-{
-
- if (logical_cpus_mask != 0) {
- TUNABLE_INT_FETCH("machdep.hlt_logical_cpus",
- &hlt_logical_cpus);
- sysctl_ctx_init(&logical_cpu_clist);
- SYSCTL_ADD_PROC(&logical_cpu_clist,
- SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
- "hlt_logical_cpus", CTLTYPE_INT|CTLFLAG_RW, 0, 0,
- sysctl_hlt_logical_cpus, "IU", "");
- SYSCTL_ADD_UINT(&logical_cpu_clist,
- SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
- "logical_cpus_mask", CTLTYPE_INT|CTLFLAG_RD,
- &logical_cpus_mask, 0, "");
-
- if (hlt_logical_cpus)
- hlt_cpus_mask |= logical_cpus_mask;
- }
-}
-SYSINIT(cpu_hlt, SI_SUB_SMP, SI_ORDER_ANY, cpu_hlt_setup, NULL);
-
-int
-mp_grab_cpu_hlt(void)
-{
- u_int mask = PCPU_GET(cpumask);
- int retval;
-
- retval = mask & hlt_cpus_mask;
- while (mask & hlt_cpus_mask)
- __asm __volatile("sti; hlt" : : : "memory");
- return (retval);
-}
diff --git a/sys/i386/isa/atpic_vector.s b/sys/i386/isa/atpic_vector.s
deleted file mode 100644
index 1023635b2ae0..000000000000
--- a/sys/i386/isa/atpic_vector.s
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * from: vector.s, 386BSD 0.1 unknown origin
- * $FreeBSD$
- */
-
-#define IRQ_BIT(irq_num) (1 << ((irq_num) % 8))
-#define IRQ_LBIT(irq_num) (1 << (irq_num))
-#define IRQ_BYTE(irq_num) ((irq_num) >> 3)
-
-#ifdef AUTO_EOI_1
-
-#define ENABLE_ICU1 /* use auto-EOI to reduce i/o */
-#define OUTB_ICU1
-
-#else
-
-#define ENABLE_ICU1 \
- movb $ICU_EOI,%al ; /* as soon as possible send EOI ... */ \
- OUTB_ICU1 /* ... to clear in service bit */
-
-#define OUTB_ICU1 \
- outb %al,$IO_ICU1
-
-#endif
-
-#ifdef AUTO_EOI_2
-/*
- * The data sheet says no auto-EOI on slave, but it sometimes works.
- */
-#define ENABLE_ICU1_AND_2 ENABLE_ICU1
-
-#else
-
-#define ENABLE_ICU1_AND_2 \
- movb $ICU_EOI,%al ; /* as above */ \
- outb %al,$IO_ICU2 ; /* but do second icu first ... */ \
- OUTB_ICU1 /* ... then first icu (if !AUTO_EOI_1) */
-
-#endif
-
-#define PUSH_FRAME \
- pushl $0 ; /* dummy error code */ \
- pushl $0 ; /* dummy trap type */ \
- pushal ; /* 8 ints */ \
- pushl %ds ; /* save data and extra segments ... */ \
- pushl %es ; \
- pushl %fs
-
-#define PUSH_DUMMY \
- pushfl ; /* eflags */ \
- pushl %cs ; /* cs */ \
- pushl 12(%esp) ; /* original caller eip */ \
- pushl $0 ; /* dummy error code */ \
- pushl $0 ; /* dummy trap type */ \
- subl $11*4,%esp
-
-#define POP_FRAME \
- popl %fs ; \
- popl %es ; \
- popl %ds ; \
- popal ; \
- addl $4+4,%esp
-
-#define POP_DUMMY \
- addl $16*4,%esp
-
-#define MASK_IRQ(icu, irq_num) \
- movb imen + IRQ_BYTE(irq_num),%al ; \
- orb $IRQ_BIT(irq_num),%al ; \
- movb %al,imen + IRQ_BYTE(irq_num) ; \
- outb %al,$icu+ICU_IMR_OFFSET
-
-#define UNMASK_IRQ(icu, irq_num) \
- movb imen + IRQ_BYTE(irq_num),%al ; \
- andb $~IRQ_BIT(irq_num),%al ; \
- movb %al,imen + IRQ_BYTE(irq_num) ; \
- outb %al,$icu+ICU_IMR_OFFSET
-/*
- * Macros for interrupt interrupt entry, call to handler, and exit.
- */
-
-#define FAST_INTR(irq_num, vec_name, icu, enable_icus) \
- .text ; \
- SUPERALIGN_TEXT ; \
-IDTVEC(vec_name) ; \
- PUSH_FRAME ; \
- mov $KDSEL,%ax ; \
- mov %ax,%ds ; \
- mov %ax,%es ; \
- mov $KPSEL,%ax ; \
- mov %ax,%fs ; \
- FAKE_MCOUNT((12+ACTUALLY_PUSHED)*4(%esp)) ; \
- movl PCPU(CURTHREAD),%ebx ; \
- cmpl $0,TD_CRITNEST(%ebx) ; \
- je 1f ; \
-; \
- movl $1,PCPU(INT_PENDING) ; \
- orl $IRQ_LBIT(irq_num),PCPU(FPENDING) ; \
- MASK_IRQ(icu, irq_num) ; \
- enable_icus ; \
- jmp 10f ; \
-1: ; \
- incl TD_CRITNEST(%ebx) ; \
- incl TD_INTR_NESTING_LEVEL(%ebx) ; \
- pushl intr_unit + (irq_num) * 4 ; \
- call *intr_handler + (irq_num) * 4 ; \
- addl $4,%esp ; \
- enable_icus ; \
- incl cnt+V_INTR ; /* book-keeping can wait */ \
- movl intr_countp + (irq_num) * 4,%eax ; \
- incl (%eax) ; \
- decl TD_CRITNEST(%ebx) ; \
- cmpl $0,PCPU(INT_PENDING) ; \
- je 2f ; \
-; \
- call i386_unpend ; \
-2: ; \
- decl TD_INTR_NESTING_LEVEL(%ebx) ; \
-10: ; \
- MEXITCOUNT ; \
- jmp doreti
-
-/*
- * Restart a fast interrupt that was held up by a critical section.
- * This routine is called from unpend(). unpend() ensures we are
- * in a critical section and deals with the interrupt nesting level
- * for us. If we previously masked the irq, we have to unmask it.
- *
- * We have a choice. We can regenerate the irq using the 'int'
- * instruction or we can create a dummy frame and call the interrupt
- * handler directly. I've chosen to use the dummy-frame method.
- */
-#define FAST_UNPEND(irq_num, vec_name, icu) \
- .text ; \
- SUPERALIGN_TEXT ; \
-IDTVEC(vec_name) ; \
-; \
- pushl %ebp ; \
- movl %esp, %ebp ; \
- PUSH_DUMMY ; \
- pushl intr_unit + (irq_num) * 4 ; \
- call *intr_handler + (irq_num) * 4 ; /* do the work ASAP */ \
- addl $4, %esp ; \
- incl cnt+V_INTR ; /* book-keeping can wait */ \
- movl intr_countp + (irq_num) * 4,%eax ; \
- incl (%eax) ; \
- UNMASK_IRQ(icu, irq_num) ; \
- POP_DUMMY ; \
- popl %ebp ; \
- ret
-
-/*
- * Slow, threaded interrupts.
- *
- * XXX Most of the parameters here are obsolete. Fix this when we're
- * done.
- * XXX we really shouldn't return via doreti if we just schedule the
- * interrupt handler and don't run anything. We could just do an
- * iret. FIXME.
- */
-#define INTR(irq_num, vec_name, icu, enable_icus, maybe_extra_ipending) \
- .text ; \
- SUPERALIGN_TEXT ; \
-IDTVEC(vec_name) ; \
- PUSH_FRAME ; \
- mov $KDSEL,%ax ; /* load kernel ds, es and fs */ \
- mov %ax,%ds ; \
- mov %ax,%es ; \
- mov $KPSEL,%ax ; \
- mov %ax,%fs ; \
-; \
- maybe_extra_ipending ; \
- MASK_IRQ(icu, irq_num) ; \
- enable_icus ; \
-; \
- movl PCPU(CURTHREAD),%ebx ; \
- cmpl $0,TD_CRITNEST(%ebx) ; \
- je 1f ; \
- movl $1,PCPU(INT_PENDING); \
- orl $IRQ_LBIT(irq_num),PCPU(IPENDING) ; \
- jmp 10f ; \
-1: ; \
- incl TD_INTR_NESTING_LEVEL(%ebx) ; \
-; \
- FAKE_MCOUNT(13*4(%esp)) ; /* XXX late to avoid double count */ \
- cmpl $0,PCPU(INT_PENDING) ; \
- je 9f ; \
- call i386_unpend ; \
-9: ; \
- pushl $irq_num; /* pass the IRQ */ \
- call sched_ithd ; \
- addl $4, %esp ; /* discard the parameter */ \
-; \
- decl TD_INTR_NESTING_LEVEL(%ebx) ; \
-10: ; \
- MEXITCOUNT ; \
- jmp doreti
-
-MCOUNT_LABEL(bintr)
- FAST_INTR(0,fastintr0, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(1,fastintr1, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(2,fastintr2, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(3,fastintr3, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(4,fastintr4, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(5,fastintr5, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(6,fastintr6, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(7,fastintr7, IO_ICU1, ENABLE_ICU1)
- FAST_INTR(8,fastintr8, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(9,fastintr9, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(10,fastintr10, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(11,fastintr11, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(12,fastintr12, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(13,fastintr13, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(14,fastintr14, IO_ICU2, ENABLE_ICU1_AND_2)
- FAST_INTR(15,fastintr15, IO_ICU2, ENABLE_ICU1_AND_2)
-
-#define CLKINTR_PENDING movl $1,CNAME(clkintr_pending)
-/* Threaded interrupts */
- INTR(0,intr0, IO_ICU1, ENABLE_ICU1, CLKINTR_PENDING)
- INTR(1,intr1, IO_ICU1, ENABLE_ICU1,)
- INTR(2,intr2, IO_ICU1, ENABLE_ICU1,)
- INTR(3,intr3, IO_ICU1, ENABLE_ICU1,)
- INTR(4,intr4, IO_ICU1, ENABLE_ICU1,)
- INTR(5,intr5, IO_ICU1, ENABLE_ICU1,)
- INTR(6,intr6, IO_ICU1, ENABLE_ICU1,)
- INTR(7,intr7, IO_ICU1, ENABLE_ICU1,)
- INTR(8,intr8, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(9,intr9, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(10,intr10, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(11,intr11, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(12,intr12, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(13,intr13, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(14,intr14, IO_ICU2, ENABLE_ICU1_AND_2,)
- INTR(15,intr15, IO_ICU2, ENABLE_ICU1_AND_2,)
-
- FAST_UNPEND(0,fastunpend0, IO_ICU1)
- FAST_UNPEND(1,fastunpend1, IO_ICU1)
- FAST_UNPEND(2,fastunpend2, IO_ICU1)
- FAST_UNPEND(3,fastunpend3, IO_ICU1)
- FAST_UNPEND(4,fastunpend4, IO_ICU1)
- FAST_UNPEND(5,fastunpend5, IO_ICU1)
- FAST_UNPEND(6,fastunpend6, IO_ICU1)
- FAST_UNPEND(7,fastunpend7, IO_ICU1)
- FAST_UNPEND(8,fastunpend8, IO_ICU2)
- FAST_UNPEND(9,fastunpend9, IO_ICU2)
- FAST_UNPEND(10,fastunpend10, IO_ICU2)
- FAST_UNPEND(11,fastunpend11, IO_ICU2)
- FAST_UNPEND(12,fastunpend12, IO_ICU2)
- FAST_UNPEND(13,fastunpend13, IO_ICU2)
- FAST_UNPEND(14,fastunpend14, IO_ICU2)
- FAST_UNPEND(15,fastunpend15, IO_ICU2)
-MCOUNT_LABEL(eintr)
-
diff --git a/sys/i386/isa/nmi.c b/sys/i386/isa/nmi.c
deleted file mode 100644
index b0269555f2fc..000000000000
--- a/sys/i386/isa/nmi.c
+++ /dev/null
@@ -1,714 +0,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)isa.c 7.2 (Berkeley) 5/13/91
- * $FreeBSD$
- */
-
-#include "opt_auto_eoi.h"
-#include "opt_isa.h"
-#include "opt_mca.h"
-
-#include <sys/param.h>
-#include <sys/bus.h>
-#include <sys/errno.h>
-#include <sys/interrupt.h>
-#include <sys/kernel.h>
-#include <sys/kthread.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/module.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/syslog.h>
-#include <sys/systm.h>
-#include <sys/unistd.h>
-
-#include <machine/md_var.h>
-#include <machine/segments.h>
-
-#if defined(APIC_IO)
-#include <machine/smptests.h> /** FAST_HI */
-#include <machine/smp.h>
-#include <machine/resource.h>
-#endif /* APIC_IO */
-#ifdef PC98
-#include <pc98/pc98/pc98.h>
-#include <pc98/pc98/pc98_machdep.h>
-#include <pc98/pc98/epsonio.h>
-#else
-#include <i386/isa/isa.h>
-#endif
-#include <i386/isa/icu.h>
-
-#ifdef DEV_ISA
-#include <isa/isavar.h>
-#endif
-#include <i386/isa/intr_machdep.h>
-#include <sys/interrupt.h>
-#ifdef APIC_IO
-#include <machine/clock.h>
-#endif
-
-#ifdef DEV_MCA
-#include <i386/bios/mca_machdep.h>
-#endif
-
-/*
- * Per-interrupt data.
- */
-u_long *intr_countp[ICU_LEN]; /* pointers to interrupt counters */
-driver_intr_t *intr_handler[ICU_LEN]; /* first level interrupt handler */
-struct ithd *ithds[ICU_LEN]; /* real interrupt handler */
-void *intr_unit[ICU_LEN];
-
-static struct mtx ithds_table_lock; /* protect the ithds table */
-
-static inthand_t *fastintr[ICU_LEN] = {
- IDTVEC(fastintr0), IDTVEC(fastintr1),
- IDTVEC(fastintr2), IDTVEC(fastintr3),
- IDTVEC(fastintr4), IDTVEC(fastintr5),
- IDTVEC(fastintr6), IDTVEC(fastintr7),
- IDTVEC(fastintr8), IDTVEC(fastintr9),
- IDTVEC(fastintr10), IDTVEC(fastintr11),
- IDTVEC(fastintr12), IDTVEC(fastintr13),
- IDTVEC(fastintr14), IDTVEC(fastintr15),
-#if defined(APIC_IO)
- IDTVEC(fastintr16), IDTVEC(fastintr17),
- IDTVEC(fastintr18), IDTVEC(fastintr19),
- IDTVEC(fastintr20), IDTVEC(fastintr21),
- IDTVEC(fastintr22), IDTVEC(fastintr23),
- IDTVEC(fastintr24), IDTVEC(fastintr25),
- IDTVEC(fastintr26), IDTVEC(fastintr27),
- IDTVEC(fastintr28), IDTVEC(fastintr29),
- IDTVEC(fastintr30), IDTVEC(fastintr31),
-#endif /* APIC_IO */
-};
-
-static unpendhand_t *fastunpend[ICU_LEN] = {
- IDTVEC(fastunpend0), IDTVEC(fastunpend1),
- IDTVEC(fastunpend2), IDTVEC(fastunpend3),
- IDTVEC(fastunpend4), IDTVEC(fastunpend5),
- IDTVEC(fastunpend6), IDTVEC(fastunpend7),
- IDTVEC(fastunpend8), IDTVEC(fastunpend9),
- IDTVEC(fastunpend10), IDTVEC(fastunpend11),
- IDTVEC(fastunpend12), IDTVEC(fastunpend13),
- IDTVEC(fastunpend14), IDTVEC(fastunpend15),
-#if defined(APIC_IO)
- IDTVEC(fastunpend16), IDTVEC(fastunpend17),
- IDTVEC(fastunpend18), IDTVEC(fastunpend19),
- IDTVEC(fastunpend20), IDTVEC(fastunpend21),
- IDTVEC(fastunpend22), IDTVEC(fastunpend23),
- IDTVEC(fastunpend24), IDTVEC(fastunpend25),
- IDTVEC(fastunpend26), IDTVEC(fastunpend27),
- IDTVEC(fastunpend28), IDTVEC(fastunpend29),
- IDTVEC(fastunpend30), IDTVEC(fastunpend31),
-#endif /* APIC_IO */
-};
-
-static inthand_t *slowintr[ICU_LEN] = {
- IDTVEC(intr0), IDTVEC(intr1), IDTVEC(intr2), IDTVEC(intr3),
- IDTVEC(intr4), IDTVEC(intr5), IDTVEC(intr6), IDTVEC(intr7),
- IDTVEC(intr8), IDTVEC(intr9), IDTVEC(intr10), IDTVEC(intr11),
- IDTVEC(intr12), IDTVEC(intr13), IDTVEC(intr14), IDTVEC(intr15),
-#if defined(APIC_IO)
- IDTVEC(intr16), IDTVEC(intr17), IDTVEC(intr18), IDTVEC(intr19),
- IDTVEC(intr20), IDTVEC(intr21), IDTVEC(intr22), IDTVEC(intr23),
- IDTVEC(intr24), IDTVEC(intr25), IDTVEC(intr26), IDTVEC(intr27),
- IDTVEC(intr28), IDTVEC(intr29), IDTVEC(intr30), IDTVEC(intr31),
-#endif /* APIC_IO */
-};
-
-static driver_intr_t isa_strayintr;
-
-static void ithds_init(void *dummy);
-static void ithread_enable(int vector);
-static void ithread_disable(int vector);
-static void init_i8259(void);
-
-#ifdef PC98
-#define NMI_PARITY 0x04
-#define NMI_EPARITY 0x02
-#else
-#define NMI_PARITY (1 << 7)
-#define NMI_IOCHAN (1 << 6)
-#define ENMI_WATCHDOG (1 << 7)
-#define ENMI_BUSTIMER (1 << 6)
-#define ENMI_IOSTATUS (1 << 5)
-#endif
-
-#ifdef DEV_ISA
-/*
- * Bus attachment for the ISA PIC.
- */
-static struct isa_pnp_id atpic_ids[] = {
- { 0x0000d041 /* PNP0000 */, "AT interrupt controller" },
- { 0 }
-};
-
-static int
-atpic_probe(device_t dev)
-{
- int result;
-
- if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, atpic_ids)) <= 0)
- device_quiet(dev);
- return(result);
-}
-
-/*
- * In the APIC_IO case we might be granted IRQ 2, as this is typically
- * consumed by chaining between the two PIC components. If we're using
- * the APIC, however, this may not be the case, and as such we should
- * free the resource. (XXX untested)
- *
- * The generic ISA attachment code will handle allocating any other resources
- * that we don't explicitly claim here.
- */
-static int
-atpic_attach(device_t dev)
-{
-#ifdef APIC_IO
- int rid;
- struct resource *res;
-
- /* try to allocate our IRQ and then free it */
- rid = 0;
- res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 0);
- if (res != NULL)
- bus_release_resource(dev, SYS_RES_IRQ, rid, res);
-#endif
- return(0);
-}
-
-static device_method_t atpic_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, atpic_probe),
- DEVMETHOD(device_attach, atpic_attach),
- DEVMETHOD(device_detach, bus_generic_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
- { 0, 0 }
-};
-
-static driver_t atpic_driver = {
- "atpic",
- atpic_methods,
- 1, /* no softc */
-};
-
-static devclass_t atpic_devclass;
-
-DRIVER_MODULE(atpic, isa, atpic_driver, atpic_devclass, 0, 0);
-DRIVER_MODULE(atpic, acpi, atpic_driver, atpic_devclass, 0, 0);
-#endif /* DEV_ISA */
-
-/*
- * Handle a NMI, possibly a machine check.
- * return true to panic system, false to ignore.
- */
-int
-isa_nmi(cd)
- int cd;
-{
- int retval = 0;
-#ifdef PC98
- int port = inb(0x33);
-
- log(LOG_CRIT, "NMI PC98 port = %x\n", port);
- if (epson_machine_id == 0x20)
- epson_outb(0xc16, epson_inb(0xc16) | 0x1);
- if (port & NMI_PARITY) {
- log(LOG_CRIT, "BASE RAM parity error, likely hardware failure.");
- retval = 1;
- } else if (port & NMI_EPARITY) {
- log(LOG_CRIT, "EXTENDED RAM parity error, likely hardware failure.");
- retval = 1;
- } else {
- log(LOG_CRIT, "\nNMI Resume ??\n");
- }
-#else /* IBM-PC */
- int isa_port = inb(0x61);
- int eisa_port = inb(0x461);
-
- log(LOG_CRIT, "NMI ISA %x, EISA %x\n", isa_port, eisa_port);
-#ifdef DEV_MCA
- if (MCA_system && mca_bus_nmi())
- return(0);
-#endif
-
- if (isa_port & NMI_PARITY) {
- log(LOG_CRIT, "RAM parity error, likely hardware failure.");
- retval = 1;
- }
-
- if (isa_port & NMI_IOCHAN) {
- log(LOG_CRIT, "I/O channel check, likely hardware failure.");
- retval = 1;
- }
-
- /*
- * On a real EISA machine, this will never happen. However it can
- * happen on ISA machines which implement XT style floating point
- * error handling (very rare). Save them from a meaningless panic.
- */
- if (eisa_port == 0xff)
- return(retval);
-
- if (eisa_port & ENMI_WATCHDOG) {
- log(LOG_CRIT, "EISA watchdog timer expired, likely hardware failure.");
- retval = 1;
- }
-
- if (eisa_port & ENMI_BUSTIMER) {
- log(LOG_CRIT, "EISA bus timeout, likely hardware failure.");
- retval = 1;
- }
-
- if (eisa_port & ENMI_IOSTATUS) {
- log(LOG_CRIT, "EISA I/O port status error.");
- retval = 1;
- }
-#endif
- return(retval);
-}
-
-/*
- * ICU reinitialize when ICU configuration has lost.
- */
-void
-icu_reinit()
-{
- int i;
- register_t crit;
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- init_i8259();
- for(i=0;i<ICU_LEN;i++)
- if(intr_handler[i] != isa_strayintr)
- INTREN(1<<i);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-}
-
-/*
- * Create a default interrupt table to avoid problems caused by
- * spurious interrupts during configuration of kernel, then setup
- * interrupt control unit.
- */
-void
-isa_defaultirq()
-{
- int i;
- register_t crit;
-
- /* icu vectors */
- for (i = 0; i < ICU_LEN; i++)
- icu_unset(i, (driver_intr_t *)NULL);
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- init_i8259();
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-}
-
-
-/*
- *initialize 8259's
- */
-static void
-init_i8259()
-{
-
-#ifdef DEV_MCA
- if (MCA_system)
- outb(IO_ICU1, 0x19); /* reset; program device, four bytes */
- else
-#endif
- outb(IO_ICU1, 0x11); /* reset; program device, four bytes */
-
- outb(IO_ICU1+ICU_IMR_OFFSET, NRSVIDT); /* starting at this vector index */
- outb(IO_ICU1+ICU_IMR_OFFSET, IRQ_SLAVE); /* slave on line 7 */
-#ifdef PC98
-#ifdef AUTO_EOI_1
- outb(IO_ICU1+ICU_IMR_OFFSET, 0x1f); /* (master) auto EOI, 8086 mode */
-#else
- outb(IO_ICU1+ICU_IMR_OFFSET, 0x1d); /* (master) 8086 mode */
-#endif
-#else /* IBM-PC */
-#ifdef AUTO_EOI_1
- outb(IO_ICU1+ICU_IMR_OFFSET, 2 | 1); /* auto EOI, 8086 mode */
-#else
- outb(IO_ICU1+ICU_IMR_OFFSET, 1); /* 8086 mode */
-#endif
-#endif /* PC98 */
- outb(IO_ICU1+ICU_IMR_OFFSET, 0xff); /* leave interrupts masked */
- outb(IO_ICU1, 0x0a); /* default to IRR on read */
-#ifndef PC98
- outb(IO_ICU1, 0xc0 | (3 - 1)); /* pri order 3-7, 0-2 (com2 first) */
-#endif /* !PC98 */
-
-#ifdef DEV_MCA
- if (MCA_system)
- outb(IO_ICU2, 0x19); /* reset; program device, four bytes */
- else
-#endif
- outb(IO_ICU2, 0x11); /* reset; program device, four bytes */
-
- outb(IO_ICU2+ICU_IMR_OFFSET, NRSVIDT+8); /* staring at this vector index */
- outb(IO_ICU2+ICU_IMR_OFFSET, ICU_SLAVEID); /* my slave id is 7 */
-#ifdef PC98
- outb(IO_ICU2+ICU_IMR_OFFSET,9); /* 8086 mode */
-#else /* IBM-PC */
-#ifdef AUTO_EOI_2
- outb(IO_ICU2+ICU_IMR_OFFSET, 2 | 1); /* auto EOI, 8086 mode */
-#else
- outb(IO_ICU2+ICU_IMR_OFFSET,1); /* 8086 mode */
-#endif
-#endif /* PC98 */
- outb(IO_ICU2+ICU_IMR_OFFSET, 0xff); /* leave interrupts masked */
- outb(IO_ICU2, 0x0a); /* default to IRR on read */
-}
-
-/*
- * Caught a stray interrupt, notify
- */
-static void
-isa_strayintr(vcookiep)
- void *vcookiep;
-{
- int intr = (void **)vcookiep - &intr_unit[0];
-
- /*
- * XXX TODO print a different message for #7 if it is for a
- * glitch. Glitches can be distinguished from real #7's by
- * testing that the in-service bit is _not_ set. The test
- * must be done before sending an EOI so it can't be done if
- * we are using AUTO_EOI_1.
- */
- if (intrcnt[1 + intr] <= 5)
- log(LOG_ERR, "stray irq %d\n", intr);
- if (intrcnt[1 + intr] == 5)
- log(LOG_CRIT,
- "too many stray irq %d's; not logging any more\n", intr);
-}
-
-#ifdef DEV_ISA
-/*
- * Return a bitmap of the current interrupt requests. This is 8259-specific
- * and is only suitable for use at probe time.
- */
-intrmask_t
-isa_irq_pending()
-{
- u_char irr1;
- u_char irr2;
-
- irr1 = inb(IO_ICU1);
- irr2 = inb(IO_ICU2);
- return ((irr2 << 8) | irr1);
-}
-#endif
-
-/*
- * Update intrnames array with the specified name. This is used by
- * vmstat(8) and the like.
- */
-static void
-update_intrname(int intr, const char *name)
-{
- char buf[32];
- char *cp;
- int name_index, off, strayintr;
-
- /*
- * Initialise strings for bitbucket and stray interrupt counters.
- * These have statically allocated indices 0 and 1 through ICU_LEN.
- */
- if (intrnames[0] == '\0') {
- off = sprintf(intrnames, "???") + 1;
- for (strayintr = 0; strayintr < ICU_LEN; strayintr++)
- off += sprintf(intrnames + off, "stray irq%d",
- strayintr) + 1;
- }
-
- if (name == NULL)
- name = "???";
- if (snprintf(buf, sizeof(buf), "%s irq%d", name, intr) >= sizeof(buf))
- goto use_bitbucket;
-
- /*
- * Search for `buf' in `intrnames'. In the usual case when it is
- * not found, append it to the end if there is enough space (the \0
- * terminator for the previous string, if any, becomes a separator).
- */
- for (cp = intrnames, name_index = 0;
- cp != eintrnames && name_index < NR_INTRNAMES;
- cp += strlen(cp) + 1, name_index++) {
- if (*cp == '\0') {
- if (strlen(buf) >= eintrnames - cp)
- break;
- strcpy(cp, buf);
- goto found;
- }
- if (strcmp(cp, buf) == 0)
- goto found;
- }
-
-use_bitbucket:
- printf("update_intrname: counting %s irq%d as %s\n", name, intr,
- intrnames);
- name_index = 0;
-found:
- intr_countp[intr] = &intrcnt[name_index];
-}
-
-int
-icu_setup(int intr, driver_intr_t *handler, void *arg, int flags)
-{
-#ifdef FAST_HI
- int select; /* the select register is 8 bits */
- int vector;
- u_int32_t value; /* the window register is 32 bits */
-#endif /* FAST_HI */
- register_t crit;
-
-#if defined(APIC_IO)
- if ((u_int)intr >= ICU_LEN) /* no 8259 SLAVE to ignore */
-#else
- if ((u_int)intr >= ICU_LEN || intr == ICU_SLAVEID)
-#endif /* APIC_IO */
- return (EINVAL);
-#if 0
- if (intr_handler[intr] != isa_strayintr)
- return (EBUSY);
-#endif
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- intr_handler[intr] = handler;
- intr_unit[intr] = arg;
-#ifdef FAST_HI
- if (flags & INTR_FAST) {
- vector = TPR_FAST_INTS + intr;
- setidt(vector, fastintr[intr],
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- }
- else {
- vector = TPR_SLOW_INTS + intr;
- setidt(vector, slowintr[intr],
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
- }
-#ifdef APIC_INTR_REORDER
- set_lapic_isrloc(intr, vector);
-#endif
- /*
- * Reprogram the vector in the IO APIC.
- */
- if (int_to_apicintpin[intr].ioapic >= 0) {
- select = int_to_apicintpin[intr].redirindex;
- value = io_apic_read(int_to_apicintpin[intr].ioapic,
- select) & ~IOART_INTVEC;
- io_apic_write(int_to_apicintpin[intr].ioapic,
- select, value | vector);
- }
-#else
- setidt(ICU_OFFSET + intr,
- flags & INTR_FAST ? fastintr[intr] : slowintr[intr],
- SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif /* FAST_HI */
- INTREN(1 << intr);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
- return (0);
-}
-
-/*
- * Dissociate an interrupt handler from an IRQ and set the handler to
- * the stray interrupt handler. The 'handler' parameter is used only
- * for consistency checking.
- */
-int
-icu_unset(intr, handler)
- int intr;
- driver_intr_t *handler;
-{
- register_t crit;
-
- if ((u_int)intr >= ICU_LEN || handler != intr_handler[intr])
- return (EINVAL);
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTRDIS(1 << intr);
- intr_countp[intr] = &intrcnt[1 + intr];
- intr_handler[intr] = isa_strayintr;
- intr_unit[intr] = &intr_unit[intr];
-#ifdef FAST_HI_XXX
- /* XXX how do I re-create dvp here? */
- setidt(flags & INTR_FAST ? TPR_FAST_INTS + intr : TPR_SLOW_INTS + intr,
- slowintr[intr], SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#else /* FAST_HI */
-#ifdef APIC_INTR_REORDER
- set_lapic_isrloc(intr, ICU_OFFSET + intr);
-#endif
- setidt(ICU_OFFSET + intr, slowintr[intr], SDT_SYS386IGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
-#endif /* FAST_HI */
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
- return (0);
-}
-
-static void
-ithds_init(void *dummy)
-{
-
- mtx_init(&ithds_table_lock, "ithread table lock", NULL, MTX_SPIN);
-}
-SYSINIT(ithds_init, SI_SUB_INTR, SI_ORDER_SECOND, ithds_init, NULL);
-
-static void
-ithread_enable(int vector)
-{
- register_t crit;
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTREN(1 << vector);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-}
-
-static void
-ithread_disable(int vector)
-{
- register_t crit;
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTRDIS(1 << vector);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-}
-
-int
-inthand_add(const char *name, int irq, driver_intr_t handler, void *arg,
- enum intr_type flags, void **cookiep)
-{
- struct ithd *ithd; /* descriptor for the IRQ */
- int errcode = 0;
- int created_ithd = 0;
-
- /*
- * Work around a race where more than one CPU may be registering
- * handlers on the same IRQ at the same time.
- */
- mtx_lock_spin(&ithds_table_lock);
- ithd = ithds[irq];
- mtx_unlock_spin(&ithds_table_lock);
- if (ithd == NULL) {
- errcode = ithread_create(&ithd, irq, 0, ithread_disable,
- ithread_enable, "irq%d:", irq);
- if (errcode)
- return (errcode);
- mtx_lock_spin(&ithds_table_lock);
- if (ithds[irq] == NULL) {
- ithds[irq] = ithd;
- created_ithd++;
- mtx_unlock_spin(&ithds_table_lock);
- } else {
- struct ithd *orphan;
-
- orphan = ithd;
- ithd = ithds[irq];
- mtx_unlock_spin(&ithds_table_lock);
- ithread_destroy(orphan);
- }
- }
-
- errcode = ithread_add_handler(ithd, name, handler, arg,
- ithread_priority(flags), flags, cookiep);
-
- if ((flags & INTR_FAST) == 0 || errcode)
- /*
- * The interrupt process must be in place, but
- * not necessarily schedulable, before we
- * initialize the ICU, since it may cause an
- * immediate interrupt.
- */
- if (icu_setup(irq, sched_ithd, arg, flags) != 0)
- panic("inthand_add: Can't initialize ICU");
-
- if (errcode)
- return (errcode);
-
- if (flags & INTR_FAST) {
- errcode = icu_setup(irq, handler, arg, flags);
- if (errcode && bootverbose)
- printf("\tinthand_add(irq%d) failed, result=%d\n",
- irq, errcode);
- if (errcode)
- return (errcode);
- }
-
- update_intrname(irq, name);
- return (0);
-}
-
-/*
- * Deactivate and remove linked list the interrupt handler descriptor
- * data connected created by an earlier call of inthand_add(), then
- * adjust the interrupt masks if necessary.
- *
- * Return the memory held by the interrupt handler descriptor data
- * structure to the system. First ensure the handler is not actively
- * in use.
- */
-int
-inthand_remove(void *cookie)
-{
-
- return (ithread_remove_handler(cookie));
-}
-
-void
-call_fast_unpend(int irq)
-{
- fastunpend[irq]();
-}
-
diff --git a/sys/i386/pci/pci_pir.c b/sys/i386/pci/pci_pir.c
deleted file mode 100644
index 4a174bd1fd73..000000000000
--- a/sys/i386/pci/pci_pir.c
+++ /dev/null
@@ -1,822 +0,0 @@
-/*
- * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
- * Copyright (c) 2000, Michael Smith <msmith@freebsd.org>
- * 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 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 ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- *
- */
-
-#include <sys/param.h> /* XXX trim includes */
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/kernel.h>
-#include <sys/module.h>
-#include <sys/malloc.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <machine/md_var.h>
-#include <dev/pci/pcivar.h>
-#include <dev/pci/pcireg.h>
-#include <isa/isavar.h>
-#include <machine/pci_cfgreg.h>
-#include <machine/segments.h>
-#include <machine/pc/bios.h>
-
-#ifdef APIC_IO
-#include <machine/smp.h>
-#endif /* APIC_IO */
-
-#include "pcib_if.h"
-
-#define PRVERB(a) do { \
- if (bootverbose) \
- printf a ; \
-} while(0)
-
-static int cfgmech;
-static int devmax;
-
-static int pci_cfgintr_valid(struct PIR_entry *pe, int pin, int irq);
-static int pci_cfgintr_unique(struct PIR_entry *pe, int pin);
-static int pci_cfgintr_linked(struct PIR_entry *pe, int pin);
-static int pci_cfgintr_search(struct PIR_entry *pe, int bus, int device, int matchpin, int pin);
-static int pci_cfgintr_virgin(struct PIR_entry *pe, int pin);
-
-static void pci_print_irqmask(u_int16_t irqs);
-static void pci_print_route_table(struct PIR_table *prt, int size);
-static int pcireg_cfgread(int bus, int slot, int func, int reg, int bytes);
-static void pcireg_cfgwrite(int bus, int slot, int func, int reg, int data, int bytes);
-static int pcireg_cfgopen(void);
-
-static struct PIR_table *pci_route_table;
-static int pci_route_count;
-
-static struct mtx pcicfg_mtx;
-
-/*
- * Some BIOS writers seem to want to ignore the spec and put
- * 0 in the intline rather than 255 to indicate none. Some use
- * numbers in the range 128-254 to indicate something strange and
- * apparently undocumented anywhere. Assume these are completely bogus
- * and map them to 255, which means "none".
- */
-static __inline__ int
-pci_i386_map_intline(int line)
-{
- if (line == 0 || line >= 128)
- return (PCI_INVALID_IRQ);
- return (line);
-}
-
-static u_int16_t
-pcibios_get_version(void)
-{
- struct bios_regs args;
-
- if (PCIbios.ventry == 0) {
- PRVERB(("pcibios: No call entry point\n"));
- return (0);
- }
- args.eax = PCIBIOS_BIOS_PRESENT;
- if (bios32(&args, PCIbios.ventry, GSEL(GCODE_SEL, SEL_KPL))) {
- PRVERB(("pcibios: BIOS_PRESENT call failed\n"));
- return (0);
- }
- if (args.edx != 0x20494350) {
- PRVERB(("pcibios: BIOS_PRESENT didn't return 'PCI ' in edx\n"));
- return (0);
- }
- return (args.ebx & 0xffff);
-}
-
-/*
- * Initialise access to PCI configuration space
- */
-int
-pci_cfgregopen(void)
-{
- static int opened = 0;
- u_long sigaddr;
- static struct PIR_table *pt;
- u_int16_t v;
- u_int8_t ck, *cv;
- int i;
-
- if (opened)
- return(1);
-
- if (pcireg_cfgopen() == 0)
- return(0);
-
- v = pcibios_get_version();
- if (v > 0)
- printf("pcibios: BIOS version %x.%02x\n", (v & 0xff00) >> 8,
- v & 0xff);
-
- /*
- * Look for the interrupt routing table.
- *
- * We use PCI BIOS's PIR table if it's available $PIR is the
- * standard way to do this. Sadly, some machines are not
- * standards conforming and have _PIR instead. We shrug and cope
- * by looking for both.
- */
- if (pcibios_get_version() >= 0x0210 && pt == NULL) {
- sigaddr = bios_sigsearch(0, "$PIR", 4, 16, 0);
- if (sigaddr == 0)
- sigaddr = bios_sigsearch(0, "_PIR", 4, 16, 0);
- if (sigaddr != 0) {
- pt = (struct PIR_table *)(uintptr_t)
- BIOS_PADDRTOVADDR(sigaddr);
- for (cv = (u_int8_t *)pt, ck = 0, i = 0;
- i < (pt->pt_header.ph_length); i++) {
- ck += cv[i];
- }
- if (ck == 0 && pt->pt_header.ph_length >
- sizeof(struct PIR_header)) {
- pci_route_table = pt;
- pci_route_count = (pt->pt_header.ph_length -
- sizeof(struct PIR_header)) /
- sizeof(struct PIR_entry);
- printf("Using $PIR table, %d entries at %p\n",
- pci_route_count, pci_route_table);
- if (bootverbose)
- pci_print_route_table(pci_route_table,
- pci_route_count);
- }
- }
- }
- mtx_init(&pcicfg_mtx, "pcicfg", NULL, MTX_SPIN);
- opened = 1;
- return(1);
-}
-
-/*
- * Read configuration space register
- */
-u_int32_t
-pci_cfgregread(int bus, int slot, int func, int reg, int bytes)
-{
- uint32_t line;
-#ifdef APIC_IO
- uint32_t pin;
-
- /*
- * If we are using the APIC, the contents of the intline
- * register will probably be wrong (since they are set up for
- * use with the PIC. Rather than rewrite these registers
- * (maybe that would be smarter) we trap attempts to read them
- * and translate to our private vector numbers.
- */
- if ((reg == PCIR_INTLINE) && (bytes == 1)) {
-
- pin = pcireg_cfgread(bus, slot, func, PCIR_INTPIN, 1);
- line = pcireg_cfgread(bus, slot, func, PCIR_INTLINE, 1);
-
- if (pin != 0) {
- int airq;
-
- airq = pci_apic_irq(bus, slot, pin);
- if (airq >= 0) {
- /* PCI specific entry found in MP table */
- if (airq != line)
- undirect_pci_irq(line);
- return(airq);
- } else {
- /*
- * PCI interrupts might be redirected
- * to the ISA bus according to some MP
- * tables. Use the same methods as
- * used by the ISA devices devices to
- * find the proper IOAPIC int pin.
- */
- airq = isa_apic_irq(line);
- if ((airq >= 0) && (airq != line)) {
- /* XXX: undirect_pci_irq() ? */
- undirect_isa_irq(line);
- return(airq);
- }
- }
- }
- return(line);
- }
-#else
- /*
- * Some BIOS writers seem to want to ignore the spec and put
- * 0 in the intline rather than 255 to indicate none. The rest of
- * the code uses 255 as an invalid IRQ.
- */
- if (reg == PCIR_INTLINE && bytes == 1) {
- line = pcireg_cfgread(bus, slot, func, PCIR_INTLINE, 1);
- return pci_i386_map_intline(line);
- }
-#endif /* APIC_IO */
- return(pcireg_cfgread(bus, slot, func, reg, bytes));
-}
-
-/*
- * Write configuration space register
- */
-void
-pci_cfgregwrite(int bus, int slot, int func, int reg, u_int32_t data, int bytes)
-{
-
- pcireg_cfgwrite(bus, slot, func, reg, data, bytes);
-}
-
-/*
- * Route a PCI interrupt
- */
-int
-pci_cfgintr(int bus, int device, int pin, int oldirq)
-{
- struct PIR_entry *pe;
- int i, irq;
- struct bios_regs args;
- u_int16_t v;
- int already = 0;
- int errok = 0;
-
- v = pcibios_get_version();
- if (v < 0x0210) {
- PRVERB((
- "pci_cfgintr: BIOS %x.%02x doesn't support interrupt routing\n",
- (v & 0xff00) >> 8, v & 0xff));
- return (PCI_INVALID_IRQ);
- }
- if ((bus < 0) || (bus > 255) || (device < 0) || (device > 255) ||
- (pin < 1) || (pin > 4))
- return(PCI_INVALID_IRQ);
-
- /*
- * Scan the entry table for a contender
- */
- for (i = 0, pe = &pci_route_table->pt_entry[0]; i < pci_route_count;
- i++, pe++) {
- if ((bus != pe->pe_bus) || (device != pe->pe_device))
- continue;
- /*
- * A link of 0 means that this intpin is not connected to
- * any other device's interrupt pins and is not connected to
- * any of the Interrupt Router's interrupt pins, so we can't
- * route it.
- */
- if (pe->pe_intpin[pin - 1].link == 0)
- continue;
-
- if (pci_cfgintr_valid(pe, pin, oldirq)) {
- printf("pci_cfgintr: %d:%d INT%c BIOS irq %d\n", bus,
- device, 'A' + pin - 1, oldirq);
- return (oldirq);
- }
-
- /*
- * We try to find a linked interrupt, then we look to see
- * if the interrupt is uniquely routed, then we look for
- * a virgin interrupt. The virgin interrupt should return
- * an interrupt we can route, but if that fails, maybe we
- * should try harder to route a different interrupt.
- * However, experience has shown that that's rarely the
- * failure mode we see.
- */
- irq = pci_cfgintr_linked(pe, pin);
- if (irq != PCI_INVALID_IRQ)
- already = 1;
- if (irq == PCI_INVALID_IRQ) {
- irq = pci_cfgintr_unique(pe, pin);
- if (irq != PCI_INVALID_IRQ)
- errok = 1;
- }
- if (irq == PCI_INVALID_IRQ)
- irq = pci_cfgintr_virgin(pe, pin);
- if (irq == PCI_INVALID_IRQ)
- break;
-
- /*
- * Ask the BIOS to route the interrupt. If we picked an
- * interrupt that failed, we should really try other
- * choices that the BIOS offers us.
- *
- * For uniquely routed interrupts, we need to try
- * to route them on some machines. Yet other machines
- * fail to route, so we have to pretend that in that
- * case it worked. Isn't pc hardware fun?
- *
- * NOTE: if we want to whack hardware to do this, then
- * I think the right way to do that would be to have
- * bridge drivers that do this. I'm not sure that the
- * $PIR table would be valid for those interrupt
- * routers.
- */
- args.eax = PCIBIOS_ROUTE_INTERRUPT;
- args.ebx = (bus << 8) | (device << 3);
- /* pin value is 0xa - 0xd */
- args.ecx = (irq << 8) | (0xa + pin - 1);
- if (!already &&
- bios32(&args, PCIbios.ventry, GSEL(GCODE_SEL, SEL_KPL)) &&
- !errok) {
- PRVERB(("pci_cfgintr: ROUTE_INTERRUPT failed.\n"));
- return(PCI_INVALID_IRQ);
- }
- printf("pci_cfgintr: %d:%d INT%c routed to irq %d\n", bus,
- device, 'A' + pin - 1, irq);
- return(irq);
- }
-
- PRVERB(("pci_cfgintr: can't route an interrupt to %d:%d INT%c\n", bus,
- device, 'A' + pin - 1));
- return(PCI_INVALID_IRQ);
-}
-
-/*
- * Check to see if an existing IRQ setting is valid.
- */
-static int
-pci_cfgintr_valid(struct PIR_entry *pe, int pin, int irq)
-{
- uint32_t irqmask;
-
- if (!PCI_INTERRUPT_VALID(irq))
- return (0);
- irqmask = pe->pe_intpin[pin - 1].irqs;
- if (irqmask & (1 << irq)) {
- PRVERB(("pci_cfgintr_valid: BIOS irq %d is valid\n", irq));
- return (1);
- }
- return (0);
-}
-
-/*
- * Look to see if the routing table claims this pin is uniquely routed.
- */
-static int
-pci_cfgintr_unique(struct PIR_entry *pe, int pin)
-{
- int irq;
- uint32_t irqmask;
-
- irqmask = pe->pe_intpin[pin - 1].irqs;
- if (irqmask != 0 && powerof2(irqmask)) {
- irq = ffs(irqmask) - 1;
- PRVERB(("pci_cfgintr_unique: hard-routed to irq %d\n", irq));
- return(irq);
- }
- return(PCI_INVALID_IRQ);
-}
-
-/*
- * Look for another device which shares the same link byte and
- * already has a unique IRQ, or which has had one routed already.
- */
-static int
-pci_cfgintr_linked(struct PIR_entry *pe, int pin)
-{
- struct PIR_entry *oe;
- struct PIR_intpin *pi;
- int i, j, irq;
-
- /*
- * Scan table slots.
- */
- for (i = 0, oe = &pci_route_table->pt_entry[0]; i < pci_route_count;
- i++, oe++) {
- /* scan interrupt pins */
- for (j = 0, pi = &oe->pe_intpin[0]; j < 4; j++, pi++) {
-
- /* don't look at the entry we're trying to match */
- if ((pe == oe) && (i == (pin - 1)))
- continue;
- /* compare link bytes */
- if (pi->link != pe->pe_intpin[pin - 1].link)
- continue;
- /* link destination mapped to a unique interrupt? */
- if (pi->irqs != 0 && powerof2(pi->irqs)) {
- irq = ffs(pi->irqs) - 1;
- PRVERB(("pci_cfgintr_linked: linked (%x) to hard-routed irq %d\n",
- pi->link, irq));
- return(irq);
- }
-
- /*
- * look for the real PCI device that matches this
- * table entry
- */
- irq = pci_cfgintr_search(pe, oe->pe_bus, oe->pe_device,
- j, pin);
- if (irq != PCI_INVALID_IRQ)
- return(irq);
- }
- }
- return(PCI_INVALID_IRQ);
-}
-
-/*
- * Scan for the real PCI device at (bus)/(device) using intpin (matchpin) and
- * see if it has already been assigned an interrupt.
- */
-static int
-pci_cfgintr_search(struct PIR_entry *pe, int bus, int device, int matchpin, int pin)
-{
- devclass_t pci_devclass;
- device_t *pci_devices;
- int pci_count;
- device_t *pci_children;
- int pci_childcount;
- device_t *busp, *childp;
- int i, j, irq;
-
- /*
- * Find all the PCI busses.
- */
- pci_count = 0;
- if ((pci_devclass = devclass_find("pci")) != NULL)
- devclass_get_devices(pci_devclass, &pci_devices, &pci_count);
-
- /*
- * Scan all the PCI busses/devices looking for this one.
- */
- irq = PCI_INVALID_IRQ;
- for (i = 0, busp = pci_devices; (i < pci_count) && (irq == PCI_INVALID_IRQ);
- i++, busp++) {
- pci_childcount = 0;
- device_get_children(*busp, &pci_children, &pci_childcount);
-
- for (j = 0, childp = pci_children; j < pci_childcount; j++,
- childp++) {
- if ((pci_get_bus(*childp) == bus) &&
- (pci_get_slot(*childp) == device) &&
- (pci_get_intpin(*childp) == matchpin)) {
- irq = pci_i386_map_intline(pci_get_irq(*childp));
- if (irq != PCI_INVALID_IRQ)
- PRVERB(("pci_cfgintr_search: linked (%x) to configured irq %d at %d:%d:%d\n",
- pe->pe_intpin[pin - 1].link, irq,
- pci_get_bus(*childp),
- pci_get_slot(*childp),
- pci_get_function(*childp)));
- break;
- }
- }
- if (pci_children != NULL)
- free(pci_children, M_TEMP);
- }
- if (pci_devices != NULL)
- free(pci_devices, M_TEMP);
- return(irq);
-}
-
-/*
- * Pick a suitable IRQ from those listed as routable to this device.
- */
-static int
-pci_cfgintr_virgin(struct PIR_entry *pe, int pin)
-{
- int irq, ibit;
-
- /*
- * first scan the set of PCI-only interrupts and see if any of these
- * are routable
- */
- for (irq = 0; irq < 16; irq++) {
- ibit = (1 << irq);
-
- /* can we use this interrupt? */
- if ((pci_route_table->pt_header.ph_pci_irqs & ibit) &&
- (pe->pe_intpin[pin - 1].irqs & ibit)) {
- PRVERB(("pci_cfgintr_virgin: using routable PCI-only interrupt %d\n", irq));
- return(irq);
- }
- }
-
- /* life is tough, so just pick an interrupt */
- for (irq = 0; irq < 16; irq++) {
- ibit = (1 << irq);
- if (pe->pe_intpin[pin - 1].irqs & ibit) {
- PRVERB(("pci_cfgintr_virgin: using routable interrupt %d\n", irq));
- return(irq);
- }
- }
- return(PCI_INVALID_IRQ);
-}
-
-static void
-pci_print_irqmask(u_int16_t irqs)
-{
- int i, first;
-
- if (irqs == 0) {
- printf("none");
- return;
- }
- first = 1;
- for (i = 0; i < 16; i++, irqs >>= 1)
- if (irqs & 1) {
- if (!first)
- printf(" ");
- else
- first = 0;
- printf("%d", i);
- }
-}
-
-/*
- * Dump the contents of a PCI BIOS Interrupt Routing Table to the console.
- */
-static void
-pci_print_route_table(struct PIR_table *prt, int size)
-{
- struct PIR_entry *entry;
- struct PIR_intpin *intpin;
- int i, pin;
-
- printf("PCI-Only Interrupts: ");
- pci_print_irqmask(prt->pt_header.ph_pci_irqs);
- printf("\nLocation Bus Device Pin Link IRQs\n");
- entry = &prt->pt_entry[0];
- for (i = 0; i < size; i++, entry++) {
- intpin = &entry->pe_intpin[0];
- for (pin = 0; pin < 4; pin++, intpin++)
- if (intpin->link != 0) {
- if (entry->pe_slot == 0)
- printf("embedded ");
- else
- printf("slot %-3d ", entry->pe_slot);
- printf(" %3d %3d %c 0x%02x ",
- entry->pe_bus, entry->pe_device,
- 'A' + pin, intpin->link);
- pci_print_irqmask(intpin->irqs);
- printf("\n");
- }
- }
-}
-
-/*
- * See if any interrupts for a given PCI bus are routed in the PIR. Don't
- * even bother looking if the BIOS doesn't support routing anyways.
- */
-int
-pci_probe_route_table(int bus)
-{
- int i;
- u_int16_t v;
-
- v = pcibios_get_version();
- if (v < 0x0210)
- return (0);
- for (i = 0; i < pci_route_count; i++)
- if (pci_route_table->pt_entry[i].pe_bus == bus)
- return (1);
- return (0);
-}
-
-/*
- * Configuration space access using direct register operations
- */
-
-/* enable configuration space accesses and return data port address */
-static int
-pci_cfgenable(unsigned bus, unsigned slot, unsigned func, int reg, int bytes)
-{
- int dataport = 0;
-
- if (bus <= PCI_BUSMAX
- && slot < devmax
- && func <= PCI_FUNCMAX
- && reg <= PCI_REGMAX
- && bytes != 3
- && (unsigned) bytes <= 4
- && (reg & (bytes - 1)) == 0) {
- switch (cfgmech) {
- case 1:
- outl(CONF1_ADDR_PORT, (1 << 31)
- | (bus << 16) | (slot << 11)
- | (func << 8) | (reg & ~0x03));
- dataport = CONF1_DATA_PORT + (reg & 0x03);
- break;
- case 2:
- outb(CONF2_ENABLE_PORT, 0xf0 | (func << 1));
- outb(CONF2_FORWARD_PORT, bus);
- dataport = 0xc000 | (slot << 8) | reg;
- break;
- }
- }
- return (dataport);
-}
-
-/* disable configuration space accesses */
-static void
-pci_cfgdisable(void)
-{
- switch (cfgmech) {
- case 1:
- outl(CONF1_ADDR_PORT, 0);
- break;
- case 2:
- outb(CONF2_ENABLE_PORT, 0);
- outb(CONF2_FORWARD_PORT, 0);
- break;
- }
-}
-
-static int
-pcireg_cfgread(int bus, int slot, int func, int reg, int bytes)
-{
- int data = -1;
- int port;
-
- mtx_lock_spin(&pcicfg_mtx);
- port = pci_cfgenable(bus, slot, func, reg, bytes);
- if (port != 0) {
- switch (bytes) {
- case 1:
- data = inb(port);
- break;
- case 2:
- data = inw(port);
- break;
- case 4:
- data = inl(port);
- break;
- }
- pci_cfgdisable();
- }
- mtx_unlock_spin(&pcicfg_mtx);
- return (data);
-}
-
-static void
-pcireg_cfgwrite(int bus, int slot, int func, int reg, int data, int bytes)
-{
- int port;
-
- mtx_lock_spin(&pcicfg_mtx);
- port = pci_cfgenable(bus, slot, func, reg, bytes);
- if (port != 0) {
- switch (bytes) {
- case 1:
- outb(port, data);
- break;
- case 2:
- outw(port, data);
- break;
- case 4:
- outl(port, data);
- break;
- }
- pci_cfgdisable();
- }
- mtx_unlock_spin(&pcicfg_mtx);
-}
-
-/* check whether the configuration mechanism has been correctly identified */
-static int
-pci_cfgcheck(int maxdev)
-{
- uint32_t id, class;
- uint8_t header;
- uint8_t device;
- int port;
-
- if (bootverbose)
- printf("pci_cfgcheck:\tdevice ");
-
- for (device = 0; device < maxdev; device++) {
- if (bootverbose)
- printf("%d ", device);
-
- port = pci_cfgenable(0, device, 0, 0, 4);
- id = inl(port);
- if (id == 0 || id == 0xffffffff)
- continue;
-
- port = pci_cfgenable(0, device, 0, 8, 4);
- class = inl(port) >> 8;
- if (bootverbose)
- printf("[class=%06x] ", class);
- if (class == 0 || (class & 0xf870ff) != 0)
- continue;
-
- port = pci_cfgenable(0, device, 0, 14, 1);
- header = inb(port);
- if (bootverbose)
- printf("[hdr=%02x] ", header);
- if ((header & 0x7e) != 0)
- continue;
-
- if (bootverbose)
- printf("is there (id=%08x)\n", id);
-
- pci_cfgdisable();
- return (1);
- }
- if (bootverbose)
- printf("-- nothing found\n");
-
- pci_cfgdisable();
- return (0);
-}
-
-static int
-pcireg_cfgopen(void)
-{
- uint32_t mode1res, oldval1;
- uint8_t mode2res, oldval2;
-
- oldval1 = inl(CONF1_ADDR_PORT);
-
- if (bootverbose) {
- printf("pci_open(1):\tmode 1 addr port (0x0cf8) is 0x%08x\n",
- oldval1);
- }
-
- if ((oldval1 & CONF1_ENABLE_MSK) == 0) {
-
- cfgmech = 1;
- devmax = 32;
-
- outl(CONF1_ADDR_PORT, CONF1_ENABLE_CHK);
- outb(CONF1_ADDR_PORT + 3, 0);
- mode1res = inl(CONF1_ADDR_PORT);
- outl(CONF1_ADDR_PORT, oldval1);
-
- if (bootverbose)
- printf("pci_open(1a):\tmode1res=0x%08x (0x%08lx)\n",
- mode1res, CONF1_ENABLE_CHK);
-
- if (mode1res) {
- if (pci_cfgcheck(32))
- return (cfgmech);
- }
-
- outl(CONF1_ADDR_PORT, CONF1_ENABLE_CHK1);
- mode1res = inl(CONF1_ADDR_PORT);
- outl(CONF1_ADDR_PORT, oldval1);
-
- if (bootverbose)
- printf("pci_open(1b):\tmode1res=0x%08x (0x%08lx)\n",
- mode1res, CONF1_ENABLE_CHK1);
-
- if ((mode1res & CONF1_ENABLE_MSK1) == CONF1_ENABLE_RES1) {
- if (pci_cfgcheck(32))
- return (cfgmech);
- }
- }
-
- oldval2 = inb(CONF2_ENABLE_PORT);
-
- if (bootverbose) {
- printf("pci_open(2):\tmode 2 enable port (0x0cf8) is 0x%02x\n",
- oldval2);
- }
-
- if ((oldval2 & 0xf0) == 0) {
-
- cfgmech = 2;
- devmax = 16;
-
- outb(CONF2_ENABLE_PORT, CONF2_ENABLE_CHK);
- mode2res = inb(CONF2_ENABLE_PORT);
- outb(CONF2_ENABLE_PORT, oldval2);
-
- if (bootverbose)
- printf("pci_open(2a):\tmode2res=0x%02x (0x%02x)\n",
- mode2res, CONF2_ENABLE_CHK);
-
- if (mode2res == CONF2_ENABLE_RES) {
- if (bootverbose)
- printf("pci_open(2a):\tnow trying mechanism 2\n");
-
- if (pci_cfgcheck(16))
- return (cfgmech);
- }
- }
-
- cfgmech = 0;
- devmax = 0;
- return (cfgmech);
-}
-
diff --git a/sys/i4b/include/i4b_cause.h b/sys/i4b/include/i4b_cause.h
deleted file mode 100644
index c98683a9ff39..000000000000
--- a/sys/i4b/include/i4b_cause.h
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (c) 1997, 2002 Hellmuth Michaelis. 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.
- *
- *---------------------------------------------------------------------------
- *
- * i4b_cause.h - causes and cause handling for i4b
- * -----------------------------------------------
- *
- * $FreeBSD$
- *
- * last edit-date: [Sun Mar 17 10:08:21 2002]
- *
- *---------------------------------------------------------------------------*/
-
-#ifndef _I4B_CAUSE_H_
-#define _I4B_CAUSE_H_
-
-/*---------------------------------------------------------------------------*
- * ISDN4BSD internal causes specification
- *---------------------------------------------------------------------------*/
-
-#define CAUSE_VAL 0x000000ff /* cause value */
-#define CAUSE_TYPE 0x0000ff00 /* cause type */
-#define CAUSET_Q850 0 /* value coded according to Q.850 */
-#define CAUSET_I4B 1 /* i4b protocol independent causes*/
-
-#define GET_CAUSE_VAL(cause) ((cause) & 0xff)
-#define SET_CAUSE_VAL(dest, val) ((dest) = ((dest & 0xffffff00) | \
- (val & 0x000000ff)))
-
-#define GET_CAUSE_TYPE(cause) (((cause) >> 8) & 0xff)
-#define SET_CAUSE_TYPE(dest, type) ((dest) = ((dest & 0xffff00ff) | \
- ((type << 8) & 0x0000ff00)))
-
-#define SET_CAUSE_TV(dest, type, val) ((dest) = ((val & 0x000000ff) | \
- ((type << 8) & 0x0000ff00)))
-
-/* CAUSET_I4B - protocol independent cause values */
-
-#define CAUSE_I4B_NORMAL 0 /* normal call clearing */
-#define CAUSE_I4B_BUSY 1 /* user busy */
-#define CAUSE_I4B_NOCHAN 2 /* circuit/channel not available*/
-#define CAUSE_I4B_INCOMP 3 /* incompatible source/dest */
-#define CAUSE_I4B_REJECT 4 /* call rejected */
-#define CAUSE_I4B_OOO 5 /* destination out of order */
-#define CAUSE_I4B_TMPFAIL 6 /* temporary failure */
-#define CAUSE_I4B_L1ERROR 7 /* L1 error / persistent deact */
-#define CAUSE_I4B_LLDIAL 8 /* no dialout on leased line */
-#define CAUSE_I4B_MAX 9
- /* NOTE: update isdnd/pcause.c when adding causes !!!!! */
- /* NOTE: update layer3/i4b_q931.c when adding causes !!!!! */
-
-/* CAUSET_Q850 - causes defined in Q.850 */
-
-#define CAUSE_Q850_SHUTDN 0x00 /* normal D-channel shutdown */
-#define CAUSE_Q850_NUNALLC 0x01 /* Unallocated (unassigned) number */
-#define CAUSE_Q850_NRTTN 0x02 /* No route to specified transit network */
-#define CAUSE_Q850_NRTDST 0x03 /* No route to destination */
-#define CAUSE_Q850_SSINFTN 0x04 /* Send special information tone */
-#define CAUSE_Q850_MDIALTP 0x05 /* Misdialled trunk prefix */
-#define CAUSE_Q850_CHUNACC 0x06 /* Channel unacceptable */
-#define CAUSE_Q850_CALLAWD 0x07 /* Call awarded and being delivered in an established channel */
-#define CAUSE_Q850_PREEMPT 0x08 /* Preemption */
-#define CAUSE_Q850_PREECRR 0x09 /* Preemption - circuit reserved for reuse */
-#define CAUSE_Q850_NCCLR 0x10 /* Normal call clearing */
-#define CAUSE_Q850_USRBSY 0x11 /* User busy */
-#define CAUSE_Q850_NOUSRRSP 0x12 /* No user responding */
-#define CAUSE_Q850_NOANSWR 0x13 /* No answer from user (user alerted) */
-#define CAUSE_Q850_SUBSABS 0x14 /* Subscriber absent */
-#define CAUSE_Q850_CALLREJ 0x15 /* Call rejected */
-#define CAUSE_Q850_NUCHNG 0x16 /* Number changed */
-#define CAUSE_Q850_NONSELUC 0x1A /* Non-selected user clearing */
-#define CAUSE_Q850_DSTOOORDR 0x1B /* Destination out of order */
-#define CAUSE_Q850_INVNUFMT 0x1C /* Invalid number format */
-#define CAUSE_Q850_FACREJ 0x1D /* Facility rejected */
-#define CAUSE_Q850_STENQRSP 0x1E /* Response to STATUS ENQUIRY */
-#define CAUSE_Q850_NORMUNSP 0x1F /* Normal, unspecified */
-#define CAUSE_Q850_NOCAVAIL 0x22 /* No circuit / channel available */
-#define CAUSE_Q850_NETOOORDR 0x26 /* Network out of order */
-#define CAUSE_Q850_PFMCDOOSERV 0x27 /* Permanent frame mode connection out of service */
-#define CAUSE_Q850_PFMCOPER 0x28 /* Permanent frame mode connection operational */
-#define CAUSE_Q850_TMPFAIL 0x29 /* Temporary failure */
-#define CAUSE_Q850_SWEQCONG 0x2A /* Switching equipment congestion */
-#define CAUSE_Q850_ACCINFDIS 0x2B /* Access information discarded */
-#define CAUSE_Q850_REQCNOTAV 0x2C /* Requested circuit/channel not available */
-#define CAUSE_Q850_PRECALBLK 0x2E /* Precedence call blocked */
-#define CAUSE_Q850_RESUNAVAIL 0x2F /* Resources unavailable, unspecified */
-#define CAUSE_Q850_QOSUNAVAIL 0x31 /* Quality of service unavailable */
-#define CAUSE_Q850_REQSERVNS 0x32 /* Requested facility not subscribed */
-#define CAUSE_Q850_OCBARRCUG 0x35 /* Outgoing calls barred within CUG */
-#define CAUSE_Q850_ICBARRCUG 0x36 /* Incoming calls barred within CUG */
-#define CAUSE_Q850_BCAPNAUTH 0x39 /* Bearer capability not authorized */
-#define CAUSE_Q850_BCAPNAVAIL 0x3A /* Bearer capability not presently available */
-#define CAUSE_Q850_INCSTOACISC 0x3E /* Inconsistenciy in designated outgoing access information and subscriber class */
-#define CAUSE_Q850_SOONOTAVAIL 0x3F /* Service or option not available, unspecified */
-#define CAUSE_Q850_BCAPNOTIMPL 0x41 /* Bearer capability not implemented */
-#define CAUSE_Q850_CHTYPNIMPL 0x42 /* Channel type not implemented */
-#define CAUSE_Q850_REQFACNIMPL 0x45 /* Requested facility not implemented */
-#define CAUSE_Q850_ORDINBCAVL 0x46 /* Only restricted digital information bearer capability is available */
-#define CAUSE_Q850_SOONOTIMPL 0x4F /* Service or option not implemented, unspecified */
-#define CAUSE_Q850_INVCLRFVAL 0x51 /* Invalid call reference value */
-#define CAUSE_Q850_IDCHDNOEX 0x52 /* Identified channel does not exist */
-#define CAUSE_Q850_SUSCAEXIN 0x53 /* A suspended call exists, but this call identity does not */
-#define CAUSE_Q850_CLIDINUSE 0x54 /* Call identity in use */
-#define CAUSE_Q850_NOCLSUSP 0x55 /* No call suspended */
-#define CAUSE_Q850_CLIDCLRD 0x56 /* Call having the requested call identity has been cleared */
-#define CAUSE_Q850_UNOTMEMCUG 0x57 /* User not member of CUG */
-#define CAUSE_Q850_INCDEST 0x58 /* Incompatible destination */
-#define CAUSE_Q850_NONEXCUG 0x5A /* Non-existent CUG */
-#define CAUSE_Q850_INVNTWSEL 0x5B /* Invalid transit network selection */
-#define CAUSE_Q850_INVMSG 0x5F /* Invalid message, unspecified */
-#define CAUSE_Q850_MIEMISS 0x60 /* Mandatory information element is missing */
-#define CAUSE_Q850_MSGTNI 0x61 /* Message type non-existent or not implemented */
-#define CAUSE_Q850_MSGNCMPT 0x62 /* Message not compatible with call state or message type non-existent or not implemented */
-#define CAUSE_Q850_IENENI 0x63 /* Information element/parameter non-existent or not implemented */
-#define CAUSE_Q850_INVIEC 0x64 /* Invalid information element contents */
-#define CAUSE_Q850_MSGNCWCS 0x65 /* Message not compatible with call state */
-#define CAUSE_Q850_RECOTIMEXP 0x66 /* Recovery on timer expiry */
-#define CAUSE_Q850_PARMNENIPO 0x67 /* Parameter non-existent or not implemented, passed on */
-#define CAUSE_Q850_MSGUNRDPRM 0x6E /* Message with unrecognized parameter, discarded */
-#define CAUSE_Q850_PROTERR 0x6F /* Protocol error, unspecified */
-#define CAUSE_Q850_INTWRKU 0x7F /* Interworking, unspecified */
-
-#define CAUSE_Q850_MAX 128
-
-#endif /* _I4B_CAUSE_H_ */
diff --git a/sys/i4b/include/i4b_debug.h b/sys/i4b/include/i4b_debug.h
deleted file mode 100644
index ac8f6a84d295..000000000000
--- a/sys/i4b/include/i4b_debug.h
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * Copyright (c) 1997, 2002 Hellmuth Michaelis. 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.
- *
- *---------------------------------------------------------------------------
- *
- * i4b_debug.h - i4b debug header file
- * -----------------------------------
- *
- * $FreeBSD$
- *
- * last edit-date: [Sun Mar 17 10:08:41 2002]
- *
- *---------------------------------------------------------------------------*/
-
-#if !defined DO_I4B_DEBUG
-# define DO_I4B_DEBUG 1 /* default = include debugging code */
-#elif DO_I4B_DEBUG != 0
-# undef DO_I4B_DEBUG
-# define DO_I4B_DEBUG 1
-#endif
-
-#undef DO_I4B_MAXDEBUG /* default = disable ALL debug messages */
-
-#if DO_I4B_DEBUG
-
-extern unsigned int i4b_l1_debug;
-extern unsigned int i4b_l2_debug;
-extern unsigned int i4b_l3_debug;
-extern unsigned int i4b_l4_debug;
-
-#define NDBGL1(bits, fmt, args...) \
- if(bits & i4b_l1_debug) \
- { printf("i4b-L1 %s: " fmt "\n", __func__ , ##args ); }
-
-#define NDBGL2(bits, fmt, args...) \
- if(bits & i4b_l2_debug) \
- { printf("i4b-L2 %s: " fmt "\n", __func__ , ##args ); }
-
-#define NDBGL3(bits, fmt, args...) \
- if(bits & i4b_l3_debug) \
- { printf("i4b-L3 %s: " fmt "\n", __func__ , ##args ); }
-
-#define NDBGL4(bits, fmt, args...) \
- if(bits & i4b_l4_debug) \
- { printf("i4b-L4 %s: " fmt "\n", __func__ , ##args ); }
-
-#else /* !DO_I4B_DEBUG */
-
-#define NDBGL1(bits, fmt, args...);
-#define NDBGL2(bits, fmt, args...);
-#define NDBGL3(bits, fmt, args...);
-#define NDBGL4(bits, fmt, args...);
-
-#endif /* DO_I4B_DEBUG */
-
-/* Layer 1 */
-
-#define L1_ERROR 0x000001 /* general error message*/
-#define L1_PRIM 0x000002 /* interlayer primitives*/
-#define L1_BCHAN 0x000004 /* B channel action */
-#define L1_H_ERR 0x000008 /* HSCX errors */
-#define L1_H_IRQ 0x000010 /* HSCX IRQ messages */
-#define L1_I_ERR 0x000020 /* ISAC errors */
-#define L1_I_MSG 0x000040 /* ISAC messages */
-#define L1_I_SETUP 0x000080 /* ISAC setup messages */
-#define L1_F_MSG 0x000100 /* FSM messages */
-#define L1_F_ERR 0x000200 /* FSM error messages */
-#define L1_T_MSG 0x000400 /* Timer messages */
-#define L1_T_ERR 0x000800 /* Timer error messages */
-#define L1_H_XFRERR 0x001000 /* HSCX data xfer error */
-#define L1_I_CICO 0x002000 /* ISAC command in/out */
-#define L1_S_MSG 0x004000 /* silent messages (soft-HDLC) */
-#define L1_S_ERR 0x008000 /* error messages (soft-HDLC) */
-#define L1_HFC_DBG 0x010000 /* HFC-S PCI messages */
-#define L1_DEBUG_MAX 0x01ffef /* all messages on except IRQ! */
-#define L1_DEBUG_ERR (L1_S_ERR | L1_H_ERR | L1_I_ERR | L1_F_ERR | L1_T_ERR | L1_ERROR)
-
-#ifndef L1_DEBUG_DEFAULT
-#ifdef DO_I4B_MAXDEBUG
-#define L1_DEBUG_DEFAULT L1_DEBUG_MAX
-#else
-#define L1_DEBUG_DEFAULT L1_DEBUG_ERR
-#endif
-#endif
-
-/* Layer 2 */
-
-#define L2_ERROR 0x0001 /* general error message */
-#define L2_PRIM 0x0002 /* interlayer primitives */
-#define L2_U_MSG 0x0004 /* U frame messages */
-#define L2_U_ERR 0x0008 /* U frame error messages */
-#define L2_S_MSG 0x0010 /* S frame messages */
-#define L2_S_ERR 0x0020 /* S frame error messages */
-#define L2_I_MSG 0x0040 /* I frame messages */
-#define L2_I_ERR 0x0080 /* I frame error messages */
-#define L2_F_MSG 0x0100 /* FSM messages */
-#define L2_F_ERR 0x0200 /* FSM error messages */
-#define L2_T_MSG 0x0400 /* timer messages */
-#define L2_T_ERR 0x0800 /* timer error messages */
-#define L2_TEI_MSG 0x1000 /* TEI messages */
-#define L2_TEI_ERR 0x2000 /* TEI error messages */
-
-#define L2_DEBUG_MAX 0x3fff /* all messages on */
-#define L2_DEBUG_ERR (L2_ERROR | L2_I_ERR | L2_F_ERR | L2_T_ERR | L2_S_ERR | L2_TEI_ERR | L2_U_ERR )
-
-#ifndef L2_DEBUG_DEFAULT
-#ifdef DO_I4B_MAXDEBUG
-#define L2_DEBUG_DEFAULT L2_DEBUG_MAX
-#else
-#define L2_DEBUG_DEFAULT L2_DEBUG_ERR
-#endif
-#endif
-
-/* Layer 3 */
-
-#define L3_ERR 0x0001 /* general error message */
-#define L3_MSG 0x0002 /* general message */
-#define L3_F_MSG 0x0004 /* FSM messages */
-#define L3_F_ERR 0x0008 /* FSM error messages */
-#define L3_T_MSG 0x0010 /* timer messages */
-#define L3_T_ERR 0x0020 /* timer error messages */
-#define L3_P_MSG 0x0040 /* protocol messages */
-#define L3_P_ERR 0x0080 /* protocol error messages */
-#define L3_A_MSG 0x0100 /* AOC messages */
-#define L3_A_ERR 0x0200 /* AOC error messages */
-#define L3_PRIM 0x0400 /* messages exchanged */
-
-#define L3_DEBUG_MAX 0x07ff /* all messages on */
-#define L3_DEBUG_ERR (L3_ERR | L3_F_ERR | L3_T_ERR | L3_P_ERR | L3_A_ERR)
-
-#ifndef L3_DEBUG_DEFAULT
-#ifdef DO_I4B_MAXDEBUG
-#define L3_DEBUG_DEFAULT L3_DEBUG_MAX
-#else
-#define L3_DEBUG_DEFAULT L3_DEBUG_ERR
-#endif
-#endif
-
-/* Layer 4 */
-
-#define L4_ERR 0x0001 /* general error message */
-#define L4_MSG 0x0002 /* general message */
-#define L4_TIMO 0x0004 /* b channel idle timeout msgs */
-#define L4_DIALST 0x0008 /* network driver dial states */
-#define L4_IPRDBG 0x0010 /* ipr driver debug messages */
-#define L4_RBCHDBG 0x0020 /* rbch driver debug messages */
-#define L4_ISPDBG 0x0040 /* isp driver debug messages */
-#define L4_TELDBG 0x0080 /* tel driver debug messages */
-#define L4_INGDBG 0x0100 /* ing driver debug messages */
-#define L4_IAVCDBG 0x0200 /* AVM B1 driver debug messages */
-#define L4_CAPIDBG 0x0400 /* CAPI driver debug messages */
-
-#define L4_DEBUG_MAX 0x0fff /* all messages on */
-#define L4_DEBUG_ERR L4_ERR
-
-#ifndef L4_DEBUG_DEFAULT
-#ifdef DO_I4B_MAXDEBUG
-#define L4_DEBUG_DEFAULT L4_DEBUG_MAX
-#else
-#define L4_DEBUG_DEFAULT L4_DEBUG_ERR
-#endif
-#endif
-
-/*---------------------------------------------------------------------------*
- * ioctl via /dev/i4bctl:
- * get/set current debug bits settings
- *---------------------------------------------------------------------------*/
-
-typedef struct {
- unsigned int l1;
- unsigned int l2;
- unsigned int l3;
- unsigned int l4;
-} ctl_debug_t;
-
-#define I4B_CTL_GET_DEBUG _IOR('C', 0, ctl_debug_t)
-
-#define I4B_CTL_SET_DEBUG _IOW('C', 1, ctl_debug_t)
-
-/*---------------------------------------------------------------------------*
- * generic get chipset statistics
- *---------------------------------------------------------------------------*/
-
-/* for the ihfc-driver: structure for HFC-1/S/SP statistics */
-
-typedef struct {
- int txframes;
- int rxframes;
- int xdu;
- int rdo;
- int crc;
- int rab;
-} hfcstat_t;
-
-
-/* for the isic-driver: structure for HSCX statistics */
-
-typedef struct {
- int unit; /* controller number */
- int chan; /* channel number */
- int vfr;
- int rdo;
- int crc;
- int rab;
- int xdu;
- int rfo;
-} hscxstat_t;
-
-/* generic statistics structure */
-
-struct chipstat {
- int driver_type; /* type, L1DRVR_XXXX */
- int driver_unit; /* the unit number */
- int driver_bchannel; /* the B-channel */
- union stats { /* union for all drivers */
- hfcstat_t hfcstat; /* for ihfc driver, L1DRVR_IHFC */
- hscxstat_t hscxstat; /* for isic driver, L1DRVR_ISIC */
- } stats;
-};
-
-/* get statistics */
-
-#define I4B_CTL_GET_CHIPSTAT _IOWR('C', 2, struct chipstat)
-
-/* clear statistics */
-
-#define I4B_CTL_CLR_CHIPSTAT _IOW('C', 3, struct chipstat)
-
-/*---------------------------------------------------------------------------*
- * get LAPD/Q.921 statistics
- *---------------------------------------------------------------------------*/
-typedef struct {
-
- /* transmit */
-
- u_long tx_i; /* I */
- u_long tx_rr; /* RR */
- u_long tx_rnr; /* RNR */
- u_long tx_rej; /* REJ */
- u_long tx_sabme; /* SABME*/
- u_long tx_dm; /* DM */
- u_long tx_disc; /* DISC */
- u_long tx_ua; /* UA */
- u_long tx_frmr; /* FRMR */
- u_long tx_tei; /* TEI */
-
- /* receive */
-
- u_long rx_i; /* I */
- u_long rx_rr; /* RR */
- u_long rx_rnr; /* RNR */
- u_long rx_rej; /* REJ */
- u_long rx_sabme; /* SABME*/
- u_long rx_tei; /* TEI */
- u_long rx_ui; /* UI */
- u_long rx_disc; /* DISC */
- u_long rx_xid; /* XID */
- u_long rx_dm; /* DM */
- u_long rx_ua; /* UA */
- u_long rx_frmr; /* FRMR */
-
- /* errors */
-
- u_long err_rx_len; /* incorrect length */
- u_long err_rx_badf; /* bad frame type */
- u_long err_rx_bads; /* bad s frame */
- u_long err_rx_badu; /* bad u frame */
- u_long err_rx_badui; /* bad ui frame */
-} lapdstat_t;
-
-typedef struct {
- int unit;
- lapdstat_t lapdstat;
-} l2stat_t;
-
-#define I4B_CTL_GET_LAPDSTAT _IOWR('C', 4, l2stat_t)
-
-#define I4B_CTL_CLR_LAPDSTAT _IOW('C', 5, int)
-
-/* EOF */
diff --git a/sys/i4b/include/i4b_ioctl.h b/sys/i4b/include/i4b_ioctl.h
deleted file mode 100644
index 9df6adb76ece..000000000000
--- a/sys/i4b/include/i4b_ioctl.h
+++ /dev/null
@@ -1,742 +0,0 @@
-/*
- * Copyright (c) 1997, 2002 Hellmuth Michaelis. 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.
- *
- *---------------------------------------------------------------------------
- *
- * i4b_ioctl.h - messages kernel <--> userland
- * -------------------------------------------
- *
- * $FreeBSD$
- *
- * last edit-date: [Sun Aug 11 19:19:08 2002]
- *
- *---------------------------------------------------------------------------*/
-
-#ifndef _I4B_IOCTL_H_
-#define _I4B_IOCTL_H_
-
-/*---------------------------------------------------------------------------*
- * version and release number for isdn4bsd package
- *---------------------------------------------------------------------------*/
-#define VERSION 1 /* version number */
-#define REL 4 /* release number */
-#define STEP 0 /* release step */
-
-/*---------------------------------------------------------------------------*
- * date/time format in i4b log messages
- * ------------------------------------
- * Being year 2000 clean is not easy with the current state of the
- * ANSI C library standard and it's implementation for some locales.
- * You might like to use the "%c" format of "strftime" sometimes,
- * but this breaks Y2K in some locales. Also the old standard logfile
- * format "%d.%m.%y %H:%M:%S" is non compliant.
- * NetBSD's current toolset warns about this problems, and we compile
- * with -Werror, so this problems need to be resolved.
- *---------------------------------------------------------------------------*/
-#define I4B_TIME_FORMAT "%d.%m.%Y %H:%M:%S"
-
-/*---------------------------------------------------------------------------*
- * max number of controllers in system
- *---------------------------------------------------------------------------*/
-#define MAX_CONTROLLERS 8 /* max number of controllers */
-
-/*---------------------------------------------------------------------------*
- * ISDN D-channel protocols
- *---------------------------------------------------------------------------*/
-#define PROTOCOL_DSS1 0 /* default, Euro-ISDN/DSS1 */
-#define PROTOCOL_D64S 1 /* 64k leased line, no protocol */
-
-/*---------------------------------------------------------------------------*
- * controller types
- *---------------------------------------------------------------------------*/
-#define CTRL_INVALID (-1) /* invalid, error */
-#define CTRL_UNKNOWN 0 /* unknown controller type */
-#define CTRL_PASSIVE 1 /* passive ISDN controller cards*/
-#define CTRL_DAIC 2 /* Diehl active controller cards*/
-#define CTRL_TINADD 3 /* Stollmann Tina-dd active card*/
-#define CTRL_AVMB1 4 /* AVM B1 active card */
-#define CTRL_CAPI 5 /* cards seen via the CAPI layer*/
-#define CTRL_NUMTYPES 6 /* number of controller types */
-
-/*---------------------------------------------------------------------------*
- * CTRL_PASSIVE: driver types
- *---------------------------------------------------------------------------*/
-#define MAXL1UNITS 8 /* max number of units */
-
-#define L1DRVR_ISIC 0 /* isic - driver */
-#define L1DRVR_IWIC 1 /* iwic - driver */
-#define L1DRVR_IFPI 2 /* ifpi - driver */
-#define L1DRVR_IHFC 3 /* ihfc - driver */
-#define L1DRVR_IFPNP 4 /* ifpnp - driver */
-#define L1DRVR_ICCHP 5 /* icchp - driver */
-#define L1DRVR_ITJC 6 /* itjc - driver */
-#define L1DRVR_IFPI2 7 /* ifpi2 - driver */
-
-/* MAXL1DRVR MUST be updated when more passive drivers are added !!! */
-#define MAXL1DRVR (L1DRVR_IFPI2 + 1)
-
-/*---------------------------------------------------------------------------*
- * card types for CTRL_PASSIVE
- *---------------------------------------------------------------------------*/
-#define CARD_TYPEP_INVAL (-1) /* invalid, error */
-#define CARD_TYPEP_UNK 0 /* unknown */
-#define CARD_TYPEP_8 1 /* Teles, S0/8 */
-#define CARD_TYPEP_16 2 /* Teles, S0/16 */
-#define CARD_TYPEP_16_3 3 /* Teles, S0/16.3 */
-#define CARD_TYPEP_AVMA1 4 /* AVM A1 or AVM Fritz!Card */
-#define CARD_TYPEP_163P 5 /* Teles, S0/16.3 PnP */
-#define CARD_TYPEP_CS0P 6 /* Creatix, S0 PnP */
-#define CARD_TYPEP_USRTA 7 /* US Robotics ISDN TA internal */
-#define CARD_TYPEP_DRNNGO 8 /* Dr. Neuhaus Niccy GO@ */
-#define CARD_TYPEP_SWS 9 /* Sedlbauer Win Speed */
-#define CARD_TYPEP_DYNALINK 10 /* Dynalink IS64PH */
-#define CARD_TYPEP_BLMASTER 11 /* ISDN Blaster / ISDN Master */
-#define CARD_TYPEP_PCFRITZ 12 /* AVM PCMCIA Fritz!Card */
-#define CARD_TYPEP_ELSAQS1ISA 13 /* ELSA QuickStep 1000pro ISA */
-#define CARD_TYPEP_ELSAQS1PCI 14 /* ELSA QuickStep 1000pro PCI */
-#define CARD_TYPEP_SIEMENSITALK 15 /* Siemens I-Talk */
-#define CARD_TYPEP_ELSAMLIMC 16 /* ELSA MicroLink ISDN/MC */
-#define CARD_TYPEP_ELSAMLMCALL 17 /* ELSA MicroLink MCall */
-#define CARD_TYPEP_ITKIX1 18 /* ITK ix1 micro */
-#define CARD_TYPEP_AVMA1PCI 19 /* AVM FRITZ!CARD PCI */
-#define CARD_TYPEP_PCC16 20 /* ELSA PCC-16 */
-#define CARD_TYPEP_AVM_PNP 21 /* AVM FRITZ!CARD PnP */
-#define CARD_TYPEP_SIE_ISURF2 22 /* Siemens I-Surf 2 PnP */
-#define CARD_TYPEP_ASUSCOMIPAC 23 /* Asuscom ISDNlink 128 K PnP */
-#define CARD_TYPEP_WINB6692 24 /* Winbond W6692 based */
-#define CARD_TYPEP_16_3C 25 /* Teles S0/16.3c PnP (HFC-S/SP */
-#define CARD_TYPEP_ACERP10 26 /* Acer ISDN P10 (HFC-S) */
-#define CARD_TYPEP_TELEINT_NO_1 27 /* TELEINT ISDN SPEED No. 1 (HFC-1) */
-#define CARD_TYPEP_CCD_HFCS_PCI 28 /* Cologne Chip HFC-S PCI based */
-#define CARD_TYPEP_NETJET_S 29 /* Traverse NetJet-S (Tiger300) */
-#define CARD_TYPEP_DIVA_ISA 30 /* Eicon DIVA ISA PnP 2.0 or 2.02 */
-#define CARD_TYPEP_COMPAQ_M610 31 /* Compaq Microcom 610 */
-#define CARD_TYPEP_AVMA1PCI_V2 32 /* AVM FRITZ!CARD PCI Ver. 2 */
-/*
- * in case you add support for more cards, please update:
- *
- * isdnd: controller.c, name_of_controller()
- *
- * and adjust CARD_TYPEP_MAX below.
- */
-
-#define CARD_TYPEP_MAX 32 /* max type */
-
-/*---------------------------------------------------------------------------*
- * card types for CTRL_DAIC
- *---------------------------------------------------------------------------*/
-#define CARD_TYPEA_DAIC_UNK 0
-#define CARD_TYPEA_DAIC_S 1
-#define CARD_TYPEA_DAIC_SX 2
-#define CARD_TYPEA_DAIC_SCOM 3
-#define CARD_TYPEA_DAIC_QUAD 4
-
-/*---------------------------------------------------------------------------*
- * card types for CTRL_CAPI
- *---------------------------------------------------------------------------*/
-#define CARD_TYPEC_CAPI_UNK 0
-#define CARD_TYPEC_AVM_T1_PCI 1
-#define CARD_TYPEC_AVM_B1_PCI 2
-#define CARD_TYPEC_AVM_B1_ISA 3
-
-/*---------------------------------------------------------------------------*
- * max length of some strings
- *---------------------------------------------------------------------------*/
-#define TELNO_MAX 41 /* max length of a telephone number (+ '\0') */
-#define SUBADDR_MAX 21 /* max length of a subaddress (+ '\0') */
-#define DISPLAY_MAX 91 /* max length of display information (+ '\0') */
-#define DATETIME_MAX 21 /* max length of datetime information (+ '\0')*/
-#define KEYPAD_MAX 35 /* max length of a keypad string (+ '\0') */
-
-/*---------------------------------------------------------------------------*
- * in case the src or dst telephone number is empty
- *---------------------------------------------------------------------------*/
-#define TELNO_EMPTY "NotAvailable"
-
-/*---------------------------------------------------------------------------*
- * B channel parameters
- *---------------------------------------------------------------------------*/
-#define BCH_MAX_DATALEN 2048 /* max length of a B channel frame */
-
-/*---------------------------------------------------------------------------*
- * userland driver types
- * ---------------------
- * a "driver" is defined here as a piece of software interfacing an
- * ISDN B channel with a userland service, such as IP, Telephony etc.
- *---------------------------------------------------------------------------*/
-#define BDRV_RBCH 0 /* raw b-channel interface driver */
-#define BDRV_TEL 1 /* telephone (speech) interface driver */
-#define BDRV_IPR 2 /* IP over raw HDLC interface driver */
-#define BDRV_ISPPP 3 /* sync Kernel PPP interface driver */
-#define BDRV_IBC 4 /* BSD/OS point to point driver */
-#define BDRV_ING 5 /* NetGraph ing driver */
-
-/*---------------------------------------------------------------------------*
- * B channel protocol
- *---------------------------------------------------------------------------*/
-#define BPROT_NONE 0 /* no protocol at all, raw data */
-#define BPROT_RHDLC 1 /* raw HDLC: flag, data, crc, flag */
-
-/*---------------------------------------------------------------------------*
- * special bearer capability settings (i.e. Data over Voice)
- *---------------------------------------------------------------------------*/
-#define BCAP_NONE 0 /* no special bearer capability */
-#define BCAP_DOV 1 /* Data over Voice */
-
-/*---------------------------------------------------------------------------*
- * causes data type
- *---------------------------------------------------------------------------*/
-typedef unsigned int cause_t; /* 32 bit unsigned int */
-
-/*---------------------------------------------------------------------------*
- * call descriptor id (cdid) definitions
- *---------------------------------------------------------------------------*/
-#define CDID_UNUSED 0 /* cdid is invalid and unused */
-#define CDID_MAX 99999 /* highest valid cdid, wraparound to 1 */
-
-/*---------------------------------------------------------------------------*
- * The shorthold algorithm to use
- *---------------------------------------------------------------------------*/
-#define SHA_FIXU 0 /* timeout algorithm for fix unit charging */
-#define SHA_VARU 1 /* timeout algorithm for variable unit charging */
-
-/*---------------------------------------------------------------------------*
- * The shorthold data struct
- *---------------------------------------------------------------------------*/
-typedef struct {
- int shorthold_algorithm; /* shorthold algorithm to use */
- int unitlen_time; /* length of a charging unit */
- int idle_time; /* time without activity on b ch*/
- int earlyhup_time; /* safety area at end of unit */
-} msg_shorthold_t;
-
-
-/****************************************************************************
-
- outgoing call:
- --------------
-
- userland kernel
- -------- ------
-
- CDID_REQ ----------------->
-
- <------------------ cdid
-
- CONNECT_REQ -------------->
-
- <------------------ PROCEEDING_IND (if connect req ok)
-
- <------------------ CONNECT_ACTIVE_IND (if connection ok)
-
- or
-
- <------------------ DISCONNECT_IND (if connection failed)
-
-
-
- incoming call:
- --------------
-
- userland kernel
- -------- ------
-
- <------------------ CONNECT_IND
-
- CONNECT_RESP ------------->
-
- <------------------ CONNECT_ACTIVE_IND (if accepted)
-
-
-
- active disconnect:
- ------------------
-
- userland kernel
- -------- ------
-
- DISCONNECT_REQ ------------>
-
- <------------------ DISCONNECT_IND
-
-
- passive disconnect:
- -------------------
-
- userland kernel
- -------- ------
-
- <------------------ DISCONNECT_IND
-
-
-****************************************************************************/
-
-
-/*===========================================================================*
- *===========================================================================*
- * "read" messages from kernel -> userland
- *===========================================================================*
- *===========================================================================*/
-
-
-/*---------------------------------------------------------------------------*
- * message header, included in every message
- *---------------------------------------------------------------------------*/
-typedef struct {
- char type; /* message identifier */
-#define MSG_CONNECT_IND 'a'
-#define MSG_CONNECT_ACTIVE_IND 'b'
-#define MSG_DISCONNECT_IND 'c'
-#define MSG_DIALOUT_IND 'd'
-#define MSG_IDLE_TIMEOUT_IND 'e'
-#define MSG_ACCT_IND 'f'
-#define MSG_CHARGING_IND 'g'
-#define MSG_PROCEEDING_IND 'h'
-#define MSG_ALERT_IND 'i'
-#define MSG_DRVRDISC_REQ 'j'
-#define MSG_L12STAT_IND 'k'
-#define MSG_TEIASG_IND 'l'
-#define MSG_PDEACT_IND 'm'
-#define MSG_NEGCOMP_IND 'n'
-#define MSG_IFSTATE_CHANGED_IND 'o'
-#define MSG_DIALOUTNUMBER_IND 'p'
-#define MSG_PACKET_IND 'q'
-#define MSG_KEYPAD_IND 'r'
- int cdid; /* call descriptor id */
-} msg_hdr_t;
-
-/*---------------------------------------------------------------------------*
- * connect indication
- * indicates incoming connection
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int controller; /* controller number */
- int channel; /* channel number */
-#define CHAN_B1 0 /* this _must_ be 0, HSCX B1 is also 0 */
-#define CHAN_B2 1 /* this _must_ be 1, HSCX B2 is also 1 */
-#define CHAN_ANY (-1) /* outgoing, not possible for incoming */
-#define CHAN_NO (-2) /* call waiting (CW) for incoming */
- int bprot; /* b channel protocot, see BPROT_XXX */
- int bcap; /* special bearer capability, see BCAP_XXX */
- char dst_telno[TELNO_MAX]; /* destination telno */
- char dst_subaddr[SUBADDR_MAX]; /* dest subaddr */
- char src_telno[TELNO_MAX]; /* source telno */
- char src_subaddr[SUBADDR_MAX]; /* src subaddr */
- int dst_ton; /* dest. type of number */
- int src_ton; /* src. type of number */
-#define TON_OTHER 0 /* other type of number */
-#define TON_INTERNAT 1 /* international number */
-#define TON_NATIONAL 2 /* national number */
- int scr_ind;/* screening indicator */
-#define SCR_NONE 0 /* no screening indicator transmitted */
-#define SCR_USR_NOSC 1 /* screening user provided, not screened*/
-#define SCR_USR_PASS 2 /* screening user provided, verified & passed */
-#define SCR_USR_FAIL 3 /* screening user provided, verified & failed */
-#define SCR_NET 4 /* screening network provided */
- int prs_ind;/* presentation indicator */
-#define PRS_NONE 0 /* no presentation indicator transmitted*/
-#define PRS_ALLOWED 1 /* presentation allowed */
-#define PRS_RESTRICT 2 /* presentation restricted */
-#define PRS_NNINTERW 3 /* number not available due to interworking */
-#define PRS_RESERVED 4 /* reserved */
- char display[DISPLAY_MAX]; /* content of display IE*/
-} msg_connect_ind_t;
-
-/*---------------------------------------------------------------------------*
- * connect active indication
- * indicates active connection
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int controller; /* controller number actually used */
- int channel; /* channel number actually used */
- char datetime[DATETIME_MAX]; /* content of date/time IE */
-} msg_connect_active_ind_t;
-
-/*---------------------------------------------------------------------------*
- * disconnect indication
- * indicates a disconnect
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- cause_t cause; /* cause code */
-} msg_disconnect_ind_t;
-
-/*---------------------------------------------------------------------------*
- * negotiation complete
- * indicates an interface is completely up & running
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
-} msg_negcomplete_ind_t;
-
-/*---------------------------------------------------------------------------*
- * interface changes internal state
- * indicates an interface has somehow switched its FSM
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int state; /* new interface state */
-} msg_ifstatechg_ind_t;
-
-/*---------------------------------------------------------------------------*
- * initiate a call to a remote site
- * i.e. the IP driver got a packet and wants a connection
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int driver; /* driver type */
- int driver_unit; /* driver unit number */
-} msg_dialout_ind_t;
-
-/*---------------------------------------------------------------------------*
- * dial a number
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int driver; /* driver type */
- int driver_unit; /* driver unit number */
- int cmdlen; /* length of string */
- int subaddrlen; /* length of subaddr */
- char cmd[TELNO_MAX]; /* the number to dial */
- char subaddr[SUBADDR_MAX]; /* dest subaddr */
-} msg_dialoutnumber_ind_t;
-
-/*---------------------------------------------------------------------------*
- * send keypad string
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int driver; /* driver type */
- int driver_unit; /* driver unit number */
- int cmdlen; /* length of string */
- char cmd[KEYPAD_MAX];/* keypad string */
-} msg_keypad_ind_t;
-
-/*---------------------------------------------------------------------------*
- * idle timeout disconnect sent indication
- * kernel has sent disconnect request because of b-ch idle
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
-} msg_idle_timeout_ind_t;
-
-/*---------------------------------------------------------------------------*
- * accounting information from userland interface driver to daemon
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int accttype; /* accounting type */
-#define ACCT_DURING 0
-#define ACCT_FINAL 1
- int driver; /* driver type */
- int driver_unit; /* driver unit number */
- int ioutbytes; /* ISDN # of bytes sent */
- int iinbytes; /* ISDN # of bytes received */
- int outbps; /* bytes per sec out */
- int inbps; /* bytes per sec in */
- int outbytes; /* driver # of bytes sent */
- int inbytes; /* driver # of bytes received */
-} msg_accounting_ind_t;
-
-/*---------------------------------------------------------------------------*
- * charging information from isdn driver to daemon
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int units; /* number of units */
- int units_type; /* type of units info */
-#define CHARGE_INVALID 0 /* invalid, unknown */
-#define CHARGE_AOCD 1 /* advice of charge during call */
-#define CHARGE_AOCE 2 /* advice of charge at end of call */
-#define CHARGE_CALC 3 /* locally calculated from rates information */
-} msg_charging_ind_t;
-
-/*---------------------------------------------------------------------------*
- * call proceeding indication
- * indicates outgoing SETUP has been acknowleged
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int controller; /* controller number actually used */
- int channel; /* channel number actually used */
-} msg_proceeding_ind_t;
-
-/*---------------------------------------------------------------------------*
- * alert indication
- * indicates remote user side "rings"
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
-} msg_alert_ind_t;
-
-/*---------------------------------------------------------------------------*
- * driver requests to disconnect line
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int driver; /* driver type */
- int driver_unit; /* driver unit number */
-} msg_drvrdisc_req_t;
-
-/*---------------------------------------------------------------------------*
- * connect packet logging
- *---------------------------------------------------------------------------*/
-
-typedef struct {
- msg_hdr_t header; /* common header */
- int driver; /* driver type */
- int driver_unit; /* driver unit number */
- int direction; /* 0=in 1=out */
-#define DIRECTION_IN 0 /* sending packet to remote */
-#define DIRECTION_OUT 1 /* received packet from remote */
-#define MAX_PACKET_LOG 40 /* space for IP and TCP header */
- u_int8_t pktdata[MAX_PACKET_LOG];
-} msg_packet_ind_t;
-
-/*---------------------------------------------------------------------------*
- * state of layer 1/2
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int controller; /* controller unit */
- int layer; /* layer number (1/2) */
-#define LAYER_ONE 1
-#define LAYER_TWO 2
- int state; /* state info */
-#define LAYER_IDLE 0
-#define LAYER_ACTIVE 1
-} msg_l12stat_ind_t;
-
-/*---------------------------------------------------------------------------*
- * TEI assignment messages
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int controller; /* controller unit */
- int tei; /* TEI or -1 if invalid */
-} msg_teiasg_ind_t;
-
-/*---------------------------------------------------------------------------*
- * persistent deactivation state of stack
- *---------------------------------------------------------------------------*/
-typedef struct {
- msg_hdr_t header; /* common header */
- int controller; /* controller unit */
- int numactive; /* number of active connections */
-} msg_pdeact_ind_t;
-
-
-/*===========================================================================*
- *===========================================================================*
- * "ioctl" messages from userland -> kernel
- *===========================================================================*
- *===========================================================================*/
-
-/*---------------------------------------------------------------------------*
- * request a unique cdid (to setup an outgoing call)
- *---------------------------------------------------------------------------*/
-typedef struct {
- int cdid; /* call descriptor id */
-} msg_cdid_req_t;
-
-#define I4B_CDID_REQ _IOWR('4', 0, int)
-
-/*---------------------------------------------------------------------------*
- * connect request
- * requests an outgoing connection
- *---------------------------------------------------------------------------*/
-typedef struct {
- int cdid; /* call descriptor id */
- int controller; /* controller to use */
- int channel; /* channel to use */
- int txdelay; /* tx delay after connect */
- int bprot; /* b channel protocol */
- int bcap; /* special bearer capability */
- int driver; /* driver to route b channel data to */
- int driver_unit; /* unit number for above driver */
- msg_shorthold_t shorthold_data; /* the shorthold data */
- int unitlen_method; /* how to calculate the unitlength */
-#define ULEN_METHOD_STATIC 0 /* use unitlen_time value (see above) */
-#define ULEN_METHOD_DYNAMIC 1 /* use AOCD */
- char dst_telno[TELNO_MAX]; /* destination telephone no */
- char dst_subaddr[SUBADDR_MAX]; /* dest subaddr */
- char src_telno[TELNO_MAX]; /* source telephone number */
- char src_subaddr[SUBADDR_MAX]; /* source subaddr */
- char keypad[KEYPAD_MAX]; /* keypad string */
-} msg_connect_req_t;
-
-#define I4B_CONNECT_REQ _IOW('4', 1, msg_connect_req_t)
-
-/*---------------------------------------------------------------------------*
- * connect response
- * this is the answer to an incoming connect indication
- *---------------------------------------------------------------------------*/
-typedef struct {
- int cdid; /* call descriptor id */
- int response; /* what to do with incoming call */
-#define SETUP_RESP_DNTCRE 0 /* dont care, call is not for me */
-#define SETUP_RESP_REJECT 1 /* reject call */
-#define SETUP_RESP_ACCEPT 2 /* accept call */
- cause_t cause; /* cause for case SETUP_RESP_REJECT */
- /* the following are only used for SETUP_RESP_ACCEPT !! */
- int txdelay; /* tx delay after connect */
- int bprot; /* B chan protocol */
- int bcap; /* special bearer capability */
- int driver; /* driver to route b channel data to */
- int driver_unit; /* unit number for above driver */
- int max_idle_time; /* max time without activity on b ch */
-} msg_connect_resp_t;
-
-#define I4B_CONNECT_RESP _IOW('4', 2, msg_connect_resp_t)
-
-/*---------------------------------------------------------------------------*
- * disconnect request
- * active disconnect request
- *---------------------------------------------------------------------------*/
-typedef struct {
- int cdid; /* call descriptor id */
- cause_t cause; /* protocol independent cause */
-} msg_discon_req_t;
-
-#define I4B_DISCONNECT_REQ _IOW('4', 3, msg_discon_req_t)
-
-/*---------------------------------------------------------------------------*
- * controller info request
- *---------------------------------------------------------------------------*/
-typedef struct {
- int controller; /* controller number */
- int ncontroller; /* number of controllers in system */
- int ctrl_type; /* controller type passive/active */
- int card_type; /* brand / version */
- int tei; /* tei controller probably has */
- int nbch; /* number of b channels provided */
-} msg_ctrl_info_req_t;
-
-#define I4B_CTRL_INFO_REQ _IOWR('4', 4, msg_ctrl_info_req_t)
-
-/*---------------------------------------------------------------------------*
- * dialout response
- * status report to driver who requested a dialout
- *---------------------------------------------------------------------------*/
-typedef struct {
- int driver; /* driver to route b channel data to */
- int driver_unit; /* unit number for above driver */
- int stat; /* state of dialout request */
-#define DSTAT_NONE 0
-#define DSTAT_TFAIL 1 /* transient failure */
-#define DSTAT_PFAIL 2 /* permanent failure */
-#define DSTAT_INONLY 3 /* no outgoing dials allowed */
- cause_t cause; /* exact i4b cause */
-} msg_dialout_resp_t;
-
-#define I4B_DIALOUT_RESP _IOW('4', 5, msg_dialout_resp_t)
-
-/*---------------------------------------------------------------------------*
- * timeout value update
- *---------------------------------------------------------------------------*/
-typedef struct {
- int cdid; /* call descriptor id */
- msg_shorthold_t shorthold_data;
-} msg_timeout_upd_t;
-
-#define I4B_TIMEOUT_UPD _IOW('4', 6, msg_timeout_upd_t)
-
-/*---------------------------------------------------------------------------*
- * soft enable/disable
- *---------------------------------------------------------------------------*/
-typedef struct {
- int driver; /* driver to route b channel data to */
- int driver_unit; /* unit number for above driver */
- int updown; /* what to do */
-#define SOFT_ENA 0 /* enable interface */
-#define SOFT_DIS 1 /* disable interface */
-} msg_updown_ind_t;
-
-#define I4B_UPDOWN_IND _IOW('4', 7, msg_updown_ind_t)
-
-/*---------------------------------------------------------------------------*
- * send alert request
- *---------------------------------------------------------------------------*/
-typedef struct {
- int cdid; /* call descriptor id */
-} msg_alert_req_t;
-
-#define I4B_ALERT_REQ _IOW('4', 8, msg_alert_req_t)
-
-/*---------------------------------------------------------------------------*
- * request version and release info from kernel part
- * (msg_vr_req_t is also used by tel & rbch drivers)
- *---------------------------------------------------------------------------*/
-typedef struct {
- int version; /* version number */
- int release; /* release number */
- int step; /* release step number */
-} msg_vr_req_t;
-
-#define I4B_VR_REQ _IOR('4', 9, msg_vr_req_t)
-
-/*---------------------------------------------------------------------------*
- * set ISDN protocol used by a controller
- *---------------------------------------------------------------------------*/
-typedef struct {
- int controller; /* controller number */
- int protocol; /* ISDN D-channel protocol type */
-} msg_prot_ind_t;
-
-#define I4B_PROT_IND _IOW('4', 10, msg_prot_ind_t)
-
-/*---------------------------------------------------------------------------*
- * Protocol download to active cards
- *---------------------------------------------------------------------------*/
-struct isdn_dr_prot {
- size_t bytecount; /* length of code */
- u_int8_t *microcode; /* pointer to microcode */
-};
-
-struct isdn_download_request {
- int controller; /* controller number */
- int numprotos; /* number of protocols in 'protocols' */
- struct isdn_dr_prot *protocols;
-};
-
-#define I4B_CTRL_DOWNLOAD _IOW('4', 100, struct isdn_download_request)
-
-/*---------------------------------------------------------------------------*
- * Generic diagnostic interface for active cards
- *---------------------------------------------------------------------------*/
-struct isdn_diagnostic_request {
- int controller; /* controller number */
- u_int32_t cmd; /* diagnostic command to execute */
- size_t in_param_len; /* length of additional input parameter */
-#define I4B_ACTIVE_DIAGNOSTIC_MAXPARAMLEN 65536
- void *in_param; /* optional input parameter */
- size_t out_param_len; /* available output space */
- void *out_param; /* output data goes here */
-};
-
-#define I4B_ACTIVE_DIAGNOSTIC _IOW('4', 102, struct isdn_diagnostic_request)
-
-#endif /* _I4B_IOCTL_H_ */
diff --git a/sys/i4b/include/i4b_rbch_ioctl.h b/sys/i4b/include/i4b_rbch_ioctl.h
deleted file mode 100644
index dbaceedc8e32..000000000000
--- a/sys/i4b/include/i4b_rbch_ioctl.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 1999, 2002 Hellmuth Michaelis. 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.
- *
- *---------------------------------------------------------------------------
- *
- * i4b_rbch_ioctl.h raw B-channel driver interface ioctls
- * ------------------------------------------------------
- *
- * $FreeBSD$
- *
- * last edit-date: [Sun Mar 17 10:10:25 2002]
- *
- *---------------------------------------------------------------------------*/
-
-#ifndef _I4B_RBCH_IOCTL_H_
-#define _I4B_RBCH_IOCTL_H_
-
-/*---------------------------------------------------------------------------*
- * instruct the rbch device to dial the given number
- *---------------------------------------------------------------------------*/
-
-typedef char telno_t[TELNO_MAX];
-
-#define I4B_RBCH_DIALOUT _IOW('R', 1, telno_t)
-
-/*---------------------------------------------------------------------------*
- * request version and release info from kernel part
- *---------------------------------------------------------------------------*/
-
-#define I4B_RBCH_VR_REQ _IOR('R', 2, msg_vr_req_t)
-
-#endif /* _I4B_RBCH_IOCTL_H_ */
diff --git a/sys/i4b/include/i4b_tel_ioctl.h b/sys/i4b/include/i4b_tel_ioctl.h
deleted file mode 100644
index 2f0bb2bdacda..000000000000
--- a/sys/i4b/include/i4b_tel_ioctl.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (c) 1997, 2002 Hellmuth Michaelis. 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.
- *
- *---------------------------------------------------------------------------
- *
- * i4b_tel_ioctl.h telephony interface ioctls
- * ------------------------------------------
- *
- * $FreeBSD$
- *
- * last edit-date: [Sun Mar 17 10:10:39 2002]
- *
- *---------------------------------------------------------------------------*/
-
-#ifndef _I4B_TEL_IOCTL_H_
-#define _I4B_TEL_IOCTL_H_
-
-/*===========================================================================*
- * /dev/i4btel<n> devices (audio data)
- *===========================================================================*/
-
-/* supported audio format conversions */
-
-#define CVT_NONE 0 /* no A-law/u-law conversion */
-#define CVT_ALAW2ULAW 1 /* ISDN line: A-law, user: u-law */
-#define CVT_ULAW2ALAW 2 /* ISDN line: u-law, user: A-law */
-
-/*---------------------------------------------------------------------------*
- * get / set audio format
- *---------------------------------------------------------------------------*/
-
-#define I4B_TEL_GETAUDIOFMT _IOR('A', 0, int)
-#define I4B_TEL_SETAUDIOFMT _IOW('A', 1, int)
-#define I4B_TEL_EMPTYINPUTQUEUE _IOW('A', 2, int)
-
-/*---------------------------------------------------------------------------*
- * request version and release info from kernel part
- *---------------------------------------------------------------------------*/
-
-#define I4B_TEL_VR_REQ _IOR('A', 3, msg_vr_req_t)
-
-/*---------------------------------------------------------------------------*
- * send tones out of the tel interface
- *---------------------------------------------------------------------------*/
-
-#define I4B_TEL_MAXTONES 32
-
-struct i4b_tel_tones {
- int frequency[I4B_TEL_MAXTONES];
- int duration[I4B_TEL_MAXTONES];
-};
-
-#define I4B_TEL_TONES _IOR('A', 4, struct i4b_tel_tones)
-
-/*===========================================================================*
- * /dev/i4bteld<n> devices (dialer interface)
- *===========================================================================*/
-
-/* dialer commands */
-
-#define CMD_DIAL 'D' /* dial the following number string */
-#define CMD_HUP 'H' /* hangup */
-#define CMD_KEYP 'K' /* send keypad string */
-
-/* dialer responses */
-
-#define RSP_CONN '0' /* connect */
-#define RSP_BUSY '1' /* busy */
-#define RSP_HUP '2' /* hangup */
-#define RSP_NOA '3' /* no answer */
-
-#endif /* _I4B_TEL_IOCTL_H_ */
diff --git a/sys/i4b/include/i4b_trace.h b/sys/i4b/include/i4b_trace.h
deleted file mode 100644
index ee05bfd7deaa..000000000000
--- a/sys/i4b/include/i4b_trace.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 1997, 2002 Hellmuth Michaelis. 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.
- *
- *---------------------------------------------------------------------------
- *
- * i4b_trace.h - header file for trace data read device
- * ----------------------------------------------------
- *
- * $FreeBSD$
- *
- * last edit-date: [Sun Mar 17 10:10:52 2002]
- *
- *---------------------------------------------------------------------------*/
-
-#ifndef _I4B_TRACE_H_
-#define _I4B_TRACE_H_
-
-/*---------------------------------------------------------------------------*
- * structure of the header at the beginning of every trace mbuf
- *---------------------------------------------------------------------------*/
-typedef struct {
- int length; /* length of the following mbuf */
- int unit; /* controller unit number */
- int type; /* type of channel */
-#define TRC_CH_I 0 /* Layer 1 INFO's */
-#define TRC_CH_D 1 /* D channel */
-#define TRC_CH_B1 2 /* B1 channel */
-#define TRC_CH_B2 3 /* B2 channel */
- int dir; /* direction */
-#define FROM_TE 0 /* user -> network */
-#define FROM_NT 1 /* network -> user */
- int trunc; /* # of truncated bytes (frame > MCLBYTES) */
- unsigned int count; /* frame count for this unit/type */
- struct timeval time; /* timestamp for this frame */
-} i4b_trace_hdr_t;
-
-#define INFO0 0 /* layer 1 */
-#define INFO1_8 1
-#define INFO1_10 2
-#define INFO2 3
-#define INFO3 4
-#define INFO4_8 5
-#define INFO4_10 6
-
-/*---------------------------------------------------------------------------*
- * ioctl via /dev/i4btrc device(s):
- * get/set current trace flag settings
- *---------------------------------------------------------------------------*/
-
-#define I4B_TRC_SET _IOW('T', 0, int) /* set trace settings */
-
-#define TRACE_OFF 0x00 /* tracing off */
-#define TRACE_I 0x01 /* trace L1 INFO's on */
-#define TRACE_D_TX 0x02 /* trace D channel on */
-#define TRACE_D_RX 0x04 /* trace D channel on */
-#define TRACE_B_TX 0x08 /* trace B channel on */
-#define TRACE_B_RX 0x10 /* trace B channel on */
-
-typedef struct {
- int rxunit; /* unit # for rx frames */
- int rxflags; /* d and/or b channel */
- int txunit; /* unit # for tx frames */
- int txflags; /* d and/or b channel */
-} i4b_trace_setupa_t;
-
-#define I4B_TRC_SETA _IOW('T', 1, i4b_trace_setupa_t) /* set analyze mode */
-#define I4B_TRC_RESETA _IOW('T', 2, int) /* reset analyze mode */
-
-#endif /* _I4B_TRACE_H_ */
diff --git a/sys/ia64/ia32/ia32_signal.c b/sys/ia64/ia32/ia32_signal.c
deleted file mode 100644
index d9066d441cde..000000000000
--- a/sys/ia64/ia32/ia32_signal.c
+++ /dev/null
@@ -1,384 +0,0 @@
-/*-
- * Copyright (c) 2002 Doug Rabson
- * 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$
- */
-
-#define __ELF_WORD_SIZE 32
-
-#include <sys/param.h>
-#include <sys/exec.h>
-#include <sys/fcntl.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/mman.h>
-#include <sys/namei.h>
-#include <sys/pioctl.h>
-#include <sys/proc.h>
-#include <sys/procfs.h>
-#include <sys/resourcevar.h>
-#include <sys/systm.h>
-#include <sys/signalvar.h>
-#include <sys/stat.h>
-#include <sys/sx.h>
-#include <sys/syscall.h>
-#include <sys/sysctl.h>
-#include <sys/sysent.h>
-#include <sys/vnode.h>
-#include <sys/imgact_elf.h>
-
-#include <machine/frame.h>
-#include <machine/md_var.h>
-#include <machine/pcb.h>
-
-#include <vm/vm.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-#include <vm/vm_extern.h>
-
-#include <ia64/ia32/ia32_util.h>
-#include <i386/include/psl.h>
-#include <i386/include/segments.h>
-#include <i386/include/specialreg.h>
-
-static register_t *ia32_copyout_strings(struct image_params *imgp);
-static void ia32_setregs(struct thread *td, u_long entry, u_long stack,
- u_long ps_strings);
-
-extern struct sysent ia32_sysent[];
-
-static char ia32_sigcode[] = {
- 0xff, 0x54, 0x24, 0x10, /* call *SIGF_HANDLER(%esp) */
- 0x8d, 0x44, 0x24, 0x14, /* lea SIGF_UC(%esp),%eax */
- 0x50, /* pushl %eax */
- 0xf7, 0x40, 0x54, 0x00, 0x00, 0x02, 0x02, /* testl $PSL_VM,UC_EFLAGS(%eax) */
- 0x75, 0x03, /* jne 9f */
- 0x8e, 0x68, 0x14, /* movl UC_GS(%eax),%gs */
- 0xb8, 0x57, 0x01, 0x00, 0x00, /* 9: movl $SYS_sigreturn,%eax */
- 0x50, /* pushl %eax */
- 0xcd, 0x80, /* int $0x80 */
- 0xeb, 0xfe, /* 0: jmp 0b */
- 0
-};
-static int ia32_szsigcode = sizeof(ia32_sigcode);
-
-struct sysentvec ia32_freebsd_sysvec = {
- SYS_MAXSYSCALL,
- ia32_sysent,
- 0,
- 0,
- NULL,
- 0,
- NULL,
- NULL,
- elf32_freebsd_fixup,
- sendsig,
- ia32_sigcode,
- &ia32_szsigcode,
- NULL,
- "FreeBSD ELF",
- elf32_coredump,
- NULL,
- IA32_MINSIGSTKSZ,
- IA32_PAGE_SIZE,
- 0,
- IA32_USRSTACK,
- IA32_USRSTACK,
- IA32_PS_STRINGS,
- VM_PROT_ALL,
- ia32_copyout_strings,
- ia32_setregs
-};
-
-static Elf32_Brandinfo ia32_brand_info = {
- ELFOSABI_FREEBSD,
- EM_386,
- "FreeBSD",
- "/compat/ia32",
- "/usr/libexec/ld-elf.so.1",
- &ia32_freebsd_sysvec
- };
-
-SYSINIT(ia32, SI_SUB_EXEC, SI_ORDER_ANY,
- (sysinit_cfunc_t) elf32_insert_brand_entry,
- &ia32_brand_info);
-
-static register_t *
-ia32_copyout_strings(struct image_params *imgp)
-{
- int argc, envc;
- u_int32_t *vectp;
- char *stringp, *destp;
- u_int32_t *stack_base;
- struct ia32_ps_strings *arginfo;
- int szsigcode;
-
- /*
- * Calculate string base and vector table pointers.
- * Also deal with signal trampoline code for this exec type.
- */
- arginfo = (struct ia32_ps_strings *)IA32_PS_STRINGS;
- szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
- destp = (caddr_t)arginfo - szsigcode - IA32_USRSPACE -
- roundup((ARG_MAX - imgp->stringspace), sizeof(char *));
-
- /*
- * install sigcode
- */
- if (szsigcode)
- copyout(imgp->proc->p_sysent->sv_sigcode,
- ((caddr_t)arginfo - szsigcode), szsigcode);
-
- /*
- * If we have a valid auxargs ptr, prepare some room
- * on the stack.
- */
- if (imgp->auxargs) {
- /*
- * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
- * lower compatibility.
- */
- imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
- : (AT_COUNT * 2);
- /*
- * The '+ 2' is for the null pointers at the end of each of
- * the arg and env vector sets,and imgp->auxarg_size is room
- * for argument of Runtime loader.
- */
- vectp = (u_int32_t *) (destp - (imgp->argc + imgp->envc + 2 +
- imgp->auxarg_size) * sizeof(u_int32_t));
-
- } else
- /*
- * The '+ 2' is for the null pointers at the end of each of
- * the arg and env vector sets
- */
- vectp = (u_int32_t *)
- (destp - (imgp->argc + imgp->envc + 2) * sizeof(u_int32_t));
-
- /*
- * vectp also becomes our initial stack base
- */
- vectp = (void*)((uintptr_t)vectp & ~15);
- stack_base = vectp;
-
- stringp = imgp->stringbase;
- argc = imgp->argc;
- envc = imgp->envc;
-
- /*
- * Copy out strings - arguments and environment.
- */
- copyout(stringp, destp, ARG_MAX - imgp->stringspace);
-
- /*
- * Fill in "ps_strings" struct for ps, w, etc.
- */
- suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
- suword32(&arginfo->ps_nargvstr, argc);
-
- /*
- * Fill in argument portion of vector table.
- */
- for (; argc > 0; --argc) {
- suword32(vectp++, (u_int32_t)(intptr_t)destp);
- while (*stringp++ != 0)
- destp++;
- destp++;
- }
-
- /* a null vector table pointer separates the argp's from the envp's */
- suword32(vectp++, 0);
-
- suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
- suword32(&arginfo->ps_nenvstr, envc);
-
- /*
- * Fill in environment portion of vector table.
- */
- for (; envc > 0; --envc) {
- suword32(vectp++, (u_int32_t)(intptr_t)destp);
- while (*stringp++ != 0)
- destp++;
- destp++;
- }
-
- /* end of vector table is a null pointer */
- suword32(vectp, 0);
-
- return ((register_t *)stack_base);
-}
-
-static void
-ia32_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
-{
- struct trapframe *tf = td->td_frame;
- vm_offset_t gdt, ldt;
- u_int64_t codesel, datasel, ldtsel;
- u_int64_t codeseg, dataseg, gdtseg, ldtseg;
- struct segment_descriptor desc;
- struct vmspace *vmspace = td->td_proc->p_vmspace;
-
- exec_setregs(td, entry, stack, ps_strings);
-
- /* Non-syscall frames are cleared by exec_setregs() */
- if (tf->tf_flags & FRAME_SYSCALL) {
- bzero(&tf->tf_scratch, sizeof(tf->tf_scratch));
- bzero(&tf->tf_scratch_fp, sizeof(tf->tf_scratch_fp));
- } else
- tf->tf_special.ndirty = 0;
-
- tf->tf_special.psr |= IA64_PSR_IS;
- tf->tf_special.sp = stack;
-
- /* Point the RSE backstore to something harmless. */
- tf->tf_special.bspstore = (IA32_PS_STRINGS - ia32_szsigcode -
- IA32_USRSPACE + 15) & ~15;
-
- codesel = LSEL(LUCODE_SEL, SEL_UPL);
- datasel = LSEL(LUDATA_SEL, SEL_UPL);
- ldtsel = GSEL(GLDT_SEL, SEL_UPL);
-
- /* Setup ia32 segment registers. */
- tf->tf_scratch.gr16 = (datasel << 48) | (datasel << 32) |
- (datasel << 16) | datasel;
- tf->tf_scratch.gr17 = (ldtsel << 32) | (datasel << 16) | codesel;
-
- /*
- * Build the GDT and LDT.
- */
- gdt = IA32_USRSTACK;
- vm_map_find(&vmspace->vm_map, 0, 0, &gdt, IA32_PAGE_SIZE << 1, 0,
- VM_PROT_ALL, VM_PROT_ALL, 0);
- ldt = gdt + IA32_PAGE_SIZE;
-
- desc.sd_lolimit = 8*NLDT-1;
- desc.sd_lobase = ldt & 0xffffff;
- desc.sd_type = SDT_SYSLDT;
- desc.sd_dpl = SEL_UPL;
- desc.sd_p = 1;
- desc.sd_hilimit = 0;
- desc.sd_def32 = 0;
- desc.sd_gran = 0;
- desc.sd_hibase = ldt >> 24;
- copyout(&desc, (caddr_t) gdt + 8*GLDT_SEL, sizeof(desc));
-
- desc.sd_lolimit = ((IA32_USRSTACK >> 12) - 1) & 0xffff;
- desc.sd_lobase = 0;
- desc.sd_type = SDT_MEMERA;
- desc.sd_dpl = SEL_UPL;
- desc.sd_p = 1;
- desc.sd_hilimit = ((IA32_USRSTACK >> 12) - 1) >> 16;
- desc.sd_def32 = 1;
- desc.sd_gran = 1;
- desc.sd_hibase = 0;
- copyout(&desc, (caddr_t) ldt + 8*LUCODE_SEL, sizeof(desc));
- desc.sd_type = SDT_MEMRWA;
- copyout(&desc, (caddr_t) ldt + 8*LUDATA_SEL, sizeof(desc));
-
- codeseg = 0 /* base */
- + (((IA32_USRSTACK >> 12) - 1) << 32) /* limit */
- + ((long)SDT_MEMERA << 52)
- + ((long)SEL_UPL << 57)
- + (1L << 59) /* present */
- + (1L << 62) /* 32 bits */
- + (1L << 63); /* page granularity */
- dataseg = 0 /* base */
- + (((IA32_USRSTACK >> 12) - 1) << 32) /* limit */
- + ((long)SDT_MEMRWA << 52)
- + ((long)SEL_UPL << 57)
- + (1L << 59) /* present */
- + (1L << 62) /* 32 bits */
- + (1L << 63); /* page granularity */
-
- tf->tf_scratch.csd = codeseg;
- tf->tf_scratch.ssd = dataseg;
- tf->tf_scratch.gr24 = dataseg; /* ESD */
- tf->tf_scratch.gr27 = dataseg; /* DSD */
- tf->tf_scratch.gr28 = dataseg; /* FSD */
- tf->tf_scratch.gr29 = dataseg; /* GSD */
-
- gdtseg = gdt /* base */
- + ((8L*NGDT - 1) << 32) /* limit */
- + ((long)SDT_SYSNULL << 52)
- + ((long)SEL_UPL << 57)
- + (1L << 59) /* present */
- + (0L << 62) /* 16 bits */
- + (0L << 63); /* byte granularity */
- ldtseg = ldt /* base */
- + ((8L*NLDT - 1) << 32) /* limit */
- + ((long)SDT_SYSLDT << 52)
- + ((long)SEL_UPL << 57)
- + (1L << 59) /* present */
- + (0L << 62) /* 16 bits */
- + (0L << 63); /* byte granularity */
-
- tf->tf_scratch.gr30 = ldtseg; /* LDTD */
- tf->tf_scratch.gr31 = gdtseg; /* GDTD */
-
- /* Set ia32 control registers on this processor. */
- ia64_set_cflg(CR0_PE | CR0_PG | ((long)(CR4_XMM | CR4_FXSR) << 32));
- ia64_set_eflag(PSL_USER);
-
- /* PS_STRINGS value for BSD/OS binaries. It is 0 for non-BSD/OS. */
- tf->tf_scratch.gr11 = IA32_PS_STRINGS;
-
- /*
- * XXX - Linux emulator
- * Make sure sure edx is 0x0 on entry. Linux binaries depend
- * on it.
- */
- td->td_retval[1] = 0;
-}
-
-void
-ia32_restorectx(struct pcb *pcb)
-{
-
- ia64_set_cflg(pcb->pcb_ia32_cflg);
- ia64_set_eflag(pcb->pcb_ia32_eflag);
- ia64_set_fcr(pcb->pcb_ia32_fcr);
- ia64_set_fdr(pcb->pcb_ia32_fdr);
- ia64_set_fir(pcb->pcb_ia32_fir);
- ia64_set_fsr(pcb->pcb_ia32_fsr);
-}
-
-void
-ia32_savectx(struct pcb *pcb)
-{
-
- pcb->pcb_ia32_cflg = ia64_get_cflg();
- pcb->pcb_ia32_eflag = ia64_get_eflag();
- pcb->pcb_ia32_fcr = ia64_get_fcr();
- pcb->pcb_ia32_fdr = ia64_get_fdr();
- pcb->pcb_ia32_fir = ia64_get_fir();
- pcb->pcb_ia32_fsr = ia64_get_fsr();
-}
diff --git a/sys/ia64/ia64/context.S b/sys/ia64/ia64/context.S
deleted file mode 100644
index c2f9ef8a83a3..000000000000
--- a/sys/ia64/ia64/context.S
+++ /dev/null
@@ -1,804 +0,0 @@
-/*
- * Copyright (c) 2003 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.
- * 2. Redistributions in binary form must 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.
- *
- * $FreeBSD$
- */
-
-#include <machine/asm.h>
-#include <assym.s>
-
- .text
-
-/*
- * void restorectx(struct pcb *)
- */
-ENTRY(restorectx, 1)
-{ .mmi
- invala
- mov ar.rsc=0
- add r31=8,r32
- ;;
-}
-{ .mmi
- ld8 r12=[r32] // sp
- ld8 r16=[r31],16 // unat (before)
- add r30=16,r32
- ;;
-}
-{ .mmi
- ld8 r17=[r30],16 // rp
- ld8 r18=[r31],16 // pr
- add r14=SIZEOF_SPECIAL,r32
- ;;
-}
-{ .mmi
- ld8 r19=[r30],16 // pfs
- ld8 r20=[r31],16 // bspstore
- mov rp=r17
- ;;
-}
-{ .mmi
- loadrs
- ld8 r21=[r30],16 // rnat
- mov pr=r18,0x1fffe
- ;;
-}
-{ .mmi
- ld8 r17=[r14],8 // unat (after)
- mov ar.bspstore=r20
- mov ar.pfs=r19
- ;;
-}
-{ .mmi
- mov ar.unat=r17
- mov ar.rnat=r21
- add r15=8,r14
- ;;
-}
-{ .mmi
- ld8.fill r4=[r14],16 // r4
- ld8.fill r5=[r15],16 // r5
- nop 0
- ;;
-}
-{ .mmi
- ld8.fill r6=[r14],16 // r6
- ld8.fill r7=[r15],16 // r7
- nop 1
- ;;
-}
-{ .mmi
- mov ar.unat=r16
- mov ar.rsc=3
- nop 2
-}
-{ .mmi
- ld8 r17=[r14],16 // b1
- ld8 r18=[r15],16 // b2
- nop 3
- ;;
-}
-{ .mmi
- ld8 r19=[r14],16 // b3
- ld8 r20=[r15],16 // b4
- mov b1=r17
- ;;
-}
-{ .mmi
- ld8 r16=[r14],24 // b5
- ld8 r17=[r15],32 // lc
- mov b2=r18
- ;;
-}
-{ .mmi
- ldf.fill f2=[r14],32
- ldf.fill f3=[r15],32
- mov b3=r19
- ;;
-}
-{ .mmi
- ldf.fill f4=[r14],32
- ldf.fill f5=[r15],32
- mov b4=r20
- ;;
-}
-{ .mmi
- ldf.fill f16=[r14],32
- ldf.fill f17=[r15],32
- mov b5=r16
- ;;
-}
-{ .mmi
- ldf.fill f18=[r14],32
- ldf.fill f19=[r15],32
- mov ar.lc=r17
- ;;
-}
- ldf.fill f20=[r14],32
- ldf.fill f21=[r15],32
- ;;
- ldf.fill f22=[r14],32
- ldf.fill f23=[r15],32
- ;;
- ldf.fill f24=[r14],32
- ldf.fill f25=[r15],32
- ;;
- ldf.fill f26=[r14],32
- ldf.fill f27=[r15],32
- ;;
-{ .mmi
- ldf.fill f28=[r14],32
- ldf.fill f29=[r15],32
- add r8=1,r0
- ;;
-}
-{ .mmb
- ldf.fill f30=[r14]
- ldf.fill f31=[r15]
- br.ret.sptk rp
- ;;
-}
-END(restorectx)
-
-/*
- * void swapctx(struct pcb *old, struct pcb *new)
- */
-
-ENTRY(swapctx, 2)
-{ .mmi
- mov ar.rsc=0
- mov r16=ar.unat
- add r31=8,r32
- ;;
-}
-{ .mmi
- flushrs
- st8 [r32]=sp,16 // sp
- mov r17=rp
- ;;
-}
-{ .mmi
- st8 [r31]=r16,16 // unat (before)
- st8 [r32]=r17,16 // rp
- mov r16=pr
- ;;
-}
-{ .mmi
- st8 [r31]=r16,16 // pr
- mov r17=ar.bsp
- mov r16=ar.pfs
- ;;
-}
-{ .mmi
- st8 [r32]=r16,16 // pfs
- st8 [r31]=r17,16 // bspstore
- cmp.eq p15,p0=0,r33
- ;;
-}
-{ .mmi
- mov r16=ar.rnat
-(p15) mov ar.rsc=3
- add r30=SIZEOF_SPECIAL-(6*8),r32
- ;;
-}
-{ .mmi
- st8 [r32]=r16,SIZEOF_SPECIAL-(4*8) // rnat
- st8 [r31]=r0,SIZEOF_SPECIAL-(6*8) // __spare
- mov r16=b1
- ;;
-}
- /* callee_saved */
-{ .mmi
- .mem.offset 8,0
- st8.spill [r31]=r4,16 // r4
- .mem.offset 16,0
- st8.spill [r32]=r5,16 // r5
- mov r17=b2
- ;;
-}
-{ .mmi
- .mem.offset 24,0
- st8.spill [r31]=r6,16 // r6
- .mem.offset 32,0
- st8.spill [r32]=r7,16 // r7
- mov r18=b3
- ;;
-}
-{ .mmi
- st8 [r31]=r16,16 // b1
- mov r16=ar.unat
- mov r19=b4
- ;;
-}
-{ .mmi
- st8 [r30]=r16 // unat (after)
- st8 [r32]=r17,16 // b2
- mov r16=b5
- ;;
-}
-{ .mmi
- st8 [r31]=r18,16 // b3
- st8 [r32]=r19,16 // b4
- mov r17=ar.lc
- ;;
-}
- st8 [r31]=r16,16 // b5
- st8 [r32]=r17,16 // lc
- ;;
- st8 [r31]=r0,24 // __spare
- stf.spill [r32]=f2,32
- ;;
- stf.spill [r31]=f3,32
- stf.spill [r32]=f4,32
- ;;
- stf.spill [r31]=f5,32
- stf.spill [r32]=f16,32
- ;;
- stf.spill [r31]=f17,32
- stf.spill [r32]=f18,32
- ;;
- stf.spill [r31]=f19,32
- stf.spill [r32]=f20,32
- ;;
- stf.spill [r31]=f21,32
- stf.spill [r32]=f22,32
- ;;
- stf.spill [r31]=f23,32
- stf.spill [r32]=f24,32
- ;;
- stf.spill [r31]=f25,32
- stf.spill [r32]=f26,32
- ;;
- stf.spill [r31]=f27,32
- stf.spill [r32]=f28,32
- ;;
-{ .mmi
- stf.spill [r31]=f29,32
- stf.spill [r32]=f30
-(p15) add r8=0,r0
- ;;
-}
-{ .mmb
- stf.spill [r31]=f31
- mf
-(p15) br.ret.sptk rp
- ;;
-}
-{ .mfb
- mov r32=r33
- nop 0
- br.sptk restorectx
- ;;
-}
-END(swapctx)
-
-/*
- * save_callee_saved(struct _callee_saved *)
- */
-ENTRY(save_callee_saved, 1)
-{ .mii
- nop 0
- add r14=8,r32
- add r15=16,r32
- ;;
-}
-{ .mmi
- .mem.offset 8,0
- st8.spill [r14]=r4,16 // r4
- .mem.offset 16,0
- st8.spill [r15]=r5,16 // r5
- mov r16=b1
- ;;
-}
-{ .mmi
- .mem.offset 24,0
- st8.spill [r14]=r6,16 // r6
- .mem.offset 32,0
- st8.spill [r15]=r7,16 // r7
- mov r17=b2
- ;;
-}
-{ .mmi
- st8 [r14]=r16,16 // b1
- mov r18=ar.unat
- mov r19=b3
- ;;
-}
-{ .mmi
- st8 [r32]=r18 // nat (after)
- st8 [r15]=r17,16 // b2
- mov r16=b4
- ;;
-}
-{ .mmi
- st8 [r14]=r19,16 // b3
- st8 [r15]=r16,16 // b4
- mov r17=b5
- ;;
-}
-{ .mfi
- st8 [r14]=r17,16 // b5
- nop 0
- mov r16=ar.lc
- ;;
-}
-{ .mmb
- st8 [r15]=r16 // ar.lc
- st8 [r14]=r0 // __spare
- br.ret.sptk rp
- ;;
-}
-END(save_callee_saved)
-
-/*
- * restore_callee_saved(struct _callee_saved *)
- */
-ENTRY(restore_callee_saved, 1)
-{ .mmi
- ld8 r30=[r32],16 // nat (after)
- ;;
- mov ar.unat=r30
- add r31=-8,r32
- ;;
-}
-{ .mmb
- ld8.fill r4=[r31],16 // r4
- ld8.fill r5=[r32],16 // r5
- nop 0
- ;;
-}
-{ .mmb
- ld8.fill r6=[r31],16 // r6
- ld8.fill r7=[r32],16 // r7
- nop 0
- ;;
-}
-{ .mmi
- ld8 r30=[r31],16 // b1
- ld8 r29=[r32],16 // b2
- nop 0
- ;;
-}
-{ .mmi
- ld8 r28=[r31],16 // b3
- ld8 r27=[r32],16 // b4
- mov b1=r30
- ;;
-}
-{ .mii
- ld8 r26=[r31] // b5
- mov b2=r29
- mov b3=r28
- ;;
-}
-{ .mii
- ld8 r25=[r32] // lc
- mov b4=r27
- mov b5=r26
- ;;
-}
-{ .mib
- nop 0
- mov ar.lc=r25
- br.ret.sptk rp
- ;;
-}
-END(restore_callee_saved)
-
-/*
- * save_callee_saved_fp(struct _callee_saved_fp *)
- */
-ENTRY(save_callee_saved_fp, 1)
- add r31=16,r32
- stf.spill [r32]=f2,32
- ;;
- stf.spill [r31]=f3,32
- stf.spill [r32]=f4,32
- ;;
- stf.spill [r31]=f5,32
- stf.spill [r32]=f16,32
- ;;
- stf.spill [r31]=f17,32
- stf.spill [r32]=f18,32
- ;;
- stf.spill [r31]=f19,32
- stf.spill [r32]=f20,32
- ;;
- stf.spill [r31]=f21,32
- stf.spill [r32]=f22,32
- ;;
- stf.spill [r31]=f23,32
- stf.spill [r32]=f24,32
- ;;
- stf.spill [r31]=f25,32
- stf.spill [r32]=f26,32
- ;;
- stf.spill [r31]=f27,32
- stf.spill [r32]=f28,32
- ;;
- stf.spill [r31]=f29,32
- stf.spill [r32]=f30
- ;;
- stf.spill [r31]=f31
- br.ret.sptk rp
- ;;
-END(save_callee_saved_fp)
-
-/*
- * restore_callee_saved_fp(struct _callee_saved_fp *)
- */
-ENTRY(restore_callee_saved_fp, 1)
- add r31=16,r32
- ldf.fill f2=[r32],32
- ;;
- ldf.fill f3=[r31],32
- ldf.fill f4=[r32],32
- ;;
- ldf.fill f5=[r31],32
- ldf.fill f16=[r32],32
- ;;
- ldf.fill f17=[r31],32
- ldf.fill f18=[r32],32
- ;;
- ldf.fill f19=[r31],32
- ldf.fill f20=[r32],32
- ;;
- ldf.fill f21=[r31],32
- ldf.fill f22=[r32],32
- ;;
- ldf.fill f23=[r31],32
- ldf.fill f24=[r32],32
- ;;
- ldf.fill f25=[r31],32
- ldf.fill f26=[r32],32
- ;;
- ldf.fill f27=[r31],32
- ldf.fill f28=[r32],32
- ;;
- ldf.fill f29=[r31],32
- ldf.fill f30=[r32]
- ;;
- ldf.fill f31=[r31]
- br.ret.sptk rp
- ;;
-END(restore_callee_saved_fp)
-
-/*
- * save_high_fp(struct _high_fp *)
- */
-ENTRY(save_high_fp, 1)
- rsm psr.dfh
- ;;
- srlz.d
- add r31=16,r32
- stf.spill [r32]=f32,32
- ;;
- stf.spill [r31]=f33,32
- stf.spill [r32]=f34,32
- ;;
- stf.spill [r31]=f35,32
- stf.spill [r32]=f36,32
- ;;
- stf.spill [r31]=f37,32
- stf.spill [r32]=f38,32
- ;;
- stf.spill [r31]=f39,32
- stf.spill [r32]=f40,32
- ;;
- stf.spill [r31]=f41,32
- stf.spill [r32]=f42,32
- ;;
- stf.spill [r31]=f43,32
- stf.spill [r32]=f44,32
- ;;
- stf.spill [r31]=f45,32
- stf.spill [r32]=f46,32
- ;;
- stf.spill [r31]=f47,32
- stf.spill [r32]=f48,32
- ;;
- stf.spill [r31]=f49,32
- stf.spill [r32]=f50,32
- ;;
- stf.spill [r31]=f51,32
- stf.spill [r32]=f52,32
- ;;
- stf.spill [r31]=f53,32
- stf.spill [r32]=f54,32
- ;;
- stf.spill [r31]=f55,32
- stf.spill [r32]=f56,32
- ;;
- stf.spill [r31]=f57,32
- stf.spill [r32]=f58,32
- ;;
- stf.spill [r31]=f59,32
- stf.spill [r32]=f60,32
- ;;
- stf.spill [r31]=f61,32
- stf.spill [r32]=f62,32
- ;;
- stf.spill [r31]=f63,32
- stf.spill [r32]=f64,32
- ;;
- stf.spill [r31]=f65,32
- stf.spill [r32]=f66,32
- ;;
- stf.spill [r31]=f67,32
- stf.spill [r32]=f68,32
- ;;
- stf.spill [r31]=f69,32
- stf.spill [r32]=f70,32
- ;;
- stf.spill [r31]=f71,32
- stf.spill [r32]=f72,32
- ;;
- stf.spill [r31]=f73,32
- stf.spill [r32]=f74,32
- ;;
- stf.spill [r31]=f75,32
- stf.spill [r32]=f76,32
- ;;
- stf.spill [r31]=f77,32
- stf.spill [r32]=f78,32
- ;;
- stf.spill [r31]=f79,32
- stf.spill [r32]=f80,32
- ;;
- stf.spill [r31]=f81,32
- stf.spill [r32]=f82,32
- ;;
- stf.spill [r31]=f83,32
- stf.spill [r32]=f84,32
- ;;
- stf.spill [r31]=f85,32
- stf.spill [r32]=f86,32
- ;;
- stf.spill [r31]=f87,32
- stf.spill [r32]=f88,32
- ;;
- stf.spill [r31]=f89,32
- stf.spill [r32]=f90,32
- ;;
- stf.spill [r31]=f91,32
- stf.spill [r32]=f92,32
- ;;
- stf.spill [r31]=f93,32
- stf.spill [r32]=f94,32
- ;;
- stf.spill [r31]=f95,32
- stf.spill [r32]=f96,32
- ;;
- stf.spill [r31]=f97,32
- stf.spill [r32]=f98,32
- ;;
- stf.spill [r31]=f99,32
- stf.spill [r32]=f100,32
- ;;
- stf.spill [r31]=f101,32
- stf.spill [r32]=f102,32
- ;;
- stf.spill [r31]=f103,32
- stf.spill [r32]=f104,32
- ;;
- stf.spill [r31]=f105,32
- stf.spill [r32]=f106,32
- ;;
- stf.spill [r31]=f107,32
- stf.spill [r32]=f108,32
- ;;
- stf.spill [r31]=f109,32
- stf.spill [r32]=f110,32
- ;;
- stf.spill [r31]=f111,32
- stf.spill [r32]=f112,32
- ;;
- stf.spill [r31]=f113,32
- stf.spill [r32]=f114,32
- ;;
- stf.spill [r31]=f115,32
- stf.spill [r32]=f116,32
- ;;
- stf.spill [r31]=f117,32
- stf.spill [r32]=f118,32
- ;;
- stf.spill [r31]=f119,32
- stf.spill [r32]=f120,32
- ;;
- stf.spill [r31]=f121,32
- stf.spill [r32]=f122,32
- ;;
- stf.spill [r31]=f123,32
- stf.spill [r32]=f124,32
- ;;
- stf.spill [r31]=f125,32
- stf.spill [r32]=f126
- ;;
- stf.spill [r31]=f127
- ssm psr.dfh
- ;;
- srlz.d
- br.ret.sptk rp
- ;;
-END(save_high_fp)
-
-/*
- * restore_high_fp(struct _high_fp *)
- */
-ENTRY(restore_high_fp, 1)
- rsm psr.dfh
- ;;
- srlz.d
- add r31=16,r32
- ldf.fill f32=[r32],32
- ;;
- ldf.fill f33=[r31],32
- ldf.fill f34=[r32],32
- ;;
- ldf.fill f35=[r31],32
- ldf.fill f36=[r32],32
- ;;
- ldf.fill f37=[r31],32
- ldf.fill f38=[r32],32
- ;;
- ldf.fill f39=[r31],32
- ldf.fill f40=[r32],32
- ;;
- ldf.fill f41=[r31],32
- ldf.fill f42=[r32],32
- ;;
- ldf.fill f43=[r31],32
- ldf.fill f44=[r32],32
- ;;
- ldf.fill f45=[r31],32
- ldf.fill f46=[r32],32
- ;;
- ldf.fill f47=[r31],32
- ldf.fill f48=[r32],32
- ;;
- ldf.fill f49=[r31],32
- ldf.fill f50=[r32],32
- ;;
- ldf.fill f51=[r31],32
- ldf.fill f52=[r32],32
- ;;
- ldf.fill f53=[r31],32
- ldf.fill f54=[r32],32
- ;;
- ldf.fill f55=[r31],32
- ldf.fill f56=[r32],32
- ;;
- ldf.fill f57=[r31],32
- ldf.fill f58=[r32],32
- ;;
- ldf.fill f59=[r31],32
- ldf.fill f60=[r32],32
- ;;
- ldf.fill f61=[r31],32
- ldf.fill f62=[r32],32
- ;;
- ldf.fill f63=[r31],32
- ldf.fill f64=[r32],32
- ;;
- ldf.fill f65=[r31],32
- ldf.fill f66=[r32],32
- ;;
- ldf.fill f67=[r31],32
- ldf.fill f68=[r32],32
- ;;
- ldf.fill f69=[r31],32
- ldf.fill f70=[r32],32
- ;;
- ldf.fill f71=[r31],32
- ldf.fill f72=[r32],32
- ;;
- ldf.fill f73=[r31],32
- ldf.fill f74=[r32],32
- ;;
- ldf.fill f75=[r31],32
- ldf.fill f76=[r32],32
- ;;
- ldf.fill f77=[r31],32
- ldf.fill f78=[r32],32
- ;;
- ldf.fill f79=[r31],32
- ldf.fill f80=[r32],32
- ;;
- ldf.fill f81=[r31],32
- ldf.fill f82=[r32],32
- ;;
- ldf.fill f83=[r31],32
- ldf.fill f84=[r32],32
- ;;
- ldf.fill f85=[r31],32
- ldf.fill f86=[r32],32
- ;;
- ldf.fill f87=[r31],32
- ldf.fill f88=[r32],32
- ;;
- ldf.fill f89=[r31],32
- ldf.fill f90=[r32],32
- ;;
- ldf.fill f91=[r31],32
- ldf.fill f92=[r32],32
- ;;
- ldf.fill f93=[r31],32
- ldf.fill f94=[r32],32
- ;;
- ldf.fill f95=[r31],32
- ldf.fill f96=[r32],32
- ;;
- ldf.fill f97=[r31],32
- ldf.fill f98=[r32],32
- ;;
- ldf.fill f99=[r31],32
- ldf.fill f100=[r32],32
- ;;
- ldf.fill f101=[r31],32
- ldf.fill f102=[r32],32
- ;;
- ldf.fill f103=[r31],32
- ldf.fill f104=[r32],32
- ;;
- ldf.fill f105=[r31],32
- ldf.fill f106=[r32],32
- ;;
- ldf.fill f107=[r31],32
- ldf.fill f108=[r32],32
- ;;
- ldf.fill f109=[r31],32
- ldf.fill f110=[r32],32
- ;;
- ldf.fill f111=[r31],32
- ldf.fill f112=[r32],32
- ;;
- ldf.fill f113=[r31],32
- ldf.fill f114=[r32],32
- ;;
- ldf.fill f115=[r31],32
- ldf.fill f116=[r32],32
- ;;
- ldf.fill f117=[r31],32
- ldf.fill f118=[r32],32
- ;;
- ldf.fill f119=[r31],32
- ldf.fill f120=[r32],32
- ;;
- ldf.fill f121=[r31],32
- ldf.fill f122=[r32],32
- ;;
- ldf.fill f123=[r31],32
- ldf.fill f124=[r32],32
- ;;
- ldf.fill f125=[r31],32
- ldf.fill f126=[r32]
- ;;
- ldf.fill f127=[r31]
- ssm psr.dfh
- ;;
- srlz.d
- br.ret.sptk rp
- ;;
-END(restore_high_fp)
diff --git a/sys/ia64/ia64/exception.S b/sys/ia64/ia64/exception.S
deleted file mode 100644
index b93244a474ba..000000000000
--- a/sys/ia64/ia64/exception.S
+++ /dev/null
@@ -1,1396 +0,0 @@
-/*-
- * Copyright (c) 2003 Marcel Moolenaar
- * Copyright (c) 2000 Doug Rabson
- * 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$
- */
-
-#include <machine/asm.h>
-#include <machine/pte.h>
-#include <assym.s>
-
-/*
- * ar.k7 = kernel memory stack
- * ar.k6 = kernel register stack
- * ar.k5 = EPC gateway page
- * ar.k4 = PCPU data
- */
-
- .text
-
-/*
- * exception_save: save interrupted state
- *
- * Arguments:
- * r16 address of bundle that contains the branch. The
- * return address will be the next bundle.
- * r17 the value to save as ifa in the trapframe. This
- * normally is cr.ifa, but some interruptions set
- * set cr.iim and not cr.ifa.
- *
- * Returns:
- * p15 interrupted from user stack
- * p14 interrupted from kernel stack
- * p13 interrupted from user backing store
- * p12 interrupted from kernel backing store
- * p11 interrupts were enabled
- * p10 interrupts were disabled
- */
-ENTRY(exception_save, 0)
-{ .mii
- mov r20=ar.unat
- extr.u r31=sp,61,3
- mov r18=pr
- ;;
-}
-{ .mmi
- cmp.le p14,p15=5,r31
- ;;
-(p15) mov r23=ar.k7 // kernel memory stack
-(p14) mov r23=sp
- ;;
-}
-{ .mii
- mov r21=ar.rsc
- add r30=-SIZEOF_TRAPFRAME,r23
- ;;
- dep r30=0,r30,0,10
- ;;
-}
-{ .mmi
- mov ar.rsc=0
- sub r19=r23,r30
- add r31=8,r30
- ;;
-}
-{ .mlx
- mov r22=cr.iip
- movl r26=exception_save_restart
- ;;
-}
-
- /*
- * We have a 1KB aligned trapframe, pointed to by sp. If we write
- * to the trapframe, we may trigger a data nested TLB fault. By
- * aligning the trapframe on a 1KB boundary, we guarantee that if
- * we get a data nested TLB fault, it will be on the very first
- * write. Since the data nested TLB fault does not preserve any
- * state, we have to be careful what we clobber. Consequently, we
- * have to be careful what we use here. Below a list of registers
- * that are currently alive:
- * r16,r17=arguments
- * r18=pr, r19=length, r20=unat, r21=rsc, r22=iip, r23=TOS
- * r26=restart point
- * r30,r31=trapframe pointers
- * p14,p15=memory stack switch
- */
-exception_save_restart:
-{ .mmi
- st8 [r30]=r19,16 // length
- st8 [r31]=r0,16 // flags
- add r19=16,r19
- ;;
-}
-{ .mmi
- st8.spill [r30]=sp,16 // sp
- st8 [r31]=r20,16 // unat
- sub sp=r23,r19
- ;;
-}
-{ .mmi
- mov r19=ar.rnat
- mov r20=ar.bspstore
- mov r23=rp
- ;;
-}
- // r18=pr, r19=rnat, r20=bspstore, r21=rsc, r22=iip, r23=rp
-{ .mmi
- st8 [r30]=r23,16 // rp
- st8 [r31]=r18,16 // pr
- mov r24=ar.pfs
- ;;
-}
-{ .mmb
- st8 [r30]=r24,16 // pfs
- st8 [r31]=r20,16 // bspstore
- cover
- ;;
-}
-{ .mmi
- mov r18=ar.fpsr
- mov r23=cr.ipsr
- extr.u r24=r20,61,3
- ;;
-}
- // r18=fpsr, r19=rnat, r20=bspstore, r21=rsc, r22=iip, r23=ipsr
-{ .mmi
- st8 [r30]=r19,16 // rnat
- st8 [r31]=r0,16 // __spare
- cmp.le p12,p13=5,r24
- ;;
-}
-{ .mmi
- st8.spill [r30]=r13,16 // tp
- st8 [r31]=r21,16 // rsc
- tbit.nz p11,p10=r23,14 // p11=interrupts enabled
- ;;
-}
-{ .mmi
- st8 [r30]=r18,16 // fpsr
-(p13) mov r20=ar.k6 // kernel register stack
- nop 0
- ;;
-}
- // r20=bspstore, r22=iip, r23=ipsr
-{ .mmi
- st8 [r31]=r23,16 // psr
-(p13) mov ar.bspstore=r20
- nop 0
- ;;
-}
-{ .mmi
- mov r18=ar.bsp
- ;;
- mov r19=cr.ifs
- sub r18=r18,r20
- ;;
-}
-{ .mmi
- st8.spill [r30]=gp,16 // gp
- st8 [r31]=r18,16 // ndirty
- nop 0
- ;;
-}
- // r19=ifs, r22=iip
-{ .mmi
- st8 [r30]=r19,16 // cfm
- st8 [r31]=r22,16 // iip
- nop 0
- ;;
-}
-{ .mmi
- st8 [r30]=r17 // ifa
- mov r18=cr.isr
- add r29=16,r30
- ;;
-}
-{ .mmi
- st8 [r31]=r18 // isr
- add r30=8,r29
- add r31=16,r29
- ;;
-}
-{ .mmi
- .mem.offset 0,0
- st8.spill [r30]=r2,16 // r2
- .mem.offset 8,0
- st8.spill [r31]=r3,16 // r3
- add r2=9*8,r29
- ;;
-}
-{ .mmi
- .mem.offset 0,0
- st8.spill [r30]=r8,16 // r8
- .mem.offset 8,0
- st8.spill [r31]=r9,16 // r9
- add r3=8,r2
- ;;
-}
-{ .mmi
- .mem.offset 0,0
- st8.spill [r30]=r10,16 // r10
- .mem.offset 8,0
- st8.spill [r31]=r11,16 // r11
- add r8=16,r16
- ;;
-}
-{ .mmi
- .mem.offset 0,0
- st8.spill [r30]=r14 // r14
- .mem.offset 8,0
- st8.spill [r31]=r15 // r15
- mov r9=r29
-}
-{ .mmb
- mov r10=ar.csd
- mov r11=ar.ssd
- bsw.1
- ;;
-}
-{ .mmi
- .mem.offset 0,0
- st8.spill [r2]=r16,16 // r16
- .mem.offset 8,0
- st8.spill [r3]=r17,16 // r17
- mov r14=b6
- ;;
-}
-{ .mmi
- .mem.offset 0,0
- st8.spill [r2]=r18,16 // r18
- .mem.offset 8,0
- st8.spill [r3]=r19,16 // r19
- mov r15=b7
- ;;
-}
-{ .mmi
- .mem.offset 0,0
- st8.spill [r2]=r20,16 // r20
- .mem.offset 8,0
- st8.spill [r3]=r21,16 // r21
- mov b7=r8
- ;;
-}
-{ .mmi
- .mem.offset 0,0
- st8.spill [r2]=r22,16 // r22
- .mem.offset 8,0
- st8.spill [r3]=r23,16 // r23
- ;;
-}
-
- .mem.offset 0,0
- st8.spill [r2]=r24,16 // r24
- .mem.offset 8,0
- st8.spill [r3]=r25,16 // r25
- ;;
- .mem.offset 0,0
- st8.spill [r2]=r26,16 // r26
- .mem.offset 8,0
- st8.spill [r3]=r27,16 // r27
- ;;
- .mem.offset 0,0
- st8.spill [r2]=r28,16 // r28
- .mem.offset 8,0
- st8.spill [r3]=r29,16 // r29
- ;;
- .mem.offset 0,0
- st8.spill [r2]=r30,16 // r30
- .mem.offset 8,0
- st8.spill [r3]=r31,16 // r31
- ;;
-
-{ .mmi
- st8 [r2]=r14,16 // b6
- mov r17=ar.unat
- nop 0
- ;;
-}
-{ .mmi
- st8 [r3]=r15,16 // b7
- mov r16=ar.ccv
- nop 0
- ;;
-}
-{ .mmi
- st8 [r2]=r16,16 // ccv
- st8 [r3]=r10,16 // csd
- nop 0
- ;;
-}
-{ .mmi
- st8 [r2]=r11,24 // ssd
- st8 [r9]=r17
- nop 0
- ;;
-}
-
- stf.spill [r3]=f6,32 // f6
- stf.spill [r2]=f7,32 // f7
- ;;
- stf.spill [r3]=f8,32 // f8
- stf.spill [r2]=f9,32 // f9
- ;;
- stf.spill [r3]=f10,32 // f10
- stf.spill [r2]=f11,32 // f11
- ;;
- stf.spill [r3]=f12,32 // f12
- stf.spill [r2]=f13,32 // f13
- ;;
- stf.spill [r3]=f14 // f14
- stf.spill [r2]=f15 // f15
- ;;
-{ .mmi
- mov ar.rsc=3
- mov r13=ar.k4
- nop 0
- ;;
-}
-{ .mlx
- ssm psr.ic|psr.dfh
- movl gp=__gp
- ;;
-}
-{ .mfb
- srlz.d
- nop 0
- br.sptk b7
- ;;
-}
-END(exception_save)
-
-/*
- * exception_restore: restore interrupted state
- *
- * Arguments:
- * sp+16 trapframe pointer
- */
-ENTRY(exception_restore, 0)
-{ .mmi
- rsm psr.i
- add sp=16,sp
- nop 0
- ;;
-}
-{ .mmi
- add r3=SIZEOF_TRAPFRAME-32,sp
- add r2=SIZEOF_TRAPFRAME-16,sp
- add r8=SIZEOF_SPECIAL+16,sp
- ;;
-}
- // The next load can trap. Let it be...
- ldf.fill f15=[r2],-32 // f15
- ldf.fill f14=[r3],-32 // f14
- ;;
- ldf.fill f13=[r2],-32 // f13
- ldf.fill f12=[r3],-32 // f12
- ;;
- ldf.fill f11=[r2],-32 // f11
- ldf.fill f10=[r3],-32 // f10
- ;;
- ldf.fill f9=[r2],-32 // f9
- ldf.fill f8=[r3],-32 // f8
- ;;
- ldf.fill f7=[r2],-24 // f7
- ldf.fill f6=[r3],-16 // f6
- ;;
-
-{ .mmi
- ld8 r8=[r8] // unat (after)
- ;;
- mov ar.unat=r8
- nop 0
- ;;
-}
-
- ld8 r10=[r2],-16 // ssd
- ld8 r11=[r3],-16 // csd
- ;;
- mov ar.ssd=r10
- mov ar.csd=r11
-
- ld8 r14=[r2],-16 // ccv
- ld8 r15=[r3],-16 // b7
- ;;
-
-{ .mmi
- mov ar.ccv=r14
- ld8 r8=[r2],-16 // b6
- mov b7=r15
- ;;
-}
-{ .mmi
- ld8.fill r31=[r3],-16 // r31
- ld8.fill r30=[r2],-16 // r30
- mov b6=r8
- ;;
-}
-
- ld8.fill r29=[r3],-16 // r29
- ld8.fill r28=[r2],-16 // r28
- ;;
- ld8.fill r27=[r3],-16 // r27
- ld8.fill r26=[r2],-16 // r26
- ;;
- ld8.fill r25=[r3],-16 // r25
- ld8.fill r24=[r2],-16 // r24
- ;;
- ld8.fill r23=[r3],-16 // r23
- ld8.fill r22=[r2],-16 // r22
- ;;
- ld8.fill r21=[r3],-16 // r21
- ld8.fill r20=[r2],-16 // r20
- ;;
- ld8.fill r19=[r3],-16 // r19
- ld8.fill r18=[r2],-16 // r18
- ;;
-
-{ .mmb
- ld8.fill r17=[r3],-16 // r17
- ld8.fill r16=[r2],-16 // r16
- bsw.0
- ;;
-}
-{ .mmi
- ld8.fill r15=[r3],-16 // r15
- ld8.fill r14=[r2],-16 // r14
- add r31=16,sp
- ;;
-}
-{ .mmi
- ld8 r16=[sp] // tf_length
- ld8.fill r11=[r3],-16 // r11
- add r30=24,sp
- ;;
-}
-{ .mmi
- ld8.fill r10=[r2],-16 // r10
- ld8.fill r9=[r3],-16 // r9
- add r16=r16,sp // ar.k7
- ;;
-}
-{ .mmi
- ld8.fill r8=[r2],-16 // r8
- ld8.fill r3=[r3] // r3
- ;;
-}
- // We want nested TLB faults from here on...
- rsm psr.ic|psr.i
- ld8.fill r2=[r2] // r2
- nop 0
- ;;
- srlz.d
- ld8.fill sp=[r31],16 // sp
- nop 0
- ;;
-
- ld8 r17=[r30],16 // unat
- ld8 r29=[r31],16 // rp
- ;;
- ld8 r18=[r30],16 // pr
- ld8 r28=[r31],16 // pfs
- mov rp=r29
- ;;
- ld8 r20=[r30],24 // bspstore
- ld8 r21=[r31],24 // rnat
- mov ar.pfs=r28
- ;;
- ld8.fill r29=[r30],16 // tp
- ld8 r22=[r31],16 // rsc
- ;;
-{ .mmi
- ld8 r23=[r30],16 // fpsr
- ld8 r24=[r31],16 // psr
- extr.u r28=r20,61,3
- ;;
-}
-{ .mmi
- ld8.fill r1=[r30],16 // gp
- ld8 r25=[r31],16 // ndirty
- cmp.le p14,p15=5,r28
- ;;
-}
-{ .mmb
- ld8 r26=[r30] // cfm
- ld8 r19=[r31] // ip
- nop 0
- ;;
-}
-{ .mib
- // Switch register stack
- alloc r30=ar.pfs,0,0,0,0 // discard current frame
- shl r31=r25,16 // value for ar.rsc
- nop 0
- ;;
-}
- // The loadrs can fault if the backing store is not currently
- // mapped. We assured forward progress by getting everything we
- // need from the trapframe so that we don't care if the CPU
- // purges that translation when it needs to insert a new one for
- // the backing store.
-{ .mmi
- mov ar.rsc=r31 // setup for loadrs
- mov ar.k7=r16
-(p15) mov r13=r29
- ;;
-}
-exception_restore_restart:
-{ .mmi
- mov r30=ar.bspstore
- ;;
- loadrs // load user regs
- nop 0
- ;;
-}
-{ .mmi
-(p15) mov r31=ar.bspstore
- ;;
- mov ar.bspstore=r20
-(p15) dep r31=0,r31,0,9
- ;;
-}
-{ .mmb
- mov ar.k6=r31
- mov ar.rnat=r21
- nop 0
- ;;
-}
-{ .mmb
- mov ar.unat=r17
- mov cr.iip=r19
- nop 0
-}
-{ .mmi
- mov cr.ipsr=r24
- mov cr.ifs=r26
- mov pr=r18,0x1fffe
- ;;
-}
-{ .mmb
- mov ar.rsc=r22
- mov ar.fpsr=r23
- rfi
- ;;
-}
-END(exception_restore)
-
-/*
- * Call exception_save_regs to preserve the interrupted state in a
- * trapframe. Note that we don't use a call instruction because we
- * must be careful not to lose track of the RSE state. We then call
- * trap() with the value of _n_ as an argument to handle the
- * exception. We arrange for trap() to return to exception_restore
- * which will restore the interrupted state before executing an rfi to
- * resume it.
- */
-#define TRAP(_n_, _ifa_) \
-{ .mib ; \
- mov r17=_ifa_ ; \
- mov r16=ip ; \
- br.sptk exception_save ; \
-} ; \
-{ .mmi ; \
-(p11) ssm psr.i ;; \
- alloc r15=ar.pfs,0,0,2,0 ; \
- mov out0=_n_ ;; \
-} ; \
-{ .mfb ; \
- add out1=16,sp ; \
- nop 0 ; \
- br.call.sptk rp=trap ; \
-} ; \
-{ .mfb ; \
- nop 0 ; \
- nop 0 ; \
- br.sptk exception_restore ; \
-}
-
-#define IVT_ENTRY(name, offset) \
- .org ia64_vector_table + offset; \
- .global ivt_##name; \
- .proc ivt_##name; \
- .prologue; \
- .unwabi @svr4, 'I'; \
- .save rp, r0; \
- .body; \
-ivt_##name:
-
-#define IVT_END(name) \
- .endp ivt_##name; \
- .align 0x100
-
-/*
- * The IA64 Interrupt Vector Table (IVT) contains 20 slots with 64
- * bundles per vector and 48 slots with 16 bundles per vector.
- */
-
- .section .text.ivt,"ax"
-
- .align 32768
- .global ia64_vector_table
- .size ia64_vector_table, 32768
-ia64_vector_table:
-
-IVT_ENTRY(VHPT_Translation, 0x0000)
- TRAP(0, cr.ifa)
-IVT_END(VHPT_Translation)
-
-IVT_ENTRY(Instruction_TLB, 0x0400)
- mov r16=cr.ifa
- mov r17=pr
- ;;
- thash r18=r16
- ttag r19=r16
- ;;
- add r21=16,r18 // tag
- add r20=24,r18 // collision chain
- ;;
- ld8 r21=[r21] // check VHPT tag
- ;;
- cmp.ne p15,p0=r21,r19
-(p15) br.dpnt.few 1f
- ;;
- ld8 r21=[r18] // read pte
- ;;
- itc.i r21 // insert pte
- ;;
- mov pr=r17,0x1ffff
- rfi // done
- ;;
-1: ld8 r20=[r20] // first entry
- ;;
- rsm psr.dt // turn off data translations
- ;;
- srlz.d // serialize
- ;;
-2: cmp.eq p15,p0=r0,r20 // done?
-(p15) br.cond.spnt.few 9f // bail if done
- ;;
- add r21=16,r20 // tag location
- ;;
- ld8 r21=[r21] // read tag
- ;;
- cmp.ne p15,p0=r21,r19 // compare tags
-(p15) br.cond.sptk.few 3f // if not, read next in chain
- ;;
- ld8 r21=[r20],8 // read pte
- ;;
- ld8 r22=[r20] // read rest of pte
- ;;
- dep r18=0,r18,61,3 // convert vhpt ptr to physical
- ;;
- add r20=16,r18 // address of tag
- ;;
- ld8.acq r23=[r20] // read old tag
- ;;
- dep r23=-1,r23,63,1 // set ti bit
- ;;
- st8.rel [r20]=r23 // store old tag + ti
- ;;
- mf // make sure everyone sees
- ;;
- st8 [r18]=r21,8 // store pte
- ;;
- st8 [r18]=r22,8
- ;;
- st8.rel [r18]=r19 // store new tag
- ;;
- itc.i r21 // and place in TLB
- ;;
- mov pr=r17,0x1ffff // restore predicates
- rfi
-
-3: add r20=24,r20 // next in chain
- ;;
- ld8 r20=[r20] // read chain
- br.cond.sptk.few 2b // loop
-
-9: mov pr=r17,0x1ffff // restore predicates
- ssm psr.dt
- ;;
- srlz.d
- ;;
- TRAP(20, cr.ifa) // Page Not Present trap
-IVT_END(Instruction_TLB)
-
-IVT_ENTRY(Data_TLB, 0x0800)
- mov r16=cr.ifa
- mov r17=pr
- ;;
- thash r18=r16
- ttag r19=r16
- ;;
- add r21=16,r18 // tag
- add r20=24,r18 // collision chain
- ;;
- ld8 r21=[r21] // check VHPT tag
- ;;
- cmp.ne p15,p0=r21,r19
-(p15) br.dpnt.few 1f
- ;;
- ld8 r21=[r18] // read pte
- ;;
- itc.d r21 // insert pte
- ;;
- mov pr=r17,0x1ffff
- rfi // done
- ;;
-1: ld8 r20=[r20] // first entry
- ;;
- rsm psr.dt // turn off data translations
- ;;
- srlz.d // serialize
- ;;
-2: cmp.eq p15,p0=r0,r20 // done?
-(p15) br.cond.spnt.few 9f // bail if done
- ;;
- add r21=16,r20 // tag location
- ;;
- ld8 r21=[r21] // read tag
- ;;
- cmp.ne p15,p0=r21,r19 // compare tags
-(p15) br.cond.sptk.few 3f // if not, read next in chain
- ;;
- ld8 r21=[r20],8 // read pte
- ;;
- ld8 r22=[r20] // read rest of pte
- ;;
- dep r18=0,r18,61,3 // convert vhpt ptr to physical
- ;;
- add r20=16,r18 // address of tag
- ;;
- ld8.acq r23=[r20] // read old tag
- ;;
- dep r23=-1,r23,63,1 // set ti bit
- ;;
- st8.rel [r20]=r23 // store old tag + ti
- ;;
- mf // make sure everyone sees
- ;;
- st8 [r18]=r21,8 // store pte
- ;;
- st8 [r18]=r22,8
- ;;
- st8.rel [r18]=r19 // store new tag
- ;;
- itc.d r21 // and place in TLB
- ;;
- mov pr=r17,0x1ffff // restore predicates
- rfi
-
-3: add r20=24,r20 // next in chain
- ;;
- ld8 r20=[r20] // read chain
- br.cond.sptk.few 2b // loop
-
-9: mov pr=r17,0x1ffff // restore predicates
- ssm psr.dt
- ;;
- srlz.d
- ;;
- TRAP(20, cr.ifa) // Page Not Present trap
-IVT_END(Data_TLB)
-
-IVT_ENTRY(Alternate_Instruction_TLB, 0x0c00)
- mov r16=cr.ifa // where did it happen
- mov r18=pr // save predicates
- ;;
- extr.u r17=r16,61,3 // get region number
- ;;
- cmp.ge p13,p0=5,r17 // RR0-RR5?
- cmp.eq p15,p14=7,r17 // RR7->p15, RR6->p14
-(p13) br.spnt 9f
- ;;
-(p15) movl r17=PTE_P+PTE_MA_WB+PTE_A+PTE_D+PTE_PL_KERN+PTE_AR_RX
-(p14) movl r17=PTE_P+PTE_MA_UC+PTE_A+PTE_D+PTE_PL_KERN+PTE_AR_RX
- ;;
- dep r16=0,r16,50,14 // clear bits above PPN
- ;;
- dep r16=r17,r16,0,12 // put pte bits in 0..11
- ;;
- itc.i r16
- mov pr=r18,0x1ffff // restore predicates
- ;;
- rfi
-9: mov pr=r18,0x1ffff // restore predicates
- TRAP(3, cr.ifa)
-IVT_END(Alternate_Instruction_TLB)
-
-IVT_ENTRY(Alternate_Data_TLB, 0x1000)
- mov r16=cr.ifa // where did it happen
- mov r18=pr // save predicates
- ;;
- extr.u r17=r16,61,3 // get region number
- ;;
- cmp.ge p13,p0=5,r17 // RR0-RR5?
- cmp.eq p15,p14=7,r17 // RR7->p15, RR6->p14
-(p13) br.spnt 9f
- ;;
-(p15) movl r17=PTE_P+PTE_MA_WB+PTE_A+PTE_D+PTE_PL_KERN+PTE_AR_RW
-(p14) movl r17=PTE_P+PTE_MA_UC+PTE_A+PTE_D+PTE_PL_KERN+PTE_AR_RW
- ;;
- dep r16=0,r16,50,14 // clear bits above PPN
- ;;
- dep r16=r17,r16,0,12 // put pte bits in 0..11
- ;;
- itc.d r16
- mov pr=r18,0x1ffff // restore predicates
- ;;
- rfi
-9: mov pr=r18,0x1ffff // restore predicates
- TRAP(4, cr.ifa)
-IVT_END(Alternate_Data_TLB)
-
-IVT_ENTRY(Data_Nested_TLB, 0x1400)
- // See exception_save_restart and exception_restore_restart for the
- // contexts that may cause a data nested TLB. We can only use the
- // banked general registers and predicates, but don't use:
- // p14 & p15 - Set in exception save
- // r16 & r17 - Arguments to exception save
- // r30 - Faulting address (modulo page size)
- // We assume r30 has the virtual addresses that relate to the data
- // nested TLB fault. The address does not have to be exact, as long
- // as it's in the same page. We use physical addressing to avoid
- // double nested faults. Since all virtual addresses we encounter
- // here are direct mapped region 7 addresses, we have no problem
- // constructing physical addresses.
-{ .mlx
- rsm psr.dt
- movl r27=ia64_kptdir
- ;;
-}
-{ .mii
- srlz.d
- dep r27=0,r27,61,3
- extr.u r28=r30,PAGE_SHIFT,61-PAGE_SHIFT
- ;;
-}
-{ .mii
- ld8 r27=[r27]
- shr.u r29=r28,PAGE_SHIFT-5 // dir index
- extr.u r28=r28,0,PAGE_SHIFT-5 // pte index
- ;;
-}
-{ .mmi
- shladd r27=r29,3,r27
- ;;
- mov cr.ifa=r30
- dep r27=0,r27,61,3
- ;;
-}
-{ .mmi
- ld8 r27=[r27]
- mov r29=rr[r30]
- shl r28=r28,5
- ;;
-}
-{ .mii
- add r27=r27,r28 // address of pte
- dep r29=0,r29,0,2
- ;;
- dep r27=0,r27,61,3
- ;;
-}
-{ .mmi
- ld8 r28=[r27]
- ;;
- mov cr.itir=r29
- or r28=PTE_D|PTE_A,r28
- ;;
-}
-{ .mlx
- st8 [r27]=r28
- movl r29=exception_save_restart
- ;;
-}
-{ .mmi
- itc.d r28
- ;;
- ssm psr.dt
- cmp.eq p12,p13=r26,r29
- ;;
-}
-{ .mbb
- srlz.d
-(p12) br.sptk exception_save_restart
-(p13) br.sptk exception_restore_restart
- ;;
-}
-IVT_END(Data_Nested_TLB)
-
-IVT_ENTRY(Instruction_Key_Miss, 0x1800)
- TRAP(6, cr.ifa)
-IVT_END(Instruction_Key_Miss)
-
-IVT_ENTRY(Data_Key_Miss, 0x1c00)
- TRAP(7, cr.ifa)
-IVT_END(Data_Key_Miss)
-
-IVT_ENTRY(Dirty_Bit, 0x2000)
- mov r16=cr.ifa
- mov r17=pr
- ;;
- thash r18=r16
- ;;
- ttag r19=r16
- add r20=24,r18 // collision chain
- ;;
- ld8 r20=[r20] // first entry
- ;;
- rsm psr.dt // turn off data translations
- ;;
- srlz.d // serialize
- ;;
-1: cmp.eq p15,p0=r0,r20 // done?
-(p15) br.cond.spnt.few 9f // bail if done
- ;;
- add r21=16,r20 // tag location
- ;;
- ld8 r21=[r21] // read tag
- ;;
- cmp.ne p15,p0=r21,r19 // compare tags
-(p15) br.cond.sptk.few 2f // if not, read next in chain
- ;;
- ld8 r21=[r20] // read pte
- mov r22=PTE_D|PTE_A
- ;;
- or r21=r22,r21 // set dirty & access bit
- ;;
- st8 [r20]=r21,8 // store back
- ;;
- ld8 r22=[r20] // read rest of pte
- ;;
- dep r18=0,r18,61,3 // convert vhpt ptr to physical
- ;;
- add r20=16,r18 // address of tag
- ;;
- ld8.acq r23=[r20] // read old tag
- ;;
- dep r23=-1,r23,63,1 // set ti bit
- ;;
- st8.rel [r20]=r23 // store old tag + ti
- ;;
- mf // make sure everyone sees
- ;;
- st8 [r18]=r21,8 // store pte
- ;;
- st8 [r18]=r22,8
- ;;
- st8.rel [r18]=r19 // store new tag
- ;;
- itc.d r21 // and place in TLB
- ;;
- mov pr=r17,0x1ffff // restore predicates
- rfi
-
-2: add r20=24,r20 // next in chain
- ;;
- ld8 r20=[r20] // read chain
- br.cond.sptk.few 1b // loop
-
-9: mov pr=r17,0x1ffff // restore predicates
- TRAP(8, cr.ifa) // die horribly
-IVT_END(Dirty_Bit)
-
-IVT_ENTRY(Instruction_Access_Bit, 0x2400)
- mov r16=cr.ifa
- mov r17=pr
- ;;
- thash r18=r16
- ;;
- ttag r19=r16
- add r20=24,r18 // collision chain
- ;;
- ld8 r20=[r20] // first entry
- ;;
- rsm psr.dt // turn off data translations
- ;;
- srlz.d // serialize
- ;;
-1: cmp.eq p15,p0=r0,r20 // done?
-(p15) br.cond.spnt.few 9f // bail if done
- ;;
- add r21=16,r20 // tag location
- ;;
- ld8 r21=[r21] // read tag
- ;;
- cmp.ne p15,p0=r21,r19 // compare tags
-(p15) br.cond.sptk.few 2f // if not, read next in chain
- ;;
- ld8 r21=[r20] // read pte
- mov r22=PTE_A
- ;;
- or r21=r22,r21 // set accessed bit
- ;;
- st8 [r20]=r21,8 // store back
- ;;
- ld8 r22=[r20] // read rest of pte
- ;;
- dep r18=0,r18,61,3 // convert vhpt ptr to physical
- ;;
- add r20=16,r18 // address of tag
- ;;
- ld8.acq r23=[r20] // read old tag
- ;;
- dep r23=-1,r23,63,1 // set ti bit
- ;;
- st8.rel [r20]=r23 // store old tag + ti
- ;;
- mf // make sure everyone sees
- ;;
- st8 [r18]=r21,8 // store pte
- ;;
- st8 [r18]=r22,8
- ;;
- st8.rel [r18]=r19 // store new tag
- ;;
- itc.i r21 // and place in TLB
- ;;
- mov pr=r17,0x1ffff // restore predicates
- rfi // walker will retry the access
-
-2: add r20=24,r20 // next in chain
- ;;
- ld8 r20=[r20] // read chain
- br.cond.sptk.few 1b // loop
-
-9: mov pr=r17,0x1ffff // restore predicates
- TRAP(9, cr.ifa)
-IVT_END(Instruction_Access_Bit)
-
-IVT_ENTRY(Data_Access_Bit, 0x2800)
- mov r16=cr.ifa
- mov r17=pr
- ;;
- thash r18=r16
- ;;
- ttag r19=r16
- add r20=24,r18 // collision chain
- ;;
- ld8 r20=[r20] // first entry
- ;;
- rsm psr.dt // turn off data translations
- ;;
- srlz.d // serialize
- ;;
-1: cmp.eq p15,p0=r0,r20 // done?
-(p15) br.cond.spnt.few 9f // bail if done
- ;;
- add r21=16,r20 // tag location
- ;;
- ld8 r21=[r21] // read tag
- ;;
- cmp.ne p15,p0=r21,r19 // compare tags
-(p15) br.cond.sptk.few 2f // if not, read next in chain
- ;;
- ld8 r21=[r20] // read pte
- mov r22=PTE_A
- ;;
- or r21=r22,r21 // set accessed bit
- ;;
- st8 [r20]=r21,8 // store back
- ;;
- ld8 r22=[r20] // read rest of pte
- ;;
- dep r18=0,r18,61,3 // convert vhpt ptr to physical
- ;;
- add r20=16,r18 // address of tag
- ;;
- ld8.acq r23=[r20] // read old tag
- ;;
- dep r23=-1,r23,63,1 // set ti bit
- ;;
- st8.rel [r20]=r23 // store old tag + ti
- ;;
- mf // make sure everyone sees
- ;;
- st8 [r18]=r21,8 // store pte
- ;;
- st8 [r18]=r22,8
- ;;
- st8.rel [r18]=r19 // store new tag
- ;;
- itc.d r21 // and place in TLB
- ;;
- mov pr=r17,0x1ffff // restore predicates
- rfi // walker will retry the access
-
-2: add r20=24,r20 // next in chain
- ;;
- ld8 r20=[r20] // read chain
- br.cond.sptk.few 1b // loop
-
-9: mov pr=r17,0x1ffff // restore predicates
- TRAP(10, cr.ifa)
-IVT_END(Data_Access_Bit)
-
-IVT_ENTRY(Break_Instruction, 0x2c00)
-{ .mib
- mov r17=cr.iim
- mov r16=ip
- br.sptk exception_save
- ;;
-}
-{ .mmi
- alloc r15=ar.pfs,0,0,2,0
- ;;
- flushrs
- mov out0=11
- ;;
-}
-{ .mib
-(p11) ssm psr.i
- add out1=16,sp
- br.call.sptk rp=trap
- ;;
-}
-{ .mfb
- nop 0
- nop 0
- br.sptk exception_restore
- ;;
-}
-IVT_END(Break_Instruction)
-
-IVT_ENTRY(External_Interrupt, 0x3000)
-{ .mib
- mov r17=cr.lid // cr.iim and cr.ifa are undefined.
- mov r16=ip
- br.sptk exception_save
- ;;
-}
-{ .mmb
-2: alloc r14=ar.pfs,0,0,2,0 // make a frame for calling with
- add out1=16,sp
- nop 0
-}
-
-3: mov out0=cr.ivr // find interrupt vector
- ;;
- cmp.eq p15,p0=15,out0 // check for spurious vector number
-(p15) br.dpnt.few exception_restore // if spurious, we are done
- ;;
- ssm psr.i // re-enable interrupts
- br.call.sptk.many rp=interrupt // call high-level handler
- ;;
- rsm psr.i // disable interrupts
- ;;
- srlz.d
- mov cr.eoi=r0 // and ack the interrupt
- ;;
- srlz.d
- br.sptk.few 3b // loop for more
- ;;
-IVT_END(External_Interrupt)
-
-IVT_ENTRY(Reserved_3400, 0x3400)
- TRAP(13, cr.ifa)
-IVT_END(Reserved_3400)
-
-IVT_ENTRY(Reserved_3800, 0x3800)
- TRAP(14, cr.ifa)
-IVT_END(Reserved_3800)
-
-IVT_ENTRY(Reserved_3c00, 0x3c00)
- TRAP(15, cr.ifa)
-IVT_END(Reserved_3c00)
-
-IVT_ENTRY(Reserved_4000, 0x4000)
- TRAP(16, cr.ifa)
-IVT_END(Reserved_4000)
-
-IVT_ENTRY(Reserved_4400, 0x4400)
- TRAP(17, cr.ifa)
-IVT_END(Reserved_4400)
-
-IVT_ENTRY(Reserved_4800, 0x4800)
- TRAP(18, cr.ifa)
-IVT_END(Reserved_4800)
-
-IVT_ENTRY(Reserved_4c00, 0x4c00)
- TRAP(19, cr.ifa)
-IVT_END(Reserved_4c00)
-
-IVT_ENTRY(Page_Not_Present, 0x5000)
- TRAP(20, cr.ifa)
-IVT_END(Page_Not_Present)
-
-IVT_ENTRY(Key_Permission, 0x5100)
- TRAP(21, cr.ifa)
-IVT_END(Key_Permission)
-
-IVT_ENTRY(Instruction_Access_Rights, 0x5200)
- TRAP(22, cr.ifa)
-IVT_END(Instruction_Access_Rights)
-
-IVT_ENTRY(Data_Access_Rights, 0x5300)
- TRAP(23, cr.ifa)
-IVT_END(Data_Access_Rights)
-
-IVT_ENTRY(General_Exception, 0x5400)
- TRAP(24, cr.ifa)
-IVT_END(General_Exception)
-
-IVT_ENTRY(Disabled_FP_Register, 0x5500)
- TRAP(25, cr.ifa)
-IVT_END(Disabled_FP_Register)
-
-IVT_ENTRY(NaT_Consumption, 0x5600)
- TRAP(26, cr.ifa)
-IVT_END(NaT_Consumption)
-
-IVT_ENTRY(Speculation, 0x5700)
- TRAP(27, cr.iim)
-IVT_END(Speculation)
-
-IVT_ENTRY(Reserved_5800, 0x5800)
- TRAP(28, cr.ifa)
-IVT_END(Reserved_5800)
-
-IVT_ENTRY(Debug, 0x5900)
- TRAP(29, cr.ifa)
-IVT_END(Debug)
-
-IVT_ENTRY(Unaligned_Reference, 0x5a00)
- TRAP(30, cr.ifa)
-IVT_END(Unaligned_Reference)
-
-IVT_ENTRY(Unsupported_Data_Reference, 0x5b00)
- TRAP(31, cr.ifa)
-IVT_END(Unsupported_Data_Reference)
-
-IVT_ENTRY(Floating_Point_Fault, 0x5c00)
- TRAP(32, cr.ifa)
-IVT_END(Floating_Point_Fault)
-
-IVT_ENTRY(Floating_Point_Trap, 0x5d00)
- TRAP(33, cr.ifa)
-IVT_END(Floating_Point_Trap)
-
-IVT_ENTRY(Lower_Privilege_Transfer_Trap, 0x5e00)
- TRAP(34, cr.ifa)
-IVT_END(Lower_Privilege_Transfer_Trap)
-
-IVT_ENTRY(Taken_Branch_Trap, 0x5f00)
- TRAP(35, cr.ifa)
-IVT_END(Taken_Branch_Trap)
-
-IVT_ENTRY(Single_Step_Trap, 0x6000)
- TRAP(36, cr.ifa)
-IVT_END(Single_Step_Trap)
-
-IVT_ENTRY(Reserved_6100, 0x6100)
- TRAP(37, cr.ifa)
-IVT_END(Reserved_6100)
-
-IVT_ENTRY(Reserved_6200, 0x6200)
- TRAP(38, cr.ifa)
-IVT_END(Reserved_6200)
-
-IVT_ENTRY(Reserved_6300, 0x6300)
- TRAP(39, cr.ifa)
-IVT_END(Reserved_6300)
-
-IVT_ENTRY(Reserved_6400, 0x6400)
- TRAP(40, cr.ifa)
-IVT_END(Reserved_6400)
-
-IVT_ENTRY(Reserved_6500, 0x6500)
- TRAP(41, cr.ifa)
-IVT_END(Reserved_6500)
-
-IVT_ENTRY(Reserved_6600, 0x6600)
- TRAP(42, cr.ifa)
-IVT_END(Reserved_6600)
-
-IVT_ENTRY(Reserved_6700, 0x6700)
- TRAP(43, cr.ifa)
-IVT_END(Reserved_6700)
-
-IVT_ENTRY(Reserved_6800, 0x6800)
- TRAP(44, cr.ifa)
-IVT_END(Reserved_6800)
-
-IVT_ENTRY(IA_32_Exception, 0x6900)
- TRAP(45, cr.ifa)
-IVT_END(IA_32_Exception)
-
-IVT_ENTRY(IA_32_Intercept, 0x6a00)
- TRAP(46, cr.iim)
-IVT_END(IA_32_Intercept)
-
-IVT_ENTRY(IA_32_Interrupt, 0x6b00)
- TRAP(47, cr.ifa)
-IVT_END(IA_32_Interrupt)
-
-IVT_ENTRY(Reserved_6c00, 0x6c00)
- TRAP(48, cr.ifa)
-IVT_END(Reserved_6c00)
-
-IVT_ENTRY(Reserved_6d00, 0x6d00)
- TRAP(49, cr.ifa)
-IVT_END(Reserved_6d00)
-
-IVT_ENTRY(Reserved_6e00, 0x6e00)
- TRAP(50, cr.ifa)
-IVT_END(Reserved_6e00)
-
-IVT_ENTRY(Reserved_6f00, 0x6f00)
- TRAP(51, cr.ifa)
-IVT_END(Reserved_6f00)
-
-IVT_ENTRY(Reserved_7000, 0x7000)
- TRAP(52, cr.ifa)
-IVT_END(Reserved_7000)
-
-IVT_ENTRY(Reserved_7100, 0x7100)
- TRAP(53, cr.ifa)
-IVT_END(Reserved_7100)
-
-IVT_ENTRY(Reserved_7200, 0x7200)
- TRAP(54, cr.ifa)
-IVT_END(Reserved_7200)
-
-IVT_ENTRY(Reserved_7300, 0x7300)
- TRAP(55, cr.ifa)
-IVT_END(Reserved_7300)
-
-IVT_ENTRY(Reserved_7400, 0x7400)
- TRAP(56, cr.ifa)
-IVT_END(Reserved_7400)
-
-IVT_ENTRY(Reserved_7500, 0x7500)
- TRAP(57, cr.ifa)
-IVT_END(Reserved_7500)
-
-IVT_ENTRY(Reserved_7600, 0x7600)
- TRAP(58, cr.ifa)
-IVT_END(Reserved_7600)
-
-IVT_ENTRY(Reserved_7700, 0x7700)
- TRAP(59, cr.ifa)
-IVT_END(Reserved_7700)
-
-IVT_ENTRY(Reserved_7800, 0x7800)
- TRAP(60, cr.ifa)
-IVT_END(Reserved_7800)
-
-IVT_ENTRY(Reserved_7900, 0x7900)
- TRAP(61, cr.ifa)
-IVT_END(Reserved_7900)
-
-IVT_ENTRY(Reserved_7a00, 0x7a00)
- TRAP(62, cr.ifa)
-IVT_END(Reserved_7a00)
-
-IVT_ENTRY(Reserved_7b00, 0x7b00)
- TRAP(63, cr.ifa)
-IVT_END(Reserved_7b00)
-
-IVT_ENTRY(Reserved_7c00, 0x7c00)
- TRAP(64, cr.ifa)
-IVT_END(Reserved_7c00)
-
-IVT_ENTRY(Reserved_7d00, 0x7d00)
- TRAP(65, cr.ifa)
-IVT_END(Reserved_7d00)
-
-IVT_ENTRY(Reserved_7e00, 0x7e00)
- TRAP(66, cr.ifa)
-IVT_END(Reserved_7e00)
-
-IVT_ENTRY(Reserved_7f00, 0x7f00)
- TRAP(67, cr.ifa)
-IVT_END(Reserved_7f00)
diff --git a/sys/ia64/ia64/locore.S b/sys/ia64/ia64/locore.S
deleted file mode 100644
index 338518d4c3e9..000000000000
--- a/sys/ia64/ia64/locore.S
+++ /dev/null
@@ -1,439 +0,0 @@
-/*-
- * Copyright (c) 1998 Doug Rabson
- * 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$
- */
-
-#include <machine/asm.h>
-#include <machine/ia64_cpu.h>
-#include <machine/fpu.h>
-#include <machine/pte.h>
-#include <sys/syscall.h>
-#include <assym.s>
-
-#ifndef EVCNT_COUNTERS
-#define _LOCORE
-#include <machine/intrcnt.h>
-#endif
-
- .section .data.proc0,"aw"
- .global kstack
- .align PAGE_SIZE
-kstack: .space KSTACK_PAGES * PAGE_SIZE
-
- .text
-
-/*
- * Not really a leaf but we can't return.
- * The EFI loader passes the physical address of the bootinfo block in
- * register r8.
- */
-ENTRY(__start, 1)
- .prologue
- .save rp,r0
- .body
-{ .mlx
- mov ar.rsc=0
- movl r16=ia64_vector_table // set up IVT early
- ;;
-}
-{ .mlx
- mov cr.iva=r16
- movl r16=kstack
- ;;
-}
-{ .mmi
- srlz.i
- ;;
- ssm IA64_PSR_DFH
- mov r17=KSTACK_PAGES*PAGE_SIZE-SIZEOF_PCB-SIZEOF_TRAPFRAME-16
- ;;
-}
-{ .mlx
- add sp=r16,r17 // proc0's stack
- movl gp=__gp // find kernel globals
- ;;
-}
-{ .mlx
- mov ar.bspstore=r16 // switch backing store
- movl r16=pa_bootinfo
- ;;
-}
- st8 [r16]=r8 // save the PA of the bootinfo block
- loadrs // invalidate regs
- ;;
- mov ar.rsc=3 // turn rse back on
- ;;
- alloc r16=ar.pfs,0,0,1,0
- ;;
- movl out0=0 // we are linked at the right address
- ;; // we just need to process fptrs
- br.call.sptk.many rp=_reloc
- ;;
- br.call.sptk.many rp=ia64_init
- ;;
- /* NOTREACHED */
-1: br.cond.sptk.few 1b
-END(__start)
-
-/*
- * fork_trampoline()
- *
- * Arrange for a function to be invoked neatly, after a cpu_switch().
- *
- * Invokes fork_exit() passing in three arguments: a callout function, an
- * argument to the callout, and a trapframe pointer. For child processes
- * returning from fork(2), the argument is a pointer to the child process.
- *
- * The callout function and its argument is in the trapframe in scratch
- * registers r2 and r3.
- */
-ENTRY(fork_trampoline, 0)
- .prologue
- .save rp,r0
- .body
-{ .mmi
- alloc r14=ar.pfs,0,0,3,0
- add r15=32+SIZEOF_SPECIAL+8,sp
- add r16=32+SIZEOF_SPECIAL+16,sp
- ;;
-}
-{ .mmi
- ld8 out0=[r15]
- ld8 out1=[r16]
- nop 0
-}
-{ .mfb
- add out2=16,sp
- nop 0
- br.call.sptk rp=fork_exit
- ;;
-}
- // If we get back here, it means we're a user space process that's
- // the immediate result of fork(2).
- .global enter_userland
- .type enter_userland, @function
-enter_userland:
-{ .mmi
- add r14=24,sp
- ;;
- ld8 r14=[r14]
- nop 0
- ;;
-}
-{ .mbb
- cmp.eq p6,p7=r0,r14
-(p6) br.sptk exception_restore
-(p7) br.sptk epc_syscall_return
- ;;
-}
-END(fork_trampoline)
-
-#ifdef SMP
-/*
- * AP wake-up entry point. The handoff state is similar as for the BSP,
- * as described on page 3-9 of the IPF SAL Specification. The difference
- * lies in the contents of register b0. For APs this register holds the
- * return address into the SAL rendezvous routine.
- *
- * Note that we're responsible for clearing the IRR bit by reading cr.ivr
- * and issuing the EOI to the local SAPIC.
- */
- .align 32
-ENTRY(os_boot_rendez,0)
- mov r16=cr.ivr // clear IRR bit
- ;;
- srlz.d
- mov cr.eoi=r0 // ACK the wake-up
- ;;
- srlz.d
- rsm IA64_PSR_IC|IA64_PSR_I
- ;;
- mov r16 = (5<<8)|(PAGE_SHIFT<<2)|1
- movl r17 = 5<<61
- ;;
- mov rr[r17] = r16
- ;;
- srlz.d
- mov r16 = (6<<8)|(28<<2)
- movl r17 = 6<<61
- ;;
- mov rr[r17] = r16
- ;;
- srlz.d
- mov r16 = (7<<8)|(28<<2)
- movl r17 = 7<<61
- ;;
- mov rr[r17] = r16
- ;;
- srlz.d
- mov r16 = (PTE_P|PTE_MA_WB|PTE_A|PTE_D|PTE_PL_KERN|PTE_AR_RWX)
- mov r18 = 28<<2
- ;;
-
- mov cr.ifa = r17
- mov cr.itir = r18
- ptr.d r17, r18
- ptr.i r17, r18
- ;;
- srlz.i
- ;;
- itr.d dtr[r0] = r16
- ;;
- itr.i itr[r0] = r16
- ;;
- srlz.i
- ;;
-1: mov r16 = ip
- add r17 = 2f-1b, r17
- movl r18 = (IA64_PSR_AC|IA64_PSR_BN|IA64_PSR_DFH|IA64_PSR_DT|IA64_PSR_IC|IA64_PSR_IT|IA64_PSR_RT)
- ;;
- add r17 = r17, r16
- mov cr.ipsr = r18
- mov cr.ifs = r0
- ;;
- mov cr.iip = r17
- ;;
- rfi
-
- .align 32
-2:
-{ .mlx
- mov ar.rsc = 0
- movl r16 = ia64_vector_table // set up IVT early
- ;;
-}
-{ .mlx
- mov cr.iva = r16
- movl r16 = ap_stack
- ;;
-}
-{ .mmi
- srlz.i
- ;;
- ld8 r16 = [r16]
- mov r18 = KSTACK_PAGES*PAGE_SIZE-SIZEOF_PCB-SIZEOF_TRAPFRAME-16
- ;;
-}
-{ .mlx
- mov ar.bspstore = r16
- movl gp = __gp
- ;;
-}
-{ .mmi
- loadrs
- ;;
- alloc r17 = ar.pfs, 0, 0, 0, 0
- add sp = r18, r16
- ;;
-}
-{ .mfb
- mov ar.rsc = 3
- nop 0
- br.call.sptk.few rp = ia64_ap_startup
- ;;
-}
- /* NOT REACHED */
-9:
-{ .mfb
- nop 0
- nop 0
- br.sptk 9b
- ;;
-}
-END(os_boot_rendez)
-
-#endif /* !SMP */
-
-/*
- * Create a default interrupt name table. The first entry (vector 0) is
- * hardwaired to the clock interrupt.
- */
- .data
- .align 8
-EXPORT(intrnames)
- .ascii "clock"
- .fill INTRNAME_LEN - 5 - 1, 1, ' '
- .byte 0
-intr_n = 0
-.rept INTRCNT_COUNT - 1
- .ascii "#"
- .byte intr_n / 100 + '0'
- .byte (intr_n % 100) / 10 + '0'
- .byte intr_n % 10 + '0'
- .fill INTRNAME_LEN - 1 - 3 - 1, 1, ' '
- .byte 0
- intr_n = intr_n + 1
-.endr
-EXPORT(eintrnames)
- .align 8
-EXPORT(intrcnt)
- .fill INTRCNT_COUNT, 8, 0
-EXPORT(eintrcnt)
-
- .text
- // in0: image base
-STATIC_ENTRY(_reloc, 1)
- alloc loc0=ar.pfs,1,2,0,0
- mov loc1=rp
- ;;
- movl r15=@gprel(_DYNAMIC) // find _DYNAMIC etc.
- movl r2=@gprel(fptr_storage)
- movl r3=@gprel(fptr_storage_end)
- ;;
- add r15=r15,gp // relocate _DYNAMIC etc.
- add r2=r2,gp
- add r3=r3,gp
- ;;
-1: ld8 r16=[r15],8 // read r15->d_tag
- ;;
- ld8 r17=[r15],8 // and r15->d_val
- ;;
- cmp.eq p6,p0=DT_NULL,r16 // done?
-(p6) br.cond.dpnt.few 2f
- ;;
- cmp.eq p6,p0=DT_RELA,r16
- ;;
-(p6) add r18=r17,in0 // found rela section
- ;;
- cmp.eq p6,p0=DT_RELASZ,r16
- ;;
-(p6) mov r19=r17 // found rela size
- ;;
- cmp.eq p6,p0=DT_SYMTAB,r16
- ;;
-(p6) add r20=r17,in0 // found symbol table
- ;;
-(p6) setf.sig f8=r20
- ;;
- cmp.eq p6,p0=DT_SYMENT,r16
- ;;
-(p6) setf.sig f9=r17 // found symbol entry size
- ;;
- cmp.eq p6,p0=DT_RELAENT,r16
- ;;
-(p6) mov r22=r17 // found rela entry size
- ;;
- br.sptk.few 1b
-
-2:
- ld8 r15=[r18],8 // read r_offset
- ;;
- ld8 r16=[r18],8 // read r_info
- add r15=r15,in0 // relocate r_offset
- ;;
- ld8 r17=[r18],8 // read r_addend
- sub r19=r19,r22 // update relasz
-
- extr.u r23=r16,0,32 // ELF64_R_TYPE(r16)
- ;;
- cmp.eq p6,p0=R_IA64_NONE,r23
-(p6) br.cond.dpnt.few 3f
- ;;
- cmp.eq p6,p0=R_IA64_REL64LSB,r23
-(p6) br.cond.dptk.few 4f
- ;;
-
- extr.u r16=r16,32,32 // ELF64_R_SYM(r16)
- ;;
- setf.sig f10=r16 // so we can multiply
- ;;
- xma.lu f10=f10,f9,f8 // f10=symtab + r_sym*syment
- ;;
- getf.sig r16=f10
- ;;
- add r16=8,r16 // address of st_value
- ;;
- ld8 r16=[r16] // read symbol value
- ;;
- add r16=r16,in0 // relocate symbol value
- ;;
-
- cmp.eq p6,p0=R_IA64_DIR64LSB,r23
-(p6) br.cond.dptk.few 5f
- ;;
- cmp.eq p6,p0=R_IA64_FPTR64LSB,r23
-(p6) br.cond.dptk.few 6f
- ;;
-
-3:
- cmp.ltu p6,p0=0,r19 // more?
-(p6) br.cond.dptk.few 2b // loop
- mov r8=0 // success return value
- br.cond.sptk.few 9f // done
-
-4:
- add r16=in0,r17 // BD + A
- ;;
- st8 [r15]=r16 // word64 (LSB)
- br.cond.sptk.few 3b
-
-5:
- add r16=r16,r17 // S + A
- ;;
- st8 [r15]=r16 // word64 (LSB)
- br.cond.sptk.few 3b
-
-6:
- movl r17=@gprel(fptr_storage)
- ;;
- add r17=r17,gp // start of fptrs
- ;;
-7: cmp.geu p6,p0=r17,r2 // end of fptrs?
-(p6) br.cond.dpnt.few 8f // can't find existing fptr
- ld8 r20=[r17] // read function from fptr
- ;;
- cmp.eq p6,p0=r16,r20 // same function?
- ;;
-(p6) st8 [r15]=r17 // reuse fptr
-(p6) br.cond.sptk.few 3b // done
- add r17=16,r17 // next fptr
- br.cond.sptk.few 7b
-
-8: // allocate new fptr
- mov r8=1 // failure return value
- cmp.geu p6,p0=r2,r3 // space left?
-(p6) br.cond.dpnt.few 9f // bail out
-
- st8 [r15]=r2 // install fptr
- st8 [r2]=r16,8 // write fptr address
- ;;
- st8 [r2]=gp,8 // write fptr gp
- br.cond.sptk.few 3b
-
-9:
- mov ar.pfs=loc0
- mov rp=loc1
- ;;
- br.ret.sptk.few rp
-
-END(_reloc)
-
- .data
- .align 16
- .global fptr_storage
-fptr_storage:
- .space 4096*16 // XXX
-fptr_storage_end:
diff --git a/sys/ia64/ia64/pal.S b/sys/ia64/ia64/pal.S
deleted file mode 100644
index eca57accf404..000000000000
--- a/sys/ia64/ia64/pal.S
+++ /dev/null
@@ -1,223 +0,0 @@
-/*-
- * Copyright (c) 2000-2001 Doug Rabson
- * 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$
- */
-
-#include <machine/asm.h>
-
- .data
- .global ia64_pal_entry
-ia64_pal_entry: .quad 0
- .text
-
-/*
- * struct ia64_pal_result ia64_call_pal_static(u_int64_t proc,
- * u_int64_t arg1, u_int64_t arg2, u_int64_t arg3)
- */
-ENTRY(ia64_call_pal_static, 4)
-
- .regstk 4,5,0,0
-palret = loc0
-entry = loc1
-rpsave = loc2
-pfssave = loc3
-psrsave = loc4
-
- alloc pfssave=ar.pfs,4,5,0,0
- ;;
- mov rpsave=rp
-
- movl entry=@gprel(ia64_pal_entry)
-1: mov palret=ip // for return address
- ;;
- add entry=entry,gp
- mov psrsave=psr
- mov r28=in0 // procedure number
- ;;
- ld8 entry=[entry] // read entry point
- mov r29=in1 // copy arguments
- mov r30=in2
- mov r31=in3
- ;;
- mov b6=entry
- add palret=2f-1b,palret // calculate return address
- ;;
- mov b0=palret
- rsm psr.i // disable interrupts
- ;;
- br.cond.sptk b6 // call into firmware
-2: mov psr.l=psrsave
- mov rp=rpsave
- mov ar.pfs=pfssave
- ;;
- srlz.d
- br.ret.sptk rp
-
-END(ia64_call_pal_static)
-
-#ifdef _KERNEL
-
-/*
- * struct ia64_pal_result ia64_call_pal_static_physical(u_int64_t proc,
- * u_int64_t arg1, u_int64_t arg2, u_int64_t arg3)
- */
-ENTRY(ia64_call_pal_static_physical, 4)
-
- .regstk 4,5,0,0
-palret = loc0
-entry = loc1
-rpsave = loc2
-pfssave = loc3
-psrsave = loc4
-
- alloc pfssave=ar.pfs,4,5,0,0
- ;;
- mov rpsave=rp
-
- movl entry=@gprel(ia64_pal_entry)
-1: mov palret=ip // for return address
- ;;
- add entry=entry,gp
- mov r28=in0 // procedure number
- ;;
- ld8 entry=[entry] // read entry point
- mov r29=in1 // copy arguments
- mov r30=in2
- mov r31=in3
- ;;
- dep entry=0,entry,61,3 // physical address
- dep palret=0,palret,61,3 // physical address
- br.call.sptk.many rp=ia64_physical_mode
- mov psrsave=ret0
- ;;
- mov b6=entry
- add palret=2f-1b,palret // calculate return address
- ;;
- mov b0=palret
- br.cond.sptk b6 // call into firmware
- ;;
-2: mov r14=psrsave
- ;;
- br.call.sptk.many rp=ia64_change_mode
- ;;
- mov rp=rpsave
- mov ar.pfs=pfssave
- ;;
- br.ret.sptk rp
-
-END(ia64_call_pal_static_physical)
-
-#endif
-
-/*
- * struct ia64_pal_result ia64_call_pal_stacked(u_int64_t proc,
- * u_int64_t arg1, u_int64_t arg2, u_int64_t arg3)
- */
-ENTRY(ia64_call_pal_stacked, 4)
-
- .regstk 4,4,4,0
-entry = loc0
-rpsave = loc1
-pfssave = loc2
-psrsave = loc3
-
- alloc pfssave=ar.pfs,4,4,4,0
- ;;
- mov rpsave=rp
- movl entry=@gprel(ia64_pal_entry)
- ;;
- add entry=entry,gp
- mov psrsave=psr
- mov r28=in0 // procedure number
- mov out0=in0
- ;;
- ld8 entry=[entry] // read entry point
- mov out1=in1 // copy arguments
- mov out2=in2
- mov out3=in3
- ;;
- mov b6=entry
- ;;
- rsm psr.i // disable interrupts
- ;;
- br.call.sptk.many rp=b6 // call into firmware
- mov psr.l=psrsave
- mov rp=rpsave
- mov ar.pfs=pfssave
- ;;
- srlz.d
- br.ret.sptk rp
-
-END(ia64_call_pal_stacked)
-
-#ifdef _KERNEL
-
-/*
- * struct ia64_pal_result ia64_call_pal_stacked_physical(u_int64_t proc,
- * u_int64_t arg1, u_int64_t arg2, u_int64_t arg3)
- */
-ENTRY(ia64_call_pal_stacked_physical, 4)
-
- .regstk 4,4,4,0
-entry = loc0
-rpsave = loc1
-pfssave = loc2
-psrsave = loc3
-
- alloc pfssave=ar.pfs,4,4,4,0
- ;;
- mov rpsave=rp
- movl entry=@gprel(ia64_pal_entry)
- ;;
- add entry=entry,gp
- mov r28=in0 // procedure number
- mov out0=in0
- ;;
- ld8 entry=[entry] // read entry point
- mov out1=in1 // copy arguments
- mov out2=in2
- mov out3=in3
- ;;
- dep entry=0,entry,61,3 // physical address
- br.call.sptk.many rp=ia64_physical_mode
- mov psrsave=ret0
- ;;
- mov b6=entry
- ;;
- br.call.sptk.many rp=b6 // call into firmware
- ;;
- mov r14=psrsave
- ;;
- br.call.sptk.many rp=ia64_change_mode
- ;;
- mov rp=rpsave
- mov ar.pfs=pfssave
- ;;
- br.ret.sptk rp
-
-END(ia64_call_pal_stacked_physical)
-
-#endif
diff --git a/sys/ia64/ia64/setjmp.S b/sys/ia64/ia64/setjmp.S
deleted file mode 100644
index dd927bfa252f..000000000000
--- a/sys/ia64/ia64/setjmp.S
+++ /dev/null
@@ -1,348 +0,0 @@
-// $FreeBSD$
-//
-// Copyright (c) 1999, 2000
-// Intel Corporation.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// 1. Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-//
-// 3. All advertising materials mentioning features or use of this software
-// must display the following acknowledgement:
-//
-// This product includes software developed by Intel Corporation and
-// its contributors.
-//
-// 4. Neither the name of Intel Corporation or its contributors may be
-// used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
-// THE POSSIBILITY OF SUCH DAMAGE.
-//
-//
-
-//
-// Module Name:
-//
-// setjmp.s
-//
-// Abstract:
-//
-// Contains an implementation of setjmp and longjmp for the
-// IA-64 architecture.
-
- .file "setjmp.s"
-
-#include <machine/asm.h>
-#include <machine/setjmp.h>
-
-// int setjmp(struct jmp_buffer *)
-//
-// Setup a non-local goto.
-//
-// Description:
-//
-// SetJump stores the current register set in the area pointed to
-// by "save". It returns zero. Subsequent calls to "LongJump" will
-// restore the registers and return non-zero to the same location.
-//
-// On entry, r32 contains the pointer to the jmp_buffer
-//
-
-ENTRY(setjmp, 1)
- //
- // Make sure buffer is aligned at 16byte boundary
- //
- add r10 = -0x10,r0 ;; // mask the lower 4 bits
- and r32 = r32, r10;;
- add r32 = 0x10, r32;; // move to next 16 byte boundary
-
- add r10 = J_PREDS, r32 // skip Unats & pfs save area
- add r11 = J_BSP, r32
- //
- // save immediate context
- //
- mov r2 = ar.bsp // save backing store pointer
- mov r3 = pr // save predicates
- flushrs
- ;;
- //
- // save user Unat register
- //
- mov r16 = ar.lc // save loop count register
- mov r14 = ar.unat // save user Unat register
-
- st8 [r10] = r3, J_LC-J_PREDS
- st8 [r11] = r2, J_R4-J_BSP
- ;;
- st8 [r10] = r16, J_R5-J_LC
- st8 [r32] = r14, J_NATS // Note: Unat at the
- // beginning of the save area
- mov r15 = ar.pfs
- ;;
- //
- // save preserved general registers & NaT's
- //
- st8.spill [r11] = r4, J_R6-J_R4
- ;;
- st8.spill [r10] = r5, J_R7-J_R5
- ;;
- st8.spill [r11] = r6, J_SP-J_R6
- ;;
- st8.spill [r10] = r7, J_F3-J_R7
- ;;
- st8.spill [r11] = sp, J_F2-J_SP
- ;;
- //
- // save spilled Unat and pfs registers
- //
- mov r2 = ar.unat // save Unat register after spill
- ;;
- st8 [r32] = r2, J_PFS-J_NATS // save unat for spilled regs
- ;;
- st8 [r32] = r15 // save pfs
- //
- // save floating registers
- //
- stf.spill [r11] = f2, J_F4-J_F2
- stf.spill [r10] = f3, J_F5-J_F3
- ;;
- stf.spill [r11] = f4, J_F16-J_F4
- stf.spill [r10] = f5, J_F17-J_F5
- ;;
- stf.spill [r11] = f16, J_F18-J_F16
- stf.spill [r10] = f17, J_F19-J_F17
- ;;
- stf.spill [r11] = f18, J_F20-J_F18
- stf.spill [r10] = f19, J_F21-J_F19
- ;;
- stf.spill [r11] = f20, J_F22-J_F20
- stf.spill [r10] = f21, J_F23-J_F21
- ;;
- stf.spill [r11] = f22, J_F24-J_F22
- stf.spill [r10] = f23, J_F25-J_F23
- ;;
- stf.spill [r11] = f24, J_F26-J_F24
- stf.spill [r10] = f25, J_F27-J_F25
- ;;
- stf.spill [r11] = f26, J_F28-J_F26
- stf.spill [r10] = f27, J_F29-J_F27
- ;;
- stf.spill [r11] = f28, J_F30-J_F28
- stf.spill [r10] = f29, J_F31-J_F29
- ;;
- stf.spill [r11] = f30, J_FPSR-J_F30
- stf.spill [r10] = f31, J_B0-J_F31 // size of f31 + fpsr
- //
- // save FPSR register & branch registers
- //
- mov r2 = ar.fpsr // save fpsr register
- mov r3 = b0
- ;;
- st8 [r11] = r2, J_B1-J_FPSR
- st8 [r10] = r3, J_B2-J_B0
- mov r2 = b1
- mov r3 = b2
- ;;
- st8 [r11] = r2, J_B3-J_B1
- st8 [r10] = r3, J_B4-J_B2
- mov r2 = b3
- mov r3 = b4
- ;;
- st8 [r11] = r2, J_B5-J_B3
- st8 [r10] = r3
- mov r2 = b5
- ;;
- st8 [r11] = r2
- ;;
- //
- // return
- //
- mov r8 = r0 // return 0 from setjmp
- mov ar.unat = r14 // restore unat
- br.ret.sptk b0
-
-END(setjmp)
-
-
-//
-// void longjmp(struct jmp_buffer *, int val)
-//
-// Perform a non-local goto.
-//
-// Description:
-//
-// LongJump initializes the register set to the values saved by a
-// previous 'SetJump' and jumps to the return location saved by that
-// 'SetJump'. This has the effect of unwinding the stack and returning
-// for a second time to the 'SetJump'.
-//
-
-ENTRY(longjmp, 2)
- //
- // Make sure buffer is aligned at 16byte boundary
- //
- add r10 = -0x10,r0 ;; // mask the lower 4 bits
- and r32 = r32, r10;;
- add r32 = 0x10, r32;; // move to next 16 byte boundary
-
- //
- // caching the return value as we do invala in the end
- //
- mov r8 = r33 // return value
-
- //
- // get immediate context
- //
- mov r14 = ar.rsc // get user RSC conf
- add r10 = J_PFS, r32 // get address of pfs
- add r11 = J_NATS, r32
- ;;
- ld8 r15 = [r10], J_BSP-J_PFS // get pfs
- ld8 r2 = [r11], J_LC-J_NATS // get unat for spilled regs
- ;;
- mov ar.unat = r2
- ;;
- ld8 r16 = [r10], J_PREDS-J_BSP // get backing store pointer
- mov ar.rsc = r0 // put RSE in enforced lazy
- mov ar.pfs = r15
- ;;
-
- //
- // while returning from longjmp the BSPSTORE and BSP needs to be
- // same and discard all the registers allocated after we did
- // setjmp. Also, we need to generate the RNAT register since we
- // did not flushed the RSE on setjmp.
- //
- mov r17 = ar.bspstore // get current BSPSTORE
- ;;
- cmp.ltu p6,p7 = r17, r16 // is it less than BSP of
-(p6) br.spnt.few .flush_rse
- mov r19 = ar.rnat // get current RNAT
- ;;
- loadrs // invalidate dirty regs
- br.sptk.many .restore_rnat // restore RNAT
-
-.flush_rse:
- flushrs
- ;;
- mov r19 = ar.rnat // get current RNAT
- mov r17 = r16 // current BSPSTORE
- ;;
-.restore_rnat:
- //
- // check if RNAT is saved between saved BSP and curr BSPSTORE
- //
- mov r18 = 0x3f
- ;;
- dep r18 = r18,r16,3,6 // get RNAT address
- ;;
- cmp.ltu p8,p9 = r18, r17 // RNAT saved on RSE
- ;;
-(p8) ld8 r19 = [r18] // get RNAT from RSE
- ;;
- mov ar.bspstore = r16 // set new BSPSTORE
- ;;
- mov ar.rnat = r19 // restore RNAT
- mov ar.rsc = r14 // restore RSC conf
-
-
- ld8 r3 = [r11], J_R4-J_LC // get lc register
- ld8 r2 = [r10], J_R5-J_PREDS // get predicates
- ;;
- mov pr = r2, -1
- mov ar.lc = r3
- //
- // restore preserved general registers & NaT's
- //
- ld8.fill r4 = [r11], J_R6-J_R4
- ;;
- ld8.fill r5 = [r10], J_R7-J_R5
- ld8.fill r6 = [r11], J_SP-J_R6
- ;;
- ld8.fill r7 = [r10], J_F2-J_R7
- ld8.fill sp = [r11], J_F3-J_SP
- ;;
- //
- // restore floating registers
- //
- ldf.fill f2 = [r10], J_F4-J_F2
- ldf.fill f3 = [r11], J_F5-J_F3
- ;;
- ldf.fill f4 = [r10], J_F16-J_F4
- ldf.fill f5 = [r11], J_F17-J_F5
- ;;
- ldf.fill f16 = [r10], J_F18-J_F16
- ldf.fill f17 = [r11], J_F19-J_F17
- ;;
- ldf.fill f18 = [r10], J_F20-J_F18
- ldf.fill f19 = [r11], J_F21-J_F19
- ;;
- ldf.fill f20 = [r10], J_F22-J_F20
- ldf.fill f21 = [r11], J_F23-J_F21
- ;;
- ldf.fill f22 = [r10], J_F24-J_F22
- ldf.fill f23 = [r11], J_F25-J_F23
- ;;
- ldf.fill f24 = [r10], J_F26-J_F24
- ldf.fill f25 = [r11], J_F27-J_F25
- ;;
- ldf.fill f26 = [r10], J_F28-J_F26
- ldf.fill f27 = [r11], J_F29-J_F27
- ;;
- ldf.fill f28 = [r10], J_F30-J_F28
- ldf.fill f29 = [r11], J_F31-J_F29
- ;;
- ldf.fill f30 = [r10], J_FPSR-J_F30
- ldf.fill f31 = [r11], J_B0-J_F31 ;;
-
- //
- // restore branch registers and fpsr
- //
- ld8 r16 = [r10], J_B1-J_FPSR // get fpsr
- ld8 r17 = [r11], J_B2-J_B0 // get return pointer
- ;;
- mov ar.fpsr = r16
- mov b0 = r17
- ld8 r2 = [r10], J_B3-J_B1
- ld8 r3 = [r11], J_B4-J_B2
- ;;
- mov b1 = r2
- mov b2 = r3
- ld8 r2 = [r10], J_B5-J_B3
- ld8 r3 = [r11]
- ;;
- mov b3 = r2
- mov b4 = r3
- ld8 r2 = [r10]
- ld8 r21 = [r32] // get user unat
- ;;
- mov b5 = r2
- mov ar.unat = r21
-
- //
- // invalidate ALAT
- //
- invala ;;
-
- br.ret.sptk b0
-
-END(longjmp)
diff --git a/sys/ia64/ia64/support.S b/sys/ia64/ia64/support.S
deleted file mode 100644
index 252ab23b2b5b..000000000000
--- a/sys/ia64/ia64/support.S
+++ /dev/null
@@ -1,901 +0,0 @@
-/*-
- * Copyright (c) 1998 Doug Rabson
- * 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$
- */
-/*
- * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-#include <machine/asm.h>
-#include <machine/ia64_cpu.h>
-#include <assym.s>
-
- .text
-
-/*
- * ia64_change_mode: change mode to/from physical mode
- *
- * Arguments:
- * r14 psr for desired mode
- *
- * Modifies:
- * r15-r19 scratch
- * ar.bsp tranlated to new mode
- */
-ENTRY(ia64_change_mode, 0)
- rsm psr.i | psr.ic
- mov r19=ar.rsc // save rsc while we change mode
- tbit.nz p6,p7=r14,17 // physical or virtual ?
- ;;
- mov ar.rsc=0 // turn off RSE
-(p6) mov r15=7 // RR base for virtual addresses
-(p7) mov r15=0 // RR base for physical addresses
- flushrs // no dirty registers please
- srlz.i
- ;;
- mov r16=ar.bsp
- mov r17=rp
- mov r18=ar.rnat
- ;;
- dep r16=r15,r16,61,3 // new address of ar.bsp
- dep r17=r15,r17,61,3 // new address of rp
- dep sp=r15,sp,61,3 // new address of sp
- ;;
- mov ar.bspstore=r16
- mov rp=r17
- ;;
-1: mov r16=ip
- mov ar.rnat=r18
- mov cr.ipsr=r14 // psr for new mode
- ;;
- add r16=2f-1b,r16 // address to rfi to
- ;;
- dep r16=r15,r16,61,3 // new mode address for rfi
- ;;
- mov cr.iip=r16 // setup for rfi
- mov cr.ifs=r0
- ;;
- rfi
-
-2: mov ar.rsc=r19 // restore ar.rsc
- br.ret.sptk.few rp // now in new mode
-END(ia64_change_mode)
-
-/*
- * ia64_physical_mode: change mode to physical mode
- *
- * Return:
- * ret0 psr to restore
- *
- * Modifies:
- * r15-r18 scratch
- * ar.bsp tranlated to physical mode
- * psr.i cleared
- */
-ENTRY(ia64_physical_mode, 0)
- mov r14=psr
- mov ret0=psr
- movl r15=(IA64_PSR_I|IA64_PSR_IT|IA64_PSR_DT|IA64_PSR_RT|IA64_PSR_DFL|IA64_PSR_DFH)
- movl r16=IA64_PSR_BN
- ;;
- andcm r14=r14,r15 // clear various xT bits
- ;;
- or r14=r14,r16 // make sure BN=1
- or ret0=ret0,r16 // make sure BN=1
-
- br.cond.sptk.many ia64_change_mode
-END(ia64_physical_mode)
-
-/*
- * ia64_call_efi_physical: call an EFI procedure in physical mode
- *
- * Arguments:
- * in0 Address of EFI procedure descriptor
- * in1-in5 Arguments to EFI procedure
- *
- * Return:
- * ret0-ret3 return values from EFI
- *
- */
-ENTRY(ia64_call_efi_physical, 6)
- .prologue
- .regstk 6,4,5,0
- .save ar.pfs,loc0
- alloc loc0=ar.pfs,6,4,5,0
- ;;
- .save rp,loc1
- mov loc1=rp
- ;;
- .body
- br.call.sptk.many rp=ia64_physical_mode
- ;;
- mov loc2=r8 // psr to restore mode
- mov loc3=gp // save kernel gp
- ld8 r14=[in0],8 // function address
- ;;
- mov out0=in1
- mov out1=in2
- mov out2=in3
- mov out3=in4
- mov out4=in5
- ld8 gp=[in0] // function gp value
- ;;
- mov b6=r14
- ;;
- br.call.sptk.many rp=b6 // call EFI procedure
- mov gp=loc3 // restore kernel gp
- ;;
- mov r14=loc2 // psr to restore mode
- br.call.sptk.many rp=ia64_change_mode
- ;;
- mov rp=loc1
- mov ar.pfs=loc0
- ;;
- br.ret.sptk.many rp
-END(ia64_call_efi_physical)
-
-/**************************************************************************/
-
-ENTRY(fusufault, 0)
-{ .mib
- st8.rel [r15]=r0 // Clear onfault.
- add ret0=-1,r0
- br.ret.sptk rp
- ;;
-}
-END(fusufault)
-
-/*
- * casuptr(intptr_t *p, intptr_t old, intptr_t new)
- * Perform a compare-exchange in user space.
- */
-ENTRY(casuptr, 3)
-{ .mlx
- add r15=PC_CURTHREAD,r13
- movl r14=VM_MAX_ADDRESS
- ;;
-}
-{ .mib
- ld8 r15=[r15] // r15 = curthread
- cmp.geu p6,p0=in0,r14
-(p6) br.dpnt.few 1f
- ;;
-}
-{ .mlx
- add r15=TD_PCB,r15
- movl r14=fusufault
- ;;
-}
-{ .mmi
- ld8 r15=[r15] // r15 = PCB
- ;;
- mov ar.ccv=in1
- add r15=PCB_ONFAULT,r15
- ;;
-}
-{ .mmi
- st8 [r15]=r14 // Set onfault
- ;;
- cmpxchg8.rel ret0=[in0],in2,ar.ccv
- nop 0
- ;;
-}
-{ .mfb
- st8.rel [r15]=r0 // Clear onfault
- nop 0
- br.ret.sptk rp
- ;;
-}
-1:
-{ .mfb
- add ret0=-1,r0
- nop 0
- br.ret.sptk rp
- ;;
-}
-END(casuptr)
-
-/*
- * subyte(void *addr, int byte)
- * suword16(void *addr, int word)
- * suword32(void *addr, int word)
- * suword64|suword(void *addr, long word)
- * Store in user space
- */
-
-ENTRY(subyte, 2)
-{ .mlx
- add r15=PC_CURTHREAD,r13
- movl r14=VM_MAX_ADDRESS
- ;;
-}
-{ .mib
- ld8 r15=[r15] // r15 = curthread
- cmp.geu p6,p0=in0,r14
-(p6) br.dpnt.few 1f
- ;;
-}
-{ .mlx
- add r15=TD_PCB,r15
- movl r14=fusufault
- ;;
-}
-{ .mmi
- ld8 r15=[r15] // r15 = PCB
- ;;
- nop 0
- add r15=PCB_ONFAULT,r15
- ;;
-}
-{ .mmi
- st8 [r15]=r14 // Set onfault
- ;;
- st1.rel [in0]=in1
- nop 0
- ;;
-}
-{ .mib
- st8.rel [r15]=r0 // Clear onfault
- mov ret0=r0
- br.ret.sptk rp
- ;;
-}
-1:
-{ .mfb
- add ret0=-1,r0
- nop 0
- br.ret.sptk rp
- ;;
-}
-END(subyte)
-
-ENTRY(suword16, 2)
-{ .mlx
- add r15=PC_CURTHREAD,r13
- movl r14=VM_MAX_ADDRESS
- ;;
-}
-{ .mib
- ld8 r15=[r15] // r15 = curthread
- cmp.geu p6,p0=in0,r14
-(p6) br.dpnt.few 1f
- ;;
-}
-{ .mlx
- add r15=TD_PCB,r15
- movl r14=fusufault
- ;;
-}
-{ .mmi
- ld8 r15=[r15] // r15 = PCB
- ;;
- nop 0
- add r15=PCB_ONFAULT,r15
- ;;
-}
-{ .mmi
- st8 [r15]=r14 // Set onfault
- ;;
- st2.rel [in0]=in1
- nop 0
- ;;
-}
-{ .mib
- st8.rel [r15]=r0 // Clear onfault
- mov ret0=r0
- br.ret.sptk rp
- ;;
-}
-1:
-{ .mfb
- add ret0=-1,r0
- nop 0
- br.ret.sptk rp
- ;;
-}
-END(suword16)
-
-ENTRY(suword32, 2)
-{ .mlx
- add r15=PC_CURTHREAD,r13
- movl r14=VM_MAX_ADDRESS
- ;;
-}
-{ .mib
- ld8 r15=[r15] // r15 = curthread
- cmp.geu p6,p0=in0,r14
-(p6) br.dpnt.few 1f
- ;;
-}
-{ .mlx
- add r15=TD_PCB,r15
- movl r14=fusufault
- ;;
-}
-{ .mmi
- ld8 r15=[r15] // r15 = PCB
- ;;
- nop 0
- add r15=PCB_ONFAULT,r15
- ;;
-}
-{ .mmi
- st8 [r15]=r14 // Set onfault
- ;;
- st4.rel [in0]=in1
- nop 0
- ;;
-}
-{ .mib
- st8.rel [r15]=r0 // Clear onfault
- mov ret0=r0
- br.ret.sptk rp
- ;;
-}
-1:
-{ .mfb
- add ret0=-1,r0
- nop 0
- br.ret.sptk rp
- ;;
-}
-END(suword32)
-
-ENTRY(suword64, 2)
-XENTRY(suword)
-{ .mlx
- add r15=PC_CURTHREAD,r13
- movl r14=VM_MAX_ADDRESS
- ;;
-}
-{ .mib
- ld8 r15=[r15] // r15 = curthread
- cmp.geu p6,p0=in0,r14
-(p6) br.dpnt.few 1f
- ;;
-}
-{ .mlx
- add r15=TD_PCB,r15
- movl r14=fusufault
- ;;
-}
-{ .mmi
- ld8 r15=[r15] // r15 = PCB
- ;;
- nop 0
- add r15=PCB_ONFAULT,r15
- ;;
-}
-{ .mmi
- st8 [r15]=r14 // Set onfault
- ;;
- st8.rel [in0]=in1
- nop 0
- ;;
-}
-{ .mib
- st8.rel [r15]=r0 // Clear onfault
- mov ret0=r0
- br.ret.sptk rp
- ;;
-}
-1:
-{ .mfb
- add ret0=-1,r0
- nop 0
- br.ret.sptk rp
- ;;
-}
-END(suword64)
-
-/*
- * fubyte(void *addr, int byte)
- * fuword16(void *addr, int word)
- * fuword32(void *addr, int word)
- * fuword64|fuword(void *addr, long word)
- * Fetch from user space
- */
-
-ENTRY(fubyte, 1)
-{ .mlx
- add r15=PC_CURTHREAD,r13
- movl r14=VM_MAX_ADDRESS
- ;;
-}
-{ .mib
- ld8 r15=[r15] // r15 = curthread
- cmp.geu p6,p0=in0,r14
-(p6) br.dpnt.few 1f
- ;;
-}
-{ .mlx
- add r15=TD_PCB,r15
- movl r14=fusufault
- ;;
-}
-{ .mmi
- ld8 r15=[r15] // r15 = PCB
- ;;
- nop 0
- add r15=PCB_ONFAULT,r15
- ;;
-}
-{ .mmi
- st8 [r15]=r14 // Set onfault
- ;;
- mf
- nop 0
- ;;
-}
-{ .mmb
- ld1 ret0=[in0]
- st8.rel [r15]=r0 // Clear onfault
- br.ret.sptk rp
- ;;
-}
-1:
-{ .mfb
- add ret0=-1,r0
- nop 0
- br.ret.sptk rp
- ;;
-}
-END(fubyte)
-
-ENTRY(fuword16, 2)
-{ .mlx
- add r15=PC_CURTHREAD,r13
- movl r14=VM_MAX_ADDRESS
- ;;
-}
-{ .mib
- ld8 r15=[r15] // r15 = curthread
- cmp.geu p6,p0=in0,r14
-(p6) br.dpnt.few 1f
- ;;
-}
-{ .mlx
- add r15=TD_PCB,r15
- movl r14=fusufault
- ;;
-}
-{ .mmi
- ld8 r15=[r15] // r15 = PCB
- ;;
- nop 0
- add r15=PCB_ONFAULT,r15
- ;;
-}
-{ .mmi
- st8 [r15]=r14 // Set onfault
- ;;
- mf
- nop 0
- ;;
-}
-{ .mmb
- ld2 ret0=[in0]
- st8.rel [r15]=r0 // Clear onfault
- br.ret.sptk rp
- ;;
-}
-1:
-{ .mfb
- add ret0=-1,r0
- nop 0
- br.ret.sptk rp
- ;;
-}
-END(fuword16)
-
-ENTRY(fuword32, 2)
-{ .mlx
- add r15=PC_CURTHREAD,r13
- movl r14=VM_MAX_ADDRESS
- ;;
-}
-{ .mib
- ld8 r15=[r15] // r15 = curthread
- cmp.geu p6,p0=in0,r14
-(p6) br.dpnt.few 1f
- ;;
-}
-{ .mlx
- add r15=TD_PCB,r15
- movl r14=fusufault
- ;;
-}
-{ .mmi
- ld8 r15=[r15] // r15 = PCB
- ;;
- nop 0
- add r15=PCB_ONFAULT,r15
- ;;
-}
-{ .mmi
- st8 [r15]=r14 // Set onfault
- ;;
- mf
- nop 0
- ;;
-}
-{ .mmb
- ld4 ret0=[in0]
- st8.rel [r15]=r0 // Clear onfault
- br.ret.sptk rp
- ;;
-}
-1:
-{ .mfb
- add ret0=-1,r0
- nop 0
- br.ret.sptk rp
- ;;
-}
-END(fuword32)
-
-ENTRY(fuword64, 2)
-XENTRY(fuword)
-{ .mlx
- add r15=PC_CURTHREAD,r13
- movl r14=VM_MAX_ADDRESS
- ;;
-}
-{ .mib
- ld8 r15=[r15] // r15 = curthread
- cmp.geu p6,p0=in0,r14
-(p6) br.dpnt.few 1f
- ;;
-}
-{ .mlx
- add r15=TD_PCB,r15
- movl r14=fusufault
- ;;
-}
-{ .mmi
- ld8 r15=[r15] // r15 = PCB
- ;;
- nop 0
- add r15=PCB_ONFAULT,r15
- ;;
-}
-{ .mmi
- st8 [r15]=r14 // Set onfault
- ;;
- mf
- nop 0
- ;;
-}
-{ .mmb
- ld8 ret0=[in0]
- st8.rel [r15]=r0 // Clear onfault
- br.ret.sptk rp
- ;;
-}
-1:
-{ .mfb
- add ret0=-1,r0
- nop 0
- br.ret.sptk rp
- ;;
-}
-END(fuword64)
-
-/*
- * fuswintr(void *addr)
- * suswintr(void *addr)
- */
-
-ENTRY(fswintrberr, 0)
-{ .mfb
- add ret0=-1,r0
- nop 0
- br.ret.sptk rp
- ;;
-}
-END(fswintrberr)
-
-ENTRY(fuswintr, 1)
-{ .mfb
- add ret0=-1,r0
- nop 0
- br.ret.sptk rp
- ;;
-}
-END(fuswintr)
-
-ENTRY(suswintr, 0)
-{ .mfb
- add ret0=-1,r0
- nop 0
- br.ret.sptk rp
- ;;
-}
-END(suswintr)
-
-/**************************************************************************/
-
-/*
- * Copy a null-terminated string within the kernel's address space.
- * If lenp is not NULL, store the number of chars copied in *lenp
- *
- * int copystr(char *from, char *to, size_t len, size_t *lenp);
- */
-ENTRY(copystr, 4)
- mov r14=in2 // r14 = i = len
- cmp.eq p6,p0=r0,in2
-(p6) br.cond.spnt.few 2f // if (len == 0), bail out
-
-1: ld1 r15=[in0],1 // read one byte
- ;;
- st1 [in1]=r15,1 // write that byte
- add in2=-1,in2 // len--
- ;;
- cmp.eq p6,p0=r0,r15
- cmp.ne p7,p0=r0,in2
- ;;
-(p6) br.cond.spnt.few 2f // if (*from == 0), bail out
-(p7) br.cond.sptk.few 1b // if (len != 0) copy more
-
-2: cmp.eq p6,p0=r0,in3
-(p6) br.cond.dpnt.few 3f // if (lenp != NULL)
- sub r14=r14,in2 // *lenp = (i - len)
- ;;
- st8 [in3]=r14
-
-3: cmp.eq p6,p0=r0,r15
-(p6) br.cond.spnt.few 4f // *from == '\0'; leave quietly
-
- mov ret0=ENAMETOOLONG // *from != '\0'; error.
- br.ret.sptk.few rp
-
-4: mov ret0=0 // return 0.
- br.ret.sptk.few rp
-END(copystr)
-
-ENTRY(copyinstr, 4)
- .prologue
- .regstk 4, 3, 4, 0
- .save ar.pfs,loc0
- alloc loc0=ar.pfs,4,3,4,0
- .save rp,loc1
- mov loc1=rp
- .body
-
- movl loc2=VM_MAX_ADDRESS // make sure that src addr
- ;;
- cmp.geu p6,p0=in0,loc2 // is in user space.
- ;;
-(p6) br.cond.spnt.few copyerr // if it's not, error out.
- movl r14=copyerr // set up fault handler.
- add r15=PC_CURTHREAD,r13 // find curthread
- ;;
- ld8 r15=[r15]
- ;;
- add r15=TD_PCB,r15 // find pcb
- ;;
- ld8 r15=[r15]
- ;;
- add loc2=PCB_ONFAULT,r15
- ;;
- st8 [loc2]=r14
- ;;
- mov out0=in0
- mov out1=in1
- mov out2=in2
- mov out3=in3
- ;;
- br.call.sptk.few rp=copystr // do the copy.
- st8 [loc2]=r0 // kill the fault handler.
- mov ar.pfs=loc0 // restore ar.pfs
- mov rp=loc1 // restore ra.
- br.ret.sptk.few rp // ret0 left over from copystr
-END(copyinstr)
-
-/*
- * Not the fastest bcopy in the world.
- */
-ENTRY(bcopy, 3)
- mov ret0=r0 // return zero for copy{in,out}
- ;;
- cmp.le p6,p0=in2,r0 // bail if len <= 0
-(p6) br.ret.spnt.few rp
-
- sub r14=in1,in0 ;; // check for overlap
- cmp.ltu p6,p0=r14,in2 // dst-src < len
-(p6) br.cond.spnt.few 5f
-
- extr.u r14=in0,0,3 // src & 7
- extr.u r15=in1,0,3 ;; // dst & 7
- cmp.eq p6,p0=r14,r15 // different alignment?
-(p6) br.cond.spnt.few 2f // branch if same alignment
-
-1: ld1 r14=[in0],1 ;; // copy bytewise
- st1 [in1]=r14,1
- add in2=-1,in2 ;; // len--
- cmp.ne p6,p0=r0,in2
-(p6) br.cond.dptk.few 1b // loop
- br.ret.sptk.few rp // done
-
-2: cmp.eq p6,p0=r14,r0 // aligned?
-(p6) br.cond.sptk.few 4f
-
-3: ld1 r14=[in0],1 ;; // copy bytewise
- st1 [in1]=r14,1
- extr.u r15=in0,0,3 // src & 7
- add in2=-1,in2 ;; // len--
- cmp.eq p6,p0=r0,in2 // done?
- cmp.eq p7,p0=r0,r15 ;; // aligned now?
-(p6) br.ret.spnt.few rp // return if done
-(p7) br.cond.spnt.few 4f // go to main copy
- br.cond.sptk.few 3b // more bytes to copy
-
- // At this point, in2 is non-zero
-
-4: mov r14=8 ;;
- cmp.ltu p6,p0=in2,r14 ;; // len < 8?
-(p6) br.cond.spnt.few 1b // byte copy the end
- ld8 r15=[in0],8 ;; // copy word
- st8 [in1]=r15,8
- add in2=-8,in2 ;; // len -= 8
- cmp.ne p6,p0=r0,in2 // done?
-(p6) br.cond.spnt.few 4b // again
-
- br.ret.sptk.few rp // return
-
- // Don't bother optimising overlap case
-
-5: add in0=in0,in2
- add in1=in1,in2 ;;
- add in0=-1,in0
- add in1=-1,in1 ;;
-
-6: ld1 r14=[in0],-1 ;;
- st1 [in1]=r14,-1
- add in2=-1,in2 ;;
- cmp.ne p6,p0=r0,in2
-(p6) br.cond.spnt.few 6b
-
- br.ret.sptk.few rp
-END(bcopy)
-
-ENTRY(memcpy,3)
- mov r14=in0 ;;
- mov in0=in1 ;;
- mov in1=r14
- br.cond.sptk.few bcopy
-END(memcpy)
-
-ENTRY(copyin, 3)
- .prologue
- .regstk 3, 3, 3, 0
- .save ar.pfs,loc0
- alloc loc0=ar.pfs,3,3,3,0
- .save rp,loc1
- mov loc1=rp
- .body
-
- movl loc2=VM_MAX_ADDRESS // make sure that src addr
- ;;
- cmp.geu p6,p0=in0,loc2 // is in user space.
- ;;
-(p6) br.cond.spnt.few copyerr // if it's not, error out.
- movl r14=copyerr // set up fault handler.
- add r15=PC_CURTHREAD,r13 // find curthread
- ;;
- ld8 r15=[r15]
- ;;
- add r15=TD_PCB,r15 // find pcb
- ;;
- ld8 r15=[r15]
- ;;
- add loc2=PCB_ONFAULT,r15
- ;;
- st8 [loc2]=r14
- ;;
- mov out0=in0
- mov out1=in1
- mov out2=in2
- ;;
- br.call.sptk.few rp=bcopy // do the copy.
- st8 [loc2]=r0 // kill the fault handler.
- mov ar.pfs=loc0 // restore ar.pfs
- mov rp=loc1 // restore ra.
- br.ret.sptk.few rp // ret0 left over from bcopy
-END(copyin)
-
-ENTRY(copyout, 3)
- .prologue
- .regstk 3, 3, 3, 0
- .save ar.pfs,loc0
- alloc loc0=ar.pfs,3,3,3,0
- .save rp,loc1
- mov loc1=rp
- .body
-
- movl loc2=VM_MAX_ADDRESS // make sure that dest addr
- ;;
- cmp.geu p6,p0=in1,loc2 // is in user space.
- ;;
-(p6) br.cond.spnt.few copyerr // if it's not, error out.
- movl r14=copyerr // set up fault handler.
- add r15=PC_CURTHREAD,r13 // find curthread
- ;;
- ld8 r15=[r15]
- ;;
- add r15=TD_PCB,r15 // find pcb
- ;;
- ld8 r15=[r15]
- ;;
- add loc2=PCB_ONFAULT,r15
- ;;
- st8 [loc2]=r14
- ;;
- mov out0=in0
- mov out1=in1
- mov out2=in2
- ;;
- br.call.sptk.few rp=bcopy // do the copy.
- st8 [loc2]=r0 // kill the fault handler.
- mov ar.pfs=loc0 // restore ar.pfs
- mov rp=loc1 // restore ra.
- br.ret.sptk.few rp // ret0 left over from bcopy
-END(copyout)
-
-ENTRY(copyerr, 0)
- add r14=PC_CURTHREAD,r13 ;; // find curthread
- ld8 r14=[r14] ;;
- add r14=TD_PCB,r14 ;; // curthread->td_addr
- ld8 r14=[r14] ;;
- add r14=PCB_ONFAULT,r14 ;; // &curthread->td_pcb->pcb_onfault
- st8 [r14]=r0 // reset fault handler
-
- mov ret0=EFAULT // return EFAULT
- br.ret.sptk.few rp
-END(copyerr)
diff --git a/sys/ia64/ia64/syscall.S b/sys/ia64/ia64/syscall.S
deleted file mode 100644
index 5aacd79e5bb6..000000000000
--- a/sys/ia64/ia64/syscall.S
+++ /dev/null
@@ -1,562 +0,0 @@
-/*
- * Copyright (c) 2002, 2003 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.
- * 2. Redistributions in binary form must 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.
- *
- * $FreeBSD$
- */
-
-#include <sys/syscall.h>
-#include <machine/asm.h>
-#include <assym.s>
-
-/*
- * A process performs a syscall by performing an indirect call to the
- * address stored in ar.k5. The contents of ar.pfs and rp should be
- * saved prior to the syscall in r9 and r10 respectively. The kernel
- * will restore these values on return. The value of gp is preserved
- * across the call. This allows for small enough syscall stubs without
- * getting too weird.
- * The address in ar.k5 is the start of the EPC gateway page and also
- * the syscall entry point. The syscall code in the gateway page is
- * primarily responsible for increasing the privilege level, but will
- * also make sure we have a reliable psr.
- *
- * A process defines:
- * r8 - syscall number
- * r9 - copy of ar.pfs
- * r10 - copy of rp
- * in0-in7 - syscall arguments
- *
- * A syscall returns:
- * r8+r9 - syscall return value(s)
- * r10 - syscall error flag
- * ar.pfs - restored from r9
- * rp - restored from r10
- * gp - preserved
- *
- * The EPC syscall code defines:
- * r11 - copy of psr.l
- * r14 - Kernel memory stack
- * r15 - Kernel register stack
- *
- * Also in the gateway page are the signal trampolines. As such, stacks
- * don't have to be made executable per se. Since debuggers have a need
- * to know about trampolines, we probably need to define a table of
- * vectors or something along those lines so that debuggers can get the
- * information they need and we have the freedom to move code around.
- */
-
- .section .text.gateway, "ax"
- .align PAGE_SIZE
- .global ia64_gateway_page
-ia64_gateway_page:
-{ .mmb
- mov r14=ar.k7 // Memory stack
- mov r15=ar.k6 // Register stack
- epc
- ;;
-}
-{ .mlx
- mov r11=psr
- movl r31=epc_syscall
- ;;
-}
-{ .mib
- rum psr.be
- mov b7=r31
- br b7
- ;;
-}
-gw_ret:
-{ .mmi
- mov ar.rnat=r22
- mov ar.rsc=r24
- mov ar.pfs=r28
-}
-{ .mib
- mov ar.fpsr=r25
- mov b0=r29
- br.sptk b6
- ;;
-}
-gw_ret_ia32:
- mov ar.rnat=r0
- mov ar.rsc=0xc
- mov ar.pfs=r0
- ;;
- br.ia.sptk b6
- ;;
-
-ENTRY(break_sigtramp, 0)
-{ .mib
- mov ar.rsc=0
- cmp.ne p15,p0=0,gp
- cover
- ;;
-}
-{ .mmi
- flushrs
-(p15) invala
- add r16=16+UC_MCONTEXT+MC_SPECIAL,sp
- ;;
-}
-{ .mmi
- mov r17=ar.bsp
- mov r18=ar.rnat
- add r14=40,r16
- ;;
-}
-{ .mmi
- st8 [r14]=r17,64 // bspstore
-(p15) mov ar.bspstore=gp
- add r15=48,r16
- ;;
-}
-{ .mmi
- st8 [r15]=r18 // rnat
- st8 [r14]=r0 // ndirty
- nop 0
- ;;
-}
-{ .mmi
- alloc r14=ar.pfs, 0, 0, 3, 0
- mov ar.rsc=15
- mov out0=r8
- ;;
-}
-{ .mmi
- ld8 r16=[r10],8 // function address
- ;;
- ld8 gp=[r10] // function's gp value
- mov b7=r16
- ;;
-}
-{ .mib
- mov out1=r9
- add out2=16,sp
- br.call.sptk rp=b7
- ;;
-}
-{ .mmi
- mov r15=SYS_sigreturn
- add out0=16,sp
- break 0x100000
- ;;
-}
-{ .mmi
- mov r15=SYS_exit
- mov out0=ret0
- break 0x100000
- ;;
-}
-END(break_sigtramp)
-
-ENTRY(epc_sigtramp, 0)
-{ .mib
- mov ar.rsc=0
- cmp.ne p15,p0=0,gp
- cover
- ;;
-}
-{ .mmi
- flushrs
-(p15) invala
- add r16=16+UC_MCONTEXT+MC_SPECIAL,sp
- ;;
-}
-{ .mmi
- mov r17=ar.bsp
- mov r18=ar.rnat
- add r14=32,r16
- ;;
-}
-{ .mmi
-(p15) mov ar.bspstore=gp
- ld8 r19=[r14],8
- add r15=48,r16
- ;;
-}
-{ .mmi
- st8 [r14]=r17,64 // bspstore
- st8 [r15]=r18,-16 // rnat
- dep r19=r19,r19,7,7
- ;;
-}
-{ .mmi
- st8 [r14]=r0 // ndirty
- st8 [r15]=r19 // pfs
- nop 0
- ;;
-}
-{ .mmi
- alloc r14=ar.pfs, 0, 0, 3, 0
- mov ar.rsc=15
- mov out0=r8
- ;;
-}
-{ .mmi
- ld8 r16=[r10],8 // function address
- ;;
- ld8 gp=[r10] // function's gp value
- mov b7=r16
- ;;
-}
-{ .mib
- mov out1=r9
- add out2=16,sp
- br.call.sptk rp=b7
- ;;
-}
- add out0=16,sp
- CALLSYS_NOERROR(sigreturn)
- mov out0=ret0
- CALLSYS_NOERROR(exit)
-END(epc_sigtramp)
-
- .align PAGE_SIZE
-
- .text
-
-ENTRY(epc_syscall, 8)
- .prologue
- .unwabi @svr4, 'E'
- .save rp, r0
-{ .mmi
- mov r16=ar.rsc
- mov ar.rsc=0
- mov r17=r13
- ;;
-}
-{ .mmi
- mov r18=ar.bspstore
- mov r19=ar.rnat
- add r30=-SIZEOF_TRAPFRAME,r14
- ;;
-}
-{ .mmi
- mov ar.bspstore=r15
- mov r13=ar.k4
- dep r30=0,r30,0,10
- ;;
-}
-{ .mii
- mov r20=sp
- add r31=8,r30
- add sp=-16,r30
- ;;
-}
-{ .mmi
- mov r21=ar.unat
- mov r22=ar.fpsr
- sub r29=r14,r30
- ;;
-}
-{ .mmi
- mov r23=ar.bsp
- mov ar.rsc=3
- add r28=FRAME_SYSCALL,r0
- ;;
-}
-{ .mmi
- st8 [r30]=r29,16 // tf_length
- st8 [r31]=r28,16 // tf_flags
- mov r24=rp
- ;;
-}
-{ .mmi
- st8 [r30]=r20,16 // sp
- st8 [r31]=r21,16 // unat
- mov r25=pr
- ;;
-}
-{ .mmi
- st8 [r30]=r24,16 // rp (syscall stub)
- st8 [r31]=r25,16 // pr
- mov r26=ar.pfs
- ;;
-}
-{ .mmi
- st8 [r30]=r26,16 // pfs (syscall stub)
- st8 [r31]=r18,16 // bspstore
- sub r27=r23,r15
- ;;
-}
-{ .mmi
- st8 [r30]=r19,16 // rnat
- st8 [r31]=r0,16 // __spare
- nop 0
- ;;
-}
-{ .mmi
- st8 [r30]=r17,16 // tp
- st8 [r31]=r16,16 // rsc
- dep r11=-1,r11,32,2 // Set psr.cpl=3
- ;;
-}
-{ .mmi
- st8 [r30]=r22,16 // fpsr
- st8 [r31]=r11,16 // psr
- nop 0
- ;;
-}
-{ .mmi
- st8 [r30]=r1,16 // gp
- st8 [r31]=r27,16 // ndirty
- nop 0
- ;;
-}
-{ .mmi
- st8 [r30]=r9,16 // pfs (syscall caller)
- st8 [r31]=r10,16 // rp (syscall caller)
- nop 0
- ;;
-}
-{ .mmi
- st8 [r30]=r0,80 // ifa
- st8 [r31]=r0,80 // isr
- nop 0
- ;;
-}
-{ .mmi
- alloc r14=ar.pfs,0,0,8,0
- st8 [r30]=r8,16 // syscall number (=r15)
- nop 0
- ;;
-}
-{ .mmi
- .mem.offset 0,0
- st8.spill [r31]=r32,16 // arg0 (=r16)
- .mem.offset 8,0
- st8.spill [r30]=r33,16 // arg1 (=r17)
- nop 0
- ;;
-}
-{ .mmi
- .mem.offset 16,0
- st8.spill [r31]=r34,16 // arg2 (=r18)
- .mem.offset 24,0
- st8.spill [r30]=r35,16 // arg3 (=r19)
- nop 0
- ;;
-}
-{ .mmi
- .mem.offset 32,0
- st8.spill [r31]=r36,16 // arg4 (=r20)
- .mem.offset 40,0
- st8.spill [r30]=r37,16 // arg5 (=r21)
- nop 0
- ;;
-}
-{ .mmi
- .mem.offset 48,0
- st8.spill [r31]=r38 // arg6 (=r22)
- .mem.offset 56,0
- st8.spill [r30]=r39 // arg7 (=r23)
- nop 0
- ;;
-}
-{ .mlx
- ssm psr.dfh|psr.ac
- movl gp=__gp
- ;;
-}
-epc_syscall_restart:
-{ .mib
- srlz.d
- add out0=16,sp
- br.call.sptk rp=syscall
- ;;
-}
-{ .mfb
- add out0=16,sp
- nop 0
- br.call.sptk rp=do_ast
- ;;
-}
-{ .mfb
- cmp4.eq p15,p0=ERESTART,r8
- nop 0
-(p15) br.spnt epc_syscall_restart
- ;;
-}
- .global epc_syscall_return
-epc_syscall_return:
-{ .mmi
- alloc r31=ar.pfs,0,0,0,0
- add r14=32,sp
- add r15=16,sp
- ;;
-}
-{ .mmi
- ld8 r31=[r15],24 // tf_length
- ld8 r16=[r14],16 // sp
- add sp=16,sp
- ;;
-}
-{ .mmi
- ld8 r17=[r15],16 // unat (before)
- ld8 r18=[r14],16 // rp (syscall stub)
- add r31=r31,sp
- ;;
-}
-{ .mmi
- ld8 r19=[r15],16 // pr
- ld8 r20=[r14],16 // pfs (syscall stub)
- mov b6=r18
- ;;
-}
-{ .mmi
- ld8 r21=[r15],24 // bspstore
- ld8 r22=[r14],24 // rnat
- mov pr=r19,0x1fffe
- ;;
-}
-{ .mmb
- ld8 r23=[r15],16 // tp
- ld8 r24=[r14],16 // rsc
- nop 0
- ;;
-}
-{ .mmi
- ld8 r25=[r15],16 // fpsr
- ld8 r26=[r14],16 // psr
- mov ar.pfs=r20
- ;;
-}
-{ .mmi
- ld8 gp=[r15],16 // gp
- ld8 r27=[r14],16 // ndirty
- tbit.z p14,p15=r26,34 // p14=ia64, p15=ia32
- ;;
-}
-{ .mmi
- ld8 r28=[r15],56 // pfs (syscall caller)
- ld8 r29=[r14],56 // rp (syscall caller)
- shl r27=r27,16
- ;;
-}
-{ .mmb
- ld8 r8=[r15],16 // r8
- mov ar.rsc=r27
- nop 0
- ;;
-}
-{ .mmb
- ld8 r9=[r14],40 // r9
- ld8 r10=[r15],40 // r10
-(p15) br.spnt epc_syscall_setup_ia32
- ;;
-}
-{ .mmi
- loadrs
- mov ar.k7=r31
- mov sp=r16
- ;;
-}
-{ .mmi
- mov r30=ar.bspstore
- ;;
- mov r14=ar.k5
- dep r30=0,r30,0,9
- ;;
-}
-{ .mmi
- mov ar.k6=r30
- mov ar.bspstore=r21
- mov r13=r23
- ;;
-}
-{ .mmi
- mov psr.l=r26
- mov ar.unat=r17
- add r14=gw_ret-ia64_gateway_page,r14
- ;;
-}
-{ .mib
- srlz.d
- mov b7=r14
- br.ret.sptk b7
- ;;
-}
-epc_syscall_setup_ia32:
-{ .mmi
- loadrs
- mov ar.k7=r31
- mov sp=r16
- ;;
-}
-{ .mmi
- mov r30=ar.bspstore
- ;;
- mov ar.bspstore=r21
- dep r30=0,r30,0,9
- ;;
-}
-{ .mmi
- mov ar.k6=r30
- mov ar.unat=r17
- mov r11=r26
- ;;
-}
-
- ld8 r16=[r14],16
- ld8 r17=[r15],16
- ;;
- ld8 r18=[r14],16
- ld8 r19=[r15],16
- ;;
- ld8 r20=[r14],16
- ld8 r21=[r15],16
- ;;
- ld8 r22=[r14],16
- ld8 r23=[r15],16
- ;;
- ld8 r24=[r14],16
- ld8 r25=[r15],16
- ;;
- ld8 r26=[r14],16
- ld8 r27=[r15],16
- ;;
- ld8 r28=[r14],16
- ld8 r29=[r15],16
- ;;
- ld8 r30=[r14],40
- ld8 r31=[r15],40
- ;;
- ld8 r2=[r14],16
- ld8 r3=[r15],8
- ;;
- mov ar.csd=r2
- mov ar.ssd=r3
- ;;
- mov r2=ar.k5
- mov psr.l=r11
- ;;
- srlz.d
- add r2=gw_ret_ia32-ia64_gateway_page,r2
- ;;
- mov b7=r2
- br.ret.sptk b7
- ;;
-END(epc_syscall)
diff --git a/sys/isa/atrtc.c b/sys/isa/atrtc.c
deleted file mode 100644
index 9e6c489637e3..000000000000
--- a/sys/isa/atrtc.c
+++ /dev/null
@@ -1,1216 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz and Don Ahn.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)clock.c 7.2 (Berkeley) 5/12/91
- * $FreeBSD$
- */
-
-/*
- * Routines to handle clock hardware.
- */
-
-/*
- * inittodr, settodr and support routines written
- * by Christoph Robitschko <chmr@edvz.tu-graz.ac.at>
- *
- * reintroduced and updated by Chris Stenton <chris@gnome.co.uk> 8/10/94
- */
-
-#include "opt_clock.h"
-#include "opt_isa.h"
-#include "opt_mca.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/time.h>
-#include <sys/timetc.h>
-#include <sys/kernel.h>
-#include <sys/limits.h>
-#include <sys/sysctl.h>
-#include <sys/cons.h>
-#include <sys/power.h>
-
-#include <machine/clock.h>
-#include <machine/cputypes.h>
-#include <machine/frame.h>
-#include <machine/md_var.h>
-#include <machine/psl.h>
-#ifdef APIC_IO
-#include <machine/segments.h>
-#endif
-#if defined(SMP) || defined(APIC_IO)
-#include <machine/smp.h>
-#endif /* SMP || APIC_IO */
-#include <machine/specialreg.h>
-
-#include <i386/isa/icu.h>
-#include <i386/isa/isa.h>
-#include <isa/rtc.h>
-#ifdef DEV_ISA
-#include <isa/isavar.h>
-#endif
-#include <i386/isa/timerreg.h>
-
-#include <i386/isa/intr_machdep.h>
-
-#ifdef DEV_MCA
-#include <i386/bios/mca_machdep.h>
-#endif
-
-#ifdef APIC_IO
-#include <i386/isa/intr_machdep.h>
-/* The interrupt triggered by the 8254 (timer) chip */
-int apic_8254_intr;
-static u_long read_intr_count(int vec);
-static void setup_8254_mixed_mode(void);
-#endif
-
-/*
- * 32-bit time_t's can't reach leap years before 1904 or after 2036, so we
- * can use a simple formula for leap years.
- */
-#define LEAPYEAR(y) ((u_int)(y) % 4 == 0)
-#define DAYSPERYEAR (31+28+31+30+31+30+31+31+30+31+30+31)
-
-#define TIMER_DIV(x) ((timer_freq + (x) / 2) / (x))
-
-/*
- * Time in timer cycles that it takes for microtime() to disable interrupts
- * and latch the count. microtime() currently uses "cli; outb ..." so it
- * normally takes less than 2 timer cycles. Add a few for cache misses.
- * Add a few more to allow for latency in bogus calls to microtime() with
- * interrupts already disabled.
- */
-#define TIMER0_LATCH_COUNT 20
-
-/*
- * Maximum frequency that we are willing to allow for timer0. Must be
- * low enough to guarantee that the timer interrupt handler returns
- * before the next timer interrupt.
- */
-#define TIMER0_MAX_FREQ 20000
-
-int adjkerntz; /* local offset from GMT in seconds */
-int clkintr_pending;
-int disable_rtc_set; /* disable resettodr() if != 0 */
-int pscnt = 1;
-int psdiv = 1;
-int statclock_disable;
-#ifndef TIMER_FREQ
-#define TIMER_FREQ 1193182
-#endif
-u_int timer_freq = TIMER_FREQ;
-int timer0_max_count;
-int wall_cmos_clock; /* wall CMOS clock assumed if != 0 */
-struct mtx clock_lock;
-
-static int beeping = 0;
-static const u_char daysinmonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};
-static u_int hardclock_max_count;
-static u_int32_t i8254_lastcount;
-static u_int32_t i8254_offset;
-static int i8254_ticked;
-/*
- * XXX new_function and timer_func should not handle clockframes, but
- * timer_func currently needs to hold hardclock to handle the
- * timer0_state == 0 case. We should use inthand_add()/inthand_remove()
- * to switch between clkintr() and a slightly different timerintr().
- */
-static void (*new_function)(struct clockframe *frame);
-static u_int new_rate;
-static u_char rtc_statusa = RTCSA_DIVIDER | RTCSA_NOPROF;
-static u_char rtc_statusb = RTCSB_24HR | RTCSB_PINTR;
-static u_int timer0_prescaler_count;
-
-/* Values for timerX_state: */
-#define RELEASED 0
-#define RELEASE_PENDING 1
-#define ACQUIRED 2
-#define ACQUIRE_PENDING 3
-
-static u_char timer0_state;
-static u_char timer2_state;
-static void (*timer_func)(struct clockframe *frame) = hardclock;
-
-static unsigned i8254_get_timecount(struct timecounter *tc);
-static void set_timer_freq(u_int freq, int intr_freq);
-
-static struct timecounter i8254_timecounter = {
- i8254_get_timecount, /* get_timecount */
- 0, /* no poll_pps */
- ~0u, /* counter_mask */
- 0, /* frequency */
- "i8254" /* name */
-};
-
-static void
-clkintr(struct clockframe frame)
-{
-
- if (timecounter->tc_get_timecount == i8254_get_timecount) {
- mtx_lock_spin(&clock_lock);
- if (i8254_ticked)
- i8254_ticked = 0;
- else {
- i8254_offset += timer0_max_count;
- i8254_lastcount = 0;
- }
- clkintr_pending = 0;
- mtx_unlock_spin(&clock_lock);
- }
- timer_func(&frame);
-#ifdef SMP
- if (timer_func == hardclock)
- forward_hardclock();
-#endif
- switch (timer0_state) {
-
- case RELEASED:
- break;
-
- case ACQUIRED:
- if ((timer0_prescaler_count += timer0_max_count)
- >= hardclock_max_count) {
- timer0_prescaler_count -= hardclock_max_count;
- hardclock(&frame);
-#ifdef SMP
- forward_hardclock();
-#endif
- }
- break;
-
- case ACQUIRE_PENDING:
- mtx_lock_spin(&clock_lock);
- i8254_offset = i8254_get_timecount(NULL);
- i8254_lastcount = 0;
- timer0_max_count = TIMER_DIV(new_rate);
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
- outb(TIMER_CNTR0, timer0_max_count & 0xff);
- outb(TIMER_CNTR0, timer0_max_count >> 8);
- mtx_unlock_spin(&clock_lock);
- timer_func = new_function;
- timer0_state = ACQUIRED;
- break;
-
- case RELEASE_PENDING:
- if ((timer0_prescaler_count += timer0_max_count)
- >= hardclock_max_count) {
- mtx_lock_spin(&clock_lock);
- i8254_offset = i8254_get_timecount(NULL);
- i8254_lastcount = 0;
- timer0_max_count = hardclock_max_count;
- outb(TIMER_MODE,
- TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
- outb(TIMER_CNTR0, timer0_max_count & 0xff);
- outb(TIMER_CNTR0, timer0_max_count >> 8);
- mtx_unlock_spin(&clock_lock);
- timer0_prescaler_count = 0;
- timer_func = hardclock;
- timer0_state = RELEASED;
- hardclock(&frame);
-#ifdef SMP
- forward_hardclock();
-#endif
- }
- break;
- }
-#ifdef DEV_MCA
- /* Reset clock interrupt by asserting bit 7 of port 0x61 */
- if (MCA_system)
- outb(0x61, inb(0x61) | 0x80);
-#endif
-}
-
-/*
- * The acquire and release functions must be called at ipl >= splclock().
- */
-int
-acquire_timer0(int rate, void (*function)(struct clockframe *frame))
-{
- static int old_rate;
-
- if (rate <= 0 || rate > TIMER0_MAX_FREQ)
- return (-1);
- switch (timer0_state) {
-
- case RELEASED:
- timer0_state = ACQUIRE_PENDING;
- break;
-
- case RELEASE_PENDING:
- if (rate != old_rate)
- return (-1);
- /*
- * The timer has been released recently, but is being
- * re-acquired before the release completed. In this
- * case, we simply reclaim it as if it had not been
- * released at all.
- */
- timer0_state = ACQUIRED;
- break;
-
- default:
- return (-1); /* busy */
- }
- new_function = function;
- old_rate = new_rate = rate;
- return (0);
-}
-
-int
-acquire_timer2(int mode)
-{
-
- if (timer2_state != RELEASED)
- return (-1);
- timer2_state = ACQUIRED;
-
- /*
- * This access to the timer registers is as atomic as possible
- * because it is a single instruction. We could do better if we
- * knew the rate. Use of splclock() limits glitches to 10-100us,
- * and this is probably good enough for timer2, so we aren't as
- * careful with it as with timer0.
- */
- outb(TIMER_MODE, TIMER_SEL2 | (mode & 0x3f));
-
- return (0);
-}
-
-int
-release_timer0()
-{
- switch (timer0_state) {
-
- case ACQUIRED:
- timer0_state = RELEASE_PENDING;
- break;
-
- case ACQUIRE_PENDING:
- /* Nothing happened yet, release quickly. */
- timer0_state = RELEASED;
- break;
-
- default:
- return (-1);
- }
- return (0);
-}
-
-int
-release_timer2()
-{
-
- if (timer2_state != ACQUIRED)
- return (-1);
- timer2_state = RELEASED;
- outb(TIMER_MODE, TIMER_SEL2 | TIMER_SQWAVE | TIMER_16BIT);
- return (0);
-}
-
-/*
- * This routine receives statistical clock interrupts from the RTC.
- * As explained above, these occur at 128 interrupts per second.
- * When profiling, we receive interrupts at a rate of 1024 Hz.
- *
- * This does not actually add as much overhead as it sounds, because
- * when the statistical clock is active, the hardclock driver no longer
- * needs to keep (inaccurate) statistics on its own. This decouples
- * statistics gathering from scheduling interrupts.
- *
- * The RTC chip requires that we read status register C (RTC_INTR)
- * to acknowledge an interrupt, before it will generate the next one.
- * Under high interrupt load, rtcintr() can be indefinitely delayed and
- * the clock can tick immediately after the read from RTC_INTR. In this
- * case, the mc146818A interrupt signal will not drop for long enough
- * to register with the 8259 PIC. If an interrupt is missed, the stat
- * clock will halt, considerably degrading system performance. This is
- * why we use 'while' rather than a more straightforward 'if' below.
- * Stat clock ticks can still be lost, causing minor loss of accuracy
- * in the statistics, but the stat clock will no longer stop.
- */
-static void
-rtcintr(struct clockframe frame)
-{
- while (rtcin(RTC_INTR) & RTCIR_PERIOD) {
- if (profprocs != 0) {
- if (--pscnt == 0)
- pscnt = psdiv;
- profclock(&frame);
- }
- if (pscnt == psdiv)
- statclock(&frame);
-#ifdef SMP
- forward_statclock();
-#endif
- }
-}
-
-#include "opt_ddb.h"
-#ifdef DDB
-#include <ddb/ddb.h>
-
-DB_SHOW_COMMAND(rtc, rtc)
-{
- printf("%02x/%02x/%02x %02x:%02x:%02x, A = %02x, B = %02x, C = %02x\n",
- rtcin(RTC_YEAR), rtcin(RTC_MONTH), rtcin(RTC_DAY),
- rtcin(RTC_HRS), rtcin(RTC_MIN), rtcin(RTC_SEC),
- rtcin(RTC_STATUSA), rtcin(RTC_STATUSB), rtcin(RTC_INTR));
-}
-#endif /* DDB */
-
-static int
-getit(void)
-{
- int high, low;
-
- mtx_lock_spin(&clock_lock);
-
- /* Select timer0 and latch counter value. */
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
-
- low = inb(TIMER_CNTR0);
- high = inb(TIMER_CNTR0);
-
- mtx_unlock_spin(&clock_lock);
- return ((high << 8) | low);
-}
-
-/*
- * Wait "n" microseconds.
- * Relies on timer 1 counting down from (timer_freq / hz)
- * Note: timer had better have been programmed before this is first used!
- */
-void
-DELAY(int n)
-{
- int delta, prev_tick, tick, ticks_left;
-
-#ifdef DELAYDEBUG
- int getit_calls = 1;
- int n1;
- static int state = 0;
-
- if (state == 0) {
- state = 1;
- for (n1 = 1; n1 <= 10000000; n1 *= 10)
- DELAY(n1);
- state = 2;
- }
- if (state == 1)
- printf("DELAY(%d)...", n);
-#endif
- /*
- * Guard against the timer being uninitialized if we are called
- * early for console i/o.
- */
- if (timer0_max_count == 0)
- set_timer_freq(timer_freq, hz);
-
- /*
- * Read the counter first, so that the rest of the setup overhead is
- * counted. Guess the initial overhead is 20 usec (on most systems it
- * takes about 1.5 usec for each of the i/o's in getit(). The loop
- * takes about 6 usec on a 486/33 and 13 usec on a 386/20. The
- * multiplications and divisions to scale the count take a while).
- */
- prev_tick = getit();
- n -= 0; /* XXX actually guess no initial overhead */
- /*
- * Calculate (n * (timer_freq / 1e6)) without using floating point
- * and without any avoidable overflows.
- */
- if (n <= 0)
- ticks_left = 0;
- else if (n < 256)
- /*
- * Use fixed point to avoid a slow division by 1000000.
- * 39099 = 1193182 * 2^15 / 10^6 rounded to nearest.
- * 2^15 is the first power of 2 that gives exact results
- * for n between 0 and 256.
- */
- ticks_left = ((u_int)n * 39099 + (1 << 15) - 1) >> 15;
- else
- /*
- * Don't bother using fixed point, although gcc-2.7.2
- * generates particularly poor code for the long long
- * division, since even the slow way will complete long
- * before the delay is up (unless we're interrupted).
- */
- ticks_left = ((u_int)n * (long long)timer_freq + 999999)
- / 1000000;
-
- while (ticks_left > 0) {
- tick = getit();
-#ifdef DELAYDEBUG
- ++getit_calls;
-#endif
- delta = prev_tick - tick;
- prev_tick = tick;
- if (delta < 0) {
- delta += timer0_max_count;
- /*
- * Guard against timer0_max_count being wrong.
- * This shouldn't happen in normal operation,
- * but it may happen if set_timer_freq() is
- * traced.
- */
- if (delta < 0)
- delta = 0;
- }
- ticks_left -= delta;
- }
-#ifdef DELAYDEBUG
- if (state == 1)
- printf(" %d calls to getit() at %d usec each\n",
- getit_calls, (n + 5) / getit_calls);
-#endif
-}
-
-static void
-sysbeepstop(void *chan)
-{
- outb(IO_PPI, inb(IO_PPI)&0xFC); /* disable counter2 output to speaker */
- release_timer2();
- beeping = 0;
-}
-
-int
-sysbeep(int pitch, int period)
-{
- int x = splclock();
-
- if (acquire_timer2(TIMER_SQWAVE|TIMER_16BIT))
- if (!beeping) {
- /* Something else owns it. */
- splx(x);
- return (-1); /* XXX Should be EBUSY, but nobody cares anyway. */
- }
- mtx_lock_spin(&clock_lock);
- outb(TIMER_CNTR2, pitch);
- outb(TIMER_CNTR2, (pitch>>8));
- mtx_unlock_spin(&clock_lock);
- if (!beeping) {
- /* enable counter2 output to speaker */
- outb(IO_PPI, inb(IO_PPI) | 3);
- beeping = period;
- timeout(sysbeepstop, (void *)NULL, period);
- }
- splx(x);
- return (0);
-}
-
-/*
- * RTC support routines
- */
-
-int
-rtcin(reg)
- int reg;
-{
- int s;
- u_char val;
-
- s = splhigh();
- outb(IO_RTC, reg);
- inb(0x84);
- val = inb(IO_RTC + 1);
- inb(0x84);
- splx(s);
- return (val);
-}
-
-static __inline void
-writertc(u_char reg, u_char val)
-{
- int s;
-
- s = splhigh();
- inb(0x84);
- outb(IO_RTC, reg);
- inb(0x84);
- outb(IO_RTC + 1, val);
- inb(0x84); /* XXX work around wrong order in rtcin() */
- splx(s);
-}
-
-static __inline int
-readrtc(int port)
-{
- return(bcd2bin(rtcin(port)));
-}
-
-static u_int
-calibrate_clocks(void)
-{
- u_int count, prev_count, tot_count;
- int sec, start_sec, timeout;
-
- if (bootverbose)
- printf("Calibrating clock(s) ... ");
- if (!(rtcin(RTC_STATUSD) & RTCSD_PWR))
- goto fail;
- timeout = 100000000;
-
- /* Read the mc146818A seconds counter. */
- for (;;) {
- if (!(rtcin(RTC_STATUSA) & RTCSA_TUP)) {
- sec = rtcin(RTC_SEC);
- break;
- }
- if (--timeout == 0)
- goto fail;
- }
-
- /* Wait for the mC146818A seconds counter to change. */
- start_sec = sec;
- for (;;) {
- if (!(rtcin(RTC_STATUSA) & RTCSA_TUP)) {
- sec = rtcin(RTC_SEC);
- if (sec != start_sec)
- break;
- }
- if (--timeout == 0)
- goto fail;
- }
-
- /* Start keeping track of the i8254 counter. */
- prev_count = getit();
- if (prev_count == 0 || prev_count > timer0_max_count)
- goto fail;
- tot_count = 0;
-
- /*
- * Wait for the mc146818A seconds counter to change. Read the i8254
- * counter for each iteration since this is convenient and only
- * costs a few usec of inaccuracy. The timing of the final reads
- * of the counters almost matches the timing of the initial reads,
- * so the main cause of inaccuracy is the varying latency from
- * inside getit() or rtcin(RTC_STATUSA) to the beginning of the
- * rtcin(RTC_SEC) that returns a changed seconds count. The
- * maximum inaccuracy from this cause is < 10 usec on 486's.
- */
- start_sec = sec;
- for (;;) {
- if (!(rtcin(RTC_STATUSA) & RTCSA_TUP))
- sec = rtcin(RTC_SEC);
- count = getit();
- if (count == 0 || count > timer0_max_count)
- goto fail;
- if (count > prev_count)
- tot_count += prev_count - (count - timer0_max_count);
- else
- tot_count += prev_count - count;
- prev_count = count;
- if (sec != start_sec)
- break;
- if (--timeout == 0)
- goto fail;
- }
-
- if (bootverbose) {
- printf("i8254 clock: %u Hz\n", tot_count);
- }
- return (tot_count);
-
-fail:
- if (bootverbose)
- printf("failed, using default i8254 clock of %u Hz\n",
- timer_freq);
- return (timer_freq);
-}
-
-static void
-set_timer_freq(u_int freq, int intr_freq)
-{
- int new_timer0_max_count;
-
- mtx_lock_spin(&clock_lock);
- timer_freq = freq;
- new_timer0_max_count = hardclock_max_count = TIMER_DIV(intr_freq);
- if (new_timer0_max_count != timer0_max_count) {
- timer0_max_count = new_timer0_max_count;
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
- outb(TIMER_CNTR0, timer0_max_count & 0xff);
- outb(TIMER_CNTR0, timer0_max_count >> 8);
- }
- mtx_unlock_spin(&clock_lock);
-}
-
-static void
-i8254_restore(void)
-{
-
- mtx_lock_spin(&clock_lock);
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
- outb(TIMER_CNTR0, timer0_max_count & 0xff);
- outb(TIMER_CNTR0, timer0_max_count >> 8);
- mtx_unlock_spin(&clock_lock);
-}
-
-static void
-rtc_restore(void)
-{
-
- /* Restore all of the RTC's "status" (actually, control) registers. */
- /* XXX locking is needed for RTC access. */
- writertc(RTC_STATUSB, RTCSB_24HR);
- writertc(RTC_STATUSA, rtc_statusa);
- writertc(RTC_STATUSB, rtc_statusb);
-}
-
-/*
- * Restore all the timers non-atomically (XXX: should be atomically).
- *
- * This function is called from pmtimer_resume() to restore all the timers.
- * This should not be necessary, but there are broken laptops that do not
- * restore all the timers on resume.
- */
-void
-timer_restore(void)
-{
-
- i8254_restore(); /* restore timer_freq and hz */
- rtc_restore(); /* reenable RTC interrupts */
-}
-
-/*
- * Initialize 8254 timer 0 early so that it can be used in DELAY().
- * XXX initialization of other timers is unintentionally left blank.
- */
-void
-startrtclock()
-{
- u_int delta, freq;
-
- writertc(RTC_STATUSA, rtc_statusa);
- writertc(RTC_STATUSB, RTCSB_24HR);
-
- set_timer_freq(timer_freq, hz);
- freq = calibrate_clocks();
-#ifdef CLK_CALIBRATION_LOOP
- if (bootverbose) {
- printf(
- "Press a key on the console to abort clock calibration\n");
- while (cncheckc() == -1)
- calibrate_clocks();
- }
-#endif
-
- /*
- * Use the calibrated i8254 frequency if it seems reasonable.
- * Otherwise use the default, and don't use the calibrated i586
- * frequency.
- */
- delta = freq > timer_freq ? freq - timer_freq : timer_freq - freq;
- if (delta < timer_freq / 100) {
-#ifndef CLK_USE_I8254_CALIBRATION
- if (bootverbose)
- printf(
-"CLK_USE_I8254_CALIBRATION not specified - using default frequency\n");
- freq = timer_freq;
-#endif
- timer_freq = freq;
- } else {
- if (bootverbose)
- printf(
- "%d Hz differs from default of %d Hz by more than 1%%\n",
- freq, timer_freq);
- }
-
- set_timer_freq(timer_freq, hz);
- i8254_timecounter.tc_frequency = timer_freq;
- tc_init(&i8254_timecounter);
-
- init_TSC();
-}
-
-/*
- * Initialize the time of day register, based on the time base which is, e.g.
- * from a filesystem.
- */
-void
-inittodr(time_t base)
-{
- unsigned long sec, days;
- int year, month;
- int y, m, s;
- struct timespec ts;
-
- if (base) {
- s = splclock();
- ts.tv_sec = base;
- ts.tv_nsec = 0;
- tc_setclock(&ts);
- splx(s);
- }
-
- /* Look if we have a RTC present and the time is valid */
- if (!(rtcin(RTC_STATUSD) & RTCSD_PWR))
- goto wrong_time;
-
- /* wait for time update to complete */
- /* If RTCSA_TUP is zero, we have at least 244us before next update */
- s = splhigh();
- while (rtcin(RTC_STATUSA) & RTCSA_TUP) {
- splx(s);
- s = splhigh();
- }
-
- days = 0;
-#ifdef USE_RTC_CENTURY
- year = readrtc(RTC_YEAR) + readrtc(RTC_CENTURY) * 100;
-#else
- year = readrtc(RTC_YEAR) + 1900;
- if (year < 1970)
- year += 100;
-#endif
- if (year < 1970) {
- splx(s);
- goto wrong_time;
- }
- month = readrtc(RTC_MONTH);
- for (m = 1; m < month; m++)
- days += daysinmonth[m-1];
- if ((month > 2) && LEAPYEAR(year))
- days ++;
- days += readrtc(RTC_DAY) - 1;
- for (y = 1970; y < year; y++)
- days += DAYSPERYEAR + LEAPYEAR(y);
- sec = ((( days * 24 +
- readrtc(RTC_HRS)) * 60 +
- readrtc(RTC_MIN)) * 60 +
- readrtc(RTC_SEC));
- /* sec now contains the number of seconds, since Jan 1 1970,
- in the local time zone */
-
- sec += tz_minuteswest * 60 + (wall_cmos_clock ? adjkerntz : 0);
-
- y = time_second - sec;
- if (y <= -2 || y >= 2) {
- /* badly off, adjust it */
- ts.tv_sec = sec;
- ts.tv_nsec = 0;
- tc_setclock(&ts);
- }
- splx(s);
- return;
-
-wrong_time:
- printf("Invalid time in real time clock.\n");
- printf("Check and reset the date immediately!\n");
-}
-
-/*
- * Write system time back to RTC
- */
-void
-resettodr()
-{
- unsigned long tm;
- int y, m, s;
-
- if (disable_rtc_set)
- return;
-
- s = splclock();
- tm = time_second;
- splx(s);
-
- /* Disable RTC updates and interrupts. */
- writertc(RTC_STATUSB, RTCSB_HALT | RTCSB_24HR);
-
- /* Calculate local time to put in RTC */
-
- tm -= tz_minuteswest * 60 + (wall_cmos_clock ? adjkerntz : 0);
-
- writertc(RTC_SEC, bin2bcd(tm%60)); tm /= 60; /* Write back Seconds */
- writertc(RTC_MIN, bin2bcd(tm%60)); tm /= 60; /* Write back Minutes */
- writertc(RTC_HRS, bin2bcd(tm%24)); tm /= 24; /* Write back Hours */
-
- /* We have now the days since 01-01-1970 in tm */
- writertc(RTC_WDAY, (tm + 4) % 7 + 1); /* Write back Weekday */
- for (y = 1970, m = DAYSPERYEAR + LEAPYEAR(y);
- tm >= m;
- y++, m = DAYSPERYEAR + LEAPYEAR(y))
- tm -= m;
-
- /* Now we have the years in y and the day-of-the-year in tm */
- writertc(RTC_YEAR, bin2bcd(y%100)); /* Write back Year */
-#ifdef USE_RTC_CENTURY
- writertc(RTC_CENTURY, bin2bcd(y/100)); /* ... and Century */
-#endif
- for (m = 0; ; m++) {
- int ml;
-
- ml = daysinmonth[m];
- if (m == 1 && LEAPYEAR(y))
- ml++;
- if (tm < ml)
- break;
- tm -= ml;
- }
-
- writertc(RTC_MONTH, bin2bcd(m + 1)); /* Write back Month */
- writertc(RTC_DAY, bin2bcd(tm + 1)); /* Write back Month Day */
-
- /* Reenable RTC updates and interrupts. */
- writertc(RTC_STATUSB, rtc_statusb);
-}
-
-
-/*
- * Start both clocks running.
- */
-void
-cpu_initclocks()
-{
- int diag;
-#ifdef APIC_IO
- int apic_8254_trial;
- void *clkdesc;
-#endif /* APIC_IO */
- register_t crit;
-
- if (statclock_disable) {
- /*
- * The stat interrupt mask is different without the
- * statistics clock. Also, don't set the interrupt
- * flag which would normally cause the RTC to generate
- * interrupts.
- */
- rtc_statusb = RTCSB_24HR;
- } else {
- /* Setting stathz to nonzero early helps avoid races. */
- stathz = RTC_NOPROFRATE;
- profhz = RTC_PROFRATE;
- }
-
- /* Finish initializing 8253 timer 0. */
-#ifdef APIC_IO
-
- apic_8254_intr = isa_apic_irq(0);
- apic_8254_trial = 0;
- if (apic_8254_intr >= 0 ) {
- if (apic_int_type(0, 0) == 3)
- apic_8254_trial = 1;
- } else {
- /* look for ExtInt on pin 0 */
- if (apic_int_type(0, 0) == 3) {
- apic_8254_intr = apic_irq(0, 0);
- setup_8254_mixed_mode();
- } else
- panic("APIC_IO: Cannot route 8254 interrupt to CPU");
- }
-
- inthand_add("clk", apic_8254_intr, (driver_intr_t *)clkintr, NULL,
- INTR_TYPE_CLK | INTR_FAST, &clkdesc);
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTREN(1 << apic_8254_intr);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-
-#else /* APIC_IO */
-
- /*
- * XXX Check the priority of this interrupt handler. I
- * couldn't find anything suitable in the BSD/OS code (grog,
- * 19 July 2000).
- */
- inthand_add("clk", 0, (driver_intr_t *)clkintr, NULL,
- INTR_TYPE_CLK | INTR_FAST, NULL);
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTREN(IRQ0);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-
-#endif /* APIC_IO */
-
- /* Initialize RTC. */
- writertc(RTC_STATUSA, rtc_statusa);
- writertc(RTC_STATUSB, RTCSB_24HR);
-
- /* Don't bother enabling the statistics clock. */
- if (statclock_disable)
- return;
- diag = rtcin(RTC_DIAG);
- if (diag != 0)
- printf("RTC BIOS diagnostic error %b\n", diag, RTCDG_BITS);
-
-#ifdef APIC_IO
- if (isa_apic_irq(8) != 8)
- panic("APIC RTC != 8");
-#endif /* APIC_IO */
-
- inthand_add("rtc", 8, (driver_intr_t *)rtcintr, NULL,
- INTR_TYPE_CLK | INTR_FAST, NULL);
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
-#ifdef APIC_IO
- INTREN(APIC_IRQ8);
-#else
- INTREN(IRQ8);
-#endif /* APIC_IO */
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-
- writertc(RTC_STATUSB, rtc_statusb);
-
-#ifdef APIC_IO
- if (apic_8254_trial) {
-
- printf("APIC_IO: Testing 8254 interrupt delivery\n");
- while (read_intr_count(8) < 6)
- ; /* nothing */
- if (read_intr_count(apic_8254_intr) < 3) {
- /*
- * The MP table is broken.
- * The 8254 was not connected to the specified pin
- * on the IO APIC.
- * Workaround: Limited variant of mixed mode.
- */
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTRDIS(1 << apic_8254_intr);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
- inthand_remove(clkdesc);
- printf("APIC_IO: Broken MP table detected: "
- "8254 is not connected to "
- "IOAPIC #%d intpin %d\n",
- int_to_apicintpin[apic_8254_intr].ioapic,
- int_to_apicintpin[apic_8254_intr].int_pin);
- /*
- * Revoke current ISA IRQ 0 assignment and
- * configure a fallback interrupt routing from
- * the 8254 Timer via the 8259 PIC to the
- * an ExtInt interrupt line on IOAPIC #0 intpin 0.
- * We reuse the low level interrupt handler number.
- */
- if (apic_irq(0, 0) < 0) {
- revoke_apic_irq(apic_8254_intr);
- assign_apic_irq(0, 0, apic_8254_intr);
- }
- apic_8254_intr = apic_irq(0, 0);
- setup_8254_mixed_mode();
- inthand_add("clk", apic_8254_intr,
- (driver_intr_t *)clkintr, NULL,
- INTR_TYPE_CLK | INTR_FAST, NULL);
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTREN(1 << apic_8254_intr);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
- }
-
- }
- if (apic_int_type(0, 0) != 3 ||
- int_to_apicintpin[apic_8254_intr].ioapic != 0 ||
- int_to_apicintpin[apic_8254_intr].int_pin != 0)
- printf("APIC_IO: routing 8254 via IOAPIC #%d intpin %d\n",
- int_to_apicintpin[apic_8254_intr].ioapic,
- int_to_apicintpin[apic_8254_intr].int_pin);
- else
- printf("APIC_IO: "
- "routing 8254 via 8259 and IOAPIC #0 intpin 0\n");
-#endif
-
-}
-
-#ifdef APIC_IO
-static u_long
-read_intr_count(int vec)
-{
- u_long *up;
- up = intr_countp[vec];
- if (up)
- return *up;
- return 0UL;
-}
-
-static void
-setup_8254_mixed_mode()
-{
- /*
- * Allow 8254 timer to INTerrupt 8259:
- * re-initialize master 8259:
- * reset; prog 4 bytes, single ICU, edge triggered
- */
- outb(IO_ICU1, 0x13);
- outb(IO_ICU1 + 1, NRSVIDT); /* start vector (unused) */
- outb(IO_ICU1 + 1, 0x00); /* ignore slave */
- outb(IO_ICU1 + 1, 0x03); /* auto EOI, 8086 */
- outb(IO_ICU1 + 1, 0xfe); /* unmask INT0 */
-
- /* program IO APIC for type 3 INT on INT0 */
- if (ext_int_setup(0, 0) < 0)
- panic("8254 redirect via APIC pin0 impossible!");
-}
-#endif
-
-void
-cpu_startprofclock(void)
-{
-
- rtc_statusa = RTCSA_DIVIDER | RTCSA_PROF;
- writertc(RTC_STATUSA, rtc_statusa);
- psdiv = pscnt = psratio;
-}
-
-void
-cpu_stopprofclock(void)
-{
-
- rtc_statusa = RTCSA_DIVIDER | RTCSA_NOPROF;
- writertc(RTC_STATUSA, rtc_statusa);
- psdiv = pscnt = 1;
-}
-
-static int
-sysctl_machdep_i8254_freq(SYSCTL_HANDLER_ARGS)
-{
- int error;
- u_int freq;
-
- /*
- * Use `i8254' instead of `timer' in external names because `timer'
- * is is too generic. Should use it everywhere.
- */
- freq = timer_freq;
- error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
- if (error == 0 && req->newptr != NULL) {
- if (timer0_state != RELEASED)
- return (EBUSY); /* too much trouble to handle */
- set_timer_freq(freq, hz);
- i8254_timecounter.tc_frequency = freq;
- }
- return (error);
-}
-
-SYSCTL_PROC(_machdep, OID_AUTO, i8254_freq, CTLTYPE_INT | CTLFLAG_RW,
- 0, sizeof(u_int), sysctl_machdep_i8254_freq, "IU", "");
-
-static unsigned
-i8254_get_timecount(struct timecounter *tc)
-{
- u_int count;
- u_int high, low;
- u_int eflags;
-
- eflags = read_eflags();
- mtx_lock_spin(&clock_lock);
-
- /* Select timer0 and latch counter value. */
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
-
- low = inb(TIMER_CNTR0);
- high = inb(TIMER_CNTR0);
- count = timer0_max_count - ((high << 8) | low);
- if (count < i8254_lastcount ||
- (!i8254_ticked && (clkintr_pending ||
- ((count < 20 || (!(eflags & PSL_I) && count < timer0_max_count / 2u)) &&
-#ifdef APIC_IO
-#define lapic_irr1 ((volatile u_int *)&lapic)[0x210 / 4] /* XXX XXX */
- /* XXX this assumes that apic_8254_intr is < 24. */
- (lapic_irr1 & (1 << apic_8254_intr))))
-#else
- (inb(IO_ICU1) & 1)))
-#endif
- )) {
- i8254_ticked = 1;
- i8254_offset += timer0_max_count;
- }
- i8254_lastcount = count;
- count += i8254_offset;
- mtx_unlock_spin(&clock_lock);
- return (count);
-}
-
-#ifdef DEV_ISA
-/*
- * Attach to the ISA PnP descriptors for the timer and realtime clock.
- */
-static struct isa_pnp_id attimer_ids[] = {
- { 0x0001d041 /* PNP0100 */, "AT timer" },
- { 0x000bd041 /* PNP0B00 */, "AT realtime clock" },
- { 0 }
-};
-
-static int
-attimer_probe(device_t dev)
-{
- int result;
-
- if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, attimer_ids)) <= 0)
- device_quiet(dev);
- return(result);
-}
-
-static int
-attimer_attach(device_t dev)
-{
- return(0);
-}
-
-static device_method_t attimer_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, attimer_probe),
- DEVMETHOD(device_attach, attimer_attach),
- DEVMETHOD(device_detach, bus_generic_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend), /* XXX stop statclock? */
- DEVMETHOD(device_resume, bus_generic_resume), /* XXX restart statclock? */
- { 0, 0 }
-};
-
-static driver_t attimer_driver = {
- "attimer",
- attimer_methods,
- 1, /* no softc */
-};
-
-static devclass_t attimer_devclass;
-
-DRIVER_MODULE(attimer, isa, attimer_driver, attimer_devclass, 0, 0);
-DRIVER_MODULE(attimer, acpi, attimer_driver, attimer_devclass, 0, 0);
-#endif /* DEV_ISA */
diff --git a/sys/kern/kern_kse.c b/sys/kern/kern_kse.c
deleted file mode 100644
index e02b7f2f3c76..000000000000
--- a/sys/kern/kern_kse.c
+++ /dev/null
@@ -1,2055 +0,0 @@
-/*
- * Copyright (C) 2001 Julian Elischer <julian@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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/smp.h>
-#include <sys/sysctl.h>
-#include <sys/sysproto.h>
-#include <sys/filedesc.h>
-#include <sys/sched.h>
-#include <sys/signalvar.h>
-#include <sys/sx.h>
-#include <sys/tty.h>
-#include <sys/user.h>
-#include <sys/jail.h>
-#include <sys/kse.h>
-#include <sys/ktr.h>
-#include <sys/ucontext.h>
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/pmap.h>
-#include <vm/uma.h>
-#include <vm/vm_map.h>
-
-#include <machine/frame.h>
-
-/*
- * KSEGRP related storage.
- */
-static uma_zone_t ksegrp_zone;
-static uma_zone_t kse_zone;
-static uma_zone_t thread_zone;
-static uma_zone_t upcall_zone;
-
-/* DEBUG ONLY */
-SYSCTL_NODE(_kern, OID_AUTO, threads, CTLFLAG_RW, 0, "thread allocation");
-static int thread_debug = 0;
-SYSCTL_INT(_kern_threads, OID_AUTO, debug, CTLFLAG_RW,
- &thread_debug, 0, "thread debug");
-
-static int max_threads_per_proc = 150;
-SYSCTL_INT(_kern_threads, OID_AUTO, max_threads_per_proc, CTLFLAG_RW,
- &max_threads_per_proc, 0, "Limit on threads per proc");
-
-static int max_groups_per_proc = 50;
-SYSCTL_INT(_kern_threads, OID_AUTO, max_groups_per_proc, CTLFLAG_RW,
- &max_groups_per_proc, 0, "Limit on thread groups per proc");
-
-static int max_threads_hits;
-SYSCTL_INT(_kern_threads, OID_AUTO, max_threads_hits, CTLFLAG_RD,
- &max_threads_hits, 0, "");
-
-static int virtual_cpu;
-
-#define RANGEOF(type, start, end) (offsetof(type, end) - offsetof(type, start))
-
-TAILQ_HEAD(, thread) zombie_threads = TAILQ_HEAD_INITIALIZER(zombie_threads);
-TAILQ_HEAD(, kse) zombie_kses = TAILQ_HEAD_INITIALIZER(zombie_kses);
-TAILQ_HEAD(, ksegrp) zombie_ksegrps = TAILQ_HEAD_INITIALIZER(zombie_ksegrps);
-TAILQ_HEAD(, kse_upcall) zombie_upcalls =
- TAILQ_HEAD_INITIALIZER(zombie_upcalls);
-struct mtx kse_zombie_lock;
-MTX_SYSINIT(kse_zombie_lock, &kse_zombie_lock, "kse zombie lock", MTX_SPIN);
-
-static void kse_purge(struct proc *p, struct thread *td);
-static void kse_purge_group(struct thread *td);
-static int thread_update_usr_ticks(struct thread *td, int user);
-static void thread_alloc_spare(struct thread *td, struct thread *spare);
-
-static int
-sysctl_kse_virtual_cpu(SYSCTL_HANDLER_ARGS)
-{
- int error, new_val;
- int def_val;
-
-#ifdef SMP
- def_val = mp_ncpus;
-#else
- def_val = 1;
-#endif
- if (virtual_cpu == 0)
- new_val = def_val;
- else
- new_val = virtual_cpu;
- error = sysctl_handle_int(oidp, &new_val, 0, req);
- if (error != 0 || req->newptr == NULL)
- return (error);
- if (new_val < 0)
- return (EINVAL);
- virtual_cpu = new_val;
- return (0);
-}
-
-/* DEBUG ONLY */
-SYSCTL_PROC(_kern_threads, OID_AUTO, virtual_cpu, CTLTYPE_INT|CTLFLAG_RW,
- 0, sizeof(virtual_cpu), sysctl_kse_virtual_cpu, "I",
- "debug virtual cpus");
-
-/*
- * Prepare a thread for use.
- */
-static void
-thread_ctor(void *mem, int size, void *arg)
-{
- struct thread *td;
-
- td = (struct thread *)mem;
- td->td_state = TDS_INACTIVE;
- td->td_oncpu = NOCPU;
-}
-
-/*
- * Reclaim a thread after use.
- */
-static void
-thread_dtor(void *mem, int size, void *arg)
-{
- struct thread *td;
-
- td = (struct thread *)mem;
-
-#ifdef INVARIANTS
- /* Verify that this thread is in a safe state to free. */
- switch (td->td_state) {
- case TDS_INHIBITED:
- case TDS_RUNNING:
- case TDS_CAN_RUN:
- case TDS_RUNQ:
- /*
- * We must never unlink a thread that is in one of
- * these states, because it is currently active.
- */
- panic("bad state for thread unlinking");
- /* NOTREACHED */
- case TDS_INACTIVE:
- break;
- default:
- panic("bad thread state");
- /* NOTREACHED */
- }
-#endif
-}
-
-/*
- * Initialize type-stable parts of a thread (when newly created).
- */
-static void
-thread_init(void *mem, int size)
-{
- struct thread *td;
-
- td = (struct thread *)mem;
- mtx_lock(&Giant);
- pmap_new_thread(td, 0);
- mtx_unlock(&Giant);
- cpu_thread_setup(td);
- td->td_sched = (struct td_sched *)&td[1];
-}
-
-/*
- * Tear down type-stable parts of a thread (just before being discarded).
- */
-static void
-thread_fini(void *mem, int size)
-{
- struct thread *td;
-
- td = (struct thread *)mem;
- pmap_dispose_thread(td);
-}
-
-/*
- * Initialize type-stable parts of a kse (when newly created).
- */
-static void
-kse_init(void *mem, int size)
-{
- struct kse *ke;
-
- ke = (struct kse *)mem;
- ke->ke_sched = (struct ke_sched *)&ke[1];
-}
-
-/*
- * Initialize type-stable parts of a ksegrp (when newly created).
- */
-static void
-ksegrp_init(void *mem, int size)
-{
- struct ksegrp *kg;
-
- kg = (struct ksegrp *)mem;
- kg->kg_sched = (struct kg_sched *)&kg[1];
-}
-
-/*
- * KSE is linked into kse group.
- */
-void
-kse_link(struct kse *ke, struct ksegrp *kg)
-{
- struct proc *p = kg->kg_proc;
-
- TAILQ_INSERT_HEAD(&kg->kg_kseq, ke, ke_kglist);
- kg->kg_kses++;
- ke->ke_state = KES_UNQUEUED;
- ke->ke_proc = p;
- ke->ke_ksegrp = kg;
- ke->ke_thread = NULL;
- ke->ke_oncpu = NOCPU;
- ke->ke_flags = 0;
-}
-
-void
-kse_unlink(struct kse *ke)
-{
- struct ksegrp *kg;
-
- mtx_assert(&sched_lock, MA_OWNED);
- kg = ke->ke_ksegrp;
- TAILQ_REMOVE(&kg->kg_kseq, ke, ke_kglist);
- if (ke->ke_state == KES_IDLE) {
- TAILQ_REMOVE(&kg->kg_iq, ke, ke_kgrlist);
- kg->kg_idle_kses--;
- }
- if (--kg->kg_kses == 0)
- ksegrp_unlink(kg);
- /*
- * Aggregate stats from the KSE
- */
- kse_stash(ke);
-}
-
-void
-ksegrp_link(struct ksegrp *kg, struct proc *p)
-{
-
- TAILQ_INIT(&kg->kg_threads);
- TAILQ_INIT(&kg->kg_runq); /* links with td_runq */
- TAILQ_INIT(&kg->kg_slpq); /* links with td_runq */
- TAILQ_INIT(&kg->kg_kseq); /* all kses in ksegrp */
- TAILQ_INIT(&kg->kg_iq); /* all idle kses in ksegrp */
- TAILQ_INIT(&kg->kg_upcalls); /* all upcall structure in ksegrp */
- kg->kg_proc = p;
- /*
- * the following counters are in the -zero- section
- * and may not need clearing
- */
- kg->kg_numthreads = 0;
- kg->kg_runnable = 0;
- kg->kg_kses = 0;
- kg->kg_runq_kses = 0; /* XXXKSE change name */
- kg->kg_idle_kses = 0;
- kg->kg_numupcalls = 0;
- /* link it in now that it's consistent */
- p->p_numksegrps++;
- TAILQ_INSERT_HEAD(&p->p_ksegrps, kg, kg_ksegrp);
-}
-
-void
-ksegrp_unlink(struct ksegrp *kg)
-{
- struct proc *p;
-
- mtx_assert(&sched_lock, MA_OWNED);
- KASSERT((kg->kg_numthreads == 0), ("ksegrp_unlink: residual threads"));
- KASSERT((kg->kg_kses == 0), ("ksegrp_unlink: residual kses"));
- KASSERT((kg->kg_numupcalls == 0), ("ksegrp_unlink: residual upcalls"));
-
- p = kg->kg_proc;
- TAILQ_REMOVE(&p->p_ksegrps, kg, kg_ksegrp);
- p->p_numksegrps--;
- /*
- * Aggregate stats from the KSE
- */
- ksegrp_stash(kg);
-}
-
-struct kse_upcall *
-upcall_alloc(void)
-{
- struct kse_upcall *ku;
-
- ku = uma_zalloc(upcall_zone, M_WAITOK);
- bzero(ku, sizeof(*ku));
- return (ku);
-}
-
-void
-upcall_free(struct kse_upcall *ku)
-{
-
- uma_zfree(upcall_zone, ku);
-}
-
-void
-upcall_link(struct kse_upcall *ku, struct ksegrp *kg)
-{
-
- mtx_assert(&sched_lock, MA_OWNED);
- TAILQ_INSERT_TAIL(&kg->kg_upcalls, ku, ku_link);
- ku->ku_ksegrp = kg;
- kg->kg_numupcalls++;
-}
-
-void
-upcall_unlink(struct kse_upcall *ku)
-{
- struct ksegrp *kg = ku->ku_ksegrp;
-
- mtx_assert(&sched_lock, MA_OWNED);
- KASSERT(ku->ku_owner == NULL, ("%s: have owner", __func__));
- TAILQ_REMOVE(&kg->kg_upcalls, ku, ku_link);
- kg->kg_numupcalls--;
- upcall_stash(ku);
-}
-
-void
-upcall_remove(struct thread *td)
-{
-
- if (td->td_upcall) {
- td->td_upcall->ku_owner = NULL;
- upcall_unlink(td->td_upcall);
- td->td_upcall = 0;
- }
-}
-
-/*
- * For a newly created process,
- * link up all the structures and its initial threads etc.
- */
-void
-proc_linkup(struct proc *p, struct ksegrp *kg,
- struct kse *ke, struct thread *td)
-{
-
- TAILQ_INIT(&p->p_ksegrps); /* all ksegrps in proc */
- TAILQ_INIT(&p->p_threads); /* all threads in proc */
- TAILQ_INIT(&p->p_suspended); /* Threads suspended */
- p->p_numksegrps = 0;
- p->p_numthreads = 0;
-
- ksegrp_link(kg, p);
- kse_link(ke, kg);
- thread_link(td, kg);
-}
-
-/*
-struct kse_thr_interrupt_args {
- struct kse_thr_mailbox * tmbx;
-};
-*/
-int
-kse_thr_interrupt(struct thread *td, struct kse_thr_interrupt_args *uap)
-{
- struct proc *p;
- struct thread *td2;
-
- p = td->td_proc;
- if (!(p->p_flag & P_THREADED) || (uap->tmbx == NULL))
- return (EINVAL);
- mtx_lock_spin(&sched_lock);
- FOREACH_THREAD_IN_PROC(p, td2) {
- if (td2->td_mailbox == uap->tmbx) {
- td2->td_flags |= TDF_INTERRUPT;
- if (TD_ON_SLEEPQ(td2) && (td2->td_flags & TDF_SINTR)) {
- if (td2->td_flags & TDF_CVWAITQ)
- cv_abort(td2);
- else
- abortsleep(td2);
- }
- mtx_unlock_spin(&sched_lock);
- return (0);
- }
- }
- mtx_unlock_spin(&sched_lock);
- return (ESRCH);
-}
-
-/*
-struct kse_exit_args {
- register_t dummy;
-};
-*/
-int
-kse_exit(struct thread *td, struct kse_exit_args *uap)
-{
- struct proc *p;
- struct ksegrp *kg;
- struct kse *ke;
-
- p = td->td_proc;
- if (td->td_upcall == NULL || TD_CAN_UNBIND(td))
- return (EINVAL);
- kg = td->td_ksegrp;
- /* Serialize removing upcall */
- PROC_LOCK(p);
- mtx_lock_spin(&sched_lock);
- if ((kg->kg_numupcalls == 1) && (kg->kg_numthreads > 1)) {
- mtx_unlock_spin(&sched_lock);
- PROC_UNLOCK(p);
- return (EDEADLK);
- }
- ke = td->td_kse;
- upcall_remove(td);
- if (p->p_numthreads == 1) {
- kse_purge(p, td);
- p->p_flag &= ~P_THREADED;
- mtx_unlock_spin(&sched_lock);
- PROC_UNLOCK(p);
- } else {
- if (kg->kg_numthreads == 1) { /* Shutdown a group */
- kse_purge_group(td);
- ke->ke_flags |= KEF_EXIT;
- }
- thread_stopped(p);
- thread_exit();
- /* NOTREACHED */
- }
- return (0);
-}
-
-/*
- * Either becomes an upcall or waits for an awakening event and
- * then becomes an upcall. Only error cases return.
- */
-/*
-struct kse_release_args {
- struct timespec *timeout;
-};
-*/
-int
-kse_release(struct thread *td, struct kse_release_args *uap)
-{
- struct proc *p;
- struct ksegrp *kg;
- struct timespec ts, ts2, ts3, timeout;
- struct timeval tv;
- int error;
-
- p = td->td_proc;
- kg = td->td_ksegrp;
- if (td->td_upcall == NULL || TD_CAN_UNBIND(td))
- return (EINVAL);
- if (uap->timeout != NULL) {
- if ((error = copyin(uap->timeout, &timeout, sizeof(timeout))))
- return (error);
- getnanouptime(&ts);
- timespecadd(&ts, &timeout);
- TIMESPEC_TO_TIMEVAL(&tv, &timeout);
- }
- mtx_lock_spin(&sched_lock);
- /* Change OURSELF to become an upcall. */
- td->td_flags = TDF_UPCALLING;
-#if 0 /* XXX This shouldn't be necessary */
- if (p->p_sflag & PS_NEEDSIGCHK)
- td->td_flags |= TDF_ASTPENDING;
-#endif
- mtx_unlock_spin(&sched_lock);
- PROC_LOCK(p);
- while ((td->td_upcall->ku_flags & KUF_DOUPCALL) == 0 &&
- (kg->kg_completed == NULL)) {
- kg->kg_upsleeps++;
- error = msleep(&kg->kg_completed, &p->p_mtx, PPAUSE|PCATCH,
- "kse_rel", (uap->timeout ? tvtohz(&tv) : 0));
- kg->kg_upsleeps--;
- PROC_UNLOCK(p);
- if (uap->timeout == NULL || error != EWOULDBLOCK)
- return (0);
- getnanouptime(&ts2);
- if (timespeccmp(&ts2, &ts, >=))
- return (0);
- ts3 = ts;
- timespecsub(&ts3, &ts2);
- TIMESPEC_TO_TIMEVAL(&tv, &ts3);
- PROC_LOCK(p);
- }
- PROC_UNLOCK(p);
- return (0);
-}
-
-/* struct kse_wakeup_args {
- struct kse_mailbox *mbx;
-}; */
-int
-kse_wakeup(struct thread *td, struct kse_wakeup_args *uap)
-{
- struct proc *p;
- struct ksegrp *kg;
- struct kse_upcall *ku;
- struct thread *td2;
-
- p = td->td_proc;
- td2 = NULL;
- ku = NULL;
- /* KSE-enabled processes only, please. */
- if (!(p->p_flag & P_THREADED))
- return (EINVAL);
- PROC_LOCK(p);
- mtx_lock_spin(&sched_lock);
- if (uap->mbx) {
- FOREACH_KSEGRP_IN_PROC(p, kg) {
- FOREACH_UPCALL_IN_GROUP(kg, ku) {
- if (ku->ku_mailbox == uap->mbx)
- break;
- }
- if (ku)
- break;
- }
- } else {
- kg = td->td_ksegrp;
- if (kg->kg_upsleeps) {
- wakeup_one(&kg->kg_completed);
- mtx_unlock_spin(&sched_lock);
- PROC_UNLOCK(p);
- return (0);
- }
- ku = TAILQ_FIRST(&kg->kg_upcalls);
- }
- if (ku) {
- if ((td2 = ku->ku_owner) == NULL) {
- panic("%s: no owner", __func__);
- } else if (TD_ON_SLEEPQ(td2) &&
- (td2->td_wchan == &kg->kg_completed)) {
- abortsleep(td2);
- } else {
- ku->ku_flags |= KUF_DOUPCALL;
- }
- mtx_unlock_spin(&sched_lock);
- PROC_UNLOCK(p);
- return (0);
- }
- mtx_unlock_spin(&sched_lock);
- PROC_UNLOCK(p);
- return (ESRCH);
-}
-
-/*
- * No new KSEG: first call: use current KSE, don't schedule an upcall
- * All other situations, do allocate max new KSEs and schedule an upcall.
- */
-/* struct kse_create_args {
- struct kse_mailbox *mbx;
- int newgroup;
-}; */
-int
-kse_create(struct thread *td, struct kse_create_args *uap)
-{
- struct kse *newke;
- struct ksegrp *newkg;
- struct ksegrp *kg;
- struct proc *p;
- struct kse_mailbox mbx;
- struct kse_upcall *newku;
- int err, ncpus;
-
- p = td->td_proc;
- if ((err = copyin(uap->mbx, &mbx, sizeof(mbx))))
- return (err);
-
- /* Too bad, why hasn't kernel always a cpu counter !? */
-#ifdef SMP
- ncpus = mp_ncpus;
-#else
- ncpus = 1;
-#endif
- if (thread_debug && virtual_cpu != 0)
- ncpus = virtual_cpu;
-
- /* Easier to just set it than to test and set */
- PROC_LOCK(p);
- p->p_flag |= P_THREADED;
- PROC_UNLOCK(p);
- kg = td->td_ksegrp;
- if (uap->newgroup) {
- /* Have race condition but it is cheap */
- if (p->p_numksegrps >= max_groups_per_proc)
- return (EPROCLIM);
- /*
- * If we want a new KSEGRP it doesn't matter whether
- * we have already fired up KSE mode before or not.
- * We put the process in KSE mode and create a new KSEGRP.
- */
- newkg = ksegrp_alloc();
- bzero(&newkg->kg_startzero, RANGEOF(struct ksegrp,
- kg_startzero, kg_endzero));
- bcopy(&kg->kg_startcopy, &newkg->kg_startcopy,
- RANGEOF(struct ksegrp, kg_startcopy, kg_endcopy));
- mtx_lock_spin(&sched_lock);
- if (p->p_numksegrps >= max_groups_per_proc) {
- mtx_unlock_spin(&sched_lock);
- ksegrp_free(newkg);
- return (EPROCLIM);
- }
- ksegrp_link(newkg, p);
- mtx_unlock_spin(&sched_lock);
- } else {
- newkg = kg;
- }
-
- /*
- * Creating upcalls more than number of physical cpu does
- * not help performance.
- */
- if (newkg->kg_numupcalls >= ncpus)
- return (EPROCLIM);
-
- if (newkg->kg_numupcalls == 0) {
- /*
- * Initialize KSE group, optimized for MP.
- * Create KSEs as many as physical cpus, this increases
- * concurrent even if userland is not MP safe and can only run
- * on single CPU (for early version of libpthread, it is true).
- * In ideal world, every physical cpu should execute a thread.
- * If there is enough KSEs, threads in kernel can be
- * executed parallel on different cpus with full speed,
- * Concurrent in kernel shouldn't be restricted by number of
- * upcalls userland provides.
- * Adding more upcall structures only increases concurrent
- * in userland.
- * Highest performance configuration is:
- * N kses = N upcalls = N phyiscal cpus
- */
- while (newkg->kg_kses < ncpus) {
- newke = kse_alloc();
- bzero(&newke->ke_startzero, RANGEOF(struct kse,
- ke_startzero, ke_endzero));
-#if 0
- mtx_lock_spin(&sched_lock);
- bcopy(&ke->ke_startcopy, &newke->ke_startcopy,
- RANGEOF(struct kse, ke_startcopy, ke_endcopy));
- mtx_unlock_spin(&sched_lock);
-#endif
- mtx_lock_spin(&sched_lock);
- kse_link(newke, newkg);
- /* Add engine */
- kse_reassign(newke);
- mtx_unlock_spin(&sched_lock);
- }
- }
- newku = upcall_alloc();
- newku->ku_mailbox = uap->mbx;
- newku->ku_func = mbx.km_func;
- bcopy(&mbx.km_stack, &newku->ku_stack, sizeof(stack_t));
-
- /* For the first call this may not have been set */
- if (td->td_standin == NULL)
- thread_alloc_spare(td, NULL);
-
- mtx_lock_spin(&sched_lock);
- if (newkg->kg_numupcalls >= ncpus) {
- mtx_unlock_spin(&sched_lock);
- upcall_free(newku);
- return (EPROCLIM);
- }
- upcall_link(newku, newkg);
- if (mbx.km_quantum)
- newkg->kg_upquantum = max(1, mbx.km_quantum/tick);
-
- /*
- * Each upcall structure has an owner thread, find which
- * one owns it.
- */
- if (uap->newgroup) {
- /*
- * Because new ksegrp hasn't thread,
- * create an initial upcall thread to own it.
- */
- thread_schedule_upcall(td, newku);
- } else {
- /*
- * If current thread hasn't an upcall structure,
- * just assign the upcall to it.
- */
- if (td->td_upcall == NULL) {
- newku->ku_owner = td;
- td->td_upcall = newku;
- } else {
- /*
- * Create a new upcall thread to own it.
- */
- thread_schedule_upcall(td, newku);
- }
- }
- mtx_unlock_spin(&sched_lock);
- return (0);
-}
-
-/*
- * Fill a ucontext_t with a thread's context information.
- *
- * This is an analogue to getcontext(3).
- */
-void
-thread_getcontext(struct thread *td, ucontext_t *uc)
-{
-
- get_mcontext(td, &uc->uc_mcontext, 0);
- PROC_LOCK(td->td_proc);
- uc->uc_sigmask = td->td_sigmask;
- PROC_UNLOCK(td->td_proc);
-}
-
-/*
- * Set a thread's context from a ucontext_t.
- *
- * This is an analogue to setcontext(3).
- */
-int
-thread_setcontext(struct thread *td, ucontext_t *uc)
-{
- int ret;
-
- ret = set_mcontext(td, &uc->uc_mcontext);
- if (ret == 0) {
- SIG_CANTMASK(uc->uc_sigmask);
- PROC_LOCK(td->td_proc);
- td->td_sigmask = uc->uc_sigmask;
- PROC_UNLOCK(td->td_proc);
- }
- return (ret);
-}
-
-/*
- * Initialize global thread allocation resources.
- */
-void
-threadinit(void)
-{
-
-#ifndef __ia64__
- thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(),
- thread_ctor, thread_dtor, thread_init, thread_fini,
- UMA_ALIGN_CACHE, 0);
-#else
- /*
- * XXX the ia64 kstack allocator is really lame and is at the mercy
- * of contigmallloc(). This hackery is to pre-construct a whole
- * pile of thread structures with associated kernel stacks early
- * in the system startup while contigmalloc() still works. Once we
- * have them, keep them. Sigh.
- */
- thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(),
- thread_ctor, thread_dtor, thread_init, thread_fini,
- UMA_ALIGN_CACHE, UMA_ZONE_NOFREE);
- uma_prealloc(thread_zone, 512); /* XXX arbitary */
-#endif
- ksegrp_zone = uma_zcreate("KSEGRP", sched_sizeof_ksegrp(),
- NULL, NULL, ksegrp_init, NULL,
- UMA_ALIGN_CACHE, 0);
- kse_zone = uma_zcreate("KSE", sched_sizeof_kse(),
- NULL, NULL, kse_init, NULL,
- UMA_ALIGN_CACHE, 0);
- upcall_zone = uma_zcreate("UPCALL", sizeof(struct kse_upcall),
- NULL, NULL, NULL, NULL, UMA_ALIGN_CACHE, 0);
-}
-
-/*
- * Stash an embarasingly extra thread into the zombie thread queue.
- */
-void
-thread_stash(struct thread *td)
-{
- mtx_lock_spin(&kse_zombie_lock);
- TAILQ_INSERT_HEAD(&zombie_threads, td, td_runq);
- mtx_unlock_spin(&kse_zombie_lock);
-}
-
-/*
- * Stash an embarasingly extra kse into the zombie kse queue.
- */
-void
-kse_stash(struct kse *ke)
-{
- mtx_lock_spin(&kse_zombie_lock);
- TAILQ_INSERT_HEAD(&zombie_kses, ke, ke_procq);
- mtx_unlock_spin(&kse_zombie_lock);
-}
-
-/*
- * Stash an embarasingly extra upcall into the zombie upcall queue.
- */
-
-void
-upcall_stash(struct kse_upcall *ku)
-{
- mtx_lock_spin(&kse_zombie_lock);
- TAILQ_INSERT_HEAD(&zombie_upcalls, ku, ku_link);
- mtx_unlock_spin(&kse_zombie_lock);
-}
-
-/*
- * Stash an embarasingly extra ksegrp into the zombie ksegrp queue.
- */
-void
-ksegrp_stash(struct ksegrp *kg)
-{
- mtx_lock_spin(&kse_zombie_lock);
- TAILQ_INSERT_HEAD(&zombie_ksegrps, kg, kg_ksegrp);
- mtx_unlock_spin(&kse_zombie_lock);
-}
-
-/*
- * Reap zombie kse resource.
- */
-void
-thread_reap(void)
-{
- struct thread *td_first, *td_next;
- struct kse *ke_first, *ke_next;
- struct ksegrp *kg_first, * kg_next;
- struct kse_upcall *ku_first, *ku_next;
-
- /*
- * Don't even bother to lock if none at this instant,
- * we really don't care about the next instant..
- */
- if ((!TAILQ_EMPTY(&zombie_threads))
- || (!TAILQ_EMPTY(&zombie_kses))
- || (!TAILQ_EMPTY(&zombie_ksegrps))
- || (!TAILQ_EMPTY(&zombie_upcalls))) {
- mtx_lock_spin(&kse_zombie_lock);
- td_first = TAILQ_FIRST(&zombie_threads);
- ke_first = TAILQ_FIRST(&zombie_kses);
- kg_first = TAILQ_FIRST(&zombie_ksegrps);
- ku_first = TAILQ_FIRST(&zombie_upcalls);
- if (td_first)
- TAILQ_INIT(&zombie_threads);
- if (ke_first)
- TAILQ_INIT(&zombie_kses);
- if (kg_first)
- TAILQ_INIT(&zombie_ksegrps);
- if (ku_first)
- TAILQ_INIT(&zombie_upcalls);
- mtx_unlock_spin(&kse_zombie_lock);
- while (td_first) {
- td_next = TAILQ_NEXT(td_first, td_runq);
- if (td_first->td_ucred)
- crfree(td_first->td_ucred);
- thread_free(td_first);
- td_first = td_next;
- }
- while (ke_first) {
- ke_next = TAILQ_NEXT(ke_first, ke_procq);
- kse_free(ke_first);
- ke_first = ke_next;
- }
- while (kg_first) {
- kg_next = TAILQ_NEXT(kg_first, kg_ksegrp);
- ksegrp_free(kg_first);
- kg_first = kg_next;
- }
- while (ku_first) {
- ku_next = TAILQ_NEXT(ku_first, ku_link);
- upcall_free(ku_first);
- ku_first = ku_next;
- }
- }
-}
-
-/*
- * Allocate a ksegrp.
- */
-struct ksegrp *
-ksegrp_alloc(void)
-{
- return (uma_zalloc(ksegrp_zone, M_WAITOK));
-}
-
-/*
- * Allocate a kse.
- */
-struct kse *
-kse_alloc(void)
-{
- return (uma_zalloc(kse_zone, M_WAITOK));
-}
-
-/*
- * Allocate a thread.
- */
-struct thread *
-thread_alloc(void)
-{
- thread_reap(); /* check if any zombies to get */
- return (uma_zalloc(thread_zone, M_WAITOK));
-}
-
-/*
- * Deallocate a ksegrp.
- */
-void
-ksegrp_free(struct ksegrp *td)
-{
- uma_zfree(ksegrp_zone, td);
-}
-
-/*
- * Deallocate a kse.
- */
-void
-kse_free(struct kse *td)
-{
- uma_zfree(kse_zone, td);
-}
-
-/*
- * Deallocate a thread.
- */
-void
-thread_free(struct thread *td)
-{
-
- cpu_thread_clean(td);
- uma_zfree(thread_zone, td);
-}
-
-/*
- * Store the thread context in the UTS's mailbox.
- * then add the mailbox at the head of a list we are building in user space.
- * The list is anchored in the ksegrp structure.
- */
-int
-thread_export_context(struct thread *td)
-{
- struct proc *p;
- struct ksegrp *kg;
- uintptr_t mbx;
- void *addr;
- int error,temp;
- ucontext_t uc;
-
- p = td->td_proc;
- kg = td->td_ksegrp;
-
- /* Export the user/machine context. */
- addr = (void *)(&td->td_mailbox->tm_context);
- error = copyin(addr, &uc, sizeof(ucontext_t));
- if (error)
- goto bad;
-
- thread_getcontext(td, &uc);
- error = copyout(&uc, addr, sizeof(ucontext_t));
- if (error)
- goto bad;
-
- /* Exports clock ticks in kernel mode */
- addr = (caddr_t)(&td->td_mailbox->tm_sticks);
- temp = fuword(addr) + td->td_usticks;
- if (suword(addr, temp))
- goto bad;
-
- /* Get address in latest mbox of list pointer */
- addr = (void *)(&td->td_mailbox->tm_next);
- /*
- * Put the saved address of the previous first
- * entry into this one
- */
- for (;;) {
- mbx = (uintptr_t)kg->kg_completed;
- if (suword(addr, mbx)) {
- error = EFAULT;
- goto bad;
- }
- PROC_LOCK(p);
- if (mbx == (uintptr_t)kg->kg_completed) {
- kg->kg_completed = td->td_mailbox;
- /*
- * The thread context may be taken away by
- * other upcall threads when we unlock
- * process lock. it's no longer valid to
- * use it again in any other places.
- */
- td->td_mailbox = NULL;
- PROC_UNLOCK(p);
- break;
- }
- PROC_UNLOCK(p);
- }
- td->td_usticks = 0;
- return (0);
-
-bad:
- PROC_LOCK(p);
- psignal(p, SIGSEGV);
- PROC_UNLOCK(p);
- /* The mailbox is bad, don't use it */
- td->td_mailbox = NULL;
- td->td_usticks = 0;
- return (error);
-}
-
-/*
- * Take the list of completed mailboxes for this KSEGRP and put them on this
- * upcall's mailbox as it's the next one going up.
- */
-static int
-thread_link_mboxes(struct ksegrp *kg, struct kse_upcall *ku)
-{
- struct proc *p = kg->kg_proc;
- void *addr;
- uintptr_t mbx;
-
- addr = (void *)(&ku->ku_mailbox->km_completed);
- for (;;) {
- mbx = (uintptr_t)kg->kg_completed;
- if (suword(addr, mbx)) {
- PROC_LOCK(p);
- psignal(p, SIGSEGV);
- PROC_UNLOCK(p);
- return (EFAULT);
- }
- PROC_LOCK(p);
- if (mbx == (uintptr_t)kg->kg_completed) {
- kg->kg_completed = NULL;
- PROC_UNLOCK(p);
- break;
- }
- PROC_UNLOCK(p);
- }
- return (0);
-}
-
-/*
- * This function should be called at statclock interrupt time
- */
-int
-thread_statclock(int user)
-{
- struct thread *td = curthread;
-
- if (td->td_ksegrp->kg_numupcalls == 0)
- return (-1);
- if (user) {
- /* Current always do via ast() */
- mtx_lock_spin(&sched_lock);
- td->td_flags |= (TDF_USTATCLOCK|TDF_ASTPENDING);
- mtx_unlock_spin(&sched_lock);
- td->td_uuticks++;
- } else {
- if (td->td_mailbox != NULL)
- td->td_usticks++;
- else {
- /* XXXKSE
- * We will call thread_user_enter() for every
- * kernel entry in future, so if the thread mailbox
- * is NULL, it must be a UTS kernel, don't account
- * clock ticks for it.
- */
- }
- }
- return (0);
-}
-
-/*
- * Export state clock ticks for userland
- */
-static int
-thread_update_usr_ticks(struct thread *td, int user)
-{
- struct proc *p = td->td_proc;
- struct kse_thr_mailbox *tmbx;
- struct kse_upcall *ku;
- struct ksegrp *kg;
- caddr_t addr;
- uint uticks;
-
- if ((ku = td->td_upcall) == NULL)
- return (-1);
-
- tmbx = (void *)fuword((void *)&ku->ku_mailbox->km_curthread);
- if ((tmbx == NULL) || (tmbx == (void *)-1))
- return (-1);
- if (user) {
- uticks = td->td_uuticks;
- td->td_uuticks = 0;
- addr = (caddr_t)&tmbx->tm_uticks;
- } else {
- uticks = td->td_usticks;
- td->td_usticks = 0;
- addr = (caddr_t)&tmbx->tm_sticks;
- }
- if (uticks) {
- if (suword(addr, uticks+fuword(addr))) {
- PROC_LOCK(p);
- psignal(p, SIGSEGV);
- PROC_UNLOCK(p);
- return (-2);
- }
- }
- kg = td->td_ksegrp;
- if (kg->kg_upquantum && ticks >= kg->kg_nextupcall) {
- mtx_lock_spin(&sched_lock);
- td->td_upcall->ku_flags |= KUF_DOUPCALL;
- mtx_unlock_spin(&sched_lock);
- }
- return (0);
-}
-
-/*
- * Discard the current thread and exit from its context.
- *
- * Because we can't free a thread while we're operating under its context,
- * push the current thread into our CPU's deadthread holder. This means
- * we needn't worry about someone else grabbing our context before we
- * do a cpu_throw().
- */
-void
-thread_exit(void)
-{
- struct thread *td;
- struct kse *ke;
- struct proc *p;
- struct ksegrp *kg;
-
- td = curthread;
- kg = td->td_ksegrp;
- p = td->td_proc;
- ke = td->td_kse;
-
- mtx_assert(&sched_lock, MA_OWNED);
- KASSERT(p != NULL, ("thread exiting without a process"));
- KASSERT(ke != NULL, ("thread exiting without a kse"));
- KASSERT(kg != NULL, ("thread exiting without a kse group"));
- PROC_LOCK_ASSERT(p, MA_OWNED);
- CTR1(KTR_PROC, "thread_exit: thread %p", td);
- KASSERT(!mtx_owned(&Giant), ("dying thread owns giant"));
-
- if (td->td_standin != NULL) {
- thread_stash(td->td_standin);
- td->td_standin = NULL;
- }
-
- cpu_thread_exit(td); /* XXXSMP */
-
- /*
- * The last thread is left attached to the process
- * So that the whole bundle gets recycled. Skip
- * all this stuff.
- */
- if (p->p_numthreads > 1) {
- thread_unlink(td);
- if (p->p_maxthrwaits)
- wakeup(&p->p_numthreads);
- /*
- * The test below is NOT true if we are the
- * sole exiting thread. P_STOPPED_SNGL is unset
- * in exit1() after it is the only survivor.
- */
- if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) {
- if (p->p_numthreads == p->p_suspcount) {
- thread_unsuspend_one(p->p_singlethread);
- }
- }
-
- /*
- * Because each upcall structure has an owner thread,
- * owner thread exits only when process is in exiting
- * state, so upcall to userland is no longer needed,
- * deleting upcall structure is safe here.
- * So when all threads in a group is exited, all upcalls
- * in the group should be automatically freed.
- */
- if (td->td_upcall)
- upcall_remove(td);
-
- ke->ke_state = KES_UNQUEUED;
- ke->ke_thread = NULL;
- /*
- * Decide what to do with the KSE attached to this thread.
- */
- if (ke->ke_flags & KEF_EXIT)
- kse_unlink(ke);
- else
- kse_reassign(ke);
- PROC_UNLOCK(p);
- td->td_kse = NULL;
- td->td_state = TDS_INACTIVE;
-#if 0
- td->td_proc = NULL;
-#endif
- td->td_ksegrp = NULL;
- td->td_last_kse = NULL;
- PCPU_SET(deadthread, td);
- } else {
- PROC_UNLOCK(p);
- }
- /* XXX Shouldn't cpu_throw() here. */
- mtx_assert(&sched_lock, MA_OWNED);
-#if !defined(__alpha__) && !defined(__powerpc__)
- cpu_throw(td, choosethread());
-#else
- cpu_throw();
-#endif
- panic("I'm a teapot!");
- /* NOTREACHED */
-}
-
-/*
- * Do any thread specific cleanups that may be needed in wait()
- * called with Giant held, proc and schedlock not held.
- */
-void
-thread_wait(struct proc *p)
-{
- struct thread *td;
-
- KASSERT((p->p_numthreads == 1), ("Muliple threads in wait1()"));
- KASSERT((p->p_numksegrps == 1), ("Muliple ksegrps in wait1()"));
- FOREACH_THREAD_IN_PROC(p, td) {
- if (td->td_standin != NULL) {
- thread_free(td->td_standin);
- td->td_standin = NULL;
- }
- cpu_thread_clean(td);
- }
- thread_reap(); /* check for zombie threads etc. */
-}
-
-/*
- * Link a thread to a process.
- * set up anything that needs to be initialized for it to
- * be used by the process.
- *
- * Note that we do not link to the proc's ucred here.
- * The thread is linked as if running but no KSE assigned.
- */
-void
-thread_link(struct thread *td, struct ksegrp *kg)
-{
- struct proc *p;
-
- p = kg->kg_proc;
- td->td_state = TDS_INACTIVE;
- td->td_proc = p;
- td->td_ksegrp = kg;
- td->td_last_kse = NULL;
- td->td_flags = 0;
- td->td_kse = NULL;
-
- LIST_INIT(&td->td_contested);
- callout_init(&td->td_slpcallout, 1);
- TAILQ_INSERT_HEAD(&p->p_threads, td, td_plist);
- TAILQ_INSERT_HEAD(&kg->kg_threads, td, td_kglist);
- p->p_numthreads++;
- kg->kg_numthreads++;
-}
-
-void
-thread_unlink(struct thread *td)
-{
- struct proc *p = td->td_proc;
- struct ksegrp *kg = td->td_ksegrp;
-
- mtx_assert(&sched_lock, MA_OWNED);
- TAILQ_REMOVE(&p->p_threads, td, td_plist);
- p->p_numthreads--;
- TAILQ_REMOVE(&kg->kg_threads, td, td_kglist);
- kg->kg_numthreads--;
- /* could clear a few other things here */
-}
-
-/*
- * Purge a ksegrp resource. When a ksegrp is preparing to
- * exit, it calls this function.
- */
-static void
-kse_purge_group(struct thread *td)
-{
- struct ksegrp *kg;
- struct kse *ke;
-
- kg = td->td_ksegrp;
- KASSERT(kg->kg_numthreads == 1, ("%s: bad thread number", __func__));
- while ((ke = TAILQ_FIRST(&kg->kg_iq)) != NULL) {
- KASSERT(ke->ke_state == KES_IDLE,
- ("%s: wrong idle KSE state", __func__));
- kse_unlink(ke);
- }
- KASSERT((kg->kg_kses == 1),
- ("%s: ksegrp still has %d KSEs", __func__, kg->kg_kses));
- KASSERT((kg->kg_numupcalls == 0),
- ("%s: ksegrp still has %d upcall datas",
- __func__, kg->kg_numupcalls));
-}
-
-/*
- * Purge a process's KSE resource. When a process is preparing to
- * exit, it calls kse_purge to release any extra KSE resources in
- * the process.
- */
-static void
-kse_purge(struct proc *p, struct thread *td)
-{
- struct ksegrp *kg;
- struct kse *ke;
-
- KASSERT(p->p_numthreads == 1, ("bad thread number"));
- while ((kg = TAILQ_FIRST(&p->p_ksegrps)) != NULL) {
- TAILQ_REMOVE(&p->p_ksegrps, kg, kg_ksegrp);
- p->p_numksegrps--;
- /*
- * There is no ownership for KSE, after all threads
- * in the group exited, it is possible that some KSEs
- * were left in idle queue, gc them now.
- */
- while ((ke = TAILQ_FIRST(&kg->kg_iq)) != NULL) {
- KASSERT(ke->ke_state == KES_IDLE,
- ("%s: wrong idle KSE state", __func__));
- TAILQ_REMOVE(&kg->kg_iq, ke, ke_kgrlist);
- kg->kg_idle_kses--;
- TAILQ_REMOVE(&kg->kg_kseq, ke, ke_kglist);
- kg->kg_kses--;
- kse_stash(ke);
- }
- KASSERT(((kg->kg_kses == 0) && (kg != td->td_ksegrp)) ||
- ((kg->kg_kses == 1) && (kg == td->td_ksegrp)),
- ("ksegrp has wrong kg_kses: %d", kg->kg_kses));
- KASSERT((kg->kg_numupcalls == 0),
- ("%s: ksegrp still has %d upcall datas",
- __func__, kg->kg_numupcalls));
-
- if (kg != td->td_ksegrp)
- ksegrp_stash(kg);
- }
- TAILQ_INSERT_HEAD(&p->p_ksegrps, td->td_ksegrp, kg_ksegrp);
- p->p_numksegrps++;
-}
-
-/*
- * This function is intended to be used to initialize a spare thread
- * for upcall. Initialize thread's large data area outside sched_lock
- * for thread_schedule_upcall().
- */
-void
-thread_alloc_spare(struct thread *td, struct thread *spare)
-{
- if (td->td_standin)
- return;
- if (spare == NULL)
- spare = thread_alloc();
- td->td_standin = spare;
- bzero(&spare->td_startzero,
- (unsigned)RANGEOF(struct thread, td_startzero, td_endzero));
- spare->td_proc = td->td_proc;
- spare->td_ucred = crhold(td->td_ucred);
-}
-
-/*
- * Create a thread and schedule it for upcall on the KSE given.
- * Use our thread's standin so that we don't have to allocate one.
- */
-struct thread *
-thread_schedule_upcall(struct thread *td, struct kse_upcall *ku)
-{
- struct thread *td2;
-
- mtx_assert(&sched_lock, MA_OWNED);
-
- /*
- * Schedule an upcall thread on specified kse_upcall,
- * the kse_upcall must be free.
- * td must have a spare thread.
- */
- KASSERT(ku->ku_owner == NULL, ("%s: upcall has owner", __func__));
- if ((td2 = td->td_standin) != NULL) {
- td->td_standin = NULL;
- } else {
- panic("no reserve thread when scheduling an upcall");
- return (NULL);
- }
- CTR3(KTR_PROC, "thread_schedule_upcall: thread %p (pid %d, %s)",
- td2, td->td_proc->p_pid, td->td_proc->p_comm);
- bcopy(&td->td_startcopy, &td2->td_startcopy,
- (unsigned) RANGEOF(struct thread, td_startcopy, td_endcopy));
- thread_link(td2, ku->ku_ksegrp);
- /* inherit blocked thread's context */
- bcopy(td->td_frame, td2->td_frame, sizeof(struct trapframe));
- cpu_set_upcall(td2, td->td_pcb);
- /* Let the new thread become owner of the upcall */
- ku->ku_owner = td2;
- td2->td_upcall = ku;
- td2->td_flags = TDF_UPCALLING;
-#if 0 /* XXX This shouldn't be necessary */
- if (td->td_proc->p_sflag & PS_NEEDSIGCHK)
- td2->td_flags |= TDF_ASTPENDING;
-#endif
- td2->td_kse = NULL;
- td2->td_state = TDS_CAN_RUN;
- td2->td_inhibitors = 0;
- setrunqueue(td2);
- return (td2); /* bogus.. should be a void function */
-}
-
-void
-thread_signal_add(struct thread *td, int sig)
-{
- struct kse_upcall *ku;
- struct proc *p;
- sigset_t ss;
- int error;
-
- PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
- td = curthread;
- ku = td->td_upcall;
- p = td->td_proc;
-
- PROC_UNLOCK(p);
- error = copyin(&ku->ku_mailbox->km_sigscaught, &ss, sizeof(sigset_t));
- if (error)
- goto error;
-
- SIGADDSET(ss, sig);
-
- error = copyout(&ss, &ku->ku_mailbox->km_sigscaught, sizeof(sigset_t));
- if (error)
- goto error;
-
- PROC_LOCK(p);
- return;
-error:
- PROC_LOCK(p);
- sigexit(td, SIGILL);
-}
-
-
-/*
- * Schedule an upcall to notify a KSE process recieved signals.
- *
- */
-void
-thread_signal_upcall(struct thread *td)
-{
- mtx_lock_spin(&sched_lock);
- td->td_flags |= TDF_UPCALLING;
- mtx_unlock_spin(&sched_lock);
-
- return;
-}
-
-void
-thread_switchout(struct thread *td)
-{
- struct kse_upcall *ku;
-
- mtx_assert(&sched_lock, MA_OWNED);
-
- /*
- * If the outgoing thread is in threaded group and has never
- * scheduled an upcall, decide whether this is a short
- * or long term event and thus whether or not to schedule
- * an upcall.
- * If it is a short term event, just suspend it in
- * a way that takes its KSE with it.
- * Select the events for which we want to schedule upcalls.
- * For now it's just sleep.
- * XXXKSE eventually almost any inhibition could do.
- */
- if (TD_CAN_UNBIND(td) && (td->td_standin) && TD_ON_SLEEPQ(td)) {
- /*
- * Release ownership of upcall, and schedule an upcall
- * thread, this new upcall thread becomes the owner of
- * the upcall structure.
- */
- ku = td->td_upcall;
- ku->ku_owner = NULL;
- td->td_upcall = NULL;
- td->td_flags &= ~TDF_CAN_UNBIND;
- thread_schedule_upcall(td, ku);
- }
-}
-
-/*
- * Setup done on the thread when it enters the kernel.
- * XXXKSE Presently only for syscalls but eventually all kernel entries.
- */
-void
-thread_user_enter(struct proc *p, struct thread *td)
-{
- struct ksegrp *kg;
- struct kse_upcall *ku;
- struct kse_thr_mailbox *tmbx;
-
- kg = td->td_ksegrp;
-
- /*
- * First check that we shouldn't just abort.
- * But check if we are the single thread first!
- */
- PROC_LOCK(p);
- if ((p->p_flag & P_SINGLE_EXIT) && (p->p_singlethread != td)) {
- mtx_lock_spin(&sched_lock);
- thread_stopped(p);
- thread_exit();
- /* NOTREACHED */
- }
- PROC_UNLOCK(p);
-
- /*
- * If we are doing a syscall in a KSE environment,
- * note where our mailbox is. There is always the
- * possibility that we could do this lazily (in kse_reassign()),
- * but for now do it every time.
- */
- kg = td->td_ksegrp;
- if (kg->kg_numupcalls) {
- ku = td->td_upcall;
- KASSERT(ku, ("%s: no upcall owned", __func__));
- KASSERT((ku->ku_owner == td), ("%s: wrong owner", __func__));
- KASSERT(!TD_CAN_UNBIND(td), ("%s: can unbind", __func__));
- ku->ku_mflags = fuword((void *)&ku->ku_mailbox->km_flags);
- tmbx = (void *)fuword((void *)&ku->ku_mailbox->km_curthread);
- if ((tmbx == NULL) || (tmbx == (void *)-1)) {
- td->td_mailbox = NULL;
- } else {
- td->td_mailbox = tmbx;
- if (td->td_standin == NULL)
- thread_alloc_spare(td, NULL);
- mtx_lock_spin(&sched_lock);
- if (ku->ku_mflags & KMF_NOUPCALL)
- td->td_flags &= ~TDF_CAN_UNBIND;
- else
- td->td_flags |= TDF_CAN_UNBIND;
- mtx_unlock_spin(&sched_lock);
- }
- }
-}
-
-/*
- * The extra work we go through if we are a threaded process when we
- * return to userland.
- *
- * If we are a KSE process and returning to user mode, check for
- * extra work to do before we return (e.g. for more syscalls
- * to complete first). If we were in a critical section, we should
- * just return to let it finish. Same if we were in the UTS (in
- * which case the mailbox's context's busy indicator will be set).
- * The only traps we suport will have set the mailbox.
- * We will clear it here.
- */
-int
-thread_userret(struct thread *td, struct trapframe *frame)
-{
- int error = 0, upcalls, uts_crit;
- struct kse_upcall *ku;
- struct ksegrp *kg, *kg2;
- struct proc *p;
- struct timespec ts;
-
- p = td->td_proc;
- kg = td->td_ksegrp;
-
- /* Nothing to do with non-threaded group/process */
- if (td->td_ksegrp->kg_numupcalls == 0)
- return (0);
-
- /*
- * Stat clock interrupt hit in userland, it
- * is returning from interrupt, charge thread's
- * userland time for UTS.
- */
- if (td->td_flags & TDF_USTATCLOCK) {
- thread_update_usr_ticks(td, 1);
- mtx_lock_spin(&sched_lock);
- td->td_flags &= ~TDF_USTATCLOCK;
- mtx_unlock_spin(&sched_lock);
- if (kg->kg_completed ||
- (td->td_upcall->ku_flags & KUF_DOUPCALL))
- thread_user_enter(p, td);
- }
-
- uts_crit = (td->td_mailbox == NULL);
- ku = td->td_upcall;
- /*
- * Optimisation:
- * This thread has not started any upcall.
- * If there is no work to report other than ourself,
- * then it can return direct to userland.
- */
- if (TD_CAN_UNBIND(td)) {
- mtx_lock_spin(&sched_lock);
- td->td_flags &= ~TDF_CAN_UNBIND;
- if ((td->td_flags & TDF_NEEDSIGCHK) == 0 &&
- (kg->kg_completed == NULL) &&
- (ku->ku_flags & KUF_DOUPCALL) == 0 &&
- (kg->kg_upquantum && ticks < kg->kg_nextupcall)) {
- mtx_unlock_spin(&sched_lock);
- thread_update_usr_ticks(td, 0);
- nanotime(&ts);
- error = copyout(&ts,
- (caddr_t)&ku->ku_mailbox->km_timeofday,
- sizeof(ts));
- td->td_mailbox = 0;
- ku->ku_mflags = 0;
- if (error)
- goto out;
- return (0);
- }
- mtx_unlock_spin(&sched_lock);
- error = thread_export_context(td);
- if (error) {
- /*
- * Failing to do the KSE operation just defaults
- * back to synchonous operation, so just return from
- * the syscall.
- */
- goto out;
- }
- /*
- * There is something to report, and we own an upcall
- * strucuture, we can go to userland.
- * Turn ourself into an upcall thread.
- */
- mtx_lock_spin(&sched_lock);
- td->td_flags |= TDF_UPCALLING;
- mtx_unlock_spin(&sched_lock);
- } else if (td->td_mailbox && (ku == NULL)) {
- error = thread_export_context(td);
- /* possibly upcall with error? */
- PROC_LOCK(p);
- /*
- * There are upcall threads waiting for
- * work to do, wake one of them up.
- * XXXKSE Maybe wake all of them up.
- */
- if (!error && kg->kg_upsleeps)
- wakeup_one(&kg->kg_completed);
- mtx_lock_spin(&sched_lock);
- thread_stopped(p);
- thread_exit();
- /* NOTREACHED */
- }
-
- KASSERT(TD_CAN_UNBIND(td) == 0, ("can unbind"));
-
- if (p->p_numthreads > max_threads_per_proc) {
- max_threads_hits++;
- PROC_LOCK(p);
- mtx_lock_spin(&sched_lock);
- while (p->p_numthreads > max_threads_per_proc) {
- if (P_SHOULDSTOP(p))
- break;
- upcalls = 0;
- FOREACH_KSEGRP_IN_PROC(p, kg2) {
- if (kg2->kg_numupcalls == 0)
- upcalls++;
- else
- upcalls += kg2->kg_numupcalls;
- }
- if (upcalls >= max_threads_per_proc)
- break;
- mtx_unlock_spin(&sched_lock);
- p->p_maxthrwaits++;
- msleep(&p->p_numthreads, &p->p_mtx, PPAUSE|PCATCH,
- "maxthreads", NULL);
- p->p_maxthrwaits--;
- mtx_lock_spin(&sched_lock);
- }
- mtx_unlock_spin(&sched_lock);
- PROC_UNLOCK(p);
- }
-
- if (td->td_flags & TDF_UPCALLING) {
- uts_crit = 0;
- kg->kg_nextupcall = ticks+kg->kg_upquantum;
- /*
- * There is no more work to do and we are going to ride
- * this thread up to userland as an upcall.
- * Do the last parts of the setup needed for the upcall.
- */
- CTR3(KTR_PROC, "userret: upcall thread %p (pid %d, %s)",
- td, td->td_proc->p_pid, td->td_proc->p_comm);
-
- mtx_lock_spin(&sched_lock);
- td->td_flags &= ~TDF_UPCALLING;
- if (ku->ku_flags & KUF_DOUPCALL)
- ku->ku_flags &= ~KUF_DOUPCALL;
- mtx_unlock_spin(&sched_lock);
-
- /*
- * Set user context to the UTS
- */
- if (!(ku->ku_mflags & KMF_NOUPCALL)) {
- cpu_set_upcall_kse(td, ku);
- error = suword(&ku->ku_mailbox->km_curthread, 0);
- if (error)
- goto out;
- }
-
- /*
- * Unhook the list of completed threads.
- * anything that completes after this gets to
- * come in next time.
- * Put the list of completed thread mailboxes on
- * this KSE's mailbox.
- */
- if (!(ku->ku_mflags & KMF_NOCOMPLETED) &&
- (error = thread_link_mboxes(kg, ku)) != 0)
- goto out;
- }
- if (!uts_crit) {
- nanotime(&ts);
- error = copyout(&ts, &ku->ku_mailbox->km_timeofday, sizeof(ts));
- }
-
-out:
- if (error) {
- /*
- * Things are going to be so screwed we should just kill
- * the process.
- * how do we do that?
- */
- PROC_LOCK(td->td_proc);
- psignal(td->td_proc, SIGSEGV);
- PROC_UNLOCK(td->td_proc);
- } else {
- /*
- * Optimisation:
- * Ensure that we have a spare thread available,
- * for when we re-enter the kernel.
- */
- if (td->td_standin == NULL)
- thread_alloc_spare(td, NULL);
- }
-
- ku->ku_mflags = 0;
- /*
- * Clear thread mailbox first, then clear system tick count.
- * The order is important because thread_statclock() use
- * mailbox pointer to see if it is an userland thread or
- * an UTS kernel thread.
- */
- td->td_mailbox = NULL;
- td->td_usticks = 0;
- return (error); /* go sync */
-}
-
-/*
- * Enforce single-threading.
- *
- * Returns 1 if the caller must abort (another thread is waiting to
- * exit the process or similar). Process is locked!
- * Returns 0 when you are successfully the only thread running.
- * A process has successfully single threaded in the suspend mode when
- * There are no threads in user mode. Threads in the kernel must be
- * allowed to continue until they get to the user boundary. They may even
- * copy out their return values and data before suspending. They may however be
- * accellerated in reaching the user boundary as we will wake up
- * any sleeping threads that are interruptable. (PCATCH).
- */
-int
-thread_single(int force_exit)
-{
- struct thread *td;
- struct thread *td2;
- struct proc *p;
-
- td = curthread;
- p = td->td_proc;
- mtx_assert(&Giant, MA_OWNED);
- PROC_LOCK_ASSERT(p, MA_OWNED);
- KASSERT((td != NULL), ("curthread is NULL"));
-
- if ((p->p_flag & P_THREADED) == 0 && p->p_numthreads == 1)
- return (0);
-
- /* Is someone already single threading? */
- if (p->p_singlethread)
- return (1);
-
- if (force_exit == SINGLE_EXIT) {
- p->p_flag |= P_SINGLE_EXIT;
- } else
- p->p_flag &= ~P_SINGLE_EXIT;
- p->p_flag |= P_STOPPED_SINGLE;
- mtx_lock_spin(&sched_lock);
- p->p_singlethread = td;
- while ((p->p_numthreads - p->p_suspcount) != 1) {
- FOREACH_THREAD_IN_PROC(p, td2) {
- if (td2 == td)
- continue;
- td2->td_flags |= TDF_ASTPENDING;
- if (TD_IS_INHIBITED(td2)) {
- if (force_exit == SINGLE_EXIT) {
- if (TD_IS_SUSPENDED(td2)) {
- thread_unsuspend_one(td2);
- }
- if (TD_ON_SLEEPQ(td2) &&
- (td2->td_flags & TDF_SINTR)) {
- if (td2->td_flags & TDF_CVWAITQ)
- cv_abort(td2);
- else
- abortsleep(td2);
- }
- } else {
- if (TD_IS_SUSPENDED(td2))
- continue;
- /*
- * maybe other inhibitted states too?
- * XXXKSE Is it totally safe to
- * suspend a non-interruptable thread?
- */
- if (td2->td_inhibitors &
- (TDI_SLEEPING | TDI_SWAPPED))
- thread_suspend_one(td2);
- }
- }
- }
- /*
- * Maybe we suspended some threads.. was it enough?
- */
- if ((p->p_numthreads - p->p_suspcount) == 1)
- break;
-
- /*
- * Wake us up when everyone else has suspended.
- * In the mean time we suspend as well.
- */
- thread_suspend_one(td);
- DROP_GIANT();
- PROC_UNLOCK(p);
- p->p_stats->p_ru.ru_nvcsw++;
- mi_switch();
- mtx_unlock_spin(&sched_lock);
- PICKUP_GIANT();
- PROC_LOCK(p);
- mtx_lock_spin(&sched_lock);
- }
- if (force_exit == SINGLE_EXIT) {
- if (td->td_upcall)
- upcall_remove(td);
- kse_purge(p, td);
- }
- mtx_unlock_spin(&sched_lock);
- return (0);
-}
-
-/*
- * Called in from locations that can safely check to see
- * whether we have to suspend or at least throttle for a
- * single-thread event (e.g. fork).
- *
- * Such locations include userret().
- * If the "return_instead" argument is non zero, the thread must be able to
- * accept 0 (caller may continue), or 1 (caller must abort) as a result.
- *
- * The 'return_instead' argument tells the function if it may do a
- * thread_exit() or suspend, or whether the caller must abort and back
- * out instead.
- *
- * If the thread that set the single_threading request has set the
- * P_SINGLE_EXIT bit in the process flags then this call will never return
- * if 'return_instead' is false, but will exit.
- *
- * P_SINGLE_EXIT | return_instead == 0| return_instead != 0
- *---------------+--------------------+---------------------
- * 0 | returns 0 | returns 0 or 1
- * | when ST ends | immediatly
- *---------------+--------------------+---------------------
- * 1 | thread exits | returns 1
- * | | immediatly
- * 0 = thread_exit() or suspension ok,
- * other = return error instead of stopping the thread.
- *
- * While a full suspension is under effect, even a single threading
- * thread would be suspended if it made this call (but it shouldn't).
- * This call should only be made from places where
- * thread_exit() would be safe as that may be the outcome unless
- * return_instead is set.
- */
-int
-thread_suspend_check(int return_instead)
-{
- struct thread *td;
- struct proc *p;
- struct ksegrp *kg;
-
- td = curthread;
- p = td->td_proc;
- kg = td->td_ksegrp;
- PROC_LOCK_ASSERT(p, MA_OWNED);
- while (P_SHOULDSTOP(p)) {
- if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) {
- KASSERT(p->p_singlethread != NULL,
- ("singlethread not set"));
- /*
- * The only suspension in action is a
- * single-threading. Single threader need not stop.
- * XXX Should be safe to access unlocked
- * as it can only be set to be true by us.
- */
- if (p->p_singlethread == td)
- return (0); /* Exempt from stopping. */
- }
- if (return_instead)
- return (1);
-
- mtx_lock_spin(&sched_lock);
- thread_stopped(p);
- /*
- * If the process is waiting for us to exit,
- * this thread should just suicide.
- * Assumes that P_SINGLE_EXIT implies P_STOPPED_SINGLE.
- */
- if ((p->p_flag & P_SINGLE_EXIT) && (p->p_singlethread != td)) {
- while (mtx_owned(&Giant))
- mtx_unlock(&Giant);
- if (p->p_flag & P_THREADED)
- thread_exit();
- else
- thr_exit1();
- }
-
- /*
- * When a thread suspends, it just
- * moves to the processes's suspend queue
- * and stays there.
- */
- thread_suspend_one(td);
- if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) {
- if (p->p_numthreads == p->p_suspcount) {
- thread_unsuspend_one(p->p_singlethread);
- }
- }
- DROP_GIANT();
- PROC_UNLOCK(p);
- p->p_stats->p_ru.ru_nivcsw++;
- mi_switch();
- mtx_unlock_spin(&sched_lock);
- PICKUP_GIANT();
- PROC_LOCK(p);
- }
- return (0);
-}
-
-void
-thread_suspend_one(struct thread *td)
-{
- struct proc *p = td->td_proc;
-
- mtx_assert(&sched_lock, MA_OWNED);
- PROC_LOCK_ASSERT(p, MA_OWNED);
- KASSERT(!TD_IS_SUSPENDED(td), ("already suspended"));
- p->p_suspcount++;
- TD_SET_SUSPENDED(td);
- TAILQ_INSERT_TAIL(&p->p_suspended, td, td_runq);
- /*
- * Hack: If we are suspending but are on the sleep queue
- * then we are in msleep or the cv equivalent. We
- * want to look like we have two Inhibitors.
- * May already be set.. doesn't matter.
- */
- if (TD_ON_SLEEPQ(td))
- TD_SET_SLEEPING(td);
-}
-
-void
-thread_unsuspend_one(struct thread *td)
-{
- struct proc *p = td->td_proc;
-
- mtx_assert(&sched_lock, MA_OWNED);
- PROC_LOCK_ASSERT(p, MA_OWNED);
- TAILQ_REMOVE(&p->p_suspended, td, td_runq);
- TD_CLR_SUSPENDED(td);
- p->p_suspcount--;
- setrunnable(td);
-}
-
-/*
- * Allow all threads blocked by single threading to continue running.
- */
-void
-thread_unsuspend(struct proc *p)
-{
- struct thread *td;
-
- mtx_assert(&sched_lock, MA_OWNED);
- PROC_LOCK_ASSERT(p, MA_OWNED);
- if (!P_SHOULDSTOP(p)) {
- while (( td = TAILQ_FIRST(&p->p_suspended))) {
- thread_unsuspend_one(td);
- }
- } else if ((P_SHOULDSTOP(p) == P_STOPPED_SINGLE) &&
- (p->p_numthreads == p->p_suspcount)) {
- /*
- * Stopping everything also did the job for the single
- * threading request. Now we've downgraded to single-threaded,
- * let it continue.
- */
- thread_unsuspend_one(p->p_singlethread);
- }
-}
-
-void
-thread_single_end(void)
-{
- struct thread *td;
- struct proc *p;
-
- td = curthread;
- p = td->td_proc;
- PROC_LOCK_ASSERT(p, MA_OWNED);
- p->p_flag &= ~P_STOPPED_SINGLE;
- mtx_lock_spin(&sched_lock);
- p->p_singlethread = NULL;
- /*
- * If there are other threads they mey now run,
- * unless of course there is a blanket 'stop order'
- * on the process. The single threader must be allowed
- * to continue however as this is a bad place to stop.
- */
- if ((p->p_numthreads != 1) && (!P_SHOULDSTOP(p))) {
- while (( td = TAILQ_FIRST(&p->p_suspended))) {
- thread_unsuspend_one(td);
- }
- }
- mtx_unlock_spin(&sched_lock);
-}
-
-
diff --git a/sys/kern/ksched.c b/sys/kern/ksched.c
deleted file mode 100644
index b51b314d72c5..000000000000
--- a/sys/kern/ksched.c
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * Copyright (c) 1996, 1997
- * HD Associates, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by HD Associates, Inc
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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$
- */
-
-/* ksched: Soft real time scheduling based on "rtprio".
- */
-
-#include "opt_posix.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/resource.h>
-#include <sys/sched.h>
-
-#include <posix4/posix4.h>
-
-/* ksched: Real-time extension to support POSIX priority scheduling.
- */
-
-struct ksched {
- struct timespec rr_interval;
-};
-
-int ksched_attach(struct ksched **p)
-{
- struct ksched *ksched= p31b_malloc(sizeof(*ksched));
-
- ksched->rr_interval.tv_sec = 0;
- ksched->rr_interval.tv_nsec = 1000000000L / sched_rr_interval();
-
- *p = ksched;
- return 0;
-}
-
-int ksched_detach(struct ksched *ks)
-{
- p31b_free(ks);
-
- return 0;
-}
-
-/*
- * XXX About priorities
- *
- * POSIX 1003.1b requires that numerically higher priorities be of
- * higher priority. It also permits sched_setparam to be
- * implementation defined for SCHED_OTHER. I don't like
- * the notion of inverted priorites for normal processes when
- * you can use "setpriority" for that.
- *
- * I'm rejecting sched_setparam for SCHED_OTHER with EINVAL.
- */
-
-/* Macros to convert between the unix (lower numerically is higher priority)
- * and POSIX 1003.1b (higher numerically is higher priority)
- */
-
-#define p4prio_to_rtpprio(P) (RTP_PRIO_MAX - (P))
-#define rtpprio_to_p4prio(P) (RTP_PRIO_MAX - (P))
-
-/* These improve readability a bit for me:
- */
-#define P1B_PRIO_MIN rtpprio_to_p4prio(RTP_PRIO_MAX)
-#define P1B_PRIO_MAX rtpprio_to_p4prio(RTP_PRIO_MIN)
-
-static __inline int
-getscheduler(register_t *ret, struct ksched *ksched, struct thread *td)
-{
- struct rtprio rtp;
- int e = 0;
-
- mtx_lock_spin(&sched_lock);
- pri_to_rtp(td->td_ksegrp, &rtp);
- mtx_unlock_spin(&sched_lock);
- switch (rtp.type)
- {
- case RTP_PRIO_FIFO:
- *ret = SCHED_FIFO;
- break;
-
- case RTP_PRIO_REALTIME:
- *ret = SCHED_RR;
- break;
-
- default:
- *ret = SCHED_OTHER;
- break;
- }
-
- return e;
-}
-
-int ksched_setparam(register_t *ret, struct ksched *ksched,
- struct thread *td, const struct sched_param *param)
-{
- register_t policy;
- int e;
-
- e = getscheduler(&policy, ksched, td);
-
- if (e == 0)
- {
- if (policy == SCHED_OTHER)
- e = EINVAL;
- else
- e = ksched_setscheduler(ret, ksched, td, policy, param);
- }
-
- return e;
-}
-
-int ksched_getparam(register_t *ret, struct ksched *ksched,
- struct thread *td, struct sched_param *param)
-{
- struct rtprio rtp;
-
- mtx_lock_spin(&sched_lock);
- pri_to_rtp(td->td_ksegrp, &rtp);
- mtx_unlock_spin(&sched_lock);
- if (RTP_PRIO_IS_REALTIME(rtp.type))
- param->sched_priority = rtpprio_to_p4prio(rtp.prio);
-
- return 0;
-}
-
-/*
- * XXX The priority and scheduler modifications should
- * be moved into published interfaces in kern/kern_sync.
- *
- * The permissions to modify process p were checked in "p31b_proc()".
- *
- */
-int ksched_setscheduler(register_t *ret, struct ksched *ksched,
- struct thread *td, int policy, const struct sched_param *param)
-{
- int e = 0;
- struct rtprio rtp;
- struct ksegrp *kg = td->td_ksegrp;
-
- switch(policy)
- {
- case SCHED_RR:
- case SCHED_FIFO:
-
- if (param->sched_priority >= P1B_PRIO_MIN &&
- param->sched_priority <= P1B_PRIO_MAX)
- {
- rtp.prio = p4prio_to_rtpprio(param->sched_priority);
- rtp.type = (policy == SCHED_FIFO)
- ? RTP_PRIO_FIFO : RTP_PRIO_REALTIME;
-
- mtx_lock_spin(&sched_lock);
- rtp_to_pri(&rtp, kg);
- FOREACH_THREAD_IN_GROUP(kg, td) { /* XXXKSE */
- if (TD_IS_RUNNING(td)) {
- td->td_flags |= TDF_NEEDRESCHED;
- } else if (TD_ON_RUNQ(td)) {
- if (td->td_priority > kg->kg_user_pri) {
- sched_prio(td, kg->kg_user_pri);
- }
- }
- }
- mtx_unlock_spin(&sched_lock);
- }
- else
- e = EPERM;
-
-
- break;
-
- case SCHED_OTHER:
- {
- rtp.type = RTP_PRIO_NORMAL;
- rtp.prio = p4prio_to_rtpprio(param->sched_priority);
- mtx_lock_spin(&sched_lock);
- rtp_to_pri(&rtp, kg);
-
- /* XXX Simply revert to whatever we had for last
- * normal scheduler priorities.
- * This puts a requirement
- * on the scheduling code: You must leave the
- * scheduling info alone.
- */
- FOREACH_THREAD_IN_GROUP(kg, td) {
- if (TD_IS_RUNNING(td)) {
- td->td_flags |= TDF_NEEDRESCHED;
- } else if (TD_ON_RUNQ(td)) {
- if (td->td_priority > kg->kg_user_pri) {
- sched_prio(td, kg->kg_user_pri);
- }
- }
-
- }
- mtx_unlock_spin(&sched_lock);
- }
- break;
- }
-
- return e;
-}
-
-int ksched_getscheduler(register_t *ret, struct ksched *ksched, struct thread *td)
-{
- return getscheduler(ret, ksched, td);
-}
-
-/* ksched_yield: Yield the CPU.
- */
-int ksched_yield(register_t *ret, struct ksched *ksched)
-{
- mtx_lock_spin(&sched_lock);
- curthread->td_flags |= TDF_NEEDRESCHED;
- mtx_unlock_spin(&sched_lock);
- return 0;
-}
-
-int ksched_get_priority_max(register_t*ret, struct ksched *ksched, int policy)
-{
- int e = 0;
-
- switch (policy)
- {
- case SCHED_FIFO:
- case SCHED_RR:
- *ret = RTP_PRIO_MAX;
- break;
-
- case SCHED_OTHER:
- *ret = PRIO_MAX;
- break;
-
- default:
- e = EINVAL;
- }
-
- return e;
-}
-
-int ksched_get_priority_min(register_t *ret, struct ksched *ksched, int policy)
-{
- int e = 0;
-
- switch (policy)
- {
- case SCHED_FIFO:
- case SCHED_RR:
- *ret = P1B_PRIO_MIN;
- break;
-
- case SCHED_OTHER:
- *ret = PRIO_MIN;
- break;
-
- default:
- e = EINVAL;
- }
-
- return e;
-}
-
-int ksched_rr_get_interval(register_t *ret, struct ksched *ksched,
- struct thread *td, struct timespec *timespec)
-{
- *timespec = ksched->rr_interval;
-
- return 0;
-}
diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c
deleted file mode 100644
index 31a6c79f00fa..000000000000
--- a/sys/kern/link_elf_obj.c
+++ /dev/null
@@ -1,1312 +0,0 @@
-/*-
- * Copyright (c) 1998-2000 Doug Rabson
- * 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$
- */
-
-#include "opt_ddb.h"
-#include "opt_mac.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/mac.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/namei.h>
-#include <sys/fcntl.h>
-#include <sys/vnode.h>
-#include <sys/linker.h>
-
-#include <machine/elf.h>
-#ifdef GPROF
-#include <machine/profile.h>
-#endif
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#ifdef SPARSE_MAPPING
-#include <vm/vm_object.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_extern.h>
-#endif
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-
-#include <sys/link_elf.h>
-
-#include "linker_if.h"
-
-typedef struct elf_file {
- 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 */
-#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 */
-#ifdef DDB
- struct link_map gdb; /* hooks for gdb */
-#endif
-} *elf_file_t;
-
-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*);
-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 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 *);
-static int link_elf_each_function_name(linker_file_t,
- int (*)(const char *, void *),
- void *);
-static void link_elf_reloc_local(linker_file_t);
-
-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),
- { 0, 0 }
-};
-
-static struct linker_class link_elf_class = {
-#if ELF_TARG_CLASS == ELFCLASS32
- "elf32",
-#else
- "elf64",
-#endif
- 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);
-
-#ifdef DDB
-static void r_debug_state(struct r_debug *dummy_one,
- struct link_map *dummy_two);
-
-/*
- * 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);
-
-/*
- * Function for the debugger to set a breakpoint on to gain control.
- */
-static void
-r_debug_state(struct r_debug *dummy_one __unused,
- struct link_map *dummy_two __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;
- }
-}
-
-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;
- }
-}
-#endif /* DDB */
-
-#ifdef __ia64__
-Elf_Addr link_elf_get_gp(linker_file_t);
-#endif
-
-/*
- * The kernel symbol table starts here.
- */
-extern struct _dynamic _DYNAMIC;
-
-static void
-link_elf_error(const char *s)
-{
- printf("kldload: %s\n", s);
-}
-
-/*
- * Actions performed after linking/loading both the preloaded kernel and any
- * modules; whether preloaded or dynamicly loaded.
- */
-static int
-link_elf_link_common_finish(linker_file_t lf)
-{
-#ifdef DDB
- elf_file_t ef = (elf_file_t)lf;
- char *newfilename;
-#endif
- int error;
-
- /* Notify MD code that a module is being loaded. */
- error = elf_cpu_load_file(lf);
- if (error)
- return (error);
-
-#ifdef DDB
- 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);
-}
-
-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;
-#ifdef SPARSE_MAPPING
- 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);
-
-#ifdef DDB
- 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);
-}
-
-SYSINIT(link_elf, SI_SUB_KLD, SI_ORDER_SECOND, 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;
- }
-
- strcnt = *(long *)base;
- base += sizeof(long);
- strtab = base;
- base += roundup(strcnt, 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;
-
- 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;
-#ifdef DDB
- 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;
- }
-
- ef->ddbsymtab = ef->symtab;
- ef->ddbsymcnt = ef->nchains;
- ef->ddbstrtab = ef->strtab;
- ef->ddbstrcnt = ef->strsz;
-
- return 0;
-}
-
-static int
-link_elf_link_preload(linker_class_t cls,
- 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;
-#ifdef SPARSE_MAPPING
- 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) {
- linker_file_unload(lf);
- 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;
-
- 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;
- }
-#endif
- error = relocate_file(ef);
- if (error)
- return error;
- (void)link_elf_preload_parse_symbols(ef);
-
- return (link_elf_link_common_finish(lf));
-}
-
-static int
-link_elf_load_file(linker_class_t cls, const char* filename,
- 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[2];
- 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;
-
- GIANT_REQUIRED;
-
- shdr = NULL;
- lf = NULL;
-
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, filename, td);
- flags = FREAD;
- error = vn_open(&nd, &flags, 0);
- if (error)
- return error;
- NDFREE(&nd, NDF_ONLY_PNBUF);
-#ifdef MAC
- error = mac_check_kld_load(curthread->td_ucred, nd.ni_vp);
- if (error) {
- 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;
- }
-
- if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS
- || hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
- link_elf_error("Unsupported file layout");
- error = ENOEXEC;
- goto out;
- }
- if (hdr->e_ident[EI_VERSION] != EV_CURRENT
- || hdr->e_version != EV_CURRENT) {
- link_elf_error("Unsupported file version");
- error = ENOEXEC;
- goto out;
- }
- if (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN) {
- link_elf_error("Unsupported file type");
- error = ENOEXEC;
- goto out;
- }
- if (hdr->e_machine != ELF_TARG_MACH) {
- link_elf_error("Unsupported machine");
- 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("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 == 2) {
- link_elf_error("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:
- link_elf_error("Unsupported file type");
- error = ENOEXEC;
- goto out;
- }
-
- ++phdr;
- }
- if (phdyn == NULL) {
- link_elf_error("Object is not dynamically-linked");
- error = ENOEXEC;
- goto out;
- }
- if (nsegs != 2) {
- link_elf_error("Too few sections");
- error = ENOEXEC;
- 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[1]->p_vaddr + segs[1]->p_memsz);
- mapsize = base_vlimit - base_vaddr;
-
- lf = linker_make_file(filename, &link_elf_class);
- if (!lf) {
- error = ENOMEM;
- 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;
- }
- vm_object_reference(ef->object);
- 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;
-
- /*
- * Read the text and data sections and zero the bss.
- */
- for (i = 0; i < 2; 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;
- }
- bzero(segbase + segs[i]->p_filesz,
- segs[i]->p_memsz - segs[i]->p_filesz);
-
-#ifdef SPARSE_MAPPING
- /*
- * Wire down the pages
- */
- vm_map_wire(kernel_map,
- (vm_offset_t) segbase,
- (vm_offset_t) segbase + segs[i]->p_memsz,
- FALSE);
-#endif
- }
-
-#ifdef GPROF
- /* Update profiling information with the new text segment. */
- kmupetext((uintfptr_t)(mapbase + segs[0]->p_vaddr - base_vaddr +
- segs[0]->p_memsz));
-#endif
-
- ef->dynamic = (Elf_Dyn *) (mapbase + phdyn->p_vaddr - base_vaddr);
-
- lf->address = ef->address;
- lf->size = mapsize;
-
- error = parse_dynamic(ef);
- if (error)
- goto out;
- link_elf_reloc_local(lf);
-
- error = linker_load_dependencies(lf);
- if (error)
- 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;
- }
-#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;
- }
- }
- 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);
-
- 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;
-
- 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;
-
-nosyms:
-
- *result = lf;
-
-out:
- if (error && lf)
- linker_file_unload(lf);
- if (shdr)
- free(shdr, M_LINKER);
- if (firstpage)
- free(firstpage, M_LINKER);
- VOP_UNLOCK(nd.ni_vp, 0, td);
- vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
-
- return error;
-}
-
-static void
-link_elf_unload_file(linker_file_t file)
-{
- elf_file_t ef = (elf_file_t) file;
-
-#ifdef DDB
- 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);
- }
-#endif
-
- /* Notify MD code that a module is being unloaded. */
- elf_cpu_unload_file(file);
-
- 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));
- vm_object_deallocate(ef->object);
- }
-#else
- if (ef->address)
- free(ef->address, M_LINKER);
-#endif
- if (ef->symbase)
- free(ef->symbase, M_LINKER);
- if (ef->strbase)
- free(ef->strbase, M_LINKER);
-}
-
-static void
-link_elf_unload_preload(linker_file_t file)
-{
- if (file->filename)
- preload_delete_name(file->filename);
-}
-
-static const char *
-symbol_name(elf_file_t ef, Elf_Word r_info)
-{
- 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;
-}
-
-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, rel, ELF_RELOC_REL)) {
- 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, rela, ELF_RELOC_RELA)) {
- 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, rel, ELF_RELOC_REL)) {
- 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, rela, ELF_RELOC_RELA)) {
- symname = symbol_name(ef, rela->r_info);
- printf("link_elf: symbol %s undefined\n", symname);
- return ENOENT;
- }
- rela++;
- }
- }
-
- return 0;
-}
-
-/*
- * Hash function for symbol table lookup. Don't even think about changing
- * this. It is specified by the System V ABI.
- */
-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;
-}
-
-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;
-
- /* First, search hashed global symbols */
- hash = elf_hash(name);
- symnum = ef->buckets[hash % ef->nbuckets];
-
- while (symnum != STN_UNDEF) {
- if (symnum >= ef->nchains) {
- printf("link_elf_lookup_symbol: corrupt symbol table\n");
- return ENOENT;
- }
-
- symp = ef->symtab + symnum;
- if (symp->st_name == 0) {
- printf("link_elf_lookup_symbol: corrupt symbol table\n");
- 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;
- }
-
- symnum = ef->chains[symnum];
- }
-
- /* 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;
- }
- }
-
- return ENOENT;
-}
-
-static int
-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;
- }
- if (ef->symtab == ef->ddbsymtab)
- 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;
- }
- return ENOENT;
-}
-
-static int
-link_elf_search_symbol(linker_file_t lf, caddr_t value,
- c_linker_sym_t* sym, long* diffp)
-{
- elf_file_t ef = (elf_file_t) lf;
- u_long off = (uintptr_t) (void *) value;
- u_long diff = off;
- u_long st_value;
- const Elf_Sym* es;
- const Elf_Sym* best = 0;
- int i;
-
- for (i = 0, es = ef->ddbsymtab; i < ef->ddbsymcnt; i++, es++) {
- if (es->st_name == 0)
- continue;
- st_value = es->st_value + (uintptr_t) (void *) ef->address;
- if (off >= st_value) {
- if (off - st_value < diff) {
- diff = off - st_value;
- best = es;
- if (diff == 0)
- break;
- } else if (off - st_value == diff) {
- best = es;
- }
- }
- }
- if (best == 0)
- *diffp = off;
- else
- *diffp = diff;
- *sym = (c_linker_sym_t) best;
-
- return 0;
-}
-
-/*
- * Look up a linker set on an ELF system.
- */
-static int
-link_elf_lookup_set(linker_file_t lf, const char *name,
- void ***startp, void ***stopp, int *countp)
-{
- c_linker_sym_t sym;
- linker_symval_t symval;
- char *setsym;
- void **start, **stop;
- int len, error = 0, count;
-
- len = strlen(name) + sizeof("__start_set_"); /* sizeof includes \0 */
- setsym = malloc(len, M_LINKER, M_WAITOK);
- if (setsym == NULL)
- 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)
- goto out;
- link_elf_symbol_values(lf, sym, &symval);
- if (symval.value == 0) {
- error = ESRCH;
- goto out;
- }
- start = (void **)symval.value;
-
- /* get address of last entry */
- snprintf(setsym, len, "%s%s", "__stop_set_", name);
- error = link_elf_lookup_symbol(lf, setsym, &sym);
- if (error)
- goto out;
- link_elf_symbol_values(lf, sym, &symval);
- if (symval.value == 0) {
- error = ESRCH;
- goto out;
- }
- stop = (void **)symval.value;
-
- /* and the number of entries */
- count = stop - start;
-
- /* and copy out */
- if (startp)
- *startp = start;
- if (stopp)
- *stopp = stop;
- if (countp)
- *countp = count;
-
-out:
- free(setsym, M_LINKER);
- 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;
-
- /* 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);
- }
- }
- return (0);
-}
-
-#ifdef __ia64__
-/*
- * Each KLD has its own GP. The GP value for each load module is given by
- * DT_PLTGOT on ia64. We need GP to construct function descriptors, but
- * don't have direct access to the ELF file structure. The link_elf_get_gp()
- * function returns the GP given a pointer to a generic linker file struct.
- */
-Elf_Addr
-link_elf_get_gp(linker_file_t lf)
-{
- elf_file_t ef = (elf_file_t)lf;
- return (Elf_Addr)ef->got;
-}
-#endif
-
-const Elf_Sym *
-elf_get_sym(linker_file_t lf, Elf_Word symidx)
-{
- elf_file_t ef = (elf_file_t)lf;
-
- if (symidx >= ef->nchains)
- return (NULL);
- return (ef->symtab + symidx);
-}
-
-const char *
-elf_get_symname(linker_file_t lf, Elf_Word symidx)
-{
- elf_file_t ef = (elf_file_t)lf;
- const Elf_Sym *sym;
-
- if (symidx >= ef->nchains)
- return (NULL);
- sym = ef->symtab + symidx;
- return (ef->strtab + sym->st_name);
-}
-
-/*
- * Symbol lookup function that can be used when the symbol index is known (ie
- * in relocations). It uses the symbol index instead of doing a fully fledged
- * hash table based lookup when such is valid. For example for local symbols.
- * This is not only more efficient, it's also more correct. It's not always
- * the case that the symbol can be found through the hash table.
- */
-Elf_Addr
-elf_lookup(linker_file_t lf, Elf_Word symidx, int deps)
-{
- elf_file_t ef = (elf_file_t)lf;
- const Elf_Sym *sym;
- const char *symbol;
-
- /* Don't even try to lookup the symbol if the index is bogus. */
- if (symidx >= ef->nchains)
- return (0);
-
- sym = ef->symtab + symidx;
-
- /*
- * Don't do a full lookup when the symbol is local. It may even
- * fail because it may not be found through the hash table.
- */
- if (ELF_ST_BIND(sym->st_info) == STB_LOCAL) {
- /* Force lookup failure when we have an insanity. */
- if (sym->st_shndx == SHN_UNDEF || sym->st_value == 0)
- return (0);
- return ((Elf_Addr)ef->address + sym->st_value);
- }
-
- /*
- * XXX we can avoid doing a hash table based lookup for global
- * symbols as well. This however is not always valid, so we'll
- * just do it the hard way for now. Performance tweaks can
- * always be added.
- */
-
- symbol = ef->strtab + sym->st_name;
-
- /* Force a lookup failure if the symbol name is bogus. */
- if (*symbol == 0)
- return (0);
-
- return ((Elf_Addr)linker_file_lookup_symbol(lf, symbol, 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, rel, ELF_RELOC_REL);
- 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, rela, ELF_RELOC_RELA);
- rela++;
- }
- }
-}
diff --git a/sys/kern/p1003_1b.c b/sys/kern/p1003_1b.c
deleted file mode 100644
index 26d3e66d0bda..000000000000
--- a/sys/kern/p1003_1b.c
+++ /dev/null
@@ -1,348 +0,0 @@
-/*
- * Copyright (c) 1996, 1997, 1998
- * HD Associates, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by HD Associates, Inc
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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$
- */
-
-/* p1003_1b: Real Time common code.
- */
-
-#include "opt_posix.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/module.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/sysctl.h>
-#include <sys/sysent.h>
-#include <sys/syslog.h>
-#include <sys/sysproto.h>
-
-#include <posix4/posix4.h>
-
-MALLOC_DEFINE(M_P31B, "p1003.1b", "Posix 1003.1B");
-
-/* The system calls return ENOSYS if an entry is called that is
- * not run-time supported. I am also logging since some programs
- * start to use this when they shouldn't. That will be removed if annoying.
- */
-int
-syscall_not_present(struct thread *td, const char *s, struct nosys_args *uap)
-{
- log(LOG_ERR, "cmd %s pid %d tried to use non-present %s\n",
- td->td_proc->p_comm, td->td_proc->p_pid, s);
-
- /* a " return nosys(p, uap); " here causes a core dump.
- */
-
- return ENOSYS;
-}
-
-#if !defined(_KPOSIX_PRIORITY_SCHEDULING)
-
-/* Not configured but loadable via a module:
- */
-
-static int sched_attach(void)
-{
- return 0;
-}
-
-SYSCALL_NOT_PRESENT_GEN(sched_setparam)
-SYSCALL_NOT_PRESENT_GEN(sched_getparam)
-SYSCALL_NOT_PRESENT_GEN(sched_setscheduler)
-SYSCALL_NOT_PRESENT_GEN(sched_getscheduler)
-SYSCALL_NOT_PRESENT_GEN(sched_yield)
-SYSCALL_NOT_PRESENT_GEN(sched_get_priority_max)
-SYSCALL_NOT_PRESENT_GEN(sched_get_priority_min)
-SYSCALL_NOT_PRESENT_GEN(sched_rr_get_interval)
-
-#else
-
-/* Configured in kernel version:
- */
-static struct ksched *ksched;
-
-static int sched_attach(void)
-{
- int ret = ksched_attach(&ksched);
-
- if (ret == 0)
- p31b_setcfg(CTL_P1003_1B_PRIORITY_SCHEDULING, 1);
-
- return ret;
-}
-
-/*
- * MPSAFE
- */
-int sched_setparam(struct thread *td,
- struct sched_setparam_args *uap)
-{
- struct thread *targettd;
- struct proc *targetp;
- int e;
- struct sched_param sched_param;
-
- e = copyin(uap->param, &sched_param, sizeof(sched_param));
- if (e)
- return (e);
-
- mtx_lock(&Giant);
- if (uap->pid == 0) {
- targetp = td->td_proc;
- targettd = td;
- PROC_LOCK(targetp);
- } else {
- targetp = pfind(uap->pid);
- if (targetp == NULL) {
- e = ESRCH;
- goto done2;
- }
- targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
- }
-
- e = p_cansched(td, targetp);
- PROC_UNLOCK(targetp);
- if (e == 0) {
- e = ksched_setparam(&td->td_retval[0], ksched, targettd,
- (const struct sched_param *)&sched_param);
- }
-done2:
- mtx_unlock(&Giant);
- return (e);
-}
-
-/*
- * MPSAFE
- */
-int sched_getparam(struct thread *td,
- struct sched_getparam_args *uap)
-{
- int e;
- struct sched_param sched_param;
- struct thread *targettd;
- struct proc *targetp;
-
- mtx_lock(&Giant);
- if (uap->pid == 0) {
- targetp = td->td_proc;
- targettd = td;
- PROC_LOCK(targetp);
- } else {
- targetp = pfind(uap->pid);
- if (targetp == NULL) {
- e = ESRCH;
- goto done2;
- }
- targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
- }
-
- e = p_cansee(td, targetp);
- PROC_UNLOCK(targetp);
- if (e)
- goto done2;
-
- e = ksched_getparam(&td->td_retval[0], ksched, targettd, &sched_param);
- if (e == 0)
- e = copyout(&sched_param, uap->param, sizeof(sched_param));
-done2:
- mtx_unlock(&Giant);
- return (e);
-}
-
-/*
- * MPSAFE
- */
-int sched_setscheduler(struct thread *td,
- struct sched_setscheduler_args *uap)
-{
- int e;
- struct sched_param sched_param;
- struct thread *targettd;
- struct proc *targetp;
-
- e = copyin(uap->param, &sched_param, sizeof(sched_param));
- if (e)
- return (e);
-
- mtx_lock(&Giant);
- if (uap->pid == 0) {
- targetp = td->td_proc;
- targettd = td;
- PROC_LOCK(targetp);
- } else {
- targetp = pfind(uap->pid);
- if (targetp == NULL) {
- e = ESRCH;
- goto done2;
- }
- targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
- }
-
- e = p_cansched(td, targetp);
- PROC_UNLOCK(targetp);
- if (e == 0) {
- e = ksched_setscheduler(&td->td_retval[0], ksched, targettd,
- uap->policy, (const struct sched_param *)&sched_param);
- }
-done2:
- mtx_unlock(&Giant);
- return (e);
-}
-
-/*
- * MPSAFE
- */
-int sched_getscheduler(struct thread *td,
- struct sched_getscheduler_args *uap)
-{
- int e;
- struct thread *targettd;
- struct proc *targetp;
-
- mtx_lock(&Giant);
- if (uap->pid == 0) {
- targetp = td->td_proc;
- targettd = td;
- PROC_LOCK(targetp);
- } else {
- targetp = pfind(uap->pid);
- if (targetp == NULL) {
- e = ESRCH;
- goto done2;
- }
- targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
- }
-
- e = p_cansee(td, targetp);
- PROC_UNLOCK(targetp);
- if (e == 0)
- e = ksched_getscheduler(&td->td_retval[0], ksched, targettd);
-
-done2:
- mtx_unlock(&Giant);
- return (e);
-}
-
-/*
- * MPSAFE
- */
-int sched_yield(struct thread *td,
- struct sched_yield_args *uap)
-{
- int error;
-
- mtx_lock(&Giant);
- error = ksched_yield(&td->td_retval[0], ksched);
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int sched_get_priority_max(struct thread *td,
- struct sched_get_priority_max_args *uap)
-{
- int error;
-
- mtx_lock(&Giant);
- error = ksched_get_priority_max(&td->td_retval[0], ksched, uap->policy);
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int sched_get_priority_min(struct thread *td,
- struct sched_get_priority_min_args *uap)
-{
- int error;
-
- mtx_lock(&Giant);
- error = ksched_get_priority_min(&td->td_retval[0], ksched, uap->policy);
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int sched_rr_get_interval(struct thread *td,
- struct sched_rr_get_interval_args *uap)
-{
- int e;
- struct thread *targettd;
- struct timespec timespec;
- struct proc *targetp;
-
- mtx_lock(&Giant);
- if (uap->pid == 0) {
- targettd = td;
- targetp = td->td_proc;
- PROC_LOCK(targetp);
- } else {
- targetp = pfind(uap->pid);
- if (targetp == NULL) {
- e = ESRCH;
- goto done2;
- }
- targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
- }
-
- e = p_cansee(td, targetp);
- PROC_UNLOCK(targetp);
- if (e == 0) {
- e = ksched_rr_get_interval(&td->td_retval[0], ksched, targettd,
- &timespec);
- if (e == 0)
- e = copyout(&timespec, uap->interval,
- sizeof(timespec));
- }
-done2:
- mtx_unlock(&Giant);
- return (e);
-}
-
-#endif
-
-static void p31binit(void *notused)
-{
- (void) sched_attach();
- p31b_setcfg(CTL_P1003_1B_PAGESIZE, PAGE_SIZE);
-}
-
-SYSINIT(p31b, SI_SUB_P1003_1B, SI_ORDER_FIRST, p31binit, NULL);
diff --git a/sys/kern/posix4_mib.c b/sys/kern/posix4_mib.c
deleted file mode 100644
index 12d5fecb4fbc..000000000000
--- a/sys/kern/posix4_mib.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*-
- * Copyright (c) 1998
- * HD Associates, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by HD Associates, Inc
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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$
- */
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/queue.h>
-#include <sys/sysctl.h>
-#include <sys/vnode.h>
-#include <posix4/posix4.h>
-
-static int facility[CTL_P1003_1B_MAXID - 1];
-static int facility_initialized[CTL_P1003_1B_MAXID - 1];
-
-/* OID_AUTO isn't working with sysconf(3). I guess I'd have to
- * modify it to do a lookup by name from the index.
- * For now I've left it a top-level sysctl.
- */
-
-#if 1
-
-SYSCTL_DECL(_p1003_1b);
-
-#define P1B_SYSCTL(num, name) \
-SYSCTL_INT(_p1003_1b, num, \
- name, CTLFLAG_RD, facility + num - 1, 0, "");
-
-#else
-
-SYSCTL_DECL(_kern_p1003_1b);
-
-#define P1B_SYSCTL(num, name) \
-SYSCTL_INT(_kern_p1003_1b, OID_AUTO, \
- name, CTLFLAG_RD, facility + num - 1, 0, "");
-SYSCTL_NODE(_kern, OID_AUTO, p1003_1b, CTLFLAG_RW, 0, "P1003.1B");
-
-#endif
-
-SYSCTL_INT(_p1003_1b, CTL_P1003_1B_ASYNCHRONOUS_IO, \
- asynchronous_io, CTLFLAG_RD, &async_io_version, 0, "");
-P1B_SYSCTL(CTL_P1003_1B_MAPPED_FILES, mapped_files);
-P1B_SYSCTL(CTL_P1003_1B_MEMLOCK, memlock);
-P1B_SYSCTL(CTL_P1003_1B_MEMLOCK_RANGE, memlock_range);
-P1B_SYSCTL(CTL_P1003_1B_MEMORY_PROTECTION, memory_protection);
-P1B_SYSCTL(CTL_P1003_1B_MESSAGE_PASSING, message_passing);
-P1B_SYSCTL(CTL_P1003_1B_PRIORITIZED_IO, prioritized_io);
-P1B_SYSCTL(CTL_P1003_1B_PRIORITY_SCHEDULING, priority_scheduling);
-P1B_SYSCTL(CTL_P1003_1B_REALTIME_SIGNALS, realtime_signals);
-P1B_SYSCTL(CTL_P1003_1B_SEMAPHORES, semaphores);
-P1B_SYSCTL(CTL_P1003_1B_FSYNC, fsync);
-P1B_SYSCTL(CTL_P1003_1B_SHARED_MEMORY_OBJECTS, shared_memory_objects);
-P1B_SYSCTL(CTL_P1003_1B_SYNCHRONIZED_IO, synchronized_io);
-P1B_SYSCTL(CTL_P1003_1B_TIMERS, timers);
-P1B_SYSCTL(CTL_P1003_1B_AIO_LISTIO_MAX, aio_listio_max);
-P1B_SYSCTL(CTL_P1003_1B_AIO_MAX, aio_max);
-P1B_SYSCTL(CTL_P1003_1B_AIO_PRIO_DELTA_MAX, aio_prio_delta_max);
-P1B_SYSCTL(CTL_P1003_1B_DELAYTIMER_MAX, delaytimer_max);
-P1B_SYSCTL(CTL_P1003_1B_MQ_OPEN_MAX, mq_open_max);
-P1B_SYSCTL(CTL_P1003_1B_PAGESIZE, pagesize);
-P1B_SYSCTL(CTL_P1003_1B_RTSIG_MAX, rtsig_max);
-P1B_SYSCTL(CTL_P1003_1B_SEM_NSEMS_MAX, sem_nsems_max);
-P1B_SYSCTL(CTL_P1003_1B_SEM_VALUE_MAX, sem_value_max);
-P1B_SYSCTL(CTL_P1003_1B_SIGQUEUE_MAX, sigqueue_max);
-P1B_SYSCTL(CTL_P1003_1B_TIMER_MAX, timer_max);
-
-#define P31B_VALID(num) ((num) >= 1 && (num) < CTL_P1003_1B_MAXID)
-
-/* p31b_setcfg: Set the configuration
- */
-void
-p31b_setcfg(int num, int value)
-{
-
- if (P31B_VALID(num)) {
- facility[num - 1] = value;
- facility_initialized[num - 1] = 1;
- }
-}
-
-int
-p31b_getcfg(int num)
-{
-
- if (P31B_VALID(num))
- return (facility[num - 1]);
- return (0);
-}
-
-int
-p31b_iscfg(int num)
-{
-
- if (P31B_VALID(num))
- return (facility_initialized[num - 1]);
- return (0);
-}
-
-/*
- * Turn on indications for standard (non-configurable) kernel features.
- */
-static void
-p31b_set_standard(void *dummy)
-{
- /* ??? p31b_setcfg(CTL_P1003_1B_FSYNC, 1); */
- p31b_setcfg(CTL_P1003_1B_MAPPED_FILES, 1);
- p31b_setcfg(CTL_P1003_1B_SHARED_MEMORY_OBJECTS, 1);
- p31b_setcfg(CTL_P1003_1B_PAGESIZE, PAGE_SIZE);
- if (!p31b_iscfg(CTL_P1003_1B_AIO_LISTIO_MAX))
- p31b_setcfg(CTL_P1003_1B_AIO_LISTIO_MAX, -1);
- if (!p31b_iscfg(CTL_P1003_1B_AIO_MAX))
- p31b_setcfg(CTL_P1003_1B_AIO_MAX, -1);
- if (!p31b_iscfg(CTL_P1003_1B_AIO_PRIO_DELTA_MAX))
- p31b_setcfg(CTL_P1003_1B_AIO_PRIO_DELTA_MAX, -1);
-}
-
-SYSINIT(p31b_set_standard, SI_SUB_P1003_1B, SI_ORDER_ANY, p31b_set_standard,
- 0);
-
diff --git a/sys/kern/subr_acl_posix1e.c b/sys/kern/subr_acl_posix1e.c
deleted file mode 100644
index 6b9f942ff54b..000000000000
--- a/sys/kern/subr_acl_posix1e.c
+++ /dev/null
@@ -1,939 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * All rights reserved.
- *
- * This software was developed by Robert Watson for the TrustedBSD Project.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-/*
- * Developed by the TrustedBSD Project.
- * Support for POSIX.1e access control lists.
- */
-
-#include "opt_mac.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/kernel.h>
-#include <sys/mac.h>
-#include <sys/malloc.h>
-#include <sys/vnode.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/namei.h>
-#include <sys/file.h>
-#include <sys/filedesc.h>
-#include <sys/proc.h>
-#include <sys/sysent.h>
-#include <sys/errno.h>
-#include <sys/stat.h>
-#include <sys/acl.h>
-
-MALLOC_DEFINE(M_ACL, "acl", "access control list");
-
-static int vacl_set_acl(struct thread *td, struct vnode *vp,
- acl_type_t type, struct acl *aclp);
-static int vacl_get_acl(struct thread *td, struct vnode *vp,
- acl_type_t type, struct acl *aclp);
-static int vacl_aclcheck(struct thread *td, struct vnode *vp,
- acl_type_t type, struct acl *aclp);
-
-/*
- * Implement a version of vaccess() that understands POSIX.1e ACL semantics.
- * Return 0 on success, else an errno value. Should be merged into
- * vaccess() eventually.
- */
-int
-vaccess_acl_posix1e(enum vtype type, uid_t file_uid, gid_t file_gid,
- struct acl *acl, mode_t acc_mode, struct ucred *cred, int *privused)
-{
- struct acl_entry *acl_other, *acl_mask;
- mode_t dac_granted;
- mode_t cap_granted;
- mode_t acl_mask_granted;
- int group_matched, i;
-
- /*
- * Look for a normal, non-privileged way to access the file/directory
- * as requested. If it exists, go with that. Otherwise, attempt
- * to use privileges granted via cap_granted. In some cases,
- * which privileges to use may be ambiguous due to "best match",
- * in which case fall back on first match for the time being.
- */
- if (privused != NULL)
- *privused = 0;
-
- /*
- * Determine privileges now, but don't apply until we've found
- * a DAC entry that matches but has failed to allow access.
- */
-#ifndef CAPABILITIES
- if (suser_cred(cred, PRISON_ROOT) == 0)
- cap_granted = VALLPERM;
- else
- cap_granted = 0;
-#else
- cap_granted = 0;
-
- if (type == VDIR) {
- if ((acc_mode & VEXEC) && !cap_check(cred, NULL,
- CAP_DAC_READ_SEARCH, PRISON_ROOT))
- cap_granted |= VEXEC;
- } else {
- if ((acc_mode & VEXEC) && !cap_check(cred, NULL,
- CAP_DAC_EXECUTE, PRISON_ROOT))
- cap_granted |= VEXEC;
- }
-
- if ((acc_mode & VREAD) && !cap_check(cred, NULL, CAP_DAC_READ_SEARCH,
- PRISON_ROOT))
- cap_granted |= VREAD;
-
- if (((acc_mode & VWRITE) || (acc_mode & VAPPEND)) &&
- !cap_check(cred, NULL, CAP_DAC_WRITE, PRISON_ROOT))
- cap_granted |= (VWRITE | VAPPEND);
-
- if ((acc_mode & VADMIN) && !cap_check(cred, NULL, CAP_FOWNER,
- PRISON_ROOT))
- cap_granted |= VADMIN;
-#endif /* CAPABILITIES */
-
- /*
- * The owner matches if the effective uid associated with the
- * credential matches that of the ACL_USER_OBJ entry. While we're
- * doing the first scan, also cache the location of the ACL_MASK
- * and ACL_OTHER entries, preventing some future iterations.
- */
- acl_mask = acl_other = NULL;
- for (i = 0; i < acl->acl_cnt; i++) {
- switch (acl->acl_entry[i].ae_tag) {
- case ACL_USER_OBJ:
- if (file_uid != cred->cr_uid)
- break;
- dac_granted = 0;
- dac_granted |= VADMIN;
- if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl->acl_entry[i].ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl->acl_entry[i].ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
- if ((acc_mode & dac_granted) == acc_mode)
- return (0);
- if ((acc_mode & (dac_granted | cap_granted)) ==
- acc_mode) {
- if (privused != NULL)
- *privused = 1;
- return (0);
- }
- goto error;
-
- case ACL_MASK:
- acl_mask = &acl->acl_entry[i];
- break;
-
- case ACL_OTHER:
- acl_other = &acl->acl_entry[i];
- break;
-
- default:
- break;
- }
- }
-
- /*
- * An ACL_OTHER entry should always exist in a valid access
- * ACL. If it doesn't, then generate a serious failure. For now,
- * this means a debugging message and EPERM, but in the future
- * should probably be a panic.
- */
- if (acl_other == NULL) {
- /*
- * XXX This should never happen
- */
- printf("vaccess_acl_posix1e: ACL_OTHER missing\n");
- return (EPERM);
- }
-
- /*
- * Checks against ACL_USER, ACL_GROUP_OBJ, and ACL_GROUP fields
- * are masked by an ACL_MASK entry, if any. As such, first identify
- * the ACL_MASK field, then iterate through identifying potential
- * user matches, then group matches. If there is no ACL_MASK,
- * assume that the mask allows all requests to succeed.
- */
- if (acl_mask != NULL) {
- acl_mask_granted = 0;
- if (acl_mask->ae_perm & ACL_EXECUTE)
- acl_mask_granted |= VEXEC;
- if (acl_mask->ae_perm & ACL_READ)
- acl_mask_granted |= VREAD;
- if (acl_mask->ae_perm & ACL_WRITE)
- acl_mask_granted |= (VWRITE | VAPPEND);
- } else
- acl_mask_granted = VEXEC | VREAD | VWRITE | VAPPEND;
-
- /*
- * Iterate through user ACL entries. Do checks twice, first
- * without privilege, and then if a match is found but failed,
- * a second time with privilege.
- */
-
- /*
- * Check ACL_USER ACL entries.
- */
- for (i = 0; i < acl->acl_cnt; i++) {
- switch (acl->acl_entry[i].ae_tag) {
- case ACL_USER:
- if (acl->acl_entry[i].ae_id != cred->cr_uid)
- break;
- dac_granted = 0;
- if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl->acl_entry[i].ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl->acl_entry[i].ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
- dac_granted &= acl_mask_granted;
- if ((acc_mode & dac_granted) == acc_mode)
- return (0);
- if ((acc_mode & (dac_granted | cap_granted)) !=
- acc_mode)
- goto error;
-
- if (privused != NULL)
- *privused = 1;
- return (0);
- }
- }
-
- /*
- * Group match is best-match, not first-match, so find a
- * "best" match. Iterate across, testing each potential group
- * match. Make sure we keep track of whether we found a match
- * or not, so that we know if we should try again with any
- * available privilege, or if we should move on to ACL_OTHER.
- */
- group_matched = 0;
- for (i = 0; i < acl->acl_cnt; i++) {
- switch (acl->acl_entry[i].ae_tag) {
- case ACL_GROUP_OBJ:
- if (!groupmember(file_gid, cred))
- break;
- dac_granted = 0;
- if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl->acl_entry[i].ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl->acl_entry[i].ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
- dac_granted &= acl_mask_granted;
-
- if ((acc_mode & dac_granted) == acc_mode)
- return (0);
-
- group_matched = 1;
- break;
-
- case ACL_GROUP:
- if (!groupmember(acl->acl_entry[i].ae_id, cred))
- break;
- dac_granted = 0;
- if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl->acl_entry[i].ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl->acl_entry[i].ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
- dac_granted &= acl_mask_granted;
-
- if ((acc_mode & dac_granted) == acc_mode)
- return (0);
-
- group_matched = 1;
- break;
-
- default:
- break;
- }
- }
-
- if (group_matched == 1) {
- /*
- * There was a match, but it did not grant rights via
- * pure DAC. Try again, this time with privilege.
- */
- for (i = 0; i < acl->acl_cnt; i++) {
- switch (acl->acl_entry[i].ae_tag) {
- case ACL_GROUP_OBJ:
- if (!groupmember(file_gid, cred))
- break;
- dac_granted = 0;
- if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl->acl_entry[i].ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl->acl_entry[i].ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
- dac_granted &= acl_mask_granted;
-
- if ((acc_mode & (dac_granted | cap_granted)) !=
- acc_mode)
- break;
-
- if (privused != NULL)
- *privused = 1;
- return (0);
-
- case ACL_GROUP:
- if (!groupmember(acl->acl_entry[i].ae_id,
- cred))
- break;
- dac_granted = 0;
- if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl->acl_entry[i].ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl->acl_entry[i].ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
- dac_granted &= acl_mask_granted;
-
- if ((acc_mode & (dac_granted | cap_granted)) !=
- acc_mode)
- break;
-
- if (privused != NULL)
- *privused = 1;
- return (0);
-
- default:
- break;
- }
- }
- /*
- * Even with privilege, group membership was not sufficient.
- * Return failure.
- */
- goto error;
- }
-
- /*
- * Fall back on ACL_OTHER. ACL_MASK is not applied to ACL_OTHER.
- */
- dac_granted = 0;
- if (acl_other->ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl_other->ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl_other->ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
-
- if ((acc_mode & dac_granted) == acc_mode)
- return (0);
- if ((acc_mode & (dac_granted | cap_granted)) == acc_mode) {
- if (privused != NULL)
- *privused = 1;
- return (0);
- }
-
-error:
- return ((acc_mode & VADMIN) ? EPERM : EACCES);
-}
-
-/*
- * For the purposes of filesystems maintaining the _OBJ entries in an
- * inode with a mode_t field, this routine converts a mode_t entry
- * to an acl_perm_t.
- */
-acl_perm_t
-acl_posix1e_mode_to_perm(acl_tag_t tag, mode_t mode)
-{
- acl_perm_t perm = 0;
-
- switch(tag) {
- case ACL_USER_OBJ:
- if (mode & S_IXUSR)
- perm |= ACL_EXECUTE;
- if (mode & S_IRUSR)
- perm |= ACL_READ;
- if (mode & S_IWUSR)
- perm |= ACL_WRITE;
- return (perm);
-
- case ACL_GROUP_OBJ:
- if (mode & S_IXGRP)
- perm |= ACL_EXECUTE;
- if (mode & S_IRGRP)
- perm |= ACL_READ;
- if (mode & S_IWGRP)
- perm |= ACL_WRITE;
- return (perm);
-
- case ACL_OTHER:
- if (mode & S_IXOTH)
- perm |= ACL_EXECUTE;
- if (mode & S_IROTH)
- perm |= ACL_READ;
- if (mode & S_IWOTH)
- perm |= ACL_WRITE;
- return (perm);
-
- default:
- printf("acl_posix1e_mode_to_perm: invalid tag (%d)\n", tag);
- return (0);
- }
-}
-
-/*
- * Given inode information (uid, gid, mode), return an acl entry of the
- * appropriate type.
- */
-struct acl_entry
-acl_posix1e_mode_to_entry(acl_tag_t tag, uid_t uid, gid_t gid, mode_t mode)
-{
- struct acl_entry acl_entry;
-
- acl_entry.ae_tag = tag;
- acl_entry.ae_perm = acl_posix1e_mode_to_perm(tag, mode);
- switch(tag) {
- case ACL_USER_OBJ:
- acl_entry.ae_id = uid;
- break;
-
- case ACL_GROUP_OBJ:
- acl_entry.ae_id = gid;
- break;
-
- case ACL_OTHER:
- acl_entry.ae_id = ACL_UNDEFINED_ID;
- break;
-
- default:
- acl_entry.ae_id = ACL_UNDEFINED_ID;
- printf("acl_posix1e_mode_to_entry: invalid tag (%d)\n", tag);
- }
-
- return (acl_entry);
-}
-
-/*
- * Utility function to generate a file mode given appropriate ACL entries.
- */
-mode_t
-acl_posix1e_perms_to_mode(struct acl_entry *acl_user_obj_entry,
- struct acl_entry *acl_group_obj_entry, struct acl_entry *acl_other_entry)
-{
- mode_t mode;
-
- mode = 0;
- if (acl_user_obj_entry->ae_perm & ACL_EXECUTE)
- mode |= S_IXUSR;
- if (acl_user_obj_entry->ae_perm & ACL_READ)
- mode |= S_IRUSR;
- if (acl_user_obj_entry->ae_perm & ACL_WRITE)
- mode |= S_IWUSR;
- if (acl_group_obj_entry->ae_perm & ACL_EXECUTE)
- mode |= S_IXGRP;
- if (acl_group_obj_entry->ae_perm & ACL_READ)
- mode |= S_IRGRP;
- if (acl_group_obj_entry->ae_perm & ACL_WRITE)
- mode |= S_IWGRP;
- if (acl_other_entry->ae_perm & ACL_EXECUTE)
- mode |= S_IXOTH;
- if (acl_other_entry->ae_perm & ACL_READ)
- mode |= S_IROTH;
- if (acl_other_entry->ae_perm & ACL_WRITE)
- mode |= S_IWOTH;
-
- return (mode);
-}
-
-/*
- * Perform a syntactic check of the ACL, sufficient to allow an
- * implementing filesystem to determine if it should accept this and
- * rely on the POSIX.1e ACL properties.
- */
-int
-acl_posix1e_check(struct acl *acl)
-{
- int num_acl_user_obj, num_acl_user, num_acl_group_obj, num_acl_group;
- int num_acl_mask, num_acl_other, i;
-
- /*
- * Verify that the number of entries does not exceed the maximum
- * defined for acl_t.
- * Verify that the correct number of various sorts of ae_tags are
- * present:
- * Exactly one ACL_USER_OBJ
- * Exactly one ACL_GROUP_OBJ
- * Exactly one ACL_OTHER
- * If any ACL_USER or ACL_GROUP entries appear, then exactly one
- * ACL_MASK entry must also appear.
- * Verify that all ae_perm entries are in ACL_PERM_BITS.
- * Verify all ae_tag entries are understood by this implementation.
- * Note: Does not check for uniqueness of qualifier (ae_id) field.
- */
- num_acl_user_obj = num_acl_user = num_acl_group_obj = num_acl_group =
- num_acl_mask = num_acl_other = 0;
- if (acl->acl_cnt > ACL_MAX_ENTRIES || acl->acl_cnt < 0)
- return (EINVAL);
- for (i = 0; i < acl->acl_cnt; i++) {
- /*
- * Check for a valid tag.
- */
- switch(acl->acl_entry[i].ae_tag) {
- case ACL_USER_OBJ:
- acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */
- if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
- return (EINVAL);
- num_acl_user_obj++;
- break;
- case ACL_GROUP_OBJ:
- acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */
- if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
- return (EINVAL);
- num_acl_group_obj++;
- break;
- case ACL_USER:
- if (acl->acl_entry[i].ae_id == ACL_UNDEFINED_ID)
- return (EINVAL);
- num_acl_user++;
- break;
- case ACL_GROUP:
- if (acl->acl_entry[i].ae_id == ACL_UNDEFINED_ID)
- return (EINVAL);
- num_acl_group++;
- break;
- case ACL_OTHER:
- acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */
- if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
- return (EINVAL);
- num_acl_other++;
- break;
- case ACL_MASK:
- acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */
- if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
- return (EINVAL);
- num_acl_mask++;
- break;
- default:
- return (EINVAL);
- }
- /*
- * Check for valid perm entries.
- */
- if ((acl->acl_entry[i].ae_perm | ACL_PERM_BITS) !=
- ACL_PERM_BITS)
- return (EINVAL);
- }
- if ((num_acl_user_obj != 1) || (num_acl_group_obj != 1) ||
- (num_acl_other != 1) || (num_acl_mask != 0 && num_acl_mask != 1))
- return (EINVAL);
- if (((num_acl_group != 0) || (num_acl_user != 0)) &&
- (num_acl_mask != 1))
- return (EINVAL);
- return (0);
-}
-
-/*
- * These calls wrap the real vnode operations, and are called by the
- * syscall code once the syscall has converted the path or file
- * descriptor to a vnode (unlocked). The aclp pointer is assumed
- * still to point to userland, so this should not be consumed within
- * the kernel except by syscall code. Other code should directly
- * invoke VOP_{SET,GET}ACL.
- */
-
-/*
- * Given a vnode, set its ACL.
- */
-static int
-vacl_set_acl(struct thread *td, struct vnode *vp, acl_type_t type,
- struct acl *aclp)
-{
- struct acl inkernacl;
- struct mount *mp;
- int error;
-
- error = copyin(aclp, &inkernacl, sizeof(struct acl));
- if (error)
- return(error);
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error != 0)
- return (error);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
-#ifdef MAC
- error = mac_check_vnode_setacl(td->td_ucred, vp, type, &inkernacl);
- if (error != 0)
- goto out;
-#endif
- error = VOP_SETACL(vp, type, &inkernacl, td->td_ucred, td);
-#ifdef MAC
-out:
-#endif
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- return(error);
-}
-
-/*
- * Given a vnode, get its ACL.
- */
-static int
-vacl_get_acl(struct thread *td, struct vnode *vp, acl_type_t type,
- struct acl *aclp)
-{
- struct acl inkernelacl;
- int error;
-
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
-#ifdef MAC
- error = mac_check_vnode_getacl(td->td_ucred, vp, type);
- if (error != 0)
- goto out;
-#endif
- error = VOP_GETACL(vp, type, &inkernelacl, td->td_ucred, td);
-#ifdef MAC
-out:
-#endif
- VOP_UNLOCK(vp, 0, td);
- if (error == 0)
- error = copyout(&inkernelacl, aclp, sizeof(struct acl));
- return (error);
-}
-
-/*
- * Given a vnode, delete its ACL.
- */
-static int
-vacl_delete(struct thread *td, struct vnode *vp, acl_type_t type)
-{
- struct mount *mp;
- int error;
-
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error)
- return (error);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
-#ifdef MAC
- error = mac_check_vnode_deleteacl(td->td_ucred, vp, type);
- if (error)
- goto out;
-#endif
- error = VOP_SETACL(vp, type, 0, td->td_ucred, td);
-#ifdef MAC
-out:
-#endif
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- return (error);
-}
-
-/*
- * Given a vnode, check whether an ACL is appropriate for it
- */
-static int
-vacl_aclcheck(struct thread *td, struct vnode *vp, acl_type_t type,
- struct acl *aclp)
-{
- struct acl inkernelacl;
- int error;
-
- error = copyin(aclp, &inkernelacl, sizeof(struct acl));
- if (error)
- return(error);
- error = VOP_ACLCHECK(vp, type, &inkernelacl, td->td_ucred, td);
- return (error);
-}
-
-/*
- * syscalls -- convert the path/fd to a vnode, and call vacl_whatever.
- * Don't need to lock, as the vacl_ code will get/release any locks
- * required.
- */
-
-/*
- * Given a file path, get an ACL for it
- *
- * MPSAFE
- */
-int
-__acl_get_file(struct thread *td, struct __acl_get_file_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_get_acl(td, nd.ni_vp, uap->type, uap->aclp);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, get an ACL for it; don't follow links.
- *
- * MPSAFE
- */
-int
-__acl_get_link(struct thread *td, struct __acl_get_link_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_get_acl(td, nd.ni_vp, uap->type, uap->aclp);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, set an ACL for it
- *
- * MPSAFE
- */
-int
-__acl_set_file(struct thread *td, struct __acl_set_file_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_set_acl(td, nd.ni_vp, uap->type, uap->aclp);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, set an ACL for it; don't follow links.
- *
- * MPSAFE
- */
-int
-__acl_set_link(struct thread *td, struct __acl_set_link_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_set_acl(td, nd.ni_vp, uap->type, uap->aclp);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file descriptor, get an ACL for it
- *
- * MPSAFE
- */
-int
-__acl_get_fd(struct thread *td, struct __acl_get_fd_args *uap)
-{
- struct file *fp;
- int error;
-
- mtx_lock(&Giant);
- error = getvnode(td->td_proc->p_fd, uap->filedes, &fp);
- if (error == 0) {
- error = vacl_get_acl(td, fp->f_data, uap->type, uap->aclp);
- fdrop(fp, td);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file descriptor, set an ACL for it
- *
- * MPSAFE
- */
-int
-__acl_set_fd(struct thread *td, struct __acl_set_fd_args *uap)
-{
- struct file *fp;
- int error;
-
- mtx_lock(&Giant);
- error = getvnode(td->td_proc->p_fd, uap->filedes, &fp);
- if (error == 0) {
- error = vacl_set_acl(td, fp->f_data, uap->type, uap->aclp);
- fdrop(fp, td);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, delete an ACL from it.
- *
- * MPSAFE
- */
-int
-__acl_delete_file(struct thread *td, struct __acl_delete_file_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_delete(td, nd.ni_vp, uap->type);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, delete an ACL from it; don't follow links.
- *
- * MPSAFE
- */
-int
-__acl_delete_link(struct thread *td, struct __acl_delete_link_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_delete(td, nd.ni_vp, uap->type);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, delete an ACL from it.
- *
- * MPSAFE
- */
-int
-__acl_delete_fd(struct thread *td, struct __acl_delete_fd_args *uap)
-{
- struct file *fp;
- int error;
-
- mtx_lock(&Giant);
- error = getvnode(td->td_proc->p_fd, uap->filedes, &fp);
- if (error == 0) {
- error = vacl_delete(td, fp->f_data, uap->type);
- fdrop(fp, td);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, check an ACL for it
- *
- * MPSAFE
- */
-int
-__acl_aclcheck_file(struct thread *td, struct __acl_aclcheck_file_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_aclcheck(td, nd.ni_vp, uap->type, uap->aclp);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, check an ACL for it; don't follow links.
- *
- * MPSAFE
- */
-int
-__acl_aclcheck_link(struct thread *td, struct __acl_aclcheck_link_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_aclcheck(td, nd.ni_vp, uap->type, uap->aclp);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file descriptor, check an ACL for it
- *
- * MPSAFE
- */
-int
-__acl_aclcheck_fd(struct thread *td, struct __acl_aclcheck_fd_args *uap)
-{
- struct file *fp;
- int error;
-
- mtx_lock(&Giant);
- error = getvnode(td->td_proc->p_fd, uap->filedes, &fp);
- if (error == 0) {
- error = vacl_aclcheck(td, fp->f_data, uap->type, uap->aclp);
- fdrop(fp, td);
- }
- mtx_unlock(&Giant);
- return (error);
-}
diff --git a/sys/kern/subr_clist.c b/sys/kern/subr_clist.c
deleted file mode 100644
index 165f628e256f..000000000000
--- a/sys/kern/subr_clist.c
+++ /dev/null
@@ -1,696 +0,0 @@
-/*
- * Copyright (c) 1994, David Greenman
- * 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.
- *
- * $FreeBSD$
- */
-
-/*
- * clist support routines
- */
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/tty.h>
-#include <sys/clist.h>
-
-static void clist_init(void *);
-SYSINIT(clist, SI_SUB_CLIST, SI_ORDER_FIRST, clist_init, NULL)
-
-static struct cblock *cfreelist = 0;
-int cfreecount = 0;
-static int cslushcount;
-static int ctotcount;
-
-#ifndef INITIAL_CBLOCKS
-#define INITIAL_CBLOCKS 50
-#endif
-
-static struct cblock *cblock_alloc(void);
-static void cblock_alloc_cblocks(int number);
-static void cblock_free(struct cblock *cblockp);
-static void cblock_free_cblocks(int number);
-
-#include "opt_ddb.h"
-#ifdef DDB
-#include <ddb/ddb.h>
-
-DB_SHOW_COMMAND(cbstat, cbstat)
-{
- int cbsize = CBSIZE;
-
- printf(
- "tot = %d (active = %d, free = %d (reserved = %d, slush = %d))\n",
- ctotcount * cbsize, ctotcount * cbsize - cfreecount, cfreecount,
- cfreecount - cslushcount * cbsize, cslushcount * cbsize);
-}
-#endif /* DDB */
-
-/*
- * Called from init_main.c
- */
-/* ARGSUSED*/
-static void
-clist_init(dummy)
- void *dummy;
-{
- /*
- * Allocate an initial base set of cblocks as a 'slush'.
- * We allocate non-slush cblocks with each initial ttyopen() and
- * deallocate them with each ttyclose().
- * We should adjust the slush allocation. This can't be done in
- * the i/o routines because they are sometimes called from
- * interrupt handlers when it may be unsafe to call malloc().
- */
- cblock_alloc_cblocks(cslushcount = INITIAL_CBLOCKS);
-}
-
-/*
- * Remove a cblock from the cfreelist queue and return a pointer
- * to it.
- */
-static __inline struct cblock *
-cblock_alloc()
-{
- struct cblock *cblockp;
-
- cblockp = cfreelist;
- if (cblockp == NULL)
- panic("clist reservation botch");
- cfreelist = cblockp->c_next;
- cblockp->c_next = NULL;
- cfreecount -= CBSIZE;
- return (cblockp);
-}
-
-/*
- * Add a cblock to the cfreelist queue.
- */
-static __inline void
-cblock_free(cblockp)
- struct cblock *cblockp;
-{
- if (isset(cblockp->c_quote, CBQSIZE * NBBY - 1))
- bzero(cblockp->c_quote, sizeof cblockp->c_quote);
- cblockp->c_next = cfreelist;
- cfreelist = cblockp;
- cfreecount += CBSIZE;
-}
-
-/*
- * Allocate some cblocks for the cfreelist queue.
- */
-static void
-cblock_alloc_cblocks(number)
- int number;
-{
- int i;
- struct cblock *cbp;
-
- for (i = 0; i < number; ++i) {
- cbp = malloc(sizeof *cbp, M_TTYS, M_NOWAIT);
- if (cbp == NULL) {
- printf(
-"cblock_alloc_cblocks: M_NOWAIT malloc failed, trying M_WAITOK\n");
- cbp = malloc(sizeof *cbp, M_TTYS, M_WAITOK);
- }
- /*
- * Freed cblocks have zero quotes and garbage elsewhere.
- * Set the may-have-quote bit to force zeroing the quotes.
- */
- setbit(cbp->c_quote, CBQSIZE * NBBY - 1);
- cblock_free(cbp);
- }
- ctotcount += number;
-}
-
-/*
- * Set the cblock allocation policy for a clist.
- * Must be called in process context at spltty().
- */
-void
-clist_alloc_cblocks(clistp, ccmax, ccreserved)
- struct clist *clistp;
- int ccmax;
- int ccreserved;
-{
- int dcbr;
-
- /*
- * Allow for wasted space at the head.
- */
- if (ccmax != 0)
- ccmax += CBSIZE - 1;
- if (ccreserved != 0)
- ccreserved += CBSIZE - 1;
-
- clistp->c_cbmax = roundup(ccmax, CBSIZE) / CBSIZE;
- dcbr = roundup(ccreserved, CBSIZE) / CBSIZE - clistp->c_cbreserved;
- if (dcbr >= 0)
- cblock_alloc_cblocks(dcbr);
- else {
- if (clistp->c_cbreserved + dcbr < clistp->c_cbcount)
- dcbr = clistp->c_cbcount - clistp->c_cbreserved;
- cblock_free_cblocks(-dcbr);
- }
- clistp->c_cbreserved += dcbr;
-}
-
-/*
- * Free some cblocks from the cfreelist queue back to the
- * system malloc pool.
- */
-static void
-cblock_free_cblocks(number)
- int number;
-{
- int i;
-
- for (i = 0; i < number; ++i)
- free(cblock_alloc(), M_TTYS);
- ctotcount -= number;
-}
-
-/*
- * Free the cblocks reserved for a clist.
- * Must be called at spltty().
- */
-void
-clist_free_cblocks(clistp)
- struct clist *clistp;
-{
- if (clistp->c_cbcount != 0)
- panic("freeing active clist cblocks");
- cblock_free_cblocks(clistp->c_cbreserved);
- clistp->c_cbmax = 0;
- clistp->c_cbreserved = 0;
-}
-
-/*
- * Get a character from the head of a clist.
- */
-int
-getc(clistp)
- struct clist *clistp;
-{
- int chr = -1;
- int s;
- struct cblock *cblockp;
-
- s = spltty();
-
- /* If there are characters in the list, get one */
- if (clistp->c_cc) {
- cblockp = (struct cblock *)((intptr_t)clistp->c_cf & ~CROUND);
- chr = (u_char)*clistp->c_cf;
-
- /*
- * If this char is quoted, set the flag.
- */
- if (isset(cblockp->c_quote, clistp->c_cf - (char *)cblockp->c_info))
- chr |= TTY_QUOTE;
-
- /*
- * Advance to next character.
- */
- clistp->c_cf++;
- clistp->c_cc--;
- /*
- * If we have advanced the 'first' character pointer
- * past the end of this cblock, advance to the next one.
- * If there are no more characters, set the first and
- * last pointers to NULL. In either case, free the
- * current cblock.
- */
- if ((clistp->c_cf >= (char *)(cblockp+1)) || (clistp->c_cc == 0)) {
- if (clistp->c_cc > 0) {
- clistp->c_cf = cblockp->c_next->c_info;
- } else {
- clistp->c_cf = clistp->c_cl = NULL;
- }
- cblock_free(cblockp);
- if (--clistp->c_cbcount >= clistp->c_cbreserved)
- ++cslushcount;
- }
- }
-
- splx(s);
- return (chr);
-}
-
-/*
- * Copy 'amount' of chars, beginning at head of clist 'clistp' to
- * destination linear buffer 'dest'. Return number of characters
- * actually copied.
- */
-int
-q_to_b(clistp, dest, amount)
- struct clist *clistp;
- char *dest;
- int amount;
-{
- struct cblock *cblockp;
- struct cblock *cblockn;
- char *dest_orig = dest;
- int numc;
- int s;
-
- s = spltty();
-
- while (clistp && amount && (clistp->c_cc > 0)) {
- cblockp = (struct cblock *)((intptr_t)clistp->c_cf & ~CROUND);
- cblockn = cblockp + 1; /* pointer arithmetic! */
- numc = min(amount, (char *)cblockn - clistp->c_cf);
- numc = min(numc, clistp->c_cc);
- bcopy(clistp->c_cf, dest, numc);
- amount -= numc;
- clistp->c_cf += numc;
- clistp->c_cc -= numc;
- dest += numc;
- /*
- * If this cblock has been emptied, advance to the next
- * one. If there are no more characters, set the first
- * and last pointer to NULL. In either case, free the
- * current cblock.
- */
- if ((clistp->c_cf >= (char *)cblockn) || (clistp->c_cc == 0)) {
- if (clistp->c_cc > 0) {
- clistp->c_cf = cblockp->c_next->c_info;
- } else {
- clistp->c_cf = clistp->c_cl = NULL;
- }
- cblock_free(cblockp);
- if (--clistp->c_cbcount >= clistp->c_cbreserved)
- ++cslushcount;
- }
- }
-
- splx(s);
- return (dest - dest_orig);
-}
-
-/*
- * Flush 'amount' of chars, beginning at head of clist 'clistp'.
- */
-void
-ndflush(clistp, amount)
- struct clist *clistp;
- int amount;
-{
- struct cblock *cblockp;
- struct cblock *cblockn;
- int numc;
- int s;
-
- s = spltty();
-
- while (amount && (clistp->c_cc > 0)) {
- cblockp = (struct cblock *)((intptr_t)clistp->c_cf & ~CROUND);
- cblockn = cblockp + 1; /* pointer arithmetic! */
- numc = min(amount, (char *)cblockn - clistp->c_cf);
- numc = min(numc, clistp->c_cc);
- amount -= numc;
- clistp->c_cf += numc;
- clistp->c_cc -= numc;
- /*
- * If this cblock has been emptied, advance to the next
- * one. If there are no more characters, set the first
- * and last pointer to NULL. In either case, free the
- * current cblock.
- */
- if ((clistp->c_cf >= (char *)cblockn) || (clistp->c_cc == 0)) {
- if (clistp->c_cc > 0) {
- clistp->c_cf = cblockp->c_next->c_info;
- } else {
- clistp->c_cf = clistp->c_cl = NULL;
- }
- cblock_free(cblockp);
- if (--clistp->c_cbcount >= clistp->c_cbreserved)
- ++cslushcount;
- }
- }
-
- splx(s);
-}
-
-/*
- * Add a character to the end of a clist. Return -1 is no
- * more clists, or 0 for success.
- */
-int
-putc(chr, clistp)
- int chr;
- struct clist *clistp;
-{
- struct cblock *cblockp;
- int s;
-
- s = spltty();
-
- if (clistp->c_cl == NULL) {
- if (clistp->c_cbreserved < 1) {
- splx(s);
- printf("putc to a clist with no reserved cblocks\n");
- return (-1); /* nothing done */
- }
- cblockp = cblock_alloc();
- clistp->c_cbcount = 1;
- clistp->c_cf = clistp->c_cl = cblockp->c_info;
- clistp->c_cc = 0;
- } else {
- cblockp = (struct cblock *)((intptr_t)clistp->c_cl & ~CROUND);
- if (((intptr_t)clistp->c_cl & CROUND) == 0) {
- struct cblock *prev = (cblockp - 1);
-
- if (clistp->c_cbcount >= clistp->c_cbreserved) {
- if (clistp->c_cbcount >= clistp->c_cbmax
- || cslushcount <= 0) {
- splx(s);
- return (-1);
- }
- --cslushcount;
- }
- cblockp = cblock_alloc();
- clistp->c_cbcount++;
- prev->c_next = cblockp;
- clistp->c_cl = cblockp->c_info;
- }
- }
-
- /*
- * If this character is quoted, set the quote bit, if not, clear it.
- */
- if (chr & TTY_QUOTE) {
- setbit(cblockp->c_quote, clistp->c_cl - (char *)cblockp->c_info);
- /*
- * Use one of the spare quote bits to record that something
- * may be quoted.
- */
- setbit(cblockp->c_quote, CBQSIZE * NBBY - 1);
- } else
- clrbit(cblockp->c_quote, clistp->c_cl - (char *)cblockp->c_info);
-
- *clistp->c_cl++ = chr;
- clistp->c_cc++;
-
- splx(s);
- return (0);
-}
-
-/*
- * Copy data from linear buffer to clist chain. Return the
- * number of characters not copied.
- */
-int
-b_to_q(src, amount, clistp)
- char *src;
- int amount;
- struct clist *clistp;
-{
- struct cblock *cblockp;
- char *firstbyte, *lastbyte;
- u_char startmask, endmask;
- int startbit, endbit, num_between, numc;
- int s;
-
- /*
- * Avoid allocating an initial cblock and then not using it.
- * c_cc == 0 must imply c_cbount == 0.
- */
- if (amount <= 0)
- return (amount);
-
- s = spltty();
-
- /*
- * If there are no cblocks assigned to this clist yet,
- * then get one.
- */
- if (clistp->c_cl == NULL) {
- if (clistp->c_cbreserved < 1) {
- splx(s);
- printf("b_to_q to a clist with no reserved cblocks.\n");
- return (amount); /* nothing done */
- }
- cblockp = cblock_alloc();
- clistp->c_cbcount = 1;
- clistp->c_cf = clistp->c_cl = cblockp->c_info;
- clistp->c_cc = 0;
- } else {
- cblockp = (struct cblock *)((intptr_t)clistp->c_cl & ~CROUND);
- }
-
- while (amount) {
- /*
- * Get another cblock if needed.
- */
- if (((intptr_t)clistp->c_cl & CROUND) == 0) {
- struct cblock *prev = cblockp - 1;
-
- if (clistp->c_cbcount >= clistp->c_cbreserved) {
- if (clistp->c_cbcount >= clistp->c_cbmax
- || cslushcount <= 0) {
- splx(s);
- return (amount);
- }
- --cslushcount;
- }
- cblockp = cblock_alloc();
- clistp->c_cbcount++;
- prev->c_next = cblockp;
- clistp->c_cl = cblockp->c_info;
- }
-
- /*
- * Copy a chunk of the linear buffer up to the end
- * of this cblock.
- */
- numc = min(amount, (char *)(cblockp + 1) - clistp->c_cl);
- bcopy(src, clistp->c_cl, numc);
-
- /*
- * Clear quote bits if they aren't known to be clear.
- * The following could probably be made into a separate
- * "bitzero()" routine, but why bother?
- */
- if (isset(cblockp->c_quote, CBQSIZE * NBBY - 1)) {
- startbit = clistp->c_cl - (char *)cblockp->c_info;
- endbit = startbit + numc - 1;
-
- firstbyte = (u_char *)cblockp->c_quote + (startbit / NBBY);
- lastbyte = (u_char *)cblockp->c_quote + (endbit / NBBY);
-
- /*
- * Calculate mask of bits to preserve in first and
- * last bytes.
- */
- startmask = NBBY - (startbit % NBBY);
- startmask = 0xff >> startmask;
- endmask = (endbit % NBBY);
- endmask = 0xff << (endmask + 1);
-
- if (firstbyte != lastbyte) {
- *firstbyte &= startmask;
- *lastbyte &= endmask;
-
- num_between = lastbyte - firstbyte - 1;
- if (num_between)
- bzero(firstbyte + 1, num_between);
- } else {
- *firstbyte &= (startmask | endmask);
- }
- }
-
- /*
- * ...and update pointer for the next chunk.
- */
- src += numc;
- clistp->c_cl += numc;
- clistp->c_cc += numc;
- amount -= numc;
- /*
- * If we go through the loop again, it's always
- * for data in the next cblock, so by adding one (cblock),
- * (which makes the pointer 1 beyond the end of this
- * cblock) we prepare for the assignment of 'prev'
- * above.
- */
- cblockp += 1;
-
- }
-
- splx(s);
- return (amount);
-}
-
-/*
- * Get the next character in the clist. Store it at dst. Don't
- * advance any clist pointers, but return a pointer to the next
- * character position.
- */
-char *
-nextc(clistp, cp, dst)
- struct clist *clistp;
- char *cp;
- int *dst;
-{
- struct cblock *cblockp;
-
- ++cp;
- /*
- * See if the next character is beyond the end of
- * the clist.
- */
- if (clistp->c_cc && (cp != clistp->c_cl)) {
- /*
- * If the next character is beyond the end of this
- * cblock, advance to the next cblock.
- */
- if (((intptr_t)cp & CROUND) == 0)
- cp = ((struct cblock *)cp - 1)->c_next->c_info;
- cblockp = (struct cblock *)((intptr_t)cp & ~CROUND);
-
- /*
- * Get the character. Set the quote flag if this character
- * is quoted.
- */
- *dst = (u_char)*cp | (isset(cblockp->c_quote, cp - (char *)cblockp->c_info) ? TTY_QUOTE : 0);
-
- return (cp);
- }
-
- return (NULL);
-}
-
-/*
- * "Unput" a character from a clist.
- */
-int
-unputc(clistp)
- struct clist *clistp;
-{
- struct cblock *cblockp = 0, *cbp = 0;
- int s;
- int chr = -1;
-
-
- s = spltty();
-
- if (clistp->c_cc) {
- --clistp->c_cc;
- --clistp->c_cl;
-
- chr = (u_char)*clistp->c_cl;
-
- cblockp = (struct cblock *)((intptr_t)clistp->c_cl & ~CROUND);
-
- /*
- * Set quote flag if this character was quoted.
- */
- if (isset(cblockp->c_quote, (u_char *)clistp->c_cl - cblockp->c_info))
- chr |= TTY_QUOTE;
-
- /*
- * If all of the characters have been unput in this
- * cblock, then find the previous one and free this
- * one.
- */
- if (clistp->c_cc && (clistp->c_cl <= (char *)cblockp->c_info)) {
- cbp = (struct cblock *)((intptr_t)clistp->c_cf & ~CROUND);
-
- while (cbp->c_next != cblockp)
- cbp = cbp->c_next;
-
- /*
- * When the previous cblock is at the end, the 'last'
- * pointer always points (invalidly) one past.
- */
- clistp->c_cl = (char *)(cbp+1);
- cblock_free(cblockp);
- if (--clistp->c_cbcount >= clistp->c_cbreserved)
- ++cslushcount;
- cbp->c_next = NULL;
- }
- }
-
- /*
- * If there are no more characters on the list, then
- * free the last cblock.
- */
- if ((clistp->c_cc == 0) && clistp->c_cl) {
- cblockp = (struct cblock *)((intptr_t)clistp->c_cl & ~CROUND);
- cblock_free(cblockp);
- if (--clistp->c_cbcount >= clistp->c_cbreserved)
- ++cslushcount;
- clistp->c_cf = clistp->c_cl = NULL;
- }
-
- splx(s);
- return (chr);
-}
-
-/*
- * Move characters in source clist to destination clist,
- * preserving quote bits.
- */
-void
-catq(src_clistp, dest_clistp)
- struct clist *src_clistp, *dest_clistp;
-{
- int chr, s;
-
- s = spltty();
- /*
- * If the destination clist is empty (has no cblocks atttached),
- * and there are no possible complications with the resource counters,
- * then we simply assign the current clist to the destination.
- */
- if (!dest_clistp->c_cf
- && src_clistp->c_cbcount <= src_clistp->c_cbmax
- && src_clistp->c_cbcount <= dest_clistp->c_cbmax) {
- dest_clistp->c_cf = src_clistp->c_cf;
- dest_clistp->c_cl = src_clistp->c_cl;
- src_clistp->c_cf = src_clistp->c_cl = NULL;
-
- dest_clistp->c_cc = src_clistp->c_cc;
- src_clistp->c_cc = 0;
- dest_clistp->c_cbcount = src_clistp->c_cbcount;
- src_clistp->c_cbcount = 0;
-
- splx(s);
- return;
- }
-
- splx(s);
-
- /*
- * XXX This should probably be optimized to more than one
- * character at a time.
- */
- while ((chr = getc(src_clistp)) != -1)
- putc(chr, dest_clistp);
-}
diff --git a/sys/kern/subr_rtc.c b/sys/kern/subr_rtc.c
deleted file mode 100644
index 19df90d75c19..000000000000
--- a/sys/kern/subr_rtc.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * Copyright (c) 1988 University of Utah.
- * Copyright (c) 1982, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * the Systems Programming Group of the University of Utah Computer
- * Science Department.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: Utah $Hdr: clock.c 1.18 91/01/21$
- * from: @(#)clock.c 8.2 (Berkeley) 1/12/94
- * from: NetBSD: clock_subr.c,v 1.6 2001/07/07 17:04:02 thorpej Exp
- * and
- * from: src/sys/i386/isa/clock.c,v 1.176 2001/09/04
- *
- * $FreeBSD$
- */
-
-/*
- * Helpers for time-of-day clocks. This is useful for architectures that need
- * support multiple models of such clocks, and generally serves to make the
- * code more machine-independent.
- * If the clock in question can also be used as a time counter, the driver
- * needs to initiate this.
- * This code is not yet used by all architectures.
- */
-
-/*
- * Generic routines to convert between a POSIX date
- * (seconds since 1/1/1970) and yr/mo/day/hr/min/sec
- * Derived from NetBSD arch/hp300/hp300/clock.c
- */
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/clock.h>
-#include <sys/sysctl.h>
-#include <sys/timetc.h>
-
-/* XXX: for the CPU_* sysctl OID constants. */
-#include <machine/cpu.h>
-
-#include "clock_if.h"
-
-static __inline int leapyear(int year);
-static int sysctl_machdep_adjkerntz(SYSCTL_HANDLER_ARGS);
-
-#define FEBRUARY 2
-#define days_in_year(y) (leapyear(y) ? 366 : 365)
-#define days_in_month(y, m) \
- (month_days[(m) - 1] + (m == FEBRUARY ? leapyear(y) : 0))
-/* Day of week. Days are counted from 1/1/1970, which was a Thursday */
-#define day_of_week(days) (((days) + 4) % 7)
-
-static const int month_days[12] = {
- 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
-};
-
-static device_t clock_dev = NULL;
-static long clock_res;
-
-int adjkerntz; /* local offset from GMT in seconds */
-int disable_rtc_set; /* disable resettodr() if != 0 */
-int wall_cmos_clock; /* wall CMOS clock assumed if != 0 */
-
-/*
- * These have traditionally been in machdep, but should probably be moved to
- * kern.
- */
-SYSCTL_PROC(_machdep, CPU_ADJKERNTZ, adjkerntz, CTLTYPE_INT|CTLFLAG_RW,
- &adjkerntz, 0, sysctl_machdep_adjkerntz, "I", "");
-
-SYSCTL_INT(_machdep, CPU_DISRTCSET, disable_rtc_set,
- CTLFLAG_RW, &disable_rtc_set, 0, "");
-
-SYSCTL_INT(_machdep, CPU_WALLCLOCK, wall_cmos_clock,
- CTLFLAG_RW, &wall_cmos_clock, 0, "");
-
-static int
-sysctl_machdep_adjkerntz(SYSCTL_HANDLER_ARGS)
-{
- int error;
- error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2,
- req);
- if (!error && req->newptr)
- resettodr();
- return (error);
-}
-
-/*
- * This inline avoids some unnecessary modulo operations
- * as compared with the usual macro:
- * ( ((year % 4) == 0 &&
- * (year % 100) != 0) ||
- * ((year % 400) == 0) )
- * It is otherwise equivalent.
- */
-static __inline int
-leapyear(int year)
-{
- int rv = 0;
-
- if ((year & 3) == 0) {
- rv = 1;
- if ((year % 100) == 0) {
- rv = 0;
- if ((year % 400) == 0)
- rv = 1;
- }
- }
- return (rv);
-}
-
-int
-clock_ct_to_ts(struct clocktime *ct, struct timespec *ts)
-{
- time_t secs;
- int i, year, days;
-
- year = ct->year;
-
- /* Sanity checks. */
- if (ct->mon < 1 || ct->mon > 12 || ct->day < 1 ||
- ct->day > days_in_month(year, ct->mon) ||
- ct->hour > 23 || ct->min > 59 || ct->sec > 59 ||
- ct->year > 2037) /* time_t overflow */
- return (EINVAL);
-
- /*
- * Compute days since start of time
- * First from years, then from months.
- */
- days = 0;
- for (i = POSIX_BASE_YEAR; i < year; i++)
- days += days_in_year(i);
-
- /* Months */
- for (i = 1; i < ct->mon; i++)
- days += days_in_month(year, i);
- days += (ct->day - 1);
-
- /* Another sanity check. */
- if (ct->dow != -1 && ct->dow != day_of_week(days))
- return (EINVAL);
-
- /* Add hours, minutes, seconds. */
- secs = ((days * 24 + ct->hour) * 60 + ct->min) * 60 + ct->sec;
-
- ts->tv_sec = secs;
- ts->tv_nsec = ct->nsec;
- return (0);
-}
-
-void
-clock_ts_to_ct(struct timespec *ts, struct clocktime *ct)
-{
- int i, year, days;
- time_t rsec; /* remainder seconds */
- time_t secs;
-
- secs = ts->tv_sec;
- days = secs / SECDAY;
- rsec = secs % SECDAY;
-
- ct->dow = day_of_week(days);
-
- /* Subtract out whole years, counting them in i. */
- for (year = POSIX_BASE_YEAR; days >= days_in_year(year); year++)
- days -= days_in_year(year);
- ct->year = year;
-
- /* Subtract out whole months, counting them in i. */
- for (i = 1; days >= days_in_month(year, i); i++)
- days -= days_in_month(year, i);
- ct->mon = i;
-
- /* Days are what is left over (+1) from all that. */
- ct->day = days + 1;
-
- /* Hours, minutes, seconds are easy */
- ct->hour = rsec / 3600;
- rsec = rsec % 3600;
- ct->min = rsec / 60;
- rsec = rsec % 60;
- ct->sec = rsec;
- ct->nsec = ts->tv_nsec;
-}
-
-void
-clock_register(device_t dev, long res)
-{
-
- if (clock_dev != NULL) {
- if (clock_res > res) {
- if (bootverbose) {
- device_printf(dev, "not installed as "
- "time-of-day clock: clock %s has higher "
- "resolution\n", device_get_name(clock_dev));
- }
- return;
- } else {
- if (bootverbose) {
- device_printf(clock_dev, "removed as "
- "time-of-day clock: clock %s has higher "
- "resolution\n", device_get_name(dev));
- }
- }
- }
- clock_dev = dev;
- clock_res = res;
- if (bootverbose) {
- device_printf(dev, "registered as a time-of-day clock "
- "(resolution %ldus)\n", res);
- }
-}
-
-/*
- * inittodr and settodr derived from the i386 versions written
- * by Christoph Robitschko <chmr@edvz.tu-graz.ac.at>, reintroduced and
- * updated by Chris Stenton <chris@gnome.co.uk> 8/10/94
- */
-
-/*
- * Initialize the time of day register, based on the time base which is, e.g.
- * from a filesystem.
- */
-void
-inittodr(time_t base)
-{
- struct timespec diff, ref, ts;
- int error;
-
- if (base) {
- ref.tv_sec = base;
- ref.tv_nsec = 0;
- tc_setclock(&ref);
- }
-
- if (clock_dev == NULL) {
- printf("warning: no time-of-day clock registered, system time "
- "will not be set accurately\n");
- return;
- }
- error = CLOCK_GETTIME(clock_dev, &ts);
- if (error != 0 && error != EINVAL) {
- printf("warning: clock_gettime failed (%d), the system time "
- "will not be set accurately\n", error);
- return;
- }
- if (error == EINVAL || ts.tv_sec < 0) {
- printf("Invalid time in real time clock.\n");
- printf("Check and reset the date immediately!\n");
- }
-
- ts.tv_sec += tz_minuteswest * 60 +
- (wall_cmos_clock ? adjkerntz : 0);
-
- if (timespeccmp(&ref, &ts, >)) {
- diff = ref;
- timespecsub(&ref, &ts);
- } else {
- diff = ts;
- timespecsub(&diff, &ref);
- }
- if (ts.tv_sec >= 2) {
- /* badly off, adjust it */
- tc_setclock(&ts);
- }
-}
-
-/*
- * Write system time back to RTC
- */
-void
-resettodr()
-{
- struct timespec ts;
- int error;
-
- if (disable_rtc_set || clock_dev == NULL)
- return;
-
- getnanotime(&ts);
- ts.tv_sec -= tz_minuteswest * 60 + (wall_cmos_clock ? adjkerntz : 0);
- if ((error = CLOCK_SETTIME(clock_dev, &ts)) != 0) {
- printf("warning: clock_settime failed (%d), time-of-day clock "
- "not adjusted to system time\n", error);
- return;
- }
-}
diff --git a/sys/kern/subr_turnstile.c b/sys/kern/subr_turnstile.c
deleted file mode 100644
index a2617f9621ee..000000000000
--- a/sys/kern/subr_turnstile.c
+++ /dev/null
@@ -1,987 +0,0 @@
-/*-
- * Copyright (c) 1998 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_witness.c,v 1.1.2.20 2000/04/27 03:10:27 cp Exp $
- * and BSDI $Id: synch_machdep.c,v 2.3.2.39 2000/04/27 03:10:25 cp Exp $
- * $FreeBSD$
- */
-
-/*
- * Machine independent bits of mutex implementation.
- */
-
-#include "opt_adaptive_mutexes.h"
-#include "opt_ddb.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/kernel.h>
-#include <sys/ktr.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/resourcevar.h>
-#include <sys/sched.h>
-#include <sys/sbuf.h>
-#include <sys/sysctl.h>
-#include <sys/vmmeter.h>
-
-#include <machine/atomic.h>
-#include <machine/bus.h>
-#include <machine/clock.h>
-#include <machine/cpu.h>
-
-#include <ddb/ddb.h>
-
-#include <vm/vm.h>
-#include <vm/vm_extern.h>
-
-/*
- * Internal utility macros.
- */
-#define mtx_unowned(m) ((m)->mtx_lock == MTX_UNOWNED)
-
-#define mtx_owner(m) (mtx_unowned((m)) ? NULL \
- : (struct thread *)((m)->mtx_lock & MTX_FLAGMASK))
-
-/*
- * Lock classes for sleep and spin mutexes.
- */
-struct lock_class lock_class_mtx_sleep = {
- "sleep mutex",
- LC_SLEEPLOCK | LC_RECURSABLE
-};
-struct lock_class lock_class_mtx_spin = {
- "spin mutex",
- LC_SPINLOCK | LC_RECURSABLE
-};
-
-/*
- * System-wide mutexes
- */
-struct mtx sched_lock;
-struct mtx Giant;
-
-/*
- * Prototypes for non-exported routines.
- */
-static void propagate_priority(struct thread *);
-
-static void
-propagate_priority(struct thread *td)
-{
- int pri = td->td_priority;
- struct mtx *m = td->td_blocked;
-
- mtx_assert(&sched_lock, MA_OWNED);
- for (;;) {
- struct thread *td1;
-
- td = mtx_owner(m);
-
- if (td == NULL) {
- /*
- * This really isn't quite right. Really
- * ought to bump priority of thread that
- * next acquires the mutex.
- */
- MPASS(m->mtx_lock == MTX_CONTESTED);
- return;
- }
-
- MPASS(td->td_proc != NULL);
- MPASS(td->td_proc->p_magic == P_MAGIC);
- KASSERT(!TD_IS_SLEEPING(td), ("sleeping thread owns a mutex"));
- if (td->td_priority <= pri) /* lower is higher priority */
- return;
-
-
- /*
- * If lock holder is actually running, just bump priority.
- */
- if (TD_IS_RUNNING(td)) {
- td->td_priority = pri;
- return;
- }
-
-#ifndef SMP
- /*
- * For UP, we check to see if td is curthread (this shouldn't
- * ever happen however as it would mean we are in a deadlock.)
- */
- KASSERT(td != curthread, ("Deadlock detected"));
-#endif
-
- /*
- * If on run queue move to new run queue, and quit.
- * XXXKSE this gets a lot more complicated under threads
- * but try anyhow.
- */
- if (TD_ON_RUNQ(td)) {
- MPASS(td->td_blocked == NULL);
- sched_prio(td, pri);
- return;
- }
- /*
- * Adjust for any other cases.
- */
- td->td_priority = pri;
-
- /*
- * If we aren't blocked on a mutex, we should be.
- */
- KASSERT(TD_ON_LOCK(td), (
- "process %d(%s):%d holds %s but isn't blocked on a mutex\n",
- td->td_proc->p_pid, td->td_proc->p_comm, td->td_state,
- m->mtx_object.lo_name));
-
- /*
- * Pick up the mutex that td is blocked on.
- */
- m = td->td_blocked;
- MPASS(m != NULL);
-
- /*
- * Check if the thread needs to be moved up on
- * the blocked chain
- */
- if (td == TAILQ_FIRST(&m->mtx_blocked)) {
- continue;
- }
-
- td1 = TAILQ_PREV(td, threadqueue, td_lockq);
- if (td1->td_priority <= pri) {
- continue;
- }
-
- /*
- * Remove thread from blocked chain and determine where
- * it should be moved up to. Since we know that td1 has
- * a lower priority than td, we know that at least one
- * thread in the chain has a lower priority and that
- * td1 will thus not be NULL after the loop.
- */
- TAILQ_REMOVE(&m->mtx_blocked, td, td_lockq);
- TAILQ_FOREACH(td1, &m->mtx_blocked, td_lockq) {
- MPASS(td1->td_proc->p_magic == P_MAGIC);
- if (td1->td_priority > pri)
- break;
- }
-
- MPASS(td1 != NULL);
- TAILQ_INSERT_BEFORE(td1, td, td_lockq);
- CTR4(KTR_LOCK,
- "propagate_priority: p %p moved before %p on [%p] %s",
- td, td1, m, m->mtx_object.lo_name);
- }
-}
-
-#ifdef MUTEX_PROFILING
-SYSCTL_NODE(_debug, OID_AUTO, mutex, CTLFLAG_RD, NULL, "mutex debugging");
-SYSCTL_NODE(_debug_mutex, OID_AUTO, prof, CTLFLAG_RD, NULL, "mutex profiling");
-static int mutex_prof_enable = 0;
-SYSCTL_INT(_debug_mutex_prof, OID_AUTO, enable, CTLFLAG_RW,
- &mutex_prof_enable, 0, "Enable tracing of mutex holdtime");
-
-struct mutex_prof {
- const char *name;
- const char *file;
- int line;
- uintmax_t cnt_max;
- uintmax_t cnt_tot;
- uintmax_t cnt_cur;
- struct mutex_prof *next;
-};
-
-/*
- * mprof_buf is a static pool of profiling records to avoid possible
- * reentrance of the memory allocation functions.
- *
- * Note: NUM_MPROF_BUFFERS must be smaller than MPROF_HASH_SIZE.
- */
-#define NUM_MPROF_BUFFERS 1000
-static struct mutex_prof mprof_buf[NUM_MPROF_BUFFERS];
-static int first_free_mprof_buf;
-#define MPROF_HASH_SIZE 1009
-static struct mutex_prof *mprof_hash[MPROF_HASH_SIZE];
-/* SWAG: sbuf size = avg stat. line size * number of locks */
-#define MPROF_SBUF_SIZE 256 * 400
-
-static int mutex_prof_acquisitions;
-SYSCTL_INT(_debug_mutex_prof, OID_AUTO, acquisitions, CTLFLAG_RD,
- &mutex_prof_acquisitions, 0, "Number of mutex acquistions recorded");
-static int mutex_prof_records;
-SYSCTL_INT(_debug_mutex_prof, OID_AUTO, records, CTLFLAG_RD,
- &mutex_prof_records, 0, "Number of profiling records");
-static int mutex_prof_maxrecords = NUM_MPROF_BUFFERS;
-SYSCTL_INT(_debug_mutex_prof, OID_AUTO, maxrecords, CTLFLAG_RD,
- &mutex_prof_maxrecords, 0, "Maximum number of profiling records");
-static int mutex_prof_rejected;
-SYSCTL_INT(_debug_mutex_prof, OID_AUTO, rejected, CTLFLAG_RD,
- &mutex_prof_rejected, 0, "Number of rejected profiling records");
-static int mutex_prof_hashsize = MPROF_HASH_SIZE;
-SYSCTL_INT(_debug_mutex_prof, OID_AUTO, hashsize, CTLFLAG_RD,
- &mutex_prof_hashsize, 0, "Hash size");
-static int mutex_prof_collisions = 0;
-SYSCTL_INT(_debug_mutex_prof, OID_AUTO, collisions, CTLFLAG_RD,
- &mutex_prof_collisions, 0, "Number of hash collisions");
-
-/*
- * mprof_mtx protects the profiling buffers and the hash.
- */
-static struct mtx mprof_mtx;
-MTX_SYSINIT(mprof, &mprof_mtx, "mutex profiling lock", MTX_SPIN | MTX_QUIET);
-
-static u_int64_t
-nanoseconds(void)
-{
- struct timespec tv;
-
- nanotime(&tv);
- return (tv.tv_sec * (u_int64_t)1000000000 + tv.tv_nsec);
-}
-
-static int
-dump_mutex_prof_stats(SYSCTL_HANDLER_ARGS)
-{
- struct sbuf *sb;
- int error, i;
- static int multiplier = 1;
-
- if (first_free_mprof_buf == 0)
- return (SYSCTL_OUT(req, "No locking recorded",
- sizeof("No locking recorded")));
-
-retry_sbufops:
- sb = sbuf_new(NULL, NULL, MPROF_SBUF_SIZE * multiplier, SBUF_FIXEDLEN);
- sbuf_printf(sb, "%6s %12s %11s %5s %s\n",
- "max", "total", "count", "avg", "name");
- /*
- * XXX this spinlock seems to be by far the largest perpetrator
- * of spinlock latency (1.6 msec on an Athlon1600 was recorded
- * even before I pessimized it further by moving the average
- * computation here).
- */
- mtx_lock_spin(&mprof_mtx);
- for (i = 0; i < first_free_mprof_buf; ++i) {
- sbuf_printf(sb, "%6ju %12ju %11ju %5ju %s:%d (%s)\n",
- mprof_buf[i].cnt_max / 1000,
- mprof_buf[i].cnt_tot / 1000,
- mprof_buf[i].cnt_cur,
- mprof_buf[i].cnt_cur == 0 ? (uintmax_t)0 :
- mprof_buf[i].cnt_tot / (mprof_buf[i].cnt_cur * 1000),
- mprof_buf[i].file, mprof_buf[i].line, mprof_buf[i].name);
- if (sbuf_overflowed(sb)) {
- mtx_unlock_spin(&mprof_mtx);
- sbuf_delete(sb);
- multiplier++;
- goto retry_sbufops;
- }
- }
- mtx_unlock_spin(&mprof_mtx);
- sbuf_finish(sb);
- error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1);
- sbuf_delete(sb);
- return (error);
-}
-SYSCTL_PROC(_debug_mutex_prof, OID_AUTO, stats, CTLTYPE_STRING | CTLFLAG_RD,
- NULL, 0, dump_mutex_prof_stats, "A", "Mutex profiling statistics");
-#endif
-
-/*
- * Function versions of the inlined __mtx_* macros. These are used by
- * modules and can also be called from assembly language if needed.
- */
-void
-_mtx_lock_flags(struct mtx *m, int opts, const char *file, int line)
-{
-
- MPASS(curthread != NULL);
- KASSERT(m->mtx_object.lo_class == &lock_class_mtx_sleep,
- ("mtx_lock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name,
- file, line));
- _get_sleep_lock(m, curthread, opts, file, line);
- LOCK_LOG_LOCK("LOCK", &m->mtx_object, opts, m->mtx_recurse, file,
- line);
- WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line);
-#ifdef MUTEX_PROFILING
- /* don't reset the timer when/if recursing */
- if (m->mtx_acqtime == 0) {
- m->mtx_filename = file;
- m->mtx_lineno = line;
- m->mtx_acqtime = mutex_prof_enable ? nanoseconds() : 0;
- ++mutex_prof_acquisitions;
- }
-#endif
-}
-
-void
-_mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line)
-{
-
- MPASS(curthread != NULL);
- KASSERT(m->mtx_object.lo_class == &lock_class_mtx_sleep,
- ("mtx_unlock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name,
- file, line));
- WITNESS_UNLOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line);
- LOCK_LOG_LOCK("UNLOCK", &m->mtx_object, opts, m->mtx_recurse, file,
- line);
- mtx_assert(m, MA_OWNED);
-#ifdef MUTEX_PROFILING
- if (m->mtx_acqtime != 0) {
- static const char *unknown = "(unknown)";
- struct mutex_prof *mpp;
- u_int64_t acqtime, now;
- const char *p, *q;
- volatile u_int hash;
-
- now = nanoseconds();
- acqtime = m->mtx_acqtime;
- m->mtx_acqtime = 0;
- if (now <= acqtime)
- goto out;
- for (p = m->mtx_filename;
- p != NULL && strncmp(p, "../", 3) == 0; p += 3)
- /* nothing */ ;
- if (p == NULL || *p == '\0')
- p = unknown;
- for (hash = m->mtx_lineno, q = p; *q != '\0'; ++q)
- hash = (hash * 2 + *q) % MPROF_HASH_SIZE;
- mtx_lock_spin(&mprof_mtx);
- for (mpp = mprof_hash[hash]; mpp != NULL; mpp = mpp->next)
- if (mpp->line == m->mtx_lineno &&
- strcmp(mpp->file, p) == 0)
- break;
- if (mpp == NULL) {
- /* Just exit if we cannot get a trace buffer */
- if (first_free_mprof_buf >= NUM_MPROF_BUFFERS) {
- ++mutex_prof_rejected;
- goto unlock;
- }
- mpp = &mprof_buf[first_free_mprof_buf++];
- mpp->name = mtx_name(m);
- mpp->file = p;
- mpp->line = m->mtx_lineno;
- mpp->next = mprof_hash[hash];
- if (mprof_hash[hash] != NULL)
- ++mutex_prof_collisions;
- mprof_hash[hash] = mpp;
- ++mutex_prof_records;
- }
- /*
- * Record if the mutex has been held longer now than ever
- * before.
- */
- if (now - acqtime > mpp->cnt_max)
- mpp->cnt_max = now - acqtime;
- mpp->cnt_tot += now - acqtime;
- mpp->cnt_cur++;
-unlock:
- mtx_unlock_spin(&mprof_mtx);
- }
-out:
-#endif
- _rel_sleep_lock(m, curthread, opts, file, line);
-}
-
-void
-_mtx_lock_spin_flags(struct mtx *m, int opts, const char *file, int line)
-{
-
- MPASS(curthread != NULL);
- KASSERT(m->mtx_object.lo_class == &lock_class_mtx_spin,
- ("mtx_lock_spin() of sleep mutex %s @ %s:%d",
- m->mtx_object.lo_name, file, line));
-#if defined(SMP) || LOCK_DEBUG > 0 || 1
- _get_spin_lock(m, curthread, opts, file, line);
-#else
- critical_enter();
-#endif
- LOCK_LOG_LOCK("LOCK", &m->mtx_object, opts, m->mtx_recurse, file,
- line);
- WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line);
-}
-
-void
-_mtx_unlock_spin_flags(struct mtx *m, int opts, const char *file, int line)
-{
-
- MPASS(curthread != NULL);
- KASSERT(m->mtx_object.lo_class == &lock_class_mtx_spin,
- ("mtx_unlock_spin() of sleep mutex %s @ %s:%d",
- m->mtx_object.lo_name, file, line));
- WITNESS_UNLOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line);
- LOCK_LOG_LOCK("UNLOCK", &m->mtx_object, opts, m->mtx_recurse, file,
- line);
- mtx_assert(m, MA_OWNED);
-#if defined(SMP) || LOCK_DEBUG > 0 || 1
- _rel_spin_lock(m);
-#else
- critical_exit();
-#endif
-}
-
-/*
- * The important part of mtx_trylock{,_flags}()
- * Tries to acquire lock `m.' We do NOT handle recursion here. If this
- * function is called on a recursed mutex, it will return failure and
- * will not recursively acquire the lock. You are expected to know what
- * you are doing.
- */
-int
-_mtx_trylock(struct mtx *m, int opts, const char *file, int line)
-{
- int rval;
-
- MPASS(curthread != NULL);
-
- rval = _obtain_lock(m, curthread);
-
- LOCK_LOG_TRY("LOCK", &m->mtx_object, opts, rval, file, line);
- if (rval)
- WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE | LOP_TRYLOCK,
- file, line);
-
- return (rval);
-}
-
-/*
- * _mtx_lock_sleep: the tougher part of acquiring an MTX_DEF lock.
- *
- * We call this if the lock is either contested (i.e. we need to go to
- * sleep waiting for it), or if we need to recurse on it.
- */
-void
-_mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line)
-{
- struct thread *td = curthread;
- struct thread *td1;
-#if defined(SMP) && defined(ADAPTIVE_MUTEXES)
- struct thread *owner;
-#endif
- uintptr_t v;
-#ifdef KTR
- int cont_logged = 0;
-#endif
-
- if (mtx_owned(m)) {
- m->mtx_recurse++;
- atomic_set_ptr(&m->mtx_lock, MTX_RECURSED);
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR1(KTR_LOCK, "_mtx_lock_sleep: %p recursing", m);
- return;
- }
-
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR4(KTR_LOCK,
- "_mtx_lock_sleep: %s contested (lock=%p) at %s:%d",
- m->mtx_object.lo_name, (void *)m->mtx_lock, file, line);
-
- while (!_obtain_lock(m, td)) {
-
- mtx_lock_spin(&sched_lock);
- v = m->mtx_lock;
-
- /*
- * Check if the lock has been released while spinning for
- * the sched_lock.
- */
- if (v == MTX_UNOWNED) {
- mtx_unlock_spin(&sched_lock);
-#ifdef __i386__
- ia32_pause();
-#endif
- continue;
- }
-
- /*
- * The mutex was marked contested on release. This means that
- * there are threads blocked on it.
- */
- if (v == MTX_CONTESTED) {
- td1 = TAILQ_FIRST(&m->mtx_blocked);
- MPASS(td1 != NULL);
- m->mtx_lock = (uintptr_t)td | MTX_CONTESTED;
-
- if (td1->td_priority < td->td_priority)
- td->td_priority = td1->td_priority;
- mtx_unlock_spin(&sched_lock);
- return;
- }
-
- /*
- * If the mutex isn't already contested and a failure occurs
- * setting the contested bit, the mutex was either released
- * or the state of the MTX_RECURSED bit changed.
- */
- if ((v & MTX_CONTESTED) == 0 &&
- !atomic_cmpset_ptr(&m->mtx_lock, (void *)v,
- (void *)(v | MTX_CONTESTED))) {
- mtx_unlock_spin(&sched_lock);
-#ifdef __i386__
- ia32_pause();
-#endif
- continue;
- }
-
-#if defined(SMP) && defined(ADAPTIVE_MUTEXES)
- /*
- * If the current owner of the lock is executing on another
- * CPU, spin instead of blocking.
- */
- owner = (struct thread *)(v & MTX_FLAGMASK);
- if (m != &Giant && TD_IS_RUNNING(owner)) {
- mtx_unlock_spin(&sched_lock);
- while (mtx_owner(m) == owner && TD_IS_RUNNING(owner)) {
-#ifdef __i386__
- ia32_pause();
-#endif
- }
- continue;
- }
-#endif /* SMP && ADAPTIVE_MUTEXES */
-
- /*
- * We definitely must sleep for this lock.
- */
- mtx_assert(m, MA_NOTOWNED);
-
-#ifdef notyet
- /*
- * If we're borrowing an interrupted thread's VM context, we
- * must clean up before going to sleep.
- */
- if (td->td_ithd != NULL) {
- struct ithd *it = td->td_ithd;
-
- if (it->it_interrupted) {
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR2(KTR_LOCK,
- "_mtx_lock_sleep: %p interrupted %p",
- it, it->it_interrupted);
- intr_thd_fixup(it);
- }
- }
-#endif
-
- /*
- * Put us on the list of threads blocked on this mutex.
- */
- if (TAILQ_EMPTY(&m->mtx_blocked)) {
- td1 = mtx_owner(m);
- LIST_INSERT_HEAD(&td1->td_contested, m, mtx_contested);
- TAILQ_INSERT_TAIL(&m->mtx_blocked, td, td_lockq);
- } else {
- TAILQ_FOREACH(td1, &m->mtx_blocked, td_lockq)
- if (td1->td_priority > td->td_priority)
- break;
- if (td1)
- TAILQ_INSERT_BEFORE(td1, td, td_lockq);
- else
- TAILQ_INSERT_TAIL(&m->mtx_blocked, td, td_lockq);
- }
-#ifdef KTR
- if (!cont_logged) {
- CTR6(KTR_CONTENTION,
- "contention: %p at %s:%d wants %s, taken by %s:%d",
- td, file, line, m->mtx_object.lo_name,
- WITNESS_FILE(&m->mtx_object),
- WITNESS_LINE(&m->mtx_object));
- cont_logged = 1;
- }
-#endif
-
- /*
- * Save who we're blocked on.
- */
- td->td_blocked = m;
- td->td_lockname = m->mtx_object.lo_name;
- TD_SET_LOCK(td);
- propagate_priority(td);
-
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR3(KTR_LOCK,
- "_mtx_lock_sleep: p %p blocked on [%p] %s", td, m,
- m->mtx_object.lo_name);
-
- td->td_proc->p_stats->p_ru.ru_nvcsw++;
- mi_switch();
-
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR3(KTR_LOCK,
- "_mtx_lock_sleep: p %p free from blocked on [%p] %s",
- td, m, m->mtx_object.lo_name);
-
- mtx_unlock_spin(&sched_lock);
- }
-
-#ifdef KTR
- if (cont_logged) {
- CTR4(KTR_CONTENTION,
- "contention end: %s acquired by %p at %s:%d",
- m->mtx_object.lo_name, td, file, line);
- }
-#endif
- return;
-}
-
-/*
- * _mtx_lock_spin: the tougher part of acquiring an MTX_SPIN lock.
- *
- * This is only called if we need to actually spin for the lock. Recursion
- * is handled inline.
- */
-void
-_mtx_lock_spin(struct mtx *m, int opts, const char *file, int line)
-{
- int i = 0;
-
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m);
-
- for (;;) {
- if (_obtain_lock(m, curthread))
- break;
-
- /* Give interrupts a chance while we spin. */
- critical_exit();
- while (m->mtx_lock != MTX_UNOWNED) {
- if (i++ < 10000000) {
-#ifdef __i386__
- ia32_pause();
-#endif
- continue;
- }
- if (i < 60000000)
- DELAY(1);
-#ifdef DDB
- else if (!db_active)
-#else
- else
-#endif
- panic("spin lock %s held by %p for > 5 seconds",
- m->mtx_object.lo_name, (void *)m->mtx_lock);
-#ifdef __i386__
- ia32_pause();
-#endif
- }
- critical_enter();
- }
-
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR1(KTR_LOCK, "_mtx_lock_spin: %p spin done", m);
-
- return;
-}
-
-/*
- * _mtx_unlock_sleep: the tougher part of releasing an MTX_DEF lock.
- *
- * We are only called here if the lock is recursed or contested (i.e. we
- * need to wake up a blocked thread).
- */
-void
-_mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line)
-{
- struct thread *td, *td1;
- struct mtx *m1;
- int pri;
-
- td = curthread;
-
- if (mtx_recursed(m)) {
- if (--(m->mtx_recurse) == 0)
- atomic_clear_ptr(&m->mtx_lock, MTX_RECURSED);
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p unrecurse", m);
- return;
- }
-
- mtx_lock_spin(&sched_lock);
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p contested", m);
-
- td1 = TAILQ_FIRST(&m->mtx_blocked);
-#if defined(SMP) && defined(ADAPTIVE_MUTEXES)
- if (td1 == NULL) {
- _release_lock_quick(m);
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p no sleepers", m);
- mtx_unlock_spin(&sched_lock);
- return;
- }
-#endif
- MPASS(td->td_proc->p_magic == P_MAGIC);
- MPASS(td1->td_proc->p_magic == P_MAGIC);
-
- TAILQ_REMOVE(&m->mtx_blocked, td1, td_lockq);
-
- if (TAILQ_EMPTY(&m->mtx_blocked)) {
- LIST_REMOVE(m, mtx_contested);
- _release_lock_quick(m);
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p not held", m);
- } else
- atomic_store_rel_ptr(&m->mtx_lock, (void *)MTX_CONTESTED);
-
- pri = PRI_MAX;
- LIST_FOREACH(m1, &td->td_contested, mtx_contested) {
- int cp = TAILQ_FIRST(&m1->mtx_blocked)->td_priority;
- if (cp < pri)
- pri = cp;
- }
-
- if (pri > td->td_base_pri)
- pri = td->td_base_pri;
- td->td_priority = pri;
-
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR2(KTR_LOCK, "_mtx_unlock_sleep: %p contested setrunqueue %p",
- m, td1);
-
- td1->td_blocked = NULL;
- TD_CLR_LOCK(td1);
- if (!TD_CAN_RUN(td1)) {
- mtx_unlock_spin(&sched_lock);
- return;
- }
- setrunqueue(td1);
-
- if (td->td_critnest == 1 && td1->td_priority < pri) {
-#ifdef notyet
- if (td->td_ithd != NULL) {
- struct ithd *it = td->td_ithd;
-
- if (it->it_interrupted) {
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR2(KTR_LOCK,
- "_mtx_unlock_sleep: %p interrupted %p",
- it, it->it_interrupted);
- intr_thd_fixup(it);
- }
- }
-#endif
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR2(KTR_LOCK,
- "_mtx_unlock_sleep: %p switching out lock=%p", m,
- (void *)m->mtx_lock);
-
- td->td_proc->p_stats->p_ru.ru_nivcsw++;
- mi_switch();
- if (LOCK_LOG_TEST(&m->mtx_object, opts))
- CTR2(KTR_LOCK, "_mtx_unlock_sleep: %p resuming lock=%p",
- m, (void *)m->mtx_lock);
- }
-
- mtx_unlock_spin(&sched_lock);
-
- return;
-}
-
-/*
- * All the unlocking of MTX_SPIN locks is done inline.
- * See the _rel_spin_lock() macro for the details.
- */
-
-/*
- * The backing function for the INVARIANTS-enabled mtx_assert()
- */
-#ifdef INVARIANT_SUPPORT
-void
-_mtx_assert(struct mtx *m, int what, const char *file, int line)
-{
-
- if (panicstr != NULL)
- return;
- switch (what) {
- case MA_OWNED:
- case MA_OWNED | MA_RECURSED:
- case MA_OWNED | MA_NOTRECURSED:
- if (!mtx_owned(m))
- panic("mutex %s not owned at %s:%d",
- m->mtx_object.lo_name, file, line);
- if (mtx_recursed(m)) {
- if ((what & MA_NOTRECURSED) != 0)
- panic("mutex %s recursed at %s:%d",
- m->mtx_object.lo_name, file, line);
- } else if ((what & MA_RECURSED) != 0) {
- panic("mutex %s unrecursed at %s:%d",
- m->mtx_object.lo_name, file, line);
- }
- break;
- case MA_NOTOWNED:
- if (mtx_owned(m))
- panic("mutex %s owned at %s:%d",
- m->mtx_object.lo_name, file, line);
- break;
- default:
- panic("unknown mtx_assert at %s:%d", file, line);
- }
-}
-#endif
-
-/*
- * The MUTEX_DEBUG-enabled mtx_validate()
- *
- * Most of these checks have been moved off into the LO_INITIALIZED flag
- * maintained by the witness code.
- */
-#ifdef MUTEX_DEBUG
-
-void mtx_validate(struct mtx *);
-
-void
-mtx_validate(struct mtx *m)
-{
-
-/*
- * XXX: When kernacc() does not require Giant we can reenable this check
- */
-#ifdef notyet
-/*
- * XXX - When kernacc() is fixed on the alpha to handle K0_SEG memory properly
- * we can re-enable the kernacc() checks.
- */
-#ifndef __alpha__
- /*
- * Can't call kernacc() from early init386(), especially when
- * initializing Giant mutex, because some stuff in kernacc()
- * requires Giant itself.
- */
- if (!cold)
- if (!kernacc((caddr_t)m, sizeof(m),
- VM_PROT_READ | VM_PROT_WRITE))
- panic("Can't read and write to mutex %p", m);
-#endif
-#endif
-}
-#endif
-
-/*
- * General init routine used by the MTX_SYSINIT() macro.
- */
-void
-mtx_sysinit(void *arg)
-{
- struct mtx_args *margs = arg;
-
- mtx_init(margs->ma_mtx, margs->ma_desc, NULL, margs->ma_opts);
-}
-
-/*
- * Mutex initialization routine; initialize lock `m' of type contained in
- * `opts' with options contained in `opts' and name `name.' The optional
- * lock type `type' is used as a general lock category name for use with
- * witness.
- */
-void
-mtx_init(struct mtx *m, const char *name, const char *type, int opts)
-{
- struct lock_object *lock;
-
- MPASS((opts & ~(MTX_SPIN | MTX_QUIET | MTX_RECURSE |
- MTX_NOWITNESS | MTX_DUPOK)) == 0);
-
-#ifdef MUTEX_DEBUG
- /* Diagnostic and error correction */
- mtx_validate(m);
-#endif
-
- lock = &m->mtx_object;
- KASSERT((lock->lo_flags & LO_INITIALIZED) == 0,
- ("mutex %s %p already initialized", name, m));
- bzero(m, sizeof(*m));
- if (opts & MTX_SPIN)
- lock->lo_class = &lock_class_mtx_spin;
- else
- lock->lo_class = &lock_class_mtx_sleep;
- lock->lo_name = name;
- lock->lo_type = type != NULL ? type : name;
- if (opts & MTX_QUIET)
- lock->lo_flags = LO_QUIET;
- if (opts & MTX_RECURSE)
- lock->lo_flags |= LO_RECURSABLE;
- if ((opts & MTX_NOWITNESS) == 0)
- lock->lo_flags |= LO_WITNESS;
- if (opts & MTX_DUPOK)
- lock->lo_flags |= LO_DUPOK;
-
- m->mtx_lock = MTX_UNOWNED;
- TAILQ_INIT(&m->mtx_blocked);
-
- LOCK_LOG_INIT(lock, opts);
-
- WITNESS_INIT(lock);
-}
-
-/*
- * Remove lock `m' from all_mtx queue. We don't allow MTX_QUIET to be
- * passed in as a flag here because if the corresponding mtx_init() was
- * called with MTX_QUIET set, then it will already be set in the mutex's
- * flags.
- */
-void
-mtx_destroy(struct mtx *m)
-{
-
- LOCK_LOG_DESTROY(&m->mtx_object, 0);
-
- if (!mtx_owned(m))
- MPASS(mtx_unowned(m));
- else {
- MPASS((m->mtx_lock & (MTX_RECURSED|MTX_CONTESTED)) == 0);
-
- /* Tell witness this isn't locked to make it happy. */
- WITNESS_UNLOCK(&m->mtx_object, LOP_EXCLUSIVE, __FILE__,
- __LINE__);
- }
-
- WITNESS_DESTROY(&m->mtx_object);
-}
-
-/*
- * Intialize the mutex code and system mutexes. This is called from the MD
- * startup code prior to mi_startup(). The per-CPU data space needs to be
- * setup before this is called.
- */
-void
-mutex_init(void)
-{
-
- /* Setup thread0 so that mutexes work. */
- LIST_INIT(&thread0.td_contested);
-
- /*
- * Initialize mutexes.
- */
- mtx_init(&Giant, "Giant", NULL, MTX_DEF | MTX_RECURSE);
- mtx_init(&sched_lock, "sched lock", NULL, MTX_SPIN | MTX_RECURSE);
- mtx_init(&proc0.p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
- mtx_lock(&Giant);
-}
diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c
deleted file mode 100644
index e2a125f2c0d2..000000000000
--- a/sys/kern/uipc_sockbuf.c
+++ /dev/null
@@ -1,1007 +0,0 @@
-/*
- * Copyright (c) 1982, 1986, 1988, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93
- * $FreeBSD$
- */
-
-#include "opt_mac.h"
-#include "opt_param.h"
-
-#include <sys/param.h>
-#include <sys/aio.h> /* for aio_swake proto */
-#include <sys/domain.h>
-#include <sys/event.h>
-#include <sys/file.h> /* for maxfiles */
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/mac.h>
-#include <sys/malloc.h>
-#include <sys/mbuf.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/protosw.h>
-#include <sys/resourcevar.h>
-#include <sys/signalvar.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/stat.h>
-#include <sys/sysctl.h>
-#include <sys/systm.h>
-
-int maxsockets;
-
-void (*aio_swake)(struct socket *, struct sockbuf *);
-
-/*
- * Primitive routines for operating on sockets and socket buffers
- */
-
-u_long sb_max = SB_MAX;
-static u_long sb_max_adj =
- SB_MAX * MCLBYTES / (MSIZE + MCLBYTES); /* adjusted sb_max */
-
-static u_long sb_efficiency = 8; /* parameter for sbreserve() */
-
-/*
- * Procedures to manipulate state flags of socket
- * and do appropriate wakeups. Normal sequence from the
- * active (originating) side is that soisconnecting() is
- * called during processing of connect() call,
- * resulting in an eventual call to soisconnected() if/when the
- * connection is established. When the connection is torn down
- * soisdisconnecting() is called during processing of disconnect() call,
- * and soisdisconnected() is called when the connection to the peer
- * is totally severed. The semantics of these routines are such that
- * connectionless protocols can call soisconnected() and soisdisconnected()
- * only, bypassing the in-progress calls when setting up a ``connection''
- * takes no time.
- *
- * From the passive side, a socket is created with
- * two queues of sockets: so_incomp for connections in progress
- * and so_comp for connections already made and awaiting user acceptance.
- * As a protocol is preparing incoming connections, it creates a socket
- * structure queued on so_incomp by calling sonewconn(). When the connection
- * is established, soisconnected() is called, and transfers the
- * socket structure to so_comp, making it available to accept().
- *
- * If a socket is closed with sockets on either
- * so_incomp or so_comp, these sockets are dropped.
- *
- * If higher level protocols are implemented in
- * the kernel, the wakeups done here will sometimes
- * cause software-interrupt process scheduling.
- */
-
-void
-soisconnecting(so)
- register struct socket *so;
-{
-
- so->so_state &= ~(SS_ISCONNECTED|SS_ISDISCONNECTING);
- so->so_state |= SS_ISCONNECTING;
-}
-
-void
-soisconnected(so)
- struct socket *so;
-{
- struct socket *head = so->so_head;
-
- so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING);
- so->so_state |= SS_ISCONNECTED;
- if (head && (so->so_state & SS_INCOMP)) {
- if ((so->so_options & SO_ACCEPTFILTER) != 0) {
- so->so_upcall = head->so_accf->so_accept_filter->accf_callback;
- so->so_upcallarg = head->so_accf->so_accept_filter_arg;
- so->so_rcv.sb_flags |= SB_UPCALL;
- so->so_options &= ~SO_ACCEPTFILTER;
- so->so_upcall(so, so->so_upcallarg, M_TRYWAIT);
- return;
- }
- TAILQ_REMOVE(&head->so_incomp, so, so_list);
- head->so_incqlen--;
- so->so_state &= ~SS_INCOMP;
- TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
- head->so_qlen++;
- so->so_state |= SS_COMP;
- sorwakeup(head);
- wakeup_one(&head->so_timeo);
- } else {
- wakeup(&so->so_timeo);
- sorwakeup(so);
- sowwakeup(so);
- }
-}
-
-void
-soisdisconnecting(so)
- register struct socket *so;
-{
-
- so->so_state &= ~SS_ISCONNECTING;
- so->so_state |= (SS_ISDISCONNECTING|SS_CANTRCVMORE|SS_CANTSENDMORE);
- wakeup(&so->so_timeo);
- sowwakeup(so);
- sorwakeup(so);
-}
-
-void
-soisdisconnected(so)
- register struct socket *so;
-{
-
- so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING);
- so->so_state |= (SS_CANTRCVMORE|SS_CANTSENDMORE|SS_ISDISCONNECTED);
- wakeup(&so->so_timeo);
- sbdrop(&so->so_snd, so->so_snd.sb_cc);
- sowwakeup(so);
- sorwakeup(so);
-}
-
-/*
- * When an attempt at a new connection is noted on a socket
- * which accepts connections, sonewconn is called. If the
- * connection is possible (subject to space constraints, etc.)
- * then we allocate a new structure, propoerly linked into the
- * data structure of the original socket, and return this.
- * Connstatus may be 0, or SO_ISCONFIRMING, or SO_ISCONNECTED.
- *
- * note: the ref count on the socket is 0 on return
- */
-struct socket *
-sonewconn(head, connstatus)
- register struct socket *head;
- int connstatus;
-{
- register struct socket *so;
-
- if (head->so_qlen > 3 * head->so_qlimit / 2)
- return ((struct socket *)0);
- so = soalloc(0);
- if (so == NULL)
- return ((struct socket *)0);
- if ((head->so_options & SO_ACCEPTFILTER) != 0)
- connstatus = 0;
- so->so_head = head;
- so->so_type = head->so_type;
- so->so_options = head->so_options &~ SO_ACCEPTCONN;
- so->so_linger = head->so_linger;
- so->so_state = head->so_state | SS_NOFDREF;
- so->so_proto = head->so_proto;
- so->so_timeo = head->so_timeo;
- so->so_cred = crhold(head->so_cred);
-#ifdef MAC
- mac_create_socket_from_socket(head, so);
-#endif
- if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat) ||
- (*so->so_proto->pr_usrreqs->pru_attach)(so, 0, NULL)) {
- sodealloc(so);
- return ((struct socket *)0);
- }
-
- if (connstatus) {
- TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
- so->so_state |= SS_COMP;
- head->so_qlen++;
- } else {
- if (head->so_incqlen > head->so_qlimit) {
- struct socket *sp;
- sp = TAILQ_FIRST(&head->so_incomp);
- (void) soabort(sp);
- }
- TAILQ_INSERT_TAIL(&head->so_incomp, so, so_list);
- so->so_state |= SS_INCOMP;
- head->so_incqlen++;
- }
- if (connstatus) {
- sorwakeup(head);
- wakeup(&head->so_timeo);
- so->so_state |= connstatus;
- }
- return (so);
-}
-
-/*
- * Socantsendmore indicates that no more data will be sent on the
- * socket; it would normally be applied to a socket when the user
- * informs the system that no more data is to be sent, by the protocol
- * code (in case PRU_SHUTDOWN). Socantrcvmore indicates that no more data
- * will be received, and will normally be applied to the socket by a
- * protocol when it detects that the peer will send no more data.
- * Data queued for reading in the socket may yet be read.
- */
-
-void
-socantsendmore(so)
- struct socket *so;
-{
-
- so->so_state |= SS_CANTSENDMORE;
- sowwakeup(so);
-}
-
-void
-socantrcvmore(so)
- struct socket *so;
-{
-
- so->so_state |= SS_CANTRCVMORE;
- sorwakeup(so);
-}
-
-/*
- * Wait for data to arrive at/drain from a socket buffer.
- */
-int
-sbwait(sb)
- struct sockbuf *sb;
-{
-
- sb->sb_flags |= SB_WAIT;
- return (tsleep(&sb->sb_cc,
- (sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK | PCATCH, "sbwait",
- sb->sb_timeo));
-}
-
-/*
- * Lock a sockbuf already known to be locked;
- * return any error returned from sleep (EINTR).
- */
-int
-sb_lock(sb)
- register struct sockbuf *sb;
-{
- int error;
-
- while (sb->sb_flags & SB_LOCK) {
- sb->sb_flags |= SB_WANT;
- error = tsleep(&sb->sb_flags,
- (sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK|PCATCH,
- "sblock", 0);
- if (error)
- return (error);
- }
- sb->sb_flags |= SB_LOCK;
- return (0);
-}
-
-/*
- * Wakeup processes waiting on a socket buffer.
- * Do asynchronous notification via SIGIO
- * if the socket has the SS_ASYNC flag set.
- */
-void
-sowakeup(so, sb)
- register struct socket *so;
- register struct sockbuf *sb;
-{
-
- selwakeup(&sb->sb_sel);
- sb->sb_flags &= ~SB_SEL;
- if (sb->sb_flags & SB_WAIT) {
- sb->sb_flags &= ~SB_WAIT;
- wakeup(&sb->sb_cc);
- }
- if ((so->so_state & SS_ASYNC) && so->so_sigio != NULL)
- pgsigio(&so->so_sigio, SIGIO, 0);
- if (sb->sb_flags & SB_UPCALL)
- (*so->so_upcall)(so, so->so_upcallarg, M_DONTWAIT);
- if (sb->sb_flags & SB_AIO)
- aio_swake(so, sb);
- KNOTE(&sb->sb_sel.si_note, 0);
-}
-
-/*
- * Socket buffer (struct sockbuf) utility routines.
- *
- * Each socket contains two socket buffers: one for sending data and
- * one for receiving data. Each buffer contains a queue of mbufs,
- * information about the number of mbufs and amount of data in the
- * queue, and other fields allowing select() statements and notification
- * on data availability to be implemented.
- *
- * Data stored in a socket buffer is maintained as a list of records.
- * Each record is a list of mbufs chained together with the m_next
- * field. Records are chained together with the m_nextpkt field. The upper
- * level routine soreceive() expects the following conventions to be
- * observed when placing information in the receive buffer:
- *
- * 1. If the protocol requires each message be preceded by the sender's
- * name, then a record containing that name must be present before
- * any associated data (mbuf's must be of type MT_SONAME).
- * 2. If the protocol supports the exchange of ``access rights'' (really
- * just additional data associated with the message), and there are
- * ``rights'' to be received, then a record containing this data
- * should be present (mbuf's must be of type MT_RIGHTS).
- * 3. If a name or rights record exists, then it must be followed by
- * a data record, perhaps of zero length.
- *
- * Before using a new socket structure it is first necessary to reserve
- * buffer space to the socket, by calling sbreserve(). This should commit
- * some of the available buffer space in the system buffer pool for the
- * socket (currently, it does nothing but enforce limits). The space
- * should be released by calling sbrelease() when the socket is destroyed.
- */
-
-int
-soreserve(so, sndcc, rcvcc)
- register struct socket *so;
- u_long sndcc, rcvcc;
-{
- struct thread *td = curthread;
-
- if (sbreserve(&so->so_snd, sndcc, so, td) == 0)
- goto bad;
- if (sbreserve(&so->so_rcv, rcvcc, so, td) == 0)
- goto bad2;
- if (so->so_rcv.sb_lowat == 0)
- so->so_rcv.sb_lowat = 1;
- if (so->so_snd.sb_lowat == 0)
- so->so_snd.sb_lowat = MCLBYTES;
- if (so->so_snd.sb_lowat > so->so_snd.sb_hiwat)
- so->so_snd.sb_lowat = so->so_snd.sb_hiwat;
- return (0);
-bad2:
- sbrelease(&so->so_snd, so);
-bad:
- return (ENOBUFS);
-}
-
-static int
-sysctl_handle_sb_max(SYSCTL_HANDLER_ARGS)
-{
- int error = 0;
- u_long old_sb_max = sb_max;
-
- error = SYSCTL_OUT(req, arg1, sizeof(u_long));
- if (error || !req->newptr)
- return (error);
- error = SYSCTL_IN(req, arg1, sizeof(u_long));
- if (error)
- return (error);
- if (sb_max < MSIZE + MCLBYTES) {
- sb_max = old_sb_max;
- return (EINVAL);
- }
- sb_max_adj = (u_quad_t)sb_max * MCLBYTES / (MSIZE + MCLBYTES);
- return (0);
-}
-
-/*
- * Allot mbufs to a sockbuf.
- * Attempt to scale mbmax so that mbcnt doesn't become limiting
- * if buffering efficiency is near the normal case.
- */
-int
-sbreserve(sb, cc, so, td)
- struct sockbuf *sb;
- u_long cc;
- struct socket *so;
- struct thread *td;
-{
-
- /*
- * td will only be NULL when we're in an interrupt
- * (e.g. in tcp_input())
- */
- if (cc > sb_max_adj)
- return (0);
- if (!chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, cc,
- td ? td->td_proc->p_rlimit[RLIMIT_SBSIZE].rlim_cur : RLIM_INFINITY)) {
- return (0);
- }
- sb->sb_mbmax = min(cc * sb_efficiency, sb_max);
- if (sb->sb_lowat > sb->sb_hiwat)
- sb->sb_lowat = sb->sb_hiwat;
- return (1);
-}
-
-/*
- * Free mbufs held by a socket, and reserved mbuf space.
- */
-void
-sbrelease(sb, so)
- struct sockbuf *sb;
- struct socket *so;
-{
-
- sbflush(sb);
- (void)chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, 0,
- RLIM_INFINITY);
- sb->sb_mbmax = 0;
-}
-
-/*
- * Routines to add and remove
- * data from an mbuf queue.
- *
- * The routines sbappend() or sbappendrecord() are normally called to
- * append new mbufs to a socket buffer, after checking that adequate
- * space is available, comparing the function sbspace() with the amount
- * of data to be added. sbappendrecord() differs from sbappend() in
- * that data supplied is treated as the beginning of a new record.
- * To place a sender's address, optional access rights, and data in a
- * socket receive buffer, sbappendaddr() should be used. To place
- * access rights and data in a socket receive buffer, sbappendrights()
- * should be used. In either case, the new data begins a new record.
- * Note that unlike sbappend() and sbappendrecord(), these routines check
- * for the caller that there will be enough space to store the data.
- * Each fails if there is not enough space, or if it cannot find mbufs
- * to store additional information in.
- *
- * Reliable protocols may use the socket send buffer to hold data
- * awaiting acknowledgement. Data is normally copied from a socket
- * send buffer in a protocol with m_copy for output to a peer,
- * and then removing the data from the socket buffer with sbdrop()
- * or sbdroprecord() when the data is acknowledged by the peer.
- */
-
-/*
- * Append mbuf chain m to the last record in the
- * socket buffer sb. The additional space associated
- * the mbuf chain is recorded in sb. Empty mbufs are
- * discarded and mbufs are compacted where possible.
- */
-void
-sbappend(sb, m)
- struct sockbuf *sb;
- struct mbuf *m;
-{
- register struct mbuf *n;
-
- if (m == 0)
- return;
- n = sb->sb_mb;
- if (n) {
- while (n->m_nextpkt)
- n = n->m_nextpkt;
- do {
- if (n->m_flags & M_EOR) {
- sbappendrecord(sb, m); /* XXXXXX!!!! */
- return;
- }
- } while (n->m_next && (n = n->m_next));
- }
- sbcompress(sb, m, n);
-}
-
-#ifdef SOCKBUF_DEBUG
-void
-sbcheck(sb)
- struct sockbuf *sb;
-{
- struct mbuf *m;
- struct mbuf *n = 0;
- u_long len = 0, mbcnt = 0;
-
- for (m = sb->sb_mb; m; m = n) {
- n = m->m_nextpkt;
- for (; m; m = m->m_next) {
- len += m->m_len;
- mbcnt += MSIZE;
- if (m->m_flags & M_EXT) /*XXX*/ /* pretty sure this is bogus */
- mbcnt += m->m_ext.ext_size;
- }
- }
- if (len != sb->sb_cc || mbcnt != sb->sb_mbcnt) {
- printf("cc %ld != %ld || mbcnt %ld != %ld\n", len, sb->sb_cc,
- mbcnt, sb->sb_mbcnt);
- panic("sbcheck");
- }
-}
-#endif
-
-/*
- * As above, except the mbuf chain
- * begins a new record.
- */
-void
-sbappendrecord(sb, m0)
- register struct sockbuf *sb;
- register struct mbuf *m0;
-{
- register struct mbuf *m;
-
- if (m0 == 0)
- return;
- m = sb->sb_mb;
- if (m)
- while (m->m_nextpkt)
- m = m->m_nextpkt;
- /*
- * Put the first mbuf on the queue.
- * Note this permits zero length records.
- */
- sballoc(sb, m0);
- if (m)
- m->m_nextpkt = m0;
- else
- sb->sb_mb = m0;
- m = m0->m_next;
- m0->m_next = 0;
- if (m && (m0->m_flags & M_EOR)) {
- m0->m_flags &= ~M_EOR;
- m->m_flags |= M_EOR;
- }
- sbcompress(sb, m, m0);
-}
-
-/*
- * As above except that OOB data
- * is inserted at the beginning of the sockbuf,
- * but after any other OOB data.
- */
-void
-sbinsertoob(sb, m0)
- register struct sockbuf *sb;
- register struct mbuf *m0;
-{
- register struct mbuf *m;
- register struct mbuf **mp;
-
- if (m0 == 0)
- return;
- for (mp = &sb->sb_mb; *mp ; mp = &((*mp)->m_nextpkt)) {
- m = *mp;
- again:
- switch (m->m_type) {
-
- case MT_OOBDATA:
- continue; /* WANT next train */
-
- case MT_CONTROL:
- m = m->m_next;
- if (m)
- goto again; /* inspect THIS train further */
- }
- break;
- }
- /*
- * Put the first mbuf on the queue.
- * Note this permits zero length records.
- */
- sballoc(sb, m0);
- m0->m_nextpkt = *mp;
- *mp = m0;
- m = m0->m_next;
- m0->m_next = 0;
- if (m && (m0->m_flags & M_EOR)) {
- m0->m_flags &= ~M_EOR;
- m->m_flags |= M_EOR;
- }
- sbcompress(sb, m, m0);
-}
-
-/*
- * Append address and data, and optionally, control (ancillary) data
- * to the receive queue of a socket. If present,
- * m0 must include a packet header with total length.
- * Returns 0 if no space in sockbuf or insufficient mbufs.
- */
-int
-sbappendaddr(sb, asa, m0, control)
- struct sockbuf *sb;
- struct sockaddr *asa;
- struct mbuf *m0, *control;
-{
- struct mbuf *m, *n;
- int space = asa->sa_len;
-
- if (m0 && (m0->m_flags & M_PKTHDR) == 0)
- panic("sbappendaddr");
- if (m0)
- space += m0->m_pkthdr.len;
- space += m_length(control, &n);
- if (space > sbspace(sb))
- return (0);
- if (asa->sa_len > MLEN)
- return (0);
- MGET(m, M_DONTWAIT, MT_SONAME);
- if (m == 0)
- return (0);
- m->m_len = asa->sa_len;
- bcopy(asa, mtod(m, caddr_t), asa->sa_len);
- if (n)
- n->m_next = m0; /* concatenate data to control */
- else
- control = m0;
- m->m_next = control;
- for (n = m; n; n = n->m_next)
- sballoc(sb, n);
- n = sb->sb_mb;
- if (n) {
- while (n->m_nextpkt)
- n = n->m_nextpkt;
- n->m_nextpkt = m;
- } else
- sb->sb_mb = m;
- return (1);
-}
-
-int
-sbappendcontrol(sb, m0, control)
- struct sockbuf *sb;
- struct mbuf *control, *m0;
-{
- struct mbuf *m, *n;
- int space;
-
- if (control == 0)
- panic("sbappendcontrol");
- space = m_length(control, &n) + m_length(m0, NULL);
- if (space > sbspace(sb))
- return (0);
- n->m_next = m0; /* concatenate data to control */
- for (m = control; m; m = m->m_next)
- sballoc(sb, m);
- n = sb->sb_mb;
- if (n) {
- while (n->m_nextpkt)
- n = n->m_nextpkt;
- n->m_nextpkt = control;
- } else
- sb->sb_mb = control;
- return (1);
-}
-
-/*
- * Compress mbuf chain m into the socket
- * buffer sb following mbuf n. If n
- * is null, the buffer is presumed empty.
- */
-void
-sbcompress(sb, m, n)
- register struct sockbuf *sb;
- register struct mbuf *m, *n;
-{
- register int eor = 0;
- register struct mbuf *o;
-
- while (m) {
- eor |= m->m_flags & M_EOR;
- if (m->m_len == 0 &&
- (eor == 0 ||
- (((o = m->m_next) || (o = n)) &&
- o->m_type == m->m_type))) {
- m = m_free(m);
- continue;
- }
- if (n && (n->m_flags & M_EOR) == 0 &&
- M_WRITABLE(n) &&
- m->m_len <= MCLBYTES / 4 && /* XXX: Don't copy too much */
- m->m_len <= M_TRAILINGSPACE(n) &&
- n->m_type == m->m_type) {
- bcopy(mtod(m, caddr_t), mtod(n, caddr_t) + n->m_len,
- (unsigned)m->m_len);
- n->m_len += m->m_len;
- sb->sb_cc += m->m_len;
- if (m->m_type != MT_DATA && m->m_type != MT_HEADER &&
- m->m_type != MT_OOBDATA)
- /* XXX: Probably don't need.*/
- sb->sb_ctl += m->m_len;
- m = m_free(m);
- continue;
- }
- if (n)
- n->m_next = m;
- else
- sb->sb_mb = m;
- sballoc(sb, m);
- n = m;
- m->m_flags &= ~M_EOR;
- m = m->m_next;
- n->m_next = 0;
- }
- if (eor) {
- if (n)
- n->m_flags |= eor;
- else
- printf("semi-panic: sbcompress\n");
- }
-}
-
-/*
- * Free all mbufs in a sockbuf.
- * Check that all resources are reclaimed.
- */
-void
-sbflush(sb)
- register struct sockbuf *sb;
-{
-
- if (sb->sb_flags & SB_LOCK)
- panic("sbflush: locked");
- while (sb->sb_mbcnt) {
- /*
- * Don't call sbdrop(sb, 0) if the leading mbuf is non-empty:
- * we would loop forever. Panic instead.
- */
- if (!sb->sb_cc && (sb->sb_mb == NULL || sb->sb_mb->m_len))
- break;
- sbdrop(sb, (int)sb->sb_cc);
- }
- if (sb->sb_cc || sb->sb_mb || sb->sb_mbcnt)
- panic("sbflush: cc %u || mb %p || mbcnt %u", sb->sb_cc, (void *)sb->sb_mb, sb->sb_mbcnt);
-}
-
-/*
- * Drop data from (the front of) a sockbuf.
- */
-void
-sbdrop(sb, len)
- register struct sockbuf *sb;
- register int len;
-{
- register struct mbuf *m;
- struct mbuf *next;
-
- next = (m = sb->sb_mb) ? m->m_nextpkt : 0;
- while (len > 0) {
- if (m == 0) {
- if (next == 0)
- panic("sbdrop");
- m = next;
- next = m->m_nextpkt;
- continue;
- }
- if (m->m_len > len) {
- m->m_len -= len;
- m->m_data += len;
- sb->sb_cc -= len;
- if (m->m_type != MT_DATA && m->m_type != MT_HEADER &&
- m->m_type != MT_OOBDATA)
- sb->sb_ctl -= len;
- break;
- }
- len -= m->m_len;
- sbfree(sb, m);
- m = m_free(m);
- }
- while (m && m->m_len == 0) {
- sbfree(sb, m);
- m = m_free(m);
- }
- if (m) {
- sb->sb_mb = m;
- m->m_nextpkt = next;
- } else
- sb->sb_mb = next;
-}
-
-/*
- * Drop a record off the front of a sockbuf
- * and move the next record to the front.
- */
-void
-sbdroprecord(sb)
- register struct sockbuf *sb;
-{
- register struct mbuf *m;
-
- m = sb->sb_mb;
- if (m) {
- sb->sb_mb = m->m_nextpkt;
- do {
- sbfree(sb, m);
- m = m_free(m);
- } while (m);
- }
-}
-
-/*
- * Create a "control" mbuf containing the specified data
- * with the specified type for presentation on a socket buffer.
- */
-struct mbuf *
-sbcreatecontrol(p, size, type, level)
- caddr_t p;
- register int size;
- int type, level;
-{
- register struct cmsghdr *cp;
- struct mbuf *m;
-
- if (CMSG_SPACE((u_int)size) > MCLBYTES)
- return ((struct mbuf *) NULL);
- if ((m = m_get(M_DONTWAIT, MT_CONTROL)) == NULL)
- return ((struct mbuf *) NULL);
- if (CMSG_SPACE((u_int)size) > MLEN) {
- MCLGET(m, M_DONTWAIT);
- if ((m->m_flags & M_EXT) == 0) {
- m_free(m);
- return ((struct mbuf *) NULL);
- }
- }
- cp = mtod(m, struct cmsghdr *);
- m->m_len = 0;
- KASSERT(CMSG_SPACE((u_int)size) <= M_TRAILINGSPACE(m),
- ("sbcreatecontrol: short mbuf"));
- if (p != NULL)
- (void)memcpy(CMSG_DATA(cp), p, size);
- m->m_len = CMSG_SPACE(size);
- cp->cmsg_len = CMSG_LEN(size);
- cp->cmsg_level = level;
- cp->cmsg_type = type;
- return (m);
-}
-
-/*
- * Some routines that return EOPNOTSUPP for entry points that are not
- * supported by a protocol. Fill in as needed.
- */
-int
-pru_accept_notsupp(struct socket *so, struct sockaddr **nam)
-{
- return EOPNOTSUPP;
-}
-
-int
-pru_connect_notsupp(struct socket *so, struct sockaddr *nam, struct thread *td)
-{
- return EOPNOTSUPP;
-}
-
-int
-pru_connect2_notsupp(struct socket *so1, struct socket *so2)
-{
- return EOPNOTSUPP;
-}
-
-int
-pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data,
- struct ifnet *ifp, struct thread *td)
-{
- return EOPNOTSUPP;
-}
-
-int
-pru_listen_notsupp(struct socket *so, struct thread *td)
-{
- return EOPNOTSUPP;
-}
-
-int
-pru_rcvd_notsupp(struct socket *so, int flags)
-{
- return EOPNOTSUPP;
-}
-
-int
-pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags)
-{
- return EOPNOTSUPP;
-}
-
-/*
- * This isn't really a ``null'' operation, but it's the default one
- * and doesn't do anything destructive.
- */
-int
-pru_sense_null(struct socket *so, struct stat *sb)
-{
- sb->st_blksize = so->so_snd.sb_hiwat;
- return 0;
-}
-
-/*
- * Make a copy of a sockaddr in a malloced buffer of type M_SONAME.
- */
-struct sockaddr *
-dup_sockaddr(sa, canwait)
- struct sockaddr *sa;
- int canwait;
-{
- struct sockaddr *sa2;
-
- MALLOC(sa2, struct sockaddr *, sa->sa_len, M_SONAME,
- canwait ? M_WAITOK : M_NOWAIT);
- if (sa2)
- bcopy(sa, sa2, sa->sa_len);
- return sa2;
-}
-
-/*
- * Create an external-format (``xsocket'') structure using the information
- * in the kernel-format socket structure pointed to by so. This is done
- * to reduce the spew of irrelevant information over this interface,
- * to isolate user code from changes in the kernel structure, and
- * potentially to provide information-hiding if we decide that
- * some of this information should be hidden from users.
- */
-void
-sotoxsocket(struct socket *so, struct xsocket *xso)
-{
- xso->xso_len = sizeof *xso;
- xso->xso_so = so;
- xso->so_type = so->so_type;
- xso->so_options = so->so_options;
- xso->so_linger = so->so_linger;
- xso->so_state = so->so_state;
- xso->so_pcb = so->so_pcb;
- xso->xso_protocol = so->so_proto->pr_protocol;
- xso->xso_family = so->so_proto->pr_domain->dom_family;
- xso->so_qlen = so->so_qlen;
- xso->so_incqlen = so->so_incqlen;
- xso->so_qlimit = so->so_qlimit;
- xso->so_timeo = so->so_timeo;
- xso->so_error = so->so_error;
- xso->so_pgid = so->so_sigio ? so->so_sigio->sio_pgid : 0;
- xso->so_oobmark = so->so_oobmark;
- sbtoxsockbuf(&so->so_snd, &xso->so_snd);
- sbtoxsockbuf(&so->so_rcv, &xso->so_rcv);
- xso->so_uid = so->so_cred->cr_uid;
-}
-
-/*
- * This does the same for sockbufs. Note that the xsockbuf structure,
- * since it is always embedded in a socket, does not include a self
- * pointer nor a length. We make this entry point public in case
- * some other mechanism needs it.
- */
-void
-sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb)
-{
- xsb->sb_cc = sb->sb_cc;
- xsb->sb_hiwat = sb->sb_hiwat;
- xsb->sb_mbcnt = sb->sb_mbcnt;
- xsb->sb_mbmax = sb->sb_mbmax;
- xsb->sb_lowat = sb->sb_lowat;
- xsb->sb_flags = sb->sb_flags;
- xsb->sb_timeo = sb->sb_timeo;
-}
-
-/*
- * Here is the definition of some of the basic objects in the kern.ipc
- * branch of the MIB.
- */
-SYSCTL_NODE(_kern, KERN_IPC, ipc, CTLFLAG_RW, 0, "IPC");
-
-/* This takes the place of kern.maxsockbuf, which moved to kern.ipc. */
-static int dummy;
-SYSCTL_INT(_kern, KERN_DUMMY, dummy, CTLFLAG_RW, &dummy, 0, "");
-SYSCTL_OID(_kern_ipc, KIPC_MAXSOCKBUF, maxsockbuf, CTLTYPE_ULONG|CTLFLAG_RW,
- &sb_max, 0, sysctl_handle_sb_max, "LU", "Maximum socket buffer size");
-SYSCTL_INT(_kern_ipc, OID_AUTO, maxsockets, CTLFLAG_RD,
- &maxsockets, 0, "Maximum number of sockets avaliable");
-SYSCTL_ULONG(_kern_ipc, KIPC_SOCKBUF_WASTE, sockbuf_waste_factor, CTLFLAG_RW,
- &sb_efficiency, 0, "");
-
-/*
- * Initialise maxsockets
- */
-static void init_maxsockets(void *ignored)
-{
- TUNABLE_INT_FETCH("kern.ipc.maxsockets", &maxsockets);
- maxsockets = imax(maxsockets, imax(maxfiles, nmbclusters));
-}
-SYSINIT(param, SI_SUB_TUNABLES, SI_ORDER_ANY, init_maxsockets, NULL);
diff --git a/sys/kern/vfs_acl.c b/sys/kern/vfs_acl.c
deleted file mode 100644
index 6b9f942ff54b..000000000000
--- a/sys/kern/vfs_acl.c
+++ /dev/null
@@ -1,939 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * All rights reserved.
- *
- * This software was developed by Robert Watson for the TrustedBSD Project.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-/*
- * Developed by the TrustedBSD Project.
- * Support for POSIX.1e access control lists.
- */
-
-#include "opt_mac.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/kernel.h>
-#include <sys/mac.h>
-#include <sys/malloc.h>
-#include <sys/vnode.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/namei.h>
-#include <sys/file.h>
-#include <sys/filedesc.h>
-#include <sys/proc.h>
-#include <sys/sysent.h>
-#include <sys/errno.h>
-#include <sys/stat.h>
-#include <sys/acl.h>
-
-MALLOC_DEFINE(M_ACL, "acl", "access control list");
-
-static int vacl_set_acl(struct thread *td, struct vnode *vp,
- acl_type_t type, struct acl *aclp);
-static int vacl_get_acl(struct thread *td, struct vnode *vp,
- acl_type_t type, struct acl *aclp);
-static int vacl_aclcheck(struct thread *td, struct vnode *vp,
- acl_type_t type, struct acl *aclp);
-
-/*
- * Implement a version of vaccess() that understands POSIX.1e ACL semantics.
- * Return 0 on success, else an errno value. Should be merged into
- * vaccess() eventually.
- */
-int
-vaccess_acl_posix1e(enum vtype type, uid_t file_uid, gid_t file_gid,
- struct acl *acl, mode_t acc_mode, struct ucred *cred, int *privused)
-{
- struct acl_entry *acl_other, *acl_mask;
- mode_t dac_granted;
- mode_t cap_granted;
- mode_t acl_mask_granted;
- int group_matched, i;
-
- /*
- * Look for a normal, non-privileged way to access the file/directory
- * as requested. If it exists, go with that. Otherwise, attempt
- * to use privileges granted via cap_granted. In some cases,
- * which privileges to use may be ambiguous due to "best match",
- * in which case fall back on first match for the time being.
- */
- if (privused != NULL)
- *privused = 0;
-
- /*
- * Determine privileges now, but don't apply until we've found
- * a DAC entry that matches but has failed to allow access.
- */
-#ifndef CAPABILITIES
- if (suser_cred(cred, PRISON_ROOT) == 0)
- cap_granted = VALLPERM;
- else
- cap_granted = 0;
-#else
- cap_granted = 0;
-
- if (type == VDIR) {
- if ((acc_mode & VEXEC) && !cap_check(cred, NULL,
- CAP_DAC_READ_SEARCH, PRISON_ROOT))
- cap_granted |= VEXEC;
- } else {
- if ((acc_mode & VEXEC) && !cap_check(cred, NULL,
- CAP_DAC_EXECUTE, PRISON_ROOT))
- cap_granted |= VEXEC;
- }
-
- if ((acc_mode & VREAD) && !cap_check(cred, NULL, CAP_DAC_READ_SEARCH,
- PRISON_ROOT))
- cap_granted |= VREAD;
-
- if (((acc_mode & VWRITE) || (acc_mode & VAPPEND)) &&
- !cap_check(cred, NULL, CAP_DAC_WRITE, PRISON_ROOT))
- cap_granted |= (VWRITE | VAPPEND);
-
- if ((acc_mode & VADMIN) && !cap_check(cred, NULL, CAP_FOWNER,
- PRISON_ROOT))
- cap_granted |= VADMIN;
-#endif /* CAPABILITIES */
-
- /*
- * The owner matches if the effective uid associated with the
- * credential matches that of the ACL_USER_OBJ entry. While we're
- * doing the first scan, also cache the location of the ACL_MASK
- * and ACL_OTHER entries, preventing some future iterations.
- */
- acl_mask = acl_other = NULL;
- for (i = 0; i < acl->acl_cnt; i++) {
- switch (acl->acl_entry[i].ae_tag) {
- case ACL_USER_OBJ:
- if (file_uid != cred->cr_uid)
- break;
- dac_granted = 0;
- dac_granted |= VADMIN;
- if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl->acl_entry[i].ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl->acl_entry[i].ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
- if ((acc_mode & dac_granted) == acc_mode)
- return (0);
- if ((acc_mode & (dac_granted | cap_granted)) ==
- acc_mode) {
- if (privused != NULL)
- *privused = 1;
- return (0);
- }
- goto error;
-
- case ACL_MASK:
- acl_mask = &acl->acl_entry[i];
- break;
-
- case ACL_OTHER:
- acl_other = &acl->acl_entry[i];
- break;
-
- default:
- break;
- }
- }
-
- /*
- * An ACL_OTHER entry should always exist in a valid access
- * ACL. If it doesn't, then generate a serious failure. For now,
- * this means a debugging message and EPERM, but in the future
- * should probably be a panic.
- */
- if (acl_other == NULL) {
- /*
- * XXX This should never happen
- */
- printf("vaccess_acl_posix1e: ACL_OTHER missing\n");
- return (EPERM);
- }
-
- /*
- * Checks against ACL_USER, ACL_GROUP_OBJ, and ACL_GROUP fields
- * are masked by an ACL_MASK entry, if any. As such, first identify
- * the ACL_MASK field, then iterate through identifying potential
- * user matches, then group matches. If there is no ACL_MASK,
- * assume that the mask allows all requests to succeed.
- */
- if (acl_mask != NULL) {
- acl_mask_granted = 0;
- if (acl_mask->ae_perm & ACL_EXECUTE)
- acl_mask_granted |= VEXEC;
- if (acl_mask->ae_perm & ACL_READ)
- acl_mask_granted |= VREAD;
- if (acl_mask->ae_perm & ACL_WRITE)
- acl_mask_granted |= (VWRITE | VAPPEND);
- } else
- acl_mask_granted = VEXEC | VREAD | VWRITE | VAPPEND;
-
- /*
- * Iterate through user ACL entries. Do checks twice, first
- * without privilege, and then if a match is found but failed,
- * a second time with privilege.
- */
-
- /*
- * Check ACL_USER ACL entries.
- */
- for (i = 0; i < acl->acl_cnt; i++) {
- switch (acl->acl_entry[i].ae_tag) {
- case ACL_USER:
- if (acl->acl_entry[i].ae_id != cred->cr_uid)
- break;
- dac_granted = 0;
- if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl->acl_entry[i].ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl->acl_entry[i].ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
- dac_granted &= acl_mask_granted;
- if ((acc_mode & dac_granted) == acc_mode)
- return (0);
- if ((acc_mode & (dac_granted | cap_granted)) !=
- acc_mode)
- goto error;
-
- if (privused != NULL)
- *privused = 1;
- return (0);
- }
- }
-
- /*
- * Group match is best-match, not first-match, so find a
- * "best" match. Iterate across, testing each potential group
- * match. Make sure we keep track of whether we found a match
- * or not, so that we know if we should try again with any
- * available privilege, or if we should move on to ACL_OTHER.
- */
- group_matched = 0;
- for (i = 0; i < acl->acl_cnt; i++) {
- switch (acl->acl_entry[i].ae_tag) {
- case ACL_GROUP_OBJ:
- if (!groupmember(file_gid, cred))
- break;
- dac_granted = 0;
- if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl->acl_entry[i].ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl->acl_entry[i].ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
- dac_granted &= acl_mask_granted;
-
- if ((acc_mode & dac_granted) == acc_mode)
- return (0);
-
- group_matched = 1;
- break;
-
- case ACL_GROUP:
- if (!groupmember(acl->acl_entry[i].ae_id, cred))
- break;
- dac_granted = 0;
- if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl->acl_entry[i].ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl->acl_entry[i].ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
- dac_granted &= acl_mask_granted;
-
- if ((acc_mode & dac_granted) == acc_mode)
- return (0);
-
- group_matched = 1;
- break;
-
- default:
- break;
- }
- }
-
- if (group_matched == 1) {
- /*
- * There was a match, but it did not grant rights via
- * pure DAC. Try again, this time with privilege.
- */
- for (i = 0; i < acl->acl_cnt; i++) {
- switch (acl->acl_entry[i].ae_tag) {
- case ACL_GROUP_OBJ:
- if (!groupmember(file_gid, cred))
- break;
- dac_granted = 0;
- if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl->acl_entry[i].ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl->acl_entry[i].ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
- dac_granted &= acl_mask_granted;
-
- if ((acc_mode & (dac_granted | cap_granted)) !=
- acc_mode)
- break;
-
- if (privused != NULL)
- *privused = 1;
- return (0);
-
- case ACL_GROUP:
- if (!groupmember(acl->acl_entry[i].ae_id,
- cred))
- break;
- dac_granted = 0;
- if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl->acl_entry[i].ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl->acl_entry[i].ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
- dac_granted &= acl_mask_granted;
-
- if ((acc_mode & (dac_granted | cap_granted)) !=
- acc_mode)
- break;
-
- if (privused != NULL)
- *privused = 1;
- return (0);
-
- default:
- break;
- }
- }
- /*
- * Even with privilege, group membership was not sufficient.
- * Return failure.
- */
- goto error;
- }
-
- /*
- * Fall back on ACL_OTHER. ACL_MASK is not applied to ACL_OTHER.
- */
- dac_granted = 0;
- if (acl_other->ae_perm & ACL_EXECUTE)
- dac_granted |= VEXEC;
- if (acl_other->ae_perm & ACL_READ)
- dac_granted |= VREAD;
- if (acl_other->ae_perm & ACL_WRITE)
- dac_granted |= (VWRITE | VAPPEND);
-
- if ((acc_mode & dac_granted) == acc_mode)
- return (0);
- if ((acc_mode & (dac_granted | cap_granted)) == acc_mode) {
- if (privused != NULL)
- *privused = 1;
- return (0);
- }
-
-error:
- return ((acc_mode & VADMIN) ? EPERM : EACCES);
-}
-
-/*
- * For the purposes of filesystems maintaining the _OBJ entries in an
- * inode with a mode_t field, this routine converts a mode_t entry
- * to an acl_perm_t.
- */
-acl_perm_t
-acl_posix1e_mode_to_perm(acl_tag_t tag, mode_t mode)
-{
- acl_perm_t perm = 0;
-
- switch(tag) {
- case ACL_USER_OBJ:
- if (mode & S_IXUSR)
- perm |= ACL_EXECUTE;
- if (mode & S_IRUSR)
- perm |= ACL_READ;
- if (mode & S_IWUSR)
- perm |= ACL_WRITE;
- return (perm);
-
- case ACL_GROUP_OBJ:
- if (mode & S_IXGRP)
- perm |= ACL_EXECUTE;
- if (mode & S_IRGRP)
- perm |= ACL_READ;
- if (mode & S_IWGRP)
- perm |= ACL_WRITE;
- return (perm);
-
- case ACL_OTHER:
- if (mode & S_IXOTH)
- perm |= ACL_EXECUTE;
- if (mode & S_IROTH)
- perm |= ACL_READ;
- if (mode & S_IWOTH)
- perm |= ACL_WRITE;
- return (perm);
-
- default:
- printf("acl_posix1e_mode_to_perm: invalid tag (%d)\n", tag);
- return (0);
- }
-}
-
-/*
- * Given inode information (uid, gid, mode), return an acl entry of the
- * appropriate type.
- */
-struct acl_entry
-acl_posix1e_mode_to_entry(acl_tag_t tag, uid_t uid, gid_t gid, mode_t mode)
-{
- struct acl_entry acl_entry;
-
- acl_entry.ae_tag = tag;
- acl_entry.ae_perm = acl_posix1e_mode_to_perm(tag, mode);
- switch(tag) {
- case ACL_USER_OBJ:
- acl_entry.ae_id = uid;
- break;
-
- case ACL_GROUP_OBJ:
- acl_entry.ae_id = gid;
- break;
-
- case ACL_OTHER:
- acl_entry.ae_id = ACL_UNDEFINED_ID;
- break;
-
- default:
- acl_entry.ae_id = ACL_UNDEFINED_ID;
- printf("acl_posix1e_mode_to_entry: invalid tag (%d)\n", tag);
- }
-
- return (acl_entry);
-}
-
-/*
- * Utility function to generate a file mode given appropriate ACL entries.
- */
-mode_t
-acl_posix1e_perms_to_mode(struct acl_entry *acl_user_obj_entry,
- struct acl_entry *acl_group_obj_entry, struct acl_entry *acl_other_entry)
-{
- mode_t mode;
-
- mode = 0;
- if (acl_user_obj_entry->ae_perm & ACL_EXECUTE)
- mode |= S_IXUSR;
- if (acl_user_obj_entry->ae_perm & ACL_READ)
- mode |= S_IRUSR;
- if (acl_user_obj_entry->ae_perm & ACL_WRITE)
- mode |= S_IWUSR;
- if (acl_group_obj_entry->ae_perm & ACL_EXECUTE)
- mode |= S_IXGRP;
- if (acl_group_obj_entry->ae_perm & ACL_READ)
- mode |= S_IRGRP;
- if (acl_group_obj_entry->ae_perm & ACL_WRITE)
- mode |= S_IWGRP;
- if (acl_other_entry->ae_perm & ACL_EXECUTE)
- mode |= S_IXOTH;
- if (acl_other_entry->ae_perm & ACL_READ)
- mode |= S_IROTH;
- if (acl_other_entry->ae_perm & ACL_WRITE)
- mode |= S_IWOTH;
-
- return (mode);
-}
-
-/*
- * Perform a syntactic check of the ACL, sufficient to allow an
- * implementing filesystem to determine if it should accept this and
- * rely on the POSIX.1e ACL properties.
- */
-int
-acl_posix1e_check(struct acl *acl)
-{
- int num_acl_user_obj, num_acl_user, num_acl_group_obj, num_acl_group;
- int num_acl_mask, num_acl_other, i;
-
- /*
- * Verify that the number of entries does not exceed the maximum
- * defined for acl_t.
- * Verify that the correct number of various sorts of ae_tags are
- * present:
- * Exactly one ACL_USER_OBJ
- * Exactly one ACL_GROUP_OBJ
- * Exactly one ACL_OTHER
- * If any ACL_USER or ACL_GROUP entries appear, then exactly one
- * ACL_MASK entry must also appear.
- * Verify that all ae_perm entries are in ACL_PERM_BITS.
- * Verify all ae_tag entries are understood by this implementation.
- * Note: Does not check for uniqueness of qualifier (ae_id) field.
- */
- num_acl_user_obj = num_acl_user = num_acl_group_obj = num_acl_group =
- num_acl_mask = num_acl_other = 0;
- if (acl->acl_cnt > ACL_MAX_ENTRIES || acl->acl_cnt < 0)
- return (EINVAL);
- for (i = 0; i < acl->acl_cnt; i++) {
- /*
- * Check for a valid tag.
- */
- switch(acl->acl_entry[i].ae_tag) {
- case ACL_USER_OBJ:
- acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */
- if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
- return (EINVAL);
- num_acl_user_obj++;
- break;
- case ACL_GROUP_OBJ:
- acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */
- if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
- return (EINVAL);
- num_acl_group_obj++;
- break;
- case ACL_USER:
- if (acl->acl_entry[i].ae_id == ACL_UNDEFINED_ID)
- return (EINVAL);
- num_acl_user++;
- break;
- case ACL_GROUP:
- if (acl->acl_entry[i].ae_id == ACL_UNDEFINED_ID)
- return (EINVAL);
- num_acl_group++;
- break;
- case ACL_OTHER:
- acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */
- if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
- return (EINVAL);
- num_acl_other++;
- break;
- case ACL_MASK:
- acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */
- if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
- return (EINVAL);
- num_acl_mask++;
- break;
- default:
- return (EINVAL);
- }
- /*
- * Check for valid perm entries.
- */
- if ((acl->acl_entry[i].ae_perm | ACL_PERM_BITS) !=
- ACL_PERM_BITS)
- return (EINVAL);
- }
- if ((num_acl_user_obj != 1) || (num_acl_group_obj != 1) ||
- (num_acl_other != 1) || (num_acl_mask != 0 && num_acl_mask != 1))
- return (EINVAL);
- if (((num_acl_group != 0) || (num_acl_user != 0)) &&
- (num_acl_mask != 1))
- return (EINVAL);
- return (0);
-}
-
-/*
- * These calls wrap the real vnode operations, and are called by the
- * syscall code once the syscall has converted the path or file
- * descriptor to a vnode (unlocked). The aclp pointer is assumed
- * still to point to userland, so this should not be consumed within
- * the kernel except by syscall code. Other code should directly
- * invoke VOP_{SET,GET}ACL.
- */
-
-/*
- * Given a vnode, set its ACL.
- */
-static int
-vacl_set_acl(struct thread *td, struct vnode *vp, acl_type_t type,
- struct acl *aclp)
-{
- struct acl inkernacl;
- struct mount *mp;
- int error;
-
- error = copyin(aclp, &inkernacl, sizeof(struct acl));
- if (error)
- return(error);
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error != 0)
- return (error);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
-#ifdef MAC
- error = mac_check_vnode_setacl(td->td_ucred, vp, type, &inkernacl);
- if (error != 0)
- goto out;
-#endif
- error = VOP_SETACL(vp, type, &inkernacl, td->td_ucred, td);
-#ifdef MAC
-out:
-#endif
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- return(error);
-}
-
-/*
- * Given a vnode, get its ACL.
- */
-static int
-vacl_get_acl(struct thread *td, struct vnode *vp, acl_type_t type,
- struct acl *aclp)
-{
- struct acl inkernelacl;
- int error;
-
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
-#ifdef MAC
- error = mac_check_vnode_getacl(td->td_ucred, vp, type);
- if (error != 0)
- goto out;
-#endif
- error = VOP_GETACL(vp, type, &inkernelacl, td->td_ucred, td);
-#ifdef MAC
-out:
-#endif
- VOP_UNLOCK(vp, 0, td);
- if (error == 0)
- error = copyout(&inkernelacl, aclp, sizeof(struct acl));
- return (error);
-}
-
-/*
- * Given a vnode, delete its ACL.
- */
-static int
-vacl_delete(struct thread *td, struct vnode *vp, acl_type_t type)
-{
- struct mount *mp;
- int error;
-
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error)
- return (error);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
-#ifdef MAC
- error = mac_check_vnode_deleteacl(td->td_ucred, vp, type);
- if (error)
- goto out;
-#endif
- error = VOP_SETACL(vp, type, 0, td->td_ucred, td);
-#ifdef MAC
-out:
-#endif
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- return (error);
-}
-
-/*
- * Given a vnode, check whether an ACL is appropriate for it
- */
-static int
-vacl_aclcheck(struct thread *td, struct vnode *vp, acl_type_t type,
- struct acl *aclp)
-{
- struct acl inkernelacl;
- int error;
-
- error = copyin(aclp, &inkernelacl, sizeof(struct acl));
- if (error)
- return(error);
- error = VOP_ACLCHECK(vp, type, &inkernelacl, td->td_ucred, td);
- return (error);
-}
-
-/*
- * syscalls -- convert the path/fd to a vnode, and call vacl_whatever.
- * Don't need to lock, as the vacl_ code will get/release any locks
- * required.
- */
-
-/*
- * Given a file path, get an ACL for it
- *
- * MPSAFE
- */
-int
-__acl_get_file(struct thread *td, struct __acl_get_file_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_get_acl(td, nd.ni_vp, uap->type, uap->aclp);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, get an ACL for it; don't follow links.
- *
- * MPSAFE
- */
-int
-__acl_get_link(struct thread *td, struct __acl_get_link_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_get_acl(td, nd.ni_vp, uap->type, uap->aclp);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, set an ACL for it
- *
- * MPSAFE
- */
-int
-__acl_set_file(struct thread *td, struct __acl_set_file_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_set_acl(td, nd.ni_vp, uap->type, uap->aclp);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, set an ACL for it; don't follow links.
- *
- * MPSAFE
- */
-int
-__acl_set_link(struct thread *td, struct __acl_set_link_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_set_acl(td, nd.ni_vp, uap->type, uap->aclp);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file descriptor, get an ACL for it
- *
- * MPSAFE
- */
-int
-__acl_get_fd(struct thread *td, struct __acl_get_fd_args *uap)
-{
- struct file *fp;
- int error;
-
- mtx_lock(&Giant);
- error = getvnode(td->td_proc->p_fd, uap->filedes, &fp);
- if (error == 0) {
- error = vacl_get_acl(td, fp->f_data, uap->type, uap->aclp);
- fdrop(fp, td);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file descriptor, set an ACL for it
- *
- * MPSAFE
- */
-int
-__acl_set_fd(struct thread *td, struct __acl_set_fd_args *uap)
-{
- struct file *fp;
- int error;
-
- mtx_lock(&Giant);
- error = getvnode(td->td_proc->p_fd, uap->filedes, &fp);
- if (error == 0) {
- error = vacl_set_acl(td, fp->f_data, uap->type, uap->aclp);
- fdrop(fp, td);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, delete an ACL from it.
- *
- * MPSAFE
- */
-int
-__acl_delete_file(struct thread *td, struct __acl_delete_file_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_delete(td, nd.ni_vp, uap->type);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, delete an ACL from it; don't follow links.
- *
- * MPSAFE
- */
-int
-__acl_delete_link(struct thread *td, struct __acl_delete_link_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_delete(td, nd.ni_vp, uap->type);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, delete an ACL from it.
- *
- * MPSAFE
- */
-int
-__acl_delete_fd(struct thread *td, struct __acl_delete_fd_args *uap)
-{
- struct file *fp;
- int error;
-
- mtx_lock(&Giant);
- error = getvnode(td->td_proc->p_fd, uap->filedes, &fp);
- if (error == 0) {
- error = vacl_delete(td, fp->f_data, uap->type);
- fdrop(fp, td);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, check an ACL for it
- *
- * MPSAFE
- */
-int
-__acl_aclcheck_file(struct thread *td, struct __acl_aclcheck_file_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_aclcheck(td, nd.ni_vp, uap->type, uap->aclp);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file path, check an ACL for it; don't follow links.
- *
- * MPSAFE
- */
-int
-__acl_aclcheck_link(struct thread *td, struct __acl_aclcheck_link_args *uap)
-{
- struct nameidata nd;
- int error;
-
- mtx_lock(&Giant);
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error == 0) {
- error = vacl_aclcheck(td, nd.ni_vp, uap->type, uap->aclp);
- NDFREE(&nd, 0);
- }
- mtx_unlock(&Giant);
- return (error);
-}
-
-/*
- * Given a file descriptor, check an ACL for it
- *
- * MPSAFE
- */
-int
-__acl_aclcheck_fd(struct thread *td, struct __acl_aclcheck_fd_args *uap)
-{
- struct file *fp;
- int error;
-
- mtx_lock(&Giant);
- error = getvnode(td->td_proc->p_fd, uap->filedes, &fp);
- if (error == 0) {
- error = vacl_aclcheck(td, fp->f_data, uap->type, uap->aclp);
- fdrop(fp, td);
- }
- mtx_unlock(&Giant);
- return (error);
-}
diff --git a/sys/kern/vfs_extattr.c b/sys/kern/vfs_extattr.c
deleted file mode 100644
index 5d41208b8dd7..000000000000
--- a/sys/kern/vfs_extattr.c
+++ /dev/null
@@ -1,4326 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94
- * $FreeBSD$
- */
-
-/* For 4.3 integer FS ID compatibility */
-#include "opt_compat.h"
-#include "opt_mac.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/sysent.h>
-#include <sys/mac.h>
-#include <sys/malloc.h>
-#include <sys/mount.h>
-#include <sys/mutex.h>
-#include <sys/sysproto.h>
-#include <sys/namei.h>
-#include <sys/filedesc.h>
-#include <sys/kernel.h>
-#include <sys/fcntl.h>
-#include <sys/file.h>
-#include <sys/limits.h>
-#include <sys/linker.h>
-#include <sys/stat.h>
-#include <sys/sx.h>
-#include <sys/unistd.h>
-#include <sys/vnode.h>
-#include <sys/proc.h>
-#include <sys/dirent.h>
-#include <sys/extattr.h>
-#include <sys/jail.h>
-#include <sys/syscallsubr.h>
-#include <sys/sysctl.h>
-
-#include <machine/stdarg.h>
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/vm_page.h>
-#include <vm/uma.h>
-
-static int chroot_refuse_vdir_fds(struct filedesc *fdp);
-static int getutimes(const struct timeval *, enum uio_seg, struct timespec *);
-static int setfown(struct thread *td, struct vnode *, uid_t, gid_t);
-static int setfmode(struct thread *td, struct vnode *, int);
-static int setfflags(struct thread *td, struct vnode *, int);
-static int setutimes(struct thread *td, struct vnode *,
- const struct timespec *, int, int);
-static int vn_access(struct vnode *vp, int user_flags, struct ucred *cred,
- struct thread *td);
-
-int (*union_dircheckp)(struct thread *td, struct vnode **, struct file *);
-int (*softdep_fsync_hook)(struct vnode *);
-
-/*
- * The module initialization routine for POSIX asynchronous I/O will
- * set this to the version of AIO that it implements. (Zero means
- * that it is not implemented.) This value is used here by pathconf()
- * and in kern_descrip.c by fpathconf().
- */
-int async_io_version;
-
-/*
- * Sync each mounted filesystem.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct sync_args {
- int dummy;
-};
-#endif
-
-#ifdef DEBUG
-static int syncprt = 0;
-SYSCTL_INT(_debug, OID_AUTO, syncprt, CTLFLAG_RW, &syncprt, 0, "");
-#endif
-
-/* ARGSUSED */
-int
-sync(td, uap)
- struct thread *td;
- struct sync_args *uap;
-{
- struct mount *mp, *nmp;
- int asyncflag;
-
- mtx_lock(&mountlist_mtx);
- for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
- if (vfs_busy(mp, LK_NOWAIT, &mountlist_mtx, td)) {
- nmp = TAILQ_NEXT(mp, mnt_list);
- continue;
- }
- if ((mp->mnt_flag & MNT_RDONLY) == 0 &&
- vn_start_write(NULL, &mp, V_NOWAIT) == 0) {
- asyncflag = mp->mnt_flag & MNT_ASYNC;
- mp->mnt_flag &= ~MNT_ASYNC;
- vfs_msync(mp, MNT_NOWAIT);
- VFS_SYNC(mp, MNT_NOWAIT,
- ((td != NULL) ? td->td_ucred : NOCRED), td);
- mp->mnt_flag |= asyncflag;
- vn_finished_write(mp);
- }
- mtx_lock(&mountlist_mtx);
- nmp = TAILQ_NEXT(mp, mnt_list);
- vfs_unbusy(mp, td);
- }
- mtx_unlock(&mountlist_mtx);
-#if 0
-/*
- * XXX don't call vfs_bufstats() yet because that routine
- * was not imported in the Lite2 merge.
- */
-#ifdef DIAGNOSTIC
- if (syncprt)
- vfs_bufstats();
-#endif /* DIAGNOSTIC */
-#endif
- return (0);
-}
-
-/* XXX PRISON: could be per prison flag */
-static int prison_quotas;
-#if 0
-SYSCTL_INT(_kern_prison, OID_AUTO, quotas, CTLFLAG_RW, &prison_quotas, 0, "");
-#endif
-
-/*
- * Change filesystem quotas.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct quotactl_args {
- char *path;
- int cmd;
- int uid;
- caddr_t arg;
-};
-#endif
-/* ARGSUSED */
-int
-quotactl(td, uap)
- struct thread *td;
- register struct quotactl_args /* {
- char *path;
- int cmd;
- int uid;
- caddr_t arg;
- } */ *uap;
-{
- struct mount *mp;
- int error;
- struct nameidata nd;
-
- if (jailed(td->td_ucred) && !prison_quotas)
- return (EPERM);
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- vrele(nd.ni_vp);
- if (error)
- return (error);
- error = VFS_QUOTACTL(mp, uap->cmd, uap->uid, uap->arg, td);
- vn_finished_write(mp);
- return (error);
-}
-
-/*
- * Get filesystem statistics.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct statfs_args {
- char *path;
- struct statfs *buf;
-};
-#endif
-/* ARGSUSED */
-int
-statfs(td, uap)
- struct thread *td;
- register struct statfs_args /* {
- char *path;
- struct statfs *buf;
- } */ *uap;
-{
- register struct mount *mp;
- register struct statfs *sp;
- int error;
- struct nameidata nd;
- struct statfs sb;
-
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- mp = nd.ni_vp->v_mount;
- sp = &mp->mnt_stat;
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vrele(nd.ni_vp);
-#ifdef MAC
- error = mac_check_mount_stat(td->td_ucred, mp);
- if (error)
- return (error);
-#endif
- error = VFS_STATFS(mp, sp, td);
- if (error)
- return (error);
- sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
- if (suser(td)) {
- bcopy(sp, &sb, sizeof(sb));
- sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
- sp = &sb;
- }
- return (copyout(sp, uap->buf, sizeof(*sp)));
-}
-
-/*
- * Get filesystem statistics.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct fstatfs_args {
- int fd;
- struct statfs *buf;
-};
-#endif
-/* ARGSUSED */
-int
-fstatfs(td, uap)
- struct thread *td;
- register struct fstatfs_args /* {
- int fd;
- struct statfs *buf;
- } */ *uap;
-{
- struct file *fp;
- struct mount *mp;
- register struct statfs *sp;
- int error;
- struct statfs sb;
-
- if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
- return (error);
- mp = ((struct vnode *)fp->f_data)->v_mount;
- fdrop(fp, td);
- if (mp == NULL)
- return (EBADF);
-#ifdef MAC
- error = mac_check_mount_stat(td->td_ucred, mp);
- if (error)
- return (error);
-#endif
- sp = &mp->mnt_stat;
- error = VFS_STATFS(mp, sp, td);
- if (error)
- return (error);
- sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
- if (suser(td)) {
- bcopy(sp, &sb, sizeof(sb));
- sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
- sp = &sb;
- }
- return (copyout(sp, uap->buf, sizeof(*sp)));
-}
-
-/*
- * Get statistics on all filesystems.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct getfsstat_args {
- struct statfs *buf;
- long bufsize;
- int flags;
-};
-#endif
-int
-getfsstat(td, uap)
- struct thread *td;
- register struct getfsstat_args /* {
- struct statfs *buf;
- long bufsize;
- int flags;
- } */ *uap;
-{
- register struct mount *mp, *nmp;
- register struct statfs *sp;
- caddr_t sfsp;
- long count, maxcount, error;
-
- maxcount = uap->bufsize / sizeof(struct statfs);
- sfsp = (caddr_t)uap->buf;
- count = 0;
- mtx_lock(&mountlist_mtx);
- for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
-#ifdef MAC
- if (mac_check_mount_stat(td->td_ucred, mp) != 0) {
- nmp = TAILQ_NEXT(mp, mnt_list);
- continue;
- }
-#endif
- if (vfs_busy(mp, LK_NOWAIT, &mountlist_mtx, td)) {
- nmp = TAILQ_NEXT(mp, mnt_list);
- continue;
- }
- if (sfsp && count < maxcount) {
- sp = &mp->mnt_stat;
- /*
- * If MNT_NOWAIT or MNT_LAZY is specified, do not
- * refresh the fsstat cache. MNT_NOWAIT or MNT_LAZY
- * overrides MNT_WAIT.
- */
- if (((uap->flags & (MNT_LAZY|MNT_NOWAIT)) == 0 ||
- (uap->flags & MNT_WAIT)) &&
- (error = VFS_STATFS(mp, sp, td))) {
- mtx_lock(&mountlist_mtx);
- nmp = TAILQ_NEXT(mp, mnt_list);
- vfs_unbusy(mp, td);
- continue;
- }
- sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
- error = copyout(sp, sfsp, sizeof(*sp));
- if (error) {
- vfs_unbusy(mp, td);
- return (error);
- }
- sfsp += sizeof(*sp);
- }
- count++;
- mtx_lock(&mountlist_mtx);
- nmp = TAILQ_NEXT(mp, mnt_list);
- vfs_unbusy(mp, td);
- }
- mtx_unlock(&mountlist_mtx);
- if (sfsp && count > maxcount)
- td->td_retval[0] = maxcount;
- else
- td->td_retval[0] = count;
- return (0);
-}
-
-/*
- * Change current working directory to a given file descriptor.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct fchdir_args {
- int fd;
-};
-#endif
-/* ARGSUSED */
-int
-fchdir(td, uap)
- struct thread *td;
- struct fchdir_args /* {
- int fd;
- } */ *uap;
-{
- register struct filedesc *fdp = td->td_proc->p_fd;
- struct vnode *vp, *tdp, *vpold;
- struct mount *mp;
- struct file *fp;
- int error;
-
- if ((error = getvnode(fdp, uap->fd, &fp)) != 0)
- return (error);
- vp = fp->f_data;
- VREF(vp);
- fdrop(fp, td);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- if (vp->v_type != VDIR)
- error = ENOTDIR;
-#ifdef MAC
- else if ((error = mac_check_vnode_chdir(td->td_ucred, vp)) != 0) {
- }
-#endif
- else
- error = VOP_ACCESS(vp, VEXEC, td->td_ucred, td);
- while (!error && (mp = vp->v_mountedhere) != NULL) {
- if (vfs_busy(mp, 0, 0, td))
- continue;
- error = VFS_ROOT(mp, &tdp);
- vfs_unbusy(mp, td);
- if (error)
- break;
- vput(vp);
- vp = tdp;
- }
- if (error) {
- vput(vp);
- return (error);
- }
- VOP_UNLOCK(vp, 0, td);
- FILEDESC_LOCK(fdp);
- vpold = fdp->fd_cdir;
- fdp->fd_cdir = vp;
- FILEDESC_UNLOCK(fdp);
- vrele(vpold);
- return (0);
-}
-
-/*
- * Change current working directory (``.'').
- */
-#ifndef _SYS_SYSPROTO_H_
-struct chdir_args {
- char *path;
-};
-#endif
-/* ARGSUSED */
-int
-chdir(td, uap)
- struct thread *td;
- struct chdir_args /* {
- char *path;
- } */ *uap;
-{
-
- return (kern_chdir(td, uap->path, UIO_USERSPACE));
-}
-
-int
-kern_chdir(struct thread *td, char *path, enum uio_seg pathseg)
-{
- register struct filedesc *fdp = td->td_proc->p_fd;
- int error;
- struct nameidata nd;
- struct vnode *vp;
-
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- if ((error = change_dir(nd.ni_vp, td)) != 0) {
- vput(nd.ni_vp);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- return (error);
- }
- VOP_UNLOCK(nd.ni_vp, 0, td);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- FILEDESC_LOCK(fdp);
- vp = fdp->fd_cdir;
- fdp->fd_cdir = nd.ni_vp;
- FILEDESC_UNLOCK(fdp);
- vrele(vp);
- return (0);
-}
-
-/*
- * Helper function for raised chroot(2) security function: Refuse if
- * any filedescriptors are open directories.
- */
-static int
-chroot_refuse_vdir_fds(fdp)
- struct filedesc *fdp;
-{
- struct vnode *vp;
- struct file *fp;
- int fd;
-
- FILEDESC_LOCK_ASSERT(fdp, MA_OWNED);
- for (fd = 0; fd < fdp->fd_nfiles ; fd++) {
- fp = fget_locked(fdp, fd);
- if (fp == NULL)
- continue;
- if (fp->f_type == DTYPE_VNODE) {
- vp = fp->f_data;
- if (vp->v_type == VDIR)
- return (EPERM);
- }
- }
- return (0);
-}
-
-/*
- * This sysctl determines if we will allow a process to chroot(2) if it
- * has a directory open:
- * 0: disallowed for all processes.
- * 1: allowed for processes that were not already chroot(2)'ed.
- * 2: allowed for all processes.
- */
-
-static int chroot_allow_open_directories = 1;
-
-SYSCTL_INT(_kern, OID_AUTO, chroot_allow_open_directories, CTLFLAG_RW,
- &chroot_allow_open_directories, 0, "");
-
-/*
- * Change notion of root (``/'') directory.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct chroot_args {
- char *path;
-};
-#endif
-/* ARGSUSED */
-int
-chroot(td, uap)
- struct thread *td;
- struct chroot_args /* {
- char *path;
- } */ *uap;
-{
- int error;
- struct nameidata nd;
-
- error = suser_cred(td->td_ucred, PRISON_ROOT);
- if (error)
- return (error);
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, uap->path, td);
- mtx_lock(&Giant);
- error = namei(&nd);
- if (error)
- goto error;
- if ((error = change_dir(nd.ni_vp, td)) != 0)
- goto e_vunlock;
-#ifdef MAC
- if ((error = mac_check_vnode_chroot(td->td_ucred, nd.ni_vp)))
- goto e_vunlock;
-#endif
- VOP_UNLOCK(nd.ni_vp, 0, td);
- error = change_root(nd.ni_vp, td);
- vrele(nd.ni_vp);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- mtx_unlock(&Giant);
- return (error);
-e_vunlock:
- vput(nd.ni_vp);
-error:
- mtx_unlock(&Giant);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- return (error);
-}
-
-/*
- * Common routine for chroot and chdir. Callers must provide a locked vnode
- * instance.
- */
-int
-change_dir(vp, td)
- struct vnode *vp;
- struct thread *td;
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "change_dir(): vp not locked");
- if (vp->v_type != VDIR)
- return (ENOTDIR);
-#ifdef MAC
- error = mac_check_vnode_chdir(td->td_ucred, vp);
- if (error)
- return (error);
-#endif
- error = VOP_ACCESS(vp, VEXEC, td->td_ucred, td);
- return (error);
-}
-
-/*
- * Common routine for kern_chroot() and jail_attach(). The caller is
- * responsible for invoking suser() and mac_check_chroot() to authorize this
- * operation.
- */
-int
-change_root(vp, td)
- struct vnode *vp;
- struct thread *td;
-{
- struct filedesc *fdp;
- struct vnode *oldvp;
- int error;
-
- mtx_assert(&Giant, MA_OWNED);
- fdp = td->td_proc->p_fd;
- FILEDESC_LOCK(fdp);
- if (chroot_allow_open_directories == 0 ||
- (chroot_allow_open_directories == 1 && fdp->fd_rdir != rootvnode)) {
- error = chroot_refuse_vdir_fds(fdp);
- if (error) {
- FILEDESC_UNLOCK(fdp);
- return (error);
- }
- }
- oldvp = fdp->fd_rdir;
- fdp->fd_rdir = vp;
- VREF(fdp->fd_rdir);
- if (!fdp->fd_jdir) {
- fdp->fd_jdir = vp;
- VREF(fdp->fd_jdir);
- }
- FILEDESC_UNLOCK(fdp);
- vrele(oldvp);
- return (0);
-}
-
-/*
- * Check permissions, allocate an open file structure,
- * and call the device open routine if any.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct open_args {
- char *path;
- int flags;
- int mode;
-};
-#endif
-int
-open(td, uap)
- struct thread *td;
- register struct open_args /* {
- char *path;
- int flags;
- int mode;
- } */ *uap;
-{
-
- return (kern_open(td, uap->path, UIO_USERSPACE, uap->flags, uap->mode));
-}
-
-int
-kern_open(struct thread *td, char *path, enum uio_seg pathseg, int flags,
- int mode)
-{
- struct proc *p = td->td_proc;
- struct filedesc *fdp = p->p_fd;
- struct file *fp;
- struct vnode *vp;
- struct vattr vat;
- struct mount *mp;
- int cmode, oflags;
- struct file *nfp;
- int type, indx, error;
- struct flock lf;
- struct nameidata nd;
-
- if ((flags & O_ACCMODE) == O_ACCMODE)
- return (EINVAL);
- oflags = flags;
- flags = FFLAGS(flags);
- error = falloc(td, &nfp, &indx);
- if (error)
- return (error);
- fp = nfp;
- cmode = ((mode &~ fdp->fd_cmask) & ALLPERMS) &~ S_ISTXT;
- NDINIT(&nd, LOOKUP, FOLLOW, pathseg, path, td);
- td->td_dupfd = -indx - 1; /* XXX check for fdopen */
- /*
- * Bump the ref count to prevent another process from closing
- * the descriptor while we are blocked in vn_open()
- */
- fhold(fp);
- error = vn_open(&nd, &flags, cmode);
- if (error) {
- /*
- * release our own reference
- */
- fdrop(fp, td);
-
- /*
- * handle special fdopen() case. bleh. dupfdopen() is
- * responsible for dropping the old contents of ofiles[indx]
- * if it succeeds.
- */
- if ((error == ENODEV || error == ENXIO) &&
- td->td_dupfd >= 0 && /* XXX from fdopen */
- (error =
- dupfdopen(td, fdp, indx, td->td_dupfd, flags, error)) == 0) {
- td->td_retval[0] = indx;
- return (0);
- }
- /*
- * Clean up the descriptor, but only if another thread hadn't
- * replaced or closed it.
- */
- FILEDESC_LOCK(fdp);
- if (fdp->fd_ofiles[indx] == fp) {
- fdp->fd_ofiles[indx] = NULL;
- FILEDESC_UNLOCK(fdp);
- fdrop(fp, td);
- } else
- FILEDESC_UNLOCK(fdp);
-
- if (error == ERESTART)
- error = EINTR;
- return (error);
- }
- td->td_dupfd = 0;
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vp = nd.ni_vp;
-
- /*
- * There should be 2 references on the file, one from the descriptor
- * table, and one for us.
- *
- * Handle the case where someone closed the file (via its file
- * descriptor) while we were blocked. The end result should look
- * like opening the file succeeded but it was immediately closed.
- */
- FILEDESC_LOCK(fdp);
- FILE_LOCK(fp);
- if (fp->f_count == 1) {
- KASSERT(fdp->fd_ofiles[indx] != fp,
- ("Open file descriptor lost all refs"));
- FILEDESC_UNLOCK(fdp);
- FILE_UNLOCK(fp);
- VOP_UNLOCK(vp, 0, td);
- vn_close(vp, flags & FMASK, fp->f_cred, td);
- fdrop(fp, td);
- td->td_retval[0] = indx;
- return 0;
- }
-
- /* assert that vn_open created a backing object if one is needed */
- KASSERT(!vn_canvmio(vp) || VOP_GETVOBJECT(vp, NULL) == 0,
- ("open: vmio vnode has no backing object after vn_open"));
-
- fp->f_data = vp;
- fp->f_flag = flags & FMASK;
- fp->f_ops = &vnops;
- fp->f_type = (vp->v_type == VFIFO ? DTYPE_FIFO : DTYPE_VNODE);
- FILEDESC_UNLOCK(fdp);
- FILE_UNLOCK(fp);
- VOP_UNLOCK(vp, 0, td);
- if (flags & (O_EXLOCK | O_SHLOCK)) {
- lf.l_whence = SEEK_SET;
- lf.l_start = 0;
- lf.l_len = 0;
- if (flags & O_EXLOCK)
- lf.l_type = F_WRLCK;
- else
- lf.l_type = F_RDLCK;
- type = F_FLOCK;
- if ((flags & FNONBLOCK) == 0)
- type |= F_WAIT;
- if ((error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf,
- type)) != 0)
- goto bad;
- fp->f_flag |= FHASLOCK;
- }
- if (flags & O_TRUNC) {
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
- goto bad;
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- VATTR_NULL(&vat);
- vat.va_size = 0;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
-#ifdef MAC
- error = mac_check_vnode_write(td->td_ucred, fp->f_cred, vp);
- if (error == 0)
-#endif
- error = VOP_SETATTR(vp, &vat, td->td_ucred, td);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- if (error)
- goto bad;
- }
- /*
- * Release our private reference, leaving the one associated with
- * the descriptor table intact.
- */
- fdrop(fp, td);
- td->td_retval[0] = indx;
- return (0);
-bad:
- FILEDESC_LOCK(fdp);
- if (fdp->fd_ofiles[indx] == fp) {
- fdp->fd_ofiles[indx] = NULL;
- FILEDESC_UNLOCK(fdp);
- fdrop(fp, td);
- } else
- FILEDESC_UNLOCK(fdp);
- fdrop(fp, td);
- return (error);
-}
-
-#ifdef COMPAT_43
-/*
- * Create a file.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct ocreat_args {
- char *path;
- int mode;
-};
-#endif
-int
-ocreat(td, uap)
- struct thread *td;
- register struct ocreat_args /* {
- char *path;
- int mode;
- } */ *uap;
-{
- struct open_args /* {
- char *path;
- int flags;
- int mode;
- } */ nuap;
-
- nuap.path = uap->path;
- nuap.mode = uap->mode;
- nuap.flags = O_WRONLY | O_CREAT | O_TRUNC;
- return (open(td, &nuap));
-}
-#endif /* COMPAT_43 */
-
-/*
- * Create a special file.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct mknod_args {
- char *path;
- int mode;
- int dev;
-};
-#endif
-/* ARGSUSED */
-int
-mknod(td, uap)
- struct thread *td;
- register struct mknod_args /* {
- char *path;
- int mode;
- int dev;
- } */ *uap;
-{
-
- return (kern_mknod(td, uap->path, UIO_USERSPACE, uap->mode, uap->dev));
-}
-
-int
-kern_mknod(struct thread *td, char *path, enum uio_seg pathseg, int mode,
- int dev)
-{
- struct vnode *vp;
- struct mount *mp;
- struct vattr vattr;
- int error;
- int whiteout = 0;
- struct nameidata nd;
-
- switch (mode & S_IFMT) {
- case S_IFCHR:
- case S_IFBLK:
- error = suser(td);
- break;
- default:
- error = suser_cred(td->td_ucred, PRISON_ROOT);
- break;
- }
- if (error)
- return (error);
-restart:
- bwillwrite();
- NDINIT(&nd, CREATE, LOCKPARENT | SAVENAME, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- vp = nd.ni_vp;
- if (vp != NULL) {
- vrele(vp);
- error = EEXIST;
- } else {
- VATTR_NULL(&vattr);
- FILEDESC_LOCK(td->td_proc->p_fd);
- vattr.va_mode = (mode & ALLPERMS) &
- ~td->td_proc->p_fd->fd_cmask;
- FILEDESC_UNLOCK(td->td_proc->p_fd);
- vattr.va_rdev = dev;
- whiteout = 0;
-
- switch (mode & S_IFMT) {
- case S_IFMT: /* used by badsect to flag bad sectors */
- vattr.va_type = VBAD;
- break;
- case S_IFCHR:
- vattr.va_type = VCHR;
- break;
- case S_IFBLK:
- vattr.va_type = VBLK;
- break;
- case S_IFWHT:
- whiteout = 1;
- break;
- default:
- error = EINVAL;
- break;
- }
- }
- if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(nd.ni_dvp);
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
- return (error);
- goto restart;
- }
-#ifdef MAC
- if (error == 0 && !whiteout)
- error = mac_check_vnode_create(td->td_ucred, nd.ni_dvp,
- &nd.ni_cnd, &vattr);
-#endif
- if (!error) {
- VOP_LEASE(nd.ni_dvp, td, td->td_ucred, LEASE_WRITE);
- if (whiteout)
- error = VOP_WHITEOUT(nd.ni_dvp, &nd.ni_cnd, CREATE);
- else {
- error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp,
- &nd.ni_cnd, &vattr);
- if (error == 0)
- vput(nd.ni_vp);
- }
- }
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(nd.ni_dvp);
- vn_finished_write(mp);
- ASSERT_VOP_UNLOCKED(nd.ni_dvp, "mknod");
- ASSERT_VOP_UNLOCKED(nd.ni_vp, "mknod");
- return (error);
-}
-
-/*
- * Create a named pipe.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct mkfifo_args {
- char *path;
- int mode;
-};
-#endif
-/* ARGSUSED */
-int
-mkfifo(td, uap)
- struct thread *td;
- register struct mkfifo_args /* {
- char *path;
- int mode;
- } */ *uap;
-{
-
- return (kern_mkfifo(td, uap->path, UIO_USERSPACE, uap->mode));
-}
-
-int
-kern_mkfifo(struct thread *td, char *path, enum uio_seg pathseg, int mode)
-{
- struct mount *mp;
- struct vattr vattr;
- int error;
- struct nameidata nd;
-
-restart:
- bwillwrite();
- NDINIT(&nd, CREATE, LOCKPARENT | SAVENAME, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- if (nd.ni_vp != NULL) {
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vrele(nd.ni_vp);
- vput(nd.ni_dvp);
- return (EEXIST);
- }
- if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(nd.ni_dvp);
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
- return (error);
- goto restart;
- }
- VATTR_NULL(&vattr);
- vattr.va_type = VFIFO;
- FILEDESC_LOCK(td->td_proc->p_fd);
- vattr.va_mode = (mode & ALLPERMS) & ~td->td_proc->p_fd->fd_cmask;
- FILEDESC_UNLOCK(td->td_proc->p_fd);
-#ifdef MAC
- error = mac_check_vnode_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd,
- &vattr);
- if (error)
- goto out;
-#endif
- VOP_LEASE(nd.ni_dvp, td, td->td_ucred, LEASE_WRITE);
- error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
- if (error == 0)
- vput(nd.ni_vp);
-#ifdef MAC
-out:
-#endif
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(nd.ni_dvp);
- vn_finished_write(mp);
- return (error);
-}
-
-/*
- * Make a hard file link.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct link_args {
- char *path;
- char *link;
-};
-#endif
-/* ARGSUSED */
-int
-link(td, uap)
- struct thread *td;
- register struct link_args /* {
- char *path;
- char *link;
- } */ *uap;
-{
-
- return (kern_link(td, uap->path, uap->link, UIO_USERSPACE));
-}
-
-int
-kern_link(struct thread *td, char *path, char *link, enum uio_seg segflg)
-{
- struct vnode *vp;
- struct mount *mp;
- struct nameidata nd;
- int error;
-
- bwillwrite();
- NDINIT(&nd, LOOKUP, FOLLOW|NOOBJ, segflg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vp = nd.ni_vp;
- if (vp->v_type == VDIR) {
- vrele(vp);
- return (EPERM); /* POSIX */
- }
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) {
- vrele(vp);
- return (error);
- }
- NDINIT(&nd, CREATE, LOCKPARENT | NOOBJ | SAVENAME, segflg, link, td);
- if ((error = namei(&nd)) == 0) {
- if (nd.ni_vp != NULL) {
- vrele(nd.ni_vp);
- error = EEXIST;
- } else if ((error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td))
- == 0) {
- VOP_LEASE(nd.ni_dvp, td, td->td_ucred, LEASE_WRITE);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
-#ifdef MAC
- error = mac_check_vnode_link(td->td_ucred, nd.ni_dvp,
- vp, &nd.ni_cnd);
- if (error == 0)
-#endif
- error = VOP_LINK(nd.ni_dvp, vp, &nd.ni_cnd);
- VOP_UNLOCK(vp, 0, td);
- }
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(nd.ni_dvp);
- }
- vrele(vp);
- vn_finished_write(mp);
- ASSERT_VOP_UNLOCKED(nd.ni_dvp, "link");
- ASSERT_VOP_UNLOCKED(nd.ni_vp, "link");
- return (error);
-}
-
-/*
- * Make a symbolic link.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct symlink_args {
- char *path;
- char *link;
-};
-#endif
-/* ARGSUSED */
-int
-symlink(td, uap)
- struct thread *td;
- register struct symlink_args /* {
- char *path;
- char *link;
- } */ *uap;
-{
-
- return (kern_symlink(td, uap->path, uap->link, UIO_USERSPACE));
-}
-
-int
-kern_symlink(struct thread *td, char *path, char *link, enum uio_seg segflg)
-{
- struct mount *mp;
- struct vattr vattr;
- char *syspath;
- int error;
- struct nameidata nd;
-
- if (segflg == UIO_SYSSPACE) {
- syspath = path;
- } else {
- syspath = uma_zalloc(namei_zone, M_WAITOK);
- if ((error = copyinstr(path, syspath, MAXPATHLEN, NULL)) != 0)
- goto out;
- }
-restart:
- bwillwrite();
- NDINIT(&nd, CREATE, LOCKPARENT | NOOBJ | SAVENAME, segflg, link, td);
- if ((error = namei(&nd)) != 0)
- goto out;
- if (nd.ni_vp) {
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vrele(nd.ni_vp);
- vput(nd.ni_dvp);
- error = EEXIST;
- goto out;
- }
- if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(nd.ni_dvp);
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
- return (error);
- goto restart;
- }
- VATTR_NULL(&vattr);
- FILEDESC_LOCK(td->td_proc->p_fd);
- vattr.va_mode = ACCESSPERMS &~ td->td_proc->p_fd->fd_cmask;
- FILEDESC_UNLOCK(td->td_proc->p_fd);
-#ifdef MAC
- vattr.va_type = VLNK;
- error = mac_check_vnode_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd,
- &vattr);
- if (error)
- goto out2;
-#endif
- VOP_LEASE(nd.ni_dvp, td, td->td_ucred, LEASE_WRITE);
- error = VOP_SYMLINK(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr, syspath);
- if (error == 0)
- vput(nd.ni_vp);
-#ifdef MAC
-out2:
-#endif
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(nd.ni_dvp);
- vn_finished_write(mp);
- ASSERT_VOP_UNLOCKED(nd.ni_dvp, "symlink");
- ASSERT_VOP_UNLOCKED(nd.ni_vp, "symlink");
-out:
- if (segflg != UIO_SYSSPACE)
- uma_zfree(namei_zone, syspath);
- return (error);
-}
-
-/*
- * Delete a whiteout from the filesystem.
- */
-/* ARGSUSED */
-int
-undelete(td, uap)
- struct thread *td;
- register struct undelete_args /* {
- char *path;
- } */ *uap;
-{
- int error;
- struct mount *mp;
- struct nameidata nd;
-
-restart:
- bwillwrite();
- NDINIT(&nd, DELETE, LOCKPARENT|DOWHITEOUT, UIO_USERSPACE,
- uap->path, td);
- error = namei(&nd);
- if (error)
- return (error);
-
- if (nd.ni_vp != NULLVP || !(nd.ni_cnd.cn_flags & ISWHITEOUT)) {
- NDFREE(&nd, NDF_ONLY_PNBUF);
- if (nd.ni_vp)
- vrele(nd.ni_vp);
- vput(nd.ni_dvp);
- return (EEXIST);
- }
- if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(nd.ni_dvp);
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
- return (error);
- goto restart;
- }
- VOP_LEASE(nd.ni_dvp, td, td->td_ucred, LEASE_WRITE);
- error = VOP_WHITEOUT(nd.ni_dvp, &nd.ni_cnd, DELETE);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(nd.ni_dvp);
- vn_finished_write(mp);
- ASSERT_VOP_UNLOCKED(nd.ni_dvp, "undelete");
- ASSERT_VOP_UNLOCKED(nd.ni_vp, "undelete");
- return (error);
-}
-
-/*
- * Delete a name from the filesystem.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct unlink_args {
- char *path;
-};
-#endif
-/* ARGSUSED */
-int
-unlink(td, uap)
- struct thread *td;
- struct unlink_args /* {
- char *path;
- } */ *uap;
-{
-
- return (kern_unlink(td, uap->path, UIO_USERSPACE));
-}
-
-int
-kern_unlink(struct thread *td, char *path, enum uio_seg pathseg)
-{
- struct mount *mp;
- struct vnode *vp;
- int error;
- struct nameidata nd;
-
-restart:
- bwillwrite();
- NDINIT(&nd, DELETE, LOCKPARENT|LOCKLEAF, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- vp = nd.ni_vp;
- if (vp->v_type == VDIR)
- error = EPERM; /* POSIX */
- else {
- /*
- * The root of a mounted filesystem cannot be deleted.
- *
- * XXX: can this only be a VDIR case?
- */
- if (vp->v_vflag & VV_ROOT)
- error = EBUSY;
- }
- if (error == 0) {
- if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
- NDFREE(&nd, NDF_ONLY_PNBUF);
- if (vp == nd.ni_dvp)
- vrele(vp);
- else
- vput(vp);
- vput(nd.ni_dvp);
- if ((error = vn_start_write(NULL, &mp,
- V_XSLEEP | PCATCH)) != 0)
- return (error);
- goto restart;
- }
-#ifdef MAC
- error = mac_check_vnode_delete(td->td_ucred, nd.ni_dvp, vp,
- &nd.ni_cnd);
- if (error)
- goto out;
-#endif
- VOP_LEASE(nd.ni_dvp, td, td->td_ucred, LEASE_WRITE);
- error = VOP_REMOVE(nd.ni_dvp, vp, &nd.ni_cnd);
-#ifdef MAC
-out:
-#endif
- vn_finished_write(mp);
- }
- NDFREE(&nd, NDF_ONLY_PNBUF);
- if (vp == nd.ni_dvp)
- vrele(vp);
- else
- vput(vp);
- vput(nd.ni_dvp);
- ASSERT_VOP_UNLOCKED(nd.ni_dvp, "unlink");
- ASSERT_VOP_UNLOCKED(nd.ni_vp, "unlink");
- return (error);
-}
-
-/*
- * Reposition read/write file offset.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct lseek_args {
- int fd;
- int pad;
- off_t offset;
- int whence;
-};
-#endif
-int
-lseek(td, uap)
- struct thread *td;
- register struct lseek_args /* {
- int fd;
- int pad;
- off_t offset;
- int whence;
- } */ *uap;
-{
- struct ucred *cred = td->td_ucred;
- struct file *fp;
- struct vnode *vp;
- struct vattr vattr;
- off_t offset;
- int error, noneg;
-
- if ((error = fget(td, uap->fd, &fp)) != 0)
- return (error);
- if (fp->f_type != DTYPE_VNODE) {
- fdrop(fp, td);
- return (ESPIPE);
- }
- vp = fp->f_data;
- noneg = (vp->v_type != VCHR);
- offset = uap->offset;
- switch (uap->whence) {
- case L_INCR:
- if (noneg &&
- (fp->f_offset < 0 ||
- (offset > 0 && fp->f_offset > OFF_MAX - offset))) {
- error = EOVERFLOW;
- break;
- }
- offset += fp->f_offset;
- break;
- case L_XTND:
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- error = VOP_GETATTR(vp, &vattr, cred, td);
- VOP_UNLOCK(vp, 0, td);
- if (error)
- break;
- if (noneg &&
- (vattr.va_size > OFF_MAX ||
- (offset > 0 && vattr.va_size > OFF_MAX - offset))) {
- error = EOVERFLOW;
- break;
- }
- offset += vattr.va_size;
- break;
- case L_SET:
- break;
- default:
- error = EINVAL;
- }
- if (error == 0 && noneg && offset < 0)
- error = EINVAL;
- if (error != 0) {
- fdrop(fp, td);
- return (error);
- }
- fp->f_offset = offset;
- *(off_t *)(td->td_retval) = fp->f_offset;
- fdrop(fp, td);
- return (0);
-}
-
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
-/*
- * Reposition read/write file offset.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct olseek_args {
- int fd;
- long offset;
- int whence;
-};
-#endif
-int
-olseek(td, uap)
- struct thread *td;
- register struct olseek_args /* {
- int fd;
- long offset;
- int whence;
- } */ *uap;
-{
- struct lseek_args /* {
- int fd;
- int pad;
- off_t offset;
- int whence;
- } */ nuap;
- int error;
-
- nuap.fd = uap->fd;
- nuap.offset = uap->offset;
- nuap.whence = uap->whence;
- error = lseek(td, &nuap);
- return (error);
-}
-#endif /* COMPAT_43 */
-
-/*
- * Check access permissions using passed credentials.
- */
-static int
-vn_access(vp, user_flags, cred, td)
- struct vnode *vp;
- int user_flags;
- struct ucred *cred;
- struct thread *td;
-{
- int error, flags;
-
- /* Flags == 0 means only check for existence. */
- error = 0;
- if (user_flags) {
- flags = 0;
- if (user_flags & R_OK)
- flags |= VREAD;
- if (user_flags & W_OK)
- flags |= VWRITE;
- if (user_flags & X_OK)
- flags |= VEXEC;
-#ifdef MAC
- error = mac_check_vnode_access(cred, vp, flags);
- if (error)
- return (error);
-#endif
- if ((flags & VWRITE) == 0 || (error = vn_writechk(vp)) == 0)
- error = VOP_ACCESS(vp, flags, cred, td);
- }
- return (error);
-}
-
-/*
- * Check access permissions using "real" credentials.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct access_args {
- char *path;
- int flags;
-};
-#endif
-int
-access(td, uap)
- struct thread *td;
- register struct access_args /* {
- char *path;
- int flags;
- } */ *uap;
-{
-
- return (kern_access(td, uap->path, UIO_USERSPACE, uap->flags));
-}
-
-int
-kern_access(struct thread *td, char *path, enum uio_seg pathseg, int flags)
-{
- struct ucred *cred, *tmpcred;
- register struct vnode *vp;
- int error;
- struct nameidata nd;
-
- /*
- * Create and modify a temporary credential instead of one that
- * is potentially shared. This could also mess up socket
- * buffer accounting which can run in an interrupt context.
- *
- * XXX - Depending on how "threads" are finally implemented, it
- * may be better to explicitly pass the credential to namei()
- * rather than to modify the potentially shared process structure.
- */
- cred = td->td_ucred;
- tmpcred = crdup(cred);
- tmpcred->cr_uid = cred->cr_ruid;
- tmpcred->cr_groups[0] = cred->cr_rgid;
- td->td_ucred = tmpcred;
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NOOBJ, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- goto out1;
- vp = nd.ni_vp;
-
- error = vn_access(vp, flags, tmpcred, td);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(vp);
-out1:
- td->td_ucred = cred;
- crfree(tmpcred);
- return (error);
-}
-
-/*
- * Check access permissions using "effective" credentials.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct eaccess_args {
- char *path;
- int flags;
-};
-#endif
-int
-eaccess(td, uap)
- struct thread *td;
- register struct eaccess_args /* {
- char *path;
- int flags;
- } */ *uap;
-{
- struct nameidata nd;
- struct vnode *vp;
- int error;
-
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
- uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- vp = nd.ni_vp;
-
- error = vn_access(vp, uap->flags, td->td_ucred, td);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(vp);
- return (error);
-}
-
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
-/*
- * Get file status; this version follows links.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct ostat_args {
- char *path;
- struct ostat *ub;
-};
-#endif
-/* ARGSUSED */
-int
-ostat(td, uap)
- struct thread *td;
- register struct ostat_args /* {
- char *path;
- struct ostat *ub;
- } */ *uap;
-{
- struct stat sb;
- struct ostat osb;
- int error;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
- uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- error = vn_stat(nd.ni_vp, &sb, td->td_ucred, NOCRED, td);
- vput(nd.ni_vp);
- if (error)
- return (error);
- cvtstat(&sb, &osb);
- error = copyout(&osb, uap->ub, sizeof (osb));
- return (error);
-}
-
-/*
- * Get file status; this version does not follow links.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct olstat_args {
- char *path;
- struct ostat *ub;
-};
-#endif
-/* ARGSUSED */
-int
-olstat(td, uap)
- struct thread *td;
- register struct olstat_args /* {
- char *path;
- struct ostat *ub;
- } */ *uap;
-{
- struct vnode *vp;
- struct stat sb;
- struct ostat osb;
- int error;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
- uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- vp = nd.ni_vp;
- error = vn_stat(vp, &sb, td->td_ucred, NOCRED, td);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(vp);
- if (error)
- return (error);
- cvtstat(&sb, &osb);
- error = copyout(&osb, uap->ub, sizeof (osb));
- return (error);
-}
-
-/*
- * Convert from an old to a new stat structure.
- */
-void
-cvtstat(st, ost)
- struct stat *st;
- struct ostat *ost;
-{
-
- ost->st_dev = st->st_dev;
- ost->st_ino = st->st_ino;
- ost->st_mode = st->st_mode;
- ost->st_nlink = st->st_nlink;
- ost->st_uid = st->st_uid;
- ost->st_gid = st->st_gid;
- ost->st_rdev = st->st_rdev;
- if (st->st_size < (quad_t)1 << 32)
- ost->st_size = st->st_size;
- else
- ost->st_size = -2;
- ost->st_atime = st->st_atime;
- ost->st_mtime = st->st_mtime;
- ost->st_ctime = st->st_ctime;
- ost->st_blksize = st->st_blksize;
- ost->st_blocks = st->st_blocks;
- ost->st_flags = st->st_flags;
- ost->st_gen = st->st_gen;
-}
-#endif /* COMPAT_43 || COMPAT_SUNOS */
-
-/*
- * Get file status; this version follows links.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct stat_args {
- char *path;
- struct stat *ub;
-};
-#endif
-/* ARGSUSED */
-int
-stat(td, uap)
- struct thread *td;
- register struct stat_args /* {
- char *path;
- struct stat *ub;
- } */ *uap;
-{
- struct stat sb;
- int error;
- struct nameidata nd;
-
-#ifdef LOOKUP_SHARED
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKSHARED | LOCKLEAF | NOOBJ,
- UIO_USERSPACE, uap->path, td);
-#else
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
- uap->path, td);
-#endif
- if ((error = namei(&nd)) != 0)
- return (error);
- error = vn_stat(nd.ni_vp, &sb, td->td_ucred, NOCRED, td);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(nd.ni_vp);
- if (error)
- return (error);
- error = copyout(&sb, uap->ub, sizeof (sb));
- return (error);
-}
-
-/*
- * Get file status; this version does not follow links.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct lstat_args {
- char *path;
- struct stat *ub;
-};
-#endif
-/* ARGSUSED */
-int
-lstat(td, uap)
- struct thread *td;
- register struct lstat_args /* {
- char *path;
- struct stat *ub;
- } */ *uap;
-{
- int error;
- struct vnode *vp;
- struct stat sb;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
- uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- vp = nd.ni_vp;
- error = vn_stat(vp, &sb, td->td_ucred, NOCRED, td);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(vp);
- if (error)
- return (error);
- error = copyout(&sb, uap->ub, sizeof (sb));
- return (error);
-}
-
-/*
- * Implementation of the NetBSD stat() function.
- * XXX This should probably be collapsed with the FreeBSD version,
- * as the differences are only due to vn_stat() clearing spares at
- * the end of the structures. vn_stat could be split to avoid this,
- * and thus collapse the following to close to zero code.
- */
-void
-cvtnstat(sb, nsb)
- struct stat *sb;
- struct nstat *nsb;
-{
- bzero(nsb, sizeof *nsb);
- nsb->st_dev = sb->st_dev;
- nsb->st_ino = sb->st_ino;
- nsb->st_mode = sb->st_mode;
- nsb->st_nlink = sb->st_nlink;
- nsb->st_uid = sb->st_uid;
- nsb->st_gid = sb->st_gid;
- nsb->st_rdev = sb->st_rdev;
- nsb->st_atimespec = sb->st_atimespec;
- nsb->st_mtimespec = sb->st_mtimespec;
- nsb->st_ctimespec = sb->st_ctimespec;
- nsb->st_size = sb->st_size;
- nsb->st_blocks = sb->st_blocks;
- nsb->st_blksize = sb->st_blksize;
- nsb->st_flags = sb->st_flags;
- nsb->st_gen = sb->st_gen;
- nsb->st_birthtimespec = sb->st_birthtimespec;
-}
-
-#ifndef _SYS_SYSPROTO_H_
-struct nstat_args {
- char *path;
- struct nstat *ub;
-};
-#endif
-/* ARGSUSED */
-int
-nstat(td, uap)
- struct thread *td;
- register struct nstat_args /* {
- char *path;
- struct nstat *ub;
- } */ *uap;
-{
- struct stat sb;
- struct nstat nsb;
- int error;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
- uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- error = vn_stat(nd.ni_vp, &sb, td->td_ucred, NOCRED, td);
- vput(nd.ni_vp);
- if (error)
- return (error);
- cvtnstat(&sb, &nsb);
- error = copyout(&nsb, uap->ub, sizeof (nsb));
- return (error);
-}
-
-/*
- * NetBSD lstat. Get file status; this version does not follow links.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct lstat_args {
- char *path;
- struct stat *ub;
-};
-#endif
-/* ARGSUSED */
-int
-nlstat(td, uap)
- struct thread *td;
- register struct nlstat_args /* {
- char *path;
- struct nstat *ub;
- } */ *uap;
-{
- int error;
- struct vnode *vp;
- struct stat sb;
- struct nstat nsb;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
- uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- vp = nd.ni_vp;
- NDFREE(&nd, NDF_ONLY_PNBUF);
- error = vn_stat(vp, &sb, td->td_ucred, NOCRED, td);
- vput(vp);
- if (error)
- return (error);
- cvtnstat(&sb, &nsb);
- error = copyout(&nsb, uap->ub, sizeof (nsb));
- return (error);
-}
-
-/*
- * Get configurable pathname variables.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct pathconf_args {
- char *path;
- int name;
-};
-#endif
-/* ARGSUSED */
-int
-pathconf(td, uap)
- struct thread *td;
- register struct pathconf_args /* {
- char *path;
- int name;
- } */ *uap;
-{
- int error;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
- uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
-
- /* If asynchronous I/O is available, it works for all files. */
- if (uap->name == _PC_ASYNC_IO)
- td->td_retval[0] = async_io_version;
- else
- error = VOP_PATHCONF(nd.ni_vp, uap->name, td->td_retval);
- vput(nd.ni_vp);
- return (error);
-}
-
-/*
- * Return target name of a symbolic link.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct readlink_args {
- char *path;
- char *buf;
- int count;
-};
-#endif
-/* ARGSUSED */
-int
-readlink(td, uap)
- struct thread *td;
- register struct readlink_args /* {
- char *path;
- char *buf;
- int count;
- } */ *uap;
-{
-
- return (kern_readlink(td, uap->path, UIO_USERSPACE, uap->buf,
- UIO_USERSPACE, uap->count));
-}
-
-int
-kern_readlink(struct thread *td, char *path, enum uio_seg pathseg, char *buf,
- enum uio_seg bufseg, int count)
-{
- register struct vnode *vp;
- struct iovec aiov;
- struct uio auio;
- int error;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | NOOBJ, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vp = nd.ni_vp;
-#ifdef MAC
- error = mac_check_vnode_readlink(td->td_ucred, vp);
- if (error) {
- vput(vp);
- return (error);
- }
-#endif
- if (vp->v_type != VLNK)
- error = EINVAL;
- else {
- aiov.iov_base = buf;
- aiov.iov_len = count;
- auio.uio_iov = &aiov;
- auio.uio_iovcnt = 1;
- auio.uio_offset = 0;
- auio.uio_rw = UIO_READ;
- auio.uio_segflg = bufseg;
- auio.uio_td = td;
- auio.uio_resid = count;
- error = VOP_READLINK(vp, &auio, td->td_ucred);
- }
- vput(vp);
- td->td_retval[0] = count - auio.uio_resid;
- return (error);
-}
-
-/*
- * Common implementation code for chflags() and fchflags().
- */
-static int
-setfflags(td, vp, flags)
- struct thread *td;
- struct vnode *vp;
- int flags;
-{
- int error;
- struct mount *mp;
- struct vattr vattr;
-
- /*
- * Prevent non-root users from setting flags on devices. When
- * a device is reused, users can retain ownership of the device
- * if they are allowed to set flags and programs assume that
- * chown can't fail when done as root.
- */
- if (vp->v_type == VCHR || vp->v_type == VBLK) {
- error = suser_cred(td->td_ucred, PRISON_ROOT);
- if (error)
- return (error);
- }
-
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
- return (error);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- VATTR_NULL(&vattr);
- vattr.va_flags = flags;
-#ifdef MAC
- error = mac_check_vnode_setflags(td->td_ucred, vp, vattr.va_flags);
- if (error == 0)
-#endif
- error = VOP_SETATTR(vp, &vattr, td->td_ucred, td);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- return (error);
-}
-
-/*
- * Change flags of a file given a path name.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct chflags_args {
- char *path;
- int flags;
-};
-#endif
-/* ARGSUSED */
-int
-chflags(td, uap)
- struct thread *td;
- register struct chflags_args /* {
- char *path;
- int flags;
- } */ *uap;
-{
- int error;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- error = setfflags(td, nd.ni_vp, uap->flags);
- vrele(nd.ni_vp);
- return error;
-}
-
-/*
- * Same as chflags() but doesn't follow symlinks.
- */
-int
-lchflags(td, uap)
- struct thread *td;
- register struct lchflags_args /* {
- char *path;
- int flags;
- } */ *uap;
-{
- int error;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- error = setfflags(td, nd.ni_vp, uap->flags);
- vrele(nd.ni_vp);
- return error;
-}
-
-/*
- * Change flags of a file given a file descriptor.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct fchflags_args {
- int fd;
- int flags;
-};
-#endif
-/* ARGSUSED */
-int
-fchflags(td, uap)
- struct thread *td;
- register struct fchflags_args /* {
- int fd;
- int flags;
- } */ *uap;
-{
- struct file *fp;
- int error;
-
- if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
- return (error);
- error = setfflags(td, fp->f_data, uap->flags);
- fdrop(fp, td);
- return (error);
-}
-
-/*
- * Common implementation code for chmod(), lchmod() and fchmod().
- */
-static int
-setfmode(td, vp, mode)
- struct thread *td;
- struct vnode *vp;
- int mode;
-{
- int error;
- struct mount *mp;
- struct vattr vattr;
-
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
- return (error);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- VATTR_NULL(&vattr);
- vattr.va_mode = mode & ALLPERMS;
-#ifdef MAC
- error = mac_check_vnode_setmode(td->td_ucred, vp, vattr.va_mode);
- if (error == 0)
-#endif
- error = VOP_SETATTR(vp, &vattr, td->td_ucred, td);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- return error;
-}
-
-/*
- * Change mode of a file given path name.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct chmod_args {
- char *path;
- int mode;
-};
-#endif
-/* ARGSUSED */
-int
-chmod(td, uap)
- struct thread *td;
- register struct chmod_args /* {
- char *path;
- int mode;
- } */ *uap;
-{
-
- return (kern_chmod(td, uap->path, UIO_USERSPACE, uap->mode));
-}
-
-int
-kern_chmod(struct thread *td, char *path, enum uio_seg pathseg, int mode)
-{
- int error;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, FOLLOW, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- error = setfmode(td, nd.ni_vp, mode);
- vrele(nd.ni_vp);
- return error;
-}
-
-/*
- * Change mode of a file given path name (don't follow links.)
- */
-#ifndef _SYS_SYSPROTO_H_
-struct lchmod_args {
- char *path;
- int mode;
-};
-#endif
-/* ARGSUSED */
-int
-lchmod(td, uap)
- struct thread *td;
- register struct lchmod_args /* {
- char *path;
- int mode;
- } */ *uap;
-{
- int error;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- error = setfmode(td, nd.ni_vp, uap->mode);
- vrele(nd.ni_vp);
- return error;
-}
-
-/*
- * Change mode of a file given a file descriptor.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct fchmod_args {
- int fd;
- int mode;
-};
-#endif
-/* ARGSUSED */
-int
-fchmod(td, uap)
- struct thread *td;
- register struct fchmod_args /* {
- int fd;
- int mode;
- } */ *uap;
-{
- struct file *fp;
- struct vnode *vp;
- int error;
-
- if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
- return (error);
- vp = fp->f_data;
- error = setfmode(td, fp->f_data, uap->mode);
- fdrop(fp, td);
- return (error);
-}
-
-/*
- * Common implementation for chown(), lchown(), and fchown()
- */
-static int
-setfown(td, vp, uid, gid)
- struct thread *td;
- struct vnode *vp;
- uid_t uid;
- gid_t gid;
-{
- int error;
- struct mount *mp;
- struct vattr vattr;
-
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
- return (error);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- VATTR_NULL(&vattr);
- vattr.va_uid = uid;
- vattr.va_gid = gid;
-#ifdef MAC
- error = mac_check_vnode_setowner(td->td_ucred, vp, vattr.va_uid,
- vattr.va_gid);
- if (error == 0)
-#endif
- error = VOP_SETATTR(vp, &vattr, td->td_ucred, td);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- return error;
-}
-
-/*
- * Set ownership given a path name.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct chown_args {
- char *path;
- int uid;
- int gid;
-};
-#endif
-/* ARGSUSED */
-int
-chown(td, uap)
- struct thread *td;
- register struct chown_args /* {
- char *path;
- int uid;
- int gid;
- } */ *uap;
-{
-
- return (kern_chown(td, uap->path, UIO_USERSPACE, uap->uid, uap->gid));
-}
-
-int
-kern_chown(struct thread *td, char *path, enum uio_seg pathseg, int uid,
- int gid)
-{
- int error;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, FOLLOW, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- error = setfown(td, nd.ni_vp, uid, gid);
- vrele(nd.ni_vp);
- return (error);
-}
-
-/*
- * Set ownership given a path name, do not cross symlinks.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct lchown_args {
- char *path;
- int uid;
- int gid;
-};
-#endif
-/* ARGSUSED */
-int
-lchown(td, uap)
- struct thread *td;
- register struct lchown_args /* {
- char *path;
- int uid;
- int gid;
- } */ *uap;
-{
-
- return (kern_lchown(td, uap->path, UIO_USERSPACE, uap->uid, uap->gid));
-}
-
-int
-kern_lchown(struct thread *td, char *path, enum uio_seg pathseg, int uid,
- int gid)
-{
- int error;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, NOFOLLOW, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- error = setfown(td, nd.ni_vp, uid, gid);
- vrele(nd.ni_vp);
- return (error);
-}
-
-/*
- * Set ownership given a file descriptor.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct fchown_args {
- int fd;
- int uid;
- int gid;
-};
-#endif
-/* ARGSUSED */
-int
-fchown(td, uap)
- struct thread *td;
- register struct fchown_args /* {
- int fd;
- int uid;
- int gid;
- } */ *uap;
-{
- struct file *fp;
- struct vnode *vp;
- int error;
-
- if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
- return (error);
- vp = fp->f_data;
- error = setfown(td, fp->f_data, uap->uid, uap->gid);
- fdrop(fp, td);
- return (error);
-}
-
-/*
- * Common implementation code for utimes(), lutimes(), and futimes().
- */
-static int
-getutimes(usrtvp, tvpseg, tsp)
- const struct timeval *usrtvp;
- enum uio_seg tvpseg;
- struct timespec *tsp;
-{
- struct timeval tv[2];
- const struct timeval *tvp;
- int error;
-
- if (usrtvp == NULL) {
- microtime(&tv[0]);
- TIMEVAL_TO_TIMESPEC(&tv[0], &tsp[0]);
- tsp[1] = tsp[0];
- } else {
- if (tvpseg == UIO_SYSSPACE) {
- tvp = usrtvp;
- } else {
- if ((error = copyin(usrtvp, tv, sizeof(tv))) != 0)
- return (error);
- tvp = tv;
- }
-
- TIMEVAL_TO_TIMESPEC(&tvp[0], &tsp[0]);
- TIMEVAL_TO_TIMESPEC(&tvp[1], &tsp[1]);
- }
- return 0;
-}
-
-/*
- * Common implementation code for utimes(), lutimes(), and futimes().
- */
-static int
-setutimes(td, vp, ts, numtimes, nullflag)
- struct thread *td;
- struct vnode *vp;
- const struct timespec *ts;
- int numtimes;
- int nullflag;
-{
- int error, setbirthtime;
- struct mount *mp;
- struct vattr vattr;
-
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
- return (error);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- setbirthtime = 0;
- if (numtimes < 3 && VOP_GETATTR(vp, &vattr, td->td_ucred, td) == 0 &&
- timespeccmp(&ts[1], &vattr.va_birthtime, < ))
- setbirthtime = 1;
- VATTR_NULL(&vattr);
- vattr.va_atime = ts[0];
- vattr.va_mtime = ts[1];
- if (setbirthtime)
- vattr.va_birthtime = ts[1];
- if (numtimes > 2)
- vattr.va_birthtime = ts[2];
- if (nullflag)
- vattr.va_vaflags |= VA_UTIMES_NULL;
-#ifdef MAC
- error = mac_check_vnode_setutimes(td->td_ucred, vp, vattr.va_atime,
- vattr.va_mtime);
-#endif
- if (error == 0)
- error = VOP_SETATTR(vp, &vattr, td->td_ucred, td);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- return error;
-}
-
-/*
- * Set the access and modification times of a file.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct utimes_args {
- char *path;
- struct timeval *tptr;
-};
-#endif
-/* ARGSUSED */
-int
-utimes(td, uap)
- struct thread *td;
- register struct utimes_args /* {
- char *path;
- struct timeval *tptr;
- } */ *uap;
-{
-
- return (kern_utimes(td, uap->path, UIO_USERSPACE, uap->tptr,
- UIO_USERSPACE));
-}
-
-int
-kern_utimes(struct thread *td, char *path, enum uio_seg pathseg,
- struct timeval *tptr, enum uio_seg tptrseg)
-{
- struct timespec ts[2];
- int error;
- struct nameidata nd;
-
- if ((error = getutimes(tptr, tptrseg, ts)) != 0)
- return (error);
- NDINIT(&nd, LOOKUP, FOLLOW, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- error = setutimes(td, nd.ni_vp, ts, 2, tptr == NULL);
- vrele(nd.ni_vp);
- return (error);
-}
-
-/*
- * Set the access and modification times of a file.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct lutimes_args {
- char *path;
- struct timeval *tptr;
-};
-#endif
-/* ARGSUSED */
-int
-lutimes(td, uap)
- struct thread *td;
- register struct lutimes_args /* {
- char *path;
- struct timeval *tptr;
- } */ *uap;
-{
-
- return (kern_lutimes(td, uap->path, UIO_USERSPACE, uap->tptr,
- UIO_USERSPACE));
-}
-
-int
-kern_lutimes(struct thread *td, char *path, enum uio_seg pathseg,
- struct timeval *tptr, enum uio_seg tptrseg)
-{
- struct timespec ts[2];
- int error;
- struct nameidata nd;
-
- if ((error = getutimes(tptr, tptrseg, ts)) != 0)
- return (error);
- NDINIT(&nd, LOOKUP, NOFOLLOW, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- error = setutimes(td, nd.ni_vp, ts, 2, tptr == NULL);
- vrele(nd.ni_vp);
- return (error);
-}
-
-/*
- * Set the access and modification times of a file.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct futimes_args {
- int fd;
- struct timeval *tptr;
-};
-#endif
-/* ARGSUSED */
-int
-futimes(td, uap)
- struct thread *td;
- register struct futimes_args /* {
- int fd;
- struct timeval *tptr;
- } */ *uap;
-{
-
- return (kern_futimes(td, uap->fd, uap->tptr, UIO_USERSPACE));
-}
-
-int
-kern_futimes(struct thread *td, int fd, struct timeval *tptr,
- enum uio_seg tptrseg)
-{
- struct timespec ts[2];
- struct file *fp;
- int error;
-
- if ((error = getutimes(tptr, tptrseg, ts)) != 0)
- return (error);
- if ((error = getvnode(td->td_proc->p_fd, fd, &fp)) != 0)
- return (error);
- error = setutimes(td, fp->f_data, ts, 2, tptr == NULL);
- fdrop(fp, td);
- return (error);
-}
-
-/*
- * Truncate a file given its path name.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct truncate_args {
- char *path;
- int pad;
- off_t length;
-};
-#endif
-/* ARGSUSED */
-int
-truncate(td, uap)
- struct thread *td;
- register struct truncate_args /* {
- char *path;
- int pad;
- off_t length;
- } */ *uap;
-{
-
- return (kern_truncate(td, uap->path, UIO_USERSPACE, uap->length));
-}
-
-int
-kern_truncate(struct thread *td, char *path, enum uio_seg pathseg, off_t length)
-{
- struct mount *mp;
- struct vnode *vp;
- struct vattr vattr;
- int error;
- struct nameidata nd;
-
- if (length < 0)
- return(EINVAL);
- NDINIT(&nd, LOOKUP, FOLLOW, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- vp = nd.ni_vp;
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) {
- vrele(vp);
- return (error);
- }
- NDFREE(&nd, NDF_ONLY_PNBUF);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- if (vp->v_type == VDIR)
- error = EISDIR;
-#ifdef MAC
- else if ((error = mac_check_vnode_write(td->td_ucred, NOCRED, vp))) {
- }
-#endif
- else if ((error = vn_writechk(vp)) == 0 &&
- (error = VOP_ACCESS(vp, VWRITE, td->td_ucred, td)) == 0) {
- VATTR_NULL(&vattr);
- vattr.va_size = length;
- error = VOP_SETATTR(vp, &vattr, td->td_ucred, td);
- }
- vput(vp);
- vn_finished_write(mp);
- return (error);
-}
-
-/*
- * Truncate a file given a file descriptor.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct ftruncate_args {
- int fd;
- int pad;
- off_t length;
-};
-#endif
-/* ARGSUSED */
-int
-ftruncate(td, uap)
- struct thread *td;
- register struct ftruncate_args /* {
- int fd;
- int pad;
- off_t length;
- } */ *uap;
-{
- struct mount *mp;
- struct vattr vattr;
- struct vnode *vp;
- struct file *fp;
- int error;
-
- if (uap->length < 0)
- return(EINVAL);
- if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
- return (error);
- if ((fp->f_flag & FWRITE) == 0) {
- fdrop(fp, td);
- return (EINVAL);
- }
- vp = fp->f_data;
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) {
- fdrop(fp, td);
- return (error);
- }
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- if (vp->v_type == VDIR)
- error = EISDIR;
-#ifdef MAC
- else if ((error = mac_check_vnode_write(td->td_ucred, fp->f_cred,
- vp))) {
- }
-#endif
- else if ((error = vn_writechk(vp)) == 0) {
- VATTR_NULL(&vattr);
- vattr.va_size = uap->length;
- error = VOP_SETATTR(vp, &vattr, fp->f_cred, td);
- }
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- fdrop(fp, td);
- return (error);
-}
-
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
-/*
- * Truncate a file given its path name.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct otruncate_args {
- char *path;
- long length;
-};
-#endif
-/* ARGSUSED */
-int
-otruncate(td, uap)
- struct thread *td;
- register struct otruncate_args /* {
- char *path;
- long length;
- } */ *uap;
-{
- struct truncate_args /* {
- char *path;
- int pad;
- off_t length;
- } */ nuap;
-
- nuap.path = uap->path;
- nuap.length = uap->length;
- return (truncate(td, &nuap));
-}
-
-/*
- * Truncate a file given a file descriptor.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct oftruncate_args {
- int fd;
- long length;
-};
-#endif
-/* ARGSUSED */
-int
-oftruncate(td, uap)
- struct thread *td;
- register struct oftruncate_args /* {
- int fd;
- long length;
- } */ *uap;
-{
- struct ftruncate_args /* {
- int fd;
- int pad;
- off_t length;
- } */ nuap;
-
- nuap.fd = uap->fd;
- nuap.length = uap->length;
- return (ftruncate(td, &nuap));
-}
-#endif /* COMPAT_43 || COMPAT_SUNOS */
-
-/*
- * Sync an open file.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct fsync_args {
- int fd;
-};
-#endif
-/* ARGSUSED */
-int
-fsync(td, uap)
- struct thread *td;
- struct fsync_args /* {
- int fd;
- } */ *uap;
-{
- struct vnode *vp;
- struct mount *mp;
- struct file *fp;
- vm_object_t obj;
- int error;
-
- GIANT_REQUIRED;
-
- if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
- return (error);
- vp = fp->f_data;
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) {
- fdrop(fp, td);
- return (error);
- }
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- if (VOP_GETVOBJECT(vp, &obj) == 0) {
- VM_OBJECT_LOCK(obj);
- vm_object_page_clean(obj, 0, 0, 0);
- VM_OBJECT_UNLOCK(obj);
- }
- error = VOP_FSYNC(vp, fp->f_cred, MNT_WAIT, td);
- if (error == 0 && vp->v_mount && (vp->v_mount->mnt_flag & MNT_SOFTDEP)
- && softdep_fsync_hook != NULL)
- error = (*softdep_fsync_hook)(vp);
-
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- fdrop(fp, td);
- return (error);
-}
-
-/*
- * Rename files. Source and destination must either both be directories,
- * or both not be directories. If target is a directory, it must be empty.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct rename_args {
- char *from;
- char *to;
-};
-#endif
-/* ARGSUSED */
-int
-rename(td, uap)
- struct thread *td;
- register struct rename_args /* {
- char *from;
- char *to;
- } */ *uap;
-{
-
- return (kern_rename(td, uap->from, uap->to, UIO_USERSPACE));
-}
-
-int
-kern_rename(struct thread *td, char *from, char *to, enum uio_seg pathseg)
-{
- struct mount *mp = NULL;
- struct vnode *tvp, *fvp, *tdvp;
- struct nameidata fromnd, tond;
- int error;
-
- bwillwrite();
-#ifdef MAC
- NDINIT(&fromnd, DELETE, LOCKPARENT | LOCKLEAF | SAVESTART, pathseg,
- from, td);
-#else
- NDINIT(&fromnd, DELETE, WANTPARENT | SAVESTART, pathseg, from, td);
-#endif
- if ((error = namei(&fromnd)) != 0)
- return (error);
-#ifdef MAC
- error = mac_check_vnode_rename_from(td->td_ucred, fromnd.ni_dvp,
- fromnd.ni_vp, &fromnd.ni_cnd);
- VOP_UNLOCK(fromnd.ni_dvp, 0, td);
- VOP_UNLOCK(fromnd.ni_vp, 0, td);
-#endif
- fvp = fromnd.ni_vp;
- if (error == 0)
- error = vn_start_write(fvp, &mp, V_WAIT | PCATCH);
- if (error != 0) {
- NDFREE(&fromnd, NDF_ONLY_PNBUF);
- vrele(fromnd.ni_dvp);
- vrele(fvp);
- goto out1;
- }
- NDINIT(&tond, RENAME, LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART |
- NOOBJ, pathseg, to, td);
- if (fromnd.ni_vp->v_type == VDIR)
- tond.ni_cnd.cn_flags |= WILLBEDIR;
- if ((error = namei(&tond)) != 0) {
- /* Translate error code for rename("dir1", "dir2/."). */
- if (error == EISDIR && fvp->v_type == VDIR)
- error = EINVAL;
- NDFREE(&fromnd, NDF_ONLY_PNBUF);
- vrele(fromnd.ni_dvp);
- vrele(fvp);
- goto out1;
- }
- tdvp = tond.ni_dvp;
- tvp = tond.ni_vp;
- if (tvp != NULL) {
- if (fvp->v_type == VDIR && tvp->v_type != VDIR) {
- error = ENOTDIR;
- goto out;
- } else if (fvp->v_type != VDIR && tvp->v_type == VDIR) {
- error = EISDIR;
- goto out;
- }
- }
- if (fvp == tdvp)
- error = EINVAL;
- /*
- * If the source is the same as the destination (that is, if they
- * are links to the same vnode), then there is nothing to do.
- */
- if (fvp == tvp)
- error = -1;
-#ifdef MAC
- else
- error = mac_check_vnode_rename_to(td->td_ucred, tdvp,
- tond.ni_vp, fromnd.ni_dvp == tdvp, &tond.ni_cnd);
-#endif
-out:
- if (!error) {
- VOP_LEASE(tdvp, td, td->td_ucred, LEASE_WRITE);
- if (fromnd.ni_dvp != tdvp) {
- VOP_LEASE(fromnd.ni_dvp, td, td->td_ucred, LEASE_WRITE);
- }
- if (tvp) {
- VOP_LEASE(tvp, td, td->td_ucred, LEASE_WRITE);
- }
- error = VOP_RENAME(fromnd.ni_dvp, fromnd.ni_vp, &fromnd.ni_cnd,
- tond.ni_dvp, tond.ni_vp, &tond.ni_cnd);
- NDFREE(&fromnd, NDF_ONLY_PNBUF);
- NDFREE(&tond, NDF_ONLY_PNBUF);
- } else {
- NDFREE(&fromnd, NDF_ONLY_PNBUF);
- NDFREE(&tond, NDF_ONLY_PNBUF);
- if (tdvp == tvp)
- vrele(tdvp);
- else
- vput(tdvp);
- if (tvp)
- vput(tvp);
- vrele(fromnd.ni_dvp);
- vrele(fvp);
- }
- vrele(tond.ni_startdir);
- ASSERT_VOP_UNLOCKED(fromnd.ni_dvp, "rename");
- ASSERT_VOP_UNLOCKED(fromnd.ni_vp, "rename");
- ASSERT_VOP_UNLOCKED(tond.ni_dvp, "rename");
- ASSERT_VOP_UNLOCKED(tond.ni_vp, "rename");
-out1:
- vn_finished_write(mp);
- if (fromnd.ni_startdir)
- vrele(fromnd.ni_startdir);
- if (error == -1)
- return (0);
- return (error);
-}
-
-/*
- * Make a directory file.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct mkdir_args {
- char *path;
- int mode;
-};
-#endif
-/* ARGSUSED */
-int
-mkdir(td, uap)
- struct thread *td;
- register struct mkdir_args /* {
- char *path;
- int mode;
- } */ *uap;
-{
-
- return (kern_mkdir(td, uap->path, UIO_USERSPACE, uap->mode));
-}
-
-int
-kern_mkdir(struct thread *td, char *path, enum uio_seg segflg, int mode)
-{
- struct mount *mp;
- struct vnode *vp;
- struct vattr vattr;
- int error;
- struct nameidata nd;
-
-restart:
- bwillwrite();
- NDINIT(&nd, CREATE, LOCKPARENT | SAVENAME, segflg, path, td);
- nd.ni_cnd.cn_flags |= WILLBEDIR;
- if ((error = namei(&nd)) != 0)
- return (error);
- vp = nd.ni_vp;
- if (vp != NULL) {
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vrele(vp);
- /*
- * XXX namei called with LOCKPARENT but not LOCKLEAF has
- * the strange behaviour of leaving the vnode unlocked
- * if the target is the same vnode as the parent.
- */
- if (vp == nd.ni_dvp)
- vrele(nd.ni_dvp);
- else
- vput(nd.ni_dvp);
- return (EEXIST);
- }
- if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(nd.ni_dvp);
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
- return (error);
- goto restart;
- }
- VATTR_NULL(&vattr);
- vattr.va_type = VDIR;
- FILEDESC_LOCK(td->td_proc->p_fd);
- vattr.va_mode = (mode & ACCESSPERMS) &~ td->td_proc->p_fd->fd_cmask;
- FILEDESC_UNLOCK(td->td_proc->p_fd);
-#ifdef MAC
- error = mac_check_vnode_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd,
- &vattr);
- if (error)
- goto out;
-#endif
- VOP_LEASE(nd.ni_dvp, td, td->td_ucred, LEASE_WRITE);
- error = VOP_MKDIR(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
-#ifdef MAC
-out:
-#endif
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vput(nd.ni_dvp);
- if (!error)
- vput(nd.ni_vp);
- vn_finished_write(mp);
- ASSERT_VOP_UNLOCKED(nd.ni_dvp, "mkdir");
- ASSERT_VOP_UNLOCKED(nd.ni_vp, "mkdir");
- return (error);
-}
-
-/*
- * Remove a directory file.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct rmdir_args {
- char *path;
-};
-#endif
-/* ARGSUSED */
-int
-rmdir(td, uap)
- struct thread *td;
- struct rmdir_args /* {
- char *path;
- } */ *uap;
-{
-
- return (kern_rmdir(td, uap->path, UIO_USERSPACE));
-}
-
-int
-kern_rmdir(struct thread *td, char *path, enum uio_seg pathseg)
-{
- struct mount *mp;
- struct vnode *vp;
- int error;
- struct nameidata nd;
-
-restart:
- bwillwrite();
- NDINIT(&nd, DELETE, LOCKPARENT | LOCKLEAF, pathseg, path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- vp = nd.ni_vp;
- if (vp->v_type != VDIR) {
- error = ENOTDIR;
- goto out;
- }
- /*
- * No rmdir "." please.
- */
- if (nd.ni_dvp == vp) {
- error = EINVAL;
- goto out;
- }
- /*
- * The root of a mounted filesystem cannot be deleted.
- */
- if (vp->v_vflag & VV_ROOT) {
- error = EBUSY;
- goto out;
- }
-#ifdef MAC
- error = mac_check_vnode_delete(td->td_ucred, nd.ni_dvp, vp,
- &nd.ni_cnd);
- if (error)
- goto out;
-#endif
- if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
- NDFREE(&nd, NDF_ONLY_PNBUF);
- if (nd.ni_dvp == vp)
- vrele(nd.ni_dvp);
- else
- vput(nd.ni_dvp);
- vput(vp);
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
- return (error);
- goto restart;
- }
- VOP_LEASE(nd.ni_dvp, td, td->td_ucred, LEASE_WRITE);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- error = VOP_RMDIR(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd);
- vn_finished_write(mp);
-out:
- NDFREE(&nd, NDF_ONLY_PNBUF);
- if (nd.ni_dvp == vp)
- vrele(nd.ni_dvp);
- else
- vput(nd.ni_dvp);
- vput(vp);
- ASSERT_VOP_UNLOCKED(nd.ni_dvp, "rmdir");
- ASSERT_VOP_UNLOCKED(nd.ni_vp, "rmdir");
- return (error);
-}
-
-#ifdef COMPAT_43
-/*
- * Read a block of directory entries in a filesystem independent format.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct ogetdirentries_args {
- int fd;
- char *buf;
- u_int count;
- long *basep;
-};
-#endif
-int
-ogetdirentries(td, uap)
- struct thread *td;
- register struct ogetdirentries_args /* {
- int fd;
- char *buf;
- u_int count;
- long *basep;
- } */ *uap;
-{
- struct vnode *vp;
- struct file *fp;
- struct uio auio, kuio;
- struct iovec aiov, kiov;
- struct dirent *dp, *edp;
- caddr_t dirbuf;
- int error, eofflag, readcnt;
- long loff;
-
- /* XXX arbitrary sanity limit on `count'. */
- if (uap->count > 64 * 1024)
- return (EINVAL);
- if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
- return (error);
- if ((fp->f_flag & FREAD) == 0) {
- fdrop(fp, td);
- return (EBADF);
- }
- vp = fp->f_data;
-unionread:
- if (vp->v_type != VDIR) {
- fdrop(fp, td);
- return (EINVAL);
- }
- aiov.iov_base = uap->buf;
- aiov.iov_len = uap->count;
- auio.uio_iov = &aiov;
- auio.uio_iovcnt = 1;
- auio.uio_rw = UIO_READ;
- auio.uio_segflg = UIO_USERSPACE;
- auio.uio_td = td;
- auio.uio_resid = uap->count;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- loff = auio.uio_offset = fp->f_offset;
-#ifdef MAC
- error = mac_check_vnode_readdir(td->td_ucred, vp);
- if (error) {
- VOP_UNLOCK(vp, 0, td);
- fdrop(fp, td);
- return (error);
- }
-#endif
-# if (BYTE_ORDER != LITTLE_ENDIAN)
- if (vp->v_mount->mnt_maxsymlinklen <= 0) {
- error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
- NULL, NULL);
- fp->f_offset = auio.uio_offset;
- } else
-# endif
- {
- kuio = auio;
- kuio.uio_iov = &kiov;
- kuio.uio_segflg = UIO_SYSSPACE;
- kiov.iov_len = uap->count;
- MALLOC(dirbuf, caddr_t, uap->count, M_TEMP, M_WAITOK);
- kiov.iov_base = dirbuf;
- error = VOP_READDIR(vp, &kuio, fp->f_cred, &eofflag,
- NULL, NULL);
- fp->f_offset = kuio.uio_offset;
- if (error == 0) {
- readcnt = uap->count - kuio.uio_resid;
- edp = (struct dirent *)&dirbuf[readcnt];
- for (dp = (struct dirent *)dirbuf; dp < edp; ) {
-# if (BYTE_ORDER == LITTLE_ENDIAN)
- /*
- * The expected low byte of
- * dp->d_namlen is our dp->d_type.
- * The high MBZ byte of dp->d_namlen
- * is our dp->d_namlen.
- */
- dp->d_type = dp->d_namlen;
- dp->d_namlen = 0;
-# else
- /*
- * The dp->d_type is the high byte
- * of the expected dp->d_namlen,
- * so must be zero'ed.
- */
- dp->d_type = 0;
-# endif
- if (dp->d_reclen > 0) {
- dp = (struct dirent *)
- ((char *)dp + dp->d_reclen);
- } else {
- error = EIO;
- break;
- }
- }
- if (dp >= edp)
- error = uiomove(dirbuf, readcnt, &auio);
- }
- FREE(dirbuf, M_TEMP);
- }
- VOP_UNLOCK(vp, 0, td);
- if (error) {
- fdrop(fp, td);
- return (error);
- }
- if (uap->count == auio.uio_resid) {
- if (union_dircheckp) {
- error = union_dircheckp(td, &vp, fp);
- if (error == -1)
- goto unionread;
- if (error) {
- fdrop(fp, td);
- return (error);
- }
- }
- /*
- * XXX We could delay dropping the lock above but
- * union_dircheckp complicates things.
- */
- vn_lock(vp, LK_EXCLUSIVE|LK_RETRY, td);
- if ((vp->v_vflag & VV_ROOT) &&
- (vp->v_mount->mnt_flag & MNT_UNION)) {
- struct vnode *tvp = vp;
- vp = vp->v_mount->mnt_vnodecovered;
- VREF(vp);
- fp->f_data = vp;
- fp->f_offset = 0;
- vput(tvp);
- goto unionread;
- }
- VOP_UNLOCK(vp, 0, td);
- }
- error = copyout(&loff, uap->basep, sizeof(long));
- fdrop(fp, td);
- td->td_retval[0] = uap->count - auio.uio_resid;
- return (error);
-}
-#endif /* COMPAT_43 */
-
-/*
- * Read a block of directory entries in a filesystem independent format.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct getdirentries_args {
- int fd;
- char *buf;
- u_int count;
- long *basep;
-};
-#endif
-int
-getdirentries(td, uap)
- struct thread *td;
- register struct getdirentries_args /* {
- int fd;
- char *buf;
- u_int count;
- long *basep;
- } */ *uap;
-{
- struct vnode *vp;
- struct file *fp;
- struct uio auio;
- struct iovec aiov;
- long loff;
- int error, eofflag;
-
- if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
- return (error);
- if ((fp->f_flag & FREAD) == 0) {
- fdrop(fp, td);
- return (EBADF);
- }
- vp = fp->f_data;
-unionread:
- if (vp->v_type != VDIR) {
- fdrop(fp, td);
- return (EINVAL);
- }
- aiov.iov_base = uap->buf;
- aiov.iov_len = uap->count;
- auio.uio_iov = &aiov;
- auio.uio_iovcnt = 1;
- auio.uio_rw = UIO_READ;
- auio.uio_segflg = UIO_USERSPACE;
- auio.uio_td = td;
- auio.uio_resid = uap->count;
- /* vn_lock(vp, LK_SHARED | LK_RETRY, td); */
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- loff = auio.uio_offset = fp->f_offset;
-#ifdef MAC
- error = mac_check_vnode_readdir(td->td_ucred, vp);
- if (error == 0)
-#endif
- error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, NULL,
- NULL);
- fp->f_offset = auio.uio_offset;
- VOP_UNLOCK(vp, 0, td);
- if (error) {
- fdrop(fp, td);
- return (error);
- }
- if (uap->count == auio.uio_resid) {
- if (union_dircheckp) {
- error = union_dircheckp(td, &vp, fp);
- if (error == -1)
- goto unionread;
- if (error) {
- fdrop(fp, td);
- return (error);
- }
- }
- /*
- * XXX We could delay dropping the lock above but
- * union_dircheckp complicates things.
- */
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- if ((vp->v_vflag & VV_ROOT) &&
- (vp->v_mount->mnt_flag & MNT_UNION)) {
- struct vnode *tvp = vp;
- vp = vp->v_mount->mnt_vnodecovered;
- VREF(vp);
- fp->f_data = vp;
- fp->f_offset = 0;
- vput(tvp);
- goto unionread;
- }
- VOP_UNLOCK(vp, 0, td);
- }
- if (uap->basep != NULL) {
- error = copyout(&loff, uap->basep, sizeof(long));
- }
- td->td_retval[0] = uap->count - auio.uio_resid;
- fdrop(fp, td);
- return (error);
-}
-#ifndef _SYS_SYSPROTO_H_
-struct getdents_args {
- int fd;
- char *buf;
- size_t count;
-};
-#endif
-int
-getdents(td, uap)
- struct thread *td;
- register struct getdents_args /* {
- int fd;
- char *buf;
- u_int count;
- } */ *uap;
-{
- struct getdirentries_args ap;
- ap.fd = uap->fd;
- ap.buf = uap->buf;
- ap.count = uap->count;
- ap.basep = NULL;
- return getdirentries(td, &ap);
-}
-
-/*
- * Set the mode mask for creation of filesystem nodes.
- *
- * MP SAFE
- */
-#ifndef _SYS_SYSPROTO_H_
-struct umask_args {
- int newmask;
-};
-#endif
-int
-umask(td, uap)
- struct thread *td;
- struct umask_args /* {
- int newmask;
- } */ *uap;
-{
- register struct filedesc *fdp;
-
- FILEDESC_LOCK(td->td_proc->p_fd);
- fdp = td->td_proc->p_fd;
- td->td_retval[0] = fdp->fd_cmask;
- fdp->fd_cmask = uap->newmask & ALLPERMS;
- FILEDESC_UNLOCK(td->td_proc->p_fd);
- return (0);
-}
-
-/*
- * Void all references to file by ripping underlying filesystem
- * away from vnode.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct revoke_args {
- char *path;
-};
-#endif
-/* ARGSUSED */
-int
-revoke(td, uap)
- struct thread *td;
- register struct revoke_args /* {
- char *path;
- } */ *uap;
-{
- struct mount *mp;
- struct vnode *vp;
- struct vattr vattr;
- int error;
- struct nameidata nd;
-
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, uap->path, td);
- if ((error = namei(&nd)) != 0)
- return (error);
- vp = nd.ni_vp;
- NDFREE(&nd, NDF_ONLY_PNBUF);
- if (vp->v_type != VCHR) {
- vput(vp);
- return (EINVAL);
- }
-#ifdef MAC
- error = mac_check_vnode_revoke(td->td_ucred, vp);
- if (error) {
- vput(vp);
- return (error);
- }
-#endif
- error = VOP_GETATTR(vp, &vattr, td->td_ucred, td);
- if (error) {
- vput(vp);
- return (error);
- }
- VOP_UNLOCK(vp, 0, td);
- if (td->td_ucred->cr_uid != vattr.va_uid) {
- error = suser_cred(td->td_ucred, PRISON_ROOT);
- if (error)
- goto out;
- }
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
- goto out;
- if (vcount(vp) > 1)
- VOP_REVOKE(vp, REVOKEALL);
- vn_finished_write(mp);
-out:
- vrele(vp);
- return (error);
-}
-
-/*
- * Convert a user file descriptor to a kernel file entry.
- * The file entry is locked upon returning.
- */
-int
-getvnode(fdp, fd, fpp)
- struct filedesc *fdp;
- int fd;
- struct file **fpp;
-{
- int error;
- struct file *fp;
-
- fp = NULL;
- if (fdp == NULL)
- error = EBADF;
- else {
- FILEDESC_LOCK(fdp);
- if ((u_int)fd >= fdp->fd_nfiles ||
- (fp = fdp->fd_ofiles[fd]) == NULL)
- error = EBADF;
- else if (fp->f_type != DTYPE_VNODE && fp->f_type != DTYPE_FIFO) {
- fp = NULL;
- error = EINVAL;
- } else {
- fhold(fp);
- error = 0;
- }
- FILEDESC_UNLOCK(fdp);
- }
- *fpp = fp;
- return (error);
-}
-/*
- * Get (NFS) file handle
- */
-#ifndef _SYS_SYSPROTO_H_
-struct getfh_args {
- char *fname;
- fhandle_t *fhp;
-};
-#endif
-int
-getfh(td, uap)
- struct thread *td;
- register struct getfh_args *uap;
-{
- struct nameidata nd;
- fhandle_t fh;
- register struct vnode *vp;
- int error;
-
- /*
- * Must be super user
- */
- error = suser(td);
- if (error)
- return (error);
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, uap->fname, td);
- error = namei(&nd);
- if (error)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vp = nd.ni_vp;
- bzero(&fh, sizeof(fh));
- fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid;
- error = VFS_VPTOFH(vp, &fh.fh_fid);
- vput(vp);
- if (error)
- return (error);
- error = copyout(&fh, uap->fhp, sizeof (fh));
- return (error);
-}
-
-/*
- * syscall for the rpc.lockd to use to translate a NFS file handle into
- * an open descriptor.
- *
- * warning: do not remove the suser() call or this becomes one giant
- * security hole.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct fhopen_args {
- const struct fhandle *u_fhp;
- int flags;
-};
-#endif
-int
-fhopen(td, uap)
- struct thread *td;
- struct fhopen_args /* {
- const struct fhandle *u_fhp;
- int flags;
- } */ *uap;
-{
- struct proc *p = td->td_proc;
- struct mount *mp;
- struct vnode *vp;
- struct fhandle fhp;
- struct vattr vat;
- struct vattr *vap = &vat;
- struct flock lf;
- struct file *fp;
- register struct filedesc *fdp = p->p_fd;
- int fmode, mode, error, type;
- struct file *nfp;
- int indx;
-
- /*
- * Must be super user
- */
- error = suser(td);
- if (error)
- return (error);
-
- fmode = FFLAGS(uap->flags);
- /* why not allow a non-read/write open for our lockd? */
- if (((fmode & (FREAD | FWRITE)) == 0) || (fmode & O_CREAT))
- return (EINVAL);
- error = copyin(uap->u_fhp, &fhp, sizeof(fhp));
- if (error)
- return(error);
- /* find the mount point */
- mp = vfs_getvfs(&fhp.fh_fsid);
- if (mp == NULL)
- return (ESTALE);
- /* now give me my vnode, it gets returned to me locked */
- error = VFS_FHTOVP(mp, &fhp.fh_fid, &vp);
- if (error)
- return (error);
- /*
- * from now on we have to make sure not
- * to forget about the vnode
- * any error that causes an abort must vput(vp)
- * just set error = err and 'goto bad;'.
- */
-
- /*
- * from vn_open
- */
- if (vp->v_type == VLNK) {
- error = EMLINK;
- goto bad;
- }
- if (vp->v_type == VSOCK) {
- error = EOPNOTSUPP;
- goto bad;
- }
- mode = 0;
- if (fmode & (FWRITE | O_TRUNC)) {
- if (vp->v_type == VDIR) {
- error = EISDIR;
- goto bad;
- }
- error = vn_writechk(vp);
- if (error)
- goto bad;
- mode |= VWRITE;
- }
- if (fmode & FREAD)
- mode |= VREAD;
- if (fmode & O_APPEND)
- mode |= VAPPEND;
-#ifdef MAC
- error = mac_check_vnode_open(td->td_ucred, vp, mode);
- if (error)
- goto bad;
-#endif
- if (mode) {
- error = VOP_ACCESS(vp, mode, td->td_ucred, td);
- if (error)
- goto bad;
- }
- if (fmode & O_TRUNC) {
- VOP_UNLOCK(vp, 0, td); /* XXX */
- if ((error = vn_start_write(NULL, &mp, V_WAIT | PCATCH)) != 0) {
- vrele(vp);
- return (error);
- }
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); /* XXX */
-#ifdef MAC
- /*
- * We don't yet have fp->f_cred, so use td->td_ucred, which
- * should be right.
- */
- error = mac_check_vnode_write(td->td_ucred, td->td_ucred, vp);
- if (error == 0) {
-#endif
- VATTR_NULL(vap);
- vap->va_size = 0;
- error = VOP_SETATTR(vp, vap, td->td_ucred, td);
-#ifdef MAC
- }
-#endif
- vn_finished_write(mp);
- if (error)
- goto bad;
- }
- error = VOP_OPEN(vp, fmode, td->td_ucred, td);
- if (error)
- goto bad;
- /*
- * Make sure that a VM object is created for VMIO support.
- */
- if (vn_canvmio(vp) == TRUE) {
- if ((error = vfs_object_create(vp, td, td->td_ucred)) != 0)
- goto bad;
- }
- if (fmode & FWRITE)
- vp->v_writecount++;
-
- /*
- * end of vn_open code
- */
-
- if ((error = falloc(td, &nfp, &indx)) != 0) {
- if (fmode & FWRITE)
- vp->v_writecount--;
- goto bad;
- }
- fp = nfp;
-
- /*
- * Hold an extra reference to avoid having fp ripped out
- * from under us while we block in the lock op
- */
- fhold(fp);
- nfp->f_data = vp;
- nfp->f_flag = fmode & FMASK;
- nfp->f_ops = &vnops;
- nfp->f_type = DTYPE_VNODE;
- if (fmode & (O_EXLOCK | O_SHLOCK)) {
- lf.l_whence = SEEK_SET;
- lf.l_start = 0;
- lf.l_len = 0;
- if (fmode & O_EXLOCK)
- lf.l_type = F_WRLCK;
- else
- lf.l_type = F_RDLCK;
- type = F_FLOCK;
- if ((fmode & FNONBLOCK) == 0)
- type |= F_WAIT;
- VOP_UNLOCK(vp, 0, td);
- if ((error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf,
- type)) != 0) {
- /*
- * The lock request failed. Normally close the
- * descriptor but handle the case where someone might
- * have dup()d or close()d it when we weren't looking.
- */
- FILEDESC_LOCK(fdp);
- if (fdp->fd_ofiles[indx] == fp) {
- fdp->fd_ofiles[indx] = NULL;
- FILEDESC_UNLOCK(fdp);
- fdrop(fp, td);
- } else
- FILEDESC_UNLOCK(fdp);
- /*
- * release our private reference
- */
- fdrop(fp, td);
- return(error);
- }
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- fp->f_flag |= FHASLOCK;
- }
- if ((vp->v_type == VREG) && (VOP_GETVOBJECT(vp, NULL) != 0))
- vfs_object_create(vp, td, td->td_ucred);
-
- VOP_UNLOCK(vp, 0, td);
- fdrop(fp, td);
- td->td_retval[0] = indx;
- return (0);
-
-bad:
- vput(vp);
- return (error);
-}
-
-/*
- * Stat an (NFS) file handle.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct fhstat_args {
- struct fhandle *u_fhp;
- struct stat *sb;
-};
-#endif
-int
-fhstat(td, uap)
- struct thread *td;
- register struct fhstat_args /* {
- struct fhandle *u_fhp;
- struct stat *sb;
- } */ *uap;
-{
- struct stat sb;
- fhandle_t fh;
- struct mount *mp;
- struct vnode *vp;
- int error;
-
- /*
- * Must be super user
- */
- error = suser(td);
- if (error)
- return (error);
-
- error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
- if (error)
- return (error);
-
- if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
- return (ESTALE);
- if ((error = VFS_FHTOVP(mp, &fh.fh_fid, &vp)))
- return (error);
- error = vn_stat(vp, &sb, td->td_ucred, NOCRED, td);
- vput(vp);
- if (error)
- return (error);
- error = copyout(&sb, uap->sb, sizeof(sb));
- return (error);
-}
-
-/*
- * Implement fstatfs() for (NFS) file handles.
- */
-#ifndef _SYS_SYSPROTO_H_
-struct fhstatfs_args {
- struct fhandle *u_fhp;
- struct statfs *buf;
-};
-#endif
-int
-fhstatfs(td, uap)
- struct thread *td;
- struct fhstatfs_args /* {
- struct fhandle *u_fhp;
- struct statfs *buf;
- } */ *uap;
-{
- struct statfs *sp;
- struct mount *mp;
- struct vnode *vp;
- struct statfs sb;
- fhandle_t fh;
- int error;
-
- /*
- * Must be super user
- */
- error = suser(td);
- if (error)
- return (error);
-
- if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
- return (error);
-
- if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
- return (ESTALE);
- if ((error = VFS_FHTOVP(mp, &fh.fh_fid, &vp)))
- return (error);
- mp = vp->v_mount;
- sp = &mp->mnt_stat;
- vput(vp);
-#ifdef MAC
- error = mac_check_mount_stat(td->td_ucred, mp);
- if (error)
- return (error);
-#endif
- if ((error = VFS_STATFS(mp, sp, td)) != 0)
- return (error);
- sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
- if (suser(td)) {
- bcopy(sp, &sb, sizeof(sb));
- sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
- sp = &sb;
- }
- return (copyout(sp, uap->buf, sizeof(*sp)));
-}
-
-/*
- * Syscall to push extended attribute configuration information into the
- * VFS. Accepts a path, which it converts to a mountpoint, as well as
- * a command (int cmd), and attribute name and misc data. For now, the
- * attribute name is left in userspace for consumption by the VFS_op.
- * It will probably be changed to be copied into sysspace by the
- * syscall in the future, once issues with various consumers of the
- * attribute code have raised their hands.
- *
- * Currently this is used only by UFS Extended Attributes.
- */
-int
-extattrctl(td, uap)
- struct thread *td;
- struct extattrctl_args /* {
- const char *path;
- int cmd;
- const char *filename;
- int attrnamespace;
- const char *attrname;
- } */ *uap;
-{
- struct vnode *filename_vp;
- struct nameidata nd;
- struct mount *mp, *mp_writable;
- char attrname[EXTATTR_MAXNAMELEN];
- int error;
-
- /*
- * uap->attrname is not always defined. We check again later when we
- * invoke the VFS call so as to pass in NULL there if needed.
- */
- if (uap->attrname != NULL) {
- error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN,
- NULL);
- if (error)
- return (error);
- }
-
- /*
- * uap->filename is not always defined. If it is, grab a vnode lock,
- * which VFS_EXTATTRCTL() will later release.
- */
- filename_vp = NULL;
- if (uap->filename != NULL) {
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
- uap->filename, td);
- error = namei(&nd);
- if (error)
- return (error);
- filename_vp = nd.ni_vp;
- NDFREE(&nd, NDF_NO_VP_RELE | NDF_NO_VP_UNLOCK);
- }
-
- /* uap->path is always defined. */
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error) {
- if (filename_vp != NULL)
- vput(filename_vp);
- return (error);
- }
- mp = nd.ni_vp->v_mount;
- error = vn_start_write(nd.ni_vp, &mp_writable, V_WAIT | PCATCH);
- NDFREE(&nd, 0);
- if (error) {
- if (filename_vp != NULL)
- vput(filename_vp);
- return (error);
- }
-
- error = VFS_EXTATTRCTL(mp, uap->cmd, filename_vp, uap->attrnamespace,
- uap->attrname != NULL ? attrname : NULL, td);
-
- vn_finished_write(mp_writable);
- /*
- * VFS_EXTATTRCTL will have unlocked, but not de-ref'd,
- * filename_vp, so vrele it if it is defined.
- */
- if (filename_vp != NULL)
- vrele(filename_vp);
- return (error);
-}
-
-/*-
- * Set a named extended attribute on a file or directory
- *
- * Arguments: unlocked vnode "vp", attribute namespace "attrnamespace",
- * kernelspace string pointer "attrname", userspace buffer
- * pointer "data", buffer length "nbytes", thread "td".
- * Returns: 0 on success, an error number otherwise
- * Locks: none
- * References: vp must be a valid reference for the duration of the call
- */
-static int
-extattr_set_vp(struct vnode *vp, int attrnamespace, const char *attrname,
- void *data, size_t nbytes, struct thread *td)
-{
- struct mount *mp;
- struct uio auio;
- struct iovec aiov;
- ssize_t cnt;
- int error;
-
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error)
- return (error);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
-
- aiov.iov_base = data;
- aiov.iov_len = nbytes;
- auio.uio_iov = &aiov;
- auio.uio_iovcnt = 1;
- auio.uio_offset = 0;
- if (nbytes > INT_MAX) {
- error = EINVAL;
- goto done;
- }
- auio.uio_resid = nbytes;
- auio.uio_rw = UIO_WRITE;
- auio.uio_segflg = UIO_USERSPACE;
- auio.uio_td = td;
- cnt = nbytes;
-
-#ifdef MAC
- error = mac_check_vnode_setextattr(td->td_ucred, vp, attrnamespace,
- attrname, &auio);
- if (error)
- goto done;
-#endif
-
- error = VOP_SETEXTATTR(vp, attrnamespace, attrname, &auio,
- td->td_ucred, td);
- cnt -= auio.uio_resid;
- td->td_retval[0] = cnt;
-
-done:
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- return (error);
-}
-
-int
-extattr_set_fd(td, uap)
- struct thread *td;
- struct extattr_set_fd_args /* {
- int fd;
- int attrnamespace;
- const char *attrname;
- void *data;
- size_t nbytes;
- } */ *uap;
-{
- struct file *fp;
- char attrname[EXTATTR_MAXNAMELEN];
- int error;
-
- error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
- if (error)
- return (error);
-
- error = getvnode(td->td_proc->p_fd, uap->fd, &fp);
- if (error)
- return (error);
-
- error = extattr_set_vp(fp->f_data, uap->attrnamespace,
- attrname, uap->data, uap->nbytes, td);
- fdrop(fp, td);
-
- return (error);
-}
-
-int
-extattr_set_file(td, uap)
- struct thread *td;
- struct extattr_set_file_args /* {
- const char *path;
- int attrnamespace;
- const char *attrname;
- void *data;
- size_t nbytes;
- } */ *uap;
-{
- struct nameidata nd;
- char attrname[EXTATTR_MAXNAMELEN];
- int error;
-
- error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
- if (error)
- return (error);
-
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
-
- error = extattr_set_vp(nd.ni_vp, uap->attrnamespace, attrname,
- uap->data, uap->nbytes, td);
-
- vrele(nd.ni_vp);
- return (error);
-}
-
-int
-extattr_set_link(td, uap)
- struct thread *td;
- struct extattr_set_link_args /* {
- const char *path;
- int attrnamespace;
- const char *attrname;
- void *data;
- size_t nbytes;
- } */ *uap;
-{
- struct nameidata nd;
- char attrname[EXTATTR_MAXNAMELEN];
- int error;
-
- error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
- if (error)
- return (error);
-
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
-
- error = extattr_set_vp(nd.ni_vp, uap->attrnamespace, attrname,
- uap->data, uap->nbytes, td);
-
- vrele(nd.ni_vp);
- return (error);
-}
-
-/*-
- * Get a named extended attribute on a file or directory
- *
- * Arguments: unlocked vnode "vp", attribute namespace "attrnamespace",
- * kernelspace string pointer "attrname", userspace buffer
- * pointer "data", buffer length "nbytes", thread "td".
- * Returns: 0 on success, an error number otherwise
- * Locks: none
- * References: vp must be a valid reference for the duration of the call
- */
-static int
-extattr_get_vp(struct vnode *vp, int attrnamespace, const char *attrname,
- void *data, size_t nbytes, struct thread *td)
-{
- struct uio auio, *auiop;
- struct iovec aiov;
- ssize_t cnt;
- size_t size, *sizep;
- int error;
-
- VOP_LEASE(vp, td, td->td_ucred, LEASE_READ);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
-
- /*
- * Slightly unusual semantics: if the user provides a NULL data
- * pointer, they don't want to receive the data, just the
- * maximum read length.
- */
- auiop = NULL;
- sizep = NULL;
- cnt = 0;
- if (data != NULL) {
- aiov.iov_base = data;
- aiov.iov_len = nbytes;
- auio.uio_iov = &aiov;
- auio.uio_offset = 0;
- if (nbytes > INT_MAX) {
- error = EINVAL;
- goto done;
- }
- auio.uio_resid = nbytes;
- auio.uio_rw = UIO_READ;
- auio.uio_segflg = UIO_USERSPACE;
- auio.uio_td = td;
- auiop = &auio;
- cnt = nbytes;
- } else
- sizep = &size;
-
-#ifdef MAC
- error = mac_check_vnode_getextattr(td->td_ucred, vp, attrnamespace,
- attrname, &auio);
- if (error)
- goto done;
-#endif
-
- error = VOP_GETEXTATTR(vp, attrnamespace, attrname, auiop, sizep,
- td->td_ucred, td);
-
- if (auiop != NULL) {
- cnt -= auio.uio_resid;
- td->td_retval[0] = cnt;
- } else
- td->td_retval[0] = size;
-
-done:
- VOP_UNLOCK(vp, 0, td);
- return (error);
-}
-
-int
-extattr_get_fd(td, uap)
- struct thread *td;
- struct extattr_get_fd_args /* {
- int fd;
- int attrnamespace;
- const char *attrname;
- void *data;
- size_t nbytes;
- } */ *uap;
-{
- struct file *fp;
- char attrname[EXTATTR_MAXNAMELEN];
- int error;
-
- error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
- if (error)
- return (error);
-
- error = getvnode(td->td_proc->p_fd, uap->fd, &fp);
- if (error)
- return (error);
-
- error = extattr_get_vp(fp->f_data, uap->attrnamespace,
- attrname, uap->data, uap->nbytes, td);
-
- fdrop(fp, td);
- return (error);
-}
-
-int
-extattr_get_file(td, uap)
- struct thread *td;
- struct extattr_get_file_args /* {
- const char *path;
- int attrnamespace;
- const char *attrname;
- void *data;
- size_t nbytes;
- } */ *uap;
-{
- struct nameidata nd;
- char attrname[EXTATTR_MAXNAMELEN];
- int error;
-
- error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
- if (error)
- return (error);
-
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
-
- error = extattr_get_vp(nd.ni_vp, uap->attrnamespace, attrname,
- uap->data, uap->nbytes, td);
-
- vrele(nd.ni_vp);
- return (error);
-}
-
-int
-extattr_get_link(td, uap)
- struct thread *td;
- struct extattr_get_link_args /* {
- const char *path;
- int attrnamespace;
- const char *attrname;
- void *data;
- size_t nbytes;
- } */ *uap;
-{
- struct nameidata nd;
- char attrname[EXTATTR_MAXNAMELEN];
- int error;
-
- error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
- if (error)
- return (error);
-
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error)
- return (error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
-
- error = extattr_get_vp(nd.ni_vp, uap->attrnamespace, attrname,
- uap->data, uap->nbytes, td);
-
- vrele(nd.ni_vp);
- return (error);
-}
-
-/*
- * extattr_delete_vp(): Delete a named extended attribute on a file or
- * directory
- *
- * Arguments: unlocked vnode "vp", attribute namespace "attrnamespace",
- * kernelspace string pointer "attrname", proc "p"
- * Returns: 0 on success, an error number otherwise
- * Locks: none
- * References: vp must be a valid reference for the duration of the call
- */
-static int
-extattr_delete_vp(struct vnode *vp, int attrnamespace, const char *attrname,
- struct thread *td)
-{
- struct mount *mp;
- int error;
-
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error)
- return (error);
- VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
-
-#ifdef MAC
- error = mac_check_vnode_setextattr(td->td_ucred, vp, attrnamespace,
- attrname, NULL);
- if (error)
- goto done;
-#endif
-
- error = VOP_SETEXTATTR(vp, attrnamespace, attrname, NULL, td->td_ucred,
- td);
-#ifdef MAC
-done:
-#endif
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
- return (error);
-}
-
-int
-extattr_delete_fd(td, uap)
- struct thread *td;
- struct extattr_delete_fd_args /* {
- int fd;
- int attrnamespace;
- const char *attrname;
- } */ *uap;
-{
- struct file *fp;
- struct vnode *vp;
- char attrname[EXTATTR_MAXNAMELEN];
- int error;
-
- error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
- if (error)
- return (error);
-
- error = getvnode(td->td_proc->p_fd, uap->fd, &fp);
- if (error)
- return (error);
- vp = fp->f_data;
-
- error = extattr_delete_vp(vp, uap->attrnamespace, attrname, td);
- fdrop(fp, td);
- return (error);
-}
-
-int
-extattr_delete_file(td, uap)
- struct thread *td;
- struct extattr_delete_file_args /* {
- const char *path;
- int attrnamespace;
- const char *attrname;
- } */ *uap;
-{
- struct nameidata nd;
- char attrname[EXTATTR_MAXNAMELEN];
- int error;
-
- error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
- if (error)
- return(error);
-
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error)
- return(error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
-
- error = extattr_delete_vp(nd.ni_vp, uap->attrnamespace, attrname, td);
- vrele(nd.ni_vp);
- return(error);
-}
-
-int
-extattr_delete_link(td, uap)
- struct thread *td;
- struct extattr_delete_link_args /* {
- const char *path;
- int attrnamespace;
- const char *attrname;
- } */ *uap;
-{
- struct nameidata nd;
- char attrname[EXTATTR_MAXNAMELEN];
- int error;
-
- error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
- if (error)
- return(error);
-
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
- error = namei(&nd);
- if (error)
- return(error);
- NDFREE(&nd, NDF_ONLY_PNBUF);
-
- error = extattr_delete_vp(nd.ni_vp, uap->attrnamespace, attrname, td);
- vrele(nd.ni_vp);
- return(error);
-}
diff --git a/sys/modules/mac_stub/Makefile b/sys/modules/mac_stub/Makefile
deleted file mode 100644
index b180f718794f..000000000000
--- a/sys/modules/mac_stub/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-# $FreeBSD$
-
-.PATH: ${.CURDIR}/../../security/mac_none
-
-KMOD= mac_none
-SRCS= vnode_if.h \
- mac_none.c
-
-.include <bsd.kmod.mk>
diff --git a/sys/modules/sound/sound/Makefile b/sys/modules/sound/sound/Makefile
deleted file mode 100644
index f540aebed7bb..000000000000
--- a/sys/modules/sound/sound/Makefile
+++ /dev/null
@@ -1,17 +0,0 @@
-# $FreeBSD$
-
-.PATH: ${.CURDIR}/../../../dev/sound/pcm
-.PATH: ${.CURDIR}/../../../dev/sound/isa
-
-KMOD= snd_pcm
-SRCS= device_if.h bus_if.h isa_if.h pci_if.h
-SRCS+= ac97_if.h channel_if.h feeder_if.h mixer_if.h
-SRCS+= ac97_if.c channel_if.c feeder_if.c mixer_if.c
-SRCS+= ac97.c ac97_patch.c buffer.c channel.c dsp.c
-SRCS+= fake.c feeder.c feeder_fmt.c feeder_rate.c
-SRCS+= mixer.c sndstat.c sound.c vchan.c
-SRCS+= sndbuf_dma.c
-
-EXPORT_SYMS= YES # XXX evaluate
-
-.include <bsd.kmod.mk>
diff --git a/sys/netatalk/ddp_pcb.c b/sys/netatalk/ddp_pcb.c
deleted file mode 100644
index 7e8eed80101f..000000000000
--- a/sys/netatalk/ddp_pcb.c
+++ /dev/null
@@ -1,594 +0,0 @@
-/*
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- *
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/protosw.h>
-#include <net/if.h>
-#include <net/route.h>
-#include <net/netisr.h>
-
-#include <netatalk/at.h>
-#include <netatalk/at_var.h>
-#include <netatalk/ddp_var.h>
-#include <netatalk/at_extern.h>
-
-static void at_pcbdisconnect( struct ddpcb *ddp );
-static void at_sockaddr(struct ddpcb *ddp, struct sockaddr **addr);
-static int at_pcbsetaddr(struct ddpcb *ddp, struct sockaddr *addr,
- struct thread *td);
-static int at_pcbconnect(struct ddpcb *ddp, struct sockaddr *addr,
- struct thread *td);
-static void at_pcbdetach(struct socket *so, struct ddpcb *ddp);
-static int at_pcballoc(struct socket *so);
-
-struct ddpcb *ddp_ports[ ATPORT_LAST ];
-struct ddpcb *ddpcb = NULL;
-static u_long ddp_sendspace = DDP_MAXSZ; /* Max ddp size + 1 (ddp_type) */
-static u_long ddp_recvspace = 10 * ( 587 + sizeof( struct sockaddr_at ));
-
-static struct ifqueue atintrq1, atintrq2, aarpintrq;
-
-static int
-ddp_attach(struct socket *so, int proto, struct thread *td)
-{
- struct ddpcb *ddp;
- int error = 0;
- int s;
-
-
- ddp = sotoddpcb( so );
- if ( ddp != NULL ) {
- return( EINVAL);
- }
-
- s = splnet();
- error = at_pcballoc( so );
- splx(s);
- if (error) {
- return (error);
- }
- return (soreserve( so, ddp_sendspace, ddp_recvspace ));
-}
-
-static int
-ddp_detach(struct socket *so)
-{
- struct ddpcb *ddp;
- int s;
-
- ddp = sotoddpcb( so );
- if ( ddp == NULL ) {
- return( EINVAL);
- }
- s = splnet();
- at_pcbdetach( so, ddp );
- splx(s);
- return(0);
-}
-
-static int
-ddp_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
-{
- struct ddpcb *ddp;
- int error = 0;
- int s;
-
- ddp = sotoddpcb( so );
- if ( ddp == NULL ) {
- return( EINVAL);
- }
- s = splnet();
- error = at_pcbsetaddr(ddp, nam, td);
- splx(s);
- return (error);
-}
-
-static int
-ddp_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
-{
- struct ddpcb *ddp;
- int error = 0;
- int s;
-
- ddp = sotoddpcb( so );
- if ( ddp == NULL ) {
- return( EINVAL);
- }
-
- if ( ddp->ddp_fsat.sat_port != ATADDR_ANYPORT ) {
- return(EISCONN);
- }
-
- s = splnet();
- error = at_pcbconnect( ddp, nam, td );
- splx(s);
- if ( error == 0 )
- soisconnected( so );
- return(error);
-}
-
-static int
-ddp_disconnect(struct socket *so)
-{
-
- struct ddpcb *ddp;
- int s;
-
- ddp = sotoddpcb( so );
- if ( ddp == NULL ) {
- return( EINVAL);
- }
- if ( ddp->ddp_fsat.sat_addr.s_node == ATADDR_ANYNODE ) {
- return(ENOTCONN);
- }
-
- s = splnet();
- at_pcbdisconnect( ddp );
- ddp->ddp_fsat.sat_addr.s_node = ATADDR_ANYNODE;
- splx(s);
- soisdisconnected( so );
- return(0);
-}
-
-static int
-ddp_shutdown(struct socket *so)
-{
- struct ddpcb *ddp;
-
- ddp = sotoddpcb( so );
- if ( ddp == NULL ) {
- return( EINVAL);
- }
- socantsendmore( so );
- return(0);
-}
-
-static int
-ddp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
- struct mbuf *control, struct thread *td)
-{
- struct ddpcb *ddp;
- int error = 0;
- int s;
-
- ddp = sotoddpcb( so );
- if ( ddp == NULL ) {
- return(EINVAL);
- }
-
- if ( control && control->m_len ) {
- return(EINVAL);
- }
-
- if ( addr ) {
- if ( ddp->ddp_fsat.sat_port != ATADDR_ANYPORT ) {
- return(EISCONN);
- }
-
- s = splnet();
- error = at_pcbconnect(ddp, addr, td);
- splx( s );
- if ( error ) {
- return(error);
- }
- } else {
- if ( ddp->ddp_fsat.sat_port == ATADDR_ANYPORT ) {
- return(ENOTCONN);
- }
- }
-
- s = splnet();
- error = ddp_output( m, so );
- if ( addr ) {
- at_pcbdisconnect( ddp );
- }
- splx(s);
- return(error);
-}
-
-static int
-ddp_abort(struct socket *so)
-{
- struct ddpcb *ddp;
- int s;
-
- ddp = sotoddpcb( so );
- if ( ddp == NULL ) {
- return(EINVAL);
- }
- soisdisconnected( so );
- s = splnet();
- at_pcbdetach( so, ddp );
- splx(s);
- return(0);
-}
-
-
-static void
-at_sockaddr(struct ddpcb *ddp, struct sockaddr **addr)
-{
- *addr = dup_sockaddr((struct sockaddr *)&ddp->ddp_lsat, 0);
-}
-
-static int
-at_pcbsetaddr(struct ddpcb *ddp, struct sockaddr *addr, struct thread *td)
-{
- struct sockaddr_at lsat, *sat;
- struct at_ifaddr *aa;
- struct ddpcb *ddpp;
-
- if ( ddp->ddp_lsat.sat_port != ATADDR_ANYPORT ) { /* shouldn't be bound */
- return( EINVAL );
- }
-
- if (addr != 0) { /* validate passed address */
- sat = (struct sockaddr_at *)addr;
- if (sat->sat_family != AF_APPLETALK) {
- return(EAFNOSUPPORT);
- }
-
- if ( sat->sat_addr.s_node != ATADDR_ANYNODE ||
- sat->sat_addr.s_net != ATADDR_ANYNET ) {
- for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
- if (( sat->sat_addr.s_net == AA_SAT( aa )->sat_addr.s_net ) &&
- ( sat->sat_addr.s_node == AA_SAT( aa )->sat_addr.s_node )) {
- break;
- }
- }
- if ( !aa ) {
- return( EADDRNOTAVAIL );
- }
- }
-
- if ( sat->sat_port != ATADDR_ANYPORT ) {
- if ( sat->sat_port < ATPORT_FIRST ||
- sat->sat_port >= ATPORT_LAST ) {
- return( EINVAL );
- }
- if ( sat->sat_port < ATPORT_RESERVED &&
- suser(td) ) {
- return( EACCES );
- }
- }
- } else {
- bzero( (caddr_t)&lsat, sizeof( struct sockaddr_at ));
- lsat.sat_len = sizeof(struct sockaddr_at);
- lsat.sat_addr.s_node = ATADDR_ANYNODE;
- lsat.sat_addr.s_net = ATADDR_ANYNET;
- lsat.sat_family = AF_APPLETALK;
- sat = &lsat;
- }
-
- if ( sat->sat_addr.s_node == ATADDR_ANYNODE &&
- sat->sat_addr.s_net == ATADDR_ANYNET ) {
- if ( at_ifaddr == NULL ) {
- return( EADDRNOTAVAIL );
- }
- sat->sat_addr = AA_SAT( at_ifaddr )->sat_addr;
- }
- ddp->ddp_lsat = *sat;
-
- /*
- * Choose port.
- */
- if ( sat->sat_port == ATADDR_ANYPORT ) {
- for ( sat->sat_port = ATPORT_RESERVED;
- sat->sat_port < ATPORT_LAST; sat->sat_port++ ) {
- if ( ddp_ports[ sat->sat_port - 1 ] == 0 ) {
- break;
- }
- }
- if ( sat->sat_port == ATPORT_LAST ) {
- return( EADDRNOTAVAIL );
- }
- ddp->ddp_lsat.sat_port = sat->sat_port;
- ddp_ports[ sat->sat_port - 1 ] = ddp;
- } else {
- for ( ddpp = ddp_ports[ sat->sat_port - 1 ]; ddpp;
- ddpp = ddpp->ddp_pnext ) {
- if ( ddpp->ddp_lsat.sat_addr.s_net == sat->sat_addr.s_net &&
- ddpp->ddp_lsat.sat_addr.s_node == sat->sat_addr.s_node ) {
- break;
- }
- }
- if ( ddpp != NULL ) {
- return( EADDRINUSE );
- }
- ddp->ddp_pnext = ddp_ports[ sat->sat_port - 1 ];
- ddp_ports[ sat->sat_port - 1 ] = ddp;
- if ( ddp->ddp_pnext ) {
- ddp->ddp_pnext->ddp_pprev = ddp;
- }
- }
-
- return( 0 );
-}
-
-static int
-at_pcbconnect(struct ddpcb *ddp, struct sockaddr *addr, struct thread *td)
-{
- struct sockaddr_at *sat = (struct sockaddr_at *)addr;
- struct route *ro;
- struct at_ifaddr *aa = 0;
- struct ifnet *ifp;
- u_short hintnet = 0, net;
-
- if (sat->sat_family != AF_APPLETALK) {
- return(EAFNOSUPPORT);
- }
-
- /*
- * Under phase 2, network 0 means "the network". We take "the
- * network" to mean the network the control block is bound to.
- * If the control block is not bound, there is an error.
- */
- if ( sat->sat_addr.s_net == ATADDR_ANYNET
- && sat->sat_addr.s_node != ATADDR_ANYNODE ) {
- if ( ddp->ddp_lsat.sat_port == ATADDR_ANYPORT ) {
- return( EADDRNOTAVAIL );
- }
- hintnet = ddp->ddp_lsat.sat_addr.s_net;
- }
-
- ro = &ddp->ddp_route;
- /*
- * If we've got an old route for this pcb, check that it is valid.
- * If we've changed our address, we may have an old "good looking"
- * route here. Attempt to detect it.
- */
- if ( ro->ro_rt ) {
- if ( hintnet ) {
- net = hintnet;
- } else {
- net = sat->sat_addr.s_net;
- }
- aa = 0;
- if ((ifp = ro->ro_rt->rt_ifp) != NULL) {
- for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
- if ( aa->aa_ifp == ifp &&
- ntohs( net ) >= ntohs( aa->aa_firstnet ) &&
- ntohs( net ) <= ntohs( aa->aa_lastnet )) {
- break;
- }
- }
- }
- if ( aa == NULL || ( satosat( &ro->ro_dst )->sat_addr.s_net !=
- ( hintnet ? hintnet : sat->sat_addr.s_net ) ||
- satosat( &ro->ro_dst )->sat_addr.s_node !=
- sat->sat_addr.s_node )) {
- RTFREE( ro->ro_rt );
- ro->ro_rt = (struct rtentry *)0;
- }
- }
-
- /*
- * If we've got no route for this interface, try to find one.
- */
- if ( ro->ro_rt == (struct rtentry *)0 ||
- ro->ro_rt->rt_ifp == (struct ifnet *)0 ) {
- ro->ro_dst.sa_len = sizeof( struct sockaddr_at );
- ro->ro_dst.sa_family = AF_APPLETALK;
- if ( hintnet ) {
- satosat( &ro->ro_dst )->sat_addr.s_net = hintnet;
- } else {
- satosat( &ro->ro_dst )->sat_addr.s_net = sat->sat_addr.s_net;
- }
- satosat( &ro->ro_dst )->sat_addr.s_node = sat->sat_addr.s_node;
- rtalloc( ro );
- }
-
- /*
- * Make sure any route that we have has a valid interface.
- */
- aa = 0;
- if ( ro->ro_rt && ( ifp = ro->ro_rt->rt_ifp )) {
- for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
- if ( aa->aa_ifp == ifp ) {
- break;
- }
- }
- }
- if ( aa == 0 ) {
- return( ENETUNREACH );
- }
-
- ddp->ddp_fsat = *sat;
- if ( ddp->ddp_lsat.sat_port == ATADDR_ANYPORT ) {
- return(at_pcbsetaddr(ddp, (struct sockaddr *)0, td));
- }
- return( 0 );
-}
-
-static void
-at_pcbdisconnect( struct ddpcb *ddp )
-{
- ddp->ddp_fsat.sat_addr.s_net = ATADDR_ANYNET;
- ddp->ddp_fsat.sat_addr.s_node = ATADDR_ANYNODE;
- ddp->ddp_fsat.sat_port = ATADDR_ANYPORT;
-}
-
-static int
-at_pcballoc( struct socket *so )
-{
- struct ddpcb *ddp;
-
- MALLOC(ddp, struct ddpcb *, sizeof *ddp, M_PCB, M_WAITOK | M_ZERO);
- ddp->ddp_lsat.sat_port = ATADDR_ANYPORT;
-
- ddp->ddp_next = ddpcb;
- ddp->ddp_prev = NULL;
- ddp->ddp_pprev = NULL;
- ddp->ddp_pnext = NULL;
- if (ddpcb) {
- ddpcb->ddp_prev = ddp;
- }
- ddpcb = ddp;
-
- ddp->ddp_socket = so;
- so->so_pcb = (caddr_t)ddp;
- return(0);
-}
-
-static void
-at_pcbdetach( struct socket *so, struct ddpcb *ddp)
-{
- soisdisconnected( so );
- so->so_pcb = 0;
- sotryfree(so);
-
- /* remove ddp from ddp_ports list */
- if ( ddp->ddp_lsat.sat_port != ATADDR_ANYPORT &&
- ddp_ports[ ddp->ddp_lsat.sat_port - 1 ] != NULL ) {
- if ( ddp->ddp_pprev != NULL ) {
- ddp->ddp_pprev->ddp_pnext = ddp->ddp_pnext;
- } else {
- ddp_ports[ ddp->ddp_lsat.sat_port - 1 ] = ddp->ddp_pnext;
- }
- if ( ddp->ddp_pnext != NULL ) {
- ddp->ddp_pnext->ddp_pprev = ddp->ddp_pprev;
- }
- }
-
- if ( ddp->ddp_route.ro_rt ) {
- rtfree( ddp->ddp_route.ro_rt );
- }
-
- if ( ddp->ddp_prev ) {
- ddp->ddp_prev->ddp_next = ddp->ddp_next;
- } else {
- ddpcb = ddp->ddp_next;
- }
- if ( ddp->ddp_next ) {
- ddp->ddp_next->ddp_prev = ddp->ddp_prev;
- }
- FREE(ddp, M_PCB);
-}
-
-/*
- * For the moment, this just find the pcb with the correct local address.
- * In the future, this will actually do some real searching, so we can use
- * the sender's address to do de-multiplexing on a single port to many
- * sockets (pcbs).
- */
-struct ddpcb *
-ddp_search( struct sockaddr_at *from, struct sockaddr_at *to,
- struct at_ifaddr *aa)
-{
- struct ddpcb *ddp;
-
- /*
- * Check for bad ports.
- */
- if ( to->sat_port < ATPORT_FIRST || to->sat_port >= ATPORT_LAST ) {
- return( NULL );
- }
-
- /*
- * Make sure the local address matches the sent address. What about
- * the interface?
- */
- for ( ddp = ddp_ports[ to->sat_port - 1 ]; ddp; ddp = ddp->ddp_pnext ) {
- /* XXX should we handle 0.YY? */
-
- /* XXXX.YY to socket on destination interface */
- if ( to->sat_addr.s_net == ddp->ddp_lsat.sat_addr.s_net &&
- to->sat_addr.s_node == ddp->ddp_lsat.sat_addr.s_node ) {
- break;
- }
-
- /* 0.255 to socket on receiving interface */
- if ( to->sat_addr.s_node == ATADDR_BCAST && ( to->sat_addr.s_net == 0 ||
- to->sat_addr.s_net == ddp->ddp_lsat.sat_addr.s_net ) &&
- ddp->ddp_lsat.sat_addr.s_net == AA_SAT( aa )->sat_addr.s_net ) {
- break;
- }
-
- /* XXXX.0 to socket on destination interface */
- if ( to->sat_addr.s_net == aa->aa_firstnet &&
- to->sat_addr.s_node == 0 &&
- ntohs( ddp->ddp_lsat.sat_addr.s_net ) >=
- ntohs( aa->aa_firstnet ) &&
- ntohs( ddp->ddp_lsat.sat_addr.s_net ) <=
- ntohs( aa->aa_lastnet )) {
- break;
- }
- }
- return( ddp );
-}
-static int
-at_setpeeraddr(struct socket *so, struct sockaddr **nam)
-{
- return(EOPNOTSUPP);
-}
-
-static int
-at_setsockaddr(struct socket *so, struct sockaddr **nam)
-{
- struct ddpcb *ddp;
-
- ddp = sotoddpcb( so );
- if ( ddp == NULL ) {
- return( EINVAL);
- }
- at_sockaddr( ddp, nam );
- return(0);
-}
-
-void
-ddp_init(void)
-{
-
- atintrq1.ifq_maxlen = IFQ_MAXLEN;
- atintrq2.ifq_maxlen = IFQ_MAXLEN;
- aarpintrq.ifq_maxlen = IFQ_MAXLEN;
- mtx_init(&atintrq1.ifq_mtx, "at1_inq", NULL, MTX_DEF);
- mtx_init(&atintrq2.ifq_mtx, "at2_inq", NULL, MTX_DEF);
- mtx_init(&aarpintrq.ifq_mtx, "aarp_inq", NULL, MTX_DEF);
- netisr_register(NETISR_ATALK1, at1intr, &atintrq1);
- netisr_register(NETISR_ATALK2, at2intr, &atintrq2);
- netisr_register(NETISR_AARP, aarpintr, &aarpintrq);
-}
-
-#if 0
-static void
-ddp_clean(void )
-{
- struct ddpcb *ddp;
-
- for ( ddp = ddpcb; ddp; ddp = ddp->ddp_next ) {
- at_pcbdetach( ddp->ddp_socket, ddp );
- }
-}
-#endif
-
-struct pr_usrreqs ddp_usrreqs = {
- ddp_abort,
- pru_accept_notsupp,
- ddp_attach,
- ddp_bind,
- ddp_connect,
- pru_connect2_notsupp,
- at_control,
- ddp_detach,
- ddp_disconnect,
- pru_listen_notsupp,
- at_setpeeraddr,
- pru_rcvd_notsupp,
- pru_rcvoob_notsupp,
- ddp_send,
- pru_sense_null,
- ddp_shutdown,
- at_setsockaddr,
- sosend,
- soreceive,
- sopoll
-};
diff --git a/sys/netinet/libalias/HISTORY b/sys/netinet/libalias/HISTORY
deleted file mode 100644
index c5bca59cac1f..000000000000
--- a/sys/netinet/libalias/HISTORY
+++ /dev/null
@@ -1,145 +0,0 @@
-$FreeBSD$
-
-Version 1.0: August 11, 1996 (cjm)
-
-Version 1.1: August 20, 1996 (cjm)
- - Host accepts incoming connections for ports 0 to 1023.
-
-Version 1.2: September 7, 1996 (cjm)
- - Fragment handling error in alias_db.c corrected.
-
-Version 1.3: September 15, 1996 (cjm)
- - Generalized mechanism for handling incoming
- connections (no more 0 to 1023 restriction).
-
- - Increased ICMP support (will handle traceroute now).
-
- - Improved TCP close connection logic.
-
-Version 1.4: September 16, 1996 (cjm)
-
-Version 1.5: September 17, 1996 (cjm)
- - Corrected error in handling incoming UDP packets
- with zero checksum.
-
-Version 1.6: September 18, 1996
- - Simplified ICMP data storage. Will now handle
- tracert from Win95 and NT as well as FreeBSD
- traceroute, which uses UDP packets to non-existent
- ports.
-
-Version 1.7: January 9, 1997 (cjm)
- - Reduced malloc() activity for ICMP echo and
- timestamp requests.
-
- - Added handling for out-of-order IP fragments.
-
- - Switched to differential checksum computation
- for IP headers (TCP, UDP and ICMP checksums
- were already differential).
-
- - Accepts FTP data connections from other than
- port 20. This allows one ftp connections
- from two hosts which are both running packet
- aliasing.
-
- - Checksum error on FTP transfers. Problem
- in code located by Martin Renters and
- Brian Somers.
-
-Version 1.8: January 14, 1997 (cjm)
- - Fixed data type error in function StartPoint()
- in alias_db.c (this bug did not exist before v1.7)
- Problem in code located by Ari Suutari.
-
-Version 1.9: February 1, 1997 (Eivind Eklund <perhaps@yes.no>)
- - Added support for IRC DCC (ee)
-
- - Changed the aliasing routines to use ANSI style
- throughout (ee)
-
- - Minor API changes for integration with other
- programs than PPP (ee)
-
- - Fixed minor security hole in alias_ftp.c for
- other applications of the aliasing software.
- Hole could _not_ manifest in ppp+pktAlias, but
- could potentially manifest in other applications
- of the aliasing. (ee)
-
- - Connections initiated from packet aliasing
- host machine will not have their port number
- aliased unless it conflicts with an aliasing
- port already being used. (There is an option
- to disable this for debugging) (cjm)
-
- - Sockets will be allocated in cases where
- there might be port interference with the
- host machine. This can be disabled in cases
- where the ppp host will be acting purely as a
- masquerading router and not generate any
- traffic of its own.
- (cjm)
-
-Version 2.0: March, 1997 (cjm)
- - Aliasing links are cleared only when a host interface address
- changes.
-
- - PacketAliasPermanentLink() API added.
-
- - Option for only aliasing private, unregistered
- IP addresses added.
-
- - Substantial rework to the aliasing lookup engine.
-
-Version 2.1: May, 1997 (cjm)
- - Continuing rework to the aliasing lookup engine
- to support multiple incoming addresses and static
- NAT. PacketAliasRedirectPort() and
- PacketAliasRedirectAddr() added to API.
-
- - Now supports outgoing as well as incoming ICMP
- error messages.
-
-Version 2.2: July, 1997 (cjm)
- - Rationalized API function names to all begin with
- "PacketAlias..." Old function names are retained
- for backwards compatibility.
-
- - Packet aliasing engine will now free memory of
- fragments which are never resolved after a timeout
- period. Once a fragment is resolved, it becomes
- the users responsibility to free the memory.
-
-Version 2.3: August 11, 1997 (cjm)
- - Problem associated with socket file descriptor
- accumulation in alias_db.c corrected. The sockets
- had to be closed when a binding failed. Problem
- in code located by Gordon Burditt.
-
-Version 2.4: September 1, 1997 (cjm)
- - PKT_ALIAS_UNREGISTERED_ONLY option repaired.
- This part of the code was incorrectly re-implemented
- in version 2.1.
-
-Version 2.5: December, 1997 (ee)
- - Added PKT_ALIAS_PUNCH_FW mode for firewall
- bypass of FTP/IRC DCC data connections. Also added
- improved TCP connection monitoring.
-
-Version 2.6: May, 1998 (amurai)
- - Added supporting routine for NetBios over TCP/IP.
-
-Version 3.0: January 1, 1999
- - Transparent proxying support added.
- - PPTP redirecting support added based on patches
- contributed by Dru Nelson <dnelson@redwoodsoft.com>.
-
-Version 3.1: May, 2000 (Erik Salander, erik@whistle.com)
- - Added support to alias 227 replies, allows aliasing for
- FTP servers in passive mode.
- - Added support for PPTP aliasing.
-
-Version 3.2: July, 2000 (Erik Salander, erik@whistle.com and
- Junichi Satoh, junichi@junichi.org)
- - Added support for streaming media (RTSP and PNA) aliasing.
diff --git a/sys/netinet/libalias/Makefile b/sys/netinet/libalias/Makefile
deleted file mode 100644
index cc909c9a9c77..000000000000
--- a/sys/netinet/libalias/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-# $FreeBSD$
-
-LIB= alias
-SHLIB_MAJOR= 4
-MAN= libalias.3
-SRCS= alias.c alias_cuseeme.c alias_db.c alias_ftp.c alias_irc.c \
- alias_nbt.c alias_pptp.c alias_proxy.c alias_smedia.c \
- alias_util.c
-INCS= alias.h
-
-.include <bsd.lib.mk>
diff --git a/sys/netinet/libalias/alias.c b/sys/netinet/libalias/alias.c
deleted file mode 100644
index 467f371cb012..000000000000
--- a/sys/netinet/libalias/alias.c
+++ /dev/null
@@ -1,1582 +0,0 @@
-/* -*- mode: c; tab-width: 8; c-basic-indent: 4; -*- */
-
-/*-
- * Copyright (c) 2001 Charles Mott <cm@linktel.net>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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$");
-
-/*
- Alias.c provides supervisory control for the functions of the
- packet aliasing software. It consists of routines to monitor
- TCP connection state, protocol-specific aliasing routines,
- fragment handling and the following outside world functional
- interfaces: SaveFragmentPtr, GetFragmentPtr, FragmentAliasIn,
- PacketAliasIn and PacketAliasOut.
-
- The other C program files are briefly described. The data
- structure framework which holds information needed to translate
- packets is encapsulated in alias_db.c. Data is accessed by
- function calls, so other segments of the program need not know
- about the underlying data structures. Alias_ftp.c contains
- special code for modifying the ftp PORT command used to establish
- data connections, while alias_irc.c does the same for IRC
- DCC. Alias_util.c contains a few utility routines.
-
- Version 1.0 August, 1996 (cjm)
-
- Version 1.1 August 20, 1996 (cjm)
- PPP host accepts incoming connections for ports 0 to 1023.
- (Gary Roberts pointed out the need to handle incoming
- connections.)
-
- Version 1.2 September 7, 1996 (cjm)
- Fragment handling error in alias_db.c corrected.
- (Tom Torrance helped fix this problem.)
-
- Version 1.4 September 16, 1996 (cjm)
- - A more generalized method for handling incoming
- connections, without the 0-1023 restriction, is
- implemented in alias_db.c
- - Improved ICMP support in alias.c. Traceroute
- packet streams can now be correctly aliased.
- - TCP connection closing logic simplified in
- alias.c and now allows for additional 1 minute
- "grace period" after FIN or RST is observed.
-
- Version 1.5 September 17, 1996 (cjm)
- Corrected error in handling incoming UDP packets with 0 checksum.
- (Tom Torrance helped fix this problem.)
-
- Version 1.6 September 18, 1996 (cjm)
- Simplified ICMP aliasing scheme. Should now support
- traceroute from Win95 as well as FreeBSD.
-
- Version 1.7 January 9, 1997 (cjm)
- - Out-of-order fragment handling.
- - IP checksum error fixed for ftp transfers
- from aliasing host.
- - Integer return codes added to all
- aliasing/de-aliasing functions.
- - Some obsolete comments cleaned up.
- - Differential checksum computations for
- IP header (TCP, UDP and ICMP were already
- differential).
-
- Version 2.1 May 1997 (cjm)
- - Added support for outgoing ICMP error
- messages.
- - Added two functions PacketAliasIn2()
- and PacketAliasOut2() for dynamic address
- control (e.g. round-robin allocation of
- incoming packets).
-
- Version 2.2 July 1997 (cjm)
- - Rationalized API function names to begin
- with "PacketAlias..."
- - Eliminated PacketAliasIn2() and
- PacketAliasOut2() as poorly conceived.
-
- Version 2.3 Dec 1998 (dillon)
- - Major bounds checking additions, see FreeBSD/CVS
-
- Version 3.1 May, 2000 (salander)
- - Added hooks to handle PPTP.
-
- Version 3.2 July, 2000 (salander and satoh)
- - Added PacketUnaliasOut routine.
- - Added hooks to handle RTSP/RTP.
-
- See HISTORY file for additional revisions.
-*/
-
-#include <sys/types.h>
-
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/ip_icmp.h>
-#include <netinet/tcp.h>
-#include <netinet/udp.h>
-
-#include <stdio.h>
-
-#include "alias_local.h"
-#include "alias.h"
-
-#define NETBIOS_NS_PORT_NUMBER 137
-#define NETBIOS_DGM_PORT_NUMBER 138
-#define FTP_CONTROL_PORT_NUMBER 21
-#define IRC_CONTROL_PORT_NUMBER_1 6667
-#define IRC_CONTROL_PORT_NUMBER_2 6668
-#define CUSEEME_PORT_NUMBER 7648
-#define RTSP_CONTROL_PORT_NUMBER_1 554
-#define RTSP_CONTROL_PORT_NUMBER_2 7070
-#define TFTP_PORT_NUMBER 69
-#define PPTP_CONTROL_PORT_NUMBER 1723
-
-
-
-
-/* TCP Handling Routines
-
- TcpMonitorIn() -- These routines monitor TCP connections, and
- TcpMonitorOut() delete a link when a connection is closed.
-
-These routines look for SYN, FIN and RST flags to determine when TCP
-connections open and close. When a TCP connection closes, the data
-structure containing packet aliasing information is deleted after
-a timeout period.
-*/
-
-/* Local prototypes */
-static void TcpMonitorIn(struct ip *, struct alias_link *);
-
-static void TcpMonitorOut(struct ip *, struct alias_link *);
-
-
-static void
-TcpMonitorIn(struct ip *pip, struct alias_link *link)
-{
- struct tcphdr *tc;
-
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
-
- switch (GetStateIn(link))
- {
- case ALIAS_TCP_STATE_NOT_CONNECTED:
- if (tc->th_flags & TH_RST)
- SetStateIn(link, ALIAS_TCP_STATE_DISCONNECTED);
- else if (tc->th_flags & TH_SYN)
- SetStateIn(link, ALIAS_TCP_STATE_CONNECTED);
- break;
- case ALIAS_TCP_STATE_CONNECTED:
- if (tc->th_flags & (TH_FIN | TH_RST))
- SetStateIn(link, ALIAS_TCP_STATE_DISCONNECTED);
- break;
- }
-}
-
-static void
-TcpMonitorOut(struct ip *pip, struct alias_link *link)
-{
- struct tcphdr *tc;
-
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
-
- switch (GetStateOut(link))
- {
- case ALIAS_TCP_STATE_NOT_CONNECTED:
- if (tc->th_flags & TH_RST)
- SetStateOut(link, ALIAS_TCP_STATE_DISCONNECTED);
- else if (tc->th_flags & TH_SYN)
- SetStateOut(link, ALIAS_TCP_STATE_CONNECTED);
- break;
- case ALIAS_TCP_STATE_CONNECTED:
- if (tc->th_flags & (TH_FIN | TH_RST))
- SetStateOut(link, ALIAS_TCP_STATE_DISCONNECTED);
- break;
- }
-}
-
-
-
-
-
-/* Protocol Specific Packet Aliasing Routines
-
- IcmpAliasIn(), IcmpAliasIn1(), IcmpAliasIn2()
- IcmpAliasOut(), IcmpAliasOut1(), IcmpAliasOut2()
- ProtoAliasIn(), ProtoAliasOut()
- UdpAliasIn(), UdpAliasOut()
- TcpAliasIn(), TcpAliasOut()
-
-These routines handle protocol specific details of packet aliasing.
-One may observe a certain amount of repetitive arithmetic in these
-functions, the purpose of which is to compute a revised checksum
-without actually summing over the entire data packet, which could be
-unnecessarily time consuming.
-
-The purpose of the packet aliasing routines is to replace the source
-address of the outgoing packet and then correctly put it back for
-any incoming packets. For TCP and UDP, ports are also re-mapped.
-
-For ICMP echo/timestamp requests and replies, the following scheme
-is used: the ID number is replaced by an alias for the outgoing
-packet.
-
-ICMP error messages are handled by looking at the IP fragment
-in the data section of the message.
-
-For TCP and UDP protocols, a port number is chosen for an outgoing
-packet, and then incoming packets are identified by IP address and
-port numbers. For TCP packets, there is additional logic in the event
-that sequence and ACK numbers have been altered (as in the case for
-FTP data port commands).
-
-The port numbers used by the packet aliasing module are not true
-ports in the Unix sense. No sockets are actually bound to ports.
-They are more correctly thought of as placeholders.
-
-All packets go through the aliasing mechanism, whether they come from
-the gateway machine or other machines on a local area network.
-*/
-
-
-/* Local prototypes */
-static int IcmpAliasIn1(struct ip *);
-static int IcmpAliasIn2(struct ip *);
-static int IcmpAliasIn (struct ip *);
-
-static int IcmpAliasOut1(struct ip *);
-static int IcmpAliasOut2(struct ip *);
-static int IcmpAliasOut (struct ip *);
-
-static int ProtoAliasIn(struct ip *);
-static int ProtoAliasOut(struct ip *);
-
-static int UdpAliasOut(struct ip *);
-static int UdpAliasIn (struct ip *);
-
-static int TcpAliasOut(struct ip *, int);
-static int TcpAliasIn (struct ip *);
-
-
-static int
-IcmpAliasIn1(struct ip *pip)
-{
-/*
- De-alias incoming echo and timestamp replies.
- Alias incoming echo and timestamp requests.
-*/
- struct alias_link *link;
- struct icmp *ic;
-
- ic = (struct icmp *) ((char *) pip + (pip->ip_hl << 2));
-
-/* Get source address from ICMP data field and restore original data */
- link = FindIcmpIn(pip->ip_src, pip->ip_dst, ic->icmp_id, 1);
- if (link != NULL)
- {
- u_short original_id;
- int accumulate;
-
- original_id = GetOriginalPort(link);
-
-/* Adjust ICMP checksum */
- accumulate = ic->icmp_id;
- accumulate -= original_id;
- ADJUST_CHECKSUM(accumulate, ic->icmp_cksum);
-
-/* Put original sequence number back in */
- ic->icmp_id = original_id;
-
-/* Put original address back into IP header */
- {
- struct in_addr original_address;
-
- original_address = GetOriginalAddress(link);
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &original_address,
- (u_short *) &pip->ip_dst,
- 2);
- pip->ip_dst = original_address;
- }
-
- return(PKT_ALIAS_OK);
- }
- return(PKT_ALIAS_IGNORED);
-}
-
-static int
-IcmpAliasIn2(struct ip *pip)
-{
-/*
- Alias incoming ICMP error messages containing
- IP header and first 64 bits of datagram.
-*/
- struct ip *ip;
- struct icmp *ic, *ic2;
- struct udphdr *ud;
- struct tcphdr *tc;
- struct alias_link *link;
-
- ic = (struct icmp *) ((char *) pip + (pip->ip_hl << 2));
- ip = &ic->icmp_ip;
-
- ud = (struct udphdr *) ((char *) ip + (ip->ip_hl <<2));
- tc = (struct tcphdr *) ud;
- ic2 = (struct icmp *) ud;
-
- if (ip->ip_p == IPPROTO_UDP)
- link = FindUdpTcpIn(ip->ip_dst, ip->ip_src,
- ud->uh_dport, ud->uh_sport,
- IPPROTO_UDP, 0);
- else if (ip->ip_p == IPPROTO_TCP)
- link = FindUdpTcpIn(ip->ip_dst, ip->ip_src,
- tc->th_dport, tc->th_sport,
- IPPROTO_TCP, 0);
- else if (ip->ip_p == IPPROTO_ICMP) {
- if (ic2->icmp_type == ICMP_ECHO || ic2->icmp_type == ICMP_TSTAMP)
- link = FindIcmpIn(ip->ip_dst, ip->ip_src, ic2->icmp_id, 0);
- else
- link = NULL;
- } else
- link = NULL;
-
- if (link != NULL)
- {
- if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP)
- {
- u_short *sptr;
- int accumulate, accumulate2;
- struct in_addr original_address;
- u_short original_port;
-
- original_address = GetOriginalAddress(link);
- original_port = GetOriginalPort(link);
-
-/* Adjust ICMP checksum */
- sptr = (u_short *) &(ip->ip_src);
- accumulate = *sptr++;
- accumulate += *sptr;
- sptr = (u_short *) &original_address;
- accumulate -= *sptr++;
- accumulate -= *sptr;
- accumulate += ud->uh_sport;
- accumulate -= original_port;
- accumulate2 = accumulate;
- accumulate2 += ip->ip_sum;
- ADJUST_CHECKSUM(accumulate, ip->ip_sum);
- accumulate2 -= ip->ip_sum;
- ADJUST_CHECKSUM(accumulate2, ic->icmp_cksum);
-
-/* Un-alias address in IP header */
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &original_address,
- (u_short *) &pip->ip_dst,
- 2);
- pip->ip_dst = original_address;
-
-/* Un-alias address and port number of original IP packet
-fragment contained in ICMP data section */
- ip->ip_src = original_address;
- ud->uh_sport = original_port;
- }
- else if (ip->ip_p == IPPROTO_ICMP)
- {
- u_short *sptr;
- int accumulate, accumulate2;
- struct in_addr original_address;
- u_short original_id;
-
- original_address = GetOriginalAddress(link);
- original_id = GetOriginalPort(link);
-
-/* Adjust ICMP checksum */
- sptr = (u_short *) &(ip->ip_src);
- accumulate = *sptr++;
- accumulate += *sptr;
- sptr = (u_short *) &original_address;
- accumulate -= *sptr++;
- accumulate -= *sptr;
- accumulate += ic2->icmp_id;
- accumulate -= original_id;
- accumulate2 = accumulate;
- accumulate2 += ip->ip_sum;
- ADJUST_CHECKSUM(accumulate, ip->ip_sum);
- accumulate2 -= ip->ip_sum;
- ADJUST_CHECKSUM(accumulate2, ic->icmp_cksum);
-
-/* Un-alias address in IP header */
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &original_address,
- (u_short *) &pip->ip_dst,
- 2);
- pip->ip_dst = original_address;
-
-/* Un-alias address of original IP packet and sequence number of
- embedded ICMP datagram */
- ip->ip_src = original_address;
- ic2->icmp_id = original_id;
- }
- return(PKT_ALIAS_OK);
- }
- return(PKT_ALIAS_IGNORED);
-}
-
-
-static int
-IcmpAliasIn(struct ip *pip)
-{
- int iresult;
- struct icmp *ic;
-
-/* Return if proxy-only mode is enabled */
- if (packetAliasMode & PKT_ALIAS_PROXY_ONLY)
- return PKT_ALIAS_OK;
-
- ic = (struct icmp *) ((char *) pip + (pip->ip_hl << 2));
-
- iresult = PKT_ALIAS_IGNORED;
- switch (ic->icmp_type)
- {
- case ICMP_ECHOREPLY:
- case ICMP_TSTAMPREPLY:
- if (ic->icmp_code == 0)
- {
- iresult = IcmpAliasIn1(pip);
- }
- break;
- case ICMP_UNREACH:
- case ICMP_SOURCEQUENCH:
- case ICMP_TIMXCEED:
- case ICMP_PARAMPROB:
- iresult = IcmpAliasIn2(pip);
- break;
- case ICMP_ECHO:
- case ICMP_TSTAMP:
- iresult = IcmpAliasIn1(pip);
- break;
- }
- return(iresult);
-}
-
-
-static int
-IcmpAliasOut1(struct ip *pip)
-{
-/*
- Alias outgoing echo and timestamp requests.
- De-alias outgoing echo and timestamp replies.
-*/
- struct alias_link *link;
- struct icmp *ic;
-
- ic = (struct icmp *) ((char *) pip + (pip->ip_hl << 2));
-
-/* Save overwritten data for when echo packet returns */
- link = FindIcmpOut(pip->ip_src, pip->ip_dst, ic->icmp_id, 1);
- if (link != NULL)
- {
- u_short alias_id;
- int accumulate;
-
- alias_id = GetAliasPort(link);
-
-/* Since data field is being modified, adjust ICMP checksum */
- accumulate = ic->icmp_id;
- accumulate -= alias_id;
- ADJUST_CHECKSUM(accumulate, ic->icmp_cksum);
-
-/* Alias sequence number */
- ic->icmp_id = alias_id;
-
-/* Change source address */
- {
- struct in_addr alias_address;
-
- alias_address = GetAliasAddress(link);
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &alias_address,
- (u_short *) &pip->ip_src,
- 2);
- pip->ip_src = alias_address;
- }
-
- return(PKT_ALIAS_OK);
- }
- return(PKT_ALIAS_IGNORED);
-}
-
-
-static int
-IcmpAliasOut2(struct ip *pip)
-{
-/*
- Alias outgoing ICMP error messages containing
- IP header and first 64 bits of datagram.
-*/
- struct ip *ip;
- struct icmp *ic, *ic2;
- struct udphdr *ud;
- struct tcphdr *tc;
- struct alias_link *link;
-
- ic = (struct icmp *) ((char *) pip + (pip->ip_hl << 2));
- ip = &ic->icmp_ip;
-
- ud = (struct udphdr *) ((char *) ip + (ip->ip_hl <<2));
- tc = (struct tcphdr *) ud;
- ic2 = (struct icmp *) ud;
-
- if (ip->ip_p == IPPROTO_UDP)
- link = FindUdpTcpOut(ip->ip_dst, ip->ip_src,
- ud->uh_dport, ud->uh_sport,
- IPPROTO_UDP, 0);
- else if (ip->ip_p == IPPROTO_TCP)
- link = FindUdpTcpOut(ip->ip_dst, ip->ip_src,
- tc->th_dport, tc->th_sport,
- IPPROTO_TCP, 0);
- else if (ip->ip_p == IPPROTO_ICMP) {
- if (ic2->icmp_type == ICMP_ECHO || ic2->icmp_type == ICMP_TSTAMP)
- link = FindIcmpOut(ip->ip_dst, ip->ip_src, ic2->icmp_id, 0);
- else
- link = NULL;
- } else
- link = NULL;
-
- if (link != NULL)
- {
- if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP)
- {
- u_short *sptr;
- int accumulate;
- struct in_addr alias_address;
- u_short alias_port;
-
- alias_address = GetAliasAddress(link);
- alias_port = GetAliasPort(link);
-
-/* Adjust ICMP checksum */
- sptr = (u_short *) &(ip->ip_dst);
- accumulate = *sptr++;
- accumulate += *sptr;
- sptr = (u_short *) &alias_address;
- accumulate -= *sptr++;
- accumulate -= *sptr;
- accumulate += ud->uh_dport;
- accumulate -= alias_port;
- ADJUST_CHECKSUM(accumulate, ic->icmp_cksum);
-
-/*
- * Alias address in IP header if it comes from the host
- * the original TCP/UDP packet was destined for.
- */
- if (pip->ip_src.s_addr == ip->ip_dst.s_addr) {
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &alias_address,
- (u_short *) &pip->ip_src,
- 2);
- pip->ip_src = alias_address;
- }
-
-/* Alias address and port number of original IP packet
-fragment contained in ICMP data section */
- ip->ip_dst = alias_address;
- ud->uh_dport = alias_port;
- }
- else if (ip->ip_p == IPPROTO_ICMP)
- {
- u_short *sptr;
- int accumulate;
- struct in_addr alias_address;
- u_short alias_id;
-
- alias_address = GetAliasAddress(link);
- alias_id = GetAliasPort(link);
-
-/* Adjust ICMP checksum */
- sptr = (u_short *) &(ip->ip_dst);
- accumulate = *sptr++;
- accumulate += *sptr;
- sptr = (u_short *) &alias_address;
- accumulate -= *sptr++;
- accumulate -= *sptr;
- accumulate += ic2->icmp_id;
- accumulate -= alias_id;
- ADJUST_CHECKSUM(accumulate, ic->icmp_cksum);
-
-/*
- * Alias address in IP header if it comes from the host
- * the original ICMP message was destined for.
- */
- if (pip->ip_src.s_addr == ip->ip_dst.s_addr) {
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &alias_address,
- (u_short *) &pip->ip_src,
- 2);
- pip->ip_src = alias_address;
- }
-
-/* Alias address of original IP packet and sequence number of
- embedded ICMP datagram */
- ip->ip_dst = alias_address;
- ic2->icmp_id = alias_id;
- }
- return(PKT_ALIAS_OK);
- }
- return(PKT_ALIAS_IGNORED);
-}
-
-
-static int
-IcmpAliasOut(struct ip *pip)
-{
- int iresult;
- struct icmp *ic;
-
-/* Return if proxy-only mode is enabled */
- if (packetAliasMode & PKT_ALIAS_PROXY_ONLY)
- return PKT_ALIAS_OK;
-
- ic = (struct icmp *) ((char *) pip + (pip->ip_hl << 2));
-
- iresult = PKT_ALIAS_IGNORED;
- switch (ic->icmp_type)
- {
- case ICMP_ECHO:
- case ICMP_TSTAMP:
- if (ic->icmp_code == 0)
- {
- iresult = IcmpAliasOut1(pip);
- }
- break;
- case ICMP_UNREACH:
- case ICMP_SOURCEQUENCH:
- case ICMP_TIMXCEED:
- case ICMP_PARAMPROB:
- iresult = IcmpAliasOut2(pip);
- break;
- case ICMP_ECHOREPLY:
- case ICMP_TSTAMPREPLY:
- iresult = IcmpAliasOut1(pip);
- }
- return(iresult);
-}
-
-
-
-static int
-ProtoAliasIn(struct ip *pip)
-{
-/*
- Handle incoming IP packets. The
- only thing which is done in this case is to alias
- the dest IP address of the packet to our inside
- machine.
-*/
- struct alias_link *link;
-
-/* Return if proxy-only mode is enabled */
- if (packetAliasMode & PKT_ALIAS_PROXY_ONLY)
- return PKT_ALIAS_OK;
-
- link = FindProtoIn(pip->ip_src, pip->ip_dst, pip->ip_p);
- if (link != NULL)
- {
- struct in_addr original_address;
-
- original_address = GetOriginalAddress(link);
-
-/* Restore original IP address */
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &original_address,
- (u_short *) &pip->ip_dst,
- 2);
- pip->ip_dst = original_address;
-
- return(PKT_ALIAS_OK);
- }
- return(PKT_ALIAS_IGNORED);
-}
-
-
-static int
-ProtoAliasOut(struct ip *pip)
-{
-/*
- Handle outgoing IP packets. The
- only thing which is done in this case is to alias
- the source IP address of the packet.
-*/
- struct alias_link *link;
-
-/* Return if proxy-only mode is enabled */
- if (packetAliasMode & PKT_ALIAS_PROXY_ONLY)
- return PKT_ALIAS_OK;
-
- link = FindProtoOut(pip->ip_src, pip->ip_dst, pip->ip_p);
- if (link != NULL)
- {
- struct in_addr alias_address;
-
- alias_address = GetAliasAddress(link);
-
-/* Change source address */
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &alias_address,
- (u_short *) &pip->ip_src,
- 2);
- pip->ip_src = alias_address;
-
- return(PKT_ALIAS_OK);
- }
- return(PKT_ALIAS_IGNORED);
-}
-
-
-static int
-UdpAliasIn(struct ip *pip)
-{
- struct udphdr *ud;
- struct alias_link *link;
-
-/* Return if proxy-only mode is enabled */
- if (packetAliasMode & PKT_ALIAS_PROXY_ONLY)
- return PKT_ALIAS_OK;
-
- ud = (struct udphdr *) ((char *) pip + (pip->ip_hl << 2));
-
- link = FindUdpTcpIn(pip->ip_src, pip->ip_dst,
- ud->uh_sport, ud->uh_dport,
- IPPROTO_UDP, 1);
- if (link != NULL)
- {
- struct in_addr alias_address;
- struct in_addr original_address;
- u_short alias_port;
- int accumulate;
- u_short *sptr;
- int r = 0;
-
- alias_address = GetAliasAddress(link);
- original_address = GetOriginalAddress(link);
- alias_port = ud->uh_dport;
- ud->uh_dport = GetOriginalPort(link);
-
-/* Special processing for IP encoding protocols */
- if (ntohs(ud->uh_dport) == CUSEEME_PORT_NUMBER)
- AliasHandleCUSeeMeIn(pip, original_address);
-/* If NETBIOS Datagram, It should be alias address in UDP Data, too */
- else if (ntohs(ud->uh_dport) == NETBIOS_DGM_PORT_NUMBER
- || ntohs(ud->uh_sport) == NETBIOS_DGM_PORT_NUMBER)
- r = AliasHandleUdpNbt(pip, link, &original_address, ud->uh_dport);
- else if (ntohs(ud->uh_dport) == NETBIOS_NS_PORT_NUMBER
- || ntohs(ud->uh_sport) == NETBIOS_NS_PORT_NUMBER)
- r = AliasHandleUdpNbtNS(pip, link, &alias_address, &alias_port,
- &original_address, &ud->uh_dport);
-
-/* If UDP checksum is not zero, then adjust since destination port */
-/* is being unaliased and destination address is being altered. */
- if (ud->uh_sum != 0)
- {
- accumulate = alias_port;
- accumulate -= ud->uh_dport;
- sptr = (u_short *) &alias_address;
- accumulate += *sptr++;
- accumulate += *sptr;
- sptr = (u_short *) &original_address;
- accumulate -= *sptr++;
- accumulate -= *sptr;
- ADJUST_CHECKSUM(accumulate, ud->uh_sum);
- }
-
-/* Restore original IP address */
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &original_address,
- (u_short *) &pip->ip_dst,
- 2);
- pip->ip_dst = original_address;
-
- /*
- * If we cannot figure out the packet, ignore it.
- */
- if (r < 0)
- return(PKT_ALIAS_IGNORED);
- else
- return(PKT_ALIAS_OK);
- }
- return(PKT_ALIAS_IGNORED);
-}
-
-static int
-UdpAliasOut(struct ip *pip)
-{
- struct udphdr *ud;
- struct alias_link *link;
-
-/* Return if proxy-only mode is enabled */
- if (packetAliasMode & PKT_ALIAS_PROXY_ONLY)
- return PKT_ALIAS_OK;
-
- ud = (struct udphdr *) ((char *) pip + (pip->ip_hl << 2));
-
- link = FindUdpTcpOut(pip->ip_src, pip->ip_dst,
- ud->uh_sport, ud->uh_dport,
- IPPROTO_UDP, 1);
- if (link != NULL)
- {
- u_short alias_port;
- struct in_addr alias_address;
-
- alias_address = GetAliasAddress(link);
- alias_port = GetAliasPort(link);
-
-/* Special processing for IP encoding protocols */
- if (ntohs(ud->uh_dport) == CUSEEME_PORT_NUMBER)
- AliasHandleCUSeeMeOut(pip, link);
-/* If NETBIOS Datagram, It should be alias address in UDP Data, too */
- else if (ntohs(ud->uh_dport) == NETBIOS_DGM_PORT_NUMBER
- || ntohs(ud->uh_sport) == NETBIOS_DGM_PORT_NUMBER)
- AliasHandleUdpNbt(pip, link, &alias_address, alias_port);
- else if (ntohs(ud->uh_dport) == NETBIOS_NS_PORT_NUMBER
- || ntohs(ud->uh_sport) == NETBIOS_NS_PORT_NUMBER)
- AliasHandleUdpNbtNS(pip, link, &pip->ip_src, &ud->uh_sport,
- &alias_address, &alias_port);
-/*
- * We don't know in advance what TID the TFTP server will choose,
- * so we create a wilcard link (destination port is unspecified)
- * that will match any TID from a given destination.
- */
- else if (ntohs(ud->uh_dport) == TFTP_PORT_NUMBER)
- FindRtspOut(pip->ip_src, pip->ip_dst,
- ud->uh_sport, alias_port, IPPROTO_UDP);
-
-/* If UDP checksum is not zero, adjust since source port is */
-/* being aliased and source address is being altered */
- if (ud->uh_sum != 0)
- {
- int accumulate;
- u_short *sptr;
-
- accumulate = ud->uh_sport;
- accumulate -= alias_port;
- sptr = (u_short *) &(pip->ip_src);
- accumulate += *sptr++;
- accumulate += *sptr;
- sptr = (u_short *) &alias_address;
- accumulate -= *sptr++;
- accumulate -= *sptr;
- ADJUST_CHECKSUM(accumulate, ud->uh_sum);
- }
-
-/* Put alias port in UDP header */
- ud->uh_sport = alias_port;
-
-/* Change source address */
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &alias_address,
- (u_short *) &pip->ip_src,
- 2);
- pip->ip_src = alias_address;
-
- return(PKT_ALIAS_OK);
- }
- return(PKT_ALIAS_IGNORED);
-}
-
-
-
-static int
-TcpAliasIn(struct ip *pip)
-{
- struct tcphdr *tc;
- struct alias_link *link;
-
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
-
- link = FindUdpTcpIn(pip->ip_src, pip->ip_dst,
- tc->th_sport, tc->th_dport,
- IPPROTO_TCP,
- !(packetAliasMode & PKT_ALIAS_PROXY_ONLY));
- if (link != NULL)
- {
- struct in_addr alias_address;
- struct in_addr original_address;
- struct in_addr proxy_address;
- u_short alias_port;
- u_short proxy_port;
- int accumulate;
- u_short *sptr;
-
-/* Special processing for IP encoding protocols */
- if (ntohs(tc->th_dport) == PPTP_CONTROL_PORT_NUMBER
- || ntohs(tc->th_sport) == PPTP_CONTROL_PORT_NUMBER)
- AliasHandlePptpIn(pip, link);
-
- alias_address = GetAliasAddress(link);
- original_address = GetOriginalAddress(link);
- proxy_address = GetProxyAddress(link);
- alias_port = tc->th_dport;
- tc->th_dport = GetOriginalPort(link);
- proxy_port = GetProxyPort(link);
-
-/* Adjust TCP checksum since destination port is being unaliased */
-/* and destination port is being altered. */
- accumulate = alias_port;
- accumulate -= tc->th_dport;
- sptr = (u_short *) &alias_address;
- accumulate += *sptr++;
- accumulate += *sptr;
- sptr = (u_short *) &original_address;
- accumulate -= *sptr++;
- accumulate -= *sptr;
-
-/* If this is a proxy, then modify the TCP source port and
- checksum accumulation */
- if (proxy_port != 0)
- {
- accumulate += tc->th_sport;
- tc->th_sport = proxy_port;
- accumulate -= tc->th_sport;
-
- sptr = (u_short *) &pip->ip_src;
- accumulate += *sptr++;
- accumulate += *sptr;
- sptr = (u_short *) &proxy_address;
- accumulate -= *sptr++;
- accumulate -= *sptr;
- }
-
-/* See if ACK number needs to be modified */
- if (GetAckModified(link) == 1)
- {
- int delta;
-
- delta = GetDeltaAckIn(pip, link);
- if (delta != 0)
- {
- sptr = (u_short *) &tc->th_ack;
- accumulate += *sptr++;
- accumulate += *sptr;
- tc->th_ack = htonl(ntohl(tc->th_ack) - delta);
- sptr = (u_short *) &tc->th_ack;
- accumulate -= *sptr++;
- accumulate -= *sptr;
- }
- }
-
- ADJUST_CHECKSUM(accumulate, tc->th_sum);
-
-/* Restore original IP address */
- sptr = (u_short *) &pip->ip_dst;
- accumulate = *sptr++;
- accumulate += *sptr;
- pip->ip_dst = original_address;
- sptr = (u_short *) &pip->ip_dst;
- accumulate -= *sptr++;
- accumulate -= *sptr;
-
-/* If this is a transparent proxy packet, then modify the source
- address */
- if (proxy_address.s_addr != 0)
- {
- sptr = (u_short *) &pip->ip_src;
- accumulate += *sptr++;
- accumulate += *sptr;
- pip->ip_src = proxy_address;
- sptr = (u_short *) &pip->ip_src;
- accumulate -= *sptr++;
- accumulate -= *sptr;
- }
-
- ADJUST_CHECKSUM(accumulate, pip->ip_sum);
-
-/* Monitor TCP connection state */
- TcpMonitorIn(pip, link);
-
- return(PKT_ALIAS_OK);
- }
- return(PKT_ALIAS_IGNORED);
-}
-
-static int
-TcpAliasOut(struct ip *pip, int maxpacketsize)
-{
- int proxy_type;
- u_short dest_port;
- u_short proxy_server_port;
- struct in_addr dest_address;
- struct in_addr proxy_server_address;
- struct tcphdr *tc;
- struct alias_link *link;
-
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
-
- proxy_type = ProxyCheck(pip, &proxy_server_address, &proxy_server_port);
-
- if (proxy_type == 0 && (packetAliasMode & PKT_ALIAS_PROXY_ONLY))
- return PKT_ALIAS_OK;
-
-/* If this is a transparent proxy, save original destination,
- then alter the destination and adjust checksums */
- dest_port = tc->th_dport;
- dest_address = pip->ip_dst;
- if (proxy_type != 0)
- {
- int accumulate;
- u_short *sptr;
-
- accumulate = tc->th_dport;
- tc->th_dport = proxy_server_port;
- accumulate -= tc->th_dport;
-
- sptr = (u_short *) &(pip->ip_dst);
- accumulate += *sptr++;
- accumulate += *sptr;
- sptr = (u_short *) &proxy_server_address;
- accumulate -= *sptr++;
- accumulate -= *sptr;
-
- ADJUST_CHECKSUM(accumulate, tc->th_sum);
-
- sptr = (u_short *) &(pip->ip_dst);
- accumulate = *sptr++;
- accumulate += *sptr;
- pip->ip_dst = proxy_server_address;
- sptr = (u_short *) &(pip->ip_dst);
- accumulate -= *sptr++;
- accumulate -= *sptr;
-
- ADJUST_CHECKSUM(accumulate, pip->ip_sum);
- }
-
- link = FindUdpTcpOut(pip->ip_src, pip->ip_dst,
- tc->th_sport, tc->th_dport,
- IPPROTO_TCP, 1);
- if (link !=NULL)
- {
- u_short alias_port;
- struct in_addr alias_address;
- int accumulate;
- u_short *sptr;
-
-/* Save original destination address, if this is a proxy packet.
- Also modify packet to include destination encoding. This may
- change the size of IP header. */
- if (proxy_type != 0)
- {
- SetProxyPort(link, dest_port);
- SetProxyAddress(link, dest_address);
- ProxyModify(link, pip, maxpacketsize, proxy_type);
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
- }
-
-/* Get alias address and port */
- alias_port = GetAliasPort(link);
- alias_address = GetAliasAddress(link);
-
-/* Monitor TCP connection state */
- TcpMonitorOut(pip, link);
-
-/* Special processing for IP encoding protocols */
- if (ntohs(tc->th_dport) == FTP_CONTROL_PORT_NUMBER
- || ntohs(tc->th_sport) == FTP_CONTROL_PORT_NUMBER)
- AliasHandleFtpOut(pip, link, maxpacketsize);
- else if (ntohs(tc->th_dport) == IRC_CONTROL_PORT_NUMBER_1
- || ntohs(tc->th_dport) == IRC_CONTROL_PORT_NUMBER_2)
- AliasHandleIrcOut(pip, link, maxpacketsize);
- else if (ntohs(tc->th_dport) == RTSP_CONTROL_PORT_NUMBER_1
- || ntohs(tc->th_sport) == RTSP_CONTROL_PORT_NUMBER_1
- || ntohs(tc->th_dport) == RTSP_CONTROL_PORT_NUMBER_2
- || ntohs(tc->th_sport) == RTSP_CONTROL_PORT_NUMBER_2)
- AliasHandleRtspOut(pip, link, maxpacketsize);
- else if (ntohs(tc->th_dport) == PPTP_CONTROL_PORT_NUMBER
- || ntohs(tc->th_sport) == PPTP_CONTROL_PORT_NUMBER)
- AliasHandlePptpOut(pip, link);
-
-/* Adjust TCP checksum since source port is being aliased */
-/* and source address is being altered */
- accumulate = tc->th_sport;
- tc->th_sport = alias_port;
- accumulate -= tc->th_sport;
-
- sptr = (u_short *) &(pip->ip_src);
- accumulate += *sptr++;
- accumulate += *sptr;
- sptr = (u_short *) &alias_address;
- accumulate -= *sptr++;
- accumulate -= *sptr;
-
-/* Modify sequence number if necessary */
- if (GetAckModified(link) == 1)
- {
- int delta;
-
- delta = GetDeltaSeqOut(pip, link);
- if (delta != 0)
- {
- sptr = (u_short *) &tc->th_seq;
- accumulate += *sptr++;
- accumulate += *sptr;
- tc->th_seq = htonl(ntohl(tc->th_seq) + delta);
- sptr = (u_short *) &tc->th_seq;
- accumulate -= *sptr++;
- accumulate -= *sptr;
- }
- }
-
- ADJUST_CHECKSUM(accumulate, tc->th_sum);
-
-/* Change source address */
- sptr = (u_short *) &(pip->ip_src);
- accumulate = *sptr++;
- accumulate += *sptr;
- pip->ip_src = alias_address;
- sptr = (u_short *) &(pip->ip_src);
- accumulate -= *sptr++;
- accumulate -= *sptr;
-
- ADJUST_CHECKSUM(accumulate, pip->ip_sum);
-
- return(PKT_ALIAS_OK);
- }
- return(PKT_ALIAS_IGNORED);
-}
-
-
-
-
-/* Fragment Handling
-
- FragmentIn()
- FragmentOut()
-
-The packet aliasing module has a limited ability for handling IP
-fragments. If the ICMP, TCP or UDP header is in the first fragment
-received, then the ID number of the IP packet is saved, and other
-fragments are identified according to their ID number and IP address
-they were sent from. Pointers to unresolved fragments can also be
-saved and recalled when a header fragment is seen.
-*/
-
-/* Local prototypes */
-static int FragmentIn(struct ip *);
-static int FragmentOut(struct ip *);
-
-
-static int
-FragmentIn(struct ip *pip)
-{
- struct alias_link *link;
-
- link = FindFragmentIn2(pip->ip_src, pip->ip_dst, pip->ip_id);
- if (link != NULL)
- {
- struct in_addr original_address;
-
- GetFragmentAddr(link, &original_address);
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &original_address,
- (u_short *) &pip->ip_dst,
- 2);
- pip->ip_dst = original_address;
-
- return(PKT_ALIAS_OK);
- }
- return(PKT_ALIAS_UNRESOLVED_FRAGMENT);
-}
-
-
-static int
-FragmentOut(struct ip *pip)
-{
- struct in_addr alias_address;
-
- alias_address = FindAliasAddress(pip->ip_src);
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &alias_address,
- (u_short *) &pip->ip_src,
- 2);
- pip->ip_src = alias_address;
-
- return(PKT_ALIAS_OK);
-}
-
-
-
-
-
-
-/* Outside World Access
-
- PacketAliasSaveFragment()
- PacketAliasGetFragment()
- PacketAliasFragmentIn()
- PacketAliasIn()
- PacketAliasOut()
- PacketUnaliasOut()
-
-(prototypes in alias.h)
-*/
-
-
-int
-PacketAliasSaveFragment(char *ptr)
-{
- int iresult;
- struct alias_link *link;
- struct ip *pip;
-
- pip = (struct ip *) ptr;
- link = AddFragmentPtrLink(pip->ip_src, pip->ip_id);
- iresult = PKT_ALIAS_ERROR;
- if (link != NULL)
- {
- SetFragmentPtr(link, ptr);
- iresult = PKT_ALIAS_OK;
- }
- return(iresult);
-}
-
-
-char *
-PacketAliasGetFragment(char *ptr)
-{
- struct alias_link *link;
- char *fptr;
- struct ip *pip;
-
- pip = (struct ip *) ptr;
- link = FindFragmentPtr(pip->ip_src, pip->ip_id);
- if (link != NULL)
- {
- GetFragmentPtr(link, &fptr);
- SetFragmentPtr(link, NULL);
- SetExpire(link, 0); /* Deletes link */
-
- return(fptr);
- }
- else
- {
- return(NULL);
- }
-}
-
-
-void
-PacketAliasFragmentIn(char *ptr, /* Points to correctly de-aliased
- header fragment */
- char *ptr_fragment /* Points to fragment which must
- be de-aliased */
- )
-{
- struct ip *pip;
- struct ip *fpip;
-
- pip = (struct ip *) ptr;
- fpip = (struct ip *) ptr_fragment;
-
- DifferentialChecksum(&fpip->ip_sum,
- (u_short *) &pip->ip_dst,
- (u_short *) &fpip->ip_dst,
- 2);
- fpip->ip_dst = pip->ip_dst;
-}
-
-
-int
-PacketAliasIn(char *ptr, int maxpacketsize)
-{
- struct in_addr alias_addr;
- struct ip *pip;
- int iresult;
-
- if (packetAliasMode & PKT_ALIAS_REVERSE) {
- packetAliasMode &= ~PKT_ALIAS_REVERSE;
- iresult = PacketAliasOut(ptr, maxpacketsize);
- packetAliasMode |= PKT_ALIAS_REVERSE;
- return iresult;
- }
-
- HouseKeeping();
- ClearCheckNewLink();
- pip = (struct ip *) ptr;
- alias_addr = pip->ip_dst;
-
- /* Defense against mangled packets */
- if (ntohs(pip->ip_len) > maxpacketsize
- || (pip->ip_hl<<2) > maxpacketsize)
- return PKT_ALIAS_IGNORED;
-
- iresult = PKT_ALIAS_IGNORED;
- if ( (ntohs(pip->ip_off) & IP_OFFMASK) == 0 )
- {
- switch (pip->ip_p)
- {
- case IPPROTO_ICMP:
- iresult = IcmpAliasIn(pip);
- break;
- case IPPROTO_UDP:
- iresult = UdpAliasIn(pip);
- break;
- case IPPROTO_TCP:
- iresult = TcpAliasIn(pip);
- break;
- case IPPROTO_GRE:
- if (packetAliasMode & PKT_ALIAS_PROXY_ONLY ||
- AliasHandlePptpGreIn(pip) == 0)
- iresult = PKT_ALIAS_OK;
- else
- iresult = ProtoAliasIn(pip);
- break;
- default:
- iresult = ProtoAliasIn(pip);
- break;
- }
-
- if (ntohs(pip->ip_off) & IP_MF)
- {
- struct alias_link *link;
-
- link = FindFragmentIn1(pip->ip_src, alias_addr, pip->ip_id);
- if (link != NULL)
- {
- iresult = PKT_ALIAS_FOUND_HEADER_FRAGMENT;
- SetFragmentAddr(link, pip->ip_dst);
- }
- else
- {
- iresult = PKT_ALIAS_ERROR;
- }
- }
- }
- else
- {
- iresult = FragmentIn(pip);
- }
-
- return(iresult);
-}
-
-
-
-/* Unregistered address ranges */
-
-/* 10.0.0.0 -> 10.255.255.255 */
-#define UNREG_ADDR_A_LOWER 0x0a000000
-#define UNREG_ADDR_A_UPPER 0x0affffff
-
-/* 172.16.0.0 -> 172.31.255.255 */
-#define UNREG_ADDR_B_LOWER 0xac100000
-#define UNREG_ADDR_B_UPPER 0xac1fffff
-
-/* 192.168.0.0 -> 192.168.255.255 */
-#define UNREG_ADDR_C_LOWER 0xc0a80000
-#define UNREG_ADDR_C_UPPER 0xc0a8ffff
-
-int
-PacketAliasOut(char *ptr, /* valid IP packet */
- int maxpacketsize /* How much the packet data may grow
- (FTP and IRC inline changes) */
- )
-{
- int iresult;
- struct in_addr addr_save;
- struct ip *pip;
-
- if (packetAliasMode & PKT_ALIAS_REVERSE) {
- packetAliasMode &= ~PKT_ALIAS_REVERSE;
- iresult = PacketAliasIn(ptr, maxpacketsize);
- packetAliasMode |= PKT_ALIAS_REVERSE;
- return iresult;
- }
-
- HouseKeeping();
- ClearCheckNewLink();
- pip = (struct ip *) ptr;
-
- /* Defense against mangled packets */
- if (ntohs(pip->ip_len) > maxpacketsize
- || (pip->ip_hl<<2) > maxpacketsize)
- return PKT_ALIAS_IGNORED;
-
- addr_save = GetDefaultAliasAddress();
- if (packetAliasMode & PKT_ALIAS_UNREGISTERED_ONLY)
- {
- u_long addr;
- int iclass;
-
- iclass = 0;
- addr = ntohl(pip->ip_src.s_addr);
- if (addr >= UNREG_ADDR_C_LOWER && addr <= UNREG_ADDR_C_UPPER)
- iclass = 3;
- else if (addr >= UNREG_ADDR_B_LOWER && addr <= UNREG_ADDR_B_UPPER)
- iclass = 2;
- else if (addr >= UNREG_ADDR_A_LOWER && addr <= UNREG_ADDR_A_UPPER)
- iclass = 1;
-
- if (iclass == 0)
- {
- SetDefaultAliasAddress(pip->ip_src);
- }
- }
-
- iresult = PKT_ALIAS_IGNORED;
- if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0)
- {
- switch (pip->ip_p)
- {
- case IPPROTO_ICMP:
- iresult = IcmpAliasOut(pip);
- break;
- case IPPROTO_UDP:
- iresult = UdpAliasOut(pip);
- break;
- case IPPROTO_TCP:
- iresult = TcpAliasOut(pip, maxpacketsize);
- break;
- case IPPROTO_GRE:
- if (AliasHandlePptpGreOut(pip) == 0)
- iresult = PKT_ALIAS_OK;
- else
- iresult = ProtoAliasOut(pip);
- break;
- default:
- iresult = ProtoAliasOut(pip);
- break;
- }
- }
- else
- {
- iresult = FragmentOut(pip);
- }
-
- SetDefaultAliasAddress(addr_save);
- return(iresult);
-}
-
-int
-PacketUnaliasOut(char *ptr, /* valid IP packet */
- int maxpacketsize /* for error checking */
- )
-{
- struct ip *pip;
- struct icmp *ic;
- struct udphdr *ud;
- struct tcphdr *tc;
- struct alias_link *link;
- int iresult = PKT_ALIAS_IGNORED;
-
- pip = (struct ip *) ptr;
-
- /* Defense against mangled packets */
- if (ntohs(pip->ip_len) > maxpacketsize
- || (pip->ip_hl<<2) > maxpacketsize)
- return(iresult);
-
- ud = (struct udphdr *) ((char *) pip + (pip->ip_hl << 2));
- tc = (struct tcphdr *) ud;
- ic = (struct icmp *) ud;
-
- /* Find a link */
- if (pip->ip_p == IPPROTO_UDP)
- link = FindUdpTcpIn(pip->ip_dst, pip->ip_src,
- ud->uh_dport, ud->uh_sport,
- IPPROTO_UDP, 0);
- else if (pip->ip_p == IPPROTO_TCP)
- link = FindUdpTcpIn(pip->ip_dst, pip->ip_src,
- tc->th_dport, tc->th_sport,
- IPPROTO_TCP, 0);
- else if (pip->ip_p == IPPROTO_ICMP)
- link = FindIcmpIn(pip->ip_dst, pip->ip_src, ic->icmp_id, 0);
- else
- link = NULL;
-
- /* Change it from an aliased packet to an unaliased packet */
- if (link != NULL)
- {
- if (pip->ip_p == IPPROTO_UDP || pip->ip_p == IPPROTO_TCP)
- {
- u_short *sptr;
- int accumulate;
- struct in_addr original_address;
- u_short original_port;
-
- original_address = GetOriginalAddress(link);
- original_port = GetOriginalPort(link);
-
- /* Adjust TCP/UDP checksum */
- sptr = (u_short *) &(pip->ip_src);
- accumulate = *sptr++;
- accumulate += *sptr;
- sptr = (u_short *) &original_address;
- accumulate -= *sptr++;
- accumulate -= *sptr;
-
- if (pip->ip_p == IPPROTO_UDP) {
- accumulate += ud->uh_sport;
- accumulate -= original_port;
- ADJUST_CHECKSUM(accumulate, ud->uh_sum);
- } else {
- accumulate += tc->th_sport;
- accumulate -= original_port;
- ADJUST_CHECKSUM(accumulate, tc->th_sum);
- }
-
- /* Adjust IP checksum */
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &original_address,
- (u_short *) &pip->ip_src,
- 2);
-
- /* Un-alias source address and port number */
- pip->ip_src = original_address;
- if (pip->ip_p == IPPROTO_UDP)
- ud->uh_sport = original_port;
- else
- tc->th_sport = original_port;
-
- iresult = PKT_ALIAS_OK;
-
- } else if (pip->ip_p == IPPROTO_ICMP) {
-
- u_short *sptr;
- int accumulate;
- struct in_addr original_address;
- u_short original_id;
-
- original_address = GetOriginalAddress(link);
- original_id = GetOriginalPort(link);
-
- /* Adjust ICMP checksum */
- sptr = (u_short *) &(pip->ip_src);
- accumulate = *sptr++;
- accumulate += *sptr;
- sptr = (u_short *) &original_address;
- accumulate -= *sptr++;
- accumulate -= *sptr;
- accumulate += ic->icmp_id;
- accumulate -= original_id;
- ADJUST_CHECKSUM(accumulate, ic->icmp_cksum);
-
- /* Adjust IP checksum */
- DifferentialChecksum(&pip->ip_sum,
- (u_short *) &original_address,
- (u_short *) &pip->ip_src,
- 2);
-
- /* Un-alias source address and port number */
- pip->ip_src = original_address;
- ic->icmp_id = original_id;
-
- iresult = PKT_ALIAS_OK;
- }
- }
- return(iresult);
-
-}
diff --git a/sys/netinet/libalias/alias.h b/sys/netinet/libalias/alias.h
deleted file mode 100644
index eab40448b0d6..000000000000
--- a/sys/netinet/libalias/alias.h
+++ /dev/null
@@ -1,182 +0,0 @@
-/* lint -save -library Flexelint comment for external headers */
-
-/*-
- * Copyright (c) 2001 Charles Mott <cm@linktel.net>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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$
- */
-
-/*-
- * Alias.h defines the outside world interfaces for the packet aliasing
- * software.
- *
- * This software is placed into the public domain with no restrictions on its
- * distribution.
- */
-
-#ifndef _ALIAS_H_
-#define _ALIAS_H_
-
-/* The external interface to libalias, the packet aliasing engine. */
-
-/* Initialization and control functions. */
-void PacketAliasInit(void);
-void PacketAliasSetAddress(struct in_addr _addr);
-void PacketAliasSetFWBase(unsigned int _base, unsigned int _num);
-unsigned int
- PacketAliasSetMode(unsigned int _flags, unsigned int _mask);
-void PacketAliasUninit(void);
-
-/* Packet Handling functions. */
-int PacketAliasIn(char *_ptr, int _maxpacketsize);
-int PacketAliasOut(char *_ptr, int _maxpacketsize);
-int PacketUnaliasOut(char *_ptr, int _maxpacketsize);
-
-/* Port and address redirection functions. */
-
-/*
- * An anonymous structure, a pointer to which is returned from
- * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or
- * PacketAliasRedirectProto(), passed to PacketAliasAddServer(),
- * and freed by PacketAliasRedirectDelete().
- */
-struct alias_link;
-
-int PacketAliasAddServer(struct alias_link *_link,
- struct in_addr _addr, unsigned short _port);
-struct alias_link *
- PacketAliasRedirectAddr(struct in_addr _src_addr,
- struct in_addr _alias_addr);
-void PacketAliasRedirectDelete(struct alias_link *_link);
-struct alias_link *
- PacketAliasRedirectPort(struct in_addr _src_addr,
- unsigned short _src_port, struct in_addr _dst_addr,
- unsigned short _dst_port, struct in_addr _alias_addr,
- unsigned short _alias_port, unsigned char _proto);
-struct alias_link *
- PacketAliasRedirectProto(struct in_addr _src_addr,
- struct in_addr _dst_addr, struct in_addr _alias_addr,
- unsigned char _proto);
-
-/* Fragment Handling functions. */
-void PacketAliasFragmentIn(char *_ptr, char *_ptr_fragment);
-char *PacketAliasGetFragment(char *_ptr);
-int PacketAliasSaveFragment(char *_ptr);
-
-/* Miscellaneous functions. */
-int PacketAliasCheckNewLink(void);
-unsigned short
- PacketAliasInternetChecksum(unsigned short *_ptr, int _nbytes);
-void PacketAliasSetTarget(struct in_addr _target_addr);
-
-/* Transparent proxying routines. */
-int PacketAliasProxyRule(const char *_cmd);
-
-/* Mode flags, set using PacketAliasSetMode() */
-
-/*
- * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log
- * every time a link is created or deleted. This is useful for debugging.
- */
-#define PKT_ALIAS_LOG 0x01
-
-/*
- * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp,
- * telnet or web servers will be prevented by the aliasing mechanism.
- */
-#define PKT_ALIAS_DENY_INCOMING 0x02
-
-/*
- * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the
- * same port as they originated on. This allows e.g. rsh to work *99% of the
- * time*, but _not_ 100% (it will be slightly flakey instead of not working
- * at all). This mode bit is set by PacketAliasInit(), so it is a default
- * mode of operation.
- */
-#define PKT_ALIAS_SAME_PORTS 0x04
-
-/*
- * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g.
- * destination port and/or address is zero), the packet aliasing engine will
- * attempt to allocate a socket for the aliasing port it chooses. This will
- * avoid interference with the host machine. Fully specified links do not
- * require this. This bit is set after a call to PacketAliasInit(), so it is
- * a default mode of operation.
- */
-#define PKT_ALIAS_USE_SOCKETS 0x08
-
-/*-
- * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with
- * unregistered source addresses will be aliased. Private
- * addresses are those in the following ranges:
- *
- * 10.0.0.0 -> 10.255.255.255
- * 172.16.0.0 -> 172.31.255.255
- * 192.168.0.0 -> 192.168.255.255
- */
-#define PKT_ALIAS_UNREGISTERED_ONLY 0x10
-
-/*
- * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
- * aliasing links will be reset whenever PacketAliasSetAddress() changes the
- * default aliasing address. If the default aliasing address is left
- * unchanged by this function call, then the table of dynamic aliasing links
- * will be left intact. This bit is set after a call to PacketAliasInit().
- */
-#define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20
-
-#ifndef NO_FW_PUNCH
-/*
- * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will
- * create a 'hole' in the firewall to allow the transfers to work. The
- * ipfw rule number that the hole is created with is controlled by
- * PacketAliasSetFWBase(). The hole will be attached to that
- * particular alias_link, so when the link goes away the hole is deleted.
- */
-#define PKT_ALIAS_PUNCH_FW 0x100
-#endif
-
-/*
- * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only
- * transparent proxying is performed.
- */
-#define PKT_ALIAS_PROXY_ONLY 0x40
-
-/*
- * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and
- * PacketAliasOut() are reversed.
- */
-#define PKT_ALIAS_REVERSE 0x80
-
-/* Function return codes. */
-#define PKT_ALIAS_ERROR -1
-#define PKT_ALIAS_OK 1
-#define PKT_ALIAS_IGNORED 2
-#define PKT_ALIAS_UNRESOLVED_FRAGMENT 3
-#define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4
-
-#endif /* !_ALIAS_H_ */
-
-/* lint -restore */
diff --git a/sys/netinet/libalias/alias_cuseeme.c b/sys/netinet/libalias/alias_cuseeme.c
deleted file mode 100644
index 27d1c65dedbd..000000000000
--- a/sys/netinet/libalias/alias_cuseeme.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*-
- * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
- * with the aid of code written by
- * Junichi SATOH <junichi@astec.co.jp> 1996, 1997.
- * 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/types.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/udp.h>
-
-#include "alias_local.h"
-
-/* CU-SeeMe Data Header */
-struct cu_header {
- u_int16_t dest_family;
- u_int16_t dest_port;
- u_int32_t dest_addr;
- int16_t family;
- u_int16_t port;
- u_int32_t addr;
- u_int32_t seq;
- u_int16_t msg;
- u_int16_t data_type;
- u_int16_t packet_len;
-};
-
-/* Open Continue Header */
-struct oc_header {
- u_int16_t client_count; /* Number of client info structs */
- u_int32_t seq_no;
- char user_name[20];
- char reserved[4]; /* flags, version stuff, etc */
-};
-
-/* client info structures */
-struct client_info {
- u_int32_t address; /* Client address */
- char reserved[8]; /* Flags, pruning bitfield, packet counts etc */
-};
-
-void
-AliasHandleCUSeeMeOut(struct ip *pip, struct alias_link *link)
-{
- struct udphdr *ud;
-
- ud = (struct udphdr *)((char *)pip + (pip->ip_hl << 2));
- if (ntohs(ud->uh_ulen) - sizeof(struct udphdr) >= sizeof(struct cu_header)) {
- struct cu_header *cu;
- struct alias_link *cu_link;
-
- cu = (struct cu_header *)(ud + 1);
- if (cu->addr)
- cu->addr = (u_int32_t)GetAliasAddress(link).s_addr;
-
- cu_link = FindUdpTcpOut(pip->ip_src, GetDestAddress(link),
- ud->uh_dport, 0, IPPROTO_UDP, 1);
-
-#ifndef NO_FW_PUNCH
- if (cu_link)
- PunchFWHole(cu_link);
-#endif
- }
-}
-
-void
-AliasHandleCUSeeMeIn(struct ip *pip, struct in_addr original_addr)
-{
- struct in_addr alias_addr;
- struct udphdr *ud;
- struct cu_header *cu;
- struct oc_header *oc;
- struct client_info *ci;
- char *end;
- int i;
-
- alias_addr.s_addr = pip->ip_dst.s_addr;
- ud = (struct udphdr *)((char *)pip + (pip->ip_hl << 2));
- cu = (struct cu_header *)(ud + 1);
- oc = (struct oc_header *)(cu + 1);
- ci = (struct client_info *)(oc + 1);
- end = (char *)ud + ntohs(ud->uh_ulen);
-
- if ((char *)oc <= end) {
- if(cu->dest_addr)
- cu->dest_addr = (u_int32_t)original_addr.s_addr;
- if(ntohs(cu->data_type) == 101)
- /* Find and change our address */
- for(i = 0; (char *)(ci + 1) <= end && i < oc->client_count; i++, ci++)
- if(ci->address == (u_int32_t)alias_addr.s_addr) {
- ci->address = (u_int32_t)original_addr.s_addr;
- break;
- }
- }
-}
diff --git a/sys/netinet/libalias/alias_db.c b/sys/netinet/libalias/alias_db.c
deleted file mode 100644
index e3aab97dd0f6..000000000000
--- a/sys/netinet/libalias/alias_db.c
+++ /dev/null
@@ -1,2931 +0,0 @@
-/* -*- mode: c; tab-width: 8; c-basic-indent: 4; -*- */
-
-/*-
- * Copyright (c) 2001 Charles Mott <cm@linktel.net>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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$");
-
-/*
- Alias_db.c encapsulates all data structures used for storing
- packet aliasing data. Other parts of the aliasing software
- access data through functions provided in this file.
-
- Data storage is based on the notion of a "link", which is
- established for ICMP echo/reply packets, UDP datagrams and
- TCP stream connections. A link stores the original source
- and destination addresses. For UDP and TCP, it also stores
- source and destination port numbers, as well as an alias
- port number. Links are also used to store information about
- fragments.
-
- There is a facility for sweeping through and deleting old
- links as new packets are sent through. A simple timeout is
- used for ICMP and UDP links. TCP links are left alone unless
- there is an incomplete connection, in which case the link
- can be deleted after a certain amount of time.
-
-
- Initial version: August, 1996 (cjm)
-
- Version 1.4: September 16, 1996 (cjm)
- Facility for handling incoming links added.
-
- Version 1.6: September 18, 1996 (cjm)
- ICMP data handling simplified.
-
- Version 1.7: January 9, 1997 (cjm)
- Fragment handling simplified.
- Saves pointers for unresolved fragments.
- Permits links for unspecified remote ports
- or unspecified remote addresses.
- Fixed bug which did not properly zero port
- table entries after a link was deleted.
- Cleaned up some obsolete comments.
-
- Version 1.8: January 14, 1997 (cjm)
- Fixed data type error in StartPoint().
- (This error did not exist prior to v1.7
- and was discovered and fixed by Ari Suutari)
-
- Version 1.9: February 1, 1997
- Optionally, connections initiated from packet aliasing host
- machine will will not have their port number aliased unless it
- conflicts with an aliasing port already being used. (cjm)
-
- All options earlier being #ifdef'ed are now available through
- a new interface, SetPacketAliasMode(). This allows run time
- control (which is now available in PPP+pktAlias through the
- 'alias' keyword). (ee)
-
- Added ability to create an alias port without
- either destination address or port specified.
- port type = ALIAS_PORT_UNKNOWN_DEST_ALL (ee)
-
- Removed K&R style function headers
- and general cleanup. (ee)
-
- Added packetAliasMode to replace compiler #defines's (ee)
-
- Allocates sockets for partially specified
- ports if ALIAS_USE_SOCKETS defined. (cjm)
-
- Version 2.0: March, 1997
- SetAliasAddress() will now clean up alias links
- if the aliasing address is changed. (cjm)
-
- PacketAliasPermanentLink() function added to support permanent
- links. (J. Fortes suggested the need for this.)
- Examples:
-
- (192.168.0.1, port 23) <-> alias port 6002, unknown dest addr/port
-
- (192.168.0.2, port 21) <-> alias port 3604, known dest addr
- unknown dest port
-
- These permanent links allow for incoming connections to
- machines on the local network. They can be given with a
- user-chosen amount of specificity, with increasing specificity
- meaning more security. (cjm)
-
- Quite a bit of rework to the basic engine. The portTable[]
- array, which kept track of which ports were in use was replaced
- by a table/linked list structure. (cjm)
-
- SetExpire() function added. (cjm)
-
- DeleteLink() no longer frees memory association with a pointer
- to a fragment (this bug was first recognized by E. Eklund in
- v1.9).
-
- Version 2.1: May, 1997 (cjm)
- Packet aliasing engine reworked so that it can handle
- multiple external addresses rather than just a single
- host address.
-
- PacketAliasRedirectPort() and PacketAliasRedirectAddr()
- added to the API. The first function is a more generalized
- version of PacketAliasPermanentLink(). The second function
- implements static network address translation.
-
- Version 3.2: July, 2000 (salander and satoh)
- Added FindNewPortGroup to get contiguous range of port values.
-
- Added QueryUdpTcpIn and QueryUdpTcpOut to look for an aliasing
- link but not actually add one.
-
- Added FindRtspOut, which is closely derived from FindUdpTcpOut,
- except that the alias port (from FindNewPortGroup) is provided
- as input.
-
- See HISTORY file for additional revisions.
-*/
-
-
-/* System include files */
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#include <sys/queue.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/types.h>
-
-/* BSD network include files */
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-
-#include "alias.h"
-#include "alias_local.h"
-
-
-
-/*
- Constants (note: constants are also defined
- near relevant functions or structs)
-*/
-
-/* Sizes of input and output link tables */
-#define LINK_TABLE_OUT_SIZE 101
-#define LINK_TABLE_IN_SIZE 4001
-
-/* Parameters used for cleanup of expired links */
-#define ALIAS_CLEANUP_INTERVAL_SECS 60
-#define ALIAS_CLEANUP_MAX_SPOKES 30
-
-/* Timeouts (in seconds) for different link types */
-#define ICMP_EXPIRE_TIME 60
-#define UDP_EXPIRE_TIME 60
-#define PROTO_EXPIRE_TIME 60
-#define FRAGMENT_ID_EXPIRE_TIME 10
-#define FRAGMENT_PTR_EXPIRE_TIME 30
-
-/* TCP link expire time for different cases */
-/* When the link has been used and closed - minimal grace time to
- allow ACKs and potential re-connect in FTP (XXX - is this allowed?) */
-#ifndef TCP_EXPIRE_DEAD
-# define TCP_EXPIRE_DEAD 10
-#endif
-
-/* When the link has been used and closed on one side - the other side
- is allowed to still send data */
-#ifndef TCP_EXPIRE_SINGLEDEAD
-# define TCP_EXPIRE_SINGLEDEAD 90
-#endif
-
-/* When the link isn't yet up */
-#ifndef TCP_EXPIRE_INITIAL
-# define TCP_EXPIRE_INITIAL 300
-#endif
-
-/* When the link is up */
-#ifndef TCP_EXPIRE_CONNECTED
-# define TCP_EXPIRE_CONNECTED 86400
-#endif
-
-
-/* Dummy port number codes used for FindLinkIn/Out() and AddLink().
- These constants can be anything except zero, which indicates an
- unknown port number. */
-
-#define NO_DEST_PORT 1
-#define NO_SRC_PORT 1
-
-
-
-/* Data Structures
-
- The fundamental data structure used in this program is
- "struct alias_link". Whenever a TCP connection is made,
- a UDP datagram is sent out, or an ICMP echo request is made,
- a link record is made (if it has not already been created).
- The link record is identified by the source address/port
- and the destination address/port. In the case of an ICMP
- echo request, the source port is treated as being equivalent
- with the 16-bit ID number of the ICMP packet.
-
- The link record also can store some auxiliary data. For
- TCP connections that have had sequence and acknowledgment
- modifications, data space is available to track these changes.
- A state field is used to keep track in changes to the TCP
- connection state. ID numbers of fragments can also be
- stored in the auxiliary space. Pointers to unresolved
- fragments can also be stored.
-
- The link records support two independent chainings. Lookup
- tables for input and out tables hold the initial pointers
- the link chains. On input, the lookup table indexes on alias
- port and link type. On output, the lookup table indexes on
- source address, destination address, source port, destination
- port and link type.
-*/
-
-struct ack_data_record /* used to save changes to ACK/sequence numbers */
-{
- u_long ack_old;
- u_long ack_new;
- int delta;
- int active;
-};
-
-struct tcp_state /* Information about TCP connection */
-{
- int in; /* State for outside -> inside */
- int out; /* State for inside -> outside */
- int index; /* Index to ACK data array */
- int ack_modified; /* Indicates whether ACK and sequence numbers */
- /* been modified */
-};
-
-#define N_LINK_TCP_DATA 3 /* Number of distinct ACK number changes
- saved for a modified TCP stream */
-struct tcp_dat
-{
- struct tcp_state state;
- struct ack_data_record ack[N_LINK_TCP_DATA];
- int fwhole; /* Which firewall record is used for this hole? */
-};
-
-struct server /* LSNAT server pool (circular list) */
-{
- struct in_addr addr;
- u_short port;
- struct server *next;
-};
-
-struct alias_link /* Main data structure */
-{
- struct in_addr src_addr; /* Address and port information */
- struct in_addr dst_addr;
- struct in_addr alias_addr;
- struct in_addr proxy_addr;
- u_short src_port;
- u_short dst_port;
- u_short alias_port;
- u_short proxy_port;
- struct server *server;
-
- int link_type; /* Type of link: TCP, UDP, ICMP, proto, frag */
-
-/* values for link_type */
-#define LINK_ICMP IPPROTO_ICMP
-#define LINK_UDP IPPROTO_UDP
-#define LINK_TCP IPPROTO_TCP
-#define LINK_FRAGMENT_ID (IPPROTO_MAX + 1)
-#define LINK_FRAGMENT_PTR (IPPROTO_MAX + 2)
-#define LINK_ADDR (IPPROTO_MAX + 3)
-#define LINK_PPTP (IPPROTO_MAX + 4)
-
- int flags; /* indicates special characteristics */
- int pflags; /* protocol-specific flags */
-
-/* flag bits */
-#define LINK_UNKNOWN_DEST_PORT 0x01
-#define LINK_UNKNOWN_DEST_ADDR 0x02
-#define LINK_PERMANENT 0x04
-#define LINK_PARTIALLY_SPECIFIED 0x03 /* logical-or of first two bits */
-#define LINK_UNFIREWALLED 0x08
-
- int timestamp; /* Time link was last accessed */
- int expire_time; /* Expire time for link */
-
- int sockfd; /* socket descriptor */
-
- LIST_ENTRY(alias_link) list_out; /* Linked list of pointers for */
- LIST_ENTRY(alias_link) list_in; /* input and output lookup tables */
-
- union /* Auxiliary data */
- {
- char *frag_ptr;
- struct in_addr frag_addr;
- struct tcp_dat *tcp;
- } data;
-};
-
-
-
-
-
-/* Global Variables
-
- The global variables listed here are only accessed from
- within alias_db.c and so are prefixed with the static
- designation.
-*/
-
-int packetAliasMode; /* Mode flags */
- /* - documented in alias.h */
-
-static struct in_addr aliasAddress; /* Address written onto source */
- /* field of IP packet. */
-
-static struct in_addr targetAddress; /* IP address incoming packets */
- /* are sent to if no aliasing */
- /* link already exists */
-
-static struct in_addr nullAddress; /* Used as a dummy parameter for */
- /* some function calls */
-static LIST_HEAD(, alias_link)
-linkTableOut[LINK_TABLE_OUT_SIZE]; /* Lookup table of pointers to */
- /* chains of link records. Each */
-static LIST_HEAD(, alias_link) /* link record is doubly indexed */
-linkTableIn[LINK_TABLE_IN_SIZE]; /* into input and output lookup */
- /* tables. */
-
-static int icmpLinkCount; /* Link statistics */
-static int udpLinkCount;
-static int tcpLinkCount;
-static int pptpLinkCount;
-static int protoLinkCount;
-static int fragmentIdLinkCount;
-static int fragmentPtrLinkCount;
-static int sockCount;
-
-static int cleanupIndex; /* Index to chain of link table */
- /* being inspected for old links */
-
-static int timeStamp; /* System time in seconds for */
- /* current packet */
-
-static int lastCleanupTime; /* Last time IncrementalCleanup() */
- /* was called */
-
-static int houseKeepingResidual; /* used by HouseKeeping() */
-
-static int deleteAllLinks; /* If equal to zero, DeleteLink() */
- /* will not remove permanent links */
-
-static FILE *monitorFile; /* File descriptor for link */
- /* statistics monitoring file */
-
-static int newDefaultLink; /* Indicates if a new aliasing */
- /* link has been created after a */
- /* call to PacketAliasIn/Out(). */
-
-#ifndef NO_FW_PUNCH
-static int fireWallFD = -1; /* File descriptor to be able to */
- /* control firewall. Opened by */
- /* PacketAliasSetMode on first */
- /* setting the PKT_ALIAS_PUNCH_FW */
- /* flag. */
-#endif
-
-
-
-
-
-
-
-/* Internal utility routines (used only in alias_db.c)
-
-Lookup table starting points:
- StartPointIn() -- link table initial search point for
- incoming packets
- StartPointOut() -- link table initial search point for
- outgoing packets
-
-Miscellaneous:
- SeqDiff() -- difference between two TCP sequences
- ShowAliasStats() -- send alias statistics to a monitor file
-*/
-
-
-/* Local prototypes */
-static u_int StartPointIn(struct in_addr, u_short, int);
-
-static u_int StartPointOut(struct in_addr, struct in_addr,
- u_short, u_short, int);
-
-static int SeqDiff(u_long, u_long);
-
-static void ShowAliasStats(void);
-
-#ifndef NO_FW_PUNCH
-/* Firewall control */
-static void InitPunchFW(void);
-static void UninitPunchFW(void);
-static void ClearFWHole(struct alias_link *link);
-#endif
-
-/* Log file control */
-static void InitPacketAliasLog(void);
-static void UninitPacketAliasLog(void);
-
-static u_int
-StartPointIn(struct in_addr alias_addr,
- u_short alias_port,
- int link_type)
-{
- u_int n;
-
- n = alias_addr.s_addr;
- if (link_type != LINK_PPTP)
- n += alias_port;
- n += link_type;
- return(n % LINK_TABLE_IN_SIZE);
-}
-
-
-static u_int
-StartPointOut(struct in_addr src_addr, struct in_addr dst_addr,
- u_short src_port, u_short dst_port, int link_type)
-{
- u_int n;
-
- n = src_addr.s_addr;
- n += dst_addr.s_addr;
- if (link_type != LINK_PPTP) {
- n += src_port;
- n += dst_port;
- }
- n += link_type;
-
- return(n % LINK_TABLE_OUT_SIZE);
-}
-
-
-static int
-SeqDiff(u_long x, u_long y)
-{
-/* Return the difference between two TCP sequence numbers */
-
-/*
- This function is encapsulated in case there are any unusual
- arithmetic conditions that need to be considered.
-*/
-
- return (ntohl(y) - ntohl(x));
-}
-
-
-static void
-ShowAliasStats(void)
-{
-/* Used for debugging */
-
- if (monitorFile)
- {
- fprintf(monitorFile, "icmp=%d, udp=%d, tcp=%d, pptp=%d, proto=%d, frag_id=%d frag_ptr=%d",
- icmpLinkCount,
- udpLinkCount,
- tcpLinkCount,
- pptpLinkCount,
- protoLinkCount,
- fragmentIdLinkCount,
- fragmentPtrLinkCount);
-
- fprintf(monitorFile, " / tot=%d (sock=%d)\n",
- icmpLinkCount + udpLinkCount
- + tcpLinkCount
- + pptpLinkCount
- + protoLinkCount
- + fragmentIdLinkCount
- + fragmentPtrLinkCount,
- sockCount);
-
- fflush(monitorFile);
- }
-}
-
-
-
-
-
-/* Internal routines for finding, deleting and adding links
-
-Port Allocation:
- GetNewPort() -- find and reserve new alias port number
- GetSocket() -- try to allocate a socket for a given port
-
-Link creation and deletion:
- CleanupAliasData() - remove all link chains from lookup table
- IncrementalCleanup() - look for stale links in a single chain
- DeleteLink() - remove link
- AddLink() - add link
- ReLink() - change link
-
-Link search:
- FindLinkOut() - find link for outgoing packets
- FindLinkIn() - find link for incoming packets
-
-Port search:
- FindNewPortGroup() - find an available group of ports
-*/
-
-/* Local prototypes */
-static int GetNewPort(struct alias_link *, int);
-
-static u_short GetSocket(u_short, int *, int);
-
-static void CleanupAliasData(void);
-
-static void IncrementalCleanup(void);
-
-static void DeleteLink(struct alias_link *);
-
-static struct alias_link *
-AddLink(struct in_addr, struct in_addr, struct in_addr,
- u_short, u_short, int, int);
-
-static struct alias_link *
-ReLink(struct alias_link *,
- struct in_addr, struct in_addr, struct in_addr,
- u_short, u_short, int, int);
-
-static struct alias_link *
-FindLinkOut(struct in_addr, struct in_addr, u_short, u_short, int, int);
-
-static struct alias_link *
-FindLinkIn(struct in_addr, struct in_addr, u_short, u_short, int, int);
-
-
-#define ALIAS_PORT_BASE 0x08000
-#define ALIAS_PORT_MASK 0x07fff
-#define ALIAS_PORT_MASK_EVEN 0x07ffe
-#define GET_NEW_PORT_MAX_ATTEMPTS 20
-
-#define GET_ALIAS_PORT -1
-#define GET_ALIAS_ID GET_ALIAS_PORT
-
-#define FIND_EVEN_ALIAS_BASE 1
-
-/* GetNewPort() allocates port numbers. Note that if a port number
- is already in use, that does not mean that it cannot be used by
- another link concurrently. This is because GetNewPort() looks for
- unused triplets: (dest addr, dest port, alias port). */
-
-static int
-GetNewPort(struct alias_link *link, int alias_port_param)
-{
- int i;
- int max_trials;
- u_short port_sys;
- u_short port_net;
-
-/*
- Description of alias_port_param for GetNewPort(). When
- this parameter is zero or positive, it precisely specifies
- the port number. GetNewPort() will return this number
- without check that it is in use.
-
- When this parameter is GET_ALIAS_PORT, it indicates to get a randomly
- selected port number.
-*/
-
- if (alias_port_param == GET_ALIAS_PORT)
- {
- /*
- * The aliasing port is automatically selected
- * by one of two methods below:
- */
- max_trials = GET_NEW_PORT_MAX_ATTEMPTS;
-
- if (packetAliasMode & PKT_ALIAS_SAME_PORTS)
- {
- /*
- * When the PKT_ALIAS_SAME_PORTS option is
- * chosen, the first try will be the
- * actual source port. If this is already
- * in use, the remainder of the trials
- * will be random.
- */
- port_net = link->src_port;
- port_sys = ntohs(port_net);
- }
- else
- {
- /* First trial and all subsequent are random. */
- port_sys = random() & ALIAS_PORT_MASK;
- port_sys += ALIAS_PORT_BASE;
- port_net = htons(port_sys);
- }
- }
- else if (alias_port_param >= 0 && alias_port_param < 0x10000)
- {
- link->alias_port = (u_short) alias_port_param;
- return(0);
- }
- else
- {
-#ifdef DEBUG
- fprintf(stderr, "PacketAlias/GetNewPort(): ");
- fprintf(stderr, "input parameter error\n");
-#endif
- return(-1);
- }
-
-
-/* Port number search */
- for (i=0; i<max_trials; i++)
- {
- int go_ahead;
- struct alias_link *search_result;
-
- search_result = FindLinkIn(link->dst_addr, link->alias_addr,
- link->dst_port, port_net,
- link->link_type, 0);
-
- if (search_result == NULL)
- go_ahead = 1;
- else if (!(link->flags & LINK_PARTIALLY_SPECIFIED)
- && (search_result->flags & LINK_PARTIALLY_SPECIFIED))
- go_ahead = 1;
- else
- go_ahead = 0;
-
- if (go_ahead)
- {
- if ((packetAliasMode & PKT_ALIAS_USE_SOCKETS)
- && (link->flags & LINK_PARTIALLY_SPECIFIED)
- && ((link->link_type == LINK_TCP) ||
- (link->link_type == LINK_UDP)))
- {
- if (GetSocket(port_net, &link->sockfd, link->link_type))
- {
- link->alias_port = port_net;
- return(0);
- }
- }
- else
- {
- link->alias_port = port_net;
- return(0);
- }
- }
-
- port_sys = random() & ALIAS_PORT_MASK;
- port_sys += ALIAS_PORT_BASE;
- port_net = htons(port_sys);
- }
-
-#ifdef DEBUG
- fprintf(stderr, "PacketAlias/GetnewPort(): ");
- fprintf(stderr, "could not find free port\n");
-#endif
-
- return(-1);
-}
-
-
-static u_short
-GetSocket(u_short port_net, int *sockfd, int link_type)
-{
- int err;
- int sock;
- struct sockaddr_in sock_addr;
-
- if (link_type == LINK_TCP)
- sock = socket(AF_INET, SOCK_STREAM, 0);
- else if (link_type == LINK_UDP)
- sock = socket(AF_INET, SOCK_DGRAM, 0);
- else
- {
-#ifdef DEBUG
- fprintf(stderr, "PacketAlias/GetSocket(): ");
- fprintf(stderr, "incorrect link type\n");
-#endif
- return(0);
- }
-
- if (sock < 0)
- {
-#ifdef DEBUG
- fprintf(stderr, "PacketAlias/GetSocket(): ");
- fprintf(stderr, "socket() error %d\n", *sockfd);
-#endif
- return(0);
- }
-
- sock_addr.sin_family = AF_INET;
- sock_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- sock_addr.sin_port = port_net;
-
- err = bind(sock,
- (struct sockaddr *) &sock_addr,
- sizeof(sock_addr));
- if (err == 0)
- {
- sockCount++;
- *sockfd = sock;
- return(1);
- }
- else
- {
- close(sock);
- return(0);
- }
-}
-
-
-/* FindNewPortGroup() returns a base port number for an available
- range of contiguous port numbers. Note that if a port number
- is already in use, that does not mean that it cannot be used by
- another link concurrently. This is because FindNewPortGroup()
- looks for unused triplets: (dest addr, dest port, alias port). */
-
-int
-FindNewPortGroup(struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_short src_port,
- u_short dst_port,
- u_short port_count,
- u_char proto,
- u_char align)
-{
- int i, j;
- int max_trials;
- u_short port_sys;
- int link_type;
-
- /*
- * Get link_type from protocol
- */
-
- switch (proto)
- {
- case IPPROTO_UDP:
- link_type = LINK_UDP;
- break;
- case IPPROTO_TCP:
- link_type = LINK_TCP;
- break;
- default:
- return (0);
- break;
- }
-
- /*
- * The aliasing port is automatically selected
- * by one of two methods below:
- */
- max_trials = GET_NEW_PORT_MAX_ATTEMPTS;
-
- if (packetAliasMode & PKT_ALIAS_SAME_PORTS) {
- /*
- * When the ALIAS_SAME_PORTS option is
- * chosen, the first try will be the
- * actual source port. If this is already
- * in use, the remainder of the trials
- * will be random.
- */
- port_sys = ntohs(src_port);
-
- } else {
-
- /* First trial and all subsequent are random. */
- if (align == FIND_EVEN_ALIAS_BASE)
- port_sys = random() & ALIAS_PORT_MASK_EVEN;
- else
- port_sys = random() & ALIAS_PORT_MASK;
-
- port_sys += ALIAS_PORT_BASE;
- }
-
-/* Port number search */
- for (i = 0; i < max_trials; i++) {
-
- struct alias_link *search_result;
-
- for (j = 0; j < port_count; j++)
- if (0 != (search_result = FindLinkIn(dst_addr, alias_addr,
- dst_port, htons(port_sys + j),
- link_type, 0)))
- break;
-
- /* Found a good range, return base */
- if (j == port_count)
- return (htons(port_sys));
-
- /* Find a new base to try */
- if (align == FIND_EVEN_ALIAS_BASE)
- port_sys = random() & ALIAS_PORT_MASK_EVEN;
- else
- port_sys = random() & ALIAS_PORT_MASK;
-
- port_sys += ALIAS_PORT_BASE;
- }
-
-#ifdef DEBUG
- fprintf(stderr, "PacketAlias/FindNewPortGroup(): ");
- fprintf(stderr, "could not find free port(s)\n");
-#endif
-
- return(0);
-}
-
-static void
-CleanupAliasData(void)
-{
- struct alias_link *link;
- int i, icount;
-
- icount = 0;
- for (i=0; i<LINK_TABLE_OUT_SIZE; i++)
- {
- link = LIST_FIRST(&linkTableOut[i]);
- while (link != NULL)
- {
- struct alias_link *link_next;
- link_next = LIST_NEXT(link, list_out);
- icount++;
- DeleteLink(link);
- link = link_next;
- }
- }
-
- cleanupIndex =0;
-}
-
-
-static void
-IncrementalCleanup(void)
-{
- int icount;
- struct alias_link *link;
-
- icount = 0;
- link = LIST_FIRST(&linkTableOut[cleanupIndex++]);
- while (link != NULL)
- {
- int idelta;
- struct alias_link *link_next;
-
- link_next = LIST_NEXT(link, list_out);
- idelta = timeStamp - link->timestamp;
- switch (link->link_type)
- {
- case LINK_TCP:
- if (idelta > link->expire_time)
- {
- struct tcp_dat *tcp_aux;
-
- tcp_aux = link->data.tcp;
- if (tcp_aux->state.in != ALIAS_TCP_STATE_CONNECTED
- || tcp_aux->state.out != ALIAS_TCP_STATE_CONNECTED)
- {
- DeleteLink(link);
- icount++;
- }
- }
- break;
- default:
- if (idelta > link->expire_time)
- {
- DeleteLink(link);
- icount++;
- }
- break;
- }
- link = link_next;
- }
-
- if (cleanupIndex == LINK_TABLE_OUT_SIZE)
- cleanupIndex = 0;
-}
-
-static void
-DeleteLink(struct alias_link *link)
-{
-
-/* Don't do anything if the link is marked permanent */
- if (deleteAllLinks == 0 && link->flags & LINK_PERMANENT)
- return;
-
-#ifndef NO_FW_PUNCH
-/* Delete associated firewall hole, if any */
- ClearFWHole(link);
-#endif
-
-/* Free memory allocated for LSNAT server pool */
- if (link->server != NULL) {
- struct server *head, *curr, *next;
-
- head = curr = link->server;
- do {
- next = curr->next;
- free(curr);
- } while ((curr = next) != head);
- }
-
-/* Adjust output table pointers */
- LIST_REMOVE(link, list_out);
-
-/* Adjust input table pointers */
- LIST_REMOVE(link, list_in);
-
-/* Close socket, if one has been allocated */
- if (link->sockfd != -1)
- {
- sockCount--;
- close(link->sockfd);
- }
-
-/* Link-type dependent cleanup */
- switch(link->link_type)
- {
- case LINK_ICMP:
- icmpLinkCount--;
- break;
- case LINK_UDP:
- udpLinkCount--;
- break;
- case LINK_TCP:
- tcpLinkCount--;
- free(link->data.tcp);
- break;
- case LINK_PPTP:
- pptpLinkCount--;
- break;
- case LINK_FRAGMENT_ID:
- fragmentIdLinkCount--;
- break;
- case LINK_FRAGMENT_PTR:
- fragmentPtrLinkCount--;
- if (link->data.frag_ptr != NULL)
- free(link->data.frag_ptr);
- break;
- case LINK_ADDR:
- break;
- default:
- protoLinkCount--;
- break;
- }
-
-/* Free memory */
- free(link);
-
-/* Write statistics, if logging enabled */
- if (packetAliasMode & PKT_ALIAS_LOG)
- {
- ShowAliasStats();
- }
-}
-
-
-static struct alias_link *
-AddLink(struct in_addr src_addr,
- struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_short src_port,
- u_short dst_port,
- int alias_port_param, /* if less than zero, alias */
- int link_type) /* port will be automatically */
-{ /* chosen. If greater than */
- u_int start_point; /* zero, equal to alias port */
- struct alias_link *link;
-
- link = malloc(sizeof(struct alias_link));
- if (link != NULL)
- {
- /* Basic initialization */
- link->src_addr = src_addr;
- link->dst_addr = dst_addr;
- link->alias_addr = alias_addr;
- link->proxy_addr.s_addr = INADDR_ANY;
- link->src_port = src_port;
- link->dst_port = dst_port;
- link->proxy_port = 0;
- link->server = NULL;
- link->link_type = link_type;
- link->sockfd = -1;
- link->flags = 0;
- link->pflags = 0;
- link->timestamp = timeStamp;
-
- /* Expiration time */
- switch (link_type)
- {
- case LINK_ICMP:
- link->expire_time = ICMP_EXPIRE_TIME;
- break;
- case LINK_UDP:
- link->expire_time = UDP_EXPIRE_TIME;
- break;
- case LINK_TCP:
- link->expire_time = TCP_EXPIRE_INITIAL;
- break;
- case LINK_PPTP:
- link->flags |= LINK_PERMANENT; /* no timeout. */
- break;
- case LINK_FRAGMENT_ID:
- link->expire_time = FRAGMENT_ID_EXPIRE_TIME;
- break;
- case LINK_FRAGMENT_PTR:
- link->expire_time = FRAGMENT_PTR_EXPIRE_TIME;
- break;
- case LINK_ADDR:
- break;
- default:
- link->expire_time = PROTO_EXPIRE_TIME;
- break;
- }
-
- /* Determine alias flags */
- if (dst_addr.s_addr == INADDR_ANY)
- link->flags |= LINK_UNKNOWN_DEST_ADDR;
- if (dst_port == 0)
- link->flags |= LINK_UNKNOWN_DEST_PORT;
-
- /* Determine alias port */
- if (GetNewPort(link, alias_port_param) != 0)
- {
- free(link);
- return(NULL);
- }
-
- /* Link-type dependent initialization */
- switch(link_type)
- {
- struct tcp_dat *aux_tcp;
-
- case LINK_ICMP:
- icmpLinkCount++;
- break;
- case LINK_UDP:
- udpLinkCount++;
- break;
- case LINK_TCP:
- aux_tcp = malloc(sizeof(struct tcp_dat));
- if (aux_tcp != NULL)
- {
- int i;
-
- tcpLinkCount++;
- aux_tcp->state.in = ALIAS_TCP_STATE_NOT_CONNECTED;
- aux_tcp->state.out = ALIAS_TCP_STATE_NOT_CONNECTED;
- aux_tcp->state.index = 0;
- aux_tcp->state.ack_modified = 0;
- for (i=0; i<N_LINK_TCP_DATA; i++)
- aux_tcp->ack[i].active = 0;
- aux_tcp->fwhole = -1;
- link->data.tcp = aux_tcp;
- }
- else
- {
-#ifdef DEBUG
- fprintf(stderr, "PacketAlias/AddLink: ");
- fprintf(stderr, " cannot allocate auxiliary TCP data\n");
-#endif
- free(link);
- return (NULL);
- }
- break;
- case LINK_PPTP:
- pptpLinkCount++;
- break;
- case LINK_FRAGMENT_ID:
- fragmentIdLinkCount++;
- break;
- case LINK_FRAGMENT_PTR:
- fragmentPtrLinkCount++;
- break;
- case LINK_ADDR:
- break;
- default:
- protoLinkCount++;
- break;
- }
-
- /* Set up pointers for output lookup table */
- start_point = StartPointOut(src_addr, dst_addr,
- src_port, dst_port, link_type);
- LIST_INSERT_HEAD(&linkTableOut[start_point], link, list_out);
-
- /* Set up pointers for input lookup table */
- start_point = StartPointIn(alias_addr, link->alias_port, link_type);
- LIST_INSERT_HEAD(&linkTableIn[start_point], link, list_in);
- }
- else
- {
-#ifdef DEBUG
- fprintf(stderr, "PacketAlias/AddLink(): ");
- fprintf(stderr, "malloc() call failed.\n");
-#endif
- }
-
- if (packetAliasMode & PKT_ALIAS_LOG)
- {
- ShowAliasStats();
- }
-
- return(link);
-}
-
-static struct alias_link *
-ReLink(struct alias_link *old_link,
- struct in_addr src_addr,
- struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_short src_port,
- u_short dst_port,
- int alias_port_param, /* if less than zero, alias */
- int link_type) /* port will be automatically */
-{ /* chosen. If greater than */
- struct alias_link *new_link; /* zero, equal to alias port */
-
- new_link = AddLink(src_addr, dst_addr, alias_addr,
- src_port, dst_port, alias_port_param,
- link_type);
-#ifndef NO_FW_PUNCH
- if (new_link != NULL &&
- old_link->link_type == LINK_TCP &&
- old_link->data.tcp->fwhole > 0) {
- PunchFWHole(new_link);
- }
-#endif
- DeleteLink(old_link);
- return new_link;
-}
-
-static struct alias_link *
-_FindLinkOut(struct in_addr src_addr,
- struct in_addr dst_addr,
- u_short src_port,
- u_short dst_port,
- int link_type,
- int replace_partial_links)
-{
- u_int i;
- struct alias_link *link;
-
- i = StartPointOut(src_addr, dst_addr, src_port, dst_port, link_type);
- LIST_FOREACH(link, &linkTableOut[i], list_out)
- {
- if (link->src_addr.s_addr == src_addr.s_addr
- && link->server == NULL
- && link->dst_addr.s_addr == dst_addr.s_addr
- && link->dst_port == dst_port
- && link->src_port == src_port
- && link->link_type == link_type)
- {
- link->timestamp = timeStamp;
- break;
- }
- }
-
-/* Search for partially specified links. */
- if (link == NULL && replace_partial_links)
- {
- if (dst_port != 0 && dst_addr.s_addr != INADDR_ANY)
- {
- link = _FindLinkOut(src_addr, dst_addr, src_port, 0,
- link_type, 0);
- if (link == NULL)
- link = _FindLinkOut(src_addr, nullAddress, src_port,
- dst_port, link_type, 0);
- }
- if (link == NULL &&
- (dst_port != 0 || dst_addr.s_addr != INADDR_ANY))
- {
- link = _FindLinkOut(src_addr, nullAddress, src_port, 0,
- link_type, 0);
- }
- if (link != NULL)
- {
- link = ReLink(link,
- src_addr, dst_addr, link->alias_addr,
- src_port, dst_port, link->alias_port,
- link_type);
- }
- }
-
- return(link);
-}
-
-static struct alias_link *
-FindLinkOut(struct in_addr src_addr,
- struct in_addr dst_addr,
- u_short src_port,
- u_short dst_port,
- int link_type,
- int replace_partial_links)
-{
- struct alias_link *link;
-
- link = _FindLinkOut(src_addr, dst_addr, src_port, dst_port,
- link_type, replace_partial_links);
-
- if (link == NULL)
- {
- /* The following allows permanent links to be
- specified as using the default source address
- (i.e. device interface address) without knowing
- in advance what that address is. */
- if (aliasAddress.s_addr != 0 &&
- src_addr.s_addr == aliasAddress.s_addr)
- {
- link = _FindLinkOut(nullAddress, dst_addr, src_port, dst_port,
- link_type, replace_partial_links);
- }
- }
-
- return(link);
-}
-
-
-static struct alias_link *
-_FindLinkIn(struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_short dst_port,
- u_short alias_port,
- int link_type,
- int replace_partial_links)
-{
- int flags_in;
- u_int start_point;
- struct alias_link *link;
- struct alias_link *link_fully_specified;
- struct alias_link *link_unknown_all;
- struct alias_link *link_unknown_dst_addr;
- struct alias_link *link_unknown_dst_port;
-
-/* Initialize pointers */
- link_fully_specified = NULL;
- link_unknown_all = NULL;
- link_unknown_dst_addr = NULL;
- link_unknown_dst_port = NULL;
-
-/* If either the dest addr or port is unknown, the search
- loop will have to know about this. */
-
- flags_in = 0;
- if (dst_addr.s_addr == INADDR_ANY)
- flags_in |= LINK_UNKNOWN_DEST_ADDR;
- if (dst_port == 0)
- flags_in |= LINK_UNKNOWN_DEST_PORT;
-
-/* Search loop */
- start_point = StartPointIn(alias_addr, alias_port, link_type);
- LIST_FOREACH(link, &linkTableIn[start_point], list_in)
- {
- int flags;
-
- flags = flags_in | link->flags;
- if (!(flags & LINK_PARTIALLY_SPECIFIED))
- {
- if (link->alias_addr.s_addr == alias_addr.s_addr
- && link->alias_port == alias_port
- && link->dst_addr.s_addr == dst_addr.s_addr
- && link->dst_port == dst_port
- && link->link_type == link_type)
- {
- link_fully_specified = link;
- break;
- }
- }
- else if ((flags & LINK_UNKNOWN_DEST_ADDR)
- && (flags & LINK_UNKNOWN_DEST_PORT))
- {
- if (link->alias_addr.s_addr == alias_addr.s_addr
- && link->alias_port == alias_port
- && link->link_type == link_type)
- {
- if (link_unknown_all == NULL)
- link_unknown_all = link;
- }
- }
- else if (flags & LINK_UNKNOWN_DEST_ADDR)
- {
- if (link->alias_addr.s_addr == alias_addr.s_addr
- && link->alias_port == alias_port
- && link->link_type == link_type
- && link->dst_port == dst_port)
- {
- if (link_unknown_dst_addr == NULL)
- link_unknown_dst_addr = link;
- }
- }
- else if (flags & LINK_UNKNOWN_DEST_PORT)
- {
- if (link->alias_addr.s_addr == alias_addr.s_addr
- && link->alias_port == alias_port
- && link->link_type == link_type
- && link->dst_addr.s_addr == dst_addr.s_addr)
- {
- if (link_unknown_dst_port == NULL)
- link_unknown_dst_port = link;
- }
- }
- }
-
-
-
- if (link_fully_specified != NULL)
- {
- link_fully_specified->timestamp = timeStamp;
- link = link_fully_specified;
- }
- else if (link_unknown_dst_port != NULL)
- link = link_unknown_dst_port;
- else if (link_unknown_dst_addr != NULL)
- link = link_unknown_dst_addr;
- else if (link_unknown_all != NULL)
- link = link_unknown_all;
- else
- return (NULL);
-
- if (replace_partial_links &&
- (link->flags & LINK_PARTIALLY_SPECIFIED || link->server != NULL))
- {
- struct in_addr src_addr;
- u_short src_port;
-
- if (link->server != NULL) { /* LSNAT link */
- src_addr = link->server->addr;
- src_port = link->server->port;
- link->server = link->server->next;
- } else {
- src_addr = link->src_addr;
- src_port = link->src_port;
- }
-
- link = ReLink(link,
- src_addr, dst_addr, alias_addr,
- src_port, dst_port, alias_port,
- link_type);
- }
-
- return (link);
-}
-
-static struct alias_link *
-FindLinkIn(struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_short dst_port,
- u_short alias_port,
- int link_type,
- int replace_partial_links)
-{
- struct alias_link *link;
-
- link = _FindLinkIn(dst_addr, alias_addr, dst_port, alias_port,
- link_type, replace_partial_links);
-
- if (link == NULL)
- {
- /* The following allows permanent links to be
- specified as using the default aliasing address
- (i.e. device interface address) without knowing
- in advance what that address is. */
- if (aliasAddress.s_addr != 0 &&
- alias_addr.s_addr == aliasAddress.s_addr)
- {
- link = _FindLinkIn(dst_addr, nullAddress, dst_port, alias_port,
- link_type, replace_partial_links);
- }
- }
-
- return(link);
-}
-
-
-
-
-/* External routines for finding/adding links
-
--- "external" means outside alias_db.c, but within alias*.c --
-
- FindIcmpIn(), FindIcmpOut()
- FindFragmentIn1(), FindFragmentIn2()
- AddFragmentPtrLink(), FindFragmentPtr()
- FindProtoIn(), FindProtoOut()
- FindUdpTcpIn(), FindUdpTcpOut()
- AddPptp(), FindPptpOutByCallId(), FindPptpInByCallId(),
- FindPptpOutByPeerCallId(), FindPptpInByPeerCallId()
- FindOriginalAddress(), FindAliasAddress()
-
-(prototypes in alias_local.h)
-*/
-
-
-struct alias_link *
-FindIcmpIn(struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_short id_alias,
- int create)
-{
- struct alias_link *link;
-
- link = FindLinkIn(dst_addr, alias_addr,
- NO_DEST_PORT, id_alias,
- LINK_ICMP, 0);
- if (link == NULL && create && !(packetAliasMode & PKT_ALIAS_DENY_INCOMING))
- {
- struct in_addr target_addr;
-
- target_addr = FindOriginalAddress(alias_addr);
- link = AddLink(target_addr, dst_addr, alias_addr,
- id_alias, NO_DEST_PORT, id_alias,
- LINK_ICMP);
- }
-
- return (link);
-}
-
-
-struct alias_link *
-FindIcmpOut(struct in_addr src_addr,
- struct in_addr dst_addr,
- u_short id,
- int create)
-{
- struct alias_link * link;
-
- link = FindLinkOut(src_addr, dst_addr,
- id, NO_DEST_PORT,
- LINK_ICMP, 0);
- if (link == NULL && create)
- {
- struct in_addr alias_addr;
-
- alias_addr = FindAliasAddress(src_addr);
- link = AddLink(src_addr, dst_addr, alias_addr,
- id, NO_DEST_PORT, GET_ALIAS_ID,
- LINK_ICMP);
- }
-
- return(link);
-}
-
-
-struct alias_link *
-FindFragmentIn1(struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_short ip_id)
-{
- struct alias_link *link;
-
- link = FindLinkIn(dst_addr, alias_addr,
- NO_DEST_PORT, ip_id,
- LINK_FRAGMENT_ID, 0);
-
- if (link == NULL)
- {
- link = AddLink(nullAddress, dst_addr, alias_addr,
- NO_SRC_PORT, NO_DEST_PORT, ip_id,
- LINK_FRAGMENT_ID);
- }
-
- return(link);
-}
-
-
-struct alias_link *
-FindFragmentIn2(struct in_addr dst_addr, /* Doesn't add a link if one */
- struct in_addr alias_addr, /* is not found. */
- u_short ip_id)
-{
- return FindLinkIn(dst_addr, alias_addr,
- NO_DEST_PORT, ip_id,
- LINK_FRAGMENT_ID, 0);
-}
-
-
-struct alias_link *
-AddFragmentPtrLink(struct in_addr dst_addr,
- u_short ip_id)
-{
- return AddLink(nullAddress, dst_addr, nullAddress,
- NO_SRC_PORT, NO_DEST_PORT, ip_id,
- LINK_FRAGMENT_PTR);
-}
-
-
-struct alias_link *
-FindFragmentPtr(struct in_addr dst_addr,
- u_short ip_id)
-{
- return FindLinkIn(dst_addr, nullAddress,
- NO_DEST_PORT, ip_id,
- LINK_FRAGMENT_PTR, 0);
-}
-
-
-struct alias_link *
-FindProtoIn(struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_char proto)
-{
- struct alias_link *link;
-
- link = FindLinkIn(dst_addr, alias_addr,
- NO_DEST_PORT, 0,
- proto, 1);
-
- if (link == NULL && !(packetAliasMode & PKT_ALIAS_DENY_INCOMING))
- {
- struct in_addr target_addr;
-
- target_addr = FindOriginalAddress(alias_addr);
- link = AddLink(target_addr, dst_addr, alias_addr,
- NO_SRC_PORT, NO_DEST_PORT, 0,
- proto);
- }
-
- return (link);
-}
-
-
-struct alias_link *
-FindProtoOut(struct in_addr src_addr,
- struct in_addr dst_addr,
- u_char proto)
-{
- struct alias_link *link;
-
- link = FindLinkOut(src_addr, dst_addr,
- NO_SRC_PORT, NO_DEST_PORT,
- proto, 1);
-
- if (link == NULL)
- {
- struct in_addr alias_addr;
-
- alias_addr = FindAliasAddress(src_addr);
- link = AddLink(src_addr, dst_addr, alias_addr,
- NO_SRC_PORT, NO_DEST_PORT, 0,
- proto);
- }
-
- return (link);
-}
-
-
-struct alias_link *
-FindUdpTcpIn(struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_short dst_port,
- u_short alias_port,
- u_char proto,
- int create)
-{
- int link_type;
- struct alias_link *link;
-
- switch (proto)
- {
- case IPPROTO_UDP:
- link_type = LINK_UDP;
- break;
- case IPPROTO_TCP:
- link_type = LINK_TCP;
- break;
- default:
- return NULL;
- break;
- }
-
- link = FindLinkIn(dst_addr, alias_addr,
- dst_port, alias_port,
- link_type, create);
-
- if (link == NULL && create && !(packetAliasMode & PKT_ALIAS_DENY_INCOMING))
- {
- struct in_addr target_addr;
-
- target_addr = FindOriginalAddress(alias_addr);
- link = AddLink(target_addr, dst_addr, alias_addr,
- alias_port, dst_port, alias_port,
- link_type);
- }
-
- return(link);
-}
-
-
-struct alias_link *
-FindUdpTcpOut(struct in_addr src_addr,
- struct in_addr dst_addr,
- u_short src_port,
- u_short dst_port,
- u_char proto,
- int create)
-{
- int link_type;
- struct alias_link *link;
-
- switch (proto)
- {
- case IPPROTO_UDP:
- link_type = LINK_UDP;
- break;
- case IPPROTO_TCP:
- link_type = LINK_TCP;
- break;
- default:
- return NULL;
- break;
- }
-
- link = FindLinkOut(src_addr, dst_addr, src_port, dst_port, link_type, create);
-
- if (link == NULL && create)
- {
- struct in_addr alias_addr;
-
- alias_addr = FindAliasAddress(src_addr);
- link = AddLink(src_addr, dst_addr, alias_addr,
- src_port, dst_port, GET_ALIAS_PORT,
- link_type);
- }
-
- return(link);
-}
-
-
-struct alias_link *
-AddPptp(struct in_addr src_addr,
- struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_int16_t src_call_id)
-{
- struct alias_link *link;
-
- link = AddLink(src_addr, dst_addr, alias_addr,
- src_call_id, 0, GET_ALIAS_PORT,
- LINK_PPTP);
-
- return (link);
-}
-
-
-struct alias_link *
-FindPptpOutByCallId(struct in_addr src_addr,
- struct in_addr dst_addr,
- u_int16_t src_call_id)
-{
- u_int i;
- struct alias_link *link;
-
- i = StartPointOut(src_addr, dst_addr, 0, 0, LINK_PPTP);
- LIST_FOREACH(link, &linkTableOut[i], list_out)
- if (link->link_type == LINK_PPTP &&
- link->src_addr.s_addr == src_addr.s_addr &&
- link->dst_addr.s_addr == dst_addr.s_addr &&
- link->src_port == src_call_id)
- break;
-
- return (link);
-}
-
-
-struct alias_link *
-FindPptpOutByPeerCallId(struct in_addr src_addr,
- struct in_addr dst_addr,
- u_int16_t dst_call_id)
-{
- u_int i;
- struct alias_link *link;
-
- i = StartPointOut(src_addr, dst_addr, 0, 0, LINK_PPTP);
- LIST_FOREACH(link, &linkTableOut[i], list_out)
- if (link->link_type == LINK_PPTP &&
- link->src_addr.s_addr == src_addr.s_addr &&
- link->dst_addr.s_addr == dst_addr.s_addr &&
- link->dst_port == dst_call_id)
- break;
-
- return (link);
-}
-
-
-struct alias_link *
-FindPptpInByCallId(struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_int16_t dst_call_id)
-{
- u_int i;
- struct alias_link *link;
-
- i = StartPointIn(alias_addr, 0, LINK_PPTP);
- LIST_FOREACH(link, &linkTableIn[i], list_in)
- if (link->link_type == LINK_PPTP &&
- link->dst_addr.s_addr == dst_addr.s_addr &&
- link->alias_addr.s_addr == alias_addr.s_addr &&
- link->dst_port == dst_call_id)
- break;
-
- return (link);
-}
-
-
-struct alias_link *
-FindPptpInByPeerCallId(struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_int16_t alias_call_id)
-{
- struct alias_link *link;
-
- link = FindLinkIn(dst_addr, alias_addr,
- 0/* any */, alias_call_id,
- LINK_PPTP, 0);
-
-
- return (link);
-}
-
-
-struct alias_link *
-FindRtspOut(struct in_addr src_addr,
- struct in_addr dst_addr,
- u_short src_port,
- u_short alias_port,
- u_char proto)
-{
- int link_type;
- struct alias_link *link;
-
- switch (proto)
- {
- case IPPROTO_UDP:
- link_type = LINK_UDP;
- break;
- case IPPROTO_TCP:
- link_type = LINK_TCP;
- break;
- default:
- return NULL;
- break;
- }
-
- link = FindLinkOut(src_addr, dst_addr, src_port, 0, link_type, 1);
-
- if (link == NULL)
- {
- struct in_addr alias_addr;
-
- alias_addr = FindAliasAddress(src_addr);
- link = AddLink(src_addr, dst_addr, alias_addr,
- src_port, 0, alias_port,
- link_type);
- }
-
- return(link);
-}
-
-
-struct in_addr
-FindOriginalAddress(struct in_addr alias_addr)
-{
- struct alias_link *link;
-
- link = FindLinkIn(nullAddress, alias_addr,
- 0, 0, LINK_ADDR, 0);
- if (link == NULL)
- {
- newDefaultLink = 1;
- if (targetAddress.s_addr == INADDR_ANY)
- return alias_addr;
- else if (targetAddress.s_addr == INADDR_NONE)
- return aliasAddress;
- else
- return targetAddress;
- }
- else
- {
- if (link->server != NULL) { /* LSNAT link */
- struct in_addr src_addr;
-
- src_addr = link->server->addr;
- link->server = link->server->next;
- return (src_addr);
- } else if (link->src_addr.s_addr == INADDR_ANY)
- return aliasAddress;
- else
- return link->src_addr;
- }
-}
-
-
-struct in_addr
-FindAliasAddress(struct in_addr original_addr)
-{
- struct alias_link *link;
-
- link = FindLinkOut(original_addr, nullAddress,
- 0, 0, LINK_ADDR, 0);
- if (link == NULL)
- {
- return aliasAddress;
- }
- else
- {
- if (link->alias_addr.s_addr == INADDR_ANY)
- return aliasAddress;
- else
- return link->alias_addr;
- }
-}
-
-
-/* External routines for getting or changing link data
- (external to alias_db.c, but internal to alias*.c)
-
- SetFragmentData(), GetFragmentData()
- SetFragmentPtr(), GetFragmentPtr()
- SetStateIn(), SetStateOut(), GetStateIn(), GetStateOut()
- GetOriginalAddress(), GetDestAddress(), GetAliasAddress()
- GetOriginalPort(), GetAliasPort()
- SetAckModified(), GetAckModified()
- GetDeltaAckIn(), GetDeltaSeqOut(), AddSeq()
- SetProtocolFlags(), GetProtocolFlags()
- SetDestCallId()
-*/
-
-
-void
-SetFragmentAddr(struct alias_link *link, struct in_addr src_addr)
-{
- link->data.frag_addr = src_addr;
-}
-
-
-void
-GetFragmentAddr(struct alias_link *link, struct in_addr *src_addr)
-{
- *src_addr = link->data.frag_addr;
-}
-
-
-void
-SetFragmentPtr(struct alias_link *link, char *fptr)
-{
- link->data.frag_ptr = fptr;
-}
-
-
-void
-GetFragmentPtr(struct alias_link *link, char **fptr)
-{
- *fptr = link->data.frag_ptr;
-}
-
-
-void
-SetStateIn(struct alias_link *link, int state)
-{
- /* TCP input state */
- switch (state) {
- case ALIAS_TCP_STATE_DISCONNECTED:
- if (link->data.tcp->state.out != ALIAS_TCP_STATE_CONNECTED)
- link->expire_time = TCP_EXPIRE_DEAD;
- else
- link->expire_time = TCP_EXPIRE_SINGLEDEAD;
- break;
- case ALIAS_TCP_STATE_CONNECTED:
- if (link->data.tcp->state.out == ALIAS_TCP_STATE_CONNECTED)
- link->expire_time = TCP_EXPIRE_CONNECTED;
- break;
- default:
- abort();
- }
- link->data.tcp->state.in = state;
-}
-
-
-void
-SetStateOut(struct alias_link *link, int state)
-{
- /* TCP output state */
- switch (state) {
- case ALIAS_TCP_STATE_DISCONNECTED:
- if (link->data.tcp->state.in != ALIAS_TCP_STATE_CONNECTED)
- link->expire_time = TCP_EXPIRE_DEAD;
- else
- link->expire_time = TCP_EXPIRE_SINGLEDEAD;
- break;
- case ALIAS_TCP_STATE_CONNECTED:
- if (link->data.tcp->state.in == ALIAS_TCP_STATE_CONNECTED)
- link->expire_time = TCP_EXPIRE_CONNECTED;
- break;
- default:
- abort();
- }
- link->data.tcp->state.out = state;
-}
-
-
-int
-GetStateIn(struct alias_link *link)
-{
- /* TCP input state */
- return link->data.tcp->state.in;
-}
-
-
-int
-GetStateOut(struct alias_link *link)
-{
- /* TCP output state */
- return link->data.tcp->state.out;
-}
-
-
-struct in_addr
-GetOriginalAddress(struct alias_link *link)
-{
- if (link->src_addr.s_addr == INADDR_ANY)
- return aliasAddress;
- else
- return(link->src_addr);
-}
-
-
-struct in_addr
-GetDestAddress(struct alias_link *link)
-{
- return(link->dst_addr);
-}
-
-
-struct in_addr
-GetAliasAddress(struct alias_link *link)
-{
- if (link->alias_addr.s_addr == INADDR_ANY)
- return aliasAddress;
- else
- return link->alias_addr;
-}
-
-
-struct in_addr
-GetDefaultAliasAddress()
-{
- return aliasAddress;
-}
-
-
-void
-SetDefaultAliasAddress(struct in_addr alias_addr)
-{
- aliasAddress = alias_addr;
-}
-
-
-u_short
-GetOriginalPort(struct alias_link *link)
-{
- return(link->src_port);
-}
-
-
-u_short
-GetAliasPort(struct alias_link *link)
-{
- return(link->alias_port);
-}
-
-#ifndef NO_FW_PUNCH
-static u_short
-GetDestPort(struct alias_link *link)
-{
- return(link->dst_port);
-}
-#endif
-
-void
-SetAckModified(struct alias_link *link)
-{
-/* Indicate that ACK numbers have been modified in a TCP connection */
- link->data.tcp->state.ack_modified = 1;
-}
-
-
-struct in_addr
-GetProxyAddress(struct alias_link *link)
-{
- return link->proxy_addr;
-}
-
-
-void
-SetProxyAddress(struct alias_link *link, struct in_addr addr)
-{
- link->proxy_addr = addr;
-}
-
-
-u_short
-GetProxyPort(struct alias_link *link)
-{
- return link->proxy_port;
-}
-
-
-void
-SetProxyPort(struct alias_link *link, u_short port)
-{
- link->proxy_port = port;
-}
-
-
-int
-GetAckModified(struct alias_link *link)
-{
-/* See if ACK numbers have been modified */
- return link->data.tcp->state.ack_modified;
-}
-
-
-int
-GetDeltaAckIn(struct ip *pip, struct alias_link *link)
-{
-/*
-Find out how much the ACK number has been altered for an incoming
-TCP packet. To do this, a circular list of ACK numbers where the TCP
-packet size was altered is searched.
-*/
-
- int i;
- struct tcphdr *tc;
- int delta, ack_diff_min;
- u_long ack;
-
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
- ack = tc->th_ack;
-
- delta = 0;
- ack_diff_min = -1;
- for (i=0; i<N_LINK_TCP_DATA; i++)
- {
- struct ack_data_record x;
-
- x = link->data.tcp->ack[i];
- if (x.active == 1)
- {
- int ack_diff;
-
- ack_diff = SeqDiff(x.ack_new, ack);
- if (ack_diff >= 0)
- {
- if (ack_diff_min >= 0)
- {
- if (ack_diff < ack_diff_min)
- {
- delta = x.delta;
- ack_diff_min = ack_diff;
- }
- }
- else
- {
- delta = x.delta;
- ack_diff_min = ack_diff;
- }
- }
- }
- }
- return (delta);
-}
-
-
-int
-GetDeltaSeqOut(struct ip *pip, struct alias_link *link)
-{
-/*
-Find out how much the sequence number has been altered for an outgoing
-TCP packet. To do this, a circular list of ACK numbers where the TCP
-packet size was altered is searched.
-*/
-
- int i;
- struct tcphdr *tc;
- int delta, seq_diff_min;
- u_long seq;
-
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
- seq = tc->th_seq;
-
- delta = 0;
- seq_diff_min = -1;
- for (i=0; i<N_LINK_TCP_DATA; i++)
- {
- struct ack_data_record x;
-
- x = link->data.tcp->ack[i];
- if (x.active == 1)
- {
- int seq_diff;
-
- seq_diff = SeqDiff(x.ack_old, seq);
- if (seq_diff >= 0)
- {
- if (seq_diff_min >= 0)
- {
- if (seq_diff < seq_diff_min)
- {
- delta = x.delta;
- seq_diff_min = seq_diff;
- }
- }
- else
- {
- delta = x.delta;
- seq_diff_min = seq_diff;
- }
- }
- }
- }
- return (delta);
-}
-
-
-void
-AddSeq(struct ip *pip, struct alias_link *link, int delta)
-{
-/*
-When a TCP packet has been altered in length, save this
-information in a circular list. If enough packets have
-been altered, then this list will begin to overwrite itself.
-*/
-
- struct tcphdr *tc;
- struct ack_data_record x;
- int hlen, tlen, dlen;
- int i;
-
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
-
- hlen = (pip->ip_hl + tc->th_off) << 2;
- tlen = ntohs(pip->ip_len);
- dlen = tlen - hlen;
-
- x.ack_old = htonl(ntohl(tc->th_seq) + dlen);
- x.ack_new = htonl(ntohl(tc->th_seq) + dlen + delta);
- x.delta = delta;
- x.active = 1;
-
- i = link->data.tcp->state.index;
- link->data.tcp->ack[i] = x;
-
- i++;
- if (i == N_LINK_TCP_DATA)
- link->data.tcp->state.index = 0;
- else
- link->data.tcp->state.index = i;
-}
-
-void
-SetExpire(struct alias_link *link, int expire)
-{
- if (expire == 0)
- {
- link->flags &= ~LINK_PERMANENT;
- DeleteLink(link);
- }
- else if (expire == -1)
- {
- link->flags |= LINK_PERMANENT;
- }
- else if (expire > 0)
- {
- link->expire_time = expire;
- }
- else
- {
-#ifdef DEBUG
- fprintf(stderr, "PacketAlias/SetExpire(): ");
- fprintf(stderr, "error in expire parameter\n");
-#endif
- }
-}
-
-void
-ClearCheckNewLink(void)
-{
- newDefaultLink = 0;
-}
-
-void
-SetProtocolFlags(struct alias_link *link, int pflags)
-{
-
- link->pflags = pflags;;
-}
-
-int
-GetProtocolFlags(struct alias_link *link)
-{
-
- return (link->pflags);
-}
-
-void
-SetDestCallId(struct alias_link *link, u_int16_t cid)
-{
-
- deleteAllLinks = 1;
- link = ReLink(link, link->src_addr, link->dst_addr, link->alias_addr,
- link->src_port, cid, link->alias_port, link->link_type);
- deleteAllLinks = 0;
-}
-
-
-/* Miscellaneous Functions
-
- HouseKeeping()
- InitPacketAliasLog()
- UninitPacketAliasLog()
-*/
-
-/*
- Whenever an outgoing or incoming packet is handled, HouseKeeping()
- is called to find and remove timed-out aliasing links. Logic exists
- to sweep through the entire table and linked list structure
- every 60 seconds.
-
- (prototype in alias_local.h)
-*/
-
-void
-HouseKeeping(void)
-{
- int i, n, n100;
- struct timeval tv;
- struct timezone tz;
-
- /*
- * Save system time (seconds) in global variable timeStamp for
- * use by other functions. This is done so as not to unnecessarily
- * waste timeline by making system calls.
- */
- gettimeofday(&tv, &tz);
- timeStamp = tv.tv_sec;
-
- /* Compute number of spokes (output table link chains) to cover */
- n100 = LINK_TABLE_OUT_SIZE * 100 + houseKeepingResidual;
- n100 *= timeStamp - lastCleanupTime;
- n100 /= ALIAS_CLEANUP_INTERVAL_SECS;
-
- n = n100/100;
-
- /* Handle different cases */
- if (n > ALIAS_CLEANUP_MAX_SPOKES)
- {
- n = ALIAS_CLEANUP_MAX_SPOKES;
- lastCleanupTime = timeStamp;
- houseKeepingResidual = 0;
-
- for (i=0; i<n; i++)
- IncrementalCleanup();
- }
- else if (n > 0)
- {
- lastCleanupTime = timeStamp;
- houseKeepingResidual = n100 - 100*n;
-
- for (i=0; i<n; i++)
- IncrementalCleanup();
- }
- else if (n < 0)
- {
-#ifdef DEBUG
- fprintf(stderr, "PacketAlias/HouseKeeping(): ");
- fprintf(stderr, "something unexpected in time values\n");
-#endif
- lastCleanupTime = timeStamp;
- houseKeepingResidual = 0;
- }
-}
-
-
-/* Init the log file and enable logging */
-static void
-InitPacketAliasLog(void)
-{
- if ((~packetAliasMode & PKT_ALIAS_LOG)
- && (monitorFile = fopen("/var/log/alias.log", "w")))
- {
- packetAliasMode |= PKT_ALIAS_LOG;
- fprintf(monitorFile,
- "PacketAlias/InitPacketAliasLog: Packet alias logging enabled.\n");
- }
-}
-
-
-/* Close the log-file and disable logging. */
-static void
-UninitPacketAliasLog(void)
-{
- if (monitorFile) {
- fclose(monitorFile);
- monitorFile = NULL;
- }
- packetAliasMode &= ~PKT_ALIAS_LOG;
-}
-
-
-
-
-
-
-/* Outside world interfaces
-
--- "outside world" means other than alias*.c routines --
-
- PacketAliasRedirectPort()
- PacketAliasAddServer()
- PacketAliasRedirectProto()
- PacketAliasRedirectAddr()
- PacketAliasRedirectDelete()
- PacketAliasSetAddress()
- PacketAliasInit()
- PacketAliasUninit()
- PacketAliasSetMode()
-
-(prototypes in alias.h)
-*/
-
-/* Redirection from a specific public addr:port to a
- private addr:port */
-struct alias_link *
-PacketAliasRedirectPort(struct in_addr src_addr, u_short src_port,
- struct in_addr dst_addr, u_short dst_port,
- struct in_addr alias_addr, u_short alias_port,
- u_char proto)
-{
- int link_type;
- struct alias_link *link;
-
- switch(proto)
- {
- case IPPROTO_UDP:
- link_type = LINK_UDP;
- break;
- case IPPROTO_TCP:
- link_type = LINK_TCP;
- break;
- default:
-#ifdef DEBUG
- fprintf(stderr, "PacketAliasRedirectPort(): ");
- fprintf(stderr, "only TCP and UDP protocols allowed\n");
-#endif
- return NULL;
- }
-
- link = AddLink(src_addr, dst_addr, alias_addr,
- src_port, dst_port, alias_port,
- link_type);
-
- if (link != NULL)
- {
- link->flags |= LINK_PERMANENT;
- }
-#ifdef DEBUG
- else
- {
- fprintf(stderr, "PacketAliasRedirectPort(): "
- "call to AddLink() failed\n");
- }
-#endif
-
- return link;
-}
-
-/* Add server to the pool of servers */
-int
-PacketAliasAddServer(struct alias_link *link, struct in_addr addr, u_short port)
-{
- struct server *server;
-
- server = malloc(sizeof(struct server));
-
- if (server != NULL) {
- struct server *head;
-
- server->addr = addr;
- server->port = port;
-
- head = link->server;
- if (head == NULL)
- server->next = server;
- else {
- struct server *s;
-
- for (s = head; s->next != head; s = s->next);
- s->next = server;
- server->next = head;
- }
- link->server = server;
- return (0);
- } else
- return (-1);
-}
-
-/* Redirect packets of a given IP protocol from a specific
- public address to a private address */
-struct alias_link *
-PacketAliasRedirectProto(struct in_addr src_addr,
- struct in_addr dst_addr,
- struct in_addr alias_addr,
- u_char proto)
-{
- struct alias_link *link;
-
- link = AddLink(src_addr, dst_addr, alias_addr,
- NO_SRC_PORT, NO_DEST_PORT, 0,
- proto);
-
- if (link != NULL)
- {
- link->flags |= LINK_PERMANENT;
- }
-#ifdef DEBUG
- else
- {
- fprintf(stderr, "PacketAliasRedirectProto(): "
- "call to AddLink() failed\n");
- }
-#endif
-
- return link;
-}
-
-/* Static address translation */
-struct alias_link *
-PacketAliasRedirectAddr(struct in_addr src_addr,
- struct in_addr alias_addr)
-{
- struct alias_link *link;
-
- link = AddLink(src_addr, nullAddress, alias_addr,
- 0, 0, 0,
- LINK_ADDR);
-
- if (link != NULL)
- {
- link->flags |= LINK_PERMANENT;
- }
-#ifdef DEBUG
- else
- {
- fprintf(stderr, "PacketAliasRedirectAddr(): "
- "call to AddLink() failed\n");
- }
-#endif
-
- return link;
-}
-
-
-void
-PacketAliasRedirectDelete(struct alias_link *link)
-{
-/* This is a dangerous function to put in the API,
- because an invalid pointer can crash the program. */
-
- deleteAllLinks = 1;
- DeleteLink(link);
- deleteAllLinks = 0;
-}
-
-
-void
-PacketAliasSetAddress(struct in_addr addr)
-{
- if (packetAliasMode & PKT_ALIAS_RESET_ON_ADDR_CHANGE
- && aliasAddress.s_addr != addr.s_addr)
- CleanupAliasData();
-
- aliasAddress = addr;
-}
-
-
-void
-PacketAliasSetTarget(struct in_addr target_addr)
-{
- targetAddress = target_addr;
-}
-
-
-void
-PacketAliasInit(void)
-{
- int i;
- struct timeval tv;
- struct timezone tz;
- static int firstCall = 1;
-
- if (firstCall == 1)
- {
- gettimeofday(&tv, &tz);
- timeStamp = tv.tv_sec;
- lastCleanupTime = tv.tv_sec;
- houseKeepingResidual = 0;
-
- for (i=0; i<LINK_TABLE_OUT_SIZE; i++)
- LIST_INIT(&linkTableOut[i]);
- for (i=0; i<LINK_TABLE_IN_SIZE; i++)
- LIST_INIT(&linkTableIn[i]);
-
- atexit(PacketAliasUninit);
- firstCall = 0;
- }
- else
- {
- deleteAllLinks = 1;
- CleanupAliasData();
- deleteAllLinks = 0;
- }
-
- aliasAddress.s_addr = INADDR_ANY;
- targetAddress.s_addr = INADDR_ANY;
-
- icmpLinkCount = 0;
- udpLinkCount = 0;
- tcpLinkCount = 0;
- pptpLinkCount = 0;
- protoLinkCount = 0;
- fragmentIdLinkCount = 0;
- fragmentPtrLinkCount = 0;
- sockCount = 0;
-
- cleanupIndex =0;
-
- packetAliasMode = PKT_ALIAS_SAME_PORTS
- | PKT_ALIAS_USE_SOCKETS
- | PKT_ALIAS_RESET_ON_ADDR_CHANGE;
-}
-
-void
-PacketAliasUninit(void) {
- deleteAllLinks = 1;
- CleanupAliasData();
- deleteAllLinks = 0;
- UninitPacketAliasLog();
-#ifndef NO_FW_PUNCH
- UninitPunchFW();
-#endif
-}
-
-
-/* Change mode for some operations */
-unsigned int
-PacketAliasSetMode(
- unsigned int flags, /* Which state to bring flags to */
- unsigned int mask /* Mask of which flags to affect (use 0 to do a
- probe for flag values) */
-)
-{
-/* Enable logging? */
- if (flags & mask & PKT_ALIAS_LOG)
- {
- InitPacketAliasLog(); /* Do the enable */
- } else
-/* _Disable_ logging? */
- if (~flags & mask & PKT_ALIAS_LOG) {
- UninitPacketAliasLog();
- }
-
-#ifndef NO_FW_PUNCH
-/* Start punching holes in the firewall? */
- if (flags & mask & PKT_ALIAS_PUNCH_FW) {
- InitPunchFW();
- } else
-/* Stop punching holes in the firewall? */
- if (~flags & mask & PKT_ALIAS_PUNCH_FW) {
- UninitPunchFW();
- }
-#endif
-
-/* Other flags can be set/cleared without special action */
- packetAliasMode = (flags & mask) | (packetAliasMode & ~mask);
- return packetAliasMode;
-}
-
-
-int
-PacketAliasCheckNewLink(void)
-{
- return newDefaultLink;
-}
-
-
-#ifndef NO_FW_PUNCH
-
-/*****************
- Code to support firewall punching. This shouldn't really be in this
- file, but making variables global is evil too.
- ****************/
-
-#ifndef IPFW2
-#define IPFW2 1 /* use new ipfw code */
-#endif
-
-/* Firewall include files */
-#include <net/if.h>
-#include <netinet/ip_fw.h>
-#include <string.h>
-#include <err.h>
-
-#if IPFW2 /* support for new firewall code */
-/*
- * helper function, updates the pointer to cmd with the length
- * of the current command, and also cleans up the first word of
- * the new command in case it has been clobbered before.
- */
-static ipfw_insn *
-next_cmd(ipfw_insn *cmd)
-{
- cmd += F_LEN(cmd);
- bzero(cmd, sizeof(*cmd));
- return cmd;
-}
-
-/*
- * A function to fill simple commands of size 1.
- * Existing flags are preserved.
- */
-static ipfw_insn *
-fill_cmd(ipfw_insn *cmd, enum ipfw_opcodes opcode, int size,
- int flags, u_int16_t arg)
-{
- cmd->opcode = opcode;
- cmd->len = ((cmd->len | flags) & (F_NOT | F_OR)) | (size & F_LEN_MASK);
- cmd->arg1 = arg;
- return next_cmd(cmd);
-}
-
-static ipfw_insn *
-fill_ip(ipfw_insn *cmd1, enum ipfw_opcodes opcode, u_int32_t addr)
-{
- ipfw_insn_ip *cmd = (ipfw_insn_ip *)cmd1;
-
- cmd->addr.s_addr = addr;
- return fill_cmd(cmd1, opcode, F_INSN_SIZE(ipfw_insn_u32), 0, 0);
-}
-
-static ipfw_insn *
-fill_one_port(ipfw_insn *cmd1, enum ipfw_opcodes opcode, u_int16_t port)
-{
- ipfw_insn_u16 *cmd = (ipfw_insn_u16 *)cmd1;
-
- cmd->ports[0] = cmd->ports[1] = port;
- return fill_cmd(cmd1, opcode, F_INSN_SIZE(ipfw_insn_u16), 0, 0);
-}
-
-static int
-fill_rule(void *buf, int bufsize, int rulenum,
- enum ipfw_opcodes action, int proto,
- struct in_addr sa, u_int16_t sp, struct in_addr da, u_int16_t dp)
-{
- struct ip_fw *rule = (struct ip_fw *)buf;
- ipfw_insn *cmd = (ipfw_insn *)rule->cmd;
-
- bzero(buf, bufsize);
- rule->rulenum = rulenum;
-
- cmd = fill_cmd(cmd, O_PROTO, F_INSN_SIZE(ipfw_insn), 0, proto);
- cmd = fill_ip(cmd, O_IP_SRC, sa.s_addr);
- cmd = fill_one_port(cmd, O_IP_SRCPORT, sp);
- cmd = fill_ip(cmd, O_IP_DST, da.s_addr);
- cmd = fill_one_port(cmd, O_IP_DSTPORT, dp);
-
- rule->act_ofs = (u_int32_t *)cmd - (u_int32_t *)rule->cmd;
- cmd = fill_cmd(cmd, action, F_INSN_SIZE(ipfw_insn), 0, 0);
-
- rule->cmd_len = (u_int32_t *)cmd - (u_int32_t *)rule->cmd;
-
- return ((void *)cmd - buf);
-}
-#endif /* IPFW2 */
-
-static void ClearAllFWHoles(void);
-
-static int fireWallBaseNum; /* The first firewall entry free for our use */
-static int fireWallNumNums; /* How many entries can we use? */
-static int fireWallActiveNum; /* Which entry did we last use? */
-static char *fireWallField; /* bool array for entries */
-
-#define fw_setfield(field, num) \
-do { \
- (field)[(num) - fireWallBaseNum] = 1; \
-} /*lint -save -e717 */ while(0) /*lint -restore */
-#define fw_clrfield(field, num) \
-do { \
- (field)[(num) - fireWallBaseNum] = 0; \
-} /*lint -save -e717 */ while(0) /*lint -restore */
-#define fw_tstfield(field, num) ((field)[(num) - fireWallBaseNum])
-
-static void
-InitPunchFW(void) {
- fireWallField = malloc(fireWallNumNums);
- if (fireWallField) {
- memset(fireWallField, 0, fireWallNumNums);
- if (fireWallFD < 0) {
- fireWallFD = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
- }
- ClearAllFWHoles();
- fireWallActiveNum = fireWallBaseNum;
- }
-}
-
-static void
-UninitPunchFW(void) {
- ClearAllFWHoles();
- if (fireWallFD >= 0)
- close(fireWallFD);
- fireWallFD = -1;
- if (fireWallField)
- free(fireWallField);
- fireWallField = NULL;
- packetAliasMode &= ~PKT_ALIAS_PUNCH_FW;
-}
-
-/* Make a certain link go through the firewall */
-void
-PunchFWHole(struct alias_link *link) {
- int r; /* Result code */
- struct ip_fw rule; /* On-the-fly built rule */
- int fwhole; /* Where to punch hole */
-
-/* Don't do anything unless we are asked to */
- if ( !(packetAliasMode & PKT_ALIAS_PUNCH_FW) ||
- fireWallFD < 0 ||
- link->link_type != LINK_TCP)
- return;
-
- memset(&rule, 0, sizeof rule);
-
-/** Build rule **/
-
- /* Find empty slot */
- for (fwhole = fireWallActiveNum;
- fwhole < fireWallBaseNum + fireWallNumNums &&
- fw_tstfield(fireWallField, fwhole);
- fwhole++)
- ;
- if (fwhole == fireWallBaseNum + fireWallNumNums) {
- for (fwhole = fireWallBaseNum;
- fwhole < fireWallActiveNum &&
- fw_tstfield(fireWallField, fwhole);
- fwhole++)
- ;
- if (fwhole == fireWallActiveNum) {
- /* No rule point empty - we can't punch more holes. */
- fireWallActiveNum = fireWallBaseNum;
-#ifdef DEBUG
- fprintf(stderr, "libalias: Unable to create firewall hole!\n");
-#endif
- return;
- }
- }
- /* Start next search at next position */
- fireWallActiveNum = fwhole+1;
-
- /*
- * generate two rules of the form
- *
- * add fwhole accept tcp from OAddr OPort to DAddr DPort
- * add fwhole accept tcp from DAddr DPort to OAddr OPort
- */
-#if IPFW2
- if (GetOriginalPort(link) != 0 && GetDestPort(link) != 0) {
- u_int32_t rulebuf[255];
- int i;
-
- i = fill_rule(rulebuf, sizeof(rulebuf), fwhole,
- O_ACCEPT, IPPROTO_TCP,
- GetOriginalAddress(link), ntohs(GetOriginalPort(link)),
- GetDestAddress(link), ntohs(GetDestPort(link)) );
- r = setsockopt(fireWallFD, IPPROTO_IP, IP_FW_ADD, rulebuf, i);
- if (r)
- err(1, "alias punch inbound(1) setsockopt(IP_FW_ADD)");
-
- i = fill_rule(rulebuf, sizeof(rulebuf), fwhole,
- O_ACCEPT, IPPROTO_TCP,
- GetDestAddress(link), ntohs(GetDestPort(link)),
- GetOriginalAddress(link), ntohs(GetOriginalPort(link)) );
- r = setsockopt(fireWallFD, IPPROTO_IP, IP_FW_ADD, rulebuf, i);
- if (r)
- err(1, "alias punch inbound(2) setsockopt(IP_FW_ADD)");
- }
-#else /* !IPFW2, old code to generate ipfw rule */
-
- /* Build generic part of the two rules */
- rule.fw_number = fwhole;
- IP_FW_SETNSRCP(&rule, 1); /* Number of source ports. */
- IP_FW_SETNDSTP(&rule, 1); /* Number of destination ports. */
- rule.fw_flg = IP_FW_F_ACCEPT | IP_FW_F_IN | IP_FW_F_OUT;
- rule.fw_prot = IPPROTO_TCP;
- rule.fw_smsk.s_addr = INADDR_BROADCAST;
- rule.fw_dmsk.s_addr = INADDR_BROADCAST;
-
- /* Build and apply specific part of the rules */
- rule.fw_src = GetOriginalAddress(link);
- rule.fw_dst = GetDestAddress(link);
- rule.fw_uar.fw_pts[0] = ntohs(GetOriginalPort(link));
- rule.fw_uar.fw_pts[1] = ntohs(GetDestPort(link));
-
- /* Skip non-bound links - XXX should not be strictly necessary,
- but seems to leave hole if not done. Leak of non-bound links?
- (Code should be left even if the problem is fixed - it is a
- clear optimization) */
- if (rule.fw_uar.fw_pts[0] != 0 && rule.fw_uar.fw_pts[1] != 0) {
- r = setsockopt(fireWallFD, IPPROTO_IP, IP_FW_ADD, &rule, sizeof rule);
-#ifdef DEBUG
- if (r)
- err(1, "alias punch inbound(1) setsockopt(IP_FW_ADD)");
-#endif
- rule.fw_src = GetDestAddress(link);
- rule.fw_dst = GetOriginalAddress(link);
- rule.fw_uar.fw_pts[0] = ntohs(GetDestPort(link));
- rule.fw_uar.fw_pts[1] = ntohs(GetOriginalPort(link));
- r = setsockopt(fireWallFD, IPPROTO_IP, IP_FW_ADD, &rule, sizeof rule);
-#ifdef DEBUG
- if (r)
- err(1, "alias punch inbound(2) setsockopt(IP_FW_ADD)");
-#endif
- }
-#endif /* !IPFW2 */
-/* Indicate hole applied */
- link->data.tcp->fwhole = fwhole;
- fw_setfield(fireWallField, fwhole);
-}
-
-/* Remove a hole in a firewall associated with a particular alias
- link. Calling this too often is harmless. */
-static void
-ClearFWHole(struct alias_link *link) {
- if (link->link_type == LINK_TCP) {
- int fwhole = link->data.tcp->fwhole; /* Where is the firewall hole? */
- struct ip_fw rule;
-
- if (fwhole < 0)
- return;
-
- memset(&rule, 0, sizeof rule); /* useless for ipfw2 */
-#if IPFW2
- while (!setsockopt(fireWallFD, IPPROTO_IP, IP_FW_DEL,
- &fwhole, sizeof fwhole))
- ;
-#else /* !IPFW2 */
- rule.fw_number = fwhole;
- while (!setsockopt(fireWallFD, IPPROTO_IP, IP_FW_DEL,
- &rule, sizeof rule))
- ;
-#endif /* !IPFW2 */
- fw_clrfield(fireWallField, fwhole);
- link->data.tcp->fwhole = -1;
- }
-}
-
-/* Clear out the entire range dedicated to firewall holes. */
-static void
-ClearAllFWHoles(void) {
- struct ip_fw rule; /* On-the-fly built rule */
- int i;
-
- if (fireWallFD < 0)
- return;
-
- memset(&rule, 0, sizeof rule);
- for (i = fireWallBaseNum; i < fireWallBaseNum + fireWallNumNums; i++) {
-#if IPFW2
- int r = i;
- while (!setsockopt(fireWallFD, IPPROTO_IP, IP_FW_DEL, &r, sizeof r))
- ;
-#else /* !IPFW2 */
- rule.fw_number = i;
- while (!setsockopt(fireWallFD, IPPROTO_IP, IP_FW_DEL, &rule, sizeof rule))
- ;
-#endif /* !IPFW2 */
- }
- memset(fireWallField, 0, fireWallNumNums);
-}
-#endif
-
-void
-PacketAliasSetFWBase(unsigned int base, unsigned int num) {
-#ifndef NO_FW_PUNCH
- fireWallBaseNum = base;
- fireWallNumNums = num;
-#endif
-}
diff --git a/sys/netinet/libalias/alias_ftp.c b/sys/netinet/libalias/alias_ftp.c
deleted file mode 100644
index efc78c734530..000000000000
--- a/sys/netinet/libalias/alias_ftp.c
+++ /dev/null
@@ -1,583 +0,0 @@
-/*-
- * Copyright (c) 2001 Charles Mott <cm@linktel.net>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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$");
-
-/*
- Alias_ftp.c performs special processing for FTP sessions under
- TCP. Specifically, when a PORT/EPRT command from the client
- side or 227/229 reply from the server is sent, it is intercepted
- and modified. The address is changed to the gateway machine
- and an aliasing port is used.
-
- For this routine to work, the message must fit entirely into a
- single TCP packet. This is typically the case, but exceptions
- can easily be envisioned under the actual specifications.
-
- Probably the most troubling aspect of the approach taken here is
- that the new message will typically be a different length, and
- this causes a certain amount of bookkeeping to keep track of the
- changes of sequence and acknowledgment numbers, since the client
- machine is totally unaware of the modification to the TCP stream.
-
-
- References: RFC 959, RFC 2428.
-
- Initial version: August, 1996 (cjm)
-
- Version 1.6
- Brian Somers and Martin Renters identified an IP checksum
- error for modified IP packets.
-
- Version 1.7: January 9, 1996 (cjm)
- Differential checksum computation for change
- in IP packet length.
-
- Version 2.1: May, 1997 (cjm)
- Very minor changes to conform with
- local/global/function naming conventions
- within the packet aliasing module.
-
- Version 3.1: May, 2000 (eds)
- Add support for passive mode, alias the 227 replies.
-
- See HISTORY file for record of revisions.
-*/
-
-/* Includes */
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
-
-#include "alias_local.h"
-
-#define FTP_CONTROL_PORT_NUMBER 21
-#define MAX_MESSAGE_SIZE 128
-
-/* FTP protocol flags. */
-#define WAIT_CRLF 0x01
-
-enum ftp_message_type {
- FTP_PORT_COMMAND,
- FTP_EPRT_COMMAND,
- FTP_227_REPLY,
- FTP_229_REPLY,
- FTP_UNKNOWN_MESSAGE
-};
-
-static int ParseFtpPortCommand(char *, int);
-static int ParseFtpEprtCommand(char *, int);
-static int ParseFtp227Reply(char *, int);
-static int ParseFtp229Reply(char *, int);
-static void NewFtpMessage(struct ip *, struct alias_link *, int, int);
-
-static struct in_addr true_addr; /* in network byte order. */
-static u_short true_port; /* in host byte order. */
-
-void
-AliasHandleFtpOut(
-struct ip *pip, /* IP packet to examine/patch */
-struct alias_link *link, /* The link to go through (aliased port) */
-int maxpacketsize /* The maximum size this packet can grow to (including headers) */)
-{
- int hlen, tlen, dlen, pflags;
- char *sptr;
- struct tcphdr *tc;
- int ftp_message_type;
-
-/* Calculate data length of TCP packet */
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
- hlen = (pip->ip_hl + tc->th_off) << 2;
- tlen = ntohs(pip->ip_len);
- dlen = tlen - hlen;
-
-/* Place string pointer and beginning of data */
- sptr = (char *) pip;
- sptr += hlen;
-
-/*
- * Check that data length is not too long and previous message was
- * properly terminated with CRLF.
- */
- pflags = GetProtocolFlags(link);
- if (dlen <= MAX_MESSAGE_SIZE && !(pflags & WAIT_CRLF)) {
- ftp_message_type = FTP_UNKNOWN_MESSAGE;
-
- if (ntohs(tc->th_dport) == FTP_CONTROL_PORT_NUMBER) {
-/*
- * When aliasing a client, check for the PORT/EPRT command.
- */
- if (ParseFtpPortCommand(sptr, dlen))
- ftp_message_type = FTP_PORT_COMMAND;
- else if (ParseFtpEprtCommand(sptr, dlen))
- ftp_message_type = FTP_EPRT_COMMAND;
- } else {
-/*
- * When aliasing a server, check for the 227/229 reply.
- */
- if (ParseFtp227Reply(sptr, dlen))
- ftp_message_type = FTP_227_REPLY;
- else if (ParseFtp229Reply(sptr, dlen)) {
- ftp_message_type = FTP_229_REPLY;
- true_addr.s_addr = pip->ip_src.s_addr;
- }
- }
-
- if (ftp_message_type != FTP_UNKNOWN_MESSAGE)
- NewFtpMessage(pip, link, maxpacketsize, ftp_message_type);
- }
-
-/* Track the msgs which are CRLF term'd for PORT/PASV FW breach */
-
- if (dlen) { /* only if there's data */
- sptr = (char *) pip; /* start over at beginning */
- tlen = ntohs(pip->ip_len); /* recalc tlen, pkt may have grown */
- if (sptr[tlen-2] == '\r' && sptr[tlen-1] == '\n')
- pflags &= ~WAIT_CRLF;
- else
- pflags |= WAIT_CRLF;
- SetProtocolFlags(link, pflags);
- }
-}
-
-static int
-ParseFtpPortCommand(char *sptr, int dlen)
-{
- char ch;
- int i, state;
- u_int32_t addr;
- u_short port;
- u_int8_t octet;
-
- /* Format: "PORT A,D,D,R,PO,RT". */
-
- /* Return if data length is too short. */
- if (dlen < 18)
- return 0;
-
- addr = port = octet = 0;
- state = -4;
- for (i = 0; i < dlen; i++) {
- ch = sptr[i];
- switch (state) {
- case -4: if (ch == 'P') state++; else return 0; break;
- case -3: if (ch == 'O') state++; else return 0; break;
- case -2: if (ch == 'R') state++; else return 0; break;
- case -1: if (ch == 'T') state++; else return 0; break;
-
- case 0:
- if (isspace(ch))
- break;
- else
- state++;
- case 1: case 3: case 5: case 7: case 9: case 11:
- if (isdigit(ch)) {
- octet = ch - '0';
- state++;
- } else
- return 0;
- break;
- case 2: case 4: case 6: case 8:
- if (isdigit(ch))
- octet = 10 * octet + ch - '0';
- else if (ch == ',') {
- addr = (addr << 8) + octet;
- state++;
- } else
- return 0;
- break;
- case 10: case 12:
- if (isdigit(ch))
- octet = 10 * octet + ch - '0';
- else if (ch == ',' || state == 12) {
- port = (port << 8) + octet;
- state++;
- } else
- return 0;
- break;
- }
- }
-
- if (state == 13) {
- true_addr.s_addr = htonl(addr);
- true_port = port;
- return 1;
- } else
- return 0;
-}
-
-static int
-ParseFtpEprtCommand(char *sptr, int dlen)
-{
- char ch, delim;
- int i, state;
- u_int32_t addr;
- u_short port;
- u_int8_t octet;
-
- /* Format: "EPRT |1|A.D.D.R|PORT|". */
-
- /* Return if data length is too short. */
- if (dlen < 18)
- return 0;
-
- addr = port = octet = 0;
- delim = '|'; /* XXX gcc -Wuninitialized */
- state = -4;
- for (i = 0; i < dlen; i++) {
- ch = sptr[i];
- switch (state)
- {
- case -4: if (ch == 'E') state++; else return 0; break;
- case -3: if (ch == 'P') state++; else return 0; break;
- case -2: if (ch == 'R') state++; else return 0; break;
- case -1: if (ch == 'T') state++; else return 0; break;
-
- case 0:
- if (!isspace(ch)) {
- delim = ch;
- state++;
- }
- break;
- case 1:
- if (ch == '1') /* IPv4 address */
- state++;
- else
- return 0;
- break;
- case 2:
- if (ch == delim)
- state++;
- else
- return 0;
- break;
- case 3: case 5: case 7: case 9:
- if (isdigit(ch)) {
- octet = ch - '0';
- state++;
- } else
- return 0;
- break;
- case 4: case 6: case 8: case 10:
- if (isdigit(ch))
- octet = 10 * octet + ch - '0';
- else if (ch == '.' || state == 10) {
- addr = (addr << 8) + octet;
- state++;
- } else
- return 0;
- break;
- case 11:
- if (isdigit(ch)) {
- port = ch - '0';
- state++;
- } else
- return 0;
- break;
- case 12:
- if (isdigit(ch))
- port = 10 * port + ch - '0';
- else if (ch == delim)
- state++;
- else
- return 0;
- break;
- }
- }
-
- if (state == 13) {
- true_addr.s_addr = htonl(addr);
- true_port = port;
- return 1;
- } else
- return 0;
-}
-
-static int
-ParseFtp227Reply(char *sptr, int dlen)
-{
- char ch;
- int i, state;
- u_int32_t addr;
- u_short port;
- u_int8_t octet;
-
- /* Format: "227 Entering Passive Mode (A,D,D,R,PO,RT)" */
-
- /* Return if data length is too short. */
- if (dlen < 17)
- return 0;
-
- addr = port = octet = 0;
-
- state = -3;
- for (i = 0; i < dlen; i++) {
- ch = sptr[i];
- switch (state)
- {
- case -3: if (ch == '2') state++; else return 0; break;
- case -2: if (ch == '2') state++; else return 0; break;
- case -1: if (ch == '7') state++; else return 0; break;
-
- case 0:
- if (ch == '(')
- state++;
- break;
- case 1: case 3: case 5: case 7: case 9: case 11:
- if (isdigit(ch)) {
- octet = ch - '0';
- state++;
- } else
- return 0;
- break;
- case 2: case 4: case 6: case 8:
- if (isdigit(ch))
- octet = 10 * octet + ch - '0';
- else if (ch == ',') {
- addr = (addr << 8) + octet;
- state++;
- } else
- return 0;
- break;
- case 10: case 12:
- if (isdigit(ch))
- octet = 10 * octet + ch - '0';
- else if (ch == ',' || (state == 12 && ch == ')')) {
- port = (port << 8) + octet;
- state++;
- } else
- return 0;
- break;
- }
- }
-
- if (state == 13) {
- true_port = port;
- true_addr.s_addr = htonl(addr);
- return 1;
- } else
- return 0;
-}
-
-static int
-ParseFtp229Reply(char *sptr, int dlen)
-{
- char ch, delim;
- int i, state;
- u_short port;
-
- /* Format: "229 Entering Extended Passive Mode (|||PORT|)" */
-
- /* Return if data length is too short. */
- if (dlen < 11)
- return 0;
-
- port = 0;
- delim = '|'; /* XXX gcc -Wuninitialized */
-
- state = -3;
- for (i = 0; i < dlen; i++) {
- ch = sptr[i];
- switch (state)
- {
- case -3: if (ch == '2') state++; else return 0; break;
- case -2: if (ch == '2') state++; else return 0; break;
- case -1: if (ch == '9') state++; else return 0; break;
-
- case 0:
- if (ch == '(')
- state++;
- break;
- case 1:
- delim = ch;
- state++;
- break;
- case 2: case 3:
- if (ch == delim)
- state++;
- else
- return 0;
- break;
- case 4:
- if (isdigit(ch)) {
- port = ch - '0';
- state++;
- } else
- return 0;
- break;
- case 5:
- if (isdigit(ch))
- port = 10 * port + ch - '0';
- else if (ch == delim)
- state++;
- else
- return 0;
- break;
- case 6:
- if (ch == ')')
- state++;
- else
- return 0;
- break;
- }
- }
-
- if (state == 7) {
- true_port = port;
- return 1;
- } else
- return 0;
-}
-
-static void
-NewFtpMessage(struct ip *pip,
- struct alias_link *link,
- int maxpacketsize,
- int ftp_message_type)
-{
- struct alias_link *ftp_link;
-
-/* Security checks. */
- if (pip->ip_src.s_addr != true_addr.s_addr)
- return;
-
- if (true_port < IPPORT_RESERVED)
- return;
-
-/* Establish link to address and port found in FTP control message. */
- ftp_link = FindUdpTcpOut(true_addr, GetDestAddress(link),
- htons(true_port), 0, IPPROTO_TCP, 1);
-
- if (ftp_link != NULL)
- {
- int slen, hlen, tlen, dlen;
- struct tcphdr *tc;
-
-#ifndef NO_FW_PUNCH
- /* Punch hole in firewall */
- PunchFWHole(ftp_link);
-#endif
-
-/* Calculate data length of TCP packet */
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
- hlen = (pip->ip_hl + tc->th_off) << 2;
- tlen = ntohs(pip->ip_len);
- dlen = tlen - hlen;
-
-/* Create new FTP message. */
- {
- char stemp[MAX_MESSAGE_SIZE + 1];
- char *sptr;
- u_short alias_port;
- u_char *ptr;
- int a1, a2, a3, a4, p1, p2;
- struct in_addr alias_address;
-
-/* Decompose alias address into quad format */
- alias_address = GetAliasAddress(link);
- ptr = (u_char *) &alias_address.s_addr;
- a1 = *ptr++; a2=*ptr++; a3=*ptr++; a4=*ptr;
-
- alias_port = GetAliasPort(ftp_link);
-
- switch (ftp_message_type)
- {
- case FTP_PORT_COMMAND:
- case FTP_227_REPLY:
- /* Decompose alias port into pair format. */
- ptr = (char *) &alias_port;
- p1 = *ptr++; p2=*ptr;
-
- if (ftp_message_type == FTP_PORT_COMMAND) {
- /* Generate PORT command string. */
- sprintf(stemp, "PORT %d,%d,%d,%d,%d,%d\r\n",
- a1,a2,a3,a4,p1,p2);
- } else {
- /* Generate 227 reply string. */
- sprintf(stemp,
- "227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n",
- a1,a2,a3,a4,p1,p2);
- }
- break;
- case FTP_EPRT_COMMAND:
- /* Generate EPRT command string. */
- sprintf(stemp, "EPRT |1|%d.%d.%d.%d|%d|\r\n",
- a1,a2,a3,a4,ntohs(alias_port));
- break;
- case FTP_229_REPLY:
- /* Generate 229 reply string. */
- sprintf(stemp, "229 Entering Extended Passive Mode (|||%d|)\r\n",
- ntohs(alias_port));
- break;
- }
-
-/* Save string length for IP header modification */
- slen = strlen(stemp);
-
-/* Copy modified buffer into IP packet. */
- sptr = (char *) pip; sptr += hlen;
- strncpy(sptr, stemp, maxpacketsize-hlen);
- }
-
-/* Save information regarding modified seq and ack numbers */
- {
- int delta;
-
- SetAckModified(link);
- delta = GetDeltaSeqOut(pip, link);
- AddSeq(pip, link, delta+slen-dlen);
- }
-
-/* Revise IP header */
- {
- u_short new_len;
-
- new_len = htons(hlen + slen);
- DifferentialChecksum(&pip->ip_sum,
- &new_len,
- &pip->ip_len,
- 1);
- pip->ip_len = new_len;
- }
-
-/* Compute TCP checksum for revised packet */
- tc->th_sum = 0;
- tc->th_sum = TcpChecksum(pip);
- }
- else
- {
-#ifdef DEBUG
- fprintf(stderr,
- "PacketAlias/HandleFtpOut: Cannot allocate FTP data port\n");
-#endif
- }
-}
diff --git a/sys/netinet/libalias/alias_irc.c b/sys/netinet/libalias/alias_irc.c
deleted file mode 100644
index 02a2bb23693e..000000000000
--- a/sys/netinet/libalias/alias_irc.c
+++ /dev/null
@@ -1,357 +0,0 @@
-/*-
- * Copyright (c) 2001 Charles Mott <cm@linktel.net>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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$");
-
-/* Alias_irc.c intercepts packages contain IRC CTCP commands, and
- changes DCC commands to export a port on the aliasing host instead
- of an aliased host.
-
- For this routine to work, the DCC command must fit entirely into a
- single TCP packet. This will usually happen, but is not
- guaranteed.
-
- The interception is likely to change the length of the packet.
- The handling of this is copied more-or-less verbatim from
- ftp_alias.c
-
- Initial version: Eivind Eklund <perhaps@yes.no> (ee) 97-01-29
-
- Version 2.1: May, 1997 (cjm)
- Very minor changes to conform with
- local/global/function naming conventions
- withing the packet alising module.
-*/
-
-/* Includes */
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
-#include <limits.h>
-
-#include "alias_local.h"
-
-/* Local defines */
-#define DBprintf(a)
-
-
-void
-AliasHandleIrcOut(struct ip *pip, /* IP packet to examine */
- struct alias_link *link, /* Which link are we on? */
- int maxsize /* Maximum size of IP packet including headers */
- )
-{
- int hlen, tlen, dlen;
- struct in_addr true_addr;
- u_short true_port;
- char *sptr;
- struct tcphdr *tc;
- int i; /* Iterator through the source */
-
-/* Calculate data length of TCP packet */
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
- hlen = (pip->ip_hl + tc->th_off) << 2;
- tlen = ntohs(pip->ip_len);
- dlen = tlen - hlen;
-
- /* Return if data length is too short - assume an entire PRIVMSG in each packet. */
- if (dlen<sizeof(":A!a@n.n PRIVMSG A :aDCC 1 1a")-1)
- return;
-
-/* Place string pointer at beginning of data */
- sptr = (char *) pip;
- sptr += hlen;
- maxsize -= hlen; /* We're interested in maximum size of data, not packet */
-
- /* Search for a CTCP command [Note 1] */
- for( i=0; i<dlen; i++ ) {
- if(sptr[i]=='\001')
- goto lFOUND_CTCP;
- }
- return; /* No CTCP commands in */
- /* Handle CTCP commands - the buffer may have to be copied */
-lFOUND_CTCP:
- {
- char newpacket[65536]; /* Estimate of maximum packet size :) */
- int copyat = i; /* Same */
- int iCopy = 0; /* How much data have we written to copy-back string? */
- unsigned long org_addr; /* Original IP address */
- unsigned short org_port; /* Original source port address */
- lCTCP_START:
- if( i >= dlen || iCopy >= sizeof(newpacket) )
- goto lPACKET_DONE;
- newpacket[iCopy++] = sptr[i++]; /* Copy the CTCP start character */
- /* Start of a CTCP */
- if( i+4 >= dlen ) /* Too short for DCC */
- goto lBAD_CTCP;
- if( sptr[i+0] != 'D' )
- goto lBAD_CTCP;
- if( sptr[i+1] != 'C' )
- goto lBAD_CTCP;
- if( sptr[i+2] != 'C' )
- goto lBAD_CTCP;
- if( sptr[i+3] != ' ' )
- goto lBAD_CTCP;
- /* We have a DCC command - handle it! */
- i+= 4; /* Skip "DCC " */
- if( iCopy+4 > sizeof(newpacket) )
- goto lPACKET_DONE;
- newpacket[iCopy++] = 'D';
- newpacket[iCopy++] = 'C';
- newpacket[iCopy++] = 'C';
- newpacket[iCopy++] = ' ';
-
- DBprintf(("Found DCC\n"));
- /* Skip any extra spaces (should not occur according to
- protocol, but DCC breaks CTCP protocol anyway */
- while(sptr[i] == ' ') {
- if( ++i >= dlen) {
- DBprintf(("DCC packet terminated in just spaces\n"));
- goto lPACKET_DONE;
- }
- }
-
- DBprintf(("Transferring command...\n"));
- while(sptr[i] != ' ') {
- newpacket[iCopy++] = sptr[i];
- if( ++i >= dlen || iCopy >= sizeof(newpacket) ) {
- DBprintf(("DCC packet terminated during command\n"));
- goto lPACKET_DONE;
- }
- }
- /* Copy _one_ space */
- if( i+1 < dlen && iCopy < sizeof(newpacket) )
- newpacket[iCopy++] = sptr[i++];
-
- DBprintf(("Done command - removing spaces\n"));
- /* Skip any extra spaces (should not occur according to
- protocol, but DCC breaks CTCP protocol anyway */
- while(sptr[i] == ' ') {
- if( ++i >= dlen ) {
- DBprintf(("DCC packet terminated in just spaces (post-command)\n"));
- goto lPACKET_DONE;
- }
- }
-
- DBprintf(("Transferring filename...\n"));
- while(sptr[i] != ' ') {
- newpacket[iCopy++] = sptr[i];
- if( ++i >= dlen || iCopy >= sizeof(newpacket) ) {
- DBprintf(("DCC packet terminated during filename\n"));
- goto lPACKET_DONE;
- }
- }
- /* Copy _one_ space */
- if( i+1 < dlen && iCopy < sizeof(newpacket) )
- newpacket[iCopy++] = sptr[i++];
-
- DBprintf(("Done filename - removing spaces\n"));
- /* Skip any extra spaces (should not occur according to
- protocol, but DCC breaks CTCP protocol anyway */
- while(sptr[i] == ' ') {
- if( ++i >= dlen ) {
- DBprintf(("DCC packet terminated in just spaces (post-filename)\n"));
- goto lPACKET_DONE;
- }
- }
-
- DBprintf(("Fetching IP address\n"));
- /* Fetch IP address */
- org_addr = 0;
- while(i<dlen && isdigit(sptr[i])) {
- if( org_addr > ULONG_MAX/10UL ) { /* Terminate on overflow */
- DBprintf(("DCC Address overflow (org_addr == 0x%08lx, next char %c\n", org_addr, sptr[i]));
- goto lBAD_CTCP;
- }
- org_addr *= 10;
- org_addr += sptr[i++]-'0';
- }
- DBprintf(("Skipping space\n"));
- if( i+1 >= dlen || sptr[i] != ' ' ) {
- DBprintf(("Overflow (%d >= %d) or bad character (%02x) terminating IP address\n", i+1, dlen, sptr[i]));
- goto lBAD_CTCP;
- }
- /* Skip any extra spaces (should not occur according to
- protocol, but DCC breaks CTCP protocol anyway, so we might
- as well play it safe */
- while(sptr[i] == ' ') {
- if( ++i >= dlen ) {
- DBprintf(("Packet failure - space overflow.\n"));
- goto lPACKET_DONE;
- }
- }
- DBprintf(("Fetching port number\n"));
- /* Fetch source port */
- org_port = 0;
- while(i<dlen && isdigit(sptr[i])) {
- if( org_port > 6554 ) { /* Terminate on overflow (65536/10 rounded up*/
- DBprintf(("DCC: port number overflow\n"));
- goto lBAD_CTCP;
- }
- org_port *= 10;
- org_port += sptr[i++]-'0';
- }
- /* Skip illegal addresses (or early termination) */
- if( i >= dlen || (sptr[i] != '\001' && sptr[i] != ' ') ) {
- DBprintf(("Bad port termination\n"));
- goto lBAD_CTCP;
- }
- DBprintf(("Got IP %lu and port %u\n", org_addr, (unsigned)org_port));
-
- /* We've got the address and port - now alias it */
- {
- struct alias_link *dcc_link;
- struct in_addr destaddr;
-
-
- true_port = htons(org_port);
- true_addr.s_addr = htonl(org_addr);
- destaddr.s_addr = 0;
-
- /* Sanity/Security checking */
- if (!org_addr || !org_port ||
- pip->ip_src.s_addr != true_addr.s_addr ||
- org_port < IPPORT_RESERVED)
- goto lBAD_CTCP;
-
- /* Steal the FTP_DATA_PORT - it doesn't really matter, and this
- would probably allow it through at least _some_
- firewalls. */
- dcc_link = FindUdpTcpOut(true_addr, destaddr,
- true_port, 0,
- IPPROTO_TCP, 1);
- DBprintf(("Got a DCC link\n"));
- if ( dcc_link ) {
- struct in_addr alias_address; /* Address from aliasing */
- u_short alias_port; /* Port given by aliasing */
- int n;
-
-#ifndef NO_FW_PUNCH
- /* Generate firewall hole as appropriate */
- PunchFWHole(dcc_link);
-#endif
-
- alias_address = GetAliasAddress(link);
- n = snprintf(&newpacket[iCopy],
- sizeof(newpacket)-iCopy,
- "%lu ", (u_long)htonl(alias_address.s_addr));
- if( n < 0 ) {
- DBprintf(("DCC packet construct failure.\n"));
- goto lBAD_CTCP;
- }
- if( (iCopy += n) >= sizeof(newpacket) ) { /* Truncated/fit exactly - bad news */
- DBprintf(("DCC constructed packet overflow.\n"));
- goto lBAD_CTCP;
- }
- alias_port = GetAliasPort(dcc_link);
- n = snprintf(&newpacket[iCopy],
- sizeof(newpacket)-iCopy,
- "%u", htons(alias_port) );
- if( n < 0 ) {
- DBprintf(("DCC packet construct failure.\n"));
- goto lBAD_CTCP;
- }
- iCopy += n;
- /* Done - truncated cases will be taken care of by lBAD_CTCP */
- DBprintf(("Aliased IP %lu and port %u\n", alias_address.s_addr, (unsigned)alias_port));
- }
- }
- /* An uninteresting CTCP - state entered right after '\001' has
- been pushed. Also used to copy the rest of a DCC, after IP
- address and port has been handled */
- lBAD_CTCP:
- for(; i<dlen && iCopy<sizeof(newpacket); i++,iCopy++) {
- newpacket[iCopy] = sptr[i]; /* Copy CTCP unchanged */
- if(sptr[i] == '\001') {
- goto lNORMAL_TEXT;
- }
- }
- goto lPACKET_DONE;
- /* Normal text */
- lNORMAL_TEXT:
- for(; i<dlen && iCopy<sizeof(newpacket); i++,iCopy++) {
- newpacket[iCopy] = sptr[i]; /* Copy CTCP unchanged */
- if(sptr[i] == '\001') {
- goto lCTCP_START;
- }
- }
- /* Handle the end of a packet */
- lPACKET_DONE:
- iCopy = iCopy > maxsize-copyat ? maxsize-copyat : iCopy;
- memcpy(sptr+copyat, newpacket, iCopy);
-
-/* Save information regarding modified seq and ack numbers */
- {
- int delta;
-
- SetAckModified(link);
- delta = GetDeltaSeqOut(pip, link);
- AddSeq(pip, link, delta+copyat+iCopy-dlen);
- }
-
- /* Revise IP header */
- {
- u_short new_len;
-
- new_len = htons(hlen + iCopy + copyat);
- DifferentialChecksum(&pip->ip_sum,
- &new_len,
- &pip->ip_len,
- 1);
- pip->ip_len = new_len;
- }
-
- /* Compute TCP checksum for revised packet */
- tc->th_sum = 0;
- tc->th_sum = TcpChecksum(pip);
- return;
- }
-}
-
-/* Notes:
- [Note 1]
- The initial search will most often fail; it could be replaced with a 32-bit specific search.
- Such a search would be done for 32-bit unsigned value V:
- V ^= 0x01010101; (Search is for null bytes)
- if( ((V-0x01010101)^V) & 0x80808080 ) {
- (found a null bytes which was a 01 byte)
- }
- To assert that the processor is 32-bits, do
- extern int ircdccar[32]; (32 bits)
- extern int ircdccar[CHAR_BIT*sizeof(unsigned int)];
- which will generate a type-error on all but 32-bit machines.
-
- [Note 2] This routine really ought to be replaced with one that
- creates a transparent proxy on the aliasing host, to allow arbitary
- changes in the TCP stream. This should not be too difficult given
- this base; I (ee) will try to do this some time later.
- */
diff --git a/sys/netinet/libalias/alias_local.h b/sys/netinet/libalias/alias_local.h
deleted file mode 100644
index 4428d2aa1941..000000000000
--- a/sys/netinet/libalias/alias_local.h
+++ /dev/null
@@ -1,229 +0,0 @@
-/*-
- * Copyright (c) 2001 Charles Mott <cm@linktel.net>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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$
- */
-
-/*
- * Alias_local.h contains the function prototypes for alias.c,
- * alias_db.c, alias_util.c and alias_ftp.c, alias_irc.c (as well
- * as any future add-ons). It also includes macros, globals and
- * struct definitions shared by more than one alias*.c file.
- *
- * This include file is intended to be used only within the aliasing
- * software. Outside world interfaces are defined in alias.h
- *
- * This software is placed into the public domain with no restrictions
- * on its distribution.
- *
- * Initial version: August, 1996 (cjm)
- *
- * <updated several times by original author and Eivind Eklund>
- */
-
-#ifndef _ALIAS_LOCAL_H_
-#define _ALIAS_LOCAL_H_
-
-/* Macros */
-
-/*
- * The following macro is used to update an
- * internet checksum. "delta" is a 32-bit
- * accumulation of all the changes to the
- * checksum (adding in new 16-bit words and
- * subtracting out old words), and "cksum"
- * is the checksum value to be updated.
- */
-#define ADJUST_CHECKSUM(acc, cksum) \
- do { \
- acc += cksum; \
- if (acc < 0) { \
- acc = -acc; \
- acc = (acc >> 16) + (acc & 0xffff); \
- acc += acc >> 16; \
- cksum = (u_short) ~acc; \
- } else { \
- acc = (acc >> 16) + (acc & 0xffff); \
- acc += acc >> 16; \
- cksum = (u_short) acc; \
- } \
- } while (0)
-
-/* Globals */
-
-extern int packetAliasMode;
-
-/* Prototypes */
-
-/* General utilities */
-u_short IpChecksum(struct ip *_pip);
-u_short TcpChecksum(struct ip *_pip);
-void DifferentialChecksum(u_short *_cksum, u_short *_new, u_short *_old,
- int _n);
-
-/* Internal data access */
-struct alias_link *
- FindIcmpIn(struct in_addr _dst_addr, struct in_addr _alias_addr,
- u_short _id_alias, int _create);
-struct alias_link *
- FindIcmpOut(struct in_addr _src_addr, struct in_addr _dst_addr,
- u_short _id, int _create);
-struct alias_link *
- FindFragmentIn1(struct in_addr _dst_addr, struct in_addr _alias_addr,
- u_short _ip_id);
-struct alias_link *
- FindFragmentIn2(struct in_addr _dst_addr, struct in_addr _alias_addr,
- u_short _ip_id);
-struct alias_link *
- AddFragmentPtrLink(struct in_addr _dst_addr, u_short _ip_id);
-struct alias_link *
- FindFragmentPtr(struct in_addr _dst_addr, u_short _ip_id);
-struct alias_link *
- FindProtoIn(struct in_addr _dst_addr, struct in_addr _alias_addr,
- u_char _proto);
-struct alias_link *
- FindProtoOut(struct in_addr _src_addr, struct in_addr _dst_addr,
- u_char _proto);
-struct alias_link *
- FindUdpTcpIn(struct in_addr _dst_addr, struct in_addr _alias_addr,
- u_short _dst_port, u_short _alias_port, u_char _proto, int _create);
-struct alias_link *
- FindUdpTcpOut(struct in_addr _src_addr, struct in_addr _dst_addr,
- u_short _src_port, u_short _dst_port, u_char _proto, int _create);
-struct alias_link *
- AddPptp(struct in_addr _src_addr, struct in_addr _dst_addr,
- struct in_addr _alias_addr, u_int16_t _src_call_id);
-struct alias_link *
- FindPptpOutByCallId(struct in_addr _src_addr,
- struct in_addr _dst_addr, u_int16_t _src_call_id);
-struct alias_link *
- FindPptpInByCallId(struct in_addr _dst_addr,
- struct in_addr _alias_addr, u_int16_t _dst_call_id);
-struct alias_link *
- FindPptpOutByPeerCallId(struct in_addr _src_addr,
- struct in_addr _dst_addr, u_int16_t _dst_call_id);
-struct alias_link *
- FindPptpInByPeerCallId(struct in_addr _dst_addr,
- struct in_addr _alias_addr, u_int16_t _alias_call_id);
-struct alias_link *
- FindRtspOut(struct in_addr _src_addr, struct in_addr _dst_addr,
- u_short _src_port, u_short _alias_port, u_char _proto);
-struct in_addr
- FindOriginalAddress(struct in_addr _alias_addr);
-struct in_addr
- FindAliasAddress(struct in_addr _original_addr);
-
-/* External data access/modification */
-int FindNewPortGroup(struct in_addr _dst_addr, struct in_addr _alias_addr,
- u_short _src_port, u_short _dst_port, u_short _port_count,
- u_char _proto, u_char _align);
-void GetFragmentAddr(struct alias_link *_link, struct in_addr *_src_addr);
-void SetFragmentAddr(struct alias_link *_link, struct in_addr _src_addr);
-void GetFragmentPtr(struct alias_link *_link, char **_fptr);
-void SetFragmentPtr(struct alias_link *_link, char *fptr);
-void SetStateIn(struct alias_link *_link, int _state);
-void SetStateOut(struct alias_link *_link, int _state);
-int GetStateIn(struct alias_link *_link);
-int GetStateOut(struct alias_link *_link);
-struct in_addr
- GetOriginalAddress(struct alias_link *_link);
-struct in_addr
- GetDestAddress(struct alias_link *_link);
-struct in_addr
- GetAliasAddress(struct alias_link *_link);
-struct in_addr
- GetDefaultAliasAddress(void);
-void SetDefaultAliasAddress(struct in_addr _alias_addr);
-u_short GetOriginalPort(struct alias_link *_link);
-u_short GetAliasPort(struct alias_link *_link);
-struct in_addr
- GetProxyAddress(struct alias_link *_link);
-void SetProxyAddress(struct alias_link *_link, struct in_addr _addr);
-u_short GetProxyPort(struct alias_link *_link);
-void SetProxyPort(struct alias_link *_link, u_short _port);
-void SetAckModified(struct alias_link *_link);
-int GetAckModified(struct alias_link *_link);
-int GetDeltaAckIn(struct ip *_pip, struct alias_link *_link);
-int GetDeltaSeqOut(struct ip *_pip, struct alias_link *_link);
-void AddSeq(struct ip *_pip, struct alias_link *_link, int _delta);
-void SetExpire(struct alias_link *_link, int _expire);
-void ClearCheckNewLink(void);
-void SetProtocolFlags(struct alias_link *_link, int _pflags);
-int GetProtocolFlags(struct alias_link *_link);
-void SetDestCallId(struct alias_link *_link, u_int16_t _cid);
-#ifndef NO_FW_PUNCH
-void PunchFWHole(struct alias_link *_link);
-#endif
-
-/* Housekeeping function */
-void HouseKeeping(void);
-
-/* Tcp specfic routines */
-/* lint -save -library Suppress flexelint warnings */
-
-/* FTP routines */
-void AliasHandleFtpOut(struct ip *_pip, struct alias_link *_link,
- int _maxpacketsize);
-
-/* IRC routines */
-void AliasHandleIrcOut(struct ip *_pip, struct alias_link *_link,
- int _maxsize);
-
-/* RTSP routines */
-void AliasHandleRtspOut(struct ip *_pip, struct alias_link *_link,
- int _maxpacketsize);
-
-/* PPTP routines */
-void AliasHandlePptpOut(struct ip *_pip, struct alias_link *_link);
-void AliasHandlePptpIn(struct ip *_pip, struct alias_link *_link);
-int AliasHandlePptpGreOut(struct ip *_pip);
-int AliasHandlePptpGreIn(struct ip *_pip);
-
-/* NetBIOS routines */
-int AliasHandleUdpNbt(struct ip *_pip, struct alias_link *_link,
- struct in_addr *_alias_address, u_short _alias_port);
-int AliasHandleUdpNbtNS(struct ip *_pip, struct alias_link *_link,
- struct in_addr *_alias_address, u_short *_alias_port,
- struct in_addr *_original_address, u_short *_original_port);
-
-/* CUSeeMe routines */
-void AliasHandleCUSeeMeOut(struct ip *_pip, struct alias_link *_link);
-void AliasHandleCUSeeMeIn(struct ip *_pip, struct in_addr _original_addr);
-
-/* Transparent proxy routines */
-int ProxyCheck(struct ip *_pip, struct in_addr *_proxy_server_addr,
- u_short *_proxy_server_port);
-void ProxyModify(struct alias_link *_link, struct ip *_pip,
- int _maxpacketsize, int _proxy_type);
-
-enum alias_tcp_state {
- ALIAS_TCP_STATE_NOT_CONNECTED,
- ALIAS_TCP_STATE_CONNECTED,
- ALIAS_TCP_STATE_DISCONNECTED
-};
-
-/*lint -restore */
-
-#endif /* !_ALIAS_LOCAL_H_ */
diff --git a/sys/netinet/libalias/alias_nbt.c b/sys/netinet/libalias/alias_nbt.c
deleted file mode 100644
index 508bf5197ee4..000000000000
--- a/sys/netinet/libalias/alias_nbt.c
+++ /dev/null
@@ -1,704 +0,0 @@
-/*-
- * Written by Atsushi Murai <amurai@spec.co.jp>
- * Copyright (c) 1998, System Planning and Engineering Co.
- * 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.
- * TODO:
- * oClean up.
- * oConsidering for word alignment for other platform.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- alias_nbt.c performs special processing for NetBios over TCP/IP
- sessions by UDP.
-
- Initial version: May, 1998 (Atsushi Murai <amurai@spec.co.jp>)
-
- See HISTORY file for record of revisions.
-*/
-
-/* Includes */
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netinet/ip.h>
-#include <netinet/udp.h>
-#include <netinet/tcp.h>
-
-#include "alias_local.h"
-
-typedef struct {
- struct in_addr oldaddr;
- u_short oldport;
- struct in_addr newaddr;
- u_short newport;
- u_short *uh_sum;
-} NBTArguments;
-
-typedef struct {
- unsigned char type;
- unsigned char flags;
- u_short id;
- struct in_addr source_ip;
- u_short source_port;
- u_short len;
- u_short offset;
-} NbtDataHeader;
-
-#define OpQuery 0
-#define OpUnknown 4
-#define OpRegist 5
-#define OpRelease 6
-#define OpWACK 7
-#define OpRefresh 8
-typedef struct {
- u_short nametrid;
- u_short dir:1, opcode:4, nmflags:7, rcode:4;
- u_short qdcount;
- u_short ancount;
- u_short nscount;
- u_short arcount;
-} NbtNSHeader;
-
-#define FMT_ERR 0x1
-#define SRV_ERR 0x2
-#define IMP_ERR 0x4
-#define RFS_ERR 0x5
-#define ACT_ERR 0x6
-#define CFT_ERR 0x7
-
-
-#ifdef DEBUG
-static void PrintRcode( u_char rcode ) {
-
- switch (rcode) {
- case FMT_ERR:
- printf("\nFormat Error.");
- case SRV_ERR:
- printf("\nSever failure.");
- case IMP_ERR:
- printf("\nUnsupported request error.\n");
- case RFS_ERR:
- printf("\nRefused error.\n");
- case ACT_ERR:
- printf("\nActive error.\n");
- case CFT_ERR:
- printf("\nName in conflict error.\n");
- default:
- printf("\n?%c?=%0x\n", '?', rcode );
-
- }
-}
-#endif
-
-
-/* Handling Name field */
-static u_char *AliasHandleName ( u_char *p, char *pmax ) {
-
- u_char *s;
- u_char c;
- int compress;
-
- /* Following length field */
-
- if (p == NULL || (char *)p >= pmax)
- return(NULL);
-
- if (*p & 0xc0 ) {
- p = p + 2;
- if ((char *)p > pmax)
- return(NULL);
- return ((u_char *)p);
- }
- while ( ( *p & 0x3f) != 0x00 ) {
- s = p + 1;
- if ( *p == 0x20 )
- compress = 1;
- else
- compress = 0;
-
- /* Get next length field */
- p = (u_char *)(p + (*p & 0x3f) + 1);
- if ((char *)p > pmax) {
- p = NULL;
- break;
- }
-#ifdef DEBUG
- printf(":");
-#endif
- while (s < p) {
- if ( compress == 1 ) {
- c = (u_char )(((((*s & 0x0f) << 4) | (*(s+1) & 0x0f)) - 0x11));
-#ifdef DEBUG
- if (isprint( c ) )
- printf("%c", c );
- else
- printf("<0x%02x>", c );
-#endif
- s +=2;
- } else {
-#ifdef DEBUG
- printf("%c", *s);
-#endif
- s++;
- }
- }
-#ifdef DEBUG
- printf(":");
-#endif
- fflush(stdout);
- }
-
- /* Set up to out of Name field */
- if (p == NULL || (char *)p >= pmax)
- p = NULL;
- else
- p++;
- return ((u_char *)p);
-}
-
-/*
- * NetBios Datagram Handler (IP/UDP)
- */
-#define DGM_DIRECT_UNIQ 0x10
-#define DGM_DIRECT_GROUP 0x11
-#define DGM_BROADCAST 0x12
-#define DGM_ERROR 0x13
-#define DGM_QUERY 0x14
-#define DGM_POSITIVE_RES 0x15
-#define DGM_NEGATIVE_RES 0x16
-
-int AliasHandleUdpNbt(
- struct ip *pip, /* IP packet to examine/patch */
- struct alias_link *link,
- struct in_addr *alias_address,
- u_short alias_port
-) {
- struct udphdr * uh;
- NbtDataHeader *ndh;
- u_char *p = NULL;
- char *pmax;
-
- /* Calculate data length of UDP packet */
- uh = (struct udphdr *) ((char *) pip + (pip->ip_hl << 2));
- pmax = (char *)uh + ntohs( uh->uh_ulen );
-
- ndh = (NbtDataHeader *)((char *)uh + (sizeof (struct udphdr)));
- if ((char *)(ndh + 1) > pmax)
- return(-1);
-#ifdef DEBUG
- printf("\nType=%02x,", ndh->type );
-#endif
- switch ( ndh->type ) {
- case DGM_DIRECT_UNIQ:
- case DGM_DIRECT_GROUP:
- case DGM_BROADCAST:
- p = (u_char *)ndh + 14;
- p = AliasHandleName ( p, pmax ); /* Source Name */
- p = AliasHandleName ( p, pmax ); /* Destination Name */
- break;
- case DGM_ERROR:
- p = (u_char *)ndh + 11;
- break;
- case DGM_QUERY:
- case DGM_POSITIVE_RES:
- case DGM_NEGATIVE_RES:
- p = (u_char *)ndh + 10;
- p = AliasHandleName ( p, pmax ); /* Destination Name */
- break;
- }
- if (p == NULL || (char *)p > pmax)
- p = NULL;
-#ifdef DEBUG
- printf("%s:%d-->", inet_ntoa(ndh->source_ip), ntohs(ndh->source_port) );
-#endif
- /* Doing an IP address and Port number Translation */
- if ( uh->uh_sum != 0 ) {
- int acc;
- u_short *sptr;
- acc = ndh->source_port;
- acc -= alias_port;
- sptr = (u_short *) &(ndh->source_ip);
- acc += *sptr++;
- acc += *sptr;
- sptr = (u_short *) alias_address;
- acc -= *sptr++;
- acc -= *sptr;
- ADJUST_CHECKSUM(acc, uh->uh_sum);
- }
- ndh->source_ip = *alias_address;
- ndh->source_port = alias_port;
-#ifdef DEBUG
- printf("%s:%d\n", inet_ntoa(ndh->source_ip), ntohs(ndh->source_port) );
- fflush(stdout);
-#endif
- return((p == NULL) ? -1 : 0);
-}
-/* Question Section */
-#define QS_TYPE_NB 0x0020
-#define QS_TYPE_NBSTAT 0x0021
-#define QS_CLAS_IN 0x0001
-typedef struct {
- u_short type; /* The type of Request */
- u_short class; /* The class of Request */
-} NBTNsQuestion;
-
-static u_char *
-AliasHandleQuestion(
- u_short count,
- NBTNsQuestion *q,
- char *pmax,
- NBTArguments *nbtarg)
-{
-
- while ( count != 0 ) {
- /* Name Filed */
- q = (NBTNsQuestion *)AliasHandleName((u_char *)q, pmax);
-
- if (q == NULL || (char *)(q + 1) > pmax) {
- q = NULL;
- break;
- }
-
- /* Type and Class filed */
- switch ( ntohs(q->type) ) {
- case QS_TYPE_NB:
- case QS_TYPE_NBSTAT:
- q= q+1;
- break;
- default:
-#ifdef DEBUG
- printf("\nUnknown Type on Question %0x\n", ntohs(q->type) );
-#endif
- break;
- }
- count--;
- }
-
- /* Set up to out of Question Section */
- return ((u_char *)q);
-}
-
-/* Resource Record */
-#define RR_TYPE_A 0x0001
-#define RR_TYPE_NS 0x0002
-#define RR_TYPE_NULL 0x000a
-#define RR_TYPE_NB 0x0020
-#define RR_TYPE_NBSTAT 0x0021
-#define RR_CLAS_IN 0x0001
-#define SizeOfNsResource 8
-typedef struct {
- u_short type;
- u_short class;
- unsigned int ttl;
- u_short rdlen;
-} NBTNsResource;
-
-#define SizeOfNsRNB 6
-typedef struct {
- u_short g:1, ont:2, resv:13;
- struct in_addr addr;
-} NBTNsRNB;
-
-static u_char *
-AliasHandleResourceNB(
- NBTNsResource *q,
- char *pmax,
- NBTArguments *nbtarg)
-{
- NBTNsRNB *nb;
- u_short bcount;
-
- if (q == NULL || (char *)(q + 1) > pmax)
- return(NULL);
- /* Check out a length */
- bcount = ntohs(q->rdlen);
-
- /* Forward to Resource NB position */
- nb = (NBTNsRNB *)((u_char *)q + SizeOfNsResource);
-
- /* Processing all in_addr array */
-#ifdef DEBUG
- printf("NB rec[%s", inet_ntoa(nbtarg->oldaddr));
- printf("->%s, %dbytes] ",inet_ntoa(nbtarg->newaddr ), bcount);
-#endif
- while ( nb != NULL && bcount != 0 ) {
- if ((char *)(nb + 1) > pmax) {
- nb = NULL;
- break;
- }
-#ifdef DEBUG
- printf("<%s>", inet_ntoa(nb->addr) );
-#endif
- if (!bcmp(&nbtarg->oldaddr,&nb->addr, sizeof(struct in_addr) ) ) {
- if ( *nbtarg->uh_sum != 0 ) {
- int acc;
- u_short *sptr;
-
- sptr = (u_short *) &(nb->addr);
- acc = *sptr++;
- acc += *sptr;
- sptr = (u_short *) &(nbtarg->newaddr);
- acc -= *sptr++;
- acc -= *sptr;
- ADJUST_CHECKSUM(acc, *nbtarg->uh_sum);
- }
-
- nb->addr = nbtarg->newaddr;
-#ifdef DEBUG
- printf("O");
-#endif
- }
-#ifdef DEBUG
- else {
- printf(".");
- }
-#endif
- nb=(NBTNsRNB *)((u_char *)nb + SizeOfNsRNB);
- bcount -= SizeOfNsRNB;
- }
- if (nb == NULL || (char *)(nb + 1) > pmax) {
- nb = NULL;
- }
-
- return ((u_char *)nb);
-}
-
-#define SizeOfResourceA 6
-typedef struct {
- struct in_addr addr;
-} NBTNsResourceA;
-
-static u_char *
-AliasHandleResourceA(
- NBTNsResource *q,
- char *pmax,
- NBTArguments *nbtarg)
-{
- NBTNsResourceA *a;
- u_short bcount;
-
- if (q == NULL || (char *)(q + 1) > pmax)
- return(NULL);
-
- /* Forward to Resource A position */
- a = (NBTNsResourceA *)( (u_char *)q + sizeof(NBTNsResource) );
-
- /* Check out of length */
- bcount = ntohs(q->rdlen);
-
- /* Processing all in_addr array */
-#ifdef DEBUG
- printf("Arec [%s", inet_ntoa(nbtarg->oldaddr));
- printf("->%s]",inet_ntoa(nbtarg->newaddr ));
-#endif
- while ( bcount != 0 ) {
- if (a == NULL || (char *)(a + 1) > pmax)
- return(NULL);
-#ifdef DEBUG
- printf("..%s", inet_ntoa(a->addr) );
-#endif
- if ( !bcmp(&nbtarg->oldaddr, &a->addr, sizeof(struct in_addr) ) ) {
- if ( *nbtarg->uh_sum != 0 ) {
- int acc;
- u_short *sptr;
-
- sptr = (u_short *) &(a->addr); /* Old */
- acc = *sptr++;
- acc += *sptr;
- sptr = (u_short *) &nbtarg->newaddr; /* New */
- acc -= *sptr++;
- acc -= *sptr;
- ADJUST_CHECKSUM(acc, *nbtarg->uh_sum);
- }
-
- a->addr = nbtarg->newaddr;
- }
- a++; /*XXXX*/
- bcount -= SizeOfResourceA;
- }
- if (a == NULL || (char *)(a + 1) > pmax)
- a = NULL;
- return ((u_char *)a);
-}
-
-typedef struct {
- u_short opcode:4, flags:8, resv:4;
-} NBTNsResourceNULL;
-
-static u_char *
-AliasHandleResourceNULL(
- NBTNsResource *q,
- char *pmax,
- NBTArguments *nbtarg)
-{
- NBTNsResourceNULL *n;
- u_short bcount;
-
- if (q == NULL || (char *)(q + 1) > pmax)
- return(NULL);
-
- /* Forward to Resource NULL position */
- n = (NBTNsResourceNULL *)( (u_char *)q + sizeof(NBTNsResource) );
-
- /* Check out of length */
- bcount = ntohs(q->rdlen);
-
- /* Processing all in_addr array */
- while ( bcount != 0 ) {
- if ((char *)(n + 1) > pmax) {
- n = NULL;
- break;
- }
- n++;
- bcount -= sizeof(NBTNsResourceNULL);
- }
- if ((char *)(n + 1) > pmax)
- n = NULL;
-
- return ((u_char *)n);
-}
-
-static u_char *
-AliasHandleResourceNS(
- NBTNsResource *q,
- char *pmax,
- NBTArguments *nbtarg)
-{
- NBTNsResourceNULL *n;
- u_short bcount;
-
- if (q == NULL || (char *)(q + 1) > pmax)
- return(NULL);
-
- /* Forward to Resource NULL position */
- n = (NBTNsResourceNULL *)( (u_char *)q + sizeof(NBTNsResource) );
-
- /* Check out of length */
- bcount = ntohs(q->rdlen);
-
- /* Resource Record Name Filed */
- q = (NBTNsResource *)AliasHandleName( (u_char *)n, pmax ); /* XXX */
-
- if (q == NULL || (char *)((u_char *)n + bcount) > pmax)
- return(NULL);
- else
- return ((u_char *)n + bcount);
-}
-
-typedef struct {
- u_short numnames;
-} NBTNsResourceNBSTAT;
-
-static u_char *
-AliasHandleResourceNBSTAT(
- NBTNsResource *q,
- char *pmax,
- NBTArguments *nbtarg)
-{
- NBTNsResourceNBSTAT *n;
- u_short bcount;
-
- if (q == NULL || (char *)(q + 1) > pmax)
- return(NULL);
-
- /* Forward to Resource NBSTAT position */
- n = (NBTNsResourceNBSTAT *)( (u_char *)q + sizeof(NBTNsResource) );
-
- /* Check out of length */
- bcount = ntohs(q->rdlen);
-
- if (q == NULL || (char *)((u_char *)n + bcount) > pmax)
- return(NULL);
- else
- return ((u_char *)n + bcount);
-}
-
-static u_char *
-AliasHandleResource(
- u_short count,
- NBTNsResource *q,
- char *pmax,
- NBTArguments
- *nbtarg)
-{
- while ( count != 0 ) {
- /* Resource Record Name Filed */
- q = (NBTNsResource *)AliasHandleName( (u_char *)q, pmax );
-
- if (q == NULL || (char *)(q + 1) > pmax)
- break;
-#ifdef DEBUG
- printf("type=%02x, count=%d\n", ntohs(q->type), count );
-#endif
-
- /* Type and Class filed */
- switch ( ntohs(q->type) ) {
- case RR_TYPE_NB:
- q = (NBTNsResource *)AliasHandleResourceNB(
- q,
- pmax,
- nbtarg
- );
- break;
- case RR_TYPE_A:
- q = (NBTNsResource *)AliasHandleResourceA(
- q,
- pmax,
- nbtarg
- );
- break;
- case RR_TYPE_NS:
- q = (NBTNsResource *)AliasHandleResourceNS(
- q,
- pmax,
- nbtarg
- );
- break;
- case RR_TYPE_NULL:
- q = (NBTNsResource *)AliasHandleResourceNULL(
- q,
- pmax,
- nbtarg
- );
- break;
- case RR_TYPE_NBSTAT:
- q = (NBTNsResource *)AliasHandleResourceNBSTAT(
- q,
- pmax,
- nbtarg
- );
- break;
- default:
-#ifdef DEBUG
- printf(
- "\nUnknown Type of Resource %0x\n",
- ntohs(q->type)
- );
-#endif
- break;
- }
- count--;
- }
- fflush(stdout);
- return ((u_char *)q);
-}
-
-int AliasHandleUdpNbtNS(
- struct ip *pip, /* IP packet to examine/patch */
- struct alias_link *link,
- struct in_addr *alias_address,
- u_short *alias_port,
- struct in_addr *original_address,
- u_short *original_port )
-{
- struct udphdr * uh;
- NbtNSHeader * nsh;
- u_char * p;
- char *pmax;
- NBTArguments nbtarg;
-
- /* Set up Common Parameter */
- nbtarg.oldaddr = *alias_address;
- nbtarg.oldport = *alias_port;
- nbtarg.newaddr = *original_address;
- nbtarg.newport = *original_port;
-
- /* Calculate data length of UDP packet */
- uh = (struct udphdr *) ((char *) pip + (pip->ip_hl << 2));
- nbtarg.uh_sum = &(uh->uh_sum);
- nsh = (NbtNSHeader *)((char *)uh + (sizeof(struct udphdr)));
- p = (u_char *)(nsh + 1);
- pmax = (char *)uh + ntohs( uh->uh_ulen );
-
- if ((char *)(nsh + 1) > pmax)
- return(-1);
-
-#ifdef DEBUG
- printf(" [%s] ID=%02x, op=%01x, flag=%02x, rcode=%01x, qd=%04x"
- ", an=%04x, ns=%04x, ar=%04x, [%d]-->",
- nsh->dir ? "Response": "Request",
- nsh->nametrid,
- nsh->opcode,
- nsh->nmflags,
- nsh->rcode,
- ntohs(nsh->qdcount),
- ntohs(nsh->ancount),
- ntohs(nsh->nscount),
- ntohs(nsh->arcount),
- (u_char *)p -(u_char *)nsh
- );
-#endif
-
- /* Question Entries */
- if (ntohs(nsh->qdcount) !=0 ) {
- p = AliasHandleQuestion(
- ntohs(nsh->qdcount),
- (NBTNsQuestion *)p,
- pmax,
- &nbtarg
- );
- }
-
- /* Answer Resource Records */
- if (ntohs(nsh->ancount) !=0 ) {
- p = AliasHandleResource(
- ntohs(nsh->ancount),
- (NBTNsResource *)p,
- pmax,
- &nbtarg
- );
- }
-
- /* Authority Resource Recodrs */
- if (ntohs(nsh->nscount) !=0 ) {
- p = AliasHandleResource(
- ntohs(nsh->nscount),
- (NBTNsResource *)p,
- pmax,
- &nbtarg
- );
- }
-
- /* Additional Resource Recodrs */
- if (ntohs(nsh->arcount) !=0 ) {
- p = AliasHandleResource(
- ntohs(nsh->arcount),
- (NBTNsResource *)p,
- pmax,
- &nbtarg
- );
- }
-
-#ifdef DEBUG
- PrintRcode(nsh->rcode);
-#endif
- return ((p == NULL) ? -1 : 0);
-}
diff --git a/sys/netinet/libalias/alias_pptp.c b/sys/netinet/libalias/alias_pptp.c
deleted file mode 100644
index 2d3d9acb3783..000000000000
--- a/sys/netinet/libalias/alias_pptp.c
+++ /dev/null
@@ -1,369 +0,0 @@
-/*
- * alias_pptp.c
- *
- * Copyright (c) 2000 Whistle Communications, Inc.
- * All rights reserved.
- *
- * Subject to the following obligations and disclaimer of warranty, use and
- * redistribution of this software, in source or object code forms, with or
- * without modifications are expressly permitted by Whistle Communications;
- * provided, however, that:
- * 1. Any and all reproductions of the source or object code must include the
- * copyright notice above and the following disclaimer of warranties; and
- * 2. No rights are granted, in any manner or form, to use Whistle
- * Communications, Inc. trademarks, including the mark "WHISTLE
- * COMMUNICATIONS" on advertising, endorsements, or otherwise except as
- * such appears in the above copyright notice or in the software.
- *
- * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
- * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
- * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
- * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
- * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
- * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
- * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
- * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
- * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
- * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
- * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * Author: Erik Salander <erik@whistle.com>
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- Alias_pptp.c performs special processing for PPTP sessions under TCP.
- Specifically, watch PPTP control messages and alias the Call ID or the
- Peer's Call ID in the appropriate messages. Note, PPTP requires
- "de-aliasing" of incoming packets, this is different than any other
- TCP applications that are currently (ie. FTP, IRC and RTSP) aliased.
-
- For Call IDs encountered for the first time, a PPTP alias link is created.
- The PPTP alias link uses the Call ID in place of the original port number.
- An alias Call ID is created.
-
- For this routine to work, the PPTP control messages must fit entirely
- into a single TCP packet. This is typically the case, but is not
- required by the spec.
-
- Unlike some of the other TCP applications that are aliased (ie. FTP,
- IRC and RTSP), the PPTP control messages that need to be aliased are
- guaranteed to remain the same length. The aliased Call ID is a fixed
- length field.
-
- Reference: RFC 2637
-
- Initial version: May, 2000 (eds)
-
-*/
-
-/* Includes */
-#include <sys/types.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
-
-#include <stdio.h>
-
-#include "alias_local.h"
-
-/*
- * PPTP definitions
- */
-
-struct grehdr /* Enhanced GRE header. */
-{
- u_int16_t gh_flags; /* Flags. */
- u_int16_t gh_protocol; /* Protocol type. */
- u_int16_t gh_length; /* Payload length. */
- u_int16_t gh_call_id; /* Call ID. */
- u_int32_t gh_seq_no; /* Sequence number (optional). */
- u_int32_t gh_ack_no; /* Acknowledgment number (optional). */
-};
-typedef struct grehdr GreHdr;
-
-/* The PPTP protocol ID used in the GRE 'proto' field. */
-#define PPTP_GRE_PROTO 0x880b
-
-/* Bits that must be set a certain way in all PPTP/GRE packets. */
-#define PPTP_INIT_VALUE ((0x2001 << 16) | PPTP_GRE_PROTO)
-#define PPTP_INIT_MASK 0xef7fffff
-
-#define PPTP_MAGIC 0x1a2b3c4d
-#define PPTP_CTRL_MSG_TYPE 1
-
-enum {
- PPTP_StartCtrlConnRequest = 1,
- PPTP_StartCtrlConnReply = 2,
- PPTP_StopCtrlConnRequest = 3,
- PPTP_StopCtrlConnReply = 4,
- PPTP_EchoRequest = 5,
- PPTP_EchoReply = 6,
- PPTP_OutCallRequest = 7,
- PPTP_OutCallReply = 8,
- PPTP_InCallRequest = 9,
- PPTP_InCallReply = 10,
- PPTP_InCallConn = 11,
- PPTP_CallClearRequest = 12,
- PPTP_CallDiscNotify = 13,
- PPTP_WanErrorNotify = 14,
- PPTP_SetLinkInfo = 15
-};
-
- /* Message structures */
- struct pptpMsgHead {
- u_int16_t length; /* total length */
- u_int16_t msgType; /* PPTP message type */
- u_int32_t magic; /* magic cookie */
- u_int16_t type; /* control message type */
- u_int16_t resv0; /* reserved */
- };
- typedef struct pptpMsgHead *PptpMsgHead;
-
- struct pptpCodes {
- u_int8_t resCode; /* Result Code */
- u_int8_t errCode; /* Error Code */
- };
- typedef struct pptpCodes *PptpCode;
-
- struct pptpCallIds {
- u_int16_t cid1; /* Call ID field #1 */
- u_int16_t cid2; /* Call ID field #2 */
- };
- typedef struct pptpCallIds *PptpCallId;
-
-static PptpCallId AliasVerifyPptp(struct ip *, u_int16_t *);
-
-
-void
-AliasHandlePptpOut(struct ip *pip, /* IP packet to examine/patch */
- struct alias_link *link) /* The PPTP control link */
-{
- struct alias_link *pptp_link;
- PptpCallId cptr;
- PptpCode codes;
- u_int16_t ctl_type; /* control message type */
- struct tcphdr *tc;
-
- /* Verify valid PPTP control message */
- if ((cptr = AliasVerifyPptp(pip, &ctl_type)) == NULL)
- return;
-
- /* Modify certain PPTP messages */
- switch (ctl_type) {
- case PPTP_OutCallRequest:
- case PPTP_OutCallReply:
- case PPTP_InCallRequest:
- case PPTP_InCallReply:
- /* Establish PPTP link for address and Call ID found in control message. */
- pptp_link = AddPptp(GetOriginalAddress(link), GetDestAddress(link),
- GetAliasAddress(link), cptr->cid1);
- break;
- case PPTP_CallClearRequest:
- case PPTP_CallDiscNotify:
- /* Find PPTP link for address and Call ID found in control message. */
- pptp_link = FindPptpOutByCallId(GetOriginalAddress(link),
- GetDestAddress(link),
- cptr->cid1);
- break;
- default:
- return;
- }
-
- if (pptp_link != NULL) {
- int accumulate = cptr->cid1;
-
- /* alias the Call Id */
- cptr->cid1 = GetAliasPort(pptp_link);
-
- /* Compute TCP checksum for revised packet */
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
- accumulate -= cptr->cid1;
- ADJUST_CHECKSUM(accumulate, tc->th_sum);
-
- switch (ctl_type) {
- case PPTP_OutCallReply:
- case PPTP_InCallReply:
- codes = (PptpCode)(cptr + 1);
- if (codes->resCode == 1) /* Connection established, */
- SetDestCallId(pptp_link, /* note the Peer's Call ID. */
- cptr->cid2);
- else
- SetExpire(pptp_link, 0); /* Connection refused. */
- break;
- case PPTP_CallDiscNotify: /* Connection closed. */
- SetExpire(pptp_link, 0);
- break;
- }
- }
-}
-
-void
-AliasHandlePptpIn(struct ip *pip, /* IP packet to examine/patch */
- struct alias_link *link) /* The PPTP control link */
-{
- struct alias_link *pptp_link;
- PptpCallId cptr;
- u_int16_t *pcall_id;
- u_int16_t ctl_type; /* control message type */
- struct tcphdr *tc;
-
- /* Verify valid PPTP control message */
- if ((cptr = AliasVerifyPptp(pip, &ctl_type)) == NULL)
- return;
-
- /* Modify certain PPTP messages */
- switch (ctl_type)
- {
- case PPTP_InCallConn:
- case PPTP_WanErrorNotify:
- case PPTP_SetLinkInfo:
- pcall_id = &cptr->cid1;
- break;
- case PPTP_OutCallReply:
- case PPTP_InCallReply:
- pcall_id = &cptr->cid2;
- break;
- case PPTP_CallDiscNotify: /* Connection closed. */
- pptp_link = FindPptpInByCallId(GetDestAddress(link),
- GetAliasAddress(link),
- cptr->cid1);
- if (pptp_link != NULL)
- SetExpire(pptp_link, 0);
- return;
- default:
- return;
- }
-
- /* Find PPTP link for address and Call ID found in PPTP Control Msg */
- pptp_link = FindPptpInByPeerCallId(GetDestAddress(link),
- GetAliasAddress(link),
- *pcall_id);
-
- if (pptp_link != NULL) {
- int accumulate = *pcall_id;
-
- /* De-alias the Peer's Call Id. */
- *pcall_id = GetOriginalPort(pptp_link);
-
- /* Compute TCP checksum for modified packet */
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
- accumulate -= *pcall_id;
- ADJUST_CHECKSUM(accumulate, tc->th_sum);
-
- if (ctl_type == PPTP_OutCallReply || ctl_type == PPTP_InCallReply) {
- PptpCode codes = (PptpCode)(cptr + 1);
-
- if (codes->resCode == 1) /* Connection established, */
- SetDestCallId(pptp_link, /* note the Call ID. */
- cptr->cid1);
- else
- SetExpire(pptp_link, 0); /* Connection refused. */
- }
- }
-}
-
-static PptpCallId
-AliasVerifyPptp(struct ip *pip, u_int16_t *ptype) /* IP packet to examine/patch */
-{
- int hlen, tlen, dlen;
- PptpMsgHead hptr;
- struct tcphdr *tc;
-
- /* Calculate some lengths */
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
- hlen = (pip->ip_hl + tc->th_off) << 2;
- tlen = ntohs(pip->ip_len);
- dlen = tlen - hlen;
-
- /* Verify data length */
- if (dlen < (sizeof(struct pptpMsgHead) + sizeof(struct pptpCallIds)))
- return(NULL);
-
- /* Move up to PPTP message header */
- hptr = (PptpMsgHead)(((char *) pip) + hlen);
-
- /* Return the control message type */
- *ptype = ntohs(hptr->type);
-
- /* Verify PPTP Control Message */
- if ((ntohs(hptr->msgType) != PPTP_CTRL_MSG_TYPE) ||
- (ntohl(hptr->magic) != PPTP_MAGIC))
- return(NULL);
-
- /* Verify data length. */
- if ((*ptype == PPTP_OutCallReply || *ptype == PPTP_InCallReply) &&
- (dlen < sizeof(struct pptpMsgHead) + sizeof(struct pptpCallIds) +
- sizeof(struct pptpCodes)))
- return (NULL);
- else
- return (PptpCallId)(hptr + 1);
-}
-
-
-int
-AliasHandlePptpGreOut(struct ip *pip)
-{
- GreHdr *gr;
- struct alias_link *link;
-
- gr = (GreHdr *)((char *)pip + (pip->ip_hl << 2));
-
- /* Check GRE header bits. */
- if ((ntohl(*((u_int32_t *)gr)) & PPTP_INIT_MASK) != PPTP_INIT_VALUE)
- return (-1);
-
- link = FindPptpOutByPeerCallId(pip->ip_src, pip->ip_dst, gr->gh_call_id);
- if (link != NULL) {
- struct in_addr alias_addr = GetAliasAddress(link);
-
- /* Change source IP address. */
- DifferentialChecksum(&pip->ip_sum,
- (u_short *)&alias_addr,
- (u_short *)&pip->ip_src,
- 2);
- pip->ip_src = alias_addr;
- }
-
- return (0);
-}
-
-
-int
-AliasHandlePptpGreIn(struct ip *pip)
-{
- GreHdr *gr;
- struct alias_link *link;
-
- gr = (GreHdr *)((char *)pip + (pip->ip_hl << 2));
-
- /* Check GRE header bits. */
- if ((ntohl(*((u_int32_t *)gr)) & PPTP_INIT_MASK) != PPTP_INIT_VALUE)
- return (-1);
-
- link = FindPptpInByPeerCallId(pip->ip_src, pip->ip_dst, gr->gh_call_id);
- if (link != NULL) {
- struct in_addr src_addr = GetOriginalAddress(link);
-
- /* De-alias the Peer's Call Id. */
- gr->gh_call_id = GetOriginalPort(link);
-
- /* Restore original IP address. */
- DifferentialChecksum(&pip->ip_sum,
- (u_short *)&src_addr,
- (u_short *)&pip->ip_dst,
- 2);
- pip->ip_dst = src_addr;
- }
-
- return (0);
-}
diff --git a/sys/netinet/libalias/alias_proxy.c b/sys/netinet/libalias/alias_proxy.c
deleted file mode 100644
index b9a979864fab..000000000000
--- a/sys/netinet/libalias/alias_proxy.c
+++ /dev/null
@@ -1,837 +0,0 @@
-/*-
- * Copyright (c) 2001 Charles Mott <cm@linktel.net>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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$");
-
-/* file: alias_proxy.c
-
- This file encapsulates special operations related to transparent
- proxy redirection. This is where packets with a particular destination,
- usually tcp port 80, are redirected to a proxy server.
-
- When packets are proxied, the destination address and port are
- modified. In certain cases, it is necessary to somehow encode
- the original address/port info into the packet. Two methods are
- presently supported: addition of a [DEST addr port] string at the
- beginning of a tcp stream, or inclusion of an optional field
- in the IP header.
-
- There is one public API function:
-
- PacketAliasProxyRule() -- Adds and deletes proxy
- rules.
-
- Rules are stored in a linear linked list, so lookup efficiency
- won't be too good for large lists.
-
-
- Initial development: April, 1998 (cjm)
-*/
-
-
-/* System includes */
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <netdb.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-/* BSD IPV4 includes */
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
-
-#include <arpa/inet.h>
-
-#include "alias_local.h" /* Functions used by alias*.c */
-#include "alias.h" /* Public API functions for libalias */
-
-
-
-/*
- Data structures
- */
-
-/*
- * A linked list of arbitrary length, based on struct proxy_entry is
- * used to store proxy rules.
- */
-struct proxy_entry
-{
-#define PROXY_TYPE_ENCODE_NONE 1
-#define PROXY_TYPE_ENCODE_TCPSTREAM 2
-#define PROXY_TYPE_ENCODE_IPHDR 3
- int rule_index;
- int proxy_type;
- u_char proto;
- u_short proxy_port;
- u_short server_port;
-
- struct in_addr server_addr;
-
- struct in_addr src_addr;
- struct in_addr src_mask;
-
- struct in_addr dst_addr;
- struct in_addr dst_mask;
-
- struct proxy_entry *next;
- struct proxy_entry *last;
-};
-
-
-
-/*
- File scope variables
-*/
-
-static struct proxy_entry *proxyList;
-
-
-
-/* Local (static) functions:
-
- IpMask() -- Utility function for creating IP
- masks from integer (1-32) specification.
- IpAddr() -- Utility function for converting string
- to IP address
- IpPort() -- Utility function for converting string
- to port number
- RuleAdd() -- Adds an element to the rule list.
- RuleDelete() -- Removes an element from the rule list.
- RuleNumberDelete() -- Removes all elements from the rule list
- having a certain rule number.
- ProxyEncodeTcpStream() -- Adds [DEST x.x.x.x xxxx] to the beginning
- of a TCP stream.
- ProxyEncodeIpHeader() -- Adds an IP option indicating the true
- destination of a proxied IP packet
-*/
-
-static int IpMask(int, struct in_addr *);
-static int IpAddr(char *, struct in_addr *);
-static int IpPort(char *, int, int *);
-static void RuleAdd(struct proxy_entry *);
-static void RuleDelete(struct proxy_entry *);
-static int RuleNumberDelete(int);
-static void ProxyEncodeTcpStream(struct alias_link *, struct ip *, int);
-static void ProxyEncodeIpHeader(struct ip *, int);
-
-static int
-IpMask(int nbits, struct in_addr *mask)
-{
- int i;
- u_int imask;
-
- if (nbits < 0 || nbits > 32)
- return -1;
-
- imask = 0;
- for (i=0; i<nbits; i++)
- imask = (imask >> 1) + 0x80000000;
- mask->s_addr = htonl(imask);
-
- return 0;
-}
-
-static int
-IpAddr(char *s, struct in_addr *addr)
-{
- if (inet_aton(s, addr) == 0)
- return -1;
- else
- return 0;
-}
-
-static int
-IpPort(char *s, int proto, int *port)
-{
- int n;
-
- n = sscanf(s, "%d", port);
- if (n != 1)
- {
- struct servent *se;
-
- if (proto == IPPROTO_TCP)
- se = getservbyname(s, "tcp");
- else if (proto == IPPROTO_UDP)
- se = getservbyname(s, "udp");
- else
- return -1;
-
- if (se == NULL)
- return -1;
-
- *port = (u_int) ntohs(se->s_port);
- }
-
- return 0;
-}
-
-void
-RuleAdd(struct proxy_entry *entry)
-{
- int rule_index;
- struct proxy_entry *ptr;
- struct proxy_entry *ptr_last;
-
- if (proxyList == NULL)
- {
- proxyList = entry;
- entry->last = NULL;
- entry->next = NULL;
- return;
- }
-
- rule_index = entry->rule_index;
- ptr = proxyList;
- ptr_last = NULL;
- while (ptr != NULL)
- {
- if (ptr->rule_index >= rule_index)
- {
- if (ptr_last == NULL)
- {
- entry->next = proxyList;
- entry->last = NULL;
- proxyList->last = entry;
- proxyList = entry;
- return;
- }
-
- ptr_last->next = entry;
- ptr->last = entry;
- entry->last = ptr->last;
- entry->next = ptr;
- return;
- }
- ptr_last = ptr;
- ptr = ptr->next;
- }
-
- ptr_last->next = entry;
- entry->last = ptr_last;
- entry->next = NULL;
-}
-
-static void
-RuleDelete(struct proxy_entry *entry)
-{
- if (entry->last != NULL)
- entry->last->next = entry->next;
- else
- proxyList = entry->next;
-
- if (entry->next != NULL)
- entry->next->last = entry->last;
-
- free(entry);
-}
-
-static int
-RuleNumberDelete(int rule_index)
-{
- int err;
- struct proxy_entry *ptr;
-
- err = -1;
- ptr = proxyList;
- while (ptr != NULL)
- {
- struct proxy_entry *ptr_next;
-
- ptr_next = ptr->next;
- if (ptr->rule_index == rule_index)
- {
- err = 0;
- RuleDelete(ptr);
- }
-
- ptr = ptr_next;
- }
-
- return err;
-}
-
-static void
-ProxyEncodeTcpStream(struct alias_link *link,
- struct ip *pip,
- int maxpacketsize)
-{
- int slen;
- char buffer[40];
- struct tcphdr *tc;
-
-/* Compute pointer to tcp header */
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
-
-/* Don't modify if once already modified */
-
- if (GetAckModified (link))
- return;
-
-/* Translate destination address and port to string form */
- snprintf(buffer, sizeof(buffer) - 2, "[DEST %s %d]",
- inet_ntoa(GetProxyAddress (link)), (u_int) ntohs(GetProxyPort (link)));
-
-/* Pad string out to a multiple of two in length */
- slen = strlen(buffer);
- switch (slen % 2)
- {
- case 0:
- strcat(buffer, " \n");
- slen += 2;
- break;
- case 1:
- strcat(buffer, "\n");
- slen += 1;
- }
-
-/* Check for packet overflow */
- if ((ntohs(pip->ip_len) + strlen(buffer)) > maxpacketsize)
- return;
-
-/* Shift existing TCP data and insert destination string */
- {
- int dlen;
- int hlen;
- u_char *p;
-
- hlen = (pip->ip_hl + tc->th_off) << 2;
- dlen = ntohs (pip->ip_len) - hlen;
-
-/* Modify first packet that has data in it */
-
- if (dlen == 0)
- return;
-
- p = (char *) pip;
- p += hlen;
-
- memmove(p + slen, p, dlen);
- memcpy(p, buffer, slen);
- }
-
-/* Save information about modfied sequence number */
- {
- int delta;
-
- SetAckModified(link);
- delta = GetDeltaSeqOut(pip, link);
- AddSeq(pip, link, delta+slen);
- }
-
-/* Update IP header packet length and checksum */
- {
- int accumulate;
-
- accumulate = pip->ip_len;
- pip->ip_len = htons(ntohs(pip->ip_len) + slen);
- accumulate -= pip->ip_len;
-
- ADJUST_CHECKSUM(accumulate, pip->ip_sum);
- }
-
-/* Update TCP checksum, Use TcpChecksum since so many things have
- already changed. */
-
- tc->th_sum = 0;
- tc->th_sum = TcpChecksum (pip);
-}
-
-static void
-ProxyEncodeIpHeader(struct ip *pip,
- int maxpacketsize)
-{
-#define OPTION_LEN_BYTES 8
-#define OPTION_LEN_INT16 4
-#define OPTION_LEN_INT32 2
- u_char option[OPTION_LEN_BYTES];
-
-#ifdef DEBUG
- fprintf(stdout, " ip cksum 1 = %x\n", (u_int) IpChecksum(pip));
- fprintf(stdout, "tcp cksum 1 = %x\n", (u_int) TcpChecksum(pip));
-#endif
-
-/* Check to see that there is room to add an IP option */
- if (pip->ip_hl > (0x0f - OPTION_LEN_INT32))
- return;
-
-/* Build option and copy into packet */
- {
- u_char *ptr;
- struct tcphdr *tc;
-
- ptr = (u_char *) pip;
- ptr += 20;
- memcpy(ptr + OPTION_LEN_BYTES, ptr, ntohs(pip->ip_len) - 20);
-
- option[0] = 0x64; /* class: 3 (reserved), option 4 */
- option[1] = OPTION_LEN_BYTES;
-
- memcpy(&option[2], (u_char *) &pip->ip_dst, 4);
-
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
- memcpy(&option[6], (u_char *) &tc->th_sport, 2);
-
- memcpy(ptr, option, 8);
- }
-
-/* Update checksum, header length and packet length */
- {
- int i;
- int accumulate;
- u_short *sptr;
-
- sptr = (u_short *) option;
- accumulate = 0;
- for (i=0; i<OPTION_LEN_INT16; i++)
- accumulate -= *(sptr++);
-
- sptr = (u_short *) pip;
- accumulate += *sptr;
- pip->ip_hl += OPTION_LEN_INT32;
- accumulate -= *sptr;
-
- accumulate += pip->ip_len;
- pip->ip_len = htons(ntohs(pip->ip_len) + OPTION_LEN_BYTES);
- accumulate -= pip->ip_len;
-
- ADJUST_CHECKSUM(accumulate, pip->ip_sum);
- }
-#undef OPTION_LEN_BYTES
-#undef OPTION_LEN_INT16
-#undef OPTION_LEN_INT32
-#ifdef DEBUG
- fprintf(stdout, " ip cksum 2 = %x\n", (u_int) IpChecksum(pip));
- fprintf(stdout, "tcp cksum 2 = %x\n", (u_int) TcpChecksum(pip));
-#endif
-}
-
-
-/* Functions by other packet alias source files
-
- ProxyCheck() -- Checks whether an outgoing packet should
- be proxied.
- ProxyModify() -- Encodes the original destination address/port
- for a packet which is to be redirected to
- a proxy server.
-*/
-
-int
-ProxyCheck(struct ip *pip,
- struct in_addr *proxy_server_addr,
- u_short *proxy_server_port)
-{
- u_short dst_port;
- struct in_addr src_addr;
- struct in_addr dst_addr;
- struct proxy_entry *ptr;
-
- src_addr = pip->ip_src;
- dst_addr = pip->ip_dst;
- dst_port = ((struct tcphdr *) ((char *) pip + (pip->ip_hl << 2)))
- ->th_dport;
-
- ptr = proxyList;
- while (ptr != NULL)
- {
- u_short proxy_port;
-
- proxy_port = ptr->proxy_port;
- if ((dst_port == proxy_port || proxy_port == 0)
- && pip->ip_p == ptr->proto
- && src_addr.s_addr != ptr->server_addr.s_addr)
- {
- struct in_addr src_addr_masked;
- struct in_addr dst_addr_masked;
-
- src_addr_masked.s_addr = src_addr.s_addr & ptr->src_mask.s_addr;
- dst_addr_masked.s_addr = dst_addr.s_addr & ptr->dst_mask.s_addr;
-
- if ((src_addr_masked.s_addr == ptr->src_addr.s_addr)
- && (dst_addr_masked.s_addr == ptr->dst_addr.s_addr))
- {
- if ((*proxy_server_port = ptr->server_port) == 0)
- *proxy_server_port = dst_port;
- *proxy_server_addr = ptr->server_addr;
- return ptr->proxy_type;
- }
- }
- ptr = ptr->next;
- }
-
- return 0;
-}
-
-void
-ProxyModify(struct alias_link *link,
- struct ip *pip,
- int maxpacketsize,
- int proxy_type)
-{
- switch (proxy_type)
- {
- case PROXY_TYPE_ENCODE_IPHDR:
- ProxyEncodeIpHeader(pip, maxpacketsize);
- break;
-
- case PROXY_TYPE_ENCODE_TCPSTREAM:
- ProxyEncodeTcpStream(link, pip, maxpacketsize);
- break;
- }
-}
-
-
-/*
- Public API functions
-*/
-
-int
-PacketAliasProxyRule(const char *cmd)
-{
-/*
- * This function takes command strings of the form:
- *
- * server <addr>[:<port>]
- * [port <port>]
- * [rule n]
- * [proto tcp|udp]
- * [src <addr>[/n]]
- * [dst <addr>[/n]]
- * [type encode_tcp_stream|encode_ip_hdr|no_encode]
- *
- * delete <rule number>
- *
- * Subfields can be in arbitrary order. Port numbers and addresses
- * must be in either numeric or symbolic form. An optional rule number
- * is used to control the order in which rules are searched. If two
- * rules have the same number, then search order cannot be guaranteed,
- * and the rules should be disjoint. If no rule number is specified,
- * then 0 is used, and group 0 rules are always checked before any
- * others.
- */
- int i, n, len;
- int cmd_len;
- int token_count;
- int state;
- char *token;
- char buffer[256];
- char str_port[sizeof(buffer)];
- char str_server_port[sizeof(buffer)];
- char *res = buffer;
-
- int rule_index;
- int proto;
- int proxy_type;
- int proxy_port;
- int server_port;
- struct in_addr server_addr;
- struct in_addr src_addr, src_mask;
- struct in_addr dst_addr, dst_mask;
- struct proxy_entry *proxy_entry;
-
-/* Copy command line into a buffer */
- cmd += strspn(cmd, " \t");
- cmd_len = strlen(cmd);
- if (cmd_len > (sizeof(buffer) - 1))
- return -1;
- strcpy(buffer, cmd);
-
-/* Convert to lower case */
- len = strlen(buffer);
- for (i=0; i<len; i++)
- buffer[i] = tolower((unsigned char)buffer[i]);
-
-/* Set default proxy type */
-
-/* Set up default values */
- rule_index = 0;
- proxy_type = PROXY_TYPE_ENCODE_NONE;
- proto = IPPROTO_TCP;
- proxy_port = 0;
- server_addr.s_addr = 0;
- server_port = 0;
- src_addr.s_addr = 0;
- IpMask(0, &src_mask);
- dst_addr.s_addr = 0;
- IpMask(0, &dst_mask);
-
- str_port[0] = 0;
- str_server_port[0] = 0;
-
-/* Parse command string with state machine */
-#define STATE_READ_KEYWORD 0
-#define STATE_READ_TYPE 1
-#define STATE_READ_PORT 2
-#define STATE_READ_SERVER 3
-#define STATE_READ_RULE 4
-#define STATE_READ_DELETE 5
-#define STATE_READ_PROTO 6
-#define STATE_READ_SRC 7
-#define STATE_READ_DST 8
- state = STATE_READ_KEYWORD;
- token = strsep(&res, " \t");
- token_count = 0;
- while (token != NULL)
- {
- token_count++;
- switch (state)
- {
- case STATE_READ_KEYWORD:
- if (strcmp(token, "type") == 0)
- state = STATE_READ_TYPE;
- else if (strcmp(token, "port") == 0)
- state = STATE_READ_PORT;
- else if (strcmp(token, "server") == 0)
- state = STATE_READ_SERVER;
- else if (strcmp(token, "rule") == 0)
- state = STATE_READ_RULE;
- else if (strcmp(token, "delete") == 0)
- state = STATE_READ_DELETE;
- else if (strcmp(token, "proto") == 0)
- state = STATE_READ_PROTO;
- else if (strcmp(token, "src") == 0)
- state = STATE_READ_SRC;
- else if (strcmp(token, "dst") == 0)
- state = STATE_READ_DST;
- else
- return -1;
- break;
-
- case STATE_READ_TYPE:
- if (strcmp(token, "encode_ip_hdr") == 0)
- proxy_type = PROXY_TYPE_ENCODE_IPHDR;
- else if (strcmp(token, "encode_tcp_stream") == 0)
- proxy_type = PROXY_TYPE_ENCODE_TCPSTREAM;
- else if (strcmp(token, "no_encode") == 0)
- proxy_type = PROXY_TYPE_ENCODE_NONE;
- else
- return -1;
- state = STATE_READ_KEYWORD;
- break;
-
- case STATE_READ_PORT:
- strcpy(str_port, token);
- state = STATE_READ_KEYWORD;
- break;
-
- case STATE_READ_SERVER:
- {
- int err;
- char *p;
- char s[sizeof(buffer)];
-
- p = token;
- while (*p != ':' && *p != 0)
- p++;
-
- if (*p != ':')
- {
- err = IpAddr(token, &server_addr);
- if (err)
- return -1;
- }
- else
- {
- *p = ' ';
-
- n = sscanf(token, "%s %s", s, str_server_port);
- if (n != 2)
- return -1;
-
- err = IpAddr(s, &server_addr);
- if (err)
- return -1;
- }
- }
- state = STATE_READ_KEYWORD;
- break;
-
- case STATE_READ_RULE:
- n = sscanf(token, "%d", &rule_index);
- if (n != 1 || rule_index < 0)
- return -1;
- state = STATE_READ_KEYWORD;
- break;
-
- case STATE_READ_DELETE:
- {
- int err;
- int rule_to_delete;
-
- if (token_count != 2)
- return -1;
-
- n = sscanf(token, "%d", &rule_to_delete);
- if (n != 1)
- return -1;
- err = RuleNumberDelete(rule_to_delete);
- if (err)
- return -1;
- return 0;
- }
-
- case STATE_READ_PROTO:
- if (strcmp(token, "tcp") == 0)
- proto = IPPROTO_TCP;
- else if (strcmp(token, "udp") == 0)
- proto = IPPROTO_UDP;
- else
- return -1;
- state = STATE_READ_KEYWORD;
- break;
-
- case STATE_READ_SRC:
- case STATE_READ_DST:
- {
- int err;
- char *p;
- struct in_addr mask;
- struct in_addr addr;
-
- p = token;
- while (*p != '/' && *p != 0)
- p++;
-
- if (*p != '/')
- {
- IpMask(32, &mask);
- err = IpAddr(token, &addr);
- if (err)
- return -1;
- }
- else
- {
- int nbits;
- char s[sizeof(buffer)];
-
- *p = ' ';
- n = sscanf(token, "%s %d", s, &nbits);
- if (n != 2)
- return -1;
-
- err = IpAddr(s, &addr);
- if (err)
- return -1;
-
- err = IpMask(nbits, &mask);
- if (err)
- return -1;
- }
-
- if (state == STATE_READ_SRC)
- {
- src_addr = addr;
- src_mask = mask;
- }
- else
- {
- dst_addr = addr;
- dst_mask = mask;
- }
- }
- state = STATE_READ_KEYWORD;
- break;
-
- default:
- return -1;
- break;
- }
-
- do {
- token = strsep(&res, " \t");
- } while (token != NULL && !*token);
- }
-#undef STATE_READ_KEYWORD
-#undef STATE_READ_TYPE
-#undef STATE_READ_PORT
-#undef STATE_READ_SERVER
-#undef STATE_READ_RULE
-#undef STATE_READ_DELETE
-#undef STATE_READ_PROTO
-#undef STATE_READ_SRC
-#undef STATE_READ_DST
-
-/* Convert port strings to numbers. This needs to be done after
- the string is parsed, because the prototype might not be designated
- before the ports (which might be symbolic entries in /etc/services) */
-
- if (strlen(str_port) != 0)
- {
- int err;
-
- err = IpPort(str_port, proto, &proxy_port);
- if (err)
- return -1;
- }
- else
- {
- proxy_port = 0;
- }
-
- if (strlen(str_server_port) != 0)
- {
- int err;
-
- err = IpPort(str_server_port, proto, &server_port);
- if (err)
- return -1;
- }
- else
- {
- server_port = 0;
- }
-
-/* Check that at least the server address has been defined */
- if (server_addr.s_addr == 0)
- return -1;
-
-/* Add to linked list */
- proxy_entry = malloc(sizeof(struct proxy_entry));
- if (proxy_entry == NULL)
- return -1;
-
- proxy_entry->proxy_type = proxy_type;
- proxy_entry->rule_index = rule_index;
- proxy_entry->proto = proto;
- proxy_entry->proxy_port = htons(proxy_port);
- proxy_entry->server_port = htons(server_port);
- proxy_entry->server_addr = server_addr;
- proxy_entry->src_addr.s_addr = src_addr.s_addr & src_mask.s_addr;
- proxy_entry->dst_addr.s_addr = dst_addr.s_addr & dst_mask.s_addr;
- proxy_entry->src_mask = src_mask;
- proxy_entry->dst_mask = dst_mask;
-
- RuleAdd(proxy_entry);
-
- return 0;
-}
diff --git a/sys/netinet/libalias/alias_smedia.c b/sys/netinet/libalias/alias_smedia.c
deleted file mode 100644
index a3ba7ae72e9e..000000000000
--- a/sys/netinet/libalias/alias_smedia.c
+++ /dev/null
@@ -1,433 +0,0 @@
-/*
- * alias_smedia.c
- *
- * Copyright (c) 2000 Whistle Communications, Inc.
- * All rights reserved.
- *
- * Subject to the following obligations and disclaimer of warranty, use and
- * redistribution of this software, in source or object code forms, with or
- * without modifications are expressly permitted by Whistle Communications;
- * provided, however, that:
- * 1. Any and all reproductions of the source or object code must include the
- * copyright notice above and the following disclaimer of warranties; and
- * 2. No rights are granted, in any manner or form, to use Whistle
- * Communications, Inc. trademarks, including the mark "WHISTLE
- * COMMUNICATIONS" on advertising, endorsements, or otherwise except as
- * such appears in the above copyright notice or in the software.
- *
- * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
- * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
- * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
- * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
- * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
- * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
- * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
- * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
- * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
- * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
- * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * Copyright (c) 2000 Junichi SATOH <junichi@astec.co.jp>
- * <junichi@junichi.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Authors: Erik Salander <erik@whistle.com>
- * Junichi SATOH <junichi@astec.co.jp>
- * <junichi@junichi.org>
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- Alias_smedia.c is meant to contain the aliasing code for streaming media
- protocols. It performs special processing for RSTP sessions under TCP.
- Specifically, when a SETUP request is sent by a client, or a 200 reply
- is sent by a server, it is intercepted and modified. The address is
- changed to the gateway machine and an aliasing port is used.
-
- More specifically, the "client_port" configuration parameter is
- parsed for SETUP requests. The "server_port" configuration parameter is
- parsed for 200 replies eminating from a server. This is intended to handle
- the unicast case.
-
- RTSP also allows a redirection of a stream to another client by using the
- "destination" configuration parameter. The destination config parm would
- indicate a different IP address. This function is NOT supported by the
- RTSP translation code below.
-
- The RTSP multicast functions without any address translation intervention.
-
- For this routine to work, the SETUP/200 must fit entirely
- into a single TCP packet. This is typically the case, but exceptions
- can easily be envisioned under the actual specifications.
-
- Probably the most troubling aspect of the approach taken here is
- that the new SETUP/200 will typically be a different length, and
- this causes a certain amount of bookkeeping to keep track of the
- changes of sequence and acknowledgment numbers, since the client
- machine is totally unaware of the modification to the TCP stream.
-
- Initial version: May, 2000 (eds)
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
-#include <netinet/udp.h>
-
-#include "alias_local.h"
-
-#define RTSP_CONTROL_PORT_NUMBER_1 554
-#define RTSP_CONTROL_PORT_NUMBER_2 7070
-#define RTSP_PORT_GROUP 2
-
-#define ISDIGIT(a) (((a) >= '0') && ((a) <= '9'))
-
-static int
-search_string(char *data, int dlen, const char *search_str)
-{
- int i, j, k;
- int search_str_len;
-
- search_str_len = strlen(search_str);
- for (i = 0; i < dlen - search_str_len; i++) {
- for (j = i, k = 0; j < dlen - search_str_len; j++, k++) {
- if (data[j] != search_str[k] &&
- data[j] != search_str[k] - ('a' - 'A')) {
- break;
- }
- if (k == search_str_len - 1) {
- return j + 1;
- }
- }
- }
- return -1;
-}
-
-static int
-alias_rtsp_out(struct ip *pip,
- struct alias_link *link,
- char *data,
- const char *port_str)
-{
- int hlen, tlen, dlen;
- struct tcphdr *tc;
- int i, j, pos, state, port_dlen, new_dlen, delta;
- u_short p[2], new_len;
- u_short sport, eport, base_port;
- u_short salias = 0, ealias = 0, base_alias = 0;
- const char *transport_str = "transport:";
- char newdata[2048], *port_data, *port_newdata, stemp[80];
- int links_created = 0, pkt_updated = 0;
- struct alias_link *rtsp_link = NULL;
- struct in_addr null_addr;
-
- /* Calculate data length of TCP packet */
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
- hlen = (pip->ip_hl + tc->th_off) << 2;
- tlen = ntohs(pip->ip_len);
- dlen = tlen - hlen;
-
- /* Find keyword, "Transport: " */
- pos = search_string(data, dlen, transport_str);
- if (pos < 0) {
- return -1;
- }
- port_data = data + pos;
- port_dlen = dlen - pos;
-
- memcpy(newdata, data, pos);
- port_newdata = newdata + pos;
-
- while (port_dlen > strlen(port_str)) {
- /* Find keyword, appropriate port string */
- pos = search_string(port_data, port_dlen, port_str);
- if (pos < 0) {
- break;
- }
-
- memcpy (port_newdata, port_data, pos + 1);
- port_newdata += (pos + 1);
-
- p[0] = p[1] = 0;
- sport = eport = 0;
- state = 0;
- for (i = pos; i < port_dlen; i++) {
- switch(state) {
- case 0:
- if (port_data[i] == '=') {
- state++;
- }
- break;
- case 1:
- if (ISDIGIT(port_data[i])) {
- p[0] = p[0] * 10 + port_data[i] - '0';
- } else {
- if (port_data[i] == ';') {
- state = 3;
- }
- if (port_data[i] == '-') {
- state++;
- }
- }
- break;
- case 2:
- if (ISDIGIT(port_data[i])) {
- p[1] = p[1] * 10 + port_data[i] - '0';
- } else {
- state++;
- }
- break;
- case 3:
- base_port = p[0];
- sport = htons(p[0]);
- eport = htons(p[1]);
-
- if (!links_created) {
-
- links_created = 1;
- /* Find an even numbered port number base that
- satisfies the contiguous number of ports we need */
- null_addr.s_addr = 0;
- if (0 == (salias = FindNewPortGroup(null_addr,
- FindAliasAddress(pip->ip_src),
- sport, 0,
- RTSP_PORT_GROUP,
- IPPROTO_UDP, 1))) {
-#ifdef DEBUG
- fprintf(stderr,
- "PacketAlias/RTSP: Cannot find contiguous RTSP data ports\n");
-#endif
- } else {
-
- base_alias = ntohs(salias);
- for (j = 0; j < RTSP_PORT_GROUP; j++) {
- /* Establish link to port found in RTSP packet */
- rtsp_link = FindRtspOut(GetOriginalAddress(link), null_addr,
- htons(base_port + j), htons(base_alias + j),
- IPPROTO_UDP);
- if (rtsp_link != NULL) {
-#ifndef NO_FW_PUNCH
- /* Punch hole in firewall */
- PunchFWHole(rtsp_link);
-#endif
- } else {
-#ifdef DEBUG
- fprintf(stderr,
- "PacketAlias/RTSP: Cannot allocate RTSP data ports\n");
-#endif
- break;
- }
- }
- }
- ealias = htons(base_alias + (RTSP_PORT_GROUP - 1));
- }
-
- if (salias && rtsp_link) {
-
- pkt_updated = 1;
-
- /* Copy into IP packet */
- sprintf(stemp, "%d", ntohs(salias));
- memcpy(port_newdata, stemp, strlen(stemp));
- port_newdata += strlen(stemp);
-
- if (eport != 0) {
- *port_newdata = '-';
- port_newdata++;
-
- /* Copy into IP packet */
- sprintf(stemp, "%d", ntohs(ealias));
- memcpy(port_newdata, stemp, strlen(stemp));
- port_newdata += strlen(stemp);
- }
-
- *port_newdata = ';';
- port_newdata++;
- }
- state++;
- break;
- }
- if (state > 3) {
- break;
- }
- }
- port_data += i;
- port_dlen -= i;
- }
-
- if (!pkt_updated)
- return -1;
-
- memcpy (port_newdata, port_data, port_dlen);
- port_newdata += port_dlen;
- *port_newdata = '\0';
-
- /* Create new packet */
- new_dlen = port_newdata - newdata;
- memcpy (data, newdata, new_dlen);
-
- SetAckModified(link);
- delta = GetDeltaSeqOut(pip, link);
- AddSeq(pip, link, delta + new_dlen - dlen);
-
- new_len = htons(hlen + new_dlen);
- DifferentialChecksum(&pip->ip_sum,
- &new_len,
- &pip->ip_len,
- 1);
- pip->ip_len = new_len;
-
- tc->th_sum = 0;
- tc->th_sum = TcpChecksum(pip);
-
- return 0;
-}
-
-/* Support the protocol used by early versions of RealPlayer */
-
-static int
-alias_pna_out(struct ip *pip,
- struct alias_link *link,
- char *data,
- int dlen)
-{
- struct alias_link *pna_links;
- u_short msg_id, msg_len;
- char *work;
- u_short alias_port, port;
- struct tcphdr *tc;
-
- work = data;
- work += 5;
- while (work + 4 < data + dlen) {
- memcpy(&msg_id, work, 2);
- work += 2;
- memcpy(&msg_len, work, 2);
- work += 2;
- if (ntohs(msg_id) == 0) {
- /* end of options */
- return 0;
- }
- if ((ntohs(msg_id) == 1) || (ntohs(msg_id) == 7)) {
- memcpy(&port, work, 2);
- pna_links = FindUdpTcpOut(pip->ip_src, GetDestAddress(link),
- port, 0, IPPROTO_UDP, 1);
- if (pna_links != NULL) {
-#ifndef NO_FW_PUNCH
- /* Punch hole in firewall */
- PunchFWHole(pna_links);
-#endif
- tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));
- alias_port = GetAliasPort(pna_links);
- memcpy(work, &alias_port, 2);
-
- /* Compute TCP checksum for revised packet */
- tc->th_sum = 0;
- tc->th_sum = TcpChecksum(pip);
- }
- }
- work += ntohs(msg_len);
- }
-
- return 0;
-}
-
-void
-AliasHandleRtspOut(struct ip *pip, struct alias_link *link, int maxpacketsize)
-{
- int hlen, tlen, dlen;
- struct tcphdr *tc;
- char *data;
- const char *setup = "SETUP", *pna = "PNA", *str200 = "200";
- const char *okstr = "OK", *client_port_str = "client_port";
- const char *server_port_str = "server_port";
- int i, parseOk;
-
- tc = (struct tcphdr *)((char *)pip + (pip->ip_hl << 2));
- hlen = (pip->ip_hl + tc->th_off) << 2;
- tlen = ntohs(pip->ip_len);
- dlen = tlen - hlen;
-
- data = (char*)pip;
- data += hlen;
-
- /* When aliasing a client, check for the SETUP request */
- if ((ntohs(tc->th_dport) == RTSP_CONTROL_PORT_NUMBER_1) ||
- (ntohs(tc->th_dport) == RTSP_CONTROL_PORT_NUMBER_2)) {
-
- if (dlen >= strlen(setup)) {
- if (memcmp(data, setup, strlen(setup)) == 0) {
- alias_rtsp_out(pip, link, data, client_port_str);
- return;
- }
- }
- if (dlen >= strlen(pna)) {
- if (memcmp(data, pna, strlen(pna)) == 0) {
- alias_pna_out(pip, link, data, dlen);
- }
- }
-
- } else {
-
- /* When aliasing a server, check for the 200 reply
- Accomodate varying number of blanks between 200 & OK */
-
- if (dlen >= strlen(str200)) {
-
- for (parseOk = 0, i = 0;
- i <= dlen - strlen(str200);
- i++) {
- if (memcmp(&data[i], str200, strlen(str200)) == 0) {
- parseOk = 1;
- break;
- }
- }
- if (parseOk) {
-
- i += strlen(str200); /* skip string found */
- while(data[i] == ' ') /* skip blank(s) */
- i++;
-
- if ((dlen - i) >= strlen(okstr)) {
-
- if (memcmp(&data[i], okstr, strlen(okstr)) == 0)
- alias_rtsp_out(pip, link, data, server_port_str);
-
- }
- }
- }
- }
-}
diff --git a/sys/netinet/libalias/alias_util.c b/sys/netinet/libalias/alias_util.c
deleted file mode 100644
index d6b40a2bc170..000000000000
--- a/sys/netinet/libalias/alias_util.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/*-
- * Copyright (c) 2001 Charles Mott <cm@linktel.net>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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$");
-
-
-/*
- Alias_util.c contains general utilities used by other functions
- in the packet aliasing module. At the moment, there are functions
- for computing IP header and TCP packet checksums.
-
- The checksum routines are based upon example code in a Unix networking
- text written by Stevens (sorry, I can't remember the title -- but
- at least this is a good author).
-
- Initial Version: August, 1996 (cjm)
-
- Version 1.7: January 9, 1997
- Added differential checksum update function.
-*/
-
-/*
-Note: the checksum routines assume that the actual checksum word has
-been zeroed out. If the checksum word is filled with the proper value,
-then these routines will give a result of zero (useful for testing
-purposes);
-*/
-
-#include <sys/types.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
-
-#include "alias.h"
-#include "alias_local.h"
-
-u_short
-PacketAliasInternetChecksum(u_short *ptr, int nbytes)
-{
- int sum, oddbyte;
-
- sum = 0;
- while (nbytes > 1)
- {
- sum += *ptr++;
- nbytes -= 2;
- }
- if (nbytes == 1)
- {
- oddbyte = 0;
- ((u_char *) &oddbyte)[0] = *(u_char *) ptr;
- ((u_char *) &oddbyte)[1] = 0;
- sum += oddbyte;
- }
- sum = (sum >> 16) + (sum & 0xffff);
- sum += (sum >> 16);
- return(~sum);
-}
-
-u_short
-IpChecksum(struct ip *pip)
-{
- return( PacketAliasInternetChecksum((u_short *) pip,
- (pip->ip_hl << 2)) );
-
-}
-
-u_short
-TcpChecksum(struct ip *pip)
-{
- u_short *ptr;
- struct tcphdr *tc;
- int nhdr, ntcp, nbytes;
- int sum, oddbyte;
-
- nhdr = pip->ip_hl << 2;
- ntcp = ntohs(pip->ip_len) - nhdr;
-
- tc = (struct tcphdr *) ((char *) pip + nhdr);
- ptr = (u_short *) tc;
-
-/* Add up TCP header and data */
- nbytes = ntcp;
- sum = 0;
- while (nbytes > 1)
- {
- sum += *ptr++;
- nbytes -= 2;
- }
- if (nbytes == 1)
- {
- oddbyte = 0;
- ((u_char *) &oddbyte)[0] = *(u_char *) ptr;
- ((u_char *) &oddbyte)[1] = 0;
- sum += oddbyte;
- }
-
-/* "Pseudo-header" data */
- ptr = (u_short *) &(pip->ip_dst);
- sum += *ptr++;
- sum += *ptr;
- ptr = (u_short *) &(pip->ip_src);
- sum += *ptr++;
- sum += *ptr;
- sum += htons((u_short) ntcp);
- sum += htons((u_short) pip->ip_p);
-
-/* Roll over carry bits */
- sum = (sum >> 16) + (sum & 0xffff);
- sum += (sum >> 16);
-
-/* Return checksum */
- return((u_short) ~sum);
-}
-
-
-void
-DifferentialChecksum(u_short *cksum, u_short *new, u_short *old, int n)
-{
- int i;
- int accumulate;
-
- accumulate = *cksum;
- for (i=0; i<n; i++)
- {
- accumulate -= *new++;
- accumulate += *old++;
- }
-
- if (accumulate < 0)
- {
- accumulate = -accumulate;
- accumulate = (accumulate >> 16) + (accumulate & 0xffff);
- accumulate += accumulate >> 16;
- *cksum = (u_short) ~accumulate;
- }
- else
- {
- accumulate = (accumulate >> 16) + (accumulate & 0xffff);
- accumulate += accumulate >> 16;
- *cksum = (u_short) accumulate;
- }
-}
-
diff --git a/sys/netinet/libalias/libalias.3 b/sys/netinet/libalias/libalias.3
deleted file mode 100644
index cd8b97c39094..000000000000
--- a/sys/netinet/libalias/libalias.3
+++ /dev/null
@@ -1,981 +0,0 @@
-.\"-
-.\" Copyright (c) 2001 Charles Mott <cm@linktel.net>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 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$
-.\"
-.Dd April 13, 2000
-.Dt LIBALIAS 3
-.Os
-.Sh NAME
-.Nm libalias
-.Nd packet aliasing library for masquerading and network address translation
-.Sh SYNOPSIS
-.In sys/types.h
-.In netinet/in.h
-.In alias.h
-.Pp
-Function prototypes are given in the main body of the text.
-.Sh DESCRIPTION
-The
-.Nm
-library is a collection of functions for aliasing and de-aliasing of IP
-packets, intended for masquerading and network address translation (NAT).
-.Sh INTRODUCTION
-This library is a moderately portable set of functions designed to assist
-in the process of IP masquerading and network address translation.
-Outgoing packets from a local network with unregistered IP addresses can
-be aliased to appear as if they came from an accessible IP address.
-Incoming packets are then de-aliased so that they are sent to the correct
-machine on the local network.
-.Pp
-A certain amount of flexibility is built into the packet aliasing engine.
-In the simplest mode of operation, a many-to-one address mapping takes
-place between local network and the packet aliasing host.
-This is known as IP masquerading.
-In addition, one-to-one mappings between local and public addresses can
-also be implemented, which is known as static NAT.
-In between these extremes, different groups of private addresses can be
-linked to different public addresses, comprising several distinct
-many-to-one mappings.
-Also, a given public address and port can be statically redirected to a
-private address/port.
-.Pp
-The packet aliasing engine was designed to operate in user space outside
-of the kernel, without any access to private kernel data structure, but
-the source code can also be ported to a kernel environment.
-.Sh INITIALIZATION AND CONTROL
-Two special functions,
-.Fn PacketAliasInit
-and
-.Fn PacketAliasSetAddress ,
-must always be called before any packet handling may be performed.
-In addition, the operating mode of the packet aliasing engine can be
-customized by calling
-.Fn PacketAliasSetMode .
-.Pp
-.Ft void
-.Fn PacketAliasInit void
-.Bd -ragged -offset indent
-This function has no arguments or return value and is used to initialize
-internal data structures.
-The following mode bits are always set after calling
-.Fn PacketAliasInit .
-See the description of
-.Fn PacketAliasSetMode
-below for the meaning of these mode bits.
-.Pp
-.Bl -item -offset indent -compact
-.It
-.Dv PKT_ALIAS_SAME_PORTS
-.It
-.Dv PKT_ALIAS_USE_SOCKETS
-.It
-.Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE
-.El
-.Pp
-This function will always return the packet aliasing engine to the same
-initial state.
-.Fn PacketAliasSetAddress
-must be called afterwards, and any desired changes from the default mode
-bits listed above require a call to
-.Fn PacketAliasSetMode .
-.Pp
-It is mandatory that this function be called at the beginning of a program
-prior to any packet handling.
-.Ed
-.Pp
-.Ft void
-.Fn PacketAliasUninit void
-.Bd -ragged -offset indent
-This function has no arguments or return value and is used to clear any
-resources attached to internal data structures.
-.Pp
-This functions should be called when a program stops using the aliasing
-engine; it does, amongst other things, clear out any firewall holes.
-To provide backwards compatibility and extra security, it is added to
-the
-.Xr atexit 3
-chain by
-.Fn PacketAliasInit .
-Calling it multiple times is harmless.
-.Ed
-.Pp
-.Ft void
-.Fn PacketAliasSetAddress "struct in_addr addr"
-.Bd -ragged -offset indent
-This function sets the source address to which outgoing packets from the
-local area network are aliased.
-All outgoing packets are re-mapped to this address unless overridden by a
-static address mapping established by
-.Fn PacketAliasRedirectAddr .
-.Pp
-If the
-.Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE
-mode bit is set (the default mode of operation), then the internal aliasing
-link tables will be reset any time the aliasing address changes.
-This is useful for interfaces such as
-.Xr ppp 8 ,
-where the IP
-address may or may not change on successive dial-up attempts.
-.Pp
-If the
-.Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE
-mode bit is set to zero, this function can also be used to dynamically change
-the aliasing address on a packet to packet basis (it is a low overhead call).
-.Pp
-It is mandatory that this function be called prior to any packet handling.
-.Ed
-.Pp
-.Ft unsigned int
-.Fn PacketAliasSetMode "unsigned int flags" "unsigned int mask"
-.Bd -ragged -offset indent
-This function sets or clears mode bits
-according to the value of
-.Fa flags .
-Only bits marked in
-.Fa mask
-are affected.
-The following mode bits are defined in
-.Aq Pa alias.h :
-.Bl -tag -width indent
-.It Dv PKT_ALIAS_LOG
-Enables logging into
-.Pa /var/log/alias.log .
-Each time an aliasing link is created or deleted, the log file is appended
-with the current number of ICMP, TCP and UDP links.
-Mainly useful for debugging when the log file is viewed continuously with
-.Xr tail 1 .
-.It Dv PKT_ALIAS_DENY_INCOMING
-If this mode bit is set, all incoming packets associated with new TCP
-connections or new UDP transactions will be marked for being ignored
-.Fn ( PacketAliasIn
-returns
-.Dv PKT_ALIAS_IGNORED
-code)
-by the calling program.
-Response packets to connections or transactions initiated from the packet
-aliasing host or local network will be unaffected.
-This mode bit is useful for implementing a one-way firewall.
-.It Dv PKT_ALIAS_SAME_PORTS
-If this mode bit is set, the packet aliasing engine will attempt to leave
-the alias port numbers unchanged from the actual local port numbers.
-This can be done as long as the quintuple (proto, alias addr, alias port,
-remote addr, remote port) is unique.
-If a conflict exists, a new aliasing port number is chosen even if this
-mode bit is set.
-.It Dv PKT_ALIAS_USE_SOCKETS
-This bit should be set when the packet aliasing host originates network
-traffic as well as forwards it.
-When the packet aliasing host is waiting for a connection from an unknown
-host address or unknown port number (e.g. an FTP data connection), this
-mode bit specifies that a socket be allocated as a place holder to prevent
-port conflicts.
-Once a connection is established, usually within a minute or so, the socket
-is closed.
-.It Dv PKT_ALIAS_UNREGISTERED_ONLY
-If this mode bit is set, traffic on the local network which does not
-originate from unregistered address spaces will be ignored.
-Standard Class A, B and C unregistered addresses are:
-.Bd -literal -offset indent
-10.0.0.0 -> 10.255.255.255 (Class A subnet)
-172.16.0.0 -> 172.31.255.255 (Class B subnets)
-192.168.0.0 -> 192.168.255.255 (Class C subnets)
-.Ed
-.Pp
-This option is useful in the case that packet aliasing host has both
-registered and unregistered subnets on different interfaces.
-The registered subnet is fully accessible to the outside world, so traffic
-from it does not need to be passed through the packet aliasing engine.
-.It Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE
-When this mode bit is set and
-.Fn PacketAliasSetAddress
-is called to change the aliasing address, the internal link table of the
-packet aliasing engine will be cleared.
-This operating mode is useful for
-.Xr ppp 8
-links where the interface address can sometimes change or remain the same
-between dial-up attempts.
-If this mode bit is not set, the link table will never be reset in the event
-of an address change.
-.It Dv PKT_ALIAS_PUNCH_FW
-This option makes
-.Nm
-`punch holes' in an
-.Xr ipfirewall 4
-based firewall for FTP/IRC DCC connections.
-The holes punched are bound by from/to IP address and port; it will not be
-possible to use a hole for another connection.
-A hole is removed when the connection that uses it dies.
-To cater to unexpected death of a program using
-.Nm
-(e.g. kill -9),
-changing the state of the flag will clear the entire firewall range
-allocated for holes.
-This will also happen on the initial call to
-.Fn PacketAliasSetFWBase .
-This call must happen prior to setting this flag.
-.It Dv PKT_ALIAS_REVERSE
-This option makes
-.Nm
-reverse the way it handles incoming and outgoing packets, allowing it
-to be fed with data that passes through the internal interface rather
-than the external one.
-.It Dv PKT_ALIAS_PROXY_ONLY
-This option tells
-.Nm
-to obey transparent proxy rules only.
-Normal packet aliasing is not performed.
-See
-.Fn PacketAliasProxyRule
-below for details.
-.El
-.Ed
-.Pp
-.Ft void
-.Fn PacketAliasSetFWBase "unsigned int base" "unsigned int num"
-.Bd -ragged -offset indent
-Set firewall range allocated for punching firewall holes (with the
-.Dv PKT_ALIAS_PUNCH_FW
-flag).
-The range will be cleared for all rules on initialization.
-.Ed
-.Sh PACKET HANDLING
-The packet handling functions are used to modify incoming (remote to local)
-and outgoing (local to remote) packets.
-The calling program is responsible for receiving and sending packets via
-network interfaces.
-.Pp
-Along with
-.Fn PacketAliasInit
-and
-.Fn PacketAliasSetAddress ,
-the two packet handling functions,
-.Fn PacketAliasIn
-and
-.Fn PacketAliasOut ,
-comprise minimal set of functions needed for a basic IP masquerading
-implementation.
-.Pp
-.Ft int
-.Fn PacketAliasIn "char *buffer" "int maxpacketsize"
-.Bd -ragged -offset indent
-An incoming packet coming from a remote machine to the local network is
-de-aliased by this function.
-The IP packet is pointed to by
-.Fa buffer ,
-and
-.Fa maxpacketsize
-indicates the size of the data structure containing the packet and should
-be at least as large as the actual packet size.
-.Pp
-Return codes:
-.Bl -tag -width indent
-.It Dv PKT_ALIAS_OK
-The packet aliasing process was successful.
-.It Dv PKT_ALIAS_IGNORED
-The packet was ignored and not de-aliased.
-This can happen if the protocol is unrecognized, possibly an ICMP message
-type is not handled or if incoming packets for new connections are being
-ignored (if
-.Dv PKT_ALIAS_DENY_INCOMING
-mode bit was set by
-.Fn PacketAliasSetMode ) .
-.It Dv PKT_ALIAS_UNRESOLVED_FRAGMENT
-This is returned when a fragment cannot be resolved because the header
-fragment has not been sent yet.
-In this situation, fragments must be saved with
-.Fn PacketAliasSaveFragment
-until a header fragment is found.
-.It Dv PKT_ALIAS_FOUND_HEADER_FRAGMENT
-The packet aliasing process was successful, and a header fragment was found.
-This is a signal to retrieve any unresolved fragments with
-.Fn PacketAliasGetFragment
-and de-alias them with
-.Fn PacketAliasFragmentIn .
-.It Dv PKT_ALIAS_ERROR
-An internal error within the packet aliasing engine occurred.
-.El
-.Ed
-.Pp
-.Ft int
-.Fn PacketAliasOut "char *buffer" "int maxpacketsize"
-.Bd -ragged -offset indent
-An outgoing packet coming from the local network to a remote machine is
-aliased by this function.
-The IP packet is pointed to by
-.Fa buffer ,
-and
-.Fa maxpacketsize
-indicates the maximum packet size permissible should the packet length be
-changed.
-IP encoding protocols place address and port information in the encapsulated
-data stream which has to be modified and can account for changes in packet
-length.
-Well known examples of such protocols are FTP and IRC DCC.
-.Pp
-Return codes:
-.Bl -tag -width indent
-.It Dv PKT_ALIAS_OK
-The packet aliasing process was successful.
-.It Dv PKT_ALIAS_IGNORED
-The packet was ignored and not aliased.
-This can happen if the protocol is unrecognized, or possibly an ICMP message
-type is not handled.
-.It Dv PKT_ALIAS_ERROR
-An internal error within the packet aliasing engine occurred.
-.El
-.Ed
-.Sh PORT AND ADDRESS REDIRECTION
-The functions described in this section allow machines on the local network
-to be accessible in some degree to new incoming connections from the external
-network.
-Individual ports can be re-mapped or static network address translations can
-be designated.
-.Pp
-.Ft struct alias_link *
-.Fo PacketAliasRedirectPort
-.Fa "struct in_addr local_addr"
-.Fa "u_short local_port"
-.Fa "struct in_addr remote_addr"
-.Fa "u_short remote_port"
-.Fa "struct in_addr alias_addr"
-.Fa "u_short alias_port"
-.Fa "u_char proto"
-.Fc
-.Bd -ragged -offset indent
-This function specifies that traffic from a given remote address/port to
-an alias address/port be redirected to a specified local address/port.
-The parameter
-.Fa proto
-can be either
-.Dv IPPROTO_TCP
-or
-.Dv IPPROTO_UDP ,
-as defined in
-.Aq Pa netinet/in.h .
-.Pp
-If
-.Fa local_addr
-or
-.Fa alias_addr
-is zero, this indicates that the packet aliasing address as established
-by
-.Fn PacketAliasSetAddress
-is to be used.
-Even if
-.Fn PacketAliasSetAddress
-is called to change the address after
-.Fn PacketAliasRedirectPort
-is called, a zero reference will track this change.
-.Pp
-If the link is further set up to operate for a load sharing, then
-.Fa local_addr
-and
-.Fa local_port
-are ignored, and are selected dynamically from the server pool, as described in
-.Fn PacketAliasAddServer
-below.
-.Pp
-If
-.Fa remote_addr
-is zero, this indicates to redirect packets from any remote address.
-Likewise, if
-.Fa remote_port
-is zero, this indicates to redirect packets originating from any remote
-port number.
-Almost always, the remote port specification will be zero, but non-zero
-remote addresses can sometimes be useful for firewalling.
-If two calls to
-.Fn PacketAliasRedirectPort
-overlap in their address/port specifications, then the most recent call
-will have precedence.
-.Pp
-This function returns a pointer which can subsequently be used by
-.Fn PacketAliasRedirectDelete .
-If
-.Dv NULL
-is returned, then the function call did not complete successfully.
-.Pp
-All port numbers should be in network address byte order, so it is necessary
-to use
-.Xr htons 3
-to convert these parameters from internally readable numbers to network byte
-order.
-Addresses are also in network byte order, which is implicit in the use of the
-.Fa struct in_addr
-data type.
-.Ed
-.Pp
-.Ft struct alias_link *
-.Fo PacketAliasRedirectAddr
-.Fa "struct in_addr local_addr"
-.Fa "struct in_addr alias_addr"
-.Fc
-.Bd -ragged -offset indent
-This function designates that all incoming traffic to
-.Fa alias_addr
-be redirected to
-.Fa local_addr .
-Similarly, all outgoing traffic from
-.Fa local_addr
-is aliased to
-.Fa alias_addr .
-.Pp
-If
-.Fa local_addr
-or
-.Fa alias_addr
-is zero, this indicates that the packet aliasing address as established by
-.Fn PacketAliasSetAddress
-is to be used.
-Even if
-.Fn PacketAliasSetAddress
-is called to change the address after
-.Fn PacketAliasRedirectAddr
-is called, a zero reference will track this change.
-.Pp
-If the link is further set up to operate for a load sharing, then
-.Fa local_addr
-is ignored, and is selected dynamically from the server pool, as described in
-.Fn PacketAliasAddServer
-below.
-.Pp
-If subsequent calls to
-.Fn PacketAliasRedirectAddr
-use the same aliasing address, all new incoming traffic to this aliasing
-address will be redirected to the local address made in the last function
-call.
-New traffic generated by any of the local machines, designated in the
-several function calls, will be aliased to the same address.
-Consider the following example:
-.Bd -literal -offset indent
-PacketAliasRedirectAddr(inet_aton("192.168.0.2"),
- inet_aton("141.221.254.101"));
-PacketAliasRedirectAddr(inet_aton("192.168.0.3"),
- inet_aton("141.221.254.101"));
-PacketAliasRedirectAddr(inet_aton("192.168.0.4"),
- inet_aton("141.221.254.101"));
-.Ed
-.Pp
-Any outgoing connections such as
-.Xr telnet 1
-or
-.Xr ftp 1
-from 192.168.0.2, 192.168.0.3 and 192.168.0.4 will appear to come from
-141.221.254.101.
-Any incoming connections to 141.221.254.101 will be directed to 192.168.0.4.
-.Pp
-Any calls to
-.Fn PacketAliasRedirectPort
-will have precedence over address mappings designated by
-.Fn PacketAliasRedirectAddr .
-.Pp
-This function returns a pointer which can subsequently be used by
-.Fn PacketAliasRedirectDelete .
-If
-.Dv NULL
-is returned, then the function call did not complete successfully.
-.Ed
-.Pp
-.Ft int
-.Fo PacketAliasAddServer
-.Fa "struct alias_link *link"
-.Fa "struct in_addr addr"
-.Fa "u_short port"
-.Fc
-.Bd -ragged -offset indent
-This function sets the
-.Fa link
-up for Load Sharing using IP Network Address Translation (RFC 2391, LSNAT).
-LSNAT operates as follows.
-A client attempts to access a server by using the server virtual address.
-The LSNAT router transparently redirects the request to one of the hosts
-in server pool, selected using a real-time load sharing algorithm.
-Multiple sessions may be initiated from the same client, and each session
-could be directed to a different host based on load balance across server
-pool hosts at the time.
-If load share is desired for just a few specific services, the configuration
-on LSNAT could be defined to restrict load share for just the services
-desired.
-.Pp
-Currently, only the simplest selection algorithm is implemented, where a
-host is selected on a round-robin basis only, without regard to load on
-the host.
-.Pp
-First, the
-.Fa link
-is created by either
-.Fn PacketAliasRedirectPort
-or
-.Fn PacketAliasRedirectAddr .
-Then,
-.Fn PacketAliasAddServer
-is called multiple times to add entries to the
-.Fa link Ns 's
-server pool.
-.Pp
-For links created with
-.Fn PacketAliasRedirectAddr ,
-the
-.Fa port
-argument is ignored and could have any value, e.g. htons(~0).
-.Pp
-This function returns 0 on success, -1 otherwise.
-.Ed
-.Pp
-.Ft void
-.Fn PacketAliasRedirectDelete "struct alias_link *link"
-.Bd -ragged -offset indent
-This function will delete a specific static redirect rule entered by
-.Fn PacketAliasRedirectPort
-or
-.Fn PacketAliasRedirectAddr .
-The parameter
-.Fa link
-is the pointer returned by either of the redirection functions.
-If an invalid pointer is passed to
-.Fn PacketAliasRedirectDelete ,
-then a program crash or unpredictable operation could result, so it is
-necessary to be careful using this function.
-.Ed
-.Pp
-.Ft int
-.Fn PacketAliasProxyRule "const char *cmd"
-.Bd -ragged -offset indent
-The passed
-.Fa cmd
-string consists of one or more pairs of words.
-The first word in each pair is a token and the second is the value that
-should be applied for that token.
-Tokens and their argument types are as follows:
-.Bl -tag -width indent
-.It Cm type encode_ip_hdr | encode_tcp_stream | no_encode
-In order to support transparent proxying, it is necessary to somehow
-pass the original address and port information into the new destination
-server.
-If
-.Cm encode_ip_hdr
-is specified, the original address and port is passed as an extra IP
-option.
-If
-.Cm encode_tcp_stream
-is specified, the original address and port is passed as the first
-piece of data in the TCP stream in the format
-.Dq DEST Ar IP port .
-.It Cm port Ar portnum
-Only packets with the destination port
-.Ar portnum
-are proxied.
-.It Cm server Ar host Ns Xo
-.Op : Ns Ar portnum
-.Xc
-This specifies the
-.Ar host
-and
-.Ar portnum
-that the data is to be redirected to.
-.Ar host
-must be an IP address rather than a DNS host name.
-If
-.Ar portnum
-is not specified, the destination port number is not changed.
-.Pp
-The
-.Ar server
-specification is mandatory unless the
-.Cm delete
-command is being used.
-.It Cm rule Ar index
-Normally, each call to
-.Fn PacketAliasProxyRule
-inserts the next rule at the start of a linear list of rules.
-If an
-.Ar index
-is specified, the new rule will be checked after all rules with lower
-indices.
-Calls to
-.Fn PacketAliasProxyRule
-that do not specify a rule are assigned rule 0.
-.It Cm delete Ar index
-This token and its argument MUST NOT be used with any other tokens.
-When used, all existing rules with the given
-.Ar index
-are deleted.
-.It Cm proto tcp | udp
-If specified, only packets of the given protocol type are matched.
-.It Cm src Ar IP Ns Xo
-.Op / Ns Ar bits
-.Xc
-If specified, only packets with a source address matching the given
-.Ar IP
-are matched.
-If
-.Ar bits
-is also specified, then the first
-.Ar bits
-bits of
-.Ar IP
-are taken as a network specification, and all IP addresses from that
-network will be matched.
-.It Cm dst Ar IP Ns Xo
-.Op / Ns Ar bits
-.Xc
-If specified, only packets with a destination address matching the given
-.Ar IP
-are matched.
-If
-.Ar bits
-is also specified, then the first
-.Ar bits
-bits of
-.Ar IP
-are taken as a network specification, and all IP addresses from that
-network will be matched.
-.El
-.Pp
-This function is usually used to redirect outgoing connections for
-internal machines that are not permitted certain types of internet
-access, or to restrict access to certain external machines.
-.Ed
-.Pp
-.Ft struct alias_link *
-.Fo PacketAliasRedirectProto
-.Fa "struct in_addr local_addr"
-.Fa "struct in_addr remote_addr"
-.Fa "struct in_addr alias_addr"
-.Fa "u_char proto"
-.Fc
-.Bd -ragged -offset indent
-This function specifies that any IP packet with protocol number of
-.Fa proto
-from a given remote address to an alias address be
-redirected to a specified local address.
-.Pp
-If
-.Fa local_addr
-or
-.Fa alias_addr
-is zero, this indicates that the packet aliasing address as established
-by
-.Fn PacketAliasSetAddress
-is to be used.
-Even if
-.Fn PacketAliasSetAddress
-is called to change the address after
-.Fn PacketAliasRedirectProto
-is called, a zero reference will track this change.
-.Pp
-If
-.Fa remote_addr
-is zero, this indicates to redirect packets from any remote address.
-Non-zero remote addresses can sometimes be useful for firewalling.
-.Pp
-If two calls to
-.Fn PacketAliasRedirectProto
-overlap in their address specifications, then the most recent call
-will have precedence.
-.Pp
-This function returns a pointer which can subsequently be used by
-.Fn PacketAliasRedirectDelete .
-If
-.Dv NULL
-is returned, then the function call did not complete successfully.
-.Ed
-.Sh FRAGMENT HANDLING
-The functions in this section are used to deal with incoming fragments.
-.Pp
-Outgoing fragments are handled within
-.Fn PacketAliasOut
-by changing the address according to any applicable mapping set by
-.Fn PacketAliasRedirectAddr ,
-or the default aliasing address set by
-.Fn PacketAliasSetAddress .
-.Pp
-Incoming fragments are handled in one of two ways.
-If the header of a fragmented IP packet has already been seen, then all
-subsequent fragments will be re-mapped in the same manner the header
-fragment was.
-Fragments which arrive before the header are saved and then retrieved
-once the header fragment has been resolved.
-.Pp
-.Ft int
-.Fn PacketAliasSaveFragment "char *ptr"
-.Bd -ragged -offset indent
-When
-.Fn PacketAliasIn
-returns
-.Dv PKT_ALIAS_UNRESOLVED_FRAGMENT ,
-this function can be used to save the pointer to the unresolved fragment.
-.Pp
-It is implicitly assumed that
-.Fa ptr
-points to a block of memory allocated by
-.Xr malloc 3 .
-If the fragment is never resolved, the packet aliasing engine will
-automatically free the memory after a timeout period.
-[Eventually this function should be modified so that a callback function
-for freeing memory is passed as an argument.]
-.Pp
-This function returns
-.Dv PKT_ALIAS_OK
-if it was successful and
-.Dv PKT_ALIAS_ERROR
-if there was an error.
-.Ed
-.Pp
-.Ft char *
-.Fn PacketAliasGetFragment "char *buffer"
-.Bd -ragged -offset indent
-This function can be used to retrieve fragment pointers saved by
-.Fn PacketAliasSaveFragment .
-The IP header fragment pointed to by
-.Fa buffer
-is the header fragment indicated when
-.Fn PacketAliasIn
-returns
-.Dv PKT_ALIAS_FOUND_HEADER_FRAGMENT .
-Once a fragment pointer is retrieved, it becomes the calling program's
-responsibility to free the dynamically allocated memory for the fragment.
-.Pp
-.Fn PacketAliasGetFragment
-can be called sequentially until there are no more fragments available,
-at which time it returns
-.Dv NULL .
-.Ed
-.Pp
-.Ft void
-.Fn PacketAliasFragmentIn "char *header" "char *fragment"
-.Bd -ragged -offset indent
-When a fragment is retrieved with
-.Fn PacketAliasGetFragment ,
-it can then be de-aliased with a call to
-.Fn PacketAliasFragmentIn .
-The
-.Fa header
-argument is the pointer to a header fragment used as a template, and
-.Fa fragment
-is the pointer to the packet to be de-aliased.
-.Ed
-.Sh MISCELLANEOUS FUNCTIONS
-.Ft void
-.Fn PacketAliasSetTarget "struct in_addr addr"
-.Bd -ragged -offset indent
-When an incoming packet not associated with any pre-existing aliasing link
-arrives at the host machine, it will be sent to the address indicated by a
-call to
-.Fn PacketAliasSetTarget .
-.Pp
-If this function is called with an
-.Dv INADDR_NONE
-address argument, then all new incoming packets go to the address set by
-.Fn PacketAliasSetAddress .
-.Pp
-If this function is not called, or is called with an
-.Dv INADDR_ANY
-address argument, then all new incoming packets go to the address specified
-in the packet.
-This allows external machines to talk directly to internal machines if they
-can route packets to the machine in question.
-.Ed
-.Pp
-.Ft int
-.Fn PacketAliasCheckNewLink void
-.Bd -ragged -offset indent
-This function returns a non-zero value when a new aliasing link is created.
-In circumstances where incoming traffic is being sequentially sent to
-different local servers, this function can be used to trigger when
-.Fn PacketAliasSetTarget
-is called to change the default target address.
-.Ed
-.Pp
-.Ft u_short
-.Fn PacketAliasInternetChecksum "u_short *buffer" "int nbytes"
-.Bd -ragged -offset indent
-This is a utility function that does not seem to be available elsewhere and
-is included as a convenience.
-It computes the internet checksum, which is used in both IP and
-protocol-specific headers (TCP, UDP, ICMP).
-.Pp
-The
-.Fa buffer
-argument points to the data block to be checksummed, and
-.Fa nbytes
-is the number of bytes.
-The 16-bit checksum field should be zeroed before computing the checksum.
-.Pp
-Checksums can also be verified by operating on a block of data including
-its checksum.
-If the checksum is valid,
-.Fn PacketAliasInternetChecksum
-will return zero.
-.Ed
-.Pp
-.Ft int
-.Fn PacketUnaliasOut "char *buffer" "int maxpacketsize"
-.Bd -ragged -offset indent
-An outgoing packet, which has already been aliased,
-has its private address/port information restored by this function.
-The IP packet is pointed to by
-.Fa buffer ,
-and
-.Fa maxpacketsize
-is provided for error checking purposes.
-This function can be used if an already-aliased packet needs to have its
-original IP header restored for further processing (eg. logging).
-.Ed
-.Sh BUGS
-PPTP aliasing does not work when more than one internal client
-connects to the same external server at the same time, because
-PPTP requires a single TCP control connection to be established
-between any two IP addresses.
-.Sh AUTHORS
-.An Charles Mott Aq cm@linktel.net ,
-versions 1.0 - 1.8, 2.0 - 2.4.
-.An Eivind Eklund Aq eivind@FreeBSD.org ,
-versions 1.8b, 1.9 and 2.5.
-Added IRC DCC support as well as contributing a number of architectural
-improvements; added the firewall bypass for FTP/IRC DCC.
-.An Erik Salander Aq erik@whistle.com
-added support for PPTP and RTSP.
-.An Junichi Satoh Aq junichi@junichi.org
-added support for RTSP/PNA.
-.Sh ACKNOWLEDGMENTS
-Listed below, in approximate chronological order, are individuals who
-have provided valuable comments and/or debugging assistance.
-.Pp
-.Bd -ragged -offset indent
-.An -split
-.An Gary Roberts
-.An Tom Torrance
-.An Reto Burkhalter
-.An Martin Renters
-.An Brian Somers
-.An Paul Traina
-.An Ari Suutari
-.An Dave Remien
-.An J. Fortes
-.An Andrzej Bialecki
-.An Gordon Burditt
-.Ed
-.Sh CONCEPTUAL BACKGROUND
-This section is intended for those who are planning to modify the source
-code or want to create somewhat esoteric applications using the packet
-aliasing functions.
-.Pp
-The conceptual framework under which the packet aliasing engine operates
-is described here.
-Central to the discussion is the idea of an
-.Em aliasing link
-which describes the relationship for a given packet transaction between
-the local machine, aliased identity and remote machine.
-It is discussed how such links come into existence and are destroyed.
-.Ss ALIASING LINKS
-There is a notion of an
-.Em aliasing link ,
-which is a 7-tuple describing a specific translation:
-.Bd -literal -offset indent
-(local addr, local port, alias addr, alias port,
- remote addr, remote port, protocol)
-.Ed
-.Pp
-Outgoing packets have the local address and port number replaced with the
-alias address and port number.
-Incoming packets undergo the reverse process.
-The packet aliasing engine attempts to match packets against an internal
-table of aliasing links to determine how to modify a given IP packet.
-Both the IP header and protocol dependent headers are modified as necessary.
-Aliasing links are created and deleted as necessary according to network
-traffic.
-.Pp
-Protocols can be TCP, UDP or even ICMP in certain circumstances.
-(Some types of ICMP packets can be aliased according to sequence or ID
-number which acts as an equivalent port number for identifying how
-individual packets should be handled.)
-.Pp
-Each aliasing link must have a unique combination of the following five
-quantities: alias address/port, remote address/port and protocol.
-This ensures that several machines on a local network can share the
-same aliasing IP address.
-In cases where conflicts might arise, the aliasing port is chosen so that
-uniqueness is maintained.
-.Ss STATIC AND DYNAMIC LINKS
-Aliasing links can either be static or dynamic.
-Static links persist indefinitely and represent fixed rules for translating
-IP packets.
-Dynamic links come into existence for a specific TCP connection or UDP
-transaction or ICMP ECHO sequence.
-For the case of TCP, the connection can be monitored to see when the
-associated aliasing link should be deleted.
-Aliasing links for UDP transactions (and ICMP ECHO and TIMESTAMP requests)
-work on a simple timeout rule.
-When no activity is observed on a dynamic link for a certain amount of time
-it is automatically deleted.
-Timeout rules also apply to TCP connections which do not open or close
-properly.
-.Ss PARTIALLY SPECIFIED ALIASING LINKS
-Aliasing links can be partially specified, meaning that the remote address
-and/or remote port are unknown.
-In this case, when a packet matching the incomplete specification is found,
-a fully specified dynamic link is created.
-If the original partially specified link is dynamic, it will be deleted
-after the fully specified link is created, otherwise it will persist.
-.Pp
-For instance, a partially specified link might be
-.Bd -literal -offset indent
-(192.168.0.4, 23, 204.228.203.215, 8066, 0, 0, tcp)
-.Ed
-.Pp
-The zeros denote unspecified components for the remote address and port.
-If this link were static it would have the effect of redirecting all
-incoming traffic from port 8066 of 204.228.203.215 to port 23 (telnet)
-of machine 192.168.0.4 on the local network.
-Each individual telnet connection would initiate the creation of a distinct
-dynamic link.
-.Ss DYNAMIC LINK CREATION
-In addition to aliasing links, there are also address mappings that can be
-stored within the internal data table of the packet aliasing mechanism.
-.Bd -literal -offset indent
-(local addr, alias addr)
-.Ed
-.Pp
-Address mappings are searched when creating new dynamic links.
-.Pp
-All outgoing packets from the local network automatically create a dynamic
-link if they do not match an already existing fully specified link.
-If an address mapping exists for the outgoing packet, this determines
-the alias address to be used.
-If no mapping exists, then a default address, usually the address of the
-packet aliasing host, is used.
-If necessary, this default address can be changed as often as each individual
-packet arrives.
-.Pp
-The aliasing port number is determined such that the new dynamic link does
-not conflict with any existing links.
-In the default operating mode, the packet aliasing engine attempts to set
-the aliasing port equal to the local port number.
-If this results in a conflict, then port numbers are randomly chosen until
-a unique aliasing link can be established.
-In an alternate operating mode, the first choice of an aliasing port is also
-random and unrelated to the local port number.
diff --git a/sys/netinet/tcp_reass.c b/sys/netinet/tcp_reass.c
deleted file mode 100644
index 0683047c0b46..000000000000
--- a/sys/netinet/tcp_reass.c
+++ /dev/null
@@ -1,2997 +0,0 @@
-/*
- * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)tcp_input.c 8.12 (Berkeley) 5/24/95
- * $FreeBSD$
- */
-
-#include "opt_ipfw.h" /* for ipfw_fwd */
-#include "opt_inet6.h"
-#include "opt_ipsec.h"
-#include "opt_mac.h"
-#include "opt_tcpdebug.h"
-#include "opt_tcp_input.h"
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/mac.h>
-#include <sys/malloc.h>
-#include <sys/mbuf.h>
-#include <sys/proc.h> /* for proc0 declaration */
-#include <sys/protosw.h>
-#include <sys/signalvar.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/sysctl.h>
-#include <sys/syslog.h>
-#include <sys/systm.h>
-
-#include <machine/cpu.h> /* before tcp_seq.h, for tcp_random18() */
-
-#include <net/if.h>
-#include <net/route.h>
-
-#include <netinet/in.h>
-#include <netinet/in_pcb.h>
-#include <netinet/in_systm.h>
-#include <netinet/in_var.h>
-#include <netinet/ip.h>
-#include <netinet/ip_icmp.h> /* for ICMP_BANDLIM */
-#include <netinet/icmp_var.h> /* for ICMP_BANDLIM */
-#include <netinet/ip_var.h>
-#include <netinet/ip6.h>
-#include <netinet/icmp6.h>
-#include <netinet6/in6_pcb.h>
-#include <netinet6/ip6_var.h>
-#include <netinet6/nd6.h>
-#include <netinet/tcp.h>
-#include <netinet/tcp_fsm.h>
-#include <netinet/tcp_seq.h>
-#include <netinet/tcp_timer.h>
-#include <netinet/tcp_var.h>
-#include <netinet6/tcp6_var.h>
-#include <netinet/tcpip.h>
-#ifdef TCPDEBUG
-#include <netinet/tcp_debug.h>
-#endif /* TCPDEBUG */
-
-#ifdef FAST_IPSEC
-#include <netipsec/ipsec.h>
-#include <netipsec/ipsec6.h>
-#endif /*FAST_IPSEC*/
-
-#ifdef IPSEC
-#include <netinet6/ipsec.h>
-#include <netinet6/ipsec6.h>
-#include <netkey/key.h>
-#endif /*IPSEC*/
-
-#include <machine/in_cksum.h>
-
-MALLOC_DEFINE(M_TSEGQ, "tseg_qent", "TCP segment queue entry");
-
-static const int tcprexmtthresh = 3;
-tcp_cc tcp_ccgen;
-
-struct tcpstat tcpstat;
-SYSCTL_STRUCT(_net_inet_tcp, TCPCTL_STATS, stats, CTLFLAG_RW,
- &tcpstat , tcpstat, "TCP statistics (struct tcpstat, netinet/tcp_var.h)");
-
-static int log_in_vain = 0;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, log_in_vain, CTLFLAG_RW,
- &log_in_vain, 0, "Log all incoming TCP connections");
-
-static int blackhole = 0;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, blackhole, CTLFLAG_RW,
- &blackhole, 0, "Do not send RST when dropping refused connections");
-
-int tcp_delack_enabled = 1;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, delayed_ack, CTLFLAG_RW,
- &tcp_delack_enabled, 0,
- "Delay ACK to try and piggyback it onto a data packet");
-
-#ifdef TCP_DROP_SYNFIN
-static int drop_synfin = 0;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, drop_synfin, CTLFLAG_RW,
- &drop_synfin, 0, "Drop TCP packets with SYN+FIN set");
-#endif
-
-static int tcp_do_rfc3042 = 0;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, rfc3042, CTLFLAG_RW,
- &tcp_do_rfc3042, 0, "Enable RFC 3042 (Limited Transmit)");
-
-static int tcp_do_rfc3390 = 0;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, rfc3390, CTLFLAG_RW,
- &tcp_do_rfc3390, 0,
- "Enable RFC 3390 (Increasing TCP's Initial Congestion Window)");
-
-struct inpcbhead tcb;
-#define tcb6 tcb /* for KAME src sync over BSD*'s */
-struct inpcbinfo tcbinfo;
-struct mtx *tcbinfo_mtx;
-
-static void tcp_dooptions(struct tcpopt *, u_char *, int, int);
-static void tcp_pulloutofband(struct socket *,
- struct tcphdr *, struct mbuf *, int);
-static int tcp_reass(struct tcpcb *, struct tcphdr *, int *,
- struct mbuf *);
-static void tcp_xmit_timer(struct tcpcb *, int);
-static void tcp_newreno_partial_ack(struct tcpcb *, struct tcphdr *);
-static int tcp_timewait(struct tcptw *, struct tcpopt *,
- struct tcphdr *, struct mbuf *, int);
-
-/* Neighbor Discovery, Neighbor Unreachability Detection Upper layer hint. */
-#ifdef INET6
-#define ND6_HINT(tp) \
-do { \
- if ((tp) && (tp)->t_inpcb && \
- ((tp)->t_inpcb->inp_vflag & INP_IPV6) != 0 && \
- (tp)->t_inpcb->in6p_route.ro_rt) \
- nd6_nud_hint((tp)->t_inpcb->in6p_route.ro_rt, NULL, 0); \
-} while (0)
-#else
-#define ND6_HINT(tp)
-#endif
-
-/*
- * Indicate whether this ack should be delayed. We can delay the ack if
- * - there is no delayed ack timer in progress and
- * - our last ack wasn't a 0-sized window. We never want to delay
- * the ack that opens up a 0-sized window and
- * - delayed acks are enabled or
- * - this is a half-synchronized T/TCP connection.
- */
-#define DELAY_ACK(tp) \
- ((!callout_active(tp->tt_delack) && \
- (tp->t_flags & TF_RXWIN0SENT) == 0) && \
- (tcp_delack_enabled || (tp->t_flags & TF_NEEDSYN)))
-
-static int
-tcp_reass(tp, th, tlenp, m)
- register struct tcpcb *tp;
- register struct tcphdr *th;
- int *tlenp;
- struct mbuf *m;
-{
- struct tseg_qent *q;
- struct tseg_qent *p = NULL;
- struct tseg_qent *nq;
- struct tseg_qent *te;
- struct socket *so = tp->t_inpcb->inp_socket;
- int flags;
-
- /*
- * Call with th==0 after become established to
- * force pre-ESTABLISHED data up to user socket.
- */
- if (th == 0)
- goto present;
-
- /* Allocate a new queue entry. If we can't, just drop the pkt. XXX */
- MALLOC(te, struct tseg_qent *, sizeof (struct tseg_qent), M_TSEGQ,
- M_NOWAIT);
- if (te == NULL) {
- tcpstat.tcps_rcvmemdrop++;
- m_freem(m);
- return (0);
- }
-
- /*
- * Find a segment which begins after this one does.
- */
- LIST_FOREACH(q, &tp->t_segq, tqe_q) {
- if (SEQ_GT(q->tqe_th->th_seq, th->th_seq))
- break;
- p = q;
- }
-
- /*
- * If there is a preceding segment, it may provide some of
- * our data already. If so, drop the data from the incoming
- * segment. If it provides all of our data, drop us.
- */
- if (p != NULL) {
- register int i;
- /* conversion to int (in i) handles seq wraparound */
- i = p->tqe_th->th_seq + p->tqe_len - th->th_seq;
- if (i > 0) {
- if (i >= *tlenp) {
- tcpstat.tcps_rcvduppack++;
- tcpstat.tcps_rcvdupbyte += *tlenp;
- m_freem(m);
- FREE(te, M_TSEGQ);
- /*
- * Try to present any queued data
- * at the left window edge to the user.
- * This is needed after the 3-WHS
- * completes.
- */
- goto present; /* ??? */
- }
- m_adj(m, i);
- *tlenp -= i;
- th->th_seq += i;
- }
- }
- tcpstat.tcps_rcvoopack++;
- tcpstat.tcps_rcvoobyte += *tlenp;
-
- /*
- * While we overlap succeeding segments trim them or,
- * if they are completely covered, dequeue them.
- */
- while (q) {
- register int i = (th->th_seq + *tlenp) - q->tqe_th->th_seq;
- if (i <= 0)
- break;
- if (i < q->tqe_len) {
- q->tqe_th->th_seq += i;
- q->tqe_len -= i;
- m_adj(q->tqe_m, i);
- break;
- }
-
- nq = LIST_NEXT(q, tqe_q);
- LIST_REMOVE(q, tqe_q);
- m_freem(q->tqe_m);
- FREE(q, M_TSEGQ);
- q = nq;
- }
-
- /* Insert the new segment queue entry into place. */
- te->tqe_m = m;
- te->tqe_th = th;
- te->tqe_len = *tlenp;
-
- if (p == NULL) {
- LIST_INSERT_HEAD(&tp->t_segq, te, tqe_q);
- } else {
- LIST_INSERT_AFTER(p, te, tqe_q);
- }
-
-present:
- /*
- * Present data to user, advancing rcv_nxt through
- * completed sequence space.
- */
- if (!TCPS_HAVEESTABLISHED(tp->t_state))
- return (0);
- q = LIST_FIRST(&tp->t_segq);
- if (!q || q->tqe_th->th_seq != tp->rcv_nxt)
- return (0);
- do {
- tp->rcv_nxt += q->tqe_len;
- flags = q->tqe_th->th_flags & TH_FIN;
- nq = LIST_NEXT(q, tqe_q);
- LIST_REMOVE(q, tqe_q);
- if (so->so_state & SS_CANTRCVMORE)
- m_freem(q->tqe_m);
- else
- sbappend(&so->so_rcv, q->tqe_m);
- FREE(q, M_TSEGQ);
- q = nq;
- } while (q && q->tqe_th->th_seq == tp->rcv_nxt);
- ND6_HINT(tp);
- sorwakeup(so);
- return (flags);
-}
-
-/*
- * TCP input routine, follows pages 65-76 of the
- * protocol specification dated September, 1981 very closely.
- */
-#ifdef INET6
-int
-tcp6_input(mp, offp, proto)
- struct mbuf **mp;
- int *offp, proto;
-{
- register struct mbuf *m = *mp;
- struct in6_ifaddr *ia6;
-
- IP6_EXTHDR_CHECK(m, *offp, sizeof(struct tcphdr), IPPROTO_DONE);
-
- /*
- * draft-itojun-ipv6-tcp-to-anycast
- * better place to put this in?
- */
- ia6 = ip6_getdstifaddr(m);
- if (ia6 && (ia6->ia6_flags & IN6_IFF_ANYCAST)) {
- struct ip6_hdr *ip6;
-
- ip6 = mtod(m, struct ip6_hdr *);
- icmp6_error(m, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR,
- (caddr_t)&ip6->ip6_dst - (caddr_t)ip6);
- return IPPROTO_DONE;
- }
-
- tcp_input(m, *offp);
- return IPPROTO_DONE;
-}
-#endif
-
-void
-tcp_input(m, off0)
- register struct mbuf *m;
- int off0;
-{
- register struct tcphdr *th;
- register struct ip *ip = NULL;
- register struct ipovly *ipov;
- register struct inpcb *inp = NULL;
- u_char *optp = NULL;
- int optlen = 0;
- int len, tlen, off;
- int drop_hdrlen;
- register struct tcpcb *tp = 0;
- register int thflags;
- struct socket *so = 0;
- int todrop, acked, ourfinisacked, needoutput = 0;
- u_long tiwin;
- struct tcpopt to; /* options in this segment */
- struct rmxp_tao *taop; /* pointer to our TAO cache entry */
- struct rmxp_tao tao_noncached; /* in case there's no cached entry */
- int headlocked = 0;
- struct sockaddr_in *next_hop = NULL;
- int rstreason; /* For badport_bandlim accounting purposes */
-
- struct ip6_hdr *ip6 = NULL;
-#ifdef INET6
- int isipv6;
-#else
- const int isipv6 = 0;
-#endif
-
-#ifdef TCPDEBUG
- /*
- * The size of tcp_saveipgen must be the size of the max ip header,
- * now IPv6.
- */
- u_char tcp_saveipgen[40];
- struct tcphdr tcp_savetcp;
- short ostate = 0;
-#endif
-
- /* Grab info from MT_TAG mbufs prepended to the chain. */
- for (;m && m->m_type == MT_TAG; m = m->m_next) {
- if (m->_m_tag_id == PACKET_TAG_IPFORWARD)
- next_hop = (struct sockaddr_in *)m->m_hdr.mh_data;
- }
-#ifdef INET6
- isipv6 = (mtod(m, struct ip *)->ip_v == 6) ? 1 : 0;
-#endif
- bzero((char *)&to, sizeof(to));
-
- tcpstat.tcps_rcvtotal++;
-
- if (isipv6) {
- /* IP6_EXTHDR_CHECK() is already done at tcp6_input() */
- ip6 = mtod(m, struct ip6_hdr *);
- tlen = sizeof(*ip6) + ntohs(ip6->ip6_plen) - off0;
- if (in6_cksum(m, IPPROTO_TCP, off0, tlen)) {
- tcpstat.tcps_rcvbadsum++;
- goto drop;
- }
- th = (struct tcphdr *)((caddr_t)ip6 + off0);
-
- /*
- * Be proactive about unspecified IPv6 address in source.
- * As we use all-zero to indicate unbounded/unconnected pcb,
- * unspecified IPv6 address can be used to confuse us.
- *
- * Note that packets with unspecified IPv6 destination is
- * already dropped in ip6_input.
- */
- if (IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) {
- /* XXX stat */
- goto drop;
- }
- } else {
- /*
- * Get IP and TCP header together in first mbuf.
- * Note: IP leaves IP header in first mbuf.
- */
- if (off0 > sizeof (struct ip)) {
- ip_stripoptions(m, (struct mbuf *)0);
- off0 = sizeof(struct ip);
- }
- if (m->m_len < sizeof (struct tcpiphdr)) {
- if ((m = m_pullup(m, sizeof (struct tcpiphdr))) == 0) {
- tcpstat.tcps_rcvshort++;
- return;
- }
- }
- ip = mtod(m, struct ip *);
- ipov = (struct ipovly *)ip;
- th = (struct tcphdr *)((caddr_t)ip + off0);
- tlen = ip->ip_len;
-
- if (m->m_pkthdr.csum_flags & CSUM_DATA_VALID) {
- if (m->m_pkthdr.csum_flags & CSUM_PSEUDO_HDR)
- th->th_sum = m->m_pkthdr.csum_data;
- else
- th->th_sum = in_pseudo(ip->ip_src.s_addr,
- ip->ip_dst.s_addr,
- htonl(m->m_pkthdr.csum_data +
- ip->ip_len +
- IPPROTO_TCP));
- th->th_sum ^= 0xffff;
- } else {
- /*
- * Checksum extended TCP header and data.
- */
- len = sizeof (struct ip) + tlen;
- bzero(ipov->ih_x1, sizeof(ipov->ih_x1));
- ipov->ih_len = (u_short)tlen;
- ipov->ih_len = htons(ipov->ih_len);
- th->th_sum = in_cksum(m, len);
- }
- if (th->th_sum) {
- tcpstat.tcps_rcvbadsum++;
- goto drop;
- }
-#ifdef INET6
- /* Re-initialization for later version check */
- ip->ip_v = IPVERSION;
-#endif
- }
-
- /*
- * Check that TCP offset makes sense,
- * pull out TCP options and adjust length. XXX
- */
- off = th->th_off << 2;
- if (off < sizeof (struct tcphdr) || off > tlen) {
- tcpstat.tcps_rcvbadoff++;
- goto drop;
- }
- tlen -= off; /* tlen is used instead of ti->ti_len */
- if (off > sizeof (struct tcphdr)) {
- if (isipv6) {
- IP6_EXTHDR_CHECK(m, off0, off, );
- ip6 = mtod(m, struct ip6_hdr *);
- th = (struct tcphdr *)((caddr_t)ip6 + off0);
- } else {
- if (m->m_len < sizeof(struct ip) + off) {
- if ((m = m_pullup(m, sizeof (struct ip) + off))
- == 0) {
- tcpstat.tcps_rcvshort++;
- return;
- }
- ip = mtod(m, struct ip *);
- ipov = (struct ipovly *)ip;
- th = (struct tcphdr *)((caddr_t)ip + off0);
- }
- }
- optlen = off - sizeof (struct tcphdr);
- optp = (u_char *)(th + 1);
- }
- thflags = th->th_flags;
-
-#ifdef TCP_DROP_SYNFIN
- /*
- * If the drop_synfin option is enabled, drop all packets with
- * both the SYN and FIN bits set. This prevents e.g. nmap from
- * identifying the TCP/IP stack.
- *
- * This is a violation of the TCP specification.
- */
- if (drop_synfin && (thflags & (TH_SYN|TH_FIN)) == (TH_SYN|TH_FIN))
- goto drop;
-#endif
-
- /*
- * Convert TCP protocol specific fields to host format.
- */
- th->th_seq = ntohl(th->th_seq);
- th->th_ack = ntohl(th->th_ack);
- th->th_win = ntohs(th->th_win);
- th->th_urp = ntohs(th->th_urp);
-
- /*
- * Delay dropping TCP, IP headers, IPv6 ext headers, and TCP options,
- * until after ip6_savecontrol() is called and before other functions
- * which don't want those proto headers.
- * Because ip6_savecontrol() is going to parse the mbuf to
- * search for data to be passed up to user-land, it wants mbuf
- * parameters to be unchanged.
- * XXX: the call of ip6_savecontrol() has been obsoleted based on
- * latest version of the advanced API (20020110).
- */
- drop_hdrlen = off0 + off;
-
- /*
- * Locate pcb for segment.
- */
- INP_INFO_WLOCK(&tcbinfo);
- headlocked = 1;
-findpcb:
- /* IPFIREWALL_FORWARD section */
- if (next_hop != NULL && isipv6 == 0) { /* IPv6 support is not yet */
- /*
- * Transparently forwarded. Pretend to be the destination.
- * already got one like this?
- */
- inp = in_pcblookup_hash(&tcbinfo, ip->ip_src, th->th_sport,
- ip->ip_dst, th->th_dport,
- 0, m->m_pkthdr.rcvif);
- if (!inp) {
- /* It's new. Try find the ambushing socket. */
- inp = in_pcblookup_hash(&tcbinfo,
- ip->ip_src, th->th_sport,
- next_hop->sin_addr,
- next_hop->sin_port ?
- ntohs(next_hop->sin_port) :
- th->th_dport,
- 1, m->m_pkthdr.rcvif);
- }
- } else {
- if (isipv6)
- inp = in6_pcblookup_hash(&tcbinfo,
- &ip6->ip6_src, th->th_sport,
- &ip6->ip6_dst, th->th_dport,
- 1, m->m_pkthdr.rcvif);
- else
- inp = in_pcblookup_hash(&tcbinfo,
- ip->ip_src, th->th_sport,
- ip->ip_dst, th->th_dport,
- 1, m->m_pkthdr.rcvif);
- }
-
-#ifdef IPSEC
- if (isipv6) {
- if (inp != NULL && ipsec6_in_reject_so(m, inp->inp_socket)) {
- ipsec6stat.in_polvio++;
- goto drop;
- }
- } else {
- if (inp != NULL && ipsec4_in_reject_so(m, inp->inp_socket)) {
- ipsecstat.in_polvio++;
- goto drop;
- }
- }
-#endif
-#ifdef FAST_IPSEC
- if (isipv6) {
- if (inp != NULL && ipsec6_in_reject(m, inp)) {
- goto drop;
- }
- } else
- if (inp != NULL && ipsec4_in_reject(m, inp)) {
- goto drop;
- }
-#endif /*FAST_IPSEC*/
-
- /*
- * If the state is CLOSED (i.e., TCB does not exist) then
- * all data in the incoming segment is discarded.
- * If the TCB exists but is in CLOSED state, it is embryonic,
- * but should either do a listen or a connect soon.
- */
- if (inp == NULL) {
- if (log_in_vain) {
-#ifdef INET6
- char dbuf[INET6_ADDRSTRLEN+2], sbuf[INET6_ADDRSTRLEN+2];
-#else
- char dbuf[4*sizeof "123"], sbuf[4*sizeof "123"];
-#endif
-
- if (isipv6) {
- strcpy(dbuf, "[");
- strcpy(sbuf, "[");
- strcat(dbuf, ip6_sprintf(&ip6->ip6_dst));
- strcat(sbuf, ip6_sprintf(&ip6->ip6_src));
- strcat(dbuf, "]");
- strcat(sbuf, "]");
- } else {
- strcpy(dbuf, inet_ntoa(ip->ip_dst));
- strcpy(sbuf, inet_ntoa(ip->ip_src));
- }
- switch (log_in_vain) {
- case 1:
- if ((thflags & TH_SYN) == 0)
- break;
- case 2:
- log(LOG_INFO,
- "Connection attempt to TCP %s:%d "
- "from %s:%d flags:0x%02x\n",
- dbuf, ntohs(th->th_dport), sbuf,
- ntohs(th->th_sport), thflags);
- break;
- default:
- break;
- }
- }
- if (blackhole) {
- switch (blackhole) {
- case 1:
- if (thflags & TH_SYN)
- goto drop;
- break;
- case 2:
- goto drop;
- default:
- goto drop;
- }
- }
- rstreason = BANDLIM_RST_CLOSEDPORT;
- goto dropwithreset;
- }
- INP_LOCK(inp);
- if (inp->inp_vflag & INP_TIMEWAIT) {
- /*
- * The only option of relevance is TOF_CC, and only if
- * present in a SYN segment. See tcp_timewait().
- */
- if (thflags & TH_SYN)
- tcp_dooptions(&to, optp, optlen, 1);
- if (tcp_timewait((struct tcptw *)inp->inp_ppcb,
- &to, th, m, tlen))
- goto findpcb;
- /*
- * tcp_timewait unlocks inp.
- */
- INP_INFO_WUNLOCK(&tcbinfo);
- return;
- }
- tp = intotcpcb(inp);
- if (tp == 0) {
- INP_UNLOCK(inp);
- rstreason = BANDLIM_RST_CLOSEDPORT;
- goto dropwithreset;
- }
- if (tp->t_state == TCPS_CLOSED)
- goto drop;
-
- /* Unscale the window into a 32-bit value. */
- if ((thflags & TH_SYN) == 0)
- tiwin = th->th_win << tp->snd_scale;
- else
- tiwin = th->th_win;
-
- so = inp->inp_socket;
-#ifdef MAC
- if (mac_check_socket_deliver(so, m))
- goto drop;
-#endif
-#ifdef TCPDEBUG
- if (so->so_options & SO_DEBUG) {
- ostate = tp->t_state;
- if (isipv6)
- bcopy((char *)ip6, (char *)tcp_saveipgen, sizeof(*ip6));
- else
- bcopy((char *)ip, (char *)tcp_saveipgen, sizeof(*ip));
- tcp_savetcp = *th;
- }
-#endif
- if (so->so_options & SO_ACCEPTCONN) {
- struct in_conninfo inc;
-
-#ifdef INET6
- inc.inc_isipv6 = isipv6;
-#endif
- if (isipv6) {
- inc.inc6_faddr = ip6->ip6_src;
- inc.inc6_laddr = ip6->ip6_dst;
- inc.inc6_route.ro_rt = NULL; /* XXX */
- } else {
- inc.inc_faddr = ip->ip_src;
- inc.inc_laddr = ip->ip_dst;
- inc.inc_route.ro_rt = NULL; /* XXX */
- }
- inc.inc_fport = th->th_sport;
- inc.inc_lport = th->th_dport;
-
- /*
- * If the state is LISTEN then ignore segment if it contains
- * a RST. If the segment contains an ACK then it is bad and
- * send a RST. If it does not contain a SYN then it is not
- * interesting; drop it.
- *
- * If the state is SYN_RECEIVED (syncache) and seg contains
- * an ACK, but not for our SYN/ACK, send a RST. If the seg
- * contains a RST, check the sequence number to see if it
- * is a valid reset segment.
- */
- if ((thflags & (TH_RST|TH_ACK|TH_SYN)) != TH_SYN) {
- if ((thflags & (TH_RST|TH_ACK|TH_SYN)) == TH_ACK) {
- if (!syncache_expand(&inc, th, &so, m)) {
- /*
- * No syncache entry, or ACK was not
- * for our SYN/ACK. Send a RST.
- */
- tcpstat.tcps_badsyn++;
- rstreason = BANDLIM_RST_OPENPORT;
- goto dropwithreset;
- }
- if (so == NULL) {
- /*
- * Could not complete 3-way handshake,
- * connection is being closed down, and
- * syncache will free mbuf.
- */
- INP_UNLOCK(inp);
- INP_INFO_WUNLOCK(&tcbinfo);
- return;
- }
- /*
- * Socket is created in state SYN_RECEIVED.
- * Continue processing segment.
- */
- INP_UNLOCK(inp);
- inp = sotoinpcb(so);
- INP_LOCK(inp);
- tp = intotcpcb(inp);
- /*
- * This is what would have happened in
- * tcp_output() when the SYN,ACK was sent.
- */
- tp->snd_up = tp->snd_una;
- tp->snd_max = tp->snd_nxt = tp->iss + 1;
- tp->last_ack_sent = tp->rcv_nxt;
- /*
- * RFC1323: The window in SYN & SYN/ACK
- * segments is never scaled.
- */
- tp->snd_wnd = tiwin; /* unscaled */
- goto after_listen;
- }
- if (thflags & TH_RST) {
- syncache_chkrst(&inc, th);
- goto drop;
- }
- if (thflags & TH_ACK) {
- syncache_badack(&inc);
- tcpstat.tcps_badsyn++;
- rstreason = BANDLIM_RST_OPENPORT;
- goto dropwithreset;
- }
- goto drop;
- }
-
- /*
- * Segment's flags are (SYN) or (SYN|FIN).
- */
-#ifdef INET6
- /*
- * If deprecated address is forbidden,
- * we do not accept SYN to deprecated interface
- * address to prevent any new inbound connection from
- * getting established.
- * When we do not accept SYN, we send a TCP RST,
- * with deprecated source address (instead of dropping
- * it). We compromise it as it is much better for peer
- * to send a RST, and RST will be the final packet
- * for the exchange.
- *
- * If we do not forbid deprecated addresses, we accept
- * the SYN packet. RFC2462 does not suggest dropping
- * SYN in this case.
- * If we decipher RFC2462 5.5.4, it says like this:
- * 1. use of deprecated addr with existing
- * communication is okay - "SHOULD continue to be
- * used"
- * 2. use of it with new communication:
- * (2a) "SHOULD NOT be used if alternate address
- * with sufficient scope is available"
- * (2b) nothing mentioned otherwise.
- * Here we fall into (2b) case as we have no choice in
- * our source address selection - we must obey the peer.
- *
- * The wording in RFC2462 is confusing, and there are
- * multiple description text for deprecated address
- * handling - worse, they are not exactly the same.
- * I believe 5.5.4 is the best one, so we follow 5.5.4.
- */
- if (isipv6 && !ip6_use_deprecated) {
- struct in6_ifaddr *ia6;
-
- if ((ia6 = ip6_getdstifaddr(m)) &&
- (ia6->ia6_flags & IN6_IFF_DEPRECATED)) {
- INP_UNLOCK(inp);
- tp = NULL;
- rstreason = BANDLIM_RST_OPENPORT;
- goto dropwithreset;
- }
- }
-#endif
- /*
- * If it is from this socket, drop it, it must be forged.
- * Don't bother responding if the destination was a broadcast.
- */
- if (th->th_dport == th->th_sport) {
- if (isipv6) {
- if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
- &ip6->ip6_src))
- goto drop;
- } else {
- if (ip->ip_dst.s_addr == ip->ip_src.s_addr)
- goto drop;
- }
- }
- /*
- * RFC1122 4.2.3.10, p. 104: discard bcast/mcast SYN
- *
- * Note that it is quite possible to receive unicast
- * link-layer packets with a broadcast IP address. Use
- * in_broadcast() to find them.
- */
- if (m->m_flags & (M_BCAST|M_MCAST))
- goto drop;
- if (isipv6) {
- if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
- IN6_IS_ADDR_MULTICAST(&ip6->ip6_src))
- goto drop;
- } else {
- if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) ||
- IN_MULTICAST(ntohl(ip->ip_src.s_addr)) ||
- ip->ip_src.s_addr == htonl(INADDR_BROADCAST) ||
- in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif))
- goto drop;
- }
- /*
- * SYN appears to be valid; create compressed TCP state
- * for syncache, or perform t/tcp connection.
- */
- if (so->so_qlen <= so->so_qlimit) {
- tcp_dooptions(&to, optp, optlen, 1);
- if (!syncache_add(&inc, &to, th, &so, m))
- goto drop;
- if (so == NULL) {
- /*
- * Entry added to syncache, mbuf used to
- * send SYN,ACK packet.
- */
- KASSERT(headlocked, ("headlocked"));
- INP_UNLOCK(inp);
- INP_INFO_WUNLOCK(&tcbinfo);
- return;
- }
- /*
- * Segment passed TAO tests.
- */
- INP_UNLOCK(inp);
- inp = sotoinpcb(so);
- INP_LOCK(inp);
- tp = intotcpcb(inp);
- tp->snd_wnd = tiwin;
- tp->t_starttime = ticks;
- tp->t_state = TCPS_ESTABLISHED;
-
- /*
- * T/TCP logic:
- * If there is a FIN or if there is data, then
- * delay SYN,ACK(SYN) in the hope of piggy-backing
- * it on a response segment. Otherwise must send
- * ACK now in case the other side is slow starting.
- */
- if (thflags & TH_FIN || tlen != 0)
- tp->t_flags |= (TF_DELACK | TF_NEEDSYN);
- else
- tp->t_flags |= (TF_ACKNOW | TF_NEEDSYN);
- tcpstat.tcps_connects++;
- soisconnected(so);
- goto trimthenstep6;
- }
- goto drop;
- }
-after_listen:
-
-/* XXX temp debugging */
- /* should not happen - syncache should pick up these connections */
- if (tp->t_state == TCPS_LISTEN)
- panic("tcp_input: TCPS_LISTEN");
-
- /*
- * Segment received on connection.
- * Reset idle time and keep-alive timer.
- */
- tp->t_rcvtime = ticks;
- if (TCPS_HAVEESTABLISHED(tp->t_state))
- callout_reset(tp->tt_keep, tcp_keepidle, tcp_timer_keep, tp);
-
- /*
- * Process options.
- * XXX this is tradtitional behavior, may need to be cleaned up.
- */
- tcp_dooptions(&to, optp, optlen, thflags & TH_SYN);
- if (thflags & TH_SYN) {
- if (to.to_flags & TOF_SCALE) {
- tp->t_flags |= TF_RCVD_SCALE;
- tp->requested_s_scale = to.to_requested_s_scale;
- }
- if (to.to_flags & TOF_TS) {
- tp->t_flags |= TF_RCVD_TSTMP;
- tp->ts_recent = to.to_tsval;
- tp->ts_recent_age = ticks;
- }
- if (to.to_flags & (TOF_CC|TOF_CCNEW))
- tp->t_flags |= TF_RCVD_CC;
- if (to.to_flags & TOF_MSS)
- tcp_mss(tp, to.to_mss);
- }
-
- /*
- * Header prediction: check for the two common cases
- * of a uni-directional data xfer. If the packet has
- * no control flags, is in-sequence, the window didn't
- * change and we're not retransmitting, it's a
- * candidate. If the length is zero and the ack moved
- * forward, we're the sender side of the xfer. Just
- * free the data acked & wake any higher level process
- * that was blocked waiting for space. If the length
- * is non-zero and the ack didn't move, we're the
- * receiver side. If we're getting packets in-order
- * (the reassembly queue is empty), add the data to
- * the socket buffer and note that we need a delayed ack.
- * Make sure that the hidden state-flags are also off.
- * Since we check for TCPS_ESTABLISHED above, it can only
- * be TH_NEEDSYN.
- */
- if (tp->t_state == TCPS_ESTABLISHED &&
- (thflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ACK)) == TH_ACK &&
- ((tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN)) == 0) &&
- ((to.to_flags & TOF_TS) == 0 ||
- TSTMP_GEQ(to.to_tsval, tp->ts_recent)) &&
- /*
- * Using the CC option is compulsory if once started:
- * the segment is OK if no T/TCP was negotiated or
- * if the segment has a CC option equal to CCrecv
- */
- ((tp->t_flags & (TF_REQ_CC|TF_RCVD_CC)) != (TF_REQ_CC|TF_RCVD_CC) ||
- ((to.to_flags & TOF_CC) != 0 && to.to_cc == tp->cc_recv)) &&
- th->th_seq == tp->rcv_nxt &&
- tiwin && tiwin == tp->snd_wnd &&
- tp->snd_nxt == tp->snd_max) {
-
- /*
- * If last ACK falls within this segment's sequence numbers,
- * record the timestamp.
- * NOTE that the test is modified according to the latest
- * proposal of the tcplw@cray.com list (Braden 1993/04/26).
- */
- if ((to.to_flags & TOF_TS) != 0 &&
- SEQ_LEQ(th->th_seq, tp->last_ack_sent)) {
- tp->ts_recent_age = ticks;
- tp->ts_recent = to.to_tsval;
- }
-
- if (tlen == 0) {
- if (SEQ_GT(th->th_ack, tp->snd_una) &&
- SEQ_LEQ(th->th_ack, tp->snd_max) &&
- tp->snd_cwnd >= tp->snd_wnd &&
- ((!tcp_do_newreno &&
- tp->t_dupacks < tcprexmtthresh) ||
- (tcp_do_newreno &&
- !SEQ_LT(tp->snd_una, tp->snd_recover)))) {
- KASSERT(headlocked, ("headlocked"));
- INP_INFO_WUNLOCK(&tcbinfo);
- /*
- * this is a pure ack for outstanding data.
- */
- ++tcpstat.tcps_predack;
- /*
- * "bad retransmit" recovery
- */
- if (tp->t_rxtshift == 1 &&
- ticks < tp->t_badrxtwin) {
- ++tcpstat.tcps_sndrexmitbad;
- tp->snd_cwnd = tp->snd_cwnd_prev;
- tp->snd_ssthresh =
- tp->snd_ssthresh_prev;
- tp->snd_high = tp->snd_high_prev;
- tp->snd_nxt = tp->snd_max;
- tp->t_badrxtwin = 0;
- }
-
- /*
- * Recalculate the transmit timer / rtt.
- *
- * Some boxes send broken timestamp replies
- * during the SYN+ACK phase, ignore
- * timestamps of 0 or we could calculate a
- * huge RTT and blow up the retransmit timer.
- */
- if ((to.to_flags & TOF_TS) != 0 &&
- to.to_tsecr) {
- tcp_xmit_timer(tp,
- ticks - to.to_tsecr + 1);
- } else if (tp->t_rtttime &&
- SEQ_GT(th->th_ack, tp->t_rtseq)) {
- tcp_xmit_timer(tp,
- ticks - tp->t_rtttime);
- }
- tcp_xmit_bandwidth_limit(tp, th->th_ack);
- acked = th->th_ack - tp->snd_una;
- tcpstat.tcps_rcvackpack++;
- tcpstat.tcps_rcvackbyte += acked;
- sbdrop(&so->so_snd, acked);
- if (SEQ_GT(tp->snd_una, tp->snd_high) &&
- SEQ_LEQ(th->th_ack, tp->snd_high))
- tp->snd_high = th->th_ack - 1;
- tp->snd_una = tp->snd_recover = th->th_ack;
- /*
- * pull snd_wl2 up to prevent seq wrap relative
- * to th_ack.
- */
- tp->snd_wl2 = th->th_ack;
- tp->t_dupacks = 0;
- m_freem(m);
- ND6_HINT(tp); /* some progress has been done */
-
- /*
- * If all outstanding data are acked, stop
- * retransmit timer, otherwise restart timer
- * using current (possibly backed-off) value.
- * If process is waiting for space,
- * wakeup/selwakeup/signal. If data
- * are ready to send, let tcp_output
- * decide between more output or persist.
- */
- if (tp->snd_una == tp->snd_max)
- callout_stop(tp->tt_rexmt);
- else if (!callout_active(tp->tt_persist))
- callout_reset(tp->tt_rexmt,
- tp->t_rxtcur,
- tcp_timer_rexmt, tp);
-
- sowwakeup(so);
- if (so->so_snd.sb_cc)
- (void) tcp_output(tp);
- goto check_delack;
- }
- } else if (th->th_ack == tp->snd_una &&
- LIST_EMPTY(&tp->t_segq) &&
- tlen <= sbspace(&so->so_rcv)) {
- KASSERT(headlocked, ("headlocked"));
- INP_INFO_WUNLOCK(&tcbinfo);
- /*
- * this is a pure, in-sequence data packet
- * with nothing on the reassembly queue and
- * we have enough buffer space to take it.
- */
- ++tcpstat.tcps_preddat;
- tp->rcv_nxt += tlen;
- /*
- * Pull snd_wl1 up to prevent seq wrap relative to
- * th_seq.
- */
- tp->snd_wl1 = th->th_seq;
- /*
- * Pull rcv_up up to prevent seq wrap relative to
- * rcv_nxt.
- */
- tp->rcv_up = tp->rcv_nxt;
- tcpstat.tcps_rcvpack++;
- tcpstat.tcps_rcvbyte += tlen;
- ND6_HINT(tp); /* some progress has been done */
- /*
- * Add data to socket buffer.
- */
- if (so->so_state & SS_CANTRCVMORE) {
- m_freem(m);
- } else {
- m_adj(m, drop_hdrlen); /* delayed header drop */
- sbappend(&so->so_rcv, m);
- }
- sorwakeup(so);
- if (DELAY_ACK(tp)) {
- tp->t_flags |= TF_DELACK;
- } else {
- tp->t_flags |= TF_ACKNOW;
- tcp_output(tp);
- }
- goto check_delack;
- }
- }
-
- /*
- * Calculate amount of space in receive window,
- * and then do TCP input processing.
- * Receive window is amount of space in rcv queue,
- * but not less than advertised window.
- */
- { int win;
-
- win = sbspace(&so->so_rcv);
- if (win < 0)
- win = 0;
- tp->rcv_wnd = imax(win, (int)(tp->rcv_adv - tp->rcv_nxt));
- }
-
- switch (tp->t_state) {
-
- /*
- * If the state is SYN_RECEIVED:
- * if seg contains an ACK, but not for our SYN/ACK, send a RST.
- */
- case TCPS_SYN_RECEIVED:
- if ((thflags & TH_ACK) &&
- (SEQ_LEQ(th->th_ack, tp->snd_una) ||
- SEQ_GT(th->th_ack, tp->snd_max))) {
- rstreason = BANDLIM_RST_OPENPORT;
- goto dropwithreset;
- }
- break;
-
- /*
- * If the state is SYN_SENT:
- * if seg contains an ACK, but not for our SYN, drop the input.
- * if seg contains a RST, then drop the connection.
- * if seg does not contain SYN, then drop it.
- * Otherwise this is an acceptable SYN segment
- * initialize tp->rcv_nxt and tp->irs
- * if seg contains ack then advance tp->snd_una
- * if SYN has been acked change to ESTABLISHED else SYN_RCVD state
- * arrange for segment to be acked (eventually)
- * continue processing rest of data/controls, beginning with URG
- */
- case TCPS_SYN_SENT:
- if ((taop = tcp_gettaocache(&inp->inp_inc)) == NULL) {
- taop = &tao_noncached;
- bzero(taop, sizeof(*taop));
- }
-
- if ((thflags & TH_ACK) &&
- (SEQ_LEQ(th->th_ack, tp->iss) ||
- SEQ_GT(th->th_ack, tp->snd_max))) {
- /*
- * If we have a cached CCsent for the remote host,
- * hence we haven't just crashed and restarted,
- * do not send a RST. This may be a retransmission
- * from the other side after our earlier ACK was lost.
- * Our new SYN, when it arrives, will serve as the
- * needed ACK.
- */
- if (taop->tao_ccsent != 0)
- goto drop;
- else {
- rstreason = BANDLIM_UNLIMITED;
- goto dropwithreset;
- }
- }
- if (thflags & TH_RST) {
- if (thflags & TH_ACK)
- tp = tcp_drop(tp, ECONNREFUSED);
- goto drop;
- }
- if ((thflags & TH_SYN) == 0)
- goto drop;
- tp->snd_wnd = th->th_win; /* initial send window */
- tp->cc_recv = to.to_cc; /* foreign CC */
-
- tp->irs = th->th_seq;
- tcp_rcvseqinit(tp);
- if (thflags & TH_ACK) {
- /*
- * Our SYN was acked. If segment contains CC.ECHO
- * option, check it to make sure this segment really
- * matches our SYN. If not, just drop it as old
- * duplicate, but send an RST if we're still playing
- * by the old rules. If no CC.ECHO option, make sure
- * we don't get fooled into using T/TCP.
- */
- if (to.to_flags & TOF_CCECHO) {
- if (tp->cc_send != to.to_ccecho) {
- if (taop->tao_ccsent != 0)
- goto drop;
- else {
- rstreason = BANDLIM_UNLIMITED;
- goto dropwithreset;
- }
- }
- } else
- tp->t_flags &= ~TF_RCVD_CC;
- tcpstat.tcps_connects++;
- soisconnected(so);
-#ifdef MAC
- mac_set_socket_peer_from_mbuf(m, so);
-#endif
- /* Do window scaling on this connection? */
- if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
- (TF_RCVD_SCALE|TF_REQ_SCALE)) {
- tp->snd_scale = tp->requested_s_scale;
- tp->rcv_scale = tp->request_r_scale;
- }
- /* Segment is acceptable, update cache if undefined. */
- if (taop->tao_ccsent == 0)
- taop->tao_ccsent = to.to_ccecho;
-
- tp->rcv_adv += tp->rcv_wnd;
- tp->snd_una++; /* SYN is acked */
- /*
- * If there's data, delay ACK; if there's also a FIN
- * ACKNOW will be turned on later.
- */
- if (DELAY_ACK(tp) && tlen != 0)
- callout_reset(tp->tt_delack, tcp_delacktime,
- tcp_timer_delack, tp);
- else
- tp->t_flags |= TF_ACKNOW;
- /*
- * Received <SYN,ACK> in SYN_SENT[*] state.
- * Transitions:
- * SYN_SENT --> ESTABLISHED
- * SYN_SENT* --> FIN_WAIT_1
- */
- tp->t_starttime = ticks;
- if (tp->t_flags & TF_NEEDFIN) {
- tp->t_state = TCPS_FIN_WAIT_1;
- tp->t_flags &= ~TF_NEEDFIN;
- thflags &= ~TH_SYN;
- } else {
- tp->t_state = TCPS_ESTABLISHED;
- callout_reset(tp->tt_keep, tcp_keepidle,
- tcp_timer_keep, tp);
- }
- } else {
- /*
- * Received initial SYN in SYN-SENT[*] state =>
- * simultaneous open. If segment contains CC option
- * and there is a cached CC, apply TAO test.
- * If it succeeds, connection is * half-synchronized.
- * Otherwise, do 3-way handshake:
- * SYN-SENT -> SYN-RECEIVED
- * SYN-SENT* -> SYN-RECEIVED*
- * If there was no CC option, clear cached CC value.
- */
- tp->t_flags |= TF_ACKNOW;
- callout_stop(tp->tt_rexmt);
- if (to.to_flags & TOF_CC) {
- if (taop->tao_cc != 0 &&
- CC_GT(to.to_cc, taop->tao_cc)) {
- /*
- * update cache and make transition:
- * SYN-SENT -> ESTABLISHED*
- * SYN-SENT* -> FIN-WAIT-1*
- */
- taop->tao_cc = to.to_cc;
- tp->t_starttime = ticks;
- if (tp->t_flags & TF_NEEDFIN) {
- tp->t_state = TCPS_FIN_WAIT_1;
- tp->t_flags &= ~TF_NEEDFIN;
- } else {
- tp->t_state = TCPS_ESTABLISHED;
- callout_reset(tp->tt_keep,
- tcp_keepidle,
- tcp_timer_keep,
- tp);
- }
- tp->t_flags |= TF_NEEDSYN;
- } else
- tp->t_state = TCPS_SYN_RECEIVED;
- } else {
- /* CC.NEW or no option => invalidate cache */
- taop->tao_cc = 0;
- tp->t_state = TCPS_SYN_RECEIVED;
- }
- }
-
-trimthenstep6:
- /*
- * Advance th->th_seq to correspond to first data byte.
- * If data, trim to stay within window,
- * dropping FIN if necessary.
- */
- th->th_seq++;
- if (tlen > tp->rcv_wnd) {
- todrop = tlen - tp->rcv_wnd;
- m_adj(m, -todrop);
- tlen = tp->rcv_wnd;
- thflags &= ~TH_FIN;
- tcpstat.tcps_rcvpackafterwin++;
- tcpstat.tcps_rcvbyteafterwin += todrop;
- }
- tp->snd_wl1 = th->th_seq - 1;
- tp->rcv_up = th->th_seq;
- /*
- * Client side of transaction: already sent SYN and data.
- * If the remote host used T/TCP to validate the SYN,
- * our data will be ACK'd; if so, enter normal data segment
- * processing in the middle of step 5, ack processing.
- * Otherwise, goto step 6.
- */
- if (thflags & TH_ACK)
- goto process_ACK;
-
- goto step6;
-
- /*
- * If the state is LAST_ACK or CLOSING or TIME_WAIT:
- * if segment contains a SYN and CC [not CC.NEW] option:
- * if state == TIME_WAIT and connection duration > MSL,
- * drop packet and send RST;
- *
- * if SEG.CC > CCrecv then is new SYN, and can implicitly
- * ack the FIN (and data) in retransmission queue.
- * Complete close and delete TCPCB. Then reprocess
- * segment, hoping to find new TCPCB in LISTEN state;
- *
- * else must be old SYN; drop it.
- * else do normal processing.
- */
- case TCPS_LAST_ACK:
- case TCPS_CLOSING:
- case TCPS_TIME_WAIT:
- KASSERT(tp->t_state != TCPS_TIME_WAIT, ("timewait"));
- if ((thflags & TH_SYN) &&
- (to.to_flags & TOF_CC) && tp->cc_recv != 0) {
- if (tp->t_state == TCPS_TIME_WAIT &&
- (ticks - tp->t_starttime) > tcp_msl) {
- rstreason = BANDLIM_UNLIMITED;
- goto dropwithreset;
- }
- if (CC_GT(to.to_cc, tp->cc_recv)) {
- tp = tcp_close(tp);
- goto findpcb;
- }
- else
- goto drop;
- }
- break; /* continue normal processing */
- }
-
- /*
- * States other than LISTEN or SYN_SENT.
- * First check the RST flag and sequence number since reset segments
- * are exempt from the timestamp and connection count tests. This
- * fixes a bug introduced by the Stevens, vol. 2, p. 960 bugfix
- * below which allowed reset segments in half the sequence space
- * to fall though and be processed (which gives forged reset
- * segments with a random sequence number a 50 percent chance of
- * killing a connection).
- * Then check timestamp, if present.
- * Then check the connection count, if present.
- * Then check that at least some bytes of segment are within
- * receive window. If segment begins before rcv_nxt,
- * drop leading data (and SYN); if nothing left, just ack.
- *
- *
- * If the RST bit is set, check the sequence number to see
- * if this is a valid reset segment.
- * RFC 793 page 37:
- * In all states except SYN-SENT, all reset (RST) segments
- * are validated by checking their SEQ-fields. A reset is
- * valid if its sequence number is in the window.
- * Note: this does not take into account delayed ACKs, so
- * we should test against last_ack_sent instead of rcv_nxt.
- * The sequence number in the reset segment is normally an
- * echo of our outgoing acknowlegement numbers, but some hosts
- * send a reset with the sequence number at the rightmost edge
- * of our receive window, and we have to handle this case.
- * If we have multiple segments in flight, the intial reset
- * segment sequence numbers will be to the left of last_ack_sent,
- * but they will eventually catch up.
- * In any case, it never made sense to trim reset segments to
- * fit the receive window since RFC 1122 says:
- * 4.2.2.12 RST Segment: RFC-793 Section 3.4
- *
- * A TCP SHOULD allow a received RST segment to include data.
- *
- * DISCUSSION
- * It has been suggested that a RST segment could contain
- * ASCII text that encoded and explained the cause of the
- * RST. No standard has yet been established for such
- * data.
- *
- * If the reset segment passes the sequence number test examine
- * the state:
- * SYN_RECEIVED STATE:
- * If passive open, return to LISTEN state.
- * If active open, inform user that connection was refused.
- * ESTABLISHED, FIN_WAIT_1, FIN_WAIT_2, CLOSE_WAIT STATES:
- * Inform user that connection was reset, and close tcb.
- * CLOSING, LAST_ACK STATES:
- * Close the tcb.
- * TIME_WAIT STATE:
- * Drop the segment - see Stevens, vol. 2, p. 964 and
- * RFC 1337.
- */
- if (thflags & TH_RST) {
- if (SEQ_GEQ(th->th_seq, tp->last_ack_sent) &&
- SEQ_LT(th->th_seq, tp->last_ack_sent + tp->rcv_wnd)) {
- switch (tp->t_state) {
-
- case TCPS_SYN_RECEIVED:
- so->so_error = ECONNREFUSED;
- goto close;
-
- case TCPS_ESTABLISHED:
- case TCPS_FIN_WAIT_1:
- case TCPS_FIN_WAIT_2:
- case TCPS_CLOSE_WAIT:
- so->so_error = ECONNRESET;
- close:
- tp->t_state = TCPS_CLOSED;
- tcpstat.tcps_drops++;
- tp = tcp_close(tp);
- break;
-
- case TCPS_CLOSING:
- case TCPS_LAST_ACK:
- tp = tcp_close(tp);
- break;
-
- case TCPS_TIME_WAIT:
- KASSERT(tp->t_state != TCPS_TIME_WAIT,
- ("timewait"));
- break;
- }
- }
- goto drop;
- }
-
- /*
- * RFC 1323 PAWS: If we have a timestamp reply on this segment
- * and it's less than ts_recent, drop it.
- */
- if ((to.to_flags & TOF_TS) != 0 && tp->ts_recent &&
- TSTMP_LT(to.to_tsval, tp->ts_recent)) {
-
- /* Check to see if ts_recent is over 24 days old. */
- if ((int)(ticks - tp->ts_recent_age) > TCP_PAWS_IDLE) {
- /*
- * Invalidate ts_recent. If this segment updates
- * ts_recent, the age will be reset later and ts_recent
- * will get a valid value. If it does not, setting
- * ts_recent to zero will at least satisfy the
- * requirement that zero be placed in the timestamp
- * echo reply when ts_recent isn't valid. The
- * age isn't reset until we get a valid ts_recent
- * because we don't want out-of-order segments to be
- * dropped when ts_recent is old.
- */
- tp->ts_recent = 0;
- } else {
- tcpstat.tcps_rcvduppack++;
- tcpstat.tcps_rcvdupbyte += tlen;
- tcpstat.tcps_pawsdrop++;
- if (tlen)
- goto dropafterack;
- goto drop;
- }
- }
-
- /*
- * T/TCP mechanism
- * If T/TCP was negotiated and the segment doesn't have CC,
- * or if its CC is wrong then drop the segment.
- * RST segments do not have to comply with this.
- */
- if ((tp->t_flags & (TF_REQ_CC|TF_RCVD_CC)) == (TF_REQ_CC|TF_RCVD_CC) &&
- ((to.to_flags & TOF_CC) == 0 || tp->cc_recv != to.to_cc))
- goto dropafterack;
-
- /*
- * In the SYN-RECEIVED state, validate that the packet belongs to
- * this connection before trimming the data to fit the receive
- * window. Check the sequence number versus IRS since we know
- * the sequence numbers haven't wrapped. This is a partial fix
- * for the "LAND" DoS attack.
- */
- if (tp->t_state == TCPS_SYN_RECEIVED && SEQ_LT(th->th_seq, tp->irs)) {
- rstreason = BANDLIM_RST_OPENPORT;
- goto dropwithreset;
- }
-
- todrop = tp->rcv_nxt - th->th_seq;
- if (todrop > 0) {
- if (thflags & TH_SYN) {
- thflags &= ~TH_SYN;
- th->th_seq++;
- if (th->th_urp > 1)
- th->th_urp--;
- else
- thflags &= ~TH_URG;
- todrop--;
- }
- /*
- * Following if statement from Stevens, vol. 2, p. 960.
- */
- if (todrop > tlen
- || (todrop == tlen && (thflags & TH_FIN) == 0)) {
- /*
- * Any valid FIN must be to the left of the window.
- * At this point the FIN must be a duplicate or out
- * of sequence; drop it.
- */
- thflags &= ~TH_FIN;
-
- /*
- * Send an ACK to resynchronize and drop any data.
- * But keep on processing for RST or ACK.
- */
- tp->t_flags |= TF_ACKNOW;
- todrop = tlen;
- tcpstat.tcps_rcvduppack++;
- tcpstat.tcps_rcvdupbyte += todrop;
- } else {
- tcpstat.tcps_rcvpartduppack++;
- tcpstat.tcps_rcvpartdupbyte += todrop;
- }
- drop_hdrlen += todrop; /* drop from the top afterwards */
- th->th_seq += todrop;
- tlen -= todrop;
- if (th->th_urp > todrop)
- th->th_urp -= todrop;
- else {
- thflags &= ~TH_URG;
- th->th_urp = 0;
- }
- }
-
- /*
- * If new data are received on a connection after the
- * user processes are gone, then RST the other end.
- */
- if ((so->so_state & SS_NOFDREF) &&
- tp->t_state > TCPS_CLOSE_WAIT && tlen) {
- tp = tcp_close(tp);
- tcpstat.tcps_rcvafterclose++;
- rstreason = BANDLIM_UNLIMITED;
- goto dropwithreset;
- }
-
- /*
- * If segment ends after window, drop trailing data
- * (and PUSH and FIN); if nothing left, just ACK.
- */
- todrop = (th->th_seq+tlen) - (tp->rcv_nxt+tp->rcv_wnd);
- if (todrop > 0) {
- tcpstat.tcps_rcvpackafterwin++;
- if (todrop >= tlen) {
- tcpstat.tcps_rcvbyteafterwin += tlen;
- /*
- * If a new connection request is received
- * while in TIME_WAIT, drop the old connection
- * and start over if the sequence numbers
- * are above the previous ones.
- */
- KASSERT(tp->t_state != TCPS_TIME_WAIT, ("timewait"));
- if (thflags & TH_SYN &&
- tp->t_state == TCPS_TIME_WAIT &&
- SEQ_GT(th->th_seq, tp->rcv_nxt)) {
- tp = tcp_close(tp);
- goto findpcb;
- }
- /*
- * If window is closed can only take segments at
- * window edge, and have to drop data and PUSH from
- * incoming segments. Continue processing, but
- * remember to ack. Otherwise, drop segment
- * and ack.
- */
- if (tp->rcv_wnd == 0 && th->th_seq == tp->rcv_nxt) {
- tp->t_flags |= TF_ACKNOW;
- tcpstat.tcps_rcvwinprobe++;
- } else
- goto dropafterack;
- } else
- tcpstat.tcps_rcvbyteafterwin += todrop;
- m_adj(m, -todrop);
- tlen -= todrop;
- thflags &= ~(TH_PUSH|TH_FIN);
- }
-
- /*
- * If last ACK falls within this segment's sequence numbers,
- * record its timestamp.
- * NOTE that the test is modified according to the latest
- * proposal of the tcplw@cray.com list (Braden 1993/04/26).
- */
- if ((to.to_flags & TOF_TS) != 0 &&
- SEQ_LEQ(th->th_seq, tp->last_ack_sent)) {
- tp->ts_recent_age = ticks;
- tp->ts_recent = to.to_tsval;
- }
-
- /*
- * If a SYN is in the window, then this is an
- * error and we send an RST and drop the connection.
- */
- if (thflags & TH_SYN) {
- tp = tcp_drop(tp, ECONNRESET);
- rstreason = BANDLIM_UNLIMITED;
- goto dropwithreset;
- }
-
- /*
- * If the ACK bit is off: if in SYN-RECEIVED state or SENDSYN
- * flag is on (half-synchronized state), then queue data for
- * later processing; else drop segment and return.
- */
- if ((thflags & TH_ACK) == 0) {
- if (tp->t_state == TCPS_SYN_RECEIVED ||
- (tp->t_flags & TF_NEEDSYN))
- goto step6;
- else
- goto drop;
- }
-
- /*
- * Ack processing.
- */
- switch (tp->t_state) {
-
- /*
- * In SYN_RECEIVED state, the ack ACKs our SYN, so enter
- * ESTABLISHED state and continue processing.
- * The ACK was checked above.
- */
- case TCPS_SYN_RECEIVED:
-
- tcpstat.tcps_connects++;
- soisconnected(so);
- /* Do window scaling? */
- if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
- (TF_RCVD_SCALE|TF_REQ_SCALE)) {
- tp->snd_scale = tp->requested_s_scale;
- tp->rcv_scale = tp->request_r_scale;
- }
- /*
- * Upon successful completion of 3-way handshake,
- * update cache.CC if it was undefined, pass any queued
- * data to the user, and advance state appropriately.
- */
- if ((taop = tcp_gettaocache(&inp->inp_inc)) != NULL &&
- taop->tao_cc == 0)
- taop->tao_cc = tp->cc_recv;
-
- /*
- * Make transitions:
- * SYN-RECEIVED -> ESTABLISHED
- * SYN-RECEIVED* -> FIN-WAIT-1
- */
- tp->t_starttime = ticks;
- if (tp->t_flags & TF_NEEDFIN) {
- tp->t_state = TCPS_FIN_WAIT_1;
- tp->t_flags &= ~TF_NEEDFIN;
- } else {
- tp->t_state = TCPS_ESTABLISHED;
- callout_reset(tp->tt_keep, tcp_keepidle,
- tcp_timer_keep, tp);
- }
- /*
- * If segment contains data or ACK, will call tcp_reass()
- * later; if not, do so now to pass queued data to user.
- */
- if (tlen == 0 && (thflags & TH_FIN) == 0)
- (void) tcp_reass(tp, (struct tcphdr *)0, 0,
- (struct mbuf *)0);
- tp->snd_wl1 = th->th_seq - 1;
- /* FALLTHROUGH */
-
- /*
- * In ESTABLISHED state: drop duplicate ACKs; ACK out of range
- * ACKs. If the ack is in the range
- * tp->snd_una < th->th_ack <= tp->snd_max
- * then advance tp->snd_una to th->th_ack and drop
- * data from the retransmission queue. If this ACK reflects
- * more up to date window information we update our window information.
- */
- case TCPS_ESTABLISHED:
- case TCPS_FIN_WAIT_1:
- case TCPS_FIN_WAIT_2:
- case TCPS_CLOSE_WAIT:
- case TCPS_CLOSING:
- case TCPS_LAST_ACK:
- case TCPS_TIME_WAIT:
- KASSERT(tp->t_state != TCPS_TIME_WAIT, ("timewait"));
- if (SEQ_LEQ(th->th_ack, tp->snd_una)) {
- if (tlen == 0 && tiwin == tp->snd_wnd) {
- tcpstat.tcps_rcvdupack++;
- /*
- * If we have outstanding data (other than
- * a window probe), this is a completely
- * duplicate ack (ie, window info didn't
- * change), the ack is the biggest we've
- * seen and we've seen exactly our rexmt
- * threshhold of them, assume a packet
- * has been dropped and retransmit it.
- * Kludge snd_nxt & the congestion
- * window so we send only this one
- * packet.
- *
- * We know we're losing at the current
- * window size so do congestion avoidance
- * (set ssthresh to half the current window
- * and pull our congestion window back to
- * the new ssthresh).
- *
- * Dup acks mean that packets have left the
- * network (they're now cached at the receiver)
- * so bump cwnd by the amount in the receiver
- * to keep a constant cwnd packets in the
- * network.
- */
- if (!callout_active(tp->tt_rexmt) ||
- th->th_ack != tp->snd_una)
- tp->t_dupacks = 0;
- else if (++tp->t_dupacks > tcprexmtthresh ||
- (tcp_do_newreno &&
- SEQ_LT(tp->snd_una,
- tp->snd_recover))) {
- tp->snd_cwnd += tp->t_maxseg;
- (void) tcp_output(tp);
- goto drop;
- } else if (tp->t_dupacks == tcprexmtthresh) {
- tcp_seq onxt = tp->snd_nxt;
- u_int win;
- if (tcp_do_newreno &&
- SEQ_LEQ(th->th_ack, tp->snd_high)) {
- tp->t_dupacks = 0;
- break;
- }
- win = min(tp->snd_wnd, tp->snd_cwnd) /
- 2 / tp->t_maxseg;
- if (win < 2)
- win = 2;
- tp->snd_ssthresh = win * tp->t_maxseg;
- tp->snd_recover = tp->snd_max;
- callout_stop(tp->tt_rexmt);
- tp->t_rtttime = 0;
- tp->snd_nxt = th->th_ack;
- tp->snd_cwnd = tp->t_maxseg;
- (void) tcp_output(tp);
- KASSERT(tp->snd_limited <= 2,
- ("tp->snd_limited too big"));
- tp->snd_cwnd = tp->snd_ssthresh +
- tp->t_maxseg *
- (tp->t_dupacks - tp->snd_limited);
- if (SEQ_GT(onxt, tp->snd_nxt))
- tp->snd_nxt = onxt;
- goto drop;
- } else if (tcp_do_rfc3042) {
- u_long oldcwnd = tp->snd_cwnd;
- tcp_seq oldsndmax = tp->snd_max;
- u_int sent;
- KASSERT(tp->t_dupacks == 1 ||
- tp->t_dupacks == 2,
- ("dupacks not 1 or 2"));
- if (tp->t_dupacks == 1) {
- tp->snd_limited = 0;
- tp->snd_cwnd += tp->t_maxseg;
- } else {
- tp->snd_cwnd +=
- tp->t_maxseg * 2;
- }
- (void) tcp_output(tp);
- sent = tp->snd_max - oldsndmax;
- if (sent > tp->t_maxseg) {
- KASSERT(tp->snd_limited == 0 &&
- tp->t_dupacks == 2,
- ("sent too much"));
- tp->snd_limited = 2;
- } else if (sent > 0)
- ++tp->snd_limited;
- tp->snd_cwnd = oldcwnd;
- goto drop;
- }
- } else
- tp->t_dupacks = 0;
- break;
- }
-
- KASSERT(SEQ_GT(th->th_ack, tp->snd_una), ("th_ack <= snd_una"));
-
- /*
- * If the congestion window was inflated to account
- * for the other side's cached packets, retract it.
- */
- if (tcp_do_newreno) {
- if (SEQ_LT(tp->snd_una, tp->snd_recover)) {
- if (SEQ_LT(th->th_ack, tp->snd_recover)) {
- tcp_newreno_partial_ack(tp, th);
- } else {
- /*
- * Window inflation should have left us
- * with approximately snd_ssthresh
- * outstanding data.
- * But in case we would be inclined to
- * send a burst, better to do it via
- * the slow start mechanism.
- */
- if (SEQ_GT(th->th_ack +
- tp->snd_ssthresh,
- tp->snd_max))
- tp->snd_cwnd = tp->snd_max -
- th->th_ack +
- tp->t_maxseg;
- else
- tp->snd_cwnd = tp->snd_ssthresh;
- }
- }
- } else {
- if (tp->t_dupacks >= tcprexmtthresh &&
- tp->snd_cwnd > tp->snd_ssthresh)
- tp->snd_cwnd = tp->snd_ssthresh;
- }
- tp->t_dupacks = 0;
- if (SEQ_GT(th->th_ack, tp->snd_max)) {
- tcpstat.tcps_rcvacktoomuch++;
- goto dropafterack;
- }
- /*
- * If we reach this point, ACK is not a duplicate,
- * i.e., it ACKs something we sent.
- */
- if (tp->t_flags & TF_NEEDSYN) {
- /*
- * T/TCP: Connection was half-synchronized, and our
- * SYN has been ACK'd (so connection is now fully
- * synchronized). Go to non-starred state,
- * increment snd_una for ACK of SYN, and check if
- * we can do window scaling.
- */
- tp->t_flags &= ~TF_NEEDSYN;
- tp->snd_una++;
- /* Do window scaling? */
- if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
- (TF_RCVD_SCALE|TF_REQ_SCALE)) {
- tp->snd_scale = tp->requested_s_scale;
- tp->rcv_scale = tp->request_r_scale;
- }
- }
-
-process_ACK:
- acked = th->th_ack - tp->snd_una;
- tcpstat.tcps_rcvackpack++;
- tcpstat.tcps_rcvackbyte += acked;
-
- /*
- * If we just performed our first retransmit, and the ACK
- * arrives within our recovery window, then it was a mistake
- * to do the retransmit in the first place. Recover our
- * original cwnd and ssthresh, and proceed to transmit where
- * we left off.
- */
- if (tp->t_rxtshift == 1 && ticks < tp->t_badrxtwin) {
- ++tcpstat.tcps_sndrexmitbad;
- tp->snd_cwnd = tp->snd_cwnd_prev;
- tp->snd_ssthresh = tp->snd_ssthresh_prev;
- tp->snd_high = tp->snd_high_prev;
- tp->snd_nxt = tp->snd_max;
- tp->t_badrxtwin = 0; /* XXX probably not required */
- }
-
- /*
- * If we have a timestamp reply, update smoothed
- * round trip time. If no timestamp is present but
- * transmit timer is running and timed sequence
- * number was acked, update smoothed round trip time.
- * Since we now have an rtt measurement, cancel the
- * timer backoff (cf., Phil Karn's retransmit alg.).
- * Recompute the initial retransmit timer.
- *
- * Some boxes send broken timestamp replies
- * during the SYN+ACK phase, ignore
- * timestamps of 0 or we could calculate a
- * huge RTT and blow up the retransmit timer.
- */
- if ((to.to_flags & TOF_TS) != 0 &&
- to.to_tsecr) {
- tcp_xmit_timer(tp, ticks - to.to_tsecr + 1);
- } else if (tp->t_rtttime && SEQ_GT(th->th_ack, tp->t_rtseq)) {
- tcp_xmit_timer(tp, ticks - tp->t_rtttime);
- }
- tcp_xmit_bandwidth_limit(tp, th->th_ack);
-
- /*
- * If all outstanding data is acked, stop retransmit
- * timer and remember to restart (more output or persist).
- * If there is more data to be acked, restart retransmit
- * timer, using current (possibly backed-off) value.
- */
- if (th->th_ack == tp->snd_max) {
- callout_stop(tp->tt_rexmt);
- needoutput = 1;
- } else if (!callout_active(tp->tt_persist))
- callout_reset(tp->tt_rexmt, tp->t_rxtcur,
- tcp_timer_rexmt, tp);
-
- /*
- * If no data (only SYN) was ACK'd,
- * skip rest of ACK processing.
- */
- if (acked == 0)
- goto step6;
-
- /*
- * When new data is acked, open the congestion window.
- * If the window gives us less than ssthresh packets
- * in flight, open exponentially (maxseg per packet).
- * Otherwise open linearly: maxseg per window
- * (maxseg^2 / cwnd per packet).
- */
- if (!tcp_do_newreno || SEQ_GEQ(tp->snd_una, tp->snd_recover)) {
- register u_int cw = tp->snd_cwnd;
- register u_int incr = tp->t_maxseg;
- if (cw > tp->snd_ssthresh)
- incr = incr * incr / cw;
- tp->snd_cwnd = min(cw+incr, TCP_MAXWIN<<tp->snd_scale);
- }
- if (acked > so->so_snd.sb_cc) {
- tp->snd_wnd -= so->so_snd.sb_cc;
- sbdrop(&so->so_snd, (int)so->so_snd.sb_cc);
- ourfinisacked = 1;
- } else {
- sbdrop(&so->so_snd, acked);
- tp->snd_wnd -= acked;
- ourfinisacked = 0;
- }
- sowwakeup(so);
- /* detect una wraparound */
- if (SEQ_GEQ(tp->snd_una, tp->snd_recover) &&
- SEQ_LT(th->th_ack, tp->snd_recover))
- tp->snd_recover = th->th_ack;
- if (SEQ_GT(tp->snd_una, tp->snd_high) &&
- SEQ_LEQ(th->th_ack, tp->snd_high))
- tp->snd_high = th->th_ack - 1;
- tp->snd_una = th->th_ack;
- if (SEQ_LT(tp->snd_nxt, tp->snd_una))
- tp->snd_nxt = tp->snd_una;
-
- switch (tp->t_state) {
-
- /*
- * In FIN_WAIT_1 STATE in addition to the processing
- * for the ESTABLISHED state if our FIN is now acknowledged
- * then enter FIN_WAIT_2.
- */
- case TCPS_FIN_WAIT_1:
- if (ourfinisacked) {
- /*
- * If we can't receive any more
- * data, then closing user can proceed.
- * Starting the timer is contrary to the
- * specification, but if we don't get a FIN
- * we'll hang forever.
- */
- /* XXXjl
- * we should release the tp also, and use a
- * compressed state.
- */
- if (so->so_state & SS_CANTRCVMORE) {
- soisdisconnected(so);
- callout_reset(tp->tt_2msl, tcp_maxidle,
- tcp_timer_2msl, tp);
- }
- tp->t_state = TCPS_FIN_WAIT_2;
- }
- break;
-
- /*
- * In CLOSING STATE in addition to the processing for
- * the ESTABLISHED state if the ACK acknowledges our FIN
- * then enter the TIME-WAIT state, otherwise ignore
- * the segment.
- */
- case TCPS_CLOSING:
- if (ourfinisacked) {
- KASSERT(headlocked, ("headlocked"));
- tcp_twstart(tp);
- INP_INFO_WUNLOCK(&tcbinfo);
- m_freem(m);
- return;
- }
- break;
-
- /*
- * In LAST_ACK, we may still be waiting for data to drain
- * and/or to be acked, as well as for the ack of our FIN.
- * If our FIN is now acknowledged, delete the TCB,
- * enter the closed state and return.
- */
- case TCPS_LAST_ACK:
- if (ourfinisacked) {
- tp = tcp_close(tp);
- goto drop;
- }
- break;
-
- /*
- * In TIME_WAIT state the only thing that should arrive
- * is a retransmission of the remote FIN. Acknowledge
- * it and restart the finack timer.
- */
- case TCPS_TIME_WAIT:
- KASSERT(tp->t_state != TCPS_TIME_WAIT, ("timewait"));
- callout_reset(tp->tt_2msl, 2 * tcp_msl,
- tcp_timer_2msl, tp);
- goto dropafterack;
- }
- }
-
-step6:
- /*
- * Update window information.
- * Don't look at window if no ACK: TAC's send garbage on first SYN.
- */
- if ((thflags & TH_ACK) &&
- (SEQ_LT(tp->snd_wl1, th->th_seq) ||
- (tp->snd_wl1 == th->th_seq && (SEQ_LT(tp->snd_wl2, th->th_ack) ||
- (tp->snd_wl2 == th->th_ack && tiwin > tp->snd_wnd))))) {
- /* keep track of pure window updates */
- if (tlen == 0 &&
- tp->snd_wl2 == th->th_ack && tiwin > tp->snd_wnd)
- tcpstat.tcps_rcvwinupd++;
- tp->snd_wnd = tiwin;
- tp->snd_wl1 = th->th_seq;
- tp->snd_wl2 = th->th_ack;
- if (tp->snd_wnd > tp->max_sndwnd)
- tp->max_sndwnd = tp->snd_wnd;
- needoutput = 1;
- }
-
- /*
- * Process segments with URG.
- */
- if ((thflags & TH_URG) && th->th_urp &&
- TCPS_HAVERCVDFIN(tp->t_state) == 0) {
- /*
- * This is a kludge, but if we receive and accept
- * random urgent pointers, we'll crash in
- * soreceive. It's hard to imagine someone
- * actually wanting to send this much urgent data.
- */
- if (th->th_urp + so->so_rcv.sb_cc > sb_max) {
- th->th_urp = 0; /* XXX */
- thflags &= ~TH_URG; /* XXX */
- goto dodata; /* XXX */
- }
- /*
- * If this segment advances the known urgent pointer,
- * then mark the data stream. This should not happen
- * in CLOSE_WAIT, CLOSING, LAST_ACK or TIME_WAIT STATES since
- * a FIN has been received from the remote side.
- * In these states we ignore the URG.
- *
- * According to RFC961 (Assigned Protocols),
- * the urgent pointer points to the last octet
- * of urgent data. We continue, however,
- * to consider it to indicate the first octet
- * of data past the urgent section as the original
- * spec states (in one of two places).
- */
- if (SEQ_GT(th->th_seq+th->th_urp, tp->rcv_up)) {
- tp->rcv_up = th->th_seq + th->th_urp;
- so->so_oobmark = so->so_rcv.sb_cc +
- (tp->rcv_up - tp->rcv_nxt) - 1;
- if (so->so_oobmark == 0)
- so->so_state |= SS_RCVATMARK;
- sohasoutofband(so);
- tp->t_oobflags &= ~(TCPOOB_HAVEDATA | TCPOOB_HADDATA);
- }
- /*
- * Remove out of band data so doesn't get presented to user.
- * This can happen independent of advancing the URG pointer,
- * but if two URG's are pending at once, some out-of-band
- * data may creep in... ick.
- */
- if (th->th_urp <= (u_long)tlen &&
- !(so->so_options & SO_OOBINLINE)) {
- /* hdr drop is delayed */
- tcp_pulloutofband(so, th, m, drop_hdrlen);
- }
- } else {
- /*
- * If no out of band data is expected,
- * pull receive urgent pointer along
- * with the receive window.
- */
- if (SEQ_GT(tp->rcv_nxt, tp->rcv_up))
- tp->rcv_up = tp->rcv_nxt;
- }
-dodata: /* XXX */
- KASSERT(headlocked, ("headlocked"));
- /*
- * Process the segment text, merging it into the TCP sequencing queue,
- * and arranging for acknowledgment of receipt if necessary.
- * This process logically involves adjusting tp->rcv_wnd as data
- * is presented to the user (this happens in tcp_usrreq.c,
- * case PRU_RCVD). If a FIN has already been received on this
- * connection then we just ignore the text.
- */
- if ((tlen || (thflags & TH_FIN)) &&
- TCPS_HAVERCVDFIN(tp->t_state) == 0) {
- m_adj(m, drop_hdrlen); /* delayed header drop */
- /*
- * Insert segment which includes th into TCP reassembly queue
- * with control block tp. Set thflags to whether reassembly now
- * includes a segment with FIN. This handles the common case
- * inline (segment is the next to be received on an established
- * connection, and the queue is empty), avoiding linkage into
- * and removal from the queue and repetition of various
- * conversions.
- * Set DELACK for segments received in order, but ack
- * immediately when segments are out of order (so
- * fast retransmit can work).
- */
- if (th->th_seq == tp->rcv_nxt &&
- LIST_EMPTY(&tp->t_segq) &&
- TCPS_HAVEESTABLISHED(tp->t_state)) {
- if (DELAY_ACK(tp))
- tp->t_flags |= TF_DELACK;
- else
- tp->t_flags |= TF_ACKNOW;
- tp->rcv_nxt += tlen;
- thflags = th->th_flags & TH_FIN;
- tcpstat.tcps_rcvpack++;
- tcpstat.tcps_rcvbyte += tlen;
- ND6_HINT(tp);
- if (so->so_state & SS_CANTRCVMORE)
- m_freem(m);
- else
- sbappend(&so->so_rcv, m);
- sorwakeup(so);
- } else {
- thflags = tcp_reass(tp, th, &tlen, m);
- tp->t_flags |= TF_ACKNOW;
- }
-
- /*
- * Note the amount of data that peer has sent into
- * our window, in order to estimate the sender's
- * buffer size.
- */
- len = so->so_rcv.sb_hiwat - (tp->rcv_adv - tp->rcv_nxt);
- } else {
- m_freem(m);
- thflags &= ~TH_FIN;
- }
-
- /*
- * If FIN is received ACK the FIN and let the user know
- * that the connection is closing.
- */
- if (thflags & TH_FIN) {
- if (TCPS_HAVERCVDFIN(tp->t_state) == 0) {
- socantrcvmore(so);
- /*
- * If connection is half-synchronized
- * (ie NEEDSYN flag on) then delay ACK,
- * so it may be piggybacked when SYN is sent.
- * Otherwise, since we received a FIN then no
- * more input can be expected, send ACK now.
- */
- if (tp->t_flags & TF_NEEDSYN)
- tp->t_flags |= TF_DELACK;
- else
- tp->t_flags |= TF_ACKNOW;
- tp->rcv_nxt++;
- }
- switch (tp->t_state) {
-
- /*
- * In SYN_RECEIVED and ESTABLISHED STATES
- * enter the CLOSE_WAIT state.
- */
- case TCPS_SYN_RECEIVED:
- tp->t_starttime = ticks;
- /*FALLTHROUGH*/
- case TCPS_ESTABLISHED:
- tp->t_state = TCPS_CLOSE_WAIT;
- break;
-
- /*
- * If still in FIN_WAIT_1 STATE FIN has not been acked so
- * enter the CLOSING state.
- */
- case TCPS_FIN_WAIT_1:
- tp->t_state = TCPS_CLOSING;
- break;
-
- /*
- * In FIN_WAIT_2 state enter the TIME_WAIT state,
- * starting the time-wait timer, turning off the other
- * standard timers.
- */
- case TCPS_FIN_WAIT_2:
- KASSERT(headlocked == 1, ("headlocked should be 1"));
- tcp_twstart(tp);
- INP_INFO_WUNLOCK(&tcbinfo);
- return;
-
- /*
- * In TIME_WAIT state restart the 2 MSL time_wait timer.
- */
- case TCPS_TIME_WAIT:
- KASSERT(tp->t_state != TCPS_TIME_WAIT, ("timewait"));
- callout_reset(tp->tt_2msl, 2 * tcp_msl,
- tcp_timer_2msl, tp);
- break;
- }
- }
- INP_INFO_WUNLOCK(&tcbinfo);
-#ifdef TCPDEBUG
- if (so->so_options & SO_DEBUG)
- tcp_trace(TA_INPUT, ostate, tp, (void *)tcp_saveipgen,
- &tcp_savetcp, 0);
-#endif
-
- /*
- * Return any desired output.
- */
- if (needoutput || (tp->t_flags & TF_ACKNOW))
- (void) tcp_output(tp);
-
-check_delack:
- if (tp->t_flags & TF_DELACK) {
- tp->t_flags &= ~TF_DELACK;
- callout_reset(tp->tt_delack, tcp_delacktime,
- tcp_timer_delack, tp);
- }
- INP_UNLOCK(inp);
- return;
-
-dropafterack:
- /*
- * Generate an ACK dropping incoming segment if it occupies
- * sequence space, where the ACK reflects our state.
- *
- * We can now skip the test for the RST flag since all
- * paths to this code happen after packets containing
- * RST have been dropped.
- *
- * In the SYN-RECEIVED state, don't send an ACK unless the
- * segment we received passes the SYN-RECEIVED ACK test.
- * If it fails send a RST. This breaks the loop in the
- * "LAND" DoS attack, and also prevents an ACK storm
- * between two listening ports that have been sent forged
- * SYN segments, each with the source address of the other.
- */
- if (tp->t_state == TCPS_SYN_RECEIVED && (thflags & TH_ACK) &&
- (SEQ_GT(tp->snd_una, th->th_ack) ||
- SEQ_GT(th->th_ack, tp->snd_max)) ) {
- rstreason = BANDLIM_RST_OPENPORT;
- goto dropwithreset;
- }
-#ifdef TCPDEBUG
- if (so->so_options & SO_DEBUG)
- tcp_trace(TA_DROP, ostate, tp, (void *)tcp_saveipgen,
- &tcp_savetcp, 0);
-#endif
- KASSERT(headlocked, ("headlocked should be 1"));
- INP_INFO_WUNLOCK(&tcbinfo);
- m_freem(m);
- tp->t_flags |= TF_ACKNOW;
- (void) tcp_output(tp);
- INP_UNLOCK(inp);
- return;
-
-dropwithreset:
- /*
- * Generate a RST, dropping incoming segment.
- * Make ACK acceptable to originator of segment.
- * Don't bother to respond if destination was broadcast/multicast.
- */
- if ((thflags & TH_RST) || m->m_flags & (M_BCAST|M_MCAST))
- goto drop;
- if (isipv6) {
- if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
- IN6_IS_ADDR_MULTICAST(&ip6->ip6_src))
- goto drop;
- } else {
- if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) ||
- IN_MULTICAST(ntohl(ip->ip_src.s_addr)) ||
- ip->ip_src.s_addr == htonl(INADDR_BROADCAST) ||
- in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif))
- goto drop;
- }
- /* IPv6 anycast check is done at tcp6_input() */
-
- /*
- * Perform bandwidth limiting.
- */
- if (badport_bandlim(rstreason) < 0)
- goto drop;
-
-#ifdef TCPDEBUG
- if (tp == 0 || (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
- tcp_trace(TA_DROP, ostate, tp, (void *)tcp_saveipgen,
- &tcp_savetcp, 0);
-#endif
-
- if (tp)
- INP_UNLOCK(inp);
-
- if (thflags & TH_ACK)
- /* mtod() below is safe as long as hdr dropping is delayed */
- tcp_respond(tp, mtod(m, void *), th, m, (tcp_seq)0, th->th_ack,
- TH_RST);
- else {
- if (thflags & TH_SYN)
- tlen++;
- /* mtod() below is safe as long as hdr dropping is delayed */
- tcp_respond(tp, mtod(m, void *), th, m, th->th_seq+tlen,
- (tcp_seq)0, TH_RST|TH_ACK);
- }
- if (headlocked)
- INP_INFO_WUNLOCK(&tcbinfo);
- return;
-
-drop:
- /*
- * Drop space held by incoming segment and return.
- */
-#ifdef TCPDEBUG
- if (tp == 0 || (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
- tcp_trace(TA_DROP, ostate, tp, (void *)tcp_saveipgen,
- &tcp_savetcp, 0);
-#endif
- if (tp)
- INP_UNLOCK(inp);
- m_freem(m);
- if (headlocked)
- INP_INFO_WUNLOCK(&tcbinfo);
- return;
-}
-
-/*
- * Parse TCP options and place in tcpopt.
- */
-static void
-tcp_dooptions(to, cp, cnt, is_syn)
- struct tcpopt *to;
- u_char *cp;
- int cnt;
- int is_syn;
-{
- int opt, optlen;
-
- to->to_flags = 0;
- for (; cnt > 0; cnt -= optlen, cp += optlen) {
- opt = cp[0];
- if (opt == TCPOPT_EOL)
- break;
- if (opt == TCPOPT_NOP)
- optlen = 1;
- else {
- if (cnt < 2)
- break;
- optlen = cp[1];
- if (optlen < 2 || optlen > cnt)
- break;
- }
- switch (opt) {
- case TCPOPT_MAXSEG:
- if (optlen != TCPOLEN_MAXSEG)
- continue;
- if (!is_syn)
- continue;
- to->to_flags |= TOF_MSS;
- bcopy((char *)cp + 2,
- (char *)&to->to_mss, sizeof(to->to_mss));
- to->to_mss = ntohs(to->to_mss);
- break;
- case TCPOPT_WINDOW:
- if (optlen != TCPOLEN_WINDOW)
- continue;
- if (! is_syn)
- continue;
- to->to_flags |= TOF_SCALE;
- to->to_requested_s_scale = min(cp[2], TCP_MAX_WINSHIFT);
- break;
- case TCPOPT_TIMESTAMP:
- if (optlen != TCPOLEN_TIMESTAMP)
- continue;
- to->to_flags |= TOF_TS;
- bcopy((char *)cp + 2,
- (char *)&to->to_tsval, sizeof(to->to_tsval));
- to->to_tsval = ntohl(to->to_tsval);
- bcopy((char *)cp + 6,
- (char *)&to->to_tsecr, sizeof(to->to_tsecr));
- to->to_tsecr = ntohl(to->to_tsecr);
- break;
- case TCPOPT_CC:
- if (optlen != TCPOLEN_CC)
- continue;
- to->to_flags |= TOF_CC;
- bcopy((char *)cp + 2,
- (char *)&to->to_cc, sizeof(to->to_cc));
- to->to_cc = ntohl(to->to_cc);
- break;
- case TCPOPT_CCNEW:
- if (optlen != TCPOLEN_CC)
- continue;
- if (!is_syn)
- continue;
- to->to_flags |= TOF_CCNEW;
- bcopy((char *)cp + 2,
- (char *)&to->to_cc, sizeof(to->to_cc));
- to->to_cc = ntohl(to->to_cc);
- break;
- case TCPOPT_CCECHO:
- if (optlen != TCPOLEN_CC)
- continue;
- if (!is_syn)
- continue;
- to->to_flags |= TOF_CCECHO;
- bcopy((char *)cp + 2,
- (char *)&to->to_ccecho, sizeof(to->to_ccecho));
- to->to_ccecho = ntohl(to->to_ccecho);
- break;
- default:
- continue;
- }
- }
-}
-
-/*
- * Pull out of band byte out of a segment so
- * it doesn't appear in the user's data queue.
- * It is still reflected in the segment length for
- * sequencing purposes.
- */
-static void
-tcp_pulloutofband(so, th, m, off)
- struct socket *so;
- struct tcphdr *th;
- register struct mbuf *m;
- int off; /* delayed to be droped hdrlen */
-{
- int cnt = off + th->th_urp - 1;
-
- while (cnt >= 0) {
- if (m->m_len > cnt) {
- char *cp = mtod(m, caddr_t) + cnt;
- struct tcpcb *tp = sototcpcb(so);
-
- tp->t_iobc = *cp;
- tp->t_oobflags |= TCPOOB_HAVEDATA;
- bcopy(cp+1, cp, (unsigned)(m->m_len - cnt - 1));
- m->m_len--;
- if (m->m_flags & M_PKTHDR)
- m->m_pkthdr.len--;
- return;
- }
- cnt -= m->m_len;
- m = m->m_next;
- if (m == 0)
- break;
- }
- panic("tcp_pulloutofband");
-}
-
-/*
- * Collect new round-trip time estimate
- * and update averages and current timeout.
- */
-static void
-tcp_xmit_timer(tp, rtt)
- register struct tcpcb *tp;
- int rtt;
-{
- register int delta;
-
- tcpstat.tcps_rttupdated++;
- tp->t_rttupdated++;
- if (tp->t_srtt != 0) {
- /*
- * srtt is stored as fixed point with 5 bits after the
- * binary point (i.e., scaled by 8). The following magic
- * is equivalent to the smoothing algorithm in rfc793 with
- * an alpha of .875 (srtt = rtt/8 + srtt*7/8 in fixed
- * point). Adjust rtt to origin 0.
- */
- delta = ((rtt - 1) << TCP_DELTA_SHIFT)
- - (tp->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT));
-
- if ((tp->t_srtt += delta) <= 0)
- tp->t_srtt = 1;
-
- /*
- * We accumulate a smoothed rtt variance (actually, a
- * smoothed mean difference), then set the retransmit
- * timer to smoothed rtt + 4 times the smoothed variance.
- * rttvar is stored as fixed point with 4 bits after the
- * binary point (scaled by 16). The following is
- * equivalent to rfc793 smoothing with an alpha of .75
- * (rttvar = rttvar*3/4 + |delta| / 4). This replaces
- * rfc793's wired-in beta.
- */
- if (delta < 0)
- delta = -delta;
- delta -= tp->t_rttvar >> (TCP_RTTVAR_SHIFT - TCP_DELTA_SHIFT);
- if ((tp->t_rttvar += delta) <= 0)
- tp->t_rttvar = 1;
- if (tp->t_rttbest > tp->t_srtt + tp->t_rttvar)
- tp->t_rttbest = tp->t_srtt + tp->t_rttvar;
- } else {
- /*
- * No rtt measurement yet - use the unsmoothed rtt.
- * Set the variance to half the rtt (so our first
- * retransmit happens at 3*rtt).
- */
- tp->t_srtt = rtt << TCP_RTT_SHIFT;
- tp->t_rttvar = rtt << (TCP_RTTVAR_SHIFT - 1);
- tp->t_rttbest = tp->t_srtt + tp->t_rttvar;
- }
- tp->t_rtttime = 0;
- tp->t_rxtshift = 0;
-
- /*
- * the retransmit should happen at rtt + 4 * rttvar.
- * Because of the way we do the smoothing, srtt and rttvar
- * will each average +1/2 tick of bias. When we compute
- * the retransmit timer, we want 1/2 tick of rounding and
- * 1 extra tick because of +-1/2 tick uncertainty in the
- * firing of the timer. The bias will give us exactly the
- * 1.5 tick we need. But, because the bias is
- * statistical, we have to test that we don't drop below
- * the minimum feasible timer (which is 2 ticks).
- */
- TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp),
- max(tp->t_rttmin, rtt + 2), TCPTV_REXMTMAX);
-
- /*
- * We received an ack for a packet that wasn't retransmitted;
- * it is probably safe to discard any error indications we've
- * received recently. This isn't quite right, but close enough
- * for now (a route might have failed after we sent a segment,
- * and the return path might not be symmetrical).
- */
- tp->t_softerror = 0;
-}
-
-/*
- * Determine a reasonable value for maxseg size.
- * If the route is known, check route for mtu.
- * If none, use an mss that can be handled on the outgoing
- * interface without forcing IP to fragment; if bigger than
- * an mbuf cluster (MCLBYTES), round down to nearest multiple of MCLBYTES
- * to utilize large mbufs. If no route is found, route has no mtu,
- * or the destination isn't local, use a default, hopefully conservative
- * size (usually 512 or the default IP max size, but no more than the mtu
- * of the interface), as we can't discover anything about intervening
- * gateways or networks. We also initialize the congestion/slow start
- * window to be a single segment if the destination isn't local.
- * While looking at the routing entry, we also initialize other path-dependent
- * parameters from pre-set or cached values in the routing entry.
- *
- * Also take into account the space needed for options that we
- * send regularly. Make maxseg shorter by that amount to assure
- * that we can send maxseg amount of data even when the options
- * are present. Store the upper limit of the length of options plus
- * data in maxopd.
- *
- * NOTE that this routine is only called when we process an incoming
- * segment, for outgoing segments only tcp_mssopt is called.
- *
- * In case of T/TCP, we call this routine during implicit connection
- * setup as well (offer = -1), to initialize maxseg from the cached
- * MSS of our peer.
- */
-void
-tcp_mss(tp, offer)
- struct tcpcb *tp;
- int offer;
-{
- register struct rtentry *rt;
- struct ifnet *ifp;
- register int rtt, mss;
- u_long bufsize;
- struct inpcb *inp = tp->t_inpcb;
- struct socket *so;
- struct rmxp_tao *taop;
- int origoffer = offer;
-#ifdef INET6
- int isipv6 = ((inp->inp_vflag & INP_IPV6) != 0) ? 1 : 0;
- size_t min_protoh = isipv6 ?
- sizeof (struct ip6_hdr) + sizeof (struct tcphdr) :
- sizeof (struct tcpiphdr);
-#else
- const int isipv6 = 0;
- const size_t min_protoh = sizeof (struct tcpiphdr);
-#endif
-
- if (isipv6)
- rt = tcp_rtlookup6(&inp->inp_inc);
- else
- rt = tcp_rtlookup(&inp->inp_inc);
- if (rt == NULL) {
- tp->t_maxopd = tp->t_maxseg =
- isipv6 ? tcp_v6mssdflt : tcp_mssdflt;
- return;
- }
- ifp = rt->rt_ifp;
- so = inp->inp_socket;
-
- taop = rmx_taop(rt->rt_rmx);
- /*
- * Offer == -1 means that we didn't receive SYN yet,
- * use cached value in that case;
- */
- if (offer == -1)
- offer = taop->tao_mssopt;
- /*
- * Offer == 0 means that there was no MSS on the SYN segment,
- * in this case we use tcp_mssdflt.
- */
- if (offer == 0)
- offer = isipv6 ? tcp_v6mssdflt : tcp_mssdflt;
- else
- /*
- * Sanity check: make sure that maxopd will be large
- * enough to allow some data on segments even is the
- * all the option space is used (40bytes). Otherwise
- * funny things may happen in tcp_output.
- */
- offer = max(offer, 64);
- taop->tao_mssopt = offer;
-
- /*
- * While we're here, check if there's an initial rtt
- * or rttvar. Convert from the route-table units
- * to scaled multiples of the slow timeout timer.
- */
- if (tp->t_srtt == 0 && (rtt = rt->rt_rmx.rmx_rtt)) {
- /*
- * XXX the lock bit for RTT indicates that the value
- * is also a minimum value; this is subject to time.
- */
- if (rt->rt_rmx.rmx_locks & RTV_RTT)
- tp->t_rttmin = rtt / (RTM_RTTUNIT / hz);
- tp->t_srtt = rtt / (RTM_RTTUNIT / (hz * TCP_RTT_SCALE));
- tp->t_rttbest = tp->t_srtt + TCP_RTT_SCALE;
- tcpstat.tcps_usedrtt++;
- if (rt->rt_rmx.rmx_rttvar) {
- tp->t_rttvar = rt->rt_rmx.rmx_rttvar /
- (RTM_RTTUNIT / (hz * TCP_RTTVAR_SCALE));
- tcpstat.tcps_usedrttvar++;
- } else {
- /* default variation is +- 1 rtt */
- tp->t_rttvar =
- tp->t_srtt * TCP_RTTVAR_SCALE / TCP_RTT_SCALE;
- }
- TCPT_RANGESET(tp->t_rxtcur,
- ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1,
- tp->t_rttmin, TCPTV_REXMTMAX);
- }
- /*
- * if there's an mtu associated with the route, use it
- * else, use the link mtu.
- */
- if (rt->rt_rmx.rmx_mtu)
- mss = rt->rt_rmx.rmx_mtu - min_protoh;
- else {
- if (isipv6) {
- mss = nd_ifinfo[rt->rt_ifp->if_index].linkmtu -
- min_protoh;
- if (!in6_localaddr(&inp->in6p_faddr))
- mss = min(mss, tcp_v6mssdflt);
- } else {
- mss = ifp->if_mtu - min_protoh;
- if (!in_localaddr(inp->inp_faddr))
- mss = min(mss, tcp_mssdflt);
- }
- }
- mss = min(mss, offer);
- /*
- * maxopd stores the maximum length of data AND options
- * in a segment; maxseg is the amount of data in a normal
- * segment. We need to store this value (maxopd) apart
- * from maxseg, because now every segment carries options
- * and thus we normally have somewhat less data in segments.
- */
- tp->t_maxopd = mss;
-
- /*
- * In case of T/TCP, origoffer==-1 indicates, that no segments
- * were received yet. In this case we just guess, otherwise
- * we do the same as before T/TCP.
- */
- if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP &&
- (origoffer == -1 ||
- (tp->t_flags & TF_RCVD_TSTMP) == TF_RCVD_TSTMP))
- mss -= TCPOLEN_TSTAMP_APPA;
- if ((tp->t_flags & (TF_REQ_CC|TF_NOOPT)) == TF_REQ_CC &&
- (origoffer == -1 ||
- (tp->t_flags & TF_RCVD_CC) == TF_RCVD_CC))
- mss -= TCPOLEN_CC_APPA;
-
-#if (MCLBYTES & (MCLBYTES - 1)) == 0
- if (mss > MCLBYTES)
- mss &= ~(MCLBYTES-1);
-#else
- if (mss > MCLBYTES)
- mss = mss / MCLBYTES * MCLBYTES;
-#endif
- /*
- * If there's a pipesize, change the socket buffer
- * to that size. Make the socket buffers an integral
- * number of mss units; if the mss is larger than
- * the socket buffer, decrease the mss.
- */
-#ifdef RTV_SPIPE
- if ((bufsize = rt->rt_rmx.rmx_sendpipe) == 0)
-#endif
- bufsize = so->so_snd.sb_hiwat;
- if (bufsize < mss)
- mss = bufsize;
- else {
- bufsize = roundup(bufsize, mss);
- if (bufsize > sb_max)
- bufsize = sb_max;
- if (bufsize > so->so_snd.sb_hiwat)
- (void)sbreserve(&so->so_snd, bufsize, so, NULL);
- }
- tp->t_maxseg = mss;
-
-#ifdef RTV_RPIPE
- if ((bufsize = rt->rt_rmx.rmx_recvpipe) == 0)
-#endif
- bufsize = so->so_rcv.sb_hiwat;
- if (bufsize > mss) {
- bufsize = roundup(bufsize, mss);
- if (bufsize > sb_max)
- bufsize = sb_max;
- if (bufsize > so->so_rcv.sb_hiwat)
- (void)sbreserve(&so->so_rcv, bufsize, so, NULL);
- }
-
- /*
- * Set the slow-start flight size depending on whether this
- * is a local network or not.
- */
- if (tcp_do_rfc3390)
- tp->snd_cwnd = min(4 * mss, max(2 * mss, 4380));
- else if ((isipv6 && in6_localaddr(&inp->in6p_faddr)) ||
- (!isipv6 && in_localaddr(inp->inp_faddr)))
- tp->snd_cwnd = mss * ss_fltsz_local;
- else
- tp->snd_cwnd = mss * ss_fltsz;
-
- if (rt->rt_rmx.rmx_ssthresh) {
- /*
- * There's some sort of gateway or interface
- * buffer limit on the path. Use this to set
- * the slow start threshhold, but set the
- * threshold to no less than 2*mss.
- */
- tp->snd_ssthresh = max(2 * mss, rt->rt_rmx.rmx_ssthresh);
- tcpstat.tcps_usedssthresh++;
- }
-}
-
-/*
- * Determine the MSS option to send on an outgoing SYN.
- */
-int
-tcp_mssopt(tp)
- struct tcpcb *tp;
-{
- struct rtentry *rt;
-#ifdef INET6
- int isipv6 = ((tp->t_inpcb->inp_vflag & INP_IPV6) != 0) ? 1 : 0;
- size_t min_protoh = isipv6 ?
- sizeof (struct ip6_hdr) + sizeof (struct tcphdr) :
- sizeof (struct tcpiphdr);
-#else
- const int isipv6 = 0;
- const size_t min_protoh = sizeof (struct tcpiphdr);
-#endif
-
- if (isipv6)
- rt = tcp_rtlookup6(&tp->t_inpcb->inp_inc);
- else
- rt = tcp_rtlookup(&tp->t_inpcb->inp_inc);
- if (rt == NULL)
- return (isipv6 ? tcp_v6mssdflt : tcp_mssdflt);
-
- return (rt->rt_ifp->if_mtu - min_protoh);
-}
-
-
-/*
- * On a partial ack arrives, force the retransmission of the
- * next unacknowledged segment. Do not clear tp->t_dupacks.
- * By setting snd_nxt to ti_ack, this forces retransmission timer to
- * be started again.
- */
-static void
-tcp_newreno_partial_ack(tp, th)
- struct tcpcb *tp;
- struct tcphdr *th;
-{
- tcp_seq onxt = tp->snd_nxt;
- u_long ocwnd = tp->snd_cwnd;
-
- callout_stop(tp->tt_rexmt);
- tp->t_rtttime = 0;
- tp->snd_nxt = th->th_ack;
- /*
- * Set snd_cwnd to one segment beyond acknowledged offset.
- * (tp->snd_una has not yet been updated when this function is called.)
- */
- tp->snd_cwnd = tp->t_maxseg + (th->th_ack - tp->snd_una);
- tp->t_flags |= TF_ACKNOW;
- (void) tcp_output(tp);
- tp->snd_cwnd = ocwnd;
- if (SEQ_GT(onxt, tp->snd_nxt))
- tp->snd_nxt = onxt;
- /*
- * Partial window deflation. Relies on fact that tp->snd_una
- * not updated yet.
- */
- tp->snd_cwnd -= (th->th_ack - tp->snd_una - tp->t_maxseg);
-}
-
-/*
- * Returns 1 if the TIME_WAIT state was killed and we should start over,
- * looking for a pcb in the listen state. Returns 0 otherwise.
- */
-static int
-tcp_timewait(tw, to, th, m, tlen)
- struct tcptw *tw;
- struct tcpopt *to;
- struct tcphdr *th;
- struct mbuf *m;
- int tlen;
-{
- int thflags;
- tcp_seq seq;
-#ifdef INET6
- int isipv6 = (mtod(m, struct ip *)->ip_v == 6) ? 1 : 0;
-#else
- const int isipv6 = 0;
-#endif
-
- thflags = th->th_flags;
-
- /*
- * NOTE: for FIN_WAIT_2 (to be added later),
- * must validate sequence number before accepting RST
- */
-
- /*
- * If the segment contains RST:
- * Drop the segment - see Stevens, vol. 2, p. 964 and
- * RFC 1337.
- */
- if (thflags & TH_RST)
- goto drop;
-
- /*
- * If segment contains a SYN and CC [not CC.NEW] option:
- * if connection duration > MSL, drop packet and send RST;
- *
- * if SEG.CC > CCrecv then is new SYN.
- * Complete close and delete TCPCB. Then reprocess
- * segment, hoping to find new TCPCB in LISTEN state;
- *
- * else must be old SYN; drop it.
- * else do normal processing.
- */
- if ((thflags & TH_SYN) && (to->to_flags & TOF_CC) && tw->cc_recv != 0) {
- if ((ticks - tw->t_starttime) > tcp_msl)
- goto reset;
- if (CC_GT(to->to_cc, tw->cc_recv)) {
- (void) tcp_twclose(tw, 0);
- return (1);
- }
- goto drop;
- }
-
-#if 0
-/* PAWS not needed at the moment */
- /*
- * RFC 1323 PAWS: If we have a timestamp reply on this segment
- * and it's less than ts_recent, drop it.
- */
- if ((to.to_flags & TOF_TS) != 0 && tp->ts_recent &&
- TSTMP_LT(to.to_tsval, tp->ts_recent)) {
- if ((thflags & TH_ACK) == 0)
- goto drop;
- goto ack;
- }
- /*
- * ts_recent is never updated because we never accept new segments.
- */
-#endif
-
- /*
- * If a new connection request is received
- * while in TIME_WAIT, drop the old connection
- * and start over if the sequence numbers
- * are above the previous ones.
- */
- if ((thflags & TH_SYN) && SEQ_GT(th->th_seq, tw->rcv_nxt)) {
- (void) tcp_twclose(tw, 0);
- return (1);
- }
-
- /*
- * Drop the the segment if it does not contain an ACK.
- */
- if ((thflags & TH_ACK) == 0)
- goto drop;
-
- /*
- * Reset the 2MSL timer if this is a duplicate FIN.
- */
- if (thflags & TH_FIN) {
- seq = th->th_seq + tlen + (thflags & TH_SYN ? 1 : 0);
- if (seq + 1 == tw->rcv_nxt)
- tcp_timer_2msl_reset(tw, 2 * tcp_msl);
- }
-
- /*
- * Acknowledge the segment if it has data or is not a duplicate ACK.
- */
- if (thflags != TH_ACK || tlen != 0 ||
- th->th_seq != tw->rcv_nxt || th->th_ack != tw->snd_nxt)
- tcp_twrespond(tw, NULL, m, TH_ACK);
- goto drop;
-
-reset:
- /*
- * Generate a RST, dropping incoming segment.
- * Make ACK acceptable to originator of segment.
- * Don't bother to respond if destination was broadcast/multicast.
- */
- if (m->m_flags & (M_BCAST|M_MCAST))
- goto drop;
- if (isipv6) {
- struct ip6_hdr *ip6;
-
- /* IPv6 anycast check is done at tcp6_input() */
- ip6 = mtod(m, struct ip6_hdr *);
- if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
- IN6_IS_ADDR_MULTICAST(&ip6->ip6_src))
- goto drop;
- } else {
- struct ip *ip;
-
- ip = mtod(m, struct ip *);
- if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) ||
- IN_MULTICAST(ntohl(ip->ip_src.s_addr)) ||
- ip->ip_src.s_addr == htonl(INADDR_BROADCAST) ||
- in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif))
- goto drop;
- }
- if (thflags & TH_ACK) {
- tcp_respond(NULL,
- mtod(m, void *), th, m, 0, th->th_ack, TH_RST);
- } else {
- seq = th->th_seq + (thflags & TH_SYN ? 1 : 0);
- tcp_respond(NULL,
- mtod(m, void *), th, m, seq, 0, TH_RST|TH_ACK);
- }
- INP_UNLOCK(tw->tw_inpcb);
- return (0);
-
-drop:
- INP_UNLOCK(tw->tw_inpcb);
- m_freem(m);
- return (0);
-}
diff --git a/sys/netinet/tcp_timewait.c b/sys/netinet/tcp_timewait.c
deleted file mode 100644
index 8816bc68986b..000000000000
--- a/sys/netinet/tcp_timewait.c
+++ /dev/null
@@ -1,1955 +0,0 @@
-/*
- * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95
- * $FreeBSD$
- */
-
-#include "opt_compat.h"
-#include "opt_inet6.h"
-#include "opt_ipsec.h"
-#include "opt_mac.h"
-#include "opt_tcpdebug.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/callout.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/mac.h>
-#include <sys/malloc.h>
-#include <sys/mbuf.h>
-#ifdef INET6
-#include <sys/domain.h>
-#endif
-#include <sys/proc.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/protosw.h>
-#include <sys/random.h>
-
-#include <vm/uma.h>
-
-#include <net/route.h>
-#include <net/if.h>
-
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#ifdef INET6
-#include <netinet/ip6.h>
-#endif
-#include <netinet/in_pcb.h>
-#ifdef INET6
-#include <netinet6/in6_pcb.h>
-#endif
-#include <netinet/in_var.h>
-#include <netinet/ip_var.h>
-#ifdef INET6
-#include <netinet6/ip6_var.h>
-#endif
-#include <netinet/tcp.h>
-#include <netinet/tcp_fsm.h>
-#include <netinet/tcp_seq.h>
-#include <netinet/tcp_timer.h>
-#include <netinet/tcp_var.h>
-#ifdef INET6
-#include <netinet6/tcp6_var.h>
-#endif
-#include <netinet/tcpip.h>
-#ifdef TCPDEBUG
-#include <netinet/tcp_debug.h>
-#endif
-#include <netinet6/ip6protosw.h>
-
-#ifdef IPSEC
-#include <netinet6/ipsec.h>
-#ifdef INET6
-#include <netinet6/ipsec6.h>
-#endif
-#endif /*IPSEC*/
-
-#ifdef FAST_IPSEC
-#include <netipsec/ipsec.h>
-#ifdef INET6
-#include <netipsec/ipsec6.h>
-#endif
-#define IPSEC
-#endif /*FAST_IPSEC*/
-
-#include <machine/in_cksum.h>
-#include <sys/md5.h>
-
-int tcp_mssdflt = TCP_MSS;
-SYSCTL_INT(_net_inet_tcp, TCPCTL_MSSDFLT, mssdflt, CTLFLAG_RW,
- &tcp_mssdflt , 0, "Default TCP Maximum Segment Size");
-
-#ifdef INET6
-int tcp_v6mssdflt = TCP6_MSS;
-SYSCTL_INT(_net_inet_tcp, TCPCTL_V6MSSDFLT, v6mssdflt,
- CTLFLAG_RW, &tcp_v6mssdflt , 0,
- "Default TCP Maximum Segment Size for IPv6");
-#endif
-
-#if 0
-static int tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ;
-SYSCTL_INT(_net_inet_tcp, TCPCTL_RTTDFLT, rttdflt, CTLFLAG_RW,
- &tcp_rttdflt , 0, "Default maximum TCP Round Trip Time");
-#endif
-
-int tcp_do_rfc1323 = 1;
-SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1323, rfc1323, CTLFLAG_RW,
- &tcp_do_rfc1323 , 0, "Enable rfc1323 (high performance TCP) extensions");
-
-int tcp_do_rfc1644 = 0;
-SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1644, rfc1644, CTLFLAG_RW,
- &tcp_do_rfc1644 , 0, "Enable rfc1644 (TTCP) extensions");
-
-static int tcp_tcbhashsize = 0;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, tcbhashsize, CTLFLAG_RD,
- &tcp_tcbhashsize, 0, "Size of TCP control-block hashtable");
-
-static int do_tcpdrain = 1;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, do_tcpdrain, CTLFLAG_RW, &do_tcpdrain, 0,
- "Enable tcp_drain routine for extra help when low on mbufs");
-
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, pcbcount, CTLFLAG_RD,
- &tcbinfo.ipi_count, 0, "Number of active PCBs");
-
-static int icmp_may_rst = 1;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, icmp_may_rst, CTLFLAG_RW, &icmp_may_rst, 0,
- "Certain ICMP unreachable messages may abort connections in SYN_SENT");
-
-static int tcp_isn_reseed_interval = 0;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, isn_reseed_interval, CTLFLAG_RW,
- &tcp_isn_reseed_interval, 0, "Seconds between reseeding of ISN secret");
-
-/*
- * TCP bandwidth limiting sysctls. Note that the default lower bound of
- * 1024 exists only for debugging. A good production default would be
- * something like 6100.
- */
-static int tcp_inflight_enable = 0;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, inflight_enable, CTLFLAG_RW,
- &tcp_inflight_enable, 0, "Enable automatic TCP inflight data limiting");
-
-static int tcp_inflight_debug = 0;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, inflight_debug, CTLFLAG_RW,
- &tcp_inflight_debug, 0, "Debug TCP inflight calculations");
-
-static int tcp_inflight_min = 6144;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, inflight_min, CTLFLAG_RW,
- &tcp_inflight_min, 0, "Lower-bound for TCP inflight window");
-
-static int tcp_inflight_max = TCP_MAXWIN << TCP_MAX_WINSHIFT;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, inflight_max, CTLFLAG_RW,
- &tcp_inflight_max, 0, "Upper-bound for TCP inflight window");
-static int tcp_inflight_stab = 20;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, inflight_stab, CTLFLAG_RW,
- &tcp_inflight_stab, 0, "Inflight Algorithm Stabilization 20 = 2 packets");
-
-static void tcp_cleartaocache(void);
-static struct inpcb *tcp_notify(struct inpcb *, int);
-static void tcp_discardcb(struct tcpcb *);
-
-/*
- * Target size of TCP PCB hash tables. Must be a power of two.
- *
- * Note that this can be overridden by the kernel environment
- * variable net.inet.tcp.tcbhashsize
- */
-#ifndef TCBHASHSIZE
-#define TCBHASHSIZE 512
-#endif
-
-/*
- * XXX
- * Callouts should be moved into struct tcp directly. They are currently
- * separate becuase the tcpcb structure is exported to userland for sysctl
- * parsing purposes, which do not know about callouts.
- */
-struct tcpcb_mem {
- struct tcpcb tcb;
- struct callout tcpcb_mem_rexmt, tcpcb_mem_persist, tcpcb_mem_keep;
- struct callout tcpcb_mem_2msl, tcpcb_mem_delack;
-};
-
-static uma_zone_t tcpcb_zone;
-static uma_zone_t tcptw_zone;
-
-/*
- * Tcp initialization
- */
-void
-tcp_init()
-{
- int hashsize = TCBHASHSIZE;
-
- tcp_ccgen = 1;
- tcp_cleartaocache();
-
- tcp_delacktime = TCPTV_DELACK;
- tcp_keepinit = TCPTV_KEEP_INIT;
- tcp_keepidle = TCPTV_KEEP_IDLE;
- tcp_keepintvl = TCPTV_KEEPINTVL;
- tcp_maxpersistidle = TCPTV_KEEP_IDLE;
- tcp_msl = TCPTV_MSL;
- tcp_rexmit_min = TCPTV_MIN;
- tcp_rexmit_slop = TCPTV_CPU_VAR;
-
- INP_INFO_LOCK_INIT(&tcbinfo, "tcp");
- LIST_INIT(&tcb);
- tcbinfo.listhead = &tcb;
- TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", &hashsize);
- if (!powerof2(hashsize)) {
- printf("WARNING: TCB hash size not a power of 2\n");
- hashsize = 512; /* safe default */
- }
- tcp_tcbhashsize = hashsize;
- tcbinfo.hashbase = hashinit(hashsize, M_PCB, &tcbinfo.hashmask);
- tcbinfo.porthashbase = hashinit(hashsize, M_PCB,
- &tcbinfo.porthashmask);
- tcbinfo.ipi_zone = uma_zcreate("inpcb", sizeof(struct inpcb),
- NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
- uma_zone_set_max(tcbinfo.ipi_zone, maxsockets);
-#ifdef INET6
-#define TCP_MINPROTOHDR (sizeof(struct ip6_hdr) + sizeof(struct tcphdr))
-#else /* INET6 */
-#define TCP_MINPROTOHDR (sizeof(struct tcpiphdr))
-#endif /* INET6 */
- if (max_protohdr < TCP_MINPROTOHDR)
- max_protohdr = TCP_MINPROTOHDR;
- if (max_linkhdr + TCP_MINPROTOHDR > MHLEN)
- panic("tcp_init");
-#undef TCP_MINPROTOHDR
- /*
- * These have to be type stable for the benefit of the timers.
- */
- tcpcb_zone = uma_zcreate("tcpcb", sizeof(struct tcpcb_mem),
- NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
- uma_zone_set_max(tcpcb_zone, maxsockets);
- tcptw_zone = uma_zcreate("tcptw", sizeof(struct tcptw),
- NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
- uma_zone_set_max(tcptw_zone, maxsockets);
- tcp_timer_init();
- syncache_init();
-}
-
-/*
- * Fill in the IP and TCP headers for an outgoing packet, given the tcpcb.
- * tcp_template used to store this data in mbufs, but we now recopy it out
- * of the tcpcb each time to conserve mbufs.
- */
-void
-tcpip_fillheaders(inp, ip_ptr, tcp_ptr)
- struct inpcb *inp;
- void *ip_ptr;
- void *tcp_ptr;
-{
- struct tcphdr *th = (struct tcphdr *)tcp_ptr;
-
-#ifdef INET6
- if ((inp->inp_vflag & INP_IPV6) != 0) {
- struct ip6_hdr *ip6;
-
- ip6 = (struct ip6_hdr *)ip_ptr;
- ip6->ip6_flow = (ip6->ip6_flow & ~IPV6_FLOWINFO_MASK) |
- (inp->in6p_flowinfo & IPV6_FLOWINFO_MASK);
- ip6->ip6_vfc = (ip6->ip6_vfc & ~IPV6_VERSION_MASK) |
- (IPV6_VERSION & IPV6_VERSION_MASK);
- ip6->ip6_nxt = IPPROTO_TCP;
- ip6->ip6_plen = sizeof(struct tcphdr);
- ip6->ip6_src = inp->in6p_laddr;
- ip6->ip6_dst = inp->in6p_faddr;
- } else
-#endif
- {
- struct ip *ip;
-
- ip = (struct ip *)ip_ptr;
- ip->ip_v = IPVERSION;
- ip->ip_hl = 5;
- ip->ip_tos = inp->inp_ip_tos;
- ip->ip_len = 0;
- ip->ip_id = 0;
- ip->ip_off = 0;
- ip->ip_ttl = inp->inp_ip_ttl;
- ip->ip_sum = 0;
- ip->ip_p = IPPROTO_TCP;
- ip->ip_src = inp->inp_laddr;
- ip->ip_dst = inp->inp_faddr;
- }
- th->th_sport = inp->inp_lport;
- th->th_dport = inp->inp_fport;
- th->th_seq = 0;
- th->th_ack = 0;
- th->th_x2 = 0;
- th->th_off = 5;
- th->th_flags = 0;
- th->th_win = 0;
- th->th_urp = 0;
- th->th_sum = 0; /* in_pseudo() is called later for ipv4 */
-}
-
-/*
- * Create template to be used to send tcp packets on a connection.
- * Allocates an mbuf and fills in a skeletal tcp/ip header. The only
- * use for this function is in keepalives, which use tcp_respond.
- */
-struct tcptemp *
-tcpip_maketemplate(inp)
- struct inpcb *inp;
-{
- struct mbuf *m;
- struct tcptemp *n;
-
- m = m_get(M_DONTWAIT, MT_HEADER);
- if (m == NULL)
- return (0);
- m->m_len = sizeof(struct tcptemp);
- n = mtod(m, struct tcptemp *);
-
- tcpip_fillheaders(inp, (void *)&n->tt_ipgen, (void *)&n->tt_t);
- return (n);
-}
-
-/*
- * Send a single message to the TCP at address specified by
- * the given TCP/IP header. If m == 0, then we make a copy
- * of the tcpiphdr at ti and send directly to the addressed host.
- * This is used to force keep alive messages out using the TCP
- * template for a connection. If flags are given then we send
- * a message back to the TCP which originated the * segment ti,
- * and discard the mbuf containing it and any other attached mbufs.
- *
- * In any case the ack and sequence number of the transmitted
- * segment are as specified by the parameters.
- *
- * NOTE: If m != NULL, then ti must point to *inside* the mbuf.
- */
-void
-tcp_respond(tp, ipgen, th, m, ack, seq, flags)
- struct tcpcb *tp;
- void *ipgen;
- register struct tcphdr *th;
- register struct mbuf *m;
- tcp_seq ack, seq;
- int flags;
-{
- register int tlen;
- int win = 0;
- struct route *ro = 0;
- struct route sro;
- struct ip *ip;
- struct tcphdr *nth;
-#ifdef INET6
- struct route_in6 *ro6 = 0;
- struct route_in6 sro6;
- struct ip6_hdr *ip6;
- int isipv6;
-#endif /* INET6 */
- int ipflags = 0;
-
- KASSERT(tp != NULL || m != NULL, ("tcp_respond: tp and m both NULL"));
-
-#ifdef INET6
- isipv6 = ((struct ip *)ipgen)->ip_v == 6;
- ip6 = ipgen;
-#endif /* INET6 */
- ip = ipgen;
-
- if (tp) {
- if (!(flags & TH_RST)) {
- win = sbspace(&tp->t_inpcb->inp_socket->so_rcv);
- if (win > (long)TCP_MAXWIN << tp->rcv_scale)
- win = (long)TCP_MAXWIN << tp->rcv_scale;
- }
-#ifdef INET6
- if (isipv6)
- ro6 = &tp->t_inpcb->in6p_route;
- else
-#endif /* INET6 */
- ro = &tp->t_inpcb->inp_route;
- } else {
-#ifdef INET6
- if (isipv6) {
- ro6 = &sro6;
- bzero(ro6, sizeof *ro6);
- } else
-#endif /* INET6 */
- {
- ro = &sro;
- bzero(ro, sizeof *ro);
- }
- }
- if (m == 0) {
- m = m_gethdr(M_DONTWAIT, MT_HEADER);
- if (m == NULL)
- return;
- tlen = 0;
- m->m_data += max_linkhdr;
-#ifdef INET6
- if (isipv6) {
- bcopy((caddr_t)ip6, mtod(m, caddr_t),
- sizeof(struct ip6_hdr));
- ip6 = mtod(m, struct ip6_hdr *);
- nth = (struct tcphdr *)(ip6 + 1);
- } else
-#endif /* INET6 */
- {
- bcopy((caddr_t)ip, mtod(m, caddr_t), sizeof(struct ip));
- ip = mtod(m, struct ip *);
- nth = (struct tcphdr *)(ip + 1);
- }
- bcopy((caddr_t)th, (caddr_t)nth, sizeof(struct tcphdr));
- flags = TH_ACK;
- } else {
- m_freem(m->m_next);
- m->m_next = 0;
- m->m_data = (caddr_t)ipgen;
- /* m_len is set later */
- tlen = 0;
-#define xchg(a,b,type) { type t; t=a; a=b; b=t; }
-#ifdef INET6
- if (isipv6) {
- xchg(ip6->ip6_dst, ip6->ip6_src, struct in6_addr);
- nth = (struct tcphdr *)(ip6 + 1);
- } else
-#endif /* INET6 */
- {
- xchg(ip->ip_dst.s_addr, ip->ip_src.s_addr, n_long);
- nth = (struct tcphdr *)(ip + 1);
- }
- if (th != nth) {
- /*
- * this is usually a case when an extension header
- * exists between the IPv6 header and the
- * TCP header.
- */
- nth->th_sport = th->th_sport;
- nth->th_dport = th->th_dport;
- }
- xchg(nth->th_dport, nth->th_sport, n_short);
-#undef xchg
- }
-#ifdef INET6
- if (isipv6) {
- ip6->ip6_flow = 0;
- ip6->ip6_vfc = IPV6_VERSION;
- ip6->ip6_nxt = IPPROTO_TCP;
- ip6->ip6_plen = htons((u_short)(sizeof (struct tcphdr) +
- tlen));
- tlen += sizeof (struct ip6_hdr) + sizeof (struct tcphdr);
- } else
-#endif
- {
- tlen += sizeof (struct tcpiphdr);
- ip->ip_len = tlen;
- ip->ip_ttl = ip_defttl;
- }
- m->m_len = tlen;
- m->m_pkthdr.len = tlen;
- m->m_pkthdr.rcvif = (struct ifnet *) 0;
-#ifdef MAC
- if (tp != NULL && tp->t_inpcb != NULL) {
- /*
- * Packet is associated with a socket, so allow the
- * label of the response to reflect the socket label.
- */
- mac_create_mbuf_from_socket(tp->t_inpcb->inp_socket, m);
- } else {
- /*
- * XXXMAC: This will need to call a mac function that
- * modifies the mbuf label in place for TCP datagrams
- * not associated with a PCB.
- */
- }
-#endif
- nth->th_seq = htonl(seq);
- nth->th_ack = htonl(ack);
- nth->th_x2 = 0;
- nth->th_off = sizeof (struct tcphdr) >> 2;
- nth->th_flags = flags;
- if (tp)
- nth->th_win = htons((u_short) (win >> tp->rcv_scale));
- else
- nth->th_win = htons((u_short)win);
- nth->th_urp = 0;
-#ifdef INET6
- if (isipv6) {
- nth->th_sum = 0;
- nth->th_sum = in6_cksum(m, IPPROTO_TCP,
- sizeof(struct ip6_hdr),
- tlen - sizeof(struct ip6_hdr));
- ip6->ip6_hlim = in6_selecthlim(tp ? tp->t_inpcb : NULL,
- ro6 && ro6->ro_rt ?
- ro6->ro_rt->rt_ifp :
- NULL);
- } else
-#endif /* INET6 */
- {
- nth->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr,
- htons((u_short)(tlen - sizeof(struct ip) + ip->ip_p)));
- m->m_pkthdr.csum_flags = CSUM_TCP;
- m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum);
- }
-#ifdef TCPDEBUG
- if (tp == NULL || (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
- tcp_trace(TA_OUTPUT, 0, tp, mtod(m, void *), th, 0);
-#endif
-#ifdef INET6
- if (isipv6) {
- (void)ip6_output(m, NULL, ro6, ipflags, NULL, NULL,
- tp ? tp->t_inpcb : NULL);
- if (ro6 == &sro6 && ro6->ro_rt) {
- RTFREE(ro6->ro_rt);
- ro6->ro_rt = NULL;
- }
- } else
-#endif /* INET6 */
- {
- (void) ip_output(m, NULL, ro, ipflags, NULL, tp ? tp->t_inpcb : NULL);
- if (ro == &sro && ro->ro_rt) {
- RTFREE(ro->ro_rt);
- ro->ro_rt = NULL;
- }
- }
-}
-
-/*
- * Create a new TCP control block, making an
- * empty reassembly queue and hooking it to the argument
- * protocol control block. The `inp' parameter must have
- * come from the zone allocator set up in tcp_init().
- */
-struct tcpcb *
-tcp_newtcpcb(inp)
- struct inpcb *inp;
-{
- struct tcpcb_mem *tm;
- struct tcpcb *tp;
-#ifdef INET6
- int isipv6 = (inp->inp_vflag & INP_IPV6) != 0;
-#endif /* INET6 */
-
- tm = uma_zalloc(tcpcb_zone, M_NOWAIT | M_ZERO);
- if (tm == NULL)
- return (NULL);
- tp = &tm->tcb;
- /* LIST_INIT(&tp->t_segq); */ /* XXX covered by M_ZERO */
- tp->t_maxseg = tp->t_maxopd =
-#ifdef INET6
- isipv6 ? tcp_v6mssdflt :
-#endif /* INET6 */
- tcp_mssdflt;
-
- /* Set up our timeouts. */
- callout_init(tp->tt_rexmt = &tm->tcpcb_mem_rexmt, 0);
- callout_init(tp->tt_persist = &tm->tcpcb_mem_persist, 0);
- callout_init(tp->tt_keep = &tm->tcpcb_mem_keep, 0);
- callout_init(tp->tt_2msl = &tm->tcpcb_mem_2msl, 0);
- callout_init(tp->tt_delack = &tm->tcpcb_mem_delack, 0);
-
- if (tcp_do_rfc1323)
- tp->t_flags = (TF_REQ_SCALE|TF_REQ_TSTMP);
- if (tcp_do_rfc1644)
- tp->t_flags |= TF_REQ_CC;
- tp->t_inpcb = inp; /* XXX */
- /*
- * Init srtt to TCPTV_SRTTBASE (0), so we can tell that we have no
- * rtt estimate. Set rttvar so that srtt + 4 * rttvar gives
- * reasonable initial retransmit time.
- */
- tp->t_srtt = TCPTV_SRTTBASE;
- tp->t_rttvar = ((TCPTV_RTOBASE - TCPTV_SRTTBASE) << TCP_RTTVAR_SHIFT) / 4;
- tp->t_rttmin = tcp_rexmit_min;
- tp->t_rxtcur = TCPTV_RTOBASE;
- tp->snd_cwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT;
- tp->snd_bwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT;
- tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT;
- tp->t_rcvtime = ticks;
- tp->t_bw_rtttime = ticks;
- /*
- * IPv4 TTL initialization is necessary for an IPv6 socket as well,
- * because the socket may be bound to an IPv6 wildcard address,
- * which may match an IPv4-mapped IPv6 address.
- */
- inp->inp_ip_ttl = ip_defttl;
- inp->inp_ppcb = (caddr_t)tp;
- return (tp); /* XXX */
-}
-
-/*
- * Drop a TCP connection, reporting
- * the specified error. If connection is synchronized,
- * then send a RST to peer.
- */
-struct tcpcb *
-tcp_drop(tp, errno)
- register struct tcpcb *tp;
- int errno;
-{
- struct socket *so = tp->t_inpcb->inp_socket;
-
- if (TCPS_HAVERCVDSYN(tp->t_state)) {
- tp->t_state = TCPS_CLOSED;
- (void) tcp_output(tp);
- tcpstat.tcps_drops++;
- } else
- tcpstat.tcps_conndrops++;
- if (errno == ETIMEDOUT && tp->t_softerror)
- errno = tp->t_softerror;
- so->so_error = errno;
- return (tcp_close(tp));
-}
-
-static void
-tcp_discardcb(tp)
- struct tcpcb *tp;
-{
- struct tseg_qent *q;
- struct inpcb *inp = tp->t_inpcb;
- struct socket *so = inp->inp_socket;
-#ifdef INET6
- int isipv6 = (inp->inp_vflag & INP_IPV6) != 0;
-#endif /* INET6 */
- struct rtentry *rt;
- int dosavessthresh;
-
- /*
- * Make sure that all of our timers are stopped before we
- * delete the PCB.
- */
- callout_stop(tp->tt_rexmt);
- callout_stop(tp->tt_persist);
- callout_stop(tp->tt_keep);
- callout_stop(tp->tt_2msl);
- callout_stop(tp->tt_delack);
-
- /*
- * If we got enough samples through the srtt filter,
- * save the rtt and rttvar in the routing entry.
- * 'Enough' is arbitrarily defined as the 16 samples.
- * 16 samples is enough for the srtt filter to converge
- * to within 5% of the correct value; fewer samples and
- * we could save a very bogus rtt.
- *
- * Don't update the default route's characteristics and don't
- * update anything that the user "locked".
- */
- if (tp->t_rttupdated >= 16) {
- register u_long i = 0;
-#ifdef INET6
- if (isipv6) {
- struct sockaddr_in6 *sin6;
-
- if ((rt = inp->in6p_route.ro_rt) == NULL)
- goto no_valid_rt;
- sin6 = (struct sockaddr_in6 *)rt_key(rt);
- if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
- goto no_valid_rt;
- }
- else
-#endif /* INET6 */
- if ((rt = inp->inp_route.ro_rt) == NULL ||
- ((struct sockaddr_in *)rt_key(rt))->sin_addr.s_addr
- == INADDR_ANY)
- goto no_valid_rt;
-
- if ((rt->rt_rmx.rmx_locks & RTV_RTT) == 0) {
- i = tp->t_srtt *
- (RTM_RTTUNIT / (hz * TCP_RTT_SCALE));
- if (rt->rt_rmx.rmx_rtt && i)
- /*
- * filter this update to half the old & half
- * the new values, converting scale.
- * See route.h and tcp_var.h for a
- * description of the scaling constants.
- */
- rt->rt_rmx.rmx_rtt =
- (rt->rt_rmx.rmx_rtt + i) / 2;
- else
- rt->rt_rmx.rmx_rtt = i;
- tcpstat.tcps_cachedrtt++;
- }
- if ((rt->rt_rmx.rmx_locks & RTV_RTTVAR) == 0) {
- i = tp->t_rttvar *
- (RTM_RTTUNIT / (hz * TCP_RTTVAR_SCALE));
- if (rt->rt_rmx.rmx_rttvar && i)
- rt->rt_rmx.rmx_rttvar =
- (rt->rt_rmx.rmx_rttvar + i) / 2;
- else
- rt->rt_rmx.rmx_rttvar = i;
- tcpstat.tcps_cachedrttvar++;
- }
- /*
- * The old comment here said:
- * update the pipelimit (ssthresh) if it has been updated
- * already or if a pipesize was specified & the threshhold
- * got below half the pipesize. I.e., wait for bad news
- * before we start updating, then update on both good
- * and bad news.
- *
- * But we want to save the ssthresh even if no pipesize is
- * specified explicitly in the route, because such
- * connections still have an implicit pipesize specified
- * by the global tcp_sendspace. In the absence of a reliable
- * way to calculate the pipesize, it will have to do.
- */
- i = tp->snd_ssthresh;
- if (rt->rt_rmx.rmx_sendpipe != 0)
- dosavessthresh = (i < rt->rt_rmx.rmx_sendpipe / 2);
- else
- dosavessthresh = (i < so->so_snd.sb_hiwat / 2);
- if (((rt->rt_rmx.rmx_locks & RTV_SSTHRESH) == 0 &&
- i != 0 && rt->rt_rmx.rmx_ssthresh != 0)
- || dosavessthresh) {
- /*
- * convert the limit from user data bytes to
- * packets then to packet data bytes.
- */
- i = (i + tp->t_maxseg / 2) / tp->t_maxseg;
- if (i < 2)
- i = 2;
- i *= (u_long)(tp->t_maxseg +
-#ifdef INET6
- (isipv6 ? sizeof (struct ip6_hdr) +
- sizeof (struct tcphdr) :
-#endif
- sizeof (struct tcpiphdr)
-#ifdef INET6
- )
-#endif
- );
- if (rt->rt_rmx.rmx_ssthresh)
- rt->rt_rmx.rmx_ssthresh =
- (rt->rt_rmx.rmx_ssthresh + i) / 2;
- else
- rt->rt_rmx.rmx_ssthresh = i;
- tcpstat.tcps_cachedssthresh++;
- }
- }
- no_valid_rt:
- /* free the reassembly queue, if any */
- while ((q = LIST_FIRST(&tp->t_segq)) != NULL) {
- LIST_REMOVE(q, tqe_q);
- m_freem(q->tqe_m);
- FREE(q, M_TSEGQ);
- }
- inp->inp_ppcb = NULL;
- tp->t_inpcb = NULL;
- uma_zfree(tcpcb_zone, tp);
- soisdisconnected(so);
-}
-
-/*
- * Close a TCP control block:
- * discard all space held by the tcp
- * discard internet protocol block
- * wake up any sleepers
- */
-struct tcpcb *
-tcp_close(tp)
- struct tcpcb *tp;
-{
- struct inpcb *inp = tp->t_inpcb;
-#ifdef INET6
- struct socket *so = inp->inp_socket;
-#endif
-
- tcp_discardcb(tp);
-#ifdef INET6
- if (INP_CHECK_SOCKAF(so, AF_INET6))
- in6_pcbdetach(inp);
- else
-#endif
- in_pcbdetach(inp);
- tcpstat.tcps_closed++;
- return ((struct tcpcb *)0);
-}
-
-void
-tcp_drain()
-{
- if (do_tcpdrain)
- {
- struct inpcb *inpb;
- struct tcpcb *tcpb;
- struct tseg_qent *te;
-
- /*
- * Walk the tcpbs, if existing, and flush the reassembly queue,
- * if there is one...
- * XXX: The "Net/3" implementation doesn't imply that the TCP
- * reassembly queue should be flushed, but in a situation
- * where we're really low on mbufs, this is potentially
- * usefull.
- */
- INP_INFO_RLOCK(&tcbinfo);
- LIST_FOREACH(inpb, tcbinfo.listhead, inp_list) {
- if (inpb->inp_vflag & INP_TIMEWAIT)
- continue;
- INP_LOCK(inpb);
- if ((tcpb = intotcpcb(inpb))) {
- while ((te = LIST_FIRST(&tcpb->t_segq))
- != NULL) {
- LIST_REMOVE(te, tqe_q);
- m_freem(te->tqe_m);
- FREE(te, M_TSEGQ);
- }
- }
- INP_UNLOCK(inpb);
- }
- INP_INFO_RUNLOCK(&tcbinfo);
- }
-}
-
-/*
- * Notify a tcp user of an asynchronous error;
- * store error as soft error, but wake up user
- * (for now, won't do anything until can select for soft error).
- *
- * Do not wake up user since there currently is no mechanism for
- * reporting soft errors (yet - a kqueue filter may be added).
- */
-static struct inpcb *
-tcp_notify(inp, error)
- struct inpcb *inp;
- int error;
-{
- struct tcpcb *tp = (struct tcpcb *)inp->inp_ppcb;
-
- /*
- * Ignore some errors if we are hooked up.
- * If connection hasn't completed, has retransmitted several times,
- * and receives a second error, give up now. This is better
- * than waiting a long time to establish a connection that
- * can never complete.
- */
- if (tp->t_state == TCPS_ESTABLISHED &&
- (error == EHOSTUNREACH || error == ENETUNREACH ||
- error == EHOSTDOWN)) {
- return inp;
- } else if (tp->t_state < TCPS_ESTABLISHED && tp->t_rxtshift > 3 &&
- tp->t_softerror) {
- tcp_drop(tp, error);
- return (struct inpcb *)0;
- } else {
- tp->t_softerror = error;
- return inp;
- }
-#if 0
- wakeup( &so->so_timeo);
- sorwakeup(so);
- sowwakeup(so);
-#endif
-}
-
-static int
-tcp_pcblist(SYSCTL_HANDLER_ARGS)
-{
- int error, i, n, s;
- struct inpcb *inp, **inp_list;
- inp_gen_t gencnt;
- struct xinpgen xig;
-
- /*
- * The process of preparing the TCB list is too time-consuming and
- * resource-intensive to repeat twice on every request.
- */
- if (req->oldptr == 0) {
- n = tcbinfo.ipi_count;
- req->oldidx = 2 * (sizeof xig)
- + (n + n/8) * sizeof(struct xtcpcb);
- return 0;
- }
-
- if (req->newptr != 0)
- return EPERM;
-
- /*
- * OK, now we're committed to doing something.
- */
- s = splnet();
- INP_INFO_RLOCK(&tcbinfo);
- gencnt = tcbinfo.ipi_gencnt;
- n = tcbinfo.ipi_count;
- INP_INFO_RUNLOCK(&tcbinfo);
- splx(s);
-
- sysctl_wire_old_buffer(req, 2 * (sizeof xig)
- + n * sizeof(struct xtcpcb));
-
- xig.xig_len = sizeof xig;
- xig.xig_count = n;
- xig.xig_gen = gencnt;
- xig.xig_sogen = so_gencnt;
- error = SYSCTL_OUT(req, &xig, sizeof xig);
- if (error)
- return error;
-
- inp_list = malloc(n * sizeof *inp_list, M_TEMP, M_WAITOK);
- if (inp_list == 0)
- return ENOMEM;
-
- s = splnet();
- INP_INFO_RLOCK(&tcbinfo);
- for (inp = LIST_FIRST(tcbinfo.listhead), i = 0; inp && i < n;
- inp = LIST_NEXT(inp, inp_list)) {
- INP_LOCK(inp);
- if (inp->inp_gencnt <= gencnt) {
- /*
- * XXX: This use of cr_cansee(), introduced with
- * TCP state changes, is not quite right, but for
- * now, better than nothing.
- */
- if (inp->inp_vflag & INP_TIMEWAIT)
- error = cr_cansee(req->td->td_ucred,
- intotw(inp)->tw_cred);
- else
- error = cr_canseesocket(req->td->td_ucred,
- inp->inp_socket);
- if (error == 0)
- inp_list[i++] = inp;
- }
- INP_UNLOCK(inp);
- }
- INP_INFO_RUNLOCK(&tcbinfo);
- splx(s);
- n = i;
-
- error = 0;
- for (i = 0; i < n; i++) {
- inp = inp_list[i];
- if (inp->inp_gencnt <= gencnt) {
- struct xtcpcb xt;
- caddr_t inp_ppcb;
- xt.xt_len = sizeof xt;
- /* XXX should avoid extra copy */
- bcopy(inp, &xt.xt_inp, sizeof *inp);
- inp_ppcb = inp->inp_ppcb;
- if (inp_ppcb == NULL)
- bzero((char *) &xt.xt_tp, sizeof xt.xt_tp);
- else if (inp->inp_vflag & INP_TIMEWAIT) {
- bzero((char *) &xt.xt_tp, sizeof xt.xt_tp);
- xt.xt_tp.t_state = TCPS_TIME_WAIT;
- } else
- bcopy(inp_ppcb, &xt.xt_tp, sizeof xt.xt_tp);
- if (inp->inp_socket)
- sotoxsocket(inp->inp_socket, &xt.xt_socket);
- else {
- bzero(&xt.xt_socket, sizeof xt.xt_socket);
- xt.xt_socket.xso_protocol = IPPROTO_TCP;
- }
- xt.xt_inp.inp_gencnt = inp->inp_gencnt;
- error = SYSCTL_OUT(req, &xt, sizeof xt);
- }
- }
- if (!error) {
- /*
- * Give the user an updated idea of our state.
- * If the generation differs from what we told
- * her before, she knows that something happened
- * while we were processing this request, and it
- * might be necessary to retry.
- */
- s = splnet();
- INP_INFO_RLOCK(&tcbinfo);
- xig.xig_gen = tcbinfo.ipi_gencnt;
- xig.xig_sogen = so_gencnt;
- xig.xig_count = tcbinfo.ipi_count;
- INP_INFO_RUNLOCK(&tcbinfo);
- splx(s);
- error = SYSCTL_OUT(req, &xig, sizeof xig);
- }
- free(inp_list, M_TEMP);
- return error;
-}
-
-SYSCTL_PROC(_net_inet_tcp, TCPCTL_PCBLIST, pcblist, CTLFLAG_RD, 0, 0,
- tcp_pcblist, "S,xtcpcb", "List of active TCP connections");
-
-static int
-tcp_getcred(SYSCTL_HANDLER_ARGS)
-{
- struct xucred xuc;
- struct sockaddr_in addrs[2];
- struct inpcb *inp;
- int error, s;
-
- error = suser_cred(req->td->td_ucred, PRISON_ROOT);
- if (error)
- return (error);
- error = SYSCTL_IN(req, addrs, sizeof(addrs));
- if (error)
- return (error);
- s = splnet();
- INP_INFO_RLOCK(&tcbinfo);
- inp = in_pcblookup_hash(&tcbinfo, addrs[1].sin_addr, addrs[1].sin_port,
- addrs[0].sin_addr, addrs[0].sin_port, 0, NULL);
- if (inp == NULL) {
- error = ENOENT;
- goto outunlocked;
- }
- INP_LOCK(inp);
- if (inp->inp_socket == NULL) {
- error = ENOENT;
- goto out;
- }
- error = cr_canseesocket(req->td->td_ucred, inp->inp_socket);
- if (error)
- goto out;
- cru2x(inp->inp_socket->so_cred, &xuc);
-out:
- INP_UNLOCK(inp);
-outunlocked:
- INP_INFO_RUNLOCK(&tcbinfo);
- splx(s);
- if (error == 0)
- error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
- return (error);
-}
-
-SYSCTL_PROC(_net_inet_tcp, OID_AUTO, getcred,
- CTLTYPE_OPAQUE|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0,
- tcp_getcred, "S,xucred", "Get the xucred of a TCP connection");
-
-#ifdef INET6
-static int
-tcp6_getcred(SYSCTL_HANDLER_ARGS)
-{
- struct xucred xuc;
- struct sockaddr_in6 addrs[2];
- struct inpcb *inp;
- int error, s, mapped = 0;
-
- error = suser_cred(req->td->td_ucred, PRISON_ROOT);
- if (error)
- return (error);
- error = SYSCTL_IN(req, addrs, sizeof(addrs));
- if (error)
- return (error);
- if (IN6_IS_ADDR_V4MAPPED(&addrs[0].sin6_addr)) {
- if (IN6_IS_ADDR_V4MAPPED(&addrs[1].sin6_addr))
- mapped = 1;
- else
- return (EINVAL);
- }
- s = splnet();
- INP_INFO_RLOCK(&tcbinfo);
- if (mapped == 1)
- inp = in_pcblookup_hash(&tcbinfo,
- *(struct in_addr *)&addrs[1].sin6_addr.s6_addr[12],
- addrs[1].sin6_port,
- *(struct in_addr *)&addrs[0].sin6_addr.s6_addr[12],
- addrs[0].sin6_port,
- 0, NULL);
- else
- inp = in6_pcblookup_hash(&tcbinfo, &addrs[1].sin6_addr,
- addrs[1].sin6_port,
- &addrs[0].sin6_addr, addrs[0].sin6_port,
- 0, NULL);
- if (inp == NULL) {
- error = ENOENT;
- goto outunlocked;
- }
- INP_LOCK(inp);
- if (inp->inp_socket == NULL) {
- error = ENOENT;
- goto out;
- }
- error = cr_canseesocket(req->td->td_ucred, inp->inp_socket);
- if (error)
- goto out;
- cru2x(inp->inp_socket->so_cred, &xuc);
-out:
- INP_UNLOCK(inp);
-outunlocked:
- INP_INFO_RUNLOCK(&tcbinfo);
- splx(s);
- if (error == 0)
- error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
- return (error);
-}
-
-SYSCTL_PROC(_net_inet6_tcp6, OID_AUTO, getcred,
- CTLTYPE_OPAQUE|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0,
- tcp6_getcred, "S,xucred", "Get the xucred of a TCP6 connection");
-#endif
-
-
-void
-tcp_ctlinput(cmd, sa, vip)
- int cmd;
- struct sockaddr *sa;
- void *vip;
-{
- struct ip *ip = vip;
- struct tcphdr *th;
- struct in_addr faddr;
- struct inpcb *inp;
- struct tcpcb *tp;
- struct inpcb *(*notify)(struct inpcb *, int) = tcp_notify;
- tcp_seq icmp_seq;
- int s;
-
- faddr = ((struct sockaddr_in *)sa)->sin_addr;
- if (sa->sa_family != AF_INET || faddr.s_addr == INADDR_ANY)
- return;
-
- if (cmd == PRC_QUENCH)
- notify = tcp_quench;
- else if (icmp_may_rst && (cmd == PRC_UNREACH_ADMIN_PROHIB ||
- cmd == PRC_UNREACH_PORT || cmd == PRC_TIMXCEED_INTRANS) && ip)
- notify = tcp_drop_syn_sent;
- else if (cmd == PRC_MSGSIZE)
- notify = tcp_mtudisc;
- else if (PRC_IS_REDIRECT(cmd)) {
- ip = 0;
- notify = in_rtchange;
- } else if (cmd == PRC_HOSTDEAD)
- ip = 0;
- else if ((unsigned)cmd > PRC_NCMDS || inetctlerrmap[cmd] == 0)
- return;
- if (ip) {
- s = splnet();
- th = (struct tcphdr *)((caddr_t)ip
- + (ip->ip_hl << 2));
- INP_INFO_WLOCK(&tcbinfo);
- inp = in_pcblookup_hash(&tcbinfo, faddr, th->th_dport,
- ip->ip_src, th->th_sport, 0, NULL);
- if (inp != NULL) {
- INP_LOCK(inp);
- if (inp->inp_socket != NULL) {
- icmp_seq = htonl(th->th_seq);
- tp = intotcpcb(inp);
- if (SEQ_GEQ(icmp_seq, tp->snd_una) &&
- SEQ_LT(icmp_seq, tp->snd_max))
- inp = (*notify)(inp, inetctlerrmap[cmd]);
- }
- if (inp)
- INP_UNLOCK(inp);
- } else {
- struct in_conninfo inc;
-
- inc.inc_fport = th->th_dport;
- inc.inc_lport = th->th_sport;
- inc.inc_faddr = faddr;
- inc.inc_laddr = ip->ip_src;
-#ifdef INET6
- inc.inc_isipv6 = 0;
-#endif
- syncache_unreach(&inc, th);
- }
- INP_INFO_WUNLOCK(&tcbinfo);
- splx(s);
- } else
- in_pcbnotifyall(&tcbinfo, faddr, inetctlerrmap[cmd], notify);
-}
-
-#ifdef INET6
-void
-tcp6_ctlinput(cmd, sa, d)
- int cmd;
- struct sockaddr *sa;
- void *d;
-{
- struct tcphdr th;
- struct inpcb *(*notify)(struct inpcb *, int) = tcp_notify;
- struct ip6_hdr *ip6;
- struct mbuf *m;
- struct ip6ctlparam *ip6cp = NULL;
- const struct sockaddr_in6 *sa6_src = NULL;
- int off;
- struct tcp_portonly {
- u_int16_t th_sport;
- u_int16_t th_dport;
- } *thp;
-
- if (sa->sa_family != AF_INET6 ||
- sa->sa_len != sizeof(struct sockaddr_in6))
- return;
-
- if (cmd == PRC_QUENCH)
- notify = tcp_quench;
- else if (cmd == PRC_MSGSIZE)
- notify = tcp_mtudisc;
- else if (!PRC_IS_REDIRECT(cmd) &&
- ((unsigned)cmd > PRC_NCMDS || inet6ctlerrmap[cmd] == 0))
- return;
-
- /* if the parameter is from icmp6, decode it. */
- if (d != NULL) {
- ip6cp = (struct ip6ctlparam *)d;
- m = ip6cp->ip6c_m;
- ip6 = ip6cp->ip6c_ip6;
- off = ip6cp->ip6c_off;
- sa6_src = ip6cp->ip6c_src;
- } else {
- m = NULL;
- ip6 = NULL;
- off = 0; /* fool gcc */
- sa6_src = &sa6_any;
- }
-
- if (ip6) {
- struct in_conninfo inc;
- /*
- * XXX: We assume that when IPV6 is non NULL,
- * M and OFF are valid.
- */
-
- /* check if we can safely examine src and dst ports */
- if (m->m_pkthdr.len < off + sizeof(*thp))
- return;
-
- bzero(&th, sizeof(th));
- m_copydata(m, off, sizeof(*thp), (caddr_t)&th);
-
- in6_pcbnotify(&tcb, sa, th.th_dport,
- (struct sockaddr *)ip6cp->ip6c_src,
- th.th_sport, cmd, notify);
-
- inc.inc_fport = th.th_dport;
- inc.inc_lport = th.th_sport;
- inc.inc6_faddr = ((struct sockaddr_in6 *)sa)->sin6_addr;
- inc.inc6_laddr = ip6cp->ip6c_src->sin6_addr;
- inc.inc_isipv6 = 1;
- syncache_unreach(&inc, &th);
- } else
- in6_pcbnotify(&tcb, sa, 0, (const struct sockaddr *)sa6_src,
- 0, cmd, notify);
-}
-#endif /* INET6 */
-
-
-/*
- * Following is where TCP initial sequence number generation occurs.
- *
- * There are two places where we must use initial sequence numbers:
- * 1. In SYN-ACK packets.
- * 2. In SYN packets.
- *
- * All ISNs for SYN-ACK packets are generated by the syncache. See
- * tcp_syncache.c for details.
- *
- * The ISNs in SYN packets must be monotonic; TIME_WAIT recycling
- * depends on this property. In addition, these ISNs should be
- * unguessable so as to prevent connection hijacking. To satisfy
- * the requirements of this situation, the algorithm outlined in
- * RFC 1948 is used to generate sequence numbers.
- *
- * Implementation details:
- *
- * Time is based off the system timer, and is corrected so that it
- * increases by one megabyte per second. This allows for proper
- * recycling on high speed LANs while still leaving over an hour
- * before rollover.
- *
- * net.inet.tcp.isn_reseed_interval controls the number of seconds
- * between seeding of isn_secret. This is normally set to zero,
- * as reseeding should not be necessary.
- *
- */
-
-#define ISN_BYTES_PER_SECOND 1048576
-
-u_char isn_secret[32];
-int isn_last_reseed;
-MD5_CTX isn_ctx;
-
-tcp_seq
-tcp_new_isn(tp)
- struct tcpcb *tp;
-{
- u_int32_t md5_buffer[4];
- tcp_seq new_isn;
-
- /* Seed if this is the first use, reseed if requested. */
- if ((isn_last_reseed == 0) || ((tcp_isn_reseed_interval > 0) &&
- (((u_int)isn_last_reseed + (u_int)tcp_isn_reseed_interval*hz)
- < (u_int)ticks))) {
- read_random(&isn_secret, sizeof(isn_secret));
- isn_last_reseed = ticks;
- }
-
- /* Compute the md5 hash and return the ISN. */
- MD5Init(&isn_ctx);
- MD5Update(&isn_ctx, (u_char *) &tp->t_inpcb->inp_fport, sizeof(u_short));
- MD5Update(&isn_ctx, (u_char *) &tp->t_inpcb->inp_lport, sizeof(u_short));
-#ifdef INET6
- if ((tp->t_inpcb->inp_vflag & INP_IPV6) != 0) {
- MD5Update(&isn_ctx, (u_char *) &tp->t_inpcb->in6p_faddr,
- sizeof(struct in6_addr));
- MD5Update(&isn_ctx, (u_char *) &tp->t_inpcb->in6p_laddr,
- sizeof(struct in6_addr));
- } else
-#endif
- {
- MD5Update(&isn_ctx, (u_char *) &tp->t_inpcb->inp_faddr,
- sizeof(struct in_addr));
- MD5Update(&isn_ctx, (u_char *) &tp->t_inpcb->inp_laddr,
- sizeof(struct in_addr));
- }
- MD5Update(&isn_ctx, (u_char *) &isn_secret, sizeof(isn_secret));
- MD5Final((u_char *) &md5_buffer, &isn_ctx);
- new_isn = (tcp_seq) md5_buffer[0];
- new_isn += ticks * (ISN_BYTES_PER_SECOND / hz);
- return new_isn;
-}
-
-/*
- * When a source quench is received, close congestion window
- * to one segment. We will gradually open it again as we proceed.
- */
-struct inpcb *
-tcp_quench(inp, errno)
- struct inpcb *inp;
- int errno;
-{
- struct tcpcb *tp = intotcpcb(inp);
-
- if (tp)
- tp->snd_cwnd = tp->t_maxseg;
- return (inp);
-}
-
-/*
- * When a specific ICMP unreachable message is received and the
- * connection state is SYN-SENT, drop the connection. This behavior
- * is controlled by the icmp_may_rst sysctl.
- */
-struct inpcb *
-tcp_drop_syn_sent(inp, errno)
- struct inpcb *inp;
- int errno;
-{
- struct tcpcb *tp = intotcpcb(inp);
-
- if (tp && tp->t_state == TCPS_SYN_SENT) {
- tcp_drop(tp, errno);
- return (struct inpcb *)0;
- }
- return inp;
-}
-
-/*
- * When `need fragmentation' ICMP is received, update our idea of the MSS
- * based on the new value in the route. Also nudge TCP to send something,
- * since we know the packet we just sent was dropped.
- * This duplicates some code in the tcp_mss() function in tcp_input.c.
- */
-struct inpcb *
-tcp_mtudisc(inp, errno)
- struct inpcb *inp;
- int errno;
-{
- struct tcpcb *tp = intotcpcb(inp);
- struct rtentry *rt;
- struct rmxp_tao *taop;
- struct socket *so = inp->inp_socket;
- int offered;
- int mss;
-#ifdef INET6
- int isipv6 = (tp->t_inpcb->inp_vflag & INP_IPV6) != 0;
-#endif /* INET6 */
-
- if (tp) {
-#ifdef INET6
- if (isipv6)
- rt = tcp_rtlookup6(&inp->inp_inc);
- else
-#endif /* INET6 */
- rt = tcp_rtlookup(&inp->inp_inc);
- if (!rt || !rt->rt_rmx.rmx_mtu) {
- tp->t_maxopd = tp->t_maxseg =
-#ifdef INET6
- isipv6 ? tcp_v6mssdflt :
-#endif /* INET6 */
- tcp_mssdflt;
- return inp;
- }
- taop = rmx_taop(rt->rt_rmx);
- offered = taop->tao_mssopt;
- mss = rt->rt_rmx.rmx_mtu -
-#ifdef INET6
- (isipv6 ?
- sizeof(struct ip6_hdr) + sizeof(struct tcphdr) :
-#endif /* INET6 */
- sizeof(struct tcpiphdr)
-#ifdef INET6
- )
-#endif /* INET6 */
- ;
-
- if (offered)
- mss = min(mss, offered);
- /*
- * XXX - The above conditional probably violates the TCP
- * spec. The problem is that, since we don't know the
- * other end's MSS, we are supposed to use a conservative
- * default. But, if we do that, then MTU discovery will
- * never actually take place, because the conservative
- * default is much less than the MTUs typically seen
- * on the Internet today. For the moment, we'll sweep
- * this under the carpet.
- *
- * The conservative default might not actually be a problem
- * if the only case this occurs is when sending an initial
- * SYN with options and data to a host we've never talked
- * to before. Then, they will reply with an MSS value which
- * will get recorded and the new parameters should get
- * recomputed. For Further Study.
- */
- if (tp->t_maxopd <= mss)
- return inp;
- tp->t_maxopd = mss;
-
- if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP &&
- (tp->t_flags & TF_RCVD_TSTMP) == TF_RCVD_TSTMP)
- mss -= TCPOLEN_TSTAMP_APPA;
- if ((tp->t_flags & (TF_REQ_CC|TF_NOOPT)) == TF_REQ_CC &&
- (tp->t_flags & TF_RCVD_CC) == TF_RCVD_CC)
- mss -= TCPOLEN_CC_APPA;
-#if (MCLBYTES & (MCLBYTES - 1)) == 0
- if (mss > MCLBYTES)
- mss &= ~(MCLBYTES-1);
-#else
- if (mss > MCLBYTES)
- mss = mss / MCLBYTES * MCLBYTES;
-#endif
- if (so->so_snd.sb_hiwat < mss)
- mss = so->so_snd.sb_hiwat;
-
- tp->t_maxseg = mss;
-
- tcpstat.tcps_mturesent++;
- tp->t_rtttime = 0;
- tp->snd_nxt = tp->snd_una;
- tcp_output(tp);
- }
- return inp;
-}
-
-/*
- * Look-up the routing entry to the peer of this inpcb. If no route
- * is found and it cannot be allocated, then return NULL. This routine
- * is called by TCP routines that access the rmx structure and by tcp_mss
- * to get the interface MTU.
- */
-struct rtentry *
-tcp_rtlookup(inc)
- struct in_conninfo *inc;
-{
- struct route *ro;
- struct rtentry *rt;
-
- ro = &inc->inc_route;
- rt = ro->ro_rt;
- if (rt == NULL || !(rt->rt_flags & RTF_UP)) {
- /* No route yet, so try to acquire one */
- if (inc->inc_faddr.s_addr != INADDR_ANY) {
- ro->ro_dst.sa_family = AF_INET;
- ro->ro_dst.sa_len = sizeof(struct sockaddr_in);
- ((struct sockaddr_in *) &ro->ro_dst)->sin_addr =
- inc->inc_faddr;
- rtalloc(ro);
- rt = ro->ro_rt;
- }
- }
- return rt;
-}
-
-#ifdef INET6
-struct rtentry *
-tcp_rtlookup6(inc)
- struct in_conninfo *inc;
-{
- struct route_in6 *ro6;
- struct rtentry *rt;
-
- ro6 = &inc->inc6_route;
- rt = ro6->ro_rt;
- if (rt == NULL || !(rt->rt_flags & RTF_UP)) {
- /* No route yet, so try to acquire one */
- if (!IN6_IS_ADDR_UNSPECIFIED(&inc->inc6_faddr)) {
- ro6->ro_dst.sin6_family = AF_INET6;
- ro6->ro_dst.sin6_len = sizeof(struct sockaddr_in6);
- ro6->ro_dst.sin6_addr = inc->inc6_faddr;
- rtalloc((struct route *)ro6);
- rt = ro6->ro_rt;
- }
- }
- return rt;
-}
-#endif /* INET6 */
-
-#ifdef IPSEC
-/* compute ESP/AH header size for TCP, including outer IP header. */
-size_t
-ipsec_hdrsiz_tcp(tp)
- struct tcpcb *tp;
-{
- struct inpcb *inp;
- struct mbuf *m;
- size_t hdrsiz;
- struct ip *ip;
-#ifdef INET6
- struct ip6_hdr *ip6;
-#endif
- struct tcphdr *th;
-
- if ((tp == NULL) || ((inp = tp->t_inpcb) == NULL))
- return 0;
- MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (!m)
- return 0;
-
-#ifdef INET6
- if ((inp->inp_vflag & INP_IPV6) != 0) {
- ip6 = mtod(m, struct ip6_hdr *);
- th = (struct tcphdr *)(ip6 + 1);
- m->m_pkthdr.len = m->m_len =
- sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
- tcpip_fillheaders(inp, ip6, th);
- hdrsiz = ipsec6_hdrsiz(m, IPSEC_DIR_OUTBOUND, inp);
- } else
-#endif /* INET6 */
- {
- ip = mtod(m, struct ip *);
- th = (struct tcphdr *)(ip + 1);
- m->m_pkthdr.len = m->m_len = sizeof(struct tcpiphdr);
- tcpip_fillheaders(inp, ip, th);
- hdrsiz = ipsec4_hdrsiz(m, IPSEC_DIR_OUTBOUND, inp);
- }
-
- m_free(m);
- return hdrsiz;
-}
-#endif /*IPSEC*/
-
-/*
- * Return a pointer to the cached information about the remote host.
- * The cached information is stored in the protocol specific part of
- * the route metrics.
- */
-struct rmxp_tao *
-tcp_gettaocache(inc)
- struct in_conninfo *inc;
-{
- struct rtentry *rt;
-
-#ifdef INET6
- if (inc->inc_isipv6)
- rt = tcp_rtlookup6(inc);
- else
-#endif /* INET6 */
- rt = tcp_rtlookup(inc);
-
- /* Make sure this is a host route and is up. */
- if (rt == NULL ||
- (rt->rt_flags & (RTF_UP|RTF_HOST)) != (RTF_UP|RTF_HOST))
- return NULL;
-
- return rmx_taop(rt->rt_rmx);
-}
-
-/*
- * Clear all the TAO cache entries, called from tcp_init.
- *
- * XXX
- * This routine is just an empty one, because we assume that the routing
- * routing tables are initialized at the same time when TCP, so there is
- * nothing in the cache left over.
- */
-static void
-tcp_cleartaocache()
-{
-}
-
-/*
- * Move a TCP connection into TIME_WAIT state.
- * tcbinfo is unlocked.
- * inp is locked, and is unlocked before returning.
- */
-void
-tcp_twstart(tp)
- struct tcpcb *tp;
-{
- struct tcptw *tw;
- struct inpcb *inp;
- int tw_time, acknow;
- struct socket *so;
-
- tw = uma_zalloc(tcptw_zone, M_NOWAIT);
- if (tw == NULL) {
- tw = tcp_timer_2msl_tw(1);
- if (tw == NULL) {
- tcp_close(tp);
- return;
- }
- }
- inp = tp->t_inpcb;
- tw->tw_inpcb = inp;
-
- /*
- * Recover last window size sent.
- */
- tw->last_win = (tp->rcv_adv - tp->rcv_nxt) >> tp->rcv_scale;
-
- /*
- * Set t_recent if timestamps are used on the connection.
- */
- if ((tp->t_flags & (TF_REQ_TSTMP|TF_RCVD_TSTMP|TF_NOOPT)) ==
- (TF_REQ_TSTMP|TF_RCVD_TSTMP))
- tw->t_recent = tp->ts_recent;
- else
- tw->t_recent = 0;
-
- tw->snd_nxt = tp->snd_nxt;
- tw->rcv_nxt = tp->rcv_nxt;
- tw->cc_recv = tp->cc_recv;
- tw->cc_send = tp->cc_send;
- tw->t_starttime = tp->t_starttime;
- tw->tw_time = 0;
-
-/* XXX
- * If this code will
- * be used for fin-wait-2 state also, then we may need
- * a ts_recent from the last segment.
- */
- /* Shorten TIME_WAIT [RFC-1644, p.28] */
- if (tp->cc_recv != 0 && (ticks - tp->t_starttime) < tcp_msl) {
- tw_time = tp->t_rxtcur * TCPTV_TWTRUNC;
- /* For T/TCP client, force ACK now. */
- acknow = 1;
- } else {
- tw_time = 2 * tcp_msl;
- acknow = tp->t_flags & TF_ACKNOW;
- }
- tcp_discardcb(tp);
- so = inp->inp_socket;
- so->so_pcb = NULL;
- tw->tw_cred = crhold(so->so_cred);
- tw->tw_so_options = so->so_options;
- if (acknow)
- tcp_twrespond(tw, so, NULL, TH_ACK);
- sotryfree(so);
- inp->inp_socket = NULL;
- inp->inp_ppcb = (caddr_t)tw;
- inp->inp_vflag |= INP_TIMEWAIT;
- tcp_timer_2msl_reset(tw, tw_time);
- INP_UNLOCK(inp);
-}
-
-struct tcptw *
-tcp_twclose(struct tcptw *tw, int reuse)
-{
- struct inpcb *inp;
-
- inp = tw->tw_inpcb;
- tw->tw_inpcb = NULL;
- tcp_timer_2msl_stop(tw);
- inp->inp_ppcb = NULL;
-#ifdef INET6
- if (inp->inp_vflag & INP_IPV6PROTO)
- in6_pcbdetach(inp);
- else
-#endif
- in_pcbdetach(inp);
- tcpstat.tcps_closed++;
- if (reuse)
- return (tw);
- uma_zfree(tcptw_zone, tw);
- return (NULL);
-}
-
-/*
- * One of so and msrc must be non-NULL for use by the MAC Framework to
- * construct a label for ay resulting packet.
- */
-int
-tcp_twrespond(struct tcptw *tw, struct socket *so, struct mbuf *msrc,
- int flags)
-{
- struct inpcb *inp = tw->tw_inpcb;
- struct tcphdr *th;
- struct mbuf *m;
- struct ip *ip = NULL;
- u_int8_t *optp;
- u_int hdrlen, optlen;
- int error;
-#ifdef INET6
- struct ip6_hdr *ip6 = NULL;
- int isipv6 = inp->inp_inc.inc_isipv6;
-#endif
-
- KASSERT(so != NULL || msrc != NULL,
- ("tcp_twrespond: so and msrc NULL"));
-
- m = m_gethdr(M_DONTWAIT, MT_HEADER);
- if (m == NULL)
- return (ENOBUFS);
- m->m_data += max_linkhdr;
-
-#ifdef MAC
- if (so != NULL)
- mac_create_mbuf_from_socket(so, m);
- else
- mac_create_mbuf_netlayer(msrc, m);
-#endif
-
-#ifdef INET6
- if (isipv6) {
- hdrlen = sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
- ip6 = mtod(m, struct ip6_hdr *);
- th = (struct tcphdr *)(ip6 + 1);
- tcpip_fillheaders(inp, ip6, th);
- } else
-#endif
- {
- hdrlen = sizeof(struct tcpiphdr);
- ip = mtod(m, struct ip *);
- th = (struct tcphdr *)(ip + 1);
- tcpip_fillheaders(inp, ip, th);
- }
- optp = (u_int8_t *)(th + 1);
-
- /*
- * Send a timestamp and echo-reply if both our side and our peer
- * have sent timestamps in our SYN's and this is not a RST.
- */
- if (tw->t_recent && flags == TH_ACK) {
- u_int32_t *lp = (u_int32_t *)optp;
-
- /* Form timestamp option as shown in appendix A of RFC 1323. */
- *lp++ = htonl(TCPOPT_TSTAMP_HDR);
- *lp++ = htonl(ticks);
- *lp = htonl(tw->t_recent);
- optp += TCPOLEN_TSTAMP_APPA;
- }
-
- /*
- * Send `CC-family' options if needed, and it's not a RST.
- */
- if (tw->cc_recv != 0 && flags == TH_ACK) {
- u_int32_t *lp = (u_int32_t *)optp;
-
- *lp++ = htonl(TCPOPT_CC_HDR(TCPOPT_CC));
- *lp = htonl(tw->cc_send);
- optp += TCPOLEN_CC_APPA;
- }
- optlen = optp - (u_int8_t *)(th + 1);
-
- m->m_len = hdrlen + optlen;
- m->m_pkthdr.len = m->m_len;
-
- KASSERT(max_linkhdr + m->m_len <= MHLEN, ("tcptw: mbuf too small"));
-
- th->th_seq = htonl(tw->snd_nxt);
- th->th_ack = htonl(tw->rcv_nxt);
- th->th_off = (sizeof(struct tcphdr) + optlen) >> 2;
- th->th_flags = flags;
- th->th_win = htons(tw->last_win);
-
-#ifdef INET6
- if (isipv6) {
- th->th_sum = in6_cksum(m, IPPROTO_TCP, sizeof(struct ip6_hdr),
- sizeof(struct tcphdr) + optlen);
- ip6->ip6_hlim = in6_selecthlim(inp, inp->in6p_route.ro_rt ?
- inp->in6p_route.ro_rt->rt_ifp : NULL);
- error = ip6_output(m, inp->in6p_outputopts, &inp->in6p_route,
- (tw->tw_so_options & SO_DONTROUTE), NULL, NULL, inp);
- } else
-#endif
- {
- th->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr,
- htons(sizeof(struct tcphdr) + optlen + IPPROTO_TCP));
- m->m_pkthdr.csum_flags = CSUM_TCP;
- m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum);
- ip->ip_len = m->m_pkthdr.len;
- error = ip_output(m, inp->inp_options, &inp->inp_route,
- (tw->tw_so_options & SO_DONTROUTE), NULL, inp);
- }
- if (flags & TH_ACK)
- tcpstat.tcps_sndacks++;
- else
- tcpstat.tcps_sndctrl++;
- tcpstat.tcps_sndtotal++;
- return (error);
-}
-
-/*
- * TCP BANDWIDTH DELAY PRODUCT WINDOW LIMITING
- *
- * This code attempts to calculate the bandwidth-delay product as a
- * means of determining the optimal window size to maximize bandwidth,
- * minimize RTT, and avoid the over-allocation of buffers on interfaces and
- * routers. This code also does a fairly good job keeping RTTs in check
- * across slow links like modems. We implement an algorithm which is very
- * similar (but not meant to be) TCP/Vegas. The code operates on the
- * transmitter side of a TCP connection and so only effects the transmit
- * side of the connection.
- *
- * BACKGROUND: TCP makes no provision for the management of buffer space
- * at the end points or at the intermediate routers and switches. A TCP
- * stream, whether using NewReno or not, will eventually buffer as
- * many packets as it is able and the only reason this typically works is
- * due to the fairly small default buffers made available for a connection
- * (typicaly 16K or 32K). As machines use larger windows and/or window
- * scaling it is now fairly easy for even a single TCP connection to blow-out
- * all available buffer space not only on the local interface, but on
- * intermediate routers and switches as well. NewReno makes a misguided
- * attempt to 'solve' this problem by waiting for an actual failure to occur,
- * then backing off, then steadily increasing the window again until another
- * failure occurs, ad-infinitum. This results in terrible oscillation that
- * is only made worse as network loads increase and the idea of intentionally
- * blowing out network buffers is, frankly, a terrible way to manage network
- * resources.
- *
- * It is far better to limit the transmit window prior to the failure
- * condition being achieved. There are two general ways to do this: First
- * you can 'scan' through different transmit window sizes and locate the
- * point where the RTT stops increasing, indicating that you have filled the
- * pipe, then scan backwards until you note that RTT stops decreasing, then
- * repeat ad-infinitum. This method works in principle but has severe
- * implementation issues due to RTT variances, timer granularity, and
- * instability in the algorithm which can lead to many false positives and
- * create oscillations as well as interact badly with other TCP streams
- * implementing the same algorithm.
- *
- * The second method is to limit the window to the bandwidth delay product
- * of the link. This is the method we implement. RTT variances and our
- * own manipulation of the congestion window, bwnd, can potentially
- * destabilize the algorithm. For this reason we have to stabilize the
- * elements used to calculate the window. We do this by using the minimum
- * observed RTT, the long term average of the observed bandwidth, and
- * by adding two segments worth of slop. It isn't perfect but it is able
- * to react to changing conditions and gives us a very stable basis on
- * which to extend the algorithm.
- */
-void
-tcp_xmit_bandwidth_limit(struct tcpcb *tp, tcp_seq ack_seq)
-{
- u_long bw;
- u_long bwnd;
- int save_ticks;
-
- /*
- * If inflight_enable is disabled in the middle of a tcp connection,
- * make sure snd_bwnd is effectively disabled.
- */
- if (tcp_inflight_enable == 0) {
- tp->snd_bwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT;
- tp->snd_bandwidth = 0;
- return;
- }
-
- /*
- * Figure out the bandwidth. Due to the tick granularity this
- * is a very rough number and it MUST be averaged over a fairly
- * long period of time. XXX we need to take into account a link
- * that is not using all available bandwidth, but for now our
- * slop will ramp us up if this case occurs and the bandwidth later
- * increases.
- *
- * Note: if ticks rollover 'bw' may wind up negative. We must
- * effectively reset t_bw_rtttime for this case.
- */
- save_ticks = ticks;
- if ((u_int)(save_ticks - tp->t_bw_rtttime) < 1)
- return;
-
- bw = (int64_t)(ack_seq - tp->t_bw_rtseq) * hz /
- (save_ticks - tp->t_bw_rtttime);
- tp->t_bw_rtttime = save_ticks;
- tp->t_bw_rtseq = ack_seq;
- if (tp->t_bw_rtttime == 0 || (int)bw < 0)
- return;
- bw = ((int64_t)tp->snd_bandwidth * 15 + bw) >> 4;
-
- tp->snd_bandwidth = bw;
-
- /*
- * Calculate the semi-static bandwidth delay product, plus two maximal
- * segments. The additional slop puts us squarely in the sweet
- * spot and also handles the bandwidth run-up case and stabilization.
- * Without the slop we could be locking ourselves into a lower
- * bandwidth.
- *
- * Situations Handled:
- * (1) Prevents over-queueing of packets on LANs, especially on
- * high speed LANs, allowing larger TCP buffers to be
- * specified, and also does a good job preventing
- * over-queueing of packets over choke points like modems
- * (at least for the transmit side).
- *
- * (2) Is able to handle changing network loads (bandwidth
- * drops so bwnd drops, bandwidth increases so bwnd
- * increases).
- *
- * (3) Theoretically should stabilize in the face of multiple
- * connections implementing the same algorithm (this may need
- * a little work).
- *
- * (4) Stability value (defaults to 20 = 2 maximal packets) can
- * be adjusted with a sysctl but typically only needs to be
- * on very slow connections. A value no smaller then 5
- * should be used, but only reduce this default if you have
- * no other choice.
- */
-#define USERTT ((tp->t_srtt + tp->t_rttbest) / 2)
- bwnd = (int64_t)bw * USERTT / (hz << TCP_RTT_SHIFT) + tcp_inflight_stab * tp->t_maxseg / 10;
-#undef USERTT
-
- if (tcp_inflight_debug > 0) {
- static int ltime;
- if ((u_int)(ticks - ltime) >= hz / tcp_inflight_debug) {
- ltime = ticks;
- printf("%p bw %ld rttbest %d srtt %d bwnd %ld\n",
- tp,
- bw,
- tp->t_rttbest,
- tp->t_srtt,
- bwnd
- );
- }
- }
- if ((long)bwnd < tcp_inflight_min)
- bwnd = tcp_inflight_min;
- if (bwnd > tcp_inflight_max)
- bwnd = tcp_inflight_max;
- if ((long)bwnd < tp->t_maxseg * 2)
- bwnd = tp->t_maxseg * 2;
- tp->snd_bwnd = bwnd;
-}
-
diff --git a/sys/pc98/cbus/30line.h b/sys/pc98/cbus/30line.h
deleted file mode 100644
index c62ec41733cd..000000000000
--- a/sys/pc98/cbus/30line.h
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (c) 1994, 1995, 1996. FreeBSD(98) porting team.
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef __PC98_PC98_30LINE_H__
-#define __PC98_PC98_30LINE_H__
-
-#include <pc98/pc98/module.h>
-
-#ifndef LINE30_ROW
-#define LINE30_ROW 30
-#endif
-
-#define _CR 80
-#ifndef _VS
-#define _VS 2
-#endif
-#ifndef _HS
-#define _HS 1 + 1
-#endif
-#ifndef _HFP
-#define _HFP 3 + 1
-#endif
-#ifndef _HBP
-#define _HBP 14 + 1
-#endif
-#ifndef _VFP
-#define _VFP 11
-#endif
-#ifndef _VBP
-#define _VBP 44
-#endif
-
-#define _LF LINE30_ROW*16
-
-#define _GDC_RESET 0x00
-#define _GDC_SYNC 0x0e
-#define _GDC_MASTER 0x6f
-#define _GDC_SLAVE 0x6e
-#define _GDC_START 0x0d
-#define _GDC_STOP 0x0c
-#define _GDC_SCROLL 0x70
-#define _GDC_PITCH 0x47
-
-#define GDC_CR 0
-#define GDC_VS 1
-#define GDC_HS 2
-#define GDC_HFP 3
-#define GDC_HBP 4
-#define GDC_VFP 5
-#define GDC_VBP 6
-#define GDC_LF 7
-
-
-#define _24KHZ 0
-#define _31KHZ 1
-
-#define _2_5MHZ 0
-#define _5MHZ 1
-
-#define _25L 0
-#define _30L 1
-
-#define T25_G400 0
-#define T30_G400 1
-#define T30_G480 2
-
-static void master_gdc_cmd(unsigned int);
-static void master_gdc_prm(unsigned int);
-static void master_gdc_word_prm(unsigned int);
-#ifdef LINE30
-static void master_gdc_fifo_empty(void);
-#endif
-static void master_gdc_wait_vsync(void);
-
-static void gdc_cmd(unsigned int);
-#ifdef LINE30
-static void gdc_prm(unsigned int);
-static void gdc_word_prm(unsigned int);
-static void gdc_fifo_empty(void);
-#endif
-static void gdc_wait_vsync(void);
-
-#ifdef LINE30
-static int check_gdc_clock(void);
-
-static int gdc_INFO = _25L;
-#endif
-static int gdc_FH = _24KHZ;
-static void initialize_gdc(unsigned int, int);
-
-#ifdef LINE30
-static unsigned int master_param[2][2][8] = {
-{{78, 8, 7, 9, 7, 7, 25, 400}, /* 400/24k */
- {_CR-2, _VS, _HS-1, _HFP-1, _HBP-1, _VFP, _VBP, _LF}}, /* 480/24k */
-{{78, 2, 7, 3, 7, 13, 34, 400}, /* 400/31k */
- {78, 2, 11, 3, 3, 6, 37, 480}}}; /* 480/31k */
-
-static unsigned int slave_param[2][6][8] = {
-{{38, 8, 3, 4, 3, 7, 25, 400}, /* normal */
- {78, 8, 7, 9, 7, 7, 25, 400},
- {_CR/2-2, _VS, (_HS)/2-1, (_HFP)/2-1, (_HBP)/2-1,
- _VFP+(_LF-400)/2+8, _VBP+(_LF-400)/2-8, 400}, /* 30 & 400 */
- {_CR-2, _VS, _HS-1, _HFP-1, _HBP-1,
- _VFP+(_LF-400)/2+8, _VBP+(_LF-400)/2-8, 400},
- {_CR/2-2, _VS, (_HS)/2-1, (_HFP)/2-1, (_HBP)/2-1,
- _VFP, _VBP, _LF}, /* 30 & 480 */
- {_CR-2, _VS, _HS-1, _HFP-1, _HBP-1, _VFP, _VBP, _LF}},
-{{38, 2, 3, 1, 3, 13, 34, 400}, /* normal */
- {78, 2, 7, 3, 7, 13, 34, 400},
- {38, 2, 5, 1, 1, 6+48, 37+32, 400}, /* 30 & 400 */
- {78, 2, 11, 3, 3, 6+48, 37+32, 400},
- {38, 2, 5, 1, 1, 6, 37, 480}, /* 30 & 480 */
- {78, 2, 11, 3, 3, 6, 37, 480}}};
-
-static int SlavePCH[2] = {40,80};
-static int MasterPCH = 80;
-static int SlaveScrlLF[3] = {400,400,_LF};
-#endif
-
-#endif /* __PC98_PC98_30LINE_H__ */
diff --git a/sys/pc98/cbus/cbus.h b/sys/pc98/cbus/cbus.h
deleted file mode 100644
index 15226d3f3b83..000000000000
--- a/sys/pc98/cbus/cbus.h
+++ /dev/null
@@ -1,184 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)isa.h 5.7 (Berkeley) 5/9/91
- * $FreeBSD$
- */
-
-#ifndef _PC98_PC98_PC98_H_
-#define _PC98_PC98_PC98_H_
-
-/* BEWARE: Included in both assembler and C code */
-
-/*
- * PC98 Bus conventions
- * modified for PC9801 by A.Kojima F.Ukai M.Ishii
- * Kyoto University Microcomputer Club (KMC)
- */
-
-/*
- * Input / Output Port Assignments
- */
-#ifndef IO_ISABEGIN
-#define IO_ISABEGIN 0x000 /* 0x000 - Beginning of I/O Registers */
-
-/* PC98 IO address ... very dirty (^_^; */
-
-#define IO_ICU1 0x000 /* 8259A Interrupt Controller #1 */
-#define IO_DMA 0x001 /* 8237A DMA Controller */
-#define IO_ICU2 0x008 /* 8259A Interrupt Controller #2 */
-#define IO_RTC 0x020 /* 4990A RTC */
-#define IO_DMAPG 0x021 /* DMA Page Registers */
-#define IO_COM1 0x030 /* 8251A RS232C serial I/O (int) */
-#define IO_SYSPORT 0x031 /* 8255A System Port */
-#define IO_PPI 0x035 /* Programmable Peripheral Interface */
-#define IO_LPT 0x040 /* 8255A Printer Port */
-#define IO_KBD 0x041 /* 8251A Keyboard */
-#define IO_NMI 0x050 /* NMI Control */
-#define IO_WAIT 0x05F /* WAIT 0.6 us */
-#define IO_GDC1 0x060 /* 7220 GDC Text Control */
-#define IO_TIMER1 0x071 /* 8253C Timer */
-#define IO_SASI 0x080 /* SASI Hard Disk Controller */
-#define IO_FD1 0x090 /* 765A 1MB FDC */
-#define IO_GDC2 0x0A0 /* 7220 GDC Graphic Control */
-#define IO_CGROM 0x0A1 /* Character ROM */
-#define IO_COM2 0x0B1 /* 8251A RS232C serial I/O (ext) */
-#define IO_COM3 0x0B9 /* 8251A RS232C serial I/O (ext) */
-#define IO_FDPORT 0x0BE /* FD I/F port (1M<->640K,EMTON) */
-#define IO_FD2 0x0C8 /* 765A 640KB FDC */
-#define IO_SIO1 0x0D0 /* MC16550II ext RS232C */
-#define IO_REEST 0x0F0 /* CPU FPU reset */
-#define IO_A2OEN 0x0F2 /* A20 enable */
-#define IO_A20CT 0x0F6 /* A20 control enable/disable */
-#define IO_NPX 0x0F8 /* Numeric Coprocessor */
-#define IO_SOUND 0x188 /* YM2203 FM sound board */
-#define IO_EGC 0x4A0 /* 7220 GDC Graphic Control */
-#define IO_SCSI 0xCC0 /* SCSI Controller */
-#define IO_SIO2 0x8D0 /* MC16550II ext RS232C */
-#define IO_BEEPF 0x3FDB /* beep frequency */
-#define IO_MOUSE 0x7FD9 /* mouse */
-#define IO_BMS 0x7FD9 /* Bus Mouse */
-#define IO_MSE 0x7FD9 /* Bus Mouse */
-#define IO_MOUSETM 0xDFBD /* mouse timer */
-
-#define IO_WD1_NEC 0x640 /* 98note IDE Hard disk controller */
-#define IO_WD1_EPSON 0x80 /* 386note Hard disk controller */
-#define IO_WD1 IO_WD1_NEC /* IDE Hard disk controller */
-
-#define IO_ISAEND 0xFFFF /* - 0x3FF End of I/O Registers */
-#endif /* !IO_ISABEGIN */
-
-/*
- * Input / Output Port Sizes - these are from several sources, and tend
- * to be the larger of what was found, ie COM ports can be 4, but some
- * boards do not fully decode the address, thus 8 ports are used.
- */
-#ifndef IO_ISASIZES
-#define IO_ISASIZES
-
-#define IO_ASCSIZE 5 /* AmiScan GI1904-based hand scanner */
-#define IO_CGASIZE 16 /* CGA controllers */
-#define IO_DMASIZE 16 /* 8237 DMA controllers */
-#define IO_DPGSIZE 32 /* 74LS612 DMA page registers */
-#define IO_EISASIZE 4096 /* EISA controllers */
-#define IO_FDCSIZE 8 /* Nec765 floppy controllers */
-#define IO_GAMSIZE 16 /* AT compatible game controllers */
-#define IO_GSCSIZE 8 /* GeniScan GS-4500G hand scanner */
-#define IO_ICUSIZE 16 /* 8259A interrupt controllers */
-#define IO_KBDSIZE 16 /* 8042 Keyboard controllers */
-#define IO_LPTSIZE 8 /* LPT controllers, some use only 4 */
-#define IO_LPTSIZE_EXTENDED 8 /* "Extended" LPT controllers */
-#define IO_LPTSIZE_NORMAL 4 /* "Normal" LPT controllers */
-#define IO_MDASIZE 16 /* Monochrome display controllers */
-#define IO_NPXSIZE 8 /* 80387/80487 NPX registers */
-#define IO_PMPSIZE 2 /* 82347 power management peripheral */
-#define IO_PSMSIZE 5 /* 8042 Keyboard controllers */
-#define IO_RTCSIZE 16 /* CMOS real time clock, NMI control */
-#define IO_TMRSIZE 16 /* 8253 programmable timers */
-#define IO_VGASIZE 16 /* VGA controllers */
-#define IO_WDCSIZE 8 /* WD compatible disk controllers */
-
-#endif /* !IO_ISASIZES */
-
-/*
- * Input / Output Memory Physical Addresses
- */
-#ifndef IOM_BEGIN
-#define IOM_BEGIN 0x0A0000 /* Start of I/O Memory "hole" */
-#define IOM_END 0x100000 /* End of I/O Memory "hole" */
-#define IOM_SIZE (IOM_END - IOM_BEGIN)
-#endif /* !IOM_BEGIN */
-
-/*
- * RAM Physical Address Space (ignoring the above mentioned "hole")
- */
-#ifndef RAM_BEGIN
-#define RAM_BEGIN 0x0000000 /* Start of RAM Memory */
-#ifdef EPSON_BOUNCEDMA
-#define RAM_END 0x0f00000 /* End of EPSON GR?? RAM Memory */
-#else
-#define RAM_END 0x1000000 /* End of RAM Memory */
-#endif
-#define RAM_SIZE (RAM_END - RAM_BEGIN)
-#endif /* !RAM_BEGIN */
-
-#ifndef PC98 /* IBM-PC */
-/*
- * Oddball Physical Memory Addresses
- */
-#ifndef COMPAQ_RAMRELOC
-#define COMPAQ_RAMRELOC 0x80C00000 /* Compaq RAM relocation/diag */
-#define COMPAQ_RAMSETUP 0x80C00002 /* Compaq RAM setup */
-#define WEITEK_FPU 0xC0000000 /* WTL 2167 */
-#define CYRIX_EMC 0xC0000000 /* Cyrix EMC */
-#endif /* !COMPAQ_RAMRELOC */
-#endif
-
-#define M_NEC_PC98 0x0001
-#define M_EPSON_PC98 0x0002
-#define M_NOT_H98 0x0010
-#define M_H98 0x0020
-#define M_NOTE 0x0040
-#define M_NORMAL 0x1000
-#define M_8M 0x8000
-
-/*
- * Obtained from NetBSD/pc98
- */
-#define MADDRUNK -1
-#define IRQUNK 0
-#define DRQUNK -1
-
-#endif /* !_PC98_PC98_PC98_H_ */
diff --git a/sys/pc98/cbus/cbus_dma.c b/sys/pc98/cbus/cbus_dma.c
deleted file mode 100644
index 163de46b8f2e..000000000000
--- a/sys/pc98/cbus/cbus_dma.c
+++ /dev/null
@@ -1,625 +0,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)isa.c 7.2 (Berkeley) 5/13/91
- * $FreeBSD$
- */
-
-/*
- * code to manage AT bus
- *
- * 92/08/18 Frank P. MacLachlan (fpm@crash.cts.com):
- * Fixed uninitialized variable problem and added code to deal
- * with DMA page boundaries in isa_dmarangecheck(). Fixed word
- * mode DMA count compution and reorganized DMA setup code in
- * isa_dmastart()
- */
-
-#ifdef PC98
-#include "opt_pc98.h"
-#endif
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <sys/lock.h>
-#include <sys/proc.h>
-#include <sys/mutex.h>
-#include <sys/module.h>
-#ifdef PC98
-#include <machine/md_var.h>
-#endif
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#ifdef PC98
-#include <pc98/pc98/pc98.h>
-#else
-#include <i386/isa/isa.h>
-#endif
-#include <dev/ic/i8237.h>
-#include <isa/isavar.h>
-
-/*
-** Register definitions for DMA controller 1 (channels 0..3):
-*/
-#ifdef PC98
-#define DMA1_CHN(c) (IO_DMA + (4*(c))) /* addr reg for channel c */
-#define DMA1_SMSK (IO_DMA + 0x14) /* single mask register */
-#define DMA1_MODE (IO_DMA + 0x16) /* mode register */
-#define DMA1_FFC (IO_DMA + 0x18) /* clear first/last FF */
-#else
-#define DMA1_CHN(c) (IO_DMA1 + 1*(2*(c))) /* addr reg for channel c */
-#define DMA1_SMSK (IO_DMA1 + 1*10) /* single mask register */
-#define DMA1_MODE (IO_DMA1 + 1*11) /* mode register */
-#define DMA1_FFC (IO_DMA1 + 1*12) /* clear first/last FF */
-#endif
-
-/*
-** Register definitions for DMA controller 2 (channels 4..7):
-*/
-#define DMA2_CHN(c) (IO_DMA2 + 2*(2*(c))) /* addr reg for channel c */
-#define DMA2_SMSK (IO_DMA2 + 2*10) /* single mask register */
-#define DMA2_MODE (IO_DMA2 + 2*11) /* mode register */
-#define DMA2_FFC (IO_DMA2 + 2*12) /* clear first/last FF */
-
-static int isa_dmarangecheck(caddr_t va, u_int length, int chan);
-
-#ifdef PC98
-static caddr_t dma_bouncebuf[4];
-static u_int dma_bouncebufsize[4];
-#else
-static caddr_t dma_bouncebuf[8];
-static u_int dma_bouncebufsize[8];
-#endif
-static u_int8_t dma_bounced = 0;
-static u_int8_t dma_busy = 0; /* Used in isa_dmastart() */
-static u_int8_t dma_inuse = 0; /* User for acquire/release */
-static u_int8_t dma_auto_mode = 0;
-
-#ifdef PC98
-#define VALID_DMA_MASK (3)
-#else
-#define VALID_DMA_MASK (7)
-#endif
-
-/* high byte of address is stored in this port for i-th dma channel */
-#ifdef PC98
-static int dmapageport[4] = { 0x27, 0x21, 0x23, 0x25 };
-#else
-static int dmapageport[8] = { 0x87, 0x83, 0x81, 0x82, 0x8f, 0x8b, 0x89, 0x8a };
-#endif
-
-/*
- * Setup a DMA channel's bounce buffer.
- */
-void
-isa_dmainit(chan, bouncebufsize)
- int chan;
- u_int bouncebufsize;
-{
- void *buf;
-
-#ifdef DIAGNOSTIC
- if (chan & ~VALID_DMA_MASK)
- panic("isa_dmainit: channel out of range");
-
- if (dma_bouncebuf[chan] != NULL)
- panic("isa_dmainit: impossible request");
-#endif
-
- dma_bouncebufsize[chan] = bouncebufsize;
-
- /* Try malloc() first. It works better if it works. */
- buf = malloc(bouncebufsize, M_DEVBUF, M_NOWAIT);
- if (buf != NULL) {
- if (isa_dmarangecheck(buf, bouncebufsize, chan) == 0) {
- dma_bouncebuf[chan] = buf;
- return;
- }
- free(buf, M_DEVBUF);
- }
- buf = contigmalloc(bouncebufsize, M_DEVBUF, M_NOWAIT, 0ul, 0xfffffful,
- 1ul, chan & 4 ? 0x20000ul : 0x10000ul);
- if (buf == NULL)
- printf("isa_dmainit(%d, %d) failed\n", chan, bouncebufsize);
- else
- dma_bouncebuf[chan] = buf;
-}
-
-/*
- * Register a DMA channel's usage. Usually called from a device driver
- * in open() or during its initialization.
- */
-int
-isa_dma_acquire(chan)
- int chan;
-{
-#ifdef DIAGNOSTIC
- if (chan & ~VALID_DMA_MASK)
- panic("isa_dma_acquire: channel out of range");
-#endif
-
- if (dma_inuse & (1 << chan)) {
- printf("isa_dma_acquire: channel %d already in use\n", chan);
- return (EBUSY);
- }
- dma_inuse |= (1 << chan);
- dma_auto_mode &= ~(1 << chan);
-
- return (0);
-}
-
-/*
- * Unregister a DMA channel's usage. Usually called from a device driver
- * during close() or during its shutdown.
- */
-void
-isa_dma_release(chan)
- int chan;
-{
-#ifdef DIAGNOSTIC
- if (chan & ~VALID_DMA_MASK)
- panic("isa_dma_release: channel out of range");
-
- if ((dma_inuse & (1 << chan)) == 0)
- printf("isa_dma_release: channel %d not in use\n", chan);
-#endif
-
- if (dma_busy & (1 << chan)) {
- dma_busy &= ~(1 << chan);
- /*
- * XXX We should also do "dma_bounced &= (1 << chan);"
- * because we are acting on behalf of isa_dmadone() which
- * was not called to end the last DMA operation. This does
- * not matter now, but it may in the future.
- */
- }
-
- dma_inuse &= ~(1 << chan);
- dma_auto_mode &= ~(1 << chan);
-}
-
-#ifndef PC98
-/*
- * isa_dmacascade(): program 8237 DMA controller channel to accept
- * external dma control by a board.
- */
-void
-isa_dmacascade(chan)
- int chan;
-{
-#ifdef DIAGNOSTIC
- if (chan & ~VALID_DMA_MASK)
- panic("isa_dmacascade: channel out of range");
-#endif
-
- /* set dma channel mode, and set dma channel mode */
- if ((chan & 4) == 0) {
- outb(DMA1_MODE, DMA37MD_CASCADE | chan);
- outb(DMA1_SMSK, chan);
- } else {
- outb(DMA2_MODE, DMA37MD_CASCADE | (chan & 3));
- outb(DMA2_SMSK, chan & 3);
- }
-}
-#endif
-
-/*
- * isa_dmastart(): program 8237 DMA controller channel, avoid page alignment
- * problems by using a bounce buffer.
- */
-void
-isa_dmastart(int flags, caddr_t addr, u_int nbytes, int chan)
-{
- vm_offset_t phys;
- int waport;
- caddr_t newaddr;
-
- GIANT_REQUIRED;
-
-#ifdef DIAGNOSTIC
- if (chan & ~VALID_DMA_MASK)
- panic("isa_dmastart: channel out of range");
-
- if ((chan < 4 && nbytes > (1<<16))
- || (chan >= 4 && (nbytes > (1<<17) || (u_int)addr & 1)))
- panic("isa_dmastart: impossible request");
-
- if ((dma_inuse & (1 << chan)) == 0)
- printf("isa_dmastart: channel %d not acquired\n", chan);
-#endif
-
-#if 0
- /*
- * XXX This should be checked, but drivers like ad1848 only call
- * isa_dmastart() once because they use Auto DMA mode. If we
- * leave this in, drivers that do this will print this continuously.
- */
- if (dma_busy & (1 << chan))
- printf("isa_dmastart: channel %d busy\n", chan);
-#endif
-
- dma_busy |= (1 << chan);
-
- if (isa_dmarangecheck(addr, nbytes, chan)) {
- if (dma_bouncebuf[chan] == NULL
- || dma_bouncebufsize[chan] < nbytes)
- panic("isa_dmastart: bad bounce buffer");
- dma_bounced |= (1 << chan);
- newaddr = dma_bouncebuf[chan];
-
- /* copy bounce buffer on write */
- if (!(flags & ISADMA_READ))
- bcopy(addr, newaddr, nbytes);
- addr = newaddr;
- }
-
- /* translate to physical */
- phys = pmap_extract(kernel_pmap, (vm_offset_t)addr);
-
- if (flags & ISADMA_RAW) {
- dma_auto_mode |= (1 << chan);
- } else {
- dma_auto_mode &= ~(1 << chan);
- }
-
-#ifdef PC98
- if (need_pre_dma_flush)
- wbinvd(); /* wbinvd (WB cache flush) */
-#endif
-
-#ifndef PC98
- if ((chan & 4) == 0) {
- /*
- * Program one of DMA channels 0..3. These are
- * byte mode channels.
- */
-#endif
- /* set dma channel mode, and reset address ff */
-
- /* If ISADMA_RAW flag is set, then use autoinitialise mode */
- if (flags & ISADMA_RAW) {
- if (flags & ISADMA_READ)
- outb(DMA1_MODE, DMA37MD_AUTO|DMA37MD_WRITE|chan);
- else
- outb(DMA1_MODE, DMA37MD_AUTO|DMA37MD_READ|chan);
- }
- else
- if (flags & ISADMA_READ)
- outb(DMA1_MODE, DMA37MD_SINGLE|DMA37MD_WRITE|chan);
- else
- outb(DMA1_MODE, DMA37MD_SINGLE|DMA37MD_READ|chan);
- outb(DMA1_FFC, 0);
-
- /* send start address */
- waport = DMA1_CHN(chan);
- outb(waport, phys);
- outb(waport, phys>>8);
- outb(dmapageport[chan], phys>>16);
-
- /* send count */
-#ifdef PC98
- outb(waport + 2, --nbytes);
- outb(waport + 2, nbytes>>8);
-#else
- outb(waport + 1, --nbytes);
- outb(waport + 1, nbytes>>8);
-#endif
-
- /* unmask channel */
- outb(DMA1_SMSK, chan);
-#ifndef PC98
- } else {
- /*
- * Program one of DMA channels 4..7. These are
- * word mode channels.
- */
- /* set dma channel mode, and reset address ff */
-
- /* If ISADMA_RAW flag is set, then use autoinitialise mode */
- if (flags & ISADMA_RAW) {
- if (flags & ISADMA_READ)
- outb(DMA2_MODE, DMA37MD_AUTO|DMA37MD_WRITE|(chan&3));
- else
- outb(DMA2_MODE, DMA37MD_AUTO|DMA37MD_READ|(chan&3));
- }
- else
- if (flags & ISADMA_READ)
- outb(DMA2_MODE, DMA37MD_SINGLE|DMA37MD_WRITE|(chan&3));
- else
- outb(DMA2_MODE, DMA37MD_SINGLE|DMA37MD_READ|(chan&3));
- outb(DMA2_FFC, 0);
-
- /* send start address */
- waport = DMA2_CHN(chan - 4);
- outb(waport, phys>>1);
- outb(waport, phys>>9);
- outb(dmapageport[chan], phys>>16);
-
- /* send count */
- nbytes >>= 1;
- outb(waport + 2, --nbytes);
- outb(waport + 2, nbytes>>8);
-
- /* unmask channel */
- outb(DMA2_SMSK, chan & 3);
- }
-#endif
-}
-
-void
-isa_dmadone(int flags, caddr_t addr, int nbytes, int chan)
-{
-#ifdef PC98
- if (flags & ISADMA_READ) {
- /* cache flush only after reading 92/12/9 by A.Kojima */
- if (need_post_dma_flush)
- invd();
- }
-#endif
-
-#ifdef DIAGNOSTIC
- if (chan & ~VALID_DMA_MASK)
- panic("isa_dmadone: channel out of range");
-
- if ((dma_inuse & (1 << chan)) == 0)
- printf("isa_dmadone: channel %d not acquired\n", chan);
-#endif
-
- if (((dma_busy & (1 << chan)) == 0) &&
- (dma_auto_mode & (1 << chan)) == 0 )
- printf("isa_dmadone: channel %d not busy\n", chan);
-
-#ifdef PC98
- if ((dma_auto_mode & (1 << chan)) == 0)
- outb(DMA1_SMSK, (chan & 3) | 4);
-#else
- if ((dma_auto_mode & (1 << chan)) == 0)
- outb(chan & 4 ? DMA2_SMSK : DMA1_SMSK, (chan & 3) | 4);
-#endif
-
- if (dma_bounced & (1 << chan)) {
- /* copy bounce buffer on read */
- if (flags & ISADMA_READ)
- bcopy(dma_bouncebuf[chan], addr, nbytes);
-
- dma_bounced &= ~(1 << chan);
- }
- dma_busy &= ~(1 << chan);
-}
-
-/*
- * Check for problems with the address range of a DMA transfer
- * (non-contiguous physical pages, outside of bus address space,
- * crossing DMA page boundaries).
- * Return true if special handling needed.
- */
-
-static int
-isa_dmarangecheck(caddr_t va, u_int length, int chan)
-{
- vm_offset_t phys, priorpage = 0, endva;
- u_int dma_pgmsk = (chan & 4) ? ~(128*1024-1) : ~(64*1024-1);
-
- GIANT_REQUIRED;
-
- endva = (vm_offset_t)round_page((vm_offset_t)va + length);
- for (; va < (caddr_t) endva ; va += PAGE_SIZE) {
- phys = trunc_page(pmap_extract(kernel_pmap, (vm_offset_t)va));
-#ifdef EPSON_BOUNCEDMA
-#define ISARAM_END 0xf00000
-#else
-#define ISARAM_END RAM_END
-#endif
- if (phys == 0)
- panic("isa_dmacheck: no physical page present");
- if (phys >= ISARAM_END)
- return (1);
- if (priorpage) {
- if (priorpage + PAGE_SIZE != phys)
- return (1);
- /* check if crossing a DMA page boundary */
- if (((u_int)priorpage ^ (u_int)phys) & dma_pgmsk)
- return (1);
- }
- priorpage = phys;
- }
- return (0);
-}
-
-/*
- * Query the progress of a transfer on a DMA channel.
- *
- * To avoid having to interrupt a transfer in progress, we sample
- * each of the high and low databytes twice, and apply the following
- * logic to determine the correct count.
- *
- * Reads are performed with interrupts disabled, thus it is to be
- * expected that the time between reads is very small. At most
- * one rollover in the low count byte can be expected within the
- * four reads that are performed.
- *
- * There are three gaps in which a rollover can occur :
- *
- * - read low1
- * gap1
- * - read high1
- * gap2
- * - read low2
- * gap3
- * - read high2
- *
- * If a rollover occurs in gap1 or gap2, the low2 value will be
- * greater than the low1 value. In this case, low2 and high2 are a
- * corresponding pair.
- *
- * In any other case, low1 and high1 can be considered to be correct.
- *
- * The function returns the number of bytes remaining in the transfer,
- * or -1 if the channel requested is not active.
- *
- */
-int
-isa_dmastatus(int chan)
-{
- u_long cnt = 0;
- int ffport, waport;
- u_long low1, high1, low2, high2;
-
- /* channel active? */
- if ((dma_inuse & (1 << chan)) == 0) {
- printf("isa_dmastatus: channel %d not active\n", chan);
- return(-1);
- }
- /* channel busy? */
-
- if (((dma_busy & (1 << chan)) == 0) &&
- (dma_auto_mode & (1 << chan)) == 0 ) {
- printf("chan %d not busy\n", chan);
- return -2 ;
- }
-#ifdef PC98
- ffport = DMA1_FFC;
- waport = DMA1_CHN(chan) + 2;
-#else
- if (chan < 4) { /* low DMA controller */
- ffport = DMA1_FFC;
- waport = DMA1_CHN(chan) + 1;
- } else { /* high DMA controller */
- ffport = DMA2_FFC;
- waport = DMA2_CHN(chan - 4) + 2;
- }
-#endif
-
- disable_intr(); /* no interrupts Mr Jones! */
- outb(ffport, 0); /* clear register LSB flipflop */
- low1 = inb(waport);
- high1 = inb(waport);
- outb(ffport, 0); /* clear again */
- low2 = inb(waport);
- high2 = inb(waport);
- enable_intr(); /* enable interrupts again */
-
- /*
- * Now decide if a wrap has tried to skew our results.
- * Note that after TC, the count will read 0xffff, while we want
- * to return zero, so we add and then mask to compensate.
- */
- if (low1 >= low2) {
- cnt = (low1 + (high1 << 8) + 1) & 0xffff;
- } else {
- cnt = (low2 + (high2 << 8) + 1) & 0xffff;
- }
-
- if (chan >= 4) /* high channels move words */
- cnt *= 2;
- return(cnt);
-}
-
-/*
- * Stop a DMA transfer currently in progress.
- */
-int
-isa_dmastop(int chan)
-{
- if ((dma_inuse & (1 << chan)) == 0)
- printf("isa_dmastop: channel %d not acquired\n", chan);
-
- if (((dma_busy & (1 << chan)) == 0) &&
- ((dma_auto_mode & (1 << chan)) == 0)) {
- printf("chan %d not busy\n", chan);
- return -2 ;
- }
-
- if ((chan & 4) == 0) {
- outb(DMA1_SMSK, (chan & 3) | 4 /* disable mask */);
- } else {
-#ifndef PC98
- outb(DMA2_SMSK, (chan & 3) | 4 /* disable mask */);
-#endif
- }
- return(isa_dmastatus(chan));
-}
-
-/*
- * Attach to the ISA PnP descriptor for the AT DMA controller
- */
-static struct isa_pnp_id atdma_ids[] = {
- { 0x0002d041 /* PNP0200 */, "AT DMA controller" },
- { 0 }
-};
-
-static int
-atdma_probe(device_t dev)
-{
- int result;
-
- if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, atdma_ids)) <= 0)
- device_quiet(dev);
- return(result);
-}
-
-static int
-atdma_attach(device_t dev)
-{
- return(0);
-}
-
-static device_method_t atdma_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, atdma_probe),
- DEVMETHOD(device_attach, atdma_attach),
- DEVMETHOD(device_detach, bus_generic_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
- { 0, 0 }
-};
-
-static driver_t atdma_driver = {
- "atdma",
- atdma_methods,
- 1, /* no softc */
-};
-
-static devclass_t atdma_devclass;
-
-DRIVER_MODULE(atdma, isa, atdma_driver, atdma_devclass, 0, 0);
-#ifndef PC98
-DRIVER_MODULE(atdma, acpi, atdma_driver, atdma_devclass, 0, 0);
-#endif
diff --git a/sys/pc98/cbus/clock.c b/sys/pc98/cbus/clock.c
deleted file mode 100644
index bc03ea6a0b6b..000000000000
--- a/sys/pc98/cbus/clock.c
+++ /dev/null
@@ -1,1146 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz and Don Ahn.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)clock.c 7.2 (Berkeley) 5/12/91
- * $FreeBSD$
- */
-
-/*
- * Routines to handle clock hardware.
- */
-
-/*
- * inittodr, settodr and support routines written
- * by Christoph Robitschko <chmr@edvz.tu-graz.ac.at>
- *
- * reintroduced and updated by Chris Stenton <chris@gnome.co.uk> 8/10/94
- */
-
-/*
- * modified for PC98 by Kakefuda
- */
-
-#include "opt_clock.h"
-#include "opt_isa.h"
-#include "opt_mca.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/limits.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/time.h>
-#include <sys/timetc.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/cons.h>
-#include <sys/power.h>
-
-#include <machine/clock.h>
-#include <machine/cputypes.h>
-#include <machine/frame.h>
-#include <machine/md_var.h>
-#include <machine/psl.h>
-#ifdef APIC_IO
-#include <machine/segments.h>
-#endif
-#if defined(SMP) || defined(APIC_IO)
-#include <machine/smp.h>
-#endif /* SMP || APIC_IO */
-#include <machine/specialreg.h>
-
-#include <i386/isa/icu.h>
-#include <pc98/pc98/pc98.h>
-#include <pc98/pc98/pc98_machdep.h>
-#include <i386/isa/isa_device.h>
-#ifdef DEV_ISA
-#include <isa/isavar.h>
-#endif
-#include <i386/isa/timerreg.h>
-
-#include <i386/isa/intr_machdep.h>
-
-#ifdef APIC_IO
-#include <i386/isa/intr_machdep.h>
-/* The interrupt triggered by the 8254 (timer) chip */
-int apic_8254_intr;
-static u_long read_intr_count(int vec);
-static void setup_8254_mixed_mode(void);
-#endif
-
-/*
- * 32-bit time_t's can't reach leap years before 1904 or after 2036, so we
- * can use a simple formula for leap years.
- */
-#define LEAPYEAR(y) ((u_int)(y) % 4 == 0)
-#define DAYSPERYEAR (31+28+31+30+31+30+31+31+30+31+30+31)
-
-#define TIMER_DIV(x) ((timer_freq + (x) / 2) / (x))
-
-/*
- * Time in timer cycles that it takes for microtime() to disable interrupts
- * and latch the count. microtime() currently uses "cli; outb ..." so it
- * normally takes less than 2 timer cycles. Add a few for cache misses.
- * Add a few more to allow for latency in bogus calls to microtime() with
- * interrupts already disabled.
- */
-#define TIMER0_LATCH_COUNT 20
-
-/*
- * Maximum frequency that we are willing to allow for timer0. Must be
- * low enough to guarantee that the timer interrupt handler returns
- * before the next timer interrupt.
- */
-#define TIMER0_MAX_FREQ 20000
-
-int adjkerntz; /* local offset from GMT in seconds */
-int clkintr_pending;
-int disable_rtc_set; /* disable resettodr() if != 0 */
-int pscnt = 1;
-int psdiv = 1;
-int statclock_disable;
-#ifndef TIMER_FREQ
-#define TIMER_FREQ 2457600
-#endif
-u_int timer_freq = TIMER_FREQ;
-int timer0_max_count;
-int wall_cmos_clock; /* wall CMOS clock assumed if != 0 */
-struct mtx clock_lock;
-
-static int beeping = 0;
-static const u_char daysinmonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};
-static u_int hardclock_max_count;
-static u_int32_t i8254_lastcount;
-static u_int32_t i8254_offset;
-static int i8254_ticked;
-/*
- * XXX new_function and timer_func should not handle clockframes, but
- * timer_func currently needs to hold hardclock to handle the
- * timer0_state == 0 case. We should use inthand_add()/inthand_remove()
- * to switch between clkintr() and a slightly different timerintr().
- */
-static void (*new_function)(struct clockframe *frame);
-static u_int new_rate;
-static u_int timer0_prescaler_count;
-
-/* Values for timerX_state: */
-#define RELEASED 0
-#define RELEASE_PENDING 1
-#define ACQUIRED 2
-#define ACQUIRE_PENDING 3
-
-static u_char timer0_state;
-static u_char timer1_state;
-static u_char timer2_state;
-static void (*timer_func)(struct clockframe *frame) = hardclock;
-static void rtc_serialcombit(int);
-static void rtc_serialcom(int);
-static int rtc_inb(void);
-static void rtc_outb(int);
-
-static unsigned i8254_get_timecount(struct timecounter *tc);
-static void set_timer_freq(u_int freq, int intr_freq);
-
-static struct timecounter i8254_timecounter = {
- i8254_get_timecount, /* get_timecount */
- 0, /* no poll_pps */
- ~0u, /* counter_mask */
- 0, /* frequency */
- "i8254" /* name */
-};
-
-static void
-clkintr(struct clockframe frame)
-{
-
- if (timecounter->tc_get_timecount == i8254_get_timecount) {
- mtx_lock_spin(&clock_lock);
- if (i8254_ticked)
- i8254_ticked = 0;
- else {
- i8254_offset += timer0_max_count;
- i8254_lastcount = 0;
- }
- clkintr_pending = 0;
- mtx_unlock_spin(&clock_lock);
- }
- timer_func(&frame);
-#ifdef SMP
- if (timer_func == hardclock)
- forward_hardclock();
-#endif
- switch (timer0_state) {
-
- case RELEASED:
- break;
-
- case ACQUIRED:
- if ((timer0_prescaler_count += timer0_max_count)
- >= hardclock_max_count) {
- timer0_prescaler_count -= hardclock_max_count;
- hardclock(&frame);
-#ifdef SMP
- forward_hardclock();
-#endif
- }
- break;
-
- case ACQUIRE_PENDING:
- mtx_lock_spin(&clock_lock);
- i8254_offset = i8254_get_timecount(NULL);
- i8254_lastcount = 0;
- timer0_max_count = TIMER_DIV(new_rate);
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
- outb(TIMER_CNTR0, timer0_max_count & 0xff);
- outb(TIMER_CNTR0, timer0_max_count >> 8);
- mtx_unlock_spin(&clock_lock);
- timer_func = new_function;
- timer0_state = ACQUIRED;
- break;
-
- case RELEASE_PENDING:
- if ((timer0_prescaler_count += timer0_max_count)
- >= hardclock_max_count) {
- mtx_lock_spin(&clock_lock);
- i8254_offset = i8254_get_timecount(NULL);
- i8254_lastcount = 0;
- timer0_max_count = hardclock_max_count;
- outb(TIMER_MODE,
- TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
- outb(TIMER_CNTR0, timer0_max_count & 0xff);
- outb(TIMER_CNTR0, timer0_max_count >> 8);
- mtx_unlock_spin(&clock_lock);
- timer0_prescaler_count = 0;
- timer_func = hardclock;
- timer0_state = RELEASED;
- hardclock(&frame);
-#ifdef SMP
- forward_hardclock();
-#endif
- }
- break;
- }
-}
-
-/*
- * The acquire and release functions must be called at ipl >= splclock().
- */
-int
-acquire_timer0(int rate, void (*function)(struct clockframe *frame))
-{
- static int old_rate;
-
- if (rate <= 0 || rate > TIMER0_MAX_FREQ)
- return (-1);
- switch (timer0_state) {
-
- case RELEASED:
- timer0_state = ACQUIRE_PENDING;
- break;
-
- case RELEASE_PENDING:
- if (rate != old_rate)
- return (-1);
- /*
- * The timer has been released recently, but is being
- * re-acquired before the release completed. In this
- * case, we simply reclaim it as if it had not been
- * released at all.
- */
- timer0_state = ACQUIRED;
- break;
-
- default:
- return (-1); /* busy */
- }
- new_function = function;
- old_rate = new_rate = rate;
- return (0);
-}
-
-int
-acquire_timer1(int mode)
-{
-
- if (timer1_state != RELEASED)
- return (-1);
- timer1_state = ACQUIRED;
-
- /*
- * This access to the timer registers is as atomic as possible
- * because it is a single instruction. We could do better if we
- * knew the rate. Use of splclock() limits glitches to 10-100us,
- * and this is probably good enough for timer2, so we aren't as
- * careful with it as with timer0.
- */
- outb(TIMER_MODE, TIMER_SEL1 | (mode & 0x3f));
-
- return (0);
-}
-
-int
-acquire_timer2(int mode)
-{
-
- if (timer2_state != RELEASED)
- return (-1);
- timer2_state = ACQUIRED;
-
- /*
- * This access to the timer registers is as atomic as possible
- * because it is a single instruction. We could do better if we
- * knew the rate. Use of splclock() limits glitches to 10-100us,
- * and this is probably good enough for timer2, so we aren't as
- * careful with it as with timer0.
- */
- outb(TIMER_MODE, TIMER_SEL2 | (mode & 0x3f));
-
- return (0);
-}
-
-int
-release_timer0()
-{
- switch (timer0_state) {
-
- case ACQUIRED:
- timer0_state = RELEASE_PENDING;
- break;
-
- case ACQUIRE_PENDING:
- /* Nothing happened yet, release quickly. */
- timer0_state = RELEASED;
- break;
-
- default:
- return (-1);
- }
- return (0);
-}
-
-int
-release_timer1()
-{
-
- if (timer1_state != ACQUIRED)
- return (-1);
- timer1_state = RELEASED;
- outb(TIMER_MODE, TIMER_SEL1 | TIMER_SQWAVE | TIMER_16BIT);
- return (0);
-}
-
-int
-release_timer2()
-{
-
- if (timer2_state != ACQUIRED)
- return (-1);
- timer2_state = RELEASED;
- outb(TIMER_MODE, TIMER_SEL2 | TIMER_SQWAVE | TIMER_16BIT);
- return (0);
-}
-
-
-static int
-getit(void)
-{
- int high, low;
-
- mtx_lock_spin(&clock_lock);
-
- /* Select timer0 and latch counter value. */
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
-
- low = inb(TIMER_CNTR0);
- high = inb(TIMER_CNTR0);
-
- mtx_unlock_spin(&clock_lock);
- return ((high << 8) | low);
-}
-
-/*
- * Wait "n" microseconds.
- * Relies on timer 1 counting down from (timer_freq / hz)
- * Note: timer had better have been programmed before this is first used!
- */
-void
-DELAY(int n)
-{
- int delta, prev_tick, tick, ticks_left;
-
-#ifdef DELAYDEBUG
- int getit_calls = 1;
- int n1;
- static int state = 0;
-
- if (state == 0) {
- state = 1;
- for (n1 = 1; n1 <= 10000000; n1 *= 10)
- DELAY(n1);
- state = 2;
- }
- if (state == 1)
- printf("DELAY(%d)...", n);
-#endif
- /*
- * Guard against the timer being uninitialized if we are called
- * early for console i/o.
- */
- if (timer0_max_count == 0)
- set_timer_freq(timer_freq, hz);
-
- /*
- * Read the counter first, so that the rest of the setup overhead is
- * counted. Guess the initial overhead is 20 usec (on most systems it
- * takes about 1.5 usec for each of the i/o's in getit(). The loop
- * takes about 6 usec on a 486/33 and 13 usec on a 386/20. The
- * multiplications and divisions to scale the count take a while).
- */
- prev_tick = getit();
- n -= 0; /* XXX actually guess no initial overhead */
- /*
- * Calculate (n * (timer_freq / 1e6)) without using floating point
- * and without any avoidable overflows.
- */
- if (n <= 0)
- ticks_left = 0;
- else if (n < 256)
- /*
- * Use fixed point to avoid a slow division by 1000000.
- * 39099 = 1193182 * 2^15 / 10^6 rounded to nearest.
- * 2^15 is the first power of 2 that gives exact results
- * for n between 0 and 256.
- */
- ticks_left = ((u_int)n * 39099 + (1 << 15) - 1) >> 15;
- else
- /*
- * Don't bother using fixed point, although gcc-2.7.2
- * generates particularly poor code for the long long
- * division, since even the slow way will complete long
- * before the delay is up (unless we're interrupted).
- */
- ticks_left = ((u_int)n * (long long)timer_freq + 999999)
- / 1000000;
-
- while (ticks_left > 0) {
- tick = getit();
-#ifdef DELAYDEBUG
- ++getit_calls;
-#endif
- delta = prev_tick - tick;
- prev_tick = tick;
- if (delta < 0) {
- delta += timer0_max_count;
- /*
- * Guard against timer0_max_count being wrong.
- * This shouldn't happen in normal operation,
- * but it may happen if set_timer_freq() is
- * traced.
- */
- if (delta < 0)
- delta = 0;
- }
- ticks_left -= delta;
- }
-#ifdef DELAYDEBUG
- if (state == 1)
- printf(" %d calls to getit() at %d usec each\n",
- getit_calls, (n + 5) / getit_calls);
-#endif
-}
-
-static void
-sysbeepstop(void *chan)
-{
- outb(IO_PPI, inb(IO_PPI)|0x08); /* disable counter1 output to speaker */
- release_timer1();
- beeping = 0;
-}
-
-int
-sysbeep(int pitch, int period)
-{
- int x = splclock();
-
- if (acquire_timer1(TIMER_SQWAVE|TIMER_16BIT))
- if (!beeping) {
- /* Something else owns it. */
- splx(x);
- return (-1); /* XXX Should be EBUSY, but nobody cares anyway. */
- }
- disable_intr();
- outb(0x3fdb, pitch);
- outb(0x3fdb, (pitch>>8));
- enable_intr();
- if (!beeping) {
- /* enable counter1 output to speaker */
- outb(IO_PPI, (inb(IO_PPI) & 0xf7));
- beeping = period;
- timeout(sysbeepstop, (void *)NULL, period);
- }
- splx(x);
- return (0);
-}
-
-
-unsigned int delaycount;
-#define FIRST_GUESS 0x2000
-static void findcpuspeed(void)
-{
- int i;
- int remainder;
-
- /* Put counter in count down mode */
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_16BIT | TIMER_RATEGEN);
- outb(TIMER_CNTR0, 0xff);
- outb(TIMER_CNTR0, 0xff);
- for (i = FIRST_GUESS; i; i--)
- ;
- remainder = getit();
- delaycount = (FIRST_GUESS * TIMER_DIV(1000)) / (0xffff - remainder);
-}
-
-static u_int
-calibrate_clocks(void)
-{
- int timeout;
- u_int count, prev_count, tot_count;
- u_short sec, start_sec;
-
- if (bootverbose)
- printf("Calibrating clock(s) ... ");
- /* Check ARTIC. */
- if (!(PC98_SYSTEM_PARAMETER(0x458) & 0x80) &&
- !(PC98_SYSTEM_PARAMETER(0x45b) & 0x04))
- goto fail;
- timeout = 100000000;
-
- /* Read the ARTIC. */
- sec = inw(0x5e);
-
- /* Wait for the ARTIC to changes. */
- start_sec = sec;
- for (;;) {
- sec = inw(0x5e);
- if (sec != start_sec)
- break;
- if (--timeout == 0)
- goto fail;
- }
- prev_count = getit();
- if (prev_count == 0 || prev_count > timer0_max_count)
- goto fail;
- tot_count = 0;
-
- start_sec = sec;
- for (;;) {
- sec = inw(0x5e);
- count = getit();
- if (count == 0 || count > timer0_max_count)
- goto fail;
- if (count > prev_count)
- tot_count += prev_count - (count - timer0_max_count);
- else
- tot_count += prev_count - count;
- prev_count = count;
- if ((sec == start_sec + 1200) ||
- (sec < start_sec &&
- (u_int)sec + 0x10000 == (u_int)start_sec + 1200))
- break;
- if (--timeout == 0)
- goto fail;
- }
-
- if (bootverbose) {
- printf("i8254 clock: %u Hz\n", tot_count);
- }
- return (tot_count);
-
-fail:
- if (bootverbose)
- printf("failed, using default i8254 clock of %u Hz\n",
- timer_freq);
- return (timer_freq);
-}
-
-static void
-set_timer_freq(u_int freq, int intr_freq)
-{
- int new_timer0_max_count;
-
- mtx_lock_spin(&clock_lock);
- timer_freq = freq;
- new_timer0_max_count = hardclock_max_count = TIMER_DIV(intr_freq);
- if (new_timer0_max_count != timer0_max_count) {
- timer0_max_count = new_timer0_max_count;
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
- outb(TIMER_CNTR0, timer0_max_count & 0xff);
- outb(TIMER_CNTR0, timer0_max_count >> 8);
- }
- mtx_unlock_spin(&clock_lock);
-}
-
-static void
-i8254_restore(void)
-{
-
- mtx_lock_spin(&clock_lock);
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
- outb(TIMER_CNTR0, timer0_max_count & 0xff);
- outb(TIMER_CNTR0, timer0_max_count >> 8);
- mtx_unlock_spin(&clock_lock);
-}
-
-
-/*
- * Restore all the timers non-atomically (XXX: should be atomically).
- *
- * This function is called from pmtimer_resume() to restore all the timers.
- * This should not be necessary, but there are broken laptops that do not
- * restore all the timers on resume.
- */
-void
-timer_restore(void)
-{
-
- i8254_restore(); /* restore timer_freq and hz */
-}
-
-/*
- * Initialize 8254 timer 0 early so that it can be used in DELAY().
- * XXX initialization of other timers is unintentionally left blank.
- */
-void
-startrtclock()
-{
- u_int delta, freq;
-
- findcpuspeed();
- if (pc98_machine_type & M_8M)
- timer_freq = 1996800L; /* 1.9968 MHz */
- else
- timer_freq = 2457600L; /* 2.4576 MHz */
-
- set_timer_freq(timer_freq, hz);
- freq = calibrate_clocks();
-#ifdef CLK_CALIBRATION_LOOP
- if (bootverbose) {
- printf(
- "Press a key on the console to abort clock calibration\n");
- while (cncheckc() == -1)
- calibrate_clocks();
- }
-#endif
-
- /*
- * Use the calibrated i8254 frequency if it seems reasonable.
- * Otherwise use the default, and don't use the calibrated i586
- * frequency.
- */
- delta = freq > timer_freq ? freq - timer_freq : timer_freq - freq;
- if (delta < timer_freq / 100) {
-#ifndef CLK_USE_I8254_CALIBRATION
- if (bootverbose)
- printf(
-"CLK_USE_I8254_CALIBRATION not specified - using default frequency\n");
- freq = timer_freq;
-#endif
- timer_freq = freq;
- } else {
- if (bootverbose)
- printf(
- "%d Hz differs from default of %d Hz by more than 1%%\n",
- freq, timer_freq);
- }
-
- set_timer_freq(timer_freq, hz);
- i8254_timecounter.tc_frequency = timer_freq;
- tc_init(&i8254_timecounter);
-
- init_TSC();
-}
-
-static void
-rtc_serialcombit(int i)
-{
- outb(IO_RTC, ((i&0x01)<<5)|0x07);
- DELAY(1);
- outb(IO_RTC, ((i&0x01)<<5)|0x17);
- DELAY(1);
- outb(IO_RTC, ((i&0x01)<<5)|0x07);
- DELAY(1);
-}
-
-static void
-rtc_serialcom(int i)
-{
- rtc_serialcombit(i&0x01);
- rtc_serialcombit((i&0x02)>>1);
- rtc_serialcombit((i&0x04)>>2);
- rtc_serialcombit((i&0x08)>>3);
- outb(IO_RTC, 0x07);
- DELAY(1);
- outb(IO_RTC, 0x0f);
- DELAY(1);
- outb(IO_RTC, 0x07);
- DELAY(1);
-}
-
-static void
-rtc_outb(int val)
-{
- int s;
- int sa = 0;
-
- for (s=0;s<8;s++) {
- sa = ((val >> s) & 0x01) ? 0x27 : 0x07;
- outb(IO_RTC, sa); /* set DI & CLK 0 */
- DELAY(1);
- outb(IO_RTC, sa | 0x10); /* CLK 1 */
- DELAY(1);
- }
- outb(IO_RTC, sa & 0xef); /* CLK 0 */
-}
-
-static int
-rtc_inb(void)
-{
- int s;
- int sa = 0;
-
- for (s=0;s<8;s++) {
- sa |= ((inb(0x33) & 0x01) << s);
- outb(IO_RTC, 0x17); /* CLK 1 */
- DELAY(1);
- outb(IO_RTC, 0x07); /* CLK 0 */
- DELAY(2);
- }
- return sa;
-}
-
-/*
- * Initialize the time of day register, based on the time base which is, e.g.
- * from a filesystem.
- */
-void
-inittodr(time_t base)
-{
- unsigned long sec, days;
- int year, month;
- int y, m, s;
- struct timespec ts;
- int second, min, hour;
-
- if (base) {
- s = splclock();
- ts.tv_sec = base;
- ts.tv_nsec = 0;
- tc_setclock(&ts);
- splx(s);
- }
-
- rtc_serialcom(0x03); /* Time Read */
- rtc_serialcom(0x01); /* Register shift command. */
- DELAY(20);
-
- second = bcd2bin(rtc_inb() & 0xff); /* sec */
- min = bcd2bin(rtc_inb() & 0xff); /* min */
- hour = bcd2bin(rtc_inb() & 0xff); /* hour */
- days = bcd2bin(rtc_inb() & 0xff) - 1; /* date */
-
- month = (rtc_inb() >> 4) & 0x0f; /* month */
- for (m = 1; m < month; m++)
- days += daysinmonth[m-1];
- year = bcd2bin(rtc_inb() & 0xff) + 1900; /* year */
- /* 2000 year problem */
- if (year < 1995)
- year += 100;
- if (year < 1970)
- goto wrong_time;
- for (y = 1970; y < year; y++)
- days += DAYSPERYEAR + LEAPYEAR(y);
- if ((month > 2) && LEAPYEAR(year))
- days ++;
- sec = ((( days * 24 +
- hour) * 60 +
- min) * 60 +
- second);
- /* sec now contains the number of seconds, since Jan 1 1970,
- in the local time zone */
-
- s = splhigh();
-
- sec += tz_minuteswest * 60 + (wall_cmos_clock ? adjkerntz : 0);
-
- y = time_second - sec;
- if (y <= -2 || y >= 2) {
- /* badly off, adjust it */
- ts.tv_sec = sec;
- ts.tv_nsec = 0;
- tc_setclock(&ts);
- }
- splx(s);
- return;
-
-wrong_time:
- printf("Invalid time in real time clock.\n");
- printf("Check and reset the date immediately!\n");
-}
-
-/*
- * Write system time back to RTC
- */
-void
-resettodr()
-{
- unsigned long tm;
- int y, m, s;
- int wd;
-
- if (disable_rtc_set)
- return;
-
- s = splclock();
- tm = time_second;
- splx(s);
-
- rtc_serialcom(0x01); /* Register shift command. */
-
- /* Calculate local time to put in RTC */
-
- tm -= tz_minuteswest * 60 + (wall_cmos_clock ? adjkerntz : 0);
-
- rtc_outb(bin2bcd(tm%60)); tm /= 60; /* Write back Seconds */
- rtc_outb(bin2bcd(tm%60)); tm /= 60; /* Write back Minutes */
- rtc_outb(bin2bcd(tm%24)); tm /= 24; /* Write back Hours */
-
- /* We have now the days since 01-01-1970 in tm */
- wd = (tm + 4) % 7 + 1; /* Write back Weekday */
- for (y = 1970, m = DAYSPERYEAR + LEAPYEAR(y);
- tm >= m;
- y++, m = DAYSPERYEAR + LEAPYEAR(y))
- tm -= m;
-
- /* Now we have the years in y and the day-of-the-year in tm */
- for (m = 0; ; m++) {
- int ml;
-
- ml = daysinmonth[m];
- if (m == 1 && LEAPYEAR(y))
- ml++;
- if (tm < ml)
- break;
- tm -= ml;
- }
-
- m++;
- rtc_outb(bin2bcd(tm+1)); /* Write back Day */
- rtc_outb((m << 4) | wd); /* Write back Month & Weekday */
- rtc_outb(bin2bcd(y%100)); /* Write back Year */
-
- rtc_serialcom(0x02); /* Time set & Counter hold command. */
- rtc_serialcom(0x00); /* Register hold command. */
-}
-
-
-/*
- * Start both clocks running.
- */
-void
-cpu_initclocks()
-{
-#ifdef APIC_IO
- int apic_8254_trial;
- void *clkdesc;
-#endif /* APIC_IO */
- register_t crit;
-
-
- /* Finish initializing 8253 timer 0. */
-#ifdef APIC_IO
-
- apic_8254_intr = isa_apic_irq(0);
- apic_8254_trial = 0;
- if (apic_8254_intr >= 0 ) {
- if (apic_int_type(0, 0) == 3)
- apic_8254_trial = 1;
- } else {
- /* look for ExtInt on pin 0 */
- if (apic_int_type(0, 0) == 3) {
- apic_8254_intr = apic_irq(0, 0);
- setup_8254_mixed_mode();
- } else
- panic("APIC_IO: Cannot route 8254 interrupt to CPU");
- }
-
- inthand_add("clk", apic_8254_intr, (driver_intr_t *)clkintr, NULL,
- INTR_TYPE_CLK | INTR_FAST, &clkdesc);
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTREN(1 << apic_8254_intr);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-
-#else /* APIC_IO */
-
- /*
- * XXX Check the priority of this interrupt handler. I
- * couldn't find anything suitable in the BSD/OS code (grog,
- * 19 July 2000).
- */
- inthand_add("clk", 0, (driver_intr_t *)clkintr, NULL,
- INTR_TYPE_CLK | INTR_FAST, NULL);
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTREN(IRQ0);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-
-#endif /* APIC_IO */
-
-
-
-#ifdef APIC_IO
- if (apic_8254_trial) {
-
- printf("APIC_IO: Testing 8254 interrupt delivery\n");
- while (read_intr_count(8) < 6)
- ; /* nothing */
- if (read_intr_count(apic_8254_intr) < 3) {
- /*
- * The MP table is broken.
- * The 8254 was not connected to the specified pin
- * on the IO APIC.
- * Workaround: Limited variant of mixed mode.
- */
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTRDIS(1 << apic_8254_intr);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
- inthand_remove(clkdesc);
- printf("APIC_IO: Broken MP table detected: "
- "8254 is not connected to "
- "IOAPIC #%d intpin %d\n",
- int_to_apicintpin[apic_8254_intr].ioapic,
- int_to_apicintpin[apic_8254_intr].int_pin);
- /*
- * Revoke current ISA IRQ 0 assignment and
- * configure a fallback interrupt routing from
- * the 8254 Timer via the 8259 PIC to the
- * an ExtInt interrupt line on IOAPIC #0 intpin 0.
- * We reuse the low level interrupt handler number.
- */
- if (apic_irq(0, 0) < 0) {
- revoke_apic_irq(apic_8254_intr);
- assign_apic_irq(0, 0, apic_8254_intr);
- }
- apic_8254_intr = apic_irq(0, 0);
- setup_8254_mixed_mode();
- inthand_add("clk", apic_8254_intr,
- (driver_intr_t *)clkintr, NULL,
- INTR_TYPE_CLK | INTR_FAST, NULL);
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTREN(1 << apic_8254_intr);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
- }
-
- }
- if (apic_int_type(0, 0) != 3 ||
- int_to_apicintpin[apic_8254_intr].ioapic != 0 ||
- int_to_apicintpin[apic_8254_intr].int_pin != 0)
- printf("APIC_IO: routing 8254 via IOAPIC #%d intpin %d\n",
- int_to_apicintpin[apic_8254_intr].ioapic,
- int_to_apicintpin[apic_8254_intr].int_pin);
- else
- printf("APIC_IO: "
- "routing 8254 via 8259 and IOAPIC #0 intpin 0\n");
-#endif
-
-}
-
-#ifdef APIC_IO
-static u_long
-read_intr_count(int vec)
-{
- u_long *up;
- up = intr_countp[vec];
- if (up)
- return *up;
- return 0UL;
-}
-
-static void
-setup_8254_mixed_mode()
-{
- /*
- * Allow 8254 timer to INTerrupt 8259:
- * re-initialize master 8259:
- * reset; prog 4 bytes, single ICU, edge triggered
- */
- outb(IO_ICU1, 0x13);
- outb(IO_ICU1 + 2, NRSVIDT); /* start vector (unused) */
- outb(IO_ICU1 + 2, 0x00); /* ignore slave */
- outb(IO_ICU1 + 2, 0x03); /* auto EOI, 8086 */
- outb(IO_ICU1 + 2, 0xfe); /* unmask INT0 */
-
- /* program IO APIC for type 3 INT on INT0 */
- if (ext_int_setup(0, 0) < 0)
- panic("8254 redirect via APIC pin0 impossible!");
-}
-#endif
-
-void
-cpu_startprofclock(void)
-{
-}
-
-void
-cpu_stopprofclock(void)
-{
-}
-
-static int
-sysctl_machdep_i8254_freq(SYSCTL_HANDLER_ARGS)
-{
- int error;
- u_int freq;
-
- /*
- * Use `i8254' instead of `timer' in external names because `timer'
- * is is too generic. Should use it everywhere.
- */
- freq = timer_freq;
- error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
- if (error == 0 && req->newptr != NULL) {
- if (timer0_state != RELEASED)
- return (EBUSY); /* too much trouble to handle */
- set_timer_freq(freq, hz);
- i8254_timecounter.tc_frequency = freq;
- }
- return (error);
-}
-
-SYSCTL_PROC(_machdep, OID_AUTO, i8254_freq, CTLTYPE_INT | CTLFLAG_RW,
- 0, sizeof(u_int), sysctl_machdep_i8254_freq, "IU", "");
-
-static unsigned
-i8254_get_timecount(struct timecounter *tc)
-{
- u_int count;
- u_int high, low;
- u_int eflags;
-
- eflags = read_eflags();
- mtx_lock_spin(&clock_lock);
-
- /* Select timer0 and latch counter value. */
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
-
- low = inb(TIMER_CNTR0);
- high = inb(TIMER_CNTR0);
- count = timer0_max_count - ((high << 8) | low);
- if (count < i8254_lastcount ||
- (!i8254_ticked && (clkintr_pending ||
- ((count < 20 || (!(eflags & PSL_I) && count < timer0_max_count / 2u)) &&
-#ifdef APIC_IO
-#define lapic_irr1 ((volatile u_int *)&lapic)[0x210 / 4] /* XXX XXX */
- /* XXX this assumes that apic_8254_intr is < 24. */
- (lapic_irr1 & (1 << apic_8254_intr))))
-#else
- (inb(IO_ICU1) & 1)))
-#endif
- )) {
- i8254_ticked = 1;
- i8254_offset += timer0_max_count;
- }
- i8254_lastcount = count;
- count += i8254_offset;
- mtx_unlock_spin(&clock_lock);
- return (count);
-}
-
-#ifdef DEV_ISA
-/*
- * Attach to the ISA PnP descriptors for the timer and realtime clock.
- */
-static struct isa_pnp_id attimer_ids[] = {
- { 0x0001d041 /* PNP0100 */, "AT timer" },
- { 0x000bd041 /* PNP0B00 */, "AT realtime clock" },
- { 0 }
-};
-
-static int
-attimer_probe(device_t dev)
-{
- int result;
-
- if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, attimer_ids)) <= 0)
- device_quiet(dev);
- return(result);
-}
-
-static int
-attimer_attach(device_t dev)
-{
- return(0);
-}
-
-static device_method_t attimer_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, attimer_probe),
- DEVMETHOD(device_attach, attimer_attach),
- DEVMETHOD(device_detach, bus_generic_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend), /* XXX stop statclock? */
- DEVMETHOD(device_resume, bus_generic_resume), /* XXX restart statclock? */
- { 0, 0 }
-};
-
-static driver_t attimer_driver = {
- "attimer",
- attimer_methods,
- 1, /* no softc */
-};
-
-static devclass_t attimer_devclass;
-
-DRIVER_MODULE(attimer, isa, attimer_driver, attimer_devclass, 0, 0);
-#endif /* DEV_ISA */
diff --git a/sys/pc98/cbus/fdc.c b/sys/pc98/cbus/fdc.c
deleted file mode 100644
index 0b5cda16e9c2..000000000000
--- a/sys/pc98/cbus/fdc.c
+++ /dev/null
@@ -1,3345 +0,0 @@
-/*
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Don Ahn.
- *
- * Libretto PCMCIA floppy support by David Horwitt (dhorwitt@ucsd.edu)
- * aided by the Linux floppy driver modifications from David Bateman
- * (dbateman@eng.uts.edu.au).
- *
- * Copyright (c) 1993, 1994 by
- * jc@irbs.UUCP (John Capo)
- * vak@zebub.msk.su (Serge Vakulenko)
- * ache@astral.msk.su (Andrew A. Chernov)
- *
- * Copyright (c) 1993, 1994, 1995 by
- * joerg_wunsch@uriah.sax.de (Joerg Wunsch)
- * dufault@hda.com (Peter Dufault)
- *
- * Copyright (c) 2001 Joerg Wunsch,
- * joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch)
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)fd.c 7.4 (Berkeley) 5/25/91
- * $FreeBSD$
- */
-
-#include "opt_fdc.h"
-#include "card.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bio.h>
-#include <sys/bus.h>
-#include <sys/conf.h>
-#include <sys/devicestat.h>
-#include <sys/disk.h>
-#include <sys/fcntl.h>
-#include <sys/fdcio.h>
-#include <sys/filio.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/module.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/syslog.h>
-
-#include <machine/bus.h>
-#include <sys/rman.h>
-
-#include <machine/clock.h>
-#include <machine/resource.h>
-#include <machine/stdarg.h>
-
-#include <isa/isavar.h>
-#ifdef PC98
-#include <pc98/pc98/pc98.h>
-#include <pc98/pc98/pc98_machdep.h>
-#include <pc98/pc98/epsonio.h>
-#include <pc98/pc98/fdreg.h>
-#else
-#include <isa/isareg.h>
-#include <isa/fdreg.h>
-#include <isa/rtc.h>
-#endif
-
-enum fdc_type
-{
- FDC_NE765, FDC_ENHANCED, FDC_UNKNOWN = -1
-};
-
-enum fdc_states {
- DEVIDLE,
- FINDWORK,
- DOSEEK,
- SEEKCOMPLETE ,
- IOCOMPLETE,
- RECALCOMPLETE,
- STARTRECAL,
- RESETCTLR,
- SEEKWAIT,
- RECALWAIT,
- MOTORWAIT,
- IOTIMEDOUT,
- RESETCOMPLETE,
- PIOREAD
-};
-
-#ifdef FDC_DEBUG
-static char const * const fdstates[] = {
- "DEVIDLE",
- "FINDWORK",
- "DOSEEK",
- "SEEKCOMPLETE",
- "IOCOMPLETE",
- "RECALCOMPLETE",
- "STARTRECAL",
- "RESETCTLR",
- "SEEKWAIT",
- "RECALWAIT",
- "MOTORWAIT",
- "IOTIMEDOUT",
- "RESETCOMPLETE",
- "PIOREAD"
-};
-#endif
-
-/*
- * Per controller structure (softc).
- */
-struct fdc_data
-{
- int fdcu; /* our unit number */
- int dmachan;
- int flags;
-#define FDC_ATTACHED 0x01
-#define FDC_STAT_VALID 0x08
-#define FDC_HAS_FIFO 0x10
-#define FDC_NEEDS_RESET 0x20
-#define FDC_NODMA 0x40
-#define FDC_ISPNP 0x80
-#define FDC_ISPCMCIA 0x100
- struct fd_data *fd;
- int fdu; /* the active drive */
- enum fdc_states state;
- int retry;
-#ifndef PC98
- int fdout; /* mirror of the w/o digital output reg */
-#endif
- u_int status[7]; /* copy of the registers */
- enum fdc_type fdct; /* chip version of FDC */
- int fdc_errs; /* number of logged errors */
- int dma_overruns; /* number of DMA overruns */
- struct bio_queue_head head;
- struct bio *bp; /* active buffer */
-#ifdef PC98
- struct resource *res_ioport, *res_fdsio, *res_fdemsio;
- struct resource *res_irq, *res_drq;
- int rid_ioport, rid_irq, rid_drq;
-#else
- struct resource *res_ioport, *res_ctl, *res_irq, *res_drq;
- int rid_ioport, rid_ctl, rid_irq, rid_drq;
-#endif
- int port_off;
- bus_space_tag_t portt;
- bus_space_handle_t porth;
-#ifdef PC98
- bus_space_tag_t sc_fdsiot;
- bus_space_handle_t sc_fdsioh;
- bus_space_tag_t sc_fdemsiot;
- bus_space_handle_t sc_fdemsioh;
-#else
- bus_space_tag_t ctlt;
- bus_space_handle_t ctlh;
-#endif
- void *fdc_intr;
- struct device *fdc_dev;
-#ifndef PC98
- void (*fdctl_wr)(struct fdc_data *fdc, u_int8_t v);
-#endif
-};
-
-#define FDBIO_FORMAT BIO_CMD2
-
-typedef int fdu_t;
-typedef int fdcu_t;
-typedef int fdsu_t;
-typedef struct fd_data *fd_p;
-typedef struct fdc_data *fdc_p;
-typedef enum fdc_type fdc_t;
-
-#define FDUNIT(s) (((s) >> 6) & 3)
-#define FDNUMTOUNIT(n) (((n) & 3) << 6)
-#define FDTYPE(s) ((s) & 0x3f)
-
-/*
- * fdc maintains a set (1!) of ivars per child of each controller.
- */
-enum fdc_device_ivars {
- FDC_IVAR_FDUNIT,
-};
-
-/*
- * Simple access macros for the ivars.
- */
-#define FDC_ACCESSOR(A, B, T) \
-static __inline T fdc_get_ ## A(device_t dev) \
-{ \
- uintptr_t v; \
- BUS_READ_IVAR(device_get_parent(dev), dev, FDC_IVAR_ ## B, &v); \
- return (T) v; \
-}
-FDC_ACCESSOR(fdunit, FDUNIT, int)
-
-/* configuration flags for fdc */
-#define FDC_NO_FIFO (1 << 2) /* do not enable FIFO */
-
-/* error returns for fd_cmd() */
-#define FD_FAILED -1
-#define FD_NOT_VALID -2
-#define FDC_ERRMAX 100 /* do not log more */
-/*
- * Stop retrying after this many DMA overruns. Since each retry takes
- * one revolution, with 300 rpm., 25 retries take approximately 5
- * seconds which the read attempt will block in case the DMA overrun
- * is persistent.
- */
-#define FDC_DMAOV_MAX 25
-
-/*
- * Timeout value for the PIO loops to wait until the FDC main status
- * register matches our expectations (request for master, direction
- * bit). This is supposed to be a number of microseconds, although
- * timing might actually not be very accurate.
- *
- * Timeouts of 100 msec are believed to be required for some broken
- * (old) hardware.
- */
-#define FDSTS_TIMEOUT 100000
-
-/*
- * Number of subdevices that can be used for different density types.
- * By now, the lower 6 bit of the minor number are reserved for this,
- * allowing for up to 64 subdevices, but we only use 16 out of this.
- * Density #0 is used for automatic format detection, the other
- * densities are available as programmable densities (for assignment
- * by fdcontrol(8)).
- * The upper 2 bits of the minor number are reserved for the subunit
- * (drive #) per controller.
- */
-#ifdef PC98
-#define NUMDENS 12
-#else
-#define NUMDENS 16
-#endif
-
-#define FDBIO_RDSECTID BIO_CMD1
-
-/*
- * List of native drive densities. Order must match enum fd_drivetype
- * in <sys/fdcio.h>. Upon attaching the drive, each of the
- * programmable subdevices is initialized with the native density
- * definition.
- */
-#ifdef PC98
-static struct fd_type fd_native_types[] =
-{
-{ 0 }, /* FDT_NONE */
-{ 0 }, /* FDT_360K */
-{ 15,2,0xFF,0x1B,80,2400,0,2,0x54,1,0,0 }, /* FDT_12M */
-{ 0 }, /* FDT_720K */
-{ 18,2,0xFF,0x1B,80,2880,2,2,0x54,1,0,0 }, /* FDT_144M */
-{ 0 }, /* FDT_288M */
-};
-
-static struct fd_type fd_searchlist_12m[] = {
-{ 15,2,0xFF,0x1B,80,2400,0,2,0x54,1,0,0 }, /* 1.2M */
-{ 10,2,0xFF,0x10,82,1640,1,2,0x30,1,0,0 }, /* 820K */
-{ 10,2,0xFF,0x10,80,1600,1,2,0x30,1,0,0 }, /* 800K */
-{ 9,2,0xFF,0x20,80,1440,1,2,0x50,1,0,0 }, /* 720K */
-{ 9,2,0xFF,0x20,40, 720,1,2,0x50,1,0,FL_2STEP },/* 360K */
-{ 8,2,0xFF,0x2A,80,1280,1,2,0x50,1,0,0 }, /* 640K */
-{ 8,3,0xFF,0x35,77,1232,0,2,0x74,1,0,0 }, /* 1.23M 1024/sec */
-
-{ 8,3,0xFF,0x35,80,1280,0,2,0x74,1,0,0 }, /* 1.28M 1024/sec */
-};
-static struct fd_type fd_searchlist_144m[] = {
-{ 21,2,0xFF,0x04,82,3444,2,2,0x0C,2,0,0 }, /* 1.72M in 3mode */
-{ 18,2,0xFF,0x1B,82,2952,2,2,0x54,1,0,0 }, /* 1.48M in 3mode */
-{ 18,2,0xFF,0x1B,80,2880,2,2,0x54,1,0,0 }, /* 1.44M in 3mode */
-{ 15,2,0xFF,0x1B,80,2400,0,2,0x54,1,0,0 }, /* 1.2M */
-{ 10,2,0xFF,0x10,82,1640,1,2,0x30,1,0,0 }, /* 820K */
-{ 10,2,0xFF,0x10,80,1600,1,2,0x30,1,0,0 }, /* 800K */
-{ 9,2,0xFF,0x20,80,1440,1,2,0x50,1,0,0 }, /* 720K */
-{ 9,2,0xFF,0x20,40, 720,1,2,0x50,1,0,FL_2STEP },/* 360K */
-{ 8,2,0xFF,0x2A,80,1280,1,2,0x50,1,0,0 }, /* 640K */
-{ 8,3,0xFF,0x35,77,1232,0,2,0x74,1,0,0 }, /* 1.23M 1024/sec */
-
-{ 8,3,0xFF,0x35,80,1280,0,2,0x74,1,0,0 }, /* 1.28M 1024/sec */
-{ 9,3,0xFF,0x35,82,1476,0,2,0x47,1,0,0 }, /* 1.48M 1024/sec 9sec */
-#if 0
-{ 10,3,0xFF,0x1B,82,1640,2,2,0x54,1,0,0 }, /* 1.64M in 3mode - Reserve */
-#endif
-};
-#else /* PC98 */
-static struct fd_type fd_native_types[] =
-{
-{ 0 }, /* FDT_NONE */
-{ 9,2,0xFF,0x2A,40, 720,FDC_250KBPS,2,0x50,1,0,FL_MFM }, /* FDT_360K */
-{ 15,2,0xFF,0x1B,80,2400,FDC_500KBPS,2,0x54,1,0,FL_MFM }, /* FDT_12M */
-{ 9,2,0xFF,0x20,80,1440,FDC_250KBPS,2,0x50,1,0,FL_MFM }, /* FDT_720K */
-{ 18,2,0xFF,0x1B,80,2880,FDC_500KBPS,2,0x6C,1,0,FL_MFM }, /* FDT_144M */
-#if 0 /* we currently don't handle 2.88 MB */
-{ 36,2,0xFF,0x1B,80,5760,FDC_1MBPS, 2,0x4C,1,1,FL_MFM|FL_PERPND } /*FDT_288M*/
-#else
-{ 18,2,0xFF,0x1B,80,2880,FDC_500KBPS,2,0x6C,1,0,FL_MFM }, /* FDT_144M */
-#endif
-};
-
-/*
- * 360 KB 5.25" and 720 KB 3.5" drives don't have automatic density
- * selection, they just start out with their native density (or lose).
- * So 1.2 MB 5.25", 1.44 MB 3.5", and 2.88 MB 3.5" drives have their
- * respective lists of densities to search for.
- */
-static struct fd_type fd_searchlist_12m[] = {
-{ 15,2,0xFF,0x1B,80,2400,FDC_500KBPS,2,0x54,1,0,FL_MFM }, /* 1.2M */
-{ 9,2,0xFF,0x23,40, 720,FDC_300KBPS,2,0x50,1,0,FL_MFM|FL_2STEP }, /* 360K */
-{ 9,2,0xFF,0x20,80,1440,FDC_300KBPS,2,0x50,1,0,FL_MFM }, /* 720K */
-};
-
-static struct fd_type fd_searchlist_144m[] = {
-{ 18,2,0xFF,0x1B,80,2880,FDC_500KBPS,2,0x6C,1,0,FL_MFM }, /* 1.44M */
-{ 9,2,0xFF,0x20,80,1440,FDC_250KBPS,2,0x50,1,0,FL_MFM }, /* 720K */
-};
-
-/* We search for 1.44M first since this is the most common case. */
-static struct fd_type fd_searchlist_288m[] = {
-{ 18,2,0xFF,0x1B,80,2880,FDC_500KBPS,2,0x6C,1,0,FL_MFM }, /* 1.44M */
-#if 0
-{ 36,2,0xFF,0x1B,80,5760,FDC_1MBPS, 2,0x4C,1,1,FL_MFM|FL_PERPND } /* 2.88M */
-#endif
-{ 9,2,0xFF,0x20,80,1440,FDC_250KBPS,2,0x50,1,0,FL_MFM }, /* 720K */
-};
-#endif /* PC98 */
-
-#define MAX_SEC_SIZE (128 << 3)
-#define MAX_CYLINDER 85 /* some people really stress their drives
- * up to cyl 82 */
-#define MAX_HEAD 1
-
-static devclass_t fdc_devclass;
-
-/*
- * Per drive structure (softc).
- */
-struct fd_data {
- struct fdc_data *fdc; /* pointer to controller structure */
- int fdsu; /* this units number on this controller */
- enum fd_drivetype type; /* drive type */
- struct fd_type *ft; /* pointer to current type descriptor */
- struct fd_type fts[NUMDENS]; /* type descriptors */
- int flags;
-#define FD_OPEN 0x01 /* it's open */
-#define FD_NONBLOCK 0x02 /* O_NONBLOCK set */
-#define FD_ACTIVE 0x04 /* it's active */
-#define FD_MOTOR 0x08 /* motor should be on */
-#define FD_MOTOR_WAIT 0x10 /* motor coming up */
-#define FD_UA 0x20 /* force unit attention */
- int skip;
- int hddrv;
-#define FD_NO_TRACK -2
- int track; /* where we think the head is */
- int options; /* user configurable options, see fdcio.h */
- struct callout_handle toffhandle;
- struct callout_handle tohandle;
- struct devstat *device_stats;
- eventhandler_tag clonetag;
- dev_t masterdev;
- dev_t clonedevs[NUMDENS - 1];
- device_t dev;
- fdu_t fdu;
-#ifdef PC98
- int pc98_trans;
-#endif
-};
-
-#ifdef PC98
-static bus_addr_t fdc_iat[] = {0, 2, 4};
-#endif
-
-struct fdc_ivars {
- int fdunit;
-};
-static devclass_t fd_devclass;
-
-/* configuration flags for fd */
-#define FD_TYPEMASK 0x0f /* drive type, matches enum
- * fd_drivetype; on i386 machines, if
- * given as 0, use RTC type for fd0
- * and fd1 */
-#define FD_DTYPE(flags) ((flags) & FD_TYPEMASK)
-#define FD_NO_CHLINE 0x10 /* drive does not support changeline
- * aka. unit attention */
-#define FD_NO_PROBE 0x20 /* don't probe drive (seek test), just
- * assume it is there */
-
-#ifdef EPSON_NRDISK
-typedef unsigned int nrd_t;
-
-#define P_NRD_ADDRH 0xc24
-#define P_NRD_ADDRM 0xc22
-#define P_NRD_ADDRL 0xc20
-#define P_NRD_CHECK 0xc20
-#define P_NRD_DATA 0xc26
-#define P_NRD_LED 0xc36
-#define B_NRD_CHK 0x80
-#define B_NRD_LED 0x40
-#define A_NRD_INFO 0x2
-#define A_NRD_BASE 0x400
-#define NRD_STATUS 0x0
-#define NRD_ST0_HD 0x04
-
-static fdu_t nrdu=-1;
-static int nrdsec=0;
-static nrd_t nrdblkn=0;
-static nrd_t nrdaddr=0x0;
-
-#define nrd_check_ready() ({ \
- (epson_inb(P_NRD_CHECK) & B_NRD_CHK) ? 0 : 1; \
- })
-#define nrd_LED_on() epson_outb(P_NRD_LED, B_NRD_LED)
-#define nrd_LED_off() epson_outb(P_NRD_LED, ~B_NRD_LED)
-#define nrd_trac() ((int)(nrd_info(nrdaddr) & 0xff))
-#define nrd_head() ((int)((nrd_info(nrdaddr) >> 8) & 0xff))
-#define nrd_sec() ((int)(nrd_info(nrdaddr + 2) & 0xff))
-#define nrd_secsize() ((int)((nrd_info(A_NRD_INFO) >> 8) & 0xff))
-#define nrd_addrset(p) nrd_addr((nrd_t)((nrd_t)p+A_NRD_BASE))
-
-static inline void
-nrd_addr(addr)
- nrd_t addr;
-{
- epson_outb(P_NRD_ADDRH, (u_char)((addr >> 16) & 0x1f));
- epson_outb(P_NRD_ADDRM, (u_char)((addr >> 8) & 0xff));
- epson_outb(P_NRD_ADDRL, (u_char)(addr & 0xff));
-}
-
-static inline u_short
-nrd_info(addr)
- nrd_t addr;
-{
- nrd_addr(addr);
- return (epson_inw(P_NRD_DATA));
-}
-#endif /* EPSON_NRDISK */
-
-/*
- * Throughout this file the following conventions will be used:
- *
- * fd is a pointer to the fd_data struct for the drive in question
- * fdc is a pointer to the fdc_data struct for the controller
- * fdu is the floppy drive unit number
- * fdcu is the floppy controller unit number
- * fdsu is the floppy drive unit number on that controller. (sub-unit)
- */
-
-/*
- * Function declarations, same (chaotic) order as they appear in the
- * file. Re-ordering is too late now, it would only obfuscate the
- * diffs against old and offspring versions (like the PC98 one).
- *
- * Anyone adding functions here, please keep this sequence the same
- * as below -- makes locating a particular function in the body much
- * easier.
- */
-#ifndef PC98
-static void fdout_wr(fdc_p, u_int8_t);
-#endif
-static u_int8_t fdsts_rd(fdc_p);
-static void fddata_wr(fdc_p, u_int8_t);
-static u_int8_t fddata_rd(fdc_p);
-#ifndef PC98
-static void fdctl_wr_isa(fdc_p, u_int8_t);
-#if NCARD > 0
-static void fdctl_wr_pcmcia(fdc_p, u_int8_t);
-#endif
-#if 0
-static u_int8_t fdin_rd(fdc_p);
-#endif
-#endif /* PC98 */
-static int fdc_err(struct fdc_data *, const char *);
-static int fd_cmd(struct fdc_data *, int, ...);
-static int enable_fifo(fdc_p fdc);
-static int fd_sense_drive_status(fdc_p, int *);
-static int fd_sense_int(fdc_p, int *, int *);
-static int fd_read_status(fdc_p);
-static int fdc_alloc_resources(struct fdc_data *);
-static void fdc_release_resources(struct fdc_data *);
-static int fdc_read_ivar(device_t, device_t, int, uintptr_t *);
-static int fdc_probe(device_t);
-#if NCARD > 0
-static int fdc_pccard_probe(device_t);
-#endif
-static int fdc_detach(device_t dev);
-static void fdc_add_child(device_t, const char *, int);
-static int fdc_attach(device_t);
-static int fdc_print_child(device_t, device_t);
-static void fd_clone (void *, char *, int, dev_t *);
-static int fd_probe(device_t);
-static int fd_attach(device_t);
-static int fd_detach(device_t);
-static void set_motor(struct fdc_data *, int, int);
-# define TURNON 1
-# define TURNOFF 0
-static timeout_t fd_turnoff;
-static timeout_t fd_motor_on;
-static void fd_turnon(struct fd_data *);
-static void fdc_reset(fdc_p);
-static int fd_in(struct fdc_data *, int *);
-static int out_fdc(struct fdc_data *, int);
-/*
- * The open function is named Fdopen() to avoid confusion with fdopen()
- * in fd(4). The difference is now only meaningful for debuggers.
- */
-static d_open_t Fdopen;
-static d_close_t fdclose;
-static d_strategy_t fdstrategy;
-static void fdstart(struct fdc_data *);
-static timeout_t fd_iotimeout;
-static timeout_t fd_pseudointr;
-static driver_intr_t fdc_intr;
-static int fdcpio(fdc_p, long, caddr_t, u_int);
-static int fdautoselect(dev_t);
-static int fdstate(struct fdc_data *);
-static int retrier(struct fdc_data *);
-static void fdbiodone(struct bio *);
-static int fdmisccmd(dev_t, u_int, void *);
-static d_ioctl_t fdioctl;
-
-static int fifo_threshold = 8; /* XXX: should be accessible via sysctl */
-
-#ifdef FDC_DEBUG
-/* CAUTION: fd_debug causes huge amounts of logging output */
-static int volatile fd_debug = 0;
-#define TRACE0(arg) do { if (fd_debug) printf(arg); } while (0)
-#define TRACE1(arg1, arg2) do { if (fd_debug) printf(arg1, arg2); } while (0)
-#else /* FDC_DEBUG */
-#define TRACE0(arg) do { } while (0)
-#define TRACE1(arg1, arg2) do { } while (0)
-#endif /* FDC_DEBUG */
-
-/*
- * Bus space handling (access to low-level IO).
- */
-#ifndef PC98
-static void
-fdout_wr(fdc_p fdc, u_int8_t v)
-{
- bus_space_write_1(fdc->portt, fdc->porth, FDOUT+fdc->port_off, v);
-}
-#endif
-
-static u_int8_t
-fdsts_rd(fdc_p fdc)
-{
- return bus_space_read_1(fdc->portt, fdc->porth, FDSTS+fdc->port_off);
-}
-
-static void
-fddata_wr(fdc_p fdc, u_int8_t v)
-{
- bus_space_write_1(fdc->portt, fdc->porth, FDDATA+fdc->port_off, v);
-}
-
-static u_int8_t
-fddata_rd(fdc_p fdc)
-{
- return bus_space_read_1(fdc->portt, fdc->porth, FDDATA+fdc->port_off);
-}
-
-#ifdef PC98
-static void
-fdctl_wr(fdc_p fdc, u_int8_t v)
-{
- bus_space_write_1(fdc->portt, fdc->porth, FDCTL, v);
-}
-#endif
-
-#ifndef PC98
-static void
-fdctl_wr_isa(fdc_p fdc, u_int8_t v)
-{
- bus_space_write_1(fdc->ctlt, fdc->ctlh, 0, v);
-}
-
-#if NCARD > 0
-static void
-fdctl_wr_pcmcia(fdc_p fdc, u_int8_t v)
-{
- bus_space_write_1(fdc->portt, fdc->porth, FDCTL+fdc->port_off, v);
-}
-#endif
-
-static u_int8_t
-fdin_rd(fdc_p fdc)
-{
- return bus_space_read_1(fdc->portt, fdc->porth, FDIN);
-}
-#endif /* PC98 */
-
-#define CDEV_MAJOR 9
-static struct cdevsw fd_cdevsw = {
- .d_open = Fdopen,
- .d_close = fdclose,
- .d_read = physread,
- .d_write = physwrite,
- .d_ioctl = fdioctl,
- .d_strategy = fdstrategy,
- .d_name = "fd",
- .d_maj = CDEV_MAJOR,
- .d_flags = D_DISK,
-};
-
-/*
- * Auxiliary functions. Well, some only. Others are scattered
- * throughout the entire file.
- */
-static int
-fdc_err(struct fdc_data *fdc, const char *s)
-{
- fdc->fdc_errs++;
- if (s) {
- if (fdc->fdc_errs < FDC_ERRMAX)
- device_printf(fdc->fdc_dev, "%s", s);
- else if (fdc->fdc_errs == FDC_ERRMAX)
- device_printf(fdc->fdc_dev, "too many errors, not "
- "logging any more\n");
- }
-
- return FD_FAILED;
-}
-
-/*
- * fd_cmd: Send a command to the chip. Takes a varargs with this structure:
- * Unit number,
- * # of output bytes, output bytes as ints ...,
- * # of input bytes, input bytes as ints ...
- */
-static int
-fd_cmd(struct fdc_data *fdc, int n_out, ...)
-{
- u_char cmd;
- int n_in;
- int n;
- va_list ap;
-
- va_start(ap, n_out);
- cmd = (u_char)(va_arg(ap, int));
- va_end(ap);
- va_start(ap, n_out);
- for (n = 0; n < n_out; n++)
- {
- if (out_fdc(fdc, va_arg(ap, int)) < 0)
- {
- char msg[50];
- snprintf(msg, sizeof(msg),
- "cmd %x failed at out byte %d of %d\n",
- cmd, n + 1, n_out);
- return fdc_err(fdc, msg);
- }
- }
- n_in = va_arg(ap, int);
- for (n = 0; n < n_in; n++)
- {
- int *ptr = va_arg(ap, int *);
- if (fd_in(fdc, ptr) < 0)
- {
- char msg[50];
- snprintf(msg, sizeof(msg),
- "cmd %02x failed at in byte %d of %d\n",
- cmd, n + 1, n_in);
- return fdc_err(fdc, msg);
- }
- }
-
- return 0;
-}
-
-static int
-enable_fifo(fdc_p fdc)
-{
- int i, j;
-
- if ((fdc->flags & FDC_HAS_FIFO) == 0) {
-
- /*
- * Cannot use fd_cmd the normal way here, since
- * this might be an invalid command. Thus we send the
- * first byte, and check for an early turn of data directon.
- */
-
- if (out_fdc(fdc, I8207X_CONFIGURE) < 0)
- return fdc_err(fdc, "Enable FIFO failed\n");
-
- /* If command is invalid, return */
- j = FDSTS_TIMEOUT;
- while ((i = fdsts_rd(fdc) & (NE7_DIO | NE7_RQM))
- != NE7_RQM && j-- > 0) {
- if (i == (NE7_DIO | NE7_RQM)) {
- fdc_reset(fdc);
- return FD_FAILED;
- }
- DELAY(1);
- }
- if (j<0 ||
- fd_cmd(fdc, 3,
- 0, (fifo_threshold - 1) & 0xf, 0, 0) < 0) {
- fdc_reset(fdc);
- return fdc_err(fdc, "Enable FIFO failed\n");
- }
- fdc->flags |= FDC_HAS_FIFO;
- return 0;
- }
- if (fd_cmd(fdc, 4,
- I8207X_CONFIGURE, 0, (fifo_threshold - 1) & 0xf, 0, 0) < 0)
- return fdc_err(fdc, "Re-enable FIFO failed\n");
- return 0;
-}
-
-static int
-fd_sense_drive_status(fdc_p fdc, int *st3p)
-{
- int st3;
-
- if (fd_cmd(fdc, 2, NE7CMD_SENSED, fdc->fdu, 1, &st3))
- {
- return fdc_err(fdc, "Sense Drive Status failed\n");
- }
- if (st3p)
- *st3p = st3;
-
- return 0;
-}
-
-static int
-fd_sense_int(fdc_p fdc, int *st0p, int *cylp)
-{
- int cyl, st0, ret;
-
-#ifdef EPSON_NRDISK
- if (fdc->fdu == nrdu) {
- if (fdc->fd->track >= 0) nrdaddr = (fdc->fd->track + 1) * 8;
- else nrdaddr = 0x0;
- *st0p = nrd_head() ? NRD_ST0_HD : NRD_STATUS;
- *cylp = nrd_trac();
- }
- else {
-#endif /* EPSON_NRDISK */
- ret = fd_cmd(fdc, 1, NE7CMD_SENSEI, 1, &st0);
- if (ret) {
- (void)fdc_err(fdc,
- "sense intr err reading stat reg 0\n");
- return ret;
- }
-
- if (st0p)
- *st0p = st0;
-
- if ((st0 & NE7_ST0_IC) == NE7_ST0_IC_IV) {
- /*
- * There doesn't seem to have been an interrupt.
- */
- return FD_NOT_VALID;
- }
-
- if (fd_in(fdc, &cyl) < 0) {
- return fdc_err(fdc, "can't get cyl num\n");
- }
-
- if (cylp)
- *cylp = cyl;
-
-#ifdef EPSON_NRDISK
- }
-#endif /* EPSON_NRDISK */
- return 0;
-}
-
-
-static int
-fd_read_status(fdc_p fdc)
-{
- int i, ret;
-
- for (i = ret = 0; i < 7; i++) {
- /*
- * XXX types are poorly chosen. Only bytes can be read
- * from the hardware, but fdc->status[] wants u_ints and
- * fd_in() gives ints.
- */
- int status;
-
-#ifdef EPSON_NRDISK
- if (fdc->fdu == nrdu) {
- switch (i) {
- case 0: fdc->status[i] = nrd_head()
- ? NRD_ST0_HD : NRD_STATUS; break;
- case 1: fdc->status[i] = NRD_STATUS; break;
- case 2: fdc->status[i] = NRD_STATUS; break;
- case 3: fdc->status[i] = nrd_trac(); break;
- case 4: fdc->status[i] = nrd_head(); break;
- case 5: fdc->status[i] = nrdsec; break;
- case 6: fdc->status[i] = nrd_secsize(); break;
- }
- ret = 0;
- }
- else {
-#endif /* EPSON_NRDISK */
- ret = fd_in(fdc, &status);
- fdc->status[i] = status;
- if (ret != 0)
- break;
-#ifdef EPSON_NRDISK
- }
-#endif /* EPSON_NRDISK */
- }
-
- if (ret == 0)
- fdc->flags |= FDC_STAT_VALID;
- else
- fdc->flags &= ~FDC_STAT_VALID;
-
- return ret;
-}
-
-#ifdef PC98
-static int pc98_trans = 0; /* 0 : HD , 1 : DD , 2 : 1.44 */
-static int pc98_trans_prev = 0;
-
-static void set_density(fdc_p fdc)
-{
- /* always motor on */
- bus_space_write_1(fdc->sc_fdsiot, fdc->sc_fdsioh, 0,
- (pc98_trans != 1 ? FDP_FDDEXC : 0) | FDP_PORTEXC);
- DELAY(100);
- fdctl_wr(fdc, FDC_RST | FDC_DMAE);
- /* in the case of note W, always inhibit 100ms timer */
-}
-
-static int pc98_fd_check_ready(fdu_t fdu)
-{
- fd_p fd = devclass_get_softc(fd_devclass, fdu);
- struct fdc_data *fdc = fd->fdc;
- int retry = 0, status;
-
-#ifdef EPSON_NRDISK
- if (fdu == nrdu) {
- if (nrd_check_ready()) return 0;
- else return -1;
- }
-#endif
- while (retry++ < 30000) {
- set_motor(fdc, fd->fdsu, TURNON);
- out_fdc(fdc, NE7CMD_SENSED); /* Sense Drive Status */
- DELAY(100);
- out_fdc(fdc, fdu); /* Drive number */
- DELAY(100);
- if ((fd_in(fdc, &status) == 0) && (status & NE7_ST3_RD)) {
- fdctl_wr(fdc, FDC_DMAE | FDC_MTON);
- DELAY(10);
- return 0;
- }
- }
- return -1;
-}
-#endif /* PC98 */
-
-static int
-fdc_alloc_resources(struct fdc_data *fdc)
-{
- device_t dev;
-#ifdef PC98
- int rid;
-#else
- int ispnp, ispcmcia, nports;
-#endif
-
- dev = fdc->fdc_dev;
-#ifndef PC98
- ispnp = (fdc->flags & FDC_ISPNP) != 0;
- ispcmcia = (fdc->flags & FDC_ISPCMCIA) != 0;
-#endif
- fdc->rid_ioport = fdc->rid_irq = fdc->rid_drq = 0;
- fdc->res_ioport = fdc->res_irq = fdc->res_drq = 0;
-
-#ifdef PC98
- fdc->res_ioport = isa_alloc_resourcev(dev, SYS_RES_IOPORT,
- &fdc->rid_ioport, fdc_iat,
- 3, RF_ACTIVE);
- if (fdc->res_ioport == 0) {
- device_printf(dev, "cannot reserve I/O port range\n");
- return ENXIO;
- }
- isa_load_resourcev(fdc->res_ioport, fdc_iat, 3);
-#else
- /*
- * On standard ISA, we don't just use an 8 port range
- * (e.g. 0x3f0-0x3f7) since that covers an IDE control
- * register at 0x3f6.
- *
- * Isn't PC hardware wonderful.
- *
- * The Y-E Data PCMCIA FDC doesn't have this problem, it
- * uses the register with offset 6 for pseudo-DMA, and the
- * one with offset 7 as control register.
- */
- nports = ispcmcia ? 8 : (ispnp ? 1 : 6);
- fdc->res_ioport = bus_alloc_resource(dev, SYS_RES_IOPORT,
- &fdc->rid_ioport, 0ul, ~0ul,
- nports, RF_ACTIVE);
- if (fdc->res_ioport == 0) {
- device_printf(dev, "cannot reserve I/O port range (%d ports)\n",
- nports);
- return ENXIO;
- }
-#endif
- fdc->portt = rman_get_bustag(fdc->res_ioport);
- fdc->porth = rman_get_bushandle(fdc->res_ioport);
-
-#ifdef PC98
- rid = 3;
- bus_set_resource(dev, SYS_RES_IOPORT, rid, IO_FDPORT, 1);
- fdc->res_fdsio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
- 1, RF_ACTIVE);
- if (fdc->res_fdsio == 0)
- return ENXIO;
- fdc->sc_fdsiot = rman_get_bustag(fdc->res_fdsio);
- fdc->sc_fdsioh = rman_get_bushandle(fdc->res_fdsio);
-
- rid = 4;
- bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x4be, 1);
- fdc->res_fdemsio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
- 1, RF_ACTIVE);
- if (fdc->res_fdemsio == 0)
- return ENXIO;
- fdc->sc_fdemsiot = rman_get_bustag(fdc->res_fdemsio);
- fdc->sc_fdemsioh = rman_get_bushandle(fdc->res_fdemsio);
-#endif
-
-#ifndef PC98
- if (!ispcmcia) {
- /*
- * Some BIOSen report the device at 0x3f2-0x3f5,0x3f7
- * and some at 0x3f0-0x3f5,0x3f7. We detect the former
- * by checking the size and adjust the port address
- * accordingly.
- */
- if (bus_get_resource_count(dev, SYS_RES_IOPORT, 0) == 4)
- fdc->port_off = -2;
-
- /*
- * Register the control port range as rid 1 if it
- * isn't there already. Most PnP BIOSen will have
- * already done this but non-PnP configurations don't.
- *
- * And some (!!) report 0x3f2-0x3f5 and completely
- * leave out the control register! It seems that some
- * non-antique controller chips have a different
- * method of programming the transfer speed which
- * doesn't require the control register, but it's
- * mighty bogus as the chip still responds to the
- * address for the control register.
- */
- if (bus_get_resource_count(dev, SYS_RES_IOPORT, 1) == 0) {
- u_long ctlstart;
-
- /* Find the control port, usually 0x3f7 */
- ctlstart = rman_get_start(fdc->res_ioport) +
- fdc->port_off + 7;
-
- bus_set_resource(dev, SYS_RES_IOPORT, 1, ctlstart, 1);
- }
-
- /*
- * Now (finally!) allocate the control port.
- */
- fdc->rid_ctl = 1;
- fdc->res_ctl = bus_alloc_resource(dev, SYS_RES_IOPORT,
- &fdc->rid_ctl,
- 0ul, ~0ul, 1, RF_ACTIVE);
- if (fdc->res_ctl == 0) {
- device_printf(dev,
- "cannot reserve control I/O port range (control port)\n");
- return ENXIO;
- }
- fdc->ctlt = rman_get_bustag(fdc->res_ctl);
- fdc->ctlh = rman_get_bushandle(fdc->res_ctl);
- }
-#endif
-
- fdc->res_irq = bus_alloc_resource(dev, SYS_RES_IRQ,
- &fdc->rid_irq, 0ul, ~0ul, 1,
- RF_ACTIVE);
- if (fdc->res_irq == 0) {
- device_printf(dev, "cannot reserve interrupt line\n");
- return ENXIO;
- }
-
- if ((fdc->flags & FDC_NODMA) == 0) {
- fdc->res_drq = bus_alloc_resource(dev, SYS_RES_DRQ,
- &fdc->rid_drq, 0ul, ~0ul, 1,
- RF_ACTIVE);
- if (fdc->res_drq == 0) {
- device_printf(dev, "cannot reserve DMA request line\n");
- return ENXIO;
- }
- fdc->dmachan = fdc->res_drq->r_start;
- }
-
- return 0;
-}
-
-static void
-fdc_release_resources(struct fdc_data *fdc)
-{
- device_t dev;
-
- dev = fdc->fdc_dev;
- if (fdc->res_irq != 0) {
- bus_deactivate_resource(dev, SYS_RES_IRQ, fdc->rid_irq,
- fdc->res_irq);
- bus_release_resource(dev, SYS_RES_IRQ, fdc->rid_irq,
- fdc->res_irq);
- }
-#ifndef PC98
- if (fdc->res_ctl != 0) {
- bus_deactivate_resource(dev, SYS_RES_IOPORT, fdc->rid_ctl,
- fdc->res_ctl);
- bus_release_resource(dev, SYS_RES_IOPORT, fdc->rid_ctl,
- fdc->res_ctl);
- }
-#endif
-#ifdef PC98
- if (fdc->res_fdsio != 0) {
- bus_deactivate_resource(dev, SYS_RES_IOPORT, 3,
- fdc->res_fdsio);
- bus_release_resource(dev, SYS_RES_IOPORT, 3, fdc->res_fdsio);
- }
- if (fdc->res_fdemsio != 0) {
- bus_deactivate_resource(dev, SYS_RES_IOPORT, 4,
- fdc->res_fdemsio);
- bus_release_resource(dev, SYS_RES_IOPORT, 4, fdc->res_fdemsio);
- }
-#endif
- if (fdc->res_ioport != 0) {
- bus_deactivate_resource(dev, SYS_RES_IOPORT, fdc->rid_ioport,
- fdc->res_ioport);
- bus_release_resource(dev, SYS_RES_IOPORT, fdc->rid_ioport,
- fdc->res_ioport);
- }
- if (fdc->res_drq != 0) {
- bus_deactivate_resource(dev, SYS_RES_DRQ, fdc->rid_drq,
- fdc->res_drq);
- bus_release_resource(dev, SYS_RES_DRQ, fdc->rid_drq,
- fdc->res_drq);
- }
-}
-
-/*
- * Configuration/initialization stuff, per controller.
- */
-
-static struct isa_pnp_id fdc_ids[] = {
- {0x0007d041, "PC standard floppy disk controller"}, /* PNP0700 */
- {0x0107d041, "Standard floppy controller supporting MS Device Bay Spec"}, /* PNP0701 */
- {0}
-};
-
-static int
-fdc_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
-{
- struct fdc_ivars *ivars = device_get_ivars(child);
-
- switch (which) {
- case FDC_IVAR_FDUNIT:
- *result = ivars->fdunit;
- break;
- default:
- return ENOENT;
- }
- return 0;
-}
-
-static int
-fdc_probe(device_t dev)
-{
-#ifdef PC98
- int error;
-#else
- int error, ic_type;
-#endif
- struct fdc_data *fdc;
-
- fdc = device_get_softc(dev);
- bzero(fdc, sizeof *fdc);
- fdc->fdc_dev = dev;
-#ifndef PC98
- fdc->fdctl_wr = fdctl_wr_isa;
-#endif
-
- /* Check pnp ids */
- error = ISA_PNP_PROBE(device_get_parent(dev), dev, fdc_ids);
- if (error == ENXIO)
- return ENXIO;
- if (error == 0)
- fdc->flags |= FDC_ISPNP;
-
- /* Attempt to allocate our resources for the duration of the probe */
- error = fdc_alloc_resources(fdc);
- if (error)
- goto out;
-
-#ifndef PC98
- /* First - lets reset the floppy controller */
- fdout_wr(fdc, 0);
- DELAY(100);
- fdout_wr(fdc, FDO_FRST);
-#endif
-
- /* see if it can handle a command */
-#ifdef PC98
- if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(4, 240),
- NE7_SPEC_2(2, 0), 0)) {
- error = ENXIO;
- goto out;
- }
-#else
- if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(3, 240),
- NE7_SPEC_2(2, 0), 0)) {
- error = ENXIO;
- goto out;
- }
-#endif
-
-#ifndef PC98
- if (fd_cmd(fdc, 1, NE7CMD_VERSION, 1, &ic_type) == 0) {
- ic_type = (u_char)ic_type;
- switch (ic_type) {
- case 0x80:
- device_set_desc(dev, "NEC 765 or clone");
- fdc->fdct = FDC_NE765;
- break;
- case 0x81: /* not mentioned in any hardware doc */
- case 0x90:
- device_set_desc(dev,
- "Enhanced floppy controller (i82077, NE72065 or clone)");
- fdc->fdct = FDC_ENHANCED;
- break;
- default:
- device_set_desc(dev, "Generic floppy controller");
- fdc->fdct = FDC_UNKNOWN;
- break;
- }
- }
-#endif
-
-out:
- fdc_release_resources(fdc);
- return (error);
-}
-
-#if NCARD > 0
-
-static int
-fdc_pccard_probe(device_t dev)
-{
- int error;
- struct fdc_data *fdc;
-
- fdc = device_get_softc(dev);
- bzero(fdc, sizeof *fdc);
- fdc->fdc_dev = dev;
-#ifndef PC98
- fdc->fdctl_wr = fdctl_wr_pcmcia;
-#endif
-
- fdc->flags |= FDC_ISPCMCIA | FDC_NODMA;
-
- /* Attempt to allocate our resources for the duration of the probe */
- error = fdc_alloc_resources(fdc);
- if (error)
- goto out;
-
-#ifndef PC98
- /* First - lets reset the floppy controller */
- fdout_wr(fdc, 0);
- DELAY(100);
- fdout_wr(fdc, FDO_FRST);
-#endif
-
- /* see if it can handle a command */
-#ifdef PC98
- if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(4, 240),
- NE7_SPEC_2(2, 0), 0)) {
- error = ENXIO;
- goto out;
- }
-#else
- if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(3, 240),
- NE7_SPEC_2(2, 0), 0)) {
- error = ENXIO;
- goto out;
- }
-#endif
-
- device_set_desc(dev, "Y-E Data PCMCIA floppy");
- fdc->fdct = FDC_NE765;
-
-out:
- fdc_release_resources(fdc);
- return (error);
-}
-
-#endif /* NCARD > 0 */
-
-static int
-fdc_detach(device_t dev)
-{
- struct fdc_data *fdc;
- int error;
-
- fdc = device_get_softc(dev);
-
- /* have our children detached first */
- if ((error = bus_generic_detach(dev)))
- return (error);
-
-#ifdef PC98
- /* reset controller, turn motor off */
- fdc_reset(fdc);
-#else
- /* reset controller, turn motor off */
- fdout_wr(fdc, 0);
-#endif
-
- if ((fdc->flags & FDC_NODMA) == 0)
- isa_dma_release(fdc->dmachan);
-
- if ((fdc->flags & FDC_ATTACHED) == 0) {
- device_printf(dev, "already unloaded\n");
- return (0);
- }
- fdc->flags &= ~FDC_ATTACHED;
-
- BUS_TEARDOWN_INTR(device_get_parent(dev), dev, fdc->res_irq,
- fdc->fdc_intr);
- fdc_release_resources(fdc);
- device_printf(dev, "unload\n");
- return (0);
-}
-
-/*
- * Add a child device to the fdc controller. It will then be probed etc.
- */
-static void
-fdc_add_child(device_t dev, const char *name, int unit)
-{
- int disabled, flags;
- struct fdc_ivars *ivar;
- device_t child;
-
- ivar = malloc(sizeof *ivar, M_DEVBUF /* XXX */, M_NOWAIT | M_ZERO);
- if (ivar == NULL)
- return;
- if (resource_int_value(name, unit, "drive", &ivar->fdunit) != 0)
- ivar->fdunit = 0;
- child = device_add_child(dev, name, unit);
- if (child == NULL) {
- free(ivar, M_DEVBUF);
- return;
- }
- device_set_ivars(child, ivar);
- if (resource_int_value(name, unit, "flags", &flags) == 0)
- device_set_flags(child, flags);
- if (resource_int_value(name, unit, "disabled", &disabled) == 0
- && disabled != 0)
- device_disable(child);
-}
-
-static int
-fdc_attach(device_t dev)
-{
- struct fdc_data *fdc;
- const char *name, *dname;
- int i, error, dunit;
-
- fdc = device_get_softc(dev);
- error = fdc_alloc_resources(fdc);
- if (error) {
- device_printf(dev, "cannot re-acquire resources\n");
- return error;
- }
- error = BUS_SETUP_INTR(device_get_parent(dev), dev, fdc->res_irq,
- INTR_TYPE_BIO | INTR_ENTROPY, fdc_intr, fdc,
- &fdc->fdc_intr);
- if (error) {
- device_printf(dev, "cannot setup interrupt\n");
- return error;
- }
- fdc->fdcu = device_get_unit(dev);
- fdc->flags |= FDC_ATTACHED | FDC_NEEDS_RESET;
-
- if ((fdc->flags & FDC_NODMA) == 0) {
- /*
- * Acquire the DMA channel forever, the driver will do
- * the rest
- * XXX should integrate with rman
- */
- isa_dma_acquire(fdc->dmachan);
- isa_dmainit(fdc->dmachan, MAX_SEC_SIZE);
- }
- fdc->state = DEVIDLE;
-
-#ifdef PC98
- /* reset controller, turn motor off, clear fdout mirror reg */
- fdc_reset(fdc);
-#else
- /* reset controller, turn motor off, clear fdout mirror reg */
- fdout_wr(fdc, fdc->fdout = 0);
-#endif
- bioq_init(&fdc->head);
-
- /*
- * Probe and attach any children. We should probably detect
- * devices from the BIOS unless overridden.
- */
- name = device_get_nameunit(dev);
- i = 0;
- while ((resource_find_match(&i, &dname, &dunit, "at", name)) == 0)
- fdc_add_child(dev, dname, dunit);
-
- if ((error = bus_generic_attach(dev)) != 0)
- return (error);
-
- return (0);
-}
-
-static int
-fdc_print_child(device_t me, device_t child)
-{
- int retval = 0, flags;
-
- retval += bus_print_child_header(me, child);
- retval += printf(" on %s drive %d", device_get_nameunit(me),
- fdc_get_fdunit(child));
- if ((flags = device_get_flags(me)) != 0)
- retval += printf(" flags %#x", flags);
- retval += printf("\n");
-
- return (retval);
-}
-
-static device_method_t fdc_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, fdc_probe),
- DEVMETHOD(device_attach, fdc_attach),
- DEVMETHOD(device_detach, fdc_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /* Bus interface */
- DEVMETHOD(bus_print_child, fdc_print_child),
- DEVMETHOD(bus_read_ivar, fdc_read_ivar),
- /* Our children never use any other bus interface methods. */
-
- { 0, 0 }
-};
-
-static driver_t fdc_driver = {
- "fdc",
- fdc_methods,
- sizeof(struct fdc_data)
-};
-
-DRIVER_MODULE(fdc, isa, fdc_driver, fdc_devclass, 0, 0);
-#ifndef PC98
-DRIVER_MODULE(fdc, acpi, fdc_driver, fdc_devclass, 0, 0);
-#endif
-
-#if NCARD > 0
-
-static device_method_t fdc_pccard_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, fdc_pccard_probe),
- DEVMETHOD(device_attach, fdc_attach),
- DEVMETHOD(device_detach, fdc_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /* Bus interface */
- DEVMETHOD(bus_print_child, fdc_print_child),
- DEVMETHOD(bus_read_ivar, fdc_read_ivar),
- /* Our children never use any other bus interface methods. */
-
- { 0, 0 }
-};
-
-static driver_t fdc_pccard_driver = {
- "fdc",
- fdc_pccard_methods,
- sizeof(struct fdc_data)
-};
-
-DRIVER_MODULE(fdc, pccard, fdc_pccard_driver, fdc_devclass, 0, 0);
-
-#endif /* NCARD > 0 */
-
-/*
- * Create a clone device upon request by devfs.
- */
-static void
-fd_clone(void *arg, char *name, int namelen, dev_t *dev)
-{
- struct fd_data *fd;
- int i, u;
- char *n;
- size_t l;
-
- fd = (struct fd_data *)arg;
- if (*dev != NODEV)
- return;
- if (dev_stdclone(name, &n, "fd", &u) != 2)
- return;
- if (u != fd->fdu)
- /* unit # mismatch */
- return;
- l = strlen(n);
- if (l == 1 && *n >= 'a' && *n <= 'h') {
- /*
- * Trailing letters a through h denote
- * pseudo-partitions. We don't support true
- * (UFS-style) partitions, so we just implement them
- * as symlinks if someone asks us nicely.
- */
- *dev = make_dev_alias(fd->masterdev, name);
- return;
- }
- if (l >= 2 && l <= 5 && *n == '.') {
- /*
- * Trailing numbers, preceded by a dot, denote
- * subdevices for different densities. Historically,
- * they have been named by density (like fd0.1440),
- * but we allow arbitrary numbers between 1 and 4
- * digits, so fd0.1 through fd0.15 are possible as
- * well.
- */
- for (i = 1; i < l; i++)
- if (n[i] < '0' || n[i] > '9')
- return;
- for (i = 0; i < NUMDENS - 1; i++)
- if (fd->clonedevs[i] == NODEV) {
- *dev = make_dev(&fd_cdevsw,
- FDNUMTOUNIT(u) + i + 1,
- UID_ROOT, GID_OPERATOR, 0640,
- name);
- fd->clonedevs[i] = *dev;
- return;
- }
- }
-}
-
-/*
- * Configuration/initialization, per drive.
- */
-static int
-fd_probe(device_t dev)
-{
- int i;
-#ifndef PC98
- u_int st0, st3;
-#endif
- struct fd_data *fd;
- struct fdc_data *fdc;
- fdsu_t fdsu;
- int flags;
-
- fdsu = *(int *)device_get_ivars(dev); /* xxx cheat a bit... */
- fd = device_get_softc(dev);
- fdc = device_get_softc(device_get_parent(dev));
- flags = device_get_flags(dev);
-
- bzero(fd, sizeof *fd);
- fd->dev = dev;
- fd->fdc = fdc;
- fd->fdsu = fdsu;
- fd->fdu = device_get_unit(dev);
- fd->flags = FD_UA; /* make sure fdautoselect() will be called */
-
- fd->type = FD_DTYPE(flags);
-#ifdef PC98
- if (fd->type == FDT_NONE && fd->fdu >= 0 && fd->fdu <= 3) {
- /* Look up what the BIOS thinks we have. */
- if ((PC98_SYSTEM_PARAMETER(0x5ae) >> fd->fdu) & 0x01)
- fd->type = FDT_144M;
-#ifdef EPSON_NRDISK
- else if ((PC98_SYSTEM_PARAMETER(0x55c) >> fd->fdu) & 0x01) {
- fd->type = FDT_12M;
- switch (epson_machine_id) {
- case 0x20:
- case 0x27:
- if ((PC98_SYSTEM_PARAMETER(0x488) >> fd->fdu)
- & 0x01) {
- if (nrd_check_ready()) {
- nrd_LED_on();
- nrdu = fd->fdu;
- } else {
- fd->type = FDT_NONE;
- }
- }
- break;
- }
- }
-#else /* !EPSON_NRDISK */
- else if ((PC98_SYSTEM_PARAMETER(0x55c) >> fd->fdu) & 0x01) {
- fd->type = FDT_12M;
- switch (epson_machine_id) {
- case 0x20:
- case 0x27:
- if ((PC98_SYSTEM_PARAMETER(0x488) >> fd->fdu)
- & 0x01)
- fd->type = FDT_NONE;
- break;
- }
- }
-#endif /* EPSON_NRDISK */
- }
-#else /* PC98 */
-/*
- * XXX I think using __i386__ is wrong here since we actually want to probe
- * for the machine type, not the CPU type (so non-PC arch's like the PC98 will
- * fail the probe). However, for whatever reason, testing for _MACHINE_ARCH
- * == i386 breaks the test on FreeBSD/Alpha.
- */
-#ifdef __i386__
- if (fd->type == FDT_NONE && (fd->fdu == 0 || fd->fdu == 1)) {
- /* Look up what the BIOS thinks we have. */
- if (fd->fdu == 0) {
- if ((fdc->flags & FDC_ISPCMCIA))
- /*
- * Somewhat special. No need to force the
- * user to set device flags, since the Y-E
- * Data PCMCIA floppy is always a 1.44 MB
- * device.
- */
- fd->type = FDT_144M;
- else
- fd->type = (rtcin(RTC_FDISKETTE) & 0xf0) >> 4;
- } else {
- fd->type = rtcin(RTC_FDISKETTE) & 0x0f;
- }
- if (fd->type == FDT_288M_1)
- fd->type = FDT_288M;
- }
-#endif /* __i386__ */
-#endif /* PC98 */
-
- /* is there a unit? */
- if (fd->type == FDT_NONE)
- return (ENXIO);
-
-#ifndef PC98
- /* select it */
- set_motor(fdc, fdsu, TURNON);
- fdc_reset(fdc); /* XXX reset, then unreset, etc. */
- DELAY(1000000); /* 1 sec */
-
- /* XXX This doesn't work before the first set_motor() */
- if ((fdc->flags & FDC_HAS_FIFO) == 0 &&
- fdc->fdct == FDC_ENHANCED &&
- (device_get_flags(fdc->fdc_dev) & FDC_NO_FIFO) == 0 &&
- enable_fifo(fdc) == 0) {
- device_printf(device_get_parent(dev),
- "FIFO enabled, %d bytes threshold\n", fifo_threshold);
- }
-
- if ((flags & FD_NO_PROBE) == 0) {
- /* If we're at track 0 first seek inwards. */
- if ((fd_sense_drive_status(fdc, &st3) == 0) &&
- (st3 & NE7_ST3_T0)) {
- /* Seek some steps... */
- if (fd_cmd(fdc, 3, NE7CMD_SEEK, fdsu, 10, 0) == 0) {
- /* ...wait a moment... */
- DELAY(300000);
- /* make ctrlr happy: */
- fd_sense_int(fdc, 0, 0);
- }
- }
-
- for (i = 0; i < 2; i++) {
- /*
- * we must recalibrate twice, just in case the
- * heads have been beyond cylinder 76, since
- * most FDCs still barf when attempting to
- * recalibrate more than 77 steps
- */
- /* go back to 0: */
- if (fd_cmd(fdc, 2, NE7CMD_RECAL, fdsu, 0) == 0) {
- /* a second being enough for full stroke seek*/
- DELAY(i == 0 ? 1000000 : 300000);
-
- /* anything responding? */
- if (fd_sense_int(fdc, &st0, 0) == 0 &&
- (st0 & NE7_ST0_EC) == 0)
- break; /* already probed succesfully */
- }
- }
- }
-
- set_motor(fdc, fdsu, TURNOFF);
-
- if ((flags & FD_NO_PROBE) == 0 &&
- (st0 & NE7_ST0_EC) != 0) /* no track 0 -> no drive present */
- return (ENXIO);
-#endif /* PC98 */
-
-#ifdef PC98
- switch (fd->type) {
- case FDT_144M:
- /* Check 3mode I/F */
- fd->pc98_trans = 0;
- bus_space_write_1(fdc->sc_fdemsiot, fdc->sc_fdemsioh, 0,
- (fd->fdu << 5) | 0x10);
- if (!(bus_space_read_1(fdc->sc_fdemsiot, fdc->sc_fdemsioh, 0) &
- 0x01)) {
- device_set_desc(dev, "1.44M FDD");
- fd->type = FDT_144M;
- break;
- }
-
- device_printf(dev,
- "Warning: can't control 3mode I/F, fallback to 2mode.\n");
- /* FALLTHROUGH */
- case FDT_12M:
-#ifdef EPSON_NRDISK
- if (fd->fdu == nrdu) {
- device_set_desc(dev, "EPSON RAM DRIVE");
- nrd_LED_off();
- } else
- device_set_desc(dev, "1M/640K FDD");
-#else
- device_set_desc(dev, "1M/640K FDD");
-#endif
- fd->type = FDT_12M;
- break;
- default:
- return (ENXIO);
- }
-#else
- switch (fd->type) {
- case FDT_12M:
- device_set_desc(dev, "1200-KB 5.25\" drive");
- fd->type = FDT_12M;
- break;
- case FDT_144M:
- device_set_desc(dev, "1440-KB 3.5\" drive");
- fd->type = FDT_144M;
- break;
- case FDT_288M:
- device_set_desc(dev, "2880-KB 3.5\" drive (in 1440-KB mode)");
- fd->type = FDT_288M;
- break;
- case FDT_360K:
- device_set_desc(dev, "360-KB 5.25\" drive");
- fd->type = FDT_360K;
- break;
- case FDT_720K:
- device_set_desc(dev, "720-KB 3.5\" drive");
- fd->type = FDT_720K;
- break;
- default:
- return (ENXIO);
- }
-#endif
- fd->track = FD_NO_TRACK;
- fd->fdc = fdc;
- fd->fdsu = fdsu;
- fd->options = 0;
-#ifdef PC98
- fd->pc98_trans = 0;
-#endif
- callout_handle_init(&fd->toffhandle);
- callout_handle_init(&fd->tohandle);
-
- /* initialize densities for subdevices */
-#ifdef PC98
- for (i = 0; i < NUMDENS; i++)
- memcpy(fd->fts + i, fd_searchlist_144m + i,
- sizeof(struct fd_type));
-#else
- for (i = 0; i < NUMDENS; i++)
- memcpy(fd->fts + i, fd_native_types + fd->type,
- sizeof(struct fd_type));
-#endif
- return (0);
-}
-
-static int
-fd_attach(device_t dev)
-{
- struct fd_data *fd;
- int i;
-
- fd = device_get_softc(dev);
- fd->clonetag = EVENTHANDLER_REGISTER(dev_clone, fd_clone, fd, 1000);
- fd->masterdev = make_dev(&fd_cdevsw, fd->fdu << 6,
- UID_ROOT, GID_OPERATOR, 0640, "fd%d", fd->fdu);
- for (i = 0; i < NUMDENS - 1; i++)
- fd->clonedevs[i] = NODEV;
- fd->device_stats = devstat_new_entry(device_get_name(dev),
- device_get_unit(dev), 0, DEVSTAT_NO_ORDERED_TAGS,
- DEVSTAT_TYPE_FLOPPY | DEVSTAT_TYPE_IF_OTHER,
- DEVSTAT_PRIORITY_FD);
- return (0);
-}
-
-static int
-fd_detach(device_t dev)
-{
- struct fd_data *fd;
- int i;
-
- fd = device_get_softc(dev);
- untimeout(fd_turnoff, fd, fd->toffhandle);
- devstat_remove_entry(fd->device_stats);
- destroy_dev(fd->masterdev);
- for (i = 0; i < NUMDENS - 1; i++)
- if (fd->clonedevs[i] != NODEV)
- destroy_dev(fd->clonedevs[i]);
- EVENTHANDLER_DEREGISTER(dev_clone, fd->clonetag);
-
- return (0);
-}
-
-static device_method_t fd_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, fd_probe),
- DEVMETHOD(device_attach, fd_attach),
- DEVMETHOD(device_detach, fd_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend), /* XXX */
- DEVMETHOD(device_resume, bus_generic_resume), /* XXX */
-
- { 0, 0 }
-};
-
-static driver_t fd_driver = {
- "fd",
- fd_methods,
- sizeof(struct fd_data)
-};
-
-DRIVER_MODULE(fd, fdc, fd_driver, fd_devclass, 0, 0);
-
-/*
- * More auxiliary functions.
- */
-/*
- * Motor control stuff.
- * Remember to not deselect the drive we're working on.
- */
-static void
-set_motor(struct fdc_data *fdc, int fdsu, int turnon)
-{
-#ifdef PC98
- bus_space_write_1(fdc->sc_fdsiot, fdc->sc_fdsioh, 0,
- (pc98_trans != 1 ? FDP_FDDEXC : 0) | FDP_PORTEXC);
- DELAY(10);
- fdctl_wr(fdc, FDC_DMAE | FDC_MTON);
-#else
- int fdout;
-
- fdout = fdc->fdout;
- if (turnon) {
- fdout &= ~FDO_FDSEL;
- fdout |= (FDO_MOEN0 << fdsu) | FDO_FDMAEN | FDO_FRST | fdsu;
- } else
- fdout &= ~(FDO_MOEN0 << fdsu);
- fdc->fdout = fdout;
- fdout_wr(fdc, fdout);
- TRACE1("[0x%x->FDOUT]", fdout);
-#endif
-}
-
-static void
-fd_turnoff(void *xfd)
-{
- int s;
- fd_p fd = xfd;
-
- TRACE1("[fd%d: turnoff]", fd->fdu);
-
- s = splbio();
- /*
- * Don't turn off the motor yet if the drive is active.
- *
- * If we got here, this could only mean we missed an interrupt.
- * This can e. g. happen on the Y-E Date PCMCIA floppy controller
- * after a controller reset. Just schedule a pseudo-interrupt
- * so the state machine gets re-entered.
- */
- if (fd->fdc->state != DEVIDLE && fd->fdc->fdu == fd->fdu) {
- fdc_intr(fd->fdc);
- splx(s);
- return;
- }
-
- fd->flags &= ~FD_MOTOR;
- set_motor(fd->fdc, fd->fdsu, TURNOFF);
- splx(s);
-}
-
-static void
-fd_motor_on(void *xfd)
-{
- int s;
- fd_p fd = xfd;
-
- s = splbio();
- fd->flags &= ~FD_MOTOR_WAIT;
- if((fd->fdc->fd == fd) && (fd->fdc->state == MOTORWAIT))
- {
- fdc_intr(fd->fdc);
- }
- splx(s);
-}
-
-static void
-fd_turnon(fd_p fd)
-{
- if(!(fd->flags & FD_MOTOR))
- {
- fd->flags |= (FD_MOTOR + FD_MOTOR_WAIT);
- set_motor(fd->fdc, fd->fdsu, TURNON);
- timeout(fd_motor_on, fd, hz); /* in 1 sec its ok */
- }
-}
-
-static void
-fdc_reset(fdc_p fdc)
-{
- /* Try a reset, keep motor on */
-#ifdef PC98
- set_density(fdc);
- if (pc98_machine_type & M_EPSON_PC98)
- fdctl_wr(fdc, FDC_RST | FDC_RDY | FDC_DD | FDC_MTON);
- else
- fdctl_wr(fdc, FDC_RST | FDC_RDY | FDC_DMAE | FDC_MTON);
- DELAY(200);
- fdctl_wr(fdc, FDC_DMAE | FDC_MTON);
- DELAY(10);
-#else
- fdout_wr(fdc, fdc->fdout & ~(FDO_FRST|FDO_FDMAEN));
- TRACE1("[0x%x->FDOUT]", fdc->fdout & ~(FDO_FRST|FDO_FDMAEN));
- DELAY(100);
- /* enable FDC, but defer interrupts a moment */
- fdout_wr(fdc, fdc->fdout & ~FDO_FDMAEN);
- TRACE1("[0x%x->FDOUT]", fdc->fdout & ~FDO_FDMAEN);
- DELAY(100);
- fdout_wr(fdc, fdc->fdout);
- TRACE1("[0x%x->FDOUT]", fdc->fdout);
-#endif
-
- /* XXX after a reset, silently believe the FDC will accept commands */
-#ifdef PC98
- (void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
- NE7_SPEC_1(4, 240), NE7_SPEC_2(2, 0),
- 0);
-#else
- (void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
- NE7_SPEC_1(3, 240), NE7_SPEC_2(2, 0),
- 0);
-#endif
- if (fdc->flags & FDC_HAS_FIFO)
- (void) enable_fifo(fdc);
-}
-
-/*
- * FDC IO functions, take care of the main status register, timeout
- * in case the desired status bits are never set.
- *
- * These PIO loops initially start out with short delays between
- * each iteration in the expectation that the required condition
- * is usually met quickly, so it can be handled immediately. After
- * about 1 ms, stepping is increased to achieve a better timing
- * accuracy in the calls to DELAY().
- */
-static int
-fd_in(struct fdc_data *fdc, int *ptr)
-{
- int i, j, step;
-
- for (j = 0, step = 1;
- (i = fdsts_rd(fdc) & (NE7_DIO|NE7_RQM)) != (NE7_DIO|NE7_RQM) &&
- j < FDSTS_TIMEOUT;
- j += step) {
- if (i == NE7_RQM)
- return (fdc_err(fdc, "ready for output in input\n"));
- if (j == 1000)
- step = 1000;
- DELAY(step);
- }
- if (j >= FDSTS_TIMEOUT)
- return (fdc_err(fdc, bootverbose? "input ready timeout\n": 0));
-#ifdef FDC_DEBUG
- i = fddata_rd(fdc);
- TRACE1("[FDDATA->0x%x]", (unsigned char)i);
- *ptr = i;
- return (0);
-#else /* !FDC_DEBUG */
- i = fddata_rd(fdc);
- if (ptr)
- *ptr = i;
- return (0);
-#endif /* FDC_DEBUG */
-}
-
-static int
-out_fdc(struct fdc_data *fdc, int x)
-{
- int i, j, step;
-
- for (j = 0, step = 1;
- (i = fdsts_rd(fdc) & (NE7_DIO|NE7_RQM)) != NE7_RQM &&
- j < FDSTS_TIMEOUT;
- j += step) {
- if (i == (NE7_DIO|NE7_RQM))
- return (fdc_err(fdc, "ready for input in output\n"));
- if (j == 1000)
- step = 1000;
- DELAY(step);
- }
- if (j >= FDSTS_TIMEOUT)
- return (fdc_err(fdc, bootverbose? "output ready timeout\n": 0));
-
- /* Send the command and return */
- fddata_wr(fdc, x);
- TRACE1("[0x%x->FDDATA]", x);
- return (0);
-}
-
-/*
- * Block device driver interface functions (interspersed with even more
- * auxiliary functions).
- */
-static int
-Fdopen(dev_t dev, int flags, int mode, struct thread *td)
-{
- fdu_t fdu = FDUNIT(minor(dev));
- int type = FDTYPE(minor(dev));
- fd_p fd;
- fdc_p fdc;
- int rv, unitattn, dflags;
-
- if ((fd = devclass_get_softc(fd_devclass, fdu)) == 0)
- return (ENXIO);
- fdc = fd->fdc;
- if ((fdc == NULL) || (fd->type == FDT_NONE))
- return (ENXIO);
- if (type > NUMDENS)
- return (ENXIO);
- dflags = device_get_flags(fd->dev);
- /*
- * This is a bit bogus. It's still possible that e. g. a
- * descriptor gets inherited to a child, but then it's at
- * least for the same subdevice. By checking FD_OPEN here, we
- * can ensure that a device isn't attempted to be opened with
- * different densities at the same time where the second open
- * could clobber the settings from the first one.
- */
- if (fd->flags & FD_OPEN)
- return (EBUSY);
-
-#ifdef PC98
- if (pc98_fd_check_ready(fdu) == -1)
- return(EIO);
-#endif
-
- if (type == 0) {
- if (flags & FNONBLOCK) {
- /*
- * Unfortunately, physio(9) discards its ioflag
- * argument, thus preventing us from seeing the
- * IO_NDELAY bit. So we need to keep track
- * ourselves.
- */
- fd->flags |= FD_NONBLOCK;
- fd->ft = 0;
- } else {
- /*
- * Figure out a unit attention condition.
- *
- * If UA has been forced, proceed.
- *
- * If motor is off, turn it on for a moment
- * and select our drive, in order to read the
- * UA hardware signal.
- *
- * If motor is on, and our drive is currently
- * selected, just read the hardware bit.
- *
- * If motor is on, but active for another
- * drive on that controller, we are lost. We
- * cannot risk to deselect the other drive, so
- * we just assume a forced UA condition to be
- * on the safe side.
- */
- unitattn = 0;
- if ((dflags & FD_NO_CHLINE) != 0 ||
- (fd->flags & FD_UA) != 0) {
- unitattn = 1;
- fd->flags &= ~FD_UA;
-#ifndef PC98
- } else if (fdc->fdout & (FDO_MOEN0 | FDO_MOEN1 |
- FDO_MOEN2 | FDO_MOEN3)) {
- if ((fdc->fdout & FDO_FDSEL) == fd->fdsu)
- unitattn = fdin_rd(fdc) & FDI_DCHG;
- else
- unitattn = 1;
- } else {
- set_motor(fdc, fd->fdsu, TURNON);
- unitattn = fdin_rd(fdc) & FDI_DCHG;
- set_motor(fdc, fd->fdsu, TURNOFF);
-#endif /* PC98 */
- }
- if (unitattn && (rv = fdautoselect(dev)) != 0)
- return (rv);
- }
- } else {
- fd->ft = fd->fts + type;
- }
- fd->flags |= FD_OPEN;
- /*
- * Clearing the DMA overrun counter at open time is a bit messy.
- * Since we're only managing one counter per controller, opening
- * the second drive could mess it up. Anyway, if the DMA overrun
- * condition is really persistent, it will eventually time out
- * still. OTOH, clearing it here will ensure we'll at least start
- * trying again after a previous (maybe even long ago) failure.
- * Also, this is merely a stop-gap measure only that should not
- * happen during normal operation, so we can tolerate it to be a
- * bit sloppy about this.
- */
- fdc->dma_overruns = 0;
-
- return 0;
-}
-
-static int
-fdclose(dev_t dev, int flags, int mode, struct thread *td)
-{
- fdu_t fdu = FDUNIT(minor(dev));
- struct fd_data *fd;
-
- fd = devclass_get_softc(fd_devclass, fdu);
- fd->flags &= ~(FD_OPEN | FD_NONBLOCK);
- fd->options &= ~(FDOPT_NORETRY | FDOPT_NOERRLOG | FDOPT_NOERROR);
-
- return (0);
-}
-
-static void
-fdstrategy(struct bio *bp)
-{
- long blknum, nblocks;
- int s;
- fdu_t fdu;
- fdc_p fdc;
- fd_p fd;
- size_t fdblk;
-
- fdu = FDUNIT(minor(bp->bio_dev));
- fd = devclass_get_softc(fd_devclass, fdu);
- if (fd == 0)
- panic("fdstrategy: buf for nonexistent device (%#lx, %#lx)",
- (u_long)major(bp->bio_dev), (u_long)minor(bp->bio_dev));
- fdc = fd->fdc;
- if (fd->type == FDT_NONE || fd->ft == 0) {
- bp->bio_error = ENXIO;
- bp->bio_flags |= BIO_ERROR;
- goto bad;
- }
- fdblk = 128 << (fd->ft->secsize);
- if (bp->bio_cmd != FDBIO_FORMAT && bp->bio_cmd != FDBIO_RDSECTID) {
- if (fd->flags & FD_NONBLOCK) {
- bp->bio_error = EAGAIN;
- bp->bio_flags |= BIO_ERROR;
- goto bad;
- }
- if (bp->bio_blkno < 0) {
- printf(
- "fd%d: fdstrat: bad request blkno = %lu, bcount = %ld\n",
- fdu, (u_long)bp->bio_blkno, bp->bio_bcount);
- bp->bio_error = EINVAL;
- bp->bio_flags |= BIO_ERROR;
- goto bad;
- }
- if ((bp->bio_bcount % fdblk) != 0) {
- bp->bio_error = EINVAL;
- bp->bio_flags |= BIO_ERROR;
- goto bad;
- }
- }
-
- /*
- * Set up block calculations.
- */
- if (bp->bio_blkno > 20000000) {
- /*
- * Reject unreasonably high block number, prevent the
- * multiplication below from overflowing.
- */
- bp->bio_error = EINVAL;
- bp->bio_flags |= BIO_ERROR;
- goto bad;
- }
- blknum = bp->bio_blkno * DEV_BSIZE / fdblk;
- nblocks = fd->ft->size;
- if (blknum + bp->bio_bcount / fdblk > nblocks) {
- if (blknum >= nblocks) {
- if (bp->bio_cmd == BIO_READ)
- bp->bio_resid = bp->bio_bcount;
- else {
- bp->bio_error = ENOSPC;
- bp->bio_flags |= BIO_ERROR;
- }
- goto bad; /* not always bad, but EOF */
- }
- bp->bio_bcount = (nblocks - blknum) * fdblk;
- }
- bp->bio_pblkno = blknum;
- s = splbio();
- bioq_disksort(&fdc->head, bp);
- untimeout(fd_turnoff, fd, fd->toffhandle); /* a good idea */
- devstat_start_transaction_bio(fd->device_stats, bp);
- device_busy(fd->dev);
- fdstart(fdc);
- splx(s);
- return;
-
-bad:
- biodone(bp);
-}
-
-/*
- * fdstart
- *
- * We have just queued something. If the controller is not busy
- * then simulate the case where it has just finished a command
- * So that it (the interrupt routine) looks on the queue for more
- * work to do and picks up what we just added.
- *
- * If the controller is already busy, we need do nothing, as it
- * will pick up our work when the present work completes.
- */
-static void
-fdstart(struct fdc_data *fdc)
-{
- int s;
-
- s = splbio();
- if(fdc->state == DEVIDLE)
- {
- fdc_intr(fdc);
- }
- splx(s);
-}
-
-static void
-fd_iotimeout(void *xfdc)
-{
- fdc_p fdc;
- int s;
-
- fdc = xfdc;
- TRACE1("fd%d[fd_iotimeout()]", fdc->fdu);
-
- /*
- * Due to IBM's brain-dead design, the FDC has a faked ready
- * signal, hardwired to ready == true. Thus, any command
- * issued if there's no diskette in the drive will _never_
- * complete, and must be aborted by resetting the FDC.
- * Many thanks, Big Blue!
- * The FDC must not be reset directly, since that would
- * interfere with the state machine. Instead, pretend that
- * the command completed but was invalid. The state machine
- * will reset the FDC and retry once.
- */
- s = splbio();
- fdc->status[0] = NE7_ST0_IC_IV;
- fdc->flags &= ~FDC_STAT_VALID;
- fdc->state = IOTIMEDOUT;
- fdc_intr(fdc);
- splx(s);
-}
-
-/* Just ensure it has the right spl. */
-static void
-fd_pseudointr(void *xfdc)
-{
- int s;
-
- s = splbio();
- fdc_intr(xfdc);
- splx(s);
-}
-
-/*
- * fdc_intr
- *
- * Keep calling the state machine until it returns a 0.
- * Always called at splbio.
- */
-static void
-fdc_intr(void *xfdc)
-{
- fdc_p fdc = xfdc;
- while(fdstate(fdc))
- ;
-}
-
-/*
- * Magic pseudo-DMA initialization for YE FDC. Sets count and
- * direction.
- */
-#define SET_BCDR(fdc,wr,cnt,port) \
- bus_space_write_1(fdc->portt, fdc->porth, fdc->port_off + port, \
- ((cnt)-1) & 0xff); \
- bus_space_write_1(fdc->portt, fdc->porth, fdc->port_off + port + 1, \
- ((wr ? 0x80 : 0) | ((((cnt)-1) >> 8) & 0x7f)));
-
-/*
- * fdcpio(): perform programmed IO read/write for YE PCMCIA floppy.
- */
-static int
-fdcpio(fdc_p fdc, long flags, caddr_t addr, u_int count)
-{
- u_char *cptr = (u_char *)addr;
-
- if (flags == BIO_READ) {
- if (fdc->state != PIOREAD) {
- fdc->state = PIOREAD;
- return(0);
- }
- SET_BCDR(fdc, 0, count, 0);
- bus_space_read_multi_1(fdc->portt, fdc->porth, fdc->port_off +
- FDC_YE_DATAPORT, cptr, count);
- } else {
- bus_space_write_multi_1(fdc->portt, fdc->porth, fdc->port_off +
- FDC_YE_DATAPORT, cptr, count);
- SET_BCDR(fdc, 0, count, 0);
- }
- return(1);
-}
-
-/*
- * Try figuring out the density of the media present in our device.
- */
-static int
-fdautoselect(dev_t dev)
-{
- fdu_t fdu;
- fd_p fd;
- struct fd_type *fdtp;
- struct fdc_readid id;
- int i, n, oopts, rv;
-
- fdu = FDUNIT(minor(dev));
- fd = devclass_get_softc(fd_devclass, fdu);
-
- switch (fd->type) {
- default:
- return (ENXIO);
-
-#ifndef PC98
- case FDT_360K:
- case FDT_720K:
- /* no autoselection on those drives */
- fd->ft = fd_native_types + fd->type;
- return (0);
-#endif
-
- case FDT_12M:
- fdtp = fd_searchlist_12m;
- n = sizeof fd_searchlist_12m / sizeof(struct fd_type);
- break;
-
- case FDT_144M:
- fdtp = fd_searchlist_144m;
- n = sizeof fd_searchlist_144m / sizeof(struct fd_type);
- break;
-
-#ifndef PC98
- case FDT_288M:
- fdtp = fd_searchlist_288m;
- n = sizeof fd_searchlist_288m / sizeof(struct fd_type);
- break;
-#endif
- }
-
- /*
- * Try reading sector ID fields, first at cylinder 0, head 0,
- * then at cylinder 2, head N. We don't probe cylinder 1,
- * since for 5.25in DD media in a HD drive, there are no data
- * to read (2 step pulses per media cylinder required). For
- * two-sided media, the second probe always goes to head 1, so
- * we can tell them apart from single-sided media. As a
- * side-effect this means that single-sided media should be
- * mentioned in the search list after two-sided media of an
- * otherwise identical density. Media with a different number
- * of sectors per track but otherwise identical parameters
- * cannot be distinguished at all.
- *
- * If we successfully read an ID field on both cylinders where
- * the recorded values match our expectation, we are done.
- * Otherwise, we try the next density entry from the table.
- *
- * Stepping to cylinder 2 has the side-effect of clearing the
- * unit attention bit.
- */
- oopts = fd->options;
- fd->options |= FDOPT_NOERRLOG | FDOPT_NORETRY;
- for (i = 0; i < n; i++, fdtp++) {
- fd->ft = fdtp;
-
- id.cyl = id.head = 0;
- rv = fdmisccmd(dev, FDBIO_RDSECTID, &id);
- if (rv != 0)
- continue;
- if (id.cyl != 0 || id.head != 0 ||
- id.secshift != fdtp->secsize)
- continue;
- id.cyl = 2;
- id.head = fd->ft->heads - 1;
- rv = fdmisccmd(dev, FDBIO_RDSECTID, &id);
- if (id.cyl != 2 || id.head != fdtp->heads - 1 ||
- id.secshift != fdtp->secsize)
- continue;
- if (rv == 0)
- break;
- }
-
- fd->options = oopts;
- if (i == n) {
- if (bootverbose)
- device_printf(fd->dev, "autoselection failed\n");
- fd->ft = 0;
- return (EIO);
- } else {
- if (bootverbose)
- device_printf(fd->dev, "autoselected %d KB medium\n",
- fd->ft->size / 2);
- return (0);
- }
-}
-
-
-/*
- * The controller state machine.
- *
- * If it returns a non zero value, it should be called again immediately.
- */
-static int
-fdstate(fdc_p fdc)
-{
- struct fdc_readid *idp;
- int read, format, rdsectid, cylinder, head, i, sec = 0, sectrac;
- int st0, cyl, st3, idf, ne7cmd, mfm, steptrac;
- unsigned long blknum;
- fdu_t fdu = fdc->fdu;
- fd_p fd;
- register struct bio *bp;
- struct fd_formb *finfo = NULL;
- size_t fdblk;
-
- bp = fdc->bp;
- if (bp == NULL) {
- bp = bioq_first(&fdc->head);
- if (bp != NULL) {
- bioq_remove(&fdc->head, bp);
- fdc->bp = bp;
- }
- }
- if (bp == NULL) {
- /*
- * Nothing left for this controller to do,
- * force into the IDLE state.
- */
- fdc->state = DEVIDLE;
- if (fdc->fd) {
- device_printf(fdc->fdc_dev,
- "unexpected valid fd pointer\n");
- fdc->fd = (fd_p) 0;
- fdc->fdu = -1;
- }
- TRACE1("[fdc%d IDLE]", fdc->fdcu);
- return (0);
- }
- fdu = FDUNIT(minor(bp->bio_dev));
- fd = devclass_get_softc(fd_devclass, fdu);
- fdblk = 128 << fd->ft->secsize;
- if (fdc->fd && (fd != fdc->fd))
- device_printf(fd->dev, "confused fd pointers\n");
- read = bp->bio_cmd == BIO_READ;
- mfm = (fd->ft->flags & FL_MFM)? NE7CMD_MFM: 0;
- steptrac = (fd->ft->flags & FL_2STEP)? 2: 1;
- if (read)
- idf = ISADMA_READ;
- else
- idf = ISADMA_WRITE;
- format = bp->bio_cmd == FDBIO_FORMAT;
- rdsectid = bp->bio_cmd == FDBIO_RDSECTID;
- if (format)
- finfo = (struct fd_formb *)bp->bio_data;
- TRACE1("fd%d", fdu);
- TRACE1("[%s]", fdstates[fdc->state]);
- TRACE1("(0x%x)", fd->flags);
- untimeout(fd_turnoff, fd, fd->toffhandle);
- fd->toffhandle = timeout(fd_turnoff, fd, 4 * hz);
- switch (fdc->state)
- {
- case DEVIDLE:
- case FINDWORK: /* we have found new work */
- fdc->retry = 0;
- fd->skip = 0;
- fdc->fd = fd;
- fdc->fdu = fdu;
-#ifdef PC98
- pc98_trans = fd->ft->trans;
- if (pc98_trans_prev != pc98_trans) {
- int i;
- set_density(fdc);
- for (i = 0; i < 10; i++) {
- outb(0x5f, 0);
- outb(0x5f, 0);
- }
- pc98_trans_prev = pc98_trans;
- }
- if (pc98_trans != fd->pc98_trans) {
- if (fd->type == FDT_144M) {
- bus_space_write_1(fdc->sc_fdemsiot,
- fdc->sc_fdemsioh,
- 0,
- (fdu << 5) | 0x10 |
- (pc98_trans >> 1));
- outb(0x5f, 0);
- outb(0x5f, 0);
- }
- fd->pc98_trans = pc98_trans;
- }
-#else
- fdc->fdctl_wr(fdc, fd->ft->trans);
-#endif
- TRACE1("[0x%x->FDCTL]", fd->ft->trans);
- /*
- * If the next drive has a motor startup pending, then
- * it will start up in its own good time.
- */
- if(fd->flags & FD_MOTOR_WAIT) {
- fdc->state = MOTORWAIT;
- return (0); /* will return later */
- }
- /*
- * Maybe if it's not starting, it SHOULD be starting.
- */
-#ifdef EPSON_NRDISK
- if (fdu != nrdu) {
- if (!(fd->flags & FD_MOTOR))
- {
- fdc->state = MOTORWAIT;
- fd_turnon(fdu);
- return(0);
- }
- else /* at least make sure we are selected */
- {
- set_motor(fdcu, fd->fdsu, TURNON);
- }
- }
-#else /* !EPSON_NRDISK */
- if (!(fd->flags & FD_MOTOR))
- {
- fdc->state = MOTORWAIT;
- fd_turnon(fd);
- return (0); /* will return later */
- }
- else /* at least make sure we are selected */
- {
- set_motor(fdc, fd->fdsu, TURNON);
- }
-#endif
- if (fdc->flags & FDC_NEEDS_RESET) {
- fdc->state = RESETCTLR;
- fdc->flags &= ~FDC_NEEDS_RESET;
- } else
- fdc->state = DOSEEK;
- return (1); /* will return immediately */
-
- case DOSEEK:
-#ifdef PC98
- blknum = bp->bio_pblkno * DEV_BSIZE / fdblk + fd->skip / fdblk;
-#else
- blknum = bp->bio_pblkno + fd->skip / fdblk;
-#endif
- cylinder = blknum / (fd->ft->sectrac * fd->ft->heads);
- if (cylinder == fd->track)
- {
- fdc->state = SEEKCOMPLETE;
- return (1); /* will return immediately */
- }
-#ifdef PC98
- pc98_fd_check_ready(fdu);
-#endif
- if (fd_cmd(fdc, 3, NE7CMD_SEEK,
- fd->fdsu, cylinder * steptrac, 0))
- {
- /*
- * Seek command not accepted, looks like
- * the FDC went off to the Saints...
- */
- fdc->retry = 6; /* try a reset */
- return(retrier(fdc));
- }
- fd->track = FD_NO_TRACK;
- fdc->state = SEEKWAIT;
- return(0); /* will return later */
-
- case SEEKWAIT:
- /* allow heads to settle */
- timeout(fd_pseudointr, fdc, hz / 16);
- fdc->state = SEEKCOMPLETE;
- return(0); /* will return later */
-
- case SEEKCOMPLETE : /* seek done, start DMA */
-#ifdef PC98
- blknum = bp->bio_pblkno * DEV_BSIZE / fdblk + fd->skip / fdblk;
-#else
- blknum = bp->bio_pblkno + fd->skip / fdblk;
-#endif
- cylinder = blknum / (fd->ft->sectrac * fd->ft->heads);
-
- /* Make sure seek really happened. */
- if(fd->track == FD_NO_TRACK) {
- int descyl = cylinder * steptrac;
- do {
- /*
- * This might be a "ready changed" interrupt,
- * which cannot really happen since the
- * RDY pin is hardwired to + 5 volts. This
- * generally indicates a "bouncing" intr
- * line, so do one of the following:
- *
- * When running on an enhanced FDC that is
- * known to not go stuck after responding
- * with INVALID, fetch all interrupt states
- * until seeing either an INVALID or a
- * real interrupt condition.
- *
- * When running on a dumb old NE765, give
- * up immediately. The controller will
- * provide up to four dummy RC interrupt
- * conditions right after reset (for the
- * corresponding four drives), so this is
- * our only chance to get notice that it
- * was not the FDC that caused the interrupt.
- */
- if (fd_sense_int(fdc, &st0, &cyl)
- == FD_NOT_VALID)
- return (0); /* will return later */
- if(fdc->fdct == FDC_NE765
- && (st0 & NE7_ST0_IC) == NE7_ST0_IC_RC)
- return (0); /* hope for a real intr */
- } while ((st0 & NE7_ST0_IC) == NE7_ST0_IC_RC);
-
- if (0 == descyl) {
- int failed = 0;
- /*
- * seek to cyl 0 requested; make sure we are
- * really there
- */
- if (fd_sense_drive_status(fdc, &st3))
- failed = 1;
-#ifdef EPSON_NRDISK
- if (fdu == nrdu) st3 = NE7_ST3_T0;
-#endif /* EPSON_NRDISK */
- if ((st3 & NE7_ST3_T0) == 0) {
- printf(
- "fd%d: Seek to cyl 0, but not really there (ST3 = %b)\n",
- fdu, st3, NE7_ST3BITS);
- failed = 1;
- }
-
- if (failed) {
- if(fdc->retry < 3)
- fdc->retry = 3;
- return (retrier(fdc));
- }
- }
-#ifdef EPSON_NRDISK
- if (fdu == nrdu) cyl = descyl;
-#endif
-
- if (cyl != descyl) {
- printf(
- "fd%d: Seek to cyl %d failed; am at cyl %d (ST0 = 0x%x)\n",
- fdu, descyl, cyl, st0);
- if (fdc->retry < 3)
- fdc->retry = 3;
- return (retrier(fdc));
- }
- }
-
- fd->track = cylinder;
- if (format)
- fd->skip = (char *)&(finfo->fd_formb_cylno(0))
- - (char *)finfo;
-#ifdef EPSON_NRDISK
- if (fdu != nrdu) {
-#endif /* EPSON_NRDISK */
- if (!rdsectid && !(fdc->flags & FDC_NODMA))
- isa_dmastart(idf, bp->bio_data+fd->skip,
- format ? bp->bio_bcount : fdblk, fdc->dmachan);
-#ifdef PC98
- blknum = bp->bio_pblkno * DEV_BSIZE / fdblk + fd->skip / fdblk;
-#else
- blknum = bp->bio_pblkno + fd->skip / fdblk;
-#endif
- sectrac = fd->ft->sectrac;
- sec = blknum % (sectrac * fd->ft->heads);
- head = sec / sectrac;
- sec = sec % sectrac + 1;
- if (head != 0 && fd->ft->offset_side2 != 0)
- sec += fd->ft->offset_side2;
- fd->hddrv = ((head&1)<<2)+fdu;
-
- if(format || !(read || rdsectid))
- {
- /* make sure the drive is writable */
- if(fd_sense_drive_status(fdc, &st3) != 0)
- {
- /* stuck controller? */
- if (!(fdc->flags & FDC_NODMA))
- isa_dmadone(idf,
- bp->bio_data + fd->skip,
- format ? bp->bio_bcount : fdblk,
- fdc->dmachan);
- fdc->retry = 6; /* reset the beast */
- return (retrier(fdc));
- }
- if(st3 & NE7_ST3_WP)
- {
- /*
- * XXX YES! this is ugly.
- * in order to force the current operation
- * to fail, we will have to fake an FDC
- * error - all error handling is done
- * by the retrier()
- */
- fdc->status[0] = NE7_ST0_IC_AT;
- fdc->status[1] = NE7_ST1_NW;
- fdc->status[2] = 0;
- fdc->status[3] = fd->track;
- fdc->status[4] = head;
- fdc->status[5] = sec;
- fdc->retry = 8; /* break out immediately */
- fdc->state = IOTIMEDOUT; /* not really... */
- return (1); /* will return immediately */
- }
- }
-
- if (format) {
- ne7cmd = NE7CMD_FORMAT | mfm;
- if (fdc->flags & FDC_NODMA) {
- /*
- * This seems to be necessary for
- * whatever obscure reason; if we omit
- * it, we end up filling the sector ID
- * fields of the newly formatted track
- * entirely with garbage, causing
- * `wrong cylinder' errors all over
- * the place when trying to read them
- * back.
- *
- * Umpf.
- */
- SET_BCDR(fdc, 1, bp->bio_bcount, 0);
-
- (void)fdcpio(fdc,bp->bio_cmd,
- bp->bio_data+fd->skip,
- bp->bio_bcount);
-
- }
- /* formatting */
- if(fd_cmd(fdc, 6, ne7cmd, head << 2 | fdu,
- finfo->fd_formb_secshift,
- finfo->fd_formb_nsecs,
- finfo->fd_formb_gaplen,
- finfo->fd_formb_fillbyte, 0)) {
- /* controller fell over */
- if (!(fdc->flags & FDC_NODMA))
- isa_dmadone(idf,
- bp->bio_data + fd->skip,
- format ? bp->bio_bcount : fdblk,
- fdc->dmachan);
- fdc->retry = 6;
- return (retrier(fdc));
- }
- } else if (rdsectid) {
- ne7cmd = NE7CMD_READID | mfm;
- if (fd_cmd(fdc, 2, ne7cmd, head << 2 | fdu, 0)) {
- /* controller jamming */
- fdc->retry = 6;
- return (retrier(fdc));
- }
- } else {
- /* read or write operation */
- ne7cmd = (read ? NE7CMD_READ | NE7CMD_SK : NE7CMD_WRITE) | mfm;
- if (fdc->flags & FDC_NODMA) {
- /*
- * This seems to be necessary even when
- * reading data.
- */
- SET_BCDR(fdc, 1, fdblk, 0);
-
- /*
- * Perform the write pseudo-DMA before
- * the WRITE command is sent.
- */
- if (!read)
- (void)fdcpio(fdc,bp->bio_cmd,
- bp->bio_data+fd->skip,
- fdblk);
- }
- if (fd_cmd(fdc, 9,
- ne7cmd,
- head << 2 | fdu, /* head & unit */
- fd->track, /* track */
- head,
- sec, /* sector + 1 */
- fd->ft->secsize, /* sector size */
- sectrac, /* sectors/track */
- fd->ft->gap, /* gap size */
- fd->ft->datalen, /* data length */
- 0)) {
- /* the beast is sleeping again */
- if (!(fdc->flags & FDC_NODMA))
- isa_dmadone(idf,
- bp->bio_data + fd->skip,
- format ? bp->bio_bcount : fdblk,
- fdc->dmachan);
- fdc->retry = 6;
- return (retrier(fdc));
- }
- }
- if (!rdsectid && (fdc->flags & FDC_NODMA))
- /*
- * If this is a read, then simply await interrupt
- * before performing PIO.
- */
- if (read && !fdcpio(fdc,bp->bio_cmd,
- bp->bio_data+fd->skip,fdblk)) {
- fd->tohandle = timeout(fd_iotimeout, fdc, hz);
- return(0); /* will return later */
- }
-
- /*
- * Write (or format) operation will fall through and
- * await completion interrupt.
- */
- fdc->state = IOCOMPLETE;
- fd->tohandle = timeout(fd_iotimeout, fdc, hz);
- return (0); /* will return later */
-#ifdef EPSON_NRDISK
- }
- else {
- nrdblkn = (nrd_t)((unsigned long)bp->b_blkno*DEV_BSIZE/fdblk
- + fd->skip/fdblk);
- nrd_LED_on();
- nrd_addrset(fdblk * nrdblkn);
- while (!nrd_check_ready()) DELAY(1);
- if (read) epson_insw(P_NRD_DATA,
- bp->bio_data + fd->skip,
- fdblk / sizeof(short));
- else epson_outsw(P_NRD_DATA,
- bp->bio_data + fd->skip,
- (format ? bp->bio_bcount : fdblk)
- / sizeof(short));
-
- blknum = (unsigned long)bp->b_blkno*DEV_BSIZE/fdblk
- + fd->skip/fdblk;
- sectrac = fd->ft->sectrac;
- sec = blknum % (sectrac * fd->ft->heads);
- head = sec / sectrac;
- sec = sec % sectrac + 1;
- fd->hddrv = ((head&1)<<2)+fdu;
-
- if (nrdsec++ >= nrd_sec())
- nrdaddr = (nrd_t)(fd->track * 8 + head * 4);
- nrdsec = sec;
- fdc->state = IOCOMPLETE;
- }
-#endif
-
- case PIOREAD:
- /*
- * Actually perform the PIO read. The IOCOMPLETE case
- * removes the timeout for us.
- */
- (void)fdcpio(fdc,bp->bio_cmd,bp->bio_data+fd->skip,fdblk);
- fdc->state = IOCOMPLETE;
- /* FALLTHROUGH */
- case IOCOMPLETE: /* IO done, post-analyze */
-#ifdef EPSON_NRDISK
- if (fdu != nrdu)
- untimeout(fd_iotimeout, fdc, fd->tohandle);
-#else
- untimeout(fd_iotimeout, fdc, fd->tohandle);
-#endif
-
- if (fd_read_status(fdc)) {
- if (!rdsectid && !(fdc->flags & FDC_NODMA))
- isa_dmadone(idf, bp->bio_data + fd->skip,
- format ? bp->bio_bcount : fdblk,
- fdc->dmachan);
- if (fdc->retry < 6)
- fdc->retry = 6; /* force a reset */
- return (retrier(fdc));
- }
-
- fdc->state = IOTIMEDOUT;
-
- /* FALLTHROUGH */
- case IOTIMEDOUT:
-#ifdef EPSON_NRDISK
- if (fdu != nrdu) {
-#endif /* EPSON_NRDISK */
- if (!rdsectid && !(fdc->flags & FDC_NODMA))
- isa_dmadone(idf, bp->bio_data + fd->skip,
- format ? bp->bio_bcount : fdblk, fdc->dmachan);
-#ifdef EPSON_NRDISK
- }
- else nrd_LED_off();
-#endif /* EPSON_NRDISK */
- if (fdc->status[0] & NE7_ST0_IC) {
- if ((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_AT
- && fdc->status[1] & NE7_ST1_OR) {
- /*
- * DMA overrun. Someone hogged the bus and
- * didn't release it in time for the next
- * FDC transfer.
- *
- * We normally restart this without bumping
- * the retry counter. However, in case
- * something is seriously messed up (like
- * broken hardware), we rather limit the
- * number of retries so the IO operation
- * doesn't block indefinately.
- */
- if (fdc->dma_overruns++ < FDC_DMAOV_MAX) {
- fdc->state = SEEKCOMPLETE;
- return (1);/* will return immediately */
- } /* else fall through */
- }
- if((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_IV
- && fdc->retry < 6)
- fdc->retry = 6; /* force a reset */
- else if((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_AT
- && fdc->status[2] & NE7_ST2_WC
- && fdc->retry < 3)
- fdc->retry = 3; /* force recalibrate */
- return (retrier(fdc));
- }
- /* All OK */
- if (rdsectid) {
- /* copy out ID field contents */
- idp = (struct fdc_readid *)bp->bio_data;
- idp->cyl = fdc->status[3];
- idp->head = fdc->status[4];
- idp->sec = fdc->status[5];
- idp->secshift = fdc->status[6];
- }
- /* Operation successful, retry DMA overruns again next time. */
- fdc->dma_overruns = 0;
- fd->skip += fdblk;
- if (!rdsectid && !format && fd->skip < bp->bio_bcount) {
- /* set up next transfer */
- fdc->state = DOSEEK;
- } else {
- /* ALL DONE */
- fd->skip = 0;
- bp->bio_resid = 0;
- fdc->bp = NULL;
- device_unbusy(fd->dev);
- biofinish(bp, fd->device_stats, 0);
- fdc->fd = (fd_p) 0;
- fdc->fdu = -1;
- fdc->state = FINDWORK;
- }
- return (1); /* will return immediately */
-
- case RESETCTLR:
- fdc_reset(fdc);
- fdc->retry++;
- fdc->state = RESETCOMPLETE;
- return (0); /* will return later */
-
- case RESETCOMPLETE:
- /*
- * Discard all the results from the reset so that they
- * can't cause an unexpected interrupt later.
- */
- for (i = 0; i < 4; i++)
- (void)fd_sense_int(fdc, &st0, &cyl);
- fdc->state = STARTRECAL;
- /* FALLTHROUGH */
- case STARTRECAL:
-#ifdef PC98
- pc98_fd_check_ready(fdu);
-#endif
- if(fd_cmd(fdc, 2, NE7CMD_RECAL, fdu, 0)) {
- /* arrgl */
- fdc->retry = 6;
- return (retrier(fdc));
- }
- fdc->state = RECALWAIT;
- return (0); /* will return later */
-
- case RECALWAIT:
- /* allow heads to settle */
- timeout(fd_pseudointr, fdc, hz / 8);
- fdc->state = RECALCOMPLETE;
- return (0); /* will return later */
-
- case RECALCOMPLETE:
- do {
- /*
- * See SEEKCOMPLETE for a comment on this:
- */
- if (fd_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
- return (0); /* will return later */
- if(fdc->fdct == FDC_NE765
- && (st0 & NE7_ST0_IC) == NE7_ST0_IC_RC)
- return (0); /* hope for a real intr */
- } while ((st0 & NE7_ST0_IC) == NE7_ST0_IC_RC);
-#ifdef EPSON_NRDISK
- if (fdu == nrdu) {
- st0 = NE7_ST0_IC_NT;
- cyl = 0;
- }
-#endif
- if ((st0 & NE7_ST0_IC) != NE7_ST0_IC_NT || cyl != 0)
- {
- if(fdc->retry > 3)
- /*
- * A recalibrate from beyond cylinder 77
- * will "fail" due to the FDC limitations;
- * since people used to complain much about
- * the failure message, try not logging
- * this one if it seems to be the first
- * time in a line.
- */
- printf("fd%d: recal failed ST0 %b cyl %d\n",
- fdu, st0, NE7_ST0BITS, cyl);
- if(fdc->retry < 3) fdc->retry = 3;
- return (retrier(fdc));
- }
- fd->track = 0;
- /* Seek (probably) necessary */
- fdc->state = DOSEEK;
- return (1); /* will return immediately */
-
- case MOTORWAIT:
- if(fd->flags & FD_MOTOR_WAIT)
- {
- return (0); /* time's not up yet */
- }
- if (fdc->flags & FDC_NEEDS_RESET) {
- fdc->state = RESETCTLR;
- fdc->flags &= ~FDC_NEEDS_RESET;
- } else
- fdc->state = DOSEEK;
- return (1); /* will return immediately */
-
- default:
- device_printf(fdc->fdc_dev, "unexpected FD int->");
- if (fd_read_status(fdc) == 0)
- printf("FDC status :%x %x %x %x %x %x %x ",
- fdc->status[0],
- fdc->status[1],
- fdc->status[2],
- fdc->status[3],
- fdc->status[4],
- fdc->status[5],
- fdc->status[6] );
- else
- printf("No status available ");
- if (fd_sense_int(fdc, &st0, &cyl) != 0)
- {
- printf("[controller is dead now]\n");
- return (0); /* will return later */
- }
- printf("ST0 = %x, PCN = %x\n", st0, cyl);
- return (0); /* will return later */
- }
- /* noone should ever get here */
-}
-
-static int
-retrier(struct fdc_data *fdc)
-{
- struct bio *bp;
- struct fd_data *fd;
- int fdu;
-
- bp = fdc->bp;
-
- /* XXX shouldn't this be cached somewhere? */
- fdu = FDUNIT(minor(bp->bio_dev));
- fd = devclass_get_softc(fd_devclass, fdu);
- if (fd->options & FDOPT_NORETRY)
- goto fail;
-
- switch (fdc->retry) {
- case 0: case 1: case 2:
- fdc->state = SEEKCOMPLETE;
- break;
- case 3: case 4: case 5:
- fdc->state = STARTRECAL;
- break;
- case 6:
- fdc->state = RESETCTLR;
- break;
- case 7:
- break;
- default:
- fail:
- if ((fd->options & FDOPT_NOERRLOG) == 0) {
- disk_err(bp, "hard error",
- fdc->fd->skip / DEV_BSIZE, 0);
- if (fdc->flags & FDC_STAT_VALID) {
- printf(
- " (ST0 %b ST1 %b ST2 %b cyl %u hd %u sec %u)\n",
- fdc->status[0], NE7_ST0BITS,
- fdc->status[1], NE7_ST1BITS,
- fdc->status[2], NE7_ST2BITS,
- fdc->status[3], fdc->status[4],
- fdc->status[5]);
- }
- else
- printf(" (No status)\n");
- }
- if ((fd->options & FDOPT_NOERROR) == 0) {
- bp->bio_flags |= BIO_ERROR;
- bp->bio_error = EIO;
- bp->bio_resid = bp->bio_bcount - fdc->fd->skip;
- } else
- bp->bio_resid = 0;
- fdc->bp = NULL;
- fdc->fd->skip = 0;
- device_unbusy(fd->dev);
- biofinish(bp, fdc->fd->device_stats, 0);
- fdc->state = FINDWORK;
- fdc->flags |= FDC_NEEDS_RESET;
- fdc->fd = (fd_p) 0;
- fdc->fdu = -1;
- return (1);
- }
- fdc->retry++;
- return (1);
-}
-
-static void
-fdbiodone(struct bio *bp)
-{
- wakeup(bp);
-}
-
-static int
-fdmisccmd(dev_t dev, u_int cmd, void *data)
-{
- fdu_t fdu;
- fd_p fd;
- struct bio *bp;
- struct fd_formb *finfo;
- struct fdc_readid *idfield;
- size_t fdblk;
- int error;
-
- fdu = FDUNIT(minor(dev));
- fd = devclass_get_softc(fd_devclass, fdu);
- fdblk = 128 << fd->ft->secsize;
- finfo = (struct fd_formb *)data;
- idfield = (struct fdc_readid *)data;
-
- bp = malloc(sizeof(struct bio), M_TEMP, M_WAITOK | M_ZERO);
-
- /*
- * Set up a bio request for fdstrategy(). bio_blkno is faked
- * so that fdstrategy() will seek to the the requested
- * cylinder, and use the desired head.
- */
- bp->bio_cmd = cmd;
- if (cmd == FDBIO_FORMAT) {
- bp->bio_blkno =
- (finfo->cyl * (fd->ft->sectrac * fd->ft->heads) +
- finfo->head * fd->ft->sectrac) *
- fdblk / DEV_BSIZE;
- bp->bio_bcount = sizeof(struct fd_idfield_data) *
- finfo->fd_formb_nsecs;
- } else if (cmd == FDBIO_RDSECTID) {
- bp->bio_blkno =
- (idfield->cyl * (fd->ft->sectrac * fd->ft->heads) +
- idfield->head * fd->ft->sectrac) *
- fdblk / DEV_BSIZE;
- bp->bio_bcount = sizeof(struct fdc_readid);
- } else
- panic("wrong cmd in fdmisccmd()");
- bp->bio_data = data;
- bp->bio_dev = dev;
- bp->bio_done = fdbiodone;
- bp->bio_flags = 0;
-
- /* Now run the command. */
- fdstrategy(bp);
- error = biowait(bp, "fdcmd");
-
- free(bp, M_TEMP);
- return (error);
-}
-
-static int
-fdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
-{
- fdu_t fdu;
- fd_p fd;
- struct fdc_status *fsp;
- struct fdc_readid *rid;
- size_t fdblk;
- int error, type;
-
- fdu = FDUNIT(minor(dev));
- type = FDTYPE(minor(dev));
- fd = devclass_get_softc(fd_devclass, fdu);
-
-#ifdef PC98
- pc98_fd_check_ready(fdu);
-#endif
-
- /*
- * First, handle everything that could be done with
- * FD_NONBLOCK still being set.
- */
- switch (cmd) {
-
- case DIOCGMEDIASIZE:
- *(off_t *)addr = (128 << (fd->ft->secsize)) * fd->ft->size;
- return (0);
-
- case DIOCGSECTORSIZE:
- *(u_int *)addr = 128 << (fd->ft->secsize);
- return (0);
-
- case FIONBIO:
- if (*(int *)addr != 0)
- fd->flags |= FD_NONBLOCK;
- else {
- if (fd->ft == 0) {
- /*
- * No drive type has been selected yet,
- * cannot turn FNONBLOCK off.
- */
- return (EINVAL);
- }
- fd->flags &= ~FD_NONBLOCK;
- }
- return (0);
-
- case FIOASYNC:
- /* keep the generic fcntl() code happy */
- return (0);
-
- case FD_GTYPE: /* get drive type */
- if (fd->ft == 0)
- /* no type known yet, return the native type */
- *(struct fd_type *)addr = fd_native_types[fd->type];
- else
- *(struct fd_type *)addr = *fd->ft;
- return (0);
-
- case FD_STYPE: /* set drive type */
- if (type == 0) {
- /*
- * Allow setting drive type temporarily iff
- * currently unset. Used for fdformat so any
- * user can set it, and then start formatting.
- */
- if (fd->ft)
- return (EINVAL); /* already set */
- fd->ft = fd->fts;
- *fd->ft = *(struct fd_type *)addr;
- fd->flags |= FD_UA;
- } else {
- /*
- * Set density definition permanently. Only
- * allow for superuser.
- */
- if (suser(td) != 0)
- return (EPERM);
- fd->fts[type] = *(struct fd_type *)addr;
- }
- return (0);
-
- case FD_GOPTS: /* get drive options */
- *(int *)addr = fd->options + (type == 0? FDOPT_AUTOSEL: 0);
- return (0);
-
- case FD_SOPTS: /* set drive options */
- fd->options = *(int *)addr & ~FDOPT_AUTOSEL;
- return (0);
-
-#ifdef FDC_DEBUG
- case FD_DEBUG:
- if ((fd_debug != 0) != (*(int *)addr != 0)) {
- fd_debug = (*(int *)addr != 0);
- printf("fd%d: debugging turned %s\n",
- fd->fdu, fd_debug ? "on" : "off");
- }
- return (0);
-#endif
-
- case FD_CLRERR:
- if (suser(td) != 0)
- return (EPERM);
- fd->fdc->fdc_errs = 0;
- return (0);
-
- case FD_GSTAT:
- fsp = (struct fdc_status *)addr;
- if ((fd->fdc->flags & FDC_STAT_VALID) == 0)
- return (EINVAL);
- memcpy(fsp->status, fd->fdc->status, 7 * sizeof(u_int));
- return (0);
-
- case FD_GDTYPE:
- *(enum fd_drivetype *)addr = fd->type;
- return (0);
- }
-
- /*
- * Now handle everything else. Make sure we have a valid
- * drive type.
- */
- if (fd->flags & FD_NONBLOCK)
- return (EAGAIN);
- if (fd->ft == 0)
- return (ENXIO);
- fdblk = 128 << fd->ft->secsize;
- error = 0;
-
- switch (cmd) {
-
- case FD_FORM:
- if ((flag & FWRITE) == 0)
- return (EBADF); /* must be opened for writing */
- if (((struct fd_formb *)addr)->format_version !=
- FD_FORMAT_VERSION)
- return (EINVAL); /* wrong version of formatting prog */
- error = fdmisccmd(dev, FDBIO_FORMAT, addr);
- break;
-
- case FD_GTYPE: /* get drive type */
- *(struct fd_type *)addr = *fd->ft;
- break;
-
- case FD_STYPE: /* set drive type */
- /* this is considered harmful; only allow for superuser */
- if (suser(td) != 0)
- return (EPERM);
- *fd->ft = *(struct fd_type *)addr;
- break;
-
- case FD_GOPTS: /* get drive options */
- *(int *)addr = fd->options;
- break;
-
- case FD_SOPTS: /* set drive options */
- fd->options = *(int *)addr;
- break;
-
-#ifdef FDC_DEBUG
- case FD_DEBUG:
- if ((fd_debug != 0) != (*(int *)addr != 0)) {
- fd_debug = (*(int *)addr != 0);
- printf("fd%d: debugging turned %s\n",
- fd->fdu, fd_debug ? "on" : "off");
- }
- break;
-#endif
-
- case FD_CLRERR:
- if (suser(td) != 0)
- return (EPERM);
- fd->fdc->fdc_errs = 0;
- break;
-
- case FD_GSTAT:
- fsp = (struct fdc_status *)addr;
- if ((fd->fdc->flags & FDC_STAT_VALID) == 0)
- return (EINVAL);
- memcpy(fsp->status, fd->fdc->status, 7 * sizeof(u_int));
- break;
-
- case FD_READID:
- rid = (struct fdc_readid *)addr;
- if (rid->cyl > MAX_CYLINDER || rid->head > MAX_HEAD)
- return (EINVAL);
- error = fdmisccmd(dev, FDBIO_RDSECTID, addr);
- break;
-
- default:
- error = ENOTTY;
- break;
- }
- return (error);
-}
diff --git a/sys/pc98/cbus/fdcreg.h b/sys/pc98/cbus/fdcreg.h
deleted file mode 100644
index e1841c9b384a..000000000000
--- a/sys/pc98/cbus/fdcreg.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)fdreg.h 7.1 (Berkeley) 5/9/91
- * $FreeBSD$
- */
-
-/*
- * AT floppy controller registers and bitfields
- */
-
-/* uses NEC765 controller */
-#include <dev/ic/nec765.h>
-
-#ifdef PC98
-/* registers */
-#define FDSTS 0 /* NEC 765 Main Status Register (R) */
-#define FDDATA 1 /* NEC 765 Data Register (R/W) */
-#define FDCTL 2 /* FD Control Register */
-#define FDC_RST 0x80 /* FDC RESET */
-#define FDC_RDY 0x40 /* force READY */
-#define FDC_DD 0x20 /* FDD Mode Exchange 0:1M 1:640K */
-#define FDC_DMAE 0x10 /* enable floppy DMA */
-#define FDC_MTON 0x08 /* MOTOR ON (when EMTON=1)*/
-#define FDC_TMSK 0x04 /* TIMER MASK */
-#define FDC_TTRG 0x01 /* TIMER TRIGER */
-
-#define FDP_EMTON 0x04 /* enable MTON */
-#define FDP_FDDEXC 0x02 /* FDD Mode Exchange 1:1M 0:640K */
-#define FDP_PORTEXC 0x01 /* PORT Exchane 1:1M 0:640K */
-
-#else
-/* registers */
-#define FDOUT 2 /* Digital Output Register (W) */
-#define FDO_FDSEL 0x03 /* floppy device select */
-#define FDO_FRST 0x04 /* floppy controller reset */
-#define FDO_FDMAEN 0x08 /* enable floppy DMA and Interrupt */
-#define FDO_MOEN0 0x10 /* motor enable drive 0 */
-#define FDO_MOEN1 0x20 /* motor enable drive 1 */
-#define FDO_MOEN2 0x40 /* motor enable drive 2 */
-#define FDO_MOEN3 0x80 /* motor enable drive 3 */
-
-#define FDSTS 4 /* NEC 765 Main Status Register (R) */
-#define FDDATA 5 /* NEC 765 Data Register (R/W) */
-#define FDCTL 7 /* Control Register (W) */
-#endif /* PC98 */
-
-/*
- * The definitions for FDC_500KBPS etc. have been moved out to <sys/fdcio.h>
- * since they need to be visible in userland. They cover the lower two bits
- * of FDCTL when used for output.
- */
-/*
- * this is the secret PIO data port (offset from base)
- */
-#define FDC_YE_DATAPORT 6
-
-#ifndef PC98
-#define FDIN 7 /* Digital Input Register (R) */
-#define FDI_DCHG 0x80 /* diskette has been changed */
- /* requires drive and motor being selected */
- /* is cleared by any step pulse to drive */
-#endif
diff --git a/sys/pc98/cbus/gdc.c b/sys/pc98/cbus/gdc.c
deleted file mode 100644
index b6d302fd6d7e..000000000000
--- a/sys/pc98/cbus/gdc.c
+++ /dev/null
@@ -1,1443 +0,0 @@
-/*
- * Copyright (c) 1999 FreeBSD(98) port team.
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include "opt_gdc.h"
-#include "opt_fb.h"
-#include "opt_syscons.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/conf.h>
-#include <sys/bus.h>
-#include <machine/bus.h>
-#include <sys/rman.h>
-#include <machine/resource.h>
-
-#include <sys/fbio.h>
-#include <sys/fcntl.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-
-#include <machine/md_var.h>
-#include <machine/pc/bios.h>
-
-#include <dev/fb/fbreg.h>
-
-#ifdef LINE30
-#include <pc98/pc98/pc98.h>
-#endif
-#include <pc98/pc98/pc98_machdep.h>
-#include <isa/isavar.h>
-
-#define TEXT_GDC 0x60
-#define GRAPHIC_GDC 0xa0
-#define ROW 25
-#define COL 80
-
-#define DRIVER_NAME "gdc"
-
-/* cdev driver declaration */
-
-#define GDC_UNIT(dev) minor(dev)
-#define GDC_MKMINOR(unit) (unit)
-
-typedef struct gdc_softc {
- video_adapter_t *adp;
- struct resource *res_tgdc, *res_ggdc;
- struct resource *res_egc, *res_pegc, *res_grcg, *res_kcg;
- struct resource *res_tmem, *res_gmem1, *res_gmem2;
-#ifdef FB_INSTALL_CDEV
- genfb_softc_t gensc;
-#endif
-} gdc_softc_t;
-
-#define GDC_SOFTC(unit) \
- ((gdc_softc_t *)devclass_get_softc(gdc_devclass, unit))
-
-static bus_addr_t gdc_iat[] = {0, 2, 4, 6, 8, 10, 12, 14};
-
-static devclass_t gdc_devclass;
-
-static int gdc_probe_unit(int unit, gdc_softc_t *sc, int flags);
-static int gdc_attach_unit(int unit, gdc_softc_t *sc, int flags);
-static int gdc_alloc_resource(device_t dev);
-static int gdc_release_resource(device_t dev);
-
-#if FB_INSTALL_CDEV
-
-static d_open_t gdcopen;
-static d_close_t gdcclose;
-static d_read_t gdcread;
-static d_write_t gdcwrite;
-static d_ioctl_t gdcioctl;
-static d_mmap_t gdcmmap;
-
-static struct cdevsw gdc_cdevsw = {
- .d_open = gdcopen,
- .d_close = gdcclose,
- .d_read = gdcread,
- .d_write = gdcwrite,
- .d_ioctl = gdcioctl,
- .d_mmap = gdcmmap,
- .d_name = DRIVER_NAME,
- .d_maj = -1,
-};
-
-#endif /* FB_INSTALL_CDEV */
-
-static void
-gdc_identify(driver_t *driver, device_t parent)
-{
- BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, DRIVER_NAME, 0);
-}
-
-static int
-gdcprobe(device_t dev)
-{
- int error;
-
- /* Check isapnp ids */
- if (isa_get_vendorid(dev))
- return (ENXIO);
-
- device_set_desc(dev, "Generic GDC");
-
- error = gdc_alloc_resource(dev);
- if (error)
- return (error);
-
- error = gdc_probe_unit(device_get_unit(dev),
- device_get_softc(dev),
- device_get_flags(dev));
-
- gdc_release_resource(dev);
-
- return (error);
-}
-
-static int
-gdc_attach(device_t dev)
-{
- gdc_softc_t *sc;
- int error;
-
- error = gdc_alloc_resource(dev);
- if (error)
- return (error);
-
- sc = device_get_softc(dev);
- error = gdc_attach_unit(device_get_unit(dev),
- sc,
- device_get_flags(dev));
- if (error) {
- gdc_release_resource(dev);
- return error;
- }
-
-#ifdef FB_INSTALL_CDEV
- /* attach a virtual frame buffer device */
- error = fb_attach(makedev(0, GDC_MKMINOR(device_get_unit(dev))),
- sc->adp, &gdc_cdevsw);
- if (error) {
- gdc_release_resource(dev);
- return error;
- }
-#endif /* FB_INSTALL_CDEV */
-
- if (bootverbose)
- (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose);
-
- return 0;
-}
-
-static int
-gdc_probe_unit(int unit, gdc_softc_t *sc, int flags)
-{
- video_switch_t *sw;
-
- sw = vid_get_switch(DRIVER_NAME);
- if (sw == NULL)
- return ENXIO;
- return (*sw->probe)(unit, &sc->adp, NULL, flags);
-}
-
-static int
-gdc_attach_unit(int unit, gdc_softc_t *sc, int flags)
-{
- video_switch_t *sw;
-
- sw = vid_get_switch(DRIVER_NAME);
- if (sw == NULL)
- return ENXIO;
- return (*sw->init)(unit, sc->adp, flags);
-}
-
-
-static int
-gdc_alloc_resource(device_t dev)
-{
- int rid;
- gdc_softc_t *sc;
-
- sc = device_get_softc(dev);
-
- /* TEXT GDC */
- rid = 0;
- bus_set_resource(dev, SYS_RES_IOPORT, rid, TEXT_GDC, 1);
- sc->res_tgdc = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid,
- gdc_iat, 8, RF_ACTIVE);
- if (sc->res_tgdc == NULL) {
- gdc_release_resource(dev);
- return (ENXIO);
- }
- isa_load_resourcev(sc->res_tgdc, gdc_iat, 8);
-
- /* GRAPHIC GDC */
- rid = 8;
- bus_set_resource(dev, SYS_RES_IOPORT, rid, GRAPHIC_GDC, 1);
- sc->res_ggdc = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid,
- gdc_iat, 8, RF_ACTIVE);
- if (sc->res_ggdc == NULL) {
- gdc_release_resource(dev);
- return (ENXIO);
- }
- isa_load_resourcev(sc->res_ggdc, gdc_iat, 8);
-
- /* EGC */
- rid = 16;
- bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x4a0, 1);
- sc->res_egc = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid,
- gdc_iat, 8, RF_ACTIVE);
- if (sc->res_egc == NULL) {
- gdc_release_resource(dev);
- return (ENXIO);
- }
- isa_load_resourcev(sc->res_egc, gdc_iat, 8);
-
- /* PEGC */
- rid = 24;
- bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x9a0, 1);
- sc->res_pegc = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid,
- gdc_iat, 8, RF_ACTIVE);
- if (sc->res_pegc == NULL) {
- gdc_release_resource(dev);
- return (ENXIO);
- }
- isa_load_resourcev(sc->res_pegc, gdc_iat, 8);
-
- /* CRTC/GRCG */
- rid = 32;
- bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x70, 1);
- sc->res_grcg = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid,
- gdc_iat, 8, RF_ACTIVE);
- if (sc->res_grcg == NULL) {
- gdc_release_resource(dev);
- return (ENXIO);
- }
- isa_load_resourcev(sc->res_grcg, gdc_iat, 8);
-
- /* KCG */
- rid = 40;
- bus_set_resource(dev, SYS_RES_IOPORT, rid, 0xa1, 1);
- sc->res_kcg = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid,
- gdc_iat, 8, RF_ACTIVE);
- if (sc->res_kcg == NULL) {
- gdc_release_resource(dev);
- return (ENXIO);
- }
- isa_load_resourcev(sc->res_kcg, gdc_iat, 8);
-
-
- /* TEXT Memory */
- rid = 0;
- sc->res_tmem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
- 0xa0000, 0xa4fff, 0x5000, RF_ACTIVE);
- if (sc->res_tmem == NULL) {
- gdc_release_resource(dev);
- return (ENXIO);
- }
-
- /* GRAPHIC Memory */
- rid = 1;
- sc->res_gmem1 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
- 0xa8000, 0xbffff, 0x18000,
- RF_ACTIVE);
- if (sc->res_gmem1 == NULL) {
- gdc_release_resource(dev);
- return (ENXIO);
- }
- rid = 2;
- sc->res_gmem2 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
- 0xe0000, 0xe7fff, 0x8000,
- RF_ACTIVE);
- if (sc->res_gmem2 == NULL) {
- gdc_release_resource(dev);
- return (ENXIO);
- }
-
- return (0);
-}
-
-static int
-gdc_release_resource(device_t dev)
-{
- gdc_softc_t *sc;
-
- sc = device_get_softc(dev);
-
- if (sc->res_tgdc)
- bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->res_tgdc);
- if (sc->res_ggdc)
- bus_release_resource(dev, SYS_RES_IOPORT, 8, sc->res_ggdc);
- if (sc->res_egc)
- bus_release_resource(dev, SYS_RES_IOPORT, 16, sc->res_egc);
- if (sc->res_pegc)
- bus_release_resource(dev, SYS_RES_IOPORT, 24, sc->res_pegc);
- if (sc->res_grcg)
- bus_release_resource(dev, SYS_RES_IOPORT, 32, sc->res_grcg);
- if (sc->res_kcg)
- bus_release_resource(dev, SYS_RES_IOPORT, 40, sc->res_kcg);
-
- if (sc->res_tmem)
- bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->res_tmem);
- if (sc->res_gmem1)
- bus_release_resource(dev, SYS_RES_MEMORY, 1, sc->res_gmem1);
- if (sc->res_gmem2)
- bus_release_resource(dev, SYS_RES_MEMORY, 2, sc->res_gmem2);
-
- return (0);
-}
-
-/* cdev driver functions */
-
-#ifdef FB_INSTALL_CDEV
-
-static int
-gdcopen(dev_t dev, int flag, int mode, struct thread *td)
-{
- gdc_softc_t *sc;
-
- sc = GDC_SOFTC(GDC_UNIT(dev));
- if (sc == NULL)
- return ENXIO;
- if (mode & (O_CREAT | O_APPEND | O_TRUNC))
- return ENODEV;
-
- return genfbopen(&sc->gensc, sc->adp, flag, mode, td);
-}
-
-static int
-gdcclose(dev_t dev, int flag, int mode, struct thread *td)
-{
- gdc_softc_t *sc;
-
- sc = GDC_SOFTC(GDC_UNIT(dev));
- return genfbclose(&sc->gensc, sc->adp, flag, mode, td);
-}
-
-static int
-gdcread(dev_t dev, struct uio *uio, int flag)
-{
- gdc_softc_t *sc;
-
- sc = GDC_SOFTC(GDC_UNIT(dev));
- return genfbread(&sc->gensc, sc->adp, uio, flag);
-}
-
-static int
-gdcwrite(dev_t dev, struct uio *uio, int flag)
-{
- gdc_softc_t *sc;
-
- sc = GDC_SOFTC(GDC_UNIT(dev));
- return genfbread(&sc->gensc, sc->adp, uio, flag);
-}
-
-static int
-gdcioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
-{
- gdc_softc_t *sc;
-
- sc = GDC_SOFTC(GDC_UNIT(dev));
- return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, td);
-}
-
-static int
-gdcmmap(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
-{
- gdc_softc_t *sc;
-
- sc = GDC_SOFTC(GDC_UNIT(dev));
- return genfbmmap(&sc->gensc, sc->adp, offset, paddr, prot);
-}
-
-#endif /* FB_INSTALL_CDEV */
-
-static device_method_t gdc_methods[] = {
- DEVMETHOD(device_identify, gdc_identify),
- DEVMETHOD(device_probe, gdcprobe),
- DEVMETHOD(device_attach, gdc_attach),
- { 0, 0 }
-};
-
-static driver_t gdcdriver = {
- DRIVER_NAME,
- gdc_methods,
- sizeof(gdc_softc_t),
-};
-
-DRIVER_MODULE(gdc, isa, gdcdriver, gdc_devclass, 0, 0);
-
-/* LOW-LEVEL */
-
-
-#include <pc98/pc98/30line.h>
-
-#define TEXT_BUF_BASE 0x000a0000
-#define TEXT_BUF_SIZE 0x00008000
-#define GRAPHICS_BUF_BASE 0x000a8000
-#define GRAPHICS_BUF_SIZE 0x00040000
-#define VIDEO_BUF_BASE 0x000a0000
-#define VIDEO_BUF_SIZE 0x00048000
-
-#define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED)
-#define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED)
-#define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED)
-
-/*
- * NOTE: `va_window' should have a virtual address, but is initialized
- * with a physical address in the following table, they will be
- * converted at run-time.
- */
-static video_adapter_t adapter_init_value[] = {
- { 0,
- KD_PC98, "gdc", /* va_type, va_name */
- 0, 0, /* va_unit, va_minor */
- V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_BORDER,
- TEXT_GDC, 16, TEXT_GDC, /* va_io*, XXX */
- VIDEO_BUF_BASE, VIDEO_BUF_SIZE, /* va_mem* */
- TEXT_BUF_BASE, TEXT_BUF_SIZE, TEXT_BUF_SIZE, 0, /* va_window* */
- 0, 0, /* va_buffer, va_buffer_size */
- 0, M_PC98_80x25, 0, /* va_*mode* */
- },
-};
-
-static video_adapter_t biosadapter[1];
-
-/* video driver declarations */
-static int gdc_configure(int flags);
-static int gdc_err(video_adapter_t *adp, ...);
-static vi_probe_t gdc_probe;
-static vi_init_t gdc_init;
-static vi_get_info_t gdc_get_info;
-static vi_query_mode_t gdc_query_mode;
-static vi_set_mode_t gdc_set_mode;
-static vi_set_border_t gdc_set_border;
-static vi_save_state_t gdc_save_state;
-static vi_load_state_t gdc_load_state;
-static vi_read_hw_cursor_t gdc_read_hw_cursor;
-static vi_set_hw_cursor_t gdc_set_hw_cursor;
-static vi_set_hw_cursor_shape_t gdc_set_hw_cursor_shape;
-static vi_blank_display_t gdc_blank_display;
-static vi_mmap_t gdc_mmap_buf;
-static vi_ioctl_t gdc_dev_ioctl;
-static vi_clear_t gdc_clear;
-static vi_fill_rect_t gdc_fill_rect;
-static vi_bitblt_t gdc_bitblt;
-static vi_diag_t gdc_diag;
-static vi_save_palette_t gdc_save_palette;
-static vi_load_palette_t gdc_load_palette;
-static vi_set_win_org_t gdc_set_origin;
-
-static video_switch_t gdcvidsw = {
- gdc_probe,
- gdc_init,
- gdc_get_info,
- gdc_query_mode,
- gdc_set_mode,
- (vi_save_font_t *)gdc_err,
- (vi_load_font_t *)gdc_err,
- (vi_show_font_t *)gdc_err,
- gdc_save_palette,
- gdc_load_palette,
- gdc_set_border,
- gdc_save_state,
- gdc_load_state,
- gdc_set_origin,
- gdc_read_hw_cursor,
- gdc_set_hw_cursor,
- gdc_set_hw_cursor_shape,
- gdc_blank_display,
- gdc_mmap_buf,
- gdc_dev_ioctl,
- gdc_clear,
- gdc_fill_rect,
- gdc_bitblt,
- (int (*)(void))gdc_err,
- (int (*)(void))gdc_err,
- gdc_diag,
-};
-
-VIDEO_DRIVER(gdc, gdcvidsw, gdc_configure);
-
-/* GDC BIOS standard video modes */
-#define EOT (-1)
-#define NA (-2)
-
-static video_info_t bios_vmode[] = {
- { M_PC98_80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1,
- TEXT_BUF_BASE, TEXT_BUF_SIZE, TEXT_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
-#ifdef LINE30
- { M_PC98_80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1,
- TEXT_BUF_BASE, TEXT_BUF_SIZE, TEXT_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
-#endif
-#ifndef GDC_NOGRAPHICS
- { M_PC98_EGC640x400, V_INFO_COLOR | V_INFO_GRAPHICS,
- 640, 400, 8, 16, 4, 4,
- GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
- V_INFO_MM_OTHER },
- { M_PC98_PEGC640x400, V_INFO_COLOR | V_INFO_GRAPHICS | V_INFO_VESA,
- 640, 400, 8, 16, 8, 1,
- GRAPHICS_BUF_BASE, 0x00008000, 0x00008000, 0, 0,
- V_INFO_MM_PACKED, 1 },
-#ifdef LINE30
- { M_PC98_PEGC640x480, V_INFO_COLOR | V_INFO_GRAPHICS | V_INFO_VESA,
- 640, 480, 8, 16, 8, 1,
- GRAPHICS_BUF_BASE, 0x00008000, 0x00008000, 0, 0,
- V_INFO_MM_PACKED, 1 },
-#endif
-#endif
- { EOT },
-};
-
-static int gdc_init_done = FALSE;
-
-/* local functions */
-static int map_gen_mode_num(int type, int color, int mode);
-static int probe_adapters(void);
-
-#define prologue(adp, flag, err) \
- if (!gdc_init_done || !((adp)->va_flags & (flag))) \
- return (err)
-
-/* a backdoor for the console driver */
-static int
-gdc_configure(int flags)
-{
- probe_adapters();
- biosadapter[0].va_flags |= V_ADP_INITIALIZED;
- if (!config_done(&biosadapter[0])) {
- if (vid_register(&biosadapter[0]) < 0)
- return 1;
- biosadapter[0].va_flags |= V_ADP_REGISTERED;
- }
-
- return 1;
-}
-
-/* local subroutines */
-
-/* map a generic video mode to a known mode number */
-static int
-map_gen_mode_num(int type, int color, int mode)
-{
- static struct {
- int from;
- int to;
- } mode_map[] = {
- { M_TEXT_80x25, M_PC98_80x25, },
-#ifdef LINE30
- { M_TEXT_80x30, M_PC98_80x30, },
-#endif
- };
- int i;
-
- for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
- if (mode_map[i].from == mode)
- return mode_map[i].to;
- }
- return mode;
-}
-
-static int
-verify_adapter(video_adapter_t *adp)
-{
-#ifndef GDC_NOGRAPHICS
- int i;
-
- if (PC98_SYSTEM_PARAMETER(0x45c) & 0x40) { /* PEGC exists */
- adp->va_flags |= V_ADP_VESA; /* XXX */
- } else {
- for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
- if (bios_vmode[i].vi_flags & V_INFO_VESA)
- bios_vmode[i].vi_mode = NA;
- }
- }
-#endif
- return 0;
-}
-
-/* probe video adapters and return the number of detected adapters */
-static int
-probe_adapters(void)
-{
- video_info_t info;
-
- /* do this test only once */
- if (gdc_init_done)
- return 1;
- gdc_init_done = TRUE;
-
- biosadapter[0] = adapter_init_value[0];
- biosadapter[0].va_flags |= V_ADP_PROBED;
- biosadapter[0].va_mode =
- biosadapter[0].va_initial_mode = biosadapter[0].va_initial_bios_mode;
-
- if ((PC98_SYSTEM_PARAMETER(0x597) & 0x80) ||
- (PC98_SYSTEM_PARAMETER(0x458) & 0x80)) {
- gdc_FH = (inb(0x9a8) & 1) ? _31KHZ : _24KHZ;
- } else {
- gdc_FH = _24KHZ;
- }
-
- gdc_get_info(&biosadapter[0], biosadapter[0].va_initial_mode, &info);
- initialize_gdc(T25_G400, info.vi_flags & V_INFO_GRAPHICS);
-
- biosadapter[0].va_window = BIOS_PADDRTOVADDR(info.vi_window);
- biosadapter[0].va_window_size = info.vi_window_size;
- biosadapter[0].va_window_gran = info.vi_window_gran;
- biosadapter[0].va_buffer = 0;
- biosadapter[0].va_buffer_size = 0;
- if (info.vi_flags & V_INFO_GRAPHICS) {
- switch (info.vi_depth/info.vi_planes) {
- case 1:
- biosadapter[0].va_line_width = info.vi_width/8;
- break;
- case 2:
- biosadapter[0].va_line_width = info.vi_width/4;
- break;
- case 4:
- biosadapter[0].va_line_width = info.vi_width/2;
- break;
- case 8:
- default: /* shouldn't happen */
- biosadapter[0].va_line_width = info.vi_width;
- break;
- }
- } else {
- biosadapter[0].va_line_width = info.vi_width;
- }
- bcopy(&info, &biosadapter[0].va_info, sizeof(info));
-
- verify_adapter(&biosadapter[0]);
-
- return 1;
-}
-
-static void master_gdc_cmd(unsigned int cmd)
-{
- while ( (inb(TEXT_GDC) & 2) != 0);
- outb(TEXT_GDC+2, cmd);
-}
-
-static void master_gdc_prm(unsigned int pmtr)
-{
- while ( (inb(TEXT_GDC) & 2) != 0);
- outb(TEXT_GDC, pmtr);
-}
-
-static void master_gdc_word_prm(unsigned int wpmtr)
-{
- master_gdc_prm(wpmtr & 0x00ff);
- master_gdc_prm((wpmtr >> 8) & 0x00ff);
-}
-
-#ifdef LINE30
-static void master_gdc_fifo_empty(void)
-{
- while ( (inb(TEXT_GDC) & 4) == 0);
-}
-#endif
-
-static void master_gdc_wait_vsync(void)
-{
- while ( (inb(TEXT_GDC) & 0x20) != 0);
- while ( (inb(TEXT_GDC) & 0x20) == 0);
-}
-
-static void gdc_cmd(unsigned int cmd)
-{
- while ( (inb(GRAPHIC_GDC) & 2) != 0);
- outb( GRAPHIC_GDC+2, cmd);
-}
-
-#ifdef LINE30
-static void gdc_prm(unsigned int pmtr)
-{
- while ( (inb(GRAPHIC_GDC) & 2) != 0);
- outb( GRAPHIC_GDC, pmtr);
-}
-
-static void gdc_word_prm(unsigned int wpmtr)
-{
- gdc_prm(wpmtr & 0x00ff);
- gdc_prm((wpmtr >> 8) & 0x00ff);
-}
-
-static void gdc_fifo_empty(void)
-{
- while ( (inb(GRAPHIC_GDC) & 0x04) == 0);
-}
-#endif
-
-static void gdc_wait_vsync(void)
-{
- while ( (inb(GRAPHIC_GDC) & 0x20) != 0);
- while ( (inb(GRAPHIC_GDC) & 0x20) == 0);
-}
-
-#ifdef LINE30
-static int check_gdc_clock(void)
-{
- if ((inb(IO_SYSPORT) & 0x80) == 0){
- return _5MHZ;
- } else {
- return _2_5MHZ;
- }
-}
-#endif
-
-static void initialize_gdc(unsigned int mode, int isGraph)
-{
-#ifdef LINE30
- /* start 30line initialize */
- int m_mode, s_mode, gdc_clock, hsync_clock;
-
- gdc_clock = check_gdc_clock();
- m_mode = (mode == T25_G400) ? _25L : _30L;
- s_mode = 2*mode+gdc_clock;
- gdc_INFO = m_mode;
-
- master_gdc_wait_vsync();
-
- if ((PC98_SYSTEM_PARAMETER(0x597) & 0x80) ||
- (PC98_SYSTEM_PARAMETER(0x458) & 0x80)) {
- if (PC98_SYSTEM_PARAMETER(0x481) & 0x08) {
- hsync_clock = (m_mode == _25L) ? gdc_FH : _31KHZ;
- outb(0x9a8, (hsync_clock == _31KHZ) ? 1 : 0);
- } else {
- hsync_clock = gdc_FH;
- }
- } else {
- hsync_clock = _24KHZ;
- }
-
- if ((gdc_clock == _2_5MHZ) &&
- (slave_param[hsync_clock][s_mode][GDC_LF] > 400)) {
- outb(0x6a, 0x83);
- outb(0x6a, 0x85);
- gdc_clock = _5MHZ;
- s_mode = 2*mode+gdc_clock;
- }
-
- master_gdc_cmd(_GDC_RESET);
- master_gdc_cmd(_GDC_MASTER);
- gdc_cmd(_GDC_RESET);
- gdc_cmd(_GDC_SLAVE);
-
- /* GDC Master */
- master_gdc_cmd(_GDC_SYNC);
- master_gdc_prm(0x00); /* flush less */ /* text & graph */
- master_gdc_prm(master_param[hsync_clock][m_mode][GDC_CR]);
- master_gdc_word_prm(((master_param[hsync_clock][m_mode][GDC_HFP] << 10)
- + (master_param[hsync_clock][m_mode][GDC_VS] << 5)
- + master_param[hsync_clock][m_mode][GDC_HS]));
- master_gdc_prm(master_param[hsync_clock][m_mode][GDC_HBP]);
- master_gdc_prm(master_param[hsync_clock][m_mode][GDC_VFP]);
- master_gdc_word_prm(((master_param[hsync_clock][m_mode][GDC_VBP] << 10)
- + (master_param[hsync_clock][m_mode][GDC_LF])));
- master_gdc_fifo_empty();
- master_gdc_cmd(_GDC_PITCH);
- master_gdc_prm(MasterPCH);
- master_gdc_fifo_empty();
-
- /* GDC slave */
- gdc_cmd(_GDC_SYNC);
- gdc_prm(0x06);
- gdc_prm(slave_param[hsync_clock][s_mode][GDC_CR]);
- gdc_word_prm((slave_param[hsync_clock][s_mode][GDC_HFP] << 10)
- + (slave_param[hsync_clock][s_mode][GDC_VS] << 5)
- + (slave_param[hsync_clock][s_mode][GDC_HS]));
- gdc_prm(slave_param[hsync_clock][s_mode][GDC_HBP]);
- gdc_prm(slave_param[hsync_clock][s_mode][GDC_VFP]);
- gdc_word_prm((slave_param[hsync_clock][s_mode][GDC_VBP] << 10)
- + (slave_param[hsync_clock][s_mode][GDC_LF]));
- gdc_fifo_empty();
- gdc_cmd(_GDC_PITCH);
- gdc_prm(SlavePCH[gdc_clock]);
- gdc_fifo_empty();
-
- /* set Master GDC scroll param */
- master_gdc_wait_vsync();
- master_gdc_wait_vsync();
- master_gdc_wait_vsync();
- master_gdc_cmd(_GDC_SCROLL);
- master_gdc_word_prm(0);
- master_gdc_word_prm((master_param[hsync_clock][m_mode][GDC_LF] << 4)
- | 0x0000);
- master_gdc_fifo_empty();
-
- /* set Slave GDC scroll param */
- gdc_wait_vsync();
- gdc_cmd(_GDC_SCROLL);
- gdc_word_prm(0);
- if (gdc_clock == _5MHZ) {
- gdc_word_prm((SlaveScrlLF[mode] << 4) | 0x4000);
- } else {
- gdc_word_prm(SlaveScrlLF[mode] << 4);
- }
- gdc_fifo_empty();
-
- gdc_word_prm(0);
- if (gdc_clock == _5MHZ) {
- gdc_word_prm((SlaveScrlLF[mode] << 4) | 0x4000);
- } else {
- gdc_word_prm(SlaveScrlLF[mode] << 4);
- }
- gdc_fifo_empty();
-
- /* sync start */
- gdc_cmd(isGraph ? _GDC_START : _GDC_STOP);
-
- gdc_wait_vsync();
- gdc_wait_vsync();
- gdc_wait_vsync();
-
- master_gdc_cmd(isGraph ? _GDC_STOP : _GDC_START);
-#else
- master_gdc_wait_vsync();
- master_gdc_cmd(isGraph ? _GDC_STOP : _GDC_START); /* text */
- gdc_wait_vsync();
- gdc_cmd(isGraph ? _GDC_START : _GDC_STOP); /* graphics */
-#endif
-}
-
-#ifndef GDC_NOGRAPHICS
-static u_char b_palette[] = {
- /* R G B */
- 0x00, 0x00, 0x00, /* 0 */
- 0x00, 0x00, 0x7f, /* 1 */
- 0x7f, 0x00, 0x00, /* 2 */
- 0x7f, 0x00, 0x7f, /* 3 */
- 0x00, 0x7f, 0x00, /* 4 */
- 0x00, 0x7f, 0x7f, /* 5 */
- 0x7f, 0x7f, 0x00, /* 6 */
- 0x7f, 0x7f, 0x7f, /* 7 */
- 0x40, 0x40, 0x40, /* 8 */
- 0x00, 0x00, 0xff, /* 9 */
- 0xff, 0x00, 0x00, /* 10 */
- 0xff, 0x00, 0xff, /* 11 */
- 0x00, 0xff, 0x00, /* 12 */
- 0x00, 0xff, 0xff, /* 13 */
- 0xff, 0xff, 0x00, /* 14 */
- 0xff, 0xff, 0xff, /* 15 */
-};
-#endif
-
-static int
-gdc_load_palette(video_adapter_t *adp, u_char *palette)
-{
-#ifndef GDC_NOGRAPHICS
- int i;
-
- if (adp->va_info.vi_flags & V_INFO_VESA) {
- gdc_wait_vsync();
- for (i = 0; i < 256; ++i) {
- outb(0xa8, i);
- outb(0xac, *palette++); /* R */
- outb(0xaa, *palette++); /* G */
- outb(0xae, *palette++); /* B */
- }
- } else {
- /*
- * XXX - Even though PC-98 text color is independent of palette,
- * we should set palette in text mode.
- * Because the background color of text mode is palette 0's one.
- */
- outb(0x6a, 1); /* 16 colors mode */
- bcopy(palette, b_palette, sizeof(b_palette));
-
- gdc_wait_vsync();
- for (i = 0; i < 16; ++i) {
- outb(0xa8, i);
- outb(0xac, *palette++ >> 4); /* R */
- outb(0xaa, *palette++ >> 4); /* G */
- outb(0xae, *palette++ >> 4); /* B */
- }
- }
-#endif
- return 0;
-}
-
-static int
-gdc_save_palette(video_adapter_t *adp, u_char *palette)
-{
-#ifndef GDC_NOGRAPHICS
- int i;
-
- if (adp->va_info.vi_flags & V_INFO_VESA) {
- for (i = 0; i < 256; ++i) {
- outb(0xa8, i);
- *palette++ = inb(0xac); /* R */
- *palette++ = inb(0xaa); /* G */
- *palette++ = inb(0xae); /* B */
- }
- } else {
- bcopy(b_palette, palette, sizeof(b_palette));
- }
-#endif
- return 0;
-}
-
-static int
-gdc_set_origin(video_adapter_t *adp, off_t offset)
-{
-#ifndef GDC_NOGRAPHICS
- if (adp->va_info.vi_flags & V_INFO_VESA) {
- writew(BIOS_PADDRTOVADDR(0x000e0004), offset >> 15);
- }
-#endif
- return 0;
-}
-
-/* entry points */
-
-static int
-gdc_err(video_adapter_t *adp, ...)
-{
- return ENODEV;
-}
-
-static int
-gdc_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
-{
- probe_adapters();
- if (unit >= 1)
- return ENXIO;
-
- *adpp = &biosadapter[unit];
-
- return 0;
-}
-
-static int
-gdc_init(int unit, video_adapter_t *adp, int flags)
-{
- if ((unit >= 1) || (adp == NULL) || !probe_done(adp))
- return ENXIO;
-
- if (!init_done(adp)) {
- /* nothing to do really... */
- adp->va_flags |= V_ADP_INITIALIZED;
- }
-
- if (!config_done(adp)) {
- if (vid_register(adp) < 0)
- return ENXIO;
- adp->va_flags |= V_ADP_REGISTERED;
- }
-
- return 0;
-}
-
-/*
- * get_info():
- * Return the video_info structure of the requested video mode.
- */
-static int
-gdc_get_info(video_adapter_t *adp, int mode, video_info_t *info)
-{
- int i;
-
- if (!gdc_init_done)
- return ENXIO;
-
- mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode);
- for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
- if (bios_vmode[i].vi_mode == NA)
- continue;
- if (mode == bios_vmode[i].vi_mode) {
- *info = bios_vmode[i];
- info->vi_buffer_size = info->vi_window_size*info->vi_planes;
- return 0;
- }
- }
- return EINVAL;
-}
-
-/*
- * query_mode():
- * Find a video mode matching the requested parameters.
- * Fields filled with 0 are considered "don't care" fields and
- * match any modes.
- */
-static int
-gdc_query_mode(video_adapter_t *adp, video_info_t *info)
-{
- int i;
-
- if (!gdc_init_done)
- return ENXIO;
-
- for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
- if (bios_vmode[i].vi_mode == NA)
- continue;
-
- if ((info->vi_width != 0)
- && (info->vi_width != bios_vmode[i].vi_width))
- continue;
- if ((info->vi_height != 0)
- && (info->vi_height != bios_vmode[i].vi_height))
- continue;
- if ((info->vi_cwidth != 0)
- && (info->vi_cwidth != bios_vmode[i].vi_cwidth))
- continue;
- if ((info->vi_cheight != 0)
- && (info->vi_cheight != bios_vmode[i].vi_cheight))
- continue;
- if ((info->vi_depth != 0)
- && (info->vi_depth != bios_vmode[i].vi_depth))
- continue;
- if ((info->vi_planes != 0)
- && (info->vi_planes != bios_vmode[i].vi_planes))
- continue;
- /* XXX: should check pixel format, memory model */
- if ((info->vi_flags != 0)
- && (info->vi_flags != bios_vmode[i].vi_flags))
- continue;
-
- /* verify if this mode is supported on this adapter */
- if (gdc_get_info(adp, bios_vmode[i].vi_mode, info))
- continue;
- return 0;
- }
- return ENODEV;
-}
-
-/*
- * set_mode():
- * Change the video mode.
- */
-static int
-gdc_set_mode(video_adapter_t *adp, int mode)
-{
- video_info_t info;
-
- prologue(adp, V_ADP_MODECHANGE, ENODEV);
-
- mode = map_gen_mode_num(adp->va_type,
- adp->va_flags & V_ADP_COLOR, mode);
- if (gdc_get_info(adp, mode, &info))
- return EINVAL;
-
- switch (info.vi_mode) {
-#ifndef GDC_NOGRAPHICS
- case M_PC98_PEGC640x480: /* PEGC 640x480 */
- initialize_gdc(T30_G480, info.vi_flags & V_INFO_GRAPHICS);
- break;
- case M_PC98_PEGC640x400: /* PEGC 640x400 */
- case M_PC98_EGC640x400: /* EGC GRAPHICS */
-#endif
- case M_PC98_80x25: /* VGA TEXT */
- initialize_gdc(T25_G400, info.vi_flags & V_INFO_GRAPHICS);
- break;
- case M_PC98_80x30: /* VGA TEXT */
- initialize_gdc(T30_G400, info.vi_flags & V_INFO_GRAPHICS);
- break;
- default:
- break;
- }
-
-#ifndef GDC_NOGRAPHICS
- if (info.vi_flags & V_INFO_VESA) {
- outb(0x6a, 0x07); /* enable mode F/F change */
- outb(0x6a, 0x21); /* enhanced graphics */
- if (info.vi_height > 400)
- outb(0x6a, 0x69); /* 800 lines */
- writeb(BIOS_PADDRTOVADDR(0x000e0100), 0); /* packed pixel */
- } else {
- if (adp->va_flags & V_ADP_VESA) {
- outb(0x6a, 0x07); /* enable mode F/F change */
- outb(0x6a, 0x20); /* normal graphics */
- outb(0x6a, 0x68); /* 400 lines */
- }
- outb(0x6a, 1); /* 16 colors */
- }
-#endif
-
- adp->va_mode = mode;
- adp->va_flags &= ~V_ADP_COLOR;
- adp->va_flags |=
- (info.vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
-#if 0
- adp->va_crtc_addr =
- (adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
-#endif
- adp->va_window = BIOS_PADDRTOVADDR(info.vi_window);
- adp->va_window_size = info.vi_window_size;
- adp->va_window_gran = info.vi_window_gran;
- if (info.vi_buffer_size == 0) {
- adp->va_buffer = 0;
- adp->va_buffer_size = 0;
- } else {
- adp->va_buffer = BIOS_PADDRTOVADDR(info.vi_buffer);
- adp->va_buffer_size = info.vi_buffer_size;
- }
- if (info.vi_flags & V_INFO_GRAPHICS) {
- switch (info.vi_depth/info.vi_planes) {
- case 1:
- adp->va_line_width = info.vi_width/8;
- break;
- case 2:
- adp->va_line_width = info.vi_width/4;
- break;
- case 4:
- adp->va_line_width = info.vi_width/2;
- break;
- case 8:
- default: /* shouldn't happen */
- adp->va_line_width = info.vi_width;
- break;
- }
- } else {
- adp->va_line_width = info.vi_width;
- }
- bcopy(&info, &adp->va_info, sizeof(info));
-
- /* move hardware cursor out of the way */
- (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
-
- return 0;
-}
-
-/*
- * set_border():
- * Change the border color.
- */
-static int
-gdc_set_border(video_adapter_t *adp, int color)
-{
- outb(0x6c, color << 4);
- return 0;
-}
-
-/*
- * save_state():
- * Read video card register values.
- */
-static int
-gdc_save_state(video_adapter_t *adp, void *p, size_t size)
-{
- return ENODEV;
-}
-
-/*
- * load_state():
- * Set video card registers at once.
- */
-static int
-gdc_load_state(video_adapter_t *adp, void *p)
-{
- return ENODEV;
-}
-
-/*
- * read_hw_cursor():
- * Read the position of the hardware text cursor.
- */
-static int
-gdc_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
-{
- u_int16_t off;
- int s;
-
- if (!gdc_init_done)
- return ENXIO;
-
- if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
- return ENODEV;
-
- s = spltty();
- master_gdc_cmd(0xe0); /* _GDC_CSRR */
- while((inb(TEXT_GDC + 0) & 0x1) == 0) {} /* GDC wait */
- off = inb(TEXT_GDC + 2); /* EADl */
- off |= (inb(TEXT_GDC + 2) << 8); /* EADh */
- inb(TEXT_GDC + 2); /* dummy */
- inb(TEXT_GDC + 2); /* dummy */
- inb(TEXT_GDC + 2); /* dummy */
- splx(s);
-
- if (off >= ROW*COL)
- off = 0;
- *row = off / adp->va_info.vi_width;
- *col = off % adp->va_info.vi_width;
-
- return 0;
-}
-
-/*
- * set_hw_cursor():
- * Move the hardware text cursor. If col and row are both -1,
- * the cursor won't be shown.
- */
-static int
-gdc_set_hw_cursor(video_adapter_t *adp, int col, int row)
-{
- u_int16_t off;
- int s;
-
- if (!gdc_init_done)
- return ENXIO;
-
- if ((col == -1) && (row == -1)) {
- off = -1;
- } else {
- if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
- return ENODEV;
- off = row*adp->va_info.vi_width + col;
- }
-
- s = spltty();
- master_gdc_cmd(0x49); /* _GDC_CSRW */
- master_gdc_word_prm(off);
- splx(s);
-
- return 0;
-}
-
-/*
- * set_hw_cursor_shape():
- * Change the shape of the hardware text cursor. If the height is zero
- * or negative, the cursor won't be shown.
- */
-static int
-gdc_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
- int celsize, int blink)
-{
- int start;
- int end;
- int s;
-
- if (!gdc_init_done)
- return ENXIO;
-
- start = celsize - (base + height);
- end = celsize - base - 1;
-
-#if 0
- /*
- * muPD7220 GDC has anomaly that if end == celsize - 1 then start
- * must be 0, otherwise the cursor won't be correctly shown
- * in the first row in the screen. We shall set end to celsize - 2;
- * if end == celsize -1 && start > 0. XXX
- */
- if ((end == celsize - 1) && (start > 0) && (start < end))
- --end;
-#endif
-
- s = spltty();
- master_gdc_cmd(0x4b); /* _GDC_CSRFORM */
- master_gdc_prm(((height > 0) ? 0x80 : 0) /* cursor on/off */
- | ((celsize - 1) & 0x1f)); /* cel size */
- master_gdc_word_prm(((end & 0x1f) << 11) /* end line */
- | (12 << 6) /* blink rate */
- | (blink ? 0 : 0x20) /* blink on/off */
- | (start & 0x1f)); /* start line */
- splx(s);
-
- return 0;
-}
-
-/*
- * blank_display()
- * Put the display in power save/power off mode.
- */
-static int
-gdc_blank_display(video_adapter_t *adp, int mode)
-{
- int s;
- static int standby = 0;
-
- if (!gdc_init_done)
- return ENXIO;
-
- s = splhigh();
- switch (mode) {
- case V_DISPLAY_SUSPEND:
- case V_DISPLAY_STAND_BY:
- outb(0x09a2, 0x80 | 0x40); /* V/H-SYNC mask */
- if (inb(0x09a2) == (0x80 | 0x40))
- standby = 1;
- /* FALLTHROUGH */
-
- case V_DISPLAY_BLANK:
- if (epson_machine_id == 0x20) {
- outb(0x43f, 0x42);
- outb(0xc17, inb(0xc17) & ~0x08); /* turn off side light */
- outb(0xc16, inb(0xc16) & ~0x02); /* turn off back light */
- outb(0x43f, 0x40);
- } else {
- while (!(inb(TEXT_GDC) & 0x20)) /* V-SYNC wait */
- ;
- outb(TEXT_GDC + 8, 0x0e); /* DISP off */
- }
- break;
-
- case V_DISPLAY_ON:
- if (epson_machine_id == 0x20) {
- outb(0x43f, 0x42);
- outb(0xc17, inb(0xc17) | 0x08);
- outb(0xc16, inb(0xc16) | 0x02);
- outb(0x43f, 0x40);
- } else {
- while (!(inb(TEXT_GDC) & 0x20)) /* V-SYNC wait */
- ;
- outb(TEXT_GDC + 8, 0x0f); /* DISP on */
- }
- if (standby) {
- outb(0x09a2, 0x00); /* V/H-SYNC unmask */
- standby = 0;
- }
- break;
- }
- splx(s);
- return 0;
-}
-
-/*
- * mmap():
- * Mmap frame buffer.
- */
-static int
-gdc_mmap_buf(video_adapter_t *adp, vm_offset_t offset, vm_offset_t *paddr,
- int prot)
-{
- /* FIXME: is this correct? XXX */
- if (offset > VIDEO_BUF_SIZE - PAGE_SIZE)
- return -1;
- *paddr = adp->va_info.vi_window + offset;
- return 0;
-}
-
-static int
-gdc_clear(video_adapter_t *adp)
-{
- /* FIXME */
- return ENODEV;
-}
-
-static int
-gdc_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
-{
- return ENODEV;
-}
-
-static int
-gdc_bitblt(video_adapter_t *adp,...)
-{
- /* FIXME */
- return ENODEV;
-}
-
-static int
-gdc_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
-{
- switch (cmd) {
- case FBIO_GETWINORG: /* get frame buffer window origin */
- *(u_int *)arg = 0;
- return 0;
-
- case FBIO_SETWINORG: /* set frame buffer window origin */
- case FBIO_SETDISPSTART: /* set display start address */
- case FBIO_SETLINEWIDTH: /* set scan line length in pixel */
- case FBIO_GETPALETTE: /* get color palette */
- case FBIO_SETPALETTE: /* set color palette */
- case FBIOGETCMAP: /* get color palette */
- case FBIOPUTCMAP: /* set color palette */
- return ENODEV;
-
- case FBIOGTYPE: /* get frame buffer type info. */
- ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type);
- ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height;
- ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width;
- ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth;
- if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8))
- ((struct fbtype *)arg)->fb_cmsize = 0;
- else
- ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth;
- ((struct fbtype *)arg)->fb_size = adp->va_buffer_size;
- return 0;
-
- default:
- return fb_commonioctl(adp, cmd, arg);
- }
-}
-
-/*
- * diag():
- * Print some information about the video adapter and video modes,
- * with requested level of details.
- */
-static int
-gdc_diag(video_adapter_t *adp, int level)
-{
-#if FB_DEBUG > 1
- int i;
-#endif
-
- if (!gdc_init_done)
- return ENXIO;
-
- fb_dump_adp_info(DRIVER_NAME, adp, level);
-
-#if FB_DEBUG > 1
- for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
- if (bios_vmode[i].vi_mode == NA)
- continue;
- if (get_mode_param(bios_vmode[i].vi_mode) == NULL)
- continue;
- fb_dump_mode_info(DRIVER_NAME, adp, &bios_vmode[i], level);
- }
-#endif
-
- return 0;
-}
diff --git a/sys/pc98/cbus/olpt.c b/sys/pc98/cbus/olpt.c
deleted file mode 100644
index e54b1433e074..000000000000
--- a/sys/pc98/cbus/olpt.c
+++ /dev/null
@@ -1,818 +0,0 @@
-/*
- * Copyright (c) 1990 William F. Jolitz, TeleMuse
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This software is a component of "386BSD" developed by
- * William F. Jolitz, TeleMuse.
- * 4. Neither the name of the developer nor the name "386BSD"
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ
- * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS
- * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
- * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
- * NOT MAKE USE OF THIS WORK.
- *
- * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
- * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN
- * REFERENCES SUCH AS THE "PORTING UNIX TO THE 386" SERIES
- * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING
- * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND
- * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE
- * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS
- * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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: unknown origin, 386BSD 0.1
- * $FreeBSD$
- */
-
-/*
- * Device Driver for AT parallel printer port
- * Written by William Jolitz 12/18/90
- */
-
-/*
- * Parallel port TCP/IP interfaces added. I looked at the driver from
- * MACH but this is a complete rewrite, and btw. incompatible, and it
- * should perform better too. I have never run the MACH driver though.
- *
- * This driver sends two bytes (0x08, 0x00) in front of each packet,
- * to allow us to distinguish another format later.
- *
- * Now added a Linux/Crynwr compatibility mode which is enabled using
- * IF_LINK0 - Tim Wilkinson.
- *
- * TODO:
- * Make HDLC/PPP mode, use IF_LLC1 to enable.
- *
- * Connect the two computers using a Laplink parallel cable to use this
- * feature:
- *
- * +----------------------------------------+
- * |A-name A-End B-End Descr. Port/Bit |
- * +----------------------------------------+
- * |DATA0 2 15 Data 0/0x01 |
- * |-ERROR 15 2 1/0x08 |
- * +----------------------------------------+
- * |DATA1 3 13 Data 0/0x02 |
- * |+SLCT 13 3 1/0x10 |
- * +----------------------------------------+
- * |DATA2 4 12 Data 0/0x04 |
- * |+PE 12 4 1/0x20 |
- * +----------------------------------------+
- * |DATA3 5 10 Strobe 0/0x08 |
- * |-ACK 10 5 1/0x40 |
- * +----------------------------------------+
- * |DATA4 6 11 Data 0/0x10 |
- * |BUSY 11 6 1/~0x80 |
- * +----------------------------------------+
- * |GND 18-25 18-25 GND - |
- * +----------------------------------------+
- *
- * Expect transfer-rates up to 75 kbyte/sec.
- *
- * If GCC could correctly grok
- * register int port asm("edx")
- * the code would be cleaner
- *
- * Poul-Henning Kamp <phk@freebsd.org>
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/conf.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/bus.h>
-#include <sys/kernel.h>
-#include <sys/uio.h>
-#include <sys/syslog.h>
-
-#include <machine/clock.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-#include <isa/isavar.h>
-
-#include <i386/isa/lptreg.h>
-#include <dev/ppbus/lptio.h>
-
-#define LPINITRDY 4 /* wait up to 4 seconds for a ready */
-#define LPTOUTINITIAL 10 /* initial timeout to wait for ready 1/10 s */
-#define LPTOUTMAX 1 /* maximal timeout 1 s */
-#define LPPRI (PZERO+8)
-#define BUFSIZE 1024
-
-#ifndef PC98
-/* BIOS printer list - used by BIOS probe*/
-#define BIOS_LPT_PORTS 0x408
-#define BIOS_PORTS (short *)(KERNBASE+BIOS_LPT_PORTS)
-#define BIOS_MAX_LPT 4
-#endif
-
-
-#ifndef DEBUG
-#define lprintf(args)
-#else
-#define lprintf(args) do { \
- if (lptflag) \
- printf args; \
- } while (0)
-static int volatile lptflag = 1;
-#endif
-
-#define LPTUNIT(s) ((s)&0x03)
-#define LPTFLAGS(s) ((s)&0xfc)
-
-struct lpt_softc {
- struct resource *res_port;
- struct resource *res_irq;
- void *sc_ih;
-
- int sc_port;
- short sc_state;
- /* default case: negative prime, negative ack, handshake strobe,
- prime once */
- u_char sc_control;
- char sc_flags;
-#define LP_POS_INIT 0x04 /* if we are a postive init signal */
-#define LP_POS_ACK 0x08 /* if we are a positive going ack */
-#define LP_NO_PRIME 0x10 /* don't prime the printer at all */
-#define LP_PRIMEOPEN 0x20 /* prime on every open */
-#define LP_AUTOLF 0x40 /* tell printer to do an automatic lf */
-#define LP_BYPASS 0x80 /* bypass printer ready checks */
- struct buf *sc_inbuf;
- short sc_xfercnt ;
- char sc_primed;
- char *sc_cp ;
- u_char sc_irq ; /* IRQ status of port */
-#define LP_HAS_IRQ 0x01 /* we have an irq available */
-#define LP_USE_IRQ 0x02 /* we are using our irq */
-#define LP_ENABLE_IRQ 0x04 /* enable IRQ on open */
- u_char sc_backoff ; /* time to call lptout() again */
-};
-
-/* bits for state */
-#define OPEN (1<<0) /* device is open */
-#define ASLP (1<<1) /* awaiting draining of printer */
-#define ERROR (1<<2) /* error was received from printer */
-#define OBUSY (1<<3) /* printer is busy doing output */
-#define LPTOUT (1<<4) /* timeout while not selected */
-#define TOUT (1<<5) /* timeout while not selected */
-#define INIT (1<<6) /* waiting to initialize for open */
-#define INTERRUPTED (1<<7) /* write call was interrupted */
-
-
-/* status masks to interrogate printer status */
-#define RDY_MASK (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR) /* ready ? */
-#define LP_READY (LPS_SEL|LPS_NBSY|LPS_NERR)
-
-/* Printer Ready condition - from lpa.c */
-/* Only used in polling code */
-#ifdef PC98
-#define NOT_READY(x) ((inb(x) & LPS_NBSY) != LPS_NBSY)
-#else /* IBM-PC */
-#define LPS_INVERT (LPS_NBSY | LPS_NACK | LPS_SEL | LPS_NERR)
-#define LPS_MASK (LPS_NBSY | LPS_NACK | LPS_OUT | LPS_SEL | LPS_NERR)
-#define NOT_READY(x) ((inb(x)^LPS_INVERT)&LPS_MASK)
-#endif
-
-#define MAX_SLEEP (hz*5) /* Timeout while waiting for device ready */
-#define MAX_SPIN 20 /* Max delay for device ready in usecs */
-
-static timeout_t lptout;
-static int lpt_probe(device_t);
-static int lpt_attach(device_t);
-static void lpt_intr(void *);
-
-static devclass_t olpt_devclass;
-
-static device_method_t olpt_methods[] = {
- DEVMETHOD(device_probe, lpt_probe),
- DEVMETHOD(device_attach, lpt_attach),
- { 0, 0 }
-};
-
-static driver_t olpt_driver = {
- "olpt",
- olpt_methods,
- sizeof (struct lpt_softc),
-};
-
-DRIVER_MODULE(olpt, isa, olpt_driver, olpt_devclass, 0, 0);
-
-static d_open_t lptopen;
-static d_close_t lptclose;
-static d_write_t lptwrite;
-static d_ioctl_t lptioctl;
-
-#define CDEV_MAJOR 16
-static struct cdevsw lpt_cdevsw = {
- .d_open = lptopen,
- .d_close = lptclose,
- .d_write = lptwrite,
- .d_ioctl = lptioctl,
- .d_name = "lpt",
- .d_maj = CDEV_MAJOR,
-};
-
-static bus_addr_t lpt_iat[] = {0, 2, 4, 6};
-
-#ifndef PC98
-/*
- * Internal routine to lptprobe to do port tests of one byte value
- */
-static int
-lpt_port_test (int port, u_char data, u_char mask)
-{
- int temp, timeout;
-
- data = data & mask;
- outb(port, data);
- timeout = 10000;
- do {
- DELAY(10);
- temp = inb(port) & mask;
- }
- while (temp != data && --timeout);
- lprintf(("Port 0x%x\tout=%x\tin=%x\ttout=%d\n",
- port, data, temp, timeout));
- return (temp == data);
-}
-#endif /* PC98 */
-
-/*
- * New lpt port probe Geoff Rehmet - Rhodes University - 14/2/94
- * Based partially on Rod Grimes' printer probe
- *
- * Logic:
- * 1) If no port address was given, use the bios detected ports
- * and autodetect what ports the printers are on.
- * 2) Otherwise, probe the data port at the address given,
- * using the method in Rod Grimes' port probe.
- * (Much code ripped off directly from Rod's probe.)
- *
- * Comments from Rod's probe:
- * Logic:
- * 1) You should be able to write to and read back the same value
- * to the data port. Do an alternating zeros, alternating ones,
- * walking zero, and walking one test to check for stuck bits.
- *
- * 2) You should be able to write to and read back the same value
- * to the control port lower 5 bits, the upper 3 bits are reserved
- * per the IBM PC technical reference manauls and different boards
- * do different things with them. Do an alternating zeros, alternating
- * ones, walking zero, and walking one test to check for stuck bits.
- *
- * Some printers drag the strobe line down when the are powered off
- * so this bit has been masked out of the control port test.
- *
- * XXX Some printers may not like a fast pulse on init or strobe, I
- * don't know at this point, if that becomes a problem these bits
- * should be turned off in the mask byte for the control port test.
- *
- * We are finally left with a mask of 0x14, due to some printers
- * being adamant about holding other bits high ........
- *
- * Before probing the control port, we write a 0 to the data port -
- * If not, some printers chuck out garbage when the strobe line
- * gets toggled.
- *
- * 3) Set the data and control ports to a value of 0
- *
- * This probe routine has been tested on Epson Lx-800, HP LJ3P,
- * Epson FX-1170 and C.Itoh 8510RM
- * printers.
- * Quick exit on fail added.
- */
-
-int
-lpt_probe(device_t dev)
-{
-#ifdef PC98
-#define PC98_OLD_LPT 0x40
-#define PC98_IEEE_1284_FUNCTION 0x149
- int rid;
- struct resource *res;
-
- /* Check isapnp ids */
- if (isa_get_vendorid(dev))
- return ENXIO;
-
- rid = 0;
- res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, lpt_iat, 4,
- RF_ACTIVE);
- if (res == NULL)
- return ENXIO;
- isa_load_resourcev(res, lpt_iat, 4);
-
- if (isa_get_port(dev) == PC98_OLD_LPT) {
- unsigned int pc98_ieee_mode, tmp;
-
- tmp = inb(PC98_IEEE_1284_FUNCTION);
- pc98_ieee_mode = tmp;
- if ((tmp & 0x10) == 0x10) {
- outb(PC98_IEEE_1284_FUNCTION, tmp & ~0x10);
- tmp = inb(PC98_IEEE_1284_FUNCTION);
- if ((tmp & 0x10) != 0x10) {
- outb(PC98_IEEE_1284_FUNCTION, pc98_ieee_mode);
- bus_release_resource(dev, SYS_RES_IOPORT, rid,
- res);
- return ENXIO;
- }
- }
- }
-
- bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
- return 0;
-#else
- int port;
- static short next_bios_lpt = 0;
- int status;
- static u_char testbyte[18] = {
- 0x55, /* alternating zeros */
- 0xaa, /* alternating ones */
- 0xfe, 0xfd, 0xfb, 0xf7,
- 0xef, 0xdf, 0xbf, 0x7f, /* walking zero */
- 0x01, 0x02, 0x04, 0x08,
- 0x10, 0x20, 0x40, 0x80 /* walking one */
- };
- int i;
-
- /*
- * Make sure there is some way for lptopen to see that
- * the port is not configured
- * This 0 will remain if the port isn't attached
- */
- (lpt_sc + dvp->id_unit)->sc_port = 0;
-
- status = IO_LPTSIZE;
- /* If port not specified, use bios list */
- if(dvp->id_iobase < 0) { /* port? */
- if((next_bios_lpt < BIOS_MAX_LPT) &&
- (*(BIOS_PORTS+next_bios_lpt) != 0) ) {
- dvp->id_iobase = *(BIOS_PORTS+next_bios_lpt++);
- goto end_probe;
- } else
- return (0);
- }
-
- /* Port was explicitly specified */
- /* This allows probing of ports unknown to the BIOS */
- port = dvp->id_iobase + lpt_data;
- for (i = 0; i < 18; i++) {
- if (!lpt_port_test(port, testbyte[i], 0xff)) {
- status = 0;
- goto end_probe;
- }
- }
-
-end_probe:
- /* write 0's to control and data ports */
- outb(dvp->id_iobase+lpt_data, 0);
- outb(dvp->id_iobase+lpt_control, 0);
-
- return (status);
-#endif
-}
-
-/* XXX Todo - try and detect if interrupt is working */
-int
-lpt_attach(device_t dev)
-{
- int rid, unit;
- struct lpt_softc *sc;
-
- unit = device_get_unit(dev);
- sc = device_get_softc(dev);
-
- rid = 0;
- sc->res_port = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid,
- lpt_iat, 4, RF_ACTIVE);
- if (sc->res_port == NULL)
- return ENXIO;
- isa_load_resourcev(sc->res_port, lpt_iat, 4);
-
- sc->sc_port = rman_get_start(sc->res_port);
- sc->sc_primed = 0; /* not primed yet */
-#ifdef PC98
- outb(sc->sc_port+lpt_pstb_ctrl, LPC_DIS_PSTB); /* PSTB disable */
- outb(sc->sc_port+lpt_control, LPC_MODE8255); /* 8255 mode set */
- outb(sc->sc_port+lpt_control, LPC_NIRQ8); /* IRQ8 inactive */
- outb(sc->sc_port+lpt_control, LPC_NPSTB); /* PSTB inactive */
- outb(sc->sc_port+lpt_pstb_ctrl, LPC_EN_PSTB); /* PSTB enable */
-#else
- outb(sc->sc_port+lpt_control, LPC_NINIT);
-#endif
-
- sc->sc_irq = 0;
- if (isa_get_irq(dev) != -1) {
- rid = 0;
- sc->res_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
- 0, ~0, 1, RF_ACTIVE);
- if (sc->res_irq == NULL) {
- bus_release_resource(dev, SYS_RES_IOPORT, 0,
- sc->res_port);
- return ENXIO;
- }
- if (bus_setup_intr(dev, sc->res_irq, INTR_TYPE_TTY, lpt_intr,
- sc, &sc->sc_ih)) {
- bus_release_resource(dev, SYS_RES_IOPORT, 0,
- sc->res_port);
- bus_release_resource(dev, SYS_RES_IRQ, 0,
- sc->res_irq);
- return ENXIO;
- }
- sc->sc_irq = LP_HAS_IRQ | LP_USE_IRQ | LP_ENABLE_IRQ;
- device_printf(dev, "Interrupt-driven port");
- }
-
- /* XXX what to do about the flags in the minor number? */
- make_dev(&lpt_cdevsw, unit, UID_ROOT, GID_WHEEL, 0600, "lpt%d", unit);
- make_dev(&lpt_cdevsw, unit | LP_BYPASS,
- UID_ROOT, GID_WHEEL, 0600, "lpctl%d", unit);
-
- return 0;
-}
-
-/*
- * lptopen -- reset the printer, then wait until it's selected and not busy.
- * If LP_BYPASS flag is selected, then we do not try to select the
- * printer -- this is just used for passing ioctls.
- */
-
-static int
-lptopen (dev_t dev, int flags, int fmt, struct thread *td)
-{
- struct lpt_softc *sc;
- int s;
-#ifdef PC98
- int port;
-#else
- int trys, port;
-#endif
-
- sc = devclass_get_softc(olpt_devclass, LPTUNIT(minor(dev)));
- if (sc->sc_port == 0)
- return (ENXIO);
-
- if (sc->sc_state) {
- lprintf(("lp: still open %x\n", sc->sc_state));
- return(EBUSY);
- } else
- sc->sc_state |= INIT;
-
- sc->sc_flags = LPTFLAGS(minor(dev));
-
- /* Check for open with BYPASS flag set. */
- if (sc->sc_flags & LP_BYPASS) {
- sc->sc_state = OPEN;
- return(0);
- }
-
- s = spltty();
- lprintf(("lp flags 0x%x\n", sc->sc_flags));
- port = sc->sc_port;
-
- /* set IRQ status according to ENABLE_IRQ flag */
- if (sc->sc_irq & LP_ENABLE_IRQ)
- sc->sc_irq |= LP_USE_IRQ;
- else
- sc->sc_irq &= ~LP_USE_IRQ;
-
- /* init printer */
-#ifndef PC98
- if ((sc->sc_flags & LP_NO_PRIME) == 0) {
- if((sc->sc_flags & LP_PRIMEOPEN) || sc->sc_primed == 0) {
- outb(port+lpt_control, 0);
- sc->sc_primed++;
- DELAY(500);
- }
- }
-
- outb (port+lpt_control, LPC_SEL|LPC_NINIT);
-
- /* wait till ready (printer running diagnostics) */
- trys = 0;
- do {
- /* ran out of waiting for the printer */
- if (trys++ >= LPINITRDY*4) {
- splx(s);
- sc->sc_state = 0;
- lprintf(("status %x\n", inb(port+lpt_status)));
- return (EBUSY);
- }
-
- /* wait 1/4 second, give up if we get a signal */
- if (tsleep (sc, LPPRI|PCATCH, "lptinit", hz/4) !=
- EWOULDBLOCK) {
- sc->sc_state = 0;
- splx(s);
- return (EBUSY);
- }
-
- /* is printer online and ready for output */
- } while ((inb(port+lpt_status) & (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)) !=
- (LPS_SEL|LPS_NBSY|LPS_NERR));
-
- sc->sc_control = LPC_SEL|LPC_NINIT;
- if (sc->sc_flags & LP_AUTOLF)
- sc->sc_control |= LPC_AUTOL;
-
- /* enable interrupt if interrupt-driven */
- if (sc->sc_irq & LP_USE_IRQ)
- sc->sc_control |= LPC_ENA;
-
- outb(port+lpt_control, sc->sc_control);
-#endif
-
- sc->sc_state = OPEN;
- sc->sc_inbuf = geteblk(BUFSIZE);
- sc->sc_xfercnt = 0;
- splx(s);
-
- /* only use timeout if using interrupt */
- lprintf(("irq %x\n", sc->sc_irq));
- if (sc->sc_irq & LP_USE_IRQ) {
- sc->sc_state |= TOUT;
- timeout (lptout, (caddr_t)sc,
- (sc->sc_backoff = hz/LPTOUTINITIAL));
- }
-
- lprintf(("opened.\n"));
- return(0);
-}
-
-static void
-lptout (void *arg)
-{
- struct lpt_softc *sc = arg;
- int pl;
-
- lprintf(("T %x ", inb(sc->sc_port+lpt_status)));
- if (sc->sc_state & OPEN) {
- sc->sc_backoff++;
- if (sc->sc_backoff > hz/LPTOUTMAX)
- sc->sc_backoff = sc->sc_backoff > hz/LPTOUTMAX;
- timeout (lptout, (caddr_t)sc, sc->sc_backoff);
- } else
- sc->sc_state &= ~TOUT;
-
- if (sc->sc_state & ERROR)
- sc->sc_state &= ~ERROR;
-
- /*
- * Avoid possible hangs do to missed interrupts
- */
- if (sc->sc_xfercnt) {
- pl = spltty();
- lpt_intr(sc);
- splx(pl);
- } else {
- sc->sc_state &= ~OBUSY;
- wakeup(sc);
- }
-}
-
-/*
- * lptclose -- close the device, free the local line buffer.
- *
- * Check for interrupted write call added.
- */
-
-static int
-lptclose(dev_t dev, int flags, int fmt, struct thread *td)
-{
- struct lpt_softc *sc;
-#ifndef PC98
- int port;
-#endif
-
- sc = devclass_get_softc(olpt_devclass, LPTUNIT(minor(dev)));
- if(sc->sc_flags & LP_BYPASS)
- goto end_close;
-
-#ifndef PC98
- port = sc->sc_port;
-#endif
- sc->sc_state &= ~OPEN;
-
-#ifndef PC98
- /* if the last write was interrupted, don't complete it */
- if((!(sc->sc_state & INTERRUPTED)) && (sc->sc_irq & LP_USE_IRQ))
- while ((inb(port+lpt_status) & (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)) !=
- (LPS_SEL|LPS_NBSY|LPS_NERR) || sc->sc_xfercnt)
- /* wait 1/4 second, give up if we get a signal */
- if (tsleep (sc, LPPRI|PCATCH,
- "lpclose", hz) != EWOULDBLOCK)
- break;
-
- outb(sc->sc_port+lpt_control, LPC_NINIT);
-#endif
- brelse(sc->sc_inbuf);
-
-end_close:
- sc->sc_state = 0;
- sc->sc_xfercnt = 0;
- lprintf(("closed.\n"));
- return(0);
-}
-
-/*
- * pushbytes()
- * Workhorse for actually spinning and writing bytes to printer
- * Derived from lpa.c
- * Originally by ?
- *
- * This code is only used when we are polling the port
- */
-static int
-pushbytes(struct lpt_softc * sc)
-{
- int spin, err, tic;
- char ch;
- int port = sc->sc_port;
-
- lprintf(("p"));
- /* loop for every character .. */
- while (sc->sc_xfercnt > 0) {
- /* printer data */
- ch = *(sc->sc_cp);
- sc->sc_cp++;
- sc->sc_xfercnt--;
-
- /*
- * Wait for printer ready.
- * Loop 20 usecs testing BUSY bit, then sleep
- * for exponentially increasing timeout. (vak)
- */
- for (spin=0; NOT_READY(port+lpt_status) && spin<MAX_SPIN; ++spin)
- DELAY(1); /* XXX delay is NOT this accurate! */
- if (spin >= MAX_SPIN) {
- tic = 0;
- while (NOT_READY(port+lpt_status)) {
- /*
- * Now sleep, every cycle a
- * little longer ..
- */
- tic = tic + tic + 1;
- /*
- * But no more than 10 seconds. (vak)
- */
- if (tic > MAX_SLEEP)
- tic = MAX_SLEEP;
- err = tsleep(sc, LPPRI,
- "lptpoll", tic);
- if (err != EWOULDBLOCK) {
- return (err);
- }
- }
- }
-
- /* output data */
- outb(port+lpt_data, ch);
-#ifdef PC98
- DELAY(1);
- outb(port+lpt_control, LPC_PSTB);
- DELAY(1);
- outb(port+lpt_control, LPC_NPSTB);
-#else
- /* strobe */
- outb(port+lpt_control, sc->sc_control|LPC_STB);
- outb(port+lpt_control, sc->sc_control);
-#endif
-
- }
- return(0);
-}
-
-/*
- * lptwrite --copy a line from user space to a local buffer, then call
- * putc to get the chars moved to the output queue.
- *
- * Flagging of interrupted write added.
- */
-
-static int
-lptwrite(dev_t dev, struct uio * uio, int ioflag)
-{
- register unsigned n;
- int pl, err;
- struct lpt_softc *sc;
-
- sc = devclass_get_softc(olpt_devclass, LPTUNIT(minor(dev)));
- if(sc->sc_flags & LP_BYPASS) {
- /* we can't do writes in bypass mode */
- return(EPERM);
- }
-
- sc->sc_state &= ~INTERRUPTED;
- while ((n = min(BUFSIZE, uio->uio_resid)) != 0) {
- sc->sc_cp = sc->sc_inbuf->b_data ;
- uiomove(sc->sc_cp, n, uio);
- sc->sc_xfercnt = n ;
- while ((sc->sc_xfercnt > 0)&&(sc->sc_irq & LP_USE_IRQ)) {
- lprintf(("i"));
- /* if the printer is ready for a char, */
- /* give it one */
- if ((sc->sc_state & OBUSY) == 0){
- lprintf(("\nC %d. ", sc->sc_xfercnt));
- pl = spltty();
- lpt_intr(sc);
- (void) splx(pl);
- }
- lprintf(("W "));
- if (sc->sc_state & OBUSY)
- if ((err = tsleep (sc,
- LPPRI|PCATCH, "lpwrite", 0))) {
- sc->sc_state |= INTERRUPTED;
- return(err);
- }
- }
- /* check to see if we must do a polled write */
- if(!(sc->sc_irq & LP_USE_IRQ) && (sc->sc_xfercnt)) {
- lprintf(("p"));
- if((err = pushbytes(sc)))
- return(err);
- }
- }
- return(0);
-}
-
-/*
- * lptintr -- handle printer interrupts which occur when the printer is
- * ready to accept another char.
- *
- * do checking for interrupted write call.
- */
-
-static void
-lpt_intr(void *arg)
-{
-}
-
-static int
-lptioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct thread *td)
-{
- int error = 0;
- struct lpt_softc *sc;
- u_int unit = LPTUNIT(minor(dev));
- u_char old_sc_irq; /* old printer IRQ status */
-
- sc = devclass_get_softc(olpt_devclass, unit);
-
- switch (cmd) {
- case LPT_IRQ :
- if(sc->sc_irq & LP_HAS_IRQ) {
- /*
- * NOTE:
- * If the IRQ status is changed,
- * this will only be visible on the
- * next open.
- *
- * If interrupt status changes,
- * this gets syslog'd.
- */
- old_sc_irq = sc->sc_irq;
- if(*(int*)data == 0)
- sc->sc_irq &= (~LP_ENABLE_IRQ);
- else
- sc->sc_irq |= LP_ENABLE_IRQ;
- if (old_sc_irq != sc->sc_irq )
- log(LOG_NOTICE, "lpt%c switched to %s mode\n",
- (char)unit+'0',
- (sc->sc_irq & LP_ENABLE_IRQ)?
- "interrupt-driven":"polled");
- } else /* polled port */
- error = EOPNOTSUPP;
- break;
- default:
- error = ENODEV;
- }
-
- return(error);
-}
diff --git a/sys/pc98/cbus/pckbd.c b/sys/pc98/cbus/pckbd.c
deleted file mode 100644
index 37fe6d258400..000000000000
--- a/sys/pc98/cbus/pckbd.c
+++ /dev/null
@@ -1,965 +0,0 @@
-/*
- * Copyright (c) 1999 FreeBSD(98) port team.
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include "opt_kbd.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/module.h>
-#include <sys/bus.h>
-#include <machine/bus.h>
-#include <sys/rman.h>
-#include <sys/kbio.h>
-
-#include <machine/resource.h>
-
-#include <dev/kbd/kbdreg.h>
-
-#include <pc98/pc98/pc98.h>
-
-#include <isa/isavar.h>
-
-#define DRIVER_NAME "pckbd"
-
-/* device configuration flags */
-#define KB_CONF_FAIL_IF_NO_KBD (1 << 0) /* don't install if no kbd is found */
-
-static devclass_t pckbd_devclass;
-
-static int pckbdprobe(device_t dev);
-static int pckbdattach(device_t dev);
-static int pckbdresume(device_t dev);
-static void pckbd_isa_intr(void *arg);
-
-static device_method_t pckbd_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, pckbdprobe),
- DEVMETHOD(device_attach, pckbdattach),
- DEVMETHOD(device_resume, pckbdresume),
- { 0, 0 }
-};
-
-static driver_t pckbd_driver = {
- DRIVER_NAME,
- pckbd_methods,
- 1,
-};
-
-DRIVER_MODULE(pckbd, isa, pckbd_driver, pckbd_devclass, 0, 0);
-
-static bus_addr_t pckbd_iat[] = {0, 2};
-
-static int pckbd_probe_unit(int unit, int port, int irq,
- int flags);
-static int pckbd_attach_unit(int unit, keyboard_t **kbd,
- int port, int irq, int flags);
-static timeout_t pckbd_timeout;
-
-
-static int
-pckbdprobe(device_t dev)
-{
- struct resource *res;
- int error, rid;
-
- /* Check isapnp ids */
- if (isa_get_vendorid(dev))
- return (ENXIO);
-
- device_set_desc(dev, "PC-98 Keyboard");
-
- rid = 0;
- res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, pckbd_iat, 2,
- RF_ACTIVE);
- if (res == NULL)
- return ENXIO;
- isa_load_resourcev(res, pckbd_iat, 2);
-
- error = pckbd_probe_unit(device_get_unit(dev),
- isa_get_port(dev),
- (1 << isa_get_irq(dev)),
- device_get_flags(dev));
-
- bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
-
- return (error);
-}
-
-static int
-pckbdattach(device_t dev)
-{
- keyboard_t *kbd;
- void *ih;
- struct resource *res;
- int error, rid;
-
- rid = 0;
- res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, pckbd_iat, 2,
- RF_ACTIVE);
- if (res == NULL)
- return ENXIO;
- isa_load_resourcev(res, pckbd_iat, 2);
-
- error = pckbd_attach_unit(device_get_unit(dev), &kbd,
- isa_get_port(dev),
- (1 << isa_get_irq(dev)),
- device_get_flags(dev));
-
- rid = 0;
- res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, RF_ACTIVE);
- if (res == NULL)
- return ENXIO;
- BUS_SETUP_INTR(device_get_parent(dev), dev, res, INTR_TYPE_TTY,
- pckbd_isa_intr, kbd, &ih);
-
- return 0;
-}
-
-static int
-pckbdresume(device_t dev)
-{
- keyboard_t *kbd;
-
- kbd = kbd_get_keyboard(kbd_find_keyboard(DRIVER_NAME,
- device_get_unit(dev)));
- if (kbd)
- (*kbdsw[kbd->kb_index]->clear_state)(kbd);
-
- return (0);
-}
-
-static void
-pckbd_isa_intr(void *arg)
-{
- keyboard_t *kbd = arg;
-
- (*kbdsw[kbd->kb_index]->intr)(kbd, NULL);
-}
-
-static int
-pckbd_probe_unit(int unit, int port, int irq, int flags)
-{
- keyboard_switch_t *sw;
- int args[2];
- int error;
-
- sw = kbd_get_switch(DRIVER_NAME);
- if (sw == NULL)
- return ENXIO;
-
- args[0] = port;
- args[1] = irq;
- error = (*sw->probe)(unit, args, flags);
- if (error)
- return error;
- return 0;
-}
-
-static int
-pckbd_attach_unit(int unit, keyboard_t **kbd, int port, int irq, int flags)
-{
- keyboard_switch_t *sw;
- int args[2];
- int error;
-
- sw = kbd_get_switch(DRIVER_NAME);
- if (sw == NULL)
- return ENXIO;
-
- /* reset, initialize and enable the device */
- args[0] = port;
- args[1] = irq;
- *kbd = NULL;
- error = (*sw->probe)(unit, args, flags);
- if (error)
- return error;
- error = (*sw->init)(unit, kbd, args, flags);
- if (error)
- return error;
- (*sw->enable)(*kbd);
-
-#ifdef KBD_INSTALL_CDEV
- /* attach a virtual keyboard cdev */
- error = kbd_attach(*kbd);
- if (error)
- return error;
-#endif /* KBD_INSTALL_CDEV */
-
- /*
- * This is a kludge to compensate for lost keyboard interrupts.
- * A similar code used to be in syscons. See below. XXX
- */
- pckbd_timeout(*kbd);
-
- if (bootverbose)
- (*sw->diag)(*kbd, bootverbose);
-
- return 0;
-}
-
-static void
-pckbd_timeout(void *arg)
-{
- keyboard_t *kbd;
- int s;
-
- /* The following comments are extracted from syscons.c (1.287) */
- /*
- * With release 2.1 of the Xaccel server, the keyboard is left
- * hanging pretty often. Apparently an interrupt from the
- * keyboard is lost, and I don't know why (yet).
- * This ugly hack calls scintr if input is ready for the keyboard
- * and conveniently hides the problem. XXX
- */
- /*
- * Try removing anything stuck in the keyboard controller; whether
- * it's a keyboard scan code or mouse data. `scintr()' doesn't
- * read the mouse data directly, but `kbdio' routines will, as a
- * side effect.
- */
- s = spltty();
- kbd = (keyboard_t *)arg;
- if ((*kbdsw[kbd->kb_index]->lock)(kbd, TRUE)) {
- /*
- * We have seen the lock flag is not set. Let's reset
- * the flag early, otherwise the LED update routine fails
- * which may want the lock during the interrupt routine.
- */
- (*kbdsw[kbd->kb_index]->lock)(kbd, FALSE);
- if ((*kbdsw[kbd->kb_index]->check_char)(kbd))
- (*kbdsw[kbd->kb_index]->intr)(kbd, NULL);
- }
- splx(s);
- timeout(pckbd_timeout, arg, hz/10);
-}
-
-/* LOW-LEVEL */
-
-#include <sys/limits.h>
-
-#define PC98KBD_DEFAULT 0
-
-typedef caddr_t KBDC;
-
-typedef struct pckbd_state {
- KBDC kbdc; /* keyboard controller */
- int ks_mode; /* input mode (K_XLATE,K_RAW,K_CODE) */
- int ks_flags; /* flags */
-#define COMPOSE (1 << 0)
- int ks_state; /* shift/lock key state */
- int ks_accents; /* accent key index (> 0) */
- u_int ks_composed_char; /* composed char code (> 0) */
-} pckbd_state_t;
-
-/* keyboard driver declaration */
-static int pckbd_configure(int flags);
-static kbd_probe_t pckbd_probe;
-static kbd_init_t pckbd_init;
-static kbd_term_t pckbd_term;
-static kbd_intr_t pckbd_intr;
-static kbd_test_if_t pckbd_test_if;
-static kbd_enable_t pckbd_enable;
-static kbd_disable_t pckbd_disable;
-static kbd_read_t pckbd_read;
-static kbd_check_t pckbd_check;
-static kbd_read_char_t pckbd_read_char;
-static kbd_check_char_t pckbd_check_char;
-static kbd_ioctl_t pckbd_ioctl;
-static kbd_lock_t pckbd_lock;
-static kbd_clear_state_t pckbd_clear_state;
-static kbd_get_state_t pckbd_get_state;
-static kbd_set_state_t pckbd_set_state;
-static kbd_poll_mode_t pckbd_poll;
-
-keyboard_switch_t pckbdsw = {
- pckbd_probe,
- pckbd_init,
- pckbd_term,
- pckbd_intr,
- pckbd_test_if,
- pckbd_enable,
- pckbd_disable,
- pckbd_read,
- pckbd_check,
- pckbd_read_char,
- pckbd_check_char,
- pckbd_ioctl,
- pckbd_lock,
- pckbd_clear_state,
- pckbd_get_state,
- pckbd_set_state,
- genkbd_get_fkeystr,
- pckbd_poll,
- genkbd_diag,
-};
-
-KEYBOARD_DRIVER(pckbd, pckbdsw, pckbd_configure);
-
-struct kbdc_softc {
- int port; /* base port address */
- int lock; /* FIXME: XXX not quite a semaphore... */
-};
-
-/* local functions */
-static int probe_keyboard(KBDC kbdc, int flags);
-static int init_keyboard(KBDC kbdc, int *type, int flags);
-static KBDC kbdc_open(int port);
-static int kbdc_lock(KBDC kbdc, int lock);
-static int kbdc_data_ready(KBDC kbdc);
-static int read_kbd_data(KBDC kbdc);
-static int read_kbd_data_no_wait(KBDC kbdc);
-static int wait_for_kbd_data(struct kbdc_softc *kbdc);
-
-/* local variables */
-
-/* the initial key map, accent map and fkey strings */
-#include <dev/kbd/kbdtables.h>
-
-/* structures for the default keyboard */
-static keyboard_t default_kbd;
-static pckbd_state_t default_kbd_state;
-static keymap_t default_keymap;
-static accentmap_t default_accentmap;
-static fkeytab_t default_fkeytab[NUM_FKEYS];
-
-/*
- * The back door to the keyboard driver!
- * This function is called by the console driver, via the kbdio module,
- * to tickle keyboard drivers when the low-level console is being initialized.
- * Almost nothing in the kernel has been initialied yet. Try to probe
- * keyboards if possible.
- * NOTE: because of the way the low-level conole is initialized, this routine
- * may be called more than once!!
- */
-static int
-pckbd_configure(int flags)
-{
- keyboard_t *kbd;
- int arg[2];
- int i;
-
- /* XXX: a kludge to obtain the device configuration flags */
- if (resource_int_value(DRIVER_NAME, 0, "flags", &i) == 0) {
- flags |= i;
- /* if the driver is disabled, unregister the keyboard if any */
- if (resource_int_value(DRIVER_NAME, 0, "disabled", &i) == 0
- && i != 0) {
- i = kbd_find_keyboard(DRIVER_NAME, PC98KBD_DEFAULT);
- if (i >= 0) {
- kbd = kbd_get_keyboard(i);
- kbd_unregister(kbd);
- kbd->kb_flags &= ~KB_REGISTERED;
- return 0;
- }
- }
- }
-
- /* probe the default keyboard */
- arg[0] = -1;
- arg[1] = -1;
- kbd = NULL;
- if (pckbd_probe(PC98KBD_DEFAULT, arg, flags))
- return 0;
- if (pckbd_init(PC98KBD_DEFAULT, &kbd, arg, flags))
- return 0;
-
- /* return the number of found keyboards */
- return 1;
-}
-
-/* low-level functions */
-
-/* detect a keyboard */
-static int
-pckbd_probe(int unit, void *arg, int flags)
-{
- KBDC kbdc;
- int *data = (int *)arg;
-
- if (unit != PC98KBD_DEFAULT)
- return ENXIO;
- if (KBD_IS_PROBED(&default_kbd))
- return 0;
-
- kbdc = kbdc_open(data[0]);
- if (kbdc == NULL)
- return ENXIO;
- if (probe_keyboard(kbdc, flags)) {
- if (flags & KB_CONF_FAIL_IF_NO_KBD)
- return ENXIO;
- }
- return 0;
-}
-
-/* reset and initialize the device */
-static int
-pckbd_init(int unit, keyboard_t **kbdp, void *arg, int flags)
-{
- keyboard_t *kbd;
- pckbd_state_t *state;
- keymap_t *keymap;
- accentmap_t *accmap;
- fkeytab_t *fkeymap;
- int fkeymap_size;
- int *data = (int *)arg;
-
- if (unit != PC98KBD_DEFAULT) /* shouldn't happen */
- return ENXIO;
-
- *kbdp = kbd = &default_kbd;
- state = &default_kbd_state;
- if (!KBD_IS_PROBED(kbd)) {
- keymap = &default_keymap;
- accmap = &default_accentmap;
- fkeymap = default_fkeytab;
- fkeymap_size =
- sizeof(default_fkeytab)/sizeof(default_fkeytab[0]);
-
- state->kbdc = kbdc_open(data[0]);
- if (state->kbdc == NULL)
- return ENXIO;
- kbd_init_struct(kbd, DRIVER_NAME, KB_OTHER, unit, flags,
- data[0], IO_KBDSIZE);
- bcopy(&key_map, keymap, sizeof(key_map));
- bcopy(&accent_map, accmap, sizeof(accent_map));
- bcopy(fkey_tab, fkeymap,
- imin(fkeymap_size*sizeof(fkeymap[0]), sizeof(fkey_tab)));
- kbd_set_maps(kbd, keymap, accmap, fkeymap, fkeymap_size);
- kbd->kb_data = (void *)state;
-
- if (probe_keyboard(state->kbdc, flags)) {/* shouldn't happen */
- if (flags & KB_CONF_FAIL_IF_NO_KBD)
- return ENXIO;
- } else {
- KBD_FOUND_DEVICE(kbd);
- }
- pckbd_clear_state(kbd);
- state->ks_mode = K_XLATE;
- KBD_PROBE_DONE(kbd);
- }
- if (!KBD_IS_INITIALIZED(kbd) && !(flags & KB_CONF_PROBE_ONLY)) {
- if (KBD_HAS_DEVICE(kbd)
- && init_keyboard(state->kbdc, &kbd->kb_type, kbd->kb_config)
- && (kbd->kb_config & KB_CONF_FAIL_IF_NO_KBD))
- return ENXIO;
- pckbd_ioctl(kbd, KDSETLED, (caddr_t)&state->ks_state);
- KBD_INIT_DONE(kbd);
- }
- if (!KBD_IS_CONFIGURED(kbd)) {
- if (kbd_register(kbd) < 0)
- return ENXIO;
- KBD_CONFIG_DONE(kbd);
- }
-
- return 0;
-}
-
-/* finish using this keyboard */
-static int
-pckbd_term(keyboard_t *kbd)
-{
- kbd_unregister(kbd);
- return 0;
-}
-
-/* keyboard interrupt routine */
-static int
-pckbd_intr(keyboard_t *kbd, void *arg)
-{
- int c;
-
- if (KBD_IS_ACTIVE(kbd) && KBD_IS_BUSY(kbd)) {
- /* let the callback function to process the input */
- (*kbd->kb_callback.kc_func)(kbd, KBDIO_KEYINPUT,
- kbd->kb_callback.kc_arg);
- } else {
- /* read and discard the input; no one is waiting for input */
- do {
- c = pckbd_read_char(kbd, FALSE);
- } while (c != NOKEY);
- }
- return 0;
-}
-
-/* test the interface to the device */
-static int
-pckbd_test_if(keyboard_t *kbd)
-{
- return 0;
-}
-
-/*
- * Enable the access to the device; until this function is called,
- * the client cannot read from the keyboard.
- */
-static int
-pckbd_enable(keyboard_t *kbd)
-{
- int s;
-
- s = spltty();
- KBD_ACTIVATE(kbd);
- splx(s);
- return 0;
-}
-
-/* disallow the access to the device */
-static int
-pckbd_disable(keyboard_t *kbd)
-{
- int s;
-
- s = spltty();
- KBD_DEACTIVATE(kbd);
- splx(s);
- return 0;
-}
-
-/* read one byte from the keyboard if it's allowed */
-static int
-pckbd_read(keyboard_t *kbd, int wait)
-{
- int c;
-
- if (wait)
- c = read_kbd_data(((pckbd_state_t *)kbd->kb_data)->kbdc);
- else
- c = read_kbd_data_no_wait(((pckbd_state_t *)kbd->kb_data)->kbdc);
- if (c != -1)
- ++kbd->kb_count;
- return (KBD_IS_ACTIVE(kbd) ? c : -1);
-}
-
-/* check if data is waiting */
-static int
-pckbd_check(keyboard_t *kbd)
-{
- if (!KBD_IS_ACTIVE(kbd))
- return FALSE;
- return kbdc_data_ready(((pckbd_state_t *)kbd->kb_data)->kbdc);
-}
-
-/* read char from the keyboard */
-static u_int
-pckbd_read_char(keyboard_t *kbd, int wait)
-{
- pckbd_state_t *state;
- u_int action;
- int scancode;
- int keycode;
-
- state = (pckbd_state_t *)kbd->kb_data;
-next_code:
- /* do we have a composed char to return? */
- if (!(state->ks_flags & COMPOSE) && (state->ks_composed_char > 0)) {
- action = state->ks_composed_char;
- state->ks_composed_char = 0;
- if (action > UCHAR_MAX)
- return ERRKEY;
- return action;
- }
-
- /* see if there is something in the keyboard port */
- if (wait) {
- do {
- scancode = read_kbd_data(state->kbdc);
- } while (scancode == -1);
- } else {
- scancode = read_kbd_data_no_wait(state->kbdc);
- if (scancode == -1)
- return NOKEY;
- }
- ++kbd->kb_count;
-
-#if 0
- printf("pckbd_read_char(): scancode:0x%x\n", scancode);
-#endif
-
- /* return the byte as is for the K_RAW mode */
- if (state->ks_mode == K_RAW)
- return scancode;
-
- /* translate the scan code into a keycode */
- keycode = scancode & 0x7F;
- switch(scancode) {
- case 0xF3: /* GRPH (compose key) released */
- if (state->ks_flags & COMPOSE) {
- state->ks_flags &= ~COMPOSE;
- if (state->ks_composed_char > UCHAR_MAX)
- state->ks_composed_char = 0;
- }
- break;
- case 0x73: /* GRPH (compose key) pressed */
- if (!(state->ks_flags & COMPOSE)) {
- state->ks_flags |= COMPOSE;
- state->ks_composed_char = 0;
- }
- break;
- }
-
- /* return the key code in the K_CODE mode */
- if (state->ks_mode == K_CODE)
- return (keycode | (scancode & 0x80));
-
- /* compose a character code */
- if (state->ks_flags & COMPOSE) {
- switch (scancode) {
- /* key pressed, process it */
- case 0x42: case 0x43: case 0x44: /* keypad 7,8,9 */
- state->ks_composed_char *= 10;
- state->ks_composed_char += scancode - 0x3B;
- if (state->ks_composed_char > UCHAR_MAX)
- return ERRKEY;
- goto next_code;
- case 0x46: case 0x47: case 0x48: /* keypad 4,5,6 */
- state->ks_composed_char *= 10;
- state->ks_composed_char += scancode - 0x42;
- if (state->ks_composed_char > UCHAR_MAX)
- return ERRKEY;
- goto next_code;
- case 0x4A: case 0x4B: case 0x4C: /* keypad 1,2,3 */
- state->ks_composed_char *= 10;
- state->ks_composed_char += scancode - 0x49;
- if (state->ks_composed_char > UCHAR_MAX)
- return ERRKEY;
- goto next_code;
- case 0x4E: /* keypad 0 */
- state->ks_composed_char *= 10;
- if (state->ks_composed_char > UCHAR_MAX)
- return ERRKEY;
- goto next_code;
-
- /* key released, no interest here */
- case 0xC2: case 0xC3: case 0xC4: /* keypad 7,8,9 */
- case 0xC6: case 0xC7: case 0xC8: /* keypad 4,5,6 */
- case 0xCA: case 0xCB: case 0xCC: /* keypad 1,2,3 */
- case 0xCE: /* keypad 0 */
- goto next_code;
-
- case 0x73: /* GRPH key */
- break;
-
- default:
- if (state->ks_composed_char > 0) {
- state->ks_flags &= ~COMPOSE;
- state->ks_composed_char = 0;
- return ERRKEY;
- }
- break;
- }
- }
-
- /* keycode to key action */
- action = genkbd_keyaction(kbd, keycode, scancode & 0x80,
- &state->ks_state, &state->ks_accents);
- if (action == NOKEY)
- goto next_code;
- else
- return action;
-}
-
-/* check if char is waiting */
-static int
-pckbd_check_char(keyboard_t *kbd)
-{
- pckbd_state_t *state;
-
- if (!KBD_IS_ACTIVE(kbd))
- return FALSE;
- state = (pckbd_state_t *)kbd->kb_data;
- if (!(state->ks_flags & COMPOSE) && (state->ks_composed_char > 0))
- return TRUE;
- return kbdc_data_ready(state->kbdc);
-}
-
-/* some useful control functions */
-static int
-pckbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
-{
- pckbd_state_t *state = kbd->kb_data;
- int s;
- int i;
-
- s = spltty();
- switch (cmd) {
-
- case KDGKBMODE: /* get keyboard mode */
- *(int *)arg = state->ks_mode;
- break;
- case KDSKBMODE: /* set keyboard mode */
- switch (*(int *)arg) {
- case K_XLATE:
- if (state->ks_mode != K_XLATE) {
- /* make lock key state and LED state match */
- state->ks_state &= ~LOCK_MASK;
- state->ks_state |= KBD_LED_VAL(kbd);
- }
- /* FALLTHROUGH */
- case K_RAW:
- case K_CODE:
- if (state->ks_mode != *(int *)arg) {
- pckbd_clear_state(kbd);
- state->ks_mode = *(int *)arg;
- }
- break;
- default:
- splx(s);
- return EINVAL;
- }
- break;
-
- case KDGETLED: /* get keyboard LED */
- *(int *)arg = KBD_LED_VAL(kbd);
- break;
- case KDSETLED: /* set keyboard LED */
- /* NOTE: lock key state in ks_state won't be changed */
- if (*(int *)arg & ~LOCK_MASK) {
- splx(s);
- return EINVAL;
- }
- i = *(int *)arg;
- /* replace CAPS LED with ALTGR LED for ALTGR keyboards */
- if (kbd->kb_keymap->n_keys > ALTGR_OFFSET) {
- if (i & ALKED)
- i |= CLKED;
- else
- i &= ~CLKED;
- }
- KBD_LED_VAL(kbd) = *(int *)arg;
- break;
-
- case KDGKBSTATE: /* get lock key state */
- *(int *)arg = state->ks_state & LOCK_MASK;
- break;
- case KDSKBSTATE: /* set lock key state */
- if (*(int *)arg & ~LOCK_MASK) {
- splx(s);
- return EINVAL;
- }
- state->ks_state &= ~LOCK_MASK;
- state->ks_state |= *(int *)arg;
- splx(s);
- /* set LEDs and quit */
- return pckbd_ioctl(kbd, KDSETLED, arg);
-
- case KDSETRAD: /* set keyboard repeat rate (old interface)*/
- break;
- case KDSETREPEAT: /* set keyboard repeat rate (new interface) */
- break;
-
- case PIO_KEYMAP: /* set keyboard translation table */
- case PIO_KEYMAPENT: /* set keyboard translation table entry */
- case PIO_DEADKEYMAP: /* set accent key translation table */
- state->ks_accents = 0;
- /* FALLTHROUGH */
- default:
- splx(s);
- return genkbd_commonioctl(kbd, cmd, arg);
- }
-
- splx(s);
- return 0;
-}
-
-/* lock the access to the keyboard */
-static int
-pckbd_lock(keyboard_t *kbd, int lock)
-{
- return kbdc_lock(((pckbd_state_t *)kbd->kb_data)->kbdc, lock);
-}
-
-/* clear the internal state of the keyboard */
-static void
-pckbd_clear_state(keyboard_t *kbd)
-{
- pckbd_state_t *state;
-
- state = (pckbd_state_t *)kbd->kb_data;
- state->ks_flags = 0;
- state->ks_state &= LOCK_MASK; /* preserve locking key state */
- state->ks_accents = 0;
- state->ks_composed_char = 0;
-}
-
-/* save the internal state */
-static int
-pckbd_get_state(keyboard_t *kbd, void *buf, size_t len)
-{
- if (len == 0)
- return sizeof(pckbd_state_t);
- if (len < sizeof(pckbd_state_t))
- return -1;
- bcopy(kbd->kb_data, buf, sizeof(pckbd_state_t));
- return 0;
-}
-
-/* set the internal state */
-static int
-pckbd_set_state(keyboard_t *kbd, void *buf, size_t len)
-{
- if (len < sizeof(pckbd_state_t))
- return ENOMEM;
- if (((pckbd_state_t *)kbd->kb_data)->kbdc
- != ((pckbd_state_t *)buf)->kbdc)
- return ENOMEM;
- bcopy(buf, kbd->kb_data, sizeof(pckbd_state_t));
- return 0;
-}
-
-/* set polling mode */
-static int
-pckbd_poll(keyboard_t *kbd, int on)
-{
- return 0;
-}
-
-/* local functions */
-
-static int
-probe_keyboard(KBDC kbdc, int flags)
-{
- return 0;
-}
-
-static int
-init_keyboard(KBDC kbdc, int *type, int flags)
-{
- *type = KB_OTHER;
- return 0;
-}
-
-/* keyboard I/O routines */
-
-/* retry count */
-#ifndef KBD_MAXRETRY
-#define KBD_MAXRETRY 3
-#endif
-
-/* timing parameters */
-#ifndef KBD_RESETDELAY
-#define KBD_RESETDELAY 200 /* wait 200msec after kbd/mouse reset */
-#endif
-#ifndef KBD_MAXWAIT
-#define KBD_MAXWAIT 5 /* wait 5 times at most after reset */
-#endif
-
-/* I/O recovery time */
-#define KBDC_DELAYTIME 37
-#define KBDD_DELAYTIME 37
-
-/* I/O ports */
-#define KBD_STATUS_PORT 2 /* status port, read */
-#define KBD_DATA_PORT 0 /* data port, read */
-
-/* status bits (KBD_STATUS_PORT) */
-#define KBDS_BUFFER_FULL 0x0002
-
-/* macros */
-
-#define kbdcp(p) ((struct kbdc_softc *)(p))
-
-/* local variables */
-
-static struct kbdc_softc kbdc_softc[1] = { { 0 }, };
-
-/* associate a port number with a KBDC */
-
-static KBDC
-kbdc_open(int port)
-{
- if (port <= 0)
- port = IO_KBD;
-
- /* PC-98 has only one keyboard I/F */
- kbdc_softc[0].port = port;
- kbdc_softc[0].lock = FALSE;
- return (KBDC)&kbdc_softc[0];
-}
-
-/* set/reset polling lock */
-static int
-kbdc_lock(KBDC p, int lock)
-{
- int prevlock;
-
- prevlock = kbdcp(p)->lock;
- kbdcp(p)->lock = lock;
-
- return (prevlock != lock);
-}
-
-/* check if any data is waiting to be processed */
-static int
-kbdc_data_ready(KBDC p)
-{
- return (inb(kbdcp(p)->port + KBD_STATUS_PORT) & KBDS_BUFFER_FULL);
-}
-
-/* wait for data from the keyboard */
-static int
-wait_for_kbd_data(struct kbdc_softc *kbdc)
-{
- /* CPU will stay inside the loop for 200msec at most */
- int retry = 10000;
- int port = kbdc->port;
-
- while (!(inb(port + KBD_STATUS_PORT) & KBDS_BUFFER_FULL)) {
- DELAY(KBDD_DELAYTIME);
- DELAY(KBDC_DELAYTIME);
- if (--retry < 0)
- return 0;
- }
- DELAY(KBDD_DELAYTIME);
- return 1;
-}
-
-/* read one byte from the keyboard */
-static int
-read_kbd_data(KBDC p)
-{
- if (!wait_for_kbd_data(kbdcp(p)))
- return -1; /* timeout */
- DELAY(KBDC_DELAYTIME);
- return inb(kbdcp(p)->port + KBD_DATA_PORT);
-}
-
-/* read one byte from the keyboard, but return immediately if
- * no data is waiting
- */
-static int
-read_kbd_data_no_wait(KBDC p)
-{
- if (inb(kbdcp(p)->port + KBD_STATUS_PORT) & KBDS_BUFFER_FULL) {
- DELAY(KBDD_DELAYTIME);
- return inb(kbdcp(p)->port + KBD_DATA_PORT);
- }
- return -1; /* no data */
-}
diff --git a/sys/pc98/cbus/pcrtc.c b/sys/pc98/cbus/pcrtc.c
deleted file mode 100644
index bc03ea6a0b6b..000000000000
--- a/sys/pc98/cbus/pcrtc.c
+++ /dev/null
@@ -1,1146 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz and Don Ahn.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)clock.c 7.2 (Berkeley) 5/12/91
- * $FreeBSD$
- */
-
-/*
- * Routines to handle clock hardware.
- */
-
-/*
- * inittodr, settodr and support routines written
- * by Christoph Robitschko <chmr@edvz.tu-graz.ac.at>
- *
- * reintroduced and updated by Chris Stenton <chris@gnome.co.uk> 8/10/94
- */
-
-/*
- * modified for PC98 by Kakefuda
- */
-
-#include "opt_clock.h"
-#include "opt_isa.h"
-#include "opt_mca.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/limits.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/time.h>
-#include <sys/timetc.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/cons.h>
-#include <sys/power.h>
-
-#include <machine/clock.h>
-#include <machine/cputypes.h>
-#include <machine/frame.h>
-#include <machine/md_var.h>
-#include <machine/psl.h>
-#ifdef APIC_IO
-#include <machine/segments.h>
-#endif
-#if defined(SMP) || defined(APIC_IO)
-#include <machine/smp.h>
-#endif /* SMP || APIC_IO */
-#include <machine/specialreg.h>
-
-#include <i386/isa/icu.h>
-#include <pc98/pc98/pc98.h>
-#include <pc98/pc98/pc98_machdep.h>
-#include <i386/isa/isa_device.h>
-#ifdef DEV_ISA
-#include <isa/isavar.h>
-#endif
-#include <i386/isa/timerreg.h>
-
-#include <i386/isa/intr_machdep.h>
-
-#ifdef APIC_IO
-#include <i386/isa/intr_machdep.h>
-/* The interrupt triggered by the 8254 (timer) chip */
-int apic_8254_intr;
-static u_long read_intr_count(int vec);
-static void setup_8254_mixed_mode(void);
-#endif
-
-/*
- * 32-bit time_t's can't reach leap years before 1904 or after 2036, so we
- * can use a simple formula for leap years.
- */
-#define LEAPYEAR(y) ((u_int)(y) % 4 == 0)
-#define DAYSPERYEAR (31+28+31+30+31+30+31+31+30+31+30+31)
-
-#define TIMER_DIV(x) ((timer_freq + (x) / 2) / (x))
-
-/*
- * Time in timer cycles that it takes for microtime() to disable interrupts
- * and latch the count. microtime() currently uses "cli; outb ..." so it
- * normally takes less than 2 timer cycles. Add a few for cache misses.
- * Add a few more to allow for latency in bogus calls to microtime() with
- * interrupts already disabled.
- */
-#define TIMER0_LATCH_COUNT 20
-
-/*
- * Maximum frequency that we are willing to allow for timer0. Must be
- * low enough to guarantee that the timer interrupt handler returns
- * before the next timer interrupt.
- */
-#define TIMER0_MAX_FREQ 20000
-
-int adjkerntz; /* local offset from GMT in seconds */
-int clkintr_pending;
-int disable_rtc_set; /* disable resettodr() if != 0 */
-int pscnt = 1;
-int psdiv = 1;
-int statclock_disable;
-#ifndef TIMER_FREQ
-#define TIMER_FREQ 2457600
-#endif
-u_int timer_freq = TIMER_FREQ;
-int timer0_max_count;
-int wall_cmos_clock; /* wall CMOS clock assumed if != 0 */
-struct mtx clock_lock;
-
-static int beeping = 0;
-static const u_char daysinmonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};
-static u_int hardclock_max_count;
-static u_int32_t i8254_lastcount;
-static u_int32_t i8254_offset;
-static int i8254_ticked;
-/*
- * XXX new_function and timer_func should not handle clockframes, but
- * timer_func currently needs to hold hardclock to handle the
- * timer0_state == 0 case. We should use inthand_add()/inthand_remove()
- * to switch between clkintr() and a slightly different timerintr().
- */
-static void (*new_function)(struct clockframe *frame);
-static u_int new_rate;
-static u_int timer0_prescaler_count;
-
-/* Values for timerX_state: */
-#define RELEASED 0
-#define RELEASE_PENDING 1
-#define ACQUIRED 2
-#define ACQUIRE_PENDING 3
-
-static u_char timer0_state;
-static u_char timer1_state;
-static u_char timer2_state;
-static void (*timer_func)(struct clockframe *frame) = hardclock;
-static void rtc_serialcombit(int);
-static void rtc_serialcom(int);
-static int rtc_inb(void);
-static void rtc_outb(int);
-
-static unsigned i8254_get_timecount(struct timecounter *tc);
-static void set_timer_freq(u_int freq, int intr_freq);
-
-static struct timecounter i8254_timecounter = {
- i8254_get_timecount, /* get_timecount */
- 0, /* no poll_pps */
- ~0u, /* counter_mask */
- 0, /* frequency */
- "i8254" /* name */
-};
-
-static void
-clkintr(struct clockframe frame)
-{
-
- if (timecounter->tc_get_timecount == i8254_get_timecount) {
- mtx_lock_spin(&clock_lock);
- if (i8254_ticked)
- i8254_ticked = 0;
- else {
- i8254_offset += timer0_max_count;
- i8254_lastcount = 0;
- }
- clkintr_pending = 0;
- mtx_unlock_spin(&clock_lock);
- }
- timer_func(&frame);
-#ifdef SMP
- if (timer_func == hardclock)
- forward_hardclock();
-#endif
- switch (timer0_state) {
-
- case RELEASED:
- break;
-
- case ACQUIRED:
- if ((timer0_prescaler_count += timer0_max_count)
- >= hardclock_max_count) {
- timer0_prescaler_count -= hardclock_max_count;
- hardclock(&frame);
-#ifdef SMP
- forward_hardclock();
-#endif
- }
- break;
-
- case ACQUIRE_PENDING:
- mtx_lock_spin(&clock_lock);
- i8254_offset = i8254_get_timecount(NULL);
- i8254_lastcount = 0;
- timer0_max_count = TIMER_DIV(new_rate);
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
- outb(TIMER_CNTR0, timer0_max_count & 0xff);
- outb(TIMER_CNTR0, timer0_max_count >> 8);
- mtx_unlock_spin(&clock_lock);
- timer_func = new_function;
- timer0_state = ACQUIRED;
- break;
-
- case RELEASE_PENDING:
- if ((timer0_prescaler_count += timer0_max_count)
- >= hardclock_max_count) {
- mtx_lock_spin(&clock_lock);
- i8254_offset = i8254_get_timecount(NULL);
- i8254_lastcount = 0;
- timer0_max_count = hardclock_max_count;
- outb(TIMER_MODE,
- TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
- outb(TIMER_CNTR0, timer0_max_count & 0xff);
- outb(TIMER_CNTR0, timer0_max_count >> 8);
- mtx_unlock_spin(&clock_lock);
- timer0_prescaler_count = 0;
- timer_func = hardclock;
- timer0_state = RELEASED;
- hardclock(&frame);
-#ifdef SMP
- forward_hardclock();
-#endif
- }
- break;
- }
-}
-
-/*
- * The acquire and release functions must be called at ipl >= splclock().
- */
-int
-acquire_timer0(int rate, void (*function)(struct clockframe *frame))
-{
- static int old_rate;
-
- if (rate <= 0 || rate > TIMER0_MAX_FREQ)
- return (-1);
- switch (timer0_state) {
-
- case RELEASED:
- timer0_state = ACQUIRE_PENDING;
- break;
-
- case RELEASE_PENDING:
- if (rate != old_rate)
- return (-1);
- /*
- * The timer has been released recently, but is being
- * re-acquired before the release completed. In this
- * case, we simply reclaim it as if it had not been
- * released at all.
- */
- timer0_state = ACQUIRED;
- break;
-
- default:
- return (-1); /* busy */
- }
- new_function = function;
- old_rate = new_rate = rate;
- return (0);
-}
-
-int
-acquire_timer1(int mode)
-{
-
- if (timer1_state != RELEASED)
- return (-1);
- timer1_state = ACQUIRED;
-
- /*
- * This access to the timer registers is as atomic as possible
- * because it is a single instruction. We could do better if we
- * knew the rate. Use of splclock() limits glitches to 10-100us,
- * and this is probably good enough for timer2, so we aren't as
- * careful with it as with timer0.
- */
- outb(TIMER_MODE, TIMER_SEL1 | (mode & 0x3f));
-
- return (0);
-}
-
-int
-acquire_timer2(int mode)
-{
-
- if (timer2_state != RELEASED)
- return (-1);
- timer2_state = ACQUIRED;
-
- /*
- * This access to the timer registers is as atomic as possible
- * because it is a single instruction. We could do better if we
- * knew the rate. Use of splclock() limits glitches to 10-100us,
- * and this is probably good enough for timer2, so we aren't as
- * careful with it as with timer0.
- */
- outb(TIMER_MODE, TIMER_SEL2 | (mode & 0x3f));
-
- return (0);
-}
-
-int
-release_timer0()
-{
- switch (timer0_state) {
-
- case ACQUIRED:
- timer0_state = RELEASE_PENDING;
- break;
-
- case ACQUIRE_PENDING:
- /* Nothing happened yet, release quickly. */
- timer0_state = RELEASED;
- break;
-
- default:
- return (-1);
- }
- return (0);
-}
-
-int
-release_timer1()
-{
-
- if (timer1_state != ACQUIRED)
- return (-1);
- timer1_state = RELEASED;
- outb(TIMER_MODE, TIMER_SEL1 | TIMER_SQWAVE | TIMER_16BIT);
- return (0);
-}
-
-int
-release_timer2()
-{
-
- if (timer2_state != ACQUIRED)
- return (-1);
- timer2_state = RELEASED;
- outb(TIMER_MODE, TIMER_SEL2 | TIMER_SQWAVE | TIMER_16BIT);
- return (0);
-}
-
-
-static int
-getit(void)
-{
- int high, low;
-
- mtx_lock_spin(&clock_lock);
-
- /* Select timer0 and latch counter value. */
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
-
- low = inb(TIMER_CNTR0);
- high = inb(TIMER_CNTR0);
-
- mtx_unlock_spin(&clock_lock);
- return ((high << 8) | low);
-}
-
-/*
- * Wait "n" microseconds.
- * Relies on timer 1 counting down from (timer_freq / hz)
- * Note: timer had better have been programmed before this is first used!
- */
-void
-DELAY(int n)
-{
- int delta, prev_tick, tick, ticks_left;
-
-#ifdef DELAYDEBUG
- int getit_calls = 1;
- int n1;
- static int state = 0;
-
- if (state == 0) {
- state = 1;
- for (n1 = 1; n1 <= 10000000; n1 *= 10)
- DELAY(n1);
- state = 2;
- }
- if (state == 1)
- printf("DELAY(%d)...", n);
-#endif
- /*
- * Guard against the timer being uninitialized if we are called
- * early for console i/o.
- */
- if (timer0_max_count == 0)
- set_timer_freq(timer_freq, hz);
-
- /*
- * Read the counter first, so that the rest of the setup overhead is
- * counted. Guess the initial overhead is 20 usec (on most systems it
- * takes about 1.5 usec for each of the i/o's in getit(). The loop
- * takes about 6 usec on a 486/33 and 13 usec on a 386/20. The
- * multiplications and divisions to scale the count take a while).
- */
- prev_tick = getit();
- n -= 0; /* XXX actually guess no initial overhead */
- /*
- * Calculate (n * (timer_freq / 1e6)) without using floating point
- * and without any avoidable overflows.
- */
- if (n <= 0)
- ticks_left = 0;
- else if (n < 256)
- /*
- * Use fixed point to avoid a slow division by 1000000.
- * 39099 = 1193182 * 2^15 / 10^6 rounded to nearest.
- * 2^15 is the first power of 2 that gives exact results
- * for n between 0 and 256.
- */
- ticks_left = ((u_int)n * 39099 + (1 << 15) - 1) >> 15;
- else
- /*
- * Don't bother using fixed point, although gcc-2.7.2
- * generates particularly poor code for the long long
- * division, since even the slow way will complete long
- * before the delay is up (unless we're interrupted).
- */
- ticks_left = ((u_int)n * (long long)timer_freq + 999999)
- / 1000000;
-
- while (ticks_left > 0) {
- tick = getit();
-#ifdef DELAYDEBUG
- ++getit_calls;
-#endif
- delta = prev_tick - tick;
- prev_tick = tick;
- if (delta < 0) {
- delta += timer0_max_count;
- /*
- * Guard against timer0_max_count being wrong.
- * This shouldn't happen in normal operation,
- * but it may happen if set_timer_freq() is
- * traced.
- */
- if (delta < 0)
- delta = 0;
- }
- ticks_left -= delta;
- }
-#ifdef DELAYDEBUG
- if (state == 1)
- printf(" %d calls to getit() at %d usec each\n",
- getit_calls, (n + 5) / getit_calls);
-#endif
-}
-
-static void
-sysbeepstop(void *chan)
-{
- outb(IO_PPI, inb(IO_PPI)|0x08); /* disable counter1 output to speaker */
- release_timer1();
- beeping = 0;
-}
-
-int
-sysbeep(int pitch, int period)
-{
- int x = splclock();
-
- if (acquire_timer1(TIMER_SQWAVE|TIMER_16BIT))
- if (!beeping) {
- /* Something else owns it. */
- splx(x);
- return (-1); /* XXX Should be EBUSY, but nobody cares anyway. */
- }
- disable_intr();
- outb(0x3fdb, pitch);
- outb(0x3fdb, (pitch>>8));
- enable_intr();
- if (!beeping) {
- /* enable counter1 output to speaker */
- outb(IO_PPI, (inb(IO_PPI) & 0xf7));
- beeping = period;
- timeout(sysbeepstop, (void *)NULL, period);
- }
- splx(x);
- return (0);
-}
-
-
-unsigned int delaycount;
-#define FIRST_GUESS 0x2000
-static void findcpuspeed(void)
-{
- int i;
- int remainder;
-
- /* Put counter in count down mode */
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_16BIT | TIMER_RATEGEN);
- outb(TIMER_CNTR0, 0xff);
- outb(TIMER_CNTR0, 0xff);
- for (i = FIRST_GUESS; i; i--)
- ;
- remainder = getit();
- delaycount = (FIRST_GUESS * TIMER_DIV(1000)) / (0xffff - remainder);
-}
-
-static u_int
-calibrate_clocks(void)
-{
- int timeout;
- u_int count, prev_count, tot_count;
- u_short sec, start_sec;
-
- if (bootverbose)
- printf("Calibrating clock(s) ... ");
- /* Check ARTIC. */
- if (!(PC98_SYSTEM_PARAMETER(0x458) & 0x80) &&
- !(PC98_SYSTEM_PARAMETER(0x45b) & 0x04))
- goto fail;
- timeout = 100000000;
-
- /* Read the ARTIC. */
- sec = inw(0x5e);
-
- /* Wait for the ARTIC to changes. */
- start_sec = sec;
- for (;;) {
- sec = inw(0x5e);
- if (sec != start_sec)
- break;
- if (--timeout == 0)
- goto fail;
- }
- prev_count = getit();
- if (prev_count == 0 || prev_count > timer0_max_count)
- goto fail;
- tot_count = 0;
-
- start_sec = sec;
- for (;;) {
- sec = inw(0x5e);
- count = getit();
- if (count == 0 || count > timer0_max_count)
- goto fail;
- if (count > prev_count)
- tot_count += prev_count - (count - timer0_max_count);
- else
- tot_count += prev_count - count;
- prev_count = count;
- if ((sec == start_sec + 1200) ||
- (sec < start_sec &&
- (u_int)sec + 0x10000 == (u_int)start_sec + 1200))
- break;
- if (--timeout == 0)
- goto fail;
- }
-
- if (bootverbose) {
- printf("i8254 clock: %u Hz\n", tot_count);
- }
- return (tot_count);
-
-fail:
- if (bootverbose)
- printf("failed, using default i8254 clock of %u Hz\n",
- timer_freq);
- return (timer_freq);
-}
-
-static void
-set_timer_freq(u_int freq, int intr_freq)
-{
- int new_timer0_max_count;
-
- mtx_lock_spin(&clock_lock);
- timer_freq = freq;
- new_timer0_max_count = hardclock_max_count = TIMER_DIV(intr_freq);
- if (new_timer0_max_count != timer0_max_count) {
- timer0_max_count = new_timer0_max_count;
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
- outb(TIMER_CNTR0, timer0_max_count & 0xff);
- outb(TIMER_CNTR0, timer0_max_count >> 8);
- }
- mtx_unlock_spin(&clock_lock);
-}
-
-static void
-i8254_restore(void)
-{
-
- mtx_lock_spin(&clock_lock);
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
- outb(TIMER_CNTR0, timer0_max_count & 0xff);
- outb(TIMER_CNTR0, timer0_max_count >> 8);
- mtx_unlock_spin(&clock_lock);
-}
-
-
-/*
- * Restore all the timers non-atomically (XXX: should be atomically).
- *
- * This function is called from pmtimer_resume() to restore all the timers.
- * This should not be necessary, but there are broken laptops that do not
- * restore all the timers on resume.
- */
-void
-timer_restore(void)
-{
-
- i8254_restore(); /* restore timer_freq and hz */
-}
-
-/*
- * Initialize 8254 timer 0 early so that it can be used in DELAY().
- * XXX initialization of other timers is unintentionally left blank.
- */
-void
-startrtclock()
-{
- u_int delta, freq;
-
- findcpuspeed();
- if (pc98_machine_type & M_8M)
- timer_freq = 1996800L; /* 1.9968 MHz */
- else
- timer_freq = 2457600L; /* 2.4576 MHz */
-
- set_timer_freq(timer_freq, hz);
- freq = calibrate_clocks();
-#ifdef CLK_CALIBRATION_LOOP
- if (bootverbose) {
- printf(
- "Press a key on the console to abort clock calibration\n");
- while (cncheckc() == -1)
- calibrate_clocks();
- }
-#endif
-
- /*
- * Use the calibrated i8254 frequency if it seems reasonable.
- * Otherwise use the default, and don't use the calibrated i586
- * frequency.
- */
- delta = freq > timer_freq ? freq - timer_freq : timer_freq - freq;
- if (delta < timer_freq / 100) {
-#ifndef CLK_USE_I8254_CALIBRATION
- if (bootverbose)
- printf(
-"CLK_USE_I8254_CALIBRATION not specified - using default frequency\n");
- freq = timer_freq;
-#endif
- timer_freq = freq;
- } else {
- if (bootverbose)
- printf(
- "%d Hz differs from default of %d Hz by more than 1%%\n",
- freq, timer_freq);
- }
-
- set_timer_freq(timer_freq, hz);
- i8254_timecounter.tc_frequency = timer_freq;
- tc_init(&i8254_timecounter);
-
- init_TSC();
-}
-
-static void
-rtc_serialcombit(int i)
-{
- outb(IO_RTC, ((i&0x01)<<5)|0x07);
- DELAY(1);
- outb(IO_RTC, ((i&0x01)<<5)|0x17);
- DELAY(1);
- outb(IO_RTC, ((i&0x01)<<5)|0x07);
- DELAY(1);
-}
-
-static void
-rtc_serialcom(int i)
-{
- rtc_serialcombit(i&0x01);
- rtc_serialcombit((i&0x02)>>1);
- rtc_serialcombit((i&0x04)>>2);
- rtc_serialcombit((i&0x08)>>3);
- outb(IO_RTC, 0x07);
- DELAY(1);
- outb(IO_RTC, 0x0f);
- DELAY(1);
- outb(IO_RTC, 0x07);
- DELAY(1);
-}
-
-static void
-rtc_outb(int val)
-{
- int s;
- int sa = 0;
-
- for (s=0;s<8;s++) {
- sa = ((val >> s) & 0x01) ? 0x27 : 0x07;
- outb(IO_RTC, sa); /* set DI & CLK 0 */
- DELAY(1);
- outb(IO_RTC, sa | 0x10); /* CLK 1 */
- DELAY(1);
- }
- outb(IO_RTC, sa & 0xef); /* CLK 0 */
-}
-
-static int
-rtc_inb(void)
-{
- int s;
- int sa = 0;
-
- for (s=0;s<8;s++) {
- sa |= ((inb(0x33) & 0x01) << s);
- outb(IO_RTC, 0x17); /* CLK 1 */
- DELAY(1);
- outb(IO_RTC, 0x07); /* CLK 0 */
- DELAY(2);
- }
- return sa;
-}
-
-/*
- * Initialize the time of day register, based on the time base which is, e.g.
- * from a filesystem.
- */
-void
-inittodr(time_t base)
-{
- unsigned long sec, days;
- int year, month;
- int y, m, s;
- struct timespec ts;
- int second, min, hour;
-
- if (base) {
- s = splclock();
- ts.tv_sec = base;
- ts.tv_nsec = 0;
- tc_setclock(&ts);
- splx(s);
- }
-
- rtc_serialcom(0x03); /* Time Read */
- rtc_serialcom(0x01); /* Register shift command. */
- DELAY(20);
-
- second = bcd2bin(rtc_inb() & 0xff); /* sec */
- min = bcd2bin(rtc_inb() & 0xff); /* min */
- hour = bcd2bin(rtc_inb() & 0xff); /* hour */
- days = bcd2bin(rtc_inb() & 0xff) - 1; /* date */
-
- month = (rtc_inb() >> 4) & 0x0f; /* month */
- for (m = 1; m < month; m++)
- days += daysinmonth[m-1];
- year = bcd2bin(rtc_inb() & 0xff) + 1900; /* year */
- /* 2000 year problem */
- if (year < 1995)
- year += 100;
- if (year < 1970)
- goto wrong_time;
- for (y = 1970; y < year; y++)
- days += DAYSPERYEAR + LEAPYEAR(y);
- if ((month > 2) && LEAPYEAR(year))
- days ++;
- sec = ((( days * 24 +
- hour) * 60 +
- min) * 60 +
- second);
- /* sec now contains the number of seconds, since Jan 1 1970,
- in the local time zone */
-
- s = splhigh();
-
- sec += tz_minuteswest * 60 + (wall_cmos_clock ? adjkerntz : 0);
-
- y = time_second - sec;
- if (y <= -2 || y >= 2) {
- /* badly off, adjust it */
- ts.tv_sec = sec;
- ts.tv_nsec = 0;
- tc_setclock(&ts);
- }
- splx(s);
- return;
-
-wrong_time:
- printf("Invalid time in real time clock.\n");
- printf("Check and reset the date immediately!\n");
-}
-
-/*
- * Write system time back to RTC
- */
-void
-resettodr()
-{
- unsigned long tm;
- int y, m, s;
- int wd;
-
- if (disable_rtc_set)
- return;
-
- s = splclock();
- tm = time_second;
- splx(s);
-
- rtc_serialcom(0x01); /* Register shift command. */
-
- /* Calculate local time to put in RTC */
-
- tm -= tz_minuteswest * 60 + (wall_cmos_clock ? adjkerntz : 0);
-
- rtc_outb(bin2bcd(tm%60)); tm /= 60; /* Write back Seconds */
- rtc_outb(bin2bcd(tm%60)); tm /= 60; /* Write back Minutes */
- rtc_outb(bin2bcd(tm%24)); tm /= 24; /* Write back Hours */
-
- /* We have now the days since 01-01-1970 in tm */
- wd = (tm + 4) % 7 + 1; /* Write back Weekday */
- for (y = 1970, m = DAYSPERYEAR + LEAPYEAR(y);
- tm >= m;
- y++, m = DAYSPERYEAR + LEAPYEAR(y))
- tm -= m;
-
- /* Now we have the years in y and the day-of-the-year in tm */
- for (m = 0; ; m++) {
- int ml;
-
- ml = daysinmonth[m];
- if (m == 1 && LEAPYEAR(y))
- ml++;
- if (tm < ml)
- break;
- tm -= ml;
- }
-
- m++;
- rtc_outb(bin2bcd(tm+1)); /* Write back Day */
- rtc_outb((m << 4) | wd); /* Write back Month & Weekday */
- rtc_outb(bin2bcd(y%100)); /* Write back Year */
-
- rtc_serialcom(0x02); /* Time set & Counter hold command. */
- rtc_serialcom(0x00); /* Register hold command. */
-}
-
-
-/*
- * Start both clocks running.
- */
-void
-cpu_initclocks()
-{
-#ifdef APIC_IO
- int apic_8254_trial;
- void *clkdesc;
-#endif /* APIC_IO */
- register_t crit;
-
-
- /* Finish initializing 8253 timer 0. */
-#ifdef APIC_IO
-
- apic_8254_intr = isa_apic_irq(0);
- apic_8254_trial = 0;
- if (apic_8254_intr >= 0 ) {
- if (apic_int_type(0, 0) == 3)
- apic_8254_trial = 1;
- } else {
- /* look for ExtInt on pin 0 */
- if (apic_int_type(0, 0) == 3) {
- apic_8254_intr = apic_irq(0, 0);
- setup_8254_mixed_mode();
- } else
- panic("APIC_IO: Cannot route 8254 interrupt to CPU");
- }
-
- inthand_add("clk", apic_8254_intr, (driver_intr_t *)clkintr, NULL,
- INTR_TYPE_CLK | INTR_FAST, &clkdesc);
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTREN(1 << apic_8254_intr);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-
-#else /* APIC_IO */
-
- /*
- * XXX Check the priority of this interrupt handler. I
- * couldn't find anything suitable in the BSD/OS code (grog,
- * 19 July 2000).
- */
- inthand_add("clk", 0, (driver_intr_t *)clkintr, NULL,
- INTR_TYPE_CLK | INTR_FAST, NULL);
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTREN(IRQ0);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
-
-#endif /* APIC_IO */
-
-
-
-#ifdef APIC_IO
- if (apic_8254_trial) {
-
- printf("APIC_IO: Testing 8254 interrupt delivery\n");
- while (read_intr_count(8) < 6)
- ; /* nothing */
- if (read_intr_count(apic_8254_intr) < 3) {
- /*
- * The MP table is broken.
- * The 8254 was not connected to the specified pin
- * on the IO APIC.
- * Workaround: Limited variant of mixed mode.
- */
-
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTRDIS(1 << apic_8254_intr);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
- inthand_remove(clkdesc);
- printf("APIC_IO: Broken MP table detected: "
- "8254 is not connected to "
- "IOAPIC #%d intpin %d\n",
- int_to_apicintpin[apic_8254_intr].ioapic,
- int_to_apicintpin[apic_8254_intr].int_pin);
- /*
- * Revoke current ISA IRQ 0 assignment and
- * configure a fallback interrupt routing from
- * the 8254 Timer via the 8259 PIC to the
- * an ExtInt interrupt line on IOAPIC #0 intpin 0.
- * We reuse the low level interrupt handler number.
- */
- if (apic_irq(0, 0) < 0) {
- revoke_apic_irq(apic_8254_intr);
- assign_apic_irq(0, 0, apic_8254_intr);
- }
- apic_8254_intr = apic_irq(0, 0);
- setup_8254_mixed_mode();
- inthand_add("clk", apic_8254_intr,
- (driver_intr_t *)clkintr, NULL,
- INTR_TYPE_CLK | INTR_FAST, NULL);
- crit = intr_disable();
- mtx_lock_spin(&icu_lock);
- INTREN(1 << apic_8254_intr);
- mtx_unlock_spin(&icu_lock);
- intr_restore(crit);
- }
-
- }
- if (apic_int_type(0, 0) != 3 ||
- int_to_apicintpin[apic_8254_intr].ioapic != 0 ||
- int_to_apicintpin[apic_8254_intr].int_pin != 0)
- printf("APIC_IO: routing 8254 via IOAPIC #%d intpin %d\n",
- int_to_apicintpin[apic_8254_intr].ioapic,
- int_to_apicintpin[apic_8254_intr].int_pin);
- else
- printf("APIC_IO: "
- "routing 8254 via 8259 and IOAPIC #0 intpin 0\n");
-#endif
-
-}
-
-#ifdef APIC_IO
-static u_long
-read_intr_count(int vec)
-{
- u_long *up;
- up = intr_countp[vec];
- if (up)
- return *up;
- return 0UL;
-}
-
-static void
-setup_8254_mixed_mode()
-{
- /*
- * Allow 8254 timer to INTerrupt 8259:
- * re-initialize master 8259:
- * reset; prog 4 bytes, single ICU, edge triggered
- */
- outb(IO_ICU1, 0x13);
- outb(IO_ICU1 + 2, NRSVIDT); /* start vector (unused) */
- outb(IO_ICU1 + 2, 0x00); /* ignore slave */
- outb(IO_ICU1 + 2, 0x03); /* auto EOI, 8086 */
- outb(IO_ICU1 + 2, 0xfe); /* unmask INT0 */
-
- /* program IO APIC for type 3 INT on INT0 */
- if (ext_int_setup(0, 0) < 0)
- panic("8254 redirect via APIC pin0 impossible!");
-}
-#endif
-
-void
-cpu_startprofclock(void)
-{
-}
-
-void
-cpu_stopprofclock(void)
-{
-}
-
-static int
-sysctl_machdep_i8254_freq(SYSCTL_HANDLER_ARGS)
-{
- int error;
- u_int freq;
-
- /*
- * Use `i8254' instead of `timer' in external names because `timer'
- * is is too generic. Should use it everywhere.
- */
- freq = timer_freq;
- error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
- if (error == 0 && req->newptr != NULL) {
- if (timer0_state != RELEASED)
- return (EBUSY); /* too much trouble to handle */
- set_timer_freq(freq, hz);
- i8254_timecounter.tc_frequency = freq;
- }
- return (error);
-}
-
-SYSCTL_PROC(_machdep, OID_AUTO, i8254_freq, CTLTYPE_INT | CTLFLAG_RW,
- 0, sizeof(u_int), sysctl_machdep_i8254_freq, "IU", "");
-
-static unsigned
-i8254_get_timecount(struct timecounter *tc)
-{
- u_int count;
- u_int high, low;
- u_int eflags;
-
- eflags = read_eflags();
- mtx_lock_spin(&clock_lock);
-
- /* Select timer0 and latch counter value. */
- outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
-
- low = inb(TIMER_CNTR0);
- high = inb(TIMER_CNTR0);
- count = timer0_max_count - ((high << 8) | low);
- if (count < i8254_lastcount ||
- (!i8254_ticked && (clkintr_pending ||
- ((count < 20 || (!(eflags & PSL_I) && count < timer0_max_count / 2u)) &&
-#ifdef APIC_IO
-#define lapic_irr1 ((volatile u_int *)&lapic)[0x210 / 4] /* XXX XXX */
- /* XXX this assumes that apic_8254_intr is < 24. */
- (lapic_irr1 & (1 << apic_8254_intr))))
-#else
- (inb(IO_ICU1) & 1)))
-#endif
- )) {
- i8254_ticked = 1;
- i8254_offset += timer0_max_count;
- }
- i8254_lastcount = count;
- count += i8254_offset;
- mtx_unlock_spin(&clock_lock);
- return (count);
-}
-
-#ifdef DEV_ISA
-/*
- * Attach to the ISA PnP descriptors for the timer and realtime clock.
- */
-static struct isa_pnp_id attimer_ids[] = {
- { 0x0001d041 /* PNP0100 */, "AT timer" },
- { 0x000bd041 /* PNP0B00 */, "AT realtime clock" },
- { 0 }
-};
-
-static int
-attimer_probe(device_t dev)
-{
- int result;
-
- if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, attimer_ids)) <= 0)
- device_quiet(dev);
- return(result);
-}
-
-static int
-attimer_attach(device_t dev)
-{
- return(0);
-}
-
-static device_method_t attimer_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, attimer_probe),
- DEVMETHOD(device_attach, attimer_attach),
- DEVMETHOD(device_detach, bus_generic_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend), /* XXX stop statclock? */
- DEVMETHOD(device_resume, bus_generic_resume), /* XXX restart statclock? */
- { 0, 0 }
-};
-
-static driver_t attimer_driver = {
- "attimer",
- attimer_methods,
- 1, /* no softc */
-};
-
-static devclass_t attimer_devclass;
-
-DRIVER_MODULE(attimer, isa, attimer_driver, attimer_devclass, 0, 0);
-#endif /* DEV_ISA */
diff --git a/sys/pc98/cbus/pmc.c b/sys/pc98/cbus/pmc.c
deleted file mode 100644
index 91768190ba8e..000000000000
--- a/sys/pc98/cbus/pmc.c
+++ /dev/null
@@ -1,244 +0,0 @@
-/*-
- * PMC (Power Management Controller of NEC PC-98Note) Driver
- *
- * Copyright (c) 2001 Chiharu Shibata.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/eventhandler.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/types.h>
-#include <sys/conf.h>
-#include <sys/reboot.h>
-
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-#include <isa/isavar.h>
-
-struct pmc_isa_softc {
- struct resource *port_res;
- eventhandler_tag evt;
- int flags;
-};
-
-static int pmc_isa_alloc_resources(device_t);
-static void pmc_isa_release_resources(device_t);
-static int pmc_isa_probe(device_t);
-static int pmc_isa_attach(device_t);
-static int pmc_isa_detach(device_t);
-
-#define PMC_ISA_PORT 0x8f0
-#define PMC_ISA_PORTSIZE 4
-
-#define sc_inw(sc, port) \
- bus_space_read_2(rman_get_bustag((sc)->port_res), \
- rman_get_bushandle((sc)->port_res), (port))
-
-#define sc_outw(sc, port, value) \
- bus_space_write_2(rman_get_bustag((sc)->port_res), \
- rman_get_bushandle((sc)->port_res), (port), (value))
-
-static void
-pmc_poweroff(void *arg, int howto)
-{
- struct pmc_isa_softc *sc = (struct pmc_isa_softc *)arg;
-
- if (!sc->flags) {
- outb(0x5e8e, inb(0x5e8e) & ~0x11); /* FDD LED off */
- }
-
- if (!(howto & RB_POWEROFF)) {
- return;
- }
-
- sc_outw(sc, 0, 0x0044);
- sc_outw(sc, 2, 1 << 10);
-#if 1
- /* for 9801NS/T */
- sc_outw(sc, 0, 0xf00a);
- sc_outw(sc, 2, 1 << 9);
-#endif
-}
-
-static int
-pmc_isa_alloc_resources(device_t dev)
-{
- struct pmc_isa_softc *sc = device_get_softc(dev);
- int rid;
-
- bzero(sc, sizeof(*sc));
-
- rid = 0;
- sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
- 0ul, ~0ul, PMC_ISA_PORTSIZE,
- RF_ACTIVE);
- if (sc->port_res == NULL) {
- return (ENOMEM);
- }
-
- return 0;
-}
-
-static void
-pmc_isa_release_resources(device_t dev)
-{
- struct pmc_isa_softc *sc = device_get_softc(dev);
-
- if (sc->port_res != NULL) {
- bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port_res);
- }
- sc->port_res = NULL;
-}
-
-static int
-pmc_isa_probe(device_t dev)
-{
- struct pmc_isa_softc *sc = device_get_softc(dev);
- u_int port;
- u_int16_t save, tmp;
-
-#if 0
- if (isa_get_vendorid(dev)) {
- return ENXIO;
- }
- if (device_get_unit(dev) > 0) {
- printf("pmc: Only one PMC driver supported.\n");
- return ENXIO;
- }
-#endif
- port = isa_get_port(dev);
- if (port == -1) {
- port = PMC_ISA_PORT;
- }
- if (bootverbose) {
- device_printf(dev, "port = 0x%x\n", port);
- }
-
- if (bus_set_resource(dev, SYS_RES_IOPORT, 0, port, PMC_ISA_PORTSIZE)) {
- if (bootverbose) {
- device_printf(dev, "bus_set_resource failed\n");
- }
- return ENXIO;
- }
- if (pmc_isa_alloc_resources(dev)) {
- if (bootverbose) {
- device_printf(dev, "pmc_isa_alloc_resources failed\n");
- }
- return ENXIO;
- }
-
- /* Check the existence of PMC */
- sc_outw(sc, 0, 0x0052);
- save = sc_inw(sc, 2);
- tmp = save & ~0x3f;
- sc_outw(sc, 2, tmp);
- if (sc_inw(sc, 2) != tmp) {
- if (bootverbose) {
- device_printf(dev, "failed to clear index(0x0052)\n");
- }
-
- pmc_isa_release_resources(dev);
- return ENXIO;
- }
-
- tmp |= 0x3e;
- sc_outw(sc, 2, tmp);
- if (sc_inw(sc, 2) != tmp) {
- if (bootverbose) {
- device_printf(dev, "failed to set index(0x0052)\n");
- }
-
- pmc_isa_release_resources(dev);
- return ENXIO;
- }
- sc_outw(sc, 2, save);
-
- pmc_isa_release_resources(dev);
-
- device_set_desc(dev, "Power Management Controller");
- return 0;
-}
-
-static int
-pmc_isa_attach(device_t dev)
-{
- struct pmc_isa_softc *sc = device_get_softc(dev);
- int error;
-
- error = pmc_isa_alloc_resources(dev);
- if (error) {
- device_printf(dev, "resource allocation failed\n");
- return error;
- }
-
- /* Power the system off using PMC */
- sc->evt = EVENTHANDLER_REGISTER(shutdown_final, pmc_poweroff, sc,
- SHUTDOWN_PRI_LAST);
- sc->flags = device_get_flags(dev);
- return 0;
-}
-
-static int
-pmc_isa_detach(device_t dev)
-{
- struct pmc_isa_softc *sc = device_get_softc(dev);
-
- if (bootverbose) {
- device_printf(dev, "pmc_isa_detach called\n");
- }
-
- if (sc->evt != NULL) {
- EVENTHANDLER_DEREGISTER(shutdown_final, sc->evt);
- }
- sc->evt = NULL;
-
- pmc_isa_release_resources(dev);
- return 0;
-}
-
-static device_method_t pmc_isa_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, pmc_isa_probe),
- DEVMETHOD(device_attach, pmc_isa_attach),
- DEVMETHOD(device_detach, pmc_isa_detach),
- {0, 0}
-};
-
-static driver_t pmc_isa_driver = {
- "pmc",
- pmc_isa_methods, sizeof(struct pmc_isa_softc),
-};
-
-devclass_t pmc_devclass;
-
-DRIVER_MODULE(pmc, isa, pmc_isa_driver, pmc_devclass, 0, 0);
diff --git a/sys/pc98/cbus/ppc.c b/sys/pc98/cbus/ppc.c
deleted file mode 100644
index d86793442d9d..000000000000
--- a/sys/pc98/cbus/ppc.c
+++ /dev/null
@@ -1,2222 +0,0 @@
-/*-
- * Copyright (c) 2001 Alcove - Nicolas Souchu
- * 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$
- *
- */
-
-#include "opt_ppc.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <machine/vmparam.h>
-#include <sys/rman.h>
-
-#ifdef PC98
-#include <pc98/pc98/pc98.h>
-#else
-#include <isa/isareg.h>
-#endif
-#include <isa/isavar.h>
-
-#include <dev/ppbus/ppbconf.h>
-#include <dev/ppbus/ppb_msq.h>
-
-#ifdef PC98
-#include <pc98/pc98/ppcreg.h>
-#else
-#include <isa/ppcreg.h>
-#endif
-
-#include "ppbus_if.h"
-
-#define LOG_PPC(function, ppc, string) \
- if (bootverbose) printf("%s: %s\n", function, string)
-
-
-#define DEVTOSOFTC(dev) ((struct ppc_data *)device_get_softc(dev))
-
-devclass_t ppc_devclass;
-
-static int ppc_probe(device_t dev);
-static int ppc_attach(device_t dev);
-static int ppc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val);
-
-static void ppc_reset_epp(device_t);
-static void ppc_ecp_sync(device_t);
-static void ppcintr(void *arg);
-
-static int ppc_exec_microseq(device_t, struct ppb_microseq **);
-static int ppc_setmode(device_t, int);
-
-static int ppc_read(device_t, char *, int, int);
-static int ppc_write(device_t, char *, int, int);
-
-static u_char ppc_io(device_t, int, u_char *, int, u_char);
-
-static int ppc_setup_intr(device_t, device_t, struct resource *, int,
- void (*)(void *), void *, void **);
-static int ppc_teardown_intr(device_t, device_t, struct resource *, void *);
-
-static device_method_t ppc_methods[] = {
- /* device interface */
- DEVMETHOD(device_probe, ppc_probe),
- DEVMETHOD(device_attach, ppc_attach),
-
- /* bus interface */
- DEVMETHOD(bus_read_ivar, ppc_read_ivar),
- DEVMETHOD(bus_setup_intr, ppc_setup_intr),
- DEVMETHOD(bus_teardown_intr, ppc_teardown_intr),
- DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
-
- /* ppbus interface */
- DEVMETHOD(ppbus_io, ppc_io),
- DEVMETHOD(ppbus_exec_microseq, ppc_exec_microseq),
- DEVMETHOD(ppbus_reset_epp, ppc_reset_epp),
- DEVMETHOD(ppbus_setmode, ppc_setmode),
- DEVMETHOD(ppbus_ecp_sync, ppc_ecp_sync),
- DEVMETHOD(ppbus_read, ppc_read),
- DEVMETHOD(ppbus_write, ppc_write),
-
- { 0, 0 }
- };
-
-static driver_t ppc_driver = {
- "ppc",
- ppc_methods,
- sizeof(struct ppc_data),
-};
-
-static char *ppc_models[] = {
- "SMC-like", "SMC FDC37C665GT", "SMC FDC37C666GT", "PC87332", "PC87306",
- "82091AA", "Generic", "W83877F", "W83877AF", "Winbond", "PC87334",
- "SMC FDC37C935", "PC87303", 0
-};
-
-/* list of available modes */
-static char *ppc_avms[] = {
- "COMPATIBLE", "NIBBLE-only", "PS2-only", "PS2/NIBBLE", "EPP-only",
- "EPP/NIBBLE", "EPP/PS2", "EPP/PS2/NIBBLE", "ECP-only",
- "ECP/NIBBLE", "ECP/PS2", "ECP/PS2/NIBBLE", "ECP/EPP",
- "ECP/EPP/NIBBLE", "ECP/EPP/PS2", "ECP/EPP/PS2/NIBBLE", 0
-};
-
-/* list of current executing modes
- * Note that few modes do not actually exist.
- */
-static char *ppc_modes[] = {
- "COMPATIBLE", "NIBBLE", "PS/2", "PS/2", "EPP",
- "EPP", "EPP", "EPP", "ECP",
- "ECP", "ECP+PS2", "ECP+PS2", "ECP+EPP",
- "ECP+EPP", "ECP+EPP", "ECP+EPP", 0
-};
-
-static char *ppc_epp_protocol[] = { " (EPP 1.9)", " (EPP 1.7)", 0 };
-
-#ifdef __i386__
-/*
- * BIOS printer list - used by BIOS probe.
- */
-#define BIOS_PPC_PORTS 0x408
-#define BIOS_PORTS (short *)(KERNBASE+BIOS_PPC_PORTS)
-#define BIOS_MAX_PPC 4
-#endif
-
-/*
- * ppc_ecp_sync() XXX
- */
-static void
-ppc_ecp_sync(device_t dev) {
-
- int i, r;
- struct ppc_data *ppc = DEVTOSOFTC(dev);
-
- if (!(ppc->ppc_avm & PPB_ECP) && !(ppc->ppc_dtm & PPB_ECP))
- return;
-
- r = r_ecr(ppc);
- if ((r & 0xe0) != PPC_ECR_EPP)
- return;
-
- for (i = 0; i < 100; i++) {
- r = r_ecr(ppc);
- if (r & 0x1)
- return;
- DELAY(100);
- }
-
- printf("ppc%d: ECP sync failed as data still " \
- "present in FIFO.\n", ppc->ppc_unit);
-
- return;
-}
-
-/*
- * ppc_detect_fifo()
- *
- * Detect parallel port FIFO
- */
-static int
-ppc_detect_fifo(struct ppc_data *ppc)
-{
- char ecr_sav;
- char ctr_sav, ctr, cc;
- short i;
-
- /* save registers */
- ecr_sav = r_ecr(ppc);
- ctr_sav = r_ctr(ppc);
-
- /* enter ECP configuration mode, no interrupt, no DMA */
- w_ecr(ppc, 0xf4);
-
- /* read PWord size - transfers in FIFO mode must be PWord aligned */
- ppc->ppc_pword = (r_cnfgA(ppc) & PPC_PWORD_MASK);
-
- /* XXX 16 and 32 bits implementations not supported */
- if (ppc->ppc_pword != PPC_PWORD_8) {
- LOG_PPC(__func__, ppc, "PWord not supported");
- goto error;
- }
-
- w_ecr(ppc, 0x34); /* byte mode, no interrupt, no DMA */
- ctr = r_ctr(ppc);
- w_ctr(ppc, ctr | PCD); /* set direction to 1 */
-
- /* enter ECP test mode, no interrupt, no DMA */
- w_ecr(ppc, 0xd4);
-
- /* flush the FIFO */
- for (i=0; i<1024; i++) {
- if (r_ecr(ppc) & PPC_FIFO_EMPTY)
- break;
- cc = r_fifo(ppc);
- }
-
- if (i >= 1024) {
- LOG_PPC(__func__, ppc, "can't flush FIFO");
- goto error;
- }
-
- /* enable interrupts, no DMA */
- w_ecr(ppc, 0xd0);
-
- /* determine readIntrThreshold
- * fill the FIFO until serviceIntr is set
- */
- for (i=0; i<1024; i++) {
- w_fifo(ppc, (char)i);
- if (!ppc->ppc_rthr && (r_ecr(ppc) & PPC_SERVICE_INTR)) {
- /* readThreshold reached */
- ppc->ppc_rthr = i+1;
- }
- if (r_ecr(ppc) & PPC_FIFO_FULL) {
- ppc->ppc_fifo = i+1;
- break;
- }
- }
-
- if (i >= 1024) {
- LOG_PPC(__func__, ppc, "can't fill FIFO");
- goto error;
- }
-
- w_ecr(ppc, 0xd4); /* test mode, no interrupt, no DMA */
- w_ctr(ppc, ctr & ~PCD); /* set direction to 0 */
- w_ecr(ppc, 0xd0); /* enable interrupts */
-
- /* determine writeIntrThreshold
- * empty the FIFO until serviceIntr is set
- */
- for (i=ppc->ppc_fifo; i>0; i--) {
- if (r_fifo(ppc) != (char)(ppc->ppc_fifo-i)) {
- LOG_PPC(__func__, ppc, "invalid data in FIFO");
- goto error;
- }
- if (r_ecr(ppc) & PPC_SERVICE_INTR) {
- /* writeIntrThreshold reached */
- ppc->ppc_wthr = ppc->ppc_fifo - i+1;
- }
- /* if FIFO empty before the last byte, error */
- if (i>1 && (r_ecr(ppc) & PPC_FIFO_EMPTY)) {
- LOG_PPC(__func__, ppc, "data lost in FIFO");
- goto error;
- }
- }
-
- /* FIFO must be empty after the last byte */
- if (!(r_ecr(ppc) & PPC_FIFO_EMPTY)) {
- LOG_PPC(__func__, ppc, "can't empty the FIFO");
- goto error;
- }
-
- w_ctr(ppc, ctr_sav);
- w_ecr(ppc, ecr_sav);
-
- return (0);
-
-error:
- w_ctr(ppc, ctr_sav);
- w_ecr(ppc, ecr_sav);
-
- return (EINVAL);
-}
-
-static int
-ppc_detect_port(struct ppc_data *ppc)
-{
-
- w_ctr(ppc, 0x0c); /* To avoid missing PS2 ports */
- w_dtr(ppc, 0xaa);
- if (r_dtr(ppc) != 0xaa)
- return (0);
-
- return (1);
-}
-
-/*
- * EPP timeout, according to the PC87332 manual
- * Semantics of clearing EPP timeout bit.
- * PC87332 - reading SPP_STR does it...
- * SMC - write 1 to EPP timeout bit XXX
- * Others - (?) write 0 to EPP timeout bit
- */
-static void
-ppc_reset_epp_timeout(struct ppc_data *ppc)
-{
- register char r;
-
- r = r_str(ppc);
- w_str(ppc, r | 0x1);
- w_str(ppc, r & 0xfe);
-
- return;
-}
-
-static int
-ppc_check_epp_timeout(struct ppc_data *ppc)
-{
- ppc_reset_epp_timeout(ppc);
-
- return (!(r_str(ppc) & TIMEOUT));
-}
-
-/*
- * Configure current operating mode
- */
-static int
-ppc_generic_setmode(struct ppc_data *ppc, int mode)
-{
- u_char ecr = 0;
-
- /* check if mode is available */
- if (mode && !(ppc->ppc_avm & mode))
- return (EINVAL);
-
- /* if ECP mode, configure ecr register */
- if ((ppc->ppc_avm & PPB_ECP) || (ppc->ppc_dtm & PPB_ECP)) {
- /* return to byte mode (keeping direction bit),
- * no interrupt, no DMA to be able to change to
- * ECP
- */
- w_ecr(ppc, PPC_ECR_RESET);
- ecr = PPC_DISABLE_INTR;
-
- if (mode & PPB_EPP)
- return (EINVAL);
- else if (mode & PPB_ECP)
- /* select ECP mode */
- ecr |= PPC_ECR_ECP;
- else if (mode & PPB_PS2)
- /* select PS2 mode with ECP */
- ecr |= PPC_ECR_PS2;
- else
- /* select COMPATIBLE/NIBBLE mode */
- ecr |= PPC_ECR_STD;
-
- w_ecr(ppc, ecr);
- }
-
- ppc->ppc_mode = mode;
-
- return (0);
-}
-
-/*
- * The ppc driver is free to choose options like FIFO or DMA
- * if ECP mode is available.
- *
- * The 'RAW' option allows the upper drivers to force the ppc mode
- * even with FIFO, DMA available.
- */
-static int
-ppc_smclike_setmode(struct ppc_data *ppc, int mode)
-{
- u_char ecr = 0;
-
- /* check if mode is available */
- if (mode && !(ppc->ppc_avm & mode))
- return (EINVAL);
-
- /* if ECP mode, configure ecr register */
- if ((ppc->ppc_avm & PPB_ECP) || (ppc->ppc_dtm & PPB_ECP)) {
- /* return to byte mode (keeping direction bit),
- * no interrupt, no DMA to be able to change to
- * ECP or EPP mode
- */
- w_ecr(ppc, PPC_ECR_RESET);
- ecr = PPC_DISABLE_INTR;
-
- if (mode & PPB_EPP)
- /* select EPP mode */
- ecr |= PPC_ECR_EPP;
- else if (mode & PPB_ECP)
- /* select ECP mode */
- ecr |= PPC_ECR_ECP;
- else if (mode & PPB_PS2)
- /* select PS2 mode with ECP */
- ecr |= PPC_ECR_PS2;
- else
- /* select COMPATIBLE/NIBBLE mode */
- ecr |= PPC_ECR_STD;
-
- w_ecr(ppc, ecr);
- }
-
- ppc->ppc_mode = mode;
-
- return (0);
-}
-
-#ifdef PPC_PROBE_CHIPSET
-/*
- * ppc_pc873xx_detect
- *
- * Probe for a Natsemi PC873xx-family part.
- *
- * References in this function are to the National Semiconductor
- * PC87332 datasheet TL/C/11930, May 1995 revision.
- */
-static int pc873xx_basetab[] = {0x0398, 0x026e, 0x015c, 0x002e, 0};
-static int pc873xx_porttab[] = {0x0378, 0x03bc, 0x0278, 0};
-static int pc873xx_irqtab[] = {5, 7, 5, 0};
-
-static int pc873xx_regstab[] = {
- PC873_FER, PC873_FAR, PC873_PTR,
- PC873_FCR, PC873_PCR, PC873_PMC,
- PC873_TUP, PC873_SID, PC873_PNP0,
- PC873_PNP1, PC873_LPTBA, -1
-};
-
-static char *pc873xx_rnametab[] = {
- "FER", "FAR", "PTR", "FCR", "PCR",
- "PMC", "TUP", "SID", "PNP0", "PNP1",
- "LPTBA", NULL
-};
-
-static int
-ppc_pc873xx_detect(struct ppc_data *ppc, int chipset_mode) /* XXX mode never forced */
-{
- static int index = 0;
- int idport, irq;
- int ptr, pcr, val, i;
-
- while ((idport = pc873xx_basetab[index++])) {
-
- /* XXX should check first to see if this location is already claimed */
-
- /*
- * Pull the 873xx through the power-on ID cycle (2.2,1.).
- * We can't use this to locate the chip as it may already have
- * been used by the BIOS.
- */
- (void)inb(idport); (void)inb(idport);
- (void)inb(idport); (void)inb(idport);
-
- /*
- * Read the SID byte. Possible values are :
- *
- * 01010xxx PC87334
- * 0001xxxx PC87332
- * 01110xxx PC87306
- * 00110xxx PC87303
- */
- outb(idport, PC873_SID);
- val = inb(idport + 1);
- if ((val & 0xf0) == 0x10) {
- ppc->ppc_model = NS_PC87332;
- } else if ((val & 0xf8) == 0x70) {
- ppc->ppc_model = NS_PC87306;
- } else if ((val & 0xf8) == 0x50) {
- ppc->ppc_model = NS_PC87334;
- } else if ((val & 0xf8) == 0x40) { /* Should be 0x30 by the
- documentation, but probing
- yielded 0x40... */
- ppc->ppc_model = NS_PC87303;
- } else {
- if (bootverbose && (val != 0xff))
- printf("PC873xx probe at 0x%x got unknown ID 0x%x\n", idport, val);
- continue ; /* not recognised */
- }
-
- /* print registers */
- if (bootverbose) {
- printf("PC873xx");
- for (i=0; pc873xx_regstab[i] != -1; i++) {
- outb(idport, pc873xx_regstab[i]);
- printf(" %s=0x%x", pc873xx_rnametab[i],
- inb(idport + 1) & 0xff);
- }
- printf("\n");
- }
-
- /*
- * We think we have one. Is it enabled and where we want it to be?
- */
- outb(idport, PC873_FER);
- val = inb(idport + 1);
- if (!(val & PC873_PPENABLE)) {
- if (bootverbose)
- printf("PC873xx parallel port disabled\n");
- continue;
- }
- outb(idport, PC873_FAR);
- val = inb(idport + 1);
- /* XXX we should create a driver instance for every port found */
- if (pc873xx_porttab[val & 0x3] != ppc->ppc_base) {
-
- /* First try to change the port address to that requested... */
-
- switch(ppc->ppc_base) {
- case 0x378:
- val &= 0xfc;
- break;
-
- case 0x3bc:
- val &= 0xfd;
- break;
-
- case 0x278:
- val &= 0xfe;
- break;
-
- default:
- val &= 0xfd;
- break;
- }
-
- outb(idport, PC873_FAR);
- outb(idport + 1, val);
- outb(idport + 1, val);
-
- /* Check for success by reading back the value we supposedly
- wrote and comparing...*/
-
- outb(idport, PC873_FAR);
- val = inb(idport + 1) & 0x3;
-
- /* If we fail, report the failure... */
-
- if (pc873xx_porttab[val] != ppc->ppc_base) {
- if (bootverbose)
- printf("PC873xx at 0x%x not for driver at port 0x%x\n",
- pc873xx_porttab[val], ppc->ppc_base);
- }
- continue;
- }
-
- outb(idport, PC873_PTR);
- ptr = inb(idport + 1);
-
- /* get irq settings */
- if (ppc->ppc_base == 0x378)
- irq = (ptr & PC873_LPTBIRQ7) ? 7 : 5;
- else
- irq = pc873xx_irqtab[val];
-
- if (bootverbose)
- printf("PC873xx irq %d at 0x%x\n", irq, ppc->ppc_base);
-
- /*
- * Check if irq settings are correct
- */
- if (irq != ppc->ppc_irq) {
- /*
- * If the chipset is not locked and base address is 0x378,
- * we have another chance
- */
- if (ppc->ppc_base == 0x378 && !(ptr & PC873_CFGLOCK)) {
- if (ppc->ppc_irq == 7) {
- outb(idport + 1, (ptr | PC873_LPTBIRQ7));
- outb(idport + 1, (ptr | PC873_LPTBIRQ7));
- } else {
- outb(idport + 1, (ptr & ~PC873_LPTBIRQ7));
- outb(idport + 1, (ptr & ~PC873_LPTBIRQ7));
- }
- if (bootverbose)
- printf("PC873xx irq set to %d\n", ppc->ppc_irq);
- } else {
- if (bootverbose)
- printf("PC873xx sorry, can't change irq setting\n");
- }
- } else {
- if (bootverbose)
- printf("PC873xx irq settings are correct\n");
- }
-
- outb(idport, PC873_PCR);
- pcr = inb(idport + 1);
-
- if ((ptr & PC873_CFGLOCK) || !chipset_mode) {
- if (bootverbose)
- printf("PC873xx %s", (ptr & PC873_CFGLOCK)?"locked":"unlocked");
-
- ppc->ppc_avm |= PPB_NIBBLE;
- if (bootverbose)
- printf(", NIBBLE");
-
- if (pcr & PC873_EPPEN) {
- ppc->ppc_avm |= PPB_EPP;
-
- if (bootverbose)
- printf(", EPP");
-
- if (pcr & PC873_EPP19)
- ppc->ppc_epp = EPP_1_9;
- else
- ppc->ppc_epp = EPP_1_7;
-
- if ((ppc->ppc_model == NS_PC87332) && bootverbose) {
- outb(idport, PC873_PTR);
- ptr = inb(idport + 1);
- if (ptr & PC873_EPPRDIR)
- printf(", Regular mode");
- else
- printf(", Automatic mode");
- }
- } else if (pcr & PC873_ECPEN) {
- ppc->ppc_avm |= PPB_ECP;
- if (bootverbose)
- printf(", ECP");
-
- if (pcr & PC873_ECPCLK) { /* XXX */
- ppc->ppc_avm |= PPB_PS2;
- if (bootverbose)
- printf(", PS/2");
- }
- } else {
- outb(idport, PC873_PTR);
- ptr = inb(idport + 1);
- if (ptr & PC873_EXTENDED) {
- ppc->ppc_avm |= PPB_SPP;
- if (bootverbose)
- printf(", SPP");
- }
- }
- } else {
- if (bootverbose)
- printf("PC873xx unlocked");
-
- if (chipset_mode & PPB_ECP) {
- if ((chipset_mode & PPB_EPP) && bootverbose)
- printf(", ECP+EPP not supported");
-
- pcr &= ~PC873_EPPEN;
- pcr |= (PC873_ECPEN | PC873_ECPCLK); /* XXX */
- outb(idport + 1, pcr);
- outb(idport + 1, pcr);
-
- if (bootverbose)
- printf(", ECP");
-
- } else if (chipset_mode & PPB_EPP) {
- pcr &= ~(PC873_ECPEN | PC873_ECPCLK);
- pcr |= (PC873_EPPEN | PC873_EPP19);
- outb(idport + 1, pcr);
- outb(idport + 1, pcr);
-
- ppc->ppc_epp = EPP_1_9; /* XXX */
-
- if (bootverbose)
- printf(", EPP1.9");
-
- /* enable automatic direction turnover */
- if (ppc->ppc_model == NS_PC87332) {
- outb(idport, PC873_PTR);
- ptr = inb(idport + 1);
- ptr &= ~PC873_EPPRDIR;
- outb(idport + 1, ptr);
- outb(idport + 1, ptr);
-
- if (bootverbose)
- printf(", Automatic mode");
- }
- } else {
- pcr &= ~(PC873_ECPEN | PC873_ECPCLK | PC873_EPPEN);
- outb(idport + 1, pcr);
- outb(idport + 1, pcr);
-
- /* configure extended bit in PTR */
- outb(idport, PC873_PTR);
- ptr = inb(idport + 1);
-
- if (chipset_mode & PPB_PS2) {
- ptr |= PC873_EXTENDED;
-
- if (bootverbose)
- printf(", PS/2");
-
- } else {
- /* default to NIBBLE mode */
- ptr &= ~PC873_EXTENDED;
-
- if (bootverbose)
- printf(", NIBBLE");
- }
- outb(idport + 1, ptr);
- outb(idport + 1, ptr);
- }
-
- ppc->ppc_avm = chipset_mode;
- }
-
- if (bootverbose)
- printf("\n");
-
- ppc->ppc_type = PPC_TYPE_GENERIC;
- ppc_generic_setmode(ppc, chipset_mode);
-
- return(chipset_mode);
- }
- return(-1);
-}
-
-/*
- * ppc_smc37c66xgt_detect
- *
- * SMC FDC37C66xGT configuration.
- */
-static int
-ppc_smc37c66xgt_detect(struct ppc_data *ppc, int chipset_mode)
-{
- int s, i;
- u_char r;
- int type = -1;
- int csr = SMC66x_CSR; /* initial value is 0x3F0 */
-
- int port_address[] = { -1 /* disabled */ , 0x3bc, 0x378, 0x278 };
-
-
-#define cio csr+1 /* config IO port is either 0x3F1 or 0x371 */
-
- /*
- * Detection: enter configuration mode and read CRD register.
- */
-
- s = splhigh();
- outb(csr, SMC665_iCODE);
- outb(csr, SMC665_iCODE);
- splx(s);
-
- outb(csr, 0xd);
- if (inb(cio) == 0x65) {
- type = SMC_37C665GT;
- goto config;
- }
-
- for (i = 0; i < 2; i++) {
- s = splhigh();
- outb(csr, SMC666_iCODE);
- outb(csr, SMC666_iCODE);
- splx(s);
-
- outb(csr, 0xd);
- if (inb(cio) == 0x66) {
- type = SMC_37C666GT;
- break;
- }
-
- /* Another chance, CSR may be hard-configured to be at 0x370 */
- csr = SMC666_CSR;
- }
-
-config:
- /*
- * If chipset not found, do not continue.
- */
- if (type == -1)
- return (-1);
-
- /* select CR1 */
- outb(csr, 0x1);
-
- /* read the port's address: bits 0 and 1 of CR1 */
- r = inb(cio) & SMC_CR1_ADDR;
- if (port_address[(int)r] != ppc->ppc_base)
- return (-1);
-
- ppc->ppc_model = type;
-
- /*
- * CR1 and CR4 registers bits 3 and 0/1 for mode configuration
- * If SPP mode is detected, try to set ECP+EPP mode
- */
-
- if (bootverbose) {
- outb(csr, 0x1);
- printf("ppc%d: SMC registers CR1=0x%x", ppc->ppc_unit,
- inb(cio) & 0xff);
-
- outb(csr, 0x4);
- printf(" CR4=0x%x", inb(cio) & 0xff);
- }
-
- /* select CR1 */
- outb(csr, 0x1);
-
- if (!chipset_mode) {
- /* autodetect mode */
-
- /* 666GT is ~certainly~ hardwired to an extended ECP+EPP mode */
- if (type == SMC_37C666GT) {
- ppc->ppc_avm |= PPB_ECP | PPB_EPP | PPB_SPP;
- if (bootverbose)
- printf(" configuration hardwired, supposing " \
- "ECP+EPP SPP");
-
- } else
- if ((inb(cio) & SMC_CR1_MODE) == 0) {
- /* already in extended parallel port mode, read CR4 */
- outb(csr, 0x4);
- r = (inb(cio) & SMC_CR4_EMODE);
-
- switch (r) {
- case SMC_SPP:
- ppc->ppc_avm |= PPB_SPP;
- if (bootverbose)
- printf(" SPP");
- break;
-
- case SMC_EPPSPP:
- ppc->ppc_avm |= PPB_EPP | PPB_SPP;
- if (bootverbose)
- printf(" EPP SPP");
- break;
-
- case SMC_ECP:
- ppc->ppc_avm |= PPB_ECP | PPB_SPP;
- if (bootverbose)
- printf(" ECP SPP");
- break;
-
- case SMC_ECPEPP:
- ppc->ppc_avm |= PPB_ECP | PPB_EPP | PPB_SPP;
- if (bootverbose)
- printf(" ECP+EPP SPP");
- break;
- }
- } else {
- /* not an extended port mode */
- ppc->ppc_avm |= PPB_SPP;
- if (bootverbose)
- printf(" SPP");
- }
-
- } else {
- /* mode forced */
- ppc->ppc_avm = chipset_mode;
-
- /* 666GT is ~certainly~ hardwired to an extended ECP+EPP mode */
- if (type == SMC_37C666GT)
- goto end_detect;
-
- r = inb(cio);
- if ((chipset_mode & (PPB_ECP | PPB_EPP)) == 0) {
- /* do not use ECP when the mode is not forced to */
- outb(cio, r | SMC_CR1_MODE);
- if (bootverbose)
- printf(" SPP");
- } else {
- /* an extended mode is selected */
- outb(cio, r & ~SMC_CR1_MODE);
-
- /* read CR4 register and reset mode field */
- outb(csr, 0x4);
- r = inb(cio) & ~SMC_CR4_EMODE;
-
- if (chipset_mode & PPB_ECP) {
- if (chipset_mode & PPB_EPP) {
- outb(cio, r | SMC_ECPEPP);
- if (bootverbose)
- printf(" ECP+EPP");
- } else {
- outb(cio, r | SMC_ECP);
- if (bootverbose)
- printf(" ECP");
- }
- } else {
- /* PPB_EPP is set */
- outb(cio, r | SMC_EPPSPP);
- if (bootverbose)
- printf(" EPP SPP");
- }
- }
- ppc->ppc_avm = chipset_mode;
- }
-
- /* set FIFO threshold to 16 */
- if (ppc->ppc_avm & PPB_ECP) {
- /* select CRA */
- outb(csr, 0xa);
- outb(cio, 16);
- }
-
-end_detect:
-
- if (bootverbose)
- printf ("\n");
-
- if (ppc->ppc_avm & PPB_EPP) {
- /* select CR4 */
- outb(csr, 0x4);
- r = inb(cio);
-
- /*
- * Set the EPP protocol...
- * Low=EPP 1.9 (1284 standard) and High=EPP 1.7
- */
- if (ppc->ppc_epp == EPP_1_9)
- outb(cio, (r & ~SMC_CR4_EPPTYPE));
- else
- outb(cio, (r | SMC_CR4_EPPTYPE));
- }
-
- /* end config mode */
- outb(csr, 0xaa);
-
- ppc->ppc_type = PPC_TYPE_SMCLIKE;
- ppc_smclike_setmode(ppc, chipset_mode);
-
- return (chipset_mode);
-}
-
-/*
- * SMC FDC37C935 configuration
- * Found on many Alpha machines
- */
-static int
-ppc_smc37c935_detect(struct ppc_data *ppc, int chipset_mode)
-{
- int s;
- int type = -1;
-
- s = splhigh();
- outb(SMC935_CFG, 0x55); /* enter config mode */
- outb(SMC935_CFG, 0x55);
- splx(s);
-
- outb(SMC935_IND, SMC935_ID); /* check device id */
- if (inb(SMC935_DAT) == 0x2)
- type = SMC_37C935;
-
- if (type == -1) {
- outb(SMC935_CFG, 0xaa); /* exit config mode */
- return (-1);
- }
-
- ppc->ppc_model = type;
-
- outb(SMC935_IND, SMC935_LOGDEV); /* select parallel port, */
- outb(SMC935_DAT, 3); /* which is logical device 3 */
-
- /* set io port base */
- outb(SMC935_IND, SMC935_PORTHI);
- outb(SMC935_DAT, (u_char)((ppc->ppc_base & 0xff00) >> 8));
- outb(SMC935_IND, SMC935_PORTLO);
- outb(SMC935_DAT, (u_char)(ppc->ppc_base & 0xff));
-
- if (!chipset_mode)
- ppc->ppc_avm = PPB_COMPATIBLE; /* default mode */
- else {
- ppc->ppc_avm = chipset_mode;
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_CENT); /* start in compatible mode */
-
- /* SPP + EPP or just plain SPP */
- if (chipset_mode & (PPB_SPP)) {
- if (chipset_mode & PPB_EPP) {
- if (ppc->ppc_epp == EPP_1_9) {
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_EPP19SPP);
- }
- if (ppc->ppc_epp == EPP_1_7) {
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_EPP17SPP);
- }
- } else {
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_SPP);
- }
- }
-
- /* ECP + EPP or just plain ECP */
- if (chipset_mode & PPB_ECP) {
- if (chipset_mode & PPB_EPP) {
- if (ppc->ppc_epp == EPP_1_9) {
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_ECPEPP19);
- }
- if (ppc->ppc_epp == EPP_1_7) {
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_ECPEPP17);
- }
- } else {
- outb(SMC935_IND, SMC935_PPMODE);
- outb(SMC935_DAT, SMC935_ECP);
- }
- }
- }
-
- outb(SMC935_CFG, 0xaa); /* exit config mode */
-
- ppc->ppc_type = PPC_TYPE_SMCLIKE;
- ppc_smclike_setmode(ppc, chipset_mode);
-
- return (chipset_mode);
-}
-
-/*
- * Winbond W83877F stuff
- *
- * EFER: extended function enable register
- * EFIR: extended function index register
- * EFDR: extended function data register
- */
-#define efir ((efer == 0x250) ? 0x251 : 0x3f0)
-#define efdr ((efer == 0x250) ? 0x252 : 0x3f1)
-
-static int w83877f_efers[] = { 0x250, 0x3f0, 0x3f0, 0x250 };
-static int w83877f_keys[] = { 0x89, 0x86, 0x87, 0x88 };
-static int w83877f_keyiter[] = { 1, 2, 2, 1 };
-static int w83877f_hefs[] = { WINB_HEFERE, WINB_HEFRAS, WINB_HEFERE | WINB_HEFRAS, 0 };
-
-static int
-ppc_w83877f_detect(struct ppc_data *ppc, int chipset_mode)
-{
- int i, j, efer;
- unsigned char r, hefere, hefras;
-
- for (i = 0; i < 4; i ++) {
- /* first try to enable configuration registers */
- efer = w83877f_efers[i];
-
- /* write the key to the EFER */
- for (j = 0; j < w83877f_keyiter[i]; j ++)
- outb (efer, w83877f_keys[i]);
-
- /* then check HEFERE and HEFRAS bits */
- outb (efir, 0x0c);
- hefere = inb(efdr) & WINB_HEFERE;
-
- outb (efir, 0x16);
- hefras = inb(efdr) & WINB_HEFRAS;
-
- /*
- * HEFRAS HEFERE
- * 0 1 write 89h to 250h (power-on default)
- * 1 0 write 86h twice to 3f0h
- * 1 1 write 87h twice to 3f0h
- * 0 0 write 88h to 250h
- */
- if ((hefere | hefras) == w83877f_hefs[i])
- goto found;
- }
-
- return (-1); /* failed */
-
-found:
- /* check base port address - read from CR23 */
- outb(efir, 0x23);
- if (ppc->ppc_base != inb(efdr) * 4) /* 4 bytes boundaries */
- return (-1);
-
- /* read CHIP ID from CR9/bits0-3 */
- outb(efir, 0x9);
-
- switch (inb(efdr) & WINB_CHIPID) {
- case WINB_W83877F_ID:
- ppc->ppc_model = WINB_W83877F;
- break;
-
- case WINB_W83877AF_ID:
- ppc->ppc_model = WINB_W83877AF;
- break;
-
- default:
- ppc->ppc_model = WINB_UNKNOWN;
- }
-
- if (bootverbose) {
- /* dump of registers */
- printf("ppc%d: 0x%x - ", ppc->ppc_unit, w83877f_keys[i]);
- for (i = 0; i <= 0xd; i ++) {
- outb(efir, i);
- printf("0x%x ", inb(efdr));
- }
- for (i = 0x10; i <= 0x17; i ++) {
- outb(efir, i);
- printf("0x%x ", inb(efdr));
- }
- outb(efir, 0x1e);
- printf("0x%x ", inb(efdr));
- for (i = 0x20; i <= 0x29; i ++) {
- outb(efir, i);
- printf("0x%x ", inb(efdr));
- }
- printf("\n");
- printf("ppc%d:", ppc->ppc_unit);
- }
-
- ppc->ppc_type = PPC_TYPE_GENERIC;
-
- if (!chipset_mode) {
- /* autodetect mode */
-
- /* select CR0 */
- outb(efir, 0x0);
- r = inb(efdr) & (WINB_PRTMODS0 | WINB_PRTMODS1);
-
- /* select CR9 */
- outb(efir, 0x9);
- r |= (inb(efdr) & WINB_PRTMODS2);
-
- switch (r) {
- case WINB_W83757:
- if (bootverbose)
- printf("ppc%d: W83757 compatible mode\n",
- ppc->ppc_unit);
- return (-1); /* generic or SMC-like */
-
- case WINB_EXTFDC:
- case WINB_EXTADP:
- case WINB_EXT2FDD:
- case WINB_JOYSTICK:
- if (bootverbose)
- printf(" not in parallel port mode\n");
- return (-1);
-
- case (WINB_PARALLEL | WINB_EPP_SPP):
- ppc->ppc_avm |= PPB_EPP | PPB_SPP;
- if (bootverbose)
- printf(" EPP SPP");
- break;
-
- case (WINB_PARALLEL | WINB_ECP):
- ppc->ppc_avm |= PPB_ECP | PPB_SPP;
- if (bootverbose)
- printf(" ECP SPP");
- break;
-
- case (WINB_PARALLEL | WINB_ECP_EPP):
- ppc->ppc_avm |= PPB_ECP | PPB_EPP | PPB_SPP;
- ppc->ppc_type = PPC_TYPE_SMCLIKE;
-
- if (bootverbose)
- printf(" ECP+EPP SPP");
- break;
- default:
- printf("%s: unknown case (0x%x)!\n", __func__, r);
- }
-
- } else {
- /* mode forced */
-
- /* select CR9 and set PRTMODS2 bit */
- outb(efir, 0x9);
- outb(efdr, inb(efdr) & ~WINB_PRTMODS2);
-
- /* select CR0 and reset PRTMODSx bits */
- outb(efir, 0x0);
- outb(efdr, inb(efdr) & ~(WINB_PRTMODS0 | WINB_PRTMODS1));
-
- if (chipset_mode & PPB_ECP) {
- if (chipset_mode & PPB_EPP) {
- outb(efdr, inb(efdr) | WINB_ECP_EPP);
- if (bootverbose)
- printf(" ECP+EPP");
-
- ppc->ppc_type = PPC_TYPE_SMCLIKE;
-
- } else {
- outb(efdr, inb(efdr) | WINB_ECP);
- if (bootverbose)
- printf(" ECP");
- }
- } else {
- /* select EPP_SPP otherwise */
- outb(efdr, inb(efdr) | WINB_EPP_SPP);
- if (bootverbose)
- printf(" EPP SPP");
- }
- ppc->ppc_avm = chipset_mode;
- }
-
- if (bootverbose)
- printf("\n");
-
- /* exit configuration mode */
- outb(efer, 0xaa);
-
- switch (ppc->ppc_type) {
- case PPC_TYPE_SMCLIKE:
- ppc_smclike_setmode(ppc, chipset_mode);
- break;
- default:
- ppc_generic_setmode(ppc, chipset_mode);
- break;
- }
-
- return (chipset_mode);
-}
-#endif
-
-/*
- * ppc_generic_detect
- */
-static int
-ppc_generic_detect(struct ppc_data *ppc, int chipset_mode)
-{
- /* default to generic */
- ppc->ppc_type = PPC_TYPE_GENERIC;
-
- if (bootverbose)
- printf("ppc%d:", ppc->ppc_unit);
-
- /* first, check for ECP */
- w_ecr(ppc, PPC_ECR_PS2);
- if ((r_ecr(ppc) & 0xe0) == PPC_ECR_PS2) {
- ppc->ppc_dtm |= PPB_ECP | PPB_SPP;
- if (bootverbose)
- printf(" ECP SPP");
-
- /* search for SMC style ECP+EPP mode */
- w_ecr(ppc, PPC_ECR_EPP);
- }
-
- /* try to reset EPP timeout bit */
- if (ppc_check_epp_timeout(ppc)) {
- ppc->ppc_dtm |= PPB_EPP;
-
- if (ppc->ppc_dtm & PPB_ECP) {
- /* SMC like chipset found */
- ppc->ppc_model = SMC_LIKE;
- ppc->ppc_type = PPC_TYPE_SMCLIKE;
-
- if (bootverbose)
- printf(" ECP+EPP");
- } else {
- if (bootverbose)
- printf(" EPP");
- }
- } else {
- /* restore to standard mode */
- w_ecr(ppc, PPC_ECR_STD);
- }
-
- /* XXX try to detect NIBBLE and PS2 modes */
- ppc->ppc_dtm |= PPB_NIBBLE;
-
- if (bootverbose)
- printf(" SPP");
-
- if (chipset_mode)
- ppc->ppc_avm = chipset_mode;
- else
- ppc->ppc_avm = ppc->ppc_dtm;
-
- if (bootverbose)
- printf("\n");
-
- switch (ppc->ppc_type) {
- case PPC_TYPE_SMCLIKE:
- ppc_smclike_setmode(ppc, chipset_mode);
- break;
- default:
- ppc_generic_setmode(ppc, chipset_mode);
- break;
- }
-
- return (chipset_mode);
-}
-
-/*
- * ppc_detect()
- *
- * mode is the mode suggested at boot
- */
-static int
-ppc_detect(struct ppc_data *ppc, int chipset_mode) {
-
-#ifdef PPC_PROBE_CHIPSET
- int i, mode;
-
- /* list of supported chipsets */
- int (*chipset_detect[])(struct ppc_data *, int) = {
- ppc_pc873xx_detect,
- ppc_smc37c66xgt_detect,
- ppc_w83877f_detect,
- ppc_smc37c935_detect,
- ppc_generic_detect,
- NULL
- };
-#endif
-
- /* if can't find the port and mode not forced return error */
- if (!ppc_detect_port(ppc) && chipset_mode == 0)
- return (EIO); /* failed, port not present */
-
- /* assume centronics compatible mode is supported */
- ppc->ppc_avm = PPB_COMPATIBLE;
-
-#ifdef PPC_PROBE_CHIPSET
- /* we have to differenciate available chipset modes,
- * chipset running modes and IEEE-1284 operating modes
- *
- * after detection, the port must support running in compatible mode
- */
- if (ppc->ppc_flags & 0x40) {
- if (bootverbose)
- printf("ppc: chipset forced to generic\n");
-#endif
-
- ppc->ppc_mode = ppc_generic_detect(ppc, chipset_mode);
-
-#ifdef PPC_PROBE_CHIPSET
- } else {
- for (i=0; chipset_detect[i] != NULL; i++) {
- if ((mode = chipset_detect[i](ppc, chipset_mode)) != -1) {
- ppc->ppc_mode = mode;
- break;
- }
- }
- }
-#endif
-
- /* configure/detect ECP FIFO */
- if ((ppc->ppc_avm & PPB_ECP) && !(ppc->ppc_flags & 0x80))
- ppc_detect_fifo(ppc);
-
- return (0);
-}
-
-/*
- * ppc_exec_microseq()
- *
- * Execute a microsequence.
- * Microsequence mechanism is supposed to handle fast I/O operations.
- */
-static int
-ppc_exec_microseq(device_t dev, struct ppb_microseq **p_msq)
-{
- struct ppc_data *ppc = DEVTOSOFTC(dev);
- struct ppb_microseq *mi;
- char cc, *p;
- int i, iter, len;
- int error;
-
- register int reg;
- register char mask;
- register int accum = 0;
- register char *ptr = 0;
-
- struct ppb_microseq *stack = 0;
-
-/* microsequence registers are equivalent to PC-like port registers */
-
-#define r_reg(register,ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, register))
-#define w_reg(register, ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, register, byte))
-
-#define INCR_PC (mi ++) /* increment program counter */
-
- mi = *p_msq;
- for (;;) {
- switch (mi->opcode) {
- case MS_OP_RSET:
- cc = r_reg(mi->arg[0].i, ppc);
- cc &= (char)mi->arg[2].i; /* clear mask */
- cc |= (char)mi->arg[1].i; /* assert mask */
- w_reg(mi->arg[0].i, ppc, cc);
- INCR_PC;
- break;
-
- case MS_OP_RASSERT_P:
- reg = mi->arg[1].i;
- ptr = ppc->ppc_ptr;
-
- if ((len = mi->arg[0].i) == MS_ACCUM) {
- accum = ppc->ppc_accum;
- for (; accum; accum--)
- w_reg(reg, ppc, *ptr++);
- ppc->ppc_accum = accum;
- } else
- for (i=0; i<len; i++)
- w_reg(reg, ppc, *ptr++);
- ppc->ppc_ptr = ptr;
-
- INCR_PC;
- break;
-
- case MS_OP_RFETCH_P:
- reg = mi->arg[1].i;
- mask = (char)mi->arg[2].i;
- ptr = ppc->ppc_ptr;
-
- if ((len = mi->arg[0].i) == MS_ACCUM) {
- accum = ppc->ppc_accum;
- for (; accum; accum--)
- *ptr++ = r_reg(reg, ppc) & mask;
- ppc->ppc_accum = accum;
- } else
- for (i=0; i<len; i++)
- *ptr++ = r_reg(reg, ppc) & mask;
- ppc->ppc_ptr = ptr;
-
- INCR_PC;
- break;
-
- case MS_OP_RFETCH:
- *((char *) mi->arg[2].p) = r_reg(mi->arg[0].i, ppc) &
- (char)mi->arg[1].i;
- INCR_PC;
- break;
-
- case MS_OP_RASSERT:
- case MS_OP_DELAY:
-
- /* let's suppose the next instr. is the same */
- prefetch:
- for (;mi->opcode == MS_OP_RASSERT; INCR_PC)
- w_reg(mi->arg[0].i, ppc, (char)mi->arg[1].i);
-
- if (mi->opcode == MS_OP_DELAY) {
- DELAY(mi->arg[0].i);
- INCR_PC;
- goto prefetch;
- }
- break;
-
- case MS_OP_ADELAY:
- if (mi->arg[0].i)
- tsleep(NULL, PPBPRI, "ppbdelay",
- mi->arg[0].i * (hz/1000));
- INCR_PC;
- break;
-
- case MS_OP_TRIG:
- reg = mi->arg[0].i;
- iter = mi->arg[1].i;
- p = (char *)mi->arg[2].p;
-
- /* XXX delay limited to 255 us */
- for (i=0; i<iter; i++) {
- w_reg(reg, ppc, *p++);
- DELAY((unsigned char)*p++);
- }
- INCR_PC;
- break;
-
- case MS_OP_SET:
- ppc->ppc_accum = mi->arg[0].i;
- INCR_PC;
- break;
-
- case MS_OP_DBRA:
- if (--ppc->ppc_accum > 0)
- mi += mi->arg[0].i;
- INCR_PC;
- break;
-
- case MS_OP_BRSET:
- cc = r_str(ppc);
- if ((cc & (char)mi->arg[0].i) == (char)mi->arg[0].i)
- mi += mi->arg[1].i;
- INCR_PC;
- break;
-
- case MS_OP_BRCLEAR:
- cc = r_str(ppc);
- if ((cc & (char)mi->arg[0].i) == 0)
- mi += mi->arg[1].i;
- INCR_PC;
- break;
-
- case MS_OP_BRSTAT:
- cc = r_str(ppc);
- if ((cc & ((char)mi->arg[0].i | (char)mi->arg[1].i)) ==
- (char)mi->arg[0].i)
- mi += mi->arg[2].i;
- INCR_PC;
- break;
-
- case MS_OP_C_CALL:
- /*
- * If the C call returns !0 then end the microseq.
- * The current state of ptr is passed to the C function
- */
- if ((error = mi->arg[0].f(mi->arg[1].p, ppc->ppc_ptr)))
- return (error);
-
- INCR_PC;
- break;
-
- case MS_OP_PTR:
- ppc->ppc_ptr = (char *)mi->arg[0].p;
- INCR_PC;
- break;
-
- case MS_OP_CALL:
- if (stack)
- panic("%s: too much calls", __func__);
-
- if (mi->arg[0].p) {
- /* store the state of the actual
- * microsequence
- */
- stack = mi;
-
- /* jump to the new microsequence */
- mi = (struct ppb_microseq *)mi->arg[0].p;
- } else
- INCR_PC;
-
- break;
-
- case MS_OP_SUBRET:
- /* retrieve microseq and pc state before the call */
- mi = stack;
-
- /* reset the stack */
- stack = 0;
-
- /* XXX return code */
-
- INCR_PC;
- break;
-
- case MS_OP_PUT:
- case MS_OP_GET:
- case MS_OP_RET:
- /* can't return to ppb level during the execution
- * of a submicrosequence */
- if (stack)
- panic("%s: can't return to ppb level",
- __func__);
-
- /* update pc for ppb level of execution */
- *p_msq = mi;
-
- /* return to ppb level of execution */
- return (0);
-
- default:
- panic("%s: unknown microsequence opcode 0x%x",
- __func__, mi->opcode);
- }
- }
-
- /* unreached */
-}
-
-static void
-ppcintr(void *arg)
-{
- device_t dev = (device_t)arg;
- struct ppc_data *ppc = (struct ppc_data *)device_get_softc(dev);
- u_char ctr, ecr, str;
-
- str = r_str(ppc);
- ctr = r_ctr(ppc);
- ecr = r_ecr(ppc);
-
-#if PPC_DEBUG > 1
- printf("![%x/%x/%x]", ctr, ecr, str);
-#endif
-
- /* don't use ecp mode with IRQENABLE set */
- if (ctr & IRQENABLE) {
- return;
- }
-
- /* interrupts are generated by nFault signal
- * only in ECP mode */
- if ((str & nFAULT) && (ppc->ppc_mode & PPB_ECP)) {
- /* check if ppc driver has programmed the
- * nFault interrupt */
- if (ppc->ppc_irqstat & PPC_IRQ_nFAULT) {
-
- w_ecr(ppc, ecr | PPC_nFAULT_INTR);
- ppc->ppc_irqstat &= ~PPC_IRQ_nFAULT;
- } else {
- /* shall be handled by underlying layers XXX */
- return;
- }
- }
-
- if (ppc->ppc_irqstat & PPC_IRQ_DMA) {
- /* disable interrupts (should be done by hardware though) */
- w_ecr(ppc, ecr | PPC_SERVICE_INTR);
- ppc->ppc_irqstat &= ~PPC_IRQ_DMA;
- ecr = r_ecr(ppc);
-
- /* check if DMA completed */
- if ((ppc->ppc_avm & PPB_ECP) && (ecr & PPC_ENABLE_DMA)) {
-#ifdef PPC_DEBUG
- printf("a");
-#endif
- /* stop DMA */
- w_ecr(ppc, ecr & ~PPC_ENABLE_DMA);
- ecr = r_ecr(ppc);
-
- if (ppc->ppc_dmastat == PPC_DMA_STARTED) {
-#ifdef PPC_DEBUG
- printf("d");
-#endif
- isa_dmadone(
- ppc->ppc_dmaflags,
- ppc->ppc_dmaddr,
- ppc->ppc_dmacnt,
- ppc->ppc_dmachan);
-
- ppc->ppc_dmastat = PPC_DMA_COMPLETE;
-
- /* wakeup the waiting process */
- wakeup(ppc);
- }
- }
- } else if (ppc->ppc_irqstat & PPC_IRQ_FIFO) {
-
- /* classic interrupt I/O */
- ppc->ppc_irqstat &= ~PPC_IRQ_FIFO;
- }
-
- return;
-}
-
-static int
-ppc_read(device_t dev, char *buf, int len, int mode)
-{
- return (EINVAL);
-}
-
-/*
- * Call this function if you want to send data in any advanced mode
- * of your parallel port: FIFO, DMA
- *
- * If what you want is not possible (no ECP, no DMA...),
- * EINVAL is returned
- */
-static int
-ppc_write(device_t dev, char *buf, int len, int how)
-{
- struct ppc_data *ppc = DEVTOSOFTC(dev);
- char ecr, ecr_sav, ctr, ctr_sav;
- int s, error = 0;
- int spin;
-
-#ifdef PPC_DEBUG
- printf("w");
-#endif
-
- ecr_sav = r_ecr(ppc);
- ctr_sav = r_ctr(ppc);
-
- /*
- * Send buffer with DMA, FIFO and interrupts
- */
- if ((ppc->ppc_avm & PPB_ECP) && (ppc->ppc_registered)) {
-
- if (ppc->ppc_dmachan > 0) {
-
- /* byte mode, no intr, no DMA, dir=0, flush fifo
- */
- ecr = PPC_ECR_STD | PPC_DISABLE_INTR;
- w_ecr(ppc, ecr);
-
- /* disable nAck interrupts */
- ctr = r_ctr(ppc);
- ctr &= ~IRQENABLE;
- w_ctr(ppc, ctr);
-
- ppc->ppc_dmaflags = 0;
- ppc->ppc_dmaddr = (caddr_t)buf;
- ppc->ppc_dmacnt = (u_int)len;
-
- switch (ppc->ppc_mode) {
- case PPB_COMPATIBLE:
- /* compatible mode with FIFO, no intr, DMA, dir=0 */
- ecr = PPC_ECR_FIFO | PPC_DISABLE_INTR | PPC_ENABLE_DMA;
- break;
- case PPB_ECP:
- ecr = PPC_ECR_ECP | PPC_DISABLE_INTR | PPC_ENABLE_DMA;
- break;
- default:
- error = EINVAL;
- goto error;
- }
-
- w_ecr(ppc, ecr);
- ecr = r_ecr(ppc);
-
- /* enter splhigh() not to be preempted
- * by the dma interrupt, we may miss
- * the wakeup otherwise
- */
- s = splhigh();
-
- ppc->ppc_dmastat = PPC_DMA_INIT;
-
- /* enable interrupts */
- ecr &= ~PPC_SERVICE_INTR;
- ppc->ppc_irqstat = PPC_IRQ_DMA;
- w_ecr(ppc, ecr);
-
- isa_dmastart(
- ppc->ppc_dmaflags,
- ppc->ppc_dmaddr,
- ppc->ppc_dmacnt,
- ppc->ppc_dmachan);
-#ifdef PPC_DEBUG
- printf("s%d", ppc->ppc_dmacnt);
-#endif
- ppc->ppc_dmastat = PPC_DMA_STARTED;
-
- /* Wait for the DMA completed interrupt. We hope we won't
- * miss it, otherwise a signal will be necessary to unlock the
- * process.
- */
- do {
- /* release CPU */
- error = tsleep(ppc,
- PPBPRI | PCATCH, "ppcdma", 0);
-
- } while (error == EWOULDBLOCK);
-
- splx(s);
-
- if (error) {
-#ifdef PPC_DEBUG
- printf("i");
-#endif
- /* stop DMA */
- isa_dmadone(
- ppc->ppc_dmaflags, ppc->ppc_dmaddr,
- ppc->ppc_dmacnt, ppc->ppc_dmachan);
-
- /* no dma, no interrupt, flush the fifo */
- w_ecr(ppc, PPC_ECR_RESET);
-
- ppc->ppc_dmastat = PPC_DMA_INTERRUPTED;
- goto error;
- }
-
- /* wait for an empty fifo */
- while (!(r_ecr(ppc) & PPC_FIFO_EMPTY)) {
-
- for (spin=100; spin; spin--)
- if (r_ecr(ppc) & PPC_FIFO_EMPTY)
- goto fifo_empty;
-#ifdef PPC_DEBUG
- printf("Z");
-#endif
- error = tsleep(ppc, PPBPRI | PCATCH, "ppcfifo", hz/100);
- if (error != EWOULDBLOCK) {
-#ifdef PPC_DEBUG
- printf("I");
-#endif
- /* no dma, no interrupt, flush the fifo */
- w_ecr(ppc, PPC_ECR_RESET);
-
- ppc->ppc_dmastat = PPC_DMA_INTERRUPTED;
- error = EINTR;
- goto error;
- }
- }
-
-fifo_empty:
- /* no dma, no interrupt, flush the fifo */
- w_ecr(ppc, PPC_ECR_RESET);
-
- } else
- error = EINVAL; /* XXX we should FIFO and
- * interrupts */
- } else
- error = EINVAL;
-
-error:
-
- /* PDRQ must be kept unasserted until nPDACK is
- * deasserted for a minimum of 350ns (SMC datasheet)
- *
- * Consequence may be a FIFO that never empty
- */
- DELAY(1);
-
- w_ecr(ppc, ecr_sav);
- w_ctr(ppc, ctr_sav);
-
- return (error);
-}
-
-static void
-ppc_reset_epp(device_t dev)
-{
- struct ppc_data *ppc = DEVTOSOFTC(dev);
-
- ppc_reset_epp_timeout(ppc);
-
- return;
-}
-
-static int
-ppc_setmode(device_t dev, int mode)
-{
- struct ppc_data *ppc = DEVTOSOFTC(dev);
-
- switch (ppc->ppc_type) {
- case PPC_TYPE_SMCLIKE:
- return (ppc_smclike_setmode(ppc, mode));
- break;
-
- case PPC_TYPE_GENERIC:
- default:
- return (ppc_generic_setmode(ppc, mode));
- break;
- }
-
- /* not reached */
- return (ENXIO);
-}
-
-static struct isa_pnp_id lpc_ids[] = {
- { 0x0004d041, "Standard parallel printer port" }, /* PNP0400 */
- { 0x0104d041, "ECP parallel printer port" }, /* PNP0401 */
- { 0 }
-};
-
-static int
-ppc_probe(device_t dev)
-{
-#ifdef __i386__
- static short next_bios_ppc = 0;
-#endif
- struct ppc_data *ppc;
- device_t parent;
- int error;
- u_long port;
-#ifdef PC98
-#define PC98_IEEE_1284_DISABLE 0x100
-#define PC98_IEEE_1284_PORT 0x140
-
- unsigned int pc98_ieee_mode = 0x00;
- unsigned int tmp;
-#endif
-
- parent = device_get_parent(dev);
-
- error = ISA_PNP_PROBE(parent, dev, lpc_ids);
- if (error == ENXIO)
- return (ENXIO);
- else if (error != 0) /* XXX shall be set after detection */
- device_set_desc(dev, "Parallel port");
-
- /*
- * Allocate the ppc_data structure.
- */
- ppc = DEVTOSOFTC(dev);
- bzero(ppc, sizeof(struct ppc_data));
-
- ppc->rid_irq = ppc->rid_drq = ppc->rid_ioport = 0;
- ppc->res_irq = ppc->res_drq = ppc->res_ioport = 0;
-
- /* retrieve ISA parameters */
- error = bus_get_resource(dev, SYS_RES_IOPORT, 0, &port, NULL);
-
-#ifdef __i386__
- /*
- * If port not specified, use bios list.
- */
- if (error) {
-#ifndef PC98
- if((next_bios_ppc < BIOS_MAX_PPC) &&
- (*(BIOS_PORTS+next_bios_ppc) != 0) ) {
- port = *(BIOS_PORTS+next_bios_ppc++);
- if (bootverbose)
- device_printf(dev, "parallel port found at 0x%x\n",
- (int) port);
- } else {
- device_printf(dev, "parallel port not found.\n");
- return ENXIO;
- }
-#else
- if (next_bios_ppc == 0) {
- /* Use default IEEE-1284 port of NEC PC-98x1 */
- port = PC98_IEEE_1284_PORT;
- next_bios_ppc += 1;
- if (bootverbose)
- device_printf(dev,
- "parallel port found at 0x%x\n",
- (int) port);
- }
-#endif
- bus_set_resource(dev, SYS_RES_IOPORT, 0, port,
- IO_LPTSIZE_EXTENDED);
- }
-#endif
-#ifdef __alpha__
- /*
- * There isn't a bios list on alpha. Put it in the usual place.
- */
- if (error) {
- bus_set_resource(dev, SYS_RES_IOPORT, 0, 0x3bc,
- IO_LPTSIZE_NORMAL);
- }
-#endif
-
- /* IO port is mandatory */
-
- /* Try "extended" IO port range...*/
- ppc->res_ioport = bus_alloc_resource(dev, SYS_RES_IOPORT,
- &ppc->rid_ioport, 0, ~0,
- IO_LPTSIZE_EXTENDED, RF_ACTIVE);
-
- if (ppc->res_ioport != 0) {
- if (bootverbose)
- device_printf(dev, "using extended I/O port range\n");
- } else {
- /* Failed? If so, then try the "normal" IO port range... */
- ppc->res_ioport = bus_alloc_resource(dev, SYS_RES_IOPORT,
- &ppc->rid_ioport, 0, ~0,
- IO_LPTSIZE_NORMAL,
- RF_ACTIVE);
- if (ppc->res_ioport != 0) {
- if (bootverbose)
- device_printf(dev, "using normal I/O port range\n");
- } else {
- device_printf(dev, "cannot reserve I/O port range\n");
- goto error;
- }
- }
-
- ppc->ppc_base = rman_get_start(ppc->res_ioport);
-
- ppc->bsh = rman_get_bushandle(ppc->res_ioport);
- ppc->bst = rman_get_bustag(ppc->res_ioport);
-
- ppc->ppc_flags = device_get_flags(dev);
-
- if (!(ppc->ppc_flags & 0x20)) {
- ppc->res_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &ppc->rid_irq,
- 0ul, ~0ul, 1, RF_SHAREABLE);
- ppc->res_drq = bus_alloc_resource(dev, SYS_RES_DRQ, &ppc->rid_drq,
- 0ul, ~0ul, 1, RF_ACTIVE);
- }
-
- if (ppc->res_irq)
- ppc->ppc_irq = rman_get_start(ppc->res_irq);
- if (ppc->res_drq)
- ppc->ppc_dmachan = rman_get_start(ppc->res_drq);
-
- ppc->ppc_unit = device_get_unit(dev);
- ppc->ppc_model = GENERIC;
-
- ppc->ppc_mode = PPB_COMPATIBLE;
- ppc->ppc_epp = (ppc->ppc_flags & 0x10) >> 4;
-
- ppc->ppc_type = PPC_TYPE_GENERIC;
-
-#ifdef PC98
- /*
- * IEEE STD 1284 Function Check and Enable
- * for default IEEE-1284 port of NEC PC-98x1
- */
- if ((ppc->ppc_base == PC98_IEEE_1284_PORT) &&
- !(ppc->ppc_flags & PC98_IEEE_1284_DISABLE)) {
- tmp = inb(ppc->ppc_base + PPC_1284_ENABLE);
- pc98_ieee_mode = tmp;
- if ((tmp & 0x10) == 0x10) {
- outb(ppc->ppc_base + PPC_1284_ENABLE, tmp & ~0x10);
- tmp = inb(ppc->ppc_base + PPC_1284_ENABLE);
- if ((tmp & 0x10) == 0x10)
- goto error;
- } else {
- outb(ppc->ppc_base + PPC_1284_ENABLE, tmp | 0x10);
- tmp = inb(ppc->ppc_base + PPC_1284_ENABLE);
- if ((tmp & 0x10) != 0x10)
- goto error;
- }
- outb(ppc->ppc_base + PPC_1284_ENABLE, pc98_ieee_mode | 0x10);
- }
-#endif
-
- /*
- * Try to detect the chipset and its mode.
- */
- if (ppc_detect(ppc, ppc->ppc_flags & 0xf))
- goto error;
-
- return (0);
-
-error:
-#ifdef PC98
- if ((ppc->ppc_base == PC98_IEEE_1284_PORT) &&
- !(ppc->ppc_flags & PC98_IEEE_1284_DISABLE)) {
- outb(ppc->ppc_base + PPC_1284_ENABLE, pc98_ieee_mode);
- }
-#endif
- if (ppc->res_irq != 0) {
- bus_release_resource(dev, SYS_RES_IRQ, ppc->rid_irq,
- ppc->res_irq);
- }
- if (ppc->res_ioport != 0) {
- bus_deactivate_resource(dev, SYS_RES_IOPORT, ppc->rid_ioport,
- ppc->res_ioport);
- bus_release_resource(dev, SYS_RES_IOPORT, ppc->rid_ioport,
- ppc->res_ioport);
- }
- if (ppc->res_drq != 0) {
- bus_deactivate_resource(dev, SYS_RES_DRQ, ppc->rid_drq,
- ppc->res_drq);
- bus_release_resource(dev, SYS_RES_DRQ, ppc->rid_drq,
- ppc->res_drq);
- }
- return (ENXIO);
-}
-
-static int
-ppc_attach(device_t dev)
-{
- struct ppc_data *ppc = DEVTOSOFTC(dev);
-
- device_t ppbus;
- device_t parent = device_get_parent(dev);
-
- device_printf(dev, "%s chipset (%s) in %s mode%s\n",
- ppc_models[ppc->ppc_model], ppc_avms[ppc->ppc_avm],
- ppc_modes[ppc->ppc_mode], (PPB_IS_EPP(ppc->ppc_mode)) ?
- ppc_epp_protocol[ppc->ppc_epp] : "");
-
- if (ppc->ppc_fifo)
- device_printf(dev, "FIFO with %d/%d/%d bytes threshold\n",
- ppc->ppc_fifo, ppc->ppc_wthr, ppc->ppc_rthr);
-
- if ((ppc->ppc_avm & PPB_ECP) && (ppc->ppc_dmachan > 0)) {
- /* acquire the DMA channel forever */ /* XXX */
- isa_dma_acquire(ppc->ppc_dmachan);
- isa_dmainit(ppc->ppc_dmachan, 1024); /* nlpt.BUFSIZE */
- }
-
- /* add ppbus as a child of this isa to parallel bridge */
- ppbus = device_add_child(dev, "ppbus", -1);
-
- /*
- * Probe the ppbus and attach devices found.
- */
- device_probe_and_attach(ppbus);
-
- /* register the ppc interrupt handler as default */
- if (ppc->res_irq) {
- /* default to the tty mask for registration */ /* XXX */
- if (BUS_SETUP_INTR(parent, dev, ppc->res_irq, INTR_TYPE_TTY,
- ppcintr, dev, &ppc->intr_cookie) == 0) {
-
- /* remember the ppcintr is registered */
- ppc->ppc_registered = 1;
- }
- }
-
- return (0);
-}
-
-static u_char
-ppc_io(device_t ppcdev, int iop, u_char *addr, int cnt, u_char byte)
-{
- struct ppc_data *ppc = DEVTOSOFTC(ppcdev);
- switch (iop) {
- case PPB_OUTSB_EPP:
- bus_space_write_multi_1(ppc->bst, ppc->bsh, PPC_EPP_DATA, addr, cnt);
- break;
- case PPB_OUTSW_EPP:
- bus_space_write_multi_2(ppc->bst, ppc->bsh, PPC_EPP_DATA, (u_int16_t *)addr, cnt);
- break;
- case PPB_OUTSL_EPP:
- bus_space_write_multi_4(ppc->bst, ppc->bsh, PPC_EPP_DATA, (u_int32_t *)addr, cnt);
- break;
- case PPB_INSB_EPP:
- bus_space_read_multi_1(ppc->bst, ppc->bsh, PPC_EPP_DATA, addr, cnt);
- break;
- case PPB_INSW_EPP:
- bus_space_read_multi_2(ppc->bst, ppc->bsh, PPC_EPP_DATA, (u_int16_t *)addr, cnt);
- break;
- case PPB_INSL_EPP:
- bus_space_read_multi_4(ppc->bst, ppc->bsh, PPC_EPP_DATA, (u_int32_t *)addr, cnt);
- break;
- case PPB_RDTR:
- return (r_dtr(ppc));
- break;
- case PPB_RSTR:
- return (r_str(ppc));
- break;
- case PPB_RCTR:
- return (r_ctr(ppc));
- break;
- case PPB_REPP_A:
- return (r_epp_A(ppc));
- break;
- case PPB_REPP_D:
- return (r_epp_D(ppc));
- break;
- case PPB_RECR:
- return (r_ecr(ppc));
- break;
- case PPB_RFIFO:
- return (r_fifo(ppc));
- break;
- case PPB_WDTR:
- w_dtr(ppc, byte);
- break;
- case PPB_WSTR:
- w_str(ppc, byte);
- break;
- case PPB_WCTR:
- w_ctr(ppc, byte);
- break;
- case PPB_WEPP_A:
- w_epp_A(ppc, byte);
- break;
- case PPB_WEPP_D:
- w_epp_D(ppc, byte);
- break;
- case PPB_WECR:
- w_ecr(ppc, byte);
- break;
- case PPB_WFIFO:
- w_fifo(ppc, byte);
- break;
- default:
- panic("%s: unknown I/O operation", __func__);
- break;
- }
-
- return (0); /* not significative */
-}
-
-static int
-ppc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
-{
- struct ppc_data *ppc = (struct ppc_data *)device_get_softc(bus);
-
- switch (index) {
- case PPC_IVAR_EPP_PROTO:
- *val = (u_long)ppc->ppc_epp;
- break;
- case PPC_IVAR_IRQ:
- *val = (u_long)ppc->ppc_irq;
- break;
- default:
- return (ENOENT);
- }
-
- return (0);
-}
-
-/*
- * Resource is useless here since ppbus devices' interrupt handlers are
- * multiplexed to the same resource initially allocated by ppc
- */
-static int
-ppc_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
- void (*ihand)(void *), void *arg, void **cookiep)
-{
- int error;
- struct ppc_data *ppc = DEVTOSOFTC(bus);
-
- if (ppc->ppc_registered) {
- /* XXX refuse registration if DMA is in progress */
-
- /* first, unregister the default interrupt handler */
- if ((error = BUS_TEARDOWN_INTR(device_get_parent(bus),
- bus, ppc->res_irq, ppc->intr_cookie)))
- return (error);
-
-/* bus_deactivate_resource(bus, SYS_RES_IRQ, ppc->rid_irq, */
-/* ppc->res_irq); */
-
- /* DMA/FIFO operation won't be possible anymore */
- ppc->ppc_registered = 0;
- }
-
- /* pass registration to the upper layer, ignore the incoming resource */
- return (BUS_SETUP_INTR(device_get_parent(bus), child,
- r, flags, ihand, arg, cookiep));
-}
-
-/*
- * When no underlying device has a registered interrupt, register the ppc
- * layer one
- */
-static int
-ppc_teardown_intr(device_t bus, device_t child, struct resource *r, void *ih)
-{
- int error;
- struct ppc_data *ppc = DEVTOSOFTC(bus);
- device_t parent = device_get_parent(bus);
-
- /* pass unregistration to the upper layer */
- if ((error = BUS_TEARDOWN_INTR(parent, child, r, ih)))
- return (error);
-
- /* default to the tty mask for registration */ /* XXX */
- if (ppc->ppc_irq &&
- !(error = BUS_SETUP_INTR(parent, bus, ppc->res_irq,
- INTR_TYPE_TTY, ppcintr, bus, &ppc->intr_cookie))) {
-
- /* remember the ppcintr is registered */
- ppc->ppc_registered = 1;
- }
-
- return (error);
-}
-
-DRIVER_MODULE(ppc, isa, ppc_driver, ppc_devclass, 0, 0);
-#ifndef PC98
-DRIVER_MODULE(ppc, acpi, ppc_driver, ppc_devclass, 0, 0);
-#endif
diff --git a/sys/pc98/cbus/ppcreg.h b/sys/pc98/cbus/ppcreg.h
deleted file mode 100644
index 2aa5ce49d89a..000000000000
--- a/sys/pc98/cbus/ppcreg.h
+++ /dev/null
@@ -1,280 +0,0 @@
-/*-
- * Copyright (c) 2001 Alcove - Nicolas Souchu
- * 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 __PPCREG_H
-#define __PPCREG_H
-
-/*
- * Parallel Port Chipset type.
- */
-#define SMC_LIKE 0
-#define SMC_37C665GT 1
-#define SMC_37C666GT 2
-#define NS_PC87332 3
-#define NS_PC87306 4
-#define INTEL_820191AA 5 /* XXX not implemented */
-#define GENERIC 6
-#define WINB_W83877F 7
-#define WINB_W83877AF 8
-#define WINB_UNKNOWN 9
-#define NS_PC87334 10
-#define SMC_37C935 11
-#define NS_PC87303 12
-
-/*
- * Parallel Port Chipset Type. SMC versus GENERIC (others)
- */
-#define PPC_TYPE_SMCLIKE 0
-#define PPC_TYPE_GENERIC 1
-
-/*
- * Generic structure to hold parallel port chipset info.
- */
-struct ppc_data {
-
- int ppc_unit;
- int ppc_model; /* chipset model if detected */
- int ppc_type; /* generic or smclike chipset type */
-
- int ppc_mode; /* chipset current mode */
- int ppc_avm; /* chipset available modes */
- int ppc_dtm; /* chipset detected modes */
-
-#define PPC_IRQ_NONE 0x0
-#define PPC_IRQ_nACK 0x1
-#define PPC_IRQ_DMA 0x2
-#define PPC_IRQ_FIFO 0x4
-#define PPC_IRQ_nFAULT 0x8
- int ppc_irqstat; /* remind irq settings */
-
-#define PPC_DMA_INIT 0x01
-#define PPC_DMA_STARTED 0x02
-#define PPC_DMA_COMPLETE 0x03
-#define PPC_DMA_INTERRUPTED 0x04
-#define PPC_DMA_ERROR 0x05
- int ppc_dmastat; /* dma state */
- int ppc_dmachan; /* dma channel */
- int ppc_dmaflags; /* dma transfer flags */
- caddr_t ppc_dmaddr; /* buffer address */
- u_int ppc_dmacnt; /* count of bytes sent with dma */
-
-#define PPC_PWORD_MASK 0x30
-#define PPC_PWORD_16 0x00
-#define PPC_PWORD_8 0x10
-#define PPC_PWORD_32 0x20
- char ppc_pword; /* PWord size */
- short ppc_fifo; /* FIFO threshold */
-
- short ppc_wthr; /* writeIntrThresold */
- short ppc_rthr; /* readIntrThresold */
-
- char *ppc_ptr; /* microseq current pointer */
- int ppc_accum; /* microseq accumulator */
- int ppc_base; /* parallel port base address */
- int ppc_epp; /* EPP mode (1.7 or 1.9) */
- int ppc_irq;
-
- unsigned char ppc_flags;
-
- device_t ppbus; /* parallel port chipset corresponding ppbus */
-
- int rid_irq, rid_drq, rid_ioport;
- struct resource *res_irq, *res_drq, *res_ioport;
-
- bus_space_handle_t bsh;
- bus_space_tag_t bst;
-
- void *intr_cookie;
-
- int ppc_registered; /* 1 if ppcintr() is the registered interrupt */
-};
-
-/*
- * Parallel Port Chipset registers.
- */
-#define PPC_SPP_DTR 0 /* SPP data register */
-#define PPC_ECP_A_FIFO 0 /* ECP Address fifo register */
-#define PPC_SPP_STR 1 /* SPP status register */
-#define PPC_SPP_CTR 2 /* SPP control register */
-#define PPC_EPP_ADDR 3 /* EPP address register (8 bit) */
-#define PPC_EPP_DATA 4 /* EPP data register (8, 16 or 32 bit) */
-#ifdef PC98
-#define PPC_1284_ENABLE 0x09 /* IEEE STD 1284 Enable register */
-#define PPC_ECP_D_FIFO 0x0c /* ECP Data fifo register */
-#define PPC_ECP_CNFGA 0x0c /* Configuration register A */
-#define PPC_ECP_CNFGB 0x0d /* Configuration register B */
-#define PPC_ECP_ECR 0x0e /* ECP extended control register */
-#else
-#define PPC_ECP_D_FIFO 0x400 /* ECP Data fifo register */
-#define PPC_ECP_CNFGA 0x400 /* Configuration register A */
-#define PPC_ECP_CNFGB 0x401 /* Configuration register B */
-#define PPC_ECP_ECR 0x402 /* ECP extended control register */
-#endif
-
-#define PPC_FIFO_EMPTY 0x1 /* ecr register - bit 0 */
-#define PPC_FIFO_FULL 0x2 /* ecr register - bit 1 */
-#define PPC_SERVICE_INTR 0x4 /* ecr register - bit 2 */
-#define PPC_ENABLE_DMA 0x8 /* ecr register - bit 3 */
-#define PPC_nFAULT_INTR 0x10 /* ecr register - bit 4 */
-#define PPC_ECR_STD 0x0
-#define PPC_ECR_PS2 0x20
-#define PPC_ECR_FIFO 0x40
-#define PPC_ECR_ECP 0x60
-#define PPC_ECR_EPP 0x80
-
-#define PPC_DISABLE_INTR (PPC_SERVICE_INTR | PPC_nFAULT_INTR)
-#define PPC_ECR_RESET (PPC_ECR_PS2 | PPC_DISABLE_INTR)
-
-#define r_dtr(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_SPP_DTR))
-#define r_str(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_SPP_STR))
-#define r_ctr(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_SPP_CTR))
-
-#define r_epp_A(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_EPP_ADDR))
-#define r_epp_D(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_EPP_DATA))
-#define r_cnfgA(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_ECP_CNFGA))
-#define r_cnfgB(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_ECP_CNFGB))
-#define r_ecr(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_ECP_ECR))
-#define r_fifo(ppc) (bus_space_read_1((ppc)->bst, (ppc)->bsh, PPC_ECP_D_FIFO))
-
-#define w_dtr(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_SPP_DTR, byte))
-#define w_str(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_SPP_STR, byte))
-#define w_ctr(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_SPP_CTR, byte))
-
-#define w_epp_A(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_EPP_ADDR, byte))
-#define w_epp_D(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_EPP_DATA, byte))
-#define w_ecr(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_ECP_ECR, byte))
-#define w_fifo(ppc, byte) (bus_space_write_1((ppc)->bst, (ppc)->bsh, PPC_ECP_D_FIFO, byte))
-
-/*
- * Register defines for the PC873xx parts
- */
-
-#define PC873_FER 0x00
-#define PC873_PPENABLE (1<<0)
-#define PC873_FAR 0x01
-#define PC873_PTR 0x02
-#define PC873_CFGLOCK (1<<6)
-#define PC873_EPPRDIR (1<<7)
-#define PC873_EXTENDED (1<<7)
-#define PC873_LPTBIRQ7 (1<<3)
-#define PC873_FCR 0x03
-#define PC873_ZWS (1<<5)
-#define PC873_ZWSPWDN (1<<6)
-#define PC873_PCR 0x04
-#define PC873_EPPEN (1<<0)
-#define PC873_EPP19 (1<<1)
-#define PC873_ECPEN (1<<2)
-#define PC873_ECPCLK (1<<3)
-#define PC873_PMC 0x06
-#define PC873_TUP 0x07
-#define PC873_SID 0x08
-#define PC873_PNP0 0x1b
-#define PC873_PNP1 0x1c
-#define PC873_LPTBA 0x19
-
-/*
- * Register defines for the SMC FDC37C66xGT parts
- */
-
-/* Init codes */
-#define SMC665_iCODE 0x55
-#define SMC666_iCODE 0x44
-
-/* Base configuration ports */
-#define SMC66x_CSR 0x3F0
-#define SMC666_CSR 0x370 /* hard-configured value for 666 */
-
-/* Bits */
-#define SMC_CR1_ADDR 0x3 /* bit 0 and 1 */
-#define SMC_CR1_MODE (1<<3) /* bit 3 */
-#define SMC_CR4_EMODE 0x3 /* bits 0 and 1 */
-#define SMC_CR4_EPPTYPE (1<<6) /* bit 6 */
-
-/* Extended modes */
-#define SMC_SPP 0x0 /* SPP */
-#define SMC_EPPSPP 0x1 /* EPP and SPP */
-#define SMC_ECP 0x2 /* ECP */
-#define SMC_ECPEPP 0x3 /* ECP and EPP */
-
-/*
- * Register defines for the SMC FDC37C935 parts
- */
-
-/* Configuration ports */
-#define SMC935_CFG 0x370
-#define SMC935_IND 0x370
-#define SMC935_DAT 0x371
-
-/* Registers */
-#define SMC935_LOGDEV 0x7
-#define SMC935_ID 0x20
-#define SMC935_PORTHI 0x60
-#define SMC935_PORTLO 0x61
-#define SMC935_PPMODE 0xf0
-
-/* Parallel port modes */
-#define SMC935_SPP 0x38 + 0
-#define SMC935_EPP19SPP 0x38 + 1
-#define SMC935_ECP 0x38 + 2
-#define SMC935_ECPEPP19 0x38 + 3
-#define SMC935_CENT 0x38 + 4
-#define SMC935_EPP17SPP 0x38 + 5
-#define SMC935_UNUSED 0x38 + 6
-#define SMC935_ECPEPP17 0x38 + 7
-
-/*
- * Register defines for the Winbond W83877F parts
- */
-
-#define WINB_W83877F_ID 0xa
-#define WINB_W83877AF_ID 0xb
-
-/* Configuration bits */
-#define WINB_HEFERE (1<<5) /* CROC bit 5 */
-#define WINB_HEFRAS (1<<0) /* CR16 bit 0 */
-
-#define WINB_PNPCVS (1<<2) /* CR16 bit 2 */
-#define WINB_CHIPID 0xf /* CR9 bits 0-3 */
-
-#define WINB_PRTMODS0 (1<<2) /* CR0 bit 2 */
-#define WINB_PRTMODS1 (1<<3) /* CR0 bit 3 */
-#define WINB_PRTMODS2 (1<<7) /* CR9 bit 7 */
-
-/* W83877F modes: CR9/bit7 | CR0/bit3 | CR0/bit2 */
-#define WINB_W83757 0x0
-#define WINB_EXTFDC 0x4
-#define WINB_EXTADP 0x8
-#define WINB_EXT2FDD 0xc
-#define WINB_JOYSTICK 0x80
-
-#define WINB_PARALLEL 0x80
-#define WINB_EPP_SPP 0x4
-#define WINB_ECP 0x8
-#define WINB_ECP_EPP 0xc
-
-#endif
diff --git a/sys/pc98/cbus/sc_machdep.h b/sys/pc98/cbus/sc_machdep.h
deleted file mode 100644
index ea7b3ba7069a..000000000000
--- a/sys/pc98/cbus/sc_machdep.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * Copyright (c) 1999 FreeBSD(98) Porting Team.
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must 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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (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 _PC98_PC98_SC_MACHDEP_H_
-#define _PC98_PC98_SC_MACHDEP_H_
-
-#undef SC_DFLT_FONT
-#undef SC_MOUSE_CHAR
-#undef SC_PIXEL_MODE
-#undef SC_NO_FONT_LOADING
-#define SC_NO_FONT_LOADING 1
-#undef SC_NO_PALETTE_LOADING
-#define SC_NO_PALETTE_LOADING 1
-
-#ifndef SC_KERNEL_CONS_ATTR
-#define SC_KERNEL_CONS_ATTR (FG_LIGHTGREY | BG_BLACK)
-#endif
-
-#define KANJI 1
-
-#define BELL_DURATION 5
-#define BELL_PITCH_8M 1339
-#define BELL_PITCH_5M 1678
-
-#define UJIS 0
-#define SJIS 1
-
-#define PRINTABLE(c) ((c) > 0x1b || ((c) > 0x0f && (c) < 0x1b) \
- || (c) < 0x07)
-
-#endif /* !_PC98_PC98_SC_MACHDEP_H_ */
diff --git a/sys/pc98/cbus/scgdcrndr.c b/sys/pc98/cbus/scgdcrndr.c
deleted file mode 100644
index 292aba7d7de7..000000000000
--- a/sys/pc98/cbus/scgdcrndr.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/*-
- * Copyright (c) 1999 FreeBSD(98) Porting Team.
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must 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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (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$
- */
-
-#include "opt_syscons.h"
-#include "opt_gdc.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/fbio.h>
-#include <sys/consio.h>
-
-#include <dev/fb/fbreg.h>
-#include <dev/syscons/syscons.h>
-
-#ifndef SC_RENDER_DEBUG
-#define SC_RENDER_DEBUG 0
-#endif
-
-static vr_clear_t gdc_txtclear;
-static vr_draw_border_t gdc_txtborder;
-static vr_draw_t gdc_txtdraw;
-static vr_set_cursor_t gdc_txtcursor_shape;
-static vr_draw_cursor_t gdc_txtcursor;
-#ifndef SC_NO_CUTPASTE
-static vr_draw_mouse_t gdc_txtmouse;
-#else
-#define gdc_txtmouse (vr_draw_mouse_t *)gdc_nop
-#endif
-
-#ifndef SC_NO_MODE_CHANGE
-static vr_draw_border_t gdc_grborder;
-#endif
-
-static void gdc_nop(scr_stat *scp, ...);
-
-static sc_rndr_sw_t txtrndrsw = {
- gdc_txtclear,
- gdc_txtborder,
- gdc_txtdraw,
- gdc_txtcursor_shape,
- gdc_txtcursor,
- (vr_blink_cursor_t *)gdc_nop,
- (vr_set_mouse_t *)gdc_nop,
- gdc_txtmouse,
-};
-RENDERER(gdc, 0, txtrndrsw, gdc_set);
-
-#ifndef SC_NO_MODE_CHANGE
-static sc_rndr_sw_t grrndrsw = {
- (vr_clear_t *)gdc_nop,
- gdc_grborder,
- (vr_draw_t *)gdc_nop,
- (vr_set_cursor_t *)gdc_nop,
- (vr_draw_cursor_t *)gdc_nop,
- (vr_blink_cursor_t *)gdc_nop,
- (vr_set_mouse_t *)gdc_nop,
- (vr_draw_mouse_t *)gdc_nop,
-};
-RENDERER(gdc, GRAPHICS_MODE, grrndrsw, gdc_set);
-#endif /* SC_NO_MODE_CHANGE */
-
-RENDERER_MODULE(gdc, gdc_set);
-
-static void
-gdc_nop(scr_stat *scp, ...)
-{
-}
-
-/* text mode renderer */
-
-static void
-gdc_txtclear(scr_stat *scp, int c, int attr)
-{
- sc_vtb_clear(&scp->scr, c, attr);
-}
-
-static void
-gdc_txtborder(scr_stat *scp, int color)
-{
- (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
-}
-
-static void
-gdc_txtdraw(scr_stat *scp, int from, int count, int flip)
-{
- vm_offset_t p;
- int c;
- int a;
-
- if (from + count > scp->xsize*scp->ysize)
- count = scp->xsize*scp->ysize - from;
-
- if (flip) {
- for (p = sc_vtb_pointer(&scp->scr, from); count-- > 0; ++from) {
- c = sc_vtb_getc(&scp->vtb, from);
- a = sc_vtb_geta(&scp->vtb, from);
-#if 0
- a ^= 0x0800;
-#else
- a = (a & 0x8800) | ((a & 0x7000) >> 4)
- | ((a & 0x0700) << 4);
-#endif
- p = sc_vtb_putchar(&scp->scr, p, c, a);
- }
- } else {
- sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
- }
-}
-
-static void
-gdc_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
-{
- if (base < 0 || base >= scp->font_size)
- return;
- /* the caller may set height <= 0 in order to disable the cursor */
- (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
- base, height,
- scp->font_size, blink);
-}
-
-static void
-gdc_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
-{
- if (on) {
- scp->status |= VR_CURSOR_ON;
- (*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp,
- at%scp->xsize, at/scp->xsize);
- } else {
- if (scp->status & VR_CURSOR_ON)
- (*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp,
- -1, -1);
- scp->status &= ~VR_CURSOR_ON;
- }
-}
-
-#ifndef SC_NO_CUTPASTE
-
-static void
-draw_txtmouse(scr_stat *scp, int x, int y)
-{
- int at;
- int a;
-
- at = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
- a = sc_vtb_geta(&scp->vtb, at);
-#if 0
- a ^= 0x0800;
-#else
- a = (a & 0x8800) | ((a & 0x7000) >> 4)
- | ((a & 0x0700) << 4);
-#endif
- sc_vtb_putc(&scp->scr, at, sc_vtb_getc(&scp->scr, at), a);
-}
-
-static void
-remove_txtmouse(scr_stat *scp, int x, int y)
-{
-}
-
-static void
-gdc_txtmouse(scr_stat *scp, int x, int y, int on)
-{
- if (on)
- draw_txtmouse(scp, x, y);
- else
- remove_txtmouse(scp, x, y);
-}
-
-#endif /* SC_NO_CUTPASTE */
-
-#ifndef SC_NO_MODE_CHANGE
-
-/* graphics mode renderer */
-
-static void
-gdc_grborder(scr_stat *scp, int color)
-{
- (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
-}
-
-#endif /* SC_NO_MODE_CHANGE */
diff --git a/sys/pc98/cbus/scterm-sck.c b/sys/pc98/cbus/scterm-sck.c
deleted file mode 100644
index 63a08aa26ee7..000000000000
--- a/sys/pc98/cbus/scterm-sck.c
+++ /dev/null
@@ -1,1217 +0,0 @@
-/*-
- * Copyright (c) 1999 FreeBSD(98) Porting Team.
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must 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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (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$
- */
-
-#include "opt_syscons.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/consio.h>
-
-#include <machine/pc/display.h>
-
-#include <dev/syscons/syscons.h>
-#include <dev/syscons/sctermvar.h>
-
-#ifndef SC_DUMB_TERMINAL
-
-#define MAX_ESC_PAR 5
-
-#ifdef KANJI
-#define IS_KTYPE_ASCII_or_HANKAKU(A) (!((A) & 0xee))
-#define IS_KTYPE_KANA(A) ((A) & 0x11)
-#define KTYPE_MASK_CTRL(A) ((A) &= 0xF0)
-#endif /* KANJI */
-
-/* attribute flags */
-typedef struct {
- u_short fg; /* foreground color */
- u_short bg; /* background color */
-} color_t;
-
-typedef struct {
- int flags;
-#define SCTERM_BUSY (1 << 0)
- int esc;
- int num_param;
- int last_param;
- int param[MAX_ESC_PAR];
- int saved_xpos;
- int saved_ypos;
-
-#ifdef KANJI
- u_char kanji_1st_char;
- u_char kanji_type;
-#define KTYPE_ASCII 0 /* ASCII */
-#define KTYPE_KANA 1 /* HANKAKU */
-#define KTYPE_JKANA 0x10 /* JIS HANKAKU */
-#define KTYPE_7JIS 0x20 /* JIS */
-#define KTYPE_SJIS 2 /* Shift JIS */
-#define KTYPE_UJIS 4 /* UJIS */
-#define KTYPE_SUKANA 3 /* Shift JIS or UJIS HANKAKU */
-#define KTYPE_SUJIS 6 /* SHift JIS or UJIS */
-#define KTYPE_KANIN 0x80 /* Kanji Invoke sequence */
-#define KTYPE_ASCIN 0x40 /* ASCII Invoke sequence */
-#endif /* KANJI */
-
- int attr_mask; /* current logical attr mask */
-#define NORMAL_ATTR 0x00
-#define BLINK_ATTR 0x01
-#define BOLD_ATTR 0x02
-#define UNDERLINE_ATTR 0x04
-#define REVERSE_ATTR 0x08
-#define FG_CHANGED 0x10
-#define BG_CHANGED 0x20
- int cur_attr; /* current hardware attr word */
- color_t cur_color; /* current hardware color */
- color_t std_color; /* normal hardware color */
- color_t rev_color; /* reverse hardware color */
- color_t dflt_std_color; /* default normal color */
- color_t dflt_rev_color; /* default reverse color */
-} term_stat;
-
-static sc_term_init_t scterm_init;
-static sc_term_term_t scterm_term;
-static sc_term_puts_t scterm_puts;
-static sc_term_ioctl_t scterm_ioctl;
-static sc_term_reset_t scterm_reset;
-static sc_term_default_attr_t scterm_default_attr;
-static sc_term_clear_t scterm_clear;
-static sc_term_notify_t scterm_notify;
-static sc_term_input_t scterm_input;
-
-static sc_term_sw_t sc_term_sc = {
- { NULL, NULL },
- "sck", /* emulator name */
- "syscons kanji terminal", /* description */
- "*", /* matching renderer, any :-) */
- sizeof(term_stat), /* softc size */
- 0,
- scterm_init,
- scterm_term,
- scterm_puts,
- scterm_ioctl,
- scterm_reset,
- scterm_default_attr,
- scterm_clear,
- scterm_notify,
- scterm_input,
-};
-
-SCTERM_MODULE(sc, sc_term_sc);
-
-static term_stat reserved_term_stat;
-static int default_kanji = UJIS;
-static void scterm_scan_esc(scr_stat *scp, term_stat *tcp,
- u_char c);
-static int mask2attr(term_stat *tcp);
-
-#ifdef KANJI
-__inline static u_char
-iskanji1(u_char mode, u_char c)
-{
- if (c > 0x80) {
- if ((c >= 0xa1) && (c <= 0xdf)) {
- if (default_kanji == UJIS) {
- /* UJIS */
- return KTYPE_UJIS;
- }
- if (default_kanji == SJIS) {
- /* SJIS HANKAKU */
- return KTYPE_KANA;
- }
- }
-
- if (c <= 0x9f) {
- if (c == 0x8e) {
- /* SJIS or UJIS HANKAKU */
- return KTYPE_SUKANA;
- }
-
- /* SJIS */
- default_kanji = SJIS;
- return KTYPE_SJIS;
- }
-
- if ((c >= 0xe0) && (c <= 0xef)) {
- /* SJIS or UJIS */
- return KTYPE_SUJIS;
- }
-
- if ((c >= 0xf0) && (c <= 0xfe)) {
- /* UJIS */
- default_kanji = UJIS;
- return KTYPE_UJIS;
- }
- } else {
- if ((mode == KTYPE_7JIS) && (c >= 0x21) && (c <= 0x7e)) {
- /* JIS */
- default_kanji = UJIS;
- return KTYPE_7JIS;
- }
-
- if ((mode == KTYPE_JKANA) && (c >= 0x21) && (c <= 0x5f)) {
- /* JIS HANKAKU */
- default_kanji = UJIS;
- return KTYPE_JKANA;
- }
- }
-
- return KTYPE_ASCII;
-}
-
-__inline static u_char
-iskanji2(u_char mode, u_char c)
-{
- switch (mode) {
- case KTYPE_7JIS:
- if ((c >= 0x21) && (c <= 0x7e)) {
- /* JIS */
- return KTYPE_7JIS;
- }
- break;
- case KTYPE_SJIS:
- if ((c >= 0x40) && (c <= 0xfc) && (c != 0x7f)) {
- /* SJIS */
- return KTYPE_SJIS;
- }
- break;
- case KTYPE_UJIS:
- if ((c >= 0xa1) && (c <= 0xfe)) {
- /* UJIS */
- return KTYPE_UJIS;
- }
- break;
- case KTYPE_SUKANA:
- if ((c >= 0xa1) && (c <= 0xdf) && (default_kanji == UJIS)) {
- /* UJIS HANKAKU */
- return KTYPE_KANA;
- }
- if ((c >= 0x40) && (c <= 0xfc) && (c != 0x7f)) {
- /* SJIS */
- default_kanji = SJIS;
- return KTYPE_SJIS;
- }
- break;
- case KTYPE_SUJIS:
- if ((c >= 0x40) && (c <= 0xa0) && (c != 0x7f)) {
- /* SJIS */
- default_kanji = SJIS;
- return KTYPE_SJIS;
- }
- if ((c == 0xfd) || (c == 0xfe)) {
- /* UJIS */
- default_kanji = UJIS;
- return KTYPE_UJIS;
- }
- if ((c >= 0xa1) && (c <= 0xfc)) {
- if (default_kanji == SJIS)
- return KTYPE_SJIS;
- if (default_kanji == UJIS)
- return KTYPE_UJIS;
- }
- break;
- }
-
- return KTYPE_ASCII;
-}
-
-/*
- * JIS X0208-83 keisen conversion table
- */
-static u_short keiConv[32] = {
- 0x240c, 0x260c, 0x300c, 0x340c, 0x3c0c, 0x380c, 0x400c, 0x500c,
- 0x480c, 0x580c, 0x600c, 0x250c, 0x270c, 0x330c, 0x370c, 0x3f0c,
- 0x3b0c, 0x470c, 0x570c, 0x4f0c, 0x5f0c, 0x6f0c, 0x440c, 0x530c,
- 0x4c0c, 0x5b0c, 0x630c, 0x410c, 0x540c, 0x490c, 0x5c0c, 0x660c
-};
-
-static u_short
-kanji_convert(u_char mode, u_char h, u_char l)
-{
- u_short tmp, high, low, c;
-
- high = (u_short) h;
- low = (u_short) l;
-
- switch (mode) {
- case KTYPE_SJIS: /* SHIFT JIS */
- if (low >= 0xe0) {
- low -= 0x40;
- }
- low = (low - 0x81) * 2 + 0x21;
- if (high > 0x7f) {
- high--;
- }
- if (high > 0x9d) {
- low++;
- high -= 0x9e - 0x21;
- } else {
- high -= 0x40 - 0x21;
- }
- high &= 0x7F;
- low &= 0x7F;
- tmp = ((high << 8) | low) - 0x20;
- break;
- case KTYPE_7JIS: /* JIS */
- case KTYPE_UJIS: /* UJIS */
- high &= 0x7F;
- low &= 0x7F;
- tmp = ((high << 8) | low) - 0x20;
- break;
- default:
- tmp = 0;
- break;
- }
-
- /* keisen */
- c = ((tmp & 0xff) << 8) | (tmp >> 8);
- /* 0x2821 .. 0x2840 */
- if (0x0821 <= c && c <= 0x0840)
- tmp = keiConv[c - 0x0821];
-
- return (tmp);
-}
-#endif /* KANJI */
-
-static int
-scterm_init(scr_stat *scp, void **softc, int code)
-{
- term_stat *tcp;
-
- if (*softc == NULL) {
- if (reserved_term_stat.flags & SCTERM_BUSY)
- return EINVAL;
- *softc = &reserved_term_stat;
- }
- tcp = *softc;
-
- switch (code) {
- case SC_TE_COLD_INIT:
- bzero(tcp, sizeof(*tcp));
- tcp->flags = SCTERM_BUSY;
- tcp->esc = 0;
- tcp->saved_xpos = -1;
- tcp->saved_ypos = -1;
-#ifdef KANJI
- tcp->kanji_1st_char = 0;
- tcp->kanji_type = KTYPE_ASCII;
-#endif
- tcp->attr_mask = NORMAL_ATTR;
- /* XXX */
- tcp->dflt_std_color.fg = SC_NORM_ATTR & 0x0f;
- tcp->dflt_std_color.bg = (SC_NORM_ATTR >> 4) & 0x0f;
- tcp->dflt_rev_color.fg = SC_NORM_REV_ATTR & 0x0f;
- tcp->dflt_rev_color.bg = (SC_NORM_REV_ATTR >> 4) & 0x0f;
- tcp->std_color = tcp->dflt_std_color;
- tcp->rev_color = tcp->dflt_rev_color;
- tcp->cur_color = tcp->std_color;
- tcp->cur_attr = mask2attr(tcp);
- ++sc_term_sc.te_refcount;
- break;
-
- case SC_TE_WARM_INIT:
- tcp->esc = 0;
- tcp->saved_xpos = -1;
- tcp->saved_ypos = -1;
-#if 0
- tcp->std_color = tcp->dflt_std_color;
- tcp->rev_color = tcp->dflt_rev_color;
-#endif
- tcp->cur_color = tcp->std_color;
- tcp->cur_attr = mask2attr(tcp);
- break;
- }
-
- return 0;
-}
-
-static int
-scterm_term(scr_stat *scp, void **softc)
-{
- if (*softc == &reserved_term_stat) {
- *softc = NULL;
- bzero(&reserved_term_stat, sizeof(reserved_term_stat));
- }
- --sc_term_sc.te_refcount;
- return 0;
-}
-
-static void
-scterm_scan_esc(scr_stat *scp, term_stat *tcp, u_char c)
-{
- static u_char ansi_col[16] = {
- FG_BLACK, FG_RED, FG_GREEN, FG_BROWN,
- FG_BLUE, FG_MAGENTA, FG_CYAN, FG_LIGHTGREY,
- FG_DARKGREY, FG_LIGHTRED, FG_LIGHTGREEN, FG_YELLOW,
- FG_LIGHTBLUE, FG_LIGHTMAGENTA, FG_LIGHTCYAN, FG_WHITE
- };
- static int cattrs[] = {
- 0, /* block */
- CONS_BLINK_CURSOR, /* blinking block */
- CONS_CHAR_CURSOR, /* underline */
- CONS_CHAR_CURSOR | CONS_BLINK_CURSOR, /* blinking underline */
- CONS_RESET_CURSOR, /* reset to default */
- CONS_HIDDEN_CURSOR, /* hide cursor */
- };
- static int tcattrs[] = {
- CONS_RESET_CURSOR | CONS_LOCAL_CURSOR, /* normal */
- CONS_HIDDEN_CURSOR | CONS_LOCAL_CURSOR, /* invisible */
- CONS_BLINK_CURSOR | CONS_LOCAL_CURSOR, /* very visible */
- };
- sc_softc_t *sc;
- int v0, v1, v2;
- int i, n;
-
- i = n = 0;
- sc = scp->sc;
- if (tcp->esc == 1) { /* seen ESC */
-#ifdef KANJI
- switch (tcp->kanji_type) {
- case KTYPE_KANIN: /* Kanji Invoke sequence */
- switch (c) {
- case 'B':
- case '@':
- tcp->kanji_type = KTYPE_7JIS;
- tcp->esc = 0;
- tcp->kanji_1st_char = 0;
- return;
- default:
- tcp->kanji_type = KTYPE_ASCII;
- tcp->esc = 0;
- break;
- }
- break;
- case KTYPE_ASCIN: /* Ascii Invoke sequence */
- switch (c) {
- case 'J':
- case 'B':
- case 'H':
- tcp->kanji_type = KTYPE_ASCII;
- tcp->esc = 0;
- tcp->kanji_1st_char = 0;
- return;
- case 'I':
- tcp->kanji_type = KTYPE_JKANA;
- tcp->esc = 0;
- tcp->kanji_1st_char = 0;
- return;
- default:
- tcp->kanji_type = KTYPE_ASCII;
- tcp->esc = 0;
- break;
- }
- break;
- default:
- break;
- }
-#endif
- switch (c) {
-
- case '7': /* Save cursor position */
- tcp->saved_xpos = scp->xpos;
- tcp->saved_ypos = scp->ypos;
- break;
-
- case '8': /* Restore saved cursor position */
- if (tcp->saved_xpos >= 0 && tcp->saved_ypos >= 0)
- sc_move_cursor(scp, tcp->saved_xpos,
- tcp->saved_ypos);
- break;
-
- case '[': /* Start ESC [ sequence */
- tcp->esc = 2;
- tcp->last_param = -1;
- for (i = tcp->num_param; i < MAX_ESC_PAR; i++)
- tcp->param[i] = 1;
- tcp->num_param = 0;
- return;
-
-#ifdef KANJI
- case '$': /* Kanji Invoke sequence */
- tcp->kanji_type = KTYPE_KANIN;
- return;
-#endif
-
- case 'M': /* Move cursor up 1 line, scroll if at top */
- sc_term_up_scroll(scp, 1, sc->scr_map[0x20],
- tcp->cur_attr, 0, 0);
- break;
-#if notyet
- case 'Q':
- tcp->esc = 4;
- return;
-#endif
- case 'c': /* reset */
- tcp->attr_mask = NORMAL_ATTR;
- tcp->cur_color = tcp->std_color
- = tcp->dflt_std_color;
- tcp->rev_color = tcp->dflt_rev_color;
- tcp->cur_attr = mask2attr(tcp);
- sc_change_cursor_shape(scp,
- CONS_RESET_CURSOR | CONS_LOCAL_CURSOR, -1, -1);
- sc_clear_screen(scp);
- break;
-
- case '(': /* iso-2022: designate 94 character set to G0 */
-#ifdef KANJI
- tcp->kanji_type = KTYPE_ASCIN;
-#else
- tcp->esc = 5;
-#endif
- return;
- }
- } else if (tcp->esc == 2) { /* seen ESC [ */
- if (c >= '0' && c <= '9') {
- if (tcp->num_param < MAX_ESC_PAR) {
- if (tcp->last_param != tcp->num_param) {
- tcp->last_param = tcp->num_param;
- tcp->param[tcp->num_param] = 0;
- } else {
- tcp->param[tcp->num_param] *= 10;
- }
- tcp->param[tcp->num_param] += c - '0';
- return;
- }
- }
- tcp->num_param = tcp->last_param + 1;
- switch (c) {
-
- case ';':
- if (tcp->num_param < MAX_ESC_PAR)
- return;
- break;
-
- case '=':
- tcp->esc = 3;
- tcp->last_param = -1;
- for (i = tcp->num_param; i < MAX_ESC_PAR; i++)
- tcp->param[i] = 1;
- tcp->num_param = 0;
- return;
-
- case 'A': /* up n rows */
- sc_term_up(scp, tcp->param[0], 0);
- break;
-
- case 'B': /* down n rows */
- sc_term_down(scp, tcp->param[0], 0);
- break;
-
- case 'C': /* right n columns */
- sc_term_right(scp, tcp->param[0]);
- break;
-
- case 'D': /* left n columns */
- sc_term_left(scp, tcp->param[0]);
- break;
-
- case 'E': /* cursor to start of line n lines down */
- n = tcp->param[0];
- if (n < 1)
- n = 1;
- sc_move_cursor(scp, 0, scp->ypos + n);
- break;
-
- case 'F': /* cursor to start of line n lines up */
- n = tcp->param[0];
- if (n < 1)
- n = 1;
- sc_move_cursor(scp, 0, scp->ypos - n);
- break;
-
- case 'f': /* Cursor move */
- case 'H':
- if (tcp->num_param == 0)
- sc_move_cursor(scp, 0, 0);
- else if (tcp->num_param == 2)
- sc_move_cursor(scp, tcp->param[1] - 1,
- tcp->param[0] - 1);
- break;
-
- case 'J': /* Clear all or part of display */
- if (tcp->num_param == 0)
- n = 0;
- else
- n = tcp->param[0];
- sc_term_clr_eos(scp, n, sc->scr_map[0x20],
- tcp->cur_attr);
- break;
-
- case 'K': /* Clear all or part of line */
- if (tcp->num_param == 0)
- n = 0;
- else
- n = tcp->param[0];
- sc_term_clr_eol(scp, n, sc->scr_map[0x20],
- tcp->cur_attr);
- break;
-
- case 'L': /* Insert n lines */
- sc_term_ins_line(scp, scp->ypos, tcp->param[0],
- sc->scr_map[0x20], tcp->cur_attr, 0);
- break;
-
- case 'M': /* Delete n lines */
- sc_term_del_line(scp, scp->ypos, tcp->param[0],
- sc->scr_map[0x20], tcp->cur_attr, 0);
- break;
-
- case 'P': /* Delete n chars */
- sc_term_del_char(scp, tcp->param[0],
- sc->scr_map[0x20], tcp->cur_attr);
- break;
-
- case '@': /* Insert n chars */
- sc_term_ins_char(scp, tcp->param[0],
- sc->scr_map[0x20], tcp->cur_attr);
- break;
-
- case 'S': /* scroll up n lines */
- sc_term_del_line(scp, 0, tcp->param[0],
- sc->scr_map[0x20], tcp->cur_attr, 0);
- break;
-
- case 'T': /* scroll down n lines */
- sc_term_ins_line(scp, 0, tcp->param[0],
- sc->scr_map[0x20], tcp->cur_attr, 0);
- break;
-
- case 'X': /* erase n characters in line */
- n = tcp->param[0];
- if (n < 1)
- n = 1;
- if (n > scp->xsize - scp->xpos)
- n = scp->xsize - scp->xpos;
- sc_vtb_erase(&scp->vtb, scp->cursor_pos, n,
- sc->scr_map[0x20], tcp->cur_attr);
- mark_for_update(scp, scp->cursor_pos);
- mark_for_update(scp, scp->cursor_pos + n - 1);
- break;
-
- case 'Z': /* move n tabs backwards */
- sc_term_backtab(scp, tcp->param[0]);
- break;
-
- case '`': /* move cursor to column n */
- sc_term_col(scp, tcp->param[0]);
- break;
-
- case 'a': /* move cursor n columns to the right */
- sc_term_right(scp, tcp->param[0]);
- break;
-
- case 'd': /* move cursor to row n */
- sc_term_row(scp, tcp->param[0]);
- break;
-
- case 'e': /* move cursor n rows down */
- sc_term_down(scp, tcp->param[0], 0);
- break;
-
- case 'm': /* change attribute */
- if (tcp->num_param == 0) {
- tcp->attr_mask = NORMAL_ATTR;
- tcp->cur_color = tcp->std_color;
- tcp->cur_attr = mask2attr(tcp);
- break;
- }
- for (i = 0; i < tcp->num_param; i++) {
- switch (n = tcp->param[i]) {
- case 0: /* back to normal */
- tcp->attr_mask = NORMAL_ATTR;
- tcp->cur_color = tcp->std_color;
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 1: /* bold */
- tcp->attr_mask |= BOLD_ATTR;
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 4: /* underline */
- tcp->attr_mask |= UNDERLINE_ATTR;
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 5: /* blink */
- tcp->attr_mask |= BLINK_ATTR;
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 7: /* reverse */
- tcp->attr_mask |= REVERSE_ATTR;
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 22: /* remove bold (or dim) */
- tcp->attr_mask &= ~BOLD_ATTR;
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 24: /* remove underline */
- tcp->attr_mask &= ~UNDERLINE_ATTR;
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 25: /* remove blink */
- tcp->attr_mask &= ~BLINK_ATTR;
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 27: /* remove reverse */
- tcp->attr_mask &= ~REVERSE_ATTR;
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 30: case 31: /* set ansi fg color */
- case 32: case 33: case 34:
- case 35: case 36: case 37:
- tcp->attr_mask |= FG_CHANGED;
- tcp->cur_color.fg = ansi_col[n - 30];
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 39: /* restore fg color back to normal */
- tcp->attr_mask &= ~(FG_CHANGED|BOLD_ATTR);
- tcp->cur_color.fg = tcp->std_color.fg;
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 40: case 41: /* set ansi bg color */
- case 42: case 43: case 44:
- case 45: case 46: case 47:
- tcp->attr_mask |= BG_CHANGED;
- tcp->cur_color.bg = ansi_col[n - 40];
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 49: /* restore bg color back to normal */
- tcp->attr_mask &= ~BG_CHANGED;
- tcp->cur_color.bg = tcp->std_color.bg;
- tcp->cur_attr = mask2attr(tcp);
- break;
- }
- }
- break;
-
- case 's': /* Save cursor position */
- tcp->saved_xpos = scp->xpos;
- tcp->saved_ypos = scp->ypos;
- break;
-
- case 'u': /* Restore saved cursor position */
- if (tcp->saved_xpos >= 0 && tcp->saved_ypos >= 0)
- sc_move_cursor(scp, tcp->saved_xpos,
- tcp->saved_ypos);
- break;
-
- case 'x':
- if (tcp->num_param == 0)
- n = 0;
- else
- n = tcp->param[0];
- switch (n) {
- case 0: /* reset colors and attributes back to normal */
- tcp->attr_mask = NORMAL_ATTR;
- tcp->cur_color = tcp->std_color
- = tcp->dflt_std_color;
- tcp->rev_color = tcp->dflt_rev_color;
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 1: /* set ansi background */
- tcp->attr_mask &= ~BG_CHANGED;
- tcp->cur_color.bg = tcp->std_color.bg
- = ansi_col[tcp->param[1] & 0x0f];
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 2: /* set ansi foreground */
- tcp->attr_mask &= ~FG_CHANGED;
- tcp->cur_color.fg = tcp->std_color.fg
- = ansi_col[tcp->param[1] & 0x0f];
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 3: /* set adapter attribute directly */
- tcp->attr_mask &= ~(FG_CHANGED | BG_CHANGED);
- tcp->cur_color.fg = tcp->std_color.fg
- = tcp->param[1] & 0x0f;
- tcp->cur_color.bg = tcp->std_color.bg
- = (tcp->param[1] >> 4) & 0x0f;
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 5: /* set ansi reverse background */
- tcp->rev_color.bg = ansi_col[tcp->param[1] & 0x0f];
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 6: /* set ansi reverse foreground */
- tcp->rev_color.fg = ansi_col[tcp->param[1] & 0x0f];
- tcp->cur_attr = mask2attr(tcp);
- break;
- case 7: /* set adapter reverse attribute directly */
- tcp->rev_color.fg = tcp->param[1] & 0x0f;
- tcp->rev_color.bg = (tcp->param[1] >> 4) & 0x0f;
- tcp->cur_attr = mask2attr(tcp);
- break;
- }
- break;
-
- case 'z': /* switch to (virtual) console n */
- if (tcp->num_param == 1)
- sc_switch_scr(sc, tcp->param[0]);
- break;
- }
- } else if (tcp->esc == 3) { /* seen ESC [0-9]+ = */
- if (c >= '0' && c <= '9') {
- if (tcp->num_param < MAX_ESC_PAR) {
- if (tcp->last_param != tcp->num_param) {
- tcp->last_param = tcp->num_param;
- tcp->param[tcp->num_param] = 0;
- } else {
- tcp->param[tcp->num_param] *= 10;
- }
- tcp->param[tcp->num_param] += c - '0';
- return;
- }
- }
- tcp->num_param = tcp->last_param + 1;
- switch (c) {
-
- case ';':
- if (tcp->num_param < MAX_ESC_PAR)
- return;
- break;
-
- case 'A': /* set display border color */
- if (tcp->num_param == 1) {
- scp->border=tcp->param[0] & 0xff;
- if (scp == sc->cur_scp)
- sc_set_border(scp, scp->border);
- }
- break;
-
- case 'B': /* set bell pitch and duration */
- if (tcp->num_param == 2) {
- scp->bell_pitch = tcp->param[0];
- scp->bell_duration =
- (tcp->param[1] * hz + 99) / 100;
- }
- break;
-
- case 'C': /* set global/parmanent cursor type & shape */
- i = spltty();
- n = tcp->num_param;
- v0 = tcp->param[0];
- v1 = tcp->param[1];
- v2 = tcp->param[2];
- switch (n) {
- case 1: /* flags only */
- if (v0 < sizeof(cattrs)/sizeof(cattrs[0]))
- v0 = cattrs[v0];
- else /* backward compatibility */
- v0 = cattrs[v0 & 0x3];
- sc_change_cursor_shape(scp, v0, -1, -1);
- break;
- case 2:
- v2 = 0;
- v0 &= 0x1f; /* backward compatibility */
- v1 &= 0x1f;
- /* FALL THROUGH */
- case 3: /* base and height */
- if (v2 == 0) /* count from top */
- sc_change_cursor_shape(scp, -1,
- scp->font_size - v1 - 1,
- v1 - v0 + 1);
- else if (v2 == 1) /* count from bottom */
- sc_change_cursor_shape(scp, -1,
- v0, v1 - v0 + 1);
- break;
- }
- splx(i);
- break;
-
- case 'F': /* set adapter foreground */
- if (tcp->num_param == 1) {
- tcp->attr_mask &= ~FG_CHANGED;
- tcp->cur_color.fg = tcp->std_color.fg
- = tcp->param[0] & 0x0f;
- tcp->cur_attr = mask2attr(tcp);
- }
- break;
-
- case 'G': /* set adapter background */
- if (tcp->num_param == 1) {
- tcp->attr_mask &= ~BG_CHANGED;
- tcp->cur_color.bg = tcp->std_color.bg
- = tcp->param[0] & 0x0f;
- tcp->cur_attr = mask2attr(tcp);
- }
- break;
-
- case 'H': /* set adapter reverse foreground */
- if (tcp->num_param == 1) {
- tcp->rev_color.fg = tcp->param[0] & 0x0f;
- tcp->cur_attr = mask2attr(tcp);
- }
- break;
-
- case 'I': /* set adapter reverse background */
- if (tcp->num_param == 1) {
- tcp->rev_color.bg = tcp->param[0] & 0x0f;
- tcp->cur_attr = mask2attr(tcp);
- }
- break;
-
- case 'S': /* set local/temporary cursor type & shape */
- i = spltty();
- n = tcp->num_param;
- v0 = tcp->param[0];
- switch (n) {
- case 0:
- v0 = 0;
- /* FALL THROUGH */
- case 1:
- if (v0 < sizeof(tcattrs)/sizeof(tcattrs[0]))
- sc_change_cursor_shape(scp,
- tcattrs[v0], -1, -1);
- break;
- }
- splx(i);
- break;
- }
-#if notyet
- } else if (tcp->esc == 4) { /* seen ESC Q */
- /* to be filled */
-#endif
- } else if (tcp->esc == 5) { /* seen ESC ( */
- switch (c) {
- case 'B': /* iso-2022: desginate ASCII into G0 */
- break;
- /* other items to be filled */
- default:
- break;
- }
- }
- tcp->esc = 0;
-}
-
-static void
-scterm_puts(scr_stat *scp, u_char *buf, int len)
-{
- term_stat *tcp;
- u_char *ptr;
-#ifdef KANJI
- u_short kanji_code;
-#endif
-
- tcp = scp->ts;
- ptr = buf;
-outloop:
- scp->sc->write_in_progress++;
-
- if (tcp->esc) {
- scterm_scan_esc(scp, tcp, *ptr++);
- len--;
- } else if (PRINTABLE(*ptr)) { /* Print only printables */
- vm_offset_t p;
- u_char *map;
- int attr;
- int i;
- int cnt;
-#ifdef KANJI
- u_char c;
-#endif
-
- p = sc_vtb_pointer(&scp->vtb, scp->cursor_pos);
- map = scp->sc->scr_map;
- attr = tcp->cur_attr;
-
-#ifdef KANJI
- c = *ptr;
- if (tcp->kanji_1st_char == 0) {
- tcp->kanji_type = iskanji1(tcp->kanji_type, c);
- if (!IS_KTYPE_ASCII_or_HANKAKU(tcp->kanji_type)) {
- /* not Ascii & not HANKAKU */
- tcp->kanji_1st_char = c;
- goto kanji_end;
- } else if (tcp->kanji_type == KTYPE_ASCII) {
- cnt = imin(len, scp->xsize - scp->xpos);
- i = cnt;
- do {
- p = sc_vtb_putchar(&scp->vtb, p, map[c], attr);
- c = *++ptr;
- --i;
- } while (i > 0 && PRINTABLE(c) &&
- iskanji1(tcp->kanji_type, c) == KTYPE_ASCII);
-
- len -= cnt - i;
- mark_for_update(scp, scp->cursor_pos);
- scp->cursor_pos += cnt - i;
- mark_for_update(scp, scp->cursor_pos - 1);
- scp->xpos += cnt - i;
- KTYPE_MASK_CTRL(tcp->kanji_type);
- goto ascii_end;
- }
- } else {
- if ((tcp->kanji_type =
- iskanji2(tcp->kanji_type, c)) & 0xee) {
- /* print kanji on TEXT VRAM */
- kanji_code = kanji_convert(tcp->kanji_type, c,
- tcp->kanji_1st_char);
- mark_for_update(scp, scp->cursor_pos);
- for (i = 0; i < 2; i++) {
- /* *cursor_pos = (kanji_code | (i*0x80)); */
- p = sc_vtb_putchar(&scp->vtb, p,
- kanji_code | ((i == 0) ? 0x00 : 0x80), attr);
- ++scp->cursor_pos;
- if (++scp->xpos >= scp->xsize) {
- scp->xpos = 0;
- scp->ypos++;
- }
- }
- mark_for_update(scp, scp->cursor_pos - 1);
- KTYPE_MASK_CTRL(tcp->kanji_type);
- tcp->kanji_1st_char = 0;
- goto kanji_end;
- } else {
- tcp->kanji_1st_char = 0;
- }
- }
- if (IS_KTYPE_KANA(tcp->kanji_type))
- c |= 0x80;
- KTYPE_MASK_CTRL(tcp->kanji_type);
- sc_vtb_putchar(&scp->vtb, p, map[c], attr);
- mark_for_update(scp, scp->cursor_pos);
- mark_for_update(scp, scp->cursor_pos);
- ++scp->cursor_pos;
- ++scp->xpos;
-kanji_end:
- ++ptr;
- --len;
-ascii_end:
-#else /* !KANJI */
- cnt = imin(len, scp->xsize - scp->xpos);
- i = cnt;
- do {
- /*
- * gcc-2.6.3 generates poor (un)sign extension code.
- * Casting the pointers in the following to volatile should
- * have no effect, but in fact speeds up this inner loop
- * from 26 to 18 cycles (+ cache misses) on i486's.
- */
-#define UCVP(ucp) ((u_char volatile *)(ucp))
- p = sc_vtb_putchar(&scp->vtb, p, UCVP(map)[*UCVP(ptr)],
- attr);
- ++ptr;
- --i;
- } while (i > 0 && PRINTABLE(*ptr));
-
- len -= cnt - i;
- mark_for_update(scp, scp->cursor_pos);
- scp->cursor_pos += cnt - i;
- mark_for_update(scp, scp->cursor_pos - 1);
- scp->xpos += cnt - i;
-#endif /* !KANJI */
-
- if (scp->xpos >= scp->xsize) {
- scp->xpos = 0;
- scp->ypos++;
- }
- } else {
- switch (*ptr) {
- case 0x07:
- sc_bell(scp, scp->bell_pitch, scp->bell_duration);
- break;
-
- case 0x08: /* non-destructive backspace */
- if (scp->cursor_pos > 0) {
- mark_for_update(scp, scp->cursor_pos);
- scp->cursor_pos--;
- mark_for_update(scp, scp->cursor_pos);
- if (scp->xpos > 0)
- scp->xpos--;
- else {
- scp->xpos += scp->xsize - 1;
- scp->ypos--;
- }
- }
- break;
-
- case 0x09: /* non-destructive tab */
- mark_for_update(scp, scp->cursor_pos);
- scp->cursor_pos += (8 - scp->xpos % 8u);
- scp->xpos += (8 - scp->xpos % 8u);
- if (scp->xpos >= scp->xsize) {
- scp->xpos = 0;
- scp->ypos++;
- scp->cursor_pos = scp->xsize * scp->ypos;
- }
- mark_for_update(scp, scp->cursor_pos);
- break;
-
- case 0x0a: /* newline, same pos */
- mark_for_update(scp, scp->cursor_pos);
- scp->cursor_pos += scp->xsize;
- mark_for_update(scp, scp->cursor_pos);
- scp->ypos++;
- break;
-
- case 0x0c: /* form feed, clears screen */
- sc_clear_screen(scp);
- break;
-
- case 0x0d: /* return, return to pos 0 */
- mark_for_update(scp, scp->cursor_pos);
- scp->cursor_pos -= scp->xpos;
- mark_for_update(scp, scp->cursor_pos);
- scp->xpos = 0;
- break;
-
-#ifdef PC98
- case 0x0e: /* ^N */
- tcp->kanji_type = KTYPE_JKANA;
- tcp->esc = 0;
- tcp->kanji_1st_char = 0;
- break;
-
- case 0x0f: /* ^O */
- tcp->kanji_type = KTYPE_ASCII;
- tcp->esc = 0;
- tcp->kanji_1st_char = 0;
- break;
-#endif /* PC98 */
-
- case 0x1b: /* start escape sequence */
- tcp->esc = 1;
- tcp->num_param = 0;
- break;
- }
- ptr++;
- len--;
- }
-
- sc_term_gen_scroll(scp, scp->sc->scr_map[0x20], tcp->cur_attr);
-
- scp->sc->write_in_progress--;
- if (len)
- goto outloop;
-}
-
-static int
-scterm_ioctl(scr_stat *scp, struct tty *tp, u_long cmd, caddr_t data,
- int flag, struct thread *td)
-{
- term_stat *tcp = scp->ts;
- vid_info_t *vi;
-
- switch (cmd) {
- case GIO_ATTR: /* get current attributes */
- /* FIXME: */
- *(int*)data = (tcp->cur_attr >> 8) & 0xff;
- return 0;
- case CONS_GETINFO: /* get current (virtual) console info */
- vi = (vid_info_t *)data;
- if (vi->size != sizeof(struct vid_info))
- return EINVAL;
- vi->mv_norm.fore = tcp->std_color.fg;
- vi->mv_norm.back = tcp->std_color.bg;
- vi->mv_rev.fore = tcp->rev_color.fg;
- vi->mv_rev.back = tcp->rev_color.bg;
- /*
- * The other fields are filled by the upper routine. XXX
- */
- return ENOIOCTL;
- }
- return ENOIOCTL;
-}
-
-static int
-scterm_reset(scr_stat *scp, int code)
-{
- /* FIXME */
- return 0;
-}
-
-static void
-scterm_default_attr(scr_stat *scp, int color, int rev_color)
-{
- term_stat *tcp = scp->ts;
-
- tcp->dflt_std_color.fg = color & 0x0f;
- tcp->dflt_std_color.bg = (color >> 4) & 0x0f;
- tcp->dflt_rev_color.fg = rev_color & 0x0f;
- tcp->dflt_rev_color.bg = (rev_color >> 4) & 0x0f;
- tcp->std_color = tcp->dflt_std_color;
- tcp->rev_color = tcp->dflt_rev_color;
- tcp->cur_color = tcp->std_color;
- tcp->cur_attr = mask2attr(tcp);
-}
-
-static void
-scterm_clear(scr_stat *scp)
-{
- term_stat *tcp = scp->ts;
-
- sc_move_cursor(scp, 0, 0);
- sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20], tcp->cur_attr);
- mark_all(scp);
-}
-
-static void
-scterm_notify(scr_stat *scp, int event)
-{
- switch (event) {
- case SC_TE_NOTIFY_VTSWITCH_IN:
- break;
- case SC_TE_NOTIFY_VTSWITCH_OUT:
- break;
- }
-}
-
-static int
-scterm_input(scr_stat *scp, int c, struct tty *tp)
-{
- return FALSE;
-}
-
-/*
- * Calculate hardware attributes word using logical attributes mask and
- * hardware colors
- */
-
-/* FIXME */
-static int
-mask2attr(term_stat *tcp)
-{
- int attr, mask = tcp->attr_mask;
-
- if (mask & REVERSE_ATTR) {
- attr = ((mask & FG_CHANGED) ?
- tcp->cur_color.bg : tcp->rev_color.fg) |
- (((mask & BG_CHANGED) ?
- tcp->cur_color.fg : tcp->rev_color.bg) << 4);
- } else
- attr = tcp->cur_color.fg | (tcp->cur_color.bg << 4);
-
- /* XXX: underline mapping for Hercules adapter can be better */
- if (mask & (BOLD_ATTR | UNDERLINE_ATTR))
- attr ^= 0x08;
- if (mask & BLINK_ATTR)
- attr ^= 0x80;
-
- return (attr << 8);
-}
-
-#endif /* SC_DUMB_TERMINAL */
diff --git a/sys/pc98/cbus/scvtb.c b/sys/pc98/cbus/scvtb.c
deleted file mode 100644
index 2d0ea3f03284..000000000000
--- a/sys/pc98/cbus/scvtb.c
+++ /dev/null
@@ -1,399 +0,0 @@
-/*-
- * Copyright (c) 1999 FreeBSD(98) Porting Team.
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must 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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (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$
- */
-
-#include "opt_syscons.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/consio.h>
-#include <sys/fbio.h>
-
-#include <machine/md_var.h>
-
-#include <dev/fb/fbreg.h>
-#include <dev/syscons/syscons.h>
-
-#define ATTR_OFFSET_FB 0x2000
-#define attr_offset(vtb) ((vtb)->vtb_size*sizeof(u_int16_t))
-
-#define vtb_pointer(vtb, at) \
- ((vtb)->vtb_buffer + sizeof(u_int16_t)*(at))
-
-#define vtb_wrap(vtb, at, offset) \
- (((at) + (offset) + (vtb)->vtb_size)%(vtb)->vtb_size)
-
-static u_int8_t ibmpc_to_pc98[256] = {
- 0x01, 0x21, 0x81, 0xa1, 0x41, 0x61, 0xc1, 0xe1,
- 0x09, 0x29, 0x89, 0xa9, 0x49, 0x69, 0xc9, 0xe9,
- 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25,
- 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25,
- 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85,
- 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85,
- 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5,
- 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5,
- 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45,
- 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45,
- 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65,
- 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65,
- 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5,
- 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5,
- 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5,
- 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5,
-
- 0x03, 0x23, 0x83, 0xa3, 0x43, 0x63, 0xc3, 0xe3,
- 0x0b, 0x2b, 0x8b, 0xab, 0x4b, 0x6b, 0xcb, 0xeb,
- 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f,
- 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f,
- 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f,
- 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f,
- 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf,
- 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf,
- 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f,
- 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f,
- 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf,
- 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf,
- 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef,
- 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef,
-};
-#define at2pc98(attr) ((attr) | ibmpc_to_pc98[(unsigned)(attr) >> 8])
-
-void
-sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows, void *buf, int wait)
-{
- vtb->vtb_flags = 0;
- vtb->vtb_type = type;
- vtb->vtb_cols = cols;
- vtb->vtb_rows = rows;
- vtb->vtb_size = cols*rows;
- vtb->vtb_buffer = 0;
- vtb->vtb_tail = 0;
-
- switch (type) {
- case VTB_MEMORY:
- case VTB_RINGBUFFER:
- if ((buf == NULL) && (cols*rows != 0)) {
- vtb->vtb_buffer =
- (vm_offset_t)malloc(cols*rows*sizeof(u_int16_t)*2,
- M_DEVBUF,
- ((wait) ? M_WAITOK : M_NOWAIT) | M_ZERO);
- if (vtb->vtb_buffer != 0) {
- vtb->vtb_flags |= VTB_ALLOCED;
- }
- } else {
- vtb->vtb_buffer = (vm_offset_t)buf;
- }
- vtb->vtb_flags |= VTB_VALID;
- break;
- case VTB_FRAMEBUFFER:
- vtb->vtb_buffer = (vm_offset_t)buf;
- vtb->vtb_flags |= VTB_VALID;
- break;
- default:
- break;
- }
-}
-
-void
-sc_vtb_destroy(sc_vtb_t *vtb)
-{
- vm_offset_t p;
-
- vtb->vtb_cols = 0;
- vtb->vtb_rows = 0;
- vtb->vtb_size = 0;
- vtb->vtb_tail = 0;
-
- p = vtb->vtb_buffer;
- vtb->vtb_buffer = 0;
- switch (vtb->vtb_type) {
- case VTB_MEMORY:
- case VTB_RINGBUFFER:
- if ((vtb->vtb_flags & VTB_ALLOCED) && (p != 0))
- free((void *)p, M_DEVBUF);
- break;
- default:
- break;
- }
- vtb->vtb_flags = 0;
- vtb->vtb_type = VTB_INVALID;
-}
-
-size_t
-sc_vtb_size(int cols, int rows)
-{
- return (size_t)(cols*rows*sizeof(u_int16_t)*2);
-}
-
-int
-sc_vtb_getc(sc_vtb_t *vtb, int at)
-{
- vm_offset_t p = vtb_pointer(vtb, at);
-
- if (vtb->vtb_type == VTB_FRAMEBUFFER)
- return (readw(p) & 0x00ff);
- else
- return (*(u_int16_t *)p & 0x00ff);
-}
-
-int
-sc_vtb_geta(sc_vtb_t *vtb, int at)
-{
- vm_offset_t p = vtb_pointer(vtb, at);
-
- if (vtb->vtb_type == VTB_FRAMEBUFFER)
- return (readw(p + ATTR_OFFSET_FB) & 0xff00);
- else
- return (*(u_int16_t *)(p + attr_offset(vtb)) & 0xff00);
-}
-
-__inline static void
-vtb_putc(sc_vtb_t *vtb, vm_offset_t p, int c, int a)
-{
- if (vtb->vtb_type == VTB_FRAMEBUFFER) {
- writew(p, c);
- writew(p + ATTR_OFFSET_FB, at2pc98(a));
- } else {
- *(u_int16_t *)p = c;
- *(u_int16_t *)(p + attr_offset(vtb)) = at2pc98(a);
- }
-}
-
-void
-sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a)
-{
- vtb_putc(vtb, vtb_pointer(vtb, at), c, a);
-}
-
-vm_offset_t
-sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a)
-{
- vtb_putc(vtb, p, c, a);
- return (p + sizeof(u_int16_t));
-}
-
-vm_offset_t
-sc_vtb_pointer(sc_vtb_t *vtb, int at)
-{
- return (vtb_pointer(vtb, at));
-}
-
-int
-sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset)
-{
- return ((pos + offset + vtb->vtb_size)%vtb->vtb_size);
-}
-
-void
-sc_vtb_clear(sc_vtb_t *vtb, int c, int attr)
-{
- vm_offset_t p = vtb_pointer(vtb, 0);
-
- if (vtb->vtb_type == VTB_FRAMEBUFFER) {
- fillw_io(c, p, vtb->vtb_size);
- fillw_io(at2pc98(attr), p + ATTR_OFFSET_FB, vtb->vtb_size);
- } else {
- fillw(c, (void *)p, vtb->vtb_size);
- fillw(at2pc98(attr), (void *)(p + attr_offset(vtb)),
- vtb->vtb_size);
- }
-}
-
-void
-sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to, int count)
-{
- vm_offset_t p1, p2;
-
- p1 = vtb_pointer(vtb1, from);
- p2 = vtb_pointer(vtb2, to);
- if (vtb2->vtb_type == VTB_FRAMEBUFFER) {
- bcopy_toio(p1, p2, count*sizeof(u_int16_t));
- bcopy_toio(p1 + attr_offset(vtb1),
- p2 + ATTR_OFFSET_FB,
- count*sizeof(u_int16_t));
- } else if (vtb1->vtb_type == VTB_FRAMEBUFFER) {
- bcopy_fromio(p1, p2, count*sizeof(u_int16_t));
- bcopy_fromio(p1 + ATTR_OFFSET_FB,
- p2 + attr_offset(vtb2),
- count*sizeof(u_int16_t));
- } else {
- bcopy((void *)p1, (void *)p2, count*sizeof(u_int16_t));
- bcopy((void *)(p1 + attr_offset(vtb1)),
- (void *)(p2 + attr_offset(vtb2)),
- count*sizeof(u_int16_t));
- }
-}
-
-void
-sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int count)
-{
- int len;
- vm_offset_t p1, p2;
-
- if (vtb2->vtb_type != VTB_RINGBUFFER)
- return;
-
- while (count > 0) {
- p1 = vtb_pointer(vtb1, from);
- p2 = vtb_pointer(vtb2, vtb2->vtb_tail);
- len = imin(count, vtb2->vtb_size - vtb2->vtb_tail);
- if (vtb1->vtb_type == VTB_FRAMEBUFFER) {
- bcopy_fromio(p1, p2, len*sizeof(u_int16_t));
- bcopy_fromio(p1 + ATTR_OFFSET_FB,
- p2 + attr_offset(vtb2),
- len*sizeof(u_int16_t));
- } else {
- bcopy((void *)p1, (void *)p2, len*sizeof(u_int16_t));
- bcopy((void *)(p1 + attr_offset(vtb1)),
- (void *)(p2 + attr_offset(vtb2)),
- len*sizeof(u_int16_t));
- }
- from += len;
- count -= len;
- vtb2->vtb_tail = vtb_wrap(vtb2, vtb2->vtb_tail, len);
- }
-}
-
-void
-sc_vtb_seek(sc_vtb_t *vtb, int pos)
-{
- vtb->vtb_tail = pos%vtb->vtb_size;
-}
-
-void
-sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr)
-{
- vm_offset_t p;
-
- if (at + count > vtb->vtb_size)
- count = vtb->vtb_size - at;
- p = vtb_pointer(vtb, at);
- if (vtb->vtb_type == VTB_FRAMEBUFFER) {
- fillw_io(c, p, count);
- fillw_io(at2pc98(attr), p + ATTR_OFFSET_FB, count);
- } else {
- fillw(c, (void *)p, count);
- fillw(at2pc98(attr), (void *)(p + attr_offset(vtb)), count);
- }
-}
-
-void
-sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count)
-{
- vm_offset_t p1, p2;
-
- if (from + count > vtb->vtb_size)
- count = vtb->vtb_size - from;
- if (to + count > vtb->vtb_size)
- count = vtb->vtb_size - to;
- if (count <= 0)
- return;
-
- p1 = vtb_pointer(vtb, from);
- p2 = vtb_pointer(vtb, to);
- if (vtb->vtb_type == VTB_FRAMEBUFFER) {
- bcopy_io(p1, p2, count*sizeof(u_int16_t));
- bcopy_io(p1 + ATTR_OFFSET_FB,
- p2 + ATTR_OFFSET_FB, count*sizeof(u_int16_t));
- } else {
- bcopy((void *)p1, (void *)p2, count*sizeof(u_int16_t));
- bcopy((void *)(p1 + attr_offset(vtb)),
- (void *)(p2 + attr_offset(vtb)), count*sizeof(u_int16_t));
- }
-}
-
-void
-sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr)
-{
- int len;
- vm_offset_t p1, p2;
-
- if (at + count > vtb->vtb_size)
- count = vtb->vtb_size - at;
- len = vtb->vtb_size - at - count;
- if (len > 0) {
- p1 = vtb_pointer(vtb, at + count);
- p2 = vtb_pointer(vtb, at);
- if (vtb->vtb_type == VTB_FRAMEBUFFER) {
- bcopy_io(p1, p2, len*sizeof(u_int16_t));
- bcopy_io(p1 + ATTR_OFFSET_FB,
- p2 + ATTR_OFFSET_FB,
- len*sizeof(u_int16_t));
- } else {
- bcopy((void *)p1, (void *)p2, len*sizeof(u_int16_t));
- bcopy((void *)(p1 + attr_offset(vtb)),
- (void *)(p2 + attr_offset(vtb)),
- len*sizeof(u_int16_t));
- }
- }
- p1 = vtb_pointer(vtb, at + len);
- if (vtb->vtb_type == VTB_FRAMEBUFFER) {
- fillw_io(c, p1, vtb->vtb_size - at - len);
- fillw_io(at2pc98(attr), p1 + ATTR_OFFSET_FB,
- vtb->vtb_size - at - len);
- } else {
- fillw(c, (void *)p1, vtb->vtb_size - at - len);
- fillw(at2pc98(attr), (void *)(p1 + attr_offset(vtb)),
- vtb->vtb_size - at - len);
- }
-}
-
-void
-sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr)
-{
- vm_offset_t p1, p2;
-
- p1 = vtb_pointer(vtb, at);
- if (at + count > vtb->vtb_size) {
- count = vtb->vtb_size - at;
- } else {
- p2 = vtb_pointer(vtb, at + count);
- if (vtb->vtb_type == VTB_FRAMEBUFFER) {
- bcopy_io(p1, p2,
- (vtb->vtb_size - at - count)*sizeof(u_int16_t));
- bcopy_io(p1 + ATTR_OFFSET_FB,
- p2 + ATTR_OFFSET_FB,
- (vtb->vtb_size - at - count)*sizeof(u_int16_t));
- } else {
- bcopy((void *)p1, (void *)p2,
- (vtb->vtb_size - at - count)*sizeof(u_int16_t));
- bcopy((void *)(p1 + attr_offset(vtb)),
- (void *)(p2 + attr_offset(vtb)),
- (vtb->vtb_size - at - count)*sizeof(u_int16_t));
- }
- }
- if (vtb->vtb_type == VTB_FRAMEBUFFER) {
- fillw_io(c, p1, count);
- fillw_io(at2pc98(attr), p1 + ATTR_OFFSET_FB, count);
- } else {
- fillw(c, (void *)p1, count);
- fillw(at2pc98(attr), (void *)(p1 + attr_offset(vtb)), count);
- }
-}
diff --git a/sys/pc98/cbus/sio.c b/sys/pc98/cbus/sio.c
deleted file mode 100644
index b571fefa4d46..000000000000
--- a/sys/pc98/cbus/sio.c
+++ /dev/null
@@ -1,5114 +0,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- * from: @(#)com.c 7.5 (Berkeley) 5/16/91
- * from: i386/isa sio.c,v 1.234
- */
-
-#include "opt_comconsole.h"
-#include "opt_compat.h"
-#include "opt_ddb.h"
-#include "opt_sio.h"
-
-/*
- * Serial driver, based on 386BSD-0.1 com driver.
- * Mostly rewritten to use pseudo-DMA.
- * Works for National Semiconductor NS8250-NS16550AF UARTs.
- * COM driver, based on HP dca driver.
- *
- * Changes for PC-Card integration:
- * - Added PC-Card driver table and handlers
- */
-/*===============================================================
- * 386BSD(98),FreeBSD-1.1x(98) com driver.
- * -----
- * modified for PC9801 by M.Ishii
- * Kyoto University Microcomputer Club (KMC)
- * Chou "TEFUTEFU" Hirotomi
- * Kyoto Univ. the faculty of medicine
- *===============================================================
- * FreeBSD-2.0.1(98) sio driver.
- * -----
- * modified for pc98 Internal i8251 and MICRO CORE MC16550II
- * T.Koike(hfc01340@niftyserve.or.jp)
- * implement kernel device configuration
- * aizu@orient.center.nitech.ac.jp
- *
- * Notes.
- * -----
- * PC98 localization based on 386BSD(98) com driver. Using its PC98 local
- * functions.
- * This driver is under debugging,has bugs.
- *
- * 1) config
- * options COM_MULTIPORT #if using MC16550II
- * device sio0 at nec? port 0x30 tty irq 4 #internal
- * device sio1 at nec? port 0xd2 tty irq 5 flags 0x101 #mc1
- * device sio2 at nec? port 0x8d2 tty flags 0x101 #mc2
- * # ~~~~~iobase ~~multi port flag
- * # ~ master device is sio1
- * 2) device
- * cd /dev; MAKEDEV ttyd0 ttyd1 ..
- * 3) /etc/rc.serial
- * 57600bps is too fast for sio0(internal8251)
- * my ex.
- * #set default speed 9600
- * modem()
- * :
- * stty </dev/ttyid$i crtscts 9600
- * : # ~~~~ default speed(can change after init.)
- * modem 0 1 2
- * 4) COMCONSOLE
- * not changed.
- * 5) PC9861K,PIO9032B,B98_01
- * not tested.
- */
-/*
- * modified for AIWA B98-01
- * by T.Hatanou <hatanou@yasuda.comm.waseda.ac.jp> last update: 15 Sep.1995
- *
- * How to configure...
- * # options COM_MULTIPORT # support for MICROCORE MC16550II
- * ... comment-out this line, which will conflict with B98_01.
- * options "B98_01" # support for AIWA B98-01
- * device sio1 at nec? port 0x00d1 tty irq ?
- * device sio2 at nec? port 0x00d5 tty irq ?
- * ... you can leave these lines `irq ?', irq will be autodetected.
- */
-/*
- * Modified by Y.Takahashi of Kogakuin University.
- */
-/*
- * modified for 8251(FIFO) by Seigo TANIMURA <tanimura@FreeBSD.org>
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/conf.h>
-#include <sys/fcntl.h>
-#include <sys/interrupt.h>
-#include <sys/kernel.h>
-#include <sys/limits.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/module.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/reboot.h>
-#include <sys/sysctl.h>
-#include <sys/syslog.h>
-#include <sys/tty.h>
-#include <machine/bus.h>
-#include <sys/rman.h>
-#include <sys/timepps.h>
-#include <sys/uio.h>
-
-#include <isa/isavar.h>
-
-#include <machine/resource.h>
-
-#include <dev/sio/sioreg.h>
-#include <dev/sio/siovar.h>
-
-#ifdef PC98
-#include <pc98/pc98/pc98.h>
-#include <pc98/pc98/pc98_machdep.h>
-#endif
-
-#ifdef COM_ESP
-#include <dev/ic/esp.h>
-#endif
-#include <dev/ic/ns16550.h>
-#ifdef PC98
-#include <dev/ic/i8251.h>
-#include <dev/ic/rsa.h>
-#endif
-
-#define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */
-
-#define CALLOUT_MASK 0x80
-#define CONTROL_MASK 0x60
-#define CONTROL_INIT_STATE 0x20
-#define CONTROL_LOCK_STATE 0x40
-#define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
-#define MINOR_TO_UNIT(mynor) ((((mynor) & ~0xffffU) >> (8 + 3)) \
- | ((mynor) & 0x1f))
-#define UNIT_TO_MINOR(unit) ((((unit) & ~0x1fU) << (8 + 3)) \
- | ((unit) & 0x1f))
-
-#ifdef COM_MULTIPORT
-/* checks in flags for multiport and which is multiport "master chip"
- * for a given card
- */
-#define COM_ISMULTIPORT(flags) ((flags) & 0x01)
-#define COM_MPMASTER(flags) (((flags) >> 8) & 0x0ff)
-#define COM_NOTAST4(flags) ((flags) & 0x04)
-#else
-#define COM_ISMULTIPORT(flags) (0)
-#endif /* COM_MULTIPORT */
-
-#define COM_CONSOLE(flags) ((flags) & 0x10)
-#define COM_FORCECONSOLE(flags) ((flags) & 0x20)
-#define COM_LLCONSOLE(flags) ((flags) & 0x40)
-#define COM_DEBUGGER(flags) ((flags) & 0x80)
-#define COM_LOSESOUTINTS(flags) ((flags) & 0x08)
-#define COM_NOFIFO(flags) ((flags) & 0x02)
-#define COM_PPSCTS(flags) ((flags) & 0x10000)
-#define COM_ST16650A(flags) ((flags) & 0x20000)
-#define COM_C_NOPROBE (0x40000)
-#define COM_NOPROBE(flags) ((flags) & COM_C_NOPROBE)
-#define COM_C_IIR_TXRDYBUG (0x80000)
-#define COM_IIR_TXRDYBUG(flags) ((flags) & COM_C_IIR_TXRDYBUG)
-#define COM_NOSCR(flags) ((flags) & 0x100000)
-#define COM_FIFOSIZE(flags) (((flags) & 0xff000000) >> 24)
-
-#define sio_getreg(com, off) \
- (bus_space_read_1((com)->bst, (com)->bsh, (off)))
-#define sio_setreg(com, off, value) \
- (bus_space_write_1((com)->bst, (com)->bsh, (off), (value)))
-
-/*
- * com state bits.
- * (CS_BUSY | CS_TTGO) and (CS_BUSY | CS_TTGO | CS_ODEVREADY) must be higher
- * than the other bits so that they can be tested as a group without masking
- * off the low bits.
- *
- * The following com and tty flags correspond closely:
- * CS_BUSY = TS_BUSY (maintained by comstart(), siopoll() and
- * comstop())
- * CS_TTGO = ~TS_TTSTOP (maintained by comparam() and comstart())
- * CS_CTS_OFLOW = CCTS_OFLOW (maintained by comparam())
- * CS_RTS_IFLOW = CRTS_IFLOW (maintained by comparam())
- * TS_FLUSH is not used.
- * XXX I think TIOCSETA doesn't clear TS_TTSTOP when it clears IXON.
- * XXX CS_*FLOW should be CF_*FLOW in com->flags (control flags not state).
- */
-#define CS_BUSY 0x80 /* output in progress */
-#define CS_TTGO 0x40 /* output not stopped by XOFF */
-#define CS_ODEVREADY 0x20 /* external device h/w ready (CTS) */
-#define CS_CHECKMSR 1 /* check of MSR scheduled */
-#define CS_CTS_OFLOW 2 /* use CTS output flow control */
-#define CS_DTR_OFF 0x10 /* DTR held off */
-#define CS_ODONE 4 /* output completed */
-#define CS_RTS_IFLOW 8 /* use RTS input flow control */
-#define CSE_BUSYCHECK 1 /* siobusycheck() scheduled */
-
-static char const * const error_desc[] = {
-#define CE_OVERRUN 0
- "silo overflow",
-#define CE_INTERRUPT_BUF_OVERFLOW 1
- "interrupt-level buffer overflow",
-#define CE_TTY_BUF_OVERFLOW 2
- "tty-level buffer overflow",
-};
-
-#define CE_NTYPES 3
-#define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum])
-
-/* types. XXX - should be elsewhere */
-typedef u_int Port_t; /* hardware port */
-typedef u_char bool_t; /* boolean */
-
-/* queue of linear buffers */
-struct lbq {
- u_char *l_head; /* next char to process */
- u_char *l_tail; /* one past the last char to process */
- struct lbq *l_next; /* next in queue */
- bool_t l_queued; /* nonzero if queued */
-};
-
-/* com device structure */
-struct com_s {
- u_int flags; /* Copy isa device flags */
- u_char state; /* miscellaneous flag bits */
- bool_t active_out; /* nonzero if the callout device is open */
- u_char cfcr_image; /* copy of value written to CFCR */
-#ifdef COM_ESP
- bool_t esp; /* is this unit a hayes esp board? */
-#endif
- u_char extra_state; /* more flag bits, separate for order trick */
- u_char fifo_image; /* copy of value written to FIFO */
- bool_t hasfifo; /* nonzero for 16550 UARTs */
- bool_t st16650a; /* Is a Startech 16650A or RTS/CTS compat */
- bool_t loses_outints; /* nonzero if device loses output interrupts */
- u_char mcr_image; /* copy of value written to MCR */
-#ifdef COM_MULTIPORT
- bool_t multiport; /* is this unit part of a multiport device? */
-#endif /* COM_MULTIPORT */
- bool_t no_irq; /* nonzero if irq is not attached */
- bool_t gone; /* hardware disappeared */
- bool_t poll; /* nonzero if polling is required */
- bool_t poll_output; /* nonzero if polling for output is required */
- int unit; /* unit number */
- int dtr_wait; /* time to hold DTR down on close (* 1/hz) */
- u_int tx_fifo_size;
- u_int wopeners; /* # processes waiting for DCD in open() */
-
- /*
- * The high level of the driver never reads status registers directly
- * because there would be too many side effects to handle conveniently.
- * Instead, it reads copies of the registers stored here by the
- * interrupt handler.
- */
- u_char last_modem_status; /* last MSR read by intr handler */
- u_char prev_modem_status; /* last MSR handled by high level */
-
- u_char hotchar; /* ldisc-specific char to be handled ASAP */
- u_char *ibuf; /* start of input buffer */
- u_char *ibufend; /* end of input buffer */
- u_char *ibufold; /* old input buffer, to be freed */
- u_char *ihighwater; /* threshold in input buffer */
- u_char *iptr; /* next free spot in input buffer */
- int ibufsize; /* size of ibuf (not include error bytes) */
- int ierroff; /* offset of error bytes in ibuf */
-
- struct lbq obufq; /* head of queue of output buffers */
- struct lbq obufs[2]; /* output buffers */
-
- bus_space_tag_t bst;
- bus_space_handle_t bsh;
-
-#ifdef PC98
- Port_t cmd_port;
- Port_t sts_port;
- Port_t in_modem_port;
- Port_t intr_ctrl_port;
- Port_t rsabase; /* Iobase address of an I/O-DATA RSA board. */
- int intr_enable;
- int pc98_prev_modem_status;
- int pc98_modem_delta;
- int modem_car_chg_timer;
- int pc98_prev_siocmd;
- int pc98_prev_siomod;
- int modem_checking;
- int pc98_if_type;
-
- bool_t pc98_8251fifo;
- bool_t pc98_8251fifo_enable;
-#endif /* PC98 */
- Port_t data_port; /* i/o ports */
-#ifdef COM_ESP
- Port_t esp_port;
-#endif
- Port_t int_id_port;
- Port_t modem_ctl_port;
- Port_t line_status_port;
- Port_t modem_status_port;
- Port_t intr_ctl_port; /* Ports of IIR register */
-
- struct tty *tp; /* cross reference */
-
- /* Initial state. */
- struct termios it_in; /* should be in struct tty */
- struct termios it_out;
-
- /* Lock state. */
- struct termios lt_in; /* should be in struct tty */
- struct termios lt_out;
-
- bool_t do_timestamp;
- bool_t do_dcd_timestamp;
- struct timeval timestamp;
- struct timeval dcd_timestamp;
- struct pps_state pps;
- int pps_bit;
-
- u_long bytes_in; /* statistics */
- u_long bytes_out;
- u_int delta_error_counts[CE_NTYPES];
- u_long error_counts[CE_NTYPES];
-
- u_long rclk;
-
- struct resource *irqres;
- struct resource *ioportres;
- void *cookie;
- dev_t devs[6];
-
- /*
- * Data area for output buffers. Someday we should build the output
- * buffer queue without copying data.
- */
-#ifdef PC98
- int obufsize;
- u_char *obuf1;
- u_char *obuf2;
-#else
- u_char obuf1[256];
- u_char obuf2[256];
-#endif
-};
-
-#ifdef COM_ESP
-static int espattach(struct com_s *com, Port_t esp_port);
-#endif
-
-static timeout_t siobusycheck;
-static u_int siodivisor(u_long rclk, speed_t speed);
-static timeout_t siodtrwakeup;
-static void comhardclose(struct com_s *com);
-static void sioinput(struct com_s *com);
-static void siointr1(struct com_s *com);
-static void siointr(void *arg);
-static int commctl(struct com_s *com, int bits, int how);
-static int comparam(struct tty *tp, struct termios *t);
-static void siopoll(void *);
-static void siosettimeout(void);
-static int siosetwater(struct com_s *com, speed_t speed);
-static void comstart(struct tty *tp);
-static void comstop(struct tty *tp, int rw);
-static timeout_t comwakeup;
-static void disc_optim(struct tty *tp, struct termios *t,
- struct com_s *com);
-
-char sio_driver_name[] = "sio";
-static struct mtx sio_lock;
-static int sio_inited;
-
-/* table and macro for fast conversion from a unit number to its com struct */
-devclass_t sio_devclass;
-#define com_addr(unit) ((struct com_s *) \
- devclass_get_softc(sio_devclass, unit)) /* XXX */
-
-static d_open_t sioopen;
-static d_close_t sioclose;
-static d_read_t sioread;
-static d_write_t siowrite;
-static d_ioctl_t sioioctl;
-
-#define CDEV_MAJOR 28
-static struct cdevsw sio_cdevsw = {
- .d_open = sioopen,
- .d_close = sioclose,
- .d_read = sioread,
- .d_write = siowrite,
- .d_ioctl = sioioctl,
- .d_poll = ttypoll,
- .d_name = sio_driver_name,
- .d_maj = CDEV_MAJOR,
- .d_flags = D_TTY,
- .d_kqfilter = ttykqfilter,
-};
-
-int comconsole = -1;
-static volatile speed_t comdefaultrate = CONSPEED;
-static u_long comdefaultrclk = DEFAULT_RCLK;
-SYSCTL_ULONG(_machdep, OID_AUTO, conrclk, CTLFLAG_RW, &comdefaultrclk, 0, "");
-static speed_t gdbdefaultrate = GDBSPEED;
-SYSCTL_UINT(_machdep, OID_AUTO, gdbspeed, CTLFLAG_RW,
- &gdbdefaultrate, GDBSPEED, "");
-static u_int com_events; /* input chars + weighted output completions */
-static Port_t siocniobase;
-static int siocnunit = -1;
-static Port_t siogdbiobase;
-static int siogdbunit = -1;
-static void *sio_slow_ih;
-static void *sio_fast_ih;
-static int sio_timeout;
-static int sio_timeouts_until_log;
-static struct callout_handle sio_timeout_handle
- = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
-static int sio_numunits;
-
-#ifdef PC98
-struct siodev {
- short if_type;
- short irq;
- Port_t cmd, sts, ctrl, mod;
-};
-static int sysclock;
-
-#define COM_INT_DISABLE {int previpri; previpri=spltty();
-#define COM_INT_ENABLE splx(previpri);}
-#define IEN_TxFLAG IEN_Tx
-
-#define COM_CARRIER_DETECT_EMULATE 0
-#define PC98_CHECK_MODEM_INTERVAL (hz/10)
-#define DCD_OFF_TOLERANCE 2
-#define DCD_ON_RECOGNITION 2
-#define IS_8251(if_type) (!(if_type & 0x10))
-#define COM1_EXT_CLOCK 0x40000
-
-static void commint(dev_t dev);
-static void com_tiocm_set(struct com_s *com, int msr);
-static void com_tiocm_bis(struct com_s *com, int msr);
-static void com_tiocm_bic(struct com_s *com, int msr);
-static int com_tiocm_get(struct com_s *com);
-static int com_tiocm_get_delta(struct com_s *com);
-static void pc98_msrint_start(dev_t dev);
-static void com_cflag_and_speed_set(struct com_s *com, int cflag, int speed);
-static int pc98_ttspeedtab(struct com_s *com, int speed, u_int *divisor);
-static int pc98_get_modem_status(struct com_s *com);
-static timeout_t pc98_check_msr;
-static void pc98_set_baud_rate(struct com_s *com, u_int count);
-static void pc98_i8251_reset(struct com_s *com, int mode, int command);
-static void pc98_disable_i8251_interrupt(struct com_s *com, int mod);
-static void pc98_enable_i8251_interrupt(struct com_s *com, int mod);
-static int pc98_check_i8251_interrupt(struct com_s *com);
-static int pc98_i8251_get_cmd(struct com_s *com);
-static int pc98_i8251_get_mod(struct com_s *com);
-static void pc98_i8251_set_cmd(struct com_s *com, int x);
-static void pc98_i8251_or_cmd(struct com_s *com, int x);
-static void pc98_i8251_clear_cmd(struct com_s *com, int x);
-static void pc98_i8251_clear_or_cmd(struct com_s *com, int clr, int x);
-static int pc98_check_if_type(device_t dev, struct siodev *iod);
-static int pc98_check_8251vfast(void);
-static int pc98_check_8251fifo(void);
-static void pc98_check_sysclock(void);
-static void pc98_set_ioport(struct com_s *com);
-
-#define com_int_Tx_disable(com) \
- pc98_disable_i8251_interrupt(com,IEN_Tx|IEN_TxEMP)
-#define com_int_Tx_enable(com) \
- pc98_enable_i8251_interrupt(com,IEN_TxFLAG)
-#define com_int_Rx_disable(com) \
- pc98_disable_i8251_interrupt(com,IEN_Rx)
-#define com_int_Rx_enable(com) \
- pc98_enable_i8251_interrupt(com,IEN_Rx)
-#define com_int_TxRx_disable(com) \
- pc98_disable_i8251_interrupt(com,IEN_Tx|IEN_TxEMP|IEN_Rx)
-#define com_int_TxRx_enable(com) \
- pc98_enable_i8251_interrupt(com,IEN_TxFLAG|IEN_Rx)
-#define com_send_break_on(com) \
- pc98_i8251_or_cmd(com,CMD8251_SBRK)
-#define com_send_break_off(com) \
- pc98_i8251_clear_cmd(com,CMD8251_SBRK)
-
-static struct speedtab pc98speedtab[] = { /* internal RS232C interface */
- { 0, 0, },
- { 50, 50, },
- { 75, 75, },
- { 150, 150, },
- { 200, 200, },
- { 300, 300, },
- { 600, 600, },
- { 1200, 1200, },
- { 2400, 2400, },
- { 4800, 4800, },
- { 9600, 9600, },
- { 19200, 19200, },
- { 38400, 38400, },
- { 51200, 51200, },
- { 76800, 76800, },
- { 20800, 20800, },
- { 31200, 31200, },
- { 41600, 41600, },
- { 62400, 62400, },
- { -1, -1 }
-};
-static struct speedtab pc98fast_speedtab[] = {
- { 9600, 0x80 | (DEFAULT_RCLK / (16 * (9600))), },
- { 19200, 0x80 | (DEFAULT_RCLK / (16 * (19200))), },
- { 38400, 0x80 | (DEFAULT_RCLK / (16 * (38400))), },
- { 57600, 0x80 | (DEFAULT_RCLK / (16 * (57600))), },
- { 115200, 0x80 | (DEFAULT_RCLK / (16 * (115200))), },
- { -1, -1 }
-};
-static struct speedtab comspeedtab_pio9032b[] = {
- { 300, 6, },
- { 600, 5, },
- { 1200, 4, },
- { 2400, 3, },
- { 4800, 2, },
- { 9600, 1, },
- { 19200, 0, },
- { 38400, 7, },
- { -1, -1 }
-};
-static struct speedtab comspeedtab_b98_01[] = {
- { 75, 11, },
- { 150, 10, },
- { 300, 9, },
- { 600, 8, },
- { 1200, 7, },
- { 2400, 6, },
- { 4800, 5, },
- { 9600, 4, },
- { 19200, 3, },
- { 38400, 2, },
- { 76800, 1, },
- { 153600, 0, },
- { -1, -1 }
-};
-static struct speedtab comspeedtab_ind[] = {
- { 300, 1536, },
- { 600, 768, },
- { 1200, 384, },
- { 2400, 192, },
- { 4800, 96, },
- { 9600, 48, },
- { 19200, 24, },
- { 38400, 12, },
- { 57600, 8, },
- { 115200, 4, },
- { 153600, 3, },
- { 230400, 2, },
- { 460800, 1, },
- { -1, -1 }
-};
-
-struct {
- char *name;
- short port_table[7];
- short irr_mask;
- struct speedtab *speedtab;
- short check_irq;
-} if_8251_type[] = {
- /* COM_IF_INTERNAL */
- { " (internal)", {0x30, 0x32, 0x32, 0x33, 0x35, -1, -1},
- -1, pc98speedtab, 1 },
- /* COM_IF_PC9861K_1 */
- { " (PC9861K)", {0xb1, 0xb3, 0xb3, 0xb0, 0xb0, -1, -1},
- 3, NULL, 1 },
- /* COM_IF_PC9861K_2 */
- { " (PC9861K)", {0xb9, 0xbb, 0xbb, 0xb2, 0xb2, -1, -1},
- 3, NULL, 1 },
- /* COM_IF_IND_SS_1 */
- { " (IND-SS)", {0xb1, 0xb3, 0xb3, 0xb0, 0xb0, 0xb3, -1},
- 3, comspeedtab_ind, 1 },
- /* COM_IF_IND_SS_2 */
- { " (IND-SS)", {0xb9, 0xbb, 0xbb, 0xb2, 0xb2, 0xbb, -1},
- 3, comspeedtab_ind, 1 },
- /* COM_IF_PIO9032B_1 */
- { " (PIO9032B)", {0xb1, 0xb3, 0xb3, 0xb0, 0xb0, 0xb8, -1},
- 7, comspeedtab_pio9032b, 1 },
- /* COM_IF_PIO9032B_2 */
- { " (PIO9032B)", {0xb9, 0xbb, 0xbb, 0xb2, 0xb2, 0xba, -1},
- 7, comspeedtab_pio9032b, 1 },
- /* COM_IF_B98_01_1 */
- { " (B98-01)", {0xb1, 0xb3, 0xb3, 0xb0, 0xb0, 0xd1, 0xd3},
- 7, comspeedtab_b98_01, 0 },
- /* COM_IF_B98_01_2 */
- { " (B98-01)", {0xb9, 0xbb, 0xbb, 0xb2, 0xb2, 0xd5, 0xd7},
- 7, comspeedtab_b98_01, 0 },
-};
-#define PC98SIO_data_port(type) (if_8251_type[type].port_table[0])
-#define PC98SIO_cmd_port(type) (if_8251_type[type].port_table[1])
-#define PC98SIO_sts_port(type) (if_8251_type[type].port_table[2])
-#define PC98SIO_in_modem_port(type) (if_8251_type[type].port_table[3])
-#define PC98SIO_intr_ctrl_port(type) (if_8251_type[type].port_table[4])
-#define PC98SIO_baud_rate_port(type) (if_8251_type[type].port_table[5])
-#define PC98SIO_func_port(type) (if_8251_type[type].port_table[6])
-
-#define I8251F_data 0x130
-#define I8251F_lsr 0x132
-#define I8251F_msr 0x134
-#define I8251F_iir 0x136
-#define I8251F_fcr 0x138
-#define I8251F_div 0x13a
-
-
-static bus_addr_t port_table_0[] =
- {0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007};
-static bus_addr_t port_table_1[] =
- {0x000, 0x002, 0x004, 0x006, 0x008, 0x00a, 0x00c, 0x00e};
-static bus_addr_t port_table_8[] =
- {0x000, 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700};
-static bus_addr_t port_table_rsa[] = {
- 0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f,
- 0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007
-};
-
-struct {
- char *name;
- short irr_read;
- short irr_write;
- bus_addr_t *iat;
- bus_size_t iatsz;
- u_long rclk;
-} if_16550a_type[] = {
- /* COM_IF_RSA98 */
- {" (RSA-98)", -1, -1, port_table_0, IO_COMSIZE, DEFAULT_RCLK},
- /* COM_IF_NS16550 */
- {"", -1, -1, port_table_0, IO_COMSIZE, DEFAULT_RCLK},
- /* COM_IF_SECOND_CCU */
- {"", -1, -1, port_table_0, IO_COMSIZE, DEFAULT_RCLK},
- /* COM_IF_MC16550II */
- {" (MC16550II)", -1, 0x1000, port_table_8, IO_COMSIZE,
- DEFAULT_RCLK * 4},
- /* COM_IF_MCRS98 */
- {" (MC-RS98)", -1, 0x1000, port_table_8, IO_COMSIZE, DEFAULT_RCLK * 4},
- /* COM_IF_RSB3000 */
- {" (RSB-3000)", 0xbf, -1, port_table_1, IO_COMSIZE, DEFAULT_RCLK * 10},
- /* COM_IF_RSB384 */
- {" (RSB-384)", 0xbf, -1, port_table_1, IO_COMSIZE, DEFAULT_RCLK * 10},
- /* COM_IF_MODEM_CARD */
- {"", -1, -1, port_table_0, IO_COMSIZE, DEFAULT_RCLK},
- /* COM_IF_RSA98III */
- {" (RSA-98III)", -1, -1, port_table_rsa, 16, DEFAULT_RCLK * 8},
- /* COM_IF_ESP98 */
- {" (ESP98)", -1, -1, port_table_1, IO_COMSIZE, DEFAULT_RCLK * 4},
-};
-#endif /* PC98 */
-
-#ifdef COM_ESP
-#ifdef PC98
-
-/* XXX configure this properly. */
-/* XXX quite broken for new-bus. */
-static Port_t likely_com_ports[] = { 0, 0xb0, 0xb1, 0 };
-static Port_t likely_esp_ports[] = { 0xc0d0, 0 };
-
-#define ESP98_CMD1 (ESP_CMD1 * 0x100)
-#define ESP98_CMD2 (ESP_CMD2 * 0x100)
-#define ESP98_STATUS1 (ESP_STATUS1 * 0x100)
-#define ESP98_STATUS2 (ESP_STATUS2 * 0x100)
-
-#else /* PC98 */
-
-/* XXX configure this properly. */
-static Port_t likely_com_ports[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, };
-static Port_t likely_esp_ports[] = { 0x140, 0x180, 0x280, 0 };
-
-#endif /* PC98 */
-#endif
-
-/*
- * handle sysctl read/write requests for console speed
- *
- * In addition to setting comdefaultrate for I/O through /dev/console,
- * also set the initial and lock values for the /dev/ttyXX device
- * if there is one associated with the console. Finally, if the /dev/tty
- * device has already been open, change the speed on the open running port
- * itself.
- */
-
-static int
-sysctl_machdep_comdefaultrate(SYSCTL_HANDLER_ARGS)
-{
- int error, s;
- speed_t newspeed;
- struct com_s *com;
- struct tty *tp;
-
- newspeed = comdefaultrate;
-
- error = sysctl_handle_opaque(oidp, &newspeed, sizeof newspeed, req);
- if (error || !req->newptr)
- return (error);
-
- comdefaultrate = newspeed;
-
- if (comconsole < 0) /* serial console not selected? */
- return (0);
-
- com = com_addr(comconsole);
- if (com == NULL)
- return (ENXIO);
-
- /*
- * set the initial and lock rates for /dev/ttydXX and /dev/cuaXX
- * (note, the lock rates really are boolean -- if non-zero, disallow
- * speed changes)
- */
- com->it_in.c_ispeed = com->it_in.c_ospeed =
- com->lt_in.c_ispeed = com->lt_in.c_ospeed =
- com->it_out.c_ispeed = com->it_out.c_ospeed =
- com->lt_out.c_ispeed = com->lt_out.c_ospeed = comdefaultrate;
-
- /*
- * if we're open, change the running rate too
- */
- tp = com->tp;
- if (tp && (tp->t_state & TS_ISOPEN)) {
- tp->t_termios.c_ispeed =
- tp->t_termios.c_ospeed = comdefaultrate;
- s = spltty();
- error = comparam(tp, &tp->t_termios);
- splx(s);
- }
- return error;
-}
-
-SYSCTL_PROC(_machdep, OID_AUTO, conspeed, CTLTYPE_INT | CTLFLAG_RW,
- 0, 0, sysctl_machdep_comdefaultrate, "I", "");
-
-/*
- * Unload the driver and clear the table.
- * XXX this is mostly wrong.
- * XXX TODO:
- * This is usually called when the card is ejected, but
- * can be caused by a kldunload of a controller driver.
- * The idea is to reset the driver's view of the device
- * and ensure that any driver entry points such as
- * read and write do not hang.
- */
-int
-siodetach(dev)
- device_t dev;
-{
- struct com_s *com;
- int i;
-
- com = (struct com_s *) device_get_softc(dev);
- if (com == NULL) {
- device_printf(dev, "NULL com in siounload\n");
- return (0);
- }
- com->gone = 1;
- for (i = 0 ; i < 6; i++)
- destroy_dev(com->devs[i]);
- if (com->irqres) {
- bus_teardown_intr(dev, com->irqres, com->cookie);
- bus_release_resource(dev, SYS_RES_IRQ, 0, com->irqres);
- }
- if (com->ioportres)
- bus_release_resource(dev, SYS_RES_IOPORT, 0, com->ioportres);
- if (com->tp && (com->tp->t_state & TS_ISOPEN)) {
- device_printf(dev, "still open, forcing close\n");
- (*linesw[com->tp->t_line].l_close)(com->tp, 0);
- com->tp->t_gen++;
- ttyclose(com->tp);
- ttwakeup(com->tp);
- ttwwakeup(com->tp);
- } else {
- if (com->ibuf != NULL)
- free(com->ibuf, M_DEVBUF);
-#ifdef PC98
- if (com->obuf1 != NULL)
- free(com->obuf1, M_DEVBUF);
-#endif
- device_set_softc(dev, NULL);
- free(com, M_DEVBUF);
- }
- return (0);
-}
-
-int
-sioprobe(dev, xrid, rclk, noprobe)
- device_t dev;
- int xrid;
- u_long rclk;
- int noprobe;
-{
-#if 0
- static bool_t already_init;
- device_t xdev;
-#endif
- struct com_s *com;
- u_int divisor;
- bool_t failures[10];
- int fn;
- device_t idev;
- Port_t iobase;
- intrmask_t irqmap[4];
- intrmask_t irqs;
- u_char mcr_image;
- int result;
- u_long xirq;
- u_int flags = device_get_flags(dev);
- int rid;
- struct resource *port;
-#ifdef PC98
- int tmp;
- struct siodev iod;
-#endif
-
-#ifdef PC98
- iod.if_type = GET_IFTYPE(flags);
- if ((iod.if_type < 0 || iod.if_type > COM_IF_END1) &&
- (iod.if_type < 0x10 || iod.if_type > COM_IF_END2))
- return ENXIO;
-#endif
-
- rid = xrid;
-#ifdef PC98
- if (IS_8251(iod.if_type)) {
- port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
- 0, ~0, 1, RF_ACTIVE);
- } else if (iod.if_type == COM_IF_MODEM_CARD ||
- iod.if_type == COM_IF_RSA98III ||
- isa_get_vendorid(dev)) {
- port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
- if_16550a_type[iod.if_type & 0x0f].iatsz, RF_ACTIVE);
- } else {
- port = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid,
- if_16550a_type[iod.if_type & 0x0f].iat,
- if_16550a_type[iod.if_type & 0x0f].iatsz, RF_ACTIVE);
- }
-#else
- port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
- 0, ~0, IO_COMSIZE, RF_ACTIVE);
-#endif
- if (!port)
- return (ENXIO);
-#ifdef PC98
- if (!IS_8251(iod.if_type)) {
- if (isa_load_resourcev(port,
- if_16550a_type[iod.if_type & 0x0f].iat,
- if_16550a_type[iod.if_type & 0x0f].iatsz) != 0) {
- bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
- return ENXIO;
- }
- }
-#endif
-
- com = malloc(sizeof(*com), M_DEVBUF, M_NOWAIT | M_ZERO);
- if (com == NULL)
- return (ENOMEM);
- device_set_softc(dev, com);
- com->bst = rman_get_bustag(port);
- com->bsh = rman_get_bushandle(port);
-#ifdef PC98
- if (!IS_8251(iod.if_type) && rclk == 0)
- rclk = if_16550a_type[iod.if_type & 0x0f].rclk;
-#else
- if (rclk == 0)
- rclk = DEFAULT_RCLK;
-#endif
- com->rclk = rclk;
-
- while (sio_inited != 2)
- if (atomic_cmpset_int(&sio_inited, 0, 1)) {
- mtx_init(&sio_lock, sio_driver_name, NULL,
- (comconsole != -1) ?
- MTX_SPIN | MTX_QUIET : MTX_SPIN);
- atomic_store_rel_int(&sio_inited, 2);
- }
-
-#if 0
- /*
- * XXX this is broken - when we are first called, there are no
- * previously configured IO ports. We could hard code
- * 0x3f8, 0x2f8, 0x3e8, 0x2e8 etc but that's probably worse.
- * This code has been doing nothing since the conversion since
- * "count" is zero the first time around.
- */
- if (!already_init) {
- /*
- * Turn off MCR_IENABLE for all likely serial ports. An unused
- * port with its MCR_IENABLE gate open will inhibit interrupts
- * from any used port that shares the interrupt vector.
- * XXX the gate enable is elsewhere for some multiports.
- */
- device_t *devs;
- int count, i, xioport;
-#ifdef PC98
- int xiftype;
-#endif
-
- devclass_get_devices(sio_devclass, &devs, &count);
-#ifdef PC98
- for (i = 0; i < count; i++) {
- xdev = devs[i];
- xioport = bus_get_resource_start(xdev, SYS_RES_IOPORT, 0);
- xiftype = GET_IFTYPE(device_get_flags(xdev));
- if (device_is_enabled(xdev) && xioport > 0) {
- if (IS_8251(xiftype))
- outb((xioport & 0xff00) | PC98SIO_cmd_port(xiftype & 0x0f), 0xf2);
- else
- outb(xioport + if_16550a_type[xiftype & 0x0f].iat[com_mcr], 0);
- }
- }
-#else
- for (i = 0; i < count; i++) {
- xdev = devs[i];
- if (device_is_enabled(xdev) &&
- bus_get_resource(xdev, SYS_RES_IOPORT, 0, &xioport,
- NULL) == 0)
- outb(xioport + com_mcr, 0);
- }
-#endif
- free(devs, M_TEMP);
- already_init = TRUE;
- }
-#endif
-
- if (COM_LLCONSOLE(flags)) {
- printf("sio%d: reserved for low-level i/o\n",
- device_get_unit(dev));
- bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
- device_set_softc(dev, NULL);
- free(com, M_DEVBUF);
- return (ENXIO);
- }
-
-#ifdef PC98
- DELAY(10);
-
- /*
- * If the port is i8251 UART (internal, B98_01)
- */
- if (pc98_check_if_type(dev, &iod) == -1) {
- bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
- device_set_softc(dev, NULL);
- free(com, M_DEVBUF);
- return (ENXIO);
- }
- if (iod.irq > 0)
- bus_set_resource(dev, SYS_RES_IRQ, 0, iod.irq, 1);
- if (IS_8251(iod.if_type)) {
- outb(iod.cmd, 0);
- DELAY(10);
- outb(iod.cmd, 0);
- DELAY(10);
- outb(iod.cmd, 0);
- DELAY(10);
- outb(iod.cmd, CMD8251_RESET);
- DELAY(1000); /* for a while...*/
- outb(iod.cmd, 0xf2); /* MODE (dummy) */
- DELAY(10);
- outb(iod.cmd, 0x01); /* CMD (dummy) */
- DELAY(1000); /* for a while...*/
- if (( inb(iod.sts) & STS8251_TxEMP ) == 0 ) {
- result = (ENXIO);
- }
- if (if_8251_type[iod.if_type & 0x0f].check_irq) {
- COM_INT_DISABLE
- tmp = ( inb( iod.ctrl ) & ~(IEN_Rx|IEN_TxEMP|IEN_Tx));
- outb( iod.ctrl, tmp|IEN_TxEMP );
- DELAY(10);
- result = isa_irq_pending() ? 0 : ENXIO;
- outb( iod.ctrl, tmp );
- COM_INT_ENABLE
- } else {
- /*
- * B98_01 doesn't activate TxEMP interrupt line
- * when being reset, so we can't check irq pending.
- */
- result = 0;
- }
- if (epson_machine_id==0x20) { /* XXX */
- result = 0;
- }
- bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
- if (result) {
- device_set_softc(dev, NULL);
- free(com, M_DEVBUF);
- }
- return result;
- }
-#endif /* PC98 */
- /*
- * If the device is on a multiport card and has an AST/4
- * compatible interrupt control register, initialize this
- * register and prepare to leave MCR_IENABLE clear in the mcr.
- * Otherwise, prepare to set MCR_IENABLE in the mcr.
- * Point idev to the device struct giving the correct id_irq.
- * This is the struct for the master device if there is one.
- */
- idev = dev;
- mcr_image = MCR_IENABLE;
-#ifdef COM_MULTIPORT
- if (COM_ISMULTIPORT(flags)) {
-#ifndef PC98
- Port_t xiobase;
- u_long io;
-#endif
-
- idev = devclass_get_device(sio_devclass, COM_MPMASTER(flags));
- if (idev == NULL) {
- printf("sio%d: master device %d not configured\n",
- device_get_unit(dev), COM_MPMASTER(flags));
- idev = dev;
- }
-#ifndef PC98
- if (!COM_NOTAST4(flags)) {
- if (bus_get_resource(idev, SYS_RES_IOPORT, 0, &io,
- NULL) == 0) {
- xiobase = io;
- if (bus_get_resource(idev, SYS_RES_IRQ, 0,
- NULL, NULL) == 0)
- outb(xiobase + com_scr, 0x80);
- else
- outb(xiobase + com_scr, 0);
- }
- mcr_image = 0;
- }
-#endif
- }
-#endif /* COM_MULTIPORT */
- if (bus_get_resource(idev, SYS_RES_IRQ, 0, NULL, NULL) != 0)
- mcr_image = 0;
-
- bzero(failures, sizeof failures);
- iobase = rman_get_start(port);
-
-#ifdef PC98
- if (iod.if_type == COM_IF_RSA98III) {
- mcr_image = 0;
-
- outb(iobase + rsa_msr, 0x04);
- outb(iobase + rsa_frr, 0x00);
- if ((inb(iobase + rsa_srr) & 0x36) != 0x36) {
- bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
- device_set_softc(dev, NULL);
- free(com, M_DEVBUF);
- return (ENXIO);
- }
- outb(iobase + rsa_ier, 0x00);
- outb(iobase + rsa_frr, 0x00);
- outb(iobase + rsa_tivsr, 0x00);
- outb(iobase + rsa_tcr, 0x00);
- }
-
- tmp = if_16550a_type[iod.if_type & 0x0f].irr_write;
- if (tmp != -1) {
- /* MC16550II */
- int irqout;
- switch (isa_get_irq(idev)) {
- case 3: irqout = 4; break;
- case 5: irqout = 5; break;
- case 6: irqout = 6; break;
- case 12: irqout = 7; break;
- default:
- printf("sio%d: irq configuration error\n",
- device_get_unit(dev));
- bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
- device_set_softc(dev, NULL);
- free(com, M_DEVBUF);
- return (ENXIO);
- }
- outb((iobase & 0x00ff) | tmp, irqout);
- }
-#endif
-
- /*
- * We don't want to get actual interrupts, just masked ones.
- * Interrupts from this line should already be masked in the ICU,
- * but mask them in the processor as well in case there are some
- * (misconfigured) shared interrupts.
- */
- mtx_lock_spin(&sio_lock);
-/* EXTRA DELAY? */
-
- /*
- * Initialize the speed and the word size and wait long enough to
- * drain the maximum of 16 bytes of junk in device output queues.
- * The speed is undefined after a master reset and must be set
- * before relying on anything related to output. There may be
- * junk after a (very fast) soft reboot and (apparently) after
- * master reset.
- * XXX what about the UART bug avoided by waiting in comparam()?
- * We don't want to to wait long enough to drain at 2 bps.
- */
- if (iobase == siocniobase)
- DELAY((16 + 1) * 1000000 / (comdefaultrate / 10));
- else {
- sio_setreg(com, com_cfcr, CFCR_DLAB | CFCR_8BITS);
- divisor = siodivisor(rclk, SIO_TEST_SPEED);
- sio_setreg(com, com_dlbl, divisor & 0xff);
- sio_setreg(com, com_dlbh, divisor >> 8);
- sio_setreg(com, com_cfcr, CFCR_8BITS);
- DELAY((16 + 1) * 1000000 / (SIO_TEST_SPEED / 10));
- }
-
- /*
- * Enable the interrupt gate and disable device interupts. This
- * should leave the device driving the interrupt line low and
- * guarantee an edge trigger if an interrupt can be generated.
- */
-/* EXTRA DELAY? */
- sio_setreg(com, com_mcr, mcr_image);
- sio_setreg(com, com_ier, 0);
- DELAY(1000); /* XXX */
- irqmap[0] = isa_irq_pending();
-
- /*
- * Attempt to set loopback mode so that we can send a null byte
- * without annoying any external device.
- */
-/* EXTRA DELAY? */
- sio_setreg(com, com_mcr, mcr_image | MCR_LOOPBACK);
-
- /*
- * Attempt to generate an output interrupt. On 8250's, setting
- * IER_ETXRDY generates an interrupt independent of the current
- * setting and independent of whether the THR is empty. On 16450's,
- * setting IER_ETXRDY generates an interrupt independent of the
- * current setting. On 16550A's, setting IER_ETXRDY only
- * generates an interrupt when IER_ETXRDY is not already set.
- */
- sio_setreg(com, com_ier, IER_ETXRDY);
-#ifdef PC98
- if (iod.if_type == COM_IF_RSA98III)
- outb(iobase + rsa_ier, 0x04);
-#endif
-
- /*
- * On some 16x50 incompatibles, setting IER_ETXRDY doesn't generate
- * an interrupt. They'd better generate one for actually doing
- * output. Loopback may be broken on the same incompatibles but
- * it's unlikely to do more than allow the null byte out.
- */
- sio_setreg(com, com_data, 0);
- DELAY((1 + 2) * 1000000 / (SIO_TEST_SPEED / 10));
-
- /*
- * Turn off loopback mode so that the interrupt gate works again
- * (MCR_IENABLE was hidden). This should leave the device driving
- * an interrupt line high. It doesn't matter if the interrupt
- * line oscillates while we are not looking at it, since interrupts
- * are disabled.
- */
-/* EXTRA DELAY? */
- sio_setreg(com, com_mcr, mcr_image);
-
- /*
- * It seems my Xircom CBEM56G Cardbus modem wants to be reset
- * to 8 bits *again*, or else probe test 0 will fail.
- * gwk@sgi.com, 4/19/2001
- */
- sio_setreg(com, com_cfcr, CFCR_8BITS);
-
- /*
- * Some pcmcia cards have the "TXRDY bug", so we check everyone
- * for IIR_TXRDY implementation ( Palido 321s, DC-1S... )
- */
- if (noprobe) {
- /* Reading IIR register twice */
- for (fn = 0; fn < 2; fn ++) {
- DELAY(10000);
- failures[6] = sio_getreg(com, com_iir);
- }
- /* Check IIR_TXRDY clear ? */
- result = 0;
- if (failures[6] & IIR_TXRDY) {
- /* No, Double check with clearing IER */
- sio_setreg(com, com_ier, 0);
- if (sio_getreg(com, com_iir) & IIR_NOPEND) {
- /* Ok. We discovered TXRDY bug! */
- SET_FLAG(dev, COM_C_IIR_TXRDYBUG);
- } else {
- /* Unknown, Just omit this chip.. XXX */
- result = ENXIO;
- sio_setreg(com, com_mcr, 0);
- }
- } else {
- /* OK. this is well-known guys */
- CLR_FLAG(dev, COM_C_IIR_TXRDYBUG);
- }
- sio_setreg(com, com_ier, 0);
- sio_setreg(com, com_cfcr, CFCR_8BITS);
- mtx_unlock_spin(&sio_lock);
- bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
- if (iobase == siocniobase)
- result = 0;
- if (result != 0) {
- device_set_softc(dev, NULL);
- free(com, M_DEVBUF);
- }
- return (result);
- }
-
- /*
- * Check that
- * o the CFCR, IER and MCR in UART hold the values written to them
- * (the values happen to be all distinct - this is good for
- * avoiding false positive tests from bus echoes).
- * o an output interrupt is generated and its vector is correct.
- * o the interrupt goes away when the IIR in the UART is read.
- */
-/* EXTRA DELAY? */
- failures[0] = sio_getreg(com, com_cfcr) - CFCR_8BITS;
- failures[1] = sio_getreg(com, com_ier) - IER_ETXRDY;
- failures[2] = sio_getreg(com, com_mcr) - mcr_image;
- DELAY(10000); /* Some internal modems need this time */
- irqmap[1] = isa_irq_pending();
- failures[4] = (sio_getreg(com, com_iir) & IIR_IMASK) - IIR_TXRDY;
-#ifdef PC98
- if (iod.if_type == COM_IF_RSA98III)
- inb(iobase + rsa_srr);
-#endif
- DELAY(1000); /* XXX */
- irqmap[2] = isa_irq_pending();
- failures[6] = (sio_getreg(com, com_iir) & IIR_IMASK) - IIR_NOPEND;
-#ifdef PC98
- if (iod.if_type == COM_IF_RSA98III)
- inb(iobase + rsa_srr);
-#endif
-
- /*
- * Turn off all device interrupts and check that they go off properly.
- * Leave MCR_IENABLE alone. For ports without a master port, it gates
- * the OUT2 output of the UART to
- * the ICU input. Closing the gate would give a floating ICU input
- * (unless there is another device driving it) and spurious interrupts.
- * (On the system that this was first tested on, the input floats high
- * and gives a (masked) interrupt as soon as the gate is closed.)
- */
- sio_setreg(com, com_ier, 0);
- sio_setreg(com, com_cfcr, CFCR_8BITS); /* dummy to avoid bus echo */
- failures[7] = sio_getreg(com, com_ier);
-#ifdef PC98
- if (iod.if_type == COM_IF_RSA98III)
- outb(iobase + rsa_ier, 0x00);
-#endif
- DELAY(1000); /* XXX */
- irqmap[3] = isa_irq_pending();
- failures[9] = (sio_getreg(com, com_iir) & IIR_IMASK) - IIR_NOPEND;
-#ifdef PC98
- if (iod.if_type == COM_IF_RSA98III) {
- inb(iobase + rsa_srr);
- outb(iobase + rsa_frr, 0x00);
- }
-#endif
-
- mtx_unlock_spin(&sio_lock);
-
- irqs = irqmap[1] & ~irqmap[0];
- if (bus_get_resource(idev, SYS_RES_IRQ, 0, &xirq, NULL) == 0 &&
- ((1 << xirq) & irqs) == 0) {
- printf(
- "sio%d: configured irq %ld not in bitmap of probed irqs %#x\n",
- device_get_unit(dev), xirq, irqs);
- printf(
- "sio%d: port may not be enabled\n",
- device_get_unit(dev));
- }
- if (bootverbose)
- printf("sio%d: irq maps: %#x %#x %#x %#x\n",
- device_get_unit(dev),
- irqmap[0], irqmap[1], irqmap[2], irqmap[3]);
-
- result = 0;
- for (fn = 0; fn < sizeof failures; ++fn)
- if (failures[fn]) {
- sio_setreg(com, com_mcr, 0);
- result = ENXIO;
- if (bootverbose) {
- printf("sio%d: probe failed test(s):",
- device_get_unit(dev));
- for (fn = 0; fn < sizeof failures; ++fn)
- if (failures[fn])
- printf(" %d", fn);
- printf("\n");
- }
- break;
- }
- bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
- if (iobase == siocniobase)
- result = 0;
- if (result != 0) {
- device_set_softc(dev, NULL);
- free(com, M_DEVBUF);
- }
- return (result);
-}
-
-#ifdef COM_ESP
-static int
-espattach(com, esp_port)
- struct com_s *com;
- Port_t esp_port;
-{
- u_char dips;
- u_char val;
-
- /*
- * Check the ESP-specific I/O port to see if we're an ESP
- * card. If not, return failure immediately.
- */
- if ((inb(esp_port) & 0xf3) == 0) {
- printf(" port 0x%x is not an ESP board?\n", esp_port);
- return (0);
- }
-
- /*
- * We've got something that claims to be a Hayes ESP card.
- * Let's hope so.
- */
-
- /* Get the dip-switch configuration */
-#ifdef PC98
- outb(esp_port + ESP98_CMD1, ESP_GETDIPS);
- dips = inb(esp_port + ESP98_STATUS1);
-#else
- outb(esp_port + ESP_CMD1, ESP_GETDIPS);
- dips = inb(esp_port + ESP_STATUS1);
-#endif
-
- /*
- * Bits 0,1 of dips say which COM port we are.
- */
-#ifdef PC98
- if ((rman_get_start(com->ioportres) & 0xff) ==
- likely_com_ports[dips & 0x03])
-#else
- if (rman_get_start(com->ioportres) == likely_com_ports[dips & 0x03])
-#endif
- printf(" : ESP");
- else {
- printf(" esp_port has com %d\n", dips & 0x03);
- return (0);
- }
-
- /*
- * Check for ESP version 2.0 or later: bits 4,5,6 = 010.
- */
-#ifdef PC98
- outb(esp_port + ESP98_CMD1, ESP_GETTEST);
- val = inb(esp_port + ESP98_STATUS1); /* clear reg 1 */
- val = inb(esp_port + ESP98_STATUS2);
-#else
- outb(esp_port + ESP_CMD1, ESP_GETTEST);
- val = inb(esp_port + ESP_STATUS1); /* clear reg 1 */
- val = inb(esp_port + ESP_STATUS2);
-#endif
- if ((val & 0x70) < 0x20) {
- printf("-old (%o)", val & 0x70);
- return (0);
- }
-
- /*
- * Check for ability to emulate 16550: bit 7 == 1
- */
- if ((dips & 0x80) == 0) {
- printf(" slave");
- return (0);
- }
-
- /*
- * Okay, we seem to be a Hayes ESP card. Whee.
- */
- com->esp = TRUE;
- com->esp_port = esp_port;
- return (1);
-}
-#endif /* COM_ESP */
-
-int
-sioattach(dev, xrid, rclk)
- device_t dev;
- int xrid;
- u_long rclk;
-{
- struct com_s *com;
-#ifdef COM_ESP
- Port_t *espp;
-#endif
- Port_t iobase;
- int minorbase;
- int unit;
- u_int flags;
- int rid;
- struct resource *port;
- int ret;
-#ifdef PC98
- u_char *obuf;
- u_long obufsize;
- int if_type = GET_IFTYPE(device_get_flags(dev));
-#endif
-
- rid = xrid;
-#ifdef PC98
- if (IS_8251(if_type)) {
- port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
- 0, ~0, 1, RF_ACTIVE);
- } else if (if_type == COM_IF_MODEM_CARD ||
- if_type == COM_IF_RSA98III ||
- isa_get_vendorid(dev)) {
- port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
- if_16550a_type[if_type & 0x0f].iatsz, RF_ACTIVE);
- } else {
- port = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid,
- if_16550a_type[if_type & 0x0f].iat,
- if_16550a_type[if_type & 0x0f].iatsz, RF_ACTIVE);
- }
-#else
- port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
- 0, ~0, IO_COMSIZE, RF_ACTIVE);
-#endif
- if (!port)
- return (ENXIO);
-#ifdef PC98
- if (!IS_8251(if_type)) {
- if (isa_load_resourcev(port,
- if_16550a_type[if_type & 0x0f].iat,
- if_16550a_type[if_type & 0x0f].iatsz) != 0) {
- bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
- return ENXIO;
- }
- }
-#endif
-
- iobase = rman_get_start(port);
- unit = device_get_unit(dev);
- com = device_get_softc(dev);
- flags = device_get_flags(dev);
-
- if (unit >= sio_numunits)
- sio_numunits = unit + 1;
-
-#ifdef PC98
- obufsize = 256;
- if (if_type == COM_IF_RSA98III)
- obufsize = 2048;
- if ((obuf = malloc(obufsize * 2, M_DEVBUF, M_NOWAIT)) == NULL) {
- bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
- return ENXIO;
- }
- bzero(obuf, obufsize * 2);
-#endif
-
- /*
- * sioprobe() has initialized the device registers as follows:
- * o cfcr = CFCR_8BITS.
- * It is most important that CFCR_DLAB is off, so that the
- * data port is not hidden when we enable interrupts.
- * o ier = 0.
- * Interrupts are only enabled when the line is open.
- * o mcr = MCR_IENABLE, or 0 if the port has AST/4 compatible
- * interrupt control register or the config specifies no irq.
- * Keeping MCR_DTR and MCR_RTS off might stop the external
- * device from sending before we are ready.
- */
- bzero(com, sizeof *com);
- com->unit = unit;
- com->ioportres = port;
- com->bst = rman_get_bustag(port);
- com->bsh = rman_get_bushandle(port);
- com->cfcr_image = CFCR_8BITS;
- com->dtr_wait = 3 * hz;
- com->loses_outints = COM_LOSESOUTINTS(flags) != 0;
- com->no_irq = bus_get_resource(dev, SYS_RES_IRQ, 0, NULL, NULL) != 0;
- com->tx_fifo_size = 1;
-#ifdef PC98
- com->obufsize = obufsize;
- com->obuf1 = obuf;
- com->obuf2 = obuf + obufsize;
-#endif
- com->obufs[0].l_head = com->obuf1;
- com->obufs[1].l_head = com->obuf2;
-
-#ifdef PC98
- com->pc98_if_type = if_type;
-
- if (IS_8251(if_type)) {
- pc98_set_ioport(com);
-
- if (if_type == COM_IF_INTERNAL && pc98_check_8251fifo()) {
- com->pc98_8251fifo = 1;
- com->pc98_8251fifo_enable = 0;
- }
- } else {
- bus_addr_t *iat = if_16550a_type[if_type & 0x0f].iat;
-
- com->data_port = iobase + iat[com_data];
- com->int_id_port = iobase + iat[com_iir];
- com->modem_ctl_port = iobase + iat[com_mcr];
- com->mcr_image = inb(com->modem_ctl_port);
- com->line_status_port = iobase + iat[com_lsr];
- com->modem_status_port = iobase + iat[com_msr];
- com->intr_ctl_port = iobase + iat[com_ier];
- }
-#else /* not PC98 */
- com->data_port = iobase + com_data;
- com->int_id_port = iobase + com_iir;
- com->modem_ctl_port = iobase + com_mcr;
- com->mcr_image = inb(com->modem_ctl_port);
- com->line_status_port = iobase + com_lsr;
- com->modem_status_port = iobase + com_msr;
- com->intr_ctl_port = iobase + com_ier;
-#endif
-
-#ifdef PC98
- if (!IS_8251(if_type) && rclk == 0)
- rclk = if_16550a_type[if_type & 0x0f].rclk;
-#else
- if (rclk == 0)
- rclk = DEFAULT_RCLK;
-#endif
- com->rclk = rclk;
-
- /*
- * We don't use all the flags from <sys/ttydefaults.h> since they
- * are only relevant for logins. It's important to have echo off
- * initially so that the line doesn't start blathering before the
- * echo flag can be turned off.
- */
- com->it_in.c_iflag = 0;
- com->it_in.c_oflag = 0;
- com->it_in.c_cflag = TTYDEF_CFLAG;
- com->it_in.c_lflag = 0;
- if (unit == comconsole) {
-#ifdef PC98
- if (IS_8251(com->pc98_if_type))
- DELAY(100000);
-#endif
- com->it_in.c_iflag = TTYDEF_IFLAG;
- com->it_in.c_oflag = TTYDEF_OFLAG;
- com->it_in.c_cflag = TTYDEF_CFLAG | CLOCAL;
- com->it_in.c_lflag = TTYDEF_LFLAG;
- com->lt_out.c_cflag = com->lt_in.c_cflag = CLOCAL;
- com->lt_out.c_ispeed = com->lt_out.c_ospeed =
- com->lt_in.c_ispeed = com->lt_in.c_ospeed =
- com->it_in.c_ispeed = com->it_in.c_ospeed = comdefaultrate;
- } else
- com->it_in.c_ispeed = com->it_in.c_ospeed = TTYDEF_SPEED;
- if (siosetwater(com, com->it_in.c_ispeed) != 0) {
- mtx_unlock_spin(&sio_lock);
- /*
- * Leave i/o resources allocated if this is a `cn'-level
- * console, so that other devices can't snarf them.
- */
- if (iobase != siocniobase)
- bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
- return (ENOMEM);
- }
- mtx_unlock_spin(&sio_lock);
- termioschars(&com->it_in);
- com->it_out = com->it_in;
-
- /* attempt to determine UART type */
- printf("sio%d: type", unit);
-
-
-#ifndef PC98
- if (!COM_ISMULTIPORT(flags) &&
- !COM_IIR_TXRDYBUG(flags) && !COM_NOSCR(flags)) {
- u_char scr;
- u_char scr1;
- u_char scr2;
-
- scr = sio_getreg(com, com_scr);
- sio_setreg(com, com_scr, 0xa5);
- scr1 = sio_getreg(com, com_scr);
- sio_setreg(com, com_scr, 0x5a);
- scr2 = sio_getreg(com, com_scr);
- sio_setreg(com, com_scr, scr);
- if (scr1 != 0xa5 || scr2 != 0x5a) {
- printf(" 8250 or not responding");
- goto determined_type;
- }
- }
-#endif /* !PC98 */
-#ifdef PC98
- if (IS_8251(com->pc98_if_type)) {
- if (com->pc98_8251fifo && !COM_NOFIFO(flags))
- com->tx_fifo_size = 16;
- com_int_TxRx_disable( com );
- com_cflag_and_speed_set( com, com->it_in.c_cflag, comdefaultrate );
- com_tiocm_bic( com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE );
- com_send_break_off( com );
-
- if (com->pc98_if_type == COM_IF_INTERNAL) {
- printf(" (internal%s%s)",
- com->pc98_8251fifo ? " fifo" : "",
- PC98SIO_baud_rate_port(com->pc98_if_type) != -1 ?
- " v-fast" : "");
- } else {
- printf(" 8251%s", if_8251_type[com->pc98_if_type & 0x0f].name);
- }
- } else {
-#endif /* PC98 */
- sio_setreg(com, com_fifo, FIFO_ENABLE | FIFO_RX_HIGH);
- DELAY(100);
- com->st16650a = 0;
- switch (inb(com->int_id_port) & IIR_FIFO_MASK) {
- case FIFO_RX_LOW:
- printf(" 16450");
- break;
- case FIFO_RX_MEDL:
- printf(" 16450?");
- break;
- case FIFO_RX_MEDH:
- printf(" 16550?");
- break;
- case FIFO_RX_HIGH:
- if (COM_NOFIFO(flags)) {
- printf(" 16550A fifo disabled");
- } else {
- com->hasfifo = TRUE;
-#ifdef PC98
- com->tx_fifo_size = 0; /* XXX flag conflicts. */
- printf(" 16550A");
-#else
- if (COM_ST16650A(flags)) {
- com->st16650a = 1;
- com->tx_fifo_size = 32;
- printf(" ST16650A");
- } else {
- com->tx_fifo_size = COM_FIFOSIZE(flags);
- printf(" 16550A");
- }
-#endif
- }
-#ifdef PC98
- if (com->pc98_if_type == COM_IF_RSA98III) {
- com->tx_fifo_size = 2048;
- com->rsabase = iobase;
- outb(com->rsabase + rsa_ier, 0x00);
- outb(com->rsabase + rsa_frr, 0x00);
- }
-#endif
-
-#ifdef COM_ESP
-#ifdef PC98
- if (com->pc98_if_type == COM_IF_ESP98)
-#endif
- for (espp = likely_esp_ports; *espp != 0; espp++)
- if (espattach(com, *espp)) {
- com->tx_fifo_size = 1024;
- break;
- }
-#endif
- if (!com->st16650a) {
- if (!com->tx_fifo_size)
- com->tx_fifo_size = 16;
- else
- printf(" lookalike with %d bytes FIFO",
- com->tx_fifo_size);
- }
-
- break;
- }
-
-#ifdef PC98
- if (com->pc98_if_type == COM_IF_RSB3000) {
- /* Set RSB-2000/3000 Extended Buffer mode. */
- u_char lcr;
- lcr = sio_getreg(com, com_cfcr);
- sio_setreg(com, com_cfcr, lcr | CFCR_DLAB);
- sio_setreg(com, com_emr, EMR_EXBUFF | EMR_EFMODE);
- sio_setreg(com, com_cfcr, lcr);
- }
-#endif
-
-#ifdef COM_ESP
- if (com->esp) {
- /*
- * Set 16550 compatibility mode.
- * We don't use the ESP_MODE_SCALE bit to increase the
- * fifo trigger levels because we can't handle large
- * bursts of input.
- * XXX flow control should be set in comparam(), not here.
- */
-#ifdef PC98
- outb(com->esp_port + ESP98_CMD1, ESP_SETMODE);
- outb(com->esp_port + ESP98_CMD2, ESP_MODE_RTS | ESP_MODE_FIFO);
-#else
- outb(com->esp_port + ESP_CMD1, ESP_SETMODE);
- outb(com->esp_port + ESP_CMD2, ESP_MODE_RTS | ESP_MODE_FIFO);
-#endif
-
- /* Set RTS/CTS flow control. */
-#ifdef PC98
- outb(com->esp_port + ESP98_CMD1, ESP_SETFLOWTYPE);
- outb(com->esp_port + ESP98_CMD2, ESP_FLOW_RTS);
- outb(com->esp_port + ESP98_CMD2, ESP_FLOW_CTS);
-#else
- outb(com->esp_port + ESP_CMD1, ESP_SETFLOWTYPE);
- outb(com->esp_port + ESP_CMD2, ESP_FLOW_RTS);
- outb(com->esp_port + ESP_CMD2, ESP_FLOW_CTS);
-#endif
-
- /* Set flow-control levels. */
-#ifdef PC98
- outb(com->esp_port + ESP98_CMD1, ESP_SETRXFLOW);
- outb(com->esp_port + ESP98_CMD2, HIBYTE(768));
- outb(com->esp_port + ESP98_CMD2, LOBYTE(768));
- outb(com->esp_port + ESP98_CMD2, HIBYTE(512));
- outb(com->esp_port + ESP98_CMD2, LOBYTE(512));
-#else
- outb(com->esp_port + ESP_CMD1, ESP_SETRXFLOW);
- outb(com->esp_port + ESP_CMD2, HIBYTE(768));
- outb(com->esp_port + ESP_CMD2, LOBYTE(768));
- outb(com->esp_port + ESP_CMD2, HIBYTE(512));
- outb(com->esp_port + ESP_CMD2, LOBYTE(512));
-#endif
-
-#ifdef PC98
- /* Set UART clock prescaler. */
- outb(com->esp_port + ESP98_CMD1, ESP_SETCLOCK);
- outb(com->esp_port + ESP98_CMD2, 2); /* 4 times */
-#endif
- }
-#endif /* COM_ESP */
- sio_setreg(com, com_fifo, 0);
-#ifdef PC98
- printf("%s", if_16550a_type[com->pc98_if_type & 0x0f].name);
-#else
-determined_type: ;
-#endif
-
-#ifdef COM_MULTIPORT
- if (COM_ISMULTIPORT(flags)) {
- device_t masterdev;
-
- com->multiport = TRUE;
- printf(" (multiport");
- if (unit == COM_MPMASTER(flags))
- printf(" master");
- printf(")");
- masterdev = devclass_get_device(sio_devclass,
- COM_MPMASTER(flags));
- com->no_irq = (masterdev == NULL || bus_get_resource(masterdev,
- SYS_RES_IRQ, 0, NULL, NULL) != 0);
- }
-#endif /* COM_MULTIPORT */
-#ifdef PC98
- }
-#endif
- if (unit == comconsole)
- printf(", console");
- if (COM_IIR_TXRDYBUG(flags))
- printf(" with a bogus IIR_TXRDY register");
- printf("\n");
-
- if (sio_fast_ih == NULL) {
- swi_add(&tty_ithd, "tty:sio", siopoll, NULL, SWI_TTY, 0,
- &sio_fast_ih);
- swi_add(&clk_ithd, "tty:sio", siopoll, NULL, SWI_TTY, 0,
- &sio_slow_ih);
- }
- minorbase = UNIT_TO_MINOR(unit);
- com->devs[0] = make_dev(&sio_cdevsw, minorbase,
- UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit);
- com->devs[1] = make_dev(&sio_cdevsw, minorbase | CONTROL_INIT_STATE,
- UID_ROOT, GID_WHEEL, 0600, "ttyid%r", unit);
- com->devs[2] = make_dev(&sio_cdevsw, minorbase | CONTROL_LOCK_STATE,
- UID_ROOT, GID_WHEEL, 0600, "ttyld%r", unit);
- com->devs[3] = make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK,
- UID_UUCP, GID_DIALER, 0660, "cuaa%r", unit);
- com->devs[4] = make_dev(&sio_cdevsw,
- minorbase | CALLOUT_MASK | CONTROL_INIT_STATE,
- UID_UUCP, GID_DIALER, 0660, "cuaia%r", unit);
- com->devs[5] = make_dev(&sio_cdevsw,
- minorbase | CALLOUT_MASK | CONTROL_LOCK_STATE,
- UID_UUCP, GID_DIALER, 0660, "cuala%r", unit);
- for (rid = 0; rid < 6; rid++)
- com->devs[rid]->si_drv1 = com;
- com->flags = flags;
- com->pps.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
-
- if (COM_PPSCTS(flags))
- com->pps_bit = MSR_CTS;
- else
- com->pps_bit = MSR_DCD;
- pps_init(&com->pps);
-
- rid = 0;
- com->irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0ul, ~0ul, 1,
- RF_ACTIVE);
- if (com->irqres) {
- ret = BUS_SETUP_INTR(device_get_parent(dev), dev, com->irqres,
- INTR_TYPE_TTY | INTR_FAST,
- siointr, com, &com->cookie);
- if (ret) {
- ret = BUS_SETUP_INTR(device_get_parent(dev), dev,
- com->irqres, INTR_TYPE_TTY,
- siointr, com, &com->cookie);
- if (ret == 0)
- device_printf(dev, "unable to activate interrupt in fast mode - using normal mode\n");
- }
- if (ret)
- device_printf(dev, "could not activate interrupt\n");
-#if defined(DDB) && (defined(BREAK_TO_DEBUGGER) || \
- defined(ALT_BREAK_TO_DEBUGGER))
- /*
- * Enable interrupts for early break-to-debugger support
- * on the console.
- */
- if (ret == 0 && unit == comconsole)
- outb(siocniobase + com_ier, IER_ERXRDY | IER_ERLS |
- IER_EMSC);
-#endif
- }
-
- return (0);
-}
-
-static int
-sioopen(dev, flag, mode, td)
- dev_t dev;
- int flag;
- int mode;
- struct thread *td;
-{
- struct com_s *com;
- int error;
- int mynor;
- int s;
- struct tty *tp;
- int unit;
-
- mynor = minor(dev);
- unit = MINOR_TO_UNIT(mynor);
- com = com_addr(unit);
- if (com == NULL)
- return (ENXIO);
- if (com->gone)
- return (ENXIO);
- if (mynor & CONTROL_MASK)
- return (0);
- tp = dev->si_tty = com->tp = ttymalloc(com->tp);
- s = spltty();
- /*
- * We jump to this label after all non-interrupted sleeps to pick
- * up any changes of the device state.
- */
-open_top:
- while (com->state & CS_DTR_OFF) {
- error = tsleep(&com->dtr_wait, TTIPRI | PCATCH, "siodtr", 0);
- if (com_addr(unit) == NULL)
- return (ENXIO);
- if (error != 0 || com->gone)
- goto out;
- }
- if (tp->t_state & TS_ISOPEN) {
- /*
- * The device is open, so everything has been initialized.
- * Handle conflicts.
- */
- if (mynor & CALLOUT_MASK) {
- if (!com->active_out) {
- error = EBUSY;
- goto out;
- }
- } else {
- if (com->active_out) {
- if (flag & O_NONBLOCK) {
- error = EBUSY;
- goto out;
- }
- error = tsleep(&com->active_out,
- TTIPRI | PCATCH, "siobi", 0);
- if (com_addr(unit) == NULL)
- return (ENXIO);
- if (error != 0 || com->gone)
- goto out;
- goto open_top;
- }
- }
- if (tp->t_state & TS_XCLUDE &&
- suser(td)) {
- error = EBUSY;
- goto out;
- }
- } else {
- /*
- * The device isn't open, so there are no conflicts.
- * Initialize it. Initialization is done twice in many
- * cases: to preempt sleeping callin opens if we are
- * callout, and to complete a callin open after DCD rises.
- */
- tp->t_oproc = comstart;
- tp->t_param = comparam;
- tp->t_stop = comstop;
- tp->t_dev = dev;
- tp->t_termios = mynor & CALLOUT_MASK
- ? com->it_out : com->it_in;
-#ifdef PC98
- if (!IS_8251(com->pc98_if_type))
-#endif
- (void)commctl(com, TIOCM_DTR | TIOCM_RTS, DMSET);
- com->poll = com->no_irq;
- com->poll_output = com->loses_outints;
- ++com->wopeners;
- error = comparam(tp, &tp->t_termios);
- --com->wopeners;
- if (error != 0)
- goto out;
-#ifdef PC98
- if (IS_8251(com->pc98_if_type)) {
- com_tiocm_bis(com, TIOCM_DTR|TIOCM_RTS);
- pc98_msrint_start(dev);
- if (com->pc98_8251fifo) {
- com->pc98_8251fifo_enable = 1;
- outb(I8251F_fcr, CTRL8251F_ENABLE |
- CTRL8251F_XMT_RST | CTRL8251F_RCV_RST);
- }
- }
-#endif
- /*
- * XXX we should goto open_top if comparam() slept.
- */
- if (com->hasfifo) {
- int i;
- /*
- * (Re)enable and drain fifos.
- *
- * Certain SMC chips cause problems if the fifos
- * are enabled while input is ready. Turn off the
- * fifo if necessary to clear the input. We test
- * the input ready bit after enabling the fifos
- * since we've already enabled them in comparam()
- * and to handle races between enabling and fresh
- * input.
- */
- for (i = 0; i < 500; i++) {
- sio_setreg(com, com_fifo,
- FIFO_RCV_RST | FIFO_XMT_RST
- | com->fifo_image);
-#ifdef PC98
- if (com->pc98_if_type == COM_IF_RSA98III)
- outb(com->rsabase + rsa_frr , 0x00);
-#endif
- /*
- * XXX the delays are for superstitious
- * historical reasons. It must be less than
- * the character time at the maximum
- * supported speed (87 usec at 115200 bps
- * 8N1). Otherwise we might loop endlessly
- * if data is streaming in. We used to use
- * delays of 100. That usually worked
- * because DELAY(100) used to usually delay
- * for about 85 usec instead of 100.
- */
- DELAY(50);
-#ifdef PC98
- if (com->pc98_if_type == COM_IF_RSA98III ?
- !(inb(com->rsabase + rsa_srr) & 0x08) :
- !(inb(com->line_status_port) & LSR_RXRDY))
- break;
-#else
- if (!(inb(com->line_status_port) & LSR_RXRDY))
- break;
-#endif
- sio_setreg(com, com_fifo, 0);
- DELAY(50);
- (void) inb(com->data_port);
- }
- if (i == 500) {
- error = EIO;
- goto out;
- }
- }
-
- mtx_lock_spin(&sio_lock);
-#ifdef PC98
- if (IS_8251(com->pc98_if_type)) {
- com_tiocm_bis(com, TIOCM_LE);
- com->pc98_prev_modem_status = pc98_get_modem_status(com);
- com_int_Rx_enable(com);
- } else {
-#endif
- (void) inb(com->line_status_port);
- (void) inb(com->data_port);
- com->prev_modem_status = com->last_modem_status
- = inb(com->modem_status_port);
- if (COM_IIR_TXRDYBUG(com->flags)) {
- outb(com->intr_ctl_port, IER_ERXRDY | IER_ERLS
- | IER_EMSC);
- } else {
- outb(com->intr_ctl_port, IER_ERXRDY | IER_ETXRDY
- | IER_ERLS | IER_EMSC);
- }
-#ifdef PC98
- if (com->pc98_if_type == COM_IF_RSA98III) {
- outb(com->rsabase + rsa_ier, 0x1d);
- outb(com->intr_ctl_port, IER_ERLS | IER_EMSC);
- }
-#endif
-#ifdef PC98
- }
-#endif
- mtx_unlock_spin(&sio_lock);
- /*
- * Handle initial DCD. Callout devices get a fake initial
- * DCD (trapdoor DCD). If we are callout, then any sleeping
- * callin opens get woken up and resume sleeping on "siobi"
- * instead of "siodcd".
- */
- /*
- * XXX `mynor & CALLOUT_MASK' should be
- * `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where
- * TRAPDOOR_CARRIER is the default initial state for callout
- * devices and SOFT_CARRIER is like CLOCAL except it hides
- * the true carrier.
- */
-#ifdef PC98
- if ((IS_8251(com->pc98_if_type) &&
- (pc98_get_modem_status(com) & TIOCM_CAR)) ||
- (!IS_8251(com->pc98_if_type) &&
- (com->prev_modem_status & MSR_DCD)) ||
- mynor & CALLOUT_MASK)
- (*linesw[tp->t_line].l_modem)(tp, 1);
-#else
- if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK)
- (*linesw[tp->t_line].l_modem)(tp, 1);
-#endif
- }
- /*
- * Wait for DCD if necessary.
- */
- if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
- && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
- ++com->wopeners;
- error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "siodcd", 0);
- if (com_addr(unit) == NULL)
- return (ENXIO);
- --com->wopeners;
- if (error != 0 || com->gone)
- goto out;
- goto open_top;
- }
- error = (*linesw[tp->t_line].l_open)(dev, tp);
- disc_optim(tp, &tp->t_termios, com);
- if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
- com->active_out = TRUE;
- siosettimeout();
-out:
- splx(s);
- if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
- comhardclose(com);
- return (error);
-}
-
-static int
-sioclose(dev, flag, mode, td)
- dev_t dev;
- int flag;
- int mode;
- struct thread *td;
-{
- struct com_s *com;
- int mynor;
- int s;
- struct tty *tp;
-
- mynor = minor(dev);
- if (mynor & CONTROL_MASK)
- return (0);
- com = com_addr(MINOR_TO_UNIT(mynor));
- if (com == NULL)
- return (ENODEV);
- tp = com->tp;
- s = spltty();
- (*linesw[tp->t_line].l_close)(tp, flag);
-#ifdef PC98
- com->modem_checking = 0;
-#endif
- disc_optim(tp, &tp->t_termios, com);
- comstop(tp, FREAD | FWRITE);
- comhardclose(com);
- ttyclose(tp);
- siosettimeout();
- splx(s);
- if (com->gone) {
- printf("sio%d: gone\n", com->unit);
- s = spltty();
- if (com->ibuf != NULL)
- free(com->ibuf, M_DEVBUF);
- bzero(tp, sizeof *tp);
- splx(s);
- }
- return (0);
-}
-
-static void
-comhardclose(com)
- struct com_s *com;
-{
- int s;
- struct tty *tp;
- int unit;
-
- unit = com->unit;
- s = spltty();
- com->poll = FALSE;
- com->poll_output = FALSE;
- com->do_timestamp = FALSE;
- com->do_dcd_timestamp = FALSE;
- com->pps.ppsparam.mode = 0;
-#ifdef PC98
- if (IS_8251(com->pc98_if_type))
- com_send_break_off(com);
- else
-#endif
- sio_setreg(com, com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
- tp = com->tp;
-
-#if defined(DDB) && (defined(BREAK_TO_DEBUGGER) || \
- defined(ALT_BREAK_TO_DEBUGGER))
- /*
- * Leave interrupts enabled and don't clear DTR if this is the
- * console. This allows us to detect break-to-debugger events
- * while the console device is closed.
- */
- if (com->unit != comconsole)
-#endif
- {
-#ifdef PC98
- int tmp;
- if (IS_8251(com->pc98_if_type))
- com_int_TxRx_disable(com);
- else
- sio_setreg(com, com_ier, 0);
- if (com->pc98_if_type == COM_IF_RSA98III)
- outb(com->rsabase + rsa_ier, 0x00);
- if (IS_8251(com->pc98_if_type))
- tmp = pc98_get_modem_status(com) & TIOCM_CAR;
- else
- tmp = com->prev_modem_status & MSR_DCD;
-#else
- sio_setreg(com, com_ier, 0);
-#endif
- if (tp->t_cflag & HUPCL
- /*
- * XXX we will miss any carrier drop between here and the
- * next open. Perhaps we should watch DCD even when the
- * port is closed; it is not sufficient to check it at
- * the next open because it might go up and down while
- * we're not watching.
- */
- || (!com->active_out
-#ifdef PC98
- && !(tmp)
-#else
- && !(com->prev_modem_status & MSR_DCD)
-#endif
- && !(com->it_in.c_cflag & CLOCAL))
- || !(tp->t_state & TS_ISOPEN)) {
-#ifdef PC98
- if (IS_8251(com->pc98_if_type))
- com_tiocm_bic(com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE);
- else
-#endif
- (void)commctl(com, TIOCM_DTR, DMBIC);
- if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) {
- timeout(siodtrwakeup, com, com->dtr_wait);
- com->state |= CS_DTR_OFF;
- }
- }
-#ifdef PC98
- else {
- if (IS_8251(com->pc98_if_type))
- com_tiocm_bic(com, TIOCM_LE);
- }
-#endif
- }
-#ifdef PC98
- if (com->pc98_8251fifo) {
- if (com->pc98_8251fifo_enable)
- outb(I8251F_fcr, CTRL8251F_XMT_RST | CTRL8251F_RCV_RST);
- com->pc98_8251fifo_enable = 0;
- }
-#endif
- if (com->hasfifo) {
- /*
- * Disable fifos so that they are off after controlled
- * reboots. Some BIOSes fail to detect 16550s when the
- * fifos are enabled.
- */
- sio_setreg(com, com_fifo, 0);
- }
- com->active_out = FALSE;
- wakeup(&com->active_out);
- wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
- splx(s);
-}
-
-static int
-sioread(dev, uio, flag)
- dev_t dev;
- struct uio *uio;
- int flag;
-{
- int mynor;
- struct com_s *com;
-
- mynor = minor(dev);
- if (mynor & CONTROL_MASK)
- return (ENODEV);
- com = com_addr(MINOR_TO_UNIT(mynor));
- if (com == NULL || com->gone)
- return (ENODEV);
- return ((*linesw[com->tp->t_line].l_read)(com->tp, uio, flag));
-}
-
-static int
-siowrite(dev, uio, flag)
- dev_t dev;
- struct uio *uio;
- int flag;
-{
- int mynor;
- struct com_s *com;
- int unit;
-
- mynor = minor(dev);
- if (mynor & CONTROL_MASK)
- return (ENODEV);
-
- unit = MINOR_TO_UNIT(mynor);
- com = com_addr(unit);
- if (com == NULL || com->gone)
- return (ENODEV);
- /*
- * (XXX) We disallow virtual consoles if the physical console is
- * a serial port. This is in case there is a display attached that
- * is not the console. In that situation we don't need/want the X
- * server taking over the console.
- */
- if (constty != NULL && unit == comconsole)
- constty = NULL;
- return ((*linesw[com->tp->t_line].l_write)(com->tp, uio, flag));
-}
-
-static void
-siobusycheck(chan)
- void *chan;
-{
- struct com_s *com;
- int s;
-
- com = (struct com_s *)chan;
-
- /*
- * Clear TS_BUSY if low-level output is complete.
- * spl locking is sufficient because siointr1() does not set CS_BUSY.
- * If siointr1() clears CS_BUSY after we look at it, then we'll get
- * called again. Reading the line status port outside of siointr1()
- * is safe because CS_BUSY is clear so there are no output interrupts
- * to lose.
- */
- s = spltty();
- if (com->state & CS_BUSY)
- com->extra_state &= ~CSE_BUSYCHECK; /* False alarm. */
-#ifdef PC98
- else if ((IS_8251(com->pc98_if_type) &&
- ((com->pc98_8251fifo_enable &&
- (inb(I8251F_lsr) & (STS8251F_TxRDY | STS8251F_TxEMP))
- == (STS8251F_TxRDY | STS8251F_TxEMP)) ||
- (!com->pc98_8251fifo_enable &&
- (inb(com->sts_port) & (STS8251_TxRDY | STS8251_TxEMP))
- == (STS8251_TxRDY | STS8251_TxEMP)))) ||
- ((inb(com->line_status_port) & (LSR_TSRE | LSR_TXRDY))
- == (LSR_TSRE | LSR_TXRDY))) {
-#else
- else if ((inb(com->line_status_port) & (LSR_TSRE | LSR_TXRDY))
- == (LSR_TSRE | LSR_TXRDY)) {
-#endif
- com->tp->t_state &= ~TS_BUSY;
- ttwwakeup(com->tp);
- com->extra_state &= ~CSE_BUSYCHECK;
- } else
- timeout(siobusycheck, com, hz / 100);
- splx(s);
-}
-
-static u_int
-siodivisor(rclk, speed)
- u_long rclk;
- speed_t speed;
-{
- long actual_speed;
- u_int divisor;
- int error;
-
- if (speed == 0 || speed > (ULONG_MAX - 1) / 8)
- return (0);
- divisor = (rclk / (8UL * speed) + 1) / 2;
- if (divisor == 0 || divisor >= 65536)
- return (0);
- actual_speed = rclk / (16UL * divisor);
-
- /* 10 times error in percent: */
- error = ((actual_speed - (long)speed) * 2000 / (long)speed + 1) / 2;
-
- /* 3.0% maximum error tolerance: */
- if (error < -30 || error > 30)
- return (0);
-
- return (divisor);
-}
-
-static void
-siodtrwakeup(chan)
- void *chan;
-{
- struct com_s *com;
-
- com = (struct com_s *)chan;
- com->state &= ~CS_DTR_OFF;
- wakeup(&com->dtr_wait);
-}
-
-/*
- * Call this function with the sio_lock mutex held. It will return with the
- * lock still held.
- */
-static void
-sioinput(com)
- struct com_s *com;
-{
- u_char *buf;
- int incc;
- u_char line_status;
- int recv_data;
- struct tty *tp;
-
- buf = com->ibuf;
- tp = com->tp;
- if (!(tp->t_state & TS_ISOPEN) || !(tp->t_cflag & CREAD)) {
- com_events -= (com->iptr - com->ibuf);
- com->iptr = com->ibuf;
- return;
- }
- if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
- /*
- * Avoid the grotesquely inefficient lineswitch routine
- * (ttyinput) in "raw" mode. It usually takes about 450
- * instructions (that's without canonical processing or echo!).
- * slinput is reasonably fast (usually 40 instructions plus
- * call overhead).
- */
- do {
- /*
- * This may look odd, but it is using save-and-enable
- * semantics instead of the save-and-disable semantics
- * that are used everywhere else.
- */
- mtx_unlock_spin(&sio_lock);
- incc = com->iptr - buf;
- if (tp->t_rawq.c_cc + incc > tp->t_ihiwat
- && (com->state & CS_RTS_IFLOW
- || tp->t_iflag & IXOFF)
- && !(tp->t_state & TS_TBLOCK))
- ttyblock(tp);
- com->delta_error_counts[CE_TTY_BUF_OVERFLOW]
- += b_to_q((char *)buf, incc, &tp->t_rawq);
- buf += incc;
- tk_nin += incc;
- tk_rawcc += incc;
- tp->t_rawcc += incc;
- ttwakeup(tp);
- if (tp->t_state & TS_TTSTOP
- && (tp->t_iflag & IXANY
- || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
- tp->t_state &= ~TS_TTSTOP;
- tp->t_lflag &= ~FLUSHO;
- comstart(tp);
- }
- mtx_lock_spin(&sio_lock);
- } while (buf < com->iptr);
- } else {
- do {
- /*
- * This may look odd, but it is using save-and-enable
- * semantics instead of the save-and-disable semantics
- * that are used everywhere else.
- */
- mtx_unlock_spin(&sio_lock);
- line_status = buf[com->ierroff];
- recv_data = *buf++;
- if (line_status
- & (LSR_BI | LSR_FE | LSR_OE | LSR_PE)) {
- if (line_status & LSR_BI)
- recv_data |= TTY_BI;
- if (line_status & LSR_FE)
- recv_data |= TTY_FE;
- if (line_status & LSR_OE)
- recv_data |= TTY_OE;
- if (line_status & LSR_PE)
- recv_data |= TTY_PE;
- }
- (*linesw[tp->t_line].l_rint)(recv_data, tp);
- mtx_lock_spin(&sio_lock);
- } while (buf < com->iptr);
- }
- com_events -= (com->iptr - com->ibuf);
- com->iptr = com->ibuf;
-
- /*
- * There is now room for another low-level buffer full of input,
- * so enable RTS if it is now disabled and there is room in the
- * high-level buffer.
- */
-#ifdef PC98
- if (IS_8251(com->pc98_if_type)) {
- if ((com->state & CS_RTS_IFLOW) &&
- !(com_tiocm_get(com) & TIOCM_RTS) &&
- !(tp->t_state & TS_TBLOCK))
- com_tiocm_bis(com, TIOCM_RTS);
- } else {
- if ((com->state & CS_RTS_IFLOW) &&
- !(com->mcr_image & MCR_RTS) &&
- !(tp->t_state & TS_TBLOCK))
- outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
- }
-#else
- if ((com->state & CS_RTS_IFLOW) && !(com->mcr_image & MCR_RTS) &&
- !(tp->t_state & TS_TBLOCK))
- outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
-#endif
-}
-
-static void
-siointr(arg)
- void *arg;
-{
- struct com_s *com;
-#if defined(PC98) && defined(COM_MULTIPORT)
- u_char rsa_buf_status;
-#endif
-
-#ifndef COM_MULTIPORT
- com = (struct com_s *)arg;
-
- mtx_lock_spin(&sio_lock);
- siointr1(com);
- mtx_unlock_spin(&sio_lock);
-#else /* COM_MULTIPORT */
- bool_t possibly_more_intrs;
- int unit;
-
- /*
- * Loop until there is no activity on any port. This is necessary
- * to get an interrupt edge more than to avoid another interrupt.
- * If the IRQ signal is just an OR of the IRQ signals from several
- * devices, then the edge from one may be lost because another is
- * on.
- */
- mtx_lock_spin(&sio_lock);
- do {
- possibly_more_intrs = FALSE;
- for (unit = 0; unit < sio_numunits; ++unit) {
- com = com_addr(unit);
- /*
- * XXX COM_LOCK();
- * would it work here, or be counter-productive?
- */
-#ifdef PC98
- if (com != NULL
- && !com->gone
- && IS_8251(com->pc98_if_type)) {
- siointr1(com);
- } else if (com != NULL
- && !com->gone
- && com->pc98_if_type == COM_IF_RSA98III) {
- rsa_buf_status =
- inb(com->rsabase + rsa_srr) & 0xc9;
- if ((rsa_buf_status & 0xc8)
- || !(rsa_buf_status & 0x01)) {
- siointr1(com);
- if (rsa_buf_status !=
- (inb(com->rsabase + rsa_srr) & 0xc9))
- possibly_more_intrs = TRUE;
- }
- } else
-#endif
- if (com != NULL
- && !com->gone
- && (inb(com->int_id_port) & IIR_IMASK)
- != IIR_NOPEND) {
- siointr1(com);
- possibly_more_intrs = TRUE;
- }
- /* XXX COM_UNLOCK(); */
- }
- } while (possibly_more_intrs);
- mtx_unlock_spin(&sio_lock);
-#endif /* COM_MULTIPORT */
-}
-
-static struct timespec siots[8192];
-static int siotso;
-static int volatile siotsunit = -1;
-
-static int
-sysctl_siots(SYSCTL_HANDLER_ARGS)
-{
- char buf[128];
- long long delta;
- size_t len;
- int error, i;
-
- for (i = 1; i < siotso; i++) {
- delta = (long long)(siots[i].tv_sec - siots[i - 1].tv_sec) *
- 1000000000 +
- (siots[i].tv_nsec - siots[i - 1].tv_nsec);
- len = sprintf(buf, "%lld\n", delta);
- if (delta >= 110000)
- len += sprintf(buf + len - 1, ": *** %ld.%09ld\n",
- (long)siots[i].tv_sec, siots[i].tv_nsec);
- if (i == siotso - 1)
- buf[len - 1] = '\0';
- error = SYSCTL_OUT(req, buf, len);
- if (error != 0)
- return (error);
- uio_yield();
- }
- return (0);
-}
-
-SYSCTL_PROC(_machdep, OID_AUTO, siots, CTLTYPE_STRING | CTLFLAG_RD,
- 0, 0, sysctl_siots, "A", "sio timestamps");
-
-static void
-siointr1(com)
- struct com_s *com;
-{
- u_char line_status;
- u_char modem_status;
- u_char *ioptr;
- u_char recv_data;
- u_char int_ctl;
- u_char int_ctl_new;
-
-#ifdef PC98
- u_char tmp = 0;
- u_char rsa_buf_status = 0;
- int rsa_tx_fifo_size = 0;
-#endif /* PC98 */
-
- int_ctl = inb(com->intr_ctl_port);
- int_ctl_new = int_ctl;
-
- while (!com->gone) {
-#ifdef PC98
-status_read:;
- if (IS_8251(com->pc98_if_type)) {
- if (com->pc98_8251fifo_enable)
- tmp = inb(I8251F_lsr);
- else
- tmp = inb(com->sts_port);
-more_intr:
- line_status = 0;
- if (com->pc98_8251fifo_enable) {
- if (tmp & STS8251F_TxRDY) line_status |= LSR_TXRDY;
- if (tmp & STS8251F_RxRDY) line_status |= LSR_RXRDY;
- if (tmp & STS8251F_TxEMP) line_status |= LSR_TSRE;
- if (tmp & STS8251F_PE) line_status |= LSR_PE;
- if (tmp & STS8251F_OE) line_status |= LSR_OE;
- if (tmp & STS8251F_BD_SD) line_status |= LSR_BI;
- } else {
- if (tmp & STS8251_TxRDY) line_status |= LSR_TXRDY;
- if (tmp & STS8251_RxRDY) line_status |= LSR_RXRDY;
- if (tmp & STS8251_TxEMP) line_status |= LSR_TSRE;
- if (tmp & STS8251_PE) line_status |= LSR_PE;
- if (tmp & STS8251_OE) line_status |= LSR_OE;
- if (tmp & STS8251_FE) line_status |= LSR_FE;
- if (tmp & STS8251_BD_SD) line_status |= LSR_BI;
- }
- } else {
-#endif /* PC98 */
- if (com->pps.ppsparam.mode & PPS_CAPTUREBOTH) {
- modem_status = inb(com->modem_status_port);
- if ((modem_status ^ com->last_modem_status) &
- com->pps_bit) {
- pps_capture(&com->pps);
- pps_event(&com->pps,
- (modem_status & com->pps_bit) ?
- PPS_CAPTUREASSERT : PPS_CAPTURECLEAR);
- }
- }
- line_status = inb(com->line_status_port);
-#ifdef PC98
- }
- if (com->pc98_if_type == COM_IF_RSA98III)
- rsa_buf_status = inb(com->rsabase + rsa_srr);
-#endif /* PC98 */
-
- /* input event? (check first to help avoid overruns) */
-#ifndef PC98
- while (line_status & LSR_RCV_MASK) {
-#else
- while ((line_status & LSR_RCV_MASK)
- || (com->pc98_if_type == COM_IF_RSA98III
- && (rsa_buf_status & 0x08))) {
-#endif /* PC98 */
- /* break/unnattached error bits or real input? */
-#ifdef PC98
- if (IS_8251(com->pc98_if_type)) {
- if (com->pc98_8251fifo_enable) {
- recv_data = inb(I8251F_data);
- if (tmp & (STS8251F_PE | STS8251F_OE |
- STS8251F_BD_SD)) {
- pc98_i8251_or_cmd(com, CMD8251_ER);
- recv_data = 0;
- }
- } else {
- recv_data = inb(com->data_port);
- if (tmp & (STS8251_PE | STS8251_OE |
- STS8251_FE | STS8251_BD_SD)) {
- pc98_i8251_or_cmd(com, CMD8251_ER);
- recv_data = 0;
- }
- }
- } else if (com->pc98_if_type == COM_IF_RSA98III) {
- if (!(rsa_buf_status & 0x08))
- recv_data = 0;
- else
- recv_data = inb(com->data_port);
- } else
-#endif
- if (!(line_status & LSR_RXRDY))
- recv_data = 0;
- else
- recv_data = inb(com->data_port);
-#if defined(DDB) && defined(ALT_BREAK_TO_DEBUGGER)
- /*
- * Solaris implements a new BREAK which is initiated
- * by a character sequence CR ~ ^b which is similar
- * to a familiar pattern used on Sun servers by the
- * Remote Console.
- */
-#define KEY_CRTLB 2 /* ^B */
-#define KEY_CR 13 /* CR '\r' */
-#define KEY_TILDE 126 /* ~ */
-
- if (com->unit == comconsole) {
- static int brk_state1 = 0, brk_state2 = 0;
- if (recv_data == KEY_CR) {
- brk_state1 = recv_data;
- brk_state2 = 0;
- } else if (brk_state1 == KEY_CR && (recv_data == KEY_TILDE || recv_data == KEY_CRTLB)) {
- if (recv_data == KEY_TILDE)
- brk_state2 = recv_data;
- else if (brk_state2 == KEY_TILDE && recv_data == KEY_CRTLB) {
- breakpoint();
- brk_state1 = brk_state2 = 0;
- goto cont;
- } else
- brk_state2 = 0;
- } else
- brk_state1 = 0;
- }
-#endif
- if (line_status & (LSR_BI | LSR_FE | LSR_PE)) {
- /*
- * Don't store BI if IGNBRK or FE/PE if IGNPAR.
- * Otherwise, push the work to a higher level
- * (to handle PARMRK) if we're bypassing.
- * Otherwise, convert BI/FE and PE+INPCK to 0.
- *
- * This makes bypassing work right in the
- * usual "raw" case (IGNBRK set, and IGNPAR
- * and INPCK clear).
- *
- * Note: BI together with FE/PE means just BI.
- */
- if (line_status & LSR_BI) {
-#if defined(DDB) && defined(BREAK_TO_DEBUGGER)
- if (com->unit == comconsole) {
- breakpoint();
- goto cont;
- }
-#endif
- if (com->tp == NULL
- || com->tp->t_iflag & IGNBRK)
- goto cont;
- } else {
- if (com->tp == NULL
- || com->tp->t_iflag & IGNPAR)
- goto cont;
- }
- if (com->tp->t_state & TS_CAN_BYPASS_L_RINT
- && (line_status & (LSR_BI | LSR_FE)
- || com->tp->t_iflag & INPCK))
- recv_data = 0;
- }
- ++com->bytes_in;
- if (com->hotchar != 0 && recv_data == com->hotchar)
- swi_sched(sio_fast_ih, 0);
- ioptr = com->iptr;
- if (ioptr >= com->ibufend)
- CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW);
- else {
- if (com->do_timestamp)
- microtime(&com->timestamp);
- ++com_events;
- swi_sched(sio_slow_ih, SWI_DELAY);
-#if 0 /* for testing input latency vs efficiency */
-if (com->iptr - com->ibuf == 8)
- swi_sched(sio_fast_ih, 0);
-#endif
- ioptr[0] = recv_data;
- ioptr[com->ierroff] = line_status;
- com->iptr = ++ioptr;
- if (ioptr == com->ihighwater
- && com->state & CS_RTS_IFLOW)
-#ifdef PC98
- IS_8251(com->pc98_if_type) ?
- com_tiocm_bic(com, TIOCM_RTS) :
-#endif
- outb(com->modem_ctl_port,
- com->mcr_image &= ~MCR_RTS);
- if (line_status & LSR_OE)
- CE_RECORD(com, CE_OVERRUN);
- }
-cont:
- /*
- * "& 0x7F" is to avoid the gcc-1.40 generating a slow
- * jump from the top of the loop to here
- */
-#ifdef PC98
- if (IS_8251(com->pc98_if_type))
- goto status_read;
- else
-#endif
- line_status = inb(com->line_status_port) & 0x7F;
-#ifdef PC98
- if (com->pc98_if_type == COM_IF_RSA98III)
- rsa_buf_status = inb(com->rsabase + rsa_srr);
-#endif /* PC98 */
- }
-
- /* modem status change? (always check before doing output) */
-#ifdef PC98
- if (!IS_8251(com->pc98_if_type)) {
-#endif
- modem_status = inb(com->modem_status_port);
- if (modem_status != com->last_modem_status) {
- if (com->do_dcd_timestamp
- && !(com->last_modem_status & MSR_DCD)
- && modem_status & MSR_DCD)
- microtime(&com->dcd_timestamp);
-
- /*
- * Schedule high level to handle DCD changes. Note
- * that we don't use the delta bits anywhere. Some
- * UARTs mess them up, and it's easy to remember the
- * previous bits and calculate the delta.
- */
- com->last_modem_status = modem_status;
- if (!(com->state & CS_CHECKMSR)) {
- com_events += LOTS_OF_EVENTS;
- com->state |= CS_CHECKMSR;
- swi_sched(sio_fast_ih, 0);
- }
-
- /* handle CTS change immediately for crisp flow ctl */
- if (com->state & CS_CTS_OFLOW) {
- if (modem_status & MSR_CTS)
- com->state |= CS_ODEVREADY;
- else
- com->state &= ~CS_ODEVREADY;
- }
- }
-#ifdef PC98
- }
-#endif
-
- /* output queued and everything ready? */
-#ifndef PC98
- if (line_status & LSR_TXRDY
- && com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
-#else
- if (((com->pc98_if_type == COM_IF_RSA98III)
- ? (rsa_buf_status & 0x02)
- : (line_status & LSR_TXRDY))
- && com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
-#endif
-#ifdef PC98
- Port_t tmp_data_port;
-
- if (IS_8251(com->pc98_if_type) &&
- com->pc98_8251fifo_enable)
- tmp_data_port = I8251F_data;
- else
- tmp_data_port = com->data_port;
-#endif
-
- ioptr = com->obufq.l_head;
- if (com->tx_fifo_size > 1 && com->unit != siotsunit) {
- u_int ocount;
-
- ocount = com->obufq.l_tail - ioptr;
-#ifdef PC98
- if (com->pc98_if_type == COM_IF_RSA98III) {
- rsa_buf_status = inb(com->rsabase + rsa_srr);
- rsa_tx_fifo_size = 1024;
- if (!(rsa_buf_status & 0x01))
- rsa_tx_fifo_size = 2048;
- if (ocount > rsa_tx_fifo_size)
- ocount = rsa_tx_fifo_size;
- } else
-#endif
- if (ocount > com->tx_fifo_size)
- ocount = com->tx_fifo_size;
- com->bytes_out += ocount;
- do
-#ifdef PC98
- outb(tmp_data_port, *ioptr++);
-#else
- outb(com->data_port, *ioptr++);
-#endif
- while (--ocount != 0);
- } else {
-#ifdef PC98
- outb(tmp_data_port, *ioptr++);
-#else
- outb(com->data_port, *ioptr++);
-#endif
- ++com->bytes_out;
- if (com->unit == siotsunit) {
- nanouptime(&siots[siotso]);
- siotso = (siotso + 1) %
- (sizeof siots / sizeof siots[0]);
- }
- }
-#ifdef PC98
- if (IS_8251(com->pc98_if_type))
- if (!(pc98_check_i8251_interrupt(com) & IEN_TxFLAG))
- com_int_Tx_enable(com);
-#endif
- com->obufq.l_head = ioptr;
- if (COM_IIR_TXRDYBUG(com->flags)) {
- int_ctl_new = int_ctl | IER_ETXRDY;
- }
- if (ioptr >= com->obufq.l_tail) {
- struct lbq *qp;
-
- qp = com->obufq.l_next;
- qp->l_queued = FALSE;
- qp = qp->l_next;
- if (qp != NULL) {
- com->obufq.l_head = qp->l_head;
- com->obufq.l_tail = qp->l_tail;
- com->obufq.l_next = qp;
- } else {
- /* output just completed */
- if (COM_IIR_TXRDYBUG(com->flags)) {
- int_ctl_new = int_ctl & ~IER_ETXRDY;
- }
- com->state &= ~CS_BUSY;
-#if defined(PC98)
- if (IS_8251(com->pc98_if_type) &&
- pc98_check_i8251_interrupt(com) & IEN_TxFLAG)
- com_int_Tx_disable(com);
-#endif
- }
- if (!(com->state & CS_ODONE)) {
- com_events += LOTS_OF_EVENTS;
- com->state |= CS_ODONE;
- /* handle at high level ASAP */
- swi_sched(sio_fast_ih, 0);
- }
- }
- if (COM_IIR_TXRDYBUG(com->flags) && (int_ctl != int_ctl_new)) {
-#ifdef PC98
- if (com->pc98_if_type == COM_IF_RSA98III) {
- int_ctl_new &= ~(IER_ETXRDY | IER_ERXRDY);
- outb(com->intr_ctl_port, int_ctl_new);
- outb(com->rsabase + rsa_ier, 0x1d);
- } else
-#endif
- outb(com->intr_ctl_port, int_ctl_new);
- }
- }
-#ifdef PC98
- else if (line_status & LSR_TXRDY) {
- if (IS_8251(com->pc98_if_type))
- if (pc98_check_i8251_interrupt(com) & IEN_TxFLAG)
- com_int_Tx_disable(com);
- }
- if (IS_8251(com->pc98_if_type)) {
- if (com->pc98_8251fifo_enable) {
- if ((tmp = inb(I8251F_lsr)) & STS8251F_RxRDY)
- goto more_intr;
- } else {
- if ((tmp = inb(com->sts_port)) & STS8251_RxRDY)
- goto more_intr;
- }
- }
-#endif
-
- /* finished? */
-#ifndef COM_MULTIPORT
-#ifdef PC98
- if (IS_8251(com->pc98_if_type))
- return;
-#endif
- if ((inb(com->int_id_port) & IIR_IMASK) == IIR_NOPEND)
-#endif /* COM_MULTIPORT */
- return;
- }
-}
-
-static int
-sioioctl(dev, cmd, data, flag, td)
- dev_t dev;
- u_long cmd;
- caddr_t data;
- int flag;
- struct thread *td;
-{
- struct com_s *com;
- int error;
- int mynor;
- int s;
- struct tty *tp;
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
- u_long oldcmd;
- struct termios term;
-#endif
-
- mynor = minor(dev);
- com = com_addr(MINOR_TO_UNIT(mynor));
- if (com == NULL || com->gone)
- return (ENODEV);
- if (mynor & CONTROL_MASK) {
- struct termios *ct;
-
- switch (mynor & CONTROL_MASK) {
- case CONTROL_INIT_STATE:
- ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in;
- break;
- case CONTROL_LOCK_STATE:
- ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in;
- break;
- default:
- return (ENODEV); /* /dev/nodev */
- }
- switch (cmd) {
- case TIOCSETA:
- error = suser(td);
- if (error != 0)
- return (error);
- *ct = *(struct termios *)data;
- return (0);
- case TIOCGETA:
- *(struct termios *)data = *ct;
- return (0);
- case TIOCGETD:
- *(int *)data = TTYDISC;
- return (0);
- case TIOCGWINSZ:
- bzero(data, sizeof(struct winsize));
- return (0);
- default:
- return (ENOTTY);
- }
- }
- tp = com->tp;
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
- term = tp->t_termios;
- oldcmd = cmd;
- error = ttsetcompat(tp, &cmd, data, &term);
- if (error != 0)
- return (error);
- if (cmd != oldcmd)
- data = (caddr_t)&term;
-#endif
- if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
- int cc;
- struct termios *dt = (struct termios *)data;
- struct termios *lt = mynor & CALLOUT_MASK
- ? &com->lt_out : &com->lt_in;
-
- dt->c_iflag = (tp->t_iflag & lt->c_iflag)
- | (dt->c_iflag & ~lt->c_iflag);
- dt->c_oflag = (tp->t_oflag & lt->c_oflag)
- | (dt->c_oflag & ~lt->c_oflag);
- dt->c_cflag = (tp->t_cflag & lt->c_cflag)
- | (dt->c_cflag & ~lt->c_cflag);
- dt->c_lflag = (tp->t_lflag & lt->c_lflag)
- | (dt->c_lflag & ~lt->c_lflag);
- for (cc = 0; cc < NCCS; ++cc)
- if (lt->c_cc[cc] != 0)
- dt->c_cc[cc] = tp->t_cc[cc];
- if (lt->c_ispeed != 0)
- dt->c_ispeed = tp->t_ispeed;
- if (lt->c_ospeed != 0)
- dt->c_ospeed = tp->t_ospeed;
- }
- error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
- if (error != ENOIOCTL)
- return (error);
- s = spltty();
- error = ttioctl(tp, cmd, data, flag);
- disc_optim(tp, &tp->t_termios, com);
- if (error != ENOIOCTL) {
- splx(s);
- return (error);
- }
-#ifdef PC98
- if (IS_8251(com->pc98_if_type)) {
- switch (cmd) {
- case TIOCSBRK:
- com_send_break_on(com);
- break;
- case TIOCCBRK:
- com_send_break_off(com);
- break;
- case TIOCSDTR:
- com_tiocm_bis(com, TIOCM_DTR | TIOCM_RTS);
- break;
- case TIOCCDTR:
- com_tiocm_bic(com, TIOCM_DTR);
- break;
- /*
- * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The
- * changes get undone on the next call to comparam().
- */
- case TIOCMSET:
- com_tiocm_set(com, *(int *)data);
- break;
- case TIOCMBIS:
- com_tiocm_bis(com, *(int *)data);
- break;
- case TIOCMBIC:
- com_tiocm_bic(com, *(int *)data);
- break;
- case TIOCMGET:
- *(int *)data = com_tiocm_get(com);
- break;
- case TIOCMSDTRWAIT:
- /* must be root since the wait applies to following logins */
- error = suser(td);
- if (error != 0) {
- splx(s);
- return (error);
- }
- com->dtr_wait = *(int *)data * hz / 100;
- break;
- case TIOCMGDTRWAIT:
- *(int *)data = com->dtr_wait * 100 / hz;
- break;
- case TIOCTIMESTAMP:
- com->do_timestamp = TRUE;
- *(struct timeval *)data = com->timestamp;
- break;
- case TIOCDCDTIMESTAMP:
- com->do_dcd_timestamp = TRUE;
- *(struct timeval *)data = com->dcd_timestamp;
- break;
- default:
- splx(s);
- error = pps_ioctl(cmd, data, &com->pps);
- if (error == ENODEV)
- error = ENOTTY;
- return (error);
- }
- } else {
-#endif
- switch (cmd) {
- case TIOCSBRK:
- sio_setreg(com, com_cfcr, com->cfcr_image |= CFCR_SBREAK);
- break;
- case TIOCCBRK:
- sio_setreg(com, com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
- break;
- case TIOCSDTR:
- (void)commctl(com, TIOCM_DTR, DMBIS);
- break;
- case TIOCCDTR:
- (void)commctl(com, TIOCM_DTR, DMBIC);
- break;
- /*
- * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The
- * changes get undone on the next call to comparam().
- */
- case TIOCMSET:
- (void)commctl(com, *(int *)data, DMSET);
- break;
- case TIOCMBIS:
- (void)commctl(com, *(int *)data, DMBIS);
- break;
- case TIOCMBIC:
- (void)commctl(com, *(int *)data, DMBIC);
- break;
- case TIOCMGET:
- *(int *)data = commctl(com, 0, DMGET);
- break;
- case TIOCMSDTRWAIT:
- /* must be root since the wait applies to following logins */
- error = suser(td);
- if (error != 0) {
- splx(s);
- return (error);
- }
- com->dtr_wait = *(int *)data * hz / 100;
- break;
- case TIOCMGDTRWAIT:
- *(int *)data = com->dtr_wait * 100 / hz;
- break;
- case TIOCTIMESTAMP:
- com->do_timestamp = TRUE;
- *(struct timeval *)data = com->timestamp;
- break;
- case TIOCDCDTIMESTAMP:
- com->do_dcd_timestamp = TRUE;
- *(struct timeval *)data = com->dcd_timestamp;
- break;
- default:
- splx(s);
- error = pps_ioctl(cmd, data, &com->pps);
- if (error == ENODEV)
- error = ENOTTY;
- return (error);
- }
-#ifdef PC98
- }
-#endif
- splx(s);
- return (0);
-}
-
-/* software interrupt handler for SWI_TTY */
-static void
-siopoll(void *dummy)
-{
- int unit;
-
- if (com_events == 0)
- return;
-repeat:
- for (unit = 0; unit < sio_numunits; ++unit) {
- struct com_s *com;
- int incc;
- struct tty *tp;
-
- com = com_addr(unit);
- if (com == NULL)
- continue;
- tp = com->tp;
- if (tp == NULL || com->gone) {
- /*
- * Discard any events related to never-opened or
- * going-away devices.
- */
- mtx_lock_spin(&sio_lock);
- incc = com->iptr - com->ibuf;
- com->iptr = com->ibuf;
- if (com->state & CS_CHECKMSR) {
- incc += LOTS_OF_EVENTS;
- com->state &= ~CS_CHECKMSR;
- }
- com_events -= incc;
- mtx_unlock_spin(&sio_lock);
- continue;
- }
- if (com->iptr != com->ibuf) {
- mtx_lock_spin(&sio_lock);
- sioinput(com);
- mtx_unlock_spin(&sio_lock);
- }
- if (com->state & CS_CHECKMSR) {
- u_char delta_modem_status;
-
-#ifdef PC98
- if (!IS_8251(com->pc98_if_type)) {
-#endif
- mtx_lock_spin(&sio_lock);
- delta_modem_status = com->last_modem_status
- ^ com->prev_modem_status;
- com->prev_modem_status = com->last_modem_status;
- com_events -= LOTS_OF_EVENTS;
- com->state &= ~CS_CHECKMSR;
- mtx_unlock_spin(&sio_lock);
- if (delta_modem_status & MSR_DCD)
- (*linesw[tp->t_line].l_modem)
- (tp, com->prev_modem_status & MSR_DCD);
-#ifdef PC98
- }
-#endif
- }
- if (com->state & CS_ODONE) {
- mtx_lock_spin(&sio_lock);
- com_events -= LOTS_OF_EVENTS;
- com->state &= ~CS_ODONE;
- mtx_unlock_spin(&sio_lock);
- if (!(com->state & CS_BUSY)
- && !(com->extra_state & CSE_BUSYCHECK)) {
- timeout(siobusycheck, com, hz / 100);
- com->extra_state |= CSE_BUSYCHECK;
- }
- (*linesw[tp->t_line].l_start)(tp);
- }
- if (com_events == 0)
- break;
- }
- if (com_events >= LOTS_OF_EVENTS)
- goto repeat;
-}
-
-static int
-comparam(tp, t)
- struct tty *tp;
- struct termios *t;
-{
- u_int cfcr;
- int cflag;
- struct com_s *com;
- u_int divisor;
- u_char dlbh;
- u_char dlbl;
- int s;
- int unit;
-#ifdef PC98
- u_char param = 0;
-#endif
-
- unit = DEV_TO_UNIT(tp->t_dev);
- com = com_addr(unit);
- if (com == NULL)
- return (ENODEV);
-
-#ifdef PC98
- cfcr = 0;
-
- if (IS_8251(com->pc98_if_type)) {
- if (pc98_ttspeedtab(com, t->c_ospeed, &divisor) != 0)
- return (EINVAL);
- } else {
-#endif
- /* do historical conversions */
- if (t->c_ispeed == 0)
- t->c_ispeed = t->c_ospeed;
-
- /* check requested parameters */
- if (t->c_ospeed == 0)
- divisor = 0;
- else {
- if (t->c_ispeed != t->c_ospeed)
- return (EINVAL);
- divisor = siodivisor(com->rclk, t->c_ispeed);
- if (divisor == 0)
- return (EINVAL);
- }
-#ifdef PC98
- }
-#endif
-
- /* parameters are OK, convert them to the com struct and the device */
- s = spltty();
-#ifdef PC98
- if (IS_8251(com->pc98_if_type)) {
- if (divisor == 0)
- com_tiocm_bic(com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE);
- else
- com_tiocm_bis(com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE);
- } else
-#endif
- if (divisor == 0)
- (void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */
- else
- (void)commctl(com, TIOCM_DTR, DMBIS);
- cflag = t->c_cflag;
-#ifdef PC98
- if (!IS_8251(com->pc98_if_type)) {
-#endif
- switch (cflag & CSIZE) {
- case CS5:
- cfcr = CFCR_5BITS;
- break;
- case CS6:
- cfcr = CFCR_6BITS;
- break;
- case CS7:
- cfcr = CFCR_7BITS;
- break;
- default:
- cfcr = CFCR_8BITS;
- break;
- }
- if (cflag & PARENB) {
- cfcr |= CFCR_PENAB;
- if (!(cflag & PARODD))
- cfcr |= CFCR_PEVEN;
- }
- if (cflag & CSTOPB)
- cfcr |= CFCR_STOPB;
-
- if (com->hasfifo && divisor != 0) {
- /*
- * Use a fifo trigger level low enough so that the input
- * latency from the fifo is less than about 16 msec and
- * the total latency is less than about 30 msec. These
- * latencies are reasonable for humans. Serial comms
- * protocols shouldn't expect anything better since modem
- * latencies are larger.
- *
- * We have to set the FIFO trigger point such that we
- * don't overflow it accidently if a serial interrupt
- * is delayed. At high speeds, FIFO_RX_HIGH does not
- * leave enough slots free.
- */
- com->fifo_image = com->unit == siotsunit ? 0
- : t->c_ospeed <= 4800
- ? FIFO_ENABLE : FIFO_ENABLE | FIFO_RX_MEDH;
-#ifdef COM_ESP
- /*
- * The Hayes ESP card needs the fifo DMA mode bit set
- * in compatibility mode. If not, it will interrupt
- * for each character received.
- */
- if (com->esp)
- com->fifo_image |= FIFO_DMA_MODE;
-#endif
- sio_setreg(com, com_fifo, com->fifo_image);
- }
-#ifdef PC98
- }
-#endif
-
- /*
- * This returns with interrupts disabled so that we can complete
- * the speed change atomically. Keeping interrupts disabled is
- * especially important while com_data is hidden.
- */
- (void) siosetwater(com, t->c_ispeed);
-
-#ifdef PC98
- if (IS_8251(com->pc98_if_type))
- com_cflag_and_speed_set(com, cflag, t->c_ospeed);
- else {
-#endif
- if (divisor != 0) {
- sio_setreg(com, com_cfcr, cfcr | CFCR_DLAB);
- /*
- * Only set the divisor registers if they would change,
- * since on some 16550 incompatibles (UMC8669F), setting
- * them while input is arriving them loses sync until
- * data stops arriving.
- */
- dlbl = divisor & 0xFF;
- if (sio_getreg(com, com_dlbl) != dlbl)
- sio_setreg(com, com_dlbl, dlbl);
- dlbh = divisor >> 8;
- if (sio_getreg(com, com_dlbh) != dlbh)
- sio_setreg(com, com_dlbh, dlbh);
- }
-
- sio_setreg(com, com_cfcr, com->cfcr_image = cfcr);
-#ifdef PC98
- }
-#endif
-
- if (!(tp->t_state & TS_TTSTOP))
- com->state |= CS_TTGO;
-
- if (cflag & CRTS_IFLOW) {
-#ifndef PC98
- if (com->st16650a) {
- sio_setreg(com, com_cfcr, 0xbf);
- sio_setreg(com, com_fifo,
- sio_getreg(com, com_fifo) | 0x40);
- }
-#endif
- com->state |= CS_RTS_IFLOW;
- /*
- * If CS_RTS_IFLOW just changed from off to on, the change
- * needs to be propagated to MCR_RTS. This isn't urgent,
- * so do it later by calling comstart() instead of repeating
- * a lot of code from comstart() here.
- */
- } else if (com->state & CS_RTS_IFLOW) {
- com->state &= ~CS_RTS_IFLOW;
- /*
- * CS_RTS_IFLOW just changed from on to off. Force MCR_RTS
- * on here, since comstart() won't do it later.
- */
-#ifdef PC98
- if (IS_8251(com->pc98_if_type))
- com_tiocm_bis(com, TIOCM_RTS);
- else
- outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
-#else
- outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
- if (com->st16650a) {
- sio_setreg(com, com_cfcr, 0xbf);
- sio_setreg(com, com_fifo,
- sio_getreg(com, com_fifo) & ~0x40);
- }
-#endif
- }
-
-
- /*
- * Set up state to handle output flow control.
- * XXX - worth handling MDMBUF (DCD) flow control at the lowest level?
- * Now has 10+ msec latency, while CTS flow has 50- usec latency.
- */
- com->state |= CS_ODEVREADY;
- com->state &= ~CS_CTS_OFLOW;
-#ifdef PC98
- if (com->pc98_if_type == COM_IF_RSA98III) {
- param = inb(com->rsabase + rsa_msr);
- outb(com->rsabase + rsa_msr, param & 0x14);
- }
-#endif
- if (cflag & CCTS_OFLOW) {
- com->state |= CS_CTS_OFLOW;
-#ifdef PC98
- if (IS_8251(com->pc98_if_type)) {
- if (!(pc98_get_modem_status(com) & TIOCM_CTS))
- com->state &= ~CS_ODEVREADY;
- } else {
- if (com->pc98_if_type == COM_IF_RSA98III) {
- /* Set automatic flow control mode */
- outb(com->rsabase + rsa_msr, param | 0x08);
- } else
-#endif
- if (!(com->last_modem_status & MSR_CTS))
- com->state &= ~CS_ODEVREADY;
-#ifdef PC98
- }
-#else
- if (com->st16650a) {
- sio_setreg(com, com_cfcr, 0xbf);
- sio_setreg(com, com_fifo,
- sio_getreg(com, com_fifo) | 0x80);
- }
- } else {
- if (com->st16650a) {
- sio_setreg(com, com_cfcr, 0xbf);
- sio_setreg(com, com_fifo,
- sio_getreg(com, com_fifo) & ~0x80);
- }
-#endif
- }
-
-#ifdef PC98
- if (!IS_8251(com->pc98_if_type))
-#endif
- sio_setreg(com, com_cfcr, com->cfcr_image);
-
- /* XXX shouldn't call functions while intrs are disabled. */
- disc_optim(tp, t, com);
- /*
- * Recover from fiddling with CS_TTGO. We used to call siointr1()
- * unconditionally, but that defeated the careful discarding of
- * stale input in sioopen().
- */
- if (com->state >= (CS_BUSY | CS_TTGO))
- siointr1(com);
-
- mtx_unlock_spin(&sio_lock);
- splx(s);
- comstart(tp);
- if (com->ibufold != NULL) {
- free(com->ibufold, M_DEVBUF);
- com->ibufold = NULL;
- }
- return (0);
-}
-
-/*
- * This function must be called with the sio_lock mutex released and will
- * return with it obtained.
- */
-static int
-siosetwater(com, speed)
- struct com_s *com;
- speed_t speed;
-{
- int cp4ticks;
- u_char *ibuf;
- int ibufsize;
- struct tty *tp;
-
- /*
- * Make the buffer size large enough to handle a softtty interrupt
- * latency of about 2 ticks without loss of throughput or data
- * (about 3 ticks if input flow control is not used or not honoured,
- * but a bit less for CS5-CS7 modes).
- */
- cp4ticks = speed / 10 / hz * 4;
- for (ibufsize = 128; ibufsize < cp4ticks;)
- ibufsize <<= 1;
-#ifdef PC98
- if (com->pc98_if_type == COM_IF_RSA98III)
- ibufsize = 2048;
-#endif
- if (ibufsize == com->ibufsize) {
- mtx_lock_spin(&sio_lock);
- return (0);
- }
-
- /*
- * Allocate input buffer. The extra factor of 2 in the size is
- * to allow for an error byte for each input byte.
- */
- ibuf = malloc(2 * ibufsize, M_DEVBUF, M_NOWAIT);
- if (ibuf == NULL) {
- mtx_lock_spin(&sio_lock);
- return (ENOMEM);
- }
-
- /* Initialize non-critical variables. */
- com->ibufold = com->ibuf;
- com->ibufsize = ibufsize;
- tp = com->tp;
- if (tp != NULL) {
- tp->t_ififosize = 2 * ibufsize;
- tp->t_ispeedwat = (speed_t)-1;
- tp->t_ospeedwat = (speed_t)-1;
- }
-
- /*
- * Read current input buffer, if any. Continue with interrupts
- * disabled.
- */
- mtx_lock_spin(&sio_lock);
- if (com->iptr != com->ibuf)
- sioinput(com);
-
- /*-
- * Initialize critical variables, including input buffer watermarks.
- * The external device is asked to stop sending when the buffer
- * exactly reaches high water, or when the high level requests it.
- * The high level is notified immediately (rather than at a later
- * clock tick) when this watermark is reached.
- * The buffer size is chosen so the watermark should almost never
- * be reached.
- * The low watermark is invisibly 0 since the buffer is always
- * emptied all at once.
- */
- com->iptr = com->ibuf = ibuf;
- com->ibufend = ibuf + ibufsize;
- com->ierroff = ibufsize;
- com->ihighwater = ibuf + 3 * ibufsize / 4;
- return (0);
-}
-
-static void
-comstart(tp)
- struct tty *tp;
-{
- struct com_s *com;
- int s;
- int unit;
-
- unit = DEV_TO_UNIT(tp->t_dev);
- com = com_addr(unit);
- if (com == NULL)
- return;
- s = spltty();
- mtx_lock_spin(&sio_lock);
- if (tp->t_state & TS_TTSTOP)
- com->state &= ~CS_TTGO;
- else
- com->state |= CS_TTGO;
- if (tp->t_state & TS_TBLOCK) {
-#ifdef PC98
- if (IS_8251(com->pc98_if_type)) {
- if ((com_tiocm_get(com) & TIOCM_RTS) &&
- (com->state & CS_RTS_IFLOW))
- com_tiocm_bic(com, TIOCM_RTS);
- } else {
- if ((com->mcr_image & MCR_RTS) &&
- (com->state & CS_RTS_IFLOW))
- outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS);
- }
-#else
- if (com->mcr_image & MCR_RTS && com->state & CS_RTS_IFLOW)
- outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS);
-#endif
- } else {
-#ifdef PC98
- if (IS_8251(com->pc98_if_type)) {
- if (!(com_tiocm_get(com) & TIOCM_RTS) &&
- com->iptr < com->ihighwater &&
- com->state & CS_RTS_IFLOW)
- com_tiocm_bis(com, TIOCM_RTS);
- } else {
- if (!(com->mcr_image & MCR_RTS) &&
- com->iptr < com->ihighwater &&
- com->state & CS_RTS_IFLOW)
- outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
- }
-#else
- if (!(com->mcr_image & MCR_RTS) && com->iptr < com->ihighwater
- && com->state & CS_RTS_IFLOW)
- outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
-#endif
- }
- mtx_unlock_spin(&sio_lock);
- if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
- ttwwakeup(tp);
- splx(s);
- return;
- }
- if (tp->t_outq.c_cc != 0) {
- struct lbq *qp;
- struct lbq *next;
-
- if (!com->obufs[0].l_queued) {
- com->obufs[0].l_tail
- = com->obuf1 + q_to_b(&tp->t_outq, com->obuf1,
-#ifdef PC98
- com->obufsize);
-#else
- sizeof com->obuf1);
-#endif
- com->obufs[0].l_next = NULL;
- com->obufs[0].l_queued = TRUE;
- mtx_lock_spin(&sio_lock);
- if (com->state & CS_BUSY) {
- qp = com->obufq.l_next;
- while ((next = qp->l_next) != NULL)
- qp = next;
- qp->l_next = &com->obufs[0];
- } else {
- com->obufq.l_head = com->obufs[0].l_head;
- com->obufq.l_tail = com->obufs[0].l_tail;
- com->obufq.l_next = &com->obufs[0];
- com->state |= CS_BUSY;
- }
- mtx_unlock_spin(&sio_lock);
- }
- if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) {
- com->obufs[1].l_tail
- = com->obuf2 + q_to_b(&tp->t_outq, com->obuf2,
-#ifdef PC98
- com->obufsize);
-#else
- sizeof com->obuf2);
-#endif
- com->obufs[1].l_next = NULL;
- com->obufs[1].l_queued = TRUE;
- mtx_lock_spin(&sio_lock);
- if (com->state & CS_BUSY) {
- qp = com->obufq.l_next;
- while ((next = qp->l_next) != NULL)
- qp = next;
- qp->l_next = &com->obufs[1];
- } else {
- com->obufq.l_head = com->obufs[1].l_head;
- com->obufq.l_tail = com->obufs[1].l_tail;
- com->obufq.l_next = &com->obufs[1];
- com->state |= CS_BUSY;
- }
- mtx_unlock_spin(&sio_lock);
- }
- tp->t_state |= TS_BUSY;
- }
- mtx_lock_spin(&sio_lock);
- if (com->state >= (CS_BUSY | CS_TTGO))
- siointr1(com); /* fake interrupt to start output */
- mtx_unlock_spin(&sio_lock);
- ttwwakeup(tp);
- splx(s);
-}
-
-static void
-comstop(tp, rw)
- struct tty *tp;
- int rw;
-{
- struct com_s *com;
-#ifdef PC98
- int rsa98_tmp = 0;
-#endif
-
- com = com_addr(DEV_TO_UNIT(tp->t_dev));
- if (com == NULL || com->gone)
- return;
- mtx_lock_spin(&sio_lock);
- if (rw & FWRITE) {
-#ifdef PC98
- if (!IS_8251(com->pc98_if_type)) {
-#endif
- if (com->hasfifo)
-#ifdef COM_ESP
- /* XXX avoid h/w bug. */
- if (!com->esp)
-#endif
- sio_setreg(com, com_fifo,
- FIFO_XMT_RST | com->fifo_image);
-#ifdef PC98
- if (com->pc98_if_type == COM_IF_RSA98III)
- for (rsa98_tmp = 0; rsa98_tmp < 2048; rsa98_tmp++)
- sio_setreg(com, com_fifo,
- FIFO_XMT_RST | com->fifo_image);
- }
-#endif
- com->obufs[0].l_queued = FALSE;
- com->obufs[1].l_queued = FALSE;
- if (com->state & CS_ODONE)
- com_events -= LOTS_OF_EVENTS;
- com->state &= ~(CS_ODONE | CS_BUSY);
- com->tp->t_state &= ~TS_BUSY;
- }
- if (rw & FREAD) {
-#ifdef PC98
- if (!IS_8251(com->pc98_if_type)) {
- if (com->pc98_if_type == COM_IF_RSA98III)
- for (rsa98_tmp = 0; rsa98_tmp < 2048; rsa98_tmp++)
- sio_getreg(com, com_data);
-#endif
- if (com->hasfifo)
-#ifdef COM_ESP
- /* XXX avoid h/w bug. */
- if (!com->esp)
-#endif
- sio_setreg(com, com_fifo,
- FIFO_RCV_RST | com->fifo_image);
-#ifdef PC98
- }
-#endif
- com_events -= (com->iptr - com->ibuf);
- com->iptr = com->ibuf;
- }
- mtx_unlock_spin(&sio_lock);
- comstart(tp);
-}
-
-static int
-commctl(com, bits, how)
- struct com_s *com;
- int bits;
- int how;
-{
- int mcr;
- int msr;
-
- if (how == DMGET) {
- bits = TIOCM_LE; /* XXX - always enabled while open */
- mcr = com->mcr_image;
- if (mcr & MCR_DTR)
- bits |= TIOCM_DTR;
- if (mcr & MCR_RTS)
- bits |= TIOCM_RTS;
- msr = com->prev_modem_status;
- if (msr & MSR_CTS)
- bits |= TIOCM_CTS;
- if (msr & MSR_DCD)
- bits |= TIOCM_CD;
- if (msr & MSR_DSR)
- bits |= TIOCM_DSR;
- /*
- * XXX - MSR_RI is naturally volatile, and we make MSR_TERI
- * more volatile by reading the modem status a lot. Perhaps
- * we should latch both bits until the status is read here.
- */
- if (msr & (MSR_RI | MSR_TERI))
- bits |= TIOCM_RI;
- return (bits);
- }
- mcr = 0;
- if (bits & TIOCM_DTR)
- mcr |= MCR_DTR;
- if (bits & TIOCM_RTS)
- mcr |= MCR_RTS;
- if (com->gone)
- return(0);
- mtx_lock_spin(&sio_lock);
- switch (how) {
- case DMSET:
- outb(com->modem_ctl_port,
- com->mcr_image = mcr | (com->mcr_image & MCR_IENABLE));
- break;
- case DMBIS:
- outb(com->modem_ctl_port, com->mcr_image |= mcr);
- break;
- case DMBIC:
- outb(com->modem_ctl_port, com->mcr_image &= ~mcr);
- break;
- }
- mtx_unlock_spin(&sio_lock);
- return (0);
-}
-
-static void
-siosettimeout()
-{
- struct com_s *com;
- bool_t someopen;
- int unit;
-
- /*
- * Set our timeout period to 1 second if no polled devices are open.
- * Otherwise set it to max(1/200, 1/hz).
- * Enable timeouts iff some device is open.
- */
- untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
- sio_timeout = hz;
- someopen = FALSE;
- for (unit = 0; unit < sio_numunits; ++unit) {
- com = com_addr(unit);
- if (com != NULL && com->tp != NULL
- && com->tp->t_state & TS_ISOPEN && !com->gone) {
- someopen = TRUE;
- if (com->poll || com->poll_output) {
- sio_timeout = hz > 200 ? hz / 200 : 1;
- break;
- }
- }
- }
- if (someopen) {
- sio_timeouts_until_log = hz / sio_timeout;
- sio_timeout_handle = timeout(comwakeup, (void *)NULL,
- sio_timeout);
- } else {
- /* Flush error messages, if any. */
- sio_timeouts_until_log = 1;
- comwakeup((void *)NULL);
- untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
- }
-}
-
-static void
-comwakeup(chan)
- void *chan;
-{
- struct com_s *com;
- int unit;
-
- sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout);
-
- /*
- * Recover from lost output interrupts.
- * Poll any lines that don't use interrupts.
- */
- for (unit = 0; unit < sio_numunits; ++unit) {
- com = com_addr(unit);
- if (com != NULL && !com->gone
- && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) {
- mtx_lock_spin(&sio_lock);
- siointr1(com);
- mtx_unlock_spin(&sio_lock);
- }
- }
-
- /*
- * Check for and log errors, but not too often.
- */
- if (--sio_timeouts_until_log > 0)
- return;
- sio_timeouts_until_log = hz / sio_timeout;
- for (unit = 0; unit < sio_numunits; ++unit) {
- int errnum;
-
- com = com_addr(unit);
- if (com == NULL)
- continue;
- if (com->gone)
- continue;
- for (errnum = 0; errnum < CE_NTYPES; ++errnum) {
- u_int delta;
- u_long total;
-
- mtx_lock_spin(&sio_lock);
- delta = com->delta_error_counts[errnum];
- com->delta_error_counts[errnum] = 0;
- mtx_unlock_spin(&sio_lock);
- if (delta == 0)
- continue;
- total = com->error_counts[errnum] += delta;
- log(LOG_ERR, "sio%d: %u more %s%s (total %lu)\n",
- unit, delta, error_desc[errnum],
- delta == 1 ? "" : "s", total);
- }
- }
-}
-
-#ifdef PC98
-/* commint is called when modem control line changes */
-static void
-commint(dev_t dev)
-{
- register struct tty *tp;
- int stat,delta;
- struct com_s *com;
- int mynor,unit;
-
- mynor = minor(dev);
- unit = MINOR_TO_UNIT(mynor);
- com = com_addr(unit);
- tp = com->tp;
-
- stat = com_tiocm_get(com);
- delta = com_tiocm_get_delta(com);
-
- if (com->state & CS_CTS_OFLOW) {
- if (stat & TIOCM_CTS)
- com->state |= CS_ODEVREADY;
- else
- com->state &= ~CS_ODEVREADY;
- }
- if ((delta & TIOCM_CAR) && (mynor & CALLOUT_MASK) == 0) {
- if (stat & TIOCM_CAR )
- (void)(*linesw[tp->t_line].l_modem)(tp, 1);
- else if ((*linesw[tp->t_line].l_modem)(tp, 0) == 0) {
- /* negate DTR, RTS */
- com_tiocm_bic(com, (tp->t_cflag & HUPCL) ?
- TIOCM_DTR|TIOCM_RTS|TIOCM_LE : TIOCM_LE );
- /* disable IENABLE */
- com_int_TxRx_disable( com );
- }
- }
-}
-#endif
-
-static void
-disc_optim(tp, t, com)
- struct tty *tp;
- struct termios *t;
- struct com_s *com;
-{
- if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
- && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
- && (!(t->c_iflag & PARMRK)
- || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
- && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
- && linesw[tp->t_line].l_rint == ttyinput)
- tp->t_state |= TS_CAN_BYPASS_L_RINT;
- else
- tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
- com->hotchar = linesw[tp->t_line].l_hotchar;
-}
-
-/*
- * Following are all routines needed for SIO to act as console
- */
-#include <sys/cons.h>
-
-struct siocnstate {
- u_char dlbl;
- u_char dlbh;
- u_char ier;
- u_char cfcr;
- u_char mcr;
-};
-
-#ifndef __alpha__
-static speed_t siocngetspeed(Port_t, u_long rclk);
-#endif
-static void siocnclose(struct siocnstate *sp, Port_t iobase);
-static void siocnopen(struct siocnstate *sp, Port_t iobase, int speed);
-static void siocntxwait(Port_t iobase);
-
-#ifdef __alpha__
-int siocnattach(int port, int speed);
-int siogdbattach(int port, int speed);
-int siogdbgetc(void);
-void siogdbputc(int c);
-#else
-static cn_probe_t siocnprobe;
-static cn_init_t siocninit;
-static cn_term_t siocnterm;
-#endif
-static cn_checkc_t siocncheckc;
-static cn_getc_t siocngetc;
-static cn_putc_t siocnputc;
-
-#ifndef __alpha__
-CONS_DRIVER(sio, siocnprobe, siocninit, siocnterm, siocngetc, siocncheckc,
- siocnputc, NULL);
-#endif
-
-/* To get the GDB related variables */
-#if DDB > 0
-#include <ddb/ddb.h>
-struct consdev gdbconsdev;
-#endif
-
-static void
-siocntxwait(iobase)
- Port_t iobase;
-{
- int timo;
-
- /*
- * Wait for any pending transmission to finish. Required to avoid
- * the UART lockup bug when the speed is changed, and for normal
- * transmits.
- */
- timo = 100000;
- while ((inb(iobase + com_lsr) & (LSR_TSRE | LSR_TXRDY))
- != (LSR_TSRE | LSR_TXRDY) && --timo != 0)
- ;
-}
-
-#ifndef __alpha__
-
-/*
- * Read the serial port specified and try to figure out what speed
- * it's currently running at. We're assuming the serial port has
- * been initialized and is basicly idle. This routine is only intended
- * to be run at system startup.
- *
- * If the value read from the serial port doesn't make sense, return 0.
- */
-
-static speed_t
-siocngetspeed(iobase, rclk)
- Port_t iobase;
- u_long rclk;
-{
- u_int divisor;
- u_char dlbh;
- u_char dlbl;
- u_char cfcr;
-
- cfcr = inb(iobase + com_cfcr);
- outb(iobase + com_cfcr, CFCR_DLAB | cfcr);
-
- dlbl = inb(iobase + com_dlbl);
- dlbh = inb(iobase + com_dlbh);
-
- outb(iobase + com_cfcr, cfcr);
-
- divisor = dlbh << 8 | dlbl;
-
- /* XXX there should be more sanity checking. */
- if (divisor == 0)
- return (CONSPEED);
- return (rclk / (16UL * divisor));
-}
-
-#endif
-
-static void
-siocnopen(sp, iobase, speed)
- struct siocnstate *sp;
- Port_t iobase;
- int speed;
-{
- u_int divisor;
- u_char dlbh;
- u_char dlbl;
-
- /*
- * Save all the device control registers except the fifo register
- * and set our default ones (cs8 -parenb speed=comdefaultrate).
- * We can't save the fifo register since it is read-only.
- */
- sp->ier = inb(iobase + com_ier);
- outb(iobase + com_ier, 0); /* spltty() doesn't stop siointr() */
- siocntxwait(iobase);
- sp->cfcr = inb(iobase + com_cfcr);
- outb(iobase + com_cfcr, CFCR_DLAB | CFCR_8BITS);
- sp->dlbl = inb(iobase + com_dlbl);
- sp->dlbh = inb(iobase + com_dlbh);
- /*
- * Only set the divisor registers if they would change, since on
- * some 16550 incompatibles (Startech), setting them clears the
- * data input register. This also reduces the effects of the
- * UMC8669F bug.
- */
- divisor = siodivisor(comdefaultrclk, speed);
- dlbl = divisor & 0xFF;
- if (sp->dlbl != dlbl)
- outb(iobase + com_dlbl, dlbl);
- dlbh = divisor >> 8;
- if (sp->dlbh != dlbh)
- outb(iobase + com_dlbh, dlbh);
- outb(iobase + com_cfcr, CFCR_8BITS);
- sp->mcr = inb(iobase + com_mcr);
- /*
- * We don't want interrupts, but must be careful not to "disable"
- * them by clearing the MCR_IENABLE bit, since that might cause
- * an interrupt by floating the IRQ line.
- */
- outb(iobase + com_mcr, (sp->mcr & MCR_IENABLE) | MCR_DTR | MCR_RTS);
-}
-
-static void
-siocnclose(sp, iobase)
- struct siocnstate *sp;
- Port_t iobase;
-{
- /*
- * Restore the device control registers.
- */
- siocntxwait(iobase);
- outb(iobase + com_cfcr, CFCR_DLAB | CFCR_8BITS);
- if (sp->dlbl != inb(iobase + com_dlbl))
- outb(iobase + com_dlbl, sp->dlbl);
- if (sp->dlbh != inb(iobase + com_dlbh))
- outb(iobase + com_dlbh, sp->dlbh);
- outb(iobase + com_cfcr, sp->cfcr);
- /*
- * XXX damp oscillations of MCR_DTR and MCR_RTS by not restoring them.
- */
- outb(iobase + com_mcr, sp->mcr | MCR_DTR | MCR_RTS);
- outb(iobase + com_ier, sp->ier);
-}
-
-#ifndef __alpha__
-
-static void
-siocnprobe(cp)
- struct consdev *cp;
-{
- speed_t boot_speed;
- u_char cfcr;
- u_int divisor;
- int s, unit;
- struct siocnstate sp;
-
- /*
- * Find our first enabled console, if any. If it is a high-level
- * console device, then initialize it and return successfully.
- * If it is a low-level console device, then initialize it and
- * return unsuccessfully. It must be initialized in both cases
- * for early use by console drivers and debuggers. Initializing
- * the hardware is not necessary in all cases, since the i/o
- * routines initialize it on the fly, but it is necessary if
- * input might arrive while the hardware is switched back to an
- * uninitialized state. We can't handle multiple console devices
- * yet because our low-level routines don't take a device arg.
- * We trust the user to set the console flags properly so that we
- * don't need to probe.
- */
- cp->cn_pri = CN_DEAD;
-
- for (unit = 0; unit < 16; unit++) { /* XXX need to know how many */
- int flags;
- int disabled;
- if (resource_int_value("sio", unit, "disabled", &disabled) == 0) {
- if (disabled)
- continue;
- }
- if (resource_int_value("sio", unit, "flags", &flags))
- continue;
- if (COM_CONSOLE(flags) || COM_DEBUGGER(flags)) {
- int port;
- Port_t iobase;
-
- if (resource_int_value("sio", unit, "port", &port))
- continue;
- iobase = port;
- s = spltty();
- if (boothowto & RB_SERIAL) {
- boot_speed =
- siocngetspeed(iobase, comdefaultrclk);
- if (boot_speed)
- comdefaultrate = boot_speed;
- }
-
- /*
- * Initialize the divisor latch. We can't rely on
- * siocnopen() to do this the first time, since it
- * avoids writing to the latch if the latch appears
- * to have the correct value. Also, if we didn't
- * just read the speed from the hardware, then we
- * need to set the speed in hardware so that
- * switching it later is null.
- */
- cfcr = inb(iobase + com_cfcr);
- outb(iobase + com_cfcr, CFCR_DLAB | cfcr);
- divisor = siodivisor(comdefaultrclk, comdefaultrate);
- outb(iobase + com_dlbl, divisor & 0xff);
- outb(iobase + com_dlbh, divisor >> 8);
- outb(iobase + com_cfcr, cfcr);
-
- siocnopen(&sp, iobase, comdefaultrate);
-
- splx(s);
- if (COM_CONSOLE(flags) && !COM_LLCONSOLE(flags)) {
- cp->cn_dev = makedev(CDEV_MAJOR, unit);
- cp->cn_pri = COM_FORCECONSOLE(flags)
- || boothowto & RB_SERIAL
- ? CN_REMOTE : CN_NORMAL;
- siocniobase = iobase;
- siocnunit = unit;
- }
- if (COM_DEBUGGER(flags)) {
- printf("sio%d: gdb debugging port\n", unit);
- siogdbiobase = iobase;
- siogdbunit = unit;
-#if DDB > 0
- gdbconsdev.cn_dev = makedev(CDEV_MAJOR, unit);
- gdb_arg = &gdbconsdev;
- gdb_getc = siocngetc;
- gdb_putc = siocnputc;
-#endif
- }
- }
- }
-#ifdef __i386__
-#if DDB > 0
- /*
- * XXX Ugly Compatability.
- * If no gdb port has been specified, set it to be the console
- * as some configuration files don't specify the gdb port.
- */
- if (gdb_arg == NULL && (boothowto & RB_GDB)) {
- printf("Warning: no GDB port specified. Defaulting to sio%d.\n",
- siocnunit);
- printf("Set flag 0x80 on desired GDB port in your\n");
- printf("configuration file (currently sio only).\n");
- siogdbiobase = siocniobase;
- siogdbunit = siocnunit;
- gdbconsdev.cn_dev = makedev(CDEV_MAJOR, siocnunit);
- gdb_arg = &gdbconsdev;
- gdb_getc = siocngetc;
- gdb_putc = siocnputc;
- }
-#endif
-#endif
-}
-
-static void
-siocninit(cp)
- struct consdev *cp;
-{
- comconsole = DEV_TO_UNIT(cp->cn_dev);
-}
-
-static void
-siocnterm(cp)
- struct consdev *cp;
-{
- comconsole = -1;
-}
-
-#endif
-
-#ifdef __alpha__
-
-CONS_DRIVER(sio, NULL, NULL, NULL, siocngetc, siocncheckc, siocnputc, NULL);
-
-int
-siocnattach(port, speed)
- int port;
- int speed;
-{
- int s;
- u_char cfcr;
- u_int divisor;
- struct siocnstate sp;
- int unit = 0; /* XXX random value! */
-
- siocniobase = port;
- siocnunit = unit;
- comdefaultrate = speed;
- sio_consdev.cn_pri = CN_NORMAL;
- sio_consdev.cn_dev = makedev(CDEV_MAJOR, unit);
-
- s = spltty();
-
- /*
- * Initialize the divisor latch. We can't rely on
- * siocnopen() to do this the first time, since it
- * avoids writing to the latch if the latch appears
- * to have the correct value. Also, if we didn't
- * just read the speed from the hardware, then we
- * need to set the speed in hardware so that
- * switching it later is null.
- */
- cfcr = inb(siocniobase + com_cfcr);
- outb(siocniobase + com_cfcr, CFCR_DLAB | cfcr);
- divisor = siodivisor(comdefaultrclk, comdefaultrate);
- outb(siocniobase + com_dlbl, divisor & 0xff);
- outb(siocniobase + com_dlbh, divisor >> 8);
- outb(siocniobase + com_cfcr, cfcr);
-
- siocnopen(&sp, siocniobase, comdefaultrate);
- splx(s);
-
- cnadd(&sio_consdev);
- return (0);
-}
-
-int
-siogdbattach(port, speed)
- int port;
- int speed;
-{
- int s;
- u_char cfcr;
- u_int divisor;
- struct siocnstate sp;
- int unit = 1; /* XXX random value! */
-
- siogdbiobase = port;
- gdbdefaultrate = speed;
-
- printf("sio%d: gdb debugging port\n", unit);
- siogdbunit = unit;
-#if DDB > 0
- gdbconsdev.cn_dev = makedev(CDEV_MAJOR, unit);
- gdb_arg = &gdbconsdev;
- gdb_getc = siocngetc;
- gdb_putc = siocnputc;
-#endif
-
- s = spltty();
-
- /*
- * Initialize the divisor latch. We can't rely on
- * siocnopen() to do this the first time, since it
- * avoids writing to the latch if the latch appears
- * to have the correct value. Also, if we didn't
- * just read the speed from the hardware, then we
- * need to set the speed in hardware so that
- * switching it later is null.
- */
- cfcr = inb(siogdbiobase + com_cfcr);
- outb(siogdbiobase + com_cfcr, CFCR_DLAB | cfcr);
- divisor = siodivisor(comdefaultrclk, gdbdefaultrate);
- outb(siogdbiobase + com_dlbl, divisor & 0xff);
- outb(siogdbiobase + com_dlbh, divisor >> 8);
- outb(siogdbiobase + com_cfcr, cfcr);
-
- siocnopen(&sp, siogdbiobase, gdbdefaultrate);
- splx(s);
-
- return (0);
-}
-
-#endif
-
-static int
-siocncheckc(struct consdev *cd)
-{
- int c;
- dev_t dev;
- Port_t iobase;
- int s;
- struct siocnstate sp;
- speed_t speed;
-
- dev = cd->cn_dev;
- if (minor(dev) == siocnunit) {
- iobase = siocniobase;
- speed = comdefaultrate;
- } else {
- iobase = siogdbiobase;
- speed = gdbdefaultrate;
- }
- s = spltty();
- siocnopen(&sp, iobase, speed);
- if (inb(iobase + com_lsr) & LSR_RXRDY)
- c = inb(iobase + com_data);
- else
- c = -1;
- siocnclose(&sp, iobase);
- splx(s);
- return (c);
-}
-
-
-static int
-siocngetc(struct consdev *cd)
-{
- int c;
- dev_t dev;
- Port_t iobase;
- int s;
- struct siocnstate sp;
- speed_t speed;
-
- dev = cd->cn_dev;
- if (minor(dev) == siocnunit) {
- iobase = siocniobase;
- speed = comdefaultrate;
- } else {
- iobase = siogdbiobase;
- speed = gdbdefaultrate;
- }
- s = spltty();
- siocnopen(&sp, iobase, speed);
- while (!(inb(iobase + com_lsr) & LSR_RXRDY))
- ;
- c = inb(iobase + com_data);
- siocnclose(&sp, iobase);
- splx(s);
- return (c);
-}
-
-static void
-siocnputc(struct consdev *cd, int c)
-{
- int need_unlock;
- int s;
- dev_t dev;
- struct siocnstate sp;
- Port_t iobase;
- speed_t speed;
-
- dev = cd->cn_dev;
- if (minor(dev) == siocnunit) {
- iobase = siocniobase;
- speed = comdefaultrate;
- } else {
- iobase = siogdbiobase;
- speed = gdbdefaultrate;
- }
- s = spltty();
- need_unlock = 0;
- if (sio_inited == 2 && !mtx_owned(&sio_lock)) {
- mtx_lock_spin(&sio_lock);
- need_unlock = 1;
- }
- siocnopen(&sp, iobase, speed);
- siocntxwait(iobase);
- outb(iobase + com_data, c);
- siocnclose(&sp, iobase);
- if (need_unlock)
- mtx_unlock_spin(&sio_lock);
- splx(s);
-}
-
-#ifdef __alpha__
-int
-siogdbgetc()
-{
- int c;
- Port_t iobase;
- speed_t speed;
- int s;
- struct siocnstate sp;
-
- if (siogdbunit == siocnunit) {
- iobase = siocniobase;
- speed = comdefaultrate;
- } else {
- iobase = siogdbiobase;
- speed = gdbdefaultrate;
- }
-
- s = spltty();
- siocnopen(&sp, iobase, speed);
- while (!(inb(iobase + com_lsr) & LSR_RXRDY))
- ;
- c = inb(iobase + com_data);
- siocnclose(&sp, iobase);
- splx(s);
- return (c);
-}
-
-void
-siogdbputc(c)
- int c;
-{
- Port_t iobase;
- speed_t speed;
- int s;
- struct siocnstate sp;
-
- if (siogdbunit == siocnunit) {
- iobase = siocniobase;
- speed = comdefaultrate;
- } else {
- iobase = siogdbiobase;
- speed = gdbdefaultrate;
- }
-
- s = spltty();
- siocnopen(&sp, iobase, speed);
- siocntxwait(siogdbiobase);
- outb(siogdbiobase + com_data, c);
- siocnclose(&sp, siogdbiobase);
- splx(s);
-}
-#endif
-
-#ifdef PC98
-/*
- * pc98 local function
- */
-
-static void
-com_tiocm_set(struct com_s *com, int msr)
-{
- int s;
- int tmp = 0;
- int mask = CMD8251_TxEN|CMD8251_RxEN|CMD8251_DTR|CMD8251_RTS;
-
- s=spltty();
- com->pc98_prev_modem_status = ( msr & (TIOCM_LE|TIOCM_DTR|TIOCM_RTS) )
- | ( com->pc98_prev_modem_status & ~(TIOCM_LE|TIOCM_DTR|TIOCM_RTS) );
- tmp |= (CMD8251_TxEN|CMD8251_RxEN);
- if ( msr & TIOCM_DTR ) tmp |= CMD8251_DTR;
- if ( msr & TIOCM_RTS ) tmp |= CMD8251_RTS;
- pc98_i8251_clear_or_cmd( com, mask, tmp );
- splx(s);
-}
-
-static void
-com_tiocm_bis(struct com_s *com, int msr)
-{
- int s;
- int tmp = 0;
-
- s=spltty();
- com->pc98_prev_modem_status |= ( msr & (TIOCM_LE|TIOCM_DTR|TIOCM_RTS) );
- tmp |= CMD8251_TxEN|CMD8251_RxEN;
- if ( msr & TIOCM_DTR ) tmp |= CMD8251_DTR;
- if ( msr & TIOCM_RTS ) tmp |= CMD8251_RTS;
-
- pc98_i8251_or_cmd( com, tmp );
- splx(s);
-}
-
-static void
-com_tiocm_bic(struct com_s *com, int msr)
-{
- int s;
- int tmp = msr;
-
- s=spltty();
- com->pc98_prev_modem_status &= ~( msr & (TIOCM_LE|TIOCM_DTR|TIOCM_RTS) );
- if ( msr & TIOCM_DTR ) tmp |= CMD8251_DTR;
- if ( msr & TIOCM_RTS ) tmp |= CMD8251_RTS;
-
- pc98_i8251_clear_cmd( com, tmp );
- splx(s);
-}
-
-static int
-com_tiocm_get(struct com_s *com)
-{
- return( com->pc98_prev_modem_status );
-}
-
-static int
-com_tiocm_get_delta(struct com_s *com)
-{
- int tmp;
-
- tmp = com->pc98_modem_delta;
- com->pc98_modem_delta = 0;
- return( tmp );
-}
-
-/* convert to TIOCM_?? ( ioctl.h ) */
-static int
-pc98_get_modem_status(struct com_s *com)
-{
- register int msr;
-
- msr = com->pc98_prev_modem_status
- & ~(TIOCM_CAR|TIOCM_RI|TIOCM_DSR|TIOCM_CTS);
- if (com->pc98_8251fifo_enable) {
- int stat2;
-
- stat2 = inb(I8251F_msr);
- if ( stat2 & CICSCDF_CD ) msr |= TIOCM_CAR;
- if ( stat2 & CICSCDF_CI ) msr |= TIOCM_RI;
- if ( stat2 & CICSCDF_DR ) msr |= TIOCM_DSR;
- if ( stat2 & CICSCDF_CS ) msr |= TIOCM_CTS;
-#if COM_CARRIER_DETECT_EMULATE
- if ( msr & (TIOCM_DSR|TIOCM_CTS) ) {
- msr |= TIOCM_CAR;
- }
-#endif
- } else {
- int stat, stat2;
-
- stat = inb(com->sts_port);
- stat2 = inb(com->in_modem_port);
- if ( !(stat2 & CICSCD_CD) ) msr |= TIOCM_CAR;
- if ( !(stat2 & CICSCD_CI) ) msr |= TIOCM_RI;
- if ( stat & STS8251_DSR ) msr |= TIOCM_DSR;
- if ( !(stat2 & CICSCD_CS) ) msr |= TIOCM_CTS;
-#if COM_CARRIER_DETECT_EMULATE
- if ( msr & (TIOCM_DSR|TIOCM_CTS) ) {
- msr |= TIOCM_CAR;
- }
-#endif
- }
- return(msr);
-}
-
-static void
-pc98_check_msr(void* chan)
-{
- int msr, delta;
- int s;
- register struct tty *tp;
- struct com_s *com;
- int mynor;
- int unit;
- dev_t dev;
-
- dev=(dev_t)chan;
- mynor = minor(dev);
- unit = MINOR_TO_UNIT(mynor);
- com = com_addr(unit);
- tp = com->tp;
-
- s = spltty();
- msr = pc98_get_modem_status(com);
- /* make change flag */
- delta = msr ^ com->pc98_prev_modem_status;
- if ( delta & TIOCM_CAR ) {
- if ( com->modem_car_chg_timer ) {
- if ( -- com->modem_car_chg_timer )
- msr ^= TIOCM_CAR;
- } else {
- if ((com->modem_car_chg_timer = (msr & TIOCM_CAR) ?
- DCD_ON_RECOGNITION : DCD_OFF_TOLERANCE) != 0)
- msr ^= TIOCM_CAR;
- }
- } else
- com->modem_car_chg_timer = 0;
- delta = ( msr ^ com->pc98_prev_modem_status ) &
- (TIOCM_CAR|TIOCM_RI|TIOCM_DSR|TIOCM_CTS);
- com->pc98_prev_modem_status = msr;
- delta = ( com->pc98_modem_delta |= delta );
- splx(s);
- if ( com->modem_checking || (tp->t_state & (TS_ISOPEN)) ) {
- if ( delta ) {
- commint(dev);
- }
- timeout(pc98_check_msr, (caddr_t)dev,
- PC98_CHECK_MODEM_INTERVAL);
- } else {
- com->modem_checking = 0;
- }
-}
-
-static void
-pc98_msrint_start(dev_t dev)
-{
- struct com_s *com;
- int mynor;
- int unit;
- int s = spltty();
-
- mynor = minor(dev);
- unit = MINOR_TO_UNIT(mynor);
- com = com_addr(unit);
- /* modem control line check routine envoke interval is 1/10 sec */
- if ( com->modem_checking == 0 ) {
- com->pc98_prev_modem_status = pc98_get_modem_status(com);
- com->pc98_modem_delta = 0;
- timeout(pc98_check_msr, (caddr_t)dev,
- PC98_CHECK_MODEM_INTERVAL);
- com->modem_checking = 1;
- }
- splx(s);
-}
-
-static void
-pc98_disable_i8251_interrupt(struct com_s *com, int mod)
-{
- /* disable interrupt */
- register int tmp;
-
- mod |= ~(IEN_Tx|IEN_TxEMP|IEN_Rx);
- COM_INT_DISABLE
- tmp = inb( com->intr_ctrl_port ) & ~(IEN_Tx|IEN_TxEMP|IEN_Rx);
- outb( com->intr_ctrl_port, (com->intr_enable&=~mod) | tmp );
- COM_INT_ENABLE
-}
-
-static void
-pc98_enable_i8251_interrupt(struct com_s *com, int mod)
-{
- register int tmp;
-
- COM_INT_DISABLE
- tmp = inb( com->intr_ctrl_port ) & ~(IEN_Tx|IEN_TxEMP|IEN_Rx);
- outb( com->intr_ctrl_port, (com->intr_enable|=mod) | tmp );
- COM_INT_ENABLE
-}
-
-static int
-pc98_check_i8251_interrupt(struct com_s *com)
-{
- return ( com->intr_enable & 0x07 );
-}
-
-static void
-pc98_i8251_clear_cmd(struct com_s *com, int x)
-{
- int tmp;
-
- COM_INT_DISABLE
- tmp = com->pc98_prev_siocmd & ~(x);
- if (com->pc98_8251fifo_enable)
- outb(I8251F_fcr, 0);
- outb(com->cmd_port, tmp);
- com->pc98_prev_siocmd = tmp & ~(CMD8251_ER|CMD8251_RESET|CMD8251_EH);
- if (com->pc98_8251fifo_enable)
- outb(I8251F_fcr, CTRL8251F_ENABLE);
- COM_INT_ENABLE
-}
-
-static void
-pc98_i8251_or_cmd(struct com_s *com, int x)
-{
- int tmp;
-
- COM_INT_DISABLE
- if (com->pc98_8251fifo_enable)
- outb(I8251F_fcr, 0);
- tmp = com->pc98_prev_siocmd | (x);
- outb(com->cmd_port, tmp);
- com->pc98_prev_siocmd = tmp & ~(CMD8251_ER|CMD8251_RESET|CMD8251_EH);
- if (com->pc98_8251fifo_enable)
- outb(I8251F_fcr, CTRL8251F_ENABLE);
- COM_INT_ENABLE
-}
-
-static void
-pc98_i8251_set_cmd(struct com_s *com, int x)
-{
- int tmp;
-
- COM_INT_DISABLE
- if (com->pc98_8251fifo_enable)
- outb(I8251F_fcr, 0);
- tmp = (x);
- outb(com->cmd_port, tmp);
- com->pc98_prev_siocmd = tmp & ~(CMD8251_ER|CMD8251_RESET|CMD8251_EH);
- if (com->pc98_8251fifo_enable)
- outb(I8251F_fcr, CTRL8251F_ENABLE);
- COM_INT_ENABLE
-}
-
-static void
-pc98_i8251_clear_or_cmd(struct com_s *com, int clr, int x)
-{
- int tmp;
- COM_INT_DISABLE
- if (com->pc98_8251fifo_enable)
- outb(I8251F_fcr, 0);
- tmp = com->pc98_prev_siocmd & ~(clr);
- tmp |= (x);
- outb(com->cmd_port, tmp);
- com->pc98_prev_siocmd = tmp & ~(CMD8251_ER|CMD8251_RESET|CMD8251_EH);
- if (com->pc98_8251fifo_enable)
- outb(I8251F_fcr, CTRL8251F_ENABLE);
- COM_INT_ENABLE
-}
-
-static int
-pc98_i8251_get_cmd(struct com_s *com)
-{
- return com->pc98_prev_siocmd;
-}
-
-static int
-pc98_i8251_get_mod(struct com_s *com)
-{
- return com->pc98_prev_siomod;
-}
-
-static void
-pc98_i8251_reset(struct com_s *com, int mode, int command)
-{
- if (com->pc98_8251fifo_enable)
- outb(I8251F_fcr, 0);
- outb(com->cmd_port, 0); /* dummy */
- DELAY(2);
- outb(com->cmd_port, 0); /* dummy */
- DELAY(2);
- outb(com->cmd_port, 0); /* dummy */
- DELAY(2);
- outb(com->cmd_port, CMD8251_RESET); /* internal reset */
- DELAY(2);
- outb(com->cmd_port, mode ); /* mode register */
- com->pc98_prev_siomod = mode;
- DELAY(2);
- pc98_i8251_set_cmd( com, (command|CMD8251_ER) );
- DELAY(10);
- if (com->pc98_8251fifo_enable)
- outb(I8251F_fcr, CTRL8251F_ENABLE |
- CTRL8251F_XMT_RST | CTRL8251F_RCV_RST);
-}
-
-static void
-pc98_check_sysclock(void)
-{
- /* get system clock from port */
- if ( pc98_machine_type & M_8M ) {
- /* 8 MHz system & H98 */
- sysclock = 8;
- } else {
- /* 5 MHz system */
- sysclock = 5;
- }
-}
-
-static void
-com_cflag_and_speed_set( struct com_s *com, int cflag, int speed)
-{
- int cfcr=0;
- int previnterrupt;
- u_int count;
-
- if (pc98_ttspeedtab(com, speed, &count) != 0)
- return;
-
- previnterrupt = pc98_check_i8251_interrupt(com);
- pc98_disable_i8251_interrupt( com, IEN_Tx|IEN_TxEMP|IEN_Rx );
-
- switch ( cflag&CSIZE ) {
- case CS5:
- cfcr = MOD8251_5BITS; break;
- case CS6:
- cfcr = MOD8251_6BITS; break;
- case CS7:
- cfcr = MOD8251_7BITS; break;
- case CS8:
- cfcr = MOD8251_8BITS; break;
- }
- if ( cflag&PARENB ) {
- if ( cflag&PARODD )
- cfcr |= MOD8251_PODD;
- else
- cfcr |= MOD8251_PEVEN;
- } else
- cfcr |= MOD8251_PDISAB;
-
- if ( cflag&CSTOPB )
- cfcr |= MOD8251_STOP2;
- else
- cfcr |= MOD8251_STOP1;
-
- if ( count & 0x10000 )
- cfcr |= MOD8251_CLKX1;
- else
- cfcr |= MOD8251_CLKX16;
-
- if (epson_machine_id != 0x20) { /* XXX */
- int tmp;
- while (!((tmp = inb(com->sts_port)) & STS8251_TxEMP))
- ;
- }
- /* set baud rate from ospeed */
- pc98_set_baud_rate( com, count );
-
- if ( cfcr != pc98_i8251_get_mod(com) )
- pc98_i8251_reset(com, cfcr, pc98_i8251_get_cmd(com) );
-
- pc98_enable_i8251_interrupt( com, previnterrupt );
-}
-
-static int
-pc98_ttspeedtab(struct com_s *com, int speed, u_int *divisor)
-{
- int if_type, effect_sp, count = -1, mod;
-
- if_type = com->pc98_if_type & 0x0f;
-
- switch (com->pc98_if_type) {
- case COM_IF_INTERNAL:
- if (PC98SIO_baud_rate_port(if_type) != -1) {
- count = ttspeedtab(speed, if_8251_type[if_type].speedtab);
- if (count > 0) {
- count |= COM1_EXT_CLOCK;
- break;
- }
- }
-
- /* for *1CLK asynchronous! mode, TEFUTEFU */
- mod = (sysclock == 5) ? 2457600 : 1996800;
- effect_sp = ttspeedtab( speed, pc98speedtab );
- if ( effect_sp < 0 ) /* XXX */
- effect_sp = ttspeedtab( (speed - 1), pc98speedtab );
- if ( effect_sp <= 0 )
- return effect_sp;
- if ( effect_sp == speed )
- mod /= 16;
- if ( mod % effect_sp )
- return(-1);
- count = mod / effect_sp;
- if ( count > 65535 )
- return(-1);
- if ( effect_sp != speed )
- count |= 0x10000;
- break;
- case COM_IF_PC9861K_1:
- case COM_IF_PC9861K_2:
- count = 1;
- break;
- case COM_IF_IND_SS_1:
- case COM_IF_IND_SS_2:
- case COM_IF_PIO9032B_1:
- case COM_IF_PIO9032B_2:
- count = ttspeedtab( speed, if_8251_type[if_type].speedtab );
- break;
- case COM_IF_B98_01_1:
- case COM_IF_B98_01_2:
- count = ttspeedtab( speed, if_8251_type[if_type].speedtab );
-#ifdef B98_01_OLD
- if (count == 0 || count == 1) {
- count += 4;
- count |= 0x20000; /* x1 mode for 76800 and 153600 */
- }
-#endif
- break;
- }
-
- if (count < 0)
- return count;
-
- *divisor = (u_int) count;
- return 0;
-}
-
-static void
-pc98_set_baud_rate( struct com_s *com, u_int count )
-{
- int if_type, io, s;
-
- if_type = com->pc98_if_type & 0x0f;
- io = rman_get_start(com->ioportres) & 0xff00;
-
- switch (com->pc98_if_type) {
- case COM_IF_INTERNAL:
- if (PC98SIO_baud_rate_port(if_type) != -1) {
- if (count & COM1_EXT_CLOCK) {
- outb((Port_t)PC98SIO_baud_rate_port(if_type), count & 0xff);
- break;
- } else {
- outb((Port_t)PC98SIO_baud_rate_port(if_type), 0x09);
- }
- }
-
- if (count == 0)
- return;
-
- /* set i8253 */
- s = splclock();
- if (count != 3)
- outb( 0x77, 0xb6 );
- else
- outb( 0x77, 0xb4 );
- outb( 0x5f, 0);
- outb( 0x75, count & 0xff );
- outb( 0x5f, 0);
- outb( 0x75, (count >> 8) & 0xff );
- splx(s);
- break;
- case COM_IF_IND_SS_1:
- case COM_IF_IND_SS_2:
- outb(io | PC98SIO_intr_ctrl_port(if_type), 0);
- outb(io | PC98SIO_baud_rate_port(if_type), 0);
- outb(io | PC98SIO_baud_rate_port(if_type), 0xc0);
- outb(io | PC98SIO_baud_rate_port(if_type), (count >> 8) | 0x80);
- outb(io | PC98SIO_baud_rate_port(if_type), count & 0xff);
- break;
- case COM_IF_PIO9032B_1:
- case COM_IF_PIO9032B_2:
- outb(io | PC98SIO_baud_rate_port(if_type), count);
- break;
- case COM_IF_B98_01_1:
- case COM_IF_B98_01_2:
- outb(io | PC98SIO_baud_rate_port(if_type), count & 0x0f);
-#ifdef B98_01_OLD
- /*
- * Some old B98_01 board should be controlled
- * in different way, but this hasn't been tested yet.
- */
- outb(io | PC98SIO_func_port(if_type),
- (count & 0x20000) ? 0xf0 : 0xf2);
-#endif
- break;
- }
-}
-static int
-pc98_check_if_type(device_t dev, struct siodev *iod)
-{
- int irr, io, if_type, tmp;
- static short irq_tab[2][8] = {
- { 3, 5, 6, 9, 10, 12, 13, -1},
- { 3, 10, 12, 13, 5, 6, 9, -1}
- };
-
- if_type = iod->if_type & 0x0f;
- iod->irq = 0;
- io = isa_get_port(dev) & 0xff00;
-
- if (IS_8251(iod->if_type)) {
- if (PC98SIO_func_port(if_type) != -1) {
- outb(io | PC98SIO_func_port(if_type), 0xf2);
- tmp = ttspeedtab(9600, if_8251_type[if_type].speedtab);
- if (tmp != -1 && PC98SIO_baud_rate_port(if_type) != -1)
- outb(io | PC98SIO_baud_rate_port(if_type), tmp);
- }
-
- iod->cmd = io | PC98SIO_cmd_port(if_type);
- iod->sts = io | PC98SIO_sts_port(if_type);
- iod->mod = io | PC98SIO_in_modem_port(if_type);
- iod->ctrl = io | PC98SIO_intr_ctrl_port(if_type);
-
- if (iod->if_type == COM_IF_INTERNAL) {
- iod->irq = 4;
-
- if (pc98_check_8251vfast()) {
- PC98SIO_baud_rate_port(if_type) = I8251F_div;
- if_8251_type[if_type].speedtab = pc98fast_speedtab;
- }
- } else {
- tmp = inb( iod->mod ) & if_8251_type[if_type].irr_mask;
- if ((isa_get_port(dev) & 0xff) == IO_COM2)
- iod->irq = irq_tab[0][tmp];
- else
- iod->irq = irq_tab[1][tmp];
- }
- } else {
- irr = if_16550a_type[if_type].irr_read;
-#ifdef COM_MULTIPORT
- if (!COM_ISMULTIPORT(device_get_flags(dev)) ||
- device_get_unit(dev) == COM_MPMASTER(device_get_flags(dev)))
-#endif
- if (irr != -1) {
- tmp = inb(io | irr);
- if (isa_get_port(dev) & 0x01) /* XXX depend on RSB-384 */
- iod->irq = irq_tab[1][tmp >> 3];
- else
- iod->irq = irq_tab[0][tmp & 0x07];
- }
- }
- if ( iod->irq == -1 ) return -1;
-
- return 0;
-}
-static void
-pc98_set_ioport(struct com_s *com)
-{
- int if_type = com->pc98_if_type & 0x0f;
- Port_t io = rman_get_start(com->ioportres) & 0xff00;
-
- pc98_check_sysclock();
- com->data_port = io | PC98SIO_data_port(if_type);
- com->cmd_port = io | PC98SIO_cmd_port(if_type);
- com->sts_port = io | PC98SIO_sts_port(if_type);
- com->in_modem_port = io | PC98SIO_in_modem_port(if_type);
- com->intr_ctrl_port = io | PC98SIO_intr_ctrl_port(if_type);
-}
-static int
-pc98_check_8251vfast(void)
-{
- int i;
-
- outb(I8251F_div, 0x8c);
- DELAY(10);
- for (i = 0; i < 100; i++) {
- if ((inb(I8251F_div) & 0x80) != 0) {
- i = 0;
- break;
- }
- DELAY(1);
- }
- outb(I8251F_div, 0);
- DELAY(10);
- for (; i < 100; i++) {
- if ((inb(I8251F_div) & 0x80) == 0)
- return 1;
- DELAY(1);
- }
-
- return 0;
-}
-static int
-pc98_check_8251fifo(void)
-{
- u_char tmp1, tmp2;
-
- tmp1 = inb(I8251F_iir);
- DELAY(10);
- tmp2 = inb(I8251F_iir);
- if (((tmp1 ^ tmp2) & 0x40) != 0 && ((tmp1 | tmp2) & 0x20) == 0)
- return 1;
-
- return 0;
-}
-#endif /* PC98 defined */
diff --git a/sys/pc98/cbus/sio_cbus.c b/sys/pc98/cbus/sio_cbus.c
deleted file mode 100644
index 10bbdc1f45f6..000000000000
--- a/sys/pc98/cbus/sio_cbus.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2001 Yoshihiro TAKAHASHI. 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.
- *
- * $FreeBSD$
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/conf.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/module.h>
-#include <sys/tty.h>
-#include <machine/bus_pio.h>
-#include <machine/bus.h>
-#include <sys/timepps.h>
-
-#include <dev/sio/siovar.h>
-
-#include <isa/isavar.h>
-
-static int sio_isa_attach(device_t dev);
-static int sio_isa_probe(device_t dev);
-
-static device_method_t sio_isa_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, sio_isa_probe),
- DEVMETHOD(device_attach, sio_isa_attach),
-
- { 0, 0 }
-};
-
-static driver_t sio_isa_driver = {
- sio_driver_name,
- sio_isa_methods,
- 0,
-};
-
-static struct isa_pnp_id sio_ids[] = {
- {0x0100e4a5, "RSA-98III"},
- {0x11802fbf, NULL}, /* OYO8011 - PC-9801-12X */
- {0x4180a3b8, NULL}, /* NEC8041 - PC-9821CB-B04 */
- {0x4182a3b8, NULL}, /* NEC8241 - (Nw150) */
- {0x5181a3b8, NULL}, /* NEC8151 - PC-9821CB2-B04 */
- {0x5182a3b8, NULL}, /* NEC8251 - PC-9801-12X */
- {0x7182a3b8, NULL}, /* NEC8271 - PC-9801-12X */
- {0x9181a3b8, NULL}, /* NEC8191 - PC-9801-120 */
- {0}
-};
-
-static int
-sio_isa_probe(dev)
- device_t dev;
-{
- int logical_id;
-
- /* Check isapnp ids */
- if (ISA_PNP_PROBE(device_get_parent(dev), dev, sio_ids) == ENXIO)
- return (ENXIO);
-
- logical_id = isa_get_logicalid(dev);
- switch (logical_id) {
- case 0x0100e4a5: /* RSA-98III */
- SET_FLAG(dev, SET_IFTYPE(COM_IF_RSA98III));
- break;
- case 0x11802fbf: /* PC-9801-12X */
- case 0x4180a3b8: /* PC-9821CB-B04 */
- case 0x4182a3b8: /* (Nw150) */
- case 0x5181a3b8: /* PC-9821CB2-B04 */
- case 0x5182a3b8: /* PC-9801-12X */
- case 0x7182a3b8: /* PC-9801-12X */
- case 0x9181a3b8: /* PC-9801-120 */
- SET_FLAG(dev, SET_IFTYPE(COM_IF_NS16550));
- break;
- }
-
- return (sioprobe(dev, 0, 0UL, 0));
-}
-
-static int
-sio_isa_attach(dev)
- device_t dev;
-{
- return (sioattach(dev, 0, 0UL));
-}
-
-DRIVER_MODULE(sio, isa, sio_isa_driver, sio_devclass, 0, 0);
diff --git a/sys/pc98/cbus/syscons_cbus.c b/sys/pc98/cbus/syscons_cbus.c
deleted file mode 100644
index 14a096ae9adf..000000000000
--- a/sys/pc98/cbus/syscons_cbus.c
+++ /dev/null
@@ -1,263 +0,0 @@
-/*-
- * Copyright (c) 1999 FreeBSD(98) Porting Team.
- * 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 as
- * the first lines of this file unmodified.
- * 2. Redistributions in binary form must 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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (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$
- */
-
-#include "opt_syscons.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/module.h>
-#include <sys/bus.h>
-#include <sys/cons.h>
-#include <sys/consio.h>
-#include <sys/sysctl.h>
-
-#include <machine/clock.h>
-
-#include <pc98/pc98/pc98.h>
-#include <pc98/pc98/pc98_machdep.h>
-
-#include <dev/syscons/syscons.h>
-
-#include <i386/isa/timerreg.h>
-
-#include <isa/isavar.h>
-
-static devclass_t sc_devclass;
-
-static sc_softc_t main_softc;
-#ifdef SC_NO_SUSPEND_VTYSWITCH
-static int sc_no_suspend_vtswitch = 1;
-#else
-static int sc_no_suspend_vtswitch = 0;
-#endif
-static int sc_cur_scr;
-
-TUNABLE_INT("hw.syscons.sc_no_suspend_vtswitch", (int *)&sc_no_suspend_vtswitch);
-SYSCTL_DECL(_hw_syscons);
-SYSCTL_INT(_hw_syscons, OID_AUTO, sc_no_suspend_vtswitch, CTLFLAG_RW,
- &sc_no_suspend_vtswitch, 0, "Disable VT switch before suspend.");
-
-static void
-scidentify (driver_t *driver, device_t parent)
-{
- BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "sc", 0);
-}
-
-static int
-scprobe(device_t dev)
-{
- /* No pnp support */
- if (isa_get_vendorid(dev))
- return (ENXIO);
-
- device_set_desc(dev, "System console");
- return sc_probe_unit(device_get_unit(dev), device_get_flags(dev));
-}
-
-static int
-scattach(device_t dev)
-{
- return sc_attach_unit(device_get_unit(dev), device_get_flags(dev));
-}
-
-static int
-scsuspend(device_t dev)
-{
- int retry = 10;
- static int dummy;
- sc_softc_t *sc;
-
- sc = &main_softc;
- sc_cur_scr = sc->cur_scp->index;
-
- if (sc_no_suspend_vtswitch)
- return (0);
-
- do {
- sc_switch_scr(sc, 0);
- if (!sc->switch_in_progress) {
- break;
- }
- tsleep(&dummy, 0, "scsuspend", 100);
- } while (retry--);
-
- return (0);
-}
-
-static int
-scresume(device_t dev)
-{
- sc_softc_t *sc;
-
- if (sc_no_suspend_vtswitch)
- return (0);
-
- sc = &main_softc;
- sc_switch_scr(sc, sc_cur_scr);
-
- return (0);
-}
-
-int
-sc_max_unit(void)
-{
- return devclass_get_maxunit(sc_devclass);
-}
-
-sc_softc_t
-*sc_get_softc(int unit, int flags)
-{
- sc_softc_t *sc;
-
- if (unit < 0)
- return NULL;
- if (flags & SC_KERNEL_CONSOLE) {
- /* FIXME: clear if it is wired to another unit! */
- sc = &main_softc;
- } else {
- sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, unit));
- if (sc == NULL)
- return NULL;
- }
- sc->unit = unit;
- if (!(sc->flags & SC_INIT_DONE)) {
- sc->keyboard = -1;
- sc->adapter = -1;
- sc->mouse_char = SC_MOUSE_CHAR;
- }
- return sc;
-}
-
-sc_softc_t
-*sc_find_softc(struct video_adapter *adp, struct keyboard *kbd)
-{
- sc_softc_t *sc;
- int units;
- int i;
-
- sc = &main_softc;
- if (((adp == NULL) || (adp == sc->adp))
- && ((kbd == NULL) || (kbd == sc->kbd)))
- return sc;
- units = devclass_get_maxunit(sc_devclass);
- for (i = 0; i < units; ++i) {
- sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, i));
- if (sc == NULL)
- continue;
- if (((adp == NULL) || (adp == sc->adp))
- && ((kbd == NULL) || (kbd == sc->kbd)))
- return sc;
- }
- return NULL;
-}
-
-int
-sc_get_cons_priority(int *unit, int *flags)
-{
- int disabled;
- const char *at;
- int u, f;
-
- *unit = -1;
- for (u = 0; u < 16; u++) {
- if ((resource_int_value(SC_DRIVER_NAME, u, "disabled",
- &disabled) == 0) && disabled)
- continue;
- if (resource_string_value(SC_DRIVER_NAME, u, "at", &at) != 0)
- continue;
- if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0)
- f = 0;
- if (f & SC_KERNEL_CONSOLE) {
- /* the user designates this unit to be the console */
- *unit = u;
- *flags = f;
- break;
- }
- if (*unit < 0) {
- /* ...otherwise remember the first found unit */
- *unit = u;
- *flags = f;
- }
- }
- if (*unit < 0)
- return CN_DEAD;
- return CN_INTERNAL;
-}
-
-void
-sc_get_bios_values(bios_values_t *values)
-{
- values->cursor_start = 15;
- values->cursor_end = 16;
- values->shift_state = 0;
- if (pc98_machine_type & M_8M)
- values->bell_pitch = BELL_PITCH_8M;
- else
- values->bell_pitch = BELL_PITCH_5M;
-}
-
-int
-sc_tone(int herz)
-{
- int pitch;
-
- if (herz) {
- /* enable counter 1 */
- outb(0x35, inb(0x35) & 0xf7);
- /* set command for counter 1, 2 byte write */
- if (acquire_timer1(TIMER_16BIT | TIMER_SQWAVE))
- return EBUSY;
- /* set pitch */
- pitch = timer_freq/herz;
- outb(TIMER_CNTR1, pitch);
- outb(TIMER_CNTR1, pitch >> 8);
- } else {
- /* disable counter 1 */
- outb(0x35, inb(0x35) | 0x08);
- release_timer1();
- }
- return 0;
-}
-
-static device_method_t sc_methods[] = {
- DEVMETHOD(device_identify, scidentify),
- DEVMETHOD(device_probe, scprobe),
- DEVMETHOD(device_attach, scattach),
- DEVMETHOD(device_suspend, scsuspend),
- DEVMETHOD(device_resume, scresume),
- { 0, 0 }
-};
-
-static driver_t sc_driver = {
- SC_DRIVER_NAME,
- sc_methods,
- sizeof(sc_softc_t),
-};
-
-DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0);
diff --git a/sys/pc98/pc98/busio.s b/sys/pc98/pc98/busio.s
deleted file mode 100644
index 1e8a42f7131c..000000000000
--- a/sys/pc98/pc98/busio.s
+++ /dev/null
@@ -1,1774 +0,0 @@
-/* $FreeBSD$ */
-/* $NecBSD: busio.s,v 1.16.4.1 1999/08/16 09:06:08 kmatsuda Exp $ */
-/* $NetBSD$ */
-
-/*
- * [NetBSD for NEC PC-98 series]
- * Copyright (c) 1996, 1997, 1998
- * NetBSD/pc98 porting staff. All rights reserved.
- *
- * [Ported for FreeBSD]
- * Copyright (c) 2001
- * TAKAHASHI Yoshihiro. 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.
- */
-
-/*
- * Copyright (c) 1997, 1998
- * Naofumi HONDA. All rights reserved.
- */
-
-#include <machine/asm.h>
-
-#include "assym.s"
-
-/***********************************************************
- * Bus IO access methods (Direct Access)
- ***********************************************************/
-#define BUS_ACCESS_ADDR(BSHREG,ADDRREG) \
- addl BUS_SPACE_HANDLE_BASE/**/(%/**/BSHREG/**/),%/**/ADDRREG
-
-/*
- * read_N
- * IN: edx port
- * OUT: eax data
- */
-ENTRY(SBUS_DA_io_space_read_1)
- BUS_ACCESS_ADDR(ebx,edx)
- inb %dx,%al
- ret
-
-ENTRY(SBUS_DA_io_space_read_2)
- BUS_ACCESS_ADDR(ebx,edx)
- inw %dx,%ax
- ret
-
-ENTRY(SBUS_DA_io_space_read_4)
- BUS_ACCESS_ADDR(ebx,edx)
- inl %dx,%eax
- ret
-
-/*
- * write_N
- * IN:eax DATA
- * edx PORT
- */
-ENTRY(SBUS_DA_io_space_write_1)
- BUS_ACCESS_ADDR(ebx,edx)
- outb %al,%dx
- ret
-
-ENTRY(SBUS_DA_io_space_write_2)
- BUS_ACCESS_ADDR(ebx,edx)
- outw %ax,%dx
- ret
-
-ENTRY(SBUS_DA_io_space_write_4)
- BUS_ACCESS_ADDR(ebx,edx)
- outl %eax,%dx
- ret
-
-/*
- * read_multi_N
- * IN: ecx COUNT
- * edx PORT
- * edi BUFP
- */
-ENTRY(SBUS_DA_io_space_read_multi_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- rep
- insb
- ret
-
-ENTRY(SBUS_DA_io_space_read_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- rep
- insw
- ret
-
-ENTRY(SBUS_DA_io_space_read_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- rep
- insl
- ret
-
-/*
- * write_multi_N
- * IN: ecx COUNT
- * edx PORT
- * esi BUFP
- */
-ENTRY(SBUS_DA_io_space_write_multi_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- rep
- outsb
- ret
-
-ENTRY(SBUS_DA_io_space_write_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- rep
- outsw
- ret
-
-ENTRY(SBUS_DA_io_space_write_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- rep
- outsl
- ret
-
-/*
- * read_region_N
- * IN: ecx COUNT
- * edx PORT
- * edi BUFP
- */
-ENTRY(SBUS_DA_io_space_read_region_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- inb %dx,%al
- stosb
- incl %edx
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-ENTRY(SBUS_DA_io_space_read_region_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- inw %dx,%ax
- stosw
- addl $2,%edx
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-ENTRY(SBUS_DA_io_space_read_region_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- inl %dx,%eax
- stosl
- addl $4,%edx
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-/*
- * write_region_N
- * IN: ecx COUNT
- * edx PORT
- * esi BUFP
- */
-ENTRY(SBUS_DA_io_space_write_region_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- lodsb
- outb %al,%dx
- incl %edx
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-ENTRY(SBUS_DA_io_space_write_region_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- lodsw
- outw %ax,%dx
- addl $2,%edx
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-ENTRY(SBUS_DA_io_space_write_region_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- lodsl
- outl %eax,%dx
- addl $4,%edx
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-/*
- * set_multi_N
- * IN: eax DATA
- * ecx COUNT
- * edx PORT
- */
-ENTRY(SBUS_DA_io_space_set_multi_1)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- outb %al,%dx
- decl %ecx
- jnz 1b
-2:
- ret
-
-ENTRY(SBUS_DA_io_space_set_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- outw %ax,%dx
- decl %ecx
- jnz 1b
-2:
- ret
-
-ENTRY(SBUS_DA_io_space_set_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- outl %eax,%dx
- decl %ecx
- jnz 1b
-2:
- ret
-
-/*
- * set_region_N
- * IN: eax DATA
- * ecx COUNT
- * edx PORT
- */
-ENTRY(SBUS_DA_io_space_set_region_1)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- outb %al,%dx
- incl %edx
- decl %ecx
- jnz 1b
-2:
- ret
-
-ENTRY(SBUS_DA_io_space_set_region_2)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- outw %ax,%dx
- addl $2,%edx
- decl %ecx
- jnz 1b
-2:
- ret
-
-ENTRY(SBUS_DA_io_space_set_region_4)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- outl %eax,%dx
- addl $4,%edx
- decl %ecx
- jnz 1b
-2:
- ret
-
-/*
- * copy_region_N
- * IN: ecx COUNT
- * esi SPORT
- * edi DPORT
- */
-ENTRY(SBUS_DA_io_space_copy_region_1)
- BUS_ACCESS_ADDR(eax,esi)
- BUS_ACCESS_ADDR(ebx,edi)
- pushl %eax
- pushl %edx
- orl %ecx,%ecx
- jz 2f
-1:
- movl %esi,%edx
- inb %dx,%al
- incl %esi
-
- movl %edi,%edx
- outb %al,%dx
- incl %edi
-
- decl %ecx
- jnz 1b
-2:
- popl %edx
- popl %eax
- ret
-
-ENTRY(SBUS_DA_io_space_copy_region_2)
- BUS_ACCESS_ADDR(eax,esi)
- BUS_ACCESS_ADDR(ebx,edi)
- pushl %eax
- pushl %edx
- orl %ecx,%ecx
- jz 2f
-1:
- movl %esi,%edx
- inw %dx,%ax
- addl $2,%esi
-
- movl %edi,%edx
- outw %ax,%dx
- addl $2,%edi
-
- decl %ecx
- jnz 1b
-2:
- popl %edx
- popl %eax
- ret
-
-ENTRY(SBUS_DA_io_space_copy_region_4)
- BUS_ACCESS_ADDR(eax,esi)
- BUS_ACCESS_ADDR(ebx,edi)
- pushl %eax
- pushl %edx
- orl %ecx,%ecx
- jz 2f
-1:
- movl %esi,%edx
- inl %dx,%eax
- addl $4,%esi
-
- movl %edi,%edx
- outl %eax,%dx
- addl $4,%edi
-
- decl %ecx
- jnz 1b
-2:
- popl %edx
- popl %eax
- ret
-
-/***********************************************************
- * Bus Memory access methods (Direct Access)
- ***********************************************************/
-/*
- * read_N
- */
-ENTRY(SBUS_DA_mem_space_read_1)
- BUS_ACCESS_ADDR(ebx,edx)
- movb (%edx),%al
- ret
-
-ENTRY(SBUS_DA_mem_space_read_2)
- BUS_ACCESS_ADDR(ebx,edx)
- movw (%edx),%ax
- ret
-
-ENTRY(SBUS_DA_mem_space_read_4)
- BUS_ACCESS_ADDR(ebx,edx)
- movl (%edx),%eax
- ret
-
-/*
- * write_N
- */
-ENTRY(SBUS_DA_mem_space_write_1)
- BUS_ACCESS_ADDR(ebx,edx)
- movb %al,(%edx)
- ret
-
-ENTRY(SBUS_DA_mem_space_write_2)
- BUS_ACCESS_ADDR(ebx,edx)
- movw %ax,(%edx)
- ret
-
-ENTRY(SBUS_DA_mem_space_write_4)
- BUS_ACCESS_ADDR(ebx,edx)
- movl %eax,(%edx)
- ret
-
-/*
- * read_multi_N
- */
-ENTRY(SBUS_DA_mem_space_read_multi_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- movb (%edx),%al
- stosb
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-ENTRY(SBUS_DA_mem_space_read_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- movw (%edx),%ax
- stosw
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-ENTRY(SBUS_DA_mem_space_read_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- movl (%edx),%eax
- stosl
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-/*
- * write_multi_N
- */
-ENTRY(SBUS_DA_mem_space_write_multi_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- lodsb
- movb %al,(%edx)
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-ENTRY(SBUS_DA_mem_space_write_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- lodsw
- movw %ax,(%edx)
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-ENTRY(SBUS_DA_mem_space_write_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- lodsl
- movl %eax,(%edx)
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-/*
- * read_region_N
- */
-ENTRY(SBUS_DA_mem_space_read_region_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %esi
- movl %edx,%esi
- rep
- movsb
- popl %esi
- ret
-
-ENTRY(SBUS_DA_mem_space_read_region_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %esi
- movl %edx,%esi
- rep
- movsw
- popl %esi
- ret
-
-ENTRY(SBUS_DA_mem_space_read_region_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %esi
- movl %edx,%esi
- rep
- movsl
- popl %esi
- ret
-
-/*
- * write_region_N
- */
-ENTRY(SBUS_DA_mem_space_write_region_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %edi
- movl %edx,%edi
- rep
- movsb
- popl %edi
- ret
-
-ENTRY(SBUS_DA_mem_space_write_region_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %edi
- movl %edx,%edi
- rep
- movsw
- popl %edi
- ret
-
-ENTRY(SBUS_DA_mem_space_write_region_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %edi
- movl %edx,%edi
- rep
- movsl
- popl %edi
- ret
-
-/*
- * set_multi_N
- */
-ENTRY(SBUS_DA_mem_space_set_multi_1)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- movb %al,(%edx)
- decl %ecx
- jnz 1b
-2:
- ret
-
-ENTRY(SBUS_DA_mem_space_set_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- movw %ax,(%edx)
- decl %ecx
- jnz 1b
-2:
- ret
-
-ENTRY(SBUS_DA_mem_space_set_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- movl %eax,(%edx)
- decl %ecx
- jnz 1b
-2:
- ret
-
-/*
- * set_region_N
- */
-ENTRY(SBUS_DA_mem_space_set_region_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %edi
- movl %edx,%edi
- rep
- stosb
- popl %edi
- ret
-
-ENTRY(SBUS_DA_mem_space_set_region_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %edi
- movl %edx,%edi
- rep
- stosw
- popl %edi
- ret
-
-ENTRY(SBUS_DA_mem_space_set_region_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %edi
- movl %edx,%edi
- rep
- stosl
- popl %edi
- ret
-
-/*
- * copy_region_N
- */
-ENTRY(SBUS_DA_mem_space_copy_region_1)
- BUS_ACCESS_ADDR(eax,esi)
- BUS_ACCESS_ADDR(ebx,edi)
- cld
- rep
- movsb
- ret
-
-ENTRY(SBUS_DA_mem_space_copy_region_2)
- BUS_ACCESS_ADDR(eax,esi)
- BUS_ACCESS_ADDR(ebx,edi)
- cld
- rep
- movsw
- ret
-
-ENTRY(SBUS_DA_mem_space_copy_region_4)
- BUS_ACCESS_ADDR(eax,esi)
- BUS_ACCESS_ADDR(ebx,edi)
- cld
- rep
- movsl
- ret
-
-#undef BUS_ACCESS_ADDR
-
-/***********************************************************
- * Bus IO access methods (Relocate Access)
- ***********************************************************/
-#define BUS_ACCESS_ADDR(BSHREG,ADDRREG) \
- movl BUS_SPACE_HANDLE_IAT/**/(%/**/BSHREG/**/, %/**/ADDRREG/**/, 4), \
- %/**/ADDRREG
-#define BUS_ACCESS_ADDR2(BSHREG,ADDRREG,DSTREG) \
- movl BUS_SPACE_HANDLE_IAT/**/(%/**/BSHREG/**/, %/**/ADDRREG/**/, 4), \
- %/**/DSTREG
-/*
- * read_N
- * IN: edx port
- * OUT: eax data
- */
-ENTRY(SBUS_RA_io_space_read_1)
- BUS_ACCESS_ADDR(ebx,edx)
- inb %dx,%al
- ret
-
-ENTRY(SBUS_RA_io_space_read_2)
- BUS_ACCESS_ADDR(ebx,edx)
- inw %dx,%ax
- ret
-
-ENTRY(SBUS_RA_io_space_read_4)
- BUS_ACCESS_ADDR(ebx,edx)
- inl %dx,%eax
- ret
-
-/*
- * write_N
- * IN:eax DATA
- * edx PORT
- */
-ENTRY(SBUS_RA_io_space_write_1)
- BUS_ACCESS_ADDR(ebx,edx)
- outb %al,%dx
- ret
-
-ENTRY(SBUS_RA_io_space_write_2)
- BUS_ACCESS_ADDR(ebx,edx)
- outw %ax,%dx
- ret
-
-ENTRY(SBUS_RA_io_space_write_4)
- BUS_ACCESS_ADDR(ebx,edx)
- outl %eax,%dx
- ret
-
-/*
- * read_multi_N
- * IN: ecx COUNT
- * edx PORT
- * edi BUFP
- */
-ENTRY(SBUS_RA_io_space_read_multi_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- rep
- insb
- ret
-
-ENTRY(SBUS_RA_io_space_read_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- rep
- insw
- ret
-
-ENTRY(SBUS_RA_io_space_read_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- rep
- insl
- ret
-
-/*
- * write_multi_N
- * IN: ecx COUNT
- * edx PORT
- * esi BUFP
- */
-ENTRY(SBUS_RA_io_space_write_multi_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- rep
- outsb
- ret
-
-ENTRY(SBUS_RA_io_space_write_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- rep
- outsw
- ret
-
-ENTRY(SBUS_RA_io_space_write_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- rep
- outsl
- ret
-
-/*
- * read_region_N
- * IN: ecx COUNT
- * edx PORT
- * edi BUFP
- */
-ENTRY(SBUS_RA_io_space_read_region_1)
- cld
- pushl %eax
- pushl %esi
- orl %ecx,%ecx
- jz 2f
- movl %edx,%esi
-1:
- BUS_ACCESS_ADDR2(ebx,esi,edx)
- inb %dx,%al
- stosb
- incl %esi
- decl %ecx
- jnz 1b
-2:
- popl %esi
- popl %eax
- ret
-
-ENTRY(SBUS_RA_io_space_read_region_2)
- cld
- pushl %eax
- pushl %esi
- orl %ecx,%ecx
- jz 2f
- movl %edx,%esi
-1:
- BUS_ACCESS_ADDR2(ebx,esi,edx)
- inw %dx,%ax
- stosw
- addl $2,%esi
- decl %ecx
- jnz 1b
-2:
- popl %esi
- popl %eax
- ret
-
-ENTRY(SBUS_RA_io_space_read_region_4)
- cld
- pushl %eax
- pushl %esi
- orl %ecx,%ecx
- jz 2f
- movl %edx,%esi
-1:
- BUS_ACCESS_ADDR2(ebx,esi,edx)
- inl %dx,%eax
- stosl
- addl $4,%esi
- decl %ecx
- jnz 1b
-2:
- popl %esi
- popl %eax
- ret
-
-/*
- * write_region_N
- * IN: ecx COUNT
- * edx PORT
- * esi BUFP
- */
-ENTRY(SBUS_RA_io_space_write_region_1)
- cld
- pushl %eax
- pushl %edi
- orl %ecx,%ecx
- jz 2f
- movl %edx,%edi
-1:
- BUS_ACCESS_ADDR2(ebx,edi,edx)
- lodsb
- outb %al,%dx
- incl %edi
- decl %ecx
- jnz 1b
-2:
- popl %edi
- popl %eax
- ret
-
-ENTRY(SBUS_RA_io_space_write_region_2)
- cld
- pushl %eax
- pushl %edi
- orl %ecx,%ecx
- jz 2f
- movl %edx,%edi
-1:
- BUS_ACCESS_ADDR2(ebx,edi,edx)
- lodsw
- outw %ax,%dx
- addl $2,%edi
- decl %ecx
- jnz 1b
-2:
- popl %edi
- popl %eax
- ret
-
-ENTRY(SBUS_RA_io_space_write_region_4)
- cld
- pushl %eax
- pushl %edi
- orl %ecx,%ecx
- jz 2f
- movl %edx,%edi
-1:
- BUS_ACCESS_ADDR2(ebx,edi,edx)
- lodsl
- outl %eax,%dx
- addl $4,%edi
- decl %ecx
- jnz 1b
-2:
- popl %edi
- popl %eax
- ret
-
-/*
- * set_multi_N
- * IN: eax DATA
- * ecx COUNT
- * edx PORT
- */
-ENTRY(SBUS_RA_io_space_set_multi_1)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- outb %al,%dx
- decl %ecx
- jnz 1b
-2:
- ret
-
-ENTRY(SBUS_RA_io_space_set_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- outw %ax,%dx
- decl %ecx
- jnz 1b
-2:
- ret
-
-ENTRY(SBUS_RA_io_space_set_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- outl %eax,%dx
- decl %ecx
- jnz 1b
-2:
- ret
-
-/*
- * set_region_N
- * IN: eax DATA
- * ecx COUNT
- * edx PORT
- */
-ENTRY(SBUS_RA_io_space_set_region_1)
- pushl %edi
- orl %ecx,%ecx
- jz 2f
- movl %edx,%edi
-1:
- BUS_ACCESS_ADDR2(ebx,edi,edx)
- outb %al,%dx
- incl %edi
- decl %ecx
- jnz 1b
-2:
- popl %edi
- ret
-
-ENTRY(SBUS_RA_io_space_set_region_2)
- pushl %edi
- orl %ecx,%ecx
- jz 2f
- movl %edx,%edi
-1:
- BUS_ACCESS_ADDR2(ebx,edi,edx)
- outw %ax,%dx
- addl $2,%edi
- decl %ecx
- jnz 1b
-2:
- popl %edi
- ret
-
-ENTRY(SBUS_RA_io_space_set_region_4)
- pushl %edi
- orl %ecx,%ecx
- jz 2f
- movl %edx,%edi
-1:
- BUS_ACCESS_ADDR2(ebx,edi,edx)
- outl %eax,%dx
- addl $4,%edi
- decl %ecx
- jnz 1b
-2:
- popl %edi
- ret
-
-/*
- * copy_region_N
- * IN: ecx COUNT
- * esi SPORT
- * edi DPORT
- */
-ENTRY(SBUS_RA_io_space_copy_region_1)
- pushl %eax
- pushl %edx
- orl %ecx,%ecx
- jz 2f
-1:
- BUS_ACCESS_ADDR2(ebx,esi,edx)
- inb %dx,%al
- incl %esi
-
- BUS_ACCESS_ADDR2(ebx,edi,edx)
- outb %al,%dx
- incl %edi
-
- decl %ecx
- jnz 1b
-2:
- popl %edx
- popl %eax
- ret
-
-ENTRY(SBUS_RA_io_space_copy_region_2)
- pushl %eax
- pushl %edx
- orl %ecx,%ecx
- jz 2f
-1:
- BUS_ACCESS_ADDR2(ebx,esi,edx)
- inw %dx,%ax
- addl $2,%esi
-
- BUS_ACCESS_ADDR2(ebx,edi,edx)
- outw %ax,%dx
- addl $2,%edi
-
- decl %ecx
- jnz 1b
-2:
- popl %edx
- popl %eax
- ret
-
-ENTRY(SBUS_RA_io_space_copy_region_4)
- pushl %eax
- pushl %edx
- orl %ecx,%ecx
- jz 2f
-1:
- BUS_ACCESS_ADDR2(ebx,esi,edx)
- inl %dx,%eax
- addl $4,%esi
-
- BUS_ACCESS_ADDR2(ebx,edi,edx)
- outl %eax,%dx
- addl $4,%edi
-
- decl %ecx
- jnz 1b
-2:
- popl %edx
- popl %eax
- ret
-
-/***********************************************************
- * Bus Memory access methods
- ***********************************************************/
-/*
- * read_N
- */
-ENTRY(SBUS_RA_mem_space_read_1)
- BUS_ACCESS_ADDR(ebx,edx)
- movb (%edx),%al
- ret
-
-ENTRY(SBUS_RA_mem_space_read_2)
- BUS_ACCESS_ADDR(ebx,edx)
- movw (%edx),%ax
- ret
-
-ENTRY(SBUS_RA_mem_space_read_4)
- BUS_ACCESS_ADDR(ebx,edx)
- movl (%edx),%eax
- ret
-
-/*
- * write_N
- */
-ENTRY(SBUS_RA_mem_space_write_1)
- BUS_ACCESS_ADDR(ebx,edx)
- movb %al,(%edx)
- ret
-
-ENTRY(SBUS_RA_mem_space_write_2)
- BUS_ACCESS_ADDR(ebx,edx)
- movw %ax,(%edx)
- ret
-
-ENTRY(SBUS_RA_mem_space_write_4)
- BUS_ACCESS_ADDR(ebx,edx)
- movl %eax,(%edx)
- ret
-
-/*
- * read_multi_N
- */
-ENTRY(SBUS_RA_mem_space_read_multi_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- movb (%edx),%al
- stosb
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-ENTRY(SBUS_RA_mem_space_read_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- movw (%edx),%ax
- stosw
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-ENTRY(SBUS_RA_mem_space_read_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- movl (%edx),%eax
- stosl
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-/*
- * write_multi_N
- */
-ENTRY(SBUS_RA_mem_space_write_multi_1)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- lodsb
- movb %al,(%edx)
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-ENTRY(SBUS_RA_mem_space_write_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- lodsw
- movw %ax,(%edx)
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-ENTRY(SBUS_RA_mem_space_write_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- cld
- pushl %eax
- orl %ecx,%ecx
- jz 2f
-1:
- lodsl
- movl %eax,(%edx)
- decl %ecx
- jnz 1b
-2:
- popl %eax
- ret
-
-/*
- * read_region_N
- */
-ENTRY(SBUS_RA_mem_space_read_region_1)
- cld
- pushl %esi
- orl %ecx,%ecx
- jz 2f
-1:
- BUS_ACCESS_ADDR2(ebx,edx,esi)
- movsb
- incl %edx
- decl %ecx
- jnz 1b
-2:
- popl %esi
- ret
-
-ENTRY(SBUS_RA_mem_space_read_region_2)
- cld
- pushl %esi
- orl %ecx,%ecx
- jz 2f
-1:
- BUS_ACCESS_ADDR2(ebx,edx,esi)
- movsw
- addl $2,%edx
- decl %ecx
- jnz 1b
-2:
- popl %esi
- ret
-
-ENTRY(SBUS_RA_mem_space_read_region_4)
- cld
- pushl %esi
- orl %ecx,%ecx
- jz 2f
-1:
- BUS_ACCESS_ADDR2(ebx,edx,esi)
- movsl
- addl $4,%edx
- decl %ecx
- jnz 1b
-2:
- popl %esi
- ret
-
-/*
- * write_region_N
- */
-ENTRY(SBUS_RA_mem_space_write_region_1)
- cld
- pushl %edi
- orl %ecx,%ecx
- jz 2f
-1:
- BUS_ACCESS_ADDR2(ebx,edx,edi)
- movsb
- incl %edx
- decl %ecx
- jnz 1b
-2:
- popl %edi
- ret
-
-ENTRY(SBUS_RA_mem_space_write_region_2)
- cld
- pushl %edi
- orl %ecx,%ecx
- jz 2f
-1:
- BUS_ACCESS_ADDR2(ebx,edx,edi)
- movsw
- addl $2,%edx
- decl %ecx
- jnz 1b
-2:
- popl %edi
- ret
-
-ENTRY(SBUS_RA_mem_space_write_region_4)
- cld
- pushl %edi
- orl %ecx,%ecx
- jz 2f
-1:
- BUS_ACCESS_ADDR2(ebx,edx,edi)
- movsl
- addl $4,%edx
- decl %ecx
- jnz 1b
-2:
- popl %edi
- ret
-
-/*
- * set_multi_N
- */
-ENTRY(SBUS_RA_mem_space_set_multi_1)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- movb %al,(%edx)
- decl %ecx
- jnz 1b
-2:
- ret
-
-ENTRY(SBUS_RA_mem_space_set_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- movw %ax,(%edx)
- decl %ecx
- jnz 1b
-2:
- ret
-
-ENTRY(SBUS_RA_mem_space_set_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- orl %ecx,%ecx
- jz 2f
-1:
- movl %eax,(%edx)
- decl %ecx
- jnz 1b
-2:
- ret
-
-/*
- * set_region_N
- */
-ENTRY(SBUS_RA_mem_space_set_region_1)
- cld
- pushl %edi
- orl %ecx,%ecx
- jz 2f
-1:
- BUS_ACCESS_ADDR2(ebx,edx,edi)
- stosb
- incl %edx
- decl %ecx
- jnz 1b
-2:
- popl %edi
- ret
-
-ENTRY(SBUS_RA_mem_space_set_region_2)
- cld
- pushl %edi
- orl %ecx,%ecx
- jz 2f
-1:
- BUS_ACCESS_ADDR2(ebx,edx,edi)
- stosw
- addl $2,%edx
- decl %ecx
- jnz 1b
-2:
- popl %edi
- ret
-
-ENTRY(SBUS_RA_mem_space_set_region_4)
- cld
- pushl %edi
- orl %ecx,%ecx
- jz 2f
-1:
- BUS_ACCESS_ADDR2(ebx,edx,edi)
- stosl
- addl $4,%edx
- decl %ecx
- jnz 1b
-2:
- popl %edi
- ret
-
-/*
- * copy_region_N
- */
-ENTRY(SBUS_RA_mem_space_copy_region_1)
- cld
- orl %ecx,%ecx
- jz 2f
-1:
- pushl %esi
- pushl %edi
- BUS_ACCESS_ADDR(eax,esi)
- BUS_ACCESS_ADDR(ebx,edi)
- movsb
- popl %edi
- popl %esi
- incl %esi
- incl %edi
- decl %ecx
- jnz 1b
-2:
- ret
-
-ENTRY(SBUS_RA_mem_space_copy_region_2)
- cld
- orl %ecx,%ecx
- jz 2f
-1:
- pushl %esi
- pushl %edi
- BUS_ACCESS_ADDR(eax,esi)
- BUS_ACCESS_ADDR(ebx,edi)
- movsw
- popl %edi
- popl %esi
- addl $2,%esi
- addl $2,%edi
- decl %ecx
- jnz 1b
-2:
- ret
-
-ENTRY(SBUS_RA_mem_space_copy_region_4)
- cld
- orl %ecx,%ecx
- jz 2f
-1:
- pushl %esi
- pushl %edi
- BUS_ACCESS_ADDR(eax,esi)
- BUS_ACCESS_ADDR(ebx,edi)
- movsl
- popl %edi
- popl %esi
- addl $4,%esi
- addl $4,%edi
- decl %ecx
- jnz 1b
-2:
- ret
-
-#undef BUS_ACCESS_ADDR
-#undef BUS_ACCESS_ADDR2
-
-
-#include "opt_mecia.h"
-#ifdef DEV_MECIA
-
-/***********************************************************
- * NEPC pcmcia 16 bits bus access
- ***********************************************************/
-#define NEPC_SWITCH_BUS16 \
- pushl %ebp ;\
- pushl %eax ;\
- pushl %edx ;\
- movl $0x2a8e,%edx ;\
- inb %dx,%al ;\
- movl %eax,%ebp ;\
- andl $~0x20,%eax ;\
- outb %al,%dx ;\
- popl %edx ;\
- popl %eax
-
-#define NEPC_BUS_RESTORE \
- pushl %eax ;\
- movl %ebp,%eax ;\
- xchgl %edx,%ebp ;\
- movl $0x2a8e,%edx ;\
- outb %al,%dx ;\
- xchgl %ebp,%edx ;\
- popl %eax ;\
- popl %ebp
-
-/***********************************************************
- * NEPC pcmcia 16 bits bus acces (Direct Access)
- ***********************************************************/
-#define BUS_ACCESS_ADDR(BSHREG,ADDRREG) \
- addl BUS_SPACE_HANDLE_BASE/**/(%/**/BSHREG/**/),%/**/ADDRREG
-
-ENTRY(NEPC_DA_io_space_read_2)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- inw %dx,%ax
- NEPC_BUS_RESTORE
- ret
-
-
-ENTRY(NEPC_DA_io_space_write_2)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- outw %ax,%dx
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_read_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- cld
- rep
- insw
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_write_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- cld
- rep
- outsw
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_read_region_2)
- NEPC_SWITCH_BUS16
- call SBUS_DA_io_space_read_region_2
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_write_region_2)
- NEPC_SWITCH_BUS16
- call SBUS_DA_io_space_write_region_2
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_set_multi_2)
- NEPC_SWITCH_BUS16
- call SBUS_DA_io_space_set_multi_2
- NEPC_BUS_RESTORE
- ret
-
-
-ENTRY(NEPC_DA_io_space_set_region_2)
- NEPC_SWITCH_BUS16
- call SBUS_DA_io_space_set_region_2
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_copy_region_2)
- NEPC_SWITCH_BUS16
- call SBUS_DA_io_space_copy_region_2
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_read_4)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- inl %dx,%eax
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_write_4)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- outl %eax,%dx
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_read_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- cld
- rep
- insl
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_write_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- cld
- rep
- outsl
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_read_region_4)
- NEPC_SWITCH_BUS16
- call SBUS_DA_io_space_read_region_4
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_write_region_4)
- NEPC_SWITCH_BUS16
- call SBUS_DA_io_space_write_region_4
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_set_multi_4)
- NEPC_SWITCH_BUS16
- call SBUS_DA_io_space_set_multi_4
- NEPC_BUS_RESTORE
- ret
-
-
-ENTRY(NEPC_DA_io_space_set_region_4)
- NEPC_SWITCH_BUS16
- call SBUS_DA_io_space_set_region_4
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_DA_io_space_copy_region_4)
- NEPC_SWITCH_BUS16
- call SBUS_DA_io_space_copy_region_4
- NEPC_BUS_RESTORE
- ret
-
-#undef BUS_ACCESS_ADDR
-
-/***********************************************************
- * NEPC pcmcia 16 bits bus acces (Relocate Access)
- ***********************************************************/
-#define BUS_ACCESS_ADDR(BSHREG,ADDRREG) \
- movl BUS_SPACE_HANDLE_IAT/**/(%/**/BSHREG/**/, %/**/ADDRREG/**/, 4), \
- %/**/ADDRREG
-
-ENTRY(NEPC_RA_io_space_read_2)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- inw %dx,%ax
- NEPC_BUS_RESTORE
- ret
-
-
-ENTRY(NEPC_RA_io_space_write_2)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- outw %ax,%dx
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_read_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- cld
- rep
- insw
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_write_multi_2)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- cld
- rep
- outsw
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_read_region_2)
- NEPC_SWITCH_BUS16
- call SBUS_RA_io_space_read_region_2
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_write_region_2)
- NEPC_SWITCH_BUS16
- call SBUS_RA_io_space_write_region_2
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_set_multi_2)
- NEPC_SWITCH_BUS16
- call SBUS_RA_io_space_set_multi_2
- NEPC_BUS_RESTORE
- ret
-
-
-ENTRY(NEPC_RA_io_space_set_region_2)
- NEPC_SWITCH_BUS16
- call SBUS_RA_io_space_set_region_2
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_copy_region_2)
- NEPC_SWITCH_BUS16
- call SBUS_RA_io_space_copy_region_2
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_read_4)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- inl %dx,%eax
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_write_4)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- outl %eax,%dx
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_read_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- cld
- rep
- insl
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_write_multi_4)
- BUS_ACCESS_ADDR(ebx,edx)
- NEPC_SWITCH_BUS16
- cld
- rep
- outsl
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_read_region_4)
- NEPC_SWITCH_BUS16
- call SBUS_RA_io_space_read_region_4
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_write_region_4)
- NEPC_SWITCH_BUS16
- call SBUS_RA_io_space_write_region_4
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_set_multi_4)
- NEPC_SWITCH_BUS16
- call SBUS_RA_io_space_set_multi_4
- NEPC_BUS_RESTORE
- ret
-
-
-ENTRY(NEPC_RA_io_space_set_region_4)
- NEPC_SWITCH_BUS16
- call SBUS_RA_io_space_set_region_4
- NEPC_BUS_RESTORE
- ret
-
-ENTRY(NEPC_RA_io_space_copy_region_4)
- NEPC_SWITCH_BUS16
- call SBUS_RA_io_space_copy_region_4
- NEPC_BUS_RESTORE
- ret
-
-#endif /* DEV_MECIA */
diff --git a/sys/pc98/pc98/busiosubr.c b/sys/pc98/pc98/busiosubr.c
deleted file mode 100644
index d8fadadf3cbd..000000000000
--- a/sys/pc98/pc98/busiosubr.c
+++ /dev/null
@@ -1,273 +0,0 @@
-/* $FreeBSD$ */
-/* $NecBSD: busiosubr.c,v 1.30.4.4 1999/08/28 02:25:35 honda Exp $ */
-/* $NetBSD$ */
-
-/*
- * [NetBSD for NEC PC-98 series]
- * Copyright (c) 1996, 1997, 1998
- * NetBSD/pc98 porting staff. All rights reserved.
- *
- * [Ported for FreeBSD]
- * Copyright (c) 2001
- * TAKAHASHI Yoshihiro. 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.
- */
-
-/*
- * Copyright (c) 1997, 1998
- * Naofumi HONDA. All rights reserved.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <machine/bus.h>
-
-static MALLOC_DEFINE(M_BUSSPACEHANDLE, "busspacehandle", "Bus space handle");
-
-_BUS_SPACE_CALL_FUNCS_PROTO(SBUS_DA_io,u_int8_t,1)
-_BUS_SPACE_CALL_FUNCS_PROTO(SBUS_DA_io,u_int16_t,2)
-_BUS_SPACE_CALL_FUNCS_PROTO(SBUS_DA_io,u_int32_t,4)
-_BUS_SPACE_CALL_FUNCS_PROTO(SBUS_DA_mem,u_int8_t,1)
-_BUS_SPACE_CALL_FUNCS_PROTO(SBUS_DA_mem,u_int16_t,2)
-_BUS_SPACE_CALL_FUNCS_PROTO(SBUS_DA_mem,u_int32_t,4)
-
-_BUS_SPACE_CALL_FUNCS_PROTO(SBUS_RA_io,u_int8_t,1)
-_BUS_SPACE_CALL_FUNCS_PROTO(SBUS_RA_io,u_int16_t,2)
-_BUS_SPACE_CALL_FUNCS_PROTO(SBUS_RA_io,u_int32_t,4)
-_BUS_SPACE_CALL_FUNCS_PROTO(SBUS_RA_mem,u_int8_t,1)
-_BUS_SPACE_CALL_FUNCS_PROTO(SBUS_RA_mem,u_int16_t,2)
-_BUS_SPACE_CALL_FUNCS_PROTO(SBUS_RA_mem,u_int32_t,4)
-
-struct bus_space_tag SBUS_io_space_tag = {
- BUS_SPACE_IO,
-
- /* direct bus access methods */
- {
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_DA_io,u_int8_t,1),
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_DA_io,u_int16_t,2),
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_DA_io,u_int32_t,4),
- },
-
- /* relocate bus access methods */
- {
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_RA_io,u_int8_t,1),
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_RA_io,u_int16_t,2),
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_RA_io,u_int32_t,4),
- }
-};
-
-struct bus_space_tag SBUS_mem_space_tag = {
- BUS_SPACE_MEM,
-
- /* direct bus access methods */
- {
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_DA_mem,u_int8_t,1),
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_DA_mem,u_int16_t,2),
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_DA_mem,u_int32_t,4),
- },
-
- /* relocate bus access methods */
- {
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_RA_mem,u_int8_t,1),
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_RA_mem,u_int16_t,2),
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_RA_mem,u_int32_t,4),
- }
-};
-
-
-#include "opt_mecia.h"
-#ifdef DEV_MECIA
-
-_BUS_SPACE_CALL_FUNCS_PROTO(NEPC_DA_io,u_int16_t,2)
-_BUS_SPACE_CALL_FUNCS_PROTO(NEPC_DA_io,u_int32_t,4)
-
-_BUS_SPACE_CALL_FUNCS_PROTO(NEPC_RA_io,u_int16_t,2)
-_BUS_SPACE_CALL_FUNCS_PROTO(NEPC_RA_io,u_int32_t,4)
-
-struct bus_space_tag NEPC_io_space_tag = {
- BUS_SPACE_IO,
-
- /* direct bus access methods */
- {
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_DA_io,u_int8_t,1),
- _BUS_SPACE_CALL_FUNCS_TAB(NEPC_DA_io,u_int16_t,2),
- _BUS_SPACE_CALL_FUNCS_TAB(NEPC_DA_io,u_int32_t,4),
- },
-
- /* relocate bus access methods */
- {
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_RA_io,u_int8_t,1),
- _BUS_SPACE_CALL_FUNCS_TAB(NEPC_RA_io,u_int16_t,2),
- _BUS_SPACE_CALL_FUNCS_TAB(NEPC_RA_io,u_int32_t,4),
- }
-};
-
-struct bus_space_tag NEPC_mem_space_tag = {
- BUS_SPACE_MEM,
-
- /* direct bus access methods */
- {
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_DA_mem,u_int8_t,1),
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_DA_mem,u_int16_t,2),
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_DA_mem,u_int32_t,4),
- },
-
- /* relocate bus access methods */
- {
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_RA_mem,u_int8_t,1),
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_RA_mem,u_int16_t,2),
- _BUS_SPACE_CALL_FUNCS_TAB(SBUS_RA_mem,u_int32_t,4),
- }
-};
-
-#endif /* DEV_MECIA */
-
-/*************************************************************************
- * map init
- *************************************************************************/
-static __inline void
-bus_space_iat_init(bus_space_handle_t bsh)
-{
- int i;
-
- for (i = 0; i < bsh->bsh_maxiatsz; i++)
- bsh->bsh_iat[i] = bsh->bsh_base + i;
-}
-
-/*************************************************************************
- * handle allocation
- *************************************************************************/
-int
-i386_bus_space_handle_alloc(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size,
- bus_space_handle_t *bshp)
-{
- bus_space_handle_t bsh;
-
- bsh = (bus_space_handle_t) malloc(sizeof (*bsh), M_BUSSPACEHANDLE,
- M_NOWAIT | M_ZERO);
- if (bsh == NULL)
- return ENOMEM;
-
- bsh->bsh_maxiatsz = BUS_SPACE_IAT_MAXSIZE;
- bsh->bsh_iatsz = 0;
- bsh->bsh_base = bpa;
- bsh->bsh_sz = size;
- bsh->bsh_res = NULL;
- bsh->bsh_ressz = 0;
- bus_space_iat_init(bsh);
-
- bsh->bsh_bam = t->bs_da; /* default: direct access */
-
- *bshp = bsh;
- return 0;
-}
-
-void
-i386_bus_space_handle_free(bus_space_tag_t t, bus_space_handle_t bsh,
- size_t size)
-{
-
- free(bsh, M_BUSSPACEHANDLE);
-}
-
-/*************************************************************************
- * map
- *************************************************************************/
-void
-i386_memio_unmap(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size)
-{
-
- i386_bus_space_handle_free(t, bsh, bsh->bsh_sz);
-}
-
-void
-i386_memio_free(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size)
-{
-
- /* i386_memio_unmap() does all that we need to do. */
- i386_memio_unmap(t, bsh, bsh->bsh_sz);
-}
-
-int
-i386_memio_subregion(bus_space_tag_t t, bus_space_handle_t pbsh,
- bus_size_t offset, bus_size_t size,
- bus_space_handle_t *tbshp)
-{
- int i, error = 0;
- bus_space_handle_t bsh;
- bus_addr_t pbase;
-
- pbase = pbsh->bsh_base + offset;
- switch (t->bs_tag) {
- case BUS_SPACE_IO:
- if (pbsh->bsh_iatsz > 0) {
- if (offset >= pbsh->bsh_iatsz ||
- offset + size > pbsh->bsh_iatsz)
- return EINVAL;
- pbase = pbsh->bsh_base;
- }
- break;
-
- case BUS_SPACE_MEM:
- if (pbsh->bsh_iatsz > 0)
- return EINVAL;
- if (offset > pbsh->bsh_sz || offset + size > pbsh->bsh_sz)
- return EINVAL;
- break;
-
- default:
- panic("i386_memio_subregion: bad bus space tag");
- break;
- }
-
- error = i386_bus_space_handle_alloc(t, pbase, size, &bsh);
- if (error != 0)
- return error;
-
- switch (t->bs_tag) {
- case BUS_SPACE_IO:
- if (pbsh->bsh_iatsz > 0) {
- for (i = 0; i < size; i ++)
- bsh->bsh_iat[i] = pbsh->bsh_iat[i + offset];
- bsh->bsh_iatsz = size;
- } else if (pbsh->bsh_base > bsh->bsh_base ||
- pbsh->bsh_base + pbsh->bsh_sz <
- bsh->bsh_base + bsh->bsh_sz) {
- i386_bus_space_handle_free(t, bsh, size);
- return EINVAL;
- }
- break;
-
- case BUS_SPACE_MEM:
- break;
- }
-
- if (pbsh->bsh_iatsz > 0)
- bsh->bsh_bam = t->bs_ra; /* relocate access */
- *tbshp = bsh;
- return error;
-}
diff --git a/sys/pc98/pc98/machdep.c b/sys/pc98/pc98/machdep.c
deleted file mode 100644
index 396d20a6eca9..000000000000
--- a/sys/pc98/pc98/machdep.c
+++ /dev/null
@@ -1,2850 +0,0 @@
-/*-
- * Copyright (c) 1992 Terrence R. Lambert.
- * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
- * $FreeBSD$
- */
-
-#include "opt_atalk.h"
-#include "opt_compat.h"
-#include "opt_cpu.h"
-#include "opt_ddb.h"
-#include "opt_inet.h"
-#include "opt_ipx.h"
-#include "opt_isa.h"
-#include "opt_maxmem.h"
-#include "opt_msgbuf.h"
-#include "opt_npx.h"
-#include "opt_perfmon.h"
-#include "opt_swtch.h"
-#include "opt_kstack_pages.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/signalvar.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/ktr.h>
-#include <sys/linker.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/pcpu.h>
-#include <sys/proc.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/reboot.h>
-#include <sys/callout.h>
-#include <sys/msgbuf.h>
-#include <sys/sched.h>
-#include <sys/sysent.h>
-#include <sys/sysctl.h>
-#include <sys/ucontext.h>
-#include <sys/vmmeter.h>
-#include <sys/bus.h>
-#include <sys/eventhandler.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_object.h>
-#include <vm/vm_page.h>
-#include <vm/vm_map.h>
-#include <vm/vm_pager.h>
-#include <vm/vm_extern.h>
-
-#include <sys/user.h>
-#include <sys/exec.h>
-#include <sys/cons.h>
-
-#include <ddb/ddb.h>
-
-#include <net/netisr.h>
-
-#include <machine/cpu.h>
-#include <machine/cputypes.h>
-#include <machine/reg.h>
-#include <machine/clock.h>
-#include <machine/specialreg.h>
-#include <machine/bootinfo.h>
-#include <machine/md_var.h>
-#include <machine/pc/bios.h>
-#include <machine/pcb_ext.h> /* pcb.h included via sys/user.h */
-#include <machine/proc.h>
-#ifdef PERFMON
-#include <machine/perfmon.h>
-#endif
-#ifdef SMP
-#include <machine/privatespace.h>
-#include <machine/smp.h>
-#endif
-
-#include <i386/isa/icu.h>
-#include <i386/isa/intr_machdep.h>
-#ifdef PC98
-#include <pc98/pc98/pc98_machdep.h>
-#include <pc98/pc98/pc98.h>
-#else
-#include <isa/rtc.h>
-#endif
-#include <machine/vm86.h>
-#include <sys/ptrace.h>
-#include <machine/sigframe.h>
-
-extern void init386(int first);
-extern void dblfault_handler(void);
-
-extern void printcpuinfo(void); /* XXX header file */
-extern void finishidentcpu(void);
-extern void panicifcpuunsupported(void);
-extern void initializecpu(void);
-
-#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL)
-#define EFL_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0)
-
-#if !defined(CPU_ENABLE_SSE) && defined(I686_CPU)
-#define CPU_ENABLE_SSE
-#endif
-#if defined(CPU_DISABLE_SSE)
-#undef CPU_ENABLE_SSE
-#endif
-
-static void cpu_startup(void *);
-static void fpstate_drop(struct thread *td);
-static void get_fpcontext(struct thread *td, mcontext_t *mcp);
-static int set_fpcontext(struct thread *td, const mcontext_t *mcp);
-#ifdef CPU_ENABLE_SSE
-static void set_fpregs_xmm(struct save87 *, struct savexmm *);
-static void fill_fpregs_xmm(struct savexmm *, struct save87 *);
-#endif /* CPU_ENABLE_SSE */
-SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL)
-
-#ifdef PC98
-int need_pre_dma_flush; /* If 1, use wbinvd befor DMA transfer. */
-int need_post_dma_flush; /* If 1, use invd after DMA transfer. */
-#endif
-
-int _udatasel, _ucodesel;
-u_int atdevbase;
-
-#if defined(SWTCH_OPTIM_STATS)
-int stupid_switch;
-SYSCTL_INT(_debug, OID_AUTO, stupid_switch,
- CTLFLAG_RW, &stupid_switch, 0, "");
-int swtch_optim_stats;
-SYSCTL_INT(_debug, OID_AUTO, swtch_optim_stats,
- CTLFLAG_RW, &swtch_optim_stats, 0, "");
-int tlb_flush_count;
-SYSCTL_INT(_debug, OID_AUTO, tlb_flush_count,
- CTLFLAG_RW, &tlb_flush_count, 0, "");
-int lazy_flush_count;
-SYSCTL_INT(_debug, OID_AUTO, lazy_flush_count,
- CTLFLAG_RW, &lazy_flush_count, 0, "");
-int lazy_flush_fixup;
-SYSCTL_INT(_debug, OID_AUTO, lazy_flush_fixup,
- CTLFLAG_RW, &lazy_flush_fixup, 0, "");
-#ifdef SMP
-int lazy_flush_smpfixup;
-SYSCTL_INT(_debug, OID_AUTO, lazy_flush_smpfixup,
- CTLFLAG_RW, &lazy_flush_smpfixup, 0, "");
-int lazy_flush_smpipi;
-SYSCTL_INT(_debug, OID_AUTO, lazy_flush_smpipi,
- CTLFLAG_RW, &lazy_flush_smpipi, 0, "");
-int lazy_flush_smpbadcr3;
-SYSCTL_INT(_debug, OID_AUTO, lazy_flush_smpbadcr3,
- CTLFLAG_RW, &lazy_flush_smpbadcr3, 0, "");
-int lazy_flush_smpmiss;
-SYSCTL_INT(_debug, OID_AUTO, lazy_flush_smpmiss,
- CTLFLAG_RW, &lazy_flush_smpmiss, 0, "");
-#endif
-#endif
-#ifdef LAZY_SWITCH
-int lazy_flush_enable = 1;
-SYSCTL_INT(_debug, OID_AUTO, lazy_flush_enable,
- CTLFLAG_RW, &lazy_flush_enable, 0, "");
-#endif
-
-#ifdef PC98
-static int ispc98 = 1;
-#else
-static int ispc98 = 0;
-#endif
-SYSCTL_INT(_machdep, OID_AUTO, ispc98, CTLFLAG_RD, &ispc98, 0, "");
-
-int cold = 1;
-
-#ifdef COMPAT_43
-static void osendsig(sig_t catcher, int sig, sigset_t *mask, u_long code);
-#endif
-#ifdef COMPAT_FREEBSD4
-static void freebsd4_sendsig(sig_t catcher, int sig, sigset_t *mask,
- u_long code);
-#endif
-
-long Maxmem = 0;
-#ifdef PC98
-int Maxmem_under16M = 0;
-#endif
-
-vm_paddr_t phys_avail[10];
-
-/* must be 2 less so 0 0 can signal end of chunks */
-#define PHYS_AVAIL_ARRAY_END ((sizeof(phys_avail) / sizeof(vm_offset_t)) - 2)
-
-struct kva_md_info kmi;
-
-static struct trapframe proc0_tf;
-#ifndef SMP
-static struct pcpu __pcpu;
-#endif
-
-struct mtx icu_lock;
-
-static void
-cpu_startup(dummy)
- void *dummy;
-{
- /*
- * Good {morning,afternoon,evening,night}.
- */
- startrtclock();
- printcpuinfo();
- panicifcpuunsupported();
-#ifdef PERFMON
- perfmon_init();
-#endif
- printf("real memory = %ju (%ju MB)\n", ptoa((uintmax_t)Maxmem),
- ptoa((uintmax_t)Maxmem) / 1048576);
- /*
- * Display any holes after the first chunk of extended memory.
- */
- if (bootverbose) {
- int indx;
-
- printf("Physical memory chunk(s):\n");
- for (indx = 0; phys_avail[indx + 1] != 0; indx += 2) {
- vm_paddr_t size;
-
- size = phys_avail[indx + 1] - phys_avail[indx];
- printf(
- "0x%016jx - 0x%016jx, %ju bytes (%ju pages)\n",
- (uintmax_t)phys_avail[indx],
- (uintmax_t)phys_avail[indx + 1] - 1,
- (uintmax_t)size, (uintmax_t)size / PAGE_SIZE);
- }
- }
-
- vm_ksubmap_init(&kmi);
-
- printf("avail memory = %ju (%ju MB)\n",
- ptoa((uintmax_t)cnt.v_free_count),
- ptoa((uintmax_t)cnt.v_free_count) / 1048576);
-
- /*
- * Set up buffers, so they can be used to read disk labels.
- */
- bufinit();
- vm_pager_bufferinit();
-
-#ifndef SMP
- /* For SMP, we delay the cpu_setregs() until after SMP startup. */
- cpu_setregs();
-#endif
-}
-
-/*
- * Send an interrupt to process.
- *
- * Stack is set up to allow sigcode stored
- * at top to call routine, followed by kcall
- * to sigreturn routine below. After sigreturn
- * resets the signal mask, the stack, and the
- * frame pointer, it returns to the user
- * specified pc, psl.
- */
-#ifdef COMPAT_43
-static void
-osendsig(catcher, sig, mask, code)
- sig_t catcher;
- int sig;
- sigset_t *mask;
- u_long code;
-{
- struct osigframe sf, *fp;
- struct proc *p;
- struct thread *td;
- struct sigacts *psp;
- struct trapframe *regs;
- int oonstack;
-
- td = curthread;
- p = td->td_proc;
- PROC_LOCK_ASSERT(p, MA_OWNED);
- psp = p->p_sigacts;
- mtx_assert(&psp->ps_mtx, MA_OWNED);
- regs = td->td_frame;
- oonstack = sigonstack(regs->tf_esp);
-
- /* Allocate space for the signal handler context. */
- if ((p->p_flag & P_ALTSTACK) && !oonstack &&
- SIGISMEMBER(psp->ps_sigonstack, sig)) {
- fp = (struct osigframe *)(p->p_sigstk.ss_sp +
- p->p_sigstk.ss_size - sizeof(struct osigframe));
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
- p->p_sigstk.ss_flags |= SS_ONSTACK;
-#endif
- } else
- fp = (struct osigframe *)regs->tf_esp - 1;
-
- /* Translate the signal if appropriate. */
- if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
- sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
-
- /* Build the argument list for the signal handler. */
- sf.sf_signum = sig;
- sf.sf_scp = (register_t)&fp->sf_siginfo.si_sc;
- if (SIGISMEMBER(psp->ps_siginfo, sig)) {
- /* Signal handler installed with SA_SIGINFO. */
- sf.sf_arg2 = (register_t)&fp->sf_siginfo;
- sf.sf_siginfo.si_signo = sig;
- sf.sf_siginfo.si_code = code;
- sf.sf_ahu.sf_action = (__osiginfohandler_t *)catcher;
- } else {
- /* Old FreeBSD-style arguments. */
- sf.sf_arg2 = code;
- sf.sf_addr = regs->tf_err;
- sf.sf_ahu.sf_handler = catcher;
- }
- mtx_unlock(&psp->ps_mtx);
- PROC_UNLOCK(p);
-
- /* Save most if not all of trap frame. */
- sf.sf_siginfo.si_sc.sc_eax = regs->tf_eax;
- sf.sf_siginfo.si_sc.sc_ebx = regs->tf_ebx;
- sf.sf_siginfo.si_sc.sc_ecx = regs->tf_ecx;
- sf.sf_siginfo.si_sc.sc_edx = regs->tf_edx;
- sf.sf_siginfo.si_sc.sc_esi = regs->tf_esi;
- sf.sf_siginfo.si_sc.sc_edi = regs->tf_edi;
- sf.sf_siginfo.si_sc.sc_cs = regs->tf_cs;
- sf.sf_siginfo.si_sc.sc_ds = regs->tf_ds;
- sf.sf_siginfo.si_sc.sc_ss = regs->tf_ss;
- sf.sf_siginfo.si_sc.sc_es = regs->tf_es;
- sf.sf_siginfo.si_sc.sc_fs = regs->tf_fs;
- sf.sf_siginfo.si_sc.sc_gs = rgs();
- sf.sf_siginfo.si_sc.sc_isp = regs->tf_isp;
-
- /* Build the signal context to be used by osigreturn(). */
- sf.sf_siginfo.si_sc.sc_onstack = (oonstack) ? 1 : 0;
- SIG2OSIG(*mask, sf.sf_siginfo.si_sc.sc_mask);
- sf.sf_siginfo.si_sc.sc_sp = regs->tf_esp;
- sf.sf_siginfo.si_sc.sc_fp = regs->tf_ebp;
- sf.sf_siginfo.si_sc.sc_pc = regs->tf_eip;
- sf.sf_siginfo.si_sc.sc_ps = regs->tf_eflags;
- sf.sf_siginfo.si_sc.sc_trapno = regs->tf_trapno;
- sf.sf_siginfo.si_sc.sc_err = regs->tf_err;
-
- /*
- * If we're a vm86 process, we want to save the segment registers.
- * We also change eflags to be our emulated eflags, not the actual
- * eflags.
- */
- if (regs->tf_eflags & PSL_VM) {
- /* XXX confusing names: `tf' isn't a trapframe; `regs' is. */
- struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs;
- struct vm86_kernel *vm86 = &td->td_pcb->pcb_ext->ext_vm86;
-
- sf.sf_siginfo.si_sc.sc_gs = tf->tf_vm86_gs;
- sf.sf_siginfo.si_sc.sc_fs = tf->tf_vm86_fs;
- sf.sf_siginfo.si_sc.sc_es = tf->tf_vm86_es;
- sf.sf_siginfo.si_sc.sc_ds = tf->tf_vm86_ds;
-
- if (vm86->vm86_has_vme == 0)
- sf.sf_siginfo.si_sc.sc_ps =
- (tf->tf_eflags & ~(PSL_VIF | PSL_VIP)) |
- (vm86->vm86_eflags & (PSL_VIF | PSL_VIP));
-
- /* See sendsig() for comments. */
- tf->tf_eflags &= ~(PSL_VM | PSL_NT | PSL_VIF | PSL_VIP);
- }
-
- /*
- * Copy the sigframe out to the user's stack.
- */
- if (copyout(&sf, fp, sizeof(*fp)) != 0) {
-#ifdef DEBUG
- printf("process %ld has trashed its stack\n", (long)p->p_pid);
-#endif
- PROC_LOCK(p);
- sigexit(td, SIGILL);
- }
-
- regs->tf_esp = (int)fp;
- regs->tf_eip = PS_STRINGS - szosigcode;
- regs->tf_eflags &= ~PSL_T;
- regs->tf_cs = _ucodesel;
- regs->tf_ds = _udatasel;
- regs->tf_es = _udatasel;
- regs->tf_fs = _udatasel;
- load_gs(_udatasel);
- regs->tf_ss = _udatasel;
- PROC_LOCK(p);
- mtx_lock(&psp->ps_mtx);
-}
-#endif /* COMPAT_43 */
-
-#ifdef COMPAT_FREEBSD4
-static void
-freebsd4_sendsig(catcher, sig, mask, code)
- sig_t catcher;
- int sig;
- sigset_t *mask;
- u_long code;
-{
- struct sigframe4 sf, *sfp;
- struct proc *p;
- struct thread *td;
- struct sigacts *psp;
- struct trapframe *regs;
- int oonstack;
-
- td = curthread;
- p = td->td_proc;
- PROC_LOCK_ASSERT(p, MA_OWNED);
- psp = p->p_sigacts;
- mtx_assert(&psp->ps_mtx, MA_OWNED);
- regs = td->td_frame;
- oonstack = sigonstack(regs->tf_esp);
-
- /* Save user context. */
- bzero(&sf, sizeof(sf));
- sf.sf_uc.uc_sigmask = *mask;
- sf.sf_uc.uc_stack = p->p_sigstk;
- sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
- ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
- sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
- sf.sf_uc.uc_mcontext.mc_gs = rgs();
- bcopy(regs, &sf.sf_uc.uc_mcontext.mc_fs, sizeof(*regs));
-
- /* Allocate space for the signal handler context. */
- if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
- SIGISMEMBER(psp->ps_sigonstack, sig)) {
- sfp = (struct sigframe4 *)(p->p_sigstk.ss_sp +
- p->p_sigstk.ss_size - sizeof(struct sigframe4));
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
- p->p_sigstk.ss_flags |= SS_ONSTACK;
-#endif
- } else
- sfp = (struct sigframe4 *)regs->tf_esp - 1;
-
- /* Translate the signal if appropriate. */
- if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
- sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
-
- /* Build the argument list for the signal handler. */
- sf.sf_signum = sig;
- sf.sf_ucontext = (register_t)&sfp->sf_uc;
- if (SIGISMEMBER(psp->ps_siginfo, sig)) {
- /* Signal handler installed with SA_SIGINFO. */
- sf.sf_siginfo = (register_t)&sfp->sf_si;
- sf.sf_ahu.sf_action = (__siginfohandler_t *)catcher;
-
- /* Fill in POSIX parts */
- sf.sf_si.si_signo = sig;
- sf.sf_si.si_code = code;
- sf.sf_si.si_addr = (void *)regs->tf_err;
- } else {
- /* Old FreeBSD-style arguments. */
- sf.sf_siginfo = code;
- sf.sf_addr = regs->tf_err;
- sf.sf_ahu.sf_handler = catcher;
- }
- mtx_unlock(&psp->ps_mtx);
- PROC_UNLOCK(p);
-
- /*
- * If we're a vm86 process, we want to save the segment registers.
- * We also change eflags to be our emulated eflags, not the actual
- * eflags.
- */
- if (regs->tf_eflags & PSL_VM) {
- struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs;
- struct vm86_kernel *vm86 = &td->td_pcb->pcb_ext->ext_vm86;
-
- sf.sf_uc.uc_mcontext.mc_gs = tf->tf_vm86_gs;
- sf.sf_uc.uc_mcontext.mc_fs = tf->tf_vm86_fs;
- sf.sf_uc.uc_mcontext.mc_es = tf->tf_vm86_es;
- sf.sf_uc.uc_mcontext.mc_ds = tf->tf_vm86_ds;
-
- if (vm86->vm86_has_vme == 0)
- sf.sf_uc.uc_mcontext.mc_eflags =
- (tf->tf_eflags & ~(PSL_VIF | PSL_VIP)) |
- (vm86->vm86_eflags & (PSL_VIF | PSL_VIP));
-
- /*
- * Clear PSL_NT to inhibit T_TSSFLT faults on return from
- * syscalls made by the signal handler. This just avoids
- * wasting time for our lazy fixup of such faults. PSL_NT
- * does nothing in vm86 mode, but vm86 programs can set it
- * almost legitimately in probes for old cpu types.
- */
- tf->tf_eflags &= ~(PSL_VM | PSL_NT | PSL_VIF | PSL_VIP);
- }
-
- /*
- * Copy the sigframe out to the user's stack.
- */
- if (copyout(&sf, sfp, sizeof(*sfp)) != 0) {
-#ifdef DEBUG
- printf("process %ld has trashed its stack\n", (long)p->p_pid);
-#endif
- PROC_LOCK(p);
- sigexit(td, SIGILL);
- }
-
- regs->tf_esp = (int)sfp;
- regs->tf_eip = PS_STRINGS - szfreebsd4_sigcode;
- regs->tf_eflags &= ~PSL_T;
- regs->tf_cs = _ucodesel;
- regs->tf_ds = _udatasel;
- regs->tf_es = _udatasel;
- regs->tf_fs = _udatasel;
- regs->tf_ss = _udatasel;
- PROC_LOCK(p);
- mtx_lock(&psp->ps_mtx);
-}
-#endif /* COMPAT_FREEBSD4 */
-
-void
-sendsig(catcher, sig, mask, code)
- sig_t catcher;
- int sig;
- sigset_t *mask;
- u_long code;
-{
- struct sigframe sf, *sfp;
- struct proc *p;
- struct thread *td;
- struct sigacts *psp;
- char *sp;
- struct trapframe *regs;
- int oonstack;
-
- td = curthread;
- p = td->td_proc;
- PROC_LOCK_ASSERT(p, MA_OWNED);
- psp = p->p_sigacts;
- mtx_assert(&psp->ps_mtx, MA_OWNED);
-#ifdef COMPAT_FREEBSD4
- if (SIGISMEMBER(psp->ps_freebsd4, sig)) {
- freebsd4_sendsig(catcher, sig, mask, code);
- return;
- }
-#endif
-#ifdef COMPAT_43
- if (SIGISMEMBER(psp->ps_osigset, sig)) {
- osendsig(catcher, sig, mask, code);
- return;
- }
-#endif
- regs = td->td_frame;
- oonstack = sigonstack(regs->tf_esp);
-
- /* Save user context. */
- bzero(&sf, sizeof(sf));
- sf.sf_uc.uc_sigmask = *mask;
- sf.sf_uc.uc_stack = p->p_sigstk;
- sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
- ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
- sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
- sf.sf_uc.uc_mcontext.mc_gs = rgs();
- bcopy(regs, &sf.sf_uc.uc_mcontext.mc_fs, sizeof(*regs));
- sf.sf_uc.uc_mcontext.mc_len = sizeof(sf.sf_uc.uc_mcontext); /* magic */
- get_fpcontext(td, &sf.sf_uc.uc_mcontext);
- fpstate_drop(td);
-
- /* Allocate space for the signal handler context. */
- if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
- SIGISMEMBER(psp->ps_sigonstack, sig)) {
- sp = p->p_sigstk.ss_sp +
- p->p_sigstk.ss_size - sizeof(struct sigframe);
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
- p->p_sigstk.ss_flags |= SS_ONSTACK;
-#endif
- } else
- sp = (char *)regs->tf_esp - sizeof(struct sigframe);
- /* Align to 16 bytes. */
- sfp = (struct sigframe *)((unsigned int)sp & ~0xF);
-
- /* Translate the signal if appropriate. */
- if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
- sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
-
- /* Build the argument list for the signal handler. */
- sf.sf_signum = sig;
- sf.sf_ucontext = (register_t)&sfp->sf_uc;
- if (SIGISMEMBER(psp->ps_siginfo, sig)) {
- /* Signal handler installed with SA_SIGINFO. */
- sf.sf_siginfo = (register_t)&sfp->sf_si;
- sf.sf_ahu.sf_action = (__siginfohandler_t *)catcher;
-
- /* Fill in POSIX parts */
- sf.sf_si.si_signo = sig;
- sf.sf_si.si_code = code;
- sf.sf_si.si_addr = (void *)regs->tf_err;
- } else {
- /* Old FreeBSD-style arguments. */
- sf.sf_siginfo = code;
- sf.sf_addr = regs->tf_err;
- sf.sf_ahu.sf_handler = catcher;
- }
- mtx_unlock(&psp->ps_mtx);
- PROC_UNLOCK(p);
-
- /*
- * If we're a vm86 process, we want to save the segment registers.
- * We also change eflags to be our emulated eflags, not the actual
- * eflags.
- */
- if (regs->tf_eflags & PSL_VM) {
- struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs;
- struct vm86_kernel *vm86 = &td->td_pcb->pcb_ext->ext_vm86;
-
- sf.sf_uc.uc_mcontext.mc_gs = tf->tf_vm86_gs;
- sf.sf_uc.uc_mcontext.mc_fs = tf->tf_vm86_fs;
- sf.sf_uc.uc_mcontext.mc_es = tf->tf_vm86_es;
- sf.sf_uc.uc_mcontext.mc_ds = tf->tf_vm86_ds;
-
- if (vm86->vm86_has_vme == 0)
- sf.sf_uc.uc_mcontext.mc_eflags =
- (tf->tf_eflags & ~(PSL_VIF | PSL_VIP)) |
- (vm86->vm86_eflags & (PSL_VIF | PSL_VIP));
-
- /*
- * Clear PSL_NT to inhibit T_TSSFLT faults on return from
- * syscalls made by the signal handler. This just avoids
- * wasting time for our lazy fixup of such faults. PSL_NT
- * does nothing in vm86 mode, but vm86 programs can set it
- * almost legitimately in probes for old cpu types.
- */
- tf->tf_eflags &= ~(PSL_VM | PSL_NT | PSL_VIF | PSL_VIP);
- }
-
- /*
- * Copy the sigframe out to the user's stack.
- */
- if (copyout(&sf, sfp, sizeof(*sfp)) != 0) {
-#ifdef DEBUG
- printf("process %ld has trashed its stack\n", (long)p->p_pid);
-#endif
- PROC_LOCK(p);
- sigexit(td, SIGILL);
- }
-
- regs->tf_esp = (int)sfp;
- regs->tf_eip = PS_STRINGS - *(p->p_sysent->sv_szsigcode);
- regs->tf_eflags &= ~PSL_T;
- regs->tf_cs = _ucodesel;
- regs->tf_ds = _udatasel;
- regs->tf_es = _udatasel;
- regs->tf_fs = _udatasel;
- regs->tf_ss = _udatasel;
- PROC_LOCK(p);
- mtx_lock(&psp->ps_mtx);
-}
-
-/*
- * System call to cleanup state after a signal
- * has been taken. Reset signal mask and
- * stack state from context left by sendsig (above).
- * Return to previous pc and psl as specified by
- * context left by sendsig. Check carefully to
- * make sure that the user has not modified the
- * state to gain improper privileges.
- *
- * MPSAFE
- */
-#ifdef COMPAT_43
-int
-osigreturn(td, uap)
- struct thread *td;
- struct osigreturn_args /* {
- struct osigcontext *sigcntxp;
- } */ *uap;
-{
- struct osigcontext sc;
- struct trapframe *regs;
- struct osigcontext *scp;
- struct proc *p = td->td_proc;
- int eflags, error;
-
- regs = td->td_frame;
- error = copyin(uap->sigcntxp, &sc, sizeof(sc));
- if (error != 0)
- return (error);
- scp = &sc;
- eflags = scp->sc_ps;
- if (eflags & PSL_VM) {
- struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs;
- struct vm86_kernel *vm86;
-
- /*
- * if pcb_ext == 0 or vm86_inited == 0, the user hasn't
- * set up the vm86 area, and we can't enter vm86 mode.
- */
- if (td->td_pcb->pcb_ext == 0)
- return (EINVAL);
- vm86 = &td->td_pcb->pcb_ext->ext_vm86;
- if (vm86->vm86_inited == 0)
- return (EINVAL);
-
- /* Go back to user mode if both flags are set. */
- if ((eflags & PSL_VIP) && (eflags & PSL_VIF))
- trapsignal(td, SIGBUS, 0);
-
- if (vm86->vm86_has_vme) {
- eflags = (tf->tf_eflags & ~VME_USERCHANGE) |
- (eflags & VME_USERCHANGE) | PSL_VM;
- } else {
- vm86->vm86_eflags = eflags; /* save VIF, VIP */
- eflags = (tf->tf_eflags & ~VM_USERCHANGE) |
- (eflags & VM_USERCHANGE) | PSL_VM;
- }
- tf->tf_vm86_ds = scp->sc_ds;
- tf->tf_vm86_es = scp->sc_es;
- tf->tf_vm86_fs = scp->sc_fs;
- tf->tf_vm86_gs = scp->sc_gs;
- tf->tf_ds = _udatasel;
- tf->tf_es = _udatasel;
- tf->tf_fs = _udatasel;
- } else {
- /*
- * Don't allow users to change privileged or reserved flags.
- */
- /*
- * XXX do allow users to change the privileged flag PSL_RF.
- * The cpu sets PSL_RF in tf_eflags for faults. Debuggers
- * should sometimes set it there too. tf_eflags is kept in
- * the signal context during signal handling and there is no
- * other place to remember it, so the PSL_RF bit may be
- * corrupted by the signal handler without us knowing.
- * Corruption of the PSL_RF bit at worst causes one more or
- * one less debugger trap, so allowing it is fairly harmless.
- */
- if (!EFL_SECURE(eflags & ~PSL_RF, regs->tf_eflags & ~PSL_RF)) {
- return (EINVAL);
- }
-
- /*
- * Don't allow users to load a valid privileged %cs. Let the
- * hardware check for invalid selectors, excess privilege in
- * other selectors, invalid %eip's and invalid %esp's.
- */
- if (!CS_SECURE(scp->sc_cs)) {
- trapsignal(td, SIGBUS, T_PROTFLT);
- return (EINVAL);
- }
- regs->tf_ds = scp->sc_ds;
- regs->tf_es = scp->sc_es;
- regs->tf_fs = scp->sc_fs;
- }
-
- /* Restore remaining registers. */
- regs->tf_eax = scp->sc_eax;
- regs->tf_ebx = scp->sc_ebx;
- regs->tf_ecx = scp->sc_ecx;
- regs->tf_edx = scp->sc_edx;
- regs->tf_esi = scp->sc_esi;
- regs->tf_edi = scp->sc_edi;
- regs->tf_cs = scp->sc_cs;
- regs->tf_ss = scp->sc_ss;
- regs->tf_isp = scp->sc_isp;
- regs->tf_ebp = scp->sc_fp;
- regs->tf_esp = scp->sc_sp;
- regs->tf_eip = scp->sc_pc;
- regs->tf_eflags = eflags;
-
- PROC_LOCK(p);
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
- if (scp->sc_onstack & 1)
- p->p_sigstk.ss_flags |= SS_ONSTACK;
- else
- p->p_sigstk.ss_flags &= ~SS_ONSTACK;
-#endif
- SIGSETOLD(td->td_sigmask, scp->sc_mask);
- SIG_CANTMASK(td->td_sigmask);
- signotify(td);
- PROC_UNLOCK(p);
- return (EJUSTRETURN);
-}
-#endif /* COMPAT_43 */
-
-#ifdef COMPAT_FREEBSD4
-/*
- * MPSAFE
- */
-int
-freebsd4_sigreturn(td, uap)
- struct thread *td;
- struct freebsd4_sigreturn_args /* {
- const ucontext4 *sigcntxp;
- } */ *uap;
-{
- struct ucontext4 uc;
- struct proc *p = td->td_proc;
- struct trapframe *regs;
- const struct ucontext4 *ucp;
- int cs, eflags, error;
-
- error = copyin(uap->sigcntxp, &uc, sizeof(uc));
- if (error != 0)
- return (error);
- ucp = &uc;
- regs = td->td_frame;
- eflags = ucp->uc_mcontext.mc_eflags;
- if (eflags & PSL_VM) {
- struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs;
- struct vm86_kernel *vm86;
-
- /*
- * if pcb_ext == 0 or vm86_inited == 0, the user hasn't
- * set up the vm86 area, and we can't enter vm86 mode.
- */
- if (td->td_pcb->pcb_ext == 0)
- return (EINVAL);
- vm86 = &td->td_pcb->pcb_ext->ext_vm86;
- if (vm86->vm86_inited == 0)
- return (EINVAL);
-
- /* Go back to user mode if both flags are set. */
- if ((eflags & PSL_VIP) && (eflags & PSL_VIF))
- trapsignal(td, SIGBUS, 0);
-
- if (vm86->vm86_has_vme) {
- eflags = (tf->tf_eflags & ~VME_USERCHANGE) |
- (eflags & VME_USERCHANGE) | PSL_VM;
- } else {
- vm86->vm86_eflags = eflags; /* save VIF, VIP */
- eflags = (tf->tf_eflags & ~VM_USERCHANGE) |
- (eflags & VM_USERCHANGE) | PSL_VM;
- }
- bcopy(&ucp->uc_mcontext.mc_fs, tf, sizeof(struct trapframe));
- tf->tf_eflags = eflags;
- tf->tf_vm86_ds = tf->tf_ds;
- tf->tf_vm86_es = tf->tf_es;
- tf->tf_vm86_fs = tf->tf_fs;
- tf->tf_vm86_gs = ucp->uc_mcontext.mc_gs;
- tf->tf_ds = _udatasel;
- tf->tf_es = _udatasel;
- tf->tf_fs = _udatasel;
- } else {
- /*
- * Don't allow users to change privileged or reserved flags.
- */
- /*
- * XXX do allow users to change the privileged flag PSL_RF.
- * The cpu sets PSL_RF in tf_eflags for faults. Debuggers
- * should sometimes set it there too. tf_eflags is kept in
- * the signal context during signal handling and there is no
- * other place to remember it, so the PSL_RF bit may be
- * corrupted by the signal handler without us knowing.
- * Corruption of the PSL_RF bit at worst causes one more or
- * one less debugger trap, so allowing it is fairly harmless.
- */
- if (!EFL_SECURE(eflags & ~PSL_RF, regs->tf_eflags & ~PSL_RF)) {
- printf("freebsd4_sigreturn: eflags = 0x%x\n", eflags);
- return (EINVAL);
- }
-
- /*
- * Don't allow users to load a valid privileged %cs. Let the
- * hardware check for invalid selectors, excess privilege in
- * other selectors, invalid %eip's and invalid %esp's.
- */
- cs = ucp->uc_mcontext.mc_cs;
- if (!CS_SECURE(cs)) {
- printf("freebsd4_sigreturn: cs = 0x%x\n", cs);
- trapsignal(td, SIGBUS, T_PROTFLT);
- return (EINVAL);
- }
-
- bcopy(&ucp->uc_mcontext.mc_fs, regs, sizeof(*regs));
- }
-
- PROC_LOCK(p);
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
- if (ucp->uc_mcontext.mc_onstack & 1)
- p->p_sigstk.ss_flags |= SS_ONSTACK;
- else
- p->p_sigstk.ss_flags &= ~SS_ONSTACK;
-#endif
-
- td->td_sigmask = ucp->uc_sigmask;
- SIG_CANTMASK(td->td_sigmask);
- signotify(td);
- PROC_UNLOCK(p);
- return (EJUSTRETURN);
-}
-#endif /* COMPAT_FREEBSD4 */
-
-/*
- * MPSAFE
- */
-int
-sigreturn(td, uap)
- struct thread *td;
- struct sigreturn_args /* {
- const __ucontext *sigcntxp;
- } */ *uap;
-{
- ucontext_t uc;
- struct proc *p = td->td_proc;
- struct trapframe *regs;
- const ucontext_t *ucp;
- int cs, eflags, error, ret;
-
- error = copyin(uap->sigcntxp, &uc, sizeof(uc));
- if (error != 0)
- return (error);
- ucp = &uc;
- regs = td->td_frame;
- eflags = ucp->uc_mcontext.mc_eflags;
- if (eflags & PSL_VM) {
- struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs;
- struct vm86_kernel *vm86;
-
- /*
- * if pcb_ext == 0 or vm86_inited == 0, the user hasn't
- * set up the vm86 area, and we can't enter vm86 mode.
- */
- if (td->td_pcb->pcb_ext == 0)
- return (EINVAL);
- vm86 = &td->td_pcb->pcb_ext->ext_vm86;
- if (vm86->vm86_inited == 0)
- return (EINVAL);
-
- /* Go back to user mode if both flags are set. */
- if ((eflags & PSL_VIP) && (eflags & PSL_VIF))
- trapsignal(td, SIGBUS, 0);
-
- if (vm86->vm86_has_vme) {
- eflags = (tf->tf_eflags & ~VME_USERCHANGE) |
- (eflags & VME_USERCHANGE) | PSL_VM;
- } else {
- vm86->vm86_eflags = eflags; /* save VIF, VIP */
- eflags = (tf->tf_eflags & ~VM_USERCHANGE) |
- (eflags & VM_USERCHANGE) | PSL_VM;
- }
- bcopy(&ucp->uc_mcontext.mc_fs, tf, sizeof(struct trapframe));
- tf->tf_eflags = eflags;
- tf->tf_vm86_ds = tf->tf_ds;
- tf->tf_vm86_es = tf->tf_es;
- tf->tf_vm86_fs = tf->tf_fs;
- tf->tf_vm86_gs = ucp->uc_mcontext.mc_gs;
- tf->tf_ds = _udatasel;
- tf->tf_es = _udatasel;
- tf->tf_fs = _udatasel;
- } else {
- /*
- * Don't allow users to change privileged or reserved flags.
- */
- /*
- * XXX do allow users to change the privileged flag PSL_RF.
- * The cpu sets PSL_RF in tf_eflags for faults. Debuggers
- * should sometimes set it there too. tf_eflags is kept in
- * the signal context during signal handling and there is no
- * other place to remember it, so the PSL_RF bit may be
- * corrupted by the signal handler without us knowing.
- * Corruption of the PSL_RF bit at worst causes one more or
- * one less debugger trap, so allowing it is fairly harmless.
- */
- if (!EFL_SECURE(eflags & ~PSL_RF, regs->tf_eflags & ~PSL_RF)) {
- printf("sigreturn: eflags = 0x%x\n", eflags);
- return (EINVAL);
- }
-
- /*
- * Don't allow users to load a valid privileged %cs. Let the
- * hardware check for invalid selectors, excess privilege in
- * other selectors, invalid %eip's and invalid %esp's.
- */
- cs = ucp->uc_mcontext.mc_cs;
- if (!CS_SECURE(cs)) {
- printf("sigreturn: cs = 0x%x\n", cs);
- trapsignal(td, SIGBUS, T_PROTFLT);
- return (EINVAL);
- }
-
- ret = set_fpcontext(td, &ucp->uc_mcontext);
- if (ret != 0)
- return (ret);
- bcopy(&ucp->uc_mcontext.mc_fs, regs, sizeof(*regs));
- }
-
- PROC_LOCK(p);
-#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
- if (ucp->uc_mcontext.mc_onstack & 1)
- p->p_sigstk.ss_flags |= SS_ONSTACK;
- else
- p->p_sigstk.ss_flags &= ~SS_ONSTACK;
-#endif
-
- td->td_sigmask = ucp->uc_sigmask;
- SIG_CANTMASK(td->td_sigmask);
- signotify(td);
- PROC_UNLOCK(p);
- return (EJUSTRETURN);
-}
-
-/*
- * Machine dependent boot() routine
- *
- * I haven't seen anything to put here yet
- * Possibly some stuff might be grafted back here from boot()
- */
-void
-cpu_boot(int howto)
-{
-}
-
-/*
- * Shutdown the CPU as much as possible
- */
-void
-cpu_halt(void)
-{
- for (;;)
- __asm__ ("hlt");
-}
-
-/*
- * Hook to idle the CPU when possible. In the SMP case we default to
- * off because a halted cpu will not currently pick up a new thread in the
- * run queue until the next timer tick. If turned on this will result in
- * approximately a 4.2% loss in real time performance in buildworld tests
- * (but improves user and sys times oddly enough), and saves approximately
- * 5% in power consumption on an idle machine (tests w/2xCPU 1.1GHz P3).
- *
- * XXX we need to have a cpu mask of idle cpus and generate an IPI or
- * otherwise generate some sort of interrupt to wake up cpus sitting in HLT.
- * Then we can have our cake and eat it too.
- *
- * XXX I'm turning it on for SMP as well by default for now. It seems to
- * help lock contention somewhat, and this is critical for HTT. -Peter
- */
-static int cpu_idle_hlt = 1;
-SYSCTL_INT(_machdep, OID_AUTO, cpu_idle_hlt, CTLFLAG_RW,
- &cpu_idle_hlt, 0, "Idle loop HLT enable");
-
-/*
- * Note that we have to be careful here to avoid a race between checking
- * sched_runnable() and actually halting. If we don't do this, we may waste
- * the time between calling hlt and the next interrupt even though there
- * is a runnable process.
- */
-void
-cpu_idle(void)
-{
-
-#ifdef SMP
- if (mp_grab_cpu_hlt())
- return;
-#endif
-
- if (cpu_idle_hlt) {
- disable_intr();
- if (sched_runnable()) {
- enable_intr();
- } else {
- /*
- * we must absolutely guarentee that hlt is the
- * absolute next instruction after sti or we
- * introduce a timing window.
- */
- __asm __volatile("sti; hlt");
- }
- }
-}
-
-/*
- * Clear registers on exec
- */
-void
-exec_setregs(td, entry, stack, ps_strings)
- struct thread *td;
- u_long entry;
- u_long stack;
- u_long ps_strings;
-{
- struct trapframe *regs = td->td_frame;
- struct pcb *pcb = td->td_pcb;
-
- /* Reset pc->pcb_gs and %gs before possibly invalidating it. */
- pcb->pcb_gs = _udatasel;
- load_gs(_udatasel);
-
- if (td->td_proc->p_md.md_ldt)
- user_ldt_free(td);
-
- bzero((char *)regs, sizeof(struct trapframe));
- regs->tf_eip = entry;
- regs->tf_esp = stack;
- regs->tf_eflags = PSL_USER | (regs->tf_eflags & PSL_T);
- regs->tf_ss = _udatasel;
- regs->tf_ds = _udatasel;
- regs->tf_es = _udatasel;
- regs->tf_fs = _udatasel;
- regs->tf_cs = _ucodesel;
-
- /* PS_STRINGS value for BSD/OS binaries. It is 0 for non-BSD/OS. */
- regs->tf_ebx = ps_strings;
-
- /*
- * Reset the hardware debug registers if they were in use.
- * They won't have any meaning for the newly exec'd process.
- */
- if (pcb->pcb_flags & PCB_DBREGS) {
- pcb->pcb_dr0 = 0;
- pcb->pcb_dr1 = 0;
- pcb->pcb_dr2 = 0;
- pcb->pcb_dr3 = 0;
- pcb->pcb_dr6 = 0;
- pcb->pcb_dr7 = 0;
- if (pcb == PCPU_GET(curpcb)) {
- /*
- * Clear the debug registers on the running
- * CPU, otherwise they will end up affecting
- * the next process we switch to.
- */
- reset_dbregs();
- }
- pcb->pcb_flags &= ~PCB_DBREGS;
- }
-
- /*
- * Initialize the math emulator (if any) for the current process.
- * Actually, just clear the bit that says that the emulator has
- * been initialized. Initialization is delayed until the process
- * traps to the emulator (if it is done at all) mainly because
- * emulators don't provide an entry point for initialization.
- */
- td->td_pcb->pcb_flags &= ~FP_SOFTFP;
-
- /*
- * Arrange to trap the next npx or `fwait' instruction (see npx.c
- * for why fwait must be trapped at least if there is an npx or an
- * emulator). This is mainly to handle the case where npx0 is not
- * configured, since the npx routines normally set up the trap
- * otherwise. It should be done only at boot time, but doing it
- * here allows modifying `npx_exists' for testing the emulator on
- * systems with an npx.
- */
- load_cr0(rcr0() | CR0_MP | CR0_TS);
-
- /* Initialize the npx (if any) for the current process. */
- /*
- * XXX the above load_cr0() also initializes it and is a layering
- * violation if NPX is configured. It drops the npx partially
- * and this would be fatal if we were interrupted now, and decided
- * to force the state to the pcb, and checked the invariant
- * (CR0_TS clear) if and only if PCPU_GET(fpcurthread) != NULL).
- * ALL of this can happen except the check. The check used to
- * happen and be fatal later when we didn't complete the drop
- * before returning to user mode. This should be fixed properly
- * soon.
- */
- fpstate_drop(td);
-
- /*
- * XXX - Linux emulator
- * Make sure sure edx is 0x0 on entry. Linux binaries depend
- * on it.
- */
- td->td_retval[1] = 0;
-}
-
-void
-cpu_setregs(void)
-{
- unsigned int cr0;
-
- cr0 = rcr0();
-#ifdef SMP
- cr0 |= CR0_NE; /* Done by npxinit() */
-#endif
- cr0 |= CR0_MP | CR0_TS; /* Done at every execve() too. */
-#ifndef I386_CPU
- cr0 |= CR0_WP | CR0_AM;
-#endif
- load_cr0(cr0);
- load_gs(_udatasel);
-}
-
-static int
-sysctl_machdep_adjkerntz(SYSCTL_HANDLER_ARGS)
-{
- int error;
- error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2,
- req);
- if (!error && req->newptr)
- resettodr();
- return (error);
-}
-
-SYSCTL_PROC(_machdep, CPU_ADJKERNTZ, adjkerntz, CTLTYPE_INT|CTLFLAG_RW,
- &adjkerntz, 0, sysctl_machdep_adjkerntz, "I", "");
-
-SYSCTL_INT(_machdep, CPU_DISRTCSET, disable_rtc_set,
- CTLFLAG_RW, &disable_rtc_set, 0, "");
-
-SYSCTL_STRUCT(_machdep, CPU_BOOTINFO, bootinfo,
- CTLFLAG_RD, &bootinfo, bootinfo, "");
-
-SYSCTL_INT(_machdep, CPU_WALLCLOCK, wall_cmos_clock,
- CTLFLAG_RW, &wall_cmos_clock, 0, "");
-
-u_long bootdev; /* not a dev_t - encoding is different */
-SYSCTL_ULONG(_machdep, OID_AUTO, guessed_bootdev,
- CTLFLAG_RD, &bootdev, 0, "Maybe the Boot device (not in dev_t format)");
-
-/*
- * Initialize 386 and configure to run kernel
- */
-
-/*
- * Initialize segments & interrupt table
- */
-
-int _default_ldt;
-union descriptor gdt[NGDT * MAXCPU]; /* global descriptor table */
-static struct gate_descriptor idt0[NIDT];
-struct gate_descriptor *idt = &idt0[0]; /* interrupt descriptor table */
-union descriptor ldt[NLDT]; /* local descriptor table */
-#ifdef SMP
-/* table descriptors - used to load tables by microp */
-struct region_descriptor r_gdt, r_idt;
-#endif
-
-int private_tss; /* flag indicating private tss */
-
-#if defined(I586_CPU) && !defined(NO_F00F_HACK)
-extern int has_f00f_bug;
-#endif
-
-static struct i386tss dblfault_tss;
-static char dblfault_stack[PAGE_SIZE];
-
-extern struct user *proc0uarea;
-extern vm_offset_t proc0kstack;
-
-
-/* software prototypes -- in more palatable form */
-struct soft_segment_descriptor gdt_segs[] = {
-/* GNULL_SEL 0 Null Descriptor */
-{ 0x0, /* segment base address */
- 0x0, /* length */
- 0, /* segment type */
- 0, /* segment descriptor priority level */
- 0, /* segment descriptor present */
- 0, 0,
- 0, /* default 32 vs 16 bit size */
- 0 /* limit granularity (byte/page units)*/ },
-/* GCODE_SEL 1 Code Descriptor for kernel */
-{ 0x0, /* segment base address */
- 0xfffff, /* length - all address space */
- SDT_MEMERA, /* segment type */
- 0, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 1, /* default 32 vs 16 bit size */
- 1 /* limit granularity (byte/page units)*/ },
-/* GDATA_SEL 2 Data Descriptor for kernel */
-{ 0x0, /* segment base address */
- 0xfffff, /* length - all address space */
- SDT_MEMRWA, /* segment type */
- 0, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 1, /* default 32 vs 16 bit size */
- 1 /* limit granularity (byte/page units)*/ },
-/* GPRIV_SEL 3 SMP Per-Processor Private Data Descriptor */
-{ 0x0, /* segment base address */
- 0xfffff, /* length - all address space */
- SDT_MEMRWA, /* segment type */
- 0, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 1, /* default 32 vs 16 bit size */
- 1 /* limit granularity (byte/page units)*/ },
-/* GPROC0_SEL 4 Proc 0 Tss Descriptor */
-{
- 0x0, /* segment base address */
- sizeof(struct i386tss)-1,/* length - all address space */
- SDT_SYS386TSS, /* segment type */
- 0, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 0, /* unused - default 32 vs 16 bit size */
- 0 /* limit granularity (byte/page units)*/ },
-/* GLDT_SEL 5 LDT Descriptor */
-{ (int) ldt, /* segment base address */
- sizeof(ldt)-1, /* length - all address space */
- SDT_SYSLDT, /* segment type */
- SEL_UPL, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 0, /* unused - default 32 vs 16 bit size */
- 0 /* limit granularity (byte/page units)*/ },
-/* GUSERLDT_SEL 6 User LDT Descriptor per process */
-{ (int) ldt, /* segment base address */
- (512 * sizeof(union descriptor)-1), /* length */
- SDT_SYSLDT, /* segment type */
- 0, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 0, /* unused - default 32 vs 16 bit size */
- 0 /* limit granularity (byte/page units)*/ },
-/* GTGATE_SEL 7 Null Descriptor - Placeholder */
-{ 0x0, /* segment base address */
- 0x0, /* length - all address space */
- 0, /* segment type */
- 0, /* segment descriptor priority level */
- 0, /* segment descriptor present */
- 0, 0,
- 0, /* default 32 vs 16 bit size */
- 0 /* limit granularity (byte/page units)*/ },
-/* GBIOSLOWMEM_SEL 8 BIOS access to realmode segment 0x40, must be #8 in GDT */
-{ 0x400, /* segment base address */
- 0xfffff, /* length */
- SDT_MEMRWA, /* segment type */
- 0, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 1, /* default 32 vs 16 bit size */
- 1 /* limit granularity (byte/page units)*/ },
-/* GPANIC_SEL 9 Panic Tss Descriptor */
-{ (int) &dblfault_tss, /* segment base address */
- sizeof(struct i386tss)-1,/* length - all address space */
- SDT_SYS386TSS, /* segment type */
- 0, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 0, /* unused - default 32 vs 16 bit size */
- 0 /* limit granularity (byte/page units)*/ },
-/* GBIOSCODE32_SEL 10 BIOS 32-bit interface (32bit Code) */
-{ 0, /* segment base address (overwritten) */
- 0xfffff, /* length */
- SDT_MEMERA, /* segment type */
- 0, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 0, /* default 32 vs 16 bit size */
- 1 /* limit granularity (byte/page units)*/ },
-/* GBIOSCODE16_SEL 11 BIOS 32-bit interface (16bit Code) */
-{ 0, /* segment base address (overwritten) */
- 0xfffff, /* length */
- SDT_MEMERA, /* segment type */
- 0, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 0, /* default 32 vs 16 bit size */
- 1 /* limit granularity (byte/page units)*/ },
-/* GBIOSDATA_SEL 12 BIOS 32-bit interface (Data) */
-{ 0, /* segment base address (overwritten) */
- 0xfffff, /* length */
- SDT_MEMRWA, /* segment type */
- 0, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 1, /* default 32 vs 16 bit size */
- 1 /* limit granularity (byte/page units)*/ },
-/* GBIOSUTIL_SEL 13 BIOS 16-bit interface (Utility) */
-{ 0, /* segment base address (overwritten) */
- 0xfffff, /* length */
- SDT_MEMRWA, /* segment type */
- 0, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 0, /* default 32 vs 16 bit size */
- 1 /* limit granularity (byte/page units)*/ },
-/* GBIOSARGS_SEL 14 BIOS 16-bit interface (Arguments) */
-{ 0, /* segment base address (overwritten) */
- 0xfffff, /* length */
- SDT_MEMRWA, /* segment type */
- 0, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 0, /* default 32 vs 16 bit size */
- 1 /* limit granularity (byte/page units)*/ },
-};
-
-static struct soft_segment_descriptor ldt_segs[] = {
- /* Null Descriptor - overwritten by call gate */
-{ 0x0, /* segment base address */
- 0x0, /* length - all address space */
- 0, /* segment type */
- 0, /* segment descriptor priority level */
- 0, /* segment descriptor present */
- 0, 0,
- 0, /* default 32 vs 16 bit size */
- 0 /* limit granularity (byte/page units)*/ },
- /* Null Descriptor - overwritten by call gate */
-{ 0x0, /* segment base address */
- 0x0, /* length - all address space */
- 0, /* segment type */
- 0, /* segment descriptor priority level */
- 0, /* segment descriptor present */
- 0, 0,
- 0, /* default 32 vs 16 bit size */
- 0 /* limit granularity (byte/page units)*/ },
- /* Null Descriptor - overwritten by call gate */
-{ 0x0, /* segment base address */
- 0x0, /* length - all address space */
- 0, /* segment type */
- 0, /* segment descriptor priority level */
- 0, /* segment descriptor present */
- 0, 0,
- 0, /* default 32 vs 16 bit size */
- 0 /* limit granularity (byte/page units)*/ },
- /* Code Descriptor for user */
-{ 0x0, /* segment base address */
- 0xfffff, /* length - all address space */
- SDT_MEMERA, /* segment type */
- SEL_UPL, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 1, /* default 32 vs 16 bit size */
- 1 /* limit granularity (byte/page units)*/ },
- /* Null Descriptor - overwritten by call gate */
-{ 0x0, /* segment base address */
- 0x0, /* length - all address space */
- 0, /* segment type */
- 0, /* segment descriptor priority level */
- 0, /* segment descriptor present */
- 0, 0,
- 0, /* default 32 vs 16 bit size */
- 0 /* limit granularity (byte/page units)*/ },
- /* Data Descriptor for user */
-{ 0x0, /* segment base address */
- 0xfffff, /* length - all address space */
- SDT_MEMRWA, /* segment type */
- SEL_UPL, /* segment descriptor priority level */
- 1, /* segment descriptor present */
- 0, 0,
- 1, /* default 32 vs 16 bit size */
- 1 /* limit granularity (byte/page units)*/ },
-};
-
-void
-setidt(idx, func, typ, dpl, selec)
- int idx;
- inthand_t *func;
- int typ;
- int dpl;
- int selec;
-{
- struct gate_descriptor *ip;
-
- ip = idt + idx;
- ip->gd_looffset = (int)func;
- ip->gd_selector = selec;
- ip->gd_stkcpy = 0;
- ip->gd_xx = 0;
- ip->gd_type = typ;
- ip->gd_dpl = dpl;
- ip->gd_p = 1;
- ip->gd_hioffset = ((int)func)>>16 ;
-}
-
-#define IDTVEC(name) __CONCAT(X,name)
-
-extern inthand_t
- IDTVEC(div), IDTVEC(dbg), IDTVEC(nmi), IDTVEC(bpt), IDTVEC(ofl),
- IDTVEC(bnd), IDTVEC(ill), IDTVEC(dna), IDTVEC(fpusegm),
- IDTVEC(tss), IDTVEC(missing), IDTVEC(stk), IDTVEC(prot),
- IDTVEC(page), IDTVEC(mchk), IDTVEC(rsvd), IDTVEC(fpu), IDTVEC(align),
- IDTVEC(xmm), IDTVEC(lcall_syscall), IDTVEC(int0x80_syscall);
-
-void
-sdtossd(sd, ssd)
- struct segment_descriptor *sd;
- struct soft_segment_descriptor *ssd;
-{
- ssd->ssd_base = (sd->sd_hibase << 24) | sd->sd_lobase;
- ssd->ssd_limit = (sd->sd_hilimit << 16) | sd->sd_lolimit;
- ssd->ssd_type = sd->sd_type;
- ssd->ssd_dpl = sd->sd_dpl;
- ssd->ssd_p = sd->sd_p;
- ssd->ssd_def32 = sd->sd_def32;
- ssd->ssd_gran = sd->sd_gran;
-}
-
-#define PHYSMAP_SIZE (2 * 8)
-
-/*
- * Populate the (physmap) array with base/bound pairs describing the
- * available physical memory in the system, then test this memory and
- * build the phys_avail array describing the actually-available memory.
- *
- * If we cannot accurately determine the physical memory map, then use
- * value from the 0xE801 call, and failing that, the RTC.
- *
- * Total memory size may be set by the kernel environment variable
- * hw.physmem or the compile-time define MAXMEM.
- *
- * XXX first should be vm_paddr_t.
- */
-static void
-getmemsize(int first)
-{
-#ifdef PC98
- int i, physmap_idx, pa_indx, pg_n;
- u_int basemem, extmem, under16;
- vm_offset_t pa, physmap[PHYSMAP_SIZE];
- pt_entry_t *pte;
- char *cp;
-#else
- int i, physmap_idx, pa_indx;
- u_int basemem, extmem;
- struct vm86frame vmf;
- struct vm86context vmc;
- vm_paddr_t pa, physmap[PHYSMAP_SIZE];
- pt_entry_t *pte;
- char *cp;
- struct bios_smap *smap;
-#endif
-
-#ifdef PC98
- /* XXX - some of EPSON machines can't use PG_N */
- pg_n = PG_N;
- if (pc98_machine_type & M_EPSON_PC98) {
- switch (epson_machine_id) {
-#ifdef WB_CACHE
- default:
-#endif
- case 0x34: /* PC-486HX */
- case 0x35: /* PC-486HG */
- case 0x3B: /* PC-486HA */
- pg_n = 0;
- break;
- }
- }
- bzero(physmap, sizeof(physmap));
-
- /*
- * Perform "base memory" related probes & setup
- */
- under16 = pc98_getmemsize(&basemem, &extmem);
- if (basemem > 640) {
- printf("Preposterous BIOS basemem of %uK, truncating to 640K\n",
- basemem);
- basemem = 640;
- }
-
- /*
- * XXX if biosbasemem is now < 640, there is a `hole'
- * between the end of base memory and the start of
- * ISA memory. The hole may be empty or it may
- * contain BIOS code or data. Map it read/write so
- * that the BIOS can write to it. (Memory from 0 to
- * the physical end of the kernel is mapped read-only
- * to begin with and then parts of it are remapped.
- * The parts that aren't remapped form holes that
- * remain read-only and are unused by the kernel.
- * The base memory area is below the physical end of
- * the kernel and right now forms a read-only hole.
- * The part of it from PAGE_SIZE to
- * (trunc_page(biosbasemem * 1024) - 1) will be
- * remapped and used by the kernel later.)
- *
- * This code is similar to the code used in
- * pmap_mapdev, but since no memory needs to be
- * allocated we simply change the mapping.
- */
- for (pa = trunc_page(basemem * 1024);
- pa < ISA_HOLE_START; pa += PAGE_SIZE)
- pmap_kenter(KERNBASE + pa, pa);
-
- /*
- * if basemem != 640, map pages r/w into vm86 page table so
- * that the bios can scribble on it.
- */
- pte = (pt_entry_t *)vm86paddr;
- for (i = basemem / 4; i < 160; i++)
- pte[i] = (i << PAGE_SHIFT) | PG_V | PG_RW | PG_U;
-
-#else /* PC98 */
-
- bzero(&vmf, sizeof(struct vm86frame));
- bzero(physmap, sizeof(physmap));
- basemem = 0;
-
- /*
- * map page 1 R/W into the kernel page table so we can use it
- * as a buffer. The kernel will unmap this page later.
- */
- pmap_kenter(KERNBASE + (1 << PAGE_SHIFT), 1 << PAGE_SHIFT);
-
- /*
- * get memory map with INT 15:E820
- */
- vmc.npages = 0;
- smap = (void *)vm86_addpage(&vmc, 1, KERNBASE + (1 << PAGE_SHIFT));
- vm86_getptr(&vmc, (vm_offset_t)smap, &vmf.vmf_es, &vmf.vmf_di);
-
- physmap_idx = 0;
- vmf.vmf_ebx = 0;
- do {
- vmf.vmf_eax = 0xE820;
- vmf.vmf_edx = SMAP_SIG;
- vmf.vmf_ecx = sizeof(struct bios_smap);
- i = vm86_datacall(0x15, &vmf, &vmc);
- if (i || vmf.vmf_eax != SMAP_SIG)
- break;
- if (boothowto & RB_VERBOSE)
- printf("SMAP type=%02x base=%016llx len=%016llx\n",
- smap->type, smap->base, smap->length);
-
- if (smap->type != 0x01)
- goto next_run;
-
- if (smap->length == 0)
- goto next_run;
-
- if (smap->base >= 0xffffffff) {
- printf("%uK of memory above 4GB ignored\n",
- (u_int)(smap->length / 1024));
- goto next_run;
- }
-
- for (i = 0; i <= physmap_idx; i += 2) {
- if (smap->base < physmap[i + 1]) {
- if (boothowto & RB_VERBOSE)
- printf(
- "Overlapping or non-montonic memory region, ignoring second region\n");
- goto next_run;
- }
- }
-
- if (smap->base == physmap[physmap_idx + 1]) {
- physmap[physmap_idx + 1] += smap->length;
- goto next_run;
- }
-
- physmap_idx += 2;
- if (physmap_idx == PHYSMAP_SIZE) {
- printf(
- "Too many segments in the physical address map, giving up\n");
- break;
- }
- physmap[physmap_idx] = smap->base;
- physmap[physmap_idx + 1] = smap->base + smap->length;
-next_run: ;
- } while (vmf.vmf_ebx != 0);
-
- /*
- * Perform "base memory" related probes & setup
- */
- for (i = 0; i <= physmap_idx; i += 2) {
- if (physmap[i] == 0x00000000) {
- basemem = physmap[i + 1] / 1024;
- break;
- }
- }
-
- /* Fall back to the old compatibility function for base memory */
- if (basemem == 0) {
- vm86_intcall(0x12, &vmf);
- basemem = vmf.vmf_ax;
- }
-
- if (basemem > 640) {
- printf("Preposterous BIOS basemem of %uK, truncating to 640K\n",
- basemem);
- basemem = 640;
- }
-
- /*
- * XXX if biosbasemem is now < 640, there is a `hole'
- * between the end of base memory and the start of
- * ISA memory. The hole may be empty or it may
- * contain BIOS code or data. Map it read/write so
- * that the BIOS can write to it. (Memory from 0 to
- * the physical end of the kernel is mapped read-only
- * to begin with and then parts of it are remapped.
- * The parts that aren't remapped form holes that
- * remain read-only and are unused by the kernel.
- * The base memory area is below the physical end of
- * the kernel and right now forms a read-only hole.
- * The part of it from PAGE_SIZE to
- * (trunc_page(biosbasemem * 1024) - 1) will be
- * remapped and used by the kernel later.)
- *
- * This code is similar to the code used in
- * pmap_mapdev, but since no memory needs to be
- * allocated we simply change the mapping.
- */
- for (pa = trunc_page(basemem * 1024);
- pa < ISA_HOLE_START; pa += PAGE_SIZE)
- pmap_kenter(KERNBASE + pa, pa);
-
- /*
- * if basemem != 640, map pages r/w into vm86 page table so
- * that the bios can scribble on it.
- */
- pte = (pt_entry_t *)vm86paddr;
- for (i = basemem / 4; i < 160; i++)
- pte[i] = (i << PAGE_SHIFT) | PG_V | PG_RW | PG_U;
-
- if (physmap[1] != 0)
- goto physmap_done;
-
- /*
- * If we failed above, try memory map with INT 15:E801
- */
- vmf.vmf_ax = 0xE801;
- if (vm86_intcall(0x15, &vmf) == 0) {
- extmem = vmf.vmf_cx + vmf.vmf_dx * 64;
- } else {
-#if 0
- vmf.vmf_ah = 0x88;
- vm86_intcall(0x15, &vmf);
- extmem = vmf.vmf_ax;
-#else
- /*
- * Prefer the RTC value for extended memory.
- */
- extmem = rtcin(RTC_EXTLO) + (rtcin(RTC_EXTHI) << 8);
-#endif
- }
-
- /*
- * Special hack for chipsets that still remap the 384k hole when
- * there's 16MB of memory - this really confuses people that
- * are trying to use bus mastering ISA controllers with the
- * "16MB limit"; they only have 16MB, but the remapping puts
- * them beyond the limit.
- *
- * If extended memory is between 15-16MB (16-17MB phys address range),
- * chop it to 15MB.
- */
- if ((extmem > 15 * 1024) && (extmem < 16 * 1024))
- extmem = 15 * 1024;
-#endif /* PC98 */
-
- physmap[0] = 0;
- physmap[1] = basemem * 1024;
- physmap_idx = 2;
- physmap[physmap_idx] = 0x100000;
- physmap[physmap_idx + 1] = physmap[physmap_idx] + extmem * 1024;
-
-#ifdef PC98
- if ((under16 != 16 * 1024) && (extmem > 15 * 1024)) {
- /* 15M - 16M region is cut off, so need to divide chunk */
- physmap[physmap_idx + 1] = under16 * 1024;
- physmap_idx += 2;
- physmap[physmap_idx] = 0x1000000;
- physmap[physmap_idx + 1] = physmap[2] + extmem * 1024;
- }
-#else
-physmap_done:
-#endif
- /*
- * Now, physmap contains a map of physical memory.
- */
-
-#ifdef SMP
- /* make hole for AP bootstrap code */
- physmap[1] = mp_bootaddress(physmap[1] / 1024);
-
- /* look for the MP hardware - needed for apic addresses */
- i386_mp_probe();
-#endif
-
- /*
- * Maxmem isn't the "maximum memory", it's one larger than the
- * highest page of the physical address space. It should be
- * called something like "Maxphyspage". We may adjust this
- * based on ``hw.physmem'' and the results of the memory test.
- */
- Maxmem = atop(physmap[physmap_idx + 1]);
-
-#ifdef MAXMEM
- Maxmem = MAXMEM / 4;
-#endif
-
- /*
- * hw.physmem is a size in bytes; we also allow k, m, and g suffixes
- * for the appropriate modifiers. This overrides MAXMEM.
- */
- if ((cp = getenv("hw.physmem")) != NULL) {
- u_int64_t AllowMem, sanity;
- char *ep;
-
- sanity = AllowMem = strtouq(cp, &ep, 0);
- if ((ep != cp) && (*ep != 0)) {
- switch(*ep) {
- case 'g':
- case 'G':
- AllowMem <<= 10;
- case 'm':
- case 'M':
- AllowMem <<= 10;
- case 'k':
- case 'K':
- AllowMem <<= 10;
- break;
- default:
- AllowMem = sanity = 0;
- }
- if (AllowMem < sanity)
- AllowMem = 0;
- }
- if (AllowMem == 0)
- printf("Ignoring invalid memory size of '%s'\n", cp);
- else
- Maxmem = atop(AllowMem);
- freeenv(cp);
- }
-
- if (atop(physmap[physmap_idx + 1]) != Maxmem &&
- (boothowto & RB_VERBOSE))
- printf("Physical memory use set to %ldK\n", Maxmem * 4);
-
- /*
- * If Maxmem has been increased beyond what the system has detected,
- * extend the last memory segment to the new limit.
- */
- if (atop(physmap[physmap_idx + 1]) < Maxmem)
- physmap[physmap_idx + 1] = ptoa((vm_paddr_t)Maxmem);
-
- /* call pmap initialization to make new kernel address space */
- pmap_bootstrap(first, 0);
-
- /*
- * Size up each available chunk of physical memory.
- */
- physmap[0] = PAGE_SIZE; /* mask off page 0 */
- pa_indx = 0;
- phys_avail[pa_indx++] = physmap[0];
- phys_avail[pa_indx] = physmap[0];
- pte = CMAP1;
-
- /*
- * physmap is in bytes, so when converting to page boundaries,
- * round up the start address and round down the end address.
- */
- for (i = 0; i <= physmap_idx; i += 2) {
- vm_paddr_t end;
-
- end = ptoa((vm_paddr_t)Maxmem);
- if (physmap[i + 1] < end)
- end = trunc_page(physmap[i + 1]);
- for (pa = round_page(physmap[i]); pa < end; pa += PAGE_SIZE) {
- int tmp, page_bad;
- int *ptr = (int *)CADDR1;
-
- /*
- * block out kernel memory as not available.
- */
- if (pa >= 0x100000 && pa < first)
- continue;
-
- page_bad = FALSE;
-
- /*
- * map page into kernel: valid, read/write,non-cacheable
- */
-#ifdef PC98
- *pte = pa | PG_V | PG_RW | pg_n;
-#else
- *pte = pa | PG_V | PG_RW | PG_N;
-#endif
- invltlb();
-
- tmp = *(int *)ptr;
- /*
- * Test for alternating 1's and 0's
- */
- *(volatile int *)ptr = 0xaaaaaaaa;
- if (*(volatile int *)ptr != 0xaaaaaaaa) {
- page_bad = TRUE;
- }
- /*
- * Test for alternating 0's and 1's
- */
- *(volatile int *)ptr = 0x55555555;
- if (*(volatile int *)ptr != 0x55555555) {
- page_bad = TRUE;
- }
- /*
- * Test for all 1's
- */
- *(volatile int *)ptr = 0xffffffff;
- if (*(volatile int *)ptr != 0xffffffff) {
- page_bad = TRUE;
- }
- /*
- * Test for all 0's
- */
- *(volatile int *)ptr = 0x0;
- if (*(volatile int *)ptr != 0x0) {
- page_bad = TRUE;
- }
- /*
- * Restore original value.
- */
- *(int *)ptr = tmp;
-
- /*
- * Adjust array of valid/good pages.
- */
- if (page_bad == TRUE) {
- continue;
- }
- /*
- * If this good page is a continuation of the
- * previous set of good pages, then just increase
- * the end pointer. Otherwise start a new chunk.
- * Note that "end" points one higher than end,
- * making the range >= start and < end.
- * If we're also doing a speculative memory
- * test and we at or past the end, bump up Maxmem
- * so that we keep going. The first bad page
- * will terminate the loop.
- */
- if (phys_avail[pa_indx] == pa) {
- phys_avail[pa_indx] += PAGE_SIZE;
- } else {
- pa_indx++;
- if (pa_indx == PHYS_AVAIL_ARRAY_END) {
- printf(
- "Too many holes in the physical address space, giving up\n");
- pa_indx--;
- break;
- }
- phys_avail[pa_indx++] = pa; /* start */
- phys_avail[pa_indx] = pa + PAGE_SIZE; /* end */
- }
- physmem++;
- }
- }
- *pte = 0;
- invltlb();
-
- /*
- * XXX
- * The last chunk must contain at least one page plus the message
- * buffer to avoid complicating other code (message buffer address
- * calculation, etc.).
- */
- while (phys_avail[pa_indx - 1] + PAGE_SIZE +
- round_page(MSGBUF_SIZE) >= phys_avail[pa_indx]) {
- physmem -= atop(phys_avail[pa_indx] - phys_avail[pa_indx - 1]);
- phys_avail[pa_indx--] = 0;
- phys_avail[pa_indx--] = 0;
- }
-
- Maxmem = atop(phys_avail[pa_indx]);
-
- /* Trim off space for the message buffer. */
- phys_avail[pa_indx] -= round_page(MSGBUF_SIZE);
-
- avail_end = phys_avail[pa_indx];
-}
-
-void
-init386(first)
- int first;
-{
- struct gate_descriptor *gdp;
- int gsel_tss, metadata_missing, off, x;
-#ifndef SMP
- /* table descriptors - used to load tables by microp */
- struct region_descriptor r_gdt, r_idt;
-#endif
- struct pcpu *pc;
-
- proc0.p_uarea = proc0uarea;
- thread0.td_kstack = proc0kstack;
- thread0.td_pcb = (struct pcb *)
- (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
- atdevbase = ISA_HOLE_START + KERNBASE;
-
- /*
- * This may be done better later if it gets more high level
- * components in it. If so just link td->td_proc here.
- */
- proc_linkup(&proc0, &ksegrp0, &kse0, &thread0);
-
-#ifdef PC98
- /*
- * Initialize DMAC
- */
- pc98_init_dmac();
-#endif
-
- metadata_missing = 0;
- if (bootinfo.bi_modulep) {
- preload_metadata = (caddr_t)bootinfo.bi_modulep + KERNBASE;
- preload_bootstrap_relocate(KERNBASE);
- } else {
- metadata_missing = 1;
- }
- if (envmode == 1)
- kern_envp = static_env;
- else if (bootinfo.bi_envp)
- kern_envp = (caddr_t)bootinfo.bi_envp + KERNBASE;
-
- /* Init basic tunables, hz etc */
- init_param1();
-
- /*
- * make gdt memory segments, the code segment goes up to end of the
- * page with etext in it, the data segment goes to the end of
- * the address space
- */
- /*
- * XXX text protection is temporarily (?) disabled. The limit was
- * i386_btop(round_page(etext)) - 1.
- */
- gdt_segs[GCODE_SEL].ssd_limit = atop(0 - 1);
- gdt_segs[GDATA_SEL].ssd_limit = atop(0 - 1);
-#ifdef SMP
- pc = &SMP_prvspace[0].pcpu;
- gdt_segs[GPRIV_SEL].ssd_limit =
- atop(sizeof(struct privatespace) - 1);
-#else
- pc = &__pcpu;
- gdt_segs[GPRIV_SEL].ssd_limit =
- atop(sizeof(struct pcpu) - 1);
-#endif
- gdt_segs[GPRIV_SEL].ssd_base = (int) pc;
- gdt_segs[GPROC0_SEL].ssd_base = (int) &pc->pc_common_tss;
-
- for (x = 0; x < NGDT; x++)
- ssdtosd(&gdt_segs[x], &gdt[x].sd);
-
- r_gdt.rd_limit = NGDT * sizeof(gdt[0]) - 1;
- r_gdt.rd_base = (int) gdt;
- lgdt(&r_gdt);
-
- pcpu_init(pc, 0, sizeof(struct pcpu));
- PCPU_SET(prvspace, pc);
- PCPU_SET(curthread, &thread0);
-
- /*
- * Initialize mutexes.
- *
- * icu_lock: in order to allow an interrupt to occur in a critical
- * section, to set pcpu->ipending (etc...) properly, we
- * must be able to get the icu lock, so it can't be
- * under witness.
- */
- mutex_init();
- mtx_init(&clock_lock, "clk", NULL, MTX_SPIN | MTX_RECURSE);
- mtx_init(&icu_lock, "icu", NULL, MTX_SPIN | MTX_NOWITNESS);
-
- /* make ldt memory segments */
- /*
- * XXX - VM_MAXUSER_ADDRESS is an end address, not a max. And it
- * should be spelled ...MAX_USER...
- */
- ldt_segs[LUCODE_SEL].ssd_limit = atop(VM_MAXUSER_ADDRESS - 1);
- ldt_segs[LUDATA_SEL].ssd_limit = atop(VM_MAXUSER_ADDRESS - 1);
- for (x = 0; x < sizeof ldt_segs / sizeof ldt_segs[0]; x++)
- ssdtosd(&ldt_segs[x], &ldt[x].sd);
-
- _default_ldt = GSEL(GLDT_SEL, SEL_KPL);
- lldt(_default_ldt);
- PCPU_SET(currentldt, _default_ldt);
-
- /* exceptions */
- for (x = 0; x < NIDT; x++)
- setidt(x, &IDTVEC(rsvd), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(0, &IDTVEC(div), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(1, &IDTVEC(dbg), SDT_SYS386IGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(2, &IDTVEC(nmi), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(3, &IDTVEC(bpt), SDT_SYS386IGT, SEL_UPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(4, &IDTVEC(ofl), SDT_SYS386TGT, SEL_UPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(5, &IDTVEC(bnd), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(6, &IDTVEC(ill), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(7, &IDTVEC(dna), SDT_SYS386TGT, SEL_KPL
- , GSEL(GCODE_SEL, SEL_KPL));
- setidt(8, 0, SDT_SYSTASKGT, SEL_KPL, GSEL(GPANIC_SEL, SEL_KPL));
- setidt(9, &IDTVEC(fpusegm), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(10, &IDTVEC(tss), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(11, &IDTVEC(missing), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(12, &IDTVEC(stk), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(13, &IDTVEC(prot), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(14, &IDTVEC(page), SDT_SYS386IGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(15, &IDTVEC(rsvd), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(16, &IDTVEC(fpu), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(17, &IDTVEC(align), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(18, &IDTVEC(mchk), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(19, &IDTVEC(xmm), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(0x80, &IDTVEC(int0x80_syscall), SDT_SYS386TGT, SEL_UPL,
- GSEL(GCODE_SEL, SEL_KPL));
-
- r_idt.rd_limit = sizeof(idt0) - 1;
- r_idt.rd_base = (int) idt;
- lidt(&r_idt);
-
- /*
- * Initialize the console before we print anything out.
- */
- cninit();
-
- if (metadata_missing)
- printf("WARNING: loader(8) metadata is missing!\n");
-
-#ifdef DEV_ISA
- isa_defaultirq();
-#endif
-
-#ifdef DDB
- kdb_init();
- if (boothowto & RB_KDB)
- Debugger("Boot flags requested debugger");
-#endif
-
- finishidentcpu(); /* Final stage of CPU initialization */
- setidt(6, &IDTVEC(ill), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- setidt(13, &IDTVEC(prot), SDT_SYS386TGT, SEL_KPL,
- GSEL(GCODE_SEL, SEL_KPL));
- initializecpu(); /* Initialize CPU registers */
-
- /* make an initial tss so cpu can get interrupt stack on syscall! */
- /* Note: -16 is so we can grow the trapframe if we came from vm86 */
- PCPU_SET(common_tss.tss_esp0, thread0.td_kstack +
- KSTACK_PAGES * PAGE_SIZE - sizeof(struct pcb) - 16);
- PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL));
- gsel_tss = GSEL(GPROC0_SEL, SEL_KPL);
- private_tss = 0;
- PCPU_SET(tss_gdt, &gdt[GPROC0_SEL].sd);
- PCPU_SET(common_tssd, *PCPU_GET(tss_gdt));
- PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16);
- ltr(gsel_tss);
-
- dblfault_tss.tss_esp = dblfault_tss.tss_esp0 = dblfault_tss.tss_esp1 =
- dblfault_tss.tss_esp2 = (int)&dblfault_stack[sizeof(dblfault_stack)];
- dblfault_tss.tss_ss = dblfault_tss.tss_ss0 = dblfault_tss.tss_ss1 =
- dblfault_tss.tss_ss2 = GSEL(GDATA_SEL, SEL_KPL);
- dblfault_tss.tss_cr3 = (int)IdlePTD;
- dblfault_tss.tss_eip = (int)dblfault_handler;
- dblfault_tss.tss_eflags = PSL_KERNEL;
- dblfault_tss.tss_ds = dblfault_tss.tss_es =
- dblfault_tss.tss_gs = GSEL(GDATA_SEL, SEL_KPL);
- dblfault_tss.tss_fs = GSEL(GPRIV_SEL, SEL_KPL);
- dblfault_tss.tss_cs = GSEL(GCODE_SEL, SEL_KPL);
- dblfault_tss.tss_ldt = GSEL(GLDT_SEL, SEL_KPL);
-
- vm86_initialize();
- getmemsize(first);
- init_param2(physmem);
-
- /* now running on new page tables, configured,and u/iom is accessible */
-
- /* Map the message buffer. */
- for (off = 0; off < round_page(MSGBUF_SIZE); off += PAGE_SIZE)
- pmap_kenter((vm_offset_t)msgbufp + off, avail_end + off);
-
- msgbufinit(msgbufp, MSGBUF_SIZE);
-
- /* make a call gate to reenter kernel with */
- gdp = &ldt[LSYS5CALLS_SEL].gd;
-
- x = (int) &IDTVEC(lcall_syscall);
- gdp->gd_looffset = x;
- gdp->gd_selector = GSEL(GCODE_SEL,SEL_KPL);
- gdp->gd_stkcpy = 1;
- gdp->gd_type = SDT_SYS386CGT;
- gdp->gd_dpl = SEL_UPL;
- gdp->gd_p = 1;
- gdp->gd_hioffset = x >> 16;
-
- /* XXX does this work? */
- ldt[LBSDICALLS_SEL] = ldt[LSYS5CALLS_SEL];
- ldt[LSOL26CALLS_SEL] = ldt[LSYS5CALLS_SEL];
-
- /* transfer to user mode */
-
- _ucodesel = LSEL(LUCODE_SEL, SEL_UPL);
- _udatasel = LSEL(LUDATA_SEL, SEL_UPL);
-
- /* setup proc 0's pcb */
- thread0.td_pcb->pcb_flags = 0; /* XXXKSE */
- thread0.td_pcb->pcb_cr3 = (int)IdlePTD;
- thread0.td_pcb->pcb_ext = 0;
- thread0.td_frame = &proc0_tf;
-}
-
-void
-cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
-{
-}
-
-#if defined(I586_CPU) && !defined(NO_F00F_HACK)
-static void f00f_hack(void *unused);
-SYSINIT(f00f_hack, SI_SUB_INTRINSIC, SI_ORDER_FIRST, f00f_hack, NULL);
-
-static void
-f00f_hack(void *unused) {
- struct gate_descriptor *new_idt;
-#ifndef SMP
- struct region_descriptor r_idt;
-#endif
- vm_offset_t tmp;
-
- if (!has_f00f_bug)
- return;
-
- GIANT_REQUIRED;
-
- printf("Intel Pentium detected, installing workaround for F00F bug\n");
-
- r_idt.rd_limit = sizeof(idt0) - 1;
-
- tmp = kmem_alloc(kernel_map, PAGE_SIZE * 2);
- if (tmp == 0)
- panic("kmem_alloc returned 0");
- if (((unsigned int)tmp & (PAGE_SIZE-1)) != 0)
- panic("kmem_alloc returned non-page-aligned memory");
- /* Put the first seven entries in the lower page */
- new_idt = (struct gate_descriptor*)(tmp + PAGE_SIZE - (7*8));
- bcopy(idt, new_idt, sizeof(idt0));
- r_idt.rd_base = (int)new_idt;
- lidt(&r_idt);
- idt = new_idt;
- if (vm_map_protect(kernel_map, tmp, tmp + PAGE_SIZE,
- VM_PROT_READ, FALSE) != KERN_SUCCESS)
- panic("vm_map_protect failed");
- return;
-}
-#endif /* defined(I586_CPU) && !NO_F00F_HACK */
-
-int
-ptrace_set_pc(struct thread *td, unsigned long addr)
-{
- td->td_frame->tf_eip = addr;
- return (0);
-}
-
-int
-ptrace_single_step(struct thread *td)
-{
- td->td_frame->tf_eflags |= PSL_T;
- return (0);
-}
-
-int
-fill_regs(struct thread *td, struct reg *regs)
-{
- struct pcb *pcb;
- struct trapframe *tp;
-
- tp = td->td_frame;
- regs->r_fs = tp->tf_fs;
- regs->r_es = tp->tf_es;
- regs->r_ds = tp->tf_ds;
- regs->r_edi = tp->tf_edi;
- regs->r_esi = tp->tf_esi;
- regs->r_ebp = tp->tf_ebp;
- regs->r_ebx = tp->tf_ebx;
- regs->r_edx = tp->tf_edx;
- regs->r_ecx = tp->tf_ecx;
- regs->r_eax = tp->tf_eax;
- regs->r_eip = tp->tf_eip;
- regs->r_cs = tp->tf_cs;
- regs->r_eflags = tp->tf_eflags;
- regs->r_esp = tp->tf_esp;
- regs->r_ss = tp->tf_ss;
- pcb = td->td_pcb;
- regs->r_gs = pcb->pcb_gs;
- return (0);
-}
-
-int
-set_regs(struct thread *td, struct reg *regs)
-{
- struct pcb *pcb;
- struct trapframe *tp;
-
- tp = td->td_frame;
- if (!EFL_SECURE(regs->r_eflags, tp->tf_eflags) ||
- !CS_SECURE(regs->r_cs))
- return (EINVAL);
- tp->tf_fs = regs->r_fs;
- tp->tf_es = regs->r_es;
- tp->tf_ds = regs->r_ds;
- tp->tf_edi = regs->r_edi;
- tp->tf_esi = regs->r_esi;
- tp->tf_ebp = regs->r_ebp;
- tp->tf_ebx = regs->r_ebx;
- tp->tf_edx = regs->r_edx;
- tp->tf_ecx = regs->r_ecx;
- tp->tf_eax = regs->r_eax;
- tp->tf_eip = regs->r_eip;
- tp->tf_cs = regs->r_cs;
- tp->tf_eflags = regs->r_eflags;
- tp->tf_esp = regs->r_esp;
- tp->tf_ss = regs->r_ss;
- pcb = td->td_pcb;
- pcb->pcb_gs = regs->r_gs;
- return (0);
-}
-
-#ifdef CPU_ENABLE_SSE
-static void
-fill_fpregs_xmm(sv_xmm, sv_87)
- struct savexmm *sv_xmm;
- struct save87 *sv_87;
-{
- register struct env87 *penv_87 = &sv_87->sv_env;
- register struct envxmm *penv_xmm = &sv_xmm->sv_env;
- int i;
-
- bzero(sv_87, sizeof(*sv_87));
-
- /* FPU control/status */
- penv_87->en_cw = penv_xmm->en_cw;
- penv_87->en_sw = penv_xmm->en_sw;
- penv_87->en_tw = penv_xmm->en_tw;
- penv_87->en_fip = penv_xmm->en_fip;
- penv_87->en_fcs = penv_xmm->en_fcs;
- penv_87->en_opcode = penv_xmm->en_opcode;
- penv_87->en_foo = penv_xmm->en_foo;
- penv_87->en_fos = penv_xmm->en_fos;
-
- /* FPU registers */
- for (i = 0; i < 8; ++i)
- sv_87->sv_ac[i] = sv_xmm->sv_fp[i].fp_acc;
-}
-
-static void
-set_fpregs_xmm(sv_87, sv_xmm)
- struct save87 *sv_87;
- struct savexmm *sv_xmm;
-{
- register struct env87 *penv_87 = &sv_87->sv_env;
- register struct envxmm *penv_xmm = &sv_xmm->sv_env;
- int i;
-
- /* FPU control/status */
- penv_xmm->en_cw = penv_87->en_cw;
- penv_xmm->en_sw = penv_87->en_sw;
- penv_xmm->en_tw = penv_87->en_tw;
- penv_xmm->en_fip = penv_87->en_fip;
- penv_xmm->en_fcs = penv_87->en_fcs;
- penv_xmm->en_opcode = penv_87->en_opcode;
- penv_xmm->en_foo = penv_87->en_foo;
- penv_xmm->en_fos = penv_87->en_fos;
-
- /* FPU registers */
- for (i = 0; i < 8; ++i)
- sv_xmm->sv_fp[i].fp_acc = sv_87->sv_ac[i];
-}
-#endif /* CPU_ENABLE_SSE */
-
-int
-fill_fpregs(struct thread *td, struct fpreg *fpregs)
-{
-#ifdef CPU_ENABLE_SSE
- if (cpu_fxsr) {
- fill_fpregs_xmm(&td->td_pcb->pcb_save.sv_xmm,
- (struct save87 *)fpregs);
- return (0);
- }
-#endif /* CPU_ENABLE_SSE */
- bcopy(&td->td_pcb->pcb_save.sv_87, fpregs, sizeof *fpregs);
- return (0);
-}
-
-int
-set_fpregs(struct thread *td, struct fpreg *fpregs)
-{
-#ifdef CPU_ENABLE_SSE
- if (cpu_fxsr) {
- set_fpregs_xmm((struct save87 *)fpregs,
- &td->td_pcb->pcb_save.sv_xmm);
- return (0);
- }
-#endif /* CPU_ENABLE_SSE */
- bcopy(fpregs, &td->td_pcb->pcb_save.sv_87, sizeof *fpregs);
- return (0);
-}
-
-/*
- * Get machine context.
- */
-int
-get_mcontext(struct thread *td, mcontext_t *mcp, int clear_ret)
-{
- struct trapframe *tp;
-
- tp = td->td_frame;
-
- PROC_LOCK(curthread->td_proc);
- mcp->mc_onstack = sigonstack(tp->tf_esp);
- PROC_UNLOCK(curthread->td_proc);
- mcp->mc_gs = td->td_pcb->pcb_gs;
- mcp->mc_fs = tp->tf_fs;
- mcp->mc_es = tp->tf_es;
- mcp->mc_ds = tp->tf_ds;
- mcp->mc_edi = tp->tf_edi;
- mcp->mc_esi = tp->tf_esi;
- mcp->mc_ebp = tp->tf_ebp;
- mcp->mc_isp = tp->tf_isp;
- mcp->mc_ebx = tp->tf_ebx;
- if (clear_ret != 0) {
- mcp->mc_eax = 0;
- mcp->mc_edx = 0;
- } else {
- mcp->mc_eax = tp->tf_eax;
- mcp->mc_edx = tp->tf_edx;
- }
- mcp->mc_ecx = tp->tf_ecx;
- mcp->mc_eip = tp->tf_eip;
- mcp->mc_cs = tp->tf_cs;
- mcp->mc_eflags = tp->tf_eflags;
- mcp->mc_esp = tp->tf_esp;
- mcp->mc_ss = tp->tf_ss;
- mcp->mc_len = sizeof(*mcp);
- get_fpcontext(td, mcp);
- return (0);
-}
-
-/*
- * Set machine context.
- *
- * However, we don't set any but the user modifiable flags, and we won't
- * touch the cs selector.
- */
-int
-set_mcontext(struct thread *td, const mcontext_t *mcp)
-{
- struct trapframe *tp;
- int eflags, ret;
-
- tp = td->td_frame;
- if (mcp->mc_len != sizeof(*mcp))
- return (EINVAL);
- eflags = (mcp->mc_eflags & PSL_USERCHANGE) |
- (tp->tf_eflags & ~PSL_USERCHANGE);
- if ((ret = set_fpcontext(td, mcp)) == 0) {
- tp->tf_fs = mcp->mc_fs;
- tp->tf_es = mcp->mc_es;
- tp->tf_ds = mcp->mc_ds;
- tp->tf_edi = mcp->mc_edi;
- tp->tf_esi = mcp->mc_esi;
- tp->tf_ebp = mcp->mc_ebp;
- tp->tf_ebx = mcp->mc_ebx;
- tp->tf_edx = mcp->mc_edx;
- tp->tf_ecx = mcp->mc_ecx;
- tp->tf_eax = mcp->mc_eax;
- tp->tf_eip = mcp->mc_eip;
- tp->tf_eflags = eflags;
- tp->tf_esp = mcp->mc_esp;
- tp->tf_ss = mcp->mc_ss;
- td->td_pcb->pcb_gs = mcp->mc_gs;
- ret = 0;
- }
- return (ret);
-}
-
-static void
-get_fpcontext(struct thread *td, mcontext_t *mcp)
-{
-#ifndef DEV_NPX
- mcp->mc_fpformat = _MC_FPFMT_NODEV;
- mcp->mc_ownedfp = _MC_FPOWNED_NONE;
-#else
- union savefpu *addr;
-
- /*
- * XXX mc_fpstate might be misaligned, since its declaration is not
- * unportabilized using __attribute__((aligned(16))) like the
- * declaration of struct savemm, and anyway, alignment doesn't work
- * for auto variables since we don't use gcc's pessimal stack
- * alignment. Work around this by abusing the spare fields after
- * mcp->mc_fpstate.
- *
- * XXX unpessimize most cases by only aligning when fxsave might be
- * called, although this requires knowing too much about
- * npxgetregs()'s internals.
- */
- addr = (union savefpu *)&mcp->mc_fpstate;
- if (td == PCPU_GET(fpcurthread) &&
-#ifdef CPU_ENABLE_SSE
- cpu_fxsr &&
-#endif
- ((uintptr_t)(void *)addr & 0xF)) {
- do
- addr = (void *)((char *)addr + 4);
- while ((uintptr_t)(void *)addr & 0xF);
- }
- mcp->mc_ownedfp = npxgetregs(td, addr);
- if (addr != (union savefpu *)&mcp->mc_fpstate) {
- bcopy(addr, &mcp->mc_fpstate, sizeof(mcp->mc_fpstate));
- bzero(&mcp->mc_spare2, sizeof(mcp->mc_spare2));
- }
- mcp->mc_fpformat = npxformat();
-#endif
-}
-
-static int
-set_fpcontext(struct thread *td, const mcontext_t *mcp)
-{
- union savefpu *addr;
-
- if (mcp->mc_fpformat == _MC_FPFMT_NODEV)
- return (0);
- else if (mcp->mc_fpformat != _MC_FPFMT_387 &&
- mcp->mc_fpformat != _MC_FPFMT_XMM)
- return (EINVAL);
- else if (mcp->mc_ownedfp == _MC_FPOWNED_NONE)
- /* We don't care what state is left in the FPU or PCB. */
- fpstate_drop(td);
- else if (mcp->mc_ownedfp == _MC_FPOWNED_FPU ||
- mcp->mc_ownedfp == _MC_FPOWNED_PCB) {
- /* XXX align as above. */
- addr = (union savefpu *)&mcp->mc_fpstate;
- if (td == PCPU_GET(fpcurthread) &&
-#ifdef CPU_ENABLE_SSE
- cpu_fxsr &&
-#endif
- ((uintptr_t)(void *)addr & 0xF)) {
- do
- addr = (void *)((char *)addr + 4);
- while ((uintptr_t)(void *)addr & 0xF);
- bcopy(&mcp->mc_fpstate, addr, sizeof(mcp->mc_fpstate));
- }
-#ifdef DEV_NPX
- /*
- * XXX we violate the dubious requirement that npxsetregs()
- * be called with interrupts disabled.
- */
- npxsetregs(td, addr);
-#endif
- /*
- * Don't bother putting things back where they were in the
- * misaligned case, since we know that the caller won't use
- * them again.
- */
- } else
- return (EINVAL);
- return (0);
-}
-
-static void
-fpstate_drop(struct thread *td)
-{
- register_t s;
-
- s = intr_disable();
-#ifdef DEV_NPX
- if (PCPU_GET(fpcurthread) == td)
- npxdrop();
-#endif
- /*
- * XXX force a full drop of the npx. The above only drops it if we
- * owned it. npxgetregs() has the same bug in the !cpu_fxsr case.
- *
- * XXX I don't much like npxgetregs()'s semantics of doing a full
- * drop. Dropping only to the pcb matches fnsave's behaviour.
- * We only need to drop to !PCB_INITDONE in sendsig(). But
- * sendsig() is the only caller of npxgetregs()... perhaps we just
- * have too many layers.
- */
- curthread->td_pcb->pcb_flags &= ~PCB_NPXINITDONE;
- intr_restore(s);
-}
-
-int
-fill_dbregs(struct thread *td, struct dbreg *dbregs)
-{
- struct pcb *pcb;
-
- if (td == NULL) {
- dbregs->dr[0] = rdr0();
- dbregs->dr[1] = rdr1();
- dbregs->dr[2] = rdr2();
- dbregs->dr[3] = rdr3();
- dbregs->dr[4] = rdr4();
- dbregs->dr[5] = rdr5();
- dbregs->dr[6] = rdr6();
- dbregs->dr[7] = rdr7();
- } else {
- pcb = td->td_pcb;
- dbregs->dr[0] = pcb->pcb_dr0;
- dbregs->dr[1] = pcb->pcb_dr1;
- dbregs->dr[2] = pcb->pcb_dr2;
- dbregs->dr[3] = pcb->pcb_dr3;
- dbregs->dr[4] = 0;
- dbregs->dr[5] = 0;
- dbregs->dr[6] = pcb->pcb_dr6;
- dbregs->dr[7] = pcb->pcb_dr7;
- }
- return (0);
-}
-
-int
-set_dbregs(struct thread *td, struct dbreg *dbregs)
-{
- struct pcb *pcb;
- int i;
- u_int32_t mask1, mask2;
-
- if (td == NULL) {
- load_dr0(dbregs->dr[0]);
- load_dr1(dbregs->dr[1]);
- load_dr2(dbregs->dr[2]);
- load_dr3(dbregs->dr[3]);
- load_dr4(dbregs->dr[4]);
- load_dr5(dbregs->dr[5]);
- load_dr6(dbregs->dr[6]);
- load_dr7(dbregs->dr[7]);
- } else {
- /*
- * Don't let an illegal value for dr7 get set. Specifically,
- * check for undefined settings. Setting these bit patterns
- * result in undefined behaviour and can lead to an unexpected
- * TRCTRAP.
- */
- for (i = 0, mask1 = 0x3<<16, mask2 = 0x2<<16; i < 8;
- i++, mask1 <<= 2, mask2 <<= 2)
- if ((dbregs->dr[7] & mask1) == mask2)
- return (EINVAL);
-
- pcb = td->td_pcb;
-
- /*
- * Don't let a process set a breakpoint that is not within the
- * process's address space. If a process could do this, it
- * could halt the system by setting a breakpoint in the kernel
- * (if ddb was enabled). Thus, we need to check to make sure
- * that no breakpoints are being enabled for addresses outside
- * process's address space, unless, perhaps, we were called by
- * uid 0.
- *
- * XXX - what about when the watched area of the user's
- * address space is written into from within the kernel
- * ... wouldn't that still cause a breakpoint to be generated
- * from within kernel mode?
- */
-
- if (suser(td) != 0) {
- if (dbregs->dr[7] & 0x3) {
- /* dr0 is enabled */
- if (dbregs->dr[0] >= VM_MAXUSER_ADDRESS)
- return (EINVAL);
- }
-
- if (dbregs->dr[7] & (0x3<<2)) {
- /* dr1 is enabled */
- if (dbregs->dr[1] >= VM_MAXUSER_ADDRESS)
- return (EINVAL);
- }
-
- if (dbregs->dr[7] & (0x3<<4)) {
- /* dr2 is enabled */
- if (dbregs->dr[2] >= VM_MAXUSER_ADDRESS)
- return (EINVAL);
- }
-
- if (dbregs->dr[7] & (0x3<<6)) {
- /* dr3 is enabled */
- if (dbregs->dr[3] >= VM_MAXUSER_ADDRESS)
- return (EINVAL);
- }
- }
-
- pcb->pcb_dr0 = dbregs->dr[0];
- pcb->pcb_dr1 = dbregs->dr[1];
- pcb->pcb_dr2 = dbregs->dr[2];
- pcb->pcb_dr3 = dbregs->dr[3];
- pcb->pcb_dr6 = dbregs->dr[6];
- pcb->pcb_dr7 = dbregs->dr[7];
-
- pcb->pcb_flags |= PCB_DBREGS;
- }
-
- return (0);
-}
-
-/*
- * Return > 0 if a hardware breakpoint has been hit, and the
- * breakpoint was in user space. Return 0, otherwise.
- */
-int
-user_dbreg_trap(void)
-{
- u_int32_t dr7, dr6; /* debug registers dr6 and dr7 */
- u_int32_t bp; /* breakpoint bits extracted from dr6 */
- int nbp; /* number of breakpoints that triggered */
- caddr_t addr[4]; /* breakpoint addresses */
- int i;
-
- dr7 = rdr7();
- if ((dr7 & 0x000000ff) == 0) {
- /*
- * all GE and LE bits in the dr7 register are zero,
- * thus the trap couldn't have been caused by the
- * hardware debug registers
- */
- return 0;
- }
-
- nbp = 0;
- dr6 = rdr6();
- bp = dr6 & 0x0000000f;
-
- if (!bp) {
- /*
- * None of the breakpoint bits are set meaning this
- * trap was not caused by any of the debug registers
- */
- return 0;
- }
-
- /*
- * at least one of the breakpoints were hit, check to see
- * which ones and if any of them are user space addresses
- */
-
- if (bp & 0x01) {
- addr[nbp++] = (caddr_t)rdr0();
- }
- if (bp & 0x02) {
- addr[nbp++] = (caddr_t)rdr1();
- }
- if (bp & 0x04) {
- addr[nbp++] = (caddr_t)rdr2();
- }
- if (bp & 0x08) {
- addr[nbp++] = (caddr_t)rdr3();
- }
-
- for (i=0; i<nbp; i++) {
- if (addr[i] <
- (caddr_t)VM_MAXUSER_ADDRESS) {
- /*
- * addr[i] is in user space
- */
- return nbp;
- }
- }
-
- /*
- * None of the breakpoints are in user space.
- */
- return 0;
-}
-
-
-#ifndef DDB
-void
-Debugger(const char *msg)
-{
- printf("Debugger(\"%s\") called.\n", msg);
-}
-#endif /* no DDB */
-
-#ifdef DDB
-
-/*
- * Provide inb() and outb() as functions. They are normally only
- * available as macros calling inlined functions, thus cannot be
- * called inside DDB.
- *
- * The actual code is stolen from <machine/cpufunc.h>, and de-inlined.
- */
-
-#undef inb
-#undef outb
-
-/* silence compiler warnings */
-u_char inb(u_int);
-void outb(u_int, u_char);
-
-u_char
-inb(u_int port)
-{
- u_char data;
- /*
- * We use %%dx and not %1 here because i/o is done at %dx and not at
- * %edx, while gcc generates inferior code (movw instead of movl)
- * if we tell it to load (u_short) port.
- */
- __asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port));
- return (data);
-}
-
-void
-outb(u_int port, u_char data)
-{
- u_char al;
- /*
- * Use an unnecessary assignment to help gcc's register allocator.
- * This make a large difference for gcc-1.40 and a tiny difference
- * for gcc-2.6.0. For gcc-1.40, al had to be ``asm("ax")'' for
- * best results. gcc-2.6.0 can't handle this.
- */
- al = data;
- __asm __volatile("outb %0,%%dx" : : "a" (al), "d" (port));
-}
-
-#endif /* DDB */
diff --git a/sys/powerpc/aim/clock.c b/sys/powerpc/aim/clock.c
deleted file mode 100644
index 11ba5d08bf9b..000000000000
--- a/sys/powerpc/aim/clock.c
+++ /dev/null
@@ -1,332 +0,0 @@
-/*
- * Copyright (C) 1995, 1996 Wolfgang Solfrank.
- * Copyright (C) 1995, 1996 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $NetBSD: clock.c,v 1.9 2000/01/19 02:52:19 msaitoh Exp $
- */
-/*
- * Copyright (C) 2001 Benno Rice.
- * 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 Benno Rice ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/bus.h>
-#include <sys/timetc.h>
-#include <sys/interrupt.h>
-
-#include <dev/ofw/openfirm.h>
-
-#include <machine/clock.h>
-#include <machine/cpu.h>
-#include <machine/intr.h>
-
-#if 0 /* XXX */
-#include "adb.h"
-#else
-#define NADB 0
-#endif
-
-/*
- * Initially we assume a processor with a bus frequency of 12.5 MHz.
- */
-u_int tickspending;
-u_long ns_per_tick = 80;
-static u_long ticks_per_sec = 12500000;
-static long ticks_per_intr;
-static volatile u_long lasttb;
-
-#define SECDAY 86400
-#define DIFF19041970 2082844800
-
-#if NADB > 0
-extern int adb_read_date_time(int *);
-extern int adb_set_date_time(int);
-#endif
-
-static int clockinitted = 0;
-
-static timecounter_get_t decr_get_timecount;
-
-static struct timecounter decr_timecounter = {
- decr_get_timecount, /* get_timecount */
- 0, /* no poll_pps */
- ~0u, /* counter_mask */
- 0, /* frequency */
- "decrementer" /* name */
-};
-
-void
-inittodr(time_t base)
-{
- time_t deltat;
- u_int rtc_time;
- struct timespec ts;
- phandle_t phandle;
- ihandle_t ihandle;
- char rtcpath[128];
- u_int rtcsecs;
-
- /*
- * If we can't read from RTC, use the fs time.
- */
- phandle = OF_finddevice("rtc");
- if (phandle != -1) {
- OF_package_to_path(phandle, rtcpath, sizeof(rtcpath));
- ihandle = OF_open(rtcpath);
- if (ihandle != -1) {
- if (OF_call_method("read-rtc", ihandle,
- 0, 1, &rtcsecs))
- printf("RTC call method error\n");
- else {
- ts.tv_sec = rtcsecs - DIFF19041970;
- ts.tv_nsec = 0;
- tc_setclock(&ts);
- return;
- }
- }
- }
-
-#if NADB > 0
- if (adb_read_date_time(&rtc_time) < 0)
-#endif
- {
- ts.tv_sec = base;
- ts.tv_nsec = 0;
- tc_setclock(&ts);
- return;
- }
- clockinitted = 1;
- ts.tv_sec = rtc_time - DIFF19041970;
-
- deltat = ts.tv_sec - base;
- if (deltat < 0) {
- deltat = -deltat;
- }
- if (deltat < 2 * SECDAY) {
- tc_setclock(&ts);
- return;
- }
-
- printf("WARNING: clock %s %d days",
- ts.tv_sec < base ? "lost" : "gained", (int)(deltat / SECDAY));
-
- printf(" -- CHECK AND RESET THE DATE!\n");
-}
-
-/*
- * Similar to the above
- */
-void
-resettodr()
-{
-#if NADB > 0
- u_int rtc_time;
-
- if (clockinitted) {
- rtc_time = time.tv_sec + DIFF19041970;
- adb_set_date_time(rtc_time);
- }
-#endif
-}
-
-void
-decr_intr(struct clockframe *frame)
-{
- u_long tb;
- long tick;
- int nticks;
- register_t msr;
-
- /*
- * Check whether we are initialized.
- */
- if (!ticks_per_intr)
- return;
-
- /*
- * Based on the actual time delay since the last decrementer reload,
- * we arrange for earlier interrupt next time.
- */
- __asm ("mftb %0; mfdec %1" : "=r"(tb), "=r"(tick));
- for (nticks = 0; tick < 0; nticks++)
- tick += ticks_per_intr;
- mtdec(tick);
- /*
- * lasttb is used during microtime. Set it to the virtual
- * start of this tick interval.
- */
- lasttb = tb + tick - ticks_per_intr;
-
- nticks += tickspending;
- tickspending = 0;
-
- /*
- * Reenable interrupts
- */
-#if 0
- msr = mfmsr();
- mtmsr(msr | PSL_EE | PSL_RI);
-#endif
- /*
- * Do standard timer interrupt stuff.
- * Do softclock stuff only on the last iteration.
- */
-#if 0
- while (--nticks > 0) {
- hardclock(frame);
- }
-#endif
- hardclock(frame);
-}
-
-void
-cpu_initclocks(void)
-{
-
- return;
-}
-
-void
-decr_init(void)
-{
- int qhandle, phandle;
- char name[32];
- unsigned int msr;
-
- phandle = 0;
-
- /*
- * Get this info during autoconf? XXX
- */
- for (qhandle = OF_peer(0); qhandle; qhandle = phandle) {
- if (OF_getprop(qhandle, "device_type", name, sizeof name) >= 0
- && !strcmp(name, "cpu")
- && OF_getprop(qhandle, "timebase-frequency",
- &ticks_per_sec, sizeof ticks_per_sec) >= 0) {
- /*
- * Should check for correct CPU here? XXX
- */
- msr = mfmsr();
- mtmsr(msr & ~(PSL_EE|PSL_RI));
-
- decr_timecounter.tc_frequency = ticks_per_sec;
- tc_init(&decr_timecounter);
-
- ns_per_tick = 1000000000 / ticks_per_sec;
- ticks_per_intr = ticks_per_sec / hz;
- __asm __volatile ("mftb %0" : "=r"(lasttb));
- mtdec(ticks_per_intr);
-
- mtmsr(msr);
-
- break;
- }
- if ((phandle = OF_child(qhandle)))
- continue;
- while (qhandle) {
- if ((phandle = OF_peer(qhandle)))
- break;
- qhandle = OF_parent(qhandle);
- }
- }
- if (!phandle)
- panic("no cpu node");
-}
-
-static __inline u_quad_t
-mftb(void)
-{
- u_long scratch;
- u_quad_t tb;
-
- __asm ("1: mftbu %0; mftb %0+1; mftbu %1; cmpw 0,%0,%1; bne 1b"
- : "=r"(tb), "=r"(scratch));
- return tb;
-}
-
-static unsigned
-decr_get_timecount(struct timecounter *tc)
-{
- return mftb();
-}
-
-/*
- * Wait for about n microseconds (at least!).
- */
-void
-delay(int n)
-{
- u_quad_t tb, ttb;
-
- tb = mftb();
- ttb = tb + (n * 1000 + ns_per_tick - 1) / ns_per_tick;
- while (tb < ttb)
- tb = mftb();
-}
-
-/*
- * Nothing to do.
- */
-void
-cpu_startprofclock(void)
-{
-
- /* Do nothing */
-}
-
-void
-cpu_stopprofclock(void)
-{
-}
diff --git a/sys/powerpc/aim/copyinout.c b/sys/powerpc/aim/copyinout.c
deleted file mode 100644
index f916351161cf..000000000000
--- a/sys/powerpc/aim/copyinout.c
+++ /dev/null
@@ -1,320 +0,0 @@
-/*
- * Copyright (C) 2002 Benno Rice
- * 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 Benno Rice ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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) 1993 Wolfgang Solfrank.
- * Copyright (C) 1993 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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/proc.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-
-int setfault(faultbuf); /* defined in locore.S */
-
-/*
- * Makes sure that the right segment of userspace is mapped in.
- */
-static __inline void
-set_user_sr(register_t vsid)
-{
-
- isync();
- __asm __volatile ("mtsr %0,%1" :: "n"(USER_SR), "r"(vsid));
- isync();
-}
-
-int
-copyout(const void *kaddr, void *udaddr, size_t len)
-{
- struct thread *td;
- pmap_t pm;
- faultbuf env;
- const char *kp;
- char *up, *p;
- size_t l;
-
- td = PCPU_GET(curthread);
- pm = &td->td_proc->p_vmspace->vm_pmap;
-
- if (setfault(env)) {
- td->td_pcb->pcb_onfault = NULL;
- return (EFAULT);
- }
-
- kp = kaddr;
- up = udaddr;
-
- while (len > 0) {
- p = (char *)USER_ADDR + ((u_int)up & ~SEGMENT_MASK);
-
- l = ((char *)USER_ADDR + SEGMENT_LENGTH) - p;
- if (l > len)
- l = len;
-
- set_user_sr(pm->pm_sr[(u_int)up >> ADDR_SR_SHFT]);
-
- bcopy(kp, p, l);
-
- up += l;
- kp += l;
- len -= l;
- }
-
- td->td_pcb->pcb_onfault = NULL;
- return (0);
-}
-
-int
-copyin(const void *udaddr, void *kaddr, size_t len)
-{
- struct thread *td;
- pmap_t pm;
- faultbuf env;
- const char *up;
- char *kp, *p;
- size_t l;
-
- td = PCPU_GET(curthread);
- pm = &td->td_proc->p_vmspace->vm_pmap;
-
- if (setfault(env)) {
- td->td_pcb->pcb_onfault = NULL;
- return (EFAULT);
- }
-
- kp = kaddr;
- up = udaddr;
-
- while (len > 0) {
- p = (char *)USER_ADDR + ((u_int)up & ~SEGMENT_MASK);
-
- l = ((char *)USER_ADDR + SEGMENT_LENGTH) - p;
- if (l > len)
- l = len;
-
- set_user_sr(pm->pm_sr[(u_int)up >> ADDR_SR_SHFT]);
-
- bcopy(p, kp, l);
-
- up += l;
- kp += l;
- len -= l;
- }
-
- td->td_pcb->pcb_onfault = NULL;
- return (0);
-}
-
-int
-copyinstr(const void *udaddr, void *kaddr, size_t len, size_t *done)
-{
- struct thread *td;
- pmap_t pm;
- faultbuf env;
- const char *up;
- char *kp;
- size_t l;
- int rv, c;
-
- td = PCPU_GET(curthread);
- pm = &td->td_proc->p_vmspace->vm_pmap;
-
- if (setfault(env)) {
- td->td_pcb->pcb_onfault = NULL;
- return (EFAULT);
- }
-
- kp = kaddr;
- up = udaddr;
-
- rv = ENAMETOOLONG;
-
- for (l = 0; len-- > 0; l++) {
- if ((c = fubyte(up++)) < 0) {
- rv = EFAULT;
- break;
- }
-
- if (!(*kp++ = c)) {
- l++;
- rv = 0;
- break;
- }
- }
-
- if (done != NULL) {
- *done = l;
- }
-
- td->td_pcb->pcb_onfault = NULL;
- return (rv);
-}
-
-int
-subyte(void *addr, int byte)
-{
- struct thread *td;
- pmap_t pm;
- faultbuf env;
- char *p;
-
- td = PCPU_GET(curthread);
- pm = &td->td_proc->p_vmspace->vm_pmap;
- p = (char *)((u_int)USER_ADDR + ((u_int)addr & ~SEGMENT_MASK));
-
- if (setfault(env)) {
- td->td_pcb->pcb_onfault = NULL;
- return (-1);
- }
-
- set_user_sr(pm->pm_sr[(u_int)addr >> ADDR_SR_SHFT]);
-
- *p = (char)byte;
-
- td->td_pcb->pcb_onfault = NULL;
- return (0);
-}
-
-int
-suword(void *addr, long word)
-{
- struct thread *td;
- pmap_t pm;
- faultbuf env;
- long *p;
-
- td = PCPU_GET(curthread);
- pm = &td->td_proc->p_vmspace->vm_pmap;
- p = (long *)((u_int)USER_ADDR + ((u_int)addr & ~SEGMENT_MASK));
-
- if (setfault(env)) {
- td->td_pcb->pcb_onfault = NULL;
- return (-1);
- }
-
- set_user_sr(pm->pm_sr[(u_int)addr >> ADDR_SR_SHFT]);
-
- *p = word;
-
- td->td_pcb->pcb_onfault = NULL;
- return (0);
-}
-
-int
-suword32(void *addr, int32_t word)
-{
- return (suword(addr, (long)word));
-}
-
-
-int
-fubyte(const void *addr)
-{
- struct thread *td;
- pmap_t pm;
- faultbuf env;
- u_char *p;
- int val;
-
- td = PCPU_GET(curthread);
- pm = &td->td_proc->p_vmspace->vm_pmap;
- p = (u_char *)((u_int)USER_ADDR + ((u_int)addr & ~SEGMENT_MASK));
-
- if (setfault(env)) {
- td->td_pcb->pcb_onfault = NULL;
- return (-1);
- }
-
- set_user_sr(pm->pm_sr[(u_int)addr >> ADDR_SR_SHFT]);
-
- val = *p;
-
- td->td_pcb->pcb_onfault = NULL;
- return (val);
-}
-
-long
-fuword(const void *addr)
-{
- struct thread *td;
- pmap_t pm;
- faultbuf env;
- long *p, val;
-
- td = PCPU_GET(curthread);
- pm = &td->td_proc->p_vmspace->vm_pmap;
- p = (long *)((u_int)USER_ADDR + ((u_int)addr & ~SEGMENT_MASK));
-
- if (setfault(env)) {
- td->td_pcb->pcb_onfault = NULL;
- return (-1);
- }
-
- set_user_sr(pm->pm_sr[(u_int)addr >> ADDR_SR_SHFT]);
-
- val = *p;
-
- td->td_pcb->pcb_onfault = NULL;
- return (val);
-}
-
-int32_t
-fuword32(const void *addr)
-{
- return ((int32_t)fuword(addr));
-}
diff --git a/sys/powerpc/aim/interrupt.c b/sys/powerpc/aim/interrupt.c
deleted file mode 100644
index 90125657300a..000000000000
--- a/sys/powerpc/aim/interrupt.c
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2002 by Peter Grehan. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-/*
- * Interrupts are dispatched to here from locore asm
- */
-
-#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/interrupt.h>
-#include <sys/kernel.h>
-#include <sys/kthread.h>
-#include <sys/ktr.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/smp.h>
-#include <sys/unistd.h>
-#include <sys/vmmeter.h>
-
-#include <machine/cpu.h>
-#include <machine/db_machdep.h>
-#include <machine/fpu.h>
-#include <machine/frame.h>
-#include <machine/pcb.h>
-#include <machine/psl.h>
-#include <machine/trap.h>
-#include <machine/spr.h>
-#include <machine/sr.h>
-#include <machine/interruptvar.h>
-
-void powerpc_interrupt(struct trapframe *);
-
-/*
- * External interrupt install routines
- */
-static void (*powerpc_extintr_handler)(void);
-
-void
-ext_intr_install(void (*new_extint)(void))
-{
- powerpc_extintr_handler = new_extint;
-}
-
-extern void decr_intr(struct clockframe *);
-extern void trap(struct trapframe *);
-
-/*
- * A very short dispatch, to try and maximise assembler code use
- * between all exception types. Maybe 'true' interrupts should go
- * here, and the trap code can come in separately
- */
-void
-powerpc_interrupt(struct trapframe *framep)
-{
- struct thread *td;
- struct clockframe ckframe;
-
- td = curthread;
-
- switch (framep->exc) {
- case EXC_EXI:
- atomic_add_int(&td->td_intr_nesting_level, 1);
- (*powerpc_extintr_handler)();
- atomic_subtract_int(&td->td_intr_nesting_level, 1);
- break;
-
- case EXC_DECR:
- atomic_add_int(&td->td_intr_nesting_level, 1);
- ckframe.srr0 = framep->srr0;
- ckframe.srr1 = framep->srr1;
- decr_intr(&ckframe);
- atomic_subtract_int(&td->td_intr_nesting_level, 1);
- break;
-
- default:
- /*
- * Re-enable interrupts and call the generic trap code
- */
-#if 0
- printf("powerpc_interrupt: got trap\n");
- mtmsr(mfmsr() | PSL_EE);
- isync();
-#endif
- trap(framep);
- }
-}
diff --git a/sys/powerpc/aim/locore.S b/sys/powerpc/aim/locore.S
deleted file mode 100644
index 734d40911e05..000000000000
--- a/sys/powerpc/aim/locore.S
+++ /dev/null
@@ -1,207 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD: locore.S,v 1.24 2000/05/31 05:09:17 thorpej Exp $ */
-
-/*
- * Copyright (C) 2001 Benno Rice
- * 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 Benno Rice ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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) 1995, 1996 Wolfgang Solfrank.
- * Copyright (C) 1995, 1996 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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 "opt_ddb.h"
-#include "opt_ipkdb.h"
-#include "assym.s"
-
-#include <sys/syscall.h>
-
-#include <machine/trap.h>
-#include <machine/param.h>
-#include <machine/sr.h>
-#include <machine/spr.h>
-#include <machine/psl.h>
-#include <machine/asm.h>
-
-/*
- * Some instructions gas doesn't understand (yet?)
- */
-#define bdneq bdnzf 2,
-
-/*
- * Globals
- */
- .data
-GLOBAL(tmpstk)
- .space 8208
-GLOBAL(esym)
- .long 0 /* end of symbol table */
-
-GLOBAL(ofmsr)
- .long 0 /* msr used in Open Firmware */
-
-GLOBAL(powersave)
- .long 0
-
-#define INTSTK 8192 /* 8K interrupt stack */
-#define SPILLSTK 4096 /* 4K spill stack */
-
-/*
- * Dummy interrupt table to keep sysctl happy until
- * it's worked out what to do with naming
- */
-GLOBAL(intrnames)
- .asciz "dummy"
-GLOBAL(eintrnames)
- .align 4
-GLOBAL(intrcnt)
- .long 0
-GLOBAL(eintrcnt)
-
-/*
- * File-scope for locore.S
- */
-idle_u:
- .long 0 /* fake uarea during idle after exit */
-openfirmware_entry:
- .long 0 /* openfirmware entry point */
-srsave:
- .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-
-/*
- * This symbol is here for the benefit of kvm_mkdb, and is supposed to
- * mark the start of kernel text.
- */
- .text
- .globl kernel_text
-kernel_text:
-
-/*
- * Startup entry. Note, this must be the first thing in the text
- * segment!
- */
- .text
- .globl __start
-__start:
-#ifdef FIRMWORKSBUGS
- mfmsr 0
- andi. 0,0,PSL_IR|PSL_DR
- beq 1f
-
- bl ofwr_init
-1:
-#endif
- li 8,0
- li 9,0x100
- mtctr 9
-1:
- dcbf 0,8
- icbi 0,8
- addi 8,8,0x20
- bdnz 1b
- sync
- isync
-
- /* Save the argument pointer and length */
- mr 20,6
- mr 21,7
-
- lis 8,openfirmware_entry@ha
- stw 5,openfirmware_entry@l(8) /* save client interface handler */
- mr 3,5
-
- lis 1,tmpstk@ha
- addi 1,1,tmpstk@l
- addi 1,1,8192
-
- mfmsr 0
- lis 9,ofmsr@ha
- stw 0,ofmsr@l(9)
-
- bl OF_init
-
- lis 4,end@ha
- addi 4,4,end@l
- mr 5,4
-
- lis 3,kernel_text@ha
- addi 3,3,kernel_text@l
-
- /* Restore the argument pointer and length */
- mr 6,20
- mr 7,21
-
- bl powerpc_init
- bl mi_startup
- b OF_exit
-
-/*
- * int setfault()
- *
- * Similar to setjmp to setup for handling faults on accesses to user memory.
- * Any routine using this may only call bcopy, either the form below,
- * or the (currently used) C code optimized, so it doesn't use any non-volatile
- * registers.
- */
- .globl setfault
-setfault:
- mflr 0
- mfcr 12
- mfsprg 4,0
- lwz 4,PC_CURTHREAD(4)
- lwz 4,TD_PCB(4)
- stw 3,PCB_ONFAULT(4)
- stw 0,0(3)
- stw 1,4(3)
- stw 2,8(3)
- stmw 12,12(3)
- xor 3,3,3
- blr
-
-#include <powerpc/powerpc/trap_subr.S>
diff --git a/sys/powerpc/aim/machdep.c b/sys/powerpc/aim/machdep.c
deleted file mode 100644
index 62e46e91e2ef..000000000000
--- a/sys/powerpc/aim/machdep.c
+++ /dev/null
@@ -1,761 +0,0 @@
-/*
- * Copyright (C) 1995, 1996 Wolfgang Solfrank.
- * Copyright (C) 1995, 1996 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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 Benno Rice
- * 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 Benno Rice ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * $NetBSD: machdep.c,v 1.74.2.1 2000/11/01 16:13:48 tv Exp $
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_ddb.h"
-#include "opt_compat.h"
-#include "opt_msgbuf.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/eventhandler.h>
-#include <sys/imgact.h>
-#include <sys/sysproto.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/ktr.h>
-#include <sys/signalvar.h>
-#include <sys/kernel.h>
-#include <sys/proc.h>
-#include <sys/malloc.h>
-#include <sys/reboot.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/bus.h>
-#include <sys/mbuf.h>
-#include <sys/vmmeter.h>
-#include <sys/msgbuf.h>
-#include <sys/exec.h>
-#include <sys/sysctl.h>
-#include <sys/uio.h>
-#include <sys/linker.h>
-#include <sys/cons.h>
-#include <sys/ucontext.h>
-#include <sys/sysent.h>
-#include <net/netisr.h>
-#include <vm/vm.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_page.h>
-#include <vm/vm_map.h>
-#include <vm/vm_extern.h>
-#include <vm/vm_object.h>
-#include <vm/vm_pager.h>
-#include <sys/user.h>
-#include <sys/ptrace.h>
-#include <machine/bat.h>
-#include <machine/clock.h>
-#include <machine/md_var.h>
-#include <machine/metadata.h>
-#include <machine/reg.h>
-#include <machine/fpu.h>
-#include <machine/vmparam.h>
-#include <machine/elf.h>
-#include <machine/trap.h>
-#include <machine/powerpc.h>
-#include <dev/ofw/openfirm.h>
-#include <ddb/ddb.h>
-#include <sys/vnode.h>
-#include <machine/sigframe.h>
-
-int cold = 1;
-
-char pcpu0[PAGE_SIZE];
-char uarea0[UAREA_PAGES * PAGE_SIZE];
-struct trapframe frame0;
-
-vm_offset_t kstack0;
-vm_offset_t kstack0_phys;
-
-char machine[] = "powerpc";
-SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, "");
-
-static char model[128];
-SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, model, 0, "");
-
-static int cacheline_size = CACHELINESIZE;
-SYSCTL_INT(_machdep, CPU_CACHELINE, cacheline_size,
- CTLFLAG_RD, &cacheline_size, 0, "");
-
-char bootpath[256];
-
-#ifdef DDB
-/* start and end of kernel symbol table */
-void *ksym_start, *ksym_end;
-#endif /* DDB */
-
-static void cpu_startup(void *);
-SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL)
-
-void powerpc_init(u_int, u_int, u_int, void *);
-
-int save_ofw_mapping(void);
-int restore_ofw_mapping(void);
-
-void install_extint(void (*)(void));
-
-int setfault(faultbuf); /* defined in locore.S */
-
-long Maxmem = 0;
-
-struct pmap ofw_pmap;
-extern int ofmsr;
-
-struct bat battable[16];
-
-struct kva_md_info kmi;
-
-static void
-powerpc_ofw_shutdown(void *junk, int howto)
-{
- if (howto & RB_HALT) {
- OF_exit();
- }
-}
-
-static void
-cpu_startup(void *dummy)
-{
-
- /*
- * Initialise the decrementer-based clock.
- */
- decr_init();
-
- /*
- * Good {morning,afternoon,evening,night}.
- */
- cpu_setup(PCPU_GET(cpuid));
-
- /* startrtclock(); */
-#ifdef PERFMON
- perfmon_init();
-#endif
- printf("real memory = %ld (%ld MB)\n", ptoa(Maxmem),
- ptoa(Maxmem) / 1048576);
-
- /*
- * Display any holes after the first chunk of extended memory.
- */
- if (bootverbose) {
- int indx;
-
- printf("Physical memory chunk(s):\n");
- for (indx = 0; phys_avail[indx + 1] != 0; indx += 2) {
- int size1 = phys_avail[indx + 1] - phys_avail[indx];
-
- printf("0x%08x - 0x%08x, %d bytes (%d pages)\n",
- phys_avail[indx], phys_avail[indx + 1] - 1, size1,
- size1 / PAGE_SIZE);
- }
- }
-
- vm_ksubmap_init(&kmi);
-
- printf("avail memory = %ld (%ld MB)\n", ptoa(cnt.v_free_count),
- ptoa(cnt.v_free_count) / 1048576);
-
- /*
- * Set up buffers, so they can be used to read disk labels.
- */
- bufinit();
- vm_pager_bufferinit();
-
- EVENTHANDLER_REGISTER(shutdown_final, powerpc_ofw_shutdown, 0,
- SHUTDOWN_PRI_LAST);
-
-#ifdef SMP
- /*
- * OK, enough kmem_alloc/malloc state should be up, lets get on with it!
- */
- mp_start(); /* fire up the secondaries */
- mp_announce();
-#endif /* SMP */
-}
-
-extern char kernel_text[], _end[];
-
-extern void *trapcode, *trapsize;
-extern void *alitrap, *alisize;
-extern void *dsitrap, *dsisize;
-extern void *isitrap, *isisize;
-extern void *decrint, *decrsize;
-extern void *tlbimiss, *tlbimsize;
-extern void *tlbdlmiss, *tlbdlmsize;
-extern void *tlbdsmiss, *tlbdsmsize;
-extern void *extint, *extsize;
-
-#if 0 /* XXX: interrupt handler. We'll get to this later */
-extern void ext_intr(void);
-#endif
-
-#ifdef DDB
-extern ddblow, ddbsize;
-#endif
-#ifdef IPKDB
-extern ipkdblow, ipkdbsize;
-#endif
-
-void
-powerpc_init(u_int startkernel, u_int endkernel, u_int basekernel, void *mdp)
-{
- struct pcpu *pc;
- vm_offset_t end, off;
- void *kmdp;
-
- end = 0;
- kmdp = NULL;
-
- /*
- * Parse metadata if present and fetch parameters. Must be done
- * before console is inited so cninit gets the right value of
- * boothowto.
- */
- if (mdp != NULL) {
- preload_metadata = mdp;
- kmdp = preload_search_by_type("elf kernel");
- if (kmdp != NULL) {
- boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
- kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *);
- end = MD_FETCH(kmdp, MODINFOMD_KERNEND, vm_offset_t);
- }
- }
-
- /*
- * Initialize the console before printing anything.
- */
- cninit();
-
- /*
- * Complain if there is no metadata.
- */
- if (mdp == NULL || kmdp == NULL) {
- printf("powerpc_init: no loader metadata.\n");
- }
-
-#ifdef DDB
- kdb_init();
-#endif
- /*
- * XXX: Initialize the interrupt tables.
- */
- bcopy(&trapcode, (void *)EXC_MCHK, (size_t)&trapsize);
- bcopy(&dsitrap, (void *)EXC_DSI, (size_t)&dsisize);
- bcopy(&isitrap, (void *)EXC_ISI, (size_t)&isisize);
- bcopy(&trapcode, (void *)EXC_EXI, (size_t)&trapsize);
- bcopy(&trapcode, (void *)EXC_ALI, (size_t)&trapsize);
- bcopy(&trapcode, (void *)EXC_PGM, (size_t)&trapsize);
- bcopy(&trapcode, (void *)EXC_FPU, (size_t)&trapsize);
- bcopy(&trapcode, (void *)EXC_DECR, (size_t)&trapsize);
- bcopy(&trapcode, (void *)EXC_SC, (size_t)&trapsize);
- bcopy(&trapcode, (void *)EXC_TRC, (size_t)&trapsize);
- __syncicache(EXC_RSVD, EXC_LAST - EXC_RSVD);
-
- /*
- * Start initializing proc0 and thread0.
- */
- proc_linkup(&proc0, &ksegrp0, &kse0, &thread0);
- proc0.p_uarea = (struct user *)uarea0;
- proc0.p_stats = &proc0.p_uarea->u_stats;
- thread0.td_frame = &frame0;
-
- /*
- * Set up per-cpu data.
- */
- pc = (struct pcpu *)(pcpu0 + PAGE_SIZE) - 1;
- pcpu_init(pc, 0, sizeof(struct pcpu));
- pc->pc_curthread = &thread0;
- pc->pc_curpcb = thread0.td_pcb;
- pc->pc_cpuid = 0;
- /* pc->pc_mid = mid; */
-
- __asm __volatile("mtsprg 0, %0" :: "r"(pc));
-
- mutex_init();
-
- /*
- * Make sure translation has been enabled
- */
- mtmsr(mfmsr() | PSL_IR|PSL_DR|PSL_ME|PSL_RI);
-
- /*
- * Initialise virtual memory.
- */
- pmap_bootstrap(startkernel, endkernel);
-
- /*
- * Initialize tunables.
- */
- init_param1();
- init_param2(physmem);
-
- /*
- * Finish setting up thread0.
- */
- thread0.td_kstack = kstack0;
- thread0.td_pcb = (struct pcb *)
- (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
-
- /*
- * Map and initialise the message buffer.
- */
- for (off = 0; off < round_page(MSGBUF_SIZE); off += PAGE_SIZE)
- pmap_kenter((vm_offset_t)msgbufp + off, msgbuf_phys + off);
- msgbufinit(msgbufp, MSGBUF_SIZE);
-}
-
-void
-bzero(void *buf, size_t len)
-{
- caddr_t p;
-
- p = buf;
-
- while (((vm_offset_t) p & (sizeof(u_long) - 1)) && len) {
- *p++ = 0;
- len--;
- }
-
- while (len >= sizeof(u_long) * 8) {
- *(u_long*) p = 0;
- *((u_long*) p + 1) = 0;
- *((u_long*) p + 2) = 0;
- *((u_long*) p + 3) = 0;
- len -= sizeof(u_long) * 8;
- *((u_long*) p + 4) = 0;
- *((u_long*) p + 5) = 0;
- *((u_long*) p + 6) = 0;
- *((u_long*) p + 7) = 0;
- p += sizeof(u_long) * 8;
- }
-
- while (len >= sizeof(u_long)) {
- *(u_long*) p = 0;
- len -= sizeof(u_long);
- p += sizeof(u_long);
- }
-
- while (len) {
- *p++ = 0;
- len--;
- }
-}
-
-void
-sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
-{
- struct trapframe *tf;
- struct sigframe *sfp;
- struct sigacts *psp;
- struct sigframe sf;
- struct thread *td;
- struct proc *p;
- int oonstack, rndfsize;
-
- td = curthread;
- p = td->td_proc;
- PROC_LOCK_ASSERT(p, MA_OWNED);
- psp = p->p_sigacts;
- mtx_assert(&psp->ps_mtx, MA_OWNED);
- tf = td->td_frame;
- oonstack = sigonstack(tf->fixreg[1]);
-
- rndfsize = ((sizeof(sf) + 15) / 16) * 16;
-
- CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm,
- catcher, sig);
-
- /*
- * Save user context
- */
- memset(&sf, 0, sizeof(sf));
- sf.sf_uc.uc_sigmask = *mask;
- sf.sf_uc.uc_stack = p->p_sigstk;
- sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
- ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
-
- sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
- memcpy(&sf.sf_uc.uc_mcontext.mc_frame, tf, sizeof(struct trapframe));
-
- /*
- * Allocate and validate space for the signal handler context.
- */
- if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
- SIGISMEMBER(psp->ps_sigonstack, sig)) {
- sfp = (struct sigframe *)((caddr_t)p->p_sigstk.ss_sp +
- p->p_sigstk.ss_size - rndfsize);
- } else {
- sfp = (struct sigframe *)(tf->fixreg[1] - rndfsize);
- }
-
- /*
- * Translate the signal if appropriate (Linux emu ?)
- */
- if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
- sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
-
- /*
- * Save the floating-point state, if necessary, then copy it.
- */
- /* XXX */
-
- /*
- * Set up the registers to return to sigcode.
- *
- * r1/sp - sigframe ptr
- * lr - sig function, dispatched to by blrl in trampoline
- * r3 - sig number
- * r4 - SIGINFO ? &siginfo : exception code
- * r5 - user context
- * srr0 - trampoline function addr
- */
- tf->lr = (register_t)catcher;
- tf->fixreg[1] = (register_t)sfp;
- tf->fixreg[FIRSTARG] = sig;
- tf->fixreg[FIRSTARG+2] = (register_t)&sfp->sf_uc;
- if (SIGISMEMBER(psp->ps_siginfo, sig)) {
- /*
- * Signal handler installed with SA_SIGINFO.
- */
- tf->fixreg[FIRSTARG+1] = (register_t)&sfp->sf_si;
-
- /*
- * Fill siginfo structure.
- */
- sf.sf_si.si_signo = sig;
- sf.sf_si.si_code = code;
- sf.sf_si.si_addr = (void *)tf->srr0;
- } else {
- /* Old FreeBSD-style arguments. */
- tf->fixreg[FIRSTARG+1] = code;
- }
- mtx_unlock(&psp->ps_mtx);
- PROC_UNLOCK(p);
-
- tf->srr0 = (register_t)(PS_STRINGS - *(p->p_sysent->sv_szsigcode));
-
- /*
- * copy the frame out to userland.
- */
- if (copyout((caddr_t)&sf, (caddr_t)sfp, sizeof(sf)) != 0) {
- /*
- * Process has trashed its stack. Kill it.
- */
- CTR2(KTR_SIG, "sendsig: sigexit td=%p sfp=%p", td, sfp);
- PROC_LOCK(p);
- sigexit(td, SIGILL);
- }
-
- CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td,
- tf->srr0, tf->fixreg[1]);
-
- PROC_LOCK(p);
- mtx_lock(&psp->ps_mtx);
-}
-
-int
-sigreturn(struct thread *td, struct sigreturn_args *uap)
-{
- struct trapframe *tf;
- struct proc *p;
- ucontext_t uc;
-
- CTR2(KTR_SIG, "sigreturn: td=%p ucp=%p", td, uap->sigcntxp);
-
- if (copyin(uap->sigcntxp, &uc, sizeof(uc)) != 0) {
- CTR1(KTR_SIG, "sigreturn: efault td=%p", td);
- return (EFAULT);
- }
-
- /*
- * Don't let the user set privileged MSR bits
- */
- tf = td->td_frame;
- if ((uc.uc_mcontext.mc_frame.srr1 & PSL_USERSTATIC) !=
- (tf->srr1 & PSL_USERSTATIC)) {
- return (EINVAL);
- }
-
- /*
- * Restore the user-supplied context
- */
- memcpy(tf, &uc.uc_mcontext.mc_frame, sizeof(struct trapframe));
-
- p = td->td_proc;
- PROC_LOCK(p);
- td->td_sigmask = uc.uc_sigmask;
- SIG_CANTMASK(td->td_sigmask);
- signotify(td);
- PROC_UNLOCK(p);
-
- /*
- * Restore FP state
- */
- /* XXX */
-
- CTR3(KTR_SIG, "sigreturn: return td=%p pc=%#x sp=%#x",
- td, tf->srr0, tf->fixreg[1]);
-
- return (EJUSTRETURN);
-}
-
-#ifdef COMPAT_FREEBSD4
-int
-freebsd4_sigreturn(struct thread *td, struct freebsd4_sigreturn_args *uap)
-{
-
- return sigreturn(td, (struct sigreturn_args *)uap);
-}
-#endif
-
-int
-get_mcontext(struct thread *td, mcontext_t *mcp, int clear_ret)
-{
-
- return (ENOSYS);
-}
-
-int
-set_mcontext(struct thread *td, const mcontext_t *mcp)
-{
-
- return (ENOSYS);
-}
-
-void
-cpu_boot(int howto)
-{
-}
-
-/*
- * Shutdown the CPU as much as possible.
- */
-void
-cpu_halt(void)
-{
-
- OF_exit();
-}
-
-/*
- * Set set up registers on exec.
- */
-void
-exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
-{
- struct trapframe *tf;
- struct ps_strings arginfo;
-
- tf = trapframe(td);
- bzero(tf, sizeof *tf);
- tf->fixreg[1] = -roundup(-stack + 8, 16);
-
- /*
- * XXX Machine-independent code has already copied arguments and
- * XXX environment to userland. Get them back here.
- */
- (void)copyin((char *)PS_STRINGS, &arginfo, sizeof(arginfo));
-
- /*
- * Set up arguments for _start():
- * _start(argc, argv, envp, obj, cleanup, ps_strings);
- *
- * Notes:
- * - obj and cleanup are the auxilliary and termination
- * vectors. They are fixed up by ld.elf_so.
- * - ps_strings is a NetBSD extention, and will be
- * ignored by executables which are strictly
- * compliant with the SVR4 ABI.
- *
- * XXX We have to set both regs and retval here due to different
- * XXX calling convention in trap.c and init_main.c.
- */
- /*
- * XXX PG: these get overwritten in the syscall return code.
- * execve() should return EJUSTRETURN, like it does on NetBSD.
- * Emulate by setting the syscall return value cells. The
- * registers still have to be set for init's fork trampoline.
- */
- td->td_retval[0] = arginfo.ps_nargvstr;
- td->td_retval[1] = (register_t)arginfo.ps_argvstr;
- tf->fixreg[3] = arginfo.ps_nargvstr;
- tf->fixreg[4] = (register_t)arginfo.ps_argvstr;
- tf->fixreg[5] = (register_t)arginfo.ps_envstr;
- tf->fixreg[6] = 0; /* auxillary vector */
- tf->fixreg[7] = 0; /* termination vector */
- tf->fixreg[8] = (register_t)PS_STRINGS; /* NetBSD extension */
-
- tf->srr0 = entry;
- tf->srr1 = PSL_MBO | PSL_USERSET | PSL_FE_DFLT;
- td->td_pcb->pcb_flags = 0;
-}
-
-#if !defined(DDB)
-void
-Debugger(const char *msg)
-{
-
- printf("Debugger(\"%s\") called.\n", msg);
-}
-#endif /* !defined(DDB) */
-
-/* XXX: dummy {fill,set}_[fp]regs */
-int
-fill_regs(struct thread *td, struct reg *regs)
-{
-
- return (ENOSYS);
-}
-
-int
-fill_dbregs(struct thread *td, struct dbreg *dbregs)
-{
-
- return (ENOSYS);
-}
-
-int
-fill_fpregs(struct thread *td, struct fpreg *fpregs)
-{
-
- return (ENOSYS);
-}
-
-int
-set_regs(struct thread *td, struct reg *regs)
-{
-
- return (ENOSYS);
-}
-
-int
-set_dbregs(struct thread *td, struct dbreg *dbregs)
-{
-
- return (ENOSYS);
-}
-
-int
-set_fpregs(struct thread *td, struct fpreg *fpregs)
-{
-
- return (ENOSYS);
-}
-
-int
-ptrace_set_pc(struct thread *td, unsigned long addr)
-{
-
- /* XXX: coming soon... */
- return (ENOSYS);
-}
-
-int
-ptrace_single_step(struct thread *td)
-{
-
- /* XXX: coming soon... */
- return (ENOSYS);
-}
-
-/*
- * Initialise a struct pcpu.
- */
-void
-cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz)
-{
-
- pcpu->pc_current_asngen = 1;
-}
-
-/*
- * kcopy(const void *src, void *dst, size_t len);
- *
- * Copy len bytes from src to dst, aborting if we encounter a fatal
- * page fault.
- *
- * kcopy() _must_ save and restore the old fault handler since it is
- * called by uiomove(), which may be in the path of servicing a non-fatal
- * page fault.
- */
-int
-kcopy(const void *src, void *dst, size_t len)
-{
- struct thread *td;
- faultbuf env, *oldfault;
- int rv;
-
- td = PCPU_GET(curthread);
- oldfault = td->td_pcb->pcb_onfault;
- if ((rv = setfault(env)) != 0) {
- td->td_pcb->pcb_onfault = oldfault;
- return rv;
- }
-
- memcpy(dst, src, len);
-
- td->td_pcb->pcb_onfault = oldfault;
- return (0);
-}
-
-
-intptr_t
-casuptr(intptr_t *p, intptr_t old, intptr_t new)
-{
- return (-1);
-}
-
diff --git a/sys/powerpc/aim/mmu_oea.c b/sys/powerpc/aim/mmu_oea.c
deleted file mode 100644
index 00528814ac51..000000000000
--- a/sys/powerpc/aim/mmu_oea.c
+++ /dev/null
@@ -1,2512 +0,0 @@
-/*
- * Copyright (c) 2001 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Matt Thomas <matt@3am-software.com> of Allegro Networks, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-/*
- * Copyright (C) 1995, 1996 Wolfgang Solfrank.
- * Copyright (C) 1995, 1996 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $NetBSD: pmap.c,v 1.28 2000/03/26 20:42:36 kleink Exp $
- */
-/*
- * Copyright (C) 2001 Benno Rice.
- * 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 Benno Rice ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$");
-
-/*
- * Manages physical address maps.
- *
- * In addition to hardware address maps, this module is called upon to
- * provide software-use-only maps which may or may not be stored in the
- * same form as hardware maps. These pseudo-maps are used to store
- * intermediate results from copy operations to and from address spaces.
- *
- * Since the information managed by this module is also stored by the
- * logical address mapping module, this module may throw away valid virtual
- * to physical mappings at almost any time. However, invalidations of
- * mappings must be done as requested.
- *
- * In order to cope with hardware architectures which make virtual to
- * physical map invalidates expensive, this module may delay invalidate
- * reduced protection operations until such time as they are actually
- * necessary. This module is given full information as to which processors
- * are currently using which maps, and to when physical maps must be made
- * correct.
- */
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/ktr.h>
-#include <sys/lock.h>
-#include <sys/msgbuf.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/sysctl.h>
-#include <sys/systm.h>
-#include <sys/vmmeter.h>
-
-#include <dev/ofw/openfirm.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_page.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-#include <vm/vm_extern.h>
-#include <vm/vm_pageout.h>
-#include <vm/vm_pager.h>
-#include <vm/uma.h>
-
-#include <machine/powerpc.h>
-#include <machine/bat.h>
-#include <machine/frame.h>
-#include <machine/md_var.h>
-#include <machine/psl.h>
-#include <machine/pte.h>
-#include <machine/sr.h>
-
-#define PMAP_DEBUG
-
-#define TODO panic("%s: not implemented", __func__);
-
-#define PMAP_LOCK(pm)
-#define PMAP_UNLOCK(pm)
-
-#define TLBIE(va) __asm __volatile("tlbie %0" :: "r"(va))
-#define TLBSYNC() __asm __volatile("tlbsync");
-#define SYNC() __asm __volatile("sync");
-#define EIEIO() __asm __volatile("eieio");
-
-#define VSID_MAKE(sr, hash) ((sr) | (((hash) & 0xfffff) << 4))
-#define VSID_TO_SR(vsid) ((vsid) & 0xf)
-#define VSID_TO_HASH(vsid) (((vsid) >> 4) & 0xfffff)
-
-#define PVO_PTEGIDX_MASK 0x0007 /* which PTEG slot */
-#define PVO_PTEGIDX_VALID 0x0008 /* slot is valid */
-#define PVO_WIRED 0x0010 /* PVO entry is wired */
-#define PVO_MANAGED 0x0020 /* PVO entry is managed */
-#define PVO_EXECUTABLE 0x0040 /* PVO entry is executable */
-#define PVO_BOOTSTRAP 0x0080 /* PVO entry allocated during
- bootstrap */
-#define PVO_VADDR(pvo) ((pvo)->pvo_vaddr & ~ADDR_POFF)
-#define PVO_ISEXECUTABLE(pvo) ((pvo)->pvo_vaddr & PVO_EXECUTABLE)
-#define PVO_PTEGIDX_GET(pvo) ((pvo)->pvo_vaddr & PVO_PTEGIDX_MASK)
-#define PVO_PTEGIDX_ISSET(pvo) ((pvo)->pvo_vaddr & PVO_PTEGIDX_VALID)
-#define PVO_PTEGIDX_CLR(pvo) \
- ((void)((pvo)->pvo_vaddr &= ~(PVO_PTEGIDX_VALID|PVO_PTEGIDX_MASK)))
-#define PVO_PTEGIDX_SET(pvo, i) \
- ((void)((pvo)->pvo_vaddr |= (i)|PVO_PTEGIDX_VALID))
-
-#define PMAP_PVO_CHECK(pvo)
-
-struct ofw_map {
- vm_offset_t om_va;
- vm_size_t om_len;
- vm_offset_t om_pa;
- u_int om_mode;
-};
-
-int pmap_bootstrapped = 0;
-
-/*
- * Virtual and physical address of message buffer.
- */
-struct msgbuf *msgbufp;
-vm_offset_t msgbuf_phys;
-
-/*
- * Physical addresses of first and last available physical page.
- */
-vm_offset_t avail_start;
-vm_offset_t avail_end;
-
-int pmap_pagedaemon_waken;
-
-/*
- * Map of physical memory regions.
- */
-vm_offset_t phys_avail[128];
-u_int phys_avail_count;
-static struct mem_region *regions;
-static struct mem_region *pregions;
-int regions_sz, pregions_sz;
-static struct ofw_map *translations;
-
-/*
- * First and last available kernel virtual addresses.
- */
-vm_offset_t virtual_avail;
-vm_offset_t virtual_end;
-vm_offset_t kernel_vm_end;
-
-/*
- * Kernel pmap.
- */
-struct pmap kernel_pmap_store;
-extern struct pmap ofw_pmap;
-
-/*
- * PTEG data.
- */
-static struct pteg *pmap_pteg_table;
-u_int pmap_pteg_count;
-u_int pmap_pteg_mask;
-
-/*
- * PVO data.
- */
-struct pvo_head *pmap_pvo_table; /* pvo entries by pteg index */
-struct pvo_head pmap_pvo_kunmanaged =
- LIST_HEAD_INITIALIZER(pmap_pvo_kunmanaged); /* list of unmanaged pages */
-struct pvo_head pmap_pvo_unmanaged =
- LIST_HEAD_INITIALIZER(pmap_pvo_unmanaged); /* list of unmanaged pages */
-
-uma_zone_t pmap_upvo_zone; /* zone for pvo entries for unmanaged pages */
-uma_zone_t pmap_mpvo_zone; /* zone for pvo entries for managed pages */
-struct vm_object pmap_upvo_zone_obj;
-struct vm_object pmap_mpvo_zone_obj;
-static vm_object_t pmap_pvo_obj;
-static u_int pmap_pvo_count;
-
-#define BPVO_POOL_SIZE 32768
-static struct pvo_entry *pmap_bpvo_pool;
-static int pmap_bpvo_pool_index = 0;
-
-#define VSID_NBPW (sizeof(u_int32_t) * 8)
-static u_int pmap_vsid_bitmap[NPMAPS / VSID_NBPW];
-
-static boolean_t pmap_initialized = FALSE;
-
-/*
- * Statistics.
- */
-u_int pmap_pte_valid = 0;
-u_int pmap_pte_overflow = 0;
-u_int pmap_pte_replacements = 0;
-u_int pmap_pvo_entries = 0;
-u_int pmap_pvo_enter_calls = 0;
-u_int pmap_pvo_remove_calls = 0;
-u_int pmap_pte_spills = 0;
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pte_valid, CTLFLAG_RD, &pmap_pte_valid,
- 0, "");
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pte_overflow, CTLFLAG_RD,
- &pmap_pte_overflow, 0, "");
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pte_replacements, CTLFLAG_RD,
- &pmap_pte_replacements, 0, "");
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pvo_entries, CTLFLAG_RD, &pmap_pvo_entries,
- 0, "");
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pvo_enter_calls, CTLFLAG_RD,
- &pmap_pvo_enter_calls, 0, "");
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pvo_remove_calls, CTLFLAG_RD,
- &pmap_pvo_remove_calls, 0, "");
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pte_spills, CTLFLAG_RD,
- &pmap_pte_spills, 0, "");
-
-struct pvo_entry *pmap_pvo_zeropage;
-
-vm_offset_t pmap_rkva_start = VM_MIN_KERNEL_ADDRESS;
-u_int pmap_rkva_count = 4;
-
-/*
- * Allocate physical memory for use in pmap_bootstrap.
- */
-static vm_offset_t pmap_bootstrap_alloc(vm_size_t, u_int);
-
-/*
- * PTE calls.
- */
-static int pmap_pte_insert(u_int, struct pte *);
-
-/*
- * PVO calls.
- */
-static int pmap_pvo_enter(pmap_t, uma_zone_t, struct pvo_head *,
- vm_offset_t, vm_offset_t, u_int, int);
-static void pmap_pvo_remove(struct pvo_entry *, int);
-static struct pvo_entry *pmap_pvo_find_va(pmap_t, vm_offset_t, int *);
-static struct pte *pmap_pvo_to_pte(const struct pvo_entry *, int);
-
-/*
- * Utility routines.
- */
-static void * pmap_pvo_allocf(uma_zone_t, int, u_int8_t *, int);
-static struct pvo_entry *pmap_rkva_alloc(void);
-static void pmap_pa_map(struct pvo_entry *, vm_offset_t,
- struct pte *, int *);
-static void pmap_pa_unmap(struct pvo_entry *, struct pte *, int *);
-static void pmap_syncicache(vm_offset_t, vm_size_t);
-static boolean_t pmap_query_bit(vm_page_t, int);
-static u_int pmap_clear_bit(vm_page_t, int, int *);
-static void tlbia(void);
-
-static __inline int
-va_to_sr(u_int *sr, vm_offset_t va)
-{
- return (sr[(uintptr_t)va >> ADDR_SR_SHFT]);
-}
-
-static __inline u_int
-va_to_pteg(u_int sr, vm_offset_t addr)
-{
- u_int hash;
-
- hash = (sr & SR_VSID_MASK) ^ (((u_int)addr & ADDR_PIDX) >>
- ADDR_PIDX_SHFT);
- return (hash & pmap_pteg_mask);
-}
-
-static __inline struct pvo_head *
-pa_to_pvoh(vm_offset_t pa, vm_page_t *pg_p)
-{
- struct vm_page *pg;
-
- pg = PHYS_TO_VM_PAGE(pa);
-
- if (pg_p != NULL)
- *pg_p = pg;
-
- if (pg == NULL)
- return (&pmap_pvo_unmanaged);
-
- return (&pg->md.mdpg_pvoh);
-}
-
-static __inline struct pvo_head *
-vm_page_to_pvoh(vm_page_t m)
-{
-
- return (&m->md.mdpg_pvoh);
-}
-
-static __inline void
-pmap_attr_clear(vm_page_t m, int ptebit)
-{
-
- m->md.mdpg_attrs &= ~ptebit;
-}
-
-static __inline int
-pmap_attr_fetch(vm_page_t m)
-{
-
- return (m->md.mdpg_attrs);
-}
-
-static __inline void
-pmap_attr_save(vm_page_t m, int ptebit)
-{
-
- m->md.mdpg_attrs |= ptebit;
-}
-
-static __inline int
-pmap_pte_compare(const struct pte *pt, const struct pte *pvo_pt)
-{
- if (pt->pte_hi == pvo_pt->pte_hi)
- return (1);
-
- return (0);
-}
-
-static __inline int
-pmap_pte_match(struct pte *pt, u_int sr, vm_offset_t va, int which)
-{
- return (pt->pte_hi & ~PTE_VALID) ==
- (((sr & SR_VSID_MASK) << PTE_VSID_SHFT) |
- ((va >> ADDR_API_SHFT) & PTE_API) | which);
-}
-
-static __inline void
-pmap_pte_create(struct pte *pt, u_int sr, vm_offset_t va, u_int pte_lo)
-{
- /*
- * Construct a PTE. Default to IMB initially. Valid bit only gets
- * set when the real pte is set in memory.
- *
- * Note: Don't set the valid bit for correct operation of tlb update.
- */
- pt->pte_hi = ((sr & SR_VSID_MASK) << PTE_VSID_SHFT) |
- (((va & ADDR_PIDX) >> ADDR_API_SHFT) & PTE_API);
- pt->pte_lo = pte_lo;
-}
-
-static __inline void
-pmap_pte_synch(struct pte *pt, struct pte *pvo_pt)
-{
-
- pvo_pt->pte_lo |= pt->pte_lo & (PTE_REF | PTE_CHG);
-}
-
-static __inline void
-pmap_pte_clear(struct pte *pt, vm_offset_t va, int ptebit)
-{
-
- /*
- * As shown in Section 7.6.3.2.3
- */
- pt->pte_lo &= ~ptebit;
- TLBIE(va);
- EIEIO();
- TLBSYNC();
- SYNC();
-}
-
-static __inline void
-pmap_pte_set(struct pte *pt, struct pte *pvo_pt)
-{
-
- pvo_pt->pte_hi |= PTE_VALID;
-
- /*
- * Update the PTE as defined in section 7.6.3.1.
- * Note that the REF/CHG bits are from pvo_pt and thus should havce
- * been saved so this routine can restore them (if desired).
- */
- pt->pte_lo = pvo_pt->pte_lo;
- EIEIO();
- pt->pte_hi = pvo_pt->pte_hi;
- SYNC();
- pmap_pte_valid++;
-}
-
-static __inline void
-pmap_pte_unset(struct pte *pt, struct pte *pvo_pt, vm_offset_t va)
-{
-
- pvo_pt->pte_hi &= ~PTE_VALID;
-
- /*
- * Force the reg & chg bits back into the PTEs.
- */
- SYNC();
-
- /*
- * Invalidate the pte.
- */
- pt->pte_hi &= ~PTE_VALID;
-
- SYNC();
- TLBIE(va);
- EIEIO();
- TLBSYNC();
- SYNC();
-
- /*
- * Save the reg & chg bits.
- */
- pmap_pte_synch(pt, pvo_pt);
- pmap_pte_valid--;
-}
-
-static __inline void
-pmap_pte_change(struct pte *pt, struct pte *pvo_pt, vm_offset_t va)
-{
-
- /*
- * Invalidate the PTE
- */
- pmap_pte_unset(pt, pvo_pt, va);
- pmap_pte_set(pt, pvo_pt);
-}
-
-/*
- * Quick sort callout for comparing memory regions.
- */
-static int mr_cmp(const void *a, const void *b);
-static int om_cmp(const void *a, const void *b);
-
-static int
-mr_cmp(const void *a, const void *b)
-{
- const struct mem_region *regiona;
- const struct mem_region *regionb;
-
- regiona = a;
- regionb = b;
- if (regiona->mr_start < regionb->mr_start)
- return (-1);
- else if (regiona->mr_start > regionb->mr_start)
- return (1);
- else
- return (0);
-}
-
-static int
-om_cmp(const void *a, const void *b)
-{
- const struct ofw_map *mapa;
- const struct ofw_map *mapb;
-
- mapa = a;
- mapb = b;
- if (mapa->om_pa < mapb->om_pa)
- return (-1);
- else if (mapa->om_pa > mapb->om_pa)
- return (1);
- else
- return (0);
-}
-
-void
-pmap_bootstrap(vm_offset_t kernelstart, vm_offset_t kernelend)
-{
- ihandle_t mmui;
- phandle_t chosen, mmu;
- int sz;
- int i, j;
- int ofw_mappings;
- vm_size_t size, physsz;
- vm_offset_t pa, va, off;
- u_int batl, batu;
-
- /*
- * Set up BAT0 to map the lowest 256 MB area
- */
- battable[0x0].batl = BATL(0x00000000, BAT_M, BAT_PP_RW);
- battable[0x0].batu = BATU(0x00000000, BAT_BL_256M, BAT_Vs);
-
- /*
- * Map PCI memory space.
- */
- battable[0x8].batl = BATL(0x80000000, BAT_I|BAT_G, BAT_PP_RW);
- battable[0x8].batu = BATU(0x80000000, BAT_BL_256M, BAT_Vs);
-
- battable[0x9].batl = BATL(0x90000000, BAT_I|BAT_G, BAT_PP_RW);
- battable[0x9].batu = BATU(0x90000000, BAT_BL_256M, BAT_Vs);
-
- battable[0xa].batl = BATL(0xa0000000, BAT_I|BAT_G, BAT_PP_RW);
- battable[0xa].batu = BATU(0xa0000000, BAT_BL_256M, BAT_Vs);
-
- battable[0xb].batl = BATL(0xb0000000, BAT_I|BAT_G, BAT_PP_RW);
- battable[0xb].batu = BATU(0xb0000000, BAT_BL_256M, BAT_Vs);
-
- /*
- * Map obio devices.
- */
- battable[0xf].batl = BATL(0xf0000000, BAT_I|BAT_G, BAT_PP_RW);
- battable[0xf].batu = BATU(0xf0000000, BAT_BL_256M, BAT_Vs);
-
- /*
- * Use an IBAT and a DBAT to map the bottom segment of memory
- * where we are.
- */
- batu = BATU(0x00000000, BAT_BL_256M, BAT_Vs);
- batl = BATL(0x00000000, BAT_M, BAT_PP_RW);
- __asm ("mtibatu 0,%0; mtibatl 0,%1; mtdbatu 0,%0; mtdbatl 0,%1"
- :: "r"(batu), "r"(batl));
-
-#if 0
- /* map frame buffer */
- batu = BATU(0x90000000, BAT_BL_256M, BAT_Vs);
- batl = BATL(0x90000000, BAT_I|BAT_G, BAT_PP_RW);
- __asm ("mtdbatu 1,%0; mtdbatl 1,%1"
- :: "r"(batu), "r"(batl));
-#endif
-
-#if 1
- /* map pci space */
- batu = BATU(0x80000000, BAT_BL_256M, BAT_Vs);
- batl = BATL(0x80000000, BAT_I|BAT_G, BAT_PP_RW);
- __asm ("mtdbatu 1,%0; mtdbatl 1,%1"
- :: "r"(batu), "r"(batl));
-#endif
-
- /*
- * Set the start and end of kva.
- */
- virtual_avail = VM_MIN_KERNEL_ADDRESS;
- virtual_end = VM_MAX_KERNEL_ADDRESS;
-
- mem_regions(&pregions, &pregions_sz, &regions, &regions_sz);
- CTR0(KTR_PMAP, "pmap_bootstrap: physical memory");
-
- qsort(pregions, pregions_sz, sizeof(*pregions), mr_cmp);
- for (i = 0; i < pregions_sz; i++) {
- vm_offset_t pa;
- vm_offset_t end;
-
- CTR3(KTR_PMAP, "physregion: %#x - %#x (%#x)",
- pregions[i].mr_start,
- pregions[i].mr_start + pregions[i].mr_size,
- pregions[i].mr_size);
- /*
- * Install entries into the BAT table to allow all
- * of physmem to be convered by on-demand BAT entries.
- * The loop will sometimes set the same battable element
- * twice, but that's fine since they won't be used for
- * a while yet.
- */
- pa = pregions[i].mr_start & 0xf0000000;
- end = pregions[i].mr_start + pregions[i].mr_size;
- do {
- u_int n = pa >> ADDR_SR_SHFT;
-
- battable[n].batl = BATL(pa, BAT_M, BAT_PP_RW);
- battable[n].batu = BATU(pa, BAT_BL_256M, BAT_Vs);
- pa += SEGMENT_LENGTH;
- } while (pa < end);
- }
-
- if (sizeof(phys_avail)/sizeof(phys_avail[0]) < regions_sz)
- panic("pmap_bootstrap: phys_avail too small");
- qsort(regions, regions_sz, sizeof(*regions), mr_cmp);
- phys_avail_count = 0;
- physsz = 0;
- for (i = 0, j = 0; i < regions_sz; i++, j += 2) {
- CTR3(KTR_PMAP, "region: %#x - %#x (%#x)", regions[i].mr_start,
- regions[i].mr_start + regions[i].mr_size,
- regions[i].mr_size);
- phys_avail[j] = regions[i].mr_start;
- phys_avail[j + 1] = regions[i].mr_start + regions[i].mr_size;
- phys_avail_count++;
- physsz += regions[i].mr_size;
- }
- physmem = btoc(physsz);
-
- /*
- * Allocate PTEG table.
- */
-#ifdef PTEGCOUNT
- pmap_pteg_count = PTEGCOUNT;
-#else
- pmap_pteg_count = 0x1000;
-
- while (pmap_pteg_count < physmem)
- pmap_pteg_count <<= 1;
-
- pmap_pteg_count >>= 1;
-#endif /* PTEGCOUNT */
-
- size = pmap_pteg_count * sizeof(struct pteg);
- CTR2(KTR_PMAP, "pmap_bootstrap: %d PTEGs, %d bytes", pmap_pteg_count,
- size);
- pmap_pteg_table = (struct pteg *)pmap_bootstrap_alloc(size, size);
- CTR1(KTR_PMAP, "pmap_bootstrap: PTEG table at %p", pmap_pteg_table);
- bzero((void *)pmap_pteg_table, pmap_pteg_count * sizeof(struct pteg));
- pmap_pteg_mask = pmap_pteg_count - 1;
-
- /*
- * Allocate pv/overflow lists.
- */
- size = sizeof(struct pvo_head) * pmap_pteg_count;
- pmap_pvo_table = (struct pvo_head *)pmap_bootstrap_alloc(size,
- PAGE_SIZE);
- CTR1(KTR_PMAP, "pmap_bootstrap: PVO table at %p", pmap_pvo_table);
- for (i = 0; i < pmap_pteg_count; i++)
- LIST_INIT(&pmap_pvo_table[i]);
-
- /*
- * Allocate the message buffer.
- */
- msgbuf_phys = pmap_bootstrap_alloc(MSGBUF_SIZE, 0);
-
- /*
- * Initialise the unmanaged pvo pool.
- */
- pmap_bpvo_pool = (struct pvo_entry *)pmap_bootstrap_alloc(
- BPVO_POOL_SIZE*sizeof(struct pvo_entry), 0);
- pmap_bpvo_pool_index = 0;
-
- /*
- * Make sure kernel vsid is allocated as well as VSID 0.
- */
- pmap_vsid_bitmap[(KERNEL_VSIDBITS & (NPMAPS - 1)) / VSID_NBPW]
- |= 1 << (KERNEL_VSIDBITS % VSID_NBPW);
- pmap_vsid_bitmap[0] |= 1;
-
- /*
- * Set up the OpenFirmware pmap and add it's mappings.
- */
- pmap_pinit(&ofw_pmap);
- ofw_pmap.pm_sr[KERNEL_SR] = KERNEL_SEGMENT;
- if ((chosen = OF_finddevice("/chosen")) == -1)
- panic("pmap_bootstrap: can't find /chosen");
- OF_getprop(chosen, "mmu", &mmui, 4);
- if ((mmu = OF_instance_to_package(mmui)) == -1)
- panic("pmap_bootstrap: can't get mmu package");
- if ((sz = OF_getproplen(mmu, "translations")) == -1)
- panic("pmap_bootstrap: can't get ofw translation count");
- translations = NULL;
- for (i = 0; phys_avail[i + 2] != 0; i += 2) {
- if (phys_avail[i + 1] >= sz)
- translations = (struct ofw_map *)phys_avail[i];
- }
- if (translations == NULL)
- panic("pmap_bootstrap: no space to copy translations");
- bzero(translations, sz);
- if (OF_getprop(mmu, "translations", translations, sz) == -1)
- panic("pmap_bootstrap: can't get ofw translations");
- CTR0(KTR_PMAP, "pmap_bootstrap: translations");
- sz /= sizeof(*translations);
- qsort(translations, sz, sizeof (*translations), om_cmp);
- for (i = 0, ofw_mappings = 0; i < sz; i++) {
- CTR3(KTR_PMAP, "translation: pa=%#x va=%#x len=%#x",
- translations[i].om_pa, translations[i].om_va,
- translations[i].om_len);
-
- /*
- * If the mapping is 1:1, let the RAM and device on-demand
- * BAT tables take care of the translation.
- */
- if (translations[i].om_va == translations[i].om_pa)
- continue;
-
- /* Enter the pages */
- for (off = 0; off < translations[i].om_len; off += PAGE_SIZE) {
- struct vm_page m;
-
- m.phys_addr = translations[i].om_pa + off;
- pmap_enter(&ofw_pmap, translations[i].om_va + off, &m,
- VM_PROT_ALL, 1);
- ofw_mappings++;
- }
- }
-#ifdef SMP
- TLBSYNC();
-#endif
-
- /*
- * Initialize the kernel pmap (which is statically allocated).
- */
- for (i = 0; i < 16; i++) {
- kernel_pmap->pm_sr[i] = EMPTY_SEGMENT;
- }
- kernel_pmap->pm_sr[KERNEL_SR] = KERNEL_SEGMENT;
- kernel_pmap->pm_active = ~0;
-
- /*
- * Allocate a kernel stack with a guard page for thread0 and map it
- * into the kernel page map.
- */
- pa = pmap_bootstrap_alloc(KSTACK_PAGES * PAGE_SIZE, 0);
- kstack0_phys = pa;
- kstack0 = virtual_avail + (KSTACK_GUARD_PAGES * PAGE_SIZE);
- CTR2(KTR_PMAP, "pmap_bootstrap: kstack0 at %#x (%#x)", kstack0_phys,
- kstack0);
- virtual_avail += (KSTACK_PAGES + KSTACK_GUARD_PAGES) * PAGE_SIZE;
- for (i = 0; i < KSTACK_PAGES; i++) {
- pa = kstack0_phys + i * PAGE_SIZE;
- va = kstack0 + i * PAGE_SIZE;
- pmap_kenter(va, pa);
- TLBIE(va);
- }
-
- /*
- * Calculate the first and last available physical addresses.
- */
- avail_start = phys_avail[0];
- for (i = 0; phys_avail[i + 2] != 0; i += 2)
- ;
- avail_end = phys_avail[i + 1];
- Maxmem = powerpc_btop(avail_end);
-
- /*
- * Allocate virtual address space for the message buffer.
- */
- msgbufp = (struct msgbuf *)virtual_avail;
- virtual_avail += round_page(MSGBUF_SIZE);
-
- /*
- * Initialize hardware.
- */
- for (i = 0; i < 16; i++) {
- mtsrin(i << ADDR_SR_SHFT, EMPTY_SEGMENT);
- }
- __asm __volatile ("mtsr %0,%1"
- :: "n"(KERNEL_SR), "r"(KERNEL_SEGMENT));
- __asm __volatile ("sync; mtsdr1 %0; isync"
- :: "r"((u_int)pmap_pteg_table | (pmap_pteg_mask >> 10)));
- tlbia();
-
- pmap_bootstrapped++;
-}
-
-/*
- * Activate a user pmap. The pmap must be activated before it's address
- * space can be accessed in any way.
- */
-void
-pmap_activate(struct thread *td)
-{
- pmap_t pm, pmr;
-
- /*
- * Load all the data we need up front to encourage the compiler to
- * not issue any loads while we have interrupts disabled below.
- */
- pm = &td->td_proc->p_vmspace->vm_pmap;
-
- if ((pmr = (pmap_t)pmap_kextract((vm_offset_t)pm)) == NULL)
- pmr = pm;
-
- pm->pm_active |= PCPU_GET(cpumask);
- PCPU_SET(curpmap, pmr);
-}
-
-void
-pmap_deactivate(struct thread *td)
-{
- pmap_t pm;
-
- pm = &td->td_proc->p_vmspace->vm_pmap;
- pm->pm_active &= ~(PCPU_GET(cpumask));
- PCPU_SET(curpmap, NULL);
-}
-
-vm_offset_t
-pmap_addr_hint(vm_object_t object, vm_offset_t va, vm_size_t size)
-{
-
- return (va);
-}
-
-void
-pmap_change_wiring(pmap_t pm, vm_offset_t va, boolean_t wired)
-{
- struct pvo_entry *pvo;
-
- pvo = pmap_pvo_find_va(pm, va & ~ADDR_POFF, NULL);
-
- if (pvo != NULL) {
- if (wired) {
- if ((pvo->pvo_vaddr & PVO_WIRED) == 0)
- pm->pm_stats.wired_count++;
- pvo->pvo_vaddr |= PVO_WIRED;
- } else {
- if ((pvo->pvo_vaddr & PVO_WIRED) != 0)
- pm->pm_stats.wired_count--;
- pvo->pvo_vaddr &= ~PVO_WIRED;
- }
- }
-}
-
-void
-pmap_copy(pmap_t dst_pmap, pmap_t src_pmap, vm_offset_t dst_addr,
- vm_size_t len, vm_offset_t src_addr)
-{
-
- /*
- * This is not needed as it's mainly an optimisation.
- * It may want to be implemented later though.
- */
-}
-
-void
-pmap_copy_page(vm_page_t msrc, vm_page_t mdst)
-{
- vm_offset_t dst;
- vm_offset_t src;
-
- dst = VM_PAGE_TO_PHYS(mdst);
- src = VM_PAGE_TO_PHYS(msrc);
-
- kcopy((void *)src, (void *)dst, PAGE_SIZE);
-}
-
-/*
- * Zero a page of physical memory by temporarily mapping it into the tlb.
- */
-void
-pmap_zero_page(vm_page_t m)
-{
- vm_offset_t pa = VM_PAGE_TO_PHYS(m);
- caddr_t va;
-
- if (pa < SEGMENT_LENGTH) {
- va = (caddr_t) pa;
- } else if (pmap_initialized) {
- if (pmap_pvo_zeropage == NULL)
- pmap_pvo_zeropage = pmap_rkva_alloc();
- pmap_pa_map(pmap_pvo_zeropage, pa, NULL, NULL);
- va = (caddr_t)PVO_VADDR(pmap_pvo_zeropage);
- } else {
- panic("pmap_zero_page: can't zero pa %#x", pa);
- }
-
- bzero(va, PAGE_SIZE);
-
- if (pa >= SEGMENT_LENGTH)
- pmap_pa_unmap(pmap_pvo_zeropage, NULL, NULL);
-}
-
-void
-pmap_zero_page_area(vm_page_t m, int off, int size)
-{
- vm_offset_t pa = VM_PAGE_TO_PHYS(m);
- caddr_t va;
-
- if (pa < SEGMENT_LENGTH) {
- va = (caddr_t) pa;
- } else if (pmap_initialized) {
- if (pmap_pvo_zeropage == NULL)
- pmap_pvo_zeropage = pmap_rkva_alloc();
- pmap_pa_map(pmap_pvo_zeropage, pa, NULL, NULL);
- va = (caddr_t)PVO_VADDR(pmap_pvo_zeropage);
- } else {
- panic("pmap_zero_page: can't zero pa %#x", pa);
- }
-
- bzero(va + off, size);
-
- if (pa >= SEGMENT_LENGTH)
- pmap_pa_unmap(pmap_pvo_zeropage, NULL, NULL);
-}
-
-void
-pmap_zero_page_idle(vm_page_t m)
-{
-
- /* XXX this is called outside of Giant, is pmap_zero_page safe? */
- /* XXX maybe have a dedicated mapping for this to avoid the problem? */
- mtx_lock(&Giant);
- pmap_zero_page(m);
- mtx_unlock(&Giant);
-}
-
-/*
- * Map the given physical page at the specified virtual address in the
- * target pmap with the protection requested. If specified the page
- * will be wired down.
- */
-void
-pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot,
- boolean_t wired)
-{
- struct pvo_head *pvo_head;
- uma_zone_t zone;
- vm_page_t pg;
- u_int pte_lo, pvo_flags, was_exec, i;
- int error;
-
- if (!pmap_initialized) {
- pvo_head = &pmap_pvo_kunmanaged;
- zone = pmap_upvo_zone;
- pvo_flags = 0;
- pg = NULL;
- was_exec = PTE_EXEC;
- } else {
- pvo_head = vm_page_to_pvoh(m);
- pg = m;
- zone = pmap_mpvo_zone;
- pvo_flags = PVO_MANAGED;
- was_exec = 0;
- }
-
- /*
- * If this is a managed page, and it's the first reference to the page,
- * clear the execness of the page. Otherwise fetch the execness.
- */
- if (pg != NULL) {
- if (LIST_EMPTY(pvo_head)) {
- pmap_attr_clear(pg, PTE_EXEC);
- } else {
- was_exec = pmap_attr_fetch(pg) & PTE_EXEC;
- }
- }
-
-
- /*
- * Assume the page is cache inhibited and access is guarded unless
- * it's in our available memory array.
- */
- pte_lo = PTE_I | PTE_G;
- for (i = 0; i < pregions_sz; i++) {
- if ((VM_PAGE_TO_PHYS(m) >= pregions[i].mr_start) &&
- (VM_PAGE_TO_PHYS(m) <
- (pregions[i].mr_start + pregions[i].mr_size))) {
- pte_lo &= ~(PTE_I | PTE_G);
- break;
- }
- }
-
- if (prot & VM_PROT_WRITE)
- pte_lo |= PTE_BW;
- else
- pte_lo |= PTE_BR;
-
- pvo_flags |= (prot & VM_PROT_EXECUTE);
-
- if (wired)
- pvo_flags |= PVO_WIRED;
-
- error = pmap_pvo_enter(pmap, zone, pvo_head, va, VM_PAGE_TO_PHYS(m),
- pte_lo, pvo_flags);
-
- /*
- * Flush the real page from the instruction cache if this page is
- * mapped executable and cacheable and was not previously mapped (or
- * was not mapped executable).
- */
- if (error == 0 && (pvo_flags & PVO_EXECUTABLE) &&
- (pte_lo & PTE_I) == 0 && was_exec == 0) {
- /*
- * Flush the real memory from the cache.
- */
- pmap_syncicache(VM_PAGE_TO_PHYS(m), PAGE_SIZE);
- if (pg != NULL)
- pmap_attr_save(pg, PTE_EXEC);
- }
-
- /* XXX syncicache always until problems are sorted */
- pmap_syncicache(VM_PAGE_TO_PHYS(m), PAGE_SIZE);
-}
-
-vm_offset_t
-pmap_extract(pmap_t pm, vm_offset_t va)
-{
- struct pvo_entry *pvo;
-
- pvo = pmap_pvo_find_va(pm, va & ~ADDR_POFF, NULL);
-
- if (pvo != NULL) {
- return ((pvo->pvo_pte.pte_lo & PTE_RPGN) | (va & ADDR_POFF));
- }
-
- return (0);
-}
-
-/*
- * Grow the number of kernel page table entries. Unneeded.
- */
-void
-pmap_growkernel(vm_offset_t addr)
-{
-}
-
-void
-pmap_init(vm_offset_t phys_start, vm_offset_t phys_end)
-{
-
- CTR0(KTR_PMAP, "pmap_init");
-
- pmap_pvo_obj = vm_object_allocate(OBJT_PHYS, 16);
- pmap_pvo_count = 0;
- pmap_upvo_zone = uma_zcreate("UPVO entry", sizeof (struct pvo_entry),
- NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_VM);
- uma_zone_set_allocf(pmap_upvo_zone, pmap_pvo_allocf);
- pmap_mpvo_zone = uma_zcreate("MPVO entry", sizeof(struct pvo_entry),
- NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_VM);
- uma_zone_set_allocf(pmap_mpvo_zone, pmap_pvo_allocf);
- pmap_initialized = TRUE;
-}
-
-void
-pmap_init2(void)
-{
-
- CTR0(KTR_PMAP, "pmap_init2");
-}
-
-boolean_t
-pmap_is_modified(vm_page_t m)
-{
-
- if ((m->flags & (PG_FICTITIOUS |PG_UNMANAGED)) != 0)
- return (FALSE);
-
- return (pmap_query_bit(m, PTE_CHG));
-}
-
-void
-pmap_clear_reference(vm_page_t m)
-{
-
- if ((m->flags & (PG_FICTITIOUS | PG_UNMANAGED)) != 0)
- return;
- pmap_clear_bit(m, PTE_REF, NULL);
-}
-
-void
-pmap_clear_modify(vm_page_t m)
-{
-
- if ((m->flags & (PG_FICTITIOUS | PG_UNMANAGED)) != 0)
- return;
- pmap_clear_bit(m, PTE_CHG, NULL);
-}
-
-/*
- * pmap_ts_referenced:
- *
- * Return a count of reference bits for a page, clearing those bits.
- * It is not necessary for every reference bit to be cleared, but it
- * is necessary that 0 only be returned when there are truly no
- * reference bits set.
- *
- * XXX: The exact number of bits to check and clear is a matter that
- * should be tested and standardized at some point in the future for
- * optimal aging of shared pages.
- */
-int
-pmap_ts_referenced(vm_page_t m)
-{
- int count;
-
- if ((m->flags & (PG_FICTITIOUS | PG_UNMANAGED)) != 0)
- return (0);
-
- count = pmap_clear_bit(m, PTE_REF, NULL);
-
- return (count);
-}
-
-/*
- * Map a wired page into kernel virtual address space.
- */
-void
-pmap_kenter(vm_offset_t va, vm_offset_t pa)
-{
- u_int pte_lo;
- int error;
- int i;
-
-#if 0
- if (va < VM_MIN_KERNEL_ADDRESS)
- panic("pmap_kenter: attempt to enter non-kernel address %#x",
- va);
-#endif
-
- pte_lo = PTE_I | PTE_G;
- for (i = 0; i < pregions_sz; i++) {
- if ((pa >= pregions[i].mr_start) &&
- (pa < (pregions[i].mr_start + pregions[i].mr_size))) {
- pte_lo &= ~(PTE_I | PTE_G);
- break;
- }
- }
-
- error = pmap_pvo_enter(kernel_pmap, pmap_upvo_zone,
- &pmap_pvo_kunmanaged, va, pa, pte_lo, PVO_WIRED);
-
- if (error != 0 && error != ENOENT)
- panic("pmap_kenter: failed to enter va %#x pa %#x: %d", va,
- pa, error);
-
- /*
- * Flush the real memory from the instruction cache.
- */
- if ((pte_lo & (PTE_I | PTE_G)) == 0) {
- pmap_syncicache(pa, PAGE_SIZE);
- }
-}
-
-/*
- * Extract the physical page address associated with the given kernel virtual
- * address.
- */
-vm_offset_t
-pmap_kextract(vm_offset_t va)
-{
- struct pvo_entry *pvo;
-
- pvo = pmap_pvo_find_va(kernel_pmap, va & ~ADDR_POFF, NULL);
- if (pvo == NULL) {
- return (0);
- }
-
- return ((pvo->pvo_pte.pte_lo & PTE_RPGN) | (va & ADDR_POFF));
-}
-
-/*
- * Remove a wired page from kernel virtual address space.
- */
-void
-pmap_kremove(vm_offset_t va)
-{
-
- pmap_remove(kernel_pmap, va, va + PAGE_SIZE);
-}
-
-/*
- * Map a range of physical addresses into kernel virtual address space.
- *
- * The value passed in *virt is a suggested virtual address for the mapping.
- * Architectures which can support a direct-mapped physical to virtual region
- * can return the appropriate address within that region, leaving '*virt'
- * unchanged. We cannot and therefore do not; *virt is updated with the
- * first usable address after the mapped region.
- */
-vm_offset_t
-pmap_map(vm_offset_t *virt, vm_offset_t pa_start, vm_offset_t pa_end, int prot)
-{
- vm_offset_t sva, va;
-
- sva = *virt;
- va = sva;
- for (; pa_start < pa_end; pa_start += PAGE_SIZE, va += PAGE_SIZE)
- pmap_kenter(va, pa_start);
- *virt = va;
- return (sva);
-}
-
-int
-pmap_mincore(pmap_t pmap, vm_offset_t addr)
-{
- TODO;
- return (0);
-}
-
-void
-pmap_object_init_pt(pmap_t pm, vm_offset_t addr, vm_object_t object,
- vm_pindex_t pindex, vm_size_t size, int limit)
-{
-
- KASSERT(pm == &curproc->p_vmspace->vm_pmap || pm == kernel_pmap,
- ("pmap_remove_pages: non current pmap"));
- /* XXX */
-}
-
-/*
- * Lower the permission for all mappings to a given page.
- */
-void
-pmap_page_protect(vm_page_t m, vm_prot_t prot)
-{
- struct pvo_head *pvo_head;
- struct pvo_entry *pvo, *next_pvo;
- struct pte *pt;
-
- /*
- * Since the routine only downgrades protection, if the
- * maximal protection is desired, there isn't any change
- * to be made.
- */
- if ((prot & (VM_PROT_READ|VM_PROT_WRITE)) ==
- (VM_PROT_READ|VM_PROT_WRITE))
- return;
-
- pvo_head = vm_page_to_pvoh(m);
- for (pvo = LIST_FIRST(pvo_head); pvo != NULL; pvo = next_pvo) {
- next_pvo = LIST_NEXT(pvo, pvo_vlink);
- PMAP_PVO_CHECK(pvo); /* sanity check */
-
- /*
- * Downgrading to no mapping at all, we just remove the entry.
- */
- if ((prot & VM_PROT_READ) == 0) {
- pmap_pvo_remove(pvo, -1);
- continue;
- }
-
- /*
- * If EXEC permission is being revoked, just clear the flag
- * in the PVO.
- */
- if ((prot & VM_PROT_EXECUTE) == 0)
- pvo->pvo_vaddr &= ~PVO_EXECUTABLE;
-
- /*
- * If this entry is already RO, don't diddle with the page
- * table.
- */
- if ((pvo->pvo_pte.pte_lo & PTE_PP) == PTE_BR) {
- PMAP_PVO_CHECK(pvo);
- continue;
- }
-
- /*
- * Grab the PTE before we diddle the bits so pvo_to_pte can
- * verify the pte contents are as expected.
- */
- pt = pmap_pvo_to_pte(pvo, -1);
- pvo->pvo_pte.pte_lo &= ~PTE_PP;
- pvo->pvo_pte.pte_lo |= PTE_BR;
- if (pt != NULL)
- pmap_pte_change(pt, &pvo->pvo_pte, pvo->pvo_vaddr);
- PMAP_PVO_CHECK(pvo); /* sanity check */
- }
-}
-
-/*
- * Returns true if the pmap's pv is one of the first
- * 16 pvs linked to from this page. This count may
- * be changed upwards or downwards in the future; it
- * is only necessary that true be returned for a small
- * subset of pmaps for proper page aging.
- */
-boolean_t
-pmap_page_exists_quick(pmap_t pmap, vm_page_t m)
-{
- int loops;
- struct pvo_entry *pvo;
-
- if (!pmap_initialized || (m->flags & PG_FICTITIOUS))
- return FALSE;
-
- loops = 0;
- LIST_FOREACH(pvo, vm_page_to_pvoh(m), pvo_vlink) {
- if (pvo->pvo_pmap == pmap)
- return (TRUE);
- if (++loops >= 16)
- break;
- }
-
- return (FALSE);
-}
-
-static u_int pmap_vsidcontext;
-
-void
-pmap_pinit(pmap_t pmap)
-{
- int i, mask;
- u_int entropy;
-
- entropy = 0;
- __asm __volatile("mftb %0" : "=r"(entropy));
-
- /*
- * Allocate some segment registers for this pmap.
- */
- for (i = 0; i < NPMAPS; i += VSID_NBPW) {
- u_int hash, n;
-
- /*
- * Create a new value by mutiplying by a prime and adding in
- * entropy from the timebase register. This is to make the
- * VSID more random so that the PT hash function collides
- * less often. (Note that the prime casues gcc to do shifts
- * instead of a multiply.)
- */
- pmap_vsidcontext = (pmap_vsidcontext * 0x1105) + entropy;
- hash = pmap_vsidcontext & (NPMAPS - 1);
- if (hash == 0) /* 0 is special, avoid it */
- continue;
- n = hash >> 5;
- mask = 1 << (hash & (VSID_NBPW - 1));
- hash = (pmap_vsidcontext & 0xfffff);
- if (pmap_vsid_bitmap[n] & mask) { /* collision? */
- /* anything free in this bucket? */
- if (pmap_vsid_bitmap[n] == 0xffffffff) {
- entropy = (pmap_vsidcontext >> 20);
- continue;
- }
- i = ffs(~pmap_vsid_bitmap[i]) - 1;
- mask = 1 << i;
- hash &= 0xfffff & ~(VSID_NBPW - 1);
- hash |= i;
- }
- pmap_vsid_bitmap[n] |= mask;
- for (i = 0; i < 16; i++)
- pmap->pm_sr[i] = VSID_MAKE(i, hash);
- return;
- }
-
- panic("pmap_pinit: out of segments");
-}
-
-/*
- * Initialize the pmap associated with process 0.
- */
-void
-pmap_pinit0(pmap_t pm)
-{
-
- pmap_pinit(pm);
- bzero(&pm->pm_stats, sizeof(pm->pm_stats));
-}
-
-void
-pmap_pinit2(pmap_t pmap)
-{
- /* XXX: Remove this stub when no longer called */
-}
-
-void
-pmap_prefault(pmap_t pm, vm_offset_t va, vm_map_entry_t entry)
-{
- KASSERT(pm == &curproc->p_vmspace->vm_pmap || pm == kernel_pmap,
- ("pmap_prefault: non current pmap"));
- /* XXX */
-}
-
-/*
- * Set the physical protection on the specified range of this map as requested.
- */
-void
-pmap_protect(pmap_t pm, vm_offset_t sva, vm_offset_t eva, vm_prot_t prot)
-{
- struct pvo_entry *pvo;
- struct pte *pt;
- int pteidx;
-
- CTR4(KTR_PMAP, "pmap_protect: pm=%p sva=%#x eva=%#x prot=%#x", pm, sva,
- eva, prot);
-
-
- KASSERT(pm == &curproc->p_vmspace->vm_pmap || pm == kernel_pmap,
- ("pmap_protect: non current pmap"));
-
- if ((prot & VM_PROT_READ) == VM_PROT_NONE) {
- pmap_remove(pm, sva, eva);
- return;
- }
-
- for (; sva < eva; sva += PAGE_SIZE) {
- pvo = pmap_pvo_find_va(pm, sva, &pteidx);
- if (pvo == NULL)
- continue;
-
- if ((prot & VM_PROT_EXECUTE) == 0)
- pvo->pvo_vaddr &= ~PVO_EXECUTABLE;
-
- /*
- * Grab the PTE pointer before we diddle with the cached PTE
- * copy.
- */
- pt = pmap_pvo_to_pte(pvo, pteidx);
- /*
- * Change the protection of the page.
- */
- pvo->pvo_pte.pte_lo &= ~PTE_PP;
- pvo->pvo_pte.pte_lo |= PTE_BR;
-
- /*
- * If the PVO is in the page table, update that pte as well.
- */
- if (pt != NULL)
- pmap_pte_change(pt, &pvo->pvo_pte, pvo->pvo_vaddr);
- }
-}
-
-/*
- * Map a list of wired pages into kernel virtual address space. This is
- * intended for temporary mappings which do not need page modification or
- * references recorded. Existing mappings in the region are overwritten.
- */
-void
-pmap_qenter(vm_offset_t sva, vm_page_t *m, int count)
-{
- vm_offset_t va;
-
- va = sva;
- while (count-- > 0) {
- pmap_kenter(va, VM_PAGE_TO_PHYS(*m));
- va += PAGE_SIZE;
- m++;
- }
-}
-
-/*
- * Remove page mappings from kernel virtual address space. Intended for
- * temporary mappings entered by pmap_qenter.
- */
-void
-pmap_qremove(vm_offset_t sva, int count)
-{
- vm_offset_t va;
-
- va = sva;
- while (count-- > 0) {
- pmap_kremove(va);
- va += PAGE_SIZE;
- }
-}
-
-void
-pmap_release(pmap_t pmap)
-{
- int idx, mask;
-
- /*
- * Free segment register's VSID
- */
- if (pmap->pm_sr[0] == 0)
- panic("pmap_release");
-
- idx = VSID_TO_HASH(pmap->pm_sr[0]) & (NPMAPS-1);
- mask = 1 << (idx % VSID_NBPW);
- idx /= VSID_NBPW;
- pmap_vsid_bitmap[idx] &= ~mask;
-}
-
-/*
- * Remove the given range of addresses from the specified map.
- */
-void
-pmap_remove(pmap_t pm, vm_offset_t sva, vm_offset_t eva)
-{
- struct pvo_entry *pvo;
- int pteidx;
-
- for (; sva < eva; sva += PAGE_SIZE) {
- pvo = pmap_pvo_find_va(pm, sva, &pteidx);
- if (pvo != NULL) {
- pmap_pvo_remove(pvo, pteidx);
- }
- }
-}
-
-/*
- * Remove physical page from all pmaps in which it resides. pmap_pvo_remove()
- * will reflect changes in pte's back to the vm_page.
- */
-void
-pmap_remove_all(vm_page_t m)
-{
- struct pvo_head *pvo_head;
- struct pvo_entry *pvo, *next_pvo;
-
- KASSERT((m->flags & (PG_FICTITIOUS|PG_UNMANAGED)) == 0,
- ("pv_remove_all: illegal for unmanaged page %#x",
- VM_PAGE_TO_PHYS(m)));
-
- pvo_head = vm_page_to_pvoh(m);
- for (pvo = LIST_FIRST(pvo_head); pvo != NULL; pvo = next_pvo) {
- next_pvo = LIST_NEXT(pvo, pvo_vlink);
-
- PMAP_PVO_CHECK(pvo); /* sanity check */
- pmap_pvo_remove(pvo, -1);
- }
- vm_page_flag_clear(m, PG_WRITEABLE);
-}
-
-/*
- * Remove all pages from specified address space, this aids process exit
- * speeds. This is much faster than pmap_remove in the case of running down
- * an entire address space. Only works for the current pmap.
- */
-void
-pmap_remove_pages(pmap_t pm, vm_offset_t sva, vm_offset_t eva)
-{
-
- KASSERT(pm == &curproc->p_vmspace->vm_pmap || pm == kernel_pmap,
- ("pmap_remove_pages: non current pmap"));
- pmap_remove(pm, sva, eva);
-}
-
-#ifndef KSTACK_MAX_PAGES
-#define KSTACK_MAX_PAGES 32
-#endif
-
-/*
- * Create the kernel stack and pcb for a new thread.
- * This routine directly affects the fork perf for a process and
- * create performance for a thread.
- */
-void
-pmap_new_thread(struct thread *td, int pages)
-{
- vm_page_t ma[KSTACK_MAX_PAGES];
- vm_object_t ksobj;
- vm_offset_t ks;
- vm_page_t m;
- u_int i;
-
- /* Bounds check */
- if (pages <= 1)
- pages = KSTACK_PAGES;
- else if (pages > KSTACK_MAX_PAGES)
- pages = KSTACK_MAX_PAGES;
-
- /*
- * Allocate object for the kstack.
- */
- ksobj = vm_object_allocate(OBJT_DEFAULT, pages);
- td->td_kstack_obj = ksobj;
-
- /*
- * Get a kernel virtual address for the kstack for this thread.
- */
- ks = kmem_alloc_nofault(kernel_map,
- (pages + KSTACK_GUARD_PAGES) * PAGE_SIZE);
- if (ks == 0)
- panic("pmap_new_thread: kstack allocation failed");
- TLBIE(ks);
- ks += KSTACK_GUARD_PAGES * PAGE_SIZE;
- td->td_kstack = ks;
-
- /*
- * Knowing the number of pages allocated is useful when you
- * want to deallocate them.
- */
- td->td_kstack_pages = pages;
-
- for (i = 0; i < pages; i++) {
- /*
- * Get a kernel stack page.
- */
- m = vm_page_grab(ksobj, i,
- VM_ALLOC_NORMAL | VM_ALLOC_RETRY | VM_ALLOC_WIRED);
- ma[i] = m;
-
- vm_page_lock_queues();
- vm_page_wakeup(m);
- vm_page_flag_clear(m, PG_ZERO);
- m->valid = VM_PAGE_BITS_ALL;
- vm_page_unlock_queues();
- }
-
- /*
- * Enter the page into the kernel address space
- */
- pmap_qenter(ks, ma, pages);
-}
-
-void
-pmap_dispose_thread(struct thread *td)
-{
- vm_object_t ksobj;
- vm_offset_t ks;
- vm_page_t m;
- int i;
- int pages;
-
- pages = td->td_kstack_pages;
- ksobj = td->td_kstack_obj;
- ks = td->td_kstack;
- for (i = 0; i < pages ; i++) {
- m = vm_page_lookup(ksobj, i);
- if (m == NULL)
- panic("pmap_dispose_thread: kstack already missing?");
- vm_page_lock_queues();
- vm_page_busy(m);
- vm_page_unwire(m, 0);
- vm_page_free(m);
- vm_page_unlock_queues();
- }
- pmap_qremove(ks, pages);
- kmem_free(kernel_map, ks - (KSTACK_GUARD_PAGES * PAGE_SIZE),
- (pages + KSTACK_GUARD_PAGES) * PAGE_SIZE);
- vm_object_deallocate(ksobj);
-}
-
-void
-pmap_new_altkstack(struct thread *td, int pages)
-{
- /* shuffle the original stack */
- td->td_altkstack_obj = td->td_kstack_obj;
- td->td_altkstack = td->td_kstack;
- td->td_altkstack_pages = td->td_kstack_pages;
-
- pmap_new_thread(td, pages);
-}
-
-void
-pmap_dispose_altkstack(struct thread *td)
-{
- pmap_dispose_thread(td);
-
- /* restore the original kstack */
- td->td_kstack = td->td_altkstack;
- td->td_kstack_obj = td->td_altkstack_obj;
- td->td_kstack_pages = td->td_altkstack_pages;
- td->td_altkstack = 0;
- td->td_altkstack_obj = NULL;
- td->td_altkstack_pages = 0;
-}
-
-void
-pmap_swapin_thread(struct thread *td)
-{
- vm_page_t ma[KSTACK_MAX_PAGES];
- vm_object_t ksobj;
- vm_offset_t ks;
- vm_page_t m;
- int rv;
- int i;
- int pages;
-
- pages = td->td_kstack_pages;
- ksobj = td->td_kstack_obj;
- ks = td->td_kstack;
- for (i = 0; i < pages; i++) {
- m = vm_page_grab(ksobj, i, VM_ALLOC_NORMAL | VM_ALLOC_RETRY);
- if (m->valid != VM_PAGE_BITS_ALL) {
- rv = vm_pager_get_pages(ksobj, &m, 1, 0);
- if (rv != VM_PAGER_OK)
- panic("pmap_swapin_thread: cannot get kstack");
- m = vm_page_lookup(ksobj, i);
- m->valid = VM_PAGE_BITS_ALL;
- }
- ma[i] = m;
- vm_page_lock_queues();
- vm_page_wire(m);
- vm_page_wakeup(m);
- vm_page_unlock_queues();
- }
- pmap_qenter(ks, ma, pages);
-}
-
-
-void
-pmap_swapout_thread(struct thread *td)
-{
- vm_object_t ksobj;
- vm_offset_t ks;
- vm_page_t m;
- int i;
- int pages;
-
- pages = td->td_kstack_pages;
- ksobj = td->td_kstack_obj;
- ks = (vm_offset_t)td->td_kstack;
- for (i = 0; i < pages; i++) {
- m = vm_page_lookup(ksobj, i);
- if (m == NULL)
- panic("pmap_swapout_thread: kstack already missing?");
- vm_page_lock_queues();
- vm_page_dirty(m);
- vm_page_unwire(m, 0);
- vm_page_unlock_queues();
- }
- pmap_qremove(ks, pages);
-}
-
-/*
- * Allocate a physical page of memory directly from the phys_avail map.
- * Can only be called from pmap_bootstrap before avail start and end are
- * calculated.
- */
-static vm_offset_t
-pmap_bootstrap_alloc(vm_size_t size, u_int align)
-{
- vm_offset_t s, e;
- int i, j;
-
- size = round_page(size);
- for (i = 0; phys_avail[i + 1] != 0; i += 2) {
- if (align != 0)
- s = (phys_avail[i] + align - 1) & ~(align - 1);
- else
- s = phys_avail[i];
- e = s + size;
-
- if (s < phys_avail[i] || e > phys_avail[i + 1])
- continue;
-
- if (s == phys_avail[i]) {
- phys_avail[i] += size;
- } else if (e == phys_avail[i + 1]) {
- phys_avail[i + 1] -= size;
- } else {
- for (j = phys_avail_count * 2; j > i; j -= 2) {
- phys_avail[j] = phys_avail[j - 2];
- phys_avail[j + 1] = phys_avail[j - 1];
- }
-
- phys_avail[i + 3] = phys_avail[i + 1];
- phys_avail[i + 1] = s;
- phys_avail[i + 2] = e;
- phys_avail_count++;
- }
-
- return (s);
- }
- panic("pmap_bootstrap_alloc: could not allocate memory");
-}
-
-/*
- * Return an unmapped pvo for a kernel virtual address.
- * Used by pmap functions that operate on physical pages.
- */
-static struct pvo_entry *
-pmap_rkva_alloc(void)
-{
- struct pvo_entry *pvo;
- struct pte *pt;
- vm_offset_t kva;
- int pteidx;
-
- if (pmap_rkva_count == 0)
- panic("pmap_rkva_alloc: no more reserved KVAs");
-
- kva = pmap_rkva_start + (PAGE_SIZE * --pmap_rkva_count);
- pmap_kenter(kva, 0);
-
- pvo = pmap_pvo_find_va(kernel_pmap, kva, &pteidx);
-
- if (pvo == NULL)
- panic("pmap_kva_alloc: pmap_pvo_find_va failed");
-
- pt = pmap_pvo_to_pte(pvo, pteidx);
-
- if (pt == NULL)
- panic("pmap_kva_alloc: pmap_pvo_to_pte failed");
-
- pmap_pte_unset(pt, &pvo->pvo_pte, pvo->pvo_vaddr);
- PVO_PTEGIDX_CLR(pvo);
-
- pmap_pte_overflow++;
-
- return (pvo);
-}
-
-static void
-pmap_pa_map(struct pvo_entry *pvo, vm_offset_t pa, struct pte *saved_pt,
- int *depth_p)
-{
- struct pte *pt;
-
- /*
- * If this pvo already has a valid pte, we need to save it so it can
- * be restored later. We then just reload the new PTE over the old
- * slot.
- */
- if (saved_pt != NULL) {
- pt = pmap_pvo_to_pte(pvo, -1);
-
- if (pt != NULL) {
- pmap_pte_unset(pt, &pvo->pvo_pte, pvo->pvo_vaddr);
- PVO_PTEGIDX_CLR(pvo);
- pmap_pte_overflow++;
- }
-
- *saved_pt = pvo->pvo_pte;
-
- pvo->pvo_pte.pte_lo &= ~PTE_RPGN;
- }
-
- pvo->pvo_pte.pte_lo |= pa;
-
- if (!pmap_pte_spill(pvo->pvo_vaddr))
- panic("pmap_pa_map: could not spill pvo %p", pvo);
-
- if (depth_p != NULL)
- (*depth_p)++;
-}
-
-static void
-pmap_pa_unmap(struct pvo_entry *pvo, struct pte *saved_pt, int *depth_p)
-{
- struct pte *pt;
-
- pt = pmap_pvo_to_pte(pvo, -1);
-
- if (pt != NULL) {
- pmap_pte_unset(pt, &pvo->pvo_pte, pvo->pvo_vaddr);
- PVO_PTEGIDX_CLR(pvo);
- pmap_pte_overflow++;
- }
-
- pvo->pvo_pte.pte_lo &= ~PTE_RPGN;
-
- /*
- * If there is a saved PTE and it's valid, restore it and return.
- */
- if (saved_pt != NULL && (saved_pt->pte_lo & PTE_RPGN) != 0) {
- if (depth_p != NULL && --(*depth_p) == 0)
- panic("pmap_pa_unmap: restoring but depth == 0");
-
- pvo->pvo_pte = *saved_pt;
-
- if (!pmap_pte_spill(pvo->pvo_vaddr))
- panic("pmap_pa_unmap: could not spill pvo %p", pvo);
- }
-}
-
-static void
-pmap_syncicache(vm_offset_t pa, vm_size_t len)
-{
- __syncicache((void *)pa, len);
-}
-
-static void
-tlbia(void)
-{
- caddr_t i;
-
- SYNC();
- for (i = 0; i < (caddr_t)0x00040000; i += 0x00001000) {
- TLBIE(i);
- EIEIO();
- }
- TLBSYNC();
- SYNC();
-}
-
-static int
-pmap_pvo_enter(pmap_t pm, uma_zone_t zone, struct pvo_head *pvo_head,
- vm_offset_t va, vm_offset_t pa, u_int pte_lo, int flags)
-{
- struct pvo_entry *pvo;
- u_int sr;
- int first;
- u_int ptegidx;
- int i;
- int bootstrap;
-
- pmap_pvo_enter_calls++;
- first = 0;
-
- bootstrap = 0;
-
- /*
- * Compute the PTE Group index.
- */
- va &= ~ADDR_POFF;
- sr = va_to_sr(pm->pm_sr, va);
- ptegidx = va_to_pteg(sr, va);
-
- /*
- * Remove any existing mapping for this page. Reuse the pvo entry if
- * there is a mapping.
- */
- LIST_FOREACH(pvo, &pmap_pvo_table[ptegidx], pvo_olink) {
- if (pvo->pvo_pmap == pm && PVO_VADDR(pvo) == va) {
- if ((pvo->pvo_pte.pte_lo & PTE_RPGN) == pa &&
- (pvo->pvo_pte.pte_lo & PTE_PP) ==
- (pte_lo & PTE_PP)) {
- return (0);
- }
- pmap_pvo_remove(pvo, -1);
- break;
- }
- }
-
- /*
- * If we aren't overwriting a mapping, try to allocate.
- */
- if (pmap_initialized) {
- pvo = uma_zalloc(zone, M_NOWAIT);
- } else {
- if (pmap_bpvo_pool_index >= BPVO_POOL_SIZE) {
- panic("pmap_enter: bpvo pool exhausted, %d, %d, %d",
- pmap_bpvo_pool_index, BPVO_POOL_SIZE,
- BPVO_POOL_SIZE * sizeof(struct pvo_entry));
- }
- pvo = &pmap_bpvo_pool[pmap_bpvo_pool_index];
- pmap_bpvo_pool_index++;
- bootstrap = 1;
- }
-
- if (pvo == NULL) {
- return (ENOMEM);
- }
-
- pmap_pvo_entries++;
- pvo->pvo_vaddr = va;
- pvo->pvo_pmap = pm;
- LIST_INSERT_HEAD(&pmap_pvo_table[ptegidx], pvo, pvo_olink);
- pvo->pvo_vaddr &= ~ADDR_POFF;
- if (flags & VM_PROT_EXECUTE)
- pvo->pvo_vaddr |= PVO_EXECUTABLE;
- if (flags & PVO_WIRED)
- pvo->pvo_vaddr |= PVO_WIRED;
- if (pvo_head != &pmap_pvo_kunmanaged)
- pvo->pvo_vaddr |= PVO_MANAGED;
- if (bootstrap)
- pvo->pvo_vaddr |= PVO_BOOTSTRAP;
- pmap_pte_create(&pvo->pvo_pte, sr, va, pa | pte_lo);
-
- /*
- * Remember if the list was empty and therefore will be the first
- * item.
- */
- if (LIST_FIRST(pvo_head) == NULL)
- first = 1;
-
- LIST_INSERT_HEAD(pvo_head, pvo, pvo_vlink);
- if (pvo->pvo_pte.pte_lo & PVO_WIRED)
- pvo->pvo_pmap->pm_stats.wired_count++;
- pvo->pvo_pmap->pm_stats.resident_count++;
-
- /*
- * We hope this succeeds but it isn't required.
- */
- i = pmap_pte_insert(ptegidx, &pvo->pvo_pte);
- if (i >= 0) {
- PVO_PTEGIDX_SET(pvo, i);
- } else {
- panic("pmap_pvo_enter: overflow");
- pmap_pte_overflow++;
- }
-
- return (first ? ENOENT : 0);
-}
-
-static void
-pmap_pvo_remove(struct pvo_entry *pvo, int pteidx)
-{
- struct pte *pt;
-
- /*
- * If there is an active pte entry, we need to deactivate it (and
- * save the ref & cfg bits).
- */
- pt = pmap_pvo_to_pte(pvo, pteidx);
- if (pt != NULL) {
- pmap_pte_unset(pt, &pvo->pvo_pte, pvo->pvo_vaddr);
- PVO_PTEGIDX_CLR(pvo);
- } else {
- pmap_pte_overflow--;
- }
-
- /*
- * Update our statistics.
- */
- pvo->pvo_pmap->pm_stats.resident_count--;
- if (pvo->pvo_pte.pte_lo & PVO_WIRED)
- pvo->pvo_pmap->pm_stats.wired_count--;
-
- /*
- * Save the REF/CHG bits into their cache if the page is managed.
- */
- if (pvo->pvo_vaddr & PVO_MANAGED) {
- struct vm_page *pg;
-
- pg = PHYS_TO_VM_PAGE(pvo->pvo_pte.pte_lo & PTE_RPGN);
- if (pg != NULL) {
- pmap_attr_save(pg, pvo->pvo_pte.pte_lo &
- (PTE_REF | PTE_CHG));
- }
- }
-
- /*
- * Remove this PVO from the PV list.
- */
- LIST_REMOVE(pvo, pvo_vlink);
-
- /*
- * Remove this from the overflow list and return it to the pool
- * if we aren't going to reuse it.
- */
- LIST_REMOVE(pvo, pvo_olink);
- if (!(pvo->pvo_vaddr & PVO_BOOTSTRAP))
- uma_zfree(pvo->pvo_vaddr & PVO_MANAGED ? pmap_mpvo_zone :
- pmap_upvo_zone, pvo);
- pmap_pvo_entries--;
- pmap_pvo_remove_calls++;
-}
-
-static __inline int
-pmap_pvo_pte_index(const struct pvo_entry *pvo, int ptegidx)
-{
- int pteidx;
-
- /*
- * We can find the actual pte entry without searching by grabbing
- * the PTEG index from 3 unused bits in pte_lo[11:9] and by
- * noticing the HID bit.
- */
- pteidx = ptegidx * 8 + PVO_PTEGIDX_GET(pvo);
- if (pvo->pvo_pte.pte_hi & PTE_HID)
- pteidx ^= pmap_pteg_mask * 8;
-
- return (pteidx);
-}
-
-static struct pvo_entry *
-pmap_pvo_find_va(pmap_t pm, vm_offset_t va, int *pteidx_p)
-{
- struct pvo_entry *pvo;
- int ptegidx;
- u_int sr;
-
- va &= ~ADDR_POFF;
- sr = va_to_sr(pm->pm_sr, va);
- ptegidx = va_to_pteg(sr, va);
-
- LIST_FOREACH(pvo, &pmap_pvo_table[ptegidx], pvo_olink) {
- if (pvo->pvo_pmap == pm && PVO_VADDR(pvo) == va) {
- if (pteidx_p)
- *pteidx_p = pmap_pvo_pte_index(pvo, ptegidx);
- return (pvo);
- }
- }
-
- return (NULL);
-}
-
-static struct pte *
-pmap_pvo_to_pte(const struct pvo_entry *pvo, int pteidx)
-{
- struct pte *pt;
-
- /*
- * If we haven't been supplied the ptegidx, calculate it.
- */
- if (pteidx == -1) {
- int ptegidx;
- u_int sr;
-
- sr = va_to_sr(pvo->pvo_pmap->pm_sr, pvo->pvo_vaddr);
- ptegidx = va_to_pteg(sr, pvo->pvo_vaddr);
- pteidx = pmap_pvo_pte_index(pvo, ptegidx);
- }
-
- pt = &pmap_pteg_table[pteidx >> 3].pt[pteidx & 7];
-
- if ((pvo->pvo_pte.pte_hi & PTE_VALID) && !PVO_PTEGIDX_ISSET(pvo)) {
- panic("pmap_pvo_to_pte: pvo %p has valid pte in pvo but no "
- "valid pte index", pvo);
- }
-
- if ((pvo->pvo_pte.pte_hi & PTE_VALID) == 0 && PVO_PTEGIDX_ISSET(pvo)) {
- panic("pmap_pvo_to_pte: pvo %p has valid pte index in pvo "
- "pvo but no valid pte", pvo);
- }
-
- if ((pt->pte_hi ^ (pvo->pvo_pte.pte_hi & ~PTE_VALID)) == PTE_VALID) {
- if ((pvo->pvo_pte.pte_hi & PTE_VALID) == 0) {
- panic("pmap_pvo_to_pte: pvo %p has valid pte in "
- "pmap_pteg_table %p but invalid in pvo", pvo, pt);
- }
-
- if (((pt->pte_lo ^ pvo->pvo_pte.pte_lo) & ~(PTE_CHG|PTE_REF))
- != 0) {
- panic("pmap_pvo_to_pte: pvo %p pte does not match "
- "pte %p in pmap_pteg_table", pvo, pt);
- }
-
- return (pt);
- }
-
- if (pvo->pvo_pte.pte_hi & PTE_VALID) {
- panic("pmap_pvo_to_pte: pvo %p has invalid pte %p in "
- "pmap_pteg_table but valid in pvo", pvo, pt);
- }
-
- return (NULL);
-}
-
-static void *
-pmap_pvo_allocf(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
-{
- vm_page_t m;
-
- if (bytes != PAGE_SIZE)
- panic("pmap_pvo_allocf: benno was shortsighted. hit him.");
-
- *flags = UMA_SLAB_PRIV;
- m = vm_page_alloc(pmap_pvo_obj, pmap_pvo_count, VM_ALLOC_SYSTEM);
- if (m == NULL)
- return (NULL);
- pmap_pvo_count++;
- return ((void *)VM_PAGE_TO_PHYS(m));
-}
-
-/*
- * XXX: THIS STUFF SHOULD BE IN pte.c?
- */
-int
-pmap_pte_spill(vm_offset_t addr)
-{
- struct pvo_entry *source_pvo, *victim_pvo;
- struct pvo_entry *pvo;
- int ptegidx, i, j;
- u_int sr;
- struct pteg *pteg;
- struct pte *pt;
-
- pmap_pte_spills++;
-
- sr = mfsrin(addr);
- ptegidx = va_to_pteg(sr, addr);
-
- /*
- * Have to substitute some entry. Use the primary hash for this.
- * Use low bits of timebase as random generator.
- */
- pteg = &pmap_pteg_table[ptegidx];
- __asm __volatile("mftb %0" : "=r"(i));
- i &= 7;
- pt = &pteg->pt[i];
-
- source_pvo = NULL;
- victim_pvo = NULL;
- LIST_FOREACH(pvo, &pmap_pvo_table[ptegidx], pvo_olink) {
- /*
- * We need to find a pvo entry for this address.
- */
- PMAP_PVO_CHECK(pvo);
- if (source_pvo == NULL &&
- pmap_pte_match(&pvo->pvo_pte, sr, addr,
- pvo->pvo_pte.pte_hi & PTE_HID)) {
- /*
- * Now found an entry to be spilled into the pteg.
- * The PTE is now valid, so we know it's active.
- */
- j = pmap_pte_insert(ptegidx, &pvo->pvo_pte);
-
- if (j >= 0) {
- PVO_PTEGIDX_SET(pvo, j);
- pmap_pte_overflow--;
- PMAP_PVO_CHECK(pvo);
- return (1);
- }
-
- source_pvo = pvo;
-
- if (victim_pvo != NULL)
- break;
- }
-
- /*
- * We also need the pvo entry of the victim we are replacing
- * so save the R & C bits of the PTE.
- */
- if ((pt->pte_hi & PTE_HID) == 0 && victim_pvo == NULL &&
- pmap_pte_compare(pt, &pvo->pvo_pte)) {
- victim_pvo = pvo;
- if (source_pvo != NULL)
- break;
- }
- }
-
- if (source_pvo == NULL)
- return (0);
-
- if (victim_pvo == NULL) {
- if ((pt->pte_hi & PTE_HID) == 0)
- panic("pmap_pte_spill: victim p-pte (%p) has no pvo"
- "entry", pt);
-
- /*
- * If this is a secondary PTE, we need to search it's primary
- * pvo bucket for the matching PVO.
- */
- LIST_FOREACH(pvo, &pmap_pvo_table[ptegidx ^ pmap_pteg_mask],
- pvo_olink) {
- PMAP_PVO_CHECK(pvo);
- /*
- * We also need the pvo entry of the victim we are
- * replacing so save the R & C bits of the PTE.
- */
- if (pmap_pte_compare(pt, &pvo->pvo_pte)) {
- victim_pvo = pvo;
- break;
- }
- }
-
- if (victim_pvo == NULL)
- panic("pmap_pte_spill: victim s-pte (%p) has no pvo"
- "entry", pt);
- }
-
- /*
- * We are invalidating the TLB entry for the EA we are replacing even
- * though it's valid. If we don't, we lose any ref/chg bit changes
- * contained in the TLB entry.
- */
- source_pvo->pvo_pte.pte_hi &= ~PTE_HID;
-
- pmap_pte_unset(pt, &victim_pvo->pvo_pte, victim_pvo->pvo_vaddr);
- pmap_pte_set(pt, &source_pvo->pvo_pte);
-
- PVO_PTEGIDX_CLR(victim_pvo);
- PVO_PTEGIDX_SET(source_pvo, i);
- pmap_pte_replacements++;
-
- PMAP_PVO_CHECK(victim_pvo);
- PMAP_PVO_CHECK(source_pvo);
-
- return (1);
-}
-
-static int
-pmap_pte_insert(u_int ptegidx, struct pte *pvo_pt)
-{
- struct pte *pt;
- int i;
-
- /*
- * First try primary hash.
- */
- for (pt = pmap_pteg_table[ptegidx].pt, i = 0; i < 8; i++, pt++) {
- if ((pt->pte_hi & PTE_VALID) == 0) {
- pvo_pt->pte_hi &= ~PTE_HID;
- pmap_pte_set(pt, pvo_pt);
- return (i);
- }
- }
-
- /*
- * Now try secondary hash.
- */
- ptegidx ^= pmap_pteg_mask;
- ptegidx++;
- for (pt = pmap_pteg_table[ptegidx].pt, i = 0; i < 8; i++, pt++) {
- if ((pt->pte_hi & PTE_VALID) == 0) {
- pvo_pt->pte_hi |= PTE_HID;
- pmap_pte_set(pt, pvo_pt);
- return (i);
- }
- }
-
- panic("pmap_pte_insert: overflow");
- return (-1);
-}
-
-static boolean_t
-pmap_query_bit(vm_page_t m, int ptebit)
-{
- struct pvo_entry *pvo;
- struct pte *pt;
-
- if (pmap_attr_fetch(m) & ptebit)
- return (TRUE);
-
- LIST_FOREACH(pvo, vm_page_to_pvoh(m), pvo_vlink) {
- PMAP_PVO_CHECK(pvo); /* sanity check */
-
- /*
- * See if we saved the bit off. If so, cache it and return
- * success.
- */
- if (pvo->pvo_pte.pte_lo & ptebit) {
- pmap_attr_save(m, ptebit);
- PMAP_PVO_CHECK(pvo); /* sanity check */
- return (TRUE);
- }
- }
-
- /*
- * No luck, now go through the hard part of looking at the PTEs
- * themselves. Sync so that any pending REF/CHG bits are flushed to
- * the PTEs.
- */
- SYNC();
- LIST_FOREACH(pvo, vm_page_to_pvoh(m), pvo_vlink) {
- PMAP_PVO_CHECK(pvo); /* sanity check */
-
- /*
- * See if this pvo has a valid PTE. if so, fetch the
- * REF/CHG bits from the valid PTE. If the appropriate
- * ptebit is set, cache it and return success.
- */
- pt = pmap_pvo_to_pte(pvo, -1);
- if (pt != NULL) {
- pmap_pte_synch(pt, &pvo->pvo_pte);
- if (pvo->pvo_pte.pte_lo & ptebit) {
- pmap_attr_save(m, ptebit);
- PMAP_PVO_CHECK(pvo); /* sanity check */
- return (TRUE);
- }
- }
- }
-
- return (TRUE);
-}
-
-static u_int
-pmap_clear_bit(vm_page_t m, int ptebit, int *origbit)
-{
- u_int count;
- struct pvo_entry *pvo;
- struct pte *pt;
- int rv;
-
- /*
- * Clear the cached value.
- */
- rv = pmap_attr_fetch(m);
- pmap_attr_clear(m, ptebit);
-
- /*
- * Sync so that any pending REF/CHG bits are flushed to the PTEs (so
- * we can reset the right ones). note that since the pvo entries and
- * list heads are accessed via BAT0 and are never placed in the page
- * table, we don't have to worry about further accesses setting the
- * REF/CHG bits.
- */
- SYNC();
-
- /*
- * For each pvo entry, clear the pvo's ptebit. If this pvo has a
- * valid pte clear the ptebit from the valid pte.
- */
- count = 0;
- LIST_FOREACH(pvo, vm_page_to_pvoh(m), pvo_vlink) {
- PMAP_PVO_CHECK(pvo); /* sanity check */
- pt = pmap_pvo_to_pte(pvo, -1);
- if (pt != NULL) {
- pmap_pte_synch(pt, &pvo->pvo_pte);
- if (pvo->pvo_pte.pte_lo & ptebit) {
- count++;
- pmap_pte_clear(pt, PVO_VADDR(pvo), ptebit);
- }
- }
- rv |= pvo->pvo_pte.pte_lo;
- pvo->pvo_pte.pte_lo &= ~ptebit;
- PMAP_PVO_CHECK(pvo); /* sanity check */
- }
-
- if (origbit != NULL) {
- *origbit = rv;
- }
-
- return (count);
-}
-
-/*
- * Return true if the physical range is encompassed by the battable[idx]
- */
-static int
-pmap_bat_mapped(int idx, vm_offset_t pa, vm_size_t size)
-{
- u_int prot;
- u_int32_t start;
- u_int32_t end;
- u_int32_t bat_ble;
-
- /*
- * Return immediately if not a valid mapping
- */
- if (!battable[idx].batu & BAT_Vs)
- return (EINVAL);
-
- /*
- * The BAT entry must be cache-inhibited, guarded, and r/w
- * so it can function as an i/o page
- */
- prot = battable[idx].batl & (BAT_I|BAT_G|BAT_PP_RW);
- if (prot != (BAT_I|BAT_G|BAT_PP_RW))
- return (EPERM);
-
- /*
- * The address should be within the BAT range. Assume that the
- * start address in the BAT has the correct alignment (thus
- * not requiring masking)
- */
- start = battable[idx].batl & BAT_PBS;
- bat_ble = (battable[idx].batu & ~(BAT_EBS)) | 0x03;
- end = start | (bat_ble << 15) | 0x7fff;
-
- if ((pa < start) || ((pa + size) > end))
- return (ERANGE);
-
- return (0);
-}
-
-
-/*
- * Map a set of physical memory pages into the kernel virtual
- * address space. Return a pointer to where it is mapped. This
- * routine is intended to be used for mapping device memory,
- * NOT real memory.
- */
-void *
-pmap_mapdev(vm_offset_t pa, vm_size_t size)
-{
- vm_offset_t va, tmpva, ppa, offset;
- int i;
-
- ppa = trunc_page(pa);
- offset = pa & PAGE_MASK;
- size = roundup(offset + size, PAGE_SIZE);
-
- GIANT_REQUIRED;
-
- /*
- * If the physical address lies within a valid BAT table entry,
- * return the 1:1 mapping. This currently doesn't work
- * for regions that overlap 256M BAT segments.
- */
- for (i = 0; i < 16; i++) {
- if (pmap_bat_mapped(i, pa, size) == 0)
- return ((void *) pa);
- }
-
- va = kmem_alloc_pageable(kernel_map, size);
- if (!va)
- panic("pmap_mapdev: Couldn't alloc kernel virtual memory");
-
- for (tmpva = va; size > 0;) {
- pmap_kenter(tmpva, ppa);
- TLBIE(tmpva); /* XXX or should it be invalidate-all ? */
- size -= PAGE_SIZE;
- tmpva += PAGE_SIZE;
- ppa += PAGE_SIZE;
- }
-
- return ((void *)(va + offset));
-}
-
-void
-pmap_unmapdev(vm_offset_t va, vm_size_t size)
-{
- vm_offset_t base, offset;
-
- /*
- * If this is outside kernel virtual space, then it's a
- * battable entry and doesn't require unmapping
- */
- if ((va >= VM_MIN_KERNEL_ADDRESS) && (va <= VM_MAX_KERNEL_ADDRESS)) {
- base = trunc_page(va);
- offset = va & PAGE_MASK;
- size = roundup(offset + size, PAGE_SIZE);
- kmem_free(kernel_map, base, size);
- }
-}
diff --git a/sys/powerpc/aim/nexus.c b/sys/powerpc/aim/nexus.c
deleted file mode 100644
index 7472bbeac881..000000000000
--- a/sys/powerpc/aim/nexus.c
+++ /dev/null
@@ -1,405 +0,0 @@
-/*
- * Copyright 1998 Massachusetts Institute of Technology
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby
- * granted, provided that both the above copyright notice and this
- * permission notice appear in all copies, that both the above
- * copyright notice and this permission notice appear in all
- * supporting documentation, and that the name of M.I.T. not be used
- * in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission. M.I.T. makes
- * no representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied
- * warranty.
- *
- * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
- * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
- * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-/*-
- * Copyright 2001 by Thomas Moestl <tmm@FreeBSD.org>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: FreeBSD: src/sys/i386/i386/nexus.c,v 1.43 2001/02/09
- *
- * $FreeBSD$
- */
-#include "opt_psim.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/cons.h>
-#include <sys/kernel.h>
-#include <sys/malloc.h>
-
-#include <dev/ofw/openfirm.h>
-
-#include <machine/bus.h>
-#include <machine/frame.h>
-#include <machine/intr_machdep.h>
-#include <machine/nexusvar.h>
-#include <machine/resource.h>
-
-#include <sys/rman.h>
-
-#include "pic_if.h"
-
-/*
- * The nexus (which is a pseudo-bus actually) iterates over the nodes that
- * exist in OpenFirmware and adds them as devices to this bus so that drivers
- * can be attached to them.
- *
- * Maybe this code should get into dev/ofw to some extent, as some of it should
- * work for all OpenFirmware based machines...
- */
-
-static MALLOC_DEFINE(M_NEXUS, "nexus", "nexus device information");
-
-struct nexus_devinfo {
- phandle_t ndi_node;
- /* Some common properties. */
- char *ndi_name;
- char *ndi_device_type;
- char *ndi_compatible;
-};
-
-struct nexus_softc {
- device_t sc_pic;
-};
-
-/*
- * Device interface
- */
-static int nexus_probe(device_t);
-static void nexus_probe_nomatch(device_t, device_t);
-
-/*
- * Bus interface
- */
-static int nexus_read_ivar(device_t, device_t, int, uintptr_t *);
-static int nexus_write_ivar(device_t, device_t, int, uintptr_t);
-static int nexus_setup_intr(device_t, device_t, struct resource *, int,
- driver_intr_t *, void *, void **);
-static int nexus_teardown_intr(device_t, device_t, struct resource *,
- void *);
-static struct resource *nexus_alloc_resource(device_t, device_t, int, int *,
- u_long, u_long, u_long, u_int);
-static int nexus_activate_resource(device_t, device_t, int, int,
- struct resource *);
-static int nexus_deactivate_resource(device_t, device_t, int, int,
- struct resource *);
-static int nexus_release_resource(device_t, device_t, int, int,
- struct resource *);
-
-/*
- * Local routines
- */
-static device_t create_device_from_node(device_t, phandle_t);
-
-static device_method_t nexus_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, nexus_probe),
- DEVMETHOD(device_attach, bus_generic_attach),
- DEVMETHOD(device_detach, bus_generic_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /* Bus interface. Resource management is business of the children... */
- DEVMETHOD(bus_print_child, bus_generic_print_child),
- DEVMETHOD(bus_probe_nomatch, nexus_probe_nomatch),
- DEVMETHOD(bus_read_ivar, nexus_read_ivar),
- DEVMETHOD(bus_write_ivar, nexus_write_ivar),
- DEVMETHOD(bus_setup_intr, nexus_setup_intr),
- DEVMETHOD(bus_teardown_intr, nexus_teardown_intr),
- DEVMETHOD(bus_alloc_resource, nexus_alloc_resource),
- DEVMETHOD(bus_activate_resource, nexus_activate_resource),
- DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource),
- DEVMETHOD(bus_release_resource, nexus_release_resource),
-
- { 0, 0 }
-};
-
-static driver_t nexus_driver = {
- "nexus",
- nexus_methods,
- sizeof(struct nexus_softc),
-};
-
-static devclass_t nexus_devclass;
-
-DRIVER_MODULE(nexus, root, nexus_driver, nexus_devclass, 0, 0);
-
-static int
-nexus_probe(device_t dev)
-{
- phandle_t root;
- phandle_t pic, cpus, child, new_node, temp_node;
- struct nexus_softc *sc;
-
- if ((root = OF_peer(0)) == -1)
- panic("nexus_probe: OF_peer failed.");
-
- sc = device_get_softc(dev);
-
- if ((cpus = OF_finddevice("/cpus")) != -1) {
- for (child = OF_child(cpus); child; child = OF_peer(child))
- (void)create_device_from_node(dev, child);
- }
-
- if ((child = OF_finddevice("/chosen")) == -1)
- printf("nexus_probe: can't find /chosen");
-
- if (OF_getprop(child, "interrupt-controller", &pic, 4) != 4)
-#ifndef PSIM
- printf("nexus_probe: can't get interrupt-controller");
-#else
- pic = OF_finddevice("/iobus/opic");
-#endif
-
- sc->sc_pic = create_device_from_node(dev, pic);
-
- if (sc->sc_pic == NULL)
- printf("nexus_probe: failed to create PIC device");
-
- child = root;
- while (child != 0) {
- if (child != pic)
- (void)create_device_from_node(dev, child);
-
- if (child == cpus)
- new_node = 0;
- else
- new_node = OF_child(child);
- if (new_node == -1)
- panic("nexus_probe: OF_child returned -1");
- if (new_node == 0)
- new_node = OF_peer(child);
- if (new_node == 0) {
- temp_node = child;
- while (new_node == 0) {
- temp_node = OF_parent(temp_node);
- if (temp_node == 0)
- break;
- new_node = OF_peer(temp_node);
- }
- }
- child = new_node;
- }
- device_set_desc(dev, "OpenFirmware Nexus device");
-
- return (0);
-}
-
-static void
-nexus_probe_nomatch(device_t dev, device_t child)
-{
- char *name, *type;
-
- if (BUS_READ_IVAR(dev, child, NEXUS_IVAR_NAME,
- (uintptr_t *)&name) != 0 ||
- BUS_READ_IVAR(dev, child, NEXUS_IVAR_DEVICE_TYPE,
- (uintptr_t *)&type) != 0)
- return;
-
- if (type == NULL)
- type = "(unknown)";
-#if 0
- device_printf(dev, "<%s>, type %s (no driver attached)\n",
- name, type);
-#endif
-}
-
-static int
-nexus_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
-{
- struct nexus_devinfo *dinfo;
-
- if ((dinfo = device_get_ivars(child)) == 0)
- return (ENOENT);
- switch (which) {
- case NEXUS_IVAR_NODE:
- *result = dinfo->ndi_node;
- break;
- case NEXUS_IVAR_NAME:
- *result = (uintptr_t)dinfo->ndi_name;
- break;
- case NEXUS_IVAR_DEVICE_TYPE:
- *result = (uintptr_t)dinfo->ndi_device_type;
- break;
- case NEXUS_IVAR_COMPATIBLE:
- *result = (uintptr_t)dinfo->ndi_compatible;
- break;
- default:
- return (ENOENT);
- }
- return 0;
-}
-
-static int
-nexus_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
-{
- struct nexus_devinfo *dinfo;
-
- if ((dinfo = device_get_ivars(child)) == 0)
- return (ENOENT);
-
- switch (which) {
- case NEXUS_IVAR_NODE:
- case NEXUS_IVAR_NAME:
- case NEXUS_IVAR_DEVICE_TYPE:
- return (EINVAL);
- default:
- return (ENOENT);
- }
- return 0;
-}
-
-static int
-nexus_setup_intr(device_t dev, device_t child, struct resource *res, int flags,
- driver_intr_t *intr, void *arg, void **cookiep)
-{
- struct nexus_softc *sc;
-
- sc = device_get_softc(dev);
-
- if (device_get_state(sc->sc_pic) != DS_ATTACHED)
- panic("nexus_setup_intr: no pic attached\n");
-
- return (PIC_SETUP_INTR(sc->sc_pic, child, res, flags, intr, arg,
- cookiep));
-}
-
-static int
-nexus_teardown_intr(device_t dev, device_t child, struct resource *res,
- void *ih)
-{
- struct nexus_softc *sc;
-
- sc = device_get_softc(dev);
-
- if (device_get_state(sc->sc_pic) != DS_ATTACHED)
- panic("nexus_teardown_intr: no pic attached\n");
-
- return (PIC_TEARDOWN_INTR(sc->sc_pic, child, res, ih));
-}
-
-/*
- * Allocate resources at the behest of a child. This only handles interrupts,
- * since I/O resources are handled by child busses.
- */
-static struct resource *
-nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
- u_long start, u_long end, u_long count, u_int flags)
-{
- struct nexus_softc *sc;
- struct resource *rv;
-
- sc = device_get_softc(bus);
-
- if (type != SYS_RES_IRQ) {
- device_printf(bus, "unknown resource request from %s\n",
- device_get_nameunit(child));
- return (NULL);
- }
-
- if (device_get_state(sc->sc_pic) != DS_ATTACHED)
- panic("nexus_alloc_resource: no pic attached\n");
-
- rv = PIC_ALLOCATE_INTR(sc->sc_pic, child, rid, start, flags);
-
- return (rv);
-}
-
-static int
-nexus_activate_resource(device_t bus, device_t child, int type, int rid,
- struct resource *res)
-{
-
- /* Not much to be done yet... */
- return (rman_activate_resource(res));
-}
-
-static int
-nexus_deactivate_resource(device_t bus, device_t child, int type, int rid,
- struct resource *res)
-{
-
- /* Not much to be done yet... */
- return (rman_deactivate_resource(res));
-}
-
-static int
-nexus_release_resource(device_t bus, device_t child, int type, int rid,
- struct resource *res)
-{
- struct nexus_softc *sc;
-
- sc = device_get_softc(bus);
-
- if (type != SYS_RES_IRQ) {
- device_printf(bus, "unknown resource request from %s\n",
- device_get_nameunit(child));
- return (NULL);
- }
-
- if (device_get_state(sc->sc_pic) != DS_ATTACHED)
- panic("nexus_release_resource: no pic attached\n");
-
- return (PIC_RELEASE_INTR(sc->sc_pic, child, rid, res));
-}
-
-static device_t
-create_device_from_node(device_t parent, phandle_t node)
-{
- device_t cdev;
- struct nexus_devinfo *dinfo;
- char *name, *type, *compatible;
-
- OF_getprop_alloc(node, "name", 1, (void **)&name);
- OF_getprop_alloc(node, "device_type", 1, (void **)&type);
- OF_getprop_alloc(node, "compatible", 1, (void **)&compatible);
- cdev = device_add_child(parent, NULL, -1);
- if (cdev != NULL) {
- dinfo = malloc(sizeof(*dinfo), M_NEXUS, M_WAITOK);
- dinfo->ndi_node = node;
- dinfo->ndi_name = name;
- dinfo->ndi_device_type = type;
- dinfo->ndi_compatible = compatible;
- device_set_ivars(cdev, dinfo);
- } else
- free(name, M_OFWPROP);
-
- return (cdev);
-}
diff --git a/sys/powerpc/aim/ofw_machdep.c b/sys/powerpc/aim/ofw_machdep.c
deleted file mode 100644
index 0111098afed9..000000000000
--- a/sys/powerpc/aim/ofw_machdep.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright (C) 1996 Wolfgang Solfrank.
- * Copyright (C) 1996 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $NetBSD: ofw_machdep.c,v 1.5 2000/05/23 13:25:43 tsubai Exp $
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/bus.h>
-#include <sys/systm.h>
-#include <sys/conf.h>
-#include <sys/disk.h>
-#include <sys/disklabel.h>
-#include <sys/fcntl.h>
-#include <sys/malloc.h>
-#include <sys/stat.h>
-
-#include <net/ethernet.h>
-
-#include <dev/ofw/openfirm.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/vm_page.h>
-
-#include <machine/powerpc.h>
-#include <machine/ofw_machdep.h>
-#include <powerpc/ofw/ofw_pci.h>
-
-#define OFMEM_REGIONS 32
-static struct mem_region OFmem[OFMEM_REGIONS + 1], OFavail[OFMEM_REGIONS + 3];
-
-extern long ofmsr;
-extern struct pmap ofw_pmap;
-extern int pmap_bootstrapped;
-static int (*ofwcall)(void *);
-
-/*
- * This is called during powerpc_init, before the system is really initialized.
- * It shall provide the total and the available regions of RAM.
- * Both lists must have a zero-size entry as terminator.
- * The available regions need not take the kernel into account, but needs
- * to provide space for two additional entry beyond the terminating one.
- */
-void
-mem_regions(struct mem_region **memp, int *memsz,
- struct mem_region **availp, int *availsz)
-{
- int phandle;
- int asz, msz;
-
- /*
- * Get memory.
- */
- if ((phandle = OF_finddevice("/memory")) == -1
- || (msz = OF_getprop(phandle, "reg",
- OFmem, sizeof OFmem[0] * OFMEM_REGIONS))
- <= 0
- || (asz = OF_getprop(phandle, "available",
- OFavail, sizeof OFavail[0] * OFMEM_REGIONS))
- <= 0)
- panic("no memory?");
- *memp = OFmem;
- *memsz = msz / sizeof(struct mem_region);
- *availp = OFavail;
- *availsz = asz / sizeof(struct mem_region);
-}
-
-void
-set_openfirm_callback(int (*openfirm)(void *))
-{
-
- ofwcall = openfirm;
-}
-
-int
-openfirmware(void *args)
-{
- long oldmsr;
- int result;
- u_int srsave[16];
- u_int i;
-
- __asm __volatile( "\t"
- "sync\n\t"
- "mfmsr %0\n\t"
- "mtmsr %1\n\t"
- "isync\n"
- : "=r" (oldmsr)
- : "r" (ofmsr)
- );
-
- if (pmap_bootstrapped) {
- /*
- * Swap the kernel's address space with OpenFirmware's
- */
- for (i = 0; i < 16; i++) {
- srsave[i] = mfsrin(i << ADDR_SR_SHFT);
- mtsrin(i << ADDR_SR_SHFT, ofw_pmap.pm_sr[i]);
- }
-
- /*
- * Clear battable[] translations
- */
- __asm __volatile("mtdbatu 2, %0\n"
- "mtdbatu 3, %0" : : "r" (0));
- isync();
- }
-
- result = ofwcall(args);
-
- if (pmap_bootstrapped) {
- /*
- * Restore the kernel's addr space. The isync() doesn;t
- * work outside the loop unless mtsrin() is open-coded
- * in an asm statement :(
- */
- for (i = 0; i < 16; i++) {
- mtsrin(i << ADDR_SR_SHFT, srsave[i]);
- isync();
- }
- }
-
- __asm( "\t"
- "mtmsr %0\n\t"
- "isync\n"
- : : "r" (oldmsr)
- );
-
- return (result);
-}
-
-void
-ppc_exit()
-{
-
- OF_exit();
-}
-
-void
-ppc_boot(str)
- char *str;
-{
-
- OF_boot(str);
-}
-
-void
-OF_getetheraddr(device_t dev, u_char *addr)
-{
- phandle_t node;
-
- node = ofw_pci_find_node(dev);
- OF_getprop(node, "local-mac-address", addr, ETHER_ADDR_LEN);
-}
diff --git a/sys/powerpc/aim/ofwmagic.S b/sys/powerpc/aim/ofwmagic.S
deleted file mode 100644
index 033a5fe98348..000000000000
--- a/sys/powerpc/aim/ofwmagic.S
+++ /dev/null
@@ -1,75 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD: ofwmagic.S,v 1.2 1997/10/09 08:38:18 jtc Exp $ */
-
-/*-
- * Copyright (c) 1997 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Jason R. Thorpe.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Magic note section used by OpenFirmware.
- */
-
- .section ".note"
-
- /*# note header */
-
- /*# length of name */
- .long 8
-
- /*# note descriptor size */
- .long 20
-
- /*# note type (IEEE 1275) */
- .long 0x1275
-
- /*# name of owner */
- .asciz "PowerPC"
- .balign 4
-
-
- /*# note descriptor */
-
- /*# real mode (-1) or virtual mode (0) */
- .long 0
-
- /*# real-base */
- .long -1
- /*# real-size */
- .long -1
-
- /*# virt-base */
- .long -1
- /*# virt-size */
- .long -1
diff --git a/sys/powerpc/aim/swtch.S b/sys/powerpc/aim/swtch.S
deleted file mode 100644
index 49e23c837c34..000000000000
--- a/sys/powerpc/aim/swtch.S
+++ /dev/null
@@ -1,158 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD: locore.S,v 1.24 2000/05/31 05:09:17 thorpej Exp $ */
-
-/*
- * Copyright (C) 2001 Benno Rice
- * 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 Benno Rice ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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) 1995, 1996 Wolfgang Solfrank.
- * Copyright (C) 1995, 1996 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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 "assym.s"
-
-#include <sys/syscall.h>
-
-#include <machine/trap.h>
-#include <machine/param.h>
-#include <machine/sr.h>
-#include <machine/psl.h>
-#include <machine/asm.h>
-
-/*
- * void cpu_switch()
- * Find a runnable thread and switch to it.
- */
-ENTRY(cpu_switch)
- mfsprg %r3,0 /* Get the pcpu pointer */
- lwz %r4,PC_CURTHREAD(%r3) /* Get the current thread */
- lwz %r3,TD_PCB(%r4) /* Get a pointer to the PCB */
-
- mr %r12,%r2
- stmw %r12,PCB_CONTEXT(%r3) /* Save the non-volatile GP regs */
- mr %r14,%r3 /* Copy the current pcb pointer */
- mr %r15,%r4 /* ... and the curthread pointer */
- mfcr %r16 /* Save the condition register */
- stw %r16,PCB_CR(%r3)
- mflr %r16 /* Save the link register */
- stw %r16,PCB_LR(%r3)
- mfsr %r16,USER_SR /* Save USER_SR for copyin/out */
- isync
- stw %r16,PCB_USR(%r3)
- stw %r1,PCB_SP(%r3) /* Save the stack pointer */
-
- lwz %r5,PCB_FLAGS(%r3) /* Save FPU context if needed */
- andi. %r5, %r5, PCB_FPU
- beq .L1
- mr %r3,%r15
- bl save_fpu
-
-.L1:
- bl choosethread /* Find a new thread to run */
- cmplw 0,%r3,%r15 /* Compare to curthread */
- beq .L2 /* If it's the same, we're done */
-
- mr %r16,%r3 /* Save off the (struct thread *) */
-
- mr %r3,%r15
- bl pmap_deactivate /* Deactivate the current pmap */
-
- mr %r3,%r16
- bl pmap_activate /* Activate the new address space */
-
- mfsprg %r4,0 /* Get the pcpu pointer */
- stw %r16,PC_CURTHREAD(%r4) /* Store new current thread */
- mr %r3,%r16 /* and save in r3 */
- lwz %r17,TD_PCB(%r16) /* Store new current PCB */
- stw %r17,PC_CURPCB(%r4)
-
- lwz %r5, PCB_FLAGS(%r17) /* Restore FPU context if needed */
- andi. %r5, %r5, PCB_FPU
- beq .L2
- bl enable_fpu
- mr %r3,%r16 /* Recover new curthread */
-
- /* thread to restore is in r3 */
-.L2:
- lwz %r3, TD_PCB(%r3)
- lmw %r12,PCB_CONTEXT(%r3) /* Load the non-volatile GP regs */
- mr %r2,%r12
- lwz %r5,PCB_CR(%r3) /* Load the condition register */
- mtcr %r5
- lwz %r5,PCB_LR(%r3) /* Load the link register */
- mtlr %r5
- lwz %r5,PCB_USR(%r3) /* Load the USER_SR segment reg */
- mtsr USER_SR,%r5
- isync
- lwz %r1,PCB_SP(%r3) /* Load the stack pointer */
- blr
-
-/*
- * savectx(pcb)
- * Update pcb, saving current processor state
- */
-ENTRY(savectx)
- mr %r12,%r2
- stmw %r12,PCB_CONTEXT(%r3) /* Save the non-volatile GP regs */
- mfcr %r4 /* Save the condition register */
- stw %r4,PCB_CONTEXT(%r3)
- blr
-
-/*
- * fork_trampoline()
- * Set up the return from cpu_fork()
- */
-ENTRY(fork_trampoline)
- lwz %r3,CF_FUNC(%r1)
- lwz %r4,CF_ARG0(%r1)
- lwz %r5,CF_ARG1(%r1)
- bl fork_exit
- addi %r1,%r1,4
- b trapexit
diff --git a/sys/powerpc/aim/trap.c b/sys/powerpc/aim/trap.c
deleted file mode 100644
index ad877640d81f..000000000000
--- a/sys/powerpc/aim/trap.c
+++ /dev/null
@@ -1,659 +0,0 @@
-/*
- * Copyright (C) 1995, 1996 Wolfgang Solfrank.
- * Copyright (C) 1995, 1996 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $NetBSD: trap.c,v 1.58 2002/03/04 04:07:35 dbj Exp $
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_ddb.h"
-#include "opt_ktrace.h"
-
-#include <sys/param.h>
-#include <sys/proc.h>
-#include <sys/ktr.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/pioctl.h>
-#include <sys/reboot.h>
-#include <sys/syscall.h>
-#include <sys/sysent.h>
-#include <sys/systm.h>
-#include <sys/uio.h>
-#include <sys/user.h>
-#ifdef KTRACE
-#include <sys/ktrace.h>
-#endif
-#include <sys/vmmeter.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <vm/vm_extern.h>
-#include <vm/vm_param.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_map.h>
-#include <vm/vm_page.h>
-
-#include <machine/cpu.h>
-#include <machine/db_machdep.h>
-#include <machine/fpu.h>
-#include <machine/frame.h>
-#include <machine/pcb.h>
-#include <machine/pmap.h>
-#include <machine/psl.h>
-#include <machine/trap.h>
-#include <machine/spr.h>
-#include <machine/sr.h>
-
-#include <ddb/ddb.h>
-
-#ifndef MULTIPROCESSOR
-extern int intr_depth;
-#endif
-
-void trap(struct trapframe *);
-
-static void trap_fatal(struct trapframe *frame);
-static void printtrap(u_int vector, struct trapframe *frame, int isfatal,
- int user);
-static int trap_pfault(struct trapframe *frame, int user);
-static int fix_unaligned(struct thread *td, struct trapframe *frame);
-static int handle_onfault(struct trapframe *frame);
-static void syscall(struct trapframe *frame);
-
-static __inline void setusr(u_int);
-
-int setfault(faultbuf); /* defined in locore.S */
-
-/* Why are these not defined in a header? */
-int badaddr(void *, size_t);
-int badaddr_read(void *, size_t, int *);
-
-#ifdef WITNESS
-extern char *syscallnames[];
-#endif
-
-struct powerpc_exception {
- u_int vector;
- char *name;
-};
-
-static struct powerpc_exception powerpc_exceptions[] = {
- { 0x0100, "system reset" },
- { 0x0200, "machine check" },
- { 0x0300, "data storage interrupt" },
- { 0x0400, "instruction storage interrupt" },
- { 0x0500, "external interrupt" },
- { 0x0600, "alignment" },
- { 0x0700, "program" },
- { 0x0800, "floating-point unavailable" },
- { 0x0900, "decrementer" },
- { 0x0c00, "system call" },
- { 0x0d00, "trace" },
- { 0x0e00, "floating-point assist" },
- { 0x0f00, "performance monitoring" },
- { 0x0f20, "altivec unavailable" },
- { 0x1000, "instruction tlb miss" },
- { 0x1100, "data load tlb miss" },
- { 0x1200, "data store tlb miss" },
- { 0x1300, "instruction breakpoint" },
- { 0x1400, "system management" },
- { 0x1600, "altivec assist" },
- { 0x1700, "thermal management" },
- { 0x2000, "run mode/trace" },
- { 0x3000, NULL }
-};
-
-static const char *
-trapname(u_int vector)
-{
- struct powerpc_exception *pe;
-
- for (pe = powerpc_exceptions; pe->vector != 0x3000; pe++) {
- if (pe->vector == vector)
- return (pe->name);
- }
-
- return ("unknown");
-}
-
-void
-trap(struct trapframe *frame)
-{
- struct thread *td;
- struct proc *p;
- int sig, type, user;
- u_int sticks, ucode;
-
- atomic_add_int(&cnt.v_trap, 1);
-
- td = PCPU_GET(curthread);
- p = td->td_proc;
-
- type = ucode = frame->exc;
- sig = 0;
- user = frame->srr1 & PSL_PR;
- sticks = 0;
-
- CTR3(KTR_TRAP, "trap: %s type=%s (%s)", p->p_comm,
- trapname(type), user ? "user" : "kernel");
-
- if (user) {
- sticks = td->td_sticks;
- td->td_frame = frame;
- if (td->td_ucred != p->p_ucred)
- cred_update_thread(td);
-
- /* User Mode Traps */
- switch (type) {
- case EXC_RUNMODETRC:
- case EXC_TRC:
- frame->srr1 &= ~PSL_SE;
- sig = SIGTRAP;
- break;
-
- case EXC_DSI:
- case EXC_ISI:
- sig = trap_pfault(frame, 1);
- break;
-
- case EXC_SC:
- syscall(frame);
- break;
-
- case EXC_FPU:
- KASSERT((td->td_pcb->pcb_flags & PCB_FPU) != PCB_FPU,
- ("FPU already enabled for thread"));
- enable_fpu(td);
- break;
-
-#ifdef ALTIVEC
- case EXC_VEC:
- if ((vecthread = PCPU_GET(vecthread)) != NULL) {
- KASSERT(vecthread != td,
- ("altivec already enabled"));
- save_vec(vecthread);
- }
- PCPU_SET(vecthread, td);
- td->td_pcb->pcb_veccpu = PCPU_GET(cpuid);
- enable_vec(td);
- frame->srr1 |= PSL_VEC;
- break;
-#endif /* ALTIVEC */
-
- case EXC_ALI:
- if (fix_unaligned(td, frame) != 0)
- sig = SIGBUS;
- else
- frame->srr0 += 4;
- break;
-
- case EXC_PGM:
- /* XXX temporarily */
- /* XXX: Magic Number? */
- if (frame->srr1 & 0x0002000)
- sig = SIGTRAP;
- else
- sig = SIGILL;
- break;
-
- default:
- trap_fatal(frame);
- }
- } else {
- /* Kernel Mode Traps */
-
- KASSERT(cold || td->td_ucred != NULL,
- ("kernel trap doesn't have ucred"));
- switch (type) {
- case EXC_DSI:
- if (trap_pfault(frame, 0) == 0)
- return;
- break;
- case EXC_MCHK:
- if (handle_onfault(frame))
- return;
- break;
- default:
- trap_fatal(frame);
- }
- }
-
-#ifdef ALTIVEC
- if (td != PCPU_GET(vecthread) ||
- td->td_pcb->pcb_veccpu != PCPU_GET(cpuid))
- frame->srr1 &= ~PSL_VEC;
-#endif /* ALTIVEC */
-
- if (sig != 0) {
- if (p->p_sysent->sv_transtrap != NULL)
- sig = (p->p_sysent->sv_transtrap)(sig, type);
- trapsignal(td, sig, ucode);
- }
-
- userret(td, frame, sticks);
- mtx_assert(&Giant, MA_NOTOWNED);
-#ifdef DIAGNOSTIC
- cred_free_thread(td);
-#endif /* DIAGNOSTIC */
-}
-
-static void
-trap_fatal(struct trapframe *frame)
-{
-
- printtrap(frame->exc, frame, 1, (frame->srr1 & PSL_PR));
-#ifdef DDB
- if ((debugger_on_panic || db_active) && kdb_trap(frame->exc, frame))
- return;
-#endif
- panic("%s trap", trapname(frame->exc));
-}
-
-static void
-printtrap(u_int vector, struct trapframe *frame, int isfatal, int user)
-{
-
- printf("\n");
- printf("%s %s trap:\n", isfatal ? "fatal" : "handled",
- user ? "user" : "kernel");
- printf("\n");
- printf(" exception = 0x%x (%s)\n", vector >> 8,
- trapname(vector));
- switch (vector) {
- case EXC_DSI:
- printf(" virtual address = 0x%x\n", frame->dar);
- break;
- case EXC_ISI:
- printf(" virtual address = 0x%x\n", frame->srr0);
- break;
- }
- printf(" srr0 = 0x%x\n", frame->srr0);
- printf(" srr1 = 0x%x\n", frame->srr1);
- printf(" curthread = %p\n", curthread);
- if (curthread != NULL)
- printf(" pid = %d, comm = %s\n",
- curthread->td_proc->p_pid, curthread->td_proc->p_comm);
- printf("\n");
-}
-
-/*
- * Handles a fatal fault when we have onfault state to recover. Returns
- * non-zero if there was onfault recovery state available.
- */
-static int
-handle_onfault(struct trapframe *frame)
-{
- struct thread *td;
- faultbuf *fb;
-
- td = curthread;
- fb = td->td_pcb->pcb_onfault;
- if (fb != NULL) {
- frame->srr0 = (*fb)[0];
- frame->fixreg[1] = (*fb)[1];
- frame->fixreg[2] = (*fb)[2];
- frame->cr = (*fb)[3];
- bcopy(&(*fb)[4], &frame->fixreg[13],
- 19 * sizeof(register_t));
- return (1);
- }
- return (0);
-}
-
-void
-syscall(struct trapframe *frame)
-{
- caddr_t params;
- struct sysent *callp;
- struct thread *td;
- struct proc *p;
- int error, n;
- size_t narg;
- register_t args[10];
- u_int code;
-
- td = PCPU_GET(curthread);
- p = td->td_proc;
-
- atomic_add_int(&cnt.v_syscall, 1);
-
- code = frame->fixreg[0];
- params = (caddr_t)(frame->fixreg + FIRSTARG);
- n = NARGREG;
-
- if (p->p_sysent->sv_prepsyscall) {
- /*
- * The prep code is MP aware.
- */
- (*p->p_sysent->sv_prepsyscall)(frame, args, &code, &params);
- } else if (code == SYS_syscall) {
- /*
- * code is first argument,
- * followed by actual args.
- */
- code = *(u_int *) params;
- params += sizeof(register_t);
- n -= 1;
- } else if (code == SYS___syscall) {
- /*
- * Like syscall, but code is a quad,
- * so as to maintain quad alignment
- * for the rest of the args.
- */
- params += sizeof(register_t);
- code = *(u_int *) params;
- params += sizeof(register_t);
- n -= 2;
- }
-
- if (p->p_sysent->sv_mask)
- code &= p->p_sysent->sv_mask;
-
- if (code >= p->p_sysent->sv_size)
- callp = &p->p_sysent->sv_table[0];
- else
- callp = &p->p_sysent->sv_table[code];
-
- narg = callp->sy_narg & SYF_ARGMASK;
-
- if (narg > n) {
- bcopy(params, args, n * sizeof(register_t));
- error = copyin(MOREARGS(frame->fixreg[1]), args + n,
- (narg - n) * sizeof(register_t));
- params = (caddr_t)args;
- } else
- error = 0;
-
-#ifdef KTRACE
- if (KTRPOINT(td, KTR_SYSCALL))
- ktrsyscall(code, narg, (register_t *)params);
-#endif
- /*
- * Try to run the syscall without Giant if the syscall is MP safe.
- */
- if ((callp->sy_narg & SYF_MPSAFE) == 0)
- mtx_lock(&Giant);
-
- if (error == 0) {
- td->td_retval[0] = 0;
- td->td_retval[1] = frame->fixreg[FIRSTARG + 1];
-
- STOPEVENT(p, S_SCE, narg);
-
- error = (*callp->sy_call)(td, params);
- }
- switch (error) {
- case 0:
- if ((frame->fixreg[0] == SYS___syscall) &&
- (code != SYS_lseek)) {
- /*
- * 64-bit return, 32-bit syscall. Fixup byte order
- */
- frame->fixreg[FIRSTARG] = 0;
- frame->fixreg[FIRSTARG + 1] = td->td_retval[0];
- } else {
- frame->fixreg[FIRSTARG] = td->td_retval[0];
- frame->fixreg[FIRSTARG + 1] = td->td_retval[1];
- }
- /* XXX: Magic number */
- frame->cr &= ~0x10000000;
- break;
- case ERESTART:
- /*
- * Set user's pc back to redo the system call.
- */
- frame->srr0 -= 4;
- break;
- case EJUSTRETURN:
- /* nothing to do */
- break;
- default:
- if (p->p_sysent->sv_errsize) {
- if (error >= p->p_sysent->sv_errsize)
- error = -1; /* XXX */
- else
- error = p->p_sysent->sv_errtbl[error];
- }
- frame->fixreg[FIRSTARG] = error;
- /* XXX: Magic number: Carry Flag Equivalent? */
- frame->cr |= 0x10000000;
- break;
- }
-
-
- if ((callp->sy_narg & SYF_MPSAFE) == 0)
- mtx_unlock(&Giant);
-
-#ifdef KTRACE
- if (KTRPOINT(td, KTR_SYSRET))
- ktrsysret(code, error, td->td_retval[0]);
-#endif
-
- /*
- * Does the comment in the i386 code about errno apply here?
- */
- STOPEVENT(p, S_SCX, code);
-
- WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning",
- (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???");
- mtx_assert(&sched_lock, MA_NOTOWNED);
- mtx_assert(&Giant, MA_NOTOWNED);
-}
-
-static int
-trap_pfault(struct trapframe *frame, int user)
-{
- vm_offset_t eva, va;
- struct thread *td;
- struct proc *p;
- vm_map_t map;
- vm_prot_t ftype;
- int rv;
- u_int user_sr;
-
- td = curthread;
- p = td->td_proc;
- if (frame->exc == EXC_ISI) {
- eva = frame->srr0;
- ftype = VM_PROT_READ | VM_PROT_EXECUTE;
- } else {
- eva = frame->dar;
- if (frame->dsisr & DSISR_STORE)
- ftype = VM_PROT_WRITE;
- else
- ftype = VM_PROT_READ;
- }
-
- if (user) {
- map = &p->p_vmspace->vm_map;
- } else {
- if ((eva >> ADDR_SR_SHFT) == USER_SR) {
- if (p->p_vmspace == NULL)
- return (SIGSEGV);
-
- __asm ("mfsr %0, %1"
- : "=r"(user_sr)
- : "K"(USER_SR));
- eva &= ADDR_PIDX | ADDR_POFF;
- eva |= user_sr << ADDR_SR_SHFT;
- map = &p->p_vmspace->vm_map;
- } else {
- map = kernel_map;
- }
- }
- va = trunc_page(eva);
-
- mtx_lock(&Giant);
- if (map != kernel_map) {
- /*
- * Keep swapout from messing with us during this
- * critical time.
- */
- PROC_LOCK(p);
- ++p->p_lock;
- PROC_UNLOCK(p);
-
- /* Fault in the user page: */
- rv = vm_fault(map, va, ftype,
- (ftype & VM_PROT_WRITE) ? VM_FAULT_DIRTY
- : VM_FAULT_NORMAL);
-
- PROC_LOCK(p);
- --p->p_lock;
- PROC_UNLOCK(p);
- } else {
- /*
- * Don't have to worry about process locking or stacks in the
- * kernel.
- */
- rv = vm_fault(map, va, ftype, VM_FAULT_NORMAL);
- }
- mtx_unlock(&Giant);
-
- if (rv == KERN_SUCCESS)
- return (0);
-
- if (!user && handle_onfault(frame))
- return (0);
-
- return (SIGSEGV);
-}
-
-static __inline void
-setusr(u_int content)
-{
- __asm __volatile ("isync; mtsr %0,%1; isync"
- :: "n"(USER_SR), "r"(content));
-}
-
-int
-badaddr(void *addr, size_t size)
-{
- return (badaddr_read(addr, size, NULL));
-}
-
-int
-badaddr_read(void *addr, size_t size, int *rptr)
-{
- struct thread *td;
- faultbuf env;
- int x;
-
- /* Get rid of any stale machine checks that have been waiting. */
- __asm __volatile ("sync; isync");
-
- td = PCPU_GET(curthread);
-
- if (setfault(env)) {
- td->td_pcb->pcb_onfault = 0;
- __asm __volatile ("sync");
- return 1;
- }
-
- __asm __volatile ("sync");
-
- switch (size) {
- case 1:
- x = *(volatile int8_t *)addr;
- break;
- case 2:
- x = *(volatile int16_t *)addr;
- break;
- case 4:
- x = *(volatile int32_t *)addr;
- break;
- default:
- panic("badaddr: invalid size (%d)", size);
- }
-
- /* Make sure we took the machine check, if we caused one. */
- __asm __volatile ("sync; isync");
-
- td->td_pcb->pcb_onfault = 0;
- __asm __volatile ("sync"); /* To be sure. */
-
- /* Use the value to avoid reorder. */
- if (rptr)
- *rptr = x;
-
- return (0);
-}
-
-/*
- * For now, this only deals with the particular unaligned access case
- * that gcc tends to generate. Eventually it should handle all of the
- * possibilities that can happen on a 32-bit PowerPC in big-endian mode.
- */
-
-static int
-fix_unaligned(struct thread *td, struct trapframe *frame)
-{
- struct thread *fputhread;
- int indicator, reg;
- double *fpr;
-
- indicator = EXC_ALI_OPCODE_INDICATOR(frame->dsisr);
-
- switch (indicator) {
- case EXC_ALI_LFD:
- case EXC_ALI_STFD:
- reg = EXC_ALI_RST(frame->dsisr);
- fpr = &td->td_pcb->pcb_fpu.fpr[reg];
- fputhread = PCPU_GET(fputhread);
-
- /* Juggle the FPU to ensure that we've initialized
- * the FPRs, and that their current state is in
- * the PCB.
- */
- if (fputhread != td) {
- if (fputhread)
- save_fpu(fputhread);
- enable_fpu(td);
- }
- save_fpu(td);
-
- if (indicator == EXC_ALI_LFD) {
- if (copyin((void *)frame->dar, fpr,
- sizeof(double)) != 0)
- return -1;
- enable_fpu(td);
- } else {
- if (copyout(fpr, (void *)frame->dar,
- sizeof(double)) != 0)
- return -1;
- }
- return 0;
- break;
- }
-
- return -1;
-}
diff --git a/sys/powerpc/aim/trap_subr.S b/sys/powerpc/aim/trap_subr.S
deleted file mode 100644
index 624272f55e75..000000000000
--- a/sys/powerpc/aim/trap_subr.S
+++ /dev/null
@@ -1,948 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD: trap_subr.S,v 1.20 2002/04/22 23:20:08 kleink Exp $ */
-
-/*
- * Copyright (C) 1995, 1996 Wolfgang Solfrank.
- * Copyright (C) 1995, 1996 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * NOTICE: This is not a standalone file. to use it, #include it in
- * your port's locore.S, like so:
- *
- * #include <powerpc/powerpc/trap_subr.S>
- */
-
-/*
- * XXX Fake AST trap vector. This is here until we work out how to safely
- * remove the AST code.
- */
-#define EXC_AST 0x3000
- .data
- .align 4
-cpassert:
- .asciz "attempting to return from kernel with no current pmap"
-
-/*
- * Data used during primary/secondary traps/interrupts
- */
-#define tempsave EXC_MCHK+0xe0 /* primary save area for trap handling */
-#define disisave EXC_DSI+0xe0 /* primary save area for dsi/isi traps */
-
-/*
- * XXX Interrupt and spill stacks need to be per-CPU.
- */
- .data
- .align 4
-intstk:
- .space INTSTK /* interrupt stack */
-
-GLOBAL(intr_depth)
- .long -1 /* in-use marker */
-
- .comm spillstk,SPILLSTK,8
-
-/*
- * This code gets copied to all the trap vectors
- * (except ISI/DSI, ALI, the interrupts, and possibly the debugging
- * traps when using IPKDB).
- */
- .text
- .globl CNAME(trapcode),CNAME(trapsize)
-CNAME(trapcode):
- mtsprg 1,1 /* save SP */
- stmw 28,tempsave(0) /* free r28-r31 */
- mflr 28 /* save LR */
- mfcr 29 /* save CR */
-/* Test whether we already had PR set */
- mfsrr1 31
- mtcr 31
- bc 4,17,1f /* branch if PSL_PR is clear */
- mfsprg 31,0
- lwz 1,PC_CURPCB(31)
-1:
- bla s_trap
-CNAME(trapsize) = .-CNAME(trapcode)
-
-/*
- * For ALI: has to save DSISR and DAR
- */
- .globl CNAME(alitrap),CNAME(alisize)
-CNAME(alitrap):
- mtsprg 1,1 /* save SP */
- stmw 28,tempsave(0) /* free r28-r31 */
- mfdar 30
- mfdsisr 31
- stmw 30,tempsave+16(0)
- mflr 28 /* save LR */
- mfcr 29 /* save CR */
-/* Test whether we already had PR set */
- mfsrr1 31
- mtcr 31
- bc 4,17,1f /* branch if PSL_PR is clear */
- mfsprg 31,0
- lwz 1,PC_CURPCB(31)
-1:
- bla s_trap
-CNAME(alisize) = .-CNAME(alitrap)
-
-/*
- * Similar to the above for DSI
- * Has to handle BAT spills
- * and standard pagetable spills
- */
- .globl CNAME(dsitrap),CNAME(dsisize)
-CNAME(dsitrap):
- stmw 28,disisave(0) /* free r28-r31 */
- mfcr 29 /* save CR */
- mfxer 30 /* save XER */
- mtsprg 2,30 /* in SPRG2 */
- mfsrr1 31 /* test kernel mode */
- mtcr 31
- bc 12,17,1f /* branch if PSL_PR is set */
- mfdar 31 /* get fault address */
- rlwinm 31,31,7,25,28 /* get segment * 8 */
-
- /* get batu */
- addis 31,31,CNAME(battable)@ha
- lwz 30,CNAME(battable)@l(31)
- mtcr 30
- bc 4,30,1f /* branch if supervisor valid is
- false */
- /* get batl */
- lwz 31,CNAME(battable)+4@l(31)
-/* We randomly use the highest two bat registers here */
- mftb 28
- andi. 28,28,1
- bne 2f
- mtdbatu 2,30
- mtdbatl 2,31
- b 3f
-2:
- mtdbatu 3,30
- mtdbatl 3,31
-3:
- mfsprg 30,2 /* restore XER */
- mtxer 30
- mtcr 29 /* restore CR */
- lmw 28,disisave(0) /* restore r28-r31 */
- rfi /* return to trapped code */
-1:
- mflr 28 /* save LR */
- bla s_dsitrap
-CNAME(dsisize) = .-CNAME(dsitrap)
-
-/*
- * Dedicated MPC601 version of the above.
- * Considers different BAT format and combined implementation
- * (being addressed as I-BAT).
- */
- .globl CNAME(dsitrap601),CNAME(dsi601size)
-CNAME(dsitrap601):
- stmw 28,disisave(0) /* free r28-r31 */
- mfcr 29 /* save CR */
- mfxer 30 /* save XER */
- mtsprg 2,30 /* in SPRG2 */
- mfsrr1 31 /* test kernel mode */
- mtcr 31
- bc 12,17,1f /* branch if PSL_PR is set */
- mfdar 31 /* get fault address */
- rlwinm 31,31,12,20,28 /* get "segment" battable offset */
-
- /* get batl */
- addis 31,31,CNAME(battable)@ha
- lwz 30,CNAME(battable)+4@l(31)
- mtcr 30
- bc 4,25,1f /* branch if Valid is is false,
- presently assumes supervisor only */
-
- /* get batu */
- lwz 31,CNAME(battable)@l(31)
-/* We randomly use the highest two bat registers here */
- mfspr 28,SPR_RTCL_R
- andi. 28,28,128
- bne 2f
- mtibatu 2,31
- mtibatl 2,30
- b 3f
-2:
- mtibatu 3,31
- mtibatl 3,30
-3:
- mfsprg 30,2 /* restore XER */
- mtxer 30
- mtcr 29 /* restore CR */
- lmw 28,disisave(0) /* restore r28-r31 */
- rfi /* return to trapped code */
-1:
- mflr 28 /* save LR */
- bla s_dsitrap
-CNAME(dsi601size) = .-CNAME(dsitrap601)
-
-/*
- * Similar to the above for ISI
- */
- .globl CNAME(isitrap),CNAME(isisize)
-CNAME(isitrap):
- stmw 28,disisave(0) /* free r28-r31 */
- mflr 28 /* save LR */
- mfcr 29 /* save CR */
- mfsrr1 31 /* test kernel mode */
- mtcr 31
- bc 12,17,1f /* branch if PSL_PR is set */
- mfsrr0 31 /* get fault address */
- rlwinm 31,31,7,25,28 /* get segment * 8 */
-
- /* get batu */
- addis 31,31,CNAME(battable)@ha
- lwz 30,CNAME(battable)@l(31)
- mtcr 30
- bc 4,30,1f /* branch if supervisor valid is
- false */
- mtibatu 3,30
-
- /* get batl */
- lwz 30,CNAME(battable)+4@l(31)
- mtibatl 3,30
-
- mtcr 29 /* restore CR */
- lmw 28,disisave(0) /* restore r28-r31 */
- rfi /* return to trapped code */
-1:
- bla s_isitrap
-CNAME(isisize)= .-CNAME(isitrap)
-
-/*
- * Dedicated MPC601 version of the above.
- * Considers different BAT format.
- */
- .globl CNAME(isitrap601),CNAME(isi601size)
-CNAME(isitrap601):
- stmw 28,disisave(0) /* free r28-r31 */
- mflr 28 /* save LR */
- mfcr 29 /* save CR */
- mfsrr1 31 /* test kernel mode */
- mtcr 31
- bc 12,17,1f /* branch if PSL_PR is set */
- mfsrr0 31 /* get fault address */
- rlwinm 31,31,12,20,28 /* get "segment" battable offset */
-
- /* get batl */
- addis 31,31,CNAME(battable)@ha
- lwz 30,CNAME(battable)+4@l(31)
- mtcr 30
- bc 4,25,1f /* branch if Valid is is false,
- presently assumes supervisor only */
- /* get batu */
- lwz 31,CNAME(battable)@l(31)
-
- mtibatu 3,31
- mtibatl 3,30
-
- mtcr 29 /* restore CR */
- lmw 28,disisave(0) /* restore r28-r31 */
- rfi /* return to trapped code */
-1:
- bla s_isitrap
-CNAME(isi601size)= .-CNAME(isitrap601)
-
-/*
- * Now the tlb software load for 603 processors:
- * (Code essentially from the 603e User Manual, Chapter 5, but
- * corrected a lot.)
- */
-
- .globl CNAME(tlbimiss),CNAME(tlbimsize)
-CNAME(tlbimiss):
-#ifdef PMAPDEBUG
- mfspr 2,SPR_IMISS /* exception address */
- li 1,24 /* get rid of the lower */
- srw 2,2,1 /* 24 bits */
- li 1,1 /* Load 1 */
- cmpl 2,1,1 /* is it > 16MB */
- blt 99f /* nope, skip saving these SPRs */
- li 1,0xc0 /* arbitrary */
- mfspr 2,SPR_HASH1
- stw 2,0(1)
- mfspr 2,SPR_HASH2
- stw 2,4(1)
- mfspr 2,SPR_IMISS
- stw 2,8(1)
- mfspr 2,SPR_ICMP
- stw 2,12(1)
-99:
-#endif /* PMAPDEBUG */
- mfspr 2,SPR_HASH1 /* get first pointer */
- li 1,8
- mfctr 0 /* save counter */
- mfspr 3,SPR_ICMP /* get first compare value */
- addi 2,2,-8 /* predec pointer */
-1:
- mtctr 1 /* load counter */
-2:
- lwzu 1,8(2) /* get next pte */
- cmpl 0,1,3 /* see if found pte */
- bdneq 2b /* loop if not eq */
- bne 3f /* not found */
- lwz 1,4(2) /* load tlb entry lower word */
- andi. 3,1,8 /* check G-bit */
- bne 4f /* if guarded, take ISI */
- mtctr 0 /* restore counter */
- mfspr 0,SPR_IMISS /* get the miss address for the tlbli */
- mfsrr1 3 /* get the saved cr0 bits */
- mtcrf 0x80,3 /* and restore */
- ori 1,1,0x100 /* set the reference bit */
- mtspr SPR_RPA,1 /* set the pte */
- srwi 1,1,8 /* get byte 7 of pte */
- tlbli 0 /* load the itlb */
- stb 1,6(2) /* update page table */
- rfi
-
-3: /* not found in pteg */
- andi. 1,3,0x40 /* have we already done second hash? */
- bne 5f
- mfspr 2,SPR_HASH2 /* get the second pointer */
- ori 3,3,0x40 /* change the compare value */
- li 1,8
- addi 2,2,-8 /* predec pointer */
- b 1b
-4: /* guarded */
- mfsrr1 3
- andi. 2,3,0xffff /* clean upper srr1 */
- oris 2,2,0x8000000@h /* set srr<4> to flag prot violation */
- b 6f
-5: /* not found anywhere */
- mfsrr1 3
- andi. 2,3,0xffff /* clean upper srr1 */
- oris 2,2,0x40000000@h /* set srr1<1> to flag pte not found */
-6:
- mtctr 0 /* restore counter */
- mtsrr1 2
- mfmsr 0
- xoris 0,0,0x20000@h /* flip the msr<tgpr> bit */
- mtcrf 0x80,3 /* restore cr0 */
- mtmsr 0 /* now with native gprs */
- isync
- ba EXC_ISI
-CNAME(tlbimsize) = .-CNAME(tlbimiss)
-
- .globl CNAME(tlbdlmiss),CNAME(tlbdlmsize)
-CNAME(tlbdlmiss):
- mfspr 2,SPR_HASH1 /* get first pointer */
- li 1,8
- mfctr 0 /* save counter */
- mfspr 3,SPR_DCMP /* get first compare value */
- addi 2,2,-8 /* predec pointer */
-1:
- mtctr 1 /* load counter */
-2:
- lwzu 1,8(2) /* get next pte */
- cmpl 0,1,3 /* see if found pte */
- bdneq 2b /* loop if not eq */
- bne 3f /* not found */
- lwz 1,4(2) /* load tlb entry lower word */
- mtctr 0 /* restore counter */
- mfspr 0,SPR_DMISS /* get the miss address for the tlbld */
- mfsrr1 3 /* get the saved cr0 bits */
- mtcrf 0x80,3 /* and restore */
- ori 1,1,0x100 /* set the reference bit */
- mtspr SPR_RPA,1 /* set the pte */
- srwi 1,1,8 /* get byte 7 of pte */
- tlbld 0 /* load the dtlb */
- stb 1,6(2) /* update page table */
- rfi
-
-3: /* not found in pteg */
- andi. 1,3,0x40 /* have we already done second hash? */
- bne 5f
- mfspr 2,SPR_HASH2 /* get the second pointer */
- ori 3,3,0x40 /* change the compare value */
- li 1,8
- addi 2,2,-8 /* predec pointer */
- b 1b
-5: /* not found anywhere */
- mfsrr1 3
- lis 1,0x40000000@h /* set dsisr<1> to flag pte not found */
- mtctr 0 /* restore counter */
- andi. 2,3,0xffff /* clean upper srr1 */
- mtsrr1 2
- mtdsisr 1 /* load the dsisr */
- mfspr 1,SPR_DMISS /* get the miss address */
- mtdar 1 /* put in dar */
- mfmsr 0
- xoris 0,0,0x20000@h /* flip the msr<tgpr> bit */
- mtcrf 0x80,3 /* restore cr0 */
- mtmsr 0 /* now with native gprs */
- isync
- ba EXC_DSI
-CNAME(tlbdlmsize) = .-CNAME(tlbdlmiss)
-
- .globl CNAME(tlbdsmiss),CNAME(tlbdsmsize)
-CNAME(tlbdsmiss):
- mfspr 2,SPR_HASH1 /* get first pointer */
- li 1,8
- mfctr 0 /* save counter */
- mfspr 3,SPR_DCMP /* get first compare value */
- addi 2,2,-8 /* predec pointer */
-1:
- mtctr 1 /* load counter */
-2:
- lwzu 1,8(2) /* get next pte */
- cmpl 0,1,3 /* see if found pte */
- bdneq 2b /* loop if not eq */
- bne 3f /* not found */
- lwz 1,4(2) /* load tlb entry lower word */
- andi. 3,1,0x80 /* check the C-bit */
- beq 4f
-5:
- mtctr 0 /* restore counter */
- mfspr 0,SPR_DMISS /* get the miss address for the tlbld */
- mfsrr1 3 /* get the saved cr0 bits */
- mtcrf 0x80,3 /* and restore */
- mtspr SPR_RPA,1 /* set the pte */
- tlbld 0 /* load the dtlb */
- rfi
-
-3: /* not found in pteg */
- andi. 1,3,0x40 /* have we already done second hash? */
- bne 5f
- mfspr 2,SPR_HASH2 /* get the second pointer */
- ori 3,3,0x40 /* change the compare value */
- li 1,8
- addi 2,2,-8 /* predec pointer */
- b 1b
-4: /* found, but C-bit = 0 */
- rlwinm. 3,1,30,0,1 /* test PP */
- bge- 7f
- andi. 3,1,1
- beq+ 8f
-9: /* found, but protection violation (PP==00)*/
- mfsrr1 3
- lis 1,0xa000000@h /* indicate protection violation
- on store */
- b 1f
-7: /* found, PP=1x */
- mfspr 3,SPR_DMISS /* get the miss address */
- mfsrin 1,3 /* get the segment register */
- mfsrr1 3
- rlwinm 3,3,18,31,31 /* get PR-bit */
- rlwnm. 2,2,3,1,1 /* get the key */
- bne- 9b /* protection violation */
-8: /* found, set reference/change bits */
- lwz 1,4(2) /* reload tlb entry */
- ori 1,1,0x180
- sth 1,6(2)
- b 5b
-5: /* not found anywhere */
- mfsrr1 3
- lis 1,0x42000000@h /* set dsisr<1> to flag pte not found */
- /* dsisr<6> to flag store */
-1:
- mtctr 0 /* restore counter */
- andi. 2,3,0xffff /* clean upper srr1 */
- mtsrr1 2
- mtdsisr 1 /* load the dsisr */
- mfspr 1,SPR_DMISS /* get the miss address */
- mtdar 1 /* put in dar */
- mfmsr 0
- xoris 0,0,0x20000@h /* flip the msr<tgpr> bit */
- mtcrf 0x80,3 /* restore cr0 */
- mtmsr 0 /* now with native gprs */
- isync
- ba EXC_DSI
-CNAME(tlbdsmsize) = .-CNAME(tlbdsmiss)
-
-#if defined(DDB) || defined(KGDB)
-#define ddbsave 0xde0 /* primary save area for DDB */
-/*
- * In case of DDB we want a separate trap catcher for it
- */
- .local ddbstk
- .comm ddbstk,INTSTK,8 /* ddb stack */
-
- .globl CNAME(ddblow),CNAME(ddbsize)
-CNAME(ddblow):
- mtsprg 1,1 /* save SP */
- stmw 28,ddbsave(0) /* free r28-r31 */
- mflr 28 /* save LR */
- mfcr 29 /* save CR */
- lis 1,ddbstk+INTSTK@ha /* get new SP */
- addi 1,1,ddbstk+INTSTK@l
- bla ddbtrap
-CNAME(ddbsize) = .-CNAME(ddblow)
-#endif /* DDB | KGDB */
-
-#ifdef IPKDB
-#define ipkdbsave 0xde0 /* primary save area for IPKDB */
-/*
- * In case of IPKDB we want a separate trap catcher for it
- */
-
- .local ipkdbstk
- .comm ipkdbstk,INTSTK,8 /* ipkdb stack */
-
- .globl CNAME(ipkdblow),CNAME(ipkdbsize)
-CNAME(ipkdblow):
- mtsprg 1,1 /* save SP */
- stmw 28,ipkdbsave(0) /* free r28-r31 */
- mflr 28 /* save LR */
- mfcr 29 /* save CR */
- lis 1,ipkdbstk+INTSTK@ha /* get new SP */
- addi 1,1,ipkdbstk+INTSTK@l
- bla ipkdbtrap
-CNAME(ipkdbsize) = .-CNAME(ipkdblow)
-#endif /* IPKDB */
-
-/*
- * FRAME_SETUP assumes:
- * SPRG1 SP (1)
- * savearea r28-r31,DAR,DSISR (DAR & DSISR only for DSI traps)
- * 28 LR
- * 29 CR
- * 1 kernel stack
- * LR trap type
- * SRR0/1 as at start of trap
- */
-#define FRAME_SETUP(savearea) \
-/* Have to enable translation to allow access of kernel stack: */ \
- mfsrr0 30; \
- mfsrr1 31; \
- stmw 30,savearea+24(0); \
- mfmsr 30; \
- ori 30,30,(PSL_DR|PSL_IR|PSL_RI)@l; \
- mtmsr 30; \
- isync; \
- mfsprg 31,1; \
- stwu 31,-FRAMELEN(1); \
- stw 0,FRAME_0+8(1); \
- stw 31,FRAME_1+8(1); \
- stw 28,FRAME_LR+8(1); \
- stw 29,FRAME_CR+8(1); \
- lmw 28,savearea(0); \
- stmw 2,FRAME_2+8(1); \
- lmw 28,savearea+16(0); \
- mfxer 3; \
- mfctr 4; \
- mflr 5; \
- andi. 5,5,0xff00; \
- stw 3,FRAME_XER+8(1); \
- stw 4,FRAME_CTR+8(1); \
- stw 5,FRAME_EXC+8(1); \
- stw 28,FRAME_DAR+8(1); \
- stw 29,FRAME_DSISR+8(1); \
- stw 30,FRAME_SRR0+8(1); \
- stw 31,FRAME_SRR1+8(1)
-
-#define FRAME_LEAVE(savearea) \
-/* Now restore regs: */ \
- lwz 2,FRAME_SRR0+8(1); \
- lwz 3,FRAME_SRR1+8(1); \
- lwz 4,FRAME_CTR+8(1); \
- lwz 5,FRAME_XER+8(1); \
- lwz 6,FRAME_LR+8(1); \
- lwz 7,FRAME_CR+8(1); \
- stw 2,savearea(0); \
- stw 3,savearea+4(0); \
- mtctr 4; \
- mtxer 5; \
- mtlr 6; \
- mtsprg 1,7; /* save cr */ \
- lmw 2,FRAME_2+8(1); \
- lwz 0,FRAME_0+8(1); \
- lwz 1,FRAME_1+8(1); \
- mtsprg 2,2; /* save r2 & r3 */ \
- mtsprg 3,3; \
-/* Disable translation, machine check and recoverability: */ \
- mfmsr 2; \
- andi. 2,2,~(PSL_DR|PSL_IR|PSL_EE|PSL_ME|PSL_RI)@l; \
- mtmsr 2; \
- isync; \
-/* Decide whether we return to user mode: */ \
- lwz 3,savearea+4(0); \
- mtcr 3; \
- bc 4,17,1f; /* branch if PSL_PR is false */ \
-/* Restore user & kernel access SR: */ \
- mfsprg 2,0; \
- lwz 2,PC_CURPMAP(2); \
- cmpwi cr4,2,0; /* is curpmap NULL? */ \
- bne cr4,2f; \
- lis 3,cpassert@ha; /* if it is, panic */ \
- addi 3,3,cpassert@l; \
- b panic; \
-2: lwz 3,PM_SR+0(2); \
- mtsr 0,3; /* restore SR0 */ \
- lwz 3,PM_SR+4(2); \
- mtsr 1,3; /* restore SR1 */ \
- lwz 3,PM_SR+8(2); \
- mtsr 2,3; /* restore SR2 */ \
- lwz 3,PM_SR+12(2); \
- mtsr 3,3; /* restore SR3 */ \
- lwz 3,PM_SR+16(2); \
- mtsr 4,3; /* restore SR4 */ \
- lwz 3,PM_SR+20(2); \
- mtsr 5,3; /* restore SR5 */ \
- lwz 3,PM_SR+24(2); \
- mtsr 6,3; /* restore SR6 */ \
- lwz 3,PM_SR+28(2); \
- mtsr 7,3; /* restore SR7 */ \
- lwz 3,PM_USRSR(2); \
- mtsr USER_SR,3; \
- lwz 3,PM_KERNELSR(2); \
- mtsr KERNEL_SR,3; \
-1: mfsprg 2,1; /* restore cr */ \
- mtcr 2; \
- lwz 2,savearea(0); \
- lwz 3,savearea+4(0); \
- mtsrr0 2; \
- mtsrr1 3; \
- mfsprg 2,2; /* restore r2 & r3 */ \
- mfsprg 3,3
-
-/*
- * Preamble code for DSI/ISI traps
- */
-disitrap:
- lmw 30,disisave(0)
- stmw 30,tempsave(0)
- lmw 30,disisave+8(0)
- stmw 30,tempsave+8(0)
- mfdar 30
- mfdsisr 31
- stmw 30,tempsave+16(0)
-realtrap:
-/* Test whether we already had PR set */
- mfsrr1 1
- mtcr 1
- mfsprg 1,1 /* restore SP (might have been
- overwritten) */
- bc 4,17,s_trap /* branch if PSL_PR is false */
- mfsprg 31,0
- lwz 1,PC_CURPCB(31)
-
-/*
- * Now the common trap catching code.
- */
-s_trap:
-/* First have to enable KERNEL mapping */
- lis 31,KERNEL_SEGMENT@h
- ori 31,31,KERNEL_SEGMENT@l
- mtsr KERNEL_SR,31
-/* Obliterate SRs so BAT spills work correctly */
- lis 31,EMPTY_SEGMENT@h
- ori 31,31,EMPTY_SEGMENT@l
- mtsr 0,31
- mtsr 1,31
- mtsr 2,31
- mtsr 3,31
- mtsr 4,31
- mtsr 5,31
- mtsr 6,31
- mtsr 7,31
- FRAME_SETUP(tempsave)
-/* Now we can recover interrupts again: */
-#if 0
- mfmsr 7
- ori 7,7,(PSL_EE|PSL_ME|PSL_RI)@l
- mtmsr 7
- isync
-#endif
-/* Call C interrupt dispatcher: */
-trapagain:
- addi 3,1,8
- bl CNAME(powerpc_interrupt)
- .globl CNAME(trapexit)
-CNAME(trapexit):
-
-/* Disable interrupts: */
- mfmsr 3
- andi. 3,3,~PSL_EE@l
- mtmsr 3
-/* Test AST pending: */
- lwz 5,FRAME_SRR1+8(1)
- mtcr 5
- bc 4,17,1f /* branch if PSL_PR is false */
-
- mfsprg 3, 0 /* get per-CPU pointer */
- lwz 4, PC_CURTHREAD(3) /* deref to get curthread */
- lwz 4, TD_FLAGS(4) /* get thread flags value */
- lis 5, (TDF_ASTPENDING|TDF_NEEDRESCHED)@h
- ori 5,5, (TDF_ASTPENDING|TDF_NEEDRESCHED)@l
- and. 4,4,5
- beq 1f
- mfmsr 3 /* re-enable interrupts */
- ori 3,3,PSL_EE@l
- mtmsr 3
- isync
- addi 3,1,8
- bl CNAME(ast)
- b trapexit /* test ast ret value ? */
-1:
- FRAME_LEAVE(tempsave)
- rfi
-
-/*
- * DSI second stage fault handler
- */
-s_dsitrap:
- mfdsisr 31 /* test whether this may be a
- spill fault */
- mtcr 31
- mtsprg 1,1 /* save SP */
- bc 4,1,disitrap /* branch if table miss is false */
- lis 1,spillstk+SPILLSTK@ha
- addi 1,1,spillstk+SPILLSTK@l /* get spill stack */
- stwu 1,-SPFRAMELEN(1)
- stw 0,SPFRAME_R0(1) /* save non-volatile registers */
- stw 3,SPFRAME_R3(1)
- stw 4,SPFRAME_R4(1)
- stw 5,SPFRAME_R5(1)
- stw 6,SPFRAME_R6(1)
- stw 7,SPFRAME_R7(1)
- stw 8,SPFRAME_R8(1)
- stw 9,SPFRAME_R9(1)
- stw 10,SPFRAME_R10(1)
- stw 11,SPFRAME_R11(1)
- stw 12,SPFRAME_R12(1)
- mflr 30 /* save trap type */
- mfctr 31 /* & CTR */
- mfdar 3
-s_pte_spill:
- bl CNAME(pmap_pte_spill) /* try a spill */
- or. 3,3,3
- mtctr 31 /* restore CTR */
- mtlr 30 /* and trap type */
- mfsprg 31,2 /* get saved XER */
- mtxer 31 /* restore XER */
- lwz 12,SPFRAME_R12(1) /* restore non-volatile registers */
- lwz 11,SPFRAME_R11(1)
- lwz 10,SPFRAME_R10(1)
- lwz 9,SPFRAME_R9(1)
- lwz 8,SPFRAME_R8(1)
- lwz 7,SPFRAME_R7(1)
- lwz 6,SPFRAME_R6(1)
- lwz 5,SPFRAME_R5(1)
- lwz 4,SPFRAME_R4(1)
- lwz 3,SPFRAME_R3(1)
- lwz 0,SPFRAME_R0(1)
- beq disitrap
- mfsprg 1,1 /* restore SP */
- mtcr 29 /* restore CR */
- mtlr 28 /* restore LR */
- lmw 28,disisave(0) /* restore r28-r31 */
- rfi /* return to trapped code */
-
-/*
- * ISI second stage fault handler
- */
-s_isitrap:
- mfsrr1 31 /* test whether this may be a
- spill fault */
- mtcr 31
- mtsprg 1,1 /* save SP */
- bc 4,1,disitrap /* branch if table miss is false */
- lis 1,spillstk+SPILLSTK@ha
- addi 1,1,spillstk+SPILLSTK@l /* get spill stack */
- stwu 1,-SPFRAMELEN(1)
- stw 0,SPFRAME_R0(1) /* save non-volatile registers */
- stw 3,SPFRAME_R3(1)
- stw 4,SPFRAME_R4(1)
- stw 5,SPFRAME_R5(1)
- stw 6,SPFRAME_R6(1)
- stw 7,SPFRAME_R7(1)
- stw 8,SPFRAME_R8(1)
- stw 9,SPFRAME_R9(1)
- stw 10,SPFRAME_R10(1)
- stw 11,SPFRAME_R11(1)
- stw 12,SPFRAME_R12(1)
- mfxer 30 /* save XER */
- mtsprg 2,30
- mflr 30 /* save trap type */
- mfctr 31 /* & ctr */
- mfsrr0 3
- b s_pte_spill /* above */
-
-
-#if defined(DDB)
-/*
- * Deliberate entry to ddbtrap
- */
- .globl CNAME(ddb_trap)
-CNAME(ddb_trap):
- mtsprg 1,1
- mfmsr 3
- mtsrr1 3
- andi. 3,3,~(PSL_EE|PSL_ME)@l
- mtmsr 3 /* disable interrupts */
- isync
- stmw 28,ddbsave(0)
- mflr 28
- li 29,EXC_BPT
- mtlr 29
- mfcr 29
- mtsrr0 28
-#endif /* DDB */
-
-#if defined(DDB) || defined(KGDB)
-/*
- * Now the ddb trap catching code.
- */
-ddbtrap:
- FRAME_SETUP(ddbsave)
-/* Call C trap code: */
- addi 3,1,8
- bl CNAME(ddb_trap_glue)
- or. 3,3,3
- bne ddbleave
-/* This wasn't for DDB, so switch to real trap: */
- lwz 3,FRAME_EXC+8(1) /* save exception */
- stw 3,ddbsave+8(0)
- FRAME_LEAVE(ddbsave)
- mtsprg 1,1 /* prepare for entrance to realtrap */
- stmw 28,tempsave(0)
- mflr 28
- mfcr 29
- lwz 31,ddbsave+8(0)
- mtlr 31
- b realtrap
-ddbleave:
- FRAME_LEAVE(ddbsave)
- rfi
-#endif /* DDB || KGDB */
-
-#ifdef IPKDB
-/*
- * Deliberate entry to ipkdbtrap
- */
- .globl CNAME(ipkdb_trap)
-CNAME(ipkdb_trap):
- mtsprg 1,1
- mfmsr 3
- mtsrr1 3
- andi. 3,3,~(PSL_EE|PSL_ME)@l
- mtmsr 3 /* disable interrupts */
- isync
- stmw 28,ipkdbsave(0)
- mflr 28
- li 29,EXC_BPT
- mtlr 29
- mfcr 29
- mtsrr0 28
-
-/*
- * Now the ipkdb trap catching code.
- */
-ipkdbtrap:
- FRAME_SETUP(ipkdbsave)
-/* Call C trap code: */
- addi 3,1,8
- bl CNAME(ipkdb_trap_glue)
- or. 3,3,3
- bne ipkdbleave
-/* This wasn't for IPKDB, so switch to real trap: */
- lwz 3,FRAME_EXC+8(1) /* save exception */
- stw 3,ipkdbsave+8(0)
- FRAME_LEAVE(ipkdbsave)
- mtsprg 1,1 /* prepare for entrance to realtrap */
- stmw 28,tempsave(0)
- mflr 28
- mfcr 29
- lwz 31,ipkdbsave+8(0)
- mtlr 31
- b realtrap
-ipkdbleave:
- FRAME_LEAVE(ipkdbsave)
- rfi
-
-ipkdbfault:
- ba _ipkdbfault
-_ipkdbfault:
- mfsrr0 3
- addi 3,3,4
- mtsrr0 3
- li 3,-1
- rfi
-
-/*
- * int ipkdbfbyte(unsigned char *p)
- */
- .globl CNAME(ipkdbfbyte)
-CNAME(ipkdbfbyte):
- li 9,EXC_DSI /* establish new fault routine */
- lwz 5,0(9)
- lis 6,ipkdbfault@ha
- lwz 6,ipkdbfault@l(6)
- stw 6,0(9)
-#ifdef IPKDBUSERHACK
- lis 8,CNAME(ipkdbsr)@ha
- lwz 8,CNAME(ipkdbsr)@l(8)
- mtsr USER_SR,8
- isync
-#endif
- dcbst 0,9 /* flush data... */
- sync
- icbi 0,9 /* and instruction caches */
- lbz 3,0(3) /* fetch data */
- stw 5,0(9) /* restore previous fault handler */
- dcbst 0,9 /* and flush data... */
- sync
- icbi 0,9 /* and instruction caches */
- blr
-
-/*
- * int ipkdbsbyte(unsigned char *p, int c)
- */
- .globl CNAME(ipkdbsbyte)
-CNAME(ipkdbsbyte):
- li 9,EXC_DSI /* establish new fault routine */
- lwz 5,0(9)
- lis 6,ipkdbfault@ha
- lwz 6,ipkdbfault@l(6)
- stw 6,0(9)
-#ifdef IPKDBUSERHACK
- lis 8,CNAME(ipkdbsr)@ha
- lwz 8,CNAME(ipkdbsr)@l(8)
- mtsr USER_SR,8
- isync
-#endif
- dcbst 0,9 /* flush data... */
- sync
- icbi 0,9 /* and instruction caches */
- mr 6,3
- xor 3,3,3
- stb 4,0(6)
- dcbst 0,6 /* Now do appropriate flushes
- to data... */
- sync
- icbi 0,6 /* and instruction caches */
- stw 5,0(9) /* restore previous fault handler */
- dcbst 0,9 /* and flush data... */
- sync
- icbi 0,9 /* and instruction caches */
- blr
-#endif /* IPKDB */
diff --git a/sys/powerpc/aim/vm_machdep.c b/sys/powerpc/aim/vm_machdep.c
deleted file mode 100644
index 61e7ba025aa3..000000000000
--- a/sys/powerpc/aim/vm_machdep.c
+++ /dev/null
@@ -1,292 +0,0 @@
-/*-
- * Copyright (c) 1982, 1986 The Regents of the University of California.
- * Copyright (c) 1989, 1990 William Jolitz
- * Copyright (c) 1994 John Dyson
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * the Systems Programming Group of the University of Utah Computer
- * Science Department, and William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91
- * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
- * $FreeBSD$
- */
-/*
- * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/proc.h>
-#include <sys/malloc.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
-#include <sys/ktr.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/vnode.h>
-#include <sys/vmmeter.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/unistd.h>
-
-#include <machine/clock.h>
-#include <machine/cpu.h>
-#include <machine/fpu.h>
-#include <machine/frame.h>
-#include <machine/md_var.h>
-
-#include <dev/ofw/openfirm.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_page.h>
-#include <vm/vm_map.h>
-#include <vm/vm_extern.h>
-
-#include <sys/user.h>
-
-/*
- * Finish a fork operation, with process p2 nearly set up.
- * Copy and update the pcb, set up the stack so that the child
- * ready to run and return to user mode.
- */
-void
-cpu_fork(struct thread *td1, struct proc *p2, struct thread *td2, int flags)
-{
- struct proc *p1;
- struct trapframe *tf;
- struct callframe *cf;
- struct pcb *pcb;
-
- KASSERT(td1 == curthread || td1 == &thread0,
- ("cpu_fork: p1 not curproc and not proc0"));
- CTR3(KTR_PROC, "cpu_fork: called td1=%08x p2=%08x flags=%x", (u_int)td1, (u_int)p2, flags);
-
- if ((flags & RFPROC) == 0)
- return;
-
- p1 = td1->td_proc;
-
- pcb = (struct pcb *)((td2->td_kstack + KSTACK_PAGES * PAGE_SIZE -
- sizeof(struct pcb)) & ~0x2fU);
- td2->td_pcb = pcb;
-
- /* Copy the pcb */
- bcopy(td1->td_pcb, pcb, sizeof(struct pcb));
-
- /*
- * Create a fresh stack for the new process.
- * Copy the trap frame for the return to user mode as if from a
- * syscall. This copies most of the user mode register values.
- */
- tf = (struct trapframe *)pcb - 1;
- bcopy(td1->td_frame, tf, sizeof(*tf));
-
- /* Set up trap frame. */
- tf->fixreg[FIRSTARG] = 0;
- tf->fixreg[FIRSTARG + 1] = 0;
- tf->cr &= ~0x10000000;
-
- td2->td_frame = tf;
-
- cf = (struct callframe *)tf - 1;
- cf->cf_func = (register_t)fork_return;
- cf->cf_arg0 = (register_t)td2;
- cf->cf_arg1 = (register_t)tf;
-
- pcb->pcb_sp = (register_t)cf;
- pcb->pcb_lr = (register_t)fork_trampoline;
- pcb->pcb_usr = kernel_pmap->pm_sr[USER_SR];
-
- /*
- * Now cpu_switch() can schedule the new process.
- */
-}
-
-/*
- * Intercept the return address from a freshly forked process that has NOT
- * been scheduled yet.
- *
- * This is needed to make kernel threads stay in kernel mode.
- */
-void
-cpu_set_fork_handler(td, func, arg)
- struct thread *td;
- void (*func)(void *);
- void *arg;
-{
- struct callframe *cf;
-
- CTR3(KTR_PROC, "cpu_set_fork_handler: called with td=%08x func=%08x arg=%08x",
- (u_int)td, (u_int)func, (u_int)arg);
-
- cf = (struct callframe *)td->td_pcb->pcb_sp;
-
- cf->cf_func = (register_t)func;
- cf->cf_arg0 = (register_t)arg;
-}
-
-/*
- * cpu_exit is called as the last action during exit.
- * We release the address space of the process, block interrupts,
- * and call switch_exit. switch_exit switches to proc0's PCB and stack,
- * then jumps into the middle of cpu_switch, as if it were switching
- * from proc0.
- */
-void
-cpu_exit(td)
- register struct thread *td;
-{
-}
-
-void
-cpu_sched_exit(td)
- register struct thread *td;
-{
-}
-
-void
-cpu_wait(td)
- struct proc *td;
-{
-}
-
-/* Temporary helper */
-void
-cpu_throw(void)
-{
-
- cpu_switch();
- panic("cpu_throw() didn't");
-}
-
-/*
- * Reset back to firmware.
- */
-void
-cpu_reset()
-{
- OF_exit();
-}
-
-/*
- * Software interrupt handler for queued VM system processing.
- */
-void
-swi_vm(void *dummy)
-{
-#if 0 /* XXX: Don't have busdma stuff yet */
- if (busdma_swi_pending != 0)
- busdma_swi();
-#endif
-}
-
-/*
- * Tell whether this address is in some physical memory region.
- * Currently used by the kernel coredump code in order to avoid
- * dumping the ``ISA memory hole'' which could cause indefinite hangs,
- * or other unpredictable behaviour.
- */
-
-
-int
-is_physical_memory(addr)
- vm_offset_t addr;
-{
- /*
- * stuff other tests for known memory-mapped devices (PCI?)
- * here
- */
-
- return 1;
-}
-
-/*
- * KSE functions
- */
-void
-cpu_thread_exit(struct thread *td)
-{
-
- return;
-}
-
-void
-cpu_thread_clean(struct thread *td)
-{
-}
-
-void
-cpu_thread_setup(struct thread *td)
-{
-
- return;
-}
-
-void
-cpu_set_upcall(struct thread *td, void *pcb)
-{
-
- return;
-}
-
-void
-cpu_set_upcall_kse(struct thread *td, struct kse_upcall *ku)
-{
-
- return;
-}
diff --git a/sys/powerpc/powerpc/mmu_oea.c b/sys/powerpc/powerpc/mmu_oea.c
deleted file mode 100644
index 00528814ac51..000000000000
--- a/sys/powerpc/powerpc/mmu_oea.c
+++ /dev/null
@@ -1,2512 +0,0 @@
-/*
- * Copyright (c) 2001 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Matt Thomas <matt@3am-software.com> of Allegro Networks, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-/*
- * Copyright (C) 1995, 1996 Wolfgang Solfrank.
- * Copyright (C) 1995, 1996 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $NetBSD: pmap.c,v 1.28 2000/03/26 20:42:36 kleink Exp $
- */
-/*
- * Copyright (C) 2001 Benno Rice.
- * 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 Benno Rice ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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$");
-
-/*
- * Manages physical address maps.
- *
- * In addition to hardware address maps, this module is called upon to
- * provide software-use-only maps which may or may not be stored in the
- * same form as hardware maps. These pseudo-maps are used to store
- * intermediate results from copy operations to and from address spaces.
- *
- * Since the information managed by this module is also stored by the
- * logical address mapping module, this module may throw away valid virtual
- * to physical mappings at almost any time. However, invalidations of
- * mappings must be done as requested.
- *
- * In order to cope with hardware architectures which make virtual to
- * physical map invalidates expensive, this module may delay invalidate
- * reduced protection operations until such time as they are actually
- * necessary. This module is given full information as to which processors
- * are currently using which maps, and to when physical maps must be made
- * correct.
- */
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/ktr.h>
-#include <sys/lock.h>
-#include <sys/msgbuf.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/sysctl.h>
-#include <sys/systm.h>
-#include <sys/vmmeter.h>
-
-#include <dev/ofw/openfirm.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_page.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-#include <vm/vm_extern.h>
-#include <vm/vm_pageout.h>
-#include <vm/vm_pager.h>
-#include <vm/uma.h>
-
-#include <machine/powerpc.h>
-#include <machine/bat.h>
-#include <machine/frame.h>
-#include <machine/md_var.h>
-#include <machine/psl.h>
-#include <machine/pte.h>
-#include <machine/sr.h>
-
-#define PMAP_DEBUG
-
-#define TODO panic("%s: not implemented", __func__);
-
-#define PMAP_LOCK(pm)
-#define PMAP_UNLOCK(pm)
-
-#define TLBIE(va) __asm __volatile("tlbie %0" :: "r"(va))
-#define TLBSYNC() __asm __volatile("tlbsync");
-#define SYNC() __asm __volatile("sync");
-#define EIEIO() __asm __volatile("eieio");
-
-#define VSID_MAKE(sr, hash) ((sr) | (((hash) & 0xfffff) << 4))
-#define VSID_TO_SR(vsid) ((vsid) & 0xf)
-#define VSID_TO_HASH(vsid) (((vsid) >> 4) & 0xfffff)
-
-#define PVO_PTEGIDX_MASK 0x0007 /* which PTEG slot */
-#define PVO_PTEGIDX_VALID 0x0008 /* slot is valid */
-#define PVO_WIRED 0x0010 /* PVO entry is wired */
-#define PVO_MANAGED 0x0020 /* PVO entry is managed */
-#define PVO_EXECUTABLE 0x0040 /* PVO entry is executable */
-#define PVO_BOOTSTRAP 0x0080 /* PVO entry allocated during
- bootstrap */
-#define PVO_VADDR(pvo) ((pvo)->pvo_vaddr & ~ADDR_POFF)
-#define PVO_ISEXECUTABLE(pvo) ((pvo)->pvo_vaddr & PVO_EXECUTABLE)
-#define PVO_PTEGIDX_GET(pvo) ((pvo)->pvo_vaddr & PVO_PTEGIDX_MASK)
-#define PVO_PTEGIDX_ISSET(pvo) ((pvo)->pvo_vaddr & PVO_PTEGIDX_VALID)
-#define PVO_PTEGIDX_CLR(pvo) \
- ((void)((pvo)->pvo_vaddr &= ~(PVO_PTEGIDX_VALID|PVO_PTEGIDX_MASK)))
-#define PVO_PTEGIDX_SET(pvo, i) \
- ((void)((pvo)->pvo_vaddr |= (i)|PVO_PTEGIDX_VALID))
-
-#define PMAP_PVO_CHECK(pvo)
-
-struct ofw_map {
- vm_offset_t om_va;
- vm_size_t om_len;
- vm_offset_t om_pa;
- u_int om_mode;
-};
-
-int pmap_bootstrapped = 0;
-
-/*
- * Virtual and physical address of message buffer.
- */
-struct msgbuf *msgbufp;
-vm_offset_t msgbuf_phys;
-
-/*
- * Physical addresses of first and last available physical page.
- */
-vm_offset_t avail_start;
-vm_offset_t avail_end;
-
-int pmap_pagedaemon_waken;
-
-/*
- * Map of physical memory regions.
- */
-vm_offset_t phys_avail[128];
-u_int phys_avail_count;
-static struct mem_region *regions;
-static struct mem_region *pregions;
-int regions_sz, pregions_sz;
-static struct ofw_map *translations;
-
-/*
- * First and last available kernel virtual addresses.
- */
-vm_offset_t virtual_avail;
-vm_offset_t virtual_end;
-vm_offset_t kernel_vm_end;
-
-/*
- * Kernel pmap.
- */
-struct pmap kernel_pmap_store;
-extern struct pmap ofw_pmap;
-
-/*
- * PTEG data.
- */
-static struct pteg *pmap_pteg_table;
-u_int pmap_pteg_count;
-u_int pmap_pteg_mask;
-
-/*
- * PVO data.
- */
-struct pvo_head *pmap_pvo_table; /* pvo entries by pteg index */
-struct pvo_head pmap_pvo_kunmanaged =
- LIST_HEAD_INITIALIZER(pmap_pvo_kunmanaged); /* list of unmanaged pages */
-struct pvo_head pmap_pvo_unmanaged =
- LIST_HEAD_INITIALIZER(pmap_pvo_unmanaged); /* list of unmanaged pages */
-
-uma_zone_t pmap_upvo_zone; /* zone for pvo entries for unmanaged pages */
-uma_zone_t pmap_mpvo_zone; /* zone for pvo entries for managed pages */
-struct vm_object pmap_upvo_zone_obj;
-struct vm_object pmap_mpvo_zone_obj;
-static vm_object_t pmap_pvo_obj;
-static u_int pmap_pvo_count;
-
-#define BPVO_POOL_SIZE 32768
-static struct pvo_entry *pmap_bpvo_pool;
-static int pmap_bpvo_pool_index = 0;
-
-#define VSID_NBPW (sizeof(u_int32_t) * 8)
-static u_int pmap_vsid_bitmap[NPMAPS / VSID_NBPW];
-
-static boolean_t pmap_initialized = FALSE;
-
-/*
- * Statistics.
- */
-u_int pmap_pte_valid = 0;
-u_int pmap_pte_overflow = 0;
-u_int pmap_pte_replacements = 0;
-u_int pmap_pvo_entries = 0;
-u_int pmap_pvo_enter_calls = 0;
-u_int pmap_pvo_remove_calls = 0;
-u_int pmap_pte_spills = 0;
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pte_valid, CTLFLAG_RD, &pmap_pte_valid,
- 0, "");
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pte_overflow, CTLFLAG_RD,
- &pmap_pte_overflow, 0, "");
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pte_replacements, CTLFLAG_RD,
- &pmap_pte_replacements, 0, "");
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pvo_entries, CTLFLAG_RD, &pmap_pvo_entries,
- 0, "");
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pvo_enter_calls, CTLFLAG_RD,
- &pmap_pvo_enter_calls, 0, "");
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pvo_remove_calls, CTLFLAG_RD,
- &pmap_pvo_remove_calls, 0, "");
-SYSCTL_INT(_machdep, OID_AUTO, pmap_pte_spills, CTLFLAG_RD,
- &pmap_pte_spills, 0, "");
-
-struct pvo_entry *pmap_pvo_zeropage;
-
-vm_offset_t pmap_rkva_start = VM_MIN_KERNEL_ADDRESS;
-u_int pmap_rkva_count = 4;
-
-/*
- * Allocate physical memory for use in pmap_bootstrap.
- */
-static vm_offset_t pmap_bootstrap_alloc(vm_size_t, u_int);
-
-/*
- * PTE calls.
- */
-static int pmap_pte_insert(u_int, struct pte *);
-
-/*
- * PVO calls.
- */
-static int pmap_pvo_enter(pmap_t, uma_zone_t, struct pvo_head *,
- vm_offset_t, vm_offset_t, u_int, int);
-static void pmap_pvo_remove(struct pvo_entry *, int);
-static struct pvo_entry *pmap_pvo_find_va(pmap_t, vm_offset_t, int *);
-static struct pte *pmap_pvo_to_pte(const struct pvo_entry *, int);
-
-/*
- * Utility routines.
- */
-static void * pmap_pvo_allocf(uma_zone_t, int, u_int8_t *, int);
-static struct pvo_entry *pmap_rkva_alloc(void);
-static void pmap_pa_map(struct pvo_entry *, vm_offset_t,
- struct pte *, int *);
-static void pmap_pa_unmap(struct pvo_entry *, struct pte *, int *);
-static void pmap_syncicache(vm_offset_t, vm_size_t);
-static boolean_t pmap_query_bit(vm_page_t, int);
-static u_int pmap_clear_bit(vm_page_t, int, int *);
-static void tlbia(void);
-
-static __inline int
-va_to_sr(u_int *sr, vm_offset_t va)
-{
- return (sr[(uintptr_t)va >> ADDR_SR_SHFT]);
-}
-
-static __inline u_int
-va_to_pteg(u_int sr, vm_offset_t addr)
-{
- u_int hash;
-
- hash = (sr & SR_VSID_MASK) ^ (((u_int)addr & ADDR_PIDX) >>
- ADDR_PIDX_SHFT);
- return (hash & pmap_pteg_mask);
-}
-
-static __inline struct pvo_head *
-pa_to_pvoh(vm_offset_t pa, vm_page_t *pg_p)
-{
- struct vm_page *pg;
-
- pg = PHYS_TO_VM_PAGE(pa);
-
- if (pg_p != NULL)
- *pg_p = pg;
-
- if (pg == NULL)
- return (&pmap_pvo_unmanaged);
-
- return (&pg->md.mdpg_pvoh);
-}
-
-static __inline struct pvo_head *
-vm_page_to_pvoh(vm_page_t m)
-{
-
- return (&m->md.mdpg_pvoh);
-}
-
-static __inline void
-pmap_attr_clear(vm_page_t m, int ptebit)
-{
-
- m->md.mdpg_attrs &= ~ptebit;
-}
-
-static __inline int
-pmap_attr_fetch(vm_page_t m)
-{
-
- return (m->md.mdpg_attrs);
-}
-
-static __inline void
-pmap_attr_save(vm_page_t m, int ptebit)
-{
-
- m->md.mdpg_attrs |= ptebit;
-}
-
-static __inline int
-pmap_pte_compare(const struct pte *pt, const struct pte *pvo_pt)
-{
- if (pt->pte_hi == pvo_pt->pte_hi)
- return (1);
-
- return (0);
-}
-
-static __inline int
-pmap_pte_match(struct pte *pt, u_int sr, vm_offset_t va, int which)
-{
- return (pt->pte_hi & ~PTE_VALID) ==
- (((sr & SR_VSID_MASK) << PTE_VSID_SHFT) |
- ((va >> ADDR_API_SHFT) & PTE_API) | which);
-}
-
-static __inline void
-pmap_pte_create(struct pte *pt, u_int sr, vm_offset_t va, u_int pte_lo)
-{
- /*
- * Construct a PTE. Default to IMB initially. Valid bit only gets
- * set when the real pte is set in memory.
- *
- * Note: Don't set the valid bit for correct operation of tlb update.
- */
- pt->pte_hi = ((sr & SR_VSID_MASK) << PTE_VSID_SHFT) |
- (((va & ADDR_PIDX) >> ADDR_API_SHFT) & PTE_API);
- pt->pte_lo = pte_lo;
-}
-
-static __inline void
-pmap_pte_synch(struct pte *pt, struct pte *pvo_pt)
-{
-
- pvo_pt->pte_lo |= pt->pte_lo & (PTE_REF | PTE_CHG);
-}
-
-static __inline void
-pmap_pte_clear(struct pte *pt, vm_offset_t va, int ptebit)
-{
-
- /*
- * As shown in Section 7.6.3.2.3
- */
- pt->pte_lo &= ~ptebit;
- TLBIE(va);
- EIEIO();
- TLBSYNC();
- SYNC();
-}
-
-static __inline void
-pmap_pte_set(struct pte *pt, struct pte *pvo_pt)
-{
-
- pvo_pt->pte_hi |= PTE_VALID;
-
- /*
- * Update the PTE as defined in section 7.6.3.1.
- * Note that the REF/CHG bits are from pvo_pt and thus should havce
- * been saved so this routine can restore them (if desired).
- */
- pt->pte_lo = pvo_pt->pte_lo;
- EIEIO();
- pt->pte_hi = pvo_pt->pte_hi;
- SYNC();
- pmap_pte_valid++;
-}
-
-static __inline void
-pmap_pte_unset(struct pte *pt, struct pte *pvo_pt, vm_offset_t va)
-{
-
- pvo_pt->pte_hi &= ~PTE_VALID;
-
- /*
- * Force the reg & chg bits back into the PTEs.
- */
- SYNC();
-
- /*
- * Invalidate the pte.
- */
- pt->pte_hi &= ~PTE_VALID;
-
- SYNC();
- TLBIE(va);
- EIEIO();
- TLBSYNC();
- SYNC();
-
- /*
- * Save the reg & chg bits.
- */
- pmap_pte_synch(pt, pvo_pt);
- pmap_pte_valid--;
-}
-
-static __inline void
-pmap_pte_change(struct pte *pt, struct pte *pvo_pt, vm_offset_t va)
-{
-
- /*
- * Invalidate the PTE
- */
- pmap_pte_unset(pt, pvo_pt, va);
- pmap_pte_set(pt, pvo_pt);
-}
-
-/*
- * Quick sort callout for comparing memory regions.
- */
-static int mr_cmp(const void *a, const void *b);
-static int om_cmp(const void *a, const void *b);
-
-static int
-mr_cmp(const void *a, const void *b)
-{
- const struct mem_region *regiona;
- const struct mem_region *regionb;
-
- regiona = a;
- regionb = b;
- if (regiona->mr_start < regionb->mr_start)
- return (-1);
- else if (regiona->mr_start > regionb->mr_start)
- return (1);
- else
- return (0);
-}
-
-static int
-om_cmp(const void *a, const void *b)
-{
- const struct ofw_map *mapa;
- const struct ofw_map *mapb;
-
- mapa = a;
- mapb = b;
- if (mapa->om_pa < mapb->om_pa)
- return (-1);
- else if (mapa->om_pa > mapb->om_pa)
- return (1);
- else
- return (0);
-}
-
-void
-pmap_bootstrap(vm_offset_t kernelstart, vm_offset_t kernelend)
-{
- ihandle_t mmui;
- phandle_t chosen, mmu;
- int sz;
- int i, j;
- int ofw_mappings;
- vm_size_t size, physsz;
- vm_offset_t pa, va, off;
- u_int batl, batu;
-
- /*
- * Set up BAT0 to map the lowest 256 MB area
- */
- battable[0x0].batl = BATL(0x00000000, BAT_M, BAT_PP_RW);
- battable[0x0].batu = BATU(0x00000000, BAT_BL_256M, BAT_Vs);
-
- /*
- * Map PCI memory space.
- */
- battable[0x8].batl = BATL(0x80000000, BAT_I|BAT_G, BAT_PP_RW);
- battable[0x8].batu = BATU(0x80000000, BAT_BL_256M, BAT_Vs);
-
- battable[0x9].batl = BATL(0x90000000, BAT_I|BAT_G, BAT_PP_RW);
- battable[0x9].batu = BATU(0x90000000, BAT_BL_256M, BAT_Vs);
-
- battable[0xa].batl = BATL(0xa0000000, BAT_I|BAT_G, BAT_PP_RW);
- battable[0xa].batu = BATU(0xa0000000, BAT_BL_256M, BAT_Vs);
-
- battable[0xb].batl = BATL(0xb0000000, BAT_I|BAT_G, BAT_PP_RW);
- battable[0xb].batu = BATU(0xb0000000, BAT_BL_256M, BAT_Vs);
-
- /*
- * Map obio devices.
- */
- battable[0xf].batl = BATL(0xf0000000, BAT_I|BAT_G, BAT_PP_RW);
- battable[0xf].batu = BATU(0xf0000000, BAT_BL_256M, BAT_Vs);
-
- /*
- * Use an IBAT and a DBAT to map the bottom segment of memory
- * where we are.
- */
- batu = BATU(0x00000000, BAT_BL_256M, BAT_Vs);
- batl = BATL(0x00000000, BAT_M, BAT_PP_RW);
- __asm ("mtibatu 0,%0; mtibatl 0,%1; mtdbatu 0,%0; mtdbatl 0,%1"
- :: "r"(batu), "r"(batl));
-
-#if 0
- /* map frame buffer */
- batu = BATU(0x90000000, BAT_BL_256M, BAT_Vs);
- batl = BATL(0x90000000, BAT_I|BAT_G, BAT_PP_RW);
- __asm ("mtdbatu 1,%0; mtdbatl 1,%1"
- :: "r"(batu), "r"(batl));
-#endif
-
-#if 1
- /* map pci space */
- batu = BATU(0x80000000, BAT_BL_256M, BAT_Vs);
- batl = BATL(0x80000000, BAT_I|BAT_G, BAT_PP_RW);
- __asm ("mtdbatu 1,%0; mtdbatl 1,%1"
- :: "r"(batu), "r"(batl));
-#endif
-
- /*
- * Set the start and end of kva.
- */
- virtual_avail = VM_MIN_KERNEL_ADDRESS;
- virtual_end = VM_MAX_KERNEL_ADDRESS;
-
- mem_regions(&pregions, &pregions_sz, &regions, &regions_sz);
- CTR0(KTR_PMAP, "pmap_bootstrap: physical memory");
-
- qsort(pregions, pregions_sz, sizeof(*pregions), mr_cmp);
- for (i = 0; i < pregions_sz; i++) {
- vm_offset_t pa;
- vm_offset_t end;
-
- CTR3(KTR_PMAP, "physregion: %#x - %#x (%#x)",
- pregions[i].mr_start,
- pregions[i].mr_start + pregions[i].mr_size,
- pregions[i].mr_size);
- /*
- * Install entries into the BAT table to allow all
- * of physmem to be convered by on-demand BAT entries.
- * The loop will sometimes set the same battable element
- * twice, but that's fine since they won't be used for
- * a while yet.
- */
- pa = pregions[i].mr_start & 0xf0000000;
- end = pregions[i].mr_start + pregions[i].mr_size;
- do {
- u_int n = pa >> ADDR_SR_SHFT;
-
- battable[n].batl = BATL(pa, BAT_M, BAT_PP_RW);
- battable[n].batu = BATU(pa, BAT_BL_256M, BAT_Vs);
- pa += SEGMENT_LENGTH;
- } while (pa < end);
- }
-
- if (sizeof(phys_avail)/sizeof(phys_avail[0]) < regions_sz)
- panic("pmap_bootstrap: phys_avail too small");
- qsort(regions, regions_sz, sizeof(*regions), mr_cmp);
- phys_avail_count = 0;
- physsz = 0;
- for (i = 0, j = 0; i < regions_sz; i++, j += 2) {
- CTR3(KTR_PMAP, "region: %#x - %#x (%#x)", regions[i].mr_start,
- regions[i].mr_start + regions[i].mr_size,
- regions[i].mr_size);
- phys_avail[j] = regions[i].mr_start;
- phys_avail[j + 1] = regions[i].mr_start + regions[i].mr_size;
- phys_avail_count++;
- physsz += regions[i].mr_size;
- }
- physmem = btoc(physsz);
-
- /*
- * Allocate PTEG table.
- */
-#ifdef PTEGCOUNT
- pmap_pteg_count = PTEGCOUNT;
-#else
- pmap_pteg_count = 0x1000;
-
- while (pmap_pteg_count < physmem)
- pmap_pteg_count <<= 1;
-
- pmap_pteg_count >>= 1;
-#endif /* PTEGCOUNT */
-
- size = pmap_pteg_count * sizeof(struct pteg);
- CTR2(KTR_PMAP, "pmap_bootstrap: %d PTEGs, %d bytes", pmap_pteg_count,
- size);
- pmap_pteg_table = (struct pteg *)pmap_bootstrap_alloc(size, size);
- CTR1(KTR_PMAP, "pmap_bootstrap: PTEG table at %p", pmap_pteg_table);
- bzero((void *)pmap_pteg_table, pmap_pteg_count * sizeof(struct pteg));
- pmap_pteg_mask = pmap_pteg_count - 1;
-
- /*
- * Allocate pv/overflow lists.
- */
- size = sizeof(struct pvo_head) * pmap_pteg_count;
- pmap_pvo_table = (struct pvo_head *)pmap_bootstrap_alloc(size,
- PAGE_SIZE);
- CTR1(KTR_PMAP, "pmap_bootstrap: PVO table at %p", pmap_pvo_table);
- for (i = 0; i < pmap_pteg_count; i++)
- LIST_INIT(&pmap_pvo_table[i]);
-
- /*
- * Allocate the message buffer.
- */
- msgbuf_phys = pmap_bootstrap_alloc(MSGBUF_SIZE, 0);
-
- /*
- * Initialise the unmanaged pvo pool.
- */
- pmap_bpvo_pool = (struct pvo_entry *)pmap_bootstrap_alloc(
- BPVO_POOL_SIZE*sizeof(struct pvo_entry), 0);
- pmap_bpvo_pool_index = 0;
-
- /*
- * Make sure kernel vsid is allocated as well as VSID 0.
- */
- pmap_vsid_bitmap[(KERNEL_VSIDBITS & (NPMAPS - 1)) / VSID_NBPW]
- |= 1 << (KERNEL_VSIDBITS % VSID_NBPW);
- pmap_vsid_bitmap[0] |= 1;
-
- /*
- * Set up the OpenFirmware pmap and add it's mappings.
- */
- pmap_pinit(&ofw_pmap);
- ofw_pmap.pm_sr[KERNEL_SR] = KERNEL_SEGMENT;
- if ((chosen = OF_finddevice("/chosen")) == -1)
- panic("pmap_bootstrap: can't find /chosen");
- OF_getprop(chosen, "mmu", &mmui, 4);
- if ((mmu = OF_instance_to_package(mmui)) == -1)
- panic("pmap_bootstrap: can't get mmu package");
- if ((sz = OF_getproplen(mmu, "translations")) == -1)
- panic("pmap_bootstrap: can't get ofw translation count");
- translations = NULL;
- for (i = 0; phys_avail[i + 2] != 0; i += 2) {
- if (phys_avail[i + 1] >= sz)
- translations = (struct ofw_map *)phys_avail[i];
- }
- if (translations == NULL)
- panic("pmap_bootstrap: no space to copy translations");
- bzero(translations, sz);
- if (OF_getprop(mmu, "translations", translations, sz) == -1)
- panic("pmap_bootstrap: can't get ofw translations");
- CTR0(KTR_PMAP, "pmap_bootstrap: translations");
- sz /= sizeof(*translations);
- qsort(translations, sz, sizeof (*translations), om_cmp);
- for (i = 0, ofw_mappings = 0; i < sz; i++) {
- CTR3(KTR_PMAP, "translation: pa=%#x va=%#x len=%#x",
- translations[i].om_pa, translations[i].om_va,
- translations[i].om_len);
-
- /*
- * If the mapping is 1:1, let the RAM and device on-demand
- * BAT tables take care of the translation.
- */
- if (translations[i].om_va == translations[i].om_pa)
- continue;
-
- /* Enter the pages */
- for (off = 0; off < translations[i].om_len; off += PAGE_SIZE) {
- struct vm_page m;
-
- m.phys_addr = translations[i].om_pa + off;
- pmap_enter(&ofw_pmap, translations[i].om_va + off, &m,
- VM_PROT_ALL, 1);
- ofw_mappings++;
- }
- }
-#ifdef SMP
- TLBSYNC();
-#endif
-
- /*
- * Initialize the kernel pmap (which is statically allocated).
- */
- for (i = 0; i < 16; i++) {
- kernel_pmap->pm_sr[i] = EMPTY_SEGMENT;
- }
- kernel_pmap->pm_sr[KERNEL_SR] = KERNEL_SEGMENT;
- kernel_pmap->pm_active = ~0;
-
- /*
- * Allocate a kernel stack with a guard page for thread0 and map it
- * into the kernel page map.
- */
- pa = pmap_bootstrap_alloc(KSTACK_PAGES * PAGE_SIZE, 0);
- kstack0_phys = pa;
- kstack0 = virtual_avail + (KSTACK_GUARD_PAGES * PAGE_SIZE);
- CTR2(KTR_PMAP, "pmap_bootstrap: kstack0 at %#x (%#x)", kstack0_phys,
- kstack0);
- virtual_avail += (KSTACK_PAGES + KSTACK_GUARD_PAGES) * PAGE_SIZE;
- for (i = 0; i < KSTACK_PAGES; i++) {
- pa = kstack0_phys + i * PAGE_SIZE;
- va = kstack0 + i * PAGE_SIZE;
- pmap_kenter(va, pa);
- TLBIE(va);
- }
-
- /*
- * Calculate the first and last available physical addresses.
- */
- avail_start = phys_avail[0];
- for (i = 0; phys_avail[i + 2] != 0; i += 2)
- ;
- avail_end = phys_avail[i + 1];
- Maxmem = powerpc_btop(avail_end);
-
- /*
- * Allocate virtual address space for the message buffer.
- */
- msgbufp = (struct msgbuf *)virtual_avail;
- virtual_avail += round_page(MSGBUF_SIZE);
-
- /*
- * Initialize hardware.
- */
- for (i = 0; i < 16; i++) {
- mtsrin(i << ADDR_SR_SHFT, EMPTY_SEGMENT);
- }
- __asm __volatile ("mtsr %0,%1"
- :: "n"(KERNEL_SR), "r"(KERNEL_SEGMENT));
- __asm __volatile ("sync; mtsdr1 %0; isync"
- :: "r"((u_int)pmap_pteg_table | (pmap_pteg_mask >> 10)));
- tlbia();
-
- pmap_bootstrapped++;
-}
-
-/*
- * Activate a user pmap. The pmap must be activated before it's address
- * space can be accessed in any way.
- */
-void
-pmap_activate(struct thread *td)
-{
- pmap_t pm, pmr;
-
- /*
- * Load all the data we need up front to encourage the compiler to
- * not issue any loads while we have interrupts disabled below.
- */
- pm = &td->td_proc->p_vmspace->vm_pmap;
-
- if ((pmr = (pmap_t)pmap_kextract((vm_offset_t)pm)) == NULL)
- pmr = pm;
-
- pm->pm_active |= PCPU_GET(cpumask);
- PCPU_SET(curpmap, pmr);
-}
-
-void
-pmap_deactivate(struct thread *td)
-{
- pmap_t pm;
-
- pm = &td->td_proc->p_vmspace->vm_pmap;
- pm->pm_active &= ~(PCPU_GET(cpumask));
- PCPU_SET(curpmap, NULL);
-}
-
-vm_offset_t
-pmap_addr_hint(vm_object_t object, vm_offset_t va, vm_size_t size)
-{
-
- return (va);
-}
-
-void
-pmap_change_wiring(pmap_t pm, vm_offset_t va, boolean_t wired)
-{
- struct pvo_entry *pvo;
-
- pvo = pmap_pvo_find_va(pm, va & ~ADDR_POFF, NULL);
-
- if (pvo != NULL) {
- if (wired) {
- if ((pvo->pvo_vaddr & PVO_WIRED) == 0)
- pm->pm_stats.wired_count++;
- pvo->pvo_vaddr |= PVO_WIRED;
- } else {
- if ((pvo->pvo_vaddr & PVO_WIRED) != 0)
- pm->pm_stats.wired_count--;
- pvo->pvo_vaddr &= ~PVO_WIRED;
- }
- }
-}
-
-void
-pmap_copy(pmap_t dst_pmap, pmap_t src_pmap, vm_offset_t dst_addr,
- vm_size_t len, vm_offset_t src_addr)
-{
-
- /*
- * This is not needed as it's mainly an optimisation.
- * It may want to be implemented later though.
- */
-}
-
-void
-pmap_copy_page(vm_page_t msrc, vm_page_t mdst)
-{
- vm_offset_t dst;
- vm_offset_t src;
-
- dst = VM_PAGE_TO_PHYS(mdst);
- src = VM_PAGE_TO_PHYS(msrc);
-
- kcopy((void *)src, (void *)dst, PAGE_SIZE);
-}
-
-/*
- * Zero a page of physical memory by temporarily mapping it into the tlb.
- */
-void
-pmap_zero_page(vm_page_t m)
-{
- vm_offset_t pa = VM_PAGE_TO_PHYS(m);
- caddr_t va;
-
- if (pa < SEGMENT_LENGTH) {
- va = (caddr_t) pa;
- } else if (pmap_initialized) {
- if (pmap_pvo_zeropage == NULL)
- pmap_pvo_zeropage = pmap_rkva_alloc();
- pmap_pa_map(pmap_pvo_zeropage, pa, NULL, NULL);
- va = (caddr_t)PVO_VADDR(pmap_pvo_zeropage);
- } else {
- panic("pmap_zero_page: can't zero pa %#x", pa);
- }
-
- bzero(va, PAGE_SIZE);
-
- if (pa >= SEGMENT_LENGTH)
- pmap_pa_unmap(pmap_pvo_zeropage, NULL, NULL);
-}
-
-void
-pmap_zero_page_area(vm_page_t m, int off, int size)
-{
- vm_offset_t pa = VM_PAGE_TO_PHYS(m);
- caddr_t va;
-
- if (pa < SEGMENT_LENGTH) {
- va = (caddr_t) pa;
- } else if (pmap_initialized) {
- if (pmap_pvo_zeropage == NULL)
- pmap_pvo_zeropage = pmap_rkva_alloc();
- pmap_pa_map(pmap_pvo_zeropage, pa, NULL, NULL);
- va = (caddr_t)PVO_VADDR(pmap_pvo_zeropage);
- } else {
- panic("pmap_zero_page: can't zero pa %#x", pa);
- }
-
- bzero(va + off, size);
-
- if (pa >= SEGMENT_LENGTH)
- pmap_pa_unmap(pmap_pvo_zeropage, NULL, NULL);
-}
-
-void
-pmap_zero_page_idle(vm_page_t m)
-{
-
- /* XXX this is called outside of Giant, is pmap_zero_page safe? */
- /* XXX maybe have a dedicated mapping for this to avoid the problem? */
- mtx_lock(&Giant);
- pmap_zero_page(m);
- mtx_unlock(&Giant);
-}
-
-/*
- * Map the given physical page at the specified virtual address in the
- * target pmap with the protection requested. If specified the page
- * will be wired down.
- */
-void
-pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot,
- boolean_t wired)
-{
- struct pvo_head *pvo_head;
- uma_zone_t zone;
- vm_page_t pg;
- u_int pte_lo, pvo_flags, was_exec, i;
- int error;
-
- if (!pmap_initialized) {
- pvo_head = &pmap_pvo_kunmanaged;
- zone = pmap_upvo_zone;
- pvo_flags = 0;
- pg = NULL;
- was_exec = PTE_EXEC;
- } else {
- pvo_head = vm_page_to_pvoh(m);
- pg = m;
- zone = pmap_mpvo_zone;
- pvo_flags = PVO_MANAGED;
- was_exec = 0;
- }
-
- /*
- * If this is a managed page, and it's the first reference to the page,
- * clear the execness of the page. Otherwise fetch the execness.
- */
- if (pg != NULL) {
- if (LIST_EMPTY(pvo_head)) {
- pmap_attr_clear(pg, PTE_EXEC);
- } else {
- was_exec = pmap_attr_fetch(pg) & PTE_EXEC;
- }
- }
-
-
- /*
- * Assume the page is cache inhibited and access is guarded unless
- * it's in our available memory array.
- */
- pte_lo = PTE_I | PTE_G;
- for (i = 0; i < pregions_sz; i++) {
- if ((VM_PAGE_TO_PHYS(m) >= pregions[i].mr_start) &&
- (VM_PAGE_TO_PHYS(m) <
- (pregions[i].mr_start + pregions[i].mr_size))) {
- pte_lo &= ~(PTE_I | PTE_G);
- break;
- }
- }
-
- if (prot & VM_PROT_WRITE)
- pte_lo |= PTE_BW;
- else
- pte_lo |= PTE_BR;
-
- pvo_flags |= (prot & VM_PROT_EXECUTE);
-
- if (wired)
- pvo_flags |= PVO_WIRED;
-
- error = pmap_pvo_enter(pmap, zone, pvo_head, va, VM_PAGE_TO_PHYS(m),
- pte_lo, pvo_flags);
-
- /*
- * Flush the real page from the instruction cache if this page is
- * mapped executable and cacheable and was not previously mapped (or
- * was not mapped executable).
- */
- if (error == 0 && (pvo_flags & PVO_EXECUTABLE) &&
- (pte_lo & PTE_I) == 0 && was_exec == 0) {
- /*
- * Flush the real memory from the cache.
- */
- pmap_syncicache(VM_PAGE_TO_PHYS(m), PAGE_SIZE);
- if (pg != NULL)
- pmap_attr_save(pg, PTE_EXEC);
- }
-
- /* XXX syncicache always until problems are sorted */
- pmap_syncicache(VM_PAGE_TO_PHYS(m), PAGE_SIZE);
-}
-
-vm_offset_t
-pmap_extract(pmap_t pm, vm_offset_t va)
-{
- struct pvo_entry *pvo;
-
- pvo = pmap_pvo_find_va(pm, va & ~ADDR_POFF, NULL);
-
- if (pvo != NULL) {
- return ((pvo->pvo_pte.pte_lo & PTE_RPGN) | (va & ADDR_POFF));
- }
-
- return (0);
-}
-
-/*
- * Grow the number of kernel page table entries. Unneeded.
- */
-void
-pmap_growkernel(vm_offset_t addr)
-{
-}
-
-void
-pmap_init(vm_offset_t phys_start, vm_offset_t phys_end)
-{
-
- CTR0(KTR_PMAP, "pmap_init");
-
- pmap_pvo_obj = vm_object_allocate(OBJT_PHYS, 16);
- pmap_pvo_count = 0;
- pmap_upvo_zone = uma_zcreate("UPVO entry", sizeof (struct pvo_entry),
- NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_VM);
- uma_zone_set_allocf(pmap_upvo_zone, pmap_pvo_allocf);
- pmap_mpvo_zone = uma_zcreate("MPVO entry", sizeof(struct pvo_entry),
- NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_VM);
- uma_zone_set_allocf(pmap_mpvo_zone, pmap_pvo_allocf);
- pmap_initialized = TRUE;
-}
-
-void
-pmap_init2(void)
-{
-
- CTR0(KTR_PMAP, "pmap_init2");
-}
-
-boolean_t
-pmap_is_modified(vm_page_t m)
-{
-
- if ((m->flags & (PG_FICTITIOUS |PG_UNMANAGED)) != 0)
- return (FALSE);
-
- return (pmap_query_bit(m, PTE_CHG));
-}
-
-void
-pmap_clear_reference(vm_page_t m)
-{
-
- if ((m->flags & (PG_FICTITIOUS | PG_UNMANAGED)) != 0)
- return;
- pmap_clear_bit(m, PTE_REF, NULL);
-}
-
-void
-pmap_clear_modify(vm_page_t m)
-{
-
- if ((m->flags & (PG_FICTITIOUS | PG_UNMANAGED)) != 0)
- return;
- pmap_clear_bit(m, PTE_CHG, NULL);
-}
-
-/*
- * pmap_ts_referenced:
- *
- * Return a count of reference bits for a page, clearing those bits.
- * It is not necessary for every reference bit to be cleared, but it
- * is necessary that 0 only be returned when there are truly no
- * reference bits set.
- *
- * XXX: The exact number of bits to check and clear is a matter that
- * should be tested and standardized at some point in the future for
- * optimal aging of shared pages.
- */
-int
-pmap_ts_referenced(vm_page_t m)
-{
- int count;
-
- if ((m->flags & (PG_FICTITIOUS | PG_UNMANAGED)) != 0)
- return (0);
-
- count = pmap_clear_bit(m, PTE_REF, NULL);
-
- return (count);
-}
-
-/*
- * Map a wired page into kernel virtual address space.
- */
-void
-pmap_kenter(vm_offset_t va, vm_offset_t pa)
-{
- u_int pte_lo;
- int error;
- int i;
-
-#if 0
- if (va < VM_MIN_KERNEL_ADDRESS)
- panic("pmap_kenter: attempt to enter non-kernel address %#x",
- va);
-#endif
-
- pte_lo = PTE_I | PTE_G;
- for (i = 0; i < pregions_sz; i++) {
- if ((pa >= pregions[i].mr_start) &&
- (pa < (pregions[i].mr_start + pregions[i].mr_size))) {
- pte_lo &= ~(PTE_I | PTE_G);
- break;
- }
- }
-
- error = pmap_pvo_enter(kernel_pmap, pmap_upvo_zone,
- &pmap_pvo_kunmanaged, va, pa, pte_lo, PVO_WIRED);
-
- if (error != 0 && error != ENOENT)
- panic("pmap_kenter: failed to enter va %#x pa %#x: %d", va,
- pa, error);
-
- /*
- * Flush the real memory from the instruction cache.
- */
- if ((pte_lo & (PTE_I | PTE_G)) == 0) {
- pmap_syncicache(pa, PAGE_SIZE);
- }
-}
-
-/*
- * Extract the physical page address associated with the given kernel virtual
- * address.
- */
-vm_offset_t
-pmap_kextract(vm_offset_t va)
-{
- struct pvo_entry *pvo;
-
- pvo = pmap_pvo_find_va(kernel_pmap, va & ~ADDR_POFF, NULL);
- if (pvo == NULL) {
- return (0);
- }
-
- return ((pvo->pvo_pte.pte_lo & PTE_RPGN) | (va & ADDR_POFF));
-}
-
-/*
- * Remove a wired page from kernel virtual address space.
- */
-void
-pmap_kremove(vm_offset_t va)
-{
-
- pmap_remove(kernel_pmap, va, va + PAGE_SIZE);
-}
-
-/*
- * Map a range of physical addresses into kernel virtual address space.
- *
- * The value passed in *virt is a suggested virtual address for the mapping.
- * Architectures which can support a direct-mapped physical to virtual region
- * can return the appropriate address within that region, leaving '*virt'
- * unchanged. We cannot and therefore do not; *virt is updated with the
- * first usable address after the mapped region.
- */
-vm_offset_t
-pmap_map(vm_offset_t *virt, vm_offset_t pa_start, vm_offset_t pa_end, int prot)
-{
- vm_offset_t sva, va;
-
- sva = *virt;
- va = sva;
- for (; pa_start < pa_end; pa_start += PAGE_SIZE, va += PAGE_SIZE)
- pmap_kenter(va, pa_start);
- *virt = va;
- return (sva);
-}
-
-int
-pmap_mincore(pmap_t pmap, vm_offset_t addr)
-{
- TODO;
- return (0);
-}
-
-void
-pmap_object_init_pt(pmap_t pm, vm_offset_t addr, vm_object_t object,
- vm_pindex_t pindex, vm_size_t size, int limit)
-{
-
- KASSERT(pm == &curproc->p_vmspace->vm_pmap || pm == kernel_pmap,
- ("pmap_remove_pages: non current pmap"));
- /* XXX */
-}
-
-/*
- * Lower the permission for all mappings to a given page.
- */
-void
-pmap_page_protect(vm_page_t m, vm_prot_t prot)
-{
- struct pvo_head *pvo_head;
- struct pvo_entry *pvo, *next_pvo;
- struct pte *pt;
-
- /*
- * Since the routine only downgrades protection, if the
- * maximal protection is desired, there isn't any change
- * to be made.
- */
- if ((prot & (VM_PROT_READ|VM_PROT_WRITE)) ==
- (VM_PROT_READ|VM_PROT_WRITE))
- return;
-
- pvo_head = vm_page_to_pvoh(m);
- for (pvo = LIST_FIRST(pvo_head); pvo != NULL; pvo = next_pvo) {
- next_pvo = LIST_NEXT(pvo, pvo_vlink);
- PMAP_PVO_CHECK(pvo); /* sanity check */
-
- /*
- * Downgrading to no mapping at all, we just remove the entry.
- */
- if ((prot & VM_PROT_READ) == 0) {
- pmap_pvo_remove(pvo, -1);
- continue;
- }
-
- /*
- * If EXEC permission is being revoked, just clear the flag
- * in the PVO.
- */
- if ((prot & VM_PROT_EXECUTE) == 0)
- pvo->pvo_vaddr &= ~PVO_EXECUTABLE;
-
- /*
- * If this entry is already RO, don't diddle with the page
- * table.
- */
- if ((pvo->pvo_pte.pte_lo & PTE_PP) == PTE_BR) {
- PMAP_PVO_CHECK(pvo);
- continue;
- }
-
- /*
- * Grab the PTE before we diddle the bits so pvo_to_pte can
- * verify the pte contents are as expected.
- */
- pt = pmap_pvo_to_pte(pvo, -1);
- pvo->pvo_pte.pte_lo &= ~PTE_PP;
- pvo->pvo_pte.pte_lo |= PTE_BR;
- if (pt != NULL)
- pmap_pte_change(pt, &pvo->pvo_pte, pvo->pvo_vaddr);
- PMAP_PVO_CHECK(pvo); /* sanity check */
- }
-}
-
-/*
- * Returns true if the pmap's pv is one of the first
- * 16 pvs linked to from this page. This count may
- * be changed upwards or downwards in the future; it
- * is only necessary that true be returned for a small
- * subset of pmaps for proper page aging.
- */
-boolean_t
-pmap_page_exists_quick(pmap_t pmap, vm_page_t m)
-{
- int loops;
- struct pvo_entry *pvo;
-
- if (!pmap_initialized || (m->flags & PG_FICTITIOUS))
- return FALSE;
-
- loops = 0;
- LIST_FOREACH(pvo, vm_page_to_pvoh(m), pvo_vlink) {
- if (pvo->pvo_pmap == pmap)
- return (TRUE);
- if (++loops >= 16)
- break;
- }
-
- return (FALSE);
-}
-
-static u_int pmap_vsidcontext;
-
-void
-pmap_pinit(pmap_t pmap)
-{
- int i, mask;
- u_int entropy;
-
- entropy = 0;
- __asm __volatile("mftb %0" : "=r"(entropy));
-
- /*
- * Allocate some segment registers for this pmap.
- */
- for (i = 0; i < NPMAPS; i += VSID_NBPW) {
- u_int hash, n;
-
- /*
- * Create a new value by mutiplying by a prime and adding in
- * entropy from the timebase register. This is to make the
- * VSID more random so that the PT hash function collides
- * less often. (Note that the prime casues gcc to do shifts
- * instead of a multiply.)
- */
- pmap_vsidcontext = (pmap_vsidcontext * 0x1105) + entropy;
- hash = pmap_vsidcontext & (NPMAPS - 1);
- if (hash == 0) /* 0 is special, avoid it */
- continue;
- n = hash >> 5;
- mask = 1 << (hash & (VSID_NBPW - 1));
- hash = (pmap_vsidcontext & 0xfffff);
- if (pmap_vsid_bitmap[n] & mask) { /* collision? */
- /* anything free in this bucket? */
- if (pmap_vsid_bitmap[n] == 0xffffffff) {
- entropy = (pmap_vsidcontext >> 20);
- continue;
- }
- i = ffs(~pmap_vsid_bitmap[i]) - 1;
- mask = 1 << i;
- hash &= 0xfffff & ~(VSID_NBPW - 1);
- hash |= i;
- }
- pmap_vsid_bitmap[n] |= mask;
- for (i = 0; i < 16; i++)
- pmap->pm_sr[i] = VSID_MAKE(i, hash);
- return;
- }
-
- panic("pmap_pinit: out of segments");
-}
-
-/*
- * Initialize the pmap associated with process 0.
- */
-void
-pmap_pinit0(pmap_t pm)
-{
-
- pmap_pinit(pm);
- bzero(&pm->pm_stats, sizeof(pm->pm_stats));
-}
-
-void
-pmap_pinit2(pmap_t pmap)
-{
- /* XXX: Remove this stub when no longer called */
-}
-
-void
-pmap_prefault(pmap_t pm, vm_offset_t va, vm_map_entry_t entry)
-{
- KASSERT(pm == &curproc->p_vmspace->vm_pmap || pm == kernel_pmap,
- ("pmap_prefault: non current pmap"));
- /* XXX */
-}
-
-/*
- * Set the physical protection on the specified range of this map as requested.
- */
-void
-pmap_protect(pmap_t pm, vm_offset_t sva, vm_offset_t eva, vm_prot_t prot)
-{
- struct pvo_entry *pvo;
- struct pte *pt;
- int pteidx;
-
- CTR4(KTR_PMAP, "pmap_protect: pm=%p sva=%#x eva=%#x prot=%#x", pm, sva,
- eva, prot);
-
-
- KASSERT(pm == &curproc->p_vmspace->vm_pmap || pm == kernel_pmap,
- ("pmap_protect: non current pmap"));
-
- if ((prot & VM_PROT_READ) == VM_PROT_NONE) {
- pmap_remove(pm, sva, eva);
- return;
- }
-
- for (; sva < eva; sva += PAGE_SIZE) {
- pvo = pmap_pvo_find_va(pm, sva, &pteidx);
- if (pvo == NULL)
- continue;
-
- if ((prot & VM_PROT_EXECUTE) == 0)
- pvo->pvo_vaddr &= ~PVO_EXECUTABLE;
-
- /*
- * Grab the PTE pointer before we diddle with the cached PTE
- * copy.
- */
- pt = pmap_pvo_to_pte(pvo, pteidx);
- /*
- * Change the protection of the page.
- */
- pvo->pvo_pte.pte_lo &= ~PTE_PP;
- pvo->pvo_pte.pte_lo |= PTE_BR;
-
- /*
- * If the PVO is in the page table, update that pte as well.
- */
- if (pt != NULL)
- pmap_pte_change(pt, &pvo->pvo_pte, pvo->pvo_vaddr);
- }
-}
-
-/*
- * Map a list of wired pages into kernel virtual address space. This is
- * intended for temporary mappings which do not need page modification or
- * references recorded. Existing mappings in the region are overwritten.
- */
-void
-pmap_qenter(vm_offset_t sva, vm_page_t *m, int count)
-{
- vm_offset_t va;
-
- va = sva;
- while (count-- > 0) {
- pmap_kenter(va, VM_PAGE_TO_PHYS(*m));
- va += PAGE_SIZE;
- m++;
- }
-}
-
-/*
- * Remove page mappings from kernel virtual address space. Intended for
- * temporary mappings entered by pmap_qenter.
- */
-void
-pmap_qremove(vm_offset_t sva, int count)
-{
- vm_offset_t va;
-
- va = sva;
- while (count-- > 0) {
- pmap_kremove(va);
- va += PAGE_SIZE;
- }
-}
-
-void
-pmap_release(pmap_t pmap)
-{
- int idx, mask;
-
- /*
- * Free segment register's VSID
- */
- if (pmap->pm_sr[0] == 0)
- panic("pmap_release");
-
- idx = VSID_TO_HASH(pmap->pm_sr[0]) & (NPMAPS-1);
- mask = 1 << (idx % VSID_NBPW);
- idx /= VSID_NBPW;
- pmap_vsid_bitmap[idx] &= ~mask;
-}
-
-/*
- * Remove the given range of addresses from the specified map.
- */
-void
-pmap_remove(pmap_t pm, vm_offset_t sva, vm_offset_t eva)
-{
- struct pvo_entry *pvo;
- int pteidx;
-
- for (; sva < eva; sva += PAGE_SIZE) {
- pvo = pmap_pvo_find_va(pm, sva, &pteidx);
- if (pvo != NULL) {
- pmap_pvo_remove(pvo, pteidx);
- }
- }
-}
-
-/*
- * Remove physical page from all pmaps in which it resides. pmap_pvo_remove()
- * will reflect changes in pte's back to the vm_page.
- */
-void
-pmap_remove_all(vm_page_t m)
-{
- struct pvo_head *pvo_head;
- struct pvo_entry *pvo, *next_pvo;
-
- KASSERT((m->flags & (PG_FICTITIOUS|PG_UNMANAGED)) == 0,
- ("pv_remove_all: illegal for unmanaged page %#x",
- VM_PAGE_TO_PHYS(m)));
-
- pvo_head = vm_page_to_pvoh(m);
- for (pvo = LIST_FIRST(pvo_head); pvo != NULL; pvo = next_pvo) {
- next_pvo = LIST_NEXT(pvo, pvo_vlink);
-
- PMAP_PVO_CHECK(pvo); /* sanity check */
- pmap_pvo_remove(pvo, -1);
- }
- vm_page_flag_clear(m, PG_WRITEABLE);
-}
-
-/*
- * Remove all pages from specified address space, this aids process exit
- * speeds. This is much faster than pmap_remove in the case of running down
- * an entire address space. Only works for the current pmap.
- */
-void
-pmap_remove_pages(pmap_t pm, vm_offset_t sva, vm_offset_t eva)
-{
-
- KASSERT(pm == &curproc->p_vmspace->vm_pmap || pm == kernel_pmap,
- ("pmap_remove_pages: non current pmap"));
- pmap_remove(pm, sva, eva);
-}
-
-#ifndef KSTACK_MAX_PAGES
-#define KSTACK_MAX_PAGES 32
-#endif
-
-/*
- * Create the kernel stack and pcb for a new thread.
- * This routine directly affects the fork perf for a process and
- * create performance for a thread.
- */
-void
-pmap_new_thread(struct thread *td, int pages)
-{
- vm_page_t ma[KSTACK_MAX_PAGES];
- vm_object_t ksobj;
- vm_offset_t ks;
- vm_page_t m;
- u_int i;
-
- /* Bounds check */
- if (pages <= 1)
- pages = KSTACK_PAGES;
- else if (pages > KSTACK_MAX_PAGES)
- pages = KSTACK_MAX_PAGES;
-
- /*
- * Allocate object for the kstack.
- */
- ksobj = vm_object_allocate(OBJT_DEFAULT, pages);
- td->td_kstack_obj = ksobj;
-
- /*
- * Get a kernel virtual address for the kstack for this thread.
- */
- ks = kmem_alloc_nofault(kernel_map,
- (pages + KSTACK_GUARD_PAGES) * PAGE_SIZE);
- if (ks == 0)
- panic("pmap_new_thread: kstack allocation failed");
- TLBIE(ks);
- ks += KSTACK_GUARD_PAGES * PAGE_SIZE;
- td->td_kstack = ks;
-
- /*
- * Knowing the number of pages allocated is useful when you
- * want to deallocate them.
- */
- td->td_kstack_pages = pages;
-
- for (i = 0; i < pages; i++) {
- /*
- * Get a kernel stack page.
- */
- m = vm_page_grab(ksobj, i,
- VM_ALLOC_NORMAL | VM_ALLOC_RETRY | VM_ALLOC_WIRED);
- ma[i] = m;
-
- vm_page_lock_queues();
- vm_page_wakeup(m);
- vm_page_flag_clear(m, PG_ZERO);
- m->valid = VM_PAGE_BITS_ALL;
- vm_page_unlock_queues();
- }
-
- /*
- * Enter the page into the kernel address space
- */
- pmap_qenter(ks, ma, pages);
-}
-
-void
-pmap_dispose_thread(struct thread *td)
-{
- vm_object_t ksobj;
- vm_offset_t ks;
- vm_page_t m;
- int i;
- int pages;
-
- pages = td->td_kstack_pages;
- ksobj = td->td_kstack_obj;
- ks = td->td_kstack;
- for (i = 0; i < pages ; i++) {
- m = vm_page_lookup(ksobj, i);
- if (m == NULL)
- panic("pmap_dispose_thread: kstack already missing?");
- vm_page_lock_queues();
- vm_page_busy(m);
- vm_page_unwire(m, 0);
- vm_page_free(m);
- vm_page_unlock_queues();
- }
- pmap_qremove(ks, pages);
- kmem_free(kernel_map, ks - (KSTACK_GUARD_PAGES * PAGE_SIZE),
- (pages + KSTACK_GUARD_PAGES) * PAGE_SIZE);
- vm_object_deallocate(ksobj);
-}
-
-void
-pmap_new_altkstack(struct thread *td, int pages)
-{
- /* shuffle the original stack */
- td->td_altkstack_obj = td->td_kstack_obj;
- td->td_altkstack = td->td_kstack;
- td->td_altkstack_pages = td->td_kstack_pages;
-
- pmap_new_thread(td, pages);
-}
-
-void
-pmap_dispose_altkstack(struct thread *td)
-{
- pmap_dispose_thread(td);
-
- /* restore the original kstack */
- td->td_kstack = td->td_altkstack;
- td->td_kstack_obj = td->td_altkstack_obj;
- td->td_kstack_pages = td->td_altkstack_pages;
- td->td_altkstack = 0;
- td->td_altkstack_obj = NULL;
- td->td_altkstack_pages = 0;
-}
-
-void
-pmap_swapin_thread(struct thread *td)
-{
- vm_page_t ma[KSTACK_MAX_PAGES];
- vm_object_t ksobj;
- vm_offset_t ks;
- vm_page_t m;
- int rv;
- int i;
- int pages;
-
- pages = td->td_kstack_pages;
- ksobj = td->td_kstack_obj;
- ks = td->td_kstack;
- for (i = 0; i < pages; i++) {
- m = vm_page_grab(ksobj, i, VM_ALLOC_NORMAL | VM_ALLOC_RETRY);
- if (m->valid != VM_PAGE_BITS_ALL) {
- rv = vm_pager_get_pages(ksobj, &m, 1, 0);
- if (rv != VM_PAGER_OK)
- panic("pmap_swapin_thread: cannot get kstack");
- m = vm_page_lookup(ksobj, i);
- m->valid = VM_PAGE_BITS_ALL;
- }
- ma[i] = m;
- vm_page_lock_queues();
- vm_page_wire(m);
- vm_page_wakeup(m);
- vm_page_unlock_queues();
- }
- pmap_qenter(ks, ma, pages);
-}
-
-
-void
-pmap_swapout_thread(struct thread *td)
-{
- vm_object_t ksobj;
- vm_offset_t ks;
- vm_page_t m;
- int i;
- int pages;
-
- pages = td->td_kstack_pages;
- ksobj = td->td_kstack_obj;
- ks = (vm_offset_t)td->td_kstack;
- for (i = 0; i < pages; i++) {
- m = vm_page_lookup(ksobj, i);
- if (m == NULL)
- panic("pmap_swapout_thread: kstack already missing?");
- vm_page_lock_queues();
- vm_page_dirty(m);
- vm_page_unwire(m, 0);
- vm_page_unlock_queues();
- }
- pmap_qremove(ks, pages);
-}
-
-/*
- * Allocate a physical page of memory directly from the phys_avail map.
- * Can only be called from pmap_bootstrap before avail start and end are
- * calculated.
- */
-static vm_offset_t
-pmap_bootstrap_alloc(vm_size_t size, u_int align)
-{
- vm_offset_t s, e;
- int i, j;
-
- size = round_page(size);
- for (i = 0; phys_avail[i + 1] != 0; i += 2) {
- if (align != 0)
- s = (phys_avail[i] + align - 1) & ~(align - 1);
- else
- s = phys_avail[i];
- e = s + size;
-
- if (s < phys_avail[i] || e > phys_avail[i + 1])
- continue;
-
- if (s == phys_avail[i]) {
- phys_avail[i] += size;
- } else if (e == phys_avail[i + 1]) {
- phys_avail[i + 1] -= size;
- } else {
- for (j = phys_avail_count * 2; j > i; j -= 2) {
- phys_avail[j] = phys_avail[j - 2];
- phys_avail[j + 1] = phys_avail[j - 1];
- }
-
- phys_avail[i + 3] = phys_avail[i + 1];
- phys_avail[i + 1] = s;
- phys_avail[i + 2] = e;
- phys_avail_count++;
- }
-
- return (s);
- }
- panic("pmap_bootstrap_alloc: could not allocate memory");
-}
-
-/*
- * Return an unmapped pvo for a kernel virtual address.
- * Used by pmap functions that operate on physical pages.
- */
-static struct pvo_entry *
-pmap_rkva_alloc(void)
-{
- struct pvo_entry *pvo;
- struct pte *pt;
- vm_offset_t kva;
- int pteidx;
-
- if (pmap_rkva_count == 0)
- panic("pmap_rkva_alloc: no more reserved KVAs");
-
- kva = pmap_rkva_start + (PAGE_SIZE * --pmap_rkva_count);
- pmap_kenter(kva, 0);
-
- pvo = pmap_pvo_find_va(kernel_pmap, kva, &pteidx);
-
- if (pvo == NULL)
- panic("pmap_kva_alloc: pmap_pvo_find_va failed");
-
- pt = pmap_pvo_to_pte(pvo, pteidx);
-
- if (pt == NULL)
- panic("pmap_kva_alloc: pmap_pvo_to_pte failed");
-
- pmap_pte_unset(pt, &pvo->pvo_pte, pvo->pvo_vaddr);
- PVO_PTEGIDX_CLR(pvo);
-
- pmap_pte_overflow++;
-
- return (pvo);
-}
-
-static void
-pmap_pa_map(struct pvo_entry *pvo, vm_offset_t pa, struct pte *saved_pt,
- int *depth_p)
-{
- struct pte *pt;
-
- /*
- * If this pvo already has a valid pte, we need to save it so it can
- * be restored later. We then just reload the new PTE over the old
- * slot.
- */
- if (saved_pt != NULL) {
- pt = pmap_pvo_to_pte(pvo, -1);
-
- if (pt != NULL) {
- pmap_pte_unset(pt, &pvo->pvo_pte, pvo->pvo_vaddr);
- PVO_PTEGIDX_CLR(pvo);
- pmap_pte_overflow++;
- }
-
- *saved_pt = pvo->pvo_pte;
-
- pvo->pvo_pte.pte_lo &= ~PTE_RPGN;
- }
-
- pvo->pvo_pte.pte_lo |= pa;
-
- if (!pmap_pte_spill(pvo->pvo_vaddr))
- panic("pmap_pa_map: could not spill pvo %p", pvo);
-
- if (depth_p != NULL)
- (*depth_p)++;
-}
-
-static void
-pmap_pa_unmap(struct pvo_entry *pvo, struct pte *saved_pt, int *depth_p)
-{
- struct pte *pt;
-
- pt = pmap_pvo_to_pte(pvo, -1);
-
- if (pt != NULL) {
- pmap_pte_unset(pt, &pvo->pvo_pte, pvo->pvo_vaddr);
- PVO_PTEGIDX_CLR(pvo);
- pmap_pte_overflow++;
- }
-
- pvo->pvo_pte.pte_lo &= ~PTE_RPGN;
-
- /*
- * If there is a saved PTE and it's valid, restore it and return.
- */
- if (saved_pt != NULL && (saved_pt->pte_lo & PTE_RPGN) != 0) {
- if (depth_p != NULL && --(*depth_p) == 0)
- panic("pmap_pa_unmap: restoring but depth == 0");
-
- pvo->pvo_pte = *saved_pt;
-
- if (!pmap_pte_spill(pvo->pvo_vaddr))
- panic("pmap_pa_unmap: could not spill pvo %p", pvo);
- }
-}
-
-static void
-pmap_syncicache(vm_offset_t pa, vm_size_t len)
-{
- __syncicache((void *)pa, len);
-}
-
-static void
-tlbia(void)
-{
- caddr_t i;
-
- SYNC();
- for (i = 0; i < (caddr_t)0x00040000; i += 0x00001000) {
- TLBIE(i);
- EIEIO();
- }
- TLBSYNC();
- SYNC();
-}
-
-static int
-pmap_pvo_enter(pmap_t pm, uma_zone_t zone, struct pvo_head *pvo_head,
- vm_offset_t va, vm_offset_t pa, u_int pte_lo, int flags)
-{
- struct pvo_entry *pvo;
- u_int sr;
- int first;
- u_int ptegidx;
- int i;
- int bootstrap;
-
- pmap_pvo_enter_calls++;
- first = 0;
-
- bootstrap = 0;
-
- /*
- * Compute the PTE Group index.
- */
- va &= ~ADDR_POFF;
- sr = va_to_sr(pm->pm_sr, va);
- ptegidx = va_to_pteg(sr, va);
-
- /*
- * Remove any existing mapping for this page. Reuse the pvo entry if
- * there is a mapping.
- */
- LIST_FOREACH(pvo, &pmap_pvo_table[ptegidx], pvo_olink) {
- if (pvo->pvo_pmap == pm && PVO_VADDR(pvo) == va) {
- if ((pvo->pvo_pte.pte_lo & PTE_RPGN) == pa &&
- (pvo->pvo_pte.pte_lo & PTE_PP) ==
- (pte_lo & PTE_PP)) {
- return (0);
- }
- pmap_pvo_remove(pvo, -1);
- break;
- }
- }
-
- /*
- * If we aren't overwriting a mapping, try to allocate.
- */
- if (pmap_initialized) {
- pvo = uma_zalloc(zone, M_NOWAIT);
- } else {
- if (pmap_bpvo_pool_index >= BPVO_POOL_SIZE) {
- panic("pmap_enter: bpvo pool exhausted, %d, %d, %d",
- pmap_bpvo_pool_index, BPVO_POOL_SIZE,
- BPVO_POOL_SIZE * sizeof(struct pvo_entry));
- }
- pvo = &pmap_bpvo_pool[pmap_bpvo_pool_index];
- pmap_bpvo_pool_index++;
- bootstrap = 1;
- }
-
- if (pvo == NULL) {
- return (ENOMEM);
- }
-
- pmap_pvo_entries++;
- pvo->pvo_vaddr = va;
- pvo->pvo_pmap = pm;
- LIST_INSERT_HEAD(&pmap_pvo_table[ptegidx], pvo, pvo_olink);
- pvo->pvo_vaddr &= ~ADDR_POFF;
- if (flags & VM_PROT_EXECUTE)
- pvo->pvo_vaddr |= PVO_EXECUTABLE;
- if (flags & PVO_WIRED)
- pvo->pvo_vaddr |= PVO_WIRED;
- if (pvo_head != &pmap_pvo_kunmanaged)
- pvo->pvo_vaddr |= PVO_MANAGED;
- if (bootstrap)
- pvo->pvo_vaddr |= PVO_BOOTSTRAP;
- pmap_pte_create(&pvo->pvo_pte, sr, va, pa | pte_lo);
-
- /*
- * Remember if the list was empty and therefore will be the first
- * item.
- */
- if (LIST_FIRST(pvo_head) == NULL)
- first = 1;
-
- LIST_INSERT_HEAD(pvo_head, pvo, pvo_vlink);
- if (pvo->pvo_pte.pte_lo & PVO_WIRED)
- pvo->pvo_pmap->pm_stats.wired_count++;
- pvo->pvo_pmap->pm_stats.resident_count++;
-
- /*
- * We hope this succeeds but it isn't required.
- */
- i = pmap_pte_insert(ptegidx, &pvo->pvo_pte);
- if (i >= 0) {
- PVO_PTEGIDX_SET(pvo, i);
- } else {
- panic("pmap_pvo_enter: overflow");
- pmap_pte_overflow++;
- }
-
- return (first ? ENOENT : 0);
-}
-
-static void
-pmap_pvo_remove(struct pvo_entry *pvo, int pteidx)
-{
- struct pte *pt;
-
- /*
- * If there is an active pte entry, we need to deactivate it (and
- * save the ref & cfg bits).
- */
- pt = pmap_pvo_to_pte(pvo, pteidx);
- if (pt != NULL) {
- pmap_pte_unset(pt, &pvo->pvo_pte, pvo->pvo_vaddr);
- PVO_PTEGIDX_CLR(pvo);
- } else {
- pmap_pte_overflow--;
- }
-
- /*
- * Update our statistics.
- */
- pvo->pvo_pmap->pm_stats.resident_count--;
- if (pvo->pvo_pte.pte_lo & PVO_WIRED)
- pvo->pvo_pmap->pm_stats.wired_count--;
-
- /*
- * Save the REF/CHG bits into their cache if the page is managed.
- */
- if (pvo->pvo_vaddr & PVO_MANAGED) {
- struct vm_page *pg;
-
- pg = PHYS_TO_VM_PAGE(pvo->pvo_pte.pte_lo & PTE_RPGN);
- if (pg != NULL) {
- pmap_attr_save(pg, pvo->pvo_pte.pte_lo &
- (PTE_REF | PTE_CHG));
- }
- }
-
- /*
- * Remove this PVO from the PV list.
- */
- LIST_REMOVE(pvo, pvo_vlink);
-
- /*
- * Remove this from the overflow list and return it to the pool
- * if we aren't going to reuse it.
- */
- LIST_REMOVE(pvo, pvo_olink);
- if (!(pvo->pvo_vaddr & PVO_BOOTSTRAP))
- uma_zfree(pvo->pvo_vaddr & PVO_MANAGED ? pmap_mpvo_zone :
- pmap_upvo_zone, pvo);
- pmap_pvo_entries--;
- pmap_pvo_remove_calls++;
-}
-
-static __inline int
-pmap_pvo_pte_index(const struct pvo_entry *pvo, int ptegidx)
-{
- int pteidx;
-
- /*
- * We can find the actual pte entry without searching by grabbing
- * the PTEG index from 3 unused bits in pte_lo[11:9] and by
- * noticing the HID bit.
- */
- pteidx = ptegidx * 8 + PVO_PTEGIDX_GET(pvo);
- if (pvo->pvo_pte.pte_hi & PTE_HID)
- pteidx ^= pmap_pteg_mask * 8;
-
- return (pteidx);
-}
-
-static struct pvo_entry *
-pmap_pvo_find_va(pmap_t pm, vm_offset_t va, int *pteidx_p)
-{
- struct pvo_entry *pvo;
- int ptegidx;
- u_int sr;
-
- va &= ~ADDR_POFF;
- sr = va_to_sr(pm->pm_sr, va);
- ptegidx = va_to_pteg(sr, va);
-
- LIST_FOREACH(pvo, &pmap_pvo_table[ptegidx], pvo_olink) {
- if (pvo->pvo_pmap == pm && PVO_VADDR(pvo) == va) {
- if (pteidx_p)
- *pteidx_p = pmap_pvo_pte_index(pvo, ptegidx);
- return (pvo);
- }
- }
-
- return (NULL);
-}
-
-static struct pte *
-pmap_pvo_to_pte(const struct pvo_entry *pvo, int pteidx)
-{
- struct pte *pt;
-
- /*
- * If we haven't been supplied the ptegidx, calculate it.
- */
- if (pteidx == -1) {
- int ptegidx;
- u_int sr;
-
- sr = va_to_sr(pvo->pvo_pmap->pm_sr, pvo->pvo_vaddr);
- ptegidx = va_to_pteg(sr, pvo->pvo_vaddr);
- pteidx = pmap_pvo_pte_index(pvo, ptegidx);
- }
-
- pt = &pmap_pteg_table[pteidx >> 3].pt[pteidx & 7];
-
- if ((pvo->pvo_pte.pte_hi & PTE_VALID) && !PVO_PTEGIDX_ISSET(pvo)) {
- panic("pmap_pvo_to_pte: pvo %p has valid pte in pvo but no "
- "valid pte index", pvo);
- }
-
- if ((pvo->pvo_pte.pte_hi & PTE_VALID) == 0 && PVO_PTEGIDX_ISSET(pvo)) {
- panic("pmap_pvo_to_pte: pvo %p has valid pte index in pvo "
- "pvo but no valid pte", pvo);
- }
-
- if ((pt->pte_hi ^ (pvo->pvo_pte.pte_hi & ~PTE_VALID)) == PTE_VALID) {
- if ((pvo->pvo_pte.pte_hi & PTE_VALID) == 0) {
- panic("pmap_pvo_to_pte: pvo %p has valid pte in "
- "pmap_pteg_table %p but invalid in pvo", pvo, pt);
- }
-
- if (((pt->pte_lo ^ pvo->pvo_pte.pte_lo) & ~(PTE_CHG|PTE_REF))
- != 0) {
- panic("pmap_pvo_to_pte: pvo %p pte does not match "
- "pte %p in pmap_pteg_table", pvo, pt);
- }
-
- return (pt);
- }
-
- if (pvo->pvo_pte.pte_hi & PTE_VALID) {
- panic("pmap_pvo_to_pte: pvo %p has invalid pte %p in "
- "pmap_pteg_table but valid in pvo", pvo, pt);
- }
-
- return (NULL);
-}
-
-static void *
-pmap_pvo_allocf(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
-{
- vm_page_t m;
-
- if (bytes != PAGE_SIZE)
- panic("pmap_pvo_allocf: benno was shortsighted. hit him.");
-
- *flags = UMA_SLAB_PRIV;
- m = vm_page_alloc(pmap_pvo_obj, pmap_pvo_count, VM_ALLOC_SYSTEM);
- if (m == NULL)
- return (NULL);
- pmap_pvo_count++;
- return ((void *)VM_PAGE_TO_PHYS(m));
-}
-
-/*
- * XXX: THIS STUFF SHOULD BE IN pte.c?
- */
-int
-pmap_pte_spill(vm_offset_t addr)
-{
- struct pvo_entry *source_pvo, *victim_pvo;
- struct pvo_entry *pvo;
- int ptegidx, i, j;
- u_int sr;
- struct pteg *pteg;
- struct pte *pt;
-
- pmap_pte_spills++;
-
- sr = mfsrin(addr);
- ptegidx = va_to_pteg(sr, addr);
-
- /*
- * Have to substitute some entry. Use the primary hash for this.
- * Use low bits of timebase as random generator.
- */
- pteg = &pmap_pteg_table[ptegidx];
- __asm __volatile("mftb %0" : "=r"(i));
- i &= 7;
- pt = &pteg->pt[i];
-
- source_pvo = NULL;
- victim_pvo = NULL;
- LIST_FOREACH(pvo, &pmap_pvo_table[ptegidx], pvo_olink) {
- /*
- * We need to find a pvo entry for this address.
- */
- PMAP_PVO_CHECK(pvo);
- if (source_pvo == NULL &&
- pmap_pte_match(&pvo->pvo_pte, sr, addr,
- pvo->pvo_pte.pte_hi & PTE_HID)) {
- /*
- * Now found an entry to be spilled into the pteg.
- * The PTE is now valid, so we know it's active.
- */
- j = pmap_pte_insert(ptegidx, &pvo->pvo_pte);
-
- if (j >= 0) {
- PVO_PTEGIDX_SET(pvo, j);
- pmap_pte_overflow--;
- PMAP_PVO_CHECK(pvo);
- return (1);
- }
-
- source_pvo = pvo;
-
- if (victim_pvo != NULL)
- break;
- }
-
- /*
- * We also need the pvo entry of the victim we are replacing
- * so save the R & C bits of the PTE.
- */
- if ((pt->pte_hi & PTE_HID) == 0 && victim_pvo == NULL &&
- pmap_pte_compare(pt, &pvo->pvo_pte)) {
- victim_pvo = pvo;
- if (source_pvo != NULL)
- break;
- }
- }
-
- if (source_pvo == NULL)
- return (0);
-
- if (victim_pvo == NULL) {
- if ((pt->pte_hi & PTE_HID) == 0)
- panic("pmap_pte_spill: victim p-pte (%p) has no pvo"
- "entry", pt);
-
- /*
- * If this is a secondary PTE, we need to search it's primary
- * pvo bucket for the matching PVO.
- */
- LIST_FOREACH(pvo, &pmap_pvo_table[ptegidx ^ pmap_pteg_mask],
- pvo_olink) {
- PMAP_PVO_CHECK(pvo);
- /*
- * We also need the pvo entry of the victim we are
- * replacing so save the R & C bits of the PTE.
- */
- if (pmap_pte_compare(pt, &pvo->pvo_pte)) {
- victim_pvo = pvo;
- break;
- }
- }
-
- if (victim_pvo == NULL)
- panic("pmap_pte_spill: victim s-pte (%p) has no pvo"
- "entry", pt);
- }
-
- /*
- * We are invalidating the TLB entry for the EA we are replacing even
- * though it's valid. If we don't, we lose any ref/chg bit changes
- * contained in the TLB entry.
- */
- source_pvo->pvo_pte.pte_hi &= ~PTE_HID;
-
- pmap_pte_unset(pt, &victim_pvo->pvo_pte, victim_pvo->pvo_vaddr);
- pmap_pte_set(pt, &source_pvo->pvo_pte);
-
- PVO_PTEGIDX_CLR(victim_pvo);
- PVO_PTEGIDX_SET(source_pvo, i);
- pmap_pte_replacements++;
-
- PMAP_PVO_CHECK(victim_pvo);
- PMAP_PVO_CHECK(source_pvo);
-
- return (1);
-}
-
-static int
-pmap_pte_insert(u_int ptegidx, struct pte *pvo_pt)
-{
- struct pte *pt;
- int i;
-
- /*
- * First try primary hash.
- */
- for (pt = pmap_pteg_table[ptegidx].pt, i = 0; i < 8; i++, pt++) {
- if ((pt->pte_hi & PTE_VALID) == 0) {
- pvo_pt->pte_hi &= ~PTE_HID;
- pmap_pte_set(pt, pvo_pt);
- return (i);
- }
- }
-
- /*
- * Now try secondary hash.
- */
- ptegidx ^= pmap_pteg_mask;
- ptegidx++;
- for (pt = pmap_pteg_table[ptegidx].pt, i = 0; i < 8; i++, pt++) {
- if ((pt->pte_hi & PTE_VALID) == 0) {
- pvo_pt->pte_hi |= PTE_HID;
- pmap_pte_set(pt, pvo_pt);
- return (i);
- }
- }
-
- panic("pmap_pte_insert: overflow");
- return (-1);
-}
-
-static boolean_t
-pmap_query_bit(vm_page_t m, int ptebit)
-{
- struct pvo_entry *pvo;
- struct pte *pt;
-
- if (pmap_attr_fetch(m) & ptebit)
- return (TRUE);
-
- LIST_FOREACH(pvo, vm_page_to_pvoh(m), pvo_vlink) {
- PMAP_PVO_CHECK(pvo); /* sanity check */
-
- /*
- * See if we saved the bit off. If so, cache it and return
- * success.
- */
- if (pvo->pvo_pte.pte_lo & ptebit) {
- pmap_attr_save(m, ptebit);
- PMAP_PVO_CHECK(pvo); /* sanity check */
- return (TRUE);
- }
- }
-
- /*
- * No luck, now go through the hard part of looking at the PTEs
- * themselves. Sync so that any pending REF/CHG bits are flushed to
- * the PTEs.
- */
- SYNC();
- LIST_FOREACH(pvo, vm_page_to_pvoh(m), pvo_vlink) {
- PMAP_PVO_CHECK(pvo); /* sanity check */
-
- /*
- * See if this pvo has a valid PTE. if so, fetch the
- * REF/CHG bits from the valid PTE. If the appropriate
- * ptebit is set, cache it and return success.
- */
- pt = pmap_pvo_to_pte(pvo, -1);
- if (pt != NULL) {
- pmap_pte_synch(pt, &pvo->pvo_pte);
- if (pvo->pvo_pte.pte_lo & ptebit) {
- pmap_attr_save(m, ptebit);
- PMAP_PVO_CHECK(pvo); /* sanity check */
- return (TRUE);
- }
- }
- }
-
- return (TRUE);
-}
-
-static u_int
-pmap_clear_bit(vm_page_t m, int ptebit, int *origbit)
-{
- u_int count;
- struct pvo_entry *pvo;
- struct pte *pt;
- int rv;
-
- /*
- * Clear the cached value.
- */
- rv = pmap_attr_fetch(m);
- pmap_attr_clear(m, ptebit);
-
- /*
- * Sync so that any pending REF/CHG bits are flushed to the PTEs (so
- * we can reset the right ones). note that since the pvo entries and
- * list heads are accessed via BAT0 and are never placed in the page
- * table, we don't have to worry about further accesses setting the
- * REF/CHG bits.
- */
- SYNC();
-
- /*
- * For each pvo entry, clear the pvo's ptebit. If this pvo has a
- * valid pte clear the ptebit from the valid pte.
- */
- count = 0;
- LIST_FOREACH(pvo, vm_page_to_pvoh(m), pvo_vlink) {
- PMAP_PVO_CHECK(pvo); /* sanity check */
- pt = pmap_pvo_to_pte(pvo, -1);
- if (pt != NULL) {
- pmap_pte_synch(pt, &pvo->pvo_pte);
- if (pvo->pvo_pte.pte_lo & ptebit) {
- count++;
- pmap_pte_clear(pt, PVO_VADDR(pvo), ptebit);
- }
- }
- rv |= pvo->pvo_pte.pte_lo;
- pvo->pvo_pte.pte_lo &= ~ptebit;
- PMAP_PVO_CHECK(pvo); /* sanity check */
- }
-
- if (origbit != NULL) {
- *origbit = rv;
- }
-
- return (count);
-}
-
-/*
- * Return true if the physical range is encompassed by the battable[idx]
- */
-static int
-pmap_bat_mapped(int idx, vm_offset_t pa, vm_size_t size)
-{
- u_int prot;
- u_int32_t start;
- u_int32_t end;
- u_int32_t bat_ble;
-
- /*
- * Return immediately if not a valid mapping
- */
- if (!battable[idx].batu & BAT_Vs)
- return (EINVAL);
-
- /*
- * The BAT entry must be cache-inhibited, guarded, and r/w
- * so it can function as an i/o page
- */
- prot = battable[idx].batl & (BAT_I|BAT_G|BAT_PP_RW);
- if (prot != (BAT_I|BAT_G|BAT_PP_RW))
- return (EPERM);
-
- /*
- * The address should be within the BAT range. Assume that the
- * start address in the BAT has the correct alignment (thus
- * not requiring masking)
- */
- start = battable[idx].batl & BAT_PBS;
- bat_ble = (battable[idx].batu & ~(BAT_EBS)) | 0x03;
- end = start | (bat_ble << 15) | 0x7fff;
-
- if ((pa < start) || ((pa + size) > end))
- return (ERANGE);
-
- return (0);
-}
-
-
-/*
- * Map a set of physical memory pages into the kernel virtual
- * address space. Return a pointer to where it is mapped. This
- * routine is intended to be used for mapping device memory,
- * NOT real memory.
- */
-void *
-pmap_mapdev(vm_offset_t pa, vm_size_t size)
-{
- vm_offset_t va, tmpva, ppa, offset;
- int i;
-
- ppa = trunc_page(pa);
- offset = pa & PAGE_MASK;
- size = roundup(offset + size, PAGE_SIZE);
-
- GIANT_REQUIRED;
-
- /*
- * If the physical address lies within a valid BAT table entry,
- * return the 1:1 mapping. This currently doesn't work
- * for regions that overlap 256M BAT segments.
- */
- for (i = 0; i < 16; i++) {
- if (pmap_bat_mapped(i, pa, size) == 0)
- return ((void *) pa);
- }
-
- va = kmem_alloc_pageable(kernel_map, size);
- if (!va)
- panic("pmap_mapdev: Couldn't alloc kernel virtual memory");
-
- for (tmpva = va; size > 0;) {
- pmap_kenter(tmpva, ppa);
- TLBIE(tmpva); /* XXX or should it be invalidate-all ? */
- size -= PAGE_SIZE;
- tmpva += PAGE_SIZE;
- ppa += PAGE_SIZE;
- }
-
- return ((void *)(va + offset));
-}
-
-void
-pmap_unmapdev(vm_offset_t va, vm_size_t size)
-{
- vm_offset_t base, offset;
-
- /*
- * If this is outside kernel virtual space, then it's a
- * battable entry and doesn't require unmapping
- */
- if ((va >= VM_MIN_KERNEL_ADDRESS) && (va <= VM_MAX_KERNEL_ADDRESS)) {
- base = trunc_page(va);
- offset = va & PAGE_MASK;
- size = roundup(offset + size, PAGE_SIZE);
- kmem_free(kernel_map, base, size);
- }
-}
diff --git a/sys/powerpc/psim/uart_iobus.c b/sys/powerpc/psim/uart_iobus.c
deleted file mode 100644
index f2174ae669a4..000000000000
--- a/sys/powerpc/psim/uart_iobus.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 2002 by Peter Grehan. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-/*
- * PSIM local bus 16550
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/conf.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/module.h>
-#include <sys/tty.h>
-#include <machine/bus_pio.h>
-#include <machine/bus.h>
-#include <sys/timepps.h>
-
-#include <dev/ofw/openfirm.h>
-#include <powerpc/psim/iobusvar.h>
-
-#include <dev/sio/sioreg.h>
-#include <dev/sio/siovar.h>
-
-#include <isa/isavar.h> /* for isa_irq_pending() prototype */
-
-static int sio_iobus_attach(device_t dev);
-static int sio_iobus_probe(device_t dev);
-
-static device_method_t sio_iobus_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, sio_iobus_probe),
- DEVMETHOD(device_attach, sio_iobus_attach),
-
- { 0, 0 }
-};
-
-static driver_t sio_iobus_driver = {
- sio_driver_name,
- sio_iobus_methods,
- 0,
-};
-
-static int
-sio_iobus_attach(device_t dev)
-{
- return (sioattach(dev, 0, DEFAULT_RCLK));
-}
-
-static int
-sio_iobus_probe(device_t dev)
-{
- char *type = iobus_get_name(dev);
-
- if (strncmp(type, "com", 3) != 0)
- return (ENXIO);
-
-
- device_set_desc(dev, "PSIM serial port");
-
- /*
- * Call sioprobe with noprobe=1, to avoid hitting a psim bug
- */
- return (sioprobe(dev, 0, 0, 1));
-}
-
-DRIVER_MODULE(sio, iobus, sio_iobus_driver, sio_devclass, 0, 0);
-
-/*
- * Stub function. Perhaps a way to get this to work correctly would
- * be for child devices to set a field in the dev structure to
- * inform the parent that they are isa devices, and then use a
- * intr_pending() call which would propagate up to nexus to see
- * if the interrupt controller had any intrs in the isa group set
- */
-intrmask_t
-isa_irq_pending(void)
-{
- return (0);
-}
diff --git a/sys/rpc/types.h b/sys/rpc/types.h
deleted file mode 100644
index 4a5c6564b270..000000000000
--- a/sys/rpc/types.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/* $NetBSD: types.h,v 1.13 2000/06/13 01:02:44 thorpej Exp $ */
-
-/*
- * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
- * unrestricted use provided that this legend is included on all tape
- * media and as a part of the software program in whole or part. Users
- * may copy or modify Sun RPC without charge, but are not authorized
- * to license or distribute it to anyone else except as part of a product or
- * program developed by the user.
- *
- * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
- * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- *
- * Sun RPC is provided with no support and without any obligation on the
- * part of Sun Microsystems, Inc. to assist in its use, correction,
- * modification or enhancement.
- *
- * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
- * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
- * OR ANY PART THEREOF.
- *
- * In no event will Sun Microsystems, Inc. be liable for any lost revenue
- * or profits or other special, indirect and consequential damages, even if
- * Sun has been advised of the possibility of such damages.
- *
- * Sun Microsystems, Inc.
- * 2550 Garcia Avenue
- * Mountain View, California 94043
- *
- * from: @(#)types.h 1.18 87/07/24 SMI
- * from: @(#)types.h 2.3 88/08/15 4.0 RPCSRC
- * $FreeBSD$
- */
-
-/*
- * Rpc additions to <sys/types.h>
- */
-#ifndef _RPC_TYPES_H
-#define _RPC_TYPES_H
-
-#include <sys/types.h>
-
-typedef int32_t bool_t;
-typedef int32_t enum_t;
-
-typedef u_int32_t rpcprog_t;
-typedef u_int32_t rpcvers_t;
-typedef u_int32_t rpcproc_t;
-typedef u_int32_t rpcprot_t;
-typedef u_int32_t rpcport_t;
-typedef int32_t rpc_inline_t;
-
-#define __dontcare__ -1
-
-#ifndef FALSE
-# define FALSE (0)
-#endif
-#ifndef TRUE
-# define TRUE (1)
-#endif
-#ifndef NULL
-# define NULL 0
-#endif
-
-#define mem_alloc(bsize) calloc(1, bsize)
-#define mem_free(ptr, bsize) free(ptr)
-
-#include <sys/time.h>
-#include <netconfig.h>
-
-/*
- * The netbuf structure is defined here, because FreeBSD / NetBSD only use
- * it inside the RPC code. It's in <xti.h> on SVR4, but it would be confusing
- * to have an xti.h, since FreeBSD / NetBSD does not support XTI/TLI.
- */
-
-/*
- * The netbuf structure is used for transport-independent address storage.
- */
-struct netbuf {
- unsigned int maxlen;
- unsigned int len;
- void *buf;
-};
-
-/*
- * The format of the addres and options arguments of the XTI t_bind call.
- * Only provided for compatibility, it should not be used.
- */
-
-struct t_bind {
- struct netbuf addr;
- unsigned int qlen;
-};
-
-/*
- * Internal library and rpcbind use. This is not an exported interface, do
- * not use.
- */
-struct __rpc_sockinfo {
- int si_af;
- int si_proto;
- int si_socktype;
- int si_alen;
-};
-
-#endif /* !_RPC_TYPES_H */
diff --git a/sys/security/mac/mac_framework.c b/sys/security/mac/mac_framework.c
deleted file mode 100644
index fb06edea3012..000000000000
--- a/sys/security/mac/mac_framework.c
+++ /dev/null
@@ -1,3975 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * Copyright (c) 2001 Ilmar S. Habibulin
- * Copyright (c) 2001, 2002, 2003 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * This software was developed by Robert Watson and Ilmar Habibulin for the
- * TrustedBSD Project.
- *
- * This software was developed for the FreeBSD Project in part by Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
- * as part of the DARPA CHATS research program.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-/*
- * Developed by the TrustedBSD Project.
- *
- * Framework for extensible kernel access control. Kernel and userland
- * interface to the framework, policy registration and composition.
- */
-
-#include "opt_mac.h"
-#include "opt_devfs.h"
-
-#include <sys/param.h>
-#include <sys/condvar.h>
-#include <sys/extattr.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/mac.h>
-#include <sys/module.h>
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/sysent.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/file.h>
-#include <sys/namei.h>
-#include <sys/socket.h>
-#include <sys/pipe.h>
-#include <sys/socketvar.h>
-#include <sys/sysctl.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-
-#include <sys/mac_policy.h>
-
-#include <fs/devfs/devfs.h>
-
-#include <net/bpfdesc.h>
-#include <net/if.h>
-#include <net/if_var.h>
-
-#include <netinet/in.h>
-#include <netinet/ip_var.h>
-
-#ifdef MAC
-
-/*
- * Declare that the kernel provides MAC support, version 1. This permits
- * modules to refuse to be loaded if the necessary support isn't present,
- * even if it's pre-boot.
- */
-MODULE_VERSION(kernel_mac_support, 1);
-
-SYSCTL_DECL(_security);
-
-SYSCTL_NODE(_security, OID_AUTO, mac, CTLFLAG_RW, 0,
- "TrustedBSD MAC policy controls");
-
-#if MAC_MAX_SLOTS > 32
-#error "MAC_MAX_SLOTS too large"
-#endif
-
-static unsigned int mac_max_slots = MAC_MAX_SLOTS;
-static unsigned int mac_slot_offsets_free = (1 << MAC_MAX_SLOTS) - 1;
-SYSCTL_UINT(_security_mac, OID_AUTO, max_slots, CTLFLAG_RD,
- &mac_max_slots, 0, "");
-
-/*
- * Has the kernel started generating labeled objects yet? All read/write
- * access to this variable is serialized during the boot process. Following
- * the end of serialization, we don't update this flag; no locking.
- */
-static int mac_late = 0;
-
-/*
- * Warn about EA transactions only the first time they happen.
- * Weak coherency, no locking.
- */
-static int ea_warn_once = 0;
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
-/*
- * Flag to indicate whether or not we should allocate label storage for
- * new mbufs. Since most dynamic policies we currently work with don't
- * rely on mbuf labeling, try to avoid paying the cost of mtag allocation
- * unless specifically notified of interest. One result of this is
- * that if a dynamically loaded policy requests mbuf labels, it must
- * be able to deal with a NULL label being returned on any mbufs that
- * were already in flight when the policy was loaded. Since the policy
- * already has to deal with uninitialized labels, this probably won't
- * be a problem. Note: currently no locking. Will this be a problem?
- */
-static int mac_labelmbufs = 0;
-#endif
-
-static int mac_enforce_fs = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_fs, CTLFLAG_RW,
- &mac_enforce_fs, 0, "Enforce MAC policy on file system objects");
-TUNABLE_INT("security.mac.enforce_fs", &mac_enforce_fs);
-
-static int mac_enforce_kld = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_kld, CTLFLAG_RW,
- &mac_enforce_kld, 0, "Enforce MAC policy on kld operations");
-TUNABLE_INT("security.mac.enforce_kld", &mac_enforce_kld);
-
-static int mac_enforce_network = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_network, CTLFLAG_RW,
- &mac_enforce_network, 0, "Enforce MAC policy on network packets");
-TUNABLE_INT("security.mac.enforce_network", &mac_enforce_network);
-
-static int mac_enforce_pipe = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_pipe, CTLFLAG_RW,
- &mac_enforce_pipe, 0, "Enforce MAC policy on pipe operations");
-TUNABLE_INT("security.mac.enforce_pipe", &mac_enforce_pipe);
-
-static int mac_enforce_process = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_process, CTLFLAG_RW,
- &mac_enforce_process, 0, "Enforce MAC policy on inter-process operations");
-TUNABLE_INT("security.mac.enforce_process", &mac_enforce_process);
-
-static int mac_enforce_socket = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_socket, CTLFLAG_RW,
- &mac_enforce_socket, 0, "Enforce MAC policy on socket operations");
-TUNABLE_INT("security.mac.enforce_socket", &mac_enforce_socket);
-
-static int mac_enforce_system = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_system, CTLFLAG_RW,
- &mac_enforce_system, 0, "Enforce MAC policy on system operations");
-TUNABLE_INT("security.mac.enforce_system", &mac_enforce_system);
-
-static int mac_enforce_vm = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_vm, CTLFLAG_RW,
- &mac_enforce_vm, 0, "Enforce MAC policy on vm operations");
-TUNABLE_INT("security.mac.enforce_vm", &mac_enforce_vm);
-
-static int mac_mmap_revocation = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation, CTLFLAG_RW,
- &mac_mmap_revocation, 0, "Revoke mmap access to files on subject "
- "relabel");
-static int mac_mmap_revocation_via_cow = 0;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation_via_cow, CTLFLAG_RW,
- &mac_mmap_revocation_via_cow, 0, "Revoke mmap access to files via "
- "copy-on-write semantics, or by removing all write access");
-
-#ifdef MAC_DEBUG
-SYSCTL_NODE(_security_mac, OID_AUTO, debug, CTLFLAG_RW, 0,
- "TrustedBSD MAC debug info");
-
-static int mac_debug_label_fallback = 0;
-SYSCTL_INT(_security_mac_debug, OID_AUTO, label_fallback, CTLFLAG_RW,
- &mac_debug_label_fallback, 0, "Filesystems should fall back to fs label"
- "when label is corrupted.");
-TUNABLE_INT("security.mac.debug_label_fallback",
- &mac_debug_label_fallback);
-
-SYSCTL_NODE(_security_mac_debug, OID_AUTO, counters, CTLFLAG_RW, 0,
- "TrustedBSD MAC object counters");
-
-static unsigned int nmacmbufs, nmaccreds, nmacifnets, nmacbpfdescs,
- nmacsockets, nmacmounts, nmactemp, nmacvnodes, nmacdevfsdirents,
- nmacipqs, nmacpipes, nmacprocs;
-
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mbufs, CTLFLAG_RD,
- &nmacmbufs, 0, "number of mbufs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, creds, CTLFLAG_RD,
- &nmaccreds, 0, "number of ucreds in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ifnets, CTLFLAG_RD,
- &nmacifnets, 0, "number of ifnets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ipqs, CTLFLAG_RD,
- &nmacipqs, 0, "number of ipqs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, bpfdescs, CTLFLAG_RD,
- &nmacbpfdescs, 0, "number of bpfdescs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, sockets, CTLFLAG_RD,
- &nmacsockets, 0, "number of sockets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, pipes, CTLFLAG_RD,
- &nmacpipes, 0, "number of pipes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, procs, CTLFLAG_RD,
- &nmacprocs, 0, "number of procs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mounts, CTLFLAG_RD,
- &nmacmounts, 0, "number of mounts in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, temp, CTLFLAG_RD,
- &nmactemp, 0, "number of temporary labels in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, vnodes, CTLFLAG_RD,
- &nmacvnodes, 0, "number of vnodes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, devfsdirents, CTLFLAG_RD,
- &nmacdevfsdirents, 0, "number of devfs dirents inuse");
-#endif
-
-static int error_select(int error1, int error2);
-static int mac_policy_register(struct mac_policy_conf *mpc);
-static int mac_policy_unregister(struct mac_policy_conf *mpc);
-
-static void mac_check_vnode_mmap_downgrade(struct ucred *cred,
- struct vnode *vp, int *prot);
-static void mac_cred_mmapped_drop_perms_recurse(struct thread *td,
- struct ucred *cred, struct vm_map *map);
-
-static void mac_destroy_socket_label(struct label *label);
-
-static int mac_setlabel_vnode_extattr(struct ucred *cred,
- struct vnode *vp, struct label *intlabel);
-
-MALLOC_DEFINE(M_MACPIPELABEL, "macpipelabel", "MAC labels for pipes");
-MALLOC_DEFINE(M_MACTEMP, "mactemp", "MAC temporary label storage");
-
-/*
- * mac_static_policy_list holds a list of policy modules that are not
- * loaded while the system is "live", and cannot be unloaded. These
- * policies can be invoked without holding the busy count.
- *
- * mac_policy_list stores the list of dynamic policies. A busy count is
- * maintained for the list, stored in mac_policy_busy. The busy count
- * is protected by mac_policy_mtx; the list may be modified only
- * while the busy count is 0, requiring that the lock be held to
- * prevent new references to the list from being acquired. For almost
- * all operations, incrementing the busy count is sufficient to
- * guarantee consistency, as the list cannot be modified while the
- * busy count is elevated. For a few special operations involving a
- * change to the list of active policies, the mtx itself must be held.
- * A condition variable, mac_policy_cv, is used to signal potential
- * exclusive consumers that they should try to acquire the lock if a
- * first attempt at exclusive access fails.
- */
-static struct mtx mac_policy_mtx;
-static struct cv mac_policy_cv;
-static int mac_policy_count;
-static LIST_HEAD(, mac_policy_conf) mac_policy_list;
-static LIST_HEAD(, mac_policy_conf) mac_static_policy_list;
-
-/*
- * We manually invoke WITNESS_WARN() to allow Witness to generate
- * warnings even if we don't end up ever triggering the wait at
- * run-time. The consumer of the exclusive interface must not hold
- * any locks (other than potentially Giant) since we may sleep for
- * long (potentially indefinite) periods of time waiting for the
- * framework to become quiescent so that a policy list change may
- * be made.
- */
-static __inline void
-mac_policy_grab_exclusive(void)
-{
- WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
- "mac_policy_grab_exclusive() at %s:%d", __FILE__, __LINE__);
- mtx_lock(&mac_policy_mtx);
- while (mac_policy_count != 0)
- cv_wait(&mac_policy_cv, &mac_policy_mtx);
-}
-
-static __inline void
-mac_policy_assert_exclusive(void)
-{
- mtx_assert(&mac_policy_mtx, MA_OWNED);
- KASSERT(mac_policy_count == 0,
- ("mac_policy_assert_exclusive(): not exclusive"));
-}
-
-static __inline void
-mac_policy_release_exclusive(void)
-{
-
- KASSERT(mac_policy_count == 0,
- ("mac_policy_release_exclusive(): not exclusive"));
- mtx_unlock(&mac_policy_mtx);
- cv_signal(&mac_policy_cv);
-}
-
-static __inline void
-mac_policy_list_busy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count++;
- mtx_unlock(&mac_policy_mtx);
-}
-
-static __inline int
-mac_policy_list_conditional_busy(void)
-{
- int ret;
-
- mtx_lock(&mac_policy_mtx);
- if (!LIST_EMPTY(&mac_policy_list)) {
- mac_policy_count++;
- ret = 1;
- } else
- ret = 0;
- mtx_unlock(&mac_policy_mtx);
- return (ret);
-}
-
-static __inline void
-mac_policy_list_unbusy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count--;
- KASSERT(mac_policy_count >= 0, ("MAC_POLICY_LIST_LOCK"));
- if (mac_policy_count == 0)
- cv_signal(&mac_policy_cv);
- mtx_unlock(&mac_policy_mtx);
-}
-
-/*
- * MAC_CHECK performs the designated check by walking the policy
- * module list and checking with each as to how it feels about the
- * request. Note that it returns its value via 'error' in the scope
- * of the caller.
- */
-#define MAC_CHECK(check, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- error = 0; \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * MAC_BOOLEAN performs the designated boolean composition by walking
- * the module list, invoking each instance of the operation, and
- * combining the results using the passed C operator. Note that it
- * returns its value via 'result' in the scope of the caller, which
- * should be initialized by the caller in a meaningful way to get
- * a meaningful result.
- */
-#define MAC_BOOLEAN(operation, composition, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation \
- (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-#define MAC_EXTERNALIZE(type, label, elementlist, outbuf, \
- outbuflen) do { \
- char *curptr, *curptr_start, *element_name, *element_temp; \
- size_t left, left_start, len; \
- int claimed, first, first_start, ignorenotfound; \
- \
- error = 0; \
- element_temp = elementlist; \
- curptr = outbuf; \
- curptr[0] = '\0'; \
- left = outbuflen; \
- first = 1; \
- while ((element_name = strsep(&element_temp, ",")) != NULL) { \
- curptr_start = curptr; \
- left_start = left; \
- first_start = first; \
- if (element_name[0] == '?') { \
- element_name++; \
- ignorenotfound = 1; \
- } else \
- ignorenotfound = 0; \
- claimed = 0; \
- if (first) { \
- len = snprintf(curptr, left, "%s/", \
- element_name); \
- first = 0; \
- } else \
- len = snprintf(curptr, left, ",%s/", \
- element_name); \
- if (len >= left) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- \
- MAC_CHECK(externalize_ ## type, label, element_name, \
- curptr, left, &len, &claimed); \
- if (error) \
- break; \
- if (claimed == 1) { \
- if (len >= outbuflen) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- } else if (claimed == 0 && ignorenotfound) { \
- /* \
- * Revert addition of the label element \
- * name. \
- */ \
- curptr = curptr_start; \
- *curptr = '\0'; \
- left = left_start; \
- first = first_start; \
- } else { \
- error = EINVAL; /* XXXMAC: ENOLABEL */ \
- break; \
- } \
- } \
-} while (0)
-
-#define MAC_INTERNALIZE(type, label, instring) do { \
- char *element, *element_name, *element_data; \
- int claimed; \
- \
- error = 0; \
- element = instring; \
- while ((element_name = strsep(&element, ",")) != NULL) { \
- element_data = element_name; \
- element_name = strsep(&element_data, "/"); \
- if (element_data == NULL) { \
- error = EINVAL; \
- break; \
- } \
- claimed = 0; \
- MAC_CHECK(internalize_ ## type, label, element_name, \
- element_data, &claimed); \
- if (error) \
- break; \
- if (claimed != 1) { \
- /* XXXMAC: Another error here? */ \
- error = EINVAL; \
- break; \
- } \
- } \
-} while (0)
-
-/*
- * MAC_PERFORM performs the designated operation by walking the policy
- * module list and invoking that operation for each policy.
- */
-#define MAC_PERFORM(operation, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * Initialize the MAC subsystem, including appropriate SMP locks.
- */
-static void
-mac_init(void)
-{
-
- LIST_INIT(&mac_static_policy_list);
- LIST_INIT(&mac_policy_list);
-
- mtx_init(&mac_policy_mtx, "mac_policy_mtx", NULL, MTX_DEF);
- cv_init(&mac_policy_cv, "mac_policy_cv");
-}
-
-/*
- * For the purposes of modules that want to know if they were loaded
- * "early", set the mac_late flag once we've processed modules either
- * linked into the kernel, or loaded before the kernel startup.
- */
-static void
-mac_late_init(void)
-{
-
- mac_late = 1;
-}
-
-/*
- * After the policy list has changed, walk the list to update any global
- * flags.
- */
-static void
-mac_policy_updateflags(void)
-{
- struct mac_policy_conf *tmpc;
-#ifndef MAC_ALWAYS_LABEL_MBUF
- int labelmbufs;
-#endif
-
- mac_policy_assert_exclusive();
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- labelmbufs = 0;
-#endif
-
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- mac_labelmbufs = (labelmbufs != 0);
-#endif
-}
-
-/*
- * Allow MAC policy modules to register during boot, etc.
- */
-int
-mac_policy_modevent(module_t mod, int type, void *data)
-{
- struct mac_policy_conf *mpc;
- int error;
-
- error = 0;
- mpc = (struct mac_policy_conf *) data;
-
- switch (type) {
- case MOD_LOAD:
- if (mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_NOTLATE &&
- mac_late) {
- printf("mac_policy_modevent: can't load %s policy "
- "after booting\n", mpc->mpc_name);
- error = EBUSY;
- break;
- }
- error = mac_policy_register(mpc);
- break;
- case MOD_UNLOAD:
- /* Don't unregister the module if it was never registered. */
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED)
- != 0)
- error = mac_policy_unregister(mpc);
- else
- error = 0;
- break;
- default:
- break;
- }
-
- return (error);
-}
-
-static int
-mac_policy_register(struct mac_policy_conf *mpc)
-{
- struct mac_policy_conf *tmpc;
- int error, slot, static_entry;
-
- error = 0;
-
- /*
- * We don't technically need exclusive access while !mac_late,
- * but hold it for assertion consistency.
- */
- mac_policy_grab_exclusive();
-
- /*
- * If the module can potentially be unloaded, or we're loading
- * late, we have to stick it in the non-static list and pay
- * an extra performance overhead. Otherwise, we can pay a
- * light locking cost and stick it in the static list.
- */
- static_entry = (!mac_late &&
- !(mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK));
-
- if (static_entry) {
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- } else {
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- }
- if (mpc->mpc_field_off != NULL) {
- slot = ffs(mac_slot_offsets_free);
- if (slot == 0) {
- error = ENOMEM;
- goto out;
- }
- slot--;
- mac_slot_offsets_free &= ~(1 << slot);
- *mpc->mpc_field_off = slot;
- }
- mpc->mpc_runtime_flags |= MPC_RUNTIME_FLAG_REGISTERED;
-
- /*
- * If we're loading a MAC module after the framework has
- * initialized, it has to go into the dynamic list. If
- * we're loading it before we've finished initializing,
- * it can go into the static list with weaker locker
- * requirements.
- */
- if (static_entry)
- LIST_INSERT_HEAD(&mac_static_policy_list, mpc, mpc_list);
- else
- LIST_INSERT_HEAD(&mac_policy_list, mpc, mpc_list);
-
- /* Per-policy initialization. */
- if (mpc->mpc_ops->mpo_init != NULL)
- (*(mpc->mpc_ops->mpo_init))(mpc);
- mac_policy_updateflags();
-
- printf("Security policy loaded: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
-out:
- mac_policy_release_exclusive();
- return (error);
-}
-
-static int
-mac_policy_unregister(struct mac_policy_conf *mpc)
-{
-
- /*
- * If we fail the load, we may get a request to unload. Check
- * to see if we did the run-time registration, and if not,
- * silently succeed.
- */
- mac_policy_grab_exclusive();
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED) == 0) {
- mac_policy_release_exclusive();
- return (0);
- }
-#if 0
- /*
- * Don't allow unloading modules with private data.
- */
- if (mpc->mpc_field_off != NULL) {
- MAC_POLICY_LIST_UNLOCK();
- return (EBUSY);
- }
-#endif
- /*
- * Only allow the unload to proceed if the module is unloadable
- * by its own definition.
- */
- if ((mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK) == 0) {
- mac_policy_release_exclusive();
- return (EBUSY);
- }
- if (mpc->mpc_ops->mpo_destroy != NULL)
- (*(mpc->mpc_ops->mpo_destroy))(mpc);
-
- LIST_REMOVE(mpc, mpc_list);
- mpc->mpc_runtime_flags &= ~MPC_RUNTIME_FLAG_REGISTERED;
- mac_policy_updateflags();
-
- mac_policy_release_exclusive();
-
- printf("Security policy unload: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
- return (0);
-}
-
-/*
- * Define an error value precedence, and given two arguments, selects the
- * value with the higher precedence.
- */
-static int
-error_select(int error1, int error2)
-{
-
- /* Certain decision-making errors take top priority. */
- if (error1 == EDEADLK || error2 == EDEADLK)
- return (EDEADLK);
-
- /* Invalid arguments should be reported where possible. */
- if (error1 == EINVAL || error2 == EINVAL)
- return (EINVAL);
-
- /* Precedence goes to "visibility", with both process and file. */
- if (error1 == ESRCH || error2 == ESRCH)
- return (ESRCH);
-
- if (error1 == ENOENT || error2 == ENOENT)
- return (ENOENT);
-
- /* Precedence goes to DAC/MAC protections. */
- if (error1 == EACCES || error2 == EACCES)
- return (EACCES);
-
- /* Precedence goes to privilege. */
- if (error1 == EPERM || error2 == EPERM)
- return (EPERM);
-
- /* Precedence goes to error over success; otherwise, arbitrary. */
- if (error1 != 0)
- return (error1);
- return (error2);
-}
-
-static struct label *
-mbuf_to_label(struct mbuf *mbuf)
-{
- struct m_tag *tag;
- struct label *label;
-
- tag = m_tag_find(mbuf, PACKET_TAG_MACLABEL, NULL);
- label = (struct label *)(tag+1);
-
- return (label);
-}
-
-static void
-mac_init_label(struct label *label)
-{
-
- bzero(label, sizeof(*label));
- label->l_flags = MAC_FLAG_INITIALIZED;
-}
-
-static void
-mac_destroy_label(struct label *label)
-{
-
- KASSERT(label->l_flags & MAC_FLAG_INITIALIZED,
- ("destroying uninitialized label"));
-
- bzero(label, sizeof(*label));
- /* implicit: label->l_flags &= ~MAC_FLAG_INITIALIZED; */
-}
-
-void
-mac_init_bpfdesc(struct bpf_d *bpf_d)
-{
-
- mac_init_label(&bpf_d->bd_label);
- MAC_PERFORM(init_bpfdesc_label, &bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_init_cred_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_cred_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_init_cred(struct ucred *cred)
-{
-
- mac_init_cred_label(&cred->cr_label);
-}
-
-void
-mac_init_devfsdirent(struct devfs_dirent *de)
-{
-
- mac_init_label(&de->de_label);
- MAC_PERFORM(init_devfsdirent_label, &de->de_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_init_ifnet_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_ifnet_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_init_ifnet(struct ifnet *ifp)
-{
-
- mac_init_ifnet_label(&ifp->if_label);
-}
-
-int
-mac_init_ipq(struct ipq *ipq, int flag)
-{
- int error;
-
- mac_init_label(&ipq->ipq_label);
-
- MAC_CHECK(init_ipq_label, &ipq->ipq_label, flag);
- if (error) {
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacipqs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf_tag(struct m_tag *tag, int flag)
-{
- struct label *label;
- int error;
-
- label = (struct label *) (tag + 1);
- mac_init_label(label);
-
- MAC_CHECK(init_mbuf_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacmbufs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf(struct mbuf *m, int flag)
-{
- struct m_tag *tag;
- int error;
-
- M_ASSERTPKTHDR(m);
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- /*
- * Don't reserve space for labels on mbufs unless we have a policy
- * that uses the labels.
- */
- if (mac_labelmbufs) {
-#endif
- tag = m_tag_get(PACKET_TAG_MACLABEL, sizeof(struct label),
- flag);
- if (tag == NULL)
- return (ENOMEM);
- error = mac_init_mbuf_tag(tag, flag);
- if (error) {
- m_tag_free(tag);
- return (error);
- }
- m_tag_prepend(m, tag);
-#ifndef MAC_ALWAYS_LABEL_MBUF
- }
-#endif
- return (0);
-}
-
-void
-mac_init_mount(struct mount *mp)
-{
-
- mac_init_label(&mp->mnt_mntlabel);
- mac_init_label(&mp->mnt_fslabel);
- MAC_PERFORM(init_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(init_mount_fs_label, &mp->mnt_fslabel);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_init_pipe_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_pipe_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_init_pipe(struct pipe *pipe)
-{
- struct label *label;
-
- label = malloc(sizeof(struct label), M_MACPIPELABEL, M_ZERO|M_WAITOK);
- pipe->pipe_label = label;
- pipe->pipe_peer->pipe_label = label;
- mac_init_pipe_label(label);
-}
-
-void
-mac_init_proc(struct proc *p)
-{
-
- mac_init_label(&p->p_label);
- MAC_PERFORM(init_proc_label, &p->p_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacprocs, 1);
-#endif
-}
-
-static int
-mac_init_socket_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacsockets, 1);
-#endif
-
- return (error);
-}
-
-static int
-mac_init_socket_peer_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_peer_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
- return (error);
-}
-
-int
-mac_init_socket(struct socket *socket, int flag)
-{
- int error;
-
- error = mac_init_socket_label(&socket->so_label, flag);
- if (error)
- return (error);
-
- error = mac_init_socket_peer_label(&socket->so_peerlabel, flag);
- if (error)
- mac_destroy_socket_label(&socket->so_label);
-
- return (error);
-}
-
-void
-mac_init_vnode_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_vnode_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_init_vnode(struct vnode *vp)
-{
-
- mac_init_vnode_label(&vp->v_label);
-}
-
-void
-mac_destroy_bpfdesc(struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(destroy_bpfdesc_label, &bpf_d->bd_label);
- mac_destroy_label(&bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_destroy_cred_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_cred_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_destroy_cred(struct ucred *cred)
-{
-
- mac_destroy_cred_label(&cred->cr_label);
-}
-
-void
-mac_destroy_devfsdirent(struct devfs_dirent *de)
-{
-
- MAC_PERFORM(destroy_devfsdirent_label, &de->de_label);
- mac_destroy_label(&de->de_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_destroy_ifnet_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_ifnet_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_destroy_ifnet(struct ifnet *ifp)
-{
-
- mac_destroy_ifnet_label(&ifp->if_label);
-}
-
-void
-mac_destroy_ipq(struct ipq *ipq)
-{
-
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacipqs, 1);
-#endif
-}
-
-void
-mac_destroy_mbuf_tag(struct m_tag *tag)
-{
- struct label *label;
-
- label = (struct label *)(tag+1);
-
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmbufs, 1);
-#endif
-}
-
-void
-mac_destroy_mount(struct mount *mp)
-{
-
- MAC_PERFORM(destroy_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(destroy_mount_fs_label, &mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_mntlabel);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_destroy_pipe_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_pipe_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_destroy_pipe(struct pipe *pipe)
-{
-
- mac_destroy_pipe_label(pipe->pipe_label);
- free(pipe->pipe_label, M_MACPIPELABEL);
-}
-
-void
-mac_destroy_proc(struct proc *p)
-{
-
- MAC_PERFORM(destroy_proc_label, &p->p_label);
- mac_destroy_label(&p->p_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacprocs, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacsockets, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_peer_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_peer_label, label);
- mac_destroy_label(label);
-}
-
-void
-mac_destroy_socket(struct socket *socket)
-{
-
- mac_destroy_socket_label(&socket->so_label);
- mac_destroy_socket_peer_label(&socket->so_peerlabel);
-}
-
-void
-mac_destroy_vnode_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_vnode_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_destroy_vnode(struct vnode *vp)
-{
-
- mac_destroy_vnode_label(&vp->v_label);
-}
-
-void
-mac_copy_mbuf_tag(struct m_tag *src, struct m_tag *dest)
-{
- struct label *src_label, *dest_label;
-
- src_label = (struct label *)(src+1);
- dest_label = (struct label *)(dest+1);
-
- /*
- * mac_init_mbuf_tag() is called on the target tag in
- * m_tag_copy(), so we don't need to call it here.
- */
- MAC_PERFORM(copy_mbuf_label, src_label, dest_label);
-}
-
-static void
-mac_copy_pipe_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_pipe_label, src, dest);
-}
-
-void
-mac_copy_vnode_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_vnode_label, src, dest);
-}
-
-static int
-mac_check_structmac_consistent(struct mac *mac)
-{
-
- if (mac->m_buflen > MAC_MAX_LABEL_BUF_LEN)
- return (EINVAL);
-
- return (0);
-}
-
-static int
-mac_externalize_cred_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(cred_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_ifnet_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(ifnet_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_pipe_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(pipe_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_peer_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_peer_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_vnode_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(vnode_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_internalize_cred_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(cred_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_ifnet_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(ifnet_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_pipe_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(pipe_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_socket_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(socket_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_vnode_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(vnode_label, label, string);
-
- return (error);
-}
-
-/*
- * Initialize MAC label for the first kernel process, from which other
- * kernel processes and threads are spawned.
- */
-void
-mac_create_proc0(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc0, cred);
-}
-
-/*
- * Initialize MAC label for the first userland process, from which other
- * userland processes and threads are spawned.
- */
-void
-mac_create_proc1(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc1, cred);
-}
-
-void
-mac_thread_userret(struct thread *td)
-{
-
- MAC_PERFORM(thread_userret, td);
-}
-
-/*
- * When a new process is created, its label must be initialized. Generally,
- * this involves inheritence from the parent process, modulo possible
- * deltas. This function allows that processing to take place.
- */
-void
-mac_create_cred(struct ucred *parent_cred, struct ucred *child_cred)
-{
-
- MAC_PERFORM(create_cred, parent_cred, child_cred);
-}
-
-void
-mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(update_devfsdirent, mp, de, &de->de_label, vp,
- &vp->v_label);
-}
-
-void
-mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_devfs, mp, &mp->mnt_fslabel, de,
- &de->de_label, vp, &vp->v_label);
-}
-
-int
-mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_associate_vnode_extattr");
-
- MAC_CHECK(associate_vnode_extattr, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-
- return (error);
-}
-
-void
-mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_singlelabel, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-}
-
-int
-mac_create_vnode_extattr(struct ucred *cred, struct mount *mp,
- struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_create_vnode_extattr");
- ASSERT_VOP_LOCKED(vp, "mac_create_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(create_vnode_extattr, cred, mp, &mp->mnt_fslabel,
- dvp, &dvp->v_label, vp, &vp->v_label, cnp);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-static int
-mac_setlabel_vnode_extattr(struct ucred *cred, struct vnode *vp,
- struct label *intlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_setlabel_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(setlabel_vnode_extattr, cred, vp, &vp->v_label, intlabel);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-int
-mac_execve_enter(struct image_params *imgp, struct mac *mac_p,
- struct label *execlabelstorage)
-{
- struct mac mac;
- char *buffer;
- int error;
-
- if (mac_p == NULL)
- return (0);
-
- error = copyin(mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(execlabelstorage);
- error = mac_internalize_cred_label(execlabelstorage, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(execlabelstorage);
- return (error);
- }
- imgp->execlabel = execlabelstorage;
- return (0);
-}
-
-void
-mac_execve_exit(struct image_params *imgp)
-{
- if (imgp->execlabel != NULL)
- mac_destroy_cred_label(imgp->execlabel);
-}
-
-void
-mac_execve_transition(struct ucred *old, struct ucred *new, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return;
-
- MAC_PERFORM(execve_transition, old, new, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-}
-
-int
-mac_execve_will_transition(struct ucred *old, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
- int result;
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_will_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- result = 0;
- MAC_BOOLEAN(execve_will_transition, ||, old, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-
- return (result);
-}
-
-int
-mac_check_vnode_access(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_access");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_access, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chroot");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chroot, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_create(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp, struct vattr *vap)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_create");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_create, cred, dvp, &dvp->v_label, cnp, vap);
- return (error);
-}
-
-int
-mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp, struct vnode *vp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_delete");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_delete");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_delete, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
- acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_deleteacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_deleteacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_exec(struct ucred *cred, struct vnode *vp,
- struct image_params *imgp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_exec");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_exec, cred, vp, &vp->v_label, imgp,
- imgp->execlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp, acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_link(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_link");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_link");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_link, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_lookup");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_lookup, cred, dvp, &dvp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mmap, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-void
-mac_check_vnode_mmap_downgrade(struct ucred *cred, struct vnode *vp, int *prot)
-{
- int result = *prot;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap_downgrade");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return;
-
- MAC_PERFORM(check_vnode_mmap_downgrade, cred, vp, &vp->v_label,
- &result);
-
- *prot = result;
-}
-
-int
-mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mprotect");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mprotect, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-int
-mac_check_vnode_open(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_open");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_open, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_poll");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_poll, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_read");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_read, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_readdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_readdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_readlink");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readlink, cred, vp, &vp->v_label);
- return (error);
-}
-
-static int
-mac_check_vnode_relabel(struct ucred *cred, struct vnode *vp,
- struct label *newlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_relabel");
-
- MAC_CHECK(check_vnode_relabel, cred, vp, &vp->v_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_from");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_from");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_from, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, int samedir, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_to");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_to");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_to, cred, dvp, &dvp->v_label, vp,
- vp != NULL ? &vp->v_label : NULL, samedir, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_revoke");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_revoke, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type,
- struct acl *acl)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setacl, cred, vp, &vp->v_label, type, acl);
- return (error);
-}
-
-int
-mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp, u_long flags)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setflags");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setflags, cred, vp, &vp->v_label, flags);
- return (error);
-}
-
-int
-mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp, mode_t mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setmode");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setmode, cred, vp, &vp->v_label, mode);
- return (error);
-}
-
-int
-mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp, uid_t uid,
- gid_t gid)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setowner");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setowner, cred, vp, &vp->v_label, uid, gid);
- return (error);
-}
-
-int
-mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
- struct timespec atime, struct timespec mtime)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setutimes");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setutimes, cred, vp, &vp->v_label, atime,
- mtime);
- return (error);
-}
-
-int
-mac_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_stat");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_stat, active_cred, file_cred, vp,
- &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_write(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_write");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_write, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-/*
- * When relabeling a process, call out to the policies for the maximum
- * permission allowed for each object type we know about in its
- * memory space, and revoke access (in the least surprising ways we
- * know) when necessary. The process lock is not held here.
- */
-void
-mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred)
-{
-
- /* XXX freeze all other threads */
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- &td->td_proc->p_vmspace->vm_map);
- /* XXX allow other threads to continue */
-}
-
-static __inline const char *
-prot2str(vm_prot_t prot)
-{
-
- switch (prot & VM_PROT_ALL) {
- case VM_PROT_READ:
- return ("r--");
- case VM_PROT_READ | VM_PROT_WRITE:
- return ("rw-");
- case VM_PROT_READ | VM_PROT_EXECUTE:
- return ("r-x");
- case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("rwx");
- case VM_PROT_WRITE:
- return ("-w-");
- case VM_PROT_EXECUTE:
- return ("--x");
- case VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("-wx");
- default:
- return ("---");
- }
-}
-
-static void
-mac_cred_mmapped_drop_perms_recurse(struct thread *td, struct ucred *cred,
- struct vm_map *map)
-{
- struct vm_map_entry *vme;
- int result;
- vm_prot_t revokeperms;
- vm_object_t object;
- vm_ooffset_t offset;
- struct vnode *vp;
-
- if (!mac_mmap_revocation)
- return;
-
- vm_map_lock_read(map);
- for (vme = map->header.next; vme != &map->header; vme = vme->next) {
- if (vme->eflags & MAP_ENTRY_IS_SUB_MAP) {
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- vme->object.sub_map);
- continue;
- }
- /*
- * Skip over entries that obviously are not shared.
- */
- if (vme->eflags & (MAP_ENTRY_COW | MAP_ENTRY_NOSYNC) ||
- !vme->max_protection)
- continue;
- /*
- * Drill down to the deepest backing object.
- */
- offset = vme->offset;
- object = vme->object.vm_object;
- if (object == NULL)
- continue;
- while (object->backing_object != NULL) {
- object = object->backing_object;
- offset += object->backing_object_offset;
- }
- /*
- * At the moment, vm_maps and objects aren't considered
- * by the MAC system, so only things with backing by a
- * normal object (read: vnodes) are checked.
- */
- if (object->type != OBJT_VNODE)
- continue;
- vp = (struct vnode *)object->handle;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- result = vme->max_protection;
- mac_check_vnode_mmap_downgrade(cred, vp, &result);
- VOP_UNLOCK(vp, 0, td);
- /*
- * Find out what maximum protection we may be allowing
- * now but a policy needs to get removed.
- */
- revokeperms = vme->max_protection & ~result;
- if (!revokeperms)
- continue;
- printf("pid %ld: revoking %s perms from %#lx:%ld "
- "(max %s/cur %s)\n", (long)td->td_proc->p_pid,
- prot2str(revokeperms), (u_long)vme->start,
- (long)(vme->end - vme->start),
- prot2str(vme->max_protection), prot2str(vme->protection));
- vm_map_lock_upgrade(map);
- /*
- * This is the really simple case: if a map has more
- * max_protection than is allowed, but it's not being
- * actually used (that is, the current protection is
- * still allowed), we can just wipe it out and do
- * nothing more.
- */
- if ((vme->protection & revokeperms) == 0) {
- vme->max_protection -= revokeperms;
- } else {
- if (revokeperms & VM_PROT_WRITE) {
- /*
- * In the more complicated case, flush out all
- * pending changes to the object then turn it
- * copy-on-write.
- */
- vm_object_reference(object);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- VM_OBJECT_LOCK(object);
- vm_object_page_clean(object,
- OFF_TO_IDX(offset),
- OFF_TO_IDX(offset + vme->end - vme->start +
- PAGE_MASK),
- OBJPC_SYNC);
- VM_OBJECT_UNLOCK(object);
- VOP_UNLOCK(vp, 0, td);
- vm_object_deallocate(object);
- /*
- * Why bother if there's no read permissions
- * anymore? For the rest, we need to leave
- * the write permissions on for COW, or
- * remove them entirely if configured to.
- */
- if (!mac_mmap_revocation_via_cow) {
- vme->max_protection &= ~VM_PROT_WRITE;
- vme->protection &= ~VM_PROT_WRITE;
- } if ((revokeperms & VM_PROT_READ) == 0)
- vme->eflags |= MAP_ENTRY_COW |
- MAP_ENTRY_NEEDS_COPY;
- }
- if (revokeperms & VM_PROT_EXECUTE) {
- vme->max_protection &= ~VM_PROT_EXECUTE;
- vme->protection &= ~VM_PROT_EXECUTE;
- }
- if (revokeperms & VM_PROT_READ) {
- vme->max_protection = 0;
- vme->protection = 0;
- }
- pmap_protect(map->pmap, vme->start, vme->end,
- vme->protection & ~revokeperms);
- vm_map_simplify_entry(map, vme);
- }
- vm_map_lock_downgrade(map);
- }
- vm_map_unlock_read(map);
-}
-
-/*
- * When the subject's label changes, it may require revocation of privilege
- * to mapped objects. This can't be done on-the-fly later with a unified
- * buffer cache.
- */
-static void
-mac_relabel_cred(struct ucred *cred, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_cred, cred, newlabel);
-}
-
-void
-mac_relabel_vnode(struct ucred *cred, struct vnode *vp, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_vnode, cred, vp, &vp->v_label, newlabel);
-}
-
-void
-mac_create_ifnet(struct ifnet *ifnet)
-{
-
- MAC_PERFORM(create_ifnet, ifnet, &ifnet->if_label);
-}
-
-void
-mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(create_bpfdesc, cred, bpf_d, &bpf_d->bd_label);
-}
-
-void
-mac_create_socket(struct ucred *cred, struct socket *socket)
-{
-
- MAC_PERFORM(create_socket, cred, socket, &socket->so_label);
-}
-
-void
-mac_create_pipe(struct ucred *cred, struct pipe *pipe)
-{
-
- MAC_PERFORM(create_pipe, cred, pipe, pipe->pipe_label);
-}
-
-void
-mac_create_socket_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(create_socket_from_socket, oldsocket, &oldsocket->so_label,
- newsocket, &newsocket->so_label);
-}
-
-static void
-mac_relabel_socket(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_socket, cred, socket, &socket->so_label, newlabel);
-}
-
-static void
-mac_relabel_pipe(struct ucred *cred, struct pipe *pipe, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_pipe, cred, pipe, pipe->pipe_label, newlabel);
-}
-
-void
-mac_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct socket *socket)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(set_socket_peer_from_mbuf, mbuf, label, socket,
- &socket->so_peerlabel);
-}
-
-void
-mac_set_socket_peer_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(set_socket_peer_from_socket, oldsocket,
- &oldsocket->so_label, newsocket, &newsocket->so_peerlabel);
-}
-
-void
-mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram)
-{
- struct label *label;
-
- label = mbuf_to_label(datagram);
-
- MAC_PERFORM(create_datagram_from_ipq, ipq, &ipq->ipq_label,
- datagram, label);
-}
-
-void
-mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment)
-{
- struct label *datagramlabel, *fragmentlabel;
-
- datagramlabel = mbuf_to_label(datagram);
- fragmentlabel = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_fragment, datagram, datagramlabel, fragment,
- fragmentlabel);
-}
-
-void
-mac_create_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_mbuf(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_from_mbuf, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-void
-mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_bpfdesc, bpf_d, &bpf_d->bd_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_linklayer, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_ifnet, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf, struct ifnet *ifnet,
- struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_multicast_encap, oldmbuf, oldmbuflabel,
- ifnet, &ifnet->if_label, newmbuf, newmbuflabel);
-}
-
-void
-mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_netlayer, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-int
-mac_fragment_match(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
- int result;
-
- label = mbuf_to_label(fragment);
-
- result = 1;
- MAC_BOOLEAN(fragment_match, &&, fragment, label, ipq,
- &ipq->ipq_label);
-
- return (result);
-}
-
-void
-mac_update_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(update_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_socket(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_socket, socket, &socket->so_label, mbuf,
- label);
-}
-
-void
-mac_create_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-void
-mac_create_root_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_root_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-int
-mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet)
-{
- int error;
-
- if (!mac_enforce_network)
- return (0);
-
- MAC_CHECK(check_bpfdesc_receive, bpf_d, &bpf_d->bd_label, ifnet,
- &ifnet->if_label);
-
- return (error);
-}
-
-static int
-mac_check_cred_relabel(struct ucred *cred, struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_cred_relabel, cred, newlabel);
-
- return (error);
-}
-
-int
-mac_check_cred_visible(struct ucred *u1, struct ucred *u2)
-{
- int error;
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_cred_visible, u1, u2);
-
- return (error);
-}
-
-int
-mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- M_ASSERTPKTHDR(mbuf);
-
- if (!mac_enforce_network)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_ifnet_transmit, ifnet, &ifnet->if_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_kenv_dump(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_dump, cred);
-
- return (error);
-}
-
-int
-mac_check_kenv_get(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_get, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kenv_set(struct ucred *cred, char *name, char *value)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_set, cred, name, value);
-
- return (error);
-}
-
-int
-mac_check_kenv_unset(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_unset, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kld_load(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_kld_load");
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_load, cred, vp, &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_kld_stat(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_stat, cred);
-
- return (error);
-}
-
-int
-mac_check_kld_unload(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_unload, cred);
-
- return (error);
-}
-
-int
-mac_check_mount_stat(struct ucred *cred, struct mount *mount)
-{
- int error;
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_mount_stat, cred, mount, &mount->mnt_mntlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, unsigned long cmd,
- void *data)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_ioctl, cred, pipe, pipe->pipe_label, cmd, data);
-
- return (error);
-}
-
-int
-mac_check_pipe_poll(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_poll, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_read(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_read, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-static int
-mac_check_pipe_relabel(struct ucred *cred, struct pipe *pipe,
- struct label *newlabel)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_relabel, cred, pipe, pipe->pipe_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_stat(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_stat, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_write(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_write, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_proc_debug(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_debug, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_sched(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_sched, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_signal(struct ucred *cred, struct proc *proc, int signum)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_signal, cred, proc, signum);
-
- return (error);
-}
-
-int
-mac_check_socket_bind(struct ucred *ucred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_bind, ucred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_connect(struct ucred *cred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_connect, cred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_deliver(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_socket_deliver, socket, &socket->so_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_socket_listen(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_listen, cred, socket, &socket->so_label);
- return (error);
-}
-
-int
-mac_check_socket_receive(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_receive, cred, so, &so->so_label);
-
- return (error);
-}
-
-static int
-mac_check_socket_relabel(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_socket_relabel, cred, socket, &socket->so_label,
- newlabel);
-
- return (error);
-}
-
-int
-mac_check_socket_send(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_send, cred, so, &so->so_label);
-
- return (error);
-}
-
-int
-mac_check_socket_visible(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_visible, cred, socket, &socket->so_label);
-
- return (error);
-}
-
-int
-mac_check_sysarch_ioperm(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_sysarch_ioperm, cred);
- return (error);
-}
-
-int
-mac_check_system_acct(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- if (vp != NULL) {
- ASSERT_VOP_LOCKED(vp, "mac_check_system_acct");
- }
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_acct, cred, vp,
- vp != NULL ? &vp->v_label : NULL);
-
- return (error);
-}
-
-int
-mac_check_system_nfsd(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_nfsd, cred);
-
- return (error);
-}
-
-int
-mac_check_system_reboot(struct ucred *cred, int howto)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_reboot, cred, howto);
-
- return (error);
-}
-
-int
-mac_check_system_settime(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_settime, cred);
-
- return (error);
-}
-
-int
-mac_check_system_swapon(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapon");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapon, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_swapoff(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapoff");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapoff, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_sysctl(struct ucred *cred, int *name, u_int namelen,
- void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen)
-{
- int error;
-
- /*
- * XXXMAC: We're very much like to assert the SYSCTL_LOCK here,
- * but since it's not exported from kern_sysctl.c, we can't.
- */
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_sysctl, cred, name, namelen, old, oldlenp,
- inkernel, new, newlen);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_ifnet_label(&ifnet->if_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- struct label intlabel;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_ifnet_label(&intlabel);
- error = mac_internalize_ifnet_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- /*
- * XXX: Note that this is a redundant privilege check, since
- * policies impose this check themselves if required by the
- * policy. Eventually, this should go away.
- */
- error = suser_cred(cred, 0);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_CHECK(check_ifnet_relabel, cred, ifnet, &ifnet->if_label,
- &intlabel);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_PERFORM(relabel_ifnet, cred, ifnet, &ifnet->if_label, &intlabel);
-
- mac_destroy_ifnet_label(&intlabel);
- return (0);
-}
-
-void
-mac_create_devfs_device(struct mount *mp, dev_t dev, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_device, mp, dev, de, &de->de_label);
-}
-
-void
-mac_create_devfs_symlink(struct ucred *cred, struct mount *mp,
- struct devfs_dirent *dd, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_symlink, cred, mp, dd, &dd->de_label, de,
- &de->de_label);
-}
-
-void
-mac_create_devfs_directory(struct mount *mp, char *dirname, int dirnamelen,
- struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_directory, mp, dirname, dirnamelen, de,
- &de->de_label);
-}
-
-int
-mac_setsockopt_label_set(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- struct label intlabel;
- char *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, buffer, mac->m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_socket_label(&intlabel, M_WAITOK);
- error = mac_internalize_socket_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_check_socket_relabel(cred, so, &intlabel);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_relabel_socket(cred, so, &intlabel);
-
- mac_destroy_socket_label(&intlabel);
- return (0);
-}
-
-int
-mac_pipe_label_set(struct ucred *cred, struct pipe *pipe, struct label *label)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- error = mac_check_pipe_relabel(cred, pipe, label);
- if (error)
- return (error);
-
- mac_relabel_pipe(cred, pipe, label);
-
- return (0);
-}
-
-int
-mac_getsockopt_label_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *buffer, *elements;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_label(&so->so_label, elements,
- buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_getsockopt_peerlabel_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *elements, *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_peer_label(&so->so_peerlabel,
- elements, buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * Implementation of VOP_SETLABEL() that relies on extended attributes
- * to store label data. Can be referenced by filesystems supporting
- * extended attributes.
- */
-int
-vop_stdsetlabel_ea(struct vop_setlabel_args *ap)
-{
- struct vnode *vp = ap->a_vp;
- struct label *intlabel = ap->a_label;
- int error;
-
- ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea");
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- error = mac_setlabel_vnode_extattr(ap->a_cred, vp, intlabel);
- if (error)
- return (error);
-
- mac_relabel_vnode(ap->a_cred, vp, intlabel);
-
- return (0);
-}
-
-static int
-vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred)
-{
- int error;
-
- if (vp->v_mount == NULL) {
- /* printf("vn_setlabel: null v_mount\n"); */
- if (vp->v_type != VNON)
- printf("vn_setlabel: null v_mount with non-VNON\n");
- return (EBADF);
- }
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- /*
- * Multi-phase commit. First check the policies to confirm the
- * change is OK. Then commit via the filesystem. Finally,
- * update the actual vnode label. Question: maybe the filesystem
- * should update the vnode at the end as part of VOP_SETLABEL()?
- */
- error = mac_check_vnode_relabel(cred, vp, intlabel);
- if (error)
- return (error);
-
- /*
- * VADMIN provides the opportunity for the filesystem to make
- * decisions about who is and is not able to modify labels
- * and protections on files. This might not be right. We can't
- * assume VOP_SETLABEL() will do it, because we might implement
- * that as part of vop_stdsetlabel_ea().
- */
- error = VOP_ACCESS(vp, VADMIN, cred, curthread);
- if (error)
- return (error);
-
- error = VOP_SETLABEL(vp, intlabel, cred, curthread);
- if (error)
- return (error);
-
- return (0);
-}
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- struct proc *tproc;
- struct ucred *tcred;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- tproc = pfind(uap->pid);
- if (tproc == NULL)
- return (ESRCH);
-
- tcred = NULL; /* Satisfy gcc. */
- error = p_cansee(td, tproc);
- if (error == 0)
- tcred = crhold(tproc->p_ucred);
- PROC_UNLOCK(tproc);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&tcred->cr_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&td->td_ucred->cr_label,
- elements, buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
- struct ucred *newcred, *oldcred;
- struct label intlabel;
- struct proc *p;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(&intlabel);
- error = mac_internalize_cred_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(&intlabel);
- return (error);
- }
-
- newcred = crget();
-
- p = td->td_proc;
- PROC_LOCK(p);
- oldcred = p->p_ucred;
-
- error = mac_check_cred_relabel(oldcred, &intlabel);
- if (error) {
- PROC_UNLOCK(p);
- crfree(newcred);
- goto out;
- }
-
- setsugid(p);
- crcopy(newcred, oldcred);
- mac_relabel_cred(newcred, &intlabel);
- p->p_ucred = newcred;
-
- /*
- * Grab additional reference for use while revoking mmaps, prior
- * to releasing the proc lock and sharing the cred.
- */
- crhold(newcred);
- PROC_UNLOCK(p);
-
- if (mac_enforce_vm) {
- mtx_lock(&Giant);
- mac_cred_mmapped_drop_perms(td, newcred);
- mtx_unlock(&Giant);
- }
-
- crfree(newcred); /* Free revocation reference. */
- crfree(oldcred);
-
-out:
- mac_destroy_cred_label(&intlabel);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
- char *elements, *buffer;
- struct label intlabel;
- struct file *fp;
- struct mac mac;
- struct vnode *vp;
- struct pipe *pipe;
- short label_type;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- label_type = fp->f_type;
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- vp = fp->f_data;
-
- mac_init_vnode_label(&intlabel);
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- mac_copy_vnode_label(&vp->v_label, &intlabel);
- VOP_UNLOCK(vp, 0, td);
-
- break;
- case DTYPE_PIPE:
- pipe = fp->f_data;
-
- mac_init_pipe_label(&intlabel);
-
- PIPE_LOCK(pipe);
- mac_copy_pipe_label(pipe->pipe_label, &intlabel);
- PIPE_UNLOCK(pipe);
- break;
- default:
- error = EINVAL;
- fdrop(fp, td);
- goto out;
- }
- fdrop(fp, td);
-
- switch (label_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- if (error == 0)
- error = mac_externalize_vnode_label(&intlabel,
- elements, buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_vnode_label(&intlabel);
- break;
- case DTYPE_PIPE:
- error = mac_externalize_pipe_label(&intlabel, elements,
- buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_pipe_label(&intlabel);
- break;
- default:
- panic("__mac_get_fd: corrupted label_type");
- }
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
-
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
- struct label intlabel;
- struct pipe *pipe;
- struct file *fp;
- struct mount *mp;
- struct vnode *vp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vp = fp->f_data;
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error != 0) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- error = vn_setlabel(vp, &intlabel, td->td_ucred);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
-
- mac_destroy_vnode_label(&intlabel);
- break;
-
- case DTYPE_PIPE:
- mac_init_pipe_label(&intlabel);
- error = mac_internalize_pipe_label(&intlabel, buffer);
- if (error == 0) {
- pipe = fp->f_data;
- PIPE_LOCK(pipe);
- error = mac_pipe_label_set(td->td_ucred, pipe,
- &intlabel);
- PIPE_UNLOCK(pipe);
- }
-
- mac_destroy_pipe_label(&intlabel);
- break;
-
- default:
- error = EINVAL;
- }
-
- fdrop(fp, td);
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
- struct mac_policy_conf *mpc;
- char target[MAC_MAX_POLICY_NAME];
- int entrycount, error;
-
- error = copyinstr(uap->policy, target, sizeof(target), NULL);
- if (error)
- return (error);
-
- error = ENOSYS;
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- goto out;
- }
- }
-
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) {
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- break;
- }
- }
- mac_policy_list_unbusy();
- }
-out:
- return (error);
-}
-
-SYSINIT(mac, SI_SUB_MAC, SI_ORDER_FIRST, mac_init, NULL);
-SYSINIT(mac_late, SI_SUB_MAC_LATE, SI_ORDER_FIRST, mac_late_init, NULL);
-
-#else /* !MAC */
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
-
- return (ENOSYS);
-}
-
-#endif
diff --git a/sys/security/mac/mac_framework.h b/sys/security/mac/mac_framework.h
deleted file mode 100644
index 2412f8bf8daf..000000000000
--- a/sys/security/mac/mac_framework.h
+++ /dev/null
@@ -1,347 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * Copyright (c) 2001, 2002, 2003 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * This software was developed by Robert Watson for the TrustedBSD Project.
- *
- * This software was developed for the FreeBSD Project in part by Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
- * as part of the DARPA CHATS research program.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-/*
- * Userland/kernel interface for Mandatory Access Control.
- *
- * The POSIX.1e implementation page may be reached at:
- * http://www.trustedbsd.org/
- */
-#ifndef _SYS_MAC_H
-#define _SYS_MAC_H
-
-#include <sys/_label.h>
-
-#ifndef _POSIX_MAC
-#define _POSIX_MAC
-#endif
-
-/*
- * MAC framework-related constants and limits.
- */
-#define MAC_MAX_POLICY_NAME 32
-#define MAC_MAX_LABEL_ELEMENT_NAME 32
-#define MAC_MAX_LABEL_ELEMENT_DATA 4096
-#define MAC_MAX_LABEL_BUF_LEN 8192
-
-struct mac {
- size_t m_buflen;
- char *m_string;
-};
-
-typedef struct mac *mac_t;
-
-#ifndef _KERNEL
-
-/*
- * Location of the userland MAC framework configuration file. mac.conf
- * binds policy names to shared libraries that understand those policies,
- * as well as setting defaults for MAC-aware applications.
- */
-#define MAC_CONFFILE "/etc/mac.conf"
-
-/*
- * Extended non-POSIX.1e interfaces that offer additional services
- * available from the userland and kernel MAC frameworks.
- */
-int mac_execve(char *fname, char **argv, char **envv,
- mac_t _label);
-int mac_free(mac_t _label);
-int mac_from_text(mac_t *_label, const char *_text);
-int mac_get_fd(int _fd, mac_t _label);
-int mac_get_file(const char *_path, mac_t _label);
-int mac_get_link(const char *_path, mac_t _label);
-int mac_get_pid(pid_t _pid, mac_t _label);
-int mac_get_proc(mac_t _label);
-int mac_is_present(const char *_policyname);
-int mac_prepare(mac_t *_label, char *_elements);
-int mac_prepare_file_label(mac_t *_label);
-int mac_prepare_ifnet_label(mac_t *_label);
-int mac_prepare_process_label(mac_t *_label);
-int mac_set_fd(int _fildes, const mac_t _label);
-int mac_set_file(const char *_path, mac_t _label);
-int mac_set_link(const char *_path, mac_t _label);
-int mac_set_proc(const mac_t _label);
-int mac_syscall(const char *_policyname, int _call, void *_arg);
-int mac_to_text(mac_t mac, char **_text);
-
-#else /* _KERNEL */
-
-/*
- * Kernel functions to manage and evaluate labels.
- */
-struct bpf_d;
-struct componentname;
-struct devfs_dirent;
-struct ifnet;
-struct ifreq;
-struct image_params;
-struct ipq;
-struct m_tag;
-struct mbuf;
-struct mount;
-struct proc;
-struct sockaddr;
-struct socket;
-struct pipe;
-struct thread;
-struct timespec;
-struct ucred;
-struct uio;
-struct vattr;
-struct vnode;
-
-#include <sys/acl.h> /* XXX acl_type_t */
-
-struct vop_setlabel_args;
-
-/*
- * Label operations.
- */
-void mac_init_bpfdesc(struct bpf_d *);
-void mac_init_cred(struct ucred *);
-void mac_init_devfsdirent(struct devfs_dirent *);
-void mac_init_ifnet(struct ifnet *);
-int mac_init_ipq(struct ipq *, int flag);
-int mac_init_socket(struct socket *, int flag);
-void mac_init_pipe(struct pipe *);
-int mac_init_mbuf(struct mbuf *mbuf, int flag);
-int mac_init_mbuf_tag(struct m_tag *, int flag);
-void mac_init_mount(struct mount *);
-void mac_init_proc(struct proc *);
-void mac_init_vnode(struct vnode *);
-void mac_init_vnode_label(struct label *);
-void mac_copy_mbuf_tag(struct m_tag *, struct m_tag *);
-void mac_copy_vnode_label(struct label *, struct label *label);
-void mac_destroy_bpfdesc(struct bpf_d *);
-void mac_destroy_cred(struct ucred *);
-void mac_destroy_devfsdirent(struct devfs_dirent *);
-void mac_destroy_ifnet(struct ifnet *);
-void mac_destroy_ipq(struct ipq *);
-void mac_destroy_socket(struct socket *);
-void mac_destroy_pipe(struct pipe *);
-void mac_destroy_proc(struct proc *);
-void mac_destroy_mbuf_tag(struct m_tag *);
-void mac_destroy_mount(struct mount *);
-void mac_destroy_vnode(struct vnode *);
-void mac_destroy_vnode_label(struct label *);
-
-/*
- * Labeling event operations: file system objects, and things that
- * look a lot like file system objects.
- */
-void mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp);
-int mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp);
-void mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp);
-void mac_create_devfs_device(struct mount *mp, dev_t dev,
- struct devfs_dirent *de);
-void mac_create_devfs_directory(struct mount *mp, char *dirname,
- int dirnamelen, struct devfs_dirent *de);
-void mac_create_devfs_symlink(struct ucred *cred, struct mount *mp,
- struct devfs_dirent *dd, struct devfs_dirent *de);
-int mac_create_vnode_extattr(struct ucred *cred, struct mount *mp,
- struct vnode *dvp, struct vnode *vp, struct componentname *cnp);
-void mac_create_mount(struct ucred *cred, struct mount *mp);
-void mac_create_root_mount(struct ucred *cred, struct mount *mp);
-void mac_relabel_vnode(struct ucred *cred, struct vnode *vp,
- struct label *newlabel);
-void mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp);
-
-/*
- * Labeling event operations: IPC objects.
- */
-void mac_create_mbuf_from_socket(struct socket *so, struct mbuf *m);
-void mac_create_socket(struct ucred *cred, struct socket *socket);
-void mac_create_socket_from_socket(struct socket *oldsocket,
- struct socket *newsocket);
-void mac_set_socket_peer_from_mbuf(struct mbuf *mbuf,
- struct socket *socket);
-void mac_set_socket_peer_from_socket(struct socket *oldsocket,
- struct socket *newsocket);
-void mac_create_pipe(struct ucred *cred, struct pipe *pipe);
-
-/*
- * Labeling event operations: network objects.
- */
-void mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d);
-void mac_create_ifnet(struct ifnet *ifp);
-void mac_create_ipq(struct mbuf *fragment, struct ipq *ipq);
-void mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram);
-void mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment);
-void mac_create_mbuf_from_mbuf(struct mbuf *oldmbuf, struct mbuf *newmbuf);
-void mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *m);
-void mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *m);
-void mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *m);
-void mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf,
- struct ifnet *ifnet, struct mbuf *newmbuf);
-void mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf);
-int mac_fragment_match(struct mbuf *fragment, struct ipq *ipq);
-void mac_update_ipq(struct mbuf *fragment, struct ipq *ipq);
-
-/*
- * Labeling event operations: processes.
- */
-void mac_create_cred(struct ucred *cred_parent, struct ucred *cred_child);
-int mac_execve_enter(struct image_params *imgp, struct mac *mac_p,
- struct label *execlabel);
-void mac_execve_exit(struct image_params *imgp);
-void mac_execve_transition(struct ucred *old, struct ucred *new,
- struct vnode *vp, struct label *interpvnodelabel,
- struct image_params *imgp);
-int mac_execve_will_transition(struct ucred *old, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp);
-void mac_create_proc0(struct ucred *cred);
-void mac_create_proc1(struct ucred *cred);
-void mac_thread_userret(struct thread *td);
-
-/* Access control checks. */
-int mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet);
-int mac_check_cred_visible(struct ucred *u1, struct ucred *u2);
-int mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *m);
-int mac_check_kenv_dump(struct ucred *cred);
-int mac_check_kenv_get(struct ucred *cred, char *name);
-int mac_check_kenv_set(struct ucred *cred, char *name, char *value);
-int mac_check_kenv_unset(struct ucred *cred, char *name);
-int mac_check_kld_load(struct ucred *cred, struct vnode *vp);
-int mac_check_kld_stat(struct ucred *cred);
-int mac_check_kld_unload(struct ucred *cred);
-int mac_check_mount_stat(struct ucred *cred, struct mount *mp);
-int mac_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe,
- unsigned long cmd, void *data);
-int mac_check_pipe_poll(struct ucred *cred, struct pipe *pipe);
-int mac_check_pipe_read(struct ucred *cred, struct pipe *pipe);
-int mac_check_pipe_stat(struct ucred *cred, struct pipe *pipe);
-int mac_check_pipe_write(struct ucred *cred, struct pipe *pipe);
-int mac_check_proc_debug(struct ucred *cred, struct proc *proc);
-int mac_check_proc_sched(struct ucred *cred, struct proc *proc);
-int mac_check_proc_signal(struct ucred *cred, struct proc *proc,
- int signum);
-int mac_check_socket_bind(struct ucred *cred, struct socket *so,
- struct sockaddr *sockaddr);
-int mac_check_socket_connect(struct ucred *cred, struct socket *so,
- struct sockaddr *sockaddr);
-int mac_check_socket_deliver(struct socket *so, struct mbuf *m);
-int mac_check_socket_listen(struct ucred *cred, struct socket *so);
-int mac_check_socket_receive(struct ucred *cred, struct socket *so);
-int mac_check_socket_send(struct ucred *cred, struct socket *so);
-int mac_check_socket_visible(struct ucred *cred, struct socket *so);
-int mac_check_sysarch_ioperm(struct ucred *cred);
-int mac_check_system_acct(struct ucred *cred, struct vnode *vp);
-int mac_check_system_nfsd(struct ucred *cred);
-int mac_check_system_reboot(struct ucred *cred, int howto);
-int mac_check_system_settime(struct ucred *cred);
-int mac_check_system_swapon(struct ucred *cred, struct vnode *vp);
-int mac_check_system_swapoff(struct ucred *cred, struct vnode *vp);
-int mac_check_system_sysctl(struct ucred *cred, int *name,
- u_int namelen, void *old, size_t *oldlenp, int inkernel,
- void *new, size_t newlen);
-int mac_check_vnode_access(struct ucred *cred, struct vnode *vp,
- int acc_mode);
-int mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp);
-int mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp);
-int mac_check_vnode_create(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp, struct vattr *vap);
-int mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp);
-int mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
- acl_type_t type);
-int mac_check_vnode_exec(struct ucred *cred, struct vnode *vp,
- struct image_params *imgp);
-int mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp,
- acl_type_t type);
-int mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio);
-int mac_check_vnode_link(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp);
-int mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp);
-int mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp,
- int prot);
-int mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp,
- int prot);
-int mac_check_vnode_open(struct ucred *cred, struct vnode *vp,
- int acc_mode);
-int mac_check_vnode_poll(struct ucred *active_cred,
- struct ucred *file_cred, struct vnode *vp);
-int mac_check_vnode_read(struct ucred *active_cred,
- struct ucred *file_cred, struct vnode *vp);
-int mac_check_vnode_readdir(struct ucred *cred, struct vnode *vp);
-int mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp);
-int mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp);
-int mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, int samedir, struct componentname *cnp);
-int mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp);
-int mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp,
- acl_type_t type, struct acl *acl);
-int mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio);
-int mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp,
- u_long flags);
-int mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp,
- mode_t mode);
-int mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp,
- uid_t uid, gid_t gid);
-int mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
- struct timespec atime, struct timespec mtime);
-int mac_check_vnode_stat(struct ucred *active_cred,
- struct ucred *file_cred, struct vnode *vp);
-int mac_check_vnode_write(struct ucred *active_cred,
- struct ucred *file_cred, struct vnode *vp);
-int mac_getsockopt_label_get(struct ucred *cred, struct socket *so,
- struct mac *extmac);
-int mac_getsockopt_peerlabel_get(struct ucred *cred, struct socket *so,
- struct mac *extmac);
-int mac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet);
-int mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet);
-int mac_setsockopt_label_set(struct ucred *cred, struct socket *so,
- struct mac *extmac);
-int mac_pipe_label_set(struct ucred *cred, struct pipe *pipe,
- struct label *label);
-void mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred);
-
-/*
- * Calls to help various file systems implement labeling functionality
- * using their existing EA implementation.
- */
-int vop_stdsetlabel_ea(struct vop_setlabel_args *ap);
-
-#endif /* !_KERNEL */
-
-#endif /* !_SYS_MAC_H */
diff --git a/sys/security/mac/mac_internal.h b/sys/security/mac/mac_internal.h
deleted file mode 100644
index fb06edea3012..000000000000
--- a/sys/security/mac/mac_internal.h
+++ /dev/null
@@ -1,3975 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * Copyright (c) 2001 Ilmar S. Habibulin
- * Copyright (c) 2001, 2002, 2003 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * This software was developed by Robert Watson and Ilmar Habibulin for the
- * TrustedBSD Project.
- *
- * This software was developed for the FreeBSD Project in part by Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
- * as part of the DARPA CHATS research program.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-/*
- * Developed by the TrustedBSD Project.
- *
- * Framework for extensible kernel access control. Kernel and userland
- * interface to the framework, policy registration and composition.
- */
-
-#include "opt_mac.h"
-#include "opt_devfs.h"
-
-#include <sys/param.h>
-#include <sys/condvar.h>
-#include <sys/extattr.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/mac.h>
-#include <sys/module.h>
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/sysent.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/file.h>
-#include <sys/namei.h>
-#include <sys/socket.h>
-#include <sys/pipe.h>
-#include <sys/socketvar.h>
-#include <sys/sysctl.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-
-#include <sys/mac_policy.h>
-
-#include <fs/devfs/devfs.h>
-
-#include <net/bpfdesc.h>
-#include <net/if.h>
-#include <net/if_var.h>
-
-#include <netinet/in.h>
-#include <netinet/ip_var.h>
-
-#ifdef MAC
-
-/*
- * Declare that the kernel provides MAC support, version 1. This permits
- * modules to refuse to be loaded if the necessary support isn't present,
- * even if it's pre-boot.
- */
-MODULE_VERSION(kernel_mac_support, 1);
-
-SYSCTL_DECL(_security);
-
-SYSCTL_NODE(_security, OID_AUTO, mac, CTLFLAG_RW, 0,
- "TrustedBSD MAC policy controls");
-
-#if MAC_MAX_SLOTS > 32
-#error "MAC_MAX_SLOTS too large"
-#endif
-
-static unsigned int mac_max_slots = MAC_MAX_SLOTS;
-static unsigned int mac_slot_offsets_free = (1 << MAC_MAX_SLOTS) - 1;
-SYSCTL_UINT(_security_mac, OID_AUTO, max_slots, CTLFLAG_RD,
- &mac_max_slots, 0, "");
-
-/*
- * Has the kernel started generating labeled objects yet? All read/write
- * access to this variable is serialized during the boot process. Following
- * the end of serialization, we don't update this flag; no locking.
- */
-static int mac_late = 0;
-
-/*
- * Warn about EA transactions only the first time they happen.
- * Weak coherency, no locking.
- */
-static int ea_warn_once = 0;
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
-/*
- * Flag to indicate whether or not we should allocate label storage for
- * new mbufs. Since most dynamic policies we currently work with don't
- * rely on mbuf labeling, try to avoid paying the cost of mtag allocation
- * unless specifically notified of interest. One result of this is
- * that if a dynamically loaded policy requests mbuf labels, it must
- * be able to deal with a NULL label being returned on any mbufs that
- * were already in flight when the policy was loaded. Since the policy
- * already has to deal with uninitialized labels, this probably won't
- * be a problem. Note: currently no locking. Will this be a problem?
- */
-static int mac_labelmbufs = 0;
-#endif
-
-static int mac_enforce_fs = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_fs, CTLFLAG_RW,
- &mac_enforce_fs, 0, "Enforce MAC policy on file system objects");
-TUNABLE_INT("security.mac.enforce_fs", &mac_enforce_fs);
-
-static int mac_enforce_kld = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_kld, CTLFLAG_RW,
- &mac_enforce_kld, 0, "Enforce MAC policy on kld operations");
-TUNABLE_INT("security.mac.enforce_kld", &mac_enforce_kld);
-
-static int mac_enforce_network = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_network, CTLFLAG_RW,
- &mac_enforce_network, 0, "Enforce MAC policy on network packets");
-TUNABLE_INT("security.mac.enforce_network", &mac_enforce_network);
-
-static int mac_enforce_pipe = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_pipe, CTLFLAG_RW,
- &mac_enforce_pipe, 0, "Enforce MAC policy on pipe operations");
-TUNABLE_INT("security.mac.enforce_pipe", &mac_enforce_pipe);
-
-static int mac_enforce_process = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_process, CTLFLAG_RW,
- &mac_enforce_process, 0, "Enforce MAC policy on inter-process operations");
-TUNABLE_INT("security.mac.enforce_process", &mac_enforce_process);
-
-static int mac_enforce_socket = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_socket, CTLFLAG_RW,
- &mac_enforce_socket, 0, "Enforce MAC policy on socket operations");
-TUNABLE_INT("security.mac.enforce_socket", &mac_enforce_socket);
-
-static int mac_enforce_system = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_system, CTLFLAG_RW,
- &mac_enforce_system, 0, "Enforce MAC policy on system operations");
-TUNABLE_INT("security.mac.enforce_system", &mac_enforce_system);
-
-static int mac_enforce_vm = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_vm, CTLFLAG_RW,
- &mac_enforce_vm, 0, "Enforce MAC policy on vm operations");
-TUNABLE_INT("security.mac.enforce_vm", &mac_enforce_vm);
-
-static int mac_mmap_revocation = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation, CTLFLAG_RW,
- &mac_mmap_revocation, 0, "Revoke mmap access to files on subject "
- "relabel");
-static int mac_mmap_revocation_via_cow = 0;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation_via_cow, CTLFLAG_RW,
- &mac_mmap_revocation_via_cow, 0, "Revoke mmap access to files via "
- "copy-on-write semantics, or by removing all write access");
-
-#ifdef MAC_DEBUG
-SYSCTL_NODE(_security_mac, OID_AUTO, debug, CTLFLAG_RW, 0,
- "TrustedBSD MAC debug info");
-
-static int mac_debug_label_fallback = 0;
-SYSCTL_INT(_security_mac_debug, OID_AUTO, label_fallback, CTLFLAG_RW,
- &mac_debug_label_fallback, 0, "Filesystems should fall back to fs label"
- "when label is corrupted.");
-TUNABLE_INT("security.mac.debug_label_fallback",
- &mac_debug_label_fallback);
-
-SYSCTL_NODE(_security_mac_debug, OID_AUTO, counters, CTLFLAG_RW, 0,
- "TrustedBSD MAC object counters");
-
-static unsigned int nmacmbufs, nmaccreds, nmacifnets, nmacbpfdescs,
- nmacsockets, nmacmounts, nmactemp, nmacvnodes, nmacdevfsdirents,
- nmacipqs, nmacpipes, nmacprocs;
-
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mbufs, CTLFLAG_RD,
- &nmacmbufs, 0, "number of mbufs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, creds, CTLFLAG_RD,
- &nmaccreds, 0, "number of ucreds in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ifnets, CTLFLAG_RD,
- &nmacifnets, 0, "number of ifnets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ipqs, CTLFLAG_RD,
- &nmacipqs, 0, "number of ipqs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, bpfdescs, CTLFLAG_RD,
- &nmacbpfdescs, 0, "number of bpfdescs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, sockets, CTLFLAG_RD,
- &nmacsockets, 0, "number of sockets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, pipes, CTLFLAG_RD,
- &nmacpipes, 0, "number of pipes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, procs, CTLFLAG_RD,
- &nmacprocs, 0, "number of procs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mounts, CTLFLAG_RD,
- &nmacmounts, 0, "number of mounts in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, temp, CTLFLAG_RD,
- &nmactemp, 0, "number of temporary labels in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, vnodes, CTLFLAG_RD,
- &nmacvnodes, 0, "number of vnodes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, devfsdirents, CTLFLAG_RD,
- &nmacdevfsdirents, 0, "number of devfs dirents inuse");
-#endif
-
-static int error_select(int error1, int error2);
-static int mac_policy_register(struct mac_policy_conf *mpc);
-static int mac_policy_unregister(struct mac_policy_conf *mpc);
-
-static void mac_check_vnode_mmap_downgrade(struct ucred *cred,
- struct vnode *vp, int *prot);
-static void mac_cred_mmapped_drop_perms_recurse(struct thread *td,
- struct ucred *cred, struct vm_map *map);
-
-static void mac_destroy_socket_label(struct label *label);
-
-static int mac_setlabel_vnode_extattr(struct ucred *cred,
- struct vnode *vp, struct label *intlabel);
-
-MALLOC_DEFINE(M_MACPIPELABEL, "macpipelabel", "MAC labels for pipes");
-MALLOC_DEFINE(M_MACTEMP, "mactemp", "MAC temporary label storage");
-
-/*
- * mac_static_policy_list holds a list of policy modules that are not
- * loaded while the system is "live", and cannot be unloaded. These
- * policies can be invoked without holding the busy count.
- *
- * mac_policy_list stores the list of dynamic policies. A busy count is
- * maintained for the list, stored in mac_policy_busy. The busy count
- * is protected by mac_policy_mtx; the list may be modified only
- * while the busy count is 0, requiring that the lock be held to
- * prevent new references to the list from being acquired. For almost
- * all operations, incrementing the busy count is sufficient to
- * guarantee consistency, as the list cannot be modified while the
- * busy count is elevated. For a few special operations involving a
- * change to the list of active policies, the mtx itself must be held.
- * A condition variable, mac_policy_cv, is used to signal potential
- * exclusive consumers that they should try to acquire the lock if a
- * first attempt at exclusive access fails.
- */
-static struct mtx mac_policy_mtx;
-static struct cv mac_policy_cv;
-static int mac_policy_count;
-static LIST_HEAD(, mac_policy_conf) mac_policy_list;
-static LIST_HEAD(, mac_policy_conf) mac_static_policy_list;
-
-/*
- * We manually invoke WITNESS_WARN() to allow Witness to generate
- * warnings even if we don't end up ever triggering the wait at
- * run-time. The consumer of the exclusive interface must not hold
- * any locks (other than potentially Giant) since we may sleep for
- * long (potentially indefinite) periods of time waiting for the
- * framework to become quiescent so that a policy list change may
- * be made.
- */
-static __inline void
-mac_policy_grab_exclusive(void)
-{
- WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
- "mac_policy_grab_exclusive() at %s:%d", __FILE__, __LINE__);
- mtx_lock(&mac_policy_mtx);
- while (mac_policy_count != 0)
- cv_wait(&mac_policy_cv, &mac_policy_mtx);
-}
-
-static __inline void
-mac_policy_assert_exclusive(void)
-{
- mtx_assert(&mac_policy_mtx, MA_OWNED);
- KASSERT(mac_policy_count == 0,
- ("mac_policy_assert_exclusive(): not exclusive"));
-}
-
-static __inline void
-mac_policy_release_exclusive(void)
-{
-
- KASSERT(mac_policy_count == 0,
- ("mac_policy_release_exclusive(): not exclusive"));
- mtx_unlock(&mac_policy_mtx);
- cv_signal(&mac_policy_cv);
-}
-
-static __inline void
-mac_policy_list_busy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count++;
- mtx_unlock(&mac_policy_mtx);
-}
-
-static __inline int
-mac_policy_list_conditional_busy(void)
-{
- int ret;
-
- mtx_lock(&mac_policy_mtx);
- if (!LIST_EMPTY(&mac_policy_list)) {
- mac_policy_count++;
- ret = 1;
- } else
- ret = 0;
- mtx_unlock(&mac_policy_mtx);
- return (ret);
-}
-
-static __inline void
-mac_policy_list_unbusy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count--;
- KASSERT(mac_policy_count >= 0, ("MAC_POLICY_LIST_LOCK"));
- if (mac_policy_count == 0)
- cv_signal(&mac_policy_cv);
- mtx_unlock(&mac_policy_mtx);
-}
-
-/*
- * MAC_CHECK performs the designated check by walking the policy
- * module list and checking with each as to how it feels about the
- * request. Note that it returns its value via 'error' in the scope
- * of the caller.
- */
-#define MAC_CHECK(check, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- error = 0; \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * MAC_BOOLEAN performs the designated boolean composition by walking
- * the module list, invoking each instance of the operation, and
- * combining the results using the passed C operator. Note that it
- * returns its value via 'result' in the scope of the caller, which
- * should be initialized by the caller in a meaningful way to get
- * a meaningful result.
- */
-#define MAC_BOOLEAN(operation, composition, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation \
- (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-#define MAC_EXTERNALIZE(type, label, elementlist, outbuf, \
- outbuflen) do { \
- char *curptr, *curptr_start, *element_name, *element_temp; \
- size_t left, left_start, len; \
- int claimed, first, first_start, ignorenotfound; \
- \
- error = 0; \
- element_temp = elementlist; \
- curptr = outbuf; \
- curptr[0] = '\0'; \
- left = outbuflen; \
- first = 1; \
- while ((element_name = strsep(&element_temp, ",")) != NULL) { \
- curptr_start = curptr; \
- left_start = left; \
- first_start = first; \
- if (element_name[0] == '?') { \
- element_name++; \
- ignorenotfound = 1; \
- } else \
- ignorenotfound = 0; \
- claimed = 0; \
- if (first) { \
- len = snprintf(curptr, left, "%s/", \
- element_name); \
- first = 0; \
- } else \
- len = snprintf(curptr, left, ",%s/", \
- element_name); \
- if (len >= left) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- \
- MAC_CHECK(externalize_ ## type, label, element_name, \
- curptr, left, &len, &claimed); \
- if (error) \
- break; \
- if (claimed == 1) { \
- if (len >= outbuflen) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- } else if (claimed == 0 && ignorenotfound) { \
- /* \
- * Revert addition of the label element \
- * name. \
- */ \
- curptr = curptr_start; \
- *curptr = '\0'; \
- left = left_start; \
- first = first_start; \
- } else { \
- error = EINVAL; /* XXXMAC: ENOLABEL */ \
- break; \
- } \
- } \
-} while (0)
-
-#define MAC_INTERNALIZE(type, label, instring) do { \
- char *element, *element_name, *element_data; \
- int claimed; \
- \
- error = 0; \
- element = instring; \
- while ((element_name = strsep(&element, ",")) != NULL) { \
- element_data = element_name; \
- element_name = strsep(&element_data, "/"); \
- if (element_data == NULL) { \
- error = EINVAL; \
- break; \
- } \
- claimed = 0; \
- MAC_CHECK(internalize_ ## type, label, element_name, \
- element_data, &claimed); \
- if (error) \
- break; \
- if (claimed != 1) { \
- /* XXXMAC: Another error here? */ \
- error = EINVAL; \
- break; \
- } \
- } \
-} while (0)
-
-/*
- * MAC_PERFORM performs the designated operation by walking the policy
- * module list and invoking that operation for each policy.
- */
-#define MAC_PERFORM(operation, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * Initialize the MAC subsystem, including appropriate SMP locks.
- */
-static void
-mac_init(void)
-{
-
- LIST_INIT(&mac_static_policy_list);
- LIST_INIT(&mac_policy_list);
-
- mtx_init(&mac_policy_mtx, "mac_policy_mtx", NULL, MTX_DEF);
- cv_init(&mac_policy_cv, "mac_policy_cv");
-}
-
-/*
- * For the purposes of modules that want to know if they were loaded
- * "early", set the mac_late flag once we've processed modules either
- * linked into the kernel, or loaded before the kernel startup.
- */
-static void
-mac_late_init(void)
-{
-
- mac_late = 1;
-}
-
-/*
- * After the policy list has changed, walk the list to update any global
- * flags.
- */
-static void
-mac_policy_updateflags(void)
-{
- struct mac_policy_conf *tmpc;
-#ifndef MAC_ALWAYS_LABEL_MBUF
- int labelmbufs;
-#endif
-
- mac_policy_assert_exclusive();
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- labelmbufs = 0;
-#endif
-
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- mac_labelmbufs = (labelmbufs != 0);
-#endif
-}
-
-/*
- * Allow MAC policy modules to register during boot, etc.
- */
-int
-mac_policy_modevent(module_t mod, int type, void *data)
-{
- struct mac_policy_conf *mpc;
- int error;
-
- error = 0;
- mpc = (struct mac_policy_conf *) data;
-
- switch (type) {
- case MOD_LOAD:
- if (mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_NOTLATE &&
- mac_late) {
- printf("mac_policy_modevent: can't load %s policy "
- "after booting\n", mpc->mpc_name);
- error = EBUSY;
- break;
- }
- error = mac_policy_register(mpc);
- break;
- case MOD_UNLOAD:
- /* Don't unregister the module if it was never registered. */
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED)
- != 0)
- error = mac_policy_unregister(mpc);
- else
- error = 0;
- break;
- default:
- break;
- }
-
- return (error);
-}
-
-static int
-mac_policy_register(struct mac_policy_conf *mpc)
-{
- struct mac_policy_conf *tmpc;
- int error, slot, static_entry;
-
- error = 0;
-
- /*
- * We don't technically need exclusive access while !mac_late,
- * but hold it for assertion consistency.
- */
- mac_policy_grab_exclusive();
-
- /*
- * If the module can potentially be unloaded, or we're loading
- * late, we have to stick it in the non-static list and pay
- * an extra performance overhead. Otherwise, we can pay a
- * light locking cost and stick it in the static list.
- */
- static_entry = (!mac_late &&
- !(mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK));
-
- if (static_entry) {
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- } else {
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- }
- if (mpc->mpc_field_off != NULL) {
- slot = ffs(mac_slot_offsets_free);
- if (slot == 0) {
- error = ENOMEM;
- goto out;
- }
- slot--;
- mac_slot_offsets_free &= ~(1 << slot);
- *mpc->mpc_field_off = slot;
- }
- mpc->mpc_runtime_flags |= MPC_RUNTIME_FLAG_REGISTERED;
-
- /*
- * If we're loading a MAC module after the framework has
- * initialized, it has to go into the dynamic list. If
- * we're loading it before we've finished initializing,
- * it can go into the static list with weaker locker
- * requirements.
- */
- if (static_entry)
- LIST_INSERT_HEAD(&mac_static_policy_list, mpc, mpc_list);
- else
- LIST_INSERT_HEAD(&mac_policy_list, mpc, mpc_list);
-
- /* Per-policy initialization. */
- if (mpc->mpc_ops->mpo_init != NULL)
- (*(mpc->mpc_ops->mpo_init))(mpc);
- mac_policy_updateflags();
-
- printf("Security policy loaded: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
-out:
- mac_policy_release_exclusive();
- return (error);
-}
-
-static int
-mac_policy_unregister(struct mac_policy_conf *mpc)
-{
-
- /*
- * If we fail the load, we may get a request to unload. Check
- * to see if we did the run-time registration, and if not,
- * silently succeed.
- */
- mac_policy_grab_exclusive();
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED) == 0) {
- mac_policy_release_exclusive();
- return (0);
- }
-#if 0
- /*
- * Don't allow unloading modules with private data.
- */
- if (mpc->mpc_field_off != NULL) {
- MAC_POLICY_LIST_UNLOCK();
- return (EBUSY);
- }
-#endif
- /*
- * Only allow the unload to proceed if the module is unloadable
- * by its own definition.
- */
- if ((mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK) == 0) {
- mac_policy_release_exclusive();
- return (EBUSY);
- }
- if (mpc->mpc_ops->mpo_destroy != NULL)
- (*(mpc->mpc_ops->mpo_destroy))(mpc);
-
- LIST_REMOVE(mpc, mpc_list);
- mpc->mpc_runtime_flags &= ~MPC_RUNTIME_FLAG_REGISTERED;
- mac_policy_updateflags();
-
- mac_policy_release_exclusive();
-
- printf("Security policy unload: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
- return (0);
-}
-
-/*
- * Define an error value precedence, and given two arguments, selects the
- * value with the higher precedence.
- */
-static int
-error_select(int error1, int error2)
-{
-
- /* Certain decision-making errors take top priority. */
- if (error1 == EDEADLK || error2 == EDEADLK)
- return (EDEADLK);
-
- /* Invalid arguments should be reported where possible. */
- if (error1 == EINVAL || error2 == EINVAL)
- return (EINVAL);
-
- /* Precedence goes to "visibility", with both process and file. */
- if (error1 == ESRCH || error2 == ESRCH)
- return (ESRCH);
-
- if (error1 == ENOENT || error2 == ENOENT)
- return (ENOENT);
-
- /* Precedence goes to DAC/MAC protections. */
- if (error1 == EACCES || error2 == EACCES)
- return (EACCES);
-
- /* Precedence goes to privilege. */
- if (error1 == EPERM || error2 == EPERM)
- return (EPERM);
-
- /* Precedence goes to error over success; otherwise, arbitrary. */
- if (error1 != 0)
- return (error1);
- return (error2);
-}
-
-static struct label *
-mbuf_to_label(struct mbuf *mbuf)
-{
- struct m_tag *tag;
- struct label *label;
-
- tag = m_tag_find(mbuf, PACKET_TAG_MACLABEL, NULL);
- label = (struct label *)(tag+1);
-
- return (label);
-}
-
-static void
-mac_init_label(struct label *label)
-{
-
- bzero(label, sizeof(*label));
- label->l_flags = MAC_FLAG_INITIALIZED;
-}
-
-static void
-mac_destroy_label(struct label *label)
-{
-
- KASSERT(label->l_flags & MAC_FLAG_INITIALIZED,
- ("destroying uninitialized label"));
-
- bzero(label, sizeof(*label));
- /* implicit: label->l_flags &= ~MAC_FLAG_INITIALIZED; */
-}
-
-void
-mac_init_bpfdesc(struct bpf_d *bpf_d)
-{
-
- mac_init_label(&bpf_d->bd_label);
- MAC_PERFORM(init_bpfdesc_label, &bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_init_cred_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_cred_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_init_cred(struct ucred *cred)
-{
-
- mac_init_cred_label(&cred->cr_label);
-}
-
-void
-mac_init_devfsdirent(struct devfs_dirent *de)
-{
-
- mac_init_label(&de->de_label);
- MAC_PERFORM(init_devfsdirent_label, &de->de_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_init_ifnet_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_ifnet_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_init_ifnet(struct ifnet *ifp)
-{
-
- mac_init_ifnet_label(&ifp->if_label);
-}
-
-int
-mac_init_ipq(struct ipq *ipq, int flag)
-{
- int error;
-
- mac_init_label(&ipq->ipq_label);
-
- MAC_CHECK(init_ipq_label, &ipq->ipq_label, flag);
- if (error) {
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacipqs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf_tag(struct m_tag *tag, int flag)
-{
- struct label *label;
- int error;
-
- label = (struct label *) (tag + 1);
- mac_init_label(label);
-
- MAC_CHECK(init_mbuf_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacmbufs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf(struct mbuf *m, int flag)
-{
- struct m_tag *tag;
- int error;
-
- M_ASSERTPKTHDR(m);
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- /*
- * Don't reserve space for labels on mbufs unless we have a policy
- * that uses the labels.
- */
- if (mac_labelmbufs) {
-#endif
- tag = m_tag_get(PACKET_TAG_MACLABEL, sizeof(struct label),
- flag);
- if (tag == NULL)
- return (ENOMEM);
- error = mac_init_mbuf_tag(tag, flag);
- if (error) {
- m_tag_free(tag);
- return (error);
- }
- m_tag_prepend(m, tag);
-#ifndef MAC_ALWAYS_LABEL_MBUF
- }
-#endif
- return (0);
-}
-
-void
-mac_init_mount(struct mount *mp)
-{
-
- mac_init_label(&mp->mnt_mntlabel);
- mac_init_label(&mp->mnt_fslabel);
- MAC_PERFORM(init_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(init_mount_fs_label, &mp->mnt_fslabel);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_init_pipe_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_pipe_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_init_pipe(struct pipe *pipe)
-{
- struct label *label;
-
- label = malloc(sizeof(struct label), M_MACPIPELABEL, M_ZERO|M_WAITOK);
- pipe->pipe_label = label;
- pipe->pipe_peer->pipe_label = label;
- mac_init_pipe_label(label);
-}
-
-void
-mac_init_proc(struct proc *p)
-{
-
- mac_init_label(&p->p_label);
- MAC_PERFORM(init_proc_label, &p->p_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacprocs, 1);
-#endif
-}
-
-static int
-mac_init_socket_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacsockets, 1);
-#endif
-
- return (error);
-}
-
-static int
-mac_init_socket_peer_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_peer_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
- return (error);
-}
-
-int
-mac_init_socket(struct socket *socket, int flag)
-{
- int error;
-
- error = mac_init_socket_label(&socket->so_label, flag);
- if (error)
- return (error);
-
- error = mac_init_socket_peer_label(&socket->so_peerlabel, flag);
- if (error)
- mac_destroy_socket_label(&socket->so_label);
-
- return (error);
-}
-
-void
-mac_init_vnode_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_vnode_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_init_vnode(struct vnode *vp)
-{
-
- mac_init_vnode_label(&vp->v_label);
-}
-
-void
-mac_destroy_bpfdesc(struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(destroy_bpfdesc_label, &bpf_d->bd_label);
- mac_destroy_label(&bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_destroy_cred_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_cred_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_destroy_cred(struct ucred *cred)
-{
-
- mac_destroy_cred_label(&cred->cr_label);
-}
-
-void
-mac_destroy_devfsdirent(struct devfs_dirent *de)
-{
-
- MAC_PERFORM(destroy_devfsdirent_label, &de->de_label);
- mac_destroy_label(&de->de_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_destroy_ifnet_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_ifnet_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_destroy_ifnet(struct ifnet *ifp)
-{
-
- mac_destroy_ifnet_label(&ifp->if_label);
-}
-
-void
-mac_destroy_ipq(struct ipq *ipq)
-{
-
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacipqs, 1);
-#endif
-}
-
-void
-mac_destroy_mbuf_tag(struct m_tag *tag)
-{
- struct label *label;
-
- label = (struct label *)(tag+1);
-
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmbufs, 1);
-#endif
-}
-
-void
-mac_destroy_mount(struct mount *mp)
-{
-
- MAC_PERFORM(destroy_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(destroy_mount_fs_label, &mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_mntlabel);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_destroy_pipe_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_pipe_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_destroy_pipe(struct pipe *pipe)
-{
-
- mac_destroy_pipe_label(pipe->pipe_label);
- free(pipe->pipe_label, M_MACPIPELABEL);
-}
-
-void
-mac_destroy_proc(struct proc *p)
-{
-
- MAC_PERFORM(destroy_proc_label, &p->p_label);
- mac_destroy_label(&p->p_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacprocs, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacsockets, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_peer_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_peer_label, label);
- mac_destroy_label(label);
-}
-
-void
-mac_destroy_socket(struct socket *socket)
-{
-
- mac_destroy_socket_label(&socket->so_label);
- mac_destroy_socket_peer_label(&socket->so_peerlabel);
-}
-
-void
-mac_destroy_vnode_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_vnode_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_destroy_vnode(struct vnode *vp)
-{
-
- mac_destroy_vnode_label(&vp->v_label);
-}
-
-void
-mac_copy_mbuf_tag(struct m_tag *src, struct m_tag *dest)
-{
- struct label *src_label, *dest_label;
-
- src_label = (struct label *)(src+1);
- dest_label = (struct label *)(dest+1);
-
- /*
- * mac_init_mbuf_tag() is called on the target tag in
- * m_tag_copy(), so we don't need to call it here.
- */
- MAC_PERFORM(copy_mbuf_label, src_label, dest_label);
-}
-
-static void
-mac_copy_pipe_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_pipe_label, src, dest);
-}
-
-void
-mac_copy_vnode_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_vnode_label, src, dest);
-}
-
-static int
-mac_check_structmac_consistent(struct mac *mac)
-{
-
- if (mac->m_buflen > MAC_MAX_LABEL_BUF_LEN)
- return (EINVAL);
-
- return (0);
-}
-
-static int
-mac_externalize_cred_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(cred_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_ifnet_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(ifnet_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_pipe_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(pipe_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_peer_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_peer_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_vnode_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(vnode_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_internalize_cred_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(cred_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_ifnet_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(ifnet_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_pipe_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(pipe_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_socket_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(socket_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_vnode_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(vnode_label, label, string);
-
- return (error);
-}
-
-/*
- * Initialize MAC label for the first kernel process, from which other
- * kernel processes and threads are spawned.
- */
-void
-mac_create_proc0(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc0, cred);
-}
-
-/*
- * Initialize MAC label for the first userland process, from which other
- * userland processes and threads are spawned.
- */
-void
-mac_create_proc1(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc1, cred);
-}
-
-void
-mac_thread_userret(struct thread *td)
-{
-
- MAC_PERFORM(thread_userret, td);
-}
-
-/*
- * When a new process is created, its label must be initialized. Generally,
- * this involves inheritence from the parent process, modulo possible
- * deltas. This function allows that processing to take place.
- */
-void
-mac_create_cred(struct ucred *parent_cred, struct ucred *child_cred)
-{
-
- MAC_PERFORM(create_cred, parent_cred, child_cred);
-}
-
-void
-mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(update_devfsdirent, mp, de, &de->de_label, vp,
- &vp->v_label);
-}
-
-void
-mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_devfs, mp, &mp->mnt_fslabel, de,
- &de->de_label, vp, &vp->v_label);
-}
-
-int
-mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_associate_vnode_extattr");
-
- MAC_CHECK(associate_vnode_extattr, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-
- return (error);
-}
-
-void
-mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_singlelabel, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-}
-
-int
-mac_create_vnode_extattr(struct ucred *cred, struct mount *mp,
- struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_create_vnode_extattr");
- ASSERT_VOP_LOCKED(vp, "mac_create_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(create_vnode_extattr, cred, mp, &mp->mnt_fslabel,
- dvp, &dvp->v_label, vp, &vp->v_label, cnp);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-static int
-mac_setlabel_vnode_extattr(struct ucred *cred, struct vnode *vp,
- struct label *intlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_setlabel_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(setlabel_vnode_extattr, cred, vp, &vp->v_label, intlabel);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-int
-mac_execve_enter(struct image_params *imgp, struct mac *mac_p,
- struct label *execlabelstorage)
-{
- struct mac mac;
- char *buffer;
- int error;
-
- if (mac_p == NULL)
- return (0);
-
- error = copyin(mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(execlabelstorage);
- error = mac_internalize_cred_label(execlabelstorage, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(execlabelstorage);
- return (error);
- }
- imgp->execlabel = execlabelstorage;
- return (0);
-}
-
-void
-mac_execve_exit(struct image_params *imgp)
-{
- if (imgp->execlabel != NULL)
- mac_destroy_cred_label(imgp->execlabel);
-}
-
-void
-mac_execve_transition(struct ucred *old, struct ucred *new, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return;
-
- MAC_PERFORM(execve_transition, old, new, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-}
-
-int
-mac_execve_will_transition(struct ucred *old, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
- int result;
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_will_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- result = 0;
- MAC_BOOLEAN(execve_will_transition, ||, old, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-
- return (result);
-}
-
-int
-mac_check_vnode_access(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_access");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_access, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chroot");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chroot, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_create(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp, struct vattr *vap)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_create");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_create, cred, dvp, &dvp->v_label, cnp, vap);
- return (error);
-}
-
-int
-mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp, struct vnode *vp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_delete");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_delete");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_delete, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
- acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_deleteacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_deleteacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_exec(struct ucred *cred, struct vnode *vp,
- struct image_params *imgp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_exec");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_exec, cred, vp, &vp->v_label, imgp,
- imgp->execlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp, acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_link(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_link");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_link");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_link, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_lookup");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_lookup, cred, dvp, &dvp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mmap, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-void
-mac_check_vnode_mmap_downgrade(struct ucred *cred, struct vnode *vp, int *prot)
-{
- int result = *prot;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap_downgrade");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return;
-
- MAC_PERFORM(check_vnode_mmap_downgrade, cred, vp, &vp->v_label,
- &result);
-
- *prot = result;
-}
-
-int
-mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mprotect");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mprotect, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-int
-mac_check_vnode_open(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_open");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_open, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_poll");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_poll, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_read");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_read, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_readdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_readdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_readlink");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readlink, cred, vp, &vp->v_label);
- return (error);
-}
-
-static int
-mac_check_vnode_relabel(struct ucred *cred, struct vnode *vp,
- struct label *newlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_relabel");
-
- MAC_CHECK(check_vnode_relabel, cred, vp, &vp->v_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_from");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_from");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_from, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, int samedir, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_to");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_to");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_to, cred, dvp, &dvp->v_label, vp,
- vp != NULL ? &vp->v_label : NULL, samedir, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_revoke");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_revoke, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type,
- struct acl *acl)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setacl, cred, vp, &vp->v_label, type, acl);
- return (error);
-}
-
-int
-mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp, u_long flags)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setflags");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setflags, cred, vp, &vp->v_label, flags);
- return (error);
-}
-
-int
-mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp, mode_t mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setmode");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setmode, cred, vp, &vp->v_label, mode);
- return (error);
-}
-
-int
-mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp, uid_t uid,
- gid_t gid)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setowner");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setowner, cred, vp, &vp->v_label, uid, gid);
- return (error);
-}
-
-int
-mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
- struct timespec atime, struct timespec mtime)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setutimes");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setutimes, cred, vp, &vp->v_label, atime,
- mtime);
- return (error);
-}
-
-int
-mac_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_stat");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_stat, active_cred, file_cred, vp,
- &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_write(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_write");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_write, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-/*
- * When relabeling a process, call out to the policies for the maximum
- * permission allowed for each object type we know about in its
- * memory space, and revoke access (in the least surprising ways we
- * know) when necessary. The process lock is not held here.
- */
-void
-mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred)
-{
-
- /* XXX freeze all other threads */
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- &td->td_proc->p_vmspace->vm_map);
- /* XXX allow other threads to continue */
-}
-
-static __inline const char *
-prot2str(vm_prot_t prot)
-{
-
- switch (prot & VM_PROT_ALL) {
- case VM_PROT_READ:
- return ("r--");
- case VM_PROT_READ | VM_PROT_WRITE:
- return ("rw-");
- case VM_PROT_READ | VM_PROT_EXECUTE:
- return ("r-x");
- case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("rwx");
- case VM_PROT_WRITE:
- return ("-w-");
- case VM_PROT_EXECUTE:
- return ("--x");
- case VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("-wx");
- default:
- return ("---");
- }
-}
-
-static void
-mac_cred_mmapped_drop_perms_recurse(struct thread *td, struct ucred *cred,
- struct vm_map *map)
-{
- struct vm_map_entry *vme;
- int result;
- vm_prot_t revokeperms;
- vm_object_t object;
- vm_ooffset_t offset;
- struct vnode *vp;
-
- if (!mac_mmap_revocation)
- return;
-
- vm_map_lock_read(map);
- for (vme = map->header.next; vme != &map->header; vme = vme->next) {
- if (vme->eflags & MAP_ENTRY_IS_SUB_MAP) {
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- vme->object.sub_map);
- continue;
- }
- /*
- * Skip over entries that obviously are not shared.
- */
- if (vme->eflags & (MAP_ENTRY_COW | MAP_ENTRY_NOSYNC) ||
- !vme->max_protection)
- continue;
- /*
- * Drill down to the deepest backing object.
- */
- offset = vme->offset;
- object = vme->object.vm_object;
- if (object == NULL)
- continue;
- while (object->backing_object != NULL) {
- object = object->backing_object;
- offset += object->backing_object_offset;
- }
- /*
- * At the moment, vm_maps and objects aren't considered
- * by the MAC system, so only things with backing by a
- * normal object (read: vnodes) are checked.
- */
- if (object->type != OBJT_VNODE)
- continue;
- vp = (struct vnode *)object->handle;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- result = vme->max_protection;
- mac_check_vnode_mmap_downgrade(cred, vp, &result);
- VOP_UNLOCK(vp, 0, td);
- /*
- * Find out what maximum protection we may be allowing
- * now but a policy needs to get removed.
- */
- revokeperms = vme->max_protection & ~result;
- if (!revokeperms)
- continue;
- printf("pid %ld: revoking %s perms from %#lx:%ld "
- "(max %s/cur %s)\n", (long)td->td_proc->p_pid,
- prot2str(revokeperms), (u_long)vme->start,
- (long)(vme->end - vme->start),
- prot2str(vme->max_protection), prot2str(vme->protection));
- vm_map_lock_upgrade(map);
- /*
- * This is the really simple case: if a map has more
- * max_protection than is allowed, but it's not being
- * actually used (that is, the current protection is
- * still allowed), we can just wipe it out and do
- * nothing more.
- */
- if ((vme->protection & revokeperms) == 0) {
- vme->max_protection -= revokeperms;
- } else {
- if (revokeperms & VM_PROT_WRITE) {
- /*
- * In the more complicated case, flush out all
- * pending changes to the object then turn it
- * copy-on-write.
- */
- vm_object_reference(object);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- VM_OBJECT_LOCK(object);
- vm_object_page_clean(object,
- OFF_TO_IDX(offset),
- OFF_TO_IDX(offset + vme->end - vme->start +
- PAGE_MASK),
- OBJPC_SYNC);
- VM_OBJECT_UNLOCK(object);
- VOP_UNLOCK(vp, 0, td);
- vm_object_deallocate(object);
- /*
- * Why bother if there's no read permissions
- * anymore? For the rest, we need to leave
- * the write permissions on for COW, or
- * remove them entirely if configured to.
- */
- if (!mac_mmap_revocation_via_cow) {
- vme->max_protection &= ~VM_PROT_WRITE;
- vme->protection &= ~VM_PROT_WRITE;
- } if ((revokeperms & VM_PROT_READ) == 0)
- vme->eflags |= MAP_ENTRY_COW |
- MAP_ENTRY_NEEDS_COPY;
- }
- if (revokeperms & VM_PROT_EXECUTE) {
- vme->max_protection &= ~VM_PROT_EXECUTE;
- vme->protection &= ~VM_PROT_EXECUTE;
- }
- if (revokeperms & VM_PROT_READ) {
- vme->max_protection = 0;
- vme->protection = 0;
- }
- pmap_protect(map->pmap, vme->start, vme->end,
- vme->protection & ~revokeperms);
- vm_map_simplify_entry(map, vme);
- }
- vm_map_lock_downgrade(map);
- }
- vm_map_unlock_read(map);
-}
-
-/*
- * When the subject's label changes, it may require revocation of privilege
- * to mapped objects. This can't be done on-the-fly later with a unified
- * buffer cache.
- */
-static void
-mac_relabel_cred(struct ucred *cred, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_cred, cred, newlabel);
-}
-
-void
-mac_relabel_vnode(struct ucred *cred, struct vnode *vp, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_vnode, cred, vp, &vp->v_label, newlabel);
-}
-
-void
-mac_create_ifnet(struct ifnet *ifnet)
-{
-
- MAC_PERFORM(create_ifnet, ifnet, &ifnet->if_label);
-}
-
-void
-mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(create_bpfdesc, cred, bpf_d, &bpf_d->bd_label);
-}
-
-void
-mac_create_socket(struct ucred *cred, struct socket *socket)
-{
-
- MAC_PERFORM(create_socket, cred, socket, &socket->so_label);
-}
-
-void
-mac_create_pipe(struct ucred *cred, struct pipe *pipe)
-{
-
- MAC_PERFORM(create_pipe, cred, pipe, pipe->pipe_label);
-}
-
-void
-mac_create_socket_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(create_socket_from_socket, oldsocket, &oldsocket->so_label,
- newsocket, &newsocket->so_label);
-}
-
-static void
-mac_relabel_socket(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_socket, cred, socket, &socket->so_label, newlabel);
-}
-
-static void
-mac_relabel_pipe(struct ucred *cred, struct pipe *pipe, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_pipe, cred, pipe, pipe->pipe_label, newlabel);
-}
-
-void
-mac_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct socket *socket)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(set_socket_peer_from_mbuf, mbuf, label, socket,
- &socket->so_peerlabel);
-}
-
-void
-mac_set_socket_peer_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(set_socket_peer_from_socket, oldsocket,
- &oldsocket->so_label, newsocket, &newsocket->so_peerlabel);
-}
-
-void
-mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram)
-{
- struct label *label;
-
- label = mbuf_to_label(datagram);
-
- MAC_PERFORM(create_datagram_from_ipq, ipq, &ipq->ipq_label,
- datagram, label);
-}
-
-void
-mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment)
-{
- struct label *datagramlabel, *fragmentlabel;
-
- datagramlabel = mbuf_to_label(datagram);
- fragmentlabel = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_fragment, datagram, datagramlabel, fragment,
- fragmentlabel);
-}
-
-void
-mac_create_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_mbuf(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_from_mbuf, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-void
-mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_bpfdesc, bpf_d, &bpf_d->bd_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_linklayer, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_ifnet, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf, struct ifnet *ifnet,
- struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_multicast_encap, oldmbuf, oldmbuflabel,
- ifnet, &ifnet->if_label, newmbuf, newmbuflabel);
-}
-
-void
-mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_netlayer, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-int
-mac_fragment_match(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
- int result;
-
- label = mbuf_to_label(fragment);
-
- result = 1;
- MAC_BOOLEAN(fragment_match, &&, fragment, label, ipq,
- &ipq->ipq_label);
-
- return (result);
-}
-
-void
-mac_update_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(update_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_socket(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_socket, socket, &socket->so_label, mbuf,
- label);
-}
-
-void
-mac_create_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-void
-mac_create_root_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_root_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-int
-mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet)
-{
- int error;
-
- if (!mac_enforce_network)
- return (0);
-
- MAC_CHECK(check_bpfdesc_receive, bpf_d, &bpf_d->bd_label, ifnet,
- &ifnet->if_label);
-
- return (error);
-}
-
-static int
-mac_check_cred_relabel(struct ucred *cred, struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_cred_relabel, cred, newlabel);
-
- return (error);
-}
-
-int
-mac_check_cred_visible(struct ucred *u1, struct ucred *u2)
-{
- int error;
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_cred_visible, u1, u2);
-
- return (error);
-}
-
-int
-mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- M_ASSERTPKTHDR(mbuf);
-
- if (!mac_enforce_network)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_ifnet_transmit, ifnet, &ifnet->if_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_kenv_dump(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_dump, cred);
-
- return (error);
-}
-
-int
-mac_check_kenv_get(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_get, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kenv_set(struct ucred *cred, char *name, char *value)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_set, cred, name, value);
-
- return (error);
-}
-
-int
-mac_check_kenv_unset(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_unset, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kld_load(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_kld_load");
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_load, cred, vp, &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_kld_stat(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_stat, cred);
-
- return (error);
-}
-
-int
-mac_check_kld_unload(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_unload, cred);
-
- return (error);
-}
-
-int
-mac_check_mount_stat(struct ucred *cred, struct mount *mount)
-{
- int error;
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_mount_stat, cred, mount, &mount->mnt_mntlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, unsigned long cmd,
- void *data)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_ioctl, cred, pipe, pipe->pipe_label, cmd, data);
-
- return (error);
-}
-
-int
-mac_check_pipe_poll(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_poll, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_read(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_read, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-static int
-mac_check_pipe_relabel(struct ucred *cred, struct pipe *pipe,
- struct label *newlabel)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_relabel, cred, pipe, pipe->pipe_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_stat(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_stat, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_write(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_write, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_proc_debug(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_debug, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_sched(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_sched, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_signal(struct ucred *cred, struct proc *proc, int signum)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_signal, cred, proc, signum);
-
- return (error);
-}
-
-int
-mac_check_socket_bind(struct ucred *ucred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_bind, ucred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_connect(struct ucred *cred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_connect, cred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_deliver(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_socket_deliver, socket, &socket->so_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_socket_listen(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_listen, cred, socket, &socket->so_label);
- return (error);
-}
-
-int
-mac_check_socket_receive(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_receive, cred, so, &so->so_label);
-
- return (error);
-}
-
-static int
-mac_check_socket_relabel(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_socket_relabel, cred, socket, &socket->so_label,
- newlabel);
-
- return (error);
-}
-
-int
-mac_check_socket_send(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_send, cred, so, &so->so_label);
-
- return (error);
-}
-
-int
-mac_check_socket_visible(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_visible, cred, socket, &socket->so_label);
-
- return (error);
-}
-
-int
-mac_check_sysarch_ioperm(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_sysarch_ioperm, cred);
- return (error);
-}
-
-int
-mac_check_system_acct(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- if (vp != NULL) {
- ASSERT_VOP_LOCKED(vp, "mac_check_system_acct");
- }
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_acct, cred, vp,
- vp != NULL ? &vp->v_label : NULL);
-
- return (error);
-}
-
-int
-mac_check_system_nfsd(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_nfsd, cred);
-
- return (error);
-}
-
-int
-mac_check_system_reboot(struct ucred *cred, int howto)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_reboot, cred, howto);
-
- return (error);
-}
-
-int
-mac_check_system_settime(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_settime, cred);
-
- return (error);
-}
-
-int
-mac_check_system_swapon(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapon");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapon, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_swapoff(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapoff");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapoff, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_sysctl(struct ucred *cred, int *name, u_int namelen,
- void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen)
-{
- int error;
-
- /*
- * XXXMAC: We're very much like to assert the SYSCTL_LOCK here,
- * but since it's not exported from kern_sysctl.c, we can't.
- */
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_sysctl, cred, name, namelen, old, oldlenp,
- inkernel, new, newlen);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_ifnet_label(&ifnet->if_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- struct label intlabel;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_ifnet_label(&intlabel);
- error = mac_internalize_ifnet_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- /*
- * XXX: Note that this is a redundant privilege check, since
- * policies impose this check themselves if required by the
- * policy. Eventually, this should go away.
- */
- error = suser_cred(cred, 0);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_CHECK(check_ifnet_relabel, cred, ifnet, &ifnet->if_label,
- &intlabel);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_PERFORM(relabel_ifnet, cred, ifnet, &ifnet->if_label, &intlabel);
-
- mac_destroy_ifnet_label(&intlabel);
- return (0);
-}
-
-void
-mac_create_devfs_device(struct mount *mp, dev_t dev, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_device, mp, dev, de, &de->de_label);
-}
-
-void
-mac_create_devfs_symlink(struct ucred *cred, struct mount *mp,
- struct devfs_dirent *dd, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_symlink, cred, mp, dd, &dd->de_label, de,
- &de->de_label);
-}
-
-void
-mac_create_devfs_directory(struct mount *mp, char *dirname, int dirnamelen,
- struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_directory, mp, dirname, dirnamelen, de,
- &de->de_label);
-}
-
-int
-mac_setsockopt_label_set(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- struct label intlabel;
- char *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, buffer, mac->m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_socket_label(&intlabel, M_WAITOK);
- error = mac_internalize_socket_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_check_socket_relabel(cred, so, &intlabel);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_relabel_socket(cred, so, &intlabel);
-
- mac_destroy_socket_label(&intlabel);
- return (0);
-}
-
-int
-mac_pipe_label_set(struct ucred *cred, struct pipe *pipe, struct label *label)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- error = mac_check_pipe_relabel(cred, pipe, label);
- if (error)
- return (error);
-
- mac_relabel_pipe(cred, pipe, label);
-
- return (0);
-}
-
-int
-mac_getsockopt_label_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *buffer, *elements;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_label(&so->so_label, elements,
- buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_getsockopt_peerlabel_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *elements, *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_peer_label(&so->so_peerlabel,
- elements, buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * Implementation of VOP_SETLABEL() that relies on extended attributes
- * to store label data. Can be referenced by filesystems supporting
- * extended attributes.
- */
-int
-vop_stdsetlabel_ea(struct vop_setlabel_args *ap)
-{
- struct vnode *vp = ap->a_vp;
- struct label *intlabel = ap->a_label;
- int error;
-
- ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea");
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- error = mac_setlabel_vnode_extattr(ap->a_cred, vp, intlabel);
- if (error)
- return (error);
-
- mac_relabel_vnode(ap->a_cred, vp, intlabel);
-
- return (0);
-}
-
-static int
-vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred)
-{
- int error;
-
- if (vp->v_mount == NULL) {
- /* printf("vn_setlabel: null v_mount\n"); */
- if (vp->v_type != VNON)
- printf("vn_setlabel: null v_mount with non-VNON\n");
- return (EBADF);
- }
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- /*
- * Multi-phase commit. First check the policies to confirm the
- * change is OK. Then commit via the filesystem. Finally,
- * update the actual vnode label. Question: maybe the filesystem
- * should update the vnode at the end as part of VOP_SETLABEL()?
- */
- error = mac_check_vnode_relabel(cred, vp, intlabel);
- if (error)
- return (error);
-
- /*
- * VADMIN provides the opportunity for the filesystem to make
- * decisions about who is and is not able to modify labels
- * and protections on files. This might not be right. We can't
- * assume VOP_SETLABEL() will do it, because we might implement
- * that as part of vop_stdsetlabel_ea().
- */
- error = VOP_ACCESS(vp, VADMIN, cred, curthread);
- if (error)
- return (error);
-
- error = VOP_SETLABEL(vp, intlabel, cred, curthread);
- if (error)
- return (error);
-
- return (0);
-}
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- struct proc *tproc;
- struct ucred *tcred;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- tproc = pfind(uap->pid);
- if (tproc == NULL)
- return (ESRCH);
-
- tcred = NULL; /* Satisfy gcc. */
- error = p_cansee(td, tproc);
- if (error == 0)
- tcred = crhold(tproc->p_ucred);
- PROC_UNLOCK(tproc);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&tcred->cr_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&td->td_ucred->cr_label,
- elements, buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
- struct ucred *newcred, *oldcred;
- struct label intlabel;
- struct proc *p;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(&intlabel);
- error = mac_internalize_cred_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(&intlabel);
- return (error);
- }
-
- newcred = crget();
-
- p = td->td_proc;
- PROC_LOCK(p);
- oldcred = p->p_ucred;
-
- error = mac_check_cred_relabel(oldcred, &intlabel);
- if (error) {
- PROC_UNLOCK(p);
- crfree(newcred);
- goto out;
- }
-
- setsugid(p);
- crcopy(newcred, oldcred);
- mac_relabel_cred(newcred, &intlabel);
- p->p_ucred = newcred;
-
- /*
- * Grab additional reference for use while revoking mmaps, prior
- * to releasing the proc lock and sharing the cred.
- */
- crhold(newcred);
- PROC_UNLOCK(p);
-
- if (mac_enforce_vm) {
- mtx_lock(&Giant);
- mac_cred_mmapped_drop_perms(td, newcred);
- mtx_unlock(&Giant);
- }
-
- crfree(newcred); /* Free revocation reference. */
- crfree(oldcred);
-
-out:
- mac_destroy_cred_label(&intlabel);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
- char *elements, *buffer;
- struct label intlabel;
- struct file *fp;
- struct mac mac;
- struct vnode *vp;
- struct pipe *pipe;
- short label_type;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- label_type = fp->f_type;
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- vp = fp->f_data;
-
- mac_init_vnode_label(&intlabel);
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- mac_copy_vnode_label(&vp->v_label, &intlabel);
- VOP_UNLOCK(vp, 0, td);
-
- break;
- case DTYPE_PIPE:
- pipe = fp->f_data;
-
- mac_init_pipe_label(&intlabel);
-
- PIPE_LOCK(pipe);
- mac_copy_pipe_label(pipe->pipe_label, &intlabel);
- PIPE_UNLOCK(pipe);
- break;
- default:
- error = EINVAL;
- fdrop(fp, td);
- goto out;
- }
- fdrop(fp, td);
-
- switch (label_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- if (error == 0)
- error = mac_externalize_vnode_label(&intlabel,
- elements, buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_vnode_label(&intlabel);
- break;
- case DTYPE_PIPE:
- error = mac_externalize_pipe_label(&intlabel, elements,
- buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_pipe_label(&intlabel);
- break;
- default:
- panic("__mac_get_fd: corrupted label_type");
- }
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
-
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
- struct label intlabel;
- struct pipe *pipe;
- struct file *fp;
- struct mount *mp;
- struct vnode *vp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vp = fp->f_data;
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error != 0) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- error = vn_setlabel(vp, &intlabel, td->td_ucred);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
-
- mac_destroy_vnode_label(&intlabel);
- break;
-
- case DTYPE_PIPE:
- mac_init_pipe_label(&intlabel);
- error = mac_internalize_pipe_label(&intlabel, buffer);
- if (error == 0) {
- pipe = fp->f_data;
- PIPE_LOCK(pipe);
- error = mac_pipe_label_set(td->td_ucred, pipe,
- &intlabel);
- PIPE_UNLOCK(pipe);
- }
-
- mac_destroy_pipe_label(&intlabel);
- break;
-
- default:
- error = EINVAL;
- }
-
- fdrop(fp, td);
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
- struct mac_policy_conf *mpc;
- char target[MAC_MAX_POLICY_NAME];
- int entrycount, error;
-
- error = copyinstr(uap->policy, target, sizeof(target), NULL);
- if (error)
- return (error);
-
- error = ENOSYS;
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- goto out;
- }
- }
-
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) {
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- break;
- }
- }
- mac_policy_list_unbusy();
- }
-out:
- return (error);
-}
-
-SYSINIT(mac, SI_SUB_MAC, SI_ORDER_FIRST, mac_init, NULL);
-SYSINIT(mac_late, SI_SUB_MAC_LATE, SI_ORDER_FIRST, mac_late_init, NULL);
-
-#else /* !MAC */
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
-
- return (ENOSYS);
-}
-
-#endif
diff --git a/sys/security/mac/mac_net.c b/sys/security/mac/mac_net.c
deleted file mode 100644
index fb06edea3012..000000000000
--- a/sys/security/mac/mac_net.c
+++ /dev/null
@@ -1,3975 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * Copyright (c) 2001 Ilmar S. Habibulin
- * Copyright (c) 2001, 2002, 2003 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * This software was developed by Robert Watson and Ilmar Habibulin for the
- * TrustedBSD Project.
- *
- * This software was developed for the FreeBSD Project in part by Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
- * as part of the DARPA CHATS research program.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-/*
- * Developed by the TrustedBSD Project.
- *
- * Framework for extensible kernel access control. Kernel and userland
- * interface to the framework, policy registration and composition.
- */
-
-#include "opt_mac.h"
-#include "opt_devfs.h"
-
-#include <sys/param.h>
-#include <sys/condvar.h>
-#include <sys/extattr.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/mac.h>
-#include <sys/module.h>
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/sysent.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/file.h>
-#include <sys/namei.h>
-#include <sys/socket.h>
-#include <sys/pipe.h>
-#include <sys/socketvar.h>
-#include <sys/sysctl.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-
-#include <sys/mac_policy.h>
-
-#include <fs/devfs/devfs.h>
-
-#include <net/bpfdesc.h>
-#include <net/if.h>
-#include <net/if_var.h>
-
-#include <netinet/in.h>
-#include <netinet/ip_var.h>
-
-#ifdef MAC
-
-/*
- * Declare that the kernel provides MAC support, version 1. This permits
- * modules to refuse to be loaded if the necessary support isn't present,
- * even if it's pre-boot.
- */
-MODULE_VERSION(kernel_mac_support, 1);
-
-SYSCTL_DECL(_security);
-
-SYSCTL_NODE(_security, OID_AUTO, mac, CTLFLAG_RW, 0,
- "TrustedBSD MAC policy controls");
-
-#if MAC_MAX_SLOTS > 32
-#error "MAC_MAX_SLOTS too large"
-#endif
-
-static unsigned int mac_max_slots = MAC_MAX_SLOTS;
-static unsigned int mac_slot_offsets_free = (1 << MAC_MAX_SLOTS) - 1;
-SYSCTL_UINT(_security_mac, OID_AUTO, max_slots, CTLFLAG_RD,
- &mac_max_slots, 0, "");
-
-/*
- * Has the kernel started generating labeled objects yet? All read/write
- * access to this variable is serialized during the boot process. Following
- * the end of serialization, we don't update this flag; no locking.
- */
-static int mac_late = 0;
-
-/*
- * Warn about EA transactions only the first time they happen.
- * Weak coherency, no locking.
- */
-static int ea_warn_once = 0;
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
-/*
- * Flag to indicate whether or not we should allocate label storage for
- * new mbufs. Since most dynamic policies we currently work with don't
- * rely on mbuf labeling, try to avoid paying the cost of mtag allocation
- * unless specifically notified of interest. One result of this is
- * that if a dynamically loaded policy requests mbuf labels, it must
- * be able to deal with a NULL label being returned on any mbufs that
- * were already in flight when the policy was loaded. Since the policy
- * already has to deal with uninitialized labels, this probably won't
- * be a problem. Note: currently no locking. Will this be a problem?
- */
-static int mac_labelmbufs = 0;
-#endif
-
-static int mac_enforce_fs = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_fs, CTLFLAG_RW,
- &mac_enforce_fs, 0, "Enforce MAC policy on file system objects");
-TUNABLE_INT("security.mac.enforce_fs", &mac_enforce_fs);
-
-static int mac_enforce_kld = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_kld, CTLFLAG_RW,
- &mac_enforce_kld, 0, "Enforce MAC policy on kld operations");
-TUNABLE_INT("security.mac.enforce_kld", &mac_enforce_kld);
-
-static int mac_enforce_network = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_network, CTLFLAG_RW,
- &mac_enforce_network, 0, "Enforce MAC policy on network packets");
-TUNABLE_INT("security.mac.enforce_network", &mac_enforce_network);
-
-static int mac_enforce_pipe = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_pipe, CTLFLAG_RW,
- &mac_enforce_pipe, 0, "Enforce MAC policy on pipe operations");
-TUNABLE_INT("security.mac.enforce_pipe", &mac_enforce_pipe);
-
-static int mac_enforce_process = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_process, CTLFLAG_RW,
- &mac_enforce_process, 0, "Enforce MAC policy on inter-process operations");
-TUNABLE_INT("security.mac.enforce_process", &mac_enforce_process);
-
-static int mac_enforce_socket = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_socket, CTLFLAG_RW,
- &mac_enforce_socket, 0, "Enforce MAC policy on socket operations");
-TUNABLE_INT("security.mac.enforce_socket", &mac_enforce_socket);
-
-static int mac_enforce_system = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_system, CTLFLAG_RW,
- &mac_enforce_system, 0, "Enforce MAC policy on system operations");
-TUNABLE_INT("security.mac.enforce_system", &mac_enforce_system);
-
-static int mac_enforce_vm = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_vm, CTLFLAG_RW,
- &mac_enforce_vm, 0, "Enforce MAC policy on vm operations");
-TUNABLE_INT("security.mac.enforce_vm", &mac_enforce_vm);
-
-static int mac_mmap_revocation = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation, CTLFLAG_RW,
- &mac_mmap_revocation, 0, "Revoke mmap access to files on subject "
- "relabel");
-static int mac_mmap_revocation_via_cow = 0;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation_via_cow, CTLFLAG_RW,
- &mac_mmap_revocation_via_cow, 0, "Revoke mmap access to files via "
- "copy-on-write semantics, or by removing all write access");
-
-#ifdef MAC_DEBUG
-SYSCTL_NODE(_security_mac, OID_AUTO, debug, CTLFLAG_RW, 0,
- "TrustedBSD MAC debug info");
-
-static int mac_debug_label_fallback = 0;
-SYSCTL_INT(_security_mac_debug, OID_AUTO, label_fallback, CTLFLAG_RW,
- &mac_debug_label_fallback, 0, "Filesystems should fall back to fs label"
- "when label is corrupted.");
-TUNABLE_INT("security.mac.debug_label_fallback",
- &mac_debug_label_fallback);
-
-SYSCTL_NODE(_security_mac_debug, OID_AUTO, counters, CTLFLAG_RW, 0,
- "TrustedBSD MAC object counters");
-
-static unsigned int nmacmbufs, nmaccreds, nmacifnets, nmacbpfdescs,
- nmacsockets, nmacmounts, nmactemp, nmacvnodes, nmacdevfsdirents,
- nmacipqs, nmacpipes, nmacprocs;
-
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mbufs, CTLFLAG_RD,
- &nmacmbufs, 0, "number of mbufs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, creds, CTLFLAG_RD,
- &nmaccreds, 0, "number of ucreds in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ifnets, CTLFLAG_RD,
- &nmacifnets, 0, "number of ifnets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ipqs, CTLFLAG_RD,
- &nmacipqs, 0, "number of ipqs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, bpfdescs, CTLFLAG_RD,
- &nmacbpfdescs, 0, "number of bpfdescs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, sockets, CTLFLAG_RD,
- &nmacsockets, 0, "number of sockets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, pipes, CTLFLAG_RD,
- &nmacpipes, 0, "number of pipes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, procs, CTLFLAG_RD,
- &nmacprocs, 0, "number of procs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mounts, CTLFLAG_RD,
- &nmacmounts, 0, "number of mounts in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, temp, CTLFLAG_RD,
- &nmactemp, 0, "number of temporary labels in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, vnodes, CTLFLAG_RD,
- &nmacvnodes, 0, "number of vnodes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, devfsdirents, CTLFLAG_RD,
- &nmacdevfsdirents, 0, "number of devfs dirents inuse");
-#endif
-
-static int error_select(int error1, int error2);
-static int mac_policy_register(struct mac_policy_conf *mpc);
-static int mac_policy_unregister(struct mac_policy_conf *mpc);
-
-static void mac_check_vnode_mmap_downgrade(struct ucred *cred,
- struct vnode *vp, int *prot);
-static void mac_cred_mmapped_drop_perms_recurse(struct thread *td,
- struct ucred *cred, struct vm_map *map);
-
-static void mac_destroy_socket_label(struct label *label);
-
-static int mac_setlabel_vnode_extattr(struct ucred *cred,
- struct vnode *vp, struct label *intlabel);
-
-MALLOC_DEFINE(M_MACPIPELABEL, "macpipelabel", "MAC labels for pipes");
-MALLOC_DEFINE(M_MACTEMP, "mactemp", "MAC temporary label storage");
-
-/*
- * mac_static_policy_list holds a list of policy modules that are not
- * loaded while the system is "live", and cannot be unloaded. These
- * policies can be invoked without holding the busy count.
- *
- * mac_policy_list stores the list of dynamic policies. A busy count is
- * maintained for the list, stored in mac_policy_busy. The busy count
- * is protected by mac_policy_mtx; the list may be modified only
- * while the busy count is 0, requiring that the lock be held to
- * prevent new references to the list from being acquired. For almost
- * all operations, incrementing the busy count is sufficient to
- * guarantee consistency, as the list cannot be modified while the
- * busy count is elevated. For a few special operations involving a
- * change to the list of active policies, the mtx itself must be held.
- * A condition variable, mac_policy_cv, is used to signal potential
- * exclusive consumers that they should try to acquire the lock if a
- * first attempt at exclusive access fails.
- */
-static struct mtx mac_policy_mtx;
-static struct cv mac_policy_cv;
-static int mac_policy_count;
-static LIST_HEAD(, mac_policy_conf) mac_policy_list;
-static LIST_HEAD(, mac_policy_conf) mac_static_policy_list;
-
-/*
- * We manually invoke WITNESS_WARN() to allow Witness to generate
- * warnings even if we don't end up ever triggering the wait at
- * run-time. The consumer of the exclusive interface must not hold
- * any locks (other than potentially Giant) since we may sleep for
- * long (potentially indefinite) periods of time waiting for the
- * framework to become quiescent so that a policy list change may
- * be made.
- */
-static __inline void
-mac_policy_grab_exclusive(void)
-{
- WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
- "mac_policy_grab_exclusive() at %s:%d", __FILE__, __LINE__);
- mtx_lock(&mac_policy_mtx);
- while (mac_policy_count != 0)
- cv_wait(&mac_policy_cv, &mac_policy_mtx);
-}
-
-static __inline void
-mac_policy_assert_exclusive(void)
-{
- mtx_assert(&mac_policy_mtx, MA_OWNED);
- KASSERT(mac_policy_count == 0,
- ("mac_policy_assert_exclusive(): not exclusive"));
-}
-
-static __inline void
-mac_policy_release_exclusive(void)
-{
-
- KASSERT(mac_policy_count == 0,
- ("mac_policy_release_exclusive(): not exclusive"));
- mtx_unlock(&mac_policy_mtx);
- cv_signal(&mac_policy_cv);
-}
-
-static __inline void
-mac_policy_list_busy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count++;
- mtx_unlock(&mac_policy_mtx);
-}
-
-static __inline int
-mac_policy_list_conditional_busy(void)
-{
- int ret;
-
- mtx_lock(&mac_policy_mtx);
- if (!LIST_EMPTY(&mac_policy_list)) {
- mac_policy_count++;
- ret = 1;
- } else
- ret = 0;
- mtx_unlock(&mac_policy_mtx);
- return (ret);
-}
-
-static __inline void
-mac_policy_list_unbusy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count--;
- KASSERT(mac_policy_count >= 0, ("MAC_POLICY_LIST_LOCK"));
- if (mac_policy_count == 0)
- cv_signal(&mac_policy_cv);
- mtx_unlock(&mac_policy_mtx);
-}
-
-/*
- * MAC_CHECK performs the designated check by walking the policy
- * module list and checking with each as to how it feels about the
- * request. Note that it returns its value via 'error' in the scope
- * of the caller.
- */
-#define MAC_CHECK(check, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- error = 0; \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * MAC_BOOLEAN performs the designated boolean composition by walking
- * the module list, invoking each instance of the operation, and
- * combining the results using the passed C operator. Note that it
- * returns its value via 'result' in the scope of the caller, which
- * should be initialized by the caller in a meaningful way to get
- * a meaningful result.
- */
-#define MAC_BOOLEAN(operation, composition, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation \
- (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-#define MAC_EXTERNALIZE(type, label, elementlist, outbuf, \
- outbuflen) do { \
- char *curptr, *curptr_start, *element_name, *element_temp; \
- size_t left, left_start, len; \
- int claimed, first, first_start, ignorenotfound; \
- \
- error = 0; \
- element_temp = elementlist; \
- curptr = outbuf; \
- curptr[0] = '\0'; \
- left = outbuflen; \
- first = 1; \
- while ((element_name = strsep(&element_temp, ",")) != NULL) { \
- curptr_start = curptr; \
- left_start = left; \
- first_start = first; \
- if (element_name[0] == '?') { \
- element_name++; \
- ignorenotfound = 1; \
- } else \
- ignorenotfound = 0; \
- claimed = 0; \
- if (first) { \
- len = snprintf(curptr, left, "%s/", \
- element_name); \
- first = 0; \
- } else \
- len = snprintf(curptr, left, ",%s/", \
- element_name); \
- if (len >= left) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- \
- MAC_CHECK(externalize_ ## type, label, element_name, \
- curptr, left, &len, &claimed); \
- if (error) \
- break; \
- if (claimed == 1) { \
- if (len >= outbuflen) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- } else if (claimed == 0 && ignorenotfound) { \
- /* \
- * Revert addition of the label element \
- * name. \
- */ \
- curptr = curptr_start; \
- *curptr = '\0'; \
- left = left_start; \
- first = first_start; \
- } else { \
- error = EINVAL; /* XXXMAC: ENOLABEL */ \
- break; \
- } \
- } \
-} while (0)
-
-#define MAC_INTERNALIZE(type, label, instring) do { \
- char *element, *element_name, *element_data; \
- int claimed; \
- \
- error = 0; \
- element = instring; \
- while ((element_name = strsep(&element, ",")) != NULL) { \
- element_data = element_name; \
- element_name = strsep(&element_data, "/"); \
- if (element_data == NULL) { \
- error = EINVAL; \
- break; \
- } \
- claimed = 0; \
- MAC_CHECK(internalize_ ## type, label, element_name, \
- element_data, &claimed); \
- if (error) \
- break; \
- if (claimed != 1) { \
- /* XXXMAC: Another error here? */ \
- error = EINVAL; \
- break; \
- } \
- } \
-} while (0)
-
-/*
- * MAC_PERFORM performs the designated operation by walking the policy
- * module list and invoking that operation for each policy.
- */
-#define MAC_PERFORM(operation, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * Initialize the MAC subsystem, including appropriate SMP locks.
- */
-static void
-mac_init(void)
-{
-
- LIST_INIT(&mac_static_policy_list);
- LIST_INIT(&mac_policy_list);
-
- mtx_init(&mac_policy_mtx, "mac_policy_mtx", NULL, MTX_DEF);
- cv_init(&mac_policy_cv, "mac_policy_cv");
-}
-
-/*
- * For the purposes of modules that want to know if they were loaded
- * "early", set the mac_late flag once we've processed modules either
- * linked into the kernel, or loaded before the kernel startup.
- */
-static void
-mac_late_init(void)
-{
-
- mac_late = 1;
-}
-
-/*
- * After the policy list has changed, walk the list to update any global
- * flags.
- */
-static void
-mac_policy_updateflags(void)
-{
- struct mac_policy_conf *tmpc;
-#ifndef MAC_ALWAYS_LABEL_MBUF
- int labelmbufs;
-#endif
-
- mac_policy_assert_exclusive();
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- labelmbufs = 0;
-#endif
-
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- mac_labelmbufs = (labelmbufs != 0);
-#endif
-}
-
-/*
- * Allow MAC policy modules to register during boot, etc.
- */
-int
-mac_policy_modevent(module_t mod, int type, void *data)
-{
- struct mac_policy_conf *mpc;
- int error;
-
- error = 0;
- mpc = (struct mac_policy_conf *) data;
-
- switch (type) {
- case MOD_LOAD:
- if (mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_NOTLATE &&
- mac_late) {
- printf("mac_policy_modevent: can't load %s policy "
- "after booting\n", mpc->mpc_name);
- error = EBUSY;
- break;
- }
- error = mac_policy_register(mpc);
- break;
- case MOD_UNLOAD:
- /* Don't unregister the module if it was never registered. */
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED)
- != 0)
- error = mac_policy_unregister(mpc);
- else
- error = 0;
- break;
- default:
- break;
- }
-
- return (error);
-}
-
-static int
-mac_policy_register(struct mac_policy_conf *mpc)
-{
- struct mac_policy_conf *tmpc;
- int error, slot, static_entry;
-
- error = 0;
-
- /*
- * We don't technically need exclusive access while !mac_late,
- * but hold it for assertion consistency.
- */
- mac_policy_grab_exclusive();
-
- /*
- * If the module can potentially be unloaded, or we're loading
- * late, we have to stick it in the non-static list and pay
- * an extra performance overhead. Otherwise, we can pay a
- * light locking cost and stick it in the static list.
- */
- static_entry = (!mac_late &&
- !(mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK));
-
- if (static_entry) {
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- } else {
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- }
- if (mpc->mpc_field_off != NULL) {
- slot = ffs(mac_slot_offsets_free);
- if (slot == 0) {
- error = ENOMEM;
- goto out;
- }
- slot--;
- mac_slot_offsets_free &= ~(1 << slot);
- *mpc->mpc_field_off = slot;
- }
- mpc->mpc_runtime_flags |= MPC_RUNTIME_FLAG_REGISTERED;
-
- /*
- * If we're loading a MAC module after the framework has
- * initialized, it has to go into the dynamic list. If
- * we're loading it before we've finished initializing,
- * it can go into the static list with weaker locker
- * requirements.
- */
- if (static_entry)
- LIST_INSERT_HEAD(&mac_static_policy_list, mpc, mpc_list);
- else
- LIST_INSERT_HEAD(&mac_policy_list, mpc, mpc_list);
-
- /* Per-policy initialization. */
- if (mpc->mpc_ops->mpo_init != NULL)
- (*(mpc->mpc_ops->mpo_init))(mpc);
- mac_policy_updateflags();
-
- printf("Security policy loaded: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
-out:
- mac_policy_release_exclusive();
- return (error);
-}
-
-static int
-mac_policy_unregister(struct mac_policy_conf *mpc)
-{
-
- /*
- * If we fail the load, we may get a request to unload. Check
- * to see if we did the run-time registration, and if not,
- * silently succeed.
- */
- mac_policy_grab_exclusive();
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED) == 0) {
- mac_policy_release_exclusive();
- return (0);
- }
-#if 0
- /*
- * Don't allow unloading modules with private data.
- */
- if (mpc->mpc_field_off != NULL) {
- MAC_POLICY_LIST_UNLOCK();
- return (EBUSY);
- }
-#endif
- /*
- * Only allow the unload to proceed if the module is unloadable
- * by its own definition.
- */
- if ((mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK) == 0) {
- mac_policy_release_exclusive();
- return (EBUSY);
- }
- if (mpc->mpc_ops->mpo_destroy != NULL)
- (*(mpc->mpc_ops->mpo_destroy))(mpc);
-
- LIST_REMOVE(mpc, mpc_list);
- mpc->mpc_runtime_flags &= ~MPC_RUNTIME_FLAG_REGISTERED;
- mac_policy_updateflags();
-
- mac_policy_release_exclusive();
-
- printf("Security policy unload: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
- return (0);
-}
-
-/*
- * Define an error value precedence, and given two arguments, selects the
- * value with the higher precedence.
- */
-static int
-error_select(int error1, int error2)
-{
-
- /* Certain decision-making errors take top priority. */
- if (error1 == EDEADLK || error2 == EDEADLK)
- return (EDEADLK);
-
- /* Invalid arguments should be reported where possible. */
- if (error1 == EINVAL || error2 == EINVAL)
- return (EINVAL);
-
- /* Precedence goes to "visibility", with both process and file. */
- if (error1 == ESRCH || error2 == ESRCH)
- return (ESRCH);
-
- if (error1 == ENOENT || error2 == ENOENT)
- return (ENOENT);
-
- /* Precedence goes to DAC/MAC protections. */
- if (error1 == EACCES || error2 == EACCES)
- return (EACCES);
-
- /* Precedence goes to privilege. */
- if (error1 == EPERM || error2 == EPERM)
- return (EPERM);
-
- /* Precedence goes to error over success; otherwise, arbitrary. */
- if (error1 != 0)
- return (error1);
- return (error2);
-}
-
-static struct label *
-mbuf_to_label(struct mbuf *mbuf)
-{
- struct m_tag *tag;
- struct label *label;
-
- tag = m_tag_find(mbuf, PACKET_TAG_MACLABEL, NULL);
- label = (struct label *)(tag+1);
-
- return (label);
-}
-
-static void
-mac_init_label(struct label *label)
-{
-
- bzero(label, sizeof(*label));
- label->l_flags = MAC_FLAG_INITIALIZED;
-}
-
-static void
-mac_destroy_label(struct label *label)
-{
-
- KASSERT(label->l_flags & MAC_FLAG_INITIALIZED,
- ("destroying uninitialized label"));
-
- bzero(label, sizeof(*label));
- /* implicit: label->l_flags &= ~MAC_FLAG_INITIALIZED; */
-}
-
-void
-mac_init_bpfdesc(struct bpf_d *bpf_d)
-{
-
- mac_init_label(&bpf_d->bd_label);
- MAC_PERFORM(init_bpfdesc_label, &bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_init_cred_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_cred_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_init_cred(struct ucred *cred)
-{
-
- mac_init_cred_label(&cred->cr_label);
-}
-
-void
-mac_init_devfsdirent(struct devfs_dirent *de)
-{
-
- mac_init_label(&de->de_label);
- MAC_PERFORM(init_devfsdirent_label, &de->de_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_init_ifnet_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_ifnet_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_init_ifnet(struct ifnet *ifp)
-{
-
- mac_init_ifnet_label(&ifp->if_label);
-}
-
-int
-mac_init_ipq(struct ipq *ipq, int flag)
-{
- int error;
-
- mac_init_label(&ipq->ipq_label);
-
- MAC_CHECK(init_ipq_label, &ipq->ipq_label, flag);
- if (error) {
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacipqs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf_tag(struct m_tag *tag, int flag)
-{
- struct label *label;
- int error;
-
- label = (struct label *) (tag + 1);
- mac_init_label(label);
-
- MAC_CHECK(init_mbuf_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacmbufs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf(struct mbuf *m, int flag)
-{
- struct m_tag *tag;
- int error;
-
- M_ASSERTPKTHDR(m);
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- /*
- * Don't reserve space for labels on mbufs unless we have a policy
- * that uses the labels.
- */
- if (mac_labelmbufs) {
-#endif
- tag = m_tag_get(PACKET_TAG_MACLABEL, sizeof(struct label),
- flag);
- if (tag == NULL)
- return (ENOMEM);
- error = mac_init_mbuf_tag(tag, flag);
- if (error) {
- m_tag_free(tag);
- return (error);
- }
- m_tag_prepend(m, tag);
-#ifndef MAC_ALWAYS_LABEL_MBUF
- }
-#endif
- return (0);
-}
-
-void
-mac_init_mount(struct mount *mp)
-{
-
- mac_init_label(&mp->mnt_mntlabel);
- mac_init_label(&mp->mnt_fslabel);
- MAC_PERFORM(init_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(init_mount_fs_label, &mp->mnt_fslabel);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_init_pipe_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_pipe_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_init_pipe(struct pipe *pipe)
-{
- struct label *label;
-
- label = malloc(sizeof(struct label), M_MACPIPELABEL, M_ZERO|M_WAITOK);
- pipe->pipe_label = label;
- pipe->pipe_peer->pipe_label = label;
- mac_init_pipe_label(label);
-}
-
-void
-mac_init_proc(struct proc *p)
-{
-
- mac_init_label(&p->p_label);
- MAC_PERFORM(init_proc_label, &p->p_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacprocs, 1);
-#endif
-}
-
-static int
-mac_init_socket_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacsockets, 1);
-#endif
-
- return (error);
-}
-
-static int
-mac_init_socket_peer_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_peer_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
- return (error);
-}
-
-int
-mac_init_socket(struct socket *socket, int flag)
-{
- int error;
-
- error = mac_init_socket_label(&socket->so_label, flag);
- if (error)
- return (error);
-
- error = mac_init_socket_peer_label(&socket->so_peerlabel, flag);
- if (error)
- mac_destroy_socket_label(&socket->so_label);
-
- return (error);
-}
-
-void
-mac_init_vnode_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_vnode_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_init_vnode(struct vnode *vp)
-{
-
- mac_init_vnode_label(&vp->v_label);
-}
-
-void
-mac_destroy_bpfdesc(struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(destroy_bpfdesc_label, &bpf_d->bd_label);
- mac_destroy_label(&bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_destroy_cred_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_cred_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_destroy_cred(struct ucred *cred)
-{
-
- mac_destroy_cred_label(&cred->cr_label);
-}
-
-void
-mac_destroy_devfsdirent(struct devfs_dirent *de)
-{
-
- MAC_PERFORM(destroy_devfsdirent_label, &de->de_label);
- mac_destroy_label(&de->de_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_destroy_ifnet_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_ifnet_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_destroy_ifnet(struct ifnet *ifp)
-{
-
- mac_destroy_ifnet_label(&ifp->if_label);
-}
-
-void
-mac_destroy_ipq(struct ipq *ipq)
-{
-
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacipqs, 1);
-#endif
-}
-
-void
-mac_destroy_mbuf_tag(struct m_tag *tag)
-{
- struct label *label;
-
- label = (struct label *)(tag+1);
-
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmbufs, 1);
-#endif
-}
-
-void
-mac_destroy_mount(struct mount *mp)
-{
-
- MAC_PERFORM(destroy_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(destroy_mount_fs_label, &mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_mntlabel);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_destroy_pipe_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_pipe_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_destroy_pipe(struct pipe *pipe)
-{
-
- mac_destroy_pipe_label(pipe->pipe_label);
- free(pipe->pipe_label, M_MACPIPELABEL);
-}
-
-void
-mac_destroy_proc(struct proc *p)
-{
-
- MAC_PERFORM(destroy_proc_label, &p->p_label);
- mac_destroy_label(&p->p_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacprocs, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacsockets, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_peer_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_peer_label, label);
- mac_destroy_label(label);
-}
-
-void
-mac_destroy_socket(struct socket *socket)
-{
-
- mac_destroy_socket_label(&socket->so_label);
- mac_destroy_socket_peer_label(&socket->so_peerlabel);
-}
-
-void
-mac_destroy_vnode_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_vnode_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_destroy_vnode(struct vnode *vp)
-{
-
- mac_destroy_vnode_label(&vp->v_label);
-}
-
-void
-mac_copy_mbuf_tag(struct m_tag *src, struct m_tag *dest)
-{
- struct label *src_label, *dest_label;
-
- src_label = (struct label *)(src+1);
- dest_label = (struct label *)(dest+1);
-
- /*
- * mac_init_mbuf_tag() is called on the target tag in
- * m_tag_copy(), so we don't need to call it here.
- */
- MAC_PERFORM(copy_mbuf_label, src_label, dest_label);
-}
-
-static void
-mac_copy_pipe_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_pipe_label, src, dest);
-}
-
-void
-mac_copy_vnode_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_vnode_label, src, dest);
-}
-
-static int
-mac_check_structmac_consistent(struct mac *mac)
-{
-
- if (mac->m_buflen > MAC_MAX_LABEL_BUF_LEN)
- return (EINVAL);
-
- return (0);
-}
-
-static int
-mac_externalize_cred_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(cred_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_ifnet_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(ifnet_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_pipe_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(pipe_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_peer_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_peer_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_vnode_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(vnode_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_internalize_cred_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(cred_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_ifnet_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(ifnet_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_pipe_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(pipe_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_socket_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(socket_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_vnode_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(vnode_label, label, string);
-
- return (error);
-}
-
-/*
- * Initialize MAC label for the first kernel process, from which other
- * kernel processes and threads are spawned.
- */
-void
-mac_create_proc0(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc0, cred);
-}
-
-/*
- * Initialize MAC label for the first userland process, from which other
- * userland processes and threads are spawned.
- */
-void
-mac_create_proc1(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc1, cred);
-}
-
-void
-mac_thread_userret(struct thread *td)
-{
-
- MAC_PERFORM(thread_userret, td);
-}
-
-/*
- * When a new process is created, its label must be initialized. Generally,
- * this involves inheritence from the parent process, modulo possible
- * deltas. This function allows that processing to take place.
- */
-void
-mac_create_cred(struct ucred *parent_cred, struct ucred *child_cred)
-{
-
- MAC_PERFORM(create_cred, parent_cred, child_cred);
-}
-
-void
-mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(update_devfsdirent, mp, de, &de->de_label, vp,
- &vp->v_label);
-}
-
-void
-mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_devfs, mp, &mp->mnt_fslabel, de,
- &de->de_label, vp, &vp->v_label);
-}
-
-int
-mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_associate_vnode_extattr");
-
- MAC_CHECK(associate_vnode_extattr, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-
- return (error);
-}
-
-void
-mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_singlelabel, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-}
-
-int
-mac_create_vnode_extattr(struct ucred *cred, struct mount *mp,
- struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_create_vnode_extattr");
- ASSERT_VOP_LOCKED(vp, "mac_create_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(create_vnode_extattr, cred, mp, &mp->mnt_fslabel,
- dvp, &dvp->v_label, vp, &vp->v_label, cnp);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-static int
-mac_setlabel_vnode_extattr(struct ucred *cred, struct vnode *vp,
- struct label *intlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_setlabel_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(setlabel_vnode_extattr, cred, vp, &vp->v_label, intlabel);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-int
-mac_execve_enter(struct image_params *imgp, struct mac *mac_p,
- struct label *execlabelstorage)
-{
- struct mac mac;
- char *buffer;
- int error;
-
- if (mac_p == NULL)
- return (0);
-
- error = copyin(mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(execlabelstorage);
- error = mac_internalize_cred_label(execlabelstorage, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(execlabelstorage);
- return (error);
- }
- imgp->execlabel = execlabelstorage;
- return (0);
-}
-
-void
-mac_execve_exit(struct image_params *imgp)
-{
- if (imgp->execlabel != NULL)
- mac_destroy_cred_label(imgp->execlabel);
-}
-
-void
-mac_execve_transition(struct ucred *old, struct ucred *new, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return;
-
- MAC_PERFORM(execve_transition, old, new, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-}
-
-int
-mac_execve_will_transition(struct ucred *old, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
- int result;
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_will_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- result = 0;
- MAC_BOOLEAN(execve_will_transition, ||, old, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-
- return (result);
-}
-
-int
-mac_check_vnode_access(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_access");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_access, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chroot");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chroot, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_create(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp, struct vattr *vap)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_create");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_create, cred, dvp, &dvp->v_label, cnp, vap);
- return (error);
-}
-
-int
-mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp, struct vnode *vp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_delete");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_delete");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_delete, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
- acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_deleteacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_deleteacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_exec(struct ucred *cred, struct vnode *vp,
- struct image_params *imgp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_exec");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_exec, cred, vp, &vp->v_label, imgp,
- imgp->execlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp, acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_link(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_link");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_link");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_link, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_lookup");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_lookup, cred, dvp, &dvp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mmap, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-void
-mac_check_vnode_mmap_downgrade(struct ucred *cred, struct vnode *vp, int *prot)
-{
- int result = *prot;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap_downgrade");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return;
-
- MAC_PERFORM(check_vnode_mmap_downgrade, cred, vp, &vp->v_label,
- &result);
-
- *prot = result;
-}
-
-int
-mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mprotect");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mprotect, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-int
-mac_check_vnode_open(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_open");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_open, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_poll");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_poll, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_read");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_read, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_readdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_readdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_readlink");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readlink, cred, vp, &vp->v_label);
- return (error);
-}
-
-static int
-mac_check_vnode_relabel(struct ucred *cred, struct vnode *vp,
- struct label *newlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_relabel");
-
- MAC_CHECK(check_vnode_relabel, cred, vp, &vp->v_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_from");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_from");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_from, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, int samedir, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_to");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_to");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_to, cred, dvp, &dvp->v_label, vp,
- vp != NULL ? &vp->v_label : NULL, samedir, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_revoke");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_revoke, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type,
- struct acl *acl)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setacl, cred, vp, &vp->v_label, type, acl);
- return (error);
-}
-
-int
-mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp, u_long flags)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setflags");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setflags, cred, vp, &vp->v_label, flags);
- return (error);
-}
-
-int
-mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp, mode_t mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setmode");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setmode, cred, vp, &vp->v_label, mode);
- return (error);
-}
-
-int
-mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp, uid_t uid,
- gid_t gid)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setowner");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setowner, cred, vp, &vp->v_label, uid, gid);
- return (error);
-}
-
-int
-mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
- struct timespec atime, struct timespec mtime)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setutimes");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setutimes, cred, vp, &vp->v_label, atime,
- mtime);
- return (error);
-}
-
-int
-mac_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_stat");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_stat, active_cred, file_cred, vp,
- &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_write(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_write");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_write, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-/*
- * When relabeling a process, call out to the policies for the maximum
- * permission allowed for each object type we know about in its
- * memory space, and revoke access (in the least surprising ways we
- * know) when necessary. The process lock is not held here.
- */
-void
-mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred)
-{
-
- /* XXX freeze all other threads */
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- &td->td_proc->p_vmspace->vm_map);
- /* XXX allow other threads to continue */
-}
-
-static __inline const char *
-prot2str(vm_prot_t prot)
-{
-
- switch (prot & VM_PROT_ALL) {
- case VM_PROT_READ:
- return ("r--");
- case VM_PROT_READ | VM_PROT_WRITE:
- return ("rw-");
- case VM_PROT_READ | VM_PROT_EXECUTE:
- return ("r-x");
- case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("rwx");
- case VM_PROT_WRITE:
- return ("-w-");
- case VM_PROT_EXECUTE:
- return ("--x");
- case VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("-wx");
- default:
- return ("---");
- }
-}
-
-static void
-mac_cred_mmapped_drop_perms_recurse(struct thread *td, struct ucred *cred,
- struct vm_map *map)
-{
- struct vm_map_entry *vme;
- int result;
- vm_prot_t revokeperms;
- vm_object_t object;
- vm_ooffset_t offset;
- struct vnode *vp;
-
- if (!mac_mmap_revocation)
- return;
-
- vm_map_lock_read(map);
- for (vme = map->header.next; vme != &map->header; vme = vme->next) {
- if (vme->eflags & MAP_ENTRY_IS_SUB_MAP) {
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- vme->object.sub_map);
- continue;
- }
- /*
- * Skip over entries that obviously are not shared.
- */
- if (vme->eflags & (MAP_ENTRY_COW | MAP_ENTRY_NOSYNC) ||
- !vme->max_protection)
- continue;
- /*
- * Drill down to the deepest backing object.
- */
- offset = vme->offset;
- object = vme->object.vm_object;
- if (object == NULL)
- continue;
- while (object->backing_object != NULL) {
- object = object->backing_object;
- offset += object->backing_object_offset;
- }
- /*
- * At the moment, vm_maps and objects aren't considered
- * by the MAC system, so only things with backing by a
- * normal object (read: vnodes) are checked.
- */
- if (object->type != OBJT_VNODE)
- continue;
- vp = (struct vnode *)object->handle;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- result = vme->max_protection;
- mac_check_vnode_mmap_downgrade(cred, vp, &result);
- VOP_UNLOCK(vp, 0, td);
- /*
- * Find out what maximum protection we may be allowing
- * now but a policy needs to get removed.
- */
- revokeperms = vme->max_protection & ~result;
- if (!revokeperms)
- continue;
- printf("pid %ld: revoking %s perms from %#lx:%ld "
- "(max %s/cur %s)\n", (long)td->td_proc->p_pid,
- prot2str(revokeperms), (u_long)vme->start,
- (long)(vme->end - vme->start),
- prot2str(vme->max_protection), prot2str(vme->protection));
- vm_map_lock_upgrade(map);
- /*
- * This is the really simple case: if a map has more
- * max_protection than is allowed, but it's not being
- * actually used (that is, the current protection is
- * still allowed), we can just wipe it out and do
- * nothing more.
- */
- if ((vme->protection & revokeperms) == 0) {
- vme->max_protection -= revokeperms;
- } else {
- if (revokeperms & VM_PROT_WRITE) {
- /*
- * In the more complicated case, flush out all
- * pending changes to the object then turn it
- * copy-on-write.
- */
- vm_object_reference(object);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- VM_OBJECT_LOCK(object);
- vm_object_page_clean(object,
- OFF_TO_IDX(offset),
- OFF_TO_IDX(offset + vme->end - vme->start +
- PAGE_MASK),
- OBJPC_SYNC);
- VM_OBJECT_UNLOCK(object);
- VOP_UNLOCK(vp, 0, td);
- vm_object_deallocate(object);
- /*
- * Why bother if there's no read permissions
- * anymore? For the rest, we need to leave
- * the write permissions on for COW, or
- * remove them entirely if configured to.
- */
- if (!mac_mmap_revocation_via_cow) {
- vme->max_protection &= ~VM_PROT_WRITE;
- vme->protection &= ~VM_PROT_WRITE;
- } if ((revokeperms & VM_PROT_READ) == 0)
- vme->eflags |= MAP_ENTRY_COW |
- MAP_ENTRY_NEEDS_COPY;
- }
- if (revokeperms & VM_PROT_EXECUTE) {
- vme->max_protection &= ~VM_PROT_EXECUTE;
- vme->protection &= ~VM_PROT_EXECUTE;
- }
- if (revokeperms & VM_PROT_READ) {
- vme->max_protection = 0;
- vme->protection = 0;
- }
- pmap_protect(map->pmap, vme->start, vme->end,
- vme->protection & ~revokeperms);
- vm_map_simplify_entry(map, vme);
- }
- vm_map_lock_downgrade(map);
- }
- vm_map_unlock_read(map);
-}
-
-/*
- * When the subject's label changes, it may require revocation of privilege
- * to mapped objects. This can't be done on-the-fly later with a unified
- * buffer cache.
- */
-static void
-mac_relabel_cred(struct ucred *cred, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_cred, cred, newlabel);
-}
-
-void
-mac_relabel_vnode(struct ucred *cred, struct vnode *vp, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_vnode, cred, vp, &vp->v_label, newlabel);
-}
-
-void
-mac_create_ifnet(struct ifnet *ifnet)
-{
-
- MAC_PERFORM(create_ifnet, ifnet, &ifnet->if_label);
-}
-
-void
-mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(create_bpfdesc, cred, bpf_d, &bpf_d->bd_label);
-}
-
-void
-mac_create_socket(struct ucred *cred, struct socket *socket)
-{
-
- MAC_PERFORM(create_socket, cred, socket, &socket->so_label);
-}
-
-void
-mac_create_pipe(struct ucred *cred, struct pipe *pipe)
-{
-
- MAC_PERFORM(create_pipe, cred, pipe, pipe->pipe_label);
-}
-
-void
-mac_create_socket_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(create_socket_from_socket, oldsocket, &oldsocket->so_label,
- newsocket, &newsocket->so_label);
-}
-
-static void
-mac_relabel_socket(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_socket, cred, socket, &socket->so_label, newlabel);
-}
-
-static void
-mac_relabel_pipe(struct ucred *cred, struct pipe *pipe, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_pipe, cred, pipe, pipe->pipe_label, newlabel);
-}
-
-void
-mac_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct socket *socket)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(set_socket_peer_from_mbuf, mbuf, label, socket,
- &socket->so_peerlabel);
-}
-
-void
-mac_set_socket_peer_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(set_socket_peer_from_socket, oldsocket,
- &oldsocket->so_label, newsocket, &newsocket->so_peerlabel);
-}
-
-void
-mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram)
-{
- struct label *label;
-
- label = mbuf_to_label(datagram);
-
- MAC_PERFORM(create_datagram_from_ipq, ipq, &ipq->ipq_label,
- datagram, label);
-}
-
-void
-mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment)
-{
- struct label *datagramlabel, *fragmentlabel;
-
- datagramlabel = mbuf_to_label(datagram);
- fragmentlabel = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_fragment, datagram, datagramlabel, fragment,
- fragmentlabel);
-}
-
-void
-mac_create_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_mbuf(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_from_mbuf, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-void
-mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_bpfdesc, bpf_d, &bpf_d->bd_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_linklayer, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_ifnet, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf, struct ifnet *ifnet,
- struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_multicast_encap, oldmbuf, oldmbuflabel,
- ifnet, &ifnet->if_label, newmbuf, newmbuflabel);
-}
-
-void
-mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_netlayer, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-int
-mac_fragment_match(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
- int result;
-
- label = mbuf_to_label(fragment);
-
- result = 1;
- MAC_BOOLEAN(fragment_match, &&, fragment, label, ipq,
- &ipq->ipq_label);
-
- return (result);
-}
-
-void
-mac_update_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(update_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_socket(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_socket, socket, &socket->so_label, mbuf,
- label);
-}
-
-void
-mac_create_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-void
-mac_create_root_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_root_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-int
-mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet)
-{
- int error;
-
- if (!mac_enforce_network)
- return (0);
-
- MAC_CHECK(check_bpfdesc_receive, bpf_d, &bpf_d->bd_label, ifnet,
- &ifnet->if_label);
-
- return (error);
-}
-
-static int
-mac_check_cred_relabel(struct ucred *cred, struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_cred_relabel, cred, newlabel);
-
- return (error);
-}
-
-int
-mac_check_cred_visible(struct ucred *u1, struct ucred *u2)
-{
- int error;
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_cred_visible, u1, u2);
-
- return (error);
-}
-
-int
-mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- M_ASSERTPKTHDR(mbuf);
-
- if (!mac_enforce_network)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_ifnet_transmit, ifnet, &ifnet->if_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_kenv_dump(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_dump, cred);
-
- return (error);
-}
-
-int
-mac_check_kenv_get(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_get, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kenv_set(struct ucred *cred, char *name, char *value)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_set, cred, name, value);
-
- return (error);
-}
-
-int
-mac_check_kenv_unset(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_unset, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kld_load(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_kld_load");
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_load, cred, vp, &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_kld_stat(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_stat, cred);
-
- return (error);
-}
-
-int
-mac_check_kld_unload(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_unload, cred);
-
- return (error);
-}
-
-int
-mac_check_mount_stat(struct ucred *cred, struct mount *mount)
-{
- int error;
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_mount_stat, cred, mount, &mount->mnt_mntlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, unsigned long cmd,
- void *data)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_ioctl, cred, pipe, pipe->pipe_label, cmd, data);
-
- return (error);
-}
-
-int
-mac_check_pipe_poll(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_poll, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_read(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_read, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-static int
-mac_check_pipe_relabel(struct ucred *cred, struct pipe *pipe,
- struct label *newlabel)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_relabel, cred, pipe, pipe->pipe_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_stat(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_stat, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_write(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_write, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_proc_debug(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_debug, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_sched(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_sched, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_signal(struct ucred *cred, struct proc *proc, int signum)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_signal, cred, proc, signum);
-
- return (error);
-}
-
-int
-mac_check_socket_bind(struct ucred *ucred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_bind, ucred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_connect(struct ucred *cred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_connect, cred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_deliver(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_socket_deliver, socket, &socket->so_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_socket_listen(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_listen, cred, socket, &socket->so_label);
- return (error);
-}
-
-int
-mac_check_socket_receive(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_receive, cred, so, &so->so_label);
-
- return (error);
-}
-
-static int
-mac_check_socket_relabel(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_socket_relabel, cred, socket, &socket->so_label,
- newlabel);
-
- return (error);
-}
-
-int
-mac_check_socket_send(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_send, cred, so, &so->so_label);
-
- return (error);
-}
-
-int
-mac_check_socket_visible(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_visible, cred, socket, &socket->so_label);
-
- return (error);
-}
-
-int
-mac_check_sysarch_ioperm(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_sysarch_ioperm, cred);
- return (error);
-}
-
-int
-mac_check_system_acct(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- if (vp != NULL) {
- ASSERT_VOP_LOCKED(vp, "mac_check_system_acct");
- }
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_acct, cred, vp,
- vp != NULL ? &vp->v_label : NULL);
-
- return (error);
-}
-
-int
-mac_check_system_nfsd(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_nfsd, cred);
-
- return (error);
-}
-
-int
-mac_check_system_reboot(struct ucred *cred, int howto)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_reboot, cred, howto);
-
- return (error);
-}
-
-int
-mac_check_system_settime(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_settime, cred);
-
- return (error);
-}
-
-int
-mac_check_system_swapon(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapon");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapon, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_swapoff(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapoff");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapoff, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_sysctl(struct ucred *cred, int *name, u_int namelen,
- void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen)
-{
- int error;
-
- /*
- * XXXMAC: We're very much like to assert the SYSCTL_LOCK here,
- * but since it's not exported from kern_sysctl.c, we can't.
- */
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_sysctl, cred, name, namelen, old, oldlenp,
- inkernel, new, newlen);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_ifnet_label(&ifnet->if_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- struct label intlabel;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_ifnet_label(&intlabel);
- error = mac_internalize_ifnet_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- /*
- * XXX: Note that this is a redundant privilege check, since
- * policies impose this check themselves if required by the
- * policy. Eventually, this should go away.
- */
- error = suser_cred(cred, 0);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_CHECK(check_ifnet_relabel, cred, ifnet, &ifnet->if_label,
- &intlabel);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_PERFORM(relabel_ifnet, cred, ifnet, &ifnet->if_label, &intlabel);
-
- mac_destroy_ifnet_label(&intlabel);
- return (0);
-}
-
-void
-mac_create_devfs_device(struct mount *mp, dev_t dev, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_device, mp, dev, de, &de->de_label);
-}
-
-void
-mac_create_devfs_symlink(struct ucred *cred, struct mount *mp,
- struct devfs_dirent *dd, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_symlink, cred, mp, dd, &dd->de_label, de,
- &de->de_label);
-}
-
-void
-mac_create_devfs_directory(struct mount *mp, char *dirname, int dirnamelen,
- struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_directory, mp, dirname, dirnamelen, de,
- &de->de_label);
-}
-
-int
-mac_setsockopt_label_set(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- struct label intlabel;
- char *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, buffer, mac->m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_socket_label(&intlabel, M_WAITOK);
- error = mac_internalize_socket_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_check_socket_relabel(cred, so, &intlabel);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_relabel_socket(cred, so, &intlabel);
-
- mac_destroy_socket_label(&intlabel);
- return (0);
-}
-
-int
-mac_pipe_label_set(struct ucred *cred, struct pipe *pipe, struct label *label)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- error = mac_check_pipe_relabel(cred, pipe, label);
- if (error)
- return (error);
-
- mac_relabel_pipe(cred, pipe, label);
-
- return (0);
-}
-
-int
-mac_getsockopt_label_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *buffer, *elements;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_label(&so->so_label, elements,
- buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_getsockopt_peerlabel_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *elements, *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_peer_label(&so->so_peerlabel,
- elements, buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * Implementation of VOP_SETLABEL() that relies on extended attributes
- * to store label data. Can be referenced by filesystems supporting
- * extended attributes.
- */
-int
-vop_stdsetlabel_ea(struct vop_setlabel_args *ap)
-{
- struct vnode *vp = ap->a_vp;
- struct label *intlabel = ap->a_label;
- int error;
-
- ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea");
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- error = mac_setlabel_vnode_extattr(ap->a_cred, vp, intlabel);
- if (error)
- return (error);
-
- mac_relabel_vnode(ap->a_cred, vp, intlabel);
-
- return (0);
-}
-
-static int
-vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred)
-{
- int error;
-
- if (vp->v_mount == NULL) {
- /* printf("vn_setlabel: null v_mount\n"); */
- if (vp->v_type != VNON)
- printf("vn_setlabel: null v_mount with non-VNON\n");
- return (EBADF);
- }
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- /*
- * Multi-phase commit. First check the policies to confirm the
- * change is OK. Then commit via the filesystem. Finally,
- * update the actual vnode label. Question: maybe the filesystem
- * should update the vnode at the end as part of VOP_SETLABEL()?
- */
- error = mac_check_vnode_relabel(cred, vp, intlabel);
- if (error)
- return (error);
-
- /*
- * VADMIN provides the opportunity for the filesystem to make
- * decisions about who is and is not able to modify labels
- * and protections on files. This might not be right. We can't
- * assume VOP_SETLABEL() will do it, because we might implement
- * that as part of vop_stdsetlabel_ea().
- */
- error = VOP_ACCESS(vp, VADMIN, cred, curthread);
- if (error)
- return (error);
-
- error = VOP_SETLABEL(vp, intlabel, cred, curthread);
- if (error)
- return (error);
-
- return (0);
-}
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- struct proc *tproc;
- struct ucred *tcred;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- tproc = pfind(uap->pid);
- if (tproc == NULL)
- return (ESRCH);
-
- tcred = NULL; /* Satisfy gcc. */
- error = p_cansee(td, tproc);
- if (error == 0)
- tcred = crhold(tproc->p_ucred);
- PROC_UNLOCK(tproc);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&tcred->cr_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&td->td_ucred->cr_label,
- elements, buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
- struct ucred *newcred, *oldcred;
- struct label intlabel;
- struct proc *p;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(&intlabel);
- error = mac_internalize_cred_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(&intlabel);
- return (error);
- }
-
- newcred = crget();
-
- p = td->td_proc;
- PROC_LOCK(p);
- oldcred = p->p_ucred;
-
- error = mac_check_cred_relabel(oldcred, &intlabel);
- if (error) {
- PROC_UNLOCK(p);
- crfree(newcred);
- goto out;
- }
-
- setsugid(p);
- crcopy(newcred, oldcred);
- mac_relabel_cred(newcred, &intlabel);
- p->p_ucred = newcred;
-
- /*
- * Grab additional reference for use while revoking mmaps, prior
- * to releasing the proc lock and sharing the cred.
- */
- crhold(newcred);
- PROC_UNLOCK(p);
-
- if (mac_enforce_vm) {
- mtx_lock(&Giant);
- mac_cred_mmapped_drop_perms(td, newcred);
- mtx_unlock(&Giant);
- }
-
- crfree(newcred); /* Free revocation reference. */
- crfree(oldcred);
-
-out:
- mac_destroy_cred_label(&intlabel);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
- char *elements, *buffer;
- struct label intlabel;
- struct file *fp;
- struct mac mac;
- struct vnode *vp;
- struct pipe *pipe;
- short label_type;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- label_type = fp->f_type;
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- vp = fp->f_data;
-
- mac_init_vnode_label(&intlabel);
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- mac_copy_vnode_label(&vp->v_label, &intlabel);
- VOP_UNLOCK(vp, 0, td);
-
- break;
- case DTYPE_PIPE:
- pipe = fp->f_data;
-
- mac_init_pipe_label(&intlabel);
-
- PIPE_LOCK(pipe);
- mac_copy_pipe_label(pipe->pipe_label, &intlabel);
- PIPE_UNLOCK(pipe);
- break;
- default:
- error = EINVAL;
- fdrop(fp, td);
- goto out;
- }
- fdrop(fp, td);
-
- switch (label_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- if (error == 0)
- error = mac_externalize_vnode_label(&intlabel,
- elements, buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_vnode_label(&intlabel);
- break;
- case DTYPE_PIPE:
- error = mac_externalize_pipe_label(&intlabel, elements,
- buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_pipe_label(&intlabel);
- break;
- default:
- panic("__mac_get_fd: corrupted label_type");
- }
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
-
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
- struct label intlabel;
- struct pipe *pipe;
- struct file *fp;
- struct mount *mp;
- struct vnode *vp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vp = fp->f_data;
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error != 0) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- error = vn_setlabel(vp, &intlabel, td->td_ucred);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
-
- mac_destroy_vnode_label(&intlabel);
- break;
-
- case DTYPE_PIPE:
- mac_init_pipe_label(&intlabel);
- error = mac_internalize_pipe_label(&intlabel, buffer);
- if (error == 0) {
- pipe = fp->f_data;
- PIPE_LOCK(pipe);
- error = mac_pipe_label_set(td->td_ucred, pipe,
- &intlabel);
- PIPE_UNLOCK(pipe);
- }
-
- mac_destroy_pipe_label(&intlabel);
- break;
-
- default:
- error = EINVAL;
- }
-
- fdrop(fp, td);
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
- struct mac_policy_conf *mpc;
- char target[MAC_MAX_POLICY_NAME];
- int entrycount, error;
-
- error = copyinstr(uap->policy, target, sizeof(target), NULL);
- if (error)
- return (error);
-
- error = ENOSYS;
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- goto out;
- }
- }
-
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) {
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- break;
- }
- }
- mac_policy_list_unbusy();
- }
-out:
- return (error);
-}
-
-SYSINIT(mac, SI_SUB_MAC, SI_ORDER_FIRST, mac_init, NULL);
-SYSINIT(mac_late, SI_SUB_MAC_LATE, SI_ORDER_FIRST, mac_late_init, NULL);
-
-#else /* !MAC */
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
-
- return (ENOSYS);
-}
-
-#endif
diff --git a/sys/security/mac/mac_pipe.c b/sys/security/mac/mac_pipe.c
deleted file mode 100644
index fb06edea3012..000000000000
--- a/sys/security/mac/mac_pipe.c
+++ /dev/null
@@ -1,3975 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * Copyright (c) 2001 Ilmar S. Habibulin
- * Copyright (c) 2001, 2002, 2003 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * This software was developed by Robert Watson and Ilmar Habibulin for the
- * TrustedBSD Project.
- *
- * This software was developed for the FreeBSD Project in part by Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
- * as part of the DARPA CHATS research program.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-/*
- * Developed by the TrustedBSD Project.
- *
- * Framework for extensible kernel access control. Kernel and userland
- * interface to the framework, policy registration and composition.
- */
-
-#include "opt_mac.h"
-#include "opt_devfs.h"
-
-#include <sys/param.h>
-#include <sys/condvar.h>
-#include <sys/extattr.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/mac.h>
-#include <sys/module.h>
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/sysent.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/file.h>
-#include <sys/namei.h>
-#include <sys/socket.h>
-#include <sys/pipe.h>
-#include <sys/socketvar.h>
-#include <sys/sysctl.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-
-#include <sys/mac_policy.h>
-
-#include <fs/devfs/devfs.h>
-
-#include <net/bpfdesc.h>
-#include <net/if.h>
-#include <net/if_var.h>
-
-#include <netinet/in.h>
-#include <netinet/ip_var.h>
-
-#ifdef MAC
-
-/*
- * Declare that the kernel provides MAC support, version 1. This permits
- * modules to refuse to be loaded if the necessary support isn't present,
- * even if it's pre-boot.
- */
-MODULE_VERSION(kernel_mac_support, 1);
-
-SYSCTL_DECL(_security);
-
-SYSCTL_NODE(_security, OID_AUTO, mac, CTLFLAG_RW, 0,
- "TrustedBSD MAC policy controls");
-
-#if MAC_MAX_SLOTS > 32
-#error "MAC_MAX_SLOTS too large"
-#endif
-
-static unsigned int mac_max_slots = MAC_MAX_SLOTS;
-static unsigned int mac_slot_offsets_free = (1 << MAC_MAX_SLOTS) - 1;
-SYSCTL_UINT(_security_mac, OID_AUTO, max_slots, CTLFLAG_RD,
- &mac_max_slots, 0, "");
-
-/*
- * Has the kernel started generating labeled objects yet? All read/write
- * access to this variable is serialized during the boot process. Following
- * the end of serialization, we don't update this flag; no locking.
- */
-static int mac_late = 0;
-
-/*
- * Warn about EA transactions only the first time they happen.
- * Weak coherency, no locking.
- */
-static int ea_warn_once = 0;
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
-/*
- * Flag to indicate whether or not we should allocate label storage for
- * new mbufs. Since most dynamic policies we currently work with don't
- * rely on mbuf labeling, try to avoid paying the cost of mtag allocation
- * unless specifically notified of interest. One result of this is
- * that if a dynamically loaded policy requests mbuf labels, it must
- * be able to deal with a NULL label being returned on any mbufs that
- * were already in flight when the policy was loaded. Since the policy
- * already has to deal with uninitialized labels, this probably won't
- * be a problem. Note: currently no locking. Will this be a problem?
- */
-static int mac_labelmbufs = 0;
-#endif
-
-static int mac_enforce_fs = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_fs, CTLFLAG_RW,
- &mac_enforce_fs, 0, "Enforce MAC policy on file system objects");
-TUNABLE_INT("security.mac.enforce_fs", &mac_enforce_fs);
-
-static int mac_enforce_kld = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_kld, CTLFLAG_RW,
- &mac_enforce_kld, 0, "Enforce MAC policy on kld operations");
-TUNABLE_INT("security.mac.enforce_kld", &mac_enforce_kld);
-
-static int mac_enforce_network = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_network, CTLFLAG_RW,
- &mac_enforce_network, 0, "Enforce MAC policy on network packets");
-TUNABLE_INT("security.mac.enforce_network", &mac_enforce_network);
-
-static int mac_enforce_pipe = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_pipe, CTLFLAG_RW,
- &mac_enforce_pipe, 0, "Enforce MAC policy on pipe operations");
-TUNABLE_INT("security.mac.enforce_pipe", &mac_enforce_pipe);
-
-static int mac_enforce_process = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_process, CTLFLAG_RW,
- &mac_enforce_process, 0, "Enforce MAC policy on inter-process operations");
-TUNABLE_INT("security.mac.enforce_process", &mac_enforce_process);
-
-static int mac_enforce_socket = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_socket, CTLFLAG_RW,
- &mac_enforce_socket, 0, "Enforce MAC policy on socket operations");
-TUNABLE_INT("security.mac.enforce_socket", &mac_enforce_socket);
-
-static int mac_enforce_system = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_system, CTLFLAG_RW,
- &mac_enforce_system, 0, "Enforce MAC policy on system operations");
-TUNABLE_INT("security.mac.enforce_system", &mac_enforce_system);
-
-static int mac_enforce_vm = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_vm, CTLFLAG_RW,
- &mac_enforce_vm, 0, "Enforce MAC policy on vm operations");
-TUNABLE_INT("security.mac.enforce_vm", &mac_enforce_vm);
-
-static int mac_mmap_revocation = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation, CTLFLAG_RW,
- &mac_mmap_revocation, 0, "Revoke mmap access to files on subject "
- "relabel");
-static int mac_mmap_revocation_via_cow = 0;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation_via_cow, CTLFLAG_RW,
- &mac_mmap_revocation_via_cow, 0, "Revoke mmap access to files via "
- "copy-on-write semantics, or by removing all write access");
-
-#ifdef MAC_DEBUG
-SYSCTL_NODE(_security_mac, OID_AUTO, debug, CTLFLAG_RW, 0,
- "TrustedBSD MAC debug info");
-
-static int mac_debug_label_fallback = 0;
-SYSCTL_INT(_security_mac_debug, OID_AUTO, label_fallback, CTLFLAG_RW,
- &mac_debug_label_fallback, 0, "Filesystems should fall back to fs label"
- "when label is corrupted.");
-TUNABLE_INT("security.mac.debug_label_fallback",
- &mac_debug_label_fallback);
-
-SYSCTL_NODE(_security_mac_debug, OID_AUTO, counters, CTLFLAG_RW, 0,
- "TrustedBSD MAC object counters");
-
-static unsigned int nmacmbufs, nmaccreds, nmacifnets, nmacbpfdescs,
- nmacsockets, nmacmounts, nmactemp, nmacvnodes, nmacdevfsdirents,
- nmacipqs, nmacpipes, nmacprocs;
-
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mbufs, CTLFLAG_RD,
- &nmacmbufs, 0, "number of mbufs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, creds, CTLFLAG_RD,
- &nmaccreds, 0, "number of ucreds in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ifnets, CTLFLAG_RD,
- &nmacifnets, 0, "number of ifnets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ipqs, CTLFLAG_RD,
- &nmacipqs, 0, "number of ipqs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, bpfdescs, CTLFLAG_RD,
- &nmacbpfdescs, 0, "number of bpfdescs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, sockets, CTLFLAG_RD,
- &nmacsockets, 0, "number of sockets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, pipes, CTLFLAG_RD,
- &nmacpipes, 0, "number of pipes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, procs, CTLFLAG_RD,
- &nmacprocs, 0, "number of procs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mounts, CTLFLAG_RD,
- &nmacmounts, 0, "number of mounts in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, temp, CTLFLAG_RD,
- &nmactemp, 0, "number of temporary labels in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, vnodes, CTLFLAG_RD,
- &nmacvnodes, 0, "number of vnodes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, devfsdirents, CTLFLAG_RD,
- &nmacdevfsdirents, 0, "number of devfs dirents inuse");
-#endif
-
-static int error_select(int error1, int error2);
-static int mac_policy_register(struct mac_policy_conf *mpc);
-static int mac_policy_unregister(struct mac_policy_conf *mpc);
-
-static void mac_check_vnode_mmap_downgrade(struct ucred *cred,
- struct vnode *vp, int *prot);
-static void mac_cred_mmapped_drop_perms_recurse(struct thread *td,
- struct ucred *cred, struct vm_map *map);
-
-static void mac_destroy_socket_label(struct label *label);
-
-static int mac_setlabel_vnode_extattr(struct ucred *cred,
- struct vnode *vp, struct label *intlabel);
-
-MALLOC_DEFINE(M_MACPIPELABEL, "macpipelabel", "MAC labels for pipes");
-MALLOC_DEFINE(M_MACTEMP, "mactemp", "MAC temporary label storage");
-
-/*
- * mac_static_policy_list holds a list of policy modules that are not
- * loaded while the system is "live", and cannot be unloaded. These
- * policies can be invoked without holding the busy count.
- *
- * mac_policy_list stores the list of dynamic policies. A busy count is
- * maintained for the list, stored in mac_policy_busy. The busy count
- * is protected by mac_policy_mtx; the list may be modified only
- * while the busy count is 0, requiring that the lock be held to
- * prevent new references to the list from being acquired. For almost
- * all operations, incrementing the busy count is sufficient to
- * guarantee consistency, as the list cannot be modified while the
- * busy count is elevated. For a few special operations involving a
- * change to the list of active policies, the mtx itself must be held.
- * A condition variable, mac_policy_cv, is used to signal potential
- * exclusive consumers that they should try to acquire the lock if a
- * first attempt at exclusive access fails.
- */
-static struct mtx mac_policy_mtx;
-static struct cv mac_policy_cv;
-static int mac_policy_count;
-static LIST_HEAD(, mac_policy_conf) mac_policy_list;
-static LIST_HEAD(, mac_policy_conf) mac_static_policy_list;
-
-/*
- * We manually invoke WITNESS_WARN() to allow Witness to generate
- * warnings even if we don't end up ever triggering the wait at
- * run-time. The consumer of the exclusive interface must not hold
- * any locks (other than potentially Giant) since we may sleep for
- * long (potentially indefinite) periods of time waiting for the
- * framework to become quiescent so that a policy list change may
- * be made.
- */
-static __inline void
-mac_policy_grab_exclusive(void)
-{
- WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
- "mac_policy_grab_exclusive() at %s:%d", __FILE__, __LINE__);
- mtx_lock(&mac_policy_mtx);
- while (mac_policy_count != 0)
- cv_wait(&mac_policy_cv, &mac_policy_mtx);
-}
-
-static __inline void
-mac_policy_assert_exclusive(void)
-{
- mtx_assert(&mac_policy_mtx, MA_OWNED);
- KASSERT(mac_policy_count == 0,
- ("mac_policy_assert_exclusive(): not exclusive"));
-}
-
-static __inline void
-mac_policy_release_exclusive(void)
-{
-
- KASSERT(mac_policy_count == 0,
- ("mac_policy_release_exclusive(): not exclusive"));
- mtx_unlock(&mac_policy_mtx);
- cv_signal(&mac_policy_cv);
-}
-
-static __inline void
-mac_policy_list_busy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count++;
- mtx_unlock(&mac_policy_mtx);
-}
-
-static __inline int
-mac_policy_list_conditional_busy(void)
-{
- int ret;
-
- mtx_lock(&mac_policy_mtx);
- if (!LIST_EMPTY(&mac_policy_list)) {
- mac_policy_count++;
- ret = 1;
- } else
- ret = 0;
- mtx_unlock(&mac_policy_mtx);
- return (ret);
-}
-
-static __inline void
-mac_policy_list_unbusy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count--;
- KASSERT(mac_policy_count >= 0, ("MAC_POLICY_LIST_LOCK"));
- if (mac_policy_count == 0)
- cv_signal(&mac_policy_cv);
- mtx_unlock(&mac_policy_mtx);
-}
-
-/*
- * MAC_CHECK performs the designated check by walking the policy
- * module list and checking with each as to how it feels about the
- * request. Note that it returns its value via 'error' in the scope
- * of the caller.
- */
-#define MAC_CHECK(check, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- error = 0; \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * MAC_BOOLEAN performs the designated boolean composition by walking
- * the module list, invoking each instance of the operation, and
- * combining the results using the passed C operator. Note that it
- * returns its value via 'result' in the scope of the caller, which
- * should be initialized by the caller in a meaningful way to get
- * a meaningful result.
- */
-#define MAC_BOOLEAN(operation, composition, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation \
- (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-#define MAC_EXTERNALIZE(type, label, elementlist, outbuf, \
- outbuflen) do { \
- char *curptr, *curptr_start, *element_name, *element_temp; \
- size_t left, left_start, len; \
- int claimed, first, first_start, ignorenotfound; \
- \
- error = 0; \
- element_temp = elementlist; \
- curptr = outbuf; \
- curptr[0] = '\0'; \
- left = outbuflen; \
- first = 1; \
- while ((element_name = strsep(&element_temp, ",")) != NULL) { \
- curptr_start = curptr; \
- left_start = left; \
- first_start = first; \
- if (element_name[0] == '?') { \
- element_name++; \
- ignorenotfound = 1; \
- } else \
- ignorenotfound = 0; \
- claimed = 0; \
- if (first) { \
- len = snprintf(curptr, left, "%s/", \
- element_name); \
- first = 0; \
- } else \
- len = snprintf(curptr, left, ",%s/", \
- element_name); \
- if (len >= left) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- \
- MAC_CHECK(externalize_ ## type, label, element_name, \
- curptr, left, &len, &claimed); \
- if (error) \
- break; \
- if (claimed == 1) { \
- if (len >= outbuflen) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- } else if (claimed == 0 && ignorenotfound) { \
- /* \
- * Revert addition of the label element \
- * name. \
- */ \
- curptr = curptr_start; \
- *curptr = '\0'; \
- left = left_start; \
- first = first_start; \
- } else { \
- error = EINVAL; /* XXXMAC: ENOLABEL */ \
- break; \
- } \
- } \
-} while (0)
-
-#define MAC_INTERNALIZE(type, label, instring) do { \
- char *element, *element_name, *element_data; \
- int claimed; \
- \
- error = 0; \
- element = instring; \
- while ((element_name = strsep(&element, ",")) != NULL) { \
- element_data = element_name; \
- element_name = strsep(&element_data, "/"); \
- if (element_data == NULL) { \
- error = EINVAL; \
- break; \
- } \
- claimed = 0; \
- MAC_CHECK(internalize_ ## type, label, element_name, \
- element_data, &claimed); \
- if (error) \
- break; \
- if (claimed != 1) { \
- /* XXXMAC: Another error here? */ \
- error = EINVAL; \
- break; \
- } \
- } \
-} while (0)
-
-/*
- * MAC_PERFORM performs the designated operation by walking the policy
- * module list and invoking that operation for each policy.
- */
-#define MAC_PERFORM(operation, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * Initialize the MAC subsystem, including appropriate SMP locks.
- */
-static void
-mac_init(void)
-{
-
- LIST_INIT(&mac_static_policy_list);
- LIST_INIT(&mac_policy_list);
-
- mtx_init(&mac_policy_mtx, "mac_policy_mtx", NULL, MTX_DEF);
- cv_init(&mac_policy_cv, "mac_policy_cv");
-}
-
-/*
- * For the purposes of modules that want to know if they were loaded
- * "early", set the mac_late flag once we've processed modules either
- * linked into the kernel, or loaded before the kernel startup.
- */
-static void
-mac_late_init(void)
-{
-
- mac_late = 1;
-}
-
-/*
- * After the policy list has changed, walk the list to update any global
- * flags.
- */
-static void
-mac_policy_updateflags(void)
-{
- struct mac_policy_conf *tmpc;
-#ifndef MAC_ALWAYS_LABEL_MBUF
- int labelmbufs;
-#endif
-
- mac_policy_assert_exclusive();
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- labelmbufs = 0;
-#endif
-
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- mac_labelmbufs = (labelmbufs != 0);
-#endif
-}
-
-/*
- * Allow MAC policy modules to register during boot, etc.
- */
-int
-mac_policy_modevent(module_t mod, int type, void *data)
-{
- struct mac_policy_conf *mpc;
- int error;
-
- error = 0;
- mpc = (struct mac_policy_conf *) data;
-
- switch (type) {
- case MOD_LOAD:
- if (mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_NOTLATE &&
- mac_late) {
- printf("mac_policy_modevent: can't load %s policy "
- "after booting\n", mpc->mpc_name);
- error = EBUSY;
- break;
- }
- error = mac_policy_register(mpc);
- break;
- case MOD_UNLOAD:
- /* Don't unregister the module if it was never registered. */
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED)
- != 0)
- error = mac_policy_unregister(mpc);
- else
- error = 0;
- break;
- default:
- break;
- }
-
- return (error);
-}
-
-static int
-mac_policy_register(struct mac_policy_conf *mpc)
-{
- struct mac_policy_conf *tmpc;
- int error, slot, static_entry;
-
- error = 0;
-
- /*
- * We don't technically need exclusive access while !mac_late,
- * but hold it for assertion consistency.
- */
- mac_policy_grab_exclusive();
-
- /*
- * If the module can potentially be unloaded, or we're loading
- * late, we have to stick it in the non-static list and pay
- * an extra performance overhead. Otherwise, we can pay a
- * light locking cost and stick it in the static list.
- */
- static_entry = (!mac_late &&
- !(mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK));
-
- if (static_entry) {
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- } else {
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- }
- if (mpc->mpc_field_off != NULL) {
- slot = ffs(mac_slot_offsets_free);
- if (slot == 0) {
- error = ENOMEM;
- goto out;
- }
- slot--;
- mac_slot_offsets_free &= ~(1 << slot);
- *mpc->mpc_field_off = slot;
- }
- mpc->mpc_runtime_flags |= MPC_RUNTIME_FLAG_REGISTERED;
-
- /*
- * If we're loading a MAC module after the framework has
- * initialized, it has to go into the dynamic list. If
- * we're loading it before we've finished initializing,
- * it can go into the static list with weaker locker
- * requirements.
- */
- if (static_entry)
- LIST_INSERT_HEAD(&mac_static_policy_list, mpc, mpc_list);
- else
- LIST_INSERT_HEAD(&mac_policy_list, mpc, mpc_list);
-
- /* Per-policy initialization. */
- if (mpc->mpc_ops->mpo_init != NULL)
- (*(mpc->mpc_ops->mpo_init))(mpc);
- mac_policy_updateflags();
-
- printf("Security policy loaded: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
-out:
- mac_policy_release_exclusive();
- return (error);
-}
-
-static int
-mac_policy_unregister(struct mac_policy_conf *mpc)
-{
-
- /*
- * If we fail the load, we may get a request to unload. Check
- * to see if we did the run-time registration, and if not,
- * silently succeed.
- */
- mac_policy_grab_exclusive();
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED) == 0) {
- mac_policy_release_exclusive();
- return (0);
- }
-#if 0
- /*
- * Don't allow unloading modules with private data.
- */
- if (mpc->mpc_field_off != NULL) {
- MAC_POLICY_LIST_UNLOCK();
- return (EBUSY);
- }
-#endif
- /*
- * Only allow the unload to proceed if the module is unloadable
- * by its own definition.
- */
- if ((mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK) == 0) {
- mac_policy_release_exclusive();
- return (EBUSY);
- }
- if (mpc->mpc_ops->mpo_destroy != NULL)
- (*(mpc->mpc_ops->mpo_destroy))(mpc);
-
- LIST_REMOVE(mpc, mpc_list);
- mpc->mpc_runtime_flags &= ~MPC_RUNTIME_FLAG_REGISTERED;
- mac_policy_updateflags();
-
- mac_policy_release_exclusive();
-
- printf("Security policy unload: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
- return (0);
-}
-
-/*
- * Define an error value precedence, and given two arguments, selects the
- * value with the higher precedence.
- */
-static int
-error_select(int error1, int error2)
-{
-
- /* Certain decision-making errors take top priority. */
- if (error1 == EDEADLK || error2 == EDEADLK)
- return (EDEADLK);
-
- /* Invalid arguments should be reported where possible. */
- if (error1 == EINVAL || error2 == EINVAL)
- return (EINVAL);
-
- /* Precedence goes to "visibility", with both process and file. */
- if (error1 == ESRCH || error2 == ESRCH)
- return (ESRCH);
-
- if (error1 == ENOENT || error2 == ENOENT)
- return (ENOENT);
-
- /* Precedence goes to DAC/MAC protections. */
- if (error1 == EACCES || error2 == EACCES)
- return (EACCES);
-
- /* Precedence goes to privilege. */
- if (error1 == EPERM || error2 == EPERM)
- return (EPERM);
-
- /* Precedence goes to error over success; otherwise, arbitrary. */
- if (error1 != 0)
- return (error1);
- return (error2);
-}
-
-static struct label *
-mbuf_to_label(struct mbuf *mbuf)
-{
- struct m_tag *tag;
- struct label *label;
-
- tag = m_tag_find(mbuf, PACKET_TAG_MACLABEL, NULL);
- label = (struct label *)(tag+1);
-
- return (label);
-}
-
-static void
-mac_init_label(struct label *label)
-{
-
- bzero(label, sizeof(*label));
- label->l_flags = MAC_FLAG_INITIALIZED;
-}
-
-static void
-mac_destroy_label(struct label *label)
-{
-
- KASSERT(label->l_flags & MAC_FLAG_INITIALIZED,
- ("destroying uninitialized label"));
-
- bzero(label, sizeof(*label));
- /* implicit: label->l_flags &= ~MAC_FLAG_INITIALIZED; */
-}
-
-void
-mac_init_bpfdesc(struct bpf_d *bpf_d)
-{
-
- mac_init_label(&bpf_d->bd_label);
- MAC_PERFORM(init_bpfdesc_label, &bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_init_cred_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_cred_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_init_cred(struct ucred *cred)
-{
-
- mac_init_cred_label(&cred->cr_label);
-}
-
-void
-mac_init_devfsdirent(struct devfs_dirent *de)
-{
-
- mac_init_label(&de->de_label);
- MAC_PERFORM(init_devfsdirent_label, &de->de_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_init_ifnet_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_ifnet_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_init_ifnet(struct ifnet *ifp)
-{
-
- mac_init_ifnet_label(&ifp->if_label);
-}
-
-int
-mac_init_ipq(struct ipq *ipq, int flag)
-{
- int error;
-
- mac_init_label(&ipq->ipq_label);
-
- MAC_CHECK(init_ipq_label, &ipq->ipq_label, flag);
- if (error) {
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacipqs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf_tag(struct m_tag *tag, int flag)
-{
- struct label *label;
- int error;
-
- label = (struct label *) (tag + 1);
- mac_init_label(label);
-
- MAC_CHECK(init_mbuf_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacmbufs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf(struct mbuf *m, int flag)
-{
- struct m_tag *tag;
- int error;
-
- M_ASSERTPKTHDR(m);
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- /*
- * Don't reserve space for labels on mbufs unless we have a policy
- * that uses the labels.
- */
- if (mac_labelmbufs) {
-#endif
- tag = m_tag_get(PACKET_TAG_MACLABEL, sizeof(struct label),
- flag);
- if (tag == NULL)
- return (ENOMEM);
- error = mac_init_mbuf_tag(tag, flag);
- if (error) {
- m_tag_free(tag);
- return (error);
- }
- m_tag_prepend(m, tag);
-#ifndef MAC_ALWAYS_LABEL_MBUF
- }
-#endif
- return (0);
-}
-
-void
-mac_init_mount(struct mount *mp)
-{
-
- mac_init_label(&mp->mnt_mntlabel);
- mac_init_label(&mp->mnt_fslabel);
- MAC_PERFORM(init_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(init_mount_fs_label, &mp->mnt_fslabel);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_init_pipe_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_pipe_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_init_pipe(struct pipe *pipe)
-{
- struct label *label;
-
- label = malloc(sizeof(struct label), M_MACPIPELABEL, M_ZERO|M_WAITOK);
- pipe->pipe_label = label;
- pipe->pipe_peer->pipe_label = label;
- mac_init_pipe_label(label);
-}
-
-void
-mac_init_proc(struct proc *p)
-{
-
- mac_init_label(&p->p_label);
- MAC_PERFORM(init_proc_label, &p->p_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacprocs, 1);
-#endif
-}
-
-static int
-mac_init_socket_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacsockets, 1);
-#endif
-
- return (error);
-}
-
-static int
-mac_init_socket_peer_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_peer_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
- return (error);
-}
-
-int
-mac_init_socket(struct socket *socket, int flag)
-{
- int error;
-
- error = mac_init_socket_label(&socket->so_label, flag);
- if (error)
- return (error);
-
- error = mac_init_socket_peer_label(&socket->so_peerlabel, flag);
- if (error)
- mac_destroy_socket_label(&socket->so_label);
-
- return (error);
-}
-
-void
-mac_init_vnode_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_vnode_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_init_vnode(struct vnode *vp)
-{
-
- mac_init_vnode_label(&vp->v_label);
-}
-
-void
-mac_destroy_bpfdesc(struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(destroy_bpfdesc_label, &bpf_d->bd_label);
- mac_destroy_label(&bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_destroy_cred_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_cred_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_destroy_cred(struct ucred *cred)
-{
-
- mac_destroy_cred_label(&cred->cr_label);
-}
-
-void
-mac_destroy_devfsdirent(struct devfs_dirent *de)
-{
-
- MAC_PERFORM(destroy_devfsdirent_label, &de->de_label);
- mac_destroy_label(&de->de_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_destroy_ifnet_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_ifnet_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_destroy_ifnet(struct ifnet *ifp)
-{
-
- mac_destroy_ifnet_label(&ifp->if_label);
-}
-
-void
-mac_destroy_ipq(struct ipq *ipq)
-{
-
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacipqs, 1);
-#endif
-}
-
-void
-mac_destroy_mbuf_tag(struct m_tag *tag)
-{
- struct label *label;
-
- label = (struct label *)(tag+1);
-
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmbufs, 1);
-#endif
-}
-
-void
-mac_destroy_mount(struct mount *mp)
-{
-
- MAC_PERFORM(destroy_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(destroy_mount_fs_label, &mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_mntlabel);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_destroy_pipe_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_pipe_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_destroy_pipe(struct pipe *pipe)
-{
-
- mac_destroy_pipe_label(pipe->pipe_label);
- free(pipe->pipe_label, M_MACPIPELABEL);
-}
-
-void
-mac_destroy_proc(struct proc *p)
-{
-
- MAC_PERFORM(destroy_proc_label, &p->p_label);
- mac_destroy_label(&p->p_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacprocs, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacsockets, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_peer_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_peer_label, label);
- mac_destroy_label(label);
-}
-
-void
-mac_destroy_socket(struct socket *socket)
-{
-
- mac_destroy_socket_label(&socket->so_label);
- mac_destroy_socket_peer_label(&socket->so_peerlabel);
-}
-
-void
-mac_destroy_vnode_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_vnode_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_destroy_vnode(struct vnode *vp)
-{
-
- mac_destroy_vnode_label(&vp->v_label);
-}
-
-void
-mac_copy_mbuf_tag(struct m_tag *src, struct m_tag *dest)
-{
- struct label *src_label, *dest_label;
-
- src_label = (struct label *)(src+1);
- dest_label = (struct label *)(dest+1);
-
- /*
- * mac_init_mbuf_tag() is called on the target tag in
- * m_tag_copy(), so we don't need to call it here.
- */
- MAC_PERFORM(copy_mbuf_label, src_label, dest_label);
-}
-
-static void
-mac_copy_pipe_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_pipe_label, src, dest);
-}
-
-void
-mac_copy_vnode_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_vnode_label, src, dest);
-}
-
-static int
-mac_check_structmac_consistent(struct mac *mac)
-{
-
- if (mac->m_buflen > MAC_MAX_LABEL_BUF_LEN)
- return (EINVAL);
-
- return (0);
-}
-
-static int
-mac_externalize_cred_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(cred_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_ifnet_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(ifnet_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_pipe_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(pipe_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_peer_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_peer_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_vnode_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(vnode_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_internalize_cred_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(cred_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_ifnet_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(ifnet_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_pipe_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(pipe_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_socket_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(socket_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_vnode_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(vnode_label, label, string);
-
- return (error);
-}
-
-/*
- * Initialize MAC label for the first kernel process, from which other
- * kernel processes and threads are spawned.
- */
-void
-mac_create_proc0(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc0, cred);
-}
-
-/*
- * Initialize MAC label for the first userland process, from which other
- * userland processes and threads are spawned.
- */
-void
-mac_create_proc1(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc1, cred);
-}
-
-void
-mac_thread_userret(struct thread *td)
-{
-
- MAC_PERFORM(thread_userret, td);
-}
-
-/*
- * When a new process is created, its label must be initialized. Generally,
- * this involves inheritence from the parent process, modulo possible
- * deltas. This function allows that processing to take place.
- */
-void
-mac_create_cred(struct ucred *parent_cred, struct ucred *child_cred)
-{
-
- MAC_PERFORM(create_cred, parent_cred, child_cred);
-}
-
-void
-mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(update_devfsdirent, mp, de, &de->de_label, vp,
- &vp->v_label);
-}
-
-void
-mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_devfs, mp, &mp->mnt_fslabel, de,
- &de->de_label, vp, &vp->v_label);
-}
-
-int
-mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_associate_vnode_extattr");
-
- MAC_CHECK(associate_vnode_extattr, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-
- return (error);
-}
-
-void
-mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_singlelabel, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-}
-
-int
-mac_create_vnode_extattr(struct ucred *cred, struct mount *mp,
- struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_create_vnode_extattr");
- ASSERT_VOP_LOCKED(vp, "mac_create_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(create_vnode_extattr, cred, mp, &mp->mnt_fslabel,
- dvp, &dvp->v_label, vp, &vp->v_label, cnp);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-static int
-mac_setlabel_vnode_extattr(struct ucred *cred, struct vnode *vp,
- struct label *intlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_setlabel_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(setlabel_vnode_extattr, cred, vp, &vp->v_label, intlabel);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-int
-mac_execve_enter(struct image_params *imgp, struct mac *mac_p,
- struct label *execlabelstorage)
-{
- struct mac mac;
- char *buffer;
- int error;
-
- if (mac_p == NULL)
- return (0);
-
- error = copyin(mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(execlabelstorage);
- error = mac_internalize_cred_label(execlabelstorage, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(execlabelstorage);
- return (error);
- }
- imgp->execlabel = execlabelstorage;
- return (0);
-}
-
-void
-mac_execve_exit(struct image_params *imgp)
-{
- if (imgp->execlabel != NULL)
- mac_destroy_cred_label(imgp->execlabel);
-}
-
-void
-mac_execve_transition(struct ucred *old, struct ucred *new, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return;
-
- MAC_PERFORM(execve_transition, old, new, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-}
-
-int
-mac_execve_will_transition(struct ucred *old, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
- int result;
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_will_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- result = 0;
- MAC_BOOLEAN(execve_will_transition, ||, old, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-
- return (result);
-}
-
-int
-mac_check_vnode_access(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_access");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_access, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chroot");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chroot, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_create(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp, struct vattr *vap)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_create");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_create, cred, dvp, &dvp->v_label, cnp, vap);
- return (error);
-}
-
-int
-mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp, struct vnode *vp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_delete");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_delete");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_delete, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
- acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_deleteacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_deleteacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_exec(struct ucred *cred, struct vnode *vp,
- struct image_params *imgp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_exec");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_exec, cred, vp, &vp->v_label, imgp,
- imgp->execlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp, acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_link(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_link");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_link");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_link, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_lookup");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_lookup, cred, dvp, &dvp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mmap, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-void
-mac_check_vnode_mmap_downgrade(struct ucred *cred, struct vnode *vp, int *prot)
-{
- int result = *prot;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap_downgrade");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return;
-
- MAC_PERFORM(check_vnode_mmap_downgrade, cred, vp, &vp->v_label,
- &result);
-
- *prot = result;
-}
-
-int
-mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mprotect");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mprotect, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-int
-mac_check_vnode_open(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_open");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_open, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_poll");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_poll, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_read");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_read, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_readdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_readdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_readlink");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readlink, cred, vp, &vp->v_label);
- return (error);
-}
-
-static int
-mac_check_vnode_relabel(struct ucred *cred, struct vnode *vp,
- struct label *newlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_relabel");
-
- MAC_CHECK(check_vnode_relabel, cred, vp, &vp->v_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_from");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_from");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_from, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, int samedir, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_to");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_to");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_to, cred, dvp, &dvp->v_label, vp,
- vp != NULL ? &vp->v_label : NULL, samedir, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_revoke");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_revoke, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type,
- struct acl *acl)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setacl, cred, vp, &vp->v_label, type, acl);
- return (error);
-}
-
-int
-mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp, u_long flags)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setflags");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setflags, cred, vp, &vp->v_label, flags);
- return (error);
-}
-
-int
-mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp, mode_t mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setmode");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setmode, cred, vp, &vp->v_label, mode);
- return (error);
-}
-
-int
-mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp, uid_t uid,
- gid_t gid)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setowner");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setowner, cred, vp, &vp->v_label, uid, gid);
- return (error);
-}
-
-int
-mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
- struct timespec atime, struct timespec mtime)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setutimes");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setutimes, cred, vp, &vp->v_label, atime,
- mtime);
- return (error);
-}
-
-int
-mac_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_stat");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_stat, active_cred, file_cred, vp,
- &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_write(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_write");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_write, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-/*
- * When relabeling a process, call out to the policies for the maximum
- * permission allowed for each object type we know about in its
- * memory space, and revoke access (in the least surprising ways we
- * know) when necessary. The process lock is not held here.
- */
-void
-mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred)
-{
-
- /* XXX freeze all other threads */
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- &td->td_proc->p_vmspace->vm_map);
- /* XXX allow other threads to continue */
-}
-
-static __inline const char *
-prot2str(vm_prot_t prot)
-{
-
- switch (prot & VM_PROT_ALL) {
- case VM_PROT_READ:
- return ("r--");
- case VM_PROT_READ | VM_PROT_WRITE:
- return ("rw-");
- case VM_PROT_READ | VM_PROT_EXECUTE:
- return ("r-x");
- case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("rwx");
- case VM_PROT_WRITE:
- return ("-w-");
- case VM_PROT_EXECUTE:
- return ("--x");
- case VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("-wx");
- default:
- return ("---");
- }
-}
-
-static void
-mac_cred_mmapped_drop_perms_recurse(struct thread *td, struct ucred *cred,
- struct vm_map *map)
-{
- struct vm_map_entry *vme;
- int result;
- vm_prot_t revokeperms;
- vm_object_t object;
- vm_ooffset_t offset;
- struct vnode *vp;
-
- if (!mac_mmap_revocation)
- return;
-
- vm_map_lock_read(map);
- for (vme = map->header.next; vme != &map->header; vme = vme->next) {
- if (vme->eflags & MAP_ENTRY_IS_SUB_MAP) {
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- vme->object.sub_map);
- continue;
- }
- /*
- * Skip over entries that obviously are not shared.
- */
- if (vme->eflags & (MAP_ENTRY_COW | MAP_ENTRY_NOSYNC) ||
- !vme->max_protection)
- continue;
- /*
- * Drill down to the deepest backing object.
- */
- offset = vme->offset;
- object = vme->object.vm_object;
- if (object == NULL)
- continue;
- while (object->backing_object != NULL) {
- object = object->backing_object;
- offset += object->backing_object_offset;
- }
- /*
- * At the moment, vm_maps and objects aren't considered
- * by the MAC system, so only things with backing by a
- * normal object (read: vnodes) are checked.
- */
- if (object->type != OBJT_VNODE)
- continue;
- vp = (struct vnode *)object->handle;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- result = vme->max_protection;
- mac_check_vnode_mmap_downgrade(cred, vp, &result);
- VOP_UNLOCK(vp, 0, td);
- /*
- * Find out what maximum protection we may be allowing
- * now but a policy needs to get removed.
- */
- revokeperms = vme->max_protection & ~result;
- if (!revokeperms)
- continue;
- printf("pid %ld: revoking %s perms from %#lx:%ld "
- "(max %s/cur %s)\n", (long)td->td_proc->p_pid,
- prot2str(revokeperms), (u_long)vme->start,
- (long)(vme->end - vme->start),
- prot2str(vme->max_protection), prot2str(vme->protection));
- vm_map_lock_upgrade(map);
- /*
- * This is the really simple case: if a map has more
- * max_protection than is allowed, but it's not being
- * actually used (that is, the current protection is
- * still allowed), we can just wipe it out and do
- * nothing more.
- */
- if ((vme->protection & revokeperms) == 0) {
- vme->max_protection -= revokeperms;
- } else {
- if (revokeperms & VM_PROT_WRITE) {
- /*
- * In the more complicated case, flush out all
- * pending changes to the object then turn it
- * copy-on-write.
- */
- vm_object_reference(object);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- VM_OBJECT_LOCK(object);
- vm_object_page_clean(object,
- OFF_TO_IDX(offset),
- OFF_TO_IDX(offset + vme->end - vme->start +
- PAGE_MASK),
- OBJPC_SYNC);
- VM_OBJECT_UNLOCK(object);
- VOP_UNLOCK(vp, 0, td);
- vm_object_deallocate(object);
- /*
- * Why bother if there's no read permissions
- * anymore? For the rest, we need to leave
- * the write permissions on for COW, or
- * remove them entirely if configured to.
- */
- if (!mac_mmap_revocation_via_cow) {
- vme->max_protection &= ~VM_PROT_WRITE;
- vme->protection &= ~VM_PROT_WRITE;
- } if ((revokeperms & VM_PROT_READ) == 0)
- vme->eflags |= MAP_ENTRY_COW |
- MAP_ENTRY_NEEDS_COPY;
- }
- if (revokeperms & VM_PROT_EXECUTE) {
- vme->max_protection &= ~VM_PROT_EXECUTE;
- vme->protection &= ~VM_PROT_EXECUTE;
- }
- if (revokeperms & VM_PROT_READ) {
- vme->max_protection = 0;
- vme->protection = 0;
- }
- pmap_protect(map->pmap, vme->start, vme->end,
- vme->protection & ~revokeperms);
- vm_map_simplify_entry(map, vme);
- }
- vm_map_lock_downgrade(map);
- }
- vm_map_unlock_read(map);
-}
-
-/*
- * When the subject's label changes, it may require revocation of privilege
- * to mapped objects. This can't be done on-the-fly later with a unified
- * buffer cache.
- */
-static void
-mac_relabel_cred(struct ucred *cred, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_cred, cred, newlabel);
-}
-
-void
-mac_relabel_vnode(struct ucred *cred, struct vnode *vp, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_vnode, cred, vp, &vp->v_label, newlabel);
-}
-
-void
-mac_create_ifnet(struct ifnet *ifnet)
-{
-
- MAC_PERFORM(create_ifnet, ifnet, &ifnet->if_label);
-}
-
-void
-mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(create_bpfdesc, cred, bpf_d, &bpf_d->bd_label);
-}
-
-void
-mac_create_socket(struct ucred *cred, struct socket *socket)
-{
-
- MAC_PERFORM(create_socket, cred, socket, &socket->so_label);
-}
-
-void
-mac_create_pipe(struct ucred *cred, struct pipe *pipe)
-{
-
- MAC_PERFORM(create_pipe, cred, pipe, pipe->pipe_label);
-}
-
-void
-mac_create_socket_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(create_socket_from_socket, oldsocket, &oldsocket->so_label,
- newsocket, &newsocket->so_label);
-}
-
-static void
-mac_relabel_socket(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_socket, cred, socket, &socket->so_label, newlabel);
-}
-
-static void
-mac_relabel_pipe(struct ucred *cred, struct pipe *pipe, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_pipe, cred, pipe, pipe->pipe_label, newlabel);
-}
-
-void
-mac_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct socket *socket)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(set_socket_peer_from_mbuf, mbuf, label, socket,
- &socket->so_peerlabel);
-}
-
-void
-mac_set_socket_peer_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(set_socket_peer_from_socket, oldsocket,
- &oldsocket->so_label, newsocket, &newsocket->so_peerlabel);
-}
-
-void
-mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram)
-{
- struct label *label;
-
- label = mbuf_to_label(datagram);
-
- MAC_PERFORM(create_datagram_from_ipq, ipq, &ipq->ipq_label,
- datagram, label);
-}
-
-void
-mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment)
-{
- struct label *datagramlabel, *fragmentlabel;
-
- datagramlabel = mbuf_to_label(datagram);
- fragmentlabel = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_fragment, datagram, datagramlabel, fragment,
- fragmentlabel);
-}
-
-void
-mac_create_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_mbuf(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_from_mbuf, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-void
-mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_bpfdesc, bpf_d, &bpf_d->bd_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_linklayer, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_ifnet, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf, struct ifnet *ifnet,
- struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_multicast_encap, oldmbuf, oldmbuflabel,
- ifnet, &ifnet->if_label, newmbuf, newmbuflabel);
-}
-
-void
-mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_netlayer, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-int
-mac_fragment_match(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
- int result;
-
- label = mbuf_to_label(fragment);
-
- result = 1;
- MAC_BOOLEAN(fragment_match, &&, fragment, label, ipq,
- &ipq->ipq_label);
-
- return (result);
-}
-
-void
-mac_update_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(update_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_socket(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_socket, socket, &socket->so_label, mbuf,
- label);
-}
-
-void
-mac_create_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-void
-mac_create_root_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_root_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-int
-mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet)
-{
- int error;
-
- if (!mac_enforce_network)
- return (0);
-
- MAC_CHECK(check_bpfdesc_receive, bpf_d, &bpf_d->bd_label, ifnet,
- &ifnet->if_label);
-
- return (error);
-}
-
-static int
-mac_check_cred_relabel(struct ucred *cred, struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_cred_relabel, cred, newlabel);
-
- return (error);
-}
-
-int
-mac_check_cred_visible(struct ucred *u1, struct ucred *u2)
-{
- int error;
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_cred_visible, u1, u2);
-
- return (error);
-}
-
-int
-mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- M_ASSERTPKTHDR(mbuf);
-
- if (!mac_enforce_network)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_ifnet_transmit, ifnet, &ifnet->if_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_kenv_dump(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_dump, cred);
-
- return (error);
-}
-
-int
-mac_check_kenv_get(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_get, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kenv_set(struct ucred *cred, char *name, char *value)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_set, cred, name, value);
-
- return (error);
-}
-
-int
-mac_check_kenv_unset(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_unset, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kld_load(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_kld_load");
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_load, cred, vp, &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_kld_stat(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_stat, cred);
-
- return (error);
-}
-
-int
-mac_check_kld_unload(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_unload, cred);
-
- return (error);
-}
-
-int
-mac_check_mount_stat(struct ucred *cred, struct mount *mount)
-{
- int error;
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_mount_stat, cred, mount, &mount->mnt_mntlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, unsigned long cmd,
- void *data)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_ioctl, cred, pipe, pipe->pipe_label, cmd, data);
-
- return (error);
-}
-
-int
-mac_check_pipe_poll(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_poll, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_read(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_read, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-static int
-mac_check_pipe_relabel(struct ucred *cred, struct pipe *pipe,
- struct label *newlabel)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_relabel, cred, pipe, pipe->pipe_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_stat(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_stat, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_write(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_write, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_proc_debug(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_debug, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_sched(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_sched, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_signal(struct ucred *cred, struct proc *proc, int signum)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_signal, cred, proc, signum);
-
- return (error);
-}
-
-int
-mac_check_socket_bind(struct ucred *ucred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_bind, ucred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_connect(struct ucred *cred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_connect, cred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_deliver(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_socket_deliver, socket, &socket->so_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_socket_listen(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_listen, cred, socket, &socket->so_label);
- return (error);
-}
-
-int
-mac_check_socket_receive(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_receive, cred, so, &so->so_label);
-
- return (error);
-}
-
-static int
-mac_check_socket_relabel(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_socket_relabel, cred, socket, &socket->so_label,
- newlabel);
-
- return (error);
-}
-
-int
-mac_check_socket_send(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_send, cred, so, &so->so_label);
-
- return (error);
-}
-
-int
-mac_check_socket_visible(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_visible, cred, socket, &socket->so_label);
-
- return (error);
-}
-
-int
-mac_check_sysarch_ioperm(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_sysarch_ioperm, cred);
- return (error);
-}
-
-int
-mac_check_system_acct(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- if (vp != NULL) {
- ASSERT_VOP_LOCKED(vp, "mac_check_system_acct");
- }
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_acct, cred, vp,
- vp != NULL ? &vp->v_label : NULL);
-
- return (error);
-}
-
-int
-mac_check_system_nfsd(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_nfsd, cred);
-
- return (error);
-}
-
-int
-mac_check_system_reboot(struct ucred *cred, int howto)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_reboot, cred, howto);
-
- return (error);
-}
-
-int
-mac_check_system_settime(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_settime, cred);
-
- return (error);
-}
-
-int
-mac_check_system_swapon(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapon");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapon, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_swapoff(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapoff");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapoff, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_sysctl(struct ucred *cred, int *name, u_int namelen,
- void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen)
-{
- int error;
-
- /*
- * XXXMAC: We're very much like to assert the SYSCTL_LOCK here,
- * but since it's not exported from kern_sysctl.c, we can't.
- */
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_sysctl, cred, name, namelen, old, oldlenp,
- inkernel, new, newlen);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_ifnet_label(&ifnet->if_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- struct label intlabel;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_ifnet_label(&intlabel);
- error = mac_internalize_ifnet_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- /*
- * XXX: Note that this is a redundant privilege check, since
- * policies impose this check themselves if required by the
- * policy. Eventually, this should go away.
- */
- error = suser_cred(cred, 0);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_CHECK(check_ifnet_relabel, cred, ifnet, &ifnet->if_label,
- &intlabel);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_PERFORM(relabel_ifnet, cred, ifnet, &ifnet->if_label, &intlabel);
-
- mac_destroy_ifnet_label(&intlabel);
- return (0);
-}
-
-void
-mac_create_devfs_device(struct mount *mp, dev_t dev, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_device, mp, dev, de, &de->de_label);
-}
-
-void
-mac_create_devfs_symlink(struct ucred *cred, struct mount *mp,
- struct devfs_dirent *dd, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_symlink, cred, mp, dd, &dd->de_label, de,
- &de->de_label);
-}
-
-void
-mac_create_devfs_directory(struct mount *mp, char *dirname, int dirnamelen,
- struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_directory, mp, dirname, dirnamelen, de,
- &de->de_label);
-}
-
-int
-mac_setsockopt_label_set(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- struct label intlabel;
- char *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, buffer, mac->m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_socket_label(&intlabel, M_WAITOK);
- error = mac_internalize_socket_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_check_socket_relabel(cred, so, &intlabel);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_relabel_socket(cred, so, &intlabel);
-
- mac_destroy_socket_label(&intlabel);
- return (0);
-}
-
-int
-mac_pipe_label_set(struct ucred *cred, struct pipe *pipe, struct label *label)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- error = mac_check_pipe_relabel(cred, pipe, label);
- if (error)
- return (error);
-
- mac_relabel_pipe(cred, pipe, label);
-
- return (0);
-}
-
-int
-mac_getsockopt_label_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *buffer, *elements;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_label(&so->so_label, elements,
- buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_getsockopt_peerlabel_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *elements, *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_peer_label(&so->so_peerlabel,
- elements, buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * Implementation of VOP_SETLABEL() that relies on extended attributes
- * to store label data. Can be referenced by filesystems supporting
- * extended attributes.
- */
-int
-vop_stdsetlabel_ea(struct vop_setlabel_args *ap)
-{
- struct vnode *vp = ap->a_vp;
- struct label *intlabel = ap->a_label;
- int error;
-
- ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea");
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- error = mac_setlabel_vnode_extattr(ap->a_cred, vp, intlabel);
- if (error)
- return (error);
-
- mac_relabel_vnode(ap->a_cred, vp, intlabel);
-
- return (0);
-}
-
-static int
-vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred)
-{
- int error;
-
- if (vp->v_mount == NULL) {
- /* printf("vn_setlabel: null v_mount\n"); */
- if (vp->v_type != VNON)
- printf("vn_setlabel: null v_mount with non-VNON\n");
- return (EBADF);
- }
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- /*
- * Multi-phase commit. First check the policies to confirm the
- * change is OK. Then commit via the filesystem. Finally,
- * update the actual vnode label. Question: maybe the filesystem
- * should update the vnode at the end as part of VOP_SETLABEL()?
- */
- error = mac_check_vnode_relabel(cred, vp, intlabel);
- if (error)
- return (error);
-
- /*
- * VADMIN provides the opportunity for the filesystem to make
- * decisions about who is and is not able to modify labels
- * and protections on files. This might not be right. We can't
- * assume VOP_SETLABEL() will do it, because we might implement
- * that as part of vop_stdsetlabel_ea().
- */
- error = VOP_ACCESS(vp, VADMIN, cred, curthread);
- if (error)
- return (error);
-
- error = VOP_SETLABEL(vp, intlabel, cred, curthread);
- if (error)
- return (error);
-
- return (0);
-}
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- struct proc *tproc;
- struct ucred *tcred;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- tproc = pfind(uap->pid);
- if (tproc == NULL)
- return (ESRCH);
-
- tcred = NULL; /* Satisfy gcc. */
- error = p_cansee(td, tproc);
- if (error == 0)
- tcred = crhold(tproc->p_ucred);
- PROC_UNLOCK(tproc);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&tcred->cr_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&td->td_ucred->cr_label,
- elements, buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
- struct ucred *newcred, *oldcred;
- struct label intlabel;
- struct proc *p;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(&intlabel);
- error = mac_internalize_cred_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(&intlabel);
- return (error);
- }
-
- newcred = crget();
-
- p = td->td_proc;
- PROC_LOCK(p);
- oldcred = p->p_ucred;
-
- error = mac_check_cred_relabel(oldcred, &intlabel);
- if (error) {
- PROC_UNLOCK(p);
- crfree(newcred);
- goto out;
- }
-
- setsugid(p);
- crcopy(newcred, oldcred);
- mac_relabel_cred(newcred, &intlabel);
- p->p_ucred = newcred;
-
- /*
- * Grab additional reference for use while revoking mmaps, prior
- * to releasing the proc lock and sharing the cred.
- */
- crhold(newcred);
- PROC_UNLOCK(p);
-
- if (mac_enforce_vm) {
- mtx_lock(&Giant);
- mac_cred_mmapped_drop_perms(td, newcred);
- mtx_unlock(&Giant);
- }
-
- crfree(newcred); /* Free revocation reference. */
- crfree(oldcred);
-
-out:
- mac_destroy_cred_label(&intlabel);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
- char *elements, *buffer;
- struct label intlabel;
- struct file *fp;
- struct mac mac;
- struct vnode *vp;
- struct pipe *pipe;
- short label_type;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- label_type = fp->f_type;
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- vp = fp->f_data;
-
- mac_init_vnode_label(&intlabel);
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- mac_copy_vnode_label(&vp->v_label, &intlabel);
- VOP_UNLOCK(vp, 0, td);
-
- break;
- case DTYPE_PIPE:
- pipe = fp->f_data;
-
- mac_init_pipe_label(&intlabel);
-
- PIPE_LOCK(pipe);
- mac_copy_pipe_label(pipe->pipe_label, &intlabel);
- PIPE_UNLOCK(pipe);
- break;
- default:
- error = EINVAL;
- fdrop(fp, td);
- goto out;
- }
- fdrop(fp, td);
-
- switch (label_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- if (error == 0)
- error = mac_externalize_vnode_label(&intlabel,
- elements, buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_vnode_label(&intlabel);
- break;
- case DTYPE_PIPE:
- error = mac_externalize_pipe_label(&intlabel, elements,
- buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_pipe_label(&intlabel);
- break;
- default:
- panic("__mac_get_fd: corrupted label_type");
- }
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
-
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
- struct label intlabel;
- struct pipe *pipe;
- struct file *fp;
- struct mount *mp;
- struct vnode *vp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vp = fp->f_data;
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error != 0) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- error = vn_setlabel(vp, &intlabel, td->td_ucred);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
-
- mac_destroy_vnode_label(&intlabel);
- break;
-
- case DTYPE_PIPE:
- mac_init_pipe_label(&intlabel);
- error = mac_internalize_pipe_label(&intlabel, buffer);
- if (error == 0) {
- pipe = fp->f_data;
- PIPE_LOCK(pipe);
- error = mac_pipe_label_set(td->td_ucred, pipe,
- &intlabel);
- PIPE_UNLOCK(pipe);
- }
-
- mac_destroy_pipe_label(&intlabel);
- break;
-
- default:
- error = EINVAL;
- }
-
- fdrop(fp, td);
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
- struct mac_policy_conf *mpc;
- char target[MAC_MAX_POLICY_NAME];
- int entrycount, error;
-
- error = copyinstr(uap->policy, target, sizeof(target), NULL);
- if (error)
- return (error);
-
- error = ENOSYS;
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- goto out;
- }
- }
-
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) {
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- break;
- }
- }
- mac_policy_list_unbusy();
- }
-out:
- return (error);
-}
-
-SYSINIT(mac, SI_SUB_MAC, SI_ORDER_FIRST, mac_init, NULL);
-SYSINIT(mac_late, SI_SUB_MAC_LATE, SI_ORDER_FIRST, mac_late_init, NULL);
-
-#else /* !MAC */
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
-
- return (ENOSYS);
-}
-
-#endif
diff --git a/sys/security/mac/mac_policy.h b/sys/security/mac/mac_policy.h
deleted file mode 100644
index 43884a077ee8..000000000000
--- a/sys/security/mac/mac_policy.h
+++ /dev/null
@@ -1,463 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * Copyright (c) 2001, 2002, 2003 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * This software was developed by Robert Watson for the TrustedBSD Project.
- *
- * This software was developed for the FreeBSD Project in part by Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
- * as part of the DARPA CHATS research program.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-/*
- * Kernel interface for MAC policy modules.
- */
-#ifndef _SYS_MAC_POLICY_H
-#define _SYS_MAC_POLICY_H
-
-/*-
- * Pluggable access control policy definition structure.
- *
- * List of operations that are performed as part of the implementation
- * of a MAC policy. Policy implementors declare operations with a
- * mac_policy_ops structure, and using the MAC_POLICY_SET() macro.
- * If an entry point is not declared, then then the policy will be ignored
- * during evaluation of that event or check.
- *
- * Operations are sorted first by general class of operation, then
- * alphabetically.
- */
-struct mac_policy_conf;
-struct mac_policy_ops {
- /*
- * Policy module operations.
- */
- void (*mpo_destroy)(struct mac_policy_conf *mpc);
- void (*mpo_init)(struct mac_policy_conf *mpc);
-
- /*
- * General policy-directed security system call so that policies
- * may implement new services without reserving explicit
- * system call numbers.
- */
- int (*mpo_syscall)(struct thread *td, int call, void *arg);
-
- /*
- * Label operations.
- */
- void (*mpo_init_bpfdesc_label)(struct label *label);
- void (*mpo_init_cred_label)(struct label *label);
- void (*mpo_init_devfsdirent_label)(struct label *label);
- void (*mpo_init_ifnet_label)(struct label *label);
- int (*mpo_init_ipq_label)(struct label *label, int flag);
- int (*mpo_init_mbuf_label)(struct label *label, int flag);
- void (*mpo_init_mount_label)(struct label *label);
- void (*mpo_init_mount_fs_label)(struct label *label);
- int (*mpo_init_socket_label)(struct label *label, int flag);
- int (*mpo_init_socket_peer_label)(struct label *label, int flag);
- void (*mpo_init_pipe_label)(struct label *label);
- void (*mpo_init_proc_label)(struct label *label);
- void (*mpo_init_vnode_label)(struct label *label);
- void (*mpo_destroy_bpfdesc_label)(struct label *label);
- void (*mpo_destroy_cred_label)(struct label *label);
- void (*mpo_destroy_devfsdirent_label)(struct label *label);
- void (*mpo_destroy_ifnet_label)(struct label *label);
- void (*mpo_destroy_ipq_label)(struct label *label);
- void (*mpo_destroy_mbuf_label)(struct label *label);
- void (*mpo_destroy_mount_label)(struct label *label);
- void (*mpo_destroy_mount_fs_label)(struct label *label);
- void (*mpo_destroy_socket_label)(struct label *label);
- void (*mpo_destroy_socket_peer_label)(struct label *label);
- void (*mpo_destroy_pipe_label)(struct label *label);
- void (*mpo_destroy_proc_label)(struct label *label);
- void (*mpo_destroy_vnode_label)(struct label *label);
- void (*mpo_copy_mbuf_label)(struct label *src,
- struct label *dest);
- void (*mpo_copy_pipe_label)(struct label *src,
- struct label *dest);
- void (*mpo_copy_vnode_label)(struct label *src,
- struct label *dest);
- int (*mpo_externalize_cred_label)(struct label *label,
- char *element_name, char *buffer, size_t buflen,
- size_t *len, int *claimed);
- int (*mpo_externalize_ifnet_label)(struct label *label,
- char *element_name, char *buffer, size_t buflen,
- size_t *len, int *claimed);
- int (*mpo_externalize_pipe_label)(struct label *label,
- char *element_name, char *buffer, size_t buflen,
- size_t *len, int *claimed);
- int (*mpo_externalize_socket_label)(struct label *label,
- char *element_name, char *buffer, size_t buflen,
- size_t *len, int *claimed);
- int (*mpo_externalize_socket_peer_label)(struct label *label,
- char *element_name, char *buffer, size_t buflen,
- size_t *len, int *claimed);
- int (*mpo_externalize_vnode_label)(struct label *label,
- char *element_name, char *buffer, size_t buflen,
- size_t *len, int *claimed);
- int (*mpo_internalize_cred_label)(struct label *label,
- char *element_name, char *element_data, int *claimed);
- int (*mpo_internalize_ifnet_label)(struct label *label,
- char *element_name, char *element_data, int *claimed);
- int (*mpo_internalize_pipe_label)(struct label *label,
- char *element_name, char *element_data, int *claimed);
- int (*mpo_internalize_socket_label)(struct label *label,
- char *element_name, char *element_data, int *claimed);
- int (*mpo_internalize_vnode_label)(struct label *label,
- char *element_name, char *element_data, int *claimed);
-
- /*
- * Labeling event operations: file system objects, and things that
- * look a lot like file system objects.
- */
- void (*mpo_associate_vnode_devfs)(struct mount *mp,
- struct label *fslabel, struct devfs_dirent *de,
- struct label *delabel, struct vnode *vp,
- struct label *vlabel);
- int (*mpo_associate_vnode_extattr)(struct mount *mp,
- struct label *fslabel, struct vnode *vp,
- struct label *vlabel);
- void (*mpo_associate_vnode_singlelabel)(struct mount *mp,
- struct label *fslabel, struct vnode *vp,
- struct label *vlabel);
- void (*mpo_create_devfs_device)(struct mount *mp, dev_t dev,
- struct devfs_dirent *de, struct label *label);
- void (*mpo_create_devfs_directory)(struct mount *mp, char *dirname,
- int dirnamelen, struct devfs_dirent *de,
- struct label *label);
- void (*mpo_create_devfs_symlink)(struct ucred *cred,
- struct mount *mp, struct devfs_dirent *dd,
- struct label *ddlabel, struct devfs_dirent *de,
- struct label *delabel);
- int (*mpo_create_vnode_extattr)(struct ucred *cred,
- struct mount *mp, struct label *fslabel,
- struct vnode *dvp, struct label *dlabel,
- struct vnode *vp, struct label *vlabel,
- struct componentname *cnp);
- void (*mpo_create_mount)(struct ucred *cred, struct mount *mp,
- struct label *mntlabel, struct label *fslabel);
- void (*mpo_create_root_mount)(struct ucred *cred, struct mount *mp,
- struct label *mountlabel, struct label *fslabel);
- void (*mpo_relabel_vnode)(struct ucred *cred, struct vnode *vp,
- struct label *vnodelabel, struct label *label);
- int (*mpo_setlabel_vnode_extattr)(struct ucred *cred,
- struct vnode *vp, struct label *vlabel,
- struct label *intlabel);
- void (*mpo_update_devfsdirent)(struct mount *mp,
- struct devfs_dirent *devfs_dirent,
- struct label *direntlabel, struct vnode *vp,
- struct label *vnodelabel);
-
- /*
- * Labeling event operations: IPC objects.
- */
- void (*mpo_create_mbuf_from_socket)(struct socket *so,
- struct label *socketlabel, struct mbuf *m,
- struct label *mbuflabel);
- void (*mpo_create_socket)(struct ucred *cred, struct socket *so,
- struct label *socketlabel);
- void (*mpo_create_socket_from_socket)(struct socket *oldsocket,
- struct label *oldsocketlabel, struct socket *newsocket,
- struct label *newsocketlabel);
- void (*mpo_relabel_socket)(struct ucred *cred, struct socket *so,
- struct label *oldlabel, struct label *newlabel);
- void (*mpo_relabel_pipe)(struct ucred *cred, struct pipe *pipe,
- struct label *oldlabel, struct label *newlabel);
- void (*mpo_set_socket_peer_from_mbuf)(struct mbuf *mbuf,
- struct label *mbuflabel, struct socket *so,
- struct label *socketpeerlabel);
- void (*mpo_set_socket_peer_from_socket)(struct socket *oldsocket,
- struct label *oldsocketlabel, struct socket *newsocket,
- struct label *newsocketpeerlabel);
- void (*mpo_create_pipe)(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel);
-
- /*
- * Labeling event operations: network objects.
- */
- void (*mpo_create_bpfdesc)(struct ucred *cred, struct bpf_d *bpf_d,
- struct label *bpflabel);
- void (*mpo_create_ifnet)(struct ifnet *ifnet,
- struct label *ifnetlabel);
- void (*mpo_create_ipq)(struct mbuf *fragment,
- struct label *fragmentlabel, struct ipq *ipq,
- struct label *ipqlabel);
- void (*mpo_create_datagram_from_ipq)
- (struct ipq *ipq, struct label *ipqlabel,
- struct mbuf *datagram, struct label *datagramlabel);
- void (*mpo_create_fragment)(struct mbuf *datagram,
- struct label *datagramlabel, struct mbuf *fragment,
- struct label *fragmentlabel);
- void (*mpo_create_mbuf_from_mbuf)(struct mbuf *oldmbuf,
- struct label *oldlabel, struct mbuf *newmbuf,
- struct label *newlabel);
- void (*mpo_create_mbuf_linklayer)(struct ifnet *ifnet,
- struct label *ifnetlabel, struct mbuf *mbuf,
- struct label *mbuflabel);
- void (*mpo_create_mbuf_from_bpfdesc)(struct bpf_d *bpf_d,
- struct label *bpflabel, struct mbuf *mbuf,
- struct label *mbuflabel);
- void (*mpo_create_mbuf_from_ifnet)(struct ifnet *ifnet,
- struct label *ifnetlabel, struct mbuf *mbuf,
- struct label *mbuflabel);
- void (*mpo_create_mbuf_multicast_encap)(struct mbuf *oldmbuf,
- struct label *oldmbuflabel, struct ifnet *ifnet,
- struct label *ifnetlabel, struct mbuf *newmbuf,
- struct label *newmbuflabel);
- void (*mpo_create_mbuf_netlayer)(struct mbuf *oldmbuf,
- struct label *oldmbuflabel, struct mbuf *newmbuf,
- struct label *newmbuflabel);
- int (*mpo_fragment_match)(struct mbuf *fragment,
- struct label *fragmentlabel, struct ipq *ipq,
- struct label *ipqlabel);
- void (*mpo_relabel_ifnet)(struct ucred *cred, struct ifnet *ifnet,
- struct label *ifnetlabel, struct label *newlabel);
- void (*mpo_update_ipq)(struct mbuf *fragment,
- struct label *fragmentlabel, struct ipq *ipq,
- struct label *ipqlabel);
-
- /*
- * Labeling event operations: processes.
- */
- void (*mpo_create_cred)(struct ucred *parent_cred,
- struct ucred *child_cred);
- void (*mpo_execve_transition)(struct ucred *old, struct ucred *new,
- struct vnode *vp, struct label *vnodelabel,
- struct label *interpvnodelabel,
- struct image_params *imgp, struct label *execlabel);
- int (*mpo_execve_will_transition)(struct ucred *old,
- struct vnode *vp, struct label *vnodelabel,
- struct label *interpvnodelabel,
- struct image_params *imgp, struct label *execlabel);
- void (*mpo_create_proc0)(struct ucred *cred);
- void (*mpo_create_proc1)(struct ucred *cred);
- void (*mpo_relabel_cred)(struct ucred *cred,
- struct label *newlabel);
- void (*mpo_thread_userret)(struct thread *thread);
-
- /*
- * Access control checks.
- */
- int (*mpo_check_bpfdesc_receive)(struct bpf_d *bpf_d,
- struct label *bpflabel, struct ifnet *ifnet,
- struct label *ifnetlabel);
- int (*mpo_check_cred_relabel)(struct ucred *cred,
- struct label *newlabel);
- int (*mpo_check_cred_visible)(struct ucred *u1, struct ucred *u2);
- int (*mpo_check_ifnet_relabel)(struct ucred *cred,
- struct ifnet *ifnet, struct label *ifnetlabel,
- struct label *newlabel);
- int (*mpo_check_ifnet_transmit)(struct ifnet *ifnet,
- struct label *ifnetlabel, struct mbuf *m,
- struct label *mbuflabel);
- int (*mpo_check_kenv_dump)(struct ucred *cred);
- int (*mpo_check_kenv_get)(struct ucred *cred, char *name);
- int (*mpo_check_kenv_set)(struct ucred *cred, char *name,
- char *value);
- int (*mpo_check_kenv_unset)(struct ucred *cred, char *name);
- int (*mpo_check_kld_load)(struct ucred *cred, struct vnode *vp,
- struct label *vlabel);
- int (*mpo_check_kld_stat)(struct ucred *cred);
- int (*mpo_check_kld_unload)(struct ucred *cred);
- int (*mpo_check_mount_stat)(struct ucred *cred, struct mount *mp,
- struct label *mntlabel);
- int (*mpo_check_pipe_ioctl)(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel, unsigned long cmd, void *data);
- int (*mpo_check_pipe_poll)(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel);
- int (*mpo_check_pipe_read)(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel);
- int (*mpo_check_pipe_relabel)(struct ucred *cred,
- struct pipe *pipe, struct label *pipelabel,
- struct label *newlabel);
- int (*mpo_check_pipe_stat)(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel);
- int (*mpo_check_pipe_write)(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel);
- int (*mpo_check_proc_debug)(struct ucred *cred,
- struct proc *proc);
- int (*mpo_check_proc_sched)(struct ucred *cred,
- struct proc *proc);
- int (*mpo_check_proc_signal)(struct ucred *cred,
- struct proc *proc, int signum);
- int (*mpo_check_socket_bind)(struct ucred *cred,
- struct socket *so, struct label *socketlabel,
- struct sockaddr *sockaddr);
- int (*mpo_check_socket_connect)(struct ucred *cred,
- struct socket *so, struct label *socketlabel,
- struct sockaddr *sockaddr);
- int (*mpo_check_socket_deliver)(struct socket *so,
- struct label *socketlabel, struct mbuf *m,
- struct label *mbuflabel);
- int (*mpo_check_socket_listen)(struct ucred *cred,
- struct socket *so, struct label *socketlabel);
- int (*mpo_check_socket_receive)(struct ucred *cred,
- struct socket *so, struct label *socketlabel);
- int (*mpo_check_socket_relabel)(struct ucred *cred,
- struct socket *so, struct label *socketlabel,
- struct label *newlabel);
- int (*mpo_check_socket_send)(struct ucred *cred,
- struct socket *so, struct label *socketlabel);
- int (*mpo_check_socket_visible)(struct ucred *cred,
- struct socket *so, struct label *socketlabel);
- int (*mpo_check_sysarch_ioperm)(struct ucred *cred);
- int (*mpo_check_system_acct)(struct ucred *cred,
- struct vnode *vp, struct label *vlabel);
- int (*mpo_check_system_nfsd)(struct ucred *cred);
- int (*mpo_check_system_reboot)(struct ucred *cred, int howto);
- int (*mpo_check_system_settime)(struct ucred *cred);
- int (*mpo_check_system_swapon)(struct ucred *cred,
- struct vnode *vp, struct label *label);
- int (*mpo_check_system_swapoff)(struct ucred *cred,
- struct vnode *vp, struct label *label);
- int (*mpo_check_system_sysctl)(struct ucred *cred, int *name,
- u_int namelen, void *old, size_t *oldlenp, int inkernel,
- void *new, size_t newlen);
- int (*mpo_check_vnode_access)(struct ucred *cred,
- struct vnode *vp, struct label *label, int acc_mode);
- int (*mpo_check_vnode_chdir)(struct ucred *cred,
- struct vnode *dvp, struct label *dlabel);
- int (*mpo_check_vnode_chroot)(struct ucred *cred,
- struct vnode *dvp, struct label *dlabel);
- int (*mpo_check_vnode_create)(struct ucred *cred,
- struct vnode *dvp, struct label *dlabel,
- struct componentname *cnp, struct vattr *vap);
- int (*mpo_check_vnode_delete)(struct ucred *cred,
- struct vnode *dvp, struct label *dlabel,
- struct vnode *vp, struct label *label,
- struct componentname *cnp);
- int (*mpo_check_vnode_deleteacl)(struct ucred *cred,
- struct vnode *vp, struct label *label, acl_type_t type);
- int (*mpo_check_vnode_exec)(struct ucred *cred, struct vnode *vp,
- struct label *label, struct image_params *imgp,
- struct label *execlabel);
- int (*mpo_check_vnode_getacl)(struct ucred *cred,
- struct vnode *vp, struct label *label, acl_type_t type);
- int (*mpo_check_vnode_getextattr)(struct ucred *cred,
- struct vnode *vp, struct label *label, int attrnamespace,
- const char *name, struct uio *uio);
- int (*mpo_check_vnode_link)(struct ucred *cred, struct vnode *dvp,
- struct label *dlabel, struct vnode *vp,
- struct label *label, struct componentname *cnp);
- int (*mpo_check_vnode_lookup)(struct ucred *cred,
- struct vnode *dvp, struct label *dlabel,
- struct componentname *cnp);
- int (*mpo_check_vnode_mmap)(struct ucred *cred, struct vnode *vp,
- struct label *label, int prot);
- void (*mpo_check_vnode_mmap_downgrade)(struct ucred *cred,
- struct vnode *vp, struct label *label, int *prot);
- int (*mpo_check_vnode_mprotect)(struct ucred *cred,
- struct vnode *vp, struct label *label, int prot);
- int (*mpo_check_vnode_open)(struct ucred *cred, struct vnode *vp,
- struct label *label, int acc_mode);
- int (*mpo_check_vnode_poll)(struct ucred *active_cred,
- struct ucred *file_cred, struct vnode *vp,
- struct label *label);
- int (*mpo_check_vnode_read)(struct ucred *active_cred,
- struct ucred *file_cred, struct vnode *vp,
- struct label *label);
- int (*mpo_check_vnode_readdir)(struct ucred *cred,
- struct vnode *dvp, struct label *dlabel);
- int (*mpo_check_vnode_readlink)(struct ucred *cred,
- struct vnode *vp, struct label *label);
- int (*mpo_check_vnode_relabel)(struct ucred *cred,
- struct vnode *vp, struct label *vnodelabel,
- struct label *newlabel);
- int (*mpo_check_vnode_rename_from)(struct ucred *cred,
- struct vnode *dvp, struct label *dlabel, struct vnode *vp,
- struct label *label, struct componentname *cnp);
- int (*mpo_check_vnode_rename_to)(struct ucred *cred,
- struct vnode *dvp, struct label *dlabel, struct vnode *vp,
- struct label *label, int samedir,
- struct componentname *cnp);
- int (*mpo_check_vnode_revoke)(struct ucred *cred,
- struct vnode *vp, struct label *label);
- int (*mpo_check_vnode_setacl)(struct ucred *cred,
- struct vnode *vp, struct label *label, acl_type_t type,
- struct acl *acl);
- int (*mpo_check_vnode_setextattr)(struct ucred *cred,
- struct vnode *vp, struct label *label, int attrnamespace,
- const char *name, struct uio *uio);
- int (*mpo_check_vnode_setflags)(struct ucred *cred,
- struct vnode *vp, struct label *label, u_long flags);
- int (*mpo_check_vnode_setmode)(struct ucred *cred,
- struct vnode *vp, struct label *label, mode_t mode);
- int (*mpo_check_vnode_setowner)(struct ucred *cred,
- struct vnode *vp, struct label *label, uid_t uid,
- gid_t gid);
- int (*mpo_check_vnode_setutimes)(struct ucred *cred,
- struct vnode *vp, struct label *label,
- struct timespec atime, struct timespec mtime);
- int (*mpo_check_vnode_stat)(struct ucred *active_cred,
- struct ucred *file_cred, struct vnode *vp,
- struct label *label);
- int (*mpo_check_vnode_write)(struct ucred *active_cred,
- struct ucred *file_cred, struct vnode *vp,
- struct label *label);
-};
-
-struct mac_policy_conf {
- char *mpc_name; /* policy name */
- char *mpc_fullname; /* policy full name */
- struct mac_policy_ops *mpc_ops; /* policy operations */
- int mpc_loadtime_flags; /* flags */
- int *mpc_field_off; /* security field */
- int mpc_runtime_flags; /* flags */
- LIST_ENTRY(mac_policy_conf) mpc_list; /* global list */
-};
-
-/* Flags for the mpc_loadtime_flags field. */
-#define MPC_LOADTIME_FLAG_NOTLATE 0x00000001
-#define MPC_LOADTIME_FLAG_UNLOADOK 0x00000002
-#define MPC_LOADTIME_FLAG_LABELMBUFS 0x00000004
-
-/* Flags for the mpc_runtime_flags field. */
-#define MPC_RUNTIME_FLAG_REGISTERED 0x00000001
-
-#define MAC_POLICY_SET(mpops, mpname, mpfullname, mpflags, privdata_wanted) \
- static struct mac_policy_conf mpname##_mac_policy_conf = { \
- #mpname, \
- mpfullname, \
- mpops, \
- mpflags, \
- privdata_wanted, \
- 0, \
- }; \
- static moduledata_t mpname##_mod = { \
- #mpname, \
- mac_policy_modevent, \
- &mpname##_mac_policy_conf \
- }; \
- MODULE_DEPEND(mpname, kernel_mac_support, 1, 1, 1); \
- DECLARE_MODULE(mpname, mpname##_mod, SI_SUB_MAC_POLICY, \
- SI_ORDER_MIDDLE)
-
-int mac_policy_modevent(module_t mod, int type, void *data);
-
-#define LABEL_TO_SLOT(l, s) (l)->l_perpolicy[s]
-
-#endif /* !_SYS_MAC_POLICY_H */
diff --git a/sys/security/mac/mac_process.c b/sys/security/mac/mac_process.c
deleted file mode 100644
index fb06edea3012..000000000000
--- a/sys/security/mac/mac_process.c
+++ /dev/null
@@ -1,3975 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * Copyright (c) 2001 Ilmar S. Habibulin
- * Copyright (c) 2001, 2002, 2003 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * This software was developed by Robert Watson and Ilmar Habibulin for the
- * TrustedBSD Project.
- *
- * This software was developed for the FreeBSD Project in part by Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
- * as part of the DARPA CHATS research program.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-/*
- * Developed by the TrustedBSD Project.
- *
- * Framework for extensible kernel access control. Kernel and userland
- * interface to the framework, policy registration and composition.
- */
-
-#include "opt_mac.h"
-#include "opt_devfs.h"
-
-#include <sys/param.h>
-#include <sys/condvar.h>
-#include <sys/extattr.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/mac.h>
-#include <sys/module.h>
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/sysent.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/file.h>
-#include <sys/namei.h>
-#include <sys/socket.h>
-#include <sys/pipe.h>
-#include <sys/socketvar.h>
-#include <sys/sysctl.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-
-#include <sys/mac_policy.h>
-
-#include <fs/devfs/devfs.h>
-
-#include <net/bpfdesc.h>
-#include <net/if.h>
-#include <net/if_var.h>
-
-#include <netinet/in.h>
-#include <netinet/ip_var.h>
-
-#ifdef MAC
-
-/*
- * Declare that the kernel provides MAC support, version 1. This permits
- * modules to refuse to be loaded if the necessary support isn't present,
- * even if it's pre-boot.
- */
-MODULE_VERSION(kernel_mac_support, 1);
-
-SYSCTL_DECL(_security);
-
-SYSCTL_NODE(_security, OID_AUTO, mac, CTLFLAG_RW, 0,
- "TrustedBSD MAC policy controls");
-
-#if MAC_MAX_SLOTS > 32
-#error "MAC_MAX_SLOTS too large"
-#endif
-
-static unsigned int mac_max_slots = MAC_MAX_SLOTS;
-static unsigned int mac_slot_offsets_free = (1 << MAC_MAX_SLOTS) - 1;
-SYSCTL_UINT(_security_mac, OID_AUTO, max_slots, CTLFLAG_RD,
- &mac_max_slots, 0, "");
-
-/*
- * Has the kernel started generating labeled objects yet? All read/write
- * access to this variable is serialized during the boot process. Following
- * the end of serialization, we don't update this flag; no locking.
- */
-static int mac_late = 0;
-
-/*
- * Warn about EA transactions only the first time they happen.
- * Weak coherency, no locking.
- */
-static int ea_warn_once = 0;
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
-/*
- * Flag to indicate whether or not we should allocate label storage for
- * new mbufs. Since most dynamic policies we currently work with don't
- * rely on mbuf labeling, try to avoid paying the cost of mtag allocation
- * unless specifically notified of interest. One result of this is
- * that if a dynamically loaded policy requests mbuf labels, it must
- * be able to deal with a NULL label being returned on any mbufs that
- * were already in flight when the policy was loaded. Since the policy
- * already has to deal with uninitialized labels, this probably won't
- * be a problem. Note: currently no locking. Will this be a problem?
- */
-static int mac_labelmbufs = 0;
-#endif
-
-static int mac_enforce_fs = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_fs, CTLFLAG_RW,
- &mac_enforce_fs, 0, "Enforce MAC policy on file system objects");
-TUNABLE_INT("security.mac.enforce_fs", &mac_enforce_fs);
-
-static int mac_enforce_kld = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_kld, CTLFLAG_RW,
- &mac_enforce_kld, 0, "Enforce MAC policy on kld operations");
-TUNABLE_INT("security.mac.enforce_kld", &mac_enforce_kld);
-
-static int mac_enforce_network = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_network, CTLFLAG_RW,
- &mac_enforce_network, 0, "Enforce MAC policy on network packets");
-TUNABLE_INT("security.mac.enforce_network", &mac_enforce_network);
-
-static int mac_enforce_pipe = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_pipe, CTLFLAG_RW,
- &mac_enforce_pipe, 0, "Enforce MAC policy on pipe operations");
-TUNABLE_INT("security.mac.enforce_pipe", &mac_enforce_pipe);
-
-static int mac_enforce_process = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_process, CTLFLAG_RW,
- &mac_enforce_process, 0, "Enforce MAC policy on inter-process operations");
-TUNABLE_INT("security.mac.enforce_process", &mac_enforce_process);
-
-static int mac_enforce_socket = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_socket, CTLFLAG_RW,
- &mac_enforce_socket, 0, "Enforce MAC policy on socket operations");
-TUNABLE_INT("security.mac.enforce_socket", &mac_enforce_socket);
-
-static int mac_enforce_system = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_system, CTLFLAG_RW,
- &mac_enforce_system, 0, "Enforce MAC policy on system operations");
-TUNABLE_INT("security.mac.enforce_system", &mac_enforce_system);
-
-static int mac_enforce_vm = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_vm, CTLFLAG_RW,
- &mac_enforce_vm, 0, "Enforce MAC policy on vm operations");
-TUNABLE_INT("security.mac.enforce_vm", &mac_enforce_vm);
-
-static int mac_mmap_revocation = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation, CTLFLAG_RW,
- &mac_mmap_revocation, 0, "Revoke mmap access to files on subject "
- "relabel");
-static int mac_mmap_revocation_via_cow = 0;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation_via_cow, CTLFLAG_RW,
- &mac_mmap_revocation_via_cow, 0, "Revoke mmap access to files via "
- "copy-on-write semantics, or by removing all write access");
-
-#ifdef MAC_DEBUG
-SYSCTL_NODE(_security_mac, OID_AUTO, debug, CTLFLAG_RW, 0,
- "TrustedBSD MAC debug info");
-
-static int mac_debug_label_fallback = 0;
-SYSCTL_INT(_security_mac_debug, OID_AUTO, label_fallback, CTLFLAG_RW,
- &mac_debug_label_fallback, 0, "Filesystems should fall back to fs label"
- "when label is corrupted.");
-TUNABLE_INT("security.mac.debug_label_fallback",
- &mac_debug_label_fallback);
-
-SYSCTL_NODE(_security_mac_debug, OID_AUTO, counters, CTLFLAG_RW, 0,
- "TrustedBSD MAC object counters");
-
-static unsigned int nmacmbufs, nmaccreds, nmacifnets, nmacbpfdescs,
- nmacsockets, nmacmounts, nmactemp, nmacvnodes, nmacdevfsdirents,
- nmacipqs, nmacpipes, nmacprocs;
-
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mbufs, CTLFLAG_RD,
- &nmacmbufs, 0, "number of mbufs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, creds, CTLFLAG_RD,
- &nmaccreds, 0, "number of ucreds in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ifnets, CTLFLAG_RD,
- &nmacifnets, 0, "number of ifnets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ipqs, CTLFLAG_RD,
- &nmacipqs, 0, "number of ipqs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, bpfdescs, CTLFLAG_RD,
- &nmacbpfdescs, 0, "number of bpfdescs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, sockets, CTLFLAG_RD,
- &nmacsockets, 0, "number of sockets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, pipes, CTLFLAG_RD,
- &nmacpipes, 0, "number of pipes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, procs, CTLFLAG_RD,
- &nmacprocs, 0, "number of procs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mounts, CTLFLAG_RD,
- &nmacmounts, 0, "number of mounts in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, temp, CTLFLAG_RD,
- &nmactemp, 0, "number of temporary labels in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, vnodes, CTLFLAG_RD,
- &nmacvnodes, 0, "number of vnodes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, devfsdirents, CTLFLAG_RD,
- &nmacdevfsdirents, 0, "number of devfs dirents inuse");
-#endif
-
-static int error_select(int error1, int error2);
-static int mac_policy_register(struct mac_policy_conf *mpc);
-static int mac_policy_unregister(struct mac_policy_conf *mpc);
-
-static void mac_check_vnode_mmap_downgrade(struct ucred *cred,
- struct vnode *vp, int *prot);
-static void mac_cred_mmapped_drop_perms_recurse(struct thread *td,
- struct ucred *cred, struct vm_map *map);
-
-static void mac_destroy_socket_label(struct label *label);
-
-static int mac_setlabel_vnode_extattr(struct ucred *cred,
- struct vnode *vp, struct label *intlabel);
-
-MALLOC_DEFINE(M_MACPIPELABEL, "macpipelabel", "MAC labels for pipes");
-MALLOC_DEFINE(M_MACTEMP, "mactemp", "MAC temporary label storage");
-
-/*
- * mac_static_policy_list holds a list of policy modules that are not
- * loaded while the system is "live", and cannot be unloaded. These
- * policies can be invoked without holding the busy count.
- *
- * mac_policy_list stores the list of dynamic policies. A busy count is
- * maintained for the list, stored in mac_policy_busy. The busy count
- * is protected by mac_policy_mtx; the list may be modified only
- * while the busy count is 0, requiring that the lock be held to
- * prevent new references to the list from being acquired. For almost
- * all operations, incrementing the busy count is sufficient to
- * guarantee consistency, as the list cannot be modified while the
- * busy count is elevated. For a few special operations involving a
- * change to the list of active policies, the mtx itself must be held.
- * A condition variable, mac_policy_cv, is used to signal potential
- * exclusive consumers that they should try to acquire the lock if a
- * first attempt at exclusive access fails.
- */
-static struct mtx mac_policy_mtx;
-static struct cv mac_policy_cv;
-static int mac_policy_count;
-static LIST_HEAD(, mac_policy_conf) mac_policy_list;
-static LIST_HEAD(, mac_policy_conf) mac_static_policy_list;
-
-/*
- * We manually invoke WITNESS_WARN() to allow Witness to generate
- * warnings even if we don't end up ever triggering the wait at
- * run-time. The consumer of the exclusive interface must not hold
- * any locks (other than potentially Giant) since we may sleep for
- * long (potentially indefinite) periods of time waiting for the
- * framework to become quiescent so that a policy list change may
- * be made.
- */
-static __inline void
-mac_policy_grab_exclusive(void)
-{
- WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
- "mac_policy_grab_exclusive() at %s:%d", __FILE__, __LINE__);
- mtx_lock(&mac_policy_mtx);
- while (mac_policy_count != 0)
- cv_wait(&mac_policy_cv, &mac_policy_mtx);
-}
-
-static __inline void
-mac_policy_assert_exclusive(void)
-{
- mtx_assert(&mac_policy_mtx, MA_OWNED);
- KASSERT(mac_policy_count == 0,
- ("mac_policy_assert_exclusive(): not exclusive"));
-}
-
-static __inline void
-mac_policy_release_exclusive(void)
-{
-
- KASSERT(mac_policy_count == 0,
- ("mac_policy_release_exclusive(): not exclusive"));
- mtx_unlock(&mac_policy_mtx);
- cv_signal(&mac_policy_cv);
-}
-
-static __inline void
-mac_policy_list_busy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count++;
- mtx_unlock(&mac_policy_mtx);
-}
-
-static __inline int
-mac_policy_list_conditional_busy(void)
-{
- int ret;
-
- mtx_lock(&mac_policy_mtx);
- if (!LIST_EMPTY(&mac_policy_list)) {
- mac_policy_count++;
- ret = 1;
- } else
- ret = 0;
- mtx_unlock(&mac_policy_mtx);
- return (ret);
-}
-
-static __inline void
-mac_policy_list_unbusy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count--;
- KASSERT(mac_policy_count >= 0, ("MAC_POLICY_LIST_LOCK"));
- if (mac_policy_count == 0)
- cv_signal(&mac_policy_cv);
- mtx_unlock(&mac_policy_mtx);
-}
-
-/*
- * MAC_CHECK performs the designated check by walking the policy
- * module list and checking with each as to how it feels about the
- * request. Note that it returns its value via 'error' in the scope
- * of the caller.
- */
-#define MAC_CHECK(check, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- error = 0; \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * MAC_BOOLEAN performs the designated boolean composition by walking
- * the module list, invoking each instance of the operation, and
- * combining the results using the passed C operator. Note that it
- * returns its value via 'result' in the scope of the caller, which
- * should be initialized by the caller in a meaningful way to get
- * a meaningful result.
- */
-#define MAC_BOOLEAN(operation, composition, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation \
- (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-#define MAC_EXTERNALIZE(type, label, elementlist, outbuf, \
- outbuflen) do { \
- char *curptr, *curptr_start, *element_name, *element_temp; \
- size_t left, left_start, len; \
- int claimed, first, first_start, ignorenotfound; \
- \
- error = 0; \
- element_temp = elementlist; \
- curptr = outbuf; \
- curptr[0] = '\0'; \
- left = outbuflen; \
- first = 1; \
- while ((element_name = strsep(&element_temp, ",")) != NULL) { \
- curptr_start = curptr; \
- left_start = left; \
- first_start = first; \
- if (element_name[0] == '?') { \
- element_name++; \
- ignorenotfound = 1; \
- } else \
- ignorenotfound = 0; \
- claimed = 0; \
- if (first) { \
- len = snprintf(curptr, left, "%s/", \
- element_name); \
- first = 0; \
- } else \
- len = snprintf(curptr, left, ",%s/", \
- element_name); \
- if (len >= left) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- \
- MAC_CHECK(externalize_ ## type, label, element_name, \
- curptr, left, &len, &claimed); \
- if (error) \
- break; \
- if (claimed == 1) { \
- if (len >= outbuflen) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- } else if (claimed == 0 && ignorenotfound) { \
- /* \
- * Revert addition of the label element \
- * name. \
- */ \
- curptr = curptr_start; \
- *curptr = '\0'; \
- left = left_start; \
- first = first_start; \
- } else { \
- error = EINVAL; /* XXXMAC: ENOLABEL */ \
- break; \
- } \
- } \
-} while (0)
-
-#define MAC_INTERNALIZE(type, label, instring) do { \
- char *element, *element_name, *element_data; \
- int claimed; \
- \
- error = 0; \
- element = instring; \
- while ((element_name = strsep(&element, ",")) != NULL) { \
- element_data = element_name; \
- element_name = strsep(&element_data, "/"); \
- if (element_data == NULL) { \
- error = EINVAL; \
- break; \
- } \
- claimed = 0; \
- MAC_CHECK(internalize_ ## type, label, element_name, \
- element_data, &claimed); \
- if (error) \
- break; \
- if (claimed != 1) { \
- /* XXXMAC: Another error here? */ \
- error = EINVAL; \
- break; \
- } \
- } \
-} while (0)
-
-/*
- * MAC_PERFORM performs the designated operation by walking the policy
- * module list and invoking that operation for each policy.
- */
-#define MAC_PERFORM(operation, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * Initialize the MAC subsystem, including appropriate SMP locks.
- */
-static void
-mac_init(void)
-{
-
- LIST_INIT(&mac_static_policy_list);
- LIST_INIT(&mac_policy_list);
-
- mtx_init(&mac_policy_mtx, "mac_policy_mtx", NULL, MTX_DEF);
- cv_init(&mac_policy_cv, "mac_policy_cv");
-}
-
-/*
- * For the purposes of modules that want to know if they were loaded
- * "early", set the mac_late flag once we've processed modules either
- * linked into the kernel, or loaded before the kernel startup.
- */
-static void
-mac_late_init(void)
-{
-
- mac_late = 1;
-}
-
-/*
- * After the policy list has changed, walk the list to update any global
- * flags.
- */
-static void
-mac_policy_updateflags(void)
-{
- struct mac_policy_conf *tmpc;
-#ifndef MAC_ALWAYS_LABEL_MBUF
- int labelmbufs;
-#endif
-
- mac_policy_assert_exclusive();
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- labelmbufs = 0;
-#endif
-
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- mac_labelmbufs = (labelmbufs != 0);
-#endif
-}
-
-/*
- * Allow MAC policy modules to register during boot, etc.
- */
-int
-mac_policy_modevent(module_t mod, int type, void *data)
-{
- struct mac_policy_conf *mpc;
- int error;
-
- error = 0;
- mpc = (struct mac_policy_conf *) data;
-
- switch (type) {
- case MOD_LOAD:
- if (mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_NOTLATE &&
- mac_late) {
- printf("mac_policy_modevent: can't load %s policy "
- "after booting\n", mpc->mpc_name);
- error = EBUSY;
- break;
- }
- error = mac_policy_register(mpc);
- break;
- case MOD_UNLOAD:
- /* Don't unregister the module if it was never registered. */
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED)
- != 0)
- error = mac_policy_unregister(mpc);
- else
- error = 0;
- break;
- default:
- break;
- }
-
- return (error);
-}
-
-static int
-mac_policy_register(struct mac_policy_conf *mpc)
-{
- struct mac_policy_conf *tmpc;
- int error, slot, static_entry;
-
- error = 0;
-
- /*
- * We don't technically need exclusive access while !mac_late,
- * but hold it for assertion consistency.
- */
- mac_policy_grab_exclusive();
-
- /*
- * If the module can potentially be unloaded, or we're loading
- * late, we have to stick it in the non-static list and pay
- * an extra performance overhead. Otherwise, we can pay a
- * light locking cost and stick it in the static list.
- */
- static_entry = (!mac_late &&
- !(mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK));
-
- if (static_entry) {
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- } else {
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- }
- if (mpc->mpc_field_off != NULL) {
- slot = ffs(mac_slot_offsets_free);
- if (slot == 0) {
- error = ENOMEM;
- goto out;
- }
- slot--;
- mac_slot_offsets_free &= ~(1 << slot);
- *mpc->mpc_field_off = slot;
- }
- mpc->mpc_runtime_flags |= MPC_RUNTIME_FLAG_REGISTERED;
-
- /*
- * If we're loading a MAC module after the framework has
- * initialized, it has to go into the dynamic list. If
- * we're loading it before we've finished initializing,
- * it can go into the static list with weaker locker
- * requirements.
- */
- if (static_entry)
- LIST_INSERT_HEAD(&mac_static_policy_list, mpc, mpc_list);
- else
- LIST_INSERT_HEAD(&mac_policy_list, mpc, mpc_list);
-
- /* Per-policy initialization. */
- if (mpc->mpc_ops->mpo_init != NULL)
- (*(mpc->mpc_ops->mpo_init))(mpc);
- mac_policy_updateflags();
-
- printf("Security policy loaded: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
-out:
- mac_policy_release_exclusive();
- return (error);
-}
-
-static int
-mac_policy_unregister(struct mac_policy_conf *mpc)
-{
-
- /*
- * If we fail the load, we may get a request to unload. Check
- * to see if we did the run-time registration, and if not,
- * silently succeed.
- */
- mac_policy_grab_exclusive();
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED) == 0) {
- mac_policy_release_exclusive();
- return (0);
- }
-#if 0
- /*
- * Don't allow unloading modules with private data.
- */
- if (mpc->mpc_field_off != NULL) {
- MAC_POLICY_LIST_UNLOCK();
- return (EBUSY);
- }
-#endif
- /*
- * Only allow the unload to proceed if the module is unloadable
- * by its own definition.
- */
- if ((mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK) == 0) {
- mac_policy_release_exclusive();
- return (EBUSY);
- }
- if (mpc->mpc_ops->mpo_destroy != NULL)
- (*(mpc->mpc_ops->mpo_destroy))(mpc);
-
- LIST_REMOVE(mpc, mpc_list);
- mpc->mpc_runtime_flags &= ~MPC_RUNTIME_FLAG_REGISTERED;
- mac_policy_updateflags();
-
- mac_policy_release_exclusive();
-
- printf("Security policy unload: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
- return (0);
-}
-
-/*
- * Define an error value precedence, and given two arguments, selects the
- * value with the higher precedence.
- */
-static int
-error_select(int error1, int error2)
-{
-
- /* Certain decision-making errors take top priority. */
- if (error1 == EDEADLK || error2 == EDEADLK)
- return (EDEADLK);
-
- /* Invalid arguments should be reported where possible. */
- if (error1 == EINVAL || error2 == EINVAL)
- return (EINVAL);
-
- /* Precedence goes to "visibility", with both process and file. */
- if (error1 == ESRCH || error2 == ESRCH)
- return (ESRCH);
-
- if (error1 == ENOENT || error2 == ENOENT)
- return (ENOENT);
-
- /* Precedence goes to DAC/MAC protections. */
- if (error1 == EACCES || error2 == EACCES)
- return (EACCES);
-
- /* Precedence goes to privilege. */
- if (error1 == EPERM || error2 == EPERM)
- return (EPERM);
-
- /* Precedence goes to error over success; otherwise, arbitrary. */
- if (error1 != 0)
- return (error1);
- return (error2);
-}
-
-static struct label *
-mbuf_to_label(struct mbuf *mbuf)
-{
- struct m_tag *tag;
- struct label *label;
-
- tag = m_tag_find(mbuf, PACKET_TAG_MACLABEL, NULL);
- label = (struct label *)(tag+1);
-
- return (label);
-}
-
-static void
-mac_init_label(struct label *label)
-{
-
- bzero(label, sizeof(*label));
- label->l_flags = MAC_FLAG_INITIALIZED;
-}
-
-static void
-mac_destroy_label(struct label *label)
-{
-
- KASSERT(label->l_flags & MAC_FLAG_INITIALIZED,
- ("destroying uninitialized label"));
-
- bzero(label, sizeof(*label));
- /* implicit: label->l_flags &= ~MAC_FLAG_INITIALIZED; */
-}
-
-void
-mac_init_bpfdesc(struct bpf_d *bpf_d)
-{
-
- mac_init_label(&bpf_d->bd_label);
- MAC_PERFORM(init_bpfdesc_label, &bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_init_cred_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_cred_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_init_cred(struct ucred *cred)
-{
-
- mac_init_cred_label(&cred->cr_label);
-}
-
-void
-mac_init_devfsdirent(struct devfs_dirent *de)
-{
-
- mac_init_label(&de->de_label);
- MAC_PERFORM(init_devfsdirent_label, &de->de_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_init_ifnet_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_ifnet_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_init_ifnet(struct ifnet *ifp)
-{
-
- mac_init_ifnet_label(&ifp->if_label);
-}
-
-int
-mac_init_ipq(struct ipq *ipq, int flag)
-{
- int error;
-
- mac_init_label(&ipq->ipq_label);
-
- MAC_CHECK(init_ipq_label, &ipq->ipq_label, flag);
- if (error) {
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacipqs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf_tag(struct m_tag *tag, int flag)
-{
- struct label *label;
- int error;
-
- label = (struct label *) (tag + 1);
- mac_init_label(label);
-
- MAC_CHECK(init_mbuf_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacmbufs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf(struct mbuf *m, int flag)
-{
- struct m_tag *tag;
- int error;
-
- M_ASSERTPKTHDR(m);
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- /*
- * Don't reserve space for labels on mbufs unless we have a policy
- * that uses the labels.
- */
- if (mac_labelmbufs) {
-#endif
- tag = m_tag_get(PACKET_TAG_MACLABEL, sizeof(struct label),
- flag);
- if (tag == NULL)
- return (ENOMEM);
- error = mac_init_mbuf_tag(tag, flag);
- if (error) {
- m_tag_free(tag);
- return (error);
- }
- m_tag_prepend(m, tag);
-#ifndef MAC_ALWAYS_LABEL_MBUF
- }
-#endif
- return (0);
-}
-
-void
-mac_init_mount(struct mount *mp)
-{
-
- mac_init_label(&mp->mnt_mntlabel);
- mac_init_label(&mp->mnt_fslabel);
- MAC_PERFORM(init_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(init_mount_fs_label, &mp->mnt_fslabel);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_init_pipe_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_pipe_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_init_pipe(struct pipe *pipe)
-{
- struct label *label;
-
- label = malloc(sizeof(struct label), M_MACPIPELABEL, M_ZERO|M_WAITOK);
- pipe->pipe_label = label;
- pipe->pipe_peer->pipe_label = label;
- mac_init_pipe_label(label);
-}
-
-void
-mac_init_proc(struct proc *p)
-{
-
- mac_init_label(&p->p_label);
- MAC_PERFORM(init_proc_label, &p->p_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacprocs, 1);
-#endif
-}
-
-static int
-mac_init_socket_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacsockets, 1);
-#endif
-
- return (error);
-}
-
-static int
-mac_init_socket_peer_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_peer_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
- return (error);
-}
-
-int
-mac_init_socket(struct socket *socket, int flag)
-{
- int error;
-
- error = mac_init_socket_label(&socket->so_label, flag);
- if (error)
- return (error);
-
- error = mac_init_socket_peer_label(&socket->so_peerlabel, flag);
- if (error)
- mac_destroy_socket_label(&socket->so_label);
-
- return (error);
-}
-
-void
-mac_init_vnode_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_vnode_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_init_vnode(struct vnode *vp)
-{
-
- mac_init_vnode_label(&vp->v_label);
-}
-
-void
-mac_destroy_bpfdesc(struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(destroy_bpfdesc_label, &bpf_d->bd_label);
- mac_destroy_label(&bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_destroy_cred_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_cred_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_destroy_cred(struct ucred *cred)
-{
-
- mac_destroy_cred_label(&cred->cr_label);
-}
-
-void
-mac_destroy_devfsdirent(struct devfs_dirent *de)
-{
-
- MAC_PERFORM(destroy_devfsdirent_label, &de->de_label);
- mac_destroy_label(&de->de_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_destroy_ifnet_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_ifnet_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_destroy_ifnet(struct ifnet *ifp)
-{
-
- mac_destroy_ifnet_label(&ifp->if_label);
-}
-
-void
-mac_destroy_ipq(struct ipq *ipq)
-{
-
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacipqs, 1);
-#endif
-}
-
-void
-mac_destroy_mbuf_tag(struct m_tag *tag)
-{
- struct label *label;
-
- label = (struct label *)(tag+1);
-
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmbufs, 1);
-#endif
-}
-
-void
-mac_destroy_mount(struct mount *mp)
-{
-
- MAC_PERFORM(destroy_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(destroy_mount_fs_label, &mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_mntlabel);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_destroy_pipe_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_pipe_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_destroy_pipe(struct pipe *pipe)
-{
-
- mac_destroy_pipe_label(pipe->pipe_label);
- free(pipe->pipe_label, M_MACPIPELABEL);
-}
-
-void
-mac_destroy_proc(struct proc *p)
-{
-
- MAC_PERFORM(destroy_proc_label, &p->p_label);
- mac_destroy_label(&p->p_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacprocs, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacsockets, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_peer_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_peer_label, label);
- mac_destroy_label(label);
-}
-
-void
-mac_destroy_socket(struct socket *socket)
-{
-
- mac_destroy_socket_label(&socket->so_label);
- mac_destroy_socket_peer_label(&socket->so_peerlabel);
-}
-
-void
-mac_destroy_vnode_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_vnode_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_destroy_vnode(struct vnode *vp)
-{
-
- mac_destroy_vnode_label(&vp->v_label);
-}
-
-void
-mac_copy_mbuf_tag(struct m_tag *src, struct m_tag *dest)
-{
- struct label *src_label, *dest_label;
-
- src_label = (struct label *)(src+1);
- dest_label = (struct label *)(dest+1);
-
- /*
- * mac_init_mbuf_tag() is called on the target tag in
- * m_tag_copy(), so we don't need to call it here.
- */
- MAC_PERFORM(copy_mbuf_label, src_label, dest_label);
-}
-
-static void
-mac_copy_pipe_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_pipe_label, src, dest);
-}
-
-void
-mac_copy_vnode_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_vnode_label, src, dest);
-}
-
-static int
-mac_check_structmac_consistent(struct mac *mac)
-{
-
- if (mac->m_buflen > MAC_MAX_LABEL_BUF_LEN)
- return (EINVAL);
-
- return (0);
-}
-
-static int
-mac_externalize_cred_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(cred_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_ifnet_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(ifnet_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_pipe_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(pipe_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_peer_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_peer_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_vnode_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(vnode_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_internalize_cred_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(cred_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_ifnet_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(ifnet_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_pipe_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(pipe_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_socket_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(socket_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_vnode_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(vnode_label, label, string);
-
- return (error);
-}
-
-/*
- * Initialize MAC label for the first kernel process, from which other
- * kernel processes and threads are spawned.
- */
-void
-mac_create_proc0(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc0, cred);
-}
-
-/*
- * Initialize MAC label for the first userland process, from which other
- * userland processes and threads are spawned.
- */
-void
-mac_create_proc1(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc1, cred);
-}
-
-void
-mac_thread_userret(struct thread *td)
-{
-
- MAC_PERFORM(thread_userret, td);
-}
-
-/*
- * When a new process is created, its label must be initialized. Generally,
- * this involves inheritence from the parent process, modulo possible
- * deltas. This function allows that processing to take place.
- */
-void
-mac_create_cred(struct ucred *parent_cred, struct ucred *child_cred)
-{
-
- MAC_PERFORM(create_cred, parent_cred, child_cred);
-}
-
-void
-mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(update_devfsdirent, mp, de, &de->de_label, vp,
- &vp->v_label);
-}
-
-void
-mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_devfs, mp, &mp->mnt_fslabel, de,
- &de->de_label, vp, &vp->v_label);
-}
-
-int
-mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_associate_vnode_extattr");
-
- MAC_CHECK(associate_vnode_extattr, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-
- return (error);
-}
-
-void
-mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_singlelabel, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-}
-
-int
-mac_create_vnode_extattr(struct ucred *cred, struct mount *mp,
- struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_create_vnode_extattr");
- ASSERT_VOP_LOCKED(vp, "mac_create_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(create_vnode_extattr, cred, mp, &mp->mnt_fslabel,
- dvp, &dvp->v_label, vp, &vp->v_label, cnp);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-static int
-mac_setlabel_vnode_extattr(struct ucred *cred, struct vnode *vp,
- struct label *intlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_setlabel_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(setlabel_vnode_extattr, cred, vp, &vp->v_label, intlabel);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-int
-mac_execve_enter(struct image_params *imgp, struct mac *mac_p,
- struct label *execlabelstorage)
-{
- struct mac mac;
- char *buffer;
- int error;
-
- if (mac_p == NULL)
- return (0);
-
- error = copyin(mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(execlabelstorage);
- error = mac_internalize_cred_label(execlabelstorage, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(execlabelstorage);
- return (error);
- }
- imgp->execlabel = execlabelstorage;
- return (0);
-}
-
-void
-mac_execve_exit(struct image_params *imgp)
-{
- if (imgp->execlabel != NULL)
- mac_destroy_cred_label(imgp->execlabel);
-}
-
-void
-mac_execve_transition(struct ucred *old, struct ucred *new, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return;
-
- MAC_PERFORM(execve_transition, old, new, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-}
-
-int
-mac_execve_will_transition(struct ucred *old, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
- int result;
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_will_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- result = 0;
- MAC_BOOLEAN(execve_will_transition, ||, old, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-
- return (result);
-}
-
-int
-mac_check_vnode_access(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_access");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_access, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chroot");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chroot, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_create(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp, struct vattr *vap)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_create");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_create, cred, dvp, &dvp->v_label, cnp, vap);
- return (error);
-}
-
-int
-mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp, struct vnode *vp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_delete");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_delete");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_delete, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
- acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_deleteacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_deleteacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_exec(struct ucred *cred, struct vnode *vp,
- struct image_params *imgp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_exec");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_exec, cred, vp, &vp->v_label, imgp,
- imgp->execlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp, acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_link(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_link");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_link");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_link, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_lookup");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_lookup, cred, dvp, &dvp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mmap, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-void
-mac_check_vnode_mmap_downgrade(struct ucred *cred, struct vnode *vp, int *prot)
-{
- int result = *prot;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap_downgrade");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return;
-
- MAC_PERFORM(check_vnode_mmap_downgrade, cred, vp, &vp->v_label,
- &result);
-
- *prot = result;
-}
-
-int
-mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mprotect");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mprotect, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-int
-mac_check_vnode_open(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_open");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_open, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_poll");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_poll, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_read");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_read, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_readdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_readdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_readlink");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readlink, cred, vp, &vp->v_label);
- return (error);
-}
-
-static int
-mac_check_vnode_relabel(struct ucred *cred, struct vnode *vp,
- struct label *newlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_relabel");
-
- MAC_CHECK(check_vnode_relabel, cred, vp, &vp->v_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_from");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_from");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_from, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, int samedir, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_to");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_to");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_to, cred, dvp, &dvp->v_label, vp,
- vp != NULL ? &vp->v_label : NULL, samedir, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_revoke");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_revoke, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type,
- struct acl *acl)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setacl, cred, vp, &vp->v_label, type, acl);
- return (error);
-}
-
-int
-mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp, u_long flags)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setflags");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setflags, cred, vp, &vp->v_label, flags);
- return (error);
-}
-
-int
-mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp, mode_t mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setmode");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setmode, cred, vp, &vp->v_label, mode);
- return (error);
-}
-
-int
-mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp, uid_t uid,
- gid_t gid)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setowner");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setowner, cred, vp, &vp->v_label, uid, gid);
- return (error);
-}
-
-int
-mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
- struct timespec atime, struct timespec mtime)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setutimes");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setutimes, cred, vp, &vp->v_label, atime,
- mtime);
- return (error);
-}
-
-int
-mac_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_stat");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_stat, active_cred, file_cred, vp,
- &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_write(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_write");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_write, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-/*
- * When relabeling a process, call out to the policies for the maximum
- * permission allowed for each object type we know about in its
- * memory space, and revoke access (in the least surprising ways we
- * know) when necessary. The process lock is not held here.
- */
-void
-mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred)
-{
-
- /* XXX freeze all other threads */
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- &td->td_proc->p_vmspace->vm_map);
- /* XXX allow other threads to continue */
-}
-
-static __inline const char *
-prot2str(vm_prot_t prot)
-{
-
- switch (prot & VM_PROT_ALL) {
- case VM_PROT_READ:
- return ("r--");
- case VM_PROT_READ | VM_PROT_WRITE:
- return ("rw-");
- case VM_PROT_READ | VM_PROT_EXECUTE:
- return ("r-x");
- case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("rwx");
- case VM_PROT_WRITE:
- return ("-w-");
- case VM_PROT_EXECUTE:
- return ("--x");
- case VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("-wx");
- default:
- return ("---");
- }
-}
-
-static void
-mac_cred_mmapped_drop_perms_recurse(struct thread *td, struct ucred *cred,
- struct vm_map *map)
-{
- struct vm_map_entry *vme;
- int result;
- vm_prot_t revokeperms;
- vm_object_t object;
- vm_ooffset_t offset;
- struct vnode *vp;
-
- if (!mac_mmap_revocation)
- return;
-
- vm_map_lock_read(map);
- for (vme = map->header.next; vme != &map->header; vme = vme->next) {
- if (vme->eflags & MAP_ENTRY_IS_SUB_MAP) {
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- vme->object.sub_map);
- continue;
- }
- /*
- * Skip over entries that obviously are not shared.
- */
- if (vme->eflags & (MAP_ENTRY_COW | MAP_ENTRY_NOSYNC) ||
- !vme->max_protection)
- continue;
- /*
- * Drill down to the deepest backing object.
- */
- offset = vme->offset;
- object = vme->object.vm_object;
- if (object == NULL)
- continue;
- while (object->backing_object != NULL) {
- object = object->backing_object;
- offset += object->backing_object_offset;
- }
- /*
- * At the moment, vm_maps and objects aren't considered
- * by the MAC system, so only things with backing by a
- * normal object (read: vnodes) are checked.
- */
- if (object->type != OBJT_VNODE)
- continue;
- vp = (struct vnode *)object->handle;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- result = vme->max_protection;
- mac_check_vnode_mmap_downgrade(cred, vp, &result);
- VOP_UNLOCK(vp, 0, td);
- /*
- * Find out what maximum protection we may be allowing
- * now but a policy needs to get removed.
- */
- revokeperms = vme->max_protection & ~result;
- if (!revokeperms)
- continue;
- printf("pid %ld: revoking %s perms from %#lx:%ld "
- "(max %s/cur %s)\n", (long)td->td_proc->p_pid,
- prot2str(revokeperms), (u_long)vme->start,
- (long)(vme->end - vme->start),
- prot2str(vme->max_protection), prot2str(vme->protection));
- vm_map_lock_upgrade(map);
- /*
- * This is the really simple case: if a map has more
- * max_protection than is allowed, but it's not being
- * actually used (that is, the current protection is
- * still allowed), we can just wipe it out and do
- * nothing more.
- */
- if ((vme->protection & revokeperms) == 0) {
- vme->max_protection -= revokeperms;
- } else {
- if (revokeperms & VM_PROT_WRITE) {
- /*
- * In the more complicated case, flush out all
- * pending changes to the object then turn it
- * copy-on-write.
- */
- vm_object_reference(object);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- VM_OBJECT_LOCK(object);
- vm_object_page_clean(object,
- OFF_TO_IDX(offset),
- OFF_TO_IDX(offset + vme->end - vme->start +
- PAGE_MASK),
- OBJPC_SYNC);
- VM_OBJECT_UNLOCK(object);
- VOP_UNLOCK(vp, 0, td);
- vm_object_deallocate(object);
- /*
- * Why bother if there's no read permissions
- * anymore? For the rest, we need to leave
- * the write permissions on for COW, or
- * remove them entirely if configured to.
- */
- if (!mac_mmap_revocation_via_cow) {
- vme->max_protection &= ~VM_PROT_WRITE;
- vme->protection &= ~VM_PROT_WRITE;
- } if ((revokeperms & VM_PROT_READ) == 0)
- vme->eflags |= MAP_ENTRY_COW |
- MAP_ENTRY_NEEDS_COPY;
- }
- if (revokeperms & VM_PROT_EXECUTE) {
- vme->max_protection &= ~VM_PROT_EXECUTE;
- vme->protection &= ~VM_PROT_EXECUTE;
- }
- if (revokeperms & VM_PROT_READ) {
- vme->max_protection = 0;
- vme->protection = 0;
- }
- pmap_protect(map->pmap, vme->start, vme->end,
- vme->protection & ~revokeperms);
- vm_map_simplify_entry(map, vme);
- }
- vm_map_lock_downgrade(map);
- }
- vm_map_unlock_read(map);
-}
-
-/*
- * When the subject's label changes, it may require revocation of privilege
- * to mapped objects. This can't be done on-the-fly later with a unified
- * buffer cache.
- */
-static void
-mac_relabel_cred(struct ucred *cred, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_cred, cred, newlabel);
-}
-
-void
-mac_relabel_vnode(struct ucred *cred, struct vnode *vp, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_vnode, cred, vp, &vp->v_label, newlabel);
-}
-
-void
-mac_create_ifnet(struct ifnet *ifnet)
-{
-
- MAC_PERFORM(create_ifnet, ifnet, &ifnet->if_label);
-}
-
-void
-mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(create_bpfdesc, cred, bpf_d, &bpf_d->bd_label);
-}
-
-void
-mac_create_socket(struct ucred *cred, struct socket *socket)
-{
-
- MAC_PERFORM(create_socket, cred, socket, &socket->so_label);
-}
-
-void
-mac_create_pipe(struct ucred *cred, struct pipe *pipe)
-{
-
- MAC_PERFORM(create_pipe, cred, pipe, pipe->pipe_label);
-}
-
-void
-mac_create_socket_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(create_socket_from_socket, oldsocket, &oldsocket->so_label,
- newsocket, &newsocket->so_label);
-}
-
-static void
-mac_relabel_socket(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_socket, cred, socket, &socket->so_label, newlabel);
-}
-
-static void
-mac_relabel_pipe(struct ucred *cred, struct pipe *pipe, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_pipe, cred, pipe, pipe->pipe_label, newlabel);
-}
-
-void
-mac_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct socket *socket)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(set_socket_peer_from_mbuf, mbuf, label, socket,
- &socket->so_peerlabel);
-}
-
-void
-mac_set_socket_peer_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(set_socket_peer_from_socket, oldsocket,
- &oldsocket->so_label, newsocket, &newsocket->so_peerlabel);
-}
-
-void
-mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram)
-{
- struct label *label;
-
- label = mbuf_to_label(datagram);
-
- MAC_PERFORM(create_datagram_from_ipq, ipq, &ipq->ipq_label,
- datagram, label);
-}
-
-void
-mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment)
-{
- struct label *datagramlabel, *fragmentlabel;
-
- datagramlabel = mbuf_to_label(datagram);
- fragmentlabel = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_fragment, datagram, datagramlabel, fragment,
- fragmentlabel);
-}
-
-void
-mac_create_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_mbuf(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_from_mbuf, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-void
-mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_bpfdesc, bpf_d, &bpf_d->bd_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_linklayer, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_ifnet, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf, struct ifnet *ifnet,
- struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_multicast_encap, oldmbuf, oldmbuflabel,
- ifnet, &ifnet->if_label, newmbuf, newmbuflabel);
-}
-
-void
-mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_netlayer, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-int
-mac_fragment_match(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
- int result;
-
- label = mbuf_to_label(fragment);
-
- result = 1;
- MAC_BOOLEAN(fragment_match, &&, fragment, label, ipq,
- &ipq->ipq_label);
-
- return (result);
-}
-
-void
-mac_update_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(update_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_socket(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_socket, socket, &socket->so_label, mbuf,
- label);
-}
-
-void
-mac_create_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-void
-mac_create_root_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_root_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-int
-mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet)
-{
- int error;
-
- if (!mac_enforce_network)
- return (0);
-
- MAC_CHECK(check_bpfdesc_receive, bpf_d, &bpf_d->bd_label, ifnet,
- &ifnet->if_label);
-
- return (error);
-}
-
-static int
-mac_check_cred_relabel(struct ucred *cred, struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_cred_relabel, cred, newlabel);
-
- return (error);
-}
-
-int
-mac_check_cred_visible(struct ucred *u1, struct ucred *u2)
-{
- int error;
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_cred_visible, u1, u2);
-
- return (error);
-}
-
-int
-mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- M_ASSERTPKTHDR(mbuf);
-
- if (!mac_enforce_network)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_ifnet_transmit, ifnet, &ifnet->if_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_kenv_dump(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_dump, cred);
-
- return (error);
-}
-
-int
-mac_check_kenv_get(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_get, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kenv_set(struct ucred *cred, char *name, char *value)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_set, cred, name, value);
-
- return (error);
-}
-
-int
-mac_check_kenv_unset(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_unset, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kld_load(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_kld_load");
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_load, cred, vp, &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_kld_stat(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_stat, cred);
-
- return (error);
-}
-
-int
-mac_check_kld_unload(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_unload, cred);
-
- return (error);
-}
-
-int
-mac_check_mount_stat(struct ucred *cred, struct mount *mount)
-{
- int error;
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_mount_stat, cred, mount, &mount->mnt_mntlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, unsigned long cmd,
- void *data)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_ioctl, cred, pipe, pipe->pipe_label, cmd, data);
-
- return (error);
-}
-
-int
-mac_check_pipe_poll(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_poll, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_read(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_read, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-static int
-mac_check_pipe_relabel(struct ucred *cred, struct pipe *pipe,
- struct label *newlabel)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_relabel, cred, pipe, pipe->pipe_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_stat(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_stat, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_write(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_write, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_proc_debug(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_debug, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_sched(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_sched, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_signal(struct ucred *cred, struct proc *proc, int signum)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_signal, cred, proc, signum);
-
- return (error);
-}
-
-int
-mac_check_socket_bind(struct ucred *ucred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_bind, ucred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_connect(struct ucred *cred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_connect, cred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_deliver(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_socket_deliver, socket, &socket->so_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_socket_listen(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_listen, cred, socket, &socket->so_label);
- return (error);
-}
-
-int
-mac_check_socket_receive(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_receive, cred, so, &so->so_label);
-
- return (error);
-}
-
-static int
-mac_check_socket_relabel(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_socket_relabel, cred, socket, &socket->so_label,
- newlabel);
-
- return (error);
-}
-
-int
-mac_check_socket_send(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_send, cred, so, &so->so_label);
-
- return (error);
-}
-
-int
-mac_check_socket_visible(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_visible, cred, socket, &socket->so_label);
-
- return (error);
-}
-
-int
-mac_check_sysarch_ioperm(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_sysarch_ioperm, cred);
- return (error);
-}
-
-int
-mac_check_system_acct(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- if (vp != NULL) {
- ASSERT_VOP_LOCKED(vp, "mac_check_system_acct");
- }
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_acct, cred, vp,
- vp != NULL ? &vp->v_label : NULL);
-
- return (error);
-}
-
-int
-mac_check_system_nfsd(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_nfsd, cred);
-
- return (error);
-}
-
-int
-mac_check_system_reboot(struct ucred *cred, int howto)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_reboot, cred, howto);
-
- return (error);
-}
-
-int
-mac_check_system_settime(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_settime, cred);
-
- return (error);
-}
-
-int
-mac_check_system_swapon(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapon");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapon, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_swapoff(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapoff");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapoff, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_sysctl(struct ucred *cred, int *name, u_int namelen,
- void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen)
-{
- int error;
-
- /*
- * XXXMAC: We're very much like to assert the SYSCTL_LOCK here,
- * but since it's not exported from kern_sysctl.c, we can't.
- */
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_sysctl, cred, name, namelen, old, oldlenp,
- inkernel, new, newlen);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_ifnet_label(&ifnet->if_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- struct label intlabel;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_ifnet_label(&intlabel);
- error = mac_internalize_ifnet_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- /*
- * XXX: Note that this is a redundant privilege check, since
- * policies impose this check themselves if required by the
- * policy. Eventually, this should go away.
- */
- error = suser_cred(cred, 0);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_CHECK(check_ifnet_relabel, cred, ifnet, &ifnet->if_label,
- &intlabel);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_PERFORM(relabel_ifnet, cred, ifnet, &ifnet->if_label, &intlabel);
-
- mac_destroy_ifnet_label(&intlabel);
- return (0);
-}
-
-void
-mac_create_devfs_device(struct mount *mp, dev_t dev, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_device, mp, dev, de, &de->de_label);
-}
-
-void
-mac_create_devfs_symlink(struct ucred *cred, struct mount *mp,
- struct devfs_dirent *dd, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_symlink, cred, mp, dd, &dd->de_label, de,
- &de->de_label);
-}
-
-void
-mac_create_devfs_directory(struct mount *mp, char *dirname, int dirnamelen,
- struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_directory, mp, dirname, dirnamelen, de,
- &de->de_label);
-}
-
-int
-mac_setsockopt_label_set(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- struct label intlabel;
- char *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, buffer, mac->m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_socket_label(&intlabel, M_WAITOK);
- error = mac_internalize_socket_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_check_socket_relabel(cred, so, &intlabel);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_relabel_socket(cred, so, &intlabel);
-
- mac_destroy_socket_label(&intlabel);
- return (0);
-}
-
-int
-mac_pipe_label_set(struct ucred *cred, struct pipe *pipe, struct label *label)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- error = mac_check_pipe_relabel(cred, pipe, label);
- if (error)
- return (error);
-
- mac_relabel_pipe(cred, pipe, label);
-
- return (0);
-}
-
-int
-mac_getsockopt_label_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *buffer, *elements;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_label(&so->so_label, elements,
- buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_getsockopt_peerlabel_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *elements, *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_peer_label(&so->so_peerlabel,
- elements, buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * Implementation of VOP_SETLABEL() that relies on extended attributes
- * to store label data. Can be referenced by filesystems supporting
- * extended attributes.
- */
-int
-vop_stdsetlabel_ea(struct vop_setlabel_args *ap)
-{
- struct vnode *vp = ap->a_vp;
- struct label *intlabel = ap->a_label;
- int error;
-
- ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea");
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- error = mac_setlabel_vnode_extattr(ap->a_cred, vp, intlabel);
- if (error)
- return (error);
-
- mac_relabel_vnode(ap->a_cred, vp, intlabel);
-
- return (0);
-}
-
-static int
-vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred)
-{
- int error;
-
- if (vp->v_mount == NULL) {
- /* printf("vn_setlabel: null v_mount\n"); */
- if (vp->v_type != VNON)
- printf("vn_setlabel: null v_mount with non-VNON\n");
- return (EBADF);
- }
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- /*
- * Multi-phase commit. First check the policies to confirm the
- * change is OK. Then commit via the filesystem. Finally,
- * update the actual vnode label. Question: maybe the filesystem
- * should update the vnode at the end as part of VOP_SETLABEL()?
- */
- error = mac_check_vnode_relabel(cred, vp, intlabel);
- if (error)
- return (error);
-
- /*
- * VADMIN provides the opportunity for the filesystem to make
- * decisions about who is and is not able to modify labels
- * and protections on files. This might not be right. We can't
- * assume VOP_SETLABEL() will do it, because we might implement
- * that as part of vop_stdsetlabel_ea().
- */
- error = VOP_ACCESS(vp, VADMIN, cred, curthread);
- if (error)
- return (error);
-
- error = VOP_SETLABEL(vp, intlabel, cred, curthread);
- if (error)
- return (error);
-
- return (0);
-}
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- struct proc *tproc;
- struct ucred *tcred;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- tproc = pfind(uap->pid);
- if (tproc == NULL)
- return (ESRCH);
-
- tcred = NULL; /* Satisfy gcc. */
- error = p_cansee(td, tproc);
- if (error == 0)
- tcred = crhold(tproc->p_ucred);
- PROC_UNLOCK(tproc);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&tcred->cr_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&td->td_ucred->cr_label,
- elements, buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
- struct ucred *newcred, *oldcred;
- struct label intlabel;
- struct proc *p;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(&intlabel);
- error = mac_internalize_cred_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(&intlabel);
- return (error);
- }
-
- newcred = crget();
-
- p = td->td_proc;
- PROC_LOCK(p);
- oldcred = p->p_ucred;
-
- error = mac_check_cred_relabel(oldcred, &intlabel);
- if (error) {
- PROC_UNLOCK(p);
- crfree(newcred);
- goto out;
- }
-
- setsugid(p);
- crcopy(newcred, oldcred);
- mac_relabel_cred(newcred, &intlabel);
- p->p_ucred = newcred;
-
- /*
- * Grab additional reference for use while revoking mmaps, prior
- * to releasing the proc lock and sharing the cred.
- */
- crhold(newcred);
- PROC_UNLOCK(p);
-
- if (mac_enforce_vm) {
- mtx_lock(&Giant);
- mac_cred_mmapped_drop_perms(td, newcred);
- mtx_unlock(&Giant);
- }
-
- crfree(newcred); /* Free revocation reference. */
- crfree(oldcred);
-
-out:
- mac_destroy_cred_label(&intlabel);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
- char *elements, *buffer;
- struct label intlabel;
- struct file *fp;
- struct mac mac;
- struct vnode *vp;
- struct pipe *pipe;
- short label_type;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- label_type = fp->f_type;
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- vp = fp->f_data;
-
- mac_init_vnode_label(&intlabel);
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- mac_copy_vnode_label(&vp->v_label, &intlabel);
- VOP_UNLOCK(vp, 0, td);
-
- break;
- case DTYPE_PIPE:
- pipe = fp->f_data;
-
- mac_init_pipe_label(&intlabel);
-
- PIPE_LOCK(pipe);
- mac_copy_pipe_label(pipe->pipe_label, &intlabel);
- PIPE_UNLOCK(pipe);
- break;
- default:
- error = EINVAL;
- fdrop(fp, td);
- goto out;
- }
- fdrop(fp, td);
-
- switch (label_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- if (error == 0)
- error = mac_externalize_vnode_label(&intlabel,
- elements, buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_vnode_label(&intlabel);
- break;
- case DTYPE_PIPE:
- error = mac_externalize_pipe_label(&intlabel, elements,
- buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_pipe_label(&intlabel);
- break;
- default:
- panic("__mac_get_fd: corrupted label_type");
- }
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
-
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
- struct label intlabel;
- struct pipe *pipe;
- struct file *fp;
- struct mount *mp;
- struct vnode *vp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vp = fp->f_data;
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error != 0) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- error = vn_setlabel(vp, &intlabel, td->td_ucred);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
-
- mac_destroy_vnode_label(&intlabel);
- break;
-
- case DTYPE_PIPE:
- mac_init_pipe_label(&intlabel);
- error = mac_internalize_pipe_label(&intlabel, buffer);
- if (error == 0) {
- pipe = fp->f_data;
- PIPE_LOCK(pipe);
- error = mac_pipe_label_set(td->td_ucred, pipe,
- &intlabel);
- PIPE_UNLOCK(pipe);
- }
-
- mac_destroy_pipe_label(&intlabel);
- break;
-
- default:
- error = EINVAL;
- }
-
- fdrop(fp, td);
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
- struct mac_policy_conf *mpc;
- char target[MAC_MAX_POLICY_NAME];
- int entrycount, error;
-
- error = copyinstr(uap->policy, target, sizeof(target), NULL);
- if (error)
- return (error);
-
- error = ENOSYS;
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- goto out;
- }
- }
-
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) {
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- break;
- }
- }
- mac_policy_list_unbusy();
- }
-out:
- return (error);
-}
-
-SYSINIT(mac, SI_SUB_MAC, SI_ORDER_FIRST, mac_init, NULL);
-SYSINIT(mac_late, SI_SUB_MAC_LATE, SI_ORDER_FIRST, mac_late_init, NULL);
-
-#else /* !MAC */
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
-
- return (ENOSYS);
-}
-
-#endif
diff --git a/sys/security/mac/mac_syscalls.c b/sys/security/mac/mac_syscalls.c
deleted file mode 100644
index fb06edea3012..000000000000
--- a/sys/security/mac/mac_syscalls.c
+++ /dev/null
@@ -1,3975 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * Copyright (c) 2001 Ilmar S. Habibulin
- * Copyright (c) 2001, 2002, 2003 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * This software was developed by Robert Watson and Ilmar Habibulin for the
- * TrustedBSD Project.
- *
- * This software was developed for the FreeBSD Project in part by Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
- * as part of the DARPA CHATS research program.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-/*
- * Developed by the TrustedBSD Project.
- *
- * Framework for extensible kernel access control. Kernel and userland
- * interface to the framework, policy registration and composition.
- */
-
-#include "opt_mac.h"
-#include "opt_devfs.h"
-
-#include <sys/param.h>
-#include <sys/condvar.h>
-#include <sys/extattr.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/mac.h>
-#include <sys/module.h>
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/sysent.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/file.h>
-#include <sys/namei.h>
-#include <sys/socket.h>
-#include <sys/pipe.h>
-#include <sys/socketvar.h>
-#include <sys/sysctl.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-
-#include <sys/mac_policy.h>
-
-#include <fs/devfs/devfs.h>
-
-#include <net/bpfdesc.h>
-#include <net/if.h>
-#include <net/if_var.h>
-
-#include <netinet/in.h>
-#include <netinet/ip_var.h>
-
-#ifdef MAC
-
-/*
- * Declare that the kernel provides MAC support, version 1. This permits
- * modules to refuse to be loaded if the necessary support isn't present,
- * even if it's pre-boot.
- */
-MODULE_VERSION(kernel_mac_support, 1);
-
-SYSCTL_DECL(_security);
-
-SYSCTL_NODE(_security, OID_AUTO, mac, CTLFLAG_RW, 0,
- "TrustedBSD MAC policy controls");
-
-#if MAC_MAX_SLOTS > 32
-#error "MAC_MAX_SLOTS too large"
-#endif
-
-static unsigned int mac_max_slots = MAC_MAX_SLOTS;
-static unsigned int mac_slot_offsets_free = (1 << MAC_MAX_SLOTS) - 1;
-SYSCTL_UINT(_security_mac, OID_AUTO, max_slots, CTLFLAG_RD,
- &mac_max_slots, 0, "");
-
-/*
- * Has the kernel started generating labeled objects yet? All read/write
- * access to this variable is serialized during the boot process. Following
- * the end of serialization, we don't update this flag; no locking.
- */
-static int mac_late = 0;
-
-/*
- * Warn about EA transactions only the first time they happen.
- * Weak coherency, no locking.
- */
-static int ea_warn_once = 0;
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
-/*
- * Flag to indicate whether or not we should allocate label storage for
- * new mbufs. Since most dynamic policies we currently work with don't
- * rely on mbuf labeling, try to avoid paying the cost of mtag allocation
- * unless specifically notified of interest. One result of this is
- * that if a dynamically loaded policy requests mbuf labels, it must
- * be able to deal with a NULL label being returned on any mbufs that
- * were already in flight when the policy was loaded. Since the policy
- * already has to deal with uninitialized labels, this probably won't
- * be a problem. Note: currently no locking. Will this be a problem?
- */
-static int mac_labelmbufs = 0;
-#endif
-
-static int mac_enforce_fs = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_fs, CTLFLAG_RW,
- &mac_enforce_fs, 0, "Enforce MAC policy on file system objects");
-TUNABLE_INT("security.mac.enforce_fs", &mac_enforce_fs);
-
-static int mac_enforce_kld = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_kld, CTLFLAG_RW,
- &mac_enforce_kld, 0, "Enforce MAC policy on kld operations");
-TUNABLE_INT("security.mac.enforce_kld", &mac_enforce_kld);
-
-static int mac_enforce_network = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_network, CTLFLAG_RW,
- &mac_enforce_network, 0, "Enforce MAC policy on network packets");
-TUNABLE_INT("security.mac.enforce_network", &mac_enforce_network);
-
-static int mac_enforce_pipe = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_pipe, CTLFLAG_RW,
- &mac_enforce_pipe, 0, "Enforce MAC policy on pipe operations");
-TUNABLE_INT("security.mac.enforce_pipe", &mac_enforce_pipe);
-
-static int mac_enforce_process = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_process, CTLFLAG_RW,
- &mac_enforce_process, 0, "Enforce MAC policy on inter-process operations");
-TUNABLE_INT("security.mac.enforce_process", &mac_enforce_process);
-
-static int mac_enforce_socket = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_socket, CTLFLAG_RW,
- &mac_enforce_socket, 0, "Enforce MAC policy on socket operations");
-TUNABLE_INT("security.mac.enforce_socket", &mac_enforce_socket);
-
-static int mac_enforce_system = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_system, CTLFLAG_RW,
- &mac_enforce_system, 0, "Enforce MAC policy on system operations");
-TUNABLE_INT("security.mac.enforce_system", &mac_enforce_system);
-
-static int mac_enforce_vm = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_vm, CTLFLAG_RW,
- &mac_enforce_vm, 0, "Enforce MAC policy on vm operations");
-TUNABLE_INT("security.mac.enforce_vm", &mac_enforce_vm);
-
-static int mac_mmap_revocation = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation, CTLFLAG_RW,
- &mac_mmap_revocation, 0, "Revoke mmap access to files on subject "
- "relabel");
-static int mac_mmap_revocation_via_cow = 0;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation_via_cow, CTLFLAG_RW,
- &mac_mmap_revocation_via_cow, 0, "Revoke mmap access to files via "
- "copy-on-write semantics, or by removing all write access");
-
-#ifdef MAC_DEBUG
-SYSCTL_NODE(_security_mac, OID_AUTO, debug, CTLFLAG_RW, 0,
- "TrustedBSD MAC debug info");
-
-static int mac_debug_label_fallback = 0;
-SYSCTL_INT(_security_mac_debug, OID_AUTO, label_fallback, CTLFLAG_RW,
- &mac_debug_label_fallback, 0, "Filesystems should fall back to fs label"
- "when label is corrupted.");
-TUNABLE_INT("security.mac.debug_label_fallback",
- &mac_debug_label_fallback);
-
-SYSCTL_NODE(_security_mac_debug, OID_AUTO, counters, CTLFLAG_RW, 0,
- "TrustedBSD MAC object counters");
-
-static unsigned int nmacmbufs, nmaccreds, nmacifnets, nmacbpfdescs,
- nmacsockets, nmacmounts, nmactemp, nmacvnodes, nmacdevfsdirents,
- nmacipqs, nmacpipes, nmacprocs;
-
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mbufs, CTLFLAG_RD,
- &nmacmbufs, 0, "number of mbufs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, creds, CTLFLAG_RD,
- &nmaccreds, 0, "number of ucreds in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ifnets, CTLFLAG_RD,
- &nmacifnets, 0, "number of ifnets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ipqs, CTLFLAG_RD,
- &nmacipqs, 0, "number of ipqs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, bpfdescs, CTLFLAG_RD,
- &nmacbpfdescs, 0, "number of bpfdescs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, sockets, CTLFLAG_RD,
- &nmacsockets, 0, "number of sockets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, pipes, CTLFLAG_RD,
- &nmacpipes, 0, "number of pipes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, procs, CTLFLAG_RD,
- &nmacprocs, 0, "number of procs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mounts, CTLFLAG_RD,
- &nmacmounts, 0, "number of mounts in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, temp, CTLFLAG_RD,
- &nmactemp, 0, "number of temporary labels in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, vnodes, CTLFLAG_RD,
- &nmacvnodes, 0, "number of vnodes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, devfsdirents, CTLFLAG_RD,
- &nmacdevfsdirents, 0, "number of devfs dirents inuse");
-#endif
-
-static int error_select(int error1, int error2);
-static int mac_policy_register(struct mac_policy_conf *mpc);
-static int mac_policy_unregister(struct mac_policy_conf *mpc);
-
-static void mac_check_vnode_mmap_downgrade(struct ucred *cred,
- struct vnode *vp, int *prot);
-static void mac_cred_mmapped_drop_perms_recurse(struct thread *td,
- struct ucred *cred, struct vm_map *map);
-
-static void mac_destroy_socket_label(struct label *label);
-
-static int mac_setlabel_vnode_extattr(struct ucred *cred,
- struct vnode *vp, struct label *intlabel);
-
-MALLOC_DEFINE(M_MACPIPELABEL, "macpipelabel", "MAC labels for pipes");
-MALLOC_DEFINE(M_MACTEMP, "mactemp", "MAC temporary label storage");
-
-/*
- * mac_static_policy_list holds a list of policy modules that are not
- * loaded while the system is "live", and cannot be unloaded. These
- * policies can be invoked without holding the busy count.
- *
- * mac_policy_list stores the list of dynamic policies. A busy count is
- * maintained for the list, stored in mac_policy_busy. The busy count
- * is protected by mac_policy_mtx; the list may be modified only
- * while the busy count is 0, requiring that the lock be held to
- * prevent new references to the list from being acquired. For almost
- * all operations, incrementing the busy count is sufficient to
- * guarantee consistency, as the list cannot be modified while the
- * busy count is elevated. For a few special operations involving a
- * change to the list of active policies, the mtx itself must be held.
- * A condition variable, mac_policy_cv, is used to signal potential
- * exclusive consumers that they should try to acquire the lock if a
- * first attempt at exclusive access fails.
- */
-static struct mtx mac_policy_mtx;
-static struct cv mac_policy_cv;
-static int mac_policy_count;
-static LIST_HEAD(, mac_policy_conf) mac_policy_list;
-static LIST_HEAD(, mac_policy_conf) mac_static_policy_list;
-
-/*
- * We manually invoke WITNESS_WARN() to allow Witness to generate
- * warnings even if we don't end up ever triggering the wait at
- * run-time. The consumer of the exclusive interface must not hold
- * any locks (other than potentially Giant) since we may sleep for
- * long (potentially indefinite) periods of time waiting for the
- * framework to become quiescent so that a policy list change may
- * be made.
- */
-static __inline void
-mac_policy_grab_exclusive(void)
-{
- WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
- "mac_policy_grab_exclusive() at %s:%d", __FILE__, __LINE__);
- mtx_lock(&mac_policy_mtx);
- while (mac_policy_count != 0)
- cv_wait(&mac_policy_cv, &mac_policy_mtx);
-}
-
-static __inline void
-mac_policy_assert_exclusive(void)
-{
- mtx_assert(&mac_policy_mtx, MA_OWNED);
- KASSERT(mac_policy_count == 0,
- ("mac_policy_assert_exclusive(): not exclusive"));
-}
-
-static __inline void
-mac_policy_release_exclusive(void)
-{
-
- KASSERT(mac_policy_count == 0,
- ("mac_policy_release_exclusive(): not exclusive"));
- mtx_unlock(&mac_policy_mtx);
- cv_signal(&mac_policy_cv);
-}
-
-static __inline void
-mac_policy_list_busy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count++;
- mtx_unlock(&mac_policy_mtx);
-}
-
-static __inline int
-mac_policy_list_conditional_busy(void)
-{
- int ret;
-
- mtx_lock(&mac_policy_mtx);
- if (!LIST_EMPTY(&mac_policy_list)) {
- mac_policy_count++;
- ret = 1;
- } else
- ret = 0;
- mtx_unlock(&mac_policy_mtx);
- return (ret);
-}
-
-static __inline void
-mac_policy_list_unbusy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count--;
- KASSERT(mac_policy_count >= 0, ("MAC_POLICY_LIST_LOCK"));
- if (mac_policy_count == 0)
- cv_signal(&mac_policy_cv);
- mtx_unlock(&mac_policy_mtx);
-}
-
-/*
- * MAC_CHECK performs the designated check by walking the policy
- * module list and checking with each as to how it feels about the
- * request. Note that it returns its value via 'error' in the scope
- * of the caller.
- */
-#define MAC_CHECK(check, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- error = 0; \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * MAC_BOOLEAN performs the designated boolean composition by walking
- * the module list, invoking each instance of the operation, and
- * combining the results using the passed C operator. Note that it
- * returns its value via 'result' in the scope of the caller, which
- * should be initialized by the caller in a meaningful way to get
- * a meaningful result.
- */
-#define MAC_BOOLEAN(operation, composition, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation \
- (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-#define MAC_EXTERNALIZE(type, label, elementlist, outbuf, \
- outbuflen) do { \
- char *curptr, *curptr_start, *element_name, *element_temp; \
- size_t left, left_start, len; \
- int claimed, first, first_start, ignorenotfound; \
- \
- error = 0; \
- element_temp = elementlist; \
- curptr = outbuf; \
- curptr[0] = '\0'; \
- left = outbuflen; \
- first = 1; \
- while ((element_name = strsep(&element_temp, ",")) != NULL) { \
- curptr_start = curptr; \
- left_start = left; \
- first_start = first; \
- if (element_name[0] == '?') { \
- element_name++; \
- ignorenotfound = 1; \
- } else \
- ignorenotfound = 0; \
- claimed = 0; \
- if (first) { \
- len = snprintf(curptr, left, "%s/", \
- element_name); \
- first = 0; \
- } else \
- len = snprintf(curptr, left, ",%s/", \
- element_name); \
- if (len >= left) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- \
- MAC_CHECK(externalize_ ## type, label, element_name, \
- curptr, left, &len, &claimed); \
- if (error) \
- break; \
- if (claimed == 1) { \
- if (len >= outbuflen) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- } else if (claimed == 0 && ignorenotfound) { \
- /* \
- * Revert addition of the label element \
- * name. \
- */ \
- curptr = curptr_start; \
- *curptr = '\0'; \
- left = left_start; \
- first = first_start; \
- } else { \
- error = EINVAL; /* XXXMAC: ENOLABEL */ \
- break; \
- } \
- } \
-} while (0)
-
-#define MAC_INTERNALIZE(type, label, instring) do { \
- char *element, *element_name, *element_data; \
- int claimed; \
- \
- error = 0; \
- element = instring; \
- while ((element_name = strsep(&element, ",")) != NULL) { \
- element_data = element_name; \
- element_name = strsep(&element_data, "/"); \
- if (element_data == NULL) { \
- error = EINVAL; \
- break; \
- } \
- claimed = 0; \
- MAC_CHECK(internalize_ ## type, label, element_name, \
- element_data, &claimed); \
- if (error) \
- break; \
- if (claimed != 1) { \
- /* XXXMAC: Another error here? */ \
- error = EINVAL; \
- break; \
- } \
- } \
-} while (0)
-
-/*
- * MAC_PERFORM performs the designated operation by walking the policy
- * module list and invoking that operation for each policy.
- */
-#define MAC_PERFORM(operation, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * Initialize the MAC subsystem, including appropriate SMP locks.
- */
-static void
-mac_init(void)
-{
-
- LIST_INIT(&mac_static_policy_list);
- LIST_INIT(&mac_policy_list);
-
- mtx_init(&mac_policy_mtx, "mac_policy_mtx", NULL, MTX_DEF);
- cv_init(&mac_policy_cv, "mac_policy_cv");
-}
-
-/*
- * For the purposes of modules that want to know if they were loaded
- * "early", set the mac_late flag once we've processed modules either
- * linked into the kernel, or loaded before the kernel startup.
- */
-static void
-mac_late_init(void)
-{
-
- mac_late = 1;
-}
-
-/*
- * After the policy list has changed, walk the list to update any global
- * flags.
- */
-static void
-mac_policy_updateflags(void)
-{
- struct mac_policy_conf *tmpc;
-#ifndef MAC_ALWAYS_LABEL_MBUF
- int labelmbufs;
-#endif
-
- mac_policy_assert_exclusive();
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- labelmbufs = 0;
-#endif
-
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- mac_labelmbufs = (labelmbufs != 0);
-#endif
-}
-
-/*
- * Allow MAC policy modules to register during boot, etc.
- */
-int
-mac_policy_modevent(module_t mod, int type, void *data)
-{
- struct mac_policy_conf *mpc;
- int error;
-
- error = 0;
- mpc = (struct mac_policy_conf *) data;
-
- switch (type) {
- case MOD_LOAD:
- if (mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_NOTLATE &&
- mac_late) {
- printf("mac_policy_modevent: can't load %s policy "
- "after booting\n", mpc->mpc_name);
- error = EBUSY;
- break;
- }
- error = mac_policy_register(mpc);
- break;
- case MOD_UNLOAD:
- /* Don't unregister the module if it was never registered. */
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED)
- != 0)
- error = mac_policy_unregister(mpc);
- else
- error = 0;
- break;
- default:
- break;
- }
-
- return (error);
-}
-
-static int
-mac_policy_register(struct mac_policy_conf *mpc)
-{
- struct mac_policy_conf *tmpc;
- int error, slot, static_entry;
-
- error = 0;
-
- /*
- * We don't technically need exclusive access while !mac_late,
- * but hold it for assertion consistency.
- */
- mac_policy_grab_exclusive();
-
- /*
- * If the module can potentially be unloaded, or we're loading
- * late, we have to stick it in the non-static list and pay
- * an extra performance overhead. Otherwise, we can pay a
- * light locking cost and stick it in the static list.
- */
- static_entry = (!mac_late &&
- !(mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK));
-
- if (static_entry) {
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- } else {
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- }
- if (mpc->mpc_field_off != NULL) {
- slot = ffs(mac_slot_offsets_free);
- if (slot == 0) {
- error = ENOMEM;
- goto out;
- }
- slot--;
- mac_slot_offsets_free &= ~(1 << slot);
- *mpc->mpc_field_off = slot;
- }
- mpc->mpc_runtime_flags |= MPC_RUNTIME_FLAG_REGISTERED;
-
- /*
- * If we're loading a MAC module after the framework has
- * initialized, it has to go into the dynamic list. If
- * we're loading it before we've finished initializing,
- * it can go into the static list with weaker locker
- * requirements.
- */
- if (static_entry)
- LIST_INSERT_HEAD(&mac_static_policy_list, mpc, mpc_list);
- else
- LIST_INSERT_HEAD(&mac_policy_list, mpc, mpc_list);
-
- /* Per-policy initialization. */
- if (mpc->mpc_ops->mpo_init != NULL)
- (*(mpc->mpc_ops->mpo_init))(mpc);
- mac_policy_updateflags();
-
- printf("Security policy loaded: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
-out:
- mac_policy_release_exclusive();
- return (error);
-}
-
-static int
-mac_policy_unregister(struct mac_policy_conf *mpc)
-{
-
- /*
- * If we fail the load, we may get a request to unload. Check
- * to see if we did the run-time registration, and if not,
- * silently succeed.
- */
- mac_policy_grab_exclusive();
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED) == 0) {
- mac_policy_release_exclusive();
- return (0);
- }
-#if 0
- /*
- * Don't allow unloading modules with private data.
- */
- if (mpc->mpc_field_off != NULL) {
- MAC_POLICY_LIST_UNLOCK();
- return (EBUSY);
- }
-#endif
- /*
- * Only allow the unload to proceed if the module is unloadable
- * by its own definition.
- */
- if ((mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK) == 0) {
- mac_policy_release_exclusive();
- return (EBUSY);
- }
- if (mpc->mpc_ops->mpo_destroy != NULL)
- (*(mpc->mpc_ops->mpo_destroy))(mpc);
-
- LIST_REMOVE(mpc, mpc_list);
- mpc->mpc_runtime_flags &= ~MPC_RUNTIME_FLAG_REGISTERED;
- mac_policy_updateflags();
-
- mac_policy_release_exclusive();
-
- printf("Security policy unload: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
- return (0);
-}
-
-/*
- * Define an error value precedence, and given two arguments, selects the
- * value with the higher precedence.
- */
-static int
-error_select(int error1, int error2)
-{
-
- /* Certain decision-making errors take top priority. */
- if (error1 == EDEADLK || error2 == EDEADLK)
- return (EDEADLK);
-
- /* Invalid arguments should be reported where possible. */
- if (error1 == EINVAL || error2 == EINVAL)
- return (EINVAL);
-
- /* Precedence goes to "visibility", with both process and file. */
- if (error1 == ESRCH || error2 == ESRCH)
- return (ESRCH);
-
- if (error1 == ENOENT || error2 == ENOENT)
- return (ENOENT);
-
- /* Precedence goes to DAC/MAC protections. */
- if (error1 == EACCES || error2 == EACCES)
- return (EACCES);
-
- /* Precedence goes to privilege. */
- if (error1 == EPERM || error2 == EPERM)
- return (EPERM);
-
- /* Precedence goes to error over success; otherwise, arbitrary. */
- if (error1 != 0)
- return (error1);
- return (error2);
-}
-
-static struct label *
-mbuf_to_label(struct mbuf *mbuf)
-{
- struct m_tag *tag;
- struct label *label;
-
- tag = m_tag_find(mbuf, PACKET_TAG_MACLABEL, NULL);
- label = (struct label *)(tag+1);
-
- return (label);
-}
-
-static void
-mac_init_label(struct label *label)
-{
-
- bzero(label, sizeof(*label));
- label->l_flags = MAC_FLAG_INITIALIZED;
-}
-
-static void
-mac_destroy_label(struct label *label)
-{
-
- KASSERT(label->l_flags & MAC_FLAG_INITIALIZED,
- ("destroying uninitialized label"));
-
- bzero(label, sizeof(*label));
- /* implicit: label->l_flags &= ~MAC_FLAG_INITIALIZED; */
-}
-
-void
-mac_init_bpfdesc(struct bpf_d *bpf_d)
-{
-
- mac_init_label(&bpf_d->bd_label);
- MAC_PERFORM(init_bpfdesc_label, &bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_init_cred_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_cred_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_init_cred(struct ucred *cred)
-{
-
- mac_init_cred_label(&cred->cr_label);
-}
-
-void
-mac_init_devfsdirent(struct devfs_dirent *de)
-{
-
- mac_init_label(&de->de_label);
- MAC_PERFORM(init_devfsdirent_label, &de->de_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_init_ifnet_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_ifnet_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_init_ifnet(struct ifnet *ifp)
-{
-
- mac_init_ifnet_label(&ifp->if_label);
-}
-
-int
-mac_init_ipq(struct ipq *ipq, int flag)
-{
- int error;
-
- mac_init_label(&ipq->ipq_label);
-
- MAC_CHECK(init_ipq_label, &ipq->ipq_label, flag);
- if (error) {
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacipqs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf_tag(struct m_tag *tag, int flag)
-{
- struct label *label;
- int error;
-
- label = (struct label *) (tag + 1);
- mac_init_label(label);
-
- MAC_CHECK(init_mbuf_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacmbufs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf(struct mbuf *m, int flag)
-{
- struct m_tag *tag;
- int error;
-
- M_ASSERTPKTHDR(m);
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- /*
- * Don't reserve space for labels on mbufs unless we have a policy
- * that uses the labels.
- */
- if (mac_labelmbufs) {
-#endif
- tag = m_tag_get(PACKET_TAG_MACLABEL, sizeof(struct label),
- flag);
- if (tag == NULL)
- return (ENOMEM);
- error = mac_init_mbuf_tag(tag, flag);
- if (error) {
- m_tag_free(tag);
- return (error);
- }
- m_tag_prepend(m, tag);
-#ifndef MAC_ALWAYS_LABEL_MBUF
- }
-#endif
- return (0);
-}
-
-void
-mac_init_mount(struct mount *mp)
-{
-
- mac_init_label(&mp->mnt_mntlabel);
- mac_init_label(&mp->mnt_fslabel);
- MAC_PERFORM(init_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(init_mount_fs_label, &mp->mnt_fslabel);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_init_pipe_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_pipe_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_init_pipe(struct pipe *pipe)
-{
- struct label *label;
-
- label = malloc(sizeof(struct label), M_MACPIPELABEL, M_ZERO|M_WAITOK);
- pipe->pipe_label = label;
- pipe->pipe_peer->pipe_label = label;
- mac_init_pipe_label(label);
-}
-
-void
-mac_init_proc(struct proc *p)
-{
-
- mac_init_label(&p->p_label);
- MAC_PERFORM(init_proc_label, &p->p_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacprocs, 1);
-#endif
-}
-
-static int
-mac_init_socket_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacsockets, 1);
-#endif
-
- return (error);
-}
-
-static int
-mac_init_socket_peer_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_peer_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
- return (error);
-}
-
-int
-mac_init_socket(struct socket *socket, int flag)
-{
- int error;
-
- error = mac_init_socket_label(&socket->so_label, flag);
- if (error)
- return (error);
-
- error = mac_init_socket_peer_label(&socket->so_peerlabel, flag);
- if (error)
- mac_destroy_socket_label(&socket->so_label);
-
- return (error);
-}
-
-void
-mac_init_vnode_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_vnode_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_init_vnode(struct vnode *vp)
-{
-
- mac_init_vnode_label(&vp->v_label);
-}
-
-void
-mac_destroy_bpfdesc(struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(destroy_bpfdesc_label, &bpf_d->bd_label);
- mac_destroy_label(&bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_destroy_cred_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_cred_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_destroy_cred(struct ucred *cred)
-{
-
- mac_destroy_cred_label(&cred->cr_label);
-}
-
-void
-mac_destroy_devfsdirent(struct devfs_dirent *de)
-{
-
- MAC_PERFORM(destroy_devfsdirent_label, &de->de_label);
- mac_destroy_label(&de->de_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_destroy_ifnet_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_ifnet_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_destroy_ifnet(struct ifnet *ifp)
-{
-
- mac_destroy_ifnet_label(&ifp->if_label);
-}
-
-void
-mac_destroy_ipq(struct ipq *ipq)
-{
-
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacipqs, 1);
-#endif
-}
-
-void
-mac_destroy_mbuf_tag(struct m_tag *tag)
-{
- struct label *label;
-
- label = (struct label *)(tag+1);
-
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmbufs, 1);
-#endif
-}
-
-void
-mac_destroy_mount(struct mount *mp)
-{
-
- MAC_PERFORM(destroy_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(destroy_mount_fs_label, &mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_mntlabel);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_destroy_pipe_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_pipe_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_destroy_pipe(struct pipe *pipe)
-{
-
- mac_destroy_pipe_label(pipe->pipe_label);
- free(pipe->pipe_label, M_MACPIPELABEL);
-}
-
-void
-mac_destroy_proc(struct proc *p)
-{
-
- MAC_PERFORM(destroy_proc_label, &p->p_label);
- mac_destroy_label(&p->p_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacprocs, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacsockets, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_peer_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_peer_label, label);
- mac_destroy_label(label);
-}
-
-void
-mac_destroy_socket(struct socket *socket)
-{
-
- mac_destroy_socket_label(&socket->so_label);
- mac_destroy_socket_peer_label(&socket->so_peerlabel);
-}
-
-void
-mac_destroy_vnode_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_vnode_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_destroy_vnode(struct vnode *vp)
-{
-
- mac_destroy_vnode_label(&vp->v_label);
-}
-
-void
-mac_copy_mbuf_tag(struct m_tag *src, struct m_tag *dest)
-{
- struct label *src_label, *dest_label;
-
- src_label = (struct label *)(src+1);
- dest_label = (struct label *)(dest+1);
-
- /*
- * mac_init_mbuf_tag() is called on the target tag in
- * m_tag_copy(), so we don't need to call it here.
- */
- MAC_PERFORM(copy_mbuf_label, src_label, dest_label);
-}
-
-static void
-mac_copy_pipe_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_pipe_label, src, dest);
-}
-
-void
-mac_copy_vnode_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_vnode_label, src, dest);
-}
-
-static int
-mac_check_structmac_consistent(struct mac *mac)
-{
-
- if (mac->m_buflen > MAC_MAX_LABEL_BUF_LEN)
- return (EINVAL);
-
- return (0);
-}
-
-static int
-mac_externalize_cred_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(cred_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_ifnet_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(ifnet_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_pipe_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(pipe_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_peer_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_peer_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_vnode_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(vnode_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_internalize_cred_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(cred_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_ifnet_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(ifnet_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_pipe_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(pipe_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_socket_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(socket_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_vnode_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(vnode_label, label, string);
-
- return (error);
-}
-
-/*
- * Initialize MAC label for the first kernel process, from which other
- * kernel processes and threads are spawned.
- */
-void
-mac_create_proc0(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc0, cred);
-}
-
-/*
- * Initialize MAC label for the first userland process, from which other
- * userland processes and threads are spawned.
- */
-void
-mac_create_proc1(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc1, cred);
-}
-
-void
-mac_thread_userret(struct thread *td)
-{
-
- MAC_PERFORM(thread_userret, td);
-}
-
-/*
- * When a new process is created, its label must be initialized. Generally,
- * this involves inheritence from the parent process, modulo possible
- * deltas. This function allows that processing to take place.
- */
-void
-mac_create_cred(struct ucred *parent_cred, struct ucred *child_cred)
-{
-
- MAC_PERFORM(create_cred, parent_cred, child_cred);
-}
-
-void
-mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(update_devfsdirent, mp, de, &de->de_label, vp,
- &vp->v_label);
-}
-
-void
-mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_devfs, mp, &mp->mnt_fslabel, de,
- &de->de_label, vp, &vp->v_label);
-}
-
-int
-mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_associate_vnode_extattr");
-
- MAC_CHECK(associate_vnode_extattr, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-
- return (error);
-}
-
-void
-mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_singlelabel, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-}
-
-int
-mac_create_vnode_extattr(struct ucred *cred, struct mount *mp,
- struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_create_vnode_extattr");
- ASSERT_VOP_LOCKED(vp, "mac_create_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(create_vnode_extattr, cred, mp, &mp->mnt_fslabel,
- dvp, &dvp->v_label, vp, &vp->v_label, cnp);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-static int
-mac_setlabel_vnode_extattr(struct ucred *cred, struct vnode *vp,
- struct label *intlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_setlabel_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(setlabel_vnode_extattr, cred, vp, &vp->v_label, intlabel);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-int
-mac_execve_enter(struct image_params *imgp, struct mac *mac_p,
- struct label *execlabelstorage)
-{
- struct mac mac;
- char *buffer;
- int error;
-
- if (mac_p == NULL)
- return (0);
-
- error = copyin(mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(execlabelstorage);
- error = mac_internalize_cred_label(execlabelstorage, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(execlabelstorage);
- return (error);
- }
- imgp->execlabel = execlabelstorage;
- return (0);
-}
-
-void
-mac_execve_exit(struct image_params *imgp)
-{
- if (imgp->execlabel != NULL)
- mac_destroy_cred_label(imgp->execlabel);
-}
-
-void
-mac_execve_transition(struct ucred *old, struct ucred *new, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return;
-
- MAC_PERFORM(execve_transition, old, new, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-}
-
-int
-mac_execve_will_transition(struct ucred *old, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
- int result;
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_will_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- result = 0;
- MAC_BOOLEAN(execve_will_transition, ||, old, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-
- return (result);
-}
-
-int
-mac_check_vnode_access(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_access");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_access, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chroot");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chroot, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_create(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp, struct vattr *vap)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_create");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_create, cred, dvp, &dvp->v_label, cnp, vap);
- return (error);
-}
-
-int
-mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp, struct vnode *vp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_delete");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_delete");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_delete, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
- acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_deleteacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_deleteacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_exec(struct ucred *cred, struct vnode *vp,
- struct image_params *imgp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_exec");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_exec, cred, vp, &vp->v_label, imgp,
- imgp->execlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp, acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_link(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_link");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_link");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_link, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_lookup");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_lookup, cred, dvp, &dvp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mmap, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-void
-mac_check_vnode_mmap_downgrade(struct ucred *cred, struct vnode *vp, int *prot)
-{
- int result = *prot;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap_downgrade");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return;
-
- MAC_PERFORM(check_vnode_mmap_downgrade, cred, vp, &vp->v_label,
- &result);
-
- *prot = result;
-}
-
-int
-mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mprotect");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mprotect, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-int
-mac_check_vnode_open(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_open");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_open, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_poll");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_poll, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_read");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_read, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_readdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_readdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_readlink");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readlink, cred, vp, &vp->v_label);
- return (error);
-}
-
-static int
-mac_check_vnode_relabel(struct ucred *cred, struct vnode *vp,
- struct label *newlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_relabel");
-
- MAC_CHECK(check_vnode_relabel, cred, vp, &vp->v_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_from");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_from");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_from, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, int samedir, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_to");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_to");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_to, cred, dvp, &dvp->v_label, vp,
- vp != NULL ? &vp->v_label : NULL, samedir, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_revoke");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_revoke, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type,
- struct acl *acl)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setacl, cred, vp, &vp->v_label, type, acl);
- return (error);
-}
-
-int
-mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp, u_long flags)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setflags");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setflags, cred, vp, &vp->v_label, flags);
- return (error);
-}
-
-int
-mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp, mode_t mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setmode");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setmode, cred, vp, &vp->v_label, mode);
- return (error);
-}
-
-int
-mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp, uid_t uid,
- gid_t gid)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setowner");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setowner, cred, vp, &vp->v_label, uid, gid);
- return (error);
-}
-
-int
-mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
- struct timespec atime, struct timespec mtime)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setutimes");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setutimes, cred, vp, &vp->v_label, atime,
- mtime);
- return (error);
-}
-
-int
-mac_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_stat");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_stat, active_cred, file_cred, vp,
- &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_write(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_write");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_write, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-/*
- * When relabeling a process, call out to the policies for the maximum
- * permission allowed for each object type we know about in its
- * memory space, and revoke access (in the least surprising ways we
- * know) when necessary. The process lock is not held here.
- */
-void
-mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred)
-{
-
- /* XXX freeze all other threads */
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- &td->td_proc->p_vmspace->vm_map);
- /* XXX allow other threads to continue */
-}
-
-static __inline const char *
-prot2str(vm_prot_t prot)
-{
-
- switch (prot & VM_PROT_ALL) {
- case VM_PROT_READ:
- return ("r--");
- case VM_PROT_READ | VM_PROT_WRITE:
- return ("rw-");
- case VM_PROT_READ | VM_PROT_EXECUTE:
- return ("r-x");
- case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("rwx");
- case VM_PROT_WRITE:
- return ("-w-");
- case VM_PROT_EXECUTE:
- return ("--x");
- case VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("-wx");
- default:
- return ("---");
- }
-}
-
-static void
-mac_cred_mmapped_drop_perms_recurse(struct thread *td, struct ucred *cred,
- struct vm_map *map)
-{
- struct vm_map_entry *vme;
- int result;
- vm_prot_t revokeperms;
- vm_object_t object;
- vm_ooffset_t offset;
- struct vnode *vp;
-
- if (!mac_mmap_revocation)
- return;
-
- vm_map_lock_read(map);
- for (vme = map->header.next; vme != &map->header; vme = vme->next) {
- if (vme->eflags & MAP_ENTRY_IS_SUB_MAP) {
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- vme->object.sub_map);
- continue;
- }
- /*
- * Skip over entries that obviously are not shared.
- */
- if (vme->eflags & (MAP_ENTRY_COW | MAP_ENTRY_NOSYNC) ||
- !vme->max_protection)
- continue;
- /*
- * Drill down to the deepest backing object.
- */
- offset = vme->offset;
- object = vme->object.vm_object;
- if (object == NULL)
- continue;
- while (object->backing_object != NULL) {
- object = object->backing_object;
- offset += object->backing_object_offset;
- }
- /*
- * At the moment, vm_maps and objects aren't considered
- * by the MAC system, so only things with backing by a
- * normal object (read: vnodes) are checked.
- */
- if (object->type != OBJT_VNODE)
- continue;
- vp = (struct vnode *)object->handle;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- result = vme->max_protection;
- mac_check_vnode_mmap_downgrade(cred, vp, &result);
- VOP_UNLOCK(vp, 0, td);
- /*
- * Find out what maximum protection we may be allowing
- * now but a policy needs to get removed.
- */
- revokeperms = vme->max_protection & ~result;
- if (!revokeperms)
- continue;
- printf("pid %ld: revoking %s perms from %#lx:%ld "
- "(max %s/cur %s)\n", (long)td->td_proc->p_pid,
- prot2str(revokeperms), (u_long)vme->start,
- (long)(vme->end - vme->start),
- prot2str(vme->max_protection), prot2str(vme->protection));
- vm_map_lock_upgrade(map);
- /*
- * This is the really simple case: if a map has more
- * max_protection than is allowed, but it's not being
- * actually used (that is, the current protection is
- * still allowed), we can just wipe it out and do
- * nothing more.
- */
- if ((vme->protection & revokeperms) == 0) {
- vme->max_protection -= revokeperms;
- } else {
- if (revokeperms & VM_PROT_WRITE) {
- /*
- * In the more complicated case, flush out all
- * pending changes to the object then turn it
- * copy-on-write.
- */
- vm_object_reference(object);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- VM_OBJECT_LOCK(object);
- vm_object_page_clean(object,
- OFF_TO_IDX(offset),
- OFF_TO_IDX(offset + vme->end - vme->start +
- PAGE_MASK),
- OBJPC_SYNC);
- VM_OBJECT_UNLOCK(object);
- VOP_UNLOCK(vp, 0, td);
- vm_object_deallocate(object);
- /*
- * Why bother if there's no read permissions
- * anymore? For the rest, we need to leave
- * the write permissions on for COW, or
- * remove them entirely if configured to.
- */
- if (!mac_mmap_revocation_via_cow) {
- vme->max_protection &= ~VM_PROT_WRITE;
- vme->protection &= ~VM_PROT_WRITE;
- } if ((revokeperms & VM_PROT_READ) == 0)
- vme->eflags |= MAP_ENTRY_COW |
- MAP_ENTRY_NEEDS_COPY;
- }
- if (revokeperms & VM_PROT_EXECUTE) {
- vme->max_protection &= ~VM_PROT_EXECUTE;
- vme->protection &= ~VM_PROT_EXECUTE;
- }
- if (revokeperms & VM_PROT_READ) {
- vme->max_protection = 0;
- vme->protection = 0;
- }
- pmap_protect(map->pmap, vme->start, vme->end,
- vme->protection & ~revokeperms);
- vm_map_simplify_entry(map, vme);
- }
- vm_map_lock_downgrade(map);
- }
- vm_map_unlock_read(map);
-}
-
-/*
- * When the subject's label changes, it may require revocation of privilege
- * to mapped objects. This can't be done on-the-fly later with a unified
- * buffer cache.
- */
-static void
-mac_relabel_cred(struct ucred *cred, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_cred, cred, newlabel);
-}
-
-void
-mac_relabel_vnode(struct ucred *cred, struct vnode *vp, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_vnode, cred, vp, &vp->v_label, newlabel);
-}
-
-void
-mac_create_ifnet(struct ifnet *ifnet)
-{
-
- MAC_PERFORM(create_ifnet, ifnet, &ifnet->if_label);
-}
-
-void
-mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(create_bpfdesc, cred, bpf_d, &bpf_d->bd_label);
-}
-
-void
-mac_create_socket(struct ucred *cred, struct socket *socket)
-{
-
- MAC_PERFORM(create_socket, cred, socket, &socket->so_label);
-}
-
-void
-mac_create_pipe(struct ucred *cred, struct pipe *pipe)
-{
-
- MAC_PERFORM(create_pipe, cred, pipe, pipe->pipe_label);
-}
-
-void
-mac_create_socket_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(create_socket_from_socket, oldsocket, &oldsocket->so_label,
- newsocket, &newsocket->so_label);
-}
-
-static void
-mac_relabel_socket(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_socket, cred, socket, &socket->so_label, newlabel);
-}
-
-static void
-mac_relabel_pipe(struct ucred *cred, struct pipe *pipe, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_pipe, cred, pipe, pipe->pipe_label, newlabel);
-}
-
-void
-mac_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct socket *socket)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(set_socket_peer_from_mbuf, mbuf, label, socket,
- &socket->so_peerlabel);
-}
-
-void
-mac_set_socket_peer_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(set_socket_peer_from_socket, oldsocket,
- &oldsocket->so_label, newsocket, &newsocket->so_peerlabel);
-}
-
-void
-mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram)
-{
- struct label *label;
-
- label = mbuf_to_label(datagram);
-
- MAC_PERFORM(create_datagram_from_ipq, ipq, &ipq->ipq_label,
- datagram, label);
-}
-
-void
-mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment)
-{
- struct label *datagramlabel, *fragmentlabel;
-
- datagramlabel = mbuf_to_label(datagram);
- fragmentlabel = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_fragment, datagram, datagramlabel, fragment,
- fragmentlabel);
-}
-
-void
-mac_create_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_mbuf(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_from_mbuf, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-void
-mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_bpfdesc, bpf_d, &bpf_d->bd_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_linklayer, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_ifnet, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf, struct ifnet *ifnet,
- struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_multicast_encap, oldmbuf, oldmbuflabel,
- ifnet, &ifnet->if_label, newmbuf, newmbuflabel);
-}
-
-void
-mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_netlayer, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-int
-mac_fragment_match(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
- int result;
-
- label = mbuf_to_label(fragment);
-
- result = 1;
- MAC_BOOLEAN(fragment_match, &&, fragment, label, ipq,
- &ipq->ipq_label);
-
- return (result);
-}
-
-void
-mac_update_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(update_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_socket(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_socket, socket, &socket->so_label, mbuf,
- label);
-}
-
-void
-mac_create_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-void
-mac_create_root_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_root_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-int
-mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet)
-{
- int error;
-
- if (!mac_enforce_network)
- return (0);
-
- MAC_CHECK(check_bpfdesc_receive, bpf_d, &bpf_d->bd_label, ifnet,
- &ifnet->if_label);
-
- return (error);
-}
-
-static int
-mac_check_cred_relabel(struct ucred *cred, struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_cred_relabel, cred, newlabel);
-
- return (error);
-}
-
-int
-mac_check_cred_visible(struct ucred *u1, struct ucred *u2)
-{
- int error;
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_cred_visible, u1, u2);
-
- return (error);
-}
-
-int
-mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- M_ASSERTPKTHDR(mbuf);
-
- if (!mac_enforce_network)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_ifnet_transmit, ifnet, &ifnet->if_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_kenv_dump(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_dump, cred);
-
- return (error);
-}
-
-int
-mac_check_kenv_get(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_get, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kenv_set(struct ucred *cred, char *name, char *value)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_set, cred, name, value);
-
- return (error);
-}
-
-int
-mac_check_kenv_unset(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_unset, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kld_load(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_kld_load");
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_load, cred, vp, &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_kld_stat(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_stat, cred);
-
- return (error);
-}
-
-int
-mac_check_kld_unload(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_unload, cred);
-
- return (error);
-}
-
-int
-mac_check_mount_stat(struct ucred *cred, struct mount *mount)
-{
- int error;
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_mount_stat, cred, mount, &mount->mnt_mntlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, unsigned long cmd,
- void *data)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_ioctl, cred, pipe, pipe->pipe_label, cmd, data);
-
- return (error);
-}
-
-int
-mac_check_pipe_poll(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_poll, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_read(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_read, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-static int
-mac_check_pipe_relabel(struct ucred *cred, struct pipe *pipe,
- struct label *newlabel)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_relabel, cred, pipe, pipe->pipe_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_stat(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_stat, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_write(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_write, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_proc_debug(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_debug, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_sched(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_sched, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_signal(struct ucred *cred, struct proc *proc, int signum)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_signal, cred, proc, signum);
-
- return (error);
-}
-
-int
-mac_check_socket_bind(struct ucred *ucred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_bind, ucred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_connect(struct ucred *cred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_connect, cred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_deliver(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_socket_deliver, socket, &socket->so_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_socket_listen(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_listen, cred, socket, &socket->so_label);
- return (error);
-}
-
-int
-mac_check_socket_receive(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_receive, cred, so, &so->so_label);
-
- return (error);
-}
-
-static int
-mac_check_socket_relabel(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_socket_relabel, cred, socket, &socket->so_label,
- newlabel);
-
- return (error);
-}
-
-int
-mac_check_socket_send(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_send, cred, so, &so->so_label);
-
- return (error);
-}
-
-int
-mac_check_socket_visible(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_visible, cred, socket, &socket->so_label);
-
- return (error);
-}
-
-int
-mac_check_sysarch_ioperm(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_sysarch_ioperm, cred);
- return (error);
-}
-
-int
-mac_check_system_acct(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- if (vp != NULL) {
- ASSERT_VOP_LOCKED(vp, "mac_check_system_acct");
- }
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_acct, cred, vp,
- vp != NULL ? &vp->v_label : NULL);
-
- return (error);
-}
-
-int
-mac_check_system_nfsd(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_nfsd, cred);
-
- return (error);
-}
-
-int
-mac_check_system_reboot(struct ucred *cred, int howto)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_reboot, cred, howto);
-
- return (error);
-}
-
-int
-mac_check_system_settime(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_settime, cred);
-
- return (error);
-}
-
-int
-mac_check_system_swapon(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapon");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapon, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_swapoff(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapoff");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapoff, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_sysctl(struct ucred *cred, int *name, u_int namelen,
- void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen)
-{
- int error;
-
- /*
- * XXXMAC: We're very much like to assert the SYSCTL_LOCK here,
- * but since it's not exported from kern_sysctl.c, we can't.
- */
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_sysctl, cred, name, namelen, old, oldlenp,
- inkernel, new, newlen);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_ifnet_label(&ifnet->if_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- struct label intlabel;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_ifnet_label(&intlabel);
- error = mac_internalize_ifnet_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- /*
- * XXX: Note that this is a redundant privilege check, since
- * policies impose this check themselves if required by the
- * policy. Eventually, this should go away.
- */
- error = suser_cred(cred, 0);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_CHECK(check_ifnet_relabel, cred, ifnet, &ifnet->if_label,
- &intlabel);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_PERFORM(relabel_ifnet, cred, ifnet, &ifnet->if_label, &intlabel);
-
- mac_destroy_ifnet_label(&intlabel);
- return (0);
-}
-
-void
-mac_create_devfs_device(struct mount *mp, dev_t dev, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_device, mp, dev, de, &de->de_label);
-}
-
-void
-mac_create_devfs_symlink(struct ucred *cred, struct mount *mp,
- struct devfs_dirent *dd, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_symlink, cred, mp, dd, &dd->de_label, de,
- &de->de_label);
-}
-
-void
-mac_create_devfs_directory(struct mount *mp, char *dirname, int dirnamelen,
- struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_directory, mp, dirname, dirnamelen, de,
- &de->de_label);
-}
-
-int
-mac_setsockopt_label_set(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- struct label intlabel;
- char *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, buffer, mac->m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_socket_label(&intlabel, M_WAITOK);
- error = mac_internalize_socket_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_check_socket_relabel(cred, so, &intlabel);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_relabel_socket(cred, so, &intlabel);
-
- mac_destroy_socket_label(&intlabel);
- return (0);
-}
-
-int
-mac_pipe_label_set(struct ucred *cred, struct pipe *pipe, struct label *label)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- error = mac_check_pipe_relabel(cred, pipe, label);
- if (error)
- return (error);
-
- mac_relabel_pipe(cred, pipe, label);
-
- return (0);
-}
-
-int
-mac_getsockopt_label_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *buffer, *elements;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_label(&so->so_label, elements,
- buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_getsockopt_peerlabel_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *elements, *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_peer_label(&so->so_peerlabel,
- elements, buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * Implementation of VOP_SETLABEL() that relies on extended attributes
- * to store label data. Can be referenced by filesystems supporting
- * extended attributes.
- */
-int
-vop_stdsetlabel_ea(struct vop_setlabel_args *ap)
-{
- struct vnode *vp = ap->a_vp;
- struct label *intlabel = ap->a_label;
- int error;
-
- ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea");
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- error = mac_setlabel_vnode_extattr(ap->a_cred, vp, intlabel);
- if (error)
- return (error);
-
- mac_relabel_vnode(ap->a_cred, vp, intlabel);
-
- return (0);
-}
-
-static int
-vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred)
-{
- int error;
-
- if (vp->v_mount == NULL) {
- /* printf("vn_setlabel: null v_mount\n"); */
- if (vp->v_type != VNON)
- printf("vn_setlabel: null v_mount with non-VNON\n");
- return (EBADF);
- }
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- /*
- * Multi-phase commit. First check the policies to confirm the
- * change is OK. Then commit via the filesystem. Finally,
- * update the actual vnode label. Question: maybe the filesystem
- * should update the vnode at the end as part of VOP_SETLABEL()?
- */
- error = mac_check_vnode_relabel(cred, vp, intlabel);
- if (error)
- return (error);
-
- /*
- * VADMIN provides the opportunity for the filesystem to make
- * decisions about who is and is not able to modify labels
- * and protections on files. This might not be right. We can't
- * assume VOP_SETLABEL() will do it, because we might implement
- * that as part of vop_stdsetlabel_ea().
- */
- error = VOP_ACCESS(vp, VADMIN, cred, curthread);
- if (error)
- return (error);
-
- error = VOP_SETLABEL(vp, intlabel, cred, curthread);
- if (error)
- return (error);
-
- return (0);
-}
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- struct proc *tproc;
- struct ucred *tcred;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- tproc = pfind(uap->pid);
- if (tproc == NULL)
- return (ESRCH);
-
- tcred = NULL; /* Satisfy gcc. */
- error = p_cansee(td, tproc);
- if (error == 0)
- tcred = crhold(tproc->p_ucred);
- PROC_UNLOCK(tproc);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&tcred->cr_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&td->td_ucred->cr_label,
- elements, buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
- struct ucred *newcred, *oldcred;
- struct label intlabel;
- struct proc *p;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(&intlabel);
- error = mac_internalize_cred_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(&intlabel);
- return (error);
- }
-
- newcred = crget();
-
- p = td->td_proc;
- PROC_LOCK(p);
- oldcred = p->p_ucred;
-
- error = mac_check_cred_relabel(oldcred, &intlabel);
- if (error) {
- PROC_UNLOCK(p);
- crfree(newcred);
- goto out;
- }
-
- setsugid(p);
- crcopy(newcred, oldcred);
- mac_relabel_cred(newcred, &intlabel);
- p->p_ucred = newcred;
-
- /*
- * Grab additional reference for use while revoking mmaps, prior
- * to releasing the proc lock and sharing the cred.
- */
- crhold(newcred);
- PROC_UNLOCK(p);
-
- if (mac_enforce_vm) {
- mtx_lock(&Giant);
- mac_cred_mmapped_drop_perms(td, newcred);
- mtx_unlock(&Giant);
- }
-
- crfree(newcred); /* Free revocation reference. */
- crfree(oldcred);
-
-out:
- mac_destroy_cred_label(&intlabel);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
- char *elements, *buffer;
- struct label intlabel;
- struct file *fp;
- struct mac mac;
- struct vnode *vp;
- struct pipe *pipe;
- short label_type;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- label_type = fp->f_type;
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- vp = fp->f_data;
-
- mac_init_vnode_label(&intlabel);
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- mac_copy_vnode_label(&vp->v_label, &intlabel);
- VOP_UNLOCK(vp, 0, td);
-
- break;
- case DTYPE_PIPE:
- pipe = fp->f_data;
-
- mac_init_pipe_label(&intlabel);
-
- PIPE_LOCK(pipe);
- mac_copy_pipe_label(pipe->pipe_label, &intlabel);
- PIPE_UNLOCK(pipe);
- break;
- default:
- error = EINVAL;
- fdrop(fp, td);
- goto out;
- }
- fdrop(fp, td);
-
- switch (label_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- if (error == 0)
- error = mac_externalize_vnode_label(&intlabel,
- elements, buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_vnode_label(&intlabel);
- break;
- case DTYPE_PIPE:
- error = mac_externalize_pipe_label(&intlabel, elements,
- buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_pipe_label(&intlabel);
- break;
- default:
- panic("__mac_get_fd: corrupted label_type");
- }
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
-
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
- struct label intlabel;
- struct pipe *pipe;
- struct file *fp;
- struct mount *mp;
- struct vnode *vp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vp = fp->f_data;
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error != 0) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- error = vn_setlabel(vp, &intlabel, td->td_ucred);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
-
- mac_destroy_vnode_label(&intlabel);
- break;
-
- case DTYPE_PIPE:
- mac_init_pipe_label(&intlabel);
- error = mac_internalize_pipe_label(&intlabel, buffer);
- if (error == 0) {
- pipe = fp->f_data;
- PIPE_LOCK(pipe);
- error = mac_pipe_label_set(td->td_ucred, pipe,
- &intlabel);
- PIPE_UNLOCK(pipe);
- }
-
- mac_destroy_pipe_label(&intlabel);
- break;
-
- default:
- error = EINVAL;
- }
-
- fdrop(fp, td);
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
- struct mac_policy_conf *mpc;
- char target[MAC_MAX_POLICY_NAME];
- int entrycount, error;
-
- error = copyinstr(uap->policy, target, sizeof(target), NULL);
- if (error)
- return (error);
-
- error = ENOSYS;
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- goto out;
- }
- }
-
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) {
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- break;
- }
- }
- mac_policy_list_unbusy();
- }
-out:
- return (error);
-}
-
-SYSINIT(mac, SI_SUB_MAC, SI_ORDER_FIRST, mac_init, NULL);
-SYSINIT(mac_late, SI_SUB_MAC_LATE, SI_ORDER_FIRST, mac_late_init, NULL);
-
-#else /* !MAC */
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
-
- return (ENOSYS);
-}
-
-#endif
diff --git a/sys/security/mac/mac_system.c b/sys/security/mac/mac_system.c
deleted file mode 100644
index fb06edea3012..000000000000
--- a/sys/security/mac/mac_system.c
+++ /dev/null
@@ -1,3975 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * Copyright (c) 2001 Ilmar S. Habibulin
- * Copyright (c) 2001, 2002, 2003 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * This software was developed by Robert Watson and Ilmar Habibulin for the
- * TrustedBSD Project.
- *
- * This software was developed for the FreeBSD Project in part by Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
- * as part of the DARPA CHATS research program.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-/*
- * Developed by the TrustedBSD Project.
- *
- * Framework for extensible kernel access control. Kernel and userland
- * interface to the framework, policy registration and composition.
- */
-
-#include "opt_mac.h"
-#include "opt_devfs.h"
-
-#include <sys/param.h>
-#include <sys/condvar.h>
-#include <sys/extattr.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/mac.h>
-#include <sys/module.h>
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/sysent.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/file.h>
-#include <sys/namei.h>
-#include <sys/socket.h>
-#include <sys/pipe.h>
-#include <sys/socketvar.h>
-#include <sys/sysctl.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-
-#include <sys/mac_policy.h>
-
-#include <fs/devfs/devfs.h>
-
-#include <net/bpfdesc.h>
-#include <net/if.h>
-#include <net/if_var.h>
-
-#include <netinet/in.h>
-#include <netinet/ip_var.h>
-
-#ifdef MAC
-
-/*
- * Declare that the kernel provides MAC support, version 1. This permits
- * modules to refuse to be loaded if the necessary support isn't present,
- * even if it's pre-boot.
- */
-MODULE_VERSION(kernel_mac_support, 1);
-
-SYSCTL_DECL(_security);
-
-SYSCTL_NODE(_security, OID_AUTO, mac, CTLFLAG_RW, 0,
- "TrustedBSD MAC policy controls");
-
-#if MAC_MAX_SLOTS > 32
-#error "MAC_MAX_SLOTS too large"
-#endif
-
-static unsigned int mac_max_slots = MAC_MAX_SLOTS;
-static unsigned int mac_slot_offsets_free = (1 << MAC_MAX_SLOTS) - 1;
-SYSCTL_UINT(_security_mac, OID_AUTO, max_slots, CTLFLAG_RD,
- &mac_max_slots, 0, "");
-
-/*
- * Has the kernel started generating labeled objects yet? All read/write
- * access to this variable is serialized during the boot process. Following
- * the end of serialization, we don't update this flag; no locking.
- */
-static int mac_late = 0;
-
-/*
- * Warn about EA transactions only the first time they happen.
- * Weak coherency, no locking.
- */
-static int ea_warn_once = 0;
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
-/*
- * Flag to indicate whether or not we should allocate label storage for
- * new mbufs. Since most dynamic policies we currently work with don't
- * rely on mbuf labeling, try to avoid paying the cost of mtag allocation
- * unless specifically notified of interest. One result of this is
- * that if a dynamically loaded policy requests mbuf labels, it must
- * be able to deal with a NULL label being returned on any mbufs that
- * were already in flight when the policy was loaded. Since the policy
- * already has to deal with uninitialized labels, this probably won't
- * be a problem. Note: currently no locking. Will this be a problem?
- */
-static int mac_labelmbufs = 0;
-#endif
-
-static int mac_enforce_fs = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_fs, CTLFLAG_RW,
- &mac_enforce_fs, 0, "Enforce MAC policy on file system objects");
-TUNABLE_INT("security.mac.enforce_fs", &mac_enforce_fs);
-
-static int mac_enforce_kld = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_kld, CTLFLAG_RW,
- &mac_enforce_kld, 0, "Enforce MAC policy on kld operations");
-TUNABLE_INT("security.mac.enforce_kld", &mac_enforce_kld);
-
-static int mac_enforce_network = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_network, CTLFLAG_RW,
- &mac_enforce_network, 0, "Enforce MAC policy on network packets");
-TUNABLE_INT("security.mac.enforce_network", &mac_enforce_network);
-
-static int mac_enforce_pipe = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_pipe, CTLFLAG_RW,
- &mac_enforce_pipe, 0, "Enforce MAC policy on pipe operations");
-TUNABLE_INT("security.mac.enforce_pipe", &mac_enforce_pipe);
-
-static int mac_enforce_process = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_process, CTLFLAG_RW,
- &mac_enforce_process, 0, "Enforce MAC policy on inter-process operations");
-TUNABLE_INT("security.mac.enforce_process", &mac_enforce_process);
-
-static int mac_enforce_socket = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_socket, CTLFLAG_RW,
- &mac_enforce_socket, 0, "Enforce MAC policy on socket operations");
-TUNABLE_INT("security.mac.enforce_socket", &mac_enforce_socket);
-
-static int mac_enforce_system = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_system, CTLFLAG_RW,
- &mac_enforce_system, 0, "Enforce MAC policy on system operations");
-TUNABLE_INT("security.mac.enforce_system", &mac_enforce_system);
-
-static int mac_enforce_vm = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_vm, CTLFLAG_RW,
- &mac_enforce_vm, 0, "Enforce MAC policy on vm operations");
-TUNABLE_INT("security.mac.enforce_vm", &mac_enforce_vm);
-
-static int mac_mmap_revocation = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation, CTLFLAG_RW,
- &mac_mmap_revocation, 0, "Revoke mmap access to files on subject "
- "relabel");
-static int mac_mmap_revocation_via_cow = 0;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation_via_cow, CTLFLAG_RW,
- &mac_mmap_revocation_via_cow, 0, "Revoke mmap access to files via "
- "copy-on-write semantics, or by removing all write access");
-
-#ifdef MAC_DEBUG
-SYSCTL_NODE(_security_mac, OID_AUTO, debug, CTLFLAG_RW, 0,
- "TrustedBSD MAC debug info");
-
-static int mac_debug_label_fallback = 0;
-SYSCTL_INT(_security_mac_debug, OID_AUTO, label_fallback, CTLFLAG_RW,
- &mac_debug_label_fallback, 0, "Filesystems should fall back to fs label"
- "when label is corrupted.");
-TUNABLE_INT("security.mac.debug_label_fallback",
- &mac_debug_label_fallback);
-
-SYSCTL_NODE(_security_mac_debug, OID_AUTO, counters, CTLFLAG_RW, 0,
- "TrustedBSD MAC object counters");
-
-static unsigned int nmacmbufs, nmaccreds, nmacifnets, nmacbpfdescs,
- nmacsockets, nmacmounts, nmactemp, nmacvnodes, nmacdevfsdirents,
- nmacipqs, nmacpipes, nmacprocs;
-
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mbufs, CTLFLAG_RD,
- &nmacmbufs, 0, "number of mbufs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, creds, CTLFLAG_RD,
- &nmaccreds, 0, "number of ucreds in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ifnets, CTLFLAG_RD,
- &nmacifnets, 0, "number of ifnets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ipqs, CTLFLAG_RD,
- &nmacipqs, 0, "number of ipqs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, bpfdescs, CTLFLAG_RD,
- &nmacbpfdescs, 0, "number of bpfdescs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, sockets, CTLFLAG_RD,
- &nmacsockets, 0, "number of sockets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, pipes, CTLFLAG_RD,
- &nmacpipes, 0, "number of pipes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, procs, CTLFLAG_RD,
- &nmacprocs, 0, "number of procs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mounts, CTLFLAG_RD,
- &nmacmounts, 0, "number of mounts in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, temp, CTLFLAG_RD,
- &nmactemp, 0, "number of temporary labels in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, vnodes, CTLFLAG_RD,
- &nmacvnodes, 0, "number of vnodes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, devfsdirents, CTLFLAG_RD,
- &nmacdevfsdirents, 0, "number of devfs dirents inuse");
-#endif
-
-static int error_select(int error1, int error2);
-static int mac_policy_register(struct mac_policy_conf *mpc);
-static int mac_policy_unregister(struct mac_policy_conf *mpc);
-
-static void mac_check_vnode_mmap_downgrade(struct ucred *cred,
- struct vnode *vp, int *prot);
-static void mac_cred_mmapped_drop_perms_recurse(struct thread *td,
- struct ucred *cred, struct vm_map *map);
-
-static void mac_destroy_socket_label(struct label *label);
-
-static int mac_setlabel_vnode_extattr(struct ucred *cred,
- struct vnode *vp, struct label *intlabel);
-
-MALLOC_DEFINE(M_MACPIPELABEL, "macpipelabel", "MAC labels for pipes");
-MALLOC_DEFINE(M_MACTEMP, "mactemp", "MAC temporary label storage");
-
-/*
- * mac_static_policy_list holds a list of policy modules that are not
- * loaded while the system is "live", and cannot be unloaded. These
- * policies can be invoked without holding the busy count.
- *
- * mac_policy_list stores the list of dynamic policies. A busy count is
- * maintained for the list, stored in mac_policy_busy. The busy count
- * is protected by mac_policy_mtx; the list may be modified only
- * while the busy count is 0, requiring that the lock be held to
- * prevent new references to the list from being acquired. For almost
- * all operations, incrementing the busy count is sufficient to
- * guarantee consistency, as the list cannot be modified while the
- * busy count is elevated. For a few special operations involving a
- * change to the list of active policies, the mtx itself must be held.
- * A condition variable, mac_policy_cv, is used to signal potential
- * exclusive consumers that they should try to acquire the lock if a
- * first attempt at exclusive access fails.
- */
-static struct mtx mac_policy_mtx;
-static struct cv mac_policy_cv;
-static int mac_policy_count;
-static LIST_HEAD(, mac_policy_conf) mac_policy_list;
-static LIST_HEAD(, mac_policy_conf) mac_static_policy_list;
-
-/*
- * We manually invoke WITNESS_WARN() to allow Witness to generate
- * warnings even if we don't end up ever triggering the wait at
- * run-time. The consumer of the exclusive interface must not hold
- * any locks (other than potentially Giant) since we may sleep for
- * long (potentially indefinite) periods of time waiting for the
- * framework to become quiescent so that a policy list change may
- * be made.
- */
-static __inline void
-mac_policy_grab_exclusive(void)
-{
- WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
- "mac_policy_grab_exclusive() at %s:%d", __FILE__, __LINE__);
- mtx_lock(&mac_policy_mtx);
- while (mac_policy_count != 0)
- cv_wait(&mac_policy_cv, &mac_policy_mtx);
-}
-
-static __inline void
-mac_policy_assert_exclusive(void)
-{
- mtx_assert(&mac_policy_mtx, MA_OWNED);
- KASSERT(mac_policy_count == 0,
- ("mac_policy_assert_exclusive(): not exclusive"));
-}
-
-static __inline void
-mac_policy_release_exclusive(void)
-{
-
- KASSERT(mac_policy_count == 0,
- ("mac_policy_release_exclusive(): not exclusive"));
- mtx_unlock(&mac_policy_mtx);
- cv_signal(&mac_policy_cv);
-}
-
-static __inline void
-mac_policy_list_busy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count++;
- mtx_unlock(&mac_policy_mtx);
-}
-
-static __inline int
-mac_policy_list_conditional_busy(void)
-{
- int ret;
-
- mtx_lock(&mac_policy_mtx);
- if (!LIST_EMPTY(&mac_policy_list)) {
- mac_policy_count++;
- ret = 1;
- } else
- ret = 0;
- mtx_unlock(&mac_policy_mtx);
- return (ret);
-}
-
-static __inline void
-mac_policy_list_unbusy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count--;
- KASSERT(mac_policy_count >= 0, ("MAC_POLICY_LIST_LOCK"));
- if (mac_policy_count == 0)
- cv_signal(&mac_policy_cv);
- mtx_unlock(&mac_policy_mtx);
-}
-
-/*
- * MAC_CHECK performs the designated check by walking the policy
- * module list and checking with each as to how it feels about the
- * request. Note that it returns its value via 'error' in the scope
- * of the caller.
- */
-#define MAC_CHECK(check, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- error = 0; \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * MAC_BOOLEAN performs the designated boolean composition by walking
- * the module list, invoking each instance of the operation, and
- * combining the results using the passed C operator. Note that it
- * returns its value via 'result' in the scope of the caller, which
- * should be initialized by the caller in a meaningful way to get
- * a meaningful result.
- */
-#define MAC_BOOLEAN(operation, composition, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation \
- (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-#define MAC_EXTERNALIZE(type, label, elementlist, outbuf, \
- outbuflen) do { \
- char *curptr, *curptr_start, *element_name, *element_temp; \
- size_t left, left_start, len; \
- int claimed, first, first_start, ignorenotfound; \
- \
- error = 0; \
- element_temp = elementlist; \
- curptr = outbuf; \
- curptr[0] = '\0'; \
- left = outbuflen; \
- first = 1; \
- while ((element_name = strsep(&element_temp, ",")) != NULL) { \
- curptr_start = curptr; \
- left_start = left; \
- first_start = first; \
- if (element_name[0] == '?') { \
- element_name++; \
- ignorenotfound = 1; \
- } else \
- ignorenotfound = 0; \
- claimed = 0; \
- if (first) { \
- len = snprintf(curptr, left, "%s/", \
- element_name); \
- first = 0; \
- } else \
- len = snprintf(curptr, left, ",%s/", \
- element_name); \
- if (len >= left) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- \
- MAC_CHECK(externalize_ ## type, label, element_name, \
- curptr, left, &len, &claimed); \
- if (error) \
- break; \
- if (claimed == 1) { \
- if (len >= outbuflen) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- } else if (claimed == 0 && ignorenotfound) { \
- /* \
- * Revert addition of the label element \
- * name. \
- */ \
- curptr = curptr_start; \
- *curptr = '\0'; \
- left = left_start; \
- first = first_start; \
- } else { \
- error = EINVAL; /* XXXMAC: ENOLABEL */ \
- break; \
- } \
- } \
-} while (0)
-
-#define MAC_INTERNALIZE(type, label, instring) do { \
- char *element, *element_name, *element_data; \
- int claimed; \
- \
- error = 0; \
- element = instring; \
- while ((element_name = strsep(&element, ",")) != NULL) { \
- element_data = element_name; \
- element_name = strsep(&element_data, "/"); \
- if (element_data == NULL) { \
- error = EINVAL; \
- break; \
- } \
- claimed = 0; \
- MAC_CHECK(internalize_ ## type, label, element_name, \
- element_data, &claimed); \
- if (error) \
- break; \
- if (claimed != 1) { \
- /* XXXMAC: Another error here? */ \
- error = EINVAL; \
- break; \
- } \
- } \
-} while (0)
-
-/*
- * MAC_PERFORM performs the designated operation by walking the policy
- * module list and invoking that operation for each policy.
- */
-#define MAC_PERFORM(operation, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * Initialize the MAC subsystem, including appropriate SMP locks.
- */
-static void
-mac_init(void)
-{
-
- LIST_INIT(&mac_static_policy_list);
- LIST_INIT(&mac_policy_list);
-
- mtx_init(&mac_policy_mtx, "mac_policy_mtx", NULL, MTX_DEF);
- cv_init(&mac_policy_cv, "mac_policy_cv");
-}
-
-/*
- * For the purposes of modules that want to know if they were loaded
- * "early", set the mac_late flag once we've processed modules either
- * linked into the kernel, or loaded before the kernel startup.
- */
-static void
-mac_late_init(void)
-{
-
- mac_late = 1;
-}
-
-/*
- * After the policy list has changed, walk the list to update any global
- * flags.
- */
-static void
-mac_policy_updateflags(void)
-{
- struct mac_policy_conf *tmpc;
-#ifndef MAC_ALWAYS_LABEL_MBUF
- int labelmbufs;
-#endif
-
- mac_policy_assert_exclusive();
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- labelmbufs = 0;
-#endif
-
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- mac_labelmbufs = (labelmbufs != 0);
-#endif
-}
-
-/*
- * Allow MAC policy modules to register during boot, etc.
- */
-int
-mac_policy_modevent(module_t mod, int type, void *data)
-{
- struct mac_policy_conf *mpc;
- int error;
-
- error = 0;
- mpc = (struct mac_policy_conf *) data;
-
- switch (type) {
- case MOD_LOAD:
- if (mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_NOTLATE &&
- mac_late) {
- printf("mac_policy_modevent: can't load %s policy "
- "after booting\n", mpc->mpc_name);
- error = EBUSY;
- break;
- }
- error = mac_policy_register(mpc);
- break;
- case MOD_UNLOAD:
- /* Don't unregister the module if it was never registered. */
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED)
- != 0)
- error = mac_policy_unregister(mpc);
- else
- error = 0;
- break;
- default:
- break;
- }
-
- return (error);
-}
-
-static int
-mac_policy_register(struct mac_policy_conf *mpc)
-{
- struct mac_policy_conf *tmpc;
- int error, slot, static_entry;
-
- error = 0;
-
- /*
- * We don't technically need exclusive access while !mac_late,
- * but hold it for assertion consistency.
- */
- mac_policy_grab_exclusive();
-
- /*
- * If the module can potentially be unloaded, or we're loading
- * late, we have to stick it in the non-static list and pay
- * an extra performance overhead. Otherwise, we can pay a
- * light locking cost and stick it in the static list.
- */
- static_entry = (!mac_late &&
- !(mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK));
-
- if (static_entry) {
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- } else {
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- }
- if (mpc->mpc_field_off != NULL) {
- slot = ffs(mac_slot_offsets_free);
- if (slot == 0) {
- error = ENOMEM;
- goto out;
- }
- slot--;
- mac_slot_offsets_free &= ~(1 << slot);
- *mpc->mpc_field_off = slot;
- }
- mpc->mpc_runtime_flags |= MPC_RUNTIME_FLAG_REGISTERED;
-
- /*
- * If we're loading a MAC module after the framework has
- * initialized, it has to go into the dynamic list. If
- * we're loading it before we've finished initializing,
- * it can go into the static list with weaker locker
- * requirements.
- */
- if (static_entry)
- LIST_INSERT_HEAD(&mac_static_policy_list, mpc, mpc_list);
- else
- LIST_INSERT_HEAD(&mac_policy_list, mpc, mpc_list);
-
- /* Per-policy initialization. */
- if (mpc->mpc_ops->mpo_init != NULL)
- (*(mpc->mpc_ops->mpo_init))(mpc);
- mac_policy_updateflags();
-
- printf("Security policy loaded: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
-out:
- mac_policy_release_exclusive();
- return (error);
-}
-
-static int
-mac_policy_unregister(struct mac_policy_conf *mpc)
-{
-
- /*
- * If we fail the load, we may get a request to unload. Check
- * to see if we did the run-time registration, and if not,
- * silently succeed.
- */
- mac_policy_grab_exclusive();
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED) == 0) {
- mac_policy_release_exclusive();
- return (0);
- }
-#if 0
- /*
- * Don't allow unloading modules with private data.
- */
- if (mpc->mpc_field_off != NULL) {
- MAC_POLICY_LIST_UNLOCK();
- return (EBUSY);
- }
-#endif
- /*
- * Only allow the unload to proceed if the module is unloadable
- * by its own definition.
- */
- if ((mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK) == 0) {
- mac_policy_release_exclusive();
- return (EBUSY);
- }
- if (mpc->mpc_ops->mpo_destroy != NULL)
- (*(mpc->mpc_ops->mpo_destroy))(mpc);
-
- LIST_REMOVE(mpc, mpc_list);
- mpc->mpc_runtime_flags &= ~MPC_RUNTIME_FLAG_REGISTERED;
- mac_policy_updateflags();
-
- mac_policy_release_exclusive();
-
- printf("Security policy unload: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
- return (0);
-}
-
-/*
- * Define an error value precedence, and given two arguments, selects the
- * value with the higher precedence.
- */
-static int
-error_select(int error1, int error2)
-{
-
- /* Certain decision-making errors take top priority. */
- if (error1 == EDEADLK || error2 == EDEADLK)
- return (EDEADLK);
-
- /* Invalid arguments should be reported where possible. */
- if (error1 == EINVAL || error2 == EINVAL)
- return (EINVAL);
-
- /* Precedence goes to "visibility", with both process and file. */
- if (error1 == ESRCH || error2 == ESRCH)
- return (ESRCH);
-
- if (error1 == ENOENT || error2 == ENOENT)
- return (ENOENT);
-
- /* Precedence goes to DAC/MAC protections. */
- if (error1 == EACCES || error2 == EACCES)
- return (EACCES);
-
- /* Precedence goes to privilege. */
- if (error1 == EPERM || error2 == EPERM)
- return (EPERM);
-
- /* Precedence goes to error over success; otherwise, arbitrary. */
- if (error1 != 0)
- return (error1);
- return (error2);
-}
-
-static struct label *
-mbuf_to_label(struct mbuf *mbuf)
-{
- struct m_tag *tag;
- struct label *label;
-
- tag = m_tag_find(mbuf, PACKET_TAG_MACLABEL, NULL);
- label = (struct label *)(tag+1);
-
- return (label);
-}
-
-static void
-mac_init_label(struct label *label)
-{
-
- bzero(label, sizeof(*label));
- label->l_flags = MAC_FLAG_INITIALIZED;
-}
-
-static void
-mac_destroy_label(struct label *label)
-{
-
- KASSERT(label->l_flags & MAC_FLAG_INITIALIZED,
- ("destroying uninitialized label"));
-
- bzero(label, sizeof(*label));
- /* implicit: label->l_flags &= ~MAC_FLAG_INITIALIZED; */
-}
-
-void
-mac_init_bpfdesc(struct bpf_d *bpf_d)
-{
-
- mac_init_label(&bpf_d->bd_label);
- MAC_PERFORM(init_bpfdesc_label, &bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_init_cred_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_cred_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_init_cred(struct ucred *cred)
-{
-
- mac_init_cred_label(&cred->cr_label);
-}
-
-void
-mac_init_devfsdirent(struct devfs_dirent *de)
-{
-
- mac_init_label(&de->de_label);
- MAC_PERFORM(init_devfsdirent_label, &de->de_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_init_ifnet_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_ifnet_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_init_ifnet(struct ifnet *ifp)
-{
-
- mac_init_ifnet_label(&ifp->if_label);
-}
-
-int
-mac_init_ipq(struct ipq *ipq, int flag)
-{
- int error;
-
- mac_init_label(&ipq->ipq_label);
-
- MAC_CHECK(init_ipq_label, &ipq->ipq_label, flag);
- if (error) {
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacipqs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf_tag(struct m_tag *tag, int flag)
-{
- struct label *label;
- int error;
-
- label = (struct label *) (tag + 1);
- mac_init_label(label);
-
- MAC_CHECK(init_mbuf_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacmbufs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf(struct mbuf *m, int flag)
-{
- struct m_tag *tag;
- int error;
-
- M_ASSERTPKTHDR(m);
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- /*
- * Don't reserve space for labels on mbufs unless we have a policy
- * that uses the labels.
- */
- if (mac_labelmbufs) {
-#endif
- tag = m_tag_get(PACKET_TAG_MACLABEL, sizeof(struct label),
- flag);
- if (tag == NULL)
- return (ENOMEM);
- error = mac_init_mbuf_tag(tag, flag);
- if (error) {
- m_tag_free(tag);
- return (error);
- }
- m_tag_prepend(m, tag);
-#ifndef MAC_ALWAYS_LABEL_MBUF
- }
-#endif
- return (0);
-}
-
-void
-mac_init_mount(struct mount *mp)
-{
-
- mac_init_label(&mp->mnt_mntlabel);
- mac_init_label(&mp->mnt_fslabel);
- MAC_PERFORM(init_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(init_mount_fs_label, &mp->mnt_fslabel);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_init_pipe_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_pipe_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_init_pipe(struct pipe *pipe)
-{
- struct label *label;
-
- label = malloc(sizeof(struct label), M_MACPIPELABEL, M_ZERO|M_WAITOK);
- pipe->pipe_label = label;
- pipe->pipe_peer->pipe_label = label;
- mac_init_pipe_label(label);
-}
-
-void
-mac_init_proc(struct proc *p)
-{
-
- mac_init_label(&p->p_label);
- MAC_PERFORM(init_proc_label, &p->p_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacprocs, 1);
-#endif
-}
-
-static int
-mac_init_socket_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacsockets, 1);
-#endif
-
- return (error);
-}
-
-static int
-mac_init_socket_peer_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_peer_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
- return (error);
-}
-
-int
-mac_init_socket(struct socket *socket, int flag)
-{
- int error;
-
- error = mac_init_socket_label(&socket->so_label, flag);
- if (error)
- return (error);
-
- error = mac_init_socket_peer_label(&socket->so_peerlabel, flag);
- if (error)
- mac_destroy_socket_label(&socket->so_label);
-
- return (error);
-}
-
-void
-mac_init_vnode_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_vnode_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_init_vnode(struct vnode *vp)
-{
-
- mac_init_vnode_label(&vp->v_label);
-}
-
-void
-mac_destroy_bpfdesc(struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(destroy_bpfdesc_label, &bpf_d->bd_label);
- mac_destroy_label(&bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_destroy_cred_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_cred_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_destroy_cred(struct ucred *cred)
-{
-
- mac_destroy_cred_label(&cred->cr_label);
-}
-
-void
-mac_destroy_devfsdirent(struct devfs_dirent *de)
-{
-
- MAC_PERFORM(destroy_devfsdirent_label, &de->de_label);
- mac_destroy_label(&de->de_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_destroy_ifnet_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_ifnet_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_destroy_ifnet(struct ifnet *ifp)
-{
-
- mac_destroy_ifnet_label(&ifp->if_label);
-}
-
-void
-mac_destroy_ipq(struct ipq *ipq)
-{
-
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacipqs, 1);
-#endif
-}
-
-void
-mac_destroy_mbuf_tag(struct m_tag *tag)
-{
- struct label *label;
-
- label = (struct label *)(tag+1);
-
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmbufs, 1);
-#endif
-}
-
-void
-mac_destroy_mount(struct mount *mp)
-{
-
- MAC_PERFORM(destroy_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(destroy_mount_fs_label, &mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_mntlabel);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_destroy_pipe_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_pipe_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_destroy_pipe(struct pipe *pipe)
-{
-
- mac_destroy_pipe_label(pipe->pipe_label);
- free(pipe->pipe_label, M_MACPIPELABEL);
-}
-
-void
-mac_destroy_proc(struct proc *p)
-{
-
- MAC_PERFORM(destroy_proc_label, &p->p_label);
- mac_destroy_label(&p->p_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacprocs, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacsockets, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_peer_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_peer_label, label);
- mac_destroy_label(label);
-}
-
-void
-mac_destroy_socket(struct socket *socket)
-{
-
- mac_destroy_socket_label(&socket->so_label);
- mac_destroy_socket_peer_label(&socket->so_peerlabel);
-}
-
-void
-mac_destroy_vnode_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_vnode_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_destroy_vnode(struct vnode *vp)
-{
-
- mac_destroy_vnode_label(&vp->v_label);
-}
-
-void
-mac_copy_mbuf_tag(struct m_tag *src, struct m_tag *dest)
-{
- struct label *src_label, *dest_label;
-
- src_label = (struct label *)(src+1);
- dest_label = (struct label *)(dest+1);
-
- /*
- * mac_init_mbuf_tag() is called on the target tag in
- * m_tag_copy(), so we don't need to call it here.
- */
- MAC_PERFORM(copy_mbuf_label, src_label, dest_label);
-}
-
-static void
-mac_copy_pipe_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_pipe_label, src, dest);
-}
-
-void
-mac_copy_vnode_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_vnode_label, src, dest);
-}
-
-static int
-mac_check_structmac_consistent(struct mac *mac)
-{
-
- if (mac->m_buflen > MAC_MAX_LABEL_BUF_LEN)
- return (EINVAL);
-
- return (0);
-}
-
-static int
-mac_externalize_cred_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(cred_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_ifnet_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(ifnet_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_pipe_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(pipe_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_peer_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_peer_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_vnode_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(vnode_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_internalize_cred_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(cred_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_ifnet_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(ifnet_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_pipe_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(pipe_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_socket_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(socket_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_vnode_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(vnode_label, label, string);
-
- return (error);
-}
-
-/*
- * Initialize MAC label for the first kernel process, from which other
- * kernel processes and threads are spawned.
- */
-void
-mac_create_proc0(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc0, cred);
-}
-
-/*
- * Initialize MAC label for the first userland process, from which other
- * userland processes and threads are spawned.
- */
-void
-mac_create_proc1(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc1, cred);
-}
-
-void
-mac_thread_userret(struct thread *td)
-{
-
- MAC_PERFORM(thread_userret, td);
-}
-
-/*
- * When a new process is created, its label must be initialized. Generally,
- * this involves inheritence from the parent process, modulo possible
- * deltas. This function allows that processing to take place.
- */
-void
-mac_create_cred(struct ucred *parent_cred, struct ucred *child_cred)
-{
-
- MAC_PERFORM(create_cred, parent_cred, child_cred);
-}
-
-void
-mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(update_devfsdirent, mp, de, &de->de_label, vp,
- &vp->v_label);
-}
-
-void
-mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_devfs, mp, &mp->mnt_fslabel, de,
- &de->de_label, vp, &vp->v_label);
-}
-
-int
-mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_associate_vnode_extattr");
-
- MAC_CHECK(associate_vnode_extattr, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-
- return (error);
-}
-
-void
-mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_singlelabel, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-}
-
-int
-mac_create_vnode_extattr(struct ucred *cred, struct mount *mp,
- struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_create_vnode_extattr");
- ASSERT_VOP_LOCKED(vp, "mac_create_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(create_vnode_extattr, cred, mp, &mp->mnt_fslabel,
- dvp, &dvp->v_label, vp, &vp->v_label, cnp);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-static int
-mac_setlabel_vnode_extattr(struct ucred *cred, struct vnode *vp,
- struct label *intlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_setlabel_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(setlabel_vnode_extattr, cred, vp, &vp->v_label, intlabel);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-int
-mac_execve_enter(struct image_params *imgp, struct mac *mac_p,
- struct label *execlabelstorage)
-{
- struct mac mac;
- char *buffer;
- int error;
-
- if (mac_p == NULL)
- return (0);
-
- error = copyin(mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(execlabelstorage);
- error = mac_internalize_cred_label(execlabelstorage, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(execlabelstorage);
- return (error);
- }
- imgp->execlabel = execlabelstorage;
- return (0);
-}
-
-void
-mac_execve_exit(struct image_params *imgp)
-{
- if (imgp->execlabel != NULL)
- mac_destroy_cred_label(imgp->execlabel);
-}
-
-void
-mac_execve_transition(struct ucred *old, struct ucred *new, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return;
-
- MAC_PERFORM(execve_transition, old, new, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-}
-
-int
-mac_execve_will_transition(struct ucred *old, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
- int result;
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_will_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- result = 0;
- MAC_BOOLEAN(execve_will_transition, ||, old, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-
- return (result);
-}
-
-int
-mac_check_vnode_access(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_access");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_access, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chroot");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chroot, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_create(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp, struct vattr *vap)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_create");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_create, cred, dvp, &dvp->v_label, cnp, vap);
- return (error);
-}
-
-int
-mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp, struct vnode *vp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_delete");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_delete");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_delete, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
- acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_deleteacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_deleteacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_exec(struct ucred *cred, struct vnode *vp,
- struct image_params *imgp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_exec");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_exec, cred, vp, &vp->v_label, imgp,
- imgp->execlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp, acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_link(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_link");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_link");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_link, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_lookup");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_lookup, cred, dvp, &dvp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mmap, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-void
-mac_check_vnode_mmap_downgrade(struct ucred *cred, struct vnode *vp, int *prot)
-{
- int result = *prot;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap_downgrade");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return;
-
- MAC_PERFORM(check_vnode_mmap_downgrade, cred, vp, &vp->v_label,
- &result);
-
- *prot = result;
-}
-
-int
-mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mprotect");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mprotect, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-int
-mac_check_vnode_open(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_open");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_open, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_poll");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_poll, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_read");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_read, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_readdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_readdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_readlink");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readlink, cred, vp, &vp->v_label);
- return (error);
-}
-
-static int
-mac_check_vnode_relabel(struct ucred *cred, struct vnode *vp,
- struct label *newlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_relabel");
-
- MAC_CHECK(check_vnode_relabel, cred, vp, &vp->v_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_from");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_from");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_from, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, int samedir, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_to");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_to");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_to, cred, dvp, &dvp->v_label, vp,
- vp != NULL ? &vp->v_label : NULL, samedir, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_revoke");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_revoke, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type,
- struct acl *acl)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setacl, cred, vp, &vp->v_label, type, acl);
- return (error);
-}
-
-int
-mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp, u_long flags)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setflags");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setflags, cred, vp, &vp->v_label, flags);
- return (error);
-}
-
-int
-mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp, mode_t mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setmode");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setmode, cred, vp, &vp->v_label, mode);
- return (error);
-}
-
-int
-mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp, uid_t uid,
- gid_t gid)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setowner");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setowner, cred, vp, &vp->v_label, uid, gid);
- return (error);
-}
-
-int
-mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
- struct timespec atime, struct timespec mtime)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setutimes");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setutimes, cred, vp, &vp->v_label, atime,
- mtime);
- return (error);
-}
-
-int
-mac_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_stat");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_stat, active_cred, file_cred, vp,
- &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_write(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_write");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_write, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-/*
- * When relabeling a process, call out to the policies for the maximum
- * permission allowed for each object type we know about in its
- * memory space, and revoke access (in the least surprising ways we
- * know) when necessary. The process lock is not held here.
- */
-void
-mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred)
-{
-
- /* XXX freeze all other threads */
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- &td->td_proc->p_vmspace->vm_map);
- /* XXX allow other threads to continue */
-}
-
-static __inline const char *
-prot2str(vm_prot_t prot)
-{
-
- switch (prot & VM_PROT_ALL) {
- case VM_PROT_READ:
- return ("r--");
- case VM_PROT_READ | VM_PROT_WRITE:
- return ("rw-");
- case VM_PROT_READ | VM_PROT_EXECUTE:
- return ("r-x");
- case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("rwx");
- case VM_PROT_WRITE:
- return ("-w-");
- case VM_PROT_EXECUTE:
- return ("--x");
- case VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("-wx");
- default:
- return ("---");
- }
-}
-
-static void
-mac_cred_mmapped_drop_perms_recurse(struct thread *td, struct ucred *cred,
- struct vm_map *map)
-{
- struct vm_map_entry *vme;
- int result;
- vm_prot_t revokeperms;
- vm_object_t object;
- vm_ooffset_t offset;
- struct vnode *vp;
-
- if (!mac_mmap_revocation)
- return;
-
- vm_map_lock_read(map);
- for (vme = map->header.next; vme != &map->header; vme = vme->next) {
- if (vme->eflags & MAP_ENTRY_IS_SUB_MAP) {
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- vme->object.sub_map);
- continue;
- }
- /*
- * Skip over entries that obviously are not shared.
- */
- if (vme->eflags & (MAP_ENTRY_COW | MAP_ENTRY_NOSYNC) ||
- !vme->max_protection)
- continue;
- /*
- * Drill down to the deepest backing object.
- */
- offset = vme->offset;
- object = vme->object.vm_object;
- if (object == NULL)
- continue;
- while (object->backing_object != NULL) {
- object = object->backing_object;
- offset += object->backing_object_offset;
- }
- /*
- * At the moment, vm_maps and objects aren't considered
- * by the MAC system, so only things with backing by a
- * normal object (read: vnodes) are checked.
- */
- if (object->type != OBJT_VNODE)
- continue;
- vp = (struct vnode *)object->handle;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- result = vme->max_protection;
- mac_check_vnode_mmap_downgrade(cred, vp, &result);
- VOP_UNLOCK(vp, 0, td);
- /*
- * Find out what maximum protection we may be allowing
- * now but a policy needs to get removed.
- */
- revokeperms = vme->max_protection & ~result;
- if (!revokeperms)
- continue;
- printf("pid %ld: revoking %s perms from %#lx:%ld "
- "(max %s/cur %s)\n", (long)td->td_proc->p_pid,
- prot2str(revokeperms), (u_long)vme->start,
- (long)(vme->end - vme->start),
- prot2str(vme->max_protection), prot2str(vme->protection));
- vm_map_lock_upgrade(map);
- /*
- * This is the really simple case: if a map has more
- * max_protection than is allowed, but it's not being
- * actually used (that is, the current protection is
- * still allowed), we can just wipe it out and do
- * nothing more.
- */
- if ((vme->protection & revokeperms) == 0) {
- vme->max_protection -= revokeperms;
- } else {
- if (revokeperms & VM_PROT_WRITE) {
- /*
- * In the more complicated case, flush out all
- * pending changes to the object then turn it
- * copy-on-write.
- */
- vm_object_reference(object);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- VM_OBJECT_LOCK(object);
- vm_object_page_clean(object,
- OFF_TO_IDX(offset),
- OFF_TO_IDX(offset + vme->end - vme->start +
- PAGE_MASK),
- OBJPC_SYNC);
- VM_OBJECT_UNLOCK(object);
- VOP_UNLOCK(vp, 0, td);
- vm_object_deallocate(object);
- /*
- * Why bother if there's no read permissions
- * anymore? For the rest, we need to leave
- * the write permissions on for COW, or
- * remove them entirely if configured to.
- */
- if (!mac_mmap_revocation_via_cow) {
- vme->max_protection &= ~VM_PROT_WRITE;
- vme->protection &= ~VM_PROT_WRITE;
- } if ((revokeperms & VM_PROT_READ) == 0)
- vme->eflags |= MAP_ENTRY_COW |
- MAP_ENTRY_NEEDS_COPY;
- }
- if (revokeperms & VM_PROT_EXECUTE) {
- vme->max_protection &= ~VM_PROT_EXECUTE;
- vme->protection &= ~VM_PROT_EXECUTE;
- }
- if (revokeperms & VM_PROT_READ) {
- vme->max_protection = 0;
- vme->protection = 0;
- }
- pmap_protect(map->pmap, vme->start, vme->end,
- vme->protection & ~revokeperms);
- vm_map_simplify_entry(map, vme);
- }
- vm_map_lock_downgrade(map);
- }
- vm_map_unlock_read(map);
-}
-
-/*
- * When the subject's label changes, it may require revocation of privilege
- * to mapped objects. This can't be done on-the-fly later with a unified
- * buffer cache.
- */
-static void
-mac_relabel_cred(struct ucred *cred, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_cred, cred, newlabel);
-}
-
-void
-mac_relabel_vnode(struct ucred *cred, struct vnode *vp, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_vnode, cred, vp, &vp->v_label, newlabel);
-}
-
-void
-mac_create_ifnet(struct ifnet *ifnet)
-{
-
- MAC_PERFORM(create_ifnet, ifnet, &ifnet->if_label);
-}
-
-void
-mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(create_bpfdesc, cred, bpf_d, &bpf_d->bd_label);
-}
-
-void
-mac_create_socket(struct ucred *cred, struct socket *socket)
-{
-
- MAC_PERFORM(create_socket, cred, socket, &socket->so_label);
-}
-
-void
-mac_create_pipe(struct ucred *cred, struct pipe *pipe)
-{
-
- MAC_PERFORM(create_pipe, cred, pipe, pipe->pipe_label);
-}
-
-void
-mac_create_socket_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(create_socket_from_socket, oldsocket, &oldsocket->so_label,
- newsocket, &newsocket->so_label);
-}
-
-static void
-mac_relabel_socket(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_socket, cred, socket, &socket->so_label, newlabel);
-}
-
-static void
-mac_relabel_pipe(struct ucred *cred, struct pipe *pipe, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_pipe, cred, pipe, pipe->pipe_label, newlabel);
-}
-
-void
-mac_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct socket *socket)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(set_socket_peer_from_mbuf, mbuf, label, socket,
- &socket->so_peerlabel);
-}
-
-void
-mac_set_socket_peer_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(set_socket_peer_from_socket, oldsocket,
- &oldsocket->so_label, newsocket, &newsocket->so_peerlabel);
-}
-
-void
-mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram)
-{
- struct label *label;
-
- label = mbuf_to_label(datagram);
-
- MAC_PERFORM(create_datagram_from_ipq, ipq, &ipq->ipq_label,
- datagram, label);
-}
-
-void
-mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment)
-{
- struct label *datagramlabel, *fragmentlabel;
-
- datagramlabel = mbuf_to_label(datagram);
- fragmentlabel = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_fragment, datagram, datagramlabel, fragment,
- fragmentlabel);
-}
-
-void
-mac_create_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_mbuf(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_from_mbuf, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-void
-mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_bpfdesc, bpf_d, &bpf_d->bd_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_linklayer, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_ifnet, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf, struct ifnet *ifnet,
- struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_multicast_encap, oldmbuf, oldmbuflabel,
- ifnet, &ifnet->if_label, newmbuf, newmbuflabel);
-}
-
-void
-mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_netlayer, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-int
-mac_fragment_match(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
- int result;
-
- label = mbuf_to_label(fragment);
-
- result = 1;
- MAC_BOOLEAN(fragment_match, &&, fragment, label, ipq,
- &ipq->ipq_label);
-
- return (result);
-}
-
-void
-mac_update_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(update_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_socket(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_socket, socket, &socket->so_label, mbuf,
- label);
-}
-
-void
-mac_create_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-void
-mac_create_root_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_root_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-int
-mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet)
-{
- int error;
-
- if (!mac_enforce_network)
- return (0);
-
- MAC_CHECK(check_bpfdesc_receive, bpf_d, &bpf_d->bd_label, ifnet,
- &ifnet->if_label);
-
- return (error);
-}
-
-static int
-mac_check_cred_relabel(struct ucred *cred, struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_cred_relabel, cred, newlabel);
-
- return (error);
-}
-
-int
-mac_check_cred_visible(struct ucred *u1, struct ucred *u2)
-{
- int error;
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_cred_visible, u1, u2);
-
- return (error);
-}
-
-int
-mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- M_ASSERTPKTHDR(mbuf);
-
- if (!mac_enforce_network)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_ifnet_transmit, ifnet, &ifnet->if_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_kenv_dump(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_dump, cred);
-
- return (error);
-}
-
-int
-mac_check_kenv_get(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_get, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kenv_set(struct ucred *cred, char *name, char *value)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_set, cred, name, value);
-
- return (error);
-}
-
-int
-mac_check_kenv_unset(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_unset, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kld_load(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_kld_load");
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_load, cred, vp, &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_kld_stat(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_stat, cred);
-
- return (error);
-}
-
-int
-mac_check_kld_unload(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_unload, cred);
-
- return (error);
-}
-
-int
-mac_check_mount_stat(struct ucred *cred, struct mount *mount)
-{
- int error;
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_mount_stat, cred, mount, &mount->mnt_mntlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, unsigned long cmd,
- void *data)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_ioctl, cred, pipe, pipe->pipe_label, cmd, data);
-
- return (error);
-}
-
-int
-mac_check_pipe_poll(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_poll, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_read(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_read, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-static int
-mac_check_pipe_relabel(struct ucred *cred, struct pipe *pipe,
- struct label *newlabel)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_relabel, cred, pipe, pipe->pipe_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_stat(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_stat, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_write(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_write, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_proc_debug(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_debug, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_sched(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_sched, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_signal(struct ucred *cred, struct proc *proc, int signum)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_signal, cred, proc, signum);
-
- return (error);
-}
-
-int
-mac_check_socket_bind(struct ucred *ucred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_bind, ucred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_connect(struct ucred *cred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_connect, cred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_deliver(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_socket_deliver, socket, &socket->so_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_socket_listen(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_listen, cred, socket, &socket->so_label);
- return (error);
-}
-
-int
-mac_check_socket_receive(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_receive, cred, so, &so->so_label);
-
- return (error);
-}
-
-static int
-mac_check_socket_relabel(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_socket_relabel, cred, socket, &socket->so_label,
- newlabel);
-
- return (error);
-}
-
-int
-mac_check_socket_send(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_send, cred, so, &so->so_label);
-
- return (error);
-}
-
-int
-mac_check_socket_visible(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_visible, cred, socket, &socket->so_label);
-
- return (error);
-}
-
-int
-mac_check_sysarch_ioperm(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_sysarch_ioperm, cred);
- return (error);
-}
-
-int
-mac_check_system_acct(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- if (vp != NULL) {
- ASSERT_VOP_LOCKED(vp, "mac_check_system_acct");
- }
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_acct, cred, vp,
- vp != NULL ? &vp->v_label : NULL);
-
- return (error);
-}
-
-int
-mac_check_system_nfsd(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_nfsd, cred);
-
- return (error);
-}
-
-int
-mac_check_system_reboot(struct ucred *cred, int howto)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_reboot, cred, howto);
-
- return (error);
-}
-
-int
-mac_check_system_settime(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_settime, cred);
-
- return (error);
-}
-
-int
-mac_check_system_swapon(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapon");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapon, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_swapoff(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapoff");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapoff, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_sysctl(struct ucred *cred, int *name, u_int namelen,
- void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen)
-{
- int error;
-
- /*
- * XXXMAC: We're very much like to assert the SYSCTL_LOCK here,
- * but since it's not exported from kern_sysctl.c, we can't.
- */
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_sysctl, cred, name, namelen, old, oldlenp,
- inkernel, new, newlen);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_ifnet_label(&ifnet->if_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- struct label intlabel;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_ifnet_label(&intlabel);
- error = mac_internalize_ifnet_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- /*
- * XXX: Note that this is a redundant privilege check, since
- * policies impose this check themselves if required by the
- * policy. Eventually, this should go away.
- */
- error = suser_cred(cred, 0);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_CHECK(check_ifnet_relabel, cred, ifnet, &ifnet->if_label,
- &intlabel);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_PERFORM(relabel_ifnet, cred, ifnet, &ifnet->if_label, &intlabel);
-
- mac_destroy_ifnet_label(&intlabel);
- return (0);
-}
-
-void
-mac_create_devfs_device(struct mount *mp, dev_t dev, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_device, mp, dev, de, &de->de_label);
-}
-
-void
-mac_create_devfs_symlink(struct ucred *cred, struct mount *mp,
- struct devfs_dirent *dd, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_symlink, cred, mp, dd, &dd->de_label, de,
- &de->de_label);
-}
-
-void
-mac_create_devfs_directory(struct mount *mp, char *dirname, int dirnamelen,
- struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_directory, mp, dirname, dirnamelen, de,
- &de->de_label);
-}
-
-int
-mac_setsockopt_label_set(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- struct label intlabel;
- char *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, buffer, mac->m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_socket_label(&intlabel, M_WAITOK);
- error = mac_internalize_socket_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_check_socket_relabel(cred, so, &intlabel);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_relabel_socket(cred, so, &intlabel);
-
- mac_destroy_socket_label(&intlabel);
- return (0);
-}
-
-int
-mac_pipe_label_set(struct ucred *cred, struct pipe *pipe, struct label *label)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- error = mac_check_pipe_relabel(cred, pipe, label);
- if (error)
- return (error);
-
- mac_relabel_pipe(cred, pipe, label);
-
- return (0);
-}
-
-int
-mac_getsockopt_label_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *buffer, *elements;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_label(&so->so_label, elements,
- buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_getsockopt_peerlabel_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *elements, *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_peer_label(&so->so_peerlabel,
- elements, buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * Implementation of VOP_SETLABEL() that relies on extended attributes
- * to store label data. Can be referenced by filesystems supporting
- * extended attributes.
- */
-int
-vop_stdsetlabel_ea(struct vop_setlabel_args *ap)
-{
- struct vnode *vp = ap->a_vp;
- struct label *intlabel = ap->a_label;
- int error;
-
- ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea");
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- error = mac_setlabel_vnode_extattr(ap->a_cred, vp, intlabel);
- if (error)
- return (error);
-
- mac_relabel_vnode(ap->a_cred, vp, intlabel);
-
- return (0);
-}
-
-static int
-vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred)
-{
- int error;
-
- if (vp->v_mount == NULL) {
- /* printf("vn_setlabel: null v_mount\n"); */
- if (vp->v_type != VNON)
- printf("vn_setlabel: null v_mount with non-VNON\n");
- return (EBADF);
- }
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- /*
- * Multi-phase commit. First check the policies to confirm the
- * change is OK. Then commit via the filesystem. Finally,
- * update the actual vnode label. Question: maybe the filesystem
- * should update the vnode at the end as part of VOP_SETLABEL()?
- */
- error = mac_check_vnode_relabel(cred, vp, intlabel);
- if (error)
- return (error);
-
- /*
- * VADMIN provides the opportunity for the filesystem to make
- * decisions about who is and is not able to modify labels
- * and protections on files. This might not be right. We can't
- * assume VOP_SETLABEL() will do it, because we might implement
- * that as part of vop_stdsetlabel_ea().
- */
- error = VOP_ACCESS(vp, VADMIN, cred, curthread);
- if (error)
- return (error);
-
- error = VOP_SETLABEL(vp, intlabel, cred, curthread);
- if (error)
- return (error);
-
- return (0);
-}
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- struct proc *tproc;
- struct ucred *tcred;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- tproc = pfind(uap->pid);
- if (tproc == NULL)
- return (ESRCH);
-
- tcred = NULL; /* Satisfy gcc. */
- error = p_cansee(td, tproc);
- if (error == 0)
- tcred = crhold(tproc->p_ucred);
- PROC_UNLOCK(tproc);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&tcred->cr_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&td->td_ucred->cr_label,
- elements, buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
- struct ucred *newcred, *oldcred;
- struct label intlabel;
- struct proc *p;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(&intlabel);
- error = mac_internalize_cred_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(&intlabel);
- return (error);
- }
-
- newcred = crget();
-
- p = td->td_proc;
- PROC_LOCK(p);
- oldcred = p->p_ucred;
-
- error = mac_check_cred_relabel(oldcred, &intlabel);
- if (error) {
- PROC_UNLOCK(p);
- crfree(newcred);
- goto out;
- }
-
- setsugid(p);
- crcopy(newcred, oldcred);
- mac_relabel_cred(newcred, &intlabel);
- p->p_ucred = newcred;
-
- /*
- * Grab additional reference for use while revoking mmaps, prior
- * to releasing the proc lock and sharing the cred.
- */
- crhold(newcred);
- PROC_UNLOCK(p);
-
- if (mac_enforce_vm) {
- mtx_lock(&Giant);
- mac_cred_mmapped_drop_perms(td, newcred);
- mtx_unlock(&Giant);
- }
-
- crfree(newcred); /* Free revocation reference. */
- crfree(oldcred);
-
-out:
- mac_destroy_cred_label(&intlabel);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
- char *elements, *buffer;
- struct label intlabel;
- struct file *fp;
- struct mac mac;
- struct vnode *vp;
- struct pipe *pipe;
- short label_type;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- label_type = fp->f_type;
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- vp = fp->f_data;
-
- mac_init_vnode_label(&intlabel);
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- mac_copy_vnode_label(&vp->v_label, &intlabel);
- VOP_UNLOCK(vp, 0, td);
-
- break;
- case DTYPE_PIPE:
- pipe = fp->f_data;
-
- mac_init_pipe_label(&intlabel);
-
- PIPE_LOCK(pipe);
- mac_copy_pipe_label(pipe->pipe_label, &intlabel);
- PIPE_UNLOCK(pipe);
- break;
- default:
- error = EINVAL;
- fdrop(fp, td);
- goto out;
- }
- fdrop(fp, td);
-
- switch (label_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- if (error == 0)
- error = mac_externalize_vnode_label(&intlabel,
- elements, buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_vnode_label(&intlabel);
- break;
- case DTYPE_PIPE:
- error = mac_externalize_pipe_label(&intlabel, elements,
- buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_pipe_label(&intlabel);
- break;
- default:
- panic("__mac_get_fd: corrupted label_type");
- }
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
-
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
- struct label intlabel;
- struct pipe *pipe;
- struct file *fp;
- struct mount *mp;
- struct vnode *vp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vp = fp->f_data;
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error != 0) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- error = vn_setlabel(vp, &intlabel, td->td_ucred);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
-
- mac_destroy_vnode_label(&intlabel);
- break;
-
- case DTYPE_PIPE:
- mac_init_pipe_label(&intlabel);
- error = mac_internalize_pipe_label(&intlabel, buffer);
- if (error == 0) {
- pipe = fp->f_data;
- PIPE_LOCK(pipe);
- error = mac_pipe_label_set(td->td_ucred, pipe,
- &intlabel);
- PIPE_UNLOCK(pipe);
- }
-
- mac_destroy_pipe_label(&intlabel);
- break;
-
- default:
- error = EINVAL;
- }
-
- fdrop(fp, td);
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
- struct mac_policy_conf *mpc;
- char target[MAC_MAX_POLICY_NAME];
- int entrycount, error;
-
- error = copyinstr(uap->policy, target, sizeof(target), NULL);
- if (error)
- return (error);
-
- error = ENOSYS;
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- goto out;
- }
- }
-
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) {
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- break;
- }
- }
- mac_policy_list_unbusy();
- }
-out:
- return (error);
-}
-
-SYSINIT(mac, SI_SUB_MAC, SI_ORDER_FIRST, mac_init, NULL);
-SYSINIT(mac_late, SI_SUB_MAC_LATE, SI_ORDER_FIRST, mac_late_init, NULL);
-
-#else /* !MAC */
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
-
- return (ENOSYS);
-}
-
-#endif
diff --git a/sys/security/mac/mac_vfs.c b/sys/security/mac/mac_vfs.c
deleted file mode 100644
index fb06edea3012..000000000000
--- a/sys/security/mac/mac_vfs.c
+++ /dev/null
@@ -1,3975 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * Copyright (c) 2001 Ilmar S. Habibulin
- * Copyright (c) 2001, 2002, 2003 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * This software was developed by Robert Watson and Ilmar Habibulin for the
- * TrustedBSD Project.
- *
- * This software was developed for the FreeBSD Project in part by Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
- * as part of the DARPA CHATS research program.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-/*
- * Developed by the TrustedBSD Project.
- *
- * Framework for extensible kernel access control. Kernel and userland
- * interface to the framework, policy registration and composition.
- */
-
-#include "opt_mac.h"
-#include "opt_devfs.h"
-
-#include <sys/param.h>
-#include <sys/condvar.h>
-#include <sys/extattr.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mutex.h>
-#include <sys/mac.h>
-#include <sys/module.h>
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/sysent.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/file.h>
-#include <sys/namei.h>
-#include <sys/socket.h>
-#include <sys/pipe.h>
-#include <sys/socketvar.h>
-#include <sys/sysctl.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-
-#include <sys/mac_policy.h>
-
-#include <fs/devfs/devfs.h>
-
-#include <net/bpfdesc.h>
-#include <net/if.h>
-#include <net/if_var.h>
-
-#include <netinet/in.h>
-#include <netinet/ip_var.h>
-
-#ifdef MAC
-
-/*
- * Declare that the kernel provides MAC support, version 1. This permits
- * modules to refuse to be loaded if the necessary support isn't present,
- * even if it's pre-boot.
- */
-MODULE_VERSION(kernel_mac_support, 1);
-
-SYSCTL_DECL(_security);
-
-SYSCTL_NODE(_security, OID_AUTO, mac, CTLFLAG_RW, 0,
- "TrustedBSD MAC policy controls");
-
-#if MAC_MAX_SLOTS > 32
-#error "MAC_MAX_SLOTS too large"
-#endif
-
-static unsigned int mac_max_slots = MAC_MAX_SLOTS;
-static unsigned int mac_slot_offsets_free = (1 << MAC_MAX_SLOTS) - 1;
-SYSCTL_UINT(_security_mac, OID_AUTO, max_slots, CTLFLAG_RD,
- &mac_max_slots, 0, "");
-
-/*
- * Has the kernel started generating labeled objects yet? All read/write
- * access to this variable is serialized during the boot process. Following
- * the end of serialization, we don't update this flag; no locking.
- */
-static int mac_late = 0;
-
-/*
- * Warn about EA transactions only the first time they happen.
- * Weak coherency, no locking.
- */
-static int ea_warn_once = 0;
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
-/*
- * Flag to indicate whether or not we should allocate label storage for
- * new mbufs. Since most dynamic policies we currently work with don't
- * rely on mbuf labeling, try to avoid paying the cost of mtag allocation
- * unless specifically notified of interest. One result of this is
- * that if a dynamically loaded policy requests mbuf labels, it must
- * be able to deal with a NULL label being returned on any mbufs that
- * were already in flight when the policy was loaded. Since the policy
- * already has to deal with uninitialized labels, this probably won't
- * be a problem. Note: currently no locking. Will this be a problem?
- */
-static int mac_labelmbufs = 0;
-#endif
-
-static int mac_enforce_fs = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_fs, CTLFLAG_RW,
- &mac_enforce_fs, 0, "Enforce MAC policy on file system objects");
-TUNABLE_INT("security.mac.enforce_fs", &mac_enforce_fs);
-
-static int mac_enforce_kld = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_kld, CTLFLAG_RW,
- &mac_enforce_kld, 0, "Enforce MAC policy on kld operations");
-TUNABLE_INT("security.mac.enforce_kld", &mac_enforce_kld);
-
-static int mac_enforce_network = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_network, CTLFLAG_RW,
- &mac_enforce_network, 0, "Enforce MAC policy on network packets");
-TUNABLE_INT("security.mac.enforce_network", &mac_enforce_network);
-
-static int mac_enforce_pipe = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_pipe, CTLFLAG_RW,
- &mac_enforce_pipe, 0, "Enforce MAC policy on pipe operations");
-TUNABLE_INT("security.mac.enforce_pipe", &mac_enforce_pipe);
-
-static int mac_enforce_process = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_process, CTLFLAG_RW,
- &mac_enforce_process, 0, "Enforce MAC policy on inter-process operations");
-TUNABLE_INT("security.mac.enforce_process", &mac_enforce_process);
-
-static int mac_enforce_socket = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_socket, CTLFLAG_RW,
- &mac_enforce_socket, 0, "Enforce MAC policy on socket operations");
-TUNABLE_INT("security.mac.enforce_socket", &mac_enforce_socket);
-
-static int mac_enforce_system = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_system, CTLFLAG_RW,
- &mac_enforce_system, 0, "Enforce MAC policy on system operations");
-TUNABLE_INT("security.mac.enforce_system", &mac_enforce_system);
-
-static int mac_enforce_vm = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, enforce_vm, CTLFLAG_RW,
- &mac_enforce_vm, 0, "Enforce MAC policy on vm operations");
-TUNABLE_INT("security.mac.enforce_vm", &mac_enforce_vm);
-
-static int mac_mmap_revocation = 1;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation, CTLFLAG_RW,
- &mac_mmap_revocation, 0, "Revoke mmap access to files on subject "
- "relabel");
-static int mac_mmap_revocation_via_cow = 0;
-SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation_via_cow, CTLFLAG_RW,
- &mac_mmap_revocation_via_cow, 0, "Revoke mmap access to files via "
- "copy-on-write semantics, or by removing all write access");
-
-#ifdef MAC_DEBUG
-SYSCTL_NODE(_security_mac, OID_AUTO, debug, CTLFLAG_RW, 0,
- "TrustedBSD MAC debug info");
-
-static int mac_debug_label_fallback = 0;
-SYSCTL_INT(_security_mac_debug, OID_AUTO, label_fallback, CTLFLAG_RW,
- &mac_debug_label_fallback, 0, "Filesystems should fall back to fs label"
- "when label is corrupted.");
-TUNABLE_INT("security.mac.debug_label_fallback",
- &mac_debug_label_fallback);
-
-SYSCTL_NODE(_security_mac_debug, OID_AUTO, counters, CTLFLAG_RW, 0,
- "TrustedBSD MAC object counters");
-
-static unsigned int nmacmbufs, nmaccreds, nmacifnets, nmacbpfdescs,
- nmacsockets, nmacmounts, nmactemp, nmacvnodes, nmacdevfsdirents,
- nmacipqs, nmacpipes, nmacprocs;
-
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mbufs, CTLFLAG_RD,
- &nmacmbufs, 0, "number of mbufs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, creds, CTLFLAG_RD,
- &nmaccreds, 0, "number of ucreds in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ifnets, CTLFLAG_RD,
- &nmacifnets, 0, "number of ifnets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, ipqs, CTLFLAG_RD,
- &nmacipqs, 0, "number of ipqs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, bpfdescs, CTLFLAG_RD,
- &nmacbpfdescs, 0, "number of bpfdescs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, sockets, CTLFLAG_RD,
- &nmacsockets, 0, "number of sockets in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, pipes, CTLFLAG_RD,
- &nmacpipes, 0, "number of pipes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, procs, CTLFLAG_RD,
- &nmacprocs, 0, "number of procs in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, mounts, CTLFLAG_RD,
- &nmacmounts, 0, "number of mounts in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, temp, CTLFLAG_RD,
- &nmactemp, 0, "number of temporary labels in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, vnodes, CTLFLAG_RD,
- &nmacvnodes, 0, "number of vnodes in use");
-SYSCTL_UINT(_security_mac_debug_counters, OID_AUTO, devfsdirents, CTLFLAG_RD,
- &nmacdevfsdirents, 0, "number of devfs dirents inuse");
-#endif
-
-static int error_select(int error1, int error2);
-static int mac_policy_register(struct mac_policy_conf *mpc);
-static int mac_policy_unregister(struct mac_policy_conf *mpc);
-
-static void mac_check_vnode_mmap_downgrade(struct ucred *cred,
- struct vnode *vp, int *prot);
-static void mac_cred_mmapped_drop_perms_recurse(struct thread *td,
- struct ucred *cred, struct vm_map *map);
-
-static void mac_destroy_socket_label(struct label *label);
-
-static int mac_setlabel_vnode_extattr(struct ucred *cred,
- struct vnode *vp, struct label *intlabel);
-
-MALLOC_DEFINE(M_MACPIPELABEL, "macpipelabel", "MAC labels for pipes");
-MALLOC_DEFINE(M_MACTEMP, "mactemp", "MAC temporary label storage");
-
-/*
- * mac_static_policy_list holds a list of policy modules that are not
- * loaded while the system is "live", and cannot be unloaded. These
- * policies can be invoked without holding the busy count.
- *
- * mac_policy_list stores the list of dynamic policies. A busy count is
- * maintained for the list, stored in mac_policy_busy. The busy count
- * is protected by mac_policy_mtx; the list may be modified only
- * while the busy count is 0, requiring that the lock be held to
- * prevent new references to the list from being acquired. For almost
- * all operations, incrementing the busy count is sufficient to
- * guarantee consistency, as the list cannot be modified while the
- * busy count is elevated. For a few special operations involving a
- * change to the list of active policies, the mtx itself must be held.
- * A condition variable, mac_policy_cv, is used to signal potential
- * exclusive consumers that they should try to acquire the lock if a
- * first attempt at exclusive access fails.
- */
-static struct mtx mac_policy_mtx;
-static struct cv mac_policy_cv;
-static int mac_policy_count;
-static LIST_HEAD(, mac_policy_conf) mac_policy_list;
-static LIST_HEAD(, mac_policy_conf) mac_static_policy_list;
-
-/*
- * We manually invoke WITNESS_WARN() to allow Witness to generate
- * warnings even if we don't end up ever triggering the wait at
- * run-time. The consumer of the exclusive interface must not hold
- * any locks (other than potentially Giant) since we may sleep for
- * long (potentially indefinite) periods of time waiting for the
- * framework to become quiescent so that a policy list change may
- * be made.
- */
-static __inline void
-mac_policy_grab_exclusive(void)
-{
- WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
- "mac_policy_grab_exclusive() at %s:%d", __FILE__, __LINE__);
- mtx_lock(&mac_policy_mtx);
- while (mac_policy_count != 0)
- cv_wait(&mac_policy_cv, &mac_policy_mtx);
-}
-
-static __inline void
-mac_policy_assert_exclusive(void)
-{
- mtx_assert(&mac_policy_mtx, MA_OWNED);
- KASSERT(mac_policy_count == 0,
- ("mac_policy_assert_exclusive(): not exclusive"));
-}
-
-static __inline void
-mac_policy_release_exclusive(void)
-{
-
- KASSERT(mac_policy_count == 0,
- ("mac_policy_release_exclusive(): not exclusive"));
- mtx_unlock(&mac_policy_mtx);
- cv_signal(&mac_policy_cv);
-}
-
-static __inline void
-mac_policy_list_busy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count++;
- mtx_unlock(&mac_policy_mtx);
-}
-
-static __inline int
-mac_policy_list_conditional_busy(void)
-{
- int ret;
-
- mtx_lock(&mac_policy_mtx);
- if (!LIST_EMPTY(&mac_policy_list)) {
- mac_policy_count++;
- ret = 1;
- } else
- ret = 0;
- mtx_unlock(&mac_policy_mtx);
- return (ret);
-}
-
-static __inline void
-mac_policy_list_unbusy(void)
-{
- mtx_lock(&mac_policy_mtx);
- mac_policy_count--;
- KASSERT(mac_policy_count >= 0, ("MAC_POLICY_LIST_LOCK"));
- if (mac_policy_count == 0)
- cv_signal(&mac_policy_cv);
- mtx_unlock(&mac_policy_mtx);
-}
-
-/*
- * MAC_CHECK performs the designated check by walking the policy
- * module list and checking with each as to how it feels about the
- * request. Note that it returns its value via 'error' in the scope
- * of the caller.
- */
-#define MAC_CHECK(check, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- error = 0; \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## check != NULL) \
- error = error_select( \
- mpc->mpc_ops->mpo_ ## check (args), \
- error); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * MAC_BOOLEAN performs the designated boolean composition by walking
- * the module list, invoking each instance of the operation, and
- * combining the results using the passed C operator. Note that it
- * returns its value via 'result' in the scope of the caller, which
- * should be initialized by the caller in a meaningful way to get
- * a meaningful result.
- */
-#define MAC_BOOLEAN(operation, composition, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- result = result composition \
- mpc->mpc_ops->mpo_ ## operation \
- (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-#define MAC_EXTERNALIZE(type, label, elementlist, outbuf, \
- outbuflen) do { \
- char *curptr, *curptr_start, *element_name, *element_temp; \
- size_t left, left_start, len; \
- int claimed, first, first_start, ignorenotfound; \
- \
- error = 0; \
- element_temp = elementlist; \
- curptr = outbuf; \
- curptr[0] = '\0'; \
- left = outbuflen; \
- first = 1; \
- while ((element_name = strsep(&element_temp, ",")) != NULL) { \
- curptr_start = curptr; \
- left_start = left; \
- first_start = first; \
- if (element_name[0] == '?') { \
- element_name++; \
- ignorenotfound = 1; \
- } else \
- ignorenotfound = 0; \
- claimed = 0; \
- if (first) { \
- len = snprintf(curptr, left, "%s/", \
- element_name); \
- first = 0; \
- } else \
- len = snprintf(curptr, left, ",%s/", \
- element_name); \
- if (len >= left) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- \
- MAC_CHECK(externalize_ ## type, label, element_name, \
- curptr, left, &len, &claimed); \
- if (error) \
- break; \
- if (claimed == 1) { \
- if (len >= outbuflen) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- } else if (claimed == 0 && ignorenotfound) { \
- /* \
- * Revert addition of the label element \
- * name. \
- */ \
- curptr = curptr_start; \
- *curptr = '\0'; \
- left = left_start; \
- first = first_start; \
- } else { \
- error = EINVAL; /* XXXMAC: ENOLABEL */ \
- break; \
- } \
- } \
-} while (0)
-
-#define MAC_INTERNALIZE(type, label, instring) do { \
- char *element, *element_name, *element_data; \
- int claimed; \
- \
- error = 0; \
- element = instring; \
- while ((element_name = strsep(&element, ",")) != NULL) { \
- element_data = element_name; \
- element_name = strsep(&element_data, "/"); \
- if (element_data == NULL) { \
- error = EINVAL; \
- break; \
- } \
- claimed = 0; \
- MAC_CHECK(internalize_ ## type, label, element_name, \
- element_data, &claimed); \
- if (error) \
- break; \
- if (claimed != 1) { \
- /* XXXMAC: Another error here? */ \
- error = EINVAL; \
- break; \
- } \
- } \
-} while (0)
-
-/*
- * MAC_PERFORM performs the designated operation by walking the policy
- * module list and invoking that operation for each policy.
- */
-#define MAC_PERFORM(operation, args...) do { \
- struct mac_policy_conf *mpc; \
- int entrycount; \
- \
- LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) { \
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \
- if (mpc->mpc_ops->mpo_ ## operation != NULL) \
- mpc->mpc_ops->mpo_ ## operation (args); \
- } \
- mac_policy_list_unbusy(); \
- } \
-} while (0)
-
-/*
- * Initialize the MAC subsystem, including appropriate SMP locks.
- */
-static void
-mac_init(void)
-{
-
- LIST_INIT(&mac_static_policy_list);
- LIST_INIT(&mac_policy_list);
-
- mtx_init(&mac_policy_mtx, "mac_policy_mtx", NULL, MTX_DEF);
- cv_init(&mac_policy_cv, "mac_policy_cv");
-}
-
-/*
- * For the purposes of modules that want to know if they were loaded
- * "early", set the mac_late flag once we've processed modules either
- * linked into the kernel, or loaded before the kernel startup.
- */
-static void
-mac_late_init(void)
-{
-
- mac_late = 1;
-}
-
-/*
- * After the policy list has changed, walk the list to update any global
- * flags.
- */
-static void
-mac_policy_updateflags(void)
-{
- struct mac_policy_conf *tmpc;
-#ifndef MAC_ALWAYS_LABEL_MBUF
- int labelmbufs;
-#endif
-
- mac_policy_assert_exclusive();
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- labelmbufs = 0;
-#endif
-
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
-#ifndef MAC_ALWAYS_LABEL_MBUF
- if (tmpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_LABELMBUFS)
- labelmbufs++;
-#endif
- }
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- mac_labelmbufs = (labelmbufs != 0);
-#endif
-}
-
-/*
- * Allow MAC policy modules to register during boot, etc.
- */
-int
-mac_policy_modevent(module_t mod, int type, void *data)
-{
- struct mac_policy_conf *mpc;
- int error;
-
- error = 0;
- mpc = (struct mac_policy_conf *) data;
-
- switch (type) {
- case MOD_LOAD:
- if (mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_NOTLATE &&
- mac_late) {
- printf("mac_policy_modevent: can't load %s policy "
- "after booting\n", mpc->mpc_name);
- error = EBUSY;
- break;
- }
- error = mac_policy_register(mpc);
- break;
- case MOD_UNLOAD:
- /* Don't unregister the module if it was never registered. */
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED)
- != 0)
- error = mac_policy_unregister(mpc);
- else
- error = 0;
- break;
- default:
- break;
- }
-
- return (error);
-}
-
-static int
-mac_policy_register(struct mac_policy_conf *mpc)
-{
- struct mac_policy_conf *tmpc;
- int error, slot, static_entry;
-
- error = 0;
-
- /*
- * We don't technically need exclusive access while !mac_late,
- * but hold it for assertion consistency.
- */
- mac_policy_grab_exclusive();
-
- /*
- * If the module can potentially be unloaded, or we're loading
- * late, we have to stick it in the non-static list and pay
- * an extra performance overhead. Otherwise, we can pay a
- * light locking cost and stick it in the static list.
- */
- static_entry = (!mac_late &&
- !(mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK));
-
- if (static_entry) {
- LIST_FOREACH(tmpc, &mac_static_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- } else {
- LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
- if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
- error = EEXIST;
- goto out;
- }
- }
- }
- if (mpc->mpc_field_off != NULL) {
- slot = ffs(mac_slot_offsets_free);
- if (slot == 0) {
- error = ENOMEM;
- goto out;
- }
- slot--;
- mac_slot_offsets_free &= ~(1 << slot);
- *mpc->mpc_field_off = slot;
- }
- mpc->mpc_runtime_flags |= MPC_RUNTIME_FLAG_REGISTERED;
-
- /*
- * If we're loading a MAC module after the framework has
- * initialized, it has to go into the dynamic list. If
- * we're loading it before we've finished initializing,
- * it can go into the static list with weaker locker
- * requirements.
- */
- if (static_entry)
- LIST_INSERT_HEAD(&mac_static_policy_list, mpc, mpc_list);
- else
- LIST_INSERT_HEAD(&mac_policy_list, mpc, mpc_list);
-
- /* Per-policy initialization. */
- if (mpc->mpc_ops->mpo_init != NULL)
- (*(mpc->mpc_ops->mpo_init))(mpc);
- mac_policy_updateflags();
-
- printf("Security policy loaded: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
-out:
- mac_policy_release_exclusive();
- return (error);
-}
-
-static int
-mac_policy_unregister(struct mac_policy_conf *mpc)
-{
-
- /*
- * If we fail the load, we may get a request to unload. Check
- * to see if we did the run-time registration, and if not,
- * silently succeed.
- */
- mac_policy_grab_exclusive();
- if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED) == 0) {
- mac_policy_release_exclusive();
- return (0);
- }
-#if 0
- /*
- * Don't allow unloading modules with private data.
- */
- if (mpc->mpc_field_off != NULL) {
- MAC_POLICY_LIST_UNLOCK();
- return (EBUSY);
- }
-#endif
- /*
- * Only allow the unload to proceed if the module is unloadable
- * by its own definition.
- */
- if ((mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK) == 0) {
- mac_policy_release_exclusive();
- return (EBUSY);
- }
- if (mpc->mpc_ops->mpo_destroy != NULL)
- (*(mpc->mpc_ops->mpo_destroy))(mpc);
-
- LIST_REMOVE(mpc, mpc_list);
- mpc->mpc_runtime_flags &= ~MPC_RUNTIME_FLAG_REGISTERED;
- mac_policy_updateflags();
-
- mac_policy_release_exclusive();
-
- printf("Security policy unload: %s (%s)\n", mpc->mpc_fullname,
- mpc->mpc_name);
-
- return (0);
-}
-
-/*
- * Define an error value precedence, and given two arguments, selects the
- * value with the higher precedence.
- */
-static int
-error_select(int error1, int error2)
-{
-
- /* Certain decision-making errors take top priority. */
- if (error1 == EDEADLK || error2 == EDEADLK)
- return (EDEADLK);
-
- /* Invalid arguments should be reported where possible. */
- if (error1 == EINVAL || error2 == EINVAL)
- return (EINVAL);
-
- /* Precedence goes to "visibility", with both process and file. */
- if (error1 == ESRCH || error2 == ESRCH)
- return (ESRCH);
-
- if (error1 == ENOENT || error2 == ENOENT)
- return (ENOENT);
-
- /* Precedence goes to DAC/MAC protections. */
- if (error1 == EACCES || error2 == EACCES)
- return (EACCES);
-
- /* Precedence goes to privilege. */
- if (error1 == EPERM || error2 == EPERM)
- return (EPERM);
-
- /* Precedence goes to error over success; otherwise, arbitrary. */
- if (error1 != 0)
- return (error1);
- return (error2);
-}
-
-static struct label *
-mbuf_to_label(struct mbuf *mbuf)
-{
- struct m_tag *tag;
- struct label *label;
-
- tag = m_tag_find(mbuf, PACKET_TAG_MACLABEL, NULL);
- label = (struct label *)(tag+1);
-
- return (label);
-}
-
-static void
-mac_init_label(struct label *label)
-{
-
- bzero(label, sizeof(*label));
- label->l_flags = MAC_FLAG_INITIALIZED;
-}
-
-static void
-mac_destroy_label(struct label *label)
-{
-
- KASSERT(label->l_flags & MAC_FLAG_INITIALIZED,
- ("destroying uninitialized label"));
-
- bzero(label, sizeof(*label));
- /* implicit: label->l_flags &= ~MAC_FLAG_INITIALIZED; */
-}
-
-void
-mac_init_bpfdesc(struct bpf_d *bpf_d)
-{
-
- mac_init_label(&bpf_d->bd_label);
- MAC_PERFORM(init_bpfdesc_label, &bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_init_cred_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_cred_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_init_cred(struct ucred *cred)
-{
-
- mac_init_cred_label(&cred->cr_label);
-}
-
-void
-mac_init_devfsdirent(struct devfs_dirent *de)
-{
-
- mac_init_label(&de->de_label);
- MAC_PERFORM(init_devfsdirent_label, &de->de_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_init_ifnet_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_ifnet_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_init_ifnet(struct ifnet *ifp)
-{
-
- mac_init_ifnet_label(&ifp->if_label);
-}
-
-int
-mac_init_ipq(struct ipq *ipq, int flag)
-{
- int error;
-
- mac_init_label(&ipq->ipq_label);
-
- MAC_CHECK(init_ipq_label, &ipq->ipq_label, flag);
- if (error) {
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacipqs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf_tag(struct m_tag *tag, int flag)
-{
- struct label *label;
- int error;
-
- label = (struct label *) (tag + 1);
- mac_init_label(label);
-
- MAC_CHECK(init_mbuf_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
- }
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacmbufs, 1);
-#endif
- return (error);
-}
-
-int
-mac_init_mbuf(struct mbuf *m, int flag)
-{
- struct m_tag *tag;
- int error;
-
- M_ASSERTPKTHDR(m);
-
-#ifndef MAC_ALWAYS_LABEL_MBUF
- /*
- * Don't reserve space for labels on mbufs unless we have a policy
- * that uses the labels.
- */
- if (mac_labelmbufs) {
-#endif
- tag = m_tag_get(PACKET_TAG_MACLABEL, sizeof(struct label),
- flag);
- if (tag == NULL)
- return (ENOMEM);
- error = mac_init_mbuf_tag(tag, flag);
- if (error) {
- m_tag_free(tag);
- return (error);
- }
- m_tag_prepend(m, tag);
-#ifndef MAC_ALWAYS_LABEL_MBUF
- }
-#endif
- return (0);
-}
-
-void
-mac_init_mount(struct mount *mp)
-{
-
- mac_init_label(&mp->mnt_mntlabel);
- mac_init_label(&mp->mnt_fslabel);
- MAC_PERFORM(init_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(init_mount_fs_label, &mp->mnt_fslabel);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_init_pipe_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_pipe_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_init_pipe(struct pipe *pipe)
-{
- struct label *label;
-
- label = malloc(sizeof(struct label), M_MACPIPELABEL, M_ZERO|M_WAITOK);
- pipe->pipe_label = label;
- pipe->pipe_peer->pipe_label = label;
- mac_init_pipe_label(label);
-}
-
-void
-mac_init_proc(struct proc *p)
-{
-
- mac_init_label(&p->p_label);
- MAC_PERFORM(init_proc_label, &p->p_label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacprocs, 1);
-#endif
-}
-
-static int
-mac_init_socket_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
-#ifdef MAC_DEBUG
- if (error == 0)
- atomic_add_int(&nmacsockets, 1);
-#endif
-
- return (error);
-}
-
-static int
-mac_init_socket_peer_label(struct label *label, int flag)
-{
- int error;
-
- mac_init_label(label);
-
- MAC_CHECK(init_socket_peer_label, label, flag);
- if (error) {
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
- }
-
- return (error);
-}
-
-int
-mac_init_socket(struct socket *socket, int flag)
-{
- int error;
-
- error = mac_init_socket_label(&socket->so_label, flag);
- if (error)
- return (error);
-
- error = mac_init_socket_peer_label(&socket->so_peerlabel, flag);
- if (error)
- mac_destroy_socket_label(&socket->so_label);
-
- return (error);
-}
-
-void
-mac_init_vnode_label(struct label *label)
-{
-
- mac_init_label(label);
- MAC_PERFORM(init_vnode_label, label);
-#ifdef MAC_DEBUG
- atomic_add_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_init_vnode(struct vnode *vp)
-{
-
- mac_init_vnode_label(&vp->v_label);
-}
-
-void
-mac_destroy_bpfdesc(struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(destroy_bpfdesc_label, &bpf_d->bd_label);
- mac_destroy_label(&bpf_d->bd_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacbpfdescs, 1);
-#endif
-}
-
-static void
-mac_destroy_cred_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_cred_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmaccreds, 1);
-#endif
-}
-
-void
-mac_destroy_cred(struct ucred *cred)
-{
-
- mac_destroy_cred_label(&cred->cr_label);
-}
-
-void
-mac_destroy_devfsdirent(struct devfs_dirent *de)
-{
-
- MAC_PERFORM(destroy_devfsdirent_label, &de->de_label);
- mac_destroy_label(&de->de_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacdevfsdirents, 1);
-#endif
-}
-
-static void
-mac_destroy_ifnet_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_ifnet_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacifnets, 1);
-#endif
-}
-
-void
-mac_destroy_ifnet(struct ifnet *ifp)
-{
-
- mac_destroy_ifnet_label(&ifp->if_label);
-}
-
-void
-mac_destroy_ipq(struct ipq *ipq)
-{
-
- MAC_PERFORM(destroy_ipq_label, &ipq->ipq_label);
- mac_destroy_label(&ipq->ipq_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacipqs, 1);
-#endif
-}
-
-void
-mac_destroy_mbuf_tag(struct m_tag *tag)
-{
- struct label *label;
-
- label = (struct label *)(tag+1);
-
- MAC_PERFORM(destroy_mbuf_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmbufs, 1);
-#endif
-}
-
-void
-mac_destroy_mount(struct mount *mp)
-{
-
- MAC_PERFORM(destroy_mount_label, &mp->mnt_mntlabel);
- MAC_PERFORM(destroy_mount_fs_label, &mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_fslabel);
- mac_destroy_label(&mp->mnt_mntlabel);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacmounts, 1);
-#endif
-}
-
-static void
-mac_destroy_pipe_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_pipe_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacpipes, 1);
-#endif
-}
-
-void
-mac_destroy_pipe(struct pipe *pipe)
-{
-
- mac_destroy_pipe_label(pipe->pipe_label);
- free(pipe->pipe_label, M_MACPIPELABEL);
-}
-
-void
-mac_destroy_proc(struct proc *p)
-{
-
- MAC_PERFORM(destroy_proc_label, &p->p_label);
- mac_destroy_label(&p->p_label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacprocs, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacsockets, 1);
-#endif
-}
-
-static void
-mac_destroy_socket_peer_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_socket_peer_label, label);
- mac_destroy_label(label);
-}
-
-void
-mac_destroy_socket(struct socket *socket)
-{
-
- mac_destroy_socket_label(&socket->so_label);
- mac_destroy_socket_peer_label(&socket->so_peerlabel);
-}
-
-void
-mac_destroy_vnode_label(struct label *label)
-{
-
- MAC_PERFORM(destroy_vnode_label, label);
- mac_destroy_label(label);
-#ifdef MAC_DEBUG
- atomic_subtract_int(&nmacvnodes, 1);
-#endif
-}
-
-void
-mac_destroy_vnode(struct vnode *vp)
-{
-
- mac_destroy_vnode_label(&vp->v_label);
-}
-
-void
-mac_copy_mbuf_tag(struct m_tag *src, struct m_tag *dest)
-{
- struct label *src_label, *dest_label;
-
- src_label = (struct label *)(src+1);
- dest_label = (struct label *)(dest+1);
-
- /*
- * mac_init_mbuf_tag() is called on the target tag in
- * m_tag_copy(), so we don't need to call it here.
- */
- MAC_PERFORM(copy_mbuf_label, src_label, dest_label);
-}
-
-static void
-mac_copy_pipe_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_pipe_label, src, dest);
-}
-
-void
-mac_copy_vnode_label(struct label *src, struct label *dest)
-{
-
- MAC_PERFORM(copy_vnode_label, src, dest);
-}
-
-static int
-mac_check_structmac_consistent(struct mac *mac)
-{
-
- if (mac->m_buflen > MAC_MAX_LABEL_BUF_LEN)
- return (EINVAL);
-
- return (0);
-}
-
-static int
-mac_externalize_cred_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(cred_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_ifnet_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(ifnet_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_pipe_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(pipe_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_socket_peer_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(socket_peer_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_externalize_vnode_label(struct label *label, char *elements,
- char *outbuf, size_t outbuflen, int flags)
-{
- int error;
-
- MAC_EXTERNALIZE(vnode_label, label, elements, outbuf, outbuflen);
-
- return (error);
-}
-
-static int
-mac_internalize_cred_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(cred_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_ifnet_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(ifnet_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_pipe_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(pipe_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_socket_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(socket_label, label, string);
-
- return (error);
-}
-
-static int
-mac_internalize_vnode_label(struct label *label, char *string)
-{
- int error;
-
- MAC_INTERNALIZE(vnode_label, label, string);
-
- return (error);
-}
-
-/*
- * Initialize MAC label for the first kernel process, from which other
- * kernel processes and threads are spawned.
- */
-void
-mac_create_proc0(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc0, cred);
-}
-
-/*
- * Initialize MAC label for the first userland process, from which other
- * userland processes and threads are spawned.
- */
-void
-mac_create_proc1(struct ucred *cred)
-{
-
- MAC_PERFORM(create_proc1, cred);
-}
-
-void
-mac_thread_userret(struct thread *td)
-{
-
- MAC_PERFORM(thread_userret, td);
-}
-
-/*
- * When a new process is created, its label must be initialized. Generally,
- * this involves inheritence from the parent process, modulo possible
- * deltas. This function allows that processing to take place.
- */
-void
-mac_create_cred(struct ucred *parent_cred, struct ucred *child_cred)
-{
-
- MAC_PERFORM(create_cred, parent_cred, child_cred);
-}
-
-void
-mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(update_devfsdirent, mp, de, &de->de_label, vp,
- &vp->v_label);
-}
-
-void
-mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de,
- struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_devfs, mp, &mp->mnt_fslabel, de,
- &de->de_label, vp, &vp->v_label);
-}
-
-int
-mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_associate_vnode_extattr");
-
- MAC_CHECK(associate_vnode_extattr, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-
- return (error);
-}
-
-void
-mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp)
-{
-
- MAC_PERFORM(associate_vnode_singlelabel, mp, &mp->mnt_fslabel, vp,
- &vp->v_label);
-}
-
-int
-mac_create_vnode_extattr(struct ucred *cred, struct mount *mp,
- struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_create_vnode_extattr");
- ASSERT_VOP_LOCKED(vp, "mac_create_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(create_vnode_extattr, cred, mp, &mp->mnt_fslabel,
- dvp, &dvp->v_label, vp, &vp->v_label, cnp);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-static int
-mac_setlabel_vnode_extattr(struct ucred *cred, struct vnode *vp,
- struct label *intlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_setlabel_vnode_extattr");
-
- error = VOP_OPENEXTATTR(vp, cred, curthread);
- if (error == EOPNOTSUPP) {
- /* XXX: Optionally abort if transactions not supported. */
- if (ea_warn_once == 0) {
- printf("Warning: transactions not supported "
- "in EA write.\n");
- ea_warn_once = 1;
- }
- } else if (error)
- return (error);
-
- MAC_CHECK(setlabel_vnode_extattr, cred, vp, &vp->v_label, intlabel);
-
- if (error) {
- VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
- return (error);
- }
-
- error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
-
- if (error == EOPNOTSUPP)
- error = 0; /* XXX */
-
- return (error);
-}
-
-int
-mac_execve_enter(struct image_params *imgp, struct mac *mac_p,
- struct label *execlabelstorage)
-{
- struct mac mac;
- char *buffer;
- int error;
-
- if (mac_p == NULL)
- return (0);
-
- error = copyin(mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(execlabelstorage);
- error = mac_internalize_cred_label(execlabelstorage, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(execlabelstorage);
- return (error);
- }
- imgp->execlabel = execlabelstorage;
- return (0);
-}
-
-void
-mac_execve_exit(struct image_params *imgp)
-{
- if (imgp->execlabel != NULL)
- mac_destroy_cred_label(imgp->execlabel);
-}
-
-void
-mac_execve_transition(struct ucred *old, struct ucred *new, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return;
-
- MAC_PERFORM(execve_transition, old, new, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-}
-
-int
-mac_execve_will_transition(struct ucred *old, struct vnode *vp,
- struct label *interpvnodelabel, struct image_params *imgp)
-{
- int result;
-
- ASSERT_VOP_LOCKED(vp, "mac_execve_will_transition");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- result = 0;
- MAC_BOOLEAN(execve_will_transition, ||, old, vp, &vp->v_label,
- interpvnodelabel, imgp, imgp->execlabel);
-
- return (result);
-}
-
-int
-mac_check_vnode_access(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_access");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_access, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chroot");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_chroot, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_create(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp, struct vattr *vap)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_create");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_create, cred, dvp, &dvp->v_label, cnp, vap);
- return (error);
-}
-
-int
-mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp, struct vnode *vp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_delete");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_delete");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_delete, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
- acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_deleteacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_deleteacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_exec(struct ucred *cred, struct vnode *vp,
- struct image_params *imgp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_exec");
-
- if (!mac_enforce_process && !mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_exec, cred, vp, &vp->v_label, imgp,
- imgp->execlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp, acl_type_t type)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getacl, cred, vp, &vp->v_label, type);
- return (error);
-}
-
-int
-mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_getextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_link(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_link");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_link");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_link, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
- struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_lookup");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_lookup, cred, dvp, &dvp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mmap, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-void
-mac_check_vnode_mmap_downgrade(struct ucred *cred, struct vnode *vp, int *prot)
-{
- int result = *prot;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap_downgrade");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return;
-
- MAC_PERFORM(check_vnode_mmap_downgrade, cred, vp, &vp->v_label,
- &result);
-
- *prot = result;
-}
-
-int
-mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp, int prot)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mprotect");
-
- if (!mac_enforce_fs || !mac_enforce_vm)
- return (0);
-
- MAC_CHECK(check_vnode_mprotect, cred, vp, &vp->v_label, prot);
- return (error);
-}
-
-int
-mac_check_vnode_open(struct ucred *cred, struct vnode *vp, int acc_mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_open");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_open, cred, vp, &vp->v_label, acc_mode);
- return (error);
-}
-
-int
-mac_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_poll");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_poll, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_read");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_read, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_vnode_readdir(struct ucred *cred, struct vnode *dvp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_readdir");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readdir, cred, dvp, &dvp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_readlink");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_readlink, cred, vp, &vp->v_label);
- return (error);
-}
-
-static int
-mac_check_vnode_relabel(struct ucred *cred, struct vnode *vp,
- struct label *newlabel)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_relabel");
-
- MAC_CHECK(check_vnode_relabel, cred, vp, &vp->v_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_from");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_from");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_from, cred, dvp, &dvp->v_label, vp,
- &vp->v_label, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
- struct vnode *vp, int samedir, struct componentname *cnp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_to");
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_to");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_rename_to, cred, dvp, &dvp->v_label, vp,
- vp != NULL ? &vp->v_label : NULL, samedir, cnp);
- return (error);
-}
-
-int
-mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_revoke");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_revoke, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type,
- struct acl *acl)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setacl");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setacl, cred, vp, &vp->v_label, type, acl);
- return (error);
-}
-
-int
-mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
- int attrnamespace, const char *name, struct uio *uio)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setextattr");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setextattr, cred, vp, &vp->v_label,
- attrnamespace, name, uio);
- return (error);
-}
-
-int
-mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp, u_long flags)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setflags");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setflags, cred, vp, &vp->v_label, flags);
- return (error);
-}
-
-int
-mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp, mode_t mode)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setmode");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setmode, cred, vp, &vp->v_label, mode);
- return (error);
-}
-
-int
-mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp, uid_t uid,
- gid_t gid)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setowner");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setowner, cred, vp, &vp->v_label, uid, gid);
- return (error);
-}
-
-int
-mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
- struct timespec atime, struct timespec mtime)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setutimes");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_setutimes, cred, vp, &vp->v_label, atime,
- mtime);
- return (error);
-}
-
-int
-mac_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_stat");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_stat, active_cred, file_cred, vp,
- &vp->v_label);
- return (error);
-}
-
-int
-mac_check_vnode_write(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_vnode_write");
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_vnode_write, active_cred, file_cred, vp,
- &vp->v_label);
-
- return (error);
-}
-
-/*
- * When relabeling a process, call out to the policies for the maximum
- * permission allowed for each object type we know about in its
- * memory space, and revoke access (in the least surprising ways we
- * know) when necessary. The process lock is not held here.
- */
-void
-mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred)
-{
-
- /* XXX freeze all other threads */
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- &td->td_proc->p_vmspace->vm_map);
- /* XXX allow other threads to continue */
-}
-
-static __inline const char *
-prot2str(vm_prot_t prot)
-{
-
- switch (prot & VM_PROT_ALL) {
- case VM_PROT_READ:
- return ("r--");
- case VM_PROT_READ | VM_PROT_WRITE:
- return ("rw-");
- case VM_PROT_READ | VM_PROT_EXECUTE:
- return ("r-x");
- case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("rwx");
- case VM_PROT_WRITE:
- return ("-w-");
- case VM_PROT_EXECUTE:
- return ("--x");
- case VM_PROT_WRITE | VM_PROT_EXECUTE:
- return ("-wx");
- default:
- return ("---");
- }
-}
-
-static void
-mac_cred_mmapped_drop_perms_recurse(struct thread *td, struct ucred *cred,
- struct vm_map *map)
-{
- struct vm_map_entry *vme;
- int result;
- vm_prot_t revokeperms;
- vm_object_t object;
- vm_ooffset_t offset;
- struct vnode *vp;
-
- if (!mac_mmap_revocation)
- return;
-
- vm_map_lock_read(map);
- for (vme = map->header.next; vme != &map->header; vme = vme->next) {
- if (vme->eflags & MAP_ENTRY_IS_SUB_MAP) {
- mac_cred_mmapped_drop_perms_recurse(td, cred,
- vme->object.sub_map);
- continue;
- }
- /*
- * Skip over entries that obviously are not shared.
- */
- if (vme->eflags & (MAP_ENTRY_COW | MAP_ENTRY_NOSYNC) ||
- !vme->max_protection)
- continue;
- /*
- * Drill down to the deepest backing object.
- */
- offset = vme->offset;
- object = vme->object.vm_object;
- if (object == NULL)
- continue;
- while (object->backing_object != NULL) {
- object = object->backing_object;
- offset += object->backing_object_offset;
- }
- /*
- * At the moment, vm_maps and objects aren't considered
- * by the MAC system, so only things with backing by a
- * normal object (read: vnodes) are checked.
- */
- if (object->type != OBJT_VNODE)
- continue;
- vp = (struct vnode *)object->handle;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- result = vme->max_protection;
- mac_check_vnode_mmap_downgrade(cred, vp, &result);
- VOP_UNLOCK(vp, 0, td);
- /*
- * Find out what maximum protection we may be allowing
- * now but a policy needs to get removed.
- */
- revokeperms = vme->max_protection & ~result;
- if (!revokeperms)
- continue;
- printf("pid %ld: revoking %s perms from %#lx:%ld "
- "(max %s/cur %s)\n", (long)td->td_proc->p_pid,
- prot2str(revokeperms), (u_long)vme->start,
- (long)(vme->end - vme->start),
- prot2str(vme->max_protection), prot2str(vme->protection));
- vm_map_lock_upgrade(map);
- /*
- * This is the really simple case: if a map has more
- * max_protection than is allowed, but it's not being
- * actually used (that is, the current protection is
- * still allowed), we can just wipe it out and do
- * nothing more.
- */
- if ((vme->protection & revokeperms) == 0) {
- vme->max_protection -= revokeperms;
- } else {
- if (revokeperms & VM_PROT_WRITE) {
- /*
- * In the more complicated case, flush out all
- * pending changes to the object then turn it
- * copy-on-write.
- */
- vm_object_reference(object);
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- VM_OBJECT_LOCK(object);
- vm_object_page_clean(object,
- OFF_TO_IDX(offset),
- OFF_TO_IDX(offset + vme->end - vme->start +
- PAGE_MASK),
- OBJPC_SYNC);
- VM_OBJECT_UNLOCK(object);
- VOP_UNLOCK(vp, 0, td);
- vm_object_deallocate(object);
- /*
- * Why bother if there's no read permissions
- * anymore? For the rest, we need to leave
- * the write permissions on for COW, or
- * remove them entirely if configured to.
- */
- if (!mac_mmap_revocation_via_cow) {
- vme->max_protection &= ~VM_PROT_WRITE;
- vme->protection &= ~VM_PROT_WRITE;
- } if ((revokeperms & VM_PROT_READ) == 0)
- vme->eflags |= MAP_ENTRY_COW |
- MAP_ENTRY_NEEDS_COPY;
- }
- if (revokeperms & VM_PROT_EXECUTE) {
- vme->max_protection &= ~VM_PROT_EXECUTE;
- vme->protection &= ~VM_PROT_EXECUTE;
- }
- if (revokeperms & VM_PROT_READ) {
- vme->max_protection = 0;
- vme->protection = 0;
- }
- pmap_protect(map->pmap, vme->start, vme->end,
- vme->protection & ~revokeperms);
- vm_map_simplify_entry(map, vme);
- }
- vm_map_lock_downgrade(map);
- }
- vm_map_unlock_read(map);
-}
-
-/*
- * When the subject's label changes, it may require revocation of privilege
- * to mapped objects. This can't be done on-the-fly later with a unified
- * buffer cache.
- */
-static void
-mac_relabel_cred(struct ucred *cred, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_cred, cred, newlabel);
-}
-
-void
-mac_relabel_vnode(struct ucred *cred, struct vnode *vp, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_vnode, cred, vp, &vp->v_label, newlabel);
-}
-
-void
-mac_create_ifnet(struct ifnet *ifnet)
-{
-
- MAC_PERFORM(create_ifnet, ifnet, &ifnet->if_label);
-}
-
-void
-mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d)
-{
-
- MAC_PERFORM(create_bpfdesc, cred, bpf_d, &bpf_d->bd_label);
-}
-
-void
-mac_create_socket(struct ucred *cred, struct socket *socket)
-{
-
- MAC_PERFORM(create_socket, cred, socket, &socket->so_label);
-}
-
-void
-mac_create_pipe(struct ucred *cred, struct pipe *pipe)
-{
-
- MAC_PERFORM(create_pipe, cred, pipe, pipe->pipe_label);
-}
-
-void
-mac_create_socket_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(create_socket_from_socket, oldsocket, &oldsocket->so_label,
- newsocket, &newsocket->so_label);
-}
-
-static void
-mac_relabel_socket(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_socket, cred, socket, &socket->so_label, newlabel);
-}
-
-static void
-mac_relabel_pipe(struct ucred *cred, struct pipe *pipe, struct label *newlabel)
-{
-
- MAC_PERFORM(relabel_pipe, cred, pipe, pipe->pipe_label, newlabel);
-}
-
-void
-mac_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct socket *socket)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(set_socket_peer_from_mbuf, mbuf, label, socket,
- &socket->so_peerlabel);
-}
-
-void
-mac_set_socket_peer_from_socket(struct socket *oldsocket,
- struct socket *newsocket)
-{
-
- MAC_PERFORM(set_socket_peer_from_socket, oldsocket,
- &oldsocket->so_label, newsocket, &newsocket->so_peerlabel);
-}
-
-void
-mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram)
-{
- struct label *label;
-
- label = mbuf_to_label(datagram);
-
- MAC_PERFORM(create_datagram_from_ipq, ipq, &ipq->ipq_label,
- datagram, label);
-}
-
-void
-mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment)
-{
- struct label *datagramlabel, *fragmentlabel;
-
- datagramlabel = mbuf_to_label(datagram);
- fragmentlabel = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_fragment, datagram, datagramlabel, fragment,
- fragmentlabel);
-}
-
-void
-mac_create_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(create_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_mbuf(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_from_mbuf, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-void
-mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_bpfdesc, bpf_d, &bpf_d->bd_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_linklayer, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_ifnet, ifnet, &ifnet->if_label, mbuf,
- label);
-}
-
-void
-mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf, struct ifnet *ifnet,
- struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_multicast_encap, oldmbuf, oldmbuflabel,
- ifnet, &ifnet->if_label, newmbuf, newmbuflabel);
-}
-
-void
-mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf)
-{
- struct label *oldmbuflabel, *newmbuflabel;
-
- oldmbuflabel = mbuf_to_label(oldmbuf);
- newmbuflabel = mbuf_to_label(newmbuf);
-
- MAC_PERFORM(create_mbuf_netlayer, oldmbuf, oldmbuflabel, newmbuf,
- newmbuflabel);
-}
-
-int
-mac_fragment_match(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
- int result;
-
- label = mbuf_to_label(fragment);
-
- result = 1;
- MAC_BOOLEAN(fragment_match, &&, fragment, label, ipq,
- &ipq->ipq_label);
-
- return (result);
-}
-
-void
-mac_update_ipq(struct mbuf *fragment, struct ipq *ipq)
-{
- struct label *label;
-
- label = mbuf_to_label(fragment);
-
- MAC_PERFORM(update_ipq, fragment, label, ipq, &ipq->ipq_label);
-}
-
-void
-mac_create_mbuf_from_socket(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
-
- label = mbuf_to_label(mbuf);
-
- MAC_PERFORM(create_mbuf_from_socket, socket, &socket->so_label, mbuf,
- label);
-}
-
-void
-mac_create_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-void
-mac_create_root_mount(struct ucred *cred, struct mount *mp)
-{
-
- MAC_PERFORM(create_root_mount, cred, mp, &mp->mnt_mntlabel,
- &mp->mnt_fslabel);
-}
-
-int
-mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet)
-{
- int error;
-
- if (!mac_enforce_network)
- return (0);
-
- MAC_CHECK(check_bpfdesc_receive, bpf_d, &bpf_d->bd_label, ifnet,
- &ifnet->if_label);
-
- return (error);
-}
-
-static int
-mac_check_cred_relabel(struct ucred *cred, struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_cred_relabel, cred, newlabel);
-
- return (error);
-}
-
-int
-mac_check_cred_visible(struct ucred *u1, struct ucred *u2)
-{
- int error;
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_cred_visible, u1, u2);
-
- return (error);
-}
-
-int
-mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- M_ASSERTPKTHDR(mbuf);
-
- if (!mac_enforce_network)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_ifnet_transmit, ifnet, &ifnet->if_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_kenv_dump(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_dump, cred);
-
- return (error);
-}
-
-int
-mac_check_kenv_get(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_get, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kenv_set(struct ucred *cred, char *name, char *value)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_set, cred, name, value);
-
- return (error);
-}
-
-int
-mac_check_kenv_unset(struct ucred *cred, char *name)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_kenv_unset, cred, name);
-
- return (error);
-}
-
-int
-mac_check_kld_load(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_kld_load");
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_load, cred, vp, &vp->v_label);
-
- return (error);
-}
-
-int
-mac_check_kld_stat(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_stat, cred);
-
- return (error);
-}
-
-int
-mac_check_kld_unload(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_kld)
- return (0);
-
- MAC_CHECK(check_kld_unload, cred);
-
- return (error);
-}
-
-int
-mac_check_mount_stat(struct ucred *cred, struct mount *mount)
-{
- int error;
-
- if (!mac_enforce_fs)
- return (0);
-
- MAC_CHECK(check_mount_stat, cred, mount, &mount->mnt_mntlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, unsigned long cmd,
- void *data)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_ioctl, cred, pipe, pipe->pipe_label, cmd, data);
-
- return (error);
-}
-
-int
-mac_check_pipe_poll(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_poll, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_read(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_read, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-static int
-mac_check_pipe_relabel(struct ucred *cred, struct pipe *pipe,
- struct label *newlabel)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_relabel, cred, pipe, pipe->pipe_label, newlabel);
-
- return (error);
-}
-
-int
-mac_check_pipe_stat(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_stat, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_pipe_write(struct ucred *cred, struct pipe *pipe)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- if (!mac_enforce_pipe)
- return (0);
-
- MAC_CHECK(check_pipe_write, cred, pipe, pipe->pipe_label);
-
- return (error);
-}
-
-int
-mac_check_proc_debug(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_debug, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_sched(struct ucred *cred, struct proc *proc)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_sched, cred, proc);
-
- return (error);
-}
-
-int
-mac_check_proc_signal(struct ucred *cred, struct proc *proc, int signum)
-{
- int error;
-
- PROC_LOCK_ASSERT(proc, MA_OWNED);
-
- if (!mac_enforce_process)
- return (0);
-
- MAC_CHECK(check_proc_signal, cred, proc, signum);
-
- return (error);
-}
-
-int
-mac_check_socket_bind(struct ucred *ucred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_bind, ucred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_connect(struct ucred *cred, struct socket *socket,
- struct sockaddr *sockaddr)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_connect, cred, socket, &socket->so_label,
- sockaddr);
-
- return (error);
-}
-
-int
-mac_check_socket_deliver(struct socket *socket, struct mbuf *mbuf)
-{
- struct label *label;
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- label = mbuf_to_label(mbuf);
-
- MAC_CHECK(check_socket_deliver, socket, &socket->so_label, mbuf,
- label);
-
- return (error);
-}
-
-int
-mac_check_socket_listen(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_listen, cred, socket, &socket->so_label);
- return (error);
-}
-
-int
-mac_check_socket_receive(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_receive, cred, so, &so->so_label);
-
- return (error);
-}
-
-static int
-mac_check_socket_relabel(struct ucred *cred, struct socket *socket,
- struct label *newlabel)
-{
- int error;
-
- MAC_CHECK(check_socket_relabel, cred, socket, &socket->so_label,
- newlabel);
-
- return (error);
-}
-
-int
-mac_check_socket_send(struct ucred *cred, struct socket *so)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_send, cred, so, &so->so_label);
-
- return (error);
-}
-
-int
-mac_check_socket_visible(struct ucred *cred, struct socket *socket)
-{
- int error;
-
- if (!mac_enforce_socket)
- return (0);
-
- MAC_CHECK(check_socket_visible, cred, socket, &socket->so_label);
-
- return (error);
-}
-
-int
-mac_check_sysarch_ioperm(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_sysarch_ioperm, cred);
- return (error);
-}
-
-int
-mac_check_system_acct(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- if (vp != NULL) {
- ASSERT_VOP_LOCKED(vp, "mac_check_system_acct");
- }
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_acct, cred, vp,
- vp != NULL ? &vp->v_label : NULL);
-
- return (error);
-}
-
-int
-mac_check_system_nfsd(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_nfsd, cred);
-
- return (error);
-}
-
-int
-mac_check_system_reboot(struct ucred *cred, int howto)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_reboot, cred, howto);
-
- return (error);
-}
-
-int
-mac_check_system_settime(struct ucred *cred)
-{
- int error;
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_settime, cred);
-
- return (error);
-}
-
-int
-mac_check_system_swapon(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapon");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapon, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_swapoff(struct ucred *cred, struct vnode *vp)
-{
- int error;
-
- ASSERT_VOP_LOCKED(vp, "mac_check_system_swapoff");
-
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_swapoff, cred, vp, &vp->v_label);
- return (error);
-}
-
-int
-mac_check_system_sysctl(struct ucred *cred, int *name, u_int namelen,
- void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen)
-{
- int error;
-
- /*
- * XXXMAC: We're very much like to assert the SYSCTL_LOCK here,
- * but since it's not exported from kern_sysctl.c, we can't.
- */
- if (!mac_enforce_system)
- return (0);
-
- MAC_CHECK(check_system_sysctl, cred, name, namelen, old, oldlenp,
- inkernel, new, newlen);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_ifnet_label(&ifnet->if_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr,
- struct ifnet *ifnet)
-{
- struct label intlabel;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_ifnet_label(&intlabel);
- error = mac_internalize_ifnet_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- /*
- * XXX: Note that this is a redundant privilege check, since
- * policies impose this check themselves if required by the
- * policy. Eventually, this should go away.
- */
- error = suser_cred(cred, 0);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_CHECK(check_ifnet_relabel, cred, ifnet, &ifnet->if_label,
- &intlabel);
- if (error) {
- mac_destroy_ifnet_label(&intlabel);
- return (error);
- }
-
- MAC_PERFORM(relabel_ifnet, cred, ifnet, &ifnet->if_label, &intlabel);
-
- mac_destroy_ifnet_label(&intlabel);
- return (0);
-}
-
-void
-mac_create_devfs_device(struct mount *mp, dev_t dev, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_device, mp, dev, de, &de->de_label);
-}
-
-void
-mac_create_devfs_symlink(struct ucred *cred, struct mount *mp,
- struct devfs_dirent *dd, struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_symlink, cred, mp, dd, &dd->de_label, de,
- &de->de_label);
-}
-
-void
-mac_create_devfs_directory(struct mount *mp, char *dirname, int dirnamelen,
- struct devfs_dirent *de)
-{
-
- MAC_PERFORM(create_devfs_directory, mp, dirname, dirnamelen, de,
- &de->de_label);
-}
-
-int
-mac_setsockopt_label_set(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- struct label intlabel;
- char *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, buffer, mac->m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_socket_label(&intlabel, M_WAITOK);
- error = mac_internalize_socket_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_check_socket_relabel(cred, so, &intlabel);
- if (error) {
- mac_destroy_socket_label(&intlabel);
- return (error);
- }
-
- mac_relabel_socket(cred, so, &intlabel);
-
- mac_destroy_socket_label(&intlabel);
- return (0);
-}
-
-int
-mac_pipe_label_set(struct ucred *cred, struct pipe *pipe, struct label *label)
-{
- int error;
-
- PIPE_LOCK_ASSERT(pipe, MA_OWNED);
-
- error = mac_check_pipe_relabel(cred, pipe, label);
- if (error)
- return (error);
-
- mac_relabel_pipe(cred, pipe, label);
-
- return (0);
-}
-
-int
-mac_getsockopt_label_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *buffer, *elements;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_label(&so->so_label, elements,
- buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-int
-mac_getsockopt_peerlabel_get(struct ucred *cred, struct socket *so,
- struct mac *mac)
-{
- char *elements, *buffer;
- int error;
-
- error = mac_check_structmac_consistent(mac);
- if (error)
- return (error);
-
- elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_socket_peer_label(&so->so_peerlabel,
- elements, buffer, mac->m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac->m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * Implementation of VOP_SETLABEL() that relies on extended attributes
- * to store label data. Can be referenced by filesystems supporting
- * extended attributes.
- */
-int
-vop_stdsetlabel_ea(struct vop_setlabel_args *ap)
-{
- struct vnode *vp = ap->a_vp;
- struct label *intlabel = ap->a_label;
- int error;
-
- ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea");
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- error = mac_setlabel_vnode_extattr(ap->a_cred, vp, intlabel);
- if (error)
- return (error);
-
- mac_relabel_vnode(ap->a_cred, vp, intlabel);
-
- return (0);
-}
-
-static int
-vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred)
-{
- int error;
-
- if (vp->v_mount == NULL) {
- /* printf("vn_setlabel: null v_mount\n"); */
- if (vp->v_type != VNON)
- printf("vn_setlabel: null v_mount with non-VNON\n");
- return (EBADF);
- }
-
- if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
- return (EOPNOTSUPP);
-
- /*
- * Multi-phase commit. First check the policies to confirm the
- * change is OK. Then commit via the filesystem. Finally,
- * update the actual vnode label. Question: maybe the filesystem
- * should update the vnode at the end as part of VOP_SETLABEL()?
- */
- error = mac_check_vnode_relabel(cred, vp, intlabel);
- if (error)
- return (error);
-
- /*
- * VADMIN provides the opportunity for the filesystem to make
- * decisions about who is and is not able to modify labels
- * and protections on files. This might not be right. We can't
- * assume VOP_SETLABEL() will do it, because we might implement
- * that as part of vop_stdsetlabel_ea().
- */
- error = VOP_ACCESS(vp, VADMIN, cred, curthread);
- if (error)
- return (error);
-
- error = VOP_SETLABEL(vp, intlabel, cred, curthread);
- if (error)
- return (error);
-
- return (0);
-}
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- struct proc *tproc;
- struct ucred *tcred;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- tproc = pfind(uap->pid);
- if (tproc == NULL)
- return (ESRCH);
-
- tcred = NULL; /* Satisfy gcc. */
- error = p_cansee(td, tproc);
- if (error == 0)
- tcred = crhold(tproc->p_ucred);
- PROC_UNLOCK(tproc);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&tcred->cr_label, elements,
- buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- crfree(tcred);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
- char *elements, *buffer;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = mac_externalize_cred_label(&td->td_ucred->cr_label,
- elements, buffer, mac.m_buflen, M_WAITOK);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
- struct ucred *newcred, *oldcred;
- struct label intlabel;
- struct proc *p;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_cred_label(&intlabel);
- error = mac_internalize_cred_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_cred_label(&intlabel);
- return (error);
- }
-
- newcred = crget();
-
- p = td->td_proc;
- PROC_LOCK(p);
- oldcred = p->p_ucred;
-
- error = mac_check_cred_relabel(oldcred, &intlabel);
- if (error) {
- PROC_UNLOCK(p);
- crfree(newcred);
- goto out;
- }
-
- setsugid(p);
- crcopy(newcred, oldcred);
- mac_relabel_cred(newcred, &intlabel);
- p->p_ucred = newcred;
-
- /*
- * Grab additional reference for use while revoking mmaps, prior
- * to releasing the proc lock and sharing the cred.
- */
- crhold(newcred);
- PROC_UNLOCK(p);
-
- if (mac_enforce_vm) {
- mtx_lock(&Giant);
- mac_cred_mmapped_drop_perms(td, newcred);
- mtx_unlock(&Giant);
- }
-
- crfree(newcred); /* Free revocation reference. */
- crfree(oldcred);
-
-out:
- mac_destroy_cred_label(&intlabel);
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
- char *elements, *buffer;
- struct label intlabel;
- struct file *fp;
- struct mac mac;
- struct vnode *vp;
- struct pipe *pipe;
- short label_type;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- label_type = fp->f_type;
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- vp = fp->f_data;
-
- mac_init_vnode_label(&intlabel);
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- mac_copy_vnode_label(&vp->v_label, &intlabel);
- VOP_UNLOCK(vp, 0, td);
-
- break;
- case DTYPE_PIPE:
- pipe = fp->f_data;
-
- mac_init_pipe_label(&intlabel);
-
- PIPE_LOCK(pipe);
- mac_copy_pipe_label(pipe->pipe_label, &intlabel);
- PIPE_UNLOCK(pipe);
- break;
- default:
- error = EINVAL;
- fdrop(fp, td);
- goto out;
- }
- fdrop(fp, td);
-
- switch (label_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- if (error == 0)
- error = mac_externalize_vnode_label(&intlabel,
- elements, buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_vnode_label(&intlabel);
- break;
- case DTYPE_PIPE:
- error = mac_externalize_pipe_label(&intlabel, elements,
- buffer, mac.m_buflen, M_WAITOK);
- mac_destroy_pipe_label(&intlabel);
- break;
- default:
- panic("__mac_get_fd: corrupted label_type");
- }
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
-
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
- char *elements, *buffer;
- struct nameidata nd;
- struct label intlabel;
- struct mac mac;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL);
- if (error) {
- free(elements, M_MACTEMP);
- return (error);
- }
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- mtx_lock(&Giant); /* VFS */
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error)
- goto out;
-
- mac_init_vnode_label(&intlabel);
- mac_copy_vnode_label(&nd.ni_vp->v_label, &intlabel);
- error = mac_externalize_vnode_label(&intlabel, elements, buffer,
- mac.m_buflen, M_WAITOK);
- NDFREE(&nd, 0);
- mac_destroy_vnode_label(&intlabel);
-
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
- free(elements, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
- struct label intlabel;
- struct pipe *pipe;
- struct file *fp;
- struct mount *mp;
- struct vnode *vp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- error = fget(td, uap->fd, &fp);
- if (error)
- goto out;
-
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vp = fp->f_data;
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
- if (error != 0) {
- mac_destroy_vnode_label(&intlabel);
- break;
- }
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
- error = vn_setlabel(vp, &intlabel, td->td_ucred);
- VOP_UNLOCK(vp, 0, td);
- vn_finished_write(mp);
-
- mac_destroy_vnode_label(&intlabel);
- break;
-
- case DTYPE_PIPE:
- mac_init_pipe_label(&intlabel);
- error = mac_internalize_pipe_label(&intlabel, buffer);
- if (error == 0) {
- pipe = fp->f_data;
- PIPE_LOCK(pipe);
- error = mac_pipe_label_set(td->td_ucred, pipe,
- &intlabel);
- PIPE_UNLOCK(pipe);
- }
-
- mac_destroy_pipe_label(&intlabel);
- break;
-
- default:
- error = EINVAL;
- }
-
- fdrop(fp, td);
-out:
- mtx_unlock(&Giant); /* VFS */
-
- free(buffer, M_MACTEMP);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
- struct label intlabel;
- struct nameidata nd;
- struct mount *mp;
- struct mac mac;
- char *buffer;
- int error;
-
- error = copyin(uap->mac_p, &mac, sizeof(mac));
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
- if (error) {
- free(buffer, M_MACTEMP);
- return (error);
- }
-
- mac_init_vnode_label(&intlabel);
- error = mac_internalize_vnode_label(&intlabel, buffer);
- free(buffer, M_MACTEMP);
- if (error) {
- mac_destroy_vnode_label(&intlabel);
- return (error);
- }
-
- mtx_lock(&Giant); /* VFS */
-
- NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p,
- td);
- error = namei(&nd);
- if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
- if (error == 0)
- error = vn_setlabel(nd.ni_vp, &intlabel,
- td->td_ucred);
- vn_finished_write(mp);
- }
-
- NDFREE(&nd, 0);
- mtx_unlock(&Giant); /* VFS */
- mac_destroy_vnode_label(&intlabel);
-
- return (error);
-}
-
-/*
- * MPSAFE
- */
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
- struct mac_policy_conf *mpc;
- char target[MAC_MAX_POLICY_NAME];
- int entrycount, error;
-
- error = copyinstr(uap->policy, target, sizeof(target), NULL);
- if (error)
- return (error);
-
- error = ENOSYS;
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- goto out;
- }
- }
-
- if ((entrycount = mac_policy_list_conditional_busy()) != 0) {
- LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
- if (strcmp(mpc->mpc_name, target) == 0 &&
- mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
- break;
- }
- }
- mac_policy_list_unbusy();
- }
-out:
- return (error);
-}
-
-SYSINIT(mac, SI_SUB_MAC, SI_ORDER_FIRST, mac_init, NULL);
-SYSINIT(mac_late, SI_SUB_MAC_LATE, SI_ORDER_FIRST, mac_late_init, NULL);
-
-#else /* !MAC */
-
-int
-__mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
-{
-
- return (ENOSYS);
-}
-
-int
-mac_syscall(struct thread *td, struct mac_syscall_args *uap)
-{
-
- return (ENOSYS);
-}
-
-#endif
diff --git a/sys/security/mac_stub/mac_stub.c b/sys/security/mac_stub/mac_stub.c
deleted file mode 100644
index 5a600ea5cff9..000000000000
--- a/sys/security/mac_stub/mac_stub.c
+++ /dev/null
@@ -1,1118 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * Copyright (c) 2001, 2002 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * This software was developed by Robert Watson for the TrustedBSD Project.
- *
- * This software was developed for the FreeBSD Project in part by Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
- * as part of the DARPA CHATS research program.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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$
- */
-
-/*
- * Developed by the TrustedBSD Project.
- * Generic mandatory access module that does nothing.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/acl.h>
-#include <sys/conf.h>
-#include <sys/extattr.h>
-#include <sys/kernel.h>
-#include <sys/mac.h>
-#include <sys/mount.h>
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/sysent.h>
-#include <sys/vnode.h>
-#include <sys/file.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/pipe.h>
-#include <sys/sysctl.h>
-
-#include <fs/devfs/devfs.h>
-
-#include <net/bpfdesc.h>
-#include <net/if.h>
-#include <net/if_types.h>
-#include <net/if_var.h>
-
-#include <netinet/in.h>
-#include <netinet/ip_var.h>
-
-#include <vm/vm.h>
-
-#include <sys/mac_policy.h>
-
-SYSCTL_DECL(_security_mac);
-
-SYSCTL_NODE(_security_mac, OID_AUTO, none, CTLFLAG_RW, 0,
- "TrustedBSD mac_none policy controls");
-
-static int mac_none_enabled = 1;
-SYSCTL_INT(_security_mac_none, OID_AUTO, enabled, CTLFLAG_RW,
- &mac_none_enabled, 0, "Enforce none policy");
-
-/*
- * Policy module operations.
- */
-static void
-mac_none_destroy(struct mac_policy_conf *conf)
-{
-
-}
-
-static void
-mac_none_init(struct mac_policy_conf *conf)
-{
-
-}
-
-static int
-mac_none_syscall(struct thread *td, int call, void *arg)
-{
-
- return (0);
-}
-
-/*
- * Label operations.
- */
-static void
-mac_none_init_label(struct label *label)
-{
-
-}
-
-static int
-mac_none_init_label_waitcheck(struct label *label, int flag)
-{
-
- return (0);
-}
-
-static void
-mac_none_destroy_label(struct label *label)
-{
-
-}
-
-static int
-mac_none_externalize_label(struct label *label, char *element_name,
- char *element_data, size_t size, size_t *len, int *claimed)
-{
-
- return (0);
-}
-
-static int
-mac_none_internalize_label(struct label *label, char *element_name,
- char *element_data, int *claimed)
-{
-
- return (0);
-}
-
-/*
- * Labeling event operations: file system objects, and things that look
- * a lot like file system objects.
- */
-static void
-mac_none_associate_vnode_devfs(struct mount *mp, struct label *fslabel,
- struct devfs_dirent *de, struct label *delabel, struct vnode *vp,
- struct label *vlabel)
-{
-
-}
-
-static int
-mac_none_associate_vnode_extattr(struct mount *mp, struct label *fslabel,
- struct vnode *vp, struct label *vlabel)
-{
-
- return (0);
-}
-
-static void
-mac_none_associate_vnode_singlelabel(struct mount *mp,
- struct label *fslabel, struct vnode *vp, struct label *vlabel)
-{
-
-}
-
-static void
-mac_none_create_devfs_device(struct mount *mp, dev_t dev,
- struct devfs_dirent *devfs_dirent, struct label *label)
-{
-
-}
-
-static void
-mac_none_create_devfs_directory(struct mount *mp, char *dirname,
- int dirnamelen, struct devfs_dirent *devfs_dirent, struct label *label)
-{
-
-}
-
-static void
-mac_none_create_devfs_symlink(struct ucred *cred, struct mount *mp,
- struct devfs_dirent *dd, struct label *ddlabel, struct devfs_dirent *de,
- struct label *delabel)
-{
-
-}
-
-static int
-mac_none_create_vnode_extattr(struct ucred *cred, struct mount *mp,
- struct label *fslabel, struct vnode *dvp, struct label *dlabel,
- struct vnode *vp, struct label *vlabel, struct componentname *cnp)
-{
-
- return (0);
-}
-
-static void
-mac_none_create_mount(struct ucred *cred, struct mount *mp,
- struct label *mntlabel, struct label *fslabel)
-{
-
-}
-
-static void
-mac_none_create_root_mount(struct ucred *cred, struct mount *mp,
- struct label *mntlabel, struct label *fslabel)
-{
-
-}
-
-static void
-mac_none_relabel_vnode(struct ucred *cred, struct vnode *vp,
- struct label *vnodelabel, struct label *label)
-{
-
-}
-
-static int
-mac_none_setlabel_vnode_extattr(struct ucred *cred, struct vnode *vp,
- struct label *vlabel, struct label *intlabel)
-{
-
- return (0);
-}
-
-static void
-mac_none_update_devfsdirent(struct mount *mp,
- struct devfs_dirent *devfs_dirent, struct label *direntlabel,
- struct vnode *vp, struct label *vnodelabel)
-{
-
-}
-
-/*
- * Labeling event operations: IPC object.
- */
-static void
-mac_none_create_mbuf_from_socket(struct socket *so, struct label *socketlabel,
- struct mbuf *m, struct label *mbuflabel)
-{
-
-}
-
-static void
-mac_none_create_socket(struct ucred *cred, struct socket *socket,
- struct label *socketlabel)
-{
-
-}
-
-static void
-mac_none_create_pipe(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel)
-{
-
-}
-
-static void
-mac_none_create_socket_from_socket(struct socket *oldsocket,
- struct label *oldsocketlabel, struct socket *newsocket,
- struct label *newsocketlabel)
-{
-
-}
-
-static void
-mac_none_relabel_socket(struct ucred *cred, struct socket *socket,
- struct label *socketlabel, struct label *newlabel)
-{
-
-}
-
-static void
-mac_none_relabel_pipe(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel, struct label *newlabel)
-{
-
-}
-
-static void
-mac_none_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct label *mbuflabel,
- struct socket *socket, struct label *socketpeerlabel)
-{
-
-}
-
-static void
-mac_none_set_socket_peer_from_socket(struct socket *oldsocket,
- struct label *oldsocketlabel, struct socket *newsocket,
- struct label *newsocketpeerlabel)
-{
-
-}
-
-/*
- * Labeling event operations: network objects.
- */
-static void
-mac_none_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d,
- struct label *bpflabel)
-{
-
-}
-
-static void
-mac_none_create_datagram_from_ipq(struct ipq *ipq, struct label *ipqlabel,
- struct mbuf *datagram, struct label *datagramlabel)
-{
-
-}
-
-static void
-mac_none_create_fragment(struct mbuf *datagram, struct label *datagramlabel,
- struct mbuf *fragment, struct label *fragmentlabel)
-{
-
-}
-
-static void
-mac_none_create_ifnet(struct ifnet *ifnet, struct label *ifnetlabel)
-{
-
-}
-
-static void
-mac_none_create_ipq(struct mbuf *fragment, struct label *fragmentlabel,
- struct ipq *ipq, struct label *ipqlabel)
-{
-
-}
-
-static void
-mac_none_create_mbuf_from_mbuf(struct mbuf *oldmbuf,
- struct label *oldmbuflabel, struct mbuf *newmbuf,
- struct label *newmbuflabel)
-{
-
-}
-
-static void
-mac_none_create_mbuf_linklayer(struct ifnet *ifnet, struct label *ifnetlabel,
- struct mbuf *mbuf, struct label *mbuflabel)
-{
-
-}
-
-static void
-mac_none_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct label *bpflabel,
- struct mbuf *mbuf, struct label *mbuflabel)
-{
-
-}
-
-static void
-mac_none_create_mbuf_from_ifnet(struct ifnet *ifnet, struct label *ifnetlabel,
- struct mbuf *m, struct label *mbuflabel)
-{
-
-}
-
-static void
-mac_none_create_mbuf_multicast_encap(struct mbuf *oldmbuf,
- struct label *oldmbuflabel, struct ifnet *ifnet, struct label *ifnetlabel,
- struct mbuf *newmbuf, struct label *newmbuflabel)
-{
-
-}
-
-static void
-mac_none_create_mbuf_netlayer(struct mbuf *oldmbuf,
- struct label *oldmbuflabel, struct mbuf *newmbuf, struct label *newmbuflabel)
-{
-
-}
-
-static int
-mac_none_fragment_match(struct mbuf *fragment, struct label *fragmentlabel,
- struct ipq *ipq, struct label *ipqlabel)
-{
-
- return (1);
-}
-
-static void
-mac_none_relabel_ifnet(struct ucred *cred, struct ifnet *ifnet,
- struct label *ifnetlabel, struct label *newlabel)
-{
-
-}
-
-static void
-mac_none_update_ipq(struct mbuf *fragment, struct label *fragmentlabel,
- struct ipq *ipq, struct label *ipqlabel)
-{
-
-}
-
-/*
- * Labeling event operations: processes.
- */
-static void
-mac_none_create_cred(struct ucred *cred_parent, struct ucred *cred_child)
-{
-
-}
-
-static void
-mac_none_execve_transition(struct ucred *old, struct ucred *new,
- struct vnode *vp, struct label *vnodelabel,
- struct label *interpvnodelabel, struct image_params *imgp,
- struct label *execlabel)
-{
-
-}
-
-static int
-mac_none_execve_will_transition(struct ucred *old, struct vnode *vp,
- struct label *vnodelabel, struct label *interpvnodelabel,
- struct image_params *imgp, struct label *execlabel)
-{
-
- return (0);
-}
-
-static void
-mac_none_create_proc0(struct ucred *cred)
-{
-
-}
-
-static void
-mac_none_create_proc1(struct ucred *cred)
-{
-
-}
-
-static void
-mac_none_relabel_cred(struct ucred *cred, struct label *newlabel)
-{
-
-}
-
-static void
-mac_none_thread_userret(struct thread *td)
-{
-
-}
-
-/*
- * Access control checks.
- */
-static int
-mac_none_check_bpfdesc_receive(struct bpf_d *bpf_d, struct label *bpflabel,
- struct ifnet *ifnet, struct label *ifnet_label)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_cred_relabel(struct ucred *cred, struct label *newlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_cred_visible(struct ucred *u1, struct ucred *u2)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_ifnet_relabel(struct ucred *cred, struct ifnet *ifnet,
- struct label *ifnetlabel, struct label *newlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_ifnet_transmit(struct ifnet *ifnet, struct label *ifnetlabel,
- struct mbuf *m, struct label *mbuflabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_kenv_dump(struct ucred *cred)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_kenv_get(struct ucred *cred, char *name)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_kenv_set(struct ucred *cred, char *name, char *value)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_kenv_unset(struct ucred *cred, char *name)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_kld_load(struct ucred *cred, struct vnode *vp,
- struct label *vlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_kld_stat(struct ucred *cred)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_kld_unload(struct ucred *cred)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_mount_stat(struct ucred *cred, struct mount *mp,
- struct label *mntlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel, unsigned long cmd, void /* caddr_t */ *data)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_pipe_poll(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_pipe_read(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_pipe_relabel(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel, struct label *newlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_pipe_stat(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_pipe_write(struct ucred *cred, struct pipe *pipe,
- struct label *pipelabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_proc_debug(struct ucred *cred, struct proc *proc)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_proc_sched(struct ucred *cred, struct proc *proc)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_proc_signal(struct ucred *cred, struct proc *proc, int signum)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_socket_bind(struct ucred *cred, struct socket *socket,
- struct label *socketlabel, struct sockaddr *sockaddr)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_socket_connect(struct ucred *cred, struct socket *socket,
- struct label *socketlabel, struct sockaddr *sockaddr)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_socket_deliver(struct socket *so, struct label *socketlabel,
- struct mbuf *m, struct label *mbuflabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_socket_listen(struct ucred *cred, struct socket *so,
- struct label *socketlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_socket_relabel(struct ucred *cred, struct socket *socket,
- struct label *socketlabel, struct label *newlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_socket_visible(struct ucred *cred, struct socket *socket,
- struct label *socketlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_sysarch_ioperm(struct ucred *cred)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_system_acct(struct ucred *cred, struct vnode *vp,
- struct label *vlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_system_reboot(struct ucred *cred, int how)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_system_settime(struct ucred *cred)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_system_swapon(struct ucred *cred, struct vnode *vp,
- struct label *label)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_system_swapoff(struct ucred *cred, struct vnode *vp,
- struct label *label)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_system_sysctl(struct ucred *cred, int *name, u_int namelen,
- void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_access(struct ucred *cred, struct vnode *vp,
- struct label *label, int acc_mode)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_chdir(struct ucred *cred, struct vnode *dvp,
- struct label *dlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_chroot(struct ucred *cred, struct vnode *dvp,
- struct label *dlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_create(struct ucred *cred, struct vnode *dvp,
- struct label *dlabel, struct componentname *cnp, struct vattr *vap)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_delete(struct ucred *cred, struct vnode *dvp,
- struct label *dlabel, struct vnode *vp, struct label *label,
- struct componentname *cnp)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
- struct label *label, acl_type_t type)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_exec(struct ucred *cred, struct vnode *vp,
- struct label *label, struct image_params *imgp,
- struct label *execlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_getacl(struct ucred *cred, struct vnode *vp,
- struct label *label, acl_type_t type)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
- struct label *label, int attrnamespace, const char *name, struct uio *uio)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_link(struct ucred *cred, struct vnode *dvp,
- struct label *dlabel, struct vnode *vp, struct label *label,
- struct componentname *cnp)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
- struct label *dlabel, struct componentname *cnp)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_mmap(struct ucred *cred, struct vnode *vp,
- struct label *label, int prot)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_mprotect(struct ucred *cred, struct vnode *vp,
- struct label *label, int prot)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_open(struct ucred *cred, struct vnode *vp,
- struct label *filelabel, int acc_mode)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp, struct label *label)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp, struct label *label)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_readdir(struct ucred *cred, struct vnode *vp,
- struct label *dlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_readlink(struct ucred *cred, struct vnode *vp,
- struct label *vnodelabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_relabel(struct ucred *cred, struct vnode *vp,
- struct label *vnodelabel, struct label *newlabel)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
- struct label *dlabel, struct vnode *vp, struct label *label,
- struct componentname *cnp)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
- struct label *dlabel, struct vnode *vp, struct label *label, int samedir,
- struct componentname *cnp)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_revoke(struct ucred *cred, struct vnode *vp,
- struct label *label)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_setacl(struct ucred *cred, struct vnode *vp,
- struct label *label, acl_type_t type, struct acl *acl)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
- struct label *label, int attrnamespace, const char *name, struct uio *uio)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_setflags(struct ucred *cred, struct vnode *vp,
- struct label *label, u_long flags)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_setmode(struct ucred *cred, struct vnode *vp,
- struct label *label, mode_t mode)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_setowner(struct ucred *cred, struct vnode *vp,
- struct label *label, uid_t uid, gid_t gid)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
- struct label *label, struct timespec atime, struct timespec mtime)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred,
- struct vnode *vp, struct label *label)
-{
-
- return (0);
-}
-
-static int
-mac_none_check_vnode_write(struct ucred *active_cred,
- struct ucred *file_cred, struct vnode *vp, struct label *label)
-{
-
- return (0);
-}
-
-static struct mac_policy_ops mac_none_ops =
-{
- .mpo_destroy = mac_none_destroy,
- .mpo_init = mac_none_init,
- .mpo_syscall = mac_none_syscall,
- .mpo_init_bpfdesc_label = mac_none_init_label,
- .mpo_init_cred_label = mac_none_init_label,
- .mpo_init_devfsdirent_label = mac_none_init_label,
- .mpo_init_ifnet_label = mac_none_init_label,
- .mpo_init_ipq_label = mac_none_init_label_waitcheck,
- .mpo_init_mbuf_label = mac_none_init_label_waitcheck,
- .mpo_init_mount_label = mac_none_init_label,
- .mpo_init_mount_fs_label = mac_none_init_label,
- .mpo_init_pipe_label = mac_none_init_label,
- .mpo_init_socket_label = mac_none_init_label_waitcheck,
- .mpo_init_socket_peer_label = mac_none_init_label_waitcheck,
- .mpo_init_vnode_label = mac_none_init_label,
- .mpo_destroy_bpfdesc_label = mac_none_destroy_label,
- .mpo_destroy_cred_label = mac_none_destroy_label,
- .mpo_destroy_devfsdirent_label = mac_none_destroy_label,
- .mpo_destroy_ifnet_label = mac_none_destroy_label,
- .mpo_destroy_ipq_label = mac_none_destroy_label,
- .mpo_destroy_mbuf_label = mac_none_destroy_label,
- .mpo_destroy_mount_label = mac_none_destroy_label,
- .mpo_destroy_mount_fs_label = mac_none_destroy_label,
- .mpo_destroy_pipe_label = mac_none_destroy_label,
- .mpo_destroy_socket_label = mac_none_destroy_label,
- .mpo_destroy_socket_peer_label = mac_none_destroy_label,
- .mpo_destroy_vnode_label = mac_none_destroy_label,
- .mpo_externalize_cred_label = mac_none_externalize_label,
- .mpo_externalize_ifnet_label = mac_none_externalize_label,
- .mpo_externalize_pipe_label = mac_none_externalize_label,
- .mpo_externalize_socket_label = mac_none_externalize_label,
- .mpo_externalize_socket_peer_label = mac_none_externalize_label,
- .mpo_externalize_vnode_label = mac_none_externalize_label,
- .mpo_internalize_cred_label = mac_none_internalize_label,
- .mpo_internalize_ifnet_label = mac_none_internalize_label,
- .mpo_internalize_pipe_label = mac_none_internalize_label,
- .mpo_internalize_socket_label = mac_none_internalize_label,
- .mpo_internalize_vnode_label = mac_none_internalize_label,
- .mpo_associate_vnode_devfs = mac_none_associate_vnode_devfs,
- .mpo_associate_vnode_extattr = mac_none_associate_vnode_extattr,
- .mpo_associate_vnode_singlelabel = mac_none_associate_vnode_singlelabel,
- .mpo_create_devfs_device = mac_none_create_devfs_device,
- .mpo_create_devfs_directory = mac_none_create_devfs_directory,
- .mpo_create_devfs_symlink = mac_none_create_devfs_symlink,
- .mpo_create_vnode_extattr = mac_none_create_vnode_extattr,
- .mpo_create_mount = mac_none_create_mount,
- .mpo_create_root_mount = mac_none_create_root_mount,
- .mpo_relabel_vnode = mac_none_relabel_vnode,
- .mpo_setlabel_vnode_extattr = mac_none_setlabel_vnode_extattr,
- .mpo_update_devfsdirent = mac_none_update_devfsdirent,
- .mpo_create_mbuf_from_socket = mac_none_create_mbuf_from_socket,
- .mpo_create_pipe = mac_none_create_pipe,
- .mpo_create_socket = mac_none_create_socket,
- .mpo_create_socket_from_socket = mac_none_create_socket_from_socket,
- .mpo_relabel_pipe = mac_none_relabel_pipe,
- .mpo_relabel_socket = mac_none_relabel_socket,
- .mpo_set_socket_peer_from_mbuf = mac_none_set_socket_peer_from_mbuf,
- .mpo_set_socket_peer_from_socket = mac_none_set_socket_peer_from_socket,
- .mpo_create_bpfdesc = mac_none_create_bpfdesc,
- .mpo_create_ifnet = mac_none_create_ifnet,
- .mpo_create_ipq = mac_none_create_ipq,
- .mpo_create_datagram_from_ipq = mac_none_create_datagram_from_ipq,
- .mpo_create_fragment = mac_none_create_fragment,
- .mpo_create_ipq = mac_none_create_ipq,
- .mpo_create_mbuf_from_mbuf = mac_none_create_mbuf_from_mbuf,
- .mpo_create_mbuf_linklayer = mac_none_create_mbuf_linklayer,
- .mpo_create_mbuf_from_bpfdesc = mac_none_create_mbuf_from_bpfdesc,
- .mpo_create_mbuf_from_ifnet = mac_none_create_mbuf_from_ifnet,
- .mpo_create_mbuf_multicast_encap = mac_none_create_mbuf_multicast_encap,
- .mpo_create_mbuf_netlayer = mac_none_create_mbuf_netlayer,
- .mpo_fragment_match = mac_none_fragment_match,
- .mpo_relabel_ifnet = mac_none_relabel_ifnet,
- .mpo_update_ipq = mac_none_update_ipq,
- .mpo_create_cred = mac_none_create_cred,
- .mpo_execve_transition = mac_none_execve_transition,
- .mpo_execve_will_transition = mac_none_execve_will_transition,
- .mpo_create_proc0 = mac_none_create_proc0,
- .mpo_create_proc1 = mac_none_create_proc1,
- .mpo_relabel_cred = mac_none_relabel_cred,
- .mpo_thread_userret = mac_none_thread_userret,
- .mpo_check_bpfdesc_receive = mac_none_check_bpfdesc_receive,
- .mpo_check_cred_relabel = mac_none_check_cred_relabel,
- .mpo_check_cred_visible = mac_none_check_cred_visible,
- .mpo_check_ifnet_relabel = mac_none_check_ifnet_relabel,
- .mpo_check_ifnet_transmit = mac_none_check_ifnet_transmit,
- .mpo_check_kenv_dump = mac_none_check_kenv_dump,
- .mpo_check_kenv_get = mac_none_check_kenv_get,
- .mpo_check_kenv_set = mac_none_check_kenv_set,
- .mpo_check_kenv_unset = mac_none_check_kenv_unset,
- .mpo_check_kld_load = mac_none_check_kld_load,
- .mpo_check_kld_stat = mac_none_check_kld_stat,
- .mpo_check_kld_unload = mac_none_check_kld_unload,
- .mpo_check_mount_stat = mac_none_check_mount_stat,
- .mpo_check_pipe_ioctl = mac_none_check_pipe_ioctl,
- .mpo_check_pipe_poll = mac_none_check_pipe_poll,
- .mpo_check_pipe_read = mac_none_check_pipe_read,
- .mpo_check_pipe_relabel = mac_none_check_pipe_relabel,
- .mpo_check_pipe_stat = mac_none_check_pipe_stat,
- .mpo_check_pipe_write = mac_none_check_pipe_write,
- .mpo_check_proc_debug = mac_none_check_proc_debug,
- .mpo_check_proc_sched = mac_none_check_proc_sched,
- .mpo_check_proc_signal = mac_none_check_proc_signal,
- .mpo_check_socket_bind = mac_none_check_socket_bind,
- .mpo_check_socket_connect = mac_none_check_socket_connect,
- .mpo_check_socket_deliver = mac_none_check_socket_deliver,
- .mpo_check_socket_listen = mac_none_check_socket_listen,
- .mpo_check_socket_relabel = mac_none_check_socket_relabel,
- .mpo_check_socket_visible = mac_none_check_socket_visible,
- .mpo_check_sysarch_ioperm = mac_none_check_sysarch_ioperm,
- .mpo_check_system_acct = mac_none_check_system_acct,
- .mpo_check_system_reboot = mac_none_check_system_reboot,
- .mpo_check_system_settime = mac_none_check_system_settime,
- .mpo_check_system_swapon = mac_none_check_system_swapon,
- .mpo_check_system_swapoff = mac_none_check_system_swapoff,
- .mpo_check_system_sysctl = mac_none_check_system_sysctl,
- .mpo_check_vnode_access = mac_none_check_vnode_access,
- .mpo_check_vnode_chdir = mac_none_check_vnode_chdir,
- .mpo_check_vnode_chroot = mac_none_check_vnode_chroot,
- .mpo_check_vnode_create = mac_none_check_vnode_create,
- .mpo_check_vnode_delete = mac_none_check_vnode_delete,
- .mpo_check_vnode_deleteacl = mac_none_check_vnode_deleteacl,
- .mpo_check_vnode_exec = mac_none_check_vnode_exec,
- .mpo_check_vnode_getacl = mac_none_check_vnode_getacl,
- .mpo_check_vnode_getextattr = mac_none_check_vnode_getextattr,
- .mpo_check_vnode_link = mac_none_check_vnode_link,
- .mpo_check_vnode_lookup = mac_none_check_vnode_lookup,
- .mpo_check_vnode_mmap = mac_none_check_vnode_mmap,
- .mpo_check_vnode_mprotect = mac_none_check_vnode_mprotect,
- .mpo_check_vnode_open = mac_none_check_vnode_open,
- .mpo_check_vnode_poll = mac_none_check_vnode_poll,
- .mpo_check_vnode_read = mac_none_check_vnode_read,
- .mpo_check_vnode_readdir = mac_none_check_vnode_readdir,
- .mpo_check_vnode_readlink = mac_none_check_vnode_readlink,
- .mpo_check_vnode_relabel = mac_none_check_vnode_relabel,
- .mpo_check_vnode_rename_from = mac_none_check_vnode_rename_from,
- .mpo_check_vnode_rename_to = mac_none_check_vnode_rename_to,
- .mpo_check_vnode_revoke = mac_none_check_vnode_revoke,
- .mpo_check_vnode_setacl = mac_none_check_vnode_setacl,
- .mpo_check_vnode_setextattr = mac_none_check_vnode_setextattr,
- .mpo_check_vnode_setflags = mac_none_check_vnode_setflags,
- .mpo_check_vnode_setmode = mac_none_check_vnode_setmode,
- .mpo_check_vnode_setowner = mac_none_check_vnode_setowner,
- .mpo_check_vnode_setutimes = mac_none_check_vnode_setutimes,
- .mpo_check_vnode_stat = mac_none_check_vnode_stat,
- .mpo_check_vnode_write = mac_none_check_vnode_write,
-};
-
-MAC_POLICY_SET(&mac_none_ops, mac_none, "TrustedBSD MAC/None",
- MPC_LOADTIME_FLAG_UNLOADOK, NULL);
diff --git a/sys/sparc64/include/ofw_nexus.h b/sys/sparc64/include/ofw_nexus.h
deleted file mode 100644
index 7ee0c401910e..000000000000
--- a/sys/sparc64/include/ofw_nexus.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 1998, 1999 Eduardo E. Horvath
- * Copyright (c) 1999 Matthew R. Green
- * 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.
- *
- * from: NetBSD: psychoreg.h,v 1.8 2001/09/10 16:17:06 eeh Exp
- *
- * $FreeBSD$
- */
-
-#ifndef _MACHINE_OFW_UPA_H_
-#define _MACHINE_OFW_UPA_H_
-
-/*
- * These are the regs and ranges property the psycho uses. They should be
- * applicable to all UPA devices. XXX: verify this.
- */
-
-struct upa_regs {
- u_int32_t phys_hi;
- u_int32_t phys_lo;
- u_int32_t size_hi;
- u_int32_t size_lo;
-};
-
-struct upa_ranges {
- u_int32_t cspace;
- u_int32_t child_hi;
- u_int32_t child_lo;
- u_int32_t phys_hi;
- u_int32_t phys_lo;
- u_int32_t size_hi;
- u_int32_t size_lo;
-};
-
-#define UPA_REG_PHYS(r) \
- (((u_int64_t)(r)->phys_hi << 32) | (u_int64_t)(r)->phys_lo)
-#define UPA_REG_SIZE(r) \
- (((u_int64_t)(r)->size_hi << 32) | (u_int64_t)(r)->size_lo)
-
-#define UPA_RANGE_CHILD(r) \
- (((u_int64_t)(r)->child_hi << 32) | (u_int64_t)(r)->child_lo)
-#define UPA_RANGE_PHYS(r) \
- (((u_int64_t)(r)->phys_hi << 32) | (u_int64_t)(r)->phys_lo)
-#define UPA_RANGE_SIZE(r) \
- (((u_int64_t)(r)->size_hi << 32) | (u_int64_t)(r)->size_lo)
-#define UPA_RANGE_CS(r) (((r)->cspace >> 24) & 0x03)
-
-#endif /* !_MACHINE_OFW_UPA_H_ */
diff --git a/sys/sparc64/pci/ofw_pci_if.m b/sys/sparc64/pci/ofw_pci_if.m
deleted file mode 100644
index fe7826e6cb2d..000000000000
--- a/sys/sparc64/pci/ofw_pci_if.m
+++ /dev/null
@@ -1,93 +0,0 @@
-# Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED 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$
-
-#include <sys/bus.h>
-#include <machine/bus.h>
-
-#include <dev/ofw/openfirm.h>
-
-INTERFACE sparcbus;
-
-HEADER {
- /* Bus tag types for the get_bustag method */
- enum sbbt_id {
- SBBT_IO,
- SBBT_MEM,
- };
-};
-
-CODE {
- static int
- sparcbus_default_intr_pending(device_t dev, int intr)
- {
-
- return (SPARCBUS_INTR_PENDING(device_get_parent(dev), intr));
- }
-
- static u_int32_t
- sparcbus_default_guess_ino(device_t dev, phandle_t node, u_int slot,
- u_int pin)
- {
-
- return (SPARCBUS_GUESS_INO(device_get_parent(dev), node, slot,
- pin));
- }
-
- static bus_space_handle_t
- sparcbus_default_get_bus_handle(device_t dev, enum sbbt_id id,
- bus_space_handle_t childhdl, bus_space_tag_t *tag)
- {
-
- return (SPARCBUS_GET_BUS_HANDLE(device_get_parent(dev), id,
- childhdl, tag));
- }
-};
-
-# Return whether an interrupt request is pending for the INO intr.
-METHOD int intr_pending {
- device_t dev;
- int intr;
-} DEFAULT sparcbus_default_intr_pending;
-
-# Let the bus driver guess the INO of the device at the given slot and intpin
-# on the bus described by the node if it could not be determined from the
-# firmware properties. Returns 255 if no INO could be found (mapping will
-# continue at the parent), or the desired INO.
-METHOD u_int32_t guess_ino {
- device_t dev;
- phandle_t node;
- u_int slot;
- u_int pin;
-} DEFAULT sparcbus_default_guess_ino;
-
-# Get the bustag for the root bus. This is needed for ISA old-stlye
-# in[bwl]()/out[bwl]() support, where no tag retrieved from a resource is
-# passed. The returned tag is used to construct a tag for the whole ISA bus.
-METHOD bus_space_handle_t get_bus_handle {
- device_t dev;
- enum sbbt_id id;
- bus_space_handle_t childhdl;
- bus_space_tag_t *tag;
-} DEFAULT sparcbus_default_get_bus_handle;
diff --git a/sys/sys/_semaphore.h b/sys/sys/_semaphore.h
deleted file mode 100644
index 0024c7291969..000000000000
--- a/sys/sys/_semaphore.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2002 Alfred Perlstein <alfred@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-#ifndef __SEMAPHORE_H_
-#define __SEMAPHORE_H_
-
-typedef intptr_t semid_t;
-
-#ifndef _KERNEL
-
-#include <sys/cdefs.h>
-
-/*
- * Semaphore definitions.
- */
-struct sem {
-#define SEM_MAGIC ((u_int32_t) 0x09fa4012)
- u_int32_t magic;
- pthread_mutex_t lock;
- pthread_cond_t gtzero;
- u_int32_t count;
- u_int32_t nwaiters;
-#define SEM_USER (NULL)
- semid_t semid; /* semaphore id if kernel (shared) semaphore */
- int syssem; /* 1 if kernel (shared) semaphore */
- LIST_ENTRY(sem) entry;
- struct sem **backpointer;
-};
-
-__BEGIN_DECLS
-
-int ksem_close(semid_t id);
-int ksem_post(semid_t id);
-int ksem_wait(semid_t id);
-int ksem_trywait(semid_t id);
-int ksem_init(semid_t *idp, unsigned int value);
-int ksem_open(semid_t *idp, const char *name, int oflag, mode_t mode,
- unsigned int value);
-int ksem_unlink(const char *name);
-int ksem_getvalue(semid_t id, int *val);
-int ksem_destroy(semid_t id);
-
-__END_DECLS
-
-#endif /* !_KERNEL */
-
-#endif /* __SEMAPHORE_H_ */
diff --git a/sys/sys/aac_ioctl.h b/sys/sys/aac_ioctl.h
deleted file mode 100644
index 1b798ebd8238..000000000000
--- a/sys/sys/aac_ioctl.h
+++ /dev/null
@@ -1,179 +0,0 @@
-/*-
- * Copyright (c) 2000 Michael Smith
- * Copyright (c) 2000 Scott Long
- * 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.
- *
- * $FreeBSD$
- */
-
-/*
- * Command queue statistics
- */
-#define AACQ_FREE 0
-#define AACQ_BIO 1
-#define AACQ_READY 2
-#define AACQ_BUSY 3
-#define AACQ_COMPLETE 4
-#define AACQ_COUNT 5 /* total number of queues */
-
-struct aac_qstat {
- u_int32_t q_length;
- u_int32_t q_max;
-};
-
-/*
- * Statistics request
- */
-union aac_statrequest {
- u_int32_t as_item;
- struct aac_qstat as_qstat;
-};
-
-#define AACIO_STATS _IOWR('T', 101, union aac_statrequest)
-
-/*
- * Ioctl commands likely to be submitted from a Linux management application.
- * These bit encodings are actually descended from Windows NT. Ick.
- */
-
-#define CTL_CODE(devType, func, meth, acc) (((devType) << 16) | ((acc) << 14) | ((func) << 2) | (meth))
-#define METHOD_BUFFERED 0
-#define METHOD_IN_DIRECT 1
-#define METHOD_OUT_DIRECT 2
-#define METHOD_NEITHER 3
-#define FILE_ANY_ACCESS 0
-#define FILE_READ_ACCESS ( 0x0001 )
-#define FILE_WRITE_ACCESS ( 0x0002 )
-#define FILE_DEVICE_CONTROLLER 0x00000004
-
-#define FSACTL_LNX_SENDFIB CTL_CODE(FILE_DEVICE_CONTROLLER, 2050, \
- METHOD_BUFFERED, FILE_ANY_ACCESS)
-#define FSACTL_LNX_GET_COMM_PERF_DATA CTL_CODE(FILE_DEVICE_CONTROLLER, 2084, \
- METHOD_BUFFERED, FILE_ANY_ACCESS)
-#define FSACTL_LNX_OPENCLS_COMM_PERF_DATA CTL_CODE(FILE_DEVICE_CONTROLLER, \
- 2085, METHOD_BUFFERED, FILE_ANY_ACCESS)
-#define FSACTL_LNX_OPEN_GET_ADAPTER_FIB CTL_CODE(FILE_DEVICE_CONTROLLER, 2100, \
- METHOD_BUFFERED, FILE_ANY_ACCESS)
-#define FSACTL_LNX_GET_NEXT_ADAPTER_FIB CTL_CODE(FILE_DEVICE_CONTROLLER, 2101, \
- METHOD_BUFFERED, FILE_ANY_ACCESS)
-#define FSACTL_LNX_CLOSE_GET_ADAPTER_FIB CTL_CODE(FILE_DEVICE_CONTROLLER, \
- 2102, METHOD_BUFFERED, FILE_ANY_ACCESS)
-#define FSACTL_LNX_CLOSE_ADAPTER_CONFIG CTL_CODE(FILE_DEVICE_CONTROLLER, 2104, \
- METHOD_BUFFERED, FILE_ANY_ACCESS)
-#define FSACTL_LNX_OPEN_ADAPTER_CONFIG CTL_CODE(FILE_DEVICE_CONTROLLER, 2105, \
- METHOD_BUFFERED, FILE_ANY_ACCESS)
-#define FSACTL_LNX_MINIPORT_REV_CHECK CTL_CODE(FILE_DEVICE_CONTROLLER, 2107, \
- METHOD_BUFFERED, FILE_ANY_ACCESS)
-#define FSACTL_LNX_QUERY_ADAPTER_CONFIG CTL_CODE(FILE_DEVICE_CONTROLLER, 2113, \
- METHOD_BUFFERED, FILE_ANY_ACCESS)
-#define FSACTL_LNX_GET_PCI_INFO CTL_CODE(FILE_DEVICE_CONTROLLER, 2119, \
- METHOD_BUFFERED, FILE_ANY_ACCESS)
-#define FSACTL_LNX_FORCE_DELETE_DISK CTL_CODE(FILE_DEVICE_CONTROLLER, 2120, \
- METHOD_NEITHER, FILE_ANY_ACCESS)
-#define FSACTL_LNX_AIF_THREAD CTL_CODE(FILE_DEVICE_CONTROLLER, 2127, \
- METHOD_NEITHER, FILE_ANY_ACCESS)
-
-/* Why these don't follow the previous convention, I don't know */
-#define FSACTL_LNX_NULL_IO_TEST 0x43
-#define FSACTL_LNX_SIM_IO_TEST 0x53
-#define FSACTL_LNX_DOWNLOAD 0x83
-#define FSACTL_LNX_GET_VAR 0x93
-#define FSACTL_LNX_SET_VAR 0xa3
-#define FSACTL_LNX_GET_FIBTIMES 0xb3
-#define FSACTL_LNX_ZERO_FIBTIMES 0xc3
-#define FSACTL_LNX_DELETE_DISK 0x163
-#define FSACTL_LNX_QUERY_DISK 0x173
-
-/* Ok, here it gets really lame */
-#define FSACTL_LNX_PROBE_CONTAINERS 2131 /* Just guessing */
-
-/* Do the native version of the ioctls. Since the BSD encoding scheme
- * conflicts with the 'standard' AAC encoding scheme, the resulting numbers
- * will be different. The '8' comes from the fact that the previous scheme
- * used 12 bits for the number, with the the 12th bit being the only set
- * bit above bit 8. Thus the value of 8, with the lower 8 bits holding the
- * command number. 9 is used for the odd overflow case.
- */
-#define FSACTL_SENDFIB _IO('8', 2)
-#define FSACTL_GET_COMM_PERF_DATA _IO('8', 36)
-#define FSACTL_OPENCLS_COMM_PERF_DATA _IO('8', 37)
-#define FSACTL_OPEN_GET_ADAPTER_FIB _IO('8', 52)
-#define FSACTL_GET_NEXT_ADAPTER_FIB _IO('8', 53)
-#define FSACTL_CLOSE_GET_ADAPTER_FIB _IO('8', 54)
-#define FSACTL_CLOSE_ADAPTER_CONFIG _IO('8', 56)
-#define FSACTL_OPEN_ADAPTER_CONFIG _IO('8', 57)
-#define FSACTL_MINIPORT_REV_CHECK _IO('8', 59)
-#define FSACTL_QUERY_ADAPTER_CONFIG _IO('8', 65)
-#define FSACTL_GET_PCI_INFO _IO('8', 71)
-#define FSACTL_FORCE_DELETE_DISK _IO('8', 72)
-#define FSACTL_AIF_THREAD _IO('8', 79)
-
-#define FSACTL_NULL_IO_TEST _IO('8', 67)
-#define FSACTL_SIM_IO_TEST _IO('8', 83)
-#define FSACTL_DOWNLOAD _IO('8', 131)
-#define FSACTL_GET_VAR _IO('8', 147)
-#define FSACTL_SET_VAR _IO('8', 163)
-#define FSACTL_GET_FIBTIMES _IO('8', 179)
-#define FSACTL_ZERO_FIBTIMES _IO('8', 195)
-#define FSACTL_DELETE_DISK _IO('8', 99)
-#define FSACTL_QUERY_DISK _IO('9', 115)
-
-#define FSACTL_PROBE_CONTAINERS _IO('9', 83) /* Just guessing */
-
-
-/*
- * Support for faking the "miniport" version.
- */
-struct aac_rev_check {
- RevComponent callingComponent;
- struct FsaRevision callingRevision;
-};
-
-struct aac_rev_check_resp {
- int possiblyCompatible;
- struct FsaRevision adapterSWRevision;
-};
-
-/*
- * Context passed in by a consumer looking to collect an AIF.
- */
-struct get_adapter_fib_ioctl {
- u_int32_t AdapterFibContext;
- int Wait;
- caddr_t AifFib;
-};
-
-struct aac_query_disk {
- int32_t ContainerNumber;
- int32_t Bus;
- int32_t Target;
- int32_t Lun;
- u_int32_t Valid;
- u_int32_t Locked;
- u_int32_t Deleted;
- int32_t Instance;
- char diskDeviceName[10];
- u_int32_t UnMapped;
-};
diff --git a/sys/sys/bitstring.h b/sys/sys/bitstring.h
deleted file mode 100644
index eafdba18b098..000000000000
--- a/sys/sys/bitstring.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Paul Vixie.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _BITSTRING_H_
-#define _BITSTRING_H_
-
-typedef unsigned char bitstr_t;
-
-/* internal macros */
- /* byte of the bitstring bit is in */
-#define _bit_byte(bit) \
- ((bit) >> 3)
-
- /* mask for the bit within its byte */
-#define _bit_mask(bit) \
- (1 << ((bit)&0x7))
-
-/* external macros */
- /* bytes in a bitstring of nbits bits */
-#define bitstr_size(nbits) \
- (((nbits) + 7) >> 3)
-
- /* allocate a bitstring */
-#define bit_alloc(nbits) \
- (bitstr_t *)calloc((size_t)bitstr_size(nbits), sizeof(bitstr_t))
-
- /* allocate a bitstring on the stack */
-#define bit_decl(name, nbits) \
- ((name)[bitstr_size(nbits)])
-
- /* is bit N of bitstring name set? */
-#define bit_test(name, bit) \
- ((name)[_bit_byte(bit)] & _bit_mask(bit))
-
- /* set bit N of bitstring name */
-#define bit_set(name, bit) \
- ((name)[_bit_byte(bit)] |= _bit_mask(bit))
-
- /* clear bit N of bitstring name */
-#define bit_clear(name, bit) \
- ((name)[_bit_byte(bit)] &= ~_bit_mask(bit))
-
- /* clear bits start ... stop in bitstring */
-#define bit_nclear(name, start, stop) do { \
- register bitstr_t *_name = (name); \
- register int _start = (start), _stop = (stop); \
- register int _startbyte = _bit_byte(_start); \
- register int _stopbyte = _bit_byte(_stop); \
- if (_startbyte == _stopbyte) { \
- _name[_startbyte] &= ((0xff >> (8 - (_start&0x7))) | \
- (0xff << ((_stop&0x7) + 1))); \
- } else { \
- _name[_startbyte] &= 0xff >> (8 - (_start&0x7)); \
- while (++_startbyte < _stopbyte) \
- _name[_startbyte] = 0; \
- _name[_stopbyte] &= 0xff << ((_stop&0x7) + 1); \
- } \
-} while (0)
-
- /* set bits start ... stop in bitstring */
-#define bit_nset(name, start, stop) do { \
- register bitstr_t *_name = (name); \
- register int _start = (start), _stop = (stop); \
- register int _startbyte = _bit_byte(_start); \
- register int _stopbyte = _bit_byte(_stop); \
- if (_startbyte == _stopbyte) { \
- _name[_startbyte] |= ((0xff << (_start&0x7)) & \
- (0xff >> (7 - (_stop&0x7)))); \
- } else { \
- _name[_startbyte] |= 0xff << ((_start)&0x7); \
- while (++_startbyte < _stopbyte) \
- _name[_startbyte] = 0xff; \
- _name[_stopbyte] |= 0xff >> (7 - (_stop&0x7)); \
- } \
-} while (0)
-
- /* find first bit clear in name */
-#define bit_ffc(name, nbits, value) do { \
- register bitstr_t *_name = (name); \
- register int _byte, _nbits = (nbits); \
- register int _stopbyte = _bit_byte(_nbits - 1), _value = -1; \
- if (_nbits > 0) \
- for (_byte = 0; _byte <= _stopbyte; ++_byte) \
- if (_name[_byte] != 0xff) { \
- bitstr_t _lb; \
- _value = _byte << 3; \
- for (_lb = _name[_byte]; (_lb&0x1); \
- ++_value, _lb >>= 1); \
- break; \
- } \
- if (_value >= nbits) \
- _value = -1; \
- *(value) = _value; \
-} while (0)
-
- /* find first bit set in name */
-#define bit_ffs(name, nbits, value) do { \
- register bitstr_t *_name = (name); \
- register int _byte, _nbits = (nbits); \
- register int _stopbyte = _bit_byte(_nbits - 1), _value = -1; \
- if (_nbits > 0) \
- for (_byte = 0; _byte <= _stopbyte; ++_byte) \
- if (_name[_byte]) { \
- bitstr_t _lb; \
- _value = _byte << 3; \
- for (_lb = _name[_byte]; !(_lb&0x1); \
- ++_value, _lb >>= 1); \
- break; \
- } \
- if (_value >= nbits) \
- _value = -1; \
- *(value) = _value; \
-} while (0)
-
-#endif /* !_BITSTRING_H_ */
diff --git a/sys/sys/bus_dma.h b/sys/sys/bus_dma.h
deleted file mode 100644
index 8a54fe3fce53..000000000000
--- a/sys/sys/bus_dma.h
+++ /dev/null
@@ -1,241 +0,0 @@
-/* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */
-
-/*-
- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
- * NASA Ames Research Center.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
- * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Christopher G. Demetriou
- * for the NetBSD Project.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/* $FreeBSD$ */
-
-#ifndef _I386_BUS_DMA_H_
-#define _I386_BUS_DMA_H_
-
-/*
- * Flags used in various bus DMA methods.
- */
-#define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */
-#define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */
-#define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */
-#define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */
-#define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */
-#define BUS_DMA_BUS2 0x20
-#define BUS_DMA_BUS3 0x40
-#define BUS_DMA_BUS4 0x80
-
-/* Forwards needed by prototypes below. */
-struct mbuf;
-struct uio;
-
-/*
- * Operations performed by bus_dmamap_sync().
- */
-typedef int bus_dmasync_op_t;
-#define BUS_DMASYNC_PREREAD 1
-#define BUS_DMASYNC_POSTREAD 2
-#define BUS_DMASYNC_PREWRITE 4
-#define BUS_DMASYNC_POSTWRITE 8
-
-/*
- * bus_dma_tag_t
- *
- * A machine-dependent opaque type describing the characteristics
- * of how to perform DMA mappings. This structure encapsultes
- * information concerning address and alignment restrictions, number
- * of S/G segments, amount of data per S/G segment, etc.
- */
-typedef struct bus_dma_tag *bus_dma_tag_t;
-
-/*
- * bus_dmamap_t
- *
- * DMA mapping instance information.
- */
-typedef struct bus_dmamap *bus_dmamap_t;
-
-/*
- * bus_dma_segment_t
- *
- * Describes a single contiguous DMA transaction. Values
- * are suitable for programming into DMA registers.
- */
-typedef struct bus_dma_segment {
- bus_addr_t ds_addr; /* DMA address */
- bus_size_t ds_len; /* length of transfer */
-} bus_dma_segment_t;
-
-/*
- * A function that returns 1 if the address cannot be accessed by
- * a device and 0 if it can be.
- */
-typedef int bus_dma_filter_t(void *, bus_addr_t);
-
-/*
- * Allocate a device specific dma_tag encapsulating the constraints of
- * the parent tag in addition to other restrictions specified:
- *
- * alignment: alignment for segments.
- * boundary: Boundary that segments cannot cross.
- * lowaddr: Low restricted address that cannot appear in a mapping.
- * highaddr: High restricted address that cannot appear in a mapping.
- * filtfunc: An optional function to further test if an address
- * within the range of lowaddr and highaddr cannot appear
- * in a mapping.
- * filtfuncarg: An argument that will be passed to filtfunc in addition
- * to the address to test.
- * maxsize: Maximum mapping size supported by this tag.
- * nsegments: Number of discontinuities allowed in maps.
- * maxsegsz: Maximum size of a segment in the map.
- * flags: Bus DMA flags.
- * dmat: A pointer to set to a valid dma tag should the return
- * value of this function indicate success.
- */
-/* XXX Should probably allow specification of alignment */
-int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
- bus_size_t boundary, bus_addr_t lowaddr,
- bus_addr_t highaddr, bus_dma_filter_t *filtfunc,
- void *filtfuncarg, bus_size_t maxsize, int nsegments,
- bus_size_t maxsegsz, int flags, bus_dma_tag_t *dmat);
-
-int bus_dma_tag_destroy(bus_dma_tag_t dmat);
-
-/*
- * Allocate a handle for mapping from kva/uva/physical
- * address space into bus device space.
- */
-int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp);
-
-/*
- * Destroy a handle for mapping from kva/uva/physical
- * address space into bus device space.
- */
-int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map);
-
-/*
- * Allocate a piece of memory that can be efficiently mapped into
- * bus device space based on the constraints lited in the dma tag.
- * A dmamap to for use with dmamap_load is also allocated.
- */
-int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
- bus_dmamap_t *mapp);
-
-/*
- * Free a piece of memory and it's allociated dmamap, that was allocated
- * via bus_dmamem_alloc.
- */
-void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);
-
-/*
- * A function that processes a successfully loaded dma map or an error
- * from a delayed load map.
- */
-typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
-
-/*
- * Map the buffer buf into bus space using the dmamap map.
- */
-int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
- bus_size_t buflen, bus_dmamap_callback_t *callback,
- void *callback_arg, int flags);
-
-/*
- * Like bus_dmamap_callback but includes map size in bytes. This is
- * defined as a separate interface to maintain compatiiblity for users
- * of bus_dmamap_callback_t--at some point these interfaces should be merged.
- */
-typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int);
-/*
- * Like bus_dmamap_load but for mbufs. Note the use of the
- * bus_dmamap_callback2_t interface.
- */
-int bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map,
- struct mbuf *mbuf,
- bus_dmamap_callback2_t *callback, void *callback_arg,
- int flags);
-/*
- * Like bus_dmamap_load but for uios. Note the use of the
- * bus_dmamap_callback2_t interface.
- */
-int bus_dmamap_load_uio(bus_dma_tag_t dmat, bus_dmamap_t map,
- struct uio *ui,
- bus_dmamap_callback2_t *callback, void *callback_arg,
- int flags);
-
-/*
- * Perform a syncronization operation on the given map.
- */
-void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t);
-#define bus_dmamap_sync(dmat, dmamap, op) \
- if ((dmamap) != NULL) \
- _bus_dmamap_sync(dmat, dmamap, op)
-
-/*
- * Release the mapping held by map.
- */
-void _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map);
-#define bus_dmamap_unload(dmat, dmamap) \
- if ((dmamap) != NULL) \
- _bus_dmamap_unload(dmat, dmamap)
-
-#endif /* _I386_BUS_DMA_H_ */
diff --git a/sys/sys/ioctl_bt848.h b/sys/sys/ioctl_bt848.h
deleted file mode 100644
index b6646c699b7c..000000000000
--- a/sys/sys/ioctl_bt848.h
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * extensions to ioctl_meteor.h for the bt848 cards
- *
- * $FreeBSD$
- */
-
-#ifndef _MACHINE_IOCTL_BT848_H_
-#define _MACHINE_IOCTL_BT848_H_
-
-/*
- * frequency sets
- */
-#define CHNLSET_NABCST 1
-#define CHNLSET_CABLEIRC 2
-#define CHNLSET_CABLEHRC 3
-#define CHNLSET_WEUROPE 4
-#define CHNLSET_JPNBCST 5
-#define CHNLSET_JPNCABLE 6
-#define CHNLSET_XUSSR 7
-#define CHNLSET_AUSTRALIA 8
-#define CHNLSET_FRANCE 9
-#define CHNLSET_MIN CHNLSET_NABCST
-#define CHNLSET_MAX CHNLSET_FRANCE
-
-
-/*
- * constants for various tuner registers
- */
-#define BT848_HUEMIN (-90)
-#define BT848_HUEMAX 90
-#define BT848_HUECENTER 0
-#define BT848_HUERANGE 179.3
-#define BT848_HUEREGMIN (-128)
-#define BT848_HUEREGMAX 127
-#define BT848_HUESTEPS 256
-
-#define BT848_BRIGHTMIN (-50)
-#define BT848_BRIGHTMAX 50
-#define BT848_BRIGHTCENTER 0
-#define BT848_BRIGHTRANGE 99.6
-#define BT848_BRIGHTREGMIN (-128)
-#define BT848_BRIGHTREGMAX 127
-#define BT848_BRIGHTSTEPS 256
-
-#define BT848_CONTRASTMIN 0
-#define BT848_CONTRASTMAX 237
-#define BT848_CONTRASTCENTER 100
-#define BT848_CONTRASTRANGE 236.57
-#define BT848_CONTRASTREGMIN 0
-#define BT848_CONTRASTREGMAX 511
-#define BT848_CONTRASTSTEPS 512
-
-#define BT848_CHROMAMIN 0
-#define BT848_CHROMAMAX 284
-#define BT848_CHROMACENTER 100
-#define BT848_CHROMARANGE 283.89
-#define BT848_CHROMAREGMIN 0
-#define BT848_CHROMAREGMAX 511
-#define BT848_CHROMASTEPS 512
-
-#define BT848_SATUMIN 0
-#define BT848_SATUMAX 202
-#define BT848_SATUCENTER 100
-#define BT848_SATURANGE 201.18
-#define BT848_SATUREGMIN 0
-#define BT848_SATUREGMAX 511
-#define BT848_SATUSTEPS 512
-
-#define BT848_SATVMIN 0
-#define BT848_SATVMAX 284
-#define BT848_SATVCENTER 100
-#define BT848_SATVRANGE 283.89
-#define BT848_SATVREGMIN 0
-#define BT848_SATVREGMAX 511
-#define BT848_SATVSTEPS 512
-
-
-/*
- * audio stuff
- */
-#define AUDIO_TUNER 0x00 /* command for the audio routine */
-#define AUDIO_EXTERN 0x01 /* don't confuse them with bit */
-#define AUDIO_INTERN 0x02 /* settings */
-#define AUDIO_MUTE 0x80
-#define AUDIO_UNMUTE 0x81
-
-
-/*
- * EEProm stuff
- */
-struct eeProm {
- short offset;
- short count;
- u_char bytes[ 256 ];
-};
-
-
-/*
- * XXX: this is a hack, should be in ioctl_meteor.h
- * here to avoid touching that file for now...
- */
-#define TVTUNER_SETCHNL _IOW('x', 32, unsigned int) /* set channel */
-#define TVTUNER_GETCHNL _IOR('x', 32, unsigned int) /* get channel */
-#define TVTUNER_SETTYPE _IOW('x', 33, unsigned int) /* set tuner type */
-#define TVTUNER_GETTYPE _IOR('x', 33, unsigned int) /* get tuner type */
-#define TVTUNER_GETSTATUS _IOR('x', 34, unsigned int) /* get tuner status */
-#define TVTUNER_SETFREQ _IOW('x', 35, unsigned int) /* set frequency */
-#define TVTUNER_GETFREQ _IOR('x', 36, unsigned int) /* get frequency */
-
-
-#define BT848_SHUE _IOW('x', 37, int) /* set hue */
-#define BT848_GHUE _IOR('x', 37, int) /* get hue */
-#define BT848_SBRIG _IOW('x', 38, int) /* set brightness */
-#define BT848_GBRIG _IOR('x', 38, int) /* get brightness */
-#define BT848_SCSAT _IOW('x', 39, int) /* set chroma sat */
-#define BT848_GCSAT _IOR('x', 39, int) /* get UV saturation */
-#define BT848_SCONT _IOW('x', 40, int) /* set contrast */
-#define BT848_GCONT _IOR('x', 40, int) /* get contrast */
-#define BT848_SVSAT _IOW('x', 41, int) /* set chroma V sat */
-#define BT848_GVSAT _IOR('x', 41, int) /* get V saturation */
-#define BT848_SUSAT _IOW('x', 42, int) /* set chroma U sat */
-#define BT848_GUSAT _IOR('x', 42, int) /* get U saturation */
-
-#define BT848_SCBARS _IOR('x', 43, int) /* set colorbar */
-#define BT848_CCBARS _IOR('x', 44, int) /* clear colorbar */
-
-
-#define BT848_SAUDIO _IOW('x', 46, int) /* set audio channel */
-#define BT848_GAUDIO _IOR('x', 47, int) /* get audio channel */
-#define BT848_SBTSC _IOW('x', 48, int) /* set audio channel */
-
-#define BT848_GSTATUS _IOR('x', 49, unsigned int) /* reap status */
-
-#define BT848_WEEPROM _IOWR('x', 50, struct eeProm) /* write to EEProm */
-#define BT848_REEPROM _IOWR('x', 51, struct eeProm) /* read from EEProm */
-
-#define BT848_SIGNATURE _IOWR('x', 52, struct eeProm) /* read card sig */
-
-#define TVTUNER_SETAFC _IOW('x', 53, int) /* turn AFC on/off */
-#define TVTUNER_GETAFC _IOR('x', 54, int) /* query AFC on/off */
-#define BT848_SLNOTCH _IOW('x', 55, int) /* set luma notch */
-#define BT848_GLNOTCH _IOR('x', 56, int) /* get luma notch */
-
-/* Read/Write the BT848's I2C bus directly
- * b7-b0: data (read/write)
- * b15-b8: internal peripheral register (write)
- * b23-b16: i2c addr (write)
- * b31-b24: 1 = write, 0 = read
- */
-#define BT848_I2CWR _IOWR('x', 57, u_long) /* i2c read-write */
-
-struct bktr_msp_control {
- unsigned char function;
- unsigned int address;
- unsigned int data;
-};
-
-#define BT848_MSP_RESET _IO('x', 76) /* MSP chip reset */
-#define BT848_MSP_READ _IOWR('x', 77, struct bktr_msp_control) /* MSP chip read */
-#define BT848_MSP_WRITE _IOWR('x', 78, struct bktr_msp_control) /* MSP chip write */
-
-/* Support for radio tuner */
-#define RADIO_SETMODE _IOW('x', 58, unsigned int) /* set radio modes */
-#define RADIO_GETMODE _IOR('x', 58, unsigned char) /* get radio modes */
-#define RADIO_AFC 0x01 /* These modes will probably not */
-#define RADIO_MONO 0x02 /* work on the FRxxxx. It does */
-#define RADIO_MUTE 0x08 /* work on the FMxxxx. */
-#define RADIO_SETFREQ _IOW('x', 59, unsigned int) /* set frequency */
-#define RADIO_GETFREQ _IOR('x', 59, unsigned int) /* set frequency */
- /* Argument is frequency*100MHz */
-
-/*
- * XXX: more bad magic,
- * we need to fix the METEORGINPUT to return something public
- * duplicate them here for now...
- */
-#define METEOR_DEV0 0x00001000
-#define METEOR_DEV1 0x00002000
-#define METEOR_DEV2 0x00004000
-#define METEOR_DEV3 0x00008000
-#define METEOR_DEV_SVIDEO 0x00006000
-/*
- * right now I don't know were to put these, but as they are suppose to be
- * a part of a common video capture interface, these should be relocated to
- * another place. Probably most of the METEOR_xxx defines need to be
- * renamed and moved to a common header
- */
-
-typedef enum { METEOR_PIXTYPE_RGB, METEOR_PIXTYPE_YUV,
- METEOR_PIXTYPE_YUV_PACKED,
- METEOR_PIXTYPE_YUV_12 } METEOR_PIXTYPE;
-
-
-struct meteor_pixfmt {
- u_int index; /* Index in supported pixfmt list */
- METEOR_PIXTYPE type; /* What's the board gonna feed us */
- u_int Bpp; /* Bytes per pixel */
- u_long masks[3]; /* R,G,B or Y,U,V masks, respectively */
- unsigned swap_bytes :1; /* Bytes swapped within shorts */
- unsigned swap_shorts:1; /* Shorts swapped within longs */
-};
-
-
-struct bktr_clip {
- int x_min;
- int x_max;
- int y_min;
- int y_max;
-};
-
-#define BT848_MAX_CLIP_NODE 100
-struct _bktr_clip {
- struct bktr_clip x[BT848_MAX_CLIP_NODE];
-};
-
-/*
- * I'm using METEOR_xxx just because that will be common to other interface
- * and less of a surprise
- */
-#define METEORSACTPIXFMT _IOW('x', 64, int )
-#define METEORGACTPIXFMT _IOR('x', 64, int )
-#define METEORGSUPPIXFMT _IOWR('x', 65, struct meteor_pixfmt)
-
-/* set clip list */
-#define BT848SCLIP _IOW('x', 66, struct _bktr_clip )
-#define BT848GCLIP _IOR('x', 66, struct _bktr_clip )
-
-
-/* set input format */
-#define BT848SFMT _IOW('x', 67, unsigned long )
-#define BT848GFMT _IOR('x', 67, unsigned long )
-
-/* set clear-buffer-on-start */
-#define BT848SCBUF _IOW('x', 68, int)
-#define BT848GCBUF _IOR('x', 68, int)
-
-/* set capture area */
-/* The capture area is the area of the video image which is grabbed */
-/* Usually the capture area is 640x480 (768x576 PAL) pixels */
-/* This area is then scaled to the dimensions the user requires */
-/* using the METEORGEO ioctl */
-/* However, the capture area could be 400x300 pixels from the top right */
-/* corner of the video image */
-struct bktr_capture_area {
- int x_offset;
- int y_offset;
- int x_size;
- int y_size;
-};
-#define BT848_SCAPAREA _IOW('x', 69, struct bktr_capture_area)
-#define BT848_GCAPAREA _IOR('x', 69, struct bktr_capture_area)
-
-
-/* Get channel Set */
-#define BT848_MAX_CHNLSET_NAME_LEN 16
-struct bktr_chnlset {
- short index;
- short max_channel;
- char name[BT848_MAX_CHNLSET_NAME_LEN];
-};
-#define TVTUNER_GETCHNLSET _IOWR('x', 70, struct bktr_chnlset)
-
-
-
-/* Infra Red Remote Control */
-struct bktr_remote {
- unsigned char data[3];
-};
-#define REMOTE_GETKEY _IOR('x', 71, struct bktr_remote)/*read the remote */
- /*control receiver*/
- /*returns raw data*/
-
-
-/*
- * Direct access to GPIO pins. You must add BKTR_GPIO_ACCESS to your kernel
- * configuration file to use these
- */
-#define BT848_GPIO_SET_EN _IOW('x', 72, int) /* set gpio_out_en */
-#define BT848_GPIO_GET_EN _IOR('x', 73, int) /* get gpio_out_en */
-#define BT848_GPIO_SET_DATA _IOW('x', 74, int) /* set gpio_data */
-#define BT848_GPIO_GET_DATA _IOR('x', 75, int) /* get gpio_data */
-
-
-
-/* XXX - Copied from /sys/pci/brktree_reg.h */
-#define BT848_IFORM_FORMAT (0x7<<0)
-# define BT848_IFORM_F_RSVD (0x7)
-# define BT848_IFORM_F_SECAM (0x6)
-# define BT848_IFORM_F_PALN (0x5)
-# define BT848_IFORM_F_PALM (0x4)
-# define BT848_IFORM_F_PALBDGHI (0x3)
-# define BT848_IFORM_F_NTSCJ (0x2)
-# define BT848_IFORM_F_NTSCM (0x1)
-# define BT848_IFORM_F_AUTO (0x0)
-
-
-#endif /* _MACHINE_IOCTL_BT848_H_ */
-
diff --git a/sys/sys/ioctl_meteor.h b/sys/sys/ioctl_meteor.h
deleted file mode 100644
index f62d392ea0ae..000000000000
--- a/sys/sys/ioctl_meteor.h
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright (c) 1995 Mark Tinguely and Jim Lowe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Mark Tinguely and Jim Lowe
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-/*
- * ioctl constants for Matrox Meteor Capture card.
- */
-
-#ifndef _MACHINE_IOCTL_METEOR_H_
-#define _MACHINE_IOCTL_METEOR_H_
-
-#ifndef _KERNEL
-#include <sys/types.h>
-#endif
-#include <sys/ioccom.h>
-
-struct meteor_capframe {
- short command; /* see below for valid METEORCAPFRM commands */
- short lowat; /* start transfer if < this number */
- short hiwat; /* stop transfer if > this number */
-} ;
-
-/* structure for METEOR[GS]ETGEO - get/set geometry */
-struct meteor_geomet {
- u_short rows;
- u_short columns;
- u_short frames;
- u_long oformat;
-} ;
-
-/* structure for METEORGCOUNT-get count of frames, fifo errors and dma errors */
-struct meteor_counts {
- u_long fifo_errors; /* count of fifo errors since open */
- u_long dma_errors; /* count of dma errors since open */
- u_long frames_captured; /* count of frames captured since open */
- u_long even_fields_captured; /* count of even fields captured */
- u_long odd_fields_captured; /* count of odd fields captured */
-} ;
-
-/* structure for getting and setting direct transfers to vram */
-struct meteor_video {
- u_long addr; /* Address of location to dma to */
- u_long width; /* Width of memory area */
- u_long banksize; /* Size of Vram bank */
- u_long ramsize; /* Size of Vram */
-};
-
-#define METEORCAPTUR _IOW('x', 1, int) /* capture a frame */
-#define METEORCAPFRM _IOW('x', 2, struct meteor_capframe) /* sync capture */
-#define METEORSETGEO _IOW('x', 3, struct meteor_geomet) /* set geometry */
-#define METEORGETGEO _IOR('x', 4, struct meteor_geomet) /* get geometry */
-#define METEORSTATUS _IOR('x', 5, unsigned short) /* get status */
-#define METEORSHUE _IOW('x', 6, signed char) /* set hue */
-#define METEORGHUE _IOR('x', 6, signed char) /* get hue */
-#define METEORSFMT _IOW('x', 7, unsigned long) /* set format */
-#define METEORGFMT _IOR('x', 7, unsigned long) /* get format */
-#define METEORSINPUT _IOW('x', 8, unsigned long) /* set input dev */
-#define METEORGINPUT _IOR('x', 8, unsigned long) /* get input dev */
-#define METEORSCHCV _IOW('x', 9, unsigned char) /* set uv gain */
-#define METEORGCHCV _IOR('x', 9, unsigned char) /* get uv gain */
-#define METEORSCOUNT _IOW('x',10, struct meteor_counts)
-#define METEORGCOUNT _IOR('x',10, struct meteor_counts)
-#define METEORSFPS _IOW('x',11, unsigned short) /* set fps */
-#define METEORGFPS _IOR('x',11, unsigned short) /* get fps */
-#define METEORSSIGNAL _IOW('x', 12, unsigned int) /* set signal */
-#define METEORGSIGNAL _IOR('x', 12, unsigned int) /* get signal */
-#define METEORSVIDEO _IOW('x', 13, struct meteor_video) /* set video */
-#define METEORGVIDEO _IOR('x', 13, struct meteor_video) /* get video */
-#define METEORSBRIG _IOW('x', 14, unsigned char) /* set brightness */
-#define METEORGBRIG _IOR('x', 14, unsigned char) /* get brightness */
-#define METEORSCSAT _IOW('x', 15, unsigned char) /* set chroma sat */
-#define METEORGCSAT _IOR('x', 15, unsigned char) /* get uv saturation */
-#define METEORSCONT _IOW('x', 16, unsigned char) /* set contrast */
-#define METEORGCONT _IOR('x', 16, unsigned char) /* get contrast */
-#define METEORSBT254 _IOW('x', 17, unsigned short) /* set Bt254 reg */
-#define METEORGBT254 _IOR('x', 17, unsigned short) /* get Bt254 reg */
-#define METEORSHWS _IOW('x', 18, unsigned char) /* set hor start reg */
-#define METEORGHWS _IOR('x', 18, unsigned char) /* get hor start reg */
-#define METEORSVWS _IOW('x', 19, unsigned char) /* set vert start reg */
-#define METEORGVWS _IOR('x', 19, unsigned char) /* get vert start reg */
-#define METEORSTS _IOW('x', 20, unsigned char) /* set time stamp */
-#define METEORGTS _IOR('x', 20, unsigned char) /* get time stamp */
-
-#define METEOR_STATUS_ID_MASK 0xf000 /* ID of 7196 */
-#define METEOR_STATUS_DIR 0x0800 /* Direction of Expansion port YUV */
-#define METEOR_STATUS_OEF 0x0200 /* Field detected: Even/Odd */
-#define METEOR_STATUS_SVP 0x0100 /* State of VRAM Port:inactive/active */
-#define METEOR_STATUS_STTC 0x0080 /* Time Constant: TV/VCR */
-#define METEOR_STATUS_HCLK 0x0040 /* Horiz PLL: locked/unlocked */
-#define METEOR_STATUS_FIDT 0x0020 /* Field detect: 50/60hz */
-#define METEOR_STATUS_ALTD 0x0002 /* Line alt: no line alt/line alt */
-#define METEOR_STATUS_CODE 0x0001 /* Colour info: no colour/colour */
-
- /* METEORCAPTUR capture options */
-#define METEOR_CAP_SINGLE 0x0001 /* capture one frame */
-#define METEOR_CAP_CONTINOUS 0x0002 /* continuously capture */
-#define METEOR_CAP_STOP_CONT 0x0004 /* stop the continuous capture */
-
- /* METEORCAPFRM capture commands */
-#define METEOR_CAP_N_FRAMES 0x0001 /* capture N frames */
-#define METEOR_CAP_STOP_FRAMES 0x0002 /* stop capture N frames */
-#define METEOR_HALT_N_FRAMES 0x0003 /* halt of capture N frames */
-#define METEOR_CONT_N_FRAMES 0x0004 /* continue after above halt */
-
- /* valid video input formats: */
-#define METEOR_FMT_NTSC 0x00100 /* NTSC -- initialized default */
-#define METEOR_FMT_PAL 0x00200 /* PAL */
-#define METEOR_FMT_SECAM 0x00400 /* SECAM */
-#define METEOR_FMT_AUTOMODE 0x00800 /* auto-mode */
-#define METEOR_INPUT_DEV0 0x01000 /* camera input 0 -- default */
-#define METEOR_INPUT_DEV_RCA METEOR_INPUT_DEV0
-#define METEOR_INPUT_DEV1 0x02000 /* camera input 1 */
-#define METEOR_INPUT_DEV2 0x04000 /* camera input 2 */
-#define METEOR_INPUT_DEV3 0x08000 /* camera input 3 */
-#define METEOR_INPUT_DEV_RGB 0x0a000 /* for rgb version of meteor */
-#define METEOR_INPUT_DEV_SVIDEO 0x06000 /* S-video input port */
-
- /* valid video output formats: */
-#define METEOR_GEO_RGB16 0x0010000 /* packed -- initialized default */
-#define METEOR_GEO_RGB24 0x0020000 /* RBG 24 bits packed */
- /* internally stored in 32 bits */
-#define METEOR_GEO_YUV_PACKED 0x0040000 /* 4-2-2 YUV 16 bits packed */
-#define METEOR_GEO_YUV_PLANAR 0x0080000 /* 4-2-2 YUV 16 bits planer */
-#define METEOR_GEO_YUV_PLANER METEOR_GEO_YUV_PLANAR
-#define METEOR_GEO_UNSIGNED 0x0400000 /* unsigned uv outputs */
-#define METEOR_GEO_EVEN_ONLY 0x1000000 /* set for even only field capture */
-#define METEOR_GEO_ODD_ONLY 0x2000000 /* set for odd only field capture */
-#define METEOR_GEO_FIELD_MASK 0x3000000
-#define METEOR_GEO_YUV_422 0x4000000 /* 4-2-2 YUV in Y-U-V combined */
-#define METEOR_GEO_OUTPUT_MASK 0x40f0000
-#define METEOR_GEO_YUV_12 0x10000000 /* YUV 12 format */
-#define METEOR_GEO_YUV_9 0x40000000 /* YUV 9 format */
-
-#define METEOR_FIELD_MODE 0x80000000 /* Field cap or Frame cap */
-
-#define METEOR_SIG_MODE_MASK 0xffff0000
-#define METEOR_SIG_FRAME 0x00000000 /* signal every frame */
-#define METEOR_SIG_FIELD 0x00010000 /* signal every field */
-
- /* following structure is used to coordinate the synchronous */
-
-struct meteor_mem {
- /* kernel write only */
- int frame_size; /* row*columns*depth */
- unsigned num_bufs; /* number of frames in buffer (1-32) */
- /* user and kernel change these */
- int lowat; /* kernel starts capture if < this number */
- int hiwat; /* kernel stops capture if > this number.
- hiwat <= numbufs */
- unsigned active; /* bit mask of active frame buffers
- kernel sets, user clears */
- int num_active_bufs; /* count of active frame buffer
- kernel increments, user decrements */
-
- /* reference to mmapped data */
- caddr_t buf; /* The real space (virtual addr) */
-} ;
-
-#endif /* !_MACHINE_IOCTL_METEOR_H_ */
diff --git a/sys/sys/linedisc.h b/sys/sys/linedisc.h
deleted file mode 100644
index effec044030c..000000000000
--- a/sys/sys/linedisc.h
+++ /dev/null
@@ -1,358 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- * Copyright (c) 2000
- * Poul-Henning Kamp. All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)conf.h 8.5 (Berkeley) 1/9/95
- * $FreeBSD$
- */
-
-#ifndef _SYS_CONF_H_
-#define _SYS_CONF_H_
-
-#ifdef _KERNEL
-#include <sys/eventhandler.h>
-
-struct tty;
-struct disk;
-struct vnode;
-struct buf;
-TAILQ_HEAD(snaphead, inode);
-
-struct cdev {
- u_int si_flags;
-#define SI_STASHED 0x0001 /* created in stashed storage */
-#define SI_ALIAS 0x0002 /* carrier of alias name */
-#define SI_NAMED 0x0004 /* make_dev{_alias} has been called */
-#define SI_CHEAPCLONE 0x0008 /* can be removed_dev'ed when vnode reclaims */
-#define SI_CHILD 0x0010 /* child of another dev_t */
-#define SI_DEVOPEN 0x0020 /* opened by device */
-#define SI_CONSOPEN 0x0040 /* opened by console */
-#define SI_DUMPDEV 0x0080 /* is kernel dumpdev */
-#define SI_CANDELETE 0x0100 /* can do BIO_DELETE */
- struct timespec si_atime;
- struct timespec si_ctime;
- struct timespec si_mtime;
- udev_t si_udev;
- LIST_ENTRY(cdev) si_hash;
- SLIST_HEAD(, vnode) si_hlist;
- LIST_HEAD(, cdev) si_children;
- LIST_ENTRY(cdev) si_siblings;
- dev_t si_parent;
- u_int si_inode;
- char *si_name;
- void *si_drv1, *si_drv2;
- struct cdevsw *si_devsw;
- int si_iosize_max; /* maximum I/O size (for physio &al) */
- u_int si_stripesize;
- u_int si_stripeoffset;
- uid_t si_uid;
- gid_t si_gid;
- mode_t si_mode;
- u_long si_usecount;
- union {
- struct {
- struct tty *__sit_tty;
- } __si_tty;
- struct {
- struct mount *__sid_mountpoint;
- int __sid_bsize_phys; /* min physical block size */
- int __sid_bsize_best; /* optimal block size */
- struct snaphead __sid_snapshots;
- daddr_t __sid_snaplistsize; /* size of snapblklist. */
- daddr_t *__sid_snapblklist; /* known snapshot blocks. */
- int (*__sid_copyonwrite)(struct vnode *, struct buf *);
- } __si_disk;
- } __si_u;
- char __si_namebuf[SPECNAMELEN + 1];
-};
-
-#define si_tty __si_u.__si_tty.__sit_tty
-#define si_mountpoint __si_u.__si_disk.__sid_mountpoint
-#define si_bsize_phys __si_u.__si_disk.__sid_bsize_phys
-#define si_bsize_best __si_u.__si_disk.__sid_bsize_best
-#define si_snapshots __si_u.__si_disk.__sid_snapshots
-#define si_snaplistsize __si_u.__si_disk.__sid_snaplistsize
-#define si_snapblklist __si_u.__si_disk.__sid_snapblklist
-#define si_copyonwrite __si_u.__si_disk.__sid_copyonwrite
-
-/*
- * Special device management
- */
-#define SPECHSZ 64
-#define SPECHASH(rdev) (((unsigned)(minor(rdev)))%SPECHSZ)
-
-/*
- * Definitions of device driver entry switches
- */
-
-struct bio;
-struct buf;
-struct thread;
-struct uio;
-struct knote;
-
-/*
- * Note: d_thread_t is provided as a transition aid for those drivers
- * that treat struct proc/struct thread as an opaque data type and
- * exist in substantially the same form in both 4.x and 5.x. Writers
- * of drivers that dips into the d_thread_t structure should use
- * struct thread or struct proc as appropriate for the version of the
- * OS they are using. It is provided in lieu of each device driver
- * inventing its own way of doing this. While it does violate style(9)
- * in a number of ways, this violation is deemed to be less
- * important than the benefits that a uniform API between releases
- * gives.
- *
- * Users of struct thread/struct proc that aren't device drivers should
- * not use d_thread_t.
- */
-
-typedef struct thread d_thread_t;
-
-typedef int d_open_t(dev_t dev, int oflags, int devtype, struct thread *td);
-typedef int d_close_t(dev_t dev, int fflag, int devtype, struct thread *td);
-typedef void d_strategy_t(struct bio *bp);
-typedef int d_ioctl_t(dev_t dev, u_long cmd, caddr_t data,
- int fflag, struct thread *td);
-
-typedef int d_read_t(dev_t dev, struct uio *uio, int ioflag);
-typedef int d_write_t(dev_t dev, struct uio *uio, int ioflag);
-typedef int d_poll_t(dev_t dev, int events, struct thread *td);
-typedef int d_kqfilter_t(dev_t dev, struct knote *kn);
-typedef int d_mmap_t(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr,
- int nprot);
-
-typedef int l_open_t(dev_t dev, struct tty *tp);
-typedef int l_close_t(struct tty *tp, int flag);
-typedef int l_read_t(struct tty *tp, struct uio *uio, int flag);
-typedef int l_write_t(struct tty *tp, struct uio *uio, int flag);
-typedef int l_ioctl_t(struct tty *tp, u_long cmd, caddr_t data,
- int flag, struct thread *td);
-typedef int l_rint_t(int c, struct tty *tp);
-typedef int l_start_t(struct tty *tp);
-typedef int l_modem_t(struct tty *tp, int flag);
-
-typedef int dumper_t(
- void *priv, /* Private to the driver. */
- void *virtual, /* Virtual (mapped) address. */
- vm_offset_t physical, /* Physical address of virtual. */
- off_t offset, /* Byte-offset to write at. */
- size_t length); /* Number of bytes to dump. */
-
-#define BIO_STRATEGY(bp) \
- do { \
- if ((!(bp)->bio_cmd) || ((bp)->bio_cmd & ((bp)->bio_cmd - 1))) \
- Debugger("bio_cmd botch"); \
- (*devsw((bp)->bio_dev)->d_strategy)(bp); \
- } while (0)
-
-#define DEV_STRATEGY(bp) \
- do { \
- if ((bp)->b_flags & B_PHYS) \
- (bp)->b_io.bio_offset = (bp)->b_offset; \
- else \
- (bp)->b_io.bio_offset = dbtob((bp)->b_blkno); \
- (bp)->b_io.bio_done = bufdonebio; \
- (bp)->b_io.bio_caller2 = (bp); \
- BIO_STRATEGY(&(bp)->b_io); \
- } while (0)
-
-#endif /* _KERNEL */
-
-/*
- * Types for d_flags.
- */
-#define D_TAPE 0x0001
-#define D_DISK 0x0002
-#define D_TTY 0x0004
-#define D_MEM 0x0008
-
-#ifdef _KERNEL
-
-#define D_TYPEMASK 0xffff
-
-/*
- * Flags for d_flags.
- */
-#define D_MEMDISK 0x00010000 /* memory type disk */
-#define D_NAGGED 0x00020000 /* nagged about missing make_dev() */
-#define D_TRACKCLOSE 0x00080000 /* track all closes */
-#define D_MMAP_ANON 0x00100000 /* special treatment in vm_mmap.c */
-#define D_NOGIANT 0x00400000 /* Doesn't want Giant */
-
-/*
- * Character device switch table
- */
-struct cdevsw {
- int d_maj;
- u_int d_flags;
- const char *d_name;
- d_open_t *d_open;
- d_close_t *d_close;
- d_read_t *d_read;
- d_write_t *d_write;
- d_ioctl_t *d_ioctl;
- d_poll_t *d_poll;
- d_mmap_t *d_mmap;
- d_strategy_t *d_strategy;
- dumper_t *d_dump;
- d_kqfilter_t *d_kqfilter;
-};
-
-/*
- * Line discipline switch table
- */
-struct linesw {
- l_open_t *l_open;
- l_close_t *l_close;
- l_read_t *l_read;
- l_write_t *l_write;
- l_ioctl_t *l_ioctl;
- l_rint_t *l_rint;
- l_start_t *l_start;
- l_modem_t *l_modem;
- u_char l_hotchar;
-};
-
-extern struct linesw linesw[];
-extern int nlinesw;
-
-int ldisc_register(int , struct linesw *);
-void ldisc_deregister(int);
-#define LDISC_LOAD -1 /* Loadable line discipline */
-#endif /* _KERNEL */
-
-#ifdef _KERNEL
-d_open_t noopen;
-d_close_t noclose;
-d_read_t noread;
-d_write_t nowrite;
-d_ioctl_t noioctl;
-d_mmap_t nommap;
-d_kqfilter_t nokqfilter;
-#define nostrategy ((d_strategy_t *)NULL)
-#define nopoll seltrue
-
-dumper_t nodump;
-
-#define NUMCDEVSW 256
-
-#define MAJOR_AUTO 0 /* XXX: Not GM */
-
-/*
- * nopsize is little used, so not worth having dummy functions for.
- */
-#define nopsize (NULL)
-
-d_open_t nullopen;
-d_close_t nullclose;
-
-l_ioctl_t l_nullioctl;
-l_read_t l_noread;
-l_write_t l_nowrite;
-
-struct module;
-
-struct devsw_module_data {
- int (*chainevh)(struct module *, int, void *); /* next handler */
- void *chainarg; /* arg for next event handler */
- /* Do not initialize fields hereafter */
-};
-
-#define DEV_MODULE(name, evh, arg) \
-static moduledata_t name##_mod = { \
- #name, \
- evh, \
- arg \
-}; \
-DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
-
-
-int count_dev(dev_t _dev);
-void destroy_dev(dev_t _dev);
-void revoke_and_destroy_dev(dev_t _dev);
-struct cdevsw *devsw(dev_t _dev);
-const char *devtoname(dev_t _dev);
-int dev_named(dev_t _pdev, const char *_name);
-void dev_depends(dev_t _pdev, dev_t _cdev);
-void freedev(dev_t _dev);
-dev_t makebdev(int _maj, int _min);
-dev_t make_dev(struct cdevsw *_devsw, int _minor, uid_t _uid, gid_t _gid,
- int _perms, const char *_fmt, ...) __printflike(6, 7);
-dev_t make_dev_alias(dev_t _pdev, const char *_fmt, ...) __printflike(2, 3);
-int dev2unit(dev_t _dev);
-int unit2minor(int _unit);
-void setconf(void);
-dev_t getdiskbyname(char *_name);
-
-void devfs_create(dev_t dev);
-void devfs_destroy(dev_t dev);
-
-#define UID_ROOT 0
-#define UID_BIN 3
-#define UID_UUCP 66
-
-#define GID_WHEEL 0
-#define GID_KMEM 2
-#define GID_OPERATOR 5
-#define GID_BIN 7
-#define GID_GAMES 13
-#define GID_DIALER 68
-
-typedef void (*dev_clone_fn)(void *arg, char *name, int namelen, dev_t *result);
-
-int dev_stdclone(char *_name, char **_namep, const char *_stem, int *_unit);
-EVENTHANDLER_DECLARE(dev_clone, dev_clone_fn);
-
-/* Stuff relating to kernel-dump */
-
-struct dumperinfo {
- dumper_t *dumper; /* Dumping function. */
- void *priv; /* Private parts. */
- u_int blocksize; /* Size of block in bytes. */
- off_t mediaoffset; /* Initial offset in bytes. */
- off_t mediasize; /* Space available in bytes. */
-};
-
-int set_dumper(struct dumperinfo *);
-void dumpsys(struct dumperinfo *);
-extern int dumping; /* system is dumping */
-
-#endif /* _KERNEL */
-
-#endif /* !_SYS_CONF_H_ */
diff --git a/sys/sys/posix4.h b/sys/sys/posix4.h
deleted file mode 100644
index b17e9270e675..000000000000
--- a/sys/sys/posix4.h
+++ /dev/null
@@ -1,116 +0,0 @@
-#ifndef _P1003_1B_P1003_1B_H_
-#define _P1003_1B_P1003_1B_H_
-/*-
- * Copyright (c) 1996, 1997, 1998
- * HD Associates, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by HD Associates, Inc
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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$
- */
-
-#include <sys/param.h>
-#include <sys/ioccom.h>
-#include <sys/malloc.h>
-#include <posix4/sched.h>
-
-/* Generate syscall stubs for when something is optionally
- * loadable as a module. References "syscall_not_present".
- * XXX Good candidate for sys/syscall.h
- */
-struct proc;
-struct nosys_args;
-extern int syscall_not_present(struct thread *, const char *, struct nosys_args *);
-
-#define SYSCALL_NOT_PRESENT_GEN(SC) \
-int SC (struct thread *td, struct SC##_args *uap) \
-{ \
- return syscall_not_present(td, #SC , (struct nosys_args *)uap); \
-}
-
-
-MALLOC_DECLARE(M_P31B);
-
-#define p31b_malloc(SIZE) malloc((SIZE), M_P31B, M_WAITOK)
-#define p31b_free(P) free((P), M_P31B)
-
-int p31b_proc(struct proc *, pid_t, struct proc **);
-
-void p31b_setcfg(int, int);
-int p31b_getcfg(int);
-int p31b_iscfg(int);
-
-#ifdef _KPOSIX_PRIORITY_SCHEDULING
-
-/*
- * KSCHED_OP_RW is a vector of read/write flags for each entry indexed
- * by the enum ksched_op.
- *
- * 1 means you need write access, 0 means read is sufficient.
- */
-
-enum ksched_op {
-
-#define KSCHED_OP_RW { 1, 0, 1, 0, 0, 0, 0, 0 }
-
- SCHED_SETPARAM,
- SCHED_GETPARAM,
- SCHED_SETSCHEDULER,
- SCHED_GETSCHEDULER,
- SCHED_YIELD,
- SCHED_GET_PRIORITY_MAX,
- SCHED_GET_PRIORITY_MIN,
- SCHED_RR_GET_INTERVAL,
- SCHED_OP_MAX
-};
-
-struct ksched;
-
-int ksched_attach(struct ksched **);
-int ksched_detach(struct ksched *);
-
-int ksched_setparam(register_t *, struct ksched *,
- struct thread *, const struct sched_param *);
-int ksched_getparam(register_t *, struct ksched *,
- struct thread *, struct sched_param *);
-
-int ksched_setscheduler(register_t *, struct ksched *,
- struct thread *, int, const struct sched_param *);
-int ksched_getscheduler(register_t *, struct ksched *, struct thread *);
-
-int ksched_yield(register_t *, struct ksched *);
-
-int ksched_get_priority_max(register_t *, struct ksched *, int);
-int ksched_get_priority_min(register_t *, struct ksched *, int);
-
-int ksched_rr_get_interval(register_t *, struct ksched *,
- struct thread *, struct timespec *);
-
-#endif /* _KPOSIX_PRIORITY_SCHEDULING */
-
-#endif /* _P1003_1B_P1003_1B_H_ */
diff --git a/sys/sys/semaphore.h b/sys/sys/semaphore.h
deleted file mode 100644
index b717b98c8c96..000000000000
--- a/sys/sys/semaphore.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-
- * Copyright (c) 1996, 1997
- * HD Associates, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by HD Associates, Inc
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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$
- */
-
-/* semaphore.h: POSIX 1003.1b semaphores */
-
-#ifndef _SEMAPHORE_H_
-#define _SEMAPHORE_H_
-
-/* Opaque type definition. */
-struct sem;
-typedef struct sem * sem_t;
-
-#define SEM_FAILED ((sem_t *)0)
-#define SEM_VALUE_MAX (~0U) /* Equivalent to UINT_MAX. */
-
-#ifndef _KERNEL
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-int sem_close(sem_t *);
-int sem_destroy(sem_t *);
-int sem_getvalue(sem_t * __restrict, int * __restrict);
-int sem_init(sem_t *, int, unsigned int);
-sem_t *sem_open(const char *, int, ...);
-int sem_post(sem_t *);
-int sem_trywait(sem_t *);
-int sem_unlink(const char *);
-int sem_wait(sem_t *);
-__END_DECLS
-
-#endif
-
-#endif /* !_SEMAPHORE_H_ */
diff --git a/sys/tools/miidevs2h.awk b/sys/tools/miidevs2h.awk
deleted file mode 100644
index 1b0cb81d8f7b..000000000000
--- a/sys/tools/miidevs2h.awk
+++ /dev/null
@@ -1,147 +0,0 @@
-#! /usr/bin/awk -f
-# $NetBSD: devlist2h.awk,v 1.2 1998/09/05 14:42:06 christos Exp $
-#
-# Copyright (c) 1998 The NetBSD Foundation, Inc.
-# All rights reserved.
-#
-# This code is derived from software contributed to The NetBSD Foundation
-# by Christos Zoulas.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by the NetBSD
-# Foundation, Inc. and its contributors.
-# 4. Neither the name of The NetBSD Foundation nor the names of its
-# contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
-# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-# Copyright (c) 1995, 1996 Christopher G. Demetriou
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This model includes software developed by Christopher G. Demetriou.
-# This model includes software developed by Christos Zoulas
-# 4. The name of the author(s) may not be used to endorse or promote models
-# derived from this software without specific prior written permission
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-# $FreeBSD$
-#
-function collectline(f, line) {
- oparen = 0
- line = ""
- while (f <= NF) {
- if ($f == "#") {
- line = line "("
- oparen = 1
- f++
- continue
- }
- if (oparen) {
- line = line $f
- if (f < NF)
- line = line " "
- f++
- continue
- }
- line = line $f
- if (f < NF)
- line = line " "
- f++
- }
- if (oparen)
- line = line ")"
- return line
-}
-BEGIN {
- nmodels = nouis = 0
- hfile="miidevs.h"
-}
-NR == 1 {
- VERSION = $0
- gsub("\\$", "", VERSION)
-
- printf("/* \$FreeBSD\$ */\n\n") > hfile
- printf("/*\n") > hfile
- printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
- > hfile
- printf(" *\n") > hfile
- printf(" * generated from:\n") > hfile
- printf(" *\t%s\n", VERSION) > hfile
- printf(" */\n") > hfile
-
- next
-}
-$1 == "oui" {
- nuios++
-
- ouiindex[$2] = nouis; # record index for this name, for later.
-
- ouis[nouis, 1] = $2; # name
- ouis[nouis, 2] = $3; # id
- printf("#define\tMII_OUI_%s\t%s\t", ouis[nouis, 1],
- ouis[nouis, 2]) > hfile
- ouis[nouis, 3] = collectline(4, line)
- printf("/* %s */\n", ouis[nouis, 3]) > hfile
- next
-}
-$1 == "model" {
- nmodels++
-
- models[nmodels, 1] = $2; # oui name
- models[nmodels, 2] = $3; # model id
- models[nmodels, 3] = $4; # id
-
- printf("#define\tMII_MODEL_%s_%s\t%s\n", models[nmodels, 1],
- models[nmodels, 2], models[nmodels, 3]) > hfile
-
- models[nmodels, 4] = collectline(5, line)
-
- printf("#define\tMII_STR_%s_%s\t\"%s\"\n",
- models[nmodels, 1], models[nmodels, 2],
- models[nmodels, 4]) > hfile
-
- next
-}
-{
- print $0 > hfile
-}
diff --git a/sys/tools/pccarddevs2h.awk b/sys/tools/pccarddevs2h.awk
deleted file mode 100644
index d53761cf018b..000000000000
--- a/sys/tools/pccarddevs2h.awk
+++ /dev/null
@@ -1,178 +0,0 @@
-#! /usr/bin/awk -f
-# $NetBSD: devlist2h.awk,v 1.3 1998/09/05 14:42:06 christos Exp $
-# $FreeBSD$
-#
-# Copyright (c) 1998 The NetBSD Foundation, Inc.
-# All rights reserved.
-#
-# This code is derived from software contributed to The NetBSD Foundation
-# by Christos Zoulas.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by the NetBSD
-# Foundation, Inc. and its contributors.
-# 4. Neither the name of The NetBSD Foundation nor the names of its
-# contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
-# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-# Copyright (c) 1995, 1996 Christopher G. Demetriou
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by Christopher G. Demetriou.
-# This product includes software developed by Christos Zoulas
-# 4. The name of the author(s) 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.
-#
-function collectline(f, line) {
- oparen = 0
- line = ""
- while (f <= NF) {
- if ($f == "#") {
- line = line "("
- oparen = 1
- f++
- continue
- }
- if (oparen) {
- line = line $f
- if (f < NF)
- line = line " "
- f++
- continue
- }
- line = line $f
- if (f < NF)
- line = line " "
- f++
- }
- if (oparen)
- line = line ")"
- return line
-}
-BEGIN {
- nproducts = nvendors = 0
- hfile="pccarddevs.h"
-}
-NR == 1 {
- VERSION = $0
- gsub("\\$", "", VERSION)
-
- printf("/*\t\$FreeBSD\$\t*/\n\n") > hfile
- printf("/*\n") > hfile
- printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
- > hfile
- printf(" *\n") > hfile
- printf(" * generated from:\n") > hfile
- printf(" *\t%s\n", VERSION) > hfile
- printf(" */\n") > hfile
-
- next
-}
-$1 == "vendor" {
- nvendors++
-
- vendorindex[$2] = nvendors; # record index for this name, for later.
- vendors[nvendors, 1] = $2; # name
- if ($3 == "-1")
- $3 = "0xffffffff";
- vendors[nvendors, 2] = $3; # id
- printf("#define\tPCMCIA_VENDOR_%s\t%s\t", vendors[nvendors, 1],
- vendors[nvendors, 2]) > hfile
- vendors[nvendors, 3] = collectline(4, line)
- printf("/* %s */\n", vendors[nvendors, 3]) > hfile
- next
-}
-$1 == "product" {
- nproducts++
-
- products[nproducts, 1] = $2; # vendor name
- if ($3 == "-1")
- $3 = "0xffffffff";
- products[nproducts, 2] = $3; # product id
- products[nproducts, 3] = $4; # id
-
- f = 5;
-
- if ($4 == "{") {
- products[nproducts, 3] = "0xffffffff";
- z = "{ "
- for (i = 0; i < 4; i++) {
- if (f <= NF) {
- gsub("&sp", " ", $f)
- gsub("&tab", "\t", $f)
- gsub("&nl", "\n", $f)
- z = z $f " "
- f++
- }
- else {
- if (i == 3)
- z = z "NULL "
- else
- z = z "NULL, "
- }
- }
- products[nproducts, 4] = z $f
- f++
- }
- else {
- products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }"
- }
- printf("#define\tPCMCIA_CIS_%s_%s\t%s\n",
- products[nproducts, 1], products[nproducts, 2],
- products[nproducts, 4]) > hfile
- printf("#define\tPCMCIA_PRODUCT_%s_%s\t%s\n", products[nproducts, 1],
- products[nproducts, 2], products[nproducts, 3]) > hfile
-
- products[nproducts, 5] = collectline(f, line)
-
- printf("#define\tPCMCIA_STR_%s_%s\t\"%s\"\n",
- products[nproducts, 1], products[nproducts, 2],
- products[nproducts, 5]) > hfile
-
- next
-}
-{
- print $0 > hfile
-}
diff --git a/sys/tools/usbdevs2h.awk b/sys/tools/usbdevs2h.awk
deleted file mode 100644
index b0d0bbf03db1..000000000000
--- a/sys/tools/usbdevs2h.awk
+++ /dev/null
@@ -1,236 +0,0 @@
-#! /usr/bin/awk -f
-# $NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $
-# $FreeBSD$
-#
-# Copyright (c) 1995, 1996 Christopher G. Demetriou
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by Christopher G. Demetriou.
-# 4. The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-BEGIN {
- nproducts = nvendors = 0
- dfile="usbdevs_data.h"
- hfile="usbdevs.h"
-}
-NR == 1 {
- VERSION = $0
- gsub("\\$", "", VERSION)
-
- if (os == "NetBSD")
- printf("/*\t\$NetBSD\$\t*/\n\n") > dfile
- else if (os == "FreeBSD")
- printf("/*\t\$FreeBSD\$\t*/\n\n") > dfile
- else if (os == "OpenBSD")
- printf("/*\t\$OpenBSD\$\t*/\n\n") > dfile
- else
- printf("/* ??? */\n\n") > dfile
- printf("/*\n") > dfile
- printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
- > dfile
- printf(" *\n") > dfile
- printf(" * generated from:\n") > dfile
- printf(" *\t%s\n", VERSION) > dfile
- printf(" */\n") > dfile
-
- if (os == "NetBSD")
- printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
- else if (os == "FreeBSD")
- printf("/*\t\$FreeBSD\$\t*/\n\n") > hfile
- else if (os == "OpenBSD")
- printf("/*\t\$OpenBSD\$\t*/\n\n") > hfile
- else
- printf("/* ??? */\n\n") > hfile
- printf("/*\n") > hfile
- printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
- > hfile
- printf(" *\n") > hfile
- printf(" * generated from:\n") > hfile
- printf(" *\t%s\n", VERSION) > hfile
- printf(" */\n") > hfile
-
- next
-}
-$1 == "vendor" {
- nvendors++
-
- vendorindex[$2] = nvendors; # record index for this name, for later.
- vendors[nvendors, 1] = $2; # name
- vendors[nvendors, 2] = $3; # id
- printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
- vendors[nvendors, 2]) > hfile
-
- i = 3; f = 4;
-
- # comments
- ocomment = oparen = 0
- if (f <= NF) {
- printf("\t/* ") > hfile
- ocomment = 1;
- }
- while (f <= NF) {
- if ($f == "#") {
- printf("(") > hfile
- oparen = 1
- f++
- continue
- }
- if (oparen) {
- printf("%s", $f) > hfile
- if (f < NF)
- printf(" ") > hfile
- f++
- continue
- }
- vendors[nvendors, i] = $f
- printf("%s", vendors[nvendors, i]) > hfile
- if (f < NF)
- printf(" ") > hfile
- i++; f++;
- }
- if (oparen)
- printf(")") > hfile
- if (ocomment)
- printf(" */") > hfile
- printf("\n") > hfile
-
- next
-}
-$1 == "product" {
- nproducts++
-
- products[nproducts, 1] = $2; # vendor name
- products[nproducts, 2] = $3; # product id
- products[nproducts, 3] = $4; # id
- printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", products[nproducts, 1],
- products[nproducts, 2], products[nproducts, 3]) > hfile
-
- i=4; f = 5;
-
- # comments
- ocomment = oparen = 0
- if (f <= NF) {
- printf("\t/* ") > hfile
- ocomment = 1;
- }
- while (f <= NF) {
- if ($f == "#") {
- printf("(") > hfile
- oparen = 1
- f++
- continue
- }
- if (oparen) {
- printf("%s", $f) > hfile
- if (f < NF)
- printf(" ") > hfile
- f++
- continue
- }
- products[nproducts, i] = $f
- printf("%s", products[nproducts, i]) > hfile
- if (f < NF)
- printf(" ") > hfile
- i++; f++;
- }
- if (oparen)
- printf(")") > hfile
- if (ocomment)
- printf(" */") > hfile
- printf("\n") > hfile
-
- next
-}
-{
- if ($0 == "")
- blanklines++
- print $0 > hfile
- if (blanklines < 2)
- print $0 > dfile
-}
-END {
- # print out the match tables
-
- printf("\n") > dfile
-
- printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
- for (i = 1; i <= nproducts; i++) {
- printf("\t{\n") > dfile
- printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
- products[i, 1], products[i, 1], products[i, 2]) \
- > dfile
- printf("\t ") > dfile
- printf("0") > dfile
- printf(",\n") > dfile
-
- vendi = vendorindex[products[i, 1]];
- printf("\t \"") > dfile
- j = 3;
- needspace = 0;
- while (vendors[vendi, j] != "") {
- if (needspace)
- printf(" ") > dfile
- printf("%s", vendors[vendi, j]) > dfile
- needspace = 1
- j++
- }
- printf("\",\n") > dfile
-
- printf("\t \"") > dfile
- j = 4;
- needspace = 0;
- while (products[i, j] != "") {
- if (needspace)
- printf(" ") > dfile
- printf("%s", products[i, j]) > dfile
- needspace = 1
- j++
- }
- printf("\",\n") > dfile
- printf("\t},\n") > dfile
- }
- for (i = 1; i <= nvendors; i++) {
- printf("\t{\n") > dfile
- printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) \
- > dfile
- printf("\t USB_KNOWNDEV_NOPROD,\n") \
- > dfile
- printf("\t \"") > dfile
- j = 3;
- needspace = 0;
- while (vendors[i, j] != "") {
- if (needspace)
- printf(" ") > dfile
- printf("%s", vendors[i, j]) > dfile
- needspace = 1
- j++
- }
- printf("\",\n") > dfile
- printf("\t NULL,\n") > dfile
- printf("\t},\n") > dfile
- }
- printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
- printf("};\n") > dfile
-}
diff --git a/tools/build/make_check/Makefile b/tools/build/make_check/Makefile
deleted file mode 100644
index 0ae687e51c09..000000000000
--- a/tools/build/make_check/Makefile
+++ /dev/null
@@ -1,95 +0,0 @@
-# $FreeBSD$
-
-# Test for broken LHS expansion.
-# This *must* cause make(1) to detect a recursive variable, and fail as such.
-.if make(lhs_expn)
-FOO= ${BAR}
-BAR${NIL}= ${FOO}
-FOO${BAR}= ${FOO}
-.endif
-
-DATA1= helllo
-DATA2:= ${DATA1}
-DATA3= ${DATA2:S/ll/rr/g}
-DATA4:= ${DATA2:S/ll/rr/g}
-DATA2?= allo
-DATA5:= ${DATA2:S/ll/ii/g} ${DATA1:S/ll/rr/g}
-DATA2= yello
-DATA1:= ${DATA5:S/l/r/g}
-NIL=
-
-all:
- @echo "Running test variables"
- @echo 1:${DATA1} 2:${DATA2} 3:${DATA3} 4:${DATA4} 5:${DATA5} | \
- diff -u ${.CURDIR}/regress.variables.out - || ${MAKE} failure
- @echo "PASS: Test variables detected no regression, output matches."
- @echo "Running test targets"
- @${MAKE} double 2>/dev/null || ${MAKE} failure
- @echo "PASS: Test targets detected no regression."
- @echo "Running test sysvmatch"
- @${MAKE} sysvmatch || ${MAKE} failure
- @echo "PASS: Test sysvmatch detected no regression."
- @echo "Running test lhs_expn"
- @! ${MAKE} lhs_expn && true || ${MAKE} failure
- @echo "PASS: Test lhs_expn detected no regression."
- @echo "Running test notdef"
- @${MAKE} notdef || ${MAKE} failure
- @echo "PASS: Test notdef detected no regression."
- @echo "Running test modifiers"
- @${MAKE} modifiers || ${MAKE} failure
- @echo "PASS: Test modifiers detected no regression."
- @echo "Running test funny_targets"
- @${MAKE} funny_targets || ${MAKE} failure
- @echo "PASS: Test funny_targets detected no regression."
-
-.if make(double)
-# Doubly-defined targets. make(1) will warn, but use the "right" one. If it
-# switches to using the "non-right" one, it breaks things worse than a little
-# regression test.
-double:
- @true
-
-double:
- @false
-.endif
-
-.if make(sysvmatch)
-# Some versions of FreeBSD make(1) do not handle a nil LHS in sysvsubst.
-sysvmatch:
- @echo EMPTY ${NIL:=foo} LHS | \
- diff -u ${.CURDIR}/regress.sysvmatch.out - || false
-.endif
-
-# A bogus target for the lhs_expn test; If this is reached, then the make(1)
-# program has not errored out because of the recursion caused by not expanding
-# the left-hand-side's embedded variables above.
-lhs_expn:
- @true
-
-.if make(notdef)
-# make(1) claims to only evaluate a conditional as far as is necessary
-# to determine its value; that was not always the case.
-.undef notdef
-notdef:
-.if defined(notdef) && ${notdef:U}
-.endif
-.endif
-
-.if make(modifiers)
-# See if make(1) supports the C modifier.
-modifiers:
- @if ${MAKE} -V .CURDIR:C/.// 2>&1 >/dev/null | \
- grep -q "Unknown modifier 'C'"; then \
- false; \
- fi
-.endif
-
-.if make(funny_targets)
-funny_targets: colons::target exclamation!target
-colons::target:
-exclamation!target:
-.endif
-
-failure:
- @echo "FAIL: Test failed: regression detected. See above."
- @false
diff --git a/tools/build/make_check/regress.sysvmatch.out b/tools/build/make_check/regress.sysvmatch.out
deleted file mode 100644
index 759859e677ae..000000000000
--- a/tools/build/make_check/regress.sysvmatch.out
+++ /dev/null
@@ -1 +0,0 @@
-EMPTY LHS
diff --git a/tools/build/make_check/regress.variables.out b/tools/build/make_check/regress.variables.out
deleted file mode 100644
index 83528d57c82e..000000000000
--- a/tools/build/make_check/regress.variables.out
+++ /dev/null
@@ -1 +0,0 @@
-1:heiiro herrro 2:yello 3:yerro 4:herrlo 5:heiilo herrlo
diff --git a/tools/regression/usr.bin/sed/hanoi.sed b/tools/regression/usr.bin/sed/hanoi.sed
deleted file mode 100644
index 6a45deaa94c7..000000000000
--- a/tools/regression/usr.bin/sed/hanoi.sed
+++ /dev/null
@@ -1,103 +0,0 @@
-# Towers of Hanoi in sed.
-#
-# @(#)hanoi.sed 8.1 (Berkeley) 6/6/93
-# $FreeBSD$
-#
-#
-# Ex:
-# Run "sed -f hanoi.sed", and enter:
-#
-# :abcd: : :<CR>
-#
-# note -- TWO carriage returns were once required, this will output the
-# sequence of states involved in moving 4 rings, the largest called "a" and
-# the smallest called "d", from the first to the second of three towers, so
-# that the rings on any tower at any time are in descending order of size.
-# You can start with a different arrangement and a different number of rings,
-# say :ce:b:ax: and it will give the shortest procedure for moving them all
-# to the middle tower. The rules are: the names of the rings must all be
-# lower-case letters, they must be input within 3 fields (representing the
-# towers) and delimited by 4 colons, such that the letters within each field
-# are in alphabetical order (i.e. rings are in descending order of size).
-#
-# For the benefit of anyone who wants to figure out the script, an "internal"
-# line of the form
-# b:0abx:1a2b3 :2 :3x2
-# has the following meaning: the material after the three markers :1, :2,
-# and :3 represents the three towers; in this case the current set-up is
-# ":ab : :x :". The numbers after a, b and x in these fields indicate
-# that the next time it gets a chance, it will move a to tower 2, move b
-# to tower 3, and move x to tower 2. The string after :0 just keeps track
-# of the alphabetical order of the names of the rings. The b at the
-# beginning means that it is now dealing with ring b (either about to move
-# it, or re-evaluating where it should next be moved to).
-#
-# Although this version is "limited" to 26 rings because of the size of the
-# alphabet, one could write a script using the same idea in which the rings
-# were represented by arbitrary [strings][within][brackets], and in place of
-# the built-in line of the script giving the order of the letters of the
-# alphabet, it would accept from the user a line giving the ordering to be
-# assumed, e.g. [ucbvax][decvax][hplabs][foo][bar].
-#
-# George Bergman
-# Math, UC Berkeley 94720 USA
-
-# cleaning, diagnostics
-s/ *//g
-/^$/d
-/[^a-z:]/{a\
-Illegal characters: use only a-z and ":". Try again.
-d
-}
-/^:[a-z]*:[a-z]*:[a-z]*:$/!{a\
-Incorrect format: use\
-\ : string1 : string2 : string3 :<CR>\
-Try again.
-d
-}
-/\([a-z]\).*\1/{a\
-Repeated letters not allowed. Try again.
-d
-}
-# initial formatting
-h
-s/[a-z]/ /g
-G
-s/^:\( *\):\( *\):\( *\):\n:\([a-z]*\):\([a-z]*\):\([a-z]*\):$/:1\4\2\3:2\5\1\3:3\6\1\2:0/
-s/[a-z]/&2/g
-s/^/abcdefghijklmnopqrstuvwxyz/
-:a
-s/^\(.\).*\1.*/&\1/
-s/.//
-/^[^:]/ba
-s/\([^0]*\)\(:0.*\)/\2\1:/
-s/^[^0]*0\(.\)/\1&/
-:b
-# outputting current state without markers
-h
-s/.*:1/:/
-s/[123]//gp
-g
-:c
-# establishing destinations
-/^\(.\).*\1:1/td
-/^\(.\).*:1[^:]*\11/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\31/
-/^\(.\).*:1[^:]*\12/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\33/
-/^\(.\).*:1[^:]*\13/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\32/
-/^\(.\).*:2[^:]*\11/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\33/
-/^\(.\).*:2[^:]*\12/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\32/
-/^\(.\).*:2[^:]*\13/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\31/
-/^\(.\).*:3[^:]*\11/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\32/
-/^\(.\).*:3[^:]*\12/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\31/
-/^\(.\).*:3[^:]*\13/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\33/
-bc
-# iterate back to find smallest out-of-place ring
-:d
-s/^\(.\)\(:0[^:]*\([^:]\)\1.*:\([123]\)[^:]*\1\)\4/\3\2\4/
-td
-# move said ring (right, resp. left)
-s/^\(.\)\(.*\)\1\([23]\)\(.*:\3[^ ]*\) /\1\2 \4\1\3/
-s/^\(.\)\(.*:\([12]\)[^ ]*\) \(.*\)\1\3/\1\2\1\3\4 /
-tb
-s/.*/Done! Try another, or end with ^D./p
-d
diff --git a/tools/regression/usr.bin/sed/math.sed b/tools/regression/usr.bin/sed/math.sed
deleted file mode 100644
index 8e7bf51fbca7..000000000000
--- a/tools/regression/usr.bin/sed/math.sed
+++ /dev/null
@@ -1,163 +0,0 @@
-#
-# @(#)math.sed 8.1 (Berkeley) 6/6/93
-#
-# Addition and multiplication in sed.
-# ++ for a limited time only do (expr) too!!!
-#
-# Kevin S Braunsdorf, PUCC UNIX Group, ksb@cc.purdue.edu.
-#
-# Ex:
-# echo "4+7*3" | sed -f %f
-
-# make sure the expression is well formed
-s/[ ]//g
-/[+*\/-]$/{
- a\
- poorly formed expression, operator on the end
- q
-}
-/^[+*\/]/{
- a\
- poorly formed expression, leading operator
- q
-}
-
-# fill hold space with done token
-x
-s/^.*/done/
-x
-
-# main loop, process operators (*, + and () )
-: loop
-/^\+/{
- s///
- b loop
-}
-/^\(.*\)(\([^)]*\))\(.*\)$/{
- H
- s//\2/
- x
- s/^\(.*\)\n\(.*\)(\([^()]*\))\(.*\)$/()\2@\4@\1/
- x
- b loop
-}
-/^[0-9]*\*/b mul
-/^\([0-9]*\)\+\([0-9+*]*\*[0-9]*\)$/{
- s//\2+\1/
- b loop
-}
-/^[0-9]*\+/{
- s/$/=/
- b add
-}
-x
-/^done$/{
- x
- p
- d
-}
-/^()/{
- s///
- x
- G
- s/\(.*\)\n\([^@]*\)@\([^@]*\)@\(.*\)/\2\1\3/
- x
- s/[^@]*@[^@]*@\(.*\)/\1/
- x
- b loop
-}
-i\
-help, stack problem
-p
-x
-p
-q
-
-# turn mul into add until 1*x -> x
-: mul
-/^0*1\*/{
- s///
- b loop
-}
-/^\([0-9]*\)0\*/{
- s/^\([0-9]*\)0\*\([0-9]*\)/\1*\20/
- b mul
-}
-s/^\([0-9]*\)1\*/\10*/
-s/^\([0-9]*\)2\*/\11*/
-s/^\([0-9]*\)3\*/\12*/
-s/^\([0-9]*\)4\*/\13*/
-s/^\([0-9]*\)5\*/\14*/
-s/^\([0-9]*\)6\*/\15*/
-s/^\([0-9]*\)7\*/\16*/
-s/^\([0-9]*\)8\*/\17*/
-s/^\([0-9]*\)9\*/\18*/
-s/\*\([0-9*]*\)/*\1+\1/
-b mul
-
-# get rid of a plus term until 0+x -> x
-: add
-/^\+\([0-9+*]*\)=/{
- s//\1/
- b loop
-}
-/^\([0-9*]*\)\+=/{
- s//\1/
- b loop
-}
-/^\([0-9]*\)\+\([0-9*+]*\)\+=/{
- s//\2+\1/
- b loop
-}
-/^\([0-9]*\)0\+\([0-9]*\)\([0-9]\)=/{
- s//\1+\2=\3/
- b add
-}
-/^\([0-9]*\)\([0-9]\)\+\([0-9]*\)0=/{
- s//\1+\3=\2/
- b add
-}
-/^\([0-9]*\)0\+\([0-9*+]*\)\+\([0-9]*\)\([0-9]\)=/{
- s//\1+\2+\3=\4/
- b add
-}
-/^\([0-9]*\)\([0-9]\)\+\([0-9*+]*\)\+\([0-9]*\)0=/{
- s//\1+\3+\4=\2/
- b add
-}
-s/^\([0-9]*\)1\+/\10+/
-s/^\([0-9]*\)2\+/\11+/
-s/^\([0-9]*\)3\+/\12+/
-s/^\([0-9]*\)4\+/\13+/
-s/^\([0-9]*\)5\+/\14+/
-s/^\([0-9]*\)6\+/\15+/
-s/^\([0-9]*\)7\+/\16+/
-s/^\([0-9]*\)8\+/\17+/
-s/^\([0-9]*\)9\+/\18+/
-
-s/9=\([0-9]*\)$/_=\1/
-s/8=\([0-9]*\)$/9=\1/
-s/7=\([0-9]*\)$/8=\1/
-s/6=\([0-9]*\)$/7=\1/
-s/5=\([0-9]*\)$/6=\1/
-s/4=\([0-9]*\)$/5=\1/
-s/3=\([0-9]*\)$/4=\1/
-s/2=\([0-9]*\)$/3=\1/
-s/1=\([0-9]*\)$/2=\1/
-/_/{
- s//_0/
- : inc
- s/9_/_0/
- s/8_/9/
- s/7_/8/
- s/6_/7/
- s/5_/6/
- s/4_/5/
- s/3_/4/
- s/2_/3/
- s/1_/2/
- s/0_/1/
- s/\+_/+1/
- /_/b inc
-}
-b add
diff --git a/tools/regression/usr.bin/sed/multitest.t b/tools/regression/usr.bin/sed/multitest.t
deleted file mode 100644
index 71c7f20b52c5..000000000000
--- a/tools/regression/usr.bin/sed/multitest.t
+++ /dev/null
@@ -1,552 +0,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1992 Diomidis Spinellis.
-# Copyright (c) 1992, 1993
-# The Regents of the University of California. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by the University of
-# California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-# may be used to endorse or promote products derived from this software
-# without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-# @(#)sed.test 8.1 (Berkeley) 6/6/93
-#
-
-# sed Regression Tests
-#
-# The following files are created:
-# lines[1-4], script1, script2
-# Two directories *.out contain the test results
-
-main()
-{
- BASE=/usr/bin/sed
- BASELOG=sed.out
- TEST=`cd ..; make whereobj`/sed
- TESTLOG=nsed.out
- DICT=/usr/share/dict/words
-
- test_error | more
-
- awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1
- awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2
-
- exec 4>&1 5>&2
-
- # Set these flags to get messages about known problems
- BSD=1
- GNU=0
- SUN=0
- tests $BASE $BASELOG
-
- BSD=0
- GNU=0
- SUN=0
- tests $TEST $TESTLOG
- exec 1>&4 2>&5
- diff -c $BASELOG $TESTLOG | more
-}
-
-tests()
-{
- SED=$1
- DIR=$2
- rm -rf $DIR
- mkdir $DIR
- MARK=100
-
- test_args
- test_addr
- echo Testing commands
- test_group
- test_acid
- test_branch
- test_pattern
- test_print
- test_subst
-}
-
-mark()
-{
- MARK=`expr $MARK + 1`
- exec 1>&4 2>&5
- exec >"$DIR/${MARK}_$1"
- echo "Test $1:$MARK"
- # Uncomment this line to match tests with sed error messages
- echo "Test $1:$MARK" >&5
-}
-
-test_args()
-{
- mark '1.1'
- echo Testing argument parsing
- echo First type
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED 's/^/e1_/p' lines1
- fi
- mark '1.2' ; $SED -n 's/^/e1_/p' lines1
- mark '1.3'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED 's/^/e1_/p' <lines1
- fi
- mark '1.4' ; $SED -n 's/^/e1_/p' <lines1
- echo Second type
- mark '1.4.1'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed fails this
- fi
- $SED -e '' <lines1
- echo 's/^/s1_/p' >script1
- echo 's/^/s2_/p' >script2
- mark '1.5'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -f script1 lines1
- fi
- mark '1.6'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -f script1 <lines1
- fi
- mark '1.7'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -e 's/^/e1_/p' lines1
- fi
- mark '1.8'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -e 's/^/e1_/p' <lines1
- fi
- mark '1.9' ; $SED -n -f script1 lines1
- mark '1.10' ; $SED -n -f script1 <lines1
- mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1
- mark '1.12'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -n -e 's/^/e1_/p' <lines1
- fi
- mark '1.13'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
- fi
- mark '1.14'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -f script1 -f script2 lines1
- fi
- mark '1.15'
- if [ $GNU -eq 1 -o $SUN -eq 1 ] ; then
- echo GNU and SunOS sed fail this following older POSIX draft
- else
- $SED -e 's/^/e1_/p' -f script1 lines1
- fi
- mark '1.16'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -e 's/^/e1_/p' lines1 lines1
- fi
- # POSIX D11.2:11251
- mark '1.17' ; $SED p <lines1 lines1
-cat >script1 <<EOF
-#n
-# A comment
-
-p
-EOF
- mark '1.18' ; $SED -f script1 <lines1 lines1
-}
-
-test_addr()
-{
- echo Testing address ranges
- mark '2.1' ; $SED -n -e '4p' lines1
- mark '2.2' ; $SED -n -e '20p' lines1 lines2
- mark '2.3' ; $SED -n -e '$p' lines1
- mark '2.4' ; $SED -n -e '$p' lines1 lines2
- mark '2.5' ; $SED -n -e '$a\
-hello' /dev/null
- mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2
- # Should not print anything
- mark '2.7' ; $SED -n -e '20p' lines1
- mark '2.8' ; $SED -n -e '0p' lines1
- mark '2.9' ; $SED -n '/l1_7/p' lines1
- mark '2.10' ; $SED -n ' /l1_7/ p' lines1
- mark '2.11'
- if [ $BSD -eq 1 ] ; then
- echo BSD sed fails this test
- fi
- if [ $GNU -eq 1 ] ; then
- echo GNU sed fails this
- fi
- $SED -n '\_l1\_7_p' lines1
- mark '2.12' ; $SED -n '1,4p' lines1
- mark '2.13' ; $SED -n '1,$p' lines1 lines2
- mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
- mark '2.15' ; $SED -n '/4/,$p' lines1 lines2
- mark '2.16' ; $SED -n '/4/,20p' lines1 lines2
- mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2
- mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
- mark '2.19'
- if [ $GNU -eq 1 ] ; then
- echo GNU sed fails this
- fi
- $SED -n '12,3p' lines1 lines2
- mark '2.20'
- if [ $GNU -eq 1 ] ; then
- echo GNU sed fails this
- fi
- $SED -n '/l1_7/,3p' lines1 lines2
-}
-
-test_group()
-{
- echo Brace and other grouping
- mark '3.1' ; $SED -e '
-4,12 {
- s/^/^/
- s/$/$/
- s/_/T/
-}' lines1
- mark '3.2' ; $SED -e '
-4,12 {
- s/^/^/
- /6/,/10/ {
- s/$/$/
- /8/ s/_/T/
- }
-}' lines1
- mark '3.3' ; $SED -e '
-4,12 !{
- s/^/^/
- /6/,/10/ !{
- s/$/$/
- /8/ !s/_/T/
- }
-}' lines1
- mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
-}
-
-test_acid()
-{
- echo Testing a c d and i commands
- mark '4.1' ; $SED -n -e '
-s/^/before_i/p
-20i\
-inserted
-s/^/after_i/p
-' lines1 lines2
- mark '4.2' ; $SED -n -e '
-5,12s/^/5-12/
-s/^/before_a/p
-/5-12/a\
-appended
-s/^/after_a/p
-' lines1 lines2
- mark '4.3'
- if [ $GNU -eq 1 ] ; then
- echo GNU sed fails this
- fi
- $SED -n -e '
-s/^/^/p
-/l1_/a\
-appended
-8,10N
-s/$/$/p
-' lines1 lines2
- mark '4.4' ; $SED -n -e '
-c\
-hello
-' lines1
- mark '4.5' ; $SED -n -e '
-8c\
-hello
-' lines1
- mark '4.6' ; $SED -n -e '
-3,14c\
-hello
-' lines1
-# SunOS and GNU sed behave differently. We follow POSIX
-# mark '4.7' ; $SED -n -e '
-#8,3c\
-#hello
-#' lines1
- mark '4.8' ; $SED d <lines1
-}
-
-test_branch()
-{
- echo Testing labels and branching
- mark '5.1' ; $SED -n -e '
-b label4
-:label3
-s/^/label3_/p
-b end
-:label4
-2,12b label1
-b label2
-:label1
-s/^/label1_/p
-b
-:label2
-s/^/label2_/p
-b label3
-:end
-' lines1
- mark '5.2'
- if [ $BSD -eq 1 ] ; then
- echo BSD sed fails this test
- fi
- $SED -n -e '
-s/l1_/l2_/
-t ok
-b
-:ok
-s/^/tested /p
-' lines1 lines2
-# SunOS sed behaves differently here. Clarification needed.
-# mark '5.3' ; $SED -n -e '
-#5,8b inside
-#1,5 {
-# s/^/^/p
-# :inside
-# s/$/$/p
-#}
-#' lines1
-# Check that t clears the substitution done flag
- mark '5.4' ; $SED -n -e '
-1,8s/^/^/
-t l1
-:l1
-t l2
-s/$/$/p
-b
-:l2
-s/^/ERROR/
-' lines1
-# Check that reading a line clears the substitution done flag
- mark '5.5'
- if [ $BSD -eq 1 ] ; then
- echo BSD sed fails this test
- fi
- $SED -n -e '
-t l2
-1,8s/^/^/p
-2,7N
-b
-:l2
-s/^/ERROR/p
-' lines1
- mark '5.6' ; $SED 5q lines1
- mark '5.7' ; $SED -e '
-5i\
-hello
-5q' lines1
-# Branch across block boundary
- mark '5.8' ; $SED -e '
-{
-:b
-}
-s/l/m/
-tb' lines1
-}
-
-test_pattern()
-{
-echo Pattern space commands
-# Check that the pattern space is deleted
- mark '6.1' ; $SED -n -e '
-c\
-changed
-p
-' lines1
- mark '6.2' ; $SED -n -e '
-4d
-p
-' lines1
-# SunOS sed refused to print here
-# mark '6.3' ; $SED -e '
-#N
-#N
-#N
-#D
-#P
-#4p
-#' lines1
- mark '6.4' ; $SED -e '
-2h
-3H
-4g
-5G
-6x
-6p
-6x
-6p
-' lines1
- mark '6.5' ; $SED -e '4n' lines1
- mark '6.6' ; $SED -n -e '4n' lines1
-}
-
-test_print()
-{
- echo Testing print and file routines
- awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
- </dev/null >lines3
- # GNU and SunOS sed behave differently here
- mark '7.1'
- if [ $BSD -eq 1 ] ; then
- echo 'BSD sed drops core on this one; TEST SKIPPED'
- else
- $SED -n l lines3
- fi
- mark '7.2' ; $SED -e '/l2_/=' lines1 lines2
- rm -f lines4
- mark '7.3' ; $SED -e '3,12w lines4' lines1
- echo w results
- cat lines4
- mark '7.4' ; $SED -e '4r lines2' lines1
- mark '7.5' ; $SED -e '5r /dev/dds' lines1
- mark '7.6' ; $SED -e '6r /dev/null' lines1
- mark '7.7'
- if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
- echo BSD, GNU and SunOS cannot pass this one
- else
- sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1
- rm -rf tmpdir
- mkdir tmpdir
- $SED -f script1 lines1
- cat tmpdir/*
- rm -rf tmpdir
- fi
- mark '7.8'
- if [ $BSD -eq 1 ] ; then
- echo BSD sed cannot pass 7.7
- else
- echo line1 > lines3
- echo "" >> lines3
- $SED -n -e '$p' lines3 /dev/null
- fi
-
-}
-
-test_subst()
-{
- echo Testing substitution commands
- mark '8.1' ; $SED -e 's/./X/g' lines1
- mark '8.2' ; $SED -e 's,.,X,g' lines1
-# GNU and SunOS sed thinks we are escaping . as wildcard, not as separator
-# mark '8.3' ; $SED -e 's.\..X.g' lines1
-# POSIX does not say that this should work
-# mark '8.4' ; $SED -e 's/[/]/Q/' lines1
- mark '8.4' ; $SED -e 's/[\/]/Q/' lines1
- mark '8.5' ; $SED -e 's_\__X_' lines1
- mark '8.6' ; $SED -e 's/./(&)/g' lines1
- mark '8.7' ; $SED -e 's/./(\&)/g' lines1
- mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
- mark '8.9' ; $SED -e 's/_/u0\
-u1\
-u2/g' lines1
- mark '8.10'
- if [ $BSD -eq 1 -o $GNU -eq 1 ] ; then
- echo 'BSD/GNU sed do not understand digit flags on s commands'
- fi
- $SED -e 's/./X/4' lines1
- rm -f lines4
- mark '8.11' ; $SED -e 's/1/X/w lines4' lines1
- echo s wfile results
- cat lines4
- mark '8.12' ; $SED -e 's/[123]/X/g' lines1
- mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
- mark '8.14' ;
- if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
- echo BSD/GNU/SUN sed fail this test
- else
- $SED -e 'y10\123456789198765432\101' lines1
- fi
- mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1
- mark '8.16'
- if [ $BSD -eq 1 ] ; then
- echo 'BSD sed does not handle branch defined REs'
- else
- echo 'eeefff' | $SED -e 'p' -e 's/e/X/p' -e ':x' \
- -e 's//Y/p' -e '/f/bx'
- fi
-}
-
-test_error()
-{
- exec 0>&3 4>&1 5>&2
- exec 0</dev/null
- exec 2>&1
- set -x
- $TEST -x && exit 1
- $TEST -f && exit 1
- $TEST -e && exit 1
- $TEST -f /dev/dds && exit 1
- $TEST p /dev/dds && exit 1
- $TEST -f /bin/sh && exit 1
- $TEST '{' && exit 1
- $TEST '{' && exit 1
- $TEST '/hello/' && exit 1
- $TEST '1,/hello/' && exit 1
- $TEST -e '-5p' && exit 1
- $TEST '/jj' && exit 1
- $TEST 'a hello' && exit 1
- $TEST 'a \ hello' && exit 1
- $TEST 'b foo' && exit 1
- $TEST 'd hello' && exit 1
- $TEST 's/aa' && exit 1
- $TEST 's/aa/' && exit 1
- $TEST 's/a/b' && exit 1
- $TEST 's/a/b/c/d' && exit 1
- $TEST 's/a/b/ 1 2' && exit 1
- $TEST 's/a/b/ 1 g' && exit 1
- $TEST 's/a/b/w' && exit 1
- $TEST 'y/aa' && exit 1
- $TEST 'y/aa/b/' && exit 1
- $TEST 'y/aa/' && exit 1
- $TEST 'y/a/b' && exit 1
- $TEST 'y/a/b/c/d' && exit 1
- $TEST '!' && exit 1
- $TEST supercalifrangolisticexprialidociussupercalifrangolisticexcius
- set +x
- exec 0>&3 1>&4 2>&5
-}
-
-main
diff --git a/tools/regression/usr.bin/sed/sed.test b/tools/regression/usr.bin/sed/sed.test
deleted file mode 100644
index 71c7f20b52c5..000000000000
--- a/tools/regression/usr.bin/sed/sed.test
+++ /dev/null
@@ -1,552 +0,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1992 Diomidis Spinellis.
-# Copyright (c) 1992, 1993
-# The Regents of the University of California. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by the University of
-# California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-# may be used to endorse or promote products derived from this software
-# without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-# @(#)sed.test 8.1 (Berkeley) 6/6/93
-#
-
-# sed Regression Tests
-#
-# The following files are created:
-# lines[1-4], script1, script2
-# Two directories *.out contain the test results
-
-main()
-{
- BASE=/usr/bin/sed
- BASELOG=sed.out
- TEST=`cd ..; make whereobj`/sed
- TESTLOG=nsed.out
- DICT=/usr/share/dict/words
-
- test_error | more
-
- awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1
- awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2
-
- exec 4>&1 5>&2
-
- # Set these flags to get messages about known problems
- BSD=1
- GNU=0
- SUN=0
- tests $BASE $BASELOG
-
- BSD=0
- GNU=0
- SUN=0
- tests $TEST $TESTLOG
- exec 1>&4 2>&5
- diff -c $BASELOG $TESTLOG | more
-}
-
-tests()
-{
- SED=$1
- DIR=$2
- rm -rf $DIR
- mkdir $DIR
- MARK=100
-
- test_args
- test_addr
- echo Testing commands
- test_group
- test_acid
- test_branch
- test_pattern
- test_print
- test_subst
-}
-
-mark()
-{
- MARK=`expr $MARK + 1`
- exec 1>&4 2>&5
- exec >"$DIR/${MARK}_$1"
- echo "Test $1:$MARK"
- # Uncomment this line to match tests with sed error messages
- echo "Test $1:$MARK" >&5
-}
-
-test_args()
-{
- mark '1.1'
- echo Testing argument parsing
- echo First type
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED 's/^/e1_/p' lines1
- fi
- mark '1.2' ; $SED -n 's/^/e1_/p' lines1
- mark '1.3'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED 's/^/e1_/p' <lines1
- fi
- mark '1.4' ; $SED -n 's/^/e1_/p' <lines1
- echo Second type
- mark '1.4.1'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed fails this
- fi
- $SED -e '' <lines1
- echo 's/^/s1_/p' >script1
- echo 's/^/s2_/p' >script2
- mark '1.5'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -f script1 lines1
- fi
- mark '1.6'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -f script1 <lines1
- fi
- mark '1.7'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -e 's/^/e1_/p' lines1
- fi
- mark '1.8'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -e 's/^/e1_/p' <lines1
- fi
- mark '1.9' ; $SED -n -f script1 lines1
- mark '1.10' ; $SED -n -f script1 <lines1
- mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1
- mark '1.12'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -n -e 's/^/e1_/p' <lines1
- fi
- mark '1.13'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
- fi
- mark '1.14'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -f script1 -f script2 lines1
- fi
- mark '1.15'
- if [ $GNU -eq 1 -o $SUN -eq 1 ] ; then
- echo GNU and SunOS sed fail this following older POSIX draft
- else
- $SED -e 's/^/e1_/p' -f script1 lines1
- fi
- mark '1.16'
- if [ $SUN -eq 1 ] ; then
- echo SunOS sed prints only with -n
- else
- $SED -e 's/^/e1_/p' lines1 lines1
- fi
- # POSIX D11.2:11251
- mark '1.17' ; $SED p <lines1 lines1
-cat >script1 <<EOF
-#n
-# A comment
-
-p
-EOF
- mark '1.18' ; $SED -f script1 <lines1 lines1
-}
-
-test_addr()
-{
- echo Testing address ranges
- mark '2.1' ; $SED -n -e '4p' lines1
- mark '2.2' ; $SED -n -e '20p' lines1 lines2
- mark '2.3' ; $SED -n -e '$p' lines1
- mark '2.4' ; $SED -n -e '$p' lines1 lines2
- mark '2.5' ; $SED -n -e '$a\
-hello' /dev/null
- mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2
- # Should not print anything
- mark '2.7' ; $SED -n -e '20p' lines1
- mark '2.8' ; $SED -n -e '0p' lines1
- mark '2.9' ; $SED -n '/l1_7/p' lines1
- mark '2.10' ; $SED -n ' /l1_7/ p' lines1
- mark '2.11'
- if [ $BSD -eq 1 ] ; then
- echo BSD sed fails this test
- fi
- if [ $GNU -eq 1 ] ; then
- echo GNU sed fails this
- fi
- $SED -n '\_l1\_7_p' lines1
- mark '2.12' ; $SED -n '1,4p' lines1
- mark '2.13' ; $SED -n '1,$p' lines1 lines2
- mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
- mark '2.15' ; $SED -n '/4/,$p' lines1 lines2
- mark '2.16' ; $SED -n '/4/,20p' lines1 lines2
- mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2
- mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
- mark '2.19'
- if [ $GNU -eq 1 ] ; then
- echo GNU sed fails this
- fi
- $SED -n '12,3p' lines1 lines2
- mark '2.20'
- if [ $GNU -eq 1 ] ; then
- echo GNU sed fails this
- fi
- $SED -n '/l1_7/,3p' lines1 lines2
-}
-
-test_group()
-{
- echo Brace and other grouping
- mark '3.1' ; $SED -e '
-4,12 {
- s/^/^/
- s/$/$/
- s/_/T/
-}' lines1
- mark '3.2' ; $SED -e '
-4,12 {
- s/^/^/
- /6/,/10/ {
- s/$/$/
- /8/ s/_/T/
- }
-}' lines1
- mark '3.3' ; $SED -e '
-4,12 !{
- s/^/^/
- /6/,/10/ !{
- s/$/$/
- /8/ !s/_/T/
- }
-}' lines1
- mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
-}
-
-test_acid()
-{
- echo Testing a c d and i commands
- mark '4.1' ; $SED -n -e '
-s/^/before_i/p
-20i\
-inserted
-s/^/after_i/p
-' lines1 lines2
- mark '4.2' ; $SED -n -e '
-5,12s/^/5-12/
-s/^/before_a/p
-/5-12/a\
-appended
-s/^/after_a/p
-' lines1 lines2
- mark '4.3'
- if [ $GNU -eq 1 ] ; then
- echo GNU sed fails this
- fi
- $SED -n -e '
-s/^/^/p
-/l1_/a\
-appended
-8,10N
-s/$/$/p
-' lines1 lines2
- mark '4.4' ; $SED -n -e '
-c\
-hello
-' lines1
- mark '4.5' ; $SED -n -e '
-8c\
-hello
-' lines1
- mark '4.6' ; $SED -n -e '
-3,14c\
-hello
-' lines1
-# SunOS and GNU sed behave differently. We follow POSIX
-# mark '4.7' ; $SED -n -e '
-#8,3c\
-#hello
-#' lines1
- mark '4.8' ; $SED d <lines1
-}
-
-test_branch()
-{
- echo Testing labels and branching
- mark '5.1' ; $SED -n -e '
-b label4
-:label3
-s/^/label3_/p
-b end
-:label4
-2,12b label1
-b label2
-:label1
-s/^/label1_/p
-b
-:label2
-s/^/label2_/p
-b label3
-:end
-' lines1
- mark '5.2'
- if [ $BSD -eq 1 ] ; then
- echo BSD sed fails this test
- fi
- $SED -n -e '
-s/l1_/l2_/
-t ok
-b
-:ok
-s/^/tested /p
-' lines1 lines2
-# SunOS sed behaves differently here. Clarification needed.
-# mark '5.3' ; $SED -n -e '
-#5,8b inside
-#1,5 {
-# s/^/^/p
-# :inside
-# s/$/$/p
-#}
-#' lines1
-# Check that t clears the substitution done flag
- mark '5.4' ; $SED -n -e '
-1,8s/^/^/
-t l1
-:l1
-t l2
-s/$/$/p
-b
-:l2
-s/^/ERROR/
-' lines1
-# Check that reading a line clears the substitution done flag
- mark '5.5'
- if [ $BSD -eq 1 ] ; then
- echo BSD sed fails this test
- fi
- $SED -n -e '
-t l2
-1,8s/^/^/p
-2,7N
-b
-:l2
-s/^/ERROR/p
-' lines1
- mark '5.6' ; $SED 5q lines1
- mark '5.7' ; $SED -e '
-5i\
-hello
-5q' lines1
-# Branch across block boundary
- mark '5.8' ; $SED -e '
-{
-:b
-}
-s/l/m/
-tb' lines1
-}
-
-test_pattern()
-{
-echo Pattern space commands
-# Check that the pattern space is deleted
- mark '6.1' ; $SED -n -e '
-c\
-changed
-p
-' lines1
- mark '6.2' ; $SED -n -e '
-4d
-p
-' lines1
-# SunOS sed refused to print here
-# mark '6.3' ; $SED -e '
-#N
-#N
-#N
-#D
-#P
-#4p
-#' lines1
- mark '6.4' ; $SED -e '
-2h
-3H
-4g
-5G
-6x
-6p
-6x
-6p
-' lines1
- mark '6.5' ; $SED -e '4n' lines1
- mark '6.6' ; $SED -n -e '4n' lines1
-}
-
-test_print()
-{
- echo Testing print and file routines
- awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
- </dev/null >lines3
- # GNU and SunOS sed behave differently here
- mark '7.1'
- if [ $BSD -eq 1 ] ; then
- echo 'BSD sed drops core on this one; TEST SKIPPED'
- else
- $SED -n l lines3
- fi
- mark '7.2' ; $SED -e '/l2_/=' lines1 lines2
- rm -f lines4
- mark '7.3' ; $SED -e '3,12w lines4' lines1
- echo w results
- cat lines4
- mark '7.4' ; $SED -e '4r lines2' lines1
- mark '7.5' ; $SED -e '5r /dev/dds' lines1
- mark '7.6' ; $SED -e '6r /dev/null' lines1
- mark '7.7'
- if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
- echo BSD, GNU and SunOS cannot pass this one
- else
- sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1
- rm -rf tmpdir
- mkdir tmpdir
- $SED -f script1 lines1
- cat tmpdir/*
- rm -rf tmpdir
- fi
- mark '7.8'
- if [ $BSD -eq 1 ] ; then
- echo BSD sed cannot pass 7.7
- else
- echo line1 > lines3
- echo "" >> lines3
- $SED -n -e '$p' lines3 /dev/null
- fi
-
-}
-
-test_subst()
-{
- echo Testing substitution commands
- mark '8.1' ; $SED -e 's/./X/g' lines1
- mark '8.2' ; $SED -e 's,.,X,g' lines1
-# GNU and SunOS sed thinks we are escaping . as wildcard, not as separator
-# mark '8.3' ; $SED -e 's.\..X.g' lines1
-# POSIX does not say that this should work
-# mark '8.4' ; $SED -e 's/[/]/Q/' lines1
- mark '8.4' ; $SED -e 's/[\/]/Q/' lines1
- mark '8.5' ; $SED -e 's_\__X_' lines1
- mark '8.6' ; $SED -e 's/./(&)/g' lines1
- mark '8.7' ; $SED -e 's/./(\&)/g' lines1
- mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
- mark '8.9' ; $SED -e 's/_/u0\
-u1\
-u2/g' lines1
- mark '8.10'
- if [ $BSD -eq 1 -o $GNU -eq 1 ] ; then
- echo 'BSD/GNU sed do not understand digit flags on s commands'
- fi
- $SED -e 's/./X/4' lines1
- rm -f lines4
- mark '8.11' ; $SED -e 's/1/X/w lines4' lines1
- echo s wfile results
- cat lines4
- mark '8.12' ; $SED -e 's/[123]/X/g' lines1
- mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
- mark '8.14' ;
- if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
- echo BSD/GNU/SUN sed fail this test
- else
- $SED -e 'y10\123456789198765432\101' lines1
- fi
- mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1
- mark '8.16'
- if [ $BSD -eq 1 ] ; then
- echo 'BSD sed does not handle branch defined REs'
- else
- echo 'eeefff' | $SED -e 'p' -e 's/e/X/p' -e ':x' \
- -e 's//Y/p' -e '/f/bx'
- fi
-}
-
-test_error()
-{
- exec 0>&3 4>&1 5>&2
- exec 0</dev/null
- exec 2>&1
- set -x
- $TEST -x && exit 1
- $TEST -f && exit 1
- $TEST -e && exit 1
- $TEST -f /dev/dds && exit 1
- $TEST p /dev/dds && exit 1
- $TEST -f /bin/sh && exit 1
- $TEST '{' && exit 1
- $TEST '{' && exit 1
- $TEST '/hello/' && exit 1
- $TEST '1,/hello/' && exit 1
- $TEST -e '-5p' && exit 1
- $TEST '/jj' && exit 1
- $TEST 'a hello' && exit 1
- $TEST 'a \ hello' && exit 1
- $TEST 'b foo' && exit 1
- $TEST 'd hello' && exit 1
- $TEST 's/aa' && exit 1
- $TEST 's/aa/' && exit 1
- $TEST 's/a/b' && exit 1
- $TEST 's/a/b/c/d' && exit 1
- $TEST 's/a/b/ 1 2' && exit 1
- $TEST 's/a/b/ 1 g' && exit 1
- $TEST 's/a/b/w' && exit 1
- $TEST 'y/aa' && exit 1
- $TEST 'y/aa/b/' && exit 1
- $TEST 'y/aa/' && exit 1
- $TEST 'y/a/b' && exit 1
- $TEST 'y/a/b/c/d' && exit 1
- $TEST '!' && exit 1
- $TEST supercalifrangolisticexprialidociussupercalifrangolisticexcius
- set +x
- exec 0>&3 1>&4 2>&5
-}
-
-main
diff --git a/usr.bin/gprof/amd64.c b/usr.bin/gprof/amd64.c
deleted file mode 100644
index c112763eafe3..000000000000
--- a/usr.bin/gprof/amd64.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "gprof.h"
-
-/*
- * gprof -c isn't currently supported...
- */
-void
-findcall( parentp , p_lowpc , p_highpc )
- nltype *parentp;
- unsigned long p_lowpc;
- unsigned long p_highpc;
-{
-}
diff --git a/usr.bin/gprof/amd64.h b/usr.bin/gprof/amd64.h
deleted file mode 100644
index 823d6562d105..000000000000
--- a/usr.bin/gprof/amd64.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)i386.h 8.1 (Berkeley) 6/6/93
- * $FreeBSD$
- */
-
- /*
- * offset (in bytes) of the code from the entry address of a routine.
- * (see asgnsamples for use and explanation.)
- */
-#define OFFSET_OF_CODE 0
-
-enum opermodes { dummy };
-typedef enum opermodes operandenum;
diff --git a/usr.bin/truss/amd64-fbsd32.c b/usr.bin/truss/amd64-fbsd32.c
deleted file mode 100644
index fb2b2567c067..000000000000
--- a/usr.bin/truss/amd64-fbsd32.c
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * Copryight 1997 Sean Eric Fagan
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Sean Eric Fagan
- * 4. Neither the name of the author 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.
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-/*
- * FreeBSD/i386-specific system call handling. This is probably the most
- * complex part of the entire truss program, although I've got lots of
- * it handled relatively cleanly now. The system call names are generated
- * automatically, thanks to /usr/src/sys/kern/syscalls.master. The
- * names used for the various structures are confusing, I sadly admit.
- */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/pioctl.h>
-#include <sys/syscall.h>
-
-#include <machine/reg.h>
-#include <machine/psl.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "truss.h"
-#include "syscall.h"
-#include "extern.h"
-
-static int fd = -1;
-static int cpid = -1;
-extern int Procfd;
-
-#include "syscalls.h"
-
-static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
-
-/*
- * This is what this particular file uses to keep track of a system call.
- * It is probably not quite sufficient -- I can probably use the same
- * structure for the various syscall personalities, and I also probably
- * need to nest system calls (for signal handlers).
- *
- * 'struct syscall' describes the system call; it may be NULL, however,
- * if we don't know about this particular system call yet.
- */
-static struct freebsd_syscall {
- struct syscall *sc;
- const char *name;
- int number;
- unsigned long *args;
- int nargs; /* number of arguments -- *not* number of words! */
- char **s_args; /* the printable arguments */
-} fsc;
-
-/* Clear up and free parts of the fsc structure. */
-static __inline void
-clear_fsc(void) {
- if (fsc.args) {
- free(fsc.args);
- }
- if (fsc.s_args) {
- int i;
- for (i = 0; i < fsc.nargs; i++)
- if (fsc.s_args[i])
- free(fsc.s_args[i]);
- free(fsc.s_args);
- }
- memset(&fsc, 0, sizeof(fsc));
-}
-
-/*
- * Called when a process has entered a system call. nargs is the
- * number of words, not number of arguments (a necessary distinction
- * in some cases). Note that if the STOPEVENT() code in i386/i386/trap.c
- * is ever changed these functions need to keep up.
- */
-
-void
-i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
- char buf[32];
- struct reg regs;
- int syscall_num;
- int i;
- unsigned int parm_offset;
- struct syscall *sc;
-
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDWR);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return;
- }
- cpid = trussinfo->pid;
- }
-
- clear_fsc();
- lseek(fd, 0L, 0);
- if (read(fd, &regs, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return;
- }
- parm_offset = regs.r_esp + sizeof(int);
-
- /*
- * FreeBSD has two special kinds of system call redirctions --
- * SYS_syscall, and SYS___syscall. The former is the old syscall()
- * routine, basicly; the latter is for quad-aligned arguments.
- */
- syscall_num = regs.r_eax;
- switch (syscall_num) {
- case SYS_syscall:
- lseek(Procfd, parm_offset, SEEK_SET);
- read(Procfd, &syscall_num, sizeof(int));
- parm_offset += sizeof(int);
- break;
- case SYS___syscall:
- lseek(Procfd, parm_offset, SEEK_SET);
- read(Procfd, &syscall_num, sizeof(int));
- parm_offset += sizeof(quad_t);
- break;
- }
-
- fsc.number = syscall_num;
- fsc.name =
- (syscall_num < 0 || syscall_num > nsyscalls) ? NULL : syscallnames[syscall_num];
- if (!fsc.name) {
- fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
- }
-
- if (fsc.name && (trussinfo->flags & FOLLOWFORKS)
- && ((!strcmp(fsc.name, "fork")
- || !strcmp(fsc.name, "rfork")
- || !strcmp(fsc.name, "vfork"))))
- {
- trussinfo->in_fork = 1;
- }
-
- if (nargs == 0)
- return;
-
- fsc.args = malloc((1+nargs) * sizeof(unsigned long));
- lseek(Procfd, parm_offset, SEEK_SET);
- if (read(Procfd, fsc.args, nargs * sizeof(unsigned long)) == -1)
- return;
-
- sc = get_syscall(fsc.name);
- if (sc) {
- fsc.nargs = sc->nargs;
- } else {
-#if DEBUG
- fprintf(trussinfo->outfile, "unknown syscall %s -- setting args to %d\n",
- fsc.name, nargs);
-#endif
- fsc.nargs = nargs;
- }
-
- fsc.s_args = malloc((1+fsc.nargs) * sizeof(char*));
- memset(fsc.s_args, 0, fsc.nargs * sizeof(char*));
- fsc.sc = sc;
-
- /*
- * At this point, we set up the system call arguments.
- * We ignore any OUT ones, however -- those are arguments that
- * are set by the system call, and so are probably meaningless
- * now. This doesn't currently support arguments that are
- * passed in *and* out, however.
- */
-
- if (fsc.name) {
-
-#if DEBUG
- fprintf(stderr, "syscall %s(", fsc.name);
-#endif
- for (i = 0; i < fsc.nargs; i++) {
-#if DEBUG
- fprintf(stderr, "0x%x%s",
- sc
- ? fsc.args[sc->args[i].offset]
- : fsc.args[i],
- i < (fsc.nargs - 1) ? "," : "");
-#endif
- if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args);
- }
- }
-#if DEBUG
- fprintf(stderr, ")\n");
-#endif
- }
-
-#if DEBUG
- fprintf(trussinfo->outfile, "\n");
-#endif
-
- /*
- * Some system calls should be printed out before they are done --
- * execve() and exit(), for example, never return. Possibly change
- * this to work for any system call that doesn't have an OUT
- * parameter?
- */
-
- if (!strcmp(fsc.name, "execve") || !strcmp(fsc.name, "exit")) {
-
- /* XXX
- * This could be done in a more general
- * manner but it still wouldn't be very pretty.
- */
- if (!strcmp(fsc.name, "execve")) {
- if ((trussinfo->flags & EXECVEARGS) == 0)
- if (fsc.s_args[1]) {
- free(fsc.s_args[1]);
- fsc.s_args[1] = NULL;
- }
- if ((trussinfo->flags & EXECVEENVS) == 0)
- if (fsc.s_args[2]) {
- free(fsc.s_args[2]);
- fsc.s_args[2] = NULL;
- }
- }
-
- print_syscall(trussinfo, fsc.name, fsc.nargs, fsc.s_args);
- fprintf(trussinfo->outfile, "\n");
- }
-
- return;
-}
-
-/*
- * And when the system call is done, we handle it here.
- * Currently, no attempt is made to ensure that the system calls
- * match -- this needs to be fixed (and is, in fact, why S_SCX includes
- * the sytem call number instead of, say, an error status).
- */
-
-int
-i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
- char buf[32];
- struct reg regs;
- int retval;
- int i;
- int errorp;
- struct syscall *sc;
-
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDONLY);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return (-1);
- }
- cpid = trussinfo->pid;
- }
-
- lseek(fd, 0L, 0);
- if (read(fd, &regs, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
- retval = regs.r_eax;
- errorp = !!(regs.r_eflags & PSL_C);
-
- /*
- * This code, while simpler than the initial versions I used, could
- * stand some significant cleaning.
- */
-
- sc = fsc.sc;
- if (!sc) {
- for (i = 0; i < fsc.nargs; i++) {
- fsc.s_args[i] = malloc(12);
- sprintf(fsc.s_args[i], "0x%lx", fsc.args[i]);
- }
- } else {
- /*
- * Here, we only look for arguments that have OUT masked in --
- * otherwise, they were handled in the syscall_entry function.
- */
- for (i = 0; i < sc->nargs; i++) {
- char *temp;
- if (sc->args[i].type & OUT) {
- /*
- * If an error occurred, than don't bothe getting the data;
- * it may not be valid.
- */
- if (errorp) {
- temp = malloc(12);
- sprintf(temp, "0x%lx", fsc.args[sc->args[i].offset]);
- } else {
- temp = print_arg(Procfd, &sc->args[i], fsc.args);
- }
- fsc.s_args[i] = temp;
- }
- }
- }
-
- /*
- * It would probably be a good idea to merge the error handling,
- * but that complicates things considerably.
- */
-
- print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, retval);
- clear_fsc();
-
- return (retval);
-}
diff --git a/usr.bin/truss/amd64-linux32.c b/usr.bin/truss/amd64-linux32.c
deleted file mode 100644
index e2f17e7f69f0..000000000000
--- a/usr.bin/truss/amd64-linux32.c
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
- * Copryight 1997 Sean Eric Fagan
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Sean Eric Fagan
- * 4. Neither the name of the author 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.
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-/*
- * Linux/i386-specific system call handling. Given how much of this code
- * is taken from the freebsd equivalent, I can probably put even more of
- * it in support routines that can be used by any personality support.
- */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/pioctl.h>
-
-#include <machine/reg.h>
-#include <machine/psl.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "truss.h"
-#include "syscall.h"
-#include "extern.h"
-
-static int fd = -1;
-static int cpid = -1;
-extern int Procfd;
-
-#include "linux_syscalls.h"
-
-static int nsyscalls =
- sizeof(linux_syscallnames) / sizeof(linux_syscallnames[0]);
-
-/*
- * This is what this particular file uses to keep track of a system call.
- * It is probably not quite sufficient -- I can probably use the same
- * structure for the various syscall personalities, and I also probably
- * need to nest system calls (for signal handlers).
- *
- * 'struct syscall' describes the system call; it may be NULL, however,
- * if we don't know about this particular system call yet.
- */
-static struct linux_syscall {
- struct syscall *sc;
- const char *name;
- int number;
- unsigned long args[5];
- int nargs; /* number of arguments -- *not* number of words! */
- char **s_args; /* the printable arguments */
-} fsc;
-
-/* Clear up and free parts of the fsc structure. */
-static __inline void
-clear_fsc(void) {
- if (fsc.s_args) {
- int i;
- for (i = 0; i < fsc.nargs; i++)
- if (fsc.s_args[i])
- free(fsc.s_args[i]);
- free(fsc.s_args);
- }
- memset(&fsc, 0, sizeof(fsc));
-}
-
-/*
- * Called when a process has entered a system call. nargs is the
- * number of words, not number of arguments (a necessary distinction
- * in some cases). Note that if the STOPEVENT() code in i386/i386/trap.c
- * is ever changed these functions need to keep up.
- */
-
-void
-i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
- char buf[32];
- struct reg regs;
- int syscall_num;
- int i;
- struct syscall *sc;
-
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDWR);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return;
- }
- cpid = trussinfo->pid;
- }
-
- clear_fsc();
- lseek(fd, 0L, 0);
- if (read(fd, &regs, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return;
- }
- syscall_num = regs.r_eax;
-
- fsc.number = syscall_num;
- fsc.name =
- (syscall_num < 0 || syscall_num > nsyscalls) ? NULL : linux_syscallnames[syscall_num];
- if (!fsc.name) {
- fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
- }
-
- if (fsc.name && (trussinfo->flags & FOLLOWFORKS)
- && ((!strcmp(fsc.name, "linux_fork")
- || !strcmp(fsc.name, "linux_vfork"))))
- {
- trussinfo->in_fork = 1;
- }
-
- if (nargs == 0)
- return;
-
- /*
- * Linux passes syscall arguments in registers, not
- * on the stack. Fortunately, we've got access to the
- * register set. Note that we don't bother checking the
- * number of arguments. And what does linux do for syscalls
- * that have more than five arguments?
- */
-
- fsc.args[0] = regs.r_ebx;
- fsc.args[1] = regs.r_ecx;
- fsc.args[2] = regs.r_edx;
- fsc.args[3] = regs.r_esi;
- fsc.args[4] = regs.r_edi;
-
- sc = get_syscall(fsc.name);
- if (sc) {
- fsc.nargs = sc->nargs;
- } else {
-#if DEBUG
- fprintf(trussinfo->outfile, "unknown syscall %s -- setting args to %d\n",
- fsc.name, nargs);
-#endif
- fsc.nargs = nargs;
- }
-
- fsc.s_args = malloc((1+fsc.nargs) * sizeof(char*));
- memset(fsc.s_args, 0, fsc.nargs * sizeof(char*));
- fsc.sc = sc;
-
- /*
- * At this point, we set up the system call arguments.
- * We ignore any OUT ones, however -- those are arguments that
- * are set by the system call, and so are probably meaningless
- * now. This doesn't currently support arguments that are
- * passed in *and* out, however.
- */
-
- if (fsc.name) {
-
-#if DEBUG
- fprintf(stderr, "syscall %s(", fsc.name);
-#endif
- for (i = 0; i < fsc.nargs; i++) {
-#if DEBUG
- fprintf(stderr, "0x%x%s",
- sc
- ? fsc.args[sc->args[i].offset]
- : fsc.args[i],
- i < (fsc.nargs - 1) ? "," : "");
-#endif
- if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args);
- }
- }
-#if DEBUG
- fprintf(stderr, ")\n");
-#endif
- }
-
-#if DEBUG
- fprintf(trussinfo->outfile, "\n");
-#endif
-
- /*
- * Some system calls should be printed out before they are done --
- * execve() and exit(), for example, never return. Possibly change
- * this to work for any system call that doesn't have an OUT
- * parameter?
- */
-
- if (!strcmp(fsc.name, "linux_execve") || !strcmp(fsc.name, "exit")) {
-
- /* XXX
- * This could be done in a more general
- * manner but it still wouldn't be very pretty.
- */
- if (!strcmp(fsc.name, "linux_execve")) {
- if ((trussinfo->flags & EXECVEARGS) == 0)
- if (fsc.s_args[1]) {
- free(fsc.s_args[1]);
- fsc.s_args[1] = NULL;
- }
- if ((trussinfo->flags & EXECVEENVS) == 0)
- if (fsc.s_args[2]) {
- free(fsc.s_args[2]);
- fsc.s_args[2] = NULL;
- }
- }
-
- print_syscall(trussinfo, fsc.name, fsc.nargs, fsc.s_args);
- fprintf(trussinfo->outfile, "\n");
- }
-
- return;
-}
-
-/*
- * Linux syscalls return negative errno's, we do positive and map them
- */
-const int bsd_to_linux_errno[] = {
- -0, -1, -2, -3, -4, -5, -6, -7, -8, -9,
- -10, -35, -12, -13, -14, -15, -16, -17, -18, -19,
- -20, -21, -22, -23, -24, -25, -26, -27, -28, -29,
- -30, -31, -32, -33, -34, -11,-115,-114, -88, -89,
- -90, -91, -92, -93, -94, -95, -96, -97, -98, -99,
- -100,-101,-102,-103,-104,-105,-106,-107,-108,-109,
- -110,-111, -40, -36,-112,-113, -39, -11, -87,-122,
- -116, -66, -6, -6, -6, -6, -6, -37, -38, -9,
- -6,
-};
-
-int
-i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
- char buf[32];
- struct reg regs;
- int retval;
- int i;
- int errorp;
- struct syscall *sc;
-
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDONLY);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return (-1);
- }
- cpid = trussinfo->pid;
- }
-
- lseek(fd, 0L, 0);
- if (read(fd, &regs, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "\n");
- return (-1);
- }
- retval = regs.r_eax;
- errorp = !!(regs.r_eflags & PSL_C);
-
- /*
- * This code, while simpler than the initial versions I used, could
- * stand some significant cleaning.
- */
-
- sc = fsc.sc;
- if (!sc) {
- for (i = 0; i < fsc.nargs; i++) {
- fsc.s_args[i] = malloc(12);
- sprintf(fsc.s_args[i], "0x%lx", fsc.args[i]);
- }
- } else {
- /*
- * Here, we only look for arguments that have OUT masked in --
- * otherwise, they were handled in the syscall_entry function.
- */
- for (i = 0; i < sc->nargs; i++) {
- char *temp;
- if (sc->args[i].type & OUT) {
- /*
- * If an error occurred, than don't bothe getting the data;
- * it may not be valid.
- */
- if (errorp) {
- temp = malloc(12);
- sprintf(temp, "0x%lx", fsc.args[sc->args[i].offset]);
- } else {
- temp = print_arg(Procfd, &sc->args[i], fsc.args);
- }
- fsc.s_args[i] = temp;
- }
- }
- }
-
- /*
- * It would probably be a good idea to merge the error handling,
- * but that complicates things considerably.
- */
- if (errorp) {
- for (i = 0; (size_t)i < sizeof(bsd_to_linux_errno) / sizeof(int); i++)
- if (retval == bsd_to_linux_errno[i])
- break;
- }
- print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp,
- errorp ? i : retval);
- clear_fsc();
-
- return (retval);
-}
diff --git a/usr.sbin/mount_nwfs/Makefile b/usr.sbin/mount_nwfs/Makefile
deleted file mode 100644
index 00fed85188b5..000000000000
--- a/usr.sbin/mount_nwfs/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-# $FreeBSD$
-
-PROG= mount_nwfs
-SRCS= mount_nwfs.c getmntopts.c
-MAN= mount_nwfs.8
-
-MOUNT= ${.CURDIR}/../mount
-CFLAGS+= -DNWFS -I${MOUNT}
-WARNS= 0
-
-.PATH: ${MOUNT}
-
-DPADD= ${LIBNCP} ${LIBIPX}
-LDADD= -lncp -lipx
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/mount_nwfs/mount_nwfs.8 b/usr.sbin/mount_nwfs/mount_nwfs.8
deleted file mode 100644
index afc68e014696..000000000000
--- a/usr.sbin/mount_nwfs/mount_nwfs.8
+++ /dev/null
@@ -1,230 +0,0 @@
-.\" $FreeBSD$
-.Dd October 14, 1999
-.Dt MOUNT_NWFS 8
-.Os
-.Sh NAME
-.Nm mount_nwfs
-.Nd mount NetWare volume from a NetWare file server
-.Sh SYNOPSIS
-.Nm
-.Op Fl Chv
-.Fl S Ar server
-.Fl U Ar user
-.Op Fl connection\ options
-.Fl V Ar volume
-.Op Fl M Ar mode
-.Op Fl c Ar case
-.Op Fl d Ar mode
-.Op Fl f Ar mode
-.Op Fl g Ar gid
-.Op Fl l Ar locale
-.Op Fl n Ar os2
-.Op Fl u Ar uid
-.Op Fl w Ar scheme
-.Ar node
-.Nm
-.Op Fl options
-.Ar /server:user/volume[/path]
-.Ar node
-.Sh DESCRIPTION
-The
-.Nm
-utility allows to mount volume from a NetWare server.
-It may use either
-existing connection or create new: if no usable connection was found
-it will try to establish a new one.
-Connection has count of references to it,
-so when last mount will be dismounted connection will be closed.
-It is
-possible to create connection without any mounts (but use it for them) with
-.Xr ncplogin 1 .
-.Pp
-Note two forms of command line.
-In the first form, server and user specified
-via
-.Fl S
-and
-.Fl U
-options respectively.
-In the second form server and user specified in
-.Ar special
-part of
-.Xr mount 8
-command line arguments (the
-.Fl S ,
-.Fl U
-and
-.Fl V
-options aren't used in this case).
-This allows use of
-.Xr fstab 5
-file (see
-.Sx EXAMPLES
-below).
-.Pp
-The options are:
-.Bl -tag -width indent
-.It Fl S Ar server
-Name of NetWare server to connect.
-For native IP you will need also
-.Fl A
-option.
-.It Fl U Ar user
-Name of user used in login sequence.
-.It Fl connection\ options
-See
-.Xr ncplogin 1
-for details.
-.It Fl V Ar volume
-Volume name to mount.
-Volume name can also be specified after all options and
-before
-.Ar mount-point .
-.It Ar node
-Path to mount volume.
-.It Fl c Ar case
-Select a
-.Ar case
-option which affects on name representation.
-.Ar Case
-can be one of the following:
-.Bl -tag -width "ValueXX"
-.It Em Value
-.Em Meaning
-.It l
-All existing file names converted to lower case.
-Newly created file gets a lower case under OS2 name space.
-This is the default when mounting volumes with DOS name space.
-.It L
-Same as 'l' but file system tries to be case insensitive.
-May not work well.
-.It n
-No case conversion is performed.
-.Em Warning !
-Use this option with DOS name space only as a last resort,
-because creating a lower case name in the DOS name space
-can lead to unpredictable results.
-This is the default when mounting volumes with OS2 name space.
-.It u
-All existing file names converted to upper case.
-Newly created file gets an upper case under OS2 name space.
-.It U
-Same as 'u' but file system tries to be case insensitive.
-May not work well.
-.El
-.It Fl f Ar mode , Fl d Ar mode
-Specify permissions that should be assigned to files and directories.
-The values must be specified as octal numbers.
-Default value for the file mode
-is taken from mount point, default value for the dir mode adds execute
-permission where the file mode gives read permission.
-.Pp
-Note that these permissions can differ from the rights granted by NetWare
-server.
-.It Fl n Ar namespace
-Don't use
-.Ar namespace .
-Currently only
-.Ar OS2
-can be here.
-.It Fl v
-Print version number.
-.It Fl u Ar uid , Fl g Ar gid
-User id and group id assigned to files.
-The default is owner and group id from
-directory where volume is mounted.
-.It Fl l Ar locale
-Set the locale for case conversion.
-By default
-.Nm
-tries to use an environment variable
-.Ev LC_* .
-.It Fl w Ar scheme
-Select a
-.Ar scheme
-used to convert file names between NetWare and
-.Fx .
-Supported conversion schemes are:
-.Bl -tag -width ".Cm koi2cp866"
-.It Cm asis
-Characters passed as is without any alteration.
-.It Cm koi2cp866
-koi8-r <-> CP866
-.It Cm se
-Suits for setups used in Sweden.
-.El
-.It Fl M Ar mode
-See
-.Xr ncplogin 1
-for details.
-If this option is omitted, connection permissions
-assumed the same as directory mode
-.Pq Fl d
-option.
-.El
-.Sh FILES
-.Bl -tag -width /var/log/wtmp -compact
-.It Pa ~/.nwfsrc
-keeps static parameters for connections and other information.
-See
-.Pa /usr/share/examples/nwclient/dot.nwfsrc
-for details.
-.El
-.Sh NOTES
-Before any NCP connection can be established kernel must be configured
-for IPX support, IPXrouted and KLD nwfs.ko should be loaded.
-.Sh EXAMPLES
-Next examples illustrates how to connect to NetWare server
-.Em nwserv
-as user
-.Em GUEST
-and mount volumes
-.Em SYS
-and
-.Em VOL1 :
-.Bd -literal -offset indent
-mount_nwfs -S nwserv -U guest -V sys /nw/s1/sys
-mount_nwfs /nwserv:guest/sys /nw/s1/sys
-mount -t nwfs /nwserv:guest/vol1 /nw/s1/vol1
-mount -t nwfs /nwserv:boris/sys/home/boris /home/boris/nw/home
-.Ed
-.Pp
-The last example mounts only subdirectory on a volume and equivalent
-to NetWare 'map root' command.
-.Pp
-It is possible to use
-.Xr fstab 5
-for nwfs mounts:
-.Bd -literal -offset indent
-/nwserv:guest/sys /nw/s1/sys nwfs rw,noauto 0 0
-/nwserv:guest/vol1 /nw/s1/vol2 nwfs rw,noauto 0 0
-.Ed
-.Sh HISTORY
-The
-.Nm
-utility first appeared in
-.Fx 4.0 .
-.Sh BUGS
-to number a few
-.Sh CREDITS
-In development of NetWare client for
-.Fx ,
-the following sources were used:
-.Pp
-Documentation from NetWare NDK.
-.Pp
-Ncpfs for Linux - written by
-.An Volker Lendecke Aq lendecke@math.uni\-goettingen.de .
-He granted me permission to publish parts of his code under
-.Bx Ns -style
-license,
-.Pp
-"Interrupt List" from
-.An Ralf Brown ,
-.Pp
-Many files from
-.Pa /sys
-directory.
-.Sh AUTHORS
-.An Boris Popov Aq bp@butya.kz ,
-.Aq rbp@chat.ru
diff --git a/usr.sbin/mount_nwfs/mount_nwfs.c b/usr.sbin/mount_nwfs/mount_nwfs.c
deleted file mode 100644
index af00071b9274..000000000000
--- a/usr.sbin/mount_nwfs/mount_nwfs.c
+++ /dev/null
@@ -1,365 +0,0 @@
-/*
- * Copyright (c) 1999, Boris Popov
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Boris Popov.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY 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$
- */
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/errno.h>
-#include <sys/mount.h>
-#include <sys/sysctl.h>
-#include <machine/cpu.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <pwd.h>
-#include <grp.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <err.h>
-#include <sysexits.h>
-#include <time.h>
-
-#include <netncp/ncp_lib.h>
-#include <netncp/ncp_rcfile.h>
-#include <fs/nwfs/nwfs_mount.h>
-#include "mntopts.h"
-
-#define NWFS_VFSNAME "nwfs"
-
-static char mount_point[MAXPATHLEN + 1];
-static void usage(void);
-static int parsercfile(struct ncp_conn_loginfo *li, struct nwfs_args *mdata);
-
-static struct mntopt mopts[] = {
- MOPT_STDOPTS,
- { NULL }
-};
-
-static int
-parsercfile(struct ncp_conn_loginfo *li, struct nwfs_args *mdata) {
- return 0;
-}
-
-int
-main(int argc, char *argv[]) {
- NWCONN_HANDLE connHandle;
- struct nwfs_args mdata;
- struct ncp_conn_loginfo li;
- struct stat st;
- struct nw_entry_info einfo;
- struct tm *tm;
- time_t ltime;
- int opt, error, mntflags, nlsopt, wall_clock, len;
- int mib[2];
- char *p, *p1, tmp[1024];
- u_char *pv;
-
- if (argc < 2)
- usage();
- if (argc == 2) {
- if (strcmp(argv[1], "-h") == 0) {
- usage();
- } else if (strcmp(argv[1], "-v") == 0) {
- errx(EX_OK, "version %d.%d.%d", NWFS_VERSION / 100000,
- (NWFS_VERSION % 10000) / 1000,
- (NWFS_VERSION % 1000) / 100);
- }
- }
-
- if(ncp_initlib()) exit(1);
-
- mntflags = error = 0;
- bzero(&mdata,sizeof(mdata));
- mdata.uid = mdata.gid = -1;
- nlsopt = 0;
-
- if (ncp_li_init(&li, argc, argv)) return 1;
- /*
- * A little bit weird, but I should figure out which server/user to use
- * _before_ reading .rc file
- */
- if (argc >= 3 && argv[argc-1][0] != '-' && argv[argc-2][0] != '-' &&
- argv[argc-2][0] == '/') {
- p = argv[argc-2];
- error = 1;
- do {
- if (*p++ != '/') break;
- p1 = tmp;
- while (*p != ':' && *p != 0) *p1++ = *p++;
- if (*p++ == 0) break;
- *p1 = 0;
- if (ncp_li_setserver(&li, tmp)) break;
- p1 = tmp;
- while (*p != '/' && *p != 0) *p1++ = *p++;
- if (*p++ == 0) break;
- *p1 = 0;
- if (ncp_li_setuser(&li, tmp)) break;
- p1 = tmp;
- while (*p != '/' && *p != 0) *p1++ = *p++;
- *p1 = 0;
- if (strlen(tmp) > NCP_VOLNAME_LEN) {
- warnx("volume name too long: %s", tmp);
- break;
- }
- ncp_str_upper(strcpy(mdata.mounted_vol,tmp));
- if (*p == '/')
- p++;
- p1 = mdata.root_path + 2;
- pv = mdata.root_path + 1;
- for(;*p;) {
- *pv = 0;
- while (*p != '/' && *p) {
- *p1++ = *p++;
- (*pv)++;
- }
- if (*pv) {
- ncp_nls_mem_u2n(pv + 1, pv + 1, *pv);
- pv += (*pv) + 1;
- mdata.root_path[0]++;
- }
- if (*p++ == 0) break;
- p1++;
- }
- error = 0;
- } while(0);
- if (error)
- errx(EX_DATAERR,
- "an error occurred while parsing '%s'",
- argv[argc - 2]);
- }
- if (ncp_li_readrc(&li)) return 1;
- if (ncp_rc) {
- parsercfile(&li,&mdata);
- rc_close(ncp_rc);
- }
- while ((opt = getopt(argc, argv, STDPARAM_OPT"V:c:d:f:g:l:n:o:u:w:")) != -1) {
- switch (opt) {
- case STDPARAM_ARGS:
- if (ncp_li_arg(&li, opt, optarg)) {
- return 1;
- }
- break;
- case 'V':
- if (strlen(optarg) > NCP_VOLNAME_LEN)
- errx(EX_DATAERR, "volume too long: %s", optarg);
- ncp_str_upper(strcpy(mdata.mounted_vol,optarg));
- break;
- case 'u': {
- struct passwd *pwd;
-
- pwd = isdigit(optarg[0]) ?
- getpwuid(atoi(optarg)) : getpwnam(optarg);
- if (pwd == NULL)
- errx(EX_NOUSER, "unknown user '%s'", optarg);
- mdata.uid = pwd->pw_uid;
- break;
- }
- case 'g': {
- struct group *grp;
-
- grp = isdigit(optarg[0]) ?
- getgrgid(atoi(optarg)) : getgrnam(optarg);
- if (grp == NULL)
- errx(EX_NOUSER, "unknown group '%s'", optarg);
- mdata.gid = grp->gr_gid;
- break;
- }
- case 'd':
- errno = 0;
- mdata.dir_mode = strtol(optarg, &p, 8);
- if (errno || *p != 0)
- errx(EX_DATAERR, "invalid value for directory mode");
- break;
- case 'f':
- errno = 0;
- mdata.file_mode = strtol(optarg, &p, 8);
- if (errno || *p != 0)
- errx(EX_DATAERR, "invalid value for file mode");
- break;
- case '?':
- usage();
- /*NOTREACHED*/
- case 'n': {
- char *inp, *nsp;
-
- nsp = inp = optarg;
- while ((nsp = strsep(&inp, ",;:")) != NULL) {
- if (strcasecmp(nsp, "OS2") == 0)
- mdata.flags |= NWFS_MOUNT_NO_OS2;
- else if (strcasecmp(nsp, "LONG") == 0)
- mdata.flags |= NWFS_MOUNT_NO_LONG;
- else if (strcasecmp(nsp, "NFS") == 0)
- mdata.flags |= NWFS_MOUNT_NO_NFS;
- else
- errx(EX_DATAERR, "unknown namespace '%s'", nsp);
- }
- break;
- };
- case 'l':
- if (ncp_nls_setlocale(optarg) != 0) return 1;
- mdata.flags |= NWFS_MOUNT_HAVE_NLS;
- break;
- case 'o':
- getmntopts(optarg, mopts, &mntflags, 0);
- break;
- case 'c':
- switch (optarg[0]) {
- case 'l':
- nlsopt |= NWHP_LOWER;
- break;
- case 'u':
- nlsopt |= NWHP_UPPER;
- break;
- case 'n':
- nlsopt |= NWHP_LOWER | NWHP_UPPER;
- break;
- case 'L':
- nlsopt |= NWHP_LOWER | NWHP_NOSTRICT;
- break;
- case 'U':
- nlsopt |= NWHP_UPPER | NWHP_NOSTRICT;
- break;
- default:
- errx(EX_DATAERR, "invalid suboption '%c' for -c",
- optarg[0]);
- }
- break;
- case 'w':
- if (ncp_nls_setrecodebyname(optarg) != 0)
- return 1;
- mdata.flags |= NWFS_MOUNT_HAVE_NLS;
- break;
- default:
- usage();
- }
- }
-
- if (optind == argc - 2) {
- optind++;
- } else if (mdata.mounted_vol[0] == 0)
- errx(EX_USAGE, "volume name should be specified");
-
- if (optind != argc - 1)
- usage();
- realpath(argv[optind], mount_point);
-
- if (stat(mount_point, &st) == -1)
- err(EX_OSERR, "could not find mount point %s", mount_point);
- if (!S_ISDIR(st.st_mode)) {
- errno = ENOTDIR;
- err(EX_OSERR, "can't mount on %s", mount_point);
- }
- if (ncp_geteinfo(mount_point, &einfo) == 0)
- errx(EX_OSERR, "can't mount on %s twice", mount_point);
-
- if (mdata.uid == -1) {
- mdata.uid = st.st_uid;
- }
- if (mdata.gid == -1) {
- mdata.gid = st.st_gid;
- }
- if (mdata.file_mode == 0 ) {
- mdata.file_mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
- }
- if (mdata.dir_mode == 0) {
- mdata.dir_mode = mdata.file_mode;
- if ((mdata.dir_mode & S_IRUSR) != 0)
- mdata.dir_mode |= S_IXUSR;
- if ((mdata.dir_mode & S_IRGRP) != 0)
- mdata.dir_mode |= S_IXGRP;
- if ((mdata.dir_mode & S_IROTH) != 0)
- mdata.dir_mode |= S_IXOTH;
- }
- if (li.access_mode == 0) {
- li.access_mode = mdata.dir_mode;
- }
-/* if (mdata.flags & NWFS_MOUNT_HAVE_NLS) {*/
- mdata.nls = ncp_nls;
-/* }*/
- mdata.nls.opt = nlsopt;
-
- mib[0] = CTL_MACHDEP;
- mib[1] = CPU_WALLCLOCK;
- len = sizeof(wall_clock);
- if (sysctl(mib, 2, &wall_clock, &len, NULL, 0) == -1)
- err(EX_OSERR, "get wall_clock");
- if (wall_clock == 0) {
- time(&ltime);
- tm = localtime(&ltime);
- mdata.tz = -(tm->tm_gmtoff / 60);
- }
-
- error = ncp_li_check(&li);
- if (error)
- return 1;
- li.opt |= NCP_OPT_WDOG;
- /* well, now we can try to login, or use already established connection */
- error = ncp_li_login(&li, &connHandle);
- if (error) {
- ncp_error("cannot login to server %s", error, li.server);
- exit(1);
- }
- error = ncp_conn2ref(connHandle, &mdata.connRef);
- if (error) {
- ncp_error("could not convert handle to reference", error);
- ncp_disconnect(connHandle);
- exit(1);
- }
- strcpy(mdata.mount_point,mount_point);
- mdata.version = NWFS_VERSION;
- error = mount(NWFS_VFSNAME, mdata.mount_point, mntflags, (void*)&mdata);
- if (error) {
- ncp_error("mount error: %s", error, mdata.mount_point);
- ncp_disconnect(connHandle);
- exit(1);
- }
- /*
- * I'm leave along my handle, but kernel should keep own ...
- */
- ncp_disconnect(connHandle);
- /* we are done ?, impossible ... */
- return 0;
-}
-
-static void
-usage(void)
-{
- fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
- "usage: mount_nwfs [-Chv] -S server -U user [-connection options]",
- " -V volume [-M mode] [-c case] [-d mode] [-f mode]",
- " [-g gid] [-l locale] [-n os2] [-u uid] [-w scheme]",
- " node",
- " mount_nwfs [-options] /server:user/volume[/path] node");
-
- exit (1);
-}
diff --git a/usr.sbin/mount_portalfs/Makefile b/usr.sbin/mount_portalfs/Makefile
deleted file mode 100644
index 90161dc27d5d..000000000000
--- a/usr.sbin/mount_portalfs/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-# From: @(#)Makefile 8.3 (Berkeley) 3/27/94
-# $FreeBSD$
-
-PROG= mount_portalfs
-SRCS= mount_portalfs.c activate.c conf.c getmntopts.c pt_conf.c \
- pt_exec.c pt_file.c pt_tcp.c pt_tcplisten.c
-MAN= mount_portalfs.8
-
-MOUNT= ${.CURDIR}/../mount
-CFLAGS+=-I${MOUNT}
-WARNS= 0
-
-.PATH: ${MOUNT}
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/mount_portalfs/activate.c b/usr.sbin/mount_portalfs/activate.c
deleted file mode 100644
index 6143620b365d..000000000000
--- a/usr.sbin/mount_portalfs/activate.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- * All rights reserved.
- *
- * This code is derived from software donated to Berkeley by
- * Jan-Simon Pendry.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)activate.c 8.3 (Berkeley) 4/28/95
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/syslog.h>
-#include <sys/uio.h>
-
-#include "portald.h"
-
-/*
- * Scan the providers list and call the
- * appropriate function.
- */
-static int activate_argv(pcr, key, v, so, fdp)
-struct portal_cred *pcr;
-char *key;
-char **v;
-int so;
-int *fdp;
-{
- provider *pr;
-
- for (pr = providers; pr->pr_match; pr++)
- if (strcmp(v[0], pr->pr_match) == 0)
- return ((*pr->pr_func)(pcr, key, v, so, fdp));
-
- return (ENOENT);
-}
-
-static int get_request(so, pcr, key, klen)
-int so;
-struct portal_cred *pcr;
-char *key;
-int klen;
-{
- struct iovec iov[2];
- struct msghdr msg;
- int n;
-
- iov[0].iov_base = (caddr_t) pcr;
- iov[0].iov_len = sizeof(*pcr);
- iov[1].iov_base = key;
- iov[1].iov_len = klen;
-
- memset(&msg, 0, sizeof(msg));
- msg.msg_iov = iov;
- msg.msg_iovlen = 2;
-
- n = recvmsg(so, &msg, 0);
- if (n < 0)
- return (errno);
-
- if (n <= sizeof(*pcr))
- return (EINVAL);
-
- n -= sizeof(*pcr);
- key[n] = '\0';
-
- return (0);
-}
-
-static void send_reply(so, fd, error)
-int so;
-int fd;
-int error;
-{
- int n;
- struct iovec iov;
- struct msghdr msg;
- union {
- struct cmsghdr cmsg;
- char control[CMSG_SPACE(sizeof(int))];
- } ctl;
-
- /*
- * Line up error code. Don't worry about byte ordering
- * because we must be sending to the local machine.
- */
- iov.iov_base = (caddr_t) &error;
- iov.iov_len = sizeof(error);
-
- /*
- * Build a msghdr
- */
- memset(&msg, 0, sizeof(msg));
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
-
- /*
- * If there is a file descriptor to send then
- * construct a suitable rights control message.
- */
- if (fd >= 0) {
- ctl.cmsg.cmsg_len = CMSG_LEN(sizeof(int));
- ctl.cmsg.cmsg_level = SOL_SOCKET;
- ctl.cmsg.cmsg_type = SCM_RIGHTS;
- *((int *)CMSG_DATA(&ctl.cmsg)) = fd;
- msg.msg_control = (caddr_t) &ctl;
- msg.msg_controllen = ctl.cmsg.cmsg_len;
- }
-
- /*
- * Send to kernel...
- */
- if ((n = sendmsg(so, &msg, 0)) < 0)
- syslog(LOG_ERR, "send: %s", strerror(errno));
-#ifdef DEBUG
- fprintf(stderr, "sent %d bytes\n", n);
-#endif
- sleep(1); /*XXX*/
-#ifdef notdef
- if (shutdown(so, 2) < 0)
- syslog(LOG_ERR, "shutdown: %s", strerror(errno));
-#endif
- /*
- * Throw away the open file descriptor
- */
- (void) close(fd);
-}
-
-void activate(q, so)
-qelem *q;
-int so;
-{
- struct portal_cred pcred;
- char key[MAXPATHLEN+1];
- int error;
- char **v;
- int fd = -1;
-
- /*
- * Read the key from the socket
- */
- error = get_request(so, &pcred, key, sizeof(key));
- if (error) {
- syslog(LOG_ERR, "activate: recvmsg: %s", strerror(error));
- goto drop;
- }
-
-#ifdef DEBUG
- fprintf(stderr, "lookup key %s\n", key);
-#endif
-
- /*
- * Find a match in the configuration file
- */
- v = conf_match(q, key);
-
- /*
- * If a match existed, then find an appropriate portal
- * otherwise simply return ENOENT.
- */
- if (v) {
- error = activate_argv(&pcred, key, v, so, &fd);
- if (error)
- fd = -1;
- else if (fd < 0)
- error = -1;
- } else {
- error = ENOENT;
- }
-
- if (error >= 0)
- send_reply(so, fd, error);
-
-drop:;
- close(so);
-}
diff --git a/usr.sbin/mount_portalfs/conf.c b/usr.sbin/mount_portalfs/conf.c
deleted file mode 100644
index d5833e4b2136..000000000000
--- a/usr.sbin/mount_portalfs/conf.c
+++ /dev/null
@@ -1,340 +0,0 @@
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- * All rights reserved.
- *
- * This code is derived from software donated to Berkeley by
- * Jan-Simon Pendry.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)conf.c 8.2 (Berkeley) 3/27/94
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-#include <errno.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <regex.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/syslog.h>
-
-#include "portald.h"
-
-#define ALLOC(ty) (xmalloc(sizeof(ty)))
-
-typedef struct path path;
-struct path {
- qelem p_q; /* 2-way linked list */
- int p_lno; /* Line number of this record */
- char *p_args; /* copy of arg string (malloc) */
- char *p_key; /* Pathname to match (also p_argv[0]) */
- regex_t p_rx; /* RE to match against pathname () */
- int p_rxvalid; /* non-zero if valid regular expression */
- int p_argc; /* number of elements in arg string */
- char **p_argv; /* argv[] pointers into arg string (malloc) */
-};
-
-static char *conf_file; /* XXX for regerror */
-static path *curp; /* XXX for regerror */
-
-/*
- * Add an element to a 2-way list,
- * just after (pred)
- */
-static void ins_que(elem, pred)
-qelem *elem, *pred;
-{
- qelem *p = pred->q_forw;
- elem->q_back = pred;
- elem->q_forw = p;
- pred->q_forw = elem;
- p->q_back = elem;
-}
-
-/*
- * Remove an element from a 2-way list
- */
-static void rem_que(elem)
-qelem *elem;
-{
- qelem *p = elem->q_forw;
- qelem *p2 = elem->q_back;
- p2->q_forw = p;
- p->q_back = p2;
-}
-
-/*
- * Error checking malloc
- */
-static void *xmalloc(siz)
-unsigned siz;
-{
- void *p = malloc(siz);
- if (p)
- return (p);
- syslog(LOG_ALERT, "malloc: failed to get %d bytes", siz);
- exit(1);
-}
-
-/*
- * Insert the path in the list.
- * If there is already an element with the same key then
- * the *second* one is ignored (return 0). If the key is
- * not found then the path is added to the end of the list
- * and 1 is returned.
- */
-static int pinsert(p0, q0)
-path *p0;
-qelem *q0;
-{
- qelem *q;
-
- if (p0->p_argc == 0)
- return (0);
-
- for (q = q0->q_forw; q != q0; q = q->q_forw) {
- path *p = (path *) q;
- if (strcmp(p->p_key, p0->p_key) == 0)
- return (0);
- }
- ins_que(&p0->p_q, q0->q_back);
- return (1);
-
-}
-
-static path *palloc(cline, lno)
-char *cline;
-int lno;
-{
- int c;
- char *s;
- char *key;
- path *p;
- char **ap;
-
- /*
- * Implement comment chars
- */
- s = strchr(cline, '#');
- if (s)
- *s = 0;
-
- /*
- * Do a pass through the string to count the number
- * of arguments
- */
- c = 0;
- key = strdup(cline);
- for (s = key; s != NULL; ) {
- char *val;
- while ((val = strsep(&s, " \t\n")) != NULL && *val == '\0')
- ;
- if (val)
- c++;
- }
- c++;
- free(key);
-
- if (c <= 1)
- return (0);
-
- /*
- * Now do another pass and generate a new path structure
- */
- p = ALLOC(path);
- p->p_argc = 0;
- p->p_argv = xmalloc(c * sizeof(char *));
- p->p_args = strdup(cline);
- ap = p->p_argv;
- for (s = p->p_args; s != NULL; ) {
- char *val;
- while ((val = strsep(&s, " \t\n")) != NULL && *val == '\0')
- ;
- if (val) {
- *ap++ = val;
- p->p_argc++;
- }
- }
- *ap = 0;
-
-#ifdef DEBUG
- for (c = 0; c < p->p_argc; c++)
- printf("%sv[%d] = %s\n", c?"\t":"", c, p->p_argv[c]);
-#endif
-
- p->p_key = p->p_argv[0];
- if (strpbrk(p->p_key, RE_CHARS)) {
- int val;
-
- curp = p; /* XXX */
- val = regcomp(&p->p_rx, p->p_key, REG_EXTENDED | REG_NOSUB);
- if (val) {
- char errbuf[_POSIX2_LINE_MAX];
- regerror(val, &p->p_rx, errbuf, sizeof errbuf);
- syslog(LOG_ERR, "%s:%d: regcomp %s: %s",
- conf_file, curp->p_lno, curp->p_key, errbuf);
- regfree(&p->p_rx);
- p->p_rxvalid = 0;
- } else {
- p->p_rxvalid = 1;
- }
- curp = 0; /* XXX */
- } else {
- p->p_rxvalid = 0;
- }
- p->p_lno = lno;
-
- return (p);
-}
-
-/*
- * Free a path structure
- */
-static void pfree(p)
-path *p;
-{
- free(p->p_args);
- if (p->p_rxvalid) {
- regfree(&p->p_rx);
- }
- free((char *) p->p_argv);
- free((char *) p);
-}
-
-/*
- * Discard all currently held path structures on q0.
- * and add all the ones on xq.
- */
-static void preplace(q0, xq)
-qelem *q0;
-qelem *xq;
-{
- /*
- * While the list is not empty,
- * take the first element off the list
- * and free it.
- */
- while (q0->q_forw != q0) {
- qelem *q = q0->q_forw;
- rem_que(q);
- pfree((path *) q);
- }
- while (xq->q_forw != xq) {
- qelem *q = xq->q_forw;
- rem_que(q);
- ins_que(q, q0);
- }
-}
-
-/*
- * Read the lines from the configuration file and
- * add them to the list of paths.
- */
-static void readfp(q0, fp)
-qelem *q0;
-FILE *fp;
-{
- char cline[LINE_MAX];
- int nread = 0;
- qelem q;
-
- /*
- * Make a new empty list.
- */
- q.q_forw = q.q_back = &q;
-
- /*
- * Read the lines from the configuration file.
- */
- while (fgets(cline, sizeof(cline), fp)) {
- path *p = palloc(cline, nread+1);
- if (p && !pinsert(p, &q))
- pfree(p);
- nread++;
- }
-
- /*
- * If some records were read, then throw
- * away the old list and replace with the
- * new one.
- */
- if (nread)
- preplace(q0, &q);
-}
-
-/*
- * Read the configuration file (conf) and replace
- * the existing path list with the new version.
- * If the file is not readable, then no changes take place
- */
-void conf_read(q, conf)
-qelem *q;
-char *conf;
-{
- FILE *fp = fopen(conf, "r");
- if (fp) {
- conf_file = conf; /* XXX */
- readfp(q, fp);
- conf_file = 0; /* XXX */
- (void) fclose(fp);
- } else {
- syslog(LOG_ERR, "open config file \"%s\": %s", conf, strerror(errno));
- }
-}
-
-
-char **conf_match(q0, key)
-qelem *q0;
-char *key;
-{
- qelem *q;
-
- for (q = q0->q_forw; q != q0; q = q->q_forw) {
- path *p = (path *) q;
- if (p->p_rxvalid) {
- if (!regexec(&p->p_rx, key, 0, 0, 0)) {
- return p->p_argv + 1;
- }
- } else {
- if (strncmp(p->p_key, key, strlen(p->p_key)) == 0)
- return (p->p_argv+1);
- }
- }
-
- return (0);
-}
diff --git a/usr.sbin/mount_portalfs/mount_portalfs.8 b/usr.sbin/mount_portalfs/mount_portalfs.8
deleted file mode 100644
index b7474667f922..000000000000
--- a/usr.sbin/mount_portalfs/mount_portalfs.8
+++ /dev/null
@@ -1,152 +0,0 @@
-.\"
-.\" Copyright (c) 1993, 1994
-.\" The Regents of the University of California. All rights reserved.
-.\" All rights reserved.
-.\"
-.\" This code is derived from software donated to Berkeley by
-.\" Jan-Simon Pendry.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)mount_portal.8 8.3 (Berkeley) 3/27/94
-.\" $FreeBSD$
-.\"
-.Dd March 27, 1994
-.Dt MOUNT_PORTALFS 8
-.Os
-.Sh NAME
-.Nm mount_portalfs
-.Nd mount the portal daemon
-.Sh SYNOPSIS
-.Nm
-.Op Fl o Ar options
-.Ar /etc/portal.conf
-.Ar mount_point
-.Sh DESCRIPTION
-The
-.Nm
-utility attaches an instance of the portal daemon
-to the global file system namespace.
-The conventional mount point is
-.Pa /p .
-.\" .PA /dev .
-This command is normally executed by
-.Xr mount 8
-at boot time.
-.Pp
-The options are as follows:
-.Bl -tag -width indent
-.It Fl o
-Options are specified with a
-.Fl o
-flag followed by a comma separated string of options.
-See the
-.Xr mount 8
-man page for possible options and their meanings.
-.El
-.Pp
-The portal daemon provides an
-.Em open
-service.
-Objects opened under the portal mount point are
-dynamically created by the portal daemon according
-to rules specified in the named configuration file.
-Using this mechanism allows descriptors such as sockets
-to be made available in the file system namespace.
-.Pp
-The portal daemon works by being passed the full pathname
-of the object being opened.
-The daemon creates an appropriate descriptor according
-to the rules in the configuration file, and then passes the descriptor back
-to the calling process as the result of the open system call.
-.Sh NAMESPACE
-By convention, the portal daemon divides the namespace into sub-namespaces,
-each of which handles objects of a particular type.
-.Pp
-The following sub-namespaces are currently implemented:
-.Pa tcplisten ,
-.Pa tcp
-and
-.Pa fs .
-The
-.Pa tcplisten
-namespace takes a slash separated hostname and port and creates a TCP/IP
-socket bound to the given hostname-port pair.
-The hostname may be
-specified as "ANY" to allow any other host to connect to the socket.
-A
-port number of 0 will dynamically allocate a port, this can be
-discovered by calling
-.Xr getsockname 2
-with the returned file descriptor.
-Privileged ports can only be bound to
-by the super-user.
-The
-.Pa tcp
-namespace takes a hostname and a port (slash separated) and
-creates an open TCP/IP connection.
-The
-.Pa fs
-namespace opens the named file, starting back at the root directory.
-This can be used to provide a controlled escape path from
-a chrooted environment.
-.Sh "CONFIGURATION FILE"
-The configuration file contains a list of rules.
-Each rule takes one line and consists of two or more
-whitespace separated fields.
-A hash (``#'') character causes the remainder of a line to
-be ignored. Blank lines are ignored.
-.Pp
-The first field is a pathname prefix to match
-against the requested pathname.
-If a match is found, the second field
-tells the daemon what type of object to create.
-Subsequent fields are passed to the creation function.
-.Bd -literal
-# @(#)portal.conf 5.1 (Berkeley) 7/13/92
-tcplisten/ tcplisten tcplisten/
-tcp/ tcp tcp/
-fs/ file fs/
-.Ed
-.Sh FILES
-.Bl -tag -width /p/* -compact
-.It Pa /p/*
-.El
-.Sh SEE ALSO
-.Xr mount 2 ,
-.Xr unmount 2 ,
-.Xr fstab 5 ,
-.Xr mount 8
-.Sh CAVEATS
-This file system may not be NFS-exported.
-.Sh HISTORY
-The
-.Nm
-utility first appeared in
-.Bx 4.4 .
diff --git a/usr.sbin/mount_portalfs/mount_portalfs.c b/usr.sbin/mount_portalfs/mount_portalfs.c
deleted file mode 100644
index baad22fffa8a..000000000000
--- a/usr.sbin/mount_portalfs/mount_portalfs.c
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * Copyright (c) 1992, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software donated to Berkeley by
- * Jan-Simon Pendry.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1992, 1993, 1994\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)mount_portal.c 8.6 (Berkeley) 4/26/95";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/stat.h>
-#include <sys/syslog.h>
-#include <sys/mount.h>
-
-#include <err.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sysexits.h>
-#include <unistd.h>
-
-#include "mntopts.h"
-#include "pathnames.h"
-#include "portald.h"
-
-struct mntopt mopts[] = {
- MOPT_STDOPTS,
- { NULL }
-};
-
-static void usage(void) __dead2;
-
-static sig_atomic_t readcf; /* Set when SIGHUP received */
-
-static void sighup(sig)
-int sig;
-{
- readcf ++;
-}
-
-static void sigchld(sig)
-int sig;
-{
- pid_t pid;
-
- while ((pid = waitpid((pid_t) -1, (int *) 0, WNOHANG)) > 0)
- ;
- /* wrtp - waitpid _doesn't_ return 0 when no children! */
-#ifdef notdef
- if (pid < 0 && errno != ECHILD)
- syslog(LOG_WARNING, "waitpid: %s", strerror(errno));
-#endif
-}
-
-int
-main(argc, argv)
- int argc;
- char *argv[];
-{
- struct portal_args args;
- struct sockaddr_un un;
- char *conf;
- char mountpt[MAXPATHLEN];
- int mntflags = 0;
- char tag[32];
- mode_t um;
-
- qelem q;
- int rc;
- int so;
- int error = 0;
-
- /*
- * Crack command line args
- */
- int ch;
-
- while ((ch = getopt(argc, argv, "o:")) != -1) {
- switch (ch) {
- case 'o':
- getmntopts(optarg, mopts, &mntflags, 0);
- break;
- default:
- error = 1;
- break;
- }
- }
-
- if (optind != (argc - 2))
- error = 1;
-
- if (error)
- usage();
-
- /*
- * Get config file and mount point
- */
- conf = argv[optind];
-
- /* resolve the mountpoint with realpath(3) */
- (void)checkpath(argv[optind+1], mountpt);
-
- /*
- * Construct the listening socket
- */
- un.sun_family = AF_UNIX;
- if (sizeof(_PATH_TMPPORTAL) >= sizeof(un.sun_path)) {
- errx(EX_SOFTWARE, "portal socket name too long");
- }
- strcpy(un.sun_path, _PATH_TMPPORTAL);
- mktemp(un.sun_path);
- un.sun_len = strlen(un.sun_path);
-
- so = socket(AF_UNIX, SOCK_STREAM, 0);
- if (so < 0) {
- err(EX_OSERR, "socket");
- }
- um = umask(077);
- (void) unlink(un.sun_path);
- if (bind(so, (struct sockaddr *) &un, sizeof(un)) < 0)
- err(1, NULL);
-
- (void) unlink(un.sun_path);
- (void) umask(um);
-
- (void) listen(so, 5);
-
- args.pa_socket = so;
- sprintf(tag, "portal:%d", getpid());
- args.pa_config = tag;
-
- rc = mount("portalfs", mountpt, mntflags, &args);
- if (rc < 0)
- err(1, NULL);
-
- /*
- * Everything is ready to go - now is a good time to fork
- */
-#ifndef DEBUG
- daemon(0, 0);
-#endif
-
- /*
- * Start logging (and change name)
- */
- openlog("portald", LOG_CONS|LOG_PID, LOG_DAEMON);
-
- q.q_forw = q.q_back = &q;
- readcf = 1;
-
- signal(SIGCHLD, sigchld);
- signal(SIGHUP, sighup);
-
- /*
- * Just loop waiting for new connections and activating them
- */
- for (;;) {
- struct sockaddr_un un2;
- int len2 = sizeof(un2);
- int so2;
- pid_t pid;
- fd_set fdset;
- int rc;
-
- /*
- * Check whether we need to re-read the configuration file
- */
- if (readcf) {
-#ifdef DEBUG
- printf ("re-reading configuration file\n");
-#endif
- readcf = 0;
- conf_read(&q, conf);
- continue;
- }
-
- /*
- * Accept a new connection
- * Will get EINTR if a signal has arrived, so just
- * ignore that error code
- */
- FD_ZERO(&fdset);
- FD_SET(so, &fdset);
- rc = select(so+1, &fdset, (fd_set *) 0, (fd_set *) 0, (struct timeval *) 0);
- if (rc < 0) {
- if (errno == EINTR)
- continue;
- syslog(LOG_ERR, "select: %s", strerror(errno));
- exit(EX_OSERR);
- }
- if (rc == 0)
- break;
- so2 = accept(so, (struct sockaddr *) &un2, &len2);
- if (so2 < 0) {
- /*
- * The unmount function does a shutdown on the socket
- * which will generated ECONNABORTED on the accept.
- */
- if (errno == ECONNABORTED)
- break;
- if (errno != EINTR) {
- syslog(LOG_ERR, "accept: %s", strerror(errno));
- exit(EX_OSERR);
- }
- continue;
- }
-
- /*
- * Now fork a new child to deal with the connection
- */
- eagain:;
- switch (pid = fork()) {
- case -1:
- if (errno == EAGAIN) {
- sleep(1);
- goto eagain;
- }
- syslog(LOG_ERR, "fork: %s", strerror(errno));
- break;
- case 0:
- (void) close(so);
- activate(&q, so2);
- exit(0);
- default:
- (void) close(so2);
- break;
- }
- }
- syslog(LOG_INFO, "%s unmounted", mountpt);
- exit(0);
-}
-
-static void
-usage()
-{
- (void)fprintf(stderr,
- "usage: mount_portalfs [-o options] config mount-point\n");
- exit(EX_USAGE);
-}
diff --git a/usr.sbin/mount_portalfs/pathnames.h b/usr.sbin/mount_portalfs/pathnames.h
deleted file mode 100644
index 16720853c70a..000000000000
--- a/usr.sbin/mount_portalfs/pathnames.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- * All rights reserved.
- *
- * This code is derived from software donated to Berkeley by
- * Jan-Simon Pendry.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pathnames.h 8.1 (Berkeley) 6/5/93
- *
- * $FreeBSD$
- */
-
-#include <paths.h>
-
-#define _PATH_TMPPORTAL "/tmp/portalXXXXXXXXXX" /* Scratch socket name */
diff --git a/usr.sbin/mount_portalfs/portal.conf b/usr.sbin/mount_portalfs/portal.conf
deleted file mode 100644
index 53a07a92231c..000000000000
--- a/usr.sbin/mount_portalfs/portal.conf
+++ /dev/null
@@ -1,7 +0,0 @@
-# @(#)portal.conf 8.1 (Berkeley) 6/5/93
-# $FreeBSD$
-tcplisten/ tcplisten tcplisten/
-tcp/ tcp tcp/
-fs/ file fs/
-pipe/ pipe
-foo/ exec ./bar bar baz
diff --git a/usr.sbin/mount_portalfs/portald.h b/usr.sbin/mount_portalfs/portald.h
deleted file mode 100644
index 46c6afe17172..000000000000
--- a/usr.sbin/mount_portalfs/portald.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- * All rights reserved.
- *
- * This code is derived from software donated to Berkeley by
- * Jan-Simon Pendry.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)portald.h 8.1 (Berkeley) 6/5/93
- *
- * $FreeBSD$
- */
-
-#include <sys/cdefs.h>
-#include <fs/portalfs/portal.h>
-
-/*
- * Meta-chars in an RE. Paths in the config file containing
- * any of these characters will be matched using regexec, other
- * paths will be prefix-matched.
- */
-#define RE_CHARS ".|()[]*+?\\^$"
-
-typedef struct qelem qelem;
-
-struct qelem {
- qelem *q_forw;
- qelem *q_back;
-};
-
-typedef struct provider provider;
-struct provider {
- char *pr_match;
- int (*pr_func)(struct portal_cred *,
- char *key, char **v, int so, int *fdp);
-};
-extern provider providers[];
-
-/*
- * Portal providers
- */
-extern int portal_exec(struct portal_cred *,
- char *key, char **v, int so, int *fdp);
-extern int portal_file(struct portal_cred *,
- char *key, char **v, int so, int *fdp);
-extern int portal_tcp(struct portal_cred *,
- char *key, char **v, int so, int *fdp);
-extern int portal_tcplisten(struct portal_cred *,
- char *key, char **v, int so, int *fdp);
-
-/*
- * Global functions
- */
-extern void activate(qelem *q, int so);
-extern char **conf_match(qelem *q, char *key);
-extern void conf_read(qelem *q, char *conf);
diff --git a/usr.sbin/mount_portalfs/pt_conf.c b/usr.sbin/mount_portalfs/pt_conf.c
deleted file mode 100644
index f158a73dd03d..000000000000
--- a/usr.sbin/mount_portalfs/pt_conf.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- * All rights reserved.
- *
- * This code is derived from software donated to Berkeley by
- * Jan-Simon Pendry.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pt_conf.c 8.1 (Berkeley) 6/5/93
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include "portald.h"
-
-provider providers[] = {
- { "exec", portal_exec },
- { "file", portal_file },
- { "tcp", portal_tcp },
- { "tcplisten", portal_tcplisten },
- { 0, 0 }
-};
diff --git a/usr.sbin/mount_portalfs/pt_exec.c b/usr.sbin/mount_portalfs/pt_exec.c
deleted file mode 100644
index 359c78e92164..000000000000
--- a/usr.sbin/mount_portalfs/pt_exec.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- * All rights reserved.
- *
- * This code is derived from software donated to Berkeley by
- * Jan-Simon Pendry.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pt_exec.c 8.1 (Berkeley) 6/5/93
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/param.h>
-
-#include "portald.h"
-
-int portal_exec(pcr, key, v, so, fdp)
-struct portal_cred *pcr;
-char *key;
-char **v;
-int so;
-int *fdp;
-{
- return (ENOEXEC);
-}
-
diff --git a/usr.sbin/mount_portalfs/pt_file.c b/usr.sbin/mount_portalfs/pt_file.c
deleted file mode 100644
index f22ebd7d2b51..000000000000
--- a/usr.sbin/mount_portalfs/pt_file.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- * All rights reserved.
- *
- * This code is derived from software donated to Berkeley by
- * Jan-Simon Pendry.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pt_file.c 8.3 (Berkeley) 7/3/94
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/syslog.h>
-
-#include "portald.h"
-
-int portal_file(pcr, key, v, so, fdp)
-struct portal_cred *pcr;
-char *key;
-char **v;
-int so;
-int *fdp;
-{
- int fd;
- char pbuf[MAXPATHLEN];
- int error;
- gid_t gidset[NGROUPS];
- int i;
-
- pbuf[0] = '/';
- strcpy(pbuf+1, key + (v[1] ? strlen(v[1]) : 0));
-
-#ifdef DEBUG
- printf("path = %s, uid = %d, gid = %d\n", pbuf, pcr->pcr_uid, pcr->pcr_groups[0]);
- printf ("fflag = %x, oflag = %x\n", pcr->pcr_flag, (pcr->pcr_flag)-1);
-#endif
-
- for (i = 0; i < pcr->pcr_ngroups; i++)
- gidset[i] = pcr->pcr_groups[i];
-
- if (setgroups(pcr->pcr_ngroups, gidset) < 0)
- return (errno);
-
- if (seteuid(pcr->pcr_uid) < 0)
- return (errno);
-
- /* dmb convert kernel flags to oflags, see <fcntl.h> */
- fd = open(pbuf, (pcr->pcr_flag)-1, 0777);
- if (fd < 0)
- error = errno;
- else
- error = 0;
-
- if (seteuid((uid_t) 0) < 0) { /* XXX - should reset gidset too */
- error = errno;
- syslog(LOG_ERR, "setcred: %s", strerror(error));
- if (fd >= 0) {
- (void) close(fd);
- fd = -1;
- }
- }
-
- if (error == 0)
- *fdp = fd;
-
-#ifdef DEBUG
- fprintf(stderr, "pt_file returns *fdp = %d, error = %d\n", *fdp, error);
-#endif
-
- return (error);
-}
diff --git a/usr.sbin/mount_portalfs/pt_tcp.c b/usr.sbin/mount_portalfs/pt_tcp.c
deleted file mode 100644
index 49056163aae3..000000000000
--- a/usr.sbin/mount_portalfs/pt_tcp.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (c) 1992, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- * All rights reserved.
- *
- * This code is derived from software donated to Berkeley by
- * Jan-Simon Pendry.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pt_tcp.c 8.5 (Berkeley) 4/28/95
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-#include <errno.h>
-#include <stdlib.h>
-#include <strings.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/syslog.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-
-#include "portald.h"
-
-/*
- * Key will be tcp/host/port[/"priv"]
- * Create a TCP socket connected to the
- * requested host and port.
- * Some trailing suffix values have special meanings.
- * An unrecognized suffix is an error.
- */
-int portal_tcp(pcr, key, v, kso, fdp)
- struct portal_cred *pcr;
- char *key;
- char **v;
- int kso;
- int *fdp;
-{
- char host[MAXHOSTNAMELEN];
- char port[MAXHOSTNAMELEN];
- char *p = key + (v[1] ? strlen(v[1]) : 0);
- char *q;
- struct hostent *hp;
- struct servent *sp;
- struct in_addr **ipp;
- struct in_addr *ip[2];
- struct in_addr ina;
- u_short s_port;
- int priv = 0;
- struct sockaddr_in sain;
-
- q = strchr(p, '/');
- if (q == 0 || q - p >= sizeof(host))
- return (EINVAL);
- *q = '\0';
- strcpy(host, p);
- p = q + 1;
-
- q = strchr(p, '/');
- if (q)
- *q = '\0';
- if (strlen(p) >= sizeof(port))
- return (EINVAL);
- strcpy(port, p);
- if (q) {
- p = q + 1;
- if (strcmp(p, "priv") == 0) {
- if (pcr->pcr_uid == 0)
- priv = 1;
- else
- return (EPERM);
- } else {
- return (EINVAL);
- }
- }
-
- hp = gethostbyname(host);
- if (hp != 0) {
- ipp = (struct in_addr **) hp->h_addr_list;
- } else {
- ina.s_addr = inet_addr(host);
- if (ina.s_addr == INADDR_NONE)
- return (EINVAL);
- ip[0] = &ina;
- ip[1] = 0;
- ipp = ip;
- }
-#ifdef DEBUG
- printf ("inet address for %s is %s\n", host, inet_ntoa(*ipp[0]));
-#endif
-
- sp = getservbyname(port, "tcp");
- if (sp != NULL) {
- s_port = (u_short)sp->s_port;
- } else {
- s_port = strtoul(port, &p, 0);
- if (s_port == 0 || *p != '\0')
- return (EINVAL);
- s_port = htons(s_port);
- }
-#ifdef DEBUG
- printf ("port number for %s is %d\n", port, (int)ntohs(s_port));
-#endif
-
- memset(&sain, 0, sizeof(sain));
- sain.sin_len = sizeof(sain);
- sain.sin_family = AF_INET;
- sain.sin_port = s_port;
-
- while (ipp[0]) {
- int so;
-
- if (priv)
- so = rresvport((int *) 0);
- else
- so = socket(AF_INET, SOCK_STREAM, 0);
- if (so < 0) {
- syslog(LOG_ERR, "socket: %m");
- return (errno);
- }
-
- sain.sin_addr = *ipp[0];
- if (connect(so, (struct sockaddr *) &sain, sizeof(sain)) == 0) {
- *fdp = so;
- return (0);
- }
- (void) close(so);
-
- ipp++;
- }
-
- return (errno);
-}
diff --git a/usr.sbin/mount_portalfs/pt_tcplisten.c b/usr.sbin/mount_portalfs/pt_tcplisten.c
deleted file mode 100644
index 43a20c5aa92c..000000000000
--- a/usr.sbin/mount_portalfs/pt_tcplisten.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- * All rights reserved.
- *
- * This code is derived from software donated to Berkeley by
- * Jan-Simon Pendry.
- *
- * Modified by Duncan Barclay.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pt_tcp.c 8.3 (Berkeley) 3/27/94
- *
- * pt_tcp.c,v 1.1.1.1 1994/05/26 06:34:34 rgrimes Exp
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <strings.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/syslog.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-
-#include "portald.h"
-
-/*
- * Key will be tcplisten/host/port
- *
- * Create a TCP socket bound to the requested host and port.
- * If the host is "ANY" the receving address will be set to INADDR_ANY.
- * If the port is 0 the caller must find out the returned port number
- * using a call to getsockname.
- *
- * XXX! The owner of the socket will be root rather then the user. This
- * may cause remote auth (identd) to return unexpected results.
- *
- */
-int portal_tcplisten(pcr, key, v, kso, fdp)
- struct portal_cred *pcr;
- char *key;
- char **v;
- int kso;
- int *fdp;
-{
- char host[MAXHOSTNAMELEN];
- char port[MAXHOSTNAMELEN];
- char *p = key + (v[1] ? strlen(v[1]) : 0);
- char *q;
- struct hostent *hp;
- struct servent *sp;
- struct in_addr **ipp;
- struct in_addr *ip[2];
- struct in_addr ina;
- u_short s_port;
- int any = 0;
- struct sockaddr_in sain;
-
- q = strchr(p, '/');
- if (q == 0 || q - p >= sizeof(host))
- return (EINVAL);
- *q = '\0';
- snprintf(host, sizeof(host), "%s", p);
- p = q + 1;
-
- q = strchr(p, '/');
- if (q)
- *q = '\0';
- if (strlen(p) >= sizeof(port))
- return (EINVAL);
- snprintf(port, sizeof(port), "%s", p);
-
- if (strcmp(host, "ANY") == 0) {
- any = 1;
- } else {
- hp = gethostbyname(host);
- if (hp != 0) {
- ipp = (struct in_addr **) hp->h_addr_list;
- } else {
- ina.s_addr = inet_addr(host);
- if (ina.s_addr == INADDR_NONE)
- return (EINVAL);
- ip[0] = &ina;
- ip[1] = 0;
- ipp = ip;
- }
- }
-#ifdef DEBUG
- if (any)
- printf("INADDR_ANY to be used for hostname\n");
- else
- printf("inet address for %s is %s\n", host, inet_ntoa(*ipp[0]));
-#endif
-
- sp = getservbyname(port, "tcp");
- if (sp != NULL) {
- s_port = (u_short) sp->s_port;
- } else {
- s_port = strtoul(port, &p, 0);
- if (*p != '\0')
- return (EINVAL);
- s_port = htons(s_port);
- }
- if ((ntohs(s_port) != 0) &&
- (ntohs(s_port) <= IPPORT_RESERVED) &&
- (pcr->pcr_uid != 0))
- return (EPERM);
-#ifdef DEBUG
- printf("port number for %s is %d\n", port, ntohs(s_port));
-#endif
-
- memset(&sain, 0, sizeof(sain));
- sain.sin_len = sizeof(sain);
- sain.sin_family = AF_INET;
- sain.sin_port = s_port;
-
- if (any) {
- int so;
- int sock;
-
- so = socket(AF_INET, SOCK_STREAM, 0);
- if (so < 0) {
- syslog(LOG_ERR, "socket: %m");
- return (errno);
- }
-
- sain.sin_addr.s_addr = INADDR_ANY;
- if (bind(so, (struct sockaddr *) &sain, sizeof(sain)) == 0) {
- listen(so, 1);
- if ((sock = accept(so, (struct sockaddr *)0, (int *)0)) == -1) {
- syslog(LOG_ERR, "accept: %m");
- (void) close(so);
- return (errno);
- }
- *fdp = sock;
- (void) close(so);
- return (0);
- }
- syslog(LOG_ERR, "bind: %m");
- (void) close(so);
- return (errno);
- }
-
- while (ipp[0]) {
- int so;
- int sock;
-
- so = socket(AF_INET, SOCK_STREAM, 0);
- if (so < 0) {
- syslog(LOG_ERR, "socket: %m");
- return (errno);
- }
-
- sain.sin_addr = *ipp[0];
- if (bind(so, (struct sockaddr *) &sain, sizeof(sain)) == 0) {
- listen(so, 1);
- if ((sock = accept(so, (struct sockaddr *)0, (int *)0)) == -1) {
- syslog(LOG_ERR, "accept: %m");
- (void) close(so);
- return (errno);
- }
- *fdp = sock;
- (void) close(so);
- return (0);
- }
- (void) close(so);
-
- ipp++;
- }
-
- syslog(LOG_ERR, "bind: %m");
- return (errno);
-
-}
diff --git a/usr.sbin/mount_smbfs/Makefile b/usr.sbin/mount_smbfs/Makefile
deleted file mode 100644
index 9c56456a03be..000000000000
--- a/usr.sbin/mount_smbfs/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-# $FreeBSD$
-
-PROG= mount_smbfs
-SRCS= mount_smbfs.c getmntopts.c
-WARNS?= 0
-MAN= mount_smbfs.8
-
-MOUNTDIR= ${.CURDIR}/../mount
-CONTRIBDIR= ${.CURDIR}/../../contrib/smbfs
-CFLAGS+= -DSMBFS -I${MOUNTDIR} -I${CONTRIBDIR}/include
-
-LDADD+= -lsmb
-DPADD+= ${LIBSMB}
-
-# Needs to be dynamically linked for optional dlopen() access to
-# userland libiconv (see the -E option).
-#
-NOSHARED?= NO
-
-.PATH: ${CONTRIBDIR}/mount_smbfs
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/nologin/Makefile b/usr.sbin/nologin/Makefile
deleted file mode 100644
index b1611c06f4c7..000000000000
--- a/usr.sbin/nologin/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# @(#)Makefile 8.2 (Berkeley) 4/22/94
-# $FreeBSD$
-
-SCRIPTS=nologin.sh
-MAN= nologin.5 nologin.8
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/nologin/nologin.5 b/usr.sbin/nologin/nologin.5
deleted file mode 100644
index 9d63c889e115..000000000000
--- a/usr.sbin/nologin/nologin.5
+++ /dev/null
@@ -1,72 +0,0 @@
-.\" Copyright (c) 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)nologin.8 8.1 (Berkeley) 6/19/93
-.\" $FreeBSD$
-.\"
-.Dd June 19, 1993
-.Dt NOLOGIN 5
-.Os
-.Sh NAME
-.Nm nologin
-.Nd disallow logins
-.Sh DESCRIPTION
-Programs such as
-.Xr login 1
-disallow logins if the file
-.Pa /var/run/nologin
-exists.
-Programs display the contents of
-.Pa /var/run/nologin
-to the user and exit.
-This makes it simple to temporarily prevent incoming logins systemwide.
-.Pp
-To disable logins on a per-account basis,
-investigate
-.Xr nologin 8 .
-.Sh SECURITY
-Ignored by
-.Xr login 1
-for user root.
-.Sh FILES
-.Bl -tag -width /var/run/nologinxxx -compact
-.It Pa /var/run/nologin
-The
-.Nm
-file resides in
-.Pa /var/run .
-.El
-.Sh SEE ALSO
-.Xr login 1 ,
-.Xr rlogin 1 ,
-.Xr telnet 1 ,
-.Xr nologin 8 ,
-.Xr shutdown 8
diff --git a/usr.sbin/nologin/nologin.8 b/usr.sbin/nologin/nologin.8
deleted file mode 100644
index 7f8f9fff2877..000000000000
--- a/usr.sbin/nologin/nologin.8
+++ /dev/null
@@ -1,61 +0,0 @@
-.\" Copyright (c) 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)nologin.8 8.1 (Berkeley) 6/19/93
-.\" $FreeBSD$
-.\"
-.Dd June 19, 1993
-.Dt NOLOGIN 8
-.Os
-.Sh NAME
-.Nm nologin
-.Nd politely refuse a login
-.Sh SYNOPSIS
-.Nm
-.Sh DESCRIPTION
-The
-.Nm
-utility displays a message that an account is not available and
-exits non-zero.
-It is intended as a replacement shell field for accounts that
-have been disabled.
-.Pp
-To disable all logins,
-investigate
-.Xr nologin 5 .
-.Sh SEE ALSO
-.Xr login 1 ,
-.Xr nologin 5
-.Sh HISTORY
-The
-.Nm
-utility appeared in
-.Bx 4.4 .
diff --git a/usr.sbin/nologin/nologin.sh b/usr.sbin/nologin/nologin.sh
deleted file mode 100644
index 52279c19ea9a..000000000000
--- a/usr.sbin/nologin/nologin.sh
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/sh -p
-#
-# Copyright (c) 1992, 1993
-# The Regents of the University of California. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by the University of
-# California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-# may be used to endorse or promote products derived from this software
-# without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-# @(#)nologin.sh 8.1 (Berkeley) 6/5/93
-# $FreeBSD$
-#
-
-echo 'This account is currently not available.'
-exit 1
diff --git a/usr.sbin/sade/Makefile b/usr.sbin/sade/Makefile
deleted file mode 100644
index 31c4281854c7..000000000000
--- a/usr.sbin/sade/Makefile
+++ /dev/null
@@ -1,93 +0,0 @@
-# $FreeBSD$
-
-PROG= sysinstall
-MAN= sysinstall.8
-SRCS= anonFTP.c cdrom.c command.c config.c devices.c dhcp.c \
- disks.c dispatch.c dist.c dmenu.c doc.c dos.c floppy.c \
- ftp.c globals.c http.c index.c install.c installUpgrade.c keymap.c \
- label.c main.c makedevs.c media.c menus.c misc.c modules.c \
- mouse.c msg.c network.c nfs.c options.c package.c \
- system.c tape.c tcpip.c termcap.c ttys.c ufs.c usb.c user.c \
- variable.c wizard.c keymap.h
-
-.if ${MACHINE} == "pc98"
-SRCS+= pccard.c
-.endif
-
-CFLAGS+= -DX_AS_PKG -DUSE_GZIP=1
-.if ${MACHINE} == "pc98"
-CFLAGS+= -DPC98
-.endif
-CFLAGS+= -I${.CURDIR}/../../gnu/lib/libdialog -I.
-
-DPADD= ${LIBDIALOG} ${LIBNCURSES} ${LIBUTIL} ${LIBDISK} ${LIBFTPIO}
-LDADD= -ldialog -lncurses -lutil -ldisk -lftpio
-
-CLEANFILES= makedevs.c rtermcap
-CLEANFILES+= keymap.tmp keymap.h
-
-makedevs.c: Makefile rtermcap
- echo '#include <sys/types.h>' > makedevs.c
- ./rtermcap ansi | \
- file2c 'const char termcap_ansi[] = {' ',0};' \
- >> makedevs.c
- ./rtermcap cons25w | \
- file2c 'const char termcap_cons25w[] = {' ',0};' \
- >> makedevs.c
- ./rtermcap cons25 | \
- file2c 'const char termcap_cons25[] = {' ',0};' \
- >> makedevs.c
- ./rtermcap cons25-m | \
- file2c 'const char termcap_cons25_m[] = {' ',0};' \
- >> makedevs.c
- ./rtermcap cons25r | \
- file2c 'const char termcap_cons25r[] = {' ',0};' \
- >> makedevs.c
- ./rtermcap cons25r-m | \
- file2c 'const char termcap_cons25r_m[] = {' ',0};' \
- >> makedevs.c
- ./rtermcap cons25l1 | \
- file2c 'const char termcap_cons25l1[] = {' ',0};' \
- >> makedevs.c
- ./rtermcap cons25l1-m | \
- file2c 'const char termcap_cons25l1_m[] = {' ',0};' \
- >> makedevs.c
- ./rtermcap vt100 | \
- file2c 'const char termcap_vt100[] = {' ',0};' \
- >> makedevs.c
- ./rtermcap xterm | \
- file2c 'const char termcap_xterm[] = {' ',0};' \
- >> makedevs.c
-
-build-tools: rtermcap
-
-rtermcap: rtermcap.c
- ${CC} -o ${.TARGET} ${.ALLSRC} -ltermcap
-
-.if ${MACHINE} == "pc98"
-KEYMAPS= jp.pc98 jp.pc98.iso
-.else
-KEYMAPS= be.iso bg.bds.ctrlcaps bg.phonetic.ctrlcaps br275.iso \
- cs.latin2.qwertz danish.iso finnish.iso fr.iso \
- german.iso hr.iso hu.iso2.101keys it.iso icelandic.iso jp.106 \
- norwegian.iso pl_PL.ISO8859-2 pt.iso ru.koi8-r si.iso \
- spanish.iso swedish.iso swissfrench.iso swissgerman.iso ua.koi8-u \
- ua.koi8-u.shift.alt uk.iso us.dvorak us.iso us.pc-ctrl us.unix
-.endif
-
-keymap.h:
- rm -f keymap.tmp
- for map in ${KEYMAPS} ; do \
- KEYMAP_PATH=${.CURDIR}/../../share/syscons/keymaps \
- kbdcontrol -L $$map | \
- sed -e '/^static accentmap_t/,$$d' >> keymap.tmp ; \
- done
- echo "static struct keymapInfo keymapInfos[] = {" >> keymap.tmp
- for map in ${KEYMAPS} ; do \
- echo -n ' { "'$$map'", ' >> keymap.tmp ; \
- echo "&keymap_$$map }," | tr '[-.]' '_' >> keymap.tmp ; \
- done
- ( echo " { 0 }"; echo "};" ; echo "" ) >> keymap.tmp
- mv keymap.tmp keymap.h
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/sade/command.c b/usr.sbin/sade/command.c
deleted file mode 100644
index 33ebc352544a..000000000000
--- a/usr.sbin/sade/command.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last program in the `sysinstall' line - the next
- * generation being essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-
-#define MAX_NUM_COMMANDS 10
-
-typedef struct {
- char key[FILENAME_MAX];
- struct {
- enum { CMD_SHELL, CMD_FUNCTION } type;
- void *ptr, *data;
- } cmds[MAX_NUM_COMMANDS];
- int ncmds;
-} Command;
-
-#define MAX_CMDS 200
-static Command *commandStack[MAX_CMDS];
-int numCommands;
-
-/* Nuke the command stack */
-void
-command_clear(void)
-{
- int i, j;
-
- for (i = 0; i < numCommands; i++)
- for (j = 0; j < commandStack[i]->ncmds; j++)
- if (commandStack[i]->cmds[j].type == CMD_SHELL)
- free(commandStack[i]->cmds[j].ptr);
- free(commandStack[i]);
- numCommands = 0;
-}
-
-static void
-addit(char *key, int type, void *cmd, void *data)
-{
- int i;
-
- /* First, look for the key already present and add a command to it if found */
- for (i = 0; i < numCommands; i++) {
- if (!strcmp(commandStack[i]->key, key)) {
- if (commandStack[i]->ncmds == MAX_NUM_COMMANDS)
- msgFatal("More than %d commands stacked up behind %s??", MAX_NUM_COMMANDS, key);
- commandStack[i]->cmds[commandStack[i]->ncmds].type = type;
- commandStack[i]->cmds[commandStack[i]->ncmds].ptr = cmd;
- commandStack[i]->cmds[commandStack[i]->ncmds].data = data;
- ++(commandStack[i]->ncmds);
- return;
- }
- }
- if (numCommands == MAX_CMDS)
- msgFatal("More than %d commands accumulated??", MAX_CMDS);
-
- /* If we fell to here, it's a new key */
- commandStack[numCommands] = safe_malloc(sizeof(Command));
- strcpy(commandStack[numCommands]->key, key);
- commandStack[numCommands]->ncmds = 1;
- commandStack[numCommands]->cmds[0].type = type;
- commandStack[numCommands]->cmds[0].ptr = cmd;
- commandStack[numCommands]->cmds[0].data = data;
- ++numCommands;
-}
-
-/* Add a shell command under a given key */
-void
-command_shell_add(char *key, char *fmt, ...)
-{
- va_list args;
- char *cmd;
-
- cmd = (char *)safe_malloc(256);
- va_start(args, fmt);
- vsnprintf(cmd, 256, fmt, args);
- va_end(args);
-
- addit(key, CMD_SHELL, cmd, NULL);
-}
-
-/* Add a shell command under a given key */
-void
-command_func_add(char *key, commandFunc func, void *data)
-{
- addit(key, CMD_FUNCTION, func, data);
-}
-
-static int
-sort_compare(Command *p1, Command *p2)
-{
- if (!p1 && !p2)
- return 0;
- else if (!p1 && p2) /* NULL has a "greater" value for commands */
- return 1;
- else if (p1 && !p2)
- return -1;
- else
- return strcmp(p1->key, p2->key);
-}
-
-void
-command_sort(void)
-{
- int i, j;
-
- commandStack[numCommands] = NULL;
- /* Just do a crude bubble sort since the list is small */
- for (i = 0; i < numCommands; i++) {
- for (j = 0; j < numCommands; j++) {
- if (sort_compare(commandStack[j], commandStack[j + 1]) > 0) {
- Command *tmp = commandStack[j];
-
- commandStack[j] = commandStack[j + 1];
- commandStack[j + 1] = tmp;
- }
- }
- }
-}
-
-/* Run all accumulated commands in sorted order */
-void
-command_execute(void)
-{
- int i, j, ret;
- commandFunc func;
-
- for (i = 0; i < numCommands; i++) {
- for (j = 0; j < commandStack[i]->ncmds; j++) {
- /* If it's a shell command, run system on it */
- if (commandStack[i]->cmds[j].type == CMD_SHELL) {
- msgNotify("Doing %s", (char *)commandStack[i]->cmds[j].ptr);
- ret = vsystem("%s", (char *)commandStack[i]->cmds[j].ptr);
- if (isDebug())
- msgDebug("Command `%s' returns status %d\n",
- (char *)commandStack[i]->cmds[j].ptr, ret);
- }
- else {
- /* It's a function pointer - call it with the key and
- the data */
- func = (commandFunc)commandStack[i]->cmds[j].ptr;
- if (isDebug())
- msgDebug("%p: Execute(%s, %s)\n",
- func, commandStack[i]->key,
- (char *)commandStack[i]->cmds[j].data);
- ret = (*func)(commandStack[i]->key, commandStack[i]->cmds[j].data);
- if (isDebug())
- msgDebug("Function @ %p returns status %d\n",
- commandStack[i]->cmds[j].ptr, ret);
- }
- }
- }
-}
diff --git a/usr.sbin/sade/config.c b/usr.sbin/sade/config.c
deleted file mode 100644
index 29e7cfe1c979..000000000000
--- a/usr.sbin/sade/config.c
+++ /dev/null
@@ -1,1093 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last program in the `sysinstall' line - the next
- * generation being essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-#include <sys/disklabel.h>
-#include <sys/wait.h>
-#include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/fcntl.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/mount.h>
-#include <time.h>
-#include <kenv.h>
-
-static Chunk *chunk_list[MAX_CHUNKS];
-static int nchunks;
-static int rootdev_is_od;
-
-/* arg to sort */
-static int
-chunk_compare(Chunk *c1, Chunk *c2)
-{
- if (!c1 && !c2)
- return 0;
- else if (!c1 && c2)
- return 1;
- else if (c1 && !c2)
- return -1;
- else if (!c1->private_data && !c2->private_data)
- return 0;
- else if (c1->private_data && !c2->private_data)
- return 1;
- else if (!c1->private_data && c2->private_data)
- return -1;
- else
- return strcmp(((PartInfo *)(c1->private_data))->mountpoint, ((PartInfo *)(c2->private_data))->mountpoint);
-}
-
-static void
-chunk_sort(void)
-{
- int i, j;
-
- for (i = 0; i < nchunks; i++) {
- for (j = 0; j < nchunks; j++) {
- if (chunk_compare(chunk_list[j], chunk_list[j + 1]) > 0) {
- Chunk *tmp = chunk_list[j];
-
- chunk_list[j] = chunk_list[j + 1];
- chunk_list[j + 1] = tmp;
- }
- }
- }
-}
-
-static void
-check_rootdev(Chunk **list, int n)
-{
- int i;
- Chunk *c;
-
- rootdev_is_od = 0;
- for (i = 0; i < n; i++) {
- c = *list++;
- if (c->type == part && (c->flags & CHUNK_IS_ROOT)
- && strncmp(c->disk->name, "od", 2) == 0)
- rootdev_is_od = 1;
- }
-}
-
-static char *
-name_of(Chunk *c1)
-{
- return c1->name;
-}
-
-static char *
-mount_point(Chunk *c1)
-{
- if (c1->type == part && c1->subtype == FS_SWAP)
- return "none";
- else if (c1->type == part || c1->type == fat || c1->type == efi)
- return ((PartInfo *)c1->private_data)->mountpoint;
- return "/bogus";
-}
-
-static char *
-fstype(Chunk *c1)
-{
- if (c1->type == fat || c1->type == efi)
- return "msdosfs";
- else if (c1->type == part) {
- if (c1->subtype != FS_SWAP)
- return "ufs";
- else
- return "swap";
- }
- return "bogus";
-}
-
-static char *
-fstype_short(Chunk *c1)
-{
- if (c1->type == part) {
- if (c1->subtype != FS_SWAP) {
- if (rootdev_is_od == 0 && strncmp(c1->name, "od", 2) == 0)
- return "rw,noauto";
- else
- return "rw";
- }
- else
- return "sw";
- }
- else if (c1->type == fat) {
- if (strncmp(c1->name, "od", 2) == 0)
- return "ro,noauto";
- else
- return "ro";
- }
- else if (c1->type == efi)
- return "rw";
-
- return "bog";
-}
-
-static int
-seq_num(Chunk *c1)
-{
- if (c1->type == part && c1->subtype != FS_SWAP) {
- if (rootdev_is_od == 0 && strncmp(c1->name, "od", 2) == 0)
- return 0;
- else if (c1->flags & CHUNK_IS_ROOT)
- return 1;
- else
- return 2;
- }
- return 0;
-}
-
-int
-configFstab(dialogMenuItem *self)
-{
- Device **devs;
- Disk *disk;
- FILE *fstab;
- int i, cnt;
- Chunk *c1, *c2;
-
- if (!RunningAsInit) {
- if (file_readable("/etc/fstab"))
- return DITEM_SUCCESS;
- else {
- msgConfirm("Attempting to rebuild your /etc/fstab file. Warning: If you had\n"
- "any CD devices in use before running sysinstall then they may NOT\n"
- "be found by this run!");
- }
- }
-
- devs = deviceFind(NULL, DEVICE_TYPE_DISK);
- if (!devs) {
- msgConfirm("No disks found!");
- return DITEM_FAILURE;
- }
-
- /* Record all the chunks */
- nchunks = 0;
- for (i = 0; devs[i]; i++) {
- if (!devs[i]->enabled)
- continue;
- disk = (Disk *)devs[i]->private;
- if (!disk->chunks)
- msgFatal("No chunk list found for %s!", disk->name);
- for (c1 = disk->chunks->part; c1; c1 = c1->next) {
- if (c1->type == freebsd) {
- for (c2 = c1->part; c2; c2 = c2->next) {
- if (c2->type == part && (c2->subtype == FS_SWAP || c2->private_data))
- chunk_list[nchunks++] = c2;
- }
- }
- else if ((c1->type == fat || c1->type == efi) && c1->private_data)
- chunk_list[nchunks++] = c1;
- }
- }
- chunk_list[nchunks] = 0;
- chunk_sort();
-
- fstab = fopen("/etc/fstab", "w");
- if (!fstab) {
- msgConfirm("Unable to create a new /etc/fstab file! Manual intervention\n"
- "will be required.");
- return DITEM_FAILURE;
- }
-
- check_rootdev(chunk_list, nchunks);
-
- /* Go for the burn */
- msgDebug("Generating /etc/fstab file\n");
- fprintf(fstab, "# Device\t\tMountpoint\tFStype\tOptions\t\tDump\tPass#\n");
- for (i = 0; i < nchunks; i++)
- fprintf(fstab, "/dev/%s\t\t%s\t\t%s\t%s\t\t%d\t%d\n", name_of(chunk_list[i]), mount_point(chunk_list[i]),
- fstype(chunk_list[i]), fstype_short(chunk_list[i]), seq_num(chunk_list[i]), seq_num(chunk_list[i]));
-
- /* Now look for the CDROMs */
- devs = deviceFind(NULL, DEVICE_TYPE_CDROM);
- cnt = deviceCount(devs);
-
- /* Write out the CDROM entries */
- for (i = 0; i < cnt; i++) {
- char cdname[10];
-
- sprintf(cdname, "/cdrom%s", i ? itoa(i) : "");
- if (Mkdir(cdname))
- msgConfirm("Unable to make mount point for: %s", cdname);
- else
- fprintf(fstab, "/dev/%s\t\t%s\t\tcd9660\tro,noauto\t0\t0\n", devs[i]->name, cdname);
- }
-
- fclose(fstab);
- if (isDebug())
- msgDebug("Wrote out /etc/fstab file\n");
- return DITEM_SUCCESS;
-}
-
-/* Do the work of sucking in a config file.
- * config is the filename to read in.
- * lines is a fixed (max) sized array of char*
- * returns number of lines read. line contents
- * are malloc'd and must be freed by the caller.
- */
-int
-readConfig(char *config, char **lines, int max)
-{
- FILE *fp;
- char line[256];
- int i, nlines;
-
- fp = fopen(config, "r");
- if (!fp)
- return -1;
-
- nlines = 0;
- /* Read in the entire file */
- for (i = 0; i < max; i++) {
- if (!fgets(line, sizeof line, fp))
- break;
- lines[nlines++] = strdup(line);
- }
- fclose(fp);
- if (isDebug())
- msgDebug("readConfig: Read %d lines from %s.\n", nlines, config);
- return nlines;
-}
-
-#define MAX_LINES 2000 /* Some big number we're not likely to ever reach - I'm being really lazy here, I know */
-
-static void
-readConfigFile(char *config, int marked)
-{
- char *lines[MAX_LINES], *cp, *cp2;
- int i, nlines;
-
- nlines = readConfig(config, lines, MAX_LINES);
- if (nlines == -1)
- return;
-
- for (i = 0; i < nlines; i++) {
- /* Skip the comments & non-variable settings */
- if (lines[i][0] == '#' || !(cp = index(lines[i], '='))) {
- free(lines[i]);
- continue;
- }
- *cp++ = '\0';
- /* Find quotes */
- if ((cp2 = index(cp, '"')) || (cp2 = index(cp, '\047'))) {
- cp = cp2 + 1;
- cp2 = index(cp, *cp2);
- }
- /* If valid quotes, use it */
- if (cp2) {
- *cp2 = '\0';
- /* If we have a legit value, set it */
- if (strlen(cp))
- variable_set2(lines[i], cp, marked);
- }
- free(lines[i]);
- }
-}
-
-/* Load the environment from rc.conf file(s) */
-void
-configEnvironmentRC_conf(void)
-{
- static struct {
- char *fname;
- int marked;
- } configs[] = {
- { "/etc/defaults/rc.conf", 0 },
- { "/etc/rc.conf", 0 },
- { "/etc/rc.conf.local", 0 },
- { NULL, 0 },
- };
- int i;
-
- for (i = 0; configs[i].fname; i++) {
- if (file_readable(configs[i].fname))
- readConfigFile(configs[i].fname, configs[i].marked);
- }
-}
-
-/* Load the environment from a resolv.conf file */
-void
-configEnvironmentResolv(char *config)
-{
- char *lines[MAX_LINES];
- int i, nlines;
-
- nlines = readConfig(config, lines, MAX_LINES);
- if (nlines == -1)
- return;
- for (i = 0; i < nlines; i++) {
- Boolean name_set = variable_get(VAR_NAMESERVER) ? 1 : 0;
-
- if (!strncmp(lines[i], "domain", 6) && !variable_get(VAR_DOMAINNAME))
- variable_set2(VAR_DOMAINNAME, string_skipwhite(string_prune(lines[i] + 6)), 0);
- else if (!name_set && !strncmp(lines[i], "nameserver", 10)) {
- /* Only take the first nameserver setting - we're lame */
- variable_set2(VAR_NAMESERVER, string_skipwhite(string_prune(lines[i] + 10)), 0);
- }
- free(lines[i]);
- }
-}
-
-/* Version of below for dispatch routines */
-int
-configRC(dialogMenuItem *unused)
-{
- configRC_conf();
- return DITEM_SUCCESS;
-}
-
-void
-configRC_conf(void)
-{
- FILE *rcSite;
- Variable *v;
- int write_header;
- time_t t_loc;
- char *cp;
- static int did_marker = 0;
- time_t tp;
-
- configTtys();
- write_header = !file_readable("/etc/rc.conf");
- rcSite = fopen("/etc/rc.conf", "a");
- if (!rcSite)
- return;
- if (write_header) {
- fprintf(rcSite, "# This file now contains just the overrides from /etc/defaults/rc.conf.\n");
- fprintf(rcSite, "# Please make all changes to this file, not to /etc/defaults/rc.conf.\n\n");
- fprintf(rcSite, "# Enable network daemons for user convenience.\n");
- if ((t_loc = time(NULL)) != -1 && (cp = ctime(&t_loc)))
- fprintf(rcSite, "# Created: %s", cp);
- }
-
- /* Now do variable substitutions */
- for (v = VarHead; v; v = v->next) {
- if (v->dirty) {
- if (!did_marker) {
- time(&tp);
- fprintf(rcSite, "# -- sysinstall generated deltas -- # "
- "%s", ctime(&tp));
- did_marker = 1;
- }
- fprintf(rcSite, "%s=\"%s\"\n", v->name, v->value);
- v->dirty = 0;
- }
- }
- fclose(rcSite);
- /* Tidy up the resulting file if it's late enough in the installation
- for sort and uniq to be available */
- if (RunningAsInit && file_readable("/usr/bin/sort") && file_readable("/usr/bin/uniq"))
- (void)vsystem("sort /etc/rc.conf | uniq > /etc/rc.conf.new && mv /etc/rc.conf.new /etc/rc.conf");
-}
-
-int
-configSaver(dialogMenuItem *self)
-{
- variable_set((char *)self->data, 1);
- if (!variable_get(VAR_BLANKTIME))
- variable_set2(VAR_BLANKTIME, "300", 1);
- return DITEM_SUCCESS;
-}
-
-int
-configSaverTimeout(dialogMenuItem *self)
-{
- return (variable_get_value(VAR_BLANKTIME,
- "Enter time-out period in seconds for screen saver", 1) ?
- DITEM_SUCCESS : DITEM_FAILURE);
-}
-
-int
-configNTP(dialogMenuItem *self)
-{
- int status;
-
- status = variable_get_value(VAR_NTPDATE_FLAGS,
- "Enter the name of an NTP server", 1)
- ? DITEM_SUCCESS : DITEM_FAILURE;
- if (status == DITEM_SUCCESS) {
- static char tmp[255];
-
- snprintf(tmp, sizeof(tmp), "ntpdate_enable=YES,ntpdate_flags=%s",
- variable_get(VAR_NTPDATE_FLAGS));
- self->data = tmp;
- dmenuSetVariables(self);
- }
- return status;
-}
-
-int
-configUsers(dialogMenuItem *self)
-{
- WINDOW *w = savescr();
-
- dialog_clear_norefresh();
- dmenuOpenSimple(&MenuUsermgmt, FALSE);
- restorescr(w);
- return DITEM_SUCCESS;
-}
-
-#ifdef WITH_LINUX
-int
-configLinux(dialogMenuItem *self)
-{
- WINDOW *w = savescr();
- int i;
-
- dialog_clear_norefresh();
- variable_set2(VAR_LINUX_ENABLE, "YES", 1);
- Mkdir("/compat/linux");
- msgNotify("Installing Linux compatibility library...");
- i = package_add("linux_base");
- restorescr(w);
- return i;
-}
-#endif
-
-#ifdef __alpha__
-int
-configOSF1(dialogMenuItem *self)
-{
-
- variable_set2(VAR_OSF1_ENABLE, "YES", 1);
- Mkdir("/compat/osf1");
- return DITEM_SUCCESS;
-}
-#endif
-
-int
-configSecurity(dialogMenuItem *self)
-{
- WINDOW *w = savescr();
-
- dialog_clear_norefresh();
- dmenuOpenSimple(&MenuSecurity, FALSE);
- restorescr(w);
- return DITEM_SUCCESS;
-}
-
-int
-configSecurityProfile(dialogMenuItem *self)
-{
- WINDOW *w = savescr();
-
- dialog_clear_norefresh();
- dmenuOpenSimple(&MenuSecurityProfile, FALSE);
- restorescr(w);
- return DITEM_SUCCESS;
-}
-
-/* Use the most extreme security settings */
-int
-configSecurityExtreme(dialogMenuItem *self)
-{
- WINDOW *w = savescr();
-
- variable_set2("nfs_server_enable", "NO", 1);
- variable_set2("sendmail_enable", "NO", 1);
- variable_set2("sshd_enable", "NO", 1);
- variable_set2("kern_securelevel_enable", "YES", 1);
- variable_set2("kern_securelevel", "2", 1);
-
- if (self)
- msgConfirm("Extreme security settings have been selected.\n\n"
- "Sendmail, sshd, and NFS services have been disabled, and\n"
- "securelevels have been enabled.\n\n"
- "PLEASE NOTE that this still does not save you from having\n"
- "to properly secure your system in other ways or exercise\n"
- "due diligence in your administration, this simply picks\n"
- "a more secure set of out-of-box defaults to start with.\n\n"
- "To change any of these settings later, edit /etc/rc.conf");
-
- restorescr(w);
- return DITEM_SUCCESS;
-}
-
-int
-configSecurityModerate(dialogMenuItem *self)
-{
- WINDOW *w = savescr();
-
- variable_set2("sendmail_enable", "YES", 1);
- variable_set2("sshd_enable", "YES", 1);
- variable_set2("kern_securelevel_enable", "NO", 1);
-
- if (self)
- msgConfirm("Moderate security settings have been selected.\n\n"
- "Sendmail and sshd have been enabled, securelevels are\n"
- "disabled, and NFS server settings have been left intact.\n\n"
- "PLEASE NOTE that this still does not save you from having\n"
- "to properly secure your system in other ways or exercise\n"
- "due diligence in your administration, this simply picks\n"
- "a standard set of out-of-box defaults to start with.\n\n"
- "To change any of these settings later, edit /etc/rc.conf");
-
- restorescr(w);
- return DITEM_SUCCESS;
-}
-
-static void
-write_root_xprofile(char *str)
-{
- FILE *fp;
- int len;
- char **cp;
- static char *flist[] = { /* take care of both xdm and startx */
- "/root/.xinitrc",
- "/root/.xsession",
- "/usr/share/skel/dot.xinitrc",
- "/usr/share/skel/dot.xsession",
- NULL,
- };
-
- len = strlen(str);
- for (cp = flist; *cp; cp++) {
- fp = fopen(*cp, "w");
- if (fp) {
- fwrite(str, 1, len, fp);
- fchmod(fileno(fp), 0755);
- fclose(fp);
- }
- }
-}
-
-static int
-gotit(char *fname)
-{
- char tmp[FILENAME_MAX];
-
- snprintf(tmp, sizeof tmp, "/usr/X11R6/bin/%s", fname);
- if (file_executable(tmp))
- return TRUE;
- snprintf(tmp, sizeof tmp, "/usr/local/bin/%s", fname);
- return file_executable(tmp);
-}
-
-int
-configXDesktop(dialogMenuItem *self)
-{
- char *desk;
- int ret = DITEM_SUCCESS;
- WINDOW *w = savescr();
-
- dialog_clear_norefresh();
- if (!dmenuOpenSimple(&MenuXDesktops, FALSE) || !(desk = variable_get(VAR_DESKSTYLE))) {
- restorescr(w);
- return DITEM_FAILURE;
- }
- if (!strcmp(desk, "kde")) {
- ret = package_add("kde");
- if (DITEM_STATUS(ret) != DITEM_FAILURE && gotit("startkde"))
- write_root_xprofile("exec startkde\n");
- }
- else if (!strcmp(desk, "gnome2")) {
- ret = package_add("gnome2");
- if (DITEM_STATUS(ret) != DITEM_FAILURE && gotit("gnome-session"))
- write_root_xprofile("exec gnome-session\n");
- }
- else if (!strcmp(desk, "afterstep")) {
- ret = package_add("afterstep");
- if (DITEM_STATUS(ret) != DITEM_FAILURE && gotit("afterstep"))
- write_root_xprofile("exec afterstep\n");
- }
- else if (!strcmp(desk, "windowmaker")) {
- ret = package_add("windowmaker");
- if (DITEM_STATUS(ret) != DITEM_FAILURE && gotit("wmaker.inst")) {
- write_root_xprofile("xterm &\n[ ! -d $HOME/GNUstep/Library/WindowMaker ] && /usr/X11R6/bin/wmaker.inst\nexec /usr/X11R6/bin/wmaker\n");
- }
- }
- else if (!strcmp(desk, "fvwm2")) {
- ret = package_add("fvwm");
- if (DITEM_STATUS(ret) != DITEM_FAILURE && gotit("fvwm"))
- write_root_xprofile("exec fvwm\n");
- }
- if (DITEM_STATUS(ret) == DITEM_FAILURE)
- msgConfirm("An error occurred while adding the package(s) required\n"
- "by this desktop type. Please change installation media\n"
- "and/or select a different, perhaps simpler, desktop\n"
- "environment and try again.");
- restorescr(w);
- return ret;
-}
-
-int
-configXSetup(dialogMenuItem *self)
-{
- char *config, *execfile, *execcmd, *style, *tmp;
-#ifdef WITH_MICE
- char *moused;
-#endif
- WINDOW *w = savescr();
-
- setenv("XWINHOME", "/usr/X11R6", 1);
-tryagain:
- variable_unset(VAR_DESKSTYLE);
- variable_unset(VAR_XF86_CONFIG);
- dialog_clear_norefresh();
- if (!dmenuOpenSimple(&MenuXF86Config, FALSE)) {
- restorescr(w);
- return DITEM_FAILURE;
- }
- config = variable_get(VAR_XF86_CONFIG);
- style = variable_get(VAR_DESKSTYLE);
- if (!config) {
- if (style)
- goto config_desktop;
- else {
- restorescr(w);
- return DITEM_FAILURE;
- }
- }
-
- if (file_readable("/var/run/ld-elf.so.hints"))
- vsystem("/sbin/ldconfig -m /usr/lib /usr/X11R6/lib /usr/local/lib /usr/lib/compat");
- else
- vsystem("/sbin/ldconfig /usr/lib /usr/X11R6/lib /usr/local/lib /usr/lib/compat");
- if (file_readable("/var/run/ld.so.hints"))
- vsystem("ldconfig -m -aout /usr/lib/aout /usr/lib/compat/aout /usr/local/lib/aout /usr/X11R6/lib/aout");
- else
- vsystem("ldconfig -aout /usr/lib/aout /usr/lib/compat/aout /usr/local/lib/aout /usr/X11R6/lib/aout");
-
- vsystem("/sbin/ifconfig lo0 127.0.0.1");
-
- /*
- * execcmd may have been passed in as a command name with
- * arguments. Therefore, before determining if it is suitable for
- * execution, we must split off the filename component from the
- * command line arguments.
- */
-
- execcmd = string_concat("/usr/X11R6/bin/", config);
- execfile = strdup(execcmd);
- if ((tmp = strchr(execfile, ' ')))
- *tmp = '\0';
- if (file_executable(execfile)) {
- free(execfile);
-#ifdef WITH_MICE
- moused = variable_get(VAR_MOUSED);
- while (!moused || strcmp(moused, "YES")) {
- if (msgYesNo("The X server may access the mouse in two ways: direct access\n"
- "or indirect access via the mouse daemon. You have not\n"
- "configured the mouse daemon. Would you like to configure it\n"
- "now? If you intend to let the X server access the mouse\n"
- "directly, choose \"No\" at this time."))
- break;
- dialog_clear_norefresh();
- dmenuOpenSimple(&MenuMouse, FALSE);
- moused = variable_get(VAR_MOUSED);
- }
- if (moused && !strcmp(moused, "YES"))
- msgConfirm("You have configured and are now running the mouse daemon.\n"
- "Choose \"/dev/sysmouse\" as the mouse port and \"SysMouse\" or\n"
- "\"MouseSystems\" as the mouse protocol in the X configuration\n"
- "utility.");
-#endif
- Mkdir("/etc/X11"); /* XXX:Remove this later after we are happy mtree will have created this for us. */
- systemExecute(execcmd);
- if (!file_readable("/etc/X11/XF86Config")) {
- if (!msgYesNo("The XFree86 configuration process seems to have\nfailed. Would you like to try again?"))
- goto tryagain;
- else {
- restorescr(w);
- return DITEM_FAILURE;
- }
- }
-config_desktop:
- configXDesktop(self);
- restorescr(w);
- return DITEM_SUCCESS;
- }
- else {
- free(execfile);
- msgConfirm("The XFree86 setup utility you chose does not appear to be installed!\n"
- "Please install this before attempting to configure XFree86.");
- restorescr(w);
- return DITEM_FAILURE;
- }
-}
-
-int
-configResolv(dialogMenuItem *ditem)
-{
- FILE *fp;
- char *cp, *c6p, *dp, *hp;
-
- cp = variable_get(VAR_NAMESERVER);
- if (!cp || !*cp)
- goto skip;
- Mkdir("/etc");
- fp = fopen("/etc/resolv.conf", "w");
- if (!fp)
- return DITEM_FAILURE;
- if (variable_get(VAR_DOMAINNAME))
- fprintf(fp, "domain\t%s\n", variable_get(VAR_DOMAINNAME));
- fprintf(fp, "nameserver\t%s\n", cp);
- fclose(fp);
- if (isDebug())
- msgDebug("Wrote out /etc/resolv.conf\n");
-
-skip:
- dp = variable_get(VAR_DOMAINNAME);
- cp = variable_get(VAR_IPADDR);
- c6p = variable_get(VAR_IPV6ADDR);
- hp = variable_get(VAR_HOSTNAME);
- /* Tack ourselves into /etc/hosts */
- fp = fopen("/etc/hosts", "w");
- if (!fp)
- return DITEM_FAILURE;
- /* Add an entry for localhost */
- if (!variable_cmp(VAR_IPV6_ENABLE, "YES")) {
- if (dp)
- fprintf(fp, "::1\t\t\tlocalhost.%s localhost\n", dp);
- else
- fprintf(fp, "::1\t\t\tlocalhost\n");
- }
- if (dp)
- fprintf(fp, "127.0.0.1\t\tlocalhost.%s localhost\n", dp);
- else
- fprintf(fp, "127.0.0.1\t\tlocalhost\n");
- /* Now the host entries, if applicable */
- if (((cp && cp[0] != '0') || (c6p && c6p[0] != '0')) && hp) {
- char cp2[255];
-
- if (!index(hp, '.'))
- cp2[0] = '\0';
- else {
- SAFE_STRCPY(cp2, hp);
- *(index(cp2, '.')) = '\0';
- }
- if (c6p && c6p[0] != '0') {
- fprintf(fp, "%s\t%s %s\n", c6p, hp, cp2);
- fprintf(fp, "%s\t%s.\n", c6p, hp);
- }
- if (cp && cp[0] != '0') {
- fprintf(fp, "%s\t\t%s %s\n", cp, hp, cp2);
- fprintf(fp, "%s\t\t%s.\n", cp, hp);
- }
- }
- fclose(fp);
- if (isDebug())
- msgDebug("Wrote out /etc/hosts\n");
- return DITEM_SUCCESS;
-}
-
-int
-configRouter(dialogMenuItem *self)
-{
- int ret;
-
- ret = variable_get_value(VAR_ROUTER,
- "Please specify the router you wish to use. Routed is\n"
- "provided with the stock system and gated is provided\n"
- "as an optional package which this installation system\n"
- "will attempt to load if you select gated. Any other\n"
- "choice of routing daemon will be assumed to be something\n"
- "the user intends to install themselves before rebooting\n"
- "the system. If you don't want any routing daemon, choose NO", 1)
- ? DITEM_SUCCESS : DITEM_FAILURE;
-
- if (ret == DITEM_SUCCESS) {
- char *cp = variable_get(VAR_ROUTER);
-
- if (cp && strcmp(cp, "NO")) {
- variable_set2(VAR_ROUTER_ENABLE, "YES", 1);
- if (!strcmp(cp, "gated")) {
- if (package_add("gated") != DITEM_SUCCESS) {
- msgConfirm("Unable to load gated package. Falling back to no router.");
- variable_unset(VAR_ROUTER);
- variable_unset(VAR_ROUTERFLAGS);
- variable_set2(VAR_ROUTER_ENABLE, "NO", 1);
- cp = NULL;
- }
- }
- if (cp) {
- /* Now get the flags, if they chose a router */
- ret = variable_get_value(VAR_ROUTERFLAGS,
- "Please Specify the routing daemon flags; if you're running routed\n"
- "then -q is the right choice for nodes and -s for gateway hosts.\n", 1)
- ? DITEM_SUCCESS : DITEM_FAILURE;
- if (ret != DITEM_SUCCESS)
- variable_unset(VAR_ROUTERFLAGS);
- }
- }
- else {
- /* No router case */
- variable_set2(VAR_ROUTER_ENABLE, "NO", 1);
- variable_unset(VAR_ROUTERFLAGS);
- variable_unset(VAR_ROUTER);
- }
- }
- else {
- variable_set2(VAR_ROUTER_ENABLE, "NO", 1);
- variable_unset(VAR_ROUTERFLAGS);
- variable_unset(VAR_ROUTER);
- }
- return ret;
-}
-
-/* Shared between us and index_initialize() */
-extern PkgNode Top, Plist;
-
-int
-configPackages(dialogMenuItem *self)
-{
- int i, restoreflag = 0;
- PkgNodePtr tmp;
-
- /* Did we get an INDEX? */
- i = index_initialize("packages/INDEX");
- if (DITEM_STATUS(i) == DITEM_FAILURE)
- return i;
-
- while (1) {
- int ret, pos, scroll;
-
- /* Bring up the packages menu */
- pos = scroll = 0;
- index_menu(&Top, &Top, &Plist, &pos, &scroll);
-
- if (Plist.kids && Plist.kids->name) {
- /* Now show the packing list menu */
- pos = scroll = 0;
- ret = index_menu(&Plist, &Plist, NULL, &pos, &scroll);
- if (ret & DITEM_LEAVE_MENU)
- break;
- else if (DITEM_STATUS(ret) != DITEM_FAILURE) {
- dialog_clear();
- restoreflag = 1;
- for (tmp = Plist.kids; tmp && tmp->name; tmp = tmp->next)
- (void)index_extract(mediaDevice, &Top, tmp, FALSE);
- break;
- }
- }
- else {
- msgConfirm("No packages were selected for extraction.");
- break;
- }
- }
- tmp = Plist.kids;
- while (tmp) {
- PkgNodePtr tmp2 = tmp->next;
-
- safe_free(tmp);
- tmp = tmp2;
- }
- index_init(NULL, &Plist);
- return DITEM_SUCCESS | (restoreflag ? DITEM_RESTORE : 0);
-}
-
-/* Load pcnfsd package */
-int
-configPCNFSD(dialogMenuItem *self)
-{
- int ret;
-
- ret = package_add("pcnfsd");
- if (DITEM_STATUS(ret) == DITEM_SUCCESS) {
- variable_set2(VAR_PCNFSD, "YES", 0);
- variable_set2("mountd_flags", "-n", 1);
- }
- return ret;
-}
-
-int
-configInetd(dialogMenuItem *self)
-{
- char cmd[256];
-
- WINDOW *w = savescr();
-
- if (msgYesNo("The Internet Super Server (inetd) allows a number of simple Internet\n"
- "services to be enabled, including finger, ftp, and telnetd. Enabling\n"
- "these services may increase risk of security problems by increasing\n"
- "the exposure of your system.\n\n"
- "With this in mind, do you wish to enable inetd?\n")) {
- variable_set2("inetd_enable", "NO", 1);
- } else {
- /* If inetd is enabled, we'll need an inetd.conf */
- variable_set2("inetd_enable", "YES", 1);
- if (!msgYesNo("inetd(8) relies on its configuration file, /etc/inetd.conf, to determine\n"
- "which of its Internet services will be available. The default FreeBSD\n"
- "inetd.conf(5) leaves all services disabled by default, so they must be\n"
- "specifically enabled in the configuration file before they will\n"
- "function, even once inetd(8) is enabled. Note that services for\n"
- "IPv6 must be separately enabled from IPv4 services.\n\n"
- "Select [Yes] now to invoke an editor on /etc/inetd.conf, or [No] to\n"
- "use the current settings.\n")) {
- sprintf(cmd, "%s /etc/inetd.conf", variable_get(VAR_EDITOR));
- dialog_clear();
- systemExecute(cmd);
- }
- }
- restorescr(w);
- return DITEM_SUCCESS;
-}
-
-int
-configNFSServer(dialogMenuItem *self)
-{
- char cmd[256];
- int retval = 0;
-
- /* If we're an NFS server, we need an exports file */
- if (!file_readable("/etc/exports")) {
- WINDOW *w = savescr();
-
- if (file_readable("/etc/exports.disabled"))
- vsystem("mv /etc/exports.disabled /etc/exports");
- else {
- dialog_clear_norefresh();
- msgConfirm("Operating as an NFS server means that you must first configure\n"
- "an /etc/exports file to indicate which hosts are allowed certain\n"
- "kinds of access to your local file systems.\n"
- "Press [ENTER] now to invoke an editor on /etc/exports\n");
- vsystem("echo '#The following examples export /usr to 3 machines named after ducks,' > /etc/exports");
- vsystem("echo '#/usr/src and /usr/ports read-only to machines named after trouble makers' >> /etc/exports");
- vsystem("echo '#/home and all directories under it to machines named after dead rock stars' >> /etc/exports");
- vsystem("echo '#and, /a to a network of privileged machines allowed to write on it as root.' >> /etc/exports");
- vsystem("echo '#/usr huey louie dewie' >> /etc/exports");
- vsystem("echo '#/usr/src /usr/obj -ro calvin hobbes' >> /etc/exports");
- vsystem("echo '#/home -alldirs janice jimmy frank' >> /etc/exports");
- vsystem("echo '#/a -maproot=0 -network 10.0.1.0 -mask 255.255.248.0' >> /etc/exports");
- vsystem("echo '#' >> /etc/exports");
- vsystem("echo '# You should replace these lines with your actual exported filesystems.' >> /etc/exports");
- vsystem("echo '# Note that BSD's export synatx is \"host-centric\" vs. Sun\'s \"FS-centric\" one.' >> /etc/exports");
- vsystem("echo >> /etc/exports");
- sprintf(cmd, "%s /etc/exports", variable_get(VAR_EDITOR));
- dialog_clear();
- systemExecute(cmd);
- }
- variable_set2(VAR_NFS_SERVER, "YES", 1);
- retval = configRpcBind(NULL);
- restorescr(w);
- }
- else if (variable_get(VAR_NFS_SERVER)) { /* We want to turn it off again? */
- vsystem("mv -f /etc/exports /etc/exports.disabled");
- variable_unset(VAR_NFS_SERVER);
- }
- return DITEM_SUCCESS | retval;
-}
-
-/*
- * Extend the standard dmenuToggleVariable() method to also check and set
- * the rpcbind variable if needed.
- */
-int
-configRpcBind(dialogMenuItem *self)
-{
- int retval = 0;
- int doupdate = 1;
-
- if (self != NULL) {
- retval = dmenuToggleVariable(self);
- if (strcmp(variable_get(self->data), "YES") != 0)
- doupdate = 0;
- }
-
- if (doupdate && strcmp(variable_get(VAR_RPCBIND_ENABLE), "YES") != 0) {
- variable_set2(VAR_RPCBIND_ENABLE, "YES", 1);
- retval |= DITEM_REDRAW;
- }
-
- return retval;
-}
-
-int
-configEtcTtys(dialogMenuItem *self)
-{
- char cmd[256];
-
- WINDOW *w = savescr();
-
- /* Simply prompt for confirmation, then edit away. */
- if (msgYesNo("Configuration of system TTYs requires editing the /etc/ttys file.\n"
- "Typical configuration activities might include enabling getty(8)\n"
- "on the first serial port to allow login via serial console after\n"
- "reboot, or to enable xdm. The default ttys file enables normal\n"
- "virtual consoles, and most sites will not need to perform manual\n"
- "configuration.\n\n"
- "To load /etc/ttys in the editor, select [Yes], otherwise, [No].")) {
- } else {
- configTtys();
- sprintf(cmd, "%s /etc/ttys", variable_get(VAR_EDITOR));
- dialog_clear();
- systemExecute(cmd);
- }
-
- restorescr(w);
- return DITEM_SUCCESS;
-}
-
-#ifdef __i386__
-int
-checkLoaderACPI(void)
-{
- char val[4];
-
- if (kenv(KENV_GET, "loader.acpi_disabled_by_user", &val[0], 4) <= 0) {
- return (0);
- }
-
- if (strtol(&val[0], NULL, 10) <= 0) {
- return (0);
- }
-
- return (1);
-}
-
-int
-configLoaderACPI(int disable)
-{
- FILE *ldconf;
-
- ldconf = fopen("/boot/loader.conf", "a");
- if (ldconf == NULL) {
- msgConfirm("Unable to open /boot/loader.conf. Please consult the\n"
- "FreeBSD Handbook for instructions on disabling ACPI");
- return DITEM_FAILURE;
- }
-
- fprintf(ldconf, "# --- Generated by sysinstall ---\n");
- fprintf(ldconf, "hint.acpi.0.disabled=%d\n", disable);
- fclose(ldconf);
-
- return DITEM_SUCCESS;
-}
-#endif
diff --git a/usr.sbin/sade/devices.c b/usr.sbin/sade/devices.c
deleted file mode 100644
index 83b52f785647..000000000000
--- a/usr.sbin/sade/devices.c
+++ /dev/null
@@ -1,578 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last program in the `sysinstall' line - the next
- * generation being essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-#include <sys/fcntl.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <sys/errno.h>
-#include <sys/time.h>
-#include <net/if.h>
-#include <net/if_var.h>
-#include <net/if_dl.h>
-#include <netinet/in.h>
-#include <netinet/in_var.h>
-#include <arpa/inet.h>
-#include <ctype.h>
-
-/* how much to bias minor number for a given /dev/<ct#><un#>s<s#> slice */
-#define SLICE_DELTA (0x10000)
-
-static Device *Devices[DEV_MAX];
-static int numDevs;
-
-static struct _devname {
- DeviceType type;
- char *name;
- char *description;
- int major, minor, delta, max;
-} device_names[] = {
- { DEVICE_TYPE_CDROM, "cd%d", "SCSI CDROM drive", 15, 2, 8, 4 },
- { DEVICE_TYPE_CDROM, "mcd%d", "Mitsumi (old model) CDROM drive", 29, 0, 8, 4 },
- { DEVICE_TYPE_CDROM, "scd%d", "Sony CDROM drive - CDU31/33A type", 45, 0, 8, 4 },
-#ifdef notdef
- { DEVICE_TYPE_CDROM, "matcd%d", "Matsushita CDROM ('sound blaster' type)", 46, 0, 8, 4 },
-#endif
- { DEVICE_TYPE_CDROM, "acd%d", "ATAPI/IDE CDROM", 117, 0, 8, 4 },
- { DEVICE_TYPE_TAPE, "rsa%d", "SCSI tape drive", 14, 0, 16, 4 },
- { DEVICE_TYPE_TAPE, "rwt%d", "Wangtek tape drive", 10, 0, 1, 4 },
- { DEVICE_TYPE_DISK, "da%d", "SCSI disk device", 13, 65538, 8, 16 },
- { DEVICE_TYPE_DISK, "ad%d", "ATA/IDE disk device", 116, 65538, 8, 16 },
- { DEVICE_TYPE_DISK, "ar%d", "ATA/IDE RAID device", 157, 65538, 8, 16 },
- { DEVICE_TYPE_DISK, "fla%d", "M-Systems DiskOnChip Flash devicee", 102, 65538, 8, 16 },
- { DEVICE_TYPE_DISK, "afd%d", "ATAPI/IDE floppy device", 118, 65538, 8, 4 },
- { DEVICE_TYPE_DISK, "mlxd%d", "Mylex RAID disk", 131, 65538, 8, 4 },
- { DEVICE_TYPE_DISK, "amrd%d", "AMI MegaRAID drive", 133, 65538, 8, 4 },
- { DEVICE_TYPE_DISK, "idad%d", "Compaq RAID array", 109, 65538, 8, 4 },
- { DEVICE_TYPE_DISK, "twed%d", "3ware ATA RAID array", 147, 65538, 8, 4 },
- { DEVICE_TYPE_DISK, "aacd%d", "Adaptec FSA RAID array", 151, 65538, 8, 4 },
- { DEVICE_TYPE_DISK, "ipsd%d", "IBM ServeRAID RAID array", 176, 65538, 8, 4 },
- { DEVICE_TYPE_FLOPPY, "fd%d", "floppy drive unit A", 9, 0, 64, 4 },
- { DEVICE_TYPE_NETWORK, "an", "Aironet 4500/4800 802.11 wireless adapter" },
- { DEVICE_TYPE_NETWORK, "aue", "ADMtek USB ethernet adapter" },
- { DEVICE_TYPE_NETWORK, "axe", "ASIX Electronics USB ethernet adapter" },
- { DEVICE_TYPE_NETWORK, "bge", "Broadcom BCM570x PCI gigabit ethernet card" },
- { DEVICE_TYPE_NETWORK, "cue", "CATC USB ethernet adapter" },
- { DEVICE_TYPE_NETWORK, "fpa", "DEC DEFPA PCI FDDI card" },
- { DEVICE_TYPE_NETWORK, "sr", "SDL T1/E1 sync serial PCI card" },
- { DEVICE_TYPE_NETWORK, "cc3i", "SDL HSSI sync serial PCI card" },
- { DEVICE_TYPE_NETWORK, "en", "Efficient Networks ATM PCI card" },
- { DEVICE_TYPE_NETWORK, "dc", "DEC/Intel 21143 (and clones) PCI fast ethernet card" },
- { DEVICE_TYPE_NETWORK, "de", "DEC DE435 PCI NIC or other DC21040-AA based card" },
- { DEVICE_TYPE_NETWORK, "fxp", "Intel EtherExpress Pro/100B PCI Fast Ethernet card" },
- { DEVICE_TYPE_NETWORK, "ed", "Novell NE1000/2000; 3C503; NE2000-compatible PCMCIA" },
- { DEVICE_TYPE_NETWORK, "ep", "3Com 3C509 ethernet card/3C589 PCMCIA" },
- { DEVICE_TYPE_NETWORK, "el", "3Com 3C501 ethernet card" },
- { DEVICE_TYPE_NETWORK, "em", "Intel(R) PRO/1000 ethernet card" },
- { DEVICE_TYPE_NETWORK, "ex", "Intel EtherExpress Pro/10 ethernet card" },
- { DEVICE_TYPE_NETWORK, "fe", "Fujitsu MB86960A/MB86965A ethernet card" },
- { DEVICE_TYPE_NETWORK, "ie", "AT&T StarLAN 10 and EN100; 3Com 3C507; NI5210" },
- { DEVICE_TYPE_NETWORK, "ix", "Intel Etherexpress ethernet card" },
- { DEVICE_TYPE_NETWORK, "kue", "Kawasaki LSI USB ethernet adapter" },
- { DEVICE_TYPE_NETWORK, "le", "DEC EtherWorks 2 or 3 ethernet card" },
- { DEVICE_TYPE_NETWORK, "lnc", "Lance/PCnet (Isolan/Novell NE2100/NE32-VL) ethernet" },
- { DEVICE_TYPE_NETWORK, "lge", "Level 1 LXT1001 gigabit ethernet card" },
- { DEVICE_TYPE_NETWORK, "nge", "NatSemi PCI gigabit ethernet card" },
- { DEVICE_TYPE_NETWORK, "pcn", "AMD Am79c79x PCI ethernet card" },
- { DEVICE_TYPE_NETWORK, "ray", "Raytheon Raylink 802.11 wireless adaptor" },
- { DEVICE_TYPE_NETWORK, "rl", "RealTek 8129/8139 PCI ethernet card" },
- { DEVICE_TYPE_NETWORK, "sf", "Adaptec AIC-6915 PCI ethernet card" },
- { DEVICE_TYPE_NETWORK, "sis", "SiS 900/SiS 7016 PCI ethernet card" },
-#ifdef PC98
- { DEVICE_TYPE_NETWORK, "snc", "SONIC ethernet card" },
-#endif
- { DEVICE_TYPE_NETWORK, "sn", "SMC/Megahertz ethernet card" },
- { DEVICE_TYPE_NETWORK, "ste", "Sundance ST201 PCI ethernet card" },
- { DEVICE_TYPE_NETWORK, "sk", "SysKonnect PCI gigabit ethernet card" },
- { DEVICE_TYPE_NETWORK, "tx", "SMC 9432TX ethernet card" },
- { DEVICE_TYPE_NETWORK, "txp", "3Com 3cR990 ethernet card" },
- { DEVICE_TYPE_NETWORK, "ti", "Alteon Networks PCI gigabit ethernet card" },
- { DEVICE_TYPE_NETWORK, "tl", "Texas Instruments ThunderLAN PCI ethernet card" },
- { DEVICE_TYPE_NETWORK, "vr", "VIA VT3043/VT86C100A Rhine PCI ethernet card" },
- { DEVICE_TYPE_NETWORK, "vlan", "IEEE 802.1Q VLAN network interface" },
- { DEVICE_TYPE_NETWORK, "vx", "3COM 3c590 / 3c595 ethernet card" },
- { DEVICE_TYPE_NETWORK, "wb", "Winbond W89C840F PCI ethernet card" },
- { DEVICE_TYPE_NETWORK, "wi", "Lucent WaveLAN/IEEE 802.11 wireless adapter" },
- { DEVICE_TYPE_NETWORK, "wx", "Intel Gigabit Ethernet (82452) card" },
- { DEVICE_TYPE_NETWORK, "xe", "Xircom/Intel EtherExpress Pro100/16 ethernet card" },
- { DEVICE_TYPE_NETWORK, "xl", "3COM 3c90x / 3c90xB PCI ethernet card" },
- { DEVICE_TYPE_NETWORK, "cuaa%d", "%s on device %s (COM%d)", 28, 128, 1, 16 },
- { DEVICE_TYPE_NETWORK, "lp", "Parallel Port IP (PLIP) peer connection" },
- { DEVICE_TYPE_NETWORK, "lo", "Loop-back (local) network interface" },
- { DEVICE_TYPE_NETWORK, "disc", "Software discard network interface" },
-#ifdef PC98
- { DEVICE_TYPE_DISK, "wd%d", "IDE disk device", 3, 65538, 8, 16 },
- { DEVICE_TYPE_CDROM, "wcd%dc", "ATAPI IDE CDROM", 69, 2, 8, 4 },
- { DEVICE_TYPE_FLOPPY, "wfd%d", "ATAPI floppy drive unit A", 87, 0, 8, 4 },
- { DEVICE_TYPE_DISK, "wfd%d", "ATAPI floppy device", 87, 65538, 8, 4 },
-#endif
- { 0 },
-};
-
-Device *
-new_device(char *name)
-{
- Device *dev;
-
- dev = safe_malloc(sizeof(Device));
- bzero(dev, sizeof(Device));
- if (name)
- SAFE_STRCPY(dev->name, name);
- return dev;
-}
-
-/* Stubs for unimplemented strategy routines */
-Boolean
-dummyInit(Device *dev)
-{
- return TRUE;
-}
-
-FILE *
-dummyGet(Device *dev, char *dist, Boolean probe)
-{
- return NULL;
-}
-
-void
-dummyShutdown(Device *dev)
-{
- return;
-}
-
-static int
-deviceTry(struct _devname dev, char *try, int i)
-{
- int fd;
- char unit[80];
- mode_t m;
- dev_t d;
- int fail;
-
- snprintf(unit, sizeof unit, dev.name, i);
- snprintf(try, FILENAME_MAX, "/dev/%s", unit);
- if (isDebug())
- msgDebug("deviceTry: attempting to open %s\n", try);
- fd = open(try, O_RDONLY);
- if (fd >= 0) {
- if (isDebug())
- msgDebug("deviceTry: open of %s succeeded on first try.\n", try);
- return fd;
- }
- m = 0640 | S_IFCHR;
- d = makedev(dev.major, dev.minor + (i * dev.delta));
- if (isDebug())
- msgDebug("deviceTry: Making %s device for %s [%d, %d]\n", m & S_IFCHR ? "raw" : "block", try, dev.major, dev.minor + (i * dev.delta));
- fail = mknod(try, m, d);
- fd = open(try, O_RDONLY);
- if (fd >= 0) {
- if (isDebug())
- msgDebug("deviceTry: open of %s succeeded on second try.\n", try);
- return fd;
- }
- else if (!fail)
- (void)unlink(try);
- /* Don't try a "make-under" here since we're using a fixit floppy in this case */
- snprintf(try, FILENAME_MAX, "/mnt/dev/%s", unit);
- fd = open(try, O_RDONLY);
- if (isDebug())
- msgDebug("deviceTry: final attempt for %s returns %d\n", try, fd);
- return fd;
-}
-
-/* Register a new device in the devices array */
-Device *
-deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean enabled,
- Boolean (*init)(Device *), FILE * (*get)(Device *, char *, Boolean),
- void (*shutdown)(Device *), void *private)
-{
- Device *newdev = NULL;
-
- if (numDevs == DEV_MAX)
- msgFatal("Too many devices found!");
- else {
- newdev = new_device(name);
- newdev->description = desc;
- newdev->devname = devname;
- newdev->type = type;
- newdev->enabled = enabled;
- newdev->init = init ? init : dummyInit;
- newdev->get = get ? get : dummyGet;
- newdev->shutdown = shutdown ? shutdown : dummyShutdown;
- newdev->private = private;
- Devices[numDevs] = newdev;
- Devices[++numDevs] = NULL;
- }
- return newdev;
-}
-
-/* Reset the registered device chain */
-void
-deviceReset(void)
-{
- int i;
-
- for (i = 0; i < numDevs; i++) {
- DEVICE_SHUTDOWN(Devices[i]);
-
- /* XXX this potentially leaks Devices[i]->private if it's being
- * used to point to something dynamic, but you're not supposed
- * to call this routine at such times that some open instance
- * has its private ptr pointing somewhere anyway. XXX
- */
- free(Devices[i]);
- }
- Devices[numDevs = 0] = NULL;
-}
-
-/* Get all device information for devices we have attached */
-void
-deviceGetAll(void)
-{
- int i, j, fd, s;
- struct ifconf ifc;
- struct ifreq *ifptr, *end;
- int ifflags;
- char buffer[INTERFACE_MAX * sizeof(struct ifreq)];
- char **names;
-
- msgNotify("Probing devices, please wait (this can take a while)...");
- /* First go for the network interfaces. Stolen shamelessly from ifconfig! */
- ifc.ifc_len = sizeof(buffer);
- ifc.ifc_buf = buffer;
-
- s = socket(AF_INET, SOCK_DGRAM, 0);
- if (s < 0)
- goto skipif; /* Jump over network iface probing */
-
- if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0)
- goto skipif; /* Jump over network iface probing */
-
- close(s);
- ifflags = ifc.ifc_req->ifr_flags;
- end = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
- for (ifptr = ifc.ifc_req; ifptr < end; ifptr++) {
- char *descr;
-
- /* If it's not a link entry, forget it */
- if (ifptr->ifr_ifru.ifru_addr.sa_family != AF_LINK)
- goto loopend;
-
- /* Eliminate network devices that don't make sense */
- if (!strncmp(ifptr->ifr_name, "lo", 2))
- goto loopend;
-
- /* If we have a slip device, don't register it */
- if (!strncmp(ifptr->ifr_name, "sl", 2)) {
- goto loopend;
- }
- /* And the same for ppp */
- if (!strncmp(ifptr->ifr_name, "tun", 3) || !strncmp(ifptr->ifr_name, "ppp", 3)) {
- goto loopend;
- }
- /* Try and find its description */
- for (i = 0, descr = NULL; device_names[i].name; i++) {
- int len = strlen(device_names[i].name);
-
- if (!ifptr->ifr_name || !ifptr->ifr_name[0])
- continue;
- else if (!strncmp(ifptr->ifr_name, device_names[i].name, len)) {
- descr = device_names[i].description;
- break;
- }
- }
- if (!descr)
- descr = "<unknown network interface type>";
-
- deviceRegister(ifptr->ifr_name, descr, strdup(ifptr->ifr_name), DEVICE_TYPE_NETWORK, TRUE,
- mediaInitNetwork, NULL, mediaShutdownNetwork, NULL);
- if (isDebug())
- msgDebug("Found a network device named %s\n", ifptr->ifr_name);
- close(s);
- if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- continue;
-
-loopend:
- if (ifptr->ifr_addr.sa_len) /* I'm not sure why this is here - it's inherited */
- ifptr = (struct ifreq *)((caddr_t)ifptr + ifptr->ifr_addr.sa_len - sizeof(struct sockaddr));
- close(s);
- }
-
-skipif:
- /* Next, try to find all the types of devices one might need
- * during the second stage of the installation.
- */
- for (i = 0; device_names[i].name; i++) {
- for (j = 0; j < device_names[i].max; j++) {
- char try[FILENAME_MAX];
-
- switch(device_names[i].type) {
- case DEVICE_TYPE_CDROM:
- fd = deviceTry(device_names[i], try, j);
- if (fd >= 0 || errno == EBUSY) { /* EBUSY if already mounted */
- char n[BUFSIZ];
-
- if (fd >= 0) close(fd);
- snprintf(n, sizeof n, device_names[i].name, j);
- deviceRegister(strdup(n), device_names[i].description, strdup(try),
- DEVICE_TYPE_CDROM, TRUE, mediaInitCDROM, mediaGetCDROM,
- mediaShutdownCDROM, NULL);
- if (isDebug())
- msgDebug("Found a CDROM device for %s\n", try);
- }
- break;
-
- case DEVICE_TYPE_TAPE:
- fd = deviceTry(device_names[i], try, j);
- if (fd >= 0) {
- char n[BUFSIZ];
-
- close(fd);
- snprintf(n, sizeof n, device_names[i].name, j);
- deviceRegister(strdup(n), device_names[i].description, strdup(try),
- DEVICE_TYPE_TAPE, TRUE, mediaInitTape, mediaGetTape, mediaShutdownTape, NULL);
- if (isDebug())
- msgDebug("Found a TAPE device for %s\n", try);
- }
- break;
-
- case DEVICE_TYPE_DISK:
- fd = deviceTry(device_names[i], try, j);
- if (fd >= 0 && RunningAsInit) {
- dev_t d;
- mode_t m;
- int s, fail;
- char unit[80], slice[80];
-
- close(fd);
- /* Make associated slice entries */
- for (s = 1; s < 8; s++) {
- snprintf(unit, sizeof unit, device_names[i].name, j);
- snprintf(slice, sizeof slice, "/dev/%ss%d", unit, s);
- d = makedev(device_names[i].major, device_names[i].minor +
- (j * device_names[i].delta) + (s * SLICE_DELTA));
- m = 0640 | S_IFCHR;
- fail = mknod(slice, m, d);
- fd = open(slice, O_RDONLY);
- if (fd >= 0)
- close(fd);
- else if (!fail)
- (void)unlink(slice);
- }
- }
- break;
-
- case DEVICE_TYPE_FLOPPY:
- fd = deviceTry(device_names[i], try, j);
- if (fd >= 0) {
- char n[BUFSIZ];
-
- close(fd);
- snprintf(n, sizeof n, device_names[i].name, j);
- deviceRegister(strdup(n), device_names[i].description, strdup(try),
- DEVICE_TYPE_FLOPPY, TRUE, mediaInitFloppy, mediaGetFloppy,
- mediaShutdownFloppy, NULL);
- if (isDebug())
- msgDebug("Found a floppy device for %s\n", try);
- }
- break;
-
- case DEVICE_TYPE_NETWORK:
- fd = deviceTry(device_names[i], try, j);
- /* The only network devices that you can open this way are serial ones */
- if (fd >= 0) {
- char *newdesc, *cp;
-
- close(fd);
- cp = device_names[i].description;
- /* Serial devices get a slip and ppp device each, if supported */
- newdesc = safe_malloc(strlen(cp) + 40);
- sprintf(newdesc, cp, "SLIP interface", try, j + 1);
- deviceRegister("sl0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork,
- NULL, mediaShutdownNetwork, NULL);
- msgDebug("Add mapping for %s to sl0\n", try);
- newdesc = safe_malloc(strlen(cp) + 50);
- sprintf(newdesc, cp, "PPP interface", try, j + 1);
- deviceRegister("ppp0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork,
- NULL, mediaShutdownNetwork, NULL);
- if (isDebug())
- msgDebug("Add mapping for %s to ppp0\n", try);
- }
- break;
-
- default:
- break;
- }
- }
- }
-
- /* Finally, go get the disks and look for DOS partitions to register */
- if ((names = Disk_Names()) != NULL) {
- int i;
-
- for (i = 0; names[i]; i++) {
- Chunk *c1;
- Disk *d;
-
- /* Ignore memory disks */
- if (!strncmp(names[i], "md", 2))
- continue;
-
- d = Open_Disk(names[i]);
- if (!d) {
- msgDebug("Unable to open disk %s\n", names[i]);
- continue;
- }
-
- deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK, FALSE,
- dummyInit, dummyGet, dummyShutdown, d);
- if (isDebug())
- msgDebug("Found a disk device named %s\n", names[i]);
-
- /* Look for existing DOS partitions to register as "DOS media devices" */
- for (c1 = d->chunks->part; c1; c1 = c1->next) {
- if (c1->type == fat || c1->type == efi || c1->type == extended) {
- Device *dev;
- char devname[80];
-
- /* Got one! */
- snprintf(devname, sizeof devname, "/dev/%s", c1->name);
- dev = deviceRegister(c1->name, c1->name, strdup(devname), DEVICE_TYPE_DOS, TRUE,
- mediaInitDOS, mediaGetDOS, mediaShutdownDOS, NULL);
- dev->private = c1;
- if (isDebug())
- msgDebug("Found a DOS partition %s on drive %s\n", c1->name, d->name);
- }
- }
- }
- free(names);
- }
- dialog_clear_norefresh();
-}
-
-/* Rescan all devices, after closing previous set - convenience function */
-void
-deviceRescan(void)
-{
- deviceReset();
- deviceGetAll();
-}
-
-/*
- * Find all devices that match the criteria, allowing "wildcarding" as well
- * by allowing NULL or ANY values to match all. The array returned is static
- * and may be used until the next invocation of deviceFind().
- */
-Device **
-deviceFind(char *name, DeviceType class)
-{
- static Device *found[DEV_MAX];
- int i, j;
-
- j = 0;
- for (i = 0; i < numDevs; i++) {
- if ((!name || !strcmp(Devices[i]->name, name))
- && (class == DEVICE_TYPE_ANY || class == Devices[i]->type))
- found[j++] = Devices[i];
- }
- found[j] = NULL;
- return j ? found : NULL;
-}
-
-Device **
-deviceFindDescr(char *name, char *desc, DeviceType class)
-{
- static Device *found[DEV_MAX];
- int i, j;
-
- j = 0;
- for (i = 0; i < numDevs; i++) {
- if ((!name || !strcmp(Devices[i]->name, name)) &&
- (!desc || !strcmp(Devices[i]->description, desc)) &&
- (class == DEVICE_TYPE_ANY || class == Devices[i]->type))
- found[j++] = Devices[i];
- }
- found[j] = NULL;
- return j ? found : NULL;
-}
-
-int
-deviceCount(Device **devs)
-{
- int i;
-
- if (!devs)
- return 0;
- for (i = 0; devs[i]; i++);
- return i;
-}
-
-/*
- * Create a menu listing all the devices of a certain type in the system.
- * The passed-in menu is expected to be a "prototype" from which the new
- * menu is cloned.
- */
-DMenu *
-deviceCreateMenu(DMenu *menu, DeviceType type, int (*hook)(dialogMenuItem *d), int (*check)(dialogMenuItem *d))
-{
- Device **devs;
- int numdevs;
- DMenu *tmp = NULL;
- int i, j;
-
- devs = deviceFind(NULL, type);
- numdevs = deviceCount(devs);
- if (!numdevs)
- return NULL;
- tmp = (DMenu *)safe_malloc(sizeof(DMenu) + (sizeof(dialogMenuItem) * (numdevs + 1)));
- bcopy(menu, tmp, sizeof(DMenu));
- for (i = 0; devs[i]; i++) {
- tmp->items[i].prompt = devs[i]->name;
- for (j = 0; j < numDevs; j++) {
- if (devs[i] == Devices[j]) {
- tmp->items[i].title = Devices[j]->description;
- break;
- }
- }
- if (j == numDevs)
- tmp->items[i].title = "<unknown device type>";
- tmp->items[i].fire = hook;
- tmp->items[i].checked = check;
- }
- tmp->items[i].title = NULL;
- return tmp;
-}
diff --git a/usr.sbin/sade/disks.c b/usr.sbin/sade/disks.c
deleted file mode 100644
index 93050f734ee5..000000000000
--- a/usr.sbin/sade/disks.c
+++ /dev/null
@@ -1,985 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last program in the `sysinstall' line - the next
- * generation being essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-#include <ctype.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/disklabel.h>
-
-#ifdef WITH_SLICES
-enum size_units_t { UNIT_BLOCKS, UNIT_KILO, UNIT_MEG, UNIT_SIZE };
-
-#ifdef PC98
-#define SUBTYPE_FREEBSD 50324
-#define SUBTYPE_FAT 37218
-#else
-#define SUBTYPE_FREEBSD 165
-#define SUBTYPE_FAT 6
-#endif
-#define SUBTYPE_EFI 239
-
-#ifdef PC98
-#define OTHER_SLICE_VALUES \
- "Other popular values are 37218 for a\n" \
- "DOS FAT partition.\n\n"
-#else
-#define OTHER_SLICE_VALUES \
- "Other popular values are 6 for a\n" \
- "DOS FAT partition, 131 for a Linux ext2fs partition, or\n" \
- "130 for a Linux swap partition.\n\n"
-#endif
-#define NON_FREEBSD_NOTE \
- "Note: If you choose a non-FreeBSD partition type, it will not\n" \
- "be formatted or otherwise prepared, it will simply reserve space\n" \
- "for you to use another tool, such as DOS format, to later format\n" \
- "and actually use the partition."
-
-/* Where we start displaying chunk information on the screen */
-#define CHUNK_START_ROW 5
-
-/* Where we keep track of MBR chunks */
-static struct chunk *chunk_info[16];
-static int current_chunk;
-
-static void diskPartitionNonInteractive(Device *dev);
-static u_char * bootalloc(char *name, size_t *size);
-
-static void
-record_chunks(Disk *d)
-{
- struct chunk *c1 = NULL;
- int i = 0;
- int last_free = 0;
-
- if (!d->chunks)
- msgFatal("No chunk list found for %s!", d->name);
-
- for (c1 = d->chunks->part; c1; c1 = c1->next) {
- if (c1->type == unused && c1->size > last_free) {
- last_free = c1->size;
- current_chunk = i;
- }
- chunk_info[i++] = c1;
- }
- chunk_info[i] = NULL;
- if (current_chunk >= i)
- current_chunk = i - 1;
-}
-
-static int Total;
-
-static void
-print_chunks(Disk *d, int u)
-{
- int row;
- int i;
- int sz;
- char *szstr;
-
- szstr = (u == UNIT_MEG ? "MB" : (u == UNIT_KILO ? "KB" : "ST"));
-
- for (i = Total = 0; chunk_info[i]; i++)
- Total += chunk_info[i]->size;
-#ifdef PC98
- if (d->bios_cyl >= 65536 || d->bios_hd > 16 || d->bios_sect >= 256) {
-#else
- if (d->bios_cyl > 65536 || d->bios_hd > 256 || d->bios_sect >= 64) {
-#endif
- dialog_clear_norefresh();
- msgConfirm("WARNING: A geometry of %lu/%lu/%lu for %s is incorrect. Using\n"
- "a more likely geometry. If this geometry is incorrect or you\n"
- "are unsure as to whether or not it's correct, please consult\n"
- "the Hardware Guide in the Documentation submenu or use the\n"
- "(G)eometry command to change it now.\n\n"
- "Remember: you need to enter whatever your BIOS thinks the\n"
- "geometry is! For IDE, it's what you were told in the BIOS\n"
- "setup. For SCSI, it's the translation mode your controller is\n"
- "using. Do NOT use a ``physical geometry''.",
- d->bios_cyl, d->bios_hd, d->bios_sect, d->name);
- Sanitize_Bios_Geom(d);
- }
- attrset(A_NORMAL);
- mvaddstr(0, 0, "Disk name:\t");
- clrtobot();
- attrset(A_REVERSE); addstr(d->name); attrset(A_NORMAL);
- attrset(A_REVERSE); mvaddstr(0, 55, "FDISK Partition Editor"); attrset(A_NORMAL);
- mvprintw(1, 0,
- "DISK Geometry:\t%lu cyls/%lu heads/%lu sectors = %lu sectors (%luMB)",
- d->bios_cyl, d->bios_hd, d->bios_sect,
- d->bios_cyl * d->bios_hd * d->bios_sect,
- d->bios_cyl * d->bios_hd * d->bios_sect / (1024/512) / 1024);
- mvprintw(3, 0, "%6s %10s(%s) %10s %8s %6s %10s %8s %8s",
- "Offset", "Size", szstr, "End", "Name", "PType", "Desc",
- "Subtype", "Flags");
- for (i = 0, row = CHUNK_START_ROW; chunk_info[i]; i++, row++) {
- switch(u) {
- default: /* fall thru */
- case UNIT_BLOCKS:
- sz = chunk_info[i]->size;
- break;
- case UNIT_KILO:
- sz = chunk_info[i]->size / (1024/512);
- break;
- case UNIT_MEG:
- sz = chunk_info[i]->size / (1024/512) / 1024;
- break;
- }
- if (i == current_chunk)
- attrset(ATTR_SELECTED);
- mvprintw(row, 0, "%10ld %10lu %10lu %8s %6d %10s %8d\t%-6s",
- chunk_info[i]->offset, sz,
- chunk_info[i]->end, chunk_info[i]->name,
- chunk_info[i]->type,
- slice_type_name(chunk_info[i]->type, chunk_info[i]->subtype),
- chunk_info[i]->subtype, ShowChunkFlags(chunk_info[i]));
- if (i == current_chunk)
- attrset(A_NORMAL);
- }
-}
-
-static void
-print_command_summary()
-{
- mvprintw(14, 0, "The following commands are supported (in upper or lower case):");
- mvprintw(16, 0, "A = Use Entire Disk G = set Drive Geometry C = Create Slice F = `DD' mode");
- mvprintw(17, 0, "D = Delete Slice Z = Toggle Size Units S = Set Bootable | = Wizard m.");
- mvprintw(18, 0, "T = Change Type U = Undo All Changes Q = Finish");
- if (!RunningAsInit)
- mvprintw(18, 47, "W = Write Changes");
- mvprintw(21, 0, "Use F1 or ? to get more help, arrow keys to select.");
- move(0, 0);
-}
-
-#ifdef PC98
-static void
-getBootMgr(char *dname, u_char **bootipl, size_t *bootipl_size,
- u_char **bootmenu, size_t *bootmenu_size)
-{
- static u_char *boot0;
- static size_t boot0_size;
- static u_char *boot05;
- static size_t boot05_size;
-
- char str[80];
- char *cp;
- int i = 0;
-
- cp = variable_get(VAR_BOOTMGR);
- if (!cp) {
- /* Figure out what kind of IPL the user wants */
- sprintf(str, "Install Boot Manager for drive %s?", dname);
- MenuIPLType.title = str;
- i = dmenuOpenSimple(&MenuIPLType, FALSE);
- } else {
- if (!strncmp(cp, "boot", 4))
- BootMgr = 0;
- else
- BootMgr = 1;
- }
- if (cp || i) {
- switch (BootMgr) {
- case 0:
- if (!boot0) boot0 = bootalloc("boot0", &boot0_size);
- *bootipl = boot0;
- *bootipl_size = boot0_size;
- if (!boot05) boot05 = bootalloc("boot0.5", &boot05_size);
- *bootmenu = boot05;
- *bootmenu_size = boot05_size;
- return;
- case 1:
- default:
- break;
- }
- }
- *bootipl = NULL;
- *bootipl_size = 0;
- *bootmenu = NULL;
- *bootmenu_size = 0;
-}
-#else
-static void
-getBootMgr(char *dname, u_char **bootCode, size_t *bootCodeSize)
-{
-#if defined(__i386__) || defined(__amd64__) /* only meaningful on x86 */
- static u_char *mbr, *boot0;
- static size_t mbr_size, boot0_size;
- char str[80];
- char *cp;
- int i = 0;
-
- cp = variable_get(VAR_BOOTMGR);
- if (!cp) {
- /* Figure out what kind of MBR the user wants */
- sprintf(str, "Install Boot Manager for drive %s?", dname);
- MenuMBRType.title = str;
- i = dmenuOpenSimple(&MenuMBRType, FALSE);
- }
- else {
- if (!strncmp(cp, "boot", 4))
- BootMgr = 0;
- else if (!strcmp(cp, "standard"))
- BootMgr = 1;
- else
- BootMgr = 2;
- }
- if (cp || i) {
- switch (BootMgr) {
- case 0:
- if (!boot0) boot0 = bootalloc("boot0", &boot0_size);
- *bootCode = boot0;
- *bootCodeSize = boot0_size;
- return;
- case 1:
- if (!mbr) mbr = bootalloc("mbr", &mbr_size);
- *bootCode = mbr;
- *bootCodeSize = mbr_size;
- return;
- case 2:
- default:
- break;
- }
- }
-#endif
- *bootCode = NULL;
- *bootCodeSize = 0;
-}
-#endif
-#endif /* WITH_SLICES */
-
-int
-diskGetSelectCount(Device ***devs)
-{
- int i, cnt, enabled;
- char *cp;
- Device **dp;
-
- cp = variable_get(VAR_DISK);
- dp = *devs = deviceFind(cp, DEVICE_TYPE_DISK);
- cnt = deviceCount(dp);
- if (!cnt)
- return -1;
- for (i = 0, enabled = 0; i < cnt; i++) {
- if (dp[i]->enabled)
- ++enabled;
- }
- return enabled;
-}
-
-#ifdef WITH_SLICES
-void
-diskPartition(Device *dev)
-{
- char *cp, *p;
- int rv, key = 0;
- Boolean chunking;
- char *msg = NULL;
-#ifdef PC98
- u_char *bootipl;
- size_t bootipl_size;
- u_char *bootmenu;
- size_t bootmenu_size;
-#else
- u_char *mbrContents;
- size_t mbrSize;
-#endif
- WINDOW *w = savescr();
- Disk *d = (Disk *)dev->private;
- int size_unit;
-
- size_unit = UNIT_BLOCKS;
- chunking = TRUE;
- keypad(stdscr, TRUE);
-
- /* Flush both the dialog and curses library views of the screen
- since we don't always know who called us */
- dialog_clear_norefresh(), clear();
- current_chunk = 0;
-
- /* Set up the chunk array */
- record_chunks(d);
-
- while (chunking) {
- char *val, geometry[80];
-
- /* Now print our overall state */
- if (d)
- print_chunks(d, size_unit);
- print_command_summary();
- if (msg) {
- attrset(title_attr); mvprintw(23, 0, msg); attrset(A_NORMAL);
- beep();
- msg = NULL;
- }
- else {
- move(23, 0);
- clrtoeol();
- }
-
- /* Get command character */
- key = getch();
- switch (toupper(key)) {
- case '\014': /* ^L (redraw) */
- clear();
- msg = NULL;
- break;
-
- case '\020': /* ^P */
- case KEY_UP:
- case '-':
- if (current_chunk != 0)
- --current_chunk;
- break;
-
- case '\016': /* ^N */
- case KEY_DOWN:
- case '+':
- case '\r':
- case '\n':
- if (chunk_info[current_chunk + 1])
- ++current_chunk;
- break;
-
- case KEY_HOME:
- current_chunk = 0;
- break;
-
- case KEY_END:
- while (chunk_info[current_chunk + 1])
- ++current_chunk;
- break;
-
- case KEY_F(1):
- case '?':
- systemDisplayHelp("slice");
- clear();
- break;
-
- case 'A':
- case 'F': /* Undocumented magic Dangerously Dedicated mode */
-#ifndef __i386__
- rv = 1;
-#else /* The rest is only relevant on x86 */
- cp = variable_get(VAR_DEDICATE_DISK);
- if (cp && !strcasecmp(cp, "always"))
- rv = 1;
- else if (toupper(key) == 'A')
- rv = 0;
- else {
- rv = msgYesNo("Do you want to do this with a true partition entry\n"
- "so as to remain cooperative with any future possible\n"
- "operating systems on the drive(s)?\n"
- "(See also the section about ``dangerously dedicated''\n"
- "disks in the FreeBSD FAQ.)");
- if (rv == -1)
- rv = 0;
- }
-#endif
- All_FreeBSD(d, rv);
- variable_set2(DISK_PARTITIONED, "yes", 0);
- record_chunks(d);
- clear();
- break;
-
- case 'C':
- if (chunk_info[current_chunk]->type != unused)
- msg = "Slice in use, delete it first or move to an unused one.";
- else {
- char *val, tmp[20], name[16], *cp;
- int size, subtype;
- chunk_e partitiontype;
-#ifdef PC98
- snprintf(name, sizeof (name), "%s", "FreeBSD");
- val = msgGetInput(name,
- "Please specify the name for new FreeBSD slice.");
- if (val)
- strncpy(name, val, sizeof (name));
-#else
- name[0] = '\0';
-#endif
- snprintf(tmp, 20, "%lu", chunk_info[current_chunk]->size);
- val = msgGetInput(tmp, "Please specify the size for new FreeBSD slice in blocks\n"
- "or append a trailing `M' for megabytes (e.g. 20M).");
- if (val && (size = strtol(val, &cp, 0)) > 0) {
- if (*cp && toupper(*cp) == 'M')
- size *= ONE_MEG;
- else if (*cp && toupper(*cp) == 'G')
- size *= ONE_GIG;
- sprintf(tmp, "%d", SUBTYPE_FREEBSD);
- val = msgGetInput(tmp, "Enter type of partition to create:\n\n"
- "Pressing Enter will choose the default, a native FreeBSD\n"
- "slice (type %u). "
- OTHER_SLICE_VALUES
- NON_FREEBSD_NOTE, SUBTYPE_FREEBSD);
- if (val && (subtype = strtol(val, NULL, 0)) > 0) {
- if (subtype == SUBTYPE_FREEBSD)
- partitiontype = freebsd;
- else if (subtype == SUBTYPE_FAT)
- partitiontype = fat;
- else if (subtype == SUBTYPE_EFI)
- partitiontype = efi;
- else
-#ifdef PC98
- partitiontype = pc98;
-#else
- partitiontype = mbr;
-#endif
- Create_Chunk(d, chunk_info[current_chunk]->offset, size, partitiontype, subtype,
- (chunk_info[current_chunk]->flags & CHUNK_ALIGN), name);
- variable_set2(DISK_PARTITIONED, "yes", 0);
- record_chunks(d);
- }
- }
- clear();
- }
- break;
-
- case KEY_DC:
- case 'D':
- if (chunk_info[current_chunk]->type == unused)
- msg = "Slice is already unused!";
- else {
- Delete_Chunk(d, chunk_info[current_chunk]);
- variable_set2(DISK_PARTITIONED, "yes", 0);
- record_chunks(d);
- }
- break;
-
- case 'T':
- if (chunk_info[current_chunk]->type == unused)
- msg = "Slice is currently unused (use create instead)";
- else {
- char *val, tmp[20];
- int subtype;
- chunk_e partitiontype;
-
- sprintf(tmp, "%d", chunk_info[current_chunk]->subtype);
- val = msgGetInput(tmp, "New partition type:\n\n"
- "Pressing Enter will use the current type. To choose a native\n"
- "FreeBSD slice enter %u. "
- OTHER_SLICE_VALUES
- NON_FREEBSD_NOTE, SUBTYPE_FREEBSD);
- if (val && (subtype = strtol(val, NULL, 0)) > 0) {
- if (subtype == SUBTYPE_FREEBSD)
- partitiontype = freebsd;
- else if (subtype == SUBTYPE_FAT)
- partitiontype = fat;
- else if (subtype == SUBTYPE_EFI)
- partitiontype = efi;
- else
-#ifdef PC98
- partitiontype = pc98;
-#else
- partitiontype = mbr;
-#endif
- chunk_info[current_chunk]->type = partitiontype;
- chunk_info[current_chunk]->subtype = subtype;
- }
- }
- break;
-
- case 'G':
- snprintf(geometry, 80, "%lu/%lu/%lu", d->bios_cyl, d->bios_hd, d->bios_sect);
- val = msgGetInput(geometry, "Please specify the new geometry in cyl/hd/sect format.\n"
- "Don't forget to use the two slash (/) separator characters!\n"
- "It's not possible to parse the field without them.");
- if (val) {
- long nc, nh, ns;
- nc = strtol(val, &val, 0);
- nh = strtol(val + 1, &val, 0);
- ns = strtol(val + 1, 0, 0);
- Set_Bios_Geom(d, nc, nh, ns);
- }
- clear();
- break;
-
- case 'S':
- /* Set Bootable */
- chunk_info[current_chunk]->flags |= CHUNK_ACTIVE;
- break;
-
- case 'U':
- if (!variable_cmp(DISK_LABELLED, "written")) {
- msgConfirm("You've already written this information out - you\n"
- "can't undo it.");
- }
- else if (!msgNoYes("Are you SURE you want to Undo everything?")) {
- char cp[BUFSIZ];
-
- sstrncpy(cp, d->name, sizeof cp);
- Free_Disk(dev->private);
- d = Open_Disk(cp);
- if (!d)
- msgConfirm("Can't reopen disk %s! Internal state is probably corrupted", cp);
- dev->private = d;
- variable_unset(DISK_PARTITIONED);
- variable_unset(DISK_LABELLED);
- if (d)
- record_chunks(d);
- }
- clear();
- break;
-
- case 'W':
- if (!msgNoYes("WARNING: This should only be used when modifying an EXISTING\n"
- "installation. If you are installing FreeBSD for the first time\n"
- "then you should simply type Q when you're finished here and your\n"
- "changes will be committed in one batch automatically at the end of\n"
- "these questions. If you're adding a disk, you should NOT write\n"
- "from this screen, you should do it from the label editor.\n\n"
- "Are you absolutely sure you want to do this now?")) {
- variable_set2(DISK_PARTITIONED, "yes", 0);
-
-#ifdef PC98
- /*
- * Don't trash the IPL if the first (and therefore only) chunk
- * is marked for a truly dedicated disk (i.e., the disklabel
- * starts at sector 0), even in cases where the user has
- * requested a FreeBSD Boot Manager -- both would be fatal in
- * this case.
- */
- /*
- * Don't offer to update the IPL on this disk if the first
- * "real" chunk looks like a FreeBSD "all disk" partition,
- * or the disk is entirely FreeBSD.
- */
- if ((d->chunks->part->type != freebsd) ||
- (d->chunks->part->offset > 1))
- getBootMgr(d->name, &bootipl, &bootipl_size,
- &bootmenu, &bootmenu_size);
- else {
- bootipl = NULL;
- bootipl_size = 0;
- bootmenu = NULL;
- bootmenu_size = 0;
- }
- Set_Boot_Mgr(d, bootipl, bootipl_size, bootmenu, bootmenu_size);
-#else
- /*
- * Don't trash the MBR if the first (and therefore only) chunk
- * is marked for a truly dedicated disk (i.e., the disklabel
- * starts at sector 0), even in cases where the user has
- * requested booteasy or a "standard" MBR -- both would be
- * fatal in this case.
- */
- /*
- * Don't offer to update the MBR on this disk if the first
- * "real" chunk looks like a FreeBSD "all disk" partition,
- * or the disk is entirely FreeBSD.
- */
- if ((d->chunks->part->type != freebsd) ||
- (d->chunks->part->offset > 1))
- getBootMgr(d->name, &mbrContents, &mbrSize);
- else {
- mbrContents = NULL;
- mbrSize = 0;
- }
- Set_Boot_Mgr(d, mbrContents, mbrSize);
-#endif
-
- if (DITEM_STATUS(diskPartitionWrite(NULL)) != DITEM_SUCCESS)
- msgConfirm("Disk partition write returned an error status!");
- else
- msgConfirm("Wrote FDISK partition information out successfully.");
- }
- clear();
- break;
-
- case '|':
- if (!msgNoYes("Are you SURE you want to go into Wizard mode?\n"
- "No seat belts whatsoever are provided!")) {
- clear();
- refresh();
- slice_wizard(d);
- variable_set2(DISK_PARTITIONED, "yes", 0);
- record_chunks(d);
- }
- else
- msg = "Wise choice!";
- clear();
- break;
-
- case '\033': /* ESC */
- case 'Q':
- chunking = FALSE;
-#ifdef PC98
- /*
- * Don't trash the IPL if the first (and therefore only) chunk
- * is marked for a truly dedicated disk (i.e., the disklabel
- * starts at sector 0), even in cases where the user has requested
- * a FreeBSD Boot Manager -- both would be fatal in this case.
- */
- /*
- * Don't offer to update the IPL on this disk if the first "real"
- * chunk looks like a FreeBSD "all disk" partition, or the disk is
- * entirely FreeBSD.
- */
- if ((d->chunks->part->type != freebsd) ||
- (d->chunks->part->offset > 1)) {
- if (variable_cmp(DISK_PARTITIONED, "written")) {
- getBootMgr(d->name, &bootipl, &bootipl_size,
- &bootmenu, &bootmenu_size);
- if (bootipl != NULL && bootmenu != NULL)
- Set_Boot_Mgr(d, bootipl, bootipl_size,
- bootmenu, bootmenu_size);
- }
- }
-#else
- /*
- * Don't trash the MBR if the first (and therefore only) chunk
- * is marked for a truly dedicated disk (i.e., the disklabel
- * starts at sector 0), even in cases where the user has requested
- * booteasy or a "standard" MBR -- both would be fatal in this case.
- */
- /*
- * Don't offer to update the MBR on this disk if the first "real"
- * chunk looks like a FreeBSD "all disk" partition, or the disk is
- * entirely FreeBSD.
- */
- if ((d->chunks->part->type != freebsd) ||
- (d->chunks->part->offset > 1)) {
- if (variable_cmp(DISK_PARTITIONED, "written")) {
- getBootMgr(d->name, &mbrContents, &mbrSize);
- if (mbrContents != NULL)
- Set_Boot_Mgr(d, mbrContents, mbrSize);
- }
- }
-#endif
- break;
-
- case 'Z':
- size_unit = (size_unit + 1) % UNIT_SIZE;
- break;
-
- default:
- beep();
- msg = "Type F1 or ? for help";
- break;
- }
- }
- p = CheckRules(d);
- if (p) {
- char buf[FILENAME_MAX];
-
- use_helpline("Press F1 to read more about disk slices.");
- use_helpfile(systemHelpFile("partition", buf));
- if (!variable_get(VAR_NO_WARN))
- dialog_mesgbox("Disk slicing warning:", p, -1, -1);
- free(p);
- }
- restorescr(w);
-}
-#endif /* WITH_SLICES */
-
-static u_char *
-bootalloc(char *name, size_t *size)
-{
- char buf[FILENAME_MAX];
- struct stat sb;
-
- snprintf(buf, sizeof buf, "/boot/%s", name);
- if (stat(buf, &sb) != -1) {
- int fd;
-
- fd = open(buf, O_RDONLY);
- if (fd != -1) {
- u_char *cp;
-
- cp = malloc(sb.st_size);
- if (read(fd, cp, sb.st_size) != sb.st_size) {
- free(cp);
- close(fd);
- msgDebug("bootalloc: couldn't read %ld bytes from %s\n", (long)sb.st_size, buf);
- return NULL;
- }
- close(fd);
- if (size != NULL)
- *size = sb.st_size;
- return cp;
- }
- msgDebug("bootalloc: couldn't open %s\n", buf);
- }
- else
- msgDebug("bootalloc: can't stat %s\n", buf);
- return NULL;
-}
-
-#ifdef WITH_SLICES
-static int
-partitionHook(dialogMenuItem *selected)
-{
- Device **devs = NULL;
-
- devs = deviceFind(selected->prompt, DEVICE_TYPE_DISK);
- if (!devs) {
- msgConfirm("Unable to find disk %s!", selected->prompt);
- return DITEM_FAILURE;
- }
- /* Toggle enabled status? */
- if (!devs[0]->enabled) {
- devs[0]->enabled = TRUE;
- diskPartition(devs[0]);
- }
- else
- devs[0]->enabled = FALSE;
- return DITEM_SUCCESS;
-}
-
-static int
-partitionCheck(dialogMenuItem *selected)
-{
- Device **devs = NULL;
-
- devs = deviceFind(selected->prompt, DEVICE_TYPE_DISK);
- if (!devs || devs[0]->enabled == FALSE)
- return FALSE;
- return TRUE;
-}
-
-int
-diskPartitionEditor(dialogMenuItem *self)
-{
- DMenu *menu;
- Device **devs;
- int i, cnt, devcnt;
-
- cnt = diskGetSelectCount(&devs);
- devcnt = deviceCount(devs);
- if (cnt == -1) {
- msgConfirm("No disks found! Please verify that your disk controller is being\n"
- "properly probed at boot time. See the Hardware Guide on the\n"
- "Documentation menu for clues on diagnosing this type of problem.");
- return DITEM_FAILURE;
- }
- else if (cnt) {
- /* Some are already selected */
- for (i = 0; i < devcnt; i++) {
- if (devs[i]->enabled) {
- if (variable_get(VAR_NONINTERACTIVE) &&
- !variable_get(VAR_DISKINTERACTIVE))
- diskPartitionNonInteractive(devs[i]);
- else
- diskPartition(devs[i]);
- }
- }
- }
- else {
- /* No disks are selected, fall-back case now */
- if (devcnt == 1) {
- devs[0]->enabled = TRUE;
- if (variable_get(VAR_NONINTERACTIVE) &&
- !variable_get(VAR_DISKINTERACTIVE))
- diskPartitionNonInteractive(devs[0]);
- else
- diskPartition(devs[0]);
- return DITEM_SUCCESS;
- }
- else {
- menu = deviceCreateMenu(&MenuDiskDevices, DEVICE_TYPE_DISK, partitionHook, partitionCheck);
- if (!menu) {
- msgConfirm("No devices suitable for installation found!\n\n"
- "Please verify that your disk controller (and attached drives)\n"
- "were detected properly. This can be done by pressing the\n"
- "[Scroll Lock] key and using the Arrow keys to move back to\n"
- "the boot messages. Press [Scroll Lock] again to return.");
- return DITEM_FAILURE;
- }
- else {
- i = dmenuOpenSimple(menu, FALSE) ? DITEM_SUCCESS : DITEM_FAILURE;
- free(menu);
- }
- return i;
- }
- }
- return DITEM_SUCCESS;
-}
-#endif /* WITH_SLICES */
-
-int
-diskPartitionWrite(dialogMenuItem *self)
-{
- Device **devs;
- int i;
-
- if (!variable_cmp(DISK_PARTITIONED, "written"))
- return DITEM_SUCCESS;
-
- devs = deviceFind(NULL, DEVICE_TYPE_DISK);
- if (!devs) {
- msgConfirm("Unable to find any disks to write to??");
- return DITEM_FAILURE;
- }
- if (isDebug())
- msgDebug("diskPartitionWrite: Examining %d devices\n", deviceCount(devs));
- for (i = 0; devs[i]; i++) {
- Disk *d = (Disk *)devs[i]->private;
- static u_char *boot1;
-#if defined(__i386__) || defined(__ia64__) || defined(__amd64__)
- static u_char *boot2;
-#endif
-
- if (!devs[i]->enabled)
- continue;
-
-#if defined(__i386__) || defined(__ia64__) || defined(__amd64__)
- if (!boot1) boot1 = bootalloc("boot1", NULL);
- if (!boot2) boot2 = bootalloc("boot2", NULL);
- Set_Boot_Blocks(d, boot1, boot2);
-#else
- if (!boot1) boot1 = bootalloc("boot1", NULL);
- Set_Boot_Blocks(d, boot1, NULL);
-#endif
-
- msgNotify("Writing partition information to drive %s", d->name);
- if (!Fake && Write_Disk(d)) {
- msgConfirm("ERROR: Unable to write data to disk %s!", d->name);
- return DITEM_FAILURE;
- }
- }
- /* Now it's not "yes", but "written" */
- variable_set2(DISK_PARTITIONED, "written", 0);
- return DITEM_SUCCESS | DITEM_RESTORE;
-}
-
-#ifdef WITH_SLICES
-/* Partition a disk based wholly on which variables are set */
-static void
-diskPartitionNonInteractive(Device *dev)
-{
- char *cp;
- int i, sz, all_disk = 0;
-#ifdef PC98
- u_char *bootipl;
- size_t bootipl_size;
- u_char *bootmenu;
- size_t bootmenu_size;
-#else
- u_char *mbrContents;
- size_t mbrSize;
-#endif
- Disk *d = (Disk *)dev->private;
-
- record_chunks(d);
- cp = variable_get(VAR_GEOMETRY);
- if (cp) {
- msgDebug("Setting geometry from script to: %s\n", cp);
- d->bios_cyl = strtol(cp, &cp, 0);
- d->bios_hd = strtol(cp + 1, &cp, 0);
- d->bios_sect = strtol(cp + 1, 0, 0);
- }
-
- cp = variable_get(VAR_PARTITION);
- if (cp) {
- if (!strcmp(cp, "free")) {
- /* Do free disk space case */
- for (i = 0; chunk_info[i]; i++) {
- /* If a chunk is at least 10MB in size, use it. */
- if (chunk_info[i]->type == unused && chunk_info[i]->size > (10 * ONE_MEG)) {
- Create_Chunk(d, chunk_info[i]->offset, chunk_info[i]->size,
- freebsd, 3,
- (chunk_info[i]->flags & CHUNK_ALIGN),
- "FreeBSD");
- variable_set2(DISK_PARTITIONED, "yes", 0);
- break;
- }
- }
- if (!chunk_info[i]) {
- msgConfirm("Unable to find any free space on this disk!");
- return;
- }
- }
- else if (!strcmp(cp, "all")) {
- /* Do all disk space case */
- msgDebug("Warning: Devoting all of disk %s to FreeBSD.\n", d->name);
-
- All_FreeBSD(d, FALSE);
- }
- else if (!strcmp(cp, "exclusive")) {
- /* Do really-all-the-disk-space case */
- msgDebug("Warning: Devoting all of disk %s to FreeBSD.\n", d->name);
-
- All_FreeBSD(d, all_disk = TRUE);
- }
- else if ((sz = strtol(cp, &cp, 0))) {
- /* Look for sz bytes free */
- if (*cp && toupper(*cp) == 'M')
- sz *= ONE_MEG;
- else if (*cp && toupper(*cp) == 'G')
- sz *= ONE_GIG;
- for (i = 0; chunk_info[i]; i++) {
- /* If a chunk is at least sz MB, use it. */
- if (chunk_info[i]->type == unused && chunk_info[i]->size >= sz) {
- Create_Chunk(d, chunk_info[i]->offset, sz, freebsd, 3,
- (chunk_info[i]->flags & CHUNK_ALIGN),
- "FreeBSD");
- variable_set2(DISK_PARTITIONED, "yes", 0);
- break;
- }
- }
- if (!chunk_info[i]) {
- msgConfirm("Unable to find %d free blocks on this disk!", sz);
- return;
- }
- }
- else if (!strcmp(cp, "existing")) {
- /* Do existing FreeBSD case */
- for (i = 0; chunk_info[i]; i++) {
- if (chunk_info[i]->type == freebsd)
- break;
- }
- if (!chunk_info[i]) {
- msgConfirm("Unable to find any existing FreeBSD partitions on this disk!");
- return;
- }
- }
- else {
- msgConfirm("`%s' is an invalid value for %s - is config file valid?", cp, VAR_PARTITION);
- return;
- }
- if (!all_disk) {
-#ifdef PC98
- getBootMgr(d->name, &bootipl, &bootipl_size,
- &bootmenu, &bootmenu_size);
- Set_Boot_Mgr(d, bootipl, bootipl_size, bootmenu, bootmenu_size);
-#else
- getBootMgr(d->name, &mbrContents, &mbrSize);
- Set_Boot_Mgr(d, mbrContents, mbrSize);
-#endif
- }
- variable_set2(DISK_PARTITIONED, "yes", 0);
- }
-}
-#endif /* WITH_SLICES */
diff --git a/usr.sbin/sade/dispatch.c b/usr.sbin/sade/dispatch.c
deleted file mode 100644
index 17b5e9a49d60..000000000000
--- a/usr.sbin/sade/dispatch.c
+++ /dev/null
@@ -1,448 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last program in the `sysinstall' line - the next
- * generation being essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-#include <ctype.h>
-#include <errno.h>
-#include <sys/signal.h>
-#include <sys/fcntl.h>
-
-#include "list.h"
-
-static int dispatch_shutdown(dialogMenuItem *unused);
-static int dispatch_systemExecute(dialogMenuItem *unused);
-static int dispatch_msgConfirm(dialogMenuItem *unused);
-static int dispatch_mediaClose(dialogMenuItem *unused);
-
-static struct _word {
- char *name;
- int (*handler)(dialogMenuItem *self);
-} resWords[] = {
- { "configAnonFTP", configAnonFTP },
- { "configRouter", configRouter },
- { "configInetd", configInetd },
- { "configNFSServer", configNFSServer },
- { "configNTP", configNTP },
- { "configPCNFSD", configPCNFSD },
- { "configPackages", configPackages },
- { "configUsers", configUsers },
- { "configXSetup", configXSetup },
- { "configXDesktop", configXDesktop },
-#ifdef WITH_SLICES
- { "diskPartitionEditor", diskPartitionEditor },
-#endif
- { "diskPartitionWrite", diskPartitionWrite },
- { "diskLabelEditor", diskLabelEditor },
- { "diskLabelCommit", diskLabelCommit },
- { "distReset", distReset },
- { "distSetCustom", distSetCustom },
- { "distUnsetCustom", distUnsetCustom },
- { "distSetDeveloper", distSetDeveloper },
- { "distSetXDeveloper", distSetXDeveloper },
- { "distSetKernDeveloper", distSetKernDeveloper },
- { "distSetUser", distSetUser },
- { "distSetXUser", distSetXUser },
- { "distSetMinimum", distSetMinimum },
- { "distSetEverything", distSetEverything },
- { "distSetSrc", distSetSrc },
-#ifndef X_AS_PKG
- { "distSetXF86", distSetXF86 },
-#endif
- { "distExtractAll", distExtractAll },
- { "docBrowser", docBrowser },
- { "docShowDocument", docShowDocument },
- { "installCommit", installCommit },
- { "installExpress", installExpress },
- { "installStandard", installStandard },
- { "installUpgrade", installUpgrade },
- { "installFixupBase", installFixupBase },
-#ifndef X_AS_PKG
- { "installFixupXFree", installFixupXFree },
-#endif
- { "installFixitHoloShell", installFixitHoloShell },
- { "installFixitCDROM", installFixitCDROM },
- { "installFixitFloppy", installFixitFloppy },
- { "installFilesystems", installFilesystems },
- { "installVarDefaults", installVarDefaults },
- { "loadConfig", dispatch_load_file },
- { "loadFloppyConfig", dispatch_load_floppy },
- { "mediaClose", dispatch_mediaClose },
- { "mediaSetCDROM", mediaSetCDROM },
- { "mediaSetFloppy", mediaSetFloppy },
- { "mediaSetDOS", mediaSetDOS },
- { "mediaSetTape", mediaSetTape },
- { "mediaSetFTP", mediaSetFTP },
- { "mediaSetFTPActive", mediaSetFTPActive },
- { "mediaSetFTPPassive", mediaSetFTPPassive },
- { "mediaSetHTTP", mediaSetHTTP },
- { "mediaSetUFS", mediaSetUFS },
- { "mediaSetNFS", mediaSetNFS },
- { "mediaSetFTPUserPass", mediaSetFTPUserPass },
- { "mediaSetCPIOVerbosity", mediaSetCPIOVerbosity },
- { "mediaGetType", mediaGetType },
- { "msgConfirm", dispatch_msgConfirm },
- { "optionsEditor", optionsEditor },
- { "packageAdd", packageAdd },
- { "addGroup", userAddGroup },
- { "addUser", userAddUser },
- { "shutdown", dispatch_shutdown },
- { "system", dispatch_systemExecute },
- { "dumpVariables", dump_variables },
- { "tcpMenuSelect", tcpMenuSelect },
- { NULL, NULL },
-};
-
-/*
- * Helper routines for buffering data.
- *
- * We read an entire configuration into memory before executing it
- * so that we are truely standalone and can do things like nuke the
- * file or disk we're working on.
- */
-
-typedef struct command_buffer_ {
- qelement queue;
- char * string;
-} command_buffer;
-
-static void
-dispatch_free_command(command_buffer *item)
-{
- REMQUE(item);
- free(item->string);
- free(item);
-}
-
-static void
-dispatch_free_all(qelement *head)
-{
- command_buffer *item;
-
- while (!EMPTYQUE(*head)) {
- item = (command_buffer *) head->q_forw;
- dispatch_free_command(item);
- }
-}
-
-static command_buffer *
-dispatch_add_command(qelement *head, char *string)
-{
- command_buffer *new;
-
- new = malloc(sizeof(command_buffer));
-
- if (!new)
- return NULL;
-
- new->string = strdup(string);
- INSQUEUE(new, head->q_back);
-
- return new;
-}
-
-/*
- * Command processing
- */
-
-/* Just convenience */
-static int
-dispatch_shutdown(dialogMenuItem *unused)
-{
- systemShutdown(0);
- return DITEM_FAILURE;
-}
-
-static int
-dispatch_systemExecute(dialogMenuItem *unused)
-{
- char *cmd = variable_get(VAR_COMMAND);
-
- if (cmd)
- return systemExecute(cmd) ? DITEM_FAILURE : DITEM_SUCCESS;
- else
- msgDebug("_systemExecute: No command passed in `command' variable.\n");
- return DITEM_FAILURE;
-}
-
-static int
-dispatch_msgConfirm(dialogMenuItem *unused)
-{
- char *msg = variable_get(VAR_COMMAND);
-
- if (msg) {
- msgConfirm("%s", msg);
- return DITEM_SUCCESS;
- }
-
- msgDebug("_msgConfirm: No message passed in `command' variable.\n");
- return DITEM_FAILURE;
-}
-
-static int
-dispatch_mediaClose(dialogMenuItem *unused)
-{
- mediaClose();
- return DITEM_SUCCESS;
-}
-
-static int
-call_possible_resword(char *name, dialogMenuItem *value, int *status)
-{
- int i, rval;
-
- rval = 0;
- for (i = 0; resWords[i].name; i++) {
- if (!strcmp(name, resWords[i].name)) {
- *status = resWords[i].handler(value);
- rval = 1;
- break;
- }
- }
- return rval;
-}
-
-/* For a given string, call it or spit out an undefined command diagnostic */
-int
-dispatchCommand(char *str)
-{
- int i;
- char *cp;
-
- if (!str || !*str) {
- msgConfirm("Null or zero-length string passed to dispatchCommand");
- return DITEM_FAILURE;
- }
- /* If it's got a newline, trim it */
- if ((cp = index(str, '\n')) != NULL)
- *cp = '\0';
-
- /* If it's got a `=' sign in there, assume it's a variable setting */
- if (index(str, '=')) {
- if (isDebug())
- msgDebug("dispatch: setting variable `%s'\n", str);
- variable_set(str, 0);
- i = DITEM_SUCCESS;
- }
- else {
- /* A command might be a pathname if it's encoded in argv[0], which
- we also support */
- if ((cp = rindex(str, '/')) != NULL)
- str = cp + 1;
- if (isDebug())
- msgDebug("dispatch: calling resword `%s'\n", str);
- if (!call_possible_resword(str, NULL, &i)) {
- msgNotify("Warning: No such command ``%s''", str);
- i = DITEM_FAILURE;
- }
- /*
- * Allow a user to prefix a command with "noError" to cause
- * us to ignore any errors for that one command.
- */
- if (i != DITEM_SUCCESS && variable_get(VAR_NO_ERROR))
- i = DITEM_SUCCESS;
- variable_unset(VAR_NO_ERROR);
- }
- return i;
-}
-
-
-/*
- * File processing
- */
-
-static qelement *
-dispatch_load_fp(FILE *fp)
-{
- qelement *head;
- char buf[BUFSIZ], *cp;
-
- head = malloc(sizeof(qelement));
-
- if (!head)
- return NULL;
-
- INITQUE(*head);
-
- while (fgets(buf, sizeof buf, fp)) {
-
- if ((cp = strchr(buf, '\n')) != NULL)
- *cp = '\0';
- if (*buf == '\0' || *buf == '#')
- continue;
-
- if (!dispatch_add_command(head, buf))
- return NULL;
- }
-
- return head;
-}
-
-static int
-dispatch_execute(qelement *head)
-{
- int result = DITEM_SUCCESS;
- command_buffer *item;
- char *old_interactive;
-
- if (!head)
- return result | DITEM_FAILURE;
-
- old_interactive = variable_get(VAR_NONINTERACTIVE);
- if (old_interactive)
- old_interactive = strdup(old_interactive); /* save copy */
-
- /* Hint to others that we're running from a script, should they care */
- variable_set2(VAR_NONINTERACTIVE, "yes", 0);
-
- while (!EMPTYQUE(*head)) {
- item = (command_buffer *) head->q_forw;
-
- if (DITEM_STATUS(dispatchCommand(item->string)) != DITEM_SUCCESS) {
- msgConfirm("Command `%s' failed - rest of script aborted.\n",
- item->string);
- result |= DITEM_FAILURE;
- break;
- }
- dispatch_free_command(item);
- }
-
- dispatch_free_all(head);
-
- if (!old_interactive)
- variable_unset(VAR_NONINTERACTIVE);
- else {
- variable_set2(VAR_NONINTERACTIVE, old_interactive, 0);
- free(old_interactive);
- }
-
- return result;
-}
-
-int
-dispatch_load_file_int(int quiet)
-{
- FILE *fp;
- char *cp;
- int i;
- qelement *list;
-
- static const char *names[] = {
- "install.cfg",
- "/stand/install.cfg",
- "/tmp/install.cfg",
- NULL
- };
-
- fp = NULL;
- cp = variable_get(VAR_CONFIG_FILE);
- if (!cp) {
- for (i = 0; names[i]; i++)
- if ((fp = fopen(names[i], "r")) != NULL)
- break;
- } else
- fp = fopen(cp, "r");
-
- if (!fp) {
- if (!quiet)
- msgConfirm("Unable to open %s: %s", cp, strerror(errno));
- return DITEM_FAILURE;
- }
-
- list = dispatch_load_fp(fp);
- fclose(fp);
-
- return dispatch_execute(list);
-}
-
-int
-dispatch_load_file(dialogMenuItem *self)
-{
- return dispatch_load_file_int(FALSE);
-}
-
-int
-dispatch_load_floppy(dialogMenuItem *self)
-{
- int what = DITEM_SUCCESS;
- extern char *distWanted;
- char *cp;
- FILE *fp;
- qelement *list;
-
- mediaClose();
- cp = variable_get_value(VAR_INSTALL_CFG,
- "Specify the name of a configuration file\n"
- "residing on a MSDOS or UFS floppy.", 0);
- if (!cp || !*cp) {
- variable_unset(VAR_INSTALL_CFG);
- what |= DITEM_FAILURE;
- return what;
- }
-
- distWanted = cp;
- /* Try to open the floppy drive */
- if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE) {
- msgConfirm("Unable to set media device to floppy.");
- what |= DITEM_FAILURE;
- mediaClose();
- return what;
- }
-
- if (!DEVICE_INIT(mediaDevice)) {
- msgConfirm("Unable to mount floppy filesystem.");
- what |= DITEM_FAILURE;
- mediaClose();
- return what;
- }
-
- fp = DEVICE_GET(mediaDevice, cp, TRUE);
- if (fp) {
- list = dispatch_load_fp(fp);
- fclose(fp);
- mediaClose();
-
- what |= dispatch_execute(list);
- }
- else {
- if (!variable_get(VAR_NO_ERROR))
- msgConfirm("Configuration file '%s' not found.", cp);
- variable_unset(VAR_INSTALL_CFG);
- what |= DITEM_FAILURE;
- mediaClose();
- }
- return what;
-}
-
diff --git a/usr.sbin/sade/dmenu.c b/usr.sbin/sade/dmenu.c
deleted file mode 100644
index 7f113fc132b3..000000000000
--- a/usr.sbin/sade/dmenu.c
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last attempt in the `sysinstall' line, the next
- * generation being slated for what's essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-#include <errno.h>
-
-#define MAX_MENU 15
-
-static Boolean exited;
-
-int
-dmenuDisplayFile(dialogMenuItem *tmp)
-{
- systemDisplayHelp((char *)tmp->data);
- return DITEM_SUCCESS;
-}
-
-int
-dmenuSubmenu(dialogMenuItem *tmp)
-{
- return (dmenuOpenSimple((DMenu *)(tmp->data), FALSE) ? DITEM_SUCCESS : DITEM_FAILURE);
-}
-
-int
-dmenuSystemCommand(dialogMenuItem *self)
-{
- WINDOW *w = NULL; /* Keep lint happy */
-
- /* If aux is set, the command is known not to produce any screen-spoiling output */
- if (!self->aux)
- w = savescr();
- systemExecute((char *)self->data);
- if (!self->aux)
- restorescr(w);
- return DITEM_SUCCESS;
-}
-
-int
-dmenuSystemCommandBox(dialogMenuItem *tmp)
-{
- WINDOW *w = savescr();
-
- use_helpfile(NULL);
- use_helpline("Select OK to dismiss this dialog");
- dialog_prgbox(tmp->title, (char *)tmp->data, 22, 76, 1, 1);
- restorescr(w);
- return DITEM_SUCCESS;
-}
-
-int
-dmenuExit(dialogMenuItem *tmp)
-{
- exited = TRUE;
- return DITEM_LEAVE_MENU;
-}
-
-int
-dmenuSetVariable(dialogMenuItem *tmp)
-{
- variable_set((char *)tmp->data, *((char *)tmp->data) != '_');
- return DITEM_SUCCESS;
-}
-
-int
-dmenuSetVariables(dialogMenuItem *tmp)
-{
- char *cp1, *cp2;
- char *copy = strdup((char *)tmp->data);
-
- for (cp1 = copy; cp1 != NULL;) {
- cp2 = index(cp1, ',');
- if (cp2 != NULL) *cp2++ = '\0';
- variable_set(cp1, *cp1 != '_');
- cp1 = cp2;
- }
- free(copy);
- return DITEM_SUCCESS;
-}
-
-int
-dmenuSetKmapVariable(dialogMenuItem *tmp)
-{
- char *lang;
- int err;
-
- variable_set((char *)tmp->data, TRUE);
- lang = variable_get(VAR_KEYMAP);
- if (lang != NULL)
- {
- err = loadKeymap(lang);
- if (err == -1)
- msgConfirm("No appropriate keyboard map found, sorry.");
- else if (err == -2)
- msgConfirm("Error installing keyboard map, errno = %d.", errno);
- }
- return DITEM_SUCCESS;
-}
-
-int
-dmenuToggleVariable(dialogMenuItem *tmp)
-{
- char *var, *cp;
- int status;
-
- if (!(var = strdup((char *)tmp->data))) {
- msgConfirm("Incorrect data field for `%s'!", tmp->title);
- return DITEM_FAILURE;
- }
- if (!(cp = index(var, '='))) {
- msgConfirm("Data field for %s is not in var=value format!", tmp->title);
- return DITEM_FAILURE;
- }
- status = variable_check(var);
- *cp = '\0';
- variable_set2(var, status ? "NO" : "YES", *var != '_');
- free(var);
- return DITEM_SUCCESS;
-}
-
-int
-dmenuISetVariable(dialogMenuItem *tmp)
-{
- char *ans, *var;
-
- if (!(var = (char *)tmp->data)) {
- msgConfirm("Incorrect data field for `%s'!", tmp->title);
- return DITEM_FAILURE;
- }
- ans = msgGetInput(variable_get(var), tmp->title, 1);
- if (!ans)
- return DITEM_FAILURE;
- else if (!*ans)
- variable_unset(var);
- else
- variable_set2(var, ans, *var != '_');
- return DITEM_SUCCESS;
-}
-
-int
-dmenuSetFlag(dialogMenuItem *tmp)
-{
- if (*((unsigned int *)tmp->data) & tmp->aux)
- *((unsigned int *)tmp->data) &= ~tmp->aux;
- else
- *((unsigned int *)tmp->data) |= tmp->aux;
- return DITEM_SUCCESS;
-}
-
-int
-dmenuSetValue(dialogMenuItem *tmp)
-{
- *((unsigned int *)tmp->data) = tmp->aux;
- return DITEM_SUCCESS;
-}
-
-/* Traverse menu but give user no control over positioning */
-Boolean
-dmenuOpenSimple(DMenu *menu, Boolean buttons)
-{
- int choice, scroll, curr, max;
-
- choice = scroll = curr = max = 0;
- return dmenuOpen(menu, &choice, &scroll, &curr, &max, buttons);
-}
-
-/* Work functions for the state hook */
-int
-dmenuFlagCheck(dialogMenuItem *item)
-{
- return (*((unsigned int *)item->data) & item->aux);
-}
-
-int
-dmenuVarCheck(dialogMenuItem *item)
-{
- char *w;
-
- w = (char *)item->aux;
- if (!w)
- w = (char *)item->data;
- return variable_check(w);
-}
-
-int
-dmenuVarsCheck(dialogMenuItem *item)
-{
- int res, init;
- char *w, *cp1, *cp2;
- char *copy;
-
- w = (char *)item->aux;
- if (!w)
- w = (char *)item->data;
- if (!w)
- return FALSE;
-
- copy = strdup(w);
- res = TRUE;
- init = FALSE;
- for (cp1 = copy; cp1 != NULL;) {
- init = TRUE;
- cp2 = index(cp1, ',');
- if (cp2 != NULL)
- *cp2++ = '\0';
- res = res && variable_check(cp1);
- cp1 = cp2;
- }
- free(copy);
- return res && init;
-}
-
-int
-dmenuRadioCheck(dialogMenuItem *item)
-{
- return (*((unsigned int *)item->data) == item->aux);
-}
-
-static int
-menu_height(DMenu *menu, int n)
-{
- int max;
- char *t;
-
- max = MAX_MENU;
- if (StatusLine > 24)
- max += StatusLine - 24;
- for (t = menu->prompt; *t; t++) {
- if (*t == '\n')
- --max;
- }
- return n > max ? max : n;
-}
-
-/* Traverse over an internal menu */
-Boolean
-dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons)
-{
- int n, rval = 0;
- dialogMenuItem *items;
-
- items = menu->items;
- if (buttons)
- items += 2;
- /* Count up all the items */
- for (n = 0; items[n].title; n++);
-
- while (1) {
- char buf[FILENAME_MAX];
- WINDOW *w = savescr();
-
- /* Any helpful hints, put 'em up! */
- use_helpline(menu->helpline);
- use_helpfile(systemHelpFile(menu->helpfile, buf));
- dialog_clear_norefresh();
- /* Pop up that dialog! */
- if (menu->type & DMENU_NORMAL_TYPE)
- rval = dialog_menu((u_char *)menu->title, (u_char *)menu->prompt, -1, -1,
- menu_height(menu, n), -n, items, (char *)buttons, choice, scroll);
-
- else if (menu->type & DMENU_RADIO_TYPE)
- rval = dialog_radiolist((u_char *)menu->title, (u_char *)menu->prompt, -1, -1,
- menu_height(menu, n), -n, items, (char *)buttons);
-
- else if (menu->type & DMENU_CHECKLIST_TYPE)
- rval = dialog_checklist((u_char *)menu->title, (u_char *)menu->prompt, -1, -1,
- menu_height(menu, n), -n, items, (char *)buttons);
- else
- msgFatal("Menu: `%s' is of an unknown type\n", menu->title);
- if (exited) {
- exited = FALSE;
- restorescr(w);
- return TRUE;
- }
- else if (rval) {
- restorescr(w);
- return FALSE;
- }
- else if (menu->type & DMENU_SELECTION_RETURNS) {
- restorescr(w);
- return TRUE;
- }
- }
-}
diff --git a/usr.sbin/sade/globals.c b/usr.sbin/sade/globals.c
deleted file mode 100644
index 4323bd0e130b..000000000000
--- a/usr.sbin/sade/globals.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last program in the `sysinstall' line - the next
- * generation being essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-
-/*
- * Various global variables and an initialization hook to set them to
- * whatever values we feel are appropriate.
- */
-
-int DebugFD; /* Where diagnostic output goes */
-Boolean Fake; /* Only pretend to be useful */
-Boolean RunningAsInit; /* Are we running as init? */
-Boolean DialogActive; /* Is libdialog initialized? */
-Boolean ColorDisplay; /* Are we on a color display? */
-Boolean OnVTY; /* Are we on a VTY? */
-Boolean Restarting; /* Are we restarting sysinstall? */
-Variable *VarHead; /* The head of the variable chain */
-Device *mediaDevice; /* Where we're installing from */
-int BootMgr; /* Which boot manager we're using */
-int StatusLine; /* Where to stick our status messages */
-jmp_buf BailOut; /* Beam me up, scotty! The natives are pissed! */
-
-/*
- * Yes, I know some of these are already automatically initialized as
- * globals. I simply find it clearer to set everything explicitly.
- */
-void
-globalsInit(void)
-{
- DebugFD = -1;
- ColorDisplay = FALSE;
- Fake = FALSE;
- Restarting = FALSE;
- OnVTY = FALSE;
- DialogActive = FALSE;
- VarHead = NULL;
- mediaDevice = NULL;
- RunningAsInit = FALSE;
-}
diff --git a/usr.sbin/sade/help/partition.hlp b/usr.sbin/sade/help/partition.hlp
deleted file mode 100644
index 1d62148e88f9..000000000000
--- a/usr.sbin/sade/help/partition.hlp
+++ /dev/null
@@ -1,169 +0,0 @@
-This is the FreeBSD DiskLabel Editor.
-
-NOTE: If you're entering this editor from the update procedure then
-you probably shouldn't (C)reate anything at all but rather use only
-the (M)ount command to check and mount existing partitions for
-upgrading.
-
-If you would like the label editor to do most of the following for
-you, simply type `A' for automatic partitioning of the disk.
-
-If you wish to create partitions manually you may do so by moving the
-highlighted selection bar with the arrow keys over the FreeBSD
-partition(s) displayed at the top of the screen. Typing (C)reate
-while a partition with available free space is selected will allow you
-to create a BSD partition inside of it using some or all of its
-available space.
-
-Typing (M)ount over an existing partition entry (displayed in the
-middle of the screen) will allow you to set a mount point for it
-without initializing it. If you want it initialized, use the (T)oggle
-command to flip the Newfs flag. When Newfs is set to "Y", the
-filesystem in question will be ERASED and rebuilt from scratch!
-
-
-You should use this editor to create at least the following
-filesystems:
-
- Name Purpose Min Size? Optional?
- ---- ------- --------- ---------
- / Root filesystem 118MB No
- swap Swap space 2 * MEM No
- /usr System & user files 80MB or more Yes
-
-Note: If you do not create a /usr filesystem then your / filesystem
-will need to be bigger - at least 200MB. This is not recommended as
-any media errors that may occur during disk I/O to user files will
-corrupt the filesystem containing vital system files as well. It is
-for this reason that / is generally kept on its own filesystem, where
-it should be considered essentially "read only" in your administration
-of it.
-
-Swap space is a little tricker, and the rule of "2 * MEM" is simply a
-best-guess approximation and not necessarily accurate for your
-intended usage of the system. If you intend to use the system heavily
-in a server or multi-user application, you may be well advised to
-increase this size. You may also create swap space on multiple drives
-for a larger "total" swap and this is, in fact, recommended if you
-have multiple, fast drives for which such load-balancing can only help
-overall I/O performance.
-
-The /usr filesystem should be sized according to what kind of
-distributions you're trying to load and how many packages you intend
-to install in locations like /usr/local. You can also make /usr/local
-a separate filesystem if you don't want to risk filling up your /usr
-by mistake.
-
-Another useful filesystem to create is /var, which contains mail, news
-printer spool files and other temporary items. It is a popular
-candidate for a separate partition and should be sized according to
-your estimates of the amount of mail, news or spooled print jobs that
-may be stored there.
-
-WARNING: If you do not create a separate filesystem for /var, space
-for such files will be allocated out of the root (/) filesystem
-instead. You may therefore wish to make the / partition bigger if you
-expect a lot of mail or news and do not want to make /var its own
-partition.
-
-If you're new to this installation, you might also want to read the
-following explanation of how FreeBSD's new "slice" paradigm for
-looking at disk storage works:
-
-
-In FreeBSD's new system, a device name can be broken up into up to 3
-parts. Take a typical name like ``/dev/da0s1a'':
-
- The first three characters represent the drive name. If we had
- a system with two SCSI drives on it then we'd see /dev/da0 and
- /dev/da1 as the device entries representing the entire drives.
-
- Next you have the "slice" (or "FDISK Partition") number,
- as seen in the Partition Editor. Assuming that our da0
- contained two slices, a FreeBSD slice and a DOS slice, that
- would give us /dev/da0s1 and /dev/da0s2 as device entries pointing
- to the entire slices.
-
- Next, if a slice is a FreeBSD slice, you can have a number of
- (confusingly named) "partitions" inside of it.
-
- These partitions are where various filesystems or swap areas live,
- and using our hypothetical two-SCSI-disk machine again, we might
- have something like the following layout on da0:
-
- Name Mountpoint
- ---- ----------
- da0s1a /
- da0s1b <swap space>
- da0s1e /usr
-
-Once you understand all this, then the purpose of the label editor
-becomes fairly clear: You're carving up the FreeBSD slices displayed
-at the top of the screen into smaller pieces, which are displayed in
-the middle of the screen, and then assigning FreeBSD file system names
-(mount points) to them.
-
-You can also use the label editor to mount existing partitions/slices
-into your filesystem hierarchy, as is frequently done for DOS FAT
-slices. For FreeBSD partitions, you can also toggle the "newfs" state
-so that the partitions are either (re)created from scratch or simply
-checked and mounted (the contents are preserved).
-
-If you set (S)oftUpdates on a filesystem, it will cause the
-"Soft Updates" policy to be in effect for it. This basically causes
-both metadata and data blocks to be written asynchronously to disk,
-but with extra state information which causes the metadata and any
-related data blocks to be committed in a single transaction. This
-results in async metadata update speeds (which are considerably
-faster than the default sync) without the potential for data loss
-which could occur if you simply mounted the filesystem with purely
-"async" update policy and then had a power failure. If you wish
-to later turn the softupdates policy back off, use the command
-"tunefs -n disable devicename". NOTE: It is probably not wise
-to use this on your root filesystem unless you have a large
-(e.g. non-standard size) root. The reason is that smaller filesystems
-with significant activity can temporarily overflow if the soft updates
-policy results in free'd blocks not being "garbage collected" as fast
-as they're being requested.
-
-The UNIX File System (UFS) on FreeBSD supports two different on-disk
-layouts: UFS1 and UFS2. UFS1 was the default file system in use
-through FreeBSD 5.0-RELEASE; as of FreeBSD 5.1-RELEASE, the default
-is now UFS2, with the exception of the PC98 platform. UFS2 provides
-sparse inode allocation (faster fsck), 64-bit storage pointers (larger
-maximum size), and native extended attributes (required for ACLs, MAC,
-and other advanced security and file system services). The selection
-of UFS1 or UFS2 must be made when the file system is created--later
-conversion is not currently possible. UFS2 is the recommended file
-system, but if disks are to be used on older FreeBSD systems, UFS1
-improves portability. When dual-booting between FreeBSD 4.x or
-earlier and FreeBSD 5.x, UFS1 file systems will be accessible from
-both. To toggle a file system to UFS1, press '1'. To restore it to
-UFS2, press '2'.
-
-WARNING: FreeBSD on i386 is currently unable to boot from root file
-systems larger than 1.5TB.
-
-To add additional flags to the newfs command line for UFS file
-systems, press 'N'. These options will be specified before the
-device argument of the command line, but after any other options
-placed there by sysinstall, such as the UFS version and soft
-updates flag; as such, arguments provided may override existing
-settings. To completely replace the newfs command used by
-sysinstall, press 'Z' to convert a partition to a Custom
-partition type. Sysinstall will prompt you with the newfs
-command line that it would have used based on existing settings
-prior to the change, but allow you to modify any aspect of the
-command line. Once a partition has been converted to a custom
-partition in the label editor, you will need to restart the
-labeling process or delete and recreate the partition to restore
-it to a non-custom state. Custom partitions are represented by
-the letters "CST" instead of "UFS" or "FAT.
-
-When you're done, type `Q' to exit.
-
-No actual changes will be made to the disk until you (C)ommit from the
-Install menu or (W)rite directly from this one. You're working with
-what is essentially a copy of the disk label(s), both here and in the
-FDISK Partition Editor, and the actual on-disk labels won't be
-affected by any changes you make until you explicitly say so.
diff --git a/usr.sbin/sade/help/slice.hlp b/usr.sbin/sade/help/slice.hlp
deleted file mode 100644
index b6f6a831ba03..000000000000
--- a/usr.sbin/sade/help/slice.hlp
+++ /dev/null
@@ -1,65 +0,0 @@
-This is the Main Slice (``FDISK'' or PC-style Partition) Editor.
-
-Possible commands are printed at the bottom and the Master Boot Record
-contents are shown at the top. You can move up and down with the
-arrow keys and (C)reate a new slice whenever the highlighted
-selection bar is over a slice whose type is marked as "unused."
-
-You are expected to leave this screen with at least one slice
-marked "FreeBSD." Note that unlike Linux, you don't need to create
-multiple FreeBSD FDISK partition entries for different things like
-swap, file systems, etc. The usual convention is to create ONE
-FreeBSD slice (FDISK partition) per drive and then subsection this slice
-into swap and file systems with the Label editor.
-
-No actual changes will be made to the disk until you (C)ommit from the
-Install menu or use the (W)rite option here! You're working with what
-is essentially a copy of the disk label(s), both here and in the Label
-Editor.
-
-If you want to use the entire disk for FreeBSD, type `A'. You'll be
-asked whether or not you wish to keep the disk (potentially) compatible
-with other operating systems, i.e. the information in the FDISK table
-should be kept valid. If you select the default of `Yes', slices will be
-aligned to fictitious cylinder boundaries and space will be reserved
-in front of the FreeBSD slice for a [future] possible boot manager.
-
-For the truly dedicated disk case, you can select `No' at the
-compatibility prompt. In that case, all BIOS geometry considerations
-will no longer be in effect and you can safely ignore any
-``The detected geometry is invalid'' warning messages you may later
-see. It is also not necessary in this case to set a slice bootable
-or install an MBR boot manager as both things are then irrelevant.
-
-The FreeBSD slice will start at absolute sector 0 of the disk (so that
-FreeBSD's disk label is identical to the Master Boot Record) and
-extend to the very last sector of the disk medium. Needless to say,
-such a disk cannot have any sort of a boot manager, `disk manager',
-or anything else that has to interact with the BIOS. This option is
-therefore only considered safe for SCSI disks and most IDE disks and
-is primarily intended for people who are going to set up a dedicated
-FreeBSD server or workstation, not a typical `home PC'.
-
-The flags field has the following legend:
-
- '=' -- This slice is properly aligned.
- '>' -- This slice doesn't end before cylinder 1024
- 'R' -- This slice contains the root (/) filesystem
- 'B' -- Slice employs BAD144 bad-spot handling
- 'C' -- This is the FreeBSD 2.0-compatibility slice (default)
- 'A' -- This slice is marked active.
-
-If you select a slice for Bad144 handling, it will be scanned
-for bad blocks before any new filesystems are made on it.
-
-If no slice is marked Active, you will need to either install
-a Boot Manager (the option for which will be presented later in the
-installation) or set one Active before leaving this screen.
-
-To leave the slice editor, type `Q'.
-
-Final Note: If you're absolutely sure you know what you're doing
- and you want to use the old "Dangerously Dedicated" mode
- which is now deprecated by sysinstall, use the (purposely)
- undocumented `F' key.
-
diff --git a/usr.sbin/sade/install.c b/usr.sbin/sade/install.c
deleted file mode 100644
index acc53f82d922..000000000000
--- a/usr.sbin/sade/install.c
+++ /dev/null
@@ -1,1262 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last program in the `sysinstall' line - the next
- * generation being essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-#include <ctype.h>
-#include <sys/disklabel.h>
-#include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/fcntl.h>
-#include <sys/wait.h>
-#include <sys/uio.h>
-#include <sys/param.h>
-#define MSDOSFS
-#include <sys/mount.h>
-#include <ufs/ufs/ufsmount.h>
-#include <fs/msdosfs/msdosfsmount.h>
-#undef MSDOSFS
-#include <sys/stat.h>
-#include <sys/sysctl.h>
-#include <limits.h>
-#include <unistd.h>
-#include <termios.h>
-
-/* Hack for rsaref package add, which displays interactive license.
- * Used by package.c
- */
-int _interactiveHack;
-int FixItMode = 0;
-
-static void create_termcap(void);
-static void fixit_common(void);
-
-#define TERMCAP_FILE "/usr/share/misc/termcap"
-
-static void installConfigure(void);
-
-Boolean
-checkLabels(Boolean whinge, Chunk **rdev, Chunk **sdev, Chunk **udev, Chunk **vdev, Chunk **tdev, Chunk **hdev)
-{
- Device **devs;
- Boolean status;
- Disk *disk;
- Chunk *c1, *c2, *rootdev, *swapdev, *usrdev, *vardev, *tmpdev, *homedev;
- int i;
-
- /* Don't allow whinging if noWarn is set */
- if (variable_get(VAR_NO_WARN))
- whinge = FALSE;
-
- status = TRUE;
- if (rdev)
- *rdev = NULL;
- if (sdev)
- *sdev = NULL;
- if (udev)
- *udev = NULL;
- if (vdev)
- *vdev = NULL;
- if (tdev)
- *tdev = NULL;
- if (hdev)
- *hdev = NULL;
- rootdev = swapdev = usrdev = vardev = tmpdev = homedev = NULL;
-
- /* We don't need to worry about root/usr/swap if we're already multiuser */
- if (!RunningAsInit)
- return status;
-
- devs = deviceFind(NULL, DEVICE_TYPE_DISK);
- /* First verify that we have a root device */
- for (i = 0; devs[i]; i++) {
- if (!devs[i]->enabled)
- continue;
- disk = (Disk *)devs[i]->private;
- msgDebug("Scanning disk %s for root filesystem\n", disk->name);
- if (!disk->chunks)
- msgFatal("No chunk list found for %s!", disk->name);
- for (c1 = disk->chunks->part; c1; c1 = c1->next) {
- if (c1->type == freebsd) {
- for (c2 = c1->part; c2; c2 = c2->next) {
- if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) {
- if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/")) {
- if (rootdev) {
- if (whinge)
- msgConfirm("WARNING: You have more than one root device set?!\n"
- "Using the first one found.");
- continue;
- }
- else {
- rootdev = c2;
- if (isDebug())
- msgDebug("Found rootdev at %s!\n", rootdev->name);
- }
- }
- else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/usr")) {
- if (usrdev) {
- if (whinge)
- msgConfirm("WARNING: You have more than one /usr filesystem.\n"
- "Using the first one found.");
- continue;
- }
- else {
- usrdev = c2;
- if (isDebug())
- msgDebug("Found usrdev at %s!\n", usrdev->name);
- }
- }
- else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/var")) {
- if (vardev) {
- if (whinge)
- msgConfirm("WARNING: You have more than one /var filesystem.\n"
- "Using the first one found.");
- continue;
- }
- else {
- vardev = c2;
- if (isDebug())
- msgDebug("Found vardev at %s!\n", vardev->name);
- }
- } else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/tmp")) {
- if (tmpdev) {
- if (whinge)
- msgConfirm("WARNING: You have more than one /tmp filesystem.\n"
- "Using the first one found.");
- continue;
- }
- else {
- tmpdev = c2;
- if (isDebug())
- msgDebug("Found tmpdev at %s!\n", tmpdev->name);
- }
- } else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/home")) {
- if (homedev) {
- if (whinge)
- msgConfirm("WARNING: You have more than one /home filesystem.\n"
- "Using the first one found.");
- continue;
- }
- else {
- homedev = c2;
- if (isDebug())
- msgDebug("Found homedev at %s!\n", homedev->name);
- }
- }
- }
- }
- }
- }
- }
-
- /* Now check for swap devices */
- for (i = 0; devs[i]; i++) {
- if (!devs[i]->enabled)
- continue;
- disk = (Disk *)devs[i]->private;
- msgDebug("Scanning disk %s for swap partitions\n", disk->name);
- if (!disk->chunks)
- msgFatal("No chunk list found for %s!", disk->name);
- for (c1 = disk->chunks->part; c1; c1 = c1->next) {
- if (c1->type == freebsd) {
- for (c2 = c1->part; c2; c2 = c2->next) {
- if (c2->type == part && c2->subtype == FS_SWAP && !swapdev) {
- swapdev = c2;
- if (isDebug())
- msgDebug("Found swapdev at %s!\n", swapdev->name);
- break;
- }
- }
- }
- }
- }
-
- /* Copy our values over */
- if (rdev)
- *rdev = rootdev;
- if (sdev)
- *sdev = swapdev;
- if (udev)
- *udev = usrdev;
- if (vdev)
- *vdev = vardev;
- if (tdev)
- *tdev = tmpdev;
- if (hdev)
- *hdev = homedev;
-
- if (!rootdev && whinge) {
- msgConfirm("No root device found - you must label a partition as /\n"
- "in the label editor.");
- status = FALSE;
- }
- if (!swapdev && whinge) {
- msgConfirm("No swap devices found - you must create at least one\n"
- "swap partition.");
- status = FALSE;
- }
- return status;
-}
-
-static int
-installInitial(void)
-{
- static Boolean alreadyDone = FALSE;
- int status = DITEM_SUCCESS;
-
- if (alreadyDone)
- return DITEM_SUCCESS;
-
- if (!variable_get(DISK_LABELLED)) {
- msgConfirm("You need to assign disk labels before you can proceed with\n"
- "the installation.");
- return DITEM_FAILURE;
- }
- /* If it's labelled, assume it's also partitioned */
- if (!variable_get(DISK_PARTITIONED))
- variable_set2(DISK_PARTITIONED, "yes", 0);
-
- /* If we refuse to proceed, bail. */
- dialog_clear_norefresh();
- if (!variable_get(VAR_NO_WARN)) {
- if (msgYesNo(
- "Last Chance! Are you SURE you want continue the installation?\n\n"
- "If you're running this on a disk with data you wish to save\n"
- "then WE STRONGLY ENCOURAGE YOU TO MAKE PROPER BACKUPS before\n"
- "proceeding!\n\n"
- "We can take no responsibility for lost disk contents!") != 0)
- return DITEM_FAILURE;
- }
-
- if (DITEM_STATUS(diskLabelCommit(NULL)) != DITEM_SUCCESS) {
- msgConfirm("Couldn't make filesystems properly. Aborting.");
- return DITEM_FAILURE;
- }
-
- if (!copySelf()) {
- msgConfirm("installInitial: Couldn't clone the boot floppy onto the\n"
- "root file system. Aborting!");
- return DITEM_FAILURE;
- }
-
- if (!Restarting && chroot("/mnt") == -1) {
- msgConfirm("installInitial: Unable to chroot to %s - this is bad!",
- "/mnt");
- return DITEM_FAILURE;
- }
-
- chdir("/");
- variable_set2(RUNNING_ON_ROOT, "yes", 0);
-
- /* Configure various files in /etc */
- if (DITEM_STATUS(configResolv(NULL)) == DITEM_FAILURE)
- status = DITEM_FAILURE;
- if (DITEM_STATUS(configFstab(NULL)) == DITEM_FAILURE)
- status = DITEM_FAILURE;
-
- /* stick a helpful shell over on the 4th VTY */
- if (!variable_get(VAR_NO_HOLOSHELL))
- systemCreateHoloshell();
-
- alreadyDone = TRUE;
- return status;
-}
-
-int
-installFixitHoloShell(dialogMenuItem *self)
-{
- FixItMode = 1;
- systemCreateHoloshell();
- return DITEM_SUCCESS;
- FixItMode = 0;
-}
-
-int
-installFixitCDROM(dialogMenuItem *self)
-{
- struct stat sb;
-
- if (!RunningAsInit)
- return DITEM_SUCCESS;
-
- variable_set2(SYSTEM_STATE, "fixit", 0);
- (void)unlink("/mnt2");
- (void)rmdir("/mnt2");
-
- while (1) {
- msgConfirm("Please insert a FreeBSD live filesystem CD/DVD and press return");
- if (DITEM_STATUS(mediaSetCDROM(NULL)) != DITEM_SUCCESS
- || !DEVICE_INIT(mediaDevice)) {
- /* If we can't initialize it, it's probably not a FreeBSD CDROM so punt on it */
- mediaClose();
- if (msgYesNo("Unable to mount the disc - do you want to try again?") != 0)
- return DITEM_FAILURE;
- }
- else
- break;
- }
-
- /* Since the fixit code expects everything to be in /mnt2, and the CDROM mounting stuff /dist, do
- * a little kludge dance here..
- */
- if (symlink("/dist", "/mnt2")) {
- msgConfirm("Unable to symlink /mnt2 to the disc mount point. Please report this\n"
- "unexpected failure to freebsd-bugs@FreeBSD.org.");
- return DITEM_FAILURE;
- }
-
- /*
- * If /tmp points to /mnt2/tmp from a previous fixit floppy session, it's
- * not very good for us if we point it to the CDROM now. Rather make it
- * a directory in the root MFS then. Experienced admins will still be
- * able to mount their disk's /tmp over this if they need.
- */
- if (lstat("/tmp", &sb) == 0 && (sb.st_mode & S_IFMT) == S_IFLNK)
- (void)unlink("/tmp");
- Mkdir("/tmp");
-
- /*
- * Since setuid binaries ignore LD_LIBRARY_PATH, we indeed need the
- * ld.so.hints file. Fortunately, it's fairly small (~ 3 KB).
- */
- if (!file_readable("/var/run/ld.so.hints")) {
- Mkdir("/var/run");
- if (vsystem("/mnt2/sbin/ldconfig -s /mnt2/usr/lib")) {
- msgConfirm("Warning: ldconfig could not create the ld.so hints file.\n"
- "Dynamic executables from the disc likely won't work.");
- }
- }
-
- /* Yet more iggly hardcoded pathnames. */
- Mkdir("/usr/libexec");
- if (!file_readable("/usr/libexec/ld.so") && file_readable("/mnt2/usr/libexec/ld.so")) {
- if (symlink("/mnt2/usr/libexec/ld.so", "/usr/libexec/ld.so"))
- msgDebug("Couldn't link to ld.so - not necessarily a problem for ELF\n");
- }
- if (!file_readable("/usr/libexec/ld-elf.so.1")) {
- if (symlink("/mnt2/usr/libexec/ld-elf.so.1", "/usr/libexec/ld-elf.so.1")) {
- msgConfirm("Warning: could not create the symlink for ld-elf.so.1\n"
- "Dynamic executables from the disc likely won't work.");
- }
- }
- /* optional nicety */
- if (!file_readable("/usr/bin/vi"))
- symlink("/mnt2/usr/bin/vi", "/usr/bin/vi");
- fixit_common();
- mediaClose();
- msgConfirm("Please remove the FreeBSD fixit CDROM/DVD now.");
- return DITEM_SUCCESS;
-}
-
-int
-installFixitFloppy(dialogMenuItem *self)
-{
- struct ufs_args args;
- extern char *distWanted;
-
- if (!RunningAsInit)
- return DITEM_SUCCESS;
-
- /* Try to open the floppy drive */
- if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE || !mediaDevice) {
- msgConfirm("Unable to set media device to floppy.");
- mediaClose();
- return DITEM_FAILURE;
- }
-
- memset(&args, 0, sizeof(args));
- args.fspec = mediaDevice->devname;
- mediaDevice->private = "/mnt2";
- distWanted = NULL;
- Mkdir("/mnt2");
-
- variable_set2(SYSTEM_STATE, "fixit", 0);
-
- while (1) {
- if (!DEVICE_INIT(mediaDevice)) {
- if (msgYesNo("The attempt to mount the fixit floppy failed, bad floppy\n"
- "or unclean filesystem. Do you want to try again?"))
- return DITEM_FAILURE;
- }
- else
- break;
- }
- if (!directory_exists("/tmp"))
- (void)symlink("/mnt2/tmp", "/tmp");
- fixit_common();
- mediaClose();
- msgConfirm("Please remove the fixit floppy now.");
- return DITEM_SUCCESS;
-}
-
-/*
- * The common code for both fixit variants.
- */
-static void
-fixit_common(void)
-{
- pid_t child;
- int waitstatus;
-
- if (!directory_exists("/var/tmp/vi.recover")) {
- if (DITEM_STATUS(Mkdir("/var/tmp/vi.recover")) != DITEM_SUCCESS) {
- msgConfirm("Warning: Was unable to create a /var/tmp/vi.recover directory.\n"
- "vi will kvetch and moan about it as a result but should still\n"
- "be essentially usable.");
- }
- }
- if (!directory_exists("/bin"))
- (void)Mkdir("/bin");
- (void)symlink("/stand/sh", "/bin/sh");
- /* Link the /etc/ files */
- if (DITEM_STATUS(Mkdir("/etc")) != DITEM_SUCCESS)
- msgConfirm("Unable to create an /etc directory! Things are weird on this floppy..");
- else if ((symlink("/mnt2/etc/spwd.db", "/etc/spwd.db") == -1 && errno != EEXIST) ||
- (symlink("/mnt2/etc/protocols", "/etc/protocols") == -1 && errno != EEXIST) ||
- (symlink("/mnt2/etc/group", "/etc/group") == -1 && errno != EEXIST) ||
- (symlink("/mnt2/etc/services", "/etc/services") == -1 && errno != EEXIST))
- msgConfirm("Couldn't symlink the /etc/ files! I'm not sure I like this..");
- if (!file_readable(TERMCAP_FILE))
- create_termcap();
- if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0)
- systemSuspendDialog(); /* must be before the fork() */
- if (!(child = fork())) {
- int i, fd;
- struct termios foo;
- extern int login_tty(int);
-
- ioctl(0, TIOCNOTTY, NULL);
- for (i = getdtablesize(); i >= 0; --i)
- close(i);
-
- if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0)
- fd = open("/dev/console", O_RDWR);
- else
- fd = open("/dev/ttyv3", O_RDWR);
- ioctl(0, TIOCSCTTY, &fd);
- dup2(0, 1);
- dup2(0, 2);
- DebugFD = 2;
- if (login_tty(fd) == -1)
- msgDebug("fixit: I can't set the controlling terminal.\n");
-
- signal(SIGTTOU, SIG_IGN);
- if (tcgetattr(0, &foo) != -1) {
- foo.c_cc[VERASE] = '\010';
- if (tcsetattr(0, TCSANOW, &foo) == -1)
- msgDebug("fixit shell: Unable to set erase character.\n");
- }
- else
- msgDebug("fixit shell: Unable to get terminal attributes!\n");
- setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/stand:"
- "/mnt2/stand:/mnt2/bin:/mnt2/sbin:/mnt2/usr/bin:/mnt2/usr/sbin", 1);
- if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) {
- printf("Waiting for fixit shell to exit.\n"
- "When you are done, type ``exit'' to exit\n"
- "the fixit shell and be returned here.\n\n");
- fflush(stdout);
- }
-
- /* use the .profile from the fixit medium */
- setenv("HOME", "/mnt2", 1);
- chdir("/mnt2");
- execlp("sh", "-sh", (char *)0);
- msgDebug("fixit shell: Failed to execute shell!\n");
- _exit(1);;
- }
- else {
- if (strcmp(variable_get(VAR_FIXIT_TTY), "standard") == 0) {
- dialog_clear_norefresh();
- msgNotify("Waiting for fixit shell to exit. Go to VTY4 now by\n"
- "typing ALT-F4. When you are done, type ``exit'' to exit\n"
- "the fixit shell and be returned here\n.");
- }
- (void)waitpid(child, &waitstatus, 0);
- if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0)
- systemResumeDialog();
- }
- dialog_clear();
-}
-
-
-int
-installExpress(dialogMenuItem *self)
-{
- int i;
-
- dialog_clear_norefresh();
- variable_set2(SYSTEM_STATE, "express", 0);
-#ifdef WITH_SLICES
- if (DITEM_STATUS((i = diskPartitionEditor(self))) == DITEM_FAILURE)
- return i;
-#endif
-
- if (DITEM_STATUS((i = diskLabelEditor(self))) == DITEM_FAILURE)
- return i;
-
- if (DITEM_STATUS((i = installCommit(self))) == DITEM_SUCCESS) {
- i |= DITEM_LEAVE_MENU;
- /* Set default security level */
- configSecurityModerate(NULL);
-
- /* Give user the option of one last configuration spree */
- installConfigure();
- }
- return i;
-}
-
-/* Standard mode installation */
-int
-installStandard(dialogMenuItem *self)
-{
- int i, tries = 0;
- Device **devs;
-
- variable_set2(SYSTEM_STATE, "standard", 0);
- dialog_clear_norefresh();
-#ifdef WITH_SLICES
- msgConfirm("In the next menu, you will need to set up a DOS-style (\"fdisk\") partitioning\n"
- "scheme for your hard disk. If you simply wish to devote all disk space\n"
- "to FreeBSD (overwriting anything else that might be on the disk(s) selected)\n"
- "then use the (A)ll command to select the default partitioning scheme followed\n"
- "by a (Q)uit. If you wish to allocate only free space to FreeBSD, move to a\n"
- "partition marked \"unused\" and use the (C)reate command.");
-
-nodisks:
- if (DITEM_STATUS(diskPartitionEditor(self)) == DITEM_FAILURE)
- return DITEM_FAILURE;
-
- if (diskGetSelectCount(&devs) <= 0 && tries < 3) {
- msgConfirm("You need to select some disks to operate on! Be sure to use SPACE\n"
- "instead of RETURN in the disk selection menu when selecting a disk.");
- ++tries;
- goto nodisks;
- }
-
- msgConfirm("Now you need to create BSD partitions inside of the fdisk partition(s)\n"
- "just created. If you have a reasonable amount of disk space (200MB or more)\n"
- "and don't have any special requirements, simply use the (A)uto command to\n"
- "allocate space automatically. If you have more specific needs or just don't\n"
- "care for the layout chosen by (A)uto, press F1 for more information on\n"
- "manual layout.");
-#else
- msgConfirm("First you need to create BSD partitions on the disk which you are\n"
- "installing to. If you have a reasonable amount of disk space (200MB or more)\n"
- "and don't have any special requirements, simply use the (A)uto command to\n"
- "allocate space automatically. If you have more specific needs or just don't\n"
- "care for the layout chosen by (A)uto, press F1 for more information on\n"
- "manual layout.");
-#endif
-
- if (DITEM_STATUS(diskLabelEditor(self)) == DITEM_FAILURE)
- return DITEM_FAILURE;
-
- if (DITEM_STATUS((i = installCommit(self))) == DITEM_FAILURE) {
- dialog_clear();
- msgConfirm("Installation completed with some errors. You may wish to\n"
- "scroll through the debugging messages on VTY1 with the\n"
- "scroll-lock feature. You can also choose \"No\" at the next\n"
- "prompt and go back into the installation menus to retry\n"
- "whichever operations have failed.");
- return i;
-
- }
- else {
- dialog_clear();
- msgConfirm("Congratulations! You now have FreeBSD installed on your system.\n\n"
- "We will now move on to the final configuration questions.\n"
- "For any option you do not wish to configure, simply select\n"
- "No.\n\n"
- "If you wish to re-enter this utility after the system is up, you\n"
- "may do so by typing: /usr/sbin/sysinstall.");
- }
- if (mediaDevice->type != DEVICE_TYPE_FTP && mediaDevice->type != DEVICE_TYPE_NFS) {
- if (!msgYesNo("Would you like to configure any Ethernet or SLIP/PPP network devices?")) {
- Device *tmp = tcpDeviceSelect();
-
- if (tmp && !((DevInfo *)tmp->private)->use_dhcp && !msgYesNo("Would you like to bring the %s interface up right now?", tmp->name))
- if (!DEVICE_INIT(tmp))
- msgConfirm("Initialization of %s device failed.", tmp->name);
- }
- dialog_clear_norefresh();
- }
-
- if (!msgNoYes("Do you want this machine to function as a network gateway?"))
- variable_set2("gateway_enable", "YES", 1);
-
- dialog_clear_norefresh();
- if (!msgNoYes("Do you want to configure inetd and the network services that it provides?"))
- configInetd(self);
-
- dialog_clear_norefresh();
- if (!msgNoYes("Do you want to have anonymous FTP access to this machine?"))
- configAnonFTP(self);
-
- dialog_clear_norefresh();
- if (!msgNoYes("Do you want to configure this machine as an NFS server?"))
- configNFSServer(self);
-
- dialog_clear_norefresh();
- if (!msgNoYes("Do you want to configure this machine as an NFS client?"))
- variable_set2("nfs_client_enable", "YES", 1);
-
- if (!msgNoYes("Do you want to select a default security profile for\n"
- "this host (select No for \"moderate\" security)?"))
- configSecurityProfile(self);
- else
- configSecurityModerate(self);
-
-#ifdef WITH_SYSCONS
- dialog_clear_norefresh();
- if (!msgNoYes("Would you like to customize your system console settings?"))
- dmenuOpenSimple(&MenuSyscons, FALSE);
-#endif
-
- dialog_clear_norefresh();
- if (!msgYesNo("Would you like to set this machine's time zone now?"))
- systemExecute("tzsetup");
-
-#ifdef WITH_LINUX
- dialog_clear_norefresh();
- if (!msgYesNo("Would you like to enable Linux binary compatibility?"))
- (void)configLinux(self);
-#endif
-
-#ifdef __alpha__
- dialog_clear_norefresh();
- if (!msgYesNo("Would you like to enable OSF/1 binary compatibility?"))
- (void)configOSF1(self);
-#endif
-
-#ifdef WITH_MICE
- dialog_clear_norefresh();
- if (!msgNoYes("Does this system have a PS/2, serial, or bus mouse?"))
- dmenuOpenSimple(&MenuMouse, FALSE);
-#endif
-
-#ifdef __i386__
- if (checkLoaderACPI() != 0) {
- dialog_clear_norefresh();
- if (!msgNoYes("ACPI was disabled during boot.\n"
- "Would you like to disable it permanently?"))
- (void)configLoaderACPI(1 /*disable*/);
- }
-#endif
-
- /* Now would be a good time to checkpoint the configuration data */
- configRC_conf();
- sync();
-
- if (directory_exists("/usr/X11R6")) {
- dialog_clear_norefresh();
- if (!msgYesNo("Would you like to configure your X server at this time?"))
- (void)configXSetup(self);
- }
-
- dialog_clear_norefresh();
- if (!msgYesNo("The FreeBSD package collection is a collection of thousands of ready-to-run\n"
- "applications, from text editors to games to WEB servers and more. Would you\n"
- "like to browse the collection now?")) {
- (void)configPackages(self);
- }
-
- if (!msgYesNo("Would you like to add any initial user accounts to the system?\n"
- "Adding at least one account for yourself at this stage is suggested\n"
- "since working as the \"root\" user is dangerous (it is easy to do\n"
- "things which adversely affect the entire system)."))
- (void)configUsers(self);
-
- msgConfirm("Now you must set the system manager's password.\n"
- "This is the password you'll use to log in as \"root\".");
- if (!systemExecute("passwd root"))
- variable_set2("root_password", "YES", 0);
-
- /* XXX Put whatever other nice configuration questions you'd like to ask the user here XXX */
-
- /* Give user the option of one last configuration spree */
- dialog_clear_norefresh();
- installConfigure();
- return DITEM_LEAVE_MENU;
-}
-
-/* The version of commit we call from the Install Custom menu */
-int
-installCustomCommit(dialogMenuItem *self)
-{
- int i;
-
- i = installCommit(self);
- if (DITEM_STATUS(i) == DITEM_SUCCESS) {
- /* Set default security level */
- configSecurityModerate(NULL);
-
- /* Give user the option of one last configuration spree */
- installConfigure();
- return i;
- }
- else
- msgConfirm("The commit operation completed with errors. Not\n"
- "updating /etc files.");
- return i;
-}
-
-/*
- * What happens when we finally decide to going ahead with the installation.
- *
- * This is broken into multiple stages so that the user can do a full
- * installation but come back here again to load more distributions,
- * perhaps from a different media type. This would allow, for
- * example, the user to load the majority of the system from CDROM and
- * then use ftp to load just the CRYPTO dist.
- */
-int
-installCommit(dialogMenuItem *self)
-{
- int i;
- char *str;
-
- dialog_clear_norefresh();
- if (!Dists)
- distConfig(NULL);
-
- if (!Dists) {
- (void)dmenuOpenSimple(&MenuDistributions, FALSE);
- /* select reasonable defaults if necessary */
- if (!Dists)
- Dists = _DIST_USER;
- }
-
- if (!mediaVerify())
- return DITEM_FAILURE;
-
- str = variable_get(SYSTEM_STATE);
- if (isDebug())
- msgDebug("installCommit: System state is `%s'\n", str);
-
- /* Installation stuff we wouldn't do to a running system */
- if (RunningAsInit && DITEM_STATUS((i = installInitial())) == DITEM_FAILURE)
- return i;
-
-try_media:
- if (!DEVICE_INIT(mediaDevice)) {
- if (!msgYesNo("Unable to initialize selected media. Would you like to\n"
- "adjust your media configuration and try again?")) {
- mediaDevice = NULL;
- if (!mediaVerify())
- return DITEM_FAILURE;
- else
- goto try_media;
- }
- else
- return DITEM_FAILURE;
- }
-
- /* Now go get it all */
- i = distExtractAll(self);
-
- /* When running as init, *now* it's safe to grab the rc.foo vars */
- installEnvironment();
-
- variable_set2(SYSTEM_STATE, DITEM_STATUS(i) == DITEM_FAILURE ? "error-install" : "full-install", 0);
-
- return i;
-}
-
-static void
-installConfigure(void)
-{
- /* Final menu of last resort */
- if (!msgNoYes("Visit the general configuration menu for a chance to set\n"
- "any last options?"))
- dmenuOpenSimple(&MenuConfigure, FALSE);
- configRC_conf();
- sync();
-}
-
-int
-installFixupBase(dialogMenuItem *self)
-{
- Device **devs;
- char *cp;
- int i;
- FILE *fp;
- int kstat = 1;
-
- /* All of this is done only as init, just to be safe */
- if (RunningAsInit) {
-#if defined(__i386__) || defined(__amd64__)
- if ((fp = fopen("/boot/loader.conf", "a")) != NULL) {
- if (!kstat || !OnVTY)
- fprintf(fp, "# -- sysinstall generated deltas -- #\n");
- if (!kstat)
- fprintf(fp, "userconfig_script_load=\"YES\"\n");
- if (!OnVTY)
- fprintf(fp, "console=\"comconsole\"\n");
- fclose(fp);
- }
-#endif
-
- /* BOGON #2: We leave /etc in a bad state */
- chmod("/etc", 0755);
-
- /* BOGON #3: No /var/db/mountdtab complains */
- Mkdir("/var/db");
- creat("/var/db/mountdtab", 0644);
-
- /* BOGON #4: /compat created by default in root fs */
- Mkdir("/usr/compat");
- vsystem("ln -s usr/compat /compat");
-
- /* BOGON #5: aliases database not build for bin */
- vsystem("newaliases");
-
- /* Now run all the mtree stuff to fix things up */
- vsystem("mtree -deU -f /etc/mtree/BSD.root.dist -p /");
- vsystem("mtree -deU -f /etc/mtree/BSD.var.dist -p /var");
- vsystem("mtree -deU -f /etc/mtree/BSD.usr.dist -p /usr");
-
- /* Do all the last ugly work-arounds here */
- }
- return DITEM_SUCCESS | DITEM_RESTORE;
-}
-
-#ifndef X_AS_PKG
-/* Fix side-effects from the the XFree86 installation */
-int
-installFixupXFree(dialogMenuItem *self)
-{
- /* BOGON #1: XFree86 requires various specialized fixups */
- if (directory_exists("/usr/X11R6")) {
- dialog_clear_norefresh();
- msgNotify("Fixing permissions in XFree86 tree..");
- vsystem("chmod -R a+r /usr/X11R6");
- vsystem("find /usr/X11R6 -type d | xargs chmod a+x");
-
- /* Also do bogus minimal package registration so ports don't whine */
- if (file_readable("/usr/X11R6/lib/X11/pkgreg.tar.gz")) {
- dialog_clear_norefresh();
- msgNotify("Installing package metainfo..");
- vsystem("tar xpzf /usr/X11R6/lib/X11/pkgreg.tar.gz -C / && rm /usr/X11R6/lib/X11/pkgreg.tar.gz");
- }
- }
- return DITEM_SUCCESS | DITEM_RESTORE;
-}
-#endif
-
-#define QUEUE_YES 1
-#define QUEUE_NO 0
-static int
-performNewfs(PartInfo *pi, char *dname, int queue)
-{
- char buffer[LINE_MAX];
-
- if (pi->do_newfs) {
- switch(pi->newfs_type) {
- case NEWFS_UFS:
- snprintf(buffer, LINE_MAX, "%s %s %s %s %s",
- NEWFS_UFS_CMD,
- pi->newfs_data.newfs_ufs.softupdates ? "-U" : "",
- pi->newfs_data.newfs_ufs.ufs1 ? "-O1" : "-O2",
- pi->newfs_data.newfs_ufs.user_options,
- dname);
- break;
-
- case NEWFS_MSDOS:
- snprintf(buffer, LINE_MAX, "%s %s", NEWFS_MSDOS_CMD,
- dname);
- break;
-
- case NEWFS_CUSTOM:
- snprintf(buffer, LINE_MAX, "%s %s",
- pi->newfs_data.newfs_custom.command, dname);
- break;
- }
-
- if (queue == QUEUE_YES) {
- command_shell_add(pi->mountpoint, buffer);
- return (0);
- } else
- return (vsystem(buffer));
- }
- return (0);
-}
-
-/* Go newfs and/or mount all the filesystems we've been asked to */
-int
-installFilesystems(dialogMenuItem *self)
-{
- int i;
- Disk *disk;
- Chunk *c1, *c2, *rootdev, *swapdev;
- Device **devs;
- PartInfo *root;
- char dname[80];
- Boolean upgrade = FALSE;
-#if defined(__ia64__)
- char efi_bootdir[FILENAME_MAX];
-#endif
-
- /* If we've already done this, bail out */
- if (!variable_cmp(DISK_LABELLED, "written"))
- return DITEM_SUCCESS;
-
- upgrade = !variable_cmp(SYSTEM_STATE, "upgrade");
- if (!checkLabels(TRUE, &rootdev, &swapdev, NULL, NULL, NULL, NULL))
- return DITEM_FAILURE;
-
- if (rootdev)
- root = (PartInfo *)rootdev->private_data;
- else
- root = NULL;
-
- command_clear();
- if (swapdev && RunningAsInit) {
- /* As the very first thing, try to get ourselves some swap space */
- sprintf(dname, "/dev/%s", swapdev->name);
- if (!Fake && !file_readable(dname)) {
- msgConfirm("Unable to find device node for %s in /dev!\n"
- "The creation of filesystems will be aborted.", dname);
- return DITEM_FAILURE;
- }
-
- if (!Fake) {
- if (!swapon(dname)) {
- dialog_clear_norefresh();
- msgNotify("Added %s as initial swap device", dname);
- }
- else {
- msgConfirm("WARNING! Unable to swap to %s: %s\n"
- "This may cause the installation to fail at some point\n"
- "if you don't have a lot of memory.", dname, strerror(errno));
- }
- }
- }
-
- if (rootdev && RunningAsInit) {
- /* Next, create and/or mount the root device */
- sprintf(dname, "/dev/%s", rootdev->name);
- if (!Fake && !file_readable(dname)) {
- msgConfirm("Unable to make device node for %s in /dev!\n"
- "The creation of filesystems will be aborted.", dname);
- return DITEM_FAILURE | DITEM_RESTORE;
- }
- if (strcmp(root->mountpoint, "/"))
- msgConfirm("Warning: %s is marked as a root partition but is mounted on %s", rootdev->name, root->mountpoint);
-
- if (root->do_newfs && (!upgrade ||
- !msgNoYes("You are upgrading - are you SURE you want to newfs "
- "the root partition?"))) {
- int i;
-
- dialog_clear_norefresh();
- msgNotify("Making a new root filesystem on %s", dname);
- i = performNewfs(root, dname, QUEUE_NO);
- if (i) {
- msgConfirm("Unable to make new root filesystem on %s!\n"
- "Command returned status %d", dname, i);
- return DITEM_FAILURE | DITEM_RESTORE;
- }
- }
- else {
- if (!upgrade) {
- msgConfirm("Warning: Using existing root partition. It will be assumed\n"
- "that you have the appropriate device entries already in /dev.");
- }
- dialog_clear_norefresh();
- msgNotify("Checking integrity of existing %s filesystem.", dname);
- i = vsystem("fsck_ffs -y %s", dname);
- if (i)
- msgConfirm("Warning: fsck returned status of %d for %s.\n"
- "This partition may be unsafe to use.", i, dname);
- }
-
- /*
- * If soft updates was enabled in the editor but we didn't newfs,
- * use tunefs to update the soft updates flag on the file system.
- */
- if (!root->do_newfs && root->newfs_type == NEWFS_UFS &&
- root->newfs_data.newfs_ufs.softupdates) {
- i = vsystem("tunefs -n enable %s", dname);
- if (i)
- msgConfirm("Warning: Unable to enable soft updates"
- " for root file system on %s", dname);
- }
-
- /* Switch to block device */
- sprintf(dname, "/dev/%s", rootdev->name);
- if (Mount("/mnt", dname)) {
- msgConfirm("Unable to mount the root file system on %s! Giving up.", dname);
- return DITEM_FAILURE | DITEM_RESTORE;
- }
-
- /* Mount devfs for other partitions to mount */
- Mkdir("/mnt/dev");
- if (!Fake) {
- struct iovec iov[4];
-
- iov[0].iov_base = "fstype";
- iov[0].iov_len = strlen(iov[0].iov_base) + 1;
- iov[1].iov_base = "devfs";
- iov[1].iov_len = strlen(iov[1].iov_base) + 1;
- iov[2].iov_base = "fspath";
- iov[2].iov_len = strlen(iov[2].iov_base) + 1;
- iov[3].iov_base = "/mnt/dev";
- iov[3].iov_len = strlen(iov[3].iov_base) + 1;
- i = nmount(iov, 4, 0);
-
- if (i) {
- dialog_clear_norefresh();
- msgConfirm("Unable to mount DEVFS (error %d)", errno);
- return DITEM_FAILURE | DITEM_RESTORE;
- }
- }
- }
-
- /* Now buzz through the rest of the partitions and mount them too */
- devs = deviceFind(NULL, DEVICE_TYPE_DISK);
- for (i = 0; devs[i]; i++) {
- if (!devs[i]->enabled)
- continue;
-
- disk = (Disk *)devs[i]->private;
- if (!disk->chunks) {
- msgConfirm("No chunk list found for %s!", disk->name);
- return DITEM_FAILURE | DITEM_RESTORE;
- }
- for (c1 = disk->chunks->part; c1; c1 = c1->next) {
- if (c1->type == freebsd) {
- for (c2 = c1->part; c2; c2 = c2->next) {
- if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) {
- PartInfo *tmp = (PartInfo *)c2->private_data;
-
- /* Already did root */
- if (c2 == rootdev)
- continue;
-
- sprintf(dname, "%s/dev/%s",
- RunningAsInit ? "/mnt" : "", c2->name);
-
- if (tmp->do_newfs && (!upgrade ||
- !msgNoYes("You are upgrading - are you SURE you"
- " want to newfs /dev/%s?", c2->name)))
- performNewfs(tmp, dname, QUEUE_YES);
- else
- command_shell_add(tmp->mountpoint,
- "fsck_ffs -y %s/dev/%s", RunningAsInit ?
- "/mnt" : "", c2->name);
-#if 0
- if (tmp->soft)
- command_shell_add(tmp->mountpoint,
- "tunefs -n enable %s/dev/%s", RunningAsInit ?
- "/mnt" : "", c2->name);
-#endif
- command_func_add(tmp->mountpoint, Mount, c2->name);
- }
- else if (c2->type == part && c2->subtype == FS_SWAP) {
- char fname[80];
- int i;
-
- if (c2 == swapdev)
- continue;
- sprintf(fname, "%s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name);
- i = (Fake || swapon(fname));
- if (!i) {
- dialog_clear_norefresh();
- msgNotify("Added %s as an additional swap device", fname);
- }
- else {
- msgConfirm("Unable to add %s as a swap device: %s", fname, strerror(errno));
- }
- }
- }
- }
- else if (c1->type == fat && c1->private_data &&
- (root->do_newfs || upgrade)) {
- char name[FILENAME_MAX];
-
- sprintf(name, "%s/%s", RunningAsInit ? "/mnt" : "", ((PartInfo *)c1->private_data)->mountpoint);
- Mkdir(name);
- }
-#if defined(__ia64__)
- else if (c1->type == efi && c1->private_data) {
- char bootdir[FILENAME_MAX];
- PartInfo *pi = (PartInfo *)c1->private_data;
- char *p;
-
- sprintf(dname, "%s/dev/%s", RunningAsInit ? "/mnt" : "",
- c1->name);
-
- if (pi->do_newfs && (!upgrade ||
- !msgNoYes("You are upgrading - are you SURE you want to "
- "newfs /dev/%s?", c1->name)))
- performNewfs(pi, dname, QUEUE_YES);
-
- command_func_add(pi->mountpoint, Mount_msdosfs, c1->name);
-
- /*
- * Create a directory boot on the EFI filesystem and create a
- * link boot on the root filesystem pointing to the one on the
- * EFI filesystem. That way, we install the loader, kernel
- * and modules on the EFI filesystem.
- */
- sprintf(bootdir, "%s", RunningAsInit ? "/mnt" : "");
- sprintf(efi_bootdir, "%s/%s", bootdir, pi->mountpoint);
- strcat(bootdir, "/boot");
- strcat(efi_bootdir, "/boot");
- command_func_add(pi->mountpoint, Mkdir_command, efi_bootdir);
-
- /* Make a relative link. */
- p = &efi_bootdir[(RunningAsInit) ? 4 : 0];
- while (*p == '/')
- p++;
- symlink(p, bootdir);
- }
-#endif
- }
- }
-
- command_sort();
- command_execute();
- dialog_clear_norefresh();
- return DITEM_SUCCESS | DITEM_RESTORE;
-}
-
-static char *
-getRelname(void)
-{
- static char buf[64];
- size_t sz = (sizeof buf) - 1;
-
- if (sysctlbyname("kern.osrelease", buf, &sz, NULL, 0) != -1) {
- buf[sz] = '\0';
- return buf;
- }
- else
- return "<unknown>";
-}
-
-/* Initialize various user-settable values to their defaults */
-int
-installVarDefaults(dialogMenuItem *self)
-{
- char *cp;
-
- /* Set default startup options */
- variable_set2(VAR_RELNAME, getRelname(), 0);
- variable_set2(VAR_CPIO_VERBOSITY, "high", 0);
- variable_set2(VAR_TAPE_BLOCKSIZE, DEFAULT_TAPE_BLOCKSIZE, 0);
- variable_set2(VAR_INSTALL_ROOT, "/", 0);
- variable_set2(VAR_INSTALL_CFG, "install.cfg", 0);
- cp = getenv("EDITOR");
- if (!cp)
- cp = "/usr/bin/ee";
- variable_set2(VAR_EDITOR, cp, 0);
- variable_set2(VAR_FTP_USER, "ftp", 0);
- variable_set2(VAR_BROWSER_PACKAGE, "links", 0);
- variable_set2(VAR_BROWSER_BINARY, "/usr/local/bin/links", 0);
- variable_set2(VAR_FTP_STATE, "passive", 0);
- variable_set2(VAR_NFS_SECURE, "NO", -1);
- if (OnVTY)
- variable_set2(VAR_FIXIT_TTY, "standard", 0);
- else
- variable_set2(VAR_FIXIT_TTY, "serial", 0);
- variable_set2(VAR_PKG_TMPDIR, "/var/tmp", 0);
- variable_set2(VAR_MEDIA_TIMEOUT, itoa(MEDIA_TIMEOUT), 0);
- if (getpid() != 1)
- variable_set2(SYSTEM_STATE, "update", 0);
- else
- variable_set2(SYSTEM_STATE, "init", 0);
- variable_set2(VAR_NEWFS_ARGS, "-b 16384 -f 2048", 0);
- variable_set2(VAR_CONSTERM, "NO", 0);
- return DITEM_SUCCESS;
-}
-
-/* Load the environment up from various system configuration files */
-void
-installEnvironment(void)
-{
- configEnvironmentRC_conf();
- if (file_readable("/etc/resolv.conf"))
- configEnvironmentResolv("/etc/resolv.conf");
-}
-
-/* Copy the boot floppy contents into /stand */
-Boolean
-copySelf(void)
-{
- int i;
-
- if (file_readable("/boot.help"))
- vsystem("cp /boot.help /mnt");
- msgWeHaveOutput("Copying the boot floppy to /stand on root filesystem");
- i = vsystem("find -x /stand | cpio %s -pdum /mnt", cpioVerbosity());
- if (i) {
- msgConfirm("Copy returned error status of %d!", i);
- return FALSE;
- }
-
- /* Copy the /etc files into their rightful place */
- if (vsystem("cd /mnt/stand; find etc | cpio %s -pdum /mnt", cpioVerbosity())) {
- msgConfirm("Couldn't copy up the /etc files!");
- return TRUE;
- }
- return TRUE;
-}
-
-static void
-create_termcap(void)
-{
- FILE *fp;
-
- const char *caps[] = {
- termcap_vt100, termcap_cons25, termcap_cons25_m, termcap_cons25r,
- termcap_cons25r_m, termcap_cons25l1, termcap_cons25l1_m,
- termcap_xterm, NULL,
- };
- const char **cp;
-
- if (!file_readable(TERMCAP_FILE)) {
- Mkdir("/usr/share/misc");
- fp = fopen(TERMCAP_FILE, "w");
- if (!fp) {
- msgConfirm("Unable to initialize termcap file. Some screen-oriented\nutilities may not work.");
- return;
- }
- cp = caps;
- while (*cp)
- fprintf(fp, "%s\n", *(cp++));
- fclose(fp);
- }
-}
diff --git a/usr.sbin/sade/keymap.c b/usr.sbin/sade/keymap.c
deleted file mode 100644
index 3c53a0070a17..000000000000
--- a/usr.sbin/sade/keymap.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 1996 Joerg Wunsch
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that 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 DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (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$
- *
- */
-
-#include "sysinstall.h"
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/kbio.h>
-
-struct keymapInfo {
- const char *name;
- const struct keymap *map;
-};
-
-#include "keymap.h"
-
-/*
- * keymap.h is being automatically generated by the Makefile. It
- * contains definitions for all desired keymaps. Note that since we
- * don't support font loading nor screen mapping during installation,
- * we simply don't care for any other keys than the ASCII subset.
- *
- * Therefore, if no keymap with the exact name has been found in the
- * first pass, we make a second pass over the table looking just for
- * the language name only.
- */
-
-/*
- * Return values:
- *
- * 0: OK
- * -1: no appropriate keymap found
- * -2: error installing map (other than ENXIO which means we're not on syscons)
- */
-
-int
-loadKeymap(const char *lang)
-{
- int passno, err;
- char *llang;
- size_t l;
- struct keymapInfo *kip;
-
- llang = strdup(lang);
- if (llang == NULL)
- abort();
-
- for (passno = 0; passno < 2; passno++)
- {
- if (passno > 0)
- {
- /* make the match more fuzzy */
- l = strspn(llang, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
- llang[l] = '\0';
- }
-
- l = strlen(llang);
-
- for (kip = keymapInfos; kip->name; kip++)
- if (strncmp(kip->name, llang, l) == 0)
- {
- /* Yep, got it! */
- err = ioctl(0, PIO_KEYMAP, kip->map);
- free(llang);
- return (err == -1 && errno != ENOTTY)? -2: 0;
- }
- }
- free(llang);
- return -1;
-}
diff --git a/usr.sbin/sade/label.c b/usr.sbin/sade/label.c
deleted file mode 100644
index bf97140966a1..000000000000
--- a/usr.sbin/sade/label.c
+++ /dev/null
@@ -1,1607 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last program in the `sysinstall' line - the next
- * generation being essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-#include <ctype.h>
-#include <sys/disklabel.h>
-#include <sys/param.h>
-#include <sys/sysctl.h>
-
-#define AUTO_HOME 0 /* do not create /home automatically */
-
-/*
- * Everything to do with editing the contents of disk labels.
- */
-
-/* A nice message we use a lot in the disklabel editor */
-#define MSG_NOT_APPLICABLE "That option is not applicable here"
-
-/* Where to start printing the freebsd slices */
-#define CHUNK_SLICE_START_ROW 2
-#define CHUNK_PART_START_ROW 11
-
-/* The smallest filesystem we're willing to create */
-#define FS_MIN_SIZE ONE_MEG
-
-/*
- * Minimum partition sizes
- */
-#if defined(__alpha__) || defined(__ia64__) || defined(__sparc64__) || defined(__amd64__)
-#define ROOT_MIN_SIZE 128
-#else
-#define ROOT_MIN_SIZE 118
-#endif
-#define SWAP_MIN_SIZE 32
-#define USR_MIN_SIZE 80
-#define VAR_MIN_SIZE 20
-#define TMP_MIN_SIZE 20
-#define HOME_MIN_SIZE 20
-
-/*
- * Swap size limit for auto-partitioning (4G).
- */
-#define SWAP_AUTO_LIMIT_SIZE 4096
-
-/*
- * Default partition sizes. If we do not have sufficient disk space
- * for this configuration we scale things relative to the NOM vs DEFAULT
- * sizes. If the disk is larger then /home will get any remaining space.
- */
-#define ROOT_DEFAULT_SIZE 256
-#define USR_DEFAULT_SIZE 3072
-#define VAR_DEFAULT_SIZE 256
-#define TMP_DEFAULT_SIZE 256
-#define HOME_DEFAULT_SIZE USR_DEFAULT_SIZE
-
-/*
- * Nominal partition sizes. These are used to scale the default sizes down
- * when we have insufficient disk space. If this isn't sufficient we scale
- * down using the MIN sizes instead.
- */
-#define ROOT_NOMINAL_SIZE 192
-#define USR_NOMINAL_SIZE 512
-#define VAR_NOMINAL_SIZE 64
-#define TMP_NOMINAL_SIZE 64
-#define HOME_NOMINAL_SIZE USR_NOMINAL_SIZE
-
-/* The bottom-most row we're allowed to scribble on */
-#define CHUNK_ROW_MAX 16
-
-
-/* All the chunks currently displayed on the screen */
-static struct {
- struct chunk *c;
- PartType type;
-} label_chunk_info[MAX_CHUNKS + 1];
-static int here;
-
-/*** with this value we try to track the most recently added label ***/
-static int label_focus = 0, pslice_focus = 0;
-
-static int diskLabel(Device *dev);
-static int diskLabelNonInteractive(Device *dev);
-static char *try_auto_label(Device **devs, Device *dev, int perc, int *req);
-
-static int
-labelHook(dialogMenuItem *selected)
-{
- Device **devs = NULL;
-
- devs = deviceFind(selected->prompt, DEVICE_TYPE_DISK);
- if (!devs) {
- msgConfirm("Unable to find disk %s!", selected->prompt);
- return DITEM_FAILURE;
- }
- /* Toggle enabled status? */
- if (!devs[0]->enabled) {
- devs[0]->enabled = TRUE;
- diskLabel(devs[0]);
- }
- else
- devs[0]->enabled = FALSE;
- return DITEM_SUCCESS;
-}
-
-static int
-labelCheck(dialogMenuItem *selected)
-{
- Device **devs = NULL;
-
- devs = deviceFind(selected->prompt, DEVICE_TYPE_DISK);
- if (!devs || devs[0]->enabled == FALSE)
- return FALSE;
- return TRUE;
-}
-
-int
-diskLabelEditor(dialogMenuItem *self)
-{
- DMenu *menu;
- Device **devs;
- int i, cnt;
-
- i = 0;
- cnt = diskGetSelectCount(&devs);
- if (cnt == -1) {
- msgConfirm("No disks found! Please verify that your disk controller is being\n"
- "properly probed at boot time. See the Hardware Guide on the\n"
- "Documentation menu for clues on diagnosing this type of problem.");
- return DITEM_FAILURE;
- }
- else if (cnt) {
- /* Some are already selected */
- if (variable_get(VAR_NONINTERACTIVE) &&
- !variable_get(VAR_DISKINTERACTIVE))
- i = diskLabelNonInteractive(NULL);
- else
- i = diskLabel(NULL);
- }
- else {
- /* No disks are selected, fall-back case now */
- cnt = deviceCount(devs);
- if (cnt == 1) {
- devs[0]->enabled = TRUE;
- if (variable_get(VAR_NONINTERACTIVE) &&
- !variable_get(VAR_DISKINTERACTIVE))
- i = diskLabelNonInteractive(devs[0]);
- else
- i = diskLabel(devs[0]);
- }
- else {
- menu = deviceCreateMenu(&MenuDiskDevices, DEVICE_TYPE_DISK, labelHook, labelCheck);
- if (!menu) {
- msgConfirm("No devices suitable for installation found!\n\n"
- "Please verify that your disk controller (and attached drives)\n"
- "were detected properly. This can be done by pressing the\n"
- "[Scroll Lock] key and using the Arrow keys to move back to\n"
- "the boot messages. Press [Scroll Lock] again to return.");
- i = DITEM_FAILURE;
- }
- else {
- i = dmenuOpenSimple(menu, FALSE) ? DITEM_SUCCESS : DITEM_FAILURE;
- free(menu);
- }
- }
- }
- if (DITEM_STATUS(i) != DITEM_FAILURE) {
- if (variable_cmp(DISK_LABELLED, "written"))
- variable_set2(DISK_LABELLED, "yes", 0);
- }
- return i;
-}
-
-int
-diskLabelCommit(dialogMenuItem *self)
-{
- char *cp;
- int i;
-
- /* Already done? */
- if ((cp = variable_get(DISK_LABELLED)) && strcmp(cp, "yes"))
- i = DITEM_SUCCESS;
- else if (!cp) {
- msgConfirm("You must assign disk labels before this option can be used.");
- i = DITEM_FAILURE;
- }
- /* The routine will guard against redundant writes, just as this one does */
- else if (DITEM_STATUS(diskPartitionWrite(self)) != DITEM_SUCCESS)
- i = DITEM_FAILURE;
- else if (DITEM_STATUS(installFilesystems(self)) != DITEM_SUCCESS)
- i = DITEM_FAILURE;
- else {
- msgInfo("All filesystem information written successfully.");
- variable_set2(DISK_LABELLED, "written", 0);
- i = DITEM_SUCCESS;
- }
- return i;
-}
-
-/* See if we're already using a desired partition name */
-static Boolean
-check_conflict(char *name)
-{
- int i;
-
- for (i = 0; label_chunk_info[i].c; i++)
- if ((label_chunk_info[i].type == PART_FILESYSTEM || label_chunk_info[i].type == PART_FAT)
- && label_chunk_info[i].c->private_data
- && !strcmp(((PartInfo *)label_chunk_info[i].c->private_data)->mountpoint, name))
- return TRUE;
- return FALSE;
-}
-
-/* How much space is in this FreeBSD slice? */
-static int
-space_free(struct chunk *c)
-{
- struct chunk *c1;
- int sz = c->size;
-
- for (c1 = c->part; c1; c1 = c1->next) {
- if (c1->type != unused)
- sz -= c1->size;
- }
- if (sz < 0)
- msgFatal("Partitions are larger than actual chunk??");
- return sz;
-}
-
-/* Snapshot the current situation into the displayed chunks structure */
-static void
-record_label_chunks(Device **devs, Device *dev)
-{
- int i, j, p;
- struct chunk *c1, *c2;
- Disk *d;
-
- j = p = 0;
- /* First buzz through and pick up the FreeBSD slices */
- for (i = 0; devs[i]; i++) {
- if ((dev && devs[i] != dev) || !devs[i]->enabled)
- continue;
- d = (Disk *)devs[i]->private;
- if (!d->chunks)
- msgFatal("No chunk list found for %s!", d->name);
-
- /* Put the slice entries first */
- for (c1 = d->chunks->part; c1; c1 = c1->next) {
- if (c1->type == freebsd) {
- label_chunk_info[j].type = PART_SLICE;
- label_chunk_info[j].c = c1;
- ++j;
- }
- }
- }
-
- /* Now run through again and get the FreeBSD partition entries */
- for (i = 0; devs[i]; i++) {
- if (!devs[i]->enabled)
- continue;
- d = (Disk *)devs[i]->private;
- /* Then buzz through and pick up the partitions */
- for (c1 = d->chunks->part; c1; c1 = c1->next) {
- if (c1->type == freebsd) {
- for (c2 = c1->part; c2; c2 = c2->next) {
- if (c2->type == part) {
- if (c2->subtype == FS_SWAP)
- label_chunk_info[j].type = PART_SWAP;
- else
- label_chunk_info[j].type = PART_FILESYSTEM;
- label_chunk_info[j].c = c2;
- ++j;
- }
- }
- }
- else if (c1->type == fat || c1->type == efi) {
- label_chunk_info[j].type = PART_FAT;
- label_chunk_info[j].c = c1;
- ++j;
- }
- }
- }
- label_chunk_info[j].c = NULL;
- if (here >= j) {
- here = j ? j - 1 : 0;
- }
-}
-
-/* A new partition entry */
-static PartInfo *
-new_part(char *mpoint, Boolean newfs)
-{
- PartInfo *pi;
-
- if (!mpoint)
- mpoint = "/change_me";
-
- pi = (PartInfo *)safe_malloc(sizeof(PartInfo));
- sstrncpy(pi->mountpoint, mpoint, FILENAME_MAX);
-
- pi->do_newfs = newfs;
-
- pi->newfs_type = NEWFS_UFS;
- strcpy(pi->newfs_data.newfs_ufs.user_options, "");
- pi->newfs_data.newfs_ufs.acls = FALSE;
- pi->newfs_data.newfs_ufs.multilabel = FALSE;
- pi->newfs_data.newfs_ufs.softupdates = strcmp(mpoint, "/");
-#ifdef PC98
- pi->newfs_data.newfs_ufs.ufs1 = TRUE;
-#else
- pi->newfs_data.newfs_ufs.ufs1 = FALSE;
-#endif
-
- return pi;
-}
-
-#if defined(__ia64__)
-static PartInfo *
-new_efi_part(char *mpoint, Boolean newfs)
-{
- PartInfo *pi;
-
- if (!mpoint)
- mpoint = "/efi";
-
- pi = (PartInfo *)safe_malloc(sizeof(PartInfo));
- sstrncpy(pi->mountpoint, mpoint, FILENAME_MAX);
-
- pi->do_newfs = newfs;
- pi->newfs_type = NEWFS_MSDOS;
-
- return pi;
-}
-#endif
-
-/* Get the mountpoint for a partition and save it away */
-static PartInfo *
-get_mountpoint(struct chunk *old)
-{
- char *val;
- PartInfo *tmp;
- Boolean newfs;
-
- if (old && old->private_data)
- tmp = old->private_data;
- else
- tmp = NULL;
- val = msgGetInput(tmp ? tmp->mountpoint : NULL, "Please specify a mount point for the partition");
- if (!val || !*val) {
- if (!old)
- return NULL;
- else {
- free(old->private_data);
- old->private_data = NULL;
- }
- return NULL;
- }
-
- /* Is it just the same value? */
- if (tmp && !strcmp(tmp->mountpoint, val))
- return NULL;
-
- /* Did we use it already? */
- if (check_conflict(val)) {
- msgConfirm("You already have a mount point for %s assigned!", val);
- return NULL;
- }
-
- /* Is it bogus? */
- if (*val != '/') {
- msgConfirm("Mount point must start with a / character");
- return NULL;
- }
-
- /* Is it going to be mounted on root? */
- if (!strcmp(val, "/")) {
- if (old)
- old->flags |= CHUNK_IS_ROOT;
- }
- else if (old)
- old->flags &= ~CHUNK_IS_ROOT;
-
- newfs = TRUE;
- if (tmp) {
- newfs = tmp->do_newfs;
- safe_free(tmp);
- }
- val = string_skipwhite(string_prune(val));
- tmp = new_part(val, newfs);
- if (old) {
- old->private_data = tmp;
- old->private_free = safe_free;
- }
- return tmp;
-}
-
-/* Get the type of the new partiton */
-static PartType
-get_partition_type(void)
-{
- char selection[20];
- int i;
- static unsigned char *fs_types[] = {
- "FS",
- "A file system",
- "Swap",
- "A swap partition.",
- };
- WINDOW *w = savescr();
-
- i = dialog_menu("Please choose a partition type",
- "If you want to use this partition for swap space, select Swap.\n"
- "If you want to put a filesystem on it, choose FS.",
- -1, -1, 2, 2, fs_types, selection, NULL, NULL);
- restorescr(w);
- if (!i) {
- if (!strcmp(selection, "FS"))
- return PART_FILESYSTEM;
- else if (!strcmp(selection, "Swap"))
- return PART_SWAP;
- }
- return PART_NONE;
-}
-
-/* If the user wants a special newfs command for this, set it */
-static void
-getNewfsCmd(PartInfo *p)
-{
- char buffer[NEWFS_CMD_ARGS_MAX];
- char *val;
-
- switch (p->newfs_type) {
- case NEWFS_UFS:
- snprintf(buffer, NEWFS_CMD_ARGS_MAX, "%s %s %s %s",
- NEWFS_UFS_CMD, p->newfs_data.newfs_ufs.softupdates ? "-U" : "",
- p->newfs_data.newfs_ufs.ufs1 ? "-O1" : "-O2",
- p->newfs_data.newfs_ufs.user_options);
- break;
- case NEWFS_MSDOS:
- snprintf(buffer, NEWFS_CMD_ARGS_MAX, "%s", NEWFS_MSDOS_CMD);
- break;
- case NEWFS_CUSTOM:
- strcpy(buffer, p->newfs_data.newfs_custom.command);
- break;
- }
-
- val = msgGetInput(buffer,
- "Please enter the newfs command and options you'd like to use in\n"
- "creating this file system.");
- if (val != NULL) {
- p->newfs_type = NEWFS_CUSTOM;
- strlcpy(p->newfs_data.newfs_custom.command, val, NEWFS_CMD_ARGS_MAX);
- }
-}
-
-static void
-getNewfsOptionalArguments(PartInfo *p)
-{
- char buffer[NEWFS_CMD_ARGS_MAX];
- char *val;
-
- /* Must be UFS, per argument checking in I/O routines. */
-
- strlcpy(buffer, p->newfs_data.newfs_ufs.user_options,
- NEWFS_CMD_ARGS_MAX);
- val = msgGetInput(buffer,
- "Please enter any additional UFS newfs options you'd like to\n"
- "use in creating this file system.");
- if (val != NULL)
- strlcpy(p->newfs_data.newfs_ufs.user_options, val,
- NEWFS_CMD_ARGS_MAX);
-}
-
-#define MAX_MOUNT_NAME 9
-
-#define PART_PART_COL 0
-#define PART_MOUNT_COL 10
-#define PART_SIZE_COL (PART_MOUNT_COL + MAX_MOUNT_NAME + 3)
-#define PART_NEWFS_COL (PART_SIZE_COL + 8)
-#define PART_OFF 38
-
-#define TOTAL_AVAIL_LINES (10)
-#define PSLICE_SHOWABLE (4)
-
-
-/* stick this all up on the screen */
-static void
-print_label_chunks(void)
-{
- int i, j, spaces, srow, prow, pcol;
- int sz;
- char clrmsg[80];
- int ChunkPartStartRow;
- WINDOW *ChunkWin;
-
- /********************************************************/
- /*** These values are for controling screen resources ***/
- /*** Each label line holds up to 2 labels, so beware! ***/
- /*** strategy will be to try to always make sure the ***/
- /*** highlighted label is in the active display area. ***/
- /********************************************************/
- int pslice_max, label_max;
- int pslice_count, label_count, label_focus_found, pslice_focus_found;
-
- attrset(A_REVERSE);
- mvaddstr(0, 25, "FreeBSD Disklabel Editor");
- attrset(A_NORMAL);
-
- /*** Count the number of parition slices ***/
- pslice_count = 0;
- for (i = 0; label_chunk_info[i].c ; i++) {
- if (label_chunk_info[i].type == PART_SLICE)
- ++pslice_count;
- }
- pslice_max = pslice_count;
-
- /*** 4 line max for partition slices ***/
- if (pslice_max > PSLICE_SHOWABLE) {
- pslice_max = PSLICE_SHOWABLE;
- }
- ChunkPartStartRow = CHUNK_SLICE_START_ROW + 3 + pslice_max;
-
- /*** View partition slices modulo pslice_max ***/
- label_max = TOTAL_AVAIL_LINES - pslice_max;
-
- for (i = 0; i < 2; i++) {
- mvaddstr(ChunkPartStartRow - 2, PART_PART_COL + (i * PART_OFF), "Part");
- mvaddstr(ChunkPartStartRow - 1, PART_PART_COL + (i * PART_OFF), "----");
-
- mvaddstr(ChunkPartStartRow - 2, PART_MOUNT_COL + (i * PART_OFF), "Mount");
- mvaddstr(ChunkPartStartRow - 1, PART_MOUNT_COL + (i * PART_OFF), "-----");
-
- mvaddstr(ChunkPartStartRow - 2, PART_SIZE_COL + (i * PART_OFF) + 3, "Size");
- mvaddstr(ChunkPartStartRow - 1, PART_SIZE_COL + (i * PART_OFF) + 3, "----");
-
- mvaddstr(ChunkPartStartRow - 2, PART_NEWFS_COL + (i * PART_OFF), "Newfs");
- mvaddstr(ChunkPartStartRow - 1, PART_NEWFS_COL + (i * PART_OFF), "-----");
- }
- srow = CHUNK_SLICE_START_ROW;
- prow = 0;
- pcol = 0;
-
- /*** these variables indicate that the focused item is shown currently ***/
- label_focus_found = 0;
- pslice_focus_found = 0;
-
- label_count = 0;
- pslice_count = 0;
- mvprintw(CHUNK_SLICE_START_ROW - 1, 0, " ");
- mvprintw(CHUNK_SLICE_START_ROW + pslice_max, 0, " ");
-
- ChunkWin = newwin(CHUNK_ROW_MAX - ChunkPartStartRow, 76, ChunkPartStartRow, 0);
-
- wclear(ChunkWin);
- /*** wrefresh(ChunkWin); ***/
-
- for (i = 0; label_chunk_info[i].c; i++) {
- /* Is it a slice entry displayed at the top? */
- if (label_chunk_info[i].type == PART_SLICE) {
- /*** This causes the new pslice to replace the previous display ***/
- /*** focus must remain on the most recently active pslice ***/
- if (pslice_count == pslice_max) {
- if (pslice_focus_found) {
- /*** This is where we can mark the more following ***/
- attrset(A_BOLD);
- mvprintw(CHUNK_SLICE_START_ROW + pslice_max, 0, "***MORE***");
- attrset(A_NORMAL);
- continue;
- }
- else {
- /*** this is where we set the more previous ***/
- attrset(A_BOLD);
- mvprintw(CHUNK_SLICE_START_ROW - 1, 0, "***MORE***");
- attrset(A_NORMAL);
- pslice_count = 0;
- srow = CHUNK_SLICE_START_ROW;
- }
- }
-
- sz = space_free(label_chunk_info[i].c);
- if (i == here)
- attrset(ATTR_SELECTED);
- if (i == pslice_focus)
- pslice_focus_found = -1;
-
- if (sz >= 100 * ONE_GIG)
- mvprintw(srow++, 0,
- "Disk: %s\tPartition name: %s\tFree: %d blocks (%dGB)",
- label_chunk_info[i].c->disk->name,
- label_chunk_info[i].c->name,
- sz, (sz / ONE_GIG));
- else
- mvprintw(srow++, 0,
- "Disk: %s\tPartition name: %s\tFree: %d blocks (%dMB)",
- label_chunk_info[i].c->disk->name,
- label_chunk_info[i].c->name,
- sz, (sz / ONE_MEG));
- attrset(A_NORMAL);
- clrtoeol();
- move(0, 0);
- /*** refresh(); ***/
- ++pslice_count;
- }
- /* Otherwise it's a DOS, swap or filesystem entry in the Chunk window */
- else {
- char onestr[PART_OFF], num[10], *mountpoint, newfs[12];
-
- /*
- * We copy this into a blank-padded string so that it looks like
- * a solid bar in reverse-video
- */
- memset(onestr, ' ', PART_OFF - 1);
- onestr[PART_OFF - 1] = '\0';
-
- /*** Track how many labels have been displayed ***/
- if (label_count == ((label_max - 1 ) * 2)) {
- if (label_focus_found) {
- continue;
- }
- else {
- label_count = 0;
- prow = 0;
- pcol = 0;
- }
- }
-
- /* Go for two columns if we've written one full columns worth */
- /*** if (prow == (CHUNK_ROW_MAX - ChunkPartStartRow)) ***/
- if (label_count == label_max - 1) {
- pcol = PART_OFF;
- prow = 0;
- }
- memcpy(onestr + PART_PART_COL, label_chunk_info[i].c->name, strlen(label_chunk_info[i].c->name));
- /* If it's a filesystem, display the mountpoint */
- if (label_chunk_info[i].c->private_data
- && (label_chunk_info[i].type == PART_FILESYSTEM || label_chunk_info[i].type == PART_FAT))
- mountpoint = ((PartInfo *)label_chunk_info[i].c->private_data)->mountpoint;
- else if (label_chunk_info[i].type == PART_SWAP)
- mountpoint = "swap";
- else
- mountpoint = "<none>";
-
- /* Now display the newfs field */
- if (label_chunk_info[i].type == PART_FAT) {
- strcpy(newfs, "DOS");
-#if defined(__ia64__)
- if (label_chunk_info[i].c->private_data &&
- label_chunk_info[i].c->type == efi) {
- strcat(newfs, " ");
- PartInfo *pi = (PartInfo *)label_chunk_info[i].c->private_data;
- strcat(newfs, pi->do_newfs ? " Y" : " N");
- }
-#endif
- }
- else if (label_chunk_info[i].c->private_data && label_chunk_info[i].type == PART_FILESYSTEM) {
- PartInfo *pi = (PartInfo *)label_chunk_info[i].c->private_data;
-
- switch (pi->newfs_type) {
- case NEWFS_UFS:
- strcpy(newfs, NEWFS_UFS_STRING);
- if (pi->newfs_data.newfs_ufs.ufs1)
- strcat(newfs, "1");
- else
- strcat(newfs, "2");
- if (pi->newfs_data.newfs_ufs.softupdates)
- strcat(newfs, "+S");
- else
- strcat(newfs, " ");
-
- break;
- case NEWFS_MSDOS:
- strcpy(newfs, "FAT");
- break;
- case NEWFS_CUSTOM:
- strcpy(newfs, "CUST");
- break;
- }
- strcat(newfs, pi->do_newfs ? " Y" : " N ");
- }
- else if (label_chunk_info[i].type == PART_SWAP)
- strcpy(newfs, "SWAP");
- else
- strcpy(newfs, "*");
- for (j = 0; j < MAX_MOUNT_NAME && mountpoint[j]; j++)
- onestr[PART_MOUNT_COL + j] = mountpoint[j];
- if (label_chunk_info[i].c->size == 0)
- snprintf(num, 10, "%5ldMB", 0);
- else if (label_chunk_info[i].c->size < (100 * ONE_GIG))
- snprintf(num, 10, "%5ldMB",
- label_chunk_info[i].c->size / ONE_MEG);
- else
- snprintf(num, 10, "%5ldGB",
- label_chunk_info[i].c->size / ONE_GIG);
- memcpy(onestr + PART_SIZE_COL, num, strlen(num));
- memcpy(onestr + PART_NEWFS_COL, newfs, strlen(newfs));
- onestr[PART_NEWFS_COL + strlen(newfs)] = '\0';
- if (i == label_focus) {
- label_focus_found = -1;
- wattrset(ChunkWin, A_BOLD);
- }
- if (i == here)
- wattrset(ChunkWin, ATTR_SELECTED);
-
- /*** lazy man's way of expensively padding this string ***/
- while (strlen(onestr) < 37)
- strcat(onestr, " ");
-
- mvwaddstr(ChunkWin, prow, pcol, onestr);
- wattrset(ChunkWin, A_NORMAL);
- move(0, 0);
- ++prow;
- ++label_count;
- }
- }
-
- /*** this will erase all the extra stuff ***/
- memset(clrmsg, ' ', 37);
- clrmsg[37] = '\0';
-
- while (pslice_count < pslice_max) {
- mvprintw(srow++, 0, clrmsg);
- clrtoeol();
- ++pslice_count;
- }
- while (label_count < (2 * (label_max - 1))) {
- mvwaddstr(ChunkWin, prow++, pcol, clrmsg);
- ++label_count;
- if (prow == (label_max - 1)) {
- prow = 0;
- pcol = PART_OFF;
- }
- }
- refresh();
- wrefresh(ChunkWin);
-}
-
-static void
-print_command_summary(void)
-{
- mvprintw(17, 0, "The following commands are valid here (upper or lower case):");
- mvprintw(18, 0, "C = Create D = Delete M = Mount pt.");
- if (!RunningAsInit)
- mvprintw(18, 56, "W = Write");
- mvprintw(19, 0, "N = Newfs Opts Q = Finish S = Toggle SoftUpdates Z = Custom Newfs");
- mvprintw(20, 0, "T = Toggle Newfs U = Undo A = Auto Defaults R = Delete+Merge");
- mvprintw(22, 0, "Use F1 or ? to get more help, arrow keys to select.");
- move(0, 0);
-}
-
-static void
-clear_wins(void)
-{
- extern void print_label_chunks();
- clear();
- print_label_chunks();
-}
-
-static int
-diskLabel(Device *dev)
-{
- int sz, key = 0;
- Boolean labeling;
- char *msg = NULL;
- PartInfo *p, *oldp;
- PartType type;
- Device **devs;
- WINDOW *w = savescr();
-
- label_focus = 0;
- pslice_focus = 0;
- here = 0;
-
- devs = deviceFind(NULL, DEVICE_TYPE_DISK);
- if (!devs) {
- msgConfirm("No disks found!");
- restorescr(w);
- return DITEM_FAILURE;
- }
- labeling = TRUE;
- keypad(stdscr, TRUE);
- record_label_chunks(devs, dev);
-
- clear();
- while (labeling) {
- char *cp;
- int rflags = DELCHUNK_NORMAL;
-
- print_label_chunks();
- print_command_summary();
- if (msg) {
- attrset(title_attr); mvprintw(23, 0, msg); attrset(A_NORMAL);
- clrtoeol();
- beep();
- msg = NULL;
- }
- else {
- move(23, 0);
- clrtoeol();
- }
-
- refresh();
- key = getch();
- switch (toupper(key)) {
- int i;
- static char _msg[40];
-
- case '\014': /* ^L */
- clear_wins();
- break;
-
- case '\020': /* ^P */
- case KEY_UP:
- case '-':
- if (here != 0)
- --here;
- else
- while (label_chunk_info[here + 1].c)
- ++here;
- break;
-
- case '\016': /* ^N */
- case KEY_DOWN:
- case '+':
- case '\r':
- case '\n':
- if (label_chunk_info[here + 1].c)
- ++here;
- else
- here = 0;
- break;
-
- case KEY_HOME:
- here = 0;
- break;
-
- case KEY_END:
- while (label_chunk_info[here + 1].c)
- ++here;
- break;
-
- case KEY_F(1):
- case '?':
- systemDisplayHelp("partition");
- clear_wins();
- break;
-
- case '1':
- if (label_chunk_info[here].type == PART_FILESYSTEM) {
- PartInfo *pi =
- ((PartInfo *)label_chunk_info[here].c->private_data);
-
- if ((pi != NULL) &&
- (pi->newfs_type == NEWFS_UFS)) {
- pi->newfs_data.newfs_ufs.ufs1 = true;
- } else
- msg = MSG_NOT_APPLICABLE;
- } else
- msg = MSG_NOT_APPLICABLE;
- break;
- break;
-
- case '2':
- if (label_chunk_info[here].type == PART_FILESYSTEM) {
- PartInfo *pi =
- ((PartInfo *)label_chunk_info[here].c->private_data);
-
- if ((pi != NULL) &&
- (pi->newfs_type == NEWFS_UFS)) {
- pi->newfs_data.newfs_ufs.ufs1 = false;
- } else
- msg = MSG_NOT_APPLICABLE;
- } else
- msg = MSG_NOT_APPLICABLE;
- break;
- break;
-
- case 'A':
- if (label_chunk_info[here].type != PART_SLICE) {
- msg = "You can only do this in a disk slice (at top of screen)";
- break;
- }
- /*
- * Generate standard partitions automatically. If we do not
- * have sufficient space we attempt to scale-down the size
- * of the partitions within certain bounds.
- */
- {
- int perc;
- int req = 0;
-
- for (perc = 100; perc > 0; perc -= 5) {
- req = 0; /* reset for each loop */
- if ((msg = try_auto_label(devs, dev, perc, &req)) == NULL)
- break;
- }
- if (msg) {
- if (req) {
- msgConfirm(msg);
- clear_wins();
- msg = NULL;
- }
- }
- }
- break;
-
- case 'C':
- if (label_chunk_info[here].type != PART_SLICE) {
- msg = "You can only do this in a master partition (see top of screen)";
- break;
- }
- sz = space_free(label_chunk_info[here].c);
- if (sz <= FS_MIN_SIZE) {
- msg = "Not enough space to create an additional FreeBSD partition";
- break;
- }
- else {
- char *val;
- int size;
- struct chunk *tmp;
- char osize[80];
- u_long flags = 0;
-
- sprintf(osize, "%d", sz);
- val = msgGetInput(osize,
- "Please specify the partition size in blocks or append a trailing G for\n"
- "gigabytes, M for megabytes, or C for cylinders.\n"
- "%d blocks (%dMB) are free.",
- sz, sz / ONE_MEG);
- if (!val || (size = strtol(val, &cp, 0)) <= 0) {
- clear_wins();
- break;
- }
-
- if (*cp) {
- if (toupper(*cp) == 'M')
- size *= ONE_MEG;
- else if (toupper(*cp) == 'G')
- size *= ONE_GIG;
- else if (toupper(*cp) == 'C')
- size *= (label_chunk_info[here].c->disk->bios_hd * label_chunk_info[here].c->disk->bios_sect);
- }
- if (size <= FS_MIN_SIZE) {
- msgConfirm("The minimum filesystem size is %dMB", FS_MIN_SIZE / ONE_MEG);
- clear_wins();
- break;
- }
- type = get_partition_type();
- if (type == PART_NONE) {
- clear_wins();
- beep();
- break;
- }
-
- if (type == PART_FILESYSTEM) {
- if ((p = get_mountpoint(NULL)) == NULL) {
- clear_wins();
- beep();
- break;
- }
- else if (!strcmp(p->mountpoint, "/"))
- flags |= CHUNK_IS_ROOT;
- else
- flags &= ~CHUNK_IS_ROOT;
- }
- else
- p = NULL;
-
- if ((flags & CHUNK_IS_ROOT) && (size < (ROOT_MIN_SIZE * ONE_MEG))) {
- msgConfirm("Warning: This is smaller than the recommended size for a\n"
- "root partition. For a variety of reasons, root\n"
- "partitions should usually be at least %dMB in size", ROOT_MIN_SIZE);
- }
- tmp = Create_Chunk_DWIM(label_chunk_info[here].c->disk,
- label_chunk_info[here].c,
- size, part,
- (type == PART_SWAP) ? FS_SWAP : FS_BSDFFS,
- flags);
- if (!tmp) {
- msgConfirm("Unable to create the partition. Too big?");
- clear_wins();
- break;
- }
-
-#ifdef __alpha__
- /*
- * SRM requires that the root partition is at the
- * begining of the disk and cannot boot otherwise.
- * Warn Alpha users if they are about to shoot themselves in
- * the foot in this way.
- *
- * Since partitions may not start precisely at offset 0 we
- * check for a "close to 0" instead. :-(
- */
- if ((flags & CHUNK_IS_ROOT) && (tmp->offset > 1024)) {
- msgConfirm("Your root partition `a' does not seem to be the first\n"
- "partition. The Alpha's firmware can only boot from the\n"
- "first partition. So it is unlikely that your current\n"
- "disk layout will be bootable boot after installation.\n"
- "\n"
- "Please allocate the root partition before allocating\n"
- "any others.\n");
- }
-#endif /* alpha */
-
- tmp->private_data = p;
- tmp->private_free = safe_free;
- if (variable_cmp(DISK_LABELLED, "written"))
- variable_set2(DISK_LABELLED, "yes", 0);
- record_label_chunks(devs, dev);
- clear_wins();
- /* This is where we assign focus to new label so it shows. */
- {
- int i;
- label_focus = -1;
- for (i = 0; label_chunk_info[i].c; ++i) {
- if (label_chunk_info[i].c == tmp) {
- label_focus = i;
- break;
- }
- }
- if (label_focus == -1)
- label_focus = i - 1;
- }
- }
- break;
-
- case KEY_DC:
- case 'R': /* recover space (delete w/ recover) */
- /*
- * Delete the partition w/ space recovery.
- */
- rflags = DELCHUNK_RECOVER;
- /* fall through */
- case 'D': /* delete */
- if (label_chunk_info[here].type == PART_SLICE) {
- msg = MSG_NOT_APPLICABLE;
- break;
- }
- else if (label_chunk_info[here].type == PART_FAT) {
- msg = "Use the Disk Partition Editor to delete DOS partitions";
- break;
- }
- Delete_Chunk2(label_chunk_info[here].c->disk, label_chunk_info[here].c, rflags);
- if (variable_cmp(DISK_LABELLED, "written"))
- variable_set2(DISK_LABELLED, "yes", 0);
- record_label_chunks(devs, dev);
- break;
-
- case 'M': /* mount */
- switch(label_chunk_info[here].type) {
- case PART_SLICE:
- msg = MSG_NOT_APPLICABLE;
- break;
-
- case PART_SWAP:
- msg = "You don't need to specify a mountpoint for a swap partition.";
- break;
-
- case PART_FAT:
- case PART_FILESYSTEM:
- oldp = label_chunk_info[here].c->private_data;
- p = get_mountpoint(label_chunk_info[here].c);
- if (p) {
- if (!oldp)
- p->do_newfs = FALSE;
- if (label_chunk_info[here].type == PART_FAT
- && (!strcmp(p->mountpoint, "/") || !strcmp(p->mountpoint, "/usr")
- || !strcmp(p->mountpoint, "/var"))) {
- msgConfirm("%s is an invalid mount point for a DOS partition!", p->mountpoint);
- strcpy(p->mountpoint, "/bogus");
- }
- }
- if (variable_cmp(DISK_LABELLED, "written"))
- variable_set2(DISK_LABELLED, "yes", 0);
- record_label_chunks(devs, dev);
- clear_wins();
- break;
-
- default:
- msgFatal("Bogus partition under cursor???");
- break;
- }
- break;
-
- case 'N': /* Set newfs options */
- if (label_chunk_info[here].c->private_data &&
- ((PartInfo *)label_chunk_info[here].c->private_data)->do_newfs)
- getNewfsOptionalArguments(
- label_chunk_info[here].c->private_data);
- else
- msg = MSG_NOT_APPLICABLE;
- clear_wins();
- break;
-
- case 'S': /* Toggle soft updates flag */
- if (label_chunk_info[here].type == PART_FILESYSTEM) {
- PartInfo *pi = ((PartInfo *)label_chunk_info[here].c->private_data);
- if (pi != NULL &&
- pi->newfs_type == NEWFS_UFS)
- pi->newfs_data.newfs_ufs.softupdates =
- !pi->newfs_data.newfs_ufs.softupdates;
- else
- msg = MSG_NOT_APPLICABLE;
- }
- else
- msg = MSG_NOT_APPLICABLE;
- break;
-
- case 'T': /* Toggle newfs state */
- if ((label_chunk_info[here].type == PART_FILESYSTEM) &&
- (label_chunk_info[here].c->private_data)) {
- PartInfo *pi = ((PartInfo *)label_chunk_info[here].c->private_data);
- if (!pi->do_newfs)
- label_chunk_info[here].c->flags |= CHUNK_NEWFS;
- else
- label_chunk_info[here].c->flags &= ~CHUNK_NEWFS;
-
- label_chunk_info[here].c->private_data =
- new_part(pi ? pi->mountpoint : NULL, pi ? !pi->do_newfs
- : TRUE);
- if (pi != NULL &&
- pi->newfs_type == NEWFS_UFS) {
- PartInfo *pi_new = label_chunk_info[here].c->private_data;
-
- pi_new->newfs_data.newfs_ufs = pi->newfs_data.newfs_ufs;
- }
- safe_free(pi);
- label_chunk_info[here].c->private_free = safe_free;
- if (variable_cmp(DISK_LABELLED, "written"))
- variable_set2(DISK_LABELLED, "yes", 0);
- }
-#if defined(__ia64__)
- else if (label_chunk_info[here].type == PART_FAT &&
- label_chunk_info[here].c->type == efi &&
- label_chunk_info[here].c->private_data) {
- PartInfo *pi =
- ((PartInfo *)label_chunk_info[here].c->private_data);
-
- if (!pi->do_newfs)
- label_chunk_info[here].c->flags |= CHUNK_NEWFS;
- else
- label_chunk_info[here].c->flags &= ~CHUNK_NEWFS;
-
- label_chunk_info[here].c->private_data =
- new_efi_part(pi->mountpoint, !pi->do_newfs);
- safe_free(pi);
- label_chunk_info[here].c->private_free = safe_free;
- if (variable_cmp(DISK_LABELLED, "written"))
- variable_set2(DISK_LABELLED, "yes", 0);
- }
-#endif
- else
- msg = MSG_NOT_APPLICABLE;
- break;
-
- case 'U':
- clear();
- if (!variable_cmp(DISK_LABELLED, "written")) {
- msgConfirm("You've already written out your changes -\n"
- "it's too late to undo!");
- }
- else if (!msgNoYes("Are you SURE you want to Undo everything?")) {
- variable_unset(DISK_PARTITIONED);
- variable_unset(DISK_LABELLED);
- for (i = 0; devs[i]; i++) {
- Disk *d;
-
- if (!devs[i]->enabled)
- continue;
- else if ((d = Open_Disk(devs[i]->name)) != NULL) {
- Free_Disk(devs[i]->private);
- devs[i]->private = d;
-#ifdef WITH_SLICES
- diskPartition(devs[i]);
-#endif
- }
- }
- record_label_chunks(devs, dev);
- }
- clear_wins();
- break;
-
- case 'W':
- if (!variable_cmp(DISK_LABELLED, "written")) {
- msgConfirm("You've already written out your changes - if you\n"
- "wish to overwrite them, you'll have to restart\n"
- "sysinstall first.");
- }
- else if (!msgNoYes("WARNING: This should only be used when modifying an EXISTING\n"
- "installation. If you are installing FreeBSD for the first time\n"
- "then you should simply type Q when you're finished here and your\n"
- "changes will be committed in one batch automatically at the end of\n"
- "these questions.\n\n"
- "Are you absolutely sure you want to do this now?")) {
- variable_set2(DISK_LABELLED, "yes", 0);
- diskLabelCommit(NULL);
- }
- clear_wins();
- break;
-
- case 'Z': /* Set newfs command line */
- if (label_chunk_info[here].c->private_data &&
- ((PartInfo *)label_chunk_info[here].c->private_data)->do_newfs)
- getNewfsCmd(label_chunk_info[here].c->private_data);
- else
- msg = MSG_NOT_APPLICABLE;
- clear_wins();
- break;
-
-
- case '|':
- if (!msgNoYes("Are you sure you want to go into Wizard mode?\n\n"
- "This is an entirely undocumented feature which you are not\n"
- "expected to understand!")) {
- int i;
- Device **devs;
-
- dialog_clear();
- end_dialog();
- DialogActive = FALSE;
- devs = deviceFind(NULL, DEVICE_TYPE_DISK);
- if (!devs) {
- msgConfirm("Can't find any disk devices!");
- break;
- }
- for (i = 0; devs[i] && ((Disk *)devs[i]->private); i++) {
- if (devs[i]->enabled)
- slice_wizard(((Disk *)devs[i]->private));
- }
- if (variable_cmp(DISK_LABELLED, "written"))
- variable_set2(DISK_LABELLED, "yes", 0);
- DialogActive = TRUE;
- record_label_chunks(devs, dev);
- clear_wins();
- }
- else
- msg = "A most prudent choice!";
- break;
-
- case '\033': /* ESC */
- case 'Q':
- labeling = FALSE;
- break;
-
- default:
- beep();
- sprintf(_msg, "Invalid key %d - Type F1 or ? for help", key);
- msg = _msg;
- break;
- }
- if (label_chunk_info[here].type == PART_SLICE)
- pslice_focus = here;
- else
- label_focus = here;
- }
- restorescr(w);
- return DITEM_SUCCESS;
-}
-
-static __inline int
-requested_part_size(char *varName, int nom, int def, int perc)
-{
- char *cp;
- int sz;
-
- if ((cp = variable_get(varName)) != NULL)
- sz = atoi(cp);
- else
- sz = nom + (def - nom) * perc / 100;
- return(sz * ONE_MEG);
-}
-
-/*
- * Attempt to auto-label the disk. 'perc' (0-100) scales
- * the size of the various partitions within appropriate
- * bounds (NOMINAL through DEFAULT sizes). The procedure
- * succeeds of NULL is returned. A non-null return message
- * is either a failure-status message (*req == 0), or
- * a confirmation requestor (*req == 1). *req is 0 on
- * entry to this call.
- *
- * We autolabel the following partitions: /, swap, /var, /tmp, /usr,
- * and /home. /home receives any extra left over disk space.
- */
-static char *
-try_auto_label(Device **devs, Device *dev, int perc, int *req)
-{
- int sz;
- struct chunk *root_chunk = NULL;
- struct chunk *swap_chunk = NULL;
- struct chunk *usr_chunk = NULL;
- struct chunk *var_chunk = NULL;
- struct chunk *tmp_chunk = NULL;
- struct chunk *home_chunk = NULL;
- int mib[2];
- unsigned long physmem;
- size_t size;
- Chunk *rootdev, *swapdev, *usrdev, *vardev;
- Chunk *tmpdev, *homedev;
- char *msg = NULL;
-
- sz = space_free(label_chunk_info[here].c);
- if (sz <= FS_MIN_SIZE)
- return("Not enough free space to create a new partition in the slice");
-
- (void)checkLabels(FALSE, &rootdev, &swapdev, &usrdev,
- &vardev, &tmpdev, &homedev);
- if (!rootdev) {
- sz = requested_part_size(VAR_ROOT_SIZE, ROOT_NOMINAL_SIZE, ROOT_DEFAULT_SIZE, perc);
-
- root_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk,
- label_chunk_info[here].c, sz, part,
- FS_BSDFFS, CHUNK_IS_ROOT | CHUNK_AUTO_SIZE);
- if (!root_chunk) {
- *req = 1;
- msg = "Unable to create the root partition. Too big?";
- goto done;
- }
- root_chunk->private_data = new_part("/", TRUE);
- root_chunk->private_free = safe_free;
- root_chunk->flags |= CHUNK_NEWFS;
- record_label_chunks(devs, dev);
- }
- if (!swapdev) {
- sz = requested_part_size(VAR_SWAP_SIZE, 0, 0, perc);
- if (sz == 0) {
- int nom;
- int def;
-
- mib[0] = CTL_HW;
- mib[1] = HW_PHYSMEM;
- size = sizeof physmem;
- sysctl(mib, 2, &physmem, &size, (void *)0, (size_t)0);
- def = 2 * (int)(physmem / 512);
- if (def < SWAP_MIN_SIZE * ONE_MEG)
- def = SWAP_MIN_SIZE * ONE_MEG;
- if (def > SWAP_AUTO_LIMIT_SIZE * ONE_MEG)
- def = SWAP_AUTO_LIMIT_SIZE * ONE_MEG;
- nom = (int)(physmem / 512) / 8;
- sz = nom + (def - nom) * perc / 100;
- }
- swap_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk,
- label_chunk_info[here].c, sz, part,
- FS_SWAP, CHUNK_AUTO_SIZE);
- if (!swap_chunk) {
- *req = 1;
- msg = "Unable to create the swap partition. Too big?";
- goto done;
- }
- swap_chunk->private_data = 0;
- swap_chunk->private_free = safe_free;
- record_label_chunks(devs, dev);
- }
- if (!vardev) {
- sz = requested_part_size(VAR_VAR_SIZE, VAR_NOMINAL_SIZE, VAR_DEFAULT_SIZE, perc);
-
- var_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk,
- label_chunk_info[here].c, sz, part,
- FS_BSDFFS, CHUNK_AUTO_SIZE);
- if (!var_chunk) {
- *req = 1;
- msg = "Not enough free space for /var - you will need to\n"
- "partition your disk manually with a custom install!";
- goto done;
- }
- var_chunk->private_data = new_part("/var", TRUE);
- var_chunk->private_free = safe_free;
- var_chunk->flags |= CHUNK_NEWFS;
- record_label_chunks(devs, dev);
- }
- if (!tmpdev && !variable_get(VAR_NO_TMP)) {
- sz = requested_part_size(VAR_TMP_SIZE, TMP_NOMINAL_SIZE, TMP_DEFAULT_SIZE, perc);
-
- tmp_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk,
- label_chunk_info[here].c, sz, part,
- FS_BSDFFS, CHUNK_AUTO_SIZE);
- if (!tmp_chunk) {
- *req = 1;
- msg = "Not enough free space for /tmp - you will need to\n"
- "partition your disk manually with a custom install!";
- goto done;
- }
- tmp_chunk->private_data = new_part("/tmp", TRUE);
- tmp_chunk->private_free = safe_free;
- tmp_chunk->flags |= CHUNK_NEWFS;
- record_label_chunks(devs, dev);
- }
- if (!usrdev && !variable_get(VAR_NO_USR)) {
- sz = requested_part_size(VAR_USR_SIZE, USR_NOMINAL_SIZE, USR_DEFAULT_SIZE, perc);
-#if AUTO_HOME == 0
- sz = space_free(label_chunk_info[here].c);
-#endif
- if (sz) {
- if (sz < (USR_MIN_SIZE * ONE_MEG)) {
- *req = 1;
- msg = "Not enough free space for /usr - you will need to\n"
- "partition your disk manually with a custom install!";
- }
-
- usr_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk,
- label_chunk_info[here].c, sz, part,
- FS_BSDFFS, CHUNK_AUTO_SIZE);
- if (!usr_chunk) {
- msg = "Unable to create the /usr partition. Not enough space?\n"
- "You will need to partition your disk manually with a custom install!";
- goto done;
- }
- usr_chunk->private_data = new_part("/usr", TRUE);
- usr_chunk->private_free = safe_free;
- usr_chunk->flags |= CHUNK_NEWFS;
- record_label_chunks(devs, dev);
- }
- }
-#if AUTO_HOME == 1
- if (!homedev && !variable_get(VAR_NO_HOME)) {
- sz = requested_part_size(VAR_HOME_SIZE, HOME_NOMINAL_SIZE, HOME_DEFAULT_SIZE, perc);
- if (sz < space_free(label_chunk_info[here].c))
- sz = space_free(label_chunk_info[here].c);
- if (sz) {
- if (sz < (HOME_MIN_SIZE * ONE_MEG)) {
- *req = 1;
- msg = "Not enough free space for /home - you will need to\n"
- "partition your disk manually with a custom install!";
- goto done;
- }
-
- home_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk,
- label_chunk_info[here].c, sz, part,
- FS_BSDFFS, CHUNK_AUTO_SIZE);
- if (!home_chunk) {
- msg = "Unable to create the /home partition. Not enough space?\n"
- "You will need to partition your disk manually with a custom install!";
- goto done;
- }
- home_chunk->private_data = new_part("/home", TRUE);
- home_chunk->private_free = safe_free;
- home_chunk->flags |= CHUNK_NEWFS;
- record_label_chunks(devs, dev);
- }
- }
-#endif
-
- /* At this point, we're reasonably "labelled" */
- if (variable_cmp(DISK_LABELLED, "written"))
- variable_set2(DISK_LABELLED, "yes", 0);
-
-done:
- if (msg) {
- if (root_chunk)
- Delete_Chunk(root_chunk->disk, root_chunk);
- if (swap_chunk)
- Delete_Chunk(swap_chunk->disk, swap_chunk);
- if (var_chunk)
- Delete_Chunk(var_chunk->disk, var_chunk);
- if (tmp_chunk)
- Delete_Chunk(tmp_chunk->disk, tmp_chunk);
- if (usr_chunk)
- Delete_Chunk(usr_chunk->disk, usr_chunk);
- if (home_chunk)
- Delete_Chunk(home_chunk->disk, home_chunk);
- record_label_chunks(devs, dev);
- }
- return(msg);
-}
-
-static int
-diskLabelNonInteractive(Device *dev)
-{
- char *cp;
- PartType type;
- PartInfo *p;
- u_long flags;
- int i, status;
- Device **devs;
- Disk *d;
-
- status = DITEM_SUCCESS;
- cp = variable_get(VAR_DISK);
- if (!cp) {
- msgConfirm("diskLabel: No disk selected - can't label automatically.");
- return DITEM_FAILURE;
- }
- devs = deviceFind(cp, DEVICE_TYPE_DISK);
- if (!devs) {
- msgConfirm("diskLabel: No disk device %s found!", cp);
- return DITEM_FAILURE;
- }
- if (dev)
- d = dev->private;
- else
- d = devs[0]->private;
- record_label_chunks(devs, dev);
- for (i = 0; label_chunk_info[i].c; i++) {
- Chunk *c1 = label_chunk_info[i].c;
-
- if (label_chunk_info[i].type == PART_SLICE) {
- char name[512];
- char typ[10], mpoint[50];
- int entries;
-
- for (entries = 1;; entries++) {
- int sz, soft = 0;
- snprintf(name, sizeof name, "%s-%d", c1->name, entries);
- if ((cp = variable_get(name)) == NULL)
- break;
- if (sscanf(cp, "%s %d %s %d", typ, &sz, mpoint, &soft) < 3) {
- msgConfirm("For slice entry %s, got an invalid detail entry of: %s", c1->name, cp);
- status = DITEM_FAILURE;
- break;
- } else {
- Chunk *tmp;
-
- flags = 0;
- if (!strcmp(typ, "swap")) {
- type = PART_SWAP;
- strcpy(mpoint, "SWAP");
- } else {
- type = PART_FILESYSTEM;
- if (!strcmp(mpoint, "/"))
- flags |= CHUNK_IS_ROOT;
- }
- if (!sz)
- sz = space_free(c1);
- if (sz > space_free(c1)) {
- msgConfirm("Not enough free space to create partition: %s", mpoint);
- status = DITEM_FAILURE;
- break;
- }
- if (!(tmp = Create_Chunk_DWIM(d, c1, sz, part,
- (type == PART_SWAP) ? FS_SWAP : FS_BSDFFS, flags))) {
- msgConfirm("Unable to create from partition spec: %s. Too big?", cp);
- status = DITEM_FAILURE;
- break;
- } else {
- PartInfo *pi;
- pi = tmp->private_data = new_part(mpoint, TRUE);
- tmp->private_free = safe_free;
- pi->newfs_data.newfs_ufs.softupdates = soft;
- }
- }
- }
- } else {
- /* Must be something we can set a mountpoint for */
- cp = variable_get(c1->name);
- if (cp) {
- char mpoint[50], do_newfs[8];
- Boolean newfs = FALSE;
-
- do_newfs[0] = '\0';
- if (sscanf(cp, "%s %s", mpoint, do_newfs) != 2) {
- msgConfirm("For slice entry %s, got an invalid detail entry of: %s", c1->name, cp);
- status = DITEM_FAILURE;
- break;
- }
- newfs = toupper(do_newfs[0]) == 'Y' ? TRUE : FALSE;
- if (c1->private_data) {
- p = c1->private_data;
- p->do_newfs = newfs;
- strcpy(p->mountpoint, mpoint);
- }
- else {
- c1->private_data = new_part(mpoint, newfs);
- c1->private_free = safe_free;
- }
- if (!strcmp(mpoint, "/"))
- c1->flags |= CHUNK_IS_ROOT;
- else
- c1->flags &= ~CHUNK_IS_ROOT;
- }
- }
- }
- if (status == DITEM_SUCCESS)
- variable_set2(DISK_LABELLED, "yes", 0);
- return status;
-}
diff --git a/usr.sbin/sade/list.h b/usr.sbin/sade/list.h
deleted file mode 100644
index 8300173e0660..000000000000
--- a/usr.sbin/sade/list.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last attempt in the `sysinstall' line, the next
- * generation being slated for what's essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1997 FreeBSD, 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 PAUL TRAINA ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL PAUL TRAINA OR HIS KILLER RATS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-/* The structure */
-typedef struct _qelement {
- struct _qelement *q_forw;
- struct _qelement *q_back;
-} qelement;
-
-#define INITQUE(Xhead) { \
- (Xhead).q_forw = &(Xhead); \
- (Xhead).q_back = &(Xhead); \
-}
-
-#define EMPTYQUE(Xhead) \
- ((Xhead).q_forw == &(Xhead))
-
-#define INSQUEUE(elem, pred) { \
- register qelement *Xe = (qelement *) (elem); \
- register qelement *Xp = (qelement *) (pred); \
- Xp->q_forw = (Xe->q_forw = (Xe->q_back = Xp)->q_forw)->q_back = Xe; \
-}
-
-#define REMQUE(elem) { \
- register qelement *Xe = (qelement *) (elem); \
- (Xe->q_back->q_forw = Xe->q_forw)->q_back = Xe->q_back; \
-}
diff --git a/usr.sbin/sade/main.c b/usr.sbin/sade/main.c
deleted file mode 100644
index 3b1df90d90c2..000000000000
--- a/usr.sbin/sade/main.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last attempt in the `sysinstall' line, the next
- * generation being slated for what's essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-#include <sys/signal.h>
-#include <sys/fcntl.h>
-
-const char *StartName; /* Initial contents of argv[0] */
-
-static void
-screech(int sig)
-{
- msgDebug("\007Signal %d caught! That's bad!\n", sig);
- longjmp(BailOut, sig);
-}
-
-int
-main(int argc, char **argv)
-{
- int choice, scroll, curr, max, status;
-
- /* Record name to be able to restart */
- StartName = argv[0];
-
- /* Catch fatal signals and complain about them if running as init */
- if (getpid() == 1) {
- signal(SIGBUS, screech);
- signal(SIGSEGV, screech);
- }
- signal(SIGPIPE, SIG_IGN);
-
- /* We don't work too well when running as non-root anymore */
- if (geteuid() != 0) {
- fprintf(stderr, "Error: This utility should only be run as root.\n");
- return 1;
- }
-
-#ifdef PC98
- {
- /* XXX */
- char *p = getenv("TERM");
- if (p && strcmp(p, "cons25") == 0)
- putenv("TERM=cons25w");
- }
-#endif
-
- /* Set up whatever things need setting up */
- systemInitialize(argc, argv);
-
- /* Set default flag and variable values */
- installVarDefaults(NULL);
- /* only when multi-user is it reasonable to do this here */
- if (!RunningAsInit)
- installEnvironment();
-
- if (argc > 1 && !strcmp(argv[1], "-fake")) {
- variable_set2(VAR_DEBUG, "YES", 0);
- Fake = TRUE;
- msgConfirm("I'll be just faking it from here on out, OK?");
- }
- if (argc > 1 && !strcmp(argv[1], "-restart"))
- Restarting = TRUE;
-
- /* Try to preserve our scroll-back buffer */
- if (OnVTY) {
- for (curr = 0; curr < 25; curr++)
- putchar('\n');
- }
- /* Move stderr aside */
- if (DebugFD)
- dup2(DebugFD, 2);
-
- /* Initialize driver modules, if we haven't already done so (ie,
- the user hit Ctrl-C -> Restart. */
- if (!pvariable_get("modulesInitialize")) {
- moduleInitialize();
- pvariable_set("modulesInitialize=1");
- }
-
- /* Initialize PC-card, if we haven't already done so. */
-#ifdef PCCARD_ARCH
- if (!pvariable_get("pccardInitialize")) {
- pccardInitialize();
- pvariable_set("pccardInitialize=1");
- }
-#endif
-
- /* Initialize USB, if we haven't already done so. */
- if (!pvariable_get("usbInitialize")) {
- usbInitialize();
- pvariable_set("usbInitialize=1");
- }
-
- /* Probe for all relevant devices on the system */
- deviceGetAll();
-
- /* Prompt for the driver floppy if appropriate. */
- if (!pvariable_get("driverFloppyCheck")) {
- driverFloppyCheck();
- pvariable_set("driverFloppyCheck=1");
- }
-
- /* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */
- if (!RunningAsInit) {
- int i, start_arg;
-
- if (!strstr(argv[0], "sysinstall"))
- start_arg = 0;
- else if (Fake || Restarting)
- start_arg = 2;
- else
- start_arg = 1;
- for (i = start_arg; i < argc; i++) {
- if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS)
- systemShutdown(1);
- }
- if (argc > start_arg)
- systemShutdown(0);
- }
- else
- dispatch_load_file_int(TRUE);
-
- status = setjmp(BailOut);
- if (status) {
- msgConfirm("A signal %d was caught - I'm saving what I can and shutting\n"
- "down. If you can reproduce the problem, please turn Debug on\n"
- "in the Options menu for the extra information it provides\n"
- "in debugging problems like this.", status);
- systemShutdown(status);
- }
-
- /* Begin user dialog at outer menu */
- dialog_clear();
- while (1) {
- choice = scroll = curr = max = 0;
- dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE);
- if (getpid() != 1
-#if defined(__alpha__) || defined(__sparc64__)
- || !msgNoYes("Are you sure you wish to exit? The system will halt.")
-#else
- || !msgNoYes("Are you sure you wish to exit? The system will reboot\n"
- "(be sure to remove any floppies/CDs/DVDs from the drives).")
-#endif
- )
- break;
- }
-
- /* Say goodnight, Gracie */
- systemShutdown(0);
-
- return 0; /* We should never get here */
-}
diff --git a/usr.sbin/sade/menus.c b/usr.sbin/sade/menus.c
deleted file mode 100644
index 183f1a7c062b..000000000000
--- a/usr.sbin/sade/menus.c
+++ /dev/null
@@ -1,2422 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last program in the `sysinstall' line - the next
- * generation being essentially a complete rewrite.
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif
-
-#include "sysinstall.h"
-
-/* Miscellaneous work routines for menus */
-static int
-setSrc(dialogMenuItem *self)
-{
- Dists |= DIST_SRC;
- SrcDists = DIST_SRC_ALL;
- CRYPTODists |= (DIST_CRYPTO_SCRYPTO | DIST_CRYPTO_SSECURE |
- DIST_CRYPTO_SKERBEROS5);
- return DITEM_SUCCESS | DITEM_REDRAW;
-}
-
-static int
-clearSrc(dialogMenuItem *self)
-{
- Dists &= ~DIST_SRC;
- SrcDists = 0;
- CRYPTODists &= ~(DIST_CRYPTO_SCRYPTO | DIST_CRYPTO_SSECURE |
- DIST_CRYPTO_SKERBEROS5);
- return DITEM_SUCCESS | DITEM_REDRAW;
-}
-
-static int
-setX11Misc(dialogMenuItem *self)
-{
- XF86Dists |= DIST_XF86_MISC_ALL;
- Dists |= DIST_XF86;
- return DITEM_SUCCESS | DITEM_REDRAW;
-}
-
-static int
-clearX11Misc(dialogMenuItem *self)
-{
- XF86Dists &= ~DIST_XF86_MISC_ALL;
- if (!XF86ServerDists && !XF86FontDists)
- Dists &= ~DIST_XF86;
- return DITEM_SUCCESS | DITEM_REDRAW;
-}
-
-static int
-setX11Servers(dialogMenuItem *self)
-{
- XF86Dists |= DIST_XF86_SERVER;
- XF86ServerDists = DIST_XF86_SERVER_ALL;
- return DITEM_SUCCESS | DITEM_REDRAW;
-}
-
-static int
-clearX11Servers(dialogMenuItem *self)
-{
- XF86Dists &= ~DIST_XF86_SERVER;
- XF86ServerDists = 0;
- return DITEM_SUCCESS | DITEM_REDRAW;
-}
-
-static int
-setX11Fonts(dialogMenuItem *self)
-{
- XF86Dists |= DIST_XF86_FONTS;
- XF86FontDists = DIST_XF86_FONTS_ALL;
- return DITEM_SUCCESS | DITEM_REDRAW;
-}
-
-static int
-clearX11Fonts(dialogMenuItem *self)
-{
- XF86Dists &= ~DIST_XF86_FONTS;
- XF86FontDists = 0;
- return DITEM_SUCCESS | DITEM_REDRAW;
-}
-
-#define _IS_SET(dist, set) (((dist) & (set)) == (set))
-
-#define IS_DEVELOPER(dist, extra) (_IS_SET(dist, _DIST_DEVELOPER | extra) || \
- _IS_SET(dist, _DIST_DEVELOPER | extra))
-
-#define IS_USER(dist, extra) (_IS_SET(dist, _DIST_USER | extra) || \
- _IS_SET(dist, _DIST_USER | extra))
-
-static int
-checkDistDeveloper(dialogMenuItem *self)
-{
- return IS_DEVELOPER(Dists, 0) && _IS_SET(SrcDists, DIST_SRC_ALL);
-}
-
-static int
-checkDistXDeveloper(dialogMenuItem *self)
-{
- return IS_DEVELOPER(Dists, DIST_XF86) && _IS_SET(SrcDists, DIST_SRC_ALL);
-}
-
-static int
-checkDistKernDeveloper(dialogMenuItem *self)
-{
- return IS_DEVELOPER(Dists, 0) && _IS_SET(SrcDists, DIST_SRC_SYS);
-}
-
-static int
-checkDistXKernDeveloper(dialogMenuItem *self)
-{
- return IS_DEVELOPER(Dists, DIST_XF86) && _IS_SET(SrcDists, DIST_SRC_SYS);
-}
-
-static int
-checkDistUser(dialogMenuItem *self)
-{
- return IS_USER(Dists, 0);
-}
-
-static int
-checkDistXUser(dialogMenuItem *self)
-{
- return IS_USER(Dists, DIST_XF86);
-}
-
-static int
-checkDistMinimum(dialogMenuItem *self)
-{
- return Dists == (DIST_BASE | DIST_CRYPTO);
-}
-
-static int
-checkDistEverything(dialogMenuItem *self)
-{
- return Dists == DIST_ALL && CRYPTODists == DIST_CRYPTO_ALL &&
- _IS_SET(SrcDists, DIST_SRC_ALL) &&
- _IS_SET(XF86Dists, DIST_XF86_ALL) &&
- _IS_SET(XF86ServerDists, DIST_XF86_SERVER_ALL) &&
- _IS_SET(XF86FontDists, DIST_XF86_FONTS_ALL);
-}
-
-static int
-srcFlagCheck(dialogMenuItem *item)
-{
- return SrcDists;
-}
-
-static int
-x11FlagCheck(dialogMenuItem *item)
-{
- return Dists & DIST_XF86;
-}
-
-static int
-checkTrue(dialogMenuItem *item)
-{
- return TRUE;
-}
-
-/* All the system menus go here.
- *
- * Hardcoded things like version number strings will disappear from
- * these menus just as soon as I add the code for doing inline variable
- * expansion.
- */
-
-DMenu MenuIndex = {
- DMENU_NORMAL_TYPE,
- "Glossary of functions",
- "This menu contains an alphabetized index of the top level functions in\n"
- "this program (sysinstall). Invoke an option by pressing [SPACE] or\n"
- "[ENTER]. To exit, use [TAB] to move to the Cancel button.",
- "Use PageUp or PageDown to move through this menu faster!",
- NULL,
- { { " Anon FTP", "Configure anonymous FTP logins.", dmenuVarCheck, configAnonFTP, NULL, "anon_ftp" },
- { " Commit", "Commit any pending actions (dangerous!)", NULL, installCustomCommit },
-#ifdef WITH_SYSCONS
- { " Console settings", "Customize system console behavior.", NULL, dmenuSubmenu, NULL, &MenuSyscons },
-#endif
- { " Configure", "The system configuration menu.", NULL, dmenuSubmenu, NULL, &MenuConfigure },
- { " Defaults, Load", "Load default settings.", NULL, dispatch_load_floppy },
-#ifdef WITH_MICE
- { " Device, Mouse", "The mouse configuration menu.", NULL, dmenuSubmenu, NULL, &MenuMouse },
-#endif
- { " Disklabel", "The disk Label editor", NULL, diskLabelEditor },
- { " Dists, All", "Root of the distribution tree.", NULL, dmenuSubmenu, NULL, &MenuDistributions },
- { " Dists, Basic", "Basic FreeBSD distribution menu.", NULL, dmenuSubmenu, NULL, &MenuSubDistributions },
- { " Dists, Developer", "Select developer's distribution.", checkDistDeveloper, distSetDeveloper },
- { " Dists, Src", "Src distribution menu.", NULL, dmenuSubmenu, NULL, &MenuSrcDistributions },
- { " Dists, X Developer", "Select X developer's distribution.", checkDistXDeveloper, distSetXDeveloper },
- { " Dists, Kern Developer", "Select kernel developer's distribution.", checkDistKernDeveloper, distSetKernDeveloper },
- { " Dists, User", "Select average user distribution.", checkDistUser, distSetUser },
- { " Dists, X User", "Select average X user distribution.", checkDistXUser, distSetXUser },
- { " Distributions, Adding", "Installing additional distribution sets", NULL, distExtractAll },
- { " Distributions, XFree86","XFree86 distribution menu.", NULL, distSetXF86 },
- { " Documentation", "Installation instructions, README, etc.", NULL, dmenuSubmenu, NULL, &MenuDocumentation },
- { " Doc, README", "The distribution README file.", NULL, dmenuDisplayFile, NULL, "README" },
- { " Doc, Early Adopter's", "Early Adopter's Guide to FreeBSD 5.0.", NULL, dmenuDisplayFile, NULL, "EARLY" },
- { " Doc, Errata", "The distribution errata.", NULL, dmenuDisplayFile, NULL, "ERRATA" },
- { " Doc, Hardware", "The distribution hardware guide.", NULL, dmenuDisplayFile, NULL, "HARDWARE" },
- { " Doc, Install", "The distribution installation guide.", NULL, dmenuDisplayFile, NULL, "INSTALL" },
- { " Doc, Copyright", "The distribution copyright notices.", NULL, dmenuDisplayFile, NULL, "COPYRIGHT" },
- { " Doc, Release", "The distribution release notes.", NULL, dmenuDisplayFile, NULL, "RELNOTES" },
- { " Doc, HTML", "The HTML documentation menu.", NULL, docBrowser },
- { " Dump Vars", "(debugging) dump out internal variables.", NULL, dump_variables },
- { " Emergency shell", "Start an Emergency Holographic shell.", NULL, installFixitHoloShell },
-#ifdef WITH_SLICES
- { " Fdisk", "The disk Partition Editor", NULL, diskPartitionEditor },
-#endif
- { " Fixit", "Repair mode with CDROM or fixit floppy.", NULL, dmenuSubmenu, NULL, &MenuFixit },
- { " FTP sites", "The FTP mirror site listing.", NULL, dmenuSubmenu, NULL, &MenuMediaFTP },
- { " Gateway", "Set flag to route packets between interfaces.", dmenuVarCheck, dmenuToggleVariable, NULL, "gateway=YES" },
- { " HTML Docs", "The HTML documentation menu", NULL, docBrowser },
- { " inetd Configuration", "Configure inetd and simple internet services.", dmenuVarCheck, configInetd, NULL, "inetd_enable=YES" },
- { " Install, Standard", "A standard system installation.", NULL, installStandard },
- { " Install, Express", "An express system installation.", NULL, installExpress },
- { " Install, Custom", "The custom installation menu", NULL, dmenuSubmenu, NULL, &MenuInstallCustom },
- { " Label", "The disk Label editor", NULL, diskLabelEditor },
- { " Media", "Top level media selection menu.", NULL, dmenuSubmenu, NULL, &MenuMedia },
- { " Media, Tape", "Select tape installation media.", NULL, mediaSetTape },
- { " Media, NFS", "Select NFS installation media.", NULL, mediaSetNFS },
- { " Media, Floppy", "Select floppy installation media.", NULL, mediaSetFloppy },
- { " Media, CDROM/DVD", "Select CDROM/DVD installation media.", NULL, mediaSetCDROM },
- { " Media, DOS", "Select DOS installation media.", NULL, mediaSetDOS },
- { " Media, UFS", "Select UFS installation media.", NULL, mediaSetUFS },
- { " Media, FTP", "Select FTP installation media.", NULL, mediaSetFTP },
- { " Media, FTP Passive", "Select passive FTP installation media.", NULL, mediaSetFTPPassive },
- { " Media, HTTP", "Select FTP via HTTP proxy installation media.", NULL, mediaSetHTTP },
- { " Network Interfaces", "Configure network interfaces", NULL, tcpMenuSelect },
- { " Networking Services", "The network services menu.", NULL, dmenuSubmenu, NULL, &MenuNetworking },
- { " NFS, client", "Set NFS client flag.", dmenuVarCheck, dmenuToggleVariable, NULL, "nfs_client_enable=YES" },
- { " NFS, server", "Set NFS server flag.", dmenuVarCheck, configNFSServer, NULL, "nfs_server_enable=YES" },
- { " NTP Menu", "The NTP configuration menu.", NULL, dmenuSubmenu, NULL, &MenuNTP },
- { " Options", "The options editor.", NULL, optionsEditor },
- { " Packages", "The packages collection", NULL, configPackages },
-#ifdef WITH_SLICES
- { " Partition", "The disk Slice (PC-style partition) Editor", NULL, diskPartitionEditor },
-#endif
- { " PCNFSD", "Run authentication server for PC-NFS.", dmenuVarCheck, configPCNFSD, NULL, "pcnfsd" },
- { " Root Password", "Set the system manager's password.", NULL, dmenuSystemCommand, NULL, "passwd root" },
- { " Router", "Select routing daemon (default: routed)", NULL, configRouter, NULL, "router_enable" },
- { " Security", "Configure system security options", NULL, dmenuSubmenu, NULL, &MenuSecurity },
-#ifdef WITH_SYSCONS
- { " Syscons", "The system console configuration menu.", NULL, dmenuSubmenu, NULL, &MenuSyscons },
-#ifndef PC98
- { " Syscons, Font", "The console screen font.", NULL, dmenuSubmenu, NULL, &MenuSysconsFont },
-#endif
- { " Syscons, Keymap", "The console keymap configuration menu.", NULL, dmenuSubmenu, NULL, &MenuSysconsKeymap },
- { " Syscons, Keyrate", "The console key rate configuration menu.", NULL, dmenuSubmenu, NULL, &MenuSysconsKeyrate },
- { " Syscons, Saver", "The console screen saver configuration menu.", NULL, dmenuSubmenu, NULL, &MenuSysconsSaver },
-#ifndef PC98
- { " Syscons, Screenmap", "The console screenmap configuration menu.", NULL, dmenuSubmenu, NULL, &MenuSysconsScrnmap },
- { " Syscons, Ttys", "The console terminal type menu.", NULL, dmenuSubmenu, NULL, &MenuSysconsTtys },
-#endif
-#endif /* WITH_SYSCONS */
- { " Time Zone", "Set the system's time zone.", NULL, dmenuSystemCommand, NULL, "tzsetup" },
- { " TTYs", "Configure system ttys.", NULL, configEtcTtys, NULL, "ttys" },
- { " Upgrade", "Upgrade an existing system.", NULL, installUpgrade },
- { " Usage", "Quick start - How to use this menu system.", NULL, dmenuDisplayFile, NULL, "usage" },
- { " User Management", "Add user and group information.", NULL, dmenuSubmenu, NULL, &MenuUsermgmt },
- { " XFree86, Fonts", "XFree86 Font selection menu.", NULL, dmenuSubmenu, NULL, &MenuXF86SelectFonts },
- { " XFree86, Server", "XFree86 Server selection menu.", NULL, dmenuSubmenu, NULL, &MenuXF86SelectServer },
-#if !defined(X_AS_PKG) && defined(__i386__) && defined(PC98)
- { " XFree86, PC98 Server", "XFree86 PC98 Server selection menu.", NULL, dmenuSubmenu, NULL, &MenuXF86SelectPC98Server },
-#endif
- { NULL } },
-};
-
-/* The initial installation menu */
-DMenu MenuInitial = {
- DMENU_NORMAL_TYPE,
- "sysinstall Main Menu", /* title */
- "Welcome to the FreeBSD installation and configuration tool. Please\n" /* prompt */
- "select one of the options below by using the arrow keys or typing the\n"
- "first character of the option name you're interested in. Invoke an\n"
- "option with [SPACE] or [ENTER]. To exit, use [TAB] to move to Exit.",
- "Press F1 for Installation Guide", /* help line */
- "INSTALL", /* help file */
- { { "Select" },
- { "X Exit Install", NULL, NULL, dmenuExit },
- { " Usage", "Quick start - How to use this menu system", NULL, dmenuDisplayFile, NULL, "usage" },
- { "Standard", "Begin a standard installation (recommended)", NULL, installStandard },
- { "Express", "Begin a quick installation (for experts)", NULL, installExpress },
- { " Custom", "Begin a custom installation (for experts)", NULL, dmenuSubmenu, NULL, &MenuInstallCustom },
- { "Configure", "Do post-install configuration of FreeBSD", NULL, dmenuSubmenu, NULL, &MenuConfigure },
- { "Doc", "Installation instructions, README, etc.", NULL, dmenuSubmenu, NULL, &MenuDocumentation },
-#ifdef WITH_SYSCONS
- { "Keymap", "Select keyboard type", NULL, dmenuSubmenu, NULL, &MenuSysconsKeymap },
-#endif
- { "Options", "View/Set various installation options", NULL, optionsEditor },
- { "Fixit", "Repair mode with CDROM/DVD/floppy or start shell", NULL, dmenuSubmenu, NULL, &MenuFixit },
- { "Upgrade", "Upgrade an existing system", NULL, installUpgrade },
- { "Load Config","Load default install configuration", NULL, dispatch_load_floppy },
- { "Index", "Glossary of functions", NULL, dmenuSubmenu, NULL, &MenuIndex },
- { NULL } },
-};
-
-/* The main documentation menu */
-DMenu MenuDocumentation = {
- DMENU_NORMAL_TYPE,
- "FreeBSD Documentation Menu",
- "If you are at all unsure about the configuration of your hardware\n"
- "or are looking to build a system specifically for FreeBSD, read the\n"
- "Hardware guide! New users should also read the Install document for\n"
- "a step-by-step tutorial on installing FreeBSD. For general information,\n"
- "consult the README file.",
- "Confused? Press F1 for help.",
- "usage",
- { { "X Exit", "Exit this menu (returning to previous)", NULL, dmenuExit },
- { "1 README", "A general description of FreeBSD. Read this!", NULL, dmenuDisplayFile, NULL, "README" },
- { "2 Early Adopter's", "Early Adopter's Guide to FreeBSD 5.0.", NULL, dmenuDisplayFile, NULL, "EARLY" },
- { "3 Errata", "Late-breaking, post-release news.", NULL, dmenuDisplayFile, NULL, "ERRATA" },
- { "4 Hardware", "The FreeBSD survival guide for PC hardware.", NULL, dmenuDisplayFile, NULL, "HARDWARE" },
- { "5 Install", "A step-by-step guide to installing FreeBSD.", NULL, dmenuDisplayFile, NULL, "INSTALL" },
- { "6 Copyright", "The FreeBSD Copyright notices.", NULL, dmenuDisplayFile, NULL, "COPYRIGHT" },
- { "7 Release" ,"The release notes for this version of FreeBSD.", NULL, dmenuDisplayFile, NULL, "RELNOTES" },
- { "8 Shortcuts", "Creating shortcuts to sysinstall.", NULL, dmenuDisplayFile, NULL, "shortcuts" },
- { "9 HTML Docs", "Go to the HTML documentation menu (post-install).", NULL, docBrowser },
- { NULL } },
-};
-
-#ifdef WITH_MICE
-DMenu MenuMouseType = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
-#ifdef PC98
- "Select a protocol type for your mouse",
- "If your mouse is attached to the bus mouse port, you should always choose\n"
- "\"Auto\", regardless of the model and the brand of the mouse. All other\n"
- "protocol types are for serial mice and should not be used with the bus\n"
- "mouse. If you have a serial mouse and are not sure about its protocol,\n"
- "you should also try \"Auto\". It may not work for the serial mouse if the\n"
- "mouse does not support the PnP standard. But, it won't hurt. Many\n"
- "2-button serial mice are compatible with \"Microsoft\" or \"MouseMan\".\n"
- "3-button serial mice may be compatible with \"MouseSystems\" or \"MouseMan\".\n"
- "If the serial mouse has a wheel, it may be compatible with \"IntelliMouse\".",
- NULL,
- NULL,
- { { "1 Auto", "Bus mouse or PnP serial mouse",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_TYPE "=auto" },
-#else
- "Select a protocol type for your mouse",
- "If your mouse is attached to the PS/2 mouse port or the bus mouse port,\n"
- "you should always choose \"Auto\", regardless of the model and the brand\n"
- "of the mouse. All other protocol types are for serial mice and should\n"
- "not be used with the PS/2 port mouse or the bus mouse. If you have\n"
- "a serial mouse and are not sure about its protocol, you should also try\n"
- "\"Auto\". It may not work for the serial mouse if the mouse does not\n"
- "support the PnP standard. But, it won't hurt. Many 2-button serial mice\n"
- "are compatible with \"Microsoft\" or \"MouseMan\". 3-button serial mice\n"
- "may be compatible with \"MouseSystems\" or \"MouseMan\". If the serial\n"
- "mouse has a wheel, it may be compatible with \"IntelliMouse\".",
- NULL,
- NULL,
- { { "1 Auto", "Bus mouse, PS/2 style mouse or PnP serial mouse",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_TYPE "=auto" },
-#endif /* PC98 */
- { "2 GlidePoint", "ALPS GlidePoint pad (serial)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_TYPE "=glidepoint" },
- { "3 Hitachi","Hitachi tablet (serial)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_TYPE "=mmhittab" },
- { "4 IntelliMouse", "Microsoft IntelliMouse (serial)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_TYPE "=intellimouse" },
- { "5 Logitech", "Logitech protocol (old models) (serial)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_TYPE "=logitech" },
- { "6 Microsoft", "Microsoft protocol (serial)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_TYPE "=microsoft" },
- { "7 MM Series","MM Series protocol (serial)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_TYPE "=mmseries" },
- { "8 MouseMan", "Logitech MouseMan/TrackMan models (serial)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_TYPE "=mouseman" },
- { "9 MouseSystems", "MouseSystems protocol (serial)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_TYPE "=mousesystems" },
- { "A ThinkingMouse","Kensington ThinkingMouse (serial)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_TYPE "=thinkingmouse" },
- { NULL } },
-};
-
-#ifdef PC98
-DMenu MenuMousePort = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Select your mouse port from the following menu",
- "The built-in pointing device of laptop/notebook computers is usually\n"
- "a BusMouse style device.",
- NULL,
- NULL,
- {
- { "1 BusMouse", "PC-98x1 bus mouse (/dev/mse0)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_PORT "=/dev/mse0" },
- { "2 COM1", "Serial mouse on COM1 (/dev/cuaa0)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_PORT "=/dev/cuaa0" },
- { "3 COM2", "Serial mouse on COM2 (/dev/cuaa1)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_PORT "=/dev/cuaa1" },
- { NULL } },
-};
-#else
-DMenu MenuMousePort = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Select your mouse port from the following menu",
- "The built-in pointing device of laptop/notebook computers is usually\n"
- "a PS/2 style device.",
- NULL,
- NULL,
- { { "1 PS/2", "PS/2 style mouse (/dev/psm0)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_PORT "=/dev/psm0" },
- { "2 COM1", "Serial mouse on COM1 (/dev/cuaa0)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_PORT "=/dev/cuaa0" },
- { "3 COM2", "Serial mouse on COM2 (/dev/cuaa1)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_PORT "=/dev/cuaa1" },
- { "4 COM3", "Serial mouse on COM3 (/dev/cuaa2)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_PORT "=/dev/cuaa2" },
- { "5 COM4", "Serial mouse on COM4 (/dev/cuaa3)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_PORT "=/dev/cuaa3" },
- { "6 BusMouse", "Logitech, ATI or MS bus mouse (/dev/mse0)",
- dmenuVarCheck, dmenuSetVariable, NULL, VAR_MOUSED_PORT "=/dev/mse0" },
- { NULL } },
-};
-#endif /* PC98 */
-
-DMenu MenuMouse = {
- DMENU_NORMAL_TYPE,
- "Please configure your mouse",
- "You can cut and paste text in the text console by running the mouse\n"
- "daemon. Specify a port and a protocol type of your mouse and enable\n"
- "the mouse daemon. If you don't want this feature, select 6 to disable\n"
- "the daemon.\n"
- "Once you've enabled the mouse daemon, you can specify \"/dev/sysmouse\"\n"
- "as your mouse device and \"SysMouse\" or \"MouseSystems\" as mouse\n"
- "protocol when running the X configuration utility (see Configuration\n"
- "menu).",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)", NULL, dmenuExit },
- { "2 Enable", "Test and run the mouse daemon", NULL, mousedTest, NULL, NULL },
- { "3 Type", "Select mouse protocol type", NULL, dmenuSubmenu, NULL, &MenuMouseType },
- { "4 Port", "Select mouse port", NULL, dmenuSubmenu, NULL, &MenuMousePort },
- { "5 Flags", "Set additional flags", dmenuVarCheck, setMouseFlags,
- NULL, VAR_MOUSED_FLAGS "=" },
- { "6 Disable", "Disable the mouse daemon", NULL, mousedDisable, NULL, NULL },
- { NULL } },
-};
-#endif /* WITH_MICE */
-
-DMenu MenuMediaCDROM = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Choose a CD/DVD type",
- "FreeBSD can be installed directly from a CD/DVD containing a valid\n"
- "FreeBSD distribution. If you are seeing this menu it is because\n"
- "more than one CD/DVD drive was found on your system. Please select one\n"
- "of the following CD/DVD drives as your installation drive.",
- "Press F1 to read the installation guide",
- "INSTALL",
- { { NULL } },
-};
-
-DMenu MenuMediaFloppy = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Choose a Floppy drive",
- "You have more than one floppy drive. Please choose which drive\n"
- "you would like to use.",
- NULL,
- NULL,
- { { NULL } },
-};
-
-DMenu MenuMediaDOS = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Choose a DOS partition",
- "FreeBSD can be installed directly from a DOS partition\n"
- "assuming, of course, that you have copied the relevant\n"
- "distributions into your DOS partition before starting this\n"
- "installation. If this is not the case then you should reboot\n"
- "DOS at this time and copy the distributions you wish to install\n"
- "into a \"FREEBSD\" subdirectory on one of your DOS partitions.\n"
- "Otherwise, please select the DOS partition containing the FreeBSD\n"
- "distribution files.",
- "Press F1 to read the installation guide",
- "INSTALL",
- { { NULL } },
-};
-
-DMenu MenuMediaFTP = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Please select a FreeBSD FTP distribution site",
- "Please select the site closest to you or \"other\" if you'd like to\n"
- "specify a different choice. Also note that not every site listed here\n"
- "carries more than the base distribution kits. Only the Primary site is\n"
- "guaranteed to carry the full range of possible distributions.",
- "Select a site that's close!",
- "INSTALL",
- { { "Primary Site", "ftp.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.freebsd.org" },
- { "URL", "Specify some other ftp site by URL", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=other" },
- { " 5.0 SNAP Server", "current.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://current.freebsd.org" },
- { " 4.x SNAP Server", "releng4.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://releng4.freebsd.org" },
- { " jp.FreeBSD.org SNAP Server", "snapshots.jp.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://snapshots.jp.freebsd.org" },
- { " IPv6 Ready", "ftp2.jp.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.jp.freebsd.org" },
- { " IPv6 Ready #2", "ftp7.jp.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp7.jp.freebsd.org" },
- { " IPv6 Ready #3", "ftp3.ie.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.ie.freebsd.org" },
- { "Argentina", "ftp.ar.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.ar.freebsd.org" },
- { "Australia", "ftp.au.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.au.freebsd.org" },
- { " Australia #2","ftp2.au.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.au.freebsd.org" },
- { " Australia #3","ftp3.au.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.au.freebsd.org" },
- { " Australia #4","ftp4.au.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.au.freebsd.org" },
- { " Australia #5","ftp5.au.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp5.au.freebsd.org" },
- { " Australia #6","ftp6.au.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp6.au.freebsd.org" },
- { "Austria", "ftp.at.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.at.freebsd.org" },
- { " Austria #2", "ftp2.at.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.at.freebsd.org" },
- { "Brazil", "ftp.br.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.br.freebsd.org" },
- { " Brazil #2", "ftp2.br.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.br.freebsd.org" },
- { " Brazil #3", "ftp3.br.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.br.freebsd.org" },
- { " Brazil #4", "ftp4.br.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.br.freebsd.org" },
- { " Brazil #5", "ftp5.br.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp5.br.freebsd.org" },
- { " Brazil #6", "ftp6.br.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp6.br.freebsd.org" },
- { " Brazil #7", "ftp7.br.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp7.br.freebsd.org" },
- /*
- { "Bulgaria", "ftp.bg.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.bg.freebsd.org" },
- */
- { "Canada", "ftp.ca.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.ca.freebsd.org" },
- /*
- { " Canada #2", "ftp2.ca.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.ca.freebsd.org" },
- */
- { "China", "ftp.cn.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.cn.freebsd.org" },
- { " China #2", "ftp2.cn.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.cn.freebsd.org" },
- { " China #3", "ftp3.cn.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.cn.freebsd.org" },
- { "Czech Republic", "ftp.cz.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.cz.freebsd.org" },
- { "Denmark (Primary)", "ftp.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.dk.freebsd.org" },
- { " Denmark", "ftp.dk.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.dk.freebsd.org" },
- { " Denmark #2", "ftp2.dk.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.dk.freebsd.org" },
- { " Denmark #3", "ftp3.dk.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.dk.freebsd.org" },
- { "Estonia", "ftp.ee.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.ee.freebsd.org" },
- { "Finland", "ftp.fi.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.fi.freebsd.org" },
- { " Finland #3", "ftp3.fi.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.fi.freebsd.org" },
- { "France", "ftp.fr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.fr.freebsd.org" },
- { " France #2", "ftp2.fr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.fr.freebsd.org" },
- { " France #3", "ftp3.fr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.fr.freebsd.org" },
- /*
- { " France #4", "ftp4.fr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.fr.freebsd.org" },
- */
- { " France #5", "ftp5.fr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp5.fr.freebsd.org" },
- { " France #6", "ftp6.fr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp6.fr.freebsd.org" },
- /*
- { " France #7", "ftp7.fr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp7.fr.freebsd.org" },
- */
- { " France #8", "ftp8.fr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp8.fr.freebsd.org" },
- { "Germany", "ftp.de.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.de.freebsd.org" },
- { " Germany #2", "ftp2.de.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.de.freebsd.org" },
- { " Germany #3", "ftp3.de.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.de.freebsd.org" },
- { " Germany #4", "ftp4.de.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.de.freebsd.org" },
- { " Germany #5", "ftp5.de.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp5.de.freebsd.org" },
- { " Germany #6", "ftp6.de.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp6.de.freebsd.org" },
- { " Germany #7", "ftp7.de.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp7.de.freebsd.org" },
- { "Greece", "ftp.gr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.gr.freebsd.org" },
- { " Greece #2", "ftp2.gr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.gr.freebsd.org" },
- { "Hong Kong", "ftp.hk.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.hk.freebsd.org" },
- { "Hungary", "ftp.hu.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.hu.freebsd.org" },
- /*
- { " Hungary #2", "ftp2.hu.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.hu.freebsd.org" },
- */
- { "Iceland", "ftp.is.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.is.freebsd.org" },
- { "Ireland", "ftp.ie.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.ie.freebsd.org" },
- { " Ireland #2", "ftp2.ie.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.ie.freebsd.org" },
- { " Ireland #3", "ftp3.ie.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.ie.freebsd.org" },
- { "Israel", "ftp.il.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.il.freebsd.org" },
- { " Israel #2", "ftp2.il.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.il.freebsd.org" },
- { "Italy", "ftp.it.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.it.freebsd.org" },
- { "Japan", "ftp.jp.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.jp.freebsd.org" },
- { " Japan #2", "ftp2.jp.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.jp.freebsd.org" },
- { " Japan #3", "ftp3.jp.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.jp.freebsd.org" },
- { " Japan #4", "ftp4.jp.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.jp.freebsd.org" },
- { " Japan #5", "ftp5.jp.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp5.jp.freebsd.org" },
- { " Japan #6", "ftp6.jp.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp6.jp.freebsd.org" },
- { " Japan #7", "ftp7.jp.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp7.jp.freebsd.org" },
- { "Korea", "ftp.kr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.kr.freebsd.org" },
- { " Korea #2", "ftp2.kr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.kr.freebsd.org" },
- { " Korea #3", "ftp3.kr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.kr.freebsd.org" },
- { " Korea #4", "ftp4.kr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.kr.freebsd.org" },
- { " Korea #5", "ftp5.kr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp5.kr.freebsd.org" },
- { " Korea #6", "ftp6.kr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp6.kr.freebsd.org" },
- { " Korea #7", "ftp7.kr.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp7.kr.freebsd.org" },
- { "Lithuania", "ftp.lt.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.lt.freebsd.org" },
- { "Netherlands", "ftp.nl.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.nl.freebsd.org" },
- { " Netherlands #2", "ftp2.nl.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.nl.freebsd.org" },
- { "New Zealand", "ftp.nz.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.nz.freebsd.org" },
- { "Norway", "ftp.no.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.no.freebsd.org" },
- { " Norway #3", "ftp3.no.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.no.freebsd.org" },
- { "Poland", "ftp.pl.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.pl.freebsd.org" },
- { " Poland #2", "ftp2.pl.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.pl.freebsd.org" },
- { " Poland #3", "ftp3.pl.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.pl.freebsd.org" },
- { "Portugal (N/A)", "ftp.pt.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.pt.freebsd.org" },
- { " Portugal #2", "ftp2.pt.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.pt.freebsd.org" },
- { " Portugal #3", "ftp3.pt.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.pt.freebsd.org" },
- { "Romania", "ftp.ro.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.ro.freebsd.org" },
- { "Russia", "ftp.ru.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.ru.freebsd.org" },
- { " Russia #2", "ftp2.ru.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.ru.freebsd.org" },
- { " Russia #3", "ftp3.ru.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.ru.freebsd.org" },
- { " Russia #4", "ftp4.ru.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.ru.freebsd.org" },
- { "Saudi Arabia", "ftp.isu.net.sa", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.isu.net.sa/pub/mirrors/ftp.freebsd.org/" },
- { "Singapore", "ftp.sg.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.sg.freebsd.org" },
- { "Slovak Republic", "ftp.sk.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.sk.freebsd.org" },
- { " Slovak Republic #2", "ftp2.sk.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.sk.freebsd.org" },
- { "Slovenia (N/A)", "ftp.si.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.si.freebsd.org" },
- { " Slovenia #2", "ftp2.si.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.si.freebsd.org" },
- { "South Africa", "ftp.za.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.za.freebsd.org" },
- { " South Africa #2", "ftp2.za.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.za.freebsd.org" },
- { " South Africa #3", "ftp3.za.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.za.freebsd.org" },
- { " South Africa #4", "ftp4.za.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.za.freebsd.org" },
- { "Spain", "ftp.es.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.es.freebsd.org" },
- { " Spain #2", "ftp2.es.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.es.freebsd.org" },
- { " Spain #3", "ftp3.es.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.es.freebsd.org" },
- { "Sweden", "ftp.se.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.se.freebsd.org" },
- { " Sweden #2", "ftp2.se.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.se.freebsd.org" },
- { " Sweden #3", "ftp3.se.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.se.freebsd.org" },
- /*
- { " Sweden #4", "ftp4.se.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.se.freebsd.org" },
- */
- { " Sweden #5", "ftp5.se.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp5.se.freebsd.org" },
- { "Switzerland", "ftp.ch.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.ch.freebsd.org" },
- { "Taiwan", "ftp.tw.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.tw.freebsd.org" },
- { " Taiwan #2", "ftp2.tw.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.tw.freebsd.org" },
- { " Taiwan #3", "ftp3.tw.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.tw.freebsd.org" },
- { " Taiwan #4", "ftp4.tw.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.tw.freebsd.org" },
- { " Taiwan #5", "ftp5.tw.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp5.tw.freebsd.org" },
- { " Taiwan #6", "ftp6.tw.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp6.tw.freebsd.org" },
- { " Taiwan #7", "ftp7.tw.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp7.tw.freebsd.org" },
- { " Taiwan #8", "ftp8.tw.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp8.tw.freebsd.org" },
- { " Taiwan #9", "ftp9.tw.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp9.tw.freebsd.org" },
- { "Thailand", "ftp.nectec.or.th", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.nectec.or.th/pub/mirrors/FreeBSD/" },
- { "UK", "ftp.uk.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.uk.freebsd.org" },
- { " UK #2", "ftp2.uk.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.uk.freebsd.org" },
- { " UK #3", "ftp3.uk.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.uk.freebsd.org" },
- { " UK #4", "ftp4.uk.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.uk.freebsd.org" },
- { " UK #5", "ftp5.uk.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp5.uk.freebsd.org" },
- { " UK #6", "ftp6.uk.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp6.uk.freebsd.org" },
- { "Ukraine", "ftp.ua.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp.ua.freebsd.org" },
- { " Ukraine #2", "ftp2.ua.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.ua.freebsd.org" },
- { " Ukraine #3", "ftp3.ua.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.ua.freebsd.org" },
- /*
- { " Ukraine #4", "ftp4.ua.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.ua.freebsd.org" },
- */
- { " Ukraine #5", "ftp5.ua.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp5.ua.freebsd.org" },
- { " USA #2", "ftp2.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp2.freebsd.org" },
- { " USA #3", "ftp3.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp3.freebsd.org" },
- { " USA #4", "ftp4.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp4.freebsd.org" },
- { " USA #5", "ftp5.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp5.freebsd.org" },
- { " USA #6", "ftp6.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp6.freebsd.org" },
- { " USA #7", "ftp7.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp7.freebsd.org" },
- { " USA #8", "ftp8.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp8.freebsd.org" },
- { " USA #9", "ftp9.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp9.freebsd.org" },
- { " USA #10", "ftp10.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp10.freebsd.org" },
- { " USA #11", "ftp11.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp11.freebsd.org" },
- { " USA #12", "ftp12.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp12.freebsd.org" },
- { " USA #13", "ftp13.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp13.freebsd.org" },
- { " USA #14", "ftp14.freebsd.org", NULL, dmenuSetVariable, NULL,
- VAR_FTP_PATH "=ftp://ftp14.freebsd.org" },
- { NULL } }
-};
-
-DMenu MenuMediaTape = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Choose a tape drive type",
- "FreeBSD can be installed from tape drive, though this installation\n"
- "method requires a certain amount of temporary storage in addition\n"
- "to the space required by the distribution itself (tape drives make\n"
- "poor random-access devices, so we extract _everything_ on the tape\n"
- "in one pass). If you have sufficient space for this, then you should\n"
- "select one of the following tape devices detected on your system.",
- "Press F1 to read the installation guide",
- "INSTALL",
- { { NULL } },
-};
-
-DMenu MenuNetworkDevice = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Network interface information required",
- "If you are using PPP over a serial device, as opposed to a direct\n"
- "ethernet connection, then you may first need to dial your Internet\n"
- "Service Provider using the ppp utility we provide for that purpose.\n"
- "If you're using SLIP over a serial device then the expectation is\n"
- "that you have a HARDWIRED connection.\n\n"
- "You can also install over a parallel port using a special \"laplink\"\n"
- "cable to another machine running a fairly recent (2.0R or later)\n"
- "version of FreeBSD.",
- "Press F1 to read network configuration manual",
- "network_device",
- { { NULL } },
-};
-
-/* Prototype KLD load menu */
-DMenu MenuKLD = {
- DMENU_NORMAL_TYPE,
- "KLD Menu",
- "Load a KLD from a floppy\n",
- NULL,
- NULL,
- { { NULL } },
-};
-
-/* The media selection menu */
-DMenu MenuMedia = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Choose Installation Media",
- "FreeBSD can be installed from a variety of different installation\n"
- "media, ranging from floppies to an Internet FTP server. If you're\n"
- "installing FreeBSD from a supported CD/DVD drive then this is generally\n"
- "the best media to use if you have no overriding reason for using other\n"
- "media.",
- "Press F1 for more information on the various media types",
- "media",
- { { "1 CD/DVD", "Install from a FreeBSD CD/DVD", NULL, mediaSetCDROM },
- { "2 FTP", "Install from an FTP server", NULL, mediaSetFTPActive },
- { "3 FTP Passive", "Install from an FTP server through a firewall", NULL, mediaSetFTPPassive },
- { "4 HTTP", "Install from an FTP server through a http proxy", NULL, mediaSetHTTP },
- { "5 DOS", "Install from a DOS partition", NULL, mediaSetDOS },
- { "6 NFS", "Install over NFS", NULL, mediaSetNFS },
- { "7 File System", "Install from an existing filesystem", NULL, mediaSetUFS },
- { "8 Floppy", "Install from a floppy disk set", NULL, mediaSetFloppy },
- { "9 Tape", "Install from SCSI or QIC tape", NULL, mediaSetTape },
- { "X Options", "Go to the Options screen", NULL, optionsEditor },
- { NULL } },
-};
-
-/* The distributions menu */
-DMenu MenuDistributions = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "Choose Distributions",
- "As a convenience, we provide several \"canned\" distribution sets.\n"
- "These select what we consider to be the most reasonable defaults for the\n"
- "type of system in question. If you would prefer to pick and choose the\n"
- "list of distributions yourself, simply select \"Custom\". You can also\n"
- "pick a canned distribution set and then fine-tune it with the Custom item.\n\n"
- "Choose an item by pressing [SPACE] or [ENTER]. When finished, choose the\n"
- "Exit item or move to the OK button with [TAB].",
- "Press F1 for more information on these options.",
- "distributions",
- { { "X Exit", "Exit this menu (returning to previous)",
- checkTrue, dmenuExit, NULL, NULL, '<', '<', '<' },
- { "All", "All system sources, binaries and X Window System",
- checkDistEverything, distSetEverything, NULL, NULL, ' ', ' ', ' ' },
- { "Reset", "Reset selected distribution list to nothing",
- NULL, distReset, NULL, NULL, ' ', ' ', ' ' },
- { "4 Developer", "Full sources, binaries and doc but no games",
- checkDistDeveloper, distSetDeveloper },
- { "5 X-Developer", "Same as above + X Window System",
- checkDistXDeveloper, distSetXDeveloper },
- { "6 Kern-Developer", "Full binaries and doc, kernel sources only",
- checkDistKernDeveloper, distSetKernDeveloper },
- { "7 X-Kern-Developer", "Same as above + X Window System",
- checkDistXKernDeveloper, distSetXKernDeveloper },
- { "8 User", "Average user - binaries and doc only",
- checkDistUser, distSetUser },
- { "9 X-User", "Same as above + X Window System",
- checkDistXUser, distSetXUser },
- { "A Minimal", "The smallest configuration possible",
- checkDistMinimum, distSetMinimum },
- { "B Custom", "Specify your own distribution set",
- NULL, dmenuSubmenu, NULL, &MenuSubDistributions, '>', '>', '>' },
- { NULL } },
-};
-
-DMenu MenuSubDistributions = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "Select the distributions you wish to install.",
- "Please check off the distributions you wish to install. At the\n"
- "very minimum, this should be \"base\".",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- checkTrue, dmenuExit, NULL, NULL, '<', '<', '<' },
- { "All", "All system sources, binaries and X Window System",
- NULL, distSetEverything, NULL, NULL, ' ', ' ', ' ' },
- { "Reset", "Reset all of the below",
- NULL, distReset, NULL, NULL, ' ', ' ', ' ' },
- { " base", "Binary base distribution (required)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_BASE },
-#ifdef __i386__
- { " compat1x", "FreeBSD 1.x binary compatibility",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_COMPAT1X },
- { " compat20", "FreeBSD 2.0 binary compatibility",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_COMPAT20 },
- { " compat21", "FreeBSD 2.1 binary compatibility",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_COMPAT21 },
- { " compat22", "FreeBSD 2.2.x and 3.0 a.out binary compatibility",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_COMPAT22 },
- { " compat3x", "FreeBSD 3.x binary compatibility",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_COMPAT3X },
-#endif
-#if __FreeBSD__ >= 4 && (defined(__i386__) || defined(__alpha__))
- { " compat4x", "FreeBSD 4.x binary compatibility",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_COMPAT4X },
-#endif
- { " crypto", "Basic encryption services",
- dmenuFlagCheck, dmenuSetFlag, NULL, &CRYPTODists, '[', 'X', ']', DIST_CRYPTO_CRYPTO, },
- { " dict", "Spelling checker dictionary files",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_DICT },
- { " doc", "Miscellaneous FreeBSD online docs",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_DOC },
- { " games", "Games (non-commercial)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_GAMES },
- { " info", "GNU info files",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_INFO },
- { " man", "System manual pages - recommended",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_MANPAGES },
- { " catman", "Preformatted system manual pages",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_CATPAGES },
- { " proflibs", "Profiled versions of the libraries",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_PROFLIBS },
- { " src", "Sources for everything",
- srcFlagCheck, distSetSrc },
- { " ports", "The FreeBSD Ports collection",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_PORTS },
- { " local", "Local additions collection",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_LOCAL},
- { " perl", "The Perl distribution",
- dmenuFlagCheck, dmenuSetFlag, NULL, &Dists, '[', 'X', ']', DIST_PERL },
- { " XFree86", "The XFree86 distribution",
- x11FlagCheck, distSetXF86 },
- { NULL } },
-};
-
-DMenu MenuSrcDistributions = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "Select the sub-components of src you wish to install.",
- "Please check off those portions of the FreeBSD source tree\n"
- "you wish to install.",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- checkTrue, dmenuExit, NULL, NULL, '<', '<', '<' },
- { "All", "Select all of the below",
- NULL, setSrc, NULL, NULL, ' ', ' ', ' ' },
- { "Reset", "Reset all of the below",
- NULL, clearSrc, NULL, NULL, ' ', ' ', ' ' },
- { " base", "top-level files in /usr/src",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_BASE },
- { " contrib", "/usr/src/contrib (contributed software)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_CONTRIB },
- { " gnu", "/usr/src/gnu (software from the GNU Project)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_GNU },
- { " etc", "/usr/src/etc (miscellaneous system files)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_ETC },
- { " games", "/usr/src/games (the obvious!)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_GAMES },
- { " include", "/usr/src/include (header files)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_INCLUDE },
- { " lib", "/usr/src/lib (system libraries)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_LIB },
- { " libexec", "/usr/src/libexec (system programs)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_LIBEXEC },
- { " release", "/usr/src/release (release-generation tools)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_RELEASE },
- { " bin", "/usr/src/bin (system binaries)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_BIN },
- { " sbin", "/usr/src/sbin (system binaries)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_SBIN },
- { " scrypto", "/usr/src/crypto (contrib encryption sources)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &CRYPTODists, '[', 'X', ']', DIST_CRYPTO_SCRYPTO },
- { " share", "/usr/src/share (documents and shared files)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_SHARE },
- { " skrb5", "/usr/src/kerberos5 (sources for Kerberos5)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &CRYPTODists, '[', 'X', ']', DIST_CRYPTO_SKERBEROS5 },
- { " ssecure", "/usr/src/secure (BSD encryption sources)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &CRYPTODists, '[', 'X', ']', DIST_CRYPTO_SSECURE },
- { " sys", "/usr/src/sys (FreeBSD kernel)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_SYS },
- { " tools", "/usr/src/tools (miscellaneous tools)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_TOOLS },
- { " ubin", "/usr/src/usr.bin (user binaries)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_UBIN },
- { " usbin", "/usr/src/usr.sbin (aux system binaries)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &SrcDists, '[', 'X', ']', DIST_SRC_USBIN },
- { NULL } },
-};
-
-DMenu MenuXF86Config = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Please select the XFree86 configuration tool you want to use.",
- "The first option, xf86cfg, is fully graphical.\n"
- "The second option provides a menu-based interface similar to\n"
- "what you are currently using. "
- "The third option, xf86config, is\n"
- "a more simplistic shell-script based tool and less friendly to\n"
- "new users, but it may work in situations where the other options\n"
- "do not.",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- NULL, dmenuExit },
- { "2 xf86cfg", "Fully graphical XFree86 configuration tool.",
- NULL, dmenuSetVariable, NULL, VAR_XF86_CONFIG "=xf86cfg" },
- { "3 xf86cfg -textmode", "ncurses-based XFree86 configuration tool.",
- NULL, dmenuSetVariable, NULL, VAR_XF86_CONFIG "=xf86cfg -textmode" },
- { "4 xf86config", "Shell-script based XFree86 configuration tool.",
- NULL, dmenuSetVariable, NULL, VAR_XF86_CONFIG "=xf86config" },
- { "D XDesktop", "X already set up, just do desktop configuration.",
- NULL, dmenuSubmenu, NULL, &MenuXDesktops },
- { NULL } },
-};
-
-DMenu MenuXDesktops = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Please select the default X desktop to use.",
- "By default, XFree86 comes with a fairly vanilla desktop which\n"
- "is based around the twm(1) window manager and does not offer\n"
- "much in the way of features. It does have the advantage of\n"
- "being a standard part of X so you don't need to load anything\n"
- "extra in order to use it. If, however, you have access to a\n"
- "reasonably full packages collection on your installation media,\n"
- "you can choose any one of the following desktops as alternatives.",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- NULL, dmenuExit },
- { "2 KDE", "The K Desktop Environment",
- NULL, dmenuSetVariable, NULL, VAR_DESKSTYLE "=kde" },
- { "3 GNOME 2", "The GNOME 2 Desktop Environment",
- NULL, dmenuSetVariable, NULL, VAR_DESKSTYLE "=gnome2" },
- { "4 Afterstep", "The Afterstep window manager",
- NULL, dmenuSetVariable, NULL, VAR_DESKSTYLE "=afterstep" },
- { "5 Windowmaker", "The Windowmaker window manager",
- NULL, dmenuSetVariable, NULL, VAR_DESKSTYLE "=windowmaker" },
- { "6 fvwm", "The fvwm window manager",
- NULL, dmenuSetVariable, NULL, VAR_DESKSTYLE "=fvwm2" },
- { NULL } },
-};
-
-DMenu MenuXF86Select = {
- DMENU_NORMAL_TYPE,
- "XFree86 Distribution",
- "Please select the components you need from the XFree86\n"
- "distribution sets.",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)", NULL, dmenuExit },
- { "Basic", "Basic component menu (required)", NULL, dmenuSubmenu, NULL, &MenuXF86SelectCore },
- { "Server", "X server menu", NULL, dmenuSubmenu, NULL, &MenuXF86SelectServer },
- { "Fonts", "Font set menu", NULL, dmenuSubmenu, NULL, &MenuXF86SelectFonts },
- { NULL } },
-};
-
-#ifdef X_AS_PKG
-DMenu MenuXF86SelectCore = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "XFree86 base distribution types",
- "Please check off the basic XFree86 components you wish to install.\n"
- "Bin, lib, and set are recommended for a minimum installaion.",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- checkTrue, dmenuExit, NULL, NULL, '<', '<', '<' },
- { "All", "Select all below",
- NULL, setX11Misc, NULL, NULL, ' ', ' ', ' ' },
- { "Reset", "Reset all below",
- NULL, clearX11Misc, NULL, NULL, ' ', ' ', ' ' },
- { " bin", "Client applications",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_CLIENTS },
- { " lib", "Shared libraries and data files needed at runtime",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_LIB },
- { " man", "Manual pages",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_MAN },
- { " doc", "Documentation",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_DOC },
- { " prog", "Programming tools",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_PROG },
- { NULL } },
-};
-
-DMenu MenuXF86SelectFonts = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "Font distribution selection.",
- "Please check off the individual font distributions you wish to\n\
-install. At the minimum, you should install the standard\n\
-75 DPI and misc fonts if you're also installing a server\n\
-(these are selected by default).",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- checkTrue, dmenuExit, NULL, NULL, '<', '<', '<' },
- { "All", "All fonts",
- NULL, setX11Fonts, NULL, NULL, ' ', ' ', ' ' },
- { "Reset", "Reset font selections",
- NULL, clearX11Fonts, NULL, NULL, ' ', ' ', ' ' },
- { " fnts", "Standard miscellaneous fonts",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86FontDists, '[', 'X', ']', DIST_XF86_FONTS_BITMAPS },
- { " f75", "75 DPI fonts",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86FontDists, '[', 'X', ']', DIST_XF86_FONTS_75 },
- { " f100", "100 DPI fonts",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86FontDists, '[', 'X', ']', DIST_XF86_FONTS_100 },
- { " fcyr", "Cyrillic Fonts",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86FontDists, '[', 'X', ']', DIST_XF86_FONTS_CYR },
- { " fscl", "Speedo and Type scalable fonts",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86FontDists, '[', 'X', ']', DIST_XF86_FONTS_SCALE },
- { " server", "Font server",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86FontDists, '[', 'X', ']', DIST_XF86_FONTS_SERVER },
- { NULL } },
-};
-
-DMenu MenuXF86SelectServer = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "X Server selection.",
- "Please check off the types of X servers you wish to install.\n",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- checkTrue, dmenuExit, NULL, NULL, '<', '<', '<' },
- { "All", "Select all of the above",
- NULL, setX11Servers, NULL, NULL, ' ', ' ', ' ' },
- { "Reset", "Reset all of the above",
- NULL, clearX11Servers, NULL, NULL, ' ', ' ', ' ' },
- { " srv", "Standard Graphics Framebuffer",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_FB },
- { " nest", "Nested X Server",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_NEST },
- { " prt", "X Print Server",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_PRINT },
- { " vfb", "Virtual Framebuffer",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_VFB },
- { NULL } },
-};
-
-#else
-DMenu MenuXF86SelectCore = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "XFree86 base distribution types",
- "Please check off the basic XFree86 components you wish to install.\n"
- "Bin, lib, and set are recommended for a minimum installaion.",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- checkTrue, dmenuExit, NULL, NULL, '<', '<', '<' },
- { "All", "Select all below",
- NULL, setX11Misc, NULL, NULL, ' ', ' ', ' ' },
- { "Reset", "Reset all below",
- NULL, clearX11Misc, NULL, NULL, ' ', ' ', ' ' },
- { " bin", "Client applications and shared libs",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_BIN },
- { " lib", "Data files needed at runtime",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_LIB },
- { " cfg", "Configuration files",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_CFG },
- { " set", "XFree86 Setup Utility",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_SET },
- { " man", "Manual pages",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_MAN },
- { " doc", "READMEs and release notes",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_DOC },
- { " html", "HTML documentation files",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_HTML },
- { " lkit", "Server link kit for all other machines",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_LKIT },
- { " prog", "Programmer's header and library files",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_PROG },
-#if defined(__i386__) && defined(PC98)
- { " 9set", "XFree86 Setup Utility for PC98 machines",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_9SET },
- { " lk98", "Server link kit for PC98 machines",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86Dists, '[', 'X', ']', DIST_XF86_LKIT98 },
-#endif
- { NULL } },
-};
-
-DMenu MenuXF86SelectFonts = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "Font distribution selection.",
- "Please check off the individual font distributions you wish to\n\
-install. At the minimum, you should install the standard\n\
-75 DPI and misc fonts if you're also installing a server\n\
-(these are selected by default).",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- checkTrue, dmenuExit, NULL, NULL, '<', '<', '<' },
- { "All", "All fonts",
- NULL, setX11Fonts, NULL, NULL, ' ', ' ', ' ' },
- { "Reset", "Reset font selections",
- NULL, clearX11Fonts, NULL, NULL, ' ', ' ', ' ' },
- { " fnts", "Standard 75 DPI and miscellaneous fonts",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86FontDists, '[', 'X', ']', DIST_XF86_FONTS_MISC },
- { " f100", "100 DPI fonts",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86FontDists, '[', 'X', ']', DIST_XF86_FONTS_100 },
- { " fcyr", "Cyrillic Fonts",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86FontDists, '[', 'X', ']', DIST_XF86_FONTS_CYR },
- { " fscl", "Speedo and Type scalable fonts",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86FontDists, '[', 'X', ']', DIST_XF86_FONTS_SCALE },
- { " non", "Japanese, Chinese and other non-english fonts",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86FontDists, '[', 'X', ']', DIST_XF86_FONTS_NON },
- { " server", "Font server",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86FontDists, '[', 'X', ']', DIST_XF86_FONTS_SERVER },
- { NULL } },
-};
-
-DMenu MenuXF86SelectServer = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "X Server selection.",
- "Please check off the types of X servers you wish to install.\n"
- "If you are unsure as to which server will work for your graphics card,\n"
- "it is recommended that try the SVGA or VGA16 servers or, for PC98\n"
- "machines, the 9EGC or 9840 servers.",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- checkTrue, dmenuExit, NULL, NULL, '<', '<', '<' },
- { "All", "Select all of the above",
- NULL, setX11Servers, NULL, NULL, ' ', ' ', ' ' },
- { "Reset", "Reset all of the above",
- NULL, clearX11Servers, NULL, NULL, ' ', ' ', ' ' },
- { " SVGA", "Standard VGA or Super VGA card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_SVGA },
- { " VGA16", "Standard 16 color VGA card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_VGA16 },
- { " Mono", "Standard Monochrome card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_MONO },
- { " 3DL", "8, 16 and 24 bit color 3D Labs boards",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_3DL },
- { " 8514", "8-bit (256 color) IBM 8514 or compatible card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_8514 },
- { " AGX", "8-bit AGX card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_AGX },
- { " I128", "8, 16 and 24-bit #9 Imagine I128 card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_I128 },
- { " Ma8", "8-bit ATI Mach8 card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_MACH8 },
- { " Ma32", "8 and 16-bit (65K color) ATI Mach32 card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_MACH32 },
- { " Ma64", "8 and 16-bit (65K color) ATI Mach64 card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_MACH64 },
- { " P9K", "8, 16, and 24-bit color Weitek P9000 based boards",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_P9000 },
- { " S3", "8, 16 and 24-bit color S3 based boards",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_S3 },
- { " S3V", "8, 16 and 24-bit color S3 Virge based boards",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_S3V },
- { " W32", "8-bit ET4000/W32, /W32i and /W32p cards",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_W32 },
-#if defined(__i386__) && defined(PC98)
- { " PC98", "Select an X server for a NEC PC98 [Submenu]",
- NULL, dmenuSubmenu, NULL, &MenuXF86SelectPC98Server, '>', ' ', '>', 0 },
-#elif defined(__alpha__)
- { " TGA", "TGA cards (alpha architecture only)",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_TGA },
-#endif
- { NULL } },
-};
-
-#if defined(__i386__) && defined(PC98)
-DMenu MenuXF86SelectPC98Server = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "PC98 X Server selection.",
- "Please check off the types of NEC PC98 X servers you wish to install.\n\
-If you are unsure as to which server will work for your graphics card,\n\
-it is recommended that try the SVGA or VGA16 servers (the VGA16 and\n\
-Mono servers are particularly well-suited to most LCD displays).",
- NULL,
- NULL,
- { { " 9480", "PC98 8-bit (256 color) PEGC-480 card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9480 },
- { " 9EGC", "PC98 4-bit (16 color) EGC card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9EGC },
- { " 9GA9", "PC98 GA-968V4/PCI (S3 968) card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9GA9 },
- { " 9GAN", "PC98 GANB-WAP (cirrus) card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9GAN },
- { " 9LPW", "PC98 PowerWindowLB (S3) card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9LPW },
- { " 9MGA", "PC98 MGA (Matrox) card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9MGA },
- { " 9NKV", "PC98 NKV-NEC (cirrus) card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9NKV },
- { " 9NS3", "PC98 NEC (S3) card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9NS3 },
- { " 9SPW", "PC98 SKB-PowerWindow (S3) card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9SPW },
- { " 9SVG", "PC98 generic SVGA card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9SVG },
- { " 9TGU", "PC98 Cyber9320 and TGUI9680 cards",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9TGU },
- { " 9WEP", "PC98 WAB-EP (cirrus) card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9WEP },
- { " 9WS", "PC98 WABS (cirrus) card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9WS },
- { " 9WSN", "PC98 WSN-A2F (cirrus) card",
- dmenuFlagCheck, dmenuSetFlag, NULL, &XF86ServerDists, '[', 'X', ']', DIST_XF86_SERVER_9WSN },
- { NULL } }
-};
-#endif
-#endif /* !X_AS_PKG */
-
-DMenu MenuDiskDevices = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "Select Drive(s)",
- "Please select the drive, or drives, on which you wish to perform\n"
- "this operation. If you are attempting to install a boot partition\n"
- "on a drive other than the first one or have multiple operating\n"
- "systems on your machine, you will have the option to install a boot\n"
- "manager later. To select a drive, use the arrow keys to move to it\n"
- "and press [SPACE] or [ENTER]. To de-select it, press it again.\n\n"
- "Use [TAB] to get to the buttons and leave this menu.",
- "Press F1 for important information regarding disk geometry!",
- "drives",
- { { NULL } },
-};
-
-DMenu MenuHTMLDoc = {
- DMENU_NORMAL_TYPE,
- "Select HTML Documentation pointer",
- "Please select the body of documentation you're interested in, the main\n"
- "ones right now being the FAQ and the Handbook. You can also choose \"other\"\n"
- "to enter an arbitrary URL for browsing.",
- "Press F1 for more help on what you see here.",
- "html",
- { { "X Exit", "Exit this menu (returning to previous)", NULL, dmenuExit },
- { "2 Handbook", "The FreeBSD Handbook.", NULL, docShowDocument },
- { "3 FAQ", "The Frequently Asked Questions guide.", NULL, docShowDocument },
- { "4 Home", "The Home Pages for the FreeBSD Project (requires net)", NULL, docShowDocument },
- { "5 Other", "Enter a URL.", NULL, docShowDocument },
- { NULL } },
-};
-
-/* The main installation menu */
-DMenu MenuInstallCustom = {
- DMENU_NORMAL_TYPE,
- "Choose Custom Installation Options",
- "This is the custom installation menu. You may use this menu to specify\n"
- "details on the type of distribution you wish to have, where you wish\n"
- "to install it from and how you wish to allocate disk storage to FreeBSD.",
- "Press F1 to read the installation guide",
- "INSTALL",
- { { "X Exit", "Exit this menu (returning to previous)", NULL, dmenuExit },
- { "2 Options", "View/Set various installation options", NULL, optionsEditor },
-#ifndef WITH_SLICES
- { "3 Label", "Label disk partitions", NULL, diskLabelEditor },
- { "4 Distributions", "Select distribution(s) to extract", NULL, dmenuSubmenu, NULL, &MenuDistributions },
- { "5 Media", "Choose the installation media type", NULL, dmenuSubmenu, NULL, &MenuMedia },
- { "6 Commit", "Perform any pending Partition/Label/Extract actions", NULL, installCustomCommit },
-#else
- { "3 Partition", "Allocate disk space for FreeBSD", NULL, diskPartitionEditor },
- { "4 Label", "Label allocated disk partitions", NULL, diskLabelEditor },
- { "5 Distributions", "Select distribution(s) to extract", NULL, dmenuSubmenu, NULL, &MenuDistributions },
- { "6 Media", "Choose the installation media type", NULL, dmenuSubmenu, NULL, &MenuMedia },
- { "7 Commit", "Perform any pending Partition/Label/Extract actions", NULL, installCustomCommit },
-#endif
- { NULL } },
-};
-
-#if defined(__i386__) || defined(__amd64__)
-#ifdef PC98
-/* IPL type menu */
-DMenu MenuIPLType = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "overwrite me", /* will be disk specific label */
- "If you want a FreeBSD Boot Manager, select \"BootMgr\". If you would\n"
- "prefer your Boot Manager to remain untouched then select \"None\".\n\n",
- "Press F1 to read about drive setup",
- "drives",
- { { "BootMgr", "Install the FreeBSD Boot Manager",
- dmenuRadioCheck, dmenuSetValue, NULL, &BootMgr },
- { "None", "Leave the IPL untouched",
- dmenuRadioCheck, dmenuSetValue, NULL, &BootMgr, '(', '*', ')', 1 },
- { NULL } },
-};
-#else
-/* MBR type menu */
-DMenu MenuMBRType = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "overwrite me", /* will be disk specific label */
- "FreeBSD comes with a boot selector that allows you to easily\n"
- "select between FreeBSD and any other operating systems on your machine\n"
- "at boot time. If you have more than one drive and want to boot\n"
- "from the second one, the boot selector will also make it possible\n"
- "to do so (limitations in the PC BIOS usually prevent this otherwise).\n"
- "If you do not want a boot selector, or wish to replace an existing\n"
- "one, select \"standard\". If you would prefer your Master Boot\n"
- "Record to remain untouched then select \"None\".\n\n"
- " NOTE: PC-DOS users will almost certainly require \"None\"!",
- "Press F1 to read about drive setup",
- "drives",
- { { "BootMgr", "Install the FreeBSD Boot Manager",
- dmenuRadioCheck, dmenuSetValue, NULL, &BootMgr },
- { "Standard", "Install a standard MBR (no boot manager)",
- dmenuRadioCheck, dmenuSetValue, NULL, &BootMgr, '(', '*', ')', 1 },
- { "None", "Leave the Master Boot Record untouched",
- dmenuRadioCheck, dmenuSetValue, NULL, &BootMgr, '(', '*', ')', 2 },
- { NULL } },
-};
-#endif /* PC98 */
-#endif /* __i386__ */
-
-/* Final configuration menu */
-DMenu MenuConfigure = {
- DMENU_NORMAL_TYPE,
- "FreeBSD Configuration Menu", /* title */
- "If you've already installed FreeBSD, you may use this menu to customize\n"
- "it somewhat to suit your particular configuration. Most importantly,\n"
- "you can use the Packages utility to load extra \"3rd party\"\n"
- "software not provided in the base distributions.",
- "Press F1 for more information on these options",
- "configure",
- { { "X Exit", "Exit this menu (returning to previous)",
- NULL, dmenuExit },
- { " Distributions", "Install additional distribution sets",
- NULL, distExtractAll },
- { " Packages", "Install pre-packaged software for FreeBSD",
- NULL, configPackages },
- { " Root Password", "Set the system manager's password",
- NULL, dmenuSystemCommand, NULL, "passwd root" },
-#ifdef WITH_SLICES
- { " Fdisk", "The disk Slice (PC-style partition) Editor",
- NULL, diskPartitionEditor },
-#endif
- { " Label", "The disk Label editor",
- NULL, diskLabelEditor },
- { " User Management", "Add user and group information",
- NULL, dmenuSubmenu, NULL, &MenuUsermgmt },
-#ifdef WITH_SYSCONS
- { " Console", "Customize system console behavior",
- NULL, dmenuSubmenu, NULL, &MenuSyscons },
-#endif
- { " Time Zone", "Set which time zone you're in",
- NULL, dmenuSystemCommand, NULL, "tzsetup" },
- { " Media", "Change the installation media type",
- NULL, dmenuSubmenu, NULL, &MenuMedia },
-#ifdef WITH_MICE
- { " Mouse", "Configure your mouse",
- NULL, dmenuSubmenu, NULL, &MenuMouse, NULL },
-#endif
- { " Networking", "Configure additional network services",
- NULL, dmenuSubmenu, NULL, &MenuNetworking },
- { " Security", "Configure system security options",
- NULL, dmenuSubmenu, NULL, &MenuSecurity },
- { " Startup", "Configure system startup options",
- NULL, dmenuSubmenu, NULL, &MenuStartup },
- { " TTYs", "Configure system ttys.",
- NULL, configEtcTtys, NULL, "ttys" },
- { " Options", "View/Set various installation options",
- NULL, optionsEditor },
- { " XFree86", "Configure XFree86 Server",
- NULL, configXSetup },
- { " Desktop", "Configure XFree86 Desktop",
- NULL, configXDesktop },
- { " HTML Docs", "Go to the HTML documentation menu (post-install)",
- NULL, docBrowser },
- { " Load KLD", "Load a KLD from a floppy",
- NULL, kldBrowser },
- { NULL } },
-};
-
-DMenu MenuStartup = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "Startup Services Menu",
- "This menu allows you to configure various aspects of your system's\n"
- "startup configuration. Use [SPACE] or [ENTER] to select items, and\n"
- "[TAB] to move to the buttons. Select Exit to leave this menu.",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- checkTrue, dmenuExit, NULL, NULL, '<', '<', '<' },
-#ifdef __i386__
- { " APM", "Auto-power management services (typically laptops)",
- dmenuVarCheck, dmenuToggleVariable, NULL, "apm_enable=YES" },
-#endif
-#ifdef PCCARD_ARCH
- { " pccard", "Enable PCCARD (AKA PCMCIA) services (also laptops)",
- dmenuVarCheck, dmenuToggleVariable, NULL, "pccard_enable=YES" },
- { " pccard mem", "Set PCCARD memory address (if enabled)",
- dmenuVarCheck, dmenuISetVariable, NULL, "pccard_mem" },
- { " pccard ifconfig", "List of PCCARD ethernet devices to configure",
- dmenuVarCheck, dmenuISetVariable, NULL, "pccard_ifconfig" },
-#endif
- { " usbd", "Enable USB daemon (detect USB attach / detach)",
- dmenuVarCheck, dmenuToggleVariable, NULL, "usbd_enable=YES" },
- { " usbd flags", "Set default flags to usbd (if enabled)",
- dmenuVarCheck, dmenuISetVariable, NULL, "usbd_flags" },
- { " ", " -- ", NULL, NULL, NULL, NULL, ' ', ' ', ' ' },
- { " Startup dirs", "Set the list of dirs to look for startup scripts",
- dmenuVarCheck, dmenuISetVariable, NULL, "local_startup" },
- { " named", "Run a local name server on this host",
- dmenuVarCheck, dmenuToggleVariable, NULL, "named_enable=YES" },
- { " named flags", "Set default flags to named (if enabled)",
- dmenuVarCheck, dmenuISetVariable, NULL, "named_flags" },
- { " NIS client", "This host wishes to be an NIS client.",
- dmenuVarCheck, configRpcBind, NULL, "nis_client_enable=YES" },
- { " NIS domainname", "Set NIS domainname (if enabled)",
- dmenuVarCheck, dmenuISetVariable, NULL, "nisdomainname" },
- { " NIS server", "This host wishes to be an NIS server.",
- dmenuVarCheck, configRpcBind, NULL, "nis_server_enable=YES" },
- { " ", " -- ", NULL, NULL, NULL, NULL, ' ', ' ', ' ' },
- { " Accounting", "This host wishes to run process accounting.",
- dmenuVarCheck, dmenuToggleVariable, NULL, "accounting_enable=YES" },
- { " lpd", "This host has a printer and wants to run lpd.",
- dmenuVarCheck, dmenuToggleVariable, NULL, "lpd_enable=YES" },
-#ifdef WITH_LINUX
- { " Linux", "This host wants to be able to run Linux binaries.",
- dmenuVarCheck, configLinux, NULL, VAR_LINUX_ENABLE "=YES" },
-#endif
-#ifdef __i386__
- { " SCO", "This host wants to be able to run IBCS2 binaries.",
- dmenuVarCheck, dmenuToggleVariable, NULL, "ibcs2_enable=YES" },
- { " SVR4", "This host wants to be able to run SVR4 binaries.",
- dmenuVarCheck, dmenuToggleVariable, NULL, "svr4_enable=YES" },
-#endif
-#ifdef __alpha__
- { " OSF/1", "This host wants to be able to run DEC OSF/1 binaries.",
- dmenuVarCheck, configOSF1, NULL, VAR_OSF1_ENABLE "=YES" },
-#endif
- { " quotas", "This host wishes to check quotas on startup.",
- dmenuVarCheck, dmenuToggleVariable, NULL, "check_quotas=YES" },
- { NULL } },
-};
-
-DMenu MenuNetworking = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "Network Services Menu",
- "You may have already configured one network device (and the other\n"
- "various hostname/gateway/name server parameters) in the process\n"
- "of installing FreeBSD. This menu allows you to configure other\n"
- "aspects of your system's network configuration.",
- NULL,
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- checkTrue, dmenuExit, NULL, NULL, '<', '<', '<' },
- { " Interfaces", "Configure additional network interfaces",
- NULL, tcpMenuSelect },
- { " AMD", "This machine wants to run the auto-mounter service",
- dmenuVarCheck, configRpcBind, NULL, "amd_enable=YES" },
- { " AMD Flags", "Set flags to AMD service (if enabled)",
- dmenuVarCheck, dmenuISetVariable, NULL, "amd_flags" },
- { " Anon FTP", "This machine wishes to allow anonymous FTP.",
- dmenuVarCheck, configAnonFTP, NULL, "anon_ftp" },
- { " Gateway", "This machine will route packets between interfaces",
- dmenuVarCheck, dmenuToggleVariable, NULL, "gateway_enable=YES" },
- { " inetd", "This machine wants to run the inet daemon",
- dmenuVarCheck, configInetd, NULL, "inetd_enable=YES" },
- { " NFS client", "This machine will be an NFS client",
- dmenuVarCheck, dmenuToggleVariable, NULL, "nfs_client_enable=YES" },
- { " NFS server", "This machine will be an NFS server",
- dmenuVarCheck, configNFSServer, NULL, "nfs_server_enable=YES" },
- { " Ntpdate", "Select a clock-synchronization server",
- dmenuVarCheck, dmenuSubmenu, NULL, &MenuNTP, '[', 'X', ']', "ntpdate_enable=YES" },
- { " PCNFSD", "Run authentication server for clients with PC-NFS.",
- dmenuVarCheck, configPCNFSD, NULL, "pcnfsd" },
- { " rpcbind", "RPC port mapping daemon (formerly portmapper)",
- dmenuVarCheck, dmenuToggleVariable, NULL, "rpcbind_enable=YES" },
- { " rpc.statd", "NFS status monitoring daemon",
- dmenuVarCheck, configRpcBind, NULL, "rpc_statd_enable=YES" },
- { " rpc.lockd", "NFS file locking daemon",
- dmenuVarCheck, configRpcBind, NULL, "rpc_lockd_enable=YES" },
- { " Routed", "Select routing daemon (default: routed)",
- dmenuVarCheck, configRouter, NULL, "router_enable=YES" },
- { " Rwhod", "This machine wants to run the rwho daemon",
- dmenuVarCheck, dmenuToggleVariable, NULL, "rwhod_enable=YES" },
- { " Sendmail", "This machine wants to run the sendmail daemon",
- NULL, dmenuSubmenu, NULL, &MenuSendmail },
- { " Sshd", "This machine wants to run the ssh daemon",
- dmenuVarCheck, dmenuToggleVariable, NULL, "sshd_enable=YES" },
- { " TCP Extensions", "Allow RFC1323 and RFC1644 TCP extensions?",
- dmenuVarCheck, dmenuToggleVariable, NULL, "tcp_extensions=YES" },
- { NULL } },
-};
-
-DMenu MenuSendmail = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Sendmail Invocation Selection",
- "There are three options for invoking sendmail at startup.\n"
- "Please select Yes if you want to use sendmail as your mail transfer\n"
- "agent. Selecting No disables sendmail's network socket for incoming\n"
- "email, but still enables sendmail for local and outbound mail.\n"
- "None disables sendmail completely at startup and disables inbound,\n"
- "outbound, and local mail. See /etc/mail/README for more\n"
- "information.\n",
- NULL,
- NULL,
- {
- { " Yes", "Start sendmail",
- dmenuVarCheck, dmenuSetVariable, NULL, "sendmail_enable=YES" },
- { " No", "Start sendmail, but don't listen from network",
- dmenuVarCheck, dmenuSetVariable, NULL, "sendmail_enable=NO" },
- { " None", "Don't start any sendmail processes",
- dmenuVarCheck, dmenuSetVariable, NULL, "sendmail_enable=NONE" },
- { NULL } },
-};
-
-DMenu MenuNTP = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "NTPDATE Server Selection",
- "There are a number of time synchronization servers available\n"
- "for public use around the Internet. Please select one reasonably\n"
- "close to you to have your system time synchronized accordingly.",
- "These are the primary open-access NTP servers",
- NULL,
- { { "None", "No NTP server",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=NO,ntpdate_flags=none" },
- { "Other", "Select a site not on this list",
- dmenuVarsCheck, configNTP, NULL, NULL },
- { "Argentina", "tick.nap.com.ar",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=tick.nap.com.ar" },
- { "Argentina #2", "time.sinectis.com.ar",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=time.sinectis.com.ar" },
- { "Argentina #3", "tock.nap.com.ar",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=tock.nap.com.ar" },
- { "Australia", "augean.eleceng.adelaide.edu.au",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=augean.eleceng.adelaide.edu.au" },
- { "Australia #2", "ntp.adelaide.edu.au",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.adelaide.edu.au" },
- { "Australia #3", "ntp.saard.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.saard.net" },
- { "Australia #4", "time.deakin.edu.au",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=time.deakin.edu.au" },
- { "Australia #5", "time.esec.com.au",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=time.esec.com.au" },
- { "Belgium", "ntp1.belbone.be",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp1.belbone.be" },
- { "Belgium #2", "ntp2.belbone.be",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2.belbone.be" },
- { "Brazil", "ntp.cais.rnp.br",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.cais.rnp.br" },
- { "Brazil #2", "ntp.pop-df.rnp.br",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.pop-df.rnp.br" },
- { "Brazil #3", "ntp.ufes.br",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.ufes.br" },
- { "Brazil #4", "ntp1.pucpr.br",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp1.pucpr.br" },
- { "Canada", "ntp.cpsc.ucalgary.ca",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.cpsc.ucalgary.ca" },
- { "Canada #2", "ntp1.cmc.ec.gc.ca",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp1.cmc.ec.gc.ca" },
- { "Canada #3", "ntp2.cmc.ec.gc.ca",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2.cmc.ec.gc.ca" },
- { "Canada #4", "tick.utoronto.ca",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=tick.utoronto.ca" },
- { "Canada #5", "time.chu.nrc.ca",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=time.chu.nrc.ca" },
- { "Canada #6", "time.nrc.ca",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=time.nrc.ca" },
- { "Canada #7", "timelord.uregina.ca",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=timelord.uregina.ca" },
- { "Canada #8", "tock.utoronto.ca",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=tock.utoronto.ca" },
- { "Czech", "ntp.karpo.cz",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.karpo.cz" },
- { "Denmark", "clock.netcetera.dk",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=clock.netcetera.dk" },
- { "Denmark", "clock2.netcetera.dk",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=clock2.netcetera.dk" },
- { "Spain", "slug.ctv.es",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=slug.ctv.es" },
- { "Finland", "tick.keso.fi",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=tick.keso.fi" },
- { "Finland #2", "tock.keso.fi",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=tock.keso.fi" },
- { "France", "ntp.obspm.fr",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.obspm.fr" },
- { "France #2", "ntp.univ-lyon1.fr",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.univ-lyon1.fr" },
- { "France #3", "ntp.via.ecp.fr",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.via.ecp.fr" },
- { "Croatia", "zg1.ntp.carnet.hr",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=zg1.ntp.carnet.hr" },
- { "Croatia #2", "zg2.ntp.carnet.hr",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=zg2.ntp.carnet.hr" },
- { "Croatia #3", "st.ntp.carnet.hr",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=st.ntp.carnet.hr" },
- { "Croatia #4", "ri.ntp.carnet.hr",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ri.ntp.carnet.hr" },
- { "Croatia #5", "os.ntp.carnet.hr",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=os.ntp.carnet.hr" },
- { "Hungary", "time.kfki.hu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=time.kfki.hu" },
- { "Indonesia", "ntp.incaf.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.incaf.net" },
- { "Ireland", "ntp.maths.tcd.ie",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.maths.tcd.ie" },
- { "Italy", "ntps.net4u.it",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=" },
- { "Japan", "ntp.cyber-fleet.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.cyber-fleet.net" },
- { "Korea", "time.nuri.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=time.nuri.net" },
- { "Mexico", "ntp2a.audiotel.com.mx",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2a.audiotel.com.mx" },
- { "Mexico #2", "ntp2b.audiotel.com.mx",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2b.audiotel.com.mx" },
- { "Mexico #3", "ntp2c.audiotel.com.mx",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2c.audiotel.com.mx" },
- { "Nigeria", "ntp.supernet300.com",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.supernet300.com" },
- { "Netherlands", "ntp1.theinternetone.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp1.theinternetone.net" },
- { "Netherlands #2", "ntp2.theinternetone.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2.theinternetone.net" },
- { "Netherlands #3", "ntp3.theinternetone.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp3.theinternetone.net" },
- { "Norway", "fartein.ifi.uio.no",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=fartein.ifi.uio.no" },
- { "Norway #2", "time.alcanet.no",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=time.alcanet.no" },
- { "New Zealand", "ntp.massey.ac.nz",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.massey.ac.nz" },
- { "New Zealand #2", "ntp.public.otago.ac.nz",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.public.otago.ac.nz" },
- { "New Zealand #3", "tk1.ihug.co.nz",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=tk1.ihug.co.nz" },
- { "New Zealand #4", "ntp.waikato.ac.nz",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.waikato.ac.nz" },
- { "Poland", "info.cyf-kr.edu.pl",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=info.cyf-kr.edu.pl" },
- { "Portugal", "bug.fe.up.pt",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=bug.fe.up.pt" },
- { "Romania", "ntp.ip.ro",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.ip.ro" },
- { "Russia", "ntp.psn.ru",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.psn.ru" },
- { "Russia #2", "sign.chg.ru",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=sign.chg.ru" },
- { "Sweden", "ntp.lth.se",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.lth.se" },
- { "Singapore", "ntp.shim.org",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.shim.org" },
- { "Slovenia", "calvus.rzs-hm.si",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=calvus.rzs-hm.si" },
- { "Slovenia #2", "sizif.mf.uni-lj.si",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=sizif.mf.uni-lj.si" },
- { "Slovenia #3", "ntp1.arnes.si",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp1.arnes.si" },
- { "Slovenia #4", "ntp2.arnes.si",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2.arnes.si" },
- { "Slovenia #5", "time.ijs.si",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=time.ijs.si" },
- { "Scotland", "ntp.cs.strath.ac.uk",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.cs.strath.ac.uk" },
- { "United Kingdom", "ntp.exnet.com",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.exnet.com" },
- { "United Kingdom #2", "ntp0.uk.uu.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp0.uk.uu.net" },
- { "United Kingdom #3", "ntp1.uk.uu.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp1.uk.uu.net" },
- { "United Kingdom #4", "ntp2.uk.uu.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2.uk.uu.net" },
- { "United Kingdom #5", "ntp2a.mcc.ac.uk",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2a.mcc.ac.uk" },
- { "United Kingdom #6", "ntp2b.mcc.ac.uk",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2b.mcc.ac.uk" },
- { "United Kingdom #7", "ntp2c.mcc.ac.uk",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2c.mcc.ac.uk" },
- { "United Kingdom #8", "ntp2d.mcc.ac.uk",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2d.mcc.ac.uk" },
- { "United Kingdom #9", "tick.tanac.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=tick.tanac.net" },
- { "U.S. AR", "sushi.compsci.lyon.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=sushi.compsci.lyon.edu" },
- { "U.S. AZ", "ntp.drydog.com",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.drydog.com" },
- { "U.S. CA", "ntp.ucsd.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.ucsd.edu" },
- { "U.S. CA #2", "ntp1.mainecoon.com",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp1.mainecoon.com" },
- { "U.S. CA #3", "ntp2.mainecoon.com",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2.mainecoon.com" },
- { "U.S. CA #4", "reloj.kjsl.com",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=reloj.kjsl.com" },
- { "U.S. CA #5", "time.five-ten-sg.com",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=time.five-ten-sg.com" },
- { "U.S. DE", "louie.udel.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=louie.udel.edu" },
- { "U.S. GA", "ntp.shorty.com",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.shorty.com" },
- { "U.S. GA #2", "rolex.usg.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=rolex.usg.edu" },
- { "U.S. GA #3", "timex.usg.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=timex.usg.edu" },
- { "U.S. IL", "ntp-0.cso.uiuc.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp-0.cso.uiuc.edu" },
- { "U.S. IL #2", "ntp-1.cso.uiuc.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp-1.cso.uiuc.edu" },
- { "U.S. IL #3", "ntp-1.mcs.anl.gov",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp-1.mcs.anl.gov" },
- { "U.S. IL #4", "ntp-2.cso.uiuc.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp-2.cso.uiuc.edu" },
- { "U.S. IL #5", "ntp-2.mcs.anl.gov",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp-2.mcs.anl.gov" },
- { "U.S. IN", "gilbreth.ecn.purdue.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=gilbreth.ecn.purdue.edu" },
- { "U.S. IN #2", "harbor.ecn.purdue.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=harbor.ecn.purdue.edu" },
- { "U.S. IN #3", "molecule.ecn.purdue.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=molecule.ecn.purdue.edu" },
- { "U.S. KS", "ntp1.kansas.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp1.kansas.net" },
- { "U.S. KS #2", "ntp2.kansas.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2.kansas.net" },
- { "U.S. MA", "ntp.ourconcord.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.ourconcord.net" },
- { "U.S. MA #2", "timeserver.cs.umb.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=timeserver.cs.umb.edu" },
- { "U.S. MN", "ns.nts.umn.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ns.nts.umn.edu" },
- { "U.S. MN #2", "nss.nts.umn.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=nss.nts.umn.edu" },
- { "U.S. MO", "time-ext.missouri.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=time-ext.missouri.edu" },
- { "U.S. MT", "chronos1.umt.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=chronos1.umt.edu" },
- { "U.S. MT #2", "chronos2.umt.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=chronos2.umt.edu" },
- { "U.S. MT #3", "chronos3.umt.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=chronos3.umt.edu" },
- { "U.S. NC", "clock1.unc.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=clock1.unc.edu" },
- { "U.S. NV", "cuckoo.nevada.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=cuckoo.nevada.edu" },
- { "U.S. NV #2", "tick.cs.unlv.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=tick.cs.unlv.edu" },
- { "U.S. NV #3", "tock.cs.unlv.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=tock.cs.unlv.edu" },
- { "U.S. NY", "clock.linuxshell.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=clock.linuxshell.net" },
- { "U.S. NY #2", "ntp.ctr.columbia.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.ctr.columbia.edu" },
- { "U.S. NY #3", "ntp0.cornell.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp0.cornell.edu" },
- { "U.S. NY #4", "ntp1.mpis.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp1.mpis.net" },
- { "U.S. NY #5", "ntp2.mpis.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2.mpis.net" },
- { "U.S. NY #6", "sundial.columbia.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=sundial.columbia.edu" },
- { "U.S. NY #7", "timex.cs.columbia.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=timex.cs.columbia.edu" },
- { "U.S. OK", "constellation.ecn.uoknor.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=constellation.ecn.uoknor.edu" },
- { "U.S. PA", "clock-1.cs.cmu.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=clock-1.cs.cmu.edu" },
- { "U.S. PA #2", "clock-2.cs.cmu.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=clock-2.cs.cmu.edu" },
- { "U.S. PA #3", "clock.psu.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=clock.psu.edu" },
- { "U.S. PA #4", "fuzz.psc.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=fuzz.psc.edu" },
- { "U.S. PA #5", "ntp-1.ece.cmu.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp-1.ece.cmu.edu" },
- { "U.S. PA #6", "ntp-2.ece.cmu.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp-2.ece.cmu.edu" },
- { "U.S. TX", "ntp.cox.smu.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.cox.smu.edu" },
- { "U.S. TX #2", "ntp.fnbhs.com",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.fnbhs.com" },
- { "U.S. TX #3", "ntp.tmc.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.tmc.edu" },
- { "U.S. TX #4", "ntp5.tamu.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp5.tamu.edu" },
- { "U.S. TX #5", "tick.greyware.com",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=tick.greyware.com" },
- { "U.S. TX #6", "tock.greyware.com",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=tock.greyware.com" },
- { "U.S. VA", "ntp-1.vt.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp-1.vt.edu" },
- { "U.S. VA #2", "ntp-2.vt.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp-2.vt.edu" },
- { "U.S. VA #3", "ntp.cmr.gov",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.cmr.gov" },
- { "U.S. VT", "ntp0.state.vt.us",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp0.state.vt.us" },
- { "U.S. VT #2", "ntp1.state.vt.us",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp1.state.vt.us" },
- { "U.S. VT #3", "ntp2.state.vt.us",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp2.state.vt.us" },
- { "U.S. WA", "clock.tricity.wsu.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=clock.tricity.wsu.edu" },
- { "U.S. WA #2", "ntp.tcp-udp.net",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.tcp-udp.net" },
- { "U.S. WI", "ntp1.cs.wisc.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp1.cs.wisc.edu" },
- { "U.S. WI #2", "ntp3.cs.wisc.edu",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp3.cs.wisc.edu" },
- { "Venezuela", "ntp.linux.org.ve",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.linux.org.ve" },
- { "South Africa", "ntp.cs.unp.ac.za",
- dmenuVarsCheck, dmenuSetVariables, NULL,
- "ntpdate_enable=YES,ntpdate_flags=ntp.cs.unp.ac.za" },
- { NULL } },
-};
-
-#ifdef WITH_SYSCONS
-DMenu MenuSyscons = {
- DMENU_NORMAL_TYPE,
- "System Console Configuration",
- "The default system console driver for FreeBSD (syscons) has a\n"
- "number of configuration options which may be set according to\n"
- "your preference.\n\n"
- "When you are done setting configuration options, select Cancel.",
- "Configure your system console settings",
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)", NULL, dmenuExit },
-#ifdef PC98
- { "2 Keymap", "Choose an alternate keyboard map", NULL, dmenuSubmenu, NULL, &MenuSysconsKeymap },
- { "3 Repeat", "Set the rate at which keys repeat", NULL, dmenuSubmenu, NULL, &MenuSysconsKeyrate },
- { "4 Saver", "Configure the screen saver", NULL, dmenuSubmenu, NULL, &MenuSysconsSaver },
-#else
- { "2 Font", "Choose an alternate screen font", NULL, dmenuSubmenu, NULL, &MenuSysconsFont },
- { "3 Keymap", "Choose an alternate keyboard map", NULL, dmenuSubmenu, NULL, &MenuSysconsKeymap },
- { "4 Repeat", "Set the rate at which keys repeat", NULL, dmenuSubmenu, NULL, &MenuSysconsKeyrate },
- { "5 Saver", "Configure the screen saver", NULL, dmenuSubmenu, NULL, &MenuSysconsSaver },
- { "6 Screenmap", "Choose an alternate screenmap", NULL, dmenuSubmenu, NULL, &MenuSysconsScrnmap },
- { "7 Ttys", "Choose console terminal type", NULL, dmenuSubmenu, NULL, &MenuSysconsTtys },
-#endif
- { NULL } },
-};
-
-#ifdef PC98
-DMenu MenuSysconsKeymap = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "System Console Keymap",
- "The default system console driver for FreeBSD (syscons) defaults\n"
- "to a standard \"PC-98x1\" keyboard map. Users may wish to choose\n"
- "one of the other keymaps below.\n"
- "Note that sysinstall itself only uses the part of the keyboard map\n"
- "which is required to generate the ANSI character subset, but your\n"
- "choice of keymap will also be saved for later (fuller) use.",
- "Choose a keyboard map",
- NULL,
- { { "Japanese PC-98x1", "Japanese PC-98x1 keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=jp.pc98" },
- { " Japanese PC-98x1 (ISO)", "Japanese PC-98x1 (ISO) keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=jp.pc98.iso" },
- { NULL } },
-};
-#else
-DMenu MenuSysconsKeymap = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "System Console Keymap",
- "The default system console driver for FreeBSD (syscons) defaults\n"
- "to a standard \"American\" keyboard map. Users in other countries\n"
- "(or with different keyboard preferences) may wish to choose one of\n"
- "the other keymaps below.\n"
- "Note that sysinstall itself only uses the part of the keyboard map\n"
- "which is required to generate the ANSI character subset, but your\n"
- "choice of keymap will also be saved for later (fuller) use.",
- "Choose a keyboard map",
- NULL,
- { { "Belgian", "Belgian ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=be.iso" },
- { " Brazil CP850", "Brazil CP850 keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=br275.cp850" },
- { " Brazil ISO (accent)", "Brazil ISO keymap (accent keys)", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=br275.iso.acc" },
- { " Brazil ISO", "Brazil ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=br275.iso" },
- { " Bulgarian BDS", "Bulgarian BDS keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=bg.bds.ctrlcaps" },
- { " Bulgarian Phonetic", "Bulgarian Phonetic keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=bg.phonetic.ctrlcaps" },
- { " Croatian ISO", "Croatian ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=hr.iso" },
- { " Czech ISO (accent)", "Czech ISO keymap (accent keys)", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=cs.latin2.qwertz" },
- { "Danish CP865", "Danish Code Page 865 keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=danish.cp865" },
- { " Danish ISO", "Danish ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=danish.iso" },
- { "Estonian ISO", "Estonian ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=estonian.iso" },
- { " Estonian ISO 15", "Estonian ISO 8859-15 keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=estonian.iso15" },
- { " Estonian CP850", "Estonian Code Page 850 keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=estonian.cp850" },
- { "Finnish CP850","Finnish Code Page 850 keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=finnish.cp850" },
- { " Finnish ISO", "Finnish ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=finnish.iso" },
- { " French ISO (accent)", "French ISO keymap (accent keys)", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=fr.iso.acc" },
- { " French ISO", "French ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=fr.iso" },
- { "German CP850", "German Code Page 850 keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=german.cp850" },
- { " German ISO", "German ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=german.iso" },
- { "Hungarian 101", "Hungarian ISO keymap (101 key)", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=hu.iso2.101keys" },
- { " Hungarian 102", "Hungarian ISO keymap (102 key)", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=hu.iso2.102keys" },
- { "Icelandic (accent)", "Icelandic ISO keymap (accent keys)", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=icelandic.iso.acc" },
- { " Icelandic", "Icelandic ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=icelandic.iso" },
- { " Italian", "Italian ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=it.iso" },
- { "Japanese 106", "Japanese 106 keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=jp.106" },
- { "Latin American", "Latin American ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=lat-amer" },
- { "Norway ISO", "Norwegian ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=norwegian.iso" },
- { "Polish ISO", "Polish ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=pl_PL.ISO8859-2" },
- { " Portuguese (accent)", "Portuguese ISO keymap (accent keys)", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=pt.iso.acc" },
- { " Portuguese", "Portuguese ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=pt.iso" },
- { "Russia KOI8-R", "Russian KOI8-R keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=ru.koi8-r" },
- { "Slovenian", "Slovenian ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=si.iso" },
- { " Spanish (accent)", "Spanish ISO keymap (accent keys)", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=spanish.iso.acc" },
- { " Spanish", "Spanish ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=spanish.iso" },
- { " Swedish CP850", "Swedish Code Page 850 keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=swedish.cp850" },
- { " Swedish ISO", "Swedish ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=swedish.iso" },
- { " Swiss French ISO (accent)", "Swiss French ISO keymap (accent keys)", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=swissfrench.iso.acc" },
- { " Swiss French ISO", "Swiss French ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=swissfrench.iso" },
- { " Swiss French CP850", "Swiss French Code Page 850 keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=swissfrench.cp850" },
- { " Swiss German ISO (accent)", "Swiss German ISO keymap (accent keys)", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=swissgerman.iso.acc" },
- { " Swiss German ISO", "Swiss German ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=swissgerman.iso" },
- { " Swiss German CP850", "Swiss German Code Page 850 keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=swissgerman.cp850" },
- { "UK CP850", "UK Code Page 850 keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=uk.cp850" },
- { " UK ISO", "UK ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=uk.iso" },
- { " Ukrainian KOI8-U", "Ukrainian KOI8-U keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=ua.koi8-u" },
- { " Ukrainian KOI8-U+KOI8-R", "Ukrainian KOI8-U+KOI8-R keymap (alter)", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=ua.koi8-u.shift.alt" },
- { " USA CapsLock->Ctrl", "US standard (Caps as L-Control)", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=us.pc-ctrl" },
- { " USA Dvorak", "US Dvorak keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=us.dvorak" },
- { " USA Dvorak (left)", "US left handed Dvorak keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=us.dvorakl" },
- { " USA Dvorak (right)", "US right handed Dvorak keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=us.dvorakr" },
- { " USA Emacs", "US standard optimized for EMACS", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=us.emacs" },
- { " USA ISO", "US ISO keymap", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=us.iso" },
- { " USA UNIX", "US traditional UNIX-workstation", dmenuVarCheck, dmenuSetKmapVariable, NULL, "keymap=us.unix" },
- { NULL } },
-};
-#endif /* PC98 */
-
-DMenu MenuSysconsKeyrate = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "System Console Keyboard Repeat Rate",
- "This menu allows you to set the speed at which keys repeat\n"
- "when held down.",
- "Choose a keyboard repeat rate",
- NULL,
- { { "Slow", "Slow keyboard repeat rate", dmenuVarCheck, dmenuSetVariable, NULL, "keyrate=slow" },
- { "Normal", "\"Normal\" keyboard repeat rate", dmenuVarCheck, dmenuSetVariable, NULL, "keyrate=normal" },
- { "Fast", "Fast keyboard repeat rate", dmenuVarCheck, dmenuSetVariable, NULL, "keyrate=fast" },
- { "Default", "Use default keyboard repeat rate", dmenuVarCheck, dmenuSetVariable, NULL, "keyrate=NO" },
- { NULL } },
-};
-
-DMenu MenuSysconsSaver = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "System Console Screen Saver",
- "By default, the console driver will not attempt to do anything\n"
- "special with your screen when it's idle. If you expect to leave your\n"
- "monitor switched on and idle for long periods of time then you should\n"
- "probably enable one of these screen savers to prevent phosphor burn-in.",
- "Choose a nifty-looking screen saver",
- NULL,
- { { "1 Blank", "Simply blank the screen",
- dmenuVarCheck, configSaver, NULL, "saver=blank" },
- { "2 Daemon", "\"BSD Daemon\" animated screen saver (text)",
- dmenuVarCheck, configSaver, NULL, "saver=daemon" },
- { "3 Fade", "Fade out effect screen saver",
- dmenuVarCheck, configSaver, NULL, "saver=fade" },
- { "4 Fire", "Flames effect screen saver",
- dmenuVarCheck, configSaver, NULL, "saver=fire" },
- { "5 Green", "\"Green\" power saving mode (if supported by monitor)",
- dmenuVarCheck, configSaver, NULL, "saver=green" },
- { "6 Logo", "\"BSD Daemon\" animated screen saver (graphics)",
- dmenuVarCheck, configSaver, NULL, "saver=logo" },
- { "7 Rain", "Rain drops screen saver",
- dmenuVarCheck, configSaver, NULL, "saver=rain" },
- { "8 Snake", "Draw a FreeBSD \"snake\" on your screen",
- dmenuVarCheck, configSaver, NULL, "saver=snake" },
- { "9 Star", "A \"twinkling stars\" effect",
- dmenuVarCheck, configSaver, NULL, "saver=star" },
- { "Warp", "A \"stars warping\" effect",
- dmenuVarCheck, configSaver, NULL, "saver=warp" },
- { "Dragon", "Dragon screensaver (graphics)",
- dmenuVarCheck, configSaver, NULL, "saver=dragon" },
- { "Timeout", "Set the screen saver timeout interval",
- NULL, configSaverTimeout, NULL, NULL, ' ', ' ', ' ' },
- { NULL } },
-};
-
-#ifndef PC98
-DMenu MenuSysconsScrnmap = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "System Console Screenmap",
- "Unless you load a specific font, most PC hardware defaults to\n"
- "displaying characters in the IBM 437 character set. However,\n"
- "in the Unix world, this character set is very rarely used. Most\n"
- "Western European countries, for example, prefer ISO 8859-1.\n"
- "American users won't notice the difference since the bottom half\n"
- "of all these character sets is ANSI anyway.\n"
- "If your hardware is capable of downloading a new display font,\n"
- "you should probably choose that option. However, for hardware\n"
- "where this is not possible (e.g. monochrome adapters), a screen\n"
- "map will give you the best approximation that your hardware can\n"
- "display at all.",
- "Choose a screen map",
- NULL,
- { { "1 None", "No screenmap, don't touch font", dmenuVarCheck, dmenuSetVariable, NULL, "scrnmap=NO" },
- { "2 ISO 8859-1 to IBM437", "W-Europe ISO 8859-1 to IBM 437 screenmap", dmenuVarCheck, dmenuSetVariable, NULL, "scrnmap=iso-8859-1_to_cp437" },
- { "3 ISO 8859-7 to IBM437", "Greek ISO 8859-7 to IBM 437 screenmap", dmenuVarCheck, dmenuSetVariable, NULL, "scrnmap=iso-8859-7_to_cp437" },
- { "4 US-ASCII to IBM437", "US-ASCII to IBM 437 screenmap", dmenuVarCheck, dmenuSetVariable, NULL, "scrnmap=us-ascii_to_cp437" },
- { "5 KOI8-R to IBM866", "Russian KOI8-R to IBM 866 screenmap", dmenuVarCheck, dmenuSetVariable, NULL, "scrnmap=koi8-r2cp866" },
- { "6 KOI8-U to IBM866u", "Ukrainian KOI8-U to IBM 866u screenmap", dmenuVarCheck, dmenuSetVariable, NULL, "scrnmap=koi8-u2cp866u" },
- { NULL } },
-};
-
-DMenu MenuSysconsTtys = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "System Console Terminal Type",
- "For various console encodings, a corresponding terminal type\n"
- "must be chosen in /etc/ttys.\n\n"
- "WARNING: For compatibility reasons, only entries starting with\n"
- "ttyv and terminal types starting with cons[0-9] can be changed\n"
- "via this menu.\n",
- "Choose a terminal type",
- NULL,
- { { "1 None", "Don't touch anything", dmenuVarCheck, dmenuSetVariable, NULL, VAR_CONSTERM "=NO" },
- { "2 IBM437 (VGA default)", "cons25", dmenuVarCheck, dmenuSetVariable, NULL, VAR_CONSTERM "=cons25" },
- { "3 ISO 8859-1", "cons25l1", dmenuVarCheck, dmenuSetVariable, NULL, VAR_CONSTERM "=cons25l1" },
- { "4 ISO 8859-2", "cons25l2", dmenuVarCheck, dmenuSetVariable, NULL, VAR_CONSTERM "=cons25l2" },
- { "5 ISO 8859-7", "cons25l7", dmenuVarCheck, dmenuSetVariable, NULL, VAR_CONSTERM "=cons25l7" },
- { "6 KOI8-R", "cons25r", dmenuVarCheck, dmenuSetVariable, NULL, VAR_CONSTERM "=cons25r" },
- { "7 KOI8-U", "cons25u", dmenuVarCheck, dmenuSetVariable, NULL, VAR_CONSTERM "=cons25u" },
- { "8 US-ASCII", "cons25w", dmenuVarCheck, dmenuSetVariable, NULL, VAR_CONSTERM "=cons25w" },
- { NULL } },
-};
-
-DMenu MenuSysconsFont = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "System Console Font",
- "Most PC hardware defaults to displaying characters in the\n"
- "IBM 437 character set. However, in the Unix world, this\n"
- "character set is very rarely used. Most Western European\n"
- "countries, for example, prefer ISO 8859-1.\n"
- "American users won't notice the difference since the bottom half\n"
- "of all these charactersets is ANSI anyway. However, they might\n"
- "want to load a font anyway to use the 30- or 50-line displays.\n"
- "If your hardware is capable of downloading a new display font,\n"
- "you can select the appropriate font below.",
- "Choose a font",
- NULL,
- { { "1 None", "Use hardware default font", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=NO,font8x14=NO,font8x16=NO" },
- { "2 IBM 437", "English and others, VGA default", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=cp437-8x8,font8x14=cp437-8x14,font8x16=cp437-8x16" },
- { "3 IBM 850", "Western Europe, IBM encoding", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=cp850-8x8,font8x14=cp850-8x14,font8x16=cp850-8x16" },
- { "4 IBM 865", "Norwegian, IBM encoding", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=cp865-8x8,font8x14=cp865-8x14,font8x16=cp865-8x16" },
- { "5 IBM 866", "Russian, IBM encoding (use with KOI8-R screenmap)", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=cp866-8x8,font8x14=cp866-8x14,font8x16=cp866b-8x16,mousechar_start=3" },
- { "6 IBM 866u", "Ukrainian, IBM encoding (use with KOI8-U screenmap)", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=cp866u-8x8,font8x14=cp866u-8x14,font8x16=cp866u-8x16,mousechar_start=3" },
- { "7 IBM 1251", "Cyrillic, MS Windows encoding", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=cp1251-8x8,font8x14=cp1251-8x14,font8x16=cp1251-8x16,mousechar_start=3" },
- { "8 ISO 8859-1", "Western Europe, ISO encoding", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=iso-8x8,font8x14=iso-8x14,font8x16=iso-8x16" },
- { "9 ISO 8859-2", "Eastern Europe, ISO encoding", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=iso02-8x8,font8x14=iso02-8x14,font8x16=iso02-8x16" },
- { "a ISO 8859-4", "Baltic, ISO encoding", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=iso04-8x8,font8x14=iso04-8x14,font8x16=iso04-8x16" },
- { "b ISO 8859-7", "Greek, ISO encoding", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=iso07-8x8,font8x14=iso07-8x14,font8x16=iso07-8x16" },
- { "c ISO 8859-8", "Hebrew, ISO encoding", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=iso08-8x8,font8x14=iso08-8x14,font8x16=iso08-8x16" },
- { "d ISO 8859-15", "Europe, ISO encoding", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=iso15-8x8,font8x14=iso15-8x14,font8x16=iso15-8x16" },
- { "e SWISS", "English, better resolution", dmenuVarCheck, dmenuSetVariables, NULL,
- "font8x8=swiss-8x8,font8x14=NO,font8x16=swiss-8x16" },
- { NULL } },
-};
-#endif /* PC98 */
-#endif /* WITH_SYSCONS */
-
-DMenu MenuUsermgmt = {
- DMENU_NORMAL_TYPE,
- "User and group management",
- "The submenus here allow to manipulate user groups and\n"
- "login accounts.\n",
- "Configure your user groups and users",
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)", NULL, dmenuExit },
- { "User", "Add a new user to the system.", NULL, userAddUser },
- { "Group", "Add a new user group to the system.", NULL, userAddGroup },
- { NULL } },
-};
-
-DMenu MenuSecurity = {
- DMENU_CHECKLIST_TYPE | DMENU_SELECTION_RETURNS,
- "System Security Options Menu",
- "This menu allows you to configure aspects of the operating system security\n"
- "policy. Please read the system documentation carefully before modifying\n"
- "these settings, as they may cause service disruption if used improperly.\n"
- "\n"
- "Most settings will take affect only following a system reboot.",
- "Configure system security options",
- NULL,
- { { "X Exit", "Exit this menu (returning to previous)",
- checkTrue, dmenuExit, NULL, NULL, '<', '<', '<' },
- { " Security Profile", "Select a security profile for the system",
- NULL, configSecurityProfile },
-#if 0
- { " LOMAC", "Use Low Watermark Mandatory Access Control at boot",
- dmenuVarCheck, dmenuToggleVariable, NULL, "lomac_enable=YES" },
-#endif
- { " NFS port", "Require that the NFS clients used reserved ports",
- dmenuVarCheck, dmenuToggleVariable, NULL, "nfs_reserved_port_only=YES" },
- { NULL } },
-};
-
-DMenu MenuSecurityProfile = {
- DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
- "Default system security profile",
- "Each item in this list will set what it considers to\n"
- "be \"appropriate\" values in that category for various\n"
- "security-related knobs in /etc/rc.conf.",
- "Select a canned security profile - F1 for help",
- "security", /* help file */
- { { "X Exit", "Exit this menu (returning to previous)", NULL, dmenuExit },
- { "Medium", "Moderate security settings.", NULL, configSecurityModerate },
- { "Extreme", "Very restrictive security settings.", NULL, configSecurityExtreme },
- { NULL } },
-};
-
-DMenu MenuFixit = {
- DMENU_NORMAL_TYPE,
- "Please choose a fixit option",
- "There are three ways of going into \"fixit\" mode:\n"
- "- you can use the live filesystem CDROM/DVD, in which case there will be\n"
- " full access to the complete set of FreeBSD commands and utilities,\n"
- "- you can use the more limited (but perhaps customized) fixit floppy,\n"
- "- or you can start an Emergency Holographic Shell now, which is\n"
- " limited to the subset of commands that is already available right now.",
- "Press F1 for more detailed repair instructions",
- "fixit",
-{ { "X Exit", "Exit this menu (returning to previous)", NULL, dmenuExit },
- { "2 CDROM/DVD", "Use the \"live\" filesystem CDROM/DVD", NULL, installFixitCDROM },
- { "3 Floppy", "Use a floppy generated from the fixit image", NULL, installFixitFloppy },
- { "4 Shell", "Start an Emergency Holographic Shell", NULL, installFixitHoloShell },
- { NULL } },
-};
diff --git a/usr.sbin/sade/misc.c b/usr.sbin/sade/misc.c
deleted file mode 100644
index 07cbc81751d1..000000000000
--- a/usr.sbin/sade/misc.c
+++ /dev/null
@@ -1,529 +0,0 @@
-/*
- * Miscellaneous support routines..
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-#include <ctype.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/errno.h>
-#include <sys/file.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <sys/wait.h>
-#include <sys/param.h>
-#include <sys/mount.h>
-#include <ufs/ufs/ufsmount.h>
-#include <sys/reboot.h>
-#include <sys/disklabel.h>
-#include <fs/msdosfs/msdosfsmount.h>
-
-/* Quick check to see if a file is readable */
-Boolean
-file_readable(char *fname)
-{
- if (!access(fname, F_OK))
- return TRUE;
- return FALSE;
-}
-
-/* Quick check to see if a file is executable */
-Boolean
-file_executable(char *fname)
-{
- if (!access(fname, X_OK))
- return TRUE;
- return FALSE;
-}
-
-/* Concatenate two strings into static storage */
-char *
-string_concat(char *one, char *two)
-{
- static char tmp[FILENAME_MAX];
-
- /* Yes, we're deliberately cavalier about not checking for overflow */
- strcpy(tmp, one);
- strcat(tmp, two);
- return tmp;
-}
-
-/* sane strncpy() function */
-char *
-sstrncpy(char *dst, const char *src, int size)
-{
- dst[size] = '\0';
- return strncpy(dst, src, size);
-}
-
-/* Concatenate three strings into static storage */
-char *
-string_concat3(char *one, char *two, char *three)
-{
- static char tmp[FILENAME_MAX];
-
- /* Yes, we're deliberately cavalier about not checking for overflow */
- strcpy(tmp, one);
- strcat(tmp, two);
- strcat(tmp, three);
- return tmp;
-}
-
-/* Clip the whitespace off the end of a string */
-char *
-string_prune(char *str)
-{
- int len = str ? strlen(str) : 0;
-
- while (len && isspace(str[len - 1]))
- str[--len] = '\0';
- return str;
-}
-
-/* run the whitespace off the front of a string */
-char *
-string_skipwhite(char *str)
-{
- while (*str && isspace(*str))
- ++str;
- return str;
-}
-
-/* copy optionally and allow second arg to be null */
-char *
-string_copy(char *s1, char *s2)
-{
- if (!s1)
- return NULL;
- if (!s2)
- s1[0] = '\0';
- else
- strcpy(s1, s2);
- return s1;
-}
-
-/* convert an integer to a string, using a static buffer */
-char *
-itoa(int value)
-{
- static char buf[13];
-
- snprintf(buf, 12, "%d", value);
- return buf;
-}
-
-Boolean
-directory_exists(const char *dirname)
-{
- DIR *tptr;
-
- if (!dirname)
- return FALSE;
- if (!strlen(dirname))
- return FALSE;
-
- tptr = opendir(dirname);
- if (!tptr)
- return (FALSE);
-
- closedir(tptr);
- return (TRUE);
-}
-
-char *
-pathBaseName(const char *path)
-{
- char *pt;
- char *ret = (char *)path;
-
- pt = strrchr(path,(int)'/');
-
- if (pt != 0) /* if there is a slash */
- {
- ret = ++pt; /* start the file after it */
- }
-
- return(ret);
-}
-
-/* A free guaranteed to take NULL ptrs */
-void
-safe_free(void *ptr)
-{
- if (ptr)
- free(ptr);
-}
-
-/* A malloc that checks errors */
-void *
-safe_malloc(size_t size)
-{
- void *ptr;
-
- if (size <= 0)
- msgFatal("Invalid malloc size of %ld!", (long)size);
- ptr = malloc(size);
- if (!ptr)
- msgFatal("Out of memory!");
- bzero(ptr, size);
- return ptr;
-}
-
-/* A realloc that checks errors */
-void *
-safe_realloc(void *orig, size_t size)
-{
- void *ptr;
-
- if (size <= 0)
- msgFatal("Invalid realloc size of %ld!", (long)size);
- ptr = reallocf(orig, size);
- if (!ptr)
- msgFatal("Out of memory!");
- return ptr;
-}
-
-/* Create a path biased from the VAR_INSTALL_ROOT variable (if not /) */
-char *
-root_bias(char *path)
-{
- static char tmp[FILENAME_MAX];
- char *cp = variable_get(VAR_INSTALL_ROOT);
-
- if (!strcmp(cp, "/"))
- return path;
- strcpy(tmp, variable_get(VAR_INSTALL_ROOT));
- strcat(tmp, path);
- return tmp;
-}
-
-/*
- * These next routines are kind of specialized just for building item lists
- * for dialog_menu().
- */
-
-/* Add an item to an item list */
-dialogMenuItem *
-item_add(dialogMenuItem *list, char *prompt, char *title,
- int (*checked)(dialogMenuItem *self),
- int (*fire)(dialogMenuItem *self),
- void (*selected)(dialogMenuItem *self, int is_selected),
- void *data, int *aux, int *curr, int *max)
-{
- dialogMenuItem *d;
-
- if (*curr == *max) {
- *max += 20;
- list = (dialogMenuItem *)safe_realloc(list, sizeof(dialogMenuItem) * *max);
- }
- d = &list[(*curr)++];
- bzero(d, sizeof(*d));
- d->prompt = prompt ? strdup(prompt) : NULL;
- d->title = title ? strdup(title) : NULL;
- d->checked = checked;
- d->fire = fire;
- d->selected = selected;
- d->data = data;
- d->aux = (long)aux;
- return list;
-}
-
-/* Toss the items out */
-void
-items_free(dialogMenuItem *list, int *curr, int *max)
-{
- int i;
-
- for (i = 0; list[i].prompt; i++) {
- safe_free(list[i].prompt);
- safe_free(list[i].title);
- }
- safe_free(list);
- *curr = *max = 0;
-}
-
-int
-Mkdir(char *ipath)
-{
- struct stat sb;
- int final;
- char *p, *path;
-
- if (file_readable(ipath) || Fake)
- return DITEM_SUCCESS;
-
- path = strcpy(alloca(strlen(ipath) + 1), ipath);
- if (isDebug())
- msgDebug("mkdir(%s)\n", path);
- p = path;
- if (p[0] == '/') /* Skip leading '/'. */
- ++p;
- for (final = FALSE; !final; ++p) {
- if (p[0] == '\0' || (p[0] == '/' && p[1] == '\0'))
- final = TRUE;
- else if (p[0] != '/')
- continue;
- *p = '\0';
- if (stat(path, &sb)) {
- if (errno != ENOENT) {
- msgConfirm("Couldn't stat directory %s: %s", path, strerror(errno));
- return DITEM_FAILURE;
- }
- if (isDebug())
- msgDebug("mkdir(%s..)\n", path);
- if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
- msgConfirm("Couldn't create directory %s: %s", path,strerror(errno));
- return DITEM_FAILURE;
- }
- }
- *p = '/';
- }
- return DITEM_SUCCESS;
-}
-
-int
-Mkdir_command(char *key, void *dir)
-{
- return (Mkdir((char*)dir));
-}
-
-int
-Mount(char *mountp, void *dev)
-{
- struct ufs_args ufsargs;
- char device[80];
- char mountpoint[FILENAME_MAX];
-
- if (Fake)
- return DITEM_SUCCESS;
-
- if (*((char *)dev) != '/') {
- sprintf(device, "%s/dev/%s", RunningAsInit ? "/mnt" : "", (char *)dev);
- sprintf(mountpoint, "%s%s", RunningAsInit ? "/mnt" : "", mountp);
- }
- else {
- strcpy(device, dev);
- strcpy(mountpoint, mountp);
- }
- memset(&ufsargs,0,sizeof ufsargs);
-
- if (Mkdir(mountpoint)) {
- msgConfirm("Unable to make directory mountpoint for %s!", mountpoint);
- return DITEM_FAILURE;
- }
- if (isDebug())
- msgDebug("mount %s %s\n", device, mountpoint);
-
- ufsargs.fspec = device;
- if (mount("ufs", mountpoint, RunningAsInit ? MNT_ASYNC | MNT_NOATIME : 0,
- (caddr_t)&ufsargs) == -1) {
- msgConfirm("Error mounting %s on %s : %s", device, mountpoint, strerror(errno));
- return DITEM_FAILURE;
- }
- return DITEM_SUCCESS;
-}
-
-int
-Mount_msdosfs(char *mountp, void *dev)
-{
- struct msdosfs_args mount_args;
- char device[80];
- char mountpoint[FILENAME_MAX];
-
- if (Fake)
- return DITEM_SUCCESS;
-
- if (*((char *)dev) != '/') {
- sprintf(device, "%s/dev/%s", RunningAsInit ? "/mnt" : "", (char *)dev);
- sprintf(mountpoint, "%s%s", RunningAsInit ? "/mnt" : "", mountp);
- }
- else {
- strcpy(device, dev);
- strcpy(mountpoint, mountp);
- }
-
- if (Mkdir(mountpoint)) {
- msgConfirm("Unable to make directory mountpoint for %s!", mountpoint);
- return DITEM_FAILURE;
- }
- if (isDebug())
- msgDebug("mount %s %s\n", device, mountpoint);
-
- memset(&mount_args, 0, sizeof(mount_args));
- mount_args.fspec = device;
- mount_args.magic = MSDOSFS_ARGSMAGIC;
- mount_args.mask = S_IRWXU | S_IRWXG | S_IRWXO;
- if (mount("msdosfs", mountpoint, RunningAsInit ? MNT_ASYNC|MNT_NOATIME : 0,
- (caddr_t)&mount_args) == -1) {
- msgConfirm("Error mounting %s on %s : %s", device, mountpoint, strerror(errno));
- return DITEM_FAILURE;
- }
- return DITEM_SUCCESS;
-}
-
-WINDOW *
-openLayoutDialog(char *helpfile, char *title, int x, int y, int width, int height)
-{
- WINDOW *win;
- static char help[FILENAME_MAX];
-
- /* We need a curses window */
- win = newwin(LINES, COLS, 0, 0);
- if (win) {
- /* Say where our help comes from */
- if (helpfile) {
- use_helpline("Press F1 for more information on this screen.");
- use_helpfile(systemHelpFile(helpfile, help));
- }
- /* Setup a nice screen for us to splat stuff onto */
- draw_box(win, y, x, height, width, dialog_attr, border_attr);
- wattrset(win, dialog_attr);
- mvwaddstr(win, y, x + (COLS - strlen(title)) / 2, title);
- }
- return win;
-}
-
-ComposeObj *
-initLayoutDialog(WINDOW *win, Layout *layout, int x, int y, int *max)
-{
- ComposeObj *obj = NULL, *first;
- int n;
-
- /* Loop over the layout list, create the objects, and add them
- onto the chain of objects that dialog uses for traversal*/
-
- n = 0;
- while (layout[n].help != NULL) {
- int t = TYPE_OF_OBJ(layout[n].type);
-
- switch (t) {
- case STRINGOBJ:
- layout[n].obj = NewStringObj(win, layout[n].prompt, layout[n].var,
- layout[n].y + y, layout[n].x + x, layout[n].len, layout[n].maxlen);
- ((StringObj *)layout[n].obj)->attr_mask = ATTR_OF_OBJ(layout[n].type);
- break;
-
- case BUTTONOBJ:
- layout[n].obj = NewButtonObj(win, layout[n].prompt, layout[n].var, layout[n].y + y, layout[n].x + x);
- break;
-
- default:
- msgFatal("Don't support this object yet!");
- }
- AddObj(&obj, t, (void *) layout[n].obj);
- n++;
- }
- *max = n - 1;
- /* Find the first object in the list */
- for (first = obj; first->prev; first = first->prev);
- return first;
-}
-
-int
-layoutDialogLoop(WINDOW *win, Layout *layout, ComposeObj **obj, int *n, int max, int *cbutton, int *cancel)
-{
- char help_line[80];
- int ret, i, len = strlen(layout[*n].help);
-
- /* Display the help line at the bottom of the screen */
- for (i = 0; i < 79; i++)
- help_line[i] = (i < len) ? layout[*n].help[i] : ' ';
- help_line[i] = '\0';
- use_helpline(help_line);
- display_helpline(win, LINES - 1, COLS - 1);
- wrefresh(win);
-
- /* Ask for libdialog to do its stuff */
- ret = PollObj(obj);
- /* Handle special case stuff that libdialog misses. Sigh */
- switch (ret) {
- case SEL_ESC: /* Bail out */
- *cancel = TRUE;
- return FALSE;
-
- /* This doesn't work for list dialogs. Oh well. Perhaps
- should special case the move from the OK button ``up''
- to make it go to the interface list, but then it gets
- awkward for the user to go back and correct screw up's
- in the per-interface section */
- case KEY_DOWN:
- case SEL_CR:
- case SEL_TAB:
- if (*n < max)
- ++*n;
- else
- *n = 0;
- break;
-
- /* The user has pressed enter over a button object */
- case SEL_BUTTON:
- if (cbutton && *cbutton)
- *cancel = TRUE;
- else
- *cancel = FALSE;
- return FALSE;
-
- case KEY_UP:
- case SEL_BACKTAB:
- if (*n)
- --*n;
- else
- *n = max;
- break;
-
- case KEY_F(1):
- display_helpfile();
-
- /* They tried some key combination we don't support - tootle them forcefully! */
- default:
- beep();
- }
- return TRUE;
-}
-
-WINDOW *
-savescr(void)
-{
- WINDOW *w;
-
- w = dupwin(newscr);
- return w;
-}
-
-void
-restorescr(WINDOW *w)
-{
- touchwin(w);
- wrefresh(w);
- delwin(w);
-}
-
diff --git a/usr.sbin/sade/msg.c b/usr.sbin/sade/msg.c
deleted file mode 100644
index 4625ce2f7752..000000000000
--- a/usr.sbin/sade/msg.c
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last program in the `sysinstall' line - the next
- * generation being essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-#include <stdarg.h>
-#include <sys/ioctl.h>
-#include <sys/consio.h>
-
-Boolean
-isDebug(void)
-{
- char *cp;
-
- return (cp = variable_get(VAR_DEBUG)) && strcmp(cp, "no");
-}
-
-/* Whack up an informational message on the status line, in stand-out */
-void
-msgYap(char *fmt, ...)
-{
- va_list args;
- char *errstr;
- int attrs;
-
- errstr = (char *)alloca(FILENAME_MAX);
- va_start(args, fmt);
- vsnprintf(errstr, FILENAME_MAX, fmt, args);
- va_end(args);
- attrs = getattrs(stdscr);
- attrset(A_REVERSE);
- mvaddstr(StatusLine, 0, errstr);
- attrset(attrs);
- refresh();
-}
-
-/* Whack up an informational message on the status line */
-void
-msgInfo(char *fmt, ...)
-{
- va_list args;
- char *errstr;
- int i, attrs;
- char line[81];
-
- attrs = getattrs(stdscr);
- /* NULL is a special convention meaning "erase the old stuff" */
- if (!fmt) {
- move(StatusLine, 0);
- clrtoeol();
- return;
- }
- errstr = (char *)alloca(FILENAME_MAX);
- va_start(args, fmt);
- vsnprintf(errstr, FILENAME_MAX, fmt, args);
- va_end(args);
- memset(line, ' ', 80);
- for (i = 0; i < 80; i++) {
- if (errstr[i])
- line[i] = errstr[i];
- else
- break;
- }
- line[80] = '\0';
- attrset(ATTR_TITLE);
- mvaddstr(StatusLine, 0, line);
- attrset(attrs);
- move(StatusLine, 79);
- refresh();
-}
-
-/* Whack up a warning on the status line */
-void
-msgWarn(char *fmt, ...)
-{
- va_list args;
- char *errstr;
- int attrs;
-
- errstr = (char *)alloca(FILENAME_MAX);
- strcpy(errstr, "Warning: ");
- va_start(args, fmt);
- vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
- va_end(args);
- attrs = getattrs(stdscr);
- beep();
- attrset(ATTR_TITLE);
- mvaddstr(StatusLine, 0, errstr);
- attrset(attrs);
- refresh();
- if (OnVTY && isDebug())
- msgDebug("Warning message `%s'\n", errstr);
-}
-
-/* Whack up an error on the status line */
-void
-msgError(char *fmt, ...)
-{
- va_list args;
- char *errstr;
- int attrs;
-
- errstr = (char *)alloca(FILENAME_MAX);
- strcpy(errstr, "Error: ");
- va_start(args, fmt);
- vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
- va_end(args);
- beep();
- attrs = getattrs(stdscr);
- attrset(ATTR_TITLE);
- mvaddstr(StatusLine, 0, errstr);
- attrset(attrs);
- refresh();
- if (OnVTY && isDebug())
- msgDebug("Error message `%s'\n", errstr);
-}
-
-/* Whack up a fatal error on the status line */
-void
-msgFatal(char *fmt, ...)
-{
- va_list args;
- char *errstr;
- int attrs;
-
- errstr = (char *)alloca(FILENAME_MAX);
- strcpy(errstr, "Fatal Error: ");
- va_start(args, fmt);
- vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
- va_end(args);
- beep();
- attrs = getattrs(stdscr);
- attrset(ATTR_TITLE);
- mvaddstr(StatusLine, 0, errstr);
- addstr(" - ");
- addstr("PRESS ANY KEY TO ");
- if (getpid() == 1)
- addstr("REBOOT");
- else
- addstr("QUIT");
- attrset(attrs);
- refresh();
- if (OnVTY)
- msgDebug("Fatal error `%s'!\n", errstr);
- getch();
- systemShutdown(1);
-}
-
-/* Put up a message in a popup confirmation box */
-void
-msgConfirm(char *fmt, ...)
-{
- va_list args;
- char *errstr;
- WINDOW *w = savescr();
-
- errstr = (char *)alloca(FILENAME_MAX);
- va_start(args, fmt);
- vsnprintf(errstr, FILENAME_MAX, fmt, args);
- va_end(args);
- use_helpline(NULL);
- use_helpfile(NULL);
- if (OnVTY) {
- ioctl(0, VT_ACTIVATE, 1);
- msgInfo(NULL);
- }
- dialog_notify(errstr);
- restorescr(w);
-}
-
-/* Put up a message in a popup information box */
-void
-msgNotify(char *fmt, ...)
-{
- va_list args;
- char *errstr;
-
- errstr = (char *)alloca(FILENAME_MAX);
- va_start(args, fmt);
- vsnprintf(errstr, FILENAME_MAX, fmt, args);
- va_end(args);
- use_helpline(NULL);
- use_helpfile(NULL);
- if (isDebug())
- msgDebug("Notify: %s\n", errstr);
- dialog_msgbox(NULL, errstr, -1, -1, 0);
-}
-
-/* Put up a message in a popup yes/no box and return 0 for YES, 1 for NO */
-int
-msgYesNo(char *fmt, ...)
-{
- va_list args;
- char *errstr;
- int ret;
- WINDOW *w = savescr();
-
- errstr = (char *)alloca(FILENAME_MAX);
- va_start(args, fmt);
- vsnprintf(errstr, FILENAME_MAX, fmt, args);
- va_end(args);
- use_helpline(NULL);
- use_helpfile(NULL);
- if (OnVTY) {
- ioctl(0, VT_ACTIVATE, 1); /* Switch back */
- msgInfo(NULL);
- }
- if (variable_get(VAR_NONINTERACTIVE))
- return 0; /* If non-interactive, return YES all the time */
- ret = dialog_yesno("User Confirmation Requested", errstr, -1, -1);
- restorescr(w);
- return ret;
-}
-
-/* Put up a message in a popup no/yes box and return 0 for YES, 1 for NO */
-int
-msgNoYes(char *fmt, ...)
-{
- va_list args;
- char *errstr;
- int ret;
- WINDOW *w = savescr();
-
- errstr = (char *)alloca(FILENAME_MAX);
- va_start(args, fmt);
- vsnprintf(errstr, FILENAME_MAX, fmt, args);
- va_end(args);
- use_helpline(NULL);
- use_helpfile(NULL);
- if (OnVTY) {
- ioctl(0, VT_ACTIVATE, 1); /* Switch back */
- msgInfo(NULL);
- }
- if (variable_get(VAR_NONINTERACTIVE))
- return 1; /* If non-interactive, return NO all the time */
- ret = dialog_noyes("User Confirmation Requested", errstr, -1, -1);
- restorescr(w);
- return ret;
-}
-
-/* Put up a message in an input box and return the value */
-char *
-msgGetInput(char *buf, char *fmt, ...)
-{
- va_list args;
- char *errstr;
- static char input_buffer[256];
- int rval;
- WINDOW *w = savescr();
-
- errstr = (char *)alloca(FILENAME_MAX);
- va_start(args, fmt);
- vsnprintf(errstr, FILENAME_MAX, fmt, args);
- va_end(args);
- use_helpline(NULL);
- use_helpfile(NULL);
- if (buf)
- SAFE_STRCPY(input_buffer, buf);
- else
- input_buffer[0] = '\0';
- if (OnVTY) {
- ioctl(0, VT_ACTIVATE, 1); /* Switch back */
- msgInfo(NULL);
- }
- rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer);
- restorescr(w);
- if (!rval)
- return input_buffer;
- else
- return NULL;
-}
-
-/* Write something to the debugging port */
-void
-msgDebug(char *fmt, ...)
-{
- va_list args;
- char *dbg;
-
- if (DebugFD == -1)
- return;
- dbg = (char *)alloca(FILENAME_MAX);
- strcpy(dbg, "DEBUG: ");
- va_start(args, fmt);
- vsnprintf((char *)(dbg + strlen(dbg)), FILENAME_MAX, fmt, args);
- va_end(args);
- write(DebugFD, dbg, strlen(dbg));
-}
-
-/* Tell the user there's some output to go look at */
-void
-msgWeHaveOutput(char *fmt, ...)
-{
- va_list args;
- char *errstr;
- WINDOW *w = savescr();
-
- errstr = (char *)alloca(FILENAME_MAX);
- va_start(args, fmt);
- vsnprintf(errstr, FILENAME_MAX, fmt, args);
- va_end(args);
- use_helpline(NULL);
- use_helpfile(NULL);
- msgDebug("Notify: %s\n", errstr);
- dialog_clear_norefresh();
- sleep(2);
- dialog_msgbox(NULL, errstr, -1, -1, 0);
- restorescr(w);
-}
-
-/* Simple versions of msgConfirm() and msgNotify() for calling from scripts */
-int
-msgSimpleConfirm(char *str)
-{
- msgConfirm("%s", str);
- return DITEM_SUCCESS;
-}
-
-int
-msgSimpleNotify(char *str)
-{
- msgNotify("%s", str);
- return DITEM_SUCCESS;
-}
diff --git a/usr.sbin/sade/rtermcap.c b/usr.sbin/sade/rtermcap.c
deleted file mode 100644
index 84b3feb49ead..000000000000
--- a/usr.sbin/sade/rtermcap.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <stdio.h>
-#include <termcap.h>
-
-int
-main(int argc, char **argv)
-{
- char buf[4096];
- int i;
-
- if (argc < 2)
- return 1;
- i = tgetent(buf, argv[1]);
- printf("%s",buf);
- return 0;
-}
diff --git a/usr.sbin/sade/sade.8 b/usr.sbin/sade/sade.8
deleted file mode 100644
index 929a121b092a..000000000000
--- a/usr.sbin/sade/sade.8
+++ /dev/null
@@ -1,1010 +0,0 @@
-.\" Copyright (c) 1997
-.\" Jordan Hubbard <jkh@FreeBSD.org>. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY Jordan Hubbard AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL Jordan Hubbard OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (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$
-.\"
-.Dd August 9, 1997
-.Dt SYSINSTALL 8
-.Os
-.Sh NAME
-.Nm sysinstall
-.Nd system installation and configuration tool
-.Sh SYNOPSIS
-.Nm
-.Op Ar var=value
-.Op Ar function
-.Op Ar ...
-.Sh DESCRIPTION
-The
-.Nm
-utility is used for installing and configuring
-.Fx
-systems.
-It is the first utility invoked by the
-.Fx
-installation boot
-floppy and is also available as
-.Pa /usr/sbin/sysinstall
-on newly installed
-.Fx
-systems for use in later configuring the system.
-.Pp
-The
-.Nm
-utility is generally invoked without arguments for the default
-behavior, where the main installation/configuration menu is presented.
-.Pp
-On those occasions where it is deemed necessary to invoke a subsystem
-of sysinstall directly, however, it is also possible to do so by
-naming the appropriate function entry points on the command line.
-Since this action is essentially identical to running an installation
-script, each command-line argument corresponding to a line of script,
-the reader is encouraged to read the section on scripting for more
-information on this feature.
-.Sh NOTES
-The
-.Nm
-utility is essentially nothing more than a monolithic C program with
-the ability to write MBRs and disk labels (through the services
-of the
-.Xr libdisk 3
-library) and install distributions or packages onto new and
-existing
-.Fx
-systems. It also contains some extra intelligence
-for running as a replacement for
-.Xr init 8
-when it's invoked by the
-.Fx
-installation boot procedure. It
-assumes very little in the way of additional utility support and
-performs most file system operations by calling the relevant syscalls
-(such as
-.Xr mount 2 )
-directly.
-.Pp
-The
-.Nm
-utility currently uses the
-.Xr dialog 3
-library to do user interaction with simple ANSI line graphics, color
-support for which is enabled by either running on a syscons VTY or some
-other color-capable terminal emulator (newer versions of xterm will support
-color when using the
-.Dq xterm-color
-termcap entry).
-.Pp
-This product is currently at the end of its life cycle and will
-eventually be replaced.
-.Sh RUNNING SCRIPTS
-The
-.Nm
-utility may be either driven interactively through its various internal menus
-or run in batch mode, driven by an external script. Such a script may
-be loaded and executed in one of 3 ways:
-.Bl -tag -width Ds
-.It Sy "LOAD_CONFIG_FILE"
-If
-.Nm
-is compiled with LOAD_CONFIG_FILE set in the environment
-(or in the Makefile) to some value, then that value will
-be used as the filename to automatically look for and load
-when
-.Nm
-starts up and with no user interaction required.
-This option is aimed primarily at large sites who wish to create a
-single prototype install for multiple machines with largely identical
-configurations and/or installation options.
-.It Sy "MAIN MENU"
-If
-.Nm
-is run interactively, that is to say in the default manner, it will
-bring up a main menu which contains a "load config file" option.
-Selecting this option will prompt for the name of a script file which
-it then will attempt to load from a DOS or UFS formatted floppy.
-.It Sy "COMMAND LINE"
-Each command line argument is treated as a script directive
-when
-.Nm
-is run in multi-user mode. Execution ends either by explicit request
-(e.g. calling the
-.Ar shutdown
-directive), upon reaching the end of the argument list or on error.
-.Pp
-For example:
-.Bd -literal
-/usr/sbin/sysinstall _ftpPath=ftp://ziggy/pub/ mediaSetFTP configPackages
-.Ed
-.Pp
-Would initialize
-.Nm
-for FTP installation media (using the server `ziggy') and then
-bring up the package installation editor, exiting when finished.
-.El
-.Sh SCRIPT SYNTAX
-A script is a list of one or more directives, each directive taking
-the form of:
-.Pp
-.Ar var=value
-.Pp
-.Ar function
-.Pp
-or
-.Ar #somecomment
-.Pp
-Where
-.Ar var=value
-is the assignment of some internal
-.Nm
-variable, e.g. "ftpPass=FuNkYChiKn", and
-.Ar function
-is the name of an internal
-.Nm
-function, e.g. "mediaSetFTP", and
-.Ar #comment
-is a single-line comment for documentation purposes (ignored by
-sysinstall). Each directive must be by itself on a single line,
-functions taking their arguments by examining known variable names.
-This requires that you be sure to assign the relevant variables before
-calling a function which requires them.
-.Pp
-The
-.Ar noError
-variable can be assigned before each directive: this will cause any error
-detected while processing the directive itself to be ignored.
-The value of
-.Ar noError
-will automatically reset to the default "unassigned" every time a directive is
-processed.
-.Pp
-When and where a function depends on the settings of one or more variables
-will be noted in the following table:
-.Pp
-.Sy "Function Glossary" :
-.Pp
-.Bl -tag -width indent
-.It configAnonFTP
-Invoke the Anonymous FTP configuration menu.
-.Pp
-.Sy Variables :
-None
-.It configRouter
-Select which routing daemon you wish to use, potentially
-loading any required 3rd-party routing daemons as necessary.
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It router
-can be set to the name of the desired routing daemon,
-e.g.\&
-.Dq routed
-or
-.Dq gated ,
-otherwise it is prompted for.
-.El
-.It configNFSServer
-Configure host as an NFS server.
-.Pp
-.Sy Variables :
-None
-.It configNTP
-Configure host as a user of the Network Time Protocol.
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It ntpdate_flags
-The flags to
-.Xr ntpdate 8 ,
-that is to say the name of the server to sync from.
-.El
-.It configPCNFSD
-Configure host to support PC NFS.
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It pcnfsd_pkg
-The name of the PCNFSD package to load if necessary (defaults to hard coded
-version).
-.El
-.It configPackages
-Bring up the interactive package management menu.
-.Pp
-.Sy Variables :
-None
-.It configUsers
-Add users and/or groups to the system.
-.Pp
-.Sy Variables :
-None
-.It configXSetup
-Configure the X display subsystem.
-.Pp
-.Sy Variables :
-None
-.It configXDesktop
-Configure the X desktop.
-.Pp
-.Sy Variables :
-None
-.It diskPartitionEditor
-Invokes the disk partition (MBR) editor.
-.Pp
-.Sy Variables :
-.Bl -tag -width findx
-.It geometry
-The disk geometry, as a cyls/heads/sectors formatted string. Default: no
-change to geometry.
-.It partition
-Set to disk partitioning type or size, its value being
-.Ar free
-in order to use only remaining free space for
-.Fx ,
-.Ar all
-to use the entire disk for
-.Fx
-but maintain a proper partition
-table,
-.Ar existing
-to use an existing
-.Fx
-partition (first found),
-.Ar exclusive
-to use the disk in
-.Dq dangerously dedicated
-mode or, finally,
-.Ar somenumber
-to allocate
-.Ar somenumber
-blocks of available free space to a new
-.Fx
-partition.
-Default: Interactive mode.
-.It bootManager
-is set to one of
-.Ar boot
-to signify the installation of a boot manager,
-.Ar standard
-to signify installation of a "standard" non-boot MGR DOS
-MBR or
-.Ar none
-to indicate that no change to the boot manager is desired.
-Default: none.
-.It diskInteractive
-If set, bring up the interactive disk partition editor.
-.El
-.Pp
-Note: Nothing is actually written to disk by this function, an explicit call to
-.Ar diskPartitionWrite
-being required for that to happen.
-.It diskPartitionWrite
-Causes any pending MBR changes (typically from the
-.Ar diskPartitionEditor
-function) to be written out.
-.Pp
-.Sy Variables :
-None
-.It diskLabelEditor
-Invokes the disk label editor. This is a bit trickier from a script
-since you need to essentially label everything inside each
-.Fx
-(type 0xA5) partition created by the
-.Ar diskPartitionEditor
-function, and that requires knowing a few rules about how things are
-laid out. When creating a script to automatically allocate disk space
-and partition it up, it is suggested that you first perform the
-installation interactively at least once and take careful notes as to
-what the slice names will be, then and only then hardwiring them into
-the script.
-.Pp
-For example, let's say you have a SCSI disk on which you've created a new
-.Fx
-partition in slice 2 (your DOS partition residing in slice 1).
-The slice name would be
-.Ar da0s2
-for the whole
-.Fx
-partition
-.Ar ( da0s1
-being your DOS primary
-partition). Now let's further assume that you have 500MB in this
-partition and you want to sub-partition that space into root, swap,
-var and usr file systems for
-.Fx .
-Your invocation of the
-.Ar diskLabelEditor
-function might involve setting the following variables:
-.Bl -tag -width findx
-.It Li "da0s2-1=ufs 40960 /"
-A 20MB root file system (all sizes are in 512 byte blocks).
-.It Li "da0s2-2=swap 131072 /"
-A 64MB swap partition.
-.It Li "da0s2-3=ufs 204800 /var"
-A 100MB /var file system.
-.It Li "da0s2-4=ufs 0 /usr 1"
-With the balance of free space (around 316MB) going to the /usr
-file system and with soft-updates enabled (the argument following
-the mount point, if non-zero, means to set the soft updates flag).
-.El
-.Pp
-One can also use the
-.Ar diskLabelEditor
-for mounting or erasing existing partitions as well as creating new
-ones. Using the previous example again, let's say that we also wanted
-to mount our DOS partition and make sure that an
-.Pa /etc/fstab
-entry is created for it in the new installation. Before calling the
-.Ar diskLabelEditor
-function, we simply add an additional line:
-.Pp
-.Dl "da0s1=/dos_c N"
-.Pp
-before the call. This tells the label editor that you want to mount
-the first slice on
-.Pa /dos_c
-and not to attempt to newfs it (not that
-.Nm
-would attempt this for a DOS partition in any case, but it could just
-as easily be an existing UFS partition being named here and the 2nd
-field is non-optional).
-.Pp
-You can also set the
-.Ar diskInteractive
-variable to request that the disk label editor use an interactive dialog
-to partition the disk instead of using variables to explicitly layout the
-disk as described above.
-.Pp
-Note: No file system data is actually written to disk until an
-explicit call to
-.Ar diskLabelCommit
-is made.
-.It diskLabelCommit
-Writes out all pending disklabel information and creates and/or mounts any
-file systems which have requests pending from the
-.Ar diskLabelEditor
-function.
-.Pp
-.Sy Variables :
-None
-.It distReset
-Resets all selected distributions to the empty set (no distributions selected).
-.Pp
-.Sy Variables :
-None
-.It distSetCustom
-Allows the selection of a custom distribution set (e.g. not just one of the
-existing "canned" sets) with no user interaction.
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It dists
-List of distributions to load. Possible distribution values are:
-.Bl -tag -width indentxx
-.It Li bin
-The base binary distribution.
-.It Li doc
-Miscellaneous documentation
-.It Li games
-Games
-.It Li manpages
-Manual pages (unformatted)
-.It Li catpages
-Pre-formatted manual pages
-.It Li proflibs
-Profiled libraries for developers.
-.It Li dict
-Dictionary information (for tools like spell).
-.It Li info
-GNU info files and other extra docs.
-.It Li crypto
-Encryption binaries and libraries.
-.It Li compat1x
-Compatibility with
-.Fx
-1.x
-.It Li compat20
-Compatibility with
-.Fx 2.0
-.It Li compat21
-Compatibility with
-.Fx 2.1
-.It Li compat22
-.Fx 2.2
-and
-.Fx 3.0
-a.out binary compatibility
-.It Li compat3x
-Compatibility with
-.Fx
-3.x
-(available for
-.Fx 4.0
-systems only)
-.It Li compat4x
-Compatibility with
-.Fx
-4.x
-(available for
-.Fx 5.0
-systems only)
-.It Li ports
-The ports collection.
-.It Li ssecure
-/usr/src/secure
-.It Li sbase
-/usr/src/[top level files]
-.It Li scontrib
-/usr/src/contrib
-.It Li sgnu
-/usr/src/gnu
-.It Li setc
-/usr/src/etc
-.It Li sgames
-/usr/src/games
-.It Li sinclude
-/usr/src/include
-.It Li skrb5
-/usr/src/kerberos5
-.It Li slib
-/usr/src/lib
-.It Li slibexec
-/usr/src/libexec
-.It Li srelease
-/usr/src/release
-.It Li sbin
-/usr/src/bin
-.It Li ssbin
-/usr/src/sbin
-.It Li sshare
-/usr/src/share
-.It Li ssys
-/usr/src/sys
-.It Li subin
-/usr/src/usr.bin
-.It Li susbin
-/usr/src/usr.sbin
-.It Li ssmailcf
-/usr/src/usr.sbin/sendmail/cf
-.It Li XF86-xc
-XFree86 official sources.
-.It Li XF86-co
-XFree86 contributed sources.
-.It Li Xbin
-XFree86 binaries.
-.It Li Xcfg
-XFree86 configuration files.
-.It Li Xdoc
-XFree86 documentation.
-.It Li Xhtml
-XFree86 HTML documentation.
-.It Li Xlib
-XFree86 libraries.
-.It Li Xlk98
-XFree86 server link-kit for PC98 machines.
-.It Li Xlkit
-XFree86 server link-kit for standard machines.
-.It Li Xman
-XFree86 manual pages.
-.It Li Xprog
-XFree86 programmer's distribution.
-.It Li Xps
-XFree86 postscript documentation.
-.It Li Xset
-XFree86 graphical setup tool.
-.It Li PC98-Servers/X9480
-XFree86 PC98 8-bit (256 color) PEGC-480 server.
-.It Li PC98-Servers/X9EGC
-XFree86 PC98 4-bit (16 color) EGC server.
-.It Li PC98-Servers/X9GA9
-XFree86 PC98 GA-968V4/PCI (S3 968) server.
-.It Li PC98-Servers/X9GAN
-XFree86 PC98 GANB-WAP (cirrus) server.
-.It Li PC98-Servers/X9LPW
-XFree86 PC98 PowerWindowLB (S3) server.
-.It Li PC98-Servers/X9MGA
-[DESCRIPTION MISSING]
-.It Li PC98-Servers/X9NKV
-XFree86 PC98 NKV-NEC (cirrus) server.
-.It Li PC98-Servers/X9NS3
-XFree86 PC98 NEC (S3) server.
-.It Li PC98-Servers/X9SPW
-XFree86 PC98 SKB-PowerWindow (S3) server.
-.It Li PC98-Servers/X9SVG
-[DESCRIPTION MISSING]
-.It Li PC98-Servers/X9TGU
-XFree86 PC98 Cyber9320 and TGUI9680 server.
-.It Li PC98-Servers/X9WEP
-XFree86 PC98 WAB-EP (cirrus) server.
-.It Li PC98-Servers/X9WS
-XFree86 PC98 WABS (cirrus) server.
-.It Li PC98-Servers/X9WSN
-XFree86 PC98 WSN-A2F (cirrus) server.
-.It Li Servers/X3DL
-XFree86 3D Labs server.
-.It Li Servers/X8514
-XFree86 8514 server.
-.It Li Servers/XAGX
-XFree86 8 bit AGX server.
-.It Li Servers/XI128
-XFree86 #9 Imagine I128 server.
-.It Li Servers/XMa8
-XFree86 ATI Mach8 server.
-.It Li Servers/XMa32
-XFree86 ATI Mach32 server.
-.It Li Servers/XMa64
-XFree86 ATI Mach64 server.
-.It Li Servers/XMono
-XFree86 monochrome server.
-.It Li Servers/XP9K
-XFree86 P9000 server.
-.It Li Servers/XS3
-XFree86 S3 server.
-.It Li Servers/XS3V
-XFree86 S3 Virge server.
-.It Li Servers/XSVGA
-XFree86 SVGA server.
-.It Li Servers/XVG16
-XFree86 VGA16 server.
-.It Li Servers/XW32
-XFree86 ET4000/W32, /W32i and /W32p server.
-.It Li Servers/XTGA
-Server for TGA cards (alpha architecture only).
-.It Li Servers/Xnest
-XFree86 nested X server.
-.It Li Servers/Xvfb
-XFree86 virtual frame-buffer X server.
-.It Li Xfnts
-XFree86 base font set.
-.It Li Xf100
-XFree86 100DPI font set.
-.It Li Xfcyr
-XFree86 Cyrillic font set.
-.It Li Xfscl
-XFree86 scalable font set.
-.It Li Xfnon
-XFree86 non-english font set.
-.It Li Xfsrv
-XFree86 font server.
-.El
-.El
-.It distSetDeveloper
-Selects the standard Developer's distribution set.
-.Pp
-.Sy Variables :
-None
-.It distSetXDeveloper
-Selects the standard X Developer's distribution set.
-.Pp
-.Sy Variables :
-None
-.It distSetKernDeveloper
-Selects the standard kernel Developer's distribution set.
-.Pp
-.Sy Variables :
-None
-.It distSetUser
-Selects the standard user distribution set.
-.Pp
-.Sy Variables :
-None
-.It distSetXUser
-Selects the standard X user's distribution set.
-.Pp
-.Sy Variables :
-None
-.It distSetMinimum
-Selects the very minimum distribution set.
-.Pp
-.Sy Variables :
-None
-.It distSetEverything
-Selects the full whack - all available distributions.
-.Pp
-.Sy Variables :
-None
-.It distSetCRYPTO
-Interactively select encryption subcomponents.
-.Pp
-.Sy Variables :
-None
-.It distSetSrc
-Interactively select source subcomponents.
-.Pp
-.Sy Variables :
-None
-.It distSetXF86
-Interactively select XFree86 subcomponents.
-.Pp
-.Sy Variables :
-None
-.It distExtractAll
-Install all currently selected distributions (requires that
-media device also be selected).
-.Pp
-.Sy Variables :
-None
-.It docBrowser
-Install (if necessary) an HTML documentation browser and go to the
-HTML documentation submenu.
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It browserPackage
-The name of the browser package to try and install as necessary.
-Defaults to latest links package.
-.It browserBinary
-The name of the browser binary itself (if overriding the
-.Ar browserPackage
-variable). Defaults to links.
-.El
-.It installCommit
-Commit any and all pending changes to disk. This function
-is essentially shorthand for a number of more granular "commit"
-functions.
-.Pp
-.Sy Variables :
-None
-.It installExpress
-Start an "express" installation, asking few questions of
-the user.
-.Pp
-.Sy Variables :
-None
-.It installStandard
-Start a "standard" installation, the most user-friendly
-installation type available.
-.Pp
-.Sy Variables :
-None
-.It installUpgrade
-Start an upgrade installation.
-.Pp
-.Sy Variables :
-None
-.It installFixitHoloShell
-Start up the "emergency holographic shell" over on VTY4
-if running as init. This will also happen automatically
-as part of the installation process unless
-.Ar noHoloShell
-is set.
-.Pp
-.Sy Variables :
-None
-.It installFixitCDROM
-Go into "fixit" mode, assuming a live file system CDROM
-currently in the drive.
-.Pp
-.Sy Variables :
-None
-.It installFixitFloppy
-Go into "fixit" mode, assuming an available fixit floppy
-disk (user will be prompted for it).
-.Pp
-.Sy Variables :
-None
-.It installFilesystems
-Do just the file system initialization part of an install.
-.Pp
-.Sy Variables :
-None
-.It installVarDefaults
-Initialize all variables to their defaults, overriding any
-previous settings.
-.Pp
-.Sy Variables :
-None
-.It loadConfig
-Sort of like an #include statement, it allows you to load one
-configuration file from another.
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It configFile
-The fully qualified pathname of the file to load.
-.El
-.It mediaClose
-If a media device is open, close it.
-.Pp
-.Sy Variables :
-None
-.It mediaSetCDROM
-Select a
-.Fx
-CDROM as the installation media.
-.Pp
-.Sy Variables :
-None
-.It mediaSetFloppy
-Select a pre-made floppy installation set as the installation media.
-.Pp
-.Sy Variables :
-None
-.It mediaSetDOS
-Select an existing DOS primary partition as the installation media.
-The first primary partition found is used (e.g. C:).
-.Pp
-.Sy Variables :
-None
-.It mediaSetTape
-Select a tape device as the installation media.
-.Pp
-.Sy Variables :
-None
-.It mediaSetFTP
-Select an FTP site as the installation media.
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It hostname
-The name of the host being installed (non-optional).
-.It domainname
-The domain name of the host being installed (optional).
-.It defaultrouter
-The default router for this host (non-optional).
-.It netDev
-Which host interface to use
-.Ar ( ed0
-or
-.Ar ep0 ,
-for example. Non-optional).
-.It netInteractive
-If set, bring up the interactive network setup form even
-if all relevant configuration variables are already set (optional).
-.It ipaddr
-The IP address for the selected host interface (non-optional).
-.It netmask
-The netmask for the selected host interface (non-optional).
-.It _ftpPath
-The fully qualified URL of the FTP site containing the
-.Fx
-distribution you're interested in, e.g.\&
-.Ar ftp://ftp.FreeBSD.org/pub/FreeBSD/ .
-.El
-.It mediaSetFTPActive
-Alias for
-.Ar mediaSetFTP
-using "active" FTP transfer mode.
-.Pp
-.Sy Variables :
-Same as for
-.Ar mediaSetFTP .
-.It mediaSetFTPPassive
-Alias for
-.Ar mediaSetFTP
-using "passive" FTP transfer mode.
-.Pp
-.Sy Variables :
-Same as for
-.Ar mediaSetFTP .
-.It mediaSetHTTP
-Alias for
-.Ar mediaSetFTP
-using an HTTP proxy.
-.Pp
-.Sy Variables :
-See
-.Ar mediaSetFTP ,
-plus
-.Bl -tag -width indent
-.It _httpPath
-The proxy to use (host:port) (non-optional).
-.El
-.It mediaSetUFS
-Select an existing UFS partition (mounted with the label editor) as
-the installation media.
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It ufs
-full /path to directory containing the
-.Fx
-distribution you're
-interested in.
-.El
-.It mediaSetNFS
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It hostname
-The name of the host being installed (non-optional).
-.It domainname
-The domain name of the host being installed (optional).
-.It defaultrouter
-The default router for this host (non-optional).
-.It netDev
-Which host interface to use
-.Ar ( ed0
-or
-.Ar ep0 ,
-for example. Non-optional).
-.It netInteractive
-If set, bring up the interactive network setup form even
-if all relevant configuration variables are already set (optional).
-.It ipaddr
-The IP address for the selected host interface (non-optional).
-.It netmask
-The netmask for the selected host interface (non-optional).
-.It nfs
-full hostname:/path specification for directory containing
-the
-.Fx
-distribution you're interested in.
-.El
-.It mediaSetFTPUserPass
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It ftpUser
-The username to log in as on the ftp server site.
-Default: ftp
-.It ftpPass
-The password to use for this username on the ftp
-server site.
-Default: user@host
-.El
-.It mediaSetCPIOVerbosity
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It cpioVerbose
-Can be used to set the verbosity of cpio extractions to low, medium or
-high.
-.El
-.It mediaGetType
-Interactively get the user to specify some type of media.
-.Pp
-.Sy Variables :
-None
-.It optionsEditor
-Invoke the interactive options editor.
-.Pp
-.Sy Variables :
-None
-.It packageAdd
-Try to fetch and add a package to the system (requires
-that a media type be set),
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It package
-The name of the package to add, e.g. bash-1.14.7 or ncftp-2.4.2.
-.El
-.It addGroup
-Invoke the interactive group editor.
-.Pp
-.Sy Variables :
-None
-.It addUser
-Invoke the interactive user editor.
-.Pp
-.Sy Variables :
-None
-.It shutdown
-Stop the script and terminate sysinstall.
-.Pp
-.Sy Variables :
-None
-.It system
-Execute an arbitrary command with
-.Xr system 3
-.Pp
-.Sy Variables :
-.Bl -tag -width indent
-.It command
-The name of the command to execute. When running
-from a boot floppy, very minimal expectations should
-be made as to what's available until/unless a relatively
-full system installation has just been done.
-.El
-.It tcpMenuSelect
-Configure a network device.
-.Pp
-.Sy Variables :
-Same as for
-.Ar mediaSetFTP
-except that
-.Ar _ftpPath
-is not used.
-.El
-.Sh DISTRIBUTION MEDIA
-The following files can be used to affect the operation of
-.Nm
-when used during initial system installation.
-.Bl -tag -width ".Pa packages/INDEX"
-.It Pa cdrom.inf
-A text file of properties, listed one per line, that describe the
-contents of the media in use.
-The syntax for each line is simply
-.Dq Ar property No = Ar value .
-Currently, only the following properties are recognized.
-.Bl -tag -width ".Va CD_MACHINE_ARCH"
-.It Va CD_VERSION
-This property should be set to the
-.Fx
-version on the current
-media volume.
-For example,
-.Dq Li "CD_VERSION = 4.6" .
-.It Va CD_MACHINE_ARCH
-This property should be set to the architecture of the contents on
-this volume.
-This property is normally only used with
-.Fx
-products that contain
-CDs for different architectures, to provide better error messages if
-users try to install Alpha packages on an i386 machine.
-For example,
-.Dq Li "CD_MACHINE_ARCH = alpha" .
-.It Va VOLUME
-In a multi-volume collection (such as the
-.Fx
-4-CD set), the
-.Pa ports/INDEX
-file on each disc should contain the full package index for the set.
-The last field of the
-.Pa INDEX
-file denotes which volume the package
-appears on, and the
-.Va VOLUME
-property here defines the volume ID of the current disc.
-.El
-.It Pa packages/INDEX
-The package index file.
-Each package is listed on a separate line with additional meta-data
-such as the required dependencies.
-This index is generated by
-.Dq Li "make index"
-from the
-.Xr ports 7
-collection.
-When multi-volume support is enabled, an additional field should be
-added to each line indicating which media volume contains the given
-package.
-.El
-.Pp
-For information about building a full release of
-.Fx ,
-please see
-.Xr release 7 .
-.Sh FILES
-This utility may edit the contents of
-.Pa /etc/rc.conf ,
-.Pa /etc/hosts ,
-and
-.Pa /etc/resolv.conf
-as necessary to reflect changes in the network configuration.
-.Sh SEE ALSO
-If you have a reasonably complete source tree online, take
-a look at
-.Pa /usr/src/usr.sbin/sysinstall/install.cfg
-for a sample installation script.
-.Sh BUGS
-This utility is a prototype which lasted several years past
-its expiration date and is greatly in need of death.
-.Sh AUTHORS
-.An Jordan K. Hubbard Aq jkh@FreeBSD.org
-.Sh HISTORY
-This version of
-.Nm
-first appeared in
-.Fx 2.0 .
diff --git a/usr.sbin/sade/sade.h b/usr.sbin/sade/sade.h
deleted file mode 100644
index b2b5d2109f98..000000000000
--- a/usr.sbin/sade/sade.h
+++ /dev/null
@@ -1,881 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last attempt in the `sysinstall' line, the next
- * generation being slated to essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-#ifndef _SYSINSTALL_H_INCLUDE
-#define _SYSINSTALL_H_INCLUDE
-
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <setjmp.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <dialog.h>
-#include "ui_objects.h"
-#include "dir.h"
-#include "colors.h"
-#include "libdisk.h"
-#include "dist.h"
-
-/*** Defines ***/
-
-#if defined(__i386__) || defined(__alpha__) || defined(__ia64__) || defined(__amd64__)
-#define WITH_SYSCONS
-#define WITH_MICE
-#endif
-
-#if defined(__i386__) || defined(__ia64__) || defined(__amd64__)
-#define WITH_SLICES
-#endif
-
-#if defined(__i386__) || defined(__alpha__)
-#define WITH_LINUX
-#endif
-
-#if defined(PC98)
-#define PCCARD_ARCH 1 /* Support PCCARD installations */
-#endif
-
-/* device limits */
-#define DEV_NAME_MAX 128 /* The maximum length of a device name */
-#define DEV_MAX 100 /* The maximum number of devices we'll deal with */
-#define INTERFACE_MAX 50 /* Maximum number of network interfaces we'll deal with */
-#define IO_ERROR -2 /* Status code for I/O error rather than normal EOF */
-
-/* Number of seconds to wait for data to come off even the slowest media */
-#define MEDIA_TIMEOUT 300
-
-/*
- * I make some pretty gross assumptions about having a max of 50 chunks
- * total - 8 slices and 42 partitions. I can't easily display many more
- * than that on the screen at once!
- *
- * For 2.1 I'll revisit this and try to make it more dynamic, but since
- * this will catch 99.99% of all possible cases, I'm not too worried.
- */
-#define MAX_CHUNKS 40
-
-/* Internal environment variable names */
-#define DISK_PARTITIONED "_diskPartitioned"
-#define DISK_LABELLED "_diskLabelled"
-#define DISK_SELECTED "_diskSelected"
-#define SYSTEM_STATE "_systemState"
-#define RUNNING_ON_ROOT "_runningOnRoot"
-#define TCP_CONFIGURED "_tcpConfigured"
-
-/* Ones that can be tweaked from config files */
-#define VAR_BLANKTIME "blanktime"
-#define VAR_BOOTMGR "bootManager"
-#define VAR_BROWSER_BINARY "browserBinary"
-#define VAR_BROWSER_PACKAGE "browserPackage"
-#define VAR_CPIO_VERBOSITY "cpioVerbose"
-#define VAR_DEBUG "debug"
-#define VAR_DESKSTYLE "_deskStyle"
-#define VAR_DISK "disk"
-#define VAR_DISKINTERACTIVE "diskInteractive"
-#define VAR_DISTS "dists"
-#define VAR_DIST_MAIN "distMain"
-#define VAR_DIST_CRYPTO "distCRYPTO"
-#define VAR_DIST_SRC "distSRC"
-#define VAR_DIST_X11 "distX11"
-#define VAR_DIST_XSERVER "distXserver"
-#define VAR_DIST_XFONTS "distXfonts"
-#define VAR_DEDICATE_DISK "dedicateDisk"
-#define VAR_DOMAINNAME "domainname"
-#define VAR_EDITOR "editor"
-#define VAR_EXTRAS "ifconfig_"
-#define VAR_COMMAND "command"
-#define VAR_CONFIG_FILE "configFile"
-#define VAR_FIXIT_TTY "fixitTty"
-#define VAR_FTP_DIR "ftpDirectory"
-#define VAR_FTP_PASS "ftpPass"
-#define VAR_FTP_PATH "_ftpPath"
-#define VAR_FTP_PORT "ftpPort"
-#define VAR_FTP_STATE "ftpState"
-#define VAR_FTP_USER "ftpUser"
-#define VAR_FTP_HOST "ftpHost"
-#define VAR_HTTP_PATH "_httpPath"
-#define VAR_HTTP_PROXY "httpProxy"
-#define VAR_HTTP_PORT "httpPort"
-#define VAR_HTTP_HOST "httpHost"
-#define VAR_HTTP_FTP_MODE "httpFtpMode"
-#define VAR_GATEWAY "defaultrouter"
-#define VAR_GEOMETRY "geometry"
-#define VAR_HOSTNAME "hostname"
-#define VAR_IFCONFIG "ifconfig_"
-#define VAR_INSTALL_CFG "installConfig"
-#define VAR_INSTALL_ROOT "installRoot"
-#define VAR_IPADDR "ipaddr"
-#define VAR_IPV6_ENABLE "ipv6_enable"
-#define VAR_IPV6ADDR "ipv6addr"
-#define VAR_KEYMAP "keymap"
-#define VAR_LABEL "label"
-#define VAR_LABEL_COUNT "labelCount"
-#define VAR_LINUX_ENABLE "linux_enable"
-#define VAR_MEDIA_TYPE "mediaType"
-#define VAR_MEDIA_TIMEOUT "MEDIA_TIMEOUT"
-#define VAR_MOUSED "moused_enable"
-#define VAR_MOUSED_FLAGS "moused_flags"
-#define VAR_MOUSED_PORT "moused_port"
-#define VAR_MOUSED_TYPE "moused_type"
-#define VAR_NAMESERVER "nameserver"
-#define VAR_NETINTERACTIVE "netInteractive"
-#define VAR_NETMASK "netmask"
-#define VAR_NETWORK_DEVICE "netDev"
-#define VAR_NEWFS_ARGS "newfsArgs"
-#define VAR_NFS_PATH "nfs"
-#define VAR_NFS_HOST "nfsHost"
-#define VAR_NFS_SECURE "nfs_reserved_port_only"
-#define VAR_NFS_SERVER "nfs_server_enable"
-#define VAR_NO_CONFIRM "noConfirm"
-#define VAR_NO_ERROR "noError"
-#define VAR_NO_HOLOSHELL "noHoloShell"
-#define VAR_NO_INET6 "noInet6"
-#define VAR_NO_WARN "noWarn"
-#define VAR_NO_USR "noUsr"
-#define VAR_NO_TMP "noTmp"
-#define VAR_NO_HOME "noHome"
-#define VAR_NONINTERACTIVE "nonInteractive"
-#define VAR_NOVELL "novell"
-#define VAR_OSF1_ENABLE "osf1_enable"
-#define VAR_RPCBIND_ENABLE "rpcbind_enable"
-#define VAR_NTPDATE_FLAGS "ntpdate_flags"
-#define VAR_PACKAGE "package"
-#define VAR_PARTITION "partition"
-#define VAR_PCNFSD "pcnfsd"
-#define VAR_PKG_TMPDIR "PKG_TMPDIR"
-#define VAR_PORTS_PATH "ports"
-#define VAR_PPP_ENABLE "ppp_enable"
-#define VAR_PPP_PROFILE "ppp_profile"
-#define VAR_RELNAME "releaseName"
-#define VAR_ROOT_SIZE "rootSize"
-#define VAR_ROUTER "router"
-#define VAR_ROUTER_ENABLE "router_enable"
-#define VAR_ROUTERFLAGS "router_flags"
-#define VAR_SERIAL_SPEED "serialSpeed"
-#define VAR_SLOW_ETHER "slowEthernetCard"
-#define VAR_SWAP_SIZE "swapSize"
-#define VAR_TAPE_BLOCKSIZE "tapeBlocksize"
-#define VAR_TRY_DHCP "tryDHCP"
-#define VAR_TRY_RTSOL "tryRTSOL"
-#define VAR_UFS_PATH "ufs"
-#define VAR_USR_SIZE "usrSize"
-#define VAR_VAR_SIZE "varSize"
-#define VAR_TMP_SIZE "tmpSize"
-#define VAR_HOME_SIZE "homeSize"
-#define VAR_XF86_CONFIG "_xf86config"
-#define VAR_TERM "TERM"
-#define VAR_CONSTERM "_consterm"
-
-#define DEFAULT_TAPE_BLOCKSIZE "20"
-
-/* One MB worth of blocks */
-#define ONE_MEG 2048
-#define ONE_GIG (ONE_MEG * 1024)
-
-/* Which selection attributes to use */
-#define ATTR_SELECTED (ColorDisplay ? item_selected_attr : item_attr)
-#define ATTR_TITLE button_active_attr
-
-/* Handy strncpy() macro */
-#define SAFE_STRCPY(to, from) sstrncpy((to), (from), sizeof (to) - 1)
-
-/*** Types ***/
-typedef int Boolean;
-typedef struct disk Disk;
-typedef struct chunk Chunk;
-
-/* Bitfields for menu options */
-#define DMENU_NORMAL_TYPE 0x1 /* Normal dialog menu */
-#define DMENU_RADIO_TYPE 0x2 /* Radio dialog menu */
-#define DMENU_CHECKLIST_TYPE 0x4 /* Multiple choice menu */
-#define DMENU_SELECTION_RETURNS 0x8 /* Immediate return on item selection */
-
-typedef struct _dmenu {
- int type; /* What sort of menu we are */
- char *title; /* Our title */
- char *prompt; /* Our prompt */
- char *helpline; /* Line of help at bottom */
- char *helpfile; /* Help file for "F1" */
-#if (__STDC_VERSION__ >= 199901L) || (__GNUC__ >= 3)
- dialogMenuItem items[]; /* Array of menu items */
-#elif __GNUC__
- dialogMenuItem items[0]; /* Array of menu items */
-#else
-#error "Create hack for C89 and K&R compilers."
-#endif
-} DMenu;
-
-/* An rc.conf variable */
-typedef struct _variable {
- struct _variable *next;
- char *name;
- char *value;
- int dirty;
-} Variable;
-
-#define NO_ECHO_OBJ(type) ((type) | (DITEM_NO_ECHO << 16))
-#define TYPE_OF_OBJ(type) ((type) & 0xff)
-#define ATTR_OF_OBJ(type) ((type) >> 16)
-
-/* A screen layout structure */
-typedef struct _layout {
- int y; /* x & Y co-ordinates */
- int x;
- int len; /* The size of the dialog on the screen */
- int maxlen; /* How much the user can type in ... */
- char *prompt; /* The string for the prompt */
- char *help; /* The display for the help line */
- void *var; /* The var to set when this changes */
- int type; /* The type of the dialog to create */
- void *obj; /* The obj pointer returned by libdialog */
-} Layout;
-
-typedef enum {
- DEVICE_TYPE_NONE,
- DEVICE_TYPE_DISK,
- DEVICE_TYPE_FLOPPY,
- DEVICE_TYPE_FTP,
- DEVICE_TYPE_NETWORK,
- DEVICE_TYPE_CDROM,
- DEVICE_TYPE_TAPE,
- DEVICE_TYPE_DOS,
- DEVICE_TYPE_UFS,
- DEVICE_TYPE_NFS,
- DEVICE_TYPE_ANY,
- DEVICE_TYPE_HTTP,
-} DeviceType;
-
-/* CDROM mount codes */
-#define CD_UNMOUNTED 0
-#define CD_ALREADY_MOUNTED 1
-#define CD_WE_MOUNTED_IT 2
-
-/* A "device" from sysinstall's point of view */
-typedef struct _device {
- char name[DEV_NAME_MAX];
- char *description;
- char *devname;
- DeviceType type;
- Boolean enabled;
- Boolean (*init)(struct _device *dev);
- FILE * (*get)(struct _device *dev, char *file, Boolean probe);
- void (*shutdown)(struct _device *dev);
- void *private;
- unsigned int flags;
- unsigned int volume;
-} Device;
-
-/* Some internal representations of partitions */
-typedef enum {
- PART_NONE,
- PART_SLICE,
- PART_SWAP,
- PART_FILESYSTEM,
- PART_FAT,
-} PartType;
-
-#define NEWFS_UFS_CMD "newfs"
-#define NEWFS_MSDOS_CMD "newfs_msdos"
-
-enum newfs_type { NEWFS_UFS, NEWFS_MSDOS, NEWFS_CUSTOM };
-#define NEWFS_UFS_STRING "UFS"
-#define NEWFS_MSDOS_STRING "FAT"
-#define NEWFS_CUSTOM_STRING "CST"
-
-/* The longest set of custom command line arguments we'll pass. */
-#define NEWFS_CMD_ARGS_MAX 256
-
-typedef struct _part_info {
- char mountpoint[FILENAME_MAX];
-
- /* Is invocation of newfs desired? */
- Boolean do_newfs;
-
- enum newfs_type newfs_type;
- union {
- struct {
- char user_options[NEWFS_CMD_ARGS_MAX];
- Boolean acls; /* unused */
- Boolean multilabel; /* unused */
- Boolean softupdates;
- Boolean ufs1;
- } newfs_ufs;
- struct {
- /* unused */
- } newfs_msdos;
- struct {
- char command[NEWFS_CMD_ARGS_MAX];
- } newfs_custom;
- } newfs_data;
-} PartInfo;
-
-/* An option */
-typedef struct _opt {
- char *name;
- char *desc;
- enum { OPT_IS_STRING, OPT_IS_INT, OPT_IS_FUNC, OPT_IS_VAR } type;
- void *data;
- void *aux;
- char *(*check)();
-} Option;
-
-/* Weird index nodey things we use for keeping track of package information */
-typedef enum { PACKAGE, PLACE } node_type; /* Types of nodes */
-
-typedef struct _pkgnode { /* A node in the reconstructed hierarchy */
- struct _pkgnode *next; /* My next sibling */
- node_type type; /* What am I? */
- char *name; /* My name */
- char *desc; /* My description (Hook) */
- struct _pkgnode *kids; /* My little children */
- void *data; /* A place to hang my data */
-} PkgNode;
-typedef PkgNode *PkgNodePtr;
-
-/* A single package */
-typedef struct _indexEntry { /* A single entry in an INDEX file */
- char *name; /* name */
- char *path; /* full path to port */
- char *prefix; /* port prefix */
- char *comment; /* one line description */
- char *descrfile; /* path to description file */
- char *deps; /* packages this depends on */
- int depc; /* how many depend on me */
- int installed; /* indicates if it is installed */
- char *maintainer; /* maintainer */
- unsigned int volume; /* Volume of package */
-} IndexEntry;
-typedef IndexEntry *IndexEntryPtr;
-
-typedef int (*commandFunc)(char *key, void *data);
-
-#define HOSTNAME_FIELD_LEN 128
-#define IPADDR_FIELD_LEN 16
-#define EXTRAS_FIELD_LEN 128
-
-/* This is the structure that Network devices carry around in their private, erm, structures */
-typedef struct _devPriv {
- int use_rtsol;
- int use_dhcp;
- char ipaddr[IPADDR_FIELD_LEN];
- char netmask[IPADDR_FIELD_LEN];
- char extras[EXTRAS_FIELD_LEN];
-} DevInfo;
-
-
-/*** Externs ***/
-extern jmp_buf BailOut; /* Used to get the heck out */
-extern int DebugFD; /* Where diagnostic output goes */
-extern Boolean Fake; /* Don't actually modify anything - testing */
-extern Boolean Restarting; /* Are we restarting sysinstall? */
-extern Boolean SystemWasInstalled; /* Did we install it? */
-extern Boolean RunningAsInit; /* Are we running stand-alone? */
-extern Boolean DialogActive; /* Is the dialog() stuff up? */
-extern Boolean ColorDisplay; /* Are we on a color display? */
-extern Boolean OnVTY; /* On a syscons VTY? */
-extern Variable *VarHead; /* The head of the variable chain */
-extern Device *mediaDevice; /* Where we're getting our distribution from */
-extern unsigned int Dists; /* Which distributions we want */
-extern unsigned int CRYPTODists; /* Which naughty distributions we want */
-extern unsigned int SrcDists; /* Which src distributions we want */
-extern unsigned int XF86Dists; /* Which XFree86 dists we want */
-extern unsigned int XF86ServerDists; /* The XFree86 servers we want */
-extern unsigned int XF86FontDists; /* The XFree86 fonts we want */
-extern int BootMgr; /* Which boot manager to use */
-extern int StatusLine; /* Where to print our status messages */
-extern DMenu MenuInitial; /* Initial installation menu */
-extern DMenu MenuFixit; /* Fixit repair menu */
-#if defined(__i386__) || defined(__amd64__)
-#ifdef PC98
-extern DMenu MenuIPLType; /* Type of IPL to write on the disk */
-#else
-extern DMenu MenuMBRType; /* Type of MBR to write on the disk */
-#endif
-#endif
-extern DMenu MenuConfigure; /* Final configuration menu */
-extern DMenu MenuDocumentation; /* Documentation menu */
-extern DMenu MenuFTPOptions; /* FTP Installation options */
-extern DMenu MenuIndex; /* Index menu */
-extern DMenu MenuOptions; /* Installation options */
-extern DMenu MenuOptionsLanguage; /* Language options menu */
-extern DMenu MenuKLD; /* Prototype KLD menu */
-extern DMenu MenuMedia; /* Media type menu */
-#ifdef WITH_MICE
-extern DMenu MenuMouse; /* Mouse type menu */
-#endif
-extern DMenu MenuMediaCDROM; /* CDROM media menu */
-extern DMenu MenuMediaDOS; /* DOS media menu */
-extern DMenu MenuMediaFloppy; /* Floppy media menu */
-extern DMenu MenuMediaFTP; /* FTP media menu */
-extern DMenu MenuMediaTape; /* Tape media menu */
-extern DMenu MenuNetworkDevice; /* Network device menu */
-extern DMenu MenuNTP; /* NTP time server menu */
-extern DMenu MenuSecurity; /* System security options menu */
-extern DMenu MenuSecurityProfile; /* Security profile menu */
-extern DMenu MenuStartup; /* Startup services menu */
-#ifdef WITH_SYSCONS
-extern DMenu MenuSyscons; /* System console configuration menu */
-extern DMenu MenuSysconsFont; /* System console font configuration menu */
-extern DMenu MenuSysconsKeymap; /* System console keymap configuration menu */
-extern DMenu MenuSysconsKeyrate; /* System console keyrate configuration menu */
-extern DMenu MenuSysconsSaver; /* System console saver configuration menu */
-extern DMenu MenuSysconsScrnmap; /* System console screenmap configuration menu */
-extern DMenu MenuSysconsTtys; /* System console terminal type menu */
-#endif
-extern DMenu MenuNetworking; /* Network configuration menu */
-extern DMenu MenuSendmail; /* Sendmail configuration menu */
-extern DMenu MenuInstallCustom; /* Custom Installation menu */
-extern DMenu MenuDistributions; /* Distribution menu */
-extern DMenu MenuDiskDevices; /* Disk type devices */
-extern DMenu MenuSubDistributions; /* Custom distribution menu */
-extern DMenu MenuSrcDistributions; /* Source distribution menu */
-extern DMenu MenuXF86; /* XFree86 main menu */
-extern DMenu MenuXF86Select; /* XFree86 distribution selection menu */
-extern DMenu MenuXF86SelectCore; /* XFree86 core distribution menu */
-extern DMenu MenuXF86SelectServer; /* XFree86 server distribution menu */
-#if !defined(X_AS_PKG) && defined(__i386__) && defined(PC98)
-extern DMenu MenuXF86SelectPC98Server; /* XFree86 server distribution menu */
-#endif
-extern DMenu MenuXF86SelectFonts; /* XFree86 font selection menu */
-extern DMenu MenuXDesktops; /* Disk devices menu */
-extern DMenu MenuHTMLDoc; /* HTML Documentation menu */
-extern DMenu MenuUsermgmt; /* User management menu */
-extern DMenu MenuFixit; /* Fixit floppy/CDROM/shell menu */
-extern DMenu MenuXF86Config; /* Select XFree86 configuration type */
-extern int FixItMode; /* FixItMode starts shell onc urrent device (ie Serial port) */
-extern const char * StartName; /* Which name we were started as */
-
-/* Stuff from libdialog which isn't properly declared outside */
-extern void display_helpfile(void);
-extern void display_helpline(WINDOW *w, int y, int width);
-
-/*** Prototypes ***/
-
-/* anonFTP.c */
-extern int configAnonFTP(dialogMenuItem *self);
-
-/* cdrom.c */
-extern Boolean mediaInitCDROM(Device *dev);
-extern FILE *mediaGetCDROM(Device *dev, char *file, Boolean probe);
-extern void mediaShutdownCDROM(Device *dev);
-
-/* command.c */
-extern void command_clear(void);
-extern void command_sort(void);
-extern void command_execute(void);
-extern void command_shell_add(char *key, char *fmt, ...) __printflike(2, 3);
-extern void command_func_add(char *key, commandFunc func, void *data);
-
-/* config.c */
-extern void configEnvironmentRC_conf(void);
-extern void configEnvironmentResolv(char *config);
-extern void configRC_conf(void);
-extern int configFstab(dialogMenuItem *self);
-extern int configRC(dialogMenuItem *self);
-extern int configResolv(dialogMenuItem *self);
-extern int configPackages(dialogMenuItem *self);
-extern int configSaver(dialogMenuItem *self);
-extern int configSaverTimeout(dialogMenuItem *self);
-#ifdef WITH_LINUX
-extern int configLinux(dialogMenuItem *self);
-#endif
-extern int configNTP(dialogMenuItem *self);
-#ifdef __alpha__
-extern int configOSF1(dialogMenuItem *self);
-#endif
-extern int configUsers(dialogMenuItem *self);
-extern int configXSetup(dialogMenuItem *self);
-extern int configXDesktop(dialogMenuItem *self);
-extern int configRouter(dialogMenuItem *self);
-extern int configPCNFSD(dialogMenuItem *self);
-extern int configInetd(dialogMenuItem *self);
-extern int configNFSServer(dialogMenuItem *self);
-extern int configRpcBind(dialogMenuItem *self);
-extern int configWriteRC_conf(dialogMenuItem *self);
-extern int configSecurityProfile(dialogMenuItem *self);
-extern int configSecurityExtreme(dialogMenuItem *self);
-extern int configSecurityModerate(dialogMenuItem *self);
-extern int configEtcTtys(dialogMenuItem *self);
-#ifdef __i386__
-extern int checkLoaderACPI(void);
-extern int configLoaderACPI(int);
-#endif
-
-/* devices.c */
-extern DMenu *deviceCreateMenu(DMenu *menu, DeviceType type, int (*hook)(dialogMenuItem *d),
- int (*check)(dialogMenuItem *d));
-extern void deviceGetAll(void);
-extern void deviceReset(void);
-extern void deviceRescan(void);
-extern Device **deviceFind(char *name, DeviceType type);
-extern Device **deviceFindDescr(char *name, char *desc, DeviceType class);
-extern int deviceCount(Device **devs);
-extern Device *new_device(char *name);
-extern Device *deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean enabled,
- Boolean (*init)(Device *mediadev),
- FILE * (*get)(Device *dev, char *file, Boolean probe),
- void (*shutDown)(Device *mediadev),
- void *private);
-extern Boolean dummyInit(Device *dev);
-extern FILE *dummyGet(Device *dev, char *dist, Boolean probe);
-extern void dummyShutdown(Device *dev);
-
-/* dhcp.c */
-extern int dhcpParseLeases(char *file, char *hostname, char *domain, char *nameserver,
- char *ipaddr, char *gateway, char *netmask);
-
-/* disks.c */
-#ifdef WITH_SLICES
-extern void diskPartition(Device *dev);
-extern int diskPartitionEditor(dialogMenuItem *self);
-#endif
-extern int diskPartitionWrite(dialogMenuItem *self);
-extern int diskGetSelectCount(Device ***devs);
-
-/* dispatch.c */
-extern int dispatchCommand(char *command);
-extern int dispatch_load_floppy(dialogMenuItem *self);
-extern int dispatch_load_file_int(int);
-extern int dispatch_load_file(dialogMenuItem *self);
-
-
-/* dist.c */
-extern int distReset(dialogMenuItem *self);
-extern int distConfig(dialogMenuItem *self);
-extern int distSetCustom(dialogMenuItem *self);
-extern int distUnsetCustom(dialogMenuItem *self);
-extern int distSetDeveloper(dialogMenuItem *self);
-extern int distSetXDeveloper(dialogMenuItem *self);
-extern int distSetKernDeveloper(dialogMenuItem *self);
-extern int distSetXKernDeveloper(dialogMenuItem *self);
-extern int distSetUser(dialogMenuItem *self);
-extern int distSetXUser(dialogMenuItem *self);
-extern int distSetMinimum(dialogMenuItem *self);
-extern int distSetEverything(dialogMenuItem *self);
-extern int distSetSrc(dialogMenuItem *self);
-extern int distSetXF86(dialogMenuItem *self);
-extern int distExtractAll(dialogMenuItem *self);
-
-/* dmenu.c */
-extern int dmenuDisplayFile(dialogMenuItem *tmp);
-extern int dmenuSubmenu(dialogMenuItem *tmp);
-extern int dmenuSystemCommand(dialogMenuItem *tmp);
-extern int dmenuSystemCommandBox(dialogMenuItem *tmp);
-extern int dmenuExit(dialogMenuItem *tmp);
-extern int dmenuISetVariable(dialogMenuItem *tmp);
-extern int dmenuSetVariable(dialogMenuItem *tmp);
-extern int dmenuSetKmapVariable(dialogMenuItem *tmp);
-extern int dmenuSetVariables(dialogMenuItem *tmp);
-extern int dmenuToggleVariable(dialogMenuItem *tmp);
-extern int dmenuSetFlag(dialogMenuItem *tmp);
-extern int dmenuSetValue(dialogMenuItem *tmp);
-extern Boolean dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons);
-extern Boolean dmenuOpenSimple(DMenu *menu, Boolean buttons);
-extern int dmenuVarCheck(dialogMenuItem *item);
-extern int dmenuVarsCheck(dialogMenuItem *item);
-extern int dmenuFlagCheck(dialogMenuItem *item);
-extern int dmenuRadioCheck(dialogMenuItem *item);
-
-/* doc.c */
-extern int docBrowser(dialogMenuItem *self);
-extern int docShowDocument(dialogMenuItem *self);
-
-/* dos.c */
-extern Boolean mediaCloseDOS(Device *dev, FILE *fp);
-extern Boolean mediaInitDOS(Device *dev);
-extern FILE *mediaGetDOS(Device *dev, char *file, Boolean probe);
-extern void mediaShutdownDOS(Device *dev);
-
-/* floppy.c */
-extern int getRootFloppy(void);
-extern Boolean mediaInitFloppy(Device *dev);
-extern FILE *mediaGetFloppy(Device *dev, char *file, Boolean probe);
-extern void mediaShutdownFloppy(Device *dev);
-
-/* ftp_strat.c */
-extern Boolean mediaCloseFTP(Device *dev, FILE *fp);
-extern Boolean mediaInitFTP(Device *dev);
-extern FILE *mediaGetFTP(Device *dev, char *file, Boolean probe);
-extern void mediaShutdownFTP(Device *dev);
-
-/* http.c */
-extern Boolean mediaInitHTTP(Device *dev);
-extern FILE *mediaGetHTTP(Device *dev, char *file, Boolean probe);
-
-/* globals.c */
-extern void globalsInit(void);
-
-/* index.c */
-int index_read(FILE *fp, PkgNodePtr papa);
-int index_menu(PkgNodePtr root, PkgNodePtr top, PkgNodePtr plist, int *pos, int *scroll);
-void index_init(PkgNodePtr top, PkgNodePtr plist);
-void index_node_free(PkgNodePtr top, PkgNodePtr plist);
-void index_sort(PkgNodePtr top);
-void index_print(PkgNodePtr top, int level);
-int index_extract(Device *dev, PkgNodePtr top, PkgNodePtr who, Boolean depended);
-int index_initialize(char *path);
-PkgNodePtr index_search(PkgNodePtr top, char *str, PkgNodePtr *tp);
-
-/* install.c */
-extern Boolean checkLabels(Boolean whinge, Chunk **rdev, Chunk **sdev, Chunk **udev, Chunk **vdev, Chunk **vtdev, Chunk **hdev);
-extern int installCommit(dialogMenuItem *self);
-extern int installCustomCommit(dialogMenuItem *self);
-extern int installExpress(dialogMenuItem *self);
-extern int installStandard(dialogMenuItem *self);
-extern int installFixitHoloShell(dialogMenuItem *self);
-extern int installFixitCDROM(dialogMenuItem *self);
-extern int installFixitFloppy(dialogMenuItem *self);
-extern int installFixupBase(dialogMenuItem *self);
-#ifndef X_AS_PKG
-extern int installFixupXFree(dialogMenuItem *self);
-#endif
-extern int installUpgrade(dialogMenuItem *self);
-extern int installFilesystems(dialogMenuItem *self);
-extern int installVarDefaults(dialogMenuItem *self);
-extern void installEnvironment(void);
-extern Boolean copySelf(void);
-
-/* kget.c */
-extern int kget(char *out);
-
-/* keymap.c */
-extern int loadKeymap(const char *lang);
-
-/* label.c */
-extern int diskLabelEditor(dialogMenuItem *self);
-extern int diskLabelCommit(dialogMenuItem *self);
-
-/* makedevs.c (auto-generated) */
-extern const char termcap_ansi[];
-extern const char termcap_vt100[];
-extern const char termcap_cons25w[];
-extern const char termcap_cons25[];
-extern const char termcap_cons25_m[];
-extern const char termcap_cons25r[];
-extern const char termcap_cons25r_m[];
-extern const char termcap_cons25l1[];
-extern const char termcap_cons25l1_m[];
-extern const char termcap_xterm[];
-extern const u_char font_iso_8x16[];
-extern const u_char font_cp850_8x16[];
-extern const u_char font_cp866_8x16[];
-extern const u_char koi8_r2cp866[];
-extern u_char default_scrnmap[];
-
-/* media.c */
-extern char *cpioVerbosity(void);
-extern void mediaClose(void);
-extern int mediaTimeout(void);
-extern int mediaSetCDROM(dialogMenuItem *self);
-extern int mediaSetFloppy(dialogMenuItem *self);
-extern int mediaSetDOS(dialogMenuItem *self);
-extern int mediaSetTape(dialogMenuItem *self);
-extern int mediaSetFTP(dialogMenuItem *self);
-extern int mediaSetFTPActive(dialogMenuItem *self);
-extern int mediaSetFTPPassive(dialogMenuItem *self);
-extern int mediaSetHTTP(dialogMenuItem *self);
-extern int mediaSetUFS(dialogMenuItem *self);
-extern int mediaSetNFS(dialogMenuItem *self);
-extern int mediaSetFTPUserPass(dialogMenuItem *self);
-extern int mediaSetCPIOVerbosity(dialogMenuItem *self);
-extern int mediaGetType(dialogMenuItem *self);
-extern Boolean mediaExtractDist(char *dir, char *dist, FILE *fp);
-extern Boolean mediaExtractDistBegin(char *dir, int *fd, int *zpid, int *cpic);
-extern Boolean mediaExtractDistEnd(int zpid, int cpid);
-extern Boolean mediaVerify(void);
-extern FILE *mediaGenericGet(char *base, const char *file);
-
-/* misc.c */
-extern Boolean file_readable(char *fname);
-extern Boolean file_executable(char *fname);
-extern Boolean directory_exists(const char *dirname);
-extern char *root_bias(char *path);
-extern char *itoa(int value);
-extern char *string_concat(char *p1, char *p2);
-extern char *string_concat3(char *p1, char *p2, char *p3);
-extern char *string_prune(char *str);
-extern char *string_skipwhite(char *str);
-extern char *string_copy(char *s1, char *s2);
-extern char *pathBaseName(const char *path);
-extern void safe_free(void *ptr);
-extern void *safe_malloc(size_t size);
-extern void *safe_realloc(void *orig, size_t size);
-extern dialogMenuItem *item_add(dialogMenuItem *list, char *prompt, char *title,
- int (*checked)(dialogMenuItem *self),
- int (*fire)(dialogMenuItem *self),
- void (*selected)(dialogMenuItem *self, int is_selected),
- void *data, int *aux, int *curr, int *max);
-extern void items_free(dialogMenuItem *list, int *curr, int *max);
-extern int Mkdir(char *);
-extern int Mkdir_command(char *key, void *data);
-extern int Mount(char *, void *data);
-extern int Mount_msdosfs(char *mountp, void *devname);
-extern WINDOW *openLayoutDialog(char *helpfile, char *title, int x, int y, int width, int height);
-extern ComposeObj *initLayoutDialog(WINDOW *win, Layout *layout, int x, int y, int *max);
-extern int layoutDialogLoop(WINDOW *win, Layout *layout, ComposeObj **obj,
- int *n, int max, int *cbutton, int *cancel);
-
-extern WINDOW *savescr(void);
-extern void restorescr(WINDOW *w);
-extern char *sstrncpy(char *dst, const char *src, int size);
-
-/* modules.c */
-extern void driverFloppyCheck(void);
-extern void moduleInitialize(void);
-extern int kldBrowser(dialogMenuItem *self);
-
-/* mouse.c */
-extern int mousedTest(dialogMenuItem *self);
-extern int mousedDisable(dialogMenuItem *self);
-extern int setMouseFlags(dialogMenuItem *self);
-
-/* msg.c */
-extern Boolean isDebug(void);
-extern void msgInfo(char *fmt, ...) __printf0like(1, 2);
-extern void msgYap(char *fmt, ...) __printflike(1, 2);
-extern void msgWarn(char *fmt, ...) __printflike(1, 2);
-extern void msgDebug(char *fmt, ...) __printflike(1, 2);
-extern void msgError(char *fmt, ...) __printflike(1, 2);
-extern void msgFatal(char *fmt, ...) __printflike(1, 2);
-extern void msgConfirm(char *fmt, ...) __printflike(1, 2);
-extern void msgNotify(char *fmt, ...) __printflike(1, 2);
-extern void msgWeHaveOutput(char *fmt, ...) __printflike(1, 2);
-extern int msgYesNo(char *fmt, ...) __printflike(1, 2);
-extern int msgNoYes(char *fmt, ...) __printflike(1, 2);
-extern char *msgGetInput(char *buf, char *fmt, ...) __printflike(2, 3);
-extern int msgSimpleConfirm(char *);
-extern int msgSimpleNotify(char *);
-
-/* network.c */
-extern Boolean mediaInitNetwork(Device *dev);
-extern void mediaShutdownNetwork(Device *dev);
-
-/* nfs.c */
-extern Boolean mediaInitNFS(Device *dev);
-extern FILE *mediaGetNFS(Device *dev, char *file, Boolean probe);
-extern void mediaShutdownNFS(Device *dev);
-
-/* options.c */
-extern int optionsEditor(dialogMenuItem *self);
-
-/* package.c */
-extern int packageAdd(dialogMenuItem *self);
-extern int package_add(char *name);
-extern int package_extract(Device *dev, char *name, Boolean depended);
-extern Boolean package_exists(char *name);
-
-/* pccard.c */
-extern void pccardInitialize(void);
-
-/* system.c */
-extern void systemInitialize(int argc, char **argv);
-extern void systemShutdown(int status);
-extern int execExecute(char *cmd, char *name);
-extern int systemExecute(char *cmd);
-extern void systemSuspendDialog(void);
-extern void systemResumeDialog(void);
-extern int systemDisplayHelp(char *file);
-extern char *systemHelpFile(char *file, char *buf);
-extern void systemChangeFont(const u_char font[]);
-extern void systemChangeLang(char *lang);
-extern void systemChangeTerminal(char *color, const u_char c_termcap[], char *mono, const u_char m_termcap[]);
-extern void systemChangeScreenmap(const u_char newmap[]);
-extern void systemCreateHoloshell(void);
-extern int vsystem(char *fmt, ...) __printflike(1, 2);
-
-/* tape.c */
-extern char *mediaTapeBlocksize(void);
-extern Boolean mediaInitTape(Device *dev);
-extern FILE *mediaGetTape(Device *dev, char *file, Boolean probe);
-extern void mediaShutdownTape(Device *dev);
-
-/* tcpip.c */
-extern int tcpOpenDialog(Device *dev);
-extern int tcpMenuSelect(dialogMenuItem *self);
-extern Device *tcpDeviceSelect(void);
-
-/* termcap.c */
-extern int set_termcap(void);
-
-/* ttys.c */
-extern void configTtys(void);
-
-/* ufs.c */
-extern void mediaShutdownUFS(Device *dev);
-extern Boolean mediaInitUFS(Device *dev);
-extern FILE *mediaGetUFS(Device *dev, char *file, Boolean probe);
-
-/* usb.c */
-extern void usbInitialize(void);
-
-/* user.c */
-extern int userAddGroup(dialogMenuItem *self);
-extern int userAddUser(dialogMenuItem *self);
-
-/* variable.c */
-extern void variable_set(char *var, int dirty);
-extern void variable_set2(char *name, char *value, int dirty);
-extern char *variable_get(char *var);
-extern int variable_cmp(char *var, char *value);
-extern void variable_unset(char *var);
-extern char *variable_get_value(char *var, char *prompt, int dirty);
-extern int variable_check(char *data);
-extern int dump_variables(dialogMenuItem *self);
-extern void free_variables(void);
-extern void pvariable_set(char *var);
-extern char *pvariable_get(char *var);
-
-/* wizard.c */
-extern void slice_wizard(Disk *d);
-
-/*
- * Macros. Please find a better place for us!
- */
-#define DEVICE_INIT(d) ((d) != NULL ? (d)->init((d)) : NULL)
-#define DEVICE_GET(d, b, f) ((d) != NULL ? (d)->get((d), (b), (f)) : NULL)
-#define DEVICE_SHUTDOWN(d) ((d) != NULL ? (d)->shutdown((d)) : (void)0)
-
-#ifdef USE_GZIP
-#define UNZIPPER "gunzip"
-#else
-#define UNZIPPER "bunzip2"
-#endif
-
-#endif
-/* _SYSINSTALL_H_INCLUDE */
diff --git a/usr.sbin/sade/system.c b/usr.sbin/sade/system.c
deleted file mode 100644
index 25ab8b1f6135..000000000000
--- a/usr.sbin/sade/system.c
+++ /dev/null
@@ -1,537 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last program in the `sysinstall' line - the next
- * generation being essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Jordan Hubbard
- *
- * My contributions are in the public domain.
- *
- * Parts of this file are also blatently stolen from Poul-Henning Kamp's
- * previous version of sysinstall, and as such fall under his "BEERWARE license"
- * so buy him a beer if you like it! Buy him a beer for me, too!
- * Heck, get him completely drunk and send me pictures! :-)
- */
-
-#include "sysinstall.h"
-#include <signal.h>
-#include <termios.h>
-#include <sys/reboot.h>
-#include <sys/consio.h>
-#include <sys/fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
-
-
-/* Where we stick our temporary expanded doc file */
-#define DOC_TMP_DIR "/tmp/.doc"
-#define DOC_TMP_FILE "/tmp/.doc/doc.tmp"
-
-static pid_t ehs_pid;
-
-/*
- * Handle interrupt signals - this probably won't work in all cases
- * due to our having bogotified the internal state of dialog or curses,
- * but we'll give it a try.
- */
-static int
-intr_continue(dialogMenuItem *self)
-{
- return DITEM_LEAVE_MENU;
-}
-
-static int
-intr_reboot(dialogMenuItem *self)
-{
- systemShutdown(-1);
- /* NOTREACHED */
- return 0;
-}
-
-static int
-intr_restart(dialogMenuItem *self)
-{
- int ret, fd, fdmax;
-
- mediaClose();
- free_variables();
- fdmax = getdtablesize();
- for (fd = 3; fd < fdmax; fd++)
- close(fd);
- ret = execl(StartName, StartName, "-restart", (char *)NULL);
- msgDebug("execl failed (%s)\n", strerror(errno));
- /* NOTREACHED */
- return -1;
-}
-
-static dialogMenuItem intrmenu[] = {
- { "Abort", "Abort the installation", NULL, intr_reboot },
- { "Restart", "Restart the installation program", NULL, intr_restart },
- { "Continue", "Continue the installation", NULL, intr_continue },
-};
-
-
-static void
-handle_intr(int sig)
-{
- WINDOW *save = savescr();
-
- use_helpline(NULL);
- use_helpfile(NULL);
- if (OnVTY) {
- ioctl(0, VT_ACTIVATE, 1); /* Switch back */
- msgInfo(NULL);
- }
- (void)dialog_menu("Installation interrupt",
- "Do you want to abort the installation?",
- -1, -1, 3, -3, intrmenu, NULL, NULL, NULL);
- restorescr(save);
-}
-
-/*
- * Harvest children if we are init.
- */
-static void
-reap_children(int sig)
-{
- int errbak = errno;
-
- while (waitpid(-1, NULL, WNOHANG) > 0)
- ;
- errno = errbak;
-}
-
-/* Expand a file into a convenient location, nuking it each time */
-static char *
-expand(char *fname)
-{
- char *gunzip = RunningAsInit ? "/stand/gunzip" : "/usr/bin/gunzip";
-
- if (!directory_exists(DOC_TMP_DIR)) {
- Mkdir(DOC_TMP_DIR);
- if (chown(DOC_TMP_DIR, 0, 0) < 0)
- return NULL;
- if (chmod(DOC_TMP_DIR, S_IRWXU) < 0)
- return NULL;
- }
- else
- unlink(DOC_TMP_FILE);
- if (!file_readable(fname) || vsystem("%s < %s > %s", gunzip, fname, DOC_TMP_FILE))
- return NULL;
- return DOC_TMP_FILE;
-}
-
-/* Initialize system defaults */
-void
-systemInitialize(int argc, char **argv)
-{
- size_t i;
- int boothowto;
- sigset_t signalset;
-
- signal(SIGINT, SIG_IGN);
- globalsInit();
-
- i = sizeof(boothowto);
- if (!sysctlbyname("debug.boothowto", &boothowto, &i, NULL, NULL) &&
- (i == sizeof(boothowto)) && (boothowto & RB_VERBOSE))
- variable_set2(VAR_DEBUG, "YES", 0);
-
- /* Are we running as init? */
- if (getpid() == 1) {
- int fd;
-
- RunningAsInit = 1;
- setsid();
- close(0);
- fd = open("/dev/ttyv0", O_RDWR);
- if (fd == -1) {
- fd = open("/dev/console", O_RDWR); /* fallback */
- variable_set2(VAR_FIXIT_TTY, "serial", 0); /* give fixit a hint */
- } else
- OnVTY = TRUE;
- /*
- * To make _sure_ we're on a VTY and don't have /dev/console switched
- * away to a serial port or something, attempt to set the cursor appearance.
- */
- if (OnVTY) {
- int fd2, type;
-
- type = 0; /* normal */
- if ((fd2 = open("/dev/console", O_RDWR)) != -1) {
- if (ioctl(fd2, CONS_CURSORTYPE, &type) == -1) {
- OnVTY = FALSE;
- variable_set2(VAR_FIXIT_TTY, "serial", 0); /* Tell Fixit
- the console
- type */
- close(fd); close(fd2);
- open("/dev/console", O_RDWR);
- }
- else
- close(fd2);
- }
- }
- close(1); dup(0);
- close(2); dup(0);
- printf("%s running as init on %s\n", argv[0], OnVTY ? "vty0" : "serial console");
- ioctl(0, TIOCSCTTY, (char *)NULL);
- setlogin("root");
- setenv("PATH", "/stand:/bin:/sbin:/usr/sbin:/usr/bin:/mnt/bin:/mnt/sbin:/mnt/usr/sbin:/mnt/usr/bin:/usr/X11R6/bin", 1);
- setbuf(stdin, 0);
- setbuf(stderr, 0);
-#ifdef __alpha__
- i = 0;
- sysctlbyname("machdep.unaligned_print", NULL, 0, &i, sizeof(i));
-#endif
-#if 0
- signal(SIGCHLD, reap_children);
-#endif
- }
- else {
- char hname[256];
-
- /* Initalize various things for a multi-user environment */
- if (!gethostname(hname, sizeof hname))
- variable_set2(VAR_HOSTNAME, hname, 0);
- }
-
- if (set_termcap() == -1) {
- printf("Can't find terminal entry\n");
- exit(-1);
- }
-
- /* XXX - libdialog has particularly bad return value checking */
- init_dialog();
-
- /* If we haven't crashed I guess dialog is running ! */
- DialogActive = TRUE;
-
- /* Make sure HOME is set for those utilities that need it */
- if (!getenv("HOME"))
- setenv("HOME", "/", 1);
- signal(SIGINT, handle_intr);
- /*
- * Make sure we can be interrupted even if we were re-executed
- * from an interrupt.
- */
- sigemptyset(&signalset);
- sigaddset(&signalset, SIGINT);
- sigprocmask(SIG_UNBLOCK, &signalset, NULL);
-
- (void)vsystem("rm -rf %s", DOC_TMP_DIR);
-}
-
-/* Close down and prepare to exit */
-void
-systemShutdown(int status)
-{
- /* If some media is open, close it down */
- if (status >=0)
- mediaClose();
-
- /* write out any changes to rc.conf .. */
- configRC_conf();
-
- /* Shut down the dialog library */
- if (DialogActive) {
- end_dialog();
- DialogActive = FALSE;
- }
-
- /* Shut down curses */
- endwin();
-
- /* If we have a temporary doc dir lying around, nuke it */
- (void)vsystem("rm -rf %s", DOC_TMP_DIR);
-
- /* REALLY exit! */
- if (RunningAsInit) {
- /* Put the console back */
- ioctl(0, VT_ACTIVATE, 2);
-#if defined(__alpha__) || defined(__sparc64__)
- reboot(RB_HALT);
-#else
- reboot(0);
-#endif
- }
- else
- exit(status);
-}
-
-/* Run some general command */
-int
-systemExecute(char *command)
-{
- int status;
- struct termios foo;
- WINDOW *w = savescr();
-
- dialog_clear();
- dialog_update();
- end_dialog();
- DialogActive = FALSE;
- if (tcgetattr(0, &foo) != -1) {
- foo.c_cc[VERASE] = '\010';
- tcsetattr(0, TCSANOW, &foo);
- }
- if (!Fake)
- status = system(command);
- else {
- status = 0;
- msgDebug("systemExecute: Faked execution of `%s'\n", command);
- }
- DialogActive = TRUE;
- restorescr(w);
- return status;
-}
-
-/* suspend/resume libdialog/curses screen */
-static WINDOW *oldW;
-
-void
-systemSuspendDialog(void)
-{
-
- oldW = savescr();
- dialog_clear();
- dialog_update();
- end_dialog();
- DialogActive = FALSE;
-}
-
-void
-systemResumeDialog(void)
-{
-
- DialogActive = TRUE;
- restorescr(oldW);
-}
-
-/* Display a help file in a filebox */
-int
-systemDisplayHelp(char *file)
-{
- char *fname = NULL;
- char buf[FILENAME_MAX];
- int ret = 0;
- WINDOW *w = savescr();
-
- fname = systemHelpFile(file, buf);
- if (!fname) {
- snprintf(buf, FILENAME_MAX, "The %s file is not provided on this particular floppy image.", file);
- use_helpfile(NULL);
- use_helpline(NULL);
- dialog_mesgbox("Sorry!", buf, -1, -1);
- ret = 1;
- }
- else {
- use_helpfile(NULL);
- use_helpline(NULL);
- dialog_textbox(file, fname, LINES, COLS);
- }
- restorescr(w);
- return ret;
-}
-
-char *
-systemHelpFile(char *file, char *buf)
-{
- if (!file)
- return NULL;
- if (file[0] == '/')
- return file;
- snprintf(buf, FILENAME_MAX, "/stand/help/%s.hlp.gz", file);
- if (file_readable(buf))
- return expand(buf);
- snprintf(buf, FILENAME_MAX, "/stand/help/%s.hlp", file);
- if (file_readable(buf))
- return expand(buf);
- snprintf(buf, FILENAME_MAX, "/stand/help/%s.TXT.gz", file);
- if (file_readable(buf))
- return expand(buf);
- snprintf(buf, FILENAME_MAX, "/stand/help/%s.TXT", file);
- if (file_readable(buf))
- return expand(buf);
- snprintf(buf, FILENAME_MAX, "/usr/src/usr.sbin/sysinstall/help/%s.hlp", file);
- if (file_readable(buf))
- return buf;
- snprintf(buf, FILENAME_MAX, "/usr/src/usr.sbin/sysinstall/help/%s.TXT", file);
- if (file_readable(buf))
- return buf;
- return NULL;
-}
-
-void
-systemChangeTerminal(char *color, const u_char c_term[],
- char *mono, const u_char m_term[])
-{
- if (OnVTY) {
- int setupterm(char *color, int, int *);
-
- if (ColorDisplay) {
- setenv("TERM", color, 1);
- setenv("TERMCAP", c_term, 1);
- reset_shell_mode();
- setterm(color);
- cbreak(); noecho();
- }
- else {
- setenv("TERM", mono, 1);
- setenv("TERMCAP", m_term, 1);
- reset_shell_mode();
- setterm(mono);
- cbreak(); noecho();
- }
- }
- clear();
- refresh();
- dialog_clear();
-}
-
-int
-vsystem(char *fmt, ...)
-{
- va_list args;
- int pstat;
- pid_t pid;
- int omask;
- sig_t intsave, quitsave;
- char *cmd;
- int i;
-
- cmd = (char *)alloca(FILENAME_MAX);
- cmd[0] = '\0';
- va_start(args, fmt);
- vsnprintf(cmd, FILENAME_MAX, fmt, args);
- va_end(args);
-
- omask = sigblock(sigmask(SIGCHLD));
- if (Fake) {
- msgDebug("vsystem: Faked execution of `%s'\n", cmd);
- return 0;
- }
- if (isDebug())
- msgDebug("Executing command `%s'\n", cmd);
- pid = fork();
- if (pid == -1) {
- (void)sigsetmask(omask);
- i = 127;
- }
- else if (!pid) { /* Junior */
- (void)sigsetmask(omask);
- if (DebugFD != -1) {
- dup2(DebugFD, 0);
- dup2(DebugFD, 1);
- dup2(DebugFD, 2);
- }
- else {
- close(1); open("/dev/null", O_WRONLY);
- dup2(1, 2);
- }
- if (!RunningAsInit)
- execl("/bin/sh", "/bin/sh", "-c", cmd, (char *)NULL);
- else
- execl("/stand/sh", "/stand/sh", "-c", cmd, (char *)NULL);
- exit(1);
- }
- else {
- intsave = signal(SIGINT, SIG_IGN);
- quitsave = signal(SIGQUIT, SIG_IGN);
- pid = waitpid(pid, &pstat, 0);
- (void)sigsetmask(omask);
- (void)signal(SIGINT, intsave);
- (void)signal(SIGQUIT, quitsave);
- i = (pid == -1) ? -1 : WEXITSTATUS(pstat);
- if (isDebug())
- msgDebug("Command `%s' returns status of %d\n", cmd, i);
- }
- return i;
-}
-
-void
-systemCreateHoloshell(void)
-{
- int waitstatus;
-
- if ((FixItMode || OnVTY) && RunningAsInit) {
-
- if (ehs_pid != 0) {
- int pstat;
-
- if (kill(ehs_pid, 0) == 0) {
-
- if (msgNoYes("There seems to be an emergency holographic shell\n"
- "already running on VTY 4.\n\n"
- "Kill it and start a new one?"))
- return;
-
- /* try cleaning up as much as possible */
- (void) kill(ehs_pid, SIGHUP);
- sleep(1);
- (void) kill(ehs_pid, SIGKILL);
- }
-
- /* avoid too many zombies */
- (void) waitpid(ehs_pid, &pstat, WNOHANG);
- }
-
- if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0)
- systemSuspendDialog(); /* must be before the fork() */
- if ((ehs_pid = fork()) == 0) {
- int i, fd;
- struct termios foo;
- extern int login_tty(int);
-
- ioctl(0, TIOCNOTTY, NULL);
- for (i = getdtablesize(); i >= 0; --i)
- close(i);
- if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0)
- fd = open("/dev/console", O_RDWR);
- else
- fd = open("/dev/ttyv3", O_RDWR);
- ioctl(0, TIOCSCTTY, &fd);
- dup2(0, 1);
- dup2(0, 2);
- DebugFD = 2;
- if (login_tty(fd) == -1)
- msgDebug("Doctor: I can't set the controlling terminal.\n");
- signal(SIGTTOU, SIG_IGN);
- if (tcgetattr(fd, &foo) != -1) {
- foo.c_cc[VERASE] = '\010';
- if (tcsetattr(fd, TCSANOW, &foo) == -1)
- msgDebug("Doctor: I'm unable to set the erase character.\n");
- }
- else
- msgDebug("Doctor: I'm unable to get the terminal attributes!\n");
- if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) {
- printf("Type ``exit'' in this fixit shell to resume sysinstall.\n\n");
- fflush(stdout);
- }
- execlp("sh", "-sh", 0);
- msgDebug("Was unable to execute sh for Holographic shell!\n");
- exit(1);
- }
- else {
- if (strcmp(variable_get(VAR_FIXIT_TTY), "standard") == 0) {
- WINDOW *w = savescr();
-
- msgNotify("Starting an emergency holographic shell on VTY4");
- sleep(2);
- restorescr(w);
- }
- else {
- (void)waitpid(ehs_pid, &waitstatus, 0); /* we only wait for
- shell to finish
- it serial mode
- since there is no
- virtual console */
- systemResumeDialog();
- }
- }
- }
-}
diff --git a/usr.sbin/sade/termcap.c b/usr.sbin/sade/termcap.c
deleted file mode 100644
index 1d8e047bc12a..000000000000
--- a/usr.sbin/sade/termcap.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (c) 1994, Paul Richards.
- *
- * All rights reserved.
- *
- * This software may be used, modified, copied, distributed, and sold, in both
- * source and binary form provided that the above copyright and these terms
- * are retained, verbatim, as the first lines of this file. 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.
- *
- * $FreeBSD$
- */
-
-#include "sysinstall.h"
-#include <stdarg.h>
-#include <fcntl.h>
-#include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/consio.h>
-
-#define VTY_STATUS_LINE 24
-#define TTY_STATUS_LINE 23
-
-static void
-prompt_term(char **termp, char **termcapp)
-{
- char str[80];
- static struct {
- const char *term, *termcap;
- } lookup[] = { { "ansi", termcap_ansi },
- { "vt100", termcap_vt100 },
- { "cons25", termcap_cons25 },
- { "cons25-m", termcap_cons25_m },
- { "xterm", termcap_xterm },
- { "cons25w", termcap_cons25w } }; /* must be last */
-
- if (RunningAsInit) {
- while (1) {
- int i;
-
- printf("\nThese are the predefined terminal types available to\n");
- printf("sysinstall when running stand-alone. Please choose the\n");
- printf("closest match for your particular terminal.\n\n");
- printf("1 ...................... Standard ANSI terminal.\n");
- printf("2 ...................... VT100 or compatible terminal.\n");
- printf("3 ...................... FreeBSD system console (color).\n");
- printf("4 ...................... FreeBSD system console (monochrome).\n\n");
- printf("5 ...................... xterm terminal emulator.\n\n");
- printf("Your choice: (1-5) ");
- fflush(stdout);
- fgets(str, 80, stdin);
- i = str[0] - '0';
- if (i > 0 && i < 6) {
- *termp = (char *)lookup[i - 1].term;
- *termcapp = (char *)lookup[i - 1].termcap;
- break;
- }
- else
- printf("\007Invalid choice, please try again.\n\n");
- }
- }
- else {
- printf("\nPlease set your TERM variable before running this program.\n");
- printf("Defaulting to an ANSI compatible terminal - please press RETURN\n");
- fgets(str, 80, stdin); /* Just to make it interactive */
- *termp = (char *)"ansi";
- *termcapp = (char *)termcap_ansi;
- }
-}
-
-int
-set_termcap(void)
-{
- char *term;
- int stat;
- struct ttysize ts;
-
- term = getenv("TERM");
- stat = ioctl(STDERR_FILENO, GIO_COLOR, &ColorDisplay);
-
- if (!RunningAsInit) {
- if (isDebug())
- DebugFD = open("sysinstall.debug", O_WRONLY|O_CREAT|O_TRUNC, 0644);
- else
- DebugFD = -1;
- if (DebugFD < 0)
- DebugFD = open("/dev/null", O_RDWR, 0);
- }
-
- if (!OnVTY || (stat < 0)) {
- if (!term) {
- char *term, *termcap;
-
- prompt_term(&term, &termcap);
- if (setenv("TERM", term, 1) < 0)
- return -1;
- if (setenv("TERMCAP", termcap, 1) < 0)
- return -1;
- }
- if (DebugFD < 0)
- DebugFD = open("/dev/null", O_RDWR, 0);
- }
- else {
- int i, on;
-
- if (getpid() == 1) {
- DebugFD = open("/dev/ttyv1", O_WRONLY);
- if (DebugFD != -1) {
- on = 1;
- i = ioctl(DebugFD, TIOCCONS, (char *)&on);
- msgDebug("ioctl(%d, TIOCCONS, NULL) = %d (%s)\n",
- DebugFD, i, !i ? "success" : strerror(errno));
- }
- }
-
-#ifdef PC98
- if (!term) {
- if (setenv("TERM", "cons25w", 1) < 0)
- return -1;
- if (setenv("TERMCAP", termcap_cons25w, 1) < 0)
- return -1;
- }
-#else
- if (ColorDisplay) {
- if (!term) {
- if (setenv("TERM", "cons25", 1) < 0)
- return -1;
- if (setenv("TERMCAP", termcap_cons25, 1) < 0)
- return -1;
- }
- }
- else {
- if (!term) {
- if (setenv("TERM", "cons25-m", 1) < 0)
- return -1;
- if (setenv("TERMCAP", termcap_cons25_m, 1) < 0)
- return -1;
- }
- }
-#endif
- }
- if (ioctl(0, TIOCGSIZE, &ts) == -1) {
- msgDebug("Unable to get terminal size - errno %d\n", errno);
- ts.ts_lines = 0;
- }
- StatusLine = ts.ts_lines ? ts.ts_lines - 1: (OnVTY ? VTY_STATUS_LINE : TTY_STATUS_LINE);
- return 0;
-}
diff --git a/usr.sbin/sade/usb.c b/usr.sbin/sade/usb.c
deleted file mode 100644
index 4eedbd555f89..000000000000
--- a/usr.sbin/sade/usb.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * USB support for sysinstall
- *
- * $FreeBSD$
- *
- * Copyright (c) 2000 John Baldwin <jhb@FreeBSD.org>. All rights reserved.
- *
- * 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.
- */
-
-#include "sysinstall.h"
-#include <sys/fcntl.h>
-#include <sys/time.h>
-
-void
-usbInitialize(void)
-{
- int fd;
- WINDOW *w;
-
- if (!RunningAsInit && !Fake) {
- /* It's not my job... */
- return;
- }
-
- if ((fd = open("/dev/usb", O_RDONLY)) < 0) {
- msgDebug("Can't open USB controller.\n");
- return;
- }
- close(fd);
-
- w = savescr();
- msgNotify("Initializing USB controller....");
-
- variable_set2("usbd_enable", "YES", 1);
-
- vsystem("/stand/usbd");
- restorescr(w);
-}
diff --git a/usr.sbin/sade/variable.c b/usr.sbin/sade/variable.c
deleted file mode 100644
index d7f0e1b981a3..000000000000
--- a/usr.sbin/sade/variable.c
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * The new sysinstall program.
- *
- * This is probably the last program in the `sysinstall' line - the next
- * generation being essentially a complete rewrite.
- *
- * $FreeBSD$
- *
- * Copyright (c) 1995
- * Jordan Hubbard. All rights reserved.
- * Copyright (c) 2001
- * Murray Stokely. 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,
- * verbatim and that no modifications are made prior to this
- * point in the file.
- * 2. Redistributions in binary form must 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 JORDAN HUBBARD ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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 "sysinstall.h"
-
-/* Routines for dealing with variable lists */
-
-static void
-make_variable(char *var, char *value, int dirty)
-{
- Variable *vp;
-
- /* Trim leading and trailing whitespace */
- var = string_skipwhite(string_prune(var));
-
- if (!var || !*var)
- return;
-
-
- /* Now search to see if it's already in the list */
- for (vp = VarHead; vp; vp = vp->next) {
- if (!strcmp(vp->name, var)) {
- if (vp->dirty && !dirty)
- return;
- setenv(var, value, 1);
- free(vp->value);
- vp->value = strdup(value);
- if (dirty != -1)
- vp->dirty = dirty;
- return;
- }
- }
-
- setenv(var, value, 1);
- /* No? Create a new one */
- vp = (Variable *)safe_malloc(sizeof(Variable));
- vp->name = strdup(var);
- vp->value = strdup(value);
- if (dirty == -1)
- dirty = 0;
- vp->dirty = dirty;
- vp->next = VarHead;
- VarHead = vp;
-}
-
-void
-variable_set(char *var, int dirty)
-{
- char tmp[1024], *cp;
-
- if (!var)
- msgFatal("NULL variable name & value passed.");
- else if (!*var)
- msgDebug("Warning: Zero length name & value passed to variable_set()\n");
- SAFE_STRCPY(tmp, var);
- if ((cp = index(tmp, '=')) == NULL)
- msgFatal("Invalid variable format: %s", var);
- *(cp++) = '\0';
- make_variable(tmp, string_skipwhite(cp), dirty);
-}
-
-void
-variable_set2(char *var, char *value, int dirty)
-{
- if (!var || !value)
- msgFatal("Null name or value passed to set_variable2(%s) = %s!",
- var ? var : "", value ? value : "");
- else if (!*var || !*value)
- msgDebug("Warning: Zero length name or value passed to variable_set2(%s) = %s\n",
- var, value);
- make_variable(var, value, dirty);
-}
-
-char *
-variable_get(char *var)
-{
- return getenv(var);
-}
-
-int
-variable_cmp(char *var, char *value)
-{
- char *val;
-
- if ((val = variable_get(var)))
- return strcmp(val, value);
- return -1;
-}
-
-void
-variable_unset(char *var)
-{
- Variable *vp;
- char name[512], *cp;
-
- if ((cp = index(var, '=')) != NULL)
- sstrncpy(name, var, cp - var);
- else
- SAFE_STRCPY(name, var);
- unsetenv(name);
- /* Now search to see if it's in our list, if we have one.. */
- if (!VarHead)
- return;
- else if (!VarHead->next && !strcmp(VarHead->name, name)) {
- safe_free(VarHead->name);
- safe_free(VarHead->value);
- free(VarHead);
- VarHead = NULL;
- }
- else {
- for (vp = VarHead; vp; vp = vp->next) {
- if (!strcmp(vp->name, name)) {
- Variable *save = vp->next;
-
- safe_free(vp->name);
- safe_free(vp->value);
- *vp = *save;
- safe_free(save);
- break;
- }
- }
- }
-}
-
-/* Prompt user for the name of a variable */
-char *
-variable_get_value(char *var, char *prompt, int dirty)
-{
- char *cp;
-
- cp = variable_get(var);
- if (cp && variable_get(VAR_NONINTERACTIVE))
- return cp;
- else if ((cp = msgGetInput(cp, "%s", prompt)) != NULL)
- variable_set2(var, cp, dirty);
- else
- cp = NULL;
- return cp;
-}
-
-/* Check if value passed in data (in the form "variable=value") is
- equal to value of variable stored in env */
-int
-variable_check(char *data)
-{
- char *cp, *cp2, *cp3, tmp[256];
-
- if (!data)
- return FALSE;
- SAFE_STRCPY(tmp, data);
- if ((cp = index(tmp, '=')) != NULL) {
- *(cp++) = '\0';
- if (*cp == '"') { /* smash quotes if present */
- ++cp;
- if ((cp3 = index(cp, '"')) != NULL)
- *cp3 = '\0';
- }
- else if ((cp3 = index(cp, ',')) != NULL)
- *cp3 = '\0';
- cp2 = variable_get(tmp);
- if (cp2) {
- if (!*cp)
- return TRUE;
- else
- return !strcmp(cp, cp2);
- }
- else
- return FALSE;
- }
- else
- return variable_get(tmp) ? TRUE : FALSE;
-}
-
-int
-dump_variables(dialogMenuItem *unused)
-{
- FILE *fp;
- Variable *vp;
-
- if (isDebug())
- msgDebug("Writing sysinstall variables to file..\n");
-
- fp = fopen("/etc/sysinstall.vars", "w");
- if (!fp) {
- msgConfirm("Unable to write to /etc/sysinstall.vars: %s",
- strerror(errno));
- return DITEM_FAILURE;
- }
-
- for (vp = VarHead; vp; vp = vp->next)
- fprintf(fp, "%s=\"%s\" (%d)\n", vp->name, vp->value, vp->dirty);
-
- fclose(fp);
-
- return DITEM_SUCCESS;
-}
-
-/* Free all of the variables, useful to really start over as when the
- user selects "restart" from the interrupt menu. */
-void
-free_variables(void)
-{
- Variable *vp;
-
- /* Free the variables from our list, if we have one.. */
- if (!VarHead)
- return;
- else if (!VarHead->next) {
- unsetenv(VarHead->name);
- safe_free(VarHead->name);
- safe_free(VarHead->value);
- free(VarHead);
- VarHead = NULL;
- }
- else {
- for (vp = VarHead; vp; ) {
- Variable *save = vp;
- unsetenv(vp->name);
- safe_free(vp->name);
- safe_free(vp->value);
- vp = vp->next;
- safe_free(save);
- }
- VarHead = NULL;
- }
-}
-
-/*
- * Persistent variables. The variables modified by these functions
- * are not cleared between invocations of sysinstall. This is useful
- * to allow the user to completely restart sysinstall, without having
- * it load all of the modules again from the installation media which
- * are still in memory.
- */
-
-void
-pvariable_set(char *var)
-{
- char tmp[1024];
-
- if (!var)
- msgFatal("NULL variable name & value passed.");
- else if (!*var)
- msgDebug("Warning: Zero length name & value passed to variable_set()\n");
- /* Add a trivial namespace to whatever name the caller chooses. */
- SAFE_STRCPY(tmp, "SYSINSTALL_PVAR");
- if (index(var, '=') == NULL)
- msgFatal("Invalid variable format: %s", var);
- strlcat(tmp, var, 1024);
- putenv(tmp);
-}
-
-char *
-pvariable_get(char *var)
-{
- char tmp[1024];
-
- SAFE_STRCPY(tmp, "SYSINSTALL_PVAR");
- strlcat(tmp, var, 1024);
- return getenv(tmp);
-}
diff --git a/usr.sbin/sade/wizard.c b/usr.sbin/sade/wizard.c
deleted file mode 100644
index 3a078871738c..000000000000
--- a/usr.sbin/sade/wizard.c
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- *
- * $FreeBSD$
- *
- */
-
-#include "sysinstall.h"
-#include <fcntl.h>
-#include <err.h>
-
-int
-scan_block(int fd, daddr_t block)
-{
- u_char foo[512];
-
- if (-1 == lseek(fd,block * 512,SEEK_SET))
- err(1,"lseek");
- if (512 != read(fd,foo, 512))
- return 1;
- return 0;
-}
-
-void
-Scan_Disk(Disk *d)
-{
- char device[64];
- u_long l;
- int i,j,fd;
-
- strcpy(device,"/dev/");
- strcat(device,d->name);
-
- fd = open(device,O_RDWR);
- if (fd < 0) {
- msgWarn("open(%s) failed", device);
- return;
- }
- for(i=-1,l=0;;l++) {
- j = scan_block(fd,l);
- if (j != i) {
- if (i == -1) {
- printf("%c: %lu.",j ? 'B' : 'G', l);
- fflush(stdout);
- } else if (i == 0) {
- printf(".%lu\nB: %lu.",l-1,l);
- fflush(stdout);
- } else {
- printf(".%lu\nG: %lu.",l-1,l);
- fflush(stdout);
- }
- i = j;
- }
- }
- close(fd);
-}
-
-void
-slice_wizard(Disk *d)
-{
- Disk *db;
- char myprompt[BUFSIZ];
- char input[BUFSIZ];
- char *p,*q=0;
- char **cp,*cmds[200];
- int ncmd,i;
-
- systemSuspendDialog();
- sprintf(myprompt,"%s> ", d->name);
- while(1) {
- printf("--==##==--\n");
- Debug_Disk(d);
- p = CheckRules(d);
- if (p) {
- printf("%s",p);
- free(p);
- }
- printf("%s", myprompt);
- fflush(stdout);
- q = p = fgets(input,sizeof(input),stdin);
- if(!p)
- break;
- for(cp = cmds; (*cp = strsep(&p, " \t\n")) != NULL;)
- if (**cp != '\0')
- cp++;
- ncmd = cp - cmds;
- if(!ncmd)
- continue;
- if (!strcasecmp(*cmds,"quit")) { break; }
- if (!strcasecmp(*cmds,"exit")) { break; }
- if (!strcasecmp(*cmds,"q")) { break; }
- if (!strcasecmp(*cmds,"x")) { break; }
- if (!strcasecmp(*cmds,"delete") && ncmd == 2) {
- printf("delete = %d\n",
- Delete_Chunk(d,
- (struct chunk *)strtol(cmds[1],0,0)));
- continue;
- }
- if (!strcasecmp(*cmds,"allfreebsd")) {
- All_FreeBSD(d, 0);
- continue;
- }
- if (!strcasecmp(*cmds,"dedicate")) {
- All_FreeBSD(d, 1);
- continue;
- }
- if (!strcasecmp(*cmds,"bios") && ncmd == 4) {
- Set_Bios_Geom(d,
- strtol(cmds[1],0,0),
- strtol(cmds[2],0,0),
- strtol(cmds[3],0,0));
- continue;
- }
- if (!strcasecmp(*cmds,"list")) {
- cp = Disk_Names();
- printf("Disks:");
- for(i=0;cp[i];i++) {
- printf(" %s",cp[i]);
- free(cp[i]);
- }
- free(cp);
- continue;
- }
-#ifdef PC98
- if (!strcasecmp(*cmds,"create") && ncmd == 7) {
- printf("Create=%d\n",
- Create_Chunk(d,
- strtol(cmds[1],0,0),
- strtol(cmds[2],0,0),
- strtol(cmds[3],0,0),
- strtol(cmds[4],0,0),
- strtol(cmds[5],0,0),
- cmds[6]));
- continue;
- }
-#else
- if (!strcasecmp(*cmds,"create") && ncmd == 6) {
- printf("Create=%d\n",
- Create_Chunk(d,
- strtol(cmds[1],0,0),
- strtol(cmds[2],0,0),
- strtol(cmds[3],0,0),
- strtol(cmds[4],0,0),
- strtol(cmds[5],0,0), ""));
- continue;
- }
-#endif
- if (!strcasecmp(*cmds,"read")) {
- db = d;
- if (ncmd > 1)
- d = Open_Disk(cmds[1]);
- else
- d = Open_Disk(d->name);
- if (d)
- Free_Disk(db);
- else
- d = db;
- continue;
- }
- if (!strcasecmp(*cmds,"scan")) {
- Scan_Disk(d);
- continue;
- }
- if (!strcasecmp(*cmds,"write")) {
- printf("Write=%d\n",
- Fake ? 0 : Write_Disk(d));
- q = strdup(d->name);
- Free_Disk(d);
- d = Open_Disk(q);
- continue;
- }
- if (strcasecmp(*cmds,"help"))
- printf("\007ERROR\n");
- printf("CMDS:\n");
- printf("allfreebsd\t\t");
- printf("dedicate\t\t");
- printf("bios cyl hd sect\n");
- printf("collapse [pointer]\t\t");
-#ifdef PC98
- printf("create offset size enum subtype flags name\n");
-#else
- printf("create offset size enum subtype flags\n");
-#endif
- printf("subtype(part): swap=1, ffs=7\t\t");
- printf("delete pointer\n");
- printf("list\t\t");
- printf("quit\n");
- printf("read [disk]\t\t");
- printf("scan\n");
- printf("write\t\t");
- printf("\n");
-
- }
- systemResumeDialog();
-}